Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose and fix bug when counting limits of repeatedly referenced components #1023

Merged
merged 1 commit into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
19 changes: 18 additions & 1 deletion fontc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1916,7 +1916,7 @@ mod tests {

#[test]
fn maxp_with_shallow_components() {
assert_maxp_composite("glyphs2/Component.glyphs", 1, 4, 1);
assert_maxp_composite("glyphs2/Component.glyphs", 1, 8, 2);
}

#[test]
Expand Down 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;
}
Loading