[reportlab-users] Font size, baseline and typography stuff

Dinu Gherman gherman at darwin.in-berlin.de
Fri Aug 5 09:34:51 EDT 2011

"Robin Becker" <robin at reportlab.com>:

> Not all fonts use the same scale unfortunately; I think that most

> truetype fonts come with a unitsperEm value of 2048. In ttfonts.py I

> think we adjust the bounding boxes to be in 1/1000. I guess that's

> so the bounding boxes can be used without knowing the original scale.

Right. I noticed when fiddling with TrueType fonts years
ago. I'll have a look into some old code to run a few
tests on my font pool, before I can give more detailed

> It might be possible with access to the curves. We do have that with

> tools in the graphics extension _renderPM (at least for those fonts

> we can cope with).


> eg


>> C:\tmp>cat xheight.py

>> from reportlab.graphics.charts.textlabels import _text2Path

>> from reportlab.pdfbase import pdfmetrics, ttfonts


>> pdfmetrics.registerFont(ttfonts.TTFont('Vera','Vera.ttf'))


>> px = _text2Path('x',fontName='Vera',fontSize=2048)

>> pX = _text2Path('X',fontName='Vera',fontSize=2048)


>> print 'x',px.getBounds()

>> print 'X',pX.getBounds()


>> C:\tmp>xheight.py

>> x (59, 0, 1145, 1120)

>> X (61, 0, 1339, 1493)


> so we seem able to get the path for x and X and there is a

> difference in the curve heights (and luckily both seem to stay on

> and above the baseline ie 0)


> Of course I'm using a fairly large value for the fontSize so the x

> height seems to be fontSize * (1120-0)/2048. and for X fontSize *

> (1493-0)/2048.


>> In the PDF generated by my script I approximated this

>> as shown by the dashed lines using an x-height equal

>> to the x-width which is not really acceptable, though.


> Anyhow if I use that in your code it seems better; see attached.

That's really nice, indeed! I didn't know the glyphs' paths
were accessible like this. One could even seperate them in-
dividually from the single path for a character.

I'm just not sure I would expect this to be inside the
charts package, though, but maybe in pdfmetrics...

In any case this is very helpful, thanks!



More information about the reportlab-users mailing list