annot_attribute_bean.dart 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. import 'dart:ui';
  2. import 'package:flutter/material.dart';
  3. import 'package:kmpdfkit_demo/widgets/models/text_stamp_bean.dart';
  4. import '../contains.dart';
  5. import '../extension/color_extension.dart';
  6. /// annot_attribute_bean.dart
  7. /// Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
  8. ///
  9. /// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  10. /// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  11. /// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  12. /// This notice may not be removed from this file.
  13. class AnnotAttributeBean {
  14. Color color;
  15. int alpha;
  16. double borderWidth;
  17. ///only shape annotation [AnnotationType.square],[AnnotationType.circle],[AnnotationType.line],[AnnotationType.arrow] ----->
  18. AnnotationType shapeType;
  19. Color borderColor;
  20. int borderColorAlpha;
  21. Color fillColor;
  22. int fillColorAlpha;
  23. bool showShapeTypeWidget;
  24. /// <------
  25. /// freetext only
  26. bool fontBold;
  27. bool fontItalic = false;
  28. Color textColor;
  29. int textColorAlpha;
  30. int fontSize;
  31. FontType fontType;
  32. /// signature, stamp
  33. String imagePath;
  34. bool isSignature;
  35. ///stamp
  36. String standardStampName;
  37. TextStampBean? customStampBean;
  38. ///link
  39. LinkType linkType;
  40. String linkWeb;
  41. int linkPage;
  42. String linkEmail;
  43. bool cancelCreateLink = false;
  44. AnnotAttributeBean(
  45. {this.color = Colors.red,
  46. this.alpha = 255,
  47. this.borderWidth = 2,
  48. this.shapeType = AnnotationType.square,
  49. this.borderColor = Colors.red,
  50. this.borderColorAlpha = 255,
  51. this.fillColor = Colors.red,
  52. this.fillColorAlpha = 0,
  53. this.showShapeTypeWidget = true,
  54. this.fontBold = false,
  55. this.fontItalic = false,
  56. this.textColor = Colors.black,
  57. this.textColorAlpha = 255,
  58. this.fontSize = 40,
  59. this.fontType = FontType.helvetica,
  60. this.imagePath = '',
  61. this.isSignature = false,
  62. this.standardStampName = '',
  63. this.customStampBean,
  64. this.linkType = LinkType.website,
  65. this.linkWeb = '',
  66. this.linkPage = 1,
  67. this.linkEmail = '',
  68. this.cancelCreateLink = false});
  69. @override
  70. String toString() {
  71. return "color:$color,"
  72. " alpha:$alpha, "
  73. "shapeType:${shapeType.name}, "
  74. "borderWidth:$borderWidth,"
  75. "borderColor:$borderColor, "
  76. "borderColorAlpha:$borderColorAlpha, "
  77. "fillColor:$fillColor, "
  78. "fillColorAlpha:$fillColorAlpha,"
  79. "fontBold:$fontBold,"
  80. "fontItalic:$fontItalic,"
  81. "textColor:${textColor},"
  82. "textColorAlpha:${textColorAlpha},"
  83. "fontSize:$fontSize,"
  84. "fontType:${fontType.name},"
  85. "imagePath:${imagePath},"
  86. "isSignature:${isSignature},"
  87. "standardStampName:${standardStampName},"
  88. "customStampBean:${customStampBean?.toString()},"
  89. "linkType:${linkType.name},"
  90. "linkWeb:${linkWeb},"
  91. "linkPage:$linkPage,"
  92. "linkEmail:$linkEmail}";
  93. }
  94. static AnnotAttributeBean parseMapValue(
  95. AnnotationType annotationType, Map<dynamic, dynamic> event) {
  96. Map<dynamic, dynamic> result = event;
  97. String annotAttrColor =
  98. result[EventParameters.annotAttrColor] ?? Colors.red.toHex();
  99. int annotAttrAlpha = result[EventParameters.annotAttrAlpha] ?? 255;
  100. num borderWidth = result[EventParameters.annotAttrBorderWidth] ?? 2.0;
  101. String borderColor =
  102. result[EventParameters.annotAttrBorderColor] ?? Colors.red.toHex();
  103. int borderColorAlpha =
  104. result[EventParameters.annotAttrBorderColorAlpha] ?? 255;
  105. String fillColor =
  106. result[EventParameters.annotAttrFillColor] ?? Colors.red.toHex();
  107. int fillColorAlpha = result[EventParameters.annotAttrFillColorAlpha] ?? 255;
  108. String shapeTypeStr = result[EventParameters.annotAttrShapeType] ?? '';
  109. AnnotationType shapeType = shapeTypeStr.isEmpty
  110. ? annotationType
  111. : AnnotationType.values.byName(shapeTypeStr);
  112. bool fontBold = result[EventParameters.annotAttrFontBold] ?? false;
  113. bool fontItalic = result[EventParameters.annotAttrFontItalic] ?? false;
  114. String textColor =
  115. result[EventParameters.annotAttrTextColor] ?? Colors.black.toHex();
  116. int textColorAlpha = result[EventParameters.annotAttrTextColorAlpha] ?? 255;
  117. num fontSize = result[EventParameters.annotAttrFontSize] ?? 40;
  118. String fontType =
  119. result[EventParameters.annotAttrFontType] ?? FontType.helvetica.name;
  120. String linkType = result[EventParameters.annotLinkType] ?? LinkType.website.name;
  121. String linkWebSite = result[EventParameters.annotLinkWeb] ?? '';
  122. int linkPage = result[EventParameters.annotLinkPage] ?? 1;
  123. String linkEmail = result[EventParameters.annotLinkEmail] ?? '';
  124. return AnnotAttributeBean(
  125. color: HexColor.fromHex(annotAttrColor),
  126. alpha: annotAttrAlpha,
  127. borderWidth: borderWidth.toDouble(),
  128. borderColor: HexColor.fromHex(borderColor),
  129. borderColorAlpha: borderColorAlpha,
  130. fillColor: HexColor.fromHex(fillColor),
  131. fillColorAlpha: fillColorAlpha,
  132. shapeType: shapeType,
  133. showShapeTypeWidget: false,
  134. fontBold: fontBold,
  135. fontItalic: fontItalic,
  136. textColor: HexColor.fromHex(textColor),
  137. textColorAlpha: textColorAlpha,
  138. fontSize: fontSize.toInt(),
  139. fontType: FontType.values.byName(fontType.toLowerCase()),
  140. linkType: LinkType.values.byName(linkType.toLowerCase()),
  141. linkWeb: linkWebSite,
  142. linkPage: linkPage,
  143. linkEmail: linkEmail);
  144. }
  145. Map<dynamic, dynamic> toMapValues(AnnotationType annotationType) {
  146. switch (annotationType) {
  147. case AnnotationType.highlight:
  148. case AnnotationType.underline:
  149. case AnnotationType.squiggly:
  150. case AnnotationType.strikeout:
  151. return {
  152. EventParameters.annotAttrColor: color.toHex(),
  153. EventParameters.annotAttrAlpha: alpha,
  154. };
  155. case AnnotationType.ink:
  156. return {
  157. EventParameters.annotType: annotationType.name,
  158. EventParameters.annotAttrColor: color.toHex(),
  159. EventParameters.annotAttrAlpha: alpha,
  160. EventParameters.annotAttrBorderWidth: borderWidth,
  161. };
  162. case AnnotationType.shape:
  163. case AnnotationType.arrow:
  164. case AnnotationType.circle:
  165. case AnnotationType.square:
  166. case AnnotationType.line:
  167. return {
  168. EventParameters.annotType: annotationType.name,
  169. EventParameters.annotAttrShapeType: shapeType.name,
  170. EventParameters.annotAttrBorderWidth: borderWidth,
  171. EventParameters.annotAttrBorderColor: borderColor.toHex(),
  172. EventParameters.annotAttrBorderColorAlpha: borderColorAlpha,
  173. EventParameters.annotAttrFillColor: fillColor.toHex(),
  174. EventParameters.annotAttrFillColorAlpha: fillColorAlpha,
  175. };
  176. case AnnotationType.freetext:
  177. return {
  178. EventParameters.annotType: annotationType.name,
  179. EventParameters.annotAttrFontBold: fontBold,
  180. EventParameters.annotAttrFontItalic: fontItalic,
  181. EventParameters.annotAttrTextColor: textColor.toHex(),
  182. EventParameters.annotAttrTextColorAlpha: textColorAlpha,
  183. EventParameters.annotAttrFontSize: fontSize,
  184. EventParameters.annotAttrFontType: fontType.name,
  185. };
  186. case AnnotationType.signature:
  187. return {
  188. EventParameters.annotType: annotationType.name,
  189. EventParameters.annotImagePath: imagePath,
  190. };
  191. case AnnotationType.stamp:
  192. if (standardStampName.isNotEmpty) {
  193. return {
  194. EventParameters.annotType: annotationType.name,
  195. EventParameters.annotStandardStampName: standardStampName,
  196. };
  197. } else {
  198. return {
  199. EventParameters.annotType: annotationType.name,
  200. EventParameters.annotTextStampContent: customStampBean?.content,
  201. EventParameters.annotTextStampDate: customStampBean?.getDateStr(),
  202. EventParameters.annotTextStampStyleShapeType:
  203. customStampBean?.shape.type,
  204. EventParameters.annotTextStampStyleColorType:
  205. customStampBean?.color.type
  206. };
  207. }
  208. case AnnotationType.link:
  209. switch (linkType) {
  210. case LinkType.website:
  211. return {
  212. EventParameters.annotType: annotationType.name,
  213. EventParameters.annotLinkType: linkType.name,
  214. EventParameters.annotLinkWeb: linkWeb,
  215. EventParameters.annotLinkCancelCreate: cancelCreateLink
  216. };
  217. case LinkType.page:
  218. return {
  219. EventParameters.annotType: annotationType.name,
  220. EventParameters.annotLinkType: linkType.name,
  221. EventParameters.annotLinkPage: linkPage,
  222. EventParameters.annotLinkCancelCreate: cancelCreateLink
  223. };
  224. case LinkType.email:
  225. return {
  226. EventParameters.annotType: annotationType.name,
  227. EventParameters.annotLinkType: linkType.name,
  228. EventParameters.annotLinkEmail: linkEmail,
  229. EventParameters.annotLinkCancelCreate: cancelCreateLink
  230. };
  231. }
  232. case AnnotationType.unknown:
  233. return {};
  234. default:
  235. return {};
  236. }
  237. }
  238. }