Merge pull request #16424 from Snuffleupagus/core-optional-chaining
Introduce more optional chaining in the `src/core/` folder
This commit is contained in:
commit
ac8032628b
@ -560,10 +560,9 @@ class Annotation {
|
||||
* @param {AnnotationStorage} [annotationStorage] - Storage for annotation
|
||||
*/
|
||||
mustBeViewed(annotationStorage) {
|
||||
const storageEntry =
|
||||
annotationStorage && annotationStorage.get(this.data.id);
|
||||
if (storageEntry && storageEntry.hidden !== undefined) {
|
||||
return !storageEntry.hidden;
|
||||
const hidden = annotationStorage?.get(this.data.id)?.hidden;
|
||||
if (hidden !== undefined) {
|
||||
return !hidden;
|
||||
}
|
||||
return this.viewable && !this._hasFlag(this.flags, AnnotationFlag.HIDDEN);
|
||||
}
|
||||
@ -578,10 +577,9 @@ class Annotation {
|
||||
* @param {AnnotationStorage} [annotationStorage] - Storage for annotation
|
||||
*/
|
||||
mustBePrinted(annotationStorage) {
|
||||
const storageEntry =
|
||||
annotationStorage && annotationStorage.get(this.data.id);
|
||||
if (storageEntry && storageEntry.print !== undefined) {
|
||||
return storageEntry.print;
|
||||
const print = annotationStorage?.get(this.data.id)?.print;
|
||||
if (print !== undefined) {
|
||||
return print;
|
||||
}
|
||||
return this.printable;
|
||||
}
|
||||
@ -1566,8 +1564,7 @@ class WidgetAnnotation extends Annotation {
|
||||
|
||||
const localResources = getInheritableProperty({ dict, key: "DR" });
|
||||
const acroFormResources = params.acroForm.get("DR");
|
||||
const appearanceResources =
|
||||
this.appearance && this.appearance.dict.get("Resources");
|
||||
const appearanceResources = this.appearance?.dict.get("Resources");
|
||||
|
||||
this._fieldResources = {
|
||||
localResources,
|
||||
@ -1627,10 +1624,7 @@ class WidgetAnnotation extends Annotation {
|
||||
}
|
||||
|
||||
getRotationMatrix(annotationStorage) {
|
||||
const storageEntry = annotationStorage
|
||||
? annotationStorage.get(this.data.id)
|
||||
: undefined;
|
||||
let rotation = storageEntry && storageEntry.rotation;
|
||||
let rotation = annotationStorage?.get(this.data.id)?.rotation;
|
||||
if (rotation === undefined) {
|
||||
rotation = this.rotation;
|
||||
}
|
||||
@ -1646,10 +1640,7 @@ class WidgetAnnotation extends Annotation {
|
||||
}
|
||||
|
||||
getBorderAndBackgroundAppearances(annotationStorage) {
|
||||
const storageEntry = annotationStorage
|
||||
? annotationStorage.get(this.data.id)
|
||||
: undefined;
|
||||
let rotation = storageEntry && storageEntry.rotation;
|
||||
let rotation = annotationStorage?.get(this.data.id)?.rotation;
|
||||
if (rotation === undefined) {
|
||||
rotation = this.rotation;
|
||||
}
|
||||
@ -1799,11 +1790,9 @@ class WidgetAnnotation extends Annotation {
|
||||
amendSavedDict(annotationStorage, dict) {}
|
||||
|
||||
async save(evaluator, task, annotationStorage) {
|
||||
const storageEntry = annotationStorage
|
||||
? annotationStorage.get(this.data.id)
|
||||
: undefined;
|
||||
let value = storageEntry && storageEntry.value;
|
||||
let rotation = storageEntry && storageEntry.rotation;
|
||||
const storageEntry = annotationStorage?.get(this.data.id);
|
||||
let value = storageEntry?.value,
|
||||
rotation = storageEntry?.rotation;
|
||||
if (value === this.data.fieldValue || value === undefined) {
|
||||
if (!this._hasValueFromXFA && rotation === undefined) {
|
||||
return null;
|
||||
@ -1845,7 +1834,7 @@ class WidgetAnnotation extends Annotation {
|
||||
}
|
||||
|
||||
let needAppearances = false;
|
||||
if (appearance && appearance.needAppearances) {
|
||||
if (appearance?.needAppearances) {
|
||||
needAppearances = true;
|
||||
appearance = null;
|
||||
}
|
||||
@ -1949,10 +1938,7 @@ class WidgetAnnotation extends Annotation {
|
||||
if (isPassword) {
|
||||
return null;
|
||||
}
|
||||
const storageEntry = annotationStorage
|
||||
? annotationStorage.get(this.data.id)
|
||||
: undefined;
|
||||
|
||||
const storageEntry = annotationStorage?.get(this.data.id);
|
||||
let value, rotation;
|
||||
if (storageEntry) {
|
||||
value = storageEntry.formattedValue || storageEntry.value;
|
||||
@ -1993,7 +1979,7 @@ class WidgetAnnotation extends Annotation {
|
||||
const option = this.data.options.find(
|
||||
({ exportValue }) => value === exportValue
|
||||
);
|
||||
value = (option && option.displayValue) || value;
|
||||
value = option?.displayValue || value;
|
||||
}
|
||||
|
||||
if (value === "") {
|
||||
@ -2383,9 +2369,7 @@ class WidgetAnnotation extends Annotation {
|
||||
const { localResources, appearanceResources, acroFormResources } =
|
||||
this._fieldResources;
|
||||
|
||||
const fontName =
|
||||
this.data.defaultAppearanceData &&
|
||||
this.data.defaultAppearanceData.fontName;
|
||||
const fontName = this.data.defaultAppearanceData?.fontName;
|
||||
if (!fontName) {
|
||||
return localResources || Dict.empty;
|
||||
}
|
||||
@ -2767,8 +2751,8 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
|
||||
return null;
|
||||
}
|
||||
const storageEntry = annotationStorage.get(this.data.id);
|
||||
let rotation = storageEntry && storageEntry.rotation;
|
||||
let value = storageEntry && storageEntry.value;
|
||||
let rotation = storageEntry?.rotation,
|
||||
value = storageEntry?.value;
|
||||
|
||||
if (rotation === undefined) {
|
||||
if (value === undefined) {
|
||||
@ -2829,8 +2813,8 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
|
||||
return null;
|
||||
}
|
||||
const storageEntry = annotationStorage.get(this.data.id);
|
||||
let rotation = storageEntry && storageEntry.rotation;
|
||||
let value = storageEntry && storageEntry.value;
|
||||
let rotation = storageEntry?.rotation,
|
||||
value = storageEntry?.value;
|
||||
|
||||
if (rotation === undefined) {
|
||||
if (value === undefined) {
|
||||
@ -3243,10 +3227,7 @@ class ChoiceWidgetAnnotation extends WidgetAnnotation {
|
||||
if (!this.hasIndices) {
|
||||
return;
|
||||
}
|
||||
const storageEntry = annotationStorage
|
||||
? annotationStorage.get(this.data.id)
|
||||
: undefined;
|
||||
let values = storageEntry && storageEntry.value;
|
||||
let values = annotationStorage?.get(this.data.id)?.value;
|
||||
if (!Array.isArray(values)) {
|
||||
values = [values];
|
||||
}
|
||||
@ -3267,10 +3248,7 @@ class ChoiceWidgetAnnotation extends WidgetAnnotation {
|
||||
}
|
||||
|
||||
let exportedValue, rotation;
|
||||
const storageEntry = annotationStorage
|
||||
? annotationStorage.get(this.data.id)
|
||||
: undefined;
|
||||
|
||||
const storageEntry = annotationStorage?.get(this.data.id);
|
||||
if (storageEntry) {
|
||||
rotation = storageEntry.rotation;
|
||||
exportedValue = storageEntry.value;
|
||||
@ -4180,10 +4158,9 @@ class HighlightAnnotation extends MarkupAnnotation {
|
||||
|
||||
const quadPoints = (this.data.quadPoints = getQuadPoints(dict, null));
|
||||
if (quadPoints) {
|
||||
const resources =
|
||||
this.appearance && this.appearance.dict.get("Resources");
|
||||
const resources = this.appearance?.dict.get("Resources");
|
||||
|
||||
if (!this.appearance || !(resources && resources.has("ExtGState"))) {
|
||||
if (!this.appearance || !resources?.has("ExtGState")) {
|
||||
if (this.appearance) {
|
||||
// Workaround for cases where there's no /ExtGState-entry directly
|
||||
// available, e.g. when the appearance stream contains a /XObject of
|
||||
|
@ -162,10 +162,10 @@ class Catalog {
|
||||
|
||||
let metadata = null;
|
||||
try {
|
||||
const suppressEncryption = !(
|
||||
this.xref.encrypt && this.xref.encrypt.encryptMetadata
|
||||
const stream = this.xref.fetch(
|
||||
streamRef,
|
||||
/* suppressEncryption = */ !this.xref.encrypt?.encryptMetadata
|
||||
);
|
||||
const stream = this.xref.fetch(streamRef, suppressEncryption);
|
||||
|
||||
if (stream instanceof BaseStream && stream.dict instanceof Dict) {
|
||||
const type = stream.dict.get("Type");
|
||||
@ -616,7 +616,7 @@ class Catalog {
|
||||
*/
|
||||
_readDests() {
|
||||
const obj = this._catDict.get("Names");
|
||||
if (obj && obj.has("Dests")) {
|
||||
if (obj?.has("Dests")) {
|
||||
return new NameTree(obj.getRaw("Dests"), this.xref);
|
||||
} else if (this._catDict.has("Dests")) {
|
||||
// Simple destination dictionary.
|
||||
|
@ -942,7 +942,7 @@ class CCITTFaxDecoder {
|
||||
if (this.eoblock) {
|
||||
code = this._lookBits(7);
|
||||
p = twoDimTable[code];
|
||||
if (p && p[0] > 0) {
|
||||
if (p?.[0] > 0) {
|
||||
this._eatBits(p[0]);
|
||||
return p[1];
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ class CFFFont {
|
||||
|
||||
if (properties.composite) {
|
||||
let invCidToGidMap;
|
||||
if (cidToGidMap && cidToGidMap.length > 0) {
|
||||
if (cidToGidMap?.length > 0) {
|
||||
invCidToGidMap = Object.create(null);
|
||||
for (let i = 0, ii = cidToGidMap.length; i < ii; i++) {
|
||||
const gid = cidToGidMap[i];
|
||||
@ -74,7 +74,7 @@ class CFFFont {
|
||||
const cid = charsets[glyphId];
|
||||
charCode = cMap.charCodeOf(cid);
|
||||
|
||||
if (invCidToGidMap && invCidToGidMap[charCode] !== undefined) {
|
||||
if (invCidToGidMap?.[charCode] !== undefined) {
|
||||
// According to the PDF specification, see Table 117, it's not clear
|
||||
// that a /CIDToGIDMap should be used with any non-TrueType fonts,
|
||||
// however it's necessary to do so in order to fix issue 15559.
|
||||
|
@ -1428,7 +1428,7 @@ class CFFCompiler {
|
||||
}
|
||||
|
||||
const xuid = cff.topDict.getByName("XUID");
|
||||
if (xuid && xuid.length > 16) {
|
||||
if (xuid?.length > 16) {
|
||||
// Length of XUID array must not be greater than 16 (issue #12399).
|
||||
cff.topDict.removeByName("XUID");
|
||||
}
|
||||
|
@ -505,7 +505,7 @@ function recoverJsURL(str) {
|
||||
);
|
||||
|
||||
const jsUrl = regex.exec(str);
|
||||
if (jsUrl && jsUrl[2]) {
|
||||
if (jsUrl?.[2]) {
|
||||
const url = jsUrl[2];
|
||||
let newWindow = false;
|
||||
|
||||
|
@ -1698,7 +1698,7 @@ const CipherTransformFactory = (function CipherTransformFactoryClosure() {
|
||||
if (cfDict instanceof Dict && streamCryptoName instanceof Name) {
|
||||
cfDict.suppressEncryption = true; // See comment below.
|
||||
const handlerDict = cfDict.get(streamCryptoName.name);
|
||||
keyLength = (handlerDict && handlerDict.get("Length")) || 128;
|
||||
keyLength = handlerDict?.get("Length") || 128;
|
||||
if (keyLength < 40) {
|
||||
// Sometimes it's incorrect value of bits, generators specify
|
||||
// bytes.
|
||||
|
@ -69,7 +69,7 @@ class DatasetReader {
|
||||
}
|
||||
|
||||
const first = node.firstChild;
|
||||
if (first && first.nodeName === "value") {
|
||||
if (first?.nodeName === "value") {
|
||||
return node.children.map(child => decodeString(child.textContent));
|
||||
}
|
||||
|
||||
|
@ -149,7 +149,7 @@ class StreamsSequenceStream extends DecodeStream {
|
||||
chunk = stream.getBytes();
|
||||
} catch (reason) {
|
||||
if (this._onError) {
|
||||
this._onError(reason, stream.dict && stream.dict.objId);
|
||||
this._onError(reason, stream.dict?.objId);
|
||||
return;
|
||||
}
|
||||
throw reason;
|
||||
|
@ -41,7 +41,7 @@ class DecryptStream extends DecodeStream {
|
||||
return;
|
||||
}
|
||||
this.nextChunk = this.str.getBytes(chunkSize);
|
||||
const hasMoreData = this.nextChunk && this.nextChunk.length > 0;
|
||||
const hasMoreData = this.nextChunk?.length > 0;
|
||||
|
||||
const decrypt = this.decrypt;
|
||||
chunk = decrypt(chunk, !hasMoreData);
|
||||
|
@ -1421,7 +1421,7 @@ class PDFDocument {
|
||||
const { catalog, linearization, xref } = this;
|
||||
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
|
||||
assert(
|
||||
linearization && linearization.pageFirst === pageIndex,
|
||||
linearization?.pageFirst === pageIndex,
|
||||
"_getLinearizationPage - invalid pageIndex argument."
|
||||
);
|
||||
}
|
||||
@ -1466,7 +1466,7 @@ class PDFDocument {
|
||||
let promise;
|
||||
if (xfaFactory) {
|
||||
promise = Promise.resolve([Dict.empty, null]);
|
||||
} else if (linearization && linearization.pageFirst === pageIndex) {
|
||||
} else if (linearization?.pageFirst === pageIndex) {
|
||||
promise = this._getLinearizationPage(pageIndex);
|
||||
} else {
|
||||
promise = catalog.getPageDict(pageIndex);
|
||||
@ -1630,7 +1630,7 @@ class PDFDocument {
|
||||
this._localIdFactory,
|
||||
/* collectFields */ true
|
||||
)
|
||||
.then(annotation => annotation && annotation.getFieldObject())
|
||||
.then(annotation => annotation?.getFieldObject())
|
||||
.catch(function (reason) {
|
||||
warn(`_collectFieldObjects: "${reason}".`);
|
||||
return null;
|
||||
|
@ -172,11 +172,7 @@ function normalizeBlendMode(value, parsingArray = false) {
|
||||
}
|
||||
|
||||
function incrementCachedImageMaskCount(data) {
|
||||
if (
|
||||
data.fn === OPS.paintImageMaskXObject &&
|
||||
data.args[0] &&
|
||||
data.args[0].count > 0
|
||||
) {
|
||||
if (data.fn === OPS.paintImageMaskXObject && data.args[0]?.count > 0) {
|
||||
data.args[0].count++;
|
||||
}
|
||||
}
|
||||
@ -517,7 +513,7 @@ class PartialEvaluator {
|
||||
}
|
||||
}
|
||||
|
||||
if (smask && smask.backdrop) {
|
||||
if (smask?.backdrop) {
|
||||
colorSpace ||= ColorSpace.singletons.rgb;
|
||||
smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
|
||||
}
|
||||
@ -623,7 +619,7 @@ class PartialEvaluator {
|
||||
width: w,
|
||||
height: h,
|
||||
imageIsFromDecodeStream: image instanceof DecodeStream,
|
||||
inverseDecode: !!decode && decode[0] > 0,
|
||||
inverseDecode: decode?.[0] > 0,
|
||||
interpolate,
|
||||
});
|
||||
|
||||
@ -660,7 +656,7 @@ class PartialEvaluator {
|
||||
width: w,
|
||||
height: h,
|
||||
imageIsFromDecodeStream: image instanceof DecodeStream,
|
||||
inverseDecode: !!decode && decode[0] > 0,
|
||||
inverseDecode: decode?.[0] > 0,
|
||||
interpolate,
|
||||
isOffscreenCanvasSupported: this.options.isOffscreenCanvasSupported,
|
||||
});
|
||||
@ -991,8 +987,7 @@ class PartialEvaluator {
|
||||
fallbackFontDict = null,
|
||||
cssFontInfo = null
|
||||
) {
|
||||
const fontName =
|
||||
fontArgs && fontArgs[0] instanceof Name ? fontArgs[0].name : null;
|
||||
const fontName = fontArgs?.[0] instanceof Name ? fontArgs[0].name : null;
|
||||
|
||||
return this.loadFont(
|
||||
fontName,
|
||||
@ -1308,7 +1303,7 @@ class PartialEvaluator {
|
||||
this.fontCache.put(font.cacheKey, fontCapability.promise);
|
||||
}
|
||||
assert(
|
||||
fontID && fontID.startsWith("f"),
|
||||
fontID?.startsWith("f"),
|
||||
'The "fontID" must be (correctly) defined.'
|
||||
);
|
||||
|
||||
@ -2569,7 +2564,7 @@ class PartialEvaluator {
|
||||
let posY = currentTransform[5];
|
||||
|
||||
// Check if the glyph is in the viewbox.
|
||||
if (textState.font && textState.font.vertical) {
|
||||
if (textState.font?.vertical) {
|
||||
if (
|
||||
posX < viewBox[0] ||
|
||||
posX > viewBox[2] ||
|
||||
@ -3655,8 +3650,7 @@ class PartialEvaluator {
|
||||
* {ToUnicodeMap|IdentityToUnicodeMap} object.
|
||||
*/
|
||||
async buildToUnicode(properties) {
|
||||
properties.hasIncludedToUnicodeMap =
|
||||
!!properties.toUnicode && properties.toUnicode.length > 0;
|
||||
properties.hasIncludedToUnicodeMap = properties.toUnicode?.length > 0;
|
||||
|
||||
// Section 9.10.2 Mapping Character Codes to Unicode Values
|
||||
if (properties.hasIncludedToUnicodeMap) {
|
||||
@ -4241,8 +4235,8 @@ class PartialEvaluator {
|
||||
}
|
||||
|
||||
if (!isType3Font) {
|
||||
const fontNameStr = fontName && fontName.name;
|
||||
const baseFontStr = baseFont && baseFont.name;
|
||||
const fontNameStr = fontName?.name;
|
||||
const baseFontStr = baseFont?.name;
|
||||
if (fontNameStr !== baseFontStr) {
|
||||
info(
|
||||
`The FontDescriptor's FontName is "${fontNameStr}" but ` +
|
||||
@ -4250,7 +4244,7 @@ class PartialEvaluator {
|
||||
);
|
||||
// Workaround for cases where e.g. fontNameStr = 'Arial' and
|
||||
// baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
|
||||
if (fontNameStr && baseFontStr && baseFontStr.startsWith(fontNameStr)) {
|
||||
if (fontNameStr && baseFontStr?.startsWith(fontNameStr)) {
|
||||
fontName = baseFont;
|
||||
}
|
||||
}
|
||||
@ -4397,7 +4391,7 @@ class PartialEvaluator {
|
||||
// If the glyph has an accent we need to build a path for its
|
||||
// fontChar too, otherwise CanvasGraphics_paintChar will fail.
|
||||
const accent = glyph.accent;
|
||||
if (accent && accent.fontChar) {
|
||||
if (accent?.fontChar) {
|
||||
buildPath(accent.fontChar);
|
||||
}
|
||||
}
|
||||
|
@ -126,11 +126,8 @@ function parseCff(data, start, end, seacAnalysisEnabled) {
|
||||
const cff = parser.parse();
|
||||
return {
|
||||
glyphs: cff.charStrings.objects,
|
||||
subrs:
|
||||
cff.topDict.privateDict &&
|
||||
cff.topDict.privateDict.subrsIndex &&
|
||||
cff.topDict.privateDict.subrsIndex.objects,
|
||||
gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects,
|
||||
subrs: cff.topDict.privateDict?.subrsIndex?.objects,
|
||||
gsubrs: cff.globalSubrIndex?.objects,
|
||||
isCFFCIDFont: cff.isCIDFont,
|
||||
fdSelect: cff.fdSelect,
|
||||
fdArray: cff.fdArray,
|
||||
@ -452,7 +449,7 @@ function compileCharString(charStringCode, cmds, font, glyphId) {
|
||||
if (fdIndex >= 0 && fdIndex < font.fdArray.length) {
|
||||
const fontDict = font.fdArray[fdIndex];
|
||||
let subrs;
|
||||
if (fontDict.privateDict && fontDict.privateDict.subrsIndex) {
|
||||
if (fontDict.privateDict?.subrsIndex) {
|
||||
subrs = fontDict.privateDict.subrsIndex.objects;
|
||||
}
|
||||
if (subrs) {
|
||||
|
@ -1426,8 +1426,7 @@ class Font {
|
||||
|
||||
for (let j = 0, jj = nameTable.length; j < jj; j++) {
|
||||
for (let k = 0, kk = nameTable[j].length; k < kk; k++) {
|
||||
const nameEntry =
|
||||
nameTable[j][k] && nameTable[j][k].replaceAll(/\s/g, "");
|
||||
const nameEntry = nameTable[j][k]?.replaceAll(/\s/g, "");
|
||||
if (!nameEntry) {
|
||||
continue;
|
||||
}
|
||||
@ -1505,9 +1504,8 @@ class Font {
|
||||
// Sometimes there are multiple of the same type of table. Default
|
||||
// to choosing the first table and skip the rest.
|
||||
if (
|
||||
potentialTable &&
|
||||
potentialTable.platformId === platformId &&
|
||||
potentialTable.encodingId === encodingId
|
||||
potentialTable?.platformId === platformId &&
|
||||
potentialTable?.encodingId === encodingId
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
@ -2629,11 +2627,7 @@ class Font {
|
||||
const version = font.getInt32();
|
||||
const numGlyphs = font.getUint16();
|
||||
|
||||
if (
|
||||
properties.scaleFactors &&
|
||||
properties.scaleFactors.length === numGlyphs &&
|
||||
isTrueType
|
||||
) {
|
||||
if (properties.scaleFactors?.length === numGlyphs && isTrueType) {
|
||||
const { scaleFactors } = properties;
|
||||
const isGlyphLocationsLong = int16(
|
||||
tables.head.data[50],
|
||||
@ -2781,7 +2775,7 @@ class Font {
|
||||
this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
|
||||
this.lineGap = metricsOverride.lineGap / metricsOverride.unitsPerEm;
|
||||
|
||||
if (this.cssFontInfo && this.cssFontInfo.lineHeight) {
|
||||
if (this.cssFontInfo?.lineHeight) {
|
||||
this.lineHeight = this.cssFontInfo.metrics.lineHeight;
|
||||
this.lineGap = this.cssFontInfo.metrics.lineGap;
|
||||
} else {
|
||||
@ -3116,7 +3110,7 @@ class Font {
|
||||
}
|
||||
|
||||
const seacs = font.seacs;
|
||||
if (newMapping && SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
|
||||
if (newMapping && SEAC_ANALYSIS_ENABLED && seacs?.length) {
|
||||
const matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
|
||||
const charset = font.getCharset();
|
||||
const seacMap = Object.create(null);
|
||||
@ -3300,13 +3294,13 @@ class Font {
|
||||
let glyph = this._glyphCache[charcode];
|
||||
// All `Glyph`-properties, except `isSpace` in multi-byte strings,
|
||||
// depend indirectly on the `charcode`.
|
||||
if (glyph && glyph.isSpace === isSpace) {
|
||||
if (glyph?.isSpace === isSpace) {
|
||||
return glyph;
|
||||
}
|
||||
let fontCharCode, width, operatorListId;
|
||||
|
||||
let widthCode = charcode;
|
||||
if (this.cMap && this.cMap.contains(charcode)) {
|
||||
if (this.cMap?.contains(charcode)) {
|
||||
widthCode = this.cMap.lookup(charcode);
|
||||
|
||||
if (typeof widthCode === "string") {
|
||||
@ -3317,7 +3311,7 @@ class Font {
|
||||
if (typeof width !== "number") {
|
||||
width = this.defaultWidth;
|
||||
}
|
||||
const vmetric = this.vmetrics && this.vmetrics[widthCode];
|
||||
const vmetric = this.vmetrics?.[widthCode];
|
||||
|
||||
let unicode = this.toUnicode.get(charcode) || charcode;
|
||||
if (typeof unicode === "number") {
|
||||
@ -3348,7 +3342,7 @@ class Font {
|
||||
}
|
||||
|
||||
let accent = null;
|
||||
if (this.seacMap && this.seacMap[charcode]) {
|
||||
if (this.seacMap?.[charcode]) {
|
||||
isInFont = true;
|
||||
const seac = this.seacMap[charcode];
|
||||
fontCharCode = seac.baseFontCharCode;
|
||||
|
@ -72,7 +72,7 @@ class PDFFunctionFactory {
|
||||
} else if (cacheKey instanceof Dict) {
|
||||
fnRef = cacheKey.objId;
|
||||
} else if (cacheKey instanceof BaseStream) {
|
||||
fnRef = cacheKey.dict && cacheKey.dict.objId;
|
||||
fnRef = cacheKey.dict?.objId;
|
||||
}
|
||||
if (fnRef) {
|
||||
const localFunction = this._localFunctionCache.getByRef(fnRef);
|
||||
@ -98,7 +98,7 @@ class PDFFunctionFactory {
|
||||
} else if (cacheKey instanceof Dict) {
|
||||
fnRef = cacheKey.objId;
|
||||
} else if (cacheKey instanceof BaseStream) {
|
||||
fnRef = cacheKey.dict && cacheKey.dict.objId;
|
||||
fnRef = cacheKey.dict?.objId;
|
||||
}
|
||||
if (fnRef) {
|
||||
this._localFunctionCache.set(/* name = */ null, fnRef, parsedFunction);
|
||||
|
@ -221,7 +221,7 @@ class PDFImage {
|
||||
const max = (1 << bitsPerComponent) - 1;
|
||||
this.decodeCoefficients = [];
|
||||
this.decodeAddends = [];
|
||||
const isIndexed = this.colorSpace && this.colorSpace.name === "Indexed";
|
||||
const isIndexed = this.colorSpace?.name === "Indexed";
|
||||
for (let i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
|
||||
const dmin = this.decode[i];
|
||||
const dmax = this.decode[i + 1];
|
||||
@ -428,18 +428,14 @@ class PDFImage {
|
||||
}
|
||||
|
||||
get drawWidth() {
|
||||
return Math.max(
|
||||
this.width,
|
||||
(this.smask && this.smask.width) || 0,
|
||||
(this.mask && this.mask.width) || 0
|
||||
);
|
||||
return Math.max(this.width, this.smask?.width || 0, this.mask?.width || 0);
|
||||
}
|
||||
|
||||
get drawHeight() {
|
||||
return Math.max(
|
||||
this.height,
|
||||
(this.smask && this.smask.height) || 0,
|
||||
(this.mask && this.mask.height) || 0
|
||||
this.smask?.height || 0,
|
||||
this.mask?.height || 0
|
||||
);
|
||||
}
|
||||
|
||||
@ -640,7 +636,7 @@ class PDFImage {
|
||||
'PDFImage.undoPreblend: Unsupported "buffer" type.'
|
||||
);
|
||||
}
|
||||
const matte = this.smask && this.smask.matte;
|
||||
const matte = this.smask?.matte;
|
||||
if (!matte) {
|
||||
return;
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ class BaseLocalCache {
|
||||
if (this.constructor === BaseLocalCache) {
|
||||
unreachable("Cannot initialize BaseLocalCache.");
|
||||
}
|
||||
this._onlyRefs = (options && options.onlyRefs) === true;
|
||||
this._onlyRefs = options?.onlyRefs === true;
|
||||
|
||||
if (!this._onlyRefs) {
|
||||
this._nameRefMap = new Map();
|
||||
|
@ -759,7 +759,7 @@ class JpegImage {
|
||||
let endOffset = offset + length - 2;
|
||||
|
||||
const fileMarker = findNextFileMarker(data, endOffset, offset);
|
||||
if (fileMarker && fileMarker.invalid) {
|
||||
if (fileMarker?.invalid) {
|
||||
warn(
|
||||
"readDataBlock - incorrect length, current marker is: " +
|
||||
fileMarker.invalid
|
||||
@ -1052,7 +1052,7 @@ class JpegImage {
|
||||
/* currentPos = */ offset - 2,
|
||||
/* startPos = */ offset - 3
|
||||
);
|
||||
if (nextFileMarker && nextFileMarker.invalid) {
|
||||
if (nextFileMarker?.invalid) {
|
||||
warn(
|
||||
"JpegImage.parse - unexpected data, current marker is: " +
|
||||
nextFileMarker.invalid
|
||||
|
@ -693,11 +693,7 @@ class OperatorList {
|
||||
case OPS.paintInlineImageXObjectGroup:
|
||||
case OPS.paintImageMaskXObject:
|
||||
const arg = argsArray[i][0]; // First parameter in imgData.
|
||||
if (
|
||||
!arg.cached &&
|
||||
arg.data &&
|
||||
arg.data.buffer instanceof ArrayBuffer
|
||||
) {
|
||||
if (!arg.cached && arg.data?.buffer instanceof ArrayBuffer) {
|
||||
transfers.push(arg.data.buffer);
|
||||
}
|
||||
break;
|
||||
|
@ -1251,7 +1251,7 @@ class Lexer {
|
||||
}
|
||||
}
|
||||
const knownCommands = this.knownCommands;
|
||||
let knownCommandFound = knownCommands && knownCommands[str] !== undefined;
|
||||
let knownCommandFound = knownCommands?.[str] !== undefined;
|
||||
while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
|
||||
// Stop if a known command is found and next character does not make
|
||||
// the string a command.
|
||||
@ -1263,7 +1263,7 @@ class Lexer {
|
||||
throw new FormatError(`Command token too long: ${str.length}`);
|
||||
}
|
||||
str = possibleCommand;
|
||||
knownCommandFound = knownCommands && knownCommands[str] !== undefined;
|
||||
knownCommandFound = knownCommands?.[str] !== undefined;
|
||||
}
|
||||
if (str === "true") {
|
||||
return true;
|
||||
|
@ -297,7 +297,7 @@ class RefSet {
|
||||
) {
|
||||
unreachable('RefSet: Invalid "parent" value.');
|
||||
}
|
||||
this._set = new Set(parent && parent._set);
|
||||
this._set = new Set(parent?._set);
|
||||
}
|
||||
|
||||
has(ref) {
|
||||
|
@ -271,7 +271,7 @@ class StructTreePage {
|
||||
let save = false;
|
||||
for (let i = 0; i < obj.length; i++) {
|
||||
const kidRef = obj[i];
|
||||
if (kidRef && kidRef.toString() === dict.objId) {
|
||||
if (kidRef?.toString() === dict.objId) {
|
||||
this.nodes[i] = element;
|
||||
save = true;
|
||||
}
|
||||
|
@ -252,9 +252,9 @@ function getCharUnicodeCategory(char) {
|
||||
}
|
||||
const groups = char.match(SpecialCharRegExp);
|
||||
const category = {
|
||||
isWhitespace: !!(groups && groups[1]),
|
||||
isZeroWidthDiacritic: !!(groups && groups[2]),
|
||||
isInvisibleFormatMark: !!(groups && groups[3]),
|
||||
isWhitespace: !!groups?.[1],
|
||||
isZeroWidthDiacritic: !!groups?.[2],
|
||||
isInvisibleFormatMark: !!groups?.[3],
|
||||
};
|
||||
CategoryCache.set(char, category);
|
||||
return category;
|
||||
|
@ -5481,8 +5481,7 @@ class Template extends XFAObject {
|
||||
breakBeforeTarget = breakBefore.beforeTarget;
|
||||
} else if (
|
||||
root.subform.children.length >= 1 &&
|
||||
root.subform.children[0].break &&
|
||||
root.subform.children[0].break.beforeTarget
|
||||
root.subform.children[0].break?.beforeTarget
|
||||
) {
|
||||
breakBefore = root.subform.children[0].break;
|
||||
breakBeforeTarget = breakBefore.beforeTarget;
|
||||
|
@ -302,7 +302,7 @@ class SimpleDOMNode {
|
||||
}
|
||||
|
||||
get firstChild() {
|
||||
return this.childNodes && this.childNodes[0];
|
||||
return this.childNodes?.[0];
|
||||
}
|
||||
|
||||
get nextSibling() {
|
||||
@ -333,7 +333,7 @@ class SimpleDOMNode {
|
||||
}
|
||||
|
||||
hasChildNodes() {
|
||||
return this.childNodes && this.childNodes.length > 0;
|
||||
return this.childNodes?.length > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -383,7 +383,7 @@ class SimpleDOMNode {
|
||||
}
|
||||
}
|
||||
|
||||
if (node.childNodes && node.childNodes.length !== 0) {
|
||||
if (node.childNodes?.length > 0) {
|
||||
stack.push([node, 0]);
|
||||
node = node.childNodes[0];
|
||||
} else if (stack.length === 0) {
|
||||
|
@ -98,7 +98,7 @@ class XRef {
|
||||
}
|
||||
if (encrypt instanceof Dict) {
|
||||
const ids = trailerDict.get("ID");
|
||||
const fileId = ids && ids.length ? ids[0] : "";
|
||||
const fileId = ids?.length ? ids[0] : "";
|
||||
// The 'Encrypt' dictionary itself should not be encrypted, and by
|
||||
// setting `suppressEncryption` we can prevent an infinite loop inside
|
||||
// of `XRef_fetchUncompressed` if the dictionary contains indirect
|
||||
|
@ -2317,8 +2317,8 @@ function webViewerPageRendered({ pageNumber, error }) {
|
||||
const thumbnailView = PDFViewerApplication.pdfThumbnailViewer?.getThumbnail(
|
||||
/* index = */ pageNumber - 1
|
||||
);
|
||||
if (pageView && thumbnailView) {
|
||||
thumbnailView.setImage(pageView);
|
||||
if (pageView) {
|
||||
thumbnailView?.setImage(pageView);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user