diff --git a/src/core/fonts.js b/src/core/fonts.js index c562ce12a..29f186fa3 100644 --- a/src/core/fonts.js +++ b/src/core/fonts.js @@ -3293,7 +3293,10 @@ class Font { return builder.toArray(); } - get spaceWidth() { + /** + * @private + */ + get _spaceWidth() { // trying to estimate space character width const possibleSpaceReplacements = ["space", "minus", "one", "i", "I"]; let width; @@ -3328,7 +3331,7 @@ class Font { break; // the non-zero width found } } - return shadow(this, "spaceWidth", width || this.defaultWidth); + return shadow(this, "_spaceWidth", width || this.defaultWidth); } /** @@ -3376,6 +3379,13 @@ class Font { // .notdef glyphs should be invisible in non-embedded Type1 fonts, so // replace them with spaces. fontCharCode = 0x20; + + if (glyphName === "") { + // Ensure that other relevant glyph properties are also updated + // (fixes issue18059.pdf). + width ||= this._spaceWidth; + unicode = String.fromCharCode(fontCharCode); + } } fontCharCode = mapSpecialUnicodeValues(fontCharCode); } diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 13450e37c..7eedf8be6 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -56,6 +56,7 @@ !issue17679_2.pdf !issue18030.pdf !issue18042.pdf +!issue18059.pdf !issue14953.pdf !issue15367.pdf !issue15372.pdf diff --git a/test/pdfs/issue18059.pdf b/test/pdfs/issue18059.pdf new file mode 100644 index 000000000..82416e266 Binary files /dev/null and b/test/pdfs/issue18059.pdf differ diff --git a/test/test_manifest.json b/test/test_manifest.json index b7d1190f6..90ad056ec 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -2990,6 +2990,20 @@ "rounds": 1, "type": "text" }, + { + "id": "issue18059", + "file": "pdfs/issue18059.pdf", + "md5": "b70373894edfcd571a41caa1a0776b6f", + "rounds": 1, + "type": "eq" + }, + { + "id": "issue18059-text", + "file": "pdfs/issue18059.pdf", + "md5": "b70373894edfcd571a41caa1a0776b6f", + "rounds": 1, + "type": "text" + }, { "id": "issue11139", "file": "pdfs/issue11139.pdf",