reportlab add font with registerFont
<p>I've to use the registerFontFamily method from reportlab.pdfbase.pdfmetrics.
I tried to add two fonts to a family but I can't use the bold font with "&lt;<em>b>sometext&lt;</em>/b>". I need this feature for my report. I can only use the regular one and I don't know why. </p>

<p>Here's the code.</p>

<pre><code>registerFont(TTFont('Own_Font', os.path.dirname(os.path.abspath(__file__)) + '\\OwnSans-Regular.ttf'))
registerFont(TTFont('OwnBold_Font', os.path.dirname(os.path.abspath(__file__)) + '\\OwnSans-Bold.ttf'))

registerFontFamily('Own_Font',normal='Own_Font',bold='OwnBold_Font')

# define parameter for the page and paragraph font
PAGE_WIDTH, PAGE_HEIGHT = landscape(A4)
STYLES                  = getSampleStyleSheet()
STYLES.add( ParagraphStyle(name='Text', fontName = 'Own_Font', fontSize = 10 ))

STYLES.add( ParagraphStyle(name='Centered', fontName = 'Own_Font', fontSize = 10, alignment=TA_CENTER ))
STYLES.add( ParagraphStyle(name='CenteredBig', parent=STYLES['Centered'], fontSize=18, spaceAfter=10) )
STYLES.add( ParagraphStyle(name='CenteredMedium', parent=STYLES['Centered'], fontSize=15, spaceAfter=10) )
</code></pre>

<p>I've got the following error message:</p>

<pre><code>  File "X:\tools\Python2\lib\site-packages\reportlab-2.7-py2.7-win32.egg\reportlab\platypus\paragraph.py", line 916, in __init__
    self._setup(text, style, bulletText or getattr(style,'bulletText',None), frags, cleanBlockQuotedText)
  File "X:\tools\Python2\lib\site-packages\reportlab-2.7-py2.7-win32.egg\reportlab\platypus\paragraph.py", line 938, in _setup
    style, frags, bulletTextFrags = _parser.parse(text,style)
  File "X:\tools\Python2\lib\site-packages\reportlab-2.7-py2.7-win32.egg\reportlab\platypus\paraparser.py", line 1083, in parse
    self.feed(text)
  File "X:\tools\Python2\lib\site-packages\reportlab-2.7-py2.7-win32.egg\reportlab\lib\xmllib.py", line 562, in finish_starttag
    self.handle_starttag(tag, method, attrs)
  File "X:\tools\Python2\lib\site-packages\reportlab-2.7-py2.7-win32.egg\reportlab\lib\xmllib.py", line 596, in handle_starttag
    method(attrs)
  File "X:\tools\Python2\lib\site-packages\reportlab-2.7-py2.7-win32.egg\reportlab\platypus\paraparser.py", line 823, in start_para
    self._stack = [self._initial_frag(attr,_paraAttrMap)]
  File "X:\tools\Python2\lib\site-packages\reportlab-2.7-py2.7-win32.egg\reportlab\platypus\paraparser.py", line 817, in _initial_frag
    frag.fontName, frag.bold, frag.italic = ps2tt(style.fontName)
  File "X:\tools\Python2\lib\site-packages\reportlab-2.7-py2.7-win32.egg\reportlab\lib\fonts.py", line 75, in ps2tt
    raise ValueError("Can't map determine family/bold/italic for %s" % psfn)
ValueError: Can't map determine family/bold/italic for Own_Font
</code></pre>

<p>Thank you in advance.</p>

<p>The first problem is that you made a typo in the <code>registerFontFamily</code>. To be more specific you register the normal font as being the bold by doing <code>bold='Own_Font'</code>.</p>

<p>The second problem is that your font family doesn't have fonts for all types (in this case italic and boldItalic). According to the manual, if you read Vera as <code>Own_font</code>:</p>

<blockquote>
  <p>If we only have a Vera regular font, no bold or italic then we must map all to the same internal fontname. <code>&lt;b&gt;</code> and <code>&lt;i&gt;</code> tags may now be used safely, but have no effect. After registering and mapping the Vera font as</p>
</blockquote>

<p>Thus to fix it you should replace the affected line like this:</p>

<pre><code>registerFontFamily('Own_Font',normal='Own_Font',bold='OwnrBold_Font',italic='Own_Font',boldItalic='OwnrBold_Font')
</code></pre>

<p>This should make <code>&lt;b&gt;&lt;/b&gt;</code> function as expected.</p>

python pdf fonts reportlab