From 18613c5b492f5086e3a20a66b5227b0f0785b76f Mon Sep 17 00:00:00 2001 From: Prasanna Gunuru Date: Thu, 29 Jun 2023 12:43:43 -0700 Subject: [PATCH 1/2] Added standard_viewbox_width property to config file to support fixed and zero/proportional width --- src/nanoemoji/color_glyph.py | 6 +++++- src/nanoemoji/config.py | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/nanoemoji/color_glyph.py b/src/nanoemoji/color_glyph.py index 5d73222b..56fd9cd0 100644 --- a/src/nanoemoji/color_glyph.py +++ b/src/nanoemoji/color_glyph.py @@ -353,7 +353,11 @@ def _advance_width(view_box: Rect, config: FontConfig) -> int: # Scale advance width proportionally to viewbox aspect ratio. # Use the default advance width if it's larger than the proportional one. font_height = config.ascender - config.descender # descender <= 0 - return max(config.width, round(font_height * view_box.w / view_box.h)) + + # If the viewbox width is lower than standard viewbox width(32), then use the zero advance width to get proportional scaling. + width = 0 if view_box.w < config.standard_viewbox_width else config.width + return max(width, round(font_height * view_box.w / view_box.h)) + def _mutating_traverse(paint, mutator): diff --git a/src/nanoemoji/config.py b/src/nanoemoji/config.py index a44d22a4..fec89603 100644 --- a/src/nanoemoji/config.py +++ b/src/nanoemoji/config.py @@ -54,6 +54,7 @@ # CLI flags override config file (which overrides default FontConfig). flags.DEFINE_integer("upem", None, "Units per em.") flags.DEFINE_integer("width", None, "Width.") +flags.DEFINE_integer("standard_viewbox_width", None, "viewBox width of the majority input SVGs.") flags.DEFINE_integer("ascender", None, "Ascender") flags.DEFINE_integer("descender", None, "Descender.") flags.DEFINE_integer("linegap", None, "Line gap.") @@ -152,6 +153,7 @@ class FontConfig(NamedTuple): # metrics default based on Noto Emoji upem: int = 1024 width: int = 1275 + standard_viewbox_width: int = 32 ascender: int = 950 descender: int = -250 linegap: int = 0 @@ -214,6 +216,7 @@ def validate(self): for attr_name in ( "upem", "width", + "standard_viewbox_width", "ascender", "linegap", "version_major", @@ -268,6 +271,7 @@ def write(dest: Path, config: FontConfig): "color_format": config.color_format, "upem": config.upem, "width": config.width, + "standard_viewbox_width": config.standard_viewbox_width, "ascender": config.ascender, "descender": config.descender, "linegap": config.linegap, @@ -356,6 +360,7 @@ def load( color_format = _pop_flag(config, "color_format") upem = int(_pop_flag(config, "upem")) width = int(_pop_flag(config, "width")) + standard_viewbox_width = int(_pop_flag(config, "standard_viewbox_width")) ascender = int(_pop_flag(config, "ascender")) descender = int(_pop_flag(config, "descender")) linegap = int(_pop_flag(config, "linegap")) @@ -441,6 +446,7 @@ def load( color_format=color_format, upem=upem, width=width, + standard_viewbox_width=standard_viewbox_width, ascender=ascender, descender=descender, linegap=linegap, From b62580f417ea78edb9b510f2e65beabde129f94d Mon Sep 17 00:00:00 2001 From: Prasanna Gunuru Date: Thu, 29 Jun 2023 12:46:08 -0700 Subject: [PATCH 2/2] removing extra space --- src/nanoemoji/color_glyph.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/nanoemoji/color_glyph.py b/src/nanoemoji/color_glyph.py index 56fd9cd0..a7702ff9 100644 --- a/src/nanoemoji/color_glyph.py +++ b/src/nanoemoji/color_glyph.py @@ -359,7 +359,6 @@ def _advance_width(view_box: Rect, config: FontConfig) -> int: return max(width, round(font_height * view_box.w / view_box.h)) - def _mutating_traverse(paint, mutator): paint = mutator(paint) assert paint is not None, "Return the input for no change, not None"