David PHAM-VAN

Fix Table border

1 # Changelog 1 # Changelog
2 2
  3 +## 3.0.0-nullsafety.1
  4 +
  5 +- Fix Table border
  6 +
3 ## 3.0.0-nullsafety.0 7 ## 3.0.0-nullsafety.0
4 8
5 - Fix SVG fit alignment 9 - Fix SVG fit alignment
@@ -41,8 +41,8 @@ abstract class BoxBorder { @@ -41,8 +41,8 @@ abstract class BoxBorder {
41 BorderRadius? borderRadius, 41 BorderRadius? borderRadius,
42 }); 42 });
43 43
44 - static void _setStyle(Context context, BorderStyle? style) {  
45 - switch (style!) { 44 + static void setStyle(Context context, BorderStyle style) {
  45 + switch (style) {
46 case BorderStyle.none: 46 case BorderStyle.none:
47 case BorderStyle.solid: 47 case BorderStyle.solid:
48 break; 48 break;
@@ -59,8 +59,8 @@ abstract class BoxBorder { @@ -59,8 +59,8 @@ abstract class BoxBorder {
59 } 59 }
60 } 60 }
61 61
62 - static void _unsetStyle(Context context, BorderStyle? style) {  
63 - switch (style!) { 62 + static void unsetStyle(Context context, BorderStyle style) {
  63 + switch (style) {
64 case BorderStyle.none: 64 case BorderStyle.none:
65 case BorderStyle.solid: 65 case BorderStyle.solid:
66 break; 66 break;
@@ -73,40 +73,40 @@ abstract class BoxBorder { @@ -73,40 +73,40 @@ abstract class BoxBorder {
73 73
74 static void _paintUniformBorderWithCircle( 74 static void _paintUniformBorderWithCircle(
75 Context context, PdfRect box, BorderSide side) { 75 Context context, PdfRect box, BorderSide side) {
76 - _setStyle(context, side.style); 76 + setStyle(context, side.style);
77 context.canvas 77 context.canvas
78 ..setStrokeColor(side.color) 78 ..setStrokeColor(side.color)
79 - ..setLineWidth(side.width!) 79 + ..setLineWidth(side.width)
80 ..drawEllipse(box.x + box.width / 2.0, box.y + box.height / 2.0, 80 ..drawEllipse(box.x + box.width / 2.0, box.y + box.height / 2.0,
81 box.width / 2.0, box.height / 2.0) 81 box.width / 2.0, box.height / 2.0)
82 ..strokePath(); 82 ..strokePath();
83 - _unsetStyle(context, side.style); 83 + unsetStyle(context, side.style);
84 } 84 }
85 85
86 static void _paintUniformBorderWithRadius(Context context, PdfRect box, 86 static void _paintUniformBorderWithRadius(Context context, PdfRect box,
87 BorderSide side, BorderRadius borderRadius) { 87 BorderSide side, BorderRadius borderRadius) {
88 - _setStyle(context, side.style); 88 + setStyle(context, side.style);
89 context.canvas 89 context.canvas
90 ..setLineJoin(PdfLineJoin.miter) 90 ..setLineJoin(PdfLineJoin.miter)
91 ..setMiterLimit(4) 91 ..setMiterLimit(4)
92 ..setStrokeColor(side.color) 92 ..setStrokeColor(side.color)
93 - ..setLineWidth(side.width!); 93 + ..setLineWidth(side.width);
94 borderRadius.paint(context, box); 94 borderRadius.paint(context, box);
95 context.canvas.strokePath(); 95 context.canvas.strokePath();
96 - _unsetStyle(context, side.style); 96 + unsetStyle(context, side.style);
97 } 97 }
98 98
99 static void _paintUniformBorderWithRectangle( 99 static void _paintUniformBorderWithRectangle(
100 Context context, PdfRect box, BorderSide side) { 100 Context context, PdfRect box, BorderSide side) {
101 - _setStyle(context, side.style); 101 + setStyle(context, side.style);
102 context.canvas 102 context.canvas
103 ..setLineJoin(PdfLineJoin.miter) 103 ..setLineJoin(PdfLineJoin.miter)
104 ..setMiterLimit(4) 104 ..setMiterLimit(4)
105 ..setStrokeColor(side.color) 105 ..setStrokeColor(side.color)
106 - ..setLineWidth(side.width!) 106 + ..setLineWidth(side.width)
107 ..drawBox(box) 107 ..drawBox(box)
108 ..strokePath(); 108 ..strokePath();
109 - _unsetStyle(context, side.style); 109 + unsetStyle(context, side.style);
110 } 110 }
111 } 111 }
112 112
@@ -124,13 +124,13 @@ class BorderSide { @@ -124,13 +124,13 @@ class BorderSide {
124 BorderSide(width: 0.0, style: BorderStyle.none); 124 BorderSide(width: 0.0, style: BorderStyle.none);
125 125
126 /// The color of this side of the border. 126 /// The color of this side of the border.
127 - final PdfColor? color; 127 + final PdfColor color;
128 128
129 /// The width of this side of the border. 129 /// The width of this side of the border.
130 - final double? width; 130 + final double width;
131 131
132 /// The style of this side of the border. 132 /// The style of this side of the border.
133 - final BorderStyle? style; 133 + final BorderStyle style;
134 134
135 BorderSide copyWith({ 135 BorderSide copyWith({
136 PdfColor? color, 136 PdfColor? color,
@@ -138,9 +138,9 @@ class BorderSide { @@ -138,9 +138,9 @@ class BorderSide {
138 BorderStyle? style, 138 BorderStyle? style,
139 }) => 139 }) =>
140 BorderSide( 140 BorderSide(
141 - color: color,  
142 - width: width,  
143 - style: style, 141 + color: color ?? this.color,
  142 + width: width ?? this.width,
  143 + style: style ?? this.style,
144 ); 144 );
145 145
146 @override 146 @override
@@ -252,43 +252,43 @@ class Border extends BoxBorder { @@ -252,43 +252,43 @@ class Border extends BoxBorder {
252 ..setLineJoin(PdfLineJoin.miter); 252 ..setLineJoin(PdfLineJoin.miter);
253 253
254 if (top.style != BorderStyle.none) { 254 if (top.style != BorderStyle.none) {
255 - BoxBorder._setStyle(context, top.style); 255 + BoxBorder.setStyle(context, top.style);
256 context.canvas 256 context.canvas
257 ..setStrokeColor(top.color) 257 ..setStrokeColor(top.color)
258 - ..setLineWidth(top.width!) 258 + ..setLineWidth(top.width)
259 ..drawLine(box.left, box.top, box.right, box.top) 259 ..drawLine(box.left, box.top, box.right, box.top)
260 ..strokePath(); 260 ..strokePath();
261 - BoxBorder._unsetStyle(context, top.style); 261 + BoxBorder.unsetStyle(context, top.style);
262 } 262 }
263 263
264 if (right.style != BorderStyle.none) { 264 if (right.style != BorderStyle.none) {
265 - BoxBorder._setStyle(context, right.style); 265 + BoxBorder.setStyle(context, right.style);
266 context.canvas 266 context.canvas
267 ..setStrokeColor(right.color) 267 ..setStrokeColor(right.color)
268 - ..setLineWidth(right.width!) 268 + ..setLineWidth(right.width)
269 ..drawLine(box.right, box.top, box.right, box.bottom) 269 ..drawLine(box.right, box.top, box.right, box.bottom)
270 ..strokePath(); 270 ..strokePath();
271 - BoxBorder._unsetStyle(context, right.style); 271 + BoxBorder.unsetStyle(context, right.style);
272 } 272 }
273 273
274 if (bottom.style != BorderStyle.none) { 274 if (bottom.style != BorderStyle.none) {
275 - BoxBorder._setStyle(context, bottom.style); 275 + BoxBorder.setStyle(context, bottom.style);
276 context.canvas 276 context.canvas
277 ..setStrokeColor(bottom.color) 277 ..setStrokeColor(bottom.color)
278 - ..setLineWidth(bottom.width!) 278 + ..setLineWidth(bottom.width)
279 ..drawLine(box.right, box.bottom, box.left, box.bottom) 279 ..drawLine(box.right, box.bottom, box.left, box.bottom)
280 ..strokePath(); 280 ..strokePath();
281 - BoxBorder._unsetStyle(context, bottom.style); 281 + BoxBorder.unsetStyle(context, bottom.style);
282 } 282 }
283 283
284 if (left.style != BorderStyle.none) { 284 if (left.style != BorderStyle.none) {
285 - BoxBorder._setStyle(context, left.style); 285 + BoxBorder.setStyle(context, left.style);
286 context.canvas 286 context.canvas
287 ..setStrokeColor(left.color) 287 ..setStrokeColor(left.color)
288 - ..setLineWidth(left.width!) 288 + ..setLineWidth(left.width)
289 ..drawLine(box.left, box.top, box.left, box.bottom) 289 ..drawLine(box.left, box.top, box.left, box.bottom)
290 ..strokePath(); 290 ..strokePath();
291 - BoxBorder._unsetStyle(context, left.style); 291 + BoxBorder.unsetStyle(context, left.style);
292 } 292 }
293 } 293 }
294 } 294 }
@@ -271,36 +271,44 @@ class GridPaper extends SingleChildWidget { @@ -271,36 +271,44 @@ class GridPaper extends SingleChildWidget {
271 } 271 }
272 272
273 if (border.left.style != BorderStyle.none) { 273 if (border.left.style != BorderStyle.none) {
  274 + BoxBorder.setStyle(context, border.left.style);
274 context.canvas 275 context.canvas
275 ..setStrokeColor(border.left.color) 276 ..setStrokeColor(border.left.color)
276 - ..setLineWidth(border.left.width!) 277 + ..setLineWidth(border.left.width)
277 ..drawLine(box!.left + margin.left, box!.top, box!.left + margin.left, 278 ..drawLine(box!.left + margin.left, box!.top, box!.left + margin.left,
278 box!.bottom) 279 box!.bottom)
279 ..strokePath(); 280 ..strokePath();
  281 + BoxBorder.unsetStyle(context, border.left.style);
280 } 282 }
281 if (border.right.style != BorderStyle.none) { 283 if (border.right.style != BorderStyle.none) {
  284 + BoxBorder.setStyle(context, border.right.style);
282 context.canvas 285 context.canvas
283 ..setStrokeColor(border.right.color) 286 ..setStrokeColor(border.right.color)
284 - ..setLineWidth(border.right.width!) 287 + ..setLineWidth(border.right.width)
285 ..drawLine(box!.right - margin.right, box!.top, 288 ..drawLine(box!.right - margin.right, box!.top,
286 box!.right - margin.right, box!.bottom) 289 box!.right - margin.right, box!.bottom)
287 ..strokePath(); 290 ..strokePath();
  291 + BoxBorder.unsetStyle(context, border.right.style);
288 } 292 }
289 if (border.top.style != BorderStyle.none) { 293 if (border.top.style != BorderStyle.none) {
  294 + BoxBorder.setStyle(context, border.top.style);
290 context.canvas 295 context.canvas
291 ..setStrokeColor(border.top.color) 296 ..setStrokeColor(border.top.color)
292 - ..setLineWidth(border.top.width!) 297 + ..setLineWidth(border.top.width)
293 ..drawLine( 298 ..drawLine(
294 box!.left, box!.top - margin.top, box!.right, box!.top - margin.top) 299 box!.left, box!.top - margin.top, box!.right, box!.top - margin.top)
295 ..strokePath(); 300 ..strokePath();
  301 + BoxBorder.unsetStyle(context, border.top.style);
296 } 302 }
297 if (border.bottom.style != BorderStyle.none) { 303 if (border.bottom.style != BorderStyle.none) {
  304 + BoxBorder.setStyle(context, border.bottom.style);
298 context.canvas 305 context.canvas
299 ..setStrokeColor(border.bottom.color) 306 ..setStrokeColor(border.bottom.color)
300 - ..setLineWidth(border.bottom.width!) 307 + ..setLineWidth(border.bottom.width)
301 ..drawLine(box!.left, box!.bottom + margin.bottom, box!.right, 308 ..drawLine(box!.left, box!.bottom + margin.bottom, box!.right,
302 box!.bottom + margin.bottom) 309 box!.bottom + margin.bottom)
303 ..strokePath(); 310 ..strokePath();
  311 + BoxBorder.unsetStyle(context, border.bottom.style);
304 } 312 }
305 313
306 context.canvas.restoreContext(); 314 context.canvas.restoreContext();
@@ -106,23 +106,32 @@ class TableBorder extends Border { @@ -106,23 +106,32 @@ class TableBorder extends Border {
106 super.paint(context, box); 106 super.paint(context, box);
107 107
108 if (verticalInside.style != BorderStyle.none) { 108 if (verticalInside.style != BorderStyle.none) {
  109 + BoxBorder.setStyle(context, verticalInside.style);
109 var offset = box.x; 110 var offset = box.x;
110 for (var width in widths!.sublist(0, widths.length - 1)) { 111 for (var width in widths!.sublist(0, widths.length - 1)) {
111 offset += width!; 112 offset += width!;
112 context.canvas.moveTo(offset, box.y); 113 context.canvas.moveTo(offset, box.y);
113 context.canvas.lineTo(offset, box.top); 114 context.canvas.lineTo(offset, box.top);
114 } 115 }
  116 + context.canvas.setStrokeColor(verticalInside.color);
  117 + context.canvas.setLineWidth(verticalInside.width);
115 context.canvas.strokePath(); 118 context.canvas.strokePath();
  119 +
  120 + BoxBorder.unsetStyle(context, verticalInside.style);
116 } 121 }
117 122
118 if (horizontalInside.style != BorderStyle.none) { 123 if (horizontalInside.style != BorderStyle.none) {
  124 + BoxBorder.setStyle(context, verticalInside.style);
119 var offset = box.top; 125 var offset = box.top;
120 for (var height in heights!.sublist(0, heights.length - 1)) { 126 for (var height in heights!.sublist(0, heights.length - 1)) {
121 offset -= height; 127 offset -= height;
122 context.canvas.moveTo(box.x, offset); 128 context.canvas.moveTo(box.x, offset);
123 context.canvas.lineTo(box.right, offset); 129 context.canvas.lineTo(box.right, offset);
124 } 130 }
  131 + context.canvas.setStrokeColor(verticalInside.color);
  132 + context.canvas.setLineWidth(verticalInside.width);
125 context.canvas.strokePath(); 133 context.canvas.strokePath();
  134 + BoxBorder.unsetStyle(context, verticalInside.style);
126 } 135 }
127 } 136 }
128 } 137 }
@@ -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: 3.0.0-nullsafety.0 7 +version: 3.0.0-nullsafety.1
8 8
9 environment: 9 environment:
10 sdk: ">=2.12.0-0 <3.0.0" 10 sdk: ">=2.12.0-0 <3.0.0"