fix(pdf): Cyrillic in print templates renders as '#' - bundle DejaVu Sans for FOP#6124
Merged
Conversation
…t with FOP FOP's built-in base-14 fonts (Helvetica/Times/Courier) are metric-only and Latin-1 encoded, and PDFFacade created a bare FopFactory with no font configuration - so every non-Latin glyph in a print template (e.g. a Cyrillic title in a Sales Invoice standard.print) rendered as '#'. - api-pdf: bundle DejaVu Sans (regular/bold/oblique/bold-oblique, Bitstream Vera license) under META-INF/fonts/dejavu and build the (now cached) FopFactory from a font configuration that embeds them as subsets; the TTFs are extracted to a temp dir because FOP cannot read fonts from inside a jar. Falls back to the unconfigured factory with a warning if extraction fails. - parsers-document: XslFoRenderer emits font-family="DejaVu Sans, Helvetica" so generated print templates pick up the Unicode font. - test: Cyrillic template renders and the PDF embeds a DejaVuSans subset. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
Printing a document whose template contains non-Latin text (e.g. a Cyrillic title
Фактураin the generatedstandard.print) produces a PDF where every non-Latin character renders as#.Root cause:
PDFFacadecreated a bareFopFactorywith no font configuration, so Apache FOP only had its built-in base-14 fonts (Helvetica/Times/Courier). Those are metric-only, Latin-1 encoded fonts with no Cyrillic glyphs, and FOP substitutes#for every glyph the font lacks.XslFoRendereradditionally hard-codedfont-family="Helvetica"at thefo:root.Fix
META-INF/fonts/dejavuand build the now-cachedFopFactoryfrom a font configuration that embeds them as subsets. The TTFs are extracted to a temp directory first because FOP cannot load fonts from inside a jar. If extraction fails, falls back to the unconfigured factory with a warning.XslFoRendereremitsfont-family="DejaVu Sans, Helvetica"so every generated print stylesheet picks up the Unicode font.Verification
mvn test -pl components/api/api-pdf,modules/parsers/document: 94 tests green, no FOP "glyph not available" warnings in the run.🤖 Generated with Claude Code