Revision: 14592
          http://sourceforge.net/p/skim-app/code/14592
Author:   hofman
Date:     2024-10-27 15:41:35 +0000 (Sun, 27 Oct 2024)
Log Message:
-----------
combine note dictionary conversion methods

Modified Paths:
--------------
    trunk/PDFAnnotation_SKExtensions.h
    trunk/PDFAnnotation_SKExtensions.m
    trunk/SKFDFParser.m
    trunk/SKMainDocument.m

Modified: trunk/PDFAnnotation_SKExtensions.h
===================================================================
--- trunk/PDFAnnotation_SKExtensions.h  2024-10-27 15:24:51 UTC (rev 14591)
+++ trunk/PDFAnnotation_SKExtensions.h  2024-10-27 15:41:35 UTC (rev 14592)
@@ -67,8 +67,7 @@
 
 + (nullable NSArray<NSArray *> *)SkimNotesAndPagesWithSelection:(PDFSelection 
*)selection forType:(NSString *)type;
 
-+ (NSDictionary<NSString *, id> 
*)textToNoteSkimNoteProperties:(NSDictionary<NSString *, id> *)properties;
-+ (NSDictionary<NSString *, id> 
*)stampToNoteSkimNoteProperties:(NSDictionary<NSString *, id> *)properties;
++ (NSDictionary<NSString *, id> 
*)normalizedSkimNoteProperties:(NSDictionary<NSString *, id> *)properties;
 
 @property (nonatomic, nullable, readonly) NSString *fdfString;
 

Modified: trunk/PDFAnnotation_SKExtensions.m
===================================================================
--- trunk/PDFAnnotation_SKExtensions.m  2024-10-27 15:24:51 UTC (rev 14591)
+++ trunk/PDFAnnotation_SKExtensions.m  2024-10-27 15:41:35 UTC (rev 14592)
@@ -193,55 +193,39 @@
     return annotation;
 }
 
