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

Flatten components: reduce log level about flags not being set #767

Merged
merged 3 commits into from
Jul 21, 2023
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
29 changes: 11 additions & 18 deletions Lib/ufo2ft/instructionCompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ def __init__(
if not autoUseMyMetrics:
# If autoUseMyMetrics is False, replace the method with a no-op
self.autoUseMyMetrics = lambda ttGlyph, glyphName: None
# Only warn--that a glyph's number of components are different in TTFont
# vs original UFO--when the USE_MY_METRICS flags are set manually, don't
# bother when automatically set:
# https://github.com/googlefonts/ufo2ft/issues/743
self.warn_if_components_mismatch = not autoUseMyMetrics

def _check_glyph_hash(
self, glyphName: str, ttglyph: TTGlyph, glyph_hash: Optional[str]
Expand Down Expand Up @@ -181,14 +176,12 @@ def _set_composite_flags(self, glyph: Glyph, ttglyph: TTGlyph) -> None:
# Set component flags

if len(ttglyph.components) != len(glyph.components):
if self.warn_if_components_mismatch:
# May happen if nested components have been flattened by a filter
logger.error(
"Number of components differ between UFO and TTF "
f"in glyph '{glyph.name}' ({len(glyph.components)} vs. "
f"{len(ttglyph.components)}, not setting component flags from"
"UFO. They may still be set heuristically."
)
# May happen if nested components have been flattened by a filter
logger.debug(
"Number of components differ between UFO and TTF "
f"in glyph '{glyph.name}' ({len(glyph.components)} vs. "
f"{len(ttglyph.components)}, not setting component flags from UFO."
)
self.autoUseMyMetrics(ttglyph, glyph.name)
return

Expand All @@ -213,10 +206,10 @@ def _set_composite_flags(self, glyph: Glyph, ttglyph: TTGlyph) -> None:
ufo_component_id = glyph.components[i].identifier
if ufo_component_id is None:
# No information about component flags is stored in the UFO.
# We don’t modify the flags. Two flags have already been set elsewhere:
# - ROUND_XY_TO_GRID is set in TTGlyphPointPen.glyph() called from
# OutlineTTFCompiler.compileGlyphs()
# - USE_MY_METRICS is set in OutlineTTFCompiler.setupTable_glyf()
# We don’t modify the flags. Two flags are being set elsewhere:
# - ROUND_XY_TO_GRID has already been set in TTGlyphPointPen.glyph()
# called from OutlineTTFCompiler.compileGlyphs()
# - USE_MY_METRICS is set automatically below if no component has it
continue

if (
Expand Down Expand Up @@ -244,7 +237,7 @@ def _set_composite_flags(self, glyph: Glyph, ttglyph: TTGlyph) -> None:
c.flags |= USE_MY_METRICS
use_my_metrics_comp = ufo_component_id
else:
logger.warning(
logger.debug(
f"Ignoring USE_MY_METRICS flag on component {i}, "
f"'{ufo_component_id}' because it has been set on "
f"component '{use_my_metrics_comp}' already "
Expand Down
8 changes: 2 additions & 6 deletions tests/instructionCompiler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,10 +570,6 @@ def test_set_composite_flags_metrics_no_id(self, quadufo, quadfont):
def test_set_composite_flags_auto_use_my_metrics_warn_if_components_mismatch(
self, quadufo, quadfont, autoUseMyMetrics, caplog
):
# check we only log error message for component number mismatch when NOT setting
# USE_MY_METRICS flags automatically (otherwise it'd be unintended noise)
do_issue_warning = not autoUseMyMetrics

ic = InstructionCompiler(quadufo, quadfont, autoUseMyMetrics=autoUseMyMetrics)
name = "h"

Expand All @@ -583,10 +579,10 @@ def test_set_composite_flags_auto_use_my_metrics_warn_if_components_mismatch(
glyph.clearComponents() # to produce an artificial len(components) mismatch
assert len(glyph.components) != len(ttglyph.components)

with caplog.at_level(logging.ERROR, logger="ufo2ft.instructionCompiler"):
with caplog.at_level(logging.DEBUG, logger="ufo2ft.instructionCompiler"):
ic._set_composite_flags(glyph=glyph, ttglyph=ttglyph)

assert ("Number of components differ" in caplog.text) is do_issue_warning
assert "Number of components differ" in caplog.text

# update_maxp

Expand Down
Loading