Fix swash rendering

This commit is contained in:
Jeremy Soller 2022-10-07 10:31:49 -06:00
parent 10870f3c81
commit ca80c8ff4a
No known key found for this signature in database
GPG key ID: 87F211AF2BE4C2FE
2 changed files with 13 additions and 14 deletions

View file

@ -12,7 +12,7 @@ pub struct FontLayoutGlyph<'a, T: 'a> {
#[cfg(feature = "rusttype")] #[cfg(feature = "rusttype")]
pub inner: rusttype::PositionedGlyph<'a>, pub inner: rusttype::PositionedGlyph<'a>,
#[cfg(feature = "swash")] #[cfg(feature = "swash")]
pub inner: Option<swash::scale::image::Image>, pub inner: (i32, i32, Option<swash::scale::image::Image>),
pub phantom: PhantomData<&'a T>, pub phantom: PhantomData<&'a T>,
} }
@ -44,11 +44,11 @@ impl<'a> FontLayoutLine<'a> {
} }
#[cfg(feature = "swash")] #[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); assert_eq!(image.content, swash::scale::image::Content::Mask);
let x = glyph.x as i32 + image.placement.left; let x = glyph.inner.0 + image.placement.left;
let y = -image.placement.top; let y = glyph.inner.1 - image.placement.top;
let mut i = 0; let mut i = 0;
for off_y in 0..image.placement.height as i32 { for off_y in 0..image.placement.height as i32 {

View file

@ -71,18 +71,17 @@ impl<'a> FontShapeGlyph<'a> {
// Compute the fractional offset-- you'll likely want to quantize this // Compute the fractional offset-- you'll likely want to quantize this
// in a real renderer // 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 // Select our source order
Render::new(&[ let image_opt = Render::new(&[Source::Outline])
Source::Outline, // Select a subpixel format
]) .format(Format::Alpha)
// Select a subpixel format // Apply the fractional offset
.format(Format::Alpha) .offset(offset)
// Apply the fractional offset // Render the image
.offset(offset) .render(&mut scaler, self.inner);
// Render the image ((x + x_offset).trunc() as i32, (y - y_offset).trunc() as i32, image_opt)
.render(&mut scaler, self.inner)
}; };
FontLayoutGlyph { FontLayoutGlyph {