@@ -140,21 +140,19 @@ def get_text_width_height(self, s, prop, ismath):
140
140
return w , h
141
141
142
142
143
- def draw_arc (self , gcEdge , rgbFace , x , y , width , height , angle1 , angle2 ):
143
+ def draw_arc (self , gc , rgbFace , x , y , width , height , angle1 , angle2 ):
144
144
"""
145
145
Draw an arc centered at x,y with width and height and angles
146
146
from 0.0 to 360.0.
147
-
148
- If rgbFace is not None, fill the arc with it. gcEdge
149
- is a GraphicsContext instance
147
+ If rgbFace is not None, fill the arc with it.
150
148
"""
151
149
if Debug : print 'backend_cairo.RendererCairo.%s()' % _fn_name ()
152
150
# cairo draws circular arcs (width=height) only?
153
151
# could curve_to() and draw a spline instead?
154
- ctx = gcEdge . ctx
155
- y = self . height - y
156
- radius = width / 2
157
- ctx .arc (x , y , radius , angle1 * pi / 180.0 , angle2 * pi / 180.0 )
152
+ radius = ( height + width ) / 4
153
+ ctx = gc . ctx
154
+ ctx . new_path ()
155
+ ctx .arc (x , self . height - y , radius , angle1 * pi / 180.0 , angle2 * pi / 180.0 )
158
156
159
157
if rgbFace :
160
158
ctx .save ()
@@ -188,12 +186,10 @@ def draw_line(self, gc, x1, y1, x2, y2):
188
186
"""
189
187
if Debug : print 'backend_cairo.RendererCairo.%s()' % _fn_name ()
190
188
ctx = gc .ctx
191
- y1 = self . height - y1
192
- y2 = self .height - y2
193
- ctx .move_to ( x1 , y1 ); ctx . line_to ( x2 , y2 )
189
+ ctx . new_path ()
190
+ ctx . move_to ( x1 , self .height - y1 )
191
+ ctx .line_to ( x2 , self . height - y2 )
194
192
ctx .stroke ()
195
- # should call new_path() so this line is not part of future paths?
196
- # or save()/restore() wrapper ?
197
193
198
194
199
195
def draw_lines (self , gc , x , y ):
@@ -202,44 +198,40 @@ def draw_lines(self, gc, x, y):
202
198
point in x, y
203
199
"""
204
200
if Debug : print 'backend_cairo.RendererCairo.%s()' % _fn_name ()
205
- ctx = gc .ctx
206
201
y = [self .height - y for y in y ]
207
202
points = zip (x ,y )
208
203
x , y = points .pop (0 )
204
+ ctx = gc .ctx
205
+ ctx .new_path ()
209
206
ctx .move_to (x , y )
210
207
211
208
for x ,y in points :
212
209
ctx .line_to (x , y )
213
210
ctx .stroke ()
214
211
215
- #ctx.new_path() # testing
216
- # should call new_path() so these lines are not part of future paths?
217
-
218
212
219
213
def draw_point (self , gc , x , y ):
220
214
"""
221
215
Draw a single point at x,y
222
216
"""
223
217
if Debug : print 'backend_cairo.RendererCairo.%s()' % _fn_name ()
224
218
# render by drawing a 0.5 radius circle
225
- y = self . height - y
226
- gc .ctx .arc (x , y , 0.5 , 0 , 2 * pi )
219
+ gc . ctx . new_path ()
220
+ gc .ctx .arc (x , self . height - y , 0.5 , 0 , 2 * pi )
227
221
gc .ctx .fill ()
228
222
229
223
230
- def draw_polygon (self , gcEdge , rgbFace , points ):
224
+ def draw_polygon (self , gc , rgbFace , points ):
231
225
"""
232
226
Draw a polygon. points is a len vertices tuple, each element
233
227
giving the x,y coords a vertex.
234
-
235
- If rgbFace is not None, fill the rectangle with it. gcEdge
236
- is a GraphicsContext instance
228
+ If rgbFace is not None, fill the rectangle with it.
237
229
"""
238
230
if Debug : print 'backend_cairo.RendererCairo.%s()' % _fn_name ()
239
- ctx = gcEdge .ctx
240
231
points = [(x , (self .height - y )) for x ,y in points ]
241
232
242
- ctx .new_path () # not required?
233
+ ctx = gc .ctx
234
+ ctx .new_path ()
243
235
x , y = points .pop (0 )
244
236
ctx .move_to (x , y )
245
237
for x ,y in points :
@@ -254,18 +246,17 @@ def draw_polygon(self, gcEdge, rgbFace, points):
254
246
ctx .stroke ()
255
247
256
248
257
- def draw_rectangle (self , gcEdge , rgbFace , x , y , width , height ):
249
+ def draw_rectangle (self , gc , rgbFace , x , y , width , height ):
258
250
"""
259
251
Draw a non-filled rectangle at x,y (lower left) with width and height,
260
252
using the GraphicsContext gcEdge.
261
253
Draw a filled rectangle within it of color rgbFace, if rgbFace is not
262
254
None.
263
255
"""
264
256
if Debug : print 'backend_cairo.RendererCairo.%s()' % _fn_name ()
265
- ctx = gcEdge .ctx
266
- y = self .height - y - height
267
-
268
- ctx .rectangle (x , y , width , height )
257
+ ctx = gc .ctx
258
+ ctx .new_path ()
259
+ ctx .rectangle (x , self .height - y - height , width , height )
269
260
if rgbFace :
270
261
ctx .save ()
271
262
ctx .set_rgb_color (* rgbFace )
@@ -288,17 +279,17 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
288
279
else :
289
280
# see also get_text_width_height()
290
281
# text is looking too small - size, scale problem?
282
+ ctx .new_path ()
283
+ ctx .move_to (x , y )
291
284
ctx .select_font (prop .get_name (),
292
285
self .fontangles [prop .get_style ()],
293
286
self .fontweights [prop .get_weight ()])
294
287
scale = self .get_text_scale ()
295
288
size = prop .get_size_in_points ()
296
- ctx .move_to (x , y )
297
289
if angle : # rotated text looks awful!
298
290
ctx .rotate (- angle * pi / 180 )
299
291
ctx .scale_font (scale * size )
300
292
ctx .show_text (s )
301
- # new_path() ?
302
293
303
294
304
295
def flipy (self ):
@@ -385,9 +376,14 @@ def set_clip_rectangle(self, rectangle):
385
376
ctx = self .ctx
386
377
ctx .new_path ()
387
378
ctx .rectangle (x , self .renderer .height - h - y , w , h )
379
+
380
+ #ctx.save() # uncomment to view the clip rectangle
381
+ #ctx.set_rgb_color(1,0,0)
382
+ #ctx.set_line_width(6)
383
+ #ctx.stroke()
384
+ #ctx.restore()
385
+
388
386
ctx .clip ()
389
- ctx .new_path () # prevents the rectangle from being drawn by next ctx.stroke()/fill()
390
- # is better to do new_path() (or save(),restore()) at start of EVERY draw_*() op ?
391
387
392
388
393
389
def set_dashes (self , offset , dashes ):
0 commit comments