1313 "RGB" , "HSB" , "CMYK" ,
1414 "CENTER" , "CORNER" ,
1515 "MOVETO" , "LINETO" , "CURVETO" , "CLOSE" ,
16+ "MITER" , "ROUND" , "BEVEL" , "BUTT" , "SQUARE" ,
1617 "LEFT" , "RIGHT" , "CENTER" , "JUSTIFY" ,
1718 "NORMAL" ,"FORTYFIVE" ,
1819 "NUMBER" , "TEXT" , "BOOLEAN" ,"BUTTON" ,
3940CURVETO = NSCurveToBezierPathElement
4041CLOSE = NSClosePathBezierPathElement
4142
43+ MITER = NSMiterLineJoinStyle
44+ ROUND = NSRoundLineJoinStyle # Also used for NSRoundLineCapStyle, same value.
45+ BEVEL = NSBevelLineJoinStyle
46+ BUTT = NSButtLineCapStyle
47+ SQUARE = NSSquareLineCapStyle
48+
4249LEFT = NSLeftTextAlignment
4350RIGHT = NSRightTextAlignment
4451CENTER = NSCenterTextAlignment
6673 '_fillcolor' : 'fill' ,
6774 '_strokecolor' : 'stroke' ,
6875 '_strokewidth' : 'strokewidth' ,
76+ '_capstyle' : 'capstyle' ,
77+ '_joinstyle' : 'joinstyle' ,
6978 '_transform' : 'transform' ,
7079 '_transformmode' : 'transformmode' ,
7180 '_fontname' : 'font' ,
@@ -210,13 +219,15 @@ def _set_strokewidth(self, strokewidth):
210219class BezierPath (Grob , TransformMixin , ColorMixin ):
211220 """A BezierPath provides a wrapper around NSBezierPath."""
212221
213- stateAttributes = ('_fillcolor' , '_strokecolor' , '_strokewidth' , '_transform' , '_transformmode' )
214- kwargs = ('fill' , 'stroke' , 'strokewidth' )
222+ stateAttributes = ('_fillcolor' , '_strokecolor' , '_strokewidth' , '_capstyle' , '_joinstyle' , ' _transform' , '_transformmode' )
223+ kwargs = ('fill' , 'stroke' , 'strokewidth' , 'capstyle' , 'joinstyle' )
215224
216225 def __init__ (self , ctx , path = None , ** kwargs ):
217226 super (BezierPath , self ).__init__ (ctx )
218227 TransformMixin .__init__ (self )
219228 ColorMixin .__init__ (self , ** kwargs )
229+ self .capstyle = kwargs .get ('capstyle' , BUTT )
230+ self .joinstyle = kwargs .get ('joinstyle' , MITER )
220231 self ._segment_cache = None
221232 if path is None :
222233 self ._nsBezierPath = NSBezierPath .bezierPath ()
@@ -238,6 +249,24 @@ def _get_path(self):
238249
239250 def copy (self ):
240251 return self .__class__ (self ._ctx , self )
252+
253+ ### Cap and Join style ###
254+
255+ def _get_capstyle (self ):
256+ return self ._capstyle
257+ def _set_capstyle (self , style ):
258+ if style not in (BUTT , ROUND , SQUARE ):
259+ raise NodeBoxError , 'Line cap style should be BUTT, ROUND or SQUARE.'
260+ self ._capstyle = style
261+ capstyle = property (_get_capstyle , _set_capstyle )
262+
263+ def _get_joinstyle (self ):
264+ return self ._joinstyle
265+ def _set_joinstyle (self , style ):
266+ if style not in (MITER , ROUND , BEVEL ):
267+ raise NodeBoxError , 'Line join style should be MITER, ROUND or BEVEL.'
268+ self ._joinstyle = style
269+ joinstyle = property (_get_joinstyle , _set_joinstyle )
241270
242271 ### Path methods ###
243272
@@ -256,7 +285,7 @@ def curveto(self, x1, y1, x2, y2, x3, y3):
256285 def closepath (self ):
257286 self ._segment_cache = None
258287 self ._nsBezierPath .closePath ()
259-
288+
260289 def setlinewidth (self , width ):
261290 self .linewidth = width
262291
@@ -359,6 +388,8 @@ def _draw(self):
359388 if (self ._strokecolor ):
360389 self ._strokecolor .set ()
361390 self ._nsBezierPath .setLineWidth_ (self ._strokewidth )
391+ self ._nsBezierPath .setLineCapStyle_ (self ._capstyle )
392+ self ._nsBezierPath .setLineJoinStyle_ (self ._joinstyle )
362393 self ._nsBezierPath .stroke ()
363394 _restore ()
364395
0 commit comments