Skip to content

Conversation

@PskDream
Copy link

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

  • Unit-Tests added to reproduce the bug
  • Unit-Tests added to the added feature

Compatibilities Issues

No breaking changes.

  • The method signature remains exactly the same.
  • Internal logic now correctly handles FOP's GlyphSequence associations.
  • The change only affects users who have the FOP library on their classpath and are using IDENTITY_H encoding with complex scripts.

Your real name

Pongsakorn Samothai No conflict of interest.

Testing details

To verify this fix:

  1. Use a Thai font (e.g., Sarabun or TH Sarabun New) with BaseFont.IDENTITY_H.
  2. Attempt to render the Thai character "จำ" or "น้ำ" (which contains the 'Sara Am' character).
  3. Without this patch, the code throws java.lang.IndexOutOfBoundsException.
  4. With this patch, the PDF renders correctly with beautiful Thai typography (properly decomposed and positioned glyphs).

@sonarqubecloud
Copy link

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.

1 participant