Showing
5 changed files
with
16 additions
and
55 deletions
@@ -4,7 +4,7 @@ import 'package:pdf/pdf.dart'; | @@ -4,7 +4,7 @@ import 'package:pdf/pdf.dart'; | ||
4 | 4 | ||
5 | void main() { | 5 | void main() { |
6 | final pdf = new PDFDocument(); | 6 | final pdf = new PDFDocument(); |
7 | - final page = new PDFPage(pdf, pageFormat: new PDFPageFormat(PDFPageFormat.LETTER)); | 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 | 10 |
@@ -48,11 +48,9 @@ class PDFPage extends PDFObject { | @@ -48,11 +48,9 @@ class PDFPage extends PDFObject { | ||
48 | /// @see PageFormat#LANDSCAPE | 48 | /// @see PageFormat#LANDSCAPE |
49 | /// @see PageFormat#REVERSE_LANDSCAPE | 49 | /// @see PageFormat#REVERSE_LANDSCAPE |
50 | /// @param pageFormat PageFormat describing the page size | 50 | /// @param pageFormat PageFormat describing the page size |
51 | - PDFPage(PDFDocument pdfDocument, {int orientation, this.pageFormat}) | ||
52 | - : super(pdfDocument, "/Page") { | 51 | + PDFPage(PDFDocument pdfDocument, {this.pageFormat}) : super(pdfDocument, "/Page") { |
53 | pdfDocument.pdfPageList.pages.add(this); | 52 | pdfDocument.pdfPageList.pages.add(this); |
54 | - if (pageFormat == null) pageFormat = new PDFPageFormat(); | ||
55 | - setOrientation(orientation); | 53 | + if (pageFormat == null) pageFormat = PDFPageFormat.A4; |
56 | } | 54 | } |
57 | 55 | ||
58 | /// This returns a PDFGraphics object, which can then be used to render | 56 | /// This returns a PDFGraphics object, which can then be used to render |
@@ -76,25 +74,7 @@ class PDFPage extends PDFObject { | @@ -76,25 +74,7 @@ class PDFPage extends PDFObject { | ||
76 | 74 | ||
77 | /// Gets the dimensions of the page. | 75 | /// Gets the dimensions of the page. |
78 | /// @return a Dimension object containing the width and height of the page. | 76 | /// @return a Dimension object containing the width and height of the page. |
79 | - PDFPoint getDimension() => new PDFPoint(pageFormat.getWidth(), pageFormat.getHeight()); | ||
80 | - | ||
81 | - /// Sets the page's orientation. | ||
82 | - /// | ||
83 | - /// <p>Normally, this should be done when the page is created, to avoid | ||
84 | - /// problems. | ||
85 | - /// | ||
86 | - /// @param orientation a PageFormat orientation constant: | ||
87 | - /// PageFormat.PORTRAIT, PageFormat.LANDSACPE or PageFromat.REVERSE_LANDSACPE | ||
88 | - void setOrientation(int orientation) { | ||
89 | - pageFormat.setOrientation(orientation); | ||
90 | - } | ||
91 | - | ||
92 | - /// Returns the pages orientation: | ||
93 | - /// PageFormat.PORTRAIT, PageFormat.LANDSACPE or PageFromat.REVERSE_LANDSACPE | ||
94 | - /// | ||
95 | - /// @see java.awt.print.PageFormat | ||
96 | - /// @return current orientation of the page | ||
97 | - int getOrientation() => pageFormat.getOrientation(); | 77 | + PDFPoint getDimension() => new PDFPoint(pageFormat.width, pageFormat.height); |
98 | 78 | ||
99 | /// This adds an Annotation to the page. | 79 | /// This adds an Annotation to the page. |
100 | /// | 80 | /// |
@@ -173,7 +153,7 @@ class PDFPage extends PDFObject { | @@ -173,7 +153,7 @@ class PDFPage extends PDFObject { | ||
173 | 153 | ||
174 | // the /MediaBox for the page size | 154 | // the /MediaBox for the page size |
175 | params["/MediaBox"] = new PDFStream() | 155 | params["/MediaBox"] = new PDFStream() |
176 | - ..putStringArray([0, 0, pageFormat.getWidth(), pageFormat.getHeight()]); | 156 | + ..putStringArray([0, 0, pageFormat.width, pageFormat.height]); |
177 | 157 | ||
178 | // Rotation (if not zero) | 158 | // Rotation (if not zero) |
179 | // if(rotate!=0) { | 159 | // if(rotate!=0) { |
@@ -237,5 +217,5 @@ class PDFPage extends PDFObject { | @@ -237,5 +217,5 @@ class PDFPage extends PDFObject { | ||
237 | /// @param x Coordinate in Java space | 217 | /// @param x Coordinate in Java space |
238 | /// @param y Coordinate in Java space | 218 | /// @param y Coordinate in Java space |
239 | /// @return array containing the x & y Coordinate in User space | 219 | /// @return array containing the x & y Coordinate in User space |
240 | - PDFPoint cxy(double x, double y) => new PDFPoint(x, pageFormat.getHeight() - y); | 220 | + PDFPoint cxy(double x, double y) => new PDFPoint(x, pageFormat.height - y); |
241 | } | 221 | } |
@@ -19,38 +19,19 @@ | @@ -19,38 +19,19 @@ | ||
19 | part of pdf; | 19 | part of pdf; |
20 | 20 | ||
21 | class PDFPageFormat { | 21 | class PDFPageFormat { |
22 | - static const A4 = const [595.28, 841.89]; | ||
23 | - static const A3 = const [841.89, 1190.55]; | ||
24 | - static const A5 = const [420.94, 595.28]; | ||
25 | - static const LETTER = const [612.0, 792.0]; | ||
26 | - static const LEGAL = const [612.0, 1008.0]; | 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 PT = 1.0; | 28 | static const PT = 1.0; |
29 | static const IN = 72.0; | 29 | static const IN = 72.0; |
30 | static const CM = IN / 2.54; | 30 | static const CM = IN / 2.54; |
31 | static const MM = IN / 25.4; | 31 | static const MM = IN / 25.4; |
32 | 32 | ||
33 | - double width; | ||
34 | - double height; | ||
35 | - double imageableX = 10.0; | ||
36 | - double imageableY = 10.0; | ||
37 | - double imageableWidth = 300.0; | ||
38 | - double imageableHeight = 300.0; | ||
39 | - int orientation = 0; | 33 | + final double width; |
34 | + final double height; | ||
40 | 35 | ||
41 | - PDFPageFormat([List<double> format]) { | ||
42 | - if (format == null || format.length != 2) format = A4; | ||
43 | - | ||
44 | - width = format[0]; | ||
45 | - height = format[1]; | ||
46 | - } | ||
47 | - | ||
48 | - double getWidth() => width; | ||
49 | - double getHeight() => height; | ||
50 | - | ||
51 | - void setOrientation(int orientation) { | ||
52 | - this.orientation = orientation; | ||
53 | - } | ||
54 | - | ||
55 | - int getOrientation() => orientation; | 36 | + const PDFPageFormat(this.width, this.height); |
56 | } | 37 | } |
@@ -6,7 +6,7 @@ import "package:test/test.dart"; | @@ -6,7 +6,7 @@ import "package:test/test.dart"; | ||
6 | void main() { | 6 | void main() { |
7 | test('Pdf1', () { | 7 | test('Pdf1', () { |
8 | var pdf = new PDFDocument(deflate: false); | 8 | var pdf = new PDFDocument(deflate: false); |
9 | - var page = new PDFPage(pdf, pageFormat: new PDFPageFormat(PDFPageFormat.A4)); | 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); |
@@ -16,7 +16,7 @@ void main() { | @@ -16,7 +16,7 @@ void main() { | ||
16 | i.creator = i.author; | 16 | i.creator = i.author; |
17 | i.title = "My Title"; | 17 | i.title = "My Title"; |
18 | i.subject = "My Subject"; | 18 | i.subject = "My Subject"; |
19 | - var page = new PDFPage(pdf, pageFormat: new PDFPageFormat([500.0, 300.0])); | 19 | + var page = new PDFPage(pdf, pageFormat: const PDFPageFormat(500.0, 300.0)); |
20 | 20 | ||
21 | var g = page.getGraphics(); | 21 | var g = page.getGraphics(); |
22 | g.saveContext(); | 22 | g.saveContext(); |
-
Please register or login to post a comment