[reportlab-users] embedding standard fonts

adam hyde adam at flossmanuals.net
Tue Jul 29 12:50:24 EDT 2008


hey

I think i just pass it thru gs:

gs -dSAFER -dNOPLATFONTS -dNOPAUSE -dBATCH -sDEVICE=pdfwrite
-sPAPERSIZE=letter -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer
-dCompatibilityLevel=1.4 -dMaxSubsetPct=100 -dSubsetFonts=true
-dEmbedAllFonts=true -sOutputFile=fm-new.pdf -f fm.pdf



adam


On Tue, 2008-07-29 at 15:59 +0100, Robin Becker wrote:

> 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).

--
Adam Hyde
FLOSS Manuals

http://www.flossmanuals.net
+ 31 6 2808 7108
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : <http://two.pairlist.net/pipermail/reportlab-users/attachments/20080729/221b44ac/attachment.pgp>


More information about the reportlab-users mailing list