David PHAM-VAN

Add default page margins

@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 * Change PdfColor.fromInt to const constructor 3 * Change PdfColor.fromInt to const constructor
4 * Fix drawShape Bézier curves 4 * Fix drawShape Bézier curves
5 * Add arcs to SVG drawShape 5 * Add arcs to SVG drawShape
  6 +* Add default page margins
6 7
7 # 1.1.0 8 # 1.1.0
8 * Rename classes to satisfy Dart conventions 9 * Rename classes to satisfy Dart conventions
@@ -19,11 +19,11 @@ @@ -19,11 +19,11 @@
19 part of pdf; 19 part of pdf;
20 20
21 class PdfPageFormat { 21 class PdfPageFormat {
22 - static const a4 = PdfPageFormat(595.28, 841.89);  
23 - static const a3 = PdfPageFormat(841.89, 1190.55);  
24 - static const a5 = PdfPageFormat(420.94, 595.28);  
25 - static const letter = PdfPageFormat(612.0, 792.0);  
26 - static const legal = PdfPageFormat(612.0, 1008.0); 22 + static const a3 = PdfPageFormat(29.7 * cm, 42 * cm, marginAll: 2.0 * cm);
  23 + static const a4 = PdfPageFormat(21.0 * cm, 29.7 * cm, marginAll: 2.0 * cm);
  24 + static const a5 = PdfPageFormat(14.8 * cm, 21.0 * cm, marginAll: 2.0 * cm);
  25 + static const letter = PdfPageFormat(8.5 * inch, 11.0 * inch, marginAll: inch);
  26 + static const legal = PdfPageFormat(8.5 * inch, 14.0 * inch, marginAll: inch);
27 27
28 static const point = 1.0; 28 static const point = 1.0;
29 static const inch = 72.0; 29 static const inch = 72.0;
@@ -33,15 +33,43 @@ class PdfPageFormat { @@ -33,15 +33,43 @@ class PdfPageFormat {
33 final double width; 33 final double width;
34 final double height; 34 final double height;
35 35
36 - const PdfPageFormat(this.width, this.height); 36 + final double marginTop;
  37 + final double marginBottom;
  38 + final double marginLeft;
  39 + final double marginRight;
  40 +
  41 + const PdfPageFormat(this.width, this.height,
  42 + {double marginTop = 0.0,
  43 + double marginBottom = 0.0,
  44 + double marginLeft = 0.0,
  45 + double marginRight = 0.0,
  46 + double marginAll})
  47 + : marginTop = marginAll ?? marginTop,
  48 + marginBottom = marginAll ?? marginBottom,
  49 + marginLeft = marginAll ?? marginLeft,
  50 + marginRight = marginAll ?? marginRight;
  51 +
  52 + PdfPageFormat copyWith(
  53 + {double width,
  54 + double height,
  55 + double marginTop,
  56 + double marginBottom,
  57 + double marginLeft,
  58 + double marginRight}) {
  59 + return PdfPageFormat(width ?? this.width, height ?? this.height,
  60 + marginTop: marginTop ?? this.marginTop,
  61 + marginBottom: marginBottom ?? this.marginBottom,
  62 + marginLeft: marginLeft ?? this.marginLeft,
  63 + marginRight: marginRight ?? this.marginRight);
  64 + }
37 65
38 PdfPoint get dimension => PdfPoint(width, height); 66 PdfPoint get dimension => PdfPoint(width, height);
39 67
40 PdfPageFormat get landscape => 68 PdfPageFormat get landscape =>
41 - width >= height ? this : PdfPageFormat(height, width); 69 + width >= height ? this : copyWith(width: height, height: width);
42 70
43 PdfPageFormat get portrait => 71 PdfPageFormat get portrait =>
44 - height >= width ? this : PdfPageFormat(height, width); 72 + height >= width ? this : copyWith(width: height, height: width);
45 73
46 @override 74 @override
47 String toString() { 75 String toString() {