AnnotToolContentViewModel.Function.cs 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKit.PDFDocument;
  3. using ComPDFKitViewer;
  4. using ComPDFKitViewer.AnnotEvent;
  5. using ComPDFKitViewer.PdfViewer;
  6. using Microsoft.Win32;
  7. using PDF_Office.CustomControl;
  8. using PDF_Office.Helper;
  9. using PDF_Office.Properties;
  10. using PDF_Office.ViewModels.PropertyPanel.AnnotPanel;
  11. using PDF_Office.Views.PropertyPanel.AnnotPanel;
  12. using PDFSettings;
  13. using Prism.Mvvm;
  14. using Prism.Regions;
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Linq;
  18. using System.Text;
  19. using System.Threading.Tasks;
  20. using System.Windows;
  21. using System.Windows.Controls;
  22. using System.Windows.Input;
  23. using System.Windows.Media;
  24. namespace PDF_Office.ViewModels.Tools
  25. {
  26. public sealed partial class AnnotToolContentViewModel : BindableBase, INavigationAware
  27. {
  28. #region 初始化
  29. #region 初始化数据
  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. //用来记录选中和创建注释的标识
  111. private void InitToolDict()
  112. {
  113. ToolExpandDict.Add("SnapshotEdit", AnnotArgsType.SnapshotWithEditTool);
  114. ToolExpandDict.Add("HighLight", AnnotArgsType.AnnotHighlight);
  115. ToolExpandDict.Add("UnderLine", AnnotArgsType.AnnotUnderline);
  116. ToolExpandDict.Add("Squiggly", AnnotArgsType.AnnotSquiggly);
  117. ToolExpandDict.Add("Strikeout", AnnotArgsType.AnnotStrikeout);
  118. ToolExpandDict.Add("Freehand", AnnotArgsType.AnnotFreehand);
  119. ToolExpandDict.Add("Freetext", AnnotArgsType.AnnotFreeText);
  120. ToolExpandDict.Add("StickyNote", AnnotArgsType.AnnotSticky);
  121. ToolExpandDict.Add("Rect", AnnotArgsType.AnnotSquare);
  122. ToolExpandDict.Add("Circle", AnnotArgsType.AnnotCircle);
  123. ToolExpandDict.Add("Arrow", AnnotArgsType.AnnotLine);
  124. ToolExpandDict.Add("Line", AnnotArgsType.AnnotLine);
  125. ToolExpandDict.Add("Link", AnnotArgsType.AnnotLink);
  126. }
  127. #endregion
  128. #endregion
  129. #region 注释工具
  130. //注释工具
  131. private void FindAnnotTypeKey(string tag, ref AnnotHandlerEventArgs annotArgs)
  132. {
  133. switch (tag)
  134. {
  135. case "SnapshotEdit"://内容选择
  136. annotArgs = GetSnapshotEdit();
  137. break;
  138. case "HighLight"://字体高亮
  139. annotArgs = GetHighLight();
  140. break;
  141. case "UnderLine"://下划线
  142. annotArgs = GetUnderLine();
  143. break;
  144. case "Squiggly"://波浪线
  145. annotArgs = GetSquiggly();
  146. break;
  147. case "Strikeout"://删除线
  148. annotArgs = GetStrikeout();
  149. break;
  150. case "Freehand"://手绘
  151. annotArgs = GetFreehand();
  152. break;
  153. case "Freetext"://文本
  154. annotArgs = GetFreetext();
  155. break;
  156. case "StickyNote"://便签
  157. annotArgs = GetStickyNote();
  158. break;
  159. case "Rect"://矩形
  160. annotArgs = GetRect();
  161. break;
  162. case "Circle"://圆
  163. annotArgs = GetCircle();
  164. break;
  165. case "Arrow"://箭头
  166. case "Line"://线
  167. annotArgs = GetArrowLine(tag);
  168. break;
  169. case "Stamp"://图章
  170. annotArgs = GetStamp();
  171. break;
  172. case "Image":
  173. annotArgs = GetImage();
  174. break;
  175. case "Signature"://签名
  176. annotArgs = GetSignature();
  177. PDFViewer.SetMouseMode(MouseModes.PanTool);//清空其他注释
  178. break;
  179. case "Link"://链接
  180. viewContentViewModel.IsCreateLink = false;
  181. annotArgs = GetLink();
  182. break;
  183. }
  184. }
  185. /// <summary>
  186. /// 高亮注释
  187. /// </summary>
  188. /// <returns></returns>
  189. private AnnotHandlerEventArgs GetHighLight(TextHighlightAnnotArgs selectedhighlightArgs = null)
  190. {
  191. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  192. TextHighlightAnnotArgs highlightArgs = null;
  193. if (selectedhighlightArgs == null)
  194. {
  195. highlightArgs = new TextHighlightAnnotArgs();
  196. highlightArgs.Color = Color.FromRgb(0xFF, 0xBB, 0x00);
  197. highlightArgs.Transparency = 0.5;
  198. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotHighlight);
  199. if (annotProperty != null)
  200. {
  201. highlightArgs.Color = annotProperty.ForgoundColor;
  202. highlightArgs.Transparency = annotProperty.Opacity;
  203. highlightArgs.Content = annotProperty.NoteText;
  204. }
  205. }
  206. else
  207. {
  208. highlightArgs = selectedhighlightArgs;
  209. }
  210. annotAttribsList[AnnotAttrib.Color] = highlightArgs.Color;
  211. annotAttribsList[AnnotAttrib.Transparency] = highlightArgs.Transparency;
  212. annotAttribsList[AnnotAttrib.NoteText] = highlightArgs.Content;
  213. AddToPropertyPanel("TextAnnotProperty", "HighLight", highlightArgs, annotAttribsList);
  214. return highlightArgs;
  215. }
  216. /// <summary>
  217. /// 链接
  218. /// </summary>
  219. /// <param name="selectedLinkAnnotArgs"></param>
  220. /// <param name="annotAttribEvent"></param>
  221. /// <returns></returns>
  222. public AnnotHandlerEventArgs GetLink(LinkAnnotArgs selectedLinkAnnotArgs = null, AnnotAttribEvent annotAttribEvent = null)
  223. {
  224. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  225. LinkAnnotArgs linkArgs = new LinkAnnotArgs();
  226. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotLink);
  227. if (annotProperty != null)
  228. {
  229. }
  230. if (selectedLinkAnnotArgs != null)
  231. {
  232. linkArgs = selectedLinkAnnotArgs;
  233. }
  234. else
  235. {
  236. linkArgs.URI = string.Empty;
  237. linkArgs.LinkType = LINK_TYPE.GOTO;
  238. linkArgs.DestIndex = -1;
  239. }
  240. annotAttribsList[AnnotAttrib.LinkType] = linkArgs.LinkType;
  241. annotAttribsList[AnnotAttrib.LinkUri] = linkArgs.URI;
  242. annotAttribsList[AnnotAttrib.LinkDestIndx] = linkArgs.DestIndex;
  243. AddToPropertyPanel("LinkAnnotProperty", "Link", linkArgs, annotAttribsList, annotAttribEvent);
  244. return linkArgs;
  245. }
  246. /// <summary>
  247. /// 下划线
  248. /// </summary>
  249. /// <param name="selectedunderlineArgs"></param>
  250. /// <returns></returns>
  251. private AnnotHandlerEventArgs GetUnderLine(TextUnderlineAnnotArgs selectedunderlineArgs = null)
  252. {
  253. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  254. TextUnderlineAnnotArgs underlineArgs = null;
  255. if (selectedunderlineArgs == null)
  256. {
  257. underlineArgs = new TextUnderlineAnnotArgs();
  258. underlineArgs.Color = Color.FromRgb(0x12, 0xFD, 0xFF);
  259. underlineArgs.Transparency = 1;
  260. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotUnderline);
  261. if (annotProperty != null)
  262. {
  263. underlineArgs.Color = annotProperty.ForgoundColor;
  264. underlineArgs.Transparency = annotProperty.Opacity;
  265. underlineArgs.Content = annotProperty.NoteText;
  266. }
  267. }
  268. else
  269. {
  270. underlineArgs = selectedunderlineArgs;
  271. }
  272. annotAttribsList[AnnotAttrib.Color] = underlineArgs.Color;
  273. annotAttribsList[AnnotAttrib.Transparency] = underlineArgs.Transparency;
  274. annotAttribsList[AnnotAttrib.NoteText] = underlineArgs.Content;
  275. AddToPropertyPanel("TextAnnotProperty", "UnderLine", underlineArgs, annotAttribsList);
  276. return underlineArgs;
  277. }
  278. /// <summary>
  279. /// 波浪线
  280. /// </summary>
  281. /// <param name="selectedsquigglyArgs"></param>
  282. /// <returns></returns>
  283. private AnnotHandlerEventArgs GetSquiggly(TextSquigglyAnnotArgs selectedsquigglyArgs = null)
  284. {
  285. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  286. TextSquigglyAnnotArgs squigglyArgs = null;
  287. if (selectedsquigglyArgs == null)
  288. {
  289. squigglyArgs = new TextSquigglyAnnotArgs();
  290. squigglyArgs.Color = Color.FromRgb(0xFF, 0x87, 0x16);
  291. squigglyArgs.Transparency = 1;
  292. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotSquiggly);
  293. if (annotProperty != null)
  294. {
  295. squigglyArgs.Color = annotProperty.ForgoundColor;
  296. squigglyArgs.Transparency = annotProperty.Opacity;
  297. squigglyArgs.Content = annotProperty.NoteText;
  298. }
  299. }
  300. else
  301. {
  302. squigglyArgs = selectedsquigglyArgs;
  303. }
  304. annotAttribsList[AnnotAttrib.Color] = squigglyArgs.Color;
  305. annotAttribsList[AnnotAttrib.Transparency] = squigglyArgs.Transparency;
  306. annotAttribsList[AnnotAttrib.NoteText] = squigglyArgs.Content;
  307. AddToPropertyPanel("TextAnnotProperty", "Squiggly", squigglyArgs, annotAttribsList);
  308. return squigglyArgs;
  309. }
  310. /// <summary>
  311. /// 删除线
  312. /// </summary>
  313. /// <param name="selectedstrikeoutArgs"></param>
  314. /// <returns></returns>
  315. private AnnotHandlerEventArgs GetStrikeout(TextStrikeoutAnnotArgs selectedstrikeoutArgs = null)
  316. {
  317. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  318. TextStrikeoutAnnotArgs strikeoutArgs = null;
  319. if (selectedstrikeoutArgs == null)
  320. {
  321. strikeoutArgs = new TextStrikeoutAnnotArgs();
  322. strikeoutArgs.Color = Color.FromRgb(0xFF, 0x3B, 0x30);
  323. strikeoutArgs.Transparency = 1;
  324. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotStrikeout);
  325. if (annotProperty != null)
  326. {
  327. strikeoutArgs.Color = annotProperty.ForgoundColor;
  328. strikeoutArgs.Transparency = annotProperty.Opacity;
  329. strikeoutArgs.Content = annotProperty.NoteText;
  330. }
  331. }
  332. else
  333. {
  334. strikeoutArgs = selectedstrikeoutArgs;
  335. }
  336. annotAttribsList[AnnotAttrib.Color] = strikeoutArgs.Color;
  337. annotAttribsList[AnnotAttrib.Transparency] = strikeoutArgs.Transparency;
  338. annotAttribsList[AnnotAttrib.NoteText] = strikeoutArgs.Content;
  339. AddToPropertyPanel("TextAnnotProperty", "Strikeout", strikeoutArgs, annotAttribsList);
  340. return strikeoutArgs;
  341. }
  342. /// <summary>
  343. /// 手绘
  344. /// </summary>
  345. /// <param name="selectedfreehandArgs"></param>
  346. /// <returns></returns>
  347. private AnnotHandlerEventArgs GetFreehand(FreehandAnnotArgs selectedfreehandArgs = null)
  348. {
  349. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  350. FreehandAnnotArgs freehandArgs = null;
  351. if (selectedfreehandArgs == null)
  352. {
  353. freehandArgs = new FreehandAnnotArgs();
  354. freehandArgs.InkColor = Color.FromRgb(0x38, 0xE0, 0x2E);
  355. freehandArgs.Transparency = 1;
  356. freehandArgs.LineWidth = 1;
  357. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotFreehand);
  358. if (annotProperty != null)
  359. {
  360. freehandArgs.InkColor = annotProperty.ForgoundColor;
  361. freehandArgs.Transparency = annotProperty.Opacity;
  362. freehandArgs.LineWidth = annotProperty.Thickness;
  363. freehandArgs.Content = annotProperty.NoteText;
  364. }
  365. }
  366. else
  367. {
  368. freehandArgs = selectedfreehandArgs;
  369. }
  370. annotAttribsList[AnnotAttrib.Color] = freehandArgs.InkColor;
  371. annotAttribsList[AnnotAttrib.Transparency] = freehandArgs.Transparency;
  372. annotAttribsList[AnnotAttrib.Thickness] = freehandArgs.LineWidth;
  373. annotAttribsList[AnnotAttrib.NoteText] = freehandArgs.Content;
  374. AddToPropertyPanel("FreehandAnnotProperty", "Freehand", freehandArgs, annotAttribsList);
  375. return freehandArgs;
  376. }
  377. /// <summary>
  378. /// 文本
  379. /// </summary>
  380. /// <param name="selectedfreetextArgs"></param>
  381. /// <returns></returns>
  382. private AnnotHandlerEventArgs GetFreetext(FreeTextAnnotArgs selectedfreetextArgs = null)
  383. {
  384. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  385. FreeTextAnnotArgs freetextArgs = null;
  386. TextAlignment textAlignment;
  387. if (selectedfreetextArgs == null)
  388. {
  389. freetextArgs = new FreeTextAnnotArgs();
  390. freetextArgs.Align = TextAlignment.Left;
  391. freetextArgs.BgColor = Colors.Transparent;
  392. freetextArgs.FontFamily = new FontFamily(Settings.Default.AppProperties.Annotate.TextFontFamaily);
  393. freetextArgs.FontColor = Colors.Black;
  394. freetextArgs.FontSize = 14;
  395. freetextArgs.Transparency = 1;
  396. freetextArgs.LineColor = Colors.Black;
  397. freetextArgs.LineWidth = 0;
  398. freetextArgs.TextContent = string.Empty;
  399. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotFreeText);
  400. if (annotProperty != null)
  401. {
  402. freetextArgs.Align = annotProperty.TextAlign;
  403. freetextArgs.BgColor = annotProperty.BackgroundColor;
  404. freetextArgs.FontFamily = new FontFamily(annotProperty.FontFamily);
  405. freetextArgs.FontColor = annotProperty.ForgoundColor;
  406. freetextArgs.FontSize = annotProperty.FontSize;
  407. freetextArgs.Transparency = annotProperty.Opacity;
  408. freetextArgs.LineColor = annotProperty.BorderColor;
  409. freetextArgs.LineWidth = annotProperty.Thickness;
  410. freetextArgs.TextContent = annotProperty.NoteText;
  411. freetextArgs.FontWeight = annotProperty.FontWeight;
  412. freetextArgs.FontStyle = annotProperty.FontStyle;
  413. }
  414. int align = (int)Settings.Default.AppProperties.Annotate.TextAlign;
  415. if (align == 0)
  416. textAlignment = TextAlignment.Left;
  417. else if (align == 1)
  418. textAlignment = TextAlignment.Center;
  419. else
  420. textAlignment = TextAlignment.Right;
  421. }
  422. else
  423. {
  424. freetextArgs = selectedfreetextArgs;
  425. textAlignment = freetextArgs.Align;
  426. }
  427. annotAttribsList[AnnotAttrib.Color] = freetextArgs.LineColor;
  428. annotAttribsList[AnnotAttrib.FillColor] = freetextArgs.BgColor;
  429. annotAttribsList[AnnotAttrib.Thickness] = freetextArgs.LineWidth;
  430. annotAttribsList[AnnotAttrib.Transparency] = freetextArgs.Transparency;
  431. annotAttribsList[AnnotAttrib.FontColor] = freetextArgs.FontColor;
  432. annotAttribsList[AnnotAttrib.FontSize] = freetextArgs.FontSize;
  433. annotAttribsList[AnnotAttrib.FontFamily] = freetextArgs.FontFamily;
  434. annotAttribsList[AnnotAttrib.FontStyle] = freetextArgs.FontStyle;
  435. annotAttribsList[AnnotAttrib.FontWeight] = freetextArgs.FontWeight;
  436. annotAttribsList[AnnotAttrib.TextAlign] = textAlignment;
  437. annotAttribsList[AnnotAttrib.NoteText] = freetextArgs.TextContent;
  438. AddToPropertyPanel("FreetextAnnotProperty", "Freetext", freetextArgs, annotAttribsList);
  439. return freetextArgs;
  440. }
  441. /// <summary>
  442. /// 便签
  443. /// </summary>
  444. /// <param name="selectedStickyArgs"></param>
  445. /// <returns></returns>
  446. private AnnotHandlerEventArgs GetStickyNote(StickyAnnotArgs selectedStickyArgs = null)
  447. {
  448. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  449. StickyAnnotArgs stickyAnnotArgs = new StickyAnnotArgs();
  450. if (selectedStickyArgs == null)
  451. {
  452. stickyAnnotArgs.Color = Color.FromRgb(0xFF, 0x81, 0x33);
  453. stickyAnnotArgs.StickyNote = string.Empty;
  454. stickyAnnotArgs.Transparency = 1;
  455. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotSticky);
  456. if (annotProperty != null)
  457. {
  458. stickyAnnotArgs.Color = annotProperty.ForgoundColor;
  459. stickyAnnotArgs.StickyNote = annotProperty.NoteText;
  460. stickyAnnotArgs.Transparency = annotProperty.Opacity;
  461. }
  462. }
  463. else
  464. {
  465. stickyAnnotArgs = selectedStickyArgs;
  466. }
  467. annotAttribsList[AnnotAttrib.Color] = stickyAnnotArgs.Color;
  468. annotAttribsList[AnnotAttrib.Transparency] = stickyAnnotArgs.Transparency;
  469. annotAttribsList[AnnotAttrib.NoteText] = stickyAnnotArgs.StickyNote;
  470. annotAttribsList[AnnotAttrib.StickyIcon] = stickyAnnotArgs.IconName;
  471. AddToPropertyPanel("StickyNoteProperty", "StickyNote", stickyAnnotArgs, annotAttribsList);
  472. return stickyAnnotArgs;
  473. }
  474. /// <summary>
  475. /// 矩形
  476. /// </summary>
  477. /// <param name="selectedsquareArgs"></param>
  478. /// <returns></returns>
  479. private AnnotHandlerEventArgs GetRect(SquareAnnotArgs selectedsquareArgs = null)
  480. {
  481. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  482. SquareAnnotArgs squareArgs = null;
  483. if (selectedsquareArgs == null)
  484. {
  485. squareArgs = new SquareAnnotArgs();
  486. squareArgs.LineColor = Colors.Red;
  487. squareArgs.BgColor = Colors.Transparent;
  488. squareArgs.LineWidth = 1;
  489. squareArgs.Transparency = 1;
  490. squareArgs.LineDash = DashStyles.Solid;
  491. squareArgs.Content = string.Empty;
  492. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotSquare);
  493. if (annotProperty != null)
  494. {
  495. squareArgs.LineColor = annotProperty.BorderColor;
  496. squareArgs.BgColor = annotProperty.BackgroundColor;
  497. if (annotProperty.DashArray == null || annotProperty.DashArray.Count == 0)
  498. {
  499. squareArgs.LineDash = DashStyles.Solid;
  500. }
  501. else
  502. {
  503. DashStyle dash = new DashStyle();
  504. foreach (var offset in annotProperty.DashArray)
  505. {
  506. dash.Dashes.Add(offset);
  507. }
  508. squareArgs.LineDash = dash;
  509. }
  510. squareArgs.LineWidth = annotProperty.Thickness;
  511. squareArgs.Transparency = annotProperty.Opacity;
  512. squareArgs.Content = annotProperty.NoteText;
  513. }
  514. }
  515. else
  516. {
  517. squareArgs = selectedsquareArgs;
  518. }
  519. annotAttribsList[AnnotAttrib.Color] = squareArgs.LineColor;
  520. annotAttribsList[AnnotAttrib.FillColor] = squareArgs.BgColor;
  521. annotAttribsList[AnnotAttrib.LineStyle] = squareArgs.LineDash;
  522. annotAttribsList[AnnotAttrib.Thickness] = squareArgs.LineWidth;
  523. annotAttribsList[AnnotAttrib.Transparency] = squareArgs.Transparency;
  524. annotAttribsList[AnnotAttrib.NoteText] = squareArgs.Content;
  525. AddToPropertyPanel("SharpsAnnotProperty", "Rect", squareArgs, annotAttribsList);
  526. return squareArgs;
  527. }
  528. /// <summary>
  529. /// 圆
  530. /// </summary>
  531. /// <param name="selectedcircleAnnotArgs"></param>
  532. /// <returns></returns>
  533. private AnnotHandlerEventArgs GetCircle(CircleAnnotArgs selectedcircleAnnotArgs = null)
  534. {
  535. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  536. CircleAnnotArgs circleAnnotArgs = null;
  537. if (selectedcircleAnnotArgs == null)
  538. {
  539. circleAnnotArgs = new CircleAnnotArgs();
  540. circleAnnotArgs.LineColor = Colors.Red;
  541. circleAnnotArgs.BgColor = Colors.Transparent;
  542. circleAnnotArgs.LineWidth = 1;
  543. circleAnnotArgs.Transparency = 1;
  544. circleAnnotArgs.LineDash = DashStyles.Solid;
  545. circleAnnotArgs.Content = string.Empty;
  546. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotCircle);
  547. if (annotProperty != null)
  548. {
  549. circleAnnotArgs.LineColor = annotProperty.BorderColor;
  550. circleAnnotArgs.BgColor = annotProperty.BackgroundColor;
  551. if (annotProperty.DashArray == null || annotProperty.DashArray.Count == 0)
  552. {
  553. circleAnnotArgs.LineDash = DashStyles.Solid;
  554. }
  555. else
  556. {
  557. DashStyle dash = new DashStyle();
  558. foreach (var offset in annotProperty.DashArray)
  559. {
  560. dash.Dashes.Add(offset);
  561. }
  562. circleAnnotArgs.LineDash = dash;
  563. }
  564. circleAnnotArgs.LineWidth = annotProperty.Thickness;
  565. circleAnnotArgs.Transparency = annotProperty.Opacity;
  566. circleAnnotArgs.Content = annotProperty.NoteText;
  567. }
  568. }
  569. else
  570. {
  571. circleAnnotArgs = selectedcircleAnnotArgs;
  572. }
  573. annotAttribsList[AnnotAttrib.Color] = circleAnnotArgs.LineColor;
  574. annotAttribsList[AnnotAttrib.FillColor] = circleAnnotArgs.BgColor;
  575. annotAttribsList[AnnotAttrib.LineStyle] = circleAnnotArgs.LineDash;
  576. annotAttribsList[AnnotAttrib.Thickness] = circleAnnotArgs.LineWidth;
  577. annotAttribsList[AnnotAttrib.Transparency] = circleAnnotArgs.Transparency;
  578. annotAttribsList[AnnotAttrib.NoteText] = circleAnnotArgs.Content;
  579. AddToPropertyPanel("SharpsAnnotProperty", "Circle", circleAnnotArgs, annotAttribsList);
  580. return circleAnnotArgs;
  581. }
  582. /// <summary>
  583. /// 箭头 线
  584. /// </summary>
  585. /// <param name="TagStr"></param>
  586. /// <param name="selectedLineAnnotArgs"></param>
  587. /// <returns></returns>
  588. private AnnotHandlerEventArgs GetArrowLine(string TagStr, LineAnnotArgs selectedLineAnnotArgs = null)
  589. {
  590. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  591. LineAnnotArgs lineArgs = new LineAnnotArgs();
  592. if (selectedLineAnnotArgs == null)
  593. {
  594. lineArgs.LineColor = Colors.Red;
  595. lineArgs.HeadLineType = C_LINE_TYPE.LINETYPE_NONE;
  596. if (TagStr == "Line")
  597. {
  598. lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_NONE;
  599. }
  600. else
  601. {
  602. lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_ARROW;
  603. }
  604. lineArgs.LineDash = DashStyles.Solid;
  605. lineArgs.LineWidth = 1;
  606. lineArgs.Transparency = 1;
  607. lineArgs.Content = string.Empty;
  608. }
  609. else
  610. {
  611. lineArgs = selectedLineAnnotArgs;
  612. }
  613. DefaultAnnotProperty annotProperty = null;
  614. if (TagStr == "Line")
  615. {
  616. annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotLine, "Line");
  617. if (annotProperty != null)
  618. {
  619. annotProperty.HeadLineType = C_LINE_TYPE.LINETYPE_NONE;
  620. annotProperty.TailLineType = C_LINE_TYPE.LINETYPE_NONE;
  621. }
  622. }
  623. else
  624. {
  625. annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotLine, "Arrow");
  626. }
  627. if (annotProperty != null)
  628. {
  629. lineArgs.LineColor = annotProperty.BorderColor;
  630. lineArgs.HeadLineType = annotProperty.HeadLineType;
  631. lineArgs.TailLineType = annotProperty.TailLineType;
  632. DashStyle dash = new DashStyle();
  633. foreach (var offset in annotProperty.DashArray)
  634. {
  635. dash.Dashes.Add(offset);
  636. }
  637. lineArgs.LineDash = dash;
  638. lineArgs.LineWidth = annotProperty.Thickness;
  639. lineArgs.Transparency = annotProperty.Opacity;
  640. lineArgs.Content = annotProperty.NoteText;
  641. }
  642. annotAttribsList[AnnotAttrib.Color] = lineArgs.LineColor;
  643. annotAttribsList[AnnotAttrib.LineStart] = lineArgs.HeadLineType;
  644. annotAttribsList[AnnotAttrib.LineEnd] = lineArgs.TailLineType;
  645. annotAttribsList[AnnotAttrib.LineStyle] = lineArgs.LineDash;
  646. annotAttribsList[AnnotAttrib.Thickness] = lineArgs.LineWidth;
  647. annotAttribsList[AnnotAttrib.Transparency] = lineArgs.Transparency;
  648. annotAttribsList[AnnotAttrib.NoteText] = lineArgs.Content;
  649. AddToPropertyPanel("SharpsAnnotProperty", TagStr, lineArgs, annotAttribsList);
  650. return lineArgs;
  651. }
  652. /// <summary>
  653. /// 图章
  654. /// </summary>
  655. /// <returns></returns>
  656. private AnnotHandlerEventArgs GetStamp()
  657. {
  658. StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  659. stampAnnotArgs.Opacity = 1;
  660. stampAnnotArgs.StampText = "APPROVED";
  661. stampAnnotArgs.Type = StampType.STANDARD_STAMP;
  662. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  663. annotAttribsList[AnnotAttrib.Transparency] = stampAnnotArgs.Opacity;
  664. AddToPropertyPanel("StampAnnotProperty", null, stampAnnotArgs, annotAttribsList);
  665. return null;
  666. }
  667. /// <summary>
  668. /// 签名
  669. /// </summary>
  670. /// <returns></returns>
  671. private AnnotHandlerEventArgs GetSignature()
  672. {
  673. AddToPropertyPanel("SignatureAnnotProperty");
  674. return null;
  675. }
  676. private AnnotHandlerEventArgs GetImage()
  677. {
  678. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  679. StampAnnotArgs stampArgs = new StampAnnotArgs();
  680. stampArgs.Opacity = 1;
  681. stampArgs.Type = StampType.IMAGE_STAMP;
  682. OpenFileDialog openFileDialog = new OpenFileDialog();
  683. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  684. if (openFileDialog.ShowDialog() == true)
  685. {
  686. stampArgs.ImagePath = openFileDialog.FileName;
  687. }
  688. AddToPropertyPanel("ImageAnnotProperty", null, stampArgs, annotAttribsList);
  689. return stampArgs;
  690. }
  691. /// <summary>
  692. /// 内容选择
  693. /// </summary>
  694. /// <param name="annotBtn"></param>
  695. /// <returns></returns>
  696. private AnnotHandlerEventArgs GetSnapshotEdit()
  697. {
  698. SnapshotEditToolArgs snapshotArgs = new SnapshotEditToolArgs();
  699. //SnapshotEditMenuViewModel snapshotEditMenuViewModel = new SnapshotEditMenuViewModel();
  700. snapshotArgs.ControlPointColor = Colors.White;
  701. snapshotArgs.BgColor = Color.FromArgb(0x99, 0x00, 0x00, 0x00);
  702. snapshotArgs.LineColor = Color.FromArgb(0xFF, 0x47, 0x7E, 0xDE);
  703. SnapshotEditMenuViewModel.SnapToolArgs = snapshotArgs;
  704. SnapshotEditMenuViewModel.PDFViewer = PDFViewer;
  705. SnapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  706. #region to do
  707. //SnapshotEditMenu snapMenu = new SnapshotEditMenu();
  708. //snapshotArgs.ToolPanel = snapMenu;
  709. //SnapshotEditMenuViewModel snapshotEditMenuViewModel = (SnapshotEditMenuViewModel)snapMenu.DataContext;
  710. //snapshotEditMenuViewModel.SnapToolArgs = snapshotArgs;
  711. //snapshotEditMenuViewModel.PDFViewer = PDFViewer;
  712. //snapshotEditMenuViewModel.ToggleBtn = annotBtn;
  713. //snapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  714. //SnapshotEditMenuViewModel = snapshotEditMenuViewModel;
  715. #endregion to do
  716. return snapshotArgs;
  717. }
  718. /// <summary>
  719. /// 导航到同一个注释xaml时,需要区分某个注释;比如高亮、删除线、下划线
  720. /// </summary>
  721. /// <param name="viewContent">对应的注释面板</param>
  722. /// <param name="toolTag">导航到同一个注释xaml时,需要区分某个注释;比如高亮、删除线、下划线</param>
  723. /// <param name="annot">注释</param>
  724. /// <param name="annotAttribsList">更改注释属性的键值对,更改值后会自动记录undoRedo容器里</param>
  725. private void AddToPropertyPanel(string viewContent, string toolTag = null, AnnotHandlerEventArgs annot = null, Dictionary<AnnotAttrib, object> annotAttribsList = null, AnnotAttribEvent annotAttribEvent = null)
  726. {
  727. //if (string.IsNullOrEmpty(toolTag) == false)
  728. //{
  729. // if (!ToolExpandDict.ContainsKey(toolTag))
  730. // {
  731. // ToolExpandDict[toolTag] = true;
  732. // }
  733. //}
  734. if (annot != null)
  735. propertyPanel.annot = annot;
  736. if (annotAttribsList != null)
  737. {
  738. propertyPanel.AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annotAttribsList);
  739. if (annot is LinkAnnotArgs && annotAttribEvent != null)
  740. {
  741. propertyPanel.AnnotEvent = annotAttribEvent;
  742. }
  743. }
  744. if (string.IsNullOrEmpty(viewContent) == false)
  745. {
  746. viewContentViewModel.SelectedPrpoertyPanel(viewContent, propertyPanel);
  747. }
  748. }
  749. #endregion 注释工具
  750. #region 属性面板
  751. /// <summary>
  752. /// 展开显示属性面板
  753. /// </summary>
  754. private void ShowPropertyPanel(bool show = true)
  755. {
  756. viewContentViewModel.IsPropertyOpen = show;
  757. }
  758. #endregion
  759. #region 菜单
  760. private ContextMenu ViewerContextMenu()
  761. {
  762. ContextMenu contextMenu = App.Current.FindResource("ViewerContextMenu") as ContextMenu;
  763. //contextMenu.Loaded += ContextMenu_Loaded;
  764. ContextMenu_Loaded(contextMenu, null);
  765. return contextMenu;
  766. }
  767. private void ContextMenu_Loaded(object sender, RoutedEventArgs e)
  768. {
  769. ContextMenu contextMenu = sender as ContextMenu;
  770. if (contextMenu.Items.Count > 0)
  771. {
  772. int index = PDFViewer.CurrentIndex;
  773. //检测是否已存在相同数据
  774. CPDFBookmark list = PDFViewer.Document.GetBookmarkList().FirstOrDefault(q => q.PageIndex == index);
  775. if (list != null)
  776. {
  777. isAddBookMark = false;
  778. }
  779. else
  780. {
  781. isAddBookMark = true;
  782. }
  783. foreach (var item in contextMenu.Items)
  784. {
  785. if (item is MenuItem menuItem1)
  786. {
  787. //if (menuItem1.Tag.ToString() == "DisplayAnnot" || menuItem1.Tag.ToString() == "HiddenAnnot")
  788. //{
  789. // SetMenuItemVisibility(menuItem1, "DisplayAnnot", "HiddenAnnot", isHiddenAnnot);
  790. //}
  791. switch (menuItem1.Tag.ToString())
  792. {
  793. case "Copy":
  794. //粘贴
  795. if (!ApplicationCommands.Paste.CanExecute(null, (UIElement)sender))
  796. {
  797. menuItem1.IsEnabled = false;
  798. menuItem1.Opacity = 0.5;
  799. }
  800. else
  801. {
  802. menuItem1.IsEnabled = true;
  803. menuItem1.Opacity = 1;
  804. }
  805. menuItem1.CommandTarget = (UIElement)sender;
  806. menuItem1.Command = ApplicationCommands.Copy;
  807. break;
  808. case "AddAnnotation":
  809. if (menuItem1.Items.Count > 0)
  810. {
  811. SetAddAnnotation(menuItem1.Items);
  812. }
  813. break;
  814. case "HiddenAnnot":
  815. menuItem1.Click -= HiddenAnnot_Click;
  816. menuItem1.Click += HiddenAnnot_Click;
  817. SetMenuItemVisibility(menuItem1, "DisplayAnnot", "HiddenAnnot", isHiddenAnnot);
  818. break;
  819. case "DisplayAnnot":
  820. menuItem1.Click -= DisplayAnnot_Click;
  821. menuItem1.Click += DisplayAnnot_Click;
  822. SetMenuItemVisibility(menuItem1, "DisplayAnnot", "HiddenAnnot", isHiddenAnnot);
  823. break;
  824. case "AddBookMark":
  825. //if (isAddBookMark)
  826. //{
  827. // menuItem1.Visibility = Visibility.Visible;
  828. //}
  829. menuItem1.Click -= AddBookMark_Click;
  830. menuItem1.Click += AddBookMark_Click;
  831. SetMenuItemVisibility(menuItem1, "DelBookMark", "AddBookMark", isAddBookMark);
  832. break;
  833. case "DelBookMark":
  834. //if (isAddBookMark == false)
  835. //{
  836. // menuItem1.Visibility = Visibility.Visible;
  837. //}
  838. menuItem1.Click -= DelBookMark_Click;
  839. menuItem1.Click += DelBookMark_Click;
  840. SetMenuItemVisibility(menuItem1, "DelBookMark", "AddBookMark", isAddBookMark);
  841. break;
  842. case "ToolMode":
  843. if (menuItem1.Items.Count > 0)
  844. {
  845. SetToolMode(menuItem1.Items);
  846. }
  847. break;
  848. case "ReadModel":
  849. SetMenuItemVisibility(menuItem1, "ReadModel", "UnReadModel", App.IsBookMode);
  850. menuItem1.Click -= ReadModel_Click;
  851. menuItem1.Click += ReadModel_Click;
  852. break;
  853. case "UnReadModel":
  854. SetMenuItemVisibility(menuItem1, "ReadModel", "UnReadModel", App.IsBookMode);
  855. menuItem1.Click -= UnReadModel_Click;
  856. menuItem1.Click += UnReadModel_Click;
  857. break;
  858. case "ViewZoom":
  859. if (menuItem1.Items.Count > 0)
  860. {
  861. ViewZoom(menuItem1.Items);
  862. }
  863. break;
  864. case "PageDisplay":
  865. if (menuItem1.Items.Count > 0)
  866. {
  867. PageDisplay(menuItem1.Items);
  868. }
  869. break;
  870. case "Select":
  871. menuItem1.Click -= Select_Click;
  872. menuItem1.Click += Select_Click;
  873. break;
  874. case "Print":
  875. menuItem1.Command = viewContentViewModel.PrintCommand;
  876. break;
  877. }
  878. }
  879. }
  880. }
  881. }
  882. private void SetMenuItemVisibility(MenuItem menuItem1, string v2, string v3, bool flag)
  883. {
  884. if (menuItem1.Tag.ToString() == v2 && flag)
  885. {
  886. menuItem1.Visibility = Visibility.Collapsed;
  887. }
  888. if (menuItem1.Tag.ToString() == v2 && flag == false)
  889. {
  890. menuItem1.Visibility = Visibility.Visible;
  891. }
  892. if (menuItem1.Tag.ToString() == v3 && flag == false)
  893. {
  894. menuItem1.Visibility = Visibility.Collapsed;
  895. }
  896. if (menuItem1.Tag.ToString() == v3 && flag)
  897. {
  898. menuItem1.Visibility = Visibility.Visible;
  899. }
  900. }
  901. private ContextMenu SelectAnnotContextMenu(object sender)
  902. {
  903. var popMenu = App.Current.FindResource("SelectAnnotContextMenu") as ContextMenu;
  904. if (popMenu != null && popMenu.Items.Count == 4)
  905. {
  906. //剪切
  907. MenuItem menuItem = popMenu.Items[0] as MenuItem;
  908. menuItem.CommandTarget = (UIElement)sender;
  909. menuItem.Command = ApplicationCommands.Cut;
  910. //复制
  911. menuItem = popMenu.Items[1] as MenuItem;
  912. menuItem.CommandTarget = (UIElement)sender;
  913. menuItem.Command = ApplicationCommands.Copy;
  914. //删除
  915. menuItem = popMenu.Items[2] as MenuItem;
  916. menuItem.CommandTarget = (UIElement)sender;
  917. menuItem.Command = ApplicationCommands.Delete;
  918. //笔记
  919. //menuItem = popMenu.Items[2] as MenuItem;
  920. //menuItem.CommandTarget = (UIElement)sender;
  921. //menuItem.Command = ApplicationCommands.no;
  922. }
  923. return popMenu;
  924. }
  925. private ContextMenu NoneSelectAnnotContextMenu(object sender, AnnotCommandArgs annotCommand)
  926. {
  927. ContextMenu popMenu = new ContextMenu();
  928. popMenu.FontSize = 14;
  929. MenuItem menuItem = new MenuItem();
  930. menuItem = new MenuItem();
  931. menuItem.CommandTarget = (UIElement)sender;
  932. menuItem.Command = ApplicationCommands.Copy;
  933. popMenu.Items.Add(menuItem);
  934. menuItem = new MenuItem();
  935. menuItem.CommandTarget = (UIElement)sender;
  936. menuItem.Command = ApplicationCommands.Paste;
  937. popMenu.Items.Add(menuItem);
  938. menuItem = new MenuItem();
  939. menuItem.CommandTarget = (UIElement)sender;
  940. menuItem.Header = "创建链接";
  941. menuItem.CommandParameter = new object[] { this, annotCommand };
  942. menuItem.Command = viewContentViewModel.CreateLinkCommand;
  943. menuItem.Click += MenuItem_Click;
  944. popMenu.Items.Add(menuItem);
  945. return popMenu;
  946. }
  947. #endregion
  948. }
  949. }