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

color_glyph: remove assertion that width > 0 #412

Merged
merged 2 commits into from
Apr 28, 2022
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
3 changes: 0 additions & 3 deletions src/nanoemoji/color_glyph.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,6 @@ def create(
base_glyph.width = _advance_width(view_box, font_config)
else:
base_glyph.width = font_config.width
assert (
base_glyph.width > 0
), f"0 width for {ufo_glyph_name} (svg {svg_filename}, bitmap {bitmap_filename})"

# Setup direct access to the glyph if possible
if len(codepoints) == 1:
Expand Down
48 changes: 48 additions & 0 deletions tests/nanoemoji_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from fontTools.ttLib.tables import otTables as ot
from lxml import etree # pytype: disable=import-error
from nanoemoji import config
from nanoemoji.glyph import glyph_name
import operator
import os
from pathlib import Path
Expand Down Expand Up @@ -368,3 +369,50 @@ def test_input_symlinks_support(tmp_path):
assert len(ligatures["f"]) == 1
assert ligatures["f"][0].Component == ["i"]
assert ligatures["f"][0].LigGlyph == "f_i"


@pytest.mark.parametrize(
"color_format",
[
"glyf_colr_1",
"picosvg",
# TODO: This is disabled because CBDT currently forces width=0 to xMax
# https://github.com/googlefonts/nanoemoji/issues/404
# "cbdt",
],
)
def test_glyph_with_zero_advance_width(color_format, tmp_path):
cp = 0x0301
gname = glyph_name(cp)
acutecomb_svg = locate_test_file(f"u{cp:04x}.svg")

assert SVG.parse(acutecomb_svg).view_box() == (0, 0, 0, 1200)

run_nanoemoji(
(
acutecomb_svg,
"--width=0",
"--noclip_to_viewbox",
"--keep_glyph_names",
f"--color_format={color_format}",
),
tmp_dir=tmp_path,
)

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

if "COLR" in font:
colr = font["COLR"].table
assert len(colr.BaseGlyphList.BaseGlyphPaintRecord) == 1
assert colr.BaseGlyphList.BaseGlyphPaintRecord[0].BaseGlyph == gname
if "SVG " in font:
svg = font["SVG "]
assert len(svg.docList) == 1
gid = font.getGlyphID(gname)
assert svg.docList[0][1:] == [gid, gid] # [start, end]
if "CBDT" in font:
cbdt = font["CBDT"]
assert len(cbdt.strikeData) == 1
assert list(cbdt.strikeData[0].keys()) == [gname]

assert font["hmtx"][gname] == (0, 0)
9 changes: 9 additions & 0 deletions tests/u0301.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.