Skip to content

Commit

Permalink
Expose and fix bug when counting limits of repeatedly referenced comp…
Browse files Browse the repository at this point in the history
…onents
  • Loading branch information
rsheeter committed Oct 11, 2024
1 parent a18c3bd commit cd6311a
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 4 deletions.
10 changes: 6 additions & 4 deletions fontbe/src/metrics_and_limits.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//! Generates the [hmtx](https://learn.microsoft.com/en-us/typography/opentype/spec/hmtx) and
//! [hhea](https://learn.microsoft.com/en-us/typography/opentype/spec/hhea) tables
//! Generates the [hmtx](https://learn.microsoft.com/en-us/typography/opentype/spec/hmtx),
//! [hhea](https://learn.microsoft.com/en-us/typography/opentype/spec/hhea), and
//! [maxp](https://learn.microsoft.com/en-us/typography/opentype/spec/maxp) tables

use std::{
cmp::{max, min},
collections::{HashMap, HashSet},
collections::HashMap,
};

use fontdrasil::orchestration::{Access, AccessBuilder, Work};
Expand Down Expand Up @@ -51,7 +52,7 @@ struct FontLimits {
struct GlyphInfo {
/// For simple glyphs always present. For composites, set by [`FontLimits::update_composite_limits`]
limits: Option<GlyphLimits>,
components: Option<HashSet<GlyphId16>>,
components: Option<Vec<GlyphId16>>,
}

impl GlyphInfo {
Expand Down Expand Up @@ -138,6 +139,7 @@ impl FontLimits {
self.glyph_info.insert(id, glyph_info);
}

// FontTools maxp <https://github.com/fonttools/fonttools/blob/e8146a6d0725d398cfa110cba683946ee762f8e2/Lib/fontTools/ttLib/tables/_m_a_x_p.py#L53>
fn update_composite_limits(&mut self) -> GlyphLimits {
let mut pending = self
.glyph_info
Expand Down
17 changes: 17 additions & 0 deletions fontc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3155,4 +3155,21 @@ mod tests {
"Should have no font specific names, got {font_specific_names:?}"
);
}

// <https://github.com/googlefonts/fontc/issues/1022>
// We used to mistakenly only count repeat use of the same component once
#[test]
fn duplicate_components_count_in_maxp() {
let compile = TestCompile::compile_source("glyphs3/PixelRef.glyphs");
let font = compile.font();
let maxp = font.maxp().unwrap();
// 3 uses of the "pixel" component which has 4 points
assert_eq!(
(12, 3),
(
maxp.max_composite_points().unwrap(),
maxp.max_composite_contours().unwrap()
)
);
}
}
76 changes: 76 additions & 0 deletions resources/testdata/glyphs3/PixelRef.glyphs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
.formatVersion = 3;
familyName = WghtVar;
fontMaster = (
{
id = m01;
name = Regular;
}
);
glyphs = (
{
glyphname = space;
layers = (
{
layerId = m01;
width = 200;
}
);
unicode = 32;
},
{
glyphname = pixel;
layers = (
{
layerId = m01;
shapes = (
{
closed = 1;
nodes = (
(30,0,l),
(0,0,l),
(0,30,l),
(30,30,l)
);
}
);
width = 30;
}
);
},
{
glyphname = hyphen;
layers = (
{
layerId = m01;
shapes = (
{
alignment = -1;
pos = (60,420);
ref = pixel;
},
{
alignment = -1;
pos = (90,420);
ref = pixel;
},
{
alignment = -1;
pos = (120,420);
ref = pixel;
}
);
width = 570;
}
);
unicode = 45;
}
);

settings = {
gridLength = 30;
};
unitsPerEm = 1230;
versionMajor = 1;
versionMinor = 0;
}

0 comments on commit cd6311a

Please sign in to comment.