Revision: 14618
          http://sourceforge.net/p/skim-app/code/14618
Author:   hofman
Date:     2024-10-31 15:03:53 +0000 (Thu, 31 Oct 2024)
Log Message:
-----------
Set stamp name in skim note dictionary so it can be restored when not an icon 
type name

Modified Paths:
--------------
    trunk/SkimNotes/PDFAnnotation_SKNExtensions.h
    trunk/SkimNotes/PDFAnnotation_SKNExtensions.m
    trunk/SkimNotes/SKNPDFAnnotationNote.m

Modified: trunk/SkimNotes/PDFAnnotation_SKNExtensions.h
===================================================================
--- trunk/SkimNotes/PDFAnnotation_SKNExtensions.h       2024-10-30 23:32:03 UTC 
(rev 14617)
+++ trunk/SkimNotes/PDFAnnotation_SKNExtensions.h       2024-10-31 15:03:53 UTC 
(rev 14618)
@@ -217,6 +217,11 @@
 extern NSString *SKNPDFAnnotationIconTypeKey;
 
 /*!
+    @discussion  Global string for annotation icon or stamp name key.
+*/
+extern NSString *SKNPDFAnnotationNameKey;
+
+/*!
     @discussion  Global string for annotation point lists key.
 */
 extern NSString *SKNPDFAnnotationPointListsKey;

Modified: trunk/SkimNotes/PDFAnnotation_SKNExtensions.m
===================================================================
--- trunk/SkimNotes/PDFAnnotation_SKNExtensions.m       2024-10-30 23:32:03 UTC 
(rev 14617)
+++ trunk/SkimNotes/PDFAnnotation_SKNExtensions.m       2024-10-31 15:03:53 UTC 
(rev 14618)
@@ -124,6 +124,8 @@
 
 NSString *SKNPDFAnnotationIconTypeKey = @"iconType";
 
+NSString *SKNPDFAnnotationNameKey = @"name";
+
 NSString *SKNPDFAnnotationPointListsKey = @"pointLists";
 
 NSString *SKNPDFAnnotationStringValueKey = @"stringValue";
@@ -270,6 +272,7 @@
 
 #if !defined(MAC_OS_X_VERSION_10_13) || MAC_OS_X_VERSION_MAX_ALLOWED < 
MAC_OS_X_VERSION_10_13
 @interface PDFAnnotation (SKNHighSierraDeclarations)
+- (NSString *)stampName;
 - (NSString *)widgetFieldType;
 - (NSInteger)buttonWidgetState;
 - (NSString *)widgetStringValue;
@@ -518,7 +521,10 @@
         }
         
         if ([type isEqualToString:SKNTextString] || [type 
isEqualToString:SKNStampString] || [type isEqualToString:SKNNoteString]) {
+            NSString *name = [dict objectForKey:SKNPDFAnnotationNameKey];
             NSNumber *iconType = [dict 
objectForKey:SKNPDFAnnotationIconTypeKey];
+            if ([name isKindOfClass:stringClass])
+                [self setStampName:name];
             if ([iconType respondsToSelector:@selector(integerValue)])
                 [self setIconType:[iconType integerValue]];
         }
@@ -696,10 +702,19 @@
         }
             
         if ([type isEqualToString:SKNStampString]) {
-            if ([self respondsToSelector:@selector(iconType)])
-                [dict setValue:[NSNumber numberWithInteger:[(id)self 
iconType]] forKey:SKNPDFAnnotationIconTypeKey];
-            else if ((value = [self valueForAnnotationKey:@"/Name"]))
-                [dict setValue:[NSNumber 
numberWithInteger:SKNIconTypeFromAnnotationValue(value)] 
forKey:SKNPDFAnnotationIconTypeKey];
+            if ([self respondsToSelector:@selector(stampName)])
+                value = [self stampName];
+            else
+                value = [self valueForAnnotationKey:@"/Name"];
+            if (value) {
+                [dict setValue:value forKey:SKNPDFAnnotationNameKey];
+                if ([[NSSet setWithObjects:@"/Comment", @"/Key", @"/Note", 
@"/Help", @"/NewParagraph", @"/Paragraph", @"/Insert", nil] 
containsObject:value]) {
+                    if ([self respondsToSelector:@selector(iconType)])
+                        [dict setValue:[NSNumber numberWithInteger:[(id)self 
iconType]] forKey:SKNPDFAnnotationIconTypeKey];
+                    else
+                        [dict setValue:[NSNumber 
numberWithInteger:SKNIconTypeFromAnnotationValue(value)] 
forKey:SKNPDFAnnotationIconTypeKey];
+                }
+            }
             [dict setValue:appearanceImageForAnnotation(self) 
forKey:SKNPDFAnnotationImageKey];
         }
             
