123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- import 'dart:ui';
- import 'package:flutter/material.dart';
- import 'package:kmpdfkit_demo/widgets/models/text_stamp_bean.dart';
- import '../contains.dart';
- import '../extension/color_extension.dart';
- /// annot_attribute_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 AnnotAttributeBean {
- Color color;
- int alpha;
- double borderWidth;
- ///only shape annotation [AnnotationType.square],[AnnotationType.circle],[AnnotationType.line],[AnnotationType.arrow] ----->
- AnnotationType shapeType;
- Color borderColor;
- int borderColorAlpha;
- Color fillColor;
- int fillColorAlpha;
- bool showShapeTypeWidget;
- /// <------
- /// freetext only
- bool fontBold;
- bool fontItalic = false;
- Color textColor;
- int textColorAlpha;
- int fontSize;
- FontType fontType;
- /// signature, stamp
- String imagePath;
- bool isSignature;
- ///stamp
- String standardStampName;
- TextStampBean? customStampBean;
- ///link
- LinkType linkType;
- String linkWeb;
- int linkPage;
- String linkEmail;
- bool cancelCreateLink = false;
- AnnotAttributeBean(
- {this.color = Colors.red,
- this.alpha = 255,
- this.borderWidth = 2,
- this.shapeType = AnnotationType.square,
- this.borderColor = Colors.red,
- this.borderColorAlpha = 255,
- this.fillColor = Colors.red,
- this.fillColorAlpha = 0,
- this.showShapeTypeWidget = true,
- this.fontBold = false,
- this.fontItalic = false,
- this.textColor = Colors.black,
- this.textColorAlpha = 255,
- this.fontSize = 40,
- this.fontType = FontType.helvetica,
- this.imagePath = '',
- this.isSignature = false,
- this.standardStampName = '',
- this.customStampBean,
- this.linkType = LinkType.website,
- this.linkWeb = '',
- this.linkPage = 1,
- this.linkEmail = '',
- this.cancelCreateLink = false});
- @override
- String toString() {
- return "color:$color,"
- " alpha:$alpha, "
- "shapeType:${shapeType.name}, "
- "borderWidth:$borderWidth,"
- "borderColor:$borderColor, "
- "borderColorAlpha:$borderColorAlpha, "
- "fillColor:$fillColor, "
- "fillColorAlpha:$fillColorAlpha,"
- "fontBold:$fontBold,"
- "fontItalic:$fontItalic,"
- "textColor:${textColor},"
- "textColorAlpha:${textColorAlpha},"
- "fontSize:$fontSize,"
- "fontType:${fontType.name},"
- "imagePath:${imagePath},"
- "isSignature:${isSignature},"
- "standardStampName:${standardStampName},"
- "customStampBean:${customStampBean?.toString()},"
- "linkType:${linkType.name},"
- "linkWeb:${linkWeb},"
- "linkPage:$linkPage,"
- "linkEmail:$linkEmail}";
- }
- static AnnotAttributeBean parseMapValue(
- AnnotationType annotationType, Map<dynamic, dynamic> event) {
- Map<dynamic, dynamic> result = event;
- String annotAttrColor =
- result[EventParameters.annotAttrColor] ?? Colors.red.toHex();
- int annotAttrAlpha = result[EventParameters.annotAttrAlpha] ?? 255;
- num borderWidth = result[EventParameters.annotAttrBorderWidth] ?? 2.0;
- String borderColor =
- result[EventParameters.annotAttrBorderColor] ?? Colors.red.toHex();
- int borderColorAlpha =
- result[EventParameters.annotAttrBorderColorAlpha] ?? 255;
- String fillColor =
- result[EventParameters.annotAttrFillColor] ?? Colors.red.toHex();
- int fillColorAlpha = result[EventParameters.annotAttrFillColorAlpha] ?? 255;
- String shapeTypeStr = result[EventParameters.annotAttrShapeType] ?? '';
- AnnotationType shapeType = shapeTypeStr.isEmpty
- ? annotationType
- : AnnotationType.values.byName(shapeTypeStr);
- bool fontBold = result[EventParameters.annotAttrFontBold] ?? false;
- bool fontItalic = result[EventParameters.annotAttrFontItalic] ?? false;
- String textColor =
- result[EventParameters.annotAttrTextColor] ?? Colors.black.toHex();
- int textColorAlpha = result[EventParameters.annotAttrTextColorAlpha] ?? 255;
- num fontSize = result[EventParameters.annotAttrFontSize] ?? 40;
- String fontType =
- result[EventParameters.annotAttrFontType] ?? FontType.helvetica.name;
- String linkType = result[EventParameters.annotLinkType] ?? LinkType.website.name;
- String linkWebSite = result[EventParameters.annotLinkWeb] ?? '';
- int linkPage = result[EventParameters.annotLinkPage] ?? 1;
- String linkEmail = result[EventParameters.annotLinkEmail] ?? '';
- return AnnotAttributeBean(
- color: HexColor.fromHex(annotAttrColor),
- alpha: annotAttrAlpha,
- borderWidth: borderWidth.toDouble(),
- borderColor: HexColor.fromHex(borderColor),
- borderColorAlpha: borderColorAlpha,
- fillColor: HexColor.fromHex(fillColor),
- fillColorAlpha: fillColorAlpha,
- shapeType: shapeType,
- showShapeTypeWidget: false,
- fontBold: fontBold,
- fontItalic: fontItalic,
- textColor: HexColor.fromHex(textColor),
- textColorAlpha: textColorAlpha,
- fontSize: fontSize.toInt(),
- fontType: FontType.values.byName(fontType.toLowerCase()),
- linkType: LinkType.values.byName(linkType.toLowerCase()),
- linkWeb: linkWebSite,
- linkPage: linkPage,
- linkEmail: linkEmail);
- }
- Map<dynamic, dynamic> toMapValues(AnnotationType annotationType) {
- switch (annotationType) {
- case AnnotationType.highlight:
- case AnnotationType.underline:
- case AnnotationType.squiggly:
- case AnnotationType.strikeout:
- return {
- EventParameters.annotAttrColor: color.toHex(),
- EventParameters.annotAttrAlpha: alpha,
- };
- case AnnotationType.ink:
- return {
- EventParameters.annotType: annotationType.name,
- EventParameters.annotAttrColor: color.toHex(),
- EventParameters.annotAttrAlpha: alpha,
- EventParameters.annotAttrBorderWidth: borderWidth,
- };
- case AnnotationType.shape:
- case AnnotationType.arrow:
- case AnnotationType.circle:
- case AnnotationType.square:
- case AnnotationType.line:
- return {
- EventParameters.annotType: annotationType.name,
- EventParameters.annotAttrShapeType: shapeType.name,
- EventParameters.annotAttrBorderWidth: borderWidth,
- EventParameters.annotAttrBorderColor: borderColor.toHex(),
- EventParameters.annotAttrBorderColorAlpha: borderColorAlpha,
- EventParameters.annotAttrFillColor: fillColor.toHex(),
- EventParameters.annotAttrFillColorAlpha: fillColorAlpha,
- };
- case AnnotationType.freetext:
- return {
- EventParameters.annotType: annotationType.name,
- EventParameters.annotAttrFontBold: fontBold,
- EventParameters.annotAttrFontItalic: fontItalic,
- EventParameters.annotAttrTextColor: textColor.toHex(),
- EventParameters.annotAttrTextColorAlpha: textColorAlpha,
- EventParameters.annotAttrFontSize: fontSize,
- EventParameters.annotAttrFontType: fontType.name,
- };
- case AnnotationType.signature:
- return {
- EventParameters.annotType: annotationType.name,
- EventParameters.annotImagePath: imagePath,
- };
- case AnnotationType.stamp:
- if (standardStampName.isNotEmpty) {
- return {
- EventParameters.annotType: annotationType.name,
- EventParameters.annotStandardStampName: standardStampName,
- };
- } else {
- return {
- EventParameters.annotType: annotationType.name,
- EventParameters.annotTextStampContent: customStampBean?.content,
- EventParameters.annotTextStampDate: customStampBean?.getDateStr(),
- EventParameters.annotTextStampStyleShapeType:
- customStampBean?.shape.type,
- EventParameters.annotTextStampStyleColorType:
- customStampBean?.color.type
- };
- }
- case AnnotationType.link:
- switch (linkType) {
- case LinkType.website:
- return {
- EventParameters.annotType: annotationType.name,
- EventParameters.annotLinkType: linkType.name,
- EventParameters.annotLinkWeb: linkWeb,
- EventParameters.annotLinkCancelCreate: cancelCreateLink
- };
- case LinkType.page:
- return {
- EventParameters.annotType: annotationType.name,
- EventParameters.annotLinkType: linkType.name,
- EventParameters.annotLinkPage: linkPage,
- EventParameters.annotLinkCancelCreate: cancelCreateLink
- };
- case LinkType.email:
- return {
- EventParameters.annotType: annotationType.name,
- EventParameters.annotLinkType: linkType.name,
- EventParameters.annotLinkEmail: linkEmail,
- EventParameters.annotLinkCancelCreate: cancelCreateLink
- };
- }
- case AnnotationType.unknown:
- return {};
- default:
- return {};
- }
- }
- }
|