1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-29 15:47:57 +02:00

Merge pull request #16424 from Snuffleupagus/core-optional-chaining

Introduce more optional chaining in the `src/core/` folder
This commit is contained in:
Tim van der Meij 2023-05-18 12:40:08 +02:00 committed by GitHub
commit ac8032628b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 90 additions and 137 deletions

View file

@ -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;