Add support for swash
This commit is contained in:
parent
51639e53cb
commit
cf43655357
7 changed files with 116 additions and 66 deletions
|
|
@ -11,6 +11,8 @@ pub struct FontLayoutGlyph<'a, T: 'a> {
|
|||
pub inner: Option<ab_glyph::OutlinedGlyph>,
|
||||
#[cfg(feature = "rusttype")]
|
||||
pub inner: rusttype::PositionedGlyph<'a>,
|
||||
#[cfg(feature = "swash")]
|
||||
pub inner: Option<swash::scale::image::Image>,
|
||||
pub phantom: PhantomData<&'a T>,
|
||||
}
|
||||
|
||||
|
|
@ -20,7 +22,7 @@ pub struct FontLayoutLine<'a> {
|
|||
}
|
||||
|
||||
impl<'a> FontLayoutLine<'a> {
|
||||
pub fn draw<F: FnMut(i32, i32, f32)>(&self, mut f: F) {
|
||||
pub fn draw<F: FnMut(i32, i32, u8)>(&self, mut f: F) {
|
||||
for glyph in self.glyphs.iter() {
|
||||
#[cfg(feature = "ab_glyph")]
|
||||
if let Some(ref outline) = glyph.inner {
|
||||
|
|
@ -28,7 +30,7 @@ impl<'a> FontLayoutLine<'a> {
|
|||
let x = bb.min.x as i32;
|
||||
let y = bb.min.y as i32;
|
||||
outline.draw(|off_x, off_y, v| {
|
||||
f(x + off_x as i32, y + off_y as i32, v);
|
||||
f(x + off_x as i32, y + off_y as i32, (v * 255.0) as u8);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -37,9 +39,25 @@ impl<'a> FontLayoutLine<'a> {
|
|||
let x = bb.min.x;
|
||||
let y = bb.min.y;
|
||||
glyph.inner.draw(|off_x, off_y, v| {
|
||||
f(x + off_x as i32, y + off_y as i32, v);
|
||||
f(x + off_x as i32, y + off_y as i32, (v * 255.0) as u8);
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(feature = "swash")]
|
||||
if let Some(ref image) = glyph.inner {
|
||||
assert_eq!(image.content, swash::scale::image::Content::Mask);
|
||||
|
||||
let x = glyph.x as i32 + image.placement.left;
|
||||
let y = -image.placement.top;
|
||||
|
||||
let mut i = 0;
|
||||
for off_y in 0..image.placement.height as i32 {
|
||||
for off_x in 0..image.placement.width as i32 {
|
||||
f(x + off_x, y + off_y, image.data[i]);
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue