AnnotToolContentViewModel.Function.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  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] = highlightArgs.Content;
  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] = underlineArgs.Content;
  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] = squigglyArgs.Content;
  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] = strikeoutArgs.Content;
  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(StickyAnnotArgs selectedStickyArgs = null)
  340. {
  341. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  342. StickyAnnotArgs stickyAnnotArgs = new StickyAnnotArgs();
  343. if (selectedStickyArgs == null)
  344. {
  345. stickyAnnotArgs.Color = Color.FromRgb(0xFF, 0x81, 0x33);
  346. stickyAnnotArgs.StickyNote = string.Empty;
  347. stickyAnnotArgs.Transparency = 1;
  348. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotSticky);
  349. if (annotProperty != null)
  350. {
  351. stickyAnnotArgs.Color = annotProperty.ForgoundColor;
  352. stickyAnnotArgs.StickyNote = annotProperty.NoteText;
  353. stickyAnnotArgs.Transparency = annotProperty.Opacity;
  354. }
  355. }
  356. else
  357. {
  358. stickyAnnotArgs = selectedStickyArgs;
  359. }
  360. annotAttribsList[AnnotAttrib.Color] = stickyAnnotArgs.Color;
  361. annotAttribsList[AnnotAttrib.Transparency] = stickyAnnotArgs.Transparency;
  362. annotAttribsList[AnnotAttrib.NoteText] = stickyAnnotArgs.StickyNote;
  363. annotAttribsList[AnnotAttrib.StickyIcon] = stickyAnnotArgs.IconName;
  364. AddToPropertyPanel("StickyNoteProperty", "StickyNote", stickyAnnotArgs, annotAttribsList);
  365. return stickyAnnotArgs;
  366. }
  367. private AnnotHandlerEventArgs GetRect(SquareAnnotArgs selectedsquareArgs = null)
  368. {
  369. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  370. SquareAnnotArgs squareArgs = null;
  371. if (selectedsquareArgs == null)
  372. {
  373. squareArgs = new SquareAnnotArgs();
  374. squareArgs.LineColor = Colors.Red;
  375. squareArgs.BgColor = Colors.Transparent;
  376. squareArgs.LineWidth = 1;
  377. squareArgs.Transparency = 1;
  378. squareArgs.LineDash = DashStyles.Solid;
  379. squareArgs.Content = string.Empty;
  380. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotSquare);
  381. if (annotProperty != null)
  382. {
  383. squareArgs.LineColor = annotProperty.BorderColor;
  384. squareArgs.BgColor = annotProperty.BackgroundColor;
  385. if (annotProperty.DashArray == null || annotProperty.DashArray.Count == 0)
  386. {
  387. squareArgs.LineDash = DashStyles.Solid;
  388. }
  389. else
  390. {
  391. DashStyle dash = new DashStyle();
  392. foreach (var offset in annotProperty.DashArray)
  393. {
  394. dash.Dashes.Add(offset);
  395. }
  396. squareArgs.LineDash = dash;
  397. }
  398. squareArgs.LineWidth = annotProperty.Thickness;
  399. squareArgs.Transparency = annotProperty.Opacity;
  400. squareArgs.Content = annotProperty.NoteText;
  401. }
  402. }
  403. else
  404. {
  405. squareArgs = selectedsquareArgs;
  406. }
  407. annotAttribsList[AnnotAttrib.Color] = squareArgs.LineColor;
  408. annotAttribsList[AnnotAttrib.FillColor] = squareArgs.BgColor;
  409. annotAttribsList[AnnotAttrib.LineStyle] = squareArgs.LineDash;
  410. annotAttribsList[AnnotAttrib.Thickness] = squareArgs.LineWidth;
  411. annotAttribsList[AnnotAttrib.Transparency] = squareArgs.Transparency;
  412. annotAttribsList[AnnotAttrib.NoteText] = squareArgs.Content;
  413. AddToPropertyPanel("SharpsAnnotProperty", "Rect", squareArgs, annotAttribsList);
  414. return squareArgs;
  415. }
  416. private AnnotHandlerEventArgs GetCircle(CircleAnnotArgs selectedcircleAnnotArgs = null)
  417. {
  418. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  419. CircleAnnotArgs circleAnnotArgs = null;
  420. if (selectedcircleAnnotArgs == null)
  421. {
  422. circleAnnotArgs = new CircleAnnotArgs();
  423. circleAnnotArgs.LineColor = Colors.Red;
  424. circleAnnotArgs.BgColor = Colors.Transparent;
  425. circleAnnotArgs.LineWidth = 1;
  426. circleAnnotArgs.Transparency = 1;
  427. circleAnnotArgs.LineDash = DashStyles.Solid;
  428. circleAnnotArgs.Content = string.Empty;
  429. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotCircle);
  430. if (annotProperty != null)
  431. {
  432. circleAnnotArgs.LineColor = annotProperty.BorderColor;
  433. circleAnnotArgs.BgColor = annotProperty.BackgroundColor;
  434. if (annotProperty.DashArray == null || annotProperty.DashArray.Count == 0)
  435. {
  436. circleAnnotArgs.LineDash = DashStyles.Solid;
  437. }
  438. else
  439. {
  440. DashStyle dash = new DashStyle();
  441. foreach (var offset in annotProperty.DashArray)
  442. {
  443. dash.Dashes.Add(offset);
  444. }
  445. circleAnnotArgs.LineDash = dash;
  446. }
  447. circleAnnotArgs.LineWidth = annotProperty.Thickness;
  448. circleAnnotArgs.Transparency = annotProperty.Opacity;
  449. circleAnnotArgs.Content = annotProperty.NoteText;
  450. }
  451. }
  452. else
  453. {
  454. circleAnnotArgs = selectedcircleAnnotArgs;
  455. }
  456. annotAttribsList[AnnotAttrib.Color] = circleAnnotArgs.LineColor;
  457. annotAttribsList[AnnotAttrib.FillColor] = circleAnnotArgs.BgColor;
  458. annotAttribsList[AnnotAttrib.LineStyle] = circleAnnotArgs.LineDash;
  459. annotAttribsList[AnnotAttrib.Thickness] = circleAnnotArgs.LineWidth;
  460. annotAttribsList[AnnotAttrib.Transparency] = circleAnnotArgs.Transparency;
  461. annotAttribsList[AnnotAttrib.NoteText] = circleAnnotArgs.Content;
  462. AddToPropertyPanel("SharpsAnnotProperty", "Circle", circleAnnotArgs, annotAttribsList);
  463. return circleAnnotArgs;
  464. }
  465. private AnnotHandlerEventArgs GetArrowLine(string TagStr, LineAnnotArgs selectedLineAnnotArgs = null)
  466. {
  467. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  468. LineAnnotArgs lineArgs = new LineAnnotArgs();
  469. if (selectedLineAnnotArgs == null)
  470. {
  471. lineArgs.LineColor = Colors.Red;
  472. lineArgs.HeadLineType = C_LINE_TYPE.LINETYPE_NONE;
  473. if (TagStr == "Line")
  474. {
  475. lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_NONE;
  476. }
  477. else
  478. {
  479. lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_ARROW;
  480. }
  481. lineArgs.LineDash = DashStyles.Solid;
  482. lineArgs.LineWidth = 1;
  483. lineArgs.Transparency = 1;
  484. lineArgs.Content = string.Empty;
  485. }
  486. else
  487. {
  488. lineArgs = selectedLineAnnotArgs;
  489. }
  490. DefaultAnnotProperty annotProperty = null;
  491. if (TagStr == "Line")
  492. {
  493. annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotLine, "Line");
  494. if (annotProperty != null)
  495. {
  496. annotProperty.HeadLineType = C_LINE_TYPE.LINETYPE_NONE;
  497. annotProperty.TailLineType = C_LINE_TYPE.LINETYPE_NONE;
  498. }
  499. }
  500. else
  501. {
  502. annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotLine, "Arrow");
  503. }
  504. if (annotProperty != null)
  505. {
  506. lineArgs.LineColor = annotProperty.BorderColor;
  507. lineArgs.HeadLineType = annotProperty.HeadLineType;
  508. lineArgs.TailLineType = annotProperty.TailLineType;
  509. DashStyle dash = new DashStyle();
  510. foreach (var offset in annotProperty.DashArray)
  511. {
  512. dash.Dashes.Add(offset);
  513. }
  514. lineArgs.LineDash = dash;
  515. lineArgs.LineWidth = annotProperty.Thickness;
  516. lineArgs.Transparency = annotProperty.Opacity;
  517. lineArgs.Content = annotProperty.NoteText;
  518. }
  519. annotAttribsList[AnnotAttrib.Color] = lineArgs.LineColor;
  520. annotAttribsList[AnnotAttrib.LineStart] = lineArgs.HeadLineType;
  521. annotAttribsList[AnnotAttrib.LineEnd] = lineArgs.TailLineType;
  522. annotAttribsList[AnnotAttrib.LineStyle] = lineArgs.LineDash;
  523. annotAttribsList[AnnotAttrib.Thickness] = lineArgs.LineWidth;
  524. annotAttribsList[AnnotAttrib.Transparency] = lineArgs.Transparency;
  525. annotAttribsList[AnnotAttrib.NoteText] = lineArgs.Content;
  526. AddToPropertyPanel("SharpsAnnotProperty", TagStr, lineArgs, annotAttribsList);
  527. return lineArgs;
  528. }
  529. private AnnotHandlerEventArgs GetStamp()
  530. {
  531. AddToPropertyPanel("StampAnnotProperty");
  532. return null;
  533. }
  534. private AnnotHandlerEventArgs GetSignature()
  535. {
  536. AddToPropertyPanel("SignatureAnnotProperty");
  537. return null;
  538. }
  539. private AnnotHandlerEventArgs GetImage(CustomIconToggleBtn annotBtn)
  540. {
  541. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  542. annotBtn.IsChecked = false;
  543. StampAnnotArgs stampArgs = new StampAnnotArgs();
  544. stampArgs.Opacity = 1;
  545. stampArgs.Type = StampType.IMAGE_STAMP;
  546. OpenFileDialog openFileDialog = new OpenFileDialog();
  547. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  548. if (openFileDialog.ShowDialog() == true)
  549. {
  550. stampArgs.ImagePath = openFileDialog.FileName;
  551. }
  552. AddToPropertyPanel("ImageAnnotProperty", null, stampArgs, annotAttribsList);
  553. return stampArgs;
  554. }
  555. private AnnotHandlerEventArgs GetSnapshotEdit(CustomIconToggleBtn annotBtn)
  556. {
  557. SnapshotEditToolArgs snapshotArgs = new SnapshotEditToolArgs();
  558. snapshotArgs.ControlPointColor = Colors.White;
  559. snapshotArgs.BgColor = Color.FromArgb(0x99, 0x00, 0x00, 0x00);
  560. snapshotArgs.LineColor = Color.FromArgb(0xFF, 0x47, 0x7E, 0xDE);
  561. SnapshotEditMenuViewModel.SnapToolArgs = snapshotArgs;
  562. SnapshotEditMenuViewModel.PDFViewer = PDFViewer;
  563. SnapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent; ;
  564. #region to do
  565. //SnapshotEditMenu snapMenu = new SnapshotEditMenu();
  566. //snapshotArgs.ToolPanel = snapMenu;
  567. //SnapshotEditMenuViewModel snapshotEditMenuViewModel = (SnapshotEditMenuViewModel)snapMenu.DataContext;
  568. //snapshotEditMenuViewModel.SnapToolArgs = snapshotArgs;
  569. //snapshotEditMenuViewModel.PdfViewer = PDFViewer;
  570. //snapshotEditMenuViewModel.ToggleBtn = annotBtn;
  571. #endregion to do
  572. return snapshotArgs;
  573. }
  574. /// <summary>
  575. /// 导航到同一个注释xaml时,需要区分某个注释;比如高亮、删除线、下划线
  576. /// </summary>
  577. /// <param name="viewContent">对应的注释面板</param>
  578. /// <param name="toolTag">导航到同一个注释xaml时,需要区分某个注释;比如高亮、删除线、下划线</param>
  579. /// <param name="annot">注释</param>
  580. /// <param name="annotAttribsList">更改注释属性的键值对,更改值后会自动记录undoRedo容器里</param>
  581. private void AddToPropertyPanel(string viewContent, string toolTag = null, AnnotHandlerEventArgs annot = null, Dictionary<AnnotAttrib, object> annotAttribsList = null, AnnotAttribEvent annotAttribEvent = null)
  582. {
  583. if (string.IsNullOrEmpty(toolTag) == false)
  584. {
  585. if (!ToolExpandDict.ContainsKey(toolTag))
  586. {
  587. ToolExpandDict[toolTag] = true;
  588. }
  589. }
  590. if (annot != null)
  591. propertyPanel.annot = annot;
  592. if (annotAttribsList != null)
  593. {
  594. propertyPanel.AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annotAttribsList);
  595. if (annot is LinkAnnotArgs && annotAttribEvent != null)
  596. {
  597. propertyPanel.AnnotEvent = annotAttribEvent;
  598. }
  599. }
  600. if (string.IsNullOrEmpty(viewContent) == false)
  601. {
  602. viewContentViewModel.SelectedPrpoertyPanel(viewContent, propertyPanel);
  603. }
  604. }
  605. #endregion 注释工具
  606. }
  607. }