David PHAM-VAN

Improve API documentation

@@ -9,24 +9,24 @@ environment: @@ -9,24 +9,24 @@ environment:
9 dependencies: 9 dependencies:
10 flutter: 10 flutter:
11 sdk: flutter 11 sdk: flutter
12 - printing:  
13 - path_provider: 12 + intl:
14 open_file: 13 open_file:
  14 + path_provider:
  15 + printing:
15 url_launcher: 16 url_launcher:
16 - intl:  
17 17
18 dev_dependencies: 18 dev_dependencies:
19 - flutter_test:  
20 - sdk: flutter  
21 flutter_driver: 19 flutter_driver:
22 sdk: flutter 20 sdk: flutter
  21 + flutter_test:
  22 + sdk: flutter
23 test: 23 test:
24 24
25 dependency_overrides: 25 dependency_overrides:
26 - printing:  
27 - path: ../printing  
28 pdf: 26 pdf:
29 path: ../pdf 27 path: ../pdf
  28 + printing:
  29 + path: ../printing
30 30
31 flutter: 31 flutter:
32 uses-material-design: true 32 uses-material-design: true
@@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
8 - Update analysis options 8 - Update analysis options
9 - Fix the line cap and joint enums 9 - Fix the line cap and joint enums
10 - Fix PdfOutlineMode enum 10 - Fix PdfOutlineMode enum
  11 +- Improve API documentation
11 12
12 ## 1.12.0 13 ## 1.12.0
13 14
@@ -16,4 +16,5 @@ @@ -16,4 +16,5 @@
16 16
17 import 'package:pdf/pdf.dart'; 17 import 'package:pdf/pdf.dart';
18 18
  19 +/// Zip compression function
19 DeflateCallback defaultDeflate; 20 DeflateCallback defaultDeflate;
@@ -18,4 +18,5 @@ import 'package:archive/archive.dart'; @@ -18,4 +18,5 @@ import 'package:archive/archive.dart';
18 18
19 import 'package:pdf/pdf.dart'; 19 import 'package:pdf/pdf.dart';
20 20
  21 +/// Zip compression function
21 DeflateCallback defaultDeflate = ZLibEncoder().encode; 22 DeflateCallback defaultDeflate = ZLibEncoder().encode;
@@ -18,4 +18,5 @@ import 'dart:io'; @@ -18,4 +18,5 @@ import 'dart:io';
18 18
19 import 'package:pdf/pdf.dart'; 19 import 'package:pdf/pdf.dart';
20 20
  21 +/// Zip compression function
