This patch fixes (enables really) alpha compositing for text, stroked
shapes, CairoSurace-images and normal images.

For stroked shapes and text this means that it falls back to filling the
outline that is then created using the GlyphVector / Stroke methods.

Also note that I build in a hack in draw(Shape) to work around
BasicStroke's current limitation wrt CubicCurve. Sven, maybe you can
look into this?

2006-06-12  Roman Kennke  <[EMAIL PROTECTED]>

        * 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.

/Roman

-- 
“Improvement makes straight roads, but the crooked roads, without
Improvement, are roads of Genius.” - William Blake
Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c,v
retrieving revision 1.18
diff -u -1 -0 -r1.18 gnu_java_awt_peer_gtk_CairoSurface.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c	10 Jun 2006 14:16:09 -0000	1.18
+++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c	12 Jun 2006 10:31:43 -0000
@@ -174,21 +174,21 @@
   if( size > width * height ) size = width * height; /* stop overflows. */
   
   memcpy (pixeldata, jpixdata, size * sizeof( jint ));
 
   (*env)->ReleaseIntArrayElements (env, jpixels, jpixdata, 0);
 }
 
 JNIEXPORT void JNICALL
 Java_gnu_java_awt_peer_gtk_CairoSurface_nativeDrawSurface 
 (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)),
- jlong surfacePointer, jlong context, jdoubleArray java_matrix)
+ jlong surfacePointer, jlong context, jdoubleArray java_matrix, double alpha)
 {
   struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, context);
   cairo_t *cr = gr->cr;
   jdouble *native_matrix = NULL;
   cairo_surface_t* surface = JLONG_TO_PTR(void, surfacePointer);
   g_assert(surface != NULL);
   g_assert(cr != NULL);
 
   native_matrix = (*env)->GetDoubleArrayElements (env, java_matrix, NULL);
   g_assert (native_matrix != NULL);
@@ -200,21 +200,25 @@
    cairo_matrix_init_identity (&mat);
    cairo_matrix_init (&mat, 
                       native_matrix[0], native_matrix[1],
                       native_matrix[2], native_matrix[3],
                       native_matrix[4], native_matrix[5]);
 
    p = cairo_pattern_create_for_surface (surface);
    cairo_pattern_set_matrix (p, &mat);
 
    cairo_set_source(cr, p);
-   cairo_paint(cr);
+   if (alpha == 1.0)
+     cairo_paint(cr);
+   else
+     cairo_paint_with_alpha(cr, alpha);
+
    cairo_pattern_destroy(p);
  }
   
  (*env)->ReleaseDoubleArrayElements (env, java_matrix, native_matrix, 0);
 }
 
 JNIEXPORT jlong JNICALL 
 Java_gnu_java_awt_peer_gtk_CairoSurface_getFlippedBuffer 
 (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)),
  jlong bufferPointer, jint size)
Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c,v
retrieving revision 1.9
diff -u -1 -0 -r1.9 gnu_java_awt_peer_gtk_CairoGraphics2D.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c	10 Jun 2006 14:16:09 -0000	1.9
+++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c	12 Jun 2006 10:31:43 -0000
@@ -181,21 +181,21 @@
   gr->pattern = cairo_pattern_create_for_surface (gr->pattern_surface);
   g_assert (gr->pattern != NULL);
   cairo_pattern_set_extend (gr->pattern, CAIRO_EXTEND_REPEAT);
   cairo_set_source (gr->cr, gr->pattern);
 }
 
 JNIEXPORT void JNICALL
 Java_gnu_java_awt_peer_gtk_CairoGraphics2D_drawPixels 
 (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)),
  jlong pointer, jintArray java_pixels, 
- jint w, jint h, jint stride, jdoubleArray java_matrix)
+ jint w, jint h, jint stride, jdoubleArray java_matrix, jdouble alpha)
 {
   jint *native_pixels = NULL;
   jdouble *native_matrix = NULL;
   struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer);
   g_assert (gr != NULL);
 
   native_pixels = (*env)->GetIntArrayElements (env, java_pixels, NULL);
   native_matrix = (*env)->GetDoubleArrayElements (env, java_matrix, NULL);
   g_assert (native_pixels != NULL);
   g_assert (native_matrix != NULL);
