mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-06-27 02:25:47 +02:00
Merge pull request #20996 from Snuffleupagus/more-logical-assignment
Use more logical assignment in the code-base
This commit is contained in:
commit
37f5902c3c
@ -158,7 +158,7 @@ const PDFViewerApplication = {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let pdfTitle;
|
let pdfTitle;
|
||||||
if (metadata && metadata.has("dc:title")) {
|
if (metadata?.has("dc:title")) {
|
||||||
const title = metadata.get("dc:title");
|
const title = metadata.get("dc:title");
|
||||||
// Ghostscript sometimes returns 'Untitled', so prevent setting the
|
// Ghostscript sometimes returns 'Untitled', so prevent setting the
|
||||||
// title to 'Untitled.
|
// title to 'Untitled.
|
||||||
@ -166,10 +166,7 @@ const PDFViewerApplication = {
|
|||||||
pdfTitle = title;
|
pdfTitle = title;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pdfTitle ||= info?.Title;
|
||||||
if (!pdfTitle && info && info.Title) {
|
|
||||||
pdfTitle = info.Title;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pdfTitle) {
|
if (pdfTitle) {
|
||||||
this.setTitle(pdfTitle + " - " + document.title);
|
this.setTitle(pdfTitle + " - " + document.title);
|
||||||
|
|||||||
@ -246,6 +246,8 @@ function createDefaultAppearance({ fontSize, fontName, fontColor }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class FakeUnicodeFont {
|
class FakeUnicodeFont {
|
||||||
|
static #fontNameId = 1;
|
||||||
|
|
||||||
constructor(xref, fontFamily) {
|
constructor(xref, fontFamily) {
|
||||||
this.xref = xref;
|
this.xref = xref;
|
||||||
this.widths = null;
|
this.widths = null;
|
||||||
@ -256,11 +258,8 @@ class FakeUnicodeFont {
|
|||||||
const canvas = new OffscreenCanvas(1, 1);
|
const canvas = new OffscreenCanvas(1, 1);
|
||||||
this.ctxMeasure = canvas.getContext("2d", { willReadFrequently: true });
|
this.ctxMeasure = canvas.getContext("2d", { willReadFrequently: true });
|
||||||
|
|
||||||
if (!FakeUnicodeFont._fontNameId) {
|
|
||||||
FakeUnicodeFont._fontNameId = 1;
|
|
||||||
}
|
|
||||||
this.fontName = Name.get(
|
this.fontName = Name.get(
|
||||||
`InvalidPDFjsFont_${fontFamily}_${FakeUnicodeFont._fontNameId++}`
|
`InvalidPDFjsFont_${fontFamily}_${FakeUnicodeFont.#fontNameId++}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1677,11 +1677,7 @@ class SimpleSegmentVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Combines exported symbols from all referred segments
|
// Combines exported symbols from all referred segments
|
||||||
let symbols = this.symbols;
|
const symbols = (this.symbols ||= {});
|
||||||
if (!symbols) {
|
|
||||||
this.symbols = symbols = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
const inputSymbols = [];
|
const inputSymbols = [];
|
||||||
for (const referredSegment of referredSegments) {
|
for (const referredSegment of referredSegments) {
|
||||||
const referredSymbols = symbols[referredSegment];
|
const referredSymbols = symbols[referredSegment];
|
||||||
@ -1766,10 +1762,7 @@ class SimpleSegmentVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onPatternDictionary(dictionary, currentSegment, data, start, end) {
|
onPatternDictionary(dictionary, currentSegment, data, start, end) {
|
||||||
let patterns = this.patterns;
|
const patterns = (this.patterns ||= {});
|
||||||
if (!patterns) {
|
|
||||||
this.patterns = patterns = {};
|
|
||||||
}
|
|
||||||
const decodingContext = new DecodingContext(data, start, end);
|
const decodingContext = new DecodingContext(data, start, end);
|
||||||
patterns[currentSegment] = decodePatternDictionary(
|
patterns[currentSegment] = decodePatternDictionary(
|
||||||
dictionary.mmr,
|
dictionary.mmr,
|
||||||
@ -1811,10 +1804,7 @@ class SimpleSegmentVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onTables(currentSegment, data, start, end) {
|
onTables(currentSegment, data, start, end) {
|
||||||
let customTables = this.customTables;
|
const customTables = (this.customTables ||= {});
|
||||||
if (!customTables) {
|
|
||||||
this.customTables = customTables = {};
|
|
||||||
}
|
|
||||||
customTables[currentSegment] = decodeTablesSegment(data, start, end);
|
customTables[currentSegment] = decodeTablesSegment(data, start, end);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1865,10 +1855,7 @@ class HuffmanTreeNode {
|
|||||||
this.children[bit] = new HuffmanTreeNode(line);
|
this.children[bit] = new HuffmanTreeNode(line);
|
||||||
} else {
|
} else {
|
||||||
// Create an intermediate node and continue recursively.
|
// Create an intermediate node and continue recursively.
|
||||||
let node = this.children[bit];
|
const node = (this.children[bit] ||= new HuffmanTreeNode(null));
|
||||||
if (!node) {
|
|
||||||
this.children[bit] = node = new HuffmanTreeNode(null);
|
|
||||||
}
|
|
||||||
node.buildTree(line, shift - 1);
|
node.buildTree(line, shift - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -110,9 +110,7 @@ class FontSelector {
|
|||||||
"size",
|
"size",
|
||||||
"letterSpacing",
|
"letterSpacing",
|
||||||
]) {
|
]) {
|
||||||
if (!xfaFont[name]) {
|
xfaFont[name] ||= lastFont.xfaFont[name];
|
||||||
xfaFont[name] = lastFont.xfaFont[name];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const name of ["top", "bottom", "left", "right"]) {
|
for (const name of ["top", "bottom", "left", "right"]) {
|
||||||
@ -127,9 +125,7 @@ class FontSelector {
|
|||||||
lineHeight || lastFont.lineHeight,
|
lineHeight || lastFont.lineHeight,
|
||||||
this.fontFinder
|
this.fontFinder
|
||||||
);
|
);
|
||||||
if (!fontInfo.pdfFont) {
|
fontInfo.pdfFont ||= lastFont.pdfFont;
|
||||||
fontInfo.pdfFont = lastFont.pdfFont;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.stack.push(fontInfo);
|
this.stack.push(fontInfo);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -199,9 +199,7 @@ class CanvasContextDetailsView {
|
|||||||
if (type !== "2d") {
|
if (type !== "2d") {
|
||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
if (!wrappedCtx) {
|
wrappedCtx ??= this.wrapContext(ctx, label);
|
||||||
wrappedCtx = this.wrapContext(ctx, label);
|
|
||||||
}
|
|
||||||
return wrappedCtx;
|
return wrappedCtx;
|
||||||
};
|
};
|
||||||
return canvas.getContext("2d");
|
return canvas.getContext("2d");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user