David PHAM-VAN

Add support for existing reference objects

... ... @@ -3,6 +3,7 @@
## 3.10.8
- Add Flutter's Logical Pixel constant
- Add support for existing reference objects
## 3.10.7
... ...
... ... @@ -104,8 +104,10 @@ class PdfChoiceField extends PdfAnnotWidget {
}
class PdfAnnot extends PdfObject<PdfDict> {
PdfAnnot(this.pdfPage, this.annot)
PdfAnnot(this.pdfPage, this.annot, {int? objser, int objgen = 0})
: super(pdfPage.pdfDocument,
objser: objser,
objgen: objgen,
params: PdfDict.values({
'/Type': const PdfName('/Annot'),
})) {
... ...
... ... @@ -142,7 +142,10 @@ class PdfCatalog extends PdfObject<PdfDict> {
(acroForm['/SigFlags'] as PdfNum? ?? const PdfNum(0));
final fields = (acroForm['/Fields'] ??= PdfArray()) as PdfArray;
for (final w in widgets) {
fields.add(w.ref());
final ref = w.ref();
if (!fields.values.contains(ref)) {
fields.add(ref);
}
}
}
}
... ...
... ... @@ -19,6 +19,7 @@ import 'dart:math';
import 'package:vector_math/vector_math_64.dart';
import '../../pdf.dart';
import '../pdf/format/indirect.dart';
import 'geometry.dart';
import 'shape.dart';
import 'text_style.dart';
... ... @@ -32,6 +33,7 @@ class Anchor extends SingleChildWidget {
this.description,
this.zoom,
this.setX = false,
this.replaces,
}) : super(child: child);
final String name;
... ... @@ -42,6 +44,8 @@ class Anchor extends SingleChildWidget {
final bool setX;
final PdfIndirect? replaces;
@override
void paint(Context context) {
super.paint(context);
... ... @@ -60,7 +64,12 @@ class Anchor extends SingleChildWidget {
if (description != null) {
final rb = mat.transform3(Vector3(box!.right, box!.top, 0));
final iBox = PdfRect.fromLTRB(lt.x, lt.y, rb.x, rb.y);
PdfAnnot(context.page, PdfAnnotText(rect: iBox, content: description!));
PdfAnnot(
context.page,
PdfAnnotText(rect: iBox, content: description!),
objser: replaces?.ser,
objgen: replaces?.gen ?? 0,
);
}
}
}
... ... @@ -70,10 +79,12 @@ abstract class AnnotationBuilder {
}
class AnnotationLink extends AnnotationBuilder {
AnnotationLink(this.destination);
AnnotationLink(this.destination, {this.replaces});
final String destination;
final PdfIndirect? replaces;
@override
PdfAnnot build(Context context, PdfRect? box) {
return PdfAnnot(
... ... @@ -82,6 +93,8 @@ class AnnotationLink extends AnnotationBuilder {
rect: context.localToGlobal(box!),
dest: destination,
),
objser: replaces?.ser,
objgen: replaces?.gen ?? 0,
);
}
}
... ... @@ -92,6 +105,7 @@ class AnnotationUrl extends AnnotationBuilder {
this.date,
this.subject,
this.author,
this.replaces,
});
final String destination;
... ... @@ -102,6 +116,8 @@ class AnnotationUrl extends AnnotationBuilder {
final String? subject;
final PdfIndirect? replaces;
@override
PdfAnnot build(Context context, PdfRect? box) {
return PdfAnnot(
... ... @@ -113,6 +129,8 @@ class AnnotationUrl extends AnnotationBuilder {
author: author,
subject: subject,
),
objser: replaces?.ser,
objgen: replaces?.gen ?? 0,
);
}
}
... ... @@ -126,6 +144,7 @@ class AnnotationSquare extends AnnotationBuilder {
this.date,
this.subject,
this.content,
this.replaces,
});
final PdfColor? color;
... ... @@ -142,6 +161,8 @@ class AnnotationSquare extends AnnotationBuilder {
final String? content;
final PdfIndirect? replaces;
@override
PdfAnnot build(Context context, PdfRect? box) {
return PdfAnnot(
... ... @@ -155,6 +176,8 @@ class AnnotationSquare extends AnnotationBuilder {
author: author,
subject: subject,
),
objser: replaces?.ser,
objgen: replaces?.gen ?? 0,
);
}
}
... ... @@ -168,6 +191,7 @@ class AnnotationCircle extends AnnotationBuilder {
this.date,
this.subject,
this.content,
this.replaces,
});
final PdfColor? color;
... ... @@ -184,6 +208,8 @@ class AnnotationCircle extends AnnotationBuilder {
final String? content;
final PdfIndirect? replaces;
@override
PdfAnnot build(Context context, PdfRect? box) {
return PdfAnnot(
... ... @@ -197,6 +223,8 @@ class AnnotationCircle extends AnnotationBuilder {
author: author,
subject: subject,
),
objser: replaces?.ser,
objgen: replaces?.gen ?? 0,
);
}
}
... ... @@ -211,6 +239,7 @@ class AnnotationPolygon extends AnnotationBuilder {
this.date,
this.subject,
this.content,
this.replaces,
});
final List<PdfPoint> points;
... ... @@ -229,6 +258,8 @@ class AnnotationPolygon extends AnnotationBuilder {
final String? content;
final PdfIndirect? replaces;
@override
PdfAnnot build(Context context, PdfRect? box) {
final globalPoints =
... ... @@ -254,7 +285,12 @@ class AnnotationPolygon extends AnnotationBuilder {
subject: subject,
);
return PdfAnnot(context.page, pdfAnnotPolygon);
return PdfAnnot(
context.page,
pdfAnnotPolygon,
objser: replaces?.ser,
objgen: replaces?.gen ?? 0,
);
}
}
... ... @@ -267,6 +303,7 @@ class AnnotationInk extends AnnotationBuilder {
this.date,
this.subject,
this.content,
this.replaces,
});
final List<List<PdfPoint>> points;
... ... @@ -283,6 +320,8 @@ class AnnotationInk extends AnnotationBuilder {
final String? content;
final PdfIndirect? replaces;
@override
PdfAnnot build(Context context, PdfRect? box) {
final globalPoints = points
... ... @@ -313,7 +352,12 @@ class AnnotationInk extends AnnotationBuilder {
content: content,
);
return PdfAnnot(context.page, pdfAnnotInk);
return PdfAnnot(
context.page,
pdfAnnotInk,
objser: replaces?.ser,
objgen: replaces?.gen ?? 0,
);
}
}
... ... @@ -335,6 +379,7 @@ class AnnotationTextField extends AnnotationBuilder {
this.value,
this.defaultValue,
this.textStyle,
this.replaces,
});
final String? name;
... ... @@ -369,6 +414,8 @@ class AnnotationTextField extends AnnotationBuilder {
final String? subject;
final PdfIndirect? replaces;
@override
PdfAnnot build(Context context, PdfRect? box) {
final _textStyle = Theme.of(context).defaultTextStyle.merge(textStyle);
... ... @@ -396,6 +443,8 @@ class AnnotationTextField extends AnnotationBuilder {
fontSize: _textStyle.fontSize!,
textColor: _textStyle.color!,
),
objser: replaces?.ser,
objgen: replaces?.gen ?? 0,
);
}
}
... ...
... ... @@ -20,6 +20,7 @@ import 'dart:typed_data';
import 'package:vector_math/vector_math_64.dart';
import '../../pdf.dart';
import '../pdf/format/indirect.dart';
import 'basic.dart';
import 'border_radius.dart';
import 'box_border.dart';
... ... @@ -89,6 +90,7 @@ class ChoiceField extends StatelessWidget with AnnotationAppearance {
required this.name,
required this.items,
this.value,
this.replaces,
});
final String name;
final TextStyle? textStyle;
... ... @@ -96,6 +98,7 @@ class ChoiceField extends StatelessWidget with AnnotationAppearance {
final double height;
final List<String> items;
final String? value;
final PdfIndirect? replaces;
@override
void paint(Context context) {
... ... @@ -125,7 +128,12 @@ class ChoiceField extends StatelessWidget with AnnotationAppearance {
);
}
PdfAnnot(context.page, bf);
PdfAnnot(
context.page,
bf,
objser: replaces?.ser,
objgen: replaces?.gen ?? 0,
);
}
@override
... ... @@ -144,6 +152,7 @@ class Checkbox extends SingleChildWidget with AnnotationAppearance {
double width = 13,
double height = 13,
BoxDecoration? decoration,
this.replaces,
}) : radius = decoration?.shape == BoxShape.circle
? Radius.circular(math.max(height, width) / 2)
: decoration?.borderRadius?.uniform ?? Radius.zero,
... ... @@ -171,6 +180,8 @@ class Checkbox extends SingleChildWidget with AnnotationAppearance {
final Radius radius;
final PdfIndirect? replaces;
@override
void paint(Context context) {
super.paint(context);
... ... @@ -217,7 +228,12 @@ class Checkbox extends SingleChildWidget with AnnotationAppearance {
child!,
);
PdfAnnot(context.page, bf);
PdfAnnot(
context.page,
bf,
objser: replaces?.ser,
objgen: replaces?.gen ?? 0,
);
}
}
... ... @@ -232,6 +248,7 @@ class FlatButton extends SingleChildWidget with AnnotationAppearance {
this.flags,
required Widget child,
required this.name,
this.replaces,
}) : _childDown = Container(
child: DefaultTextStyle(
style: TextStyle(color: textColor),
... ... @@ -282,6 +299,8 @@ class FlatButton extends SingleChildWidget with AnnotationAppearance {
final Set<PdfAnnotFlags>? flags;
final PdfIndirect? replaces;
@override
void paint(Context context) {
super.paint(context);
... ... @@ -300,7 +319,12 @@ class FlatButton extends SingleChildWidget with AnnotationAppearance {
drawAppearance(context, bf, mat, _childRollover,
type: PdfAnnotAppearance.rollover);
PdfAnnot(context.page, bf);
PdfAnnot(
context.page,
bf,
objser: replaces?.ser,
objgen: replaces?.gen ?? 0,
);
}
}
... ... @@ -323,6 +347,7 @@ class TextField extends StatelessWidget with AnnotationAppearance {
this.value,
this.defaultValue,
this.textStyle,
this.replaces,
});
final Widget? child;
... ... @@ -342,6 +367,7 @@ class TextField extends StatelessWidget with AnnotationAppearance {
final String? value;
final String? defaultValue;
final TextStyle? textStyle;
final PdfIndirect? replaces;
@override
Widget build(Context context) {
... ... @@ -386,7 +412,12 @@ class TextField extends StatelessWidget with AnnotationAppearance {
);
}
PdfAnnot(context.page, tf);
PdfAnnot(
context.page,
tf,
objser: replaces?.ser,
objgen: replaces?.gen ?? 0,
);
}
}
... ... @@ -405,6 +436,7 @@ class Signature extends SingleChildWidget with AnnotationAppearance {
this.crl,
this.cert,
this.ocsp,
this.replaces,
}) : value = value ?? crypto,
super(child: child);
... ... @@ -440,6 +472,8 @@ class Signature extends SingleChildWidget with AnnotationAppearance {
/// Online Certificate Status Protocol
final List<Uint8List>? ocsp;
final PdfIndirect? replaces;
@override
void paint(Context context) {
super.paint(context);
... ... @@ -475,6 +509,11 @@ class Signature extends SingleChildWidget with AnnotationAppearance {
drawAppearance(context, bf, mat, child!);
}
PdfAnnot(context.page, bf);
PdfAnnot(
context.page,
bf,
objser: replaces?.ser,
objgen: replaces?.gen ?? 0,
);
}
}
... ...