Skip to content

Commit 0402adf

Browse files
committed
Migrate to vector_math 2.2.0
1 parent d718963 commit 0402adf

25 files changed

+68
-70
lines changed

pdf/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- creates catalog.names earlier for attached files [ilaurillard]
88
- fix: Prevent "Index out of range" error when reading simple glyphs in certain fonts [Eghosa Osayande]
99
- Improve PdfRect naming consistency
10+
- Migrate to vector_math 2.2.0
1011

1112
## 3.11.3
1213

pdf/lib/src/pdf/graphics.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ class PdfGraphics {
976976
// Our box bézier arcs can't handle rotations directly
977977
// move to a well known point, eliminate phi and transform the other point
978978
final mat = Matrix4.identity();
979-
mat.translate(-x1, -y1);
979+
mat.translateByDouble(-x1, -y1, 0, 1);
980980
mat.rotateZ(-phi);
981981
final tr = mat.transform3(Vector3(x2, y2, 0));
982982
_endToCenterParameters(0, 0, tr[0], tr[1], large, sweep, rx, ry);

pdf/lib/src/svg/gradient.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ class SvgLinearGradient extends SvgGradient {
199199
if (gradientUnits != GradientUnits.userSpaceOnUse) {
200200
final bb = op.boundingBox();
201201
mat
202-
..translate(bb.left, bb.bottom)
203-
..scale(bb.width, bb.height);
202+
..translateByDouble(bb.left, bb.bottom, 0, 1)
203+
..scaleByDouble(bb.width, bb.height, 1, 1);
204204
}
205205

206206
if (transform.isNotEmpty) {
@@ -348,8 +348,8 @@ class SvgRadialGradient extends SvgGradient {
348348
if (gradientUnits != GradientUnits.userSpaceOnUse) {
349349
final bb = op.boundingBox();
350350
mat
351-
..translate(bb.left, bb.bottom)
352-
..scale(bb.width, bb.height);
351+
..translateByDouble(bb.left, bb.bottom, 0, 1)
352+
..scaleByDouble(bb.width, bb.height, 1, 1);
353353
}
354354

355355
if (transform.isNotEmpty) {

pdf/lib/src/svg/image.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ class SvgImg extends SvgOperation {
118118
canvas
119119
..setTransform(
120120
Matrix4.identity()
121-
..translate(x, y + height, 0)
122-
..scale(sx, -sy),
121+
..translateByDouble(x, y + height, 0, 1)
122+
..scaleByDouble(sx, -sy, 1, 1),
123123
)
124124
..drawImage(image!, 0, 0);
125125
}

pdf/lib/src/svg/text.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ class SvgText extends SvgOperation {
123123
canvas
124124
..saveContext()
125125
..setTransform(Matrix4.identity()
126-
..scale(1.0, -1.0)
127-
..translate(x, -y!));
126+
..scaleByDouble(1, -1, 1, 1)
127+
..translateByDouble(x!, -y!, 0, 1));
128128

129129
if (brush.fill!.isNotEmpty) {
130130
brush.fill!.setFillColor(this, canvas);
@@ -166,8 +166,8 @@ class SvgText extends SvgOperation {
166166
canvas
167167
..saveContext()
168168
..setTransform(Matrix4.identity()
169-
..scale(1.0, -1.0)
170-
..translate(x, -y!))
169+
..scaleByDouble(1, -1, 1, 1)
170+
..translateByDouble(x!, -y!, 0, 1))
171171
..drawString(font, brush.fontSize!.sizeValue, text, 0, 0,
172172
mode: PdfTextRenderingMode.clip)
173173
..restoreContext();

pdf/lib/src/svg/transform.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ class SvgTransform {
5151
final dx = parameterList[0];
5252
final dy = [...parameterList, .0][1];
5353

54-
mat.multiply(Matrix4.identity()..translate(dx, dy));
54+
mat.multiply(Matrix4.identity()..translateByDouble(dx, dy, 0, 1));
5555
break;
5656
case 'scale':
5757
final sw = parameterList[0];
5858
final sh = [...parameterList, sw][1];
5959

60-
mat.multiply(Matrix4.identity()..scale(sw, sh));
60+
mat.multiply(Matrix4.identity()..scaleByDouble(sw, sh, 1, 1));
6161
break;
6262
case 'rotate':
6363
final degrees = parameterList[0];
@@ -68,13 +68,13 @@ class SvgTransform {
6868
// Rotation about the origin (ox, oy)
6969
ox = parameterList[1];
7070
oy = [...parameterList, .0][2];
71-
mat.translate(ox, oy);
71+
mat.translateByDouble(ox, oy, 0, 1);
7272
}
7373

7474
mat.multiply(Matrix4.rotationZ(radians(degrees)));
7575

7676
if (ox != 0 || oy != 0) {
77-
mat.translate(-ox, -oy);
77+
mat.translateByDouble(-ox, -oy, 0, 1);
7878
}
7979
break;
8080

pdf/lib/src/widgets/basic.dart

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ class Padding extends SingleChildWidget {
120120
final resolvedPadding = padding.resolve(Directionality.of(context));
121121
if (child != null) {
122122
final mat = Matrix4.identity();
123-
mat.translate(box!.left + resolvedPadding.left,
124-
box!.bottom + resolvedPadding.bottom);
123+
mat.translateByDouble(box!.left + resolvedPadding.left,
124+
box!.bottom + resolvedPadding.bottom, 0, 1);
125125
context.canvas
126126
..saveContext()
127127
..setTransform(mat);
@@ -203,21 +203,21 @@ class Transform extends SingleChildWidget {
203203
Matrix4 _effectiveTransform(Context context) {
204204
final result = Matrix4.identity();
205205
if (origin != null) {
206-
result.translate(origin!.x, origin!.y);
206+
result.translateByDouble(origin!.x, origin!.y, 0, 1);
207207
}
208-
result.translate(box!.left, box!.bottom);
208+
result.translateByDouble(box!.left, box!.bottom, 0, 1);
209209
late PdfPoint translation;
210210
if (alignment != null) {
211211
final resolvedAlignment = alignment!.resolve(Directionality.of(context));
212212
translation = resolvedAlignment.alongSize(box!.size);
213-
result.translate(translation.x, translation.y);
213+
result.translateByDouble(translation.x, translation.y, 0, 1);
214214
}
215215
result.multiply(transform);
216216
if (alignment != null) {
217-
result.translate(-translation.x, -translation.y);
217+
result.translateByDouble(-translation.x, -translation.y, 0, 1);
218218
}
219219
if (origin != null) {
220-
result.translate(-origin!.x, -origin!.y);
220+
result.translateByDouble(-origin!.x, -origin!.y, 0, 1);
221221
}
222222
return result;
223223
}
@@ -269,7 +269,7 @@ class Transform extends SingleChildWidget {
269269
dy,
270270
);
271271

272-
transform.leftTranslate(dx, dy);
272+
transform.leftTranslateByDouble(dx, dy, 0, 1);
273273
} else {
274274
box = PdfRect.fromPoints(PdfPoint.zero, constraints.smallest);
275275
}
@@ -503,8 +503,8 @@ class FittedBox extends SingleChildWidget {
503503

504504
final mat = Matrix4.translationValues(
505505
destinationRect.left, destinationRect.bottom, 0)
506-
..scale(scaleX, scaleY, 1)
507-
..translate(-sourceRect.left, -sourceRect.bottom);
506+
..scaleByDouble(scaleX, scaleY, 1, 1)
507+
..translateByDouble(-sourceRect.left, -sourceRect.bottom, 0, 1);
508508

509509
context.canvas
510510
..saveContext()
@@ -610,7 +610,7 @@ class CustomPaint extends SingleChildWidget {
610610
super.paint(context);
611611

612612
final mat = Matrix4.identity();
613-
mat.translate(box!.left, box!.bottom);
613+
mat.translateByDouble(box!.left, box!.bottom, 0, 1);
614614
context.canvas
615615
..saveContext()
616616
..setTransform(mat);
@@ -776,7 +776,7 @@ class FullPage extends SingleChildWidget {
776776

777777
final box = _getBox(context);
778778
final mat = Matrix4.tryInvert(context.canvas.getTransform())!;
779-
mat.translate(box.left, box.bottom);
779+
mat.translateByDouble(box.left, box.bottom, 0, 1);
780780
context.canvas
781781
..saveContext()
782782
..setTransform(mat);
@@ -799,7 +799,7 @@ class Opacity extends SingleChildWidget {
799799

800800
if (child != null) {
801801
final mat = Matrix4.identity();
802-
mat.translate(box!.left, box!.bottom);
802+
mat.translateByDouble(box!.left, box!.bottom, 0, 1);
803803
context.canvas
804804
..saveContext()
805805
..setTransform(mat)

pdf/lib/src/widgets/chart/chart.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class Chart extends Widget implements Inherited {
122122
super.paint(_context!);
123123

124124
final mat = Matrix4.identity();
125-
mat.translate(box!.left, box!.bottom);
125+
mat.translateByDouble(box!.left, box!.bottom, 0, 1);
126126
_context!.canvas
127127
..saveContext()
128128
..setTransform(mat);

pdf/lib/src/widgets/clip.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ClipRect extends SingleChildWidget {
3737

3838
if (child != null) {
3939
final mat = Matrix4.identity();
40-
mat.translate(box!.left, box!.bottom);
40+
mat.translateByDouble(box!.left, box!.bottom, 0, 1);
4141
context.canvas
4242
..saveContext()
4343
..drawBox(box!)
@@ -75,7 +75,7 @@ class ClipRRect extends SingleChildWidget {
7575

7676
if (child != null) {
7777
final mat = Matrix4.identity();
78-
mat.translate(box!.left, box!.bottom);
78+
mat.translateByDouble(box!.left, box!.bottom, 0, 1);
7979
context.canvas
8080
..saveContext()
8181
..drawRRect(box!.left, box!.bottom, box!.width, box!.height,
@@ -112,7 +112,7 @@ class ClipOval extends SingleChildWidget {
112112

113113
if (child != null) {
114114
final mat = Matrix4.identity();
115-
mat.translate(box!.left, box!.bottom);
115+
mat.translateByDouble(box!.left, box!.bottom, 0, 1);
116116
context.canvas
117117
..saveContext()
118118
..drawEllipse(box!.left + rx, box!.bottom + ry, rx, ry)

pdf/lib/src/widgets/decoration.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ class DecorationImage extends DecorationGraphic {
5959
final destinationRect = alignment.inscribe(sizes.destination!, box);
6060
final mat = Matrix4.translationValues(
6161
destinationRect.left, destinationRect.bottom, 0)
62-
..scale(scaleX, scaleY, 1)
63-
..translate(-sourceRect.left, -sourceRect.bottom);
62+
..scaleByDouble(scaleX, scaleY, 1, 1)
63+
..translateByDouble(-sourceRect.left, -sourceRect.bottom, 0, 1);
6464

6565
context.canvas
6666
..saveContext()

0 commit comments

Comments
 (0)