Tread a zero source rectangle as the full image and clip to the

image bounds.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@25649 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
fredkiefer 2007-11-30 19:52:26 +00:00
parent 296fd50a2e
commit ff79c63530
2 changed files with 45 additions and 29 deletions

View file

@ -1,3 +1,9 @@
2007-11-30 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSImage.m (-drawInRect:fromRect:operation:fraction:):
Tread a zero source rectangle as the full image and clip to the
image bounds.
2007-11-30 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSClipView.m: ([scrollToPoint]) reset cursor rectangles when

View file

@ -957,35 +957,48 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
fraction: (float)delta
{
[self drawInRect: NSMakeRect(point.x, point.y, srcRect.size.width,
srcRect.size.height)
fromRect: srcRect
operation: op
fraction: delta];
srcRect.size.height)
fromRect: srcRect
operation: op
fraction: delta];
}
- (void) drawInRect: (NSRect)dstRect
fromRect: (NSRect)srcRect
operation: (NSCompositingOperation)op
fraction: (float)delta
fromRect: (NSRect)srcRect
operation: (NSCompositingOperation)op
fraction: (float)delta
{
NSGraphicsContext *ctxt = GSCurrentContext();
NSAffineTransform *transform;
NSSize s;
s = [self size];
if (NSEqualRects(srcRect, NSZeroRect))
srcRect = NSMakeRect(0, 0, s.width, s.height);
if (!dstRect.size.width || !dstRect.size.height
|| !srcRect.size.width || !srcRect.size.height)
return;
// CLip to image bounds
if (srcRect.origin.x < 0)
srcRect.origin.x = 0;
if (srcRect.origin.y < 0)
srcRect.origin.y = 0;
if (NSMaxX(srcRect) > s.width)
srcRect.size.width = s.width - srcRect.origin.x;
if (NSMaxY(srcRect) > s.height)
srcRect.size.height = s.height - srcRect.origin.y;
if (![ctxt isDrawingToScreen])
{
/* We can't composite or dissolve if we aren't drawing to a screen,
so we'll just draw the right part of the image in the right
place. */
NSSize s;
so we'll just draw the right part of the image in the right
place. */
NSPoint p;
double fx, fy;
s = [self size];
fx = dstRect.size.width / srcRect.size.width;
fy = dstRect.size.height / srcRect.size.height;
@ -994,10 +1007,10 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
DPSgsave(ctxt);
DPSrectclip(ctxt, dstRect.origin.x, dstRect.origin.y,
dstRect.size.width, dstRect.size.height);
dstRect.size.width, dstRect.size.height);
DPSscale(ctxt, fx, fy);
[self drawRepresentation: [self bestRepresentationForDevice: nil]
inRect: NSMakeRect(p.x, p.y, s.width, s.height)];
inRect: NSMakeRect(p.x, p.y, s.width, s.height)];
DPSgrestore(ctxt);
return;
@ -1019,13 +1032,13 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
NSAffineTransformStruct ts = [transform transformStruct];
if (fabs(ts.m11 - 1.0) < 0.01 && fabs(ts.m12) < 0.01
&& fabs(ts.m21) < 0.01 && fabs(ts.m22 - 1.0) < 0.01)
{
[self compositeToPoint: dstRect.origin
fromRect: srcRect
operation: op];
return;
}
&& fabs(ts.m21) < 0.01 && fabs(ts.m22 - 1.0) < 0.01)
{
[self compositeToPoint: dstRect.origin
fromRect: srcRect
operation: op];
return;
}
}
/* We can't composite or dissolve directly from the image reps, so we
@ -1038,25 +1051,22 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
things we could do to:
1. Take srcRect into account and only process the parts of the image
we really need.
we really need.
2. Take the clipping path into account. Desirable, especially if we're
being drawn as lots of small strips in a scrollview. We don't have
the clipping path here, though.
being drawn as lots of small strips in a scrollview. We don't have
the clipping path here, though.
3. Allocate a permanent but small buffer and process the image
piecewise.
piecewise.
*/
{
NSCachedImageRep *cache;
NSAffineTransformStruct ts;
NSSize s;
NSPoint p;
double x0, y0, x1, y1, w, h;
int gState;
NSGraphicsContext *ctxt1;
s = [self size];
/* Figure out how big we need to make the window that'll hold the
transformed image. */
p = [transform transformPoint: NSMakePoint(0, s.height)];