Skip to content

Commit

Permalink
write_font_test: test colored .notdef with --color_format=picosvg
Browse files Browse the repository at this point in the history
  • Loading branch information
anthrotype committed Sep 1, 2022
1 parent 6289f0e commit e962001
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
14 changes: 14 additions & 0 deletions tests/colored_notdef.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion tests/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def color_font_config(
svgs,
tmp_dir=None,
codepoint_fn=lambda svg_file, idx: (0xE000 + idx,),
glyphname_fn=None,
):
if tmp_dir is None:
tmp_dir = Path(tempfile.gettempdir())
Expand Down Expand Up @@ -118,14 +119,19 @@ def color_font_config(
for svg in svgs
]

if glyphname_fn is None:

def glyphname_fn(svg_file, idx):
return glyph_name(codepoint_fn(svg_file, idx))

return (
font_config,
[
write_font.InputGlyph(
svg_file,
bitmap_file,
codepoint_fn(svg_file, idx),
glyph_name(codepoint_fn(svg_file, idx)),
glyphname_fn(svg_file, idx),
svg,
bitmap,
)
Expand Down
30 changes: 30 additions & 0 deletions tests/write_font_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,3 +589,33 @@ def test_square_varied_hmetrics():
assert (
glyph_widths[i] * 2 == glyph_widths[i + 1]
), f"n+1 should double, fails at {i}; {glyph_widths}"


def test_picosvg_colored_notdef():
# https://github.com/googlefonts/nanoemoji/issues/427
svgs = [
("colored_notdef.svg", ".notdef", []),
("emoji_u42.svg", "B", [0x42]),
]
svg_files = [s[0] for s in svgs]

config, glyph_inputs = test_helper.color_font_config(
{"color_format": "picosvg", "pretty_print": True},
svg_files,
glyphname_fn=lambda svg_file, idx: svgs[idx][1],
codepoint_fn=lambda svg_file, idx: svgs[idx][2],
)
_, ttfont = write_font._generate_color_font(config, glyph_inputs)
ttfont = test_helper.reload_font(ttfont)

# check .notdef glyph is still the first glyph and that space character
# follows it and has its codepoint assigned in cmap
assert ttfont.getGlyphOrder() == [".notdef", ".space", "B"]
assert ttfont["cmap"].getBestCmap() == {0x20: ".space", 0x42: "B"}

# check that SVG table contains a .notdef glyph as first GID
assert len(ttfont["SVG "].docList) == 2
assert ttfont["SVG "].docList[0].startGlyphID == 0
assert ttfont["SVG "].docList[0].startGlyphID == 0
assert ttfont["SVG "].docList[1].endGlyphID == 2
assert ttfont["SVG "].docList[1].endGlyphID == 2

0 comments on commit e962001

Please sign in to comment.