David PHAM-VAN

Rename classes to satisfy Dart conventions

@@ -10,21 +10,21 @@ images and text using TrueType fonts. @@ -10,21 +10,21 @@ images and text using TrueType fonts.
10 The coordinate system is using the internal Pdf system: 10 The coordinate system is using the internal Pdf system:
11 * (0.0, 0.0) is bottom-left 11 * (0.0, 0.0) is bottom-left
12 * 1.0 is defined as 1 / 72.0 inch 12 * 1.0 is defined as 1 / 72.0 inch
13 - * you can use the constants for centimeters, milimeters and inch defined in PDFPageFormat 13 + * you can use the constants for centimeters, milimeters and inch defined in PdfPageFormat
14 14
15 Example: 15 Example:
16 ```dart 16 ```dart
17 -final pdf = new PDFDocument();  
18 -final page = new PDFPage(pdf, pageFormat: PDFPageFormat.letter); 17 +final pdf = new PdfDocument();
  18 +final page = new PdfPage(pdf, pageFormat: PdfPageFormat.letter);
19 final g = page.getGraphics(); 19 final g = page.getGraphics();
20 -final font = new PDFFont(pdf); 20 +final font = new PdfFont(pdf);
21 21
22 -g.setColor(new PDFColor(0.0, 1.0, 1.0)); 22 +g.setColor(new PdfColor(0.0, 1.0, 1.0));
23 g.drawRect(50.0, 30.0, 100.0, 50.0); 23 g.drawRect(50.0, 30.0, 100.0, 50.0);
24 g.fillPath(); 24 g.fillPath();
25 25
26 -g.setColor(new PDFColor(0.3, 0.3, 0.3));  
27 -g.drawString(font, 12.0, "Hello World!", 5.0 * PDFPageFormat.mm, 300.0); 26 +g.setColor(new PdfColor(0.3, 0.3, 0.3));
  27 +g.drawString(font, 12.0, "Hello World!", 5.0 * PdfPageFormat.mm, 300.0);