@@ -211,21 +211,25 @@
    cairo_matrix_init (&mat, 
                       native_matrix[0], native_matrix[1],
                       native_matrix[2], native_matrix[3],
                       native_matrix[4], native_matrix[5]);
 
    p = cairo_pattern_create_for_surface (surf);
    cairo_pattern_set_matrix (p, &mat);
    if (gr->pattern)
      cairo_pattern_set_filter (p, cairo_pattern_get_filter (gr->pattern));
    cairo_set_source (gr->cr, p);
-   cairo_paint (gr->cr);
+   if (alpha == 1.)
+     cairo_paint (gr->cr);
+   else
+     cairo_paint_with_alpha(gr->cr, alpha);
+
    cairo_pattern_destroy (p);
    cairo_surface_destroy (surf);
  }
   
  (*env)->ReleaseIntArrayElements (env, java_pixels, native_pixels, 0);
  (*env)->ReleaseDoubleArrayElements (env, java_matrix, native_matrix, 0);
 }
 
 
 JNIEXPORT void JNICALL
@@ -574,26 +578,34 @@
 {
   struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer);
   g_assert (gr != NULL);
 
   cairo_stroke (gr->cr);
 }
 
 JNIEXPORT void JNICALL
 Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoFill 
 (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)),
- jlong pointer)
+ jlong pointer, jdouble alpha)
 {
   struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer);
   g_assert (gr != NULL);
 
-  cairo_fill (gr->cr);
+  if (alpha == 1.0)
+    cairo_fill (gr->cr);
+  else
+    {
+      cairo_save(gr->cr);
+      cairo_clip(gr->cr);
+      cairo_paint_with_alpha(gr->cr, alpha);
+      cairo_restore(gr->cr);
+    }
 }
 
 JNIEXPORT void JNICALL
 Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoClip 
 (JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)),
  jlong pointer)
 {
   struct cairographics2d *gr = JLONG_TO_PTR(struct cairographics2d, pointer);
   g_assert( gr != NULL );
 
@@ -646,20 +658,21 @@
       break;
     case java_awt_rendering_hints_VALUE_ALPHA_INTERPOLATION_DEFAULT:
       cairo_pattern_set_filter (gr->pattern, CAIRO_FILTER_NEAREST);
       break;
     case java_awt_rendering_hints_VALUE_ALPHA_INTERPOLATION_QUALITY:
       cairo_pattern_set_filter (gr->pattern, CAIRO_FILTER_BEST);
       break;
     }
 }
 
+
 /************************** FONT STUFF ****************************/
 static void
 install_font_peer(cairo_t *cr,
 		  struct peerfont *pfont)
 {
   cairo_font_face_t *ft;
   FT_Face face = NULL;
 
   g_assert(cr != NULL);
   g_assert(pfont != NULL);
@@ -696,11 +709,10 @@
   cairo_matrix_t mat;
 
   g_assert (gr != NULL);
   if (gr->pattern == NULL)
     return;
 
   cairo_get_matrix (gr->cr, &mat);
   cairo_pattern_set_matrix (gr->pattern, &mat);
 }
 
