CPDFAnnotationControl.xaml.cs 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191
  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 ComPDFKit.PDFDocument;
  22. using ComPDFKitViewer.BaseObject;
  23. using ComPDFKitViewer.Helper;
  24. using ComPDFKit.Viewer.Helper;
  25. namespace Compdfkit_Tools.PDFControl
  26. {
  27. public partial class CPDFAnnotationControl : UserControl
  28. {
  29. private bool isTempPanel = false;
  30. private CPDFAnnotationType currentAnnotationType = CPDFAnnotationType.Unknown;
  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.MouseLeftButtonDownHandler -= PDFToolManager_MouseLeftButtonDownHandler;
  68. pdfViewerControl.MouseLeftButtonDownHandler += PDFToolManager_MouseLeftButtonDownHandler;
  69. pdfViewerControl.MouseLeftButtonUpHandler -= PdfViewerControl_MouseLeftButtonUpHandler;
  70. pdfViewerControl.MouseLeftButtonUpHandler += PdfViewerControl_MouseLeftButtonUpHandler;
  71. pdfViewerControl.MouseRightButtonDownHandler -= PDFViewControl_MouseRightButtonDownHandler;
  72. pdfViewerControl.MouseRightButtonDownHandler += PDFViewControl_MouseRightButtonDownHandler;
  73. }
  74. }
  75. private void PDFViewControl_MouseRightButtonDownHandler(object sender, MouseEventObject e)
  76. {
  77. //throw new NotImplementedException();
  78. }
  79. private void PdfViewerControl_MouseLeftButtonUpHandler(object sender, MouseEventObject e)
  80. {
  81. if (e.IsCreate)
  82. {
  83. pdfViewerControl.UpdateAnnotFrame();
  84. if (currentAnnotationType == CPDFAnnotationType.Image || currentAnnotationType == CPDFAnnotationType.Stamp || currentAnnotationType == CPDFAnnotationType.Signature)
  85. {
  86. pdfViewerControl.SetToolType(ToolType.Pan);
  87. pdfViewerControl.SetIsVisibleCustomMouse(false);
  88. pdfViewerControl.SetIsShowStampMouse(false);
  89. }
  90. }
  91. }
  92. public void UnLoadPDFViewHandler()
  93. {
  94. if (this.pdfViewerControl != null)
  95. {
  96. pdfViewerControl.MouseLeftButtonDownHandler -= PDFToolManager_MouseLeftButtonDownHandler;
  97. }
  98. }
  99. private void AnnotationControl_Loaded(object sender, RoutedEventArgs e)
  100. {
  101. LoadPDFViewHandler();
  102. }
  103. private void AnnotationControl_Unloaded(object sender, RoutedEventArgs e)
  104. {
  105. // UnLoadPDFViewHandler();
  106. }
  107. private UIElement GetAnnotationPanel()
  108. {
  109. return AnnotationPanelContainer.Child;
  110. }
  111. private void SetAnnotationPanel(UIElement newChild)
  112. {
  113. AnnotationPanelContainer.Child = newChild;
  114. }
  115. private void ExpandPanel()
  116. {
  117. AnnotationPanelContainer.Visibility = Visibility.Visible;
  118. }
  119. private void ChangeAnnotationData()
  120. {
  121. switch (currentAnnotationType)
  122. {
  123. case CPDFAnnotationType.Highlight:
  124. case CPDFAnnotationType.Underline:
  125. case CPDFAnnotationType.Squiggly:
  126. case CPDFAnnotationType.Strikeout:
  127. (annotationPanel as CPDFMarkupUI).PropertyChanged -= CPDFAnnotationControl_PropertyChanged;
  128. (annotationPanel as CPDFMarkupUI).PropertyChanged += CPDFAnnotationControl_PropertyChanged;
  129. SetAnnotationProperty((annotationPanel as CPDFMarkupUI).GetMarkupData());
  130. break;
  131. case CPDFAnnotationType.Square:
  132. case CPDFAnnotationType.Circle:
  133. case CPDFAnnotationType.Line:
  134. case CPDFAnnotationType.Arrow:
  135. (annotationPanel as CPDFShapeUI).PropertyChanged -= CPDFAnnotationControl_PropertyChanged;
  136. (annotationPanel as CPDFShapeUI).PropertyChanged += CPDFAnnotationControl_PropertyChanged;
  137. SetAnnotationProperty((annotationPanel as CPDFShapeUI).GetShapeData());
  138. break;
  139. case CPDFAnnotationType.Note:
  140. (annotationPanel as CPDFNoteUI).PropertyChanged -= CPDFAnnotationControl_PropertyChanged;
  141. (annotationPanel as CPDFNoteUI).PropertyChanged += CPDFAnnotationControl_PropertyChanged;
  142. SetAnnotationProperty((annotationPanel as CPDFNoteUI).GetNoteData());
  143. break;
  144. case CPDFAnnotationType.Freehand:
  145. (annotationPanel as CPDFFreehandUI).PropertyChanged -= CPDFAnnotationControl_PropertyChanged;
  146. (annotationPanel as CPDFFreehandUI).PropertyChanged += CPDFAnnotationControl_PropertyChanged;
  147. SetAnnotationProperty((annotationPanel as CPDFFreehandUI).GetFreehandData());
  148. break;
  149. case CPDFAnnotationType.FreeText:
  150. (annotationPanel as CPDFFreeTextUI).PropertyChanged -= CPDFAnnotationControl_PropertyChanged;
  151. (annotationPanel as CPDFFreeTextUI).PropertyChanged += CPDFAnnotationControl_PropertyChanged;
  152. SetAnnotationProperty((annotationPanel as CPDFFreeTextUI).GetFreeTextData());
  153. break;
  154. case CPDFAnnotationType.Stamp:
  155. (annotationPanel as CPDFStampUI).PropertyChanged -= CPDFAnnotationControl_PropertyChanged;
  156. (annotationPanel as CPDFStampUI).PropertyChanged += CPDFAnnotationControl_PropertyChanged;
  157. break;
  158. case CPDFAnnotationType.Signature:
  159. (annotationPanel as CPDFSignatureUI).PropertyChanged -= CPDFAnnotationControl_PropertyChanged;
  160. (annotationPanel as CPDFSignatureUI).PropertyChanged += CPDFAnnotationControl_PropertyChanged;
  161. break;
  162. default:
  163. break;
  164. }
  165. }
  166. private void SetAnnotationProperty(CPDFAnnotationData pdfAnnotationData = null)
  167. {
  168. if (pdfAnnotationData == null)
  169. {
  170. pdfViewerControl.SetToolType(ToolType.Pan);
  171. pdfViewerControl.SetIsShowStampMouse(false);
  172. pdfViewerControl.SetIsVisibleCustomMouse(false);
  173. return;
  174. }
  175. CPDFAnnotationType annotationType = pdfAnnotationData.AnnotationType;
  176. AnnotParam annotHandlerEventArgs = null;
  177. pdfViewerControl.SetToolType(ToolType.CreateAnnot);
  178. switch (annotationType)
  179. {
  180. case CPDFAnnotationType.Highlight:
  181. {
  182. CPDFMarkupData highlightData = pdfAnnotationData as CPDFMarkupData;
  183. annotHandlerEventArgs = new HighlightParam();
  184. byte[] Color = new byte[] { highlightData.Color.R, highlightData.Color.G, highlightData.Color.B };
  185. annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT;
  186. (annotHandlerEventArgs as HighlightParam).HighlightColor = Color;
  187. (annotHandlerEventArgs as HighlightParam).Transparency = Convert.ToByte(highlightData.Opacity * 255);
  188. (annotHandlerEventArgs as HighlightParam).Content = highlightData.Note;
  189. (annotHandlerEventArgs as HighlightParam).Author = CPDFMarkupData.Author;
  190. (annotHandlerEventArgs as HighlightParam).Locked = highlightData.IsLocked;
  191. pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT);
  192. }
  193. break;
  194. case CPDFAnnotationType.Underline:
  195. {
  196. CPDFMarkupData underlineData = pdfAnnotationData as CPDFMarkupData;
  197. annotHandlerEventArgs = new UnderlineParam();
  198. byte[] Color = new byte[] { underlineData.Color.R, underlineData.Color.G, underlineData.Color.B };
  199. annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE;
  200. (annotHandlerEventArgs as UnderlineParam).UnderlineColor = Color;
  201. (annotHandlerEventArgs as UnderlineParam).Transparency = Convert.ToByte(underlineData.Opacity * 255);
  202. (annotHandlerEventArgs as UnderlineParam).Author = CPDFMarkupData.Author;
  203. (annotHandlerEventArgs as UnderlineParam).Content = underlineData.Note;
  204. (annotHandlerEventArgs as UnderlineParam).Locked = underlineData.IsLocked;
  205. pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE);
  206. }
  207. break;
  208. case CPDFAnnotationType.Strikeout:
  209. {
  210. CPDFMarkupData strikeoutData = pdfAnnotationData as CPDFMarkupData;
  211. annotHandlerEventArgs = new StrikeoutParam();
  212. byte[] Color = new byte[] { strikeoutData.Color.R, strikeoutData.Color.G, strikeoutData.Color.B };
  213. annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT;
  214. (annotHandlerEventArgs as StrikeoutParam).StrikeoutColor = Color;
  215. (annotHandlerEventArgs as StrikeoutParam).Transparency = Convert.ToByte(strikeoutData.Opacity * 255);
  216. (annotHandlerEventArgs as StrikeoutParam).Locked = strikeoutData.IsLocked;
  217. (annotHandlerEventArgs as StrikeoutParam).Author = CPDFMarkupData.Author;
  218. (annotHandlerEventArgs as StrikeoutParam).Content = strikeoutData.Note;
  219. pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT);
  220. }
  221. break;
  222. case CPDFAnnotationType.Squiggly:
  223. {
  224. CPDFMarkupData squigglyData = pdfAnnotationData as CPDFMarkupData;
  225. annotHandlerEventArgs = new SquigglyParam();
  226. byte[] Color = new byte[] { squigglyData.Color.R, squigglyData.Color.G, squigglyData.Color.B };
  227. annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY;
  228. (annotHandlerEventArgs as SquigglyParam).SquigglyColor = Color;
  229. (annotHandlerEventArgs as SquigglyParam).Transparency = Convert.ToByte(squigglyData.Opacity * 255);
  230. (annotHandlerEventArgs as SquigglyParam).Locked = squigglyData.IsLocked;
  231. (annotHandlerEventArgs as SquigglyParam).Author = CPDFMarkupData.Author;
  232. (annotHandlerEventArgs as SquigglyParam).Content = squigglyData.Note;
  233. pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY);
  234. }
  235. break;
  236. case CPDFAnnotationType.Square:
  237. {
  238. CPDFShapeData squareData = pdfAnnotationData as CPDFShapeData;
  239. annotHandlerEventArgs = new SquareParam();
  240. annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE;
  241. byte[] LineColor = new byte[] { squareData.BorderColor.R, squareData.BorderColor.G, squareData.BorderColor.B };
  242. (annotHandlerEventArgs as SquareParam).LineColor = LineColor;
  243. if (squareData.FillColor != Colors.Transparent)
  244. {
  245. byte[] FillColor = new byte[] { squareData.FillColor.R, squareData.FillColor.G, squareData.FillColor.B };
  246. (annotHandlerEventArgs as SquareParam).BgColor = FillColor;
  247. (annotHandlerEventArgs as SquareParam).HasBgColor = true;
  248. }
  249. (annotHandlerEventArgs as SquareParam).LineWidth = squareData.Thickness;
  250. (annotHandlerEventArgs as SquareParam).Transparency = Convert.ToByte(squareData.Opacity * 255);
  251. ParamConverter.ParseDashStyle(squareData.DashStyle, out float[] LineDash, out C_BORDER_STYLE BorderStyle);
  252. (annotHandlerEventArgs as SquareParam).LineDash = LineDash;
  253. (annotHandlerEventArgs as SquareParam).BorderStyle = BorderStyle;
  254. (annotHandlerEventArgs as SquareParam).Author = CPDFMarkupData.Author;
  255. (annotHandlerEventArgs as SquareParam).Content = squareData.Note;
  256. pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE);
  257. }
  258. break;
  259. case CPDFAnnotationType.Circle:
  260. {
  261. CPDFShapeData cicleData = pdfAnnotationData as CPDFShapeData;
  262. annotHandlerEventArgs = new CircleParam();
  263. annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE;
  264. byte[] LineColor = new byte[] { cicleData.BorderColor.R, cicleData.BorderColor.G, cicleData.BorderColor.B };
  265. (annotHandlerEventArgs as CircleParam).LineColor = LineColor;
  266. if (cicleData.FillColor != Colors.Transparent)
  267. {
  268. byte[] BgColor = new byte[] { cicleData.FillColor.R, cicleData.FillColor.G, cicleData.FillColor.B };
  269. (annotHandlerEventArgs as CircleParam).BgColor = BgColor;
  270. (annotHandlerEventArgs as CircleParam).HasBgColor = true;
  271. }
  272. (annotHandlerEventArgs as CircleParam).LineWidth = cicleData.Thickness;
  273. (annotHandlerEventArgs as CircleParam).Transparency = Convert.ToByte(cicleData.Opacity * 255);
  274. ParamConverter.ParseDashStyle(cicleData.DashStyle, out float[] LineDash, out C_BORDER_STYLE BorderStyle);
  275. (annotHandlerEventArgs as CircleParam).LineDash = LineDash;
  276. (annotHandlerEventArgs as CircleParam).BorderStyle = BorderStyle;
  277. (annotHandlerEventArgs as CircleParam).Author = CPDFMarkupData.Author;
  278. (annotHandlerEventArgs as CircleParam).Content = cicleData.Note;
  279. pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE);
  280. }
  281. break;
  282. case CPDFAnnotationType.Arrow:
  283. case CPDFAnnotationType.Line:
  284. {
  285. CPDFLineShapeData lineData = pdfAnnotationData as CPDFLineShapeData;
  286. annotHandlerEventArgs = new LineParam();
  287. annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_LINE;
  288. byte[] LineColor = new byte[] { lineData.BorderColor.R, lineData.BorderColor.G, lineData.BorderColor.B };
  289. (annotHandlerEventArgs as LineParam).LineColor = LineColor;
  290. (annotHandlerEventArgs as LineParam).LineWidth = lineData.Thickness;
  291. (annotHandlerEventArgs as LineParam).Transparency = Convert.ToByte(lineData.Opacity * 255);
  292. ParamConverter.ParseDashStyle(lineData.DashStyle, out float[] LineDash, out C_BORDER_STYLE BorderStyle);
  293. (annotHandlerEventArgs as LineParam).LineDash = LineDash;
  294. (annotHandlerEventArgs as LineParam).BorderStyle = BorderStyle;
  295. (annotHandlerEventArgs as LineParam).HeadLineType = lineData.LineType.HeadLineType;
  296. (annotHandlerEventArgs as LineParam).TailLineType = lineData.LineType.TailLineType;
  297. (annotHandlerEventArgs as LineParam).Author = CPDFMarkupData.Author;
  298. (annotHandlerEventArgs as LineParam).Content = lineData.Note;
  299. pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_LINE);
  300. }
  301. break;
  302. case CPDFAnnotationType.Note:
  303. {
  304. CPDFNoteData noteData = pdfAnnotationData as CPDFNoteData;
  305. annotHandlerEventArgs = new StickyNoteParam();
  306. annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_TEXT;
  307. byte[] StickyNoteColor = new byte[] { noteData.BorderColor.R, noteData.BorderColor.G, noteData.BorderColor.B };
  308. (annotHandlerEventArgs as StickyNoteParam).StickyNoteColor = StickyNoteColor;
  309. (annotHandlerEventArgs as StickyNoteParam).Content = noteData.Note;
  310. (annotHandlerEventArgs as StickyNoteParam).Transparency = 255;
  311. (annotHandlerEventArgs as StickyNoteParam).Author = CPDFMarkupData.Author;
  312. pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_TEXT);
  313. }
  314. break;
  315. case CPDFAnnotationType.Freehand:
  316. {
  317. CPDFFreehandData freehandData = pdfAnnotationData as CPDFFreehandData;
  318. annotHandlerEventArgs = new InkParam();
  319. annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_INK;
  320. byte[] LineColor = new byte[] { freehandData.BorderColor.R, freehandData.BorderColor.G, freehandData.BorderColor.B };
  321. (annotHandlerEventArgs as InkParam).InkColor = LineColor;
  322. (annotHandlerEventArgs as InkParam).Thickness = freehandData.Thickness;
  323. (annotHandlerEventArgs as InkParam).Transparency = Convert.ToByte(freehandData.Opacity * 255);
  324. (annotHandlerEventArgs as InkParam).Content = freehandData.Note;
  325. (annotHandlerEventArgs as InkParam).Author = CPDFMarkupData.Author;
  326. pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_INK);
  327. }
  328. break;
  329. case CPDFAnnotationType.FreeText:
  330. {
  331. CPDFFreeTextData freeTextData = pdfAnnotationData as CPDFFreeTextData;
  332. annotHandlerEventArgs = new FreeTextParam();
  333. annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT;
  334. (annotHandlerEventArgs as FreeTextParam).Transparency = Convert.ToByte(freeTextData.Opacity * 255);
  335. (annotHandlerEventArgs as FreeTextParam).FontName = freeTextData.FontFamily.ToString();
  336. byte[] FontColor = new byte[] { freeTextData.BorderColor.R, freeTextData.BorderColor.G, freeTextData.BorderColor.B };
  337. (annotHandlerEventArgs as FreeTextParam).FontColor = FontColor;
  338. (annotHandlerEventArgs as FreeTextParam).FontSize = freeTextData.FontSize;
  339. string postScriptName = string.Empty;
  340. CPDFFont.GetPostScriptName(pdfFreeTextUI.CPDFFontControl.FontFamilyValue, pdfFreeTextUI.CPDFFontControl.FontStyleValue, ref postScriptName);
  341. (annotHandlerEventArgs as FreeTextParam).FontName = postScriptName;
  342. switch (freeTextData.TextAlignment)
  343. {
  344. case TextAlignment.Left:
  345. (annotHandlerEventArgs as FreeTextParam).Alignment = C_TEXT_ALIGNMENT.ALIGNMENT_LEFT;
  346. break;
  347. case TextAlignment.Right:
  348. (annotHandlerEventArgs as FreeTextParam).Alignment = C_TEXT_ALIGNMENT.ALIGNMENT_RIGHT;
  349. break;
  350. case TextAlignment.Center:
  351. (annotHandlerEventArgs as FreeTextParam).Alignment = C_TEXT_ALIGNMENT.ALIGNMENT_CENTER;
  352. break;
  353. default:
  354. break;
  355. }
  356. (annotHandlerEventArgs as FreeTextParam).Content = freeTextData.Note;
  357. (annotHandlerEventArgs as FreeTextParam).Author = CPDFMarkupData.Author;
  358. pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT);
  359. }
  360. break;
  361. case CPDFAnnotationType.Stamp:
  362. {
  363. StampParam stampParam = new StampParam();
  364. stampParam.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_STAMP;
  365. CPDFStampData stampData = pdfAnnotationData as CPDFStampData;
  366. SetStamp(ref stampParam, stampData);
  367. annotHandlerEventArgs = stampParam;
  368. pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_STAMP);
  369. byte[] imageData = null;
  370. int imageWidth = 0;
  371. int imageHeight = 0;
  372. PDFHelp.ImageStreamToByte(stampParam.ImageStream, ref imageData, ref imageWidth, ref imageHeight);
  373. if (imageData != null && imageWidth > 0 && imageHeight > 0)
  374. {
  375. pdfViewerControl.SetStampMouseImage(imageData, imageWidth, imageHeight);
  376. }
  377. pdfViewerControl.SetIsVisibleCustomMouse(true);
  378. pdfViewerControl.SetIsShowStampMouse(true);
  379. }
  380. break;
  381. case CPDFAnnotationType.Signature:
  382. {
  383. AnnotParam signatureParam = new AnnotParam();
  384. CPDFSignatureData SignatureData = pdfAnnotationData as CPDFSignatureData;
  385. SetSignature(ref signatureParam, SignatureData);
  386. switch (signatureParam.CurrentType)
  387. {
  388. case C_ANNOTATION_TYPE.C_ANNOTATION_STAMP:
  389. {
  390. StampParam stampParam = (StampParam)signatureParam;
  391. stampParam.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_STAMP;
  392. byte[] imageData = null;
  393. int imageWidth = 0;
  394. int imageHeight = 0;
  395. PDFHelp.ImageStreamToByte(stampParam.ImageStream, ref imageData, ref imageWidth, ref imageHeight);
  396. if (imageData != null && imageWidth > 0 && imageHeight > 0)
  397. {
  398. pdfViewerControl.SetStampMouseImage(imageData, imageWidth, imageHeight);
  399. pdfViewerControl.SetIsVisibleCustomMouse(true);
  400. pdfViewerControl.SetIsShowStampMouse(true);
  401. annotHandlerEventArgs = signatureParam;
  402. }
  403. }
  404. break;
  405. case C_ANNOTATION_TYPE.C_ANNOTATION_INK:
  406. {
  407. WriteableBitmap writeableBitmap = CreateInkImage(signatureParam as InkParam);
  408. byte[] imageArray = new byte[writeableBitmap.PixelWidth * writeableBitmap.PixelHeight * 4];
  409. writeableBitmap.CopyPixels(imageArray, writeableBitmap.PixelWidth * 4, 0);
  410. pdfViewerControl.SetStampMouseImage(imageArray, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight);
  411. pdfViewerControl.SetIsVisibleCustomMouse(true);
  412. pdfViewerControl.SetIsShowStampMouse(true);
  413. annotHandlerEventArgs = signatureParam;
  414. }
  415. break;
  416. default:
  417. return;
  418. }
  419. }
  420. break;
  421. case CPDFAnnotationType.Link:
  422. if (annotHandlerEventArgs != null)
  423. {
  424. annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_LINK;
  425. pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_LINK);
  426. }
  427. break;
  428. case CPDFAnnotationType.Unknown:
  429. pdfViewerControl.SetToolType(ToolType.Pan);
  430. return;
  431. default:
  432. break;
  433. }
  434. pdfViewerControl.SetToolType(ToolType.CreateAnnot);
  435. if (annotationType != CPDFAnnotationType.Stamp && annotationType != CPDFAnnotationType.Signature && annotationType != CPDFAnnotationType.Image)
  436. {
  437. pdfViewerControl.SetIsShowStampMouse(false);
  438. }
  439. pdfViewerControl.SetAnnotParam(annotHandlerEventArgs);
  440. }
  441. private WriteableBitmap CreateInkImage(InkParam inkParam)
  442. {
  443. if (inkParam == null)
  444. {
  445. return null;
  446. }
  447. if (inkParam.InkPath != null && inkParam.InkPath.Count > 0)
  448. {
  449. GeometryGroup PaintGeomtry = new GeometryGroup();
  450. int minLeft = -1;
  451. int minTop = -1;
  452. int maxLeft = -1;
  453. int maxTop = -1;
  454. foreach (List<CPoint> Item in inkParam.InkPath)
  455. {
  456. for (int i = 0; i < Item.Count; i++)
  457. {
  458. CPoint paintPoint = Item[i];
  459. if (minLeft == -1)
  460. {
  461. minLeft = (int)paintPoint.x;
  462. maxLeft = (int)paintPoint.x;
  463. minTop = (int)paintPoint.y;
  464. maxTop = (int)paintPoint.y;
  465. }
  466. else
  467. {
  468. minLeft = (int)Math.Min(minLeft, paintPoint.x);
  469. maxLeft = (int)Math.Max(maxLeft, paintPoint.x);
  470. minTop = (int)Math.Min(minTop, paintPoint.y);
  471. maxTop = (int)Math.Max(maxTop, paintPoint.y);
  472. }
  473. }
  474. }
  475. if (minLeft >= 0 && maxLeft > minLeft && minTop >= 0 && maxTop > minTop)
  476. {
  477. List<List<CPoint>> points = new List<List<CPoint>>();
  478. foreach (List<CPoint> Item in inkParam.InkPath)
  479. {
  480. PathGeometry PaintPath = new PathGeometry();
  481. PathFigureCollection Figures = new PathFigureCollection();
  482. PathFigure AddFigure = new PathFigure();
  483. Figures.Add(AddFigure);
  484. PaintPath.Figures = Figures;
  485. PaintGeomtry.Children.Add(PaintPath);
  486. List<CPoint> changeList = new List<CPoint>();
  487. for (int i = 0; i < Item.Count; i++)
  488. {
  489. Point paintPoint = new Point(DpiHelper.PDFNumToStandardNum(Item[i].x - minLeft), DpiHelper.PDFNumToStandardNum(Item[i].y - minTop));
  490. changeList.Add(DataConversionForWPF.PointConversionForCPoint(DpiHelper.StandardPointToPDFPoint(paintPoint)));
  491. if (i == 0)
  492. {
  493. AddFigure.StartPoint = paintPoint;
  494. }
  495. else
  496. {
  497. LineSegment AddSegment = new LineSegment();
  498. AddSegment.Point = paintPoint;
  499. AddFigure.Segments.Add(AddSegment);
  500. }
  501. }
  502. if (changeList.Count > 0)
  503. {
  504. points.Add(changeList);
  505. }
  506. }
  507. int drawWidth = (int)DpiHelper.PDFNumToStandardNum(maxLeft - minLeft);
  508. int drawHeight = (int)DpiHelper.PDFNumToStandardNum(maxTop - minTop);
  509. inkParam.InkPath = points;
  510. DefaultSettingParam defaultSettingParam = pdfViewerControl.PDFViewTool.GetDefaultSettingParam();
  511. defaultSettingParam.SetAnnotParam(inkParam);
  512. DrawingVisual copyVisual = new DrawingVisual();
  513. DrawingContext copyContext = copyVisual.RenderOpen();
  514. Color color = ParamConverter.ConverterByteForColor(inkParam.InkColor);
  515. color.A = inkParam.Transparency;
  516. Pen drawPen = new Pen(new SolidColorBrush(color), inkParam.Thickness);
  517. copyContext?.DrawGeometry(null, drawPen, PaintGeomtry);
  518. copyContext.Close();
  519. RenderTargetBitmap targetBitmap = new RenderTargetBitmap(drawWidth, drawHeight, 96, 96, PixelFormats.Pbgra32);
  520. targetBitmap.Render(copyVisual);
  521. byte[] ImageArray = new byte[targetBitmap.PixelWidth * targetBitmap.PixelHeight * 4];
  522. targetBitmap.CopyPixels(new Int32Rect(0, 0, (int)targetBitmap.PixelWidth, (int)targetBitmap.PixelHeight), ImageArray, targetBitmap.PixelWidth * 4, 0);
  523. WriteableBitmap writeBitmap = new WriteableBitmap(targetBitmap.PixelWidth, targetBitmap.PixelHeight, 96, 96, PixelFormats.Bgra32, null);
  524. writeBitmap.WritePixels(new Int32Rect(0, 0, targetBitmap.PixelWidth, targetBitmap.PixelHeight), ImageArray, targetBitmap.PixelWidth * 4, 0);
  525. return writeBitmap;
  526. }
  527. }
  528. return null;
  529. }
  530. public void SetSignature(ref AnnotParam annotParam, CPDFSignatureData stamp)
  531. {
  532. switch (stamp.Type)
  533. {
  534. case SignatureType.TextType:
  535. case SignatureType.ImageType:
  536. {
  537. annotParam = new StampParam();
  538. annotParam.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_STAMP;
  539. (annotParam as StampParam).Transparency = 255;
  540. (annotParam as StampParam).StampType = C_STAMP_TYPE.IMAGE_STAMP;
  541. if (!string.IsNullOrEmpty(stamp.SourcePath))
  542. {
  543. BitmapImage image = new BitmapImage(new Uri(stamp.SourcePath));
  544. PngBitmapEncoder encoder = new PngBitmapEncoder();
  545. encoder.Frames.Add(BitmapFrame.Create(image));
  546. MemoryStream memoryStream = new MemoryStream();
  547. encoder.Save(memoryStream);
  548. (annotParam as StampParam).ImageStream = memoryStream;
  549. }
  550. pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_STAMP);
  551. }
  552. break;
  553. case SignatureType.Drawing:
  554. {
  555. annotParam = new InkParam();
  556. (annotParam as InkParam).Transparency = stamp.inkColor.A;
  557. annotParam.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_INK;
  558. List<List<Point>> RawPointList = GetPoints(stamp.DrawingPath);
  559. if (RawPointList != null && RawPointList.Count > 0)
  560. {
  561. List<List<CPoint>> inkPath = new List<List<CPoint>>();
  562. foreach (List<Point> inkPoints in RawPointList)
  563. {
  564. List<CPoint> ink = new List<CPoint>();
  565. foreach (Point point in inkPoints)
  566. {
  567. ink.Add(new CPoint((float)DpiHelper.StandardNumToPDFNum(point.X), (float)DpiHelper.StandardNumToPDFNum(point.Y)));
  568. }
  569. if (ink.Count > 0)
  570. {
  571. inkPath.Add(ink);
  572. }
  573. }
  574. if (inkPath.Count > 0)
  575. {
  576. (annotParam as InkParam).InkPath = inkPath;
  577. }
  578. }
  579. (annotParam as InkParam).Thickness = stamp.inkThickness;
  580. byte[] InkColor = new byte[] { stamp.inkColor.R, stamp.inkColor.G, stamp.inkColor.B };
  581. (annotParam as InkParam).InkColor = InkColor;
  582. pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_INK);
  583. }
  584. break;
  585. default:
  586. break;
  587. }
  588. }
  589. private List<List<Point>> GetPoints(string Path)
  590. {
  591. StrokeCollection Strokes;
  592. List<List<Point>> RawPointList = new List<List<Point>>();
  593. using (FileStream strokeStream = File.OpenRead(Path))
  594. {
  595. Strokes = new StrokeCollection(strokeStream);
  596. }
  597. for (int kk = 0; kk < Strokes.Count; kk++)
  598. {
  599. List<Point> p = new List<Point>();
  600. RawPointList.Add(p);
  601. for (int gg = 0; gg < Strokes[kk].StylusPoints.Count; gg++)
  602. {
  603. var point = Strokes[kk].StylusPoints[gg].ToPoint();
  604. if (point.X >= 0 && point.Y >= 0)
  605. RawPointList[kk].Add(point);
  606. }
  607. }
  608. return RawPointList;
  609. }
  610. private void SetStamp(ref StampParam stampParam, CPDFStampData stamp)
  611. {
  612. stampParam.StampText = stamp.StampText;
  613. stampParam.Author = CPDFMarkupData.Author;
  614. stampParam.Transparency = Convert.ToByte(stamp.Opacity * 255);
  615. stampParam.DateText = stamp.StampTextDate;
  616. stampParam.TextStampColor = stamp.TextColor;
  617. stampParam.TextStampShape = stamp.TextSharp;
  618. if (!string.IsNullOrEmpty(stamp.SourcePath))
  619. {
  620. BitmapImage image = new BitmapImage(new Uri(stamp.SourcePath));
  621. PngBitmapEncoder encoder = new PngBitmapEncoder();
  622. encoder.Frames.Add(BitmapFrame.Create(image));
  623. MemoryStream memoryStream = new MemoryStream();
  624. encoder.Save(memoryStream);
  625. stampParam.ImageStream = memoryStream;
  626. }
  627. else
  628. {
  629. var i = pdfStampUI.CustomStampList.IndexOf(stamp);
  630. Settings.Default.CustomStampList.RemoveAt(i);
  631. Settings.Default.Save();
  632. pdfStampUI.LoadSettings();
  633. return;
  634. }
  635. stampParam.StampType = stamp.Type;
  636. }
  637. public void AnnotationCancel()
  638. {
  639. this.pdfViewerControl.SetToolType(ToolType.Pan);
  640. pdfViewerControl.SetIsShowStampMouse(false);
  641. pdfViewerControl.SetIsVisibleCustomMouse(false);
  642. ClearPanel();
  643. }
  644. private void CPDFAnnotationControl_PropertyChanged(object sender, CPDFAnnotationData e)
  645. {
  646. SetAnnotationProperty(e);
  647. }
  648. public void InitAnnotationPanel(CPDFAnnotationType annotationType)
  649. {
  650. switch (annotationType)
  651. {
  652. case CPDFAnnotationType.Highlight:
  653. if (pdfHighlightUI == null)
  654. {
  655. pdfHighlightUI = new CPDFMarkupUI();
  656. }
  657. annotationPanel = pdfHighlightUI;
  658. (annotationPanel as CPDFMarkupUI).InitWithAnnotationType(annotationType);
  659. break;
  660. case CPDFAnnotationType.Underline:
  661. if (pdfUnderlineUI == null)
  662. {
  663. pdfUnderlineUI = new CPDFMarkupUI();
  664. }
  665. annotationPanel = pdfUnderlineUI;
  666. (annotationPanel as CPDFMarkupUI).InitWithAnnotationType(annotationType);
  667. break;
  668. case CPDFAnnotationType.Strikeout:
  669. if (pdfStrikeoutUI == null)
  670. {
  671. pdfStrikeoutUI = new CPDFMarkupUI();
  672. }
  673. annotationPanel = pdfStrikeoutUI;
  674. (annotationPanel as CPDFMarkupUI).InitWithAnnotationType(annotationType);
  675. break;
  676. case CPDFAnnotationType.Squiggly:
  677. if (pdfSquigglyUI == null)
  678. {
  679. pdfSquigglyUI = new CPDFMarkupUI();
  680. }
  681. annotationPanel = pdfSquigglyUI;
  682. (annotationPanel as CPDFMarkupUI).InitWithAnnotationType(annotationType);
  683. break;
  684. case CPDFAnnotationType.Square:
  685. if (pdfSquareUI == null)
  686. {
  687. pdfSquareUI = new CPDFShapeUI();
  688. }
  689. annotationPanel = pdfSquareUI;
  690. (annotationPanel as CPDFShapeUI).InitWithAnnotationType(annotationType);
  691. break;
  692. case CPDFAnnotationType.Circle:
  693. if (pdfCircleUI == null)
  694. {
  695. pdfCircleUI = new CPDFShapeUI();
  696. }
  697. annotationPanel = pdfCircleUI;
  698. (annotationPanel as CPDFShapeUI).InitWithAnnotationType(annotationType);
  699. break;
  700. case CPDFAnnotationType.Arrow:
  701. if (pdfArrowUI == null)
  702. {
  703. pdfArrowUI = new CPDFShapeUI();
  704. }
  705. annotationPanel = pdfArrowUI;
  706. (annotationPanel as CPDFShapeUI).InitWithAnnotationType(annotationType);
  707. break;
  708. case CPDFAnnotationType.Line:
  709. if (pdfLineUI == null)
  710. {
  711. pdfLineUI = new CPDFShapeUI();
  712. }
  713. annotationPanel = pdfLineUI;
  714. (annotationPanel as CPDFShapeUI).InitWithAnnotationType(annotationType);
  715. break;
  716. case CPDFAnnotationType.Freehand:
  717. if (pdfFreehandUI == null)
  718. {
  719. pdfFreehandUI = new CPDFFreehandUI();
  720. pdfFreehandUI.EraseClickHandler -= PdfFreehandUI_EraseClickHandler;
  721. pdfFreehandUI.EraseChangeHandler -= PdfFreehandUI_EraseChangeHandler;
  722. pdfFreehandUI.EraseClickHandler += PdfFreehandUI_EraseClickHandler;
  723. pdfFreehandUI.EraseChangeHandler += PdfFreehandUI_EraseChangeHandler;
  724. }
  725. annotationPanel = pdfFreehandUI;
  726. break;
  727. case CPDFAnnotationType.FreeText:
  728. if (pdfFreeTextUI == null)
  729. {
  730. pdfFreeTextUI = new CPDFFreeTextUI();
  731. }
  732. annotationPanel = pdfFreeTextUI;
  733. break;
  734. case CPDFAnnotationType.Note:
  735. if (pdfNoteUI == null)
  736. {
  737. pdfNoteUI = new CPDFNoteUI();
  738. }
  739. annotationPanel = pdfNoteUI;
  740. break;
  741. case CPDFAnnotationType.Stamp:
  742. if (pdfStampUI == null)
  743. {
  744. pdfStampUI = new CPDFStampUI();
  745. }
  746. annotationPanel = pdfStampUI;
  747. break;
  748. case CPDFAnnotationType.Signature:
  749. if (pdfSignatureUI == null)
  750. {
  751. pdfSignatureUI = new CPDFSignatureUI();
  752. }
  753. annotationPanel = pdfSignatureUI;
  754. break;
  755. case CPDFAnnotationType.Link:
  756. if (pdfLinkUI == null)
  757. {
  758. pdfLinkUI = new CPDFLinkUI();
  759. }
  760. LinkParam linkAnnotArgs = new LinkParam();
  761. if (this.pdfViewerControl != null && pdfViewerControl.PDFViewTool != null && pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument() != null)
  762. {
  763. pdfViewerControl.SetToolType(ToolType.CreateAnnot);
  764. pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_LINK);
  765. pdfLinkUI.InitLinkAnnotArgs(linkAnnotArgs, pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument().PageCount);
  766. }
  767. annotationPanel = pdfLinkUI;
  768. break;
  769. case CPDFAnnotationType.Audio:
  770. SoundParam soundParam = new SoundParam();
  771. soundParam.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_SOUND;
  772. OpenFileDialog openAudioDialog = new OpenFileDialog();
  773. openAudioDialog.Filter = "Wave Files(*.wav)|*.wav|All Files(*.*;)|*.*;";
  774. if (openAudioDialog.ShowDialog() == true)
  775. {
  776. BitmapImage img = new BitmapImage(new Uri("pack://application:,,,/Compdfkit_Tools;component/Asset/Resource/SoundAnnot.png"));
  777. PngBitmapEncoder encoder = new PngBitmapEncoder();
  778. encoder.Frames.Add(BitmapFrame.Create(img));
  779. MemoryStream memoryStream = new MemoryStream();
  780. encoder.Save(memoryStream);
  781. soundParam.ImageStream = memoryStream;
  782. soundParam.SoundFilePath = openAudioDialog.FileName;
  783. pdfViewerControl.SetToolType(ToolType.CreateAnnot);
  784. pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_SOUND);
  785. pdfViewerControl.SetAnnotParam(soundParam);
  786. }
  787. else
  788. {
  789. pdfViewerControl.SetToolType(ToolType.Pan);
  790. ClearAnnotationBar?.Invoke(this, EventArgs.Empty);
  791. }
  792. ClearPanel();
  793. break;
  794. case CPDFAnnotationType.Image:
  795. StampParam stampParam = new StampParam();
  796. OpenFileDialog openFileDialog = new OpenFileDialog();
  797. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  798. if (openFileDialog.ShowDialog() == true)
  799. {
  800. try
  801. {
  802. using (FileStream stream = new FileStream(openFileDialog.FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
  803. {
  804. PngBitmapEncoder encoder = new PngBitmapEncoder();
  805. encoder.Frames.Add(BitmapFrame.Create(stream, BitmapCreateOptions.DelayCreation, BitmapCacheOption.None));
  806. MemoryStream memoryStream = new MemoryStream();
  807. encoder.Save(memoryStream);
  808. stampParam.ImageStream = memoryStream;
  809. stampParam.Transparency = 255;
  810. stampParam.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_STAMP;
  811. stampParam.StampType = C_STAMP_TYPE.IMAGE_STAMP;
  812. BitmapFrame frame = null;
  813. if (encoder != null && encoder.Frames.Count > 0)
  814. {
  815. frame = encoder.Frames[0];
  816. }
  817. if (frame != null)
  818. {
  819. byte[] imageArray = new byte[frame.PixelWidth * frame.PixelHeight * 4];
  820. if (frame.Format != PixelFormats.Bgra32)
  821. {
  822. FormatConvertedBitmap covert = new FormatConvertedBitmap(
  823. frame,
  824. PixelFormats.Bgra32,
  825. frame.Palette,
  826. 0);
  827. covert.CopyPixels(imageArray, frame.PixelWidth * 4, 0);
  828. }
  829. else
  830. {
  831. frame.CopyPixels(imageArray, frame.PixelWidth * 4, 0);
  832. }
  833. pdfViewerControl.SetStampMouseImage(imageArray, frame.PixelWidth, frame.PixelHeight);
  834. }
  835. pdfViewerControl.SetToolType(ToolType.CreateAnnot);
  836. pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_STAMP);
  837. pdfViewerControl.SetIsVisibleCustomMouse(true);
  838. pdfViewerControl.SetIsShowStampMouse(true);
  839. pdfViewerControl.SetAnnotParam(stampParam);
  840. }
  841. }
  842. catch
  843. {
  844. }
  845. }
  846. else
  847. {
  848. pdfViewerControl.SetToolType(ToolType.Pan);
  849. ClearAnnotationBar?.Invoke(this, EventArgs.Empty);
  850. }
  851. ClearPanel();
  852. break;
  853. default:
  854. break;
  855. }
  856. }
  857. private void PdfFreehandUI_EraseChangeHandler(object sender, double e)
  858. {
  859. if (pdfViewerControl != null)
  860. {
  861. pdfViewerControl.PDFViewTool.SetEraseZoom(e);
  862. }
  863. }
  864. private void PdfFreehandUI_EraseClickHandler(object sender, bool e)
  865. {
  866. if (e)
  867. {
  868. //pdfViewerControl.PDFToolManager.ClearSelect();
  869. pdfViewerControl.PDFViewTool.SetViewerModel(MouseModes.CustomizeTool);
  870. }
  871. else
  872. {
  873. pdfViewerControl.SetToolType(ToolType.CreateAnnot);
  874. pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_INK);
  875. }
  876. }
  877. public void CreatTempAnnotationPanel(BaseAnnot baseAnnot)
  878. {
  879. switch (baseAnnot.CurrentType)
  880. {
  881. case C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT:
  882. {
  883. tempAnnotationPanel = new CPDFMarkupUI();
  884. (tempAnnotationPanel as CPDFMarkupUI).InitWithAnnotationType(CPDFAnnotationType.Highlight);
  885. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  886. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  887. baseAnnot.GetAnnotData().PageIndex,
  888. baseAnnot.GetAnnotData().Annot);
  889. (tempAnnotationPanel as CPDFMarkupUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot as CPDFMarkupAnnotation, pdfViewerControl);
  890. }
  891. break;
  892. case C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE:
  893. {
  894. tempAnnotationPanel = new CPDFMarkupUI();
  895. (tempAnnotationPanel as CPDFMarkupUI).InitWithAnnotationType(CPDFAnnotationType.Underline);
  896. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  897. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  898. baseAnnot.GetAnnotData().PageIndex,
  899. baseAnnot.GetAnnotData().Annot);
  900. (tempAnnotationPanel as CPDFMarkupUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot as CPDFMarkupAnnotation, pdfViewerControl);
  901. }
  902. break;
  903. case C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT:
  904. {
  905. tempAnnotationPanel = new CPDFMarkupUI();
  906. (tempAnnotationPanel as CPDFMarkupUI).InitWithAnnotationType(CPDFAnnotationType.Strikeout);
  907. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  908. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  909. baseAnnot.GetAnnotData().PageIndex,
  910. baseAnnot.GetAnnotData().Annot);
  911. (tempAnnotationPanel as CPDFMarkupUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot as CPDFMarkupAnnotation, pdfViewerControl);
  912. }
  913. break;
  914. case C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY:
  915. {
  916. tempAnnotationPanel = new CPDFMarkupUI();
  917. (tempAnnotationPanel as CPDFMarkupUI).InitWithAnnotationType(CPDFAnnotationType.Squiggly);
  918. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  919. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  920. baseAnnot.GetAnnotData().PageIndex,
  921. baseAnnot.GetAnnotData().Annot);
  922. (tempAnnotationPanel as CPDFMarkupUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot as CPDFMarkupAnnotation, pdfViewerControl);
  923. }
  924. break;
  925. case C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE:
  926. {
  927. tempAnnotationPanel = new CPDFShapeUI();
  928. (tempAnnotationPanel as CPDFShapeUI).InitWithAnnotationType(CPDFAnnotationType.Square);
  929. int page = baseAnnot.GetAnnotData().PageIndex;
  930. var annot = baseAnnot.GetAnnotData().Annot;
  931. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  932. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  933. baseAnnot.GetAnnotData().PageIndex,
  934. baseAnnot.GetAnnotData().Annot);
  935. (tempAnnotationPanel as CPDFShapeUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot, pdfViewerControl);
  936. }
  937. break;
  938. case C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE:
  939. {
  940. tempAnnotationPanel = new CPDFShapeUI();
  941. (tempAnnotationPanel as CPDFShapeUI).InitWithAnnotationType(CPDFAnnotationType.Circle);
  942. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  943. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  944. baseAnnot.GetAnnotData().PageIndex,
  945. baseAnnot.GetAnnotData().Annot);
  946. (tempAnnotationPanel as CPDFShapeUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot, pdfViewerControl);
  947. }
  948. break;
  949. case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
  950. {
  951. tempAnnotationPanel = new CPDFShapeUI();
  952. (tempAnnotationPanel as CPDFShapeUI).InitWithAnnotationType(CPDFAnnotationType.Line);
  953. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  954. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  955. baseAnnot.GetAnnotData().PageIndex,
  956. baseAnnot.GetAnnotData().Annot);
  957. (tempAnnotationPanel as CPDFShapeUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot, pdfViewerControl);
  958. }
  959. break;
  960. case C_ANNOTATION_TYPE.C_ANNOTATION_INK:
  961. {
  962. CPDFFreehandUI tempFreehandPanel = new CPDFFreehandUI();
  963. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  964. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  965. baseAnnot.GetAnnotData().PageIndex,
  966. baseAnnot.GetAnnotData().Annot);
  967. tempFreehandPanel.SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot, pdfViewerControl);
  968. tempFreehandPanel.EraseClickHandler -= PdfFreehandUI_EraseClickHandler;
  969. tempFreehandPanel.EraseChangeHandler -= PdfFreehandUI_EraseChangeHandler;
  970. tempFreehandPanel.EraseClickHandler += PdfFreehandUI_EraseClickHandler;
  971. tempFreehandPanel.EraseChangeHandler += PdfFreehandUI_EraseChangeHandler;
  972. tempAnnotationPanel = tempFreehandPanel;
  973. }
  974. break;
  975. case C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT:
  976. {
  977. tempAnnotationPanel = new CPDFFreeTextUI();
  978. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  979. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  980. baseAnnot.GetAnnotData().PageIndex,
  981. baseAnnot.GetAnnotData().Annot);
  982. (tempAnnotationPanel as CPDFFreeTextUI).SetPresentAnnotAttrib(annotParam as FreeTextParam, baseAnnot.GetAnnotData().Annot as CPDFFreeTextAnnotation, pdfViewerControl);
  983. }
  984. break;
  985. case C_ANNOTATION_TYPE.C_ANNOTATION_TEXT:
  986. {
  987. tempAnnotationPanel = new CPDFNoteUI();
  988. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  989. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  990. baseAnnot.GetAnnotData().PageIndex,
  991. baseAnnot.GetAnnotData().Annot);
  992. (tempAnnotationPanel as CPDFNoteUI).SetPresentAnnotAttrib(annotParam as StickyNoteParam, baseAnnot.GetAnnotData().Annot as CPDFTextAnnotation, pdfViewerControl);
  993. }
  994. break;
  995. case C_ANNOTATION_TYPE.C_ANNOTATION_STAMP:
  996. {
  997. tempAnnotationPanel = new CPDFTempStampUI();
  998. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  999. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  1000. baseAnnot.GetAnnotData().PageIndex,
  1001. baseAnnot.GetAnnotData().Annot);
  1002. (tempAnnotationPanel as CPDFTempStampUI).SetPresentAnnotAttrib(annotParam as StampParam, baseAnnot.GetAnnotData().Annot as CPDFStampAnnotation, pdfViewerControl.PDFToolManager.GetDocument(), pdfViewerControl);
  1003. }
  1004. break;
  1005. case C_ANNOTATION_TYPE.C_ANNOTATION_LINK:
  1006. {
  1007. tempAnnotationPanel = new CPDFLinkUI();
  1008. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  1009. pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  1010. baseAnnot.GetAnnotData().PageIndex,
  1011. baseAnnot.GetAnnotData().Annot);
  1012. (tempAnnotationPanel as CPDFLinkUI).SetPresentAnnotAttrib(annotParam as LinkParam, baseAnnot.GetAnnotData().Annot as CPDFLinkAnnotation, pdfViewerControl, pdfViewerControl.PDFToolManager.GetDocument().PageCount);
  1013. }
  1014. break;
  1015. case C_ANNOTATION_TYPE.C_ANNOTATION_SOUND:
  1016. tempAnnotationPanel = null;
  1017. break;
  1018. default:
  1019. break;
  1020. }
  1021. }
  1022. public void LoadAnnotationPanel(CPDFAnnotationType annotationType)
  1023. {
  1024. this.pdfViewerControl.SetToolType(ToolType.Pan);
  1025. currentAnnotationType = annotationType;
  1026. annotationPanel = GetAnnotationPanel();
  1027. InitAnnotationPanel(annotationType);
  1028. ShowCurrentAnnotPanel();
  1029. }
  1030. private void ShowCurrentAnnotPanel()
  1031. {
  1032. if (annotationPanel != null)
  1033. {
  1034. if (annotationPanel is CPDFFreehandUI)
  1035. {
  1036. (annotationPanel as CPDFFreehandUI)?.SetEraseCheck(false);
  1037. }
  1038. SetAnnotationPanel(annotationPanel);
  1039. ExpandPanel();
  1040. ChangeAnnotationData();
  1041. EmptyMessage.Visibility = Visibility.Collapsed;
  1042. }
  1043. else
  1044. {
  1045. EmptyMessage.Visibility = Visibility.Visible;
  1046. SetAnnotationPanel(null);
  1047. if (pdfViewerControl != null)
  1048. {
  1049. EmptyMessage.Visibility = Visibility.Collapsed;
  1050. }
  1051. }
  1052. }
  1053. private void ShowTempAnnotPanel()
  1054. {
  1055. BaseAnnot baseAnnot = pdfViewerControl.GetCacheHitTestAnnot();
  1056. if (baseAnnot != null)
  1057. {
  1058. CreatTempAnnotationPanel(baseAnnot);
  1059. SetAnnotationPanel(tempAnnotationPanel);
  1060. ExpandPanel();
  1061. if (tempAnnotationPanel != null)
  1062. {
  1063. EmptyMessage.Visibility = Visibility.Collapsed;
  1064. }
  1065. else
  1066. {
  1067. EmptyMessage.Visibility = Visibility.Visible;
  1068. }
  1069. }
  1070. }
  1071. private void PDFToolManager_MouseLeftButtonDownHandler(object sender, MouseEventObject e)
  1072. {
  1073. SetAnnotEventData();
  1074. }
  1075. public void ClearPanel()
  1076. {
  1077. annotationPanel = null;
  1078. SetAnnotationPanel(annotationPanel);
  1079. EmptyMessage.Visibility = Visibility.Visible;
  1080. }
  1081. public void SetAnnotEventData()
  1082. {
  1083. if (pdfViewerControl.GetCacheHitTestAnnot() != null)
  1084. {
  1085. ShowTempAnnotPanel();
  1086. isTempPanel = true;
  1087. }
  1088. else
  1089. {
  1090. if (pdfViewerControl != null && pdfViewerControl.PDFToolManager.GetToolType() == ToolType.CreateAnnot)
  1091. {
  1092. ShowCurrentAnnotPanel();
  1093. isTempPanel = false;
  1094. }
  1095. else if (annotationPanel is CPDFStampUI && currentAnnotationType == CPDFAnnotationType.Stamp)
  1096. {
  1097. ShowCurrentAnnotPanel();
  1098. }
  1099. else if (annotationPanel is CPDFSignatureUI && currentAnnotationType == CPDFAnnotationType.Signature)
  1100. {
  1101. ShowCurrentAnnotPanel();
  1102. }
  1103. else if (disableClean == false)
  1104. {
  1105. ClearPanel();
  1106. }
  1107. }
  1108. }
  1109. }
  1110. }