mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-27 18:18:13 +08:00
Add line height and character spacing to the Text node (#2016)
This commit is contained in:
@@ -94,6 +94,8 @@ pub enum GraphOperationMessage {
|
||||
text: String,
|
||||
font: Font,
|
||||
size: f64,
|
||||
line_height_ratio: f64,
|
||||
character_spacing: f64,
|
||||
parent: LayerNodeIdentifier,
|
||||
insert_index: usize,
|
||||
},
|
||||
|
||||
+4
-2
@@ -182,12 +182,14 @@ impl MessageHandler<GraphOperationMessage, GraphOperationMessageData<'_>> for Gr
|
||||
text,
|
||||
font,
|
||||
size,
|
||||
line_height_ratio,
|
||||
character_spacing,
|
||||
parent,
|
||||
insert_index,
|
||||
} => {
|
||||
let mut modify_inputs = ModifyInputsContext::new(network_interface, responses);
|
||||
let layer = modify_inputs.create_layer(id);
|
||||
modify_inputs.insert_text(text, font, size, layer);
|
||||
modify_inputs.insert_text(text, font, size, line_height_ratio, character_spacing, layer);
|
||||
network_interface.move_layer_to_stack(layer, parent, insert_index, &[]);
|
||||
responses.add(GraphOperationMessage::StrokeSet { layer, stroke: Stroke::default() });
|
||||
responses.add(NodeGraphMessage::RunDocumentGraph);
|
||||
@@ -284,7 +286,7 @@ fn import_usvg_node(modify_inputs: &mut ModifyInputsContext, node: &usvg::Node,
|
||||
}
|
||||
usvg::Node::Text(text) => {
|
||||
let font = Font::new(graphene_core::consts::DEFAULT_FONT_FAMILY.to_string(), graphene_core::consts::DEFAULT_FONT_STYLE.to_string());
|
||||
modify_inputs.insert_text(text.chunks().iter().map(|chunk| chunk.text()).collect(), font, 24., layer);
|
||||
modify_inputs.insert_text(text.chunks().iter().map(|chunk| chunk.text()).collect(), font, 24., 1.2, 1., layer);
|
||||
modify_inputs.fill_set(Fill::Solid(Color::BLACK));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ impl<'a> ModifyInputsContext<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn insert_text(&mut self, text: String, font: Font, size: f64, layer: LayerNodeIdentifier) {
|
||||
pub fn insert_text(&mut self, text: String, font: Font, size: f64, line_height_ratio: f64, character_spacing: f64, layer: LayerNodeIdentifier) {
|
||||
let stroke = resolve_document_node_type("Stroke").expect("Stroke node does not exist").default_node_template();
|
||||
let fill = resolve_document_node_type("Fill").expect("Fill node does not exist").default_node_template();
|
||||
let transform = resolve_document_node_type("Transform").expect("Transform node does not exist").default_node_template();
|
||||
@@ -186,6 +186,8 @@ impl<'a> ModifyInputsContext<'a> {
|
||||
Some(NodeInput::value(TaggedValue::String(text), false)),
|
||||
Some(NodeInput::value(TaggedValue::Font(font), false)),
|
||||
Some(NodeInput::value(TaggedValue::F64(size), false)),
|
||||
Some(NodeInput::value(TaggedValue::F64(line_height_ratio), false)),
|
||||
Some(NodeInput::value(TaggedValue::F64(character_spacing), false)),
|
||||
]);
|
||||
|
||||
let text_id = NodeId(generate_uuid());
|
||||
|
||||
@@ -2056,11 +2056,20 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
|
||||
false,
|
||||
),
|
||||
NodeInput::value(TaggedValue::F64(24.), false),
|
||||
NodeInput::value(TaggedValue::F64(1.2), false),
|
||||
NodeInput::value(TaggedValue::F64(1.), false),
|
||||
],
|
||||
..Default::default()
|
||||
},
|
||||
persistent_node_metadata: DocumentNodePersistentMetadata {
|
||||
input_names: vec!["Editor API".to_string(), "Text".to_string(), "Font".to_string(), "Size".to_string()],
|
||||
input_names: vec![
|
||||
"Editor API".to_string(),
|
||||
"Text".to_string(),
|
||||
"Font".to_string(),
|
||||
"Size".to_string(),
|
||||
"Line Height".to_string(),
|
||||
"Character Spacing".to_string(),
|
||||
],
|
||||
output_names: vec!["Vector".to_string()],
|
||||
..Default::default()
|
||||
},
|
||||
|
||||
@@ -1731,12 +1731,16 @@ pub(crate) fn text_properties(document_node: &DocumentNode, node_id: NodeId, _co
|
||||
let text = text_area_widget(document_node, node_id, 1, "Text", true);
|
||||
let (font, style) = font_inputs(document_node, node_id, 2, "Font", true);
|
||||
let size = number_widget(document_node, node_id, 3, "Size", NumberInput::default().unit(" px").min(1.), true);
|
||||
let line_height_ratio = number_widget(document_node, node_id, 4, "Line Height", NumberInput::default().min(0.).step(0.1), true);
|
||||
let character_spacing = number_widget(document_node, node_id, 5, "Character Spacing", NumberInput::default().min(0.).step(0.1), true);
|
||||
|
||||
let mut result = vec![LayoutGroup::Row { widgets: text }, LayoutGroup::Row { widgets: font }];
|
||||
if let Some(style) = style {
|
||||
result.push(LayoutGroup::Row { widgets: style });
|
||||
}
|
||||
result.push(LayoutGroup::Row { widgets: size });
|
||||
result.push(LayoutGroup::Row { widgets: line_height_ratio });
|
||||
result.push(LayoutGroup::Row { widgets: character_spacing });
|
||||
result
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user