AnnotToolContentViewModel.Function.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  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 selectedfreetextArgs = 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 (selectedfreetextArgs != null)
  152. {
  153. linkArgs.URI = selectedfreetextArgs.URI;
  154. linkArgs.LinkType = selectedfreetextArgs.LinkType;
  155. linkArgs.DestIndex = selectedfreetextArgs.DestIndex;
  156. }
  157. else
  158. {
  159. linkArgs.URI = string.Empty;
  160. linkArgs.LinkType = LINK_TYPE.GOTO;
  161. linkArgs.DestIndex = -1;
  162. }
  163. //if (viewCtrl.PdfViewer.Document != null)
  164. //{
  165. // linkProperty.SetTotalPage(viewCtrl.PdfViewer.Document.PageCount);
  166. //}
  167. //linkProperty.SetLinkPageNum(linkArgs.DestIndex);
  168. //linkProperty.SetLinkUrl(linkArgs.URI);
  169. //linkProperty.SetLinkEmail(string.Empty);
  170. //linkProperty.AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(linkArgs, annotAttribsList);
  171. //linkProperty.AnnotArgs = linkArgs;
  172. //propertyPanel = linkProperty;
  173. //annotArgs = linkArgs;
  174. //viewCtrl.ShowPropertyPanel();
  175. annotAttribsList[AnnotAttrib.LinkType] = linkArgs.LinkType;
  176. annotAttribsList[AnnotAttrib.LinkUri] = linkArgs.URI;
  177. annotAttribsList[AnnotAttrib.LinkDestIndx] = linkArgs.DestIndex;
  178. AddToPropertyPanel("LinkAnnotProperty", "Link", linkArgs, annotAttribsList, annotAttribEvent);
  179. return linkArgs;
  180. }
  181. private AnnotHandlerEventArgs GetUnderLine(TextUnderlineAnnotArgs selectedunderlineArgs = null)
  182. {
  183. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  184. TextUnderlineAnnotArgs underlineArgs = null;
  185. if (selectedunderlineArgs == null)
  186. {
  187. underlineArgs = new TextUnderlineAnnotArgs();
  188. underlineArgs.Color = Color.FromRgb(0x12, 0xFD, 0xFF);
  189. underlineArgs.Transparency = 1;
  190. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotUnderline);
  191. if (annotProperty != null)
  192. {
  193. underlineArgs.Color = annotProperty.ForgoundColor;
  194. underlineArgs.Transparency = annotProperty.Opacity;
  195. underlineArgs.Content = annotProperty.NoteText;
  196. }
  197. }
  198. else
  199. {
  200. underlineArgs = selectedunderlineArgs;
  201. }
  202. annotAttribsList[AnnotAttrib.Color] = underlineArgs.Color;
  203. annotAttribsList[AnnotAttrib.Transparency] = underlineArgs.Transparency;
  204. annotAttribsList[AnnotAttrib.NoteText] = string.Empty;
  205. AddToPropertyPanel("TextAnnotProperty", "UnderLine", underlineArgs, annotAttribsList);
  206. return underlineArgs;
  207. }
  208. private AnnotHandlerEventArgs GetSquiggly(TextSquigglyAnnotArgs selectedsquigglyArgs = null)
  209. {
  210. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  211. TextSquigglyAnnotArgs squigglyArgs = null;
  212. if (selectedsquigglyArgs == null)
  213. {
  214. squigglyArgs = new TextSquigglyAnnotArgs();
  215. squigglyArgs.Color = Color.FromRgb(0xFF, 0x87, 0x16);
  216. squigglyArgs.Transparency = 1;
  217. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotSquiggly);
  218. if (annotProperty != null)
  219. {
  220. squigglyArgs.Color = annotProperty.ForgoundColor;
  221. squigglyArgs.Transparency = annotProperty.Opacity;
  222. squigglyArgs.Content = annotProperty.NoteText;
  223. }
  224. }
  225. else
  226. {
  227. squigglyArgs = selectedsquigglyArgs;
  228. }
  229. annotAttribsList[AnnotAttrib.Color] = squigglyArgs.Color;
  230. annotAttribsList[AnnotAttrib.Transparency] = squigglyArgs.Transparency;
  231. annotAttribsList[AnnotAttrib.NoteText] = string.Empty;
  232. AddToPropertyPanel("TextAnnotProperty", "Squiggly", squigglyArgs, annotAttribsList);
  233. return squigglyArgs;
  234. }
  235. private AnnotHandlerEventArgs GetStrikeout(TextStrikeoutAnnotArgs selectedstrikeoutArgs = null)
  236. {
  237. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  238. TextStrikeoutAnnotArgs strikeoutArgs = null;
  239. if (selectedstrikeoutArgs == null)
  240. {
  241. strikeoutArgs = new TextStrikeoutAnnotArgs();
  242. strikeoutArgs.Color = Color.FromRgb(0xFF, 0x3B, 0x30);
  243. strikeoutArgs.Transparency = 1;
  244. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotStrikeout);
  245. if (annotProperty != null)
  246. {
  247. strikeoutArgs.Color = annotProperty.ForgoundColor;
  248. strikeoutArgs.Transparency = annotProperty.Opacity;
  249. strikeoutArgs.Content = annotProperty.NoteText;
  250. }
  251. }
  252. else
  253. {
  254. strikeoutArgs = selectedstrikeoutArgs;
  255. }
  256. annotAttribsList[AnnotAttrib.Color] = strikeoutArgs.Color;
  257. annotAttribsList[AnnotAttrib.Transparency] = strikeoutArgs.Transparency;
  258. annotAttribsList[AnnotAttrib.NoteText] = string.Empty;
  259. AddToPropertyPanel("TextAnnotProperty", "Strikeout", strikeoutArgs, annotAttribsList);
  260. return strikeoutArgs;
  261. }
  262. private AnnotHandlerEventArgs GetFreehand(FreehandAnnotArgs selectedfreehandArgs = null)
  263. {
  264. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  265. FreehandAnnotArgs freehandArgs = null;
  266. if (selectedfreehandArgs == null)
  267. {
  268. freehandArgs = new FreehandAnnotArgs();
  269. freehandArgs.InkColor = Color.FromRgb(0x38, 0xE0, 0x2E);
  270. freehandArgs.Transparency = 1;
  271. freehandArgs.LineWidth = 1;
  272. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotFreehand);
  273. if (annotProperty != null)
  274. {
  275. freehandArgs.InkColor = annotProperty.ForgoundColor;
  276. freehandArgs.Transparency = annotProperty.Opacity;
  277. freehandArgs.LineWidth = annotProperty.Thickness;
  278. freehandArgs.Content = annotProperty.NoteText;
  279. }
  280. }
  281. else
  282. {
  283. freehandArgs = selectedfreehandArgs;
  284. }
  285. annotAttribsList[AnnotAttrib.Color] = freehandArgs.InkColor;
  286. annotAttribsList[AnnotAttrib.Transparency] = freehandArgs.Transparency;
  287. annotAttribsList[AnnotAttrib.Thickness] = freehandArgs.LineWidth;
  288. annotAttribsList[AnnotAttrib.NoteText] = freehandArgs.Content;
  289. AddToPropertyPanel("FreehandAnnotProperty", "Freehand", freehandArgs, annotAttribsList);
  290. return freehandArgs;
  291. }
  292. private AnnotHandlerEventArgs GetFreetext(FreeTextAnnotArgs selectedfreetextArgs = null)
  293. {
  294. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  295. FreeTextAnnotArgs freetextArgs = null;
  296. TextAlignment textAlignment;
  297. if (selectedfreetextArgs == null)
  298. {
  299. freetextArgs = new FreeTextAnnotArgs();
  300. freetextArgs.Align = TextAlignment.Left;
  301. freetextArgs.BgColor = Colors.Transparent;
  302. freetextArgs.FontFamily = new FontFamily(Settings.Default.AppProperties.Annotate.TextFontFamaily);
  303. freetextArgs.FontColor = Colors.Black;
  304. freetextArgs.FontSize = 14;
  305. freetextArgs.Transparency = 1;
  306. freetextArgs.LineColor = Colors.Black;
  307. freetextArgs.LineWidth = 0;
  308. freetextArgs.TextContent = string.Empty;
  309. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotFreeText);
  310. if (annotProperty != null)
  311. {
  312. freetextArgs.Align = annotProperty.TextAlign;
  313. freetextArgs.BgColor = annotProperty.BackgroundColor;
  314. freetextArgs.FontFamily = new FontFamily(annotProperty.FontFamily);
  315. freetextArgs.FontColor = annotProperty.ForgoundColor;
  316. freetextArgs.FontSize = annotProperty.FontSize;
  317. freetextArgs.Transparency = annotProperty.Opacity;
  318. freetextArgs.LineColor = annotProperty.BorderColor;
  319. freetextArgs.LineWidth = annotProperty.Thickness;
  320. freetextArgs.TextContent = annotProperty.NoteText;
  321. freetextArgs.FontWeight = annotProperty.FontWeight;
  322. freetextArgs.FontStyle = annotProperty.FontStyle;
  323. }
  324. int align = Settings.Default.AppProperties.Annotate.TextAlign;
  325. if (align == 0)
  326. textAlignment = TextAlignment.Left;
  327. else if (align == 1)
  328. textAlignment = TextAlignment.Center;
  329. else
  330. textAlignment = TextAlignment.Right;
  331. }
  332. else
  333. {
  334. freetextArgs = selectedfreetextArgs;
  335. textAlignment = freetextArgs.Align;
  336. }
  337. annotAttribsList[AnnotAttrib.Color] = freetextArgs.LineColor;
  338. annotAttribsList[AnnotAttrib.FillColor] = freetextArgs.BgColor;
  339. annotAttribsList[AnnotAttrib.Thickness] = freetextArgs.LineWidth;
  340. annotAttribsList[AnnotAttrib.Transparency] = freetextArgs.Transparency;
  341. annotAttribsList[AnnotAttrib.FontColor] = freetextArgs.FontColor;
  342. annotAttribsList[AnnotAttrib.FontSize] = freetextArgs.FontSize;
  343. annotAttribsList[AnnotAttrib.FontFamily] = freetextArgs.FontFamily;
  344. annotAttribsList[AnnotAttrib.FontStyle] = freetextArgs.FontStyle;
  345. annotAttribsList[AnnotAttrib.FontWeight] = freetextArgs.FontWeight;
  346. annotAttribsList[AnnotAttrib.TextAlign] = textAlignment;
  347. annotAttribsList[AnnotAttrib.NoteText] = freetextArgs.TextContent;
  348. AddToPropertyPanel("FreetextAnnotProperty", "Freetext", freetextArgs, annotAttribsList);
  349. return freetextArgs;
  350. }
  351. private AnnotHandlerEventArgs GetStickyNote()
  352. {
  353. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  354. StickyAnnotArgs stickyAnnotArgs = new StickyAnnotArgs();
  355. stickyAnnotArgs.Color = Color.FromRgb(0xFF, 0x81, 0x33);
  356. stickyAnnotArgs.StickyNote = string.Empty;
  357. stickyAnnotArgs.Transparency = 1;
  358. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotSticky);
  359. if (annotProperty != null)
  360. {
  361. stickyAnnotArgs.Color = annotProperty.ForgoundColor;
  362. stickyAnnotArgs.StickyNote = annotProperty.NoteText;
  363. stickyAnnotArgs.Transparency = annotProperty.Opacity;
  364. }
  365. annotAttribsList[AnnotAttrib.Color] = stickyAnnotArgs.Color;
  366. annotAttribsList[AnnotAttrib.Transparency] = stickyAnnotArgs.Transparency;
  367. annotAttribsList[AnnotAttrib.NoteText] = stickyAnnotArgs.StickyNote;
  368. AddToPropertyPanel("FreetextAnnotProperty", "StickyNote", stickyAnnotArgs, annotAttribsList);
  369. return stickyAnnotArgs;
  370. }
  371. private AnnotHandlerEventArgs GetRect(SquareAnnotArgs selectedsquareArgs = null)
  372. {
  373. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  374. SquareAnnotArgs squareArgs = null;
  375. if (selectedsquareArgs == null)
  376. {
  377. squareArgs = new SquareAnnotArgs();
  378. squareArgs.LineColor = Colors.Red;
  379. squareArgs.BgColor = Colors.Transparent;
  380. squareArgs.LineWidth = 1;
  381. squareArgs.Transparency = 1;
  382. squareArgs.LineDash = DashStyles.Solid;
  383. squareArgs.Content = string.Empty;
  384. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotSquare);
  385. if (annotProperty != null)
  386. {
  387. squareArgs.LineColor = annotProperty.BorderColor;
  388. squareArgs.BgColor = annotProperty.BackgroundColor;
  389. if (annotProperty.DashArray == null || annotProperty.DashArray.Count == 0)
  390. {
  391. squareArgs.LineDash = DashStyles.Solid;
  392. }
  393. else
  394. {
  395. DashStyle dash = new DashStyle();
  396. foreach (var offset in annotProperty.DashArray)
  397. {
  398. dash.Dashes.Add(offset);
  399. }
  400. squareArgs.LineDash = dash;
  401. }
  402. squareArgs.LineWidth = annotProperty.Thickness;
  403. squareArgs.Transparency = annotProperty.Opacity;
  404. squareArgs.Content = annotProperty.NoteText;
  405. }
  406. }
  407. else
  408. {
  409. squareArgs = selectedsquareArgs;
  410. }
  411. annotAttribsList[AnnotAttrib.Color] = squareArgs.LineColor;
  412. annotAttribsList[AnnotAttrib.FillColor] = squareArgs.BgColor;
  413. annotAttribsList[AnnotAttrib.LineStyle] = squareArgs.LineDash;
  414. annotAttribsList[AnnotAttrib.Thickness] = squareArgs.LineWidth;
  415. annotAttribsList[AnnotAttrib.Transparency] = squareArgs.Transparency;
  416. annotAttribsList[AnnotAttrib.NoteText] = squareArgs.Content;
  417. AddToPropertyPanel("SharpsAnnotProperty", "Rect", squareArgs, annotAttribsList);
  418. return squareArgs;
  419. }
  420. private AnnotHandlerEventArgs GetCircle(CircleAnnotArgs selectedcircleAnnotArgs = null)
  421. {
  422. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  423. CircleAnnotArgs circleAnnotArgs = null;
  424. if (selectedcircleAnnotArgs == null)
  425. {
  426. circleAnnotArgs = new CircleAnnotArgs();
  427. circleAnnotArgs.LineColor = Colors.Red;
  428. circleAnnotArgs.BgColor = Colors.Transparent;
  429. circleAnnotArgs.LineWidth = 1;
  430. circleAnnotArgs.Transparency = 1;
  431. circleAnnotArgs.LineDash = DashStyles.Solid;
  432. circleAnnotArgs.Content = string.Empty;
  433. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotCircle);
  434. if (annotProperty != null)
  435. {
  436. circleAnnotArgs.LineColor = annotProperty.BorderColor;
  437. circleAnnotArgs.BgColor = annotProperty.BackgroundColor;
  438. if (annotProperty.DashArray == null || annotProperty.DashArray.Count == 0)
  439. {
  440. circleAnnotArgs.LineDash = DashStyles.Solid;
  441. }
  442. else
  443. {
  444. DashStyle dash = new DashStyle();
  445. foreach (var offset in annotProperty.DashArray)
  446. {
  447. dash.Dashes.Add(offset);
  448. }
  449. circleAnnotArgs.LineDash = dash;
  450. }
  451. circleAnnotArgs.LineWidth = annotProperty.Thickness;
  452. circleAnnotArgs.Transparency = annotProperty.Opacity;
  453. circleAnnotArgs.Content = annotProperty.NoteText;
  454. }
  455. }
  456. else
  457. {
  458. circleAnnotArgs = selectedcircleAnnotArgs;
  459. }
  460. annotAttribsList[AnnotAttrib.Color] = circleAnnotArgs.LineColor;
  461. annotAttribsList[AnnotAttrib.FillColor] = circleAnnotArgs.BgColor;
  462. annotAttribsList[AnnotAttrib.LineStyle] = circleAnnotArgs.LineDash;
  463. annotAttribsList[AnnotAttrib.Thickness] = circleAnnotArgs.LineWidth;
  464. annotAttribsList[AnnotAttrib.Transparency] = circleAnnotArgs.Transparency;
  465. annotAttribsList[AnnotAttrib.NoteText] = circleAnnotArgs.Content;
  466. AddToPropertyPanel("SharpsAnnotProperty", "Circle", circleAnnotArgs, annotAttribsList);
  467. return circleAnnotArgs;
  468. }
  469. private AnnotHandlerEventArgs GetArrowLine(string TagStr, LineAnnotArgs selectedLineAnnotArgs = null)
  470. {
  471. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  472. LineAnnotArgs lineArgs = new LineAnnotArgs();
  473. if (selectedLineAnnotArgs == null)
  474. {
  475. lineArgs.LineColor = Colors.Red;
  476. lineArgs.HeadLineType = C_LINE_TYPE.LINETYPE_NONE;
  477. if (TagStr == "Line")
  478. {
  479. lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_NONE;
  480. }
  481. else
  482. {
  483. lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_ARROW;
  484. }
  485. lineArgs.LineDash = DashStyles.Solid;
  486. lineArgs.LineWidth = 1;
  487. lineArgs.Transparency = 1;
  488. lineArgs.Content = string.Empty;
  489. }
  490. else
  491. {
  492. lineArgs = selectedLineAnnotArgs;
  493. }
  494. DefaultAnnotProperty annotProperty = null;
  495. if (TagStr == "Line")
  496. {
  497. annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotLine, "Line");
  498. if (annotProperty != null)
  499. {
  500. annotProperty.HeadLineType = C_LINE_TYPE.LINETYPE_NONE;
  501. annotProperty.TailLineType = C_LINE_TYPE.LINETYPE_NONE;
  502. }
  503. }
  504. else
  505. {
  506. annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotLine, "Arrow");
  507. }
  508. if (annotProperty != null)
  509. {
  510. lineArgs.LineColor = annotProperty.BorderColor;
  511. lineArgs.HeadLineType = annotProperty.HeadLineType;
  512. lineArgs.TailLineType = annotProperty.TailLineType;
  513. DashStyle dash = new DashStyle();
  514. foreach (var offset in annotProperty.DashArray)
  515. {
  516. dash.Dashes.Add(offset);
  517. }
  518. lineArgs.LineDash = dash;
  519. lineArgs.LineWidth = annotProperty.Thickness;
  520. lineArgs.Transparency = annotProperty.Opacity;
  521. lineArgs.Content = annotProperty.NoteText;
  522. }
  523. annotAttribsList[AnnotAttrib.Color] = lineArgs.LineColor;
  524. annotAttribsList[AnnotAttrib.LineStart] = lineArgs.HeadLineType;
  525. annotAttribsList[AnnotAttrib.LineEnd] = lineArgs.TailLineType;
  526. annotAttribsList[AnnotAttrib.LineStyle] = lineArgs.LineDash;
  527. annotAttribsList[AnnotAttrib.Thickness] = lineArgs.LineWidth;
  528. annotAttribsList[AnnotAttrib.Transparency] = lineArgs.Transparency;
  529. annotAttribsList[AnnotAttrib.NoteText] = lineArgs.Content;
  530. AddToPropertyPanel("SharpsAnnotProperty", TagStr, lineArgs, annotAttribsList);
  531. return lineArgs;
  532. }
  533. private AnnotHandlerEventArgs GetStamp()
  534. {
  535. AddToPropertyPanel("StampAnnotProperty");
  536. return null;
  537. }
  538. private AnnotHandlerEventArgs GetSignature()
  539. {
  540. AddToPropertyPanel("SignatureAnnotProperty");
  541. return null;
  542. }
  543. private AnnotHandlerEventArgs GetImage(CustomIconToggleBtn annotBtn)
  544. {
  545. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  546. annotBtn.IsChecked = false;
  547. StampAnnotArgs stampArgs = new StampAnnotArgs();
  548. stampArgs.Opacity = 1;
  549. stampArgs.Type = StampType.IMAGE_STAMP;
  550. OpenFileDialog openFileDialog = new OpenFileDialog();
  551. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  552. if (openFileDialog.ShowDialog() == true)
  553. {
  554. stampArgs.ImagePath = openFileDialog.FileName;
  555. }
  556. AddToPropertyPanel("ImageAnnotProperty", null, stampArgs, annotAttribsList);
  557. return stampArgs;
  558. }
  559. /// <summary>
  560. /// 导航到同一个注释xaml时,需要区分某个注释;比如高亮、删除线、下划线
  561. /// </summary>
  562. /// <param name="viewContent">对应的注释面板</param>
  563. /// <param name="toolTag">导航到同一个注释xaml时,需要区分某个注释;比如高亮、删除线、下划线</param>
  564. /// <param name="annot">注释</param>
  565. /// <param name="annotAttribsList">更改注释属性的键值对,更改值后会自动记录undoRedo容器里</param>
  566. private void AddToPropertyPanel(string viewContent, string toolTag = null, AnnotHandlerEventArgs annot = null, Dictionary<AnnotAttrib, object> annotAttribsList = null, AnnotAttribEvent annotAttribEvent = null)
  567. {
  568. if (string.IsNullOrEmpty(toolTag) == false)
  569. {
  570. if (!ToolExpandDict.ContainsKey(toolTag))
  571. {
  572. ToolExpandDict[toolTag] = true;
  573. }
  574. }
  575. if (annot != null)
  576. propertyPanel.annot = annot;
  577. propertyPanel.AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annotAttribsList);
  578. if (annotAttribsList != null)
  579. {
  580. if (annot is LinkAnnotArgs && annotAttribEvent != null)
  581. {
  582. //if (annotAttribEvent.IsAnnotCreateReset)
  583. //{
  584. // propertyPanel.AnnotEvent.IsAnnotCreateReset = true;
  585. //}
  586. propertyPanel.AnnotEvent = annotAttribEvent;
  587. }
  588. }
  589. if (string.IsNullOrEmpty(viewContent) == false)
  590. viewContentViewModel.SelectedPrpoertyPanel(viewContent, propertyPanel);
  591. }
  592. #endregion 注释工具
  593. }
  594. }