-
Index: include/gnu_java_awt_peer_gtk_CairoSurface.h
===================================================================
RCS file: /cvsroot/classpath/classpath/include/gnu_java_awt_peer_gtk_CairoSurface.h,v
retrieving revision 1.5
diff -u -1 -0 -r1.5 gnu_java_awt_peer_gtk_CairoSurface.h
--- include/gnu_java_awt_peer_gtk_CairoSurface.h	10 Jun 2006 14:16:10 -0000	1.5
+++ include/gnu_java_awt_peer_gtk_CairoSurface.h	12 Jun 2006 10:31:43 -0000
@@ -7,21 +7,21 @@
 
 #ifdef __cplusplus
 extern "C"
 {
 #endif
 
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoSurface_create (JNIEnv *env, jobject, jint, jint, jint);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoSurface_destroy (JNIEnv *env, jobject, jlong, jlong);
 JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_gtk_CairoSurface_nativeGetElem (JNIEnv *env, jobject, jlong, jint);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoSurface_nativeSetElem (JNIEnv *env, jobject, jlong, jint, jint);
-JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoSurface_nativeDrawSurface (JNIEnv *env, jobject, jlong, jlong, jdoubleArray);
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoSurface_nativeDrawSurface (JNIEnv *env, jobject, jlong, jlong, jdoubleArray, jdouble);
 JNIEXPORT jintArray JNICALL Java_gnu_java_awt_peer_gtk_CairoSurface_nativeGetPixels (JNIEnv *env, jobject, jlong, jint);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoSurface_nativeSetPixels (JNIEnv *env, jobject, jlong, jintArray);
 JNIEXPORT jlong JNICALL Java_gnu_java_awt_peer_gtk_CairoSurface_getFlippedBuffer (JNIEnv *env, jobject, jlong, jint);
 JNIEXPORT jlong JNICALL Java_gnu_java_awt_peer_gtk_CairoSurface_nativeNewCairoContext (JNIEnv *env, jobject, jlong);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoSurface_copyAreaNative2 (JNIEnv *env, jobject, jlong, jint, jint, jint, jint, jint, jint, jint);
 
 #ifdef __cplusplus
 }
 #endif
 
Index: include/gnu_java_awt_peer_gtk_CairoGraphics2D.h
===================================================================
RCS file: /cvsroot/classpath/classpath/include/gnu_java_awt_peer_gtk_CairoGraphics2D.h,v
retrieving revision 1.5
diff -u -1 -0 -r1.5 gnu_java_awt_peer_gtk_CairoGraphics2D.h
--- include/gnu_java_awt_peer_gtk_CairoGraphics2D.h	10 Jun 2006 14:16:10 -0000	1.5
+++ include/gnu_java_awt_peer_gtk_CairoGraphics2D.h	12 Jun 2006 10:31:43 -0000
@@ -5,41 +5,41 @@
 
 #include <jni.h>
 
 #ifdef __cplusplus
 extern "C"
 {
 #endif
 
 JNIEXPORT jlong JNICALL Java_gnu_java_awt_peer_gtk_CairoGraphics2D_init (JNIEnv *env, jobject, jlong);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoGraphics2D_disposeNative (JNIEnv *env, jobject, jlong);
-JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoGraphics2D_drawPixels (JNIEnv *env, jobject, jlong, jintArray, jint, jint, jint, jdoubleArray);
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoGraphics2D_drawPixels (JNIEnv *env, jobject, jlong, jintArray, jint, jint, jint, jdoubleArray, jdouble);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoGraphics2D_setGradient (JNIEnv *env, jobject, jlong, jdouble, jdouble, jdouble, jdouble, jint, jint, jint, jint, jint, jint, jint, jint, jboolean);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoGraphics2D_setTexturePixels (JNIEnv *env, jobject, jlong, jintArray, jint, jint, jint);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoSetMatrix (JNIEnv *env, jobject, jlong, jdoubleArray);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoSetOperator (JNIEnv *env, jobject, jlong, jint);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoSetRGBAColor (JNIEnv *env, jobject, jlong, jdouble, jdouble, jdouble, jdouble);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoSetFillRule (JNIEnv *env, jobject, jlong, jint);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoSetLine (JNIEnv *env, jobject, jlong, jdouble, jint, jint, jdouble);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoSetDash (JNIEnv *env, jobject, jlong, jdoubleArray, jint, jdouble);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoDrawGlyphVector (JNIEnv *env, jobject, jlong, jobject, jfloat, jfloat, jint, jintArray, jfloatArray);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoRelCurveTo (JNIEnv *env, jobject, jlong, jdouble, jdouble, jdouble, jdouble, jdouble, jdouble);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoRectangle (JNIEnv *env, jobject, jlong, jdouble, jdouble, jdouble, jdouble);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoNewPath (JNIEnv *env, jobject, jlong);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoClosePath (JNIEnv *env, jobject, jlong);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoMoveTo (JNIEnv *env, jobject, jlong, jdouble, jdouble);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoRelMoveTo (JNIEnv *env, jobject, jlong, jdouble, jdouble);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoLineTo (JNIEnv *env, jobject, jlong, jdouble, jdouble);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoRelLineTo (JNIEnv *env, jobject, jlong, jdouble, jdouble);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoCurveTo (JNIEnv *env, jobject, jlong, jdouble, jdouble, jdouble, jdouble, jdouble, jdouble);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoStroke (JNIEnv *env, jobject, jlong);
-JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoFill (JNIEnv *env, jobject, jlong);
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoFill (JNIEnv *env, jobject, jlong, jdouble);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoClip (JNIEnv *env, jobject, jlong);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoPreserveClip (JNIEnv *env, jobject, jlong);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoResetClip (JNIEnv *env, jobject, jlong);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoSurfaceSetFilter (JNIEnv *env, jobject, jlong, jint);
 
 #ifdef __cplusplus
 }
 #endif
 
 #endif /* __gnu_java_awt_peer_gtk_CairoGraphics2D__ */
