Skip to content

Commit c246a91

Browse files
hansonrhansonr
authored andcommitted
antialiasing fixes
1 parent 3e97e0e commit c246a91

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

sources/net.sf.j2s.java.core/src/swingjs/JSGraphics2D.java

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,6 @@ public JSGraphics2D(Object canvas) { // this must be Object, because we are
8787
hints = new RenderingHints(new Hashtable());
8888
this.canvas = (HTML5Canvas) canvas;
8989
ctx = this.canvas.getContext("2d");
90-
// removed - caused blurriness 9/17/2018
91-
// // reduce antialiasing, thank you,
92-
// // http://www.rgraph.net/docs/howto-get-crisp-lines-with-no- antialias.html
93-
// if (!isShifted)
94-
// ctx.translate(-0.5, -0.5);
95-
// isShifted = true;
9690
transform = new AffineTransform();
9791
setStroke(new BasicStroke());
9892
/**
@@ -104,12 +98,37 @@ public JSGraphics2D(Object canvas) { // this must be Object, because we are
10498
*/
10599
{
106100
}
101+
// removed - caused blurriness 9/17/2018
102+
// // reduce antialiasing, thank you,
103+
// // http://www.rgraph.net/docs/howto-get-crisp-lines-with-no- antialias.html
104+
setAntialias(true);
107105
}
108106

107+
public void setAntialias(boolean tf) {
108+
if (tf) {
109+
if (!isShifted)
110+
ctx.translate(-0.5, -0.5);
111+
} else {
112+
if (isShifted)
113+
ctx.translate(0.5, 0.5);
114+
}
115+
// this is important if images are being drawn - test/TAPP6
116+
// see also http://vaughnroyko.com/state-of-nearest-neighbor-interpolation-in-canvas/
117+
/**
118+
* @j2sNative
119+
*
120+
* this.ctx.mozImageSmoothingEnabled = false;
121+
* this.ctx.webkitImageSmoothingEnabled = false;
122+
* this.ctx.msImageSmoothingEnabled = false;
123+
* this.ctx.imageSmoothingEnabled = false;
124+
*
125+
*/
126+
isShifted = tf;
127+
}
128+
109129
/**
110130
* the SwingJS object
111131
*/
112-
113132
public GraphicsConfiguration getDeviceConfiguration() {
114133
return gc;
115134
}
@@ -243,9 +262,11 @@ public void fillRect(int x, int y, int width, int height) {
243262
if (width <= 0 || height <= 0)
244263
return;
245264
backgroundPainted = true;
246-
ctx.translate(0.5, 0.5);
265+
// if (!isShifted)
266+
// ctx.translate(0.5, 0.5);
247267
ctx.fillRect(x, y, width, height);
248-
ctx.translate(-0.5, -0.5);
268+
// if (!isShifted)
269+
// ctx.translate(-0.5, -0.5);
249270
//
250271
// if (width == 1)
251272
// drawLine(x, y, x, y + height);

0 commit comments

Comments
 (0)