SourceForge logo
SourceForge logo
Menu

matplotlib-checkins

Revision: 3619
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3619&view=rev
Author: mdboom
Date: 2007年07月26日 11:40:36 -0700 (2007年7月26日)
Log Message:
-----------
Fix bug in pdf backend (numpy.inf not numpy.infinity)
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py	2007年07月26日 14:47:27 UTC (rev 3618)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py	2007年07月26日 18:40:36 UTC (rev 3619)
@@ -112,7 +112,7 @@
 # need to use %f with some precision. Perhaps the precision
 # should adapt to the magnitude of the number?
 elif isinstance(obj, float):
- if npy.isnan(obj) or obj in (-npy.infinity, npy.infinity):
+ if npy.isnan(obj) or obj in (-npy.inf, npy.inf):
 raise ValueError, "Can only output finite numbers in PDF"
 r = "%.10f" % obj
 return r.rstrip('0').rstrip('.')
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 3622
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3622&view=rev
Author: jouni
Date: 2007年07月26日 14:13:58 -0700 (2007年7月26日)
Log Message:
-----------
Numpy has isfinite, unlike the old numerix
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py	2007年07月26日 19:44:35 UTC (rev 3621)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py	2007年07月26日 21:13:58 UTC (rev 3622)
@@ -112,7 +112,7 @@
 # need to use %f with some precision. Perhaps the precision
 # should adapt to the magnitude of the number?
 elif isinstance(obj, float):
- if npy.isnan(obj) or obj in (-npy.inf, npy.inf):
+ if not npy.isfinite(obj):
 raise ValueError, "Can only output finite numbers in PDF"
 r = "%.10f" % obj
 return r.rstrip('0').rstrip('.')
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 3674
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3674&view=rev
Author: mdboom
Date: 2007年08月06日 11:49:19 -0700 (2007年8月06日)
Log Message:
-----------
Fix bug when rendering character codes > 255 in PDF
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py	2007年08月03日 19:47:49 UTC (rev 3673)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py	2007年08月06日 18:49:19 UTC (rev 3674)
@@ -1103,7 +1103,7 @@
 oldx, oldy = 0, 0
 for record in pswriter:
 if record[0] == 'glyph':
- rec_type, ox, oy, fontname, fontsize, glyph = record
+ rec_type, ox, oy, fontname, fontsize, num = record
 a = angle / 180.0 * pi
 newx = x + cos(a)*ox - sin(a)*oy
 newy = y + sin(a)*ox + cos(a)*oy
@@ -1114,7 +1114,10 @@
 Op.selectfont)
 prev_font = fontname, fontsize
 
- string = chr(glyph)
+ if num < 256:
+ string = chr(num)
+ else:
+ string = "?"
 self.file.output(string, Op.show)
 self.file.output(Op.end_text)
 
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 3684
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3684&view=rev
Author: mdboom
Date: 2007年08月08日 09:46:54 -0700 (2007年8月08日)
Log Message:
-----------
Add support for fonts with more than 256 codepoints in PDF backend.
This currently only works when pdf.fonttype == 42. (It doesn't seem
possible to have a CID-keyed Type 3 font in PDF, so some hacky
solution will have to be developed.)
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py	2007年08月08日 16:44:38 UTC (rev 3683)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py	2007年08月08日 16:46:54 UTC (rev 3684)
@@ -28,7 +28,7 @@
 from matplotlib.font_manager import fontManager
 from matplotlib.afm import AFM
 from matplotlib.dviread import Dvi
-from matplotlib.ft2font import FT2Font, FIXED_WIDTH, ITALIC, LOAD_NO_SCALE, LOAD_NO_HINTING
+from matplotlib.ft2font import FT2Font, FIXED_WIDTH, ITALIC, LOAD_NO_SCALE
 from matplotlib.mathtext import math_parse_s_pdf
 from matplotlib.transforms import Bbox
 from matplotlib import ttconv
@@ -491,124 +491,52 @@
 # boxes and the like
 if value < 0: return floor(value)
 else: return ceil(value)
-
- # You are lost in a maze of TrueType tables, all different...
- ps_name = Name(font.get_sfnt()[(1,0,0,6)])
- pclt = font.get_sfnt_table('pclt') \
- or { 'capHeight': 0, 'xHeight': 0 }
- post = font.get_sfnt_table('post') \
- or { 'italicAngle': (0,0) }
- ff = font.face_flags
- sf = font.style_flags
-
- # Get widths for the 256 characters of PDF encoding "WinAnsiEncoding" (similar to
- # Python encoding "cp1252"). According to the PDF Reference, a simple font, based on
- # single-byte characters, can't manage more than 256 characters, contrary to a
- # composite font, based on multi-byte characters.
-
- from encodings import cp1252
- # The "decoding_map" was changed to a "decoding_table" as of Python 2.5.
- if hasattr(cp1252, 'decoding_map'):
- def decode_char(charcode):
- return cp1252.decoding_map[charcode] or 0
- else:
- def decode_char(charcode):
- return ord(cp1252.decoding_table[charcode])
-
- def get_char_width(charcode):
- unicode = decode_char(charcode)
- width = font.load_char(unicode, flags=LOAD_NO_SCALE|LOAD_NO_HINTING).horiAdvance
- return cvt(width)
-
- firstchar, lastchar = 0, 255
- widths = [ get_char_width(charcode) for charcode in range(firstchar, lastchar+1) ]
- font_bbox = [ cvt(x, nearest=False) for x in font.bbox ]
-
- widthsObject = self.reserveObject('font widths')
- fontdescObject = self.reserveObject('font descriptor')
- # TODO: "WinAnsiEncoding" could become a parameter of PdfFile. The PDF encoding
- # "WinAnsiEncoding" matches the Python enconding "cp1252" used in method
- # RendererPdf.draw_text and RendererPdf.get_text_width_height to encode Unicode strings.
- fontdict = { 'Type': Name('Font'),
- 'BaseFont': ps_name,
- 'FirstChar': firstchar,
- 'LastChar': lastchar,
- 'Widths': widthsObject,
- 'FontDescriptor': fontdescObject }
-
- if fonttype == 3:
+ 
+ def embedTTFType3(font, characters, descriptor):
+ """The Type 3-specific part of embedding a Truetype font"""
+ widthsObject = self.reserveObject('font widths')
+ fontdescObject = self.reserveObject('font descriptor')
+ fontdictObject = self.reserveObject('font dictionary')
 charprocsObject = self.reserveObject('character procs')
 differencesArray = []
