diff options
Diffstat (limited to 'libjava/classpath/gnu/java/awt/peer/gtk/GdkGraphics2D.java')
-rw-r--r-- | libjava/classpath/gnu/java/awt/peer/gtk/GdkGraphics2D.java | 180 |
1 files changed, 177 insertions, 3 deletions
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GdkGraphics2D.java b/libjava/classpath/gnu/java/awt/peer/gtk/GdkGraphics2D.java index b8203179d29..6d9aabf77d5 100644 --- a/libjava/classpath/gnu/java/awt/peer/gtk/GdkGraphics2D.java +++ b/libjava/classpath/gnu/java/awt/peer/gtk/GdkGraphics2D.java @@ -45,6 +45,7 @@ import java.awt.AlphaComposite; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Composite; +import java.awt.Dimension; import java.awt.Font; import java.awt.FontMetrics; import java.awt.GradientPaint; @@ -106,8 +107,7 @@ public class GdkGraphics2D extends Graphics2D if (Configuration.INIT_LOAD_LIBRARY) System.loadLibrary("gtkpeer"); - if (GtkToolkit.useGraphics2D()) - initStaticState(); + initStaticState(); } static native void initStaticState(); @@ -132,12 +132,14 @@ public class GdkGraphics2D extends Graphics2D Composite comp; private Stack stateStack; + private native void initStateUnlocked(GtkComponentPeer component); private native void initState(GtkComponentPeer component); private native void initState(int width, int height); private native void initState(int[] pixes, int width, int height); private native void copyState(GdkGraphics2D g); public native void dispose(); private native void cairoSurfaceSetFilter(int filter); + private native void cairoSurfaceSetFilterUnlocked(int filter); native void connectSignals(GtkComponentPeer component); public void finalize() @@ -236,6 +238,21 @@ public class GdkGraphics2D extends Graphics2D stateStack = new Stack(); } + void initComponentGraphics2DUnlocked() + { + initStateUnlocked(component); + + setColorUnlocked(component.awtComponent.getForeground()); + setBackgroundUnlocked(component.awtComponent.getBackground()); + setPaintUnlocked(getColorUnlocked()); + setTransformUnlocked(new AffineTransform()); + setStrokeUnlocked(new BasicStroke()); + setRenderingHintsUnlocked(getDefaultHints()); + setFontUnlocked(new Font("SansSerif", Font.PLAIN, 12)); + + stateStack = new Stack(); + } + GdkGraphics2D(BufferedImage bimage) { this.bimage = bimage; @@ -280,25 +297,37 @@ public class GdkGraphics2D extends Graphics2D // drawing utility methods private native void drawPixels(int[] pixels, int w, int h, int stride, double[] i2u); + private native void setTexturePixelsUnlocked(int[] pixels, int w, int h, int stride); private native void setTexturePixels(int[] pixels, int w, int h, int stride); private native void setGradient(double x1, double y1, double x2, double y2, int r1, int g1, int b1, int a1, int r2, int g2, int b2, int a2, boolean cyclic); + private native void setGradientUnlocked(double x1, double y1, double x2, double y2, + int r1, int g1, int b1, int a1, int r2, + int g2, int b2, int a2, boolean cyclic); // simple passthroughs to cairo private native void cairoSave(); private native void cairoRestore(); private native void cairoSetMatrix(double[] m); + private native void cairoSetMatrixUnlocked(double[] m); private native void cairoSetOperator(int cairoOperator); private native void cairoSetRGBAColor(double red, double green, double blue, double alpha); + private native void cairoSetRGBAColorUnlocked(double red, double green, + double blue, double alpha); private native void cairoSetFillRule(int cairoFillRule); private native void cairoSetLineWidth(double width); + private native void cairoSetLineWidthUnlocked(double width); private native void cairoSetLineCap(int cairoLineCap); + private native void cairoSetLineCapUnlocked(int cairoLineCap); private native void cairoSetLineJoin(int cairoLineJoin); + private native void cairoSetLineJoinUnlocked(int cairoLineJoin); private native void cairoSetDash(double[] dashes, int ndash, double offset); + private native void cairoSetDashUnlocked(double[] dashes, int ndash, double offset); private native void cairoSetMiterLimit(double limit); + private native void cairoSetMiterLimitUnlocked(double limit); private native void cairoNewPath(); private native void cairoMoveTo(double x, double y); private native void cairoLineTo(double x, double y); @@ -689,6 +718,49 @@ public class GdkGraphics2D extends Graphics2D throw new java.lang.UnsupportedOperationException(); } + public void setPaintUnlocked(Paint p) + { + if (paint == null) + return; + + paint = p; + if (paint instanceof Color) + { + setColorUnlocked((Color) paint); + } + else if (paint instanceof TexturePaint) + { + TexturePaint tp = (TexturePaint) paint; + BufferedImage img = tp.getImage(); + + // map the image to the anchor rectangle + int width = (int) tp.getAnchorRect().getWidth(); + int height = (int) tp.getAnchorRect().getHeight(); + + double scaleX = width / (double) img.getWidth(); + double scaleY = width / (double) img.getHeight(); + + AffineTransform at = new AffineTransform(scaleX, 0, 0, scaleY, 0, 0); + AffineTransformOp op = new AffineTransformOp(at, getRenderingHints()); + BufferedImage texture = op.filter(img, null); + int[] pixels = texture.getRGB(0, 0, width, height, null, 0, width); + setTexturePixelsUnlocked(pixels, width, height, width); + } + else if (paint instanceof GradientPaint) + { + GradientPaint gp = (GradientPaint) paint; + Point2D p1 = gp.getPoint1(); + Point2D p2 = gp.getPoint2(); + Color c1 = gp.getColor1(); + Color c2 = gp.getColor2(); + setGradientUnlocked(p1.getX(), p1.getY(), p2.getX(), p2.getY(), c1.getRed(), + c1.getGreen(), c1.getBlue(), c1.getAlpha(), c2.getRed(), + c2.getGreen(), c2.getBlue(), c2.getAlpha(), gp.isCyclic()); + } + else + throw new java.lang.UnsupportedOperationException(); + } + public void setTransform(AffineTransform tx) { transform = tx; @@ -700,6 +772,17 @@ public class GdkGraphics2D extends Graphics2D } } + public void setTransformUnlocked(AffineTransform tx) + { + transform = tx; + if (transform != null) + { + double[] m = new double[6]; + transform.getMatrix(m); + cairoSetMatrixUnlocked(m); + } + } + public void transform(AffineTransform tx) { if (transform == null) @@ -784,6 +867,32 @@ public class GdkGraphics2D extends Graphics2D cairoSetDash(double_dashes, double_dashes.length, (double) bs.getDashPhase()); } + else + cairoSetDash(new double[0], 0, 0.0); + } + } + + public void setStrokeUnlocked(Stroke st) + { + stroke = st; + if (stroke instanceof BasicStroke) + { + BasicStroke bs = (BasicStroke) stroke; + cairoSetLineCapUnlocked(bs.getEndCap()); + cairoSetLineWidthUnlocked(bs.getLineWidth()); + cairoSetLineJoinUnlocked(bs.getLineJoin()); + cairoSetMiterLimitUnlocked(bs.getMiterLimit()); + float[] dashes = bs.getDashArray(); + if (dashes != null) + { + double[] double_dashes = new double[dashes.length]; + for (int i = 0; i < dashes.length; i++) + double_dashes[i] = dashes[i]; + cairoSetDashUnlocked(double_dashes, double_dashes.length, + (double) bs.getDashPhase()); + } + else + cairoSetDashUnlocked(new double[0], 0, 0.0); } } @@ -812,11 +921,27 @@ public class GdkGraphics2D extends Graphics2D fg.getBlue() / 255.0, fg.getAlpha() / 255.0); } + public void setColorUnlocked(Color c) + { + if (c == null) + c = Color.BLACK; + + fg = c; + paint = c; + cairoSetRGBAColorUnlocked(fg.getRed() / 255.0, fg.getGreen() / 255.0, + fg.getBlue() / 255.0, fg.getAlpha() / 255.0); + } + public Color getColor() { return fg; } + public Color getColorUnlocked() + { + return getColor(); + } + public void clipRect(int x, int y, int width, int height) { clip(new Rectangle(x, y, width, height)); @@ -864,7 +989,13 @@ public class GdkGraphics2D extends Graphics2D public void setClip(Shape s) { clip = s; - if (s != null) + if (clip == null) + { + // Reset clipping. + Dimension d = component.awtComponent.getSize(); + setClip(0, 0, d.width, d.height); + } + else { cairoNewPath(); if (s instanceof Rectangle2D) @@ -929,6 +1060,11 @@ public class GdkGraphics2D extends Graphics2D bg = c; } + public void setBackgroundUnlocked(Color c) + { + setBackground(c); + } + public Color getBackground() { return bg; @@ -1180,6 +1316,36 @@ public class GdkGraphics2D extends Graphics2D || hints.containsValue(RenderingHints.VALUE_STROKE_DEFAULT); } + public void setRenderingHintsUnlocked(Map hints) + { + this.hints = new RenderingHints(getDefaultHints()); + this.hints.add(new RenderingHints(hints)); + + if (hints.containsKey(RenderingHints.KEY_INTERPOLATION)) + { + if (hints.containsValue(RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR)) + cairoSurfaceSetFilterUnlocked(0); + + else if (hints.containsValue(RenderingHints.VALUE_INTERPOLATION_BILINEAR)) + cairoSurfaceSetFilterUnlocked(1); + } + + if (hints.containsKey(RenderingHints.KEY_ALPHA_INTERPOLATION)) + { + if (hints.containsValue(RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED)) + cairoSurfaceSetFilterUnlocked(2); + + else if (hints.containsValue(RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY)) + cairoSurfaceSetFilterUnlocked(3); + + else if (hints.containsValue(RenderingHints.VALUE_ALPHA_INTERPOLATION_DEFAULT)) + cairoSurfaceSetFilterUnlocked(4); + } + + shiftDrawCalls = hints.containsValue(RenderingHints.VALUE_STROKE_NORMALIZE) + || hints.containsValue(RenderingHints.VALUE_STROKE_DEFAULT); + } + public void addRenderingHints(Map hints) { this.hints.add(new RenderingHints(hints)); @@ -1344,6 +1510,9 @@ public class GdkGraphics2D extends Graphics2D public void drawString(String str, float x, float y) { + if (str == null || str.length() == 0) + return; + drawGlyphVector(getFont().createGlyphVector(null, str), x, y); updateBufferedImage (); } @@ -1443,6 +1612,11 @@ public class GdkGraphics2D extends Graphics2D .getFont(f.getName(), f.getAttributes()); } + public void setFontUnlocked(Font f) + { + setFont (f); + } + public String toString() { return (getClass().getName() |