Issue #50 resolved

Fonts not rendering properly in PNG output

created an issue

Recently, I have noticed that all my PNG diagrams are not rendering the fonts properly; they are cropping the fonts so that only the top parts of all the characters are visible. SVG output is fine. I have attached three files: a test actdiag source, and the PNG and SVG output from it.

Here is details of my environment:

  • Mac OSX 10.8.5

  • Python 2.7.6

  • actdiag 0.5.1

  • Pillow 2.2.2

  • freetype 2.5.2

  • graphviz 2.34.0

  • Sphinx 1.2

  • sphinxcontrib-actdiag 0.6.0 (not used for test; used actdiag directly)

What other information can I provide to help solve this problem?

Comments (11)

  1. Paul Hinze

    I'm observing the same behavior on OSX with seqdiag - bottom half of text is cut off on png output.

    Let me know if there's anything else I can to do help debug this.

  2. Seth Hill

    The font size from ImageDraw seems to be getting calculated incorrectly on Mac OS X.

    Adding the following height adjustment hack in blockdiag/imagedraw/ in text() corrected the issue for me.

    # Fix fonts being cut off in PNGs
    size = (size[0], int(size[1] * 1.5))

    I'm using Mac OS X 10.9.1, and pillow 2.3.0 (not PIL), so it might be a problem with pillow. I'm also rendering with Deja Vu Sans Mono.ttf, if that matters.

  3. ViktorHaag reporter

    Is it good practice to submit a patch that basically does what +Seth Hill suggests (albeit perhaps one that checks the host platform first?), or should this get traced back to a root cause (Pillow?) and fixed there? I've hacked my local version of this package, but that strikes me as untidy for the long haul.

  4. Yann Dirson

    Well, good practice is surely to track the root cause. In the meantime we have the workaround - I'd say it's more a matter of "does anyone have time to hunt for the bug, or can we introduce the workaround with a bit FIXME until someone does"

  5. lifeisstillgood

    I (rather annoyingly) independently hunted down a workaround for this today.

    I can confirm it is not (just) Pillow - in fact I suspect the problem is not caused by ImageDraw.textsize at all. This returns different values whether passed fonts or not, however the ttfont flag seems to be always set (the code in 280-309) is not exercised it seems at all. If so then getting the cutoff of characters will depend on the choice of font.

    I have also got a patch which is indistinguisable from seth Hill and I see no value in taking my work further unless it is helpful to someone on here.

    Thank you btw - great Python library - wish I had found it earlier !

  6. lifeisstillgood

    Actually it is different :

                ## Expand text box to avoid cutting lower half of char
                size = (int(size[0]*1.5),

    I also have pushed the width of the box out - I can see the same cut off on the RHS.

  7. mike_photivo

    I get a similar problem with blockdiag (1.3.2) on Windows.

    The lower parts of the letters are cut in the png (the svg is ok):

    blockdiag {
      good -> morning


  8. Log in to comment