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")]
pub inner: rusttype::PositionedGlyph<'a>,
#[cfg(feature = "swash")]
pub inner: Option<swash::scale::image::Image>,
pub inner: (i32, i32, Option<swash::scale::image::Image>),
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 {

View file

@ -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 {