Revision: 14585
http://sourceforge.net/p/skim-app/code/14585
Author: hofman
Date: 2024-10-26 16:06:59 +0000 (Sat, 26 Oct 2024)
Log Message:
-----------
Support converting Stamp annotations to Note Skim annotations
Modified Paths:
--------------
trunk/PDFAnnotation_SKExtensions.h
trunk/PDFAnnotation_SKExtensions.m
trunk/SKFDFParser.m
trunk/SKMainDocument.m
trunk/Skim.xcodeproj/project.pbxproj
Added Paths:
-----------
trunk/PDFAnnotationStamp_SKExtensions.h
trunk/PDFAnnotationStamp_SKExtensions.m
Added: trunk/PDFAnnotationStamp_SKExtensions.h
===================================================================
--- trunk/PDFAnnotationStamp_SKExtensions.h (rev 0)
+++ trunk/PDFAnnotationStamp_SKExtensions.h 2024-10-26 16:06:59 UTC (rev
14585)
@@ -0,0 +1,47 @@
+//
+// PDFAnnotationStamp_SKExtensions.h
+// Skim
+//
+// Created by Christiaan Hofman on 26/10/2024.
+/*
+ This software is Copyright (c) 2024
+ Christiaan Hofman. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ - Neither the name of Christiaan Hofman nor the names of any
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <Cocoa/Cocoa.h>
+#import <Quartz/Quartz.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface PDFAnnotationStamp (SKExtensions)
+@end
+
+NS_ASSUME_NONNULL_END
Added: trunk/PDFAnnotationStamp_SKExtensions.m
===================================================================
--- trunk/PDFAnnotationStamp_SKExtensions.m (rev 0)
+++ trunk/PDFAnnotationStamp_SKExtensions.m 2024-10-26 16:06:59 UTC (rev
14585)
@@ -0,0 +1,72 @@
+//
+// PDFAnnotationStamp_SKExtensions.m
+// Skim
+//
+// Created by Christiaan Hofman on 26/10/2024.
+/*
+ This software is Copyright (c) 2024
+ Christiaan Hofman. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ - Neither the name of Christiaan Hofman nor the names of any
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "PDFAnnotationStamp_SKExtensions.h"
+#import <SkimNotes/SkimNotes.h>
+#import "PDFAnnotation_SKExtensions.h"
+#import "SKFDFParser.h"
+
+@implementation PDFAnnotationStamp (SKExtensions)
+
+- (NSString *)fdfString {
+ NSMutableString *fdfString = [[super fdfString] mutableCopy];
+ [fdfString appendFDFName:SKFDFAnnotationIconTypeKey];
+ [fdfString
appendFDFName:SKFDFTextAnnotationIconTypeFromPDFTextAnnotationIconType([self
iconType])];
+ return fdfString;
+}
+
+- (BOOL)isWidget { return NO; }
+
+- (BOOL)isLnk { return NO; }
+
+- (BOOL)isMovable { return [self isSkimNote]; }
+
+- (BOOL)isConvertibleAnnotation { return YES; }
+
+- (NSSet *)keysForValuesToObserveForUndo {
+ static NSSet *textKeys = nil;
+ if (textKeys == nil) {
+ NSMutableSet *mutableKeys = [[super keysForValuesToObserveForUndo]
mutableCopy];
+ [mutableKeys addObject:SKNPDFAnnotationIconTypeKey];
+ [mutableKeys removeObject:SKNPDFAnnotationBorderKey];
+ textKeys = [mutableKeys copy];
+ }
+ return textKeys;
+}
+
+@end
Modified: trunk/PDFAnnotation_SKExtensions.h
===================================================================
--- trunk/PDFAnnotation_SKExtensions.h 2024-10-26 16:00:29 UTC (rev 14584)
+++ trunk/PDFAnnotation_SKExtensions.h 2024-10-26 16:06:59 UTC (rev 14585)
@@ -68,6 +68,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;
@property (nonatomic, nullable, readonly) NSString *fdfString;
Modified: trunk/PDFAnnotation_SKExtensions.m
===================================================================
--- trunk/PDFAnnotation_SKExtensions.m 2024-10-26 16:00:29 UTC (rev 14584)
+++ trunk/PDFAnnotation_SKExtensions.m 2024-10-26 16:06:59 UTC (rev 14585)
@@ -220,6 +220,29 @@
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];
+ 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;
+}
+
- (NSString *)fdfString {
NSMutableString *fdfString = [NSMutableString string];
NSRect bounds = [self bounds];
Modified: trunk/SKFDFParser.m
===================================================================
--- trunk/SKFDFParser.m 2024-10-26 16:00:29 UTC (rev 14584)
+++ trunk/SKFDFParser.m 2024-10-26 16:06:59 UTC (rev 14585)
@@ -256,6 +256,8 @@
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) {
success = NO;
}
Modified: trunk/SKMainDocument.m
===================================================================
--- trunk/SKMainDocument.m 2024-10-26 16:00:29 UTC (rev 14584)
+++ trunk/SKMainDocument.m 2024-10-26 16:06:59 UTC (rev 14585)
@@ -1130,6 +1130,8 @@
NSDictionary *properties = [annotation SkimNoteProperties];
if ([[annotation type] isEqualToString:SKNTextString])
properties = [PDFAnnotation
textToNoteSkimNoteProperties:properties];
+ else if ([[annotation type] isEqualToString:SKNStampString])
+ properties = [PDFAnnotation
stampToNoteSkimNoteProperties:properties];
if (noteDicts == nil)
noteDicts = [[NSMutableArray alloc] init];
[noteDicts addObject:properties];
Modified: trunk/Skim.xcodeproj/project.pbxproj
===================================================================
--- trunk/Skim.xcodeproj/project.pbxproj 2024-10-26 16:00:29 UTC (rev
14584)
+++ trunk/Skim.xcodeproj/project.pbxproj 2024-10-26 16:06:59 UTC (rev
14585)
@@ -276,6 +276,7 @@
CEE8DFCE0E5C809C00EFA97F /* SkimNotes.framework in Frameworks
*/ = {isa = PBXBuildFile; fileRef = CE7DC7320E09286500D6D76D /*
SkimNotes.framework */; };
CEE8DFCF0E5C809C00EFA97F /* Sparkle.framework in Frameworks */
= {isa = PBXBuildFile; fileRef = CE2BD8200BD4127A00A5F4DB /* Sparkle.framework
*/; };
CEE9BC0814CDD98100262718 /* SKBookmarkSheetController.m in
Sources */ = {isa = PBXBuildFile; fileRef = CEE9BC0714CDD98100262718 /*
SKBookmarkSheetController.m */; };
+ CEEA05D32CCD49F400D7417A /* PDFAnnotationStamp_SKExtensions.m
in Sources */ = {isa = PBXBuildFile; fileRef = CEEA05D22CCD49F400D7417A /*
PDFAnnotationStamp_SKExtensions.m */; };
CEEC0A0A0DCB2594003DD9B6 /* SKMainWindowController_UI.m in
Sources */ = {isa = PBXBuildFile; fileRef = CEEC0A090DCB2594003DD9B6 /*
SKMainWindowController_UI.m */; };
CEECD61C12E9E30B00B9E35E /* NSError_SKExtensions.m in Sources
*/ = {isa = PBXBuildFile; fileRef = CEECD61B12E9E30B00B9E35E /*
NSError_SKExtensions.m */; };
CEED148C2709EE4D00A8C4AA /* SKBasePDFView.m in Sources */ =
{isa = PBXBuildFile; fileRef = CEED148B2709EE4D00A8C4AA /* SKBasePDFView.m */;
};
@@ -1234,6 +1235,8 @@
CEE7E77A24426C380034690E /*
PDFAnnotationChoiceWidget_SKExtensions.m */ = {isa = PBXFileReference;
lastKnownFileType = sourcecode.c.objc; path =
PDFAnnotationChoiceWidget_SKExtensions.m; sourceTree = "<group>"; };
CEE9BC0614CDD98100262718 /* SKBookmarkSheetController.h */ =
{isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h;
path = SKBookmarkSheetController.h; sourceTree = "<group>"; };
CEE9BC0714CDD98100262718 /* SKBookmarkSheetController.m */ =
{isa = PBXFileReference; fileEncoding = 4; lastKnownFileType =
sourcecode.c.objc; path = SKBookmarkSheetController.m; sourceTree = "<group>";
};
+ CEEA05D12CCD49F400D7417A /* PDFAnnotationStamp_SKExtensions.h
*/ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path =
PDFAnnotationStamp_SKExtensions.h; sourceTree = "<group>"; };
+ CEEA05D22CCD49F400D7417A /* PDFAnnotationStamp_SKExtensions.m
*/ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path =
PDFAnnotationStamp_SKExtensions.m; sourceTree = "<group>"; };
CEEC0A080DCB2594003DD9B6 /* SKMainWindowController_UI.h */ =
{isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h;
path = SKMainWindowController_UI.h; sourceTree = "<group>"; };
CEEC0A090DCB2594003DD9B6 /* SKMainWindowController_UI.m */ =
{isa = PBXFileReference; fileEncoding = 4; lastKnownFileType =
sourcecode.c.objc; path = SKMainWindowController_UI.m; sourceTree = "<group>";
};
CEECD61A12E9E30B00B9E35E /* NSError_SKExtensions.h */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path =
NSError_SKExtensions.h; sourceTree = "<group>"; };
@@ -2223,6 +2226,8 @@
CEE54DB30DA2E99D0037169F /*
PDFAnnotationMarkup_SKExtensions.m */,
CEE54D960DA2E6FC0037169F /*
PDFAnnotationSquare_SKExtensions.h */,
CEE54D970DA2E6FC0037169F /*
PDFAnnotationSquare_SKExtensions.m */,
+ CEEA05D12CCD49F400D7417A /*
PDFAnnotationStamp_SKExtensions.h */,
+ CEEA05D22CCD49F400D7417A /*
PDFAnnotationStamp_SKExtensions.m */,
CE4642E30DF5CBD900CFD8D2 /*
PDFAnnotationText_SKExtensions.h */,
CE4642E40DF5CBD900CFD8D2 /*
PDFAnnotationText_SKExtensions.m */,
CEE7E76324426BFF0034690E /*
PDFAnnotationTextWidget_SKExtensions.h */,
@@ -2829,6 +2834,7 @@
CE3A41580B790C56006B64D3 /* SKDragImageView.m
in Sources */,
CE3A45530B7A04A4006B64D3 /*
NSBezierPath_SKExtensions.m in Sources */,
CEBCA4C02868A93A00E6376E /* SKLine.m in Sources
*/,
+ CEEA05D32CCD49F400D7417A /*
PDFAnnotationStamp_SKExtensions.m in Sources */,
CE4EBDDA0B7BF3B30091F228 /* SKSideWindow.m in
Sources */,
CE2526362B3834E40084F43D /*
NSToolbarItem_SKExtensions.m in Sources */,
CE4EC88C0B7E6EDB0091F228 /* SKSplitView.m in
Sources */,
@@ -3507,7 +3513,6 @@
CEF60DD3114C0E8E0074ACC4 /* it */,
CEF60DFF114C0EC10074ACC4 /* es */,
CEF877521190593E006436A2 /* pl */,
- CEF60DE7114C0EA80074ACC4 /* ru */,
CE157EEC12D4EBC100515B85 /* ja */,
CE1632BD1582AC6200CFF419 /* zh_CN */,
CEF60E15114C0ED70074ACC4 /* zh_TW */,
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