mirror of
https://github.com/italicsjenga/vello.git
synced 2025-01-10 12:41:30 +11:00
Coarser grain ScaleContext
This patch sets up a ScaleContext for the duration of a draw_text call, where it was previously per-glyph.
This commit is contained in:
parent
8b4a6c54cd
commit
529e5cce5e
|
@ -1,6 +1,6 @@
|
||||||
use std::ops::RangeBounds;
|
use std::ops::RangeBounds;
|
||||||
|
|
||||||
use swash::scale::ScaleContext;
|
use swash::scale::{ScaleContext, Scaler};
|
||||||
use swash::zeno::{Vector, Verb};
|
use swash::zeno::{Vector, Verb};
|
||||||
use swash::{FontRef, GlyphId};
|
use swash::{FontRef, GlyphId};
|
||||||
|
|
||||||
|
@ -59,6 +59,10 @@ pub struct PathEncoder {
|
||||||
n_colr_layers: usize,
|
n_colr_layers: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct TextRenderCtx<'a> {
|
||||||
|
scaler: Scaler<'a>,
|
||||||
|
}
|
||||||
|
|
||||||
impl PietGpuText {
|
impl PietGpuText {
|
||||||
pub(crate) fn new(font: Font) -> PietGpuText {
|
pub(crate) fn new(font: Font) -> PietGpuText {
|
||||||
PietGpuText { font }
|
PietGpuText { font }
|
||||||
|
@ -122,18 +126,10 @@ impl Font {
|
||||||
Font { font_ref }
|
Font { font_ref }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_path(&self, glyph_id: GlyphId) -> PathEncoder {
|
fn make_path<'a>(&self, glyph_id: GlyphId, tc: &mut TextRenderCtx<'a>) -> PathEncoder {
|
||||||
/*
|
|
||||||
let mut encoder = PathEncoder::default();
|
let mut encoder = PathEncoder::default();
|
||||||
self.face.outline_glyph(glyph_id, &mut encoder);
|
if tc.scaler.has_color_outlines() {
|
||||||
encoder
|
if let Some(outline) = tc.scaler.scale_color_outline(glyph_id) {
|
||||||
*/
|
|
||||||
// Should the scale context be in the font? In the RenderCtx?
|
|
||||||
let mut scale_context = ScaleContext::new();
|
|
||||||
let mut scaler = scale_context.builder(self.font_ref).size(2048.).build();
|
|
||||||
let mut encoder = PathEncoder::default();
|
|
||||||
if scaler.has_color_outlines() {
|
|
||||||
if let Some(outline) = scaler.scale_color_outline(glyph_id) {
|
|
||||||
// TODO: be more sophisticated choosing a palette
|
// TODO: be more sophisticated choosing a palette
|
||||||
let palette = self.font_ref.color_palettes().next().unwrap();
|
let palette = self.font_ref.color_palettes().next().unwrap();
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
|
@ -148,7 +144,7 @@ impl Font {
|
||||||
return encoder;
|
return encoder;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(outline) = scaler.scale_outline(glyph_id) {
|
if let Some(outline) = tc.scaler.scale_outline(glyph_id) {
|
||||||
encoder.append_outline(outline.verbs(), outline.points());
|
encoder.append_outline(outline.verbs(), outline.points());
|
||||||
}
|
}
|
||||||
encoder
|
encoder
|
||||||
|
@ -175,6 +171,12 @@ impl PietGpuTextLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn draw_text(&self, ctx: &mut PietGpuRenderContext, pos: Point) {
|
pub(crate) fn draw_text(&self, ctx: &mut PietGpuRenderContext, pos: Point) {
|
||||||
|
let mut scale_ctx = ScaleContext::new();
|
||||||
|
let scaler = scale_ctx.builder(self.font.font_ref).size(2048.)
|
||||||
|
.build();
|
||||||
|
let mut tc = TextRenderCtx {
|
||||||
|
scaler,
|
||||||
|
};
|
||||||
// Should we use ppem from font, or let swash scale?
|
// Should we use ppem from font, or let swash scale?
|
||||||
const DEFAULT_UPEM: u16 = 2048;
|
const DEFAULT_UPEM: u16 = 2048;
|
||||||
let scale = self.size as f32 / DEFAULT_UPEM as f32;
|
let scale = self.size as f32 / DEFAULT_UPEM as f32;
|
||||||
|
@ -213,7 +215,7 @@ impl PietGpuTextLayout {
|
||||||
last_x = glyph.x;
|
last_x = glyph.x;
|
||||||
//println!("{:?}, {:?}", transform.mat, transform.translate);
|
//println!("{:?}, {:?}", transform.mat, transform.translate);
|
||||||
ctx.encode_transform(transform);
|
ctx.encode_transform(transform);
|
||||||
let path = self.font.make_path(glyph.glyph_id);
|
let path = self.font.make_path(glyph.glyph_id, &mut tc);
|
||||||
ctx.append_path_encoder(&path);
|
ctx.append_path_encoder(&path);
|
||||||
if path.n_colr_layers == 0 {
|
if path.n_colr_layers == 0 {
|
||||||
ctx.fill_glyph(0xff_ff_ff_ff);
|
ctx.fill_glyph(0xff_ff_ff_ff);
|
||||||
|
|
Loading…
Reference in a new issue