AnnotToolContentViewModel.Function.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKitViewer;
  3. using ComPDFKitViewer.AnnotEvent;
  4. using Microsoft.Win32;
  5. using PDF_Office.CustomControl;
  6. using PDF_Office.Helper;
  7. using PDF_Office.Properties;
  8. using PDFSettings;
  9. using Prism.Mvvm;
  10. using Prism.Regions;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. using System.Windows;
  17. using System.Windows.Media;
  18. namespace PDF_Office.ViewModels.Tools
  19. {
  20. public sealed partial class AnnotToolContentViewModel : BindableBase, INavigationAware
  21. {
  22. #region 初始化
  23. private void BindingEvent()
  24. {
  25. propertyPanel.DataChanged += AnnotPropertyPanel_DataChanged;
  26. propertyPanel.DefaultStored += AnnotProperty_DefaultStored;
  27. propertyPanel.AnnotTypeChanged += AnnotPropertyPanel_AnnotTypeChanged;
  28. }
  29. private void InitDefaultValue()
  30. {
  31. InitAnnotHighlight();
  32. InitAnnotUnderline();
  33. InitAnnotSquiggly();
  34. InitAnnotStrikeout();
  35. }
  36. private void InitAnnotHighlight()
  37. {
  38. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotHighlight);
  39. if (annotProperty == null)
  40. {
  41. annotProperty = new DefaultAnnotProperty();
  42. annotProperty.AnnotToolType = AnnotArgsType.AnnotHighlight;
  43. annotProperty.BackgroundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
  44. annotProperty.ForgoundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
  45. annotProperty.Opacity = 0.5;
  46. SettingHelper.SetAnnotDefaultProperty(annotProperty);
  47. }
  48. else
  49. {
  50. HighLightColor = new SolidColorBrush(annotProperty.BackgroundColor);
  51. HighLightOpacity = annotProperty.Opacity;
  52. }
  53. }
  54. private void InitAnnotUnderline()
  55. {
  56. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotUnderline);
  57. if (annotProperty == null)
  58. {
  59. annotProperty = new DefaultAnnotProperty();
  60. annotProperty.AnnotToolType = AnnotArgsType.AnnotUnderline;
  61. annotProperty.BackgroundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
  62. annotProperty.ForgoundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
  63. annotProperty.Opacity = 0.5;
  64. SettingHelper.SetAnnotDefaultProperty(annotProperty);
  65. }
  66. else
  67. {
  68. UnderLineColor = new SolidColorBrush(annotProperty.BackgroundColor);
  69. UnderLineOpacity = annotProperty.Opacity;
  70. }
  71. }
  72. private void InitAnnotSquiggly()
  73. {
  74. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotSquiggly);
  75. if (annotProperty == null)
  76. {
  77. annotProperty = new DefaultAnnotProperty();
  78. annotProperty.AnnotToolType = AnnotArgsType.AnnotSquiggly;
  79. annotProperty.BackgroundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
  80. annotProperty.ForgoundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
  81. annotProperty.Opacity = 0.5;
  82. SettingHelper.SetAnnotDefaultProperty(annotProperty);
  83. }
  84. else
  85. {
  86. SquigglyColor = new SolidColorBrush(annotProperty.BackgroundColor);
  87. SquigglyOpacity = annotProperty.Opacity;
  88. }
  89. }
  90. private void InitAnnotStrikeout()
  91. {
  92. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotStrikeout);
  93. if (annotProperty == null)
  94. {
  95. annotProperty = new DefaultAnnotProperty();
  96. annotProperty.AnnotToolType = AnnotArgsType.AnnotStrikeout;
  97. annotProperty.BackgroundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
  98. annotProperty.ForgoundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
  99. annotProperty.Opacity = 0.5;
  100. SettingHelper.SetAnnotDefaultProperty(annotProperty);
  101. }
  102. else
  103. {
  104. StrikeoutColor = new SolidColorBrush(annotProperty.BackgroundColor);
  105. StrikeoutOpacity = annotProperty.Opacity;
  106. }
  107. }
  108. #endregion
  109. #region 注释工具
  110. /// <summary>
  111. /// 高亮注释
  112. /// </summary>
  113. /// <returns></returns>
  114. private AnnotHandlerEventArgs GetHighLight(TextHighlightAnnotArgs selectedhighlightArgs = null)
  115. {
  116. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  117. TextHighlightAnnotArgs highlightArgs = null;
  118. if(selectedhighlightArgs == null)
  119. {
  120. highlightArgs = new TextHighlightAnnotArgs();
  121. highlightArgs.Color = Color.FromRgb(0xFF, 0xBB, 0x00);
  122. highlightArgs.Transparency = 0.5;
  123. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotHighlight);
  124. if (annotProperty != null)
  125. {
  126. highlightArgs.Color = annotProperty.ForgoundColor;
  127. highlightArgs.Transparency = annotProperty.Opacity;
  128. highlightArgs.Content = annotProperty.NoteText;
  129. }
  130. }
  131. else
  132. {
  133. highlightArgs = selectedhighlightArgs;
  134. }
  135. annotAttribsList[AnnotAttrib.Color] = highlightArgs.Color;
  136. annotAttribsList[AnnotAttrib.Transparency] = highlightArgs.Transparency;
  137. annotAttribsList[AnnotAttrib.NoteText] = string.Empty;
  138. AddToPropertyPanel("TextAnnotProperty", "HighLight", highlightArgs, annotAttribsList);
  139. return highlightArgs;
  140. }
  141. private AnnotHandlerEventArgs GetUnderLine(TextUnderlineAnnotArgs selectedunderlineArgs = null)
  142. {
  143. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  144. TextUnderlineAnnotArgs underlineArgs = null;
  145. if (selectedunderlineArgs == null)
  146. {
  147. underlineArgs = new TextUnderlineAnnotArgs();
  148. underlineArgs.Color = Color.FromRgb(0x12, 0xFD, 0xFF);
  149. underlineArgs.Transparency = 1;
  150. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotUnderline);
  151. if (annotProperty != null)
  152. {
  153. underlineArgs.Color = annotProperty.ForgoundColor;
  154. underlineArgs.Transparency = annotProperty.Opacity;
  155. underlineArgs.Content = annotProperty.NoteText;
  156. }
  157. }
  158. else
  159. {
  160. underlineArgs = selectedunderlineArgs;
  161. }
  162. annotAttribsList[AnnotAttrib.Color] = underlineArgs.Color;
  163. annotAttribsList[AnnotAttrib.Transparency] = underlineArgs.Transparency;
  164. annotAttribsList[AnnotAttrib.NoteText] = string.Empty;
  165. AddToPropertyPanel("TextAnnotProperty", "UnderLine", underlineArgs, annotAttribsList);
  166. return underlineArgs;
  167. }
  168. private AnnotHandlerEventArgs GetSquiggly(TextSquigglyAnnotArgs selectedsquigglyArgs = null)
  169. {
  170. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  171. TextSquigglyAnnotArgs squigglyArgs = null;
  172. if (selectedsquigglyArgs == null)
  173. {
  174. squigglyArgs = new TextSquigglyAnnotArgs();
  175. squigglyArgs.Color = Color.FromRgb(0xFF, 0x87, 0x16);
  176. squigglyArgs.Transparency = 1;
  177. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotSquiggly);
  178. if (annotProperty != null)
  179. {
  180. squigglyArgs.Color = annotProperty.ForgoundColor;
  181. squigglyArgs.Transparency = annotProperty.Opacity;
  182. squigglyArgs.Content = annotProperty.NoteText;
  183. }
  184. }
  185. else
  186. {
  187. squigglyArgs = selectedsquigglyArgs;
  188. }
  189. annotAttribsList[AnnotAttrib.Color] = squigglyArgs.Color;
  190. annotAttribsList[AnnotAttrib.Transparency] = squigglyArgs.Transparency;
  191. annotAttribsList[AnnotAttrib.NoteText] = string.Empty;
  192. AddToPropertyPanel("TextAnnotProperty", "Squiggly", squigglyArgs, annotAttribsList);
  193. return squigglyArgs;
  194. }
  195. private AnnotHandlerEventArgs GetStrikeout(TextStrikeoutAnnotArgs selectedstrikeoutArgs = null)
  196. {
  197. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  198. TextStrikeoutAnnotArgs strikeoutArgs = null;
  199. if(selectedstrikeoutArgs == null)
  200. {
  201. strikeoutArgs = new TextStrikeoutAnnotArgs();
  202. strikeoutArgs.Color = Color.FromRgb(0xFF, 0x3B, 0x30);
  203. strikeoutArgs.Transparency = 1;
  204. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotStrikeout);
  205. if (annotProperty != null)
  206. {
  207. strikeoutArgs.Color = annotProperty.ForgoundColor;
  208. strikeoutArgs.Transparency = annotProperty.Opacity;
  209. strikeoutArgs.Content = annotProperty.NoteText;
  210. }
  211. }
  212. else
  213. {
  214. strikeoutArgs = selectedstrikeoutArgs;
  215. }
  216. annotAttribsList[AnnotAttrib.Color] = strikeoutArgs.Color;
  217. annotAttribsList[AnnotAttrib.Transparency] = strikeoutArgs.Transparency;
  218. annotAttribsList[AnnotAttrib.NoteText] = string.Empty;
  219. AddToPropertyPanel("TextAnnotProperty", "Strikeout", strikeoutArgs, annotAttribsList);
  220. return strikeoutArgs;
  221. }
  222. private AnnotHandlerEventArgs GetFreehand(FreehandAnnotArgs selectedfreehandArgs = null)
  223. {
  224. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  225. FreehandAnnotArgs freehandArgs = null;
  226. if(selectedfreehandArgs == null)
  227. {
  228. freehandArgs = new FreehandAnnotArgs();
  229. freehandArgs.InkColor = Color.FromRgb(0x38, 0xE0, 0x2E);
  230. freehandArgs.Transparency = 1;
  231. freehandArgs.LineWidth = 1;
  232. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotFreehand);
  233. if (annotProperty != null)
  234. {
  235. freehandArgs.InkColor = annotProperty.ForgoundColor;
  236. freehandArgs.Transparency = annotProperty.Opacity;
  237. freehandArgs.LineWidth = annotProperty.Thickness;
  238. freehandArgs.Content = annotProperty.NoteText;
  239. }
  240. }
  241. else
  242. {
  243. freehandArgs = selectedfreehandArgs;
  244. }
  245. annotAttribsList[AnnotAttrib.Color] = freehandArgs.InkColor;
  246. annotAttribsList[AnnotAttrib.Transparency] = freehandArgs.Transparency;
  247. annotAttribsList[AnnotAttrib.Thickness] = freehandArgs.LineWidth;
  248. annotAttribsList[AnnotAttrib.NoteText] = freehandArgs.Content;
  249. AddToPropertyPanel("FreehandAnnotProperty", "Freehand", freehandArgs, annotAttribsList);
  250. return freehandArgs;
  251. }
  252. private AnnotHandlerEventArgs GetFreetext(FreeTextAnnotArgs selectedfreetextArgs = null)
  253. {
  254. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  255. FreeTextAnnotArgs freetextArgs = null;
  256. TextAlignment textAlignment;
  257. if (selectedfreetextArgs == null)
  258. {
  259. freetextArgs = new FreeTextAnnotArgs();
  260. freetextArgs.Align = TextAlignment.Left;
  261. freetextArgs.BgColor = Colors.Transparent;
  262. freetextArgs.FontFamily = new FontFamily(Settings.Default.AppProperties.Annotate.TextFontFamaily);
  263. freetextArgs.FontColor = Colors.Black;
  264. freetextArgs.FontSize = 14;
  265. freetextArgs.Transparency = 1;
  266. freetextArgs.LineColor = Colors.Black;
  267. freetextArgs.LineWidth = 0;
  268. freetextArgs.TextContent = string.Empty;
  269. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotFreeText);
  270. if (annotProperty != null)
  271. {
  272. freetextArgs.Align = annotProperty.TextAlign;
  273. freetextArgs.BgColor = annotProperty.BackgroundColor;
  274. freetextArgs.FontFamily = new FontFamily(annotProperty.FontFamily);
  275. freetextArgs.FontColor = annotProperty.ForgoundColor;
  276. freetextArgs.FontSize = annotProperty.FontSize;
  277. freetextArgs.Transparency = annotProperty.Opacity;
  278. freetextArgs.LineColor = annotProperty.BorderColor;
  279. freetextArgs.LineWidth = annotProperty.Thickness;
  280. freetextArgs.TextContent = annotProperty.NoteText;
  281. freetextArgs.FontWeight = annotProperty.FontWeight;
  282. freetextArgs.FontStyle = annotProperty.FontStyle;
  283. }
  284. int align = Settings.Default.AppProperties.Annotate.TextAlign;
  285. if (align == 0)
  286. textAlignment = TextAlignment.Left;
  287. else if (align == 1)
  288. textAlignment = TextAlignment.Center;
  289. else
  290. textAlignment = TextAlignment.Right;
  291. }
  292. else
  293. {
  294. freetextArgs = selectedfreetextArgs;
  295. textAlignment = freetextArgs.Align;
  296. }
  297. annotAttribsList[AnnotAttrib.Color] = freetextArgs.LineColor;
  298. annotAttribsList[AnnotAttrib.FillColor] = freetextArgs.BgColor;
  299. annotAttribsList[AnnotAttrib.Thickness] = freetextArgs.LineWidth;
  300. annotAttribsList[AnnotAttrib.Transparency] = freetextArgs.Transparency;
  301. annotAttribsList[AnnotAttrib.FontColor] = freetextArgs.FontColor;
  302. annotAttribsList[AnnotAttrib.FontSize] = freetextArgs.FontSize;
  303. annotAttribsList[AnnotAttrib.FontFamily] = freetextArgs.FontFamily;
  304. annotAttribsList[AnnotAttrib.FontStyle] = freetextArgs.FontStyle;
  305. annotAttribsList[AnnotAttrib.FontWeight] = freetextArgs.FontWeight;
  306. annotAttribsList[AnnotAttrib.TextAlign] = textAlignment;
  307. annotAttribsList[AnnotAttrib.NoteText] = freetextArgs.TextContent;
  308. AddToPropertyPanel("FreetextAnnotProperty", "Freetext", freetextArgs, annotAttribsList);
  309. return freetextArgs;
  310. }
  311. private AnnotHandlerEventArgs GetStickyNote()
  312. {
  313. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  314. StickyAnnotArgs stickyAnnotArgs = new StickyAnnotArgs();
  315. stickyAnnotArgs.Color = Color.FromRgb(0xFF, 0x81, 0x33);
  316. stickyAnnotArgs.StickyNote = string.Empty;
  317. stickyAnnotArgs.Transparency = 1;
  318. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotSticky);
  319. if (annotProperty != null)
  320. {
  321. stickyAnnotArgs.Color = annotProperty.ForgoundColor;
  322. stickyAnnotArgs.StickyNote = annotProperty.NoteText;
  323. stickyAnnotArgs.Transparency = annotProperty.Opacity;
  324. }
  325. annotAttribsList[AnnotAttrib.Color] = stickyAnnotArgs.Color;
  326. annotAttribsList[AnnotAttrib.Transparency] = stickyAnnotArgs.Transparency;
  327. annotAttribsList[AnnotAttrib.NoteText] = stickyAnnotArgs.StickyNote;
  328. AddToPropertyPanel("FreetextAnnotProperty", "StickyNote", stickyAnnotArgs, annotAttribsList);
  329. return stickyAnnotArgs;
  330. }
  331. private AnnotHandlerEventArgs GetRect(SquareAnnotArgs selectedsquareArgs = null)
  332. {
  333. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  334. SquareAnnotArgs squareArgs = null;
  335. if(selectedsquareArgs == null)
  336. {
  337. squareArgs = new SquareAnnotArgs();
  338. squareArgs.LineColor = Colors.Red;
  339. squareArgs.BgColor = Colors.Transparent;
  340. squareArgs.LineWidth = 1;
  341. squareArgs.Transparency = 1;
  342. squareArgs.LineDash = DashStyles.Solid;
  343. squareArgs.Content = string.Empty;
  344. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotSquare);
  345. if (annotProperty != null)
  346. {
  347. squareArgs.LineColor = annotProperty.BorderColor;
  348. squareArgs.BgColor = annotProperty.BackgroundColor;
  349. if (annotProperty.DashArray == null || annotProperty.DashArray.Count == 0)
  350. {
  351. squareArgs.LineDash = DashStyles.Solid;
  352. }
  353. else
  354. {
  355. DashStyle dash = new DashStyle();
  356. foreach (var offset in annotProperty.DashArray)
  357. {
  358. dash.Dashes.Add(offset);
  359. }
  360. squareArgs.LineDash = dash;
  361. }
  362. squareArgs.LineWidth = annotProperty.Thickness;
  363. squareArgs.Transparency = annotProperty.Opacity;
  364. squareArgs.Content = annotProperty.NoteText;
  365. }
  366. }
  367. else
  368. {
  369. squareArgs = selectedsquareArgs;
  370. }
  371. annotAttribsList[AnnotAttrib.Color] = squareArgs.LineColor;
  372. annotAttribsList[AnnotAttrib.FillColor] = squareArgs.BgColor;
  373. annotAttribsList[AnnotAttrib.LineStyle] = squareArgs.LineDash;
  374. annotAttribsList[AnnotAttrib.Thickness] = squareArgs.LineWidth;
  375. annotAttribsList[AnnotAttrib.Transparency] = squareArgs.Transparency;
  376. annotAttribsList[AnnotAttrib.NoteText] = squareArgs.Content;
  377. AddToPropertyPanel("SharpsAnnotProperty", "Rect", squareArgs, annotAttribsList);
  378. return squareArgs;
  379. }
  380. private AnnotHandlerEventArgs GetCircle(CircleAnnotArgs selectedcircleAnnotArgs = null)
  381. {
  382. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  383. CircleAnnotArgs circleAnnotArgs = null;
  384. if(selectedcircleAnnotArgs == null)
  385. {
  386. circleAnnotArgs = new CircleAnnotArgs();
  387. circleAnnotArgs.LineColor = Colors.Red;
  388. circleAnnotArgs.BgColor = Colors.Transparent;
  389. circleAnnotArgs.LineWidth = 1;
  390. circleAnnotArgs.Transparency = 1;
  391. circleAnnotArgs.LineDash = DashStyles.Solid;
  392. circleAnnotArgs.Content = string.Empty;
  393. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotCircle);
  394. if (annotProperty != null)
  395. {
  396. circleAnnotArgs.LineColor = annotProperty.BorderColor;
  397. circleAnnotArgs.BgColor = annotProperty.BackgroundColor;
  398. if (annotProperty.DashArray == null || annotProperty.DashArray.Count == 0)
  399. {
  400. circleAnnotArgs.LineDash = DashStyles.Solid;
  401. }
  402. else
  403. {
  404. DashStyle dash = new DashStyle();
  405. foreach (var offset in annotProperty.DashArray)
  406. {
  407. dash.Dashes.Add(offset);
  408. }
  409. circleAnnotArgs.LineDash = dash;
  410. }
  411. circleAnnotArgs.LineWidth = annotProperty.Thickness;
  412. circleAnnotArgs.Transparency = annotProperty.Opacity;
  413. circleAnnotArgs.Content = annotProperty.NoteText;
  414. }
  415. }
  416. else
  417. {
  418. circleAnnotArgs = selectedcircleAnnotArgs;
  419. }
  420. annotAttribsList[AnnotAttrib.Color] = circleAnnotArgs.LineColor;
  421. annotAttribsList[AnnotAttrib.FillColor] = circleAnnotArgs.BgColor;
  422. annotAttribsList[AnnotAttrib.LineStyle] = circleAnnotArgs.LineDash;
  423. annotAttribsList[AnnotAttrib.Thickness] = circleAnnotArgs.LineWidth;
  424. annotAttribsList[AnnotAttrib.Transparency] = circleAnnotArgs.Transparency;
  425. annotAttribsList[AnnotAttrib.NoteText] = circleAnnotArgs.Content;
  426. AddToPropertyPanel("SharpsAnnotProperty", "Circle", circleAnnotArgs, annotAttribsList);
  427. return circleAnnotArgs;
  428. }
  429. private AnnotHandlerEventArgs GetArrowLine(string TagStr,LineAnnotArgs selectedLineAnnotArgs = null)
  430. {
  431. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  432. LineAnnotArgs lineArgs = new LineAnnotArgs();
  433. if(selectedLineAnnotArgs == null)
  434. {
  435. lineArgs.LineColor = Colors.Red;
  436. lineArgs.HeadLineType = C_LINE_TYPE.LINETYPE_NONE;
  437. if (TagStr == "Line")
  438. {
  439. lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_NONE;
  440. }
  441. else
  442. {
  443. lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_ARROW;
  444. }
  445. lineArgs.LineDash = DashStyles.Solid;
  446. lineArgs.LineWidth = 1;
  447. lineArgs.Transparency = 1;
  448. lineArgs.Content = string.Empty;
  449. }
  450. else
  451. {
  452. lineArgs = selectedLineAnnotArgs;
  453. }
  454. DefaultAnnotProperty annotProperty = null;
  455. if (TagStr == "Line")
  456. {
  457. annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotLine, "Line");
  458. if (annotProperty != null)
  459. {
  460. annotProperty.HeadLineType = C_LINE_TYPE.LINETYPE_NONE;
  461. annotProperty.TailLineType = C_LINE_TYPE.LINETYPE_NONE;
  462. }
  463. }
  464. else
  465. {
  466. annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotLine, "Arrow");
  467. }
  468. if (annotProperty != null)
  469. {
  470. lineArgs.LineColor = annotProperty.BorderColor;
  471. lineArgs.HeadLineType = annotProperty.HeadLineType;
  472. lineArgs.TailLineType = annotProperty.TailLineType;
  473. DashStyle dash = new DashStyle();
  474. foreach (var offset in annotProperty.DashArray)
  475. {
  476. dash.Dashes.Add(offset);
  477. }
  478. lineArgs.LineDash = dash;
  479. lineArgs.LineWidth = annotProperty.Thickness;
  480. lineArgs.Transparency = annotProperty.Opacity;
  481. lineArgs.Content = annotProperty.NoteText;
  482. }
  483. annotAttribsList[AnnotAttrib.Color] = lineArgs.LineColor;
  484. annotAttribsList[AnnotAttrib.LineStart] = lineArgs.HeadLineType;
  485. annotAttribsList[AnnotAttrib.LineEnd] = lineArgs.TailLineType;
  486. annotAttribsList[AnnotAttrib.LineStyle] = lineArgs.LineDash;
  487. annotAttribsList[AnnotAttrib.Thickness] = lineArgs.LineWidth;
  488. annotAttribsList[AnnotAttrib.Transparency] = lineArgs.Transparency;
  489. annotAttribsList[AnnotAttrib.NoteText] = lineArgs.Content;
  490. AddToPropertyPanel("SharpsAnnotProperty", TagStr, lineArgs, annotAttribsList);
  491. return lineArgs;
  492. }
  493. private AnnotHandlerEventArgs GetStamp()
  494. {
  495. AddToPropertyPanel("StampAnnotProperty");
  496. return null;
  497. }
  498. private AnnotHandlerEventArgs GetSignature()
  499. {
  500. AddToPropertyPanel("SignatureAnnotProperty");
  501. return null;
  502. }
  503. private AnnotHandlerEventArgs GetImage(CustomIconToggleBtn annotBtn)
  504. {
  505. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  506. annotBtn.IsChecked = false;
  507. StampAnnotArgs stampArgs = new StampAnnotArgs();
  508. stampArgs.Opacity = 1;
  509. stampArgs.Type = StampType.IMAGE_STAMP;
  510. OpenFileDialog openFileDialog = new OpenFileDialog();
  511. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  512. if (openFileDialog.ShowDialog() == true)
  513. {
  514. stampArgs.ImagePath = openFileDialog.FileName;
  515. }
  516. AddToPropertyPanel("ImageAnnotProperty", null, stampArgs, annotAttribsList);
  517. return stampArgs;
  518. }
  519. /// <summary>
  520. /// 导航到同一个注释xaml时,需要区分某个注释;比如高亮、删除线、下划线
  521. /// </summary>
  522. /// <param name="viewContent">对应的注释面板</param>
  523. /// <param name="toolTag">导航到同一个注释xaml时,需要区分某个注释;比如高亮、删除线、下划线</param>
  524. /// <param name="annot">注释</param>
  525. /// <param name="annotAttribsList">更改注释属性的键值对,更改值后会自动记录undoRedo容器里</param>
  526. private void AddToPropertyPanel(string viewContent, string toolTag = null, AnnotHandlerEventArgs annot = null, Dictionary<AnnotAttrib, object> annotAttribsList = null)
  527. {
  528. if (string.IsNullOrEmpty(toolTag) == false)
  529. {
  530. if (!ToolExpandDict.ContainsKey(toolTag))
  531. {
  532. ToolExpandDict[toolTag] = true;
  533. }
  534. }
  535. if (annot != null)
  536. propertyPanel.annot = annot;
  537. if (annotAttribsList != null)
  538. propertyPanel.AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annotAttribsList);
  539. if (string.IsNullOrEmpty(viewContent) == false)
  540. viewContentViewModel.SelectedPrpoertyPanel(viewContent, propertyPanel);
  541. }
  542. #endregion
  543. }
  544. }