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