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

Don't generate GDEF when already in Glyphs file #740

Closed
wants to merge 2 commits into from
Closed
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
9 changes: 9 additions & 0 deletions Lib/fontmake/font_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import logging
import math
import os
import re
import shutil
import tempfile
from collections import OrderedDict
Expand Down Expand Up @@ -164,12 +165,20 @@ def build_master_ufos(
instance_dir = os.path.relpath(instance_dir, designspace_dir)
assert not os.path.isabs(instance_dir)

# https://github.com/googlefonts/fontmake/issues/702
generate_GDEF = True
for fea in font.featurePrefixes:
if re.search(r"^\s*table\s+GDEF\s+{", fea.code, flags=re.MULTILINE):
generate_GDEF = False
break

designspace = glyphsLib.to_designspace(
font,
family_name=family_name,
instance_dir=instance_dir,
write_skipexportglyphs=write_skipexportglyphs,
ufo_module=ufoLib2,
generate_GDEF=generate_GDEF,
)

masters = {}
Expand Down
133 changes: 133 additions & 0 deletions tests/data/GDEFPresent.glyphs
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{
.appVersion = "1354";
classes = (
{
automatic = 1;
code = A;
name = Uppercase;
}
);
customParameters = (
{
name = "Use Line Breaks";
value = 1;
}
);
date = "2021-02-25 11:04:52 +0000";
familyName = GDEFPresent;
featurePrefixes = (
{
code = "table GDEF {
GlyphClassDef [A], , , ;
} GDEF;
";
name = Prefix;
}
);
features = (
{
automatic = 1;
code = "pos @Uppercase <5 0 10 0>;
";
name = cpsp;
}
);
fontMaster = (
{
ascender = 800;
capHeight = 700;
descender = -200;
id = "A82E8779-E9D6-4341-BA1A-AF1FA001C07D";
xHeight = 500;
}
);
glyphs = (
{
glyphname = A;
lastChange = "2021-02-25 11:11:10 +0000";
layers = (
{
anchors = (
{
name = top;
position = "{300, 700}";
}
);
layerId = "A82E8779-E9D6-4341-BA1A-AF1FA001C07D";
paths = (
{
closed = 1;
nodes = (
"60 0 LINE",
"540 0 LINE",
"540 700 LINE",
"60 700 LINE"
);
}
);
width = 600;
}
);
unicode = 0041;
},
{
glyphname = B;
lastChange = "2021-02-25 11:20:00 +0000";
layers = (
{
anchors = (
{
name = top;
position = "{300, 700}";
}
);
layerId = "A82E8779-E9D6-4341-BA1A-AF1FA001C07D";
paths = (
{
closed = 1;
nodes = (
"60 0 LINE",
"540 0 LINE",
"540 700 LINE",
"60 700 LINE"
);
}
);
width = 600;
}
);
unicode = 0042;
},
{
glyphname = acutecomb;
lastChange = "2021-02-25 11:12:05 +0000";
layers = (
{
anchors = (
{
name = _top;
position = "{300, 621}";
}
);
layerId = "A82E8779-E9D6-4341-BA1A-AF1FA001C07D";
paths = (
{
closed = 1;
nodes = (
"60 621 LINE",
"540 621 LINE",
"540 700 LINE",
"60 700 LINE"
);
}
);
width = 600;
}
);
unicode = 0301;
}
);
unitsPerEm = 1000;
versionMajor = 1;
versionMinor = 0;
}
25 changes: 25 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,3 +657,28 @@ def test_static_otf_cffsubr_subroutinizer(data_dir, tmp_path):
)

assert {p.name for p in tmp_path.glob("*.otf")} == {"MyFont-Light.otf"}


def test_GDEF_in_glyphs_features(data_dir, tmp_path):
shutil.copyfile(data_dir / "GDEFPresent.glyphs", tmp_path / "GDEFPresent.glyphs")

output_dir = tmp_path / "master_ttf"
fontmake.__main__.main(
[
"-g",
str(tmp_path / "GDEFPresent.glyphs"),
"--output-dir",
str(output_dir),
"-o",
"ttf",
]
)

assert {p.name for p in output_dir.glob("*.*")} == {
"GDEFPresent-Regular.ttf",
}

test_output_ttf = fontTools.ttLib.TTFont(output_dir / "GDEFPresent-Regular.ttf")
assert "GDEF" in test_output_ttf
gdef = test_output_ttf["GDEF"].table
assert gdef.GlyphClassDef.classDefs == {"A": 1}