21 DeflateCallback defaultDeflate = zlib.encode; 22 DeflateCallback defaultDeflate = zlib.encode;
@@ -30,8 +30,6 @@ class PdfAnnot extends PdfObject { @@ -30,8 +30,6 @@ class PdfAnnot extends PdfObject {
30 final PdfPage pdfPage; 30 final PdfPage pdfPage;
31 31
32 /// Output the annotation 32 /// Output the annotation
33 - ///  
34 - /// @param os OutputStream to send the object to  
35 @override 33 @override
36 void _prepare() { 34 void _prepare() {
37 super._prepare(); 35 super._prepare();
@@ -20,6 +20,7 @@ @@ -20,6 +20,7 @@
20 20
21 part of pdf; 21 part of pdf;
22 22
  23 +/// Arabic shape substitutions functions
23 class PdfArabic { 24 class PdfArabic {
24 /// Arabic shape substitutions: char code => (isolated, final, initial, medial). 25 /// Arabic shape substitutions: char code => (isolated, final, initial, medial).
25 /// Arabic Substition A 26 /// Arabic Substition A
@@ -398,6 +399,7 @@ class PdfArabic { @@ -398,6 +399,7 @@ class PdfArabic {
398 } 399 }
399 } 400 }
400 401
  402 + /// Apply Arabic shape substitutions
401 static String convert(String input) { 403 static String convert(String input) {
402 return List<String>.from(_parse(input)).join(''); 404 return List<String>.from(_parse(input)).join('');
403 } 405 }
@@ -16,13 +16,16 @@ @@ -16,13 +16,16 @@
16 16
17 part of pdf; 17 part of pdf;
18 18
  19 +/// An array object
19 class PdfArrayObject extends PdfObject { 20 class PdfArrayObject extends PdfObject {
  21 + /// Creates an array object
20 PdfArrayObject( 22 PdfArrayObject(
21 PdfDocument pdfDocument, 23 PdfDocument pdfDocument,
22 this.array, 24 this.array,
23 ) : assert(array != null), 25 ) : assert(array != null),
24 super(pdfDocument); 26 super(pdfDocument);
25 27
  28 + /// The array
26 final PdfArray array; 29 final PdfArray array;
27 30
28 @override 31 @override
@@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
16 16
17 part of pdf; 17 part of pdf;
18 18
  19 +/// Ascii 85 encoder
19 class Ascii85Encoder extends Converter<Uint8List, Uint8List> { 20 class Ascii85Encoder extends Converter<Uint8List, Uint8List> {
20 @override 21 @override
21 Uint8List convert(Uint8List input) { 22 Uint8List convert(Uint8List input) {
@@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
16 16
17 part of pdf; 17 part of pdf;
18 18
  19 +/// Border style
19 enum PdfBorderStyle { 20 enum PdfBorderStyle {
20 /// Solid border. The border is drawn as a solid line. 21 /// Solid border. The border is drawn as a solid line.
21 solid, 22 solid,
@@ -35,15 +36,9 @@ enum PdfBorderStyle { @@ -35,15 +36,9 @@ enum PdfBorderStyle {
35 underlined 36 underlined
36 } 37 }
37 38
  39 +/// Defines a border object
38 class PdfBorder extends PdfObject { 40 class PdfBorder extends PdfObject {
39 /// Creates a border using the predefined styles in [PdfAnnot]. 41 /// Creates a border using the predefined styles in [PdfAnnot].
40 - /// Note: Do not use [PdfAnnot.dashed] with this method.  
41 - /// Use the other constructor.  
42 - ///  
43 - /// @param width The width of the border  
44 - /// @param style The style of the border  
45 - /// @param dash The line pattern definition  
46 - /// @see [PdfAnnot]  
47 PdfBorder( 42 PdfBorder(
48 PdfDocument pdfDocument, 43 PdfDocument pdfDocument,
49 this.width, { 44 this.width, {
@@ -62,7 +57,6 @@ class PdfBorder extends PdfObject { @@ -62,7 +57,6 @@ class PdfBorder extends PdfObject {
62 /// This array allows the definition of a dotted line for the border 57 /// This array allows the definition of a dotted line for the border
63 final List<double> dash; 58 final List<double> dash;
64 59
65 - /// @param os OutputStream to send the object to  
66 @override 60 @override
67 void _prepare() { 61 void _prepare() {
68 super._prepare(); 62 super._prepare();
@@ -16,12 +16,9 @@ @@ -16,12 +16,9 @@
16 16
17 part of pdf; 17 part of pdf;
18 18
  19 +/// Pdf Catalog object
19 class PdfCatalog extends PdfObject { 20 class PdfCatalog extends PdfObject {
20 /// This constructs a Pdf Catalog object 21 /// 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( 22 PdfCatalog(
26 PdfDocument pdfDocument, 23 PdfDocument pdfDocument,
27 this.pdfPageList, 24 this.pdfPageList,
@@ -44,7 +41,6 @@ class PdfCatalog extends PdfObject { @@ -44,7 +41,6 @@ class PdfCatalog extends PdfObject {
44 /// The initial page mode 41 /// The initial page mode
45 final PdfNames names; 42 final PdfNames names;
46 43
47 - /// @param os OutputStream to send the object to  
48 @override 44 @override
49 void _prepare() { 45 void _prepare() {
50 super._prepare(); 46 super._prepare();
@@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
16 16
17 part of pdf; 17 part of pdf;
18 18
  19 +/// Represents an RGB color
19 class PdfColor { 20 class PdfColor {
20 /// Create a color with red, green, blue and alpha components 21 /// Create a color with red, green, blue and alpha components
21 /// values between 0 and 1 22 /// values between 0 and 1
@@ -69,6 +70,7 @@ class PdfColor { @@ -69,6 +70,7 @@ class PdfColor {
69 return PdfColor(red, green, blue, alpha); 70 return PdfColor(red, green, blue, alpha);
70 } 71 }
71 72
  73 + /// Load an RGB color from a RYB color
72 factory PdfColor.fromRYB(double red, double yellow, double blue, 74 factory PdfColor.fromRYB(double red, double yellow, double blue,
73 [double alpha = 1.0]) { 75 [double alpha = 1.0]) {
74 assert(red >= 0 && red <= 1); 76 assert(red >= 0 && red <= 1);
@@ -128,11 +130,19 @@ class PdfColor { @@ -128,11 +130,19 @@ class PdfColor {
128 return PdfColor(redValue, greenValue, blueValue, alpha); 130 return PdfColor(redValue, greenValue, blueValue, alpha);
129 } 131 }
130 132
  133 + /// Opacity
131 final double alpha; 134 final double alpha;
  135 +
  136 + /// Red component
132 final double red; 137 final double red;
  138 +
  139 + /// Green component
133 final double green; 140 final double green;
  141 +
  142 + /// Blue component
134 final double blue; 143 final double blue;
135 144
  145 + /// Get the int32 representation of this color
136 int toInt() => 146 int toInt() =>
137 ((((alpha * 255.0).round() & 0xff) << 24) | 147 ((((alpha * 255.0).round() & 0xff) << 24) |
138 (((red * 255.0).round() & 0xff) << 16) | 148 (((red * 255.0).round() & 0xff) << 16) |
@@ -140,6 +150,7 @@ class PdfColor { @@ -140,6 +150,7 @@ class PdfColor {
140 (((blue * 255.0).round() & 0xff) << 0)) & 150 (((blue * 255.0).round() & 0xff) << 0)) &
141 0xFFFFFFFF; 151 0xFFFFFFFF;
142 152
  153 + /// Get an Hexadecimal representation of this color
143 String toHex() { 154 String toHex() {
144 final i = toInt(); 155 final i = toInt();
145 final rgb = (i & 0xffffff).toRadixString(16); 156 final rgb = (i & 0xffffff).toRadixString(16);
@@ -147,14 +158,17 @@ class PdfColor { @@ -147,14 +158,17 @@ class PdfColor {
147 return '#$rgb$a'; 158 return '#$rgb$a';
148 } 159 }
149 160
  161 + /// Convert this color to CMYK
150 PdfColorCmyk toCmyk() { 162 PdfColorCmyk toCmyk() {
151 return PdfColorCmyk.fromRgb(red, green, blue, alpha); 163 return PdfColorCmyk.fromRgb(red, green, blue, alpha);
152 } 164 }
153 165
  166 + /// Convert this color to HSV
154 PdfColorHsv toHsv() { 167 PdfColorHsv toHsv() {
155 return PdfColorHsv.fromRgb(red, green, blue, alpha); 168 return PdfColorHsv.fromRgb(red, green, blue, alpha);
156 } 169 }
157 170
  171 + /// Convert this color to HSL
158 PdfColorHsl toHsl() { 172 PdfColorHsl toHsl() {
159 return PdfColorHsl.fromRgb(red, green, blue, alpha); 173 return PdfColorHsl.fromRgb(red, green, blue, alpha);
160 } 174 }
@@ -166,6 +180,7 @@ class PdfColor { @@ -166,6 +180,7 @@ class PdfColor {
166 return math.pow((component + 0.055) / 1.055, 2.4); 180 return math.pow((component + 0.055) / 1.055, 2.4);
167 } 181 }
168 182
  183 + /// Get the luminance
169 double get luminance { 184 double get luminance {
170 final R = _linearizeColorComponent(red); 185 final R = _linearizeColorComponent(red);
171 final G = _linearizeColorComponent(green); 186 final G = _linearizeColorComponent(green);
@@ -191,24 +206,31 @@ class PdfColor { @@ -191,24 +206,31 @@ class PdfColor {
191 /// Get some similar colors 206 /// Get some similar colors
192 List<PdfColor> get monochromatic => toHsv().monochromatic; 207 List<PdfColor> get monochromatic => toHsv().monochromatic;
193 208
  209 + /// Returns a list of complementary colors
194 List<PdfColor> get splitcomplementary => toHsv().splitcomplementary; 210 List<PdfColor> get splitcomplementary => toHsv().splitcomplementary;
195 211
  212 + /// Returns a list of tetradic colors
196 List<PdfColor> get tetradic => toHsv().tetradic; 213 List<PdfColor> get tetradic => toHsv().tetradic;
197 214
  215 + /// Returns a list of triadic colors
198 List<PdfColor> get triadic => toHsv().triadic; 216 List<PdfColor> get triadic => toHsv().triadic;
199 217
  218 + /// Returns a list of analagous colors
200 List<PdfColor> get analagous => toHsv().analagous; 219 List<PdfColor> get analagous => toHsv().analagous;
201 220
202 @override 221 @override
203 String toString() => '$runtimeType($red, $green, $blue, $alpha)'; 222 String toString() => '$runtimeType($red, $green, $blue, $alpha)';
204 } 223 }
205 224
  225 +/// Represents an CMYK color
206 class PdfColorCmyk extends PdfColor { 226 class PdfColorCmyk extends PdfColor {
  227 + /// Creates a CMYK color
207 const PdfColorCmyk(this.cyan, this.magenta, this.yellow, this.black, 228 const PdfColorCmyk(this.cyan, this.magenta, this.yellow, this.black,
208 [double a = 1.0]) 229 [double a = 1.0])
209 : super((1.0 - cyan) * (1.0 - black), (1.0 - magenta) * (1.0 - black), 230 : super((1.0 - cyan) * (1.0 - black), (1.0 - magenta) * (1.0 - black),
210 (1.0 - yellow) * (1.0 - black), a); 231 (1.0 - yellow) * (1.0 - black), a);
211 232
  233 + /// Create a CMYK color from red ,green and blue components
212 const PdfColorCmyk.fromRgb(double r, double g, double b, [double a = 1.0]) 234 const PdfColorCmyk.fromRgb(double r, double g, double b, [double a = 1.0])
213 : black = 1.0 - r > g 235 : black = 1.0 - r > g
214 ? r 236 ? r
@@ -270,9 +292,16 @@ class PdfColorCmyk extends PdfColor { @@ -270,9 +292,16 @@ class PdfColorCmyk extends PdfColor {
270 : b)), 292 : b)),
271 super(r, g, b, a); 293 super(r, g, b, a);
272 294
  295 + /// Cyan component
273 final double cyan; 296 final double cyan;
  297 +
  298 + /// Magenta component
274 final double magenta; 299 final double magenta;
  300 +
  301 + /// Yellow component
275 final double yellow; 302 final double yellow;
  303 +
  304 + /// Black component
276 final double black; 305 final double black;
277 306
278 @override 307 @override
@@ -306,6 +335,7 @@ double _getHue( @@ -306,6 +335,7 @@ double _getHue(
306 /// starting at the red primary at 0°, passing through the green primary 335 /// starting at the red primary at 0°, passing through the green primary
307 /// at 120° and the blue primary at 240°, and then wrapping back to red at 360° 336 /// at 120° and the blue primary at 240°, and then wrapping back to red at 360°
308 class PdfColorHsv extends PdfColor { 337 class PdfColorHsv extends PdfColor {
  338 + /// Creates an HSV color
309 factory PdfColorHsv(double hue, double saturation, double value, 339 factory PdfColorHsv(double hue, double saturation, double value,
310 [double alpha = 1.0]) { 340 [double alpha = 1.0]) {
311 final chroma = saturation * value; 341 final chroma = saturation * value;
@@ -352,6 +382,7 @@ class PdfColorHsv extends PdfColor { @@ -352,6 +382,7 @@ class PdfColorHsv extends PdfColor {
352 assert(value >= 0 && value <= 1), 382 assert(value >= 0 && value <= 1),
353 super(red, green, blue, alpha); 383 super(red, green, blue, alpha);
354 384
  385 + /// Creates an HSV color from red, green, blue components
355 factory PdfColorHsv.fromRgb(double red, double green, double blue, 386 factory PdfColorHsv.fromRgb(double red, double green, double blue,
356 [double alpha = 1.0]) { 387 [double alpha = 1.0]) {
357 final max = math.max(red, math.max(green, blue)); 388 final max = math.max(red, math.max(green, blue));
@@ -433,7 +464,9 @@ class PdfColorHsv extends PdfColor { @@ -433,7 +464,9 @@ class PdfColorHsv extends PdfColor {
433 String toString() => '$runtimeType($hue, $saturation, $value, $alpha)'; 464 String toString() => '$runtimeType($hue, $saturation, $value, $alpha)';
434 } 465 }
435 466
  467 +/// Represents an HSL color
436 class PdfColorHsl extends PdfColor { 468 class PdfColorHsl extends PdfColor {
  469 + /// Creates an HSL color
437 factory PdfColorHsl(double hue, double saturation, double lightness, 470 factory PdfColorHsl(double hue, double saturation, double lightness,
438 [double alpha = 1.0]) { 471 [double alpha = 1.0]) {
439 final chroma = (1.0 - (2.0 * lightness - 1.0).abs()) * saturation; 472 final chroma = (1.0 - (2.0 * lightness - 1.0).abs()) * saturation;
@@ -485,6 +518,7 @@ class PdfColorHsl extends PdfColor { @@ -485,6 +518,7 @@ class PdfColorHsl extends PdfColor {
485 assert(lightness >= 0 && lightness <= 1), 518 assert(lightness >= 0 && lightness <= 1),
486 super(red, green, blue, alpha); 519 super(red, green, blue, alpha);
487 520
  521 + /// Creates an HSL color from red, green, and blue components
488 factory PdfColorHsl.fromRgb(double red, double green, double blue, 522 factory PdfColorHsl.fromRgb(double red, double green, double blue,
489 [double alpha = 1.0]) { 523 [double alpha = 1.0]) {
490 final max = math.max(red, math.max(green, blue)); 524 final max = math.max(red, math.max(green, blue));
@@ -500,8 +534,13 @@ class PdfColorHsl extends PdfColor { @@ -500,8 +534,13 @@ class PdfColorHsl extends PdfColor {
500 return PdfColorHsl._(hue, saturation, lightness, alpha, red, green, blue); 534 return PdfColorHsl._(hue, saturation, lightness, alpha, red, green, blue);
501 } 535 }
502 536
  537 + /// Hue component
503 final double hue; 538 final double hue;
  539 +
  540 + /// Saturation component
504 final double saturation; 541 final double saturation;
  542 +
  543 + /// Lightness component
505 final double lightness; 544 final double lightness;
506 545
507 @override 546 @override
@@ -14,8 +14,11 @@ @@ -14,8 +14,11 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
  17 +// ignore_for_file: public_member_api_docs
  18 +
17 part of pdf; 19 part of pdf;
18 20
  21 +/// Material design colors
19 class PdfColors { 22 class PdfColors {
20 PdfColors._(); 23 PdfColors._();
21 24
@@ -393,6 +396,7 @@ class PdfColors { @@ -393,6 +396,7 @@ class PdfColors {
393 deepOrangeAccent, 396 deepOrangeAccent,
394 ]; 397 ];
395 398
  399 + /// Get a pseudo-random color
396 static PdfColor getColor(int index) { 400 static PdfColor getColor(int index) {
397 final hue = index * 137.508; 401 final hue = index * 137.508;
398 final PdfColor color = PdfColorHsv(hue % 360, 1, 1); 402 final PdfColor color = PdfColorHsv(hue % 360, 1, 1);
@@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
16 16
17 part of pdf; 17 part of pdf;
18 18
  19 +/// Display hint for the PDF viewer
19 enum PdfPageMode { 20 enum PdfPageMode {
20 /// This page mode indicates that the document 21 /// This page mode indicates that the document
21 /// should be opened just with the page visible. This is the default 22 /// should be opened just with the page visible. This is the default
@@ -35,6 +36,7 @@ enum PdfPageMode { @@ -35,6 +36,7 @@ enum PdfPageMode {
35 fullscreen 36 fullscreen
36 } 37 }
37 38
  39 +/// Callback used to compress the data
38 typedef DeflateCallback = List<int> Function(List<int> data); 40 typedef DeflateCallback = List<int> Function(List<int> data);
39 41
40 /// This class is the base of the Pdf generator. A [PdfDocument] class is 42 /// This class is the base of the Pdf generator. A [PdfDocument] class is
@@ -44,8 +46,6 @@ typedef DeflateCallback = List<int> Function(List<int> data); @@ -44,8 +46,6 @@ typedef DeflateCallback = List<int> Function(List<int> data);
44 /// document's internal structures are kept in sync. 46 /// document's internal structures are kept in sync.
45 class PdfDocument { 47 class PdfDocument {
46 /// This creates a Pdf document 48 /// 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({ 49 PdfDocument({
50 PdfPageMode pageMode = PdfPageMode.none, 50 PdfPageMode pageMode = PdfPageMode.none,
51 DeflateCallback deflate, 51 DeflateCallback deflate,
@@ -113,8 +113,9 @@ class PdfDocument { @@ -113,8 +113,9 @@ class PdfDocument {
113 /// This holds the current fonts 113 /// This holds the current fonts
114 final Set<PdfFont> fonts = <PdfFont>{}; 114 final Set<PdfFont> fonts = <PdfFont>{};
115 115
116 - /// Generates the document ID  
117 Uint8List _documentID; 116 Uint8List _documentID;
  117 +
  118 + /// Generates the document ID
118 Uint8List get documentID { 119 Uint8List get documentID {
119 if (_documentID == null) { 120 if (_documentID == null) {
120 final rnd = math.Random(); 121 final rnd = math.Random();
@@ -132,16 +133,11 @@ class PdfDocument { @@ -132,16 +133,11 @@ class PdfDocument {
132 133
133 /// This returns a specific page. It's used mainly when using a 134 /// This returns a specific page. It's used mainly when using a
134 /// Serialized template file. 135 /// Serialized template file.
135 - ///  
136 - /// ?? How does a serialized template file work ???  
137 - ///  
138 - /// @param page page number to return  
139 - /// @return [PdfPage] at that position  
140 PdfPage page(int page) { 136 PdfPage page(int page) {
141 return pdfPageList.getPage(page); 137 return pdfPageList.getPage(page);
142 } 138 }
143 139
144 - /// @return the root outline 140 + /// The root outline
145 PdfOutline get outline { 141 PdfOutline get outline {
146 if (_outline == null) { 142 if (_outline == null) {
147 _outline = PdfOutline(this); 143 _outline = PdfOutline(this);
@@ -156,19 +152,10 @@ class PdfDocument { @@ -156,19 +152,10 @@ class PdfDocument {
156 return _graphicStates; 152 return _graphicStates;
157 } 153 }
158 154
  155 + /// This document has at least one graphic state
159 bool get hasGraphicStates => _graphicStates != null; 156 bool get hasGraphicStates => _graphicStates != null;
160 157
161 /// This writes the document to an OutputStream. 158 /// This writes the document to an OutputStream.
162 - ///  
163 - /// Note: You can call this as many times as you wish, as long as  
164 - /// the calls are not running at the same time.  
165 - ///  
166 - /// Also, objects can be added or amended between these calls.  
167 - ///  
168 - /// Also, the OutputStream is not closed, but will be flushed on  
169 - /// completion. It is up to the caller to close the stream.  
170 - ///  
171 - /// @param os OutputStream to write the document to  
172 void _write(PdfStream os) { 159 void _write(PdfStream os) {
173 final pos = PdfOutput(os); 160 final pos = PdfOutput(os);
174 161
@@ -180,6 +167,7 @@ class PdfDocument { @@ -180,6 +167,7 @@ class PdfDocument {
180 pos.close(); 167 pos.close();
181 } 168 }
182 169
  170 + /// Generate the PDF document as a memory file
183 Uint8List save() { 171 Uint8List save() {
184 final os = PdfStream(); 172 final os = PdfStream();
185 _write(os); 173 _write(os);
@@ -16,8 +16,11 @@ @@ -16,8 +16,11 @@
16 16
17 part of pdf; 17 part of pdf;
18 18
  19 +/// Encryption object
19 abstract class PdfEncryption extends PdfObject { 20 abstract class PdfEncryption extends PdfObject {
  21 + /// Creates an encryption object
20 PdfEncryption(PdfDocument pdfDocument) : super(pdfDocument, null); 22 PdfEncryption(PdfDocument pdfDocument) : super(pdfDocument, null);
21 23
  24 + /// Encrypt some data
22 Uint8List encrypt(Uint8List input, PdfObject object); 25 Uint8List encrypt(Uint8List input, PdfObject object);
23 } 26 }
@@ -16,7 +16,9 @@ @@ -16,7 +16,9 @@
16 16
17 part of pdf; 17 part of pdf;
18 18
  19 +/// Jpeg metadata extraction
19 class PdfJpegInfo { 20 class PdfJpegInfo {
  21 + /// Load a Jpeg image's metadata
20 factory PdfJpegInfo(Uint8List image) { 22 factory PdfJpegInfo(Uint8List image) {
21 assert(image != null); 23 assert(image != null);
22 24
@@ -73,14 +75,18 @@ class PdfJpegInfo { @@ -73,14 +75,18 @@ class PdfJpegInfo {
73 75
74 PdfJpegInfo._(this.width, this.height, this._color, this.tags); 76 PdfJpegInfo._(this.width, this.height, this._color, this.tags);
75 77
  78 + /// Width of the image
76 final int width; 79 final int width;
77 80
  81 + /// Height of the image
78 final int height; 82 final int height;
79 83
80 final int _color; 84 final int _color;
81 85
  86 + /// Is the image color or greyscale
82 bool get isRGB => _color == 3; 87 bool get isRGB => _color == 3;
83 88
  89 + /// Exif tags discovered
84 final Map<PdfExifTag, dynamic> tags; 90 final Map<PdfExifTag, dynamic> tags;
85 91
86 /// EXIF version 92 /// EXIF version
@@ -94,6 +100,7 @@ class PdfJpegInfo { @@ -94,6 +100,7 @@ class PdfJpegInfo {
94 ? null 100 ? null
95 : utf8.decode(tags[PdfExifTag.FlashpixVersion]); 101 : utf8.decode(tags[PdfExifTag.FlashpixVersion]);
96 102
  103 + /// Rotation angle of this image
97 PdfImageOrientation get orientation { 104 PdfImageOrientation get orientation {
98 if (tags == null || tags[PdfExifTag.Orientation] == null) { 105 if (tags == null || tags[PdfExifTag.Orientation] == null) {
99 return PdfImageOrientation.topLeft; 106 return PdfImageOrientation.topLeft;
@@ -106,21 +113,25 @@ class PdfJpegInfo { @@ -106,21 +113,25 @@ class PdfJpegInfo {
106 } 113 }
107 } 114 }
108 115
  116 + /// Exif horizontal resolution
109 double get xResolution => tags == null || tags[PdfExifTag.XResolution] == null 117 double get xResolution => tags == null || tags[PdfExifTag.XResolution] == null
110 ? null 118 ? null
111 : tags[PdfExifTag.XResolution][0].toDouble() / 119 : tags[PdfExifTag.XResolution][0].toDouble() /
112 tags[PdfExifTag.XResolution][1].toDouble(); 120 tags[PdfExifTag.XResolution][1].toDouble();
113 121
  122 + /// Exif vertical resolution
114 double get yResolution => tags == null || tags[PdfExifTag.YResolution] == null 123 double get yResolution => tags == null || tags[PdfExifTag.YResolution] == null
115 ? null 124 ? null
116 : tags[PdfExifTag.YResolution][0].toDouble() / 125 : tags[PdfExifTag.YResolution][0].toDouble() /
117 tags[PdfExifTag.YResolution][1].toDouble(); 126 tags[PdfExifTag.YResolution][1].toDouble();
118 127
  128 + /// Exif horizontal pixel dimension
119 int get pixelXDimension => 129 int get pixelXDimension =>
120 tags == null || tags[PdfExifTag.PixelXDimension] == null 130 tags == null || tags[PdfExifTag.PixelXDimension] == null
121 ? width 131 ? width
122 : tags[PdfExifTag.PixelXDimension]; 132 : tags[PdfExifTag.PixelXDimension];
123 133
  134 + /// Exif vertical pixel dimension
124 int get pixelYDimension => 135 int get pixelYDimension =>
125 tags == null || tags[PdfExifTag.PixelYDimension] == null 136 tags == null || tags[PdfExifTag.PixelYDimension] == null
126 ? height 137 ? height
@@ -440,111 +451,280 @@ orientation: $orientation'''; @@ -440,111 +451,280 @@ orientation: $orientation''';
440 }; 451 };
441 } 452 }
442 453
  454 +/// Possible Exif tags
443 enum PdfExifTag { 455 enum PdfExifTag {
444 // version tags 456 // version tags
445 - ExifVersion, // EXIF version  
446 - FlashpixVersion, // Flashpix format version 457 + /// EXIF version
  458 + ExifVersion,
  459 +
  460 + /// Flashpix format version
  461 + FlashpixVersion,
447 462
448 // colorspace tags 463 // colorspace tags
449 - ColorSpace, // Color space information tag 464 + /// Color space information tag
  465 + ColorSpace,
450 466
451 // image configuration 467 // image configuration
452 - PixelXDimension, // Valid width of meaningful image  
453 - PixelYDimension, // Valid height of meaningful image  
454 - ComponentsConfiguration, // Information about channels  
455 - CompressedBitsPerPixel, // Compressed bits per pixel 468 + /// Valid width of meaningful image
  469 + PixelXDimension,
  470 +
  471 + /// Valid height of meaningful image
  472 + PixelYDimension,
  473 +
  474 + /// Information about channels
  475 + ComponentsConfiguration,
  476 +
  477 + /// Compressed bits per pixel
  478 + CompressedBitsPerPixel,
456 479
457 // user information 480 // user information
458 - MakerNote, // Any desired information written by the manufacturer  
459 - UserComment, // Comments by user 481 + /// Any desired information written by the manufacturer
  482 + MakerNote,
  483 +
  484 + /// Comments by user
  485 + UserComment,
460 486
461 // related file 487 // related file
462 - RelatedSoundFile, // Name of related sound file 488 + /// Name of related sound file
  489 + RelatedSoundFile,
463 490
464 // date and time 491 // date and time
465 - DateTimeOriginal, // Date and time when the original image was generated  
466 - DateTimeDigitized, // Date and time when the image was stored digitally  
467 - SubsecTime, // Fractions of seconds for DateTime  
468 - SubsecTimeOriginal, // Fractions of seconds for DateTimeOriginal  
469 - SubsecTimeDigitized, // Fractions of seconds for DateTimeDigitized 492 + /// Date and time when the original image was generated
  493 + DateTimeOriginal,
  494 +
  495 + /// Date and time when the image was stored digitally
  496 + DateTimeDigitized,
  497 +
  498 + /// Fractions of seconds for DateTime
  499 + SubsecTime,
  500 +
  501 + /// Fractions of seconds for DateTimeOriginal
  502 + SubsecTimeOriginal,
  503 +
  504 + /// Fractions of seconds for DateTimeDigitized
  505 + SubsecTimeDigitized,
470 506
471 // picture-taking conditions 507 // picture-taking conditions
472 - ExposureTime, // Exposure time (in seconds)  
473 - FNumber, // F number  
474 - ExposureProgram, // Exposure program  
475 - SpectralSensitivity, // Spectral sensitivity  
476 - ISOSpeedRatings, // ISO speed rating  
477 - OECF, // Optoelectric conversion factor  
478 - ShutterSpeedValue, // Shutter speed  
479 - ApertureValue, // Lens aperture  
480 - BrightnessValue, // Value of brightness  
481 - ExposureBias, // Exposure bias  
482 - MaxApertureValue, // Smallest F number of lens  
483 - SubjectDistance, // Distance to subject in meters  
484 - MeteringMode, // Metering mode  
485 - LightSource, // Kind of light source  
486 - Flash, // Flash status  
487 - SubjectArea, // Location and area of main subject  
488 - FocalLength, // Focal length of the lens in mm  
489 - FlashEnergy, // Strobe energy in BCPS  
490 - SpatialFrequencyResponse, //  
491 - FocalPlaneXResolution, // Number of pixels in width direction per FocalPlaneResolutionUnit  
492 - FocalPlaneYResolution, // Number of pixels in height direction per FocalPlaneResolutionUnit  
493 - FocalPlaneResolutionUnit, // Unit for measuring FocalPlaneXResolution and FocalPlaneYResolution  
494 - SubjectLocation, // Location of subject in image  
495 - ExposureIndex, // Exposure index selected on camera  
496 - SensingMethod, // Image sensor type  
497 - FileSource, // Image source (3 == DSC)  
498 - SceneType, // Scene type (1 == directly photographed)  
499 - CFAPattern, // Color filter array geometric pattern  
500 - CustomRendered, // Special processing  
501 - ExposureMode, // Exposure mode  
502 - WhiteBalance, // 1 = auto white balance, 2 = manual  
503 - DigitalZoomRation, // Digital zoom ratio  
504 - FocalLengthIn35mmFilm, // Equivalent foacl length assuming 35mm film camera (in mm)  
505 - SceneCaptureType, // Type of scene  
506 - GainControl, // Degree of overall image gain adjustment  
507 - Contrast, // Direction of contrast processing applied by camera  
508 - Saturation, // Direction of saturation processing applied by camera  
509 - Sharpness, // Direction of sharpness processing applied by camera  
510 - DeviceSettingDescription, //  
511 - SubjectDistanceRange, // Distance to subject 508 + /// Exposure time (in seconds)
  509 + ExposureTime,
  510 +
  511 + /// F number
  512 + FNumber,
  513 +
  514 + /// Exposure program
  515 + ExposureProgram,
  516 +
  517 + /// Spectral sensitivity
  518 + SpectralSensitivity,
  519 +
  520 + /// ISO speed rating
  521 + ISOSpeedRatings,
  522 +
  523 + /// Optoelectric conversion factor
  524 + OECF,
  525 +
  526 + /// Shutter speed
  527 + ShutterSpeedValue,
  528 +
  529 + /// Lens aperture
  530 + ApertureValue,
  531 +
  532 + /// Value of brightness
  533 + BrightnessValue,
  534 +
  535 + /// Exposure bias
  536 + ExposureBias,
  537 +
  538 + /// Smallest F number of lens
  539 + MaxApertureValue,
  540 +
  541 + /// Distance to subject in meters
  542 + SubjectDistance,
  543 +
  544 + /// Metering mode
  545 + MeteringMode,
  546 +
  547 + /// Kind of light source
  548 + LightSource,
  549 +
  550 + /// Flash status
  551 + Flash,
  552 +
  553 + /// Location and area of main subject
  554 + SubjectArea,
  555 +
  556 + /// Focal length of the lens in mm
  557 + FocalLength,
  558 +
  559 + /// Strobe energy in BCPS
  560 + FlashEnergy,
  561 +
  562 + /// Spatial Frequency Response
  563 + SpatialFrequencyResponse,
  564 +
  565 + /// Number of pixels in width direction per FocalPlaneResolutionUnit
  566 + FocalPlaneXResolution,
  567 +
  568 + /// Number of pixels in height direction per FocalPlaneResolutionUnit
  569 + FocalPlaneYResolution,
  570 +
  571 + /// Unit for measuring FocalPlaneXResolution and FocalPlaneYResolution
  572 + FocalPlaneResolutionUnit,
  573 +
  574 + /// Location of subject in image
  575 + SubjectLocation,
  576 +
  577 + /// Exposure index selected on camera
  578 + ExposureIndex,
  579 +
  580 + /// Image sensor type
  581 + SensingMethod,
  582 +
  583 + /// Image source (3 == DSC)
  584 + FileSource,
  585 +
  586 + /// Scene type (1 == directly photographed)
  587 + SceneType,
  588 +
  589 + /// Color filter array geometric pattern
  590 + CFAPattern,
  591 +
  592 + /// Special processing
  593 + CustomRendered,
  594 +
  595 + /// Exposure mode
  596 + ExposureMode,
  597 +
  598 + /// 1 = auto white balance, 2 = manual
  599 + WhiteBalance,
  600 +
  601 + /// Digital zoom ratio
  602 + DigitalZoomRation,
  603 +
  604 + /// Equivalent foacl length assuming 35mm film camera (in mm)
  605 + FocalLengthIn35mmFilm,
  606 +
  607 + /// Type of scene
  608 + SceneCaptureType,
  609 +
  610 + /// Degree of overall image gain adjustment
  611 + GainControl,
  612 +
  613 + /// Direction of contrast processing applied by camera
  614 + Contrast,
  615 +
  616 + /// Direction of saturation processing applied by camera
  617 + Saturation,
  618 +
  619 + /// Direction of sharpness processing applied by camera
  620 + Sharpness,
  621 +
  622 + /// Device Setting Description
  623 + DeviceSettingDescription,
  624 +
  625 + /// Distance to subject
  626 + SubjectDistanceRange,
512 627
513 // other tags 628 // other tags
  629 + /// Interoperability IFD Pointer
514 InteroperabilityIFDPointer, 630 InteroperabilityIFDPointer,
515 - ImageUniqueID, // Identifier assigned uniquely to each image 631 + //// Identifier assigned uniquely to each image
  632 + ImageUniqueID,
516 633
517 // tiff Tags 634 // tiff Tags
  635 + /// ImageWidth
518 ImageWidth, 636 ImageWidth,
  637 +
  638 + /// ImageHeight
519 ImageHeight, 639 ImageHeight,
  640 +
  641 + /// ExifIFDPointer
520 ExifIFDPointer, 642 ExifIFDPointer,
  643 +
  644 + /// GPSInfoIFDPointer
521 GPSInfoIFDPointer, 645 GPSInfoIFDPointer,
  646 +
  647 + /// BitsPerSample
522 BitsPerSample, 648 BitsPerSample,
  649 +
  650 + /// Compression
523 Compression, 651 Compression,
  652 +
  653 + /// PhotometricInterpretation
524 PhotometricInterpretation, 654 PhotometricInterpretation,
  655 +
  656 + /// Orientation
525 Orientation, 657 Orientation,
  658 +
  659 + /// SamplesPerPixel
526 SamplesPerPixel, 660 SamplesPerPixel,
  661 +
  662 + /// PlanarConfiguration
527 PlanarConfiguration, 663 PlanarConfiguration,
  664 +
  665 + /// YCbCrSubSampling
528 YCbCrSubSampling, 666 YCbCrSubSampling,
  667 +
  668 + /// YCbCrPositioning
529 YCbCrPositioning, 669 YCbCrPositioning,
  670 +
  671 + /// XResolution
530 XResolution, 672 XResolution,
  673 +
  674 + /// YResolution
531 YResolution, 675 YResolution,
  676 +
  677 + /// ResolutionUnit
532 ResolutionUnit, 678 ResolutionUnit,
  679 +
  680 + /// StripOffsets
533 StripOffsets, 681 StripOffsets,
  682 +
  683 + /// RowsPerStrip
534 RowsPerStrip, 684 RowsPerStrip,
  685 +
  686 + /// StripByteCounts
535 StripByteCounts, 687 StripByteCounts,
  688 +
  689 + /// JPEGInterchangeFormat
536 JPEGInterchangeFormat, 690 JPEGInterchangeFormat,
  691 +
  692 + /// JPEGInterchangeFormatLength
537 JPEGInterchangeFormatLength, 693 JPEGInterchangeFormatLength,
  694 +
  695 + /// TransferFunction
538 TransferFunction, 696 TransferFunction,
  697 +
  698 + /// WhitePoint
539 WhitePoint, 699 WhitePoint,
  700 +
  701 + /// PrimaryChromaticities
540 PrimaryChromaticities, 702 PrimaryChromaticities,
  703 +
  704 + /// YCbCrCoefficients
541 YCbCrCoefficients, 705 YCbCrCoefficients,
  706 +
  707 + /// ReferenceBlackWhite
542 ReferenceBlackWhite, 708 ReferenceBlackWhite,
  709 +
  710 + /// DateTime
543 DateTime, 711 DateTime,
  712 +
  713 + /// ImageDescription
544 ImageDescription, 714 ImageDescription,
  715 +
  716 + /// Make
545 Make, 717 Make,
  718 +
  719 + /// Model
546 Model, 720 Model,
  721 +
  722 + /// Software
547 Software, 723 Software,
  724 +
  725 + /// Artist
548 Artist, 726 Artist,
  727 +
  728 + /// Copyright
549 Copyright, 729 Copyright,
550 } 730 }
@@ -16,84 +16,96 @@ @@ -16,84 +16,96 @@
16 16
17 part of pdf; 17 part of pdf;
18 18
  19 +/// Pdf font object
19 abstract class PdfFont extends PdfObject { 20 abstract class PdfFont extends PdfObject {
20 /// Constructs a [PdfFont]. This will attempt to map the font from a known 21 /// Constructs a [PdfFont]. This will attempt to map the font from a known
21 /// font name to that in Pdf, defaulting to Helvetica if not possible. 22 /// font name to that in Pdf, defaulting to Helvetica if not possible.
22 - ///  
23 - /// @param name The document name, ie /F1  
24 - /// @param subtype The pdf type, ie /Type1  
25 - /// @param baseFont The font name, ie /Helvetica  
26 PdfFont._create(PdfDocument pdfDocument, {@required this.subtype}) 23 PdfFont._create(PdfDocument pdfDocument, {@required this.subtype})
27 : assert(subtype != null), 24 : assert(subtype != null),
28 super(pdfDocument, '/Font') { 25 super(pdfDocument, '/Font') {
29 pdfDocument.fonts.add(this); 26 pdfDocument.fonts.add(this);
30 } 27 }
31 28
  29 + /// Monospaced slab serif typeface.
32 factory PdfFont.courier(PdfDocument pdfDocument) { 30 factory PdfFont.courier(PdfDocument pdfDocument) {
33 return PdfType1Font._create( 31 return PdfType1Font._create(
34 pdfDocument, 'Courier', 0.910, -0.220, const <double>[]); 32 pdfDocument, 'Courier', 0.910, -0.220, const <double>[]);
35 } 33 }
36 34
  35 + /// Bold monospaced slab serif typeface.
37 factory PdfFont.courierBold(PdfDocument pdfDocument) { 36 factory PdfFont.courierBold(PdfDocument pdfDocument) {
38 return PdfType1Font._create( 37 return PdfType1Font._create(
39 pdfDocument, 'Courier-Bold', 0.910, -0.220, const <double>[]); 38 pdfDocument, 'Courier-Bold', 0.910, -0.220, const <double>[]);
40 } 39 }
41 40
  41 + /// Bold and Italic monospaced slab serif typeface.
42 factory PdfFont.courierBoldOblique(PdfDocument pdfDocument) { 42 factory PdfFont.courierBoldOblique(PdfDocument pdfDocument) {
43 return PdfType1Font._create( 43 return PdfType1Font._create(
44 pdfDocument, 'Courier-BoldOblique', 0.910, -0.220, const <double>[]); 44 pdfDocument, 'Courier-BoldOblique', 0.910, -0.220, const <double>[]);
45 } 45 }
46 46
  47 + /// Italic monospaced slab serif typeface.
47 factory PdfFont.courierOblique(PdfDocument pdfDocument) { 48 factory PdfFont.courierOblique(PdfDocument pdfDocument) {
48 return PdfType1Font._create( 49 return PdfType1Font._create(
49 pdfDocument, 'Courier-Oblique', 0.910, -0.220, const <double>[]); 50 pdfDocument, 'Courier-Oblique', 0.910, -0.220, const <double>[]);
50 } 51 }
51 52
  53 + /// Neo-grotesque design sans-serif typeface
52 factory PdfFont.helvetica(PdfDocument pdfDocument) { 54 factory PdfFont.helvetica(PdfDocument pdfDocument) {
53 return PdfType1Font._create( 55 return PdfType1Font._create(
54 pdfDocument, 'Helvetica', 0.931, -0.225, _helveticaWidths); 56 pdfDocument, 'Helvetica', 0.931, -0.225, _helveticaWidths);
55 } 57 }
56 58
  59 + /// Bold Neo-grotesque design sans-serif typeface
57 factory PdfFont.helveticaBold(PdfDocument pdfDocument) { 60 factory PdfFont.helveticaBold(PdfDocument pdfDocument) {
58 return PdfType1Font._create( 61 return PdfType1Font._create(
59 pdfDocument, 'Helvetica-Bold', 0.962, -0.228, _helveticaBoldWidths); 62 pdfDocument, 'Helvetica-Bold', 0.962, -0.228, _helveticaBoldWidths);
60 } 63 }
61 64
  65 + /// Bold and Italic Neo-grotesque design sans-serif typeface
62 factory PdfFont.helveticaBoldOblique(PdfDocument pdfDocument) { 66 factory PdfFont.helveticaBoldOblique(PdfDocument pdfDocument) {
63 return PdfType1Font._create(pdfDocument, 'Helvetica-BoldOblique', 0.962, 67 return PdfType1Font._create(pdfDocument, 'Helvetica-BoldOblique', 0.962,
64 -0.228, _helveticaBoldObliqueWidths); 68 -0.228, _helveticaBoldObliqueWidths);
65 } 69 }
66 70
  71 + /// Italic Neo-grotesque design sans-serif typeface
67 factory PdfFont.helveticaOblique(PdfDocument pdfDocument) { 72 factory PdfFont.helveticaOblique(PdfDocument pdfDocument) {
68 return PdfType1Font._create(pdfDocument, 'Helvetica-Oblique', 0.931, -0.225, 73 return PdfType1Font._create(pdfDocument, 'Helvetica-Oblique', 0.931, -0.225,
69 _helveticaObliqueWidths); 74 _helveticaObliqueWidths);
70 } 75 }
71 76
  77 + /// Serif typeface commissioned by the British newspaper The Times
72 factory PdfFont.times(PdfDocument pdfDocument) { 78 factory PdfFont.times(PdfDocument pdfDocument) {
73 return PdfType1Font._create( 79 return PdfType1Font._create(
74 pdfDocument, 'Times-Roman', 0.898, -0.218, _timesWidths); 80 pdfDocument, 'Times-Roman', 0.898, -0.218, _timesWidths);
75 } 81 }
76 82
  83 + /// Bold serif typeface commissioned by the British newspaper The Times
77 factory PdfFont.timesBold(PdfDocument pdfDocument) { 84 factory PdfFont.timesBold(PdfDocument pdfDocument) {
78 return PdfType1Font._create( 85 return PdfType1Font._create(
79 pdfDocument, 'Times-Bold', 0.935, -0.218, _timesBoldWidths); 86 pdfDocument, 'Times-Bold', 0.935, -0.218, _timesBoldWidths);
80 } 87 }
81 88
  89 + /// Bold and Italic serif typeface commissioned by the British newspaper The Times
82 factory PdfFont.timesBoldItalic(PdfDocument pdfDocument) { 90 factory PdfFont.timesBoldItalic(PdfDocument pdfDocument) {
83 return PdfType1Font._create( 91 return PdfType1Font._create(
84 pdfDocument, 'Times-BoldItalic', 0.921, -0.218, _timesBoldItalicWidths); 92 pdfDocument, 'Times-BoldItalic', 0.921, -0.218, _timesBoldItalicWidths);
85 } 93 }
86 94
  95 + /// Italic serif typeface commissioned by the British newspaper The Times
87 factory PdfFont.timesItalic(PdfDocument pdfDocument) { 96 factory PdfFont.timesItalic(PdfDocument pdfDocument) {
88 return PdfType1Font._create( 97 return PdfType1Font._create(
89 pdfDocument, 'Times-Italic', 0.883, -0.217, _timesItalicWidths); 98 pdfDocument, 'Times-Italic', 0.883, -0.217, _timesItalicWidths);
90 } 99 }
91 100
  101 + /// Complete unaccented serif Greek alphabet (upper and lower case) and a
  102 + /// selection of commonly used mathematical symbols.
92 factory PdfFont.symbol(PdfDocument pdfDocument) { 103 factory PdfFont.symbol(PdfDocument pdfDocument) {
93 return PdfType1Font._create( 104 return PdfType1Font._create(
94 pdfDocument, 'Symbol', 1.010, -0.293, _symbolWidths); 105 pdfDocument, 'Symbol', 1.010, -0.293, _symbolWidths);
95 } 106 }
96 107
  108 + /// Hermann Zapf ornament glyphs or spacers, often employed to create box frames
97 factory PdfFont.zapfDingbats(PdfDocument pdfDocument) { 109 factory PdfFont.zapfDingbats(PdfDocument pdfDocument) {
98 return PdfType1Font._create( 110 return PdfType1Font._create(
99 pdfDocument, 'ZapfDingbats', 0.820, -0.143, _zapfDingbatsWidths); 111 pdfDocument, 'ZapfDingbats', 0.820, -0.143, _zapfDingbatsWidths);
@@ -110,17 +122,22 @@ See https://github.com/DavBfr/dart_pdf/wiki/Fonts-Management @@ -110,17 +122,22 @@ See https://github.com/DavBfr/dart_pdf/wiki/Fonts-Management
110 /// The df type of the font, usually /Type1 122 /// The df type of the font, usually /Type1
111 final String subtype; 123 final String subtype;
112 124
  125 + /// Internal name
113 String get name => '/F$objser'; 126 String get name => '/F$objser';
114 127
  128 + /// The font's real name
115 String get fontName => null; 129 String get fontName => null;
116 130
  131 + /// Spans the distance between the baseline and the top of the glyph that
  132 + /// reaches farthest from the baseline
117 double get ascent => null; 133 double get ascent => null;
118 134
  135 + /// Spans the distance between the baseline and the lowest descending glyph
119 double get descent => null; 136 double get descent => null;
120 137
  138 + /// Default width of a glyph
121 static const double defaultGlyphWidth = 0.600; 139 static const double defaultGlyphWidth = 0.600;
122 140
123 - /// @param os OutputStream to send the object to  
124 @override 141 @override
125 void _prepare() { 142 void _prepare() {
126 super._prepare(); 143 super._prepare();
@@ -130,14 +147,18 @@ See https://github.com/DavBfr/dart_pdf/wiki/Fonts-Management @@ -130,14 +147,18 @@ See https://github.com/DavBfr/dart_pdf/wiki/Fonts-Management
130 params['/Encoding'] = const PdfName('/WinAnsiEncoding'); 147 params['/Encoding'] = const PdfName('/WinAnsiEncoding');
131 } 148 }
132 149
  150 + /// How many units to move for the next glyph
133 @Deprecated('Use `glyphMetrics` instead') 151 @Deprecated('Use `glyphMetrics` instead')
134 double glyphAdvance(int charCode) => glyphMetrics(charCode).advanceWidth; 152 double glyphAdvance(int charCode) => glyphMetrics(charCode).advanceWidth;
135 153
  154 + /// Calculate the [PdfFontMetrics] for this glyph
136 PdfFontMetrics glyphMetrics(int charCode); 155 PdfFontMetrics glyphMetrics(int charCode);
137 156
  157 + /// Calculate the dimensions of this glyph
138 @Deprecated('Use `glyphMetrics` instead') 158 @Deprecated('Use `glyphMetrics` instead')
139 PdfRect glyphBounds(int charCode) => glyphMetrics(charCode).toPdfRect(); 159 PdfRect glyphBounds(int charCode) => glyphMetrics(charCode).toPdfRect();
140 160
  161 + /// Calculate the [PdfFontMetrics] for this string
141 PdfFontMetrics stringMetrics(String s, {double letterSpacing = 0}) { 162 PdfFontMetrics stringMetrics(String s, {double letterSpacing = 0}) {
142 if (s.isEmpty) { 163 if (s.isEmpty) {
143 return PdfFontMetrics.zero; 164 return PdfFontMetrics.zero;
@@ -157,9 +178,11 @@ See https://github.com/DavBfr/dart_pdf/wiki/Fonts-Management @@ -157,9 +178,11 @@ See https://github.com/DavBfr/dart_pdf/wiki/Fonts-Management
157 } 178 }
158 } 179 }
159 180
  181 + /// Calculage the bounding box for this string
160 @Deprecated('Use `stringMetrics` instead') 182 @Deprecated('Use `stringMetrics` instead')
161 PdfRect stringBounds(String s) => stringMetrics(s).toPdfRect(); 183 PdfRect stringBounds(String s) => stringMetrics(s).toPdfRect();
162 184
  185 + /// Calculage the unit size of this string
163 PdfPoint stringSize(String s) { 186 PdfPoint stringSize(String s) {
164 final metrics = stringMetrics(s); 187 final metrics = stringMetrics(s);
165 return PdfPoint(metrics.width, metrics.height); 188 return PdfPoint(metrics.width, metrics.height);
@@ -168,6 +191,7 @@ See https://github.com/DavBfr/dart_pdf/wiki/Fonts-Management @@ -168,6 +191,7 @@ See https://github.com/DavBfr/dart_pdf/wiki/Fonts-Management
168 @override 191 @override
169 String toString() => 'Font($fontName)'; 192 String toString() => 'Font($fontName)';
170 193
  194 + /// Draw some text
171 void putText(PdfStream stream, String text) { 195 void putText(PdfStream stream, String text) {
172 try { 196 try {
173 PdfString(latin1.encode(text), PdfStringFormat.litteral).output(stream); 197 PdfString(latin1.encode(text), PdfStringFormat.litteral).output(stream);
@@ -16,7 +16,9 @@ @@ -16,7 +16,9 @@
16 16
17 part of pdf; 17 part of pdf;
18 18
  19 +/// Font descriptor object
19 class PdfFontDescriptor extends PdfObject { 20 class PdfFontDescriptor extends PdfObject {
  21 + /// Create a Font descriptor object
20 PdfFontDescriptor( 22 PdfFontDescriptor(
21 this.ttfFont, 23 this.ttfFont,
22 this.file, 24 this.file,
@@ -24,8 +26,10 @@ class PdfFontDescriptor extends PdfObject { @@ -24,8 +26,10 @@ class PdfFontDescriptor extends PdfObject {
24 assert(file != null), 26 assert(file != null),
25 super(ttfFont.pdfDocument, '/FontDescriptor'); 27 super(ttfFont.pdfDocument, '/FontDescriptor');
26 28
  29 + /// File data
27 final PdfObjectStream file; 30 final PdfObjectStream file;
28 31
  32 + /// Truetype font
29 final PdfTtfFont ttfFont; 33 final PdfTtfFont ttfFont;
30 34
31 @override 35 @override
@@ -16,8 +16,10 @@ @@ -16,8 +16,10 @@
16 16
17 part of pdf; 17 part of pdf;
18 18
  19 +/// Describe dimensions for glyphs in a font
19 @immutable 20 @immutable
20 class PdfFontMetrics { 21 class PdfFontMetrics {
  22 + /// Create a PdfFontMetrics object
21 const PdfFontMetrics( 23 const PdfFontMetrics(
22 {@required this.left, 24 {@required this.left,
23 @required this.top, 25 @required this.top,
@@ -37,6 +39,7 @@ class PdfFontMetrics { @@ -37,6 +39,7 @@ class PdfFontMetrics {
37 assert(top <= bottom), 39 assert(top <= bottom),
38 assert((descent ?? top) <= (ascent ?? bottom)); 40 assert((descent ?? top) <= (ascent ?? bottom));
39 41
  42 + /// Add another metric
40 factory PdfFontMetrics.append( 43 factory PdfFontMetrics.append(
41 Iterable<PdfFontMetrics> metrics, { 44 Iterable<PdfFontMetrics> metrics, {
42 double letterSpacing = 0, 45 double letterSpacing = 0,
@@ -76,42 +79,59 @@ class PdfFontMetrics { @@ -76,42 +79,59 @@ class PdfFontMetrics {
76 advanceWidth: right - spacing); 79 advanceWidth: right - spacing);
77 } 80 }
78 81
  82 + /// Zero-sized dimensions
79 static const PdfFontMetrics zero = 83 static const PdfFontMetrics zero =
80 PdfFontMetrics(left: 0, top: 0, right: 0, bottom: 0); 84 PdfFontMetrics(left: 0, top: 0, right: 0, bottom: 0);
81 85
  86 + /// Left most of the bounding box
82 final double left; 87 final double left;
83 88
  89 + /// Top most of the bounding box
84 final double top; 90 final double top;
85 91
  92 + /// Bottom most of the bounding box
86 final double bottom; 93 final double bottom;
87 94
  95 + /// Right most of the bounding box
88 final double right; 96 final double right;
89 97
  98 + /// Spans the distance between the baseline and the top of the glyph that
  99 + /// reaches farthest from the baseline
90 final double ascent; 100 final double ascent;
91 101
  102 + /// Spans the distance between the baseline and the lowest descending glyph
92 final double descent; 103 final double descent;
93 104
  105 + /// distance to move right to draw the next glyph
94 final double advanceWidth; 106 final double advanceWidth;
95 107
  108 + /// Width of the glyph
96 double get width => right - left; 109 double get width => right - left;
97 110
  111 + /// Height of the glyph
98 double get height => bottom - top; 112 double get height => bottom - top;
99 113
100 - double get maxHeight => ascent - descent;  
101 - 114 + /// Maximum Width any glyph from this font can have
102 double get maxWidth => 115 double get maxWidth =>
103 math.max(advanceWidth, right) + math.max(-leftBearing, 0.0); 116 math.max(advanceWidth, right) + math.max(-leftBearing, 0.0);
104 117
  118 + /// Maximum Height any glyph from this font can have
  119 + double get maxHeight => ascent - descent;
  120 +
  121 + /// Real left position. The glyph may overflow on the left
105 double get effectiveLeft => math.min(leftBearing, 0); 122 double get effectiveLeft => math.min(leftBearing, 0);
106 123
  124 + /// Starting point
107 double get leftBearing => left; 125 double get leftBearing => left;
108 126
  127 + /// Ending point
109 double get rightBearing => advanceWidth - right; 128 double get rightBearing => advanceWidth - right;
110 129
111 @override 130 @override
112 String toString() => 131 String toString() =>
113 'PdfFontMetrics(left:$left, top:$top, right:$right, bottom:$bottom, ascent:$ascent, descent:$descent, advanceWidth:$advanceWidth)'; 132 'PdfFontMetrics(left:$left, top:$top, right:$right, bottom:$bottom, ascent:$ascent, descent:$descent, advanceWidth:$advanceWidth)';
114 133
  134 + /// Make a copy of this object
115 PdfFontMetrics copyWith( 135 PdfFontMetrics copyWith(
116 {double left, 136 {double left,
117 double top, 137 double top,
@@ -130,6 +150,7 @@ class PdfFontMetrics { @@ -130,6 +150,7 @@ class PdfFontMetrics {
130 advanceWidth: advanceWidth ?? this.advanceWidth); 150 advanceWidth: advanceWidth ?? this.advanceWidth);
131 } 151 }
132 152
  153 + /// Multiply this metrics object with a font size
133 PdfFontMetrics operator *(double factor) { 154 PdfFontMetrics operator *(double factor) {
134 return copyWith( 155 return copyWith(
135 left: left * factor, 156 left: left * factor,
@@ -142,5 +163,6 @@ class PdfFontMetrics { @@ -142,5 +163,6 @@ class PdfFontMetrics {
142 ); 163 );
143 } 164 }
144 165
  166 + /// Get the bounding box
145 PdfRect toPdfRect() => PdfRect.fromLTRB(left, top, right, bottom); 167 PdfRect toPdfRect() => PdfRect.fromLTRB(left, top, right, bottom);
146 } 168 }
@@ -16,7 +16,9 @@ @@ -16,7 +16,9 @@
16 16
17 part of pdf; 17 part of pdf;
18 18
  19 +/// Form XObject
19 class PdfFormXObject extends PdfXObject { 20 class PdfFormXObject extends PdfXObject {
  21 + /// Create a Form XObject
20 PdfFormXObject(PdfDocument pdfDocument) : super(pdfDocument, '/Form') { 22 PdfFormXObject(PdfDocument pdfDocument) : super(pdfDocument, '/Form') {
21 params['/FormType'] = const PdfNum(1); 23 params['/FormType'] = const PdfNum(1);
22 params['/BBox'] = PdfArray.fromNum(const <int>[0, 0, 1000, 1000]); 24 params['/BBox'] = PdfArray.fromNum(const <int>[0, 0, 1000, 1000]);
@@ -28,7 +30,7 @@ class PdfFormXObject extends PdfXObject { @@ -28,7 +30,7 @@ class PdfFormXObject extends PdfXObject {
28 /// The xobjects or other images in the pdf 30 /// The xobjects or other images in the pdf
29 final Map<String, PdfXObject> xobjects = <String, PdfXObject>{}; 31 final Map<String, PdfXObject> xobjects = <String, PdfXObject>{};
30 32
31 - /// set matrix 33 + /// Transformation matrix
32 void setMatrix(Matrix4 t) { 34 void setMatrix(Matrix4 t) {
33 final s = t.storage; 35 final s = t.storage;
34 params['/Matrix'] = 36 params['/Matrix'] =
@@ -39,8 +41,7 @@ class PdfFormXObject extends PdfXObject { @@ -39,8 +41,7 @@ class PdfFormXObject extends PdfXObject {
39 void _prepare() { 41 void _prepare() {
40 super._prepare(); 42 super._prepare();
41 43
42 - // Now the resources  
43 - /// This holds any resources for this FormXObject 44 + // This holds any resources for this FormXObject
44 final resources = PdfDict(); 45 final resources = PdfDict();
45 46
46 // fonts 47 // fonts
@@ -18,10 +18,13 @@ @@ -18,10 +18,13 @@
18 18
19 part of pdf; 19 part of pdf;
20 20
  21 +/// Graphic state
21 @immutable 22 @immutable
22 class PdfGraphicState { 23 class PdfGraphicState {
  24 + /// Create a new graphic state
23 const PdfGraphicState({this.opacity}); 25 const PdfGraphicState({this.opacity});
24 26
  27 + /// The opacity to apply to this graphic state
25 final double opacity; 28 final double opacity;
26 29
27 @protected 30 @protected
@@ -48,13 +51,16 @@ class PdfGraphicState { @@ -48,13 +51,16 @@ class PdfGraphicState {
48 int get hashCode => opacity.hashCode; 51 int get hashCode => opacity.hashCode;
49 } 52 }
50 53
  54 +/// Stores all the graphic states used in the document
51 class PdfGraphicStates extends PdfObject { 55 class PdfGraphicStates extends PdfObject {
  56 + /// Create a new Graphic States object
52 PdfGraphicStates(PdfDocument pdfDocument) : super(pdfDocument); 57 PdfGraphicStates(PdfDocument pdfDocument) : super(pdfDocument);
53 58
54 final List<PdfGraphicState> _states = <PdfGraphicState>[]; 59 final List<PdfGraphicState> _states = <PdfGraphicState>[];
55 60
56 static const String _prefix = '/a'; 61 static const String _prefix = '/a';
57 62
  63 + /// Generate a name for a state object
58 String stateName(PdfGraphicState state) { 64 String stateName(PdfGraphicState state) {
59 var index = _states.indexOf(state); 65 var index = _states.indexOf(state);
60 if (index < 0) { 66 if (index < 0) {
@@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
16 16
17 part of pdf; 17 part of pdf;
18 18
  19 +/// Helper functions for graphic objects
19 mixin PdfGraphicStream on PdfObject { 20 mixin PdfGraphicStream on PdfObject {
20 /// Isolated transparency: If this flag is true, objects within the group 21 /// Isolated transparency: If this flag is true, objects within the group
21 /// shall be composited against a fully transparent initial backdrop; 22 /// shall be composited against a fully transparent initial backdrop;
@@ -38,24 +39,28 @@ mixin PdfGraphicStream on PdfObject { @@ -38,24 +39,28 @@ mixin PdfGraphicStream on PdfObject {
38 /// The xobjects or other images in the pdf 39 /// The xobjects or other images in the pdf
39 final Map<String, PdfXObject> xObjects = <String, PdfXObject>{}; 40 final Map<String, PdfXObject> xObjects = <String, PdfXObject>{};
40 41
  42 + /// Add a font to this graphic object
41 void addFont(PdfFont font) { 43 void addFont(PdfFont font) {
42 if (!fonts.containsKey(font.name)) { 44 if (!fonts.containsKey(font.name)) {
43 fonts[font.name] = font; 45 fonts[font.name] = font;
44 } 46 }
45 } 47 }
46 48
  49 + /// Add a shader to this graphic object
47 void addShader(PdfShading shader) { 50 void addShader(PdfShading shader) {
48 if (!shading.containsKey(shader.name)) { 51 if (!shading.containsKey(shader.name)) {
49 shading[shader.name] = shader; 52 shading[shader.name] = shader;
50 } 53 }
51 } 54 }
52 55
  56 + /// Add an XObject to this graphic object
53 void addXObject(PdfXObject object) { 57 void addXObject(PdfXObject object) {
54 if (!xObjects.containsKey(object.name)) { 58 if (!xObjects.containsKey(object.name)) {
55 xObjects[object.name] = object; 59 xObjects[object.name] = object;
56 } 60 }
57 } 61 }
58 62
  63 + /// Get the default font of this graphic object
59 PdfFont getDefaultFont() { 64 PdfFont getDefaultFont() {
60 if (pdfDocument.fonts.isEmpty) { 65 if (pdfDocument.fonts.isEmpty) {
61 PdfFont.helvetica(pdfDocument); 66 PdfFont.helvetica(pdfDocument);
@@ -64,6 +69,7 @@ mixin PdfGraphicStream on PdfObject { @@ -64,6 +69,7 @@ mixin PdfGraphicStream on PdfObject {
64 return pdfDocument.fonts.elementAt(0); 69 return pdfDocument.fonts.elementAt(0);
65 } 70 }
66 71
  72 + /// Generate a name for the graphic state object
67 String stateName(PdfGraphicState state) { 73 String stateName(PdfGraphicState state) {
68 return pdfDocument.graphicStates.stateName(state); 74 return pdfDocument.graphicStates.stateName(state);
69 } 75 }
@@ -114,7 +120,9 @@ mixin PdfGraphicStream on PdfObject { @@ -114,7 +120,9 @@ mixin PdfGraphicStream on PdfObject {
114 } 120 }
115 } 121 }
116 122
  123 +/// Graphic XObject
117 class PdfGraphicXObject extends PdfXObject with PdfGraphicStream { 124 class PdfGraphicXObject extends PdfXObject with PdfGraphicStream {
  125 + /// Creates a Graphic XObject
118 PdfGraphicXObject( 126 PdfGraphicXObject(
119 PdfDocument pdfDocument, [ 127 PdfDocument pdfDocument, [
120 String subtype, 128 String subtype,
@@ -76,7 +76,9 @@ class _PdfGraphicsContext { @@ -76,7 +76,9 @@ class _PdfGraphicsContext {
76 _PdfGraphicsContext copy() => _PdfGraphicsContext(ctm: ctm.clone()); 76 _PdfGraphicsContext copy() => _PdfGraphicsContext(ctm: ctm.clone());
77 } 77 }
78 78
  79 +/// Pdf drawing operations
79 class PdfGraphics { 80 class PdfGraphics {
  81 + /// Create a new graphic canvas
80 PdfGraphics(this._page, this.buf) { 82 PdfGraphics(this._page, this.buf) {
81 _context = _PdfGraphicsContext(ctm: Matrix4.identity()); 83 _context = _PdfGraphicsContext(ctm: Matrix4.identity());
82 } 84 }
@@ -90,22 +92,29 @@ class PdfGraphics { @@ -90,22 +92,29 @@ class PdfGraphics {
90 92
91 final PdfGraphicStream _page; 93 final PdfGraphicStream _page;
92 94
  95 + /// Buffer where to write the graphic operations
93 final PdfStream buf; 96 final PdfStream buf;
94 97
  98 + /// Default font if none selected
95 PdfFont get defaultFont => _page.getDefaultFont(); 99 PdfFont get defaultFont => _page.getDefaultFont();
96 100
  101 + /// Draw a surface on the previously defined shape
97 void fillPath() { 102 void fillPath() {
98 buf.putString('f\n'); 103 buf.putString('f\n');
99 } 104 }
100 105
  106 + /// Draw the contour of the previously defined shape
101 void strokePath() { 107 void strokePath() {
102 buf.putString('S\n'); 108 buf.putString('S\n');
103 } 109 }
104 110
  111 + /// Close the path with a line
105 void closePath() { 112 void closePath() {
106 buf.putString('s\n'); 113 buf.putString('s\n');
107 } 114 }
108 115
  116 + /// Create a clipping surface from the previously defined shape,
  117 + /// to prevent any further drawing outside
109 void clipPath() { 118 void clipPath() {
110 buf.putString('W n\n'); 119 buf.putString('W n\n');
111 } 120 }
@@ -130,26 +139,13 @@ class PdfGraphics { @@ -130,26 +139,13 @@ class PdfGraphics {
130 } 139 }
131 } 140 }
132 141
  142 + /// Save the graphc context
133 void saveContext() { 143 void saveContext() {
134 - // save graphics context  
135 buf.putString('q\n'); 144 buf.putString('q\n');
136 _contextQueue.addLast(_context.copy()); 145 _contextQueue.addLast(_context.copy());
137 } 146 }
138 147
139 /// Draws an image onto the page. 148 /// Draws an image onto the page.
140 - ///  
141 - /// This method is implemented with [Ascii85Encoder] encoding and the  
142 - /// zip stream deflater. It results in a stream that is anywhere  
143 - /// from 3 to 10 times as big as the image. This obviously needs some  
144 - /// improvement, but it works well for small images  
145 - ///  
146 - /// @param img The Image  
147 - /// @param x coordinate on page  
148 - /// @param y coordinate on page  
149 - /// @param w Width on page  
150 - /// @param h height on page  
151 - /// @param bgcolor Background colour  
152 - /// @return true if drawn  
153 void drawImage(PdfImage img, double x, double y, [double w, double h]) { 149 void drawImage(PdfImage img, double x, double y, [double w, double h]) {
154 w ??= img.width.toDouble(); 150 w ??= img.width.toDouble();
155 h ??= img.height.toDouble() * w / img.width.toDouble(); 151 h ??= img.height.toDouble() * w / img.width.toDouble();
@@ -190,19 +186,12 @@ class PdfGraphics { @@ -190,19 +186,12 @@ class PdfGraphics {
190 } 186 }
191 187
192 /// Draws a line between two coordinates. 188 /// Draws a line between two coordinates.
193 - ///  
194 - /// If the first coordinate is the same as the last one drawn  
195 - /// (i.e. a previous drawLine, moveto, etc) it is ignored.  
196 - ///  
197 - /// @param x1 coordinate  
198 - /// @param y1 coordinate  
199 - /// @param x2 coordinate  
200 - /// @param y2 coordinate  
201 void drawLine(double x1, double y1, double x2, double y2) { 189 void drawLine(double x1, double y1, double x2, double y2) {
202 moveTo(x1, y1); 190 moveTo(x1, y1);
203 lineTo(x2, y2); 191 lineTo(x2, y2);
204 } 192 }
205 193
  194 + /// Draws an ellipse
206 void drawEllipse(double x, double y, double r1, double r2) { 195 void drawEllipse(double x, double y, double r1, double r2) {
207 moveTo(x, y - r2); 196 moveTo(x, y - r2);
208 curveTo(x + _m4 * r1, y - r2, x + r1, y - _m4 * r2, x + r1, y); 197 curveTo(x + _m4 * r1, y - r2, x + r1, y - _m4 * r2, x + r1, y);
@@ -212,11 +201,6 @@ class PdfGraphics { @@ -212,11 +201,6 @@ class PdfGraphics {
212 } 201 }
213 202
214 /// Draws a Rectangle 203 /// Draws a Rectangle
215 - ///  
216 - /// @param x coordinate  
217 - /// @param y coordinate  
218 - /// @param w width  
219 - /// @param h height  
220 void drawRect( 204 void drawRect(
221 double x, 205 double x,
222 double y, 206 double y,
@@ -228,13 +212,6 @@ class PdfGraphics { @@ -228,13 +212,6 @@ class PdfGraphics {
228 } 212 }
229 213
230 /// Draws a Rounded Rectangle 214 /// Draws a Rounded Rectangle
231 - ///  
232 - /// @param x coordinate  
233 - /// @param y coordinate  
234 - /// @param w width  
235 - /// @param h height  
236 - /// @param rh horizontal radius  
237 - /// @param rv vertical radius  
238 void drawRRect(double x, double y, double w, double h, double rv, double rh) { 215 void drawRRect(double x, double y, double w, double h, double rv, double rh) {
239 moveTo(x, y + rv); 216 moveTo(x, y + rv);
240 curveTo(x, y - _m4 * rv + rv, x - _m4 * rh + rh, y, x + rh, y); 217 curveTo(x, y - _m4 * rv + rv, x - _m4 * rh + rh, y, x + rh, y);
@@ -283,10 +260,6 @@ class PdfGraphics { @@ -283,10 +260,6 @@ class PdfGraphics {
283 } 260 }
284 261
285 /// This draws a string. 262 /// This draws a string.
286 - ///  
287 - /// @param x coordinate  
288 - /// @param y coordinate  
289 - /// @param s String to draw  
290 void drawString( 263 void drawString(
291 PdfFont font, 264 PdfFont font,
292 double size, 265 double size,
@@ -316,16 +289,12 @@ class PdfGraphics { @@ -316,16 +289,12 @@ class PdfGraphics {
316 } 289 }
317 290
318 /// Sets the color for drawing 291 /// Sets the color for drawing
319 - ///  
320 - /// @param c Color to use  
321 void setColor(PdfColor color) { 292 void setColor(PdfColor color) {
322 setFillColor(color); 293 setFillColor(color);
323 setStrokeColor(color); 294 setStrokeColor(color);
324 } 295 }
325 296
326 /// Sets the fill color for drawing 297 /// Sets the fill color for drawing
327 - ///  
328 - /// @param c Color to use  
329 void setFillColor(PdfColor color) { 298 void setFillColor(PdfColor color) {
330 if (color is PdfColorCmyk) { 299 if (color is PdfColorCmyk) {
331 PdfNumList(<double>[color.cyan, color.magenta, color.yellow, color.black]) 300 PdfNumList(<double>[color.cyan, color.magenta, color.yellow, color.black])
@@ -338,8 +307,6 @@ class PdfGraphics { @@ -338,8 +307,6 @@ class PdfGraphics {
338 } 307 }
339 308
340 /// Sets the stroke color for drawing 309 /// Sets the stroke color for drawing
341 - ///  
342 - /// @param c Color to use  
343 void setStrokeColor(PdfColor color) { 310 void setStrokeColor(PdfColor color) {
344 if (color is PdfColorCmyk) { 311 if (color is PdfColorCmyk) {
345 PdfNumList(<double>[color.cyan, color.magenta, color.yellow, color.black]) 312 PdfNumList(<double>[color.cyan, color.magenta, color.yellow, color.black])
@@ -371,18 +338,12 @@ class PdfGraphics { @@ -371,18 +338,12 @@ class PdfGraphics {
371 } 338 }
372 339
373 /// This adds a line segment to the current path 340 /// This adds a line segment to the current path
374 - ///  
375 - /// @param x coordinate  
376 - /// @param y coordinate  
377 void lineTo(double x, double y) { 341 void lineTo(double x, double y) {
378 PdfNumList(<double>[x, y]).output(buf); 342 PdfNumList(<double>[x, y]).output(buf);
379 buf.putString(' l\n'); 343 buf.putString(' l\n');
380 } 344 }
381 345
382 /// This moves the current drawing point. 346 /// This moves the current drawing point.
383 - ///  
384 - /// @param x coordinate  
385 - /// @param y coordinate  
386 void moveTo(double x, double y) { 347 void moveTo(double x, double y) {
387 PdfNumList(<double>[x, y]).output(buf); 348 PdfNumList(<double>[x, y]).output(buf);
388 buf.putString(' m\n'); 349 buf.putString(' m\n');
@@ -391,13 +352,6 @@ class PdfGraphics { @@ -391,13 +352,6 @@ class PdfGraphics {
391 /// Draw a cubic bézier curve from the current point to (x3,y3) 352 /// Draw a cubic bézier curve from the current point to (x3,y3)
392 /// using (x1,y1) as the control point at the beginning of the curve 353 /// using (x1,y1) as the control point at the beginning of the curve
393 /// and (x2,y2) as the control point at the end of the curve. 354 /// and (x2,y2) as the control point at the end of the curve.
394 - ///  
395 - /// @param x1 first control point  
396 - /// @param y1 first control point  
397 - /// @param x2 second control point  
398 - /// @param y2 second control point  
399 - /// @param x3 end point  
400 - /// @param y3 end point  
401 void curveTo( 355 void curveTo(
402 double x1, double y1, double x2, double y2, double x3, double y3) { 356 double x1, double y1, double x2, double y2, double x3, double y3) {
403 PdfNumList(<double>[x1, y1, x2, y2, x3, y3]).output(buf); 357 PdfNumList(<double>[x1, y1, x2, y2, x3, y3]).output(buf);
@@ -546,11 +500,13 @@ class PdfGraphics { @@ -546,11 +500,13 @@ class PdfGraphics {
546 } 500 }
547 } 501 }
548 502
  503 + /// Draw an SVG path
549 void drawShape(String d, {bool stroke = true}) { 504 void drawShape(String d, {bool stroke = true}) {
550 final proxy = _PathProxy(this, stroke); 505 final proxy = _PathProxy(this, stroke);
551 writeSvgPathDataToPath(d, proxy); 506 writeSvgPathDataToPath(d, proxy);
552 } 507 }
553 508
  509 + /// Set line starting and ending cap type
554 void setLineCap(PdfLineCap cap) { 510 void setLineCap(PdfLineCap cap) {
555 buf.putString('${cap.index} J\n'); 511 buf.putString('${cap.index} J\n');
556 } 512 }
@@ -560,16 +516,22 @@ class PdfGraphics { @@ -560,16 +516,22 @@ class PdfGraphics {
560 buf.putString('${join.index} j\n'); 516 buf.putString('${join.index} j\n');
561 } 517 }
562 518
  519 + /// Set line width
563 void setLineWidth(double width) { 520 void setLineWidth(double width) {
564 PdfNum(width).output(buf); 521 PdfNum(width).output(buf);
565 buf.putString(' w\n'); 522 buf.putString(' w\n');
566 } 523 }
567 524
  525 + /// Set line joint miter limit, applies if the
568 void setMiterLimit(double limit) { 526 void setMiterLimit(double limit) {
569 PdfNum(limit).output(buf); 527 PdfNum(limit).output(buf);
570 buf.putString(' M\n'); 528 buf.putString(' M\n');
571 } 529 }
572 530
  531 + /// The dash array shall be cycled through, adding up the lengths of dashes and gaps.
  532 + /// When the accumulated length equals the value specified by the dash phase
  533 + ///
  534 + /// Example: [2 1] will create a dash pattern with 2 on, 1 off, 2 on, 1 off, ...
573 void setLineDashPattern([List<int> array = const <int>[], int phase = 0]) { 535 void setLineDashPattern([List<int> array = const <int>[], int phase = 0]) {
574 PdfArray.fromNum(array).output(buf); 536 PdfArray.fromNum(array).output(buf);
575 buf.putString(' $phase d\n'); 537 buf.putString(' $phase d\n');
@@ -19,16 +19,32 @@ part of pdf; @@ -19,16 +19,32 @@ part of pdf;
19 /// Represents the position of the first pixel in the data stream 19 /// Represents the position of the first pixel in the data stream
20 /// This corresponds to the exif orientations 20 /// This corresponds to the exif orientations
21 enum PdfImageOrientation { 21 enum PdfImageOrientation {
  22 + /// Rotated 0°
22 topLeft, 23 topLeft,
  24 +
  25 + /// Rotated 90°
23 topRight, 26 topRight,
  27 +
  28 + /// Rotated 180°
24 bottomRight, 29 bottomRight,
  30 +
  31 + /// Rotated 270°
25 bottomLeft, 32 bottomLeft,
  33 +
  34 + /// Rotated 0° mirror
26 leftTop, 35 leftTop,
  36 +
  37 + /// Rotated 90° mirror
27 rightTop, 38 rightTop,
  39 +
  40 + /// Rotated 180° mirror
28 rightBottom, 41 rightBottom,
  42 +
  43 + /// Rotated 270° mirror
29 leftBottom, 44 leftBottom,
30 } 45 }
31 46
  47 +/// Image object stored in the Pdf document
32 class PdfImage extends PdfXObject { 48 class PdfImage extends PdfXObject {
33 /// Creates a new [PdfImage] instance. 49 /// Creates a new [PdfImage] instance.
34 factory PdfImage( 50 factory PdfImage(
@@ -77,6 +93,7 @@ class PdfImage extends PdfXObject { @@ -77,6 +93,7 @@ class PdfImage extends PdfXObject {
77 return im; 93 return im;
78 } 94 }
79 95
  96 + /// Create an image from a jpeg file
80 factory PdfImage.jpeg( 97 factory PdfImage.jpeg(
81 PdfDocument pdfDocument, { 98 PdfDocument pdfDocument, {
82 @required Uint8List image, 99 @required Uint8List image,
@@ -107,6 +124,7 @@ class PdfImage extends PdfXObject { @@ -107,6 +124,7 @@ class PdfImage extends PdfXObject {
107 return im; 124 return im;
108 } 125 }
109 126
  127 + /// Create an image from an [im.Image] object
110 factory PdfImage.fromImage( 128 factory PdfImage.fromImage(
111 PdfDocument pdfDocument, { 129 PdfDocument pdfDocument, {
112 @required im.Image image, 130 @required im.Image image,
@@ -124,6 +142,7 @@ class PdfImage extends PdfXObject { @@ -124,6 +142,7 @@ class PdfImage extends PdfXObject {
124 ); 142 );
125 } 143 }
126 144
  145 + /// Create an image from an image file
127 factory PdfImage.file( 146 factory PdfImage.file(
128 PdfDocument pdfDocument, { 147 PdfDocument pdfDocument, {
129 @required Uint8List bytes, 148 @required Uint8List bytes,
@@ -185,12 +204,14 @@ class PdfImage extends PdfXObject { @@ -185,12 +204,14 @@ class PdfImage extends PdfXObject {
185 params['/Height'] = PdfNum(_height); 204 params['/Height'] = PdfNum(_height);
186 } 205 }
187 206
188 - /// Image width  
189 final int _width; 207 final int _width;
  208 +
  209 + /// Image width
190 int get width => orientation.index >= 4 ? _height : _width; 210 int get width => orientation.index >= 4 ? _height : _width;
191 211
192 - /// Image height  
193 final int _height; 212 final int _height;
  213 +
  214 + /// Image height
194 int get height => orientation.index < 4 ? _height : _width; 215 int get height => orientation.index < 4 ? _height : _width;
195 216
196 /// The internal orientation of the image 217 /// The internal orientation of the image
@@ -16,8 +16,9 @@ @@ -16,8 +16,9 @@
16 16
17 part of pdf; 17 part of pdf;
18 18
  19 +/// Information object
19 class PdfInfo extends PdfObject { 20 class PdfInfo extends PdfObject {
20 - /// @param title Title of this document 21 + /// Create an information object
21 PdfInfo(PdfDocument pdfDocument, 22 PdfInfo(PdfDocument pdfDocument,
22 {this.title, 23 {this.title,
23 this.author, 24 this.author,
@@ -53,15 +54,21 @@ class PdfInfo extends PdfObject { @@ -53,15 +54,21 @@ class PdfInfo extends PdfObject {
53 54
54 static const String _libraryName = 'https://github.com/DavBfr/dart_pdf'; 55 static const String _libraryName = 'https://github.com/DavBfr/dart_pdf';
55 56
  57 + /// Author of this document
56 final String author; 58 final String author;
57 59
  60 + /// Creator of this document
58 final String creator; 61 final String creator;
59 62
  63 + /// Title of this document
60 final String title; 64 final String title;
61 65
  66 + /// Subject of this document
62 final String subject; 67 final String subject;
63 68
  69 + /// Keywords of this document
64 final String keywords; 70 final String keywords;
65 71
  72 + /// Application that created this document
66 final String producer; 73 final String producer;
67 } 74 }
@@ -16,12 +16,14 @@ @@ -16,12 +16,14 @@
16 16
17 part of pdf; 17 part of pdf;
18 18
  19 +/// Pdf Name object
19 class PdfNames extends PdfObject { 20 class PdfNames extends PdfObject {
20 /// This constructs a Pdf Name object 21 /// This constructs a Pdf Name object
21 PdfNames(PdfDocument pdfDocument) : super(pdfDocument); 22 PdfNames(PdfDocument pdfDocument) : super(pdfDocument);
22 23
23 final Map<String, PdfDataType> _dests = <String, PdfDataType>{}; 24 final Map<String, PdfDataType> _dests = <String, PdfDataType>{};
24 25
  26 + /// Add a named destination
25 void addDest( 27 void addDest(
26 String name, 28 String name,
27 PdfPage page, { 29 PdfPage page, {
@@ -16,12 +16,14 @@ @@ -16,12 +16,14 @@
16 16
17 part of pdf; 17 part of pdf;
18 18
  19 +/// Base Object used in the PDF file
19 class PdfObject { 20 class PdfObject {
20 /// This is usually called by extensors to this class, and sets the 21 /// This is usually called by extensors to this class, and sets the
21 /// Pdf Object Type 22 /// Pdf Object Type
22 - /// @param type the Pdf Object Type  
23 - PdfObject(this.pdfDocument, [String type])  
24 - : assert(pdfDocument != null), 23 + PdfObject(
  24 + this.pdfDocument, [
  25 + String type,
  26 + ]) : assert(pdfDocument != null),
25 objser = pdfDocument._genSerial() { 27 objser = pdfDocument._genSerial() {
26 if (type != null) { 28 if (type != null) {
27 params['/Type'] = PdfName(type); 29 params['/Type'] = PdfName(type);
@@ -43,12 +45,6 @@ class PdfObject { @@ -43,12 +45,6 @@ class PdfObject {
43 final PdfDocument pdfDocument; 45 final PdfDocument pdfDocument;
44 46
45 /// Writes the object to the output stream. 47 /// Writes the object to the output stream.
46 - /// This method must be overridden.  
47 - ///  
48 - /// Note: It should not write any other objects, even if they are  
49 - /// it's Kids, as they will be written by the calling routine.  
50 - ///  
51 - /// @param os OutputStream to send the object to  
52 void _write(PdfStream os) { 48 void _write(PdfStream os) {
53 _prepare(); 49 _prepare();
54 _writeStart(os); 50 _writeStart(os);
@@ -62,10 +58,6 @@ class PdfObject { @@ -62,10 +58,6 @@ class PdfObject {
62 58
63 /// The write method should call this before writing anything to the 59 /// The write method should call this before writing anything to the
64 /// OutputStream. This will send the standard header for each object. 60 /// OutputStream. This will send the standard header for each object.
65 - ///  
66 - /// Note: There are a few rare cases where this method is not called.  
67 - ///  
68 - /// @param os OutputStream to write to  
69 void _writeStart(PdfStream os) { 61 void _writeStart(PdfStream os) {
70 os.putString('$objser $objgen obj\n'); 62 os.putString('$objser $objgen obj\n');
71 } 63 }
@@ -79,15 +71,10 @@ class PdfObject { @@ -79,15 +71,10 @@ class PdfObject {
79 71
80 /// The write method should call this after writing anything to the 72 /// The write method should call this after writing anything to the
81 /// OutputStream. This will send the standard footer for each object. 73 /// OutputStream. This will send the standard footer for each object.
82 - ///  
83 - /// Note: There are a few rare cases where this method is not called.  
84 - ///  
85 - /// @param os OutputStream to write to  
86 void _writeEnd(PdfStream os) { 74 void _writeEnd(PdfStream os) {
87 os.putString('endobj\n'); 75 os.putString('endobj\n');
88 } 76 }
89 77
90 /// Returns the unique serial number in Pdf format 78 /// Returns the unique serial number in Pdf format
91 - /// @return the serial number in Pdf format  
92 PdfIndirect ref() => PdfIndirect(objser, objgen); 79 PdfIndirect ref() => PdfIndirect(objser, objgen);
93 } 80 }
@@ -16,16 +16,14 @@ @@ -16,16 +16,14 @@
16 16
17 part of pdf; 17 part of pdf;
18 18
  19 +/// Stream Object
19 class PdfObjectStream extends PdfObject { 20 class PdfObjectStream extends PdfObject {
20 - /// Constructs a stream. The supplied type is stored in the stream's header  
21 - /// and is used by other objects that extend the [PdfStream] class (like  
22 - /// [PdfImage]).  
23 - /// By default, the stream will be compressed.  
24 - ///  
25 - /// @param type type for the stream  
26 - /// @see [PdfImage]  
27 - PdfObjectStream(PdfDocument pdfDocument, {String type, this.isBinary = false})  
28 - : super(pdfDocument, type); 21 + /// Constructs a stream object to store some data
  22 + PdfObjectStream(
  23 + PdfDocument pdfDocument, {
  24 + String type,
  25 + this.isBinary = false,
  26 + }) : super(pdfDocument, type);
29 27
30 /// This holds the stream's content. 28 /// This holds the stream's content.
31 final PdfStream buf = PdfStream(); 29 final PdfStream buf = PdfStream();
@@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
16 16
17 part of pdf; 17 part of pdf;
18 18
  19 +/// Outline mode
19 enum PdfOutlineMode { 20 enum PdfOutlineMode {
20 /// When jumping to the destination, display the whole page 21 /// When jumping to the destination, display the whole page
21 fitPage, 22 fitPage,
@@ -24,6 +25,7 @@ enum PdfOutlineMode { @@ -24,6 +25,7 @@ enum PdfOutlineMode {
24 fitRect 25 fitRect
25 } 26 }
26 27
  28 +/// Outline style
27 enum PdfOutlineStyle { 29 enum PdfOutlineStyle {
28 /// Normal 30 /// Normal
29 normal, 31 normal,
@@ -31,16 +33,17 @@ enum PdfOutlineStyle { @@ -31,16 +33,17 @@ enum PdfOutlineStyle {
31 /// Italic 33 /// Italic
32 italic, 34 italic,
33 35
34 - // Bold 36 + /// Bold
35 bold, 37 bold,
36 38
37 /// Italic and Bold 39 /// Italic and Bold
38 italicBold, 40 italicBold,
39 } 41 }
40 42
  43 +/// Pdf Outline object
41 class PdfOutline extends PdfObject { 44 class PdfOutline extends PdfObject {
42 - /// Constructs a Pdf Outline object. When selected, the specified region  
43 - /// is displayed. 45 + /// Constructs a Pdf Outline object.
  46 + /// When selected, the specified region is displayed.
44 PdfOutline( 47 PdfOutline(
45 PdfDocument pdfDocument, { 48 PdfDocument pdfDocument, {
46 this.title, 49 this.title,
@@ -82,6 +85,7 @@ class PdfOutline extends PdfObject { @@ -82,6 +85,7 @@ class PdfOutline extends PdfObject {
82 /// How to display the outline text 85 /// How to display the outline text
83 final PdfOutlineStyle style; 86 final PdfOutlineStyle style;
84 87
  88 + /// External level for this outline
85 int effectiveLevel; 89 int effectiveLevel;
86 90
87 /// This method creates an outline, and attaches it to this one. 91 /// This method creates an outline, and attaches it to this one.
@@ -91,7 +95,6 @@ class PdfOutline extends PdfObject { @@ -91,7 +95,6 @@ class PdfOutline extends PdfObject {
91 outlines.add(outline); 95 outlines.add(outline);
92 } 96 }
93 97
94 - /// @param os OutputStream to send the object to  
95 @override 98 @override
96 void _prepare() { 99 void _prepare() {
97 super._prepare(); 100 super._prepare();
@@ -162,22 +165,15 @@ class PdfOutline extends PdfObject { @@ -162,22 +165,15 @@ class PdfOutline extends PdfObject {
162 165
163 /// This is called by children to find their position in this outlines 166 /// This is called by children to find their position in this outlines
164 /// tree. 167 /// tree.
165 - ///  
166 - /// @param outline [PdfOutline] to search for  
167 - /// @return index within Vector  
168 int getIndex(PdfOutline outline) => outlines.indexOf(outline); 168 int getIndex(PdfOutline outline) => outlines.indexOf(outline);
169 169
170 /// Returns the last index in this outline 170 /// Returns the last index in this outline
171 - /// @return last index in outline  
172 int getLast() => outlines.length - 1; 171 int getLast() => outlines.length - 1;
173 172
174 /// Returns the outline at a specified position. 173 /// Returns the outline at a specified position.
175 - /// @param i index  
176 - /// @return the node at index i  
177 PdfOutline getNode(int i) => outlines[i]; 174 PdfOutline getNode(int i) => outlines[i];
178 175
179 /// Returns the total number of descendants below this one. 176 /// Returns the total number of descendants below this one.
180 - /// @return the number of descendants below this one  
181 int descendants() { 177 int descendants() {
182 var c = outlines.length; // initially the number of kids 178 var c = outlines.length; // initially the number of kids
183 179
@@ -16,10 +16,9 @@ @@ -16,10 +16,9 @@
16 16
17 part of pdf; 17 part of pdf;
18 18
  19 +/// PDF document writer
19 class PdfOutput { 20 class PdfOutput {
20 /// This creates a Pdf [PdfStream] 21 /// This creates a Pdf [PdfStream]
21 - ///  
22 - /// @param os The output stream to write the Pdf file to.  
23 PdfOutput(this.os) { 22 PdfOutput(this.os) {
24 os.putString('%PDF-1.4\n'); 23 os.putString('%PDF-1.4\n');
25 os.putBytes(const <int>[0x25, 0xC2, 0xA5, 0xC2, 0xB1, 0xC3, 0xAB, 0x0A]); 24 os.putBytes(const <int>[0x25, 0xC2, 0xA5, 0xC2, 0xB1, 0xC3, 0xAB, 0x0A]);
@@ -44,8 +43,6 @@ class PdfOutput { @@ -44,8 +43,6 @@ class PdfOutput {
44 PdfSignature signatureID; 43 PdfSignature signatureID;
45 44
46 /// This method writes a [PdfObject] to the stream. 45 /// This method writes a [PdfObject] to the stream.
47 - ///  
48 - /// @param ob [PdfObject] Object to write  
49 void write(PdfObject ob) { 46 void write(PdfObject ob) {
50 // Check the object to see if it's one that is needed in the trailer 47 // Check the object to see if it's one that is needed in the trailer
51 // object 48 // object
@@ -146,8 +143,6 @@ class PdfOutput { @@ -146,8 +143,6 @@ class PdfOutput {
146 } 143 }
147 144
148 /// Writes a block of references to the Pdf file 145 /// Writes a block of references to the Pdf file
149 - /// @param firstid ID of the first reference in this block  
150 - /// @param block Vector containing the references in this block  
151 void writeblock(int firstid, List<PdfXref> block) { 146 void writeblock(int firstid, List<PdfXref> block) {
152 os.putString('$firstid ${block.length}\n'); 147 os.putString('$firstid ${block.length}\n');
153 148
@@ -16,14 +16,10 @@ @@ -16,14 +16,10 @@
16 16
17 part of pdf; 17 part of pdf;
18 18
  19 +/// Page object, which will hold any contents for this page.
19 class PdfPage extends PdfObject with PdfGraphicStream { 20 class PdfPage extends PdfObject with PdfGraphicStream {
20 /// This constructs a Page object, which will hold any contents for this 21 /// This constructs a Page object, which will hold any contents for this
21 /// page. 22 /// 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.standard}) 23 PdfPage(PdfDocument pdfDocument, {this.pageFormat = PdfPageFormat.standard})
28 : super(pdfDocument, '/Page') { 24 : super(pdfDocument, '/Page') {
29 pdfDocument.pdfPageList.pages.add(this); 25 pdfDocument.pdfPageList.pages.add(this);
@@ -46,8 +42,6 @@ class PdfPage extends PdfObject with PdfGraphicStream { @@ -46,8 +42,6 @@ class PdfPage extends PdfObject with PdfGraphicStream {
46 /// on to this page. If a previous [PdfGraphics] object was used, this object 42 /// on to this page. If a previous [PdfGraphics] object was used, this object
47 /// is appended to the page, and will be drawn over the top of any previous 43 /// is appended to the page, and will be drawn over the top of any previous
48 /// objects. 44 /// objects.
49 - ///  
50 - /// @return a new [PdfGraphics] object to be used to draw this page.  
51 PdfGraphics getGraphics() { 45 PdfGraphics getGraphics() {
52 final stream = PdfObjectStream(pdfDocument); 46 final stream = PdfObjectStream(pdfDocument);
53 final g = PdfGraphics(this, stream.buf); 47 final g = PdfGraphics(this, stream.buf);
@@ -56,11 +50,6 @@ class PdfPage extends PdfObject with PdfGraphicStream { @@ -56,11 +50,6 @@ class PdfPage extends PdfObject with PdfGraphicStream {
56 } 50 }
57 51
58 /// This adds an Annotation to the page. 52 /// This adds an Annotation to the page.
59 - ///  
60 - /// As with other objects, the annotation must be added to the pdf  
61 - /// document using [PdfDocument.add()] before adding to the page.  
62 - ///  
63 - /// @param ob Annotation to add.  
64 void addAnnotation(PdfObject ob) { 53 void addAnnotation(PdfObject ob) {
65 annotations.add(ob); 54 annotations.add(ob);
66 } 55 }
@@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
16 16
17 part of pdf; 17 part of pdf;
18 18
  19 +/// PdfPageList object
19 class PdfPageList extends PdfObject { 20 class PdfPageList extends PdfObject {
20 /// This constructs a [PdfPageList] object. 21 /// This constructs a [PdfPageList] object.
21 PdfPageList(PdfDocument pdfDocument) : super(pdfDocument, '/Pages'); 22 PdfPageList(PdfDocument pdfDocument) : super(pdfDocument, '/Pages');
@@ -24,8 +25,6 @@ class PdfPageList extends PdfObject { @@ -24,8 +25,6 @@ class PdfPageList extends PdfObject {
24 final List<PdfPage> pages = <PdfPage>[]; 25 final List<PdfPage> pages = <PdfPage>[];
25 26
26 /// This returns a specific page. Used by the Pdf class. 27 /// This returns a specific page. Used by the Pdf class.
27 - /// @param page page number to return  
28 - /// @return [PdfPage] at that position  
29 PdfPage getPage(int page) => pages[page]; 28 PdfPage getPage(int page) => pages[page];
30 29
31 @override 30 @override
@@ -16,10 +16,15 @@ @@ -16,10 +16,15 @@
16 16
17 part of pdf; 17 part of pdf;
18 18
  19 +/// Generate a TTF font copy with the minimal number of glyph to embedd
  20 +/// into the PDF document
  21 +///
19 /// https://opentype.js.org/ 22 /// https://opentype.js.org/
20 class TtfWriter { 23 class TtfWriter {
  24 + /// Create a Truetype Writer object
21 TtfWriter(this.ttf); 25 TtfWriter(this.ttf);
22 26
  27 + /// original truetype file
23 final TtfParser ttf; 28 final TtfParser ttf;
24 29
25 int _calcTableChecksum(ByteData table) { 30 int _calcTableChecksum(ByteData table) {
@@ -52,6 +57,7 @@ class TtfWriter { @@ -52,6 +57,7 @@ class TtfWriter {
52 return offset + ((align - (offset % align)) % align); 57 return offset + ((align - (offset % align)) % align);
53 } 58 }
54 59
  60 + /// Write this list of glyphs
55 Uint8List withChars(List<int> chars) { 61 Uint8List withChars(List<int> chars) {
56 final tables = <String, Uint8List>{}; 62 final tables = <String, Uint8List>{};
57 final tablesLength = <String, int>{}; 63 final tablesLength = <String, int>{};
@@ -16,6 +16,14 @@ @@ -16,6 +16,14 @@
16 16
17 part of pdf; 17 part of pdf;
18 18
  19 +/// Type 1 font object.
  20 +/// this font is a default PDF font available in all PDF readers,
  21 +/// but it's only compatible with western latin languages.
  22 +///
  23 +/// To use other languages, use a [PdfTtfFont] that contains the
  24 +/// glyph for the language you will use.
  25 +///
  26 +/// see https://github.com/DavBfr/dart_pdf/wiki/Fonts-Management
19 class PdfType1Font extends PdfFont { 27 class PdfType1Font extends PdfFont {
20 /// Constructs a [PdfTtfFont] 28 /// Constructs a [PdfTtfFont]
21 PdfType1Font._create(PdfDocument pdfDocument, this.fontName, this.ascent, 29 PdfType1Font._create(PdfDocument pdfDocument, this.fontName, this.ascent,
@@ -27,7 +35,6 @@ class PdfType1Font extends PdfFont { @@ -27,7 +35,6 @@ class PdfType1Font extends PdfFont {
27 }()), 35 }()),
28 super._create(pdfDocument, subtype: '/Type1'); 36 super._create(pdfDocument, subtype: '/Type1');
29 37
30 - /// The font's real name  
31 @override 38 @override
32 final String fontName; 39 final String fontName;
33 40
@@ -37,9 +44,9 @@ class PdfType1Font extends PdfFont { @@ -37,9 +44,9 @@ class PdfType1Font extends PdfFont {
37 @override 44 @override
38 final double descent; 45 final double descent;
39 46
  47 + /// Width of each glyph
40 final List<double> widths; 48 final List<double> widths;
41 49
42 - /// @param os OutputStream to send the object to  
43 @override 50 @override
44 void _prepare() { 51 void _prepare() {
45 super._prepare(); 52 super._prepare();
@@ -16,11 +16,15 @@ @@ -16,11 +16,15 @@
16 16
17 part of pdf; 17 part of pdf;
18 18
  19 +/// Unicode character map object
19 class PdfUnicodeCmap extends PdfObjectStream { 20 class PdfUnicodeCmap extends PdfObjectStream {
  21 + /// Create a Unicode character map object
20 PdfUnicodeCmap(PdfDocument pdfDocument, this.protect) : super(pdfDocument); 22 PdfUnicodeCmap(PdfDocument pdfDocument, this.protect) : super(pdfDocument);
21 23
  24 + /// List of characters
22 final List<int> cmap = <int>[0]; 25 final List<int> cmap = <int>[0];
23 26
  27 + /// Protects the text from being "seen" by the PDF reader.
24 final bool protect; 28 final bool protect;
25 29
26 @override 30 @override
@@ -16,11 +16,9 @@ @@ -16,11 +16,9 @@
16 16
17 part of pdf; 17 part of pdf;
18 18
  19 +/// Cross-reference for a Pdf Object
19 class PdfXref { 20 class PdfXref {
20 /// Creates a cross-reference for a Pdf Object 21 /// 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}); 22 PdfXref(this.id, this.offset, {this.generation = 0});
25 23
26 /// The id of a Pdf Object 24 /// The id of a Pdf Object
@@ -32,7 +30,7 @@ class PdfXref { @@ -32,7 +30,7 @@ class PdfXref {
32 /// The generation of the object, usually 0 30 /// The generation of the object, usually 0
33 int generation = 0; 31 int generation = 0;
34 32
35 - /// @return The xref in the format of the xref section in the Pdf file 33 + /// The xref in the format of the xref section in the Pdf file
36 String ref() { 34 String ref() {
37 final rs = offset.toString().padLeft(10, '0') + 35 final rs = offset.toString().padLeft(10, '0') +
38 ' ' + 36 ' ' +
@@ -149,8 +149,9 @@ class _BarcodeWidget extends Widget { @@ -149,8 +149,9 @@ class _BarcodeWidget extends Widget {
149 } 149 }
150 } 150 }
151 151
  152 +/// Draw a barcode using String data
152 class BarcodeWidget extends StatelessWidget { 153 class BarcodeWidget extends StatelessWidget {
153 - /// Draw a barcode using String data 154 + /// Create a BarcodeWidget
154 factory BarcodeWidget({ 155 factory BarcodeWidget({
155 @required String data, 156 @required String data,
156 @required Barcode barcode, 157 @required Barcode barcode,