Fix IndexOutOfBoundsException in FopGlyphProcessor due to 1:N Thai Glyph Expansion #1457
+157
−2
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.



Description of the new Feature/Bugfix
This PR fixes a IndexOutOfBoundsException in FopGlyphProcessor when rendering complex scripts (specifically Thai).
The Root Cause: In FopGlyphProcessor.convertToBytesWithGlyphs, the code incorrectly assumed a 1:1 mapping between characters and glyphs. In Thai (and other Indic scripts), the shaping engine often performs "Glyph Expansion" where one character (e.g., Sara Am ำ) is decomposed into two glyphs (Nikkhahit ํ and Lak Khang า).
The original code used the glyph loop index i to access charBuffer.get(i), which leads to a crash when the number of glyphs exceeds the number of original characters.
The Fix: I have implemented a proper mapping using FOP's CharAssociation. By calling glyphSequence.getAssociations()[i].getStart(), we can accurately map each glyph back to its original character index, ensuring both thread safety and correct data retrieval regardless of glyph expansion or contraction.
Related Issue: #1456
Unit-Tests for the new Feature/Bugfix
Compatibilities Issues
No breaking changes.
Your real name
Pongsakorn Samothai No conflict of interest.
Testing details
To verify this fix: