mirror of
https://github.com/foliojs/pdfkit.git
synced 2025-12-08 20:15:54 +00:00
Merge pull request #939 from blikblum/cleanup
Cleanup remaining artifacts from CoffeScript conversion
This commit is contained in:
commit
a704eda4f1
17
lib/data.js
17
lib/data.js
@ -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;
|
||||
@ -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());
|
||||
}
|
||||
|
||||
@ -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());
|
||||
}
|
||||
|
||||
|
||||
@ -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));
|
||||
@ -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));
|
||||
}
|
||||
|
||||
@ -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.
|
||||
@ -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;
|
||||
|
||||
@ -45,8 +45,7 @@ class PDFGradient {
|
||||
}
|
||||
|
||||
embed(m) {
|
||||
let asc, i;
|
||||
let end, fn;
|
||||
let fn;
|
||||
if (this.stops.length === 0) {
|
||||
return;
|
||||
}
|
||||
@ -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]);
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
});
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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) {
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
}
|
||||
@ -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;
|
||||
|
||||
@ -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];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user