David PHAM-VAN

Improve PdfRect

1 # 1.2.0 1 # 1.2.0
2 * Change license to Apache 2.0 2 * Change license to Apache 2.0
  3 +* Improve PdfRect
3 4
4 # 1.1.1 5 # 1.1.1
5 * Improve PdfPoint and PdfRect 6 * Improve PdfPoint and PdfRect
@@ -84,7 +84,7 @@ class PdfAnnot extends PdfObject { @@ -84,7 +84,7 @@ class PdfAnnot extends PdfObject {
84 84
85 params["/Subtype"] = PdfStream.string(subtype); 85 params["/Subtype"] = PdfStream.string(subtype);
86 params["/Rect"] = PdfStream.string( 86 params["/Rect"] = PdfStream.string(
87 - "[${srcRect.l} ${srcRect.b} ${srcRect.r} ${srcRect.t}]"); 87 + "[${srcRect.left} ${srcRect.bottom} ${srcRect.right} ${srcRect.top}]");
88 88
89 // handle the border 89 // handle the border
90 if (border == null) { 90 if (border == null) {
@@ -103,7 +103,7 @@ class PdfAnnot extends PdfObject { @@ -103,7 +103,7 @@ class PdfAnnot extends PdfObject {
103 dests.add(PdfStream.string("/Fit")); 103 dests.add(PdfStream.string("/Fit"));
104 else { 104 else {
105 dests.add(PdfStream.string( 105 dests.add(PdfStream.string(
106 - "/FitR ${destRect.l} ${destRect.b} ${destRect.r} ${destRect.t}")); 106 + "/FitR ${destRect.left} ${destRect.bottom} ${destRect.right} ${destRect.top}"));
107 } 107 }
108 params["/Dest"] = PdfStream.array(dests); 108 params["/Dest"] = PdfStream.array(dests);
109 } 109 }
@@ -63,15 +63,15 @@ class PdfFont extends PdfObject { @@ -63,15 +63,15 @@ class PdfFont extends PdfObject {
63 var r = glyphBounds(c); 63 var r = glyphBounds(c);
64 var x = r.x; 64 var x = r.x;
65 var y = r.y; 65 var y = r.y;
66 - var h = r.h;  
67 - var w = n == chars.length - 1 ? r.w : glyphAdvance(c); 66 + var h = r.height;
  67 + var w = n == chars.length - 1 ? r.width : glyphAdvance(c);
68 68
69 while (++n < chars.length) { 69 while (++n < chars.length) {
70 c = chars[n]; 70 c = chars[n];
71 r = glyphBounds(c); 71 r = glyphBounds(c);
72 if (r.y < y) y = r.y; 72 if (r.y < y) y = r.y;
73 - if (r.h > h) h = r.h;  
74 - w += n == chars.length - 1 ? r.w : glyphAdvance(c); 73 + if (r.height > h) h = r.height;
  74 + w += n == chars.length - 1 ? r.width : glyphAdvance(c);
75 } 75 }
76 76
77 return PdfRect(x, y, w, h); 77 return PdfRect(x, y, w, h);
@@ -85,7 +85,7 @@ class PdfFont extends PdfObject { @@ -85,7 +85,7 @@ class PdfFont extends PdfObject {
85 85
86 for (var c in chars) { 86 for (var c in chars) {
87 var r = glyphBounds(c); 87 var r = glyphBounds(c);
88 - if (r.h > h) h = r.h; 88 + if (r.height > h) h = r.height;
89 w += glyphAdvance(c); 89 w += glyphAdvance(c);
90 } 90 }
91 91
@@ -92,8 +92,8 @@ class PdfOutline extends PdfObject { @@ -92,8 +92,8 @@ class PdfOutline extends PdfObject {
92 if (destMode == PdfOutlineMode.fitpage) { 92 if (destMode == PdfOutlineMode.fitpage) {
93 dests.add(PdfStream.string("/Fit")); 93 dests.add(PdfStream.string("/Fit"));
94 } else { 94 } else {
95 - dests.add(  
96 - PdfStream.string("/FitR ${rect.l} ${rect.b} ${rect.r} ${rect.t}")); 95 + dests.add(PdfStream.string(
  96 + "/FitR ${rect.left} ${rect.bottom} ${rect.right} ${rect.top}"));
97 } 97 }
98 params["/Parent"] = parent.ref(); 98 params["/Parent"] = parent.ref();
99 params["/Dest"] = PdfStream.array(dests); 99 params["/Dest"] = PdfStream.array(dests);
@@ -18,11 +18,11 @@ part of pdf; @@ -18,11 +18,11 @@ part of pdf;
18 18
19 @immutable 19 @immutable
20 class PdfRect { 20 class PdfRect {
21 - final double x, y, w, h; 21 + final double x, y, width, height;
22 22
23 static const zero = PdfRect(0.0, 0.0, 0.0, 0.0); 23 static const zero = PdfRect(0.0, 0.0, 0.0, 0.0);
24 24
25 - const PdfRect(this.x, this.y, this.w, this.h); 25 + const PdfRect(this.x, this.y, this.width, this.height);
26 26
27 factory PdfRect.fromLTRB( 27 factory PdfRect.fromLTRB(
28 double left, double top, double right, double bottom) { 28 double left, double top, double right, double bottom) {
@@ -33,23 +33,36 @@ class PdfRect { @@ -33,23 +33,36 @@ class PdfRect {
33 return PdfRect(offset.x, offset.y, size.x, size.y); 33 return PdfRect(offset.x, offset.y, size.x, size.y);
34 } 34 }
35 35
36 - double get l => x;  
37 - double get b => y;  
38 - double get r => x + w;  
39 - double get t => y + h; 36 + double get left => x;
  37 + double get bottom => y;
  38 + double get right => x + width;
  39 + double get top => y + height;
  40 +
  41 + @deprecated
  42 + double get l => left;
  43 + @deprecated
  44 + double get b => bottom;
  45 + @deprecated
  46 + double get r => right;
  47 + @deprecated
  48 + double get t => top;
  49 + @deprecated
  50 + double get w => width;
  51 + @deprecated
  52 + double get h => height;
40 53
41 @override 54 @override
42 - String toString() => "PdfRect($x, $y, $w, $h)"; 55 + String toString() => "PdfRect($x, $y, $width, $height)";
43 56
44 PdfRect operator *(double factor) { 57 PdfRect operator *(double factor) {
45 - return PdfRect(x * factor, y * factor, w * factor, h * factor); 58 + return PdfRect(x * factor, y * factor, width * factor, height * factor);
46 } 59 }
47 60
48 PdfPoint get offset => PdfPoint(x, y); 61 PdfPoint get offset => PdfPoint(x, y);
49 - PdfPoint get size => PdfPoint(w, h); 62 + PdfPoint get size => PdfPoint(width, height);
50 63
51 PdfPoint get topLeft => PdfPoint(x, y); 64 PdfPoint get topLeft => PdfPoint(x, y);
52 - PdfPoint get topRight => PdfPoint(r, y);  
53 - PdfPoint get bottomLeft => PdfPoint(x, t);  
54 - PdfPoint get bottomRight => PdfPoint(r, t); 65 + PdfPoint get topRight => PdfPoint(right, y);
  66 + PdfPoint get bottomLeft => PdfPoint(x, top);
  67 + PdfPoint get bottomRight => PdfPoint(right, top);
55 } 68 }
@@ -70,7 +70,7 @@ void main() { @@ -70,7 +70,7 @@ void main() {
70 var r = font2.stringBounds(s); 70 var r = font2.stringBounds(s);
71 const FS = 20.0; 71 const FS = 20.0;
72 g.setColor(PdfColor(0.0, 1.0, 1.0)); 72 g.setColor(PdfColor(0.0, 1.0, 1.0));
73 - g.drawRect(50.0 + r.x * FS, 30.0 + r.y * FS, r.w * FS, r.h * FS); 73 + g.drawRect(50.0 + r.x * FS, 30.0 + r.y * FS, r.width * FS, r.height * FS);
74 g.fillPath(); 74 g.fillPath();
75 g.setColor(PdfColor(0.3, 0.3, 0.3)); 75 g.setColor(PdfColor(0.3, 0.3, 0.3));
76 g.drawString(font2, FS, s, 50.0, 30.0); 76 g.drawString(font2, FS, s, 50.0, 30.0);
@@ -35,7 +35,7 @@ void main() { @@ -35,7 +35,7 @@ void main() {
35 var r = ttf.stringBounds(s); 35 var r = ttf.stringBounds(s);
36 const FS = 20.0; 36 const FS = 20.0;
37 g.setColor(PdfColor(0.0, 1.0, 1.0)); 37 g.setColor(PdfColor(0.0, 1.0, 1.0));
38 - g.drawRect(50.0 + r.x * FS, 30.0 + r.y * FS, r.w * FS, r.h * FS); 38 + g.drawRect(50.0 + r.x * FS, 30.0 + r.y * FS, r.width * FS, r.height * FS);
39 g.fillPath(); 39 g.fillPath();
40 g.setColor(PdfColor(0.3, 0.3, 0.3)); 40 g.setColor(PdfColor(0.3, 0.3, 0.3));
41 g.drawString(ttf, FS, s, 50.0, 30.0); 41 g.drawString(ttf, FS, s, 50.0, 30.0);
@@ -48,7 +48,7 @@ void main() { @@ -48,7 +48,7 @@ void main() {
48 48
49 r = roboto.stringBounds(s); 49 r = roboto.stringBounds(s);
50 g.setColor(PdfColor(0.0, 1.0, 1.0)); 50 g.setColor(PdfColor(0.0, 1.0, 1.0));
51 - g.drawRect(50.0 + r.x * FS, 130.0 + r.y * FS, r.w * FS, r.h * FS); 51 + g.drawRect(50.0 + r.x * FS, 130.0 + r.y * FS, r.width * FS, r.height * FS);
52 g.fillPath(); 52 g.fillPath();
53 g.setColor(PdfColor(0.3, 0.3, 0.3)); 53 g.setColor(PdfColor(0.3, 0.3, 0.3));
54 g.drawString(roboto, FS, s, 50.0, 130.0); 54 g.drawString(roboto, FS, s, 50.0, 130.0);
@@ -25,7 +25,7 @@ void printText(PdfGraphics g, String text, PdfFont font, double top) { @@ -25,7 +25,7 @@ void printText(PdfGraphics g, String text, PdfFont font, double top) {
25 const FS = 20.0; 25 const FS = 20.0;
26 g.setColor(PdfColor(0.9, 0.9, 0.9)); 26 g.setColor(PdfColor(0.9, 0.9, 0.9));
27 g.drawRect(50.0 + r.x * FS, g.page.pageFormat.height - top + r.y * FS, 27 g.drawRect(50.0 + r.x * FS, g.page.pageFormat.height - top + r.y * FS,
28 - r.w * FS, r.h * FS); 28 + r.width * FS, r.height * FS);
29 g.fillPath(); 29 g.fillPath();
30 g.setColor(PdfColor(0.3, 0.3, 0.3)); 30 g.setColor(PdfColor(0.3, 0.3, 0.3));
31 g.drawString(font, FS, text, 50.0, g.page.pageFormat.height - top); 31 g.drawString(font, FS, text, 50.0, g.page.pageFormat.height - top);