AnnotToolContentViewModel.Function.cs 28 KB

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