123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- import 'package:flutter/material.dart';
- /// text_stamp_bean.dart
- ///
- /// Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
- ///
- /// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
- /// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
- /// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
- /// This notice may not be removed from this file.
- class TextStampBean {
- String content;
- String date;
- String time;
- TextStampStyleShape shape;
- TextStampStyleShapeColor color;
- String? previewImagePath;
- bool select;
- TextStampBean(
- {required this.content,
- this.date = "",
- this.time = "",
- this.shape = TextStampStyleShape.rightRect,
- this.color = TextStampStyleShapeColor.textStampGreen,
- this.previewImagePath = '',
- this.select = false});
- TextStampColorData getColors() {
- switch (color) {
- case TextStampStyleShapeColor.textStampWhite:
- return TextStampColorData(
- const Color(0x00FFFFFF), Colors.black, const Color(0x00FFFFFF));
- case TextStampStyleShapeColor.textStampRed:
- return TextStampColorData(const Color(0xFFFEC7C7),
- const Color(0xFF77140B), const Color(0xFF8C3022));
- case TextStampStyleShapeColor.textStampGreen:
- return TextStampColorData(const Color(0xFFCFE0C7),
- const Color(0xFF325413), const Color(0xFF567335));
- case TextStampStyleShapeColor.textStampBlue:
- return TextStampColorData(const Color(0xFFCBCFE2),
- const Color(0xFF09144A), const Color(0xFF313968));
- }
- }
- List<Color> getLinearGradientColors() {
- // 将原始颜色的 alpha 值降低为 85,即透明度降低约 67%
- Color bgColor = getColors().bgColor;
- return [bgColor.withOpacity(0.33), bgColor];
- }
- Map<String, dynamic> toJson() {
- return {
- 'content': content,
- 'date': date,
- 'time': time,
- 'shape': shape.name,
- 'color': color.name
- };
- }
- factory TextStampBean.fromJson(Map<String, dynamic> json) {
- return TextStampBean(
- content: json['content'],
- date: json['date'],
- time: json['time'],
- shape: TextStampStyleShape.values.byName(json['shape']),
- color: TextStampStyleShapeColor.values.byName(json['color']));
- }
- @override
- String toString() {
- return '{content:$content, date:$date, time:$time, shape:${shape.name}, color:${color.name}';
- }
- String getDateStr() {
- if(date.isEmpty && time.isEmpty){
- return '';
- }
- if (date.isNotEmpty && time.isEmpty){
- return date;
- } else if (date.isEmpty && time.isNotEmpty){
- return time;
- }else {
- return '$date $time';
- }
- }
- bool available(){
- return content.isNotEmpty || date.isNotEmpty || time.isNotEmpty;
- }
- }
- class TextStampColorData {
- Color bgColor;
- Color textColor;
- Color lineColor;
- TextStampColorData(this.bgColor, this.textColor, this.lineColor);
- }
- enum TextStampStyleShape { empty, rect, leftRect, rightRect }
- extension TextStampStyleShapeExtension on TextStampStyleShape {
- String get type {
- switch (this) {
- case TextStampStyleShape.empty:
- return 'TEXTSTAMP_NONE';
- case TextStampStyleShape.rect:
- return 'TEXTSTAMP_RECT';
- case TextStampStyleShape.leftRect:
- return 'TEXTSTAMP_LEFT_TRIANGLE';
- case TextStampStyleShape.rightRect:
- return 'TEXTSTAMP_RIGHT_TRIANGLE';
- }
- }
- }
- enum TextStampStyleShapeColor {
- textStampWhite,
- textStampRed,
- textStampGreen,
- textStampBlue
- }
- extension TextStampStyleShapeColorExtension on TextStampStyleShapeColor {
- String get type {
- switch (this) {
- case TextStampStyleShapeColor.textStampWhite:
- return 'TEXTSTAMP_WHITE';
- case TextStampStyleShapeColor.textStampRed:
- return 'TEXTSTAMP_RED';
- case TextStampStyleShapeColor.textStampGreen:
- return 'TEXTSTAMP_GREEN';
- case TextStampStyleShapeColor.textStampBlue:
- return 'TEXTSTAMP_BLUE';
- }
- }
- }
|