简体   繁体   中英

Weird symbols when exporting SVG to EPS using Inkscape

I'm trying to convert a SVG image to a EPS file using the Inkscape command line. This is the command I run (from a Python script) to do the conversion:

bashCommand = "inkscape " + file + " -D --without-gui --export-eps=exports/" + type + ".eps"
process = subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE)
output, error = process.communicate()

The file is generated and when it opens most of it seems to be as expected. The problem is that some of the text won't show up (see screenshot below). Instead there are weird rectangular symbols. Most of the missing text doesn't have special characters. I really have no clue what can cause this problem.

在此处输入图片说明

This is the error I see when printing the error variable:

(process:1855): Gtk-WARNING **: Locale not supported by C library.
Using the fallback 'C' locale.
Fontconfig warning: ignoring UTF-8: not a valid region tag 

In /etc/default/locale I've tried to add the following (I came across this possible fix while I was looking for a solution):

LANG="en_US.UTF-8"
LANGUAGE="en_US.UTF-8"
LC_ALL="en_US.UTF-8"

Then I reconfigured the locales using sudo dpkg-reconfigure locales

This is the output I get when using the locale command:

LANG=en_US.UTF-8
LANGUAGE=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8

I'm using Open Sans as font and installed the font on the server as well. After adding the fonts to /usr/local/share/fonts I rebuild the font cache with the fc-cache -f -v command.

When converting the SVG to a PDF with the code below, everything works as expected. All text is visible and the Open Sans font is used.

bashCommand = "inkscape " + file + " -D -d 300 --without-gui --export-pdf=exports/" + type + ".pdf"
process = subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE)
output, error = process.communicate()

This is what the PDF looks like:

在此处输入图片说明

I've been searching the internet for a while to find a solution, but I couldn't find one so far.

I'm working with a Ubuntu 16.04 server. I got Inkscape 0.91 installed.

Does anyone know how to get the text right? And why is the text converted to these symbols (first screenshot)? Hope someone can help!

I can only tell you part of what's going on. The 'weird rectangular characters' are TrueType .notdef glyphs. When you use a font, it does not contain every possible glyph in every written language known to man. In addition, in PostScript regular fotns (as opposed to CIDFonts) can only access 255 different glyphs at a time.

So to cater for the case where you try to use a glyph that the font doesn't have a copy of, fonts are supposed to contain a .notdef glyph, and thsat's what gets used whenever you try to use a glyph which is missing. In general PostScript fonts define a .notdef which makes no marks, and TrueType fonts define one which makes a hollow rectangle. There are other possibilities, but these are the most common.

So why are you getting .notdef ? Well that seems likely too be caused (in some sense) by the error message from gtk about the locale not being supported, and ignoring UTF-8.

gtk needs to remap the character codes of the text into 'something' which will work with the embedded fonts, and it seems that it doesn't know how to deal with UTF-8 encoded text, so it falls back to pretending its 'C' which is basically US ASCII I think.

Unfortunately, I can't tell you how ti fix this, I don't know enough about the front-end, but this doesn't look to me like its an actual 'EPS' problem, the problem lies in the application generating the EPS, and possibly with gtk in particular.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM