Skip to content

IndexOutOfBoundsException in FopGlyphProcessor when shaping Thai characters (Complex Scripts) #1456

@PskDream

Description

@PskDream

Describe the bug

I found a bug in FopGlyphProcessor when rendering Thai language with FOP support enabled. The application crashes with IndexOutOfBoundsException because the processor assumes a 1:1 mapping between characters and glyphs.

To Reproduce

When rendering Thai characters like "ำ" (Sara Am), the FOP shaping engine decomposes one character into two glyphs (Nikkhahit + Lak Khang).
The current loop in FopGlyphProcessor.convertToBytesWithGlyphs iterates based on the glyph count but tries to access the charBuffer using the same index:

for (int i = 0; i < limit; i++) {
    // ...
    longTag.put(glyphCode, new int[]{..., charBuffer.get(i)}); // This throws Exception when limit > charBuffer size
}

Expected behavior

The processor should handle cases where the number of glyphs is greater than the number of characters by correctly mapping glyphs back to their original source characters using FOP's CharAssociation.

Screenshots

Image Image Image

System

OpenPDF version: 3.0.0
FOP version: 2.11
Language: Thai

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions