TrueType font embedding in eps problem.

Setting ps.useafm = True while ps.fonttype = 42 allows illustrator to open the eps files again and gives me back text editing capability, but I don't have any control over the typeface anymore, it just defaults to Helvetica.

Jordan

There have been quite a few changes to fonts in MPL since 8.x. Perhaps one of the biggest is mathtext. Real unicode fonts with mathematics. Since you do what I do, sort of, I am guessing that you might be happy with the same configuration I use. I looks great, and can be edited in Illustrator (et al.).

I really like Arev Sans, but others like the new STIX fonts. This setup is for Arev Sans. The important stuff is what begins with mathtext. If you want serif fonts, this should be enough to get you started on customizing. Just make sure whatever fontset you pick has all of the math symbols built in, or change fallback_to_cm to True.

-Rob

font.family : sans-serif
font.style : normal
font.variant : normal
font.weight : medium
font.stretch : normal
font.size : 12.0
font.serif : STIX, Bitstream Vera Serif, New Century Schoolbook, Century Schoolbook L, Utopia, ITC Bookman, Bookman, Nimbus Roman No9 L, Times New Roman, Times, Palatino, Charter, serif
font.sans-serif : Arev Sans
font.cursive : Zapfino, Apple Chancery, Textile, Sand, cursive
font.fantasy : Chicago, Comic Sans MS, Charcoal, Impact, Western, fantasy
font.monospace : Bitstream Vera Sans Mono, Andale Mono, Nimbus Mono L, Courier New, Courier, Fixed, Terminal, monospace

text.color : black
text.usetex : False
text.dvipnghack : True

mathtext.fallback_to_cm : False
mathtext.fontset : custom

mathtext.cal : Arev Sans:oblique
mathtext.it : Arev Sans:oblique
mathtext.rm : Arev Sans
mathtext.bf : Arev Sans:bold
mathtext.sf : Arev Sans

pdf.fonttype : 42

···

On Jan 16, 2008, at 10:13 PM, Jordan Dawe wrote:

Setting ps.useafm = True while ps.fonttype = 42 allows illustrator to
open the eps files again and gives me back text editing capability, but
I don't have any control over the typeface anymore, it just defaults to
Helvetica.

Jordan

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

----
Rob Hetland, Associate Professor
Dept. of Oceanography, Texas A&M University
http://pong.tamu.edu/~rob
phone: 979-458-0096, fax: 979-845-6331

There was a change between 0.90 to 0.91 as to how the TrueType to Type 42 (which is essentially a thin wrapper around a TrueType font) conversion is done. In 0.90 it was done in Python -- in 0.91 when font subsetting was added, this conversion is done in some borrowed C code called "ttconv". That's just a guess as to what may be the specific cause. I don't have a copy of Illustrator, so I haven't done any testing with that. I'm happy to hear of a positive report from Rob. Perhaps you both (Rob and Jordan) are using different versions of Illustrator?

Note that ps.useafm essentially overrides the ps.fonttype setting. If ps.useafm is True, you will always only get one of the 14 "builtin" Postscript fonts, which are not embedded in the file because all Postscript interpreters are required to support them. If ps.useafm is False, then the other setting kicks in. Type 42 essentially includes the whole Truetype font somewhat verbatim in the Ps file. Type 3 will include only the used characters, using a format that is more native to Postscript.

All of them *should* be able to be editable on a purely theoretical level, though I would imagine Type 3 to be broken if you try to add a character that wasn't embedded in the file. (This is different from how matplotlib does SVG font embedding where the original text really is lost). But I don't really know what Illustrator's abilities and limitations are in that regard.

Hopefully Rob's suggestions will work for you. Otherwise, I may want to revisit pulling the old Type 42 code back out of SVN to see if that solves your problem. A good place to start might be if you could send me (off list) two eps files of the same plot -- one created with 0.90.1, and one with 0.91.2.

Cheers,
Mike

Rob Hetland wrote:

···

There have been quite a few changes to fonts in MPL since 8.x. Perhaps one of the biggest is mathtext. Real unicode fonts with mathematics. Since you do what I do, sort of, I am guessing that you might be happy with the same configuration I use. I looks great, and can be edited in Illustrator (et al.).

I really like Arev Sans, but others like the new STIX fonts. This setup is for Arev Sans. The important stuff is what begins with mathtext. If you want serif fonts, this should be enough to get you started on customizing. Just make sure whatever fontset you pick has all of the math symbols built in, or change fallback_to_cm to True.

-Rob

