David PHAM-VAN

Fix Transform.adjustLayout

1 # Changelog 1 # Changelog
2 2
  3 +## 1.3.20
  4 +
  5 +- Fix Transform.rotateBox
  6 +
3 ## 1.3.19 7 ## 1.3.19
4 8
5 - Fix Ascii85 encoding 9 - Fix Ascii85 encoding
@@ -126,9 +126,9 @@ class Transform extends SingleChildWidget { @@ -126,9 +126,9 @@ class Transform extends SingleChildWidget {
126 @required this.transform, 126 @required this.transform,
127 this.origin, 127 this.origin,
128 this.alignment, 128 this.alignment,
  129 + this.adjustLayout = false,
129 Widget child, 130 Widget child,
130 }) : assert(transform != null), 131 }) : assert(transform != null),
131 - _relayout = false,  
132 super(child: child); 132 super(child: child);
133 133
134 /// Creates a widget that transforms its child using a rotation around the 134 /// Creates a widget that transforms its child using a rotation around the
@@ -139,7 +139,7 @@ class Transform extends SingleChildWidget { @@ -139,7 +139,7 @@ class Transform extends SingleChildWidget {
139 this.alignment = Alignment.center, 139 this.alignment = Alignment.center,
140 Widget child, 140 Widget child,
141 }) : transform = Matrix4.rotationZ(angle), 141 }) : transform = Matrix4.rotationZ(angle),
142 - _relayout = false, 142 + adjustLayout = false,
143 super(child: child); 143 super(child: child);
144 144
145 /// Creates a widget that transforms its child using a rotation around the 145 /// Creates a widget that transforms its child using a rotation around the
@@ -148,7 +148,7 @@ class Transform extends SingleChildWidget { @@ -148,7 +148,7 @@ class Transform extends SingleChildWidget {
148 @required double angle, 148 @required double angle,
149 Widget child, 149 Widget child,
150 }) : transform = Matrix4.rotationZ(angle), 150 }) : transform = Matrix4.rotationZ(angle),
151 - _relayout = true, 151 + adjustLayout = true,
152 alignment = null, 152 alignment = null,
153 origin = null, 153 origin = null,
154 super(child: child); 154 super(child: child);
@@ -160,7 +160,7 @@ class Transform extends SingleChildWidget { @@ -160,7 +160,7 @@ class Transform extends SingleChildWidget {
160 }) : transform = Matrix4.translationValues(offset.x, offset.y, 0), 160 }) : transform = Matrix4.translationValues(offset.x, offset.y, 0),
161 origin = null, 161 origin = null,
162 alignment = null, 162 alignment = null,
163 - _relayout = false, 163 + adjustLayout = false,
164 super(child: child); 164 super(child: child);
165 165
166 /// Creates a widget that scales its child uniformly. 166 /// Creates a widget that scales its child uniformly.
@@ -170,7 +170,7 @@ class Transform extends SingleChildWidget { @@ -170,7 +170,7 @@ class Transform extends SingleChildWidget {
170 this.alignment = Alignment.center, 170 this.alignment = Alignment.center,
171 Widget child, 171 Widget child,
172 }) : transform = Matrix4.diagonal3Values(scale, scale, 1), 172 }) : transform = Matrix4.diagonal3Values(scale, scale, 1),
173 - _relayout = false, 173 + adjustLayout = false,
174 super(child: child); 174 super(child: child);
175 175
176 /// The matrix to transform the child by during painting. 176 /// The matrix to transform the child by during painting.
@@ -182,7 +182,7 @@ class Transform extends SingleChildWidget { @@ -182,7 +182,7 @@ class Transform extends SingleChildWidget {
182 /// The alignment of the origin, relative to the size of the box. 182 /// The alignment of the origin, relative to the size of the box.
183 final Alignment alignment; 183 final Alignment alignment;
184 184
185 - final bool _relayout; 185 + final bool adjustLayout;
186 186
187 Matrix4 get _effectiveTransform { 187 Matrix4 get _effectiveTransform {
188 final Matrix4 result = Matrix4.identity(); 188 final Matrix4 result = Matrix4.identity();
@@ -208,14 +208,13 @@ class Transform extends SingleChildWidget { @@ -208,14 +208,13 @@ class Transform extends SingleChildWidget {
208 @override 208 @override
209 void layout(Context context, BoxConstraints constraints, 209 void layout(Context context, BoxConstraints constraints,
210 {bool parentUsesSize = false}) { 210 {bool parentUsesSize = false}) {
211 - if (!_relayout) { 211 + if (!adjustLayout) {
212 return super.layout(context, constraints, parentUsesSize: parentUsesSize); 212 return super.layout(context, constraints, parentUsesSize: parentUsesSize);
213 } 213 }
214 214
215 if (child != null) { 215 if (child != null) {
216 child.layout(context, constraints, parentUsesSize: parentUsesSize); 216 child.layout(context, constraints, parentUsesSize: parentUsesSize);
217 assert(child.box != null); 217 assert(child.box != null);
218 - box = child.box;  
219 218
220 final Matrix4 mat = transform; 219 final Matrix4 mat = transform;
221 final List<double> values = mat.applyToVector3Array(<double>[ 220 final List<double> values = mat.applyToVector3Array(<double>[
@@ -233,17 +232,23 @@ class Transform extends SingleChildWidget { @@ -233,17 +232,23 @@ class Transform extends SingleChildWidget {
233 0, 232 0,
234 ]); 233 ]);
235 234
  235 + final double dx = -math.min(
  236 + math.min(math.min(values[0], values[3]), values[6]), values[9]);
  237 + final double dy = -math.min(
  238 + math.min(math.min(values[1], values[4]), values[7]), values[10]);
  239 +
236 box = PdfRect.fromLTRB( 240 box = PdfRect.fromLTRB(
237 - math.min(  
238 - math.min(math.min(values[0], values[3]), values[6]), values[9]),  
239 - math.min(  
240 - math.min(math.min(values[1], values[4]), values[7]), values[10]),  
241 - math.max(  
242 - math.max(math.max(values[0], values[3]), values[6]), values[9]),  
243 - math.max(  
244 - math.max(math.max(values[1], values[4]), values[7]), values[10]), 241 + 0,
  242 + 0,
  243 + math.max(math.max(math.max(values[0], values[3]), values[6]),
  244 + values[9]) +
  245 + dx,
  246 + math.max(math.max(math.max(values[1], values[4]), values[7]),
  247 + values[10]) +
  248 + dy,
245 ); 249 );
246 - transform.leftTranslate(-box.x, -box.y); 250 +
  251 + transform.leftTranslate(dx, dy);
247 } else { 252 } else {
248 box = PdfRect.fromPoints(PdfPoint.zero, constraints.smallest); 253 box = PdfRect.fromPoints(PdfPoint.zero, constraints.smallest);
249 } 254 }
@@ -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: 1.3.19 7 +version: 1.3.20
8 8
9 environment: 9 environment:
10 sdk: ">=2.1.0 <3.0.0" 10 sdk: ">=2.1.0 <3.0.0"
@@ -80,11 +80,13 @@ void main() { @@ -80,11 +80,13 @@ void main() {
80 padding: const EdgeInsets.only(left: 30, top: 20), 80 padding: const EdgeInsets.only(left: 30, top: 20),
81 child: Lorem(textAlign: TextAlign.justify)), 81 child: Lorem(textAlign: TextAlign.justify)),
82 Expanded( 82 Expanded(
83 - child: Transform.scale(  
84 - child: Transform.rotate(  
85 - child: FittedBox(child: Text('Expanded')),  
86 - angle: 0.2),  
87 - scale: 0.9)), 83 + child: FittedBox(
  84 + child: Transform.rotateBox(
  85 + angle: 0.2,
  86 + child: Text('Expanded'),
  87 + ),
  88 + ),
  89 + ),
88 Container( 90 Container(
89 padding: const EdgeInsets.only(top: 5), 91 padding: const EdgeInsets.only(top: 5),
90 decoration: const BoxDecoration( 92 decoration: const BoxDecoration(