Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 60430fd

Browse files
committed
Merged revisions 4683-4688 via svnmerge from
http://matplotlib.svn.sf.net/svnroot/matplotlib/trunk/matplotlib ........ r4684 | mdboom | 2007-12-10 10:23:08 -0500 (Mon, 10 Dec 2007) | 2 lines Fix variable name. ........ r4685 | mdboom | 2007-12-10 10:34:29 -0500 (Mon, 10 Dec 2007) | 2 lines Fix syntax for pre-Python 2.5 ........ r4686 | mdboom | 2007-12-10 11:15:30 -0500 (Mon, 10 Dec 2007) | 4 lines Support draw_path (importantly for ellipses) in Pdf, Svg and Cairo backends. Fix SVG text rendering bug. ........ svn path=/branches/transforms/; revision=4689
1 parent 19ed984 commit 60430fd

6 files changed

Lines changed: 183 additions & 153 deletions

File tree

CHANGELOG

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2007-12-10 Fix SVG text rendering bug.
2+
3+
2007-12-10 Increase accuracy of circle and ellipse drawing by using an 8-piece
4+
bezier approximation, rather than a 4-piece one. Fix PDF, SVG and
5+
Cairo backends so they can draw paths (meaning ellipses as well).
6+
17
2007-12-07 Issue a warning when drawing an image on a non-linear axis. - MGD
28

39
2007-12-06 let widgets.Cursor initialize to the lower x and y bounds

lib/matplotlib/backends/backend_cairo.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def _fn_name(): return sys._getframe(1).f_code.co_name
3434
backend_version = cairo.version
3535
del _version_required
3636

37+
from matplotlib import agg
3738
from matplotlib.backend_bases import RendererBase, GraphicsContextBase,\
3839
FigureManagerBase, FigureCanvasBase
3940
from matplotlib.cbook import enumerate, izip, is_string_like
@@ -117,6 +118,7 @@ def _fill_and_stroke (self, ctx, fill_c, alpha):
117118
ctx.stroke()
118119

119120

121+
<<<<<<< .working
120122
#@staticmethod
121123
def convert_path(ctx, tpath):
122124
for points, code in tpath.iter_segments():
@@ -133,12 +135,48 @@ def convert_path(ctx, tpath):
133135
elif code == Path.CLOSEPOLY:
134136
ctx.close_path()
135137
convert_path = staticmethod(convert_path)
138+
=======
139+
def draw_path(self, gc, rgbFace, path):
140+
ctx = gc.ctx
141+
ctx.new_path()
142+
>>>>>>> .merge-right.r4686
136143

144+
<<<<<<< .working
137145

138146
def draw_path(self, gc, path, transform, rgbFace=None):
139147
if len(path.vertices) > 18980:
140148
raise ValueError("The Cairo backend can not draw paths longer than 18980 points.")
141149

150+
=======
151+
while 1:
152+
code, xp, yp = path.vertex()
153+
yp = self.height - yp
154+
155+
if code == agg.path_cmd_stop:
156+
ctx.close_path()
157+
break
158+
elif code == agg.path_cmd_move_to:
159+
ctx.move_to(xp, yp)
160+
elif code == agg.path_cmd_line_to:
161+
ctx.line_to(xp, yp)
162+
elif code == agg.path_cmd_curve3:
163+
_, xp1, yp1 = path.vertex()
164+
yp1 = self.height - yp1
165+
ctx.curve_to(xp, yp, xp, yp, xp1, yp1)
166+
elif code == agg.path_cmd_curve4:
167+
_, xp1, yp1 = path.vertex()
168+
yp1 = self.height - yp1
169+
_, xp2, yp2 = path.vertex()
170+
yp2 = self.height - yp2
171+
ctx.curve_to(xp, yp, xp1, yp1, xp2, yp2)
172+
elif code == agg.path_cmd_end_poly:
173+
ctx.close_path()
174+
self._fill_and_stroke(ctx, rgbFace)
175+
176+
def draw_arc(self, gc, rgbFace, x, y, width, height, angle1, angle2,
177+
rotation):
178+
if _debug: print '%s.%s()' % (self.__class__.__name__, _fn_name())
179+
>>>>>>> .merge-right.r4686
142180
ctx = gc.ctx
143181
transform = transform + \
144182
Affine2D().scale(1.0, -1.0).translate(0, self.height)