font.family : sans-serif
font.style : normal
font.variant : normal
font.weight : medium
font.stretch : normal
font.size : 12.0
font.serif : STIX, Bitstream Vera Serif, New Century Schoolbook, Century Schoolbook L, Utopia, ITC Bookman, Bookman, Nimbus Roman No9 L, Times New Roman, Times, Palatino, Charter, serif
font.sans-serif : Arev Sans
font.cursive : Zapfino, Apple Chancery, Textile, Sand, cursive
font.fantasy : Chicago, Comic Sans MS, Charcoal, Impact, Western, fantasy
font.monospace : Bitstream Vera Sans Mono, Andale Mono, Nimbus Mono L, Courier New, Courier, Fixed, Terminal, monospace

text.color : black
text.usetex : False
text.dvipnghack : True

mathtext.fallback_to_cm : False
mathtext.fontset : custom

mathtext.cal : Arev Sans:oblique
mathtext.it : Arev Sans:oblique
mathtext.rm : Arev Sans
mathtext.bf : Arev Sans:bold
mathtext.sf : Arev Sans

pdf.fonttype : 42

On Jan 16, 2008, at 10:13 PM, Jordan Dawe wrote:

Setting ps.useafm = True while ps.fonttype = 42 allows illustrator to
open the eps files again and gives me back text editing capability, but
I don't have any control over the typeface anymore, it just defaults to
Helvetica.

Jordan

---------------------------------------------------------------------- ---
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

----
Rob Hetland, Associate Professor
Dept. of Oceanography, Texas A&M University
http://pong.tamu.edu/~rob
phone: 979-458-0096, fax: 979-845-6331

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

Rob Hetland wrote:

I really like Arev Sans, but others like the new STIX fonts. This setup is for Arev Sans. The important stuff is what begins with mathtext. If you want serif fonts, this should be enough to get you started on customizing. Just make sure whatever fontset you pick has all of the math symbols built in, or change fallback_to_cm to True.

When I converted my matplotlibrc to the settings you listed, the result was pages and pages of exception tracebacks ending in:

C:\Python25\Lib\site-packages\matplotlib\mathtext.py in _get_font(self, font)
    590 cached_font = self._fonts.get(basename)
    591 if cached_font is None:
--> 592 font = FT2Font(basename)
    593 cached_font = self.CachedFont(font)
    594 self._fonts[basename] = cached_font

If I remove all the LaTeX from my expressions, this error goes away.

Jordan

TypeError: cannot return std::string from Unicode object

I suspect an explicit conversion to str may be required on your configuration/platform. (I think you mentioned you were using Windows).

Can you change line 592 of mathtext.py to read:

     font = FT2Font(str(basename))

and let me know if that fixes your problem? If so, I'll commit this to SVN.

Note that you may also have problems if there are any non-ascii characters (with accents etc.) anywhere in the path to mpl's fonts. In general mpl doesn't really handle Unicode paths correctly wherever C/C++ code is involved. Hopefully that can be resolved in a future version.

Cheers,
Mike

Jordan Dawe wrote:

···

Rob Hetland wrote:

I really like Arev Sans, but others like the new STIX fonts. This setup is for Arev Sans. The important stuff is what begins with mathtext. If you want serif fonts, this should be enough to get you started on customizing. Just make sure whatever fontset you pick has all of the math symbols built in, or change fallback_to_cm to True.

When I converted my matplotlibrc to the settings you listed, the result was pages and pages of exception tracebacks ending in:

C:\Python25\Lib\site-packages\matplotlib\mathtext.py in _get_font(self, font)
    590 cached_font = self._fonts.get(basename)
    591 if cached_font is None:
--> 592 font = FT2Font(basename)
    593 cached_font = self.CachedFont(font)
    594 self._fonts[basename] = cached_font

If I remove all the LaTeX from my expressions, this error goes away.

Jordan

TypeError: cannot return std::string from Unicode object

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

Michael Droettboom wrote:

I suspect an explicit conversion to str may be required on your configuration/platform. (I think you mentioned you were using Windows).

Indeed I am.

Can you change line 592 of mathtext.py to read:

    font = FT2Font(str(basename))

and let me know if that fixes your problem? If so, I'll commit this to SVN.

It fixed it perfectly.

Rob, that configuration you suggested is amazing. Arev Sans is very attractive (once I downloaded and installed it) and now I have all of Matlab's Tex-command goodness! Still errors on the eps output in illustrator (CS3), but the pdf file output opens great in illustrator.

Rob, have you tried setting ps.fonttype to 42 and opening the eps output in illustrator? In the files you sent me, it looked like you had ps.fonttype set to 3.

Jordan