Skip to content

Commit c2d0787

Browse files
0HyperCubeKeavon
authored andcommitted
Text spans
1 parent 938a688 commit c2d0787

File tree

33 files changed

+1283
-474
lines changed

33 files changed

+1283
-474
lines changed

Cargo.lock

Lines changed: 81 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ glam = { version = "0.25", default-features = false, features = ["serde"] }
7272
node-macro = { path = "node-graph/node-macro" }
7373
base64 = { version = "0.21" }
7474
image = { version = "0.24", default-features = false, features = ["png"] }
75-
rustybuzz = { version = "0.10.0" }
75+
cosmic-text = { version = "0.10", default-features = false, features = ["std"] }
7676
num-derive = { version = "0.4" }
7777
num-traits = { version = "0.2.15", default-features = false, features = [
7878
"i128",

editor/src/messages/frontend/frontend_message.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::messages::prelude::*;
66
use crate::messages::tool::utility_types::HintData;
77

88
use graph_craft::document::NodeId;
9-
use graphene_core::raster::color::Color;
109
use graphene_core::text::Font;
1110

1211
#[impl_message(Message, Frontend)]
@@ -24,15 +23,6 @@ pub enum FrontendMessage {
2423
},
2524
DisplayEditableTextbox {
2625
text: String,
27-
#[serde(rename = "lineWidth")]
28-
line_width: Option<f64>,
29-
#[serde(rename = "fontSize")]
30-
font_size: f64,
31-
color: Color,
32-
url: String,
33-
transform: [f64; 6],
34-
},
35-
DisplayEditableTextboxTransform {
3626
transform: [f64; 6],
3727
},
3828
DisplayRemoveEditableTextbox,
@@ -94,7 +84,6 @@ pub enum FrontendMessage {
9484
TriggerSavePreferences {
9585
preferences: PreferencesMessageHandler,
9686
},
97-
TriggerTextCommit,
9887
TriggerTextCopy {
9988
#[serde(rename = "copyText")]
10089
copy_text: String,

editor/src/messages/input_mapper/default_mapping.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ pub fn default_mapping() -> Mapping {
134134
entry!(KeyDown(Escape); action_dispatch=EyedropperToolMessage::Abort),
135135
//
136136
// TextToolMessage
137+
entry!(KeyDown(Lmb); action_dispatch=TextToolMessage::Select),
138+
entry!(PointerMove; action_dispatch=TextToolMessage::Drag),
137139
entry!(KeyUp(Lmb); action_dispatch=TextToolMessage::Interact),
138140
entry!(KeyDown(Escape); action_dispatch=TextToolMessage::Abort),
139141
entry!(KeyDown(Enter); modifiers=[Accel], action_dispatch=TextToolMessage::CommitText),

editor/src/messages/portfolio/document/graph_operation/graph_operation_message.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use graph_craft::document::DocumentNode;
88
use graph_craft::document::NodeId;
99
use graphene_core::raster::BlendMode;
1010
use graphene_core::raster::ImageFrame;
11-
use graphene_core::text::Font;
1211
use graphene_core::uuid::ManipulatorGroupId;
1312
use graphene_core::vector::brush_stroke::BrushStroke;
1413
use graphene_core::vector::style::{Fill, Stroke};
@@ -89,9 +88,7 @@ pub enum GraphOperationMessage {
8988
},
9089
NewTextLayer {
9190
id: NodeId,
92-
text: String,
93-
font: Font,
94-
size: f64,
91+
text: graphene_core::text::RichText,
9592
parent: LayerNodeIdentifier,
9693
insert_index: isize,
9794
},

editor/src/messages/portfolio/document/graph_operation/graph_operation_message_handler.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use crate::messages::prelude::*;
77
use bezier_rs::{ManipulatorGroup, Subpath};
88
use graph_craft::document::{generate_uuid, NodeId, NodeInput, NodeNetwork};
99
use graphene_core::renderer::Quad;
10-
use graphene_core::text::Font;
1110
use graphene_core::uuid::ManipulatorGroupId;
1211
use graphene_core::vector::style::{Fill, Gradient, GradientType, LineCap, LineJoin, Stroke};
1312
use graphene_core::Color;
@@ -180,17 +179,10 @@ impl MessageHandler<GraphOperationMessage, GraphOperationMessageData<'_>> for Gr
180179
}
181180
load_network_structure(document_network, document_metadata, selected_nodes, collapsed);
182181
}
183-
GraphOperationMessage::NewTextLayer {
184-
id,
185-
text,
186-
font,
187-
size,
188-
parent,
189-
insert_index,
190-
} => {
182+
GraphOperationMessage::NewTextLayer { id, text, parent, insert_index } => {
191183
let mut modify_inputs = ModifyInputsContext::new(document_network, document_metadata, node_graph, responses);
192184
if let Some(layer) = modify_inputs.create_layer_with_insert_index(id, insert_index, parent) {
193-
modify_inputs.insert_text(text, font, size, layer);
185+
modify_inputs.insert_text(text, layer);
194186
}
195187
load_network_structure(document_network, document_metadata, selected_nodes, collapsed);
196188
}
@@ -318,10 +310,11 @@ fn import_usvg_node(modify_inputs: &mut ModifyInputsContext, node: &usvg::Node,
318310
usvg::Node::Image(_image) => {
319311
warn!("Skip image")
320312
}
321-
usvg::Node::Text(text) => {
322-
let font = Font::new(crate::consts::DEFAULT_FONT_FAMILY.to_string(), crate::consts::DEFAULT_FONT_STYLE.to_string());
323-
modify_inputs.insert_text(text.chunks.iter().map(|chunk| chunk.text.clone()).collect(), font, 24., layer);
324-
modify_inputs.fill_set(Fill::Solid(Color::BLACK));
313+
usvg::Node::Text(_text) => {
314+
warn!("Skip text");
315+
// let font = Font::new(crate::consts::DEFAULT_FONT_FAMILY.to_string(), crate::consts::DEFAULT_FONT_STYLE.to_string());
316+
// modify_inputs.insert_text(text.chunks.iter().map(|chunk| chunk.text.clone()).collect(), layer);
317+
// modify_inputs.fill_set(Fill::Solid(Color::BLACK));
325318
}
326319
}
327320
}

editor/src/messages/portfolio/document/graph_operation/utility_types.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use bezier_rs::Subpath;
77
use graph_craft::document::value::TaggedValue;
88
use graph_craft::document::{generate_uuid, DocumentNode, NodeId, NodeInput, NodeNetwork, NodeOutput};
99
use graphene_core::raster::{BlendMode, ImageFrame};
10-
use graphene_core::text::Font;
10+
use graphene_core::text::RichText;
1111
use graphene_core::uuid::ManipulatorGroupId;
1212
use graphene_core::vector::brush_stroke::BrushStroke;
1313
use graphene_core::vector::style::{Fill, FillType, Stroke};
@@ -226,13 +226,13 @@ impl<'a> ModifyInputsContext<'a> {
226226
self.responses.add(NodeGraphMessage::RunDocumentGraph);
227227
}
228228

229-
pub fn insert_text(&mut self, text: String, font: Font, size: f64, layer: NodeId) {
229+
pub fn insert_text(&mut self, rich_text: RichText, layer: NodeId) {
230230
let text = resolve_document_node_type("Text").expect("Text node does not exist").to_document_node(
231231
[
232232
NodeInput::Network(graph_craft::concrete!(graphene_std::wasm_application_io::WasmEditorApi)),
233-
NodeInput::value(TaggedValue::String(text), false),
234-
NodeInput::value(TaggedValue::Font(font), false),
235-
NodeInput::value(TaggedValue::F64(size), false),
233+
NodeInput::value(TaggedValue::RichText(rich_text), false),
234+
NodeInput::value(TaggedValue::F64(f64::MAX), false),
235+
NodeInput::value(TaggedValue::VectorData(graphene_core::vector::VectorData::empty()), false),
236236
],
237237
Default::default(),
238238
);

editor/src/messages/portfolio/document/node_graph/document_node_types.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2482,9 +2482,9 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
24822482
name: "Text Generator".to_string(),
24832483
inputs: vec![
24842484
NodeInput::Network(concrete!(application_io::EditorApi<graphene_std::wasm_application_io::WasmApplicationIo>)),
2485-
NodeInput::Network(concrete!(String)),
2486-
NodeInput::Network(concrete!(graphene_core::text::Font)),
2485+
NodeInput::Network(concrete!(graphene_core::text::RichText)),
24872486
NodeInput::Network(concrete!(f64)),
2487+
NodeInput::Network(concrete!(graphene_core::vector::VectorData)),
24882488
],
24892489
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::text::TextGeneratorNode<_, _, _>")),
24902490
..Default::default()
@@ -2505,9 +2505,16 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
25052505
}),
25062506
inputs: vec![
25072507
DocumentInputType::none(),
2508-
DocumentInputType::value("Text", TaggedValue::String("Lorem ipsum".to_string()), false),
2509-
DocumentInputType::value("Font", TaggedValue::Font(Font::new(DEFAULT_FONT_FAMILY.into(), DEFAULT_FONT_STYLE.into())), false),
2510-
DocumentInputType::value("Size", TaggedValue::F64(24.), false),
2508+
DocumentInputType::value(
2509+
"Rich Text",
2510+
TaggedValue::RichText(graphene_core::text::RichText::new(
2511+
"Rich Text",
2512+
[graphene_core::text::TextSpan::new(Font::new(DEFAULT_FONT_FAMILY.into(), DEFAULT_FONT_STYLE.into()), 24.)],
2513+
)),
2514+
false,
2515+
),
2516+
DocumentInputType::value("Line Length", TaggedValue::F64(f64::MAX), false),
2517+
DocumentInputType::value("Path", TaggedValue::VectorData(graphene_core::vector::VectorData::empty()), false),
25112518
],
25122519
outputs: vec![DocumentOutputType::new("Vector", FrontendGraphDataType::Subpath)],
25132520
properties: node_properties::node_section_font,

0 commit comments

Comments
 (0)