@@ -86,6 +86,11 @@ public JSGraphics2D(Object canvas) { // this must be Object, because we are
8686 hints = new RenderingHints (new Hashtable ());
8787 this .canvas = (HTML5Canvas ) canvas ;
8888 ctx = this .canvas .getContext ("2d" );
89+ // reduce antialiasing, thank you,
90+ // http://www.rgraph.net/docs/howto-get-crisp-lines-with-no- antialias.html
91+ if (!isShifted )
92+ ctx .translate (-0.5 , -0.5 );
93+ isShifted = true ;
8994 transform = new AffineTransform ();
9095 setStroke (new BasicStroke ());
9196 /**
@@ -184,14 +189,6 @@ private double toRad(double a) {
184189 public void background (Color bgcolor ) {
185190 backgroundColor = bgcolor ;
186191 if (bgcolor == null ) {
187- /*
188- *
189- * reduce antialiasing, thank you,
190- * http://www.rgraph.net/docs/howto-get-crisp-lines-with-no- antialias.html
191- */
192- if (!isShifted )
193- ctx .translate (-0.5 , -0.5 );
194- isShifted = true ;
195192 return ;
196193 }
197194 clearRect (0 , 0 , width , height );
@@ -244,7 +241,15 @@ public void fillRect(int x, int y, int width, int height) {
244241 if (width <= 0 || height <= 0 )
245242 return ;
246243 backgroundPainted = true ;
244+ ctx .translate (0.5 , 0.5 );
247245 ctx .fillRect (x , y , width , height );
246+ ctx .translate (-0.5 , -0.5 );
247+ //
248+ // if (width == 1)
249+ // drawLine(x, y, x, y + height);
250+ // else if (height == 1)
251+ // drawLine(x, y, x + width, y);
252+ // else
248253 }
249254
250255 public void draw3DRect (int x , int y , int width , int height , boolean raised ) {
@@ -702,10 +707,14 @@ public Shape getClip() {
702707 }
703708
704709 public void drawString (String s , int x , int y ) {
705- ctx . fillText (s , x , y );
710+ fillText (s , x , y );
706711 }
707712
708713 public void drawString (String str , float x , float y ) {
714+ fillText (str , x , y );
715+ }
716+
717+ private void fillText (String str , float x , float y ) {
709718 ctx .fillText (str , x , y );
710719 }
711720
0 commit comments