peteraisher opened a new pull request, #538: URL: https://github.com/apache/pdfbox/pull/538
# parse a TrueType font from a `ByteBuffer` without copying it ## What Adds `TTFParser.parse(ByteBuffer)`, which reads the font in place. Each font receives its own slice of the buffer, so multiple fonts can be parsed from one buffer and used in different threads. `GlyphTable` now has a view of its part of the font data. Before, it copied `glyf` twice. Streams that aren't in memory (e.g. a TTC over a file) still copy, but only once. `RandomAccessReadDataStream` holds a `ByteBuffer` instead of a `byte[]` and an `int` position. Behaviour is otherwise unchanged. Arial Unicode MS (23.3 MB, glyf 22.4 MB), memory allocated per call: | | before | after | |---|---|---| | `parse(RandomAccessRead)` | 72.2 MB | 27.4 MB | | `parse(ByteBuffer)` | n/a | 4.1 MB | | `PDType0Font.load` + one page saved | 79.3 MB | 11.3 MB | ## Why Reduce memory usage while enabling safe resource sharing across threads. With a cheap parse, each document can have its own font instead of sharing one (PDFBOX-4220, PDFBOX-5779). ## Safety Tests: `TestTTFParser.testParseByteBuffer` and `RandomAccessReadBufferDataStreamTest.testCreateSubStream`. The fontbox and pdfbox module tests pass on 3.0 and trunk. ## LLM usage disclaimer Claude Opus 5.5 was used during development. The code submitted represents standard usage of the `ByteBuffer` interface. I would expect (and hope) that any code making use of this interface, proprietary or otherwise, would look similar, and am confident that this doesn't present a copyright risk. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
