[reportlab-users] question re: paragraph bounding box vertical offset

Andy Robinson andy at reportlab.com
Wed Sep 1 05:47:50 EDT 2010


I will stay silent on what's "right" but can at least give you the
original reasoning.

When we started out, we decided that paragraphs should 'enclose' their
text properly. We had to work with the font metrics provided in the
.afm files. There were three choices:

(a) use the 'ascent' and 'descent' given by the font designer for the
font as a whole

(b) look at the metrics for every single glyph, and try to work out
the exact bounding box of the glyphs beingt used in that word or on
that line.

(c) adopt a simple convention which was easy to compute.

---


(a) turned out to be numbers the font designer thought 'looked nice'
and which gave the right spacing. Very often they did NOT agree with
the height of the actual ascenders and descenders in the glyphs. This
drives programmers nuts but it's true. Also, what do you do if a
sentence switches fonts mid-line? If you're going for the
ascent/descent bounding box, your text baseline would jiggle up or
down.

(b) would have been plain nuts - - super-slow and making line heights
vary depending on the glyphs in some cases, and many fonts did not
give you per-glyph metrics anyway.

(c) still looks pretty good. If you are using, say, 10 point text
with 2 point leading, we assume that the bounding box will extend 10
points above the baseline and 2 below. This gave a nice optical
spacing with all the standard fonts, the baseline can be computed
easily, and the baseline doesn't jiggle if you switch fonts
mid-paragraph. And we can churn out paragraphs quickly - Homer's
Odyssey in a couple of seconds etc - which is/was more important to us
than the precision.

So, we're keeping the default approach simple, but hoping to allow
people to refine it for specific situations when they need to.


--
Andy Robinson
CEO/Chief Architect
ReportLab Europe Ltd.


More information about the reportlab-users mailing list