Skip to content

Commit

Permalink
Don't add empty glyphs without painted layers to COLR or SVG table
Browse files Browse the repository at this point in the history
  • Loading branch information
anthrotype committed Nov 9, 2021
1 parent 744813c commit a9b0746
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/nanoemoji/svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,8 @@ def _picosvg_docs(
svg = SVG(root)

for color_glyph in (color_glyphs[g] for g in group):
_add_glyph(svg, color_glyph, reuse_cache)
if color_glyph.painted_layers:
_add_glyph(svg, color_glyph, reuse_cache)

# tidy use elements, they may emerge from _add_glyph with unnecessary attributes
_tidy_use_elements(svg)
Expand All @@ -664,6 +665,9 @@ def _picosvg_docs(
if len(defs) == 0:
root.remove(defs)

if len(root) == 0:
continue

gids = tuple(color_glyphs[g].glyph_id for g in group)
doc_list.append(
(svg.tostring(pretty_print=config.pretty_print), min(gids), max(gids))
Expand Down
9 changes: 5 additions & 4 deletions src/nanoemoji/write_font.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,10 +592,11 @@ def _colr_ufo(
color_glyph, glyph_cache
)

# write out the ufo structures for COLR
ufo_color_layers[color_glyph.glyph_name] = _ufo_colr_layers(
colr_version, colors, color_glyph
)
if color_glyph.painted_layers:
# write out the ufo structures for COLR
ufo_color_layers[color_glyph.glyph_name] = _ufo_colr_layers(
colr_version, colors, color_glyph
)
bounds = _bounds(color_glyph, quantization)
if bounds is not None:
clipBoxes.setdefault(bounds, []).append(color_glyph.glyph_name)
Expand Down
1 change: 1 addition & 0 deletions tests/emoji_u200c.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions tests/nanoemoji_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,26 @@ def test_glyphmap_games():
assert_expected_ttx(
svgs, font, "glyphmap_games.ttx", include_tables=["GlyphOrder", "cmap"]
)


def test_omit_empty_color_glyphs():
svgs = [
"emoji_u200c.svg", # whitespace glyph, contains no paths
"emoji_u42.svg",
]

tmp_dir = _run(
(
"--color_format=glyf_colr_1_and_picosvgz",
"--keep_glyph_names",
*(locate_test_file(svg) for svg in svgs),
)
)

font = TTFont(tmp_dir / "Font.ttf")

colr = font["COLR"].table
assert len(colr.BaseGlyphList.BaseGlyphPaintRecord) == 1

svg = font["SVG "]
assert len(svg.docList) == 1

0 comments on commit a9b0746

Please sign in to comment.