Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: third_party/icon_family/IconFamily.m

Issue 9385035: Minor fixes to IconFamily library (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed review comments Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // IconFamily.m 1 // IconFamily.m
2 // IconFamily class implementation 2 // IconFamily class implementation
3 // by Troy Stephens, Thomas Schnitzer, David Remahl, Nathan Day, Ben Haller, Sve n Janssen, Peter Hosey, Conor Dearden, Elliot Glaysher, and Dave MacLachlan 3 // by Troy Stephens, Thomas Schnitzer, David Remahl, Nathan Day, Ben Haller, Sve n Janssen, Peter Hosey, Conor Dearden, Elliot Glaysher, and Dave MacLachlan
4 // version 0.9.4 4 // version 0.9.4
5 // 5 //
6 // Project Home Page: 6 // Project Home Page:
7 // http://iconfamily.sourceforge.net/ 7 // http://iconfamily.sourceforge.net/
8 // 8 //
9 // Problems, shortcomings, and uncertainties that I'm aware of are flagged with "NOTE:". Please address bug reports, bug fixes, suggestions, etc. to the projec t Forums and bug tracker at https://sourceforge.net/projects/iconfamily/ 9 // Problems, shortcomings, and uncertainties that I'm aware of are flagged with "NOTE:". Please address bug reports, bug fixes, suggestions, etc. to the projec t Forums and bug tracker at https://sourceforge.net/projects/iconfamily/
10 10
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 + (NSImage*) resampleImage:(NSImage*)image toIconWidth:(int)width usingImageInte rpolation:(NSImageInterpolation)imageInterpolation; 84 + (NSImage*) resampleImage:(NSImage*)image toIconWidth:(int)width usingImageInte rpolation:(NSImageInterpolation)imageInterpolation;
85 85
86 + (Handle) get32BitDataFromBitmapImageRep:(NSBitmapImageRep*)bitmapImageRep requ iredPixelSize:(int)requiredPixelSize; 86 + (Handle) get32BitDataFromBitmapImageRep:(NSBitmapImageRep*)bitmapImageRep requ iredPixelSize:(int)requiredPixelSize;
87 87
88 + (Handle) get8BitDataFromBitmapImageRep:(NSBitmapImageRep*)bitmapImageRep requi redPixelSize:(int)requiredPixelSize; 88 + (Handle) get8BitDataFromBitmapImageRep:(NSBitmapImageRep*)bitmapImageRep requi redPixelSize:(int)requiredPixelSize;
89 89
90 + (Handle) get8BitMaskFromBitmapImageRep:(NSBitmapImageRep*)bitmapImageRep requi redPixelSize:(int)requiredPixelSize; 90 + (Handle) get8BitMaskFromBitmapImageRep:(NSBitmapImageRep*)bitmapImageRep requi redPixelSize:(int)requiredPixelSize;
91 91
92 + (Handle) get1BitMaskFromBitmapImageRep:(NSBitmapImageRep*)bitmapImageRep requi redPixelSize:(int)requiredPixelSize; 92 + (Handle) get1BitMaskFromBitmapImageRep:(NSBitmapImageRep*)bitmapImageRep requi redPixelSize:(int)requiredPixelSize;
93 93
94 #if !defined(DISABLE_CUSTOM_ICON)
94 - (BOOL) addResourceType:(OSType)type asResID:(int)resID; 95 - (BOOL) addResourceType:(OSType)type asResID:(int)resID;
96 #endif
95 97
96 @end 98 @end
97 99
98 @implementation IconFamily 100 @implementation IconFamily
99 101
100 + (IconFamily*) iconFamily 102 + (IconFamily*) iconFamily
101 { 103 {
102 return [[[IconFamily alloc] init] autorelease]; 104 return [[[IconFamily alloc] init] autorelease];
103 } 105 }
104 106
(...skipping 23 matching lines...) Expand all
128 } 130 }
129 131
130 + (IconFamily*) iconFamilyWithThumbnailsOfImage:(NSImage*)image usingImageInterp olation:(NSImageInterpolation)imageInterpolation 132 + (IconFamily*) iconFamilyWithThumbnailsOfImage:(NSImage*)image usingImageInterp olation:(NSImageInterpolation)imageInterpolation
131 { 133 {
132 return [[[IconFamily alloc] initWithThumbnailsOfImage:image usingImageInterp olation:imageInterpolation] autorelease]; 134 return [[[IconFamily alloc] initWithThumbnailsOfImage:image usingImageInterp olation:imageInterpolation] autorelease];
133 } 135 }
134 136
135 // This is IconFamily's designated initializer. It creates a new IconFamily tha t initially has no elements. 137 // This is IconFamily's designated initializer. It creates a new IconFamily tha t initially has no elements.
136 // 138 //
137 // The proper way to do this is to simply allocate a zero-sized handle (not to b e confused with an empty handle) and assign it to hIconFamily. This technique w orks on Mac OS X 10.2 as well as on 10.0.x and 10.1.x. Our previous technique o f allocating an IconFamily struct with a resourceSize of 0 no longer works as of Mac OS X 10.2. 139 // The proper way to do this is to simply allocate a zero-sized handle (not to b e confused with an empty handle) and assign it to hIconFamily. This technique w orks on Mac OS X 10.2 as well as on 10.0.x and 10.1.x. Our previous technique o f allocating an IconFamily struct with a resourceSize of 0 no longer works as of Mac OS X 10.2.
138 - init 140 - (id) init
139 { 141 {
140 self = [super init]; 142 self = [super init];
141 if (self) { 143 if (self) {
142 hIconFamily = (IconFamilyHandle) NewHandle( 0 ); 144 hIconFamily = (IconFamilyHandle) NewHandle( 0 );
143 if (hIconFamily == NULL) { 145 if (hIconFamily == NULL) {
144 [self autorelease]; 146 [self autorelease];
145 return nil; 147 return nil;
146 } 148 }
147 } 149 }
148 return self; 150 return self;
149 } 151 }
150 152
151 - initWithData:(NSData *)data 153 - (id) initWithData:(NSData *)data
152 { 154 {
153 self = [self init]; 155 self = [self init];
154 if (self) { 156 if (self) {
155 Handle storageMem = NULL; 157 Handle storageMem = NULL;
156 158
157 OSStatus err = PtrToHand([data bytes], &storageMem, (long)[data length]) ; 159 OSStatus err = PtrToHand([data bytes], &storageMem, (long)[data length]) ;
158 if( err != noErr ) 160 if( err != noErr )
159 { 161 {
160 [self release]; 162 [self release];
161 return nil; 163 return nil;
162 } 164 }
163 165
164 hIconFamily = (IconFamilyHandle)storageMem; 166 hIconFamily = (IconFamilyHandle)storageMem;
165 } 167 }
166 return self; 168 return self;
167 } 169 }
168 170
169 - initWithContentsOfFile:(NSString*)path 171 - (id) initWithContentsOfFile:(NSString*)path
170 { 172 {
171 FSRef ref; 173 FSRef ref;
172 OSStatus result; 174 OSStatus result;
173 175
174 self = [self init]; 176 self = [self init];
175 if (self) { 177 if (self) {
176 if (hIconFamily) { 178 if (hIconFamily) {
177 DisposeHandle( (Handle)hIconFamily ); 179 DisposeHandle( (Handle)hIconFamily );
178 hIconFamily = NULL; 180 hIconFamily = NULL;
179 } 181 }
180 if (![path getFSRef:&ref createFileIfNecessary:NO]) { 182 if (![path getFSRef:&ref createFileIfNecessary:NO]) {
181 [self autorelease]; 183 [self autorelease];
182 return nil; 184 return nil;
183 } 185 }
184 result = ReadIconFromFSRef( &ref, &hIconFamily ); 186 result = ReadIconFromFSRef( &ref, &hIconFamily );
185 if (result != noErr) { 187 if (result != noErr) {
186 [self autorelease]; 188 [self autorelease];
187 return nil; 189 return nil;
188 } 190 }
189 } 191 }
190 return self; 192 return self;
191 } 193 }
192 194
193 - initWithIconFamilyHandle:(IconFamilyHandle)hNewIconFamily 195 - (id) initWithIconFamilyHandle:(IconFamilyHandle)hNewIconFamily
194 { 196 {
195 self = [self init]; 197 self = [self init];
196 if (self) { 198 if (self) {
197 if (hIconFamily) { 199 if (hIconFamily) {
198 DisposeHandle( (Handle)hIconFamily ); 200 DisposeHandle( (Handle)hIconFamily );
199 hIconFamily = NULL; 201 hIconFamily = NULL;
200 } 202 }
201 hIconFamily = hNewIconFamily; 203 hIconFamily = hNewIconFamily;
202 } 204 }
203 return self; 205 return self;
204 } 206 }
205 207
206 - initWithIconOfFile:(NSString*)path 208 - (id) initWithIconOfFile:(NSString*)path
207 { 209 {
208 IconRef iconRef; 210 IconRef iconRef;
209 OSStatus result; 211 OSStatus result;
210 SInt16 label; 212 SInt16 label;
211 FSRef ref; 213 FSRef ref;
212 214
213 self = [self init]; 215 self = [self init];
214 if (self) 216 if (self)
215 { 217 {
216 if (hIconFamily) 218 if (hIconFamily)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 252
251 if (result != noErr || !hIconFamily) 253 if (result != noErr || !hIconFamily)
252 { 254 {
253 [self autorelease]; 255 [self autorelease];
254 return nil; 256 return nil;
255 } 257 }
256 } 258 }
257 return self; 259 return self;
258 } 260 }
259 261
260 - initWithSystemIcon:(int)fourByteCode 262 - (id) initWithSystemIcon:(int)fourByteCode
261 { 263 {
262 IconRef iconRef; 264 IconRef iconRef;
263 OSErr result; 265 OSErr result;
264 266
265 self = [self init]; 267 self = [self init];
266 if (self) 268 if (self)
267 { 269 {
268 if (hIconFamily) 270 if (hIconFamily)
269 { 271 {
270 DisposeHandle( (Handle)hIconFamily ); 272 DisposeHandle( (Handle)hIconFamily );
(...skipping 17 matching lines...) Expand all
288 { 290 {
289 [self autorelease]; 291 [self autorelease];
290 return nil; 292 return nil;
291 } 293 }
292 294
293 ReleaseIconRef( iconRef ); 295 ReleaseIconRef( iconRef );
294 } 296 }
295 return self; 297 return self;
296 } 298 }
297 299
298 - initWithThumbnailsOfImage:(NSImage*)image 300 - (id) initWithThumbnailsOfImage:(NSImage*)image
299 { 301 {
300 // The default is to use a high degree of antialiasing, producing a smooth i mage. 302 // The default is to use a high degree of antialiasing, producing a smooth i mage.
301 return [self initWithThumbnailsOfImage:image usingImageInterpolation:NSImage InterpolationHigh]; 303 return [self initWithThumbnailsOfImage:image usingImageInterpolation:NSImage InterpolationHigh];
302 } 304 }
303 305
304 - initWithThumbnailsOfImage:(NSImage*)image usingImageInterpolation:(NSImageInte rpolation)imageInterpolation 306 - (id) initWithThumbnailsOfImage:(NSImage*)image usingImageInterpolation:(NSImag eInterpolation)imageInterpolation
305 { 307 {
306 NSImage* iconImage512x512; 308 NSImage* iconImage512x512;
307 NSImage* iconImage256x256; 309 NSImage* iconImage256x256;
308 NSImage* iconImage128x128; 310 NSImage* iconImage128x128;
309 NSImage* iconImage32x32; 311 NSImage* iconImage32x32;
310 NSImage* iconImage16x16; 312 NSImage* iconImage16x16;
311 NSImage* bitmappedIconImage512x512; 313 NSImage* bitmappedIconImage512x512;
312 NSBitmapImageRep* iconBitmap512x512; 314 NSBitmapImageRep* iconBitmap512x512;
313 NSBitmapImageRep* iconBitmap256x256; 315 NSBitmapImageRep* iconBitmap256x256;
314 NSBitmapImageRep* iconBitmap128x128; 316 NSBitmapImageRep* iconBitmap128x128;
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 719
718 if (result != noErr) 720 if (result != noErr)
719 { 721 {
720 NSLog(@"SetIconFamilyData() returned error %d", result); 722 NSLog(@"SetIconFamilyData() returned error %d", result);
721 return NO; 723 return NO;
722 } 724 }
723 725
724 return YES; 726 return YES;
725 } 727 }
726 728
729 #if !defined(DISABLE_CUSTOM_ICON)
730
727 - (BOOL) setAsCustomIconForFile:(NSString*)path 731 - (BOOL) setAsCustomIconForFile:(NSString*)path
728 { 732 {
729 return( [self setAsCustomIconForFile:path withCompatibility:NO] ); 733 return( [self setAsCustomIconForFile:path withCompatibility:NO] );
730 } 734 }
731 735
732 - (BOOL) setAsCustomIconForFile:(NSString*)path withCompatibility:(BOOL)compat 736 - (BOOL) setAsCustomIconForFile:(NSString*)path withCompatibility:(BOOL)compat
733 { 737 {
734 FSRef targetFileFSRef; 738 FSRef targetFileFSRef;
735 FSRef parentDirectoryFSRef; 739 FSRef parentDirectoryFSRef;
736 SInt16 file; 740 SInt16 file;
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
1132 if (result != noErr) 1136 if (result != noErr)
1133 return NO; 1137 return NO;
1134 } 1138 }
1135 1139
1136 if( ! [[NSFileManager defaultManager] iconfamily_removeItemAtPath:[path stri ngByAppendingPathComponent:@"Icon\r"]] ) 1140 if( ! [[NSFileManager defaultManager] iconfamily_removeItemAtPath:[path stri ngByAppendingPathComponent:@"Icon\r"]] )
1137 return NO; 1141 return NO;
1138 1142
1139 return YES; 1143 return YES;
1140 } 1144 }
1141 1145
1146 #endif // !defined(DISABLE_CUSTOM_ICON)
1147
1142 - (NSData *) data 1148 - (NSData *) data
1143 { 1149 {
1144 return [NSData dataWithBytes:*hIconFamily length:GetHandleSize((Handle)hIcon Family)]; 1150 return [NSData dataWithBytes:*hIconFamily length:GetHandleSize((Handle)hIcon Family)];
1145 } 1151 }
1146 1152
1147 - (BOOL) writeToFile:(NSString*)path 1153 - (BOOL) writeToFile:(NSString*)path
1148 { 1154 {
1149 return [[self data] writeToFile:path atomically:NO]; 1155 return [[self data] writeToFile:path atomically:NO];
1150 } 1156 }
1151 1157
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
1582 } 1588 }
1583 else 1589 else
1584 { 1590 {
1585 NSLog(@"get1BitMaskFromBitmapImageRep:requiredPixelSize: returni ng NULL due to bitsPerPixel == %ld, samplesPerPixel== %ld, bitsPerSample == %ld" , bitsPerPixel, samplesPerPixel, bitsPerSample); 1591 NSLog(@"get1BitMaskFromBitmapImageRep:requiredPixelSize: returni ng NULL due to bitsPerPixel == %ld, samplesPerPixel== %ld, bitsPerSample == %ld" , bitsPerPixel, samplesPerPixel, bitsPerSample);
1586 return NULL; 1592 return NULL;
1587 } 1593 }
1588 1594
1589 return hRawData; 1595 return hRawData;
1590 } 1596 }
1591 1597
1598 #if !defined(DISABLE_CUSTOM_ICON)
1599
1592 - (BOOL) addResourceType:(OSType)type asResID:(int)resID 1600 - (BOOL) addResourceType:(OSType)type asResID:(int)resID
1593 { 1601 {
1594 Handle hIconRes = NewHandle(0); 1602 Handle hIconRes = NewHandle(0);
1595 OSErr err; 1603 OSErr err;
1596 1604
1597 err = GetIconFamilyData( hIconFamily, type, hIconRes ); 1605 err = GetIconFamilyData( hIconFamily, type, hIconRes );
1598 1606
1599 if( !GetHandleSize(hIconRes) || err != noErr ) 1607 if( !GetHandleSize(hIconRes) || err != noErr )
1600 return NO; 1608 return NO;
1601 1609
1602 AddResource( hIconRes, type, resID, "\p" ); 1610 AddResource( hIconRes, type, resID, "\p" );
1603 1611
1604 return YES; 1612 return YES;
1605 } 1613 }
1606 1614
1615 #endif // !defined(DISABLE_CUSTOM_ICON)
1616
1607 @end 1617 @end
1608 1618
1609 // Methods for interfacing with the Cocoa Pasteboard. 1619 // Methods for interfacing with the Cocoa Pasteboard.
1610 1620
1611 @implementation IconFamily (ScrapAdditions) 1621 @implementation IconFamily (ScrapAdditions)
1612 1622
1613 + (BOOL) canInitWithScrap 1623 + (BOOL) canInitWithScrap
1614 { 1624 {
1615 NSArray *types = [[NSPasteboard generalPasteboard] types]; 1625 NSArray *types = [[NSPasteboard generalPasteboard] types];
1616 return [types containsObject:ICONFAMILY_UTI] || [types containsObject:ICONFA MILY_PBOARD_TYPE]; 1626 return [types containsObject:ICONFAMILY_UTI] || [types containsObject:ICONFA MILY_PBOARD_TYPE];
1617 } 1627 }
1618 1628
1619 + (IconFamily*) iconFamilyWithScrap 1629 + (IconFamily*) iconFamilyWithScrap
1620 { 1630 {
1621 return [[[IconFamily alloc] initWithScrap] autorelease]; 1631 return [[[IconFamily alloc] initWithScrap] autorelease];
1622 } 1632 }
1623 1633
1624 - initWithScrap 1634 - (id) initWithScrap
1625 { 1635 {
1626 NSPasteboard *pboard = [NSPasteboard generalPasteboard]; 1636 NSPasteboard *pboard = [NSPasteboard generalPasteboard];
1627 1637
1628 NSData *data = [pboard dataForType:ICONFAMILY_UTI]; 1638 NSData *data = [pboard dataForType:ICONFAMILY_UTI];
1629 if( !data ) 1639 if( !data )
1630 data = [pboard dataForType:ICONFAMILY_PBOARD_TYPE]; 1640 data = [pboard dataForType:ICONFAMILY_PBOARD_TYPE];
1631 if( !data ) 1641 if( !data )
1632 { 1642 {
1633 [self release]; 1643 [self release];
1634 return nil; 1644 return nil;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1695 } 1705 }
1696 1706
1697 @end 1707 @end
1698 1708
1699 1709
1700 @implementation NSImage (IconFamilyCompatibility) 1710 @implementation NSImage (IconFamilyCompatibility)
1701 1711
1702 - (NSImageRep *) iconfamily_bestRepresentation 1712 - (NSImageRep *) iconfamily_bestRepresentation
1703 { 1713 {
1704 #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 1714 #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
1705 » if ([!self respondsToSelector:@selector(bestRepresentationForRect:contex t:hints:)]) 1715 » if (![self respondsToSelector:@selector(bestRepresentationForRect:contex t:hints:)])
1706 { 1716 {
1707 return [self bestRepresentationForDevice:nil]; 1717 return [self bestRepresentationForDevice:nil];
1708 } 1718 }
1709 #endif 1719 #endif
1710 1720
1711 return [self bestRepresentationForRect:(NSRect){NSZeroPoint, [self size] } context:nil hints:nil]; 1721 return [self bestRepresentationForRect:(NSRect){NSZeroPoint, [self size] } context:nil hints:nil];
1712 } 1722 }
1713 1723
1714 @end 1724 @end
OLDNEW
« no previous file with comments | « third_party/icon_family/IconFamily.h ('k') | third_party/icon_family/NSString+CarbonFSRefCreation.m » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698