CPDFAnnotationData.cs 11 KB

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