AnnotToolContentViewModel.Function.cs 75 KB

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