diff --git a/piet-gpu/src/lib.rs b/piet-gpu/src/lib.rs index 096f84e..c171c62 100644 --- a/piet-gpu/src/lib.rs +++ b/piet-gpu/src/lib.rs @@ -192,7 +192,7 @@ fn render_text_test(rc: &mut impl RenderContext) { //rc.transform(Affine::new([0.2, 0.0, 0.0, -0.2, 200.0, 800.0])); let layout = rc .text() - .new_text_layout("hello piet-gpu text!") + .new_text_layout("\u{1f600}hello piet-gpu text!") .default_attribute(TextAttribute::FontSize(100.0)) .build() .unwrap(); diff --git a/piet-gpu/src/render_ctx.rs b/piet-gpu/src/render_ctx.rs index 43762fa..eb8fbea 100644 --- a/piet-gpu/src/render_ctx.rs +++ b/piet-gpu/src/render_ctx.rs @@ -492,7 +492,7 @@ impl PietGpuRenderContext { pub(crate) fn append_path_encoder(&mut self, path: &PathEncoder) { let elements = path.elements(); self.elements.extend(elements.iter().cloned()); - self.pathseg_count += elements.len(); + self.pathseg_count += path.n_segs(); } pub(crate) fn fill_glyph(&mut self, rgba_color: u32) { diff --git a/piet-gpu/src/text.rs b/piet-gpu/src/text.rs index 64ee88a..db8b547 100644 --- a/piet-gpu/src/text.rs +++ b/piet-gpu/src/text.rs @@ -16,7 +16,7 @@ use crate::render_ctx::{self, FillMode}; use crate::PietGpuRenderContext; // This is very much a hack to get things working. -const FONT_DATA: &[u8] = include_bytes!("../third-party/Roboto-Regular.ttf"); +const FONT_DATA: &[u8] = include_bytes!("c:\\Windows\\Fonts\\seguiemj.ttf"); #[derive(Clone)] pub struct Font { @@ -53,6 +53,9 @@ struct Glyph { #[derive(Default)] pub struct PathEncoder { elements: Vec, + n_segs: usize, + // If this is zero, then it's a text glyph and should be followed by a fill + n_colr_layers: usize, } impl PietGpuText { @@ -128,6 +131,7 @@ impl Font { let mut scale_context = ScaleContext::new(); let mut scaler = scale_context.builder(self.font_ref).size(2048.).build(); let mut encoder = PathEncoder::default(); + println!("glyph {} has_color_outlines {}", glyph_id, scaler.has_color_outlines()); if let Some(outline) = scaler.scale_outline(glyph_id) { let verbs = outline.verbs(); let points = outline.points(); @@ -186,6 +190,7 @@ impl Font { } } } + encoder.n_segs = encoder.elements.len(); encoder } } @@ -307,6 +312,10 @@ impl PathEncoder { pub(crate) fn elements(&self) -> &[Element] { &self.elements } + + pub(crate) fn n_segs(&self) -> usize { + self.n_segs + } } fn convert_swash_point(v: Vector) -> [f32; 2] {