David PHAM-VAN

Add FullPage widget

... ... @@ -17,6 +17,7 @@
- Implement Image orientation
- Add Exif reader
- Add support for GreyScale Jpeg
- Add FullPage widget
## 1.3.23
... ...
... ... @@ -666,3 +666,74 @@ class Builder extends StatelessWidget {
@override
Widget build(Context context) => builder(context);
}
class FullPage extends SingleChildWidget {
FullPage({
@required this.ignoreMargins,
Widget child,
}) : assert(ignoreMargins != null),
super(child: child);
final bool ignoreMargins;
BoxConstraints _getConstraints(Context context) {
return ignoreMargins
? BoxConstraints.tightFor(
width: context.page.pageFormat.width,
height: context.page.pageFormat.height,
)
: BoxConstraints.tightFor(
width: context.page.pageFormat.availableWidth,
height: context.page.pageFormat.availableHeight,
);
}
PdfRect _getBox(Context context) {
final PdfRect box = _getConstraints(context).constrainRect();
if (ignoreMargins) {
return box;
}
return PdfRect.fromPoints(
PdfPoint(
context.page.pageFormat.marginLeft,
context.page.pageFormat.marginTop,
),
box.size);
}
@override
void layout(Context context, BoxConstraints constraints,
{bool parentUsesSize = false}) {
final BoxConstraints constraints = _getConstraints(context);
if (child != null) {
child.layout(context, constraints, parentUsesSize: false);
assert(child.box != null);
}
box = _getBox(context);
print('layout box: $box');
}
@override
void debugPaint(Context context) {}
@override
void paint(Context context) {
super.paint(context);
if (child == null) {
return;
}
final PdfRect box = _getBox(context);
final Matrix4 mat = Matrix4.tryInvert(context.canvas.getTransform());
mat.translate(box.x, box.y);
context.canvas
..saveContext()
..setTransform(mat);
child.paint(context);
context.canvas.restoreContext();
}
}
... ...
... ... @@ -104,6 +104,14 @@ class Page {
page: _pdfPage,
canvas: canvas,
).inheritFrom(calculatedTheme);
assert(() {
if (Document.debug) {
debugPaint(context);
}
return true;
}());
if (pageTheme.buildBackground != null) {
final Widget child = pageTheme.buildBackground(context);
if (child != null) {
... ... @@ -111,6 +119,7 @@ class Page {
paint(child, context);
}
}
if (_build != null) {
final Widget child = _build(context);
if (child != null) {
... ... @@ -118,6 +127,7 @@ class Page {
paint(child, context);
}
}
if (pageTheme.buildForeground != null) {
final Widget child = pageTheme.buildForeground(context);
if (child != null) {
... ... @@ -144,13 +154,6 @@ class Page {
@protected
void paint(Widget child, Context context) {
assert(() {
if (Document.debug) {
debugPaint(context);
}
return true;
}());
if (child == null) {
return;
}
... ...
... ... @@ -25,7 +25,10 @@ void main() {
final Document pdf = Document();
final PageTheme pageTheme = PageTheme(
buildBackground: (Context context) => Watermark.text('DRAFT'),
buildBackground: (Context context) => FullPage(
ignoreMargins: true,
child: Watermark.text('DRAFT'),
),
buildForeground: (Context context) => Align(
alignment: Alignment.bottomLeft,
child: SizedBox(
... ...