David PHAM-VAN

Improve PdfRect

# 1.2.0
* Change license to Apache 2.0
* Improve PdfRect
# 1.1.1
* Improve PdfPoint and PdfRect
... ...
... ... @@ -84,7 +84,7 @@ class PdfAnnot extends PdfObject {
params["/Subtype"] = PdfStream.string(subtype);
params["/Rect"] = PdfStream.string(
"[${srcRect.l} ${srcRect.b} ${srcRect.r} ${srcRect.t}]");
"[${srcRect.left} ${srcRect.bottom} ${srcRect.right} ${srcRect.top}]");
// handle the border
if (border == null) {
... ... @@ -103,7 +103,7 @@ class PdfAnnot extends PdfObject {
dests.add(PdfStream.string("/Fit"));
else {
dests.add(PdfStream.string(
"/FitR ${destRect.l} ${destRect.b} ${destRect.r} ${destRect.t}"));
"/FitR ${destRect.left} ${destRect.bottom} ${destRect.right} ${destRect.top}"));
}
params["/Dest"] = PdfStream.array(dests);
}
... ...
... ... @@ -63,15 +63,15 @@ class PdfFont extends PdfObject {
var r = glyphBounds(c);
var x = r.x;
var y = r.y;
var h = r.h;
var w = n == chars.length - 1 ? r.w : glyphAdvance(c);
var h = r.height;
var w = n == chars.length - 1 ? r.width : glyphAdvance(c);
while (++n < chars.length) {
c = chars[n];
r = glyphBounds(c);
if (r.y < y) y = r.y;
if (r.h > h) h = r.h;
w += n == chars.length - 1 ? r.w : glyphAdvance(c);
if (r.height > h) h = r.height;
w += n == chars.length - 1 ? r.width : glyphAdvance(c);
}
return PdfRect(x, y, w, h);
... ... @@ -85,7 +85,7 @@ class PdfFont extends PdfObject {
for (var c in chars) {
var r = glyphBounds(c);
if (r.h > h) h = r.h;
if (r.height > h) h = r.height;
w += glyphAdvance(c);
}
... ...
... ... @@ -92,8 +92,8 @@ class PdfOutline extends PdfObject {
if (destMode == PdfOutlineMode.fitpage) {
dests.add(PdfStream.string("/Fit"));
} else {
dests.add(
PdfStream.string("/FitR ${rect.l} ${rect.b} ${rect.r} ${rect.t}"));
dests.add(PdfStream.string(
"/FitR ${rect.left} ${rect.bottom} ${rect.right} ${rect.top}"));
}
params["/Parent"] = parent.ref();
params["/Dest"] = PdfStream.array(dests);
... ...
... ... @@ -18,11 +18,11 @@ part of pdf;
@immutable
class PdfRect {
final double x, y, w, h;
final double x, y, width, height;
static const zero = PdfRect(0.0, 0.0, 0.0, 0.0);
const PdfRect(this.x, this.y, this.w, this.h);
const PdfRect(this.x, this.y, this.width, this.height);
factory PdfRect.fromLTRB(
double left, double top, double right, double bottom) {
... ... @@ -33,23 +33,36 @@ class PdfRect {
return PdfRect(offset.x, offset.y, size.x, size.y);
}
double get l => x;
double get b => y;
double get r => x + w;
double get t => y + h;
double get left => x;
double get bottom => y;
double get right => x + width;
double get top => y + height;
@deprecated
double get l => left;
@deprecated
double get b => bottom;
@deprecated
double get r => right;
@deprecated
double get t => top;
@deprecated
double get w => width;
@deprecated
double get h => height;
@override
String toString() => "PdfRect($x, $y, $w, $h)";
String toString() => "PdfRect($x, $y, $width, $height)";
PdfRect operator *(double factor) {
return PdfRect(x * factor, y * factor, w * factor, h * factor);
return PdfRect(x * factor, y * factor, width * factor, height * factor);
}
PdfPoint get offset => PdfPoint(x, y);
PdfPoint get size => PdfPoint(w, h);
PdfPoint get size => PdfPoint(width, height);
PdfPoint get topLeft => PdfPoint(x, y);
PdfPoint get topRight => PdfPoint(r, y);
PdfPoint get bottomLeft => PdfPoint(x, t);
PdfPoint get bottomRight => PdfPoint(r, t);
PdfPoint get topRight => PdfPoint(right, y);
PdfPoint get bottomLeft => PdfPoint(x, top);
PdfPoint get bottomRight => PdfPoint(right, top);
}
... ...
... ... @@ -70,7 +70,7 @@ void main() {
var r = font2.stringBounds(s);
const FS = 20.0;
g.setColor(PdfColor(0.0, 1.0, 1.0));
g.drawRect(50.0 + r.x * FS, 30.0 + r.y * FS, r.w * FS, r.h * FS);
g.drawRect(50.0 + r.x * FS, 30.0 + r.y * FS, r.width * FS, r.height * FS);
g.fillPath();
g.setColor(PdfColor(0.3, 0.3, 0.3));
g.drawString(font2, FS, s, 50.0, 30.0);
... ...
... ... @@ -35,7 +35,7 @@ void main() {
var r = ttf.stringBounds(s);
const FS = 20.0;
g.setColor(PdfColor(0.0, 1.0, 1.0));
g.drawRect(50.0 + r.x * FS, 30.0 + r.y * FS, r.w * FS, r.h * FS);
g.drawRect(50.0 + r.x * FS, 30.0 + r.y * FS, r.width * FS, r.height * FS);
g.fillPath();
g.setColor(PdfColor(0.3, 0.3, 0.3));
g.drawString(ttf, FS, s, 50.0, 30.0);
... ... @@ -48,7 +48,7 @@ void main() {
r = roboto.stringBounds(s);
g.setColor(PdfColor(0.0, 1.0, 1.0));
g.drawRect(50.0 + r.x * FS, 130.0 + r.y * FS, r.w * FS, r.h * FS);
g.drawRect(50.0 + r.x * FS, 130.0 + r.y * FS, r.width * FS, r.height * FS);
g.fillPath();
g.setColor(PdfColor(0.3, 0.3, 0.3));
g.drawString(roboto, FS, s, 50.0, 130.0);
... ...
... ... @@ -25,7 +25,7 @@ void printText(PdfGraphics g, String text, PdfFont font, double top) {
const FS = 20.0;
g.setColor(PdfColor(0.9, 0.9, 0.9));
g.drawRect(50.0 + r.x * FS, g.page.pageFormat.height - top + r.y * FS,
r.w * FS, r.h * FS);
r.width * FS, r.height * FS);
g.fillPath();
g.setColor(PdfColor(0.3, 0.3, 0.3));
g.drawString(font, FS, text, 50.0, g.page.pageFormat.height - top);
... ...