Index: gui/Source/NSImage.m
===================================================================
--- gui/Source/NSImage.m	(revision 28916)
+++ gui/Source/NSImage.m	(working copy)
@@ -773,16 +773,14 @@
   return _color;
 }
 
-
 // Using the Image 
 - (void) compositeToPoint: (NSPoint)aPoint 
                 operation: (NSCompositingOperation)op
 {
-  NSRect rect;
   // Might not be computed up to now
   NSSize size = [self size];
+  NSRect rect = NSMakeRect(0, 0, size.width, size.height);
 
-  rect = NSMakeRect(0, 0, size.width, size.height);
   [self compositeToPoint: aPoint fromRect: rect operation: op];
 }
 
@@ -790,64 +788,10 @@
                  fromRect: (NSRect)aRect
                 operation: (NSCompositingOperation)op
 {
-#if 0
-  [self compositeToPoint: aPoint
-        fromRect: aRect
+  [self compositeToPoint: aPoint 
+        fromRect: aRect 
         operation: op
         fraction: 1.0];
-#else 
-  NS_DURING
-    { 
-      NSImageRep *rep = [self bestRepresentationForDevice: nil];
-      NSCachedImageRep *cache = nil;
-
-      if (rep == nil)
-        NS_VOIDRETURN;
-
-      if (([GSCurrentContext() isDrawingToScreen] == YES)
-          && _cacheMode != NSImageCacheNever)
-        cache = [self _doImageCache: rep];
-
-      if (cache != nil)
-        {
-          NSRect rect;
-
-          rect = [cache rect];
-          NSDebugLLog(@"NSImage", @"composite rect %@ in %@", 
-                      NSStringFromRect(rect), NSStringFromRect(aRect));
-          // Move the drawing rectangle to the origin of the image rep
-          // and intersect the two rects.
-          aRect.origin.x += rect.origin.x;
-          aRect.origin.y += rect.origin.y;
-          rect = NSIntersectionRect(aRect, rect);
-          
-          PScomposite(NSMinX(rect), NSMinY(rect), NSWidth(rect), NSHeight(rect),
-                      [[cache window] gState], aPoint.x, aPoint.y, op);
-        }
-      else        
-        {
-          NSRect rect;
-
-          rect = NSMakeRect(aPoint.x, aPoint.y, _size.width, _size.height);
-          [self drawRepresentation: rep inRect: rect];
-        }
-    }
-  NS_HANDLER
-    {
-      NSLog(@"NSImage: compositeToPoint:fromRect:operation: failed due to %@: %@", 
-            [localException name], [localException reason]);
-      if ([_delegate respondsToSelector: @selector(imageDidNotDraw:inRect:)])
-        {
-          NSImage *image = [_delegate imageDidNotDraw: self inRect: aRect];
-
-          if (image != nil)
-            [image compositeToPoint: aPoint
-                   fromRect: aRect 
-                   operation: op];
-        }
-    }
-  NS_ENDHANDLER
-#endif
 }
 
 - (void) compositeToPoint: (NSPoint)aPoint
@@ -881,28 +825,55 @@
 
       if (cache != nil)
         {
-          NSRect rect;
+          NSGraphicsContext *ctxt = GSCurrentContext();
+          NSAffineTransform *transform = [ctxt GSCurrentCTM];
+          NSAffineTransformStruct oldTs = [transform transformStruct];
+          NSAffineTransformStruct newTs;
+          NSRect rect = [cache rect];
 
-          rect = [cache rect];
+          NSParameterAssert(NSEqualSizes(rect.size, srcRect.size));
+
           NSDebugLLog(@"NSImage", @"composite rect %@ in %@", 
                       NSStringFromRect(rect), NSStringFromRect(srcRect));
+
+         /* We want to suppress scaling and rotation only at aPoint, otherwise 
+            aPoint location will depend on the transform we apply by editing 
+            the transform struct.
+            The order matters and that's why we cannot use GScomposite with 
+            aPoint as the destination point. */
+          [transform translateXBy: aPoint.x yBy: aPoint.y];
+
+          newTs = [transform transformStruct];
+          /* Put identity matrix 2x2 in the CTM to suppress scaling and 
+             rotation but keep translation as is */
+          newTs.m11 = 1;
+          newTs.m12 = 0;
+          newTs.m21 = 0;
+          newTs.m22 = 1;
+
+         [transform setTransformStruct: newTs];
+         [ctxt GSSetCTM: transform];
+
           // Move the drawing rectangle to the origin of the image rep
           // and intersect the two rects.
           srcRect.origin.x += rect.origin.x;
           srcRect.origin.y += rect.origin.y;
           rect = NSIntersectionRect(srcRect, rect);
           
-          [GSCurrentContext() GScomposite: [[cache window] gState]
-                           toPoint: aPoint
-                           fromRect: rect
-                           operation: op
-                           fraction: delta];
+          [ctxt GScomposite: [[cache window] gState]
+                    toPoint: NSZeroPoint
+                   fromRect: rect
+                  operation: op
+                   fraction: delta];
+
+          /* Next line reverts -translateXBy:yBy: because oldTs was initialized 
+             before we translate the CTM */
+          [transform setTransformStruct: oldTs];
+          [ctxt GSSetCTM: transform];
         }
       else        
         {
-          NSRect rect;
-
-          rect = NSMakeRect(aPoint.x, aPoint.y, _size.width, _size.height);
+          NSRect rect = NSMakeRect(aPoint.x, aPoint.y, _size.width, _size.height);
           [self drawRepresentation: rep inRect: rect];
         }
     }
