CPDFAnnotationPreviewerControl.xaml.cs 8.3 KB

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