From ca80c8ff4a2e84c68c4bcecbc2ddb7dbfd0dc02f Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Fri, 7 Oct 2022 10:31:49 -0600 Subject: [PATCH] Fix swash rendering --- examples/text/src/font/layout.rs | 8 ++++---- examples/text/src/font/shape.rs | 19 +++++++++---------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/examples/text/src/font/layout.rs b/examples/text/src/font/layout.rs index 7f3101ce..dc5cf735 100644 --- a/examples/text/src/font/layout.rs +++ b/examples/text/src/font/layout.rs @@ -12,7 +12,7 @@ pub struct FontLayoutGlyph<'a, T: 'a> { #[cfg(feature = "rusttype")] pub inner: rusttype::PositionedGlyph<'a>, #[cfg(feature = "swash")] - pub inner: Option, + pub inner: (i32, i32, Option), pub phantom: PhantomData<&'a T>, } @@ -44,11 +44,11 @@ impl<'a> FontLayoutLine<'a> { } #[cfg(feature = "swash")] - if let Some(ref image) = glyph.inner { + if let Some(ref image) = glyph.inner.2 { assert_eq!(image.content, swash::scale::image::Content::Mask); - let x = glyph.x as i32 + image.placement.left; - let y = -image.placement.top; + let x = glyph.inner.0 + image.placement.left; + let y = glyph.inner.1 - image.placement.top; let mut i = 0; for off_y in 0..image.placement.height as i32 { diff --git a/examples/text/src/font/shape.rs b/examples/text/src/font/shape.rs index 04820693..ed6065a2 100644 --- a/examples/text/src/font/shape.rs +++ b/examples/text/src/font/shape.rs @@ -71,18 +71,17 @@ impl<'a> FontShapeGlyph<'a> { // Compute the fractional offset-- you'll likely want to quantize this // in a real renderer - let offset = Vector::new(x_offset, y_offset); + let offset = Vector::new((x + x_offset).fract(), (y - y_offset).fract()); // Select our source order - Render::new(&[ - Source::Outline, - ]) - // Select a subpixel format - .format(Format::Alpha) - // Apply the fractional offset - .offset(offset) - // Render the image - .render(&mut scaler, self.inner) + let image_opt = Render::new(&[Source::Outline]) + // Select a subpixel format + .format(Format::Alpha) + // Apply the fractional offset + .offset(offset) + // Render the image + .render(&mut scaler, self.inner); + ((x + x_offset).trunc() as i32, (y - y_offset).trunc() as i32, image_opt) }; FontLayoutGlyph {