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

layerize.js doesn't correctly handle color keywords (such as azure) #3

Open
SimonBrandner opened this issue Mar 23, 2022 · 2 comments

Comments

@SimonBrandner
Copy link

In twitter/twemoji@36bac69 the image 1faa9.svg contains azure as a colo. When the script runs, it generates a ttx file with azureff (azure as a color + ff as the alpha) somewhere in it, which then leads to the script failing with:

❯ make
node layerize.js twe-svg.zip overrides extras build Twemoji\ Mozilla
(node:193444) Warning: Accessing non-existent property 'Reader' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
(node:193444) Warning: Accessing non-existent property 'Reader' of module exports inside circular dependency
found mis-named 1f441-200d-1f5e8, renamed to 1f441-fe0f-200d-1f5e8-fe0f
found mis-named keycap 37-20e3, renamed to 37-fe0f-20e3
found mis-named keycap 30-20e3, renamed to 30-fe0f-20e3
found mis-named keycap 38-20e3, renamed to 38-fe0f-20e3
found mis-named keycap 2a-20e3, renamed to 2a-fe0f-20e3
found mis-named keycap 35-20e3, renamed to 35-fe0f-20e3
found mis-named keycap 23-20e3, renamed to 23-fe0f-20e3
found mis-named keycap 31-20e3, renamed to 31-fe0f-20e3
found mis-named keycap 36-20e3, renamed to 36-fe0f-20e3
found mis-named keycap 32-20e3, renamed to 32-fe0f-20e3
found mis-named keycap 34-20e3, renamed to 34-fe0f-20e3
found mis-named keycap 33-20e3, renamed to 33-fe0f-20e3
found mis-named keycap 39-20e3, renamed to 39-fe0f-20e3
overriding 1f1fa-1f1f3.svg with local copy
npm run grunt webfont

> [email protected] grunt
> grunt "webfont"

(node:193518) V8: /home/simon/GIT/Matrix/twemoji-colr/node_modules/ttf2woff2/jssrc/ttf2woff2.js:3 Invalid asm.js: Invalid member of stdlib
(Use `node --trace-warnings ...` to show where the warning was created)
Running "webfont:Twemoji" (webfont) task
Font Twemoji Mozilla with 13720 glyphs created.

Done.
rm -f build/Twemoji\ Mozilla.ttf
# remove illegal <space> from the PostScript name in the font
ttx -t name -o build/raw-font/Twemoji\ Mozilla.ttf.names build/raw-font/Twemoji\ Mozilla.ttf
Dumping "build/raw-font/Twemoji Mozilla.ttf" to "build/raw-font/Twemoji Mozilla.ttf.names"...
Dumping 'name' table...
perl -i -e 'my $ps = 0;' \
        -e 'while(<>) {' \
        -e '  $ps = 1 if m/nameID="6"/;' \
        -e '  $ps = 0 if m|</namerecord>|;' \
        -e '  s/Twemoji Mozilla/TwemojiMozilla/ if $ps;' \
        -e '  print;' \
        -e '}' build/raw-font/Twemoji\ Mozilla.ttf.names
ttx -m build/raw-font/Twemoji\ Mozilla.ttf -o build/raw-font/Twemoji\ Mozilla.ttf.renamed.ttf build/raw-font/Twemoji\ Mozilla.ttf.names
Compiling "build/raw-font/Twemoji Mozilla.ttf.names" to "build/raw-font/Twemoji Mozilla.ttf.renamed.ttf"...
Parsing 'name' table...
python fixDirection.py build/raw-font/Twemoji\ Mozilla.ttf.renamed.ttf
ttx -m build/raw-font/Twemoji\ Mozilla.ttf.renamed.ttf -o build/Twemoji\ Mozilla.ttf build/Twemoji\ Mozilla.ttx
Compiling "build/Twemoji Mozilla.ttx" to "build/Twemoji Mozilla.ttf"...
Parsing 'COLR' table...
Parsing 'CPAL' table...
ERROR: Unhandled exception has occurred
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/fontTools/ttx.py", line 405, in main
    process(jobs, options)
  File "/usr/lib/python3/dist-packages/fontTools/ttx.py", line 387, in process
    action(input, output, options)
  File "/usr/lib/python3/dist-packages/fontTools/misc/loggingTools.py", line 372, in wrapper
    return func(*args, **kwds)
  File "/usr/lib/python3/dist-packages/fontTools/ttx.py", line 298, in ttCompile
    ttf.importXML(input)
  File "/usr/lib/python3/dist-packages/fontTools/ttLib/ttFont.py", line 345, in importXML
    reader.read()
  File "/usr/lib/python3/dist-packages/fontTools/misc/xmlReader.py", line 47, in read
    self._parseFile(self.file)
  File "/usr/lib/python3/dist-packages/fontTools/misc/xmlReader.py", line 72, in _parseFile
    parser.Parse(chunk, 0)
  File "../Modules/pyexpat.c", line 459, in EndElement
  File "/usr/lib/python3/dist-packages/fontTools/misc/xmlReader.py", line 155, in _endElementHandler
    self.currentTable.fromXML(name, attrs, content, self.ttFont)
  File "/usr/lib/python3/dist-packages/fontTools/ttLib/tables/C_P_A_L_.py", line 213, in fromXML
    color = Color.fromHex(attrs["value"])
  File "/usr/lib/python3/dist-packages/fontTools/ttLib/tables/C_P_A_L_.py", line 252, in fromHex
    red = int(value[0:2], 16)
ValueError: invalid literal for int() with base 16: 'az'
make: *** [Makefile:31: build/Twemoji Mozilla.ttf] Error 1

@SimonBrandner
Copy link
Author

The non-proper way to fix this is to search for the file that contains the color keyword (grep -iRl "azure" svg) and replace it with a hex value

@SimonBrandner
Copy link
Author

Related twitter/twemoji#537

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant