Skip to content

Commit 2fb8205

Browse files
committed
refactor
1 parent 736e525 commit 2fb8205

7 files changed

Lines changed: 40 additions & 26 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use graphene_std::Color;
1414
use graphene_std::renderer::Quad;
1515
use graphene_std::renderer::convert_usvg_path::{convert_tiny_skia_path, convert_usvg_path};
1616
use graphene_std::table::Table;
17-
use graphene_std::text::{Font, TextAnchor, TypesettingConfig};
17+
use graphene_std::text::{Font, TypesettingConfig};
1818
use graphene_std::vector::style::{Fill, Gradient, GradientStop, GradientStops, GradientType, PaintOrder, Stroke, StrokeAlign, StrokeCap, StrokeJoin};
1919
#[derive(ExtractField)]
2020
pub struct GraphOperationMessageContext<'a> {

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::messages::portfolio::document::utility_types::document_metadata::Laye
44
use crate::messages::portfolio::document::utility_types::network_interface::{self, InputConnector, NodeNetworkInterface, OutputConnector};
55
use crate::messages::prelude::*;
66
use glam::{DAffine2, DVec2, IVec2};
7-
use graphene_std::transform::Transform as _;
87
use graph_craft::document::value::TaggedValue;
98
use graph_craft::document::{NodeId, NodeInput};
109
use graph_craft::{ProtoNodeIdentifier, concrete};
@@ -15,6 +14,7 @@ use graphene_std::raster_types::{CPU, Raster};
1514
use graphene_std::subpath::Subpath;
1615
use graphene_std::table::Table;
1716
use graphene_std::text::{Font, TextAnchor, TypesettingConfig};
17+
use graphene_std::transform::Transform as _;
1818
use graphene_std::vector::Vector;
1919
use graphene_std::vector::style::{Fill, Stroke};
2020
use graphene_std::vector::{PointId, VectorModificationType};
@@ -290,8 +290,18 @@ impl<'a> ModifyInputsContext<'a> {
290290
self.network_interface.move_node_to_chain_start(&fill_id, layer, &[], self.import);
291291
}
292292

293-
294-
pub fn insert_text_on_path(&mut self, text: String, font: Font, font_size: f64, character_spacing: f64, path_subpaths: Vec<Subpath<PointId>>, start_offset: f64, text_anchor: TextAnchor, transform: DAffine2, layer: LayerNodeIdentifier) {
293+
pub fn insert_text_on_path(
294+
&mut self,
295+
text: String,
296+
font: Font,
297+
font_size: f64,
298+
character_spacing: f64,
299+
path_subpaths: Vec<Subpath<PointId>>,
300+
start_offset: f64,
301+
text_anchor: TextAnchor,
302+
transform: DAffine2,
303+
layer: LayerNodeIdentifier,
304+
) {
295305
use graphene_std::text::TextPathSide;
296306

297307
// Create the path vector object

node-graph/nodes/gstd/src/text.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use core_types::{Ctx, table::Table};
22
use graph_craft::wasm_application_io::WasmEditorApi;
33
use graphic_types::Vector;
4-
pub use text_nodes::*;
54
pub use text_nodes::text_on_path::{TextAnchor, TextPathSide};
5+
pub use text_nodes::*;
66

77
/// Draws a text string as vector geometry with a choice of font and styling.
88
#[node_macro::node(category("Text"))]
@@ -80,8 +80,7 @@ fn text<'i: 'n>(
8080
#[node_macro::node(category("Text"))]
8181
fn text_on_path<'i: 'n>(
8282
_: impl Ctx,
83-
#[scope("editor-api")]
84-
editor_resources: &'i WasmEditorApi,
83+
#[scope("editor-api")] editor_resources: &'i WasmEditorApi,
8584
/// The text content to flow along the path.
8685
#[default("Lorem ipsum")]
8786
text: String,

node-graph/nodes/text/src/font_cache.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use dyn_any::DynAny;
22
use parley::fontique::Blob;
3+
use serde::Deserialize;
34
use std::collections::HashMap;
45
use std::hash::Hash;
56
use std::sync::Arc;
6-
use serde::Deserialize;
77

88
/// A font type (storing font family and font style and an optional preview URL)
99
#[cfg_attr(feature = "wasm", derive(tsify::Tsify))]
@@ -119,15 +119,15 @@ impl FontCache {
119119
if self.font_file_data.contains_key(font) {
120120
Some(font)
121121
} else {
122-
let fallback = self.font_file_data
122+
let fallback = self
123+
.font_file_data
123124
.keys()
124125
.find(|font| font.font_family == core_types::consts::DEFAULT_FONT_FAMILY && font.font_style == core_types::consts::DEFAULT_FONT_STYLE)
125-
.or_else(|| self.font_file_data.keys().next());
126+
.or_else(|| self.font_file_data.keys().next());
126127
fallback
127128
}
128129
}
129130

130-
131131
/// Try to get the bytes for a font
132132
pub fn get<'a>(&'a self, font: &'a Font) -> Option<(&'a Vec<u8>, &'a Font)> {
133133
let resolved = self.resolve_font(font)?;

node-graph/nodes/text/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
mod font_cache;
22
mod path_builder;
33
mod text_context;
4-
mod to_path;
54
pub mod text_on_path;
5+
mod to_path;
66

77
use dyn_any::DynAny;
88
pub use font_cache::*;

node-graph/nodes/text/src/path_builder.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use core_types::table::{Table, TableRow};
22
use glam::{DAffine2, DVec2};
3-
use vector_types::{Subpath, Vector};
3+
use kurbo::{PathSeg, Point};
44
use skrifa::instance::{NormalizedCoord, Size};
5-
use skrifa::outline::{OutlineGlyph, OutlinePen, DrawSettings};
5+
use skrifa::outline::{DrawSettings, OutlineGlyph, OutlinePen};
66
use skrifa::raw::FontRef as ReadFontsRef;
77
use skrifa::{GlyphId, MetadataProvider};
8-
use kurbo::{PathSeg, Point};
8+
use vector_types::{Subpath, Vector};
99

1010
pub struct PathBuilder<Upstream: Default + 'static> {
1111
vector_table: Table<Vector<Upstream>>,
@@ -39,7 +39,7 @@ impl<Upstream: Default + 'static> PathBuilder<Upstream> {
3939
self.glyph_subpaths.clear();
4040
self.current_segments.clear();
4141
self.current_point = Point::ZERO;
42-
42+
4343
let settings = DrawSettings::unhinted(Size::new(size), normalized_coords);
4444
glyph.draw(settings, self).unwrap();
4545

@@ -48,7 +48,11 @@ impl<Upstream: Default + 'static> PathBuilder<Upstream> {
4848
self.current_segments.clear();
4949
}
5050

51-
let transform = if self.is_text_on_path { final_transform } else { final_transform * DAffine2::from_scale(DVec2::splat(self.scale)) };
51+
let transform = if self.is_text_on_path {
52+
final_transform
53+
} else {
54+
final_transform * DAffine2::from_scale(DVec2::splat(self.scale))
55+
};
5256
let transform = if let Some(skew) = style_skew { transform * skew } else { transform };
5357

5458
let subpaths = std::mem::take(&mut self.glyph_subpaths);
@@ -88,14 +92,18 @@ impl<Upstream: Default + 'static> PathBuilder<Upstream> {
8892

8993
if let Some(glyph_outline) = outlines.get(GlyphId::from(glyph.id)) {
9094
let final_transform = DAffine2::from_translation(glyph_offset);
91-
if !per_glyph_instances { self.origin = DVec2::ZERO }
95+
if !per_glyph_instances {
96+
self.origin = DVec2::ZERO
97+
}
9298
self.draw_glyph(&glyph_outline, font_size, &normalized_coords, style_skew, final_transform, per_glyph_instances);
9399
}
94100
});
95101
}
96102