- fontdict['Subtype'] = Name('Type3')
- fontdict['Name'] = ps_name
- fontdict['FontBBox'] = font_bbox
- fontdict['FontMatrix'] = [ .001, 0, 0, .001, 0, 0 ]
- fontdict['CharProcs'] = charprocsObject
- fontdict['Encoding'] = {
- 'Type': Name('Encoding'),
- 'Differences': differencesArray}
- elif fonttype == 42:
- fontdict['Subtype'] = Name('TrueType')
- fontdict['Encoding'] = Name('WinAnsiEncoding')
+ firstchar, lastchar = 0, 255
+ 
+ fontdict = {
+ 'Type' : Name('Font'),
+ 'BaseFont' : ps_name,
+ 'FirstChar' : firstchar,
+ 'LastChar' : lastchar,
+ 'FontDescriptor' : fontdescObject,
+ 'Subtype' : Name('Type3'),
+ 'Name' : descriptor['FontName'],
+ 'FontBBox' : [cvt(x, nearest=False) for x in font.bbox],
+ 'FontMatrix' : [ .001, 0, 0, .001, 0, 0 ],
+ 'CharProcs' : charprocsObject,
+ 'Encoding' : {
+ 'Type' : Name('Encoding'),
+ 'Differences' : differencesArray},
+ 'Widths' : widthsObject
+ }
 
+ # Make the "Widths" array
+ from encodings import cp1252
+ # The "decoding_map" was changed to a "decoding_table" as of Python 2.5.
+ if hasattr(cp1252, 'decoding_map'):
+ def decode_char(charcode):
+ return cp1252.decoding_map[charcode] or 0
+ else:
+ def decode_char(charcode):
+ return ord(cp1252.decoding_table[charcode])
 
- flags = 0
- symbolic = False #ps_name.name in ('Cmsy10', 'Cmmi10', 'Cmex10')
- if ff & FIXED_WIDTH: flags |= 1 << 0
- if 0: flags |= 1 << 1 # TODO: serif
- if symbolic: flags |= 1 << 2
- else: flags |= 1 << 5
- if sf & ITALIC: flags |= 1 << 6
- if 0: flags |= 1 << 16 # TODO: all caps
- if 0: flags |= 1 << 17 # TODO: small caps
- if 0: flags |= 1 << 18 # TODO: force bold
+ def get_char_width(charcode):
+ unicode = decode_char(charcode)
+ width = font.load_char(unicode, flags=LOAD_NO_SCALE).horiAdvance
+ return cvt(width)
 
- descriptor = {
- 'Type': Name('FontDescriptor'),
- 'FontName': ps_name,
- 'Flags': flags,
- 'FontBBox': [ cvt(x, nearest=False) for x in font.bbox ],
- 'Ascent': cvt(font.ascender, nearest=False),
- 'Descent': cvt(font.descender, nearest=False),
- 'CapHeight': cvt(pclt['capHeight'], nearest=False),
- 'XHeight': cvt(pclt['xHeight']),
- 'ItalicAngle': post['italicAngle'][1], # ???
- 'MaxWidth': max(widths),
- 'StemV': 0 # ???
- }
+ widths = [ get_char_width(charcode) for charcode in range(firstchar, lastchar+1) ]
+ descriptor['MaxWidth'] = max(widths)
 
- if fonttype == 42:
- descriptor['FontFile2'] = self.reserveObject('font file')
-
- # Other FontDescriptor keys include:
- # /FontFamily /Times (optional)
- # /FontStretch /Normal (optional)
- # /FontFile (stream for type 1 font)
- # /CharSet (used when subsetting type1 fonts)
-
- # Make an Identity-H encoded CID font for CM fonts? (Doesn't quite work)
- if False:
- del fontdict['Widths'], fontdict['FontDescriptor'], \
- fontdict['LastChar'], fontdict['FirstChar']
-
- fontdict['Subtype'] = Name('Type0')
- fontdict['Encoding'] = Name('Identity-H')
- fontdict2Object = self.reserveObject('descendant font')
- fontdict['DescendantFonts'] = [ fontdict2Object ]
- # TODO: fontdict['ToUnicode']
- fontdict2 = { 'Type': Name('Font'),
- 'Subtype': Name('CIDFontType2'),
- 'BaseFont': ps_name,
- 'W': widthsObject,
- 'CIDSystemInfo': { 'Registry': 'Adobe',
- 'Ordering': 'Identity',
- 'Supplement': 0 },
- 'FontDescriptor': fontdescObject }
- self.writeObject(fontdict2Object, fontdict2)
-
- widths = [ firstchar, widths ]
-
- if fonttype == 3:
+ # Make the "Differences" array
 cmap = font.get_charmap()
 glyph_ids = []
 differences = []
@@ -626,6 +554,8 @@
 differencesArray.append(Name(name))
 last_c = c
 
+ # Make the charprocs array (using ttconv for the
+ # actual outlines)
 rawcharprocs = ttconv.get_pdf_charprocs(filename, glyph_ids)
 charprocs = {}
 charprocsRef = {}
@@ -637,13 +567,52 @@
 self.currentstream.write(stream)
 self.endStream()
 charprocs[charname] = charprocObject
+
+ # Write everything out
+ self.writeObject(fontdictObject, fontdict)
+ self.writeObject(fontdescObject, descriptor)
+ self.writeObject(widthsObject, widths)
 self.writeObject(charprocsObject, charprocs)
 
