unified-font-object / ufoNormalizer

A tool that will normalize the XML and other data inside of a UFO.
Other
51 stars 19 forks source link

Non ascii character in glyph name or lib #63

Closed typoman closed 5 years ago

typoman commented 5 years ago

I get this error when a glyph name has a non ASCII character or the glyph lib has a key with string with a non ASCII character.

Normalizing "Untitled.ufo".
Traceback (most recent call last):
  File "/usr/local/bin/ufonormalizer", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/site-packages/ufonormalizer.py", line 84, in main
    floatPrecision=floatPrecision, writeModTimes=writeModTimes)
  File "/usr/local/lib/python2.7/site-packages/ufonormalizer.py", line 217, in normalizeUFO
    layerReferencedImages = normalizeGlyphsDirectory(ufoPath, layerDirectory, onlyModified=onlyModified, writeModTimes=writeModTimes)
  File "/usr/local/lib/python2.7/site-packages/ufonormalizer.py", line 320, in normalizeGlyphsDirectory
    imageFileName = normalizeGLIF(ufoPath, layerDirectory, fileName)
  File "/usr/local/lib/python2.7/site-packages/ufonormalizer.py", line 627, in normalizeGLIF
    normalizedText = normalizeGLIFString(text, glifPath, imageFileRef)
  File "/usr/local/lib/python2.7/site-packages/ufonormalizer.py", line 543, in normalizeGLIFString
    tree = ET.fromstring(text)
  File "<string>", line 124, in XML
UnicodeEncodeError: 'ascii' codec can't encode character u'\u0634' in position 383: ordinal not in range(128)

The glyph contents for non ASCII string.

<?xml version="1.0" encoding="UTF-8"?>
<glyph name="space" format="2">
    <unicode hex="0020"/>
    <advance width="500"/>
    <outline>
        <contour>
            <point x="134" y="235" type="line"/>
        </contour>
    </outline>
    <lib>
        <dict>
            <key>test</key>
            <string>ش</string>
        </dict>
    </lib>
</glyph>

I also saved the file in UTF-8 encoding. Am I mistaken or this should be allowed in UFO according to the spec?

justvanrossum commented 5 years ago

Can you try with Python 3?

typoman commented 5 years ago

Yes, it worked! I had to uninstall and reinstall it. Thank you Just!