KMLineInspector.swift 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. //
  2. // KMLineInspector.swift
  3. // PDF Master
  4. //
  5. // Created by tangchao on 2023/11/10.
  6. //
  7. import Cocoa
  8. class KMLineInspector: NSWindowController {
  9. /*
  10. extern NSString *SKLineInspectorLineAttributeDidChangeNotification;
  11. typedef NS_ENUM(NSUInteger, SKLineChangeAction) {
  12. SKNoLineChangeAction,
  13. SKLineChangeActionLineWidth,
  14. SKLineChangeActionStyle,
  15. SKLineChangeActionDashPattern,
  16. SKLineChangeActionStartLineStyle,
  17. SKLineChangeActionEndLineStyle
  18. };
  19. @class SKLineWell;
  20. @interface SKLineInspector : SKWindowController {
  21. NSSlider *lineWidthSlider;
  22. NSTextField *lineWidthField;
  23. NSSegmentedControl *styleButton;
  24. NSTextField *dashPatternField;
  25. NSSegmentedControl *startLineStyleButton;
  26. NSSegmentedControl *endLineStyleButton;
  27. SKLineWell *lineWell;
  28. NSTextField *lineWidthLabelField;
  29. NSTextField *styleLabelField;
  30. NSTextField *dashPatternLabelField;
  31. NSTextField *startLineStyleLabelField;
  32. NSTextField *endLineStyleLabelField;
  33. NSArray *labelFields;
  34. CGFloat lineWidth;
  35. PDFBorderStyle style;
  36. NSArray *dashPattern;
  37. PDFLineStyle startLineStyle;
  38. PDFLineStyle endLineStyle;
  39. SKLineChangeAction currentLineChangeAction;
  40. }
  41. @property (nonatomic, retain) IBOutlet NSArray *labelFields;
  42. @property (nonatomic) CGFloat lineWidth;
  43. @property (nonatomic) PDFBorderStyle style;
  44. @property (nonatomic, copy) NSArray *dashPattern;
  45. @property (nonatomic) PDFLineStyle startLineStyle, endLineStyle;
  46. @property (nonatomic, readonly) SKLineChangeAction currentLineChangeAction;
  47. + (id)sharedLineInspector;
  48. + (BOOL)sharedLineInspectorExists;
  49. - (void)setAnnotationStyle:(PDFAnnotation *)annotation;
  50. */
  51. @IBOutlet var lineWidthSlider: NSSlider!
  52. @IBOutlet var lineWidthField: NSTextField!
  53. @IBOutlet var dashPatternField: NSTextField!
  54. @IBOutlet var styleButton: NSSegmentedControl!
  55. @IBOutlet var startLineStyleButton: NSSegmentedControl!
  56. @IBOutlet var endLineStyleButton: NSSegmentedControl!
  57. @IBOutlet var lineWidthLabelField: NSTextField!
  58. @IBOutlet var styleLabelField: NSTextField!
  59. @IBOutlet var dashPatternLabelField: NSTextField!
  60. @IBOutlet var startLineStyleLabelField: NSTextField!
  61. @IBOutlet var endLineStyleLabelField: NSTextField!
  62. @IBOutlet var lineWell: KMLineWell!
  63. @IBOutlet weak var labelField1: NSTextField!
  64. @IBOutlet weak var labelField2: NSTextField!
  65. @IBOutlet weak var labelField3: NSTextField!
  66. @IBOutlet weak var labelField4: NSTextField!
  67. @IBOutlet weak var labelField5: NSTextField!
  68. var lineWidth: CGFloat = 0
  69. // var style: CPDFBorderStyle = .solid
  70. var style: Int = CPDFBorderStyle.solid.rawValue
  71. // var startLineStyle: CPDFLineStyle = .none
  72. var startLineStyle: Int = CPDFLineStyle.none.rawValue
  73. // var endLineStyle: CPDFLineStyle = .none
  74. var endLineStyle: Int = CPDFLineStyle.none.rawValue
  75. var dashPattern: [CGFloat] = []
  76. static let shared = KMLineInspector(windowNibName: "LineInspector")
  77. override func windowDidLoad() {
  78. super.windowDidLoad()
  79. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
  80. }
  81. /*
  82. SString *SKLineInspectorLineAttributeDidChangeNotification = @"SKLineInspectorLineAttributeDidChangeNotification";
  83. #define LINEWIDTH_KEY @"lineWidth"
  84. #define STYLE_KEY @"style"
  85. #define DASHPATTERN_KEY @"dashPattern"
  86. #define STARTLINESTYLE_KEY @"startLineStyle"
  87. #define ENDLINESTYLE_KEY @"endLineStyle"
  88. #define ACTION_KEY @"action"
  89. #define SKLineInspectorFrameAutosaveName @"SKLineInspector"
  90. @implementation SKLineInspector
  91. @synthesize lineWidthSlider, lineWidthField, dashPatternField, styleButton, startLineStyleButton, endLineStyleButton, lineWell, lineWidthLabelField, styleLabelField, dashPatternLabelField, startLineStyleLabelField, endLineStyleLabelField, labelFields, lineWidth, style, dashPattern, startLineStyle, endLineStyle, currentLineChangeAction;
  92. static SKLineInspector *sharedLineInspector = nil;
  93. + (id)sharedLineInspector {
  94. if (sharedLineInspector == nil)
  95. sharedLineInspector = [[self alloc] init];
  96. return sharedLineInspector;
  97. }
  98. + (BOOL)sharedLineInspectorExists {
  99. return sharedLineInspector != nil;
  100. }
  101. - (id)init {
  102. if (sharedLineInspector) NSLog(@"Attempt to allocate second instance of %@", [self class]);
  103. self = [super initWithWindowNibName:@"LineInspector"];
  104. if (self) {
  105. style = kPDFBorderStyleSolid;
  106. lineWidth = 1.0;
  107. dashPattern = nil;
  108. startLineStyle = kPDFLineStyleNone;
  109. endLineStyle = kPDFLineStyleNone;
  110. currentLineChangeAction = SKNoLineChangeAction;
  111. }
  112. return self;
  113. }
  114. - (void)dealloc {
  115. SKDESTROY(dashPattern);
  116. SKDESTROY(lineWidthSlider);
  117. SKDESTROY(lineWidthField);
  118. SKDESTROY(dashPatternField);
  119. SKDESTROY(styleButton);
  120. SKDESTROY(startLineStyleButton);
  121. SKDESTROY(endLineStyleButton);
  122. SKDESTROY(lineWell);
  123. SKDESTROY(lineWidthLabelField);
  124. SKDESTROY(styleLabelField);
  125. SKDESTROY(dashPatternLabelField);
  126. SKDESTROY(startLineStyleLabelField);
  127. SKDESTROY(endLineStyleLabelField);
  128. SKDESTROY(labelFields);
  129. [super dealloc];
  130. }
  131. - (void)windowDidLoad {
  132. [lineWell setCanActivate:NO];
  133. [lineWell bind:SKLineWellLineWidthKey toObject:self withKeyPath:LINEWIDTH_KEY options:nil];
  134. [lineWell bind:SKLineWellStyleKey toObject:self withKeyPath:STYLE_KEY options:nil];
  135. [lineWell bind:SKLineWellDashPatternKey toObject:self withKeyPath:DASHPATTERN_KEY options:nil];
  136. [lineWell bind:SKLineWellStartLineStyleKey toObject:self withKeyPath:STARTLINESTYLE_KEY options:nil];
  137. [lineWell bind:SKLineWellEndLineStyleKey toObject:self withKeyPath:ENDLINESTYLE_KEY options:nil];
  138. [styleButton setHelp:NSLocalizedString(@"Solid line style", @"Tool tip message") forSegment:kPDFBorderStyleSolid];
  139. [styleButton setHelp:NSLocalizedString(@"Dashed line style", @"Tool tip message") forSegment:kPDFBorderStyleDashed];
  140. [styleButton setHelp:NSLocalizedString(@"Beveled line style", @"Tool tip message") forSegment:kPDFBorderStyleBeveled];
  141. [styleButton setHelp:NSLocalizedString(@"Inset line style", @"Tool tip message") forSegment:kPDFBorderStyleInset];
  142. [styleButton setHelp:NSLocalizedString(@"Underline line style", @"Tool tip message") forSegment:kPDFBorderStyleUnderline];
  143. [startLineStyleButton setHelp:NSLocalizedString(@"No start line style", @"Tool tip message") forSegment:kPDFLineStyleNone];
  144. [startLineStyleButton setHelp:NSLocalizedString(@"Square start line style", @"Tool tip message") forSegment:kPDFLineStyleSquare];
  145. [startLineStyleButton setHelp:NSLocalizedString(@"Circle start line style", @"Tool tip message") forSegment:kPDFLineStyleCircle];
  146. [startLineStyleButton setHelp:NSLocalizedString(@"Diamond start line style", @"Tool tip message") forSegment:kPDFLineStyleDiamond];
  147. [startLineStyleButton setHelp:NSLocalizedString(@"Open arrow start line style", @"Tool tip message") forSegment:kPDFLineStyleOpenArrow];
  148. [startLineStyleButton setHelp:NSLocalizedString(@"Closed arrow start line style", @"Tool tip message") forSegment:kPDFLineStyleClosedArrow];
  149. [endLineStyleButton setHelp:NSLocalizedString(@"No end line style", @"Tool tip message") forSegment:kPDFLineStyleNone];
  150. [endLineStyleButton setHelp:NSLocalizedString(@"Square end line style", @"Tool tip message") forSegment:kPDFLineStyleSquare];
  151. [endLineStyleButton setHelp:NSLocalizedString(@"Circle end line style", @"Tool tip message") forSegment:kPDFLineStyleCircle];
  152. [endLineStyleButton setHelp:NSLocalizedString(@"Diamond end line style", @"Tool tip message") forSegment:kPDFLineStyleDiamond];
  153. [endLineStyleButton setHelp:NSLocalizedString(@"Open arrow end line style", @"Tool tip message") forSegment:kPDFLineStyleOpenArrow];
  154. [endLineStyleButton setHelp:NSLocalizedString(@"Closed arrow end line style", @"Tool tip message") forSegment:kPDFLineStyleClosedArrow];
  155. CGFloat dw = SKAutoSizeLabelFields(labelFields, [NSArray arrayWithObjects:lineWidthSlider, lineWidthField, styleButton, dashPatternField, startLineStyleButton, endLineStyleButton, nil], NO);
  156. if (fabs(dw) > 0.0)
  157. SKResizeWindow([self window], dw);
  158. [self setWindowFrameAutosaveName:SKLineInspectorFrameAutosaveName];
  159. NSImage *image = nil;
  160. NSSize size = NSMakeSize(29.0, 12.0);
  161. image = [NSImage imageWithSize:size drawingHandler:^(NSRect rect){
  162. NSBezierPath *path = [NSBezierPath bezierPathWithRect:NSMakeRect(6.0, 3.0, 17.0, 6.0)];
  163. [path setLineWidth:2.0];
  164. [[NSColor blackColor] setStroke];
  165. [path stroke];
  166. return YES;
  167. }];
  168. [styleButton setImage:image forSegment:kPDFBorderStyleSolid];
  169. image = [NSImage imageWithSize:size drawingHandler:^(NSRect rect){
  170. NSBezierPath *path = [NSBezierPath bezierPath];
  171. [path moveToPoint:NSMakePoint(6.0, 5.0)];
  172. [path lineToPoint:NSMakePoint(6.0, 3.0)];
  173. [path lineToPoint:NSMakePoint(9.0, 3.0)];
  174. [path moveToPoint:NSMakePoint(12.0, 3.0)];
  175. [path lineToPoint:NSMakePoint(17.0, 3.0)];
  176. [path moveToPoint:NSMakePoint(20.0, 3.0)];
  177. [path lineToPoint:NSMakePoint(23.0, 3.0)];
  178. [path lineToPoint:NSMakePoint(23.0, 5.0)];
  179. [path moveToPoint:NSMakePoint(23.0, 7.0)];
  180. [path lineToPoint:NSMakePoint(23.0, 9.0)];
  181. [path lineToPoint:NSMakePoint(20.0, 9.0)];
  182. [path moveToPoint:NSMakePoint(17.0, 9.0)];
  183. [path lineToPoint:NSMakePoint(12.0, 9.0)];
  184. [path moveToPoint:NSMakePoint(9.0, 9.0)];
  185. [path lineToPoint:NSMakePoint(6.0, 9.0)];
  186. [path lineToPoint:NSMakePoint(6.0, 7.0)];
  187. [path setLineWidth:2.0];
  188. [[NSColor blackColor] setStroke];
  189. [path stroke];
  190. return YES;
  191. }];
  192. [styleButton setImage:image forSegment:kPDFBorderStyleDashed];
  193. image = [NSImage imageWithSize:size drawingHandler:^(NSRect rect){
  194. NSBezierPath *path = [NSBezierPath bezierPathWithRect:NSMakeRect(6.0, 3.0, 17.0, 6.0)];
  195. [path setLineWidth:2.0];
  196. [[NSColor colorWithCalibratedWhite:0.0 alpha:0.25] setStroke];
  197. [path stroke];
  198. path = [NSBezierPath bezierPath];
  199. [path moveToPoint:NSMakePoint(7.0, 3.0)];
  200. [path lineToPoint:NSMakePoint(23.0, 3.0)];
  201. [path lineToPoint:NSMakePoint(23.0, 8.0)];
  202. [path setLineWidth:2.0];
  203. [[NSColor colorWithCalibratedWhite:0.0 alpha:0.35] set];
  204. [path stroke];
  205. path = [NSBezierPath bezierPath];
  206. [path moveToPoint:NSMakePoint(5.0, 2.0)];
  207. [path lineToPoint:NSMakePoint(7.0, 4.0)];
  208. [path lineToPoint:NSMakePoint(7.0, 2.0)];
  209. [path closePath];
  210. [path moveToPoint:NSMakePoint(24.0, 10.0)];
  211. [path lineToPoint:NSMakePoint(22.0, 8.0)];
  212. [path lineToPoint:NSMakePoint(24.0, 8.0)];
  213. [path closePath];
  214. [path fill];
  215. return YES;
  216. }];
  217. [styleButton setImage:image forSegment:kPDFBorderStyleBeveled];
  218. image = [NSImage imageWithSize:size drawingHandler:^(NSRect rect){
  219. NSBezierPath *path = [NSBezierPath bezierPathWithRect:NSMakeRect(6.0, 3.0, 17.0, 6.0)];
  220. [path setLineWidth:2.0];
  221. [[NSColor colorWithCalibratedWhite:0.0 alpha:0.25] setStroke];
  222. [path stroke];
  223. path = [NSBezierPath bezierPath];
  224. [path moveToPoint:NSMakePoint(6.0, 4.0)];
  225. [path lineToPoint:NSMakePoint(6.0, 9.0)];
  226. [path lineToPoint:NSMakePoint(22.0, 9.0)];
  227. [path setLineWidth:2.0];
  228. [[NSColor colorWithCalibratedWhite:0.0 alpha:0.35] set];
  229. [path stroke];
  230. path = [NSBezierPath bezierPath];
  231. [path moveToPoint:NSMakePoint(5.0, 2.0)];
  232. [path lineToPoint:NSMakePoint(7.0, 4.0)];
  233. [path lineToPoint:NSMakePoint(5.0, 4.0)];
  234. [path closePath];
  235. [path moveToPoint:NSMakePoint(24.0, 10.0)];
  236. [path lineToPoint:NSMakePoint(22.0, 8.0)];
  237. [path lineToPoint:NSMakePoint(22.0, 10.0)];
  238. [path closePath];
  239. [path fill];
  240. return YES;
  241. }];
  242. [styleButton setImage:image forSegment:kPDFBorderStyleInset];
  243. image = [NSImage imageWithSize:size drawingHandler:^(NSRect rect){
  244. NSBezierPath *path = [NSBezierPath bezierPath];
  245. [path moveToPoint:NSMakePoint(6.0, 3.0)];
  246. [path lineToPoint:NSMakePoint(23.0, 3.0)];
  247. [path setLineWidth:2.0];
  248. [[NSColor colorWithCalibratedWhite:0.0 alpha:0.5] setStroke];
  249. [path stroke];
  250. return YES;
  251. }];
  252. [styleButton setImage:image forSegment:kPDFBorderStyleUnderline];
  253. size = NSMakeSize(24.0, 12.0);
  254. image = [NSImage imageWithSize:size drawingHandler:^(NSRect rect){
  255. NSBezierPath *path = [NSBezierPath bezierPath];
  256. [path moveToPoint:NSMakePoint(20.0, 6.0)];
  257. [path lineToPoint:NSMakePoint(8.0, 6.0)];
  258. [path setLineWidth:2.0];
  259. [[NSColor blackColor] setStroke];
  260. [path stroke];
  261. return YES;
  262. }];
  263. [startLineStyleButton setImage:image forSegment:kPDFLineStyleNone];
  264. image = [NSImage imageWithSize:size drawingHandler:^(NSRect rect){
  265. NSBezierPath *path = [NSBezierPath bezierPath];
  266. [path moveToPoint:NSMakePoint(4.0, 6.0)];
  267. [path lineToPoint:NSMakePoint(16.0, 6.0)];
  268. [path setLineWidth:2.0];
  269. [[NSColor blackColor] setStroke];
  270. [path stroke];
  271. return YES;
  272. }];
  273. [endLineStyleButton setImage:image forSegment:kPDFLineStyleNone];
  274. image = [NSImage imageWithSize:size drawingHandler:^(NSRect rect){
  275. NSBezierPath *path = [NSBezierPath bezierPath];
  276. [path moveToPoint:NSMakePoint(20.0, 6.0)];
  277. [path lineToPoint:NSMakePoint(8.0, 6.0)];
  278. [path appendBezierPathWithRect:NSMakeRect(5.0, 3.0, 6.0, 6.0)];
  279. [path setLineWidth:2.0];
  280. [[NSColor blackColor] setStroke];
  281. [path stroke];
  282. return YES;
  283. }];
  284. [startLineStyleButton setImage:image forSegment:kPDFLineStyleSquare];
  285. image = [NSImage imageWithSize:size drawingHandler:^(NSRect rect){
  286. NSBezierPath *path = [NSBezierPath bezierPath];
  287. [path moveToPoint:NSMakePoint(4.0, 6.0)];
  288. [path lineToPoint:NSMakePoint(16.0, 6.0)];
  289. [path appendBezierPathWithRect:NSMakeRect(13.0, 3.0, 6.0, 6.0)];
  290. [path setLineWidth:2.0];
  291. [[NSColor blackColor] setStroke];
  292. [path stroke];
  293. return YES;
  294. }];
  295. [endLineStyleButton setImage:image forSegment:kPDFLineStyleSquare];
  296. image = [NSImage imageWithSize:size drawingHandler:^(NSRect rect){
  297. NSBezierPath *path = [NSBezierPath bezierPath];
  298. [path moveToPoint:NSMakePoint(20.0, 6.0)];
  299. [path lineToPoint:NSMakePoint(8.0, 6.0)];
  300. [path appendBezierPathWithOvalInRect:NSMakeRect(5.0, 3.0, 6.0, 6.0)];
  301. [path setLineWidth:2.0];
  302. [[NSColor blackColor] setStroke];
  303. [path stroke];
  304. return YES;
  305. }];
  306. [startLineStyleButton setImage:image forSegment:kPDFLineStyleCircle];
  307. image = [NSImage imageWithSize:size drawingHandler:^(NSRect rect){
  308. NSBezierPath *path = [NSBezierPath bezierPath];
  309. [path moveToPoint:NSMakePoint(4.0, 6.0)];
  310. [path lineToPoint:NSMakePoint(16.0, 6.0)];
  311. [path appendBezierPathWithOvalInRect:NSMakeRect(13.0, 3.0, 6.0, 6.0)];
  312. [path setLineWidth:2.0];
  313. [[NSColor blackColor] setStroke];
  314. [path stroke];
  315. return YES;
  316. }];
  317. [endLineStyleButton setImage:image forSegment:kPDFLineStyleCircle];
  318. image = [NSImage imageWithSize:size drawingHandler:^(NSRect rect){
  319. NSBezierPath *path = [NSBezierPath bezierPath];
  320. [path moveToPoint:NSMakePoint(20.0, 6.0)];
  321. [path lineToPoint:NSMakePoint(8.0, 6.0)];
  322. [path moveToPoint:NSMakePoint(12.0, 6.0)];
  323. [path lineToPoint:NSMakePoint(8.0, 10.0)];
  324. [path lineToPoint:NSMakePoint(4.0, 6.0)];
  325. [path lineToPoint:NSMakePoint(8.0, 2.0)];
  326. [path closePath];
  327. [path setLineWidth:2.0];
  328. [path stroke];
  329. return YES;
  330. }];
  331. [startLineStyleButton setImage:image forSegment:kPDFLineStyleDiamond];
  332. image = [NSImage imageWithSize:size drawingHandler:^(NSRect rect){
  333. NSBezierPath *path = [NSBezierPath bezierPath];
  334. [path moveToPoint:NSMakePoint(4.0, 6.0)];
  335. [path lineToPoint:NSMakePoint(16.0, 6.0)];
  336. [path moveToPoint:NSMakePoint(12.0, 6.0)];
  337. [path lineToPoint:NSMakePoint(16.0, 10.0)];
  338. [path lineToPoint:NSMakePoint(20.0, 6.0)];
  339. [path lineToPoint:NSMakePoint(16.0, 2.0)];
  340. [path closePath];
  341. [path setLineWidth:2.0];
  342. [path stroke];
  343. return YES;
  344. }];
  345. [endLineStyleButton setImage:image forSegment:kPDFLineStyleDiamond];
  346. image = [NSImage imageWithSize:size drawingHandler:^(NSRect rect){
  347. NSBezierPath *path = [NSBezierPath bezierPath];
  348. [path moveToPoint:NSMakePoint(20.0, 6.0)];
  349. [path lineToPoint:NSMakePoint(8.0, 6.0)];
  350. [path moveToPoint:NSMakePoint(14.0, 3.0)];
  351. [path lineToPoint:NSMakePoint(8.0, 6.0)];
  352. [path lineToPoint:NSMakePoint(14.0, 9.0)];
  353. [path setLineWidth:2.0];
  354. [[NSColor blackColor] setStroke];
  355. [path stroke];
  356. return YES;
  357. }];
  358. [startLineStyleButton setImage:image forSegment:kPDFLineStyleOpenArrow];
  359. image = [NSImage imageWithSize:size drawingHandler:^(NSRect rect){
  360. NSBezierPath *path = [NSBezierPath bezierPath];
  361. [path moveToPoint:NSMakePoint(4.0, 6.0)];
  362. [path lineToPoint:NSMakePoint(16.0, 6.0)];
  363. [path moveToPoint:NSMakePoint(10.0, 3.0)];
  364. [path lineToPoint:NSMakePoint(16.0, 6.0)];
  365. [path lineToPoint:NSMakePoint(10.0, 9.0)];
  366. [path setLineWidth:2.0];
  367. [[NSColor blackColor] setStroke];
  368. [path stroke];
  369. return YES;
  370. }];
  371. [endLineStyleButton setImage:image forSegment:kPDFLineStyleOpenArrow];
  372. image = [NSImage imageWithSize:size drawingHandler:^(NSRect rect){
  373. NSBezierPath *path = [NSBezierPath bezierPath];
  374. [path moveToPoint:NSMakePoint(20.0, 6.0)];
  375. [path lineToPoint:NSMakePoint(8.0, 6.0)];
  376. [path moveToPoint:NSMakePoint(14.0, 3.0)];
  377. [path lineToPoint:NSMakePoint(8.0, 6.0)];
  378. [path lineToPoint:NSMakePoint(14.0, 9.0)];
  379. [path closePath];
  380. [path setLineWidth:2.0];
  381. [[NSColor blackColor] setStroke];
  382. [path stroke];
  383. return YES;
  384. }];
  385. [startLineStyleButton setImage:image forSegment:kPDFLineStyleClosedArrow];
  386. image = [NSImage imageWithSize:size drawingHandler:^(NSRect rect){
  387. NSBezierPath *path = [NSBezierPath bezierPath];
  388. [path moveToPoint:NSMakePoint(4.0, 6.0)];
  389. [path lineToPoint:NSMakePoint(16.0, 6.0)];
  390. [path moveToPoint:NSMakePoint(10.0, 3.0)];
  391. [path lineToPoint:NSMakePoint(16.0, 6.0)];
  392. [path lineToPoint:NSMakePoint(10.0, 9.0)];
  393. [path closePath];
  394. [path setLineWidth:2.0];
  395. [[NSColor blackColor] setStroke];
  396. [path stroke];
  397. return YES;
  398. }];
  399. [endLineStyleButton setImage:image forSegment:kPDFLineStyleClosedArrow];
  400. }
  401. - (void)notifyChangeAction:(SKLineChangeAction)action {
  402. currentLineChangeAction = action;
  403. SEL selector = @selector(changeLineAttribute:);
  404. NSWindow *mainWindow = [NSApp mainWindow];
  405. NSResponder *responder = [mainWindow firstResponder];
  406. while (responder && [responder respondsToSelector:selector] == NO)
  407. responder = [responder nextResponder];
  408. [responder performSelector:selector withObject:self];
  409. NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInteger:action], ACTION_KEY, nil];
  410. [[NSNotificationCenter defaultCenter] postNotificationName:SKLineInspectorLineAttributeDidChangeNotification object:self userInfo:userInfo];
  411. currentLineChangeAction = SKNoLineChangeAction;
  412. }
  413. #pragma mark Accessors
  414. - (void)setLineWidth:(CGFloat)width {
  415. if (fabs(lineWidth - width) > 0.00001) {
  416. lineWidth = width;
  417. [self notifyChangeAction:SKLineChangeActionLineWidth];
  418. }
  419. }
  420. - (void)setStyle:(PDFBorderStyle)newStyle {
  421. if (newStyle != style) {
  422. style = newStyle;
  423. [self notifyChangeAction:SKLineChangeActionStyle];
  424. }
  425. }
  426. - (void)setDashPattern:(NSArray *)pattern {
  427. if ([pattern isEqualToArray:dashPattern] == NO && (pattern || dashPattern)) {
  428. [dashPattern release];
  429. dashPattern = [pattern copy];
  430. [self notifyChangeAction:SKLineChangeActionDashPattern];
  431. }
  432. }
  433. - (void)setStartLineStyle:(PDFLineStyle)newStyle {
  434. if (newStyle != startLineStyle) {
  435. startLineStyle = newStyle;
  436. [self notifyChangeAction:SKLineChangeActionStartLineStyle];
  437. }
  438. }
  439. - (void)setEndLineStyle:(PDFLineStyle)newStyle {
  440. if (newStyle != endLineStyle) {
  441. endLineStyle = newStyle;
  442. [self notifyChangeAction:SKLineChangeActionEndLineStyle];
  443. }
  444. }
  445. - (void)setAnnotationStyle:(PDFAnnotation *)annotation {
  446. NSString *type = [annotation type];
  447. if ([type isEqualToString:SKNFreeTextString] || [type isEqualToString:SKNCircleString] || [type isEqualToString:SKNSquareString] || [type isEqualToString:SKNLineString] || [type isEqualToString:SKNInkString]) {
  448. [self setLineWidth:[annotation border] ? [[annotation border] lineWidth] : 0.0];
  449. [self setDashPattern:[[annotation border] dashPattern]];
  450. [self setStyle:[annotation border] ? [[annotation border] style] : 0];
  451. }
  452. if ([type isEqualToString:SKNLineString]) {
  453. [self setStartLineStyle:[(PDFAnnotationLine *)annotation startLineStyle]];
  454. [self setEndLineStyle:[(PDFAnnotationLine *)annotation endLineStyle]];
  455. }
  456. }
  457. - (void)setNilValueForKey:(NSString *)key {
  458. if ([key isEqualToString:LINEWIDTH_KEY]) {
  459. [self setValue:[NSNumber numberWithDouble:0.0] forKey:key];
  460. } else if ([key isEqualToString:STYLE_KEY] || [key isEqualToString:STARTLINESTYLE_KEY] || [key isEqualToString:ENDLINESTYLE_KEY]) {
  461. [self setValue:[NSNumber numberWithInteger:0] forKey:key];
  462. } else {
  463. [super setNilValueForKey:key];
  464. }
  465. }
  466. */
  467. // override class func value(forUndefinedKey key: String) -> Any? {
  468. // KMPrint("forUndefinedKey: \(key)")
  469. // }
  470. override func value(forUndefinedKey key: String) -> Any? {
  471. KMPrint("forUndefinedKey: \(key)")
  472. }
  473. }