Revision: 6737
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6737&view=rev
Author:   jouni
Date:     2009-01-05 17:48:01 +0000 (Mon, 05 Jan 2009)

Log Message:
-----------
Fix a bug in pdf usetex: allow using non-embedded fonts

Modified Paths:
--------------
    trunk/matplotlib/CHANGELOG
    trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py

Modified: trunk/matplotlib/CHANGELOG
===================================================================
--- trunk/matplotlib/CHANGELOG  2009-01-05 14:47:08 UTC (rev 6736)
+++ trunk/matplotlib/CHANGELOG  2009-01-05 17:48:01 UTC (rev 6737)
@@ -1,3 +1,5 @@
+2009-01-05 Fix a bug in pdf usetex: allow using non-embedded fonts. - JKS
+
 2009-01-05 optional use of preview.sty in usetex mode. - JJL
 
 2009-01-02 Allow multipage pdf files. - JKS

Modified: trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py     2009-01-05 
14:47:08 UTC (rev 6736)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py     2009-01-05 
17:48:01 UTC (rev 6737)
@@ -88,11 +88,9 @@
 # * the alpha channel of images
 # * image compression could be improved (PDF supports png-like compression)
 # * encoding of fonts, including mathtext fonts and unicode support
-# * Type 1 font support (i.e., "pdf.use_afm")
 # * TTF support has lots of small TODOs, e.g. how do you know if a font
 #   is serif/sans-serif, or symbolic/non-symbolic?
 # * draw_markers, draw_line_collection, etc.
-# * use_tex
 
 def fill(strings, linelen=75):
     """Make one string from sequence of strings, with whitespace
@@ -518,7 +516,7 @@
             elif self.dviFontInfo.has_key(filename):
                 # a Type 1 font from a dvi file; the filename is really the 
TeX name
                 matplotlib.verbose.report('Writing Type-1 font', 'debug')
-                fontdictObject = self.embedType1(filename, 
self.dviFontInfo[filename])
+                fontdictObject = self.embedTeXFont(filename, 
self.dviFontInfo[filename])
             else:
                 # a normal TrueType font
                 matplotlib.verbose.report('Writing TrueType font', 'debug')
@@ -542,53 +540,62 @@
         self.writeObject(fontdictObject, fontdict)
         return fontdictObject
 
-    def embedType1(self, texname, fontinfo):
+    def embedTeXFont(self, texname, fontinfo):
         matplotlib.verbose.report(
-            'Embedding ' + texname +
-            ' which is the Type 1 font ' + (fontinfo.fontfile or '(none)') +
-            ' with encoding ' + (fontinfo.encodingfile or '(none)') +
-            ' and effects ' + `fontinfo.effects`,
+            'Embedding TeX font ' + texname + ' - fontinfo=' + 
`fontinfo.__dict__`,
             'debug')
 
-        t1font = type1font.Type1Font(fontinfo.fontfile)
-        if fontinfo.effects:
-            t1font = t1font.transform(fontinfo.effects)
-
-        # Font descriptors may be shared between differently encoded
-        # Type-1 fonts, so only create a new descriptor if there is no
-        # existing descriptor for this font.
-        effects = (fontinfo.effects.get('slant', 0.0), 
fontinfo.effects.get('extend', 1.0))
-        fontdesc = self.type1Descriptors.get((fontinfo.fontfile, effects))
-        if fontdesc is None:
-            fontdesc = self.createType1Descriptor(t1font, fontinfo.fontfile)
-            self.type1Descriptors[(fontinfo.fontfile, effects)] = fontdesc
-
         # Widths
         widthsObject = self.reserveObject('font widths')
-        self.writeObject(widthsObject, fontinfo.widths)
+        self.writeObject(widthsObject, fontinfo.dvifont.widths)
 
         # Font dictionary
         fontdictObject = self.reserveObject('font dictionary')
         fontdict = {
-            'Type':           Name('Font'),
-            'Subtype':        Name('Type1'),
-            'BaseFont':       Name(t1font.prop['FontName']),
-            'FirstChar':      0,
-            'LastChar':       len(fontinfo.widths) - 1,
-            'Widths':         widthsObject,
-            'FontDescriptor': fontdesc,
-            }
+            'Type':      Name('Font'),
+            'Subtype':   Name('Type1'),
+            'FirstChar': 0,
+            'LastChar':  len(fontinfo.dvifont.widths) - 1,
+            'Widths':    widthsObject,
+            }            
 
         # Encoding (if needed)
         if fontinfo.encodingfile is not None:
             enc = dviread.Encoding(fontinfo.encodingfile)
             differencesArray = [ Name(ch) for ch in enc ]
             differencesArray = [ 0 ] + differencesArray
-            fontdict.update({
-                    'Encoding': { 'Type': Name('Encoding'),
-                                  'Differences': differencesArray },
-                    })
+            fontdict['Encoding'] = \
+                { 'Type': Name('Encoding'),
+                  'Differences': differencesArray }
 
+        # If no file is specified, stop short
+        if fontinfo.fontfile is None:
+            warnings.warn(
+                'Because of TeX configuration (pdftex.map, see updmap ' +
+                'option pdftexDownloadBase14) the font %s ' % 
fontinfo.basefont +
+                'is not embedded. This is deprecated as of PDF 1.5 ' +
+                'and it may cause the consumer application to show something ' 
+
+                'that was not intended.')
+            fontdict['BaseFont'] = Name(fontinfo.basefont)
+            self.writeObject(fontdictObject, fontdict)
+            return fontdictObject
+
+        # We have a font file to embed - read it in and apply any effects
+        t1font = type1font.Type1Font(fontinfo.fontfile)
+        if fontinfo.effects:
+            t1font = t1font.transform(fontinfo.effects)
+        fontdict['BaseFont'] = Name(t1font.prop['FontName'])
+
+        # Font descriptors may be shared between differently encoded
+        # Type-1 fonts, so only create a new descriptor if there is no
+        # existing descriptor for this font.
+        effects = (fontinfo.effects.get('slant', 0.0), 
fontinfo.effects.get('extend', 1.0))
+        fontdesc = self.type1Descriptors.get((fontinfo.fontfile, effects))
+        if fontdesc is None:
+            fontdesc = self.createType1Descriptor(t1font, fontinfo.fontfile)
+            self.type1Descriptors[(fontinfo.fontfile, effects)] = fontdesc
+        fontdict['FontDescriptor'] = fontdesc
+            
         self.writeObject(fontdictObject, fontdict)
         return fontdictObject
 
@@ -1389,11 +1396,12 @@
                 pdfname = self.file.fontName(dvifont.texname)
                 if not self.file.dviFontInfo.has_key(dvifont.texname):
                     psfont = self.tex_font_mapping(dvifont.texname)
+                    fontfile = psfont.filename
                     self.file.dviFontInfo[dvifont.texname] = Bunch(
                         fontfile=psfont.filename,
+                        basefont=psfont.psname,
                         encodingfile=psfont.encoding,
                         effects=psfont.effects,
-                        widths=dvifont.widths,
                         dvifont=dvifont)
                 seq += [['font', pdfname, dvifont.size]]
                 oldfont = dvifont


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
_______________________________________________
Matplotlib-checkins mailing list
Matplotlib-checkins@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to