CPDFAnnotationData.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. using ComPDFKit.PDFAnnotation;
  2. using Compdfkit_Tools.PDFControl;
  3. using ComPDFKitViewer.AnnotEvent;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Markup;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. namespace Compdfkit_Tools.Data
  15. {
  16. public enum CPDFAnnotationType
  17. {
  18. Unknow = 0,
  19. Highlight,
  20. Underline,
  21. Strikeout,
  22. Squiggly,
  23. FreeText,
  24. Freehand,
  25. Note,
  26. Circle,
  27. Square,
  28. Arrow,
  29. Line,
  30. Stamp,
  31. Signature,
  32. Link,
  33. Audio,
  34. Image
  35. }
  36. public enum SignatureType
  37. {
  38. TextType,
  39. Drawing,
  40. ImageType
  41. }
  42. public class LineType : INotifyPropertyChanged
  43. {
  44. private C_LINE_TYPE _headLineType;
  45. public C_LINE_TYPE HeadLineType
  46. {
  47. get { return _headLineType; }
  48. set { _headLineType = value; OnPropertyChanged(nameof(HeadLineType)); }
  49. }
  50. private C_LINE_TYPE _tailLineType;
  51. public C_LINE_TYPE TailLineType
  52. {
  53. get { return _tailLineType; }
  54. set { _tailLineType = value; OnPropertyChanged(nameof(TailLineType)); }
  55. }
  56. public event PropertyChangedEventHandler PropertyChanged;
  57. protected virtual void OnPropertyChanged(string propertyName)
  58. {
  59. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  60. }
  61. }
  62. public static class CPDFAnnotationDictionary
  63. {
  64. public static Dictionary<string, CPDFAnnotationType> GetAnnotationFromTag = new Dictionary<string, CPDFAnnotationType>() {
  65. { "Highlight", CPDFAnnotationType.Highlight },
  66. { "Underline", CPDFAnnotationType.Underline },
  67. { "Strikeout", CPDFAnnotationType.Strikeout },
  68. { "Squiggly", CPDFAnnotationType.Squiggly },
  69. { "Square", CPDFAnnotationType.Square },
  70. { "Circle", CPDFAnnotationType.Circle },
  71. { "Line", CPDFAnnotationType.Line },
  72. { "Arrow", CPDFAnnotationType.Arrow },
  73. { "Freehand", CPDFAnnotationType.Freehand },
  74. { "FreeText", CPDFAnnotationType.FreeText },
  75. { "Note", CPDFAnnotationType.Note },
  76. { "Stamp", CPDFAnnotationType.Stamp },
  77. { "Signature", CPDFAnnotationType.Signature },
  78. { "Link", CPDFAnnotationType.Link },
  79. {"Audio", CPDFAnnotationType.Audio },
  80. {"Image", CPDFAnnotationType.Image }
  81. };
  82. public static Dictionary<int, C_LINE_TYPE> GetLineTypeFromIndex = new Dictionary<int, C_LINE_TYPE>()
  83. {
  84. { 0, C_LINE_TYPE.LINETYPE_NONE },
  85. { 1, C_LINE_TYPE.LINETYPE_ARROW },
  86. { 2, C_LINE_TYPE.LINETYPE_CLOSEDARROW },
  87. { 3, C_LINE_TYPE.LINETYPE_SQUARE },
  88. { 4, C_LINE_TYPE.LINETYPE_CIRCLE },
  89. { 5, C_LINE_TYPE.LINETYPE_DIAMOND },
  90. { 6, C_LINE_TYPE.LINETYPE_BUTT },
  91. { 7, C_LINE_TYPE.LINETYPE_ROPENARROW },
  92. { 8, C_LINE_TYPE.LINETYPE_RCLOSEDARROW },
  93. { 9, C_LINE_TYPE.LINETYPE_SLASH }
  94. };
  95. public static Dictionary<AnnotArgsType, CPDFAnnotationType> GetAnnotArgsTypeFromAnnotationType = new Dictionary<AnnotArgsType, CPDFAnnotationType>()
  96. {
  97. { AnnotArgsType.AnnotHighlight, CPDFAnnotationType.Highlight},
  98. { AnnotArgsType.AnnotUnderline, CPDFAnnotationType.Underline },
  99. {AnnotArgsType.AnnotSquiggly , CPDFAnnotationType.Squiggly },
  100. {AnnotArgsType.AnnotStrikeout , CPDFAnnotationType.Strikeout},
  101. {AnnotArgsType.AnnotSquare , CPDFAnnotationType.Square },
  102. {AnnotArgsType.AnnotCircle , CPDFAnnotationType.Circle },
  103. {AnnotArgsType.AnnotLine , CPDFAnnotationType.Line},
  104. };
  105. }
  106. /// <summary>
  107. /// 用于换算的dash
  108. /// </summary>
  109. public class CPDFDashData
  110. {
  111. public event PropertyChangedEventHandler PropertyChanged;
  112. public void RaisePropertyChanged(string PropertyName)
  113. {
  114. if (this.PropertyChanged != null)
  115. {
  116. this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs(PropertyName));
  117. }
  118. }
  119. private bool _isSolid = true;
  120. public bool IsSolid
  121. {
  122. get => _isSolid;
  123. set
  124. {
  125. _isSolid = value;
  126. RaisePropertyChanged("IsSolid");
  127. }
  128. }
  129. private int _dashSpacing = 1;
  130. public int DashSpacing {
  131. get => _dashSpacing;
  132. set
  133. {
  134. _dashSpacing = value;
  135. RaisePropertyChanged("IsSolid");
  136. }
  137. }
  138. }
  139. public class CPDFFontData
  140. {
  141. public string FontFamily = "Helvetica";
  142. public int FontSize = 20;
  143. public bool IsBold = false;
  144. public bool IsItalic = false;
  145. public TextAlignment TextAlignment = TextAlignment.Left;
  146. }
  147. public abstract class CPDFAnnotationData
  148. {
  149. public CPDFAnnotationType AnnotationType;
  150. public string Note = string.Empty;
  151. public string Author = "ComPDFKit";
  152. public bool IsLocked = false;
  153. }
  154. public class CPDFMarkupData : CPDFAnnotationData
  155. {
  156. public double Opacity = 1;
  157. public Color Color = Color.FromRgb(255, 0, 0);
  158. }
  159. public class CPDFShapeData : CPDFAnnotationData
  160. {
  161. public Color BorderColor = Color.FromRgb(255, 0, 0);
  162. public Color FillColor = Color.FromRgb(255, 255, 255);
  163. public double Opacity = 1;
  164. public int Thickness = 1;
  165. public DashStyle DashStyle = DashStyles.Solid;
  166. }
  167. public class CPDFLineShapeData : CPDFAnnotationData
  168. {
  169. public Color BorderColor = Color.FromRgb(255, 0, 0);
  170. public double Opacity = 1;
  171. public int Thickness = 1;
  172. public DashStyle DashStyle = DashStyles.Solid;
  173. public LineType LineType = new LineType() { HeadLineType = C_LINE_TYPE.LINETYPE_NONE, TailLineType = C_LINE_TYPE.LINETYPE_NONE };
  174. }
  175. public class CPDFFreeTextData : CPDFAnnotationData
  176. {
  177. public Color BorderColor = Color.FromRgb(255, 0, 0);
  178. public double Opacity = 1;
  179. public string FontFamily = "Helvetica";
  180. public int FontSize = 20;
  181. public bool IsBold = false;
  182. public bool IsItalic = false;
  183. public TextAlignment TextAlignment = TextAlignment.Left;
  184. }
  185. public class CPDFNoteData : CPDFAnnotationData
  186. {
  187. public Color BorderColor = Color.FromRgb(255, 0, 0);
  188. }
  189. public class CPDFFreehandData : CPDFAnnotationData
  190. {
  191. public Color BorderColor = Color.FromRgb(255, 0, 0);
  192. public double Opacity = 1;
  193. public double Thickness = 1;
  194. }
  195. public class CPDFStampData : CPDFAnnotationData, INotifyPropertyChanged
  196. {
  197. public event PropertyChangedEventHandler PropertyChanged;
  198. public void RaisePropertyChanged(string PropertyName)
  199. {
  200. if (this.PropertyChanged != null)
  201. {
  202. this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs(PropertyName));
  203. }
  204. }
  205. private string stampText;
  206. public string StampText
  207. {
  208. get { return stampText; }
  209. set
  210. {
  211. stampText = value;
  212. RaisePropertyChanged("StampText");
  213. }
  214. }
  215. private string sourcePath;
  216. public string SourcePath
  217. {
  218. get { return sourcePath; }
  219. set
  220. {
  221. sourcePath = value;
  222. RaisePropertyChanged("SourcePath");
  223. }
  224. }
  225. private int maxWidth;
  226. public int MaxWidth
  227. {
  228. get { return maxWidth; }
  229. set
  230. {
  231. maxWidth = value;
  232. RaisePropertyChanged("MaxWidth");
  233. }
  234. }
  235. private int maxHeight;
  236. public int MaxHeight
  237. {
  238. get { return maxHeight; }
  239. set
  240. {
  241. maxHeight = value;
  242. RaisePropertyChanged("MaxHeight");
  243. }
  244. }
  245. private StampType type = StampType.UNKNOWN_STAMP;
  246. public StampType Type
  247. {
  248. get { return type; }
  249. set
  250. {
  251. type = value;
  252. RaisePropertyChanged("Type");
  253. }
  254. }
  255. public string TypeText
  256. {
  257. get
  258. {
  259. if(Type == StampType.TEXT_STAMP)
  260. {
  261. return "Text Stamp";
  262. }
  263. if (Type == StampType.IMAGE_STAMP)
  264. {
  265. return "Image Stamp";
  266. }
  267. return type.ToString();
  268. }
  269. }
  270. private double opacity;
  271. public double Opacity
  272. {
  273. get { return opacity; }
  274. set
  275. {
  276. opacity = value;
  277. RaisePropertyChanged("Opacity");
  278. }
  279. }
  280. private BitmapSource imageSource;
  281. public BitmapSource ImageSource
  282. {
  283. get { return imageSource; }
  284. set
  285. {
  286. imageSource = value;
  287. RaisePropertyChanged("ImageSource");
  288. }
  289. }
  290. public TextStampColor TextColor = TextStampColor.TEXTSTAMP_WHITE;
  291. public string StampTextDate = "";
  292. public TextStampSharp TextSharp = TextStampSharp.TEXTSTAMP_NONE;
  293. public bool IsCheckedDate = false;
  294. public bool IsCheckedTime = false;
  295. }
  296. public class CustomStampList : List<CPDFStampData>
  297. {
  298. }
  299. public class CPDFSignatureData : CPDFAnnotationData, INotifyPropertyChanged
  300. {
  301. public event PropertyChangedEventHandler PropertyChanged;
  302. public void RaisePropertyChanged(string PropertyName)
  303. {
  304. if (this.PropertyChanged != null)
  305. {
  306. this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs(PropertyName));
  307. }
  308. }
  309. private string sourcePath;
  310. public string SourcePath
  311. {
  312. get { return sourcePath; }
  313. set
  314. {
  315. sourcePath = value;
  316. RaisePropertyChanged("SourcePath");
  317. }
  318. }
  319. private string drawingPath;
  320. public string DrawingPath
  321. {
  322. get { return drawingPath; }
  323. set
  324. {
  325. drawingPath = value;
  326. RaisePropertyChanged("DrawingPath");
  327. }
  328. }
  329. public SignatureType Type { get; set; }
  330. public double inkThickness { get; set; }
  331. public Color inkColor { get; set; }
  332. }
  333. public class SignatureList : List<CPDFSignatureData>
  334. {
  335. }
  336. }