Showing
5 changed files
with
140 additions
and
62 deletions
| @@ -17,7 +17,6 @@ | @@ -17,7 +17,6 @@ | ||
| 17 | import 'package:pdf/pdf.dart'; | 17 | import 'package:pdf/pdf.dart'; |
| 18 | import 'package:vector_math/vector_math_64.dart'; | 18 | import 'package:vector_math/vector_math_64.dart'; |
| 19 | 19 | ||
| 20 | -import 'basic.dart'; | ||
| 21 | import 'geometry.dart'; | 20 | import 'geometry.dart'; |
| 22 | import 'text_style.dart'; | 21 | import 'text_style.dart'; |
| 23 | import 'theme.dart'; | 22 | import 'theme.dart'; |
| @@ -285,45 +284,6 @@ class Signature extends Annotation { | @@ -285,45 +284,6 @@ class Signature extends Annotation { | ||
| 285 | )); | 284 | )); |
| 286 | } | 285 | } |
| 287 | 286 | ||
| 288 | -class TextField extends Annotation { | ||
| 289 | - TextField({ | ||
| 290 | - Widget? child, | ||
| 291 | - double width = 120, | ||
| 292 | - double height = 13, | ||
| 293 | - required String name, | ||
| 294 | - PdfBorder? border, | ||
| 295 | - Set<PdfAnnotFlags>? flags, | ||
| 296 | - DateTime? date, | ||
| 297 | - PdfColor? color, | ||
| 298 | - PdfColor? backgroundColor, | ||
| 299 | - PdfAnnotHighlighting? highlighting, | ||
| 300 | - int? maxLength, | ||
| 301 | - String? alternateName, | ||
| 302 | - String? mappingName, | ||
| 303 | - Set<PdfFieldFlags>? fieldFlags, | ||
| 304 | - String? value, | ||
| 305 | - String? defaultValue, | ||
| 306 | - TextStyle? textStyle, | ||
| 307 | - }) : super( | ||
| 308 | - child: child ?? SizedBox(width: width, height: height), | ||
| 309 | - builder: AnnotationTextField( | ||
| 310 | - name: name, | ||
| 311 | - border: border, | ||
| 312 | - flags: flags, | ||
| 313 | - date: date, | ||
| 314 | - color: color, | ||
| 315 | - backgroundColor: backgroundColor, | ||
| 316 | - highlighting: highlighting, | ||
| 317 | - maxLength: maxLength, | ||
| 318 | - alternateName: alternateName, | ||
| 319 | - mappingName: mappingName, | ||
| 320 | - fieldFlags: fieldFlags, | ||
| 321 | - value: value, | ||
| 322 | - defaultValue: defaultValue, | ||
| 323 | - textStyle: textStyle, | ||
| 324 | - )); | ||
| 325 | -} | ||
| 326 | - | ||
| 327 | class Outline extends Anchor { | 287 | class Outline extends Anchor { |
| 328 | Outline({ | 288 | Outline({ |
| 329 | Widget? child, | 289 | Widget? child, |
| @@ -17,11 +17,13 @@ | @@ -17,11 +17,13 @@ | ||
| 17 | import 'package:pdf/pdf.dart'; | 17 | import 'package:pdf/pdf.dart'; |
| 18 | import 'package:vector_math/vector_math_64.dart'; | 18 | import 'package:vector_math/vector_math_64.dart'; |
| 19 | 19 | ||
| 20 | +import 'basic.dart'; | ||
| 20 | import 'border_radius.dart'; | 21 | import 'border_radius.dart'; |
| 21 | import 'box_border.dart'; | 22 | import 'box_border.dart'; |
| 22 | import 'container.dart'; | 23 | import 'container.dart'; |
| 23 | import 'decoration.dart'; | 24 | import 'decoration.dart'; |
| 24 | import 'geometry.dart'; | 25 | import 'geometry.dart'; |
| 26 | +import 'text.dart'; | ||
| 25 | import 'text_style.dart'; | 27 | import 'text_style.dart'; |
| 26 | import 'theme.dart'; | 28 | import 'theme.dart'; |
| 27 | import 'widget.dart'; | 29 | import 'widget.dart'; |
| @@ -98,6 +100,7 @@ class FlatButton extends SingleChildWidget { | @@ -98,6 +100,7 @@ class FlatButton extends SingleChildWidget { | ||
| 98 | PdfColor colorRollover = PdfColors.blueAccent, | 100 | PdfColor colorRollover = PdfColors.blueAccent, |
| 99 | EdgeInsets? padding, | 101 | EdgeInsets? padding, |
| 100 | BoxDecoration? decoration, | 102 | BoxDecoration? decoration, |
| 103 | + this.flags, | ||
| 101 | required Widget child, | 104 | required Widget child, |
| 102 | required this.name, | 105 | required this.name, |
| 103 | }) : _childDown = Container( | 106 | }) : _childDown = Container( |
| @@ -148,6 +151,8 @@ class FlatButton extends SingleChildWidget { | @@ -148,6 +151,8 @@ class FlatButton extends SingleChildWidget { | ||
| 148 | 151 | ||
| 149 | final Widget _childRollover; | 152 | final Widget _childRollover; |
| 150 | 153 | ||
| 154 | + final Set<PdfAnnotFlags>? flags; | ||
| 155 | + | ||
| 151 | @override | 156 | @override |
| 152 | void paint(Context context) { | 157 | void paint(Context context) { |
| 153 | super.paint(context); | 158 | super.paint(context); |
| @@ -155,7 +160,7 @@ class FlatButton extends SingleChildWidget { | @@ -155,7 +160,7 @@ class FlatButton extends SingleChildWidget { | ||
| 155 | final bf = PdfButtonField( | 160 | final bf = PdfButtonField( |
| 156 | rect: context.localToGlobal(box!), | 161 | rect: context.localToGlobal(box!), |
| 157 | fieldName: name, | 162 | fieldName: name, |
| 158 | - flags: <PdfAnnotFlags>{PdfAnnotFlags.print}, | 163 | + flags: flags, |
| 159 | fieldFlags: <PdfFieldFlags>{PdfFieldFlags.pushButton}, | 164 | fieldFlags: <PdfFieldFlags>{PdfFieldFlags.pushButton}, |
| 160 | ); | 165 | ); |
| 161 | 166 | ||
| @@ -168,27 +173,137 @@ class FlatButton extends SingleChildWidget { | @@ -168,27 +173,137 @@ class FlatButton extends SingleChildWidget { | ||
| 168 | ..leftTranslate(-translation.x, -translation.y) | 173 | ..leftTranslate(-translation.x, -translation.y) |
| 169 | ..translate(box!.x, box!.y); | 174 | ..translate(box!.x, box!.y); |
| 170 | 175 | ||
| 171 | - final cn = context.copyWith( | ||
| 172 | - canvas: bf.appearance(context.document, PdfAnnotAppearance.normal, | ||
| 173 | - matrix: mat, boundingBox: box)); | ||
| 174 | - child!.layout( | ||
| 175 | - cn, BoxConstraints.tightFor(width: box!.width, height: box!.height)); | ||
| 176 | - child!.paint(cn); | ||
| 177 | - | ||
| 178 | - final cd = context.copyWith( | ||
| 179 | - canvas: bf.appearance(context.document, PdfAnnotAppearance.down, | ||
| 180 | - matrix: mat, boundingBox: box)); | ||
| 181 | - _childDown.layout( | ||
| 182 | - cd, BoxConstraints.tightFor(width: box!.width, height: box!.height)); | ||
| 183 | - _childDown.paint(cd); | ||
| 184 | - | ||
| 185 | - final cr = context.copyWith( | ||
| 186 | - canvas: bf.appearance(context.document, PdfAnnotAppearance.rollover, | ||
| 187 | - matrix: mat, boundingBox: box)); | ||
| 188 | - _childRollover.layout( | ||
| 189 | - cr, BoxConstraints.tightFor(width: box!.width, height: box!.height)); | ||
| 190 | - _childRollover.paint(cr); | 176 | + var canvas = bf.appearance(context.document, PdfAnnotAppearance.normal, |
| 177 | + matrix: mat, boundingBox: box); | ||
| 178 | + Widget.draw( | ||
| 179 | + child!, | ||
| 180 | + offset: PdfPoint.zero, | ||
| 181 | + canvas: canvas, | ||
| 182 | + page: context.page, | ||
| 183 | + constraints: | ||
| 184 | + BoxConstraints.tightFor(width: box!.width, height: box!.height), | ||
| 185 | + ); | ||
| 186 | + | ||
| 187 | + canvas = bf.appearance(context.document, PdfAnnotAppearance.down, | ||
| 188 | + matrix: mat, boundingBox: box); | ||
| 189 | + Widget.draw( | ||
| 190 | + _childDown, | ||
| 191 | + offset: PdfPoint.zero, | ||
| 192 | + canvas: canvas, | ||
| 193 | + page: context.page, | ||
| 194 | + constraints: | ||
| 195 | + BoxConstraints.tightFor(width: box!.width, height: box!.height), | ||
| 196 | + ); | ||
| 197 | + | ||
| 198 | + canvas = bf.appearance(context.document, PdfAnnotAppearance.rollover, | ||
| 199 | + matrix: mat, boundingBox: box); | ||
| 200 | + Widget.draw( | ||
| 201 | + _childRollover, | ||
| 202 | + offset: PdfPoint.zero, | ||
| 203 | + canvas: canvas, | ||
| 204 | + page: context.page, | ||
| 205 | + constraints: | ||
| 206 | + BoxConstraints.tightFor(width: box!.width, height: box!.height), | ||
| 207 | + ); | ||
| 191 | 208 | ||
| 192 | PdfAnnot(context.page, bf); | 209 | PdfAnnot(context.page, bf); |
| 193 | } | 210 | } |
| 194 | } | 211 | } |
| 212 | + | ||
| 213 | +class TextField extends StatelessWidget { | ||
| 214 | + TextField({ | ||
| 215 | + this.child, | ||
| 216 | + this.width = 120, | ||
| 217 | + this.height = 13, | ||
| 218 | + required this.name, | ||
| 219 | + this.border, | ||
| 220 | + this.flags, | ||
| 221 | + this.date, | ||
| 222 | + this.color, | ||
| 223 | + this.backgroundColor, | ||
| 224 | + this.highlighting, | ||
| 225 | + this.maxLength, | ||
| 226 | + this.alternateName, | ||
| 227 | + this.mappingName, | ||
| 228 | + this.fieldFlags, | ||
| 229 | + this.value, | ||
| 230 | + this.defaultValue, | ||
| 231 | + this.textStyle, | ||
| 232 | + }); | ||
| 233 | + | ||
| 234 | + final Widget? child; | ||
| 235 | + final double width; | ||
| 236 | + final double height; | ||
| 237 | + final String name; | ||
| 238 | + final PdfBorder? border; | ||
| 239 | + final Set<PdfAnnotFlags>? flags; | ||
| 240 | + final DateTime? date; | ||
| 241 | + final PdfColor? color; | ||
| 242 | + final PdfColor? backgroundColor; | ||
| 243 | + final PdfAnnotHighlighting? highlighting; | ||
| 244 | + final int? maxLength; | ||
| 245 | + final String? alternateName; | ||
| 246 | + final String? mappingName; | ||
| 247 | + final Set<PdfFieldFlags>? fieldFlags; | ||
| 248 | + final String? value; | ||
| 249 | + final String? defaultValue; | ||
| 250 | + final TextStyle? textStyle; | ||
| 251 | + | ||
| 252 | + @override | ||
| 253 | + Widget build(Context context) { | ||
| 254 | + return child ?? SizedBox(width: width, height: height); | ||
| 255 | + } | ||
| 256 | + | ||
| 257 | + @override | ||
| 258 | + void paint(Context context) { | ||
| 259 | + super.paint(context); | ||
| 260 | + | ||
| 261 | + final _textStyle = Theme.of(context).defaultTextStyle.merge(textStyle); | ||
| 262 | + | ||
| 263 | + final tf = PdfTextField( | ||
| 264 | + rect: context.localToGlobal(box!), | ||
| 265 | + fieldName: name, | ||
| 266 | + border: border, | ||
| 267 | + flags: flags ?? const {PdfAnnotFlags.print}, | ||
| 268 | + date: date, | ||
| 269 | + color: color, | ||
| 270 | + backgroundColor: backgroundColor, | ||
| 271 | + highlighting: highlighting, | ||
| 272 | + maxLength: maxLength, | ||
| 273 | + alternateName: alternateName, | ||
| 274 | + mappingName: mappingName, | ||
| 275 | + fieldFlags: fieldFlags, | ||
| 276 | + value: value, | ||
| 277 | + defaultValue: defaultValue, | ||
| 278 | + font: _textStyle.font!.getFont(context)!, | ||
| 279 | + fontSize: _textStyle.fontSize!, | ||
| 280 | + textColor: _textStyle.color!, | ||
| 281 | + ); | ||
| 282 | + | ||
| 283 | + final mat = context.canvas.getTransform(); | ||
| 284 | + final translation = Vector3(0, 0, 0); | ||
| 285 | + final rotation = Quaternion(0, 0, 0, 0); | ||
| 286 | + final scale = Vector3(0, 0, 0); | ||
| 287 | + mat | ||
| 288 | + ..decompose(translation, rotation, scale) | ||
| 289 | + ..leftTranslate(-translation.x, -translation.y) | ||
| 290 | + ..translate(box!.x, box!.y); | ||
| 291 | + | ||
| 292 | + if (value != null) { | ||
| 293 | + final canvas = tf.appearance(context.document, PdfAnnotAppearance.normal, | ||
| 294 | + matrix: mat, boundingBox: box); | ||
| 295 | + canvas.buf.putString('/Tx BMC\n'); | ||
| 296 | + Widget.draw( | ||
| 297 | + Text(value!, style: _textStyle), | ||
| 298 | + offset: PdfPoint.zero, | ||
| 299 | + canvas: canvas, | ||
| 300 | + page: context.page, | ||
| 301 | + constraints: | ||
| 302 | + BoxConstraints.tightFor(width: box!.width, height: box!.height), | ||
| 303 | + ); | ||
| 304 | + canvas.buf.putString('EMC\n'); | ||
| 305 | + } | ||
| 306 | + | ||
| 307 | + PdfAnnot(context.page, tf); | ||
| 308 | + } | ||
| 309 | +} |
| @@ -81,13 +81,15 @@ void main() { | @@ -81,13 +81,15 @@ void main() { | ||
| 81 | Decorated( | 81 | Decorated( |
| 82 | child: TextField( | 82 | child: TextField( |
| 83 | name: 'Given Name', | 83 | name: 'Given Name', |
| 84 | + value: 'David', | ||
| 84 | textStyle: const TextStyle(color: PdfColors.amber), | 85 | textStyle: const TextStyle(color: PdfColors.amber), |
| 85 | )), | 86 | )), |
| 86 | // | 87 | // |
| 87 | SizedBox(width: double.infinity, height: 10), | 88 | SizedBox(width: double.infinity, height: 10), |
| 88 | // | 89 | // |
| 89 | Label(label: 'Family Name:', width: 100), | 90 | Label(label: 'Family Name:', width: 100), |
| 90 | - Decorated(child: TextField(name: 'Family Name')), | 91 | + Decorated( |
| 92 | + child: TextField(name: 'Family Name', value: 'PHAM-VAN')), | ||
| 91 | // | 93 | // |
| 92 | SizedBox(width: double.infinity, height: 10), | 94 | SizedBox(width: double.infinity, height: 10), |
| 93 | // | 95 | // |
No preview for this file type
-
Please register or login to post a comment