AnnotToolContentViewModel.Function.cs 79 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKit.PDFDocument;
  3. using ComPDFKitViewer;
  4. using ComPDFKitViewer.AnnotEvent;
  5. using ComPDFKitViewer.PdfViewer;
  6. using Dropbox.Api.TeamLog;
  7. using Microsoft.Office.Core;
  8. using Microsoft.Win32;
  9. using PDF_Office.CustomControl;
  10. using PDF_Office.EventAggregators;
  11. using PDF_Office.Helper;
  12. using PDF_Office.Model;
  13. using PDF_Office.Model.BOTA;
  14. using PDF_Office.Properties;
  15. using PDF_Office.ViewModels.BOTA;
  16. using PDF_Office.ViewModels.PropertyPanel.AnnotPanel;
  17. using PDF_Office.ViewModels.Tools.AnnotManager;
  18. using PDF_Office.Views.BOTA;
  19. using PDF_Office.Views.PropertyPanel.AnnotPanel;
  20. using PDFSettings;
  21. using Prism.Mvvm;
  22. using Prism.Regions;
  23. using Prism.Services.Dialogs;
  24. using System;
  25. using System.Collections.Generic;
  26. using System.IO;
  27. using System.Linq;
  28. using System.Text;
  29. using System.Threading.Tasks;
  30. using System.Windows;
  31. using System.Windows.Controls;
  32. using System.Windows.Documents;
  33. using System.Windows.Forms;
  34. using System.Windows.Input;
  35. using System.Windows.Media;
  36. using System.Windows.Media.Imaging;
  37. using static Dropbox.Api.Sharing.ListFileMembersIndividualResult;
  38. using ContextMenu = System.Windows.Controls.ContextMenu;
  39. using HorizontalAlignment = System.Windows.HorizontalAlignment;
  40. using MenuItem = System.Windows.Controls.MenuItem;
  41. using OpenFileDialog = Microsoft.Win32.OpenFileDialog;
  42. namespace PDF_Office.ViewModels.Tools
  43. {
  44. //文件说明:初始化注释工具的数据,注释工具,菜单响应事件
  45. public sealed partial class AnnotToolContentViewModel : BindableBase, INavigationAware
  46. {
  47. #region 初始化
  48. #region 初始化数据
  49. //初始化注释的属性值,并存在本地缓存数据集里
  50. private void InitDefaultValue()
  51. {
  52. InitToolBtnUI();
  53. }
  54. //注释工具按钮初始化时的属性值
  55. private void InitToolBtnUI()
  56. {
  57. InitAnnotHighlight();
  58. InitAnnotUnderline();
  59. InitAnnotSquiggly();
  60. InitAnnotStrikeout();
  61. }
  62. private void InitAnnotHighlight()
  63. {
  64. var annotate = Settings.Default.AppProperties.Annotate;
  65. if (annotate != null && annotate.HighLightColor != Colors.Transparent)
  66. {
  67. HighLightColor = new SolidColorBrush(annotate.HighLightColor);
  68. HighLightOpacity = 1;
  69. }
  70. else
  71. {
  72. HighLightColor = new SolidColorBrush(Colors.Red);
  73. HighLightOpacity = 1;
  74. }
  75. }
  76. private void InitAnnotUnderline()
  77. {
  78. var annotate = Settings.Default.AppProperties.Annotate;
  79. //避免默认值为透明度
  80. if (annotate != null && annotate.UnderLineColor != Colors.Transparent)
  81. {
  82. UnderLineColor = new SolidColorBrush(annotate.UnderLineColor);
  83. HighLightOpacity = 1;
  84. }
  85. else
  86. {
  87. UnderLineColor = new SolidColorBrush(Colors.Red);
  88. UnderLineOpacity = 1;
  89. }
  90. }
  91. private void InitAnnotSquiggly()
  92. {
  93. var annotate = Settings.Default.AppProperties.Annotate;
  94. if (annotate != null && annotate.StrikethroughColor != Colors.Transparent)
  95. {
  96. SquigglyColor = new SolidColorBrush(annotate.StrikethroughColor);
  97. SquigglyOpacity = 1;
  98. }
  99. else
  100. {
  101. SquigglyColor = new SolidColorBrush(Colors.Red);
  102. SquigglyOpacity = 1;
  103. }
  104. }
  105. private void InitAnnotStrikeout()
  106. {
  107. var annotate = Settings.Default.AppProperties.Annotate;
  108. if (annotate != null && annotate.StrikethroughColor != Colors.Transparent)
  109. {
  110. StrikeoutColor = new SolidColorBrush(annotate.StrikethroughColor);
  111. StrikeoutOpacity = 1;
  112. }
  113. else
  114. {
  115. StrikeoutColor = new SolidColorBrush(Colors.Red);
  116. StrikeoutOpacity = 1;
  117. }
  118. }
  119. //在xaml里引用
  120. public Dictionary<string, string> GetToolTipDict
  121. { get { return ToolTipDict; } }
  122. //用来记录选中、创建注释的标识
  123. private void InitToolDict()
  124. {
  125. ToolExpandDict.Add("SnapshotEdit", AnnotArgsType.SnapshotWithEditTool);
  126. ToolExpandDict.Add("HighLight", AnnotArgsType.AnnotHighlight);
  127. ToolExpandDict.Add("UnderLine", AnnotArgsType.AnnotUnderline);
  128. ToolExpandDict.Add("Squiggly", AnnotArgsType.AnnotSquiggly);
  129. ToolExpandDict.Add("Strikeout", AnnotArgsType.AnnotStrikeout);
  130. ToolExpandDict.Add("Freehand", AnnotArgsType.AnnotFreehand);
  131. ToolExpandDict.Add("Freetext", AnnotArgsType.AnnotFreeText);
  132. ToolExpandDict.Add("StickyNote", AnnotArgsType.AnnotSticky);
  133. ToolExpandDict.Add("Rect", AnnotArgsType.AnnotSquare);
  134. ToolExpandDict.Add("Circle", AnnotArgsType.AnnotCircle);
  135. ToolExpandDict.Add("Arrow", AnnotArgsType.AnnotLine);
  136. ToolExpandDict.Add("Line", AnnotArgsType.AnnotLine);
  137. ToolExpandDict.Add("Link", AnnotArgsType.AnnotLink);
  138. }
  139. //注释工具按钮悬浮文案
  140. private void InitToolTipDict()
  141. {
  142. ToolTipDict.Add("Hand", "滚动工具");
  143. ToolTipDict.Add("BtnSelecttool", "内容选择工具");
  144. ToolTipDict.Add("SnapshotEdit", "内容选择工具");
  145. ToolTipDict.Add("HighLight", "高亮" + " | Ctrl+Alt+H");
  146. ToolTipDict.Add("UnderLine", "高亮" + " | Ctrl+Alt+U");
  147. ToolTipDict.Add("Squiggly", "波浪线" + " | Ctrl+Alt+Q");
  148. ToolTipDict.Add("Strikeout", "删除线" + " | Ctrl+Alt+S");
  149. ToolTipDict.Add("Freehand", "手绘");
  150. ToolTipDict.Add("Freetext", "文字");
  151. ToolTipDict.Add("StickyNote", "便签");
  152. ToolTipDict.Add("Rect", "矩形");
  153. ToolTipDict.Add("Circle", "圆");
  154. ToolTipDict.Add("Arrow", "箭头");
  155. ToolTipDict.Add("Line", "线条");
  156. ToolTipDict.Add("Link", "超链接");
  157. ToolTipDict.Add("Stamp", "图章");
  158. ToolTipDict.Add("Image", "图片");
  159. ToolTipDict.Add("Signature", "签名");
  160. ToolTipDict.Add("ShowAnnot", "显示/隐藏注释");
  161. }
  162. //便签批注弹窗
  163. private void LoaedStickyNotePopup()
  164. {
  165. if (PDFViewer == null) return;
  166. if (customStickyPopup == null)
  167. {
  168. customStickyPopup = new StickyNotePopup();
  169. PDFViewer.SetStickyNotePop(customStickyPopup);
  170. }
  171. }
  172. #endregion 初始化数据
  173. #endregion 初始化
  174. #region 注释工具
  175. //注释工具
  176. private void FindAnnotTypeKey(string tag, ref AnnotHandlerEventArgs annotArgs, bool isRightMenuAdd = false)
  177. {
  178. switch (tag)
  179. {
  180. case "SnapshotEdit"://内容选择
  181. annotArgs = GetSnapshotEdit();
  182. break;
  183. case "HighLight"://字体高亮
  184. annotArgs = GetHighLight();
  185. break;
  186. case "UnderLine"://下划线
  187. annotArgs = GetUnderLine();
  188. break;
  189. case "Squiggly"://波浪线
  190. annotArgs = GetSquiggly();
  191. break;
  192. case "Strikeout"://删除线
  193. annotArgs = GetStrikeout();
  194. break;
  195. case "Freehand"://手绘
  196. annotArgs = GetFreehand();
  197. break;
  198. case "Freetext"://文本
  199. annotArgs = GetFreetext();
  200. break;
  201. case "StickyNote"://便签
  202. annotArgs = GetStickyNote();
  203. break;
  204. case "Rect"://矩形
  205. annotArgs = GetRect();
  206. break;
  207. case "Circle"://圆
  208. annotArgs = GetCircle();
  209. break;
  210. case "Arrow"://箭头
  211. case "Line"://线
  212. annotArgs = GetArrowLine(tag);
  213. break;
  214. case "Stamp"://图章
  215. //付费锁
  216. if (!App.IsLogin)
  217. {
  218. dialogs.ShowDialog(DialogNames.IAPCompareDialog);
  219. return;
  220. }
  221. annotArgs = GetStamp();
  222. break;
  223. case "Image":
  224. annotArgs = GetImage();
  225. break;
  226. case "Signature"://签名
  227. //付费锁
  228. if (!App.IsLogin)
  229. {
  230. dialogs.ShowDialog(DialogNames.IAPCompareDialog);
  231. return;
  232. }
  233. annotArgs = GetSignature();
  234. PDFViewer.SetMouseMode(MouseModes.PanTool);//清空其他注释
  235. break;
  236. case "Link"://链接
  237. //付费锁
  238. if (!App.IsLogin)
  239. {
  240. dialogs.ShowDialog(DialogNames.IAPCompareDialog);
  241. return;
  242. }
  243. propertyPanel.IsAddLink = true;
  244. viewContentViewModel.IsRightMenuCreateLink = isRightMenuAdd;
  245. annotArgs = GetLink();
  246. break;
  247. }
  248. if (annotArgs != null)
  249. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  250. }
  251. /// <summary>
  252. /// 高亮注释
  253. /// </summary>
  254. private AnnotHandlerEventArgs GetHighLight(List<AnnotHandlerEventArgs> selectedArgs = null)
  255. {
  256. TextHighlightAnnotArgs highlightArgs = null;
  257. if (selectedArgs == null || selectedArgs.Count == 0)
  258. {
  259. highlightArgs = new TextHighlightAnnotArgs();
  260. highlightArgs.Transparency = highLightOpacity;
  261. highlightArgs.Color = (highLightColor as SolidColorBrush).Color;
  262. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(highlightArgs.EventType);
  263. if (defaultAnnot == null)
  264. {
  265. defaultAnnot = new DefaultAnnotProperty();
  266. defaultAnnot.AnnotToolType = highlightArgs.EventType;
  267. defaultAnnot.ForgoundColor = (highLightColor as SolidColorBrush).Color;
  268. defaultAnnot.Opacity = 1;
  269. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  270. Settings.Default.Save();
  271. }
  272. highLightOpacity = highlightArgs.Transparency = defaultAnnot.Opacity;
  273. selectedArgs = new List<AnnotHandlerEventArgs>();
  274. selectedArgs.Add(highlightArgs);
  275. }
  276. else
  277. {
  278. highlightArgs = selectedArgs[0] as TextHighlightAnnotArgs;
  279. }
  280. AddToPropertyPanel("TextAnnotProperty", "HighLight", selectedArgs);
  281. return highlightArgs;
  282. }
  283. /// <summary>
  284. /// 链接
  285. /// </summary>
  286. /// <param name="selectedArgs">所选中的注释</param>
  287. /// <param name="annotAttribEvent">注释属性列表</param>
  288. public AnnotHandlerEventArgs GetLink(List<AnnotHandlerEventArgs> selectedArgs = null, AnnotAttribEvent annotAttribEvent = null)
  289. {
  290. LinkAnnotArgs linkArgs = new LinkAnnotArgs();
  291. if (selectedArgs != null && selectedArgs.Count > 0)
  292. {
  293. linkArgs = selectedArgs[0] as LinkAnnotArgs;
  294. }
  295. else
  296. {
  297. linkArgs.URI = string.Empty;
  298. linkArgs.LinkType = LINK_TYPE.GOTO;
  299. linkArgs.DestIndex = -1;
  300. if (linkArgs != null)
  301. {
  302. selectedArgs = new List<AnnotHandlerEventArgs>();
  303. selectedArgs.Add(linkArgs);
  304. }
  305. }
  306. AddToPropertyPanel("LinkAnnotProperty", "Link", selectedArgs, annotAttribEvent);
  307. return linkArgs;
  308. }
  309. /// <summary>
  310. /// 下划线
  311. /// </summary>
  312. /// <param name="selectedArgs"></param>
  313. private AnnotHandlerEventArgs GetUnderLine(List<AnnotHandlerEventArgs> selectedArgs = null)
  314. {
  315. TextUnderlineAnnotArgs underlineArgs = null;
  316. if (selectedArgs == null || selectedArgs.Count == 0)
  317. {
  318. underlineArgs = new TextUnderlineAnnotArgs();
  319. underlineArgs.Transparency = UnderLineOpacity;
  320. underlineArgs.Color = (UnderLineColor as SolidColorBrush).Color;
  321. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(underlineArgs.EventType);
  322. if (defaultAnnot == null)
  323. {
  324. defaultAnnot = new DefaultAnnotProperty();
  325. defaultAnnot.AnnotToolType = underlineArgs.EventType;
  326. defaultAnnot.ForgoundColor = (UnderLineColor as SolidColorBrush).Color;
  327. defaultAnnot.Opacity = 1;
  328. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  329. Settings.Default.Save();
  330. }
  331. UnderLineOpacity = underlineArgs.Transparency = defaultAnnot.Opacity;
  332. selectedArgs = new List<AnnotHandlerEventArgs>();
  333. selectedArgs.Add(underlineArgs);
  334. }
  335. else
  336. {
  337. underlineArgs = selectedArgs[0] as TextUnderlineAnnotArgs;
  338. }
  339. AddToPropertyPanel("TextAnnotProperty", "UnderLine", selectedArgs);
  340. return underlineArgs;
  341. }
  342. /// <summary>
  343. /// 波浪线
  344. /// </summary>
  345. /// <param name="selectedArgs"></param>
  346. /// <returns></returns>
  347. private AnnotHandlerEventArgs GetSquiggly(List<AnnotHandlerEventArgs> selectedArgs = null)
  348. {
  349. TextSquigglyAnnotArgs squigglyArgs = null;
  350. if (selectedArgs == null || selectedArgs.Count == 0)
  351. {
  352. squigglyArgs = new TextSquigglyAnnotArgs();
  353. squigglyArgs.Transparency = SquigglyOpacity;
  354. squigglyArgs.Color = (squigglyColor as SolidColorBrush).Color;
  355. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(squigglyArgs.EventType);
  356. if (defaultAnnot == null)
  357. {
  358. defaultAnnot = new DefaultAnnotProperty();
  359. defaultAnnot.AnnotToolType = squigglyArgs.EventType;
  360. defaultAnnot.ForgoundColor = (squigglyColor as SolidColorBrush).Color;
  361. defaultAnnot.Opacity = 1;
  362. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  363. Settings.Default.Save();
  364. }
  365. SquigglyOpacity = squigglyArgs.Transparency = defaultAnnot.Opacity;
  366. selectedArgs = new List<AnnotHandlerEventArgs>();
  367. selectedArgs.Add(squigglyArgs);
  368. }
  369. else
  370. {
  371. squigglyArgs = selectedArgs[0] as TextSquigglyAnnotArgs;
  372. }
  373. AddToPropertyPanel("TextAnnotProperty", "Squiggly", selectedArgs);
  374. return squigglyArgs;
  375. }
  376. /// <summary>
  377. /// 删除线
  378. /// </summary>
  379. /// <param name="selectedArgs"></param>
  380. /// <returns></returns>
  381. private AnnotHandlerEventArgs GetStrikeout(List<AnnotHandlerEventArgs> selectedArgs = null)
  382. {
  383. TextStrikeoutAnnotArgs strikeoutArgs = null;
  384. if (selectedArgs == null || selectedArgs.Count == 0)
  385. {
  386. strikeoutArgs = new TextStrikeoutAnnotArgs();
  387. strikeoutArgs.Transparency = strikeoutOpacity;
  388. strikeoutArgs.Color = (strikeoutColor as SolidColorBrush).Color;
  389. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(strikeoutArgs.EventType);
  390. if (defaultAnnot == null)
  391. {
  392. defaultAnnot = new DefaultAnnotProperty();
  393. defaultAnnot.AnnotToolType = strikeoutArgs.EventType;
  394. defaultAnnot.ForgoundColor = (strikeoutColor as SolidColorBrush).Color;
  395. defaultAnnot.Opacity = 1;
  396. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  397. Settings.Default.Save();
  398. }
  399. strikeoutArgs.Transparency = defaultAnnot.Opacity;
  400. selectedArgs = new List<AnnotHandlerEventArgs>();
  401. selectedArgs.Add(strikeoutArgs);
  402. }
  403. else
  404. {
  405. strikeoutArgs = selectedArgs[0] as TextStrikeoutAnnotArgs;
  406. }
  407. AddToPropertyPanel("TextAnnotProperty", "Strikeout", selectedArgs);
  408. return strikeoutArgs;
  409. }
  410. /// <summary>
  411. /// 手绘
  412. /// </summary>
  413. /// <param name="selectedArgs"></param>
  414. /// <returns></returns>
  415. private AnnotHandlerEventArgs GetFreehand(List<AnnotHandlerEventArgs> selectedArgs = null)
  416. {
  417. FreehandAnnotArgs freehandArgs = null;
  418. if (selectedArgs == null || selectedArgs.Count == 0)
  419. {
  420. freehandArgs = new FreehandAnnotArgs();
  421. var annotate = Settings.Default.AppProperties.Annotate;
  422. if (annotate != null)
  423. {
  424. freehandArgs.InkColor = annotate.FreeHandColor;
  425. }
  426. else
  427. {
  428. freehandArgs.InkColor = Color.FromRgb(0x38, 0xE0, 0x2E);
  429. }
  430. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(freehandArgs.EventType);
  431. if (defaultAnnot == null)
  432. {
  433. defaultAnnot = new DefaultAnnotProperty();
  434. defaultAnnot.AnnotToolType = freehandArgs.EventType;
  435. defaultAnnot.ForgoundColor = annotate.FreeHandColor;
  436. defaultAnnot.Opacity = 1;
  437. defaultAnnot.Thickness = 2;
  438. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  439. Settings.Default.Save();
  440. }
  441. freehandArgs.Transparency = defaultAnnot.Opacity;
  442. freehandArgs.LineWidth = defaultAnnot.Thickness;
  443. if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
  444. {
  445. freehandArgs.LineDash = DashStyles.Solid;
  446. }
  447. else
  448. {
  449. var collect = new DoubleCollection();
  450. foreach (var item in defaultAnnot.DashArray)
  451. {
  452. collect.Add(item);
  453. }
  454. if (freehandArgs.LineDash == null)
  455. freehandArgs.LineDash = new DashStyle();
  456. freehandArgs.LineDash.Dashes = collect;
  457. }
  458. selectedArgs = new List<AnnotHandlerEventArgs>();
  459. selectedArgs.Add(freehandArgs);
  460. }
  461. else
  462. {
  463. freehandArgs = selectedArgs[0] as FreehandAnnotArgs;
  464. if (NavigatedToFillAndSignVM(selectedArgs, "Freehand"))
  465. {
  466. return freehandArgs;
  467. }
  468. }
  469. AddToPropertyPanel("FreehandAnnotProperty", "Freehand", selectedArgs);
  470. return freehandArgs;
  471. }
  472. /// <summary>
  473. /// 文本
  474. /// </summary>
  475. /// <param name="selectedArgs"></param>
  476. /// <returns></returns>
  477. private AnnotHandlerEventArgs GetFreetext(List<AnnotHandlerEventArgs> selectedArgs = null)
  478. {
  479. FreeTextAnnotArgs freetextArgs = null;
  480. TextAlignment textAlignment;
  481. if (selectedArgs == null || selectedArgs.Count == 0)
  482. {
  483. freetextArgs = new FreeTextAnnotArgs();
  484. var annotate = Settings.Default.AppProperties.Annotate;
  485. if (annotate != null)
  486. {
  487. freetextArgs.FontColor = annotate.TextAnnoteColor;
  488. }
  489. else
  490. {
  491. freetextArgs.FontColor = Colors.Black;
  492. }
  493. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(freetextArgs.EventType);
  494. if (defaultAnnot == null)
  495. {
  496. defaultAnnot = new DefaultAnnotProperty();
  497. defaultAnnot.AnnotToolType = freetextArgs.EventType;
  498. defaultAnnot.ForgoundColor = freetextArgs.FontColor;
  499. defaultAnnot.BorderColor = Colors.Transparent;
  500. defaultAnnot.BackgroundColor = Colors.Transparent;
  501. defaultAnnot.Opacity = 1;
  502. defaultAnnot.FontFamily = Settings.Default.AppProperties.Annotate.TextFontFamaily;
  503. defaultAnnot.FontSize = 14;
  504. defaultAnnot.TextAlign = TextAlignment.Left;
  505. defaultAnnot.Thickness = 0;
  506. defaultAnnot.NoteText = string.Empty;
  507. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  508. Settings.Default.Save();
  509. }
  510. freetextArgs.FontColor = defaultAnnot.ForgoundColor;
  511. freetextArgs.LineColor = defaultAnnot.BorderColor;
  512. freetextArgs.BgColor = defaultAnnot.BackgroundColor;
  513. freetextArgs.Transparency = defaultAnnot.Opacity;
  514. freetextArgs.FontFamily = new FontFamily(defaultAnnot.FontFamily);
  515. freetextArgs.FontSize = defaultAnnot.FontSize;
  516. freetextArgs.FontWeight = defaultAnnot.FontWeight;
  517. freetextArgs.FontStyle = defaultAnnot.FontStyle;
  518. freetextArgs.LineWidth = defaultAnnot.Thickness;
  519. int align = (int)Settings.Default.AppProperties.Annotate.TextAlign;
  520. if (align == 0)
  521. textAlignment = TextAlignment.Left;
  522. else if (align == 1)
  523. textAlignment = TextAlignment.Center;
  524. else
  525. textAlignment = TextAlignment.Right;
  526. freetextArgs.Align = textAlignment;
  527. if (freetextArgs != null)
  528. {
  529. selectedArgs = new List<AnnotHandlerEventArgs>();
  530. selectedArgs.Add(freetextArgs);
  531. }
  532. }
  533. else
  534. {
  535. freetextArgs = selectedArgs[0] as FreeTextAnnotArgs;
  536. textAlignment = freetextArgs.Align;
  537. if (NavigatedToFillAndSignVM(selectedArgs, "Freetext"))
  538. {
  539. return freetextArgs;
  540. }
  541. }
  542. AddToPropertyPanel("FreetextAnnotProperty", "Freetext", selectedArgs);
  543. return freetextArgs;
  544. }
  545. //Event导航到填写与签名的属性面板
  546. private bool NavigatedToFillAndSignVM(List<AnnotHandlerEventArgs> annots, string tag)
  547. {
  548. if (viewContentViewModel.FillAndSign != null && viewContentViewModel.FillAndSign.Count > 0 && annots != null && annots.Count > 0)
  549. {
  550. var annotFillAndSign = viewContentViewModel.FillAndSign.FirstOrDefault(temp => temp.Item1 == annots[0].PageIndex && temp.Item2 == annots[0].AnnotIndex);
  551. if (annotFillAndSign != null)
  552. {
  553. this.events.GetEvent<FillAndSignEvent>().Publish(new FillAndSigntEventArgs { Unicode = tag, AppUnicode = App.mainWindowViewModel.SelectedItem.Unicode, Annots = annots });
  554. return true;
  555. }
  556. }
  557. return false;
  558. }
  559. private void FromFillAndSign(FillAndSigntEventArgs obj)
  560. {
  561. if (obj != null)
  562. {
  563. if (string.IsNullOrEmpty(obj.Unicode) == false)
  564. {
  565. if (obj.Unicode == "Clear")
  566. {
  567. AnnotSignatures.Clear();
  568. }
  569. }
  570. }
  571. }
  572. /// <summary>
  573. /// 便签
  574. /// </summary>
  575. /// <param name="selectedArgs"></param>
  576. /// <returns></returns>
  577. private AnnotHandlerEventArgs GetStickyNote(List<AnnotHandlerEventArgs> selectedArgs = null)
  578. {
  579. StickyAnnotArgs stickyAnnotArgs = new StickyAnnotArgs();
  580. if (selectedArgs == null || selectedArgs.Count == 0)
  581. {
  582. var annotate = Settings.Default.AppProperties.Annotate;
  583. if (annotate != null)
  584. {
  585. stickyAnnotArgs.Color = annotate.NoteAnnoteColor;
  586. }
  587. else
  588. {
  589. stickyAnnotArgs.Color = Color.FromRgb(0xFF, 0x81, 0x33);
  590. }
  591. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(stickyAnnotArgs.EventType);
  592. if (defaultAnnot == null)
  593. {
  594. defaultAnnot = new DefaultAnnotProperty();
  595. defaultAnnot.AnnotToolType = stickyAnnotArgs.EventType;
  596. defaultAnnot.NoteText = string.Empty;
  597. defaultAnnot.Opacity = 1;
  598. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  599. Settings.Default.Save();
  600. }
  601. stickyAnnotArgs.Transparency = defaultAnnot.Opacity;
  602. if (stickyAnnotArgs != null)
  603. {
  604. selectedArgs = new List<AnnotHandlerEventArgs>();
  605. selectedArgs.Add(stickyAnnotArgs);
  606. }
  607. }
  608. else
  609. {
  610. stickyAnnotArgs = selectedArgs[0] as StickyAnnotArgs;
  611. }
  612. List<AnnotHandlerEventArgs> stickyAnnotArgsList = new List<AnnotHandlerEventArgs>();
  613. if (stickyAnnotArgs != null)
  614. stickyAnnotArgsList.Add(stickyAnnotArgs);
  615. AddToPropertyPanel("StickyNoteProperty", "StickyNote", selectedArgs);
  616. return stickyAnnotArgs;
  617. }
  618. /// <summary>
  619. /// 矩形
  620. /// </summary>
  621. /// <param name="selectedArgs"></param>
  622. /// <returns></returns>
  623. private AnnotHandlerEventArgs GetRect(List<AnnotHandlerEventArgs> selectedArgs = null)
  624. {
  625. SquareAnnotArgs squareArgs = null;
  626. if (selectedArgs == null || selectedArgs.Count == 0)
  627. {
  628. squareArgs = new SquareAnnotArgs();
  629. var annotate = Settings.Default.AppProperties.Annotate;
  630. if (annotate != null)
  631. {
  632. squareArgs.BgColor = annotate.RectangleFillColor;
  633. squareArgs.LineColor = annotate.RectangleBorderColor;
  634. }
  635. else
  636. {
  637. squareArgs.LineColor = Colors.Red;
  638. squareArgs.BgColor = Colors.Red;
  639. }
  640. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(squareArgs.EventType);
  641. if (defaultAnnot == null)
  642. {
  643. defaultAnnot = new DefaultAnnotProperty();
  644. defaultAnnot.AnnotToolType = squareArgs.EventType;
  645. defaultAnnot.Thickness = 1;
  646. defaultAnnot.Opacity = 1;
  647. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  648. Settings.Default.Save();
  649. }
  650. squareArgs.LineWidth = defaultAnnot.Thickness;
  651. squareArgs.Transparency = defaultAnnot.Opacity;
  652. if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
  653. {
  654. squareArgs.LineDash = DashStyles.Solid;
  655. }
  656. else
  657. {
  658. var collect = new DoubleCollection();
  659. foreach (var item in defaultAnnot.DashArray)
  660. {
  661. collect.Add(item);
  662. }
  663. if (squareArgs.LineDash == null)
  664. squareArgs.LineDash = new DashStyle();
  665. squareArgs.LineDash.Dashes = collect;
  666. }
  667. if (squareArgs != null)
  668. {
  669. selectedArgs = new List<AnnotHandlerEventArgs>();
  670. selectedArgs.Add(squareArgs);
  671. }
  672. }
  673. else
  674. {
  675. squareArgs = selectedArgs[0] as SquareAnnotArgs;
  676. }
  677. AddToPropertyPanel("SharpsAnnotProperty", "Rect", selectedArgs);
  678. return squareArgs;
  679. }
  680. /// <summary>
  681. /// 圆
  682. /// </summary>
  683. /// <param name="selectedArgs"></param>
  684. /// <returns></returns>
  685. private AnnotHandlerEventArgs GetCircle(List<AnnotHandlerEventArgs> selectedArgs = null)
  686. {
  687. CircleAnnotArgs circleAnnotArgs = null;
  688. if (selectedArgs == null || selectedArgs.Count == 0)
  689. {
  690. circleAnnotArgs = new CircleAnnotArgs();
  691. var annotate = Settings.Default.AppProperties.Annotate;
  692. if (annotate != null)
  693. {
  694. circleAnnotArgs.LineColor = annotate.CircleBorderColor;
  695. circleAnnotArgs.BgColor = annotate.CircleFillColor;
  696. }
  697. else
  698. {
  699. circleAnnotArgs.LineColor = Colors.Red;
  700. circleAnnotArgs.BgColor = Colors.Red;
  701. }
  702. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(circleAnnotArgs.EventType);
  703. if (defaultAnnot == null)
  704. {
  705. defaultAnnot = new DefaultAnnotProperty();
  706. defaultAnnot.AnnotToolType = circleAnnotArgs.EventType;
  707. defaultAnnot.Thickness = 1;
  708. defaultAnnot.Opacity = 1;
  709. defaultAnnot.NoteText = string.Empty;
  710. defaultAnnot.DashArray = null;
  711. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  712. Settings.Default.Save();
  713. }
  714. circleAnnotArgs.LineWidth = defaultAnnot.Thickness;
  715. circleAnnotArgs.Transparency = defaultAnnot.Opacity;
  716. if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
  717. {
  718. circleAnnotArgs.LineDash = DashStyles.Solid;
  719. }
  720. else
  721. {
  722. var collect = new DoubleCollection();
  723. foreach (var item in defaultAnnot.DashArray)
  724. {
  725. collect.Add(item);
  726. }
  727. if (circleAnnotArgs.LineDash == null)
  728. circleAnnotArgs.LineDash = new DashStyle();
  729. circleAnnotArgs.LineDash.Dashes = collect;
  730. }
  731. if (circleAnnotArgs != null)
  732. {
  733. selectedArgs = new List<AnnotHandlerEventArgs>();
  734. selectedArgs.Add(circleAnnotArgs);
  735. }
  736. }
  737. else
  738. {
  739. circleAnnotArgs = selectedArgs[0] as CircleAnnotArgs;
  740. }
  741. AddToPropertyPanel("SharpsAnnotProperty", "Circle", selectedArgs);
  742. return circleAnnotArgs;
  743. }
  744. /// <summary>
  745. /// 箭头 线
  746. /// </summary>
  747. /// <param name="TagStr"></param>
  748. /// <param name="selectedArgs"></param>
  749. /// <returns></returns>
  750. private AnnotHandlerEventArgs GetArrowLine(string TagStr, List<AnnotHandlerEventArgs> selectedArgs = null)
  751. {
  752. LineAnnotArgs lineArgs = new LineAnnotArgs();
  753. if (selectedArgs == null || selectedArgs.Count == 0)
  754. {
  755. var annotate = Settings.Default.AppProperties.Annotate;
  756. if (annotate != null)
  757. {
  758. lineArgs.LineColor = annotate.LineColor;
  759. }
  760. else
  761. {
  762. lineArgs.LineColor = Colors.Red;
  763. }
  764. lineArgs.LineColor = Colors.Red;
  765. lineArgs.HeadLineType = C_LINE_TYPE.LINETYPE_NONE;
  766. if (TagStr == "Line")
  767. {
  768. lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_NONE;
  769. }
  770. else
  771. {
  772. lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_ARROW;
  773. }
  774. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(lineArgs.EventType);
  775. if (defaultAnnot == null)
  776. {
  777. defaultAnnot = new DefaultAnnotProperty();
  778. defaultAnnot.AnnotToolType = lineArgs.EventType;
  779. defaultAnnot.Thickness = 1;
  780. defaultAnnot.Opacity = 1;
  781. defaultAnnot.NoteText = string.Empty;
  782. defaultAnnot.DashArray = null;
  783. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  784. Settings.Default.Save();
  785. }
  786. lineArgs.LineDash = DashStyles.Solid;
  787. lineArgs.LineWidth = defaultAnnot.Thickness;
  788. lineArgs.Transparency = defaultAnnot.Opacity;
  789. if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
  790. {
  791. lineArgs.LineDash = DashStyles.Solid;
  792. }
  793. else
  794. {
  795. var collect = new DoubleCollection();
  796. foreach (var item in defaultAnnot.DashArray)
  797. {
  798. collect.Add(item);
  799. }
  800. if (lineArgs.LineDash == null)
  801. lineArgs.LineDash = new DashStyle();
  802. lineArgs.LineDash.Dashes = collect;
  803. }
  804. if (lineArgs != null)
  805. {
  806. selectedArgs = new List<AnnotHandlerEventArgs>();
  807. selectedArgs.Add(lineArgs);
  808. }
  809. }
  810. else
  811. {
  812. lineArgs = selectedArgs[0] as LineAnnotArgs;
  813. }
  814. AddToPropertyPanel("SharpsAnnotProperty", TagStr, selectedArgs);
  815. return lineArgs;
  816. }
  817. /// <summary>
  818. /// 图章
  819. /// </summary>
  820. /// <returns></returns>
  821. private AnnotHandlerEventArgs GetStamp()
  822. {
  823. StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  824. stampAnnotArgs.Opacity = 1;
  825. stampAnnotArgs.StampText = "APPROVED";
  826. stampAnnotArgs.Type = StampType.STANDARD_STAMP;
  827. List<AnnotHandlerEventArgs> stampAnnotArgsList = new List<AnnotHandlerEventArgs>();
  828. if (stampAnnotArgs != null)
  829. stampAnnotArgsList.Add(stampAnnotArgs);
  830. AddToPropertyPanel("StampAnnotProperty", null, stampAnnotArgsList);
  831. return stampAnnotArgs;
  832. }
  833. /// <summary>
  834. /// 签名
  835. /// </summary>
  836. /// <returns></returns>
  837. private AnnotHandlerEventArgs GetSignature()
  838. {
  839. AddToPropertyPanel("SignatureAnnotProperty");
  840. return null;
  841. }
  842. private AnnotHandlerEventArgs GetImage()
  843. {
  844. StampAnnotArgs stampArgs = new StampAnnotArgs();
  845. stampArgs.Opacity = 1;
  846. stampArgs.Type = StampType.IMAGE_STAMP;
  847. OpenFileDialog openFileDialog = new OpenFileDialog();
  848. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  849. if (openFileDialog.ShowDialog() == true)
  850. {
  851. stampArgs.ImagePath = openFileDialog.FileName;
  852. }
  853. List<AnnotHandlerEventArgs> stampArgsList = new List<AnnotHandlerEventArgs>();
  854. if (stampArgs != null)
  855. stampArgsList.Add(stampArgs);
  856. AddToPropertyPanel("ImageAnnotProperty", null, stampArgsList);
  857. return stampArgs;
  858. }
  859. /// <summary>
  860. /// 内容选择
  861. /// </summary>
  862. /// <param name="annotBtn"></param>
  863. /// <returns></returns>
  864. private AnnotHandlerEventArgs GetSnapshotEdit()
  865. {
  866. SnapshotEditToolArgs snapshotArgs = new SnapshotEditToolArgs();
  867. //SnapshotEditMenuViewModel snapshotEditMenuViewModel = new SnapshotEditMenuViewModel();
  868. snapshotArgs.ControlPointColor = Colors.White;
  869. snapshotArgs.BgColor = Color.FromArgb(0x99, 0x00, 0x00, 0x00);
  870. snapshotArgs.LineColor = Color.FromArgb(0xFF, 0x47, 0x7E, 0xDE);
  871. SnapshotEditMenuViewModel.SnapToolArgs = snapshotArgs;
  872. SnapshotEditMenuViewModel.PDFViewer = PDFViewer;
  873. SnapshotEditMenuViewModel.SnapToolEvent -= SnapshotEditMenuViewModel_SnapToolEvent;
  874. SnapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  875. #region to do
  876. //SnapshotEditMenu snapMenu = new SnapshotEditMenu();
  877. //snapshotArgs.ToolPanel = snapMenu;
  878. //SnapshotEditMenuViewModel snapshotEditMenuViewModel = (SnapshotEditMenuViewModel)snapMenu.DataContext;
  879. //snapshotEditMenuViewModel.SnapToolArgs = snapshotArgs;
  880. //snapshotEditMenuViewModel.PDFViewer = PDFViewer;
  881. //snapshotEditMenuViewModel.ToggleBtn = annotBtn;
  882. //snapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  883. //SnapshotEditMenuViewModel = snapshotEditMenuViewModel;
  884. #endregion to do
  885. return snapshotArgs;
  886. }
  887. #endregion 注释工具
  888. #region 菜单
  889. /// <summary>
  890. /// 空白处-右键菜单-添加注释
  891. /// </summary>
  892. /// <param name="sender"></param>
  893. private void AddAnnotation_Click(object sender)
  894. {
  895. if (sender is MenuItem menuItem)
  896. {
  897. AnnotHandlerEventArgs annotHandler = null;
  898. string str = menuItem.Tag.ToString();
  899. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  900. propertyPanel.IsAddLink = false;
  901. propertyPanel.IsLocationLink = false;
  902. if (str == AddAnnotType.AnnotFreehand.ToString())
  903. {
  904. annotHandler = GetFreehand();
  905. }
  906. if (str == AddAnnotType.AnnotFreeText.ToString())
  907. {
  908. annotHandler = GetFreetext();
  909. }
  910. if (str == AddAnnotType.AnnotSticky.ToString())
  911. {
  912. annotHandler = GetStickyNote();
  913. }
  914. if (str == AddAnnotType.AnnotSquare.ToString())
  915. {
  916. annotHandler = GetRect();
  917. }
  918. if (str == AddAnnotType.AnnotCircle.ToString())
  919. {
  920. annotHandler = GetCircle();
  921. }
  922. if (str == AddAnnotType.AnnotArrow.ToString())
  923. {
  924. annotHandler = GetArrowLine("Arrow");
  925. }
  926. if (str == AddAnnotType.AnnotLine.ToString())
  927. {
  928. annotHandler = GetArrowLine("Line");
  929. }
  930. if (str == AddAnnotType.AnnotLink.ToString())
  931. {
  932. propertyPanel.IsAddLink = true;
  933. annotHandler = GetLink();
  934. }
  935. if (str == AddAnnotType.AnnotStamp.ToString())
  936. {
  937. annotHandler = GetStamp();
  938. }
  939. if (str == AddAnnotType.AnnotAutograph.ToString())
  940. {
  941. annotHandler = GetSignature();
  942. }
  943. if (annotHandler != null)
  944. {
  945. annotHandler.Author = Settings.Default.AppProperties.Description.Author;
  946. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  947. PDFViewer.SetToolParam(annotHandler);
  948. //是否展开右侧面板 =>否(链接、图章、签名除外)
  949. ShowPropertyPanel(false);
  950. if (str == AddAnnotType.AnnotLink.ToString()
  951. || str == AddAnnotType.AnnotStamp.ToString()
  952. || str == AddAnnotType.AnnotAutograph.ToString()
  953. )
  954. {
  955. ShowPropertyPanel(true);
  956. }
  957. IsNoSelectMenu = true;
  958. }
  959. }
  960. }
  961. private bool InBookModeSetIsEnabled(MenuItem menuItem)
  962. {
  963. if (viewContentViewModel.mainViewModel.IsBookMode)
  964. {
  965. menuItem.IsEnabled = false;
  966. return true;
  967. }
  968. else
  969. {
  970. menuItem.IsEnabled = true;
  971. return false;
  972. }
  973. }
  974. /// <summary>
  975. /// 选择文本、图片,右键菜单
  976. /// </summary>
  977. /// <param name="sender"></param>
  978. /// <param name="e"></param>
  979. private void AnnotToolMenu_Click(object sender, RoutedEventArgs e)
  980. {
  981. if (sender is MenuItem clickMenu && clickMenu.CommandParameter is AnnotCommandArgs)
  982. {
  983. AnnotCommandArgs annotCommand = clickMenu.CommandParameter as AnnotCommandArgs;
  984. switch (clickMenu.Tag.ToString())
  985. {
  986. case "HighLight"://字体高亮
  987. TextHighlightAnnotArgs highlightArgs = (TextHighlightAnnotArgs)GetHighLight();
  988. highlightArgs.ClientRect = annotCommand.TextRect;
  989. highlightArgs.Content = annotCommand.Text;
  990. highlightArgs.Author = Settings.Default.AppProperties.Description.Author;
  991. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  992. PDFViewer.SetToolParam(highlightArgs);
  993. PDFViewer.SetMouseMode(MouseModes.PanTool);
  994. break;
  995. case "UnderLine"://下划线
  996. TextUnderlineAnnotArgs underlineArgs = (TextUnderlineAnnotArgs)GetUnderLine();
  997. underlineArgs.ClientRect = annotCommand.TextRect;
  998. underlineArgs.Content = annotCommand.Text;
  999. underlineArgs.Author = Settings.Default.AppProperties.Description.Author;
  1000. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1001. PDFViewer.SetToolParam(underlineArgs);
  1002. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1003. break;
  1004. case "Strikeout"://删除线
  1005. TextStrikeoutAnnotArgs strikeoutArgs = (TextStrikeoutAnnotArgs)GetStrikeout();
  1006. strikeoutArgs.ClientRect = annotCommand.TextRect;
  1007. strikeoutArgs.Content = annotCommand.Text;
  1008. strikeoutArgs.Author = Settings.Default.AppProperties.Description.Author;
  1009. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1010. PDFViewer.SetToolParam(strikeoutArgs);
  1011. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1012. break;
  1013. case "Freetext"://文本
  1014. FreeTextAnnotArgs textArgs = (FreeTextAnnotArgs)GetFreetext();
  1015. textArgs.ClientRect = annotCommand.TextRect;
  1016. //textArgs.Transparency = 1;
  1017. //textArgs.BgColor = Colors.Transparent;
  1018. //textArgs.LineColor = Colors.Red;
  1019. //textArgs.LineWidth = 2;
  1020. textArgs.TextContent = annotCommand.Text;
  1021. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, textArgs);
  1022. break;
  1023. case "StickyNote"://便签
  1024. StickyAnnotArgs stickyAnnotArgs = (StickyAnnotArgs)GetStickyNote();
  1025. //stickyAnnotArgs.ClientRect = annotCommand.TextRect;
  1026. List<TextSelectNode> textSelectNodes = PDFViewer.GetSelectTextInfo();
  1027. //stickyAnnotArgs.ClientRect = new Rect(textSelectNodes[0].StartPoint.X, annotCommand.TextRect.Y - annotCommand.TextRect.Height, annotCommand.TextRect.Width, annotCommand.TextRect.Height);
  1028. Rect rect = annotCommand.TextRectList[0];
  1029. #region to do 转dpi
  1030. //int dpi = DpiHelpers.Dpi;
  1031. //double x = rect.X / 72D * dpi;
  1032. //double y = (rect.Y - rect.Height) / 72D * dpi;
  1033. //double width = rect.Width / 72D * dpi;
  1034. //double height = rect.Height / 72D * dpi;
  1035. #endregion to do 转dpi
  1036. //stickyAnnotArgs.ClientRect = new Rect(x, y, width, height);
  1037. //stickyAnnotArgs.ClientRect = new Rect(rect.X, rect.Y - rect.Height, rect.Width, rect.Height);
  1038. stickyAnnotArgs.ClientRect = rect;
  1039. //PDFViewer.CreatePageAnnot(annotCommand.PageIndex, stickyAnnotArgs);
  1040. NavigationParameters param = new NavigationParameters();
  1041. param.Add(ParameterNames.PDFViewer, PDFViewer);
  1042. param.Add(ParameterNames.StickyAnnotArgs, stickyAnnotArgs);
  1043. param.Add(ParameterNames.ViewContentViewModel, viewContentViewModel);
  1044. param.Add(ParameterNames.AnnotCommandArgs, annotCommand);
  1045. ContentControl window = null;
  1046. if (PDFViewer.Parent as ContentControl != null)
  1047. {
  1048. window = PDFViewer.Parent as ContentControl;
  1049. }
  1050. else
  1051. {
  1052. window = App.Current.MainWindow;
  1053. }
  1054. var point = Mouse.GetPosition(window);
  1055. viewContentViewModel.NotePopupVisible = Visibility.Visible;
  1056. viewContentViewModel.CanvasNoteLeft = point.X;
  1057. viewContentViewModel.CanvasNoteBottom = point.Y;
  1058. if (point.Y > window.ActualHeight / 2)
  1059. {
  1060. viewContentViewModel.CanvasNoteBottom = point.Y - window.ActualHeight / 2;
  1061. }
  1062. viewContentViewModel.IsNoteAdd = true;
  1063. region.RequestNavigate(viewContentViewModel.NotePopupRegionName, "StickyNotePopup", param);
  1064. //stickyAnnotArgs.Author = Settings.Default.AppProperties.Description.Author;
  1065. //PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1066. //PDFViewer.SetToolParam(stickyAnnotArgs);
  1067. //PDFViewer.SetMouseMode(MouseModes.PanTool);
  1068. break;
  1069. case "Rect"://矩形
  1070. SquareAnnotArgs squareAnnotArgs = (SquareAnnotArgs)GetRect();
  1071. squareAnnotArgs.ClientRect = annotCommand.TextRect;
  1072. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, squareAnnotArgs);
  1073. break;
  1074. case "Circle"://圆
  1075. CircleAnnotArgs circleAnnotArgs = (CircleAnnotArgs)GetCircle();
  1076. circleAnnotArgs.ClientRect = annotCommand.TextRect;
  1077. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, circleAnnotArgs);
  1078. break;
  1079. case "Line"://线
  1080. LineAnnotArgs lineAnnotArgs = (LineAnnotArgs)GetArrowLine(clickMenu.Tag.ToString());
  1081. lineAnnotArgs.ClientRect = annotCommand.TextRect;
  1082. lineAnnotArgs.LinePoints.Add(new Point(annotCommand.TextRect.Left, annotCommand.TextRect.Top));
  1083. lineAnnotArgs.LinePoints.Add(new Point(annotCommand.TextRect.Right, annotCommand.TextRect.Bottom));
  1084. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, lineAnnotArgs);
  1085. break;
  1086. case "Link"://链接
  1087. LinkAnnotArgs linkArgs = new LinkAnnotArgs();
  1088. linkArgs.ClientRect = annotCommand.TextRect;
  1089. linkArgs.URI = string.Empty;
  1090. linkArgs.LinkType = LINK_TYPE.GOTO;
  1091. linkArgs.DestIndex = annotCommand.PageIndex;
  1092. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, linkArgs);
  1093. BtnLinkIsChecked = true;
  1094. List<AnnotHandlerEventArgs> lists = new List<AnnotHandlerEventArgs>();
  1095. lists.Add(linkArgs);
  1096. propertyPanel.IsAddLink = true;
  1097. AnnotHandlerEventArgs annotArgs = GetLink(lists);
  1098. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1099. PDFViewer.SetToolParam(annotArgs);
  1100. viewContentViewModel.IsPropertyOpen = true;
  1101. break;
  1102. case "OutLine":
  1103. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemOutLine");
  1104. if (isTabItemAnnotation == false)
  1105. {
  1106. bOTAContent.TabItemOutLine.IsSelected = true;
  1107. }
  1108. OutLineControlViewModel outLineControlViewModel = GetOutLineControlViewModel(bOTAContentViewModel, out OutLineControl outLineControl);
  1109. if (outLineControlViewModel != null && outLineControl != null)
  1110. {
  1111. string str = null;
  1112. if (string.IsNullOrEmpty(annotCommand.Text))
  1113. {
  1114. str = (annotCommand.PageIndex + 1).ToString();
  1115. }
  1116. else
  1117. {
  1118. str = annotCommand.Text;
  1119. }
  1120. outLineControl.AddOutlineNode(str);
  1121. }
  1122. break;
  1123. case "ExportPicture":
  1124. ExportPicture_MenuItemClick();
  1125. break;
  1126. }
  1127. //ShowPropertyPanel(false);
  1128. }
  1129. }
  1130. private void ExportPicture_MenuItemClick()
  1131. {
  1132. //图片提取
  1133. try
  1134. {
  1135. List<System.Drawing.Bitmap> imageList = new List<System.Drawing.Bitmap>();
  1136. Dictionary<int, List<System.Drawing.Bitmap>> imageDict = PDFViewer?.GetSelectedImages();
  1137. foreach (int pageIndex in imageDict.Keys)
  1138. {
  1139. imageList = imageDict[pageIndex];
  1140. }
  1141. string path = PDFViewer.Document.FileName;
  1142. System.Windows.Forms.FolderBrowserDialog folderDialog = new FolderBrowserDialog();
  1143. if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  1144. {
  1145. int i = 1;
  1146. int pagenum = 1;
  1147. string choosePath = folderDialog.SelectedPath;
  1148. string sPath = choosePath + "\\" + path + "_Extract Image";
  1149. sPath = GetExportPathName(sPath);
  1150. if (!Directory.Exists(sPath))
  1151. {
  1152. Directory.CreateDirectory(sPath);
  1153. }
  1154. if (Directory.Exists(sPath))
  1155. {
  1156. foreach (System.Drawing.Bitmap image in imageList)
  1157. {
  1158. foreach (var item in imageDict.Keys)
  1159. {
  1160. pagenum = item;
  1161. }
  1162. string filename = path + "_" + "Page" + (pagenum + 1).ToString() + "_" + GetNum(i);
  1163. string savePath = System.IO.Path.Combine(sPath, filename + ".jpg");
  1164. image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  1165. i++;
  1166. }
  1167. System.Diagnostics.Process.Start("explorer", "/select,\"" + sPath + "\"");
  1168. }
  1169. }
  1170. }
  1171. catch (Exception ex) { }
  1172. }
  1173. public string GetExportPathName(string path)
  1174. {
  1175. int i = 1;
  1176. string outpath = path;
  1177. while (Directory.Exists(outpath))
  1178. {
  1179. outpath = path + $"({i.ToString()})";
  1180. i++;
  1181. }
  1182. return outpath;
  1183. }
  1184. private string GetNum(int num)
  1185. {
  1186. if (num % 10 < 1)
  1187. {
  1188. return "00" + num.ToString();
  1189. }
  1190. if (num % 10 >= 1 && num % 10 < 10)
  1191. {
  1192. return "0" + num.ToString();
  1193. }
  1194. else
  1195. {
  1196. return num.ToString();
  1197. }
  1198. }
  1199. #region 注释右键菜单事件
  1200. //高亮、下划线、删除
  1201. private void HightAnnotCopyText_Menu(object obj)
  1202. {
  1203. if (obj as CusMenuItem != null)
  1204. {
  1205. var menu = obj as CusMenuItem;
  1206. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1207. if (annot != null)
  1208. {
  1209. System.Windows.Clipboard.SetText(annot.Content);
  1210. }
  1211. }
  1212. }
  1213. //更改为当前注释属性默认值
  1214. private void AnnotDefaultValues_Menu(object obj)
  1215. {
  1216. if (obj as CusMenuItem != null)
  1217. {
  1218. var menu = obj as CusMenuItem;
  1219. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1220. if (annot != null)
  1221. {
  1222. if (annot is TextHighlightAnnotArgs)
  1223. {
  1224. var color = (annot as TextHighlightAnnotArgs).Color;
  1225. HighLightColor = new SolidColorBrush(color);
  1226. Settings.Default.AppProperties.Annotate.HighLightColor = color;
  1227. var hightlight = GetAnnotDefault(AnnotArgsType.AnnotHighlight);
  1228. hightlight.ForgoundColor = color;
  1229. hightlight.Opacity = (annot as TextHighlightAnnotArgs).Transparency;
  1230. SettingHelper.SetAnnotDefaultProperty(hightlight);
  1231. }
  1232. else if (annot is TextUnderlineAnnotArgs)
  1233. {
  1234. var color = (annot as TextUnderlineAnnotArgs).Color;
  1235. UnderLineColor = new SolidColorBrush(color);
  1236. Settings.Default.AppProperties.Annotate.UnderLineColor = color;
  1237. var Underline = GetAnnotDefault(AnnotArgsType.AnnotUnderline);
  1238. Underline.ForgoundColor = color;
  1239. Underline.Opacity = (annot as TextUnderlineAnnotArgs).Transparency;
  1240. SettingHelper.SetAnnotDefaultProperty(Underline);
  1241. }
  1242. else if (annot is TextStrikeoutAnnotArgs)
  1243. {
  1244. var color = (annot as TextStrikeoutAnnotArgs).Color;
  1245. StrikeoutColor = new SolidColorBrush(color);
  1246. Settings.Default.AppProperties.Annotate.StrikethroughColor = color;
  1247. var Strikeout = GetAnnotDefault(AnnotArgsType.AnnotStrikeout);
  1248. Strikeout.ForgoundColor = color;
  1249. Strikeout.Opacity = (annot as TextStrikeoutAnnotArgs).Transparency;
  1250. SettingHelper.SetAnnotDefaultProperty(Strikeout);
  1251. }
  1252. else if (annot is FreehandAnnotArgs)
  1253. {
  1254. var freeHand = annot as FreehandAnnotArgs;
  1255. var color = freeHand.InkColor;
  1256. Settings.Default.AppProperties.Annotate.FreeHandColor = color;
  1257. var FreehandDefault = GetAnnotDefault(AnnotArgsType.AnnotFreehand);
  1258. FreehandDefault.ForgoundColor = color;
  1259. FreehandDefault.Opacity = freeHand.Transparency;
  1260. FreehandDefault.Thickness = freeHand.LineWidth;
  1261. var isSolid = AnnotTransfer.IsSolidStyle(freeHand.LineDash);
  1262. if (isSolid)
  1263. {
  1264. FreehandDefault.DashArray = null;
  1265. }
  1266. else
  1267. {
  1268. FreehandDefault.DashArray = new List<double>();
  1269. foreach (var item in freeHand.LineDash.Dashes)
  1270. {
  1271. FreehandDefault.DashArray.Add(item);
  1272. }
  1273. }
  1274. SettingHelper.SetAnnotDefaultProperty(FreehandDefault);
  1275. }
  1276. else if (annot is FreeTextAnnotArgs)
  1277. {
  1278. var freeText = annot as FreeTextAnnotArgs;
  1279. Settings.Default.AppProperties.Annotate.TextAnnoteColor = freeText.FontColor;
  1280. Settings.Default.AppProperties.Annotate.TextFontFamaily = freeText.FontFamily.ToString();
  1281. Settings.Default.AppProperties.Annotate.TextAlign = freeText.Align;
  1282. var FreeTextDefalut = GetAnnotDefault(AnnotArgsType.AnnotFreeText);
  1283. FreeTextDefalut.ForgoundColor = freeText.FontColor;
  1284. FreeTextDefalut.FontFamily = freeText.FontFamily.ToString();
  1285. FreeTextDefalut.TextAlign = freeText.Align;
  1286. FreeTextDefalut.FontSize = freeText.FontSize;
  1287. FreeTextDefalut.FontWeight = freeText.FontWeight;
  1288. FreeTextDefalut.FontStyle = freeText.FontStyle;
  1289. FreeTextDefalut.BackgroundColor = freeText.BgColor;
  1290. FreeTextDefalut.Opacity = (annot as FreeTextAnnotArgs).Transparency;
  1291. SettingHelper.SetAnnotDefaultProperty(FreeTextDefalut);
  1292. }
  1293. else if (annot is StickyAnnotArgs)
  1294. {
  1295. var color = (annot as StickyAnnotArgs).Color;
  1296. Settings.Default.AppProperties.Annotate.NoteAnnoteColor = color;
  1297. var StickyDefalut = GetAnnotDefault(AnnotArgsType.AnnotSticky);
  1298. StickyDefalut.ForgoundColor = color;
  1299. SettingHelper.SetAnnotDefaultProperty(StickyDefalut);
  1300. }
  1301. else if (annot is SquareAnnotArgs)
  1302. {
  1303. var square = annot as SquareAnnotArgs;
  1304. var bgColor = square.BgColor;
  1305. Settings.Default.AppProperties.Annotate.RectangleFillColor = bgColor;
  1306. var borderColor = square.LineColor;
  1307. Settings.Default.AppProperties.Annotate.RectangleBorderColor = borderColor;
  1308. var SquareDefalut = GetAnnotDefault(AnnotArgsType.AnnotSquare);
  1309. SquareDefalut.BorderColor = borderColor;
  1310. SquareDefalut.BackgroundColor = bgColor;
  1311. SquareDefalut.Opacity = square.Transparency;
  1312. SquareDefalut.Thickness = square.LineWidth;
  1313. var isSolid = AnnotTransfer.IsSolidStyle(square.LineDash);
  1314. if (isSolid)
  1315. {
  1316. SquareDefalut.DashArray = null;
  1317. }
  1318. else
  1319. {
  1320. SquareDefalut.DashArray = new List<double>();
  1321. foreach (var item in square.LineDash.Dashes)
  1322. {
  1323. SquareDefalut.DashArray.Add(item);
  1324. }
  1325. }
  1326. SettingHelper.SetAnnotDefaultProperty(SquareDefalut);
  1327. }
  1328. else if (annot is CircleAnnotArgs)
  1329. {
  1330. var circle = annot as CircleAnnotArgs;
  1331. var bgColor = circle.BgColor;
  1332. Settings.Default.AppProperties.Annotate.CircleFillColor = bgColor;
  1333. var borderColor = circle.LineColor;
  1334. Settings.Default.AppProperties.Annotate.CircleBorderColor = borderColor;
  1335. var CircleDefalut = GetAnnotDefault(AnnotArgsType.AnnotCircle);
  1336. CircleDefalut.BorderColor = borderColor;
  1337. CircleDefalut.BackgroundColor = bgColor;
  1338. CircleDefalut.Opacity = circle.Transparency;
  1339. CircleDefalut.Thickness = circle.LineWidth;
  1340. var isSolid = AnnotTransfer.IsSolidStyle(circle.LineDash);
  1341. if (isSolid)
  1342. {
  1343. CircleDefalut.DashArray = null;
  1344. }
  1345. else
  1346. {
  1347. CircleDefalut.DashArray = new List<double>();
  1348. foreach (var item in circle.LineDash.Dashes)
  1349. {
  1350. CircleDefalut.DashArray.Add(item);
  1351. }
  1352. }
  1353. SettingHelper.SetAnnotDefaultProperty(CircleDefalut);
  1354. }
  1355. else if (annot is LineAnnotArgs)
  1356. {
  1357. var line = (annot as LineAnnotArgs);
  1358. var color = (annot as LineAnnotArgs).LineColor;
  1359. Settings.Default.AppProperties.Annotate.LineColor = color;
  1360. var lineDefalut = GetAnnotDefault(AnnotArgsType.AnnotLine);
  1361. lineDefalut.BorderColor = color;
  1362. lineDefalut.Opacity = (annot as LineAnnotArgs).Transparency;
  1363. lineDefalut.Thickness = (annot as LineAnnotArgs).LineWidth;
  1364. var isSolid = AnnotTransfer.IsSolidStyle(line.LineDash);
  1365. if (isSolid)
  1366. {
  1367. lineDefalut.DashArray = null;
  1368. }
  1369. else
  1370. {
  1371. lineDefalut.DashArray = new List<double>();
  1372. foreach (var item in line.LineDash.Dashes)
  1373. {
  1374. lineDefalut.DashArray.Add(item);
  1375. }
  1376. }
  1377. SettingHelper.SetAnnotDefaultProperty(lineDefalut);
  1378. }
  1379. Settings.Default.Save();
  1380. }
  1381. }
  1382. }
  1383. private DefaultAnnotProperty GetAnnotDefault(AnnotArgsType annotArgsType)
  1384. {
  1385. var Annot = SettingHelper.GetAnnotDefaultProperty(annotArgsType);
  1386. if (Annot == null)
  1387. {
  1388. Annot = new DefaultAnnotProperty();
  1389. Annot.AnnotToolType = annotArgsType;
  1390. }
  1391. return Annot;
  1392. }
  1393. private System.Windows.Controls.Primitives.Popup popup = null;
  1394. //更改颜色
  1395. private async void AnnotColorPalette_Menu(object obj)
  1396. {
  1397. if (obj as CusMenuItem != null)
  1398. {
  1399. var menu = obj as CusMenuItem;
  1400. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1401. if (annot != null)
  1402. {
  1403. var item = new ColorDropBoxPop();
  1404. item.DataContext = menu;
  1405. item.ColorSelected -= AnnotMenu_ColorSelected;
  1406. item.ColorSelected += AnnotMenu_ColorSelected;
  1407. if (popup == null)
  1408. popup = new System.Windows.Controls.Primitives.Popup();
  1409. ContentControl window = null;
  1410. if (PDFViewer.Parent as ContentControl != null)
  1411. window = PDFViewer.Parent as ContentControl;
  1412. else
  1413. window = App.Current.MainWindow;
  1414. popup.Child = item;
  1415. popup.PlacementRectangle = new Rect(Mouse.GetPosition(window), new Size(item.Width, item.Height));
  1416. popup.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
  1417. popup.PlacementTarget = window;
  1418. popup.IsOpen = true;
  1419. Window parentWnd = Window.GetWindow(App.Current.MainWindow);
  1420. if (parentWnd != null)
  1421. {
  1422. parentWnd.MouseDown -= parentWnd_MouseDown;
  1423. parentWnd.MouseDown += parentWnd_MouseDown;
  1424. }
  1425. while (popup.IsOpen)
  1426. await Task.Delay(20);
  1427. parentWnd.MouseDown -= parentWnd_MouseDown;
  1428. popup = null;
  1429. }
  1430. }
  1431. }
  1432. private void parentWnd_MouseDown(object sender, MouseButtonEventArgs e)
  1433. {
  1434. var ui = Mouse.DirectlyOver as FrameworkElement;
  1435. if (ui != null)
  1436. {
  1437. if (popup != null)
  1438. {
  1439. popup.IsOpen = false;
  1440. }
  1441. }
  1442. }
  1443. private void AnnotMenu_ColorSelected(object sender, Color e)
  1444. {
  1445. if (sender != null)
  1446. {
  1447. var menu = (sender as FrameworkElement).DataContext as CusMenuItem;
  1448. if (menu == null) return;
  1449. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1450. if (annot != null)
  1451. {
  1452. if (annot is FreehandAnnotArgs || annot is StickyAnnotArgs || annot is LineAnnotArgs)
  1453. {
  1454. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1455. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  1456. AnnotEvent?.UpdateAnnot();
  1457. }
  1458. else if (annot is FreeTextAnnotArgs)
  1459. {
  1460. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1461. if (menu.tag.ToString() == "FontColor")
  1462. AnnotEvent?.UpdateAttrib(AnnotAttrib.FontColor, e);
  1463. else
  1464. AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, e);
  1465. AnnotEvent?.UpdateAnnot();
  1466. }
  1467. else if (annot is SquareAnnotArgs || annot is CircleAnnotArgs)
  1468. {
  1469. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1470. if (menu.tag.ToString() == "FillColor")
  1471. AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, e);
  1472. else
  1473. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  1474. AnnotEvent?.UpdateAnnot();
  1475. }
  1476. else if (annot is TextHighlightAnnotArgs || annot is TextUnderlineAnnotArgs || annot is TextStrikeoutAnnotArgs)
  1477. {
  1478. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1479. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  1480. AnnotEvent?.UpdateAnnot();
  1481. }
  1482. }
  1483. }
  1484. }
  1485. //添加笔记
  1486. private void AnnotAddNoteText_Menu(object obj)
  1487. {
  1488. if (obj as CusMenuItem != null)
  1489. {
  1490. var menu = obj as CusMenuItem;
  1491. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1492. PopAnnotNoteText(annot);
  1493. }
  1494. }
  1495. private void PopAnnotNoteText(AnnotHandlerEventArgs annot)
  1496. {
  1497. if (annot != null)
  1498. {
  1499. AnnotationHandlerEventArgs args = new AnnotationHandlerEventArgs();
  1500. args.ClientRect = annot.ClientRect;
  1501. args.AnnotHandlerEventArgs = annot;
  1502. args.PageIndex = annot.PageIndex;
  1503. args.AnnotIndex = annot.AnnotIndex;
  1504. args.EventType = annot.EventType;
  1505. args.CreateTime = annot.CreateTime;
  1506. args.UpdateTime = annot.UpdateTime;
  1507. args.Content = annot.Content;
  1508. args.MarkupContent = annot.MarkupContent;
  1509. args.Author = annot.Author;
  1510. args.Locked = annot.Locked;
  1511. args.ReadOnly = annot.ReadOnly;
  1512. args.FormField = annot.FormField;
  1513. args.Document = PDFViewer.Document;
  1514. DialogParameters value = new DialogParameters();
  1515. value.Add(ParameterNames.Annotation, args);
  1516. dialogs.ShowDialog(DialogNames.AddAnnotationDialog, value, e =>
  1517. {
  1518. if (e.Result == ButtonResult.OK && e.Parameters != null)
  1519. {
  1520. PDFViewer.UndoManager.CanSave = true;
  1521. if (e.Parameters.ContainsKey(ParameterNames.Annotation) && e.Parameters.ContainsKey(ParameterNames.AnnotEvent))
  1522. {
  1523. }
  1524. }
  1525. });
  1526. }
  1527. }
  1528. //手绘
  1529. private void FreeHandLineStyle_Menu(object obj)
  1530. {
  1531. if (obj as CusMenuItem != null)
  1532. {
  1533. var menu = obj as CusMenuItem;
  1534. var annot = menu.Parameter as FreehandAnnotArgs;
  1535. if (annot != null)
  1536. {
  1537. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1538. if (menu.tag.ToString() == "Solid")
  1539. {
  1540. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, AnnotTransfer.GetLineDashStyle(true));
  1541. }
  1542. else
  1543. {
  1544. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, AnnotTransfer.GetLineDashStyle(false));
  1545. }
  1546. AnnotEvent?.UpdateAnnot();
  1547. }
  1548. }
  1549. }
  1550. //文本
  1551. private void FreeTextFontFamily_Menu(object obj)
  1552. {
  1553. if (obj as CusMenuItem != null)
  1554. {
  1555. var menu = obj as CusMenuItem;
  1556. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1557. if (annot != null)
  1558. {
  1559. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1560. AnnotEvent?.UpdateAttrib(AnnotAttrib.FontFamily, new FontFamily(menu.tag.ToString()));
  1561. AnnotEvent?.UpdateAnnot();
  1562. }
  1563. }
  1564. }
  1565. private void FreeTextAglin_Menu(object obj)
  1566. {
  1567. if (obj as CusMenuItem != null)
  1568. {
  1569. var menu = obj as CusMenuItem;
  1570. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1571. var tag = menu.control.Tag;
  1572. if (annot != null && tag != null)
  1573. {
  1574. var strTag = tag.ToString();
  1575. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1576. if (strTag == "Left")
  1577. {
  1578. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Left);
  1579. }
  1580. else if (strTag == "Center")
  1581. {
  1582. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Center);
  1583. }
  1584. else if (strTag == "Right")
  1585. {
  1586. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Right);
  1587. }
  1588. else if (strTag == "Justify")
  1589. {
  1590. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Justify);
  1591. }
  1592. AnnotEvent?.UpdateAnnot();
  1593. }
  1594. }
  1595. }
  1596. //便签
  1597. private void StrikeNoteEditStrike_Menu(object obj)
  1598. {
  1599. if (obj as CusMenuItem != null)
  1600. {
  1601. var menu = obj as CusMenuItem;
  1602. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1603. if (annot != null)
  1604. {
  1605. var sticky = annot as StickyAnnotArgs;
  1606. sticky.PopupEditWnd();
  1607. #region 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
  1608. //isRightMenuAddAnnot = false;
  1609. #endregion 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
  1610. }
  1611. }
  1612. }
  1613. //形状
  1614. private void ShapeLineStyle_Menu(object obj)
  1615. {
  1616. if (obj as CusMenuItem != null)
  1617. {
  1618. var menu = obj as CusMenuItem;
  1619. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1620. var tag = menu.control.Tag;
  1621. if (annot != null && tag != null)
  1622. {
  1623. var strTag = tag.ToString();
  1624. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1625. if (strTag == "Solid")
  1626. {
  1627. var dashStyle = AnnotTransfer.GetLineDashStyle(true);
  1628. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, dashStyle);
  1629. }
  1630. else
  1631. {
  1632. var dashStyle = AnnotTransfer.GetLineDashStyle(false);
  1633. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, dashStyle);
  1634. }
  1635. AnnotEvent?.UpdateAnnot();
  1636. }
  1637. }
  1638. }
  1639. private void ShapeLineDirect_Menu(object obj)
  1640. {
  1641. if (obj as CusMenuItem != null)
  1642. {
  1643. var menu = obj as CusMenuItem;
  1644. var annot = menu.Parameter as LineAnnotArgs;
  1645. var tag = menu.control.Tag;
  1646. if (annot != null && tag != null)
  1647. {
  1648. var strTag = tag.ToString();
  1649. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1650. if (strTag == "Ver")
  1651. {
  1652. annot.SetLineVertical();
  1653. }
  1654. else
  1655. {
  1656. annot.SetLineHorizontal();
  1657. }
  1658. }
  1659. }
  1660. }
  1661. private void Link_Menu(object obj)
  1662. {
  1663. if (obj is CusMenuItem menuItem)
  1664. {
  1665. if (menuItem.Parameter is LinkAnnotArgs linkAnnotArgs)
  1666. {
  1667. var result = PDFViewer.RemovePageAnnot(linkAnnotArgs.PageIndex, linkAnnotArgs.AnnotIndex);
  1668. if (result)
  1669. {
  1670. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1671. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  1672. if (isTabItemAnnotation)
  1673. {
  1674. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  1675. if (viewModel != null)
  1676. {
  1677. viewModel.UpdateModifiedAnnot(linkAnnotArgs.PageIndex, linkAnnotArgs.AnnotIndex, true);
  1678. }
  1679. }
  1680. }
  1681. }
  1682. }
  1683. }
  1684. //图章
  1685. private void StampExportPicture_Menu(object obj)
  1686. {
  1687. if (obj as CusMenuItem != null)
  1688. {
  1689. var menu = obj as CusMenuItem;
  1690. var annot = menu.Parameter as StampAnnotArgs;
  1691. if (annot != null)
  1692. {
  1693. Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  1694. var format = menu.tag.ToString();
  1695. if (format == "PDF")
  1696. dlg.Filter = "PDF|*.pdf";
  1697. else
  1698. dlg.Filter = format + "|*." + format.ToLower();
  1699. dlg.DefaultExt = "." + menu.tag.ToString().ToLower();
  1700. dlg.FileName = PDFViewer.Document.FileName;
  1701. if (dlg.ShowDialog() == true)
  1702. {
  1703. var stampPicture = dlg.FileName;
  1704. if (menu.tag.ToString() == "PDF")
  1705. {
  1706. var writeStamp = annot.GetStampDrawing();
  1707. var tempDoc = new CPDFViewer();
  1708. tempDoc.CreateDocument();
  1709. if (tempDoc.Document == null)
  1710. {
  1711. AlertsMessage alertsMessage = new AlertsMessage();
  1712. alertsMessage.ShowDialog("", "创建文件失败.", "OK");
  1713. return;
  1714. }
  1715. byte[] buffer;
  1716. var encoder = new PngBitmapEncoder();
  1717. encoder.Frames.Add(BitmapFrame.Create(writeStamp));
  1718. using (var memoryStream = new MemoryStream())
  1719. {
  1720. encoder.Save(memoryStream);
  1721. buffer = memoryStream.ToArray();
  1722. }
  1723. tempDoc.Document.InsertPage(0, writeStamp.PixelWidth, writeStamp.PixelHeight, buffer, CPDFDocumentImageMode.CPDFDocumentImageModeScaleAspectFit);
  1724. var result = tempDoc.Document.WriteToFilePath(dlg.FileName);
  1725. if (result)
  1726. {
  1727. }
  1728. }
  1729. else
  1730. {
  1731. var writeStamp = annot.GetStampDrawing();
  1732. using (FileStream stream5 = new FileStream(stampPicture, FileMode.Create))
  1733. {
  1734. PngBitmapEncoder encoder5 = new PngBitmapEncoder();
  1735. encoder5.Frames.Add(BitmapFrame.Create(writeStamp));
  1736. encoder5.Save(stream5);
  1737. }
  1738. }
  1739. }
  1740. }
  1741. }
  1742. }
  1743. #endregion 注释右键菜单事件
  1744. #endregion 菜单
  1745. }
  1746. }