AnnotToolContentViewModel.Function.cs 79 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958
  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. /// <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. private bool InBookModeSetIsEnabled(MenuItem menuItem)
  948. {
  949. if (viewContentViewModel.mainViewModel.IsBookMode)
  950. {
  951. menuItem.IsEnabled = false;
  952. return true;
  953. }
  954. else
  955. {
  956. menuItem.IsEnabled = true;
  957. return false;
  958. }
  959. }
  960. /// <summary>
  961. /// 选择文本、图片,右键菜单
  962. /// </summary>
  963. /// <param name="sender"></param>
  964. /// <param name="e"></param>
  965. private void AnnotToolMenu_Click(object sender, RoutedEventArgs e)
  966. {
  967. if (sender is MenuItem clickMenu && clickMenu.CommandParameter is AnnotCommandArgs)
  968. {
  969. AnnotCommandArgs annotCommand = clickMenu.CommandParameter as AnnotCommandArgs;
  970. switch (clickMenu.Tag.ToString())
  971. {
  972. case "HighLight"://字体高亮
  973. TextHighlightAnnotArgs highlightArgs = (TextHighlightAnnotArgs)GetHighLight();
  974. highlightArgs.ClientRect = annotCommand.TextRect;
  975. highlightArgs.Content = annotCommand.Text;
  976. highlightArgs.Author = Settings.Default.AppProperties.Description.Author;
  977. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  978. PDFViewer.SetToolParam(highlightArgs);
  979. PDFViewer.SetMouseMode(MouseModes.PanTool);
  980. break;
  981. case "UnderLine"://下划线
  982. TextUnderlineAnnotArgs underlineArgs = (TextUnderlineAnnotArgs)GetUnderLine();
  983. underlineArgs.ClientRect = annotCommand.TextRect;
  984. underlineArgs.Content = annotCommand.Text;
  985. underlineArgs.Author = Settings.Default.AppProperties.Description.Author;
  986. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  987. PDFViewer.SetToolParam(underlineArgs);
  988. PDFViewer.SetMouseMode(MouseModes.PanTool);
  989. break;
  990. case "Strikeout"://删除线
  991. TextStrikeoutAnnotArgs strikeoutArgs = (TextStrikeoutAnnotArgs)GetStrikeout();
  992. strikeoutArgs.ClientRect = annotCommand.TextRect;
  993. strikeoutArgs.Content = annotCommand.Text;
  994. strikeoutArgs.Author = Settings.Default.AppProperties.Description.Author;
  995. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  996. PDFViewer.SetToolParam(strikeoutArgs);
  997. PDFViewer.SetMouseMode(MouseModes.PanTool);
  998. break;
  999. case "Freetext"://文本
  1000. FreeTextAnnotArgs textArgs = (FreeTextAnnotArgs)GetFreetext();
  1001. textArgs.ClientRect = annotCommand.TextRect;
  1002. //textArgs.Transparency = 1;
  1003. //textArgs.BgColor = Colors.Transparent;
  1004. //textArgs.LineColor = Colors.Red;
  1005. //textArgs.LineWidth = 2;
  1006. textArgs.TextContent = annotCommand.Text;
  1007. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, textArgs);
  1008. break;
  1009. case "StickyNote"://便签
  1010. StickyAnnotArgs stickyAnnotArgs = (StickyAnnotArgs)GetStickyNote();
  1011. //stickyAnnotArgs.ClientRect = annotCommand.TextRect;
  1012. List<TextSelectNode> textSelectNodes = PDFViewer.GetSelectTextInfo();
  1013. //stickyAnnotArgs.ClientRect = new Rect(textSelectNodes[0].StartPoint.X, annotCommand.TextRect.Y - annotCommand.TextRect.Height, annotCommand.TextRect.Width, annotCommand.TextRect.Height);
  1014. Rect rect = annotCommand.TextRectList[0];
  1015. #region to do 转dpi
  1016. //int dpi = DpiHelpers.Dpi;
  1017. //double x = rect.X / 72D * dpi;
  1018. //double y = (rect.Y - rect.Height) / 72D * dpi;
  1019. //double width = rect.Width / 72D * dpi;
  1020. //double height = rect.Height / 72D * dpi;
  1021. #endregion to do 转dpi
  1022. //stickyAnnotArgs.ClientRect = new Rect(x, y, width, height);
  1023. //stickyAnnotArgs.ClientRect = new Rect(rect.X, rect.Y - rect.Height, rect.Width, rect.Height);
  1024. stickyAnnotArgs.ClientRect = rect;
  1025. //PDFViewer.CreatePageAnnot(annotCommand.PageIndex, stickyAnnotArgs);
  1026. NavigationParameters param = new NavigationParameters();
  1027. param.Add(ParameterNames.PDFViewer, PDFViewer);
  1028. param.Add(ParameterNames.StickyAnnotArgs, stickyAnnotArgs);
  1029. param.Add(ParameterNames.ViewContentViewModel, viewContentViewModel);
  1030. param.Add(ParameterNames.AnnotCommandArgs, annotCommand);
  1031. ContentControl window = null;
  1032. if (PDFViewer.Parent as ContentControl != null)
  1033. {
  1034. window = PDFViewer.Parent as ContentControl;
  1035. }
  1036. else
  1037. {
  1038. window = App.Current.MainWindow;
  1039. }
  1040. var point = Mouse.GetPosition(window);
  1041. viewContentViewModel.NotePopupVisible = Visibility.Visible;
  1042. viewContentViewModel.CanvasNoteLeft = point.X;
  1043. viewContentViewModel.CanvasNoteBottom = point.Y;
  1044. if (point.Y > window.ActualHeight / 2)
  1045. {
  1046. viewContentViewModel.CanvasNoteBottom = point.Y - window.ActualHeight / 2;
  1047. }
  1048. viewContentViewModel.IsNoteAdd = true;
  1049. region.RequestNavigate(viewContentViewModel.NotePopupRegionName, "StickyNotePopup", param);
  1050. //stickyAnnotArgs.Author = Settings.Default.AppProperties.Description.Author;
  1051. //PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1052. //PDFViewer.SetToolParam(stickyAnnotArgs);
  1053. //PDFViewer.SetMouseMode(MouseModes.PanTool);
  1054. break;
  1055. case "Rect"://矩形
  1056. SquareAnnotArgs squareAnnotArgs = (SquareAnnotArgs)GetRect();
  1057. squareAnnotArgs.ClientRect = annotCommand.TextRect;
  1058. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, squareAnnotArgs);
  1059. break;
  1060. case "Circle"://圆
  1061. CircleAnnotArgs circleAnnotArgs = (CircleAnnotArgs)GetCircle();
  1062. circleAnnotArgs.ClientRect = annotCommand.TextRect;
  1063. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, circleAnnotArgs);
  1064. break;
  1065. case "Line"://线
  1066. LineAnnotArgs lineAnnotArgs = (LineAnnotArgs)GetArrowLine(clickMenu.Tag.ToString());
  1067. lineAnnotArgs.ClientRect = annotCommand.TextRect;
  1068. lineAnnotArgs.LinePoints.Add(new Point(annotCommand.TextRect.Left, annotCommand.TextRect.Top));
  1069. lineAnnotArgs.LinePoints.Add(new Point(annotCommand.TextRect.Right, annotCommand.TextRect.Bottom));
  1070. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, lineAnnotArgs);
  1071. break;
  1072. case "Link"://链接
  1073. LinkAnnotArgs linkArgs = new LinkAnnotArgs();
  1074. linkArgs.ClientRect = annotCommand.TextRect;
  1075. linkArgs.URI = string.Empty;
  1076. linkArgs.LinkType = LINK_TYPE.GOTO;
  1077. linkArgs.DestIndex = annotCommand.PageIndex;
  1078. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, linkArgs);
  1079. BtnLinkIsChecked = true;
  1080. List<AnnotHandlerEventArgs> lists = new List<AnnotHandlerEventArgs>();
  1081. lists.Add(linkArgs);
  1082. propertyPanel.IsAddLink = true;
  1083. AnnotHandlerEventArgs annotArgs = GetLink(lists);
  1084. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1085. PDFViewer.SetToolParam(annotArgs);
  1086. viewContentViewModel.IsPropertyOpen = true;
  1087. break;
  1088. case "OutLine":
  1089. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemOutLine");
  1090. if (isTabItemAnnotation == false)
  1091. {
  1092. bOTAContent.TabItemOutLine.IsSelected = true;
  1093. }
  1094. OutLineControlViewModel outLineControlViewModel = GetOutLineControlViewModel(bOTAContentViewModel, out OutLineControl outLineControl);
  1095. if (outLineControlViewModel != null && outLineControl != null)
  1096. {
  1097. string str = null;
  1098. if (string.IsNullOrEmpty(annotCommand.Text))
  1099. {
  1100. str = (annotCommand.PageIndex + 1).ToString();
  1101. }
  1102. else
  1103. {
  1104. str = annotCommand.Text;
  1105. }
  1106. outLineControl.AddOutlineNode(str);
  1107. }
  1108. break;
  1109. case "ExportPicture":
  1110. ExportPicture_MenuItemClick();
  1111. break;
  1112. }
  1113. //ShowPropertyPanel(false);
  1114. }
  1115. }
  1116. private void ExportPicture_MenuItemClick()
  1117. {
  1118. //图片提取
  1119. try
  1120. {
  1121. List<System.Drawing.Bitmap> imageList = new List<System.Drawing.Bitmap>();
  1122. Dictionary<int, List<System.Drawing.Bitmap>> imageDict = PDFViewer?.GetSelectedImages();
  1123. foreach (int pageIndex in imageDict.Keys)
  1124. {
  1125. imageList = imageDict[pageIndex];
  1126. }
  1127. string path = PDFViewer.Document.FileName;
  1128. System.Windows.Forms.FolderBrowserDialog folderDialog = new FolderBrowserDialog();
  1129. if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  1130. {
  1131. int i = 1;
  1132. int pagenum = 1;
  1133. string choosePath = folderDialog.SelectedPath;
  1134. string sPath = choosePath + "\\" + path + "_Extract Image";
  1135. sPath = GetExportPathName(sPath);
  1136. if (!Directory.Exists(sPath))
  1137. {
  1138. Directory.CreateDirectory(sPath);
  1139. }
  1140. if (Directory.Exists(sPath))
  1141. {
  1142. foreach (System.Drawing.Bitmap image in imageList)
  1143. {
  1144. foreach (var item in imageDict.Keys)
  1145. {
  1146. pagenum = item;
  1147. }
  1148. string filename = path + "_" + "Page" + (pagenum + 1).ToString() + "_" + GetNum(i);
  1149. string savePath = System.IO.Path.Combine(sPath, filename + ".jpg");
  1150. image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  1151. i++;
  1152. }
  1153. System.Diagnostics.Process.Start("explorer", "/select,\"" + sPath + "\"");
  1154. }
  1155. }
  1156. }
  1157. catch (Exception ex) { }
  1158. }
  1159. public string GetExportPathName(string path)
  1160. {
  1161. int i = 1;
  1162. string outpath = path;
  1163. while (Directory.Exists(outpath))
  1164. {
  1165. outpath = path + $"({i.ToString()})";
  1166. i++;
  1167. }
  1168. return outpath;
  1169. }
  1170. private string GetNum(int num)
  1171. {
  1172. if (num % 10 < 1)
  1173. {
  1174. return "00" + num.ToString();
  1175. }
  1176. if (num % 10 >= 1 && num % 10 < 10)
  1177. {
  1178. return "0" + num.ToString();
  1179. }
  1180. else
  1181. {
  1182. return num.ToString();
  1183. }
  1184. }
  1185. #region 注释右键菜单事件
  1186. //高亮、下划线、删除
  1187. private void HightAnnotCopyText_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. System.Windows.Clipboard.SetText(annot.Content);
  1196. }
  1197. }
  1198. }
  1199. //更改为当前注释属性默认值
  1200. private void AnnotDefaultValues_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. if (annot is TextHighlightAnnotArgs)
  1209. {
  1210. var color = (annot as TextHighlightAnnotArgs).Color;
  1211. HighLightColor = new SolidColorBrush(color);
  1212. Settings.Default.AppProperties.Annotate.HighLightColor = color;
  1213. var hightlight = GetAnnotDefault(AnnotArgsType.AnnotHighlight);
  1214. hightlight.ForgoundColor = color;
  1215. hightlight.Opacity = (annot as TextHighlightAnnotArgs).Transparency;
  1216. SettingHelper.SetAnnotDefaultProperty(hightlight);
  1217. }
  1218. else if (annot is TextUnderlineAnnotArgs)
  1219. {
  1220. var color = (annot as TextUnderlineAnnotArgs).Color;
  1221. UnderLineColor = new SolidColorBrush(color);
  1222. Settings.Default.AppProperties.Annotate.UnderLineColor = color;
  1223. var Underline = GetAnnotDefault(AnnotArgsType.AnnotUnderline);
  1224. Underline.ForgoundColor = color;
  1225. Underline.Opacity = (annot as TextUnderlineAnnotArgs).Transparency;
  1226. SettingHelper.SetAnnotDefaultProperty(Underline);
  1227. }
  1228. else if (annot is TextStrikeoutAnnotArgs)
  1229. {
  1230. var color = (annot as TextStrikeoutAnnotArgs).Color;
  1231. StrikeoutColor = new SolidColorBrush(color);
  1232. Settings.Default.AppProperties.Annotate.StrikethroughColor = color;
  1233. var Strikeout = GetAnnotDefault(AnnotArgsType.AnnotStrikeout);
  1234. Strikeout.ForgoundColor = color;
  1235. Strikeout.Opacity = (annot as TextStrikeoutAnnotArgs).Transparency;
  1236. SettingHelper.SetAnnotDefaultProperty(Strikeout);
  1237. }
  1238. else if (annot is FreehandAnnotArgs)
  1239. {
  1240. var freeHand = annot as FreehandAnnotArgs;
  1241. var color = freeHand.InkColor;
  1242. Settings.Default.AppProperties.Annotate.FreeHandColor = color;
  1243. var FreehandDefault = GetAnnotDefault(AnnotArgsType.AnnotFreehand);
  1244. FreehandDefault.ForgoundColor = color;
  1245. FreehandDefault.Opacity = freeHand.Transparency;
  1246. FreehandDefault.Thickness = freeHand.LineWidth;
  1247. var isSolid = AnnotPropertyPanel.IsSolidStyle(freeHand.LineDash);
  1248. if (isSolid)
  1249. {
  1250. FreehandDefault.DashArray = null;
  1251. }
  1252. else
  1253. {
  1254. FreehandDefault.DashArray = new List<double>();
  1255. foreach (var item in freeHand.LineDash.Dashes)
  1256. {
  1257. FreehandDefault.DashArray.Add(item);
  1258. }
  1259. }
  1260. SettingHelper.SetAnnotDefaultProperty(FreehandDefault);
  1261. }
  1262. else if (annot is FreeTextAnnotArgs)
  1263. {
  1264. var freeText = annot as FreeTextAnnotArgs;
  1265. Settings.Default.AppProperties.Annotate.TextAnnoteColor = freeText.FontColor;
  1266. Settings.Default.AppProperties.Annotate.TextFontFamaily = freeText.FontFamily.ToString();
  1267. Settings.Default.AppProperties.Annotate.TextAlign = freeText.Align;
  1268. var FreeTextDefalut = GetAnnotDefault(AnnotArgsType.AnnotFreeText);
  1269. FreeTextDefalut.ForgoundColor = freeText.FontColor;
  1270. FreeTextDefalut.FontFamily = freeText.FontFamily.ToString();
  1271. FreeTextDefalut.TextAlign = freeText.Align;
  1272. FreeTextDefalut.FontSize = freeText.FontSize;
  1273. FreeTextDefalut.FontWeight = freeText.FontWeight;
  1274. FreeTextDefalut.FontStyle = freeText.FontStyle;
  1275. FreeTextDefalut.BackgroundColor = freeText.BgColor;
  1276. FreeTextDefalut.Opacity = (annot as FreeTextAnnotArgs).Transparency;
  1277. SettingHelper.SetAnnotDefaultProperty(FreeTextDefalut);
  1278. }
  1279. else if (annot is StickyAnnotArgs)
  1280. {
  1281. var color = (annot as StickyAnnotArgs).Color;
  1282. Settings.Default.AppProperties.Annotate.NoteAnnoteColor = color;
  1283. var StickyDefalut = GetAnnotDefault(AnnotArgsType.AnnotSticky);
  1284. StickyDefalut.ForgoundColor = color;
  1285. SettingHelper.SetAnnotDefaultProperty(StickyDefalut);
  1286. }
  1287. else if (annot is SquareAnnotArgs)
  1288. {
  1289. var square = annot as SquareAnnotArgs;
  1290. var bgColor = square.BgColor;
  1291. Settings.Default.AppProperties.Annotate.RectangleFillColor = bgColor;
  1292. var borderColor = square.LineColor;
  1293. Settings.Default.AppProperties.Annotate.RectangleBorderColor = borderColor;
  1294. var SquareDefalut = GetAnnotDefault(AnnotArgsType.AnnotSquare);
  1295. SquareDefalut.BorderColor = borderColor;
  1296. SquareDefalut.BackgroundColor = bgColor;
  1297. SquareDefalut.Opacity = square.Transparency;
  1298. SquareDefalut.Thickness = square.LineWidth;
  1299. var isSolid = AnnotPropertyPanel.IsSolidStyle(square.LineDash);
  1300. if (isSolid)
  1301. {
  1302. SquareDefalut.DashArray = null;
  1303. }
  1304. else
  1305. {
  1306. SquareDefalut.DashArray = new List<double>();
  1307. foreach (var item in square.LineDash.Dashes)
  1308. {
  1309. SquareDefalut.DashArray.Add(item);
  1310. }
  1311. }
  1312. SettingHelper.SetAnnotDefaultProperty(SquareDefalut);
  1313. }
  1314. else if (annot is CircleAnnotArgs)
  1315. {
  1316. var circle = annot as CircleAnnotArgs;
  1317. var bgColor = circle.BgColor;
  1318. Settings.Default.AppProperties.Annotate.CircleFillColor = bgColor;
  1319. var borderColor = circle.LineColor;
  1320. Settings.Default.AppProperties.Annotate.CircleBorderColor = borderColor;
  1321. var CircleDefalut = GetAnnotDefault(AnnotArgsType.AnnotCircle);
  1322. CircleDefalut.BorderColor = borderColor;
  1323. CircleDefalut.BackgroundColor = bgColor;
  1324. CircleDefalut.Opacity = circle.Transparency;
  1325. CircleDefalut.Thickness = circle.LineWidth;
  1326. var isSolid = AnnotPropertyPanel.IsSolidStyle(circle.LineDash);
  1327. if (isSolid)
  1328. {
  1329. CircleDefalut.DashArray = null;
  1330. }
  1331. else
  1332. {
  1333. CircleDefalut.DashArray = new List<double>();
  1334. foreach (var item in circle.LineDash.Dashes)
  1335. {
  1336. CircleDefalut.DashArray.Add(item);
  1337. }
  1338. }
  1339. SettingHelper.SetAnnotDefaultProperty(CircleDefalut);
  1340. }
  1341. else if (annot is LineAnnotArgs)
  1342. {
  1343. var line = (annot as LineAnnotArgs);
  1344. var color = (annot as LineAnnotArgs).LineColor;
  1345. Settings.Default.AppProperties.Annotate.LineColor = color;
  1346. var lineDefalut = GetAnnotDefault(AnnotArgsType.AnnotLine);
  1347. lineDefalut.BorderColor = color;
  1348. lineDefalut.Opacity = (annot as LineAnnotArgs).Transparency;
  1349. lineDefalut.Thickness = (annot as LineAnnotArgs).LineWidth;
  1350. var isSolid = AnnotPropertyPanel.IsSolidStyle(line.LineDash);
  1351. if (isSolid)
  1352. {
  1353. lineDefalut.DashArray = null;
  1354. }
  1355. else
  1356. {
  1357. lineDefalut.DashArray = new List<double>();
  1358. foreach (var item in line.LineDash.Dashes)
  1359. {
  1360. lineDefalut.DashArray.Add(item);
  1361. }
  1362. }
  1363. SettingHelper.SetAnnotDefaultProperty(lineDefalut);
  1364. }
  1365. Settings.Default.Save();
  1366. }
  1367. }
  1368. }
  1369. private DefaultAnnotProperty GetAnnotDefault(AnnotArgsType annotArgsType)
  1370. {
  1371. var Annot = SettingHelper.GetAnnotDefaultProperty(annotArgsType);
  1372. if (Annot == null)
  1373. {
  1374. Annot = new DefaultAnnotProperty();
  1375. Annot.AnnotToolType = annotArgsType;
  1376. }
  1377. return Annot;
  1378. }
  1379. private System.Windows.Controls.Primitives.Popup popup = null;
  1380. //更改颜色
  1381. private async void AnnotColorPalette_Menu(object obj)
  1382. {
  1383. if (obj as CusMenuItem != null)
  1384. {
  1385. var menu = obj as CusMenuItem;
  1386. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1387. if (annot != null)
  1388. {
  1389. var item = new ColorDropBoxPop();
  1390. item.DataContext = menu;
  1391. item.ColorSelected -= AnnotMenu_ColorSelected;
  1392. item.ColorSelected += AnnotMenu_ColorSelected;
  1393. if (popup == null)
  1394. popup = new System.Windows.Controls.Primitives.Popup();
  1395. ContentControl window = null;
  1396. if (PDFViewer.Parent as ContentControl != null)
  1397. window = PDFViewer.Parent as ContentControl;
  1398. else
  1399. window = App.Current.MainWindow;
  1400. popup.Child = item;
  1401. popup.PlacementRectangle = new Rect(Mouse.GetPosition(window), new Size(item.Width, item.Height));
  1402. popup.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
  1403. popup.PlacementTarget = window;
  1404. popup.IsOpen = true;
  1405. Window parentWnd = Window.GetWindow(App.Current.MainWindow);
  1406. if (parentWnd != null)
  1407. {
  1408. parentWnd.MouseDown -= parentWnd_MouseDown;
  1409. parentWnd.MouseDown += parentWnd_MouseDown;
  1410. }
  1411. while (popup.IsOpen)
  1412. await Task.Delay(20);
  1413. parentWnd.MouseDown -= parentWnd_MouseDown;
  1414. popup = null;
  1415. }
  1416. }
  1417. }
  1418. private void parentWnd_MouseDown(object sender, MouseButtonEventArgs e)
  1419. {
  1420. var ui = Mouse.DirectlyOver as FrameworkElement;
  1421. if (ui != null)
  1422. {
  1423. if (popup != null)
  1424. {
  1425. popup.IsOpen = false;
  1426. }
  1427. }
  1428. }
  1429. private void AnnotMenu_ColorSelected(object sender, Color e)
  1430. {
  1431. if (sender != null)
  1432. {
  1433. var menu = (sender as FrameworkElement).DataContext as CusMenuItem;
  1434. if (menu == null) return;
  1435. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1436. if (annot != null)
  1437. {
  1438. if (annot is FreehandAnnotArgs || annot is StickyAnnotArgs || annot is LineAnnotArgs)
  1439. {
  1440. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1441. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  1442. AnnotEvent?.UpdateAnnot();
  1443. }
  1444. else if (annot is FreeTextAnnotArgs)
  1445. {
  1446. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1447. if (menu.tag.ToString() == "FontColor")
  1448. AnnotEvent?.UpdateAttrib(AnnotAttrib.FontColor, e);
  1449. else
  1450. AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, e);
  1451. AnnotEvent?.UpdateAnnot();
  1452. }
  1453. else if (annot is SquareAnnotArgs || annot is CircleAnnotArgs)
  1454. {
  1455. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1456. if (menu.tag.ToString() == "FillColor")
  1457. AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, e);
  1458. else
  1459. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  1460. AnnotEvent?.UpdateAnnot();
  1461. }
  1462. else if (annot is TextHighlightAnnotArgs || annot is TextUnderlineAnnotArgs || annot is TextStrikeoutAnnotArgs)
  1463. {
  1464. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1465. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  1466. AnnotEvent?.UpdateAnnot();
  1467. }
  1468. }
  1469. }
  1470. }
  1471. //添加笔记
  1472. private void AnnotAddNoteText_Menu(object obj)
  1473. {
  1474. if (obj as CusMenuItem != null)
  1475. {
  1476. var menu = obj as CusMenuItem;
  1477. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1478. PopAnnotNoteText(annot);
  1479. }
  1480. }
  1481. private void PopAnnotNoteText(AnnotHandlerEventArgs annot)
  1482. {
  1483. if (annot != null)
  1484. {
  1485. AnnotationHandlerEventArgs args = new AnnotationHandlerEventArgs();
  1486. args.ClientRect = annot.ClientRect;
  1487. args.AnnotHandlerEventArgs = annot;
  1488. args.PageIndex = annot.PageIndex;
  1489. args.AnnotIndex = annot.AnnotIndex;
  1490. args.EventType = annot.EventType;
  1491. args.CreateTime = annot.CreateTime;
  1492. args.UpdateTime = annot.UpdateTime;
  1493. args.Content = annot.Content;
  1494. args.MarkupContent = annot.MarkupContent;
  1495. args.Author = annot.Author;
  1496. args.Locked = annot.Locked;
  1497. args.ReadOnly = annot.ReadOnly;
  1498. args.FormField = annot.FormField;
  1499. args.Document = PDFViewer.Document;
  1500. DialogParameters value = new DialogParameters();
  1501. value.Add(ParameterNames.Annotation, args);
  1502. dialogs.ShowDialog(DialogNames.AddAnnotationDialog, value, e =>
  1503. {
  1504. if (e.Result == ButtonResult.OK && e.Parameters != null)
  1505. {
  1506. PDFViewer.UndoManager.CanSave = true;
  1507. if (e.Parameters.ContainsKey(ParameterNames.Annotation) && e.Parameters.ContainsKey(ParameterNames.AnnotEvent))
  1508. {
  1509. }
  1510. }
  1511. });
  1512. }
  1513. }
  1514. //手绘
  1515. private void FreeHandLineStyle_Menu(object obj)
  1516. {
  1517. if (obj as CusMenuItem != null)
  1518. {
  1519. var menu = obj as CusMenuItem;
  1520. var annot = menu.Parameter as FreehandAnnotArgs;
  1521. if (annot != null)
  1522. {
  1523. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1524. if (menu.tag.ToString() == "Solid")
  1525. {
  1526. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, AnnotPropertyPanel.GetLineDashStyle(true));
  1527. }
  1528. else
  1529. {
  1530. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, AnnotPropertyPanel.GetLineDashStyle(false));
  1531. }
  1532. AnnotEvent?.UpdateAnnot();
  1533. }
  1534. }
  1535. }
  1536. //文本
  1537. private void FreeTextFontFamily_Menu(object obj)
  1538. {
  1539. if (obj as CusMenuItem != null)
  1540. {
  1541. var menu = obj as CusMenuItem;
  1542. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1543. if (annot != null)
  1544. {
  1545. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1546. AnnotEvent?.UpdateAttrib(AnnotAttrib.FontFamily, new FontFamily(menu.tag.ToString()));
  1547. AnnotEvent?.UpdateAnnot();
  1548. }
  1549. }
  1550. }
  1551. private void FreeTextAglin_Menu(object obj)
  1552. {
  1553. if (obj as CusMenuItem != null)
  1554. {
  1555. var menu = obj as CusMenuItem;
  1556. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1557. var tag = menu.control.Tag;
  1558. if (annot != null && tag != null)
  1559. {
  1560. var strTag = tag.ToString();
  1561. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1562. if (strTag == "Left")
  1563. {
  1564. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Left);
  1565. }
  1566. else if (strTag == "Center")
  1567. {
  1568. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Center);
  1569. }
  1570. else if (strTag == "Right")
  1571. {
  1572. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Right);
  1573. }
  1574. else if (strTag == "Justify")
  1575. {
  1576. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Justify);
  1577. }
  1578. AnnotEvent?.UpdateAnnot();
  1579. }
  1580. }
  1581. }
  1582. //便签
  1583. private void StrikeNoteEditStrike_Menu(object obj)
  1584. {
  1585. if (obj as CusMenuItem != null)
  1586. {
  1587. var menu = obj as CusMenuItem;
  1588. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1589. if (annot != null)
  1590. {
  1591. var sticky = annot as StickyAnnotArgs;
  1592. sticky.PopupEditWnd();
  1593. #region 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
  1594. //isRightMenuAddAnnot = false;
  1595. #endregion 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
  1596. }
  1597. }
  1598. }
  1599. //形状
  1600. private void ShapeLineStyle_Menu(object obj)
  1601. {
  1602. if (obj as CusMenuItem != null)
  1603. {
  1604. var menu = obj as CusMenuItem;
  1605. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1606. var tag = menu.control.Tag;
  1607. if (annot != null && tag != null)
  1608. {
  1609. var strTag = tag.ToString();
  1610. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1611. if (strTag == "Solid")
  1612. {
  1613. var dashStyle = AnnotPropertyPanel.GetLineDashStyle(true);
  1614. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, dashStyle);
  1615. }
  1616. else
  1617. {
  1618. var dashStyle = AnnotPropertyPanel.GetLineDashStyle(false);
  1619. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, dashStyle);
  1620. }
  1621. AnnotEvent?.UpdateAnnot();
  1622. }
  1623. }
  1624. }
  1625. private void ShapeLineDirect_Menu(object obj)
  1626. {
  1627. if (obj as CusMenuItem != null)
  1628. {
  1629. var menu = obj as CusMenuItem;
  1630. var annot = menu.Parameter as LineAnnotArgs;
  1631. var tag = menu.control.Tag;
  1632. if (annot != null && tag != null)
  1633. {
  1634. var strTag = tag.ToString();
  1635. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1636. if (strTag == "Ver")
  1637. {
  1638. annot.SetLineVertical();
  1639. }
  1640. else
  1641. {
  1642. annot.SetLineHorizontal();
  1643. }
  1644. }
  1645. }
  1646. }
  1647. private void Link_Menu(object obj)
  1648. {
  1649. if (obj is CusMenuItem menuItem)
  1650. {
  1651. if (menuItem.Parameter is LinkAnnotArgs linkAnnotArgs)
  1652. {
  1653. var result = PDFViewer.RemovePageAnnot(linkAnnotArgs.PageIndex, linkAnnotArgs.AnnotIndex);
  1654. if (result)
  1655. {
  1656. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1657. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  1658. if (isTabItemAnnotation)
  1659. {
  1660. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  1661. if (viewModel != null)
  1662. {
  1663. viewModel.UpdateModifiedAnnot(linkAnnotArgs.PageIndex, linkAnnotArgs.AnnotIndex, true);
  1664. }
  1665. }
  1666. }
  1667. }
  1668. }
  1669. }
  1670. //图章
  1671. private void StampExportPicture_Menu(object obj)
  1672. {
  1673. if (obj as CusMenuItem != null)
  1674. {
  1675. var menu = obj as CusMenuItem;
  1676. var annot = menu.Parameter as StampAnnotArgs;
  1677. if (annot != null)
  1678. {
  1679. Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  1680. var format = menu.tag.ToString();
  1681. if (format == "PDF")
  1682. dlg.Filter = "PDF|*.pdf";
  1683. else
  1684. dlg.Filter = format + "|*." + format.ToLower();
  1685. dlg.DefaultExt = "." + menu.tag.ToString().ToLower();
  1686. dlg.FileName = PDFViewer.Document.FileName;
  1687. if (dlg.ShowDialog() == true)
  1688. {
  1689. var stampPicture = dlg.FileName;
  1690. if (menu.tag.ToString() == "PDF")
  1691. {
  1692. var writeStamp = annot.GetStampDrawing();
  1693. var tempDoc = new CPDFViewer();
  1694. tempDoc.CreateDocument();
  1695. if (tempDoc.Document == null)
  1696. {
  1697. AlertsMessage alertsMessage = new AlertsMessage();
  1698. alertsMessage.ShowDialog("", "创建文件失败.", "OK");
  1699. return;
  1700. }
  1701. byte[] buffer;
  1702. var encoder = new PngBitmapEncoder();
  1703. encoder.Frames.Add(BitmapFrame.Create(writeStamp));
  1704. using (var memoryStream = new MemoryStream())
  1705. {
  1706. encoder.Save(memoryStream);
  1707. buffer = memoryStream.ToArray();
  1708. }
  1709. tempDoc.Document.InsertPage(0, writeStamp.PixelWidth, writeStamp.PixelHeight, buffer, CPDFDocumentImageMode.CPDFDocumentImageModeScaleAspectFit);
  1710. var result = tempDoc.Document.WriteToFilePath(dlg.FileName);
  1711. if (result)
  1712. {
  1713. }
  1714. }
  1715. else
  1716. {
  1717. var writeStamp = annot.GetStampDrawing();
  1718. using (FileStream stream5 = new FileStream(stampPicture, FileMode.Create))
  1719. {
  1720. PngBitmapEncoder encoder5 = new PngBitmapEncoder();
  1721. encoder5.Frames.Add(BitmapFrame.Create(writeStamp));
  1722. encoder5.Save(stream5);
  1723. }
  1724. }
  1725. }
  1726. }
  1727. }
  1728. }
  1729. #endregion 注释右键菜单事件
  1730. #endregion 菜单
  1731. }
  1732. }