[reportlab-users] OTF fonts supported by Reportlab?

2,363 views
Skip to first unread message

Mike Driscoll

unread,
Jul 23, 2013, 9:47:28 AM7/23/13
to reportl...@lists2.reportlab.com
Hi,

After writing a tutorial on fonts in Reportlab, I got a comment asking if OTF fonts are supported. So far, I've found conflicting information.

This old thread seems to indicate that it should work: http://two.pairlist.net/pipermail/reportlab-users/2008-August/007120.html

While this one says that if the font uses CFF format, Reportlab will spit out an error:

http://stackoverflow.com/questions/895596/can-anyone-recomend-a-python-pdf-generator-with-opentype-otf-support

So I tried it. I went to http://www.fontsquirrel.com/ and downloaded the first OTF font on there, specifically "Source Sans Pro Black". Then I ran the attached code which gave me the following traceback:

reportlab.pdfbase.ttfonts.TTFError: TTF file "C:\Users\mdriscoll\Desktop\rep-fonts\otf\SourceSansPro-Black.otf": postscript outlines are not supported
File "c:\Users\mdriscoll\Desktop\rep-fonts\otfDemo.py", line 29, in <module>
  embedOTF(r"C:\Users\mdriscoll\Desktop\rep-fonts\otf.pdf")
File "c:\Users\mdriscoll\Desktop\rep-fonts\otfDemo.py", line 17, in embedOTF
  pdfmetrics.registerFont(TTFont("Source Sans Pro Black", otf_font))
File "C:\Python26\Lib\site-packages\reportlab\pdfbase\ttfonts.py", line 1009, in __init__
  self.face = TTFontFace(filename, validate=validate, subfontIndex=subfontIndex)
File "C:\Python26\Lib\site-packages\reportlab\pdfbase\ttfonts.py", line 915, in __init__
  TTFontFile.__init__(self, filename, validate=validate, subfontIndex=subfontIndex)
File "C:\Python26\Lib\site-packages\reportlab\pdfbase\ttfonts.py", line 412, in __init__
  TTFontParser.__init__(self, file, validate=validate,subfontIndex=subfontIndex)
File "C:\Python26\Lib\site-packages\reportlab\pdfbase\ttfonts.py", line 190, in __init__
  isCollection = self.readHeader()
File "C:\Python26\Lib\site-packages\reportlab\pdfbase\ttfonts.py", line 253, in readHeader
  raise TTFError('%s file "%s": postscript outlines are not supported'%(self.fileKind,self.filename))

Is there a way to make Reportlab accept this font or fonts like it?

Thanks,
Mike Driscoll

otfDemo.py

Tim Roberts

unread,
Jul 23, 2013, 12:48:54 PM7/23/13
to reportlab-users
Mike Driscoll wrote:
>
> After writing a tutorial on fonts in Reportlab, I got a comment asking
> if OTF fonts are supported. So far, I've found conflicting information.

OTF files are an odd beast. You can have OTF files that actually
contain TrueType font data, and you can have OTF files that actually
contain PostScript Type 2 font data. I know ReportLab supports TrueType
OTF files. I don't know that it supports PostScript OTF files.


> While this one says that if the font uses CFF format, Reportlab will
> spit out an error:

OTF/CFF fonts were not allowed in PDF files at all until PDF version
1.6, and I'm not sure ReportLab supports that.


> Is there a way to make Reportlab accept this font or fonts like it?

Submit a patch? ;)

--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

_______________________________________________
reportlab-users mailing list
reportl...@lists2.reportlab.com
http://two.pairlist.net/mailman/listinfo/reportlab-users

Robin Becker

unread,
Jul 24, 2013, 5:48:12 AM7/24/13
to reportlab-users, Tim Roberts
Currently we don't support postscript otf fonts.
--
Robin Becker


On 23/07/2013 17:48, Tim Roberts wrote:
> Mike Driscoll wrote:
>>
>> After writing a tutorial on fonts in Reportlab, I got a comment asking
>> if OTF fonts are supported. So far, I've found conflicting information.
>
> OTF files are an odd beast. You can have OTF files that actually
> contain TrueType font data, and you can have OTF files that actually
> contain PostScript Type 2 font data. I know ReportLab supports TrueType
> OTF files. I don't know that it supports PostScript OTF files.
>
>
>> While this one says that if the font uses CFF format, Reportlab will
>> spit out an error:
>
> OTF/CFF fonts were not allowed in PDF files at all until PDF version
> 1.6, and I'm not sure ReportLab supports that.
>
>
>> Is there a way to make Reportlab accept this font or fonts like it?
>
> Submit a patch? ;)
>



Andy Robinson

unread,
Jul 24, 2013, 6:01:37 AM7/24/13
to reportlab-users
On 23 July 2013 17:48, Tim Roberts <ti...@probo.com> wrote:
>> Is there a way to make Reportlab accept this font or fonts like it?
>
> Submit a patch? ;)
>
That would be nice!

I'm hoping to find time to review this next month. Part of the
problem is that we use third party extensions for rendering bitmaps in
charts which themselves did not easily support postscript-style OTF
files. Maybe they do now, maybe they don't - it needs some research.
It's obviously a desirable enhancement.

One paying customer asking for this, or one good patch from a
contributor, would of course make all the difference. Otherwise it
tends to just sit on the big wish list while we are busy with the
day-jobs....

- Andy
Reply all
Reply to author
Forward
0 new messages