SourceForge logo
SourceForge logo
Menu

matplotlib-checkins

Revision: 6295
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6295&view=rev
Author: mdboom
Date: 2008年10月22日 17:29:41 +0000 (2008年10月22日)
Log Message:
-----------
Fix alignment of Unicode strings in PS backend. Thanks, Stan West.
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/backends/backend_ps.py
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_ps.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_ps.py	2008年10月22日 15:27:24 UTC (rev 6294)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_ps.py	2008年10月22日 17:29:41 UTC (rev 6295)
@@ -669,7 +669,8 @@
 fontsize = prop.get_size_in_points()
 scale = 0.001*fontsize
 
- thisx, thisy = 0, 0
+ thisx = 0
+ thisy = font.get_str_bbox_and_descent(s)[4] * scale
 last_name = None
 lines = []
 for c in s:
@@ -705,16 +706,18 @@
 
 else:
 font = self._get_font_ttf(prop)
+ font.set_text(s, 0, flags=LOAD_NO_HINTING)
+ self.track_characters(font, s)
 
 self.set_color(*gc.get_rgb())
 self.set_font(font.get_sfnt()[(1,0,0,6)], prop.get_size_in_points())
- self.track_characters(font, s)
 
 cmap = font.get_charmap()
 lastgind = None
 #print 'text', s
 lines = []
- thisx, thisy = 0,0
+ thisx = 0
+ thisy = font.get_descent() / 64.0
 for c in s:
 ccode = ord(c)
 gind = cmap.get(ccode)
@@ -739,11 +742,11 @@
 
 thetext = '\n'.join(lines)
 ps = """gsave
- %(x)f %(y)f translate
- %(angle)f rotate
- %(thetext)s
- grestore
- """ % locals()
+%(x)f %(y)f translate
+%(angle)f rotate
+%(thetext)s
+grestore
+""" % locals()
 self._pswriter.write(ps)
 
 def draw_mathtext(self, gc,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 7057
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7057&view=rev
Author: mdboom
Date: 2009年04月23日 14:20:27 +0000 (2009年4月23日)
Log Message:
-----------
Fix clipping of images in PS backend.
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/backends/backend_ps.py
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_ps.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_ps.py	2009年04月21日 03:12:53 UTC (rev 7056)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_ps.py	2009年04月23日 14:20:27 UTC (rev 7057)
@@ -428,8 +428,8 @@
 ps = []
 last_points = None
 if clip:
- clip = (0.0, 0.0, self.width * self.imagedpi,
- self.height * self.imagedpi)
+ clip = (0.0, 0.0, self.width * 72.0,
+ self.height * 72.0)
 else:
 clip = None
 for points, code in path.iter_segments(transform, clip=clip):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 7630
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7630&view=rev
Author: mdboom
Date: 2009年09月02日 20:48:06 +0000 (2009年9月02日)
Log Message:
-----------
Add Gouraud triangle support to PS backend.
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/backends/backend_ps.py
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_ps.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_ps.py	2009年09月02日 19:31:32 UTC (rev 7629)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_ps.py	2009年09月02日 20:48:06 UTC (rev 7630)
@@ -754,6 +754,57 @@
 """ % locals()
 self._pswriter.write(ps)
 
+ def draw_gouraud_triangle(self, gc, points, colors, trans):
+ self.draw_gouraud_triangles(gc, points.reshape((1, 3, 2)),
+ colors.reshape((1, 3, 4)), trans)
+
+ def draw_gouraud_triangles(self, gc, points, colors, trans):
+ assert len(points) == len(colors)
+ assert points.ndim == 3
+ assert points.shape[1] == 3
+ assert points.shape[2] == 2
+ assert colors.ndim == 3
+ assert colors.shape[1] == 3
+ assert colors.shape[2] == 4
+
+ points = trans.transform(points)
+
+ shape = points.shape
+ flat_points = points.reshape((shape[0] * shape[1], 2))
+ flat_colors = colors.reshape((shape[0] * shape[1], 4))
+ points_min = npy.min(flat_points, axis=0) - (1 << 8)
+ points_max = npy.max(flat_points, axis=0) + (1 << 8)
+ factor = float(0xffffffff) / (points_max - points_min)
+
+ xmin, ymin = points_min
+ xmax, ymax = points_max
+
+ streamarr = npy.empty(
+ (shape[0] * shape[1],),
+ dtype=[('flags', 'u1'),
+ ('points', '>u4', (2,)),
+ ('colors', 'u1', (3,))])
+ streamarr['flags'] = 0
+ streamarr['points'] = (flat_points - points_min) * factor
+ streamarr['colors'] = flat_colors[:, :3] * 255.0
+
+ stream = quote_ps_string(streamarr.tostring())
+
+ self._pswriter.write("""
+gsave
+<< /ShadingType 4
+ /ColorSpace [/DeviceRGB]
+ /BitsPerCoordinate 32
+ /BitsPerComponent 8
+ /BitsPerFlag 8
+ /AntiAlias true
+ /Decode [ %(xmin)f %(xmax)f %(ymin)f %(ymax)f 0 1 0 1 0 1 ]
+ /DataSource (%(stream)s)
+>>
+shfill
+grestore
+""" % locals())
+
 def _draw_ps(self, ps, gc, rgbFace, fill=True, stroke=True, command=None):
 """
 Emit the PostScript sniplet 'ps' with all the attributes from 'gc'
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 8109
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8109&view=rev
Author: leejjoon
Date: 2010年02月03日 19:42:00 +0000 (2010年2月03日)
Log Message:
-----------
minor refactoring of the ps backend
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/backends/backend_ps.py
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_ps.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_ps.py	2010年02月03日 19:41:53 UTC (rev 8108)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_ps.py	2010年02月03日 19:42:00 UTC (rev 8109)
@@ -387,6 +387,16 @@
 """
 return True
 
