mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-07-13 02:25:47 +02:00
Use for...of even more in the code-base
This replaces a couple of "standard" `for` loops with the shorter `for...of` format instead.
This commit is contained in:
parent
c4574a5470
commit
c46720d893
@ -4792,19 +4792,19 @@ class InkAnnotation extends MarkupAnnotation {
|
|||||||
if (!Array.isArray(rawInkLists)) {
|
if (!Array.isArray(rawInkLists)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (let i = 0, ii = rawInkLists.length; i < ii; ++i) {
|
for (const rawInkList of rawInkLists) {
|
||||||
// The raw ink lists array contains arrays of numbers representing
|
// The raw ink lists array contains arrays of numbers representing
|
||||||
// the alternating horizontal and vertical coordinates, respectively,
|
// the alternating horizontal and vertical coordinates, respectively,
|
||||||
// of each vertex. Convert this to an array of objects with x and y
|
// of each vertex. Convert this to an array of objects with x and y
|
||||||
// coordinates.
|
// coordinates.
|
||||||
if (!Array.isArray(rawInkLists[i])) {
|
if (!Array.isArray(rawInkList)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const inkList = new Float32Array(rawInkLists[i].length);
|
const inkList = new Float32Array(rawInkList.length);
|
||||||
this.data.inkLists.push(inkList);
|
this.data.inkLists.push(inkList);
|
||||||
for (let j = 0, jj = rawInkLists[i].length; j < jj; j += 2) {
|
for (let j = 0, jj = rawInkList.length; j < jj; j += 2) {
|
||||||
const x = xref.fetchIfRef(rawInkLists[i][j]),
|
const x = xref.fetchIfRef(rawInkList[j]),
|
||||||
y = xref.fetchIfRef(rawInkLists[i][j + 1]);
|
y = xref.fetchIfRef(rawInkList[j + 1]);
|
||||||
if (typeof x === "number" && typeof y === "number") {
|
if (typeof x === "number" && typeof y === "number") {
|
||||||
inkList[j] = x;
|
inkList[j] = x;
|
||||||
inkList[j + 1] = y;
|
inkList[j + 1] = y;
|
||||||
|
|||||||
@ -200,8 +200,7 @@ async function createImage(bitmap, xref, { closeBitmap = false } = {}) {
|
|||||||
const colorCounter = new Set();
|
const colorCounter = new Set();
|
||||||
let hasAlpha = false;
|
let hasAlpha = false;
|
||||||
let useFlate = true;
|
let useFlate = true;
|
||||||
for (let i = 0, ii = buf32.length; i < ii; i++) {
|
for (const v of buf32) {
|
||||||
const v = buf32[i];
|
|
||||||
if ((isLE ? v >>> 24 : v & 0xff) !== 0xff) {
|
if ((isLE ? v >>> 24 : v & 0xff) !== 0xff) {
|
||||||
hasAlpha = true;
|
hasAlpha = true;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -3273,9 +3273,7 @@ class PartialEvaluator {
|
|||||||
|
|
||||||
const spaceFactor =
|
const spaceFactor =
|
||||||
((textState.font.vertical ? 1 : -1) * textState.fontSize) / 1000;
|
((textState.font.vertical ? 1 : -1) * textState.fontSize) / 1000;
|
||||||
const elements = args[0];
|
for (const item of args[0]) {
|
||||||
for (let i = 0, ii = elements.length; i < ii; i++) {
|
|
||||||
const item = elements[i];
|
|
||||||
if (typeof item === "string") {
|
if (typeof item === "string") {
|
||||||
showSpacedTextBuffer.push(item);
|
showSpacedTextBuffer.push(item);
|
||||||
} else if (typeof item === "number" && item !== 0) {
|
} else if (typeof item === "number" && item !== 0) {
|
||||||
|
|||||||
@ -1525,9 +1525,9 @@ class Font {
|
|||||||
}
|
}
|
||||||
const [nameTable] = readNameTable(potentialTables.name);
|
const [nameTable] = readNameTable(potentialTables.name);
|
||||||
|
|
||||||
for (let j = 0, jj = nameTable.length; j < jj; j++) {
|
for (const nameArr of nameTable) {
|
||||||
for (let k = 0, kk = nameTable[j].length; k < kk; k++) {
|
for (const entry of nameArr) {
|
||||||
const nameEntry = nameTable[j][k]?.replaceAll(/\s/g, "");
|
const nameEntry = entry?.replaceAll(/\s/g, "");
|
||||||
if (!nameEntry) {
|
if (!nameEntry) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3517,10 +3517,10 @@ class InkAnnotationElement extends AnnotationElement {
|
|||||||
g.setAttribute("fill", "transparent");
|
g.setAttribute("fill", "transparent");
|
||||||
g.setAttribute("transform", transform);
|
g.setAttribute("transform", transform);
|
||||||
|
|
||||||
for (let i = 0, ii = inkLists.length; i < ii; i++) {
|
for (const inkList of inkLists) {
|
||||||
const polyline = this.svgFactory.createElement(this.svgElementName);
|
const polyline = this.svgFactory.createElement(this.svgElementName);
|
||||||
this.#polylines.push(polyline);
|
this.#polylines.push(polyline);
|
||||||
polyline.setAttribute("points", inkLists[i].join(","));
|
polyline.setAttribute("points", inkList.join(","));
|
||||||
g.append(polyline);
|
g.append(polyline);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -517,8 +517,7 @@ class Stepper {
|
|||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
for (let i = 0; i < operatorsGroupsByZindex.length; i++) {
|
for (const group of operatorsGroupsByZindex) {
|
||||||
const group = operatorsGroupsByZindex[i];
|
|
||||||
if (group.minX !== null) {
|
if (group.minX !== null) {
|
||||||
const el = this.#c("div");
|
const el = this.#c("div");
|
||||||
el.style.left = `${group.minX * 100}%`;
|
el.style.left = `${group.minX * 100}%`;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user