Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions lib/data.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
class Data {
constructor(data) {
if (data == null) {
data = [];
}
constructor(data = []) {
this.data = data;
this.pos = 0;
this.length = this.data.length;
Expand Down Expand Up @@ -88,11 +85,7 @@ class Data {

readString(length) {
const ret = [];
for (
let i = 0, end = length, asc = 0 <= end;
asc ? i < end : i > end;
asc ? i++ : i--
) {
for (let i = 0; i < length; i++) {
ret[i] = String.fromCharCode(this.readByte());
}

Expand Down Expand Up @@ -186,11 +179,7 @@ class Data {

read(bytes) {
const buf = [];
for (
let i = 0, end = bytes, asc = 0 <= end;
asc ? i < end : i > end;
asc ? i++ : i--
) {
for (let i = 0; i < bytes; i++) {
buf.push(this.readByte());
}

Expand Down
12 changes: 2 additions & 10 deletions lib/font/afm.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,7 @@ class AFMFont {

encodeText(text) {
const res = [];
for (
let i = 0, end = text.length, asc = 0 <= end;
asc ? i < end : i > end;
asc ? i++ : i--
) {
for (let i = 0, len = text.length; i < len; i++) {
let char = text.charCodeAt(i);
char = WIN_ANSI_MAP[char] || char;
res.push(char.toString(16));
Expand All @@ -197,11 +193,7 @@ class AFMFont {
glyphsForString(string) {
const glyphs = [];

for (
let i = 0, end = string.length, asc = 0 <= end;
asc ? i < end : i > end;
asc ? i++ : i--
) {
for (let i = 0, len = string.length; i < len; i++) {
const charCode = string.charCodeAt(i);
glyphs.push(this.characterToGlyph(charCode));
}
Expand Down
11 changes: 4 additions & 7 deletions lib/font/embedded.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,12 @@ class EmbeddedFont extends PDFFont {

layout(text, features, onlyWidth) {
// Skip the cache if any user defined features are applied
if (onlyWidth == null) {
onlyWidth = false;
}
if (features) {
return this.layoutRun(text, features);
}

const glyphs = onlyWidth ? null : [];
const positions = onlyWidth ? null : [];
let glyphs = onlyWidth ? null : [];
let positions = onlyWidth ? null : [];
let advanceWidth = 0;

// Split the string by words to increase cache efficiency.
Expand All @@ -83,8 +80,8 @@ class EmbeddedFont extends PDFFont {
) {
const run = this.layoutCached(text.slice(last, ++index));
if (!onlyWidth) {
glyphs.push(...(run.glyphs || []));
positions.push(...(run.positions || []));
glyphs = glyphs.concat(run.glyphs);
positions = positions.concat(run.positions);
}

advanceWidth += run.advanceWidth;
Expand Down
11 changes: 3 additions & 8 deletions lib/gradient.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ class PDFGradient {
}

embed(m) {
let asc, i;
let end, fn;
let fn;
if (this.stops.length === 0) {
return;
}
Expand All @@ -63,13 +62,9 @@ class PDFGradient {
const encode = [];
const stops = [];

for (
i = 0, end = this.stops.length - 1, asc = 0 <= end;
asc ? i < end : i > end;
asc ? i++ : i--
) {
for (let i = 0, stopsLength = this.stops.length - 1; i < stopsLength; i++) {
encode.push(0, 1);
if (i + 2 !== this.stops.length) {
if (i + 2 !== stopsLength) {
bounds.push(this.stops[i + 1][0]);
}

Expand Down
38 changes: 14 additions & 24 deletions lib/mixins/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,13 @@ export default {
},

heightOfString(text, options) {
if (options == null) {
options = {};
}
const { x, y } = this;

options = this._initOptions(options);
options.height = Infinity; // don't break pages

const lineGap = options.lineGap || this._lineGap || 0;
this._text(text, this.x, this.y, options, (line, options) => {
this._text(text, this.x, this.y, options, () => {
return (this.y += this.currentLineHeight(true) + lineGap);
});

Expand Down Expand Up @@ -205,22 +202,15 @@ export default {
}

// clone options object
options = (function() {
const opts = {};
for (let k in options) {
const v = options[k];
opts[k] = v;
}
return opts;
})();
const result = Object.assign({}, options);

// extend options with previous values for continued text
if (this._textOptions) {
for (let key in this._textOptions) {
const val = this._textOptions[key];
if (key !== 'continued') {
if (options[key] == null) {
options[key] = val;
if (result[key] == null) {
result[key] = val;
}
}
}
Expand All @@ -235,20 +225,20 @@ export default {
}

// wrap to margins if no x or y position passed
if (options.lineBreak !== false) {
if (options.width == null) {
options.width = this.page.width - this.x - this.page.margins.right;
if (result.lineBreak !== false) {
if (result.width == null) {
result.width = this.page.width - this.x - this.page.margins.right;
}
}

if (!options.columns) {
options.columns = 0;
if (!result.columns) {
result.columns = 0;
}
if (options.columnGap == null) {
options.columnGap = 18;
if (result.columnGap == null) {
result.columnGap = 18;
} // 1/4 inch

return options;
return result;
},

_line(text, options, wrapper) {
Expand Down Expand Up @@ -431,8 +421,8 @@ export default {
word,
options.features
);
encoded.push(...(encodedWord || []));
positions.push(...(positionsWord || []));
encoded = encoded.concat(encodedWord);
positions = positions.concat(positionsWord);

// add the word spacing to the end of the word
// clone object because of cache
Expand Down
6 changes: 1 addition & 5 deletions lib/mixins/vector.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,7 @@ export default {
// calculate and render segments
this.moveTo(ax, ay);

for (
let segIdx = 0, end = numSegs, asc = 0 <= end;
asc ? segIdx < end : segIdx > end;
asc ? segIdx++ : segIdx--
) {
for (let segIdx = 0; segIdx < numSegs; segIdx++) {
// starting control point
const cp1x = ax + deltaCx;
const cp1y = ay + deltaCy;
Expand Down
8 changes: 1 addition & 7 deletions lib/outline.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ class PDFOutline {
}

endOutline() {
let end;
if (this.children.length > 0) {
let asc, i;
if (this.options.expanded) {
this.outlineData.Count = this.children.length;
}
Expand All @@ -52,11 +50,7 @@ class PDFOutline {
this.outlineData.First = first.dictionary;
this.outlineData.Last = last.dictionary;

for (
i = 0, end = this.children.length, asc = 0 <= end;
asc ? i < end : i > end;
asc ? i++ : i--
) {
for (let i = 0, len = this.children.length; i < len; i++) {
const child = this.children[i];
if (i > 0) {
child.outlineData.Prev = this.children[i - 1].dictionary;
Expand Down
6 changes: 1 addition & 5 deletions lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,11 +370,7 @@ const arcToSegments = function(x, y, rx, ry, large, sweep, rotateX, ox, oy) {
const segments = Math.ceil(Math.abs(th_arc / (Math.PI * 0.5 + 0.001)));
const result = [];

for (
let i = 0, end = segments, asc = 0 <= end;
asc ? i < end : i > end;
asc ? i++ : i--
) {
for (let i = 0; i < segments; i++) {
const th2 = th0 + (i * th_arc) / segments;
const th3 = th0 + ((i + 1) * th_arc) / segments;
result[i] = [xc, yc, th2, th3, rx, ry, sin_th, cos_th];
Expand Down