Index: gnu/java/awt/peer/gtk/CairoGraphics2D.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/CairoGraphics2D.java,v
retrieving revision 1.19
diff -u -1 -0 -r1.19 CairoGraphics2D.java
--- gnu/java/awt/peer/gtk/CairoGraphics2D.java	11 Jun 2006 11:21:52 -0000	1.19
+++ gnu/java/awt/peer/gtk/CairoGraphics2D.java	12 Jun 2006 10:31:44 -0000
@@ -58,20 +58,21 @@
 import java.awt.Stroke;
 import java.awt.Polygon;
 import java.awt.TexturePaint;
 import java.awt.Toolkit;
 import java.awt.font.FontRenderContext;
 import java.awt.font.GlyphVector;
 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;
 import java.awt.geom.Point2D;
 import java.awt.geom.Rectangle2D;
 import java.awt.geom.RoundRectangle2D;
 import java.awt.image.AffineTransformOp;
 import java.awt.image.BufferedImage;
 import java.awt.image.BufferedImageOp;
 import java.awt.image.ColorModel;
@@ -302,21 +303,21 @@
    */
   public native void disposeNative(long pointer);
 
   /**
    * Draw pixels as an RGBA int matrix
    * @param w, h - width and height
    * @param stride - stride of the array width
    * @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,
                                   int r1, int g1, int b1, int a1, int r2,
                                   int g2, int b2, int a2, boolean cyclic);
   
   private native void setTexturePixels(long pointer, int[] pixels, int w,
                                        int h, int stride);
 
   /**
@@ -399,21 +400,21 @@
                                    double x3, double y3);
 
   /**
    * Stroke current path
    */
   private native void cairoStroke(long pointer);
 
   /**
    * Fill current path
    */
-  private native void cairoFill(long pointer);
+  private native void cairoFill(long pointer, double alpha);
 
   /** 
    * Clip current path
    */
   private native void cairoClip(long pointer);
 
   /** 
    * Save clip
    */
   private native void cairoPreserveClip(long pointer);