@@ -1344,6 +1359,10 @@
 - (id)initSkimNoteWithProperties:(NSDictionary *)dict{
     self = [super initSkimNoteWithProperties:dict];
     if (self) {
+        Class stringClass = [NSString class];
+        NSString *name = [dict objectForKey:SKNPDFAnnotationNameKey];
+        if ([name isKindOfClass:stringClass])
+            [self setName:name];
         NSNumber *iconType = [dict objectForKey:SKNPDFAnnotationIconTypeKey];
         if ([iconType respondsToSelector:@selector(integerValue)] && [self 
respondsToSelector:@selector(setIconType:)])
             [self setIconType:[iconType integerValue]];
@@ -1353,14 +1372,9 @@
 
 - (NSDictionary *)SkimNoteProperties{
     NSMutableDictionary *dict = [self genericSkimNoteProperties];
-#if !defined(MAC_OS_X_VERSION_10_12) || MAC_OS_X_VERSION_MAX_ALLOWED < 
MAC_OS_X_VERSION_10_12
-    if ([self respondsToSelector:@selector(iconType)] == NO) {
-        NSString *name = [self name];
-        if (name && [name hasPrefix:@"/"] == NO)
-            name = [@"/" stringByAppendingString:name];
-        [dict setValue:[NSNumber 
numberWithInteger:SKNIconTypeFromAnnotationValue(name)] 
forKey:SKNPDFAnnotationIconTypeKey];
-    } else
-#endif
+    NSString *name = [self name];
+    [dict setValue:name forKey:SKNPDFAnnotationNameKey];
+    if (name && [[NSSet setWithObjects:@"/Comment", @"/Key", @"/Note", 
@"/Help", @"/NewParagraph", @"/Paragraph", @"/Insert", nil] 
containsObject:name] && [self respondsToSelector:@selector(iconType)])
         [dict setValue:[NSNumber numberWithInteger:[self iconType]] 
forKey:SKNPDFAnnotationIconTypeKey];
     [dict setValue:appearanceImageForAnnotation(self) 
forKey:SKNPDFAnnotationImageKey];
     return dict;

Modified: trunk/SkimNotes/SKNPDFAnnotationNote.m
===================================================================
--- trunk/SkimNotes/SKNPDFAnnotationNote.m      2024-10-30 23:32:03 UTC (rev 
14617)
+++ trunk/SkimNotes/SKNPDFAnnotationNote.m      2024-10-31 15:03:53 UTC (rev 
14618)
@@ -58,6 +58,7 @@
 #if !defined(MAC_OS_X_VERSION_10_12) || MAC_OS_X_VERSION_MAX_ALLOWED < 
MAC_OS_X_VERSION_10_12
 @interface PDFAnnotation (SKNSierraDeclarations)
 - (void)drawWithBox:(PDFDisplayBox)box inContext:(CGContextRef)context;
+- (id)valueForAnnotationKey:(NSString *)key;
 - (void)setValue:(id)value forAnnotationKey:(NSString *)key;
 @end
 @interface PDFPage (SKNSierraDeclarations)
@@ -106,9 +107,12 @@
         Class stringClass = [NSString class];
         Class imageClass = [PDFKitPlatformImage class];
         Class dataClass = [NSData class];
+        NSString *aName = [dict objectForKey:SKNPDFAnnotationNameKey];
         NSAttributedString *aText = [dict 
objectForKey:SKNPDFAnnotationTextKey];
         PDFKitPlatformImage *anImage = [dict 
objectForKey:SKNPDFAnnotationImageKey];
         NSNumber *drawImage = [dict 
objectForKey:SKNPDFAnnotationDrawsImageKey];
+        if ([aName isKindOfClass:stringClass] && [self 
respondsToSelector:@selector(setValue:forAnnotationKey:)])
+            [self setValue:aName forAnnotationKey:@"/Name"];
         if ([drawImage respondsToSelector:@selector(boolValue)])
             _drawsImage = [drawImage boolValue];
         else
@@ -133,8 +137,14 @@
 - (NSDictionary *)SkimNoteProperties{
     NSMutableDictionary *dict = [self genericSkimNoteProperties];
     [dict setValue:[NSNumber numberWithInteger:[self iconType]] 
forKey:SKNPDFAnnotationIconTypeKey];
-    if ([self drawsImage])
+    if ([self drawsImage]) {
         [dict setValue:[NSNumber numberWithBool:YES] 
forKey:SKNPDFAnnotationDrawsImageKey];
+        if ([self respondsToSelector:@selector(valueForAnnotationKey:)]) {
+            NSString *name = [self valueForAnnotationKey:@"/Name"];
+            if (name && [[NSSet setWithObjects:@"/Comment", @"/Key", @"/Note", 
@"/Help", @"/NewParagraph", @"/Paragraph", @"/Insert", nil] 
containsObject:name] == NO)
+                [dict setValue:name forKey:SKNPDFAnnotationNameKey];
+        }
+    }
     [dict setValue:[self text] forKey:SKNPDFAnnotationTextKey];
     [dict setValue:[self image] forKey:SKNPDFAnnotationImageKey];
     return dict;

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