Skip to content

Commit d198695

Browse files
committed
Code review
1 parent 5b5373a commit d198695

File tree

5 files changed

+42
-31
lines changed

5 files changed

+42
-31
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ perf.data*
55
profile.json
66
flamegraph.svg
77
.idea/
8-
98
.direnv

.nix/flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
libraw
5252

5353

54-
# Tauri dependencies: keep in sync with https://v2.tauri.app/start/prerequisites/
54+
# Tauri dependencies: keep in sync with https://v2.tauri.app/start/prerequisites/#system-dependencies (under the NixOS tab)
5555
at-spi2-atk
5656
atkmm
5757
cairo

Cargo.lock

Lines changed: 21 additions & 1 deletion
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
@@ -105,7 +105,7 @@ glam = { version = "0.29", default-features = false, features = ["serde", "scala
105105
base64 = "0.22"
106106
image = { version = "0.25", default-features = false, features = ["png", "jpeg", "bmp"] }
107107
parley = "0.5.0"
108-
skrifa = "0.31.3"
108+
skrifa = "0.32.0"
109109
pretty_assertions = "1.4.1"
110110
fern = { version = "0.7", features = ["colored"] }
111111
num_enum = "0.7"

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

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
use core::cell::RefCell;
2-
use std::sync::Arc;
3-
41
use crate::vector::PointId;
52
use bezier_rs::{ManipulatorGroup, Subpath};
3+
use core::cell::RefCell;
64
use glam::DVec2;
7-
use parley::{Alignment, AlignmentOptions, FontContext, GlyphRun, Layout, LayoutContext, LineHeight, PositionedLayoutItem, StyleProperty, fontique::Blob};
8-
use skrifa::{
9-
GlyphId, MetadataProvider, OutlineGlyph,
10-
instance::{LocationRef, NormalizedCoord, Size},
11-
outline::{DrawSettings, OutlinePen},
12-
raw::FontRef as ReadFontsRef,
13-
};
5+
use parley::fontique::Blob;
6+
use parley::{Alignment, AlignmentOptions, FontContext, GlyphRun, Layout, LayoutContext, LineHeight, PositionedLayoutItem, StyleProperty};
7+
use skrifa::GlyphId;
8+
use skrifa::instance::{LocationRef, NormalizedCoord, Size};
9+
use skrifa::outline::{DrawSettings, OutlinePen};
10+
use skrifa::raw::FontRef as ReadFontsRef;
11+
use skrifa::{MetadataProvider, OutlineGlyph};
12+
use std::sync::Arc;
1413

1514
thread_local! {
1615
static FONT_CONTEXT: RefCell<FontContext> = RefCell::new(FontContext::new());
@@ -20,20 +19,18 @@ thread_local! {
2019
struct PathBuilder {
2120
current_subpath: Subpath<PointId>,
2221
other_subpaths: Vec<Subpath<PointId>>,
23-
x: f32,
24-
y: f32,
22+
origin: DVec2,
2523
scale: f64,
2624
id: PointId,
2725
}
2826

2927
impl PathBuilder {
3028
fn point(&self, x: f32, y: f32) -> DVec2 {
31-
DVec2::new((self.x + x) as f64, (self.y - y) as f64) * self.scale
29+
DVec2::new(self.origin.x + x as f64, self.origin.y - y as f64) * self.scale
3230
}
3331

34-
fn set_origin(&mut self, x: f32, y: f32) {
35-
self.x = x;
36-
self.y = y;
32+
fn set_origin(&mut self, x: f64, y: f64) {
33+
self.origin = DVec2::new(x, y);
3734
}
3835

3936
fn draw_glyph(&mut self, glyph: &OutlineGlyph<'_>, size: f32, normalized_coords: &[NormalizedCoord]) {
@@ -122,7 +119,7 @@ fn render_glyph_run(glyph_run: &GlyphRun<'_, ()>, path_builder: &mut PathBuilder
122119

123120
let glyph_id = GlyphId::from(glyph.id);
124121
if let Some(glyph_outline) = outlines.get(glyph_id) {
125-
path_builder.set_origin(glyph_x, glyph_y);
122+
path_builder.set_origin(glyph_x as f64, glyph_y as f64);
126123
path_builder.draw_glyph(&glyph_outline, font_size, &normalized_coords);
127124
}
128125
}
@@ -138,11 +135,11 @@ fn layout_text(str: &str, font_data: Option<Blob<u8>>, typesetting: TypesettingC
138135
font_cx
139136
.collection
140137
.register_fonts(font_data, None)
141-
.get(0)
138+
.first()
142139
.and_then(|(family_id, _)| font_cx.collection.family_name(*family_id).map(String::from))
143140
})?;
144141

145-
const DISPLAY_SCALE: f32 = 1.0;
142+
const DISPLAY_SCALE: f32 = 1.;
146143
let mut builder = layout_cx.ranged_builder(&mut font_cx, str, DISPLAY_SCALE, true);
147144

148145
builder.push_default(StyleProperty::FontSize(typesetting.font_size as f32));
@@ -159,15 +156,12 @@ fn layout_text(str: &str, font_data: Option<Blob<u8>>, typesetting: TypesettingC
159156
}
160157

161158
pub fn to_path(str: &str, font_data: Option<Blob<u8>>, typesetting: TypesettingConfig) -> Vec<Subpath<PointId>> {
162-
let Some(layout) = layout_text(str, font_data, typesetting) else {
163-
return vec![];
164-
};
159+
let Some(layout) = layout_text(str, font_data, typesetting) else { return Vec::new() };
165160

166161
let mut path_builder = PathBuilder {
167162
current_subpath: Subpath::new(Vec::new(), false),
168163
other_subpaths: Vec::new(),
169-
x: 0.,
170-
y: 0.,
164+
origin: DVec2::ZERO,
171165
scale: layout.scale() as f64,
172166
id: PointId::ZERO,
173167
};
@@ -195,9 +189,7 @@ pub fn bounding_box(str: &str, font_data: Option<Blob<u8>>, typesetting: Typeset
195189
}
196190
}
197191

198-
let Some(layout) = layout_text(str, font_data, typesetting) else {
199-
return DVec2::ZERO;
200-
};
192+
let Some(layout) = layout_text(str, font_data, typesetting) else { return DVec2::ZERO };
201193

202194
DVec2::new(layout.full_width() as f64, layout.height() as f64)
203195
}

0 commit comments

Comments
 (0)