CPDFAnnotationControl.xaml.cs 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095
  1. using Compdfkit_Tools.Data;
  2. using Compdfkit_Tools.PDFControlUI;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Media.Imaging;
  8. using Compdfkit_Tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI;
  9. using System.IO;
  10. using System.Windows.Ink;
  11. using Compdfkit_Tools.Annotation.PDFAnnotationUI;
  12. using Microsoft.Win32;
  13. using System.Windows.Media;
  14. using Compdfkit_Tools.Properties;
  15. using static ComPDFKit.Tool.CPDFToolManager;
  16. using ComPDFKit.PDFAnnotation;
  17. using ComPDFKit.Tool;
  18. using ComPDFKit.Tool.Help;
  19. using ComPDFKit.Tool.SettingParam;
  20. using ComPDFKit.Import;
  21. using ComPDFKitViewer.BaseObject;
  22. using ComPDFKitViewer.Widget;
  23. using ComPDFKit.PDFDocument;
  24. using System.Text;
  25. namespace Compdfkit_Tools.PDFControl
  26. {
  27. public partial class CPDFAnnotationControl : UserControl
  28. {
  29. private bool isTempPanel = false;
  30. private CPDFAnnotationType currentAnnotationType = CPDFAnnotationType.Unknow;
  31. private PDFViewControl pdfViewerControl;
  32. private UIElement annotationPanel = null;
  33. private UIElement tempAnnotationPanel = null;
  34. private CPDFMarkupUI pdfHighlightUI;
  35. private CPDFMarkupUI pdfUnderlineUI;
  36. private CPDFMarkupUI pdfSquigglyUI;
  37. private CPDFMarkupUI pdfStrikeoutUI;
  38. private CPDFShapeUI pdfSquareUI;
  39. private CPDFShapeUI pdfCircleUI;
  40. private CPDFShapeUI pdfLineUI;
  41. private CPDFShapeUI pdfArrowUI;
  42. private CPDFFreehandUI pdfFreehandUI;
  43. private CPDFFreeTextUI pdfFreeTextUI;
  44. private CPDFNoteUI pdfNoteUI;
  45. private CPDFStampUI pdfStampUI;
  46. private CPDFSignatureUI pdfSignatureUI;
  47. private CPDFLinkUI pdfLinkUI;
  48. private bool disableClean;
  49. public event EventHandler ClearAnnotationBar;
  50. public CPDFAnnotationControl()
  51. {
  52. InitializeComponent();
  53. }
  54. public void SetPDFViewer(PDFViewControl pdfViewer)
  55. {
  56. if (this.pdfViewerControl != null)
  57. {
  58. UnLoadPDFViewHandler();
  59. }
  60. this.pdfViewerControl = pdfViewer;
  61. LoadPDFViewHandler();
  62. }
  63. public void LoadPDFViewHandler()
  64. {
  65. if (this.pdfViewerControl != null)
  66. {
  67. pdfViewerControl.PDFToolManager.MouseLeftButtonDownHandler += PDFToolManager_MouseLeftButtonDownHandler; ;
  68. //this.pdfViewerControl.AnnotActiveHandler += PDFViewer_AnnotActiveHandler;
  69. //this.pdfViewerControl.AnnotEditHandler -= PdfViewer_AnnotEditHandler;
  70. //this.pdfViewerControl.AnnotEditHandler += PdfViewer_AnnotEditHandler;
  71. }
  72. }
  73. //private void PdfViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
  74. //{
  75. // if (e != null && e.Count > 0)
  76. // {
  77. // if (e[0].EditAction == ActionType.Del)
  78. // {
  79. // if (pdfViewerControl.MouseMode == MouseModes.AnnotCreate && pdfViewerControl.ToolManager.CurrentAnnotArgs is EraseArgs)
  80. // {
  81. // return;
  82. // }
  83. // SetAnnotEventData(null);
  84. // }
  85. // if (e[0].EditAction == ActionType.Modify && e[0].EditAnnotArgs != null && e[0].EditAnnotArgs.EventType == AnnotArgsType.AnnotSticky)
  86. // {
  87. // CPDFNoteUI tempUI = annotationPanel as CPDFNoteUI;
  88. // if (tempUI == null || tempUI.annotAttribEvent == null)
  89. // {
  90. // tempUI = tempAnnotationPanel as CPDFNoteUI;
  91. // }
  92. // if (tempUI == null || tempUI.annotAttribEvent == null)
  93. // {
  94. // tempUI = pdfNoteUI;
  95. // }
  96. // if (tempUI != null && tempUI.annotAttribEvent != null)
  97. // {
  98. // AnnotAttribEvent oldEvent = tempUI.annotAttribEvent;
  99. // oldEvent.Attribs[AnnotAttrib.NoteText] = e[0].EditAnnotArgs.Content;
  100. // tempUI.SetPresentAnnotAttrib(oldEvent);
  101. // }
  102. // }
  103. // if (e[0].EditAction == ActionType.Add && e[0].EditAnnotArgs.EventType == AnnotArgsType.AnnotStamp)
  104. // {
  105. // pdfViewerControl.SetMouseMode(MouseModes.PanTool);
  106. // }
  107. // }
  108. //}
  109. public void UnLoadPDFViewHandler()
  110. {
  111. if (this.pdfViewerControl != null)
  112. {
  113. //this.pdfViewerControl.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
  114. }
  115. }
  116. private void AnnotationControl_Loaded(object sender, RoutedEventArgs e)
  117. {
  118. LoadPDFViewHandler();
  119. }
  120. private void AnnotationControl_Unloaded(object sender, RoutedEventArgs e)
  121. {
  122. UnLoadPDFViewHandler();
  123. }
  124. private UIElement GetAnnotationPanel()
  125. {
  126. return AnnotationPanelContainer.Child;
  127. }
  128. private void SetAnnotationPanel(UIElement newChild)
  129. {
  130. AnnotationPanelContainer.Child = newChild;
  131. }
  132. private void ExpandPanel()
  133. {
  134. AnnotationPanelContainer.Visibility = Visibility.Visible;
  135. }
  136. private void ChangeAnnotationData()
  137. {
  138. switch (currentAnnotationType)
  139. {
  140. case CPDFAnnotationType.Highlight:
  141. case CPDFAnnotationType.Underline:
  142. case CPDFAnnotationType.Squiggly:
  143. case CPDFAnnotationType.Strikeout:
  144. (annotationPanel as CPDFMarkupUI).PropertyChanged -= CPDFAnnotationControl_PropertyChanged;
  145. (annotationPanel as CPDFMarkupUI).PropertyChanged += CPDFAnnotationControl_PropertyChanged;
  146. SetAnnotationProperty((annotationPanel as CPDFMarkupUI).GetMarkupData());
  147. break;
  148. case CPDFAnnotationType.Square:
  149. case CPDFAnnotationType.Circle:
  150. case CPDFAnnotationType.Line:
  151. case CPDFAnnotationType.Arrow:
  152. (annotationPanel as CPDFShapeUI).PropertyChanged -= CPDFAnnotationControl_PropertyChanged;
  153. (annotationPanel as CPDFShapeUI).PropertyChanged += CPDFAnnotationControl_PropertyChanged;
  154. SetAnnotationProperty((annotationPanel as CPDFShapeUI).GetShapeData());
  155. break;
  156. case CPDFAnnotationType.Note:
  157. (annotationPanel as CPDFNoteUI).PropertyChanged -= CPDFAnnotationControl_PropertyChanged;
  158. (annotationPanel as CPDFNoteUI).PropertyChanged += CPDFAnnotationControl_PropertyChanged;
  159. SetAnnotationProperty((annotationPanel as CPDFNoteUI).GetNoteData());
  160. break;
  161. case CPDFAnnotationType.Freehand:
  162. (annotationPanel as CPDFFreehandUI).PropertyChanged -= CPDFAnnotationControl_PropertyChanged;
  163. (annotationPanel as CPDFFreehandUI).PropertyChanged += CPDFAnnotationControl_PropertyChanged;
  164. SetAnnotationProperty((annotationPanel as CPDFFreehandUI).GetFreehandData());
  165. break;
  166. case CPDFAnnotationType.FreeText:
  167. (annotationPanel as CPDFFreeTextUI).PropertyChanged -= CPDFAnnotationControl_PropertyChanged;
  168. (annotationPanel as CPDFFreeTextUI).PropertyChanged += CPDFAnnotationControl_PropertyChanged;
  169. SetAnnotationProperty((annotationPanel as CPDFFreeTextUI).GetFreeTextData());
  170. break;
  171. case CPDFAnnotationType.Stamp:
  172. (annotationPanel as CPDFStampUI).PropertyChanged -= CPDFAnnotationControl_PropertyChanged;
  173. (annotationPanel as CPDFStampUI).PropertyChanged += CPDFAnnotationControl_PropertyChanged;
  174. break;
  175. case CPDFAnnotationType.Signature:
  176. (annotationPanel as CPDFSignatureUI).PropertyChanged -= CPDFAnnotationControl_PropertyChanged;
  177. (annotationPanel as CPDFSignatureUI).PropertyChanged += CPDFAnnotationControl_PropertyChanged;
  178. break;
  179. default:
  180. break;
  181. }
  182. }
  183. private void SetAnnotationProperty(CPDFAnnotationData pdfAnnotationData = null)
  184. {
  185. if (pdfAnnotationData == null)
  186. {
  187. pdfViewerControl.PDFToolManager.SetToolType(ToolType.Pan);
  188. return;
  189. }
  190. CPDFAnnotationType annotationType = pdfAnnotationData.AnnotationType;
  191. AnnotParam annotHandlerEventArgs = null;
  192. pdfViewerControl.PDFToolManager.SetToolType(ToolType.CreateAnnot);
  193. switch (annotationType)
  194. {
  195. case CPDFAnnotationType.Highlight:
  196. {
  197. CPDFMarkupData highlightData = pdfAnnotationData as CPDFMarkupData;
  198. annotHandlerEventArgs = new HighlightParam();
  199. byte[] Color = new byte[] { highlightData.Color.R, highlightData.Color.G, highlightData.Color.B };
  200. annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT;
  201. (annotHandlerEventArgs as HighlightParam).HighlightColor = Color;
  202. (annotHandlerEventArgs as HighlightParam).Transparency = Convert.ToByte(highlightData.Opacity * 255);
  203. (annotHandlerEventArgs as HighlightParam).Content = highlightData.Note;
  204. (annotHandlerEventArgs as HighlightParam).Author = highlightData.Author;
  205. (annotHandlerEventArgs as HighlightParam).Locked = highlightData.IsLocked;
  206. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT);
  207. }
  208. break;
  209. case CPDFAnnotationType.Underline:
  210. {
  211. CPDFMarkupData underlineData = pdfAnnotationData as CPDFMarkupData;
  212. annotHandlerEventArgs = new UnderlineParam();
  213. byte[] Color = new byte[] { underlineData.Color.R, underlineData.Color.G, underlineData.Color.B };
  214. annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE;
  215. (annotHandlerEventArgs as UnderlineParam).UnderlineColor = Color;
  216. (annotHandlerEventArgs as UnderlineParam).Transparency = Convert.ToByte(underlineData.Opacity * 255);
  217. (annotHandlerEventArgs as UnderlineParam).Author = underlineData.Author;
  218. (annotHandlerEventArgs as UnderlineParam).Content = underlineData.Note;
  219. (annotHandlerEventArgs as UnderlineParam).Locked = underlineData.IsLocked;
  220. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE);
  221. }
  222. break;
  223. case CPDFAnnotationType.Strikeout:
  224. {
  225. CPDFMarkupData strikeoutData = pdfAnnotationData as CPDFMarkupData;
  226. annotHandlerEventArgs = new StrikeoutParam();
  227. byte[] Color = new byte[] { strikeoutData.Color.R, strikeoutData.Color.G, strikeoutData.Color.B };
  228. annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT;
  229. (annotHandlerEventArgs as StrikeoutParam).StrikeoutColor = Color;
  230. (annotHandlerEventArgs as StrikeoutParam).Transparency = Convert.ToByte(strikeoutData.Opacity * 255);
  231. (annotHandlerEventArgs as StrikeoutParam).Locked = strikeoutData.IsLocked;
  232. (annotHandlerEventArgs as StrikeoutParam).Author = strikeoutData.Author;
  233. (annotHandlerEventArgs as StrikeoutParam).Content = strikeoutData.Note;
  234. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT);
  235. }
  236. break;
  237. case CPDFAnnotationType.Squiggly:
  238. {
  239. CPDFMarkupData squigglyData = pdfAnnotationData as CPDFMarkupData;
  240. annotHandlerEventArgs = new SquigglyParam();
  241. byte[] Color = new byte[] { squigglyData.Color.R, squigglyData.Color.G, squigglyData.Color.B };
  242. annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY;
  243. (annotHandlerEventArgs as SquigglyParam).SquigglyColor = Color;
  244. (annotHandlerEventArgs as SquigglyParam).Transparency = Convert.ToByte(squigglyData.Opacity * 255);
  245. (annotHandlerEventArgs as SquigglyParam).Locked = squigglyData.IsLocked;
  246. (annotHandlerEventArgs as SquigglyParam).Author = squigglyData.Author;
  247. (annotHandlerEventArgs as SquigglyParam).Content = squigglyData.Note;
  248. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY);
  249. }
  250. break;
  251. case CPDFAnnotationType.Square:
  252. {
  253. CPDFShapeData squareData = pdfAnnotationData as CPDFShapeData;
  254. annotHandlerEventArgs = new SquareParam();
  255. annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE;
  256. byte[] LineColor = new byte[] { squareData.BorderColor.R, squareData.BorderColor.G, squareData.BorderColor.B };
  257. (annotHandlerEventArgs as SquareParam).LineColor = LineColor;
  258. if(squareData.FillColor!=Colors.Transparent)
  259. {
  260. byte[] FillColor = new byte[] { squareData.FillColor.R, squareData.FillColor.G, squareData.FillColor.B };
  261. (annotHandlerEventArgs as SquareParam).BgColor = FillColor;
  262. (annotHandlerEventArgs as SquareParam).HasBgColor = true;
  263. }
  264. (annotHandlerEventArgs as SquareParam).LineWidth = squareData.Thickness;
  265. (annotHandlerEventArgs as SquareParam).Transparency = Convert.ToByte(squareData.Opacity * 255);
  266. ParamConverter.ParseDashStyle(squareData.DashStyle, out float[] LineDash, out C_BORDER_STYLE BorderStyle);
  267. (annotHandlerEventArgs as SquareParam).LineDash = LineDash;
  268. (annotHandlerEventArgs as SquareParam).BorderStyle = BorderStyle;
  269. (annotHandlerEventArgs as SquareParam).Author = squareData.Author;
  270. (annotHandlerEventArgs as SquareParam).Content = squareData.Note;
  271. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE);
  272. }
  273. break;
  274. case CPDFAnnotationType.Circle:
  275. {
  276. CPDFShapeData cicleData = pdfAnnotationData as CPDFShapeData;
  277. annotHandlerEventArgs = new CircleParam();
  278. annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE;
  279. byte[] LineColor = new byte[] { cicleData.BorderColor.R, cicleData.BorderColor.G, cicleData.BorderColor.B };
  280. (annotHandlerEventArgs as CircleParam).LineColor = LineColor;
  281. if(cicleData.FillColor!=Colors.Transparent)
  282. {
  283. byte[] BgColor = new byte[] { cicleData.FillColor.R, cicleData.FillColor.G, cicleData.FillColor.B };
  284. (annotHandlerEventArgs as CircleParam).BgColor = BgColor;
  285. (annotHandlerEventArgs as CircleParam).HasBgColor=true;
  286. }
  287. (annotHandlerEventArgs as CircleParam).LineWidth = cicleData.Thickness;
  288. (annotHandlerEventArgs as CircleParam).Transparency = Convert.ToByte(cicleData.Opacity * 255);
  289. ParamConverter.ParseDashStyle(cicleData.DashStyle, out float[] LineDash, out C_BORDER_STYLE BorderStyle);
  290. (annotHandlerEventArgs as CircleParam).LineDash = LineDash;
  291. (annotHandlerEventArgs as CircleParam).BorderStyle = BorderStyle;
  292. (annotHandlerEventArgs as CircleParam).Author = cicleData.Author;
  293. (annotHandlerEventArgs as CircleParam).Content = cicleData.Note;
  294. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE);
  295. }
  296. break;
  297. case CPDFAnnotationType.Arrow:
  298. case CPDFAnnotationType.Line:
  299. {
  300. CPDFLineShapeData lineData = pdfAnnotationData as CPDFLineShapeData;
  301. annotHandlerEventArgs = new LineParam();
  302. annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_LINE;
  303. byte[] LineColor = new byte[] { lineData.BorderColor.R, lineData.BorderColor.G, lineData.BorderColor.B };
  304. (annotHandlerEventArgs as LineParam).LineColor = LineColor;
  305. (annotHandlerEventArgs as LineParam).LineWidth = lineData.Thickness;
  306. (annotHandlerEventArgs as LineParam).Transparency = Convert.ToByte(lineData.Opacity * 255);
  307. ParamConverter.ParseDashStyle(lineData.DashStyle, out float[] LineDash, out C_BORDER_STYLE BorderStyle);
  308. (annotHandlerEventArgs as LineParam).LineDash = LineDash;
  309. (annotHandlerEventArgs as LineParam).BorderStyle = BorderStyle;
  310. (annotHandlerEventArgs as LineParam).HeadLineType = lineData.LineType.HeadLineType;
  311. (annotHandlerEventArgs as LineParam).TailLineType = lineData.LineType.TailLineType;
  312. (annotHandlerEventArgs as LineParam).Author = lineData.Author;
  313. (annotHandlerEventArgs as LineParam).Content = lineData.Note;
  314. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_LINE);
  315. }
  316. break;
  317. case CPDFAnnotationType.Note:
  318. {
  319. CPDFNoteData noteData = pdfAnnotationData as CPDFNoteData;
  320. annotHandlerEventArgs = new StickyNoteParam();
  321. annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_TEXT;
  322. byte[] StickyNoteColor = new byte[] { noteData.BorderColor.R, noteData.BorderColor.G, noteData.BorderColor.B };
  323. (annotHandlerEventArgs as StickyNoteParam).StickyNoteColor = StickyNoteColor;
  324. (annotHandlerEventArgs as StickyNoteParam).Content = noteData.Note;
  325. (annotHandlerEventArgs as StickyNoteParam).Transparency = 255;
  326. (annotHandlerEventArgs as StickyNoteParam).Author = noteData.Author;
  327. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_TEXT);
  328. }
  329. break;
  330. case CPDFAnnotationType.Freehand:
  331. {
  332. CPDFFreehandData freehandData = pdfAnnotationData as CPDFFreehandData;
  333. annotHandlerEventArgs = new InkParam();
  334. annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_INK;
  335. byte[] LineColor = new byte[] { freehandData.BorderColor.R, freehandData.BorderColor.G, freehandData.BorderColor.B };
  336. (annotHandlerEventArgs as InkParam).InkColor = LineColor;
  337. (annotHandlerEventArgs as InkParam).Thickness = freehandData.Thickness;
  338. (annotHandlerEventArgs as InkParam).Transparency = Convert.ToByte(freehandData.Opacity * 255);
  339. (annotHandlerEventArgs as InkParam).Content = freehandData.Note;
  340. (annotHandlerEventArgs as InkParam).Author = freehandData.Author;
  341. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_INK);
  342. }
  343. break;
  344. case CPDFAnnotationType.FreeText:
  345. {
  346. CPDFFreeTextData freeTextData = pdfAnnotationData as CPDFFreeTextData;
  347. annotHandlerEventArgs = new FreeTextParam();
  348. annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT;
  349. (annotHandlerEventArgs as FreeTextParam).Transparency = Convert.ToByte(freeTextData.Opacity * 255);
  350. (annotHandlerEventArgs as FreeTextParam).FontName = freeTextData.FontFamily.ToString();
  351. byte[] FontColor = new byte[] { freeTextData.BorderColor.R, freeTextData.BorderColor.G, freeTextData.BorderColor.B };
  352. (annotHandlerEventArgs as FreeTextParam).FontColor = FontColor;
  353. (annotHandlerEventArgs as FreeTextParam).IsBold = freeTextData.IsBold;
  354. (annotHandlerEventArgs as FreeTextParam).IsItalic = freeTextData.IsItalic;
  355. (annotHandlerEventArgs as FreeTextParam).FontSize = freeTextData.FontSize;
  356. switch (freeTextData.TextAlignment)
  357. {
  358. case TextAlignment.Left:
  359. (annotHandlerEventArgs as FreeTextParam).Alignment = C_TEXT_ALIGNMENT.ALIGNMENT_LEFT;
  360. break;
  361. case TextAlignment.Right:
  362. (annotHandlerEventArgs as FreeTextParam).Alignment = C_TEXT_ALIGNMENT.ALIGNMENT_RIGHT;
  363. break;
  364. case TextAlignment.Center:
  365. (annotHandlerEventArgs as FreeTextParam).Alignment = C_TEXT_ALIGNMENT.ALIGNMENT_CENTER;
  366. break;
  367. default:
  368. break;
  369. }
  370. (annotHandlerEventArgs as FreeTextParam).Content = freeTextData.Note;
  371. (annotHandlerEventArgs as FreeTextParam).Author = freeTextData.Author;
  372. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT);
  373. }
  374. break;
  375. case CPDFAnnotationType.Stamp:
  376. {
  377. StampParam stampParam = new StampParam();
  378. stampParam.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_STAMP;
  379. CPDFStampData stampData = pdfAnnotationData as CPDFStampData;
  380. SetStamp(ref stampParam, stampData);
  381. annotHandlerEventArgs = stampParam;
  382. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_STAMP);
  383. stampParam.ImageStream.Seek(0, SeekOrigin.Begin);
  384. BitmapDecoder decoder = BitmapDecoder.Create(stampParam.ImageStream,
  385. BitmapCreateOptions.None,
  386. BitmapCacheOption.Default);
  387. BitmapFrame frame = null;
  388. if (decoder != null && decoder.Frames.Count > 0)
  389. {
  390. frame = decoder.Frames[0];
  391. }
  392. if (frame != null)
  393. {
  394. byte[] imageArray = new byte[frame.PixelWidth * frame.PixelHeight * 4];
  395. if (frame.Format != PixelFormats.Bgra32)
  396. {
  397. FormatConvertedBitmap covert = new FormatConvertedBitmap(
  398. frame,
  399. PixelFormats.Bgra32,
  400. frame.Palette,
  401. 0);
  402. covert.CopyPixels(imageArray, frame.PixelWidth * 4, 0);
  403. }
  404. else
  405. {
  406. frame.CopyPixels(imageArray, frame.PixelWidth * 4, 0);
  407. }
  408. pdfViewerControl.PDFViewTool.GetCPDFViewer().SetStampMouseImage(imageArray, frame.PixelWidth, frame.PixelHeight);
  409. }
  410. pdfViewerControl.PDFViewTool.GetCPDFViewer().SetIsVisibleCustomMouse(true);
  411. pdfViewerControl.PDFViewTool.GetCPDFViewer().SetIsShowStampMouse(true);
  412. }
  413. break;
  414. case CPDFAnnotationType.Signature:
  415. AnnotParam signatureParam = new AnnotParam();
  416. CPDFSignatureData SignatureData = pdfAnnotationData as CPDFSignatureData;
  417. SetSignature(ref signatureParam, SignatureData);
  418. annotHandlerEventArgs = signatureParam;
  419. break;
  420. case CPDFAnnotationType.Link:
  421. if (annotHandlerEventArgs != null)
  422. {
  423. annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_LINK;
  424. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_LINK);
  425. }
  426. break;
  427. case CPDFAnnotationType.Unknow:
  428. pdfViewerControl.PDFToolManager.SetToolType(ToolType.Pan);
  429. return;
  430. default:
  431. break;
  432. }
  433. pdfViewerControl.PDFToolManager.SetToolType(ToolType.CreateAnnot);
  434. DefaultSettingParam defaultSettingParam = pdfViewerControl.PDFViewTool.GetDefaultSettingParam();
  435. defaultSettingParam.SetAnnotParam(annotHandlerEventArgs);
  436. }
  437. public void SetSignature(ref AnnotParam annotParam, CPDFSignatureData stamp)
  438. {
  439. switch (stamp.Type)
  440. {
  441. case SignatureType.TextType:
  442. case SignatureType.ImageType:
  443. {
  444. annotParam = new StampParam();
  445. annotParam.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_STAMP;
  446. (annotParam as StampParam).Transparency = 1;
  447. (annotParam as StampParam).StampType = C_STAMP_TYPE.IMAGE_STAMP;
  448. if (!string.IsNullOrEmpty(stamp.SourcePath))
  449. {
  450. BitmapImage image = new BitmapImage(new Uri(stamp.SourcePath));
  451. PngBitmapEncoder encoder = new PngBitmapEncoder();
  452. encoder.Frames.Add(BitmapFrame.Create(image));
  453. MemoryStream memoryStream = new MemoryStream();
  454. encoder.Save(memoryStream);
  455. (annotParam as StampParam).ImageStream = memoryStream;
  456. }
  457. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_STAMP);
  458. }
  459. break;
  460. case SignatureType.Drawing:
  461. {
  462. annotParam = new InkParam();
  463. annotParam.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_INK;
  464. List<List<Point>> RawPointList = GetPoints(stamp.DrawingPath);
  465. List<CPoint> linqList = new List<CPoint>();
  466. if (RawPointList != null && RawPointList.Count > 0)
  467. {
  468. List<List<CPoint>> inkPath = new List<List<CPoint>>();
  469. foreach (List<Point> inkPoints in RawPointList)
  470. {
  471. List<CPoint> ink = new List<CPoint>();
  472. foreach (Point point in inkPoints)
  473. {
  474. ink.Add(new CPoint((float)point.X, (float)point.Y));
  475. linqList.Add(new CPoint((float)point.X, (float)point.Y));
  476. }
  477. if (ink.Count > 0)
  478. {
  479. inkPath.Add(ink);
  480. }
  481. }
  482. if (inkPath.Count > 0)
  483. {
  484. (annotParam as InkParam).InkPath = inkPath;
  485. }
  486. }
  487. (annotParam as InkParam).Thickness = stamp.inkThickness;
  488. byte[] InkColor = new byte[] { stamp.inkColor.R, stamp.inkColor.G, stamp.inkColor.B };
  489. (annotParam as InkParam).InkColor = InkColor;
  490. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_INK);
  491. }
  492. break;
  493. default:
  494. break;
  495. }
  496. }
  497. private List<List<Point>> GetPoints(string Path)
  498. {
  499. StrokeCollection Strokes;
  500. List<List<Point>> RawPointList = new List<List<Point>>();
  501. using (FileStream strokeStream = File.OpenRead(Path))
  502. {
  503. Strokes = new StrokeCollection(strokeStream);
  504. }
  505. for (int kk = 0; kk < Strokes.Count; kk++)
  506. {
  507. List<Point> p = new List<Point>();
  508. RawPointList.Add(p);
  509. for (int gg = 0; gg < Strokes[kk].StylusPoints.Count; gg++)
  510. {
  511. var point = Strokes[kk].StylusPoints[gg].ToPoint();
  512. if (point.X >= 0 && point.Y >= 0)
  513. RawPointList[kk].Add(point);
  514. }
  515. }
  516. return RawPointList;
  517. }
  518. private void SetStamp(ref StampParam stampParam, CPDFStampData stamp)
  519. {
  520. stampParam.StampText = stamp.StampText;
  521. stampParam.Author = stamp.Author;
  522. stampParam.Transparency = Convert.ToByte(stamp.Opacity * 255);
  523. stampParam.DateText = stamp.StampTextDate;
  524. stampParam.TextStampColor = stamp.TextColor;
  525. stampParam.TextStampShape = stamp.TextSharp;
  526. if (!string.IsNullOrEmpty(stamp.SourcePath))
  527. {
  528. BitmapImage image = new BitmapImage(new Uri(stamp.SourcePath));
  529. PngBitmapEncoder encoder = new PngBitmapEncoder();
  530. encoder.Frames.Add(BitmapFrame.Create(image));
  531. MemoryStream memoryStream = new MemoryStream();
  532. encoder.Save(memoryStream);
  533. stampParam.ImageStream = memoryStream;
  534. }
  535. else
  536. {
  537. var i = pdfStampUI.CustomStampList.IndexOf(stamp);
  538. Settings.Default.CustomStampList.RemoveAt(i);
  539. Settings.Default.Save();
  540. pdfStampUI.LoadSettings();
  541. return;
  542. }
  543. stampParam.StampType = stamp.Type;
  544. }
  545. public void AnnotationCancel()
  546. {
  547. this.pdfViewerControl.PDFToolManager.SetToolType(ToolType.Pan);
  548. ClearPanel();
  549. }
  550. private void CPDFAnnotationControl_PropertyChanged(object sender, CPDFAnnotationData e)
  551. {
  552. SetAnnotationProperty(e);
  553. }
  554. public void InitAnnotationPanel(CPDFAnnotationType annotationType)
  555. {
  556. switch (annotationType)
  557. {
  558. case CPDFAnnotationType.Highlight:
  559. if (pdfHighlightUI == null)
  560. {
  561. pdfHighlightUI = new CPDFMarkupUI();
  562. }
  563. annotationPanel = pdfHighlightUI;
  564. (annotationPanel as CPDFMarkupUI).InitWithAnnotationType(annotationType);
  565. break;
  566. case CPDFAnnotationType.Underline:
  567. if (pdfUnderlineUI == null)
  568. {
  569. pdfUnderlineUI = new CPDFMarkupUI();
  570. }
  571. annotationPanel = pdfUnderlineUI;
  572. (annotationPanel as CPDFMarkupUI).InitWithAnnotationType(annotationType);
  573. break;
  574. case CPDFAnnotationType.Strikeout:
  575. if (pdfStrikeoutUI == null)
  576. {
  577. pdfStrikeoutUI = new CPDFMarkupUI();
  578. }
  579. annotationPanel = pdfStrikeoutUI;
  580. (annotationPanel as CPDFMarkupUI).InitWithAnnotationType(annotationType);
  581. break;
  582. case CPDFAnnotationType.Squiggly:
  583. if (pdfSquigglyUI == null)
  584. {
  585. pdfSquigglyUI = new CPDFMarkupUI();
  586. }
  587. annotationPanel = pdfSquigglyUI;
  588. (annotationPanel as CPDFMarkupUI).InitWithAnnotationType(annotationType);
  589. break;
  590. case CPDFAnnotationType.Square:
  591. if (pdfSquareUI == null)
  592. {
  593. pdfSquareUI = new CPDFShapeUI();
  594. }
  595. annotationPanel = pdfSquareUI;
  596. (annotationPanel as CPDFShapeUI).InitWithAnnotationType(annotationType);
  597. break;
  598. case CPDFAnnotationType.Circle:
  599. if (pdfCircleUI == null)
  600. {
  601. pdfCircleUI = new CPDFShapeUI();
  602. }
  603. annotationPanel = pdfCircleUI;
  604. (annotationPanel as CPDFShapeUI).InitWithAnnotationType(annotationType);
  605. break;
  606. case CPDFAnnotationType.Arrow:
  607. if (pdfArrowUI == null)
  608. {
  609. pdfArrowUI = new CPDFShapeUI();
  610. }
  611. annotationPanel = pdfArrowUI;
  612. (annotationPanel as CPDFShapeUI).InitWithAnnotationType(annotationType);
  613. break;
  614. case CPDFAnnotationType.Line:
  615. if (pdfLineUI == null)
  616. {
  617. pdfLineUI = new CPDFShapeUI();
  618. }
  619. annotationPanel = pdfLineUI;
  620. (annotationPanel as CPDFShapeUI).InitWithAnnotationType(annotationType);
  621. break;
  622. case CPDFAnnotationType.Freehand:
  623. if (pdfFreehandUI == null)
  624. {
  625. pdfFreehandUI = new CPDFFreehandUI();
  626. pdfFreehandUI.EraseClickHandler += PdfFreehandUI_EraseClickHandler;
  627. pdfFreehandUI.EraseChangeHandler += PdfFreehandUI_EraseChangeHandler;
  628. }
  629. annotationPanel = pdfFreehandUI;
  630. break;
  631. case CPDFAnnotationType.FreeText:
  632. if (pdfFreeTextUI == null)
  633. {
  634. pdfFreeTextUI = new CPDFFreeTextUI();
  635. }
  636. annotationPanel = pdfFreeTextUI;
  637. break;
  638. case CPDFAnnotationType.Note:
  639. if (pdfNoteUI == null)
  640. {
  641. pdfNoteUI = new CPDFNoteUI();
  642. }
  643. annotationPanel = pdfNoteUI;
  644. break;
  645. case CPDFAnnotationType.Stamp:
  646. if (pdfStampUI == null)
  647. {
  648. pdfStampUI = new CPDFStampUI();
  649. }
  650. annotationPanel = pdfStampUI;
  651. break;
  652. case CPDFAnnotationType.Signature:
  653. if (pdfSignatureUI == null)
  654. {
  655. pdfSignatureUI = new CPDFSignatureUI();
  656. }
  657. annotationPanel = pdfSignatureUI;
  658. break;
  659. case CPDFAnnotationType.Link:
  660. if (pdfLinkUI == null)
  661. {
  662. pdfLinkUI = new CPDFLinkUI();
  663. }
  664. LinkParam linkAnnotArgs = new LinkParam();
  665. if (this.pdfViewerControl != null && pdfViewerControl.PDFViewTool != null && pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument() != null)
  666. {
  667. pdfViewerControl.PDFToolManager.SetToolType(ToolType.CreateAnnot);
  668. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_LINK);
  669. pdfLinkUI.InitLinkAnnotArgs(linkAnnotArgs, pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument().PageCount);
  670. }
  671. annotationPanel = pdfLinkUI;
  672. break;
  673. case CPDFAnnotationType.Audio:
  674. //SoundAnnotArgs soundArgs = new SoundAnnotArgs();
  675. //OpenFileDialog openAudioDialog = new OpenFileDialog();
  676. //openAudioDialog.Filter = "Wave Files(*.wav)|*.wav|All Files(*.*;)|*.*;";
  677. //if (openAudioDialog.ShowDialog() == true)
  678. //{
  679. // soundArgs.SoundFilePath = openAudioDialog.FileName;
  680. // this.pdfViewerControl.SetMouseMode(MouseModes.AnnotCreate);
  681. // pdfViewerControl.SetToolParam(soundArgs);
  682. //}
  683. //else
  684. //{
  685. // this.pdfViewerControl.SetMouseMode(MouseModes.PanTool);
  686. // ClearAnnotationBar?.Invoke(this, EventArgs.Empty);
  687. //}
  688. ClearPanel();
  689. break;
  690. case CPDFAnnotationType.Image:
  691. //StampAnnotArgs stampArgs = new StampAnnotArgs();
  692. //stampArgs.Opacity = 1;
  693. //stampArgs.Type = StampType.IMAGE_STAMP;
  694. //OpenFileDialog openFileDialog = new OpenFileDialog();
  695. //openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  696. //if (openFileDialog.ShowDialog() == true)
  697. //{
  698. // stampArgs.ImagePath = openFileDialog.FileName;
  699. // this.pdfViewerControl?.SetMouseMode(MouseModes.AnnotCreate);
  700. // this.pdfViewerControl?.SetToolParam(stampArgs);
  701. //}
  702. //else
  703. //{
  704. // this.pdfViewerControl.SetMouseMode(MouseModes.PanTool);
  705. //}
  706. //ClearAnnotationBar?.Invoke(this, EventArgs.Empty);
  707. ClearPanel();
  708. break;
  709. default:
  710. break;
  711. }
  712. }
  713. private void PdfFreehandUI_EraseChangeHandler(object sender, double e)
  714. {
  715. if (pdfViewerControl != null )
  716. {
  717. pdfViewerControl.PDFViewTool.SetEraseZoom(e);
  718. }
  719. }
  720. private void PdfFreehandUI_EraseClickHandler(object sender, bool e)
  721. {
  722. if (e)
  723. {
  724. pdfViewerControl.PDFViewTool.SetViewerModel(MouseModess.kCustomizeTool);
  725. }
  726. else
  727. {
  728. pdfViewerControl.PDFToolManager.SetToolType(ToolType.CreateAnnot);
  729. pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_INK);
  730. }
  731. //if (pdfViewerControl != null)
  732. //{
  733. // CPDFFreehandUI freehandUI = sender as CPDFFreehandUI;
  734. // if (e)
  735. // {
  736. // annotArgs = pdfViewerControl.ToolManager.CurrentAnnotArgs;
  737. // eraseArgs = new EraseArgs();
  738. // eraseArgs.UIBorderColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  739. // eraseArgs.UIFillColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  740. // if (freehandUI != null)
  741. // {
  742. // eraseArgs.Thickness = freehandUI.GetEraseThickness();
  743. // }
  744. // else
  745. // {
  746. // eraseArgs.Thickness = 1;
  747. // }
  748. // disableClean = true;
  749. // pdfViewerControl.PDFToolManager.SetToolType(ToolType.CreateAnnot);
  750. // pdfViewerControl.SetToolParam(eraseArgs);
  751. // disableClean = false;
  752. // EmptyMessage.Visibility = Visibility.Collapsed;
  753. // }
  754. // else
  755. // {
  756. // pdfViewerControl.PDFToolManager.SetToolType(ToolType.CreateAnnot);
  757. // FreehandAnnotArgs freehandAnnotArgs = annotArgs as FreehandAnnotArgs;
  758. // if (freehandAnnotArgs == null)
  759. // {
  760. // freehandAnnotArgs = new FreehandAnnotArgs();
  761. // freehandAnnotArgs.InkColor = Colors.Red;
  762. // freehandAnnotArgs.Transparency = 1;
  763. // freehandAnnotArgs.LineWidth = 1;
  764. // annotArgs = freehandAnnotArgs;
  765. // }
  766. // if (freehandUI != null)
  767. // {
  768. // freehandUI.PropertyChanged -= CPDFAnnotationControl_PropertyChanged;
  769. // Dictionary<AnnotAttrib, object> attribDict = new Dictionary<AnnotAttrib, object>();
  770. // attribDict[AnnotAttrib.Color] = freehandAnnotArgs.InkColor;
  771. // attribDict[AnnotAttrib.Transparency] = freehandAnnotArgs.Transparency;
  772. // attribDict[AnnotAttrib.Thickness] = freehandAnnotArgs.LineWidth;
  773. // attribDict[AnnotAttrib.NoteText] = freehandAnnotArgs.Content;
  774. // AnnotAttribEvent annotEvent = AnnotAttribEvent.GetAnnotAttribEvent(freehandAnnotArgs, attribDict);
  775. // freehandUI.SetPresentAnnotAttrib(annotEvent);
  776. // freehandUI.PropertyChanged += CPDFAnnotationControl_PropertyChanged;
  777. // freehandUI.ClearAnnotAttribEvent();
  778. // }
  779. // pdfViewerControl.SetToolParam(freehandAnnotArgs);
  780. // }
  781. //}
  782. }
  783. public void CreatTempAnnotationPanel(BaseAnnot baseAnnot)
  784. {
  785. switch (baseAnnot.CurrentType)
  786. {
  787. case C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT:
  788. {
  789. tempAnnotationPanel = new CPDFMarkupUI();
  790. (tempAnnotationPanel as CPDFMarkupUI).InitWithAnnotationType(CPDFAnnotationType.Highlight);
  791. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  792. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  793. baseAnnot.GetAnnotData().PageIndex,
  794. baseAnnot.GetAnnotData().Annot);
  795. (tempAnnotationPanel as CPDFMarkupUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot as CPDFMarkupAnnotation, pdfViewerControl);
  796. }
  797. break;
  798. case C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE:
  799. {
  800. tempAnnotationPanel = new CPDFMarkupUI();
  801. (tempAnnotationPanel as CPDFMarkupUI).InitWithAnnotationType(CPDFAnnotationType.Underline);
  802. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  803. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  804. baseAnnot.GetAnnotData().PageIndex,
  805. baseAnnot.GetAnnotData().Annot);
  806. (tempAnnotationPanel as CPDFMarkupUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot as CPDFMarkupAnnotation, pdfViewerControl);
  807. }
  808. break;
  809. case C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT:
  810. {
  811. tempAnnotationPanel = new CPDFMarkupUI();
  812. (tempAnnotationPanel as CPDFMarkupUI).InitWithAnnotationType(CPDFAnnotationType.Strikeout);
  813. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  814. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  815. baseAnnot.GetAnnotData().PageIndex,
  816. baseAnnot.GetAnnotData().Annot);
  817. (tempAnnotationPanel as CPDFMarkupUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot as CPDFMarkupAnnotation, pdfViewerControl);
  818. }
  819. break;
  820. case C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY:
  821. {
  822. tempAnnotationPanel = new CPDFMarkupUI();
  823. (tempAnnotationPanel as CPDFMarkupUI).InitWithAnnotationType(CPDFAnnotationType.Squiggly);
  824. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  825. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  826. baseAnnot.GetAnnotData().PageIndex,
  827. baseAnnot.GetAnnotData().Annot);
  828. (tempAnnotationPanel as CPDFMarkupUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot as CPDFMarkupAnnotation, pdfViewerControl);
  829. }
  830. break;
  831. case C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE:
  832. {
  833. tempAnnotationPanel = new CPDFShapeUI();
  834. (tempAnnotationPanel as CPDFShapeUI).InitWithAnnotationType(CPDFAnnotationType.Square);
  835. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  836. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  837. baseAnnot.GetAnnotData().PageIndex,
  838. baseAnnot.GetAnnotData().Annot);
  839. (tempAnnotationPanel as CPDFShapeUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot, pdfViewerControl);
  840. }
  841. break;
  842. case C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE:
  843. {
  844. tempAnnotationPanel = new CPDFShapeUI();
  845. (tempAnnotationPanel as CPDFShapeUI).InitWithAnnotationType(CPDFAnnotationType.Circle);
  846. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  847. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  848. baseAnnot.GetAnnotData().PageIndex,
  849. baseAnnot.GetAnnotData().Annot);
  850. (tempAnnotationPanel as CPDFShapeUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot, pdfViewerControl);
  851. }
  852. break;
  853. case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
  854. {
  855. tempAnnotationPanel = new CPDFShapeUI();
  856. (tempAnnotationPanel as CPDFShapeUI).InitWithAnnotationType(CPDFAnnotationType.Line);
  857. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  858. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  859. baseAnnot.GetAnnotData().PageIndex,
  860. baseAnnot.GetAnnotData().Annot);
  861. (tempAnnotationPanel as CPDFShapeUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot, pdfViewerControl);
  862. }
  863. break;
  864. case C_ANNOTATION_TYPE.C_ANNOTATION_INK:
  865. {
  866. CPDFFreehandUI tempFreehandPanel = new CPDFFreehandUI();
  867. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  868. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  869. baseAnnot.GetAnnotData().PageIndex,
  870. baseAnnot.GetAnnotData().Annot);
  871. tempFreehandPanel.SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot, pdfViewerControl.PDFToolManager.GetDocument(), pdfViewerControl);
  872. tempFreehandPanel.EraseClickHandler += PdfFreehandUI_EraseClickHandler;
  873. tempFreehandPanel.EraseChangeHandler += PdfFreehandUI_EraseChangeHandler;
  874. tempAnnotationPanel = tempFreehandPanel;
  875. }
  876. break;
  877. case C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT:
  878. {
  879. tempAnnotationPanel = new CPDFFreeTextUI();
  880. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  881. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  882. baseAnnot.GetAnnotData().PageIndex,
  883. baseAnnot.GetAnnotData().Annot);
  884. (tempAnnotationPanel as CPDFFreeTextUI).SetPresentAnnotAttrib(annotParam as FreeTextParam, baseAnnot.GetAnnotData().Annot as CPDFFreeTextAnnotation, pdfViewerControl);
  885. }
  886. break;
  887. case C_ANNOTATION_TYPE.C_ANNOTATION_TEXT:
  888. {
  889. tempAnnotationPanel = new CPDFNoteUI();
  890. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  891. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  892. baseAnnot.GetAnnotData().PageIndex,
  893. baseAnnot.GetAnnotData().Annot);
  894. (tempAnnotationPanel as CPDFNoteUI).SetPresentAnnotAttrib(annotParam as StickyNoteParam, baseAnnot.GetAnnotData().Annot as CPDFTextAnnotation, pdfViewerControl);
  895. }
  896. break;
  897. case C_ANNOTATION_TYPE.C_ANNOTATION_STAMP:
  898. {
  899. tempAnnotationPanel = new CPDFTempStampUI();
  900. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  901. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  902. baseAnnot.GetAnnotData().PageIndex,
  903. baseAnnot.GetAnnotData().Annot);
  904. (tempAnnotationPanel as CPDFTempStampUI).SetPresentAnnotAttrib(annotParam as StampParam , baseAnnot.GetAnnotData().Annot as CPDFStampAnnotation , pdfViewerControl.PDFToolManager.GetDocument(), pdfViewerControl);
  905. }
  906. break;
  907. case C_ANNOTATION_TYPE.C_ANNOTATION_LINK:
  908. {
  909. tempAnnotationPanel = new CPDFLinkUI();
  910. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  911. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  912. baseAnnot.GetAnnotData().PageIndex,
  913. baseAnnot.GetAnnotData().Annot);
  914. (tempAnnotationPanel as CPDFLinkUI).SetPresentAnnotAttrib(annotParam as LinkParam, baseAnnot.GetAnnotData().Annot as CPDFLinkAnnotation, pdfViewerControl, pdfViewerControl.PDFToolManager.GetDocument().PageCount);
  915. }
  916. break;
  917. case C_ANNOTATION_TYPE.C_ANNOTATION_SOUND:
  918. tempAnnotationPanel = null;
  919. break;
  920. default:
  921. break;
  922. }
  923. }
  924. public void LoadAnnotationPanel(CPDFAnnotationType annotationType)
  925. {
  926. this.pdfViewerControl.PDFToolManager.SetToolType(ToolType.Pan);
  927. currentAnnotationType = annotationType;
  928. annotationPanel = GetAnnotationPanel();
  929. InitAnnotationPanel(annotationType);
  930. ShowCurrentAnnotPanel();
  931. }
  932. private void ShowCurrentAnnotPanel()
  933. {
  934. if (annotationPanel != null)
  935. {
  936. if (annotationPanel is CPDFFreehandUI)
  937. {
  938. (annotationPanel as CPDFFreehandUI)?.SetEraseCheck(false);
  939. }
  940. SetAnnotationPanel(annotationPanel);
  941. ExpandPanel();
  942. ChangeAnnotationData();
  943. EmptyMessage.Visibility = Visibility.Collapsed;
  944. }
  945. else
  946. {
  947. EmptyMessage.Visibility = Visibility.Visible;
  948. SetAnnotationPanel(null);
  949. if (pdfViewerControl != null)
  950. {
  951. EmptyMessage.Visibility = Visibility.Collapsed;
  952. }
  953. }
  954. }
  955. private void ShowTempAnnotPanel()
  956. {
  957. BaseAnnot baseAnnot = pdfViewerControl.PDFToolManager.GetCacheHitTestAnnot();
  958. if (baseAnnot != null)
  959. {
  960. CreatTempAnnotationPanel(baseAnnot);
  961. SetAnnotationPanel(tempAnnotationPanel);
  962. ExpandPanel();
  963. if (tempAnnotationPanel != null)
  964. {
  965. EmptyMessage.Visibility = Visibility.Collapsed;
  966. }
  967. else
  968. {
  969. EmptyMessage.Visibility = Visibility.Visible;
  970. }
  971. }
  972. }
  973. private void PDFToolManager_MouseLeftButtonDownHandler(object sender, MouseEventObject e)
  974. {
  975. SetAnnotEventData();
  976. }
  977. public void ClearPanel()
  978. {
  979. annotationPanel = null;
  980. SetAnnotationPanel(annotationPanel);
  981. EmptyMessage.Visibility = Visibility.Visible;
  982. }
  983. public void SetAnnotEventData()
  984. {
  985. if (pdfViewerControl.PDFToolManager != null)
  986. {
  987. if (pdfViewerControl.PDFToolManager.GetCacheHitTestAnnot() == null && isTempPanel)
  988. {
  989. ShowCurrentAnnotPanel();
  990. isTempPanel = false;
  991. }
  992. else if (pdfViewerControl.PDFToolManager.GetCacheHitTestAnnot() != null)
  993. {
  994. ShowTempAnnotPanel();
  995. isTempPanel = true;
  996. }
  997. }
  998. else
  999. {
  1000. if (pdfViewerControl != null && pdfViewerControl.PDFToolManager.GetToolType() == ToolType.CreateAnnot)
  1001. {
  1002. ShowCurrentAnnotPanel();
  1003. isTempPanel = false;
  1004. }
  1005. else if (annotationPanel is CPDFStampUI && currentAnnotationType == CPDFAnnotationType.Stamp)
  1006. {
  1007. ShowCurrentAnnotPanel();
  1008. }
  1009. else if (annotationPanel is CPDFSignatureUI && currentAnnotationType == CPDFAnnotationType.Signature)
  1010. {
  1011. ShowCurrentAnnotPanel();
  1012. }
  1013. else if (disableClean == false)
  1014. {
  1015. ClearPanel();
  1016. }
  1017. }
  1018. }
  1019. }
  1020. }