diff --git a/src/core/annotation.js b/src/core/annotation.js index e795f8572..9d0baf1d7 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -3826,7 +3826,7 @@ class FreeTextAnnotation extends MarkupAnnotation { fontColor, strokeAlpha ); - this._streams.push(this.appearance, FakeUnicodeFont.toUnicodeStream); + this._streams.push(this.appearance); } else { warn( "FreeTextAnnotation: OffscreenCanvas is not supported, annotation may not render correctly." diff --git a/src/core/core_utils.js b/src/core/core_utils.js index 4b8fa637e..a9bd298c7 100644 --- a/src/core/core_utils.js +++ b/src/core/core_utils.js @@ -386,6 +386,17 @@ const XMLEntities = { /* ' */ 0x27: "'", }; +function* codePointIter(str) { + for (let i = 0, ii = str.length; i < ii; i++) { + const char = str.codePointAt(i); + if (char > 0xd7ff && (char < 0xe000 || char > 0xfffd)) { + // char is represented by two u16 + i++; + } + yield char; + } +} + function encodeToXmlString(str) { const buffer = []; let start = 0; @@ -602,6 +613,7 @@ function getRotationMatrix(rotation, width, height) { export { arrayBuffersToBytes, + codePointIter, collectActions, encodeToXmlString, escapePDFName, diff --git a/src/core/default_appearance.js b/src/core/default_appearance.js index c01ea5987..cb84b1a7e 100644 --- a/src/core/default_appearance.js +++ b/src/core/default_appearance.js @@ -13,13 +13,14 @@ * limitations under the License. */ -import { Dict, Name } from "./primitives.js"; import { + codePointIter, escapePDFName, getRotationMatrix, numberToString, stringToUTF16HexString, } from "./core_utils.js"; +import { Dict, Name } from "./primitives.js"; import { LINE_DESCENT_FACTOR, LINE_FACTOR, @@ -251,35 +252,6 @@ class FakeUnicodeFont { ); } - get toUnicodeRef() { - if (!FakeUnicodeFont._toUnicodeRef) { - const toUnicode = `/CIDInit /ProcSet findresource begin -12 dict begin -begincmap -/CIDSystemInfo -<< /Registry (Adobe) -/Ordering (UCS) /Supplement 0 >> def -/CMapName /Adobe-Identity-UCS def -/CMapType 2 def -1 begincodespacerange -<0000> -endcodespacerange -1 beginbfrange -<0000> <0000> -endbfrange -endcmap CMapName currentdict /CMap defineresource pop end end`; - const toUnicodeStream = (FakeUnicodeFont.toUnicodeStream = - new StringStream(toUnicode)); - const toUnicodeDict = new Dict(this.xref); - toUnicodeStream.dict = toUnicodeDict; - toUnicodeDict.set("Length", toUnicode.length); - FakeUnicodeFont._toUnicodeRef = - this.xref.getNewPersistentRef(toUnicodeStream); - } - - return FakeUnicodeFont._toUnicodeRef; - } - get fontDescriptorRef() { if (!FakeUnicodeFont._fontDescriptorRef) { const fontDescriptor = new Dict(this.xref); @@ -350,7 +322,7 @@ endcmap CMapName currentdict /CMap defineresource pop end end`; baseFont.set("Subtype", Name.get("Type0")); baseFont.set("Encoding", Name.get("Identity-H")); baseFont.set("DescendantFonts", [this.descendantFontRef]); - baseFont.set("ToUnicode", this.toUnicodeRef); + baseFont.set("ToUnicode", Name.get("Identity-H")); return this.xref.getNewPersistentRef(baseFont); } @@ -420,8 +392,8 @@ endcmap CMapName currentdict /CMap defineresource pop end end`; // languages, like arabic, it'd be wrong because of ligatures. const lineWidth = ctx.measureText(line).width; maxWidth = Math.max(maxWidth, lineWidth); - for (const char of line.split("")) { - const code = char.charCodeAt(0); + for (const code of codePointIter(line)) { + const char = String.fromCodePoint(code); let width = this.widths.get(code); if (width === undefined) { const metrics = ctx.measureText(char); diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index e178e95ff..fbc0cf99c 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -627,3 +627,4 @@ !file_pdfjs_form.pdf !issue17492.pdf !issue17540.pdf +!bug1669097.pdf diff --git a/test/pdfs/bug1669097.pdf b/test/pdfs/bug1669097.pdf new file mode 100755 index 000000000..07b9ef9c4 Binary files /dev/null and b/test/pdfs/bug1669097.pdf differ diff --git a/test/test_manifest.json b/test/test_manifest.json index c258a2483..016082e89 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -9650,5 +9650,30 @@ "structTreeParentId": null } } + }, + { + "id": "bug1669097", + "file": "pdfs/bug1669097.pdf", + "md5": "561b3abac1fe49e1c9cd265cbf4a456e", + "rounds": 1, + "type": "eq", + "save": true, + "print": true, + "annotationStorage": { + "24R": { + "value": "😇👽🖖" + }, + "pdfjs_internal_editor_0": { + "annotationType": 3, + "color": [0, 0, 0], + "fontSize": 10, + "value": "😇😇😇😇😇😇👽👽👽👽👽👽🖖", + "pageIndex": 0, + "rect": [267, 638, 452, 658], + "rotation": 0, + "structTreeParentId": null, + "id": null + } + } } ]