- elif fonttype == 42:
+ return fontdictObject
+
+ def embedTTFType42(font, characters, descriptor):
+ """The Type 42-specific part of embedding a Truetype font"""
+ fontdescObject = self.reserveObject('font descriptor')
+ cidFontDictObject = self.reserveObject('CID font dictionary')
+ type0FontDictObject = self.reserveObject('Type 0 font dictionary')
+ cidToGidMapObject = self.reserveObject('CIDToGIDMap stream')
+ fontfileObject = self.reserveObject('font file stream')
+ wObject = self.reserveObject('Type 0 widths')
+
+ cidFontDict = {
+ 'Type' : Name('Font'),
+ 'Subtype' : Name('CIDFontType2'),
+ 'BaseFont' : ps_name,
+ 'CIDSystemInfo' : {
+ 'Registry' : 'Adobe',
+ 'Ordering' : 'Identity',
+ 'Supplement' : 0 },
+ 'FontDescriptor' : fontdescObject,
+ 'W' : wObject,
+ 'CIDToGIDMap' : cidToGidMapObject
+ }
+
+ type0FontDict = {
+ 'Type' : Name('Font'),
+ 'Subtype' : Name('Type0'),
+ 'BaseFont' : ps_name,
+ 'Encoding' : Name('Identity-H'),
+ 'DescendantFonts' : [cidFontDictObject]
+ }
+
+ # Make fontfile stream
+ descriptor['FontFile2'] = fontfileObject
 length1Object = self.reserveObject('decoded length of a font')
- self.beginStream(descriptor['FontFile2'].id,
- self.reserveObject('length of font stream'),
- {'Length1': length1Object})
+ self.beginStream(
+ fontfileObject.id,
+ self.reserveObject('length of font stream'),
+ {'Length1': length1Object})
 fontfile = open(filename, 'rb')
 length1 = 0
 while True:
@@ -655,13 +624,92 @@
 self.endStream()
 self.writeObject(length1Object, length1)
 
- fontdictObject = self.reserveObject('font dictionary')
- self.writeObject(fontdictObject, fontdict)
- self.writeObject(widthsObject, widths)
- self.writeObject(fontdescObject, descriptor)
+ # Make the 'W' (Widths) array and the CidToGidMap at the same time
+ cid_to_gid_map = [u'\u0000'] * 65536
+ cmap = font.get_charmap()
+ widths = []
+ max_ccode = 0
+ for c in characters:
+ ccode = ord(c)
+ gind = cmap.get(ccode) or 0
+ glyph = font.load_char(ccode)
+ # Why divided by 3.0 ??? Wish I knew... MGD
+ widths.append((ccode, cvt(glyph.horiAdvance) / 3.0))
+ cid_to_gid_map[ccode] = unichr(gind)
+ max_ccode = max(ccode, max_ccode)
+ widths.sort()
+ cid_to_gid_map = cid_to_gid_map[:max_ccode + 1]
+ 
+ last_ccode = -2
+ w = []
+ max_width = 0
+ for ccode, width in widths:
+ if ccode != last_ccode + 1:
+ w.append(ccode)
+ w.append([width])
+ else:
+ w[-1].append(width)
+ max_width = max(max_width, width)
+ last_ccode = ccode
 
- return fontdictObject
+ # CIDToGIDMap stream
+ cid_to_gid_map = "".join(cid_to_gid_map).encode("utf-16be")
+ self.beginStream(cidToGidMapObject.id,
+ None,
+ {'Length': len(cid_to_gid_map)})
+ self.currentstream.write(cid_to_gid_map)
+ self.endStream()
 
+ descriptor['MaxWidth'] = max_width
+ 
+ # Write everything out
+ self.writeObject(cidFontDictObject, cidFontDict)
+ self.writeObject(type0FontDictObject, type0FontDict)
+ self.writeObject(fontdescObject, descriptor)
+ self.writeObject(wObject, w)
+
+ return type0FontDictObject
+
+ # Beginning of main embedTTF function...
+ 
+ # You are lost in a maze of TrueType tables, all different...
+ ps_name = Name(font.get_sfnt()[(1,0,0,6)])
+ pclt = font.get_sfnt_table('pclt') \
+ or { 'capHeight': 0, 'xHeight': 0 }
+ post = font.get_sfnt_table('post') \
+ or { 'italicAngle': (0,0) }
+ ff = font.face_flags
+ sf = font.style_flags
+
+ flags = 0
+ symbolic = False #ps_name.name in ('Cmsy10', 'Cmmi10', 'Cmex10')
+ if ff & FIXED_WIDTH: flags |= 1 << 0
+ if 0: flags |= 1 << 1 # TODO: serif
+ if symbolic: flags |= 1 << 2
+ else: flags |= 1 << 5
+ if sf & ITALIC: flags |= 1 << 6
+ if 0: flags |= 1 << 16 # TODO: all caps
+ if 0: flags |= 1 << 17 # TODO: small caps
+ if 0: flags |= 1 << 18 # TODO: force bold
+
+ descriptor = {
+ 'Type' : Name('FontDescriptor'),
+ 'FontName' : ps_name,
+ 'Flags' : flags,
+ 'FontBBox' : [ cvt(x, nearest=False) for x in font.bbox ],
+ 'Ascent' : cvt(font.ascender, nearest=False),
+ 'Descent' : cvt(font.descender, nearest=False),
+ 'CapHeight' : cvt(pclt['capHeight'], nearest=False),
+ 'XHeight' : cvt(pclt['xHeight']),
+ 'ItalicAngle' : post['italicAngle'][1], # ???
+ 'StemV' : 0 # ???
+ }
+
+ if fonttype == 3:
+ return embedTTFType3(font, characters, descriptor)
+ elif fonttype == 42:
+ return embedTTFType42(font, characters, descriptor)
+ 
 def alphaState(self, alpha):
 """Return name of an ExtGState that sets alpha to the given value"""
 
@@ -1113,12 +1161,7 @@
 self.file.output(self.file.fontName(fontname), fontsize,
 Op.selectfont)
 prev_font = fontname, fontsize
