Showing
3 changed files
with
34 additions
and
10 deletions
@@ -28,13 +28,15 @@ class Page { | @@ -28,13 +28,15 @@ class Page { | ||
28 | BuildCallback build, | 28 | BuildCallback build, |
29 | Theme theme, | 29 | Theme theme, |
30 | PageOrientation orientation, | 30 | PageOrientation orientation, |
31 | - EdgeInsets margin}) | 31 | + EdgeInsets margin, |
32 | + bool clip = false}) | ||
32 | : assert( | 33 | : assert( |
33 | pageTheme == null || | 34 | pageTheme == null || |
34 | (pageFormat == null && | 35 | (pageFormat == null && |
35 | theme == null && | 36 | theme == null && |
36 | orientation == null && | 37 | orientation == null && |
37 | - margin == null), | 38 | + margin == null && |
39 | + clip == false), | ||
38 | 'Don\'t set both pageTheme and other settings'), | 40 | 'Don\'t set both pageTheme and other settings'), |
39 | pageTheme = pageTheme ?? | 41 | pageTheme = pageTheme ?? |
40 | PageTheme( | 42 | PageTheme( |
@@ -42,6 +44,7 @@ class Page { | @@ -42,6 +44,7 @@ class Page { | ||
42 | orientation: orientation, | 44 | orientation: orientation, |
43 | margin: margin, | 45 | margin: margin, |
44 | theme: theme, | 46 | theme: theme, |
47 | + clip: clip, | ||
45 | ), | 48 | ), |
46 | _build = build; | 49 | _build = build; |
47 | 50 | ||
@@ -152,6 +155,19 @@ class Page { | @@ -152,6 +155,19 @@ class Page { | ||
152 | return; | 155 | return; |
153 | } | 156 | } |
154 | 157 | ||
158 | + if (pageTheme.clip) { | ||
159 | + final EdgeInsets _margin = margin; | ||
160 | + context.canvas | ||
161 | + ..saveContext() | ||
162 | + ..drawRect( | ||
163 | + _margin.left, | ||
164 | + _margin.bottom, | ||
165 | + pageFormat.width - _margin.horizontal, | ||
166 | + pageFormat.height - _margin.vertical, | ||
167 | + ) | ||
168 | + ..clipPath(); | ||
169 | + } | ||
170 | + | ||
155 | if (mustRotate) { | 171 | if (mustRotate) { |
156 | final EdgeInsets _margin = margin; | 172 | final EdgeInsets _margin = margin; |
157 | final Matrix4 mat = Matrix4.identity(); | 173 | final Matrix4 mat = Matrix4.identity(); |
@@ -167,5 +183,9 @@ class Page { | @@ -167,5 +183,9 @@ class Page { | ||
167 | } else { | 183 | } else { |
168 | child.paint(context); | 184 | child.paint(context); |
169 | } | 185 | } |
186 | + | ||
187 | + if (pageTheme.clip) { | ||
188 | + context.canvas.restoreContext(); | ||
189 | + } | ||
170 | } | 190 | } |
171 | } | 191 | } |
@@ -18,14 +18,15 @@ part of widget; | @@ -18,14 +18,15 @@ part of widget; | ||
18 | 18 | ||
19 | @immutable | 19 | @immutable |
20 | class PageTheme { | 20 | class PageTheme { |
21 | - const PageTheme( | ||
22 | - {PdfPageFormat pageFormat, | ||
23 | - this.buildBackground, | ||
24 | - this.buildForeground, | ||
25 | - this.theme, | ||
26 | - PageOrientation orientation, | ||
27 | - EdgeInsets margin}) | ||
28 | - : pageFormat = pageFormat ?? PdfPageFormat.standard, | 21 | + const PageTheme({ |
22 | + PdfPageFormat pageFormat, | ||
23 | + this.buildBackground, | ||
24 | + this.buildForeground, | ||
25 | + this.theme, | ||
26 | + PageOrientation orientation, | ||
27 | + EdgeInsets margin, | ||
28 | + this.clip = false, | ||
29 | + }) : pageFormat = pageFormat ?? PdfPageFormat.standard, | ||
29 | orientation = orientation ?? PageOrientation.natural, | 30 | orientation = orientation ?? PageOrientation.natural, |
30 | _margin = margin; | 31 | _margin = margin; |
31 | 32 | ||
@@ -41,6 +42,8 @@ class PageTheme { | @@ -41,6 +42,8 @@ class PageTheme { | ||
41 | 42 | ||
42 | final Theme theme; | 43 | final Theme theme; |
43 | 44 | ||
45 | + final bool clip; | ||
46 | + | ||
44 | bool get mustRotate => | 47 | bool get mustRotate => |
45 | (orientation == PageOrientation.landscape && | 48 | (orientation == PageOrientation.landscape && |
46 | pageFormat.height > pageFormat.width) || | 49 | pageFormat.height > pageFormat.width) || |
-
Please register or login to post a comment