Thanks to visit codestin.com
Credit goes to github.com

Skip to content

some FreeSans characters distorted in PDF backend #903

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
mspacek opened this issue May 25, 2012 · 15 comments
Closed

some FreeSans characters distorted in PDF backend #903

mspacek opened this issue May 25, 2012 · 15 comments
Assignees

Comments

@mspacek
Copy link
Contributor

mspacek commented May 25, 2012

Having just tried saving to .pdf with MPL for the first time in years (potentially in place of .png, for embedding in .tex files), it looks great, except for an obvious glitch. I'm using FreeSans as my default font in rcParams, 13 pt size, and when saving to .pdf, the '0' character comes out distorted. Same goes for 'B' and '8', but none others that I can tell. This doesn't happen when saving to .png. Here's the example code

plot(np.arange(10))
text(0, 5, 'abcdefghijklmnopqrstuvwxyz\nABCDEFGHIJKLMNOPQRSTUVWXYZ\n012345687890\n~!@#$%^&*()_+-=')
gcf().savefig('freesans_example.png')
gcf().savefig('freesans_example.pdf')

You'll have to set FreeSans as your default in rcParams to replicate this, or pass it the appropriate way when plotting or adding the text. I'll see if I can attach the output.

I suppose since this doesn't happen in the .png, this must be a PDF backend bug, and not some quirk in FreeSans?

Martin

@mspacek
Copy link
Contributor Author

mspacek commented May 25, 2012

Can't see any obvious way of attaching a file in GitHub. Here's the output:

http://devio.us/~mspacek/freesans_example.png
http://devio.us/~mspacek/freesans_example.pdf

I've looked at the PDF in evince, which seems to indicate that FreeSans is indeed embedded in the file. I've also viewed it with PDF XChange Viewer, which shows the same distortion.

@mspacek
Copy link
Contributor Author

mspacek commented May 25, 2012

I'm running the latest from git by the way.

@WeatherGod
Copy link
Member

Can you post a screen capture of what you are seeing? This is unlikely to be a bug in mpl, but rather in the PDF renderer. Some PDF viewers share similar renderers, so the same distortion could show up in multiple readers.

@mspacek
Copy link
Contributor Author

mspacek commented May 26, 2012

Sure, here it is:

http://devio.us/~mspacek/freesans_screenshot.png

I can confirm that I get the same artifacts in Adobe Reader on my Android phone.

The system generating these PDFs is Ubuntu 11.04 with ttf-freefont 20090104-7

@mdboom
Copy link
Member

mdboom commented May 26, 2012

I can confirm this with version 20100919-5 of FreeSans and matplotlib git master.

As a workaround for now (as we get to the bottom of this bug), you can set the rcParam "pdf.fonttype" to 42. This will embed the entire TrueType font verbatim, so will result in larger PDF files, but the font glitches don't appear to be there.

@jkseppan
Copy link
Member

Looks like ttconv has a bug in converting TrueType. The zero glyph in the pdf file includes this as the inner contour:

417 631 m
227 631 133 534 133 342 c
133 147 179 50 273 50 c
322 50 358 74 382 122 c
405 170 417 244 417 345 c
417 631 l

Compare this with the fontforge output from FreeSans.ttf:

275 631 m 132,-1,15
 133 631 133 631 133 342 c 0,16,17
 133 50 133 50 273 50 c 0,18,19
 347 50 347 50 382 122 c 128,-1,20
 417 194 417 194 417 345 c 0,21,14
 417 631 417 631 275 631 c 132,-1,15

The inner curveto endpoints match (133 342, 273 50, 382 122, 417 345) but the first and final points don't (417 631 vs 275 631; note that 417 631 looks like it's a control point of the final curveto in the ttf data). Also, the pdf data ends with a lineto but the ttf data ends with a curveto.

@jkseppan
Copy link
Member

Does pull request #905 fix the problem?

@ghost ghost assigned jkseppan May 27, 2012
@mspacek
Copy link
Contributor Author

mspacek commented May 27, 2012

Yes, #905 fixes it for me. Thanks Jouni!

@mspacek
Copy link
Contributor Author

mspacek commented May 27, 2012

Actually, I just noticed that in the .pdf, the FreeSans '1' doesn't align properly on both the x and y axes labels (see attachments above). It's too far to the right. This isn't really apparent in the .png, and doesn't happen with the default sans-serif font. Is this another truetype conversion bug? Should I file another bug?

@jkseppan
Copy link
Member

Does changing pdf.fontType to 42 fix the alignment issue? If it does, then it could be another TTF to Type 3 conversion bug, but if it doesn't, it sounds more like a font metrics issue.

@mspacek
Copy link
Contributor Author

mspacek commented May 28, 2012

Changing pdf.fonttype to 42 doesn't seem to change the alignment of the FreeSans '1' on the axes. As before, the axes as displayed on screen and as saved to .png are fine, but in the .pdf the '1' is aligned somewhat too far to the right. I can tell I've correctly switched to using type 42 because the output .pdf files are much bigger than before.

@jkseppan
Copy link
Member

Then I don't think it's a bug in the same component as the first one. Possibly the font metrics are read wrong.

@mspacek
Copy link
Contributor Author

mspacek commented May 29, 2012

OK, should I open up a separate issue for the alignment problem?

@jkseppan
Copy link
Member

Yes, I'd suggest a separate issue for that. Please see if it is backend-dependent, or occurs in both agg and pdf (and possibly svg).

mdboom pushed a commit to mdboom/matplotlib that referenced this issue May 30, 2012
If I enable svg, I see artifacts in the resulting file that look
like there are similar bugs as matplotlib#903 in svg.
@jkseppan
Copy link
Member

Merged into v1.1.x.

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

No branches or pull requests

4 participants