[reportlab-users] embedding standard fonts
Robin Becker
robin at reportlab.com
Tue Jul 29 10:59:17 EDT 2008
adam hyde wrote:
>> ........
>> I thought this would be easy, but it seems we don't have the original afm files
>> for these fonts which measn we need to synthesize some as I believe they're not
>> freely available on the interweb. If we had them we could change the names in
>> the reportlab internal data structure to allow the embedding to proceed without
>> interfering with the standard fonts.
>>
>> I guess I'll try and think of a way to use the pfb file for embedding purposes
>> without having the afm.
>
> any way to kill the standard font name check so it will embed the fonts
> anyway? a little switch --embed-all or something...
>
> adam
>
>
>
All the standard fonts are registered in a different way ie by just naming them.
First we need to create a new font that uses the PFB data (which is what
actually will get embedded) and then some mechanism to obtain the metrics from
the standard font data.
So we need a simple override of EmbeddedType1Face that does approximately
class StdEmbeddedT1Face(EmbeddedType1Face):
def __init__(self,pfbFileName,stdName):
TypeFace.__init__(self, stdName)
self.stdName = stdName
self.pfbFileName = os.path.abspath(pfbFileName)
self.requiredEncoding = None
self._loadGlyphs(pfbFileName)
self._loadMetrics(stdName)
def _loadMetrics(self,stdName):
.......
and then we need to do stuff to inhibit the normal registration of the standard
fonts and promote the embedded registration for the actually used fonts. Since
these fonts are supposed to be standard and there are many assumptions related
to their implicitness presence that will probably be hard.
I guess you definitely need to eliminate the standard registration as your
printer will be looking for the font.
Perhaps it might be easier to try and inhibit the normal font registration, but
use some other fonts instead?
What happens when you try this
def run():
from reportlab.pdfgen.canvas import Canvas
from reportlab.pdfbase.pdfdoc import PDFName
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.pdfbase.pdfmetrics import registerFont
from reportlab.pdfbase import pdfdoc
from reportlab import rl_config
registerFont(TTFont('Vera','c:/code/reportlab/fonts/vera.ttf'))
rl_config.canvas_basefontname='Vera'
rl_config.invariant = 1
rl_config.pageCompression = 0
c = Canvas('trl_hello.pdf')
c.setFont('Vera', 36)
c.drawString(100,700, 'Hello World')
c.setViewerPreference('PrintScaling',PDFName('None'))
c.save()
if __name__=='__main__':
run()
substitute the right path to vera.ttf. This doesn't use the standard names at
all (at least in the pdf output).
--
Robin Becker
More information about the reportlab-users
mailing list