cpdf_annot_attr.dart 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. // Copyright © 2014-2024 PDF Technologies, Inc. All Rights Reserved.
  2. //
  3. // THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  4. // AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  5. // UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  6. // This notice may not be removed from this file.
  7. import 'package:flutter/material.dart';
  8. import '../cpdf_options.dart';
  9. import 'package:compdfkit_flutter/util/extension/cpdf_color_extension.dart';
  10. abstract class CPDFAnnotAttrBase {
  11. const CPDFAnnotAttrBase();
  12. Map<String, dynamic> toJson();
  13. }
  14. /// note annotation attribute parameter class
  15. class CPDFTextAttr extends CPDFAnnotAttrBase {
  16. /// note icon color
  17. final Color? color;
  18. /// Color transparency.<br/>
  19. /// Value Range:0-255.
  20. final int? alpha;
  21. const CPDFTextAttr({this.color = const Color(0xFF1460F3), this.alpha = 255});
  22. @override
  23. Map<String, dynamic> toJson() => {'color': color?.toHex(), 'alpha': alpha};
  24. }
  25. class CPDFMarkupAttr extends CPDFAnnotAttrBase {
  26. /// note icon color
  27. final Color? color;
  28. /// Color transparency.<br/>
  29. /// Value Range:0-255.
  30. final int? alpha;
  31. const CPDFMarkupAttr({this.color = const Color(0xFF1460F3), this.alpha = 77});
  32. @override
  33. Map<String, dynamic> toJson() => {'color': color?.toHex(), 'alpha': alpha};
  34. }
  35. typedef CPDFHighlightAttr = CPDFMarkupAttr;
  36. typedef CPDFUnderlineAttr = CPDFMarkupAttr;
  37. typedef CPDFStrikeoutAttr = CPDFMarkupAttr;
  38. typedef CPDFSquigglyAttr = CPDFMarkupAttr;
  39. class CPDFInkAttr extends CPDFAnnotAttrBase {
  40. /// note icon color
  41. final Color? color;
  42. /// Color transparency.<br/>
  43. /// Value Range:0-255.
  44. final int? alpha;
  45. /// border width.
  46. /// Value Range:1~10.
  47. final int borderWidth;
  48. const CPDFInkAttr(
  49. {this.color = const Color(0xFF1460F3),
  50. this.alpha = 255,
  51. this.borderWidth = 10});
  52. @override
  53. Map<String, dynamic> toJson() =>
  54. {'color': color?.toHex(), 'alpha': alpha, 'borderWidth': borderWidth};
  55. }
  56. class CPDFShapeAttr extends CPDFAnnotAttrBase {
  57. final Color? fillColor;
  58. final Color? borderColor;
  59. /// Fill color and border color transparency.<br/>
  60. /// Range: 0-255.
  61. final int? colorAlpha;
  62. /// border thickness, value range:1~10
  63. final int? borderWidth;
  64. /// Set the border style to dashed or solid.
  65. final CPDFBorderStyle? borderStyle;
  66. const CPDFShapeAttr(
  67. {this.fillColor = const Color(0xFF1460F3),
  68. this.borderColor = Colors.black,
  69. this.colorAlpha = 128,
  70. this.borderWidth = 2,
  71. this.borderStyle = const CPDFBorderStyle.solid()});
  72. @override
  73. Map<String, dynamic> toJson() => {
  74. 'fillColor': fillColor?.toHex(),
  75. 'borderColor': borderColor?.toHex(),
  76. 'colorAlpha': colorAlpha,
  77. 'borderWidth': borderWidth,
  78. 'borderStyle': borderStyle?.toJson()
  79. };
  80. }
  81. typedef CPDFSquareAttr = CPDFShapeAttr;
  82. typedef CPDFCircleAttr = CPDFShapeAttr;
  83. class CPDFLineAttr extends CPDFShapeAttr {
  84. const CPDFLineAttr({
  85. super.fillColor = const Color(0xFF1460F3),
  86. super.borderColor = Colors.black,
  87. super.colorAlpha = 128,
  88. super.borderWidth = 2,
  89. super.borderStyle = const CPDFBorderStyle.solid(),
  90. });
  91. @override
  92. Map<String, dynamic> toJson() {
  93. return super.toJson()
  94. ..addAll({
  95. 'startLineType': CPDFLineType.none.name,
  96. 'tailLineType': CPDFLineType.none.name
  97. });
  98. }
  99. }
  100. class CPDFArrowAttr extends CPDFShapeAttr {
  101. /// Arrow starting position shape.
  102. final CPDFLineType? headType;
  103. /// Arrow tail position shape.
  104. final CPDFLineType? tailType;
  105. const CPDFArrowAttr({
  106. super.fillColor = const Color(0xFF1460F3),
  107. super.borderColor = Colors.black,
  108. super.colorAlpha = 128,
  109. super.borderWidth = 2,
  110. super.borderStyle = const CPDFBorderStyle.solid(),
  111. this.headType = CPDFLineType.none,
  112. this.tailType = CPDFLineType.openArrow,
  113. });
  114. @override
  115. Map<String, dynamic> toJson() {
  116. return super.toJson()
  117. ..addAll(
  118. {'startLineType': headType?.name, 'tailLineType': tailType?.name});
  119. }
  120. }
  121. class CPDFFreetextAttr extends CPDFAnnotAttrBase {
  122. final Color? fontColor;
  123. /// text color opacity. value range:0~255
  124. final int? fontColorAlpha;
  125. /// font size, value range:1~100
  126. final int? fontSize;
  127. /// Whether the font is bold.
  128. final bool? isBold;
  129. /// Is the font italicized.
  130. final bool? isItalic;
  131. /// Text alignment, [CPDFAlignment.left] aligned by default.
  132. final CPDFAlignment? alignment;
  133. /// The font used by default for text. The default is:[CPDFTypeface.helvetica].
  134. final CPDFTypeface? typeface;
  135. const CPDFFreetextAttr({
  136. this.fontColor = Colors.black,
  137. this.fontColorAlpha = 255,
  138. this.fontSize = 30,
  139. this.isBold = false,
  140. this.isItalic = false,
  141. this.alignment = CPDFAlignment.left,
  142. this.typeface = CPDFTypeface.helvetica,
  143. });
  144. @override
  145. Map<String, dynamic> toJson() => {
  146. 'fontColor': fontColor?.toHex(),
  147. 'fontColorAlpha': fontColorAlpha,
  148. 'fontSize': fontSize,
  149. 'isBold': isBold,
  150. 'isItalic': isItalic,
  151. 'alignment': alignment?.name,
  152. 'typeface': typeface?.getFontName(),
  153. };
  154. }
  155. class CPDFBorderStyle {
  156. /// default: [CPDFAnnotBorderStyle.solid]
  157. final CPDFAnnotBorderStyle style;
  158. /// Dashed gap, only style=[CPDFAnnotBorderStyle.dashed] is valid.
  159. final double dashGap;
  160. const CPDFBorderStyle(
  161. {this.style = CPDFAnnotBorderStyle.solid, this.dashGap = 8.0});
  162. const CPDFBorderStyle.solid()
  163. : style = CPDFAnnotBorderStyle.solid,
  164. dashGap = 0;
  165. const CPDFBorderStyle.dashed({this.dashGap = 9.0})
  166. : style = CPDFAnnotBorderStyle.dashed;
  167. Map<String, dynamic> toJson() => {'style': style.name, 'dashGap': dashGap};
  168. }
  169. class CPDFEditorTextAttr extends CPDFAnnotAttrBase {
  170. final Color fontColor;
  171. /// text color opacity. value range:0~255
  172. final int fontColorAlpha;
  173. /// font size, value range:1~100
  174. final int fontSize;
  175. /// Whether the font is bold.
  176. final bool isBold;
  177. /// Is the font italicized.
  178. final bool isItalic;
  179. /// The font used by default for text. The default is:[CPDFTypeface.helvetica].
  180. final CPDFTypeface typeface;
  181. /// Text alignment, [CPDFAlignment.left] aligned by default.
  182. final CPDFAlignment alignment;
  183. const CPDFEditorTextAttr(
  184. {this.fontColor = Colors.black,
  185. this.fontColorAlpha = 255,
  186. this.fontSize = 30,
  187. this.isBold = false,
  188. this.isItalic = false,
  189. this.typeface = CPDFTypeface.helvetica,
  190. this.alignment = CPDFAlignment.left});
  191. @override
  192. Map<String, dynamic> toJson() => {
  193. 'fontColor': fontColor.toHex(),
  194. 'fontColorAlpha': fontColorAlpha,
  195. 'fontSize': fontSize,
  196. 'isBold': isBold,
  197. 'isItalic': isItalic,
  198. 'typeface': typeface.getFontName(),
  199. 'alignment': alignment.name
  200. };
  201. }
  202. class CPDFTextFieldAttr extends CPDFAnnotAttrBase {
  203. final Color? fillColor;
  204. /// The border color, the default is: [Color(0xFF1460F3)]
  205. final Color? borderColor;
  206. /// The border width, the default is: 2
  207. /// border thickness, value range:0~10
  208. final int? borderWidth;
  209. /// The text color, the default is: [Colors.black]
  210. final Color? fontColor;
  211. /// The font size, the default is: 20
  212. /// value range:1~100
  213. final int? fontSize;
  214. final bool? isBold;
  215. final bool? isItalic;
  216. final CPDFAlignment? alignment;
  217. /// Whether the text can be multiple lines.
  218. final bool? multiline;
  219. final CPDFTypeface? typeface;
  220. const CPDFTextFieldAttr(
  221. {this.fillColor = const Color(0xFFDDE9FF),
  222. this.borderColor = const Color(0xFF1460F3),
  223. this.borderWidth = 2,
  224. this.fontColor = Colors.black,
  225. this.fontSize = 20,
  226. this.isBold = false,
  227. this.isItalic = false,
  228. this.alignment = CPDFAlignment.left,
  229. this.multiline = true,
  230. this.typeface = CPDFTypeface.helvetica});
  231. @override
  232. Map<String, dynamic> toJson() {
  233. return {
  234. 'fillColor': fillColor?.toHex(),
  235. 'borderColor': borderColor?.toHex(),
  236. 'borderWidth': borderWidth,
  237. 'fontColor': fontColor?.toHex(),
  238. 'fontSize': fontSize,
  239. 'isBold': isBold,
  240. 'isItalic': isItalic,
  241. 'alignment': alignment?.name,
  242. 'multiline': multiline,
  243. 'typeface': typeface?.getFontName()
  244. };
  245. }
  246. }
  247. class CPDFCheckBoxAttr extends CPDFAnnotAttrBase {
  248. final Color? fillColor;
  249. final Color? borderColor;
  250. /// border thickness, value range:0~10
  251. final int? borderWidth;
  252. final Color? checkedColor;
  253. final bool? isChecked;
  254. final CPDFCheckStyle? checkedStyle;
  255. const CPDFCheckBoxAttr(
  256. {this.fillColor = const Color(0xFFDDE9FF),
  257. this.borderColor = const Color(0xFF1460F3),
  258. this.borderWidth = 2,
  259. this.checkedColor = const Color(0xFF43474D),
  260. this.isChecked = false,
  261. this.checkedStyle = CPDFCheckStyle.check});
  262. @override
  263. Map<String, dynamic> toJson() {
  264. return {
  265. 'fillColor': fillColor?.toHex(),
  266. 'borderColor': borderColor?.toHex(),
  267. 'borderWidth': borderWidth,
  268. 'checkedColor': checkedColor?.toHex(),
  269. 'isChecked': false,
  270. 'checkedStyle': checkedStyle?.name
  271. };
  272. }
  273. }
  274. class CPDFRadioButtonAttr extends CPDFCheckBoxAttr {
  275. const CPDFRadioButtonAttr(
  276. {super.fillColor = const Color(0xFFDDE9FF),
  277. super.borderColor = const Color(0xFF1460F3),
  278. super.borderWidth = 2,
  279. super.checkedColor = const Color(0xFF43474D),
  280. super.isChecked = false,
  281. super.checkedStyle = CPDFCheckStyle.circle});
  282. }
  283. class CPDFListBoxAttr extends CPDFAnnotAttrBase {
  284. final Color? fillColor;
  285. /// The border color, the default is: [Color(0xFF1460F3)]
  286. final Color? borderColor;
  287. /// The border width, the default is: 2
  288. /// border thickness, value range:0~10
  289. final int? borderWidth;
  290. /// The text color, the default is: [Colors.black]
  291. final Color? fontColor;
  292. /// The font size, the default is: 20
  293. /// value range:1~100
  294. final int? fontSize;
  295. final bool? isBold;
  296. final bool? isItalic;
  297. final CPDFTypeface? typeface;
  298. const CPDFListBoxAttr(
  299. {this.fillColor = const Color(0xFFDDE9FF),
  300. this.borderColor = const Color(0xFF1460F3),
  301. this.borderWidth = 2,
  302. this.fontColor = Colors.black,
  303. this.fontSize = 20,
  304. this.isBold = false,
  305. this.isItalic = false,
  306. this.typeface = CPDFTypeface.helvetica});
  307. @override
  308. Map<String, dynamic> toJson() {
  309. return {
  310. 'fillColor': fillColor?.toHex(),
  311. 'borderColor': borderColor?.toHex(),
  312. 'borderWidth': borderWidth,
  313. 'fontColor': fontColor?.toHex(),
  314. 'fontSize': fontSize,
  315. 'isBold': isBold,
  316. 'isItalic': isItalic,
  317. 'typeface': typeface?.getFontName()
  318. };
  319. }
  320. }
  321. class CPDFComboBoxAttr extends CPDFListBoxAttr {
  322. const CPDFComboBoxAttr(
  323. {super.fillColor = const Color(0xFFDDE9FF),
  324. super.borderColor = const Color(0xFF1460F3),
  325. super.borderWidth = 2,
  326. super.fontColor = Colors.black,
  327. super.fontSize = 20,
  328. super.isBold = false,
  329. super.isItalic = false,
  330. super.typeface = CPDFTypeface.helvetica});
  331. }
  332. class CPDFPushButtonAttr extends CPDFAnnotAttrBase {
  333. final String? title;
  334. final Color? fillColor;
  335. /// The border color, the default is: [Color(0xFF1460F3)]
  336. final Color? borderColor;
  337. /// The border width, the default is: 2
  338. /// border thickness, value range:0~10
  339. final int? borderWidth;
  340. /// The text color, the default is: [Colors.black]
  341. final Color? fontColor;
  342. /// The font size, the default is: 20
  343. /// value range:1~100
  344. final int? fontSize;
  345. final bool? isBold;
  346. final bool? isItalic;
  347. final CPDFTypeface? typeface;
  348. const CPDFPushButtonAttr({
  349. this.title = 'Button',
  350. this.fillColor = const Color(0xFFDDE9FF),
  351. this.borderColor = const Color(0xFF1460F3),
  352. this.borderWidth = 2,
  353. this.fontColor = Colors.black,
  354. this.fontSize = 20,
  355. this.typeface = CPDFTypeface.helvetica,
  356. this.isBold = false,
  357. this.isItalic = false,
  358. });
  359. @override
  360. Map<String, dynamic> toJson() {
  361. return {
  362. 'fillColor': fillColor?.toHex(),
  363. 'borderColor': borderColor?.toHex(),
  364. 'borderWidth': borderWidth,
  365. 'fontColor': fontColor?.toHex(),
  366. 'fontSize': fontSize,
  367. 'typeface': typeface?.getFontName(),
  368. 'isBold': isBold,
  369. 'isItalic': isItalic,
  370. 'title': title
  371. };
  372. }
  373. }
  374. class CPDFSignatureWidgetAttr extends CPDFAnnotAttrBase {
  375. final Color? fillColor;
  376. final Color? borderColor;
  377. final int? borderWidth;
  378. const CPDFSignatureWidgetAttr({
  379. this.fillColor = const Color(0xFFDDE9FF),
  380. this.borderColor = const Color(0xFF1460F3),
  381. this.borderWidth = 2,
  382. });
  383. @override
  384. Map<String, dynamic> toJson() {
  385. return {
  386. 'fillColor': fillColor?.toHex(),
  387. 'borderColor': borderColor?.toHex(),
  388. 'borderWidth': borderWidth,
  389. };
  390. }
  391. }