Revision: 16526
http://sourceforge.net/p/skim-app/code/16526
Author: hofman
Date: 2026-09-22 21:41:32 +0000 (Tue, 22 Sep 2026)
Log Message:
-----------
Fix quadrilateral points on macOS also when not using legacy classes
Modified Paths:
--------------
trunk/SkimNotes/PDFAnnotation_SKNExtensions.m
Modified: trunk/SkimNotes/PDFAnnotation_SKNExtensions.m
===================================================================
--- trunk/SkimNotes/PDFAnnotation_SKNExtensions.m 2026-09-22 15:52:02 UTC
(rev 16525)
+++ trunk/SkimNotes/PDFAnnotation_SKNExtensions.m 2026-09-22 21:41:32 UTC
(rev 16526)
@@ -297,6 +297,8 @@
#endif
+static inline NSArray *quadrilateralPointsFromPointStrings(NSArray
*pointStrings);
+
@implementation PDFAnnotation (SKNExtensions)
char SKNIsSkimNoteKey;
@@ -529,12 +531,8 @@
} else if ([type isEqualToString:SKNHighlightString] || [type
isEqualToString:SKNMarkUpString] || [type isEqualToString:SKNUnderlineString]
|| [type isEqualToString:SKNStrikeOutString] || [type
isEqualToString:SKNSquigglyString]) {
NSArray *pointStrings = [dict
objectForKey:SKNPDFAnnotationQuadrilateralPointsKey];
- NSMutableArray *pointValues = [[NSMutableArray alloc]
initWithCapacity:[pointStrings count]];
- for (NSString *pointString in pointStrings) {
- PDFPoint p = SKNPointFromString(pointString);
- [pointValues addObject:[[NSValue alloc] initWithBytes:&p
objCType:@encode(PDFPoint)]];
- }
- [self setQuadrilateralPoints:pointValues];
+ if ([pointStrings isKindOfClass:arrayClass])
+ [self
setQuadrilateralPoints:quadrilateralPointsFromPointStrings(pointStrings)];
} else if ([type isEqualToString:SKNTextString] || [type
isEqualToString:SKNStampString] || [type isEqualToString:SKNNoteString]) {
@@ -1362,52 +1360,14 @@
#pragma mark -
@implementation PDFAnnotationMarkup (SKNExtensions)
-/*
- http://www.cocoabuilder.com/archive/message/cocoa/2007/2/16/178891
- The docs are wrong (as is Adobe's spec). The ordering on the rotated page is:
- --------
- | 0 1 |
- | 2 3 |
- --------
- */
-static inline void swapPoints(NSPoint p[4], NSUInteger i, NSUInteger j) {
- NSPoint tmp = p[i];
- p[i] = p[j];
- p[j] = tmp;
-}
-
- (id)initSkimNoteWithProperties:(NSDictionary *)dict{
self = [super initSkimNoteWithProperties:dict];
if (self) {
Class arrayClass = [NSArray class];
NSArray *pointStrings = [dict
objectForKey:SKNPDFAnnotationQuadrilateralPointsKey];
- if ([pointStrings isKindOfClass:arrayClass]) {
- // fix the order, as we have done it wrong for a long time
- NSUInteger i, iMax = [pointStrings count] / 4;
- NSMutableArray *quadPoints = [[NSMutableArray alloc]
initWithCapacity:4 * iMax];
- for (i = 0; i < iMax; i++) {
- NSPoint p[4];
- NSUInteger j;
- for (j = 0; j < 4; j++)
- p[j] = NSPointFromString([pointStrings objectAtIndex:4 * i
+ j]);
- // p[0]-p[1] should be in the same direction as p[2]-p[3]
- if ((p[1].x - p[0].x) * (p[3].x - p[2].x) + (p[1].y - p[0].y)
* (p[3].y - p[2].y) < 0.0) {
- swapPoints(p, 2, 3);
- }
- // p[0], p[1], p[2] should be ordered clockwise
- if ((p[1].y - p[0].y) * (p[2].x - p[0].x) - (p[1].x - p[0].x)
* (p[2].y - p[0].y) < 0.0) {
- swapPoints(p, 0, 2);
- swapPoints(p, 1, 3);
- }
- for (j = 0; j < 4; j++) {
- NSValue *value = [[NSValue alloc] initWithBytes:&p[j]
objCType:@encode(NSPoint)];
- [quadPoints addObject:value];
- }
- }
- [self setQuadrilateralPoints:quadPoints];
- }
-
+ if ([pointStrings isKindOfClass:arrayClass])
+ [self
setQuadrilateralPoints:quadrilateralPointsFromPointStrings(pointStrings)];
}
return self;
}
@@ -2075,3 +2035,53 @@
}
#endif
+
+/*
+ http://www.cocoabuilder.com/archive/message/cocoa/2007/2/16/178891
+ The docs are wrong (as is Adobe's spec). The ordering on the rotated page is:
+ --------
+ | 0 1 |
+ | 2 3 |
+ --------
+ */
+
+#ifndef PDFKIT_PLATFORM_IOS
+static inline void swapPoints(NSPoint p[4], NSUInteger i, NSUInteger j) {
+ NSPoint tmp = p[i];
+ p[i] = p[j];
+ p[j] = tmp;
+}
+#endif
+
+static inline NSArray *quadrilateralPointsFromPointStrings(NSArray
*pointStrings) {
+ NSMutableArray *quadPoints = [[NSMutableArray alloc]
initWithCapacity:[pointStrings count]];
+#ifdef PDFKIT_PLATFORM_IOS
+ for (NSString *pointString in pointStrings) {
+ CGPoint p = CGPointFromString(pointString);
+ [pointValues addObject:[[NSValue alloc] initWithBytes:&p
objCType:@encode(CGPoint)]];
+ }
+#else
+ // fix the order, as we have done it wrong for a long time
+ NSUInteger i, iMax = [pointStrings count] / 4;
+ for (i = 0; i < iMax; i++) {
+ NSPoint p[4];
+ NSUInteger j;
+ for (j = 0; j < 4; j++)
+ p[j] = NSPointFromString([pointStrings objectAtIndex:4 * i + j]);
+ // p[0]-p[1] should be in the same direction as p[2]-p[3]
+ if ((p[1].x - p[0].x) * (p[3].x - p[2].x) + (p[1].y - p[0].y) *
(p[3].y - p[2].y) < 0.0) {
+ swapPoints(p, 2, 3);
+ }
+ // p[0], p[1], p[2] should be ordered clockwise
+ if ((p[1].y - p[0].y) * (p[2].x - p[0].x) - (p[1].x - p[0].x) *
(p[2].y - p[0].y) < 0.0) {
+ swapPoints(p, 0, 2);
+ swapPoints(p, 1, 3);
+ }
+ for (j = 0; j < 4; j++) {
+ NSValue *value = [[NSValue alloc] initWithBytes:&p[j]
objCType:@encode(NSPoint)];
+ [quadPoints addObject:value];
+ }
+ }
+#endif
+ return quadPoints;
+}
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