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 getLinearGradientColors() { // 将原始颜色的 alpha 值降低为 85,即透明度降低约 67% Color bgColor = getColors().bgColor; return [bgColor.withOpacity(0.33), bgColor]; } Map toJson() { return { 'content': content, 'date': date, 'time': time, 'shape': shape.name, 'color': color.name }; } factory TextStampBean.fromJson(Map 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'; } } }