Get the device description for an NSImage representation from the window.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@27074 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
fredkiefer 2008-11-16 23:21:58 +00:00
parent bd1466c314
commit 83c47a9e6f
2 changed files with 79 additions and 70 deletions

View file

@ -1,3 +1,8 @@
2008-11-17 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSImage.m (-bestRepresentationForDevice:): Get the device
desription from the window.
2008-11-16 Fred Kiefer <FredKiefer@gmx.de> 2008-11-16 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSView.m (-setBounds:, -setBoundsSize:): Fixed bug in * Source/NSView.m (-setBounds:, -setBoundsSize:): Fixed bug in

View file

@ -1201,13 +1201,15 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
- (void) lockFocusOnRepresentation: (NSImageRep *)imageRep - (void) lockFocusOnRepresentation: (NSImageRep *)imageRep
{ {
// FIXME: THis should rather use
// [NSGraphicsContext graphicsContextWithBitmapImageRep:]
if (_cacheMode != NSImageCacheNever) if (_cacheMode != NSImageCacheNever)
{ {
NSWindow *window; NSWindow *window;
GSRepData *repd; GSRepData *repd;
if (imageRep == nil) if (imageRep == nil)
imageRep = [self bestRepresentationForDevice: nil]; imageRep = [self bestRepresentationForDevice: nil];
imageRep = [self _cacheForRep: imageRep]; imageRep = [self _cacheForRep: imageRep];
repd = repd_for_rep(_reps, imageRep); repd = repd_for_rep(_reps, imageRep);
@ -1215,30 +1217,30 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
window = [(NSCachedImageRep *)imageRep window]; window = [(NSCachedImageRep *)imageRep window];
_lockedView = [window contentView]; _lockedView = [window contentView];
if (_lockedView == nil) if (_lockedView == nil)
[NSException raise: NSImageCacheException [NSException raise: NSImageCacheException
format: @"Cannot lock focus on nil rep"]; format: @"Cannot lock focus on nil rep"];
[_lockedView lockFocus]; [_lockedView lockFocus];
/* Validate cached image */ /* Validate cached image */
if (repd->bg == nil) if (repd->bg == nil)
{ {
repd->bg = [_color copy]; repd->bg = [_color copy];
[_color set]; [_color set];
if ([_color alphaComponent] < 1) if ([_color alphaComponent] < 1)
{ {
/* With a Quartz-like alpha model, alpha can't be cleared /* With a Quartz-like alpha model, alpha can't be cleared
with a rectfill, so we need to clear the alpha channel with a rectfill, so we need to clear the alpha channel
explictly. (A compositerect with NSCompositeCopy would explictly. (A compositerect with NSCompositeCopy would
be more efficient, but it doesn't seem like it's be more efficient, but it doesn't seem like it's
implemented correctly in all backends yet (as of implemented correctly in all backends yet (as of
2002-08-23). Also, this will work with both the Quartz- 2002-08-23). Also, this will work with both the Quartz-
and DPS-model.) */ and DPS-model.) */
PScompositerect(0, 0, _size.width, _size.height, PScompositerect(0, 0, _size.width, _size.height,
NSCompositeClear); NSCompositeClear);
} }
NSRectFill(NSMakeRect(0, 0, _size.width, _size.height)); NSRectFill(NSMakeRect(0, 0, _size.width, _size.height));
} }
} }
} }
@ -1390,13 +1392,15 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
{ {
if ([GSCurrentContext() isDrawingToScreen] == YES) if ([GSCurrentContext() isDrawingToScreen] == YES)
{ {
// Take the device description from the current context. // Take the device description from the current context.
deviceDescription = [GSCurrentContext() attributes]; deviceDescription = [[[GSCurrentContext() attributes] objectForKey:
NSGraphicsContextDestinationAttributeName]
deviceDescription];
} }
else if ([NSPrintOperation currentOperation]) else if ([NSPrintOperation currentOperation])
{ {
/* FIXME: We could try to use the current printer, /* FIXME: We could try to use the current printer,
but there are many cases where might but there are many cases where might
not be printing (EPS, PDF, etc) to a specific device */ not be printing (EPS, PDF, etc) to a specific device */
} }
} }
@ -1458,7 +1462,7 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
} }
- (NSData *) TIFFRepresentationUsingCompression: (NSTIFFCompression)comp - (NSData *) TIFFRepresentationUsingCompression: (NSTIFFCompression)comp
factor: (float)aFloat factor: (float)aFloat
{ {
NSData *data; NSData *data;
@ -1588,71 +1592,71 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
{ {
if ([coder containsValueForKey: @"NSColor"]) if ([coder containsValueForKey: @"NSColor"])
{ {
[self setBackgroundColor: [coder decodeObjectForKey: @"NSColor"]]; [self setBackgroundColor: [coder decodeObjectForKey: @"NSColor"]];
} }
if ([coder containsValueForKey: @"NSImageFlags"]) if ([coder containsValueForKey: @"NSImageFlags"])
{ {
int flags; int flags;
//FIXME //FIXME
flags = [coder decodeIntForKey: @"NSImageFlags"]; flags = [coder decodeIntForKey: @"NSImageFlags"];
} }
if ([coder containsValueForKey: @"NSReps"]) if ([coder containsValueForKey: @"NSReps"])
{ {
NSArray *reps; NSArray *reps;
// FIXME: NSReps is in a strange format. It is a mutable array with one // FIXME: NSReps is in a strange format. It is a mutable array with one
// element which is an array with a first element 0 and than the image rep. // element which is an array with a first element 0 and than the image rep.
reps = [coder decodeObjectForKey: @"NSReps"]; reps = [coder decodeObjectForKey: @"NSReps"];
reps = [reps objectAtIndex: 0]; reps = [reps objectAtIndex: 0];
[self addRepresentation: [reps objectAtIndex: 1]]; [self addRepresentation: [reps objectAtIndex: 1]];
} }
if ([coder containsValueForKey: @"NSSize"]) if ([coder containsValueForKey: @"NSSize"])
{ {
[self setSize: [coder decodeSizeForKey: @"NSSize"]]; [self setSize: [coder decodeSizeForKey: @"NSSize"]];
} }
} }
else else
{ {
[coder decodeValueOfObjCType: @encode(BOOL) at: &flag]; [coder decodeValueOfObjCType: @encode(BOOL) at: &flag];
if (flag == YES) if (flag == YES)
{ {
NSString *theName = [coder decodeObject]; NSString *theName = [coder decodeObject];
RELEASE(self); RELEASE(self);
self = RETAIN([NSImage imageNamed: theName]); self = RETAIN([NSImage imageNamed: theName]);
} }
else else
{ {
NSArray *a; NSArray *a;
[coder decodeValueOfObjCType: @encode(NSSize) at: &_size]; [coder decodeValueOfObjCType: @encode(NSSize) at: &_size];
[coder decodeValueOfObjCType: @encode(id) at: &_color]; [coder decodeValueOfObjCType: @encode(id) at: &_color];
[coder decodeValueOfObjCType: @encode(BOOL) at: &flag]; [coder decodeValueOfObjCType: @encode(BOOL) at: &flag];
_flags.scalable = flag; _flags.scalable = flag;
[coder decodeValueOfObjCType: @encode(BOOL) at: &flag]; [coder decodeValueOfObjCType: @encode(BOOL) at: &flag];
_flags.dataRetained = flag; _flags.dataRetained = flag;
[coder decodeValueOfObjCType: @encode(BOOL) at: &flag]; [coder decodeValueOfObjCType: @encode(BOOL) at: &flag];
_flags.flipDraw = flag; _flags.flipDraw = flag;
[coder decodeValueOfObjCType: @encode(BOOL) at: &flag]; [coder decodeValueOfObjCType: @encode(BOOL) at: &flag];
_flags.sizeWasExplicitlySet = flag; _flags.sizeWasExplicitlySet = flag;
[coder decodeValueOfObjCType: @encode(BOOL) at: &flag]; [coder decodeValueOfObjCType: @encode(BOOL) at: &flag];
_flags.useEPSOnResolutionMismatch = flag; _flags.useEPSOnResolutionMismatch = flag;
[coder decodeValueOfObjCType: @encode(BOOL) at: &flag]; [coder decodeValueOfObjCType: @encode(BOOL) at: &flag];
_flags.colorMatchPreferred = flag; _flags.colorMatchPreferred = flag;
[coder decodeValueOfObjCType: @encode(BOOL) at: &flag]; [coder decodeValueOfObjCType: @encode(BOOL) at: &flag];
_flags.multipleResolutionMatching = flag; _flags.multipleResolutionMatching = flag;
[coder decodeValueOfObjCType: @encode(BOOL) at: &flag]; [coder decodeValueOfObjCType: @encode(BOOL) at: &flag];
_flags.cacheSeparately = flag; _flags.cacheSeparately = flag;
[coder decodeValueOfObjCType: @encode(BOOL) at: &flag]; [coder decodeValueOfObjCType: @encode(BOOL) at: &flag];
_flags.unboundedCacheDepth = flag; _flags.unboundedCacheDepth = flag;
/* /*
* get the image reps and add them. * get the image reps and add them.
*/ */
a = [coder decodeObject]; a = [coder decodeObject];
[self addRepresentations: a]; [self addRepresentations: a];
} }
} }
return self; return self;
} }