davsclaus opened a new pull request, #30885: URL: https://github.com/apache/camel/pull/30885
CAMEL-15912: camel-pdf - write text with a TrueType font file of the new fontFile option JIRA: https://issues.apache.org/jira/browse/CAMEL-15912 ## Problem The `font` option of `pdf:create` / `pdf:append` takes only the 14 standard fonts of PDF (`HELVETICA`, `COURIER`, ...), and `DefaultWriteStrategy` / `DefaultLineBuilderStrategy` always use `new PDType1Font(Standard14Fonts...)`. These fonts cover only Latin text (WinAnsiEncoding), so any text with Cyrillic, Greek, Chinese or emoji characters fails the exchange, for both `lineTermination` and `autoFormatting`: ``` IllegalArgumentException: U+041F ('Pecyrillic') is not available in the font Helvetica, encoding: WinAnsiEncoding ``` There was no way to use another font. ## Change - New endpoint option `fontFile`: a TrueType font file (`.ttf`), loaded as a resource (`classpath:` by default, `file:`, `http:`) via `ResourceHelper` when the endpoint is initialized. The endpoint also checks that PDFBox can use it, so a missing file or an unsupported font (OpenType with CFF outlines, `.ttc` collection) fails when the endpoint is created rather than with the first message. - Both strategies get the font from a new `PdfUtils.createFont(...)`: `PDType0Font.load(document, ...)` when `fontFile` is set, else the standard font of `font`. The write strategy creates the font once per document (so it is embedded once, as a subset, for all pages); the line builder of `autoFormatting` measures with it in a scratch document. It also no longer creates a new font object for every width measurement. - Without `fontFile`, the `IllegalArgumentException` of a character the standard font cannot show now adds a hint to use the `fontFile` option (same exception type, original message kept). - Docs: new "Fonts" section in the component page; `font` option description says it covers only Latin text. A character the font file does not have still fails the operation (PDFBox), rather than being left out. Only ISO control characters are left out, as before. ## Tests `PdfFontFileTest` (8 tests) uses `LiberationSans-Regular.ttf`, which the `pdfbox` jar already ships (`org/apache/pdfbox/resources/ttf/`, SIL Open Font License, Latin + Cyrillic + Greek), so no font is added to the repo: create from `classpath:` and from `file:` (a `@TempDir` copy), `autoFormatting` over several pages with one embedded subset font, append, a character missing from the font file, the standard-font error hint, a missing file and a file that is not a font failing at endpoint creation. Fails on main: 6 of the 8 (unknown option `fontFile`; no hint in the standard-font error). The two endpoint-creation tests also pass on main, only because the option is unknown there. camel-pdf: 32 tests, all pass. ## Upgrade notes None: a new option; existing routes behave as before (only the exception message of an unsupported character gains a hint). _Claude Code on behalf of davsclaus_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
