Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rich text spans #1589

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
91 changes: 81 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ glam = { version = "0.25", default-features = false, features = ["serde"] }
node-macro = { path = "node-graph/node-macro" }
base64 = { version = "0.21" }
image = { version = "0.24", default-features = false, features = ["png"] }
rustybuzz = { version = "0.10.0" }
cosmic-text = { version = "0.10", default-features = false, features = ["std"] }
num-derive = { version = "0.4" }
num-traits = { version = "0.2.15", default-features = false, features = [
"i128",
Expand Down
11 changes: 0 additions & 11 deletions editor/src/messages/frontend/frontend_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::messages::prelude::*;
use crate::messages::tool::utility_types::HintData;

use graph_craft::document::NodeId;
use graphene_core::raster::color::Color;
use graphene_core::text::Font;

#[impl_message(Message, Frontend)]
Expand All @@ -24,15 +23,6 @@ pub enum FrontendMessage {
},
DisplayEditableTextbox {
text: String,
#[serde(rename = "lineWidth")]
line_width: Option<f64>,
#[serde(rename = "fontSize")]
font_size: f64,
color: Color,
url: String,
transform: [f64; 6],
},
DisplayEditableTextboxTransform {
transform: [f64; 6],
},
DisplayRemoveEditableTextbox,
Expand Down Expand Up @@ -94,7 +84,6 @@ pub enum FrontendMessage {
TriggerSavePreferences {
preferences: PreferencesMessageHandler,
},
TriggerTextCommit,
TriggerTextCopy {
#[serde(rename = "copyText")]
copy_text: String,
Expand Down
2 changes: 2 additions & 0 deletions editor/src/messages/input_mapper/default_mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ pub fn default_mapping() -> Mapping {
entry!(KeyDown(Escape); action_dispatch=EyedropperToolMessage::Abort),
//
// TextToolMessage
entry!(KeyDown(Lmb); action_dispatch=TextToolMessage::Select),
entry!(PointerMove; action_dispatch=TextToolMessage::Drag),
entry!(KeyUp(Lmb); action_dispatch=TextToolMessage::Interact),
entry!(KeyDown(Escape); action_dispatch=TextToolMessage::Abort),
entry!(KeyDown(Enter); modifiers=[Accel], action_dispatch=TextToolMessage::CommitText),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use graph_craft::document::DocumentNode;
use graph_craft::document::NodeId;
use graphene_core::raster::BlendMode;
use graphene_core::raster::ImageFrame;
use graphene_core::text::Font;
use graphene_core::uuid::ManipulatorGroupId;
use graphene_core::vector::brush_stroke::BrushStroke;
use graphene_core::vector::style::{Fill, Stroke};
Expand Down Expand Up @@ -89,9 +88,7 @@ pub enum GraphOperationMessage {
},
NewTextLayer {
id: NodeId,
text: String,
font: Font,
size: f64,
text: graphene_core::text::RichText,
parent: LayerNodeIdentifier,
insert_index: isize,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::messages::prelude::*;
use bezier_rs::{ManipulatorGroup, Subpath};
use graph_craft::document::{generate_uuid, NodeId, NodeInput, NodeNetwork};
use graphene_core::renderer::Quad;
use graphene_core::text::Font;
use graphene_core::uuid::ManipulatorGroupId;
use graphene_core::vector::style::{Fill, Gradient, GradientType, LineCap, LineJoin, Stroke};
use graphene_core::Color;
Expand Down Expand Up @@ -180,17 +179,10 @@ impl MessageHandler<GraphOperationMessage, GraphOperationMessageData<'_>> for Gr
}
load_network_structure(document_network, document_metadata, selected_nodes, collapsed);
}
GraphOperationMessage::NewTextLayer {
id,
text,
font,
size,
parent,
insert_index,
} => {
GraphOperationMessage::NewTextLayer { id, text, parent, insert_index } => {
let mut modify_inputs = ModifyInputsContext::new(document_network, document_metadata, node_graph, responses);
if let Some(layer) = modify_inputs.create_layer_with_insert_index(id, insert_index, parent) {
modify_inputs.insert_text(text, font, size, layer);
modify_inputs.insert_text(text, layer);
}
load_network_structure(document_network, document_metadata, selected_nodes, collapsed);
}
Expand Down Expand Up @@ -318,10 +310,11 @@ fn import_usvg_node(modify_inputs: &mut ModifyInputsContext, node: &usvg::Node,
usvg::Node::Image(_image) => {
warn!("Skip image")
}
usvg::Node::Text(text) => {
let font = Font::new(crate::consts::DEFAULT_FONT_FAMILY.to_string(), crate::consts::DEFAULT_FONT_STYLE.to_string());
modify_inputs.insert_text(text.chunks.iter().map(|chunk| chunk.text.clone()).collect(), font, 24., layer);
modify_inputs.fill_set(Fill::Solid(Color::BLACK));
usvg::Node::Text(_text) => {
warn!("Skip text");
// let font = Font::new(crate::consts::DEFAULT_FONT_FAMILY.to_string(), crate::consts::DEFAULT_FONT_STYLE.to_string());
// modify_inputs.insert_text(text.chunks.iter().map(|chunk| chunk.text.clone()).collect(), layer);
// modify_inputs.fill_set(Fill::Solid(Color::BLACK));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use bezier_rs::Subpath;
use graph_craft::document::value::TaggedValue;
use graph_craft::document::{generate_uuid, DocumentNode, NodeId, NodeInput, NodeNetwork, NodeOutput};
use graphene_core::raster::{BlendMode, ImageFrame};
use graphene_core::text::Font;
use graphene_core::text::RichText;
use graphene_core::uuid::ManipulatorGroupId;
use graphene_core::vector::brush_stroke::BrushStroke;
use graphene_core::vector::style::{Fill, FillType, Stroke};
Expand Down Expand Up @@ -226,13 +226,13 @@ impl<'a> ModifyInputsContext<'a> {
self.responses.add(NodeGraphMessage::RunDocumentGraph);
}

pub fn insert_text(&mut self, text: String, font: Font, size: f64, layer: NodeId) {
pub fn insert_text(&mut self, rich_text: RichText, layer: NodeId) {
let text = resolve_document_node_type("Text").expect("Text node does not exist").to_document_node(
[
NodeInput::Network(graph_craft::concrete!(graphene_std::wasm_application_io::WasmEditorApi)),
NodeInput::value(TaggedValue::String(text), false),
NodeInput::value(TaggedValue::Font(font), false),
NodeInput::value(TaggedValue::F64(size), false),
NodeInput::value(TaggedValue::RichText(rich_text), false),
NodeInput::value(TaggedValue::F64(f64::MAX), false),
NodeInput::value(TaggedValue::VectorData(graphene_core::vector::VectorData::empty()), false),
],
Default::default(),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2482,9 +2482,9 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
name: "Text Generator".to_string(),
inputs: vec![
NodeInput::Network(concrete!(application_io::EditorApi<graphene_std::wasm_application_io::WasmApplicationIo>)),
NodeInput::Network(concrete!(String)),
NodeInput::Network(concrete!(graphene_core::text::Font)),
NodeInput::Network(concrete!(graphene_core::text::RichText)),
NodeInput::Network(concrete!(f64)),
NodeInput::Network(concrete!(graphene_core::vector::VectorData)),
],
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::text::TextGeneratorNode<_, _, _>")),
..Default::default()
Expand All @@ -2505,9 +2505,16 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
}),
inputs: vec![
DocumentInputType::none(),
DocumentInputType::value("Text", TaggedValue::String("Lorem ipsum".to_string()), false),
DocumentInputType::value("Font", TaggedValue::Font(Font::new(DEFAULT_FONT_FAMILY.into(), DEFAULT_FONT_STYLE.into())), false),
DocumentInputType::value("Size", TaggedValue::F64(24.), false),
DocumentInputType::value(
"Rich Text",
TaggedValue::RichText(graphene_core::text::RichText::new(
"Rich Text",
[graphene_core::text::TextSpan::new(Font::new(DEFAULT_FONT_FAMILY.into(), DEFAULT_FONT_STYLE.into()), 24.)],
)),
false,
),
DocumentInputType::value("Line Length", TaggedValue::F64(f64::MAX), false),
DocumentInputType::value("Path", TaggedValue::VectorData(graphene_core::vector::VectorData::empty()), false),
],
outputs: vec![DocumentOutputType::new("Vector", FrontendGraphDataType::Subpath)],
properties: node_properties::node_section_font,
Expand Down