AnnotToolContentViewModel.Function.cs 76 KB

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