ES6 syntax for default values

This commit is contained in:
Libor M 2019-03-24 13:51:47 +01:00
parent 1f5565d087
commit a2abfb4765
7 changed files with 21 additions and 87 deletions

View File

@ -26,10 +26,7 @@ export default {
return this;
},
note(x, y, w, h, contents, options) {
if (options == null) {
options = {};
}
note(x, y, w, h, contents, options = {}) {
options.Subtype = 'Text';
options.Contents = new String(contents);
options.Name = 'Comment';
@ -39,10 +36,7 @@ export default {
return this.annotate(x, y, w, h, options);
},
link(x, y, w, h, url, options) {
if (options == null) {
options = {};
}
link(x, y, w, h, url, options = {}) {
options.Subtype = 'Link';
if (typeof url === 'number') {
@ -69,20 +63,14 @@ export default {
return this.annotate(x, y, w, h, options);
},
_markup(x, y, w, h, options) {
if (options == null) {
options = {};
}
_markup(x, y, w, h, options = {}) {
const [x1, y1, x2, y2] = this._convertRect(x, y, w, h);
options.QuadPoints = [x1, y2, x2, y2, x1, y1, x2, y1];
options.Contents = new String();
return this.annotate(x, y, w, h, options);
},
highlight(x, y, w, h, options) {
if (options == null) {
options = {};
}
highlight(x, y, w, h, options = {}) {
options.Subtype = 'Highlight';
if (options.color == null) {
options.color = [241, 238, 148];
@ -90,54 +78,36 @@ export default {
return this._markup(x, y, w, h, options);
},
underline(x, y, w, h, options) {
if (options == null) {
options = {};
}
underline(x, y, w, h, options = {}) {
options.Subtype = 'Underline';
return this._markup(x, y, w, h, options);
},
strike(x, y, w, h, options) {
if (options == null) {
options = {};
}
strike(x, y, w, h, options = {}) {
options.Subtype = 'StrikeOut';
return this._markup(x, y, w, h, options);
},
lineAnnotation(x1, y1, x2, y2, options) {
if (options == null) {
options = {};
}
lineAnnotation(x1, y1, x2, y2, options = {}) {
options.Subtype = 'Line';
options.Contents = new String();
options.L = [x1, this.page.height - y1, x2, this.page.height - y2];
return this.annotate(x1, y1, x2, y2, options);
},
rectAnnotation(x, y, w, h, options) {
if (options == null) {
options = {};
}
rectAnnotation(x, y, w, h, options = {}) {
options.Subtype = 'Square';
options.Contents = new String();
return this.annotate(x, y, w, h, options);
},
ellipseAnnotation(x, y, w, h, options) {
if (options == null) {
options = {};
}
ellipseAnnotation(x, y, w, h, options = {}) {
options.Subtype = 'Circle';
options.Contents = new String();
return this.annotate(x, y, w, h, options);
},
textAnnotation(x, y, w, h, text, options) {
if (options == null) {
options = {};
}
textAnnotation(x, y, w, h, text, options = {}) {
options.Subtype = 'FreeText';
options.Contents = new String(text);
options.DA = new String();

View File

@ -6,11 +6,8 @@ export default {
return (this._imageCount = 0);
},
image(src, x, y, options) {
image(src, x, y, options = {}) {
let bh, bp, bw, image, ip, left, left1;
if (options == null) {
options = {};
}
if (typeof x === 'object') {
options = x;
x = null;

View File

@ -70,10 +70,7 @@ export default {
return this._text(text, x, y, options, this._line);
},
widthOfString(string, options) {
if (options == null) {
options = {};
}
widthOfString(string, options = {}) {
return (
this._font.widthOfString(string, this._fontSize, options.features) +
(options.characterSpacing || 0) * (string.length - 1)
@ -189,13 +186,7 @@ export default {
return this;
},
_initOptions(x, y, options) {
if (x == null) {
x = {};
}
if (options == null) {
options = {};
}
_initOptions(x = {}, y, options = {}) {
if (typeof x === 'object') {
options = x;
x = null;
@ -241,10 +232,7 @@ export default {
return result;
},
_line(text, options, wrapper) {
if (options == null) {
options = {};
}
_line(text, options = {}, wrapper) {
this._fragment(text, this.x, this.y, options);
const lineGap = options.lineGap || this._lineGap || 0;

View File

@ -61,11 +61,8 @@ export default {
return this.addContent(`${number(m)} M`);
},
dash(length, options) {
dash(length, options = {}) {
let phase;
if (options == null) {
options = {};
}
if (length == null) {
return this;
}
@ -308,11 +305,8 @@ export default {
return this.transform(1, 0, 0, 1, x, y);
},
rotate(angle, options) {
rotate(angle, options = {}) {
let y;
if (options == null) {
options = {};
}
const rad = (angle * Math.PI) / 180;
const cos = Math.cos(rad);
const sin = Math.sin(rad);
@ -329,14 +323,11 @@ export default {
return this.transform(cos, sin, -sin, cos, x, y);
},
scale(xFactor, yFactor, options) {
scale(xFactor, yFactor, options = {}) {
let y;
if (yFactor == null) {
yFactor = xFactor;
}
if (options == null) {
options = {};
}
if (typeof yFactor === 'object') {
options = yFactor;
yFactor = xFactor;

View File

@ -1,9 +1,6 @@
class PDFOutline {
constructor(document, parent, title, dest, options) {
constructor(document, parent, title, dest, options = { expanded: false }) {
this.document = document;
if (options == null) {
options = { expanded: false };
}
this.options = options;
this.outlineData = {};
@ -23,10 +20,7 @@ class PDFOutline {
this.children = [];
}
addItem(title, options) {
if (options == null) {
options = { expanded: false };
}
addItem(title, options = { expanded: false }) {
const result = new PDFOutline(
this.document,
this.dictionary,

View File

@ -64,11 +64,8 @@ const SIZES = {
};
class PDFPage {
constructor(document, options) {
constructor(document, options = {}) {
this.document = document;
if (options == null) {
options = {};
}
this.size = options.size || 'letter';
this.layout = options.layout || 'portrait';

View File

@ -8,13 +8,10 @@ import PDFAbstractReference from './abstract_reference';
import PDFObject from './object';
class PDFReference extends PDFAbstractReference {
constructor(document, id, data) {
constructor(document, id, data = {}) {
super();
this.document = document;
this.id = id;
if (data == null) {
data = {};
}
this.data = data;
this.gen = 0;
this.compress = this.document.compress && !this.data.Filter;