AnnotToolContentViewModel.Function.cs 32 KB

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