David PHAM-VAN

Rework constructors

@@ -27,48 +27,78 @@ class PdfAnnot extends PdfObject { @@ -27,48 +27,78 @@ class PdfAnnot extends PdfObject {
27 this.border, 27 this.border,
28 this.url, 28 this.url,
29 this.name}) 29 this.name})
30 - : super(pdfPage.pdfDocument, type ?? '/Annot') { 30 + : assert(subtype != null),
  31 + super(pdfPage.pdfDocument, type ?? '/Annot') {
31 pdfPage.annotations.add(this); 32 pdfPage.annotations.add(this);
32 } 33 }
33 34
34 /// Creates a text annotation 35 /// Creates a text annotation
35 /// @param rect coordinates 36 /// @param rect coordinates
36 /// @param s Text for this annotation 37 /// @param s Text for this annotation
37 - factory PdfAnnot.text(PdfPage pdfPage,  
38 - {@required PdfRect rect, 38 + factory PdfAnnot.text(
  39 + PdfPage pdfPage, {
  40 + @required PdfRect rect,
39 @required String content, 41 @required String content,
40 - PdfBorder border}) =>  
41 - PdfAnnot._create(pdfPage,  
42 - subtype: '/Text', srcRect: rect, content: content, border: border); 42 + PdfBorder border,
  43 + }) =>
  44 + PdfAnnot._create(
  45 + pdfPage,
  46 + subtype: '/Text',
  47 + srcRect: rect,
  48 + content: content,
  49 + border: border,
  50 + );
43 51
44 /// Creates a link annotation 52 /// Creates a link annotation
45 /// @param srcRect coordinates 53 /// @param srcRect coordinates
46 /// @param dest Destination for this link. The page will fit the display. 54 /// @param dest Destination for this link. The page will fit the display.
47 /// @param destRect Rectangle describing what part of the page to be displayed 55 /// @param destRect Rectangle describing what part of the page to be displayed
48 /// (must be in User Coordinates) 56 /// (must be in User Coordinates)
49 - factory PdfAnnot.link(PdfPage pdfPage,  
50 - {@required PdfRect srcRect, 57 + factory PdfAnnot.link(
  58 + PdfPage pdfPage, {
  59 + @required PdfRect srcRect,
51 @required PdfPage dest, 60 @required PdfPage dest,
52 PdfRect destRect, 61 PdfRect destRect,
53 - PdfBorder border}) =>  
54 - PdfAnnot._create(pdfPage, 62 + PdfBorder border,
  63 + }) =>
  64 + PdfAnnot._create(
  65 + pdfPage,
55 subtype: '/Link', 66 subtype: '/Link',
56 srcRect: srcRect, 67 srcRect: srcRect,
57 dest: dest, 68 dest: dest,
58 destRect: destRect, 69 destRect: destRect,
59 - border: border); 70 + border: border,
  71 + );
60 72
61 /// Creates an external link annotation 73 /// Creates an external link annotation
62 - factory PdfAnnot.urlLink(PdfPage pdfPage,  
63 - {@required PdfRect rect, @required String dest, PdfBorder border}) =>  
64 - PdfAnnot._create(pdfPage,  
65 - subtype: '/Link', srcRect: rect, url: dest, border: border); 74 + factory PdfAnnot.urlLink(
  75 + PdfPage pdfPage, {
  76 + @required PdfRect rect,
  77 + @required String dest,
  78 + PdfBorder border,
  79 + }) =>
  80 + PdfAnnot._create(
  81 + pdfPage,
  82 + subtype: '/Link',
  83 + srcRect: rect,
  84 + url: dest,
  85 + border: border,
  86 + );
66 87
67 /// Creates a link annotation to a named destination 88 /// Creates a link annotation to a named destination
68 - factory PdfAnnot.namedLink(PdfPage pdfPage,  
69 - {@required PdfRect rect, @required String dest, PdfBorder border}) =>  
70 - PdfAnnot._create(pdfPage,  
71 - subtype: '/Link', srcRect: rect, name: dest, border: border); 89 + factory PdfAnnot.namedLink(
  90 + PdfPage pdfPage, {
  91 + @required PdfRect rect,
  92 + @required String dest,
  93 + PdfBorder border,
  94 + }) =>
  95 + PdfAnnot._create(
  96 + pdfPage,
  97 + subtype: '/Link',
  98 + srcRect: rect,
  99 + name: dest,
  100 + border: border,
  101 + );