-+ (NSDictionary *)textToNoteSkimNoteProperties:(NSDictionary *)properties {
-    if ([[properties objectForKey:SKNPDFAnnotationTypeKey] 
isEqualToString:SKNTextString]) {
-        NSMutableDictionary *mutableProperties = [properties mutableCopy];
++ (NSDictionary *)normalizedSkimNoteProperties:(NSDictionary *)properties {
+    NSString *type = [properties objectForKey:SKNPDFAnnotationTypeKey];
+    if ([type isEqualToString:SKNTextString] == NO && [type 
isEqualToString:SKNStampString] == NO)
+        return properties;
+    NSMutableDictionary *mutableProperties = [properties mutableCopy];
+    [mutableProperties setObject:SKNNoteString forKey:SKNPDFAnnotationTypeKey];
+    NSString *contents = [properties objectForKey:SKNPDFAnnotationContentsKey];
+    if (contents) {
+        NSRange r = [contents rangeOfString:@"  "];
+        NSRange r1 = [contents rangeOfString:@"\n"];
+        if (r1.location < r.location)
+            r = r1;
+        if (NSMaxRange(r) < [contents length]) {
+            NSFont *font = [[NSUserDefaults standardUserDefaults] 
fontForNameKey:SKAnchoredNoteFontNameKey sizeKey:SKAnchoredNoteFontSizeKey];
+            NSAttributedString *attrString = [[NSAttributedString alloc] 
initWithString:[contents substringFromIndex:NSMaxRange(r)]
+                                                attributes:[NSDictionary 
dictionaryWithObjectsAndKeys:font, NSFontAttributeName, nil]];
+            [mutableProperties setObject:attrString 
forKey:SKNPDFAnnotationTextKey];
+            [mutableProperties setObject:[contents 
substringToIndex:r.location] forKey:SKNPDFAnnotationContentsKey];
+        }
+    }
+    if ([type isEqualToString:SKNTextString]) {
         NSRect bounds = NSRectFromString([properties 
objectForKey:SKNPDFAnnotationBoundsKey]);
-        NSString *contents = [properties 
objectForKey:SKNPDFAnnotationContentsKey];
-        [mutableProperties setObject:SKNNoteString 
forKey:SKNPDFAnnotationTypeKey];
-        bounds.origin.y = NSMaxY(bounds) - SKNPDFAnnotationNoteSize.height;
-        bounds.size = SKNPDFAnnotationNoteSize;
-        [mutableProperties setObject:NSStringFromRect(bounds) 
forKey:SKNPDFAnnotationBoundsKey];
-        if (contents) {
-            NSRange r = [contents rangeOfString:@"  "];
-            NSRange r1 = [contents rangeOfString:@"\n"];
-            if (r1.location < r.location)
-                r = r1;
-            if (NSMaxRange(r) < [contents length]) {
-                NSFont *font = [[NSUserDefaults standardUserDefaults] 
fontForNameKey:SKAnchoredNoteFontNameKey sizeKey:SKAnchoredNoteFontSizeKey];
-                NSAttributedString *attrString = [[NSAttributedString alloc] 
initWithString:[contents substringFromIndex:NSMaxRange(r)]
-                                                    attributes:[NSDictionary 
dictionaryWithObjectsAndKeys:font, NSFontAttributeName, nil]];
-                [mutableProperties setObject:attrString 
forKey:SKNPDFAnnotationTextKey];
-                [mutableProperties setObject:[contents 
substringToIndex:r.location] forKey:SKNPDFAnnotationContentsKey];
-            }
+        if (NSEqualSizes(bounds.size, SKNPDFAnnotationNoteSize) == NO) {
+            bounds.origin.y = NSMaxY(bounds) - SKNPDFAnnotationNoteSize.height;
+            bounds.size = SKNPDFAnnotationNoteSize;
+            bounds.origin.y = NSMaxY(bounds) - SKNPDFAnnotationNoteSize.height;
+            bounds.size = SKNPDFAnnotationNoteSize;
+            [mutableProperties setObject:NSStringFromRect(bounds) 
forKey:SKNPDFAnnotationBoundsKey];
         }
-        return mutableProperties;
-    }
-    return properties;
-}
-
-+ (NSDictionary *)stampToNoteSkimNoteProperties:(NSDictionary *)properties {
-    if ([[properties objectForKey:SKNPDFAnnotationTypeKey] 
isEqualToString:SKNStampString]) {
-        NSMutableDictionary *mutableProperties = [properties mutableCopy];
-        NSString *contents = [properties 
objectForKey:SKNPDFAnnotationContentsKey];
-        [mutableProperties setObject:SKNNoteString 
forKey:SKNPDFAnnotationTypeKey];
+    } else if ([type isEqualToString:SKNStampString]) {
         [mutableProperties setObject:@YES 
forKey:SKNPDFAnnotationDrawsImageKey];
-        if (contents) {
-            NSRange r = [contents rangeOfString:@"  "];
-            NSRange r1 = [contents rangeOfString:@"\n"];
-            if (r1.location < r.location)
-                r = r1;
-            if (NSMaxRange(r) < [contents length]) {
-                NSFont *font = [[NSUserDefaults standardUserDefaults] 
fontForNameKey:SKAnchoredNoteFontNameKey sizeKey:SKAnchoredNoteFontSizeKey];
-                NSAttributedString *attrString = [[NSAttributedString alloc] 
initWithString:[contents substringFromIndex:NSMaxRange(r)]
-                                                    attributes:[NSDictionary 
dictionaryWithObjectsAndKeys:font, NSFontAttributeName, nil]];
-                [mutableProperties setObject:attrString 
forKey:SKNPDFAnnotationTextKey];
-                [mutableProperties setObject:[contents 
substringToIndex:r.location] forKey:SKNPDFAnnotationContentsKey];
-            }
-        }
-        return mutableProperties;
     }
-    return properties;
+    return mutableProperties;
 }
 
 - (NSString *)fdfString {

Modified: trunk/SKFDFParser.m
===================================================================
--- trunk/SKFDFParser.m 2024-10-27 15:24:51 UTC (rev 14591)
+++ trunk/SKFDFParser.m 2024-10-27 15:41:35 UTC (rev 14592)
@@ -254,13 +254,10 @@
     if (success) {
         NSSet *validTypes = [NSSet setWithObjects:SKNFreeTextString, 
SKNNoteString, SKNCircleString, SKNSquareString, SKNHighlightString, 
SKNUnderlineString, SKNStrikeOutString, SKNLineString, SKNInkString, nil];
         NSString *type = [dictionary objectForKey:SKNPDFAnnotationTypeKey];
-        if ([type isEqualToString:SKNTextString]) {
-            [dictionary setDictionary:[PDFAnnotation 
textToNoteSkimNoteProperties:dictionary]];
-        } else if ([type isEqualToString:SKNStampString]) {
-            [dictionary setDictionary:[PDFAnnotation 
stampToNoteSkimNoteProperties:dictionary]];
-        } else if ([validTypes containsObject:type] == NO) {
+        if ([type isEqualToString:SKNTextString] || [type 
isEqualToString:SKNStampString])
+            [dictionary setDictionary:[PDFAnnotation 
normalizedSkimNoteProperties:dictionary]];
+        else if ([validTypes containsObject:type] == NO)
             success = NO;
-        }
     }
     
     if (success && CGPDFDictionaryGetInteger(annot, 
SKFDFAnnotationPageIndexKey, &integer)) {

Modified: trunk/SKMainDocument.m
===================================================================
--- trunk/SKMainDocument.m      2024-10-27 15:24:51 UTC (rev 14591)
+++ trunk/SKMainDocument.m      2024-10-27 15:41:35 UTC (rev 14592)
@@ -1127,11 +1127,7 @@
                 if (annotations == nil)
                     annotations = [[NSMutableArray alloc] init];
                 [annotations addObject:annotation];
-                NSDictionary *properties = [annotation SkimNoteProperties];
-                if ([[annotation type] isEqualToString:SKNTextString])
-                    properties = [PDFAnnotation 
textToNoteSkimNoteProperties:properties];
-                else if ([[annotation type] isEqualToString:SKNStampString])
-                    properties = [PDFAnnotation 
stampToNoteSkimNoteProperties:properties];
+                NSDictionary *properties = [PDFAnnotation 
normalizedSkimNoteProperties:[annotation SkimNoteProperties]];
                 if (noteDicts == nil)
                     noteDicts = [[NSMutableArray alloc] init];
                 [noteDicts addObject:properties];

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

Reply via email to