text_stamp_bean.dart 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import 'package:flutter/material.dart';
  2. /// text_stamp_bean.dart
  3. ///
  4. /// Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
  5. ///
  6. /// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  7. /// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  8. /// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  9. /// This notice may not be removed from this file.
  10. class TextStampBean {
  11. String content;
  12. String date;
  13. String time;
  14. TextStampStyleShape shape;
  15. TextStampStyleShapeColor color;
  16. String? previewImagePath;
  17. bool select;
  18. TextStampBean(
  19. {required this.content,
  20. this.date = "",
  21. this.time = "",
  22. this.shape = TextStampStyleShape.rightRect,
  23. this.color = TextStampStyleShapeColor.textStampGreen,
  24. this.previewImagePath = '',
  25. this.select = false});
  26. TextStampColorData getColors() {
  27. switch (color) {
  28. case TextStampStyleShapeColor.textStampWhite:
  29. return TextStampColorData(
  30. const Color(0x00FFFFFF), Colors.black, const Color(0x00FFFFFF));
  31. case TextStampStyleShapeColor.textStampRed:
  32. return TextStampColorData(const Color(0xFFFEC7C7),
  33. const Color(0xFF77140B), const Color(0xFF8C3022));
  34. case TextStampStyleShapeColor.textStampGreen:
  35. return TextStampColorData(const Color(0xFFCFE0C7),
  36. const Color(0xFF325413), const Color(0xFF567335));
  37. case TextStampStyleShapeColor.textStampBlue:
  38. return TextStampColorData(const Color(0xFFCBCFE2),
  39. const Color(0xFF09144A), const Color(0xFF313968));
  40. }
  41. }
  42. List<Color> getLinearGradientColors() {
  43. // 将原始颜色的 alpha 值降低为 85,即透明度降低约 67%
  44. Color bgColor = getColors().bgColor;
  45. return [bgColor.withOpacity(0.33), bgColor];
  46. }
  47. Map<String, dynamic> toJson() {
  48. return {
  49. 'content': content,
  50. 'date': date,
  51. 'time': time,
  52. 'shape': shape.name,
  53. 'color': color.name
  54. };
  55. }
  56. factory TextStampBean.fromJson(Map<String, dynamic> json) {
  57. return TextStampBean(
  58. content: json['content'],
  59. date: json['date'],
  60. time: json['time'],
  61. shape: TextStampStyleShape.values.byName(json['shape']),
  62. color: TextStampStyleShapeColor.values.byName(json['color']));
  63. }
  64. @override
  65. String toString() {
  66. return '{content:$content, date:$date, time:$time, shape:${shape.name}, color:${color.name}';
  67. }
  68. String getDateStr() {
  69. if(date.isEmpty && time.isEmpty){
  70. return '';
  71. }
  72. if (date.isNotEmpty && time.isEmpty){
  73. return date;
  74. } else if (date.isEmpty && time.isNotEmpty){
  75. return time;
  76. }else {
  77. return '$date $time';
  78. }
  79. }
  80. bool available(){
  81. return content.isNotEmpty || date.isNotEmpty || time.isNotEmpty;
  82. }
  83. }
  84. class TextStampColorData {
  85. Color bgColor;
  86. Color textColor;
  87. Color lineColor;
  88. TextStampColorData(this.bgColor, this.textColor, this.lineColor);
  89. }
  90. enum TextStampStyleShape { empty, rect, leftRect, rightRect }
  91. extension TextStampStyleShapeExtension on TextStampStyleShape {
  92. String get type {
  93. switch (this) {
  94. case TextStampStyleShape.empty:
  95. return 'TEXTSTAMP_NONE';
  96. case TextStampStyleShape.rect:
  97. return 'TEXTSTAMP_RECT';
  98. case TextStampStyleShape.leftRect:
  99. return 'TEXTSTAMP_LEFT_TRIANGLE';
  100. case TextStampStyleShape.rightRect:
  101. return 'TEXTSTAMP_RIGHT_TRIANGLE';
  102. }
  103. }
  104. }
  105. enum TextStampStyleShapeColor {
  106. textStampWhite,
  107. textStampRed,
  108. textStampGreen,
  109. textStampBlue
  110. }
  111. extension TextStampStyleShapeColorExtension on TextStampStyleShapeColor {
  112. String get type {
  113. switch (this) {
  114. case TextStampStyleShapeColor.textStampWhite:
  115. return 'TEXTSTAMP_WHITE';
  116. case TextStampStyleShapeColor.textStampRed:
  117. return 'TEXTSTAMP_RED';
  118. case TextStampStyleShapeColor.textStampGreen:
  119. return 'TEXTSTAMP_GREEN';
  120. case TextStampStyleShapeColor.textStampBlue:
  121. return 'TEXTSTAMP_BLUE';
  122. }
  123. }
  124. }