+ def _get_image_h_w_bits_command(self, im):
+ if im.is_grayscale:
+ h, w, bits = self._gray(im)
+ imagecmd = "image"
+ else:
+ h, w, bits = self._rgb(im)
+ imagecmd = "false 3 colorimage"
+
+ return h, w, bits, imagecmd
+ 
 def draw_image(self, gc, x, y, im, dx=None, dy=None, transform=None):
 """
 Draw the Image instance into the current axes; x is the
@@ -400,12 +410,7 @@
 
 im.flipud_out()
 
- if im.is_grayscale:
- h, w, bits = self._gray(im)
- imagecmd = "image"
- else:
- h, w, bits = self._rgb(im)
- imagecmd = "false 3 colorimage"
+ h, w, bits, imagecmd = self._get_image_h_w_bits_command(im)
 hexlines = '\n'.join(self._hex_lines(bits))
 
 if dx is None:
@@ -924,6 +929,8 @@
 return manager
 
 class FigureCanvasPS(FigureCanvasBase):
+ _renderer_class = RendererPS
+
 def draw(self):
 pass
 
@@ -1057,7 +1064,8 @@
 
 # mixed mode rendering
 _bbox_inches_restore = kwargs.pop("bbox_inches_restore", None)
- ps_renderer = RendererPS(width, height, self._pswriter, imagedpi=dpi)
+ ps_renderer = self._renderer_class(width, height, self._pswriter,
+ imagedpi=dpi)
 renderer = MixedModeRenderer(self.figure,
 width, height, dpi, ps_renderer,
 bbox_inches_restore=_bbox_inches_restore)
@@ -1189,7 +1197,8 @@
 
 # mixed mode rendering
 _bbox_inches_restore = kwargs.pop("bbox_inches_restore", None)
- ps_renderer = RendererPS(width, height, self._pswriter, imagedpi=dpi)
+ ps_renderer = self._renderer_class(width, height,
+ self._pswriter, imagedpi=dpi)
 renderer = MixedModeRenderer(self.figure,
 width, height, dpi, ps_renderer,
 bbox_inches_restore=_bbox_inches_restore)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 8228
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8228&view=rev
Author: jrevans
Date: 2010年04月14日 18:48:36 +0000 (2010年4月14日)
Log Message:
-----------
Added the ps temp file ipermissions copy fix (as discussed on the devel list).
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/backends/backend_ps.py
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_ps.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_ps.py	2010年04月13日 22:55:23 UTC (rev 8227)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_ps.py	2010年04月14日 18:48:36 UTC (rev 8228)
@@ -1156,7 +1156,11 @@
 fh = file(tmpfile)
 print >>outfile, fh.read()
 else:
+ f = open(outfile, 'w')
+ mode = os.stat(outfile).st_mode
+ f.close()
 shutil.move(tmpfile, outfile)
+ os.chmod(outfile, mode)
 
 def _print_figure_tex(self, outfile, format, dpi, facecolor, edgecolor,
 orientation, isLandscape, papertype,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 8229
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8229&view=rev
Author: efiring
Date: 2010年04月14日 22:44:13 +0000 (2010年4月14日)
Log Message:
-----------
backend_ps: fix file perms when TeX is used; minor clarifications
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/backends/backend_ps.py
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_ps.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_ps.py	2010年04月14日 18:48:36 UTC (rev 8228)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_ps.py	2010年04月14日 22:44:13 UTC (rev 8229)
@@ -997,7 +997,6 @@
 """
 isEPSF = format == 'eps'
 passed_in_file_object = False