lib/matplotlib/backends/backend_pdf.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,7 +1211,97 @@ def merge_used_characters(self, other):
12111211
stat_key, (realpath, Set()))
12121212
used_characters[1].update(set)
12131213

1214+
<<<<<<< .working
12141215
def draw_image(self, x, y, im, bbox, clippath=None, clippath_trans=None):
1216+
=======
1217+
def draw_arc(self, gcEdge, rgbFace, x, y, width, height,
1218+
angle1, angle2, rotation):
1219+
"""
1220+
Draw an arc using GraphicsContext instance gcEdge, centered at x,y,
1221+
with width and height and angles from 0.0 to 360.0
1222+
0 degrees is at 3-o'clock, rotated by `rotation` degrees
1223+
positive angles are anti-clockwise
1224+
1225+
If the color rgbFace is not None, fill the arc with it.
1226+
"""
1227+
# source: agg_bezier_arc.cpp in agg23
1228+
1229+
def arc_to_bezier(cx, cy, rx, ry, angle1, sweep, rotation):
1230+
halfsweep = sweep / 2.0
1231+
x0, y0 = cos(halfsweep), sin(halfsweep)
1232+
tx = (1.0 - x0) * 4.0/3.0;
1233+
ty = y0 - tx * x0 / y0;
1234+
px = x0, x0+tx, x0+tx, x0
1235+
py = -y0, -ty, ty, y0
1236+
sn, cs = sin(angle1 + halfsweep), cos(angle1 + halfsweep)
1237+
result = [ (rx * (pxi * cs - pyi * sn),
1238+
ry * (pxi * sn + pyi * cs))
1239+
for pxi, pyi in zip(px, py) ]
1240+
result = [ (cx + cos(rotation)*x - sin(rotation)*y,
1241+
cy + sin(rotation)*x + cos(rotation)*y)
1242+
for x, y in result ]
1243+
return reduce(lambda x, y: x + y, result)
1244+
1245+
epsilon = 0.01
1246+
angle1 *= pi/180.0
1247+
angle2 *= pi/180.0
1248+
rotation *= pi/180.0
1249+
sweep = angle2 - angle1
1250+
angle1 = angle1 % (2*pi)
1251+
sweep = min(max(-2*pi, sweep), 2*pi)
1252+
1253+
if sweep < 0.0:
1254+
sweep, angle1, angle2 = -sweep, angle2, angle1
1255+
bp = [ pi/2.0 * i
1256+
for i in range(4)
1257+
if pi/2.0 * i < sweep-epsilon ]
1258+
bp.append(sweep)
1259+
subarcs = [ arc_to_bezier(x, y, width/2.0, height/2.0,
1260+
bp[i], bp[i+1]-bp[i], rotation)
1261+
for i in range(len(bp)-1) ]
1262+
1263+
self.check_gc(gcEdge, rgbFace)
1264+
self.file.output(subarcs[0][0], subarcs[0][1], Op.moveto)
1265+
for arc in subarcs:
1266+
self.file.output(*(arc[2:] + (Op.curveto,)))
1267+
1268+
self.file.output(self.gc.close_and_paint())
1269+
1270+
def draw_path(self, gc, rgbFace, path):
1271+
self.check_gc(gc, rgbFace)
1272+
1273+
cmds = []
1274+
1275+
while 1:
1276+
code, xp, yp = path.vertex()
1277+
1278+
if code == agg.path_cmd_stop:
1279+
cmds.append(Op.closepath)
1280+
break
1281+
elif code == agg.path_cmd_move_to:
1282+
cmds.extend([xp, yp, Op.moveto])
1283+
elif code == agg.path_cmd_line_to:
1284+
cmds.extend([xp, yp, Op.lineto])
1285+
elif code == agg.path_cmd_curve3:
1286+
cmds.extend([xp, yp])
1287+
cmds.extend([xp, yp])
1288+
cmds.extend(path.vertex()[1:])
1289+
cmds.append(Op.curveto)
1290+
elif code == agg.path_cmd_curve4:
1291+
cmds.extend([xp, yp])
1292+
cmds.extend(path.vertex()[1:])
1293+
cmds.extend(path.vertex()[1:])
1294+
cmds.append(Op.curveto)
1295+
elif code == agg.path_cmd_end_poly:
1296+
cmds.append(Op.closepath)
1297+
self.file.output(*cmds)
1298+
self.file.output(self.gc.paint())
1299+
1300+
def get_image_magnification(self):
1301+
return self.image_magnification
1302+
1303+
def draw_image(self, x, y, im, bbox):
1304+
>>>>>>> .merge-right.r4686
12151305
#print >>sys.stderr, "draw_image called"
12161306

