Message Boards Message Boards

0
|
9462 Views
|
13 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Avoid problem when importing of EPS-Graphics with text?

Posted 5 years ago

The following works fine:

Graphics[Disk[]]
Export["image.eps", %];
Import["image.eps"]

But if there is some text in the image, its not possible to import anymore (mathematica keeps running and cannont be abortet):

Graphics[Text["A", {0, 0}]]
Export["image.eps", %];
Import["image.eps"]

Other formats works fine (as far as I tested), the problem is only with "eps". Are there some options to solve this problem?

POSTED BY: Juerg Baertsch
13 Replies

I understand that ghostscript can convert texts fonts to outlines with the option -dNoOutputFonts. You may run that before importing into Mathematica.

POSTED BY: Gianluca Gorni
Posted 5 years ago

That would probably work, but in a way that is a manual version of font substitution :P

POSTED BY: Dan Stimits
Posted 5 years ago

I spent many years writing PostScrpt drivers and controllers on larger printers, but very little with EPS. One of the concepts of EPS is that it must be self-contained, which is where this is failing.

As an example in where PostScript can have issues due to not being self-contained, and for which EPS was designed to get around this, would be the case of printing out of order. If regular PostScript has definitions of fonts, their glyphs, or character encodings change, then printing out of order will possibly miss the change in one of those and end up using the previous (incorrect) encoding, glyph, font, so on (the change in state relative to font handling is inherited as printing increments from one page to the next...each individual page does not necessarily contain the full information).

A second example is that PostScript can be "optimized for size". In that case definitions of fonts and their glyphs are introduced only at the start of each page which uses them. A regular document would normally introduce the entire character set and not pieces of a character set. Printing this out of order would result in missing graphics for characters not yet introduced.

EPS is designed to be more or less copy and paste (it is an encapsulated block of PostScript, with a few rules about what it must or must not contain), but it has a weakness in that people often assume that although the structure is syntactically correct, that the data is also complete. This results in valid EPS which cannot be printed correctly. In this case you have to either add the missing information into the EPS, or else substitute. This latter is why ghostscript works, but it warns about the missing character set. Ghostscript displays because ghostscript did a substitution. Mathematica fails because it is importing an image which it refuses to do substitution on.

What Mathematica exported is syntactically correct. What Mathematica exported is where the real fault exists. Mathematica could substitute as a "workaround", but it would have been better if it had embedded the information in the first place. If Mathematica has no concept of substitution, then this is a weak point in Mathematica's import mechanism.

Normally an operating system has an environment, and if done correctly, that environment lists the current encoding. This is where the EPS information should come from if it isn't explicitly set by the user in a preference. Either the mechanism to do so broke, or else the mechanism was never run.

POSTED BY: Dan Stimits
Anonymous User
Anonymous User
Posted 5 years ago

