[reportlab-users] Cursive Font Question

Richie Marini richardjmarini at gmail.com
Wed Jun 1 15:28:13 EDT 2011



I'm using the reportlab with pyfribidi to create pdf's with Arabic fonts.
I'm noticing that canvas.StringWidth() returns a value larger then the
actual rendered string which is causing me some issues. From what I'm
guessing this has to do with the "cursive" nature of the glyphs in that
they overlap each other a little to make the cursive connection to the
glyph next to it? Therefore, string width is simply returning the
summation of widths of all the glyphs used and not accounting for the
overlapping. So the value return is the width of all the Glyph's and not
the amount of space the entire string is taking up on the canvas.
So, if I were to render two separate words on a canvas with two separate
calls to render and increment the X value by the stringWidth() of the
first string I get a large white space between the two because the width
returned is to big. For example:

### START ###
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from reportlab.pdfgen import canvas
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont

pdfmetrics.registerFont(TTFont('Arabic', '/Library/fonts/Arial
Unicode.ttf'))

c= canvas.Canvas(filename= "test.pdf")

x= 10
y= 500
text= u"هذا هو مجرد اختبار للغة العربية"

c.setFont('Arabic', 12)

c.drawString(x, y, text)

x+= c.stringWidth(text)

c.drawString(x, y, text)

c.showPage()
c.save()


### END ###


Wondering if there's a least a way to get the summed value of the
overlapped glyph's so I can at least substract that value from that
returned from stringWidth()? Or maybe, it's a different problem all
together?

Thanks,
-richie


More information about the reportlab-users mailing list