-
- if num < 256:
- string = chr(num)
- else:
- string = "?"
- self.file.output(string, Op.show)
+ self.file.output(self.encode_string(unichr(num)), Op.show)
 self.file.output(Op.end_text)
 
 for record in pswriter:
@@ -1178,12 +1221,14 @@
 self.draw_polygon(boxgc, gc._rgb,
 ((x1,y1), (x2,y2), (x3,y3), (x4,y4)))
 
+ def encode_string(self, s):
+ if rcParams['pdf.fonttype'] == 42:
+ return s.encode('utf-16be', 'replace')
+ return s.encode('cp1252', 'replace')
+ 
 def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
 # TODO: combine consecutive texts into one BT/ET delimited section
 
- if isinstance(s, unicode):
- s = s.encode('cp1252', 'replace')
-
 if ismath: return self.draw_mathtext(gc, x, y, s, prop, angle)
 self.check_gc(gc, gc._rgb)
 
@@ -1195,7 +1240,7 @@
 else:
 font = self._get_font_ttf(prop)
 self.track_characters(font, s)
- font.set_text(s, 0.0, flags=LOAD_NO_HINTING)
+ font.set_text(s, 0.0)
 y += font.get_descent() / 64.0
 
 self.file.output(Op.begin_text,
@@ -1204,7 +1249,8 @@
 Op.selectfont)
 
 self._setup_textpos(x, y, angle)
- self.file.output(s, Op.show, Op.end_text)
+ 
+ self.file.output(self.encode_string(s), Op.show, Op.end_text)
 
 def get_text_width_height(self, s, prop, ismath):
 if isinstance(s, unicode):
@@ -1222,7 +1268,7 @@
 
 else:
 font = self._get_font_ttf(prop)
- font.set_text(s, 0.0, flags=LOAD_NO_HINTING)
+ font.set_text(s, 0.0)
 w, h = font.get_width_height()
 w /= 64.0
 h /= 64.0
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 3686
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3686&view=rev
Author: mdboom
Date: 2007年08月08日 09:52:44 -0700 (2007年8月08日)
Log Message:
-----------
Load characters without hinting for PDF output.
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py	2007年08月08日 16:48:48 UTC (rev 3685)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py	2007年08月08日 16:52:44 UTC (rev 3686)
@@ -28,7 +28,7 @@
 from matplotlib.font_manager import fontManager
 from matplotlib.afm import AFM
 from matplotlib.dviread import Dvi
-from matplotlib.ft2font import FT2Font, FIXED_WIDTH, ITALIC, LOAD_NO_SCALE
+from matplotlib.ft2font import FT2Font, FIXED_WIDTH, ITALIC, LOAD_NO_SCALE, LOAD_NO_HINTING
 from matplotlib.mathtext import math_parse_s_pdf
 from matplotlib.transforms import Bbox
 from matplotlib import ttconv
@@ -530,7 +530,7 @@
 
 def get_char_width(charcode):
 unicode = decode_char(charcode)
- width = font.load_char(unicode, flags=LOAD_NO_SCALE).horiAdvance
+ width = font.load_char(unicode, flags=LOAD_NO_SCALE|LOAD_NO_HINTING).horiAdvance
 return cvt(width)
 
 widths = [ get_char_width(charcode) for charcode in range(firstchar, lastchar+1) ]
@@ -632,7 +632,7 @@
 for c in characters:
 ccode = ord(c)
 gind = cmap.get(ccode) or 0
- glyph = font.load_char(ccode)
+ glyph = font.load_char(ccode, flags=LOAD_NO_HINTING)
 # Why divided by 3.0 ??? Wish I knew... MGD
 widths.append((ccode, cvt(glyph.horiAdvance) / 3.0))
 cid_to_gid_map[ccode] = unichr(gind)
@@ -1240,7 +1240,7 @@
 else:
 font = self._get_font_ttf(prop)
 self.track_characters(font, s)
