Convert Glyph Layers to SVG Font: Traceback when font includes apostrophe (single-quote) glyph.
Steps to reproduce:
- open Inkscape
- Select Extensions > Typography > 1 - Setup Typography Canvas
- Select Extensions > Typography > 2 - Add Glyph Layer
- Enter
'
as the unicode character; click Apply. - Select Extensions > Typography > 3 - Convert Glyph Layers to SVG Font
OR
- open Inkscape
- Open an existing SVG font document that contains a glyph for
'
(sometimes encoded as'
). For example,svg_fonts/HersheySans1.svg
or the SVG version of Relief SingleLine. - Select Extensions > Typography > Convert SVG Font to Glyph Layers
- Select Extensions > Typography > 3 - Convert Glyph Layers to SVG Font
What happened?
Traceback:
Traceback (most recent call last):
File "/Applications/Inkscape.app/Contents/Resources/share/inkscape/extensions/layers2svgfont.py", line 102, in <module>
LayersToSvgFont().run()
File "/Applications/Inkscape.app/Contents/Resources/share/inkscape/extensions/inkex/base.py", line 231, in run
self.save_raw(self.effect())
File "/Applications/Inkscape.app/Contents/Resources/share/inkscape/extensions/layers2svgfont.py", line 68, in effect
glyph = font.get_or_create(
File "/Applications/Inkscape.app/Contents/Resources/share/inkscape/extensions/inkex/elements/_base.py", line 361, in get_or_create
node = self.findone(xpath)
File "/Applications/Inkscape.app/Contents/Resources/share/inkscape/extensions/inkex/elements/_base.py", line 445, in findone
el_list = self.xpath(xpath)
File "/Applications/Inkscape.app/Contents/Resources/share/inkscape/extensions/inkex/elements/_base.py", line 435, in xpath
return super().xpath(pattern, namespaces=namespaces)
File "src/lxml/etree.pyx", line 1597, in lxml.etree._Element.xpath
File "src/lxml/xpath.pxi", line 305, in lxml.etree.XPathElementEvaluator.__call__
File "src/lxml/xpath.pxi", line 225, in lxml.etree._XPathEvaluatorBase._handle_result
lxml.etree.XPathEvalError: Invalid predicate
What should have happened?
The extension should operate (without producing a traceback).
Inkscape Version and Operating System:
- Inkscape Version: Inkscape 1.2 (dc2aeda, 2022-05-15), with latest extensions from master.
- Operating System: macOS Monterey
- Operating System version: 12.3.1
Root cause and solution:
The relevant code in layers2svgfont.py
reads as follows:
"svg:glyph[@unicode='{}']".format(unicode_char)
When the value of unicode_char
is '
, this reduces to "svg:glyph[@unicode=''']" which is problematic.
I'll follow up with a merge request shortly.