David PHAM-VAN

Run dartfmt on sources

* Add example
... ...
... ... @@ -64,4 +64,3 @@ part 'src/stream.dart';
part 'src/ttffont.dart';
part 'src/xobject.dart';
part 'src/xref.dart';
... ...
... ... @@ -59,7 +59,18 @@ class PDFAnnot extends PDFObject {
PDFBorder border;
PDFAnnot(PDFPage pdfPage,
{String type, this.s, this.l, this.b, this.r, this.t, this.subtype, this.dest, this.fl, this.fb, this.fr, this.ft})
{String type,
this.s,
this.l,
this.b,
this.r,
this.t,
this.subtype,
this.dest,
this.fl,
this.fb,
this.fr,
this.ft})
: super(pdfPage.pdfDocument, type) {
pdfPage.annotations.add(this);
}
... ... @@ -70,7 +81,8 @@ class PDFAnnot extends PDFObject {
/// @param b Bottom coordinate
/// @param r Right coordinate
/// @param t Top coordinate
factory PDFAnnot.annotation(PDFPage pdfPage, String s, double l, double b, double r, double t) =>
factory PDFAnnot.annotation(
PDFPage pdfPage, String s, double l, double b, double r, double t) =>
new PDFAnnot(pdfPage, type: "/Annot", s: s, l: l, b: b, r: r, t: t);
/// Creates a text annotation
... ... @@ -94,9 +106,14 @@ class PDFAnnot extends PDFObject {
/// @param ft Top coordinate
/// <br><br>Rectangle describing what part of the page to be displayed
/// (must be in User Coordinates)
factory PDFAnnot.link(PDFPage pdfPage, double l, double b, double r, double t, PDFObject dest,
[double fl = FULL_PAGE, double fb = FULL_PAGE, double fr = FULL_PAGE, double ft = FULL_PAGE]) =>
new PDFAnnot(pdfPage, type: "/Link", l: l, b: b, r: r, t: t, dest: dest, fl: fl, fb: fb, fr: fr, ft: ft);
factory PDFAnnot.link(
PDFPage pdfPage, double l, double b, double r, double t, PDFObject dest,
[double fl = FULL_PAGE,
double fb = FULL_PAGE,
double fr = FULL_PAGE,
double ft = FULL_PAGE]) =>
new PDFAnnot(pdfPage,
type: "/Link", l: l, b: b, r: r, t: t, dest: dest, fl: fl, fb: fb, fr: fr, ft: ft);
/// Sets the border for the annotation. By default, no border is defined.
///
... ...
... ... @@ -36,7 +36,8 @@ 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 = 0, this.dash}) : super(pdfDocument);
PDFBorder(PDFDocument pdfDocument, this.width, {this.style = 0, this.dash})
: super(pdfDocument);
/// @param os OutputStream to send the object to
@override
... ...
... ... @@ -34,7 +34,8 @@ class PDFCatalog extends PDFObject {
/// of the documents page tree
/// @param pagemode How the document should appear when opened.
/// Allowed values are USENONE, USEOUTLINES, USETHUMBS or FULLSCREEN.
PDFCatalog(PDFDocument pdfDocument, this.pdfPageList, this.pageMode) : super(pdfDocument, "/Catalog");
PDFCatalog(PDFDocument pdfDocument, this.pdfPageList, this.pageMode)
: super(pdfDocument, "/Catalog");
/// @param os OutputStream to send the object to
@override
... ...
... ... @@ -29,8 +29,8 @@ class PDFColor {
PDFColor(this.r, this.g, this.b, [this.a = 1.0]);
factory PDFColor.fromInt(int color) {
return new PDFColor(
(color >> 16 & 0xff) / 255.0, (color >> 8 & 0xff) / 255.0, (color & 0xff) / 255.0, (color >> 24 & 0xff) / 255.0);
return new PDFColor((color >> 16 & 0xff) / 255.0, (color >> 8 & 0xff) / 255.0,
(color & 0xff) / 255.0, (color >> 24 & 0xff) / 255.0);
}
factory PDFColor.fromHex(String color) {
... ... @@ -43,8 +43,8 @@ class PDFColor {
int toInt() =>
((((a * 255.0).round() & 0xff) << 24) |
(((r * 255.0).round() & 0xff) << 16) |
(((g * 255.0).round() & 0xff) << 8) |
(((b * 255.0).round() & 0xff) << 0)) &
(((r * 255.0).round() & 0xff) << 16) |
(((g * 255.0).round() & 0xff) << 8) |
(((b * 255.0).round() & 0xff) << 0)) &
0xFFFFFFFF;
}
... ...
... ... @@ -72,7 +72,12 @@ class PDFDocument {
/// <p>
/// These map the page modes just defined to the pagemodes setting of PDF.
/// </p>
static const _PDF_PAGE_MODES = const ["/UseNone", "/UseOutlines", "/UseThumbs", "/FullScreen"];
static const _PDF_PAGE_MODES = const [
"/UseNone",
"/UseOutlines",
"/UseThumbs",
"/FullScreen"
];
/// This holds the current fonts
final Set<PDFFont> fonts = new Set<PDFFont>();
... ...
... ... @@ -32,7 +32,8 @@ class PDFFont extends PDFObject {
/// @param type The pdf type, ie /Type1
/// @param font The font name, ie Helvetica
/// @param style The java.awt.Font style, ie: Font.PLAIN
PDFFont(PDFDocument pdfDocument, {this.subtype = "/Type1", this.baseFont = "/Helvetica"}) : super(pdfDocument, "/Font") {
PDFFont(PDFDocument pdfDocument, {this.subtype = "/Type1", this.baseFont = "/Helvetica"})
: super(pdfDocument, "/Font") {
pdfDocument.fonts.add(this);
}
... ...
... ... @@ -23,7 +23,8 @@ class PDFFontDescriptor extends PDFObject {
final TtfFont font;
final PDFTTFFont ttfFont;
PDFFontDescriptor(this.ttfFont, this.file, this.font) : super(ttfFont.pdfDocument, "/FontDescriptor");
PDFFontDescriptor(this.ttfFont, this.file, this.font)
: super(ttfFont.pdfDocument, "/FontDescriptor");
@override
void prepare() {
... ... @@ -32,7 +33,8 @@ class PDFFontDescriptor extends PDFObject {
params["/FontName"] = PDFStream.string(ttfFont.baseFont);
params["/FontFile2"] = file.ref();
params["/Flags"] = PDFStream.intNum(32);
params["/FontBBox"] = new PDFStream()..putStringArray([font.head.xMin, font.head.yMin, font.head.xMax, font.head.yMax]);
params["/FontBBox"] = new PDFStream()
..putStringArray([font.head.xMin, font.head.yMin, font.head.xMax, font.head.yMax]);
params["/Ascent"] = PDFStream.intNum(font.hhea.ascent);
params["/Descent"] = PDFStream.intNum(font.hhea.descent);
params["/ItalicAngle"] = PDFStream.intNum(0);
... ...
... ... @@ -33,7 +33,8 @@ class PDFFormXObject extends PDFXObject {
/// set matrix
void setMatrix(Matrix4 t) {
var s = t.storage;
params["/Matrix"] = PDFStream.string("[${s[0]} ${s[1]} ${s[4]} ${s[5]} ${s[12]} ${s[13]}]");
params["/Matrix"] =
PDFStream.string("[${s[0]} ${s[1]} ${s[4]} ${s[5]} ${s[12]} ${s[13]}]");
}
@override
... ...
... ... @@ -174,8 +174,7 @@ class PDFGraphics {
///
/// @param c Color to use
void setColor(PDFColor color) {
buf.putString("${color.r} ${color.g} ${color.b} rg ${color.r} ${color.g} ${color
.b} RG\n");
buf.putString("${color.r} ${color.g} ${color.b} rg ${color.r} ${color.g} ${color.b} RG\n");
}
/// Set the transformation Matrix
... ...
... ... @@ -26,7 +26,8 @@ class PDFInfo extends PDFObject {
String keywords;
/// @param title Title of this document
PDFInfo(PDFDocument pdfDocument, {this.title, this.author, this.creator, this.subject, this.keywords})
PDFInfo(PDFDocument pdfDocument,
{this.title, this.author, this.creator, this.subject, this.keywords})
: super(pdfDocument, null) {
params["/Producer"] = PDFStream.text("dpdf - David PHAM-VAN");
}
... ...
... ... @@ -76,7 +76,8 @@ class PDFOutline extends PDFObject {
PDFOutline add({String title, PDFPage dest, double x, y, w, h}) {
var xy1 = dest.cxy(x, y + h);
var xy2 = dest.cxy(x + w, y);
PDFOutline outline = new PDFOutline(pdfDocument, title: title, dest: dest, l: xy1.w, b: xy1.h, r: xy2.w, t: xy2.h);
PDFOutline outline = new PDFOutline(pdfDocument,
title: title, dest: dest, l: xy1.w, b: xy1.h, r: xy2.w, t: xy2.h);
// Tell the outline of ourselves
outline.parent = this;
return outline;
... ...
... ... @@ -48,7 +48,8 @@ class PDFPage extends PDFObject {
/// @see PageFormat#LANDSCAPE
/// @see PageFormat#REVERSE_LANDSCAPE
/// @param pageFormat PageFormat describing the page size
PDFPage(PDFDocument pdfDocument, {int orientation, this.pageFormat}) : super(pdfDocument, "/Page") {
PDFPage(PDFDocument pdfDocument, {int orientation, this.pageFormat})
: super(pdfDocument, "/Page") {
pdfDocument.pdfPageList.pages.add(this);
if (pageFormat == null) pageFormat = new PDFPageFormat();
setOrientation(orientation);
... ... @@ -132,12 +133,16 @@ class PDFPage extends PDFObject {
/// @param vh Height of the view area
/// @return Returns the annotation, so other settings can be changed.
PDFAnnot addLink(double x, y, w, h, PDFObject dest,
[double vx = PDFAnnot.FULL_PAGE, vy = PDFAnnot.FULL_PAGE, vw = PDFAnnot.FULL_PAGE, vh = PDFAnnot.FULL_PAGE]) {
[double vx = PDFAnnot.FULL_PAGE,
vy = PDFAnnot.FULL_PAGE,
vw = PDFAnnot.FULL_PAGE,
vh = PDFAnnot.FULL_PAGE]) {
var xy1 = cxy(x, y + h);
var xy2 = cxy(x + w, y);
var xy3 = cxy(vx, vy + vh);
var xy4 = cxy(vx + vw, vy);
PDFAnnot ob = new PDFAnnot.link(this, xy1.w, xy1.h, xy2.w, xy2.h, dest, xy3.w, xy3.h, xy4.w, xy4.h);
PDFAnnot ob =
new PDFAnnot.link(this, xy1.w, xy1.h, xy2.w, xy2.h, dest, xy3.w, xy3.h, xy4.w, xy4.h);
return ob;
}
... ... @@ -152,7 +157,8 @@ class PDFPage extends PDFObject {
PDFOutline addOutline(String title, {double x, double y, double w, double h}) {
PDFPoint xy1 = cxy(x, y + h);
PDFPoint xy2 = cxy(x + w, y);
PDFOutline outline = new PDFOutline(pdfDocument, title: title, dest: this, l: xy1.w, b: xy1.h, r: xy2.w, t: xy2.h);
PDFOutline outline = new PDFOutline(pdfDocument,
title: title, dest: this, l: xy1.w, b: xy1.h, r: xy2.w, t: xy2.h);
pdfDocument.outline.outlines.add(outline);
return outline;
}
... ... @@ -166,7 +172,8 @@ class PDFPage extends PDFObject {
params["/Parent"] = pdfDocument.pdfPageList.ref();
// the /MediaBox for the page size
params["/MediaBox"] = new PDFStream()..putStringArray([0, 0, pageFormat.getWidth(), pageFormat.getHeight()]);
params["/MediaBox"] = new PDFStream()
..putStringArray([0, 0, pageFormat.getWidth(), pageFormat.getHeight()]);
// Rotation (if not zero)
// if(rotate!=0) {
... ...
... ... @@ -119,7 +119,8 @@ class PDFStream {
putString(">>");
}
static PDFStream dictionary(Map<String, PDFStream> values) => new PDFStream()..putDictionary(values);
static PDFStream dictionary(Map<String, PDFStream> values) =>
new PDFStream()..putDictionary(values);
void putObjectDictionary(Map<String, PDFObject> values) {
putString("<< ");
... ...
... ... @@ -28,7 +28,8 @@ class PDFTTFFont extends PDFFont {
int _charMax;
/// Constructs a PDFTTFFont
PDFTTFFont(PDFDocument pdfDocument, Uint8List bytes) : super(pdfDocument, subtype: "/TrueType") {
PDFTTFFont(PDFDocument pdfDocument, Uint8List bytes)
: super(pdfDocument, subtype: "/TrueType") {
_font = new TtfParser().parse(bytes);
baseFont = "/" + _font.name.fontName.replaceAll(" ", "");
... ...
... ... @@ -36,7 +36,8 @@ class PDFXref {
/// @return The xref in the format of the xref section in the PDF file
String ref() {
String rs = offset.toString().padLeft(10, '0') + " " + generation.toString().padLeft(5, '0');
String rs =
offset.toString().padLeft(10, '0') + " " + generation.toString().padLeft(5, '0');
if (generation == 65535) return rs + " f ";
return rs + " n ";
... ...