@@ -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
0 commit comments