12171307
# MGDTODO: Support clippath here

lib/matplotlib/backends/backend_svg.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os, codecs, base64, tempfile, urllib, gzip
44

5+
from matplotlib import agg
56
from matplotlib import verbose, __version__, rcParams
67
from matplotlib.backend_bases import RendererBase, GraphicsContextBase,\
78
FigureManagerBase, FigureCanvasBase
@@ -139,6 +140,49 @@ def open_group(self, s):
139140
def close_group(self, s):
140141
self._svgwriter.write('</g>\n')
141142

143+
<<<<<<< .working
144+
=======
145+
def draw_path(self, gc, rgbFace, path):
146+
cmd = []
147+
148+
while 1:
149+
code, xp, yp = path.vertex()
150+
yp = self.height - yp
151+
152+
if code == agg.path_cmd_stop:
153+
cmd.append('z') # Hack, path_cmd_end_poly not found
154+
break
155+
elif code == agg.path_cmd_move_to:
156+
cmd.append('M%g %g' % (xp, yp))
157+
elif code == agg.path_cmd_line_to:
158+
cmd.append('L%g %g' % (xp, yp))
159+
elif code == agg.path_cmd_curve3:
160+
verts = [xp, yp]
161+
verts.extent(path.vertex()[1:])
162+
verts[-1] = self.height - verts[-1]
163+
cmd.append('Q%g %g %g %g' % tuple(verts))
164+
elif code == agg.path_cmd_curve4:
165+
verts = [xp, yp]
166+
verts.extend(path.vertex()[1:])
167+
verts[-1] = self.height - verts[-1]
168+
verts.extend(path.vertex()[1:])
169+
verts[-1] = self.height - verts[-1]
170+
cmd.append('C%g %g %g %g %g %g'%tuple(verts))
171+
elif code == agg.path_cmd_end_poly:
172+
cmd.append('z')
173+
174+
path_data = "".join(cmd)
175+
self._draw_svg_element("path", 'd="%s"' % path_data, gc, rgbFace)
176+
177+
def draw_arc(self, gc, rgbFace, x, y, width, height, angle1, angle2, rotation):
178+
"""
179+
Ignores angles for now
180+
"""
181+
details = 'cx="%s" cy="%s" rx="%s" ry="%s" transform="rotate(%1.1f %s %s)"' % \
182+
(x, self.height-y, width/2.0, height/2.0, -rotation, x, self.height-y)
183+
self._draw_svg_element('ellipse', details, gc, rgbFace)
184+
185+
>>>>>>> .merge-right.r4686
142186
def option_image_nocomposite(self):
143187
"""
144188
if svg.image_noscale is True, compositing multiple images into one is prohibited
@@ -327,7 +371,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath):
327371
svg.append(' x="%s"' %
328372
(currx * (self.FONT_SCALE / fontsize)))
329373
svg.append('/>\n')
330-
currx += (glyph.linearHoriAdvance / 65536.0)
374+
currx += (glyph.linearHoriAdvance / 65536.0) / (self.FONT_SCALE / fontsize)
331375
svg.append('</g>\n')
332376
svg = ''.join(svg)
333377
else:

lib/matplotlib/font_manager.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,10 @@ def win32FontDirectory():
109109
else:
110110
user = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, MSFolders)
111111
try:
112-
return _winreg.QueryValueEx(user, 'Fonts')[0]
113-
except OSError:
114-
pass # Fall through to default
112+
try:
113+
return _winreg.QueryValueEx(user, 'Fonts')[0]
114+
except OSError:
115+
pass # Fall through to default
115116
finally:
116117
_winreg.CloseKey(user)
117118
return os.path.join(os.environ['WINDIR'], 'Fonts')

0 commit comments

Comments
 (0)