28 28
29 var file = new File('file.pdf'); 29 var file = new File('file.pdf');
30 file.writeAsBytesSync(pdf.save()); 30 file.writeAsBytesSync(pdf.save());
@@ -34,7 +34,7 @@ To load an image it is possible to use the dart library [image](https://pub.dart @@ -34,7 +34,7 @@ To load an image it is possible to use the dart library [image](https://pub.dart
34 34
35 ```dart 35 ```dart
36 Image image = decodeImage(new Io.File('test.webp').readAsBytesSync()); 36 Image image = decodeImage(new Io.File('test.webp').readAsBytesSync());
37 -PDFImage image = new PDFImage( 37 +PdfImage image = new PdfImage(
38 pdf, 38 pdf,
39 image: img.data.buffer.asUint8List(), 39 image: img.data.buffer.asUint8List(),
40 width: img.width, 40 width: img.width,
@@ -45,9 +45,9 @@ g.drawImage(image, 100.0, 100.0, 80.0); @@ -45,9 +45,9 @@ g.drawImage(image, 100.0, 100.0, 80.0);
45 To use a TrueType font: 45 To use a TrueType font:
46 46
47 ```dart 47 ```dart
48 -PDFTTFFont ttf = new PDFTTFFont( 48 +PdfTtfFont ttf = new PdfTtfFont(
49 pdf, 49 pdf,
50 (new File("open-sans.ttf").readAsBytesSync() as Uint8List).buffer.asByteData()); 50 (new File("open-sans.ttf").readAsBytesSync() as Uint8List).buffer.asByteData());
51 -g.setColor(new PDFColor(0.3, 0.3, 0.3)); 51 +g.setColor(new PdfColor(0.3, 0.3, 0.3));
52 g.drawString(ttf, 20.0, "Dart is awesome", 50.0, 30.0); 52 g.drawString(ttf, 20.0, "Dart is awesome", 50.0, 30.0);
53 ``` 53 ```
@@ -3,20 +3,20 @@ import 'dart:io'; @@ -3,20 +3,20 @@ import 'dart:io';
3 import 'package:pdf/pdf.dart'; 3 import 'package:pdf/pdf.dart';
4 4
5 void main() { 5 void main() {
6 - final pdf = new PDFDocument(deflate: zlib.encode);  
7 - final page = new PDFPage(pdf, pageFormat: PDFPageFormat.letter); 6 + final pdf = new PdfDocument(deflate: zlib.encode);
  7 + final page = new PdfPage(pdf, pageFormat: PdfPageFormat.letter);
8 final g = page.getGraphics(); 8 final g = page.getGraphics();
9 - final font = new PDFFont(pdf); 9 + final font = new PdfFont(pdf);
10 final top = page.pageFormat.height; 10 final top = page.pageFormat.height;
11 11
12 - g.setColor(new PDFColor(0.0, 1.0, 1.0));  
13 - g.drawRect(50.0 * PDFPageFormat.mm, top - 80.0 * PDFPageFormat.mm,  
14 - 100.0 * PDFPageFormat.mm, 50.0 * PDFPageFormat.mm); 12 + g.setColor(new PdfColor(0.0, 1.0, 1.0));
  13 + g.drawRect(50.0 * PdfPageFormat.mm, top - 80.0 * PdfPageFormat.mm,
  14 + 100.0 * PdfPageFormat.mm, 50.0 * PdfPageFormat.mm);
15 g.fillPath(); 15 g.fillPath();
16 16
17 - g.setColor(new PDFColor(0.3, 0.3, 0.3));  
18 - g.drawString(font, 12.0, "Hello World!", 10.0 * PDFPageFormat.mm,  
19 - top - 10.0 * PDFPageFormat.mm); 17 + g.setColor(new PdfColor(0.3, 0.3, 0.3));
  18 + g.drawString(font, 12.0, "Hello World!", 10.0 * PdfPageFormat.mm,
  19 + top - 10.0 * PdfPageFormat.mm);
20 20
21 var file = new File('example.pdf'); 21 var file = new File('example.pdf');
22 file.writeAsBytesSync(pdf.save()); 22 file.writeAsBytesSync(pdf.save());
@@ -30,6 +30,7 @@ part 'src/ascii85.dart'; @@ -30,6 +30,7 @@ part 'src/ascii85.dart';
30 part 'src/border.dart'; 30 part 'src/border.dart';
31 part 'src/catalog.dart'; 31 part 'src/catalog.dart';
32 part 'src/color.dart'; 32 part 'src/color.dart';
  33 +part 'src/compatibility.dart';
33 part 'src/document.dart'; 34 part 'src/document.dart';
34 part 'src/font.dart'; 35 part 'src/font.dart';
35 part 'src/font_descriptor.dart'; 36 part 'src/font_descriptor.dart';
@@ -18,128 +18,75 @@ @@ -18,128 +18,75 @@
18 18
19 part of pdf; 19 part of pdf;
20 20
21 -class PDFAnnot extends PDFObject {  
22 - /// Solid border. The border is drawn as a solid line.  
23 - static const SOLID = 0;  
24 -  
25 - /// The border is drawn with a dashed line.  
26 - static const DASHED = 1;  
27 -  
28 - /// The border is drawn in a beveled style (faux three-dimensional) such  
29 - /// that it looks as if it is pushed out of the page (opposite of INSET)  
30 - static const BEVELED = 2;  
31 -  
32 - /// The border is drawn in an inset style (faux three-dimensional) such  
33 - /// that it looks as if it is inset into the page (opposite of BEVELED)  
34 - static const INSET = 3;  
35 -  
36 - /// The border is drawn as a line on the bottom of the annotation rectangle  
37 - static const UNDERLINED = 4;  
38 - 21 +class PdfAnnot extends PdfObject {
39 /// The subtype of the outline, ie text, note, etc 22 /// The subtype of the outline, ie text, note, etc
40 final String subtype; 23 final String subtype;
41 24
42 /// The size of the annotation 25 /// The size of the annotation
43 - final double l, b, r, t; 26 + final PdfRect srcRect;
44 27
45 /// The text of a text annotation 28 /// The text of a text annotation
46 final String s; 29 final String s;
47 30
48 - /// flag used to indicate that the destination should fit the screen  
49 - static const FULL_PAGE = -9999.0;  
50 -  
51 /// Link to the Destination page 31 /// Link to the Destination page
52 - PDFObject dest; 32 + final PdfObject dest;
53 33
54 - /// If fl!=FULL_PAGE then this is the region of the destination page shown. 34 + /// If destRect is null then this is the region of the destination page shown.
55 /// Otherwise they are ignored. 35 /// Otherwise they are ignored.
56 - final double fl, fb, fr, ft; 36 + final PdfRect destRect;
57 37
58 /// the border for this annotation 38 /// the border for this annotation
59 - PDFBorder border; 39 + PdfBorder border;
60 40
61 - PDFAnnot(PDFPage pdfPage, 41 + PdfAnnot(PdfPage pdfPage,
62 {String type, 42 {String type,
63 this.s, 43 this.s,
64 - this.l,  
65 - this.b,  
66 - this.r,  
67 - this.t, 44 + this.srcRect,
68 this.subtype, 45 this.subtype,
69 this.dest, 46 this.dest,
70 - this.fl,  
71 - this.fb,  
72 - this.fr,  
73 - this.ft}) 47 + this.destRect})
74 : super(pdfPage.pdfDocument, type) { 48 : super(pdfPage.pdfDocument, type) {
75 pdfPage.annotations.add(this); 49 pdfPage.annotations.add(this);
76 } 50 }
77 51
78 /// This is used to create an annotation. 52 /// This is used to create an annotation.
79 /// @param s Subtype for this annotation 53 /// @param s Subtype for this annotation
80 - /// @param l Left coordinate  
81 - /// @param b Bottom coordinate  
82 - /// @param r Right coordinate  
83 - /// @param t Top coordinate  
84 - factory PDFAnnot.annotation(  
85 - PDFPage pdfPage, String s, double l, double b, double r, double t) =>  
86 - new PDFAnnot(pdfPage, type: "/Annot", s: s, l: l, b: b, r: r, t: t); 54 + /// @param rect coordinates
  55 + factory PdfAnnot.annotation(PdfPage pdfPage, String s, PdfRect rect) =>
  56 + new PdfAnnot(pdfPage, type: "/Annot", s: s, srcRect: rect);
87 57
88 /// Creates a text annotation 58 /// Creates a text annotation
89 - /// @param l Left coordinate  
90 - /// @param b Bottom coordinate  
91 - /// @param r Right coordinate  
92 - /// @param t Top coordinate 59 + /// @param rect coordinates
93 /// @param s Text for this annotation 60 /// @param s Text for this annotation
94 - factory PDFAnnot.text(  
95 - PDFPage pdfPage, double l, double b, double r, double t, String s) =>  
96 - new PDFAnnot(pdfPage, type: "/Text", l: l, b: b, r: r, t: t, s: s); 61 + factory PdfAnnot.text(PdfPage pdfPage, PdfRect rect, String s) =>
  62 + new PdfAnnot(pdfPage, type: "/Text", srcRect: rect, s: s);
97 63
98 /// Creates a link annotation 64 /// Creates a link annotation
99 - /// @param l Left coordinate  
100 - /// @param b Bottom coordinate  
101 - /// @param r Right coordinate  
102 - /// @param t Top coordinate 65 + /// @param srcRect coordinates
103 /// @param dest Destination for this link. The page will fit the display. 66 /// @param dest Destination for this link. The page will fit the display.
104 - /// @param fl Left coordinate  
105 - /// @param fb Bottom coordinate  
106 - /// @param fr Right coordinate  
107 - /// @param ft Top coordinate  
108 - /// <br><br>Rectangle describing what part of the page to be displayed 67 + /// @param destRect Rectangle describing what part of the page to be displayed
109 /// (must be in User Coordinates) 68 /// (must be in User Coordinates)
110 - factory PDFAnnot.link(PDFPage pdfPage, double l, double b, double r, double t,  
111 - PDFObject dest,  
112 - [double fl = FULL_PAGE,  
113 - double fb = FULL_PAGE,  
114 - double fr = FULL_PAGE,  
115 - double ft = FULL_PAGE]) =>  
116 - new PDFAnnot(pdfPage,  
117 - type: "/Link",  
118 - l: l,  
119 - b: b,  
120 - r: r,  
121 - t: t,  
122 - dest: dest,  
123 - fl: fl,  
124 - fb: fb,  
125 - fr: fr,  
126 - ft: ft); 69 + factory PdfAnnot.link(PdfPage pdfPage, PdfRect srcRect, PdfObject dest,
  70 + [PdfRect destRect]) =>
  71 + new PdfAnnot(pdfPage,
  72 + type: "/Link", srcRect: srcRect, dest: dest, destRect: destRect);
127 73
128 /// Sets the border for the annotation. By default, no border is defined. 74 /// Sets the border for the annotation. By default, no border is defined.
129 /// 75 ///
130 - /// <p>If the style is DASHED, then this method uses PDF's default dash 76 + /// If the style is dashed, then this method uses Pdf's default dash
131 /// scheme {3} 77 /// scheme {3}
132 /// 78 ///
133 - /// <p>Important: the annotation must have been added to the document before 79 + /// Important: the annotation must have been added to the document before
134 /// this is used. If the annotation was created using the methods in 80 /// this is used. If the annotation was created using the methods in
135 - /// PDFPage, then the annotation is already in the document. 81 + /// [PdfPage], then the annotation is already in the document.
136 /// 82 ///
137 - /// @param style Border style SOLID, DASHED, BEVELED, INSET or UNDERLINED. 83 + /// @param style Border style solid, dashed, beveled, inset or underlined.
138 /// @param width Width of the border 84 /// @param width Width of the border
139 /// @param dash Array of lengths, used for drawing the dashes. If this 85 /// @param dash Array of lengths, used for drawing the dashes. If this
140 /// is null, then the default of {3} is used. 86 /// is null, then the default of {3} is used.
141 - void setBorder(double width, {int style = 0, List<double> dash}) {  
142 - border = new PDFBorder(pdfDocument, width, style: style, dash: dash); 87 + void setBorder(double width,
  88 + {PdfBorderStyle style = PdfBorderStyle.solid, List<double> dash}) {
  89 + border = new PdfBorder(pdfDocument, width, style: style, dash: dash);
143 } 90 }
144 91
145 /// Output the annotation 92 /// Output the annotation
@@ -149,28 +96,30 @@ class PDFAnnot extends PDFObject { @@ -149,28 +96,30 @@ class PDFAnnot extends PDFObject {
149 void prepare() { 96 void prepare() {
150 super.prepare(); 97 super.prepare();
151 98
152 - params["/Subtype"] = PDFStream.string(subtype);  
153 - params["/Rect"] = PDFStream.string("[$l $b $r $t]"); 99 + params["/Subtype"] = PdfStream.string(subtype);
  100 + params["/Rect"] = PdfStream.string(
  101 + "[${srcRect.l} ${srcRect.b} ${srcRect.r} ${srcRect.t}]");
154 102
155 // handle the border 103 // handle the border
156 if (border == null) { 104 if (border == null) {
157 - params["/Border"] = PDFStream.string("[0 0 0]"); 105 + params["/Border"] = PdfStream.string("[0 0 0]");
158 } else { 106 } else {
159 params["/BS"] = border.ref(); 107 params["/BS"] = border.ref();
160 } 108 }
161 109
162 // Now the annotation subtypes 110 // Now the annotation subtypes
163 if (subtype == "/Text") { 111 if (subtype == "/Text") {
164 - params["/Contents"] = PDFStream.string(s); 112 + params["/Contents"] = PdfStream.string(s);
165 } else if (subtype == "/Link") { 113 } else if (subtype == "/Link") {
166 - var dests = new List<PDFStream>(); 114 + var dests = new List<PdfStream>();
167 dests.add(dest.ref()); 115 dests.add(dest.ref());
168 - if (fl == FULL_PAGE)  
169 - dests.add(PDFStream.string("/Fit")); 116 + if (destRect == null)
  117 + dests.add(PdfStream.string("/Fit"));
170 else { 118 else {
171 - dests.add(PDFStream.string("/FitR $fl $fb $fr $ft")); 119 + dests.add(PdfStream.string(
  120 + "/FitR ${destRect.l} ${destRect.b} ${destRect.r} ${destRect.t}"));
172 } 121 }
173 - params["/Dest"] = PDFStream.array(dests); 122 + params["/Dest"] = PdfStream.array(dests);
174 } 123 }
175 } 124 }
176 } 125 }
@@ -18,13 +18,13 @@ @@ -18,13 +18,13 @@
18 18
19 part of pdf; 19 part of pdf;
20 20
21 -class PDFArrayObject extends PDFObject { 21 +class PdfArrayObject extends PdfObject {
22 final List<String> values; 22 final List<String> values;
23 23
24 - PDFArrayObject(PDFDocument pdfDocument, this.values) : super(pdfDocument); 24 + PdfArrayObject(PdfDocument pdfDocument, this.values) : super(pdfDocument);
25 25
26 @override 26 @override
27 - void writeContent(PDFStream os) { 27 + void writeContent(PdfStream os) {
28 super.writeContent(os); 28 super.writeContent(os);
29 29
30 os.putStringArray(values); 30 os.putStringArray(values);
@@ -18,9 +18,28 @@ @@ -18,9 +18,28 @@
18 18
19 part of pdf; 19 part of pdf;
20 20
21 -class PDFBorder extends PDFObject { 21 +enum PdfBorderStyle {
  22 + /// Solid border. The border is drawn as a solid line.
  23 + solid,
  24 +
  25 + /// The border is drawn with a dashed line.
  26 + dashed,
  27 +
  28 + /// The border is drawn in a beveled style (faux three-dimensional) such
  29 + /// that it looks as if it is pushed out of the page (opposite of INSET)
  30 + beveled,
  31 +
  32 + /// The border is drawn in an inset style (faux three-dimensional) such
  33 + /// that it looks as if it is inset into the page (opposite of BEVELED)
  34 + inset,
  35 +
  36 + /// The border is drawn as a line on the bottom of the annotation rectangle
  37 + underlined
  38 +}
  39 +
  40 +class PdfBorder extends PdfObject {
22 /// The style of the border 41 /// The style of the border
23 - final int style; 42 + final PdfBorderStyle style;
24 43
25 /// The width of the border 44 /// The width of the border
26 final double width; 45 final double width;
@@ -28,29 +47,31 @@ class PDFBorder extends PDFObject { @@ -28,29 +47,31 @@ class PDFBorder extends PDFObject {
28 /// This array allows the definition of a dotted line for the border 47 /// This array allows the definition of a dotted line for the border
29 final List<double> dash; 48 final List<double> dash;
30 49
31 - /// Creates a border using the predefined styles in PDFAnnot.  
32 - /// <p>Note: Do not use PDFAnnot.DASHED with this method. 50 + /// Creates a border using the predefined styles in [PdfAnnot].
  51 + /// Note: Do not use [PdfAnnot.dashed] with this method.
33 /// Use the other constructor. 52 /// Use the other constructor.
34 /// 53 ///
35 /// @param width The width of the border 54 /// @param width The width of the border
36 /// @param style The style of the border 55 /// @param style The style of the border
37 /// @param dash The line pattern definition 56 /// @param dash The line pattern definition
38 - /// @see PDFAnnot  
39 - PDFBorder(PDFDocument pdfDocument, this.width, {this.style = 0, this.dash}) 57 + /// @see [PdfAnnot]
  58 + PdfBorder(PdfDocument pdfDocument, this.width,
  59 + {this.style = PdfBorderStyle.solid, this.dash})
40 : super(pdfDocument); 60 : super(pdfDocument);
41 61
42 /// @param os OutputStream to send the object to 62 /// @param os OutputStream to send the object to
43 @override 63 @override
44 - void writeContent(PDFStream os) { 64 + void writeContent(PdfStream os) {
45 super.writeContent(os); 65 super.writeContent(os);
46 66
47 - var data = new List<PDFStream>();  
48 - data.add(PDFStream.string("/S"));  
49 - data.add(PDFStream.string("/" + "SDBIU".substring(style, style + 1)));  
50 - data.add(PDFStream.string("/W $width")); 67 + var data = new List<PdfStream>();
  68 + data.add(PdfStream.string("/S"));
  69 + data.add(PdfStream.string(
  70 + "/" + "SDBIU".substring(style.index, style.index + 1)));
  71 + data.add(PdfStream.string("/W $width"));
51 if (dash != null) { 72 if (dash != null) {
52 - data.add(PDFStream.string("/D"));  
53 - data.add(PDFStream.array(dash.map((double d) => PDFStream.num(d)))); 73 + data.add(PdfStream.string("/D"));
  74 + data.add(PdfStream.array(dash.map((double d) => PdfStream.num(d))));
54 } 75 }
55 os.putArray(data); 76 os.putArray(data);
56 } 77 }
@@ -18,23 +18,22 @@ @@ -18,23 +18,22 @@
18 18
19 part of pdf; 19 part of pdf;
20 20
21 -class PDFCatalog extends PDFObject { 21 +class PdfCatalog extends PdfObject {
22 /// The pages of the document 22 /// The pages of the document
23 - final PDFPageList pdfPageList; 23 + final PdfPageList pdfPageList;
24 24
25 /// The outlines of the document 25 /// The outlines of the document
26 - PDFOutline outlines; 26 + PdfOutline outlines;
27 27
28 /// The initial page mode 28 /// The initial page mode
29 - final PDFPageMode pageMode; 29 + final PdfPageMode pageMode;
30 30
31 - /// This constructs a PDF Catalog object 31 + /// This constructs a Pdf Catalog object
32 /// 32 ///
33 - /// @param pdfPageList The PDFPageList object that's the root  
34 - /// of the documents page tree 33 + /// @param pdfPageList The [PdfPageList] object that's the root of the documents page tree
35 /// @param pagemode How the document should appear when opened. 34 /// @param pagemode How the document should appear when opened.
36 - /// Allowed values are USENONE, USEOUTLINES, USETHUMBS or FULLSCREEN.  
37 - PDFCatalog(PDFDocument pdfDocument, this.pdfPageList, this.pageMode) 35 + /// Allowed values are usenone, useoutlines, usethumbs or fullscreen.
  36 + PdfCatalog(PdfDocument pdfDocument, this.pdfPageList, this.pageMode)
38 : super(pdfDocument, "/Catalog"); 37 : super(pdfDocument, "/Catalog");
39 38
40 /// @param os OutputStream to send the object to 39 /// @param os OutputStream to send the object to
@@ -51,6 +50,6 @@ class PDFCatalog extends PDFObject { @@ -51,6 +50,6 @@ class PDFCatalog extends PDFObject {
51 50
52 // the /PageMode setting 51 // the /PageMode setting
53 params["/PageMode"] = 52 params["/PageMode"] =
54 - PDFStream.string(PDFDocument._PDF_PAGE_MODES[pageMode.index]); 53 + PdfStream.string(PdfDocument._PdfPageModes[pageMode.index]);
55 } 54 }
56 } 55 }
@@ -18,26 +18,26 @@ @@ -18,26 +18,26 @@
18 18
19 part of pdf; 19 part of pdf;
20 20
21 -class PDFColor { 21 +class PdfColor {
22 final double a; 22 final double a;
23 final double r; 23 final double r;
24 final double g; 24 final double g;
25 final double b; 25 final double b;
26 26
27 - static var black = new PDFColor(0.0, 0.0, 0.0); 27 + static var black = new PdfColor(0.0, 0.0, 0.0);
28 28
29 - PDFColor(this.r, this.g, this.b, [this.a = 1.0]); 29 + const PdfColor(this.r, this.g, this.b, [this.a = 1.0]);
30 30
31 - factory PDFColor.fromInt(int color) {  
32 - return new PDFColor( 31 + factory PdfColor.fromInt(int color) {
  32 + return new PdfColor(
33 (color >> 16 & 0xff) / 255.0, 33 (color >> 16 & 0xff) / 255.0,
34 (color >> 8 & 0xff) / 255.0, 34 (color >> 8 & 0xff) / 255.0,
35 (color & 0xff) / 255.0, 35 (color & 0xff) / 255.0,
36 (color >> 24 & 0xff) / 255.0); 36 (color >> 24 & 0xff) / 255.0);
37 } 37 }
38 38
39 - factory PDFColor.fromHex(String color) {  
40 - return new PDFColor( 39 + factory PdfColor.fromHex(String color) {
  40 + return new PdfColor(
41 (int.parse(color.substring(0, 1), radix: 16) >> 16 & 0xff) / 255.0, 41 (int.parse(color.substring(0, 1), radix: 16) >> 16 & 0xff) / 255.0,
42 (int.parse(color.substring(2, 3), radix: 16) >> 8 & 0xff) / 255.0, 42 (int.parse(color.substring(2, 3), radix: 16) >> 8 & 0xff) / 255.0,
43 (int.parse(color.substring(4, 5), radix: 16) & 0xff) / 255.0, 43 (int.parse(color.substring(4, 5), radix: 16) & 0xff) / 255.0,
  1 +/*
  2 + * Copyright (C) 2017, David PHAM-VAN <dev.nfet.net@gmail.com>
  3 + *
  4 + * This library is free software; you can redistribute it and/or
  5 + * modify it under the terms of the GNU Lesser General Public
  6 + * License as published by the Free Software Foundation; either
  7 + * version 2.1 of the License, or (at your option) any later version.
  8 + *
  9 + * This library is distributed in the hope that it will be useful,
  10 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12 + * Lesser General Public License for more details.
  13 + *
  14 + * You should have received a copy of the GNU Lesser General Public
  15 + * License along with this library; if not, write to the Free Software
  16 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17 + */
  18 +
  19 +part of pdf;
  20 +
  21 +@deprecated
  22 +class PDFAnnot extends PdfAnnot {
  23 + static const SOLID = PdfBorderStyle.solid;
  24 + static const DASHED = PdfBorderStyle.dashed;
  25 + static const BEVELED = PdfBorderStyle.beveled;
  26 + static const INSET = PdfBorderStyle.inset;
  27 + static const UNDERLINED = PdfBorderStyle.underlined;
  28 + static const FULL_PAGE = -9999.0;
  29 +
  30 + PDFAnnot(PdfPage pdfPage,
  31 + {String type,
  32 + String s,
  33 + double l,
  34 + double b,
  35 + double r,
  36 + double t,
  37 + String subtype,
  38 + PdfObject dest,
  39 + double fl,
  40 + double fb,
  41 + double fr,
  42 + double ft})
  43 + : super(pdfPage,
  44 + type: type,
  45 + s: s,
  46 + srcRect: PdfRect.fromLTRB(l, t, r, b),
  47 + subtype: subtype,
  48 + dest: dest,
  49 + destRect: PdfRect.fromLTRB(fl, ft, fr, fb));
  50 +
  51 + factory PDFAnnot.annotation(
  52 + PdfPage pdfPage, String s, double l, double b, double r, double t) =>
  53 + new PDFAnnot(pdfPage, type: "/Annot", s: s, l: l, b: b, r: r, t: t);
  54 +
  55 + factory PDFAnnot.text(
  56 + PdfPage pdfPage, double l, double b, double r, double t, String s) =>
  57 + new PDFAnnot(pdfPage, type: "/Text", l: l, b: b, r: r, t: t, s: s);
  58 +
  59 + factory PDFAnnot.link(PdfPage pdfPage, double l, double b, double r, double t,
  60 + PdfObject dest,
  61 + [double fl = FULL_PAGE,
  62 + double fb = FULL_PAGE,
  63 + double fr = FULL_PAGE,
  64 + double ft = FULL_PAGE]) =>
  65 + new PDFAnnot(pdfPage,
  66 + type: "/Link",
  67 + l: l,
  68 + b: b,
  69 + r: r,
  70 + t: t,
  71 + dest: dest,
  72 + fl: fl,
  73 + fb: fb,
  74 + fr: fr,
  75 + ft: ft);
  76 +}
  77 +
  78 +@deprecated
  79 +class PDFArrayObject extends PdfArrayObject {
  80 + PDFArrayObject(PdfDocument pdfDocument, List<String> values)
  81 + : super(pdfDocument, values);
  82 +}
  83 +
  84 +@deprecated
  85 +class PDFBorder extends PdfBorder {
  86 + PDFBorder(PdfDocument pdfDocument, double width,
  87 + {int style, List<double> dash})
  88 + : super(pdfDocument, width,
  89 + style: PdfBorderStyle.values[style], dash: dash);
  90 +}
  91 +
  92 +@deprecated
  93 +class PDFCatalog extends PdfCatalog {
  94 + PDFCatalog(
  95 + PdfDocument pdfDocument, PdfPageList pdfPageList, PdfPageMode pageMode)
  96 + : super(pdfDocument, pdfPageList, pageMode);
  97 +}
  98 +
  99 +@deprecated
  100 +class PDFDocument extends PdfDocument {
  101 + PDFDocument(
  102 + {PdfPageMode pageMode = PdfPageMode.none, DeflateCallback deflate})
  103 + : super(pageMode: pageMode, deflate: deflate);
  104 +}
  105 +
  106 +@deprecated
  107 +class PDFColor extends PdfColor {
  108 + PDFColor(double r, double g, double b, [double a = 1.0]) : super(r, g, b, a);
  109 +
  110 + factory PDFColor.fromInt(int color) {
  111 + final c = PdfColor.fromInt(color);
  112 + return PDFColor(c.r, c.g, c.b, c.a);
  113 + }
  114 +
  115 + factory PDFColor.fromHex(String color) {
  116 + final c = PdfColor.fromHex(color);
  117 + return PDFColor(c.r, c.g, c.b, c.a);
  118 + }
  119 +}
  120 +
  121 +@deprecated
  122 +class PDFFontDescriptor extends PdfFontDescriptor {
  123 + PDFFontDescriptor(PdfTtfFont ttfFont, PdfObjectStream file)
  124 + : super(ttfFont, file);
  125 +}
  126 +
  127 +@deprecated
  128 +class PDFFont extends PdfFont {
  129 + PDFFont(PdfDocument pdfDocument,
  130 + {String subtype = "/Type1", String baseFont = "/Helvetica"})
  131 + : super(pdfDocument, subtype: subtype, baseFont: baseFont);
  132 +}
  133 +
  134 +@deprecated
  135 +class PDFFormXObject extends PdfFormXObject {
  136 + PDFFormXObject(PdfDocument pdfDocument) : super(pdfDocument);
  137 +}
  138 +
  139 +@deprecated
  140 +class PDFGraphics extends PdfGraphics {
  141 + PDFGraphics(PdfPage page, PdfStream buf) : super(page, buf);
  142 +}
  143 +
  144 +@deprecated
  145 +class PDFImage extends PdfImage {
  146 + PDFImage(PdfDocument pdfDocument,
  147 + {@required Uint8List image,
  148 + @required int width,
  149 + @required int height,
  150 + bool alpha = true,
  151 + bool alphaChannel = false})
  152 + : super(pdfDocument,
  153 + image: image,
  154 + width: width,
  155 + height: height,
  156 + alpha: alpha,
  157 + alphaChannel: alphaChannel);
  158 +}
  159 +
  160 +@deprecated
  161 +class PDFInfo extends PdfInfo {
  162 + PDFInfo(PdfDocument pdfDocument,
  163 + {String title,
  164 + String author,
  165 + String creator,
  166 + String subject,
  167 + String keywords})
  168 + : super(pdfDocument,
  169 + title: title,
  170 + author: author,
  171 + creator: creator,
  172 + subject: subject,
  173 + keywords: keywords);
  174 +}
  175 +
  176 +@deprecated
  177 +class PDFObjectStream extends PdfObjectStream {
  178 + PDFObjectStream(PdfDocument pdfDocument, {String type, bool isBinary = false})
  179 + : super(pdfDocument, type: type, isBinary: isBinary);
  180 +}
  181 +
  182 +@deprecated
  183 +class PDFObject extends PdfObject {
  184 + PDFObject(PdfDocument pdfDocument, [String type]) : super(pdfDocument, type);
  185 +}
  186 +
  187 +@deprecated
  188 +class PDFOutline extends PdfOutline {
  189 + @deprecated
  190 + static const PdfOutlineMode FITPAGE = PdfOutlineMode.fitpage;
  191 +
  192 + @deprecated
  193 + static const PdfOutlineMode FITRECT = PdfOutlineMode.fitrect;
  194 +
  195 + PDFOutline(PdfDocument pdfDocument,
  196 + {String title, PdfPage dest, double l, double b, double r, double t})
  197 + : super(pdfDocument,
  198 + title: title, dest: dest, rect: PdfRect.fromLTRB(l, t, r, b));
  199 +}
  200 +
  201 +@deprecated
  202 +class PDFOutput extends PdfOutput {
  203 + PDFOutput(PdfStream os) : super(os);
  204 +}
  205 +
  206 +@deprecated
  207 +class PDFPageFormat extends PdfPageFormat {
  208 + static const a4 = PdfPageFormat.a4;
  209 + static const a3 = PdfPageFormat.a3;
  210 + static const a5 = PdfPageFormat.a5;
  211 + static const letter = PdfPageFormat.letter;
  212 + static const legal = PdfPageFormat.legal;
  213 + static const point = PdfPageFormat.point;
  214 + static const inch = PdfPageFormat.inch;
  215 + static const cm = PdfPageFormat.cm;
  216 + static const mm = PdfPageFormat.mm;
  217 + static const A4 = a4;
  218 + static const A3 = a3;
  219 + static const A5 = a5;
  220 + static const LETTER = letter;
  221 + static const LEGAL = legal;
  222 + static const PT = point;
  223 + static const IN = inch;
  224 + static const CM = cm;
  225 + static const MM = mm;
  226 +
  227 + const PDFPageFormat(double width, double height) : super(width, height);
  228 +}
  229 +
  230 +@deprecated
  231 +class PDFPageList extends PdfPageList {
  232 + PDFPageList(PdfDocument pdfDocument) : super(pdfDocument);
  233 +}
  234 +
  235 +@deprecated
  236 +class PDFPage extends PdfPage {
  237 + PDFPage(PdfDocument pdfDocument, {PdfPageFormat pageFormat})
  238 + : super(pdfDocument, pageFormat: pageFormat);
  239 +
  240 + /// Returns the page's PageFormat.
  241 + /// @return PageFormat describing the page size in device units (72dpi)
  242 + /// use pageFormat
  243 + @deprecated
  244 + PdfPageFormat getPageFormat() {
  245 + return pageFormat;
  246 + }
  247 +
  248 + /// Gets the dimensions of the page.
  249 + /// @return a Dimension object containing the width and height of the page.
  250 + /// use pageFormat.dimension
  251 + @deprecated
  252 + PdfPoint getDimension() => new PdfPoint(pageFormat.width, pageFormat.height);
  253 +
  254 + /// This method adds a text note to the document.
  255 + /// @param note Text of the note
  256 + /// @param x Coordinate of note
  257 + /// @param y Coordinate of note
  258 + /// @param w Width of the note
  259 + /// @param h Height of the note
  260 + /// @return Returns the annotation, so other settings can be changed.
  261 + @deprecated
  262 + PdfAnnot addNote(String note, double x, y, w, h) {
  263 + var xy1 = cxy(x, y + h);
  264 + var xy2 = cxy(x + w, y);
  265 + PdfAnnot ob = new PdfAnnot.text(
  266 + this, PdfRect.fromLTRB(xy1.x, xy1.y, xy2.x, xy2.y), note);
  267 + return ob;
  268 + }
  269 +
  270 + /// Adds a hyperlink to the document.
  271 + /// @param x Coordinate of active area
  272 + /// @param y Coordinate of active area
  273 + /// @param w Width of the active area
  274 + /// @param h Height of the active area
  275 + /// @param dest Page that will be displayed when the link is activated. When
  276 + /// displayed, the zoom factor will be changed to fit the display.
  277 + /// @param vx Coordinate of view area
  278 + /// @param vy Coordinate of view area
  279 + /// @param vw Width of the view area
  280 + /// @param vh Height of the view area
  281 + /// @return Returns the annotation, so other settings can be changed.
  282 + @deprecated
  283 + PdfAnnot addLink(double x, y, w, h, PdfObject dest,
  284 + [double vx = PDFAnnot.FULL_PAGE,
  285 + vy = PDFAnnot.FULL_PAGE,
  286 + vw = PDFAnnot.FULL_PAGE,
  287 + vh = PDFAnnot.FULL_PAGE]) {
  288 + var xy1 = cxy(x, y + h);
  289 + var xy2 = cxy(x + w, y);
  290 + var xy3 = cxy(vx, vy + vh);
  291 + var xy4 = cxy(vx + vw, vy);
  292 + PdfAnnot ob = new PdfAnnot.link(
  293 + this,
  294 + PdfRect.fromLTRB(xy1.x, xy1.y, xy2.x, xy2.y),
  295 + dest,
  296 + PdfRect.fromLTRB(xy3.x, xy3.y, xy4.x, xy4.y));
  297 + return ob;
  298 + }
  299 +
  300 + /// This method attaches an outline to the current page being generated. When
  301 + /// selected, the outline displays the top of the page.
  302 + /// @param title Outline title to attach
  303 + /// @param x Left coordinate of region
  304 + /// @param y Bottom coordinate of region
  305 + /// @param w Width of region
  306 + /// @param h Height coordinate of region
  307 + /// @return [PdfOutline] object created, for addSubOutline if required.
  308 + @deprecated
  309 + PdfOutline addOutline(String title,
  310 + {double x, double y, double w, double h}) {
  311 + PdfPoint xy1 = cxy(x, y + h);
  312 + PdfPoint xy2 = cxy(x + w, y);
  313 + PdfOutline outline = new PdfOutline(pdfDocument,
  314 + title: title,
  315 + dest: this,
  316 + rect: PdfRect.fromLTRB(xy1.x, xy2.y, xy2.x, xy1.y));
  317 + pdfDocument.outline.outlines.add(outline);
  318 + return outline;
  319 + }
  320 +
  321 + /// This utility method converts the y coordinate to User space
  322 + /// within the page.
  323 + /// @param x Coordinate in User space
  324 + /// @param y Coordinate in User space
  325 + /// @return y Coordinate in User space
  326 + @deprecated
  327 + double cy(double x, double y) => cxy(x, y).y;
  328 +
  329 + /// This utility method converts the x coordinate to User space
  330 + /// within the page.
  331 + /// @param x Coordinate in User space
  332 + /// @param y Coordinate in User space
  333 + /// @return x Coordinate in User space
  334 + @deprecated
  335 + double cx(double x, double y) => cxy(x, y).x;
  336 +
  337 + /// This utility method converts the coordinates to User space
  338 + /// within the page.
  339 + /// @param x Coordinate in User space
  340 + /// @param y Coordinate in User space
  341 + /// @return array containing the x & y Coordinate in User space
  342 + @deprecated
  343 + PdfPoint cxy(double x, double y) => new PdfPoint(x, pageFormat.height - y);
  344 +}
  345 +
  346 +@deprecated
  347 +class PDFPoint extends PdfPoint {
  348 + @deprecated
  349 + double get w => x;
  350 +
  351 + @deprecated
  352 + double get h => y;
  353 +
  354 + PDFPoint(double w, double h) : super(w, h);
  355 +}
  356 +
  357 +@deprecated
  358 +class PDFRect extends PdfRect {
  359 + const PDFRect(double x, double y, double w, double h) : super(x, y, w, h);
  360 +}
  361 +
  362 +@deprecated
  363 +class PDFStream extends PdfStream {}
  364 +
  365 +@deprecated
  366 +class TTFParser extends TtfParser {
  367 + TTFParser(ByteData bytes) : super(bytes);
  368 +}
  369 +
  370 +@deprecated
  371 +class PDFTTFFont extends PdfTtfFont {
  372 + PDFTTFFont(PdfDocument pdfDocument, ByteData bytes)
  373 + : super(pdfDocument, bytes);
  374 +}
  375 +
  376 +@deprecated
  377 +class PDFXObject extends PdfXObject {
  378 + PDFXObject(PdfDocument pdfDocument, String subtype)
  379 + : super(pdfDocument, subtype);
  380 +}
  381 +
  382 +@deprecated
  383 +enum PDFPageMode { NONE, OUTLINES, THUMBS, FULLSCREEN }
  384 +
  385 +@deprecated
  386 +enum PDFLineCap { JOIN_MITER, JOIN_ROUND, JOIN_BEVEL }
  387 +
  388 +@deprecated
  389 +class PDFXref extends PdfXref {
  390 + PDFXref(int id, int offset) : super(id, offset);
  391 +}
@@ -18,65 +18,63 @@ @@ -18,65 +18,63 @@
18 18
19 part of pdf; 19 part of pdf;
20 20
21 -enum PDFPageMode { 21 +enum PdfPageMode {
22 /// This page mode indicates that the document 22 /// This page mode indicates that the document
23 /// should be opened just with the page visible. This is the default 23 /// should be opened just with the page visible. This is the default
24 - NONE, 24 + none,
25 25
26 /// This page mode indicates that the Outlines 26 /// This page mode indicates that the Outlines
27 /// should also be displayed when the document is opened. 27 /// should also be displayed when the document is opened.
28 - OUTLINES, 28 + outlines,
29 29
30 /// This page mode indicates that the Thumbnails should be visible when the 30 /// This page mode indicates that the Thumbnails should be visible when the
31 /// document first opens. 31 /// document first opens.
32 - THUMBS, 32 + thumbs,
33 33
34 /// This page mode indicates that when the document is opened, it is displayed 34 /// This page mode indicates that when the document is opened, it is displayed
35 /// in full-screen-mode. There is no menu bar, window controls nor any other 35 /// in full-screen-mode. There is no menu bar, window controls nor any other
36 /// window present. 36 /// window present.
37 - FULLSCREEN 37 + fullscreen
38 } 38 }
39 39
40 typedef List<int> DeflateCallback(List<int> data); 40 typedef List<int> DeflateCallback(List<int> data);
41 41
42 -/// <p>This class is the base of the PDF generator. A PDFDocument class is 42 +/// This class is the base of the Pdf generator. A [PdfDocument] class is
43 /// created for a document, and each page, object, annotation, 43 /// created for a document, and each page, object, annotation,
44 /// etc is added to the document. 44 /// etc is added to the document.
45 -/// Once complete, the document can be written to a Stream, and the PDF 45 +/// Once complete, the document can be written to a Stream, and the Pdf
46 /// document's internal structures are kept in sync. 46 /// document's internal structures are kept in sync.
47 -class PDFDocument { 47 +class PdfDocument {
48 /// This is used to allocate objects a unique serial number in the document. 48 /// This is used to allocate objects a unique serial number in the document.
49 int _objser; 49 int _objser;
50 50
51 /// This vector contains each indirect object within the document. 51 /// This vector contains each indirect object within the document.
52 - final Set<PDFObject> objects = new Set<PDFObject>(); 52 + final Set<PdfObject> objects = new Set<PdfObject>();
53 53
54 - /// This is the Catalog object, which is required by each PDF Document  
55 - PDFCatalog catalog; 54 + /// This is the Catalog object, which is required by each Pdf Document
  55 + PdfCatalog catalog;
56 56
57 /// This is the info object. Although this is an optional object, we 57 /// This is the info object. Although this is an optional object, we
58 /// include it. 58 /// include it.
59 - PDFInfo info; 59 + PdfInfo info;
60 60
61 - /// This is the Pages object, which is required by each PDF Document  
62 - PDFPageList pdfPageList; 61 + /// This is the Pages object, which is required by each Pdf Document
  62 + PdfPageList pdfPageList;
63 63
64 /// This is the Outline object, which is optional 64 /// This is the Outline object, which is optional
65 - PDFOutline _outline; 65 + PdfOutline _outline;
66 66
67 - /// This holds a PDFObject describing the default border for annotations. 67 + /// This holds a [PdfObject] describing the default border for annotations.
68 /// It's only used when the document is being written. 68 /// It's only used when the document is being written.
69 - PDFObject defaultOutlineBorder; 69 + PdfObject defaultOutlineBorder;
70 70
71 /// Callback to compress the stream in the pdf file. 71 /// Callback to compress the stream in the pdf file.
72 /// Use `deflate: zlib.encode` if using dart:io 72 /// Use `deflate: zlib.encode` if using dart:io
73 /// No compression by default 73 /// No compression by default
74 final DeflateCallback deflate; 74 final DeflateCallback deflate;
75 75
76 - /// <p>  
77 - /// These map the page modes just defined to the pagemodes setting of PDF.  
78 - /// </p>  
79 - static const _PDF_PAGE_MODES = const [ 76 + /// These map the page modes just defined to the pagemodes setting of Pdf.
  77 + static const _PdfPageModes = const [
80 "/UseNone", 78 "/UseNone",
81 "/UseOutlines", 79 "/UseOutlines",
82 "/UseThumbs", 80 "/UseThumbs",
@@ -84,38 +82,38 @@ class PDFDocument { @@ -84,38 +82,38 @@ class PDFDocument {
84 ]; 82 ];
85 83
86 /// This holds the current fonts 84 /// This holds the current fonts
87 - final Set<PDFFont> fonts = new Set<PDFFont>(); 85 + final Set<PdfFont> fonts = new Set<PdfFont>();
88 86
89 /// Creates a new serial number 87 /// Creates a new serial number
90 int _genSerial() => _objser++; 88 int _genSerial() => _objser++;
91 89
92 - /// <p>This creates a PDF document</p> 90 + /// This creates a Pdf document
93 /// @param pagemode an int, determines how the document will present itself to 91 /// @param pagemode an int, determines how the document will present itself to
94 /// the viewer when it first opens. 92 /// the viewer when it first opens.
95 - PDFDocument({PDFPageMode pageMode = PDFPageMode.NONE, this.deflate}) { 93 + PdfDocument({PdfPageMode pageMode = PdfPageMode.none, this.deflate}) {
96 _objser = 1; 94 _objser = 1;
97 95
98 // Now create some standard objects 96 // Now create some standard objects
99 - pdfPageList = new PDFPageList(this);  
100 - catalog = new PDFCatalog(this, pdfPageList, pageMode);  
101 - info = new PDFInfo(this); 97 + pdfPageList = new PdfPageList(this);
  98 + catalog = new PdfCatalog(this, pdfPageList, pageMode);
  99 + info = new PdfInfo(this);
102 } 100 }
103 101
104 - /// <p>This returns a specific page. It's used mainly when using a  
105 - /// Serialized template file.</p> 102 + /// This returns a specific page. It's used mainly when using a
  103 + /// Serialized template file.
106 /// 104 ///
107 /// ?? How does a serialized template file work ??? 105 /// ?? How does a serialized template file work ???
108 /// 106 ///
109 /// @param page page number to return 107 /// @param page page number to return
110 - /// @return PDFPage at that position  
111 - PDFPage page(int page) { 108 + /// @return [PdfPage] at that position
  109 + PdfPage page(int page) {
112 return pdfPageList.getPage(page); 110 return pdfPageList.getPage(page);
113 } 111 }
114 112
115 /// @return the root outline 113 /// @return the root outline
116 - PDFOutline get outline { 114 + PdfOutline get outline {
117 if (_outline == null) { 115 if (_outline == null) {
118 - _outline = new PDFOutline(this); 116 + _outline = new PdfOutline(this);
119 catalog.outlines = _outline; 117 catalog.outlines = _outline;
120 } 118 }
121 return _outline; 119 return _outline;
@@ -123,21 +121,21 @@ class PDFDocument { @@ -123,21 +121,21 @@ class PDFDocument {
123 121
124 /// This writes the document to an OutputStream. 122 /// This writes the document to an OutputStream.
125 /// 123 ///
126 - /// <p><b>Note:</b> You can call this as many times as you wish, as long as 124 + /// Note: You can call this as many times as you wish, as long as
127 /// the calls are not running at the same time. 125 /// the calls are not running at the same time.
128 /// 126 ///
129 - /// <p>Also, objects can be added or amended between these calls. 127 + /// Also, objects can be added or amended between these calls.
130 /// 128 ///
131 - /// <p>Also, the OutputStream is not closed, but will be flushed on 129 + /// Also, the OutputStream is not closed, but will be flushed on
132 /// completion. It is up to the caller to close the stream. 130 /// completion. It is up to the caller to close the stream.
133 /// 131 ///
134 /// @param os OutputStream to write the document to 132 /// @param os OutputStream to write the document to
135 - void write(PDFStream os) {  
136 - PDFOutput pos = new PDFOutput(os); 133 + void write(PdfStream os) {
  134 + PdfOutput pos = new PdfOutput(os);
137 135
138 - // Write each object to the PDFStream. We call via the output 136 + // Write each object to the [PdfStream]. We call via the output
139 // as that builds the xref table 137 // as that builds the xref table
140 - for (PDFObject o in objects) { 138 + for (PdfObject o in objects) {
141 pos.write(o); 139 pos.write(o);
142 } 140 }
143 141
@@ -146,7 +144,7 @@ class PDFDocument { @@ -146,7 +144,7 @@ class PDFDocument {
146 } 144 }
147 145
148 List<int> save() { 146 List<int> save() {
149 - PDFStream os = new PDFStream(); 147 + PdfStream os = new PdfStream();
150 write(os); 148 write(os);
151 return os.output(); 149 return os.output();
152 } 150 }
@@ -18,21 +18,20 @@ @@ -18,21 +18,20 @@
18 18
19 part of pdf; 19 part of pdf;
20 20
21 -class PDFFont extends PDFObject {  
22 - /// The PDF type of the font, usually /Type1 21 +class PdfFont extends PdfObject {
  22 + /// Thedf type of the font, usually /Type1
23 final String subtype; 23 final String subtype;
24 24
25 /// The font's real name 25 /// The font's real name
26 String baseFont; 26 String baseFont;
27 27
28 - /// Constructs a PDFFont. This will attempt to map the font from a known  
29 - /// Java font name to that in PDF, defaulting to Helvetica if not possible. 28 + /// Constructs a [PdfFont]. This will attempt to map the font from a known
  29 + /// font name to that in Pdf, defaulting to Helvetica if not possible.
30 /// 30 ///
31 /// @param name The document name, ie /F1 31 /// @param name The document name, ie /F1
32 - /// @param type The pdf type, ie /Type1  
33 - /// @param font The font name, ie Helvetica  
34 - /// @param style The java.awt.Font style, ie: Font.PLAIN  
35 - PDFFont(PDFDocument pdfDocument, 32 + /// @param subtype The pdf type, ie /Type1
  33 + /// @param baseFont The font name, ie /Helvetica
  34 + PdfFont(PdfDocument pdfDocument,
36 {this.subtype = "/Type1", this.baseFont = "/Helvetica"}) 35 {this.subtype = "/Type1", this.baseFont = "/Helvetica"})
37 : super(pdfDocument, "/Font") { 36 : super(pdfDocument, "/Font") {
38 pdfDocument.fonts.add(this); 37 pdfDocument.fonts.add(this);
@@ -45,24 +44,24 @@ class PDFFont extends PDFObject { @@ -45,24 +44,24 @@ class PDFFont extends PDFObject {
45 void prepare() { 44 void prepare() {
46 super.prepare(); 45 super.prepare();
47 46
48 - params["/Subtype"] = PDFStream.string(subtype);  
49 - params["/Name"] = PDFStream.string(name);  
50 - params["/BaseFont"] = PDFStream.string(baseFont);  
51 - params["/Encoding"] = PDFStream.string("/WinAnsiEncoding"); 47 + params["/Subtype"] = PdfStream.string(subtype);
  48 + params["/Name"] = PdfStream.string(name);
  49 + params["/BaseFont"] = PdfStream.string(baseFont);
  50 + params["/Encoding"] = PdfStream.string("/WinAnsiEncoding");
52 } 51 }
53 52
54 double glyphAdvance(int charCode) { 53 double glyphAdvance(int charCode) {
55 return 0.454; 54 return 0.454;
56 } 55 }
57 56
58 - PDFRect glyphBounds(int charCode) {  
59 - return const PDFRect(0.0, 0.0, 0.4, 1.0); 57 + PdfRect glyphBounds(int charCode) {
  58 + return const PdfRect(0.0, 0.0, 0.4, 1.0);
60 } 59 }
61 60
62 - PDFRect stringBounds(String s) { 61 + PdfRect stringBounds(String s) {
63 var chars = latin1.encode(s); 62 var chars = latin1.encode(s);
64 63
65 - if (chars.length == 0) return const PDFRect(0.0, 0.0, 0.0, 0.0); 64 + if (chars.length == 0) return const PdfRect(0.0, 0.0, 0.0, 0.0);
66 65
67 var n = 0; 66 var n = 0;
68 var c = chars[n]; 67 var c = chars[n];
@@ -80,10 +79,10 @@ class PDFFont extends PDFObject { @@ -80,10 +79,10 @@ class PDFFont extends PDFObject {
80 w += n == chars.length - 1 ? r.w : glyphAdvance(c); 79 w += n == chars.length - 1 ? r.w : glyphAdvance(c);
81 } 80 }
82 81
83 - return new PDFRect(x, y, w, h); 82 + return new PdfRect(x, y, w, h);
84 } 83 }
85 84
86 - PDFPoint stringSize(String s) { 85 + PdfPoint stringSize(String s) {
87 var chars = latin1.encode(s); 86 var chars = latin1.encode(s);
88 87
89 var w = 0.0; 88 var w = 0.0;
@@ -95,6 +94,6 @@ class PDFFont extends PDFObject { @@ -95,6 +94,6 @@ class PDFFont extends PDFObject {
95 w += glyphAdvance(c); 94 w += glyphAdvance(c);
96 } 95 }
97 96
98 - return new PDFPoint(w, h); 97 + return new PdfPoint(w, h);
99 } 98 }
100 } 99 }
@@ -18,31 +18,31 @@ @@ -18,31 +18,31 @@
18 18
19 part of pdf; 19 part of pdf;
20 20
21 -class PDFFontDescriptor extends PDFObject {  
22 - final PDFObjectStream file;  
23 - final PDFTTFFont ttfFont; 21 +class PdfFontDescriptor extends PdfObject {
  22 + final PdfObjectStream file;
  23 + final PdfTtfFont ttfFont;
24 24
25 - PDFFontDescriptor(this.ttfFont, this.file) 25 + PdfFontDescriptor(this.ttfFont, this.file)
26 : super(ttfFont.pdfDocument, "/FontDescriptor"); 26 : super(ttfFont.pdfDocument, "/FontDescriptor");
27 27
28 @override 28 @override
29 void prepare() { 29 void prepare() {
30 super.prepare(); 30 super.prepare();
31 31
32 - params["/FontName"] = PDFStream.string(ttfFont.baseFont); 32 + params["/FontName"] = PdfStream.string(ttfFont.baseFont);
33 params["/FontFile2"] = file.ref(); 33 params["/FontFile2"] = file.ref();
34 - params["/Flags"] = PDFStream.intNum(32);  
35 - params["/FontBBox"] = new PDFStream() 34 + params["/Flags"] = PdfStream.intNum(32);
  35 + params["/FontBBox"] = new PdfStream()
36 ..putStringArray([ 36 ..putStringArray([
37 ttfFont.font.xMin, 37 ttfFont.font.xMin,
38 ttfFont.font.yMin, 38 ttfFont.font.yMin,
39 ttfFont.font.xMax, 39 ttfFont.font.xMax,
40 ttfFont.font.yMax 40 ttfFont.font.yMax
41 ]); 41 ]);
42 - params["/Ascent"] = PDFStream.intNum(ttfFont.font.ascent);  
43 - params["/Descent"] = PDFStream.intNum(ttfFont.font.descent);  
44 - params["/ItalicAngle"] = PDFStream.intNum(0);  
45 - params["/CapHeight"] = PDFStream.intNum(10);  
46 - params["/StemV"] = PDFStream.intNum(79); 42 + params["/Ascent"] = PdfStream.intNum(ttfFont.font.ascent);
  43 + params["/Descent"] = PdfStream.intNum(ttfFont.font.descent);
  44 + params["/ItalicAngle"] = PdfStream.intNum(0);
  45 + params["/CapHeight"] = PdfStream.intNum(10);
  46 + params["/StemV"] = PdfStream.intNum(79);
47 } 47 }
48 } 48 }
@@ -18,23 +18,23 @@ @@ -18,23 +18,23 @@
18 18
19 part of pdf; 19 part of pdf;
20 20
21 -class PDFFormXObject extends PDFXObject { 21 +class PdfFormXObject extends PdfXObject {
22 /// The fonts associated with this page 22 /// The fonts associated with this page
23 - final fonts = new Map<String, PDFFont>(); 23 + final fonts = new Map<String, PdfFont>();
24 24
25 /// The xobjects or other images in the pdf 25 /// The xobjects or other images in the pdf
26 - final xobjects = new Map<String, PDFXObject>(); 26 + final xobjects = new Map<String, PdfXObject>();
27 27
28 - PDFFormXObject(PDFDocument pdfDocument) : super(pdfDocument, '/Form') {  
29 - params["/FormType"] = PDFStream.string("1");  
30 - params["/BBox"] = PDFStream.string("[0 0 1000 1000]"); 28 + PdfFormXObject(PdfDocument pdfDocument) : super(pdfDocument, '/Form') {
  29 + params["/FormType"] = PdfStream.string("1");
  30 + params["/BBox"] = PdfStream.string("[0 0 1000 1000]");
31 } 31 }
32 32
33 /// set matrix 33 /// set matrix
34 void setMatrix(Matrix4 t) { 34 void setMatrix(Matrix4 t) {
35 var s = t.storage; 35 var s = t.storage;
36 params["/Matrix"] = 36 params["/Matrix"] =
37 - PDFStream.string("[${s[0]} ${s[1]} ${s[4]} ${s[5]} ${s[12]} ${s[13]}]"); 37 + PdfStream.string("[${s[0]} ${s[1]} ${s[4]} ${s[5]} ${s[12]} ${s[13]}]");
38 } 38 }
39 39
40 @override 40 @override
@@ -43,20 +43,20 @@ class PDFFormXObject extends PDFXObject { @@ -43,20 +43,20 @@ class PDFFormXObject extends PDFXObject {
43 43
44 // Now the resources 44 // Now the resources
45 /// This holds any resources for this FormXObject 45 /// This holds any resources for this FormXObject
46 - final resources = new Map<String, PDFStream>(); 46 + final resources = new Map<String, PdfStream>();
47 47
48 // fonts 48 // fonts
49 if (fonts.length > 0) { 49 if (fonts.length > 0) {
50 - resources["/Font"] = new PDFStream()..putObjectDictionary(fonts); 50 + resources["/Font"] = new PdfStream()..putObjectDictionary(fonts);
51 } 51 }
52 52
53 // Now the XObjects 53 // Now the XObjects
54 if (xobjects.length > 0) { 54 if (xobjects.length > 0) {
55 - resources["/XObject"] = new PDFStream()..putObjectDictionary(xobjects); 55 + resources["/XObject"] = new PdfStream()..putObjectDictionary(xobjects);
56 } 56 }
57 57
58 if (resources.length > 0) { 58 if (resources.length > 0) {
59 - params["/Resources"] = PDFStream.dictionary(resources); 59 + params["/Resources"] = PdfStream.dictionary(resources);
60 } 60 }
61 } 61 }
62 } 62 }
@@ -18,21 +18,21 @@ @@ -18,21 +18,21 @@
18 18
19 part of pdf; 19 part of pdf;
20 20
21 -enum PDFLineCap { JOIN_MITER, JOIN_ROUND, JOIN_BEVEL } 21 +enum PdfLineCap { joinMiter, joinRound, joinBevel }
22 22
23 -class PDFGraphics { 23 +class PdfGraphics {
24 /// Graphic context number 24 /// Graphic context number
25 var _context = 0; 25 var _context = 0;
26 26
27 - final PDFPage page; 27 + final PdfPage page;
28 28
29 - final PDFStream buf; 29 + final PdfStream buf;
30 30
31 - PDFGraphics(this.page, this.buf); 31 + PdfGraphics(this.page, this.buf);
32 32
33 - PDFFont get defaultFont { 33 + PdfFont get defaultFont {
34 if (page.pdfDocument.fonts.length == 0) { 34 if (page.pdfDocument.fonts.length == 0) {
35 - new PDFFont(page.pdfDocument); 35 + new PdfFont(page.pdfDocument);
36 } 36 }
37 37
38 return page.pdfDocument.fonts.elementAt(0); 38 return page.pdfDocument.fonts.elementAt(0);
@@ -54,16 +54,11 @@ class PDFGraphics { @@ -54,16 +54,11 @@ class PDFGraphics {
54 buf.putString("W n\n"); 54 buf.putString("W n\n");
55 } 55 }
56 56
57 - /// <p>This releases any resources used by this Graphics object. You must use  
58 - /// this method once finished with it. Leaving it open will leave the PDF  
59 - /// stream in an inconsistent state, and will produce errors.</p>  
60 - /// <p>  
61 - /// <p>If this was created with Graphics.create() then the parent instance  
62 - /// can be used again. If not, then this closes the graphics operations for  
63 - /// this page when used with PDFJob.</p>  
64 - /// <p>  
65 - /// <p>When using PDFPage, you can create another fresh Graphics instance,  
66 - /// which will draw over this one.</p> 57 + /// This releases any resources used by this Graphics object. You must use
  58 + /// this method once finished with it.
  59 + ///
  60 + /// When using [PdfPage], you can create another fresh Graphics instance,
  61 + /// which will draw over this one.
67 void restoreContext() { 62 void restoreContext() {
68 if (_context > 0) { 63 if (_context > 0) {
69 // restore graphics context 64 // restore graphics context
@@ -78,21 +73,21 @@ class PDFGraphics { @@ -78,21 +73,21 @@ class PDFGraphics {
78 _context++; 73 _context++;
79 } 74 }
80 75
81 - /// <p>Draws an image onto the page.</p>  
82 - /// <p>  
83 - /// <p>This method is implemented with ASCIIbase85 encoding and the 76 + /// Draws an image onto the page.
  77 + ///
  78 + /// This method is implemented with [Ascii85Encoder] encoding and the
84 /// zip stream deflater. It results in a stream that is anywhere 79 /// zip stream deflater. It results in a stream that is anywhere
85 /// from 3 to 10 times as big as the image. This obviously needs some 80 /// from 3 to 10 times as big as the image. This obviously needs some
86 - /// improvement, but it works well for small images</p> 81 + /// improvement, but it works well for small images
87 /// 82 ///
88 - /// @param img The java.awt.Image 83 + /// @param img The Image
89 /// @param x coordinate on page 84 /// @param x coordinate on page
90 /// @param y coordinate on page 85 /// @param y coordinate on page
91 /// @param w Width on page 86 /// @param w Width on page
92 /// @param h height on page 87 /// @param h height on page
93 /// @param bgcolor Background colour 88 /// @param bgcolor Background colour
94 /// @return true if drawn 89 /// @return true if drawn
95 - void drawImage(PDFImage img, double x, double y, [double w, double h]) { 90 + void drawImage(PdfImage img, double x, double y, [double w, double h]) {
96 if (w == null) w = img.width.toDouble(); 91 if (w == null) w = img.width.toDouble();
97 if (h == null) h = img.height.toDouble() * w / img.width.toDouble(); 92 if (h == null) h = img.height.toDouble() * w / img.width.toDouble();
98 93
@@ -104,7 +99,7 @@ class PDFGraphics { @@ -104,7 +99,7 @@ class PDFGraphics {
104 } 99 }
105 100
106 /// Draws a line between two coordinates. 101 /// Draws a line between two coordinates.
107 - /// <p> 102 + ///
108 /// If the first coordinate is the same as the last one drawn 103 /// If the first coordinate is the same as the last one drawn
109 /// (i.e. a previous drawLine, moveto, etc) it is ignored. 104 /// (i.e. a previous drawLine, moveto, etc) it is ignored.
110 /// 105 ///
@@ -122,7 +117,7 @@ class PDFGraphics { @@ -122,7 +117,7 @@ class PDFGraphics {
122 /// @param xp Array of x coordinates 117 /// @param xp Array of x coordinates
123 /// @param yp Array of y coordinates 118 /// @param yp Array of y coordinates
124 /// @param np number of points in polygon 119 /// @param np number of points in polygon
125 - void drawPolygon(Polygon p) { 120 + void drawPolygon(PdfPolygon p) {
126 _polygon(p.points); 121 _polygon(p.points);
127 } 122 }
128 123
@@ -144,7 +139,7 @@ class PDFGraphics { @@ -144,7 +139,7 @@ class PDFGraphics {
144 } 139 }
145 140
146 /// We override Graphics.drawRect as it doesn't join the 4 lines. 141 /// We override Graphics.drawRect as it doesn't join the 4 lines.
147 - /// Also, PDF provides us with a Rectangle operator, so we will use that. 142 + /// Also, Pdf provides us with a Rectangle operator, so we will use that.
148 /// 143 ///
149 /// @param x coordinate 144 /// @param x coordinate
150 /// @param y coordinate 145 /// @param y coordinate
@@ -164,7 +159,7 @@ class PDFGraphics { @@ -164,7 +159,7 @@ class PDFGraphics {
164 /// @param x coordinate 159 /// @param x coordinate
165 /// @param y coordinate 160 /// @param y coordinate
166 /// @oaran s String to draw 161 /// @oaran s String to draw
167 - void drawString(PDFFont font, size, String s, double x, double y) { 162 + void drawString(PdfFont font, size, String s, double x, double y) {
168 if (!page.fonts.containsKey(font.name)) { 163 if (!page.fonts.containsKey(font.name)) {
169 page.fonts[font.name] = font; 164 page.fonts[font.name] = font;
170 } 165 }
@@ -177,7 +172,7 @@ class PDFGraphics { @@ -177,7 +172,7 @@ class PDFGraphics {
177 /// Sets the color for drawing 172 /// Sets the color for drawing
178 /// 173 ///
179 /// @param c Color to use 174 /// @param c Color to use
180 - void setColor(PDFColor color) { 175 + void setColor(PdfColor color) {
181 buf.putString( 176 buf.putString(
182 "${color.r} ${color.g} ${color.b} rg ${color.r} ${color.g} ${color.b} RG\n"); 177 "${color.r} ${color.g} ${color.b} rg ${color.r} ${color.g} ${color.b} RG\n");
183 } 178 }
@@ -234,18 +229,18 @@ class PDFGraphics { @@ -234,18 +229,18 @@ class PDFGraphics {
234 /// @see #drawPolygon 229 /// @see #drawPolygon
235 /// @see #drawPolyline 230 /// @see #drawPolyline
236 /// @see #fillPolygon 231 /// @see #fillPolygon
237 - void _polygon(List<PDFPoint> p) { 232 + void _polygon(List<PdfPoint> p) {
238 // newPath() not needed here as moveto does it ;-) 233 // newPath() not needed here as moveto does it ;-)
239 - moveTo(p[0].w, p[0].h); 234 + moveTo(p[0].x, p[0].y);
240 235
241 - for (int i = 1; i < p.length; i++) lineTo(p[i].w, p[i].h); 236 + for (int i = 1; i < p.length; i++) lineTo(p[i].x, p[i].y);
242 } 237 }
243 238
244 - void setLineCap(PDFLineCap cap) { 239 + void setLineCap(PdfLineCap cap) {
245 buf.putString("${cap.index} J\n"); 240 buf.putString("${cap.index} J\n");
246 } 241 }
247 242
248 - void setLineJoin(PDFLineCap join) { 243 + void setLineJoin(PdfLineCap join) {
249 buf.putString("${join.index} j\n"); 244 buf.putString("${join.index} j\n");
250 } 245 }
251 246
@@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
18 18
19 part of pdf; 19 part of pdf;
20 20
21 -class PDFImage extends PDFXObject { 21 +class PdfImage extends PdfXObject {
22 /// RGBA Image Data 22 /// RGBA Image Data
23 final Uint8List image; 23 final Uint8List image;
24 24
@@ -36,15 +36,14 @@ class PDFImage extends PDFXObject { @@ -36,15 +36,14 @@ class PDFImage extends PDFXObject {
36 /// Process alphaChannel only 36 /// Process alphaChannel only
37 final bool alphaChannel; 37 final bool alphaChannel;
38 38
39 - /// Creates a new <code>PDFImage</code> instance. 39 + /// Creates a new [PdfImage] instance.
40 /// 40 ///
41 - /// @param img an <code>Image</code> value  
42 - /// @param x an <code>int</code> value  
43 - /// @param y an <code>int</code> value  
44 - /// @param w an <code>int</code> value  
45 - /// @param h an <code>int</code> value  
46 - /// @param obs an <code>ImageObserver</code> value  
47 - PDFImage(PDFDocument pdfDocument, 41 + /// @param imgage an [Uint8List] value
  42 + /// @param width
  43 + /// @param height
  44 + /// @param alpha if the image is transparent
  45 + /// @param alphaChannel if this is transparency mask
  46 + PdfImage(PdfDocument pdfDocument,
48 {@required this.image, 47 {@required this.image,
49 @required this.width, 48 @required this.width,
50 @required this.height, 49 @required this.height,
@@ -55,25 +54,25 @@ class PDFImage extends PDFXObject { @@ -55,25 +54,25 @@ class PDFImage extends PDFXObject {
55 assert(height != null), 54 assert(height != null),
56 super(pdfDocument, "/Image", isBinary: true) { 55 super(pdfDocument, "/Image", isBinary: true) {
57 _name = "/Image$objser"; 56 _name = "/Image$objser";
58 - params["/Width"] = PDFStream.string(width.toString());  
59 - params["/Height"] = PDFStream.string(height.toString());  
60 - params["/BitsPerComponent"] = PDFStream.intNum(8);  
61 - params['/Name'] = PDFStream.string(_name); 57 + params["/Width"] = PdfStream.string(width.toString());
  58 + params["/Height"] = PdfStream.string(height.toString());
  59 + params["/BitsPerComponent"] = PdfStream.intNum(8);
  60 + params['/Name'] = PdfStream.string(_name);
62 61
63 if (alphaChannel == false && alpha) { 62 if (alphaChannel == false && alpha) {
64 - var _sMask = new PDFImage(pdfDocument, 63 + var _sMask = new PdfImage(pdfDocument,
65 image: image, 64 image: image,
66 width: width, 65 width: width,
67 height: height, 66 height: height,
68 alpha: alpha, 67 alpha: alpha,
69 alphaChannel: true); 68 alphaChannel: true);
70 - params["/SMask"] = PDFStream.string("${_sMask.objser} 0 R"); 69 + params["/SMask"] = PdfStream.string("${_sMask.objser} 0 R");
71 } 70 }
72 71
73 if (alphaChannel) { 72 if (alphaChannel) {
74 - params["/ColorSpace"] = PDFStream.string("/DeviceGray"); 73 + params["/ColorSpace"] = PdfStream.string("/DeviceGray");
75 } else { 74 } else {
76 - params["/ColorSpace"] = PDFStream.string("/DeviceRGB"); 75 + params["/ColorSpace"] = PdfStream.string("/DeviceRGB");
77 } 76 }
78 } 77 }
79 78
@@ -107,6 +106,6 @@ class PDFImage extends PDFXObject { @@ -107,6 +106,6 @@ class PDFImage extends PDFXObject {
107 106
108 /// Get the name 107 /// Get the name
109 /// 108 ///
110 - /// @return a <code>String</code> value 109 + /// @return a String value
111 String get name => _name; 110 String get name => _name;
112 } 111 }
@@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
18 18
19 part of pdf; 19 part of pdf;
20 20
21 -class PDFInfo extends PDFObject { 21 +class PdfInfo extends PdfObject {
22 String author; 22 String author;
23 String creator; 23 String creator;
24 String title; 24 String title;
@@ -26,10 +26,10 @@ class PDFInfo extends PDFObject { @@ -26,10 +26,10 @@ class PDFInfo extends PDFObject {
26 String keywords; 26 String keywords;
27 27
28 /// @param title Title of this document 28 /// @param title Title of this document
29 - PDFInfo(PDFDocument pdfDocument, 29 + PdfInfo(PdfDocument pdfDocument,
30 {this.title, this.author, this.creator, this.subject, this.keywords}) 30 {this.title, this.author, this.creator, this.subject, this.keywords})
31 : super(pdfDocument, null) { 31 : super(pdfDocument, null) {
32 - params["/Producer"] = PDFStream.text("dpdf - David PHAM-VAN"); 32 + params["/Producer"] = PdfStream.text("dpdf - David PHAM-VAN");
33 } 33 }
34 34
35 /// @param os OutputStream to send the object to 35 /// @param os OutputStream to send the object to
@@ -37,10 +37,10 @@ class PDFInfo extends PDFObject { @@ -37,10 +37,10 @@ class PDFInfo extends PDFObject {
37 void prepare() { 37 void prepare() {
38 super.prepare(); 38 super.prepare();
39 39
40 - if (author != null) params["/Author"] = PDFStream.text(author);  
41 - if (creator != null) params["/Creator"] = PDFStream.text(creator);  
42 - if (title != null) params["/Title"] = PDFStream.text(title);  
43 - if (subject != null) params["/Subject"] = PDFStream.text(subject);  
44 - if (keywords != null) params["/Keywords"] = PDFStream.text(keywords); 40 + if (author != null) params["/Author"] = PdfStream.text(author);
  41 + if (creator != null) params["/Creator"] = PdfStream.text(creator);
  42 + if (title != null) params["/Title"] = PdfStream.text(title);
  43 + if (subject != null) params["/Subject"] = PdfStream.text(subject);
  44 + if (keywords != null) params["/Keywords"] = PdfStream.text(keywords);
45 } 45 }
46 } 46 }
@@ -18,9 +18,9 @@ @@ -18,9 +18,9 @@
18 18
19 part of pdf; 19 part of pdf;
20 20
21 -class PDFObject { 21 +class PdfObject {
22 /// This is the object parameters. 22 /// This is the object parameters.
23 - final params = new Map<String, PDFStream>(); 23 + final params = new Map<String, PdfStream>();
24 24
25 /// This is the unique serial number for this object. 25 /// This is the unique serial number for this object.
26 final int objser; 26 final int objser;
@@ -28,29 +28,29 @@ class PDFObject { @@ -28,29 +28,29 @@ class PDFObject {
28 /// This is the generation number for this object. 28 /// This is the generation number for this object.
29 final int objgen = 0; 29 final int objgen = 0;
30 30
31 - /// This allows any PDF object to refer to the document being constructed.  
32 - final PDFDocument pdfDocument; 31 + /// This allows any Pdf object to refer to the document being constructed.
  32 + final PdfDocument pdfDocument;
33 33
34 /// This is usually called by extensors to this class, and sets the 34 /// This is usually called by extensors to this class, and sets the
35 - /// PDF Object Type  
36 - /// @param type the PDF Object Type  
37 - PDFObject(this.pdfDocument, [String type]) 35 + /// Pdf Object Type
  36 + /// @param type the Pdf Object Type
  37 + PdfObject(this.pdfDocument, [String type])
38 : objser = pdfDocument._genSerial() { 38 : objser = pdfDocument._genSerial() {
39 if (type != null) { 39 if (type != null) {
40 - params["/Type"] = PDFStream.string(type); 40 + params["/Type"] = PdfStream.string(type);
41 } 41 }
42 42
43 pdfDocument.objects.add(this); 43 pdfDocument.objects.add(this);
44 } 44 }
45 45
46 - /// <p>Writes the object to the output stream.  
47 - /// This method must be overidden.</p> 46 + /// Writes the object to the output stream.
  47 + /// This method must be overidden.
48 /// 48 ///
49 - /// <p><b>Note:</b> It should not write any other objects, even if they are  
50 - /// it's Kids, as they will be written by the calling routine.</p> 49 + /// Note: It should not write any other objects, even if they are
  50 + /// it's Kids, as they will be written by the calling routine.
51 /// 51 ///
52 /// @param os OutputStream to send the object to 52 /// @param os OutputStream to send the object to
53 - void write(PDFStream os) { 53 + void write(PdfStream os) {
54 prepare(); 54 prepare();
55 writeStart(os); 55 writeStart(os);
56 writeContent(os); 56 writeContent(os);
@@ -64,14 +64,14 @@ class PDFObject { @@ -64,14 +64,14 @@ class PDFObject {
64 /// The write method should call this before writing anything to the 64 /// The write method should call this before writing anything to the
65 /// OutputStream. This will send the standard header for each object. 65 /// OutputStream. This will send the standard header for each object.
66 /// 66 ///
67 - /// <p>Note: There are a few rare cases where this method is not called. 67 + /// Note: There are a few rare cases where this method is not called.
68 /// 68 ///
69 /// @param os OutputStream to write to 69 /// @param os OutputStream to write to
70 - void writeStart(PDFStream os) { 70 + void writeStart(PdfStream os) {
71 os.putString("$objser $objgen obj\n"); 71 os.putString("$objser $objgen obj\n");
72 } 72 }
73 73
74 - void writeContent(PDFStream os) { 74 + void writeContent(PdfStream os) {
75 if (params.length > 0) { 75 if (params.length > 0) {
76 os.putDictionary(params); 76 os.putDictionary(params);
77 os.putString("\n"); 77 os.putString("\n");
@@ -81,14 +81,14 @@ class PDFObject { @@ -81,14 +81,14 @@ class PDFObject {
81 /// The write method should call this after writing anything to the 81 /// The write method should call this after writing anything to the
82 /// OutputStream. This will send the standard footer for each object. 82 /// OutputStream. This will send the standard footer for each object.
83 /// 83 ///
84 - /// <p>Note: There are a few rare cases where this method is not called. 84 + /// Note: There are a few rare cases where this method is not called.
85 /// 85 ///
86 /// @param os OutputStream to write to 86 /// @param os OutputStream to write to
87 - void writeEnd(PDFStream os) { 87 + void writeEnd(PdfStream os) {
88 os.putString("endobj\n"); 88 os.putString("endobj\n");
89 } 89 }
90 90
91 - /// Returns the unique serial number in PDF format  
92 - /// @return the serial number in PDF format  
93 - PDFStream ref() => PDFStream.string("$objser $objgen R"); 91 + /// Returns the unique serial number in Pdf format
  92 + /// @return the serial number in Pdf format
  93 + PdfStream ref() => PdfStream.string("$objser $objgen R");
94 } 94 }
@@ -18,20 +18,21 @@ @@ -18,20 +18,21 @@
18 18
19 part of pdf; 19 part of pdf;
20 20
21 -class PDFObjectStream extends PDFObject { 21 +class PdfObjectStream extends PdfObject {
22 /// This holds the stream's content. 22 /// This holds the stream's content.
23 - final PDFStream buf = new PDFStream(); 23 + final PdfStream buf = new PdfStream();
24 24
25 /// defines if the stream needs to be converted to ascii85 25 /// defines if the stream needs to be converted to ascii85
26 final bool isBinary; 26 final bool isBinary;
27 27
28 /// Constructs a stream. The supplied type is stored in the stream's header 28 /// Constructs a stream. The supplied type is stored in the stream's header
29 - /// and is used by other objects that extend the PDFStream class (like  
30 - /// PDFImage).  
31 - /// <p>By default, the stream will be compressed. 29 + /// and is used by other objects that extend the [PdfStream] class (like
  30 + /// [PdfImage]).
  31 + /// By default, the stream will be compressed.
  32 + ///
32 /// @param type type for the stream 33 /// @param type type for the stream
33 - /// @see PDFImage  
34 - PDFObjectStream(PDFDocument pdfDocument, {String type, this.isBinary = false}) 34 + /// @see [PdfImage]
  35 + PdfObjectStream(PdfDocument pdfDocument, {String type, this.isBinary = false})
35 : super(pdfDocument, type); 36 : super(pdfDocument, type);
36 37
37 List<int> _data; 38 List<int> _data;
@@ -42,21 +43,21 @@ class PDFObjectStream extends PDFObject { @@ -42,21 +43,21 @@ class PDFObjectStream extends PDFObject {
42 43
43 if (pdfDocument.deflate != null) { 44 if (pdfDocument.deflate != null) {
44 _data = pdfDocument.deflate(buf.output()); 45 _data = pdfDocument.deflate(buf.output());
45 - params["/Filter"] = PDFStream.string("/FlateDecode"); 46 + params["/Filter"] = PdfStream.string("/FlateDecode");
46 } else if (isBinary) { 47 } else if (isBinary) {
47 // This is a Ascii85 stream 48 // This is a Ascii85 stream
48 var e = new Ascii85Encoder(); 49 var e = new Ascii85Encoder();
49 _data = e.convert(buf.output()); 50 _data = e.convert(buf.output());
50 - params["/Filter"] = PDFStream.string("/ASCII85Decode"); 51 + params["/Filter"] = PdfStream.string("/ASCII85Decode");
51 } else { 52 } else {
52 // This is a non-deflated stream 53 // This is a non-deflated stream
53 _data = buf.output(); 54 _data = buf.output();
54 } 55 }
55 - params["/Length"] = PDFStream.intNum(_data.length); 56 + params["/Length"] = PdfStream.intNum(_data.length);
56 } 57 }
57 58
58 @override 59 @override
59 - void writeContent(PDFStream os) { 60 + void writeContent(PdfStream os) {
60 super.writeContent(os); 61 super.writeContent(os);
61 62
62 os.putString("stream\n"); 63 os.putString("stream\n");
@@ -18,67 +18,63 @@ @@ -18,67 +18,63 @@
18 18
19 part of pdf; 19 part of pdf;
20 20
21 -class PDFOutline extends PDFObject { 21 +enum PdfOutlineMode {
  22 + /// When jumping to the destination, display the whole page
  23 + fitpage,
  24 +
  25 + /// When jumping to the destination, display the specified region
  26 + fitrect
  27 +}
  28 +
  29 +class PdfOutline extends PdfObject {
22 /// This holds any outlines below us 30 /// This holds any outlines below us
23 - List<PDFOutline> outlines = []; 31 + List<PdfOutline> outlines = [];
24 32
25 /// For subentries, this points to it's parent outline 33 /// For subentries, this points to it's parent outline
26 - PDFOutline parent; 34 + PdfOutline parent;
27 35
28 /// This is this outlines Title 36 /// This is this outlines Title
29 final String title; 37 final String title;
30 38
31 /// The destination page 39 /// The destination page
32 - PDFPage dest; 40 + PdfPage dest;
33 41
34 /// The region on the destination page 42 /// The region on the destination page
35 - final double l, b, r, t;  
36 -  
37 - /// When jumping to the destination, display the whole page  
38 - static const bool FITPAGE = false;  
39 -  
40 - /// When jumping to the destination, display the specified region  
41 - static const bool FITRECT = true; 43 + final PdfRect rect;
42 44
43 /// How the destination is handled 45 /// How the destination is handled
44 - bool destMode = FITPAGE; 46 + PdfOutlineMode destMode = PdfOutlineMode.fitpage;
45 47
46 - /// Constructs a PDF Outline object. When selected, the specified region 48 + /// Constructs a Pdf Outline object. When selected, the specified region
47 /// is displayed. 49 /// is displayed.
48 /// 50 ///
49 /// @param title Title of the outline 51 /// @param title Title of the outline
50 /// @param dest The destination page 52 /// @param dest The destination page
51 - /// @param l left coordinate  
52 - /// @param b bottom coordinate  
53 - /// @param r right coordinate  
54 - /// @param t top coordinate  
55 - PDFOutline(PDFDocument pdfDocument,  
56 - {this.title, this.dest, this.l, this.b, this.r, this.t}) 53 + /// @param rect coordinate
  54 + PdfOutline(PdfDocument pdfDocument, {this.title, this.dest, this.rect})
57 : super(pdfDocument, "/Outlines"); 55 : super(pdfDocument, "/Outlines");
58 56
59 /// This method creates an outline, and attaches it to this one. 57 /// This method creates an outline, and attaches it to this one.
60 /// When the outline is selected, the supplied region is displayed. 58 /// When the outline is selected, the supplied region is displayed.
61 /// 59 ///
62 - /// <p>Note: the coordiates are in Java space. They are converted to User 60 + /// Note: the coordiates are in User space. They are converted to User
63 /// space. 61 /// space.
64 /// 62 ///
65 - /// <p>This allows you to have an outline for say a Chapter, 63 + /// This allows you to have an outline for say a Chapter,
66 /// then under the chapter, one for each section. You are not really 64 /// then under the chapter, one for each section. You are not really
67 /// limited on how deep you go, but it's best not to go below say 6 levels, 65 /// limited on how deep you go, but it's best not to go below say 6 levels,
68 /// for the reader's sake. 66 /// for the reader's sake.
69 /// 67 ///
70 /// @param title Title of the outline 68 /// @param title Title of the outline
71 /// @param dest The destination page 69 /// @param dest The destination page
72 - /// @param x coordinate of region in Java space  
73 - /// @param y coordinate of region in Java space  
74 - /// @param w width of region in Java space  
75 - /// @param h height of region in Java space  
76 - /// @return PDFOutline object created, for creating sub-outlines  
77 - PDFOutline add({String title, PDFPage dest, double x, y, w, h}) {  
78 - var xy1 = dest.cxy(x, y + h);  
79 - var xy2 = dest.cxy(x + w, y);  
80 - PDFOutline outline = new PDFOutline(pdfDocument,  
81 - title: title, dest: dest, l: xy1.w, b: xy1.h, r: xy2.w, t: xy2.h); 70 + /// @param x coordinate of region in User space
  71 + /// @param y coordinate of region in User space
  72 + /// @param w width of region in User space
  73 + /// @param h height of region in User space
  74 + /// @return [PdfOutline] object created, for creating sub-outlines
  75 + PdfOutline add({String title, PdfPage dest, PdfRect rect}) {
  76 + PdfOutline outline =
  77 + new PdfOutline(pdfDocument, title: title, dest: dest, rect: rect);
82 // Tell the outline of ourselves 78 // Tell the outline of ourselves
83 outline.parent = this; 79 outline.parent = this;
84 return outline; 80 return outline;
@@ -91,23 +87,24 @@ class PDFOutline extends PDFObject { @@ -91,23 +87,24 @@ class PDFOutline extends PDFObject {
91 87
92 // These are for kids only 88 // These are for kids only
93 if (parent != null) { 89 if (parent != null) {
94 - params["/Title"] = PDFStream.string(title);  
95 - var dests = new List<PDFStream>(); 90 + params["/Title"] = PdfStream.string(title);
  91 + var dests = new List<PdfStream>();
96 dests.add(dest.ref()); 92 dests.add(dest.ref());
97 93
98 - if (destMode == FITPAGE) {  
99 - dests.add(PDFStream.string("/Fit")); 94 + if (destMode == PdfOutlineMode.fitpage) {
  95 + dests.add(PdfStream.string("/Fit"));
100 } else { 96 } else {
101 - dests.add(PDFStream.string("/FitR $l $b $r $t")); 97 + dests.add(
  98 + PdfStream.string("/FitR ${rect.l} ${rect.b} ${rect.r} ${rect.t}"));
102 } 99 }
103 params["/Parent"] = parent.ref(); 100 params["/Parent"] = parent.ref();
104 - params["/Dest"] = PDFStream.array(dests); 101 + params["/Dest"] = PdfStream.array(dests);
105 102
106 // were a decendent, so by default we are closed. Find out how many 103 // were a decendent, so by default we are closed. Find out how many
107 // entries are below us 104 // entries are below us
108 int c = descendants(); 105 int c = descendants();
109 if (c > 0) { 106 if (c > 0) {
110 - params["/Count"] = PDFStream.intNum(-c); 107 + params["/Count"] = PdfStream.intNum(-c);
111 } 108 }
112 109
113 int index = parent.getIndex(this); 110 int index = parent.getIndex(this);
@@ -123,7 +120,7 @@ class PDFOutline extends PDFObject { @@ -123,7 +120,7 @@ class PDFOutline extends PDFObject {
123 } else { 120 } else {
124 // the number of outlines in this document 121 // the number of outlines in this document
125 // were the top level node, so all are open by default 122 // were the top level node, so all are open by default
126 - params["/Count"] = PDFStream.intNum(outlines.length); 123 + params["/Count"] = PdfStream.intNum(outlines.length);
127 } 124 }
128 125
129 // These only valid if we have children 126 // These only valid if we have children
@@ -139,9 +136,9 @@ class PDFOutline extends PDFObject { @@ -139,9 +136,9 @@ class PDFOutline extends PDFObject {
139 /// This is called by children to find their position in this outlines 136 /// This is called by children to find their position in this outlines
140 /// tree. 137 /// tree.
141 /// 138 ///
142 - /// @param outline PDFOutline to search for 139 + /// @param outline [PdfOutline] to search for
143 /// @return index within Vector 140 /// @return index within Vector
144 - int getIndex(PDFOutline outline) => outlines.indexOf(outline); 141 + int getIndex(PdfOutline outline) => outlines.indexOf(outline);
145 142
146 /// Returns the last index in this outline 143 /// Returns the last index in this outline
147 /// @return last index in outline 144 /// @return last index in outline
@@ -150,7 +147,7 @@ class PDFOutline extends PDFObject { @@ -150,7 +147,7 @@ class PDFOutline extends PDFObject {
150 /// Returns the outline at a specified position. 147 /// Returns the outline at a specified position.
151 /// @param i index 148 /// @param i index
152 /// @return the node at index i 149 /// @return the node at index i
153 - PDFOutline getNode(int i) => outlines[i]; 150 + PdfOutline getNode(int i) => outlines[i];
154 151
155 /// Returns the total number of descendants below this one. 152 /// Returns the total number of descendants below this one.
156 /// @return the number of descendants below this one 153 /// @return the number of descendants below this one
@@ -158,7 +155,7 @@ class PDFOutline extends PDFObject { @@ -158,7 +155,7 @@ class PDFOutline extends PDFObject {
158 int c = outlines.length; // initially the number of kids 155 int c = outlines.length; // initially the number of kids
159 156
160 // now call each one for their descendants 157 // now call each one for their descendants
161 - for (PDFOutline o in outlines) { 158 + for (PdfOutline o in outlines) {
162 c += o.descendants(); 159 c += o.descendants();
163 } 160 }
164 161
@@ -18,37 +18,37 @@ @@ -18,37 +18,37 @@
18 18
19 part of pdf; 19 part of pdf;
20 20
21 -class PDFOutput {  
22 - /// This is the actual PDFStream used to write to.  
23 - final PDFStream os; 21 +class PdfOutput {
  22 + /// This is the actual [PdfStream] used to write to.
  23 + final PdfStream os;
24 24
25 /// This vector contains offsets of each object 25 /// This vector contains offsets of each object
26 - List<PDFXref> offsets = []; 26 + List<PdfXref> offsets = [];
27 27
28 /// This is used to track the /Root object (catalog) 28 /// This is used to track the /Root object (catalog)
29 - PDFObject rootID; 29 + PdfObject rootID;
30 30
31 /// This is used to track the /Info object (info) 31 /// This is used to track the /Info object (info)
32 - PDFObject infoID; 32 + PdfObject infoID;
33 33
34 - /// This creates a PDF PDFStream 34 + /// This creates a Pdf [PdfStream]
35 /// 35 ///
36 - /// @param os The output stream to write the PDF file to.  
37 - PDFOutput(this.os) { 36 + /// @param os The output stream to write the Pdf file to.
  37 + PdfOutput(this.os) {
38 os.putString("%PDF-1.4\n"); 38 os.putString("%PDF-1.4\n");
39 os.putBytes([0x25, 0xC2, 0xA5, 0xC2, 0xB1, 0xC3, 0xAB, 0x0A]); 39 os.putBytes([0x25, 0xC2, 0xA5, 0xC2, 0xB1, 0xC3, 0xAB, 0x0A]);
40 } 40 }
41 41
42 - /// This method writes a PDFObject to the stream. 42 + /// This method writes a [PdfObject] to the stream.
43 /// 43 ///
44 - /// @param ob PDFObject Obeject to write  
45 - void write(PDFObject ob) { 44 + /// @param ob [PdfObject] Obeject to write
  45 + void write(PdfObject ob) {
46 // Check the object to see if it's one that is needed in the trailer 46 // Check the object to see if it's one that is needed in the trailer
47 // object 47 // object
48 - if (ob is PDFCatalog) rootID = ob;  
49 - if (ob is PDFInfo) infoID = ob; 48 + if (ob is PdfCatalog) rootID = ob;
  49 + if (ob is PdfInfo) infoID = ob;
50 50
51 - offsets.add(new PDFXref(ob.objser, os.offset)); 51 + offsets.add(new PdfXref(ob.objser, os.offset));
52 ob.write(os); 52 ob.write(os);
53 } 53 }
54 54
@@ -56,7 +56,7 @@ class PDFOutput { @@ -56,7 +56,7 @@ class PDFOutput {
56 void close() { 56 void close() {
57 // we use baos to speed things up a little. 57 // we use baos to speed things up a little.
58 // Also, offset is preserved, and marks the begining of this block. 58 // Also, offset is preserved, and marks the begining of this block.
59 - // This is required by PDF at the end of the PDF file. 59 + // This is required by Pdf at the end of the Pdf file.
60 60
61 int xref = os.offset; 61 int xref = os.offset;
62 62
@@ -72,9 +72,9 @@ class PDFOutput { @@ -72,9 +72,9 @@ class PDFOutput {
72 var block = []; // xrefs in this block 72 var block = []; // xrefs in this block
73 73
74 // We need block 0 to exist 74 // We need block 0 to exist
75 - block.add(new PDFXref(0, 0, generation: 65535)); 75 + block.add(new PdfXref(0, 0, generation: 65535));
76 76
77 - for (PDFXref x in offsets) { 77 + for (PdfXref x in offsets) {
78 if (firstid == -1) firstid = x.id; 78 if (firstid == -1) firstid = x.id;
79 79
80 // check to see if block is in range (-1 means empty) 80 // check to see if block is in range (-1 means empty)
@@ -120,14 +120,14 @@ class PDFOutput { @@ -120,14 +120,14 @@ class PDFOutput {
120 os.putString(">>\nstartxref\n$xref\n%%EOF\n"); 120 os.putString(">>\nstartxref\n$xref\n%%EOF\n");
121 } 121 }
122 122
123 - /// Writes a block of references to the PDF file 123 + /// Writes a block of references to the Pdf file
124 /// @param firstid ID of the first reference in this block 124 /// @param firstid ID of the first reference in this block
125 /// @param block Vector containing the references in this block 125 /// @param block Vector containing the references in this block
126 void writeblock(int firstid, var block) { 126 void writeblock(int firstid, var block) {
127 os.putString("$firstid ${block.length}\n"); 127 os.putString("$firstid ${block.length}\n");
128 //os.write("\n0000000000 65535 f\n"); 128 //os.write("\n0000000000 65535 f\n");
129 129
130 - for (PDFXref x in block) { 130 + for (PdfXref x in block) {
131 os.putString(x.ref()); 131 os.putString(x.ref());
132 os.putString("\n"); 132 os.putString("\n");
133 } 133 }
@@ -18,137 +18,62 @@ @@ -18,137 +18,62 @@
18 18
19 part of pdf; 19 part of pdf;
20 20
21 -class PDFPage extends PDFObject { 21 +class PdfPage extends PdfObject {
22 /// This is this page format, ie the size of the page, margins, and rotation 22 /// This is this page format, ie the size of the page, margins, and rotation
23 - PDFPageFormat pageFormat; 23 + PdfPageFormat pageFormat;
24 24
25 /// This holds the contents of the page. 25 /// This holds the contents of the page.
26 - List<PDFObjectStream> contents = []; 26 + List<PdfObjectStream> contents = [];
27 27
28 /// Object ID that contains a thumbnail sketch of the page. 28 /// Object ID that contains a thumbnail sketch of the page.
29 /// -1 indicates no thumbnail. 29 /// -1 indicates no thumbnail.
30 - PDFObject thumbnail; 30 + PdfObject thumbnail;
31 31
32 /// This holds any Annotations contained within this page. 32 /// This holds any Annotations contained within this page.
33 - List<PDFAnnot> annotations = []; 33 + List<PdfAnnot> annotations = [];
34 34
35 /// The fonts associated with this page 35 /// The fonts associated with this page
36 - final fonts = new Map<String, PDFFont>(); 36 + final fonts = new Map<String, PdfFont>();
37 37
38 /// The xobjects or other images in the pdf 38 /// The xobjects or other images in the pdf
39 - final xObjects = new Map<String, PDFXObject>(); 39 + final xObjects = new Map<String, PdfXObject>();
40 40
41 /// This constructs a Page object, which will hold any contents for this 41 /// This constructs a Page object, which will hold any contents for this
42 /// page. 42 /// page.
43 /// 43 ///
44 - /// <p>Once created, it is added to the document via the PDF.add() method. 44 + /// Once created, it is added to the document via the [PdfDocument.add()] method.
45 /// 45 ///
46 - /// @param orientation Orientation: 0, 90 or 270  
47 - /// @see PageFormat#PORTRAIT  
48 - /// @see PageFormat#LANDSCAPE  
49 - /// @see PageFormat#REVERSE_LANDSCAPE  
50 - /// @param pageFormat PageFormat describing the page size  
51 - PDFPage(PDFDocument pdfDocument, {this.pageFormat}) 46 + /// @param pdfDocument Document
  47 + /// @param pageFormat [PdfPageFormat] describing the page size
  48 + PdfPage(PdfDocument pdfDocument, {this.pageFormat})
52 : super(pdfDocument, "/Page") { 49 : super(pdfDocument, "/Page") {
53 pdfDocument.pdfPageList.pages.add(this); 50 pdfDocument.pdfPageList.pages.add(this);
54 - if (pageFormat == null) pageFormat = PDFPageFormat.a4; 51 + if (pageFormat == null) pageFormat = PdfPageFormat.a4;
55 } 52 }
56 53
57 - /// This returns a PDFGraphics object, which can then be used to render  
58 - /// on to this page. If a previous PDFGraphics object was used, this object 54 + /// This returns a [PdfGraphics] object, which can then be used to render
  55 + /// on to this page. If a previous [PdfGraphics] object was used, this object
59 /// is appended to the page, and will be drawn over the top of any previous 56 /// is appended to the page, and will be drawn over the top of any previous
60 /// objects. 57 /// objects.
61 /// 58 ///
62 - /// @return a new PDFGraphics object to be used to draw this page.  
63 - PDFGraphics getGraphics() {  
64 - var stream = new PDFObjectStream(pdfDocument);  
65 - var g = new PDFGraphics(this, stream.buf); 59 + /// @return a new [PdfGraphics] object to be used to draw this page.
  60 + PdfGraphics getGraphics() {
  61 + var stream = new PdfObjectStream(pdfDocument);
  62 + var g = new PdfGraphics(this, stream.buf);
66 contents.add(stream); 63 contents.add(stream);
67 return g; 64 return g;
68 } 65 }
69 66
70 - /// Returns the page's PageFormat.  
71 - /// @return PageFormat describing the page size in device units (72dpi)  
72 - /// use pageFormat  
73 - @deprecated  
74 - PDFPageFormat getPageFormat() {  
75 - return pageFormat;  
76 - }  
77 -  
78 - /// Gets the dimensions of the page.  
79 - /// @return a Dimension object containing the width and height of the page.  
80 - /// use pageFormat.dimension  
81 - @deprecated  
82 - PDFPoint getDimension() => new PDFPoint(pageFormat.width, pageFormat.height);  
83 -  
84 /// This adds an Annotation to the page. 67 /// This adds an Annotation to the page.
85 /// 68 ///
86 - /// <p>As with other objects, the annotation must be added to the pdf  
87 - /// document using PDF.add() before adding to the page. 69 + /// As with other objects, the annotation must be added to the pdf
  70 + /// document using [PdfDocument.add()] before adding to the page.
88 /// 71 ///
89 /// @param ob Annotation to add. 72 /// @param ob Annotation to add.
90 - void addAnnotation(PDFObject ob) { 73 + void addAnnotation(PdfObject ob) {
91 annotations.add(ob); 74 annotations.add(ob);
92 } 75 }
93 76
94 - /// This method adds a text note to the document.  
95 - /// @param note Text of the note  
96 - /// @param x Coordinate of note  
97 - /// @param y Coordinate of note  
98 - /// @param w Width of the note  
99 - /// @param h Height of the note  
100 - /// @return Returns the annotation, so other settings can be changed.  
101 - PDFAnnot addNote(String note, double x, y, w, h) {  
102 - var xy1 = cxy(x, y + h);  
103 - var xy2 = cxy(x + w, y);  
104 - PDFAnnot ob = new PDFAnnot.text(this, xy1.w, xy1.h, xy2.w, xy2.h, note);  
105 - return ob;  
106 - }  
107 -  
108 - /// Adds a hyperlink to the document.  
109 - /// @param x Coordinate of active area  
110 - /// @param y Coordinate of active area  
111 - /// @param w Width of the active area  
112 - /// @param h Height of the active area  
113 - /// @param dest Page that will be displayed when the link is activated. When  
114 - /// displayed, the zoom factor will be changed to fit the display.  
115 - /// @param vx Coordinate of view area  
116 - /// @param vy Coordinate of view area  
117 - /// @param vw Width of the view area  
118 - /// @param vh Height of the view area  
119 - /// @return Returns the annotation, so other settings can be changed.  
120 - PDFAnnot addLink(double x, y, w, h, PDFObject dest,  
121 - [double vx = PDFAnnot.FULL_PAGE,  
122 - vy = PDFAnnot.FULL_PAGE,  
123 - vw = PDFAnnot.FULL_PAGE,  
124 - vh = PDFAnnot.FULL_PAGE]) {  
125 - var xy1 = cxy(x, y + h);  
126 - var xy2 = cxy(x + w, y);  
127 - var xy3 = cxy(vx, vy + vh);  
128 - var xy4 = cxy(vx + vw, vy);  
129 - PDFAnnot ob = new PDFAnnot.link(  
130 - this, xy1.w, xy1.h, xy2.w, xy2.h, dest, xy3.w, xy3.h, xy4.w, xy4.h);  
131 - return ob;  
132 - }  
133 -  
134 - /// This method attaches an outline to the current page being generated. When  
135 - /// selected, the outline displays the top of the page.  
136 - /// @param title Outline title to attach  
137 - /// @param x Left coordinate of region  
138 - /// @param y Bottom coordinate of region  
139 - /// @param w Width of region  
140 - /// @param h Height coordinate of region  
141 - /// @return PDFOutline object created, for addSubOutline if required.  
142 - PDFOutline addOutline(String title,  
143 - {double x, double y, double w, double h}) {  
144 - PDFPoint xy1 = cxy(x, y + h);  
145 - PDFPoint xy2 = cxy(x + w, y);  
146 - PDFOutline outline = new PDFOutline(pdfDocument,  
147 - title: title, dest: this, l: xy1.w, b: xy1.h, r: xy2.w, t: xy2.h);  
148 - pdfDocument.outline.outlines.add(outline);  
149 - return outline;  
150 - }  
151 -  
152 /// @param os OutputStream to send the object to 77 /// @param os OutputStream to send the object to
153 @override 78 @override
154 void prepare() { 79 void prepare() {
@@ -158,7 +83,7 @@ class PDFPage extends PDFObject { @@ -158,7 +83,7 @@ class PDFPage extends PDFObject {
158 params["/Parent"] = pdfDocument.pdfPageList.ref(); 83 params["/Parent"] = pdfDocument.pdfPageList.ref();
159 84
160 // the /MediaBox for the page size 85 // the /MediaBox for the page size
161 - params["/MediaBox"] = new PDFStream() 86 + params["/MediaBox"] = new PdfStream()
162 ..putStringArray([0, 0, pageFormat.width, pageFormat.height]); 87 ..putStringArray([0, 0, pageFormat.width, pageFormat.height]);
163 88
164 // Rotation (if not zero) 89 // Rotation (if not zero)
@@ -173,25 +98,25 @@ class PDFPage extends PDFObject { @@ -173,25 +98,25 @@ class PDFPage extends PDFObject {
173 if (contents.length == 1) { 98 if (contents.length == 1) {
174 params["/Contents"] = contents[0].ref(); 99 params["/Contents"] = contents[0].ref();
175 } else { 100 } else {
176 - params["/Contents"] = new PDFStream()..putObjectArray(contents); 101 + params["/Contents"] = new PdfStream()..putObjectArray(contents);
177 } 102 }
178 } 103 }
179 104
180 // Now the resources 105 // Now the resources
181 /// This holds any resources for this page 106 /// This holds any resources for this page
182 - final resources = new Map<String, PDFStream>(); 107 + final resources = new Map<String, PdfStream>();
183 108
184 // fonts 109 // fonts
185 if (fonts.length > 0) { 110 if (fonts.length > 0) {
186 - resources["/Font"] = new PDFStream()..putObjectDictionary(fonts); 111 + resources["/Font"] = new PdfStream()..putObjectDictionary(fonts);
187 } 112 }
188 113
189 // Now the XObjects 114 // Now the XObjects
190 if (xObjects.length > 0) { 115 if (xObjects.length > 0) {
191 - resources["/XObject"] = new PDFStream()..putObjectDictionary(xObjects); 116 + resources["/XObject"] = new PdfStream()..putObjectDictionary(xObjects);
192 } 117 }
193 118
194 - params["/Resources"] = PDFStream.dictionary(resources); 119 + params["/Resources"] = PdfStream.dictionary(resources);
195 120
196 // The thumbnail 121 // The thumbnail
197 if (thumbnail != null) { 122 if (thumbnail != null) {
@@ -200,28 +125,7 @@ class PDFPage extends PDFObject { @@ -200,28 +125,7 @@ class PDFPage extends PDFObject {
200 125
201 // The /Annots object 126 // The /Annots object
202 if (annotations.length > 0) { 127 if (annotations.length > 0) {
203 - params["/Annots"] = new PDFStream()..putObjectArray(annotations); 128 + params["/Annots"] = new PdfStream()..putObjectArray(annotations);
204 } 129 }
205 } 130 }
206 -  
207 - /// This utility method converts the y coordinate from Java to User space  
208 - /// within the page.  
209 - /// @param x Coordinate in Java space  
210 - /// @param y Coordinate in Java space  
211 - /// @return y Coordinate in User space  
212 - double cy(double x, double y) => cxy(x, y).h;  
213 -  
214 - /// This utility method converts the y coordinate from Java to User space  
215 - /// within the page.  
216 - /// @param x Coordinate in Java space  
217 - /// @param y Coordinate in Java space  
218 - /// @return x Coordinate in User space  
219 - double cx(double x, double y) => cxy(x, y).w;  
220 -  
221 - /// This utility method converts the Java coordinates to User space  
222 - /// within the page.  
223 - /// @param x Coordinate in Java space  
224 - /// @param y Coordinate in Java space  
225 - /// @return array containing the x & y Coordinate in User space  
226 - PDFPoint cxy(double x, double y) => new PDFPoint(x, pageFormat.height - y);  
227 } 131 }
@@ -18,49 +18,30 @@ @@ -18,49 +18,30 @@
18 18
19 part of pdf; 19 part of pdf;
20 20
21 -class PDFPageFormat {  
22 - static const a4 = const PDFPageFormat(595.28, 841.89);  
23 - static const a3 = const PDFPageFormat(841.89, 1190.55);  
24 - static const a5 = const PDFPageFormat(420.94, 595.28);  
25 - static const letter = const PDFPageFormat(612.0, 792.0);  
26 - static const legal = const PDFPageFormat(612.0, 1008.0); 21 +class PdfPageFormat {
  22 + static const a4 = const PdfPageFormat(595.28, 841.89);
  23 + static const a3 = const PdfPageFormat(841.89, 1190.55);
  24 + static const a5 = const PdfPageFormat(420.94, 595.28);
  25 + static const letter = const PdfPageFormat(612.0, 792.0);
  26 + static const legal = const PdfPageFormat(612.0, 1008.0);
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;
30 static const cm = inch / 2.54; 30 static const cm = inch / 2.54;
31 static const mm = inch / 25.4; 31 static const mm = inch / 25.4;
32 32
33 - @deprecated  
34 - static const A4 = a4;  
35 - @deprecated  
36 - static const A3 = a3;  
37 - @deprecated  
38 - static const A5 = a5;  
39 - @deprecated  
40 - static const LETTER = letter;  
41 - @deprecated  
42 - static const LEGAL = legal;  
43 - @deprecated  
44 - static const PT = point;  
45 - @deprecated  
46 - static const IN = inch;  
47 - @deprecated  
48 - static const CM = cm;  
49 - @deprecated  
50 - static const MM = mm;  
51 -  
52 final double width; 33 final double width;
53 final double height; 34 final double height;
54 35
55 - const PDFPageFormat(this.width, this.height); 36 + const PdfPageFormat(this.width, this.height);
56 37
57 - PDFPoint get dimension => new PDFPoint(width, height); 38 + PdfPoint get dimension => new PdfPoint(width, height);
58 39
59 - PDFPageFormat get landscape =>  
60 - width >= height ? this : PDFPageFormat(height, width); 40 + PdfPageFormat get landscape =>
  41 + width >= height ? this : PdfPageFormat(height, width);
61 42
62 - PDFPageFormat get portrait =>  
63 - height >= width ? this : PDFPageFormat(height, width); 43 + PdfPageFormat get portrait =>
  44 + height >= width ? this : PdfPageFormat(height, width);
64 45
65 @override 46 @override
66 String toString() { 47 String toString() {
@@ -18,24 +18,23 @@ @@ -18,24 +18,23 @@
18 18
19 part of pdf; 19 part of pdf;
20 20
21 -class PDFPageList extends PDFObject { 21 +class PdfPageList extends PdfObject {
22 /// This holds the pages 22 /// This holds the pages
23 - final List<PDFPage> pages = []; 23 + final List<PdfPage> pages = [];
24 24
25 - /// This constructs a PDF Pages object.  
26 - PDFPageList(PDFDocument pdfDocument) : super(pdfDocument, "/Pages"); 25 + /// This constructs a [PdfPageList] object.
  26 + PdfPageList(PdfDocument pdfDocument) : super(pdfDocument, "/Pages");
27 27
28 - /// This returns a specific page. Used by the PDF class. 28 + /// This returns a specific page. Used by the Pdf class.
29 /// @param page page number to return 29 /// @param page page number to return
30 - /// @return PDFPage at that position  
31 - PDFPage getPage(int page) => pages[page]; 30 + /// @return [PdfPage] at that position
  31 + PdfPage getPage(int page) => pages[page];
32 32
33 - /// @param os OutputStream to send the object to  
34 @override 33 @override
35 void prepare() { 34 void prepare() {
36 super.prepare(); 35 super.prepare();
37 36
38 - params["/Kids"] = new PDFStream()..putObjectArray(pages);  
39 - params["/Count"] = PDFStream.intNum(pages.length); 37 + params["/Kids"] = new PdfStream()..putObjectArray(pages);
  38 + params["/Count"] = PdfStream.intNum(pages.length);
40 } 39 }
41 } 40 }
@@ -18,10 +18,12 @@ @@ -18,10 +18,12 @@
18 18
19 part of pdf; 19 part of pdf;
20 20
21 -class PDFPoint {  
22 - final double w, h;  
23 - const PDFPoint(this.w, this.h); 21 +@immutable
  22 +class PdfPoint {
  23 + final double x, y;
  24 +
  25 + const PdfPoint(this.x, this.y);
24 26
25 @override 27 @override
26 - String toString() => "PDFPoint($w, $h)"; 28 + String toString() => "PdfPoint($x, $y)";
27 } 29 }
@@ -18,13 +18,13 @@ @@ -18,13 +18,13 @@
18 18
19 part of pdf; 19 part of pdf;
20 20
21 -class Polygon {  
22 - List<PDFPoint> points; 21 +class PdfPolygon {
  22 + List<PdfPoint> points;
23 23
24 - Polygon(this.points); 24 + PdfPolygon(this.points);
25 25
26 - PDFRect getBounds() { 26 + PdfRect getBounds() {
27 // TODO: Implement properly 27 // TODO: Implement properly
28 - return const PDFRect(0.0, 0.0, 0.0, 0.0); 28 + return const PdfRect(0.0, 0.0, 0.0, 0.0);
29 } 29 }
30 } 30 }
@@ -18,10 +18,22 @@ @@ -18,10 +18,22 @@
18 18
19 part of pdf; 19 part of pdf;
20 20
21 -class PDFRect { 21 +@immutable
  22 +class PdfRect {
22 final double x, y, w, h; 23 final double x, y, w, h;
23 - const PDFRect(this.x, this.y, this.w, this.h); 24 +
  25 + const PdfRect(this.x, this.y, this.w, this.h);
  26 +
  27 + factory PdfRect.fromLTRB(
  28 + double left, double top, double right, double bottom) {
  29 + return PdfRect(left, top, right - left, bottom - top);
  30 + }
  31 +
  32 + double get l => x;
  33 + double get b => y;
  34 + double get r => x + w;
  35 + double get t => y + h;
24 36
25 @override 37 @override
26 - String toString() => "PDFRect($x, $y, $w, $h)"; 38 + String toString() => "PdfRect($x, $y, $w, $h)";
27 } 39 }
@@ -18,10 +18,10 @@ @@ -18,10 +18,10 @@
18 18
19 part of pdf; 19 part of pdf;
20 20
21 -class PDFStream { 21 +class PdfStream {
22 final _stream = List<int>(); 22 final _stream = List<int>();
23 23
24 - void putStream(PDFStream s) { 24 + void putStream(PdfStream s) {
25 _stream.addAll(s._stream); 25 _stream.addAll(s._stream);
26 } 26 }
27 27
@@ -35,7 +35,7 @@ class PDFStream { @@ -35,7 +35,7 @@ class PDFStream {
35 } 35 }
36 } 36 }
37 37
38 - static PDFStream string(String s) => new PDFStream()..putString(s); 38 + static PdfStream string(String s) => new PdfStream()..putString(s);
39 39
40 void putStringUtf16(String s) { 40 void putStringUtf16(String s) {
41 for (int codeUnit in s.codeUnits) { 41 for (int codeUnit in s.codeUnits) {
@@ -52,8 +52,8 @@ class PDFStream { @@ -52,8 +52,8 @@ class PDFStream {
52 putString(d.toString()); 52 putString(d.toString());
53 } 53 }
54 54
55 - static PDFStream num(double d) => new PDFStream()..putNum(d);  
56 - static PDFStream intNum(int i) => new PDFStream()..putString(i.toString()); 55 + static PdfStream num(double d) => new PdfStream()..putNum(d);
  56 + static PdfStream intNum(int i) => new PdfStream()..putString(i.toString());
57 57
58 void putText(String s) { 58 void putText(String s) {
59 // Escape special characters 59 // Escape special characters
@@ -79,13 +79,13 @@ class PDFStream { @@ -79,13 +79,13 @@ class PDFStream {
79 putBytes(latin1.encode('(' + s + ')')); 79 putBytes(latin1.encode('(' + s + ')'));
80 } 80 }
81 81
82 - static PDFStream text(String s) => new PDFStream()..putText(s); 82 + static PdfStream text(String s) => new PdfStream()..putText(s);
83 83
84 void putBool(bool value) { 84 void putBool(bool value) {
85 putString(value ? "true" : "false"); 85 putString(value ? "true" : "false");
86 } 86 }
87 87
88 - void putArray(List<PDFStream> values) { 88 + void putArray(List<PdfStream> values) {
89 putString("["); 89 putString("[");
90 for (var val in values) { 90 for (var val in values) {
91 putStream(val); 91 putStream(val);
@@ -94,7 +94,7 @@ class PDFStream { @@ -94,7 +94,7 @@ class PDFStream {
94 putString("]"); 94 putString("]");
95 } 95 }
96 96
97 - void putObjectArray(List<PDFObject> values) { 97 + void putObjectArray(List<PdfObject> values) {
98 putString("["); 98 putString("[");
99 for (var val in values) { 99 for (var val in values) {
100 putStream(val.ref()); 100 putStream(val.ref());
@@ -107,10 +107,10 @@ class PDFStream { @@ -107,10 +107,10 @@ class PDFStream {
107 putString("[" + values.join(" ") + "]"); 107 putString("[" + values.join(" ") + "]");
108 } 108 }
109 109
110 - static PDFStream array(List<PDFStream> values) =>  
111 - new PDFStream()..putArray(values); 110 + static PdfStream array(List<PdfStream> values) =>
  111 + new PdfStream()..putArray(values);
112 112
113 - void putDictionary(Map<String, PDFStream> values) { 113 + void putDictionary(Map<String, PdfStream> values) {
114 putString("<< "); 114 putString("<< ");
115 values.forEach((k, v) { 115 values.forEach((k, v) {
116 putString("$k "); 116 putString("$k ");
@@ -120,10 +120,10 @@ class PDFStream { @@ -120,10 +120,10 @@ class PDFStream {
120 putString(">>"); 120 putString(">>");
121 } 121 }
122 122
123 - static PDFStream dictionary(Map<String, PDFStream> values) =>  
124 - new PDFStream()..putDictionary(values); 123 + static PdfStream dictionary(Map<String, PdfStream> values) =>
  124 + new PdfStream()..putDictionary(values);
125 125
126 - void putObjectDictionary(Map<String, PDFObject> values) { 126 + void putObjectDictionary(Map<String, PdfObject> values) {
127 putString("<< "); 127 putString("<< ");
128 values.forEach((k, v) { 128 values.forEach((k, v) {
129 putString("$k "); 129 putString("$k ");
@@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
18 18
19 part of pdf; 19 part of pdf;
20 20
21 -class TTFParser { 21 +class TtfParser {
22 static const _HEAD = "head"; 22 static const _HEAD = "head";
23 static const _NAME = "name"; 23 static const _NAME = "name";
24 static const _HMTX = "hmtx"; 24 static const _HMTX = "hmtx";
@@ -34,9 +34,9 @@ class TTFParser { @@ -34,9 +34,9 @@ class TTFParser {
34 final advanceWidth = new List<double>(); 34 final advanceWidth = new List<double>();
35 final charToGlyphIndexMap = new Map<int, int>(); 35 final charToGlyphIndexMap = new Map<int, int>();
36 final glyphOffsets = new List<int>(); 36 final glyphOffsets = new List<int>();
37 - final glyphInfoMap = new Map<int, PDFRect>(); 37 + final glyphInfoMap = new Map<int, PdfRect>();
38 38
39 - TTFParser(this.bytes) { 39 + TtfParser(this.bytes) {
40 final numTables = bytes.getUint16(4); 40 final numTables = bytes.getUint16(4);
41 41
42 for (var i = 0; i < numTables; i++) { 42 for (var i = 0; i < numTables; i++) {
@@ -210,7 +210,7 @@ class TTFParser { @@ -210,7 +210,7 @@ class TTFParser {
210 final yMin = bytes.getInt16(baseOffset + offset + 4); // 4 210 final yMin = bytes.getInt16(baseOffset + offset + 4); // 4
211 final xMax = bytes.getInt16(baseOffset + offset + 6); // 6 211 final xMax = bytes.getInt16(baseOffset + offset + 6); // 6
212 final yMax = bytes.getInt16(baseOffset + offset + 8); // 8 212 final yMax = bytes.getInt16(baseOffset + offset + 8); // 8
213 - glyphInfoMap[glyphIndex] = new PDFRect( 213 + glyphInfoMap[glyphIndex] = new PdfRect(
214 xMin.toDouble() / unitsPerEm, 214 xMin.toDouble() / unitsPerEm,
215 yMin.toDouble() / unitsPerEm, 215 yMin.toDouble() / unitsPerEm,
216 xMax.toDouble() / unitsPerEm, 216 xMax.toDouble() / unitsPerEm,
@@ -18,25 +18,25 @@ @@ -18,25 +18,25 @@
18 18
19 part of pdf; 19 part of pdf;
20 20
21 -class PDFTTFFont extends PDFFont {  
22 - PDFObject unicodeCMap;  
23 - PDFFontDescriptor descriptor;  
24 - PDFArrayObject widthsObject; 21 +class PdfTtfFont extends PdfFont {
  22 + PdfObject unicodeCMap;
  23 + PdfFontDescriptor descriptor;
  24 + PdfArrayObject widthsObject;
25 final widths = new List<String>(); 25 final widths = new List<String>();
26 - final TTFParser font; 26 + final TtfParser font;
27 int _charMin; 27 int _charMin;
28 int _charMax; 28 int _charMax;
29 29
30 - /// Constructs a PDFTTFFont  
31 - PDFTTFFont(PDFDocument pdfDocument, ByteData bytes)  
32 - : font = new TTFParser(bytes), 30 + /// Constructs a [PdfTtfFont]
  31 + PdfTtfFont(PdfDocument pdfDocument, ByteData bytes)
  32 + : font = new TtfParser(bytes),
33 super(pdfDocument, subtype: "/TrueType") { 33 super(pdfDocument, subtype: "/TrueType") {
34 baseFont = "/" + font.fontName.replaceAll(" ", ""); 34 baseFont = "/" + font.fontName.replaceAll(" ", "");
35 35
36 - PDFObjectStream file = new PDFObjectStream(pdfDocument, isBinary: true); 36 + PdfObjectStream file = new PdfObjectStream(pdfDocument, isBinary: true);
37 final data = bytes.buffer.asUint8List(); 37 final data = bytes.buffer.asUint8List();
38 file.buf.putBytes(data); 38 file.buf.putBytes(data);
39 - file.params["/Length1"] = PDFStream.intNum(data.length); 39 + file.params["/Length1"] = PdfStream.intNum(data.length);
40 40
41 _charMin = 32; 41 _charMin = 32;
42 _charMax = 255; 42 _charMax = 255;
@@ -45,9 +45,9 @@ class PDFTTFFont extends PDFFont { @@ -45,9 +45,9 @@ class PDFTTFFont extends PDFFont {
45 widths.add((glyphAdvance(i) * 1000.0).toString()); 45 widths.add((glyphAdvance(i) * 1000.0).toString());
46 } 46 }
47 47
48 - unicodeCMap = new PDFObject(pdfDocument);  
49 - descriptor = new PDFFontDescriptor(this, file);  
50 - widthsObject = new PDFArrayObject(pdfDocument, widths); 48 + unicodeCMap = new PdfObject(pdfDocument);
  49 + descriptor = new PdfFontDescriptor(this, file);
  50 + widthsObject = new PdfArrayObject(pdfDocument, widths);
51 } 51 }
52 52
53 @override 53 @override
@@ -63,7 +63,7 @@ class PDFTTFFont extends PDFFont { @@ -63,7 +63,7 @@ class PDFTTFFont extends PDFFont {
63 } 63 }
64 64
65 @override 65 @override
66 - PDFRect glyphBounds(int charCode) { 66 + PdfRect glyphBounds(int charCode) {
67 var g = font.charToGlyphIndexMap[charCode]; 67 var g = font.charToGlyphIndexMap[charCode];
68 68
69 if (g == null) { 69 if (g == null) {
@@ -77,11 +77,11 @@ class PDFTTFFont extends PDFFont { @@ -77,11 +77,11 @@ class PDFTTFFont extends PDFFont {
77 void prepare() { 77 void prepare() {
78 super.prepare(); 78 super.prepare();
79 79
80 - params["/FirstChar"] = PDFStream.intNum(_charMin);  
81 - params["/LastChar"] = PDFStream.intNum(_charMax); 80 + params["/FirstChar"] = PdfStream.intNum(_charMin);
  81 + params["/LastChar"] = PdfStream.intNum(_charMax);
82 params["/Widths"] = widthsObject.ref(); 82 params["/Widths"] = widthsObject.ref();
83 params["/FontDescriptor"] = descriptor.ref(); 83 params["/FontDescriptor"] = descriptor.ref();
84 -// params["/Encoding"] = PDFStream.string("/Identity-H"); 84 +// params["/Encoding"] = PdfStream.string("/Identity-H");
85 // params["/ToUnicode"] = unicodeCMap.ref(); 85 // params["/ToUnicode"] = unicodeCMap.ref();
86 } 86 }
87 } 87 }
@@ -18,9 +18,9 @@ @@ -18,9 +18,9 @@
18 18
19 part of pdf; 19 part of pdf;
20 20
21 -class PDFXObject extends PDFObjectStream {  
22 - PDFXObject(PDFDocument pdfDocument, String subtype, {bool isBinary = false}) 21 +class PdfXObject extends PdfObjectStream {
  22 + PdfXObject(PdfDocument pdfDocument, String subtype, {bool isBinary = false})
23 : super(pdfDocument, type: '/XObject', isBinary: isBinary) { 23 : super(pdfDocument, type: '/XObject', isBinary: isBinary) {
24 - params['/Subtype'] = PDFStream.string(subtype); 24 + params['/Subtype'] = PdfStream.string(subtype);
25 } 25 }
26 } 26 }
@@ -18,23 +18,23 @@ @@ -18,23 +18,23 @@
18 18
19 part of pdf; 19 part of pdf;
20 20
21 -class PDFXref {  
22 - /// The id of a PDF Object 21 +class PdfXref {
  22 + /// The id of a Pdf Object
23 int id; 23 int id;
24 24
25 - /// The offset within the PDF file 25 + /// The offset within the Pdf file
26 int offset; 26 int offset;
27 27
28 /// The generation of the object, usually 0 28 /// The generation of the object, usually 0
29 int generation = 0; 29 int generation = 0;
30 30
31 - /// Creates a crossreference for a PDF Object 31 + /// Creates a crossreference for a Pdf Object
32 /// @param id The object's ID 32 /// @param id The object's ID
33 /// @param offset The object's position in the file 33 /// @param offset The object's position in the file
34 /// @param generation The object's generation, usually 0 34 /// @param generation The object's generation, usually 0
35 - PDFXref(this.id, this.offset, {this.generation = 0}); 35 + PdfXref(this.id, this.offset, {this.generation = 0});
36 36
37 - /// @return The xref in the format of the xref section in the PDF file 37 + /// @return The xref in the format of the xref section in the Pdf file
38 String ref() { 38 String ref() {
39 String rs = offset.toString().padLeft(10, '0') + 39 String rs = offset.toString().padLeft(10, '0') +
40 " " + 40 " " +
@@ -11,13 +11,13 @@ void main() { @@ -11,13 +11,13 @@ void main() {
11 var img = new Uint32List(10 * 10); 11 var img = new Uint32List(10 * 10);
12 img.fillRange(0, img.length - 1, 0x12345678); 12 img.fillRange(0, img.length - 1, 0x12345678);
13 13
14 - var pdf = new PDFDocument(deflate: zlib.encode); 14 + var pdf = new PdfDocument(deflate: zlib.encode);
15 var i = pdf.info; 15 var i = pdf.info;
16 i.author = "David PHAM-VAN"; 16 i.author = "David PHAM-VAN";
17 i.creator = i.author; 17 i.creator = i.author;
18 i.title = "My Title"; 18 i.title = "My Title";
19 i.subject = "My Subject"; 19 i.subject = "My Subject";
20 - var page = new PDFPage(pdf, pageFormat: const PDFPageFormat(500.0, 300.0)); 20 + var page = new PdfPage(pdf, pageFormat: const PdfPageFormat(500.0, 300.0));
21 21
22 var g = page.getGraphics(); 22 var g = page.getGraphics();
23 g.saveContext(); 23 g.saveContext();
@@ -26,9 +26,9 @@ void main() { @@ -26,9 +26,9 @@ void main() {
26 g.setTransform(tm); 26 g.setTransform(tm);
27 // g.drawShape("M37 0H9C6.24 0 4 2.24 4 5v38c0 2.76 2.24 5 5 5h28c2.76 0 5-2.24 5-5V5c0-2.76-2.24-5-5-5zM23 46c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3zm15-8H8V6h30v32z"); 27 // g.drawShape("M37 0H9C6.24 0 4 2.24 4 5v38c0 2.76 2.24 5 5 5h28c2.76 0 5-2.24 5-5V5c0-2.76-2.24-5-5-5zM23 46c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3zm15-8H8V6h30v32z");
28 g.restoreContext(); 28 g.restoreContext();
29 - var font1 = new PDFFont(pdf); 29 + var font1 = new PdfFont(pdf);
30 30
31 - var font2 = new PDFTTFFont( 31 + var font2 = new PdfTtfFont(
32 pdf, 32 pdf,
33 (new File("open-sans.ttf").readAsBytesSync() as Uint8List) 33 (new File("open-sans.ttf").readAsBytesSync() as Uint8List)
34 .buffer 34 .buffer
@@ -36,21 +36,21 @@ void main() { @@ -36,21 +36,21 @@ void main() {
36 var s = "Hello World!"; 36 var s = "Hello World!";
37 var r = font2.stringBounds(s); 37 var r = font2.stringBounds(s);
38 const FS = 20.0; 38 const FS = 20.0;
39 - g.setColor(new PDFColor(0.0, 1.0, 1.0)); 39 + g.setColor(new PdfColor(0.0, 1.0, 1.0));
40 g.drawRect(50.0 + r.x * FS, 30.0 + r.y * FS, r.w * FS, r.h * FS); 40 g.drawRect(50.0 + r.x * FS, 30.0 + r.y * FS, r.w * FS, r.h * FS);
41 g.fillPath(); 41 g.fillPath();
42 - g.setColor(new PDFColor(0.3, 0.3, 0.3)); 42 + g.setColor(new PdfColor(0.3, 0.3, 0.3));
43 g.drawString(font2, FS, s, 50.0, 30.0); 43 g.drawString(font2, FS, s, 50.0, 30.0);
44 44
45 - g.setColor(new PDFColor(1.0, 0.0, 0.0)); 45 + g.setColor(new PdfColor(1.0, 0.0, 0.0));
46 g.drawString(font2, 20.0, "Hé (Olà)", 50.0, 10.0); 46 g.drawString(font2, 20.0, "Hé (Olà)", 50.0, 10.0);
47 g.drawLine(30.0, 30.0, 200.0, 200.0); 47 g.drawLine(30.0, 30.0, 200.0, 200.0);
48 g.strokePath(); 48 g.strokePath();
49 - g.setColor(new PDFColor(1.0, 0.0, 0.0)); 49 + g.setColor(new PdfColor(1.0, 0.0, 0.0));
50 g.drawRect(300.0, 150.0, 50.0, 50.0); 50 g.drawRect(300.0, 150.0, 50.0, 50.0);
51 g.fillPath(); 51 g.fillPath();
52 - g.setColor(new PDFColor(0.0, 0.5, 0.0));  
53 - var image = new PDFImage(pdf, 52 + g.setColor(new PdfColor(0.0, 0.5, 0.0));
  53 + var image = new PdfImage(pdf,
54 image: img.buffer.asUint8List(), width: 10, height: 10); 54 image: img.buffer.asUint8List(), width: 10, height: 10);
55 for (var i = 10.0; i < 90.0; i += 5.0) { 55 for (var i = 10.0; i < 90.0; i += 5.0) {
56 g.saveContext(); 56 g.saveContext();
@@ -5,8 +5,8 @@ import "package:test/test.dart"; @@ -5,8 +5,8 @@ import "package:test/test.dart";
5 5
6 void main() { 6 void main() {
7 test('Pdf1', () { 7 test('Pdf1', () {
8 - var pdf = new PDFDocument();  
9 - var page = new PDFPage(pdf, pageFormat: PDFPageFormat.a4); 8 + var pdf = new PdfDocument();
  9 + var page = new PdfPage(pdf, pageFormat: PdfPageFormat.a4);
10 10
11 var g = page.getGraphics(); 11 var g = page.getGraphics();
12 g.drawLine(30.0, 30.0, 200.0, 200.0); 12 g.drawLine(30.0, 30.0, 200.0, 200.0);
@@ -6,16 +6,16 @@ import 'package:test/test.dart'; @@ -6,16 +6,16 @@ import 'package:test/test.dart';
6 6
7 void main() { 7 void main() {
8 test('Pdf', () { 8 test('Pdf', () {
9 - var pdf = new PDFDocument(); 9 + var pdf = new PdfDocument();
10 var i = pdf.info; 10 var i = pdf.info;
11 i.author = "David PHAM-VAN"; 11 i.author = "David PHAM-VAN";
12 i.creator = i.author; 12 i.creator = i.author;
13 i.title = "My Title"; 13 i.title = "My Title";
14 i.subject = "My Subject"; 14 i.subject = "My Subject";
15 - var page = new PDFPage(pdf, pageFormat: const PDFPageFormat(500.0, 300.0)); 15 + var page = new PdfPage(pdf, pageFormat: const PdfPageFormat(500.0, 300.0));
16 16
17 var g = page.getGraphics(); 17 var g = page.getGraphics();
18 - var ttf = new PDFTTFFont( 18 + var ttf = new PdfTtfFont(
19 pdf, 19 pdf,
20 (new File("open-sans.ttf").readAsBytesSync() as Uint8List) 20 (new File("open-sans.ttf").readAsBytesSync() as Uint8List)
21 .buffer 21 .buffer
@@ -23,23 +23,23 @@ void main() { @@ -23,23 +23,23 @@ void main() {
23 var s = "Hello World!"; 23 var s = "Hello World!";
24 var r = ttf.stringBounds(s); 24 var r = ttf.stringBounds(s);
25 const FS = 20.0; 25 const FS = 20.0;
26 - g.setColor(new PDFColor(0.0, 1.0, 1.0)); 26 + g.setColor(new PdfColor(0.0, 1.0, 1.0));
27 g.drawRect(50.0 + r.x * FS, 30.0 + r.y * FS, r.w * FS, r.h * FS); 27 g.drawRect(50.0 + r.x * FS, 30.0 + r.y * FS, r.w * FS, r.h * FS);
28 g.fillPath(); 28 g.fillPath();
29 - g.setColor(new PDFColor(0.3, 0.3, 0.3)); 29 + g.setColor(new PdfColor(0.3, 0.3, 0.3));
30 g.drawString(ttf, FS, s, 50.0, 30.0); 30 g.drawString(ttf, FS, s, 50.0, 30.0);
31 31
32 - var roboto = new PDFTTFFont( 32 + var roboto = new PdfTtfFont(
33 pdf, 33 pdf,
34 (new File("roboto.ttf").readAsBytesSync() as Uint8List) 34 (new File("roboto.ttf").readAsBytesSync() as Uint8List)
35 .buffer 35 .buffer
36 .asByteData()); 36 .asByteData());
37 37
38 r = roboto.stringBounds(s); 38 r = roboto.stringBounds(s);
39 - g.setColor(new PDFColor(0.0, 1.0, 1.0)); 39 + g.setColor(new PdfColor(0.0, 1.0, 1.0));
40 g.drawRect(50.0 + r.x * FS, 130.0 + r.y * FS, r.w * FS, r.h * FS); 40 g.drawRect(50.0 + r.x * FS, 130.0 + r.y * FS, r.w * FS, r.h * FS);
41 g.fillPath(); 41 g.fillPath();
42 - g.setColor(new PDFColor(0.3, 0.3, 0.3)); 42 + g.setColor(new PdfColor(0.3, 0.3, 0.3));
43 g.drawString(roboto, FS, s, 50.0, 130.0); 43 g.drawString(roboto, FS, s, 50.0, 130.0);
44 44
45 var file = new File('file2.pdf'); 45 var file = new File('file2.pdf');
@@ -16,7 +16,7 @@ To load an image it is possible to use @@ -16,7 +16,7 @@ To load an image it is possible to use
16 var Image im; 16 var Image im;
17 var bytes = await im.toByteData(format: ui.ImageByteFormat.rawRgba); 17 var bytes = await im.toByteData(format: ui.ImageByteFormat.rawRgba);
18 18
19 -PDFImage image = PDFImage( 19 +PdfImage image = PdfImage(
20 pdf, 20 pdf,
21 image: bytes.buffer.asUint8List(), 21 image: bytes.buffer.asUint8List(),
22 width: im.width, 22 width: im.width,
@@ -28,7 +28,7 @@ To use a TrueType font from a flutter bundle: @@ -28,7 +28,7 @@ To use a TrueType font from a flutter bundle:
28 28
29 ```dart 29 ```dart
30 var font = await rootBundle.load("assets/open-sans.ttf"); 30 var font = await rootBundle.load("assets/open-sans.ttf");
31 -PDFTTFFont ttf = new PDFTTFFont(pdf, font);  
32 -g.setColor(new PDFColor(0.3, 0.3, 0.3)); 31 +PdfTtfFont ttf = new PdfTtfFont(pdf, font);
  32 +g.setColor(new PdfColor(0.3, 0.3, 0.3));
33 g.drawString(ttf, 20.0, "Dart is awesome", 50.0, 30.0); 33 g.drawString(ttf, 20.0, "Dart is awesome", 50.0, 30.0);
34 ``` 34 ```
@@ -19,21 +19,21 @@ class MyAppState extends State<MyApp> { @@ -19,21 +19,21 @@ class MyAppState extends State<MyApp> {
19 final shareWidget = new GlobalKey(); 19 final shareWidget = new GlobalKey();
20 final previewContainer = new GlobalKey(); 20 final previewContainer = new GlobalKey();
21 21
22 - PDFDocument _generateDocument() {  
23 - final pdf = new PDFDocument(deflate: zlib.encode);  
24 - final page = new PDFPage(pdf, pageFormat: PDFPageFormat.a4); 22 + PdfDocument _generateDocument() {
  23 + final pdf = new PdfDocument(deflate: zlib.encode);
  24 + final page = new PdfPage(pdf, pageFormat: PdfPageFormat.a4);
25 final g = page.getGraphics(); 25 final g = page.getGraphics();
26 - final font = new PDFFont(pdf); 26 + final font = new PdfFont(pdf);
27 final top = page.pageFormat.height; 27 final top = page.pageFormat.height;
28 28
29 - g.setColor(new PDFColor(0.0, 1.0, 1.0));  
30 - g.drawRect(50.0 * PDFPageFormat.mm, top - 80.0 * PDFPageFormat.mm,  
31 - 100.0 * PDFPageFormat.mm, 50.0 * PDFPageFormat.mm); 29 + g.setColor(new PdfColor(0.0, 1.0, 1.0));
  30 + g.drawRect(50.0 * PdfPageFormat.mm, top - 80.0 * PdfPageFormat.mm,
  31 + 100.0 * PdfPageFormat.mm, 50.0 * PdfPageFormat.mm);
32 g.fillPath(); 32 g.fillPath();
33 33
34 - g.setColor(new PDFColor(0.3, 0.3, 0.3));  
35 - g.drawString(font, 12.0, "Hello World!", 10.0 * PDFPageFormat.mm,  
36 - top - 10.0 * PDFPageFormat.mm); 34 + g.setColor(new PdfColor(0.3, 0.3, 0.3));
  35 + g.drawString(font, 12.0, "Hello World!", 10.0 * PdfPageFormat.mm,
  36 + top - 10.0 * PdfPageFormat.mm);
37 37
38 return pdf; 38 return pdf;
39 } 39 }
@@ -61,9 +61,9 @@ class MyAppState extends State<MyApp> { @@ -61,9 +61,9 @@ class MyAppState extends State<MyApp> {
61 } 61 }
62 62
63 Future<void> _printScreen() async { 63 Future<void> _printScreen() async {
64 - const margin = 10.0 * PDFPageFormat.mm;  
65 - final pdf = new PDFDocument(deflate: zlib.encode);  
66 - final page = new PDFPage(pdf, pageFormat: PDFPageFormat.a4); 64 + const margin = 10.0 * PdfPageFormat.mm;
  65 + final pdf = new PdfDocument(deflate: zlib.encode);
  66 + final page = new PdfPage(pdf, pageFormat: PdfPageFormat.a4);
67 final g = page.getGraphics(); 67 final g = page.getGraphics();
68 68
69 RenderRepaintBoundary boundary = 69 RenderRepaintBoundary boundary =
@@ -84,7 +84,7 @@ class MyAppState extends State<MyApp> { @@ -84,7 +84,7 @@ class MyAppState extends State<MyApp> {
84 ih = im.height.toDouble() * iw / im.width.toDouble(); 84 ih = im.height.toDouble() * iw / im.width.toDouble();
85 } 85 }
86 86
87 - PDFImage image = PDFImage(pdf, 87 + PdfImage image = PdfImage(pdf,
88 image: bytes.buffer.asUint8List(), width: im.width, height: im.height); 88 image: bytes.buffer.asUint8List(), width: im.width, height: im.height);
89 g.drawImage(image, margin + (w - iw) / 2.0, 89 g.drawImage(image, margin + (w - iw) / 2.0,
90 page.pageFormat.height - margin - ih - (h - ih) / 2.0, iw, ih); 90 page.pageFormat.height - margin - ih - (h - ih) / 2.0, iw, ih);
@@ -27,7 +27,7 @@ import 'package:pdf/pdf.dart'; @@ -27,7 +27,7 @@ import 'package:pdf/pdf.dart';
27 class Printing { 27 class Printing {
28 static const MethodChannel _channel = const MethodChannel('printing'); 28 static const MethodChannel _channel = const MethodChannel('printing');
29 29
30 - static Future<Null> printPdf({PDFDocument document, List<int> bytes}) async { 30 + static Future<Null> printPdf({PdfDocument document, List<int> bytes}) async {
31 assert(document != null || bytes != null); 31 assert(document != null || bytes != null);
32 assert(!(document == null && bytes == null)); 32 assert(!(document == null && bytes == null));
33 33
@@ -41,7 +41,7 @@ class Printing { @@ -41,7 +41,7 @@ class Printing {
41 } 41 }
42 42
43 static Future<Null> sharePdf( 43 static Future<Null> sharePdf(
44 - {PDFDocument document, List<int> bytes, Rect bounds}) async { 44 + {PdfDocument document, List<int> bytes, Rect bounds}) async {
45 assert(document != null || bytes != null); 45 assert(document != null || bytes != null);
46 assert(!(document == null && bytes == null)); 46 assert(!(document == null && bytes == null));
47 47