88import java .awt .FontMetrics ;
99import java .awt .GradientPaint ;
1010import java .awt .Graphics ;
11- import java .awt .Graphics2D ;
1211import java .awt .GraphicsConfiguration ;
1312import java .awt .Image ;
1413import java .awt .Paint ;
3433import java .awt .image .RenderedImage ;
3534import java .awt .image .renderable .RenderableImage ;
3635import java .text .AttributedCharacterIterator ;
37- import java .util .ArrayList ;
3836import java .util .Hashtable ;
39- import java .util .List ;
4037import java .util .Map ;
41- import java .util .Map .Entry ;
4238
43- import sun .font .TextSource ;
4439import swingjs .api .js .DOMNode ;
4540import swingjs .api .js .HTML5Canvas ;
4641import swingjs .api .js .HTML5CanvasContext2D ;
@@ -65,8 +60,6 @@ public class JSGraphics2D implements
6560 private static final int DRAW_CLOSE = 1 ;
6661 private static final int FILL = 2 ;
6762
68- // private boolean backgroundPainted;
69-
7063 public int constrainX ;
7164 public int constrainY ;
7265
@@ -249,7 +242,6 @@ private double toRad(double a) {
249242 }
250243
251244 public void clearRect (int x , int y , int width , int height ) {
252- // backgroundPainted = true;
253245 clearRectPriv (x , y , width , height );
254246 }
255247
@@ -325,7 +317,6 @@ public void drawRect(int x, int y, int width, int height) {
325317 public void fillRect (int x , int y , int width , int height ) {
326318 if (width <= 0 || height <= 0 )
327319 return ;
328- // backgroundPainted = true;
329320 ctx .fillRect (x , y , width , height );
330321 }
331322
@@ -587,7 +578,6 @@ public boolean drawImage(Image img, int x, int y, int width, int height, Color b
587578 public boolean drawImage (Image img , int x , int y , int width , int height , ImageObserver observer ) {
588579 if (width <= 0 || height <= 0 )
589580 return true ;
590- // backgroundPainted = true;
591581 if (img != null ) {
592582 DOMNode imgNode = ((BufferedImage ) img ).秘getImageNode (BufferedImage .GET_IMAGE_ALLOW_NULL );
593583 if (imgNode == null ) {
@@ -625,7 +615,6 @@ public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1,
625615 @ SuppressWarnings ("unused" )
626616 public boolean drawImage (Image img , int dx1 , int dy1 , int dx2 , int dy2 , int sx1 , int sy1 , int sx2 , int sy2 ,
627617 ImageObserver observer ) {
628- // backgroundPainted = true;
629618 if (img != null ) {
630619 byte [] bytes = null ;
631620 DOMNode imgNode = ((BufferedImage ) img ).秘getImageNode (BufferedImage .GET_IMAGE_ALLOW_NULL );
@@ -770,9 +759,6 @@ private void getBuf8(int x, int y, int w, int h) {
770759 }
771760 }
772761
773- private void loadCTX (int x , int y , int w , int h , int [] pixels , double m4 , double m5 , boolean isOpaque ) {
774- }
775-
776762 private static boolean isTranslationOnly (double [] m ) {
777763 return (m [0 ] == 1 && m [1 ] == 0 && m [2 ] == 0 && m [3 ] == 1 );
778764 }
@@ -988,15 +974,14 @@ public boolean hitClip(int x, int y, int width, int height) {
988974 return clipRect .intersects (x , y , width , height );
989975 }
990976
991- private int alpha ;
992-
993977 private void setGraphicsColor (Color c ) {
994978 if (c == null )
995979 return ; // this was the case with a JRootPanel graphic call
996980 int a = c .getAlpha ();
997981 // set alpha only if it is new and if this color has an alpha not 0xFF
998- if (a != alpha && a != 255 )
999- ctx .globalAlpha = (alpha = a ) / 256F ;
982+ float fa = a / 255F ;
983+ if (ctx .globalAlpha != fa )
984+ ctx .globalAlpha = fa ;
1000985 ctx .fillStyle = ctx .strokeStyle = JSToolkit .getCSSColor (c );
1001986 }
1002987
@@ -1219,22 +1204,12 @@ public void drawImage(BufferedImage img, BufferedImageOp op, int x, int y) {
12191204
12201205 public void setAlpha (float f ) {
12211206 ctx .globalAlpha = f ;
1222- alpha = (int ) Math .floor (f * 256 + 0.0039 );
12231207 }
12241208
12251209 public HTML5Canvas getCanvas () {
12261210 return canvas ;
12271211 }
12281212
1229- // /**
1230- // * used to determine if it is likely that the background was painted
1231- // *
1232- // * @return background taint count
1233- // */
1234- // public boolean isBackgroundPainted() {
1235- // return backgroundPainted;
1236- // }
1237-
12381213 /////////////// saving of the state ////////////////
12391214
12401215 private final static int SAVE_ALPHA = 0 ;
@@ -1243,7 +1218,6 @@ public HTML5Canvas getCanvas() {
12431218 private final static int SAVE_TRANSFORM = 3 ;
12441219 private final static int SAVE_FONT = 4 ;
12451220 private final static int SAVE_CLIP = 5 ;
1246- private final static int SAVE_BACKGROUND_PAINTED = 6 ;
12471221 private final static int SAVE_MAX = 7 ;
12481222
12491223 /**
@@ -1272,8 +1246,6 @@ private int mark(boolean isClone) {
12721246 map [SAVE_TRANSFORM ] = transform ;
12731247 map [SAVE_FONT ] = font ;
12741248 map [SAVE_CLIP ] = currentClip ;
1275- // map[SAVE_BACKGROUND_PAINTED] = (backgroundPainted ? Boolean.TRUE : Boolean.FALSE);
1276- // backgroundPainted = false;
12771249 return HTML5CanvasContext2D .push (ctx , map );
12781250 }
12791251
@@ -1342,16 +1314,11 @@ private void setState(Object[] map) {
13421314 @ SuppressWarnings ("unused" )
13431315 int a = SAVE_ALPHA ;
13441316 setAlpha (/** @j2sNative map[a] || */ 0 );
1345- // Float alpha = (Float) map[SAVE_ALPHA];
1346- // if (alpha != null) {
1347- // setAlpha(alpha.floatValue());
1348- // }
13491317 shader = null ;
13501318 setStroke ((Stroke ) map [SAVE_STROKE ]);
13511319 setTransform ((AffineTransform ) map [SAVE_TRANSFORM ]);
13521320 setFont ((Font ) map [SAVE_FONT ]);
13531321 currentClip = (Shape ) map [SAVE_CLIP ];
1354- // backgroundPainted = ((Boolean) map[SAVE_BACKGROUND_PAINTED]).booleanValue();
13551322 }
13561323
13571324 public Graphics create (int x , int y , int width , int height ) {
@@ -1421,4 +1388,12 @@ public void dispose() {
14211388 reset (initialState );
14221389 }
14231390
1391+ public int getWidth () {
1392+ return width ;
1393+ }
1394+
1395+ public int getHeight () {
1396+ return height ;
1397+ }
1398+
14241399}
0 commit comments