72 102
73 /// The subtype of the outline, ie text, note, etc 103 /// The subtype of the outline, ie text, note, etc
74 final String subtype; 104 final String subtype;
@@ -17,7 +17,11 @@ @@ -17,7 +17,11 @@
17 part of pdf; 17 part of pdf;
18 18
19 class PdfArrayObject extends PdfObject { 19 class PdfArrayObject extends PdfObject {
20 - PdfArrayObject(PdfDocument pdfDocument, this.values) : super(pdfDocument); 20 + PdfArrayObject(
  21 + PdfDocument pdfDocument,
  22 + this.values,
  23 + ) : assert(values != null),
  24 + super(pdfDocument);
21 25
22 final List<String> values; 26 final List<String> values;
23 27
@@ -44,9 +44,14 @@ class PdfBorder extends PdfObject { @@ -44,9 +44,14 @@ class PdfBorder extends PdfObject {
44 /// @param style The style of the border 44 /// @param style The style of the border
45 /// @param dash The line pattern definition 45 /// @param dash The line pattern definition
46 /// @see [PdfAnnot] 46 /// @see [PdfAnnot]
47 - PdfBorder(PdfDocument pdfDocument, this.width,  
48 - {this.style = PdfBorderStyle.solid, this.dash})  
49 - : super(pdfDocument); 47 + PdfBorder(
  48 + PdfDocument pdfDocument,
  49 + this.width, {
  50 + this.style = PdfBorderStyle.solid,
  51 + this.dash,
  52 + }) : assert(width != null),
  53 + assert(style != null),
  54 + super(pdfDocument);
50 55
51 /// The style of the border 56 /// The style of the border
52 final PdfBorderStyle style; 57 final PdfBorderStyle style;
@@ -23,8 +23,14 @@ class PdfCatalog extends PdfObject { @@ -23,8 +23,14 @@ class PdfCatalog extends PdfObject {
23 /// @param pagemode How the document should appear when opened. 23 /// @param pagemode How the document should appear when opened.
24 /// Allowed values are usenone, useoutlines, usethumbs or fullscreen. 24 /// Allowed values are usenone, useoutlines, usethumbs or fullscreen.
25 PdfCatalog( 25 PdfCatalog(
26 - PdfDocument pdfDocument, this.pdfPageList, this.pageMode, this.names)  
27 - : super(pdfDocument, '/Catalog'); 26 + PdfDocument pdfDocument,
  27 + this.pdfPageList,
  28 + this.pageMode,
  29 + this.names,
  30 + ) : assert(pdfPageList != null),
  31 + assert(pageMode != null),
  32 + assert(names != null),
  33 + super(pdfDocument, '/Catalog');
28 34
29 /// The pages of the document 35 /// The pages of the document
30 final PdfPageList pdfPageList; 36 final PdfPageList pdfPageList;
@@ -122,14 +122,12 @@ abstract class PdfFont extends PdfObject { @@ -122,14 +122,12 @@ abstract class PdfFont extends PdfObject {
122 params['/Encoding'] = PdfStream.string('/WinAnsiEncoding'); 122 params['/Encoding'] = PdfStream.string('/WinAnsiEncoding');
123 } 123 }
124 124
125 - // Use glyphMetrics instead  
126 - @deprecated 125 + @Deprecated('Use `glyphMetrics` instead')
127 double glyphAdvance(int charCode) => glyphMetrics(charCode).advanceWidth; 126 double glyphAdvance(int charCode) => glyphMetrics(charCode).advanceWidth;
128 127
129 PdfFontMetrics glyphMetrics(int charCode); 128 PdfFontMetrics glyphMetrics(int charCode);
130 129
131 - // Use glyphMetrics instead  
132 - @deprecated 130 + @Deprecated('Use `glyphMetrics` instead')
133 PdfRect glyphBounds(int charCode) => glyphMetrics(charCode).toPdfRect(); 131 PdfRect glyphBounds(int charCode) => glyphMetrics(charCode).toPdfRect();
134 132
135 PdfFontMetrics stringMetrics(String s) { 133 PdfFontMetrics stringMetrics(String s) {
@@ -152,8 +150,7 @@ See https://github.com/DavBfr/dart_pdf/issues/76 @@ -152,8 +150,7 @@ See https://github.com/DavBfr/dart_pdf/issues/76
152 } 150 }
153 } 151 }
154 152
155 - // Use stringMetrics instead  
156 - @deprecated 153 + @Deprecated('Use `stringMetrics` instead')
157 PdfRect stringBounds(String s) => stringMetrics(s).toPdfRect(); 154 PdfRect stringBounds(String s) => stringMetrics(s).toPdfRect();
158 155
159 PdfPoint stringSize(String s) { 156 PdfPoint stringSize(String s) {
@@ -17,8 +17,12 @@ @@ -17,8 +17,12 @@
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'); 20 + PdfFontDescriptor(
  21 + this.ttfFont,
  22 + this.file,
  23 + ) : assert(ttfFont != null),
  24 + assert(file != null),
  25 + super(ttfFont.pdfDocument, '/FontDescriptor');
22 26
23 final PdfObjectStream file; 27 final PdfObjectStream file;
24 28
@@ -21,7 +21,8 @@ class PdfObject { @@ -21,7 +21,8 @@ class PdfObject {
21 /// Pdf Object Type 21 /// Pdf Object Type
22 /// @param type the Pdf Object Type 22 /// @param type the Pdf Object Type
23 PdfObject(this.pdfDocument, [String type]) 23 PdfObject(this.pdfDocument, [String type])
24 - : objser = pdfDocument._genSerial() { 24 + : assert(pdfDocument != null),
  25 + objser = pdfDocument._genSerial() {
25 if (type != null) { 26 if (type != null) {
26 params['/Type'] = PdfStream.string(type); 27 params['/Type'] = PdfStream.string(type);
27 } 28 }
@@ -22,10 +22,10 @@ class PdfPoint { @@ -22,10 +22,10 @@ class PdfPoint {
22 22
23 final double x, y; 23 final double x, y;
24 24
25 - @deprecated 25 + @Deprecated('Use `x` instead')
26 double get w => x; 26 double get w => x;
27 27
28 - @deprecated 28 + @Deprecated('Use `y` instead')
29 double get h => y; 29 double get h => y;
30 30
31 static const PdfPoint zero = PdfPoint(0.0, 0.0); 31 static const PdfPoint zero = PdfPoint(0.0, 0.0);
@@ -41,17 +41,22 @@ class PdfRect { @@ -41,17 +41,22 @@ class PdfRect {
41 double get horizondalCenter => x + width / 2; 41 double get horizondalCenter => x + width / 2;
42 double get verticalCenter => y + height / 2; 42 double get verticalCenter => y + height / 2;
43 43
44 - @deprecated 44 + @Deprecated('Use `left` instead')
45 double get l => left; 45 double get l => left;
46 - @deprecated 46 +
  47 + @Deprecated('Use `bottom` instead')
47 double get b => bottom; 48 double get b => bottom;
48 - @deprecated 49 +
  50 + @Deprecated('Use `right` instead')
49 double get r => right; 51 double get r => right;
50 - @deprecated 52 +
  53 + @Deprecated('Use `top` instead')
51 double get t => top; 54 double get t => top;
52 - @deprecated 55 +
  56 + @Deprecated('Use `width` instead')
53 double get w => width; 57 double get w => width;
54 - @deprecated 58 +
  59 + @Deprecated('Use `height` instead')
55 double get h => height; 60 double get h => height;
56 61
57 @override 62 @override
@@ -343,7 +343,7 @@ class TextStyle { @@ -343,7 +343,7 @@ class TextStyle {
343 ); 343 );
344 } 344 }
345 345
346 - @Deprecated('use font instead') 346 + @Deprecated('use `font` instead')
347 Font get paintFont => font; 347 Font get paintFont => font;
348 348
349 Font get font { 349 Font get font {
@@ -16,7 +16,7 @@ @@ -16,7 +16,7 @@
16 16
17 part of printing; 17 part of printing;
18 18
19 -@deprecated 19 +@Deprecated('Use `Document` instead')
20 class PdfDoc extends Document { 20 class PdfDoc extends Document {
21 /// Wrapper for a [Document] with zlib compression enabled by default 21 /// Wrapper for a [Document] with zlib compression enabled by default
22 PdfDoc( 22 PdfDoc(