Repository navigation
Consolidate UTF-16 and CMap decoding and fix wide ToUnicode codes - #581
Merged
Merged
Conversation
Share one borrowing UTF-16BE reader (Utf16BeUnits) between PDF text strings and ToUnicode destinations, replacing the allocating BigEndianU16Units and the hand-rolled surrogate decoding with char::decode_utf16. The ToUnicode parser now builds its final UnicodeSequence map directly, and Type0 code-space decoding returns CidMapping values built once through TryFrom<&[u8]> for PdfCode. Test-only Type0EncodingCMap helpers are removed. ToUnicode source codes keep their full one-to-four-byte value instead of being truncated to two bytes, and sequential bfrange destinations advance their final UTF-16 unit, so surrogate-pair and multi-character bases map correctly. Range spans are capped at 65,536 codes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Conformance readsDocuments that Safe-PDF reads differently from the base commit, compared with PDFium. A read pdf.js corpus1008 documents compared with Improvements
840 documents of the PDFium corpus read as on Details are in the job summaries of the workflow run. Rerun a case locally with |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Utf16BeUnits, is now shared by PDF text strings and ToUnicode destinations. It replaces the allocatingBigEndianU16Units, and the hand-written surrogate decoding incmap/unicode.rsis replaced bychar::decode_utf16.HashMap<u32, UnicodeSequence>directly, so the second copying pass is gone. Sequential ranges no longer allocate oneVecper code, becauseUnicodeSequence: FromIterator<char>only allocates for mappings with two or more characters.CidMappingdirectly, built through a newTryFrom<&[u8]> for PdfCode. The(u32, usize, u16)tuple and its re-validation are gone.Type0EncodingCMap::decode_identity,decodeandis_identityare removed, since only tests used them.decodeis now a helper inside the tests.Behavior changes
<AABBCC>was stored as0xBBCC. Lookup still matches by numeric value only, so<0041>also maps the one-byte code0x41.bfrangedestinations now advance their last UTF-16 unit, so<D835DC00>and<00660066>bases map correctly. Previously they mapped nothing.<00000000> <FFFFFFFF>range can't demand unbounded memory.D83D 0041, now decodes as'A'(standard library lossy behavior). Previously both units were dropped.Test plan
cargo testpasses forpdf-object-reader,pdf-cmap,pdf-font,pdf-annotation-core,pdf-canvas,pdf-content-streamandpdf-document. The full workspace wasn't run locally because the Skia build needs a download.cargo clippy --all --workspaceshows no warnings in changed files, andcargo fmtis applied.🤖 Generated with Claude Code