- font.set_text(s, 0.0)
+ font.set_text(s, 0.0, flags=LOAD_NO_HINTING)
 y += font.get_descent() / 64.0
 
 self.file.output(Op.begin_text,
@@ -1268,7 +1268,7 @@
 
 else:
 font = self._get_font_ttf(prop)
- font.set_text(s, 0.0)
+ font.set_text(s, 0.0, flags=LOAD_NO_HINTING)
 w, h = font.get_width_height()
 w /= 64.0
 h /= 64.0
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 3691
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3691&view=rev
Author: mdboom
Date: 2007年08月09日 07:39:11 -0700 (2007年8月09日)
Log Message:
-----------
Removed some unnecessary imports.
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py	2007年08月09日 14:23:46 UTC (rev 3690)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py	2007年08月09日 14:39:11 UTC (rev 3691)
@@ -30,7 +30,7 @@
 from matplotlib.ft2font import FT2Font, FIXED_WIDTH, ITALIC, LOAD_NO_SCALE, \
 LOAD_NO_HINTING, KERNING_UNFITTED
 from matplotlib.mathtext import math_parse_s_pdf
-from matplotlib.transforms import Bbox, Affine, multiply_affines, Value
+from matplotlib.transforms import Bbox
 from matplotlib import ttconv
 
 # Overview
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 3695
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3695&view=rev
Author: mdboom
Date: 2007年08月09日 08:14:59 -0700 (2007年8月09日)
Log Message:
-----------
Minor PDF filesize improvement.
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py	2007年08月09日 15:14:28 UTC (rev 3694)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py	2007年08月09日 15:14:59 UTC (rev 3695)
@@ -508,6 +508,7 @@
 charprocsObject = self.reserveObject('character procs')
 differencesArray = []
 firstchar, lastchar = 0, 255
+ bbox = [cvt(x, nearest=False) for x in font.bbox]
 
 fontdict = {
 'Type' : Name('Font'),
@@ -517,7 +518,7 @@
 'FontDescriptor' : fontdescObject,
 'Subtype' : Name('Type3'),
 'Name' : descriptor['FontName'],
- 'FontBBox' : [cvt(x, nearest=False) for x in font.bbox],
+ 'FontBBox' : bbox,
 'FontMatrix' : [ .001, 0, 0, .001, 0, 0 ],
 'CharProcs' : charprocsObject,
 'Encoding' : {
@@ -575,15 +576,18 @@
 charprocs = {}
 charprocsRef = {}
 for charname, stream in rawcharprocs.items():
+ charprocDict = { 'Length': len(stream) }
+ # The 2-byte characters are used as XObjects, so they
+ # need extra info in their dictionary
+ if charname in two_byte_chars:
+ charprocDict['Type'] = Name('XObject')
+ charprocDict['Subtype'] = Name('Form')
+ charprocDict['BBox'] = bbox
 charprocObject = self.reserveObject('charProc for %s' % name)
- self.beginStream(charprocObject.id,
- None,
- {'Length': len(stream),
- 'Type': Name('XObject'),
- 'Subtype': Name('Form'),
- 'BBox': [cvt(x, nearest=False) for x in font.bbox]})
+ self.beginStream(charprocObject.id, None, charprocDict)
 self.currentstream.write(stream)
 self.endStream()
+
 # Send the glyphs with ccode > 255 to the XObject dictionary,
 # and the others to the font itself
 if charname in two_byte_chars:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 3708
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3708&view=rev
Author: mdboom
Date: 2007年08月14日 06:22:56 -0700 (2007年8月14日)
Log Message:
-----------
Make searching and copy/paste work in Pdf files (by adding a ToUnicode
CMap). Only works with Type42 fonts.
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py	2007年08月14日 07:07:45 UTC (rev 3707)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py	2007年08月14日 13:22:56 UTC (rev 3708)
@@ -485,6 +485,27 @@
 os.path.splitext(os.path.basename(filename))[0],
 symbol_name)
 
+ _identityToUnicodeCMap = """/CIDInit /ProcSet findresource begin
+12 dict begin
+begincmap
+/CIDSystemInfo
+<< /Registry (Adobe)
+ /Ordering (UCS)
+ /Supplement 0
+>> def
+/CMapName /Adobe-Identity-UCS def
+/CMapType 2 def
+1 begincodespacerange
+<0000> <ffff>
+endcodespacerange
+%d beginbfrange
+%s
+endbfrange
+endcmap
+CMapName currentdict /CMap defineresource pop
+end
+end"""
+ 
 def embedTTF(self, filename, characters):
 """Embed the TTF font from the named file into the document."""
 
@@ -612,6 +633,7 @@
 cidToGidMapObject = self.reserveObject('CIDToGIDMap stream')
 fontfileObject = self.reserveObject('font file stream')
 wObject = self.reserveObject('Type 0 widths')
+ toUnicodeMapObject = self.reserveObject('ToUnicode map')
 
 cidFontDict = {
 'Type' : Name('Font'),
@@ -631,7 +653,8 @@
 'Subtype' : Name('Type0'),
 'BaseFont' : ps_name,
 'Encoding' : Name('Identity-H'),
- 'DescendantFonts' : [cidFontDictObject]
+ 'DescendantFonts' : [cidFontDictObject],
+ 'ToUnicode' : toUnicodeMapObject
 }
 
 # Make fontfile stream
@@ -652,9 +675,11 @@
 self.endStream()
 self.writeObject(length1Object, length1)
 
- # Make the 'W' (Widths) array and the CidToGidMap at the same time
+ # Make the 'W' (Widths) array, CidToGidMap and ToUnicode CMap
+ # at the same time
 cid_to_gid_map = [u'\u0000'] * 65536
 cmap = font.get_charmap()
+ unicode_mapping = []
 widths = []
 max_ccode = 0
 for c in characters:
@@ -671,15 +696,28 @@
 last_ccode = -2
 w = []
 max_width = 0
+ unicode_groups = []
 for ccode, width in widths:
 if ccode != last_ccode + 1:
 w.append(ccode)
 w.append([width])
+ unicode_groups.append([ccode, ccode])
 else:
 w[-1].append(width)
+ unicode_groups[-1][1] = ccode
 max_width = max(max_width, width)
 last_ccode = ccode
 
+ unicode_bfrange = []
+ for start, end in unicode_groups:
+ unicode_bfrange.append(
+ "<%04x> <%04x> [%s]" %
+ (start, end,
+ " ".join(["<%04x>" % x for x in range(start, end+1)])))
+ unicode_cmap = (self._identityToUnicodeCMap %
+ (len(unicode_groups),
+ "\n".join(unicode_bfrange)))
+ 
 # CIDToGIDMap stream
 cid_to_gid_map = "".join(cid_to_gid_map).encode("utf-16be")
 self.beginStream(cidToGidMapObject.id,
@@ -688,6 +726,13 @@
 self.currentstream.write(cid_to_gid_map)
 self.endStream()
 
+ # ToUnicode CMap
+ self.beginStream(toUnicodeMapObject.id,
+ None,
+ {'Length': unicode_cmap})
+ self.currentstream.write(unicode_cmap)
+ self.endStream()
+ 
 descriptor['MaxWidth'] = max_width
 
 # Write everything out
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 3736
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3736&view=rev
Author: jouni
Date: 2007年08月24日 11:17:51 -0700 (2007年8月24日)
Log Message:
-----------
Support get_image_magnification in pdf backend
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py	2007年08月23日 18:02:03 UTC (rev 3735)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py	2007年08月24日 18:17:51 UTC (rev 3736)
@@ -1021,7 +1021,7 @@
 
 class RendererPdf(RendererBase):
 
- def __init__(self, file):
+ def __init__(self, file, dpi):
 RendererBase.__init__(self)
 self.file = file
 self.gc = self.new_gc()
@@ -1033,6 +1033,7 @@
 else:
 self.encode_string = self.encode_string_type42
 self.mathtext_parser = MathTextParser("Pdf")
+ self.image_magnification = dpi/72.0
 
 def finalize(self):
 self.gc.finalize()
@@ -1120,6 +1121,9 @@
 
 self.file.output(self.gc.close_and_paint())
 
+ def get_image_magnification(self):
+ return self.image_magnification
+
 def draw_image(self, x, y, im, bbox):
 #print >>sys.stderr, "draw_image called"
 
@@ -1128,6 +1132,7 @@
 self.check_gc(gc)
 
 h, w = im.get_size_out()
+ h, w = h/self.image_magnification, w/self.image_magnification
 imob = self.file.imageObject(im)
 self.file.output(Op.gsave, w, 0, 0, h, x, y, Op.concat_matrix,
 imob, Op.use_xobject, Op.grestore)
@@ -1735,7 +1740,7 @@
 filename += '.pdf'
 
 file = PdfFile(width, height, filename)
- renderer = RendererPdf(file)
+ renderer = RendererPdf(file, dpi)
 self.figure.draw(renderer)
 renderer.finalize()
 file.close()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 3753
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3753&view=rev
Author: mdboom
Date: 2007年08月30日 06:04:05 -0700 (2007年8月30日)
Log Message:
-----------
Fix bug where mathtext colors were not being set properly.
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py	2007年08月29日 20:39:07 UTC (rev 3752)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py	2007年08月30日 13:04:05 UTC (rev 3753)
@@ -1348,8 +1348,8 @@
 # this complication is avoided, but of course, those fonts can
 # not be subsetted.
 
+ self.check_gc(gc, gc._rgb)
 if ismath: return self.draw_mathtext(gc, x, y, s, prop, angle)
- self.check_gc(gc, gc._rgb)
 
 fontsize = prop.get_size_in_points()
 
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 3771
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3771&view=rev
Author: jouni
Date: 2007年09月03日 15:16:19 -0700 (2007年9月03日)
Log Message:
-----------
Fix some obvious bugs in Type 1 font support; now it at least 
produces a pdf file, at least with Computer Modern Roman, but 
viewer applications complain that the fonts are broken.
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py	2007年09月03日 21:36:17 UTC (rev 3770)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py	2007年09月03日 22:16:19 UTC (rev 3771)
@@ -515,21 +515,30 @@
 _, _, fullname, familyname, weight, italic_angle, fixed_pitch, \
 ul_position, ul_thickness = font.get_ps_font_info()
 
- differencesArray = [ 0 ] + [ Name(ch) for ch in 
- dviread.Encoding(fontinfo.encoding) ]
+ if fontinfo.encodingfile is not None:
+ differencesArray = [ Name(ch) for ch in 
+ dviread.Encoding(fontinfo.encodingfile) ]
+ differencesArray = [ 0 ] + differencesArray
+ lastchar = len(differencesArray) - 2
+ else:
+ lastchar = 255 # ?
 
 fontdict = {
 'Type': Name('Font'),
 'Subtype': Name('Type1'),
 'BaseFont': Name(font.postscript_name),
 'FirstChar': 0,
- 'LastChar': len(differencesArray) - 2,
+ 'LastChar': lastchar,
 'Widths': widthsObject,
 'FontDescriptor': fontdescObject,
- 'Encoding': { 'Type': Name('Encoding'),
- 'Differences': differencesArray },
 }
 
+ if fontinfo.encodingfile is not None:
+ 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
@@ -570,11 +579,11 @@
 descriptor['StemH'] = StemH
 
 self.writeObject(fontdictObject, fontdict)
- self.writeObject(widthsObject, widths)
+ self.writeObject(widthsObject, [ 100 for i in range(256)]) # XXX TODO
 self.writeObject(fontdescObject, descriptor)
 
 fontdata = type1font.Type1Font(filename)
- len1, len2, len3 = fontdata.lenghts()
+ len1, len2, len3 = fontdata.lengths()
 self.beginStream(fontfileObject.id, None,
 { 'Length1': len1,
 'Length2': len2,
@@ -1386,14 +1395,8 @@
 self.file.output(Op.grestore)
 
 def _draw_tex(self, gc, x, y, s, prop, angle):
- # Rename to draw_tex to enable, but note the following:
- # TODO:
- # - font sizes other than 10pt
- # - fonts other than the three ttf files included with matplotlib
- # (will need to support Type-1 fonts and find them with kpsewhich)
- # - encoding issues (e.g. \alpha doesn't work now)
- # - overall robustness
- # - ...
+ # Rename to draw_tex to enable, but it doesn't work at the moment
+
 texmanager = self.get_texmanager()
 fontsize = prop.get_size_in_points()
 dvifile = texmanager.make_dvi(s, fontsize)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 3797
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3797&view=rev
Author: jouni
Date: 2007年09月06日 07:46:49 -0700 (2007年9月06日)
Log Message:
-----------
Small bugfix in pdf backend
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py	2007年09月06日 12:10:07 UTC (rev 3796)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py	2007年09月06日 14:46:49 UTC (rev 3797)
@@ -1435,9 +1435,8 @@
 return x+x1, y+y1
 else:
 def mytrans(x1, y1, x=x, y=y, a=angle / 180.0 * pi):
- x1 = x + cos(a)*x1 - sin(a)*y1
- y1 = y + sin(a)*x1 + cos(a)*y1
- return x1, y1
+ return x + cos(a)*x1 - sin(a)*y1, \
+ y + sin(a)*x1 + cos(a)*y1
 
 self.check_gc(gc, gc._rgb)
 self.file.output(Op.begin_text)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 3814
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3814&view=rev
Author: jouni
Date: 2007年09月07日 12:45:48 -0700 (2007年9月07日)
Log Message:
-----------
In backend_pdf usetex, gather consecutive characters with same x
coordinate and same font into strings.
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py	2007年09月07日 18:53:51 UTC (rev 3813)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py	2007年09月07日 19:45:48 UTC (rev 3814)
@@ -1435,6 +1435,7 @@
 dvifile = texmanager.make_dvi(s, fontsize)
 dvi = dviread.Dvi(dvifile, 72)
 text, boxes = iter(dvi).next()
+ dvi.close()
 
 if angle == 0: # avoid rounding errors in common case
 def mytrans(x1, y1):
@@ -1444,10 +1445,10 @@
 return x + cos(a)*x1 - sin(a)*y1, \
 y + sin(a)*x1 + cos(a)*y1
 
- self.check_gc(gc, gc._rgb)
- self.file.output(Op.begin_text)
- oldfontnum, oldx, oldy = None, 0, 0
- for x1, y1, fontnum, glyph in text:
+ # Gather font information and do some setup for combining
+ # characters into strings.
+ oldfontnum, seq = None, []
+ for x1, y1, fontnum, glyph, width in text:
 if fontnum != oldfontnum:
 texname, fontsize = dvi.fontinfo(fontnum)
 fontinfo = self.tex_font_mapping(texname)
@@ -1455,14 +1456,50 @@
 self.file.fontInfo[pdfname] = Bunch(
 encodingfile=fontinfo.encoding,
 afmfile=fontinfo.afm)
- self.file.output(pdfname, fontsize, Op.selectfont)
+ seq += [['font', pdfname, fontsize]]
 oldfontnum = fontnum
- x1, y1 = mytrans(x1, y1)
- self._setup_textpos(x1, y1, angle, oldx, oldy)
- self.file.output(chr(glyph), Op.show)
- oldx, oldy = x1, y1
+ seq += [['text', x1, y1, [chr(glyph)], x1+width]]
+ seq += [('end',)]
+
+ # Find consecutive text strings with constant x coordinate and
+ # combine into one string (if needed kern would be less than
+ # 0.1 points) or several strings interspersed with kerns.
+ i, curx = 0, 0
+ while i < len(seq)-1:
+ elt, next = seq[i:i+2]
+ if elt[0] == next[0] == 'text' and elt[2] == next[2]:
+ offset = elt[4] - next[1]
+ if abs(offset) < 0.1:
+ elt[3][-1] += next[3][0]
+ elt[4] += next[4]-next[1]
+ else:
+ elt[3] += [offset, next[3][0]]
+ elt[4] = next[4]
+ del seq[i+1]
+ continue
+ i += 1
+
+ # Now do the actual output.
+ self.check_gc(gc, gc._rgb)
+ self.file.output(Op.begin_text)
+ curx, cury, oldx, oldy = 0, 0, 0, 0
+ for elt in seq:
+ if elt[0] == 'font':
+ self.file.output(elt[1], elt[2], Op.selectfont)
+ elif elt[0] == 'text':
+ curx, cury = mytrans(elt[1], elt[2])
+ self._setup_textpos(curx, cury, angle, oldx, oldy)
+ oldx, oldy = curx, cury
+ if len(elt[3]) == 1:
+ self.file.output(elt[3][0], Op.show)
+ else:
+ self.file.output(elt[3], Op.showkern)
+ else:
+ assert elt[0] == 'end'
 self.file.output(Op.end_text)
 
+ # Finally output the boxes (used for the variable-length lines
+ # in square roots and the like).
 boxgc = self.new_gc()
 boxgc.copy_properties(gc)
 boxgc.set_linewidth(0)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 3828
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3828&view=rev
Author: jouni
Date: 2007年09月10日 13:55:29 -0700 (2007年9月10日)
Log Message:
-----------
Bugfixes in pdf usetex
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py	2007年09月10日 20:31:01 UTC (rev 3827)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py	2007年09月10日 20:55:29 UTC (rev 3828)
@@ -519,12 +519,13 @@
 ul_position, ul_thickness = font.get_ps_font_info()
 
 if fontinfo.encodingfile is not None:
- differencesArray = [ Name(ch) for ch in 
- dviread.Encoding(fontinfo.encodingfile) ]
+ enc = dviread.Encoding(fontinfo.encodingfile)
+ widths = [ afmdata.get_width_from_char_name(ch)
+ for ch in enc ]
+ differencesArray = [ Name(ch) for ch in enc ]
 differencesArray = [ 0 ] + differencesArray
 firstchar = 0
 lastchar = len(differencesArray) - 2
- widths = [ 100 for x in range(firstchar,lastchar+1) ] # XXX TODO
 else:
 widths = [ None for i in range(256) ]
 for ch in range(256):
@@ -1427,7 +1428,7 @@
 # Pop off the global transformation
 self.file.output(Op.grestore)
 
- def draw_tex(self, gc, x, y, s, prop, angle):
+ def _draw_tex(self, gc, x, y, s, prop, angle):
 # Rename to draw_tex to enable
 
 texmanager = self.get_texmanager()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 3829
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3829&view=rev
Author: mdboom
Date: 2007年09月11日 05:46:27 -0700 (2007年9月11日)
Log Message:
-----------
Fix bug in PDF clip routine that resulted in the cryptic error message
"There are too many arguments" in Adobe Acrobat.
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py	2007年09月10日 20:55:29 UTC (rev 3828)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py	2007年09月11日 12:46:27 UTC (rev 3829)
@@ -1833,7 +1833,7 @@
 cmds.extend(self.pop())
 # Unless we hit the right one, set the clip polygon
 if (self._cliprect, self._clippath) != (cliprect, clippath):
- cmds.append(self.push())
+ cmds.extend(self.push())
 if self._cliprect != cliprect:
 cmds.extend([t for t in cliprect] + 
 [Op.rectangle, Op.clip, Op.endpath])
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 3963
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3963&view=rev
Author: mdboom
Date: 2007年10月18日 10:40:30 -0700 (2007年10月18日)
Log Message:
-----------
Major speedup in PDF backend by using hasattr() rather than 'in dir()'
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py	2007年10月18日 15:06:49 UTC (rev 3962)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py	2007年10月18日 17:40:30 UTC (rev 3963)
@@ -105,7 +105,7 @@
 """Map Python objects to PDF syntax."""
 
 # Some objects defined later have their own pdfRepr method.
- if 'pdfRepr' in dir(obj):
+ if hasattr(obj, 'pdfRepr'):
 return obj.pdfRepr()
 
 # Floats. PDF does not have exponential notation (1.0e-10) so we
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 3964
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3964&view=rev
Author: mdboom
Date: 2007年10月18日 11:07:06 -0700 (2007年10月18日)
Log Message:
-----------
Faster version of fill() for PDF writing
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py	2007年10月18日 17:40:30 UTC (rev 3963)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py	2007年10月18日 18:07:06 UTC (rev 3964)
@@ -90,15 +90,19 @@
 """Make one string from sequence of strings, with whitespace
 in between. The whitespace is chosen to form lines of at most
 linelen characters, if possible."""
-
- s, strings = [strings[0]], strings[1:]
- while strings:
- if len(s[-1]) + len(strings[0]) < linelen:
- s[-1] += ' ' + strings[0]
+ currpos = 0
+ lasti = 0
+ result = []
+ for i, s in enumerate(strings):
+ length = len(s)
+ if currpos + length < linelen:
+ currpos += length + 1
 else:
- s.append(strings[0])
- strings = strings[1:]
- return '\n'.join(s)
+ result.append(' '.join(strings[lasti:i]))
+ lasti = i
+ currpos = length
+ result.append(' '.join(strings[lasti:]))
+ return '\n'.join(result)
 
 
 def pdfRepr(obj):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 4498
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4498&view=rev
Author: mdboom
Date: 2007年11月28日 12:58:06 -0800 (2007年11月28日)
Log Message:
-----------
Fix for STIX fonts with PDF backend.
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py	2007年11月28日 20:43:01 UTC (rev 4497)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py	2007年11月28日 20:58:06 UTC (rev 4498)
@@ -334,7 +334,7 @@
 self.passed_in_file_object = True
 else:
 raise ValueError("filename must be a path or a file-like object")
- 
+
 self.fh = fh
 self.currentstream = None # stream object to write to, if any
 fh.write("%PDF-1.4\n") # 1.4 is the first version to have alpha
@@ -524,7 +524,7 @@
 
 firstchar = 0
 lastchar = len(fontinfo.widths) - 1
- 
+
 fontdict = {
 'Type': Name('Font'),
 'Subtype': Name('Type1'),
@@ -569,7 +569,7 @@
 'XHeight': 500, # TODO: this one too
 'FontFile': fontfileObject,
 'FontFamily': familyname,
- 'StemV': 50, # TODO 
+ 'StemV': 50, # TODO
 # (see also revision 3874; but not all TeX distros have AFM files!)
 #'FontWeight': a number where 400 = Regular, 700 = Bold
 }
@@ -614,7 +614,7 @@
 CMapName currentdict /CMap defineresource pop
 end
 end"""
- 
+
 def embedTTF(self, filename, characters):
 """Embed the TTF font from the named file into the document."""
 
@@ -713,7 +713,7 @@
 charprocDict['Type'] = Name('XObject')
 charprocDict['Subtype'] = Name('Form')
 charprocDict['BBox'] = bbox
- charprocObject = self.reserveObject('charProc for %s' % name)
+ charprocObject = self.reserveObject('charProc')
 self.beginStream(charprocObject.id, None, charprocDict)
 self.currentstream.write(stream)
 self.endStream()
@@ -827,7 +827,7 @@
 unicode_cmap = (self._identityToUnicodeCMap %
 (len(unicode_groups),
 "\n".join(unicode_bfrange)))
- 
+
 # CIDToGIDMap stream
 cid_to_gid_map = "".join(cid_to_gid_map).encode("utf-16be")
 self.beginStream(cidToGidMapObject.id,
@@ -842,7 +842,7 @@
 {'Length': unicode_cmap})
 self.currentstream.write(unicode_cmap)
 self.endStream()
- 
+
 descriptor['MaxWidth'] = max_width
 
 # Write everything out
@@ -896,7 +896,7 @@
 warnings.warn(("'%s' can not be subsetted into a Type 3 font. " +
 "The entire font will be embedded in the output.") %
 os.path.basename(filename))
- 
+
 if fonttype == 3:
 return embedTTFType3(font, characters, descriptor)
 elif fonttype == 42:
@@ -1378,7 +1378,7 @@
 fonttype = 42
 else:
 fonttype = global_fonttype
- 
+
 if fonttype == 42 or num <= 255:
 self._setup_textpos(ox, oy, 0, oldx, oldy)
 oldx, oldy = ox, oy
@@ -1397,8 +1397,9 @@
 fonttype = 42
 else:
 fonttype = global_fonttype
- 
+
 if fonttype == 3 and num > 255:
+ self.file.fontName(fontname)
 self.file.output(Op.gsave,
 0.001 * fontsize, 0,
 0, 0.001 * fontsize,
@@ -1534,12 +1535,12 @@
 y += font.get_descent() / 64.0
 
 fonttype = rcParams['pdf.fonttype']
- 
+
 # We can't subset all OpenType fonts, so switch to Type 42
 # in that case.
 if is_opentype_cff_font(font.fname):
 fonttype = 42
- 
+
 def check_simple_method(s):
 """Determine if we should use the simple or woven method
 to output this text, and chunks the string into 1-byte and
@@ -1830,7 +1831,7 @@
 if (self._cliprect, self._clippath) != (cliprect, clippath):
 cmds.extend(self.push())
 if self._cliprect != cliprect:
- cmds.extend([t for t in cliprect] + 
+ cmds.extend([t for t in cliprect] +
 [Op.rectangle, Op.clip, Op.endpath])
 if self._clippath != clippath:
 cmds.extend(PdfFile.pathOperations(clippath) +
@@ -1858,7 +1859,7 @@
 """
 cmds = []
 for params, cmd in self.commands:
- ours = [ getattr(self, p) for p in params ] 
+ ours = [ getattr(self, p) for p in params ]
 theirs = [ getattr(other, p) for p in params ]
 if ours != theirs:
 cmds.extend(cmd(self, *theirs))
@@ -1919,10 +1920,10 @@
 pass
 
 filetypes = {'pdf': 'Portable Document Format'}
- 
+
 def get_default_filetype(self):
 return 'pdf'
- 
+
 def print_pdf(self, filename, **kwargs):
 dpi = kwargs.get('dpi', None)
 self.figure.set_dpi(72) # Override the dpi kwarg
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /