[reportlab-users] Newbie -- How to center text in a paragraph

Jim Steil jim at qlf.com
Fri Jun 23 10:57:08 EDT 2006


Ok, I tried the addMappings for the Arial font.  Now it works in that it
does bold and italicize when asked, but it is doing it with the wrong font.
I have the following code:

pdfmetrics.registerFont(TTFont('Arial', 'arial.ttf'))
pdfmetrics.registerFont(TTFont('Arial Bold', 'arialbd.ttf'))
pdfmetrics.registerFont(TTFont('Arial Bold Italic', 'arialbi.ttf'))
pdfmetrics.registerFont(TTFont('Arial Italic', 'ariali.ttf'))

addMapping('Arial', 0, 0, 'Arial')
addMapping('Arial', 0, 1, 'Arial Italic')
addMapping('Arial', 1, 0, 'Arial Bold')
addMapping('Arial', 1, 1, 'Arial Bold Italic')

Then in my text I used the <b> and <i> tags to turn it off and on.  The
problem is not that it is bolding and italicizing the text, but not with the
Arial font.  It is reverting back to a Times-Roman (I think) font.  

Any ideas of what I'm doing wrong?

	-Jim

Jim Steil
IT Manager
Quality Liquid Feeds
(608) 935-2345 
(608) 341-9896 cell
-----Original Message-----
From: reportlab-users-bounces at reportlab.com
[mailto:reportlab-users-bounces at reportlab.com] On Behalf Of Andy Robinson
Sent: Thursday, June 22, 2006 4:18 PM
To: Support list for users of Reportlab software
Subject: Re: [reportlab-users] Newbie -- How to center text in a paragraph

Jim Steil wrote:
> Ok, I've got that all working now, but now I have a couple of other
'funny'
> things going on.  
> 
> 1.  I have 3 paragraphs in a frame.  I set the style on the first one to
be
> centered and set the other 2 paragraphs to be left justified.  But, all
> three paragraphs are centered.
> 
>     section5P1 = Paragraph(s5Text1, styleCentered)
>     section5P2 = Paragraph(s5Text2, style)
>     section5P3 = Paragraph(s5Text3, style)

Looking below, my hunch is that you have modified the normal style
in the standard stylesheet to be centered, and 'styleCenteredd' and 
'style' are references to the same centered object.  You should actually 
create a new style object.


> 2.  In my paragraph text, I was using the <b> and <i> tags to bold and
> italicize.  It was working fine until I changed my font to Arial.  Now
none
> of my font decoration stuff is working.
> 
> pdfmetrics.registerFont(TTFont('Arial', 'arial.ttf'))
> pdfmetrics.registerFont(TTFont('Arial Bold', 'arialbd.ttf'))
> pdfmetrics.registerFont(TTFont('Arial Bold Italic', 'arialbi.ttf'))
> pdfmetrics.registerFont(TTFont('Arial Italic', 'ariali.ttf'))
> baseFont = 'Arial'
> styleCentered = styles['Normal']
> styleCentered.alignment = 1
> styleCentered.fontName = baseFont
> text = '<b>This is my bold text</b>'
> paragraph = Paragraph(text, styleCentered)

What you have done here is to register 4 fonts, but as yet it has no 
knowledge that they are in the same 'family', so it doesn't know what to 
do when encountering a <b> or <i> tag.  The system has builtin knowledge 
of the 'font families' for Helvetica, Courier and Times but no others.
So you need to tell it which combinations of facename/bold/italic map to 
which actual font files:

from reportlab.lib.fonts import addMapping
addMapping('Arial', 0, 0, 'Arial')
addMapping('Arial', 0, 1, 'Arial Italic')
addMapping('Arial', 1, 0, 'Arial Bold')
addMapping('Arial', 1, 1, 'Arial Bold Italic')

The user guide mentions this for Rina, which is a poor example
as there were no variants and all we wanted to do was allow <b> and <i> 
through harmlessly.

- Andy
_______________________________________________
reportlab-users mailing list
reportlab-users at reportlab.com
http://two.pairlist.net/mailman/listinfo/reportlab-users




More information about the reportlab-users mailing list