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

Robin Becker robin at reportlab.com
Fri Aug 5 12:37:55 EDT 2011


On 05/08/2011 15:44, Andy Robinson wrote:

> On 5 August 2011 14:34, Dinu Gherman<gherman at darwin.in-berlin.de> wrote:

>> I'm just not sure I would expect this to be inside the

>> charts package, though, but maybe in pdfmetrics...

>>

>

> It happened this way because our charts/shapes package already had a

> 'getBounds' operation - we needed that to dynamically resize charts to

> be just big enough to contain their text labels and titles, and

> sometimes to make sure labels don't overlap - and when you want to

> define that for a text label, Robin realised he could get the paths

> out of freetype2. It doesn't really have anything to do with PDF and

> applies equally when making a bitmap.

>

> You're right, it would probably make sense to have an equivalent

> function available within pdfmetrics for the many users who don't

> delve into the chart code.

>

>

for what it's worth I have fixed (hopefully) Path.getBounds so it doesn't use
the simplistic assumption from the original code.

Testing using some rather extreme paths eg



> from reportlab.graphics.shapes import Drawing, _DrawingEditorMixin, definePath, String, Rect

> from reportlab.lib.colors import red, blue, green

>

> class TPathBounds_002(_DrawingEditorMixin,Drawing):

> def __init__(self,width=400,height=200,*args,**kw):

> Drawing.__init__(self,width,height,*args,**kw)

> self._add(self,definePath([('moveTo',10,100),('curveTo',70,160,160,40,100,100)],strokeWidth=1,strokeColor=red),name='p',validate=None,desc=None)

> sb = self.p.getBounds()

> self._add(self,String(10,self.height-12,'bounds: '+str(sb),fillColor=blue),name=None,validate=None,desc=None)

> self._add(self,Rect(sb[0],sb[1],sb[2]-sb[0],sb[3]-sb[1],strokeColor=blue,strokeDashArray=(1,1),fillColor=None),name='b',validate=None,desc=None)

>

> if __name__=="__main__": #NORUNTESTS

> TPathBounds_002().save(formats=['pdf'],outDir='.',fnRoot=None)


revealed an error in renderPM (caused by the old version of libart_lgpl); the
bounds were good, but the _renderPM bpath to vpath conversion left out the
extreme point.

It should now be fixed.
--
Robin Becker


More information about the reportlab-users mailing list