|
From: <jo...@us...> - 2007-09-04 18:19:20
|
Revision: 3775
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3775&view=rev
Author: jouni
Date: 2007-09-04 11:19:16 -0700 (Tue, 04 Sep 2007)
Log Message:
-----------
More work on supporting Type 1 fonts in PDF,
still doesn't produce usable files.
Modified Paths:
--------------
trunk/matplotlib/API_CHANGES
trunk/matplotlib/lib/matplotlib/afm.py
trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
trunk/matplotlib/lib/matplotlib/dviread.py
Modified: trunk/matplotlib/API_CHANGES
===================================================================
--- trunk/matplotlib/API_CHANGES 2007-09-04 14:52:03 UTC (rev 3774)
+++ trunk/matplotlib/API_CHANGES 2007-09-04 18:19:16 UTC (rev 3775)
@@ -15,7 +15,8 @@
to read an afm file in addition to a pfa/pfb file, to get metrics
and kerning information for a Type 1 font.
- The AFM class now supports querying CapHeight and stem widths.
+ The AFM class now supports querying CapHeight and stem widths. The
+ get_name_char method now has an isord kwarg like get_width_char.
Changed pcolor default to shading='flat'; but as noted now in the
docstring, it is preferable to simply use the edgecolor kwarg.
Modified: trunk/matplotlib/lib/matplotlib/afm.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/afm.py 2007-09-04 14:52:03 UTC (rev 3774)
+++ trunk/matplotlib/lib/matplotlib/afm.py 2007-09-04 18:19:16 UTC (rev 3775)
@@ -378,11 +378,12 @@
"""
return self.get_str_bbox_and_descent(s)[:4]
- def get_name_char(self, c):
+ def get_name_char(self, c, isord=False):
"""
Get the name of the character, ie, ';' is 'semicolon'
"""
- wx, name, bbox = self._metrics[ord(c)]
+ if not isord: c=ord(c)
+ wx, name, bbox = self._metrics[c]
return name
def get_width_char(self, c, isord=False):
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py 2007-09-04 14:52:03 UTC (rev 3774)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py 2007-09-04 18:19:16 UTC (rev 3775)
@@ -18,6 +18,7 @@
from math import ceil, cos, floor, pi, sin
from sets import Set
+import matplotlib
from matplotlib import __version__, rcParams, agg, get_data_path
from matplotlib._pylab_helpers import Gcf
from matplotlib.backend_bases import RendererBase, GraphicsContextBase,\
@@ -493,12 +494,16 @@
def embedType1(self, filename, fontinfo):
fh = open(filename, 'rb')
+ matplotlib.verbose.report(
+ 'Embedding Type 1 font ' + filename, 'debug')
try:
fontdata = fh.read()
finally:
fh.close()
fh = open(fontinfo.afmfile, 'rb')
+ matplotlib.verbose.report(
+ 'Reading metrics from ' + fontinfo.afmfile, 'debug')
try:
afmdata = AFM(fh)
finally:
@@ -519,9 +524,26 @@
differencesArray = [ Name(ch) for ch in
dviread.Encoding(fontinfo.encodingfile) ]
differencesArray = [ 0 ] + differencesArray
+ firstchar = 0
lastchar = len(differencesArray) - 2
+ widths = [ 100 for x in range(firstchar,lastchar+1) ] # XXX TODO
else:
- lastchar = 255 # ?
+ widths = [ None for i in range(256) ]
+ for ch in range(256):
+ try:
+ widths[ch] = afmdata.get_width_char(ch, isord=True)
+ except KeyError:
+ pass
+ not_None = (ch for ch in range(256)
+ if widths[ch] is not None)
+ firstchar = not_None.next()
+ lastchar = max(not_None)
+ widths = widths[firstchar:lastchar+1]
+
+ differencesArray = [ firstchar ]
+ for ch in range(firstchar, lastchar+1):
+ differencesArray.append(Name(
+ afmdata.get_name_char(ch, isord=True)))
fontdict = {
'Type': Name('Font'),
@@ -533,16 +555,15 @@
'FontDescriptor': fontdescObject,
}
- if fontinfo.encodingfile is not None:
- fontdict.update({
- 'Encoding': { 'Type': Name('Encoding'),
- 'Differences': differencesArray },
- })
+ fontdict.update({
+ 'Encoding': { 'Type': Name('Encoding'),
+ 'Differences': differencesArray },
+ })
flags = 0
if fixed_pitch: flags |= 1 << 0 # fixed width
if 0: flags |= 1 << 1 # TODO: serif
- if 0: flags |= 1 << 2 # TODO: symbolic
+ if 1: flags |= 1 << 2 # TODO: symbolic
else: flags |= 1 << 5 # non-symbolic
if italic_angle: flags |= 1 << 6 # italic
if 0: flags |= 1 << 16 # TODO: all caps
@@ -557,12 +578,16 @@
'ItalicAngle': italic_angle,
'Ascent': font.ascender,
'Descent': font.descender,
- 'CapHeight': afmdata.get_capheight(),
+ 'CapHeight': 1000, # default guess if missing from AFM file
'XHeight': afmdata.get_xheight(),
'FontFile': fontfileObject,
'FontFamily': Name(familyname),
#'FontWeight': a number where 400 = Regular, 700 = Bold
}
+ try:
+ descriptor['CapHeight'] = afmdata.get_capheight()
+ except KeyError:
+ pass
# StemV is obligatory in PDF font descriptors but optional in
# AFM files. The collection of AFM files in my TeX Live 2007
@@ -579,7 +604,7 @@
descriptor['StemH'] = StemH
self.writeObject(fontdictObject, fontdict)
- self.writeObject(widthsObject, [ 100 for i in range(256)]) # XXX TODO
+ self.writeObject(widthsObject, widths)
self.writeObject(fontdescObject, descriptor)
fontdata = type1font.Type1Font(filename)
@@ -591,6 +616,8 @@
self.currentstream.write(fontdata.data)
self.endStream()
+ return fontdictObject
+
def _get_xobject_symbol_name(self, filename, symbol_name):
return "%s-%s" % (
os.path.splitext(os.path.basename(filename))[0],
Modified: trunk/matplotlib/lib/matplotlib/dviread.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/dviread.py 2007-09-04 14:52:03 UTC (rev 3774)
+++ trunk/matplotlib/lib/matplotlib/dviread.py 2007-09-04 18:19:16 UTC (rev 3775)
@@ -35,6 +35,7 @@
opens the file; actually reading the file happens when
iterating through the pages of the file.
"""
+ matplotlib.verbose.report('Dvi: ' + filename, 'debug')
self.file = open(filename, 'rb')
self.dpi = dpi
self.fonts = {}
@@ -57,7 +58,7 @@
while True:
have_page = self._read()
if have_page:
- yield self.text, self.boxes
+ yield self._output()
else:
break
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|