- fd, tmpfile = mkstemp()
 if is_string_like(outfile):
 title = outfile
 elif is_writable_file_like(outfile):
@@ -1005,9 +1004,10 @@
 passed_in_file_object = True
 else:
 raise ValueError("outfile must be a path or a file-like object")
- os.close(fd)
- fh = file(tmpfile, 'w')
 
+ fd, tmpfile = mkstemp()
+ fh = os.fdopen(fd, 'w')
+
 # find the appropriate papertype
 width, height = self.figure.get_size_inches()
 if papertype == 'auto':
@@ -1153,12 +1153,11 @@
 xpdf_distill(tmpfile, isEPSF, ptype=papertype, bbox=bbox)
 
 if passed_in_file_object:
- fh = file(tmpfile)
+ fh = open(tmpfile)
 print >>outfile, fh.read()
 else:
- f = open(outfile, 'w')
+ open(outfile, 'w')
 mode = os.stat(outfile).st_mode
- f.close()
 shutil.move(tmpfile, outfile)
 os.chmod(outfile, mode)
 
@@ -1175,8 +1174,7 @@
 
 # write to a temp file, we'll move it to outfile when done
 fd, tmpfile = mkstemp()
- os.close(fd)
- fh = file(tmpfile, 'w')
+ fh = os.fdopen(fd, 'w')
 
 self.figure.dpi = 72 # ignore the dpi kwarg
 width, height = self.figure.get_size_inches()
@@ -1301,7 +1299,11 @@
 if isinstance(outfile, file):
 fh = file(tmpfile)
 print >>outfile, fh.read()
- else: shutil.move(tmpfile, outfile)
+ else:
+ open(outfile, 'w')
+ mode = os.stat(outfile).st_mode
+ shutil.move(tmpfile, outfile)
+ os.chmod(outfile, mode)
 
 def convert_psfrags(tmpfile, psfrags, font_preamble, custom_preamble,
 paperWidth, paperHeight, orientation):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 8385
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8385&view=rev
Author: leejjoon
Date: 2010年06月05日 18:32:11 +0000 (2010年6月05日)
Log Message:
-----------
eps output restores the correct bounding box when convert_psfrags creates a ps in landscape mode
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/backends/backend_ps.py
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_ps.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_ps.py	2010年06月05日 18:32:06 UTC (rev 8384)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_ps.py	2010年06月05日 18:32:11 UTC (rev 8385)
@@ -1284,17 +1284,21 @@
 font_preamble = texmanager.get_font_preamble()
 custom_preamble = texmanager.get_custom_preamble()
 
- convert_psfrags(tmpfile, ps_renderer.psfrag, font_preamble,
- custom_preamble, paperWidth, paperHeight,
- orientation)
+ psfrag_rotated = convert_psfrags(tmpfile, ps_renderer.psfrag,
+ font_preamble,
+ custom_preamble, paperWidth, paperHeight,
+ orientation)
 
 if rcParams['ps.usedistiller'] == 'ghostscript':
- gs_distill(tmpfile, isEPSF, ptype=papertype, bbox=bbox)
+ gs_distill(tmpfile, isEPSF, ptype=papertype, bbox=bbox,
+ rotated=psfrag_rotated)
 elif rcParams['ps.usedistiller'] == 'xpdf':
- xpdf_distill(tmpfile, isEPSF, ptype=papertype, bbox=bbox)
+ xpdf_distill(tmpfile, isEPSF, ptype=papertype, bbox=bbox,
+ rotated=psfrag_rotated)
 elif rcParams['text.usetex']:
 if False: pass # for debugging
- else: gs_distill(tmpfile, isEPSF, ptype=papertype, bbox=bbox)
+ else: gs_distill(tmpfile, isEPSF, ptype=papertype, bbox=bbox,
+ rotated=psfrag_rotated)
 
 if isinstance(outfile, file):
 fh = file(tmpfile)
@@ -1395,12 +1399,26 @@
 os.remove(outfile)
 os.remove(epsfile)
 shutil.move(psfile, tmpfile)
+
+ # check if the dvips created a ps in landscape paper. Somehow,
+ # above latex+dvips results in a ps file in a landscape mode for a
+ # certain figure sizes (e.g., 8.3in,5.8in which is a5). And the
+ # bounding box of the final output got messed up. We check see if
+ # the generated ps file is in landscape and return this
+ # information. The return value is used in pstoeps step to recover
+ # the correct bounding box. 2010年06月05日 JJL
+ if "Landscape" in open(tmpfile).read(1000):
+ psfrag_rotated = True
+ else:
+ psfrag_rotated = False
+
 if not debugPS:
 for fname in glob.glob(tmpfile+'.*'):
 os.remove(fname)
 
