AnnotToolContentViewModel.Function.cs 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553
  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_Master.CustomControl;
  10. using PDF_Master.EventAggregators;
  11. using PDF_Master.Helper;
  12. using PDF_Master.Model;
  13. using PDF_Master.Model.AnnotPanel;
  14. using PDF_Master.Model.BOTA;
  15. using PDF_Master.Properties;
  16. using PDF_Master.ViewModels.BOTA;
  17. using PDF_Master.ViewModels.PropertyPanel.AnnotPanel;
  18. using PDF_Master.ViewModels.Tools.AnnotManager;
  19. using PDF_Master.Views.BOTA;
  20. using PDF_Master.Views.PropertyPanel.AnnotPanel;
  21. using PDFSettings;
  22. using Prism.Mvvm;
  23. using Prism.Regions;
  24. using Prism.Services.Dialogs;
  25. using System;
  26. using System.Collections.Generic;
  27. using System.Drawing;
  28. using System.IO;
  29. using System.Linq;
  30. using System.Text;
  31. using System.Threading.Tasks;
  32. using System.Windows;
  33. using System.Windows.Controls;
  34. using System.Windows.Documents;
  35. using System.Windows.Forms;
  36. using System.Windows.Input;
  37. using System.Windows.Media;
  38. using System.Windows.Media.Imaging;
  39. using static Dropbox.Api.Sharing.ListFileMembersIndividualResult;
  40. using Color = System.Windows.Media.Color;
  41. using ContextMenu = System.Windows.Controls.ContextMenu;
  42. using FontFamily = System.Windows.Media.FontFamily;
  43. using HorizontalAlignment = System.Windows.HorizontalAlignment;
  44. using MenuItem = System.Windows.Controls.MenuItem;
  45. using OpenFileDialog = Microsoft.Win32.OpenFileDialog;
  46. namespace PDF_Master.ViewModels.Tools
  47. {
  48. //文件说明:初始化注释工具的数据,注释工具,菜单响应事件
  49. public sealed partial class AnnotToolContentViewModel : BindableBase, INavigationAware
  50. {
  51. #region 初始化
  52. #region 初始化数据
  53. //初始化注释的属性值,并存在本地缓存数据集里
  54. private void InitDefaultValue()
  55. {
  56. InitToolBtnUI();
  57. }
  58. //注释工具按钮初始化时的属性值
  59. private void InitToolBtnUI()
  60. {
  61. var annotate = Settings.Default.AppProperties.Annotate;
  62. InitAnnotHighlight(annotate);
  63. InitAnnotUnderline(annotate);
  64. InitAnnotSquiggly(annotate);
  65. InitAnnotStrikeout(annotate);
  66. InitAnnotFreeHand(annotate);
  67. InitAnnotLine(annotate);
  68. }
  69. private void InitAnnotLine(AnnotatePropertyClass annotate)
  70. {
  71. if (annotate != null && annotate.LineColor != Colors.Transparent)
  72. {
  73. LineColor = new SolidColorBrush(annotate.LineColor);
  74. }
  75. else
  76. {
  77. LineColor = new SolidColorBrush(Colors.Red);
  78. }
  79. if (annotate != null && annotate.ArrowColor != Colors.Transparent)
  80. {
  81. ArrowColor = new SolidColorBrush(annotate.ArrowColor);
  82. }
  83. else
  84. {
  85. ArrowColor = new SolidColorBrush(Colors.Red);
  86. }
  87. }
  88. private void InitAnnotFreeHand(AnnotatePropertyClass annotate)
  89. {
  90. if (annotate != null && annotate.FreeHandColor != Colors.Transparent)
  91. {
  92. FreeHandColor = new SolidColorBrush(annotate.FreeHandColor);
  93. }
  94. else
  95. {
  96. Color color = Color.FromRgb(0x38, 0xE0, 0x2E);
  97. FreeHandColor = new SolidColorBrush(color);
  98. }
  99. }
  100. private void InitAnnotHighlight(AnnotatePropertyClass annotate)
  101. {
  102. //var annotate = Settings.Default.AppProperties.Annotate;
  103. if (annotate != null && annotate.HighLightColor != Colors.Transparent)
  104. {
  105. HighLightColor = new SolidColorBrush(annotate.HighLightColor);
  106. HighLightOpacity = 1;
  107. }
  108. else
  109. {
  110. HighLightColor = new SolidColorBrush(Colors.Red);
  111. HighLightOpacity = 1;
  112. }
  113. }
  114. private void InitAnnotUnderline(AnnotatePropertyClass annotate)
  115. {
  116. //var annotate = Settings.Default.AppProperties.Annotate;
  117. //避免默认值为透明度
  118. if (annotate != null && annotate.UnderLineColor != Colors.Transparent)
  119. {
  120. UnderLineColor = new SolidColorBrush(annotate.UnderLineColor);
  121. HighLightOpacity = 1;
  122. }
  123. else
  124. {
  125. UnderLineColor = new SolidColorBrush(Colors.Red);
  126. UnderLineOpacity = 1;
  127. }
  128. }
  129. private void InitAnnotSquiggly(AnnotatePropertyClass annotate)
  130. {
  131. //var annotate = Settings.Default.AppProperties.Annotate;
  132. if (annotate != null && annotate.StrikethroughColor != Colors.Transparent)
  133. {
  134. SquigglyColor = new SolidColorBrush(annotate.StrikethroughColor);
  135. SquigglyOpacity = 1;
  136. }
  137. else
  138. {
  139. SquigglyColor = new SolidColorBrush(Colors.Red);
  140. SquigglyOpacity = 1;
  141. }
  142. }
  143. private void InitAnnotStrikeout(AnnotatePropertyClass annotate)
  144. {
  145. //var annotate = Settings.Default.AppProperties.Annotate;
  146. if (annotate != null && annotate.StrikethroughColor != Colors.Transparent)
  147. {
  148. StrikeoutColor = new SolidColorBrush(annotate.StrikethroughColor);
  149. StrikeoutOpacity = 1;
  150. }
  151. else
  152. {
  153. StrikeoutColor = new SolidColorBrush(Colors.Red);
  154. StrikeoutOpacity = 1;
  155. }
  156. }
  157. //在xaml里引用
  158. public Dictionary<string, string> GetToolTipDict
  159. { get { return ToolTipDict; } }
  160. //用来记录选中、创建注释的标识
  161. private void InitToolDict()
  162. {
  163. ToolExpandDict.Add("SnapshotEdit", AnnotArgsType.SnapshotWithEditTool);
  164. ToolExpandDict.Add("HighLight", AnnotArgsType.AnnotHighlight);
  165. ToolExpandDict.Add("UnderLine", AnnotArgsType.AnnotUnderline);
  166. ToolExpandDict.Add("Squiggly", AnnotArgsType.AnnotSquiggly);
  167. ToolExpandDict.Add("Strikeout", AnnotArgsType.AnnotStrikeout);
  168. ToolExpandDict.Add("Freehand", AnnotArgsType.AnnotFreehand);
  169. ToolExpandDict.Add("Freetext", AnnotArgsType.AnnotFreeText);
  170. ToolExpandDict.Add("StickyNote", AnnotArgsType.AnnotSticky);
  171. ToolExpandDict.Add("Rect", AnnotArgsType.AnnotSquare);
  172. ToolExpandDict.Add("Circle", AnnotArgsType.AnnotCircle);
  173. ToolExpandDict.Add("Arrow", AnnotArgsType.AnnotLine);
  174. ToolExpandDict.Add("Line", AnnotArgsType.AnnotLine);
  175. ToolExpandDict.Add("Link", AnnotArgsType.AnnotLink);
  176. ToolExpandDict.Add("Stamp", AnnotArgsType.AnnotStamp);
  177. }
  178. //注释工具按钮悬浮文案
  179. private void InitToolTipDict()
  180. {
  181. //原来文案
  182. //ToolTipDict.Add("Hand", "滚动工具");
  183. //ToolTipDict.Add("BtnSelecttool", "内容选择工具");
  184. //ToolTipDict.Add("SnapshotEdit", "内容选择工具");
  185. //ToolTipDict.Add("HighLight", "高亮" + " | Ctrl+Alt+H");
  186. //ToolTipDict.Add("UnderLine", "下划线" + " | Ctrl+Alt+U");
  187. //ToolTipDict.Add("Squiggly", "波浪线" + " | Ctrl+Alt+Q");
  188. //ToolTipDict.Add("Strikeout", "删除线" + " | Ctrl+Alt+S");
  189. //ToolTipDict.Add("Freehand", "手绘");
  190. //ToolTipDict.Add("Freetext", "文字");
  191. //ToolTipDict.Add("StickyNote", "便签");
  192. //ToolTipDict.Add("Rect", "矩形");
  193. //ToolTipDict.Add("Circle", "圆");
  194. //ToolTipDict.Add("Arrow", "箭头");
  195. //ToolTipDict.Add("Line", "线条");
  196. //ToolTipDict.Add("Link", "超链接");
  197. //ToolTipDict.Add("Stamp", "图章");
  198. //ToolTipDict.Add("Image", "图片");
  199. //ToolTipDict.Add("Signature", "签名");
  200. //ToolTipDict.Add("ShowAnnot", "显示/隐藏注释");
  201. ToolTipDict.Add("Hand", App.MainPageLoader.GetString("ToolTipsAonnot_ScrollTool"));
  202. ToolTipDict.Add("BtnSelecttool", App.MainPageLoader.GetString("ToolTipsAonnot_ContentSelection"));
  203. ToolTipDict.Add("SnapshotEdit", App.MainPageLoader.GetString("ToolTipsAonnot_ContentSelection"));
  204. ToolTipDict.Add("HighLight", App.MainPageLoader.GetString("ToolTipsAonnot_HighLight"));
  205. ToolTipDict.Add("UnderLine", App.MainPageLoader.GetString("ToolTipsAonnot_UnderLine"));
  206. ToolTipDict.Add("Squiggly", App.MainPageLoader.GetString("ToolTipsAonnot_Squiggly"));
  207. ToolTipDict.Add("Strikeout", App.MainPageLoader.GetString("ToolTipsAonnot_Strikeout"));
  208. ToolTipDict.Add("Freehand", App.MainPageLoader.GetString("ToolTipsAonnot_Freehand"));
  209. ToolTipDict.Add("Freetext", App.MainPageLoader.GetString("ToolTipsAonnot_Text"));
  210. ToolTipDict.Add("StickyNote", App.MainPageLoader.GetString("ToolTipsAonnot_StickyNote"));
  211. ToolTipDict.Add("Rect", App.MainPageLoader.GetString("ToolTipsAonnot_Sharps"));
  212. ToolTipDict.Add("Circle", App.MainPageLoader.GetString("ToolTipsAonnot_Sharps"));
  213. ToolTipDict.Add("Arrow", App.MainPageLoader.GetString("ToolTipsAonnot_Sharps"));
  214. ToolTipDict.Add("Line", App.MainPageLoader.GetString("ToolTipsAonnot_Sharps"));
  215. ToolTipDict.Add("Link", App.MainPageLoader.GetString("ToolTipsAonnot_Link"));
  216. ToolTipDict.Add("Stamp", App.MainPageLoader.GetString("ToolTipsAonnot_Stamp"));
  217. ToolTipDict.Add("Image", App.MainPageLoader.GetString("ToolTipsAonnot_Stamp"));
  218. ToolTipDict.Add("Signature", App.MainPageLoader.GetString("ToolTipsAonnot_Signature"));
  219. ToolTipDict.Add("ShowAnnot", App.MainPageLoader.GetString("ToolTipsAonnot_ShowAnnot"));
  220. }
  221. //便签批注弹窗
  222. private void LoaedStickyNotePopup()
  223. {
  224. if (PDFViewer == null) return;
  225. if (customStickyPopup == null)
  226. {
  227. customStickyPopup = new StickyNotePopup(events);
  228. PDFViewer.SetStickyNotePop(customStickyPopup);
  229. }
  230. }
  231. #endregion 初始化数据
  232. #endregion 初始化
  233. #region 注释工具
  234. //注释工具
  235. public void FindAnnotTypeKey(string tag, ref AnnotHandlerEventArgs annotArgs, bool isRightMenuAdd = false)
  236. {
  237. switch (tag)
  238. {
  239. case "SnapshotEdit"://内容选择
  240. annotArgs = GetSnapshotEdit();
  241. break;
  242. case "HighLight"://字体高亮
  243. annotArgs = GetHighLight();
  244. break;
  245. case "UnderLine"://下划线
  246. annotArgs = GetUnderLine();
  247. break;
  248. case "Squiggly"://波浪线
  249. annotArgs = GetSquiggly();
  250. break;
  251. case "Strikeout"://删除线
  252. annotArgs = GetStrikeout();
  253. break;
  254. case "Freehand"://手绘
  255. annotArgs = GetFreehand();
  256. break;
  257. case "Freetext"://文本
  258. annotArgs = GetFreetext();
  259. break;
  260. case "StickyNote"://便签
  261. annotArgs = GetStickyNote();
  262. break;
  263. case "Rect"://矩形
  264. switch (PropertyPanel.SharpsAnnot)
  265. {
  266. case "Rect":
  267. annotArgs = GetRect();
  268. break;
  269. case "Circle":
  270. annotArgs = GetCircle();
  271. break;
  272. case "Arrow":
  273. annotArgs = GetArrowLine("Arrow");
  274. break;
  275. case "Line":
  276. annotArgs = GetArrowLine("Line");
  277. break;
  278. }
  279. break;
  280. case "RectKey":
  281. //选中时需设置以及点击图形按钮选中("Rect"->即代表按钮标识有代表矩形图案(将快捷键矩形改名为RectKey))
  282. StrAnnotToolChecked = "Rect";
  283. PropertyPanel.IsSharpAnnotSelected = true;
  284. annotArgs = GetRect();
  285. break;
  286. case "Circle"://圆
  287. StrAnnotToolChecked = "Rect";
  288. PropertyPanel.IsSharpAnnotSelected = true;
  289. annotArgs = GetCircle();
  290. break;
  291. case "Arrow"://箭头
  292. case "Line"://线
  293. StrAnnotToolChecked = "Rect";
  294. PropertyPanel.IsSharpAnnotSelected = true;
  295. annotArgs = GetArrowLine(tag);
  296. break;
  297. case "Stamp"://图章
  298. //付费锁
  299. //判断本地有没有token,没有显示登录,有再判断登录状态
  300. if (!viewContentViewModel.IAPBeforeFunction())
  301. {
  302. return;
  303. }
  304. annotArgs = GetStamp();
  305. break;
  306. case "Image":
  307. annotArgs = GetImage();
  308. break;
  309. case "Signature"://签名
  310. //判断本地有没有token,没有显示登录,有再判断登录状态
  311. if (!viewContentViewModel.IAPBeforeFunction())
  312. {
  313. return;
  314. }
  315. annotArgs = GetSignature();
  316. PDFViewer.SetMouseMode(MouseModes.PanTool);//清空其他注释
  317. break;
  318. case "Link"://链接
  319. //付费锁
  320. //判断本地有没有token,没有显示登录,有再判断登录状态
  321. if (!viewContentViewModel.IAPBeforeFunction())
  322. {
  323. return;
  324. }
  325. PropertyPanel.IsAddLink = true;
  326. viewContentViewModel.IsRightMenuCreateLink = isRightMenuAdd;
  327. annotArgs = GetLink();
  328. break;
  329. }
  330. if (annotArgs != null)
  331. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  332. }
  333. /// <summary>
  334. /// 链接
  335. /// </summary>
  336. /// <param name="selectedArgs">所选中的注释</param>
  337. /// <param name="annotAttribEvent">注释属性列表</param>
  338. public AnnotHandlerEventArgs GetLink(List<AnnotHandlerEventArgs> selectedArgs = null, AnnotAttribEvent annotAttribEvent = null)
  339. {
  340. LinkAnnotArgs linkArgs = new LinkAnnotArgs();
  341. if (selectedArgs != null && selectedArgs.Count > 0)
  342. {
  343. linkArgs = selectedArgs[0] as LinkAnnotArgs;
  344. }
  345. else
  346. {
  347. linkArgs.URI = string.Empty;
  348. linkArgs.LinkType = LINK_TYPE.GOTO;
  349. linkArgs.DestIndex = -1;
  350. if (linkArgs != null)
  351. {
  352. selectedArgs = new List<AnnotHandlerEventArgs>();
  353. selectedArgs.Add(linkArgs);
  354. if (viewContentViewModel.IsRightMenuCreateLink == false)
  355. {
  356. AnnotHandlerEventArgs annotHandler = CreateAnnotFromSelectPageText(linkArgs);
  357. if (annotHandler is LinkAnnotArgs annotArgs)
  358. {
  359. selectedArgs.Clear();
  360. selectedArgs.Add(annotArgs);
  361. PropertyPanel.IsSelectedTextAddLink = true;
  362. //PDFViewer.SelectAnnotation(annotArgs.PageIndex, annotArgs.AnnotIndex);
  363. //viewContentViewModel.IsPropertyOpen = true;
  364. //return linkArgs;
  365. }
  366. }
  367. }
  368. }
  369. AddToPropertyPanel("LinkAnnotProperty", "Link", selectedArgs, annotAttribEvent);
  370. return linkArgs;
  371. }
  372. //创建,选中,保留上次属性值的注释
  373. /// <summary>
  374. /// 高亮注释
  375. /// </summary>
  376. private AnnotHandlerEventArgs GetHighLight(List<AnnotHandlerEventArgs> selectedArgs = null)
  377. {
  378. TextHighlightAnnotArgs highlightArgs = null;
  379. if (selectedArgs == null || selectedArgs.Count == 0)
  380. {
  381. highlightArgs = new TextHighlightAnnotArgs();
  382. highlightArgs.Transparency = HighLightOpacity;
  383. highlightArgs.Color = (HighLightColor as SolidColorBrush).Color;
  384. if (PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotHighlight] == null)
  385. {
  386. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(highlightArgs.EventType);
  387. if (defaultAnnot == null)
  388. {
  389. defaultAnnot = new DefaultAnnotProperty();
  390. defaultAnnot.AnnotToolType = highlightArgs.EventType;
  391. defaultAnnot.ForgoundColor = (HighLightColor as SolidColorBrush).Color;
  392. defaultAnnot.Opacity = 1;
  393. HighLightOpacity = defaultAnnot.Opacity;
  394. HighLightColor = new SolidColorBrush(defaultAnnot.ForgoundColor);
  395. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  396. Settings.Default.Save();
  397. }
  398. //else
  399. //{
  400. // (HighLightColor as SolidColorBrush).Color = defaultAnnot.ForgoundColor;
  401. // highlightArgs.Color = defaultAnnot.ForgoundColor;
  402. //}
  403. //HighLightOpacity = highlightArgs.Transparency = defaultAnnot.Opacity;
  404. highlightArgs.Color = defaultAnnot.ForgoundColor;
  405. highlightArgs.Transparency = defaultAnnot.Opacity;
  406. }
  407. //else
  408. //{
  409. // TextHighlightAnnotArgs annotArgs = PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotHighlight] as TextHighlightAnnotArgs;
  410. // highlightArgs = new TextHighlightAnnotArgs();
  411. // highlightArgs.Color = annotArgs.Color;
  412. // highlightArgs.Transparency = annotArgs.Transparency;
  413. // HighLightColor = new SolidColorBrush(highlightArgs.Color);
  414. // HighLightOpacity = highlightArgs.Transparency;
  415. //}
  416. selectedArgs = new List<AnnotHandlerEventArgs>();
  417. highlightArgs.Color = (HighLightColor as SolidColorBrush).Color;
  418. highlightArgs.Transparency = HighLightOpacity;
  419. selectedArgs.Add(highlightArgs);
  420. }
  421. else
  422. {
  423. highlightArgs = selectedArgs[0] as TextHighlightAnnotArgs;
  424. HighLightColor = new SolidColorBrush(highlightArgs.Color);
  425. HighLightOpacity = highlightArgs.Transparency;
  426. }
  427. selectedArgs = new List<AnnotHandlerEventArgs>();
  428. selectedArgs.Add(highlightArgs);
  429. AddToPropertyPanel("TextAnnotProperty", "HighLight", selectedArgs);
  430. return highlightArgs;
  431. }
  432. /// <summary>
  433. /// 下划线
  434. /// </summary>
  435. /// <param name="selectedArgs"></param>
  436. private AnnotHandlerEventArgs GetUnderLine(List<AnnotHandlerEventArgs> selectedArgs = null)
  437. {
  438. TextUnderlineAnnotArgs underlineArgs = null;
  439. if (selectedArgs == null || selectedArgs.Count == 0)
  440. {
  441. underlineArgs = new TextUnderlineAnnotArgs();
  442. underlineArgs.Transparency = UnderLineOpacity;
  443. underlineArgs.Color = (UnderLineColor as SolidColorBrush).Color;
  444. if (PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotUnderline] == null)
  445. {
  446. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(underlineArgs.EventType);
  447. if (defaultAnnot == null)
  448. {
  449. defaultAnnot = new DefaultAnnotProperty();
  450. defaultAnnot.AnnotToolType = underlineArgs.EventType;
  451. defaultAnnot.ForgoundColor = (UnderLineColor as SolidColorBrush).Color;
  452. defaultAnnot.Opacity = 1;
  453. UnderLineOpacity = defaultAnnot.Opacity;
  454. UnderLineColor = new SolidColorBrush(defaultAnnot.ForgoundColor);
  455. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  456. Settings.Default.Save();
  457. }
  458. underlineArgs.Color = defaultAnnot.ForgoundColor;
  459. underlineArgs.Transparency = defaultAnnot.Opacity;
  460. }
  461. selectedArgs = new List<AnnotHandlerEventArgs>();
  462. underlineArgs.Color = (UnderLineColor as SolidColorBrush).Color;
  463. underlineArgs.Transparency = UnderLineOpacity;
  464. selectedArgs.Add(underlineArgs);
  465. }
  466. else
  467. {
  468. underlineArgs = selectedArgs[0] as TextUnderlineAnnotArgs;
  469. UnderLineColor = new SolidColorBrush(underlineArgs.Color);
  470. UnderLineOpacity = underlineArgs.Transparency;
  471. }
  472. //selectedArgs = new List<AnnotHandlerEventArgs>();
  473. //selectedArgs.Add(underlineArgs);
  474. AddToPropertyPanel("TextAnnotProperty", "UnderLine", selectedArgs);
  475. return underlineArgs;
  476. }
  477. /// <summary>
  478. /// 波浪线
  479. /// </summary>
  480. /// <param name="selectedArgs"></param>
  481. /// <returns></returns>
  482. private AnnotHandlerEventArgs GetSquiggly(List<AnnotHandlerEventArgs> selectedArgs = null)
  483. {
  484. TextSquigglyAnnotArgs squigglyArgs = null;
  485. if (selectedArgs == null || selectedArgs.Count == 0)
  486. {
  487. squigglyArgs = new TextSquigglyAnnotArgs();
  488. squigglyArgs.Transparency = SquigglyOpacity;
  489. squigglyArgs.Color = (squigglyColor as SolidColorBrush).Color;
  490. if (PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotSquiggly] == null)
  491. {
  492. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(squigglyArgs.EventType);
  493. if (defaultAnnot == null)
  494. {
  495. defaultAnnot = new DefaultAnnotProperty();
  496. defaultAnnot.AnnotToolType = squigglyArgs.EventType;
  497. defaultAnnot.ForgoundColor = (squigglyColor as SolidColorBrush).Color;
  498. defaultAnnot.Opacity = 1;
  499. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  500. Settings.Default.Save();
  501. }
  502. SquigglyOpacity = squigglyArgs.Transparency = defaultAnnot.Opacity;
  503. }
  504. selectedArgs = new List<AnnotHandlerEventArgs>();
  505. selectedArgs.Add(squigglyArgs);
  506. }
  507. else
  508. {
  509. squigglyArgs = selectedArgs[0] as TextSquigglyAnnotArgs;
  510. }
  511. AddToPropertyPanel("TextAnnotProperty", "Squiggly", selectedArgs);
  512. return squigglyArgs;
  513. }
  514. /// <summary>
  515. /// 删除线
  516. /// </summary>
  517. /// <param name="selectedArgs"></param>
  518. /// <returns></returns>
  519. private AnnotHandlerEventArgs GetStrikeout(List<AnnotHandlerEventArgs> selectedArgs = null)
  520. {
  521. TextStrikeoutAnnotArgs strikeoutArgs = null;
  522. if (selectedArgs == null || selectedArgs.Count == 0)
  523. {
  524. strikeoutArgs = new TextStrikeoutAnnotArgs();
  525. strikeoutArgs.Transparency = StrikeoutOpacity;
  526. strikeoutArgs.Color = (StrikeoutColor as SolidColorBrush).Color;
  527. if (PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotStrikeout] == null)
  528. {
  529. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(strikeoutArgs.EventType);
  530. if (defaultAnnot == null)
  531. {
  532. defaultAnnot = new DefaultAnnotProperty();
  533. defaultAnnot.AnnotToolType = strikeoutArgs.EventType;
  534. defaultAnnot.ForgoundColor = (StrikeoutColor as SolidColorBrush).Color;
  535. defaultAnnot.Opacity = 1;
  536. StrikeoutOpacity = defaultAnnot.Opacity;
  537. StrikeoutColor = new SolidColorBrush(defaultAnnot.ForgoundColor);
  538. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  539. Settings.Default.Save();
  540. }
  541. strikeoutArgs.Color = defaultAnnot.ForgoundColor;
  542. strikeoutArgs.Transparency = defaultAnnot.Opacity;
  543. }
  544. selectedArgs = new List<AnnotHandlerEventArgs>();
  545. strikeoutArgs.Color = (StrikeoutColor as SolidColorBrush).Color;
  546. strikeoutArgs.Transparency = StrikeoutOpacity;
  547. selectedArgs.Add(strikeoutArgs);
  548. }
  549. else
  550. {
  551. strikeoutArgs = selectedArgs[0] as TextStrikeoutAnnotArgs;
  552. StrikeoutColor = new SolidColorBrush(strikeoutArgs.Color);
  553. StrikeoutOpacity = strikeoutArgs.Transparency;
  554. }
  555. AddToPropertyPanel("TextAnnotProperty", "Strikeout", selectedArgs);
  556. return strikeoutArgs;
  557. }
  558. /// <summary>
  559. /// 手绘
  560. /// </summary>
  561. /// <param name="selectedArgs"></param>
  562. /// <returns></returns>
  563. private AnnotHandlerEventArgs GetFreehand(List<AnnotHandlerEventArgs> selectedArgs = null)
  564. {
  565. FreehandAnnotArgs freehandArgs = null;
  566. if (selectedArgs == null || selectedArgs.Count == 0)
  567. {
  568. freehandArgs = new FreehandAnnotArgs();
  569. //var annotate = Settings.Default.AppProperties.Annotate;
  570. //if (annotate != null)
  571. //{
  572. // freehandArgs.InkColor = annotate.FreeHandColor;
  573. //}
  574. //else
  575. //{
  576. // freehandArgs.InkColor = Color.FromRgb(0x38, 0xE0, 0x2E);
  577. //}
  578. freehandArgs.InkColor = (FreeHandColor as SolidColorBrush).Color;
  579. if (PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotFreehand] == null)
  580. {
  581. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(freehandArgs.EventType);
  582. if (defaultAnnot == null)
  583. {
  584. defaultAnnot = new DefaultAnnotProperty();
  585. defaultAnnot.AnnotToolType = freehandArgs.EventType;
  586. defaultAnnot.ForgoundColor = (FreeHandColor as SolidColorBrush).Color;
  587. defaultAnnot.Opacity = 1;
  588. defaultAnnot.Thickness = 2;
  589. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  590. Settings.Default.Save();
  591. }
  592. freehandArgs.Transparency = defaultAnnot.Opacity;
  593. freehandArgs.LineWidth = defaultAnnot.Thickness;
  594. freehandArgs.InkColor = defaultAnnot.ForgoundColor;
  595. if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
  596. {
  597. freehandArgs.LineDash = DashStyles.Solid;
  598. }
  599. else
  600. {
  601. var collect = new DoubleCollection();
  602. foreach (var item in defaultAnnot.DashArray)
  603. {
  604. collect.Add(item);
  605. }
  606. if (freehandArgs.LineDash == null)
  607. freehandArgs.LineDash = new DashStyle();
  608. freehandArgs.LineDash.Dashes = collect;
  609. }
  610. }
  611. else
  612. {
  613. FreehandAnnotArgs freehandAnnotArgs = PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotFreehand] as FreehandAnnotArgs;
  614. freehandArgs = new FreehandAnnotArgs();
  615. freehandArgs.InkColor = freehandAnnotArgs.InkColor;
  616. freehandArgs.Transparency = freehandAnnotArgs.Transparency;
  617. freehandArgs.LineWidth = freehandAnnotArgs.LineWidth;
  618. freehandArgs.LineDash = freehandAnnotArgs.LineDash;
  619. }
  620. selectedArgs = new List<AnnotHandlerEventArgs>();
  621. selectedArgs.Add(freehandArgs);
  622. }
  623. else
  624. {
  625. freehandArgs = selectedArgs[0] as FreehandAnnotArgs;
  626. if (NavigatedToFillAndSignVM(selectedArgs, "Freehand"))
  627. {
  628. return freehandArgs;
  629. }
  630. }
  631. AddToPropertyPanel("FreehandAnnotProperty", "Freehand", selectedArgs);
  632. return freehandArgs;
  633. }
  634. /// <summary>
  635. /// 文本
  636. /// </summary>
  637. /// <param name="selectedArgs"></param>
  638. /// <returns></returns>
  639. private AnnotHandlerEventArgs GetFreetext(List<AnnotHandlerEventArgs> selectedArgs = null)
  640. {
  641. FreeTextAnnotArgs freetextArgs = null;
  642. TextAlignment textAlignment;
  643. if (selectedArgs == null || selectedArgs.Count == 0)
  644. {
  645. freetextArgs = new FreeTextAnnotArgs();
  646. var annotate = Settings.Default.AppProperties.Annotate;
  647. if (annotate != null)
  648. {
  649. freetextArgs.FontColor = annotate.TextAnnoteColor;
  650. }
  651. else
  652. {
  653. freetextArgs.FontColor = Colors.Black;
  654. }
  655. if (PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotFreeText] == null)
  656. {
  657. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(freetextArgs.EventType);
  658. if (defaultAnnot == null)
  659. {
  660. defaultAnnot = new DefaultAnnotProperty();
  661. defaultAnnot.AnnotToolType = freetextArgs.EventType;
  662. defaultAnnot.ForgoundColor = freetextArgs.FontColor;
  663. defaultAnnot.BorderColor = Colors.Transparent;
  664. defaultAnnot.BackgroundColor = Colors.White;
  665. defaultAnnot.Opacity = 1;
  666. defaultAnnot.FontFamily = Settings.Default.AppProperties.Annotate.TextFontFamaily;
  667. defaultAnnot.FontSize = 14;
  668. defaultAnnot.TextAlign = TextAlignment.Left;
  669. defaultAnnot.Thickness = 0;
  670. defaultAnnot.NoteText = string.Empty;
  671. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  672. Settings.Default.Save();
  673. }
  674. freetextArgs.FontColor = defaultAnnot.ForgoundColor;
  675. freetextArgs.LineColor = defaultAnnot.BorderColor;
  676. freetextArgs.BgColor = defaultAnnot.BackgroundColor;
  677. freetextArgs.Transparency = defaultAnnot.Opacity;
  678. freetextArgs.FontFamily = new FontFamily(defaultAnnot.FontFamily);
  679. freetextArgs.FontSize = defaultAnnot.FontSize;
  680. freetextArgs.FontWeight = defaultAnnot.FontWeight;
  681. freetextArgs.FontStyle = defaultAnnot.FontStyle;
  682. freetextArgs.LineWidth = defaultAnnot.Thickness;
  683. freetextArgs.BgColor = defaultAnnot.BackgroundColor;
  684. int align = (int)Settings.Default.AppProperties.Annotate.TextAlign;
  685. if (align == 0)
  686. textAlignment = TextAlignment.Left;
  687. else if (align == 1)
  688. textAlignment = TextAlignment.Center;
  689. else
  690. textAlignment = TextAlignment.Right;
  691. freetextArgs.Align = textAlignment;
  692. }
  693. else
  694. {
  695. FreeTextAnnotArgs freeText = PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotFreeText] as FreeTextAnnotArgs;
  696. freetextArgs = SetFreetextArgs(freeText);
  697. //freetextArgs = SetFreetextArgs(freeText);
  698. //freetextArgs.Content = string.Empty;
  699. //freetextArgs.TextContent = string.Empty;
  700. }
  701. if (freetextArgs != null)
  702. {
  703. selectedArgs = new List<AnnotHandlerEventArgs>();
  704. selectedArgs.Add(freetextArgs);
  705. SelectTextCreateAnnot(freetextArgs);
  706. }
  707. }
  708. else
  709. {
  710. FreeTextAnnotArgs freeText = selectedArgs[0] as FreeTextAnnotArgs;
  711. freetextArgs = SetFreetextArgs(freeText);
  712. textAlignment = freetextArgs.Align;
  713. if (NavigatedToFillAndSignVM(selectedArgs, "Freetext"))
  714. {
  715. return freetextArgs;
  716. }
  717. }
  718. AddToPropertyPanel("FreetextAnnotProperty", "Freetext", selectedArgs);
  719. return freetextArgs;
  720. }
  721. private FreeTextAnnotArgs SetFreetextArgs(FreeTextAnnotArgs defaultAnnot)
  722. {
  723. FreeTextAnnotArgs freetextArgs = new FreeTextAnnotArgs();
  724. freetextArgs.FontColor = defaultAnnot.FontColor;
  725. freetextArgs.LineColor = defaultAnnot.LineColor;
  726. freetextArgs.BgColor = defaultAnnot.BgColor;
  727. freetextArgs.Transparency = defaultAnnot.Transparency;
  728. freetextArgs.FontFamily = defaultAnnot.FontFamily;
  729. freetextArgs.FontSize = defaultAnnot.FontSize;
  730. freetextArgs.FontWeight = defaultAnnot.FontWeight;
  731. freetextArgs.FontStyle = defaultAnnot.FontStyle;
  732. freetextArgs.LineWidth = defaultAnnot.LineWidth;
  733. freetextArgs.Align = defaultAnnot.Align;
  734. return freetextArgs;
  735. }
  736. private void SelectTextCreateAnnot(FreeTextAnnotArgs freeText)
  737. {
  738. List<TextSelectNode> selectList = PDFViewer.GetSelectTextInfo();
  739. if (selectList != null && selectList.Count > 0)
  740. {
  741. foreach (TextSelectNode selectNode in selectList)
  742. {
  743. FreeTextAnnotArgs textArgs = new FreeTextAnnotArgs();
  744. Rect clientRect = Rect.Empty;
  745. foreach (Rect rawRect in selectNode.RawRect)
  746. {
  747. clientRect.Union(rawRect);
  748. }
  749. if (clientRect.IsEmpty == false)
  750. {
  751. clientRect = new Rect(
  752. clientRect.Left / 72D * 96D,
  753. clientRect.Top / 72D * 96D,
  754. clientRect.Width / 72D * 96D,
  755. clientRect.Height / 72D * 96D);
  756. textArgs.ClientRect = DpiHelpers.GetDpiRelatedRect(clientRect);
  757. //textArgs.Transparency = 1;
  758. //textArgs.BgColor = Colors.Transparent;
  759. //textArgs.LineColor = Colors.Red;
  760. //textArgs.LineWidth = 2;
  761. textArgs.Transparency = freeText.Transparency;
  762. textArgs.BgColor = freeText.BgColor;
  763. textArgs.LineColor = freeText.LineColor;
  764. textArgs.LineWidth = freeText.LineWidth;
  765. textArgs.TextContent = selectNode.SelectText;
  766. PDFViewer.CreatePageAnnot(selectNode.PageIndex, textArgs);
  767. }
  768. break;
  769. }
  770. }
  771. }
  772. //获取选中文字内容的区域大小,以及内容内容所在的页码
  773. private Tuple<int, Rect> DrawRectCreateAnnot()
  774. {
  775. List<TextSelectNode> selectList = PDFViewer.GetSelectTextInfo();
  776. Rect clientRect = Rect.Empty;
  777. int pageIndex = -1;
  778. if (selectList != null && selectList.Count > 0)
  779. {
  780. pageIndex = selectList[0].PageIndex;
  781. }
  782. if (selectList != null && selectList.Count > 0)
  783. {
  784. foreach (TextSelectNode selectNode in selectList)
  785. {
  786. foreach (Rect rawRect in selectNode.RawRect)
  787. {
  788. clientRect.Union(rawRect);
  789. }
  790. int dpi = DpiHelpers.Dpi;
  791. if (clientRect.IsEmpty == false)
  792. {
  793. clientRect = new Rect(
  794. clientRect.Left / 72D * dpi,
  795. clientRect.Top / 72D * dpi,
  796. clientRect.Width / 72D * dpi,
  797. clientRect.Height / 72D * dpi);
  798. }
  799. break;
  800. }
  801. }
  802. if (clientRect != Rect.Empty && pageIndex > -1)
  803. {
  804. return new Tuple<int, Rect>(pageIndex, clientRect);
  805. }
  806. return null;
  807. }
  808. /// <summary>
  809. /// 根据选中的文本内容,来创建指定大小的注释。
  810. /// </summary>
  811. /// <param name="annotArgs"></param>
  812. private AnnotHandlerEventArgs CreateAnnotFromSelectPageText(AnnotHandlerEventArgs annotArgs)
  813. {
  814. AnnotHandlerEventArgs annotHandler = null;
  815. //点击注释工具,在阅读页根据选中的文本内容,创建注释矩形大小
  816. var drawRectTuple = DrawRectCreateAnnot();
  817. if (drawRectTuple != null)
  818. {
  819. if (annotArgs is LinkAnnotArgs linkAnnot)
  820. {
  821. linkAnnot.ClientRect = drawRectTuple.Item2;
  822. linkAnnot.URI = string.Empty;
  823. linkAnnot.LinkType = LINK_TYPE.GOTO;
  824. linkAnnot.DestIndex = drawRectTuple.Item1;
  825. PDFViewer.CreatePageAnnot(drawRectTuple.Item1, linkAnnot);
  826. annotHandler = linkAnnot;
  827. }
  828. if (annotArgs is SquareAnnotArgs squareAnnot)
  829. {
  830. PropertyPanel.IsSelectedTextAddShape = true;
  831. squareAnnot.ClientRect = drawRectTuple.Item2;
  832. PDFViewer.CreatePageAnnot(drawRectTuple.Item1, squareAnnot);
  833. annotHandler = squareAnnot;
  834. }
  835. if (annotArgs is CircleAnnotArgs circleAnnot)
  836. {
  837. PropertyPanel.IsSelectedTextAddShape = true;
  838. circleAnnot.ClientRect = drawRectTuple.Item2;
  839. PDFViewer.CreatePageAnnot(drawRectTuple.Item1, circleAnnot);
  840. annotHandler = circleAnnot;
  841. }
  842. if (annotArgs is LineAnnotArgs lineAnnot)
  843. {
  844. PropertyPanel.IsSelectedTextAddShape = true;
  845. lineAnnot.ClientRect = drawRectTuple.Item2;
  846. PDFViewer.CreatePageAnnot(drawRectTuple.Item1, lineAnnot);
  847. annotHandler = lineAnnot;
  848. }
  849. }
  850. return annotHandler;
  851. }
  852. //Event导航到填写与签名的属性面板
  853. private bool NavigatedToFillAndSignVM(List<AnnotHandlerEventArgs> annots, string tag)
  854. {
  855. if (viewContentViewModel.FillAndSign != null && viewContentViewModel.FillAndSign.Count > 0 && annots != null && annots.Count > 0)
  856. {
  857. var annotFillAndSign = viewContentViewModel.FillAndSign.FirstOrDefault(temp => temp.PageIndex == annots[0].PageIndex && temp.AnnotIndex == annots[0].AnnotIndex);
  858. if (annotFillAndSign != null)
  859. {
  860. this.events.GetEvent<FillAndSignEvent>().Publish(new FillAndSigntEventArgs { Action = tag, AppUnicode = App.mainWindowViewModel.SelectedItem.Unicode, Annots = annots });
  861. return true;
  862. }
  863. }
  864. return false;
  865. }
  866. private void FromFillAndSign(FillAndSigntEventArgs obj)
  867. {
  868. if (obj != null)
  869. {
  870. if (string.IsNullOrEmpty(obj.Action) == false)
  871. {
  872. if (obj.Action == "Clear")
  873. {
  874. viewContentViewModel.AnnotSignatures.Clear();
  875. }
  876. }
  877. }
  878. }
  879. /// <summary>
  880. /// 便签
  881. /// </summary>
  882. /// <param name="selectedArgs"></param>
  883. /// <returns></returns>
  884. private AnnotHandlerEventArgs GetStickyNote(List<AnnotHandlerEventArgs> selectedArgs = null)
  885. {
  886. StickyAnnotArgs stickyAnnotArgs = new StickyAnnotArgs();
  887. if (selectedArgs == null || selectedArgs.Count == 0)
  888. {
  889. var annotate = Settings.Default.AppProperties.Annotate;
  890. if (annotate != null)
  891. {
  892. stickyAnnotArgs.Color = annotate.NoteAnnoteColor;
  893. }
  894. else
  895. {
  896. stickyAnnotArgs.Color = Color.FromRgb(0xFF, 0x81, 0x33);
  897. }
  898. if (PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotSticky] == null)
  899. {
  900. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(stickyAnnotArgs.EventType);
  901. if (defaultAnnot == null)
  902. {
  903. defaultAnnot = new DefaultAnnotProperty();
  904. defaultAnnot.AnnotToolType = stickyAnnotArgs.EventType;
  905. defaultAnnot.NoteText = string.Empty;
  906. defaultAnnot.Opacity = 1;
  907. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  908. Settings.Default.Save();
  909. }
  910. stickyAnnotArgs.Transparency = defaultAnnot.Opacity;
  911. //希望defaultAnnot里面可以缓存这个名字 2023/4/4
  912. stickyAnnotArgs.IconName = "Comment";
  913. }
  914. else
  915. {
  916. stickyAnnotArgs = PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotSticky] as StickyAnnotArgs;
  917. stickyAnnotArgs.Content = string.Empty;
  918. stickyAnnotArgs.StickyNote = string.Empty;
  919. //希望defaultAnnot里面可以缓存这个名字 2023/4/4
  920. stickyAnnotArgs.IconName = "Comment";
  921. }
  922. if (stickyAnnotArgs != null)
  923. {
  924. selectedArgs = new List<AnnotHandlerEventArgs>();
  925. selectedArgs.Add(stickyAnnotArgs);
  926. }
  927. }
  928. else
  929. {
  930. stickyAnnotArgs = selectedArgs[0] as StickyAnnotArgs;
  931. }
  932. List<AnnotHandlerEventArgs> stickyAnnotArgsList = new List<AnnotHandlerEventArgs>();
  933. if (stickyAnnotArgs != null)
  934. stickyAnnotArgsList.Add(stickyAnnotArgs);
  935. AddToPropertyPanel("StickyNoteProperty", "StickyNote", selectedArgs);
  936. return stickyAnnotArgs;
  937. }
  938. /// <summary>
  939. /// 矩形
  940. /// </summary>
  941. /// <param name="selectedArgs"></param>
  942. /// <returns></returns>
  943. public AnnotHandlerEventArgs GetRect(List<AnnotHandlerEventArgs> selectedArgs = null)
  944. {
  945. SquareAnnotArgs squareArgs = null;
  946. if (selectedArgs == null || selectedArgs.Count == 0)
  947. {
  948. squareArgs = new SquareAnnotArgs();
  949. var annotate = Settings.Default.AppProperties.Annotate;
  950. if (annotate != null)
  951. {
  952. squareArgs.BgColor = annotate.RectangleFillColor;
  953. squareArgs.LineColor = annotate.RectangleBorderColor;
  954. }
  955. else
  956. {
  957. squareArgs.LineColor = Colors.Red;
  958. squareArgs.BgColor = Colors.Red;
  959. }
  960. if (PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotSquare] == null)
  961. {
  962. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(squareArgs.EventType);
  963. if (defaultAnnot == null)
  964. {
  965. defaultAnnot = new DefaultAnnotProperty();
  966. defaultAnnot.AnnotToolType = squareArgs.EventType;
  967. defaultAnnot.Thickness = 1;
  968. defaultAnnot.Opacity = 1;
  969. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  970. Settings.Default.Save();
  971. }
  972. squareArgs.LineWidth = defaultAnnot.Thickness;
  973. squareArgs.Transparency = defaultAnnot.Opacity;
  974. if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
  975. {
  976. squareArgs.LineDash = DashStyles.Solid;
  977. }
  978. else
  979. {
  980. var collect = new DoubleCollection();
  981. foreach (var item in defaultAnnot.DashArray)
  982. {
  983. collect.Add(item);
  984. }
  985. if (squareArgs.LineDash == null)
  986. squareArgs.LineDash = new DashStyle();
  987. squareArgs.LineDash.Dashes = collect;
  988. }
  989. }
  990. else
  991. {
  992. SquareAnnotArgs squareAnnot = PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotSquare] as SquareAnnotArgs;
  993. squareArgs.BgColor = squareAnnot.BgColor;
  994. squareArgs.LineColor = squareAnnot.LineColor;
  995. squareArgs.LineWidth = squareAnnot.LineWidth;
  996. squareArgs.Transparency = squareAnnot.Transparency;
  997. squareArgs.LineDash = squareAnnot.LineDash;
  998. squareArgs.ClientRect = Rect.Empty;
  999. }
  1000. if (squareArgs != null)
  1001. {
  1002. selectedArgs = new List<AnnotHandlerEventArgs>();
  1003. selectedArgs.Add(squareArgs);
  1004. if (StrAnnotToolChecked == "Rect")
  1005. {
  1006. AnnotHandlerEventArgs annotHandler = CreateAnnotFromSelectPageText(squareArgs);
  1007. if (annotHandler is SquareAnnotArgs annotArgs)
  1008. {
  1009. selectedArgs.Clear();
  1010. selectedArgs.Add(annotArgs);
  1011. }
  1012. }
  1013. }
  1014. }
  1015. else
  1016. {
  1017. squareArgs = selectedArgs[0] as SquareAnnotArgs;
  1018. }
  1019. AddToPropertyPanel("SharpsAnnotProperty", "Rect", selectedArgs);
  1020. return squareArgs;
  1021. }
  1022. /// <summary>
  1023. /// 圆
  1024. /// </summary>
  1025. /// <param name="selectedArgs"></param>
  1026. /// <returns></returns>
  1027. public AnnotHandlerEventArgs GetCircle(List<AnnotHandlerEventArgs> selectedArgs = null)
  1028. {
  1029. CircleAnnotArgs circleAnnotArgs = null;
  1030. if (selectedArgs == null || selectedArgs.Count == 0)
  1031. {
  1032. circleAnnotArgs = new CircleAnnotArgs();
  1033. var annotate = Settings.Default.AppProperties.Annotate;
  1034. if (annotate != null)
  1035. {
  1036. circleAnnotArgs.LineColor = annotate.CircleBorderColor;
  1037. circleAnnotArgs.BgColor = annotate.CircleFillColor;
  1038. }
  1039. else
  1040. {
  1041. circleAnnotArgs.LineColor = Colors.Red;
  1042. circleAnnotArgs.BgColor = Colors.Red;
  1043. }
  1044. if (PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotCircle] == null)
  1045. {
  1046. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(circleAnnotArgs.EventType);
  1047. if (defaultAnnot == null)
  1048. {
  1049. defaultAnnot = new DefaultAnnotProperty();
  1050. defaultAnnot.AnnotToolType = circleAnnotArgs.EventType;
  1051. defaultAnnot.Thickness = 1;
  1052. defaultAnnot.Opacity = 1;
  1053. defaultAnnot.NoteText = string.Empty;
  1054. defaultAnnot.DashArray = null;
  1055. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  1056. Settings.Default.Save();
  1057. }
  1058. circleAnnotArgs.LineWidth = defaultAnnot.Thickness;
  1059. circleAnnotArgs.Transparency = defaultAnnot.Opacity;
  1060. if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
  1061. {
  1062. circleAnnotArgs.LineDash = DashStyles.Solid;
  1063. }
  1064. else
  1065. {
  1066. var collect = new DoubleCollection();
  1067. foreach (var item in defaultAnnot.DashArray)
  1068. {
  1069. collect.Add(item);
  1070. }
  1071. if (circleAnnotArgs.LineDash == null)
  1072. circleAnnotArgs.LineDash = new DashStyle();
  1073. circleAnnotArgs.LineDash.Dashes = collect;
  1074. }
  1075. }
  1076. else
  1077. {
  1078. CircleAnnotArgs circleAnnot = PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotCircle] as CircleAnnotArgs;
  1079. circleAnnotArgs.LineColor = circleAnnot.LineColor;
  1080. circleAnnotArgs.BgColor = circleAnnot.BgColor;
  1081. circleAnnotArgs.LineWidth = circleAnnot.LineWidth;
  1082. circleAnnotArgs.Transparency = circleAnnot.Transparency;
  1083. circleAnnotArgs.LineDash = circleAnnot.LineDash;
  1084. circleAnnotArgs.ClientRect = Rect.Empty;
  1085. }
  1086. if (circleAnnotArgs != null)
  1087. {
  1088. selectedArgs = new List<AnnotHandlerEventArgs>();
  1089. selectedArgs.Add(circleAnnotArgs);
  1090. if (StrAnnotToolChecked == "Rect")
  1091. {
  1092. AnnotHandlerEventArgs annotHandler = CreateAnnotFromSelectPageText(circleAnnotArgs);
  1093. if (annotHandler is CircleAnnotArgs annotArgs)
  1094. {
  1095. selectedArgs.Clear();
  1096. selectedArgs.Add(annotArgs);
  1097. }
  1098. }
  1099. }
  1100. }
  1101. else
  1102. {
  1103. circleAnnotArgs = selectedArgs[0] as CircleAnnotArgs;
  1104. }
  1105. AddToPropertyPanel("SharpsAnnotProperty", "Circle", selectedArgs);
  1106. return circleAnnotArgs;
  1107. }
  1108. /// <summary>
  1109. /// 箭头 线
  1110. /// </summary>
  1111. /// <param name="TagStr"></param>
  1112. /// <param name="selectedArgs"></param>
  1113. /// <returns></returns>
  1114. public AnnotHandlerEventArgs GetArrowLine(string TagStr, List<AnnotHandlerEventArgs> selectedArgs = null)
  1115. {
  1116. LineAnnotArgs lineArgs = new LineAnnotArgs();
  1117. if (selectedArgs == null || selectedArgs.Count == 0)
  1118. {
  1119. //var annotate = Settings.Default.AppProperties.Annotate;
  1120. //if (annotate != null)
  1121. //{
  1122. // lineArgs.LineColor = annotate.LineColor;
  1123. //}
  1124. //else
  1125. //{
  1126. // lineArgs.LineColor = Colors.Red;
  1127. //}
  1128. //lineArgs.LineColor = Colors.Red;
  1129. lineArgs.HeadLineType = C_LINE_TYPE.LINETYPE_NONE;
  1130. bool isLastAnnot = false;
  1131. if (TagStr == "Line")
  1132. {
  1133. lineArgs.LineColor = (LineColor as SolidColorBrush).Color;
  1134. lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_NONE;
  1135. isLastAnnot = (PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotLine] != null ? true : false);
  1136. }
  1137. else
  1138. {
  1139. lineArgs.LineColor = (ArrowColor as SolidColorBrush).Color;
  1140. lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_ARROW;
  1141. isLastAnnot = (PropertyPanel.LastArrowAnnot != null ? true : false);
  1142. }
  1143. if (isLastAnnot == false)
  1144. {
  1145. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(lineArgs.EventType);
  1146. if (defaultAnnot == null)
  1147. {
  1148. defaultAnnot = new DefaultAnnotProperty();
  1149. defaultAnnot.AnnotToolType = lineArgs.EventType;
  1150. defaultAnnot.Thickness = 1;
  1151. defaultAnnot.Opacity = 1;
  1152. defaultAnnot.NoteText = string.Empty;
  1153. defaultAnnot.DashArray = null;
  1154. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  1155. Settings.Default.Save();
  1156. }
  1157. lineArgs.LineDash = DashStyles.Solid;
  1158. lineArgs.LineWidth = defaultAnnot.Thickness;
  1159. lineArgs.Transparency = defaultAnnot.Opacity;
  1160. if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
  1161. {
  1162. lineArgs.LineDash = DashStyles.Solid;
  1163. }
  1164. else
  1165. {
  1166. var collect = new DoubleCollection();
  1167. foreach (var item in defaultAnnot.DashArray)
  1168. {
  1169. collect.Add(item);
  1170. }
  1171. if (lineArgs.LineDash == null)
  1172. lineArgs.LineDash = new DashStyle();
  1173. lineArgs.LineDash.Dashes = collect;
  1174. }
  1175. }
  1176. else
  1177. {
  1178. LineAnnotArgs lineAnnot = null;
  1179. if (lineArgs.TailLineType == C_LINE_TYPE.LINETYPE_ARROW)
  1180. {
  1181. lineAnnot = PropertyPanel.LastArrowAnnot as LineAnnotArgs;
  1182. }
  1183. else
  1184. {
  1185. lineAnnot = PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotLine] as LineAnnotArgs;
  1186. }
  1187. lineArgs.LineColor = lineAnnot.LineColor;
  1188. lineArgs.HeadLineType = lineAnnot.HeadLineType;
  1189. lineArgs.TailLineType = lineAnnot.TailLineType;
  1190. lineArgs.LineWidth = lineAnnot.LineWidth;
  1191. lineArgs.Transparency = lineAnnot.Transparency;
  1192. lineArgs.LineDash = lineAnnot.LineDash;
  1193. }
  1194. if (lineArgs != null)
  1195. {
  1196. selectedArgs = new List<AnnotHandlerEventArgs>();
  1197. selectedArgs.Add(lineArgs);
  1198. }
  1199. }
  1200. else
  1201. {
  1202. lineArgs = selectedArgs[0] as LineAnnotArgs;
  1203. }
  1204. AddToPropertyPanel("SharpsAnnotProperty", TagStr, selectedArgs);
  1205. return lineArgs;
  1206. }
  1207. /// <summary>
  1208. /// 图章
  1209. /// </summary>
  1210. /// <returns></returns>
  1211. private AnnotHandlerEventArgs GetStamp()
  1212. {
  1213. StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  1214. stampAnnotArgs.Opacity = 1;
  1215. stampAnnotArgs.StampText = "APPROVED";
  1216. stampAnnotArgs.Type = StampType.STANDARD_STAMP;
  1217. List<AnnotHandlerEventArgs> stampAnnotArgsList = new List<AnnotHandlerEventArgs>();
  1218. if (stampAnnotArgs != null)
  1219. stampAnnotArgsList.Add(stampAnnotArgs);
  1220. if (string.IsNullOrEmpty(StrAnnotToolChecked))
  1221. {
  1222. if (IsNoSelectMenu)
  1223. {
  1224. AddToPropertyPanel("StampAnnotProperty", null, stampAnnotArgsList);
  1225. return stampAnnotArgs;
  1226. }
  1227. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1228. return stampAnnotArgs;
  1229. }
  1230. //已选中注释工具的前提下,选中页面已经添加的图章注释时,右侧属性面板显示空状态(不自动收起)
  1231. if (StrAnnotToolChecked != "Stamp" && string.IsNullOrEmpty(StrAnnotToolChecked) == false)
  1232. {
  1233. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1234. ShowPropertyPanel(true);
  1235. return stampAnnotArgs;
  1236. }
  1237. AddToPropertyPanel("StampAnnotProperty", null, stampAnnotArgsList);
  1238. return stampAnnotArgs;
  1239. }
  1240. /// <summary>
  1241. /// 签名
  1242. /// </summary>
  1243. /// <returns></returns>
  1244. private AnnotHandlerEventArgs GetSignature()
  1245. {
  1246. AddToPropertyPanel("SignatureAnnotProperty");
  1247. return null;
  1248. }
  1249. private AnnotHandlerEventArgs GetImage()
  1250. {
  1251. StampAnnotArgs stampArgs = new StampAnnotArgs();
  1252. stampArgs.Opacity = 1;
  1253. stampArgs.Type = StampType.IMAGE_STAMP;
  1254. OpenFileDialog openFileDialog = new OpenFileDialog();
  1255. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  1256. if (openFileDialog.ShowDialog() == true)
  1257. {
  1258. stampArgs.ImagePath = openFileDialog.FileName;
  1259. }
  1260. List<AnnotHandlerEventArgs> stampArgsList = new List<AnnotHandlerEventArgs>();
  1261. if (stampArgs != null)
  1262. stampArgsList.Add(stampArgs);
  1263. AddToPropertyPanel("ImageAnnotProperty", null, stampArgsList);
  1264. return stampArgs;
  1265. }
  1266. /// <summary>
  1267. /// 内容选择
  1268. /// </summary>
  1269. /// <param name="annotBtn"></param>
  1270. /// <returns></returns>
  1271. private AnnotHandlerEventArgs GetSnapshotEdit()
  1272. {
  1273. SnapshotEditToolArgs snapshotArgs = new SnapshotEditToolArgs();
  1274. //SnapshotEditMenuViewModel snapshotEditMenuViewModel = new SnapshotEditMenuViewModel();
  1275. snapshotArgs.ControlPointColor = Colors.White;
  1276. snapshotArgs.BgColor = Color.FromArgb(0x99, 0x00, 0x00, 0x00);
  1277. snapshotArgs.LineColor = Color.FromArgb(0xFF, 0x47, 0x7E, 0xDE);
  1278. SnapshotEditMenuViewModel.SnapToolArgs = snapshotArgs;
  1279. SnapshotEditMenuViewModel.PDFViewer = PDFViewer;
  1280. SnapshotEditMenuViewModel.SnapToolEvent -= SnapshotEditMenuViewModel_SnapToolEvent;
  1281. SnapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  1282. #region to do
  1283. //SnapshotEditMenu snapMenu = new SnapshotEditMenu();
  1284. //snapshotArgs.ToolPanel = snapMenu;
  1285. //SnapshotEditMenuViewModel snapshotEditMenuViewModel = (SnapshotEditMenuViewModel)snapMenu.DataContext;
  1286. //snapshotEditMenuViewModel.SnapToolArgs = snapshotArgs;
  1287. //snapshotEditMenuViewModel.PDFViewer = PDFViewer;
  1288. //snapshotEditMenuViewModel.ToggleBtn = annotBtn;
  1289. //snapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  1290. //SnapshotEditMenuViewModel = snapshotEditMenuViewModel;
  1291. #endregion to do
  1292. StrAnnotToolChecked = "";
  1293. return snapshotArgs;
  1294. }
  1295. #endregion 注释工具
  1296. #region 菜单
  1297. private bool InBookModeSetIsHidden(object obj)
  1298. {
  1299. bool flag = false;
  1300. if (obj is MenuItem menuItem)
  1301. {
  1302. if (viewContentViewModel.mainViewModel.IsBookMode)
  1303. {
  1304. menuItem.Visibility = Visibility.Collapsed;
  1305. return true;
  1306. }
  1307. else
  1308. {
  1309. menuItem.Visibility = Visibility.Visible;
  1310. return false;
  1311. }
  1312. }
  1313. if (obj is Separator separator)
  1314. {
  1315. if (viewContentViewModel.mainViewModel.IsBookMode)
  1316. {
  1317. separator.Visibility = Visibility.Collapsed;
  1318. return true;
  1319. }
  1320. else
  1321. {
  1322. separator.Visibility = Visibility.Visible;
  1323. return false;
  1324. }
  1325. }
  1326. return flag;
  1327. }
  1328. private void ExportPicture_MenuItemClick()
  1329. {
  1330. //图片提取
  1331. try
  1332. {
  1333. List<System.Drawing.Bitmap> imageList = new List<System.Drawing.Bitmap>();
  1334. Dictionary<int, List<System.Drawing.Bitmap>> imageDict = PDFViewer?.GetSelectedImages();
  1335. foreach (int pageIndex in imageDict.Keys)
  1336. {
  1337. imageList = imageDict[pageIndex];
  1338. }
  1339. string path = PDFViewer.Document.FileName;
  1340. System.Windows.Forms.FolderBrowserDialog folderDialog = new FolderBrowserDialog();
  1341. if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  1342. {
  1343. int i = 1;
  1344. int pagenum = 1;
  1345. string choosePath = folderDialog.SelectedPath;
  1346. string sPath = choosePath + "\\" + path + "_Extract Image";
  1347. sPath = GetExportPathName(sPath);
  1348. if (!Directory.Exists(sPath))
  1349. {
  1350. Directory.CreateDirectory(sPath);
  1351. }
  1352. if (Directory.Exists(sPath))
  1353. {
  1354. foreach (System.Drawing.Bitmap image in imageList)
  1355. {
  1356. foreach (var item in imageDict.Keys)
  1357. {
  1358. pagenum = item;
  1359. }
  1360. string filename = path + "_" + "Page" + (pagenum + 1).ToString() + "_" + GetNum(i);
  1361. string savePath = System.IO.Path.Combine(sPath, filename + ".jpg");
  1362. image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  1363. i++;
  1364. }
  1365. System.Diagnostics.Process.Start("explorer", "/select,\"" + sPath + "\"");
  1366. }
  1367. }
  1368. }
  1369. catch (Exception ex) { }
  1370. }
  1371. public string GetExportPathName(string path)
  1372. {
  1373. int i = 1;
  1374. string outpath = path;
  1375. while (Directory.Exists(outpath))
  1376. {
  1377. outpath = path + $"({i.ToString()})";
  1378. i++;
  1379. }
  1380. return outpath;
  1381. }
  1382. private string GetNum(int num)
  1383. {
  1384. if (num % 10 < 1)
  1385. {
  1386. return "00" + num.ToString();
  1387. }
  1388. if (num % 10 >= 1 && num % 10 < 10)
  1389. {
  1390. return "0" + num.ToString();
  1391. }
  1392. else
  1393. {
  1394. return num.ToString();
  1395. }
  1396. }
  1397. #endregion 菜单
  1398. }
  1399. }