|
@@ -0,0 +1,523 @@
|
|
|
+//
|
|
|
+// KMLineInspector.swift
|
|
|
+// PDF Master
|
|
|
+//
|
|
|
+// Created by tangchao on 2023/11/10.
|
|
|
+//
|
|
|
+
|
|
|
+import Cocoa
|
|
|
+
|
|
|
+class KMLineInspector: NSWindowController {
|
|
|
+ /*
|
|
|
+ extern NSString *SKLineInspectorLineAttributeDidChangeNotification;
|
|
|
+
|
|
|
+ typedef NS_ENUM(NSUInteger, SKLineChangeAction) {
|
|
|
+ SKNoLineChangeAction,
|
|
|
+ SKLineChangeActionLineWidth,
|
|
|
+ SKLineChangeActionStyle,
|
|
|
+ SKLineChangeActionDashPattern,
|
|
|
+ SKLineChangeActionStartLineStyle,
|
|
|
+ SKLineChangeActionEndLineStyle
|
|
|
+ };
|
|
|
+
|
|
|
+ @class SKLineWell;
|
|
|
+
|
|
|
+ @interface SKLineInspector : SKWindowController {
|
|
|
+ NSSlider *lineWidthSlider;
|
|
|
+ NSTextField *lineWidthField;
|
|
|
+ NSSegmentedControl *styleButton;
|
|
|
+ NSTextField *dashPatternField;
|
|
|
+ NSSegmentedControl *startLineStyleButton;
|
|
|
+ NSSegmentedControl *endLineStyleButton;
|
|
|
+ SKLineWell *lineWell;
|
|
|
+ NSTextField *lineWidthLabelField;
|
|
|
+ NSTextField *styleLabelField;
|
|
|
+ NSTextField *dashPatternLabelField;
|
|
|
+ NSTextField *startLineStyleLabelField;
|
|
|
+ NSTextField *endLineStyleLabelField;
|
|
|
+ NSArray *labelFields;
|
|
|
+ CGFloat lineWidth;
|
|
|
+ PDFBorderStyle style;
|
|
|
+ NSArray *dashPattern;
|
|
|
+ PDFLineStyle startLineStyle;
|
|
|
+ PDFLineStyle endLineStyle;
|
|
|
+ SKLineChangeAction currentLineChangeAction;
|
|
|
+ }
|
|
|
+
|
|
|
+ @property (nonatomic, retain) IBOutlet NSArray *labelFields;
|
|
|
+ @property (nonatomic) CGFloat lineWidth;
|
|
|
+ @property (nonatomic) PDFBorderStyle style;
|
|
|
+ @property (nonatomic, copy) NSArray *dashPattern;
|
|
|
+ @property (nonatomic) PDFLineStyle startLineStyle, endLineStyle;
|
|
|
+ @property (nonatomic, readonly) SKLineChangeAction currentLineChangeAction;
|
|
|
+
|
|
|
+ + (id)sharedLineInspector;
|
|
|
+ + (BOOL)sharedLineInspectorExists;
|
|
|
+
|
|
|
+ - (void)setAnnotationStyle:(PDFAnnotation *)annotation;
|
|
|
+ */
|
|
|
+
|
|
|
+ @IBOutlet var lineWidthSlider: NSSlider!
|
|
|
+ @IBOutlet var lineWidthField: NSTextField!
|
|
|
+ @IBOutlet var dashPatternField: NSTextField!
|
|
|
+ @IBOutlet var styleButton: NSSegmentedControl!
|
|
|
+ @IBOutlet var startLineStyleButton: NSSegmentedControl!
|
|
|
+ @IBOutlet var endLineStyleButton: NSSegmentedControl!
|
|
|
+ @IBOutlet var lineWidthLabelField: NSTextField!
|
|
|
+ @IBOutlet var styleLabelField: NSTextField!
|
|
|
+ @IBOutlet var dashPatternLabelField: NSTextField!
|
|
|
+ @IBOutlet var startLineStyleLabelField: NSTextField!
|
|
|
+ @IBOutlet var endLineStyleLabelField: NSTextField!
|
|
|
+ @IBOutlet var lineWell: KMLineWell!
|
|
|
+
|
|
|
+ @IBOutlet weak var labelField1: NSTextField!
|
|
|
+ @IBOutlet weak var labelField2: NSTextField!
|
|
|
+ @IBOutlet weak var labelField3: NSTextField!
|
|
|
+ @IBOutlet weak var labelField4: NSTextField!
|
|
|
+ @IBOutlet weak var labelField5: NSTextField!
|
|
|
+
|
|
|
+ static let shared = KMLineInspector(windowNibName: "LineInspector")
|
|
|
+
|
|
|
+ override func windowDidLoad() {
|
|
|
+ super.windowDidLoad()
|
|
|
+
|
|
|
+ // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ SString *SKLineInspectorLineAttributeDidChangeNotification = @"SKLineInspectorLineAttributeDidChangeNotification";
|
|
|
+
|
|
|
+ #define LINEWIDTH_KEY @"lineWidth"
|
|
|
+ #define STYLE_KEY @"style"
|
|
|
+ #define DASHPATTERN_KEY @"dashPattern"
|
|
|
+ #define STARTLINESTYLE_KEY @"startLineStyle"
|
|
|
+ #define ENDLINESTYLE_KEY @"endLineStyle"
|
|
|
+ #define ACTION_KEY @"action"
|
|
|
+
|
|
|
+ #define SKLineInspectorFrameAutosaveName @"SKLineInspector"
|
|
|
+
|
|
|
+ @implementation SKLineInspector
|
|
|
+
|
|
|
+ @synthesize lineWidthSlider, lineWidthField, dashPatternField, styleButton, startLineStyleButton, endLineStyleButton, lineWell, lineWidthLabelField, styleLabelField, dashPatternLabelField, startLineStyleLabelField, endLineStyleLabelField, labelFields, lineWidth, style, dashPattern, startLineStyle, endLineStyle, currentLineChangeAction;
|
|
|
+
|
|
|
+ static SKLineInspector *sharedLineInspector = nil;
|
|
|
+
|
|
|
+ + (id)sharedLineInspector {
|
|
|
+ if (sharedLineInspector == nil)
|
|
|
+ sharedLineInspector = [[self alloc] init];
|
|
|
+ return sharedLineInspector;
|
|
|
+ }
|
|
|
+
|
|
|
+ + (BOOL)sharedLineInspectorExists {
|
|
|
+ return sharedLineInspector != nil;
|
|
|
+ }
|
|
|
+
|
|
|
+ - (id)init {
|
|
|
+ if (sharedLineInspector) NSLog(@"Attempt to allocate second instance of %@", [self class]);
|
|
|
+ self = [super initWithWindowNibName:@"LineInspector"];
|
|
|
+ if (self) {
|
|
|
+ style = kPDFBorderStyleSolid;
|
|
|
+ lineWidth = 1.0;
|
|
|
+ dashPattern = nil;
|
|
|
+ startLineStyle = kPDFLineStyleNone;
|
|
|
+ endLineStyle = kPDFLineStyleNone;
|
|
|
+ currentLineChangeAction = SKNoLineChangeAction;
|
|
|
+ }
|
|
|
+ return self;
|
|
|
+ }
|
|
|
+
|
|
|
+ - (void)dealloc {
|
|
|
+ SKDESTROY(dashPattern);
|
|
|
+ SKDESTROY(lineWidthSlider);
|
|
|
+ SKDESTROY(lineWidthField);
|
|
|
+ SKDESTROY(dashPatternField);
|
|
|
+ SKDESTROY(styleButton);
|
|
|
+ SKDESTROY(startLineStyleButton);
|
|
|
+ SKDESTROY(endLineStyleButton);
|
|
|
+ SKDESTROY(lineWell);
|
|
|
+ SKDESTROY(lineWidthLabelField);
|
|
|
+ SKDESTROY(styleLabelField);
|
|
|
+ SKDESTROY(dashPatternLabelField);
|
|
|
+ SKDESTROY(startLineStyleLabelField);
|
|
|
+ SKDESTROY(endLineStyleLabelField);
|
|
|
+ SKDESTROY(labelFields);
|
|
|
+ [super dealloc];
|
|
|
+ }
|
|
|
+
|
|
|
+ - (void)windowDidLoad {
|
|
|
+ [lineWell setCanActivate:NO];
|
|
|
+ [lineWell bind:SKLineWellLineWidthKey toObject:self withKeyPath:LINEWIDTH_KEY options:nil];
|
|
|
+ [lineWell bind:SKLineWellStyleKey toObject:self withKeyPath:STYLE_KEY options:nil];
|
|
|
+ [lineWell bind:SKLineWellDashPatternKey toObject:self withKeyPath:DASHPATTERN_KEY options:nil];
|
|
|
+ [lineWell bind:SKLineWellStartLineStyleKey toObject:self withKeyPath:STARTLINESTYLE_KEY options:nil];
|
|
|
+ [lineWell bind:SKLineWellEndLineStyleKey toObject:self withKeyPath:ENDLINESTYLE_KEY options:nil];
|
|
|
+
|
|
|
+ [styleButton setHelp:NSLocalizedString(@"Solid line style", @"Tool tip message") forSegment:kPDFBorderStyleSolid];
|
|
|
+ [styleButton setHelp:NSLocalizedString(@"Dashed line style", @"Tool tip message") forSegment:kPDFBorderStyleDashed];
|
|
|
+ [styleButton setHelp:NSLocalizedString(@"Beveled line style", @"Tool tip message") forSegment:kPDFBorderStyleBeveled];
|
|
|
+ [styleButton setHelp:NSLocalizedString(@"Inset line style", @"Tool tip message") forSegment:kPDFBorderStyleInset];
|
|
|
+ [styleButton setHelp:NSLocalizedString(@"Underline line style", @"Tool tip message") forSegment:kPDFBorderStyleUnderline];
|
|
|
+
|
|
|
+ [startLineStyleButton setHelp:NSLocalizedString(@"No start line style", @"Tool tip message") forSegment:kPDFLineStyleNone];
|
|
|
+ [startLineStyleButton setHelp:NSLocalizedString(@"Square start line style", @"Tool tip message") forSegment:kPDFLineStyleSquare];
|
|
|
+ [startLineStyleButton setHelp:NSLocalizedString(@"Circle start line style", @"Tool tip message") forSegment:kPDFLineStyleCircle];
|
|
|
+ [startLineStyleButton setHelp:NSLocalizedString(@"Diamond start line style", @"Tool tip message") forSegment:kPDFLineStyleDiamond];
|
|
|
+ [startLineStyleButton setHelp:NSLocalizedString(@"Open arrow start line style", @"Tool tip message") forSegment:kPDFLineStyleOpenArrow];
|
|
|
+ [startLineStyleButton setHelp:NSLocalizedString(@"Closed arrow start line style", @"Tool tip message") forSegment:kPDFLineStyleClosedArrow];
|
|
|
+
|
|
|
+ [endLineStyleButton setHelp:NSLocalizedString(@"No end line style", @"Tool tip message") forSegment:kPDFLineStyleNone];
|
|
|
+ [endLineStyleButton setHelp:NSLocalizedString(@"Square end line style", @"Tool tip message") forSegment:kPDFLineStyleSquare];
|
|
|
+ [endLineStyleButton setHelp:NSLocalizedString(@"Circle end line style", @"Tool tip message") forSegment:kPDFLineStyleCircle];
|
|
|
+ [endLineStyleButton setHelp:NSLocalizedString(@"Diamond end line style", @"Tool tip message") forSegment:kPDFLineStyleDiamond];
|
|
|
+ [endLineStyleButton setHelp:NSLocalizedString(@"Open arrow end line style", @"Tool tip message") forSegment:kPDFLineStyleOpenArrow];
|
|
|
+ [endLineStyleButton setHelp:NSLocalizedString(@"Closed arrow end line style", @"Tool tip message") forSegment:kPDFLineStyleClosedArrow];
|
|
|
+
|
|
|
+ CGFloat dw = SKAutoSizeLabelFields(labelFields, [NSArray arrayWithObjects:lineWidthSlider, lineWidthField, styleButton, dashPatternField, startLineStyleButton, endLineStyleButton, nil], NO);
|
|
|
+ if (fabs(dw) > 0.0)
|
|
|
+ SKResizeWindow([self window], dw);
|
|
|
+
|
|
|
+ [self setWindowFrameAutosaveName:SKLineInspectorFrameAutosaveName];
|
|
|
+
|
|
|
+ NSImage *image = nil;
|
|
|
+ NSSize size = NSMakeSize(29.0, 12.0);
|
|
|
+
|
|
|
+ image = [NSImage imageWithSize:size drawingHandler:^(NSRect rect){
|
|
|
+ NSBezierPath *path = [NSBezierPath bezierPathWithRect:NSMakeRect(6.0, 3.0, 17.0, 6.0)];
|
|
|
+ [path setLineWidth:2.0];
|
|
|
+ [[NSColor blackColor] setStroke];
|
|
|
+ [path stroke];
|
|
|
+ return YES;
|
|
|
+ }];
|
|
|
+ [styleButton setImage:image forSegment:kPDFBorderStyleSolid];
|
|
|
+
|
|
|
+ image = [NSImage imageWithSize:size drawingHandler:^(NSRect rect){
|
|
|
+ NSBezierPath *path = [NSBezierPath bezierPath];
|
|
|
+ [path moveToPoint:NSMakePoint(6.0, 5.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(6.0, 3.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(9.0, 3.0)];
|
|
|
+ [path moveToPoint:NSMakePoint(12.0, 3.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(17.0, 3.0)];
|
|
|
+ [path moveToPoint:NSMakePoint(20.0, 3.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(23.0, 3.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(23.0, 5.0)];
|
|
|
+ [path moveToPoint:NSMakePoint(23.0, 7.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(23.0, 9.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(20.0, 9.0)];
|
|
|
+ [path moveToPoint:NSMakePoint(17.0, 9.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(12.0, 9.0)];
|
|
|
+ [path moveToPoint:NSMakePoint(9.0, 9.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(6.0, 9.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(6.0, 7.0)];
|
|
|
+ [path setLineWidth:2.0];
|
|
|
+ [[NSColor blackColor] setStroke];
|
|
|
+ [path stroke];
|
|
|
+ return YES;
|
|
|
+ }];
|
|
|
+ [styleButton setImage:image forSegment:kPDFBorderStyleDashed];
|
|
|
+
|
|
|
+ image = [NSImage imageWithSize:size drawingHandler:^(NSRect rect){
|
|
|
+ NSBezierPath *path = [NSBezierPath bezierPathWithRect:NSMakeRect(6.0, 3.0, 17.0, 6.0)];
|
|
|
+ [path setLineWidth:2.0];
|
|
|
+ [[NSColor colorWithCalibratedWhite:0.0 alpha:0.25] setStroke];
|
|
|
+ [path stroke];
|
|
|
+ path = [NSBezierPath bezierPath];
|
|
|
+ [path moveToPoint:NSMakePoint(7.0, 3.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(23.0, 3.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(23.0, 8.0)];
|
|
|
+ [path setLineWidth:2.0];
|
|
|
+ [[NSColor colorWithCalibratedWhite:0.0 alpha:0.35] set];
|
|
|
+ [path stroke];
|
|
|
+ path = [NSBezierPath bezierPath];
|
|
|
+ [path moveToPoint:NSMakePoint(5.0, 2.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(7.0, 4.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(7.0, 2.0)];
|
|
|
+ [path closePath];
|
|
|
+ [path moveToPoint:NSMakePoint(24.0, 10.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(22.0, 8.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(24.0, 8.0)];
|
|
|
+ [path closePath];
|
|
|
+ [path fill];
|
|
|
+ return YES;
|
|
|
+ }];
|
|
|
+ [styleButton setImage:image forSegment:kPDFBorderStyleBeveled];
|
|
|
+
|
|
|
+ image = [NSImage imageWithSize:size drawingHandler:^(NSRect rect){
|
|
|
+ NSBezierPath *path = [NSBezierPath bezierPathWithRect:NSMakeRect(6.0, 3.0, 17.0, 6.0)];
|
|
|
+ [path setLineWidth:2.0];
|
|
|
+ [[NSColor colorWithCalibratedWhite:0.0 alpha:0.25] setStroke];
|
|
|
+ [path stroke];
|
|
|
+ path = [NSBezierPath bezierPath];
|
|
|
+ [path moveToPoint:NSMakePoint(6.0, 4.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(6.0, 9.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(22.0, 9.0)];
|
|
|
+ [path setLineWidth:2.0];
|
|
|
+ [[NSColor colorWithCalibratedWhite:0.0 alpha:0.35] set];
|
|
|
+ [path stroke];
|
|
|
+ path = [NSBezierPath bezierPath];
|
|
|
+ [path moveToPoint:NSMakePoint(5.0, 2.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(7.0, 4.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(5.0, 4.0)];
|
|
|
+ [path closePath];
|
|
|
+ [path moveToPoint:NSMakePoint(24.0, 10.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(22.0, 8.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(22.0, 10.0)];
|
|
|
+ [path closePath];
|
|
|
+ [path fill];
|
|
|
+ return YES;
|
|
|
+ }];
|
|
|
+ [styleButton setImage:image forSegment:kPDFBorderStyleInset];
|
|
|
+
|
|
|
+ image = [NSImage imageWithSize:size drawingHandler:^(NSRect rect){
|
|
|
+ NSBezierPath *path = [NSBezierPath bezierPath];
|
|
|
+ [path moveToPoint:NSMakePoint(6.0, 3.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(23.0, 3.0)];
|
|
|
+ [path setLineWidth:2.0];
|
|
|
+ [[NSColor colorWithCalibratedWhite:0.0 alpha:0.5] setStroke];
|
|
|
+ [path stroke];
|
|
|
+ return YES;
|
|
|
+ }];
|
|
|
+ [styleButton setImage:image forSegment:kPDFBorderStyleUnderline];
|
|
|
+
|
|
|
+ size = NSMakeSize(24.0, 12.0);
|
|
|
+
|
|
|
+ image = [NSImage imageWithSize:size drawingHandler:^(NSRect rect){
|
|
|
+ NSBezierPath *path = [NSBezierPath bezierPath];
|
|
|
+ [path moveToPoint:NSMakePoint(20.0, 6.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(8.0, 6.0)];
|
|
|
+ [path setLineWidth:2.0];
|
|
|
+ [[NSColor blackColor] setStroke];
|
|
|
+ [path stroke];
|
|
|
+ return YES;
|
|
|
+ }];
|
|
|
+ [startLineStyleButton setImage:image forSegment:kPDFLineStyleNone];
|
|
|
+
|
|
|
+ image = [NSImage imageWithSize:size drawingHandler:^(NSRect rect){
|
|
|
+ NSBezierPath *path = [NSBezierPath bezierPath];
|
|
|
+ [path moveToPoint:NSMakePoint(4.0, 6.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(16.0, 6.0)];
|
|
|
+ [path setLineWidth:2.0];
|
|
|
+ [[NSColor blackColor] setStroke];
|
|
|
+ [path stroke];
|
|
|
+ return YES;
|
|
|
+ }];
|
|
|
+ [endLineStyleButton setImage:image forSegment:kPDFLineStyleNone];
|
|
|
+
|
|
|
+ image = [NSImage imageWithSize:size drawingHandler:^(NSRect rect){
|
|
|
+ NSBezierPath *path = [NSBezierPath bezierPath];
|
|
|
+ [path moveToPoint:NSMakePoint(20.0, 6.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(8.0, 6.0)];
|
|
|
+ [path appendBezierPathWithRect:NSMakeRect(5.0, 3.0, 6.0, 6.0)];
|
|
|
+ [path setLineWidth:2.0];
|
|
|
+ [[NSColor blackColor] setStroke];
|
|
|
+ [path stroke];
|
|
|
+ return YES;
|
|
|
+ }];
|
|
|
+ [startLineStyleButton setImage:image forSegment:kPDFLineStyleSquare];
|
|
|
+
|
|
|
+ image = [NSImage imageWithSize:size drawingHandler:^(NSRect rect){
|
|
|
+ NSBezierPath *path = [NSBezierPath bezierPath];
|
|
|
+ [path moveToPoint:NSMakePoint(4.0, 6.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(16.0, 6.0)];
|
|
|
+ [path appendBezierPathWithRect:NSMakeRect(13.0, 3.0, 6.0, 6.0)];
|
|
|
+ [path setLineWidth:2.0];
|
|
|
+ [[NSColor blackColor] setStroke];
|
|
|
+ [path stroke];
|
|
|
+ return YES;
|
|
|
+ }];
|
|
|
+ [endLineStyleButton setImage:image forSegment:kPDFLineStyleSquare];
|
|
|
+
|
|
|
+ image = [NSImage imageWithSize:size drawingHandler:^(NSRect rect){
|
|
|
+ NSBezierPath *path = [NSBezierPath bezierPath];
|
|
|
+ [path moveToPoint:NSMakePoint(20.0, 6.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(8.0, 6.0)];
|
|
|
+ [path appendBezierPathWithOvalInRect:NSMakeRect(5.0, 3.0, 6.0, 6.0)];
|
|
|
+ [path setLineWidth:2.0];
|
|
|
+ [[NSColor blackColor] setStroke];
|
|
|
+ [path stroke];
|
|
|
+ return YES;
|
|
|
+ }];
|
|
|
+ [startLineStyleButton setImage:image forSegment:kPDFLineStyleCircle];
|
|
|
+
|
|
|
+ image = [NSImage imageWithSize:size drawingHandler:^(NSRect rect){
|
|
|
+ NSBezierPath *path = [NSBezierPath bezierPath];
|
|
|
+ [path moveToPoint:NSMakePoint(4.0, 6.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(16.0, 6.0)];
|
|
|
+ [path appendBezierPathWithOvalInRect:NSMakeRect(13.0, 3.0, 6.0, 6.0)];
|
|
|
+ [path setLineWidth:2.0];
|
|
|
+ [[NSColor blackColor] setStroke];
|
|
|
+ [path stroke];
|
|
|
+ return YES;
|
|
|
+ }];
|
|
|
+ [endLineStyleButton setImage:image forSegment:kPDFLineStyleCircle];
|
|
|
+
|
|
|
+ image = [NSImage imageWithSize:size drawingHandler:^(NSRect rect){
|
|
|
+ NSBezierPath *path = [NSBezierPath bezierPath];
|
|
|
+ [path moveToPoint:NSMakePoint(20.0, 6.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(8.0, 6.0)];
|
|
|
+ [path moveToPoint:NSMakePoint(12.0, 6.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(8.0, 10.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(4.0, 6.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(8.0, 2.0)];
|
|
|
+ [path closePath];
|
|
|
+ [path setLineWidth:2.0];
|
|
|
+ [path stroke];
|
|
|
+ return YES;
|
|
|
+ }];
|
|
|
+ [startLineStyleButton setImage:image forSegment:kPDFLineStyleDiamond];
|
|
|
+
|
|
|
+ image = [NSImage imageWithSize:size drawingHandler:^(NSRect rect){
|
|
|
+ NSBezierPath *path = [NSBezierPath bezierPath];
|
|
|
+ [path moveToPoint:NSMakePoint(4.0, 6.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(16.0, 6.0)];
|
|
|
+ [path moveToPoint:NSMakePoint(12.0, 6.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(16.0, 10.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(20.0, 6.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(16.0, 2.0)];
|
|
|
+ [path closePath];
|
|
|
+ [path setLineWidth:2.0];
|
|
|
+ [path stroke];
|
|
|
+ return YES;
|
|
|
+ }];
|
|
|
+ [endLineStyleButton setImage:image forSegment:kPDFLineStyleDiamond];
|
|
|
+
|
|
|
+ image = [NSImage imageWithSize:size drawingHandler:^(NSRect rect){
|
|
|
+ NSBezierPath *path = [NSBezierPath bezierPath];
|
|
|
+ [path moveToPoint:NSMakePoint(20.0, 6.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(8.0, 6.0)];
|
|
|
+ [path moveToPoint:NSMakePoint(14.0, 3.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(8.0, 6.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(14.0, 9.0)];
|
|
|
+ [path setLineWidth:2.0];
|
|
|
+ [[NSColor blackColor] setStroke];
|
|
|
+ [path stroke];
|
|
|
+ return YES;
|
|
|
+ }];
|
|
|
+ [startLineStyleButton setImage:image forSegment:kPDFLineStyleOpenArrow];
|
|
|
+
|
|
|
+ image = [NSImage imageWithSize:size drawingHandler:^(NSRect rect){
|
|
|
+ NSBezierPath *path = [NSBezierPath bezierPath];
|
|
|
+ [path moveToPoint:NSMakePoint(4.0, 6.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(16.0, 6.0)];
|
|
|
+ [path moveToPoint:NSMakePoint(10.0, 3.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(16.0, 6.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(10.0, 9.0)];
|
|
|
+ [path setLineWidth:2.0];
|
|
|
+ [[NSColor blackColor] setStroke];
|
|
|
+ [path stroke];
|
|
|
+ return YES;
|
|
|
+ }];
|
|
|
+ [endLineStyleButton setImage:image forSegment:kPDFLineStyleOpenArrow];
|
|
|
+
|
|
|
+ image = [NSImage imageWithSize:size drawingHandler:^(NSRect rect){
|
|
|
+ NSBezierPath *path = [NSBezierPath bezierPath];
|
|
|
+ [path moveToPoint:NSMakePoint(20.0, 6.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(8.0, 6.0)];
|
|
|
+ [path moveToPoint:NSMakePoint(14.0, 3.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(8.0, 6.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(14.0, 9.0)];
|
|
|
+ [path closePath];
|
|
|
+ [path setLineWidth:2.0];
|
|
|
+ [[NSColor blackColor] setStroke];
|
|
|
+ [path stroke];
|
|
|
+ return YES;
|
|
|
+ }];
|
|
|
+ [startLineStyleButton setImage:image forSegment:kPDFLineStyleClosedArrow];
|
|
|
+
|
|
|
+ image = [NSImage imageWithSize:size drawingHandler:^(NSRect rect){
|
|
|
+ NSBezierPath *path = [NSBezierPath bezierPath];
|
|
|
+ [path moveToPoint:NSMakePoint(4.0, 6.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(16.0, 6.0)];
|
|
|
+ [path moveToPoint:NSMakePoint(10.0, 3.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(16.0, 6.0)];
|
|
|
+ [path lineToPoint:NSMakePoint(10.0, 9.0)];
|
|
|
+ [path closePath];
|
|
|
+ [path setLineWidth:2.0];
|
|
|
+ [[NSColor blackColor] setStroke];
|
|
|
+ [path stroke];
|
|
|
+ return YES;
|
|
|
+ }];
|
|
|
+ [endLineStyleButton setImage:image forSegment:kPDFLineStyleClosedArrow];
|
|
|
+ }
|
|
|
+
|
|
|
+ - (void)notifyChangeAction:(SKLineChangeAction)action {
|
|
|
+ currentLineChangeAction = action;
|
|
|
+
|
|
|
+ SEL selector = @selector(changeLineAttribute:);
|
|
|
+ NSWindow *mainWindow = [NSApp mainWindow];
|
|
|
+ NSResponder *responder = [mainWindow firstResponder];
|
|
|
+
|
|
|
+ while (responder && [responder respondsToSelector:selector] == NO)
|
|
|
+ responder = [responder nextResponder];
|
|
|
+
|
|
|
+ [responder performSelector:selector withObject:self];
|
|
|
+
|
|
|
+ NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInteger:action], ACTION_KEY, nil];
|
|
|
+ [[NSNotificationCenter defaultCenter] postNotificationName:SKLineInspectorLineAttributeDidChangeNotification object:self userInfo:userInfo];
|
|
|
+
|
|
|
+ currentLineChangeAction = SKNoLineChangeAction;
|
|
|
+ }
|
|
|
+
|
|
|
+ #pragma mark Accessors
|
|
|
+
|
|
|
+ - (void)setLineWidth:(CGFloat)width {
|
|
|
+ if (fabs(lineWidth - width) > 0.00001) {
|
|
|
+ lineWidth = width;
|
|
|
+ [self notifyChangeAction:SKLineChangeActionLineWidth];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ - (void)setStyle:(PDFBorderStyle)newStyle {
|
|
|
+ if (newStyle != style) {
|
|
|
+ style = newStyle;
|
|
|
+ [self notifyChangeAction:SKLineChangeActionStyle];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ - (void)setDashPattern:(NSArray *)pattern {
|
|
|
+ if ([pattern isEqualToArray:dashPattern] == NO && (pattern || dashPattern)) {
|
|
|
+ [dashPattern release];
|
|
|
+ dashPattern = [pattern copy];
|
|
|
+ [self notifyChangeAction:SKLineChangeActionDashPattern];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ - (void)setStartLineStyle:(PDFLineStyle)newStyle {
|
|
|
+ if (newStyle != startLineStyle) {
|
|
|
+ startLineStyle = newStyle;
|
|
|
+ [self notifyChangeAction:SKLineChangeActionStartLineStyle];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ - (void)setEndLineStyle:(PDFLineStyle)newStyle {
|
|
|
+ if (newStyle != endLineStyle) {
|
|
|
+ endLineStyle = newStyle;
|
|
|
+ [self notifyChangeAction:SKLineChangeActionEndLineStyle];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ - (void)setAnnotationStyle:(PDFAnnotation *)annotation {
|
|
|
+ NSString *type = [annotation type];
|
|
|
+ if ([type isEqualToString:SKNFreeTextString] || [type isEqualToString:SKNCircleString] || [type isEqualToString:SKNSquareString] || [type isEqualToString:SKNLineString] || [type isEqualToString:SKNInkString]) {
|
|
|
+ [self setLineWidth:[annotation border] ? [[annotation border] lineWidth] : 0.0];
|
|
|
+ [self setDashPattern:[[annotation border] dashPattern]];
|
|
|
+ [self setStyle:[annotation border] ? [[annotation border] style] : 0];
|
|
|
+ }
|
|
|
+ if ([type isEqualToString:SKNLineString]) {
|
|
|
+ [self setStartLineStyle:[(PDFAnnotationLine *)annotation startLineStyle]];
|
|
|
+ [self setEndLineStyle:[(PDFAnnotationLine *)annotation endLineStyle]];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ - (void)setNilValueForKey:(NSString *)key {
|
|
|
+ if ([key isEqualToString:LINEWIDTH_KEY]) {
|
|
|
+ [self setValue:[NSNumber numberWithDouble:0.0] forKey:key];
|
|
|
+ } else if ([key isEqualToString:STYLE_KEY] || [key isEqualToString:STARTLINESTYLE_KEY] || [key isEqualToString:ENDLINESTYLE_KEY]) {
|
|
|
+ [self setValue:[NSNumber numberWithInteger:0] forKey:key];
|
|
|
+ } else {
|
|
|
+ [super setNilValueForKey:key];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ */
|
|
|
+
|
|
|
+}
|