ugly hacks to accomodate Apple's buggy AWT implementation
[org.ibex.core.git] / src / org / ibex / plat / Java2.java
index d8b5dc4..b91eeba 100644 (file)
@@ -7,6 +7,7 @@ package org.ibex.plat;
 import java.awt.*;
 import java.awt.event.*;
 import java.awt.image.*;
+import java.awt.geom.*;
 import java.net.*;
 import java.util.*;
 import org.ibex.util.*;
@@ -20,13 +21,6 @@ public class Java2 extends AWT {
 
     protected String getDescriptiveName() { return "Java 1.2+ JVM"; }
     public Java2() {
-        // Properties for Apple JDK 1.3
-        System.setProperty("apple.awt.showGrowBox", "false");
-        System.setProperty("com.apple.hwaccel", "true");
-        System.setProperty("com.apple.forcehwaccel", "true");
-        System.setProperty("apple.awt.window.position.forceSafeUserPositioning", "true");
-        System.setProperty("apple.awt.window.position.forceSafeCreation", "true");
-
         // disable the focus manager so we can intercept the tab key
         javax.swing.FocusManager.setCurrentManager(new javax.swing.FocusManager() {
                 public void processKeyEvent(Component focusedComponent, KeyEvent anEvent) { }
@@ -96,7 +90,6 @@ public class Java2 extends AWT {
 
     public static class Java2Surface extends AWTSurface {
         public Java2Surface(Box root, boolean framed) { super(root, framed); }
-
         protected void _setMinimized(boolean b) {
             if (frame == null) Log.info(this, "JDK 1.2 can only minimize frames, not windows");
             else if (b) frame.setState(java.awt.Frame.ICONIFIED);
@@ -119,18 +112,27 @@ public class Java2 extends AWT {
         private SampleModel sm = null;
         private DataBuffer buf = null;
 
-        // this doens't seem to work on Windows
-        public void drawGlyph(org.ibex.graphics.Font.Glyph source, int dx, int dy, int cx1, int cy1, int cx2, int cy2, int rgb) {
-            Image i2 = ((AWTGlyph)source).getImage();
-            Graphics2D g2 = (Graphics2D)i.getGraphics();
-            g2.setComposite(AlphaComposite.DstOut);
-            g2.setClip(cx1, cy1, cx2 - cx1, cy2 - cy1);
-            g2.drawImage(i2, dx, dy, null);
-            g2.setComposite(AlphaComposite.DstOver);
-            g2.setColor(new java.awt.Color((rgb & 0x00FF0000) >> 16, (rgb & 0x0000FF00) >> 8, (rgb & 0x000000FF)));
-            g2.fillRect(dx, dy, cx2 - dx, cy2 - dy);
-            g2.drawImage(i2, 0, 0, null);
-            g2.setClip(0, 0, i.getWidth(null), i.getHeight(null));
+        private static int[] xs = new int[65535];
+        private static int[] ys = new int[65535];
+        private static GeneralPath gp = new GeneralPath();
+
+        public void fill(org.ibex.graphics.Polygon p, org.ibex.graphics.Paint paint) { fillStroke(p, paint, true, false); }
+        public void stroke(org.ibex.graphics.Polygon p, org.ibex.graphics.Paint paint) { fillStroke(p, paint, false, true); }
+        public void fillStroke(org.ibex.graphics.Polygon p, org.ibex.graphics.Paint paint, boolean fill, boolean stroke) {
+            if (g == null) g = getGraphics();
+            ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); 
+            int argb = ((org.ibex.graphics.Paint.SingleColorPaint)paint).color;
+            g.setColor(new java.awt.Color((argb & 0x00FF0000) >> 16, (argb & 0x0000FF00) >> 8, (argb & 0x000000FF)));
+            gp.reset();
+            gp.setWindingRule(GeneralPath.WIND_EVEN_ODD);
+            for(int j=0; j<p.numcontours; j++) {
+                if (p.contours[j+1] <= p.contours[j]) continue;
+                gp.moveTo(p.x[p.contours[j]], p.y[p.contours[j]]);
+                for(int i=p.contours[j]+1; i<p.contours[j+1]; i++) gp.lineTo(p.x[i], p.y[i]);
+                gp.closePath();
+            }
+            if (fill) ((Graphics2D)g).fill(gp);
+            if (stroke) ((Graphics2D)g).draw(gp);
         }
 
         public Java2PixelBuffer(int w, int h) {