David PHAM-VAN

Rework constructors

... ... @@ -27,48 +27,78 @@ class PdfAnnot extends PdfObject {
this.border,
this.url,
this.name})
: super(pdfPage.pdfDocument, type ?? '/Annot') {
: assert(subtype != null),
super(pdfPage.pdfDocument, type ?? '/Annot') {
pdfPage.annotations.add(this);
}
/// Creates a text annotation
/// @param rect coordinates
/// @param s Text for this annotation
factory PdfAnnot.text(PdfPage pdfPage,
{@required PdfRect rect,
factory PdfAnnot.text(
PdfPage pdfPage, {
@required PdfRect rect,
@required String content,
PdfBorder border}) =>
PdfAnnot._create(pdfPage,
subtype: '/Text', srcRect: rect, content: content, border: border);
PdfBorder border,
}) =>
PdfAnnot._create(
pdfPage,
subtype: '/Text',
srcRect: rect,
content: content,
border: border,
);
/// Creates a link annotation
/// @param srcRect coordinates
/// @param dest Destination for this link. The page will fit the display.
/// @param destRect Rectangle describing what part of the page to be displayed
/// (must be in User Coordinates)
factory PdfAnnot.link(PdfPage pdfPage,
{@required PdfRect srcRect,
factory PdfAnnot.link(
PdfPage pdfPage, {
@required PdfRect srcRect,
@required PdfPage dest,
PdfRect destRect,
PdfBorder border}) =>
PdfAnnot._create(pdfPage,
PdfBorder border,
}) =>
PdfAnnot._create(
pdfPage,
subtype: '/Link',
srcRect: srcRect,
dest: dest,
destRect: destRect,
border: border);
border: border,
);
/// Creates an external link annotation
factory PdfAnnot.urlLink(PdfPage pdfPage,
{@required PdfRect rect, @required String dest, PdfBorder border}) =>
PdfAnnot._create(pdfPage,
subtype: '/Link', srcRect: rect, url: dest, border: border);
factory PdfAnnot.urlLink(
PdfPage pdfPage, {
@required PdfRect rect,
@required String dest,
PdfBorder border,
}) =>
PdfAnnot._create(
pdfPage,
subtype: '/Link',
srcRect: rect,
url: dest,
border: border,
);
/// Creates a link annotation to a named destination
factory PdfAnnot.namedLink(PdfPage pdfPage,
{@required PdfRect rect, @required String dest, PdfBorder border}) =>
PdfAnnot._create(pdfPage,
subtype: '/Link', srcRect: rect, name: dest, border: border);
factory PdfAnnot.namedLink(
PdfPage pdfPage, {
@required PdfRect rect,
@required String dest,
PdfBorder border,
}) =>
PdfAnnot._create(
pdfPage,
subtype: '/Link',
srcRect: rect,
name: dest,
border: border,
);
/// The subtype of the outline, ie text, note, etc
final String subtype;
... ...
... ... @@ -17,7 +17,11 @@
part of pdf;
class PdfArrayObject extends PdfObject {
PdfArrayObject(PdfDocument pdfDocument, this.values) : super(pdfDocument);
PdfArrayObject(
PdfDocument pdfDocument,
this.values,
) : assert(values != null),
super(pdfDocument);
final List<String> values;
... ...
... ... @@ -44,9 +44,14 @@ class PdfBorder extends PdfObject {
/// @param style The style of the border
/// @param dash The line pattern definition
/// @see [PdfAnnot]
PdfBorder(PdfDocument pdfDocument, this.width,
{this.style = PdfBorderStyle.solid, this.dash})
: super(pdfDocument);
PdfBorder(
PdfDocument pdfDocument,
this.width, {
this.style = PdfBorderStyle.solid,
this.dash,
}) : assert(width != null),
assert(style != null),
super(pdfDocument);
/// The style of the border
final PdfBorderStyle style;
... ...
... ... @@ -23,8 +23,14 @@ class PdfCatalog extends PdfObject {
/// @param pagemode How the document should appear when opened.
/// Allowed values are usenone, useoutlines, usethumbs or fullscreen.
PdfCatalog(
PdfDocument pdfDocument, this.pdfPageList, this.pageMode, this.names)
: super(pdfDocument, '/Catalog');
PdfDocument pdfDocument,
this.pdfPageList,
this.pageMode,
this.names,
) : assert(pdfPageList != null),
assert(pageMode != null),
assert(names != null),
super(pdfDocument, '/Catalog');
/// The pages of the document
final PdfPageList pdfPageList;
... ...
... ... @@ -122,14 +122,12 @@ abstract class PdfFont extends PdfObject {
params['/Encoding'] = PdfStream.string('/WinAnsiEncoding');
}
// Use glyphMetrics instead
@deprecated
@Deprecated('Use `glyphMetrics` instead')
double glyphAdvance(int charCode) => glyphMetrics(charCode).advanceWidth;
PdfFontMetrics glyphMetrics(int charCode);
// Use glyphMetrics instead
@deprecated
@Deprecated('Use `glyphMetrics` instead')
PdfRect glyphBounds(int charCode) => glyphMetrics(charCode).toPdfRect();
PdfFontMetrics stringMetrics(String s) {
... ... @@ -152,8 +150,7 @@ See https://github.com/DavBfr/dart_pdf/issues/76
}
}
// Use stringMetrics instead
@deprecated
@Deprecated('Use `stringMetrics` instead')
PdfRect stringBounds(String s) => stringMetrics(s).toPdfRect();
PdfPoint stringSize(String s) {
... ...
... ... @@ -17,8 +17,12 @@
part of pdf;
class PdfFontDescriptor extends PdfObject {
PdfFontDescriptor(this.ttfFont, this.file)
: super(ttfFont.pdfDocument, '/FontDescriptor');
PdfFontDescriptor(
this.ttfFont,
this.file,
) : assert(ttfFont != null),
assert(file != null),
super(ttfFont.pdfDocument, '/FontDescriptor');
final PdfObjectStream file;
... ...
... ... @@ -21,7 +21,8 @@ class PdfObject {
/// Pdf Object Type
/// @param type the Pdf Object Type
PdfObject(this.pdfDocument, [String type])
: objser = pdfDocument._genSerial() {
: assert(pdfDocument != null),
objser = pdfDocument._genSerial() {
if (type != null) {
params['/Type'] = PdfStream.string(type);
}
... ...
... ... @@ -22,10 +22,10 @@ class PdfPoint {
final double x, y;
@deprecated
@Deprecated('Use `x` instead')
double get w => x;
@deprecated
@Deprecated('Use `y` instead')
double get h => y;
static const PdfPoint zero = PdfPoint(0.0, 0.0);
... ...
... ... @@ -41,17 +41,22 @@ class PdfRect {
double get horizondalCenter => x + width / 2;
double get verticalCenter => y + height / 2;
@deprecated
@Deprecated('Use `left` instead')
double get l => left;
@deprecated
@Deprecated('Use `bottom` instead')
double get b => bottom;
@deprecated
@Deprecated('Use `right` instead')
double get r => right;
@deprecated
@Deprecated('Use `top` instead')
double get t => top;
@deprecated
@Deprecated('Use `width` instead')
double get w => width;
@deprecated
@Deprecated('Use `height` instead')
double get h => height;
@override
... ...
... ... @@ -343,7 +343,7 @@ class TextStyle {
);
}
@Deprecated('use font instead')
@Deprecated('use `font` instead')
Font get paintFont => font;
Font get font {
... ...
... ... @@ -16,7 +16,7 @@
part of printing;
@deprecated
@Deprecated('Use `Document` instead')
class PdfDoc extends Document {
/// Wrapper for a [Document] with zlib compression enabled by default
PdfDoc(
... ...