Skip to content

Commit

Permalink
Merge pull request #690 from googlefonts/scaler-cff-hint
Browse files Browse the repository at this point in the history
[skrifa] plumb hinting request to CFF scaler
  • Loading branch information
rsheeter authored Nov 3, 2023
2 parents 0200bd2 + beac1f9 commit 47493f7
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions skrifa/src/scale/scaler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ impl<'a> ScalerBuilder<'a> {
Scaler {
size,
coords,
#[cfg(feature = "hinting")]
hint: self.hint,
outlines,
}
}
Expand Down Expand Up @@ -204,6 +206,8 @@ impl<'a> ScalerBuilder<'a> {
pub struct Scaler<'a> {
size: f32,
coords: &'a [NormalizedCoord],
#[cfg(feature = "hinting")]
hint: Option<Hinting>,
outlines: Option<Outlines<'a>>,
}

Expand All @@ -222,7 +226,14 @@ impl<'a> Scaler<'a> {
/// in the given pen for the sequence of path commands that define the outline.
pub fn outline(&mut self, glyph_id: GlyphId, pen: &mut impl Pen) -> Result<ScalerMetrics> {
if let Some(outlines) = &mut self.outlines {
outlines.outline(glyph_id, self.size, self.coords, pen)
outlines.outline(
glyph_id,
self.size,
self.coords,
#[cfg(feature = "hinting")]
self.hint,
pen,
)
} else {
Err(Error::NoSources)
}
Expand All @@ -243,6 +254,7 @@ impl<'a> Outlines<'a> {
glyph_id: GlyphId,
size: f32,
coords: &'a [NormalizedCoord],
#[cfg(feature = "hinting")] hint: Option<Hinting>,
pen: &mut impl Pen,
) -> Result<ScalerMetrics> {
match self {
Expand All @@ -267,7 +279,13 @@ impl<'a> Outlines<'a> {
if subfont_index != subfont.index() {
*subfont = scaler.subfont(subfont_index, size, coords)?;
}
scaler.outline(subfont, glyph_id, coords, false, pen)?;
// CFF only has a single hinting mode and FT enables it
// if any of the hinting load flags are set.
#[cfg(feature = "hinting")]
let hint = hint.is_some();
#[cfg(not(feature = "hinting"))]
let hint = false;
scaler.outline(subfont, glyph_id, coords, hint, pen)?;
// CFF does not have overlap flags and hinting never adjusts
// horizontal metrics
Ok(ScalerMetrics::default())
Expand Down

0 comments on commit 47493f7

Please sign in to comment.