@@ -795,37 +796,47 @@
    * Sets the current composite context.
    */
   public void setComposite(Composite comp)
   {
     this.comp = comp;
 
     if (comp instanceof AlphaComposite)
       {
 	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
       {
         // FIXME: implement general Composite support
         throw new java.lang.UnsupportedOperationException();
       }
   }
 
   ///////////////////////// DRAWING PRIMITIVES ///////////////////////////////////
 
   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;
       }
 
     cairoNewPath(nativePointer);
 
     if (s instanceof Rectangle2D)
       {
 	Rectangle2D r = (Rectangle2D) s;
 	cairoRectangle(nativePointer, shifted(r.getX(), shiftDrawCalls),
@@ -842,21 +853,24 @@
     cairoNewPath(nativePointer);
     if (s instanceof Rectangle2D)
       {
 	Rectangle2D r = (Rectangle2D) s;
 	cairoRectangle(nativePointer, r.getX(), r.getY(), r.getWidth(),
                        r.getHeight());
       }
     else
       walkPath(s.getPathIterator(null), false);
 
-    cairoFill(nativePointer);
+    double alpha = 1.0;
+    if (comp instanceof AlphaComposite)
+      alpha = ((AlphaComposite) comp).getAlpha();
+    cairoFill(nativePointer, alpha);
   }
 
   /**
    * Note that the rest of the drawing methods go via fill() or draw() for the drawing,
    * although subclasses may with to overload these methods where context-specific 
    * optimizations are possible (e.g. bitmaps and fillRect(int, int, int, int)
    */
 
   public void clearRect(int x, int y, int width, int height)
   {
@@ -1118,23 +1132,27 @@
 
     // If this BufferedImage has a BufferedImageGraphics object, 
     // use the cached CairoSurface that BIG is drawing onto
     if( BufferedImageGraphics.bufferedImages.get( b ) != null )
       db = (DataBuffer)BufferedImageGraphics.bufferedImages.get( b );
     else
       db = b.getRaster().getDataBuffer();
 
     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;
       }
 	    
     if( bgcolor != null )
       {
 	// Fill a rectangle with the background color 
 	// to composite the image onto.
 	Paint oldPaint = paint;
 	AffineTransform oldTransform = transform;
 	setPaint( bgcolor );
@@ -1156,21 +1174,21 @@
     else if( b.getColorModel().equals(argb32) )
       {
 	pixels = ((DataBufferInt)db).getData();
       }
     else
       {
 	pixels = b.getRGB(0, 0, width, height,
 			  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();
     return true;
   }
 
   public void drawRenderedImage(RenderedImage image, AffineTransform xform)
   {
     drawRaster(image.getColorModel(), image.getData(), xform, null);
   }
@@ -1288,21 +1306,24 @@
     drawString (str, (float) x, (float) y);
   }
 
   public void drawString(AttributedCharacterIterator ci, int x, int y)
   {
     drawString (ci, (float) x, (float) y);
   }
 
   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);
         float[] positions = gv.getGlyphPositions (0, n, null);
 
         setFont (gv.getFont ());
         cairoDrawGlyphVector(nativePointer, (GdkFontPeer)getFont().getPeer(),
                              x, y, n, codes, positions);
       }
     else
@@ -1456,22 +1477,25 @@
 	  for (int i = 0; i < pixels.length; i++)
 	    {
 	      if (cm.getAlpha(pixels[i]) == 0)
 		pixels[i] = bgcolor.getRGB();
 	    }
       }
     else
       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();
     
     return true;
   }
 
   /**
    * Shifts coordinates by 0.5.
    */
Index: gnu/java/awt/peer/gtk/CairoSurface.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/CairoSurface.java,v
retrieving revision 1.8
diff -u -1 -0 -r1.8 CairoSurface.java
--- gnu/java/awt/peer/gtk/CairoSurface.java	10 Jun 2006 10:33:18 -0000	1.8
+++ gnu/java/awt/peer/gtk/CairoSurface.java	12 Jun 2006 10:31:44 -0000
@@ -105,25 +105,25 @@
   /**
    * Sets buffer elements.
    */
   private native void nativeSetElem(long bufferPointer, int i, int val);
 
   /**
    * Draws this image to a given CairoGraphics context, 
    * 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);
   }
 
   /**
    * getPixels -return the pixels as a java array.
    */
   native int[] nativeGetPixels(long bufferPointer, int size);
 
   public int[] getPixels(int size)
   {
     return nativeGetPixels(bufferPointer, size);

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil

Reply via email to