[reportlab-users] background color and string width

Karol Bryd karol at python.org.pl
Wed Feb 16 03:49:36 EST 2005


Hello!

    I am new to Reportlab and these questions may sound silly
but I am going to ask them anyway :)

I have problem with calculating width of string when using Symbol font,
for example, this example code works fine with Courier font, but not
with Symbol:

#!/usr/bin/python

import sys
from reportlab.pdfbase import pdfmetrics

from reportlab.pdfgen import canvas
from reportlab.lib.units import inch, cm
from reportlab.lib.pagesizes import A4

top_margin = A4[1] - cm

def run(mode):
    enc = 'WinAnsi'
    canv = canvas.Canvas(
                'out_%s.pdf' % enc,
                encoding = enc
                )
    canv.setPageCompression(0)

    faceName = 'Symbol'
    encLabel = 'StandardEncoding'
	    
    symbolFontName = faceName + '-' + encLabel
    pdfmetrics.registerFont(pdfmetrics.Font(symbolFontName,
                                faceName,
                                encLabel))
    canv.setFont(symbolFontName, 14)
    textobj = canv.beginText(inch, top_margin)
    textobj.textOut(str(chr(191)) + str(chr(190)))
    canv.drawText(textobj)
    lastX = textobj.getX()
    print lastX
    canv.showPage()
    canv.save()
    sys.exit(0)

if __name__ == '__main__':
    run(0)

This always returs 72.0 as an X position regardless how manu characters
I print. What is wrong with it?

Second question is: is there any simple way to set background color
of text printed using TextObject? 

Thanks for help
Karol
-- 
  karol (at) karolbryd.art.pl       ----------------------------------
    "Zbyt malo wiem by byc niekompetentnym"         www.karolbryd.art.pl
   ----------------------------------------      fotografia przyrodnicza


More information about the reportlab-users mailing list