CPDFAnnotationPreviewerControl.xaml.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. using Compdfkit_Tools.Data;
  2. using System;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. using System.Windows.Media;
  6. using System.Windows.Media.Imaging;
  7. using System.Windows.Shapes;
  8. using static Compdfkit_Tools.Helper.CommonHelper;
  9. namespace Compdfkit_Tools.PDFControl
  10. {
  11. public partial class CPDFAnnotationPreviewerControl : UserControl
  12. {
  13. public CPDFAnnotationPreviewerControl()
  14. {
  15. InitializeComponent();
  16. }
  17. public void CollapsedAll()
  18. {
  19. MarkupGrid.Visibility = Visibility.Collapsed;
  20. HighlightPath.Visibility = Visibility.Collapsed;
  21. UnderlinePath.Visibility = Visibility.Collapsed;
  22. StrikeoutPath.Visibility = Visibility.Collapsed;
  23. SquigglyPath.Visibility = Visibility.Collapsed;
  24. FreehandGrid.Visibility = Visibility.Collapsed;
  25. FreeTextGrid.Visibility = Visibility.Collapsed;
  26. ShapeGrid.Visibility = Visibility.Collapsed;
  27. Ellipse.Visibility = Visibility.Collapsed;
  28. Rectangle.Visibility = Visibility.Collapsed;
  29. Line.Visibility = Visibility.Collapsed;
  30. NoteGrid.Visibility = Visibility.Collapsed;
  31. StampGrid.Visibility = Visibility.Collapsed;
  32. }
  33. public void DrawMarkUpPreview(CPDFAnnotationData annotationData)
  34. {
  35. CPDFMarkupData markupData = annotationData as CPDFMarkupData;
  36. CollapsedAll();
  37. CPDFAnnotationType annotationType = annotationData.AnnotationType;
  38. switch (annotationType)
  39. {
  40. case CPDFAnnotationType.Highlight:
  41. MarkupGrid.Visibility = Visibility.Visible;
  42. HighlightPath.Visibility = Visibility.Visible;
  43. HighlightPath.Stroke = new SolidColorBrush(markupData.Color);
  44. HighlightPath.Opacity = markupData.Opacity;
  45. break;
  46. case CPDFAnnotationType.Underline:
  47. MarkupGrid.Visibility = Visibility.Visible;
  48. UnderlinePath.Visibility = Visibility.Visible;
  49. UnderlinePath.Stroke = new SolidColorBrush(markupData.Color);
  50. UnderlinePath.Opacity = markupData.Opacity;
  51. break;
  52. case CPDFAnnotationType.Squiggly:
  53. MarkupGrid.Visibility = Visibility.Visible;
  54. SquigglyPath.Visibility = Visibility.Visible;
  55. SquigglyPath.Stroke = new SolidColorBrush(markupData.Color);
  56. SquigglyPath.Opacity = markupData.Opacity;
  57. break;
  58. case CPDFAnnotationType.Strikeout:
  59. MarkupGrid.Visibility = Visibility.Visible;
  60. StrikeoutPath.Visibility = Visibility.Visible;
  61. StrikeoutPath.Stroke = new SolidColorBrush(markupData.Color);
  62. StrikeoutPath.Opacity = markupData.Opacity;
  63. break;
  64. }
  65. }
  66. public void DrawShapePreview(CPDFAnnotationData annotationData)
  67. {
  68. CPDFAnnotationType annotationType = annotationData.AnnotationType;
  69. switch (annotationType)
  70. {
  71. case CPDFAnnotationType.Circle:
  72. CPDFShapeData circleData = annotationData as CPDFShapeData;
  73. ShapeGrid.Visibility = Visibility.Visible;
  74. Ellipse.Visibility = Visibility.Visible;
  75. Ellipse.StrokeThickness = circleData.Thickness;
  76. Ellipse.Opacity = circleData.Opacity;
  77. Ellipse.Fill = new SolidColorBrush(circleData.FillColor);
  78. Ellipse.Stroke = new SolidColorBrush(circleData.BorderColor);
  79. DashStyle circleDash = new DashStyle();
  80. if (circleData.DashStyle.Dashes.Count == 2)
  81. {
  82. circleDash.Dashes.Add(circleData.DashStyle.Dashes[0] / Math.Max(Ellipse.StrokeThickness, 1));
  83. circleDash.Dashes.Add(circleData.DashStyle.Dashes[1] / Math.Max(Ellipse.StrokeThickness, 1));
  84. }
  85. Ellipse.StrokeDashArray = circleDash.Dashes;
  86. break;
  87. case CPDFAnnotationType.Square:
  88. CPDFShapeData squareData = annotationData as CPDFShapeData;
  89. ShapeGrid.Visibility = Visibility.Visible;
  90. Rectangle.Visibility = Visibility.Visible;
  91. Rectangle.StrokeThickness = squareData.Thickness;
  92. Rectangle.Opacity = squareData.Opacity;
  93. Rectangle.Fill = new SolidColorBrush(squareData.FillColor);
  94. Rectangle.Stroke = new SolidColorBrush(squareData.BorderColor);
  95. DashStyle squareDash = new DashStyle();
  96. if (squareData.DashStyle.Dashes.Count == 2)
  97. {
  98. squareDash.Dashes.Add(squareData.DashStyle.Dashes[0] / Math.Max(Rectangle.StrokeThickness, 1));
  99. squareDash.Dashes.Add(squareData.DashStyle.Dashes[1] / Math.Max(Rectangle.StrokeThickness, 1));
  100. }
  101. Rectangle.StrokeDashArray = squareDash.Dashes;
  102. break;
  103. case CPDFAnnotationType.Line:
  104. case CPDFAnnotationType.Arrow:
  105. CPDFLineShapeData lineShapeData = annotationData as CPDFLineShapeData;
  106. ShapeGrid.Visibility = Visibility.Visible;
  107. Line.Visibility = Visibility.Visible;
  108. ArrowHelper arrowLine = new ArrowHelper();
  109. arrowLine.ArrowLength = 8;
  110. arrowLine.LineStart = new Point(20, 50);
  111. arrowLine.LineEnd = new Point(50, 20);
  112. arrowLine.StartSharp = lineShapeData.LineType.HeadLineType;
  113. arrowLine.EndSharp = lineShapeData.LineType.TailLineType;
  114. Line.Stroke = new SolidColorBrush(lineShapeData.BorderColor);
  115. Line.StrokeThickness = lineShapeData.Thickness;
  116. Line.Opacity = lineShapeData.Opacity;
  117. Line.Data = arrowLine.BuildArrowBody();
  118. DashStyle lineDash = new DashStyle();
  119. if (lineShapeData.DashStyle.Dashes.Count == 2)
  120. {
  121. lineDash.Dashes.Add(lineShapeData.DashStyle.Dashes[0] / Math.Max(Line.StrokeThickness, 1));
  122. lineDash.Dashes.Add(lineShapeData.DashStyle.Dashes[1] / Math.Max(Line.StrokeThickness, 1));
  123. }
  124. Line.StrokeDashArray = lineDash.Dashes;
  125. break;
  126. }
  127. }
  128. public void DrawFreehandPreview(CPDFAnnotationData annotationData)
  129. {
  130. CPDFFreehandData freehandData = annotationData as CPDFFreehandData;
  131. CollapsedAll();
  132. FreehandGrid.Visibility = Visibility.Visible;
  133. SharpPath.Stroke = new SolidColorBrush(freehandData.BorderColor);
  134. SharpPath.Opacity = freehandData.Opacity;
  135. SharpPath.StrokeThickness = freehandData.Thickness;
  136. }
  137. public void DrawNotePreview(CPDFAnnotationData annotationData)
  138. {
  139. CollapsedAll();
  140. NoteGrid.Visibility = Visibility.Visible;
  141. CPDFNoteData noteData = annotationData as CPDFNoteData;
  142. NotePath.Fill = new SolidColorBrush(noteData.BorderColor);
  143. }
  144. public void DrawStampPreview(WriteableBitmap writeableBitmap)
  145. {
  146. CollapsedAll();
  147. StampGrid.Visibility = Visibility.Visible;
  148. StampImage.Source = writeableBitmap;
  149. }
  150. public void DrawFreeTextPreview(CPDFFreeTextData freeTextData)
  151. {
  152. CollapsedAll();
  153. FreeTextGrid.Visibility = Visibility.Visible;
  154. FreeText.FontFamily = new FontFamily(freeTextData.FontFamily);
  155. FreeText.FontSize = freeTextData.FontSize / 1.2;
  156. FreeText.Foreground = new SolidColorBrush(freeTextData.BorderColor);
  157. FreeText.Opacity = freeTextData.Opacity;
  158. if (freeTextData.IsBold)
  159. {
  160. FreeText.FontWeight = FontWeights.Bold;
  161. }
  162. else
  163. {
  164. FreeText.FontWeight = FontWeights.Medium;
  165. }
  166. if (freeTextData.IsItalic)
  167. {
  168. FreeText.FontStyle = FontStyles.Italic;
  169. }
  170. else
  171. {
  172. FreeText.FontStyle = FontStyles.Normal;
  173. }
  174. }
  175. }
  176. }