Skip to content

Preserve unicode text elements with CallExtensions

Benjamin Nanes requested to merge bnanes/inkscape-extensions:master into master

Running a CallExtension on an Inkscape document containing text elements with non-ASCII characters disrupts the text element contents when the system default encoding in not UTF-8. I think this is caused by the way the extension temporary output file is loaded in inkex/extensions.py lines 125-128. Specifically, the text stream is opened using system default encoding, but parsed using UTF-8 encoding:

       if self.output_ext == 'svg':
                with open(document, 'r') as fhl:
                    document = fhl.read()
                if '<' in document:
                    document = load_svg(document.encode('utf-8'))

Specifying UTF-8 encoding when opening the stream corrects the problem:

            if self.output_ext == 'svg':
                with open(document, 'r', encoding='utf-8') as fhl:
                    document = fhl.read()
                if '<' in document:
                    document = load_svg(document.encode('utf-8'))

Merge request reports