AnnotToolContentViewModel.Function.cs 83 KB

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