AnnotToolContentViewModel.Function.cs 79 KB

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