Revision: 14562
http://sourceforge.net/p/skim-app/code/14562
Author: hofman
Date: 2024-10-21 17:03:31 +0000 (Mon, 21 Oct 2024)
Log Message:
-----------
Add a flag to note annotation to draw the image instead of an icon
Modified Paths:
--------------
trunk/SkimNotes/SKNPDFAnnotationNote.h
trunk/SkimNotes/SKNPDFAnnotationNote.m
Modified: trunk/SkimNotes/SKNPDFAnnotationNote.h
===================================================================
--- trunk/SkimNotes/SKNPDFAnnotationNote.h 2024-10-20 14:59:59 UTC (rev
14561)
+++ trunk/SkimNotes/SKNPDFAnnotationNote.h 2024-10-21 17:03:31 UTC (rev
14562)
@@ -61,6 +61,10 @@
@discussion Global string for annotation image key.
*/
extern NSString *SKNPDFAnnotationImageKey;
+/*!
+ @discussion Global string for annotation drawsImage key.
+*/
+extern NSString *SKNPDFAnnotationDrawsImageKey;
/*!
@discussion Default size of an anchored note.
@@ -82,6 +86,7 @@
{
NSString *_string;
PDFKitPlatformImage *_image;
+ BOOL _drawsImage;
NSAttributedString *_text;
#if !defined(PDFKIT_PLATFORM_IOS)
NSTextStorage *_textStorage;
@@ -109,6 +114,12 @@
@property (nonatomic, strong, nullable) PDFKitPlatformImage *image;
/*!
+ @abstract Whether the annotation should draw the image rather than an
icon.
+ @discussion
+*/
+@property (nonatomic) BOOL drawsImage;
+
+/*!
@abstract Synchronizes the contents of the annotation with the string
and text.
@discussion This sets the contents to the string value and the text
appended, separated by a double space.
*/
Modified: trunk/SkimNotes/SKNPDFAnnotationNote.m
===================================================================
--- trunk/SkimNotes/SKNPDFAnnotationNote.m 2024-10-20 14:59:59 UTC (rev
14561)
+++ trunk/SkimNotes/SKNPDFAnnotationNote.m 2024-10-21 17:03:31 UTC (rev
14562)
@@ -41,6 +41,7 @@
NSString *SKNPDFAnnotationTextKey = @"text";
NSString *SKNPDFAnnotationImageKey = @"image";
+NSString *SKNPDFAnnotationDrawsImageKey = @"drawsImage";
PDFSize SKNPDFAnnotationNoteSize = {16.0, 16.0};
@@ -86,6 +87,7 @@
@synthesize string = _string;
@synthesize text = _text;
@synthesize image = _image;
+@synthesize drawsImage = _drawsImage;
#if !defined(PDFKIT_PLATFORM_IOS)
@dynamic mutableText;
@synthesize texts = _texts;
@@ -111,6 +113,9 @@
Class dataClass = [NSData class];
NSAttributedString *aText = [dict
objectForKey:SKNPDFAnnotationTextKey];
PDFKitPlatformImage *anImage = [dict
objectForKey:SKNPDFAnnotationImageKey];
+ NSNumber *drawImage = [dict
objectForKey:SKNPDFAnnotationDrawsImageKey];
+ if ([drawImage respondsToSelector:@selector(boolValue)])
+ _drawsImage = [drawImage boolValue];
if ([anImage isKindOfClass:imageClass])
_image = anImage;
else if ([anImage isKindOfClass:dataClass])
@@ -129,6 +134,8 @@
- (NSDictionary *)SkimNoteProperties{
NSMutableDictionary *dict = [self genericSkimNoteProperties];
[dict setValue:[NSNumber numberWithInteger:[self iconType]]
forKey:SKNPDFAnnotationIconTypeKey];
+ if ([self drawsImage])
+ [dict setValue:[NSNumber numberWithBool:YES]
forKey:SKNPDFAnnotationDrawsImageKey];
[dict setValue:[self text] forKey:SKNPDFAnnotationTextKey];
[dict setValue:[self image] forKey:SKNPDFAnnotationImageKey];
return dict;
@@ -156,6 +163,18 @@
}
}
+- (void)drawWithBox:(PDFDisplayBox)box inContext:(CGContextRef)context {
+ if ([self drawsImage] && [self hasAppearanceStream] == NO && [self image]
!= nil) {
+ CGContextSaveGState(context);
+ [[self page] transformContext:context forBox:box];
+ UIGraphicsPushContext(context);
+ [[self image] drawInRect:[self bounds]];
+ UIGraphicsPopContext(context);
+ CGContextRestoreGState(context);
+ } else {
+ [super drawWithBox:box inContext:context];
+ }
+}
#else
- (void)setText:(NSAttributedString *)text {
@@ -201,11 +220,17 @@
return _textStorage;
}
-
+- (void)drawWithBox:(PDFDisplayBox)box inContext:(CGContextRef)context {
+ if ([self drawsImage] && [self hasAppearanceStream] == NO && [self image]
!= nil) {
+ CGContextSaveGState(context);
+ [[self page] transformContext:context forBox:box];
+ [NSGraphicsContext saveGraphicsState];
+ [NSGraphicsContext setCurrentContext:[NSGraphicsContext
graphicsContextWithCGContext:context flipped:NO]];
+ [[self image] drawInRect:[self bounds]];
+ [NSGraphicsContext restoreGraphicsState];
+ CGContextRestoreGState(context);
#if !defined(MAC_OS_X_VERSION_10_15) || MAC_OS_X_VERSION_MIN_REQUIRED <
MAC_OS_X_VERSION_10_15
-
-- (void)drawWithBox:(PDFDisplayBox)box inContext:(CGContextRef)context {
- if (floor(NSAppKitVersionNumber) < SKNAppKitVersionNumber10_12 ||
floor(NSAppKitVersionNumber) > SKNAppKitVersionNumber10_14 || [self
hasAppearanceStream]) {
+ } else if (floor(NSAppKitVersionNumber) < SKNAppKitVersionNumber10_12 ||
floor(NSAppKitVersionNumber) > SKNAppKitVersionNumber10_14 || [self
hasAppearanceStream]) {
[super drawWithBox:box inContext:context];
} else {
// on 10.12 draws based on the type rather than the (super)class
@@ -237,12 +262,15 @@
}
CGContextRestoreGState(context);
}
+#else
+ } else {
+ [super drawWithBox:box inContext:context];
+ }
+#endif
}
#endif
-#endif
-
@end
#if !defined(PDFKIT_PLATFORM_IOS) && (!defined(MAC_OS_X_VERSION_10_15) ||
MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_15)
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