mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-29 15:47:57 +02:00
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:
parent
c20c1b3362
commit
1b4a7c5965
27 changed files with 90 additions and 137 deletions
|
@ -1424,8 +1424,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;
|
||||
}
|
||||
|
@ -1503,9 +1502,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;
|
||||
}
|
||||
|
@ -2627,11 +2625,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],
|
||||
|
@ -2779,7 +2773,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 {
|
||||
|
@ -3114,7 +3108,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);
|
||||
|
@ -3298,13 +3292,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") {
|
||||
|
@ -3315,7 +3309,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") {
|
||||
|
@ -3346,7 +3340,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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue