KMLineInspector.swift 24 KB

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