-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathtext.rs
More file actions
78 lines (76 loc) · 2.82 KB
/
text.rs
File metadata and controls
78 lines (76 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use core_types::{Ctx, table::Table};
use graph_craft::wasm_application_io::WasmEditorApi;
use graphic_types::Vector;
pub use text_nodes::*;
/// Draws a text string as vector geometry with a choice of font and styling.
#[node_macro::node(category("Text"))]
fn text<'i: 'n>(
_: impl Ctx,
/// The Graphite editor's source for global font resources.
#[scope("editor-api")]
editor_resources: &'i WasmEditorApi,
/// The text content to be drawn.
#[widget(ParsedWidgetOverride::Custom = "text_area")]
#[default("Lorem ipsum")]
text: String,
/// The typeface used to draw the text.
#[widget(ParsedWidgetOverride::Custom = "text_font")]
font: Font,
/// The font size used to draw the text.
#[unit(" px")]
#[default(24.)]
#[hard_min(1.)]
size: f64,
/// The line height ratio, relative to the font size. Each line is drawn lower than its previous line by the distance of *Size* × *Line Height*.
///
/// 0 means all lines overlap. 1 means all lines are spaced by just the font size. 1.2 is a common default for readable text. 2 means double-spaced text.
#[unit("x")]
#[hard_min(0.)]
#[step(0.1)]
#[default(1.2)]
line_height: f64,
/// Additional spacing, in pixels, added between each character.
#[unit(" px")]
#[step(0.1)]
character_spacing: f64,
/// Whether the *Max Width* property is enabled so that lines can wrap to fit its specified block width.
#[widget(ParsedWidgetOverride::Hidden)]
has_max_width: bool,
/// The maximum width that the text block can occupy before wrapping to a new line. Otherwise, lines do not wrap.
#[unit(" px")]
#[hard_min(1.)]
#[widget(ParsedWidgetOverride::Custom = "optional_f64")]
max_width: f64,
/// Whether the *Max Height* property is enabled so that lines beyond it are not drawn.
#[widget(ParsedWidgetOverride::Hidden)]
has_max_height: bool,
/// The maximum height that the text block can occupy. Excess lines are not drawn.
#[unit(" px")]
#[hard_min(1.)]
#[widget(ParsedWidgetOverride::Custom = "optional_f64")]
max_height: f64,
/// The angle of faux italic slant applied to each glyph.
#[unit("°")]
#[hard_min(-85.)]
#[hard_max(85.)]
tilt: f64,
/// The horizontal alignment of each line of text within its surrounding box.
/// To have an effect on a single line of text, *Max Width* must be set.
#[widget(ParsedWidgetOverride::Custom = "text_align")]
align: TextAlign,
/// Whether to split every letterform into its own vector path element. Otherwise, a single compound path is produced.
separate_glyph_elements: bool,
hyphenate: bool,
) -> Table<Vector> {
let typesetting = TypesettingConfig {
font_size: size,
line_height_ratio: line_height,
character_spacing,
max_width: has_max_width.then_some(max_width),
max_height: has_max_height.then_some(max_height),
tilt,
align,
hyphenate,
};
to_path(&text, &font, &editor_resources.font_cache, typesetting, separate_glyph_elements)
}