AnnotToolContentViewModel.Function.cs 55 KB

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