Showing
7 changed files
with
43 additions
and
36 deletions
@@ -82,7 +82,7 @@ enum PdfAnnotFlags { | @@ -82,7 +82,7 @@ enum PdfAnnotFlags { | ||
82 | lockedContent, | 82 | lockedContent, |
83 | } | 83 | } |
84 | 84 | ||
85 | -enum PdfAnnotApparence { | 85 | +enum PdfAnnotAppearance { |
86 | normal, | 86 | normal, |
87 | rollover, | 87 | rollover, |
88 | down, | 88 | down, |
@@ -125,6 +125,8 @@ abstract class PdfAnnotBase { | @@ -125,6 +125,8 @@ abstract class PdfAnnotBase { | ||
125 | 125 | ||
126 | final Map<String?, PdfDataType> _appearances = <String?, PdfDataType>{}; | 126 | final Map<String?, PdfDataType> _appearances = <String?, PdfDataType>{}; |
127 | 127 | ||
128 | + PdfName? _as; | ||
129 | + | ||
128 | int get flagValue { | 130 | int get flagValue { |
129 | if (flags == null || flags!.isEmpty) { | 131 | if (flags == null || flags!.isEmpty) { |
130 | return 0; | 132 | return 0; |
@@ -137,21 +139,22 @@ abstract class PdfAnnotBase { | @@ -137,21 +139,22 @@ abstract class PdfAnnotBase { | ||
137 | 139 | ||
138 | PdfGraphics appearance( | 140 | PdfGraphics appearance( |
139 | PdfDocument pdfDocument, | 141 | PdfDocument pdfDocument, |
140 | - PdfAnnotApparence type, { | 142 | + PdfAnnotAppearance type, { |
141 | String? name, | 143 | String? name, |
142 | Matrix4? matrix, | 144 | Matrix4? matrix, |
143 | PdfRect? boundingBox, | 145 | PdfRect? boundingBox, |
146 | + bool selected = false, | ||
144 | }) { | 147 | }) { |
145 | final s = PdfGraphicXObject(pdfDocument, '/Form'); | 148 | final s = PdfGraphicXObject(pdfDocument, '/Form'); |
146 | String? n; | 149 | String? n; |
147 | switch (type) { | 150 | switch (type) { |
148 | - case PdfAnnotApparence.normal: | 151 | + case PdfAnnotAppearance.normal: |
149 | n = '/N'; | 152 | n = '/N'; |
150 | break; | 153 | break; |
151 | - case PdfAnnotApparence.rollover: | 154 | + case PdfAnnotAppearance.rollover: |
152 | n = '/R'; | 155 | n = '/R'; |
153 | break; | 156 | break; |
154 | - case PdfAnnotApparence.down: | 157 | + case PdfAnnotAppearance.down: |
155 | n = '/D'; | 158 | n = '/D'; |
156 | break; | 159 | break; |
157 | } | 160 | } |
@@ -182,6 +185,10 @@ abstract class PdfAnnotBase { | @@ -182,6 +185,10 @@ abstract class PdfAnnotBase { | ||
182 | s.params['/BBox'] = | 185 | s.params['/BBox'] = |
183 | PdfArray.fromNum(<double?>[bbox.x, bbox.y, bbox.width, bbox.height]); | 186 | PdfArray.fromNum(<double?>[bbox.x, bbox.y, bbox.width, bbox.height]); |
184 | final g = PdfGraphics(s, s.buf); | 187 | final g = PdfGraphics(s, s.buf); |
188 | + | ||
189 | + if (selected && name != null) { | ||
190 | + _as = PdfName(name); | ||
191 | + } | ||
185 | return g; | 192 | return g; |
186 | } | 193 | } |
187 | 194 | ||
@@ -223,11 +230,8 @@ abstract class PdfAnnotBase { | @@ -223,11 +230,8 @@ abstract class PdfAnnotBase { | ||
223 | 230 | ||
224 | if (_appearances.isNotEmpty) { | 231 | if (_appearances.isNotEmpty) { |
225 | params['/AP'] = PdfDict(_appearances); | 232 | params['/AP'] = PdfDict(_appearances); |
226 | - if (_appearances['/N'] is PdfDict) { | ||
227 | - final n = _appearances['/N']; | ||
228 | - if (n is PdfDict) { | ||
229 | - params['/AS'] = PdfName(n.values.keys.first!); | ||
230 | - } | 233 | + if (_as != null) { |
234 | + params['/AS'] = _as; | ||
231 | } | 235 | } |
232 | } | 236 | } |
233 | } | 237 | } |
@@ -656,7 +660,7 @@ class PdfTextField extends PdfFormField { | @@ -656,7 +660,7 @@ class PdfTextField extends PdfFormField { | ||
656 | class PdfButtonField extends PdfFormField { | 660 | class PdfButtonField extends PdfFormField { |
657 | PdfButtonField({ | 661 | PdfButtonField({ |
658 | required PdfRect rect, | 662 | required PdfRect rect, |
659 | - String? fieldName, | 663 | + required String fieldName, |
660 | String? alternateName, | 664 | String? alternateName, |
661 | String? mappingName, | 665 | String? mappingName, |
662 | PdfBorder? border, | 666 | PdfBorder? border, |
@@ -683,20 +687,20 @@ class PdfButtonField extends PdfFormField { | @@ -683,20 +687,20 @@ class PdfButtonField extends PdfFormField { | ||
683 | fieldFlags: fieldFlags, | 687 | fieldFlags: fieldFlags, |
684 | ); | 688 | ); |
685 | 689 | ||
686 | - final bool? value; | 690 | + final String? value; |
687 | 691 | ||
688 | - final bool? defaultValue; | 692 | + final String? defaultValue; |
689 | 693 | ||
690 | @override | 694 | @override |
691 | void build(PdfPage page, PdfObject object, PdfDict params) { | 695 | void build(PdfPage page, PdfObject object, PdfDict params) { |
692 | super.build(page, object, params); | 696 | super.build(page, object, params); |
693 | 697 | ||
694 | if (value != null) { | 698 | if (value != null) { |
695 | - params['/V'] = value! ? const PdfName('/Yes') : const PdfName('/Off'); | 699 | + params['/V'] = PdfName(value!); |
696 | } | 700 | } |
701 | + | ||
697 | if (defaultValue != null) { | 702 | if (defaultValue != null) { |
698 | - params['/DV'] = | ||
699 | - defaultValue! ? const PdfName('/Yes') : const PdfName('/Off'); | 703 | + params['/DV'] = PdfName(defaultValue!); |
700 | } | 704 | } |
701 | } | 705 | } |
702 | } | 706 | } |
@@ -290,7 +290,7 @@ class TextField extends Annotation { | @@ -290,7 +290,7 @@ class TextField extends Annotation { | ||
290 | Widget? child, | 290 | Widget? child, |
291 | double width = 120, | 291 | double width = 120, |
292 | double height = 13, | 292 | double height = 13, |
293 | - String? name, | 293 | + required String name, |
294 | PdfBorder? border, | 294 | PdfBorder? border, |
295 | Set<PdfAnnotFlags>? flags, | 295 | Set<PdfAnnotFlags>? flags, |
296 | DateTime? date, | 296 | DateTime? date, |
@@ -29,7 +29,6 @@ import 'widget.dart'; | @@ -29,7 +29,6 @@ import 'widget.dart'; | ||
29 | class Checkbox extends SingleChildWidget { | 29 | class Checkbox extends SingleChildWidget { |
30 | Checkbox({ | 30 | Checkbox({ |
31 | required this.value, | 31 | required this.value, |
32 | - this.defaultValue, | ||
33 | this.tristate = false, | 32 | this.tristate = false, |
34 | this.activeColor = PdfColors.blue, | 33 | this.activeColor = PdfColors.blue, |
35 | this.checkColor = PdfColors.white, | 34 | this.checkColor = PdfColors.white, |
@@ -51,8 +50,6 @@ class Checkbox extends SingleChildWidget { | @@ -51,8 +50,6 @@ class Checkbox extends SingleChildWidget { | ||
51 | 50 | ||
52 | final bool value; | 51 | final bool value; |
53 | 52 | ||
54 | - final bool? defaultValue; | ||
55 | - | ||
56 | final bool tristate; | 53 | final bool tristate; |
57 | 54 | ||
58 | final PdfColor activeColor; | 55 | final PdfColor activeColor; |
@@ -69,13 +66,13 @@ class Checkbox extends SingleChildWidget { | @@ -69,13 +66,13 @@ class Checkbox extends SingleChildWidget { | ||
69 | final bf = PdfButtonField( | 66 | final bf = PdfButtonField( |
70 | rect: context.localToGlobal(box!), | 67 | rect: context.localToGlobal(box!), |
71 | fieldName: name, | 68 | fieldName: name, |
72 | - value: value, | ||
73 | - defaultValue: value, | 69 | + value: value ? '/Yes' : null, |
70 | + defaultValue: value ? '/Yes' : null, | ||
74 | flags: <PdfAnnotFlags>{PdfAnnotFlags.print}, | 71 | flags: <PdfAnnotFlags>{PdfAnnotFlags.print}, |
75 | ); | 72 | ); |
76 | 73 | ||
77 | - final g = | ||
78 | - bf.appearance(context.document, PdfAnnotApparence.normal, name: '/Yes'); | 74 | + final g = bf.appearance(context.document, PdfAnnotAppearance.normal, |
75 | + name: '/Yes', selected: value); | ||
79 | g.drawRect(0, 0, bf.rect.width, bf.rect.height); | 76 | g.drawRect(0, 0, bf.rect.width, bf.rect.height); |
80 | g.setFillColor(activeColor); | 77 | g.setFillColor(activeColor); |
81 | g.fillPath(); | 78 | g.fillPath(); |
@@ -86,7 +83,8 @@ class Checkbox extends SingleChildWidget { | @@ -86,7 +83,8 @@ class Checkbox extends SingleChildWidget { | ||
86 | g.setLineWidth(2); | 83 | g.setLineWidth(2); |
87 | g.strokePath(); | 84 | g.strokePath(); |
88 | 85 | ||
89 | - bf.appearance(context.document, PdfAnnotApparence.normal, name: '/Off'); | 86 | + bf.appearance(context.document, PdfAnnotAppearance.normal, |
87 | + name: '/Off', selected: !value); | ||
90 | 88 | ||
91 | PdfAnnot(context.page, bf); | 89 | PdfAnnot(context.page, bf); |
92 | } | 90 | } |
@@ -144,12 +142,6 @@ class FlatButton extends SingleChildWidget { | @@ -144,12 +142,6 @@ class FlatButton extends SingleChildWidget { | ||
144 | ), | 142 | ), |
145 | ); | 143 | ); |
146 | 144 | ||
147 | - // final PdfColor textColor; | ||
148 | - | ||
149 | - // final PdfColor color; | ||
150 | - | ||
151 | - // final EdgeInsets padding; | ||
152 | - | ||
153 | final String name; | 145 | final String name; |
154 | 146 | ||
155 | final Widget _childDown; | 147 | final Widget _childDown; |
@@ -177,21 +169,21 @@ class FlatButton extends SingleChildWidget { | @@ -177,21 +169,21 @@ class FlatButton extends SingleChildWidget { | ||
177 | ..translate(box!.x, box!.y); | 169 | ..translate(box!.x, box!.y); |
178 | 170 | ||
179 | final cn = context.copyWith( | 171 | final cn = context.copyWith( |
180 | - canvas: bf.appearance(context.document, PdfAnnotApparence.normal, | 172 | + canvas: bf.appearance(context.document, PdfAnnotAppearance.normal, |
181 | matrix: mat, boundingBox: box)); | 173 | matrix: mat, boundingBox: box)); |
182 | child!.layout( | 174 | child!.layout( |
183 | cn, BoxConstraints.tightFor(width: box!.width, height: box!.height)); | 175 | cn, BoxConstraints.tightFor(width: box!.width, height: box!.height)); |
184 | child!.paint(cn); | 176 | child!.paint(cn); |
185 | 177 | ||
186 | final cd = context.copyWith( | 178 | final cd = context.copyWith( |
187 | - canvas: bf.appearance(context.document, PdfAnnotApparence.down, | 179 | + canvas: bf.appearance(context.document, PdfAnnotAppearance.down, |
188 | matrix: mat, boundingBox: box)); | 180 | matrix: mat, boundingBox: box)); |
189 | _childDown.layout( | 181 | _childDown.layout( |
190 | cd, BoxConstraints.tightFor(width: box!.width, height: box!.height)); | 182 | cd, BoxConstraints.tightFor(width: box!.width, height: box!.height)); |
191 | _childDown.paint(cd); | 183 | _childDown.paint(cd); |
192 | 184 | ||
193 | final cr = context.copyWith( | 185 | final cr = context.copyWith( |
194 | - canvas: bf.appearance(context.document, PdfAnnotApparence.rollover, | 186 | + canvas: bf.appearance(context.document, PdfAnnotAppearance.rollover, |
195 | matrix: mat, boundingBox: box)); | 187 | matrix: mat, boundingBox: box)); |
196 | _childRollover.layout( | 188 | _childRollover.layout( |
197 | cr, BoxConstraints.tightFor(width: box!.width, height: box!.height)); | 189 | cr, BoxConstraints.tightFor(width: box!.width, height: box!.height)); |
@@ -4,7 +4,7 @@ description: A pdf producer for Dart. It can create pdf files for both web or fl | @@ -4,7 +4,7 @@ description: A pdf producer for Dart. It can create pdf files for both web or fl | ||
4 | homepage: https://github.com/DavBfr/dart_pdf/tree/master/pdf | 4 | homepage: https://github.com/DavBfr/dart_pdf/tree/master/pdf |
5 | repository: https://github.com/DavBfr/dart_pdf | 5 | repository: https://github.com/DavBfr/dart_pdf |
6 | issue_tracker: https://github.com/DavBfr/dart_pdf/issues | 6 | issue_tracker: https://github.com/DavBfr/dart_pdf/issues |
7 | -version: 3.0.0-nullsafety.1 | 7 | +version: 3.0.0-nullsafety.2 |
8 | 8 | ||
9 | environment: | 9 | environment: |
10 | sdk: ">=2.12.0-0 <3.0.0" | 10 | sdk: ">=2.12.0-0 <3.0.0" |
@@ -118,7 +118,14 @@ void main() { | @@ -118,7 +118,14 @@ void main() { | ||
118 | Checkbox( | 118 | Checkbox( |
119 | name: 'Checkbox', | 119 | name: 'Checkbox', |
120 | value: true, | 120 | value: true, |
121 | - defaultValue: true, | 121 | + ), |
122 | + // | ||
123 | + SizedBox(width: 20, height: 10), | ||
124 | + // | ||
125 | + Label(label: 'unchecked:', width: 100), | ||
126 | + Checkbox( | ||
127 | + name: 'Unchecked', | ||
128 | + value: false, | ||
122 | ), | 129 | ), |
123 | // | 130 | // |
124 | SizedBox(width: double.infinity, height: 10), | 131 | SizedBox(width: double.infinity, height: 10), |
No preview for this file type
-
Please register or login to post a comment