@@ -938,63 +909,10 @@
                 fromRect: (NSRect)aRect 
                 fraction: (float)aFloat
 {
-#if 0
   [self compositeToPoint: aPoint
         fromRect: aRect
         operation: NSCompositeSourceOver
         fraction: aFloat];
-#else 
-  NS_DURING
-    {
-      NSImageRep *rep = [self bestRepresentationForDevice: nil];
-      NSCachedImageRep *cache = nil;
-
-      if (rep == nil)
-        NS_VOIDRETURN;
-
-      if (([GSCurrentContext() isDrawingToScreen] == YES)
-          && _cacheMode != NSImageCacheNever)
-        cache = [self _doImageCache: rep];
-
-      if (cache != nil)
-        {
-          NSRect rect;
-          
-          rect = [cache rect];
-          // Move the drawing rectangle to the origin of the image rep
-          // and intersect the two rects.
-          aRect.origin.x += rect.origin.x;
-          aRect.origin.y += rect.origin.y;
-          rect = NSIntersectionRect(aRect, rect);
-          PSdissolve(NSMinX(rect), NSMinY(rect), NSWidth(rect), NSHeight(rect),
-                     [[cache window] gState], aPoint.x, aPoint.y, aFloat);
-        }
-      else
-        {
-          NSRect rect;
-
-          /* FIXME: Here we are supposed to composite directly from the source
-             but how do you do that? */
-          rect = NSMakeRect(aPoint.x, aPoint.y, _size.width, _size.height);
-          [self drawRepresentation: rep inRect: rect];
-        }
-    }
-  NS_HANDLER
-    {
-      NSLog(@"NSImage: dissolve failed due to %@: %@", 
-            [localException name], [localException reason]);
-      if ([_delegate respondsToSelector: @selector(imageDidNotDraw:inRect:)])
-        {
-          NSImage *image = [_delegate imageDidNotDraw: self inRect: aRect];
-
-          if (image != nil)
-            [image dissolveToPoint: aPoint
-                   fromRect: aRect 
-                   fraction: aFloat];
-        }
-    }
-  NS_ENDHANDLER
-#endif
 }
 
 - (BOOL) drawRepresentation: (NSImageRep *)imageRep inRect: (NSRect)aRect
Index: back/Source/cairo/CairoGState.m
===================================================================
--- back/Source/cairo/CairoGState.m	(revision 28916)
+++ back/Source/cairo/CairoGState.m	(working copy)
@@ -1179,35 +1179,21 @@
 		    tstruct.tX, tstruct.tY);
   cairo_transform(_ct, &local_matrix);
 
-  // Make up for flip done in GUI
-  if (viewIsFlipped)
-    {
-      cairo_pattern_t *cpattern;
-      cairo_matrix_t local_matrix;
+  // Flip Cairo coordinates to match AppKit
+  {
+    cairo_pattern_t *cpattern;
+    cairo_matrix_t local_matrix;
       
-      cpattern = cairo_pattern_create_for_surface(surface);
-      cairo_matrix_init_scale(&local_matrix, 1, -1);
-      cairo_matrix_translate(&local_matrix, 0, -2*pixelsHigh);
-      cairo_pattern_set_matrix(cpattern, &local_matrix);
-      cairo_set_source(_ct, cpattern);
-      cairo_pattern_destroy(cpattern);
+    cpattern = cairo_pattern_create_for_surface(surface);
+    cairo_matrix_init_scale(&local_matrix, 1, -1);
+    cairo_matrix_translate(&local_matrix, 0, -pixelsHigh);
+    cairo_pattern_set_matrix(cpattern, &local_matrix);
+    cairo_set_source(_ct, cpattern);
+    cairo_pattern_destroy(cpattern);
 
-      cairo_rectangle(_ct, 0, pixelsHigh, pixelsWide, pixelsHigh);
-    }
-  else 
-    {
-      cairo_pattern_t *cpattern;
-      cairo_matrix_t local_matrix;
-      
-      cpattern = cairo_pattern_create_for_surface(surface);
-      cairo_matrix_init_scale(&local_matrix, 1, -1);
-      cairo_matrix_translate(&local_matrix, 0, -pixelsHigh);
-      cairo_pattern_set_matrix(cpattern, &local_matrix);
-      cairo_set_source(_ct, cpattern);
-      cairo_pattern_destroy(cpattern);
-
-      cairo_rectangle(_ct, 0, 0, pixelsWide, pixelsHigh);
-    }
+    cairo_rectangle(_ct, 0, 0, pixelsWide, pixelsHigh);
+  }
+ 
   cairo_clip(_ct);
   cairo_paint(_ct);
   cairo_surface_destroy(surface);
@@ -1285,11 +1271,6 @@
   cairo_new_path(_ct);
   _set_op(_ct, op);
   
-  if (viewIsFlipped && !copyOnSelf)
-    {
-      aPoint.y -= aRect.size.height;
-    }
-
   {
       NSRect newRect;
       