97103
pub fn finalize(mut self) -> Table<Vector<Upstream>> {
98-
if self.vector_table.is_empty() { self.vector_table = Table::new_from_element(Vector::default()) }
104+
if self.vector_table.is_empty() {
105+
self.vector_table = Table::new_from_element(Vector::default())
106+
}
99107
self.vector_table
100108
}
101109
}

node-graph/nodes/text/src/text_on_path.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use dyn_any::DynAny;
33
use glam::{DAffine2, DVec2};
44
use kurbo::{BezPath, ParamCurve, ParamCurveArclen, ParamCurveDeriv, PathEl, PathSeg};
55
use parley::PositionedLayoutItem;
6-
use skrifa::raw::FontRef as ReadFontsRef;
76
use skrifa::MetadataProvider;
7+
use skrifa::raw::FontRef as ReadFontsRef;
88
use vector_types::Vector;
99

1010
#[derive(Debug, Default, Clone, Copy, PartialEq, Hash, serde::Serialize, serde::Deserialize, DynAny, node_macro::ChoiceType)]
@@ -90,11 +90,7 @@ impl ArcLengthLut {
9090
let (seg_idx1, t1) = self.params[next_idx];
9191

9292
// Interpolate t within the segment
93-
let t = if seg_idx0 == seg_idx1 && (l1 - l0) > 1e-9 {
94-
t0 + (t1 - t0) * (s - l0) / (l1 - l0)
95-
} else {
96-
t0
97-
};
93+
let t = if seg_idx0 == seg_idx1 && (l1 - l0) > 1e-9 { t0 + (t1 - t0) * (s - l0) / (l1 - l0) } else { t0 };
9894

9995
let seg = self.segs.get(seg_idx0)?;
10096
let point = seg.eval(t);
@@ -233,7 +229,8 @@ pub fn place_text_on_path<Upstream: Default + 'static>(
233229
let (point, angle) = if lut.is_closed { lut.at_or_zero(effective_mid) } else { at_with_extension(&lut, effective_mid) };
234230

235231
if let Some(glyph_outline) = outlines.get(skrifa::GlyphId::from(glyph.id)) {
236-
let final_transform = DAffine2::from_translation(DVec2::new(point.x, point.y)) * DAffine2::from_angle(angle) * DAffine2::from_translation(DVec2::new(glyph.x as f64, -glyph.y as f64));
232+
let final_transform =
233+
DAffine2::from_translation(DVec2::new(point.x, point.y)) * DAffine2::from_angle(angle) * DAffine2::from_translation(DVec2::new(glyph.x as f64, -glyph.y as f64));
237234
path_builder.draw_glyph(&glyph_outline, font_size, &normalized_coords, style_skew, final_transform, true);
238235
}
239236
}

0 commit comments

Comments
 (0)