AnnotToolContentViewModel.Function.cs 78 KB

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