@@ -103,24 +103,24 @@ def __init__(self, width, height, pswriter):
103103 def set_color (self , r , g , b , store = 1 ):
104104 if (r ,g ,b ) != self .color :
105105 if r == g and r == b :
106- self ._pswriter .write ("%s setgray\n " % _num_to_str ( r ) )
106+ self ._pswriter .write ("%1.3f setgray\n " % r )
107107 else :
108- self ._pswriter .write ("%s setrgbcolor\n " % _nums_to_str (r ,g ,b ))
108+ self ._pswriter .write ("%1.3f %1.3f %1.3f setrgbcolor\n " % (r ,g ,b ))
109109 self .color = (r ,g ,b )
110110
111111 def set_linewidth (self , linewidth ):
112112 if linewidth != self .linewidth :
113- self ._pswriter .write ("%s setlinewidth\n " % _num_to_str ( linewidth ) )
113+ self ._pswriter .write ("%1.3f setlinewidth\n " % linewidth )
114114 self .linewidth = linewidth
115115
116116 def set_linejoin (self , linejoin ):
117117 if linejoin != self .linejoin :
118- self ._pswriter .write ("%s setlinejoin\n " % _num_to_str ( linejoin ) )
118+ self ._pswriter .write ("%1.3f setlinejoin\n " % linejoin )
119119 self .linejoin = linejoin
120120
121121 def set_linecap (self , linecap ):
122122 if linecap != self .linecap :
123- self ._pswriter .write ("%s setlinecap\n " % _num_to_str ( linecap ) )
123+ self ._pswriter .write ("%1.3f setlinecap\n " % linecap )
124124 self .linecap = linecap
125125
126126 def set_linedash (self , offset , seq ):
@@ -137,9 +137,10 @@ def set_linedash(self, offset, seq):
137137
138138 def set_font (self , fontname , fontsize ):
139139 if (fontname ,fontsize ) != (self .fontname ,self .fontsize ):
140- self ._pswriter .write ("/%s findfont\n " % fontname )
141- self ._pswriter .write ("%s scalefont\n " % _num_to_str (fontsize ))
142- self ._pswriter .write ("setfont\n " )
140+ writer = self ._pswriter
141+ writer .write ("/%s findfont\n " % fontname )
142+ writer .write ("%1.3f scalefont\n " % fontsize )
143+ writer .write ("setfont\n " )
143144 self .fontname = fontname
144145 self .fontsize = fontsize
145146
@@ -387,8 +388,10 @@ def _draw_ps(self, ps, gc, rgbFace, command=None):
387388 Emit the PostScript sniplet 'ps' with all the attributes from 'gc'
388389 applied. 'ps' must consist of PostScript commands to construct a path.
389390 """
391+ # local attr lookup faster and this is
392+ writer = self ._pswriter
390393 if debugPS and command :
391- self . _pswriter .write ("% " + command + "\n " )
394+ writer .write ("% " + command + "\n " )
392395
393396 cliprect = gc .get_clip_rectangle ()
394397 self .set_color (* gc .get_rgb ())
@@ -400,21 +403,21 @@ def _draw_ps(self, ps, gc, rgbFace, command=None):
400403 cint = {'butt' :0 , 'round' :1 , 'projecting' :2 }[gc .get_capstyle ()]
401404 self .set_linecap (cint )
402405 self .set_linedash (* gc .get_dashes ())
403- if cliprect :
404- self ._pswriter .write ("gsave\n " )
405406 if cliprect :
406407 x ,y ,w ,h = cliprect
407- self ._pswriter .write ('%s clipbox\n ' % _nums_to_str (w ,h ,x ,y ))
408- self ._pswriter .write (ps .strip ()+ '\n ' )
408+ writer .write ('gsave\n %1.3f %1.3f %1.3f %1.3f clipbox\n ' % (w ,h ,x ,y ))
409+ # Jochen, is the strip necessary? - this could be a honking big string
410+ writer .write (ps .strip ())
411+ writer .write ("\n " )
409412 if rgbFace :
410413 #print 'rgbface', rgbFace
411- self . _pswriter .write ("gsave\n " )
414+ writer .write ("gsave\n " )
412415 self .set_color (store = 0 , * rgbFace )
413- self . _pswriter . write ("fill\n " )
414- self . _pswriter . write ( "grestore \n " )
415- self . _pswriter .write ("stroke\n " )
416+ writer . write ("fill\n grestore \n " )
417+
418+ writer .write ("stroke\n " )
416419 if cliprect :
417- self . _pswriter .write ("grestore\n " )
420+ writer .write ("grestore\n " )
418421
419422
420423class GraphicsContextPS (GraphicsContextBase ):
0 commit comments