* GormCore/GormImage.m: Fix the init issue for the second

method as well. Small cleanup.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@38002 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2014-07-21 07:21:48 +00:00
parent 2af7de1105
commit abce1603c7
2 changed files with 45 additions and 48 deletions

View file

@ -1,3 +1,8 @@
2014-07-21 Fred Kiefer <FredKiefer@gmx.de>
* GormCore/GormImage.m: Fix the init issue for the second
method as well. Small cleanup.
2014-05-31 10:58-EDT Gregory John Casamento <greg.casamento@gmail.com> 2014-05-31 10:58-EDT Gregory John Casamento <greg.casamento@gmail.com>
* GormCore/GormDocumentController.h: add declaration of * GormCore/GormDocumentController.h: add declaration of

View file

@ -56,37 +56,49 @@
return AUTORELEASE([[GormImage alloc] initWithData: aData withFileName: aName inWrapper: flag]); return AUTORELEASE([[GormImage alloc] initWithData: aData withFileName: aName inWrapper: flag]);
} }
- (void) _resizeSmallImage
{
NSSize originalSize;
CGFloat ratioH;
CGFloat ratioW;
originalSize = [smallImage size];
ratioW = originalSize.width / 70;
ratioH = originalSize.height / 55;
if (ratioH > 1 || ratioW > 1)
{
[smallImage setScalesWhenResized: YES];
if (ratioH > ratioW)
{
[smallImage setSize: NSMakeSize(originalSize.width / ratioH, 55)];
}
else
{
[smallImage setSize: NSMakeSize(70, originalSize.height / ratioW)];
}
}
}
- (id) initWithData: (NSData *)aData withFileName: (NSString *)aName inWrapper: (BOOL)flag - (id) initWithData: (NSData *)aData withFileName: (NSString *)aName inWrapper: (BOOL)flag
{ {
if((self = [super initWithData: aData withFileName: aName inWrapper: flag])) if ((self = [super initWithData: aData withFileName: aName inWrapper: flag]) != nil)
{ {
NSSize originalSize; // FIXME: Why not make one a copy of the other?
float ratioH; image = [[NSImage alloc] initWithData: aData];
float ratioW; smallImage = [[NSImage alloc] initWithData: aData];
ASSIGN(image, AUTORELEASE([[NSImage alloc] initWithData: aData])); if (smallImage == nil)
ASSIGN(smallImage, AUTORELEASE([[NSImage alloc] initWithData: aData]));
[image setName: aName];
originalSize = [smallImage size];
ratioW = originalSize.width / 70;
ratioH = originalSize.height / 55;
if (ratioH > 1 || ratioW > 1)
{ {
[smallImage setScalesWhenResized: YES]; RELEASE(self);
if (ratioH > ratioW) return nil;
{
[smallImage setSize: NSMakeSize(originalSize.width / ratioH, 55)];
}
else
{
[smallImage setSize: NSMakeSize(70, originalSize.height / ratioW)];
}
} }
[image setName: aName];
// FIXME: Not needed
[image setArchiveByName: NO]; [image setArchiveByName: NO];
[smallImage setArchiveByName: NO]; [smallImage setArchiveByName: NO];
[self _resizeSmallImage];
} }
return self; return self;
} }
@ -95,15 +107,10 @@
path: (NSString *)aPath path: (NSString *)aPath
inWrapper: (BOOL)flag inWrapper: (BOOL)flag
{ {
if((self = [super initWithName: aName path: aPath inWrapper: flag])) if ((self = [super initWithName: aName path: aPath inWrapper: flag]) != nil)
{ {
NSSize originalSize; image = [[NSImage alloc] initByReferencingFile: aPath];
float ratioH; smallImage = [[NSImage alloc] initWithContentsOfFile: aPath];
float ratioW;
ASSIGN(image, AUTORELEASE([[NSImage alloc] initByReferencingFile: aPath]));
ASSIGN(smallImage, AUTORELEASE([[NSImage alloc] initWithContentsOfFile: aPath]));
[image setName: aName];
if (smallImage == nil) if (smallImage == nil)
{ {
@ -111,25 +118,10 @@
return nil; return nil;
} }
originalSize = [smallImage size]; [image setName: aName];
ratioW = originalSize.width / 70;
ratioH = originalSize.height / 55;
if (ratioH > 1 || ratioW > 1)
{
[smallImage setScalesWhenResized: YES];
if (ratioH > ratioW)
{
[smallImage setSize: NSMakeSize(originalSize.width / ratioH, 55)];
}
else
{
[smallImage setSize: NSMakeSize(70, originalSize.height / ratioW)];
}
}
[image setArchiveByName: NO]; [image setArchiveByName: NO];
[smallImage setArchiveByName: NO]; [smallImage setArchiveByName: NO];
[self _resizeSmallImage];
} }
return self; return self;