diff options
author | Francis Kung <fkung@redhat.com> | 2006-11-30 18:44:44 +0000 |
---|---|---|
committer | Francis Kung <fkung@redhat.com> | 2006-11-30 18:44:44 +0000 |
commit | 550f0d2a3367fd7dff43dc588c8b9c29f2b83f3a (patch) | |
tree | 2e0bff1fe8a969bbff8cd40aa7a71727b7ef7d43 /gnu/java/awt | |
parent | a0022fdf8ebe3311225cb2bc3a1d9fbba9cb26e1 (diff) | |
download | classpath-550f0d2a3367fd7dff43dc588c8b9c29f2b83f3a.tar.gz |
2006-11-30 Francis Kung <fkung@redhat.com>
* gnu/java/awt/peer/gtk/BufferedImageGraphics.java
(draw): Set transform in buffered composite.
(drawComposite): Do not transform bounds; round bounds.
(drawGlyphVector): Set transform in buffered composite.
(drawRenderedImage): Set transform in buffered composite.
(fill): Set transform in buffered composite.
(updateBufferedImage): Fix scanline & height calculations.
* gnu/java/awt/peer/gtk/CairoGraphics2D.java
(createPath): Simplify width & height calculation.
(drawImage): Also transform width & height.
Diffstat (limited to 'gnu/java/awt')
-rw-r--r-- | gnu/java/awt/peer/gtk/BufferedImageGraphics.java | 72 | ||||
-rw-r--r-- | gnu/java/awt/peer/gtk/CairoGraphics2D.java | 11 |
2 files changed, 55 insertions, 28 deletions
diff --git a/gnu/java/awt/peer/gtk/BufferedImageGraphics.java b/gnu/java/awt/peer/gtk/BufferedImageGraphics.java index 7de9c057e..37ae498ad 100644 --- a/gnu/java/awt/peer/gtk/BufferedImageGraphics.java +++ b/gnu/java/awt/peer/gtk/BufferedImageGraphics.java @@ -248,13 +248,13 @@ public class BufferedImageGraphics extends CairoGraphics2D if (sm.getScanlineStride() == imageWidth && minX == 0) { System.arraycopy(pixels, y * imageWidth, - db, y * imageWidth - minY, + db, (y - minY) * imageWidth, height * imageWidth); } else { int scanline = sm.getScanlineStride(); - for (int i = y; i < height; i++) + for (int i = y; i < (height + y); i++) System.arraycopy(pixels, i * imageWidth + x, db, (i - minY) * scanline + x - minX, width); @@ -313,6 +313,7 @@ public class BufferedImageGraphics extends CairoGraphics2D Graphics2D g2d = (Graphics2D)buffer.getGraphics(); g2d.setStroke(this.getStroke()); g2d.setColor(this.getColor()); + g2d.setTransform(transform); g2d.draw(s); drawComposite(r.getBounds2D(), null); @@ -334,6 +335,7 @@ public class BufferedImageGraphics extends CairoGraphics2D Graphics2D g2d = (Graphics2D)buffer.getGraphics(); g2d.setPaint(this.getPaint()); g2d.setColor(this.getColor()); + g2d.setTransform(transform); g2d.fill(s); drawComposite(s.getBounds2D(), null); @@ -353,6 +355,7 @@ public class BufferedImageGraphics extends CairoGraphics2D Graphics2D g2d = (Graphics2D)buffer.getGraphics(); g2d.setRenderingHints(this.getRenderingHints()); + g2d.setTransform(transform); g2d.drawRenderedImage(image, xform); drawComposite(buffer.getRaster().getBounds(), null); @@ -427,43 +430,64 @@ public class BufferedImageGraphics extends CairoGraphics2D Graphics2D g2d = (Graphics2D)buffer.getGraphics(); g2d.setPaint(this.getPaint()); g2d.setStroke(this.getStroke()); + g2d.setTransform(transform); g2d.drawGlyphVector(gv, x, y); drawComposite(bounds, null); } } + /** + * Perform composite drawing from the buffer onto the main image. + * + * The image to be composited should already be drawn into the buffer, in the + * proper place, after all necessary transforms have been applied. + * + * @param bounds The bounds to draw, in user-space. + * @param observer The image observer, if any (may be null). + * @return True on success, false on failure. + */ private boolean drawComposite(Rectangle2D bounds, ImageObserver observer) { - // Clip source to visible areas that need updating - Rectangle2D clip = this.getClipBounds(); - Rectangle2D.intersect(bounds, clip, bounds); - clip = new Rectangle(buffer.getMinX(), buffer.getMinY(), - buffer.getWidth(), buffer.getHeight()); - Rectangle2D.intersect(bounds, clip, bounds); + // Find bounds in device space + double[] points = new double[] {bounds.getX(), bounds.getY(), + bounds.getMaxX(), bounds.getMaxY()}; + transform.transform(points, 0, points, 0, 2); + bounds = new Rectangle2D.Double(points[0], points[1], + (points[2] - points[0]), + (points[3] - points[1])); + + // Clip bounds by the stored clip, and by the internal buffer + Rectangle2D devClip = this.getClipInDevSpace(); + Rectangle2D.intersect(bounds, devClip, bounds); + devClip = new Rectangle(buffer.getMinX(), buffer.getMinY(), + buffer.getWidth(), buffer.getHeight()); + Rectangle2D.intersect(bounds, devClip, bounds); + + // Round bounds as needed, but be conservative in our rounding + // (otherwise it may leave unpainted stripes) + double x = bounds.getX(); + double y = bounds.getY(); + double w = bounds.getWidth(); + double h = bounds.getHeight(); + if (Math.floor(x) != x) + w--; + if (Math.floor(y) != y) + h--; + bounds.setRect(Math.ceil(x), Math.ceil(y), Math.floor(w), Math.floor(h)); + // Find subimage of internal buffer for updating BufferedImage buffer2 = buffer; if (!bounds.equals(buffer2.getRaster().getBounds())) buffer2 = buffer2.getSubimage((int)bounds.getX(), (int)bounds.getY(), (int)bounds.getWidth(), (int)bounds.getHeight()); - - // Get destination clip to bounds - double[] points = new double[] {bounds.getX(), bounds.getY(), - bounds.getMaxX(), bounds.getMaxY()}; - transform.transform(points, 0, points, 0, 2); - - Rectangle2D deviceBounds = new Rectangle2D.Double(points[0], points[1], - points[2] - points[0], - points[3] - points[1]); - - Rectangle2D.intersect(deviceBounds, this.getClipInDevSpace(), deviceBounds); - + + // Find subimage of main image for updating BufferedImage current = image; - current = current.getSubimage((int)deviceBounds.getX(), - (int)deviceBounds.getY(), - (int)deviceBounds.getWidth(), - (int)deviceBounds.getHeight()); + current = current.getSubimage((int)bounds.getX(), (int)bounds.getY(), + (int)bounds.getWidth(), + (int)bounds.getHeight()); // Perform actual composite operation compCtx.compose(buffer2.getRaster(), current.getRaster(), diff --git a/gnu/java/awt/peer/gtk/CairoGraphics2D.java b/gnu/java/awt/peer/gtk/CairoGraphics2D.java index 16de95185..ec9890524 100644 --- a/gnu/java/awt/peer/gtk/CairoGraphics2D.java +++ b/gnu/java/awt/peer/gtk/CairoGraphics2D.java @@ -1153,8 +1153,8 @@ public abstract class CairoGraphics2D extends Graphics2D // does not get distorted by this shifting operation double x = shiftX(r.getX(),shiftDrawCalls && isDraw); double y = shiftY(r.getY(), shiftDrawCalls && isDraw); - double w = shiftX(r.getWidth() + r.getX(), shiftDrawCalls && isDraw) - x; - double h = shiftY(r.getHeight() + r.getY(), shiftDrawCalls && isDraw) - y; + double w = Math.round(r.getWidth()); + double h = Math.round(r.getHeight()); cairoRectangle(nativePointer, x, y, w, h); } @@ -1506,8 +1506,11 @@ public abstract class CairoGraphics2D extends Graphics2D setBackground(bgcolor); double[] origin = new double[] {0,0}; + double[] dimensions = new double[] {width, height}; xform.transform(origin, 0, origin, 0, 1); - clearRect((int)origin[0], (int)origin[1], width, height); + xform.deltaTransform(dimensions, 0, dimensions, 0, 1); + clearRect((int)origin[0], (int)origin[1], + (int)dimensions[0], (int)dimensions[1]); setBackground(oldColor); } @@ -2051,4 +2054,4 @@ public abstract class CairoGraphics2D extends Graphics2D return rect; } -} +}
\ No newline at end of file |