diff --git a/src/core/annotation.js b/src/core/annotation.js index 27de618b90dd2..1e32d56f43268 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -997,9 +997,7 @@ class WidgetAnnotation extends Annotation { data.defaultAppearance = isString(defaultAppearance) ? defaultAppearance : ""; - this._defaultAppearanceData = parseDefaultAppearance( - data.defaultAppearance - ); + data.defaultAppearanceData = parseDefaultAppearance(data.defaultAppearance); const fieldType = getInheritableProperty({ dict, key: "FT" }); data.fieldType = isName(fieldType) ? fieldType.name : null; @@ -1294,7 +1292,7 @@ class WidgetAnnotation extends Annotation { // Doing so prevents exceptions and allows saving/printing // the file as expected. this.data.defaultAppearance = "/Helvetica 0 Tf 0 g"; - this._defaultAppearanceData = parseDefaultAppearance( + this.data.defaultAppearanceData = parseDefaultAppearance( this.data.defaultAppearance ); } @@ -1377,7 +1375,7 @@ class WidgetAnnotation extends Annotation { }, }; - const { fontName, fontSize } = this._defaultAppearanceData; + const { fontName, fontSize } = this.data.defaultAppearanceData; await evaluator.handleSetFont( this._fieldResources.mergedResources, [fontName, fontSize], @@ -1392,9 +1390,9 @@ class WidgetAnnotation extends Annotation { } _computeFontSize(font, height) { - let fontSize = this._defaultAppearanceData.fontSize; + let fontSize = this.data.defaultAppearanceData.fontSize; if (!fontSize) { - const { fontColor, fontName } = this._defaultAppearanceData; + const { fontColor, fontName } = this.data.defaultAppearanceData; let capHeight; if (font.capHeight) { capHeight = font.capHeight; @@ -1456,7 +1454,7 @@ class WidgetAnnotation extends Annotation { PDFJSDev.test("!PRODUCTION || TESTING") ) { assert( - this._defaultAppearanceData, + this.data.defaultAppearanceData, "Expected `_defaultAppearanceData` to have been set." ); } @@ -1467,7 +1465,8 @@ class WidgetAnnotation extends Annotation { } = this._fieldResources; const fontNameStr = - this._defaultAppearanceData && this._defaultAppearanceData.fontName.name; + this.data.defaultAppearanceData && + this.data.defaultAppearanceData.fontName.name; if (!fontNameStr) { return localResources || Dict.empty; } diff --git a/src/display/annotation_layer.js b/src/display/annotation_layer.js index 25a8fda525673..2e8e5f5265946 100644 --- a/src/display/annotation_layer.js +++ b/src/display/annotation_layer.js @@ -595,7 +595,6 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement { } render() { - const TEXT_ALIGNMENT = ["left", "center", "right"]; const storage = this.annotationStorage; const id = this.data.id; @@ -834,20 +833,9 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement { element.textContent = this.data.fieldValue; element.style.verticalAlign = "middle"; element.style.display = "table-cell"; - - let font = null; - if ( - this.data.fontRefName && - this.page.commonObjs.has(this.data.fontRefName) - ) { - font = this.page.commonObjs.get(this.data.fontRefName); - } - this._setTextStyle(element, font); } - if (this.data.textAlignment !== null) { - element.style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment]; - } + this._setTextStyle(element); this.container.appendChild(element); return this.container; @@ -858,32 +846,25 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement { * * @private * @param {HTMLDivElement} element - * @param {Object} font * @memberof TextWidgetAnnotationElement */ - _setTextStyle(element, font) { - // TODO: This duplicates some of the logic in CanvasGraphics.setFont(). + _setTextStyle(element) { + const TEXT_ALIGNMENT = ["left", "center", "right"]; + const { fontSize, fontColor } = this.data.defaultAppearanceData; const style = element.style; - style.fontSize = `${this.data.fontSize}px`; - style.direction = this.data.fontDirection < 0 ? "rtl" : "ltr"; - if (!font) { - return; + // TODO: If the font-size is zero, calculate it based on the height and + // width of the element. + // Not setting `style.fontSize` will use the default font-size for now. + if (fontSize) { + style.fontSize = `${fontSize}px`; } - let bold = "normal"; - if (font.black) { - bold = "900"; - } else if (font.bold) { - bold = "bold"; - } - style.fontWeight = bold; - style.fontStyle = font.italic ? "italic" : "normal"; + style.color = Util.makeHexColor(fontColor[0], fontColor[1], fontColor[2]); - // Use a reasonable default font if the font doesn't specify a fallback. - const fontFamily = font.loadedName ? `"${font.loadedName}", ` : ""; - const fallbackName = font.fallbackName || "Helvetica, sans-serif"; - style.fontFamily = fontFamily + fallbackName; + if (this.data.textAlignment !== null) { + style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment]; + } } } diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 2c72de34bd1cb..b53fb8b1ee61f 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -418,3 +418,4 @@ !issue11555.pdf !issue12337.pdf !pr12564.pdf +!pr12828.pdf diff --git a/test/pdfs/pr12828.pdf b/test/pdfs/pr12828.pdf new file mode 100644 index 0000000000000..f69caee844dce Binary files /dev/null and b/test/pdfs/pr12828.pdf differ diff --git a/test/test_manifest.json b/test/test_manifest.json index 29cd2ac475360..dfdf0983e9a4c 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -5005,5 +5005,13 @@ "rounds": 1, "type": "eq", "annotations": true + }, + { + "id": "pr12828", + "file": "pdfs/pr12828.pdf", + "md5": "e44d364fba2f146aed04f9d9abbb0f28", + "rounds": 1, + "type": "eq", + "forms": true } ]