diff --git a/src/core/annotation.js b/src/core/annotation.js index 252e1529b4849..3241152d76882 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -25,6 +25,7 @@ import { escapeString, getModificationDate, isString, + objectSize, OPS, shadow, stringToPDFString, @@ -1326,7 +1327,7 @@ class WidgetAnnotation extends Annotation { _computeFontSize(font, fontName, fontSize, height) { if (fontSize === null || fontSize === 0) { - const em = font.charsToGlyphs("M", true)[0].width / 1000; + const em = font.charsToGlyphs("M")[0].width / 1000; // According to https://en.wikipedia.org/wiki/Em_(typography) // an average cap height should be 70% of 1em const capHeight = 0.7 * em; @@ -1460,18 +1461,20 @@ class WidgetAnnotation extends Annotation { if (dict.has("AA")) { const additionalActions = dict.get("AA"); for (const key of additionalActions.getKeys()) { - if (key in AnnotationActionEventType) { - const actionDict = additionalActions.getRaw(key); - const parents = new RefSet(); - const list = []; - this._collectJS(actionDict, xref, list, parents); - if (list.length > 0) { - actions[AnnotationActionEventType[key]] = list; - } + const action = AnnotationActionEventType[key]; + if (!action) { + continue; + } + const actionDict = additionalActions.getRaw(key); + const parents = new RefSet(); + const list = []; + this._collectJS(actionDict, xref, list, parents); + if (list.length > 0) { + actions[action] = list; } } } - // Collect the Action if any (we may have one on pushbutton) + // Collect the Action if any (we may have one on pushbutton). if (dict.has("A")) { const actionDict = dict.get("A"); const parents = new RefSet(); @@ -1481,7 +1484,7 @@ class WidgetAnnotation extends Annotation { actions.Action = list; } } - return actions; + return objectSize(actions) > 0 ? actions : null; } getFieldObject() { @@ -1597,7 +1600,7 @@ class TextWidgetAnnotation extends WidgetAnnotation { } const scale = fontSize / 1000; - const whitespace = font.charsToGlyphs(" ", true)[0].width * scale; + const whitespace = font.charsToGlyphs(" ")[0].width * scale; const chunks = []; let lastSpacePos = -1, @@ -1618,7 +1621,7 @@ class TextWidgetAnnotation extends WidgetAnnotation { lastSpacePos = i; } } else { - const charWidth = font.charsToGlyphs(character, false)[0].width * scale; + const charWidth = font.charsToGlyphs(character)[0].width * scale; if (currentWidth + charWidth > width) { // We must break to the last white position (if available) if (lastSpacePos !== -1) { diff --git a/src/core/fonts.js b/src/core/fonts.js index 3839a701bc1da..6f8d60b319f10 100644 --- a/src/core/fonts.js +++ b/src/core/fonts.js @@ -3208,7 +3208,10 @@ var Font = (function FontClosure() { return shadow(this, "spaceWidth", width); }, - charToGlyph: function Font_charToGlyph(charcode, isSpace) { + /** + * @private + */ + _charToGlyph(charcode, isSpace = false) { var fontCharCode, width, operatorListId; var widthCode = charcode; @@ -3332,13 +3335,13 @@ var Font = (function FontClosure() { i += length; // Space is char with code 0x20 and length 1 in multiple-byte codes. var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20; - glyph = this.charToGlyph(charcode, isSpace); + glyph = this._charToGlyph(charcode, isSpace); glyphs.push(glyph); } } else { for (i = 0, ii = chars.length; i < ii; ++i) { charcode = chars.charCodeAt(i); - glyph = this.charToGlyph(charcode, charcode === 0x20); + glyph = this._charToGlyph(charcode, charcode === 0x20); glyphs.push(glyph); } } diff --git a/src/core/obj.js b/src/core/obj.js index 9aeb8f4a5904f..f45fc40ea19b3 100644 --- a/src/core/obj.js +++ b/src/core/obj.js @@ -25,7 +25,7 @@ import { isBool, isNum, isString, - objectFromEntries, + objectSize, PermissionFlag, shadow, stringToPDFString, @@ -787,7 +787,7 @@ class Catalog { */ get openAction() { const obj = this._catDict.get("OpenAction"); - const openActionMap = new Map(); + const openAction = Object.create(null); if (isDict(obj)) { // Convert the OpenAction dictionary into a format that works with @@ -799,17 +799,17 @@ class Catalog { Catalog.parseDestDictionary({ destDict, resultObj }); if (Array.isArray(resultObj.dest)) { - openActionMap.set("dest", resultObj.dest); + openAction.dest = resultObj.dest; } else if (resultObj.action) { - openActionMap.set("action", resultObj.action); + openAction.action = resultObj.action; } } else if (Array.isArray(obj)) { - openActionMap.set("dest", obj); + openAction.dest = obj; } return shadow( this, "openAction", - openActionMap.size > 0 ? objectFromEntries(openActionMap) : null + objectSize(openAction) > 0 ? openAction : null ); } diff --git a/src/shared/util.js b/src/shared/util.js index ab1f58aef2dda..c49e6e30c1538 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -585,6 +585,10 @@ function string32(value) { ); } +function objectSize(obj) { + return Object.keys(obj).length; +} + // Ensures that the returned Object has a `null` prototype. function objectFromEntries(iterable) { return Object.assign(Object.create(null), Object.fromEntries(iterable)); @@ -1040,6 +1044,7 @@ export { isString, isSameOrigin, createValidAbsoluteUrl, + objectSize, objectFromEntries, IsLittleEndianCached, IsEvalSupportedCached,