+ return psfrag_rotated
 
-def gs_distill(tmpfile, eps=False, ptype='letter', bbox=None):
+def gs_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
 """
 Use ghostscript's pswrite or epswrite device to distill a file.
 This yields smaller files without illegal encapsulated postscript
@@ -1434,10 +1452,10 @@
 # the input to eps format, but also restores the original bbox.
 
 if eps:
- pstoeps(tmpfile, bbox)
+ pstoeps(tmpfile, bbox, rotated=rotated)
 
 
-def xpdf_distill(tmpfile, eps=False, ptype='letter', bbox=None):
+def xpdf_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
 """
 Use ghostscript's ps2pdf and xpdf's/poppler's pdftops to distill a file.
 This yields smaller files without illegal encapsulated postscript
@@ -1482,20 +1500,26 @@
 # 8.61). Thus, the original bbox need to be resotred.
 
 if eps:
- pstoeps(tmpfile, bbox)
+ pstoeps(tmpfile, bbox, rotated)
 for fname in glob.glob(tmpfile+'.*'):
 os.remove(fname)
 
 
-def get_bbox_header(l, b, r, t):
+def get_bbox_header(lbrt, rotated=False):
 """
- return a postscript header stringfor the given bbox (l, b, r, t)
+ return a postscript header stringfor the given bbox lbrt=(l, b, r, t).
+ Optionally, return rotate command.
 """
 
+ l, b, r, t = lbrt
+ if rotated:
+ rotate = "%.2f %.2f translate\n90 rotate" % (l+r, 0)
+ else:
+ rotate = ""
 bbox_info = '%%%%BoundingBox: %d %d %d %d' % (l, b, np.ceil(r), np.ceil(t))
 hires_bbox_info = '%%%%HiResBoundingBox: %.6f %.6f %.6f %.6f' % (l, b, r, t)
 
- return '\n'.join([bbox_info, hires_bbox_info])
+ return '\n'.join([bbox_info, hires_bbox_info]), rotate
 
 
 # get_bbox is deprecated. I don't see any reason to use ghostscript to
@@ -1543,12 +1567,14 @@
 return '\n'.join([bbox_info, hires_bbox_info])
 
 
-def pstoeps(tmpfile, bbox):
+def pstoeps(tmpfile, bbox, rotated=False):
 """
 Convert the postscript to encapsulated postscript.
 """
- bbox_info = get_bbox_header(*bbox)
 
+ # if rotated==True, the output eps file need to be rotated
+ bbox_info, rotate = get_bbox_header(bbox, rotated=rotated)
+
 epsfile = tmpfile + '.eps'
 epsh = file(epsfile, 'w')
 
@@ -1570,9 +1596,12 @@
 print >>epsh, '/setpagedevice {pop} def'
 print >>epsh, '%%EndProlog'
 print >>epsh, '%%Page 1 1'
+ if rotate:
+ print >>epsh, rotate
 break
 elif line.startswith('%%Bound') \
 or line.startswith('%%HiResBound') \
+ or line.startswith('%%DocumentMedia') \
 or line.startswith('%%Pages'):
 pass
 else:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 8801
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8801&view=rev
Author: leejjoon
Date: 2010年11月15日 01:09:27 +0000 (2010年11月15日)
Log Message:
-----------
disable pstoeps when xpdf distiller is used
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/backends/backend_ps.py
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_ps.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_ps.py	2010年11月15日 00:36:14 UTC (rev 8800)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_ps.py	2010年11月15日 01:09:27 UTC (rev 8801)
@@ -1438,7 +1438,7 @@
 # 8.61). Thus, the original bbox need to be resotred.
 
 if eps:
- pstoeps(tmpfile, bbox, rotated)
+ pass
 for fname in glob.glob(tmpfile+'.*'):
 os.remove(fname)
 
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 8802
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8802&view=rev
Author: leejjoon
Date: 2010年11月15日 10:40:58 +0000 (2010年11月15日)
Log Message:
-----------
pstoeps skips a line starting with %%PageBoundingBox
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/backends/backend_ps.py
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_ps.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_ps.py	2010年11月15日 01:09:27 UTC (rev 8801)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_ps.py	2010年11月15日 10:40:58 UTC (rev 8802)
@@ -1559,6 +1559,8 @@
 if rcParams['ps.usedistiller'] == 'xpdf':
 # remove extraneous "end" operator:
 line = tmph.readline()
+ elif line.startswith('%%PageBoundingBox'):
+ pass
 else:
 epsh.write(line)
 line = tmph.readline()
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 によって変換されたページ (->オリジナル) /