diff options
| author | Roman Kennke <roman@kennke.org> | 2006-06-12 10:32:44 +0000 |
|---|---|---|
| committer | Roman Kennke <roman@kennke.org> | 2006-06-12 10:32:44 +0000 |
| commit | ee5cfd42b6126fcfc3a780c0f63a7e8c0d8eb4ec (patch) | |
| tree | c5edc9cab04a79986acdd33e168747dfd943bf1c /gnu/java | |
| parent | 19d1362e9b7a8f492d202a4466085cf6640d3307 (diff) | |
| download | classpath-ee5cfd42b6126fcfc3a780c0f63a7e8c0d8eb4ec.tar.gz | |
2006-06-12 Roman Kennke <kennke@aicas.com>
* gnu/java/awt/peer/gtk/CairoGraphics2D.java
(drawPixels): Include alpha in parameter list.
(cairoFill): Include alpha in parameter list.
(setComposite): Don't modify the color.
(draw(Shape))): Use fill when the current composite has an alpha
of != 1.0, so that the stroked shaped will be composited.
(fill(Shape)): Call cairoFill() with alpha.
(drawImage): Call drawPixels or drawSurface with alpha.
(drawGlyphVector): When composite alpha is != 1.0, render the
outline using fill() to enable compositing for text.
(drawRaster): Call drawPixels with alpha.
* gnu/java/awt/peer/gtk/CairoGraphics2D.java
(nativeDrawSurface): Include alpha in parameter list.
(drawSurface): Include alpha in parameter list. Pass it to
nativeDrawSurface().
* include/gnu_java_awt_peer_gtk_CairoGraphics2D.h
* include/gnu_java_awt_peer_gtk_CairoSurface.h:
Regenerated.
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c
(drawPixels): Handle possible alpha for compositing.
(cairoFill): Likewise.
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c
(nativeDrawSurface): Handle possible alpha for compositing.
Diffstat (limited to 'gnu/java')
| -rw-r--r-- | gnu/java/awt/peer/gtk/CairoGraphics2D.java | 46 | ||||
| -rw-r--r-- | gnu/java/awt/peer/gtk/CairoSurface.java | 6 |
2 files changed, 38 insertions, 14 deletions
diff --git a/gnu/java/awt/peer/gtk/CairoGraphics2D.java b/gnu/java/awt/peer/gtk/CairoGraphics2D.java index a76962afc..692d556d3 100644 --- a/gnu/java/awt/peer/gtk/CairoGraphics2D.java +++ b/gnu/java/awt/peer/gtk/CairoGraphics2D.java @@ -65,6 +65,7 @@ import java.awt.font.TextLayout; import java.awt.geom.AffineTransform; import java.awt.geom.Arc2D; import java.awt.geom.Area; +import java.awt.geom.GeneralPath; import java.awt.geom.Line2D; import java.awt.geom.NoninvertibleTransformException; import java.awt.geom.PathIterator; @@ -309,7 +310,7 @@ public abstract class CairoGraphics2D extends Graphics2D * @param i2u - affine transform array */ private native void drawPixels(long pointer, int[] pixels, int w, int h, - int stride, double[] i2u); + int stride, double[] i2u, double alpha); private native void setGradient(long pointer, double x1, double y1, double x2, double y2, @@ -406,7 +407,7 @@ public abstract class CairoGraphics2D extends Graphics2D /** * Fill current path */ - private native void cairoFill(long pointer); + private native void cairoFill(long pointer, double alpha); /** * Clip current path @@ -802,9 +803,6 @@ public abstract class CairoGraphics2D extends Graphics2D { AlphaComposite a = (AlphaComposite) comp; cairoSetOperator(nativePointer, a.getRule()); - Color c = getColor(); - setColor(new Color(c.getRed(), c.getGreen(), c.getBlue(), - (int) (a.getAlpha() * ((float) c.getAlpha())))); } else { @@ -817,8 +815,21 @@ public abstract class CairoGraphics2D extends Graphics2D public void draw(Shape s) { - if (stroke != null && ! (stroke instanceof BasicStroke)) + if ((stroke != null && ! (stroke instanceof BasicStroke)) + || (comp instanceof AlphaComposite + && ((AlphaComposite) comp).getAlpha() != 1.0)) { + // FIXME: This is a hack to work around BasicStrokes's current + // limitations wrt cubic curves. + // See CubicSegment.getDisplacedSegments(). + if (stroke instanceof BasicStroke) + { + PathIterator flatten = s.getPathIterator(new AffineTransform(), + 1.0); + GeneralPath p = new GeneralPath(); + p.append(flatten, false); + s = p; + } fill(stroke.createStrokedShape(s)); return; } @@ -849,7 +860,10 @@ public abstract class CairoGraphics2D extends Graphics2D else walkPath(s.getPathIterator(null), false); - cairoFill(nativePointer); + double alpha = 1.0; + if (comp instanceof AlphaComposite) + alpha = ((AlphaComposite) comp).getAlpha(); + cairoFill(nativePointer, alpha); } /** @@ -1125,9 +1139,13 @@ public abstract class CairoGraphics2D extends Graphics2D invertedXform.getMatrix(i2u); + double alpha = 1.0; + if (comp instanceof AlphaComposite) + alpha = ((AlphaComposite) comp).getAlpha(); + if(db instanceof CairoSurface) { - ((CairoSurface)db).drawSurface(nativePointer, i2u); + ((CairoSurface)db).drawSurface(nativePointer, i2u, alpha); return true; } @@ -1163,7 +1181,7 @@ public abstract class CairoGraphics2D extends Graphics2D null, 0, width); } - drawPixels(nativePointer, pixels, width, height, width, i2u); + drawPixels(nativePointer, pixels, width, height, width, i2u, alpha); // Cairo seems to lose the current color which must be restored. updateColor(); @@ -1295,7 +1313,10 @@ public abstract class CairoGraphics2D extends Graphics2D public void drawGlyphVector(GlyphVector gv, float x, float y) { - if (gv instanceof FreetypeGlyphVector) + double alpha = 1.0; + if (comp instanceof AlphaComposite) + alpha = ((AlphaComposite) comp).getAlpha(); + if (gv instanceof FreetypeGlyphVector && alpha == 1.0) { int n = gv.getNumGlyphs (); int[] codes = gv.getGlyphCodes (0, n, null); @@ -1463,8 +1484,11 @@ public abstract class CairoGraphics2D extends Graphics2D for (int i = 0; i < pixels.length; i++) pixels[i] |= 0xFF000000; + double alpha = 1.0; + if (comp instanceof AlphaComposite) + alpha = ((AlphaComposite) comp).getAlpha(); drawPixels(nativePointer, pixels, r.getWidth(), r.getHeight(), - r.getWidth(), i2u); + r.getWidth(), i2u, alpha); // Cairo seems to lose the current color which must be restored. updateColor(); diff --git a/gnu/java/awt/peer/gtk/CairoSurface.java b/gnu/java/awt/peer/gtk/CairoSurface.java index 8287b95f2..b052ba229 100644 --- a/gnu/java/awt/peer/gtk/CairoSurface.java +++ b/gnu/java/awt/peer/gtk/CairoSurface.java @@ -112,11 +112,11 @@ public class CairoSurface extends DataBuffer * with an affine transform given by i2u. */ public native void nativeDrawSurface(long surfacePointer, long contextPointer, - double[] i2u); + double[] i2u, double alpha); - public void drawSurface(long contextPointer, double[] i2u) + public void drawSurface(long contextPointer, double[] i2u, double alpha) { - nativeDrawSurface(surfacePointer, contextPointer, i2u); + nativeDrawSurface(surfacePointer, contextPointer, i2u, alpha); } /** |
