Revision: 13854
http://sourceforge.net/p/skim-app/code/13854
Author: hofman
Date: 2023-12-07 23:28:08 +0000 (Thu, 07 Dec 2023)
Log Message:
-----------
return early for some simple cases
Modified Paths:
--------------
trunk/SkimNotes/SKNUtilities.m
Modified: trunk/SkimNotes/SKNUtilities.m
===================================================================
--- trunk/SkimNotes/SKNUtilities.m 2023-12-07 23:19:48 UTC (rev 13853)
+++ trunk/SkimNotes/SKNUtilities.m 2023-12-07 23:28:08 UTC (rev 13854)
@@ -288,75 +288,72 @@
}
NSData *SKNDataFromSkimNotes(NSArray *noteDicts, BOOL asPlist) {
- NSData *data = nil;
- if (noteDicts) {
+ if (noteDicts == nil) {
+ return nil;
+ }
#if !defined(PDFKIT_PLATFORM_IOS)
- if (asPlist == NO) {
- data = [NSKeyedArchiver archivedDataWithRootObject:noteDicts];
- } else
+ if (asPlist == NO) {
+ return [NSKeyedArchiver archivedDataWithRootObject:noteDicts];
+ }
#endif
- {
- NSMutableArray *array = [[NSMutableArray alloc] init];
- NSMapTable *colors = [[NSMapTable alloc]
initWithKeyOptions:NSPointerFunctionsStrongMemory |
NSPointerFunctionsObjectPersonality valueOptions:NSPointerFunctionsStrongMemory
| NSPointerFunctionsObjectPersonality capacity:0];
- for (NSDictionary *noteDict in noteDicts) {
- NSMutableDictionary *dict = [noteDict mutableCopy];
- id value;
- if ((value = [dict objectForKey:NOTE_COLOR_KEY])) {
- value = SKNArrayFromColor(value, colors);
- [dict setValue:value forKey:NOTE_COLOR_KEY];
- }
- if ((value = [dict objectForKey:NOTE_INTERIOR_COLOR_KEY])) {
- value = SKNArrayFromColor(value, colors);
- [dict setValue:value forKey:NOTE_INTERIOR_COLOR_KEY];
- }
- if ((value = [dict objectForKey:NOTE_FONT_COLOR_KEY])) {
- value = SKNArrayFromColor(value, colors);
- [dict setValue:value forKey:NOTE_FONT_COLOR_KEY];
- }
- if ((value = [dict objectForKey:NOTE_FONT_KEY])) {
- if ([value isKindOfClass:[SKNFont class]]) {
- [dict setObject:[value fontName]
forKey:NOTE_FONT_NAME_KEY];
- [dict setObject:[NSNumber numberWithDouble:[value
pointSize]] forKey:NOTE_FONT_SIZE_KEY];
- }
- [dict removeObjectForKey:NOTE_FONT_KEY];
- }
- if ((value = [dict objectForKey:NOTE_TEXT_KEY])) {
- if ([value isKindOfClass:[NSAttributedString class]]) {
+ NSMutableArray *array = [[NSMutableArray alloc] init];
+ NSMapTable *colors = [[NSMapTable alloc]
initWithKeyOptions:NSPointerFunctionsStrongMemory |
NSPointerFunctionsObjectPersonality valueOptions:NSPointerFunctionsStrongMemory
| NSPointerFunctionsObjectPersonality capacity:0];
+ for (NSDictionary *noteDict in noteDicts) {
+ NSMutableDictionary *dict = [noteDict mutableCopy];
+ id value;
+ if ((value = [dict objectForKey:NOTE_COLOR_KEY])) {
+ value = SKNArrayFromColor(value, colors);
+ [dict setValue:value forKey:NOTE_COLOR_KEY];
+ }
+ if ((value = [dict objectForKey:NOTE_INTERIOR_COLOR_KEY])) {
+ value = SKNArrayFromColor(value, colors);
+ [dict setValue:value forKey:NOTE_INTERIOR_COLOR_KEY];
+ }
+ if ((value = [dict objectForKey:NOTE_FONT_COLOR_KEY])) {
+ value = SKNArrayFromColor(value, colors);
+ [dict setValue:value forKey:NOTE_FONT_COLOR_KEY];
+ }
+ if ((value = [dict objectForKey:NOTE_FONT_KEY])) {
+ if ([value isKindOfClass:[SKNFont class]]) {
+ [dict setObject:[value fontName] forKey:NOTE_FONT_NAME_KEY];
+ [dict setObject:[NSNumber numberWithDouble:[value pointSize]]
forKey:NOTE_FONT_SIZE_KEY];
+ }
+ [dict removeObjectForKey:NOTE_FONT_KEY];
+ }
+ if ((value = [dict objectForKey:NOTE_TEXT_KEY])) {
+ if ([value isKindOfClass:[NSAttributedString class]]) {
#if !defined(PDFKIT_PLATFORM_IOS) && (!defined(MAC_OS_X_VERSION_10_11) ||
MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_11)
- if ([value containsAttachments]) {
+ if ([value containsAttachments]) {
#else
- if ([value containsAttachmentsInRange:NSMakeRange(0,
[value length])]) {
+ if ([value containsAttachmentsInRange:NSMakeRange(0, [value
length])]) {
#endif
- value = [value dataFromRange:NSMakeRange(0, [value
length]) documentAttributes:[NSDictionary
dictionaryWithObjectsAndKeys:NSRTFDTextDocumentType,
NSDocumentTypeDocumentAttribute, nil] error:NULL];
- } else {
- value = [value dataFromRange:NSMakeRange(0, [value
length]) documentAttributes:[NSDictionary
dictionaryWithObjectsAndKeys:NSRTFTextDocumentType,
NSDocumentTypeDocumentAttribute, nil] error:NULL];
- }
- [dict setObject:value forKey:NOTE_TEXT_KEY];
- } else if ([value isKindOfClass:[NSData class]] == NO) {
- [dict removeObjectForKey:NOTE_TEXT_KEY];
- }
+ value = [value dataFromRange:NSMakeRange(0, [value
length]) documentAttributes:[NSDictionary
dictionaryWithObjectsAndKeys:NSRTFDTextDocumentType,
NSDocumentTypeDocumentAttribute, nil] error:NULL];
+ } else {
+ value = [value dataFromRange:NSMakeRange(0, [value
length]) documentAttributes:[NSDictionary
dictionaryWithObjectsAndKeys:NSRTFTextDocumentType,
NSDocumentTypeDocumentAttribute, nil] error:NULL];
}
- if ((value = [dict objectForKey:NOTE_IMAGE_KEY])) {
- if ([value isKindOfClass:[SKNImage class]]) {
+ [dict setObject:value forKey:NOTE_TEXT_KEY];
+ } else if ([value isKindOfClass:[NSData class]] == NO) {
+ [dict removeObjectForKey:NOTE_TEXT_KEY];
+ }
+ }
+ if ((value = [dict objectForKey:NOTE_IMAGE_KEY])) {
+ if ([value isKindOfClass:[SKNImage class]]) {
#if defined(SKIMNOTES_PLATFORM_IOS)
- value = UIImagePNGRepresentation(value);
+ value = UIImagePNGRepresentation(value);
#else
- id imageRep = [[value representations] count] == 1 ?
[[value representations] objectAtIndex:0] : nil;
- if ([imageRep isKindOfClass:[NSPDFImageRep class]]) {
- value = [imageRep PDFRepresentation];
- } else {
- value = [value TIFFRepresentation];
- }
+ id imageRep = [[value representations] count] == 1 ? [[value
representations] objectAtIndex:0] : nil;
+ if ([imageRep isKindOfClass:[NSPDFImageRep class]]) {
+ value = [imageRep PDFRepresentation];
+ } else {
+ value = [value TIFFRepresentation];
+ }
#endif
- [dict setObject:value forKey:NOTE_IMAGE_KEY];
- } else if ([value isKindOfClass:[NSData class]] == NO) {
- [dict removeObjectForKey:NOTE_IMAGE_KEY];
- }
- }
- [array addObject:dict];
+ [dict setObject:value forKey:NOTE_IMAGE_KEY];
+ } else if ([value isKindOfClass:[NSData class]] == NO) {
+ [dict removeObjectForKey:NOTE_IMAGE_KEY];
}
- data = [NSPropertyListSerialization dataWithPropertyList:array
format:NSPropertyListBinaryFormat_v1_0 options:0 error:NULL];
}
+ [array addObject:dict];
}
- return data;
+ return [NSPropertyListSerialization dataWithPropertyList:array
format:NSPropertyListBinaryFormat_v1_0 options:0 error:NULL];
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit