Skip to content

Commit b145202

Browse files
committed
Shift glyphs up by embolden amount
Signed-off-by: Nico Burns <nico@nicoburns.com>
1 parent 89808f0 commit b145202

4 files changed

Lines changed: 34 additions & 33 deletions

File tree

crates/anyrender_vello/src/scene.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ impl PaintScene for VelloScenePainter<'_, '_> {
163163
glyphs.map(|g: anyrender::Glyph| vello::Glyph {
164164
id: g.id,
165165
x: g.x,
166-
y: g.y,
166+
y: g.y - embolden.y as f32,
167167
}),
168168
);
169169
}

crates/anyrender_vello_cpu/src/scene.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,6 @@ impl PaintScene for VelloCpuScenePainter {
138138
self.render_ctx
139139
.set_paint(anyrender_paint_to_vello_cpu_paint(paint.into()));
140140

141-
fn into_vello_cpu_glyph(g: anyrender::Glyph) -> vello_cpu::Glyph {
142-
vello_cpu::Glyph {
143-
id: g.id,
144-
x: g.x,
145-
y: g.y,
146-
}
147-
}
148-
149141
let style: StyleRef<'a> = style.into();
150142
match style {
151143
StyleRef::Fill(fill) => {
@@ -157,7 +149,11 @@ impl PaintScene for VelloCpuScenePainter {
157149
.normalized_coords(normalized_coords)
158150
.font_embolden(FontEmbolden::new(Diagonal2::new(embolden.x, embolden.y)))
159151
.glyph_transform(glyph_transform.unwrap_or_default())
160-
.fill_glyphs(glyphs.map(into_vello_cpu_glyph));
152+
.fill_glyphs(glyphs.map(|g| vello_cpu::Glyph {
153+
id: g.id,
154+
x: g.x,
155+
y: g.y - embolden.y as f32,
156+
}));
161157
}
162158
StyleRef::Stroke(stroke) => {
163159
self.render_ctx.set_stroke(stroke.clone());
@@ -167,7 +163,11 @@ impl PaintScene for VelloCpuScenePainter {
167163
.hint(hint)
168164
.normalized_coords(normalized_coords)
169165
.glyph_transform(glyph_transform.unwrap_or_default())
170-
.stroke_glyphs(glyphs.map(into_vello_cpu_glyph));
166+
.stroke_glyphs(glyphs.map(|g| vello_cpu::Glyph {
167+
id: g.id,
168+
x: g.x,
169+
y: g.y,
170+
}));
171171
}
172172
}
173173
}

crates/anyrender_vello_hybrid/src/scene.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,6 @@ impl PaintScene for VelloHybridScenePainter<'_> {
209209
self.scene.set_paint(paint);
210210
self.scene.set_transform(transform);
211211

212-
fn into_vello_hybrid_glyph(g: anyrender::Glyph) -> glifo::Glyph {
213-
glifo::Glyph {
214-
id: g.id,
215-
x: g.x,
216-
y: g.y,
217-
}
218-
}
219-
220212
let style: StyleRef<'a> = style.into();
221213
match style {
222214
StyleRef::Fill(fill) => {
@@ -228,7 +220,11 @@ impl PaintScene for VelloHybridScenePainter<'_> {
228220
.normalized_coords(normalized_coords)
229221
.font_embolden(FontEmbolden::new(Diagonal2::new(embolden.x, embolden.y)))
230222
.glyph_transform(glyph_transform.unwrap_or_default())
231-
.fill_glyphs(glyphs.map(into_vello_hybrid_glyph));
223+
.fill_glyphs(glyphs.map(|g| glifo::Glyph {
224+
id: g.id,
225+
x: g.x,
226+
y: g.y - embolden.y as f32,
227+
}));
232228
}
233229
StyleRef::Stroke(stroke) => {
234230
self.scene.set_stroke(stroke.clone());
@@ -238,7 +234,11 @@ impl PaintScene for VelloHybridScenePainter<'_> {
238234
.hint(hint)
239235
.normalized_coords(normalized_coords)
240236
.glyph_transform(glyph_transform.unwrap_or_default())
241-
.stroke_glyphs(glyphs.map(into_vello_hybrid_glyph));
237+
.stroke_glyphs(glyphs.map(|g| glifo::Glyph {
238+
id: g.id,
239+
x: g.x,
240+
y: g.y,
241+
}));
242242
}
243243
}
244244
}

crates/anyrender_vello_hybrid/src/webgl_scene.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
//! WebGL-compatible [`PaintScene`] implementation for [`vello_hybrid::Scene`].
22
33
use anyrender::{Glyph, NormalizedCoord, Paint, PaintRef, PaintScene, RenderContext};
4-
use kurbo::{Affine, Rect, Shape, Stroke};
4+
use glifo::FontEmbolden;
5+
use kurbo::{Affine, Diagonal2, Rect, Shape, Stroke};
56
use peniko::{BlendMode, Color, Fill, FontData, StyleRef};
67
use vello_common::paint::PaintType;
78

@@ -174,7 +175,7 @@ impl PaintScene for WebGlScenePainter<'_> {
174175
font_size: f32,
175176
hint: bool,
176177
normalized_coords: &'a [NormalizedCoord],
177-
_embolden: kurbo::Vec2,
178+
embolden: kurbo::Vec2,
178179
style: impl Into<StyleRef<'a>>,
179180
paint: impl Into<PaintRef<'a>>,
180181
_brush_alpha: f32,
@@ -186,14 +187,6 @@ impl PaintScene for WebGlScenePainter<'_> {
186187
self.scene.set_paint(paint);
187188
self.scene.set_transform(transform);
188189

189-
fn into_vello_glyph(g: Glyph) -> glifo::Glyph {
190-
glifo::Glyph {
191-
id: g.id,
192-
x: g.x,
193-
y: g.y,
194-
}
195-
}
196-
197190
let style: StyleRef<'a> = style.into();
198191
match style {
199192
StyleRef::Fill(fill) => {
@@ -205,7 +198,11 @@ impl PaintScene for WebGlScenePainter<'_> {
205198
.normalized_coords(normalized_coords)
206199
.font_embolden(FontEmbolden::new(Diagonal2::new(embolden.x, embolden.y)))
207200
.glyph_transform(glyph_transform.unwrap_or_default())
208-
.fill_glyphs(glyphs.map(into_vello_glyph));
201+
.fill_glyphs(glyphs.map(|g| glifo::Glyph {
202+
id: g.id,
203+
x: g.x,
204+
y: g.y - embolden.y as f32,
205+
}));
209206
}
210207
StyleRef::Stroke(stroke) => {
211208
self.scene.set_stroke(stroke.clone());
@@ -215,7 +212,11 @@ impl PaintScene for WebGlScenePainter<'_> {
215212
.hint(hint)
216213
.normalized_coords(normalized_coords)
217214
.glyph_transform(glyph_transform.unwrap_or_default())
218-
.stroke_glyphs(glyphs.map(into_vello_glyph));
215+
.stroke_glyphs(glyphs.map(|g| glifo::Glyph {
216+
id: g.id,
217+
x: g.x,
218+
y: g.y,
219+
}));
219220
}
220221
}
221222
}

0 commit comments

Comments
 (0)