David PHAM-VAN

Fix dart lint warnings

Too many changes to show.

To preserve performance only 44 of 44+ files are displayed.

  1 +# 1.3.3
  2 +* Fix dart lint warnings
  3 +
1 # 1.3.2 4 # 1.3.2
2 * Update Readme 5 * Update Readme
3 6
@@ -120,7 +120,7 @@ linter: @@ -120,7 +120,7 @@ linter:
120 # - parameter_assignments # we do this commonly 120 # - parameter_assignments # we do this commonly
121 - prefer_adjacent_string_concatenation 121 - prefer_adjacent_string_concatenation
122 - prefer_asserts_in_initializer_lists 122 - prefer_asserts_in_initializer_lists
123 - - prefer_collection_literals 123 + # - prefer_collection_literals # temporary until all platforms support set literals
124 - prefer_conditional_assignment 124 - prefer_conditional_assignment
125 - prefer_const_constructors 125 - prefer_const_constructors
126 - prefer_const_constructors_in_immutables 126 - prefer_const_constructors_in_immutables
@@ -151,7 +151,7 @@ linter: @@ -151,7 +151,7 @@ linter:
151 - sort_constructors_first 151 - sort_constructors_first
152 - sort_pub_dependencies 152 - sort_pub_dependencies
153 - sort_unnamed_constructors_first 153 - sort_unnamed_constructors_first
154 - - super_goes_last 154 + # - super_goes_last # no longer needed w/ Dart 2
155 - test_types_in_equals 155 - test_types_in_equals
156 - throw_in_finally 156 - throw_in_finally
157 # - type_annotate_public_apis # subset of always_specify_types 157 # - type_annotate_public_apis # subset of always_specify_types
@@ -4,22 +4,24 @@ import 'package:pdf/pdf.dart'; @@ -4,22 +4,24 @@ import 'package:pdf/pdf.dart';
4 import 'package:pdf/widgets.dart'; 4 import 'package:pdf/widgets.dart';
5 5
6 void main() { 6 void main() {
7 - final pdf = Document(deflate: zlib.encode); 7 + final Document pdf = Document(deflate: zlib.encode);
8 8
9 pdf.addPage(MultiPage( 9 pdf.addPage(MultiPage(
10 pageFormat: 10 pageFormat:
11 PdfPageFormat.letter.copyWith(marginBottom: 1.5 * PdfPageFormat.cm), 11 PdfPageFormat.letter.copyWith(marginBottom: 1.5 * PdfPageFormat.cm),
12 crossAxisAlignment: CrossAxisAlignment.start, 12 crossAxisAlignment: CrossAxisAlignment.start,
13 header: (Context context) { 13 header: (Context context) {
14 - if (context.pageNumber == 1) return null; 14 + if (context.pageNumber == 1) {
  15 + return null;
  16 + }
15 return Container( 17 return Container(
16 alignment: Alignment.centerRight, 18 alignment: Alignment.centerRight,
17 - margin: EdgeInsets.only(bottom: 3.0 * PdfPageFormat.mm),  
18 - padding: EdgeInsets.only(bottom: 3.0 * PdfPageFormat.mm),  
19 - decoration: BoxDecoration( 19 + margin: const EdgeInsets.only(bottom: 3.0 * PdfPageFormat.mm),
  20 + padding: const EdgeInsets.only(bottom: 3.0 * PdfPageFormat.mm),
  21 + decoration: const BoxDecoration(
20 border: 22 border:
21 BoxBorder(bottom: true, width: 0.5, color: PdfColor.grey)), 23 BoxBorder(bottom: true, width: 0.5, color: PdfColor.grey)),
22 - child: Text("Portable Document Format", 24 + child: Text('Portable Document Format',
23 style: Theme.of(context) 25 style: Theme.of(context)
24 .defaultTextStyle 26 .defaultTextStyle
25 .copyWith(color: PdfColor.grey))); 27 .copyWith(color: PdfColor.grey)));
@@ -27,8 +29,8 @@ void main() { @@ -27,8 +29,8 @@ void main() {
27 footer: (Context context) { 29 footer: (Context context) {
28 return Container( 30 return Container(
29 alignment: Alignment.centerRight, 31 alignment: Alignment.centerRight,
30 - margin: EdgeInsets.only(top: 1.0 * PdfPageFormat.cm),  
31 - child: Text("Page ${context.pageNumber}", 32 + margin: const EdgeInsets.only(top: 1.0 * PdfPageFormat.cm),
  33 + child: Text('Page ${context.pageNumber}',
32 style: Theme.of(context) 34 style: Theme.of(context)
33 .defaultTextStyle 35 .defaultTextStyle
34 .copyWith(color: PdfColor.grey))); 36 .copyWith(color: PdfColor.grey)));
@@ -39,111 +41,111 @@ void main() { @@ -39,111 +41,111 @@ void main() {
39 child: Row( 41 child: Row(
40 mainAxisAlignment: MainAxisAlignment.spaceBetween, 42 mainAxisAlignment: MainAxisAlignment.spaceBetween,
41 children: <Widget>[ 43 children: <Widget>[
42 - Text("Portable Document Format", textScaleFactor: 2.0), 44 + Text('Portable Document Format', textScaleFactor: 2.0),
43 PdfLogo() 45 PdfLogo()
44 ])), 46 ])),
45 Paragraph( 47 Paragraph(
46 text: 48 text:
47 - "The Portable Document Format (PDF) is a file format developed by Adobe in the 1990s to present documents, including text formatting and images, in a manner independent of application software, hardware, and operating systems. Based on the PostScript language, each PDF file encapsulates a complete description of a fixed-layout flat document, including the text, fonts, vector graphics, raster images and other information needed to display it. PDF was standardized as an open format, ISO 32000, in 2008, and no longer requires any royalties for its implementation."), 49 + 'The Portable Document Format (PDF) is a file format developed by Adobe in the 1990s to present documents, including text formatting and images, in a manner independent of application software, hardware, and operating systems. Based on the PostScript language, each PDF file encapsulates a complete description of a fixed-layout flat document, including the text, fonts, vector graphics, raster images and other information needed to display it. PDF was standardized as an open format, ISO 32000, in 2008, and no longer requires any royalties for its implementation.'),
48 Paragraph( 50 Paragraph(
49 text: 51 text:
50 - "Today, PDF files may contain a variety of content besides flat text and graphics including logical structuring elements, interactive elements such as annotations and form-fields, layers, rich media (including video content) and three dimensional objects using U3D or PRC, and various other data formats.[citation needed] The PDF specification also provides for encryption and digital signatures, file attachments and metadata to enable workflows requiring these features."),  
51 - Header(level: 1, text: "History and standardization"), 52 + 'Today, PDF files may contain a variety of content besides flat text and graphics including logical structuring elements, interactive elements such as annotations and form-fields, layers, rich media (including video content) and three dimensional objects using U3D or PRC, and various other data formats.[citation needed] The PDF specification also provides for encryption and digital signatures, file attachments and metadata to enable workflows requiring these features.'),
  53 + Header(level: 1, text: 'History and standardization'),
52 Paragraph( 54 Paragraph(
53 text: 55 text:
54 "Adobe Systems made the PDF specification available free of charge in 1993. In the early years PDF was popular mainly in desktop publishing workflows, and competed with a variety of formats such as DjVu, Envoy, Common Ground Digital Paper, Farallon Replica and even Adobe's own PostScript format."), 56 "Adobe Systems made the PDF specification available free of charge in 1993. In the early years PDF was popular mainly in desktop publishing workflows, and competed with a variety of formats such as DjVu, Envoy, Common Ground Digital Paper, Farallon Replica and even Adobe's own PostScript format."),
55 Paragraph( 57 Paragraph(
56 text: 58 text:
57 - "PDF was a proprietary format controlled by Adobe until it was released as an open standard on July 1, 2008, and published by the International Organization for Standardization as ISO 32000-1:2008, at which time control of the specification passed to an ISO Committee of volunteer industry experts. In 2008, Adobe published a Public Patent License to ISO 32000-1 granting royalty-free rights for all patents owned by Adobe that are necessary to make, use, sell, and distribute PDF compliant implementations."), 59 + 'PDF was a proprietary format controlled by Adobe until it was released as an open standard on July 1, 2008, and published by the International Organization for Standardization as ISO 32000-1:2008, at which time control of the specification passed to an ISO Committee of volunteer industry experts. In 2008, Adobe published a Public Patent License to ISO 32000-1 granting royalty-free rights for all patents owned by Adobe that are necessary to make, use, sell, and distribute PDF compliant implementations.'),
58 Paragraph( 60 Paragraph(
59 text: 61 text:
60 "PDF 1.7, the sixth edition of the PDF specification that became ISO 32000-1, includes some proprietary technologies defined only by Adobe, such as Adobe XML Forms Architecture (XFA) and JavaScript extension for Acrobat, which are referenced by ISO 32000-1 as normative and indispensable for the full implementation of the ISO 32000-1 specification. These proprietary technologies are not standardized and their specification is published only on Adobe's website. Many of them are also not supported by popular third-party implementations of PDF."), 62 "PDF 1.7, the sixth edition of the PDF specification that became ISO 32000-1, includes some proprietary technologies defined only by Adobe, such as Adobe XML Forms Architecture (XFA) and JavaScript extension for Acrobat, which are referenced by ISO 32000-1 as normative and indispensable for the full implementation of the ISO 32000-1 specification. These proprietary technologies are not standardized and their specification is published only on Adobe's website. Many of them are also not supported by popular third-party implementations of PDF."),
61 Paragraph( 63 Paragraph(
62 text: 64 text:
63 - "On July 28, 2017, ISO 32000-2:2017 (PDF 2.0) was published. ISO 32000-2 does not include any proprietary technologies as normative references."),  
64 - Header(level: 1, text: "Technical foundations"),  
65 - Paragraph(text: "The PDF combines three technologies:"), 65 + 'On July 28, 2017, ISO 32000-2:2017 (PDF 2.0) was published. ISO 32000-2 does not include any proprietary technologies as normative references.'),
  66 + Header(level: 1, text: 'Technical foundations'),
  67 + Paragraph(text: 'The PDF combines three technologies:'),
66 Bullet( 68 Bullet(
67 text: 69 text:
68 - "A subset of the PostScript page description programming language, for generating the layout and graphics."), 70 + 'A subset of the PostScript page description programming language, for generating the layout and graphics.'),
69 Bullet( 71 Bullet(
70 text: 72 text:
71 - "A font-embedding/replacement system to allow fonts to travel with the documents."), 73 + 'A font-embedding/replacement system to allow fonts to travel with the documents.'),
72 Bullet( 74 Bullet(
73 text: 75 text:
74 - "A structured storage system to bundle these elements and any associated content into a single file, with data compression where appropriate."),  
75 - Header(level: 2, text: "PostScript"), 76 + 'A structured storage system to bundle these elements and any associated content into a single file, with data compression where appropriate.'),
  77 + Header(level: 2, text: 'PostScript'),
76 Paragraph( 78 Paragraph(
77 text: 79 text:
78 - "PostScript is a page description language run in an interpreter to generate an image, a process requiring many resources. It can handle graphics and standard features of programming languages such as if and loop commands. PDF is largely based on PostScript but simplified to remove flow control features like these, while graphics commands such as lineto remain."), 80 + 'PostScript is a page description language run in an interpreter to generate an image, a process requiring many resources. It can handle graphics and standard features of programming languages such as if and loop commands. PDF is largely based on PostScript but simplified to remove flow control features like these, while graphics commands such as lineto remain.'),
79 Paragraph( 81 Paragraph(
80 text: 82 text:
81 - "Often, the PostScript-like PDF code is generated from a source PostScript file. The graphics commands that are output by the PostScript code are collected and tokenized. Any files, graphics, or fonts to which the document refers also are collected. Then, everything is compressed to a single file. Therefore, the entire PostScript world (fonts, layout, measurements) remains intact."), 83 + 'Often, the PostScript-like PDF code is generated from a source PostScript file. The graphics commands that are output by the PostScript code are collected and tokenized. Any files, graphics, or fonts to which the document refers also are collected. Then, everything is compressed to a single file. Therefore, the entire PostScript world (fonts, layout, measurements) remains intact.'),
82 Column( 84 Column(
83 crossAxisAlignment: CrossAxisAlignment.start, 85 crossAxisAlignment: CrossAxisAlignment.start,
84 children: <Widget>[ 86 children: <Widget>[
85 Paragraph( 87 Paragraph(
86 text: 88 text:
87 - "As a document format, PDF has several advantages over PostScript:"), 89 + 'As a document format, PDF has several advantages over PostScript:'),
88 Bullet( 90 Bullet(
89 text: 91 text:
90 - "PDF contains tokenized and interpreted results of the PostScript source code, for direct correspondence between changes to items in the PDF page description and changes to the resulting page appearance."), 92 + 'PDF contains tokenized and interpreted results of the PostScript source code, for direct correspondence between changes to items in the PDF page description and changes to the resulting page appearance.'),
91 Bullet( 93 Bullet(
92 text: 94 text:
93 - "PDF (from version 1.4) supports graphic transparency; PostScript does not."), 95 + 'PDF (from version 1.4) supports graphic transparency; PostScript does not.'),
94 Bullet( 96 Bullet(
95 text: 97 text:
96 - "PostScript is an interpreted programming language with an implicit global state, so instructions accompanying the description of one page can affect the appearance of any following page. Therefore, all preceding pages in a PostScript document must be processed to determine the correct appearance of a given page, whereas each page in a PDF document is unaffected by the others. As a result, PDF viewers allow the user to quickly jump to the final pages of a long document, whereas a PostScript viewer needs to process all pages sequentially before being able to display the destination page (unless the optional PostScript Document Structuring Conventions have been carefully complied with)."), 98 + 'PostScript is an interpreted programming language with an implicit global state, so instructions accompanying the description of one page can affect the appearance of any following page. Therefore, all preceding pages in a PostScript document must be processed to determine the correct appearance of a given page, whereas each page in a PDF document is unaffected by the others. As a result, PDF viewers allow the user to quickly jump to the final pages of a long document, whereas a PostScript viewer needs to process all pages sequentially before being able to display the destination page (unless the optional PostScript Document Structuring Conventions have been carefully complied with).'),
97 ]), 99 ]),
98 - Header(level: 1, text: "Content"), 100 + Header(level: 1, text: 'Content'),
99 Paragraph( 101 Paragraph(
100 text: 102 text:
101 - "A PDF file is often a combination of vector graphics, text, and bitmap graphics. The basic types of content in a PDF are:"), 103 + 'A PDF file is often a combination of vector graphics, text, and bitmap graphics. The basic types of content in a PDF are:'),
102 Bullet( 104 Bullet(
103 text: 105 text:
104 - "Text stored as content streams (i.e., not encoded in plain text)"), 106 + 'Text stored as content streams (i.e., not encoded in plain text)'),
105 Bullet( 107 Bullet(
106 text: 108 text:
107 - "Vector graphics for illustrations and designs that consist of shapes and lines"), 109 + 'Vector graphics for illustrations and designs that consist of shapes and lines'),
108 Bullet( 110 Bullet(
109 text: 111 text:
110 - "Raster graphics for photographs and other types of image"),  
111 - Bullet(text: "Multimedia objects in the document"), 112 + 'Raster graphics for photographs and other types of image'),
  113 + Bullet(text: 'Multimedia objects in the document'),
112 Paragraph( 114 Paragraph(
113 text: 115 text:
114 - "In later PDF revisions, a PDF document can also support links (inside document or web page), forms, JavaScript (initially available as plugin for Acrobat 3.0), or any other types of embedded contents that can be handled using plug-ins."), 116 + 'In later PDF revisions, a PDF document can also support links (inside document or web page), forms, JavaScript (initially available as plugin for Acrobat 3.0), or any other types of embedded contents that can be handled using plug-ins.'),
115 Paragraph( 117 Paragraph(
116 text: 118 text:
117 - "PDF 1.6 supports interactive 3D documents embedded in the PDF - 3D drawings can be embedded using U3D or PRC and various other data formats."), 119 + 'PDF 1.6 supports interactive 3D documents embedded in the PDF - 3D drawings can be embedded using U3D or PRC and various other data formats.'),
118 Paragraph( 120 Paragraph(
119 text: 121 text:
120 - "Two PDF files that look similar on a computer screen may be of very different sizes. For example, a high resolution raster image takes more space than a low resolution one. Typically higher resolution is needed for printing documents than for displaying them on screen. Other things that may increase the size of a file is embedding full fonts, especially for Asiatic scripts, and storing text as graphics. "),  
121 - Header(level: 1, text: "File formats and Adobe Acrobat versions"), 122 + 'Two PDF files that look similar on a computer screen may be of very different sizes. For example, a high resolution raster image takes more space than a low resolution one. Typically higher resolution is needed for printing documents than for displaying them on screen. Other things that may increase the size of a file is embedding full fonts, especially for Asiatic scripts, and storing text as graphics. '),
  123 + Header(level: 1, text: 'File formats and Adobe Acrobat versions'),
122 Paragraph( 124 Paragraph(
123 text: 125 text:
124 - "The PDF file format has changed several times, and continues to evolve, along with the release of new versions of Adobe Acrobat. There have been nine versions of PDF and the corresponding version of the software:"),  
125 - Table.fromTextArray(context: context, data: [  
126 - ["Date", "PDF Version", "Acrobat Version"],  
127 - ["1993", "PDF 1.0", "Acrobat 1"],  
128 - ["1994", "PDF 1.1", "Acrobat 2"],  
129 - ["1996", "PDF 1.2", "Acrobat 3"],  
130 - ["1999", "PDF 1.3", "Acrobat 4"],  
131 - ["2001", "PDF 1.4", "Acrobat 5"],  
132 - ["2003", "PDF 1.5", "Acrobat 6"],  
133 - ["2005", "PDF 1.6", "Acrobat 7"],  
134 - ["2006", "PDF 1.7", "Acrobat 8"],  
135 - ["2008", "PDF 1.7", "Acrobat 9"],  
136 - ["2009", "PDF 1.7", "Acrobat 9.1"],  
137 - ["2010", "PDF 1.7", "Acrobat X"],  
138 - ["2012", "PDF 1.7", "Acrobat XI"],  
139 - ["2017", "PDF 2.0", "Acrobat DC"], 126 + 'The PDF file format has changed several times, and continues to evolve, along with the release of new versions of Adobe Acrobat. There have been nine versions of PDF and the corresponding version of the software:'),
  127 + Table.fromTextArray(context: context, data: const <List<String>>[
  128 + <String>['Date', 'PDF Version', 'Acrobat Version'],
  129 + <String>['1993', 'PDF 1.0', 'Acrobat 1'],
  130 + <String>['1994', 'PDF 1.1', 'Acrobat 2'],
  131 + <String>['1996', 'PDF 1.2', 'Acrobat 3'],
  132 + <String>['1999', 'PDF 1.3', 'Acrobat 4'],
  133 + <String>['2001', 'PDF 1.4', 'Acrobat 5'],
  134 + <String>['2003', 'PDF 1.5', 'Acrobat 6'],
  135 + <String>['2005', 'PDF 1.6', 'Acrobat 7'],
  136 + <String>['2006', 'PDF 1.7', 'Acrobat 8'],
  137 + <String>['2008', 'PDF 1.7', 'Acrobat 9'],
  138 + <String>['2009', 'PDF 1.7', 'Acrobat 9.1'],
  139 + <String>['2010', 'PDF 1.7', 'Acrobat X'],
  140 + <String>['2012', 'PDF 1.7', 'Acrobat XI'],
  141 + <String>['2017', 'PDF 2.0', 'Acrobat DC'],
140 ]), 142 ]),
141 - Padding(padding: EdgeInsets.all(10)), 143 + Padding(padding: const EdgeInsets.all(10)),
142 Paragraph( 144 Paragraph(
143 text: 145 text:
144 - "Text is available under the Creative Commons Attribution Share Alike License.") 146 + 'Text is available under the Creative Commons Attribution Share Alike License.')
145 ])); 147 ]));
146 148
147 - var file = File('example.pdf'); 149 + final File file = File('example.pdf');
148 file.writeAsBytesSync(pdf.document.save()); 150 file.writeAsBytesSync(pdf.document.save());
149 } 151 }
@@ -17,8 +17,8 @@ @@ -17,8 +17,8 @@
17 library pdf; 17 library pdf;
18 18
19 import 'dart:convert'; 19 import 'dart:convert';
20 -import 'dart:typed_data';  
21 import 'dart:math' as math; 20 import 'dart:math' as math;
  21 +import 'dart:typed_data';
22 22
23 import 'package:meta/meta.dart'; 23 import 'package:meta/meta.dart';
24 import 'package:utf/utf.dart'; 24 import 'package:utf/utf.dart';
@@ -17,25 +17,6 @@ @@ -17,25 +17,6 @@
17 part of pdf; 17 part of pdf;
18 18
19 class PdfAnnot extends PdfObject { 19 class PdfAnnot extends PdfObject {
20 - /// The subtype of the outline, ie text, note, etc  
21 - final String subtype;  
22 -  
23 - /// The size of the annotation  
24 - final PdfRect srcRect;  
25 -  
26 - /// The text of a text annotation  
27 - final String content;  
28 -  
29 - /// Link to the Destination page  
30 - final PdfObject dest;  
31 -  
32 - /// If destRect is null then this is the region of the destination page shown.  
33 - /// Otherwise they are ignored.  
34 - final PdfRect destRect;  
35 -  
36 - /// the border for this annotation  
37 - final PdfBorder border;  
38 -  
39 PdfAnnot._create(PdfPage pdfPage, 20 PdfAnnot._create(PdfPage pdfPage,
40 {String type, 21 {String type,
41 this.content, 22 this.content,
@@ -56,7 +37,7 @@ class PdfAnnot extends PdfObject { @@ -56,7 +37,7 @@ class PdfAnnot extends PdfObject {
56 @required String content, 37 @required String content,
57 PdfBorder border}) => 38 PdfBorder border}) =>
58 PdfAnnot._create(pdfPage, 39 PdfAnnot._create(pdfPage,
59 - subtype: "/Text", srcRect: rect, content: content, border: border); 40 + subtype: '/Text', srcRect: rect, content: content, border: border);
60 41
61 /// Creates a link annotation 42 /// Creates a link annotation
62 /// @param srcRect coordinates 43 /// @param srcRect coordinates
@@ -69,12 +50,31 @@ class PdfAnnot extends PdfObject { @@ -69,12 +50,31 @@ class PdfAnnot extends PdfObject {
69 PdfRect destRect, 50 PdfRect destRect,
70 PdfBorder border}) => 51 PdfBorder border}) =>
71 PdfAnnot._create(pdfPage, 52 PdfAnnot._create(pdfPage,
72 - subtype: "/Link", 53 + subtype: '/Link',
73 srcRect: srcRect, 54 srcRect: srcRect,
74 dest: dest, 55 dest: dest,
75 destRect: destRect, 56 destRect: destRect,
76 border: border); 57 border: border);
77 58
  59 + /// The subtype of the outline, ie text, note, etc
  60 + final String subtype;
  61 +
  62 + /// The size of the annotation
  63 + final PdfRect srcRect;
  64 +
  65 + /// The text of a text annotation
  66 + final String content;
  67 +
  68 + /// Link to the Destination page
  69 + final PdfObject dest;
  70 +
  71 + /// If destRect is null then this is the region of the destination page shown.
  72 + /// Otherwise they are ignored.
  73 + final PdfRect destRect;
  74 +
  75 + /// the border for this annotation
  76 + final PdfBorder border;
  77 +
78 /// Output the annotation 78 /// Output the annotation
79 /// 79 ///
80 /// @param os OutputStream to send the object to 80 /// @param os OutputStream to send the object to
@@ -82,30 +82,30 @@ class PdfAnnot extends PdfObject { @@ -82,30 +82,30 @@ class PdfAnnot extends PdfObject {
82 void _prepare() { 82 void _prepare() {
83 super._prepare(); 83 super._prepare();
84 84
85 - params["/Subtype"] = PdfStream.string(subtype);  
86 - params["/Rect"] = PdfStream.string(  
87 - "[${srcRect.left} ${srcRect.bottom} ${srcRect.right} ${srcRect.top}]"); 85 + params['/Subtype'] = PdfStream.string(subtype);
  86 + params['/Rect'] = PdfStream.string(
  87 + '[${srcRect.left} ${srcRect.bottom} ${srcRect.right} ${srcRect.top}]');
88 88
89 // handle the border 89 // handle the border
90 if (border == null) { 90 if (border == null) {
91 - params["/Border"] = PdfStream.string("[0 0 0]"); 91 + params['/Border'] = PdfStream.string('[0 0 0]');
92 } else { 92 } else {
93 - params["/BS"] = border.ref(); 93 + params['/BS'] = border.ref();
94 } 94 }
95 95
96 // Now the annotation subtypes 96 // Now the annotation subtypes
97 - if (subtype == "/Text") {  
98 - params["/Contents"] = PdfStream()..putLiteral(content);  
99 - } else if (subtype == "/Link") {  
100 - var dests = List<PdfStream>(); 97 + if (subtype == '/Text') {
  98 + params['/Contents'] = PdfStream()..putLiteral(content);
  99 + } else if (subtype == '/Link') {
  100 + final List<PdfStream> dests = <PdfStream>[];
101 dests.add(dest.ref()); 101 dests.add(dest.ref());
102 if (destRect == null) 102 if (destRect == null)
103 - dests.add(PdfStream.string("/Fit")); 103 + dests.add(PdfStream.string('/Fit'));
104 else { 104 else {
105 dests.add(PdfStream.string( 105 dests.add(PdfStream.string(
106 - "/FitR ${destRect.left} ${destRect.bottom} ${destRect.right} ${destRect.top}")); 106 + '/FitR ${destRect.left} ${destRect.bottom} ${destRect.right} ${destRect.top}'));
107 } 107 }
108 - params["/Dest"] = PdfStream.array(dests); 108 + params['/Dest'] = PdfStream.array(dests);
109 } 109 }
110 } 110 }
111 } 111 }
@@ -17,10 +17,10 @@ @@ -17,10 +17,10 @@
17 part of pdf; 17 part of pdf;
18 18
19 class PdfArrayObject extends PdfObject { 19 class PdfArrayObject extends PdfObject {
20 - final List<String> values;  
21 -  
22 PdfArrayObject(PdfDocument pdfDocument, this.values) : super(pdfDocument); 20 PdfArrayObject(PdfDocument pdfDocument, this.values) : super(pdfDocument);
23 21
  22 + final List<String> values;
  23 +
24 @override 24 @override
25 void _writeContent(PdfStream os) { 25 void _writeContent(PdfStream os) {
26 super._writeContent(os); 26 super._writeContent(os);
@@ -17,11 +17,12 @@ @@ -17,11 +17,12 @@
17 part of pdf; 17 part of pdf;
18 18
19 class Ascii85Encoder extends Converter<List<int>, List<int>> { 19 class Ascii85Encoder extends Converter<List<int>, List<int>> {
  20 + @override
20 List<int> convert(List<int> input) { 21 List<int> convert(List<int> input) {
21 - Uint8List buffer = Uint8List(_maxEncodedLen(input.length) + 2); 22 + final Uint8List buffer = Uint8List(_maxEncodedLen(input.length) + 2);
22 23
23 - var b = 0;  
24 - var s = 0; 24 + int b = 0;
  25 + int s = 0;
25 26
26 while (s < input.length) { 27 while (s < input.length) {
27 buffer[b + 0] = 0; 28 buffer[b + 0] = 0;
@@ -68,7 +69,7 @@ class Ascii85Encoder extends Converter<List<int>, List<int>> { @@ -68,7 +69,7 @@ class Ascii85Encoder extends Converter<List<int>, List<int>> {
68 } 69 }
69 70
70 // If input was short, discard the low destination bytes. 71 // If input was short, discard the low destination bytes.
71 - var m = 5; 72 + int m = 5;
72 if (input.length - s < 4) { 73 if (input.length - s < 4) {
73 m -= 4 - (input.length - s); 74 m -= 4 - (input.length - s);
74 break; 75 break;
1 /* 1 /*
2 * Copyright (C) 2017, David PHAM-VAN <dev.nfet.net@gmail.com> 2 * Copyright (C) 2017, David PHAM-VAN <dev.nfet.net@gmail.com>
3 * 3 *
4 - * Licensed under the Apache License, Version 2.0 (the "License"); 4 + * Licensed under the Apache License, Version 2.0 (the 'License');
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at 6 * You may obtain a copy of the License at
7 * 7 *
8 * http://www.apache.org/licenses/LICENSE-2.0 8 * http://www.apache.org/licenses/LICENSE-2.0
9 * 9 *
10 * Unless required by applicable law or agreed to in writing, software 10 * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS, 11 + * distributed under the License is distributed on an 'AS IS' BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
@@ -36,15 +36,6 @@ enum PdfBorderStyle { @@ -36,15 +36,6 @@ enum PdfBorderStyle {
36 } 36 }
37 37
38 class PdfBorder extends PdfObject { 38 class PdfBorder extends PdfObject {
39 - /// The style of the border  
40 - final PdfBorderStyle style;  
41 -  
42 - /// The width of the border  
43 - final double width;  
44 -  
45 - /// This array allows the definition of a dotted line for the border  
46 - final List<double> dash;  
47 -  
48 /// Creates a border using the predefined styles in [PdfAnnot]. 39 /// Creates a border using the predefined styles in [PdfAnnot].
49 /// Note: Do not use [PdfAnnot.dashed] with this method. 40 /// Note: Do not use [PdfAnnot.dashed] with this method.
50 /// Use the other constructor. 41 /// Use the other constructor.
@@ -57,18 +48,27 @@ class PdfBorder extends PdfObject { @@ -57,18 +48,27 @@ class PdfBorder extends PdfObject {
57 {this.style = PdfBorderStyle.solid, this.dash}) 48 {this.style = PdfBorderStyle.solid, this.dash})
58 : super(pdfDocument); 49 : super(pdfDocument);
59 50
  51 + /// The style of the border
  52 + final PdfBorderStyle style;
  53 +
  54 + /// The width of the border
  55 + final double width;
  56 +
  57 + /// This array allows the definition of a dotted line for the border
  58 + final List<double> dash;
  59 +
60 /// @param os OutputStream to send the object to 60 /// @param os OutputStream to send the object to
61 @override 61 @override
62 void _writeContent(PdfStream os) { 62 void _writeContent(PdfStream os) {
63 super._writeContent(os); 63 super._writeContent(os);
64 64
65 - var data = List<PdfStream>();  
66 - data.add(PdfStream.string("/S")); 65 + final List<PdfStream> data = <PdfStream>[];
  66 + data.add(PdfStream.string('/S'));
67 data.add(PdfStream.string( 67 data.add(PdfStream.string(
68 - "/" + "SDBIU".substring(style.index, style.index + 1)));  
69 - data.add(PdfStream.string("/W $width")); 68 + '/' + 'SDBIU'.substring(style.index, style.index + 1)));
  69 + data.add(PdfStream.string('/W $width'));
70 if (dash != null) { 70 if (dash != null) {
71 - data.add(PdfStream.string("/D")); 71 + data.add(PdfStream.string('/D'));
72 data.add(PdfStream.array(dash.map((double d) => PdfStream.num(d)))); 72 data.add(PdfStream.array(dash.map((double d) => PdfStream.num(d))));
73 } 73 }
74 os.putArray(data); 74 os.putArray(data);
1 /* 1 /*
2 * Copyright (C) 2017, David PHAM-VAN <dev.nfet.net@gmail.com> 2 * Copyright (C) 2017, David PHAM-VAN <dev.nfet.net@gmail.com>
3 * 3 *
4 - * Licensed under the Apache License, Version 2.0 (the "License"); 4 + * Licensed under the Apache License, Version 2.0 (the 'License');
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at 6 * You may obtain a copy of the License at
7 * 7 *
8 * http://www.apache.org/licenses/LICENSE-2.0 8 * http://www.apache.org/licenses/LICENSE-2.0
9 * 9 *
10 * Unless required by applicable law or agreed to in writing, software 10 * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS, 11 + * distributed under the License is distributed on an 'AS IS' BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
@@ -17,6 +17,14 @@ @@ -17,6 +17,14 @@
17 part of pdf; 17 part of pdf;
18 18
19 class PdfCatalog extends PdfObject { 19 class PdfCatalog extends PdfObject {
  20 + /// This constructs a Pdf Catalog object
  21 + ///
  22 + /// @param pdfPageList The [PdfPageList] object that's the root of the documents page tree
  23 + /// @param pagemode How the document should appear when opened.
  24 + /// Allowed values are usenone, useoutlines, usethumbs or fullscreen.
  25 + PdfCatalog(PdfDocument pdfDocument, this.pdfPageList, this.pageMode)
  26 + : super(pdfDocument, '/Catalog');
  27 +
20 /// The pages of the document 28 /// The pages of the document
21 final PdfPageList pdfPageList; 29 final PdfPageList pdfPageList;
22 30
@@ -26,28 +34,20 @@ class PdfCatalog extends PdfObject { @@ -26,28 +34,20 @@ class PdfCatalog extends PdfObject {
26 /// The initial page mode 34 /// The initial page mode
27 final PdfPageMode pageMode; 35 final PdfPageMode pageMode;
28 36
29 - /// This constructs a Pdf Catalog object  
30 - ///  
31 - /// @param pdfPageList The [PdfPageList] object that's the root of the documents page tree  
32 - /// @param pagemode How the document should appear when opened.  
33 - /// Allowed values are usenone, useoutlines, usethumbs or fullscreen.  
34 - PdfCatalog(PdfDocument pdfDocument, this.pdfPageList, this.pageMode)  
35 - : super(pdfDocument, "/Catalog");  
36 -  
37 /// @param os OutputStream to send the object to 37 /// @param os OutputStream to send the object to
38 @override 38 @override
39 void _prepare() { 39 void _prepare() {
40 super._prepare(); 40 super._prepare();
41 41
42 - params["/Pages"] = pdfPageList.ref(); 42 + params['/Pages'] = pdfPageList.ref();
43 43
44 // the Outlines object 44 // the Outlines object
45 if (outlines != null && outlines.outlines.isNotEmpty) { 45 if (outlines != null && outlines.outlines.isNotEmpty) {
46 - params["/Outlines"] = outlines.ref(); 46 + params['/Outlines'] = outlines.ref();
47 } 47 }
48 48
49 // the /PageMode setting 49 // the /PageMode setting
50 - params["/PageMode"] = 50 + params['/PageMode'] =
51 PdfStream.string(PdfDocument._PdfPageModes[pageMode.index]); 51 PdfStream.string(PdfDocument._PdfPageModes[pageMode.index]);
52 } 52 }
53 } 53 }
@@ -17,33 +17,6 @@ @@ -17,33 +17,6 @@
17 part of pdf; 17 part of pdf;
18 18
19 class PdfColor { 19 class PdfColor {
20 - final double a;  
21 - final double r;  
22 - final double g;  
23 - final double b;  
24 -  
25 - static const black = PdfColor(0.0, 0.0, 0.0);  
26 - static const white = PdfColor(1.0, 1.0, 1.0);  
27 - static const red = PdfColor(0.95686, 0.26274, 0.21176);  
28 - static const pink = PdfColor(0.91372, 0.11764, 0.38823);  
29 - static const purple = PdfColor(0.91372, 0.11764, 0.38823);  
30 - static const deepPurple = PdfColor(0.40392, 0.22745, 0.71765);  
31 - static const indigo = PdfColor(0.24705, 0.31765, 0.70980);  
32 - static const blue = PdfColor(0.12941, 0.58823, 0.95294);  
33 - static const lightBlue = PdfColor(0.01176, 0.66274, 0.95686);  
34 - static const cyan = PdfColor(0.0, 0.73725, 0.83137);  
35 - static const teal = PdfColor(0.0, 0.58823, 0.53333);  
36 - static const green = PdfColor(0.29803, 0.68627, 0.31372);  
37 - static const lightGreen = PdfColor(0.54509, 0.76470, 0.29020);  
38 - static const lime = PdfColor(0.80392, 0.86274, 0.22353);  
39 - static const yellow = PdfColor(1.0, 0.92157, 0.23137);  
40 - static const amber = PdfColor(1.0, 0.75686, 0.02745);  
41 - static const orange = PdfColor(1.0, 0.59608, 0.0);  
42 - static const deepOrange = PdfColor(1.0, 0.34118, 0.13333);  
43 - static const brown = PdfColor(0.47451, 0.33333, 0.28235);  
44 - static const grey = PdfColor(0.61961, 0.61961, 0.61961);  
45 - static const blueGrey = PdfColor(0.37647, 0.49020, 0.54510);  
46 -  
47 const PdfColor(this.r, this.g, this.b, [this.a = 1.0]); 20 const PdfColor(this.r, this.g, this.b, [this.a = 1.0]);
48 21
49 const PdfColor.fromInt(int color) 22 const PdfColor.fromInt(int color)
@@ -60,6 +33,33 @@ class PdfColor { @@ -60,6 +33,33 @@ class PdfColor {
60 (int.parse(color.substring(6, 7), radix: 16) >> 24 & 0xff) / 255.0); 33 (int.parse(color.substring(6, 7), radix: 16) >> 24 & 0xff) / 255.0);
61 } 34 }
62 35
  36 + final double a;
  37 + final double r;
  38 + final double g;
  39 + final double b;
  40 +
  41 + static const PdfColor black = PdfColor(0.0, 0.0, 0.0);
  42 + static const PdfColor white = PdfColor(1.0, 1.0, 1.0);
  43 + static const PdfColor red = PdfColor(0.95686, 0.26274, 0.21176);
  44 + static const PdfColor pink = PdfColor(0.91372, 0.11764, 0.38823);
  45 + static const PdfColor purple = PdfColor(0.91372, 0.11764, 0.38823);
  46 + static const PdfColor deepPurple = PdfColor(0.40392, 0.22745, 0.71765);
  47 + static const PdfColor indigo = PdfColor(0.24705, 0.31765, 0.70980);
  48 + static const PdfColor blue = PdfColor(0.12941, 0.58823, 0.95294);
  49 + static const PdfColor lightBlue = PdfColor(0.01176, 0.66274, 0.95686);
  50 + static const PdfColor cyan = PdfColor(0.0, 0.73725, 0.83137);
  51 + static const PdfColor teal = PdfColor(0.0, 0.58823, 0.53333);
  52 + static const PdfColor green = PdfColor(0.29803, 0.68627, 0.31372);
  53 + static const PdfColor lightGreen = PdfColor(0.54509, 0.76470, 0.29020);
  54 + static const PdfColor lime = PdfColor(0.80392, 0.86274, 0.22353);
  55 + static const PdfColor yellow = PdfColor(1.0, 0.92157, 0.23137);
  56 + static const PdfColor amber = PdfColor(1.0, 0.75686, 0.02745);
  57 + static const PdfColor orange = PdfColor(1.0, 0.59608, 0.0);
  58 + static const PdfColor deepOrange = PdfColor(1.0, 0.34118, 0.13333);
  59 + static const PdfColor brown = PdfColor(0.47451, 0.33333, 0.28235);
  60 + static const PdfColor grey = PdfColor(0.61961, 0.61961, 0.61961);
  61 + static const PdfColor blueGrey = PdfColor(0.37647, 0.49020, 0.54510);
  62 +
63 int toInt() => 63 int toInt() =>
64 ((((a * 255.0).round() & 0xff) << 24) | 64 ((((a * 255.0).round() & 0xff) << 24) |
65 (((r * 255.0).round() & 0xff) << 16) | 65 (((r * 255.0).round() & 0xff) << 16) |
@@ -80,7 +80,9 @@ class PdfColor { @@ -80,7 +80,9 @@ class PdfColor {
80 } 80 }
81 81
82 static double _linearizeColorComponent(double component) { 82 static double _linearizeColorComponent(double component) {
83 - if (component <= 0.03928) return component / 12.92; 83 + if (component <= 0.03928) {
  84 + return component / 12.92;
  85 + }
84 return math.pow((component + 0.055) / 1.055, 2.4); 86 return math.pow((component + 0.055) / 1.055, 2.4);
85 } 87 }
86 88
@@ -91,21 +93,14 @@ class PdfColor { @@ -91,21 +93,14 @@ class PdfColor {
91 return 0.2126 * R + 0.7152 * G + 0.0722 * B; 93 return 0.2126 * R + 0.7152 * G + 0.0722 * B;
92 } 94 }
93 95
94 - String toString() => "$runtimeType($r, $g, $b, $a)"; 96 + @override
  97 + String toString() => '$runtimeType($r, $g, $b, $a)';
95 } 98 }
96 99
97 class PdfColorCmyk extends PdfColor { 100 class PdfColorCmyk extends PdfColor {
98 - final double c;  
99 - final double m;  
100 - final double y;  
101 - final double k;  
102 -  
103 const PdfColorCmyk(this.c, this.m, this.y, this.k, [double a = 1.0]) 101 const PdfColorCmyk(this.c, this.m, this.y, this.k, [double a = 1.0])
104 - : super(  
105 - (1.0 - c) * (1.0 - k),  
106 - (1.0 - m) * (1.0 - k),  
107 - (1.0 - y) * (1.0 - k),  
108 - ); 102 + : super((1.0 - c) * (1.0 - k), (1.0 - m) * (1.0 - k),
  103 + (1.0 - y) * (1.0 - k), a);
109 104
110 const PdfColorCmyk.fromRgb(double r, double g, double b, [double a = 1.0]) 105 const PdfColorCmyk.fromRgb(double r, double g, double b, [double a = 1.0])
111 : k = 1.0 - r > g ? r : g > b ? r > g ? r : g : b, 106 : k = 1.0 - r > g ? r : g > b ? r > g ? r : g : b,
@@ -117,12 +112,18 @@ class PdfColorCmyk extends PdfColor { @@ -117,12 +112,18 @@ class PdfColorCmyk extends PdfColor {
117 (1.0 - (1.0 - r > g ? r : g > b ? r > g ? r : g : b)), 112 (1.0 - (1.0 - r > g ? r : g > b ? r > g ? r : g : b)),
118 super(r, g, b, a); 113 super(r, g, b, a);
119 114
  115 + final double c;
  116 + final double m;
  117 + final double y;
  118 + final double k;
  119 +
120 @override 120 @override
121 PdfColorCmyk toCmyk() { 121 PdfColorCmyk toCmyk() {
122 return this; 122 return this;
123 } 123 }
124 124
125 - String toString() => "$runtimeType($c, $m, $y, $k, $a)"; 125 + @override
  126 + String toString() => '$runtimeType($c, $m, $y, $k, $a)';
126 } 127 }
127 128
128 double _getHue( 129 double _getHue(
@@ -144,14 +145,6 @@ double _getHue( @@ -144,14 +145,6 @@ double _getHue(
144 } 145 }
145 146
146 class PdfColorHsv extends PdfColor { 147 class PdfColorHsv extends PdfColor {
147 - final double hue;  
148 - final double saturation;  
149 - final double value;  
150 -  
151 - const PdfColorHsv._(this.hue, this.saturation, this.value, double red,  
152 - double green, double blue, double alpha)  
153 - : super(red, green, blue, alpha);  
154 -  
155 factory PdfColorHsv(double hue, double saturation, double value, 148 factory PdfColorHsv(double hue, double saturation, double value,
156 [double alpha = 1.0]) { 149 [double alpha = 1.0]) {
157 final double chroma = saturation * value; 150 final double chroma = saturation * value;
@@ -192,35 +185,36 @@ class PdfColorHsv extends PdfColor { @@ -192,35 +185,36 @@ class PdfColorHsv extends PdfColor {
192 blue + match, alpha); 185 blue + match, alpha);
193 } 186 }
194 187
  188 + const PdfColorHsv._(this.hue, this.saturation, this.value, double red,
  189 + double green, double blue, double alpha)
  190 + : super(red, green, blue, alpha);
  191 +
195 factory PdfColorHsv.fromRgb(double red, double green, double blue, 192 factory PdfColorHsv.fromRgb(double red, double green, double blue,
196 [double alpha]) { 193 [double alpha]) {
197 final double max = math.max(red, math.max(green, blue)); 194 final double max = math.max(red, math.max(green, blue));
198 final double min = math.min(red, math.min(green, blue)); 195 final double min = math.min(red, math.min(green, blue));
199 final double delta = max - min; 196 final double delta = max - min;
200 197
201 - final hue = _getHue(red, green, blue, max, delta); 198 + final double hue = _getHue(red, green, blue, max, delta);
202 final double saturation = max == 0.0 ? 0.0 : delta / max; 199 final double saturation = max == 0.0 ? 0.0 : delta / max;
203 200
204 return PdfColorHsv._(hue, saturation, max, red, green, blue, alpha); 201 return PdfColorHsv._(hue, saturation, max, red, green, blue, alpha);
205 } 202 }
206 203
  204 + final double hue;
  205 + final double saturation;
  206 + final double value;
  207 +
207 @override 208 @override
208 PdfColorHsv toHsv() { 209 PdfColorHsv toHsv() {
209 return this; 210 return this;
210 } 211 }
211 212
212 - String toString() => "$runtimeType($hue, $saturation, $value, $a)"; 213 + @override
  214 + String toString() => '$runtimeType($hue, $saturation, $value, $a)';
213 } 215 }
214 216
215 class PdfColorHsl extends PdfColor { 217 class PdfColorHsl extends PdfColor {
216 - final double hue;  
217 - final double saturation;  
218 - final double lightness;  
219 -  
220 - const PdfColorHsl._(this.hue, this.saturation, this.lightness, double alpha,  
221 - double red, double green, double blue)  
222 - : super(red, green, blue, alpha);  
223 -  
224 factory PdfColorHsl(double hue, double saturation, double lightness, 218 factory PdfColorHsl(double hue, double saturation, double lightness,
225 [double alpha]) { 219 [double alpha]) {
226 final double chroma = (1.0 - (2.0 * lightness - 1.0).abs()) * saturation; 220 final double chroma = (1.0 - (2.0 * lightness - 1.0).abs()) * saturation;
@@ -260,6 +254,10 @@ class PdfColorHsl extends PdfColor { @@ -260,6 +254,10 @@ class PdfColorHsl extends PdfColor {
260 green + match, blue + match); 254 green + match, blue + match);
261 } 255 }
262 256
  257 + const PdfColorHsl._(this.hue, this.saturation, this.lightness, double alpha,
  258 + double red, double green, double blue)
  259 + : super(red, green, blue, alpha);
  260 +
263 factory PdfColorHsl.fromRgb(double red, double green, double blue, 261 factory PdfColorHsl.fromRgb(double red, double green, double blue,
264 [double alpha]) { 262 [double alpha]) {
265 final double max = math.max(red, math.max(green, blue)); 263 final double max = math.max(red, math.max(green, blue));
@@ -275,6 +273,10 @@ class PdfColorHsl extends PdfColor { @@ -275,6 +273,10 @@ class PdfColorHsl extends PdfColor {
275 return PdfColorHsl._(hue, saturation, lightness, alpha, red, green, blue); 273 return PdfColorHsl._(hue, saturation, lightness, alpha, red, green, blue);
276 } 274 }
277 275
  276 + final double hue;
  277 + final double saturation;
  278 + final double lightness;
  279 +
278 @override 280 @override
279 PdfColorHsl toHsl() { 281 PdfColorHsl toHsl() {
280 return this; 282 return this;
@@ -18,13 +18,6 @@ part of pdf; @@ -18,13 +18,6 @@ part of pdf;
18 18
19 @deprecated 19 @deprecated
20 class PDFAnnot extends PdfAnnot { 20 class PDFAnnot extends PdfAnnot {
21 - static const SOLID = PdfBorderStyle.solid;  
22 - static const DASHED = PdfBorderStyle.dashed;  
23 - static const BEVELED = PdfBorderStyle.beveled;  
24 - static const INSET = PdfBorderStyle.inset;  
25 - static const UNDERLINED = PdfBorderStyle.underlined;  
26 - static const FULL_PAGE = -9999.0;  
27 -  
28 PDFAnnot(PdfPage pdfPage, 21 PDFAnnot(PdfPage pdfPage,
29 {String type, 22 {String type,
30 String s, 23 String s,
@@ -48,11 +41,11 @@ class PDFAnnot extends PdfAnnot { @@ -48,11 +41,11 @@ class PDFAnnot extends PdfAnnot {
48 41
49 factory PDFAnnot.annotation( 42 factory PDFAnnot.annotation(
50 PdfPage pdfPage, String s, double l, double b, double r, double t) => 43 PdfPage pdfPage, String s, double l, double b, double r, double t) =>
51 - PDFAnnot(pdfPage, type: "/Annot", s: s, l: l, b: b, r: r, t: t); 44 + PDFAnnot(pdfPage, type: '/Annot', s: s, l: l, b: b, r: r, t: t);
52 45
53 factory PDFAnnot.text( 46 factory PDFAnnot.text(
54 PdfPage pdfPage, double l, double b, double r, double t, String s) => 47 PdfPage pdfPage, double l, double b, double r, double t, String s) =>
55 - PDFAnnot(pdfPage, type: "/Text", l: l, b: b, r: r, t: t, s: s); 48 + PDFAnnot(pdfPage, type: '/Text', l: l, b: b, r: r, t: t, s: s);
56 49
57 factory PDFAnnot.link(PdfPage pdfPage, double l, double b, double r, double t, 50 factory PDFAnnot.link(PdfPage pdfPage, double l, double b, double r, double t,
58 PdfObject dest, 51 PdfObject dest,
@@ -61,7 +54,7 @@ class PDFAnnot extends PdfAnnot { @@ -61,7 +54,7 @@ class PDFAnnot extends PdfAnnot {
61 double fr = FULL_PAGE, 54 double fr = FULL_PAGE,
62 double ft = FULL_PAGE]) => 55 double ft = FULL_PAGE]) =>
63 PDFAnnot(pdfPage, 56 PDFAnnot(pdfPage,
64 - type: "/Link", 57 + type: '/Link',
65 l: l, 58 l: l,
66 b: b, 59 b: b,
67 r: r, 60 r: r,
@@ -71,6 +64,13 @@ class PDFAnnot extends PdfAnnot { @@ -71,6 +64,13 @@ class PDFAnnot extends PdfAnnot {
71 fb: fb, 64 fb: fb,
72 fr: fr, 65 fr: fr,
73 ft: ft); 66 ft: ft);
  67 +
  68 + static const PdfBorderStyle SOLID = PdfBorderStyle.solid;
  69 + static const PdfBorderStyle DASHED = PdfBorderStyle.dashed;
  70 + static const PdfBorderStyle BEVELED = PdfBorderStyle.beveled;
  71 + static const PdfBorderStyle INSET = PdfBorderStyle.inset;
  72 + static const PdfBorderStyle UNDERLINED = PdfBorderStyle.underlined;
  73 + static const double FULL_PAGE = -9999.0;
74 } 74 }
75 75
76 @deprecated 76 @deprecated
@@ -106,12 +106,12 @@ class PDFColor extends PdfColor { @@ -106,12 +106,12 @@ class PDFColor extends PdfColor {
106 PDFColor(double r, double g, double b, [double a = 1.0]) : super(r, g, b, a); 106 PDFColor(double r, double g, double b, [double a = 1.0]) : super(r, g, b, a);
107 107
108 factory PDFColor.fromInt(int color) { 108 factory PDFColor.fromInt(int color) {
109 - final c = PdfColor.fromInt(color); 109 + final PdfColor c = PdfColor.fromInt(color);
110 return PDFColor(c.r, c.g, c.b, c.a); 110 return PDFColor(c.r, c.g, c.b, c.a);
111 } 111 }
112 112
113 factory PDFColor.fromHex(String color) { 113 factory PDFColor.fromHex(String color) {
114 - final c = PdfColor.fromHex(color); 114 + final PdfColor c = PdfColor.fromHex(color);
115 return PDFColor(c.r, c.g, c.b, c.a); 115 return PDFColor(c.r, c.g, c.b, c.a);
116 } 116 }
117 } 117 }
@@ -125,6 +125,7 @@ class PDFFontDescriptor extends PdfFontDescriptor { @@ -125,6 +125,7 @@ class PDFFontDescriptor extends PdfFontDescriptor {
125 @deprecated 125 @deprecated
126 class PDFFont extends PdfFont { 126 class PDFFont extends PdfFont {
127 factory PDFFont(PdfDocument pdfDocument, {String subtype, String baseFont}) { 127 factory PDFFont(PdfDocument pdfDocument, {String subtype, String baseFont}) {
  128 + subtype ??= baseFont;
128 return PdfFont.helvetica(pdfDocument); 129 return PdfFont.helvetica(pdfDocument);
129 } 130 }
130 } 131 }
@@ -184,16 +185,16 @@ class PDFObject extends PdfObject { @@ -184,16 +185,16 @@ class PDFObject extends PdfObject {
184 185
185 @deprecated 186 @deprecated
186 class PDFOutline extends PdfOutline { 187 class PDFOutline extends PdfOutline {
  188 + PDFOutline(PdfDocument pdfDocument,
  189 + {String title, PdfPage dest, double l, double b, double r, double t})
  190 + : super(pdfDocument,
  191 + title: title, dest: dest, rect: PdfRect.fromLTRB(l, t, r, b));
  192 +
187 @deprecated 193 @deprecated
188 static const PdfOutlineMode FITPAGE = PdfOutlineMode.fitpage; 194 static const PdfOutlineMode FITPAGE = PdfOutlineMode.fitpage;
189 195
190 @deprecated 196 @deprecated
191 static const PdfOutlineMode FITRECT = PdfOutlineMode.fitrect; 197 static const PdfOutlineMode FITRECT = PdfOutlineMode.fitrect;
192 -  
193 - PDFOutline(PdfDocument pdfDocument,  
194 - {String title, PdfPage dest, double l, double b, double r, double t})  
195 - : super(pdfDocument,  
196 - title: title, dest: dest, rect: PdfRect.fromLTRB(l, t, r, b));  
197 } 198 }
198 199
199 @deprecated 200 @deprecated
@@ -203,26 +204,26 @@ class PDFOutput extends PdfOutput { @@ -203,26 +204,26 @@ class PDFOutput extends PdfOutput {
203 204
204 @deprecated 205 @deprecated
205 class PDFPageFormat extends PdfPageFormat { 206 class PDFPageFormat extends PdfPageFormat {
206 - static const a4 = PdfPageFormat.a4;  
207 - static const a3 = PdfPageFormat.a3;  
208 - static const a5 = PdfPageFormat.a5;  
209 - static const letter = PdfPageFormat.letter;  
210 - static const legal = PdfPageFormat.legal;  
211 - static const point = PdfPageFormat.point;  
212 - static const inch = PdfPageFormat.inch;  
213 - static const cm = PdfPageFormat.cm;  
214 - static const mm = PdfPageFormat.mm;  
215 - static const A4 = a4;  
216 - static const A3 = a3;  
217 - static const A5 = a5;  
218 - static const LETTER = letter;  
219 - static const LEGAL = legal;  
220 - static const PT = point;  
221 - static const IN = inch;  
222 - static const CM = cm;  
223 - static const MM = mm;  
224 -  
225 const PDFPageFormat(double width, double height) : super(width, height); 207 const PDFPageFormat(double width, double height) : super(width, height);
  208 +
  209 + static const PdfPageFormat a4 = PdfPageFormat.a4;
  210 + static const PdfPageFormat a3 = PdfPageFormat.a3;
  211 + static const PdfPageFormat a5 = PdfPageFormat.a5;
  212 + static const PdfPageFormat letter = PdfPageFormat.letter;
  213 + static const PdfPageFormat legal = PdfPageFormat.legal;
  214 + static const double point = PdfPageFormat.point;
  215 + static const double inch = PdfPageFormat.inch;
  216 + static const double cm = PdfPageFormat.cm;
  217 + static const double mm = PdfPageFormat.mm;
  218 + static const PdfPageFormat A4 = a4;
  219 + static const PdfPageFormat A3 = a3;
  220 + static const PdfPageFormat A5 = a5;
  221 + static const PdfPageFormat LETTER = letter;
  222 + static const PdfPageFormat LEGAL = legal;
  223 + static const double PT = point;
  224 + static const double IN = inch;
  225 + static const double CM = cm;
  226 + static const double MM = mm;
226 } 227 }
227 228
228 @deprecated 229 @deprecated
@@ -257,10 +258,10 @@ class PDFPage extends PdfPage { @@ -257,10 +258,10 @@ class PDFPage extends PdfPage {
257 /// @param h Height of the note 258 /// @param h Height of the note
258 /// @return Returns the annotation, so other settings can be changed. 259 /// @return Returns the annotation, so other settings can be changed.
259 @deprecated 260 @deprecated
260 - PdfAnnot addNote(String note, double x, y, w, h) {  
261 - var xy1 = cxy(x, y + h);  
262 - var xy2 = cxy(x + w, y);  
263 - PdfAnnot ob = PdfAnnot.text(this, 261 + PdfAnnot addNote(String note, double x, double y, double w, double h) {
  262 + final PdfPoint xy1 = cxy(x, y + h);
  263 + final PdfPoint xy2 = cxy(x + w, y);
  264 + final PdfAnnot ob = PdfAnnot.text(this,
264 rect: PdfRect.fromLTRB(xy1.x, xy1.y, xy2.x, xy2.y), content: note); 265 rect: PdfRect.fromLTRB(xy1.x, xy1.y, xy2.x, xy2.y), content: note);
265 return ob; 266 return ob;
266 } 267 }
@@ -278,16 +279,16 @@ class PDFPage extends PdfPage { @@ -278,16 +279,16 @@ class PDFPage extends PdfPage {
278 /// @param vh Height of the view area 279 /// @param vh Height of the view area
279 /// @return Returns the annotation, so other settings can be changed. 280 /// @return Returns the annotation, so other settings can be changed.
280 @deprecated 281 @deprecated
281 - PdfAnnot addLink(double x, y, w, h, PdfObject dest, 282 + PdfAnnot addLink(double x, double y, double w, double h, PdfObject dest,
282 [double vx = PDFAnnot.FULL_PAGE, 283 [double vx = PDFAnnot.FULL_PAGE,
283 - vy = PDFAnnot.FULL_PAGE,  
284 - vw = PDFAnnot.FULL_PAGE,  
285 - vh = PDFAnnot.FULL_PAGE]) {  
286 - var xy1 = cxy(x, y + h);  
287 - var xy2 = cxy(x + w, y);  
288 - var xy3 = cxy(vx, vy + vh);  
289 - var xy4 = cxy(vx + vw, vy);  
290 - PdfAnnot ob = PdfAnnot.link(this, 284 + double vy = PDFAnnot.FULL_PAGE,
  285 + double vw = PDFAnnot.FULL_PAGE,
  286 + double vh = PDFAnnot.FULL_PAGE]) {
  287 + final PdfPoint xy1 = cxy(x, y + h);
  288 + final PdfPoint xy2 = cxy(x + w, y);
  289 + final PdfPoint xy3 = cxy(vx, vy + vh);
  290 + final PdfPoint xy4 = cxy(vx + vw, vy);
  291 + final PdfAnnot ob = PdfAnnot.link(this,
291 srcRect: PdfRect.fromLTRB(xy1.x, xy1.y, xy2.x, xy2.y), 292 srcRect: PdfRect.fromLTRB(xy1.x, xy1.y, xy2.x, xy2.y),
292 dest: dest, 293 dest: dest,
293 destRect: PdfRect.fromLTRB(xy3.x, xy3.y, xy4.x, xy4.y)); 294 destRect: PdfRect.fromLTRB(xy3.x, xy3.y, xy4.x, xy4.y));
@@ -305,9 +306,9 @@ class PDFPage extends PdfPage { @@ -305,9 +306,9 @@ class PDFPage extends PdfPage {
305 @deprecated 306 @deprecated
306 PdfOutline addOutline(String title, 307 PdfOutline addOutline(String title,
307 {double x, double y, double w, double h}) { 308 {double x, double y, double w, double h}) {
308 - PdfPoint xy1 = cxy(x, y + h);  
309 - PdfPoint xy2 = cxy(x + w, y);  
310 - PdfOutline outline = PdfOutline(pdfDocument, 309 + final PdfPoint xy1 = cxy(x, y + h);
  310 + final PdfPoint xy2 = cxy(x + w, y);
  311 + final PdfOutline outline = PdfOutline(pdfDocument,
311 title: title, 312 title: title,
312 dest: this, 313 dest: this,
313 rect: PdfRect.fromLTRB(xy1.x, xy2.y, xy2.x, xy1.y)); 314 rect: PdfRect.fromLTRB(xy1.x, xy2.y, xy2.x, xy1.y));
@@ -342,7 +343,7 @@ class PDFPage extends PdfPage { @@ -342,7 +343,7 @@ class PDFPage extends PdfPage {
342 343
343 @deprecated 344 @deprecated
344 class PDFPoint extends PdfPoint { 345 class PDFPoint extends PdfPoint {
345 - PDFPoint(double w, double h) : super(w, h); 346 + const PDFPoint(double w, double h) : super(w, h);
346 } 347 }
347 348
348 @deprecated 349 @deprecated
1 /* 1 /*
2 * Copyright (C) 2017, David PHAM-VAN <dev.nfet.net@gmail.com> 2 * Copyright (C) 2017, David PHAM-VAN <dev.nfet.net@gmail.com>
3 * 3 *
4 - * Licensed under the Apache License, Version 2.0 (the "License"); 4 + * Licensed under the Apache License, Version 2.0 (the 'License');
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at 6 * You may obtain a copy of the License at
7 * 7 *
8 * http://www.apache.org/licenses/LICENSE-2.0 8 * http://www.apache.org/licenses/LICENSE-2.0
9 * 9 *
10 * Unless required by applicable law or agreed to in writing, software 10 * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS, 11 + * distributed under the License is distributed on an 'AS IS' BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
@@ -35,7 +35,7 @@ enum PdfPageMode { @@ -35,7 +35,7 @@ enum PdfPageMode {
35 fullscreen 35 fullscreen
36 } 36 }
37 37
38 -typedef List<int> DeflateCallback(List<int> data); 38 +typedef DeflateCallback = List<int> Function(List<int> data);
39 39
40 /// This class is the base of the Pdf generator. A [PdfDocument] class is 40 /// This class is the base of the Pdf generator. A [PdfDocument] class is
41 /// created for a document, and each page, object, annotation, 41 /// created for a document, and each page, object, annotation,
@@ -43,6 +43,17 @@ typedef List<int> DeflateCallback(List<int> data); @@ -43,6 +43,17 @@ typedef List<int> DeflateCallback(List<int> data);
43 /// Once complete, the document can be written to a Stream, and the Pdf 43 /// Once complete, the document can be written to a Stream, and the Pdf
44 /// document's internal structures are kept in sync. 44 /// document's internal structures are kept in sync.
45 class PdfDocument { 45 class PdfDocument {
  46 + /// This creates a Pdf document
  47 + /// @param pagemode an int, determines how the document will present itself to
  48 + /// the viewer when it first opens.
  49 + PdfDocument({PdfPageMode pageMode = PdfPageMode.none, this.deflate}) {
  50 + _objser = 1;
  51 +
  52 + // Now create some standard objects
  53 + pdfPageList = PdfPageList(this);
  54 + catalog = PdfCatalog(this, pdfPageList, pageMode);
  55 + }
  56 +
46 /// This is used to allocate objects a unique serial number in the document. 57 /// This is used to allocate objects a unique serial number in the document.
47 int _objser; 58 int _objser;
48 59
@@ -72,11 +83,11 @@ class PdfDocument { @@ -72,11 +83,11 @@ class PdfDocument {
72 final DeflateCallback deflate; 83 final DeflateCallback deflate;
73 84
74 /// These map the page modes just defined to the pagemodes setting of Pdf. 85 /// These map the page modes just defined to the pagemodes setting of Pdf.
75 - static const _PdfPageModes = [  
76 - "/UseNone",  
77 - "/UseOutlines",  
78 - "/UseThumbs",  
79 - "/FullScreen" 86 + static const List<String> _PdfPageModes = <String>[
  87 + '/UseNone',
  88 + '/UseOutlines',
  89 + '/UseThumbs',
  90 + '/FullScreen'
80 ]; 91 ];
81 92
82 /// This holds the current fonts 93 /// This holds the current fonts
@@ -85,17 +96,6 @@ class PdfDocument { @@ -85,17 +96,6 @@ class PdfDocument {
85 /// Creates a new serial number 96 /// Creates a new serial number
86 int _genSerial() => _objser++; 97 int _genSerial() => _objser++;
87 98
88 - /// This creates a Pdf document  
89 - /// @param pagemode an int, determines how the document will present itself to  
90 - /// the viewer when it first opens.  
91 - PdfDocument({PdfPageMode pageMode = PdfPageMode.none, this.deflate}) {  
92 - _objser = 1;  
93 -  
94 - // Now create some standard objects  
95 - pdfPageList = PdfPageList(this);  
96 - catalog = PdfCatalog(this, pdfPageList, pageMode);  
97 - }  
98 -  
99 /// This returns a specific page. It's used mainly when using a 99 /// This returns a specific page. It's used mainly when using a
100 /// Serialized template file. 100 /// Serialized template file.
101 /// 101 ///
@@ -128,20 +128,18 @@ class PdfDocument { @@ -128,20 +128,18 @@ class PdfDocument {
128 /// 128 ///
129 /// @param os OutputStream to write the document to 129 /// @param os OutputStream to write the document to
130 void _write(PdfStream os) { 130 void _write(PdfStream os) {
131 - PdfOutput pos = PdfOutput(os); 131 + final PdfOutput pos = PdfOutput(os);
132 132
133 // Write each object to the [PdfStream]. We call via the output 133 // Write each object to the [PdfStream]. We call via the output
134 // as that builds the xref table 134 // as that builds the xref table
135 - for (PdfObject o in objects) {  
136 - pos.write(o);  
137 - } 135 + objects.forEach(pos.write);
138 136
139 // Finally close the output, which writes the xref table. 137 // Finally close the output, which writes the xref table.
140 pos.close(); 138 pos.close();
141 } 139 }
142 140
143 List<int> save() { 141 List<int> save() {
144 - PdfStream os = PdfStream(); 142 + final PdfStream os = PdfStream();
145 _write(os); 143 _write(os);
146 return os.output(); 144 return os.output();
147 } 145 }
@@ -17,9 +17,6 @@ @@ -17,9 +17,6 @@
17 part of pdf; 17 part of pdf;
18 18
19 class PdfFont extends PdfObject { 19 class PdfFont extends PdfObject {
20 - /// The df type of the font, usually /Type1  
21 - final String subtype;  
22 -  
23 /// Constructs a [PdfFont]. This will attempt to map the font from a known 20 /// Constructs a [PdfFont]. This will attempt to map the font from a known
24 /// font name to that in Pdf, defaulting to Helvetica if not possible. 21 /// font name to that in Pdf, defaulting to Helvetica if not possible.
25 /// 22 ///
@@ -27,94 +24,33 @@ class PdfFont extends PdfObject { @@ -27,94 +24,33 @@ class PdfFont extends PdfObject {
27 /// @param subtype The pdf type, ie /Type1 24 /// @param subtype The pdf type, ie /Type1
28 /// @param baseFont The font name, ie /Helvetica 25 /// @param baseFont The font name, ie /Helvetica
29 PdfFont._create(PdfDocument pdfDocument, {@required this.subtype}) 26 PdfFont._create(PdfDocument pdfDocument, {@required this.subtype})
30 - : super(pdfDocument, "/Font") { 27 + : super(pdfDocument, '/Font') {
31 pdfDocument.fonts.add(this); 28 pdfDocument.fonts.add(this);
32 } 29 }
33 30
34 - String get name => "/F$objser";  
35 -  
36 - String get fontName => null;  
37 -  
38 - /// @param os OutputStream to send the object to  
39 - @override  
40 - void _prepare() {  
41 - super._prepare();  
42 -  
43 - params["/Subtype"] = PdfStream.string(subtype);  
44 - params["/Name"] = PdfStream.string(name);  
45 - params["/Encoding"] = PdfStream.string("/WinAnsiEncoding");  
46 - }  
47 -  
48 - double glyphAdvance(int charCode) {  
49 - return 0.454;  
50 - }  
51 -  
52 - PdfRect glyphBounds(int charCode) {  
53 - return PdfRect(0.0, 0.0, glyphAdvance(charCode), 1.0);  
54 - }  
55 -  
56 - PdfRect stringBounds(String s) {  
57 - var chars = latin1.encode(s);  
58 -  
59 - if (chars.isEmpty) return const PdfRect(0.0, 0.0, 0.0, 0.0);  
60 -  
61 - var n = 0;  
62 - var c = chars[n];  
63 - var r = glyphBounds(c);  
64 - var x = r.x;  
65 - var y = r.y;  
66 - var h = r.height;  
67 - var w = n == chars.length - 1 ? r.width : glyphAdvance(c);  
68 -  
69 - while (++n < chars.length) {  
70 - c = chars[n];  
71 - r = glyphBounds(c);  
72 - if (r.y < y) y = r.y;  
73 - if (r.height > h) h = r.height;  
74 - w += n == chars.length - 1 ? r.width : glyphAdvance(c);  
75 - }  
76 -  
77 - return PdfRect(x, y, w, h);  
78 - }  
79 -  
80 - PdfPoint stringSize(String s) {  
81 - var chars = latin1.encode(s);  
82 -  
83 - var w = 0.0;  
84 - var h = 0.0;  
85 -  
86 - for (var c in chars) {  
87 - var r = glyphBounds(c);  
88 - if (r.height > h) h = r.height;  
89 - w += glyphAdvance(c);  
90 - }  
91 -  
92 - return PdfPoint(w, h);  
93 - }  
94 -  
95 factory PdfFont.courier(PdfDocument pdfDocument) { 31 factory PdfFont.courier(PdfDocument pdfDocument) {
96 - return PdfType1Font._create(pdfDocument, "Courier", 0.910, -0.220, 32 + return PdfType1Font._create(pdfDocument, 'Courier', 0.910, -0.220,
97 List<double>.generate(256, (int index) => 0.600)); 33 List<double>.generate(256, (int index) => 0.600));
98 } 34 }
99 35
100 factory PdfFont.courierBold(PdfDocument pdfDocument) { 36 factory PdfFont.courierBold(PdfDocument pdfDocument) {
101 - return PdfType1Font._create(pdfDocument, "Courier-Bold", 0.910, -0.220, 37 + return PdfType1Font._create(pdfDocument, 'Courier-Bold', 0.910, -0.220,
102 List<double>.generate(256, (int index) => 0.600)); 38 List<double>.generate(256, (int index) => 0.600));
103 } 39 }
104 40
105 factory PdfFont.courierBoldOblique(PdfDocument pdfDocument) { 41 factory PdfFont.courierBoldOblique(PdfDocument pdfDocument) {
106 - return PdfType1Font._create(pdfDocument, "Courier-BoldOblique", 0.910, 42 + return PdfType1Font._create(pdfDocument, 'Courier-BoldOblique', 0.910,
107 -0.220, List<double>.generate(256, (int index) => 0.600)); 43 -0.220, List<double>.generate(256, (int index) => 0.600));
108 } 44 }
109 45
110 factory PdfFont.courierOblique(PdfDocument pdfDocument) { 46 factory PdfFont.courierOblique(PdfDocument pdfDocument) {
111 - return PdfType1Font._create(pdfDocument, "Courier-Oblique", 0.910, -0.220, 47 + return PdfType1Font._create(pdfDocument, 'Courier-Oblique', 0.910, -0.220,
112 List<double>.generate(256, (int index) => 0.600)); 48 List<double>.generate(256, (int index) => 0.600));
113 } 49 }
114 50
115 factory PdfFont.helvetica(PdfDocument pdfDocument) { 51 factory PdfFont.helvetica(PdfDocument pdfDocument) {
116 return PdfType1Font._create( 52 return PdfType1Font._create(
117 - pdfDocument, "Helvetica", 0.931, -0.225, <double>[ 53 + pdfDocument, 'Helvetica', 0.931, -0.225, const <double>[
118 0.500, 54 0.500,
119 0.500, 55 0.500,
120 0.500, 56 0.500,
@@ -376,7 +312,7 @@ class PdfFont extends PdfObject { @@ -376,7 +312,7 @@ class PdfFont extends PdfObject {
376 312
377 factory PdfFont.helveticaBold(PdfDocument pdfDocument) { 313 factory PdfFont.helveticaBold(PdfDocument pdfDocument) {
378 return PdfType1Font._create( 314 return PdfType1Font._create(
379 - pdfDocument, "Helvetica-Bold", 0.962, -0.228, <double>[ 315 + pdfDocument, 'Helvetica-Bold', 0.962, -0.228, const <double>[
380 0.278, 316 0.278,
381 0.278, 317 0.278,
382 0.278, 318 0.278,
@@ -638,7 +574,7 @@ class PdfFont extends PdfObject { @@ -638,7 +574,7 @@ class PdfFont extends PdfObject {
638 574
639 factory PdfFont.helveticaBoldOblique(PdfDocument pdfDocument) { 575 factory PdfFont.helveticaBoldOblique(PdfDocument pdfDocument) {
640 return PdfType1Font._create( 576 return PdfType1Font._create(
641 - pdfDocument, "Helvetica-BoldOblique", 0.962, -0.228, <double>[ 577 + pdfDocument, 'Helvetica-BoldOblique', 0.962, -0.228, const <double>[
642 0.278, 578 0.278,
643 0.278, 579 0.278,
644 0.278, 580 0.278,
@@ -900,7 +836,7 @@ class PdfFont extends PdfObject { @@ -900,7 +836,7 @@ class PdfFont extends PdfObject {
900 836
901 factory PdfFont.helveticaOblique(PdfDocument pdfDocument) { 837 factory PdfFont.helveticaOblique(PdfDocument pdfDocument) {
902 return PdfType1Font._create( 838 return PdfType1Font._create(
903 - pdfDocument, "Helvetica-Oblique", 0.931, -0.225, <double>[ 839 + pdfDocument, 'Helvetica-Oblique', 0.931, -0.225, <double>[
904 0.278, 840 0.278,
905 0.278, 841 0.278,
906 0.278, 842 0.278,
@@ -1162,7 +1098,7 @@ class PdfFont extends PdfObject { @@ -1162,7 +1098,7 @@ class PdfFont extends PdfObject {
1162 1098
1163 factory PdfFont.times(PdfDocument pdfDocument) { 1099 factory PdfFont.times(PdfDocument pdfDocument) {
1164 return PdfType1Font._create( 1100 return PdfType1Font._create(
1165 - pdfDocument, "Times-Roman", 0.898, -0.218, <double>[ 1101 + pdfDocument, 'Times-Roman', 0.898, -0.218, <double>[
1166 0.250, 1102 0.250,
1167 0.250, 1103 0.250,
1168 0.250, 1104 0.250,
@@ -1424,7 +1360,7 @@ class PdfFont extends PdfObject { @@ -1424,7 +1360,7 @@ class PdfFont extends PdfObject {
1424 1360
1425 factory PdfFont.timesBold(PdfDocument pdfDocument) { 1361 factory PdfFont.timesBold(PdfDocument pdfDocument) {
1426 return PdfType1Font._create( 1362 return PdfType1Font._create(
1427 - pdfDocument, "Times-Bold", 0.935, -0.218, <double>[ 1363 + pdfDocument, 'Times-Bold', 0.935, -0.218, <double>[
1428 0.250, 1364 0.250,
1429 0.250, 1365 0.250,
1430 0.250, 1366 0.250,
@@ -1686,7 +1622,7 @@ class PdfFont extends PdfObject { @@ -1686,7 +1622,7 @@ class PdfFont extends PdfObject {
1686 1622
1687 factory PdfFont.timesBoldItalic(PdfDocument pdfDocument) { 1623 factory PdfFont.timesBoldItalic(PdfDocument pdfDocument) {
1688 return PdfType1Font._create( 1624 return PdfType1Font._create(
1689 - pdfDocument, "Times-BoldItalic", 0.921, -0.218, <double>[ 1625 + pdfDocument, 'Times-BoldItalic', 0.921, -0.218, <double>[
1690 0.250, 1626 0.250,
1691 0.250, 1627 0.250,
1692 0.250, 1628 0.250,
@@ -1948,7 +1884,7 @@ class PdfFont extends PdfObject { @@ -1948,7 +1884,7 @@ class PdfFont extends PdfObject {
1948 1884
1949 factory PdfFont.timesItalic(PdfDocument pdfDocument) { 1885 factory PdfFont.timesItalic(PdfDocument pdfDocument) {
1950 return PdfType1Font._create( 1886 return PdfType1Font._create(
1951 - pdfDocument, "Times-Italic", 0.883, -0.217, <double>[ 1887 + pdfDocument, 'Times-Italic', 0.883, -0.217, <double>[
1952 0.250, 1888 0.250,
1953 0.250, 1889 0.250,
1954 0.250, 1890 0.250,
@@ -2209,7 +2145,7 @@ class PdfFont extends PdfObject { @@ -2209,7 +2145,7 @@ class PdfFont extends PdfObject {
2209 } 2145 }
2210 2146
2211 factory PdfFont.symbol(PdfDocument pdfDocument) { 2147 factory PdfFont.symbol(PdfDocument pdfDocument) {
2212 - return PdfType1Font._create(pdfDocument, "Symbol", 1.010, -0.293, <double>[ 2148 + return PdfType1Font._create(pdfDocument, 'Symbol', 1.010, -0.293, <double>[
2213 0.587, 2149 0.587,
2214 0.587, 2150 0.587,
2215 0.587, 2151 0.587,
@@ -2471,7 +2407,7 @@ class PdfFont extends PdfObject { @@ -2471,7 +2407,7 @@ class PdfFont extends PdfObject {
2471 2407
2472 factory PdfFont.zapfDingbats(PdfDocument pdfDocument) { 2408 factory PdfFont.zapfDingbats(PdfDocument pdfDocument) {
2473 return PdfType1Font._create( 2409 return PdfType1Font._create(
2474 - pdfDocument, "ZapfDingbats", 0.820, -0.143, <double>[ 2410 + pdfDocument, 'ZapfDingbats', 0.820, -0.143, <double>[
2475 0.746, 2411 0.746,
2476 0.746, 2412 0.746,
2477 0.746, 2413 0.746,
@@ -2730,4 +2666,76 @@ class PdfFont extends PdfObject { @@ -2730,4 +2666,76 @@ class PdfFont extends PdfObject {
2730 0.746 2666 0.746
2731 ]); 2667 ]);
2732 } 2668 }
  2669 +
  2670 + /// The df type of the font, usually /Type1
  2671 + final String subtype;
  2672 +
  2673 + String get name => '/F$objser';
  2674 +
  2675 + String get fontName => null;
  2676 +
  2677 + /// @param os OutputStream to send the object to
  2678 + @override
  2679 + void _prepare() {
  2680 + super._prepare();
  2681 +
  2682 + params['/Subtype'] = PdfStream.string(subtype);
  2683 + params['/Name'] = PdfStream.string(name);
  2684 + params['/Encoding'] = PdfStream.string('/WinAnsiEncoding');
  2685 + }
  2686 +
  2687 + double glyphAdvance(int charCode) {
  2688 + return 0.454;
  2689 + }
  2690 +
  2691 + PdfRect glyphBounds(int charCode) {
  2692 + return PdfRect(0.0, 0.0, glyphAdvance(charCode), 1.0);
  2693 + }
  2694 +
  2695 + PdfRect stringBounds(String s) {
  2696 + final Uint8List chars = latin1.encode(s);
  2697 +
  2698 + if (chars.isEmpty) {
  2699 + return const PdfRect(0.0, 0.0, 0.0, 0.0);
  2700 + }
  2701 +
  2702 + int n = 0;
  2703 + int c = chars[n];
  2704 + PdfRect r = glyphBounds(c);
  2705 + final double x = r.x;
  2706 + double y = r.y;
  2707 + double h = r.height;
  2708 + double w = n == chars.length - 1 ? r.width : glyphAdvance(c);
  2709 +
  2710 + while (++n < chars.length) {
  2711 + c = chars[n];
  2712 + r = glyphBounds(c);
  2713 + if (r.y < y) {
  2714 + y = r.y;
  2715 + }
  2716 + if (r.height > h) {
  2717 + h = r.height;
  2718 + }
  2719 + w += n == chars.length - 1 ? r.width : glyphAdvance(c);
  2720 + }
  2721 +
  2722 + return PdfRect(x, y, w, h);
  2723 + }
  2724 +
  2725 + PdfPoint stringSize(String s) {
  2726 + final Uint8List chars = latin1.encode(s);
  2727 +
  2728 + double w = 0.0;
  2729 + double h = 0.0;
  2730 +
  2731 + for (int c in chars) {
  2732 + final PdfRect r = glyphBounds(c);
  2733 + if (r.height > h) {
  2734 + h = r.height;
  2735 + }
  2736 + w += glyphAdvance(c);
  2737 + }
  2738 +
  2739 + return PdfPoint(w, h);
  2740 + }
2733 } 2741 }
@@ -17,30 +17,31 @@ @@ -17,30 +17,31 @@
17 part of pdf; 17 part of pdf;
18 18
19 class PdfFontDescriptor extends PdfObject { 19 class PdfFontDescriptor extends PdfObject {
  20 + PdfFontDescriptor(this.ttfFont, this.file)
  21 + : super(ttfFont.pdfDocument, '/FontDescriptor');
  22 +
20 final PdfObjectStream file; 23 final PdfObjectStream file;
21 - final PdfTtfFont ttfFont;  
22 24
23 - PdfFontDescriptor(this.ttfFont, this.file)  
24 - : super(ttfFont.pdfDocument, "/FontDescriptor"); 25 + final PdfTtfFont ttfFont;
25 26
26 @override 27 @override
27 void _prepare() { 28 void _prepare() {
28 super._prepare(); 29 super._prepare();
29 30
30 - params["/FontName"] = PdfStream.string(ttfFont.fontName);  
31 - params["/FontFile2"] = file.ref();  
32 - params["/Flags"] = PdfStream.intNum(32);  
33 - params["/FontBBox"] = PdfStream()  
34 - ..putStringArray([ 31 + params['/FontName'] = PdfStream.string(ttfFont.fontName);
  32 + params['/FontFile2'] = file.ref();
  33 + params['/Flags'] = PdfStream.intNum(32);
  34 + params['/FontBBox'] = PdfStream()
  35 + ..putIntArray(<int>[
35 ttfFont.font.xMin, 36 ttfFont.font.xMin,
36 ttfFont.font.yMin, 37 ttfFont.font.yMin,
37 ttfFont.font.xMax, 38 ttfFont.font.xMax,
38 ttfFont.font.yMax 39 ttfFont.font.yMax
39 ]); 40 ]);
40 - params["/Ascent"] = PdfStream.intNum(ttfFont.font.ascent);  
41 - params["/Descent"] = PdfStream.intNum(ttfFont.font.descent);  
42 - params["/ItalicAngle"] = PdfStream.intNum(0);  
43 - params["/CapHeight"] = PdfStream.intNum(10);  
44 - params["/StemV"] = PdfStream.intNum(79); 41 + params['/Ascent'] = PdfStream.intNum(ttfFont.font.ascent);
  42 + params['/Descent'] = PdfStream.intNum(ttfFont.font.descent);
  43 + params['/ItalicAngle'] = PdfStream.intNum(0);
  44 + params['/CapHeight'] = PdfStream.intNum(10);
  45 + params['/StemV'] = PdfStream.intNum(79);
45 } 46 }
46 } 47 }
@@ -17,22 +17,22 @@ @@ -17,22 +17,22 @@
17 part of pdf; 17 part of pdf;
18 18
19 class PdfFormXObject extends PdfXObject { 19 class PdfFormXObject extends PdfXObject {
  20 + PdfFormXObject(PdfDocument pdfDocument) : super(pdfDocument, '/Form') {
  21 + params['/FormType'] = PdfStream.string('1');
  22 + params['/BBox'] = PdfStream.string('[0 0 1000 1000]');
  23 + }
  24 +
20 /// The fonts associated with this page 25 /// The fonts associated with this page
21 - final fonts = Map<String, PdfFont>(); 26 + final Map<String, PdfFont> fonts = <String, PdfFont>{};
22 27
23 /// The xobjects or other images in the pdf 28 /// The xobjects or other images in the pdf
24 - final xobjects = Map<String, PdfXObject>();  
25 -  
26 - PdfFormXObject(PdfDocument pdfDocument) : super(pdfDocument, '/Form') {  
27 - params["/FormType"] = PdfStream.string("1");  
28 - params["/BBox"] = PdfStream.string("[0 0 1000 1000]");  
29 - } 29 + final Map<String, PdfXObject> xobjects = <String, PdfXObject>{};
30 30
31 /// set matrix 31 /// set matrix
32 void setMatrix(Matrix4 t) { 32 void setMatrix(Matrix4 t) {
33 - var s = t.storage;  
34 - params["/Matrix"] =  
35 - PdfStream.string("[${s[0]} ${s[1]} ${s[4]} ${s[5]} ${s[12]} ${s[13]}]"); 33 + final Float64List s = t.storage;
  34 + params['/Matrix'] =
  35 + PdfStream.string('[${s[0]} ${s[1]} ${s[4]} ${s[5]} ${s[12]} ${s[13]}]');
36 } 36 }
37 37
38 @override 38 @override
@@ -41,20 +41,20 @@ class PdfFormXObject extends PdfXObject { @@ -41,20 +41,20 @@ class PdfFormXObject extends PdfXObject {
41 41
42 // Now the resources 42 // Now the resources
43 /// This holds any resources for this FormXObject 43 /// This holds any resources for this FormXObject
44 - final resources = Map<String, PdfStream>(); 44 + final Map<String, PdfStream> resources = <String, PdfStream>{};
45 45
46 // fonts 46 // fonts
47 if (fonts.isNotEmpty) { 47 if (fonts.isNotEmpty) {
48 - resources["/Font"] = PdfStream()..putObjectDictionary(fonts); 48 + resources['/Font'] = PdfStream()..putObjectDictionary(fonts);
49 } 49 }
50 50
51 // Now the XObjects 51 // Now the XObjects
52 if (xobjects.isNotEmpty) { 52 if (xobjects.isNotEmpty) {
53 - resources["/XObject"] = PdfStream()..putObjectDictionary(xobjects); 53 + resources['/XObject'] = PdfStream()..putObjectDictionary(xobjects);
54 } 54 }
55 55
56 if (resources.isNotEmpty) { 56 if (resources.isNotEmpty) {
57 - params["/Resources"] = PdfStream.dictionary(resources); 57 + params['/Resources'] = PdfStream.dictionary(resources);
58 } 58 }
59 } 59 }
60 } 60 }
@@ -19,18 +19,18 @@ part of pdf; @@ -19,18 +19,18 @@ part of pdf;
19 enum PdfLineCap { joinMiter, joinRound, joinBevel } 19 enum PdfLineCap { joinMiter, joinRound, joinBevel }
20 20
21 class PdfGraphics { 21 class PdfGraphics {
  22 + PdfGraphics(this.page, this.buf);
  23 +
22 /// Ellipse 4-spline magic number 24 /// Ellipse 4-spline magic number
23 - static const _m4 = 0.551784; 25 + static const double _m4 = 0.551784;
24 26
25 /// Graphic context number 27 /// Graphic context number
26 - var _context = 0; 28 + int _context = 0;
27 29
28 final PdfPage page; 30 final PdfPage page;
29 31
30 final PdfStream buf; 32 final PdfStream buf;
31 33
32 - PdfGraphics(this.page, this.buf);  
33 -  
34 PdfFont get defaultFont { 34 PdfFont get defaultFont {
35 if (page.pdfDocument.fonts.isEmpty) { 35 if (page.pdfDocument.fonts.isEmpty) {
36 PdfFont.helvetica(page.pdfDocument); 36 PdfFont.helvetica(page.pdfDocument);
@@ -40,19 +40,19 @@ class PdfGraphics { @@ -40,19 +40,19 @@ class PdfGraphics {
40 } 40 }
41 41
42 void fillPath() { 42 void fillPath() {
43 - buf.putString("f\n"); 43 + buf.putString('f\n');
44 } 44 }
45 45
46 void strokePath() { 46 void strokePath() {
47 - buf.putString("S\n"); 47 + buf.putString('S\n');
48 } 48 }
49 49
50 void closePath() { 50 void closePath() {
51 - buf.putString("s\n"); 51 + buf.putString('s\n');
52 } 52 }
53 53
54 void clipPath() { 54 void clipPath() {
55 - buf.putString("W n\n"); 55 + buf.putString('W n\n');
56 } 56 }
57 57
58 /// This releases any resources used by this Graphics object. You must use 58 /// This releases any resources used by this Graphics object. You must use
@@ -63,14 +63,14 @@ class PdfGraphics { @@ -63,14 +63,14 @@ class PdfGraphics {
63 void restoreContext() { 63 void restoreContext() {
64 if (_context > 0) { 64 if (_context > 0) {
65 // restore graphics context 65 // restore graphics context
66 - buf.putString("Q\n"); 66 + buf.putString('Q\n');
67 _context--; 67 _context--;
68 } 68 }
69 } 69 }
70 70
71 void saveContext() { 71 void saveContext() {
72 // save graphics context 72 // save graphics context
73 - buf.putString("q\n"); 73 + buf.putString('q\n');
74 _context++; 74 _context++;
75 } 75 }
76 76
@@ -89,16 +89,16 @@ class PdfGraphics { @@ -89,16 +89,16 @@ class PdfGraphics {
89 /// @param bgcolor Background colour 89 /// @param bgcolor Background colour
90 /// @return true if drawn 90 /// @return true if drawn
91 void drawImage(PdfImage img, double x, double y, [double w, double h]) { 91 void drawImage(PdfImage img, double x, double y, [double w, double h]) {
92 - if (w == null) w = img.width.toDouble();  
93 - if (h == null) h = img.height.toDouble() * w / img.width.toDouble(); 92 + w ??= img.width.toDouble();
  93 + h ??= img.height.toDouble() * w / img.width.toDouble();
94 94
95 // The image needs to be registered in the page resources 95 // The image needs to be registered in the page resources
96 page.xObjects[img.name] = img; 96 page.xObjects[img.name] = img;
97 97
98 // q w 0 0 h x y cm % the coordinate matrix 98 // q w 0 0 h x y cm % the coordinate matrix
99 - buf.putString("q "); 99 + buf.putString('q ');
100 buf.putNumList(<double>[w, 0.0, 0.0, h, x, y]); 100 buf.putNumList(<double>[w, 0.0, 0.0, h, x, y]);
101 - buf.putString(" cm ${img.name} Do Q\n"); 101 + buf.putString(' cm ${img.name} Do Q\n');
102 } 102 }
103 103
104 /// Draws a line between two coordinates. 104 /// Draws a line between two coordinates.
@@ -145,7 +145,7 @@ class PdfGraphics { @@ -145,7 +145,7 @@ class PdfGraphics {
145 double h, 145 double h,
146 ) { 146 ) {
147 buf.putNumList(<double>[x, y, w, h]); 147 buf.putNumList(<double>[x, y, w, h]);
148 - buf.putString(" re\n"); 148 + buf.putString(' re\n');
149 } 149 }
150 150
151 /// Draws a Rounded Rectangle 151 /// Draws a Rounded Rectangle
@@ -179,13 +179,13 @@ class PdfGraphics { @@ -179,13 +179,13 @@ class PdfGraphics {
179 page.fonts[font.name] = font; 179 page.fonts[font.name] = font;
180 } 180 }
181 181
182 - buf.putString("BT "); 182 + buf.putString('BT ');
183 buf.putNumList(<double>[x, y]); 183 buf.putNumList(<double>[x, y]);
184 - buf.putString(" Td ${font.name} "); 184 + buf.putString(' Td ${font.name} ');
185 buf.putNum(size); 185 buf.putNum(size);
186 - buf.putString(" Tf "); 186 + buf.putString(' Tf ');
187 buf.putText(s); 187 buf.putText(s);
188 - buf.putString(" Tj ET\n"); 188 + buf.putString(' Tj ET\n');
189 } 189 }
190 190
191 /// Sets the color for drawing 191 /// Sets the color for drawing
@@ -202,10 +202,10 @@ class PdfGraphics { @@ -202,10 +202,10 @@ class PdfGraphics {
202 void setFillColor(PdfColor color) { 202 void setFillColor(PdfColor color) {
203 if (color is PdfColorCmyk) { 203 if (color is PdfColorCmyk) {
204 buf.putNumList(<double>[color.c, color.m, color.y, color.k]); 204 buf.putNumList(<double>[color.c, color.m, color.y, color.k]);
205 - buf.putString(" k\n"); 205 + buf.putString(' k\n');
206 } else { 206 } else {
207 buf.putNumList(<double>[color.r, color.g, color.b]); 207 buf.putNumList(<double>[color.r, color.g, color.b]);
208 - buf.putString(" rg\n"); 208 + buf.putString(' rg\n');
209 } 209 }
210 } 210 }
211 211
@@ -215,18 +215,18 @@ class PdfGraphics { @@ -215,18 +215,18 @@ class PdfGraphics {
215 void setStrokeColor(PdfColor color) { 215 void setStrokeColor(PdfColor color) {
216 if (color is PdfColorCmyk) { 216 if (color is PdfColorCmyk) {
217 buf.putNumList(<double>[color.c, color.m, color.y, color.k]); 217 buf.putNumList(<double>[color.c, color.m, color.y, color.k]);
218 - buf.putString(" K\n"); 218 + buf.putString(' K\n');
219 } else { 219 } else {
220 buf.putNumList(<double>[color.r, color.g, color.b]); 220 buf.putNumList(<double>[color.r, color.g, color.b]);
221 - buf.putString(" RG\n"); 221 + buf.putString(' RG\n');
222 } 222 }
223 } 223 }
224 224
225 /// Set the transformation Matrix 225 /// Set the transformation Matrix
226 void setTransform(Matrix4 t) { 226 void setTransform(Matrix4 t) {
227 - var s = t.storage; 227 + final Float64List s = t.storage;
228 buf.putNumList(<double>[s[0], s[1], s[4], s[5], s[12], s[13]]); 228 buf.putNumList(<double>[s[0], s[1], s[4], s[5], s[12], s[13]]);
229 - buf.putString(" cm\n"); 229 + buf.putString(' cm\n');
230 } 230 }
231 231
232 /// This adds a line segment to the current path 232 /// This adds a line segment to the current path
@@ -235,7 +235,7 @@ class PdfGraphics { @@ -235,7 +235,7 @@ class PdfGraphics {
235 /// @param y coordinate 235 /// @param y coordinate
236 void lineTo(double x, double y) { 236 void lineTo(double x, double y) {
237 buf.putNumList(<double>[x, y]); 237 buf.putNumList(<double>[x, y]);
238 - buf.putString(" l\n"); 238 + buf.putString(' l\n');
239 } 239 }
240 240
241 /// This moves the current drawing point. 241 /// This moves the current drawing point.
@@ -244,7 +244,7 @@ class PdfGraphics { @@ -244,7 +244,7 @@ class PdfGraphics {
244 /// @param y coordinate 244 /// @param y coordinate
245 void moveTo(double x, double y) { 245 void moveTo(double x, double y) {
246 buf.putNumList(<double>[x, y]); 246 buf.putNumList(<double>[x, y]);
247 - buf.putString(" m\n"); 247 + buf.putString(' m\n');
248 } 248 }
249 249
250 /// Draw a cubic bézier curve from the current point to (x3,y3) 250 /// Draw a cubic bézier curve from the current point to (x3,y3)
@@ -260,17 +260,22 @@ class PdfGraphics { @@ -260,17 +260,22 @@ class PdfGraphics {
260 void curveTo( 260 void curveTo(
261 double x1, double y1, double x2, double y2, double x3, double y3) { 261 double x1, double y1, double x2, double y2, double x3, double y3) {
262 buf.putNumList(<double>[x1, y1, x2, y2, x3, y3]); 262 buf.putNumList(<double>[x1, y1, x2, y2, x3, y3]);
263 - buf.putString(" c\n"); 263 + buf.putString(' c\n');
264 } 264 }
265 265
266 double _vectorAngle(double ux, double uy, double vx, double vy) { 266 double _vectorAngle(double ux, double uy, double vx, double vy) {
267 - final d = math.sqrt(ux * ux + uy * uy) * math.sqrt(vx * vx + vy * vy);  
268 - if (d == 0.0) return 0.0;  
269 - var c = (ux * vx + uy * vy) / d; 267 + final double d =
  268 + math.sqrt(ux * ux + uy * uy) * math.sqrt(vx * vx + vy * vy);
  269 + if (d == 0.0) {
  270 + return 0.0;
  271 + }
  272 + double c = (ux * vx + uy * vy) / d;
270 if (c < -1.0) { 273 if (c < -1.0) {
271 c = -1.0; 274 c = -1.0;
272 - } else if (c > 1.0) c = 1.0;  
273 - final s = ux * vy - uy * vx; 275 + } else if (c > 1.0) {
  276 + c = 1.0;
  277 + }
  278 + final double s = ux * vy - uy * vx;
274 c = math.acos(c); 279 c = math.acos(c);
275 return c.sign == s.sign ? c : -c; 280 return c.sign == s.sign ? c : -c;
276 } 281 }
@@ -282,35 +287,44 @@ class PdfGraphics { @@ -282,35 +287,44 @@ class PdfGraphics {
282 rx = rx.abs(); 287 rx = rx.abs();
283 ry = ry.abs(); 288 ry = ry.abs();
284 289
285 - final x1d = 0.5 * (x1 - x2);  
286 - final y1d = 0.5 * (y1 - y2); 290 + final double x1d = 0.5 * (x1 - x2);
  291 + final double y1d = 0.5 * (y1 - y2);
287 292
288 - var r = x1d * x1d / (rx * rx) + y1d * y1d / (ry * ry); 293 + double r = x1d * x1d / (rx * rx) + y1d * y1d / (ry * ry);
289 if (r > 1.0) { 294 if (r > 1.0) {
290 - var rr = math.sqrt(r); 295 + final double rr = math.sqrt(r);
291 rx *= rr; 296 rx *= rr;
292 ry *= rr; 297 ry *= rr;
293 r = x1d * x1d / (rx * rx) + y1d * y1d / (ry * ry); 298 r = x1d * x1d / (rx * rx) + y1d * y1d / (ry * ry);
294 - } else if (r != 0.0) r = 1.0 / r - 1.0; 299 + } else if (r != 0.0) {
  300 + r = 1.0 / r - 1.0;
  301 + }
295 302
296 - if (-1e-10 < r && r < 0.0) r = 0.0; 303 + if (-1e-10 < r && r < 0.0) {
  304 + r = 0.0;
  305 + }
297 306
298 r = math.sqrt(r); 307 r = math.sqrt(r);
299 - if (large == sweep) r = -r; 308 + if (large == sweep) {
  309 + r = -r;
  310 + }
300 311
301 - final cxd = (r * rx * y1d) / ry;  
302 - final cyd = -(r * ry * x1d) / rx; 312 + final double cxd = (r * rx * y1d) / ry;
  313 + final double cyd = -(r * ry * x1d) / rx;
303 314
304 - final cx = cxd + 0.5 * (x1 + x2);  
305 - final cy = cyd + 0.5 * (y1 + y2); 315 + final double cx = cxd + 0.5 * (x1 + x2);
  316 + final double cy = cyd + 0.5 * (y1 + y2);
306 317
307 - final theta = _vectorAngle(1.0, 0.0, (x1d - cxd) / rx, (y1d - cyd) / ry);  
308 - var dTheta = _vectorAngle((x1d - cxd) / rx, (y1d - cyd) / ry, 318 + final double theta =
  319 + _vectorAngle(1.0, 0.0, (x1d - cxd) / rx, (y1d - cyd) / ry);
  320 + double dTheta = _vectorAngle((x1d - cxd) / rx, (y1d - cyd) / ry,
309 (-x1d - cxd) / rx, (-y1d - cyd) / ry) % 321 (-x1d - cxd) / rx, (-y1d - cyd) / ry) %
310 (math.pi * 2.0); 322 (math.pi * 2.0);
311 if (sweep == false && dTheta > 0.0) 323 if (sweep == false && dTheta > 0.0)
312 dTheta -= math.pi * 2.0; 324 dTheta -= math.pi * 2.0;
313 - else if (sweep == true && dTheta < 0.0) dTheta += math.pi * 2.0; 325 + else if (sweep == true && dTheta < 0.0) {
  326 + dTheta += math.pi * 2.0;
  327 + }
314 _bezierArcFromCentre(cx, cy, rx, ry, -theta, -dTheta); 328 _bezierArcFromCentre(cx, cy, rx, ry, -theta, -dTheta);
315 } 329 }
316 330
@@ -330,21 +344,23 @@ class PdfGraphics { @@ -330,21 +344,23 @@ class PdfGraphics {
330 return; 344 return;
331 } 345 }
332 346
333 - final halfFragment = fragmentsAngle * 0.5;  
334 - var kappa = 347 + final double halfFragment = fragmentsAngle * 0.5;
  348 + double kappa =
335 (4.0 / 3.0 * (1.0 - math.cos(halfFragment)) / math.sin(halfFragment)) 349 (4.0 / 3.0 * (1.0 - math.cos(halfFragment)) / math.sin(halfFragment))
336 .abs(); 350 .abs();
337 351
338 - if (fragmentsAngle < 0.0) kappa = -kappa; 352 + if (fragmentsAngle < 0.0) {
  353 + kappa = -kappa;
  354 + }
339 355
340 - var theta = startAngle;  
341 - final startFragment = theta + fragmentsAngle; 356 + double theta = startAngle;
  357 + final double startFragment = theta + fragmentsAngle;
342 358
343 - var c1 = math.cos(theta);  
344 - var s1 = math.sin(theta);  
345 - for (var i = 0; i < fragmentsCount; i++) {  
346 - final c0 = c1;  
347 - final s0 = s1; 359 + double c1 = math.cos(theta);
  360 + double s1 = math.sin(theta);
  361 + for (int i = 0; i < fragmentsCount; i++) {
  362 + final double c0 = c1;
  363 + final double s0 = s1;
348 theta = startFragment + i * fragmentsAngle; 364 theta = startFragment + i * fragmentsAngle;
349 c1 = math.cos(theta); 365 c1 = math.cos(theta);
350 s1 = math.sin(theta); 366 s1 = math.sin(theta);
@@ -365,7 +381,7 @@ class PdfGraphics { @@ -365,7 +381,7 @@ class PdfGraphics {
365 /// contribute to the automatic calculations and help determine how the arc is drawn. 381 /// contribute to the automatic calculations and help determine how the arc is drawn.
366 void _bezierArc( 382 void _bezierArc(
367 double x1, double y1, double rx, double ry, double x2, double y2, 383 double x1, double y1, double rx, double ry, double x2, double y2,
368 - {large = false, sweep = false, phi = 0.0}) { 384 + {bool large = false, bool sweep = false, double phi = 0.0}) {
369 if (x1 == x2 && y1 == y2) { 385 if (x1 == x2 && y1 == y2) {
370 // From https://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes: 386 // From https://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes:
371 // If the endpoints (x1, y1) and (x2, y2) are identical, then this is 387 // If the endpoints (x1, y1) and (x2, y2) are identical, then this is
@@ -381,10 +397,10 @@ class PdfGraphics { @@ -381,10 +397,10 @@ class PdfGraphics {
381 if (phi != 0.0) { 397 if (phi != 0.0) {
382 // Our box bézier arcs can't handle rotations directly 398 // Our box bézier arcs can't handle rotations directly
383 // move to a well known point, eliminate phi and transform the other point 399 // move to a well known point, eliminate phi and transform the other point
384 - final mat = Matrix4.identity(); 400 + final Matrix4 mat = Matrix4.identity();
385 mat.translate(-x1, -y1); 401 mat.translate(-x1, -y1);
386 mat.rotateZ(-phi); 402 mat.rotateZ(-phi);
387 - final tr = mat.transform3(Vector3(x2, y2, 0.0)); 403 + final Vector3 tr = mat.transform3(Vector3(x2, y2, 0.0));
388 _endToCenterParameters(0.0, 0.0, tr[0], tr[1], large, sweep, rx, ry); 404 _endToCenterParameters(0.0, 0.0, tr[0], tr[1], large, sweep, rx, ry);
389 } else { 405 } else {
390 _endToCenterParameters(x1, y1, x2, y2, large, sweep, rx, ry); 406 _endToCenterParameters(x1, y1, x2, y2, large, sweep, rx, ry);
@@ -392,17 +408,18 @@ class PdfGraphics { @@ -392,17 +408,18 @@ class PdfGraphics {
392 } 408 }
393 409
394 /// https://github.com/deeplook/svglib/blob/master/svglib/svglib.py#L911 410 /// https://github.com/deeplook/svglib/blob/master/svglib/svglib.py#L911
395 - void drawShape(String d, {stroke = true}) {  
396 - final exp = RegExp(r"([MmZzLlHhVvCcSsQqTtAaE])|(-[\.0-9]+)|([\.0-9]+)");  
397 - final matches = exp.allMatches(d + " E"); 411 + void drawShape(String d, {bool stroke = true}) {
  412 + final RegExp exp =
  413 + RegExp(r'([MmZzLlHhVvCcSsQqTtAaE])|(-[\.0-9]+)|([\.0-9]+)');
  414 + final Iterable<Match> matches = exp.allMatches(d + ' E');
398 String action; 415 String action;
399 String lastAction; 416 String lastAction;
400 List<double> points; 417 List<double> points;
401 - PdfPoint lastControl = PdfPoint(0.0, 0.0);  
402 - PdfPoint lastPoint = PdfPoint(0.0, 0.0);  
403 - for (var m in matches) {  
404 - var a = m.group(1);  
405 - var b = m.group(0); 418 + PdfPoint lastControl = const PdfPoint(0.0, 0.0);
  419 + PdfPoint lastPoint = const PdfPoint(0.0, 0.0);
  420 + for (Match m in matches) {
  421 + final String a = m.group(1);
  422 + final String b = m.group(0);
406 423
407 if (a == null) { 424 if (a == null) {
408 points.add(double.parse(b)); 425 points.add(double.parse(b));
@@ -446,7 +463,7 @@ class PdfGraphics { @@ -446,7 +463,7 @@ class PdfGraphics {
446 lineTo(lastPoint.x, lastPoint.y); 463 lineTo(lastPoint.x, lastPoint.y);
447 break; 464 break;
448 case 'C': // cubic bezier, absolute 465 case 'C': // cubic bezier, absolute
449 - var len = 0; 466 + int len = 0;
450 while (len < points.length) { 467 while (len < points.length) {
451 curveTo(points[len + 0], points[len + 1], points[len + 2], 468 curveTo(points[len + 0], points[len + 1], points[len + 2],
452 points[len + 3], points[len + 4], points[len + 5]); 469 points[len + 3], points[len + 4], points[len + 5]);
@@ -475,7 +492,7 @@ class PdfGraphics { @@ -475,7 +492,7 @@ class PdfGraphics {
475 } 492 }
476 break; 493 break;
477 case 'c': // cubic bezier, relative 494 case 'c': // cubic bezier, relative
478 - var len = 0; 495 + int len = 0;
479 while (len < points.length) { 496 while (len < points.length) {
480 points[len + 0] += lastPoint.x; 497 points[len + 0] += lastPoint.x;
481 points[len + 1] += lastPoint.y; 498 points[len + 1] += lastPoint.y;
@@ -518,7 +535,7 @@ class PdfGraphics { @@ -518,7 +535,7 @@ class PdfGraphics {
518 // case 't': // quadratic bezier, relative 535 // case 't': // quadratic bezier, relative
519 // break; 536 // break;
520 case 'A': // elliptical arc, absolute 537 case 'A': // elliptical arc, absolute
521 - var len = 0; 538 + int len = 0;
522 while (len < points.length) { 539 while (len < points.length) {
523 _bezierArc(lastPoint.x, lastPoint.y, points[len + 0], 540 _bezierArc(lastPoint.x, lastPoint.y, points[len + 0],
524 points[len + 1], points[len + 5], points[len + 6], 541 points[len + 1], points[len + 5], points[len + 6],
@@ -530,7 +547,7 @@ class PdfGraphics { @@ -530,7 +547,7 @@ class PdfGraphics {
530 } 547 }
531 break; 548 break;
532 case 'a': // elliptical arc, relative 549 case 'a': // elliptical arc, relative
533 - var len = 0; 550 + int len = 0;
534 while (len < points.length) { 551 while (len < points.length) {
535 points[len + 5] += lastPoint.x; 552 points[len + 5] += lastPoint.x;
536 points[len + 6] += lastPoint.y; 553 points[len + 6] += lastPoint.y;
@@ -545,15 +562,17 @@ class PdfGraphics { @@ -545,15 +562,17 @@ class PdfGraphics {
545 break; 562 break;
546 case 'Z': // close path 563 case 'Z': // close path
547 case 'z': // close path 564 case 'z': // close path
548 - if (stroke) closePath(); 565 + if (stroke) {
  566 + closePath();
  567 + }
549 break; 568 break;
550 default: 569 default:
551 - print("Unknown path action: $action"); 570 + print('Unknown path action: $action');
552 } 571 }
553 } 572 }
554 lastAction = action; 573 lastAction = action;
555 action = a; 574 action = a;
556 - points = List<double>(); 575 + points = <double>[];
557 } 576 }
558 } 577 }
559 578
@@ -568,24 +587,26 @@ class PdfGraphics { @@ -568,24 +587,26 @@ class PdfGraphics {
568 // newPath() not needed here as moveto does it ;-) 587 // newPath() not needed here as moveto does it ;-)
569 moveTo(p[0].x, p[0].y); 588 moveTo(p[0].x, p[0].y);
570 589
571 - for (int i = 1; i < p.length; i++) lineTo(p[i].x, p[i].y); 590 + for (int i = 1; i < p.length; i++) {
  591 + lineTo(p[i].x, p[i].y);
  592 + }
572 } 593 }
573 594
574 void setLineCap(PdfLineCap cap) { 595 void setLineCap(PdfLineCap cap) {
575 - buf.putString("${cap.index} J\n"); 596 + buf.putString('${cap.index} J\n');
576 } 597 }
577 598
578 void setLineJoin(PdfLineCap join) { 599 void setLineJoin(PdfLineCap join) {
579 - buf.putString("${join.index} j\n"); 600 + buf.putString('${join.index} j\n');
580 } 601 }
581 602
582 void setLineWidth(double width) { 603 void setLineWidth(double width) {
583 buf.putNum(width); 604 buf.putNum(width);
584 - buf.putString(" w\n"); 605 + buf.putString(' w\n');
585 } 606 }
586 607
587 void setMiterLimit(double limit) { 608 void setMiterLimit(double limit) {
588 buf.putNum(limit); 609 buf.putNum(limit);
589 - buf.putString(" M\n"); 610 + buf.putString(' M\n');
590 } 611 }
591 } 612 }
@@ -17,26 +17,6 @@ @@ -17,26 +17,6 @@
17 part of pdf; 17 part of pdf;
18 18
19 class PdfImage extends PdfXObject { 19 class PdfImage extends PdfXObject {
20 - /// RGBA Image Data  
21 - final Uint8List image;  
22 -  
23 - /// Image width  
24 - final int width;  
25 -  
26 - /// Image height  
27 - final int height;  
28 -  
29 - /// Image has alpha channel  
30 - final bool alpha;  
31 -  
32 - String _name;  
33 -  
34 - /// Process alphaChannel only  
35 - final bool alphaChannel;  
36 -  
37 - /// The image data is a jpeg image  
38 - final bool jpeg;  
39 -  
40 /// Creates a new [PdfImage] instance. 20 /// Creates a new [PdfImage] instance.
41 /// 21 ///
42 /// @param image an [Uint8List] value 22 /// @param image an [Uint8List] value
@@ -54,49 +34,69 @@ class PdfImage extends PdfXObject { @@ -54,49 +34,69 @@ class PdfImage extends PdfXObject {
54 : assert(alphaChannel == false || alpha == true), 34 : assert(alphaChannel == false || alpha == true),
55 assert(width != null), 35 assert(width != null),
56 assert(height != null), 36 assert(height != null),
57 - super(pdfDocument, "/Image", isBinary: true) {  
58 - _name = "/Image$objser";  
59 - params["/Width"] = PdfStream.string(width.toString());  
60 - params["/Height"] = PdfStream.string(height.toString());  
61 - params["/BitsPerComponent"] = PdfStream.intNum(8); 37 + super(pdfDocument, '/Image', isBinary: true) {
  38 + _name = '/Image$objser';
  39 + params['/Width'] = PdfStream.string(width.toString());
  40 + params['/Height'] = PdfStream.string(height.toString());
  41 + params['/BitsPerComponent'] = PdfStream.intNum(8);
62 params['/Name'] = PdfStream.string(_name); 42 params['/Name'] = PdfStream.string(_name);
63 43
64 if (alphaChannel == false && alpha) { 44 if (alphaChannel == false && alpha) {
65 - var _sMask = PdfImage(pdfDocument, 45 + final PdfImage _sMask = PdfImage(pdfDocument,
66 image: image, 46 image: image,
67 width: width, 47 width: width,
68 height: height, 48 height: height,
69 alpha: alpha, 49 alpha: alpha,
70 alphaChannel: true); 50 alphaChannel: true);
71 - params["/SMask"] = PdfStream.string("${_sMask.objser} 0 R"); 51 + params['/SMask'] = PdfStream.string('${_sMask.objser} 0 R');
72 } 52 }
73 53
74 if (alphaChannel) { 54 if (alphaChannel) {
75 - params["/ColorSpace"] = PdfStream.string("/DeviceGray"); 55 + params['/ColorSpace'] = PdfStream.string('/DeviceGray');
76 } else { 56 } else {
77 - params["/ColorSpace"] = PdfStream.string("/DeviceRGB"); 57 + params['/ColorSpace'] = PdfStream.string('/DeviceRGB');
78 } 58 }
79 59
80 if (jpeg) { 60 if (jpeg) {
81 - params["/Intent"] = PdfStream.string("/RelativeColorimetric"); 61 + params['/Intent'] = PdfStream.string('/RelativeColorimetric');
82 } 62 }
83 } 63 }
84 64
  65 + /// RGBA Image Data
  66 + final Uint8List image;
  67 +
  68 + /// Image width
  69 + final int width;
  70 +
  71 + /// Image height
  72 + final int height;
  73 +
  74 + /// Image has alpha channel
  75 + final bool alpha;
  76 +
  77 + String _name;
  78 +
  79 + /// Process alphaChannel only
  80 + final bool alphaChannel;
  81 +
  82 + /// The image data is a jpeg image
  83 + final bool jpeg;
  84 +
85 /// write the pixels to the stream 85 /// write the pixels to the stream
86 @override 86 @override
87 void _prepare() { 87 void _prepare() {
88 if (jpeg) { 88 if (jpeg) {
89 buf.putBytes(image); 89 buf.putBytes(image);
90 - params["/Filter"] = PdfStream.string("/DCTDecode"); 90 + params['/Filter'] = PdfStream.string('/DCTDecode');
91 super._prepare(); 91 super._prepare();
92 return; 92 return;
93 } 93 }
94 94
95 - int w = width;  
96 - int h = height;  
97 - int s = w * h; 95 + final int w = width;
  96 + final int h = height;
  97 + final int s = w * h;
98 98
99 - Uint8List out = Uint8List(alphaChannel ? s : s * 3); 99 + final Uint8List out = Uint8List(alphaChannel ? s : s * 3);
100 100
101 if (alphaChannel) { 101 if (alphaChannel) {
102 for (int i = 0; i < s; i++) { 102 for (int i = 0; i < s; i++) {
1 /* 1 /*
2 * Copyright (C) 2017, David PHAM-VAN <dev.nfet.net@gmail.com> 2 * Copyright (C) 2017, David PHAM-VAN <dev.nfet.net@gmail.com>
3 * 3 *
4 - * Licensed under the Apache License, Version 2.0 (the "License"); 4 + * Licensed under the Apache License, Version 2.0 (the 'License');
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at 6 * You may obtain a copy of the License at
7 * 7 *
8 * http://www.apache.org/licenses/LICENSE-2.0 8 * http://www.apache.org/licenses/LICENSE-2.0
9 * 9 *
10 * Unless required by applicable law or agreed to in writing, software 10 * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS, 11 + * distributed under the License is distributed on an 'AS IS' BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
@@ -17,14 +17,6 @@ @@ -17,14 +17,6 @@
17 part of pdf; 17 part of pdf;
18 18
19 class PdfInfo extends PdfObject { 19 class PdfInfo extends PdfObject {
20 - static const String _libraryName = "https://github.com/DavBfr/dart_pdf";  
21 - final String author;  
22 - final String creator;  
23 - final String title;  
24 - final String subject;  
25 - final String keywords;  
26 - final String producer;  
27 -  
28 /// @param title Title of this document 20 /// @param title Title of this document
29 PdfInfo(PdfDocument pdfDocument, 21 PdfInfo(PdfDocument pdfDocument,
30 {this.title, 22 {this.title,
@@ -35,25 +27,39 @@ class PdfInfo extends PdfObject { @@ -35,25 +27,39 @@ class PdfInfo extends PdfObject {
35 this.producer}) 27 this.producer})
36 : super(pdfDocument, null) { 28 : super(pdfDocument, null) {
37 if (author != null) { 29 if (author != null) {
38 - params["/Author"] = PdfStream()..putLiteral(author); 30 + params['/Author'] = PdfStream()..putLiteral(author);
39 } 31 }
40 if (creator != null) { 32 if (creator != null) {
41 - params["/Creator"] = PdfStream()..putLiteral(creator); 33 + params['/Creator'] = PdfStream()..putLiteral(creator);
42 } 34 }
43 if (title != null) { 35 if (title != null) {
44 - params["/Title"] = PdfStream()..putLiteral(title); 36 + params['/Title'] = PdfStream()..putLiteral(title);
45 } 37 }
46 if (subject != null) { 38 if (subject != null) {
47 - params["/Subject"] = PdfStream()..putLiteral(subject); 39 + params['/Subject'] = PdfStream()..putLiteral(subject);
48 } 40 }
49 if (keywords != null) { 41 if (keywords != null) {
50 - params["/Keywords"] = PdfStream()..putLiteral(keywords); 42 + params['/Keywords'] = PdfStream()..putLiteral(keywords);
51 } 43 }
52 if (producer != null) { 44 if (producer != null) {
53 - params["/Producer"] = PdfStream()  
54 - ..putLiteral("$producer ($_libraryName)"); 45 + params['/Producer'] = PdfStream()
  46 + ..putLiteral('$producer ($_libraryName)');
55 } else { 47 } else {
56 - params["/Producer"] = PdfStream()..putLiteral(_libraryName); 48 + params['/Producer'] = PdfStream()..putLiteral(_libraryName);
57 } 49 }
58 } 50 }
  51 +
  52 + static const String _libraryName = 'https://github.com/DavBfr/dart_pdf';
  53 +
  54 + final String author;
  55 +
  56 + final String creator;
  57 +
  58 + final String title;
  59 +
  60 + final String subject;
  61 +
  62 + final String keywords;
  63 +
  64 + final String producer;
59 } 65 }
@@ -17,30 +17,30 @@ @@ -17,30 +17,30 @@
17 part of pdf; 17 part of pdf;
18 18
19 class PdfObject { 19 class PdfObject {
20 - /// This is the object parameters.  
21 - final params = Map<String, PdfStream>();  
22 -  
23 - /// This is the unique serial number for this object.  
24 - final int objser;  
25 -  
26 - /// This is the generation number for this object.  
27 - final int objgen = 0;  
28 -  
29 - /// This allows any Pdf object to refer to the document being constructed.  
30 - final PdfDocument pdfDocument;  
31 -  
32 /// This is usually called by extensors to this class, and sets the 20 /// This is usually called by extensors to this class, and sets the
33 /// Pdf Object Type 21 /// Pdf Object Type
34 /// @param type the Pdf Object Type 22 /// @param type the Pdf Object Type
35 PdfObject(this.pdfDocument, [String type]) 23 PdfObject(this.pdfDocument, [String type])
36 : objser = pdfDocument._genSerial() { 24 : objser = pdfDocument._genSerial() {
37 if (type != null) { 25 if (type != null) {
38 - params["/Type"] = PdfStream.string(type); 26 + params['/Type'] = PdfStream.string(type);
39 } 27 }
40 28
41 pdfDocument.objects.add(this); 29 pdfDocument.objects.add(this);
42 } 30 }
43 31
  32 + /// This is the object parameters.
  33 + final Map<String, PdfStream> params = <String, PdfStream>{};
  34 +
  35 + /// This is the unique serial number for this object.
  36 + final int objser;
  37 +
  38 + /// This is the generation number for this object.
  39 + final int objgen = 0;
  40 +
  41 + /// This allows any Pdf object to refer to the document being constructed.
  42 + final PdfDocument pdfDocument;
  43 +
44 /// Writes the object to the output stream. 44 /// Writes the object to the output stream.
45 /// This method must be overridden. 45 /// This method must be overridden.
46 /// 46 ///
@@ -66,13 +66,13 @@ class PdfObject { @@ -66,13 +66,13 @@ class PdfObject {
66 /// 66 ///
67 /// @param os OutputStream to write to 67 /// @param os OutputStream to write to
68 void _writeStart(PdfStream os) { 68 void _writeStart(PdfStream os) {
69 - os.putString("$objser $objgen obj\n"); 69 + os.putString('$objser $objgen obj\n');
70 } 70 }
71 71
72 void _writeContent(PdfStream os) { 72 void _writeContent(PdfStream os) {
73 if (params.isNotEmpty) { 73 if (params.isNotEmpty) {
74 os.putDictionary(params); 74 os.putDictionary(params);
75 - os.putString("\n"); 75 + os.putString('\n');
76 } 76 }
77 } 77 }
78 78
@@ -83,10 +83,10 @@ class PdfObject { @@ -83,10 +83,10 @@ class PdfObject {
83 /// 83 ///
84 /// @param os OutputStream to write to 84 /// @param os OutputStream to write to
85 void _writeEnd(PdfStream os) { 85 void _writeEnd(PdfStream os) {
86 - os.putString("endobj\n"); 86 + os.putString('endobj\n');
87 } 87 }
88 88
89 /// Returns the unique serial number in Pdf format 89 /// Returns the unique serial number in Pdf format
90 /// @return the serial number in Pdf format 90 /// @return the serial number in Pdf format
91 - PdfStream ref() => PdfStream.string("$objser $objgen R"); 91 + PdfStream ref() => PdfStream.string('$objser $objgen R');
92 } 92 }
@@ -17,12 +17,6 @@ @@ -17,12 +17,6 @@
17 part of pdf; 17 part of pdf;
18 18
19 class PdfObjectStream extends PdfObject { 19 class PdfObjectStream extends PdfObject {
20 - /// This holds the stream's content.  
21 - final PdfStream buf = PdfStream();  
22 -  
23 - /// defines if the stream needs to be converted to ascii85  
24 - final bool isBinary;  
25 -  
26 /// Constructs a stream. The supplied type is stored in the stream's header 20 /// Constructs a stream. The supplied type is stored in the stream's header
27 /// and is used by other objects that extend the [PdfStream] class (like 21 /// and is used by other objects that extend the [PdfStream] class (like
28 /// [PdfImage]). 22 /// [PdfImage]).
@@ -33,36 +27,42 @@ class PdfObjectStream extends PdfObject { @@ -33,36 +27,42 @@ class PdfObjectStream extends PdfObject {
33 PdfObjectStream(PdfDocument pdfDocument, {String type, this.isBinary = false}) 27 PdfObjectStream(PdfDocument pdfDocument, {String type, this.isBinary = false})
34 : super(pdfDocument, type); 28 : super(pdfDocument, type);
35 29
  30 + /// This holds the stream's content.
  31 + final PdfStream buf = PdfStream();
  32 +
  33 + /// defines if the stream needs to be converted to ascii85
  34 + final bool isBinary;
  35 +
36 List<int> _data; 36 List<int> _data;
37 37
38 @override 38 @override
39 void _prepare() { 39 void _prepare() {
40 super._prepare(); 40 super._prepare();
41 41
42 - if (params.containsKey("/Filter")) { 42 + if (params.containsKey('/Filter')) {
43 // The data is already in the right format 43 // The data is already in the right format
44 _data = buf.output(); 44 _data = buf.output();
45 } else if (pdfDocument.deflate != null) { 45 } else if (pdfDocument.deflate != null) {
46 _data = pdfDocument.deflate(buf.output()); 46 _data = pdfDocument.deflate(buf.output());
47 - params["/Filter"] = PdfStream.string("/FlateDecode"); 47 + params['/Filter'] = PdfStream.string('/FlateDecode');
48 } else if (isBinary) { 48 } else if (isBinary) {
49 // This is a Ascii85 stream 49 // This is a Ascii85 stream
50 - var e = Ascii85Encoder(); 50 + final Ascii85Encoder e = Ascii85Encoder();
51 _data = e.convert(buf.output()); 51 _data = e.convert(buf.output());
52 - params["/Filter"] = PdfStream.string("/ASCII85Decode"); 52 + params['/Filter'] = PdfStream.string('/ASCII85Decode');
53 } else { 53 } else {
54 // This is a non-deflated stream 54 // This is a non-deflated stream
55 _data = buf.output(); 55 _data = buf.output();
56 } 56 }
57 - params["/Length"] = PdfStream.intNum(_data.length); 57 + params['/Length'] = PdfStream.intNum(_data.length);
58 } 58 }
59 59
60 @override 60 @override
61 void _writeContent(PdfStream os) { 61 void _writeContent(PdfStream os) {
62 super._writeContent(os); 62 super._writeContent(os);
63 63
64 - os.putString("stream\n"); 64 + os.putString('stream\n');
65 os.putBytes(_data); 65 os.putBytes(_data);
66 - os.putString("\nendstream\n"); 66 + os.putString('\nendstream\n');
67 } 67 }
68 } 68 }
@@ -25,8 +25,17 @@ enum PdfOutlineMode { @@ -25,8 +25,17 @@ enum PdfOutlineMode {
25 } 25 }
26 26
27 class PdfOutline extends PdfObject { 27 class PdfOutline extends PdfObject {
  28 + /// Constructs a Pdf Outline object. When selected, the specified region
  29 + /// is displayed.
  30 + ///
  31 + /// @param title Title of the outline
  32 + /// @param dest The destination page
  33 + /// @param rect coordinate
  34 + PdfOutline(PdfDocument pdfDocument, {this.title, this.dest, this.rect})
  35 + : super(pdfDocument, '/Outlines');
  36 +
28 /// This holds any outlines below us 37 /// This holds any outlines below us
29 - List<PdfOutline> outlines = []; 38 + List<PdfOutline> outlines = <PdfOutline>[];
30 39
31 /// For subentries, this points to it's parent outline 40 /// For subentries, this points to it's parent outline
32 PdfOutline parent; 41 PdfOutline parent;
@@ -43,15 +52,6 @@ class PdfOutline extends PdfObject { @@ -43,15 +52,6 @@ class PdfOutline extends PdfObject {
43 /// How the destination is handled 52 /// How the destination is handled
44 PdfOutlineMode destMode = PdfOutlineMode.fitpage; 53 PdfOutlineMode destMode = PdfOutlineMode.fitpage;
45 54
46 - /// Constructs a Pdf Outline object. When selected, the specified region  
47 - /// is displayed.  
48 - ///  
49 - /// @param title Title of the outline  
50 - /// @param dest The destination page  
51 - /// @param rect coordinate  
52 - PdfOutline(PdfDocument pdfDocument, {this.title, this.dest, this.rect})  
53 - : super(pdfDocument, "/Outlines");  
54 -  
55 /// This method creates an outline, and attaches it to this one. 55 /// This method creates an outline, and attaches it to this one.
56 /// When the outline is selected, the supplied region is displayed. 56 /// When the outline is selected, the supplied region is displayed.
57 /// 57 ///
@@ -71,7 +71,7 @@ class PdfOutline extends PdfObject { @@ -71,7 +71,7 @@ class PdfOutline extends PdfObject {
71 /// @param h height of region in User space 71 /// @param h height of region in User space
72 /// @return [PdfOutline] object created, for creating sub-outlines 72 /// @return [PdfOutline] object created, for creating sub-outlines
73 PdfOutline add({String title, PdfPage dest, PdfRect rect}) { 73 PdfOutline add({String title, PdfPage dest, PdfRect rect}) {
74 - PdfOutline outline = 74 + final PdfOutline outline =
75 PdfOutline(pdfDocument, title: title, dest: dest, rect: rect); 75 PdfOutline(pdfDocument, title: title, dest: dest, rect: rect);
76 // Tell the outline of ourselves 76 // Tell the outline of ourselves
77 outline.parent = this; 77 outline.parent = this;
@@ -85,49 +85,49 @@ class PdfOutline extends PdfObject { @@ -85,49 +85,49 @@ class PdfOutline extends PdfObject {
85 85
86 // These are for kids only 86 // These are for kids only
87 if (parent != null) { 87 if (parent != null) {
88 - params["/Title"] = PdfStream.string(title);  
89 - var dests = List<PdfStream>(); 88 + params['/Title'] = PdfStream.string(title);
  89 + final List<PdfStream> dests = <PdfStream>[];
90 dests.add(dest.ref()); 90 dests.add(dest.ref());
91 91
92 if (destMode == PdfOutlineMode.fitpage) { 92 if (destMode == PdfOutlineMode.fitpage) {
93 - dests.add(PdfStream.string("/Fit")); 93 + dests.add(PdfStream.string('/Fit'));
94 } else { 94 } else {
95 dests.add(PdfStream.string( 95 dests.add(PdfStream.string(
96 - "/FitR ${rect.left} ${rect.bottom} ${rect.right} ${rect.top}")); 96 + '/FitR ${rect.left} ${rect.bottom} ${rect.right} ${rect.top}'));
97 } 97 }
98 - params["/Parent"] = parent.ref();  
99 - params["/Dest"] = PdfStream.array(dests); 98 + params['/Parent'] = parent.ref();
  99 + params['/Dest'] = PdfStream.array(dests);
100 100
101 // were a descendent, so by default we are closed. Find out how many 101 // were a descendent, so by default we are closed. Find out how many
102 // entries are below us 102 // entries are below us
103 - int c = descendants(); 103 + final int c = descendants();
104 if (c > 0) { 104 if (c > 0) {
105 - params["/Count"] = PdfStream.intNum(-c); 105 + params['/Count'] = PdfStream.intNum(-c);
106 } 106 }
107 107
108 - int index = parent.getIndex(this); 108 + final int index = parent.getIndex(this);
109 if (index > 0) { 109 if (index > 0) {
110 // Now if were not the first, then we have a /Prev node 110 // Now if were not the first, then we have a /Prev node
111 - params["/Prev"] = parent.getNode(index - 1).ref(); 111 + params['/Prev'] = parent.getNode(index - 1).ref();
112 } 112 }
113 113
114 if (index < parent.getLast()) { 114 if (index < parent.getLast()) {
115 // We have a /Next node 115 // We have a /Next node
116 - params["/Next"] = parent.getNode(index + 1).ref(); 116 + params['/Next'] = parent.getNode(index + 1).ref();
117 } 117 }
118 } else { 118 } else {
119 // the number of outlines in this document 119 // the number of outlines in this document
120 // were the top level node, so all are open by default 120 // were the top level node, so all are open by default
121 - params["/Count"] = PdfStream.intNum(outlines.length); 121 + params['/Count'] = PdfStream.intNum(outlines.length);
122 } 122 }
123 123
124 // These only valid if we have children 124 // These only valid if we have children
125 if (outlines.isNotEmpty) { 125 if (outlines.isNotEmpty) {
126 // the number of the first outline in list 126 // the number of the first outline in list
127 - params["/First"] = outlines[0].ref(); 127 + params['/First'] = outlines[0].ref();
128 128
129 // the number of the last outline in list 129 // the number of the last outline in list
130 - params["/Last"] = outlines[outlines.length - 1].ref(); 130 + params['/Last'] = outlines[outlines.length - 1].ref();
131 } 131 }
132 } 132 }
133 133
@@ -17,11 +17,19 @@ @@ -17,11 +17,19 @@
17 part of pdf; 17 part of pdf;
18 18
19 class PdfOutput { 19 class PdfOutput {
  20 + /// This creates a Pdf [PdfStream]
  21 + ///
  22 + /// @param os The output stream to write the Pdf file to.
  23 + PdfOutput(this.os) {
  24 + os.putString('%PDF-1.4\n');
  25 + os.putBytes(const <int>[0x25, 0xC2, 0xA5, 0xC2, 0xB1, 0xC3, 0xAB, 0x0A]);
  26 + }
  27 +
20 /// This is the actual [PdfStream] used to write to. 28 /// This is the actual [PdfStream] used to write to.
21 final PdfStream os; 29 final PdfStream os;
22 30
23 /// This vector contains offsets of each object 31 /// This vector contains offsets of each object
24 - List<PdfXref> offsets = []; 32 + List<PdfXref> offsets = <PdfXref>[];
25 33
26 /// This is used to track the /Root object (catalog) 34 /// This is used to track the /Root object (catalog)
27 PdfObject rootID; 35 PdfObject rootID;
@@ -29,22 +37,18 @@ class PdfOutput { @@ -29,22 +37,18 @@ class PdfOutput {
29 /// This is used to track the /Info object (info) 37 /// This is used to track the /Info object (info)
30 PdfObject infoID; 38 PdfObject infoID;
31 39
32 - /// This creates a Pdf [PdfStream]  
33 - ///  
34 - /// @param os The output stream to write the Pdf file to.  
35 - PdfOutput(this.os) {  
36 - os.putString("%PDF-1.4\n");  
37 - os.putBytes([0x25, 0xC2, 0xA5, 0xC2, 0xB1, 0xC3, 0xAB, 0x0A]);  
38 - }  
39 -  
40 /// This method writes a [PdfObject] to the stream. 40 /// This method writes a [PdfObject] to the stream.
41 /// 41 ///
42 /// @param ob [PdfObject] Object to write 42 /// @param ob [PdfObject] Object to write
43 void write(PdfObject ob) { 43 void write(PdfObject ob) {
44 // Check the object to see if it's one that is needed in the trailer 44 // Check the object to see if it's one that is needed in the trailer
45 // object 45 // object
46 - if (ob is PdfCatalog) rootID = ob;  
47 - if (ob is PdfInfo) infoID = ob; 46 + if (ob is PdfCatalog) {
  47 + rootID = ob;
  48 + }
  49 + if (ob is PdfInfo) {
  50 + infoID = ob;
  51 + }
48 52
49 offsets.add(PdfXref(ob.objser, os.offset)); 53 offsets.add(PdfXref(ob.objser, os.offset));
50 ob._write(os); 54 ob._write(os);
@@ -52,9 +56,9 @@ class PdfOutput { @@ -52,9 +56,9 @@ class PdfOutput {
52 56
53 /// This closes the Stream, writing the xref table 57 /// This closes the Stream, writing the xref table
54 void close() { 58 void close() {
55 - int xref = os.offset; 59 + final int xref = os.offset;
56 60
57 - os.putString("xref\n"); 61 + os.putString('xref\n');
58 62
59 // Now a single subsection for object 0 63 // Now a single subsection for object 0
60 //os.write("0 1\n0000000000 65535 f \n"); 64 //os.write("0 1\n0000000000 65535 f \n");
@@ -63,19 +67,21 @@ class PdfOutput { @@ -63,19 +67,21 @@ class PdfOutput {
63 // but just in case: 67 // but just in case:
64 int firstid = 0; // First id in block 68 int firstid = 0; // First id in block
65 int lastid = -1; // The last id used 69 int lastid = -1; // The last id used
66 - var block = []; // xrefs in this block 70 + final List<PdfXref> block = <PdfXref>[]; // xrefs in this block
67 71
68 // We need block 0 to exist 72 // We need block 0 to exist
69 block.add(PdfXref(0, 0, generation: 65535)); 73 block.add(PdfXref(0, 0, generation: 65535));
70 74
71 for (PdfXref x in offsets) { 75 for (PdfXref x in offsets) {
72 - if (firstid == -1) firstid = x.id; 76 + if (firstid == -1) {
  77 + firstid = x.id;
  78 + }
73 79
74 // check to see if block is in range (-1 means empty) 80 // check to see if block is in range (-1 means empty)
75 if (lastid > -1 && x.id != (lastid + 1)) { 81 if (lastid > -1 && x.id != (lastid + 1)) {
76 // no, so write this block, and reset 82 // no, so write this block, and reset
77 writeblock(firstid, block); 83 writeblock(firstid, block);
78 - block = []; 84 + block.clear();
79 firstid = -1; 85 firstid = -1;
80 } 86 }
81 87
@@ -85,45 +91,46 @@ class PdfOutput { @@ -85,45 +91,46 @@ class PdfOutput {
85 } 91 }
86 92
87 // now write the last block 93 // now write the last block
88 - if (firstid > -1) writeblock(firstid, block); 94 + if (firstid > -1) {
  95 + writeblock(firstid, block);
  96 + }
89 97
90 // now the trailer object 98 // now the trailer object
91 - os.putString("trailer\n<<\n"); 99 + os.putString('trailer\n<<\n');
92 100
93 // the number of entries (REQUIRED) 101 // the number of entries (REQUIRED)
94 - os.putString("/Size "); 102 + os.putString('/Size ');
95 os.putString((offsets.length + 1).toString()); 103 os.putString((offsets.length + 1).toString());
96 - os.putString("\n"); 104 + os.putString('\n');
97 105
98 // the /Root catalog indirect reference (REQUIRED) 106 // the /Root catalog indirect reference (REQUIRED)
99 if (rootID != null) { 107 if (rootID != null) {
100 - os.putString("/Root "); 108 + os.putString('/Root ');
101 os.putStream(rootID.ref()); 109 os.putStream(rootID.ref());
102 - os.putString("\n"); 110 + os.putString('\n');
103 } else 111 } else
104 - throw Exception("Root object is not present in document"); 112 + throw Exception('Root object is not present in document');
105 113
106 // the /Info reference (OPTIONAL) 114 // the /Info reference (OPTIONAL)
107 if (infoID != null) { 115 if (infoID != null) {
108 - os.putString("/Info "); 116 + os.putString('/Info ');
109 os.putStream(infoID.ref()); 117 os.putStream(infoID.ref());
110 - os.putString("\n"); 118 + os.putString('\n');
111 } 119 }
112 120
113 // end the trailer object 121 // end the trailer object
114 - os.putString(">>\nstartxref\n$xref\n%%EOF\n"); 122 + os.putString('>>\nstartxref\n$xref\n%%EOF\n');
115 } 123 }
116 124
117 /// Writes a block of references to the Pdf file 125 /// Writes a block of references to the Pdf file
118 /// @param firstid ID of the first reference in this block 126 /// @param firstid ID of the first reference in this block
119 /// @param block Vector containing the references in this block 127 /// @param block Vector containing the references in this block
120 - void writeblock(int firstid, var block) {  
121 - os.putString("$firstid ${block.length}\n");  
122 - //os.write("\n0000000000 65535 f\n"); 128 + void writeblock(int firstid, List<PdfXref> block) {
  129 + os.putString('$firstid ${block.length}\n');
123 130
124 for (PdfXref x in block) { 131 for (PdfXref x in block) {
125 os.putString(x.ref()); 132 os.putString(x.ref());
126 - os.putString("\n"); 133 + os.putString('\n');
127 } 134 }
128 } 135 }
129 } 136 }
@@ -17,36 +17,36 @@ @@ -17,36 +17,36 @@
17 part of pdf; 17 part of pdf;
18 18
19 class PdfPage extends PdfObject { 19 class PdfPage extends PdfObject {
  20 + /// This constructs a Page object, which will hold any contents for this
  21 + /// page.
  22 + ///
  23 + /// Once created, it is added to the document via the [PdfDocument.add()] method.
  24 + ///
  25 + /// @param pdfDocument Document
  26 + /// @param pageFormat [PdfPageFormat] describing the page size
  27 + PdfPage(PdfDocument pdfDocument, {this.pageFormat = PdfPageFormat.a4})
  28 + : super(pdfDocument, '/Page') {
  29 + pdfDocument.pdfPageList.pages.add(this);
  30 + }
  31 +
20 /// This is this page format, ie the size of the page, margins, and rotation 32 /// This is this page format, ie the size of the page, margins, and rotation
21 final PdfPageFormat pageFormat; 33 final PdfPageFormat pageFormat;
22 34
23 /// This holds the contents of the page. 35 /// This holds the contents of the page.
24 - List<PdfObjectStream> contents = []; 36 + List<PdfObjectStream> contents = <PdfObjectStream>[];
25 37
26 /// Object ID that contains a thumbnail sketch of the page. 38 /// Object ID that contains a thumbnail sketch of the page.
27 /// -1 indicates no thumbnail. 39 /// -1 indicates no thumbnail.
28 PdfObject thumbnail; 40 PdfObject thumbnail;
29 41
30 /// This holds any Annotations contained within this page. 42 /// This holds any Annotations contained within this page.
31 - List<PdfAnnot> annotations = []; 43 + List<PdfAnnot> annotations = <PdfAnnot>[];
32 44
33 /// The fonts associated with this page 45 /// The fonts associated with this page
34 - final fonts = Map<String, PdfFont>(); 46 + final Map<String, PdfFont> fonts = <String, PdfFont>{};
35 47
36 /// The xobjects or other images in the pdf 48 /// The xobjects or other images in the pdf
37 - final xObjects = Map<String, PdfXObject>();  
38 -  
39 - /// This constructs a Page object, which will hold any contents for this  
40 - /// page.  
41 - ///  
42 - /// Once created, it is added to the document via the [PdfDocument.add()] method.  
43 - ///  
44 - /// @param pdfDocument Document  
45 - /// @param pageFormat [PdfPageFormat] describing the page size  
46 - PdfPage(PdfDocument pdfDocument, {this.pageFormat = PdfPageFormat.a4})  
47 - : super(pdfDocument, "/Page") {  
48 - pdfDocument.pdfPageList.pages.add(this);  
49 - } 49 + final Map<String, PdfXObject> xObjects = <String, PdfXObject>{};
50 50
51 /// This returns a [PdfGraphics] object, which can then be used to render 51 /// This returns a [PdfGraphics] object, which can then be used to render
52 /// on to this page. If a previous [PdfGraphics] object was used, this object 52 /// on to this page. If a previous [PdfGraphics] object was used, this object
@@ -55,8 +55,8 @@ class PdfPage extends PdfObject { @@ -55,8 +55,8 @@ class PdfPage extends PdfObject {
55 /// 55 ///
56 /// @return a new [PdfGraphics] object to be used to draw this page. 56 /// @return a new [PdfGraphics] object to be used to draw this page.
57 PdfGraphics getGraphics() { 57 PdfGraphics getGraphics() {
58 - var stream = PdfObjectStream(pdfDocument);  
59 - var g = PdfGraphics(this, stream.buf); 58 + final PdfObjectStream stream = PdfObjectStream(pdfDocument);
  59 + final PdfGraphics g = PdfGraphics(this, stream.buf);
60 contents.add(stream); 60 contents.add(stream);
61 return g; 61 return g;
62 } 62 }
@@ -77,11 +77,11 @@ class PdfPage extends PdfObject { @@ -77,11 +77,11 @@ class PdfPage extends PdfObject {
77 super._prepare(); 77 super._prepare();
78 78
79 // the /Parent pages object 79 // the /Parent pages object
80 - params["/Parent"] = pdfDocument.pdfPageList.ref(); 80 + params['/Parent'] = pdfDocument.pdfPageList.ref();
81 81
82 // the /MediaBox for the page size 82 // the /MediaBox for the page size
83 - params["/MediaBox"] = PdfStream()  
84 - ..putStringArray([0, 0, pageFormat.width, pageFormat.height]); 83 + params['/MediaBox'] = PdfStream()
  84 + ..putNumArray(<double>[0.0, 0.0, pageFormat.width, pageFormat.height]);
85 85
86 // Rotation (if not zero) 86 // Rotation (if not zero)
87 // if(rotate!=0) { 87 // if(rotate!=0) {
@@ -93,36 +93,36 @@ class PdfPage extends PdfObject { @@ -93,36 +93,36 @@ class PdfPage extends PdfObject {
93 // the /Contents pages object 93 // the /Contents pages object
94 if (contents.isNotEmpty) { 94 if (contents.isNotEmpty) {
95 if (contents.length == 1) { 95 if (contents.length == 1) {
96 - params["/Contents"] = contents[0].ref(); 96 + params['/Contents'] = contents[0].ref();
97 } else { 97 } else {
98 - params["/Contents"] = PdfStream()..putObjectArray(contents); 98 + params['/Contents'] = PdfStream()..putObjectArray(contents);
99 } 99 }
100 } 100 }
101 101
102 // Now the resources 102 // Now the resources
103 /// This holds any resources for this page 103 /// This holds any resources for this page
104 - final resources = Map<String, PdfStream>(); 104 + final Map<String, PdfStream> resources = <String, PdfStream>{};
105 105
106 // fonts 106 // fonts
107 if (fonts.isNotEmpty) { 107 if (fonts.isNotEmpty) {
108 - resources["/Font"] = PdfStream()..putObjectDictionary(fonts); 108 + resources['/Font'] = PdfStream()..putObjectDictionary(fonts);
109 } 109 }
110 110
111 // Now the XObjects 111 // Now the XObjects
112 if (xObjects.isNotEmpty) { 112 if (xObjects.isNotEmpty) {
113 - resources["/XObject"] = PdfStream()..putObjectDictionary(xObjects); 113 + resources['/XObject'] = PdfStream()..putObjectDictionary(xObjects);
114 } 114 }
115 115
116 - params["/Resources"] = PdfStream.dictionary(resources); 116 + params['/Resources'] = PdfStream.dictionary(resources);
117 117
118 // The thumbnail 118 // The thumbnail
119 if (thumbnail != null) { 119 if (thumbnail != null) {
120 - params["/Thumb"] = thumbnail.ref(); 120 + params['/Thumb'] = thumbnail.ref();
121 } 121 }
122 122
123 // The /Annots object 123 // The /Annots object
124 if (annotations.isNotEmpty) { 124 if (annotations.isNotEmpty) {
125 - params["/Annots"] = PdfStream()..putObjectArray(annotations); 125 + params['/Annots'] = PdfStream()..putObjectArray(annotations);
126 } 126 }
127 } 127 }
128 } 128 }
@@ -17,25 +17,6 @@ @@ -17,25 +17,6 @@
17 part of pdf; 17 part of pdf;
18 18
19 class PdfPageFormat { 19 class PdfPageFormat {
20 - static const a3 = PdfPageFormat(29.7 * cm, 42 * cm, marginAll: 2.0 * cm);  
21 - static const a4 = PdfPageFormat(21.0 * cm, 29.7 * cm, marginAll: 2.0 * cm);  
22 - static const a5 = PdfPageFormat(14.8 * cm, 21.0 * cm, marginAll: 2.0 * cm);  
23 - static const letter = PdfPageFormat(8.5 * inch, 11.0 * inch, marginAll: inch);  
24 - static const legal = PdfPageFormat(8.5 * inch, 14.0 * inch, marginAll: inch);  
25 -  
26 - static const point = 1.0;  
27 - static const inch = 72.0;  
28 - static const cm = inch / 2.54;  
29 - static const mm = inch / 25.4;  
30 -  
31 - final double width;  
32 - final double height;  
33 -  
34 - final double marginTop;  
35 - final double marginBottom;  
36 - final double marginLeft;  
37 - final double marginRight;  
38 -  
39 const PdfPageFormat(this.width, this.height, 20 const PdfPageFormat(this.width, this.height,
40 {double marginTop = 0.0, 21 {double marginTop = 0.0,
41 double marginBottom = 0.0, 22 double marginBottom = 0.0,
@@ -47,6 +28,30 @@ class PdfPageFormat { @@ -47,6 +28,30 @@ class PdfPageFormat {
47 marginLeft = marginAll ?? marginLeft, 28 marginLeft = marginAll ?? marginLeft,
48 marginRight = marginAll ?? marginRight; 29 marginRight = marginAll ?? marginRight;
49 30
  31 + static const PdfPageFormat a3 =
  32 + PdfPageFormat(29.7 * cm, 42 * cm, marginAll: 2.0 * cm);
  33 + static const PdfPageFormat a4 =
  34 + PdfPageFormat(21.0 * cm, 29.7 * cm, marginAll: 2.0 * cm);
  35 + static const PdfPageFormat a5 =
  36 + PdfPageFormat(14.8 * cm, 21.0 * cm, marginAll: 2.0 * cm);
  37 + static const PdfPageFormat letter =
  38 + PdfPageFormat(8.5 * inch, 11.0 * inch, marginAll: inch);
  39 + static const PdfPageFormat legal =
  40 + PdfPageFormat(8.5 * inch, 14.0 * inch, marginAll: inch);
  41 +
  42 + static const double point = 1.0;
  43 + static const double inch = 72.0;
  44 + static const double cm = inch / 2.54;
  45 + static const double mm = inch / 25.4;
  46 +
  47 + final double width;
  48 + final double height;
  49 +
  50 + final double marginTop;
  51 + final double marginBottom;
  52 + final double marginLeft;
  53 + final double marginRight;
  54 +
50 PdfPageFormat copyWith( 55 PdfPageFormat copyWith(
51 {double width, 56 {double width,
52 double height, 57 double height,
@@ -80,6 +85,6 @@ class PdfPageFormat { @@ -80,6 +85,6 @@ class PdfPageFormat {
80 85
81 @override 86 @override
82 String toString() { 87 String toString() {
83 - return "${width}x$height"; 88 + return '${width}x$height';
84 } 89 }
85 } 90 }
@@ -17,11 +17,11 @@ @@ -17,11 +17,11 @@
17 part of pdf; 17 part of pdf;
18 18
19 class PdfPageList extends PdfObject { 19 class PdfPageList extends PdfObject {
20 - /// This holds the pages  
21 - final List<PdfPage> pages = [];  
22 -  
23 /// This constructs a [PdfPageList] object. 20 /// This constructs a [PdfPageList] object.
24 - PdfPageList(PdfDocument pdfDocument) : super(pdfDocument, "/Pages"); 21 + PdfPageList(PdfDocument pdfDocument) : super(pdfDocument, '/Pages');
  22 +
  23 + /// This holds the pages
  24 + final List<PdfPage> pages = <PdfPage>[];
25 25
26 /// This returns a specific page. Used by the Pdf class. 26 /// This returns a specific page. Used by the Pdf class.
27 /// @param page page number to return 27 /// @param page page number to return
@@ -32,7 +32,7 @@ class PdfPageList extends PdfObject { @@ -32,7 +32,7 @@ class PdfPageList extends PdfObject {
32 void _prepare() { 32 void _prepare() {
33 super._prepare(); 33 super._prepare();
34 34
35 - params["/Kids"] = PdfStream()..putObjectArray(pages);  
36 - params["/Count"] = PdfStream.intNum(pages.length); 35 + params['/Kids'] = PdfStream()..putObjectArray(pages);
  36 + params['/Count'] = PdfStream.intNum(pages.length);
37 } 37 }
38 } 38 }
@@ -18,6 +18,8 @@ part of pdf; @@ -18,6 +18,8 @@ part of pdf;
18 18
19 @immutable 19 @immutable
20 class PdfPoint { 20 class PdfPoint {
  21 + const PdfPoint(this.x, this.y);
  22 +
21 final double x, y; 23 final double x, y;
22 24
23 @deprecated 25 @deprecated
@@ -26,10 +28,8 @@ class PdfPoint { @@ -26,10 +28,8 @@ class PdfPoint {
26 @deprecated 28 @deprecated
27 double get h => y; 29 double get h => y;
28 30
29 - const PdfPoint(this.x, this.y);  
30 -  
31 - static const zero = PdfPoint(0.0, 0.0); 31 + static const PdfPoint zero = PdfPoint(0.0, 0.0);
32 32
33 @override 33 @override
34 - String toString() => "PdfPoint($x, $y)"; 34 + String toString() => 'PdfPoint($x, $y)';
35 } 35 }
@@ -17,12 +17,12 @@ @@ -17,12 +17,12 @@
17 part of pdf; 17 part of pdf;
18 18
19 class PdfPolygon { 19 class PdfPolygon {
20 - List<PdfPoint> points;  
21 -  
22 PdfPolygon(this.points); 20 PdfPolygon(this.points);
23 21
  22 + List<PdfPoint> points;
  23 +
24 PdfRect getBounds() { 24 PdfRect getBounds() {
25 - // TODO: Implement properly 25 + // TODO(me): Implement properly
26 return const PdfRect(0.0, 0.0, 0.0, 0.0); 26 return const PdfRect(0.0, 0.0, 0.0, 0.0);
27 } 27 }
28 } 28 }
@@ -18,10 +18,6 @@ part of pdf; @@ -18,10 +18,6 @@ part of pdf;
18 18
19 @immutable 19 @immutable
20 class PdfRect { 20 class PdfRect {
21 - final double x, y, width, height;  
22 -  
23 - static const zero = PdfRect(0.0, 0.0, 0.0, 0.0);  
24 -  
25 const PdfRect(this.x, this.y, this.width, this.height); 21 const PdfRect(this.x, this.y, this.width, this.height);
26 22
27 factory PdfRect.fromLTRB( 23 factory PdfRect.fromLTRB(
@@ -33,6 +29,10 @@ class PdfRect { @@ -33,6 +29,10 @@ class PdfRect {
33 return PdfRect(offset.x, offset.y, size.x, size.y); 29 return PdfRect(offset.x, offset.y, size.x, size.y);
34 } 30 }
35 31
  32 + final double x, y, width, height;
  33 +
  34 + static const PdfRect zero = PdfRect(0.0, 0.0, 0.0, 0.0);
  35 +
36 double get left => x; 36 double get left => x;
37 double get bottom => y; 37 double get bottom => y;
38 double get right => x + width; 38 double get right => x + width;
@@ -52,7 +52,7 @@ class PdfRect { @@ -52,7 +52,7 @@ class PdfRect {
52 double get h => height; 52 double get h => height;
53 53
54 @override 54 @override
55 - String toString() => "PdfRect($x, $y, $width, $height)"; 55 + String toString() => 'PdfRect($x, $y, $width, $height)';
56 56
57 PdfRect operator *(double factor) { 57 PdfRect operator *(double factor) {
58 return PdfRect(x * factor, y * factor, width * factor, height * factor); 58 return PdfRect(x * factor, y * factor, width * factor, height * factor);
@@ -17,8 +17,8 @@ @@ -17,8 +17,8 @@
17 part of pdf; 17 part of pdf;
18 18
19 class PdfStream { 19 class PdfStream {
20 - static const precision = 5;  
21 - final _stream = List<int>(); 20 + static const int precision = 5;
  21 + final List<int> _stream = <int>[];
22 22
23 void putStream(PdfStream s) { 23 void putStream(PdfStream s) {
24 _stream.addAll(s._stream); 24 _stream.addAll(s._stream);
@@ -52,7 +52,11 @@ class PdfStream { @@ -52,7 +52,11 @@ class PdfStream {
52 } 52 }
53 53
54 void putNumList(List<double> d) { 54 void putNumList(List<double> d) {
55 - putString(d.map((v) => v.toStringAsFixed(precision)).join(" ")); 55 + putString(d.map((double v) => v.toStringAsFixed(precision)).join(' '));
  56 + }
  57 +
  58 + void putIntList(List<int> d) {
  59 + putString(d.map((int v) => v.toString()).join(' '));
56 } 60 }
57 61
58 static PdfStream num(double d) => PdfStream()..putNum(d); 62 static PdfStream num(double d) => PdfStream()..putNum(d);
@@ -61,7 +65,7 @@ class PdfStream { @@ -61,7 +65,7 @@ class PdfStream {
61 /// Escape special characters 65 /// Escape special characters
62 /// \ddd Character code ddd (octal) 66 /// \ddd Character code ddd (octal)
63 void putTextBytes(List<int> s) { 67 void putTextBytes(List<int> s) {
64 - for (var c in s) { 68 + for (int c in s) {
65 switch (c) { 69 switch (c) {
66 case 0x0a: // \n Line feed (LF) 70 case 0x0a: // \n Line feed (LF)
67 _stream.add(0x5c); 71 _stream.add(0x5c);
@@ -109,61 +113,73 @@ class PdfStream { @@ -109,61 +113,73 @@ class PdfStream {
109 113
110 void putLiteral(String s) { 114 void putLiteral(String s) {
111 putBytes(latin1.encode('(')); 115 putBytes(latin1.encode('('));
112 - putBytes([0xfe, 0xff]); 116 + putBytes(<int>[0xfe, 0xff]);
113 putTextBytes(encodeUtf16be(s)); 117 putTextBytes(encodeUtf16be(s));
114 putBytes(latin1.encode(')')); 118 putBytes(latin1.encode(')'));
115 } 119 }
116 120
117 void putBool(bool value) { 121 void putBool(bool value) {
118 - putString(value ? "true" : "false"); 122 + putString(value ? 'true' : 'false');
119 } 123 }
120 124
121 void putArray(List<PdfStream> values) { 125 void putArray(List<PdfStream> values) {
122 - putString("[");  
123 - for (var val in values) { 126 + putString('[');
  127 + for (PdfStream val in values) {
124 putStream(val); 128 putStream(val);
125 - putString(" "); 129 + putString(' ');
126 } 130 }
127 - putString("]"); 131 + putString(']');
128 } 132 }
129 133
130 void putObjectArray(List<PdfObject> values) { 134 void putObjectArray(List<PdfObject> values) {
131 - putString("[");  
132 - for (var val in values) { 135 + putString('[');
  136 + for (PdfObject val in values) {
133 putStream(val.ref()); 137 putStream(val.ref());
134 - putString(" "); 138 + putString(' ');
135 } 139 }
136 - putString("]"); 140 + putString(']');
  141 + }
  142 +
  143 + void putStringArray(List<String> values) {
  144 + putString('[' + values.join(' ') + ']');
  145 + }
  146 +
  147 + void putNumArray(List<double> values) {
  148 + putString('[');
  149 + putNumList(values);
  150 + putString(']');
137 } 151 }
138 152
139 - void putStringArray(List<dynamic> values) {  
140 - putString("[" + values.join(" ") + "]"); 153 + void putIntArray(List<int> values) {
  154 + putString('[');
  155 + putIntList(values);
  156 + putString(']');
141 } 157 }
142 158
143 static PdfStream array(List<PdfStream> values) => 159 static PdfStream array(List<PdfStream> values) =>
144 PdfStream()..putArray(values); 160 PdfStream()..putArray(values);
145 161
146 void putDictionary(Map<String, PdfStream> values) { 162 void putDictionary(Map<String, PdfStream> values) {
147 - putString("<< ");  
148 - values.forEach((k, v) {  
149 - putString("$k "); 163 + putString('<< ');
  164 + values.forEach((String k, PdfStream v) {
  165 + putString('$k ');
150 putStream(v); 166 putStream(v);
151 - putString("\n"); 167 + putString('\n');
152 }); 168 });
153 - putString(">>"); 169 + putString('>>');
154 } 170 }
155 171
156 static PdfStream dictionary(Map<String, PdfStream> values) => 172 static PdfStream dictionary(Map<String, PdfStream> values) =>
157 PdfStream()..putDictionary(values); 173 PdfStream()..putDictionary(values);
158 174
159 void putObjectDictionary(Map<String, PdfObject> values) { 175 void putObjectDictionary(Map<String, PdfObject> values) {
160 - putString("<< ");  
161 - values.forEach((k, v) {  
162 - putString("$k "); 176 + putString('<< ');
  177 + values.forEach((String k, PdfObject v) {
  178 + putString('$k ');
163 putStream(v.ref()); 179 putStream(v.ref());
164 - putString(" "); 180 + putString(' ');
165 }); 181 });
166 - putString(">>"); 182 + putString('>>');
167 } 183 }
168 184
169 int get offset => _stream.length; 185 int get offset => _stream.length;
@@ -17,29 +17,12 @@ @@ -17,29 +17,12 @@
17 part of pdf; 17 part of pdf;
18 18
19 class TtfParser { 19 class TtfParser {
20 - static const _HEAD = "head";  
21 - static const _NAME = "name";  
22 - static const _HMTX = "hmtx";  
23 - static const _HHEA = "hhea";  
24 - static const _CMAP = "cmap";  
25 - static const _MAXP = "maxp";  
26 - static const _LOCA = "loca";  
27 - static const _GLYF = "glyf";  
28 -  
29 - final ByteData bytes;  
30 - final _tableOffsets = Map<String, int>();  
31 - String _fontName;  
32 - final advanceWidth = List<double>();  
33 - final charToGlyphIndexMap = Map<int, int>();  
34 - final glyphOffsets = List<int>();  
35 - final glyphInfoMap = Map<int, PdfRect>();  
36 -  
37 TtfParser(this.bytes) { 20 TtfParser(this.bytes) {
38 - final numTables = bytes.getUint16(4); 21 + final int numTables = bytes.getUint16(4);
39 22
40 - for (var i = 0; i < numTables; i++) {  
41 - final name = utf8.decode(bytes.buffer.asUint8List(i * 16 + 12, 4));  
42 - final offset = bytes.getUint32(i * 16 + 20); 23 + for (int i = 0; i < numTables; i++) {
  24 + final String name = utf8.decode(bytes.buffer.asUint8List(i * 16 + 12, 4));
  25 + final int offset = bytes.getUint32(i * 16 + 20);
43 _tableOffsets[name] = offset; 26 _tableOffsets[name] = offset;
44 } 27 }
45 28
@@ -50,38 +33,55 @@ class TtfParser { @@ -50,38 +33,55 @@ class TtfParser {
50 _parseGlyf(); 33 _parseGlyf();
51 } 34 }
52 35
53 - get unitsPerEm => bytes.getUint16(_tableOffsets[_HEAD] + 18); 36 + static const String _HEAD = 'head';
  37 + static const String _NAME = 'name';
  38 + static const String _HMTX = 'hmtx';
  39 + static const String _HHEA = 'hhea';
  40 + static const String _CMAP = 'cmap';
  41 + static const String _MAXP = 'maxp';
  42 + static const String _LOCA = 'loca';
  43 + static const String _GLYF = 'glyf';
  44 +
  45 + final ByteData bytes;
  46 + final Map<String, int> _tableOffsets = <String, int>{};
  47 + String _fontName;
  48 + final List<double> advanceWidth = <double>[];
  49 + final Map<int, int> charToGlyphIndexMap = <int, int>{};
  50 + final List<int> glyphOffsets = <int>[];
  51 + final Map<int, PdfRect> glyphInfoMap = <int, PdfRect>{};
  52 +
  53 + int get unitsPerEm => bytes.getUint16(_tableOffsets[_HEAD] + 18);
54 54
55 - get xMin => bytes.getInt16(_tableOffsets[_HEAD] + 36); 55 + int get xMin => bytes.getInt16(_tableOffsets[_HEAD] + 36);
56 56
57 - get yMin => bytes.getInt16(_tableOffsets[_HEAD] + 38); 57 + int get yMin => bytes.getInt16(_tableOffsets[_HEAD] + 38);
58 58
59 - get xMax => bytes.getInt16(_tableOffsets[_HEAD] + 40); 59 + int get xMax => bytes.getInt16(_tableOffsets[_HEAD] + 40);
60 60
61 - get yMax => bytes.getInt16(_tableOffsets[_HEAD] + 42); 61 + int get yMax => bytes.getInt16(_tableOffsets[_HEAD] + 42);
62 62
63 - get indexToLocFormat => bytes.getInt16(_tableOffsets[_HEAD] + 50); 63 + int get indexToLocFormat => bytes.getInt16(_tableOffsets[_HEAD] + 50);
64 64
65 - get ascent => bytes.getInt16(_tableOffsets[_HHEA] + 4); 65 + int get ascent => bytes.getInt16(_tableOffsets[_HHEA] + 4);
66 66
67 - get descent => bytes.getInt16(_tableOffsets[_HHEA] + 6); 67 + int get descent => bytes.getInt16(_tableOffsets[_HHEA] + 6);
68 68
69 - get numOfLongHorMetrics => bytes.getInt16(_tableOffsets[_HHEA] + 34); 69 + int get numOfLongHorMetrics => bytes.getInt16(_tableOffsets[_HHEA] + 34);
70 70
71 - get numGlyphs => bytes.getInt16(_tableOffsets[_MAXP] + 4); 71 + int get numGlyphs => bytes.getInt16(_tableOffsets[_MAXP] + 4);
72 72
73 - get fontName => _fontName; 73 + String get fontName => _fontName;
74 74
75 void _parseFontName() { 75 void _parseFontName() {
76 - final basePosition = _tableOffsets[_NAME];  
77 - final count = bytes.getUint16(basePosition + 2);  
78 - final stringOffset = bytes.getUint16(basePosition + 4); 76 + final int basePosition = _tableOffsets[_NAME];
  77 + final int count = bytes.getUint16(basePosition + 2);
  78 + final int stringOffset = bytes.getUint16(basePosition + 4);
79 int pos = basePosition + 6; 79 int pos = basePosition + 6;
80 - for (var i = 0; i < count; i++) {  
81 - int platformID = bytes.getUint16(pos);  
82 - int nameID = bytes.getUint16(pos + 6);  
83 - int length = bytes.getUint16(pos + 8);  
84 - int offset = bytes.getUint16(pos + 10); 80 + for (int i = 0; i < count; i++) {
  81 + final int platformID = bytes.getUint16(pos);
  82 + final int nameID = bytes.getUint16(pos + 6);
  83 + final int length = bytes.getUint16(pos + 8);
  84 + final int offset = bytes.getUint16(pos + 10);
85 pos += 12; 85 pos += 12;
86 if (platformID == 1 && nameID == 6) { 86 if (platformID == 1 && nameID == 6) {
87 _fontName = utf8.decode(bytes.buffer 87 _fontName = utf8.decode(bytes.buffer
@@ -93,20 +93,20 @@ class TtfParser { @@ -93,20 +93,20 @@ class TtfParser {
93 } 93 }
94 94
95 void _parseHmtx() { 95 void _parseHmtx() {
96 - final offset = _tableOffsets[_HMTX];  
97 - final unitsPerEm = this.unitsPerEm;  
98 - for (var i = 0; i < numOfLongHorMetrics; i++) { 96 + final int offset = _tableOffsets[_HMTX];
  97 + final int unitsPerEm = this.unitsPerEm;
  98 + for (int i = 0; i < numOfLongHorMetrics; i++) {
99 advanceWidth.add(bytes.getInt16(offset + i * 4).toDouble() / unitsPerEm); 99 advanceWidth.add(bytes.getInt16(offset + i * 4).toDouble() / unitsPerEm);
100 } 100 }
101 } 101 }
102 102
103 void _parseCMap() { 103 void _parseCMap() {
104 - final basePosition = _tableOffsets[_CMAP];  
105 - final numSubTables = bytes.getUint16(basePosition + 2);  
106 - for (var i = 0; i < numSubTables; i++) {  
107 - final offset = bytes.getUint32(basePosition + i * 8 + 8);  
108 - final format = bytes.getUint16(basePosition + offset);  
109 - final length = bytes.getUint16(basePosition + offset + 2); 104 + final int basePosition = _tableOffsets[_CMAP];
  105 + final int numSubTables = bytes.getUint16(basePosition + 2);
  106 + for (int i = 0; i < numSubTables; i++) {
  107 + final int offset = bytes.getUint32(basePosition + i * 8 + 8);
  108 + final int format = bytes.getUint16(basePosition + offset);
  109 + final int length = bytes.getUint16(basePosition + offset + 2);
110 110
111 switch (format) { 111 switch (format) {
112 case 0: 112 case 0:
@@ -125,9 +125,9 @@ class TtfParser { @@ -125,9 +125,9 @@ class TtfParser {
125 125
126 void _parseCMapFormat0(int basePosition, int length) { 126 void _parseCMapFormat0(int basePosition, int length) {
127 assert(length == 262); 127 assert(length == 262);
128 - for (var i = 0; i < 256; i++) {  
129 - int charCode = i;  
130 - int glyphIndex = bytes.getUint8(basePosition + i); 128 + for (int i = 0; i < 256; i++) {
  129 + final int charCode = i;
  130 + final int glyphIndex = bytes.getUint8(basePosition + i);
131 if (glyphIndex > 0) { 131 if (glyphIndex > 0) {
132 charToGlyphIndexMap[charCode] = glyphIndex; 132 charToGlyphIndexMap[charCode] = glyphIndex;
133 } 133 }
@@ -135,36 +135,36 @@ class TtfParser { @@ -135,36 +135,36 @@ class TtfParser {
135 } 135 }
136 136
137 void _parseCMapFormat4(int basePosition, int length) { 137 void _parseCMapFormat4(int basePosition, int length) {
138 - final segCount = bytes.getUint16(basePosition + 2) ~/ 2;  
139 - final endCodes = List<int>();  
140 - for (var i = 0; i < segCount; i++) { 138 + final int segCount = bytes.getUint16(basePosition + 2) ~/ 2;
  139 + final List<int> endCodes = <int>[];
  140 + for (int i = 0; i < segCount; i++) {
141 endCodes.add(bytes.getUint16(basePosition + i * 2 + 10)); 141 endCodes.add(bytes.getUint16(basePosition + i * 2 + 10));
142 } 142 }
143 - final startCodes = List<int>();  
144 - for (var i = 0; i < segCount; i++) { 143 + final List<int> startCodes = <int>[];
  144 + for (int i = 0; i < segCount; i++) {
145 startCodes.add(bytes.getUint16(basePosition + (segCount + i) * 2 + 12)); 145 startCodes.add(bytes.getUint16(basePosition + (segCount + i) * 2 + 12));
146 } 146 }
147 - final idDeltas = List<int>();  
148 - for (var i = 0; i < segCount; i++) { 147 + final List<int> idDeltas = <int>[];
  148 + for (int i = 0; i < segCount; i++) {
149 idDeltas.add(bytes.getUint16(basePosition + (segCount * 2 + i) * 2 + 12)); 149 idDeltas.add(bytes.getUint16(basePosition + (segCount * 2 + i) * 2 + 12));
150 } 150 }
151 - final idRangeOffsetBasePos = basePosition + segCount * 6 + 12;  
152 - final idRangeOffsets = List<int>();  
153 - for (var i = 0; i < segCount; i++) { 151 + final int idRangeOffsetBasePos = basePosition + segCount * 6 + 12;
  152 + final List<int> idRangeOffsets = <int>[];
  153 + for (int i = 0; i < segCount; i++) {
154 idRangeOffsets.add(bytes.getUint16(idRangeOffsetBasePos + i * 2)); 154 idRangeOffsets.add(bytes.getUint16(idRangeOffsetBasePos + i * 2));
155 } 155 }
156 - for (var s = 0; s < segCount - 1; s++) {  
157 - final startCode = startCodes[s];  
158 - final endCode = endCodes[s];  
159 - final idDelta = idDeltas[s];  
160 - final idRangeOffset = idRangeOffsets[s];  
161 - final idRangeOffsetAddress = idRangeOffsetBasePos + s * 2;  
162 - for (var c = startCode; c <= endCode; c++) {  
163 - var glyphIndex; 156 + for (int s = 0; s < segCount - 1; s++) {
  157 + final int startCode = startCodes[s];
  158 + final int endCode = endCodes[s];
  159 + final int idDelta = idDeltas[s];
  160 + final int idRangeOffset = idRangeOffsets[s];
  161 + final int idRangeOffsetAddress = idRangeOffsetBasePos + s * 2;
  162 + for (int c = startCode; c <= endCode; c++) {
  163 + int glyphIndex;
164 if (idRangeOffset == 0) { 164 if (idRangeOffset == 0) {
165 glyphIndex = (idDelta + c) % 65536; 165 glyphIndex = (idDelta + c) % 65536;
166 } else { 166 } else {
167 - final glyphIndexAddress = 167 + final int glyphIndexAddress =
168 idRangeOffset + 2 * (c - startCode) + idRangeOffsetAddress; 168 idRangeOffset + 2 * (c - startCode) + idRangeOffsetAddress;
169 glyphIndex = bytes.getUint16(glyphIndexAddress); 169 glyphIndex = bytes.getUint16(glyphIndexAddress);
170 } 170 }
@@ -174,11 +174,11 @@ class TtfParser { @@ -174,11 +174,11 @@ class TtfParser {
174 } 174 }
175 175
176 void _parseCMapFormat6(int basePosition, int length) { 176 void _parseCMapFormat6(int basePosition, int length) {
177 - final firstCode = bytes.getUint16(basePosition + 2);  
178 - final entryCount = bytes.getUint16(basePosition + 4);  
179 - for (var i = 0; i < entryCount; i++) {  
180 - final charCode = firstCode + i;  
181 - final glyphIndex = bytes.getUint16(basePosition + i * 2 + 6); 177 + final int firstCode = bytes.getUint16(basePosition + 2);
  178 + final int entryCount = bytes.getUint16(basePosition + 4);
  179 + for (int i = 0; i < entryCount; i++) {
  180 + final int charCode = firstCode + i;
  181 + final int glyphIndex = bytes.getUint16(basePosition + i * 2 + 6);
182 if (glyphIndex > 0) { 182 if (glyphIndex > 0) {
183 charToGlyphIndexMap[charCode] = glyphIndex; 183 charToGlyphIndexMap[charCode] = glyphIndex;
184 } 184 }
@@ -186,28 +186,28 @@ class TtfParser { @@ -186,28 +186,28 @@ class TtfParser {
186 } 186 }
187 187
188 void _parseIndexes() { 188 void _parseIndexes() {
189 - final basePosition = _tableOffsets[_LOCA];  
190 - final numGlyphs = this.numGlyphs; 189 + final int basePosition = _tableOffsets[_LOCA];
  190 + final int numGlyphs = this.numGlyphs;
191 if (indexToLocFormat == 0) { 191 if (indexToLocFormat == 0) {
192 - for (var i = 0; i < numGlyphs; i++) { 192 + for (int i = 0; i < numGlyphs; i++) {
193 glyphOffsets.add(bytes.getUint16(basePosition + i * 2) * 2); 193 glyphOffsets.add(bytes.getUint16(basePosition + i * 2) * 2);
194 } 194 }
195 } else { 195 } else {
196 - for (var i = 0; i < numGlyphs; i++) { 196 + for (int i = 0; i < numGlyphs; i++) {
197 glyphOffsets.add(bytes.getUint32(basePosition + i * 4)); 197 glyphOffsets.add(bytes.getUint32(basePosition + i * 4));
198 } 198 }
199 } 199 }
200 } 200 }
201 201
202 void _parseGlyf() { 202 void _parseGlyf() {
203 - final baseOffset = _tableOffsets[_GLYF];  
204 - final unitsPerEm = this.unitsPerEm; 203 + final int baseOffset = _tableOffsets[_GLYF];
  204 + final int unitsPerEm = this.unitsPerEm;
205 int glyphIndex = 0; 205 int glyphIndex = 0;
206 - for (var offset in glyphOffsets) {  
207 - final xMin = bytes.getInt16(baseOffset + offset + 2); // 2  
208 - final yMin = bytes.getInt16(baseOffset + offset + 4); // 4  
209 - final xMax = bytes.getInt16(baseOffset + offset + 6); // 6  
210 - final yMax = bytes.getInt16(baseOffset + offset + 8); // 8 206 + for (int offset in glyphOffsets) {
  207 + final int xMin = bytes.getInt16(baseOffset + offset + 2); // 2
  208 + final int yMin = bytes.getInt16(baseOffset + offset + 4); // 4
  209 + final int xMax = bytes.getInt16(baseOffset + offset + 6); // 6
  210 + final int yMax = bytes.getInt16(baseOffset + offset + 8); // 8
211 glyphInfoMap[glyphIndex] = PdfRect( 211 glyphInfoMap[glyphIndex] = PdfRect(
212 xMin.toDouble() / unitsPerEm, 212 xMin.toDouble() / unitsPerEm,
213 yMin.toDouble() / unitsPerEm, 213 yMin.toDouble() / unitsPerEm,
@@ -17,27 +17,19 @@ @@ -17,27 +17,19 @@
17 part of pdf; 17 part of pdf;
18 18
19 class PdfTtfFont extends PdfFont { 19 class PdfTtfFont extends PdfFont {
20 - PdfObject unicodeCMap;  
21 - PdfFontDescriptor descriptor;  
22 - PdfArrayObject widthsObject;  
23 - final widths = List<String>();  
24 - final TtfParser font;  
25 - int _charMin;  
26 - int _charMax;  
27 -  
28 /// Constructs a [PdfTtfFont] 20 /// Constructs a [PdfTtfFont]
29 PdfTtfFont(PdfDocument pdfDocument, ByteData bytes) 21 PdfTtfFont(PdfDocument pdfDocument, ByteData bytes)
30 : font = TtfParser(bytes), 22 : font = TtfParser(bytes),
31 - super._create(pdfDocument, subtype: "/TrueType") {  
32 - PdfObjectStream file = PdfObjectStream(pdfDocument, isBinary: true);  
33 - final data = bytes.buffer.asUint8List(); 23 + super._create(pdfDocument, subtype: '/TrueType') {
  24 + final PdfObjectStream file = PdfObjectStream(pdfDocument, isBinary: true);
  25 + final Uint8List data = bytes.buffer.asUint8List();
34 file.buf.putBytes(data); 26 file.buf.putBytes(data);
35 - file.params["/Length1"] = PdfStream.intNum(data.length); 27 + file.params['/Length1'] = PdfStream.intNum(data.length);
36 28
37 _charMin = 32; 29 _charMin = 32;
38 _charMax = 255; 30 _charMax = 255;
39 31
40 - for (var i = _charMin; i <= _charMax; i++) { 32 + for (int i = _charMin; i <= _charMax; i++) {
41 widths.add((glyphAdvance(i) * 1000.0).toString()); 33 widths.add((glyphAdvance(i) * 1000.0).toString());
42 } 34 }
43 35
@@ -46,12 +38,26 @@ class PdfTtfFont extends PdfFont { @@ -46,12 +38,26 @@ class PdfTtfFont extends PdfFont {
46 widthsObject = PdfArrayObject(pdfDocument, widths); 38 widthsObject = PdfArrayObject(pdfDocument, widths);
47 } 39 }
48 40
  41 + PdfObject unicodeCMap;
  42 +
  43 + PdfFontDescriptor descriptor;
  44 +
  45 + PdfArrayObject widthsObject;
  46 +
  47 + final List<String> widths = <String>[];
  48 +
  49 + final TtfParser font;
  50 +
  51 + int _charMin;
  52 +
  53 + int _charMax;
  54 +
49 @override 55 @override
50 - String get fontName => "/" + font.fontName.replaceAll(" ", ""); 56 + String get fontName => '/' + font.fontName.replaceAll(' ', '');
51 57
52 @override 58 @override
53 double glyphAdvance(int charCode) { 59 double glyphAdvance(int charCode) {
54 - var g = font.charToGlyphIndexMap[charCode]; 60 + final int g = font.charToGlyphIndexMap[charCode];
55 61
56 if (g == null) { 62 if (g == null) {
57 return super.glyphAdvance(charCode); 63 return super.glyphAdvance(charCode);
@@ -63,7 +69,7 @@ class PdfTtfFont extends PdfFont { @@ -63,7 +69,7 @@ class PdfTtfFont extends PdfFont {
63 69
64 @override 70 @override
65 PdfRect glyphBounds(int charCode) { 71 PdfRect glyphBounds(int charCode) {
66 - var g = font.charToGlyphIndexMap[charCode]; 72 + final int g = font.charToGlyphIndexMap[charCode];
67 73
68 if (g == null) { 74 if (g == null) {
69 return super.glyphBounds(charCode); 75 return super.glyphBounds(charCode);
@@ -76,12 +82,12 @@ class PdfTtfFont extends PdfFont { @@ -76,12 +82,12 @@ class PdfTtfFont extends PdfFont {
76 void _prepare() { 82 void _prepare() {
77 super._prepare(); 83 super._prepare();
78 84
79 - params["/BaseFont"] = PdfStream.string(fontName);  
80 - params["/FirstChar"] = PdfStream.intNum(_charMin);  
81 - params["/LastChar"] = PdfStream.intNum(_charMax);  
82 - params["/Widths"] = widthsObject.ref();  
83 - params["/FontDescriptor"] = descriptor.ref();  
84 -// params["/Encoding"] = PdfStream.string("/Identity-H");  
85 -// params["/ToUnicode"] = unicodeCMap.ref(); 85 + params['/BaseFont'] = PdfStream.string(fontName);
  86 + params['/FirstChar'] = PdfStream.intNum(_charMin);
  87 + params['/LastChar'] = PdfStream.intNum(_charMax);
  88 + params['/Widths'] = widthsObject.ref();
  89 + params['/FontDescriptor'] = descriptor.ref();
  90 +// params['/Encoding'] = PdfStream.string('/Identity-H');
  91 +// params['/ToUnicode'] = unicodeCMap.ref();
86 } 92 }
87 } 93 }
@@ -17,23 +17,27 @@ @@ -17,23 +17,27 @@
17 part of pdf; 17 part of pdf;
18 18
19 class PdfType1Font extends PdfFont { 19 class PdfType1Font extends PdfFont {
  20 + /// Constructs a [PdfTtfFont]
  21 + PdfType1Font._create(PdfDocument pdfDocument, this.fontName, this.ascent,
  22 + this.descent, this.widths)
  23 + : super._create(pdfDocument, subtype: '/Type1');
  24 +
20 /// The font's real name 25 /// The font's real name
  26 + @override
21 final String fontName; 27 final String fontName;
  28 +
22 final double ascent; 29 final double ascent;
  30 +
23 final double descent; 31 final double descent;
24 - final List<double> widths;  
25 32
26 - /// Constructs a [PdfTtfFont]  
27 - PdfType1Font._create(PdfDocument pdfDocument, this.fontName, this.ascent,  
28 - this.descent, this.widths)  
29 - : super._create(pdfDocument, subtype: "/Type1") {} 33 + final List<double> widths;
30 34
31 /// @param os OutputStream to send the object to 35 /// @param os OutputStream to send the object to
32 @override 36 @override
33 void _prepare() { 37 void _prepare() {
34 super._prepare(); 38 super._prepare();
35 39
36 - params["/BaseFont"] = PdfStream.string("/" + fontName); 40 + params['/BaseFont'] = PdfStream.string('/' + fontName);
37 } 41 }
38 42
39 @override 43 @override
@@ -17,6 +17,12 @@ @@ -17,6 +17,12 @@
17 part of pdf; 17 part of pdf;
18 18
19 class PdfXref { 19 class PdfXref {
  20 + /// Creates a cross-reference for a Pdf Object
  21 + /// @param id The object's ID
  22 + /// @param offset The object's position in the file
  23 + /// @param generation The object's generation, usually 0
  24 + PdfXref(this.id, this.offset, {this.generation = 0});
  25 +
20 /// The id of a Pdf Object 26 /// The id of a Pdf Object
21 int id; 27 int id;
22 28
@@ -26,19 +32,15 @@ class PdfXref { @@ -26,19 +32,15 @@ class PdfXref {
26 /// The generation of the object, usually 0 32 /// The generation of the object, usually 0
27 int generation = 0; 33 int generation = 0;
28 34
29 - /// Creates a cross-reference for a Pdf Object  
30 - /// @param id The object's ID  
31 - /// @param offset The object's position in the file  
32 - /// @param generation The object's generation, usually 0  
33 - PdfXref(this.id, this.offset, {this.generation = 0});  
34 -  
35 /// @return The xref in the format of the xref section in the Pdf file 35 /// @return The xref in the format of the xref section in the Pdf file
36 String ref() { 36 String ref() {
37 - String rs = offset.toString().padLeft(10, '0') +  
38 - " " + 37 + final String rs = offset.toString().padLeft(10, '0') +
  38 + ' ' +
39 generation.toString().padLeft(5, '0'); 39 generation.toString().padLeft(5, '0');
40 40
41 - if (generation == 65535) return rs + " f ";  
42 - return rs + " n "; 41 + if (generation == 65535) {
  42 + return rs + ' f ';
  43 + }
  44 + return rs + ' n ';
43 } 45 }
44 } 46 }
@@ -45,7 +45,7 @@ class LimitedBox extends SingleChildWidget { @@ -45,7 +45,7 @@ class LimitedBox extends SingleChildWidget {
45 45
46 @override 46 @override
47 void layout(Context context, BoxConstraints constraints, 47 void layout(Context context, BoxConstraints constraints,
48 - {parentUsesSize = false}) { 48 + {bool parentUsesSize = false}) {
49 PdfPoint size; 49 PdfPoint size;
50 if (child != null) { 50 if (child != null) {
51 child.layout(context, _limitConstraints(constraints), 51 child.layout(context, _limitConstraints(constraints),
@@ -69,9 +69,9 @@ class Padding extends SingleChildWidget { @@ -69,9 +69,9 @@ class Padding extends SingleChildWidget {
69 69
70 @override 70 @override
71 void layout(Context context, BoxConstraints constraints, 71 void layout(Context context, BoxConstraints constraints,
72 - {parentUsesSize = false}) { 72 + {bool parentUsesSize = false}) {
73 if (child != null) { 73 if (child != null) {
74 - final childConstraints = constraints.deflate(padding); 74 + final BoxConstraints childConstraints = constraints.deflate(padding);
75 child.layout(context, childConstraints, parentUsesSize: parentUsesSize); 75 child.layout(context, childConstraints, parentUsesSize: parentUsesSize);
76 box = constraints.constrainRect( 76 box = constraints.constrainRect(
77 width: child.box.width + padding.horizontal, 77 width: child.box.width + padding.horizontal,
@@ -100,12 +100,14 @@ class Padding extends SingleChildWidget { @@ -100,12 +100,14 @@ class Padding extends SingleChildWidget {
100 @override 100 @override
101 void paint(Context context) { 101 void paint(Context context) {
102 assert(() { 102 assert(() {
103 - if (Document.debug) debugPaint(context); 103 + if (Document.debug) {
  104 + debugPaint(context);
  105 + }
104 return true; 106 return true;
105 }()); 107 }());
106 108
107 if (child != null) { 109 if (child != null) {
108 - final mat = Matrix4.identity(); 110 + final Matrix4 mat = Matrix4.identity();
109 mat.translate(box.x + padding.left, box.y + padding.bottom); 111 mat.translate(box.x + padding.left, box.y + padding.bottom);
110 context.canvas 112 context.canvas
111 ..saveContext() 113 ..saveContext()
@@ -163,29 +165,39 @@ class Transform extends SingleChildWidget { @@ -163,29 +165,39 @@ class Transform extends SingleChildWidget {
163 final Alignment alignment; 165 final Alignment alignment;
164 166
165 Matrix4 get _effectiveTransform { 167 Matrix4 get _effectiveTransform {
166 - if (origin == null && alignment == null) return transform; 168 + if (origin == null && alignment == null) {
  169 + return transform;
  170 + }
167 final Matrix4 result = Matrix4.identity(); 171 final Matrix4 result = Matrix4.identity();
168 - if (origin != null) result.translate(origin.x, origin.y); 172 + if (origin != null) {
  173 + result.translate(origin.x, origin.y);
  174 + }
169 PdfPoint translation; 175 PdfPoint translation;
170 if (alignment != null) { 176 if (alignment != null) {
171 translation = alignment.alongSize(box.size); 177 translation = alignment.alongSize(box.size);
172 result.translate(translation.x, translation.y); 178 result.translate(translation.x, translation.y);
173 } 179 }
174 result.multiply(transform); 180 result.multiply(transform);
175 - if (alignment != null) result.translate(-translation.x, -translation.y);  
176 - if (origin != null) result.translate(-origin.x, -origin.y); 181 + if (alignment != null) {
  182 + result.translate(-translation.x, -translation.y);
  183 + }
  184 + if (origin != null) {
  185 + result.translate(-origin.x, -origin.y);
  186 + }
177 return result; 187 return result;
178 } 188 }
179 189
180 @override 190 @override
181 void paint(Context context) { 191 void paint(Context context) {
182 assert(() { 192 assert(() {
183 - if (Document.debug) debugPaint(context); 193 + if (Document.debug) {
  194 + debugPaint(context);
  195 + }
184 return true; 196 return true;
185 }()); 197 }());
186 198
187 if (child != null) { 199 if (child != null) {
188 - final mat = _effectiveTransform; 200 + final Matrix4 mat = _effectiveTransform;
189 context.canvas 201 context.canvas
190 ..saveContext() 202 ..saveContext()
191 ..setTransform(mat); 203 ..setTransform(mat);
@@ -219,7 +231,7 @@ class Align extends SingleChildWidget { @@ -219,7 +231,7 @@ class Align extends SingleChildWidget {
219 231
220 @override 232 @override
221 void layout(Context context, BoxConstraints constraints, 233 void layout(Context context, BoxConstraints constraints,
222 - {parentUsesSize = false}) { 234 + {bool parentUsesSize = false}) {
223 final bool shrinkWrapWidth = 235 final bool shrinkWrapWidth =
224 widthFactor != null || constraints.maxWidth == double.infinity; 236 widthFactor != null || constraints.maxWidth == double.infinity;
225 final bool shrinkWrapHeight = 237 final bool shrinkWrapHeight =
@@ -256,7 +268,7 @@ class ConstrainedBox extends SingleChildWidget { @@ -256,7 +268,7 @@ class ConstrainedBox extends SingleChildWidget {
256 268
257 @override 269 @override
258 void layout(Context context, BoxConstraints constraints, 270 void layout(Context context, BoxConstraints constraints,
259 - {parentUsesSize = false}) { 271 + {bool parentUsesSize = false}) {
260 if (child != null) { 272 if (child != null) {
261 child.layout(context, this.constraints.enforce(constraints), 273 child.layout(context, this.constraints.enforce(constraints),
262 parentUsesSize: true); 274 parentUsesSize: true);
@@ -292,7 +304,7 @@ class FittedBox extends SingleChildWidget { @@ -292,7 +304,7 @@ class FittedBox extends SingleChildWidget {
292 304
293 @override 305 @override
294 void layout(Context context, BoxConstraints constraints, 306 void layout(Context context, BoxConstraints constraints,
295 - {parentUsesSize = false}) { 307 + {bool parentUsesSize = false}) {
296 PdfPoint size; 308 PdfPoint size;
297 if (child != null) { 309 if (child != null) {
298 child.layout(context, const BoxConstraints(), parentUsesSize: true); 310 child.layout(context, const BoxConstraints(), parentUsesSize: true);
@@ -316,7 +328,7 @@ class FittedBox extends SingleChildWidget { @@ -316,7 +328,7 @@ class FittedBox extends SingleChildWidget {
316 final PdfRect destinationRect = 328 final PdfRect destinationRect =
317 alignment.inscribe(sizes.destination, box); 329 alignment.inscribe(sizes.destination, box);
318 330
319 - final mat = 331 + final Matrix4 mat =
320 Matrix4.translationValues(destinationRect.x, destinationRect.y, 0.0) 332 Matrix4.translationValues(destinationRect.x, destinationRect.y, 0.0)
321 ..scale(scaleX, scaleY, 1.0) 333 ..scale(scaleX, scaleY, 1.0)
322 ..translate(-sourceRect.x, -sourceRect.y); 334 ..translate(-sourceRect.x, -sourceRect.y);
@@ -341,7 +353,9 @@ class AspectRatio extends SingleChildWidget { @@ -341,7 +353,9 @@ class AspectRatio extends SingleChildWidget {
341 final double aspectRatio; 353 final double aspectRatio;
342 354
343 PdfPoint _applyAspectRatio(BoxConstraints constraints) { 355 PdfPoint _applyAspectRatio(BoxConstraints constraints) {
344 - if (constraints.isTight) return constraints.smallest; 356 + if (constraints.isTight) {
  357 + return constraints.smallest;
  358 + }
345 359
346 double width = constraints.maxWidth; 360 double width = constraints.maxWidth;
347 double height; 361 double height;
@@ -378,7 +392,7 @@ class AspectRatio extends SingleChildWidget { @@ -378,7 +392,7 @@ class AspectRatio extends SingleChildWidget {
378 392
379 @override 393 @override
380 void layout(Context context, BoxConstraints constraints, 394 void layout(Context context, BoxConstraints constraints,
381 - {parentUsesSize = false}) { 395 + {bool parentUsesSize = false}) {
382 box = PdfRect.fromPoints(PdfPoint.zero, _applyAspectRatio(constraints)); 396 box = PdfRect.fromPoints(PdfPoint.zero, _applyAspectRatio(constraints));
383 if (child != null) 397 if (child != null)
384 child.layout(context, 398 child.layout(context,
@@ -386,7 +400,7 @@ class AspectRatio extends SingleChildWidget { @@ -386,7 +400,7 @@ class AspectRatio extends SingleChildWidget {
386 } 400 }
387 } 401 }
388 402
389 -typedef CustomPainter(PdfGraphics canvas, PdfPoint size); 403 +typedef CustomPainter = Function(PdfGraphics canvas, PdfPoint size);
390 404
391 class CustomPaint extends SingleChildWidget { 405 class CustomPaint extends SingleChildWidget {
392 CustomPaint( 406 CustomPaint(
@@ -402,7 +416,7 @@ class CustomPaint extends SingleChildWidget { @@ -402,7 +416,7 @@ class CustomPaint extends SingleChildWidget {
402 416
403 @override 417 @override
404 void layout(Context context, BoxConstraints constraints, 418 void layout(Context context, BoxConstraints constraints,
405 - {parentUsesSize = false}) { 419 + {bool parentUsesSize = false}) {
406 if (child != null) { 420 if (child != null) {
407 child.layout(context, constraints.tighten(width: size.x, height: size.y), 421 child.layout(context, constraints.tighten(width: size.x, height: size.y),
408 parentUsesSize: parentUsesSize); 422 parentUsesSize: parentUsesSize);
@@ -415,18 +429,26 @@ class CustomPaint extends SingleChildWidget { @@ -415,18 +429,26 @@ class CustomPaint extends SingleChildWidget {
415 @override 429 @override
416 void paint(Context context) { 430 void paint(Context context) {
417 assert(() { 431 assert(() {
418 - if (Document.debug) debugPaint(context); 432 + if (Document.debug) {
  433 + debugPaint(context);
  434 + }
419 return true; 435 return true;
420 }()); 436 }());
421 437
422 - final mat = Matrix4.identity(); 438 + final Matrix4 mat = Matrix4.identity();
423 mat.translate(box.x, box.y); 439 mat.translate(box.x, box.y);
424 context.canvas 440 context.canvas
425 ..saveContext() 441 ..saveContext()
426 ..setTransform(mat); 442 ..setTransform(mat);
427 - if (painter != null) painter(context.canvas, box.size);  
428 - if (child != null) child.paint(context);  
429 - if (foregroundPainter != null) foregroundPainter(context.canvas, box.size); 443 + if (painter != null) {
  444 + painter(context.canvas, box.size);
  445 + }
  446 + if (child != null) {
  447 + child.paint(context);
  448 + }
  449 + if (foregroundPainter != null) {
  450 + foregroundPainter(context.canvas, box.size);
  451 + }
430 context.canvas.restoreContext(); 452 context.canvas.restoreContext();
431 } 453 }
432 } 454 }
@@ -19,7 +19,7 @@ part of widget; @@ -19,7 +19,7 @@ part of widget;
19 class ClipRect extends SingleChildWidget { 19 class ClipRect extends SingleChildWidget {
20 ClipRect({Widget child}) : super(child: child); 20 ClipRect({Widget child}) : super(child: child);
21 21
22 - @protected 22 + @override
23 void debugPaint(Context context) { 23 void debugPaint(Context context) {
24 context.canvas 24 context.canvas
25 ..setStrokeColor(PdfColor.deepPurple) 25 ..setStrokeColor(PdfColor.deepPurple)
@@ -30,12 +30,14 @@ class ClipRect extends SingleChildWidget { @@ -30,12 +30,14 @@ class ClipRect extends SingleChildWidget {
30 @override 30 @override
31 void paint(Context context) { 31 void paint(Context context) {
32 assert(() { 32 assert(() {
33 - if (Document.debug) debugPaint(context); 33 + if (Document.debug) {
  34 + debugPaint(context);
  35 + }
34 return true; 36 return true;
35 }()); 37 }());
36 38
37 if (child != null) { 39 if (child != null) {
38 - final mat = Matrix4.identity(); 40 + final Matrix4 mat = Matrix4.identity();
39 mat.translate(box.x, box.y); 41 mat.translate(box.x, box.y);
40 context.canvas 42 context.canvas
41 ..saveContext() 43 ..saveContext()
@@ -58,7 +60,7 @@ class ClipRRect extends SingleChildWidget { @@ -58,7 +60,7 @@ class ClipRRect extends SingleChildWidget {
58 final double horizontalRadius; 60 final double horizontalRadius;
59 final double verticalRadius; 61 final double verticalRadius;
60 62
61 - @protected 63 + @override
62 void debugPaint(Context context) { 64 void debugPaint(Context context) {
63 context.canvas 65 context.canvas
64 ..setStrokeColor(PdfColor.deepPurple) 66 ..setStrokeColor(PdfColor.deepPurple)
@@ -70,12 +72,14 @@ class ClipRRect extends SingleChildWidget { @@ -70,12 +72,14 @@ class ClipRRect extends SingleChildWidget {
70 @override 72 @override
71 void paint(Context context) { 73 void paint(Context context) {
72 assert(() { 74 assert(() {
73 - if (Document.debug) debugPaint(context); 75 + if (Document.debug) {
  76 + debugPaint(context);
  77 + }
74 return true; 78 return true;
75 }()); 79 }());
76 80
77 if (child != null) { 81 if (child != null) {
78 - final mat = Matrix4.identity(); 82 + final Matrix4 mat = Matrix4.identity();
79 mat.translate(box.x, box.y); 83 mat.translate(box.x, box.y);
80 context.canvas 84 context.canvas
81 ..saveContext() 85 ..saveContext()
@@ -92,10 +96,10 @@ class ClipRRect extends SingleChildWidget { @@ -92,10 +96,10 @@ class ClipRRect extends SingleChildWidget {
92 class ClipOval extends SingleChildWidget { 96 class ClipOval extends SingleChildWidget {
93 ClipOval({Widget child}) : super(child: child); 97 ClipOval({Widget child}) : super(child: child);
94 98
95 - @protected 99 + @override
96 void debugPaint(Context context) { 100 void debugPaint(Context context) {
97 - final rx = box.width / 2.0;  
98 - final ry = box.height / 2.0; 101 + final double rx = box.width / 2.0;
  102 + final double ry = box.height / 2.0;
99 103
100 context.canvas 104 context.canvas
101 ..setStrokeColor(PdfColor.deepPurple) 105 ..setStrokeColor(PdfColor.deepPurple)
@@ -106,15 +110,17 @@ class ClipOval extends SingleChildWidget { @@ -106,15 +110,17 @@ class ClipOval extends SingleChildWidget {
106 @override 110 @override
107 void paint(Context context) { 111 void paint(Context context) {
108 assert(() { 112 assert(() {
109 - if (Document.debug) debugPaint(context); 113 + if (Document.debug) {
  114 + debugPaint(context);
  115 + }
110 return true; 116 return true;
111 }()); 117 }());
112 118
113 - final rx = box.width / 2.0;  
114 - final ry = box.height / 2.0; 119 + final double rx = box.width / 2.0;
  120 + final double ry = box.height / 2.0;
115 121
116 if (child != null) { 122 if (child != null) {
117 - final mat = Matrix4.identity(); 123 + final Matrix4 mat = Matrix4.identity();
118 mat.translate(box.x, box.y); 124 mat.translate(box.x, box.y);
119 context.canvas 125 context.canvas
120 ..saveContext() 126 ..saveContext()
@@ -219,7 +219,9 @@ class Container extends StatelessWidget { @@ -219,7 +219,9 @@ class Container extends StatelessWidget {
219 if (alignment != null) 219 if (alignment != null)
220 current = Align(alignment: alignment, child: current); 220 current = Align(alignment: alignment, child: current);
221 221
222 - if (padding != null) current = Padding(padding: padding, child: current); 222 + if (padding != null) {
  223 + current = Padding(padding: padding, child: current);
  224 + }
223 225
224 if (decoration != null) 226 if (decoration != null)
225 current = DecoratedBox(decoration: decoration, child: current); 227 current = DecoratedBox(decoration: decoration, child: current);
@@ -234,7 +236,9 @@ class Container extends StatelessWidget { @@ -234,7 +236,9 @@ class Container extends StatelessWidget {
234 if (constraints != null) 236 if (constraints != null)
235 current = ConstrainedBox(constraints: constraints, child: current); 237 current = ConstrainedBox(constraints: constraints, child: current);
236 238
237 - if (margin != null) current = Padding(padding: margin, child: current); 239 + if (margin != null) {
  240 + current = Padding(padding: margin, child: current);
  241 + }
238 242
239 if (transform != null) 243 if (transform != null)
240 current = Transform(transform: transform, child: current); 244 current = Transform(transform: transform, child: current);
@@ -17,13 +17,13 @@ @@ -17,13 +17,13 @@
17 part of widget; 17 part of widget;
18 18
19 class Header extends StatelessWidget { 19 class Header extends StatelessWidget {
  20 + Header({this.level = 1, this.text, this.child})
  21 + : assert(level >= 0 && level <= 5);
  22 +
20 final String text; 23 final String text;
21 final Widget child; 24 final Widget child;
22 final int level; 25 final int level;
23 26
24 - Header({this.level = 1, this.text, this.child})  
25 - : assert(level >= 0 && level <= 5);  
26 -  
27 @override 27 @override
28 Widget build(Context context) { 28 Widget build(Context context) {
29 BoxDecoration _decoration; 29 BoxDecoration _decoration;
@@ -32,36 +32,36 @@ class Header extends StatelessWidget { @@ -32,36 +32,36 @@ class Header extends StatelessWidget {
32 double _textSize; 32 double _textSize;
33 switch (level) { 33 switch (level) {
34 case 0: 34 case 0:
35 - _margin = EdgeInsets.only(bottom: 5.0 * PdfPageFormat.mm);  
36 - _padding = EdgeInsets.only(bottom: 1.0 * PdfPageFormat.mm); 35 + _margin = const EdgeInsets.only(bottom: 5.0 * PdfPageFormat.mm);
  36 + _padding = const EdgeInsets.only(bottom: 1.0 * PdfPageFormat.mm);
37 _decoration = 37 _decoration =
38 - BoxDecoration(border: BoxBorder(bottom: true, width: 1.0)); 38 + const BoxDecoration(border: BoxBorder(bottom: true, width: 1.0));
39 _textSize = 2.0; 39 _textSize = 2.0;
40 break; 40 break;
41 case 1: 41 case 1:
42 - _margin = EdgeInsets.only( 42 + _margin = const EdgeInsets.only(
43 top: 3.0 * PdfPageFormat.mm, bottom: 5.0 * PdfPageFormat.mm); 43 top: 3.0 * PdfPageFormat.mm, bottom: 5.0 * PdfPageFormat.mm);
44 _decoration = 44 _decoration =
45 - BoxDecoration(border: BoxBorder(bottom: true, width: 0.2)); 45 + const BoxDecoration(border: BoxBorder(bottom: true, width: 0.2));
46 _textSize = 1.5; 46 _textSize = 1.5;
47 break; 47 break;
48 case 2: 48 case 2:
49 - _margin = EdgeInsets.only( 49 + _margin = const EdgeInsets.only(
50 top: 2.0 * PdfPageFormat.mm, bottom: 4.0 * PdfPageFormat.mm); 50 top: 2.0 * PdfPageFormat.mm, bottom: 4.0 * PdfPageFormat.mm);
51 _textSize = 1.4; 51 _textSize = 1.4;
52 break; 52 break;
53 case 3: 53 case 3:
54 - _margin = EdgeInsets.only( 54 + _margin = const EdgeInsets.only(
55 top: 2.0 * PdfPageFormat.mm, bottom: 4.0 * PdfPageFormat.mm); 55 top: 2.0 * PdfPageFormat.mm, bottom: 4.0 * PdfPageFormat.mm);
56 _textSize = 1.3; 56 _textSize = 1.3;
57 break; 57 break;
58 case 4: 58 case 4:
59 - _margin = EdgeInsets.only( 59 + _margin = const EdgeInsets.only(
60 top: 2.0 * PdfPageFormat.mm, bottom: 4.0 * PdfPageFormat.mm); 60 top: 2.0 * PdfPageFormat.mm, bottom: 4.0 * PdfPageFormat.mm);
61 _textSize = 1.2; 61 _textSize = 1.2;
62 break; 62 break;
63 case 5: 63 case 5:
64 - _margin = EdgeInsets.only( 64 + _margin = const EdgeInsets.only(
65 top: 2.0 * PdfPageFormat.mm, bottom: 4.0 * PdfPageFormat.mm); 65 top: 2.0 * PdfPageFormat.mm, bottom: 4.0 * PdfPageFormat.mm);
66 _textSize = 1.1; 66 _textSize = 1.1;
67 break; 67 break;
@@ -77,14 +77,14 @@ class Header extends StatelessWidget { @@ -77,14 +77,14 @@ class Header extends StatelessWidget {
77 } 77 }
78 78
79 class Paragraph extends StatelessWidget { 79 class Paragraph extends StatelessWidget {
80 - final String text;  
81 -  
82 Paragraph({this.text}); 80 Paragraph({this.text});
83 81
  82 + final String text;
  83 +
84 @override 84 @override
85 Widget build(Context context) { 85 Widget build(Context context) {
86 return Container( 86 return Container(
87 - margin: EdgeInsets.only(bottom: 5.0 * PdfPageFormat.mm), 87 + margin: const EdgeInsets.only(bottom: 5.0 * PdfPageFormat.mm),
88 child: Text( 88 child: Text(
89 text, 89 text,
90 textAlign: TextAlign.justify, 90 textAlign: TextAlign.justify,
@@ -95,26 +95,26 @@ class Paragraph extends StatelessWidget { @@ -95,26 +95,26 @@ class Paragraph extends StatelessWidget {
95 } 95 }
96 96
97 class Bullet extends StatelessWidget { 97 class Bullet extends StatelessWidget {
98 - final String text;  
99 -  
100 Bullet({this.text}); 98 Bullet({this.text});
101 99
  100 + final String text;
  101 +
102 @override 102 @override
103 Widget build(Context context) { 103 Widget build(Context context) {
104 return Container( 104 return Container(
105 - margin: EdgeInsets.only(bottom: 2.0 * PdfPageFormat.mm), 105 + margin: const EdgeInsets.only(bottom: 2.0 * PdfPageFormat.mm),
106 child: Row( 106 child: Row(
107 crossAxisAlignment: CrossAxisAlignment.start, 107 crossAxisAlignment: CrossAxisAlignment.start,
108 children: <Widget>[ 108 children: <Widget>[
109 Container( 109 Container(
110 width: 2.0 * PdfPageFormat.mm, 110 width: 2.0 * PdfPageFormat.mm,
111 height: 2.0 * PdfPageFormat.mm, 111 height: 2.0 * PdfPageFormat.mm,
112 - margin: EdgeInsets.only( 112 + margin: const EdgeInsets.only(
113 top: 0.5 * PdfPageFormat.mm, 113 top: 0.5 * PdfPageFormat.mm,
114 left: 5.0 * PdfPageFormat.mm, 114 left: 5.0 * PdfPageFormat.mm,
115 right: 2.0 * PdfPageFormat.mm, 115 right: 2.0 * PdfPageFormat.mm,
116 ), 116 ),
117 - decoration: BoxDecoration( 117 + decoration: const BoxDecoration(
118 color: PdfColor.black, shape: BoxShape.circle), 118 color: PdfColor.black, shape: BoxShape.circle),
119 ), 119 ),
120 Expanded(child: Text(text, style: Theme.of(context).bulletStyle)) 120 Expanded(child: Text(text, style: Theme.of(context).bulletStyle))
@@ -17,40 +17,36 @@ @@ -17,40 +17,36 @@
17 part of widget; 17 part of widget;
18 18
19 abstract class BasePage { 19 abstract class BasePage {
20 - final PdfPageFormat pageFormat; 20 + BasePage({@required this.pageFormat}) : assert(pageFormat != null);
21 21
22 - BasePage({this.pageFormat}) : assert(pageFormat != null); 22 + final PdfPageFormat pageFormat;
23 23
24 @protected 24 @protected
25 void generate(Document document); 25 void generate(Document document);
26 } 26 }
27 27
28 class Document { 28 class Document {
29 - static var debug = false;  
30 -  
31 - final PdfDocument document;  
32 -  
33 - final Theme theme;  
34 -  
35 Document( 29 Document(
36 {PdfPageMode pageMode = PdfPageMode.none, 30 {PdfPageMode pageMode = PdfPageMode.none,
37 DeflateCallback deflate, 31 DeflateCallback deflate,
38 this.theme}) 32 this.theme})
39 : document = PdfDocument(pageMode: pageMode, deflate: deflate); 33 : document = PdfDocument(pageMode: pageMode, deflate: deflate);
40 34
  35 + static bool debug = false;
  36 +
  37 + final PdfDocument document;
  38 +
  39 + final Theme theme;
  40 +
41 void addPage(BasePage page) { 41 void addPage(BasePage page) {
42 page.generate(this); 42 page.generate(this);
43 } 43 }
44 } 44 }
45 45
46 -typedef Widget BuildCallback(Context context);  
47 -typedef List<Widget> BuildListCallback(Context context); 46 +typedef BuildCallback = Widget Function(Context context);
  47 +typedef BuildListCallback = List<Widget> Function(Context context);
48 48
49 class Page extends BasePage { 49 class Page extends BasePage {
50 - final EdgeInsets margin;  
51 - final BuildCallback _build;  
52 - final Theme theme;  
53 -  
54 Page( 50 Page(
55 {PdfPageFormat pageFormat = PdfPageFormat.a4, 51 {PdfPageFormat pageFormat = PdfPageFormat.a4,
56 BuildCallback build, 52 BuildCallback build,
@@ -62,6 +58,12 @@ class Page extends BasePage { @@ -62,6 +58,12 @@ class Page extends BasePage {
62 _build = build, 58 _build = build,
63 super(pageFormat: pageFormat); 59 super(pageFormat: pageFormat);
64 60
  61 + final EdgeInsets margin;
  62 +
  63 + final BuildCallback _build;
  64 +
  65 + final Theme theme;
  66 +
65 void debugPaint(Context context) { 67 void debugPaint(Context context) {
66 context.canvas 68 context.canvas
67 ..setFillColor(PdfColor.lightGreen) 69 ..setFillColor(PdfColor.lightGreen)
@@ -78,18 +80,19 @@ class Page extends BasePage { @@ -78,18 +80,19 @@ class Page extends BasePage {
78 80
79 @override 81 @override
80 void generate(Document document) { 82 void generate(Document document) {
81 - final pdfPage = PdfPage(document.document, pageFormat: pageFormat);  
82 - final canvas = pdfPage.getGraphics();  
83 - final constraints = BoxConstraints( 83 + final PdfPage pdfPage = PdfPage(document.document, pageFormat: pageFormat);
  84 + final PdfGraphics canvas = pdfPage.getGraphics();
  85 + final BoxConstraints constraints = BoxConstraints(
84 maxWidth: pageFormat.width, maxHeight: pageFormat.height); 86 maxWidth: pageFormat.width, maxHeight: pageFormat.height);
85 87
86 - final calculatedTheme = theme ?? document.theme ?? Theme(document.document);  
87 - final inherited = Map<Type, Inherited>(); 88 + final Theme calculatedTheme =
  89 + theme ?? document.theme ?? Theme(document.document);
  90 + final Map<Type, Inherited> inherited = <Type, Inherited>{};
88 inherited[calculatedTheme.runtimeType] = calculatedTheme; 91 inherited[calculatedTheme.runtimeType] = calculatedTheme;
89 - final context = 92 + final Context context =
90 Context(page: pdfPage, canvas: canvas, inherited: inherited); 93 Context(page: pdfPage, canvas: canvas, inherited: inherited);
91 if (_build != null) { 94 if (_build != null) {
92 - final child = _build(context); 95 + final Widget child = _build(context);
93 layout(child, context, constraints); 96 layout(child, context, constraints);
94 paint(child, context); 97 paint(child, context);
95 } 98 }
@@ -97,9 +100,9 @@ class Page extends BasePage { @@ -97,9 +100,9 @@ class Page extends BasePage {
97 100
98 @protected 101 @protected
99 void layout(Widget child, Context context, BoxConstraints constraints, 102 void layout(Widget child, Context context, BoxConstraints constraints,
100 - {parentUsesSize = false}) { 103 + {bool parentUsesSize = false}) {
101 if (child != null) { 104 if (child != null) {
102 - final childConstraints = BoxConstraints( 105 + final BoxConstraints childConstraints = BoxConstraints(
103 minWidth: constraints.minWidth, 106 minWidth: constraints.minWidth,
104 minHeight: constraints.minHeight, 107 minHeight: constraints.minHeight,
105 maxWidth: constraints.hasBoundedWidth 108 maxWidth: constraints.hasBoundedWidth
@@ -120,7 +123,9 @@ class Page extends BasePage { @@ -120,7 +123,9 @@ class Page extends BasePage {
120 @protected 123 @protected
121 void paint(Widget child, Context context) { 124 void paint(Widget child, Context context) {
122 assert(() { 125 assert(() {
123 - if (Document.debug) debugPaint(context); 126 + if (Document.debug) {
  127 + debugPaint(context);
  128 + }
124 return true; 129 return true;
125 }()); 130 }());
126 131
@@ -131,11 +136,6 @@ class Page extends BasePage { @@ -131,11 +136,6 @@ class Page extends BasePage {
131 } 136 }
132 137
133 class MultiPage extends Page { 138 class MultiPage extends Page {
134 - final BuildListCallback _buildList;  
135 - final CrossAxisAlignment crossAxisAlignment;  
136 - final BuildCallback header;  
137 - final BuildCallback footer;  
138 -  
139 MultiPage( 139 MultiPage(
140 {PdfPageFormat pageFormat = PdfPageFormat.a4, 140 {PdfPageFormat pageFormat = PdfPageFormat.a4,
141 BuildListCallback build, 141 BuildListCallback build,
@@ -146,39 +146,53 @@ class MultiPage extends Page { @@ -146,39 +146,53 @@ class MultiPage extends Page {
146 : _buildList = build, 146 : _buildList = build,
147 super(pageFormat: pageFormat, margin: margin); 147 super(pageFormat: pageFormat, margin: margin);
148 148
  149 + final BuildListCallback _buildList;
  150 +
  151 + final CrossAxisAlignment crossAxisAlignment;
  152 +
  153 + final BuildCallback header;
  154 +
  155 + final BuildCallback footer;
  156 +
149 @override 157 @override
150 void generate(Document document) { 158 void generate(Document document) {
151 - if (_buildList == null) return; 159 + if (_buildList == null) {
  160 + return;
  161 + }
152 162
153 - final constraints = BoxConstraints( 163 + final BoxConstraints constraints = BoxConstraints(
154 maxWidth: pageFormat.width, maxHeight: pageFormat.height); 164 maxWidth: pageFormat.width, maxHeight: pageFormat.height);
155 - final childConstraints = 165 + final BoxConstraints childConstraints =
156 BoxConstraints(maxWidth: constraints.maxWidth - margin.horizontal); 166 BoxConstraints(maxWidth: constraints.maxWidth - margin.horizontal);
157 - final calculatedTheme = theme ?? document.theme ?? Theme(document.document);  
158 - final inherited = Map<Type, Inherited>(); 167 + final Theme calculatedTheme =
  168 + theme ?? document.theme ?? Theme(document.document);
  169 + final Map<Type, Inherited> inherited = <Type, Inherited>{};
159 inherited[calculatedTheme.runtimeType] = calculatedTheme; 170 inherited[calculatedTheme.runtimeType] = calculatedTheme;
160 Context context; 171 Context context;
161 double offsetEnd; 172 double offsetEnd;
162 double offsetStart; 173 double offsetStart;
163 - var index = 0;  
164 - final children = _buildList(Context(inherited: inherited)); 174 + int index = 0;
  175 + final List<Widget> children = _buildList(Context(inherited: inherited));
165 WidgetContext widgetContext; 176 WidgetContext widgetContext;
166 177
167 while (index < children.length) { 178 while (index < children.length) {
168 - final child = children[index]; 179 + final Widget child = children[index];
169 180
170 if (context == null) { 181 if (context == null) {
171 - final pdfPage = PdfPage(document.document, pageFormat: pageFormat);  
172 - final canvas = pdfPage.getGraphics(); 182 + final PdfPage pdfPage =
  183 + PdfPage(document.document, pageFormat: pageFormat);
  184 + final PdfGraphics canvas = pdfPage.getGraphics();
173 context = Context(page: pdfPage, canvas: canvas, inherited: inherited); 185 context = Context(page: pdfPage, canvas: canvas, inherited: inherited);
174 assert(() { 186 assert(() {
175 - if (Document.debug) debugPaint(context); 187 + if (Document.debug) {
  188 + debugPaint(context);
  189 + }
176 return true; 190 return true;
177 }()); 191 }());
178 offsetStart = pageFormat.height - margin.top; 192 offsetStart = pageFormat.height - margin.top;
179 offsetEnd = margin.bottom; 193 offsetEnd = margin.bottom;
180 if (header != null) { 194 if (header != null) {
181 - final headerWidget = header(context); 195 + final Widget headerWidget = header(context);
182 if (headerWidget != null) { 196 if (headerWidget != null) {
183 headerWidget.layout(context, childConstraints, 197 headerWidget.layout(context, childConstraints,
184 parentUsesSize: false); 198 parentUsesSize: false);
@@ -193,7 +207,7 @@ class MultiPage extends Page { @@ -193,7 +207,7 @@ class MultiPage extends Page {
193 } 207 }
194 208
195 if (footer != null) { 209 if (footer != null) {
196 - final footerWidget = footer(context); 210 + final Widget footerWidget = footer(context);
197 if (footerWidget != null) { 211 if (footerWidget != null) {
198 footerWidget.layout(context, childConstraints, 212 footerWidget.layout(context, childConstraints,
199 parentUsesSize: false); 213 parentUsesSize: false);
@@ -206,7 +220,7 @@ class MultiPage extends Page { @@ -206,7 +220,7 @@ class MultiPage extends Page {
206 } 220 }
207 221
208 if (widgetContext != null && child is SpanningWidget) { 222 if (widgetContext != null && child is SpanningWidget) {
209 - (child as SpanningWidget).restoreContext(widgetContext); 223 + child.restoreContext(widgetContext);
210 widgetContext = null; 224 widgetContext = null;
211 } 225 }
212 226
@@ -222,7 +236,7 @@ class MultiPage extends Page { @@ -222,7 +236,7 @@ class MultiPage extends Page {
222 throw Exception("Widget won't fit into the page"); 236 throw Exception("Widget won't fit into the page");
223 } 237 }
224 238
225 - final span = child as SpanningWidget; 239 + final SpanningWidget span = child;
226 240
227 child.layout(context, 241 child.layout(context,
228 childConstraints.copyWith(maxHeight: offsetStart - offsetEnd), 242 childConstraints.copyWith(maxHeight: offsetStart - offsetEnd),
@@ -93,11 +93,11 @@ class Flex extends MultiChildWidget { @@ -93,11 +93,11 @@ class Flex extends MultiChildWidget {
93 double inflexibleSpace = 0.0; 93 double inflexibleSpace = 0.0;
94 double maxFlexFractionSoFar = 0.0; 94 double maxFlexFractionSoFar = 0.0;
95 95
96 - for (var child in children) {  
97 - final int flex = child._flex; 96 + for (Widget child in children) {
  97 + final int flex = child is Expanded ? child.flex : 0;
98 totalFlex += flex; 98 totalFlex += flex;
99 if (flex > 0) { 99 if (flex > 0) {
100 - final double flexFraction = childSize(child, extent) / child._flex; 100 + final double flexFraction = childSize(child, extent) / flex;
101 maxFlexFractionSoFar = math.max(maxFlexFractionSoFar, flexFraction); 101 maxFlexFractionSoFar = math.max(maxFlexFractionSoFar, flexFraction);
102 } else { 102 } else {
103 inflexibleSpace += childSize(child, extent); 103 inflexibleSpace += childSize(child, extent);
@@ -115,8 +115,8 @@ class Flex extends MultiChildWidget { @@ -115,8 +115,8 @@ class Flex extends MultiChildWidget {
115 int totalFlex = 0; 115 int totalFlex = 0;
116 double inflexibleSpace = 0.0; 116 double inflexibleSpace = 0.0;
117 double maxCrossSize = 0.0; 117 double maxCrossSize = 0.0;
118 - for (var child in children) {  
119 - final int flex = child._flex; 118 + for (Widget child in children) {
  119 + final int flex = child is Expanded ? child.flex : 0;
120 totalFlex += flex; 120 totalFlex += flex;
121 double mainSize; 121 double mainSize;
122 double crossSize; 122 double crossSize;
@@ -142,8 +142,8 @@ class Flex extends MultiChildWidget { @@ -142,8 +142,8 @@ class Flex extends MultiChildWidget {
142 math.max(0.0, (availableMainSpace - inflexibleSpace) / totalFlex); 142 math.max(0.0, (availableMainSpace - inflexibleSpace) / totalFlex);
143 143
144 // Size remaining (flexible) items, find the maximum cross size. 144 // Size remaining (flexible) items, find the maximum cross size.
145 - for (var child in children) {  
146 - final int flex = child._flex; 145 + for (Widget child in children) {
  146 + final int flex = child is Expanded ? child.flex : 0;
147 if (flex > 0) 147 if (flex > 0)
148 maxCrossSize = 148 maxCrossSize =
149 math.max(maxCrossSize, childSize(child, spacePerFlex * flex)); 149 math.max(maxCrossSize, childSize(child, spacePerFlex * flex));
@@ -203,10 +203,10 @@ class Flex extends MultiChildWidget { @@ -203,10 +203,10 @@ class Flex extends MultiChildWidget {
203 203
204 @override 204 @override
205 void layout(Context context, BoxConstraints constraints, 205 void layout(Context context, BoxConstraints constraints,
206 - {parentUsesSize = false}) { 206 + {bool parentUsesSize = false}) {
207 // Determine used flex factor, size inflexible items, calculate free space. 207 // Determine used flex factor, size inflexible items, calculate free space.
208 int totalFlex = 0; 208 int totalFlex = 0;
209 - final totalChildren = children.length; 209 + final int totalChildren = children.length;
210 Widget lastFlexChild; 210 Widget lastFlexChild;
211 assert(constraints != null); 211 assert(constraints != null);
212 final double maxMainSize = direction == Axis.horizontal 212 final double maxMainSize = direction == Axis.horizontal
@@ -218,22 +218,22 @@ class Flex extends MultiChildWidget { @@ -218,22 +218,22 @@ class Flex extends MultiChildWidget {
218 double allocatedSize = 218 double allocatedSize =
219 0.0; // Sum of the sizes of the non-flexible children. 219 0.0; // Sum of the sizes of the non-flexible children.
220 220
221 - for (var child in children) {  
222 - final int flex = child._flex; 221 + for (Widget child in children) {
  222 + final int flex = child is Expanded ? child.flex : 0;
  223 + final FlexFit fit = child is Expanded ? child.fit : FlexFit.loose;
223 if (flex > 0) { 224 if (flex > 0) {
224 assert(() { 225 assert(() {
225 final String dimension = 226 final String dimension =
226 direction == Axis.horizontal ? 'width' : 'height'; 227 direction == Axis.horizontal ? 'width' : 'height';
227 if (!canFlex && 228 if (!canFlex &&
228 - (mainAxisSize == MainAxisSize.max ||  
229 - child._fit == FlexFit.tight)) { 229 + (mainAxisSize == MainAxisSize.max || fit == FlexFit.tight)) {
230 throw Exception( 230 throw Exception(
231 'Flex children have non-zero flex but incoming $dimension constraints are unbounded.'); 231 'Flex children have non-zero flex but incoming $dimension constraints are unbounded.');
232 } else { 232 } else {
233 return true; 233 return true;
234 } 234 }
235 }()); 235 }());
236 - totalFlex += child._flex; 236 + totalFlex += flex;
237 } else { 237 } else {
238 BoxConstraints innerConstraints; 238 BoxConstraints innerConstraints;
239 if (crossAxisAlignment == CrossAxisAlignment.stretch) { 239 if (crossAxisAlignment == CrossAxisAlignment.stretch) {
@@ -275,8 +275,9 @@ class Flex extends MultiChildWidget { @@ -275,8 +275,9 @@ class Flex extends MultiChildWidget {
275 final double spacePerFlex = 275 final double spacePerFlex =
276 canFlex && totalFlex > 0 ? (freeSpace / totalFlex) : double.nan; 276 canFlex && totalFlex > 0 ? (freeSpace / totalFlex) : double.nan;
277 277
278 - for (var child in children) {  
279 - final int flex = child._flex; 278 + for (Widget child in children) {
  279 + final int flex = child is Expanded ? child.flex : 0;
  280 + final FlexFit fit = child is Expanded ? child.fit : FlexFit.loose;
280 if (flex > 0) { 281 if (flex > 0) {
281 final double maxChildExtent = canFlex 282 final double maxChildExtent = canFlex
282 ? (child == lastFlexChild 283 ? (child == lastFlexChild
@@ -284,7 +285,7 @@ class Flex extends MultiChildWidget { @@ -284,7 +285,7 @@ class Flex extends MultiChildWidget {
284 : spacePerFlex * flex) 285 : spacePerFlex * flex)
285 : double.infinity; 286 : double.infinity;
286 double minChildExtent; 287 double minChildExtent;
287 - switch (child._fit) { 288 + switch (fit) {
288 case FlexFit.tight: 289 case FlexFit.tight:
289 assert(maxChildExtent < double.infinity); 290 assert(maxChildExtent < double.infinity);
290 minChildExtent = maxChildExtent; 291 minChildExtent = maxChildExtent;
@@ -404,7 +405,7 @@ class Flex extends MultiChildWidget { @@ -404,7 +405,7 @@ class Flex extends MultiChildWidget {
404 direction == Axis.vertical); 405 direction == Axis.vertical);
405 double childMainPosition = 406 double childMainPosition =
406 flipMainAxis ? actualSize - leadingSpace : leadingSpace; 407 flipMainAxis ? actualSize - leadingSpace : leadingSpace;
407 - for (var child in children) { 408 + for (Widget child in children) {
408 double childCrossPosition; 409 double childCrossPosition;
409 switch (crossAxisAlignment) { 410 switch (crossAxisAlignment) {
410 case CrossAxisAlignment.start: 411 case CrossAxisAlignment.start:
@@ -423,7 +424,9 @@ class Flex extends MultiChildWidget { @@ -423,7 +424,9 @@ class Flex extends MultiChildWidget {
423 break; 424 break;
424 } 425 }
425 426
426 - if (flipMainAxis) childMainPosition -= _getMainSize(child); 427 + if (flipMainAxis) {
  428 + childMainPosition -= _getMainSize(child);
  429 + }
427 switch (direction) { 430 switch (direction) {
428 case Axis.horizontal: 431 case Axis.horizontal:
429 child.box = PdfRect(box.x + childMainPosition, 432 child.box = PdfRect(box.x + childMainPosition,
@@ -446,12 +449,12 @@ class Flex extends MultiChildWidget { @@ -446,12 +449,12 @@ class Flex extends MultiChildWidget {
446 void paint(Context context) { 449 void paint(Context context) {
447 super.paint(context); 450 super.paint(context);
448 451
449 - final mat = Matrix4.identity(); 452 + final Matrix4 mat = Matrix4.identity();
450 mat.translate(box.x, box.y); 453 mat.translate(box.x, box.y);
451 context.canvas 454 context.canvas
452 ..saveContext() 455 ..saveContext()
453 ..setTransform(mat); 456 ..setTransform(mat);
454 - for (var child in children) { 457 + for (Widget child in children) {
455 child.paint(context); 458 child.paint(context);
456 } 459 }
457 context.canvas.restoreContext(); 460 context.canvas.restoreContext();
@@ -494,20 +497,22 @@ class Column extends Flex { @@ -494,20 +497,22 @@ class Column extends Flex {
494 497
495 class Expanded extends SingleChildWidget { 498 class Expanded extends SingleChildWidget {
496 Expanded({ 499 Expanded({
497 - int flex = 1, 500 + this.flex = 1,
  501 + this.fit = FlexFit.tight,
498 @required Widget child, 502 @required Widget child,
499 - }) : super(child: child) {  
500 - this._flex = flex;  
501 - this._fit = FlexFit.tight;  
502 - } 503 + }) : super(child: child);
  504 +
  505 + final int flex;
  506 +
  507 + final FlexFit fit;
503 } 508 }
504 509
505 class ListView extends Flex { 510 class ListView extends Flex {
506 ListView( 511 ListView(
507 {Axis direction = Axis.vertical, 512 {Axis direction = Axis.vertical,
508 - EdgeInsets padding,  
509 - double spacing = 0.0,  
510 - List<Widget> children = const []}) 513 + // EdgeInsets padding,
  514 + // double spacing = 0.0,
  515 + List<Widget> children = const <Widget>[]})
511 : super( 516 : super(
512 direction: direction, 517 direction: direction,
513 mainAxisAlignment: MainAxisAlignment.start, 518 mainAxisAlignment: MainAxisAlignment.start,
@@ -18,6 +18,27 @@ part of widget; @@ -18,6 +18,27 @@ part of widget;
18 18
19 @immutable 19 @immutable
20 class BoxConstraints { 20 class BoxConstraints {
  21 + /// Creates box constraints with the given constraints.
  22 + const BoxConstraints(
  23 + {this.minWidth = 0.0,
  24 + this.maxWidth = double.infinity,
  25 + this.minHeight = 0.0,
  26 + this.maxHeight = double.infinity});
  27 +
  28 + /// Creates box constraints that require the given width or height.
  29 + const BoxConstraints.tightFor({double width, double height})
  30 + : minWidth = width != null ? width : 0.0,
  31 + maxWidth = width != null ? width : double.infinity,
  32 + minHeight = height != null ? height : 0.0,
  33 + maxHeight = height != null ? height : double.infinity;
  34 +
  35 + /// Creates box constraints that expand to fill another box constraints.
  36 + const BoxConstraints.expand({double width, double height})
  37 + : minWidth = width != null ? width : double.infinity,
  38 + maxWidth = width != null ? width : double.infinity,
  39 + minHeight = height != null ? height : double.infinity,
  40 + maxHeight = height != null ? height : double.infinity;
  41 +
21 /// The minimum width that satisfies the constraints. 42 /// The minimum width that satisfies the constraints.
22 final double minWidth; 43 final double minWidth;
23 44
@@ -34,13 +55,6 @@ class BoxConstraints { @@ -34,13 +55,6 @@ class BoxConstraints {
34 /// Might be [double.infinity]. 55 /// Might be [double.infinity].
35 final double maxHeight; 56 final double maxHeight;
36 57
37 - /// Creates box constraints with the given constraints.  
38 - const BoxConstraints(  
39 - {this.minWidth = 0.0,  
40 - this.maxWidth = double.infinity,  
41 - this.minHeight = 0.0,  
42 - this.maxHeight = double.infinity});  
43 -  
44 bool get hasBoundedWidth => maxWidth < double.infinity; 58 bool get hasBoundedWidth => maxWidth < double.infinity;
45 59
46 bool get hasBoundedHeight => maxHeight < double.infinity; 60 bool get hasBoundedHeight => maxHeight < double.infinity;
@@ -65,13 +79,15 @@ class BoxConstraints { @@ -65,13 +79,15 @@ class BoxConstraints {
65 bool get isTight => hasTightWidth && hasTightHeight; 79 bool get isTight => hasTightWidth && hasTightHeight;
66 80
67 PdfPoint constrain(PdfPoint size) { 81 PdfPoint constrain(PdfPoint size) {
68 - final result = PdfPoint(constrainWidth(size.x), constrainHeight(size.y)); 82 + final PdfPoint result =
  83 + PdfPoint(constrainWidth(size.x), constrainHeight(size.y));
69 return result; 84 return result;
70 } 85 }
71 86
72 PdfRect constrainRect( 87 PdfRect constrainRect(
73 {double width = double.infinity, double height = double.infinity}) { 88 {double width = double.infinity, double height = double.infinity}) {
74 - final result = PdfPoint(constrainWidth(width), constrainHeight(height)); 89 + final PdfPoint result =
  90 + PdfPoint(constrainWidth(width), constrainHeight(height));
75 return PdfRect.fromPoints(PdfPoint.zero, result); 91 return PdfRect.fromPoints(PdfPoint.zero, result);
76 } 92 }
77 93
@@ -86,8 +102,7 @@ class BoxConstraints { @@ -86,8 +102,7 @@ class BoxConstraints {
86 /// Returns a size that attempts to meet the conditions 102 /// Returns a size that attempts to meet the conditions
87 PdfPoint constrainSizeAndAttemptToPreserveAspectRatio(PdfPoint size) { 103 PdfPoint constrainSizeAndAttemptToPreserveAspectRatio(PdfPoint size) {
88 if (isTight) { 104 if (isTight) {
89 - PdfPoint result = smallest;  
90 - 105 + final PdfPoint result = smallest;
91 return result; 106 return result;
92 } 107 }
93 108
@@ -117,7 +132,8 @@ class BoxConstraints { @@ -117,7 +132,8 @@ class BoxConstraints {
117 width = height * aspectRatio; 132 width = height * aspectRatio;
118 } 133 }
119 134
120 - PdfPoint result = PdfPoint(constrainWidth(width), constrainHeight(height)); 135 + final PdfPoint result =
  136 + PdfPoint(constrainWidth(width), constrainHeight(height));
121 return result; 137 return result;
122 } 138 }
123 139
@@ -134,20 +150,6 @@ class BoxConstraints { @@ -134,20 +150,6 @@ class BoxConstraints {
134 height == null ? maxHeight : height.clamp(minHeight, maxHeight)); 150 height == null ? maxHeight : height.clamp(minHeight, maxHeight));
135 } 151 }
136 152
137 - /// Creates box constraints that require the given width or height.  
138 - const BoxConstraints.tightFor({double width, double height})  
139 - : minWidth = width != null ? width : 0.0,  
140 - maxWidth = width != null ? width : double.infinity,  
141 - minHeight = height != null ? height : 0.0,  
142 - maxHeight = height != null ? height : double.infinity;  
143 -  
144 - /// Creates box constraints that expand to fill another box constraints.  
145 - const BoxConstraints.expand({double width, double height})  
146 - : minWidth = width != null ? width : double.infinity,  
147 - maxWidth = width != null ? width : double.infinity,  
148 - minHeight = height != null ? height : double.infinity,  
149 - maxHeight = height != null ? height : double.infinity;  
150 -  
151 /// Returns new box constraints that are smaller by the given edge dimensions. 153 /// Returns new box constraints that are smaller by the given edge dimensions.
152 BoxConstraints deflate(EdgeInsets edges) { 154 BoxConstraints deflate(EdgeInsets edges) {
153 assert(edges != null); 155 assert(edges != null);
@@ -194,7 +196,7 @@ class BoxConstraints { @@ -194,7 +196,7 @@ class BoxConstraints {
194 196
195 @override 197 @override
196 String toString() { 198 String toString() {
197 - return "BoxConstraint <$minWidth, $maxWidth> <$minHeight, $maxHeight>"; 199 + return 'BoxConstraint <$minWidth, $maxWidth> <$minHeight, $maxHeight>';
198 } 200 }
199 } 201 }
200 202
@@ -327,7 +329,7 @@ class Alignment { @@ -327,7 +329,7 @@ class Alignment {
327 } 329 }
328 330
329 @override 331 @override
330 - String toString() => "($x, $y)"; 332 + String toString() => '($x, $y)';
331 } 333 }
332 334
333 /// The pair of sizes returned by [applyBoxFit]. 335 /// The pair of sizes returned by [applyBoxFit].
@@ -411,10 +413,10 @@ PdfPoint transformPoint(Matrix4 transform, PdfPoint point) { @@ -411,10 +413,10 @@ PdfPoint transformPoint(Matrix4 transform, PdfPoint point) {
411 } 413 }
412 414
413 PdfRect transformRect(Matrix4 transform, PdfRect rect) { 415 PdfRect transformRect(Matrix4 transform, PdfRect rect) {
414 - final point1 = transformPoint(transform, rect.topLeft);  
415 - final point2 = transformPoint(transform, rect.topRight);  
416 - final point3 = transformPoint(transform, rect.bottomLeft);  
417 - final point4 = transformPoint(transform, rect.bottomRight); 416 + final PdfPoint point1 = transformPoint(transform, rect.topLeft);
  417 + final PdfPoint point2 = transformPoint(transform, rect.topRight);
  418 + final PdfPoint point3 = transformPoint(transform, rect.bottomLeft);
  419 + final PdfPoint point4 = transformPoint(transform, rect.bottomRight);
418 return PdfRect.fromLTRB( 420 return PdfRect.fromLTRB(
419 math.min(point1.x, math.min(point2.x, math.min(point3.x, point4.x))), 421 math.min(point1.x, math.min(point2.x, math.min(point3.x, point4.x))),
420 math.min(point1.y, math.min(point2.y, math.min(point3.y, point4.y))), 422 math.min(point1.y, math.min(point2.y, math.min(point3.y, point4.y))),
@@ -24,7 +24,7 @@ class GridView extends MultiChildWidget { @@ -24,7 +24,7 @@ class GridView extends MultiChildWidget {
24 this.mainAxisSpacing = 0.0, 24 this.mainAxisSpacing = 0.0,
25 this.crossAxisSpacing = 0.0, 25 this.crossAxisSpacing = 0.0,
26 this.childAspectRatio = double.infinity, 26 this.childAspectRatio = double.infinity,
27 - List<Widget> children = const []}) 27 + List<Widget> children = const <Widget>[]})
28 : assert(padding != null), 28 : assert(padding != null),
29 super(children: children); 29 super(children: children);
30 30
@@ -43,7 +43,7 @@ class GridView extends MultiChildWidget { @@ -43,7 +43,7 @@ class GridView extends MultiChildWidget {
43 43
44 @override 44 @override
45 void layout(Context context, BoxConstraints constraints, 45 void layout(Context context, BoxConstraints constraints,
46 - {parentUsesSize = false}) { 46 + {bool parentUsesSize = false}) {
47 double mainAxisExtent; 47 double mainAxisExtent;
48 double crossAxisExtent; 48 double crossAxisExtent;
49 switch (direction) { 49 switch (direction) {
@@ -69,10 +69,10 @@ class GridView extends MultiChildWidget { @@ -69,10 +69,10 @@ class GridView extends MultiChildWidget {
69 _totalCross = (_childCrossAxis + crossAxisSpacing) * crossAxisCount - 69 _totalCross = (_childCrossAxis + crossAxisSpacing) * crossAxisCount -
70 crossAxisSpacing; 70 crossAxisSpacing;
71 71
72 - var startX = padding.left;  
73 - var startY = 0.0;  
74 - var mainAxis;  
75 - var crossAxis; 72 + final double startX = padding.left;
  73 + const double startY = 0.0;
  74 + double mainAxis;
  75 + double crossAxis;
76 BoxConstraints innerConstraints; 76 BoxConstraints innerConstraints;
77 switch (direction) { 77 switch (direction) {
78 case Axis.vertical: 78 case Axis.vertical:
@@ -89,8 +89,8 @@ class GridView extends MultiChildWidget { @@ -89,8 +89,8 @@ class GridView extends MultiChildWidget {
89 break; 89 break;
90 } 90 }
91 91
92 - var c = 0;  
93 - for (var child in children) { 92 + int c = 0;
  93 + for (Widget child in children) {
94 child.layout(context, innerConstraints); 94 child.layout(context, innerConstraints);
95 95
96 switch (direction) { 96 switch (direction) {
@@ -157,7 +157,7 @@ class GridView extends MultiChildWidget { @@ -157,7 +157,7 @@ class GridView extends MultiChildWidget {
157 ..lineTo(box.right - padding.right, box.bottom + padding.bottom) 157 ..lineTo(box.right - padding.right, box.bottom + padding.bottom)
158 ..fillPath(); 158 ..fillPath();
159 159
160 - for (var c = 1; c < crossAxisCount; c++) { 160 + for (int c = 1; c < crossAxisCount; c++) {
161 switch (direction) { 161 switch (direction) {
162 case Axis.vertical: 162 case Axis.vertical:
163 context.canvas 163 context.canvas
@@ -176,7 +176,7 @@ class GridView extends MultiChildWidget { @@ -176,7 +176,7 @@ class GridView extends MultiChildWidget {
176 } 176 }
177 } 177 }
178 178
179 - for (var c = 1; c < _mainAxisCount; c++) { 179 + for (int c = 1; c < _mainAxisCount; c++) {
180 switch (direction) { 180 switch (direction) {
181 case Axis.vertical: 181 case Axis.vertical:
182 context.canvas 182 context.canvas
@@ -200,12 +200,12 @@ class GridView extends MultiChildWidget { @@ -200,12 +200,12 @@ class GridView extends MultiChildWidget {
200 void paint(Context context) { 200 void paint(Context context) {
201 super.paint(context); 201 super.paint(context);
202 202
203 - final mat = Matrix4.identity(); 203 + final Matrix4 mat = Matrix4.identity();
204 mat.translate(box.x, box.y); 204 mat.translate(box.x, box.y);
205 context.canvas 205 context.canvas
206 ..saveContext() 206 ..saveContext()
207 ..setTransform(mat); 207 ..setTransform(mat);
208 - for (var child in children) { 208 + for (Widget child in children) {
209 child.paint(context); 209 child.paint(context);
210 } 210 }
211 context.canvas.restoreContext(); 211 context.canvas.restoreContext();
@@ -17,21 +17,23 @@ @@ -17,21 +17,23 @@
17 part of widget; 17 part of widget;
18 18
19 class Image extends Widget { 19 class Image extends Widget {
  20 + Image(this.image, {this.fit = BoxFit.contain})
  21 + : assert(image != null),
  22 + aspectRatio = image.height.toDouble() / image.width.toDouble();
  23 +
20 final PdfImage image; 24 final PdfImage image;
  25 +
21 final double aspectRatio; 26 final double aspectRatio;
22 - final BoxFit fit;  
23 27
24 - Image(this.image, {this.fit = BoxFit.contain})  
25 - : assert(image != null),  
26 - aspectRatio = (image.height.toDouble() / image.width.toDouble()); 28 + final BoxFit fit;
27 29
28 @override 30 @override
29 void layout(Context context, BoxConstraints constraints, 31 void layout(Context context, BoxConstraints constraints,
30 - {parentUsesSize = false}) {  
31 - final w = constraints.hasBoundedWidth 32 + {bool parentUsesSize = false}) {
  33 + final double w = constraints.hasBoundedWidth
32 ? constraints.maxWidth 34 ? constraints.maxWidth
33 : constraints.constrainWidth(image.width.toDouble()); 35 : constraints.constrainWidth(image.width.toDouble());
34 - final h = constraints.hasBoundedHeight 36 + final double h = constraints.hasBoundedHeight
35 ? constraints.maxHeight 37 ? constraints.maxHeight
36 : constraints.constrainHeight(image.height.toDouble()); 38 : constraints.constrainHeight(image.height.toDouble());
37 39
@@ -51,14 +53,6 @@ class Image extends Widget { @@ -51,14 +53,6 @@ class Image extends Widget {
51 } 53 }
52 54
53 class Shape extends Widget { 55 class Shape extends Widget {
54 - final String shape;  
55 - final PdfColor strokeColor;  
56 - final PdfColor fillColor;  
57 - final double width;  
58 - final double height;  
59 - final double aspectRatio;  
60 - final BoxFit fit;  
61 -  
62 Shape( 56 Shape(
63 this.shape, { 57 this.shape, {
64 this.strokeColor, 58 this.strokeColor,
@@ -70,13 +64,27 @@ class Shape extends Widget { @@ -70,13 +64,27 @@ class Shape extends Widget {
70 assert(height != null && height > 0.0), 64 assert(height != null && height > 0.0),
71 aspectRatio = height / width; 65 aspectRatio = height / width;
72 66
  67 + final String shape;
  68 +
  69 + final PdfColor strokeColor;
  70 +
  71 + final PdfColor fillColor;
  72 +
  73 + final double width;
  74 +
  75 + final double height;
  76 +
  77 + final double aspectRatio;
  78 +
  79 + final BoxFit fit;
  80 +
73 @override 81 @override
74 void layout(Context context, BoxConstraints constraints, 82 void layout(Context context, BoxConstraints constraints,
75 - {parentUsesSize = false}) {  
76 - final w = constraints.hasBoundedWidth 83 + {bool parentUsesSize = false}) {
  84 + final double w = constraints.hasBoundedWidth
77 ? constraints.maxWidth 85 ? constraints.maxWidth
78 : constraints.constrainWidth(width); 86 : constraints.constrainWidth(width);
79 - final h = constraints.hasBoundedHeight 87 + final double h = constraints.hasBoundedHeight
80 ? constraints.maxHeight 88 ? constraints.maxHeight
81 : constraints.constrainHeight(height); 89 : constraints.constrainHeight(height);
82 90
@@ -89,7 +97,7 @@ class Shape extends Widget { @@ -89,7 +97,7 @@ class Shape extends Widget {
89 void paint(Context context) { 97 void paint(Context context) {
90 super.paint(context); 98 super.paint(context);
91 99
92 - final mat = Matrix4.identity(); 100 + final Matrix4 mat = Matrix4.identity();
93 mat.translate(box.x, box.y + box.height); 101 mat.translate(box.x, box.y + box.height);
94 mat.scale(box.width / width, -box.height / height); 102 mat.scale(box.width / width, -box.height / height);
95 context.canvas 103 context.canvas
@@ -17,20 +17,23 @@ @@ -17,20 +17,23 @@
17 part of widget; 17 part of widget;
18 18
19 class Placeholder extends Widget { 19 class Placeholder extends Widget {
20 - final PdfColor color;  
21 - final double strokeWidth;  
22 - final double fallbackWidth;  
23 - final double fallbackHeight;  
24 -  
25 Placeholder( 20 Placeholder(
26 {this.color = const PdfColor.fromInt(0xFF455A64), 21 {this.color = const PdfColor.fromInt(0xFF455A64),
27 this.strokeWidth = 2.0, 22 this.strokeWidth = 2.0,
28 this.fallbackWidth = 400.0, 23 this.fallbackWidth = 400.0,
29 this.fallbackHeight = 400.0}); 24 this.fallbackHeight = 400.0});
30 25
  26 + final PdfColor color;
  27 +
  28 + final double strokeWidth;
  29 +
  30 + final double fallbackWidth;
  31 +
  32 + final double fallbackHeight;
  33 +
31 @override 34 @override
32 void layout(Context context, BoxConstraints constraints, 35 void layout(Context context, BoxConstraints constraints,
33 - {parentUsesSize = false}) { 36 + {bool parentUsesSize = false}) {
34 box = PdfRect( 37 box = PdfRect(
35 0.0, 38 0.0,
36 0.0, 39 0.0,
@@ -41,7 +44,7 @@ class Placeholder extends Widget { @@ -41,7 +44,7 @@ class Placeholder extends Widget {
41 : fallbackHeight)); 44 : fallbackHeight));
42 } 45 }
43 46
44 - @protected 47 + @override
45 void paint(Context context) { 48 void paint(Context context) {
46 super.paint(context); 49 super.paint(context);
47 50
@@ -63,8 +66,8 @@ class PdfLogo extends StatelessWidget { @@ -63,8 +66,8 @@ class PdfLogo extends StatelessWidget {
63 final PdfColor color; 66 final PdfColor color;
64 final BoxFit fit; 67 final BoxFit fit;
65 68
66 - static const pdf =  
67 - "M 2.424 26.712 L 2.424 26.712 C 2.076 26.712 1.742 26.599 1.457 26.386 C 0.416 25.605 0.276 24.736 0.342 24.144 C 0.524 22.516 2.537 20.812 6.327 19.076 C 7.831 15.78 9.262 11.719 10.115 8.326 C 9.117 6.154 8.147 3.336 8.854 1.683 C 9.102 1.104 9.411 0.66 9.988 0.468 C 10.216 0.392 10.792 0.296 11.004 0.296 C 11.508 0.296 11.951 0.945 12.265 1.345 C 12.56 1.721 13.229 2.518 11.892 8.147 C 13.24 10.931 15.15 13.767 16.98 15.709 C 18.291 15.472 19.419 15.351 20.338 15.351 C 21.904 15.351 22.853 15.716 23.24 16.468 C 23.56 17.09 23.429 17.817 22.85 18.628 C 22.293 19.407 21.525 19.819 20.63 19.819 C 19.414 19.819 17.998 19.051 16.419 17.534 C 13.582 18.127 10.269 19.185 7.591 20.356 C 6.755 22.13 5.954 23.559 5.208 24.607 C 4.183 26.042 3.299 26.712 2.424 26.712 Z M 5.086 21.586 C 2.949 22.787 2.078 23.774 2.015 24.33 C 2.005 24.422 1.978 24.664 2.446 25.022 C 2.595 24.975 3.465 24.578 5.086 21.586 Z M 18.723 17.144 C 19.538 17.771 19.737 18.088 20.27 18.088 C 20.504 18.088 21.171 18.078 21.48 17.647 C 21.629 17.438 21.687 17.304 21.71 17.232 C 21.587 17.167 21.424 17.035 20.535 17.035 C 20.03 17.036 19.395 17.058 18.723 17.144 Z M 11.253 10.562 C 10.538 13.036 9.594 15.707 8.579 18.126 C 10.669 17.315 12.941 16.607 15.075 16.106 C 13.725 14.538 12.376 12.58 11.253 10.562 Z M 10.646 2.1 C 10.548 2.133 9.316 3.857 10.742 5.316 C 11.691 3.201 10.689 2.086 10.646 2.1 Z"; 69 + static const String pdf =
  70 + 'M 2.424 26.712 L 2.424 26.712 C 2.076 26.712 1.742 26.599 1.457 26.386 C 0.416 25.605 0.276 24.736 0.342 24.144 C 0.524 22.516 2.537 20.812 6.327 19.076 C 7.831 15.78 9.262 11.719 10.115 8.326 C 9.117 6.154 8.147 3.336 8.854 1.683 C 9.102 1.104 9.411 0.66 9.988 0.468 C 10.216 0.392 10.792 0.296 11.004 0.296 C 11.508 0.296 11.951 0.945 12.265 1.345 C 12.56 1.721 13.229 2.518 11.892 8.147 C 13.24 10.931 15.15 13.767 16.98 15.709 C 18.291 15.472 19.419 15.351 20.338 15.351 C 21.904 15.351 22.853 15.716 23.24 16.468 C 23.56 17.09 23.429 17.817 22.85 18.628 C 22.293 19.407 21.525 19.819 20.63 19.819 C 19.414 19.819 17.998 19.051 16.419 17.534 C 13.582 18.127 10.269 19.185 7.591 20.356 C 6.755 22.13 5.954 23.559 5.208 24.607 C 4.183 26.042 3.299 26.712 2.424 26.712 Z M 5.086 21.586 C 2.949 22.787 2.078 23.774 2.015 24.33 C 2.005 24.422 1.978 24.664 2.446 25.022 C 2.595 24.975 3.465 24.578 5.086 21.586 Z M 18.723 17.144 C 19.538 17.771 19.737 18.088 20.27 18.088 C 20.504 18.088 21.171 18.078 21.48 17.647 C 21.629 17.438 21.687 17.304 21.71 17.232 C 21.587 17.167 21.424 17.035 20.535 17.035 C 20.03 17.036 19.395 17.058 18.723 17.144 Z M 11.253 10.562 C 10.538 13.036 9.594 15.707 8.579 18.126 C 10.669 17.315 12.941 16.607 15.075 16.106 C 13.725 14.538 12.376 12.58 11.253 10.562 Z M 10.646 2.1 C 10.548 2.133 9.316 3.857 10.742 5.316 C 11.691 3.201 10.689 2.086 10.646 2.1 Z';
68 71
69 @override 72 @override
70 Widget build(Context context) { 73 Widget build(Context context) {
@@ -79,38 +82,42 @@ class LoremText { @@ -79,38 +82,42 @@ class LoremText {
79 82
80 final math.Random random; 83 final math.Random random;
81 84
82 - static final words =  
83 - "ad adipiscing aliqua aliquip amet anim aute cillum commodo consectetur consequat culpa cupidatat deserunt do dolor dolore duis ea eiusmod elit enim esse est et eu ex excepteur exercitation fugiat id in incididunt ipsum irure labore laboris laborum lorem magna minim mollit nisi non nostrud nulla occaecat officia pariatur proident qui quis reprehenderit sed sint sit sunt tempor ullamco ut velit veniam voluptate"  
84 - .split(" "); 85 + static final List<String> words =
  86 + 'ad adipiscing aliqua aliquip amet anim aute cillum commodo consectetur consequat culpa cupidatat deserunt do dolor dolore duis ea eiusmod elit enim esse est et eu ex excepteur exercitation fugiat id in incididunt ipsum irure labore laboris laborum lorem magna minim mollit nisi non nostrud nulla occaecat officia pariatur proident qui quis reprehenderit sed sint sit sunt tempor ullamco ut velit veniam voluptate'
  87 + .split(' ');
85 88
86 String word() { 89 String word() {
87 return words[random.nextInt(words.length - 1)]; 90 return words[random.nextInt(words.length - 1)];
88 } 91 }
89 92
90 String sentence(int length) { 93 String sentence(int length) {
91 - final wordList = List<String>();  
92 - for (var i = 0; i < length; i++) {  
93 - var w = word();  
94 - if (i < length - 1 && random.nextInt(10) == 0) w += ","; 94 + final List<String> wordList = <String>[];
  95 + for (int i = 0; i < length; i++) {
  96 + String w = word();
  97 + if (i < length - 1 && random.nextInt(10) == 0) {
  98 + w += ',';
  99 + }
95 wordList.add(w); 100 wordList.add(w);
96 } 101 }
97 - var text = wordList.join(" ") + "."; 102 + final String text = wordList.join(' ') + '.';
98 return text[0].toUpperCase() + text.substring(1); 103 return text[0].toUpperCase() + text.substring(1);
99 } 104 }
100 105
101 String paragraph(int length) { 106 String paragraph(int length) {
102 - var wordsCount = 0;  
103 - final sentenceList = List<String>();  
104 - var n = 0; 107 + int wordsCount = 0;
  108 + final List<String> sentenceList = <String>[];
  109 + int n = 0;
105 while (wordsCount < length) { 110 while (wordsCount < length) {
106 n++; 111 n++;
107 - if (n > 100) break;  
108 - var count = math.min(length, 112 + if (n > 100) {
  113 + break;
  114 + }
  115 + final int count = math.min(length,
109 math.max(10, math.min(3, random.nextInt(length - wordsCount)))); 116 math.max(10, math.min(3, random.nextInt(length - wordsCount))));
110 sentenceList.add(sentence(count)); 117 sentenceList.add(sentence(count));
111 wordsCount += count; 118 wordsCount += count;
112 } 119 }
113 - return sentenceList.join(" "); 120 + return sentenceList.join(' ');
114 } 121 }
115 } 122 }
116 123
@@ -134,8 +141,8 @@ class Lorem extends StatelessWidget { @@ -134,8 +141,8 @@ class Lorem extends StatelessWidget {
134 141
135 @override 142 @override
136 Widget build(Context context) { 143 Widget build(Context context) {
137 - final lorem = LoremText(random: random);  
138 - final text = lorem.paragraph(length); 144 + final LoremText lorem = LoremText(random: random);
  145 + final String text = lorem.paragraph(length);
139 146
140 return Text(text, 147 return Text(text,
141 style: style, 148 style: style,
@@ -59,8 +59,8 @@ class TableBorder extends BoxBorder { @@ -59,8 +59,8 @@ class TableBorder extends BoxBorder {
59 super.paintBorders(context, box); 59 super.paintBorders(context, box);
60 60
61 if (verticalInside) { 61 if (verticalInside) {
62 - var offset = box.x;  
63 - for (var width in widths.sublist(0, widths.length - 1)) { 62 + double offset = box.x;
  63 + for (double width in widths.sublist(0, widths.length - 1)) {
64 offset += width; 64 offset += width;
65 context.canvas.moveTo(offset, box.y); 65 context.canvas.moveTo(offset, box.y);
66 context.canvas.lineTo(offset, box.top); 66 context.canvas.lineTo(offset, box.top);
@@ -69,8 +69,8 @@ class TableBorder extends BoxBorder { @@ -69,8 +69,8 @@ class TableBorder extends BoxBorder {
69 } 69 }
70 70
71 if (horizontalInside) { 71 if (horizontalInside) {
72 - var offset = box.top;  
73 - for (var height in heights.sublist(0, heights.length - 1)) { 72 + double offset = box.top;
  73 + for (double height in heights.sublist(0, heights.length - 1)) {
74 offset -= height; 74 offset -= height;
75 context.canvas.moveTo(box.x, offset); 75 context.canvas.moveTo(box.x, offset);
76 context.canvas.lineTo(box.right, offset); 76 context.canvas.lineTo(box.right, offset);
@@ -81,8 +81,8 @@ class TableBorder extends BoxBorder { @@ -81,8 +81,8 @@ class TableBorder extends BoxBorder {
81 } 81 }
82 82
83 class _TableContext extends WidgetContext { 83 class _TableContext extends WidgetContext {
84 - var firstLine = 0;  
85 - var lastLine = 0; 84 + int firstLine = 0;
  85 + int lastLine = 0;
86 } 86 }
87 87
88 /// A widget that uses the table layout algorithm for its children. 88 /// A widget that uses the table layout algorithm for its children.
@@ -95,6 +95,33 @@ class Table extends Widget implements SpanningWidget { @@ -95,6 +95,33 @@ class Table extends Widget implements SpanningWidget {
95 : assert(children != null), 95 : assert(children != null),
96 super(); 96 super();
97 97
  98 + factory Table.fromTextArray(
  99 + {@required Context context, @required List<List<String>> data}) {
  100 + final List<TableRow> rows = <TableRow>[];
  101 + for (List<String> row in data) {
  102 + final List<Widget> tableRow = <Widget>[];
  103 + if (row == data.first) {
  104 + for (String cell in row) {
  105 + tableRow.add(Container(
  106 + alignment: Alignment.center,
  107 + margin: const EdgeInsets.all(5),
  108 + child: Text(cell, style: Theme.of(context).tableHeader)));
  109 + }
  110 + } else {
  111 + for (String cell in row) {
  112 + tableRow.add(Container(
  113 + margin: const EdgeInsets.all(5),
  114 + child: Text(cell, style: Theme.of(context).tableCell)));
  115 + }
  116 + }
  117 + rows.add(TableRow(children: tableRow, repeat: row == data.first));
  118 + }
  119 + return Table(
  120 + border: const TableBorder(),
  121 + tableWidth: TableWidth.max,
  122 + children: rows);
  123 + }
  124 +
98 @override 125 @override
99 bool get canSpan => true; 126 bool get canSpan => true;
100 127
@@ -107,10 +134,10 @@ class Table extends Widget implements SpanningWidget { @@ -107,10 +134,10 @@ class Table extends Widget implements SpanningWidget {
107 134
108 final TableWidth tableWidth; 135 final TableWidth tableWidth;
109 136
110 - final _widths = List<double>();  
111 - final _heights = List<double>(); 137 + final List<double> _widths = <double>[];
  138 + final List<double> _heights = <double>[];
112 139
113 - var _context = _TableContext(); 140 + _TableContext _context = _TableContext();
114 141
115 @override 142 @override
116 WidgetContext saveContext() { 143 WidgetContext saveContext() {
@@ -125,20 +152,21 @@ class Table extends Widget implements SpanningWidget { @@ -125,20 +152,21 @@ class Table extends Widget implements SpanningWidget {
125 152
126 @override 153 @override
127 void layout(Context context, BoxConstraints constraints, 154 void layout(Context context, BoxConstraints constraints,
128 - {parentUsesSize = false}) { 155 + {bool parentUsesSize = false}) {
129 // Compute required width for all row/columns width flex 156 // Compute required width for all row/columns width flex
130 - final flex = List<double>(); 157 + final List<double> flex = <double>[];
131 _widths.clear(); 158 _widths.clear();
132 _heights.clear(); 159 _heights.clear();
133 - var index = 0; 160 + int index = 0;
134 161
135 - for (var row in children) {  
136 - var n = 0;  
137 - for (var child in row.children) {  
138 - child.layout(context, BoxConstraints());  
139 - final calculatedWidth = 162 + for (TableRow row in children) {
  163 + int n = 0;
  164 + for (Widget child in row.children) {
  165 + child.layout(context, const BoxConstraints());
  166 + final double calculatedWidth =
140 child.box.width == double.infinity ? 0.0 : child.box.width; 167 child.box.width == double.infinity ? 0.0 : child.box.width;
141 - final childFlex = child._flex.toDouble(); 168 + final double childFlex =
  169 + child is Expanded ? child.flex.toDouble() : 0.0;
142 if (flex.length < n + 1) { 170 if (flex.length < n + 1) {
143 flex.add(childFlex); 171 flex.add(childFlex);
144 _widths.add(calculatedWidth); 172 _widths.add(calculatedWidth);
@@ -152,15 +180,15 @@ class Table extends Widget implements SpanningWidget { @@ -152,15 +180,15 @@ class Table extends Widget implements SpanningWidget {
152 } 180 }
153 } 181 }
154 182
155 - final maxWidth = _widths.reduce((a, b) => a + b); 183 + final double maxWidth = _widths.reduce((double a, double b) => a + b);
156 184
157 // Compute column widths using flex and estimated width 185 // Compute column widths using flex and estimated width
158 if (constraints.hasBoundedWidth) { 186 if (constraints.hasBoundedWidth) {
159 - final totalFlex = flex.reduce((a, b) => a + b);  
160 - var flexSpace = 0.0;  
161 - for (var n = 0; n < _widths.length; n++) { 187 + final double totalFlex = flex.reduce((double a, double b) => a + b);
  188 + double flexSpace = 0.0;
  189 + for (int n = 0; n < _widths.length; n++) {
162 if (flex[n] == 0.0) { 190 if (flex[n] == 0.0) {
163 - var newWidth = _widths[n] / maxWidth * constraints.maxWidth; 191 + final double newWidth = _widths[n] / maxWidth * constraints.maxWidth;
164 if ((tableWidth == TableWidth.max && totalFlex == 0.0) || 192 if ((tableWidth == TableWidth.max && totalFlex == 0.0) ||
165 newWidth < _widths[n]) { 193 newWidth < _widths[n]) {
166 _widths[n] = newWidth; 194 _widths[n] = newWidth;
@@ -168,32 +196,35 @@ class Table extends Widget implements SpanningWidget { @@ -168,32 +196,35 @@ class Table extends Widget implements SpanningWidget {
168 flexSpace += _widths[n]; 196 flexSpace += _widths[n];
169 } 197 }
170 } 198 }
171 - final spacePerFlex = totalFlex > 0.0 199 + final double spacePerFlex = totalFlex > 0.0
172 ? ((constraints.maxWidth - flexSpace) / totalFlex) 200 ? ((constraints.maxWidth - flexSpace) / totalFlex)
173 : double.nan; 201 : double.nan;
174 202
175 - for (var n = 0; n < _widths.length; n++) { 203 + for (int n = 0; n < _widths.length; n++) {
176 if (flex[n] > 0.0) { 204 if (flex[n] > 0.0) {
177 - var newWidth = spacePerFlex * flex[n]; 205 + final double newWidth = spacePerFlex * flex[n];
178 _widths[n] = newWidth; 206 _widths[n] = newWidth;
179 } 207 }
180 } 208 }
181 } 209 }
182 210
183 - final totalWidth = _widths.reduce((a, b) => a + b); 211 + final double totalWidth = _widths.reduce((double a, double b) => a + b);
184 212
185 // Compute final widths 213 // Compute final widths
186 - var totalHeight = 0.0; 214 + double totalHeight = 0.0;
187 index = 0; 215 index = 0;
188 - for (var row in children) {  
189 - if (index++ < _context.firstLine && !row.repeat) continue; 216 + for (TableRow row in children) {
  217 + if (index++ < _context.firstLine && !row.repeat) {
  218 + continue;
  219 + }
190 220
191 - var n = 0;  
192 - var x = 0.0; 221 + int n = 0;
  222 + double x = 0.0;
193 223
194 - var lineHeight = 0.0;  
195 - for (var child in row.children) {  
196 - final childConstraints = BoxConstraints.tightFor(width: _widths[n]); 224 + double lineHeight = 0.0;
  225 + for (Widget child in row.children) {
  226 + final BoxConstraints childConstraints =
  227 + BoxConstraints.tightFor(width: _widths[n]);
197 child.layout(context, childConstraints); 228 child.layout(context, childConstraints);
198 child.box = PdfRect(x, totalHeight, child.box.width, child.box.height); 229 child.box = PdfRect(x, totalHeight, child.box.width, child.box.height);
199 x += _widths[n]; 230 x += _widths[n];
@@ -212,10 +243,12 @@ class Table extends Widget implements SpanningWidget { @@ -212,10 +243,12 @@ class Table extends Widget implements SpanningWidget {
212 243
213 // Compute final y position 244 // Compute final y position
214 index = 0; 245 index = 0;
215 - for (var row in children) {  
216 - if (index++ < _context.firstLine && !row.repeat) continue; 246 + for (TableRow row in children) {
  247 + if (index++ < _context.firstLine && !row.repeat) {
  248 + continue;
  249 + }
217 250
218 - for (var child in row.children) { 251 + for (Widget child in row.children) {
219 child.box = PdfRect( 252 child.box = PdfRect(
220 child.box.x, 253 child.box.x,
221 totalHeight - child.box.y - child.box.height, 254 totalHeight - child.box.y - child.box.height,
@@ -223,7 +256,9 @@ class Table extends Widget implements SpanningWidget { @@ -223,7 +256,9 @@ class Table extends Widget implements SpanningWidget {
223 child.box.height); 256 child.box.height);
224 } 257 }
225 258
226 - if (index >= _context.lastLine) break; 259 + if (index >= _context.lastLine) {
  260 + break;
  261 + }
227 } 262 }
228 263
229 box = PdfRect(0.0, 0.0, totalWidth, totalHeight); 264 box = PdfRect(0.0, 0.0, totalWidth, totalHeight);
@@ -233,19 +268,23 @@ class Table extends Widget implements SpanningWidget { @@ -233,19 +268,23 @@ class Table extends Widget implements SpanningWidget {
233 void paint(Context context) { 268 void paint(Context context) {
234 super.paint(context); 269 super.paint(context);
235 270
236 - final mat = Matrix4.identity(); 271 + final Matrix4 mat = Matrix4.identity();
237 mat.translate(box.x, box.y); 272 mat.translate(box.x, box.y);
238 context.canvas 273 context.canvas
239 ..saveContext() 274 ..saveContext()
240 ..setTransform(mat); 275 ..setTransform(mat);
241 276
242 - var index = 0;  
243 - for (var row in children) {  
244 - if (index++ < _context.firstLine && !row.repeat) continue;  
245 - for (var child in row.children) { 277 + int index = 0;
  278 + for (TableRow row in children) {
  279 + if (index++ < _context.firstLine && !row.repeat) {
  280 + continue;
  281 + }
  282 + for (Widget child in row.children) {
246 child.paint(context); 283 child.paint(context);
247 } 284 }
248 - if (index >= _context.lastLine) break; 285 + if (index >= _context.lastLine) {
  286 + break;
  287 + }
249 } 288 }
250 context.canvas.restoreContext(); 289 context.canvas.restoreContext();
251 290
@@ -253,29 +292,4 @@ class Table extends Widget implements SpanningWidget { @@ -253,29 +292,4 @@ class Table extends Widget implements SpanningWidget {
253 border.paintBorders(context, box, _widths, _heights); 292 border.paintBorders(context, box, _widths, _heights);
254 } 293 }
255 } 294 }
256 -  
257 - factory Table.fromTextArray(  
258 - {@required Context context, @required List<List<String>> data}) {  
259 - final rows = List<TableRow>();  
260 - for (var row in data) {  
261 - final tableRow = List<Widget>();  
262 - if (row == data.first) {  
263 - for (var cell in row) {  
264 - tableRow.add(Container(  
265 - alignment: Alignment.center,  
266 - margin: EdgeInsets.all(5),  
267 - child: Text(cell, style: Theme.of(context).tableHeader)));  
268 - }  
269 - } else {  
270 - for (var cell in row) {  
271 - tableRow.add(Container(  
272 - margin: EdgeInsets.all(5),  
273 - child: Text(cell, style: Theme.of(context).tableCell)));  
274 - }  
275 - }  
276 - rows.add(TableRow(children: tableRow, repeat: row == data.first));  
277 - }  
278 - return Table(  
279 - border: TableBorder(), tableWidth: TableWidth.max, children: rows);  
280 - }  
281 } 295 }