Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/core/fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3602,8 +3602,11 @@ class Font {
}
}
// ... via toUnicode map
if (!charcode && this.toUnicode) {
charcode = this.toUnicode.charCodeOf(glyphUnicode);
if (!charcode && this.toUnicode && glyphUnicode !== undefined) {
charcode =
this.toUnicode instanceof IdentityToUnicodeMap
? this.toUnicode.charCodeOf(glyphUnicode)
: this.toUnicode.charCodeOf(String.fromCodePoint(glyphUnicode));
}
// setting it to unicode if negative or undefined
if (charcode <= 0) {
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,7 @@
!issue18768_text_matrix_spacing.pdf
!issue18768_type3_wide_glyph.pdf
!issue18768_word_spaces.pdf
!tounicode_space_width.pdf
!issue19954_reduced.pdf
!issue1936_reduced.pdf
!issue22462.pdf
Binary file added test/pdfs/tounicode_space_width.pdf
Binary file not shown.
15 changes: 15 additions & 0 deletions test/unit/api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5370,6 +5370,21 @@ ABCD E`);
await loadingTask.destroy();
});

it("gets text content, using the ToUnicode space width for letter-spaced text", async function () {
const loadingTask = getDocument(
buildGetDocumentParams("tounicode_space_width.pdf")
);
const pdfDoc = await loadingTask.promise;
const pdfPage = await pdfDoc.getPage(1);
const { items } = await pdfPage.getTextContent({
disableNormalization: true,
});

expect(mergeText(items)).toEqual("TRACK TACK");

await loadingTask.destroy();
});

it("gets text content, preserving various word spaces", async function () {
const loadingTask = getDocument(
buildGetDocumentParams("issue18768_word_spaces.pdf")
Expand Down