Revision: 14445
http://sourceforge.net/p/skim-app/code/14445
Author: hofman
Date: 2024-09-01 17:44:34 +0000 (Sun, 01 Sep 2024)
Log Message:
-----------
Add support for real rectangle scripting type, to get as bounds of a selection
Modified Paths:
--------------
trunk/NSData_SKExtensions.h
trunk/NSData_SKExtensions.m
trunk/SKObtainCommand.m
trunk/Skim.sdef
Modified: trunk/NSData_SKExtensions.h
===================================================================
--- trunk/NSData_SKExtensions.h 2024-09-01 17:26:09 UTC (rev 14444)
+++ trunk/NSData_SKExtensions.h 2024-09-01 17:44:34 UTC (rev 14445)
@@ -63,10 +63,12 @@
+ (NSData *)dataWithPointAsQDPoint:(NSPoint)point;
+ (NSData *)dataWithRectAsQDRect:(NSRect)rect;
+ (NSData *)dataWithPointAsNSPoint:(NSPoint)point;
++ (NSData *)dataWithRectAsNSRect:(NSRect)rect;
@property (nonatomic, readonly) NSPoint pointValueAsQDPoint;
@property (nonatomic, readonly) NSRect rectValueAsQDRect;
@property (nonatomic, readonly) NSPoint pointValueAsNSPoint;
+@property (nonatomic, readonly) NSRect rectValueAsNSRect;
+ (instancetype)scriptingPdfWithDescriptor:(NSAppleEventDescriptor
*)descriptor;
@property (nonatomic, readonly) NSAppleEventDescriptor *scriptingPdfDescriptor;
@@ -76,6 +78,8 @@
@property (nonatomic, readonly) NSAppleEventDescriptor *scriptingRtfDescriptor;
+ (instancetype)scriptingRealPointWithDescriptor:(NSAppleEventDescriptor
*)descriptor;
@property (nonatomic, readonly) NSAppleEventDescriptor
*scriptingRealPointDescriptor;
++ (instancetype)scriptingRealRectangleWithDescriptor:(NSAppleEventDescriptor
*)descriptor;
+@property (nonatomic, readonly) NSAppleEventDescriptor
*scriptingRealRectangleDescriptor;
@end
Modified: trunk/NSData_SKExtensions.m
===================================================================
--- trunk/NSData_SKExtensions.m 2024-09-01 17:26:09 UTC (rev 14444)
+++ trunk/NSData_SKExtensions.m 2024-09-01 17:44:34 UTC (rev 14445)
@@ -191,6 +191,12 @@
return [self dataWithBytes:&point length:sizeof(NSPoint)];
}
++ (NSData *)dataWithRectAsNSRect:(NSRect)rect {
+ if (floor(NSMinX(rect)) >= NSMinX(rect) && floor(NSMinY(rect)) >=
NSMinY(rect) && floor(NSMaxX(rect)) >= NSMaxX(rect) && floor(NSMaxY(rect)) >=
NSMaxY(rect))
+ return [self dataWithRectAsQDRect:rect];
+ return [self dataWithBytes:&rect length:sizeof(NSRect)];
+}
+
- (NSPoint)pointValueAsQDPoint {
NSPoint point = NSZeroPoint;
if ([self length] == sizeof(Point)) {
@@ -218,6 +224,15 @@
return point;
}
+- (NSRect)rectValueAsNSRect {
+ NSRect rect = NSZeroRect;
+ if ([self length] == sizeof(NSRect)) {
+ const NSRect *nsRect = (const NSRect *)[self bytes];
+ rect = *nsRect;
+ }
+ return rect;
+}
+
+ (instancetype)scriptingPdfWithDescriptor:(NSAppleEventDescriptor
*)descriptor {
return [descriptor data];
}
@@ -275,4 +290,41 @@
return descriptor;
}
++ (instancetype)scriptingRealRectangleWithDescriptor:(NSAppleEventDescriptor
*)descriptor {
+ NSRect rect = NSZeroRect;
+ if ([descriptor descriptorType] == typeAEList) {
+ if ([descriptor numberOfItems] == 4) {
+ rect.origin.x = [[descriptor descriptorAtIndex:1] doubleValue];
+ rect.size.width = [[descriptor descriptorAtIndex:3] doubleValue] -
NSMinX(rect);
+ rect.origin.y = [[descriptor descriptorAtIndex:4] doubleValue];
+ rect.size.height = [[descriptor descriptorAtIndex:2] doubleValue]
- NSMinY(rect);
+ }
+ } else {
+ NSData *data = [descriptor data];
+ if ([data length] == sizeof(NSRect) || [data length] == sizeof(Rect))
+ return data;
+ }
+ return [NSData dataWithRectAsNSRect:rect];
+}
+
+- (NSAppleEventDescriptor *)scriptingRealRectangleDescriptor {
+ NSAppleEventDescriptor *descriptor;
+ if ([self length] == sizeof(Rect)) {
+ descriptor = [NSAppleEventDescriptor
descriptorWithDescriptorType:typeQDRectangle data:self];
+ } else {
+ NSRect rect = [self rectValueAsNSRect];
+ if (floor(NSMinX(rect)) >= NSMinX(rect) && floor(NSMinY(rect)) >=
NSMinY(rect) && floor(NSMaxX(rect)) >= NSMaxX(rect) && floor(NSMaxY(rect)) >=
NSMaxY(rect)) {
+ Rect qdRect = SKQDRectFromNSRect(rect);
+ descriptor = [NSAppleEventDescriptor
descriptorWithDescriptorType:typeQDRectangle bytes:&qdRect length:sizeof(Rect)];
+ } else {
+ descriptor = [NSAppleEventDescriptor listDescriptor];
+ [descriptor insertDescriptor:[NSAppleEventDescriptor
descriptorWithDouble:NSMinX(rect)] atIndex:1];
+ [descriptor insertDescriptor:[NSAppleEventDescriptor
descriptorWithDouble:NSMaxY(rect)] atIndex:2];
+ [descriptor insertDescriptor:[NSAppleEventDescriptor
descriptorWithDouble:NSMaxX(rect)] atIndex:3];
+ [descriptor insertDescriptor:[NSAppleEventDescriptor
descriptorWithDouble:NSMinY(rect)] atIndex:4];
+ }
+ }
+ return descriptor;
+}
+
@end
Modified: trunk/SKObtainCommand.m
===================================================================
--- trunk/SKObtainCommand.m 2024-09-01 17:26:09 UTC (rev 14444)
+++ trunk/SKObtainCommand.m 2024-09-01 17:44:34 UTC (rev 14445)
@@ -41,10 +41,12 @@
#import "PDFSelection_SKExtensions.h"
#import "NSAttributedString_SKExtensions.h"
#import "NSGeometry_SKExtensions.h"
+#import "NSData_SKExtensions.h"
-#define typeRichText 'ricT'
-#define typeRTF 'RTF '
-#define typePage 'Page'
+#define typeRichText 'ricT'
+#define typeRTF 'RTF '
+#define typeNSRectangle 'NSrt'
+#define typePage 'Page'
@implementation SKObtainCommand
@@ -92,6 +94,9 @@
NSRect bounds = [selection hasCharacters] ? [selection
boundsForPage:page ?: [selection safeFirstPage]] : NSZeroRect;
Rect qdBounds = SKQDRectFromNSRect(bounds);
desc = [NSAppleEventDescriptor descriptorWithDescriptorType:type
bytes:&qdBounds length:sizeof(Rect)];
+ } else if (type == typeNSRectangle) {
+ NSRect bounds = [selection hasCharacters] ? [selection
boundsForPage:page ?: [selection safeFirstPage]] : NSZeroRect;
+ desc = [[NSData dataWithRectAsNSRect:bounds]
scriptingRealRectangleDescriptor];
} else if (type == typeSInt32) {
NSUInteger first = NSNotFound, last = NSNotFound;
if ((page = [selection safeFirstPage]))
Modified: trunk/Skim.sdef
===================================================================
--- trunk/Skim.sdef 2024-09-01 17:26:09 UTC (rev 14444)
+++ trunk/Skim.sdef 2024-09-01 17:44:34 UTC (rev 14445)
@@ -486,7 +486,7 @@
description="Get properties for a selection or raw RTF data.">
<cocoa class="SKObtainCommand"/>
<direct-parameter type="type"
- description="The type of object to return. Can be (rich) text,
RTF, rectangle, integer, or page."/>
+ description="The type of object to return. Can be (rich) text,
RTF, (real) rectangle, integer, or page."/>
<parameter name="for" code="for "
description="The selection or raw RTF data.">
<type type="specifier" list="yes"/>
@@ -1262,6 +1262,10 @@
<cocoa class="NSData"/>
</value-type>
+ <value-type name="real rectangle" code="NSrt">
+ <cocoa class="NSData"/>
+ </value-type>
+
<value-type name="PDF" code="PDF ">
<cocoa class="NSData"/>
</value-type>
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