AnnotToolContentViewModel.Function.cs 78 KB

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