cairo was not (originally) a page description language: it was a vector graphics language for programs to make vector graphics in X Windows only when x.org was in use. Postcript was developed in BELL LABS for X and printers both to use (it's a 2D language not 3D) (as i said, cairo is a rip-off of postscript per say but was easier to program in and had more features). printers and postscript did not support it cairo (initially) - and driver support in (linux) was a hairy issue.

perhaps your system has a cairo <> postscript converter that is GPL. very like, if so, IT HAS ALLOT OF BUG that anyone who is to the em would not appreciate. that would mean you would never get "justice" if you wanted exact output using "eps" or "ps" you could take a fine ruler to. GPL software does get hacked by "mal contents" (including competitors to Wolfram Mathematica) ... a thing which is just un-avoidable.

i'm unsure if PDF uses cairo - but it might not. if it doesn't - try that

my upshot here is avoid the whole situation by not using any of it if possible

personally i expect a math program to have output one can use and engineering slide rule with. in today's IT environment that might be too much to expect since people just wreck stuff they have no idea about

POSTED BY: Anonymous User
Anonymous User
Anonymous User
Posted 5 years ago

EPS can only store 1 postscript page ("encapsulated") - it's a special-use thing that intently does not have multi-page postscript code in it. that being so it may also not include all font definitions or things Import "needs".

if you check Help you can find a full writeup on each Export type of which EPS is one, but perhaps google EPS and you'll find many adobe or unix documents on EPS

I see what you mean now. a Plot exported as EPS then imported the text is missing

Again as other's indicated. EPS was exported without all page description (perhaps viewable in ghostscript perhaps not). The Mathematica Import function using EPS did not understand the whole EPS and dropped the text.

Use PS or PDF, not EPS is the answer there. Your might be able to carefully make the plot text to insure it uses your system fonts that both you and poscript have installed (that Import doesn't have to do any work to import fonts) and it would work. But in general (across different systems), as things are, it is never going to work using EPS.

also - Mathematica's Import functions are FAR FROM PERFECT, some hardly work at all some are very good. do no expect if that ghostscript can "see an eps" that Import[] should do the same equally well. find the Help section and the full writeup page for EPS importer - there's one online to find.

POSTED BY: Anonymous User
Anonymous User
Anonymous User
Posted 5 years ago

my upshot here is avoid the whole situation by not using any of it if possible

there are many reason why you may never "get justice" and should "try another way that doesn't involve EPS or maybe even PS either

I don't have time to test this but I do know basic postscript programming.

As the person above said: save a simple Mathematica plot (it has text) then hit Ctrl-Shift-e you'll see the postscript (eps) code. (it works, your other software is not working)

The plot will import and export (there is a few minor bugs with line width for tables in some cases).

The EPS is both Adobe (paid use non-free) and Mathematica postscript code, in the postscript programming language. PDF is similar but newer version and is (partly) compressed (you can't see all the code without finding the right de-compression).

The Mathematica postscript in each .ps or .eps does two things:

(1) it provides the postscript programming for using Mathematica fonts (for loading them, naming them, scaling them - ie for radical verticuland width, printing them at the right width). you have to have those fonts installed on the system or you won't see them in GhostScript. they are copyright wolfram your not allowed to "share them" (if you bought mathematica there are instructions for installing fonts for ghostscript to make use of for the purpose of printing)

(2) it provides basic functions for doing plot lines and such (in the ps programming language, with frames of total width and units - which is a new bug sometimes the total width is wrong so the line width gets multiplied wrong). i'm unsure when and if what ps functions go automatically in every .eps - but there will be some in there. typical ps functions do things like check plot range and plot scale and generate tick marks for axis based on scale. for example this would be in an EPS:

(0.5)Tj
(is some text)
Tj is a wolfram function that ads postscript code as to the font and placement of the text

actually i see wolfram has "lifted" gpl'd cairo borrows from linux libs (that's probably both un-necessary and probably why it's has new bugs. but i'd have to check if adobe has released it's own cairo. cairo was originally a rewrite of postscript graphics for X that "stole postscript" and extended it's vector abilities which in turn could be used on the X desktop with X.org - but many no longer support x.org because of many many reasons)

POSTED BY: Anonymous User
Posted 5 years ago

Wolfram probably needs to examine if the character set information is being properly exported to eps. In the case of import, then Wolfram might want to add a fallback when character set is missing.

POSTED BY: Dan Stimits
Posted 5 years ago

I don't understand too much about this things. Normally I use the Mathematica-generated EPS-Files with LaTeX or somtimes with inscape or Ghostviewer to dieplay them. And there was no problems at all.

Only Mathematica itself make trouble with importing its own files.

After your hint I looked up a little bit for "Character Encodings". The Standard is WinowsANSI, but there seems to be an option to change this with exporting and importing. So I tried this:

Graphics[Text["A", {0, 0}]]
Export["image.eps", %, CharacterEncoding -> "UTF8"];
Import["image.eps", CharacterEncoding -> "UTF8"]

But it doesnt help, same problem like before. I don't know if this option had some effect on the output-file.

I make now a workaround: I export and import the file as PDF and export the graphic with the inserted PDF at the end as EPS.

Thank you for your hints!

Attachments:
POSTED BY: Juerg Baertsch
Posted 5 years ago

I see this in a ghostview debug:

Warning: Missing charsets in String to FontSet conversion

Basically the eps isn't entirely valid because it has some definitions, but it doesn't know which character set table to look it up in. It might be UTF-8, UTF-16, ASCII...who knows?

My thought is that there are two possibilities:

  • No environment detected character set, and thus inherited environment couldn't pass this on.
  • The Mathematic app doesn't take this into consideration (but should).

Btw, if I use my default character set it does display correctly in other applications after a warning.

POSTED BY: Dan Stimits
Posted 5 years ago

Can you save the EPS as a separate file? I'd like to see the PostScript code within the file.

POSTED BY: Dan Stimits
Posted 5 years ago

Yes sure, I only thougt that Export["image.eps",Graphics[Text["A", {0, 0}]]] produces the same file for everybody. But perhaps I might be wrong.

Attachments:
POSTED BY: Juerg Baertsch
Posted 5 years ago

You might post the source code of the eps image (surround it in the "code sample" tag). Also mention what error you see and which operating system you use.

POSTED BY: Dan Stimits
Posted 5 years ago

The EPS is generated with mathematica with Export[], see the code above. Does the code above work for you?

As written above there is no error-message, mathematica keeps running and cannot be aborted anymore.

I use Windows 10 and Mathematica 12.

POSTED BY: Juerg Baertsch
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract