-
Notifications
You must be signed in to change notification settings - Fork 20
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
maximum_color is unhappy with > 1 palette #421
Comments
hm no good. (LOL how the line just above that says To fully support this we need #422 |
That's trivial, we can maybe do that as first round |
I like the idea of doing the trivial fix first :) |
if I apply the following patch, I can get past that assertion and the subsequent code will use diff --git a/src/nanoemoji/colr_to_svg.py b/src/nanoemoji/colr_to_svg.py
index 9c514e9..4778558 100644
--- a/src/nanoemoji/colr_to_svg.py
+++ b/src/nanoemoji/colr_to_svg.py
@@ -407,7 +407,13 @@ def colr_to_svg(
rounding_ndigits: Optional[int] = None,
) -> Dict[str, SVG]:
"""For testing only, don't use for real!"""
- assert len(ttfont["CPAL"].palettes) == 1, "We assume one palette"
+ num_palettes = len(ttfont["CPAL"].palettes)
+ if num_palettes > 1:
+ logging.warning(
+ "Multiple CPAL palettes are not supported! Only using the first"
+ )
+ elif num_palettes < 1:
+ raise ValueError("No CPAL palettes found, at least one required")
colr_version = ttfont["COLR"].version
if colr_version == 0: But... then I hit a new assertion error because some glyphs have zero advance width (which is normal and expected for glyphs used as combining marks).
I forgot why we do that, but we should support converting glyphs with 0 advance somehow |
there's at least 3 places that assert that width be 0 in the code that converts COLR => SVG
|
if I comment-out all three of those Now, I'll see whether the 0-width glyphs display correctly, and most importantly why those assertions are there in the first place. |
hm, it looks like we had removed a similar assertion about width==0 in #412 in that conversation, it appeared these asserts have something to do with bitmap conversion..
|
Would be nice to summon @khaledhosny to confirm that we haven't crippled his Arabic font. 066E ARABIC LETTER DOTLESS BEH $ hb-shape /tmp/reemkufiink/Font.ttf --unicodes=066E,062D This is how the COLRv1 looks in Chrome 103 on macOS: And the OT-SVG font (as converted by maximum_color tool after removing the above-mentioned assertions) appears like this in FireFox 102 (Safari 15.5 also using OT-SVG table appears the same as FireFox) I don't know Arabic, so I can't tell which one is the correct one (even though "visually" the second one [FireFox & Safari's] looks better to me as the letter shapes don't overlap but again I'm not arabic expert) |
The COLRv1 rendering is the correct one, the two glyphs should be attached. The font does not use cursive anchors to attach the two glyphs, but relied on the |
@khaledhosny thanks for confirming! |
Ha! After commenting out another couple of lines I can make the ReemKufiInk OT-SVG work with the 0-width glyphs: diff --git a/src/nanoemoji/colr_to_svg.py b/src/nanoemoji/colr_to_svg.py
index 9c514e9..903fe9c 100644
--- a/src/nanoemoji/colr_to_svg.py
+++ b/src/nanoemoji/colr_to_svg.py
@@ -312,8 +312,8 @@ def glyph_region(ttfont: ttLib.TTFont, glyph_name: str) -> Rect:
map_font_space_to_viewbox handles font +y goes up => svg +y goes down."""
width = ttfont["hmtx"][glyph_name][0]
- if width == 0:
- width = ttfont["glyf"][glyph_name].xMax
+ # if width == 0:
+ # width = ttfont["glyf"][glyph_name].xMax
return Rect(
0,
-ttfont["OS/2"].sTypoAscender, it now looks correct both in FireFox and Safari (the latter shown below) I think all these hacks were put in place in order to be able to not chop off CBDT glyphs when we rasterize SVG=>PNG (this bug basically #402) We should either get rid of them of put them behind a flag somehow |
attempting to
Yet one more reason to get rid of those lines. The error is probably because the glyph is not only 0-width but also has 0 contours (it's a whitespace glyph), so has no bounding box attributes Conversion works after #423 |
this will make zero-width glyphs disappear when rasterized via resvg to PNG, because anything outside viewbox gets clipped (#402). Thus, running maximum_color --bitmaps with a font that has such zero-width glyphs will produce invisible empty CBDT/sbix glyphs until that issue is resolved. However, removing this assertions allows us to support zero-width glyphs in vector color formats like OT-SVG/COLR (cf. #421)
I suggest we go on and merge those two PRs, cut a release and use the updated nanoemoji to onboard the COLRv1 fonts |
In a clone of google/fonts:
This is far less helpful than building a functional font with only one - presumably the first - palette.
The text was updated successfully, but these errors were encountered: