← 输入框|github.com|刷新
Skip to content

some FreeSans characters distorted in PDF backend #903

Closed

Description

@mspacek

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

Activity

  1. mspacek commented on May 25, 2012

    @mspacek
    ContributorAuthor

    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.

  2. mspacek commented on May 25, 2012

    @mspacek
    ContributorAuthor

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

  3. WeatherGod commented on May 26, 2012

    @WeatherGod
    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.

  4. mspacek commented on May 26, 2012

    @mspacek
    ContributorAuthor

    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

  5. mdboom commented on May 26, 2012

    @mdboom
    Member

    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.

  6. jkseppan commented on May 26, 2012

    @jkseppan
    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.

  7. jkseppan commented on May 27, 2012

    @jkseppan
    Member

    Does pull request #905 fix the problem?

  8. mspacek commented on May 27, 2012

    @mspacek
    ContributorAuthor

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

  9. mspacek commented on May 27, 2012

    @mspacek
    ContributorAuthor

    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?

  10. jkseppan commented on May 28, 2012

    @jkseppan
    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.

  11. mspacek commented on May 28, 2012

    @mspacek
    ContributorAuthor

    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.

  12. jkseppan commented on May 28, 2012

    @jkseppan
    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.

  13. mspacek commented on May 29, 2012

    @mspacek
    ContributorAuthor

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

  14. jkseppan commented on May 29, 2012

    @jkseppan
    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).

  15. added a commit that references this issue on May 30, 2012
  16. jkseppan commented on May 31, 2012

    @jkseppan
    Member

    Merged into v1.1.x.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions