CPDFAnnotationControl.xaml.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. using compdfkit_tools.Data;
  2. using compdfkit_tools.PDFControl;
  3. using compdfkit_tools.PDFControlUI;
  4. using ComPDFKitViewer.AnnotEvent;
  5. using ComPDFKitViewer;
  6. using ComPDFKitViewer.PdfViewer;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows;
  13. using System.Windows.Controls;
  14. using System.Windows.Data;
  15. using System.Windows.Documents;
  16. using System.Windows.Input;
  17. using System.Windows.Media;
  18. using System.Windows.Media.Imaging;
  19. using System.Windows.Navigation;
  20. using System.Windows.Shapes;
  21. using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
  22. using compdfkit_tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI;
  23. using System.IO;
  24. using System.Windows.Ink;
  25. using compdfkit_tools.Annotation.PDFAnnotationUI;
  26. using Microsoft.Win32;
  27. namespace compdfkit_tools.PDFControl
  28. {
  29. /// <summary>
  30. /// CPDFAnnotationControl.xaml 的交互逻辑
  31. /// </summary>
  32. public partial class CPDFAnnotationControl : UserControl
  33. {
  34. private CPDFViewer pdfViewer;
  35. private UIElement annotationPanel = null;
  36. private UIElement tempAnnotationPanel = null;
  37. private bool isTempPanel = false;
  38. private CPDFAnnotationType currentAnnotationType = CPDFAnnotationType.Unknow;
  39. private CPDFMarkupUI pdfHighlightUI;
  40. private CPDFMarkupUI pdfUnderlineUI;
  41. private CPDFMarkupUI pdfSquigglyUI;
  42. private CPDFMarkupUI pdfStrikeoutUI;
  43. private CPDFShapeUI pdfSquareUI;
  44. private CPDFShapeUI pdfCircleUI;
  45. private CPDFShapeUI pdfLineUI;
  46. private CPDFShapeUI pdfArrowUI;
  47. private CPDFFreehandUI pdfFreehandUI;
  48. private CPDFFreeTextUI pdfFreeTextUI;
  49. private CPDFNoteUI pdfNoteUI;
  50. private CPDFStampUI pdfStampUI;
  51. private CPDFSignatureUI pdfSignatureUI;
  52. private CPDFLinkUI pdfLinkUI;
  53. public CPDFAnnotationControl()
  54. {
  55. InitializeComponent();
  56. }
  57. public void SetPDFViewer(CPDFViewer pdfViewer)
  58. {
  59. if (this.pdfViewer!=null)
  60. {
  61. UnLoadPDFViewHandler();
  62. }
  63. this.pdfViewer = pdfViewer;
  64. LoadPDFViewHandler();
  65. }
  66. private void LoadPDFViewHandler()
  67. {
  68. if (this.pdfViewer!=null)
  69. {
  70. this.pdfViewer.AnnotActiveHandler += PDFViewer_AnnotActiveHandler;
  71. }
  72. }
  73. private void UnLoadPDFViewHandler()
  74. {
  75. if (this.pdfViewer != null)
  76. {
  77. this.pdfViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
  78. }
  79. }
  80. private void AnnotationControl_Loaded(object sender, RoutedEventArgs e)
  81. {
  82. LoadPDFViewHandler();
  83. }
  84. private void AnnotationControl_Unloaded(object sender, RoutedEventArgs e)
  85. {
  86. UnLoadPDFViewHandler();
  87. }
  88. /// <summary>
  89. /// 获取Annotation面板
  90. /// </summary>
  91. /// <returns></returns>
  92. private UIElement GetAnnotationPanel()
  93. {
  94. return AnnotationPanelContainer.Child;
  95. }
  96. private void SetAnnotationPanel(UIElement newChild)
  97. {
  98. AnnotationPanelContainer.Child = newChild;
  99. }
  100. /// <summary>
  101. /// 展开Annotation面板
  102. /// </summary>
  103. /// <param name="isExpand"></param>
  104. private void ExpandPanel()
  105. {
  106. AnnotationPanelContainer.Visibility = Visibility.Visible;
  107. }
  108. private void ChangeAnnotationData()
  109. {
  110. switch (currentAnnotationType)
  111. {
  112. case CPDFAnnotationType.Highlight:
  113. case CPDFAnnotationType.Underline:
  114. case CPDFAnnotationType.Squiggly:
  115. case CPDFAnnotationType.Strikeout:
  116. (annotationPanel as CPDFMarkupUI).PropertyChanged += CPDFAnnotationControl_PropertyChanged;
  117. SetAnnotationProperty((annotationPanel as CPDFMarkupUI).GetMarkupData());
  118. break;
  119. case CPDFAnnotationType.Square:
  120. case CPDFAnnotationType.Circle:
  121. case CPDFAnnotationType.Line:
  122. case CPDFAnnotationType.Arrow:
  123. (annotationPanel as CPDFShapeUI).PropertyChanged += CPDFAnnotationControl_PropertyChanged;
  124. SetAnnotationProperty((annotationPanel as CPDFShapeUI).GetShapeData());
  125. break;
  126. case CPDFAnnotationType.Note:
  127. (annotationPanel as CPDFNoteUI).PropertyChanged += CPDFAnnotationControl_PropertyChanged;
  128. SetAnnotationProperty((annotationPanel as CPDFNoteUI).GetNoteData());
  129. break;
  130. case CPDFAnnotationType.Freehand:
  131. (annotationPanel as CPDFFreehandUI).PropertyChanged += CPDFAnnotationControl_PropertyChanged;
  132. SetAnnotationProperty((annotationPanel as CPDFFreehandUI).GetFreehandData());
  133. break;
  134. case CPDFAnnotationType.FreeText:
  135. (annotationPanel as CPDFFreeTextUI).PropertyChanged += CPDFAnnotationControl_PropertyChanged;
  136. SetAnnotationProperty((annotationPanel as CPDFFreeTextUI).GetFreeTextData());
  137. break;
  138. case CPDFAnnotationType.Stamp:
  139. (annotationPanel as CPDFStampUI).PropertyChanged += CPDFAnnotationControl_PropertyChanged;
  140. break;
  141. case CPDFAnnotationType.Signature:
  142. (annotationPanel as CPDFSignatureUI).PropertyChanged += CPDFAnnotationControl_PropertyChanged;
  143. break;
  144. case CPDFAnnotationType.Audio:
  145. SoundAnnotArgs soundArgs = new SoundAnnotArgs();
  146. OpenFileDialog openAudioDialog = new OpenFileDialog();
  147. openAudioDialog.Filter = "Wave Files(*.wav;*.wave;)|*.wav;*.wave|All Files(*.*;)|*.*;";
  148. if (openAudioDialog.ShowDialog() == true)
  149. {
  150. soundArgs.SoundFilePath = openAudioDialog.FileName;
  151. this.pdfViewer.SetMouseMode(MouseModes.AnnotCreate);
  152. pdfViewer.SetToolParam(soundArgs);
  153. }
  154. else
  155. {
  156. this.pdfViewer.SetMouseMode(MouseModes.PanTool);
  157. }
  158. break;
  159. default:
  160. break;
  161. }
  162. }
  163. /// <summary>
  164. /// 参数解析
  165. /// </summary>
  166. /// <param name="pdfAnnotationData"></param>
  167. private void SetAnnotationProperty(CPDFAnnotationData pdfAnnotationData = null)
  168. {
  169. if (pdfAnnotationData == null)
  170. {
  171. pdfViewer.SetMouseMode(MouseModes.PanTool);
  172. return;
  173. }
  174. CPDFAnnotationType annotationType = pdfAnnotationData.AnnotationType;
  175. AnnotHandlerEventArgs annotHandlerEventArgs = null;
  176. this.pdfViewer.SetMouseMode(MouseModes.PanTool);
  177. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  178. switch (annotationType)
  179. {
  180. case CPDFAnnotationType.Highlight:
  181. CPDFMarkupData highlightData = pdfAnnotationData as CPDFMarkupData;
  182. annotHandlerEventArgs = new TextHighlightAnnotArgs();
  183. (annotHandlerEventArgs as TextHighlightAnnotArgs).Color = highlightData.Color;
  184. (annotHandlerEventArgs as TextHighlightAnnotArgs).Transparency = highlightData.Opacity;
  185. (annotHandlerEventArgs as TextHighlightAnnotArgs).Content = highlightData.Note;
  186. (annotHandlerEventArgs as TextHighlightAnnotArgs).Author = highlightData.Author;
  187. (annotHandlerEventArgs as TextHighlightAnnotArgs).Locked = highlightData.IsLocked;
  188. break;
  189. case CPDFAnnotationType.Underline:
  190. CPDFMarkupData underlineData = pdfAnnotationData as CPDFMarkupData;
  191. annotHandlerEventArgs = new TextUnderlineAnnotArgs();
  192. (annotHandlerEventArgs as TextUnderlineAnnotArgs).Color = underlineData.Color;
  193. (annotHandlerEventArgs as TextUnderlineAnnotArgs).Transparency = underlineData.Opacity;
  194. (annotHandlerEventArgs as TextUnderlineAnnotArgs).Author = underlineData.Author;
  195. (annotHandlerEventArgs as TextUnderlineAnnotArgs).Content = underlineData.Note;
  196. (annotHandlerEventArgs as TextUnderlineAnnotArgs).Locked = underlineData.IsLocked;
  197. break;
  198. case CPDFAnnotationType.Strikeout:
  199. CPDFMarkupData strikeoutData = pdfAnnotationData as CPDFMarkupData;
  200. annotHandlerEventArgs = new TextStrikeoutAnnotArgs();
  201. (annotHandlerEventArgs as TextStrikeoutAnnotArgs).Color = strikeoutData.Color;
  202. (annotHandlerEventArgs as TextStrikeoutAnnotArgs).Transparency = strikeoutData.Opacity;
  203. (annotHandlerEventArgs as TextStrikeoutAnnotArgs).Locked = strikeoutData.IsLocked;
  204. (annotHandlerEventArgs as TextStrikeoutAnnotArgs).Author = strikeoutData.Author;
  205. (annotHandlerEventArgs as TextStrikeoutAnnotArgs).Content = strikeoutData.Note;
  206. break;
  207. case CPDFAnnotationType.Squiggly:
  208. CPDFMarkupData squigglyData = pdfAnnotationData as CPDFMarkupData;
  209. annotHandlerEventArgs = new TextSquigglyAnnotArgs();
  210. (annotHandlerEventArgs as TextSquigglyAnnotArgs).Color = squigglyData.Color;
  211. (annotHandlerEventArgs as TextSquigglyAnnotArgs).Transparency = squigglyData.Opacity;
  212. (annotHandlerEventArgs as TextSquigglyAnnotArgs).Locked = squigglyData.IsLocked;
  213. (annotHandlerEventArgs as TextSquigglyAnnotArgs).Author = squigglyData.Author;
  214. (annotHandlerEventArgs as TextSquigglyAnnotArgs).Content = squigglyData.Note;
  215. break;
  216. case CPDFAnnotationType.Square:
  217. CPDFShapeData squareData = pdfAnnotationData as CPDFShapeData;
  218. annotHandlerEventArgs = new SquareAnnotArgs();
  219. (annotHandlerEventArgs as SquareAnnotArgs).LineColor = squareData.BorderColor;
  220. (annotHandlerEventArgs as SquareAnnotArgs).BgColor = squareData.FillColor;
  221. (annotHandlerEventArgs as SquareAnnotArgs).LineWidth = squareData.Thickness;
  222. (annotHandlerEventArgs as SquareAnnotArgs).Transparency = squareData.Opacity;
  223. (annotHandlerEventArgs as SquareAnnotArgs).LineDash = squareData.DashStyle;
  224. (annotHandlerEventArgs as SquareAnnotArgs).Author = squareData.Author;
  225. (annotHandlerEventArgs as SquareAnnotArgs).Content = squareData.Note;
  226. break;
  227. case CPDFAnnotationType.Circle:
  228. CPDFShapeData cicleData = pdfAnnotationData as CPDFShapeData;
  229. annotHandlerEventArgs = new CircleAnnotArgs();
  230. (annotHandlerEventArgs as CircleAnnotArgs).LineColor = cicleData.BorderColor;
  231. (annotHandlerEventArgs as CircleAnnotArgs).BgColor = cicleData.FillColor;
  232. (annotHandlerEventArgs as CircleAnnotArgs).LineWidth = cicleData.Thickness;
  233. (annotHandlerEventArgs as CircleAnnotArgs).Transparency = cicleData.Opacity;
  234. (annotHandlerEventArgs as CircleAnnotArgs).LineDash = cicleData.DashStyle;
  235. (annotHandlerEventArgs as CircleAnnotArgs).Author = cicleData.Author;
  236. (annotHandlerEventArgs as CircleAnnotArgs).Content = cicleData.Note;
  237. break;
  238. case CPDFAnnotationType.Arrow:
  239. case CPDFAnnotationType.Line:
  240. CPDFLineShapeData lineData = pdfAnnotationData as CPDFLineShapeData;
  241. annotHandlerEventArgs = new LineAnnotArgs();
  242. (annotHandlerEventArgs as LineAnnotArgs).LineColor = lineData.BorderColor;
  243. (annotHandlerEventArgs as LineAnnotArgs).LineWidth = lineData.Thickness;
  244. (annotHandlerEventArgs as LineAnnotArgs).Transparency = lineData.Opacity;
  245. (annotHandlerEventArgs as LineAnnotArgs).LineDash = lineData.DashStyle;
  246. (annotHandlerEventArgs as LineAnnotArgs).HeadLineType = lineData.LineType.HeadLineType;
  247. (annotHandlerEventArgs as LineAnnotArgs).TailLineType = lineData.LineType.TailLineType;
  248. (annotHandlerEventArgs as LineAnnotArgs).Author = lineData.Author;
  249. (annotHandlerEventArgs as LineAnnotArgs).Content = lineData.Note;
  250. break;
  251. case CPDFAnnotationType.Note:
  252. CPDFNoteData noteData = pdfAnnotationData as CPDFNoteData;
  253. annotHandlerEventArgs = new StickyAnnotArgs();
  254. (annotHandlerEventArgs as StickyAnnotArgs).Color = noteData.BorderColor;
  255. (annotHandlerEventArgs as StickyAnnotArgs).StickyNote = noteData.Note;
  256. (annotHandlerEventArgs as StickyAnnotArgs).Transparency = 1;
  257. (annotHandlerEventArgs as StickyAnnotArgs).Author = noteData.Author;
  258. break;
  259. case CPDFAnnotationType.Freehand:
  260. CPDFFreehandData freehandData = pdfAnnotationData as CPDFFreehandData;
  261. annotHandlerEventArgs = new FreehandAnnotArgs();
  262. (annotHandlerEventArgs as FreehandAnnotArgs).InkColor = freehandData.BorderColor;
  263. (annotHandlerEventArgs as FreehandAnnotArgs).LineWidth = freehandData.Thickness;
  264. (annotHandlerEventArgs as FreehandAnnotArgs).Transparency = freehandData.Opacity;
  265. (annotHandlerEventArgs as FreehandAnnotArgs).Content = freehandData.Note;
  266. (annotHandlerEventArgs as FreehandAnnotArgs).Author = freehandData.Author;
  267. break;
  268. case CPDFAnnotationType.FreeText:
  269. CPDFFreeTextData freeTextData = pdfAnnotationData as CPDFFreeTextData;
  270. annotHandlerEventArgs = new FreeTextAnnotArgs();
  271. (annotHandlerEventArgs as FreeTextAnnotArgs).Transparency = freeTextData.Opacity;
  272. (annotHandlerEventArgs as FreeTextAnnotArgs).FontName = freeTextData.FontFamily.ToString();
  273. (annotHandlerEventArgs as FreeTextAnnotArgs).FontColor = freeTextData.BorderColor;
  274. (annotHandlerEventArgs as FreeTextAnnotArgs).IsBold = freeTextData.IsBold;
  275. (annotHandlerEventArgs as FreeTextAnnotArgs).IsItalic = freeTextData.IsItalic;
  276. (annotHandlerEventArgs as FreeTextAnnotArgs).FontSize = freeTextData.FontSize;
  277. (annotHandlerEventArgs as FreeTextAnnotArgs).Align = freeTextData.TextAlignment;
  278. (annotHandlerEventArgs as FreeTextAnnotArgs).Content = freeTextData.Note;
  279. (annotHandlerEventArgs as FreeTextAnnotArgs).Author = freeTextData.Author;
  280. break;
  281. case CPDFAnnotationType.Stamp:
  282. annotHandlerEventArgs = new StampAnnotArgs();
  283. StampAnnotArgs stampAnnot = annotHandlerEventArgs as StampAnnotArgs;
  284. CPDFStampData stampData = pdfAnnotationData as CPDFStampData;
  285. SetStamp(ref stampAnnot, stampData);
  286. break;
  287. case CPDFAnnotationType.Signature:
  288. annotHandlerEventArgs = new StampAnnotArgs();
  289. StampAnnotArgs SignatureAnnot = annotHandlerEventArgs as StampAnnotArgs;
  290. CPDFSignatureData SignatureData = pdfAnnotationData as CPDFSignatureData;
  291. SetSignature(ref SignatureAnnot, SignatureData);
  292. break;
  293. case CPDFAnnotationType.Link:
  294. if (annotHandlerEventArgs != null)
  295. {
  296. pdfViewer.SetToolParam(annotHandlerEventArgs);
  297. (annotHandlerEventArgs as LinkAnnotArgs).AnnotIndex = 0;
  298. (annotHandlerEventArgs as LinkAnnotArgs).InvokeLinkSaveCalled(null, null);
  299. (annotHandlerEventArgs as LinkAnnotArgs).AnnotIndex = 2;
  300. (annotHandlerEventArgs as LinkAnnotArgs).InvokeLinkSaveCalled(null, null);
  301. }
  302. break;
  303. case CPDFAnnotationType.Audio:
  304. break;
  305. case CPDFAnnotationType.Unknow:
  306. pdfViewer.SetMouseMode(MouseModes.PanTool);
  307. return;
  308. default:
  309. break;
  310. }
  311. this.pdfViewer.SetMouseMode(MouseModes.AnnotCreate);
  312. pdfViewer.SetToolParam(annotHandlerEventArgs);
  313. }
  314. public void SetSignature(ref StampAnnotArgs Args, CPDFSignatureData stamp)
  315. {
  316. switch (stamp.Type)
  317. {
  318. case SignatureType.TextType:
  319. case SignatureType.ImageType:
  320. {
  321. Args.Opacity = 1;
  322. Args.Type = StampType.IMAGE_STAMP;
  323. Args.ImagePath = stamp.SourcePath;
  324. }
  325. break;
  326. case SignatureType.Drawing:
  327. {
  328. Args.SetInkData(GetPoints(stamp.DrawingPath), stamp.inkThickness, stamp.inkColor);
  329. }
  330. break;
  331. default:
  332. break;
  333. }
  334. }
  335. private List<List<Point>> GetPoints(string Path)
  336. {
  337. StrokeCollection Strokes;
  338. List<List<Point>> RawPointList = new List<List<Point>>();
  339. using (FileStream strokeStream = File.OpenRead(Path))
  340. {
  341. Strokes = new StrokeCollection(strokeStream);
  342. }
  343. for (int kk = 0; kk < Strokes.Count; kk++)
  344. {
  345. List<Point> p = new List<Point>();
  346. RawPointList.Add(p);
  347. for (int gg = 0; gg < Strokes[kk].StylusPoints.Count; gg++)
  348. {
  349. var point = Strokes[kk].StylusPoints[gg].ToPoint();
  350. if (point.X >= 0 && point.Y >= 0)
  351. RawPointList[kk].Add(point);
  352. }
  353. }
  354. return RawPointList;
  355. }
  356. private void SetStamp(ref StampAnnotArgs Args, CPDFStampData stamp)
  357. {
  358. Args.StampText = stamp.StampText;
  359. Args.Author = stamp.Author;
  360. Args.Opacity = stamp.Opacity;
  361. if (stamp.Type == StampType.IMAGE_STAMP)
  362. {
  363. Args.ImageWidth = stamp.MaxWidth;
  364. Args.ImageHeight = stamp.MaxHeight;
  365. }
  366. else
  367. {
  368. Args.MaxWidth = stamp.MaxWidth;
  369. Args.MaxHeight = stamp.MaxHeight;
  370. }
  371. Args.StampTextDate = stamp.StampTextDate;
  372. Args.TextColor = stamp.TextColor;
  373. Args.TextSharp = stamp.TextSharp;
  374. if (!string.IsNullOrEmpty(stamp.SourcePath))
  375. {
  376. BitmapImage image = new BitmapImage(new Uri(stamp.SourcePath));
  377. Args.ImageArray = new byte[image.PixelWidth * image.PixelHeight * 4];
  378. image.CopyPixels(Args.ImageArray, image.PixelWidth * 4, 0);
  379. Args.ImageHeight = image.PixelHeight;
  380. Args.ImageWidth = image.PixelWidth;
  381. }
  382. else
  383. {
  384. Args.ImageArray = new byte[stamp.ImageSource.PixelWidth * stamp.ImageSource.PixelHeight * 4];
  385. stamp.ImageSource.CopyPixels(Args.ImageArray, stamp.ImageSource.PixelWidth * 4, 0);
  386. Args.ImageHeight = stamp.ImageSource.PixelHeight;
  387. Args.ImageWidth = stamp.ImageSource.PixelWidth;
  388. }
  389. Args.Type = stamp.Type;
  390. }
  391. public void AnnotationCancel()
  392. {
  393. this.pdfViewer.SetMouseMode(MouseModes.PanTool);
  394. }
  395. private void CPDFAnnotationControl_PropertyChanged(object sender, CPDFAnnotationData e)
  396. {
  397. SetAnnotationProperty(e);
  398. }
  399. /// <summary>
  400. /// 选择对应注释面板
  401. /// 若未创建则创建
  402. /// 已创建则使用已有项
  403. /// </summary>
  404. /// <param name="annotationType"></param>
  405. public void InitAnnotationPanel(CPDFAnnotationType annotationType)
  406. {
  407. switch (annotationType)
  408. {
  409. case CPDFAnnotationType.Highlight:
  410. if (pdfHighlightUI == null)
  411. {
  412. pdfHighlightUI = new CPDFMarkupUI();
  413. }
  414. annotationPanel = pdfHighlightUI;
  415. (annotationPanel as CPDFMarkupUI).InitWithAnnotationType(annotationType);
  416. break;
  417. case CPDFAnnotationType.Underline:
  418. if (pdfUnderlineUI == null)
  419. {
  420. pdfUnderlineUI = new CPDFMarkupUI();
  421. }
  422. annotationPanel = pdfUnderlineUI;
  423. (annotationPanel as CPDFMarkupUI).InitWithAnnotationType(annotationType);
  424. break;
  425. case CPDFAnnotationType.Strikeout:
  426. if (pdfStrikeoutUI == null)
  427. {
  428. pdfStrikeoutUI = new CPDFMarkupUI();
  429. }
  430. annotationPanel = pdfStrikeoutUI;
  431. (annotationPanel as CPDFMarkupUI).InitWithAnnotationType(annotationType);
  432. break;
  433. case CPDFAnnotationType.Squiggly:
  434. if (pdfSquigglyUI == null)
  435. {
  436. pdfSquigglyUI = new CPDFMarkupUI();
  437. }
  438. annotationPanel = pdfSquigglyUI;
  439. (annotationPanel as CPDFMarkupUI).InitWithAnnotationType(annotationType);
  440. break;
  441. case CPDFAnnotationType.Square:
  442. if (pdfSquareUI == null)
  443. {
  444. pdfSquareUI = new CPDFShapeUI();
  445. }
  446. annotationPanel = pdfSquareUI;
  447. (annotationPanel as CPDFShapeUI).InitWithAnnotationType(annotationType);
  448. break;
  449. case CPDFAnnotationType.Circle:
  450. if (pdfCircleUI == null)
  451. {
  452. pdfCircleUI = new CPDFShapeUI();
  453. }
  454. annotationPanel = pdfCircleUI;
  455. (annotationPanel as CPDFShapeUI).InitWithAnnotationType(annotationType);
  456. break;
  457. case CPDFAnnotationType.Arrow:
  458. if (pdfArrowUI == null)
  459. {
  460. pdfArrowUI = new CPDFShapeUI();
  461. }
  462. annotationPanel = pdfArrowUI;
  463. (annotationPanel as CPDFShapeUI).InitWithAnnotationType(annotationType);
  464. break;
  465. case CPDFAnnotationType.Line:
  466. if (pdfLineUI == null)
  467. {
  468. pdfLineUI = new CPDFShapeUI();
  469. }
  470. annotationPanel = pdfLineUI;
  471. (annotationPanel as CPDFShapeUI).InitWithAnnotationType(annotationType);
  472. break;
  473. case CPDFAnnotationType.Freehand:
  474. if (pdfFreehandUI == null)
  475. {
  476. pdfFreehandUI = new CPDFFreehandUI();
  477. }
  478. annotationPanel = pdfFreehandUI;
  479. break;
  480. case CPDFAnnotationType.FreeText:
  481. if (pdfFreeTextUI == null)
  482. {
  483. pdfFreeTextUI = new CPDFFreeTextUI();
  484. }
  485. annotationPanel = pdfFreeTextUI;
  486. break;
  487. case CPDFAnnotationType.Note:
  488. if (pdfNoteUI == null)
  489. {
  490. pdfNoteUI = new CPDFNoteUI();
  491. }
  492. annotationPanel = pdfNoteUI;
  493. break;
  494. case CPDFAnnotationType.Stamp:
  495. if (pdfStampUI == null)
  496. {
  497. pdfStampUI = new CPDFStampUI();
  498. }
  499. annotationPanel = pdfStampUI;
  500. break;
  501. case CPDFAnnotationType.Signature:
  502. if (pdfSignatureUI == null)
  503. {
  504. pdfSignatureUI = new CPDFSignatureUI();
  505. }
  506. annotationPanel = pdfSignatureUI;
  507. break;
  508. case CPDFAnnotationType.Link:
  509. if (pdfLinkUI==null)
  510. {
  511. pdfLinkUI = new CPDFLinkUI();
  512. }
  513. LinkAnnotArgs linkAnnotArgs = new LinkAnnotArgs();
  514. if (this.pdfViewer != null&& this.pdfViewer.Document!=null)
  515. {
  516. this.pdfViewer.SetMouseMode(MouseModes.AnnotCreate);
  517. pdfViewer.SetToolParam(linkAnnotArgs);
  518. pdfLinkUI.InitLinkAnnotArgs(linkAnnotArgs, pdfViewer.Document.PageCount);
  519. }
  520. annotationPanel = pdfLinkUI;
  521. break;
  522. default:
  523. break;
  524. }
  525. }
  526. /// <summary>
  527. /// 创建临时注释面板
  528. /// </summary>
  529. /// <param name="annotArgsType"></param>
  530. public void CreatTempAnnotationPanel(AnnotAttribEvent annotAttribEvent)
  531. {
  532. AnnotArgsType annotArgsType = annotAttribEvent.GetAnnotTypes();
  533. switch (annotArgsType)
  534. {
  535. case AnnotArgsType.AnnotHighlight:
  536. case AnnotArgsType.AnnotUnderline:
  537. case AnnotArgsType.AnnotStrikeout:
  538. case AnnotArgsType.AnnotSquiggly:
  539. tempAnnotationPanel = new CPDFMarkupUI();
  540. (tempAnnotationPanel as CPDFMarkupUI).InitWithAnnotationType(CPDFAnnotationDictionary.GetAnnotArgsTypeFromAnnotationType[annotArgsType]);
  541. (tempAnnotationPanel as CPDFMarkupUI).SetPresentAnnotAttrib(annotAttribEvent);
  542. break;
  543. case AnnotArgsType.AnnotSquare:
  544. case AnnotArgsType.AnnotCircle:
  545. case AnnotArgsType.AnnotLine:
  546. tempAnnotationPanel = new CPDFShapeUI();
  547. (tempAnnotationPanel as CPDFShapeUI).InitWithAnnotationType(CPDFAnnotationDictionary.GetAnnotArgsTypeFromAnnotationType[annotArgsType]);
  548. (tempAnnotationPanel as CPDFShapeUI).SetPresentAnnotAttrib(annotAttribEvent);
  549. break;
  550. case AnnotArgsType.AnnotFreehand:
  551. tempAnnotationPanel = new CPDFFreehandUI();
  552. (tempAnnotationPanel as CPDFFreehandUI).SetPresentAnnotAttrib(annotAttribEvent);
  553. break;
  554. case AnnotArgsType.AnnotFreeText:
  555. tempAnnotationPanel = new CPDFFreeTextUI();
  556. (tempAnnotationPanel as CPDFFreeTextUI).SetPresentAnnotAttrib(annotAttribEvent);
  557. break;
  558. case AnnotArgsType.AnnotSticky:
  559. tempAnnotationPanel = new CPDFNoteUI();
  560. (tempAnnotationPanel as CPDFNoteUI).SetPresentAnnotAttrib(annotAttribEvent);
  561. break;
  562. case AnnotArgsType.AnnotStamp:
  563. tempAnnotationPanel = new CPDFTempStampUI();
  564. (tempAnnotationPanel as CPDFTempStampUI).SetPresentAnnotAttrib(annotAttribEvent);
  565. break;
  566. case AnnotArgsType.AnnotLink:
  567. tempAnnotationPanel = new CPDFLinkUI();
  568. (tempAnnotationPanel as CPDFLinkUI).SetPresentAnnotAttrib(annotAttribEvent, pdfViewer.Document.PageCount);
  569. break;
  570. default:
  571. break;
  572. }
  573. }
  574. /// <summary>
  575. /// 根据注释类型显示注释面板
  576. /// </summary>
  577. /// <param name="annotationType"></param>
  578. public void LoadAnnotationPanel(CPDFAnnotationType annotationType)
  579. {
  580. currentAnnotationType = annotationType;
  581. annotationPanel = GetAnnotationPanel();
  582. InitAnnotationPanel(annotationType);
  583. ShowCurrentAnnotPanel();
  584. }
  585. /// <summary>
  586. /// 展示正在使用的属性面板
  587. /// </summary>
  588. private void ShowCurrentAnnotPanel()
  589. {
  590. SetAnnotationPanel(annotationPanel);
  591. ExpandPanel();
  592. ChangeAnnotationData();
  593. }
  594. /// <summary>
  595. /// 根据参数展开指定临时面板
  596. /// </summary>
  597. /// <param name="annotArgsType"></param>
  598. private void ShowTempAnnotPanel(AnnotAttribEvent annotAttribEvent)
  599. {
  600. CreatTempAnnotationPanel(annotAttribEvent);
  601. SetAnnotationPanel(tempAnnotationPanel);
  602. ExpandPanel();
  603. }
  604. private void PDFViewer_AnnotActiveHandler(object sender, AnnotAttribEvent e)
  605. {
  606. if (e != null)
  607. {
  608. if (e.IsAnnotCreateReset && isTempPanel)
  609. {
  610. ShowCurrentAnnotPanel();
  611. isTempPanel = false;
  612. }
  613. else if(!e.IsAnnotCreateReset)
  614. {
  615. AnnotArgsType annotArgsType = e.GetAnnotTypes();
  616. ShowTempAnnotPanel(e);
  617. isTempPanel = true;
  618. }
  619. }
  620. }
  621. }
  622. }