David PHAM-VAN

Add optional clipping on Page

... ... @@ -8,6 +8,7 @@
- Fix warning in tests
- Fix warning in example
- Format Java code
- Add optional clipping on Page
## 1.3.23
... ...
... ... @@ -28,13 +28,15 @@ class Page {
BuildCallback build,
Theme theme,
PageOrientation orientation,
EdgeInsets margin})
EdgeInsets margin,
bool clip = false})
: assert(
pageTheme == null ||
(pageFormat == null &&
theme == null &&
orientation == null &&
margin == null),
margin == null &&
clip == false),
'Don\'t set both pageTheme and other settings'),
pageTheme = pageTheme ??
PageTheme(
... ... @@ -42,6 +44,7 @@ class Page {
orientation: orientation,
margin: margin,
theme: theme,
clip: clip,
),
_build = build;
... ... @@ -152,6 +155,19 @@ class Page {
return;
}
if (pageTheme.clip) {
final EdgeInsets _margin = margin;
context.canvas
..saveContext()
..drawRect(
_margin.left,
_margin.bottom,
pageFormat.width - _margin.horizontal,
pageFormat.height - _margin.vertical,
)
..clipPath();
}
if (mustRotate) {
final EdgeInsets _margin = margin;
final Matrix4 mat = Matrix4.identity();
... ... @@ -167,5 +183,9 @@ class Page {
} else {
child.paint(context);
}
if (pageTheme.clip) {
context.canvas.restoreContext();
}
}
}
... ...
... ... @@ -18,14 +18,15 @@ part of widget;
@immutable
class PageTheme {
const PageTheme(
{PdfPageFormat pageFormat,
const PageTheme({
PdfPageFormat pageFormat,
this.buildBackground,
this.buildForeground,
this.theme,
PageOrientation orientation,
EdgeInsets margin})
: pageFormat = pageFormat ?? PdfPageFormat.standard,
EdgeInsets margin,
this.clip = false,
}) : pageFormat = pageFormat ?? PdfPageFormat.standard,
orientation = orientation ?? PageOrientation.natural,
_margin = margin;
... ... @@ -41,6 +42,8 @@ class PageTheme {
final Theme theme;
final bool clip;
bool get mustRotate =>
(orientation == PageOrientation.landscape &&
pageFormat.height > pageFormat.width) ||
... ...