Skip to content

Conversation

@markbruce
Copy link
Contributor

@markbruce markbruce commented Nov 26, 2025

Fixes garbled text copying in Chrome/Edge for PDFs with >256 unique characters

What kind of change does this PR introduce?
Bug fix
issue : #1659
Checklist:

  • Unit Tests
  • Documentation N/A
  • Update CHANGELOG.md
  • Ready to be merged

PDF standards 1.3 Chapter 5. Page 344
(https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/pdfreference1.3.pdf)

image

Fixes garbled text copying in Chrome/Edge for PDFs with >256 unique characters
Addressed an issue with garbled text copying in Chrome/Edge for PDFs containing more than 256 unique characters.
Add test cases to verify that the beginbfrange count declaration
in ToUnicode CMap matches the actual number of bfrange entries.

- Test for fonts with >256 characters (multiple ranges)
- Test for fonts with <=256 characters (single range)

These tests ensure the fix for the beginbfrange count bug is
correct and prevent regression.

Related to foliojs#1659
});
});

test.each([
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why removed this test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for that. Maybe I use wrong version of the file to generate tests code. I have fixed it.

const font = PDFFontFactory.open(
document,
'tests/fonts/Roboto-Regular.ttf',
'tests/fonts/Roboto-Regular.ttf'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please run prettier to make style consistent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for that. Maybe I use wrong version of the file to generate tests code. I have fixed it.

@blikblum
Copy link
Member

There s one remaining eslint error

Replace for loops with unused match variables with spread operator
to directly get array length, fixing ESLint no-unused-vars errors.

- Replace loop counting with [...rangeMatches].length
- Fixes ESLint errors at lines 152 and 197 in tests/unit/font.spec.js
- All tests pass successfully
@markbruce
Copy link
Contributor Author

There s one remaining eslint error

My bad. I Fixed it. ToT

@blikblum blikblum merged commit d010815 into foliojs:master Dec 1, 2025
3 checks passed
@blikblum
Copy link
Member

blikblum commented Dec 1, 2025

Many thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants