Introduce more optional chaining in the src/core/ folder

After PR 12563 we're now free to use optional chaining in the worker-thread as well. (This patch also fixes one previously "missed" case in the `web/` folder.)

For the MOZCENTRAL build-target this patch reduces the total bundle-size by `1.6` kilobytes.
This commit is contained in:
Jonas Jenwald 2023-05-15 12:38:28 +02:00
parent c20c1b3362
commit 1b4a7c5965
27 changed files with 90 additions and 137 deletions

View file

@ -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,
@ -1315,7 +1310,7 @@ class PartialEvaluator {
this.fontCache.put(font.cacheKey, fontCapability.promise);
}
assert(
fontID && fontID.startsWith("f"),
fontID?.startsWith("f"),
'The "fontID" must be (correctly) defined.'
);
@ -2576,7 +2571,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] ||
@ -3662,8 +3657,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) {
@ -4248,8 +4242,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 ` +
@ -4257,7 +4251,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;
}
}
@ -4404,7 +4398,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);
}
}