Showing
5 changed files
with
93 additions
and
2 deletions
@@ -38,6 +38,9 @@ class PdfRect { | @@ -38,6 +38,9 @@ class PdfRect { | ||
38 | double get right => x + width; | 38 | double get right => x + width; |
39 | double get top => y + height; | 39 | double get top => y + height; |
40 | 40 | ||
41 | + double get horizondalCenter => x + width / 2; | ||
42 | + double get verticalCenter => y + height / 2; | ||
43 | + | ||
41 | @deprecated | 44 | @deprecated |
42 | double get l => left; | 45 | double get l => left; |
43 | @deprecated | 46 | @deprecated |
@@ -257,6 +257,82 @@ class Align extends SingleChildWidget { | @@ -257,6 +257,82 @@ class Align extends SingleChildWidget { | ||
257 | } | 257 | } |
258 | 258 | ||
259 | @override | 259 | @override |
260 | + void debugPaint(Context context) { | ||
261 | + context.canvas | ||
262 | + ..setStrokeColor(PdfColors.green) | ||
263 | + ..drawRect(box.x, box.y, box.width, box.height); | ||
264 | + | ||
265 | + if (child == null) { | ||
266 | + context.canvas.strokePath(); | ||
267 | + return; | ||
268 | + } | ||
269 | + | ||
270 | + if (child.box.bottom > box.bottom) { | ||
271 | + final double headSize = | ||
272 | + math.min((child.box.bottom - box.bottom) * 0.2, 10); | ||
273 | + context.canvas | ||
274 | + ..moveTo( | ||
275 | + box.left + child.box.horizondalCenter, | ||
276 | + box.bottom, | ||
277 | + ) | ||
278 | + ..lineTo(box.left + child.box.horizondalCenter, | ||
279 | + box.bottom + child.box.bottom) | ||
280 | + ..lineTo(box.left + child.box.horizondalCenter - headSize, | ||
281 | + box.bottom + child.box.bottom - headSize) | ||
282 | + ..moveTo(box.left + child.box.horizondalCenter, | ||
283 | + box.bottom + child.box.bottom) | ||
284 | + ..lineTo(box.left + child.box.horizondalCenter + headSize, | ||
285 | + box.bottom + child.box.bottom - headSize); | ||
286 | + } | ||
287 | + | ||
288 | + if (box.bottom + child.box.top < box.top) { | ||
289 | + final double headSize = | ||
290 | + math.min((box.top - child.box.top - box.bottom) * 0.2, 10); | ||
291 | + context.canvas | ||
292 | + ..moveTo(box.left + child.box.horizondalCenter, box.top) | ||
293 | + ..lineTo( | ||
294 | + box.left + child.box.horizondalCenter, box.bottom + child.box.top) | ||
295 | + ..lineTo(box.left + child.box.horizondalCenter - headSize, | ||
296 | + box.bottom + child.box.top + headSize) | ||
297 | + ..moveTo( | ||
298 | + box.left + child.box.horizondalCenter, box.bottom + child.box.top) | ||
299 | + ..lineTo(box.left + child.box.horizondalCenter + headSize, | ||
300 | + box.bottom + child.box.top + headSize); | ||
301 | + } | ||
302 | + | ||
303 | + if (child.box.left > box.left) { | ||
304 | + final double headSize = math.min((child.box.left - box.left) * 0.2, 10); | ||
305 | + context.canvas | ||
306 | + ..moveTo(box.left, box.bottom + child.box.verticalCenter) | ||
307 | + ..lineTo( | ||
308 | + box.left + child.box.left, box.bottom + child.box.verticalCenter) | ||
309 | + ..lineTo(box.left + child.box.left - headSize, | ||
310 | + box.bottom + child.box.verticalCenter - headSize) | ||
311 | + ..moveTo( | ||
312 | + box.left + child.box.left, box.bottom + child.box.verticalCenter) | ||
313 | + ..lineTo(box.left + child.box.left - headSize, | ||
314 | + box.bottom + child.box.verticalCenter + headSize); | ||
315 | + } | ||
316 | + | ||
317 | + if (box.left + child.box.right < box.right) { | ||
318 | + final double headSize = | ||
319 | + math.min((box.right - child.box.right - box.left) * 0.2, 10); | ||
320 | + context.canvas | ||
321 | + ..moveTo(box.right, box.bottom + child.box.verticalCenter) | ||
322 | + ..lineTo( | ||
323 | + box.left + child.box.right, box.bottom + child.box.verticalCenter) | ||
324 | + ..lineTo(box.left + child.box.right + headSize, | ||
325 | + box.bottom + child.box.verticalCenter - headSize) | ||
326 | + ..moveTo( | ||
327 | + box.left + child.box.right, box.bottom + child.box.verticalCenter) | ||
328 | + ..lineTo(box.left + child.box.right + headSize, | ||
329 | + box.bottom + child.box.verticalCenter + headSize); | ||
330 | + } | ||
331 | + | ||
332 | + context.canvas.strokePath(); | ||
333 | + } | ||
334 | + | ||
335 | + @override | ||
260 | void paint(Context context) { | 336 | void paint(Context context) { |
261 | super.paint(context); | 337 | super.paint(context); |
262 | paintChild(context); | 338 | paintChild(context); |
@@ -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.15 | 7 | +version: 1.3.16 |
8 | 8 | ||
9 | environment: | 9 | environment: |
10 | sdk: ">=2.1.0 <3.0.0" | 10 | sdk: ">=2.1.0 <3.0.0" |
@@ -28,7 +28,7 @@ void main() { | @@ -28,7 +28,7 @@ void main() { | ||
28 | pdf = Document(); | 28 | pdf = Document(); |
29 | }); | 29 | }); |
30 | 30 | ||
31 | - test('Basic Widgets Align', () { | 31 | + test('Basic Widgets Align 1', () { |
32 | pdf.addPage(Page( | 32 | pdf.addPage(Page( |
33 | build: (Context context) => Align( | 33 | build: (Context context) => Align( |
34 | alignment: Alignment.bottomRight, | 34 | alignment: Alignment.bottomRight, |
@@ -36,6 +36,14 @@ void main() { | @@ -36,6 +36,14 @@ void main() { | ||
36 | ))); | 36 | ))); |
37 | }); | 37 | }); |
38 | 38 | ||
39 | + test('Basic Widgets Align 2', () { | ||
40 | + pdf.addPage(Page( | ||
41 | + build: (Context context) => Align( | ||
42 | + alignment: const Alignment(0.8, 0.2), | ||
43 | + child: SizedBox(width: 100, height: 100, child: PdfLogo()), | ||
44 | + ))); | ||
45 | + }); | ||
46 | + | ||
39 | test('Basic Widgets AspectRatio', () { | 47 | test('Basic Widgets AspectRatio', () { |
40 | pdf.addPage(Page( | 48 | pdf.addPage(Page( |
41 | build: (Context context) => AspectRatio( | 49 | build: (Context context) => AspectRatio( |
-
Please register or login to post a comment