[reportlab-users] TTFont in ParagraphStyle

Marius Gedminas reportlab-users@reportlab.com
Mon, 21 Oct 2002 12:45:52 +0200

Sorry for late replies.  I was ill last week and didn't read my work
e-mail account.

On Wed, Oct 16, 2002 at 03:12:01PM +0100, Robin Becker wrote:
> >       pdfmetrics.registerFont(TTFont('Arial', 'Arialn.ttf')) # works fine
> >
> >       levelZeroParaStyle = \
> >           ParagraphStyle(name='LevelZero',
> >                          fontName='Arial',
> >                          fontSize=10,
> >                          leading=11,                     
> >                          firstLineIndent = -epsilon,
> >                          leftIndent = 0*delta + epsilon)
> ......
> I think there's a bug in what's currently being done for registration.
> The problem is that when we use bold/italic etc we need to have the
> concept of a root face name. That allows us to map
>  -   -       b    -      -     i      b     i
> Times-Roman Times-Bold Times-Italic Times-BoldItalic
> I'm fairly sure that registerFont isn't doing the right thing about
> this.

I thought it wasn't supposed to.  I saw the following code somewhere

  # register normal, italic, bold and bold-italic
  pdfmetrics.registerFont(... 'Arial' ...)
  pdfmetrics.registerFont(... 'ArialI' ...)
  pdfmetrics.registerFont(... 'ArialB' ...)
  pdfmetrics.registerFont(... 'ArialBI' ...)

  # provide mappings for Platypus
  from reportlab.lib.fonts import addMapping
  addMapping('Arial', 0, 0, 'Arial')
  addMapping('Arial', 0, 1, 'ArialI')
  addMapping('Arial', 1, 0, 'ArialB')
  addMapping('Arial', 1, 1, 'ArialBI')

(and this is not TTF specific, you have to do the same thing with Type1
font, unless my memory is failing.)

> Assuming that Arial is the base font you need to do something like
>         from reportlab.lib import fonts
>         fonts._tt2ps_map.update({
>                         ('arial', 0, 0) :'Arial',
>                         ('arial', 1, 0) :'Arial',
>                         ('arial', 0, 1) :'Arial',
>                         ('arial', 1, 1) :'Arial',
>                         })
>         fonts._ps2tt_map.update({'arial': ('arial',0,0)})

These underscored names seem private to me, I thought fonts.addMapping
is the tool for this.

What I think is a bug is that addMapping does not allow you to map two
different styles (say arial normal and arial italic) to a single font
name, like this:

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

On Wed, Oct 16, 2002 at 06:17:37PM +0100, Robin Becker wrote:
> >UnicodeError :ASCII encoding error: ordinal not in range 128
> I think that we use UTF-8 encoding, but I'm not the expert on this
> that's Marius.

Yes, due to Python 1.5.2 compatibility you cannot use Unicode strings.
If you have one, say, called ustr, just pass ustr.encode("UTF-8") to
reportlab functions.

I'd like to make this transparent, so that Reportlab could handle both
UTF-8 and Python 1.6+ Unicode strings.  I think only two places ought
to be modified, parse_utf8 in ttfont.py, and someplace in Platypus,
before the string is fed to the Unicode-unaware parser.

On Thu, Oct 17, 2002 at 02:49:23PM +0200, Jo-Bader@gmx.de wrote:
> thanks for the hint.
> I found the Beispiel and test it with my customer font
> It seams to work. Only the TTFontFileTestCase class chrashes in many cases.

I would like to hear about any crashes in TT font code.

Marius Gedminas
To err is human... to really foul up requires the root password.