AnnotToolContentViewModel.Function.cs 29 KB

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