8000 PostScript Type42 embedding is broken in various ways · Issue #18191 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

PostScript Type42 embedding is broken in various ways #18191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
anntzer opened this issue Aug 6, 2020 · 5 comments · Fixed by #20391
Closed

PostScript Type42 embedding is broken in various ways #18191

anntzer opened this issue Aug 6, 2020 · 5 comments · Fixed by #20391

Comments

@anntzer
Copy link
Contributor
anntzer commented Aug 6, 2020

Bug report

Bug summary

As in the title.

Code for reproduction

from pylab import *
rcParams["ps.fonttype"] = 42
figtext(.5, .5, "€"); savefig("/tmp/euro.ps"); close("all")
figtext(.5, .5, "0€"); savefig("/tmp/zeroeuro.ps"); close("all")
figtext(.5, .5, "$\sqrt{2}$"); savefig("/tmp/sqrt.ps"); close("all")

Actual outcome

In euro.ps the font is actually embedded as Type 3, not Type 42 (as can be checked by opening the file in a text editor).
In zeroeuro.ps the font is correctly embedded as Type 42, but the euro sign fails to display correctly (we get a rectangular box instead).
sqrt.ps causes an error with the viewer (Error: /invalidfont in definefont).

Given that in all likelihood this has been broken for a loooooong time (as ttconv is rarely touched) it may be worth waiting for a decision on #18143 first before trying to fix this.

On the other hand, note that this also affects the ps.fonttype = 3 case when rendering more than 255 characters, because we fall back to type 42 in that case (example below). By the spec, a type 3 font cannot contain more than 255 glyphs, but empirically, things work just fine for us, likely because we always refer to glyphs by glyph name rather than by glyph index? If we want to be super safe wrt. the spec, I guess we could split a >255-glyph font into multiple fonts and call setfont as needed (we're positioning glyphs one at a time anyways).

import textwrap
from pylab import *
figtext(0, .5, "\n".join(textwrap.wrap("".join(c for c in map(chr, range(512)) if c.isprintable()))))
savefig("/tmp/test.ps")

As a side point, it seems likely that type 42 embedding is also broken for the pdf backend, per #12636...

Matplotlib version

  • Operating system: linux
  • Matplotlib version: master
  • Matplotlib backend (print(matplotlib.get_backend())): ps
  • Python version: 38
  • Jupyter version (if applicable):
  • Other libraries:
@aitikgupta
Copy link
Contributor
aitikgupta commented Mar 27, 2021

fails to display correctly (we get a rectangular box instead)

Or sometimes fail to display anything at all.

import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
plt.rcParams["ps.fonttype"] = 42

path = '/path/to/matplotlib/doc/_static/fonts/Carlogo-bolditalic.ttf'
prop = FontProperties(fname=path)

plt.figtext(0.5, 0.5, "normal_text", font=prop)
plt.savefig('normal_text.ps')

The font has the glyphs (Type 3 works fine), but the output is blank (even though the whole font is embedded).

@aitikgupta
Copy link
Contributor
aitikgupta commented Jul 13, 2021

Updating this issue:
euro.ps, zeroeuro.ps and test.ps outputs are now correct with #20391 pulled in.
(both of them are subsetted, as well as are embedded as Type 42 (test.ps is a hybrid Type3/Type42 output, since chars > 255))

sqrt.ps however, is still broken. I wonder if recent PRs by @sauerburger ends up fixing this as well?

@sauerburger
Copy link
Member

I think the issue with sqrt.ps was the missing header bytes in the embedded font and should be fixed with #20597.

@aitikgupta
Copy link
Contributor

I just checked, #20597 indeed fixes the sqrt.ps bug too!

@tacaswell tacaswell added this to the v3.5.0 milestone Jul 20, 2021
@aitikgupta
Copy link
Contributor

Since we don't have more examples/references about how and what more is broken for Type42 embedding, I think we can close this with #20391.. every example here has been fixed either by subsetting PR or #20597

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
0