Skip to content

Commit 4688432

Browse files
committed
Apply transform on instance instead of applying it when drawing the glyph
1 parent 4f1dbfd commit 4688432

File tree

2 files changed

+12
-24
lines changed

2 files changed

+12
-24
lines changed

node-graph/gcore/src/text/to_path.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,17 @@ thread_local! {
2121
struct PathBuilder {
2222
current_subpath: Subpath<PointId>,
2323
glyph_subpaths: Vec<Subpath<PointId>>,
24-
other_subpaths: Vec<VectorData>,
25-
origin: DVec2,
24+
other_subpaths: Vec<crate::instances::Instance<VectorData>>,
2625
scale: f64,
2726
id: PointId,
2827
}
2928

3029
impl PathBuilder {
3130
fn point(&self, x: f32, y: f32) -> DVec2 {
32-
// Y-axis inversion converts from font coordinate system (Y-up) to graphics coordinate system (Y-down)
33-
DVec2::new(self.origin.x + x as f64, self.origin.y - y as f64) * self.scale
31+
DVec2::new(x as f64, -y as f64) * self.scale
3432
}
3533

36-
fn set_origin(&mut self, x: f64, y: f64) {
37-
self.origin = DVec2::new(x, y);
38-
}
39-
40-
fn draw_glyph(&mut self, glyph: &OutlineGlyph<'_>, size: f32, normalized_coords: &[NormalizedCoord], style_skew: Option<DAffine2>, skew: DAffine2) {
34+
fn draw_glyph(&mut self, glyph: &OutlineGlyph<'_>, size: f32, normalized_coords: &[NormalizedCoord], glyph_offset: DVec2, style_skew: Option<DAffine2>, skew: DAffine2) {
4135
let location_ref = LocationRef::new(normalized_coords);
4236
let settings = DrawSettings::unhinted(Size::new(size), location_ref);
4337
glyph.draw(settings, self).unwrap();
@@ -53,7 +47,11 @@ impl PathBuilder {
5347
}
5448

5549
if !self.glyph_subpaths.is_empty() {
56-
self.other_subpaths.push(VectorData::from_subpaths(core::mem::take(&mut self.glyph_subpaths), false));
50+
self.other_subpaths.push(crate::instances::Instance {
51+
instance: VectorData::from_subpaths(core::mem::take(&mut self.glyph_subpaths), false),
52+
transform: DAffine2::from_translation(glyph_offset),
53+
..Default::default()
54+
})
5755
}
5856
}
5957
}
@@ -145,14 +143,12 @@ fn render_glyph_run(glyph_run: &GlyphRun<'_, ()>, path_builder: &mut PathBuilder
145143
let outlines = font_ref.outline_glyphs();
146144

147145
for glyph in glyph_run.glyphs() {
148-
let glyph_x = run_x + glyph.x;
149-
let glyph_y = run_y - glyph.y;
146+
let glyph_offset = DVec2::new((run_x + glyph.x) as f64, (run_y - glyph.y) as f64);
150147
run_x += glyph.advance;
151148

152149
let glyph_id = GlyphId::from(glyph.id);
153150
if let Some(glyph_outline) = outlines.get(glyph_id) {
154-
path_builder.set_origin(glyph_x as f64, glyph_y as f64);
155-
path_builder.draw_glyph(&glyph_outline, font_size, &normalized_coords, style_skew, skew);
151+
path_builder.draw_glyph(&glyph_outline, font_size, &normalized_coords, glyph_offset, style_skew, skew);
156152
}
157153
}
158154
}
@@ -187,14 +183,13 @@ fn layout_text(str: &str, font_data: Option<Blob<u8>>, typesetting: TypesettingC
187183
Some(layout)
188184
}
189185

190-
pub fn to_path(str: &str, font_data: Option<Blob<u8>>, typesetting: TypesettingConfig) -> Vec<VectorData> {
186+
pub fn to_path(str: &str, font_data: Option<Blob<u8>>, typesetting: TypesettingConfig) -> Vec<crate::instances::Instance<VectorData>> {
191187
let Some(layout) = layout_text(str, font_data, typesetting) else { return Vec::new() };
192188

193189
let mut path_builder = PathBuilder {
194190
current_subpath: Subpath::new(Vec::new(), false),
195191
glyph_subpaths: Vec::new(),
196192
other_subpaths: Vec::new(),
197-
origin: DVec2::ZERO,
198193
scale: layout.scale() as f64,
199194
id: PointId::ZERO,
200195
};

node-graph/gstd/src/text.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::vector::{VectorData, VectorDataTable};
2-
use glam::DAffine2;
32
use graph_craft::wasm_application_io::WasmEditorApi;
43
use graphene_core::Ctx;
54
pub use graphene_core::text::*;
@@ -49,13 +48,7 @@ fn text<'i: 'n>(
4948
};
5049

5150
for glyph in glyph_vectors {
52-
let instance = graphene_core::instances::Instance {
53-
instance: glyph,
54-
transform: DAffine2::IDENTITY,
55-
..Default::default()
56-
};
57-
58-
glyph_table.push(instance);
51+
glyph_table.push(glyph);
5952
}
6053

6154
glyph_table

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy