Package com.nsdev.lettergenerator
Class LetterPdfGenerator.Builder
java.lang.Object
com.nsdev.lettergenerator.LetterPdfGenerator.Builder
- Enclosing class:
- LetterPdfGenerator
Mutable configuration that accumulates trusted Java font sources in registration order.
Registration defers font reads to
build(); each build loads a separate immutable
font snapshot. Reusing or changing this builder does not alter an existing generator. Each
custom family requires a regular face and any bold/italic faces used by its content.-
Method Summary
Modifier and TypeMethodDescriptionbuild()Reads and validates every registered font and creates an independent reusable generator.hyphenationPatterns(String languageTag, byte[] trustedXml) Registers trusted TeX-style FOP hyphenation XML for one language or language-country.registerClasspathFont(String family, FontVariant variant, String resourcePath) Appends a TrueType classpath source without resolving or reading it yet.registerFont(String family, FontVariant variant, Path path) Appends a local TrueType font source without reading the file yet.
-
Method Details
-
registerFont
Appends a local TrueType font source without reading the file yet. Family names and variants are checked at build time; duplicate family/variant pairs are errors rather than replacements. Built-in family names cannot be overridden.- Parameters:
family- nonblank, case-sensitive family identifier used by document stylesvariant- non-null face represented by the filepath- non-null trusted local font file, read whenbuild()is called- Returns:
- this builder
- Throws:
InvalidLetterException- ifpathis null
-
registerClasspathFont
public LetterPdfGenerator.Builder registerClasspathFont(String family, FontVariant variant, String resourcePath) Appends a TrueType classpath source without resolving or reading it yet. At build time the thread context class loader is used, falling back to the library loader if absent. A leading slash is ignored. Duplicate family/variant pairs are rejected then.- Parameters:
family- nonblank, case-sensitive family identifier used by document stylesvariant- non-null face represented by the resourceresourcePath- nonblank classpath resource name, resolved bybuild()- Returns:
- this builder
-
hyphenationPatterns
Registers trusted TeX-style FOP hyphenation XML for one language or language-country. XML declarations of external entities or DTDs are rejected. No dictionary lookup or download is performed; document hyphenation requires its exact registered tag.- Parameters:
languageTag- BCP 47 language or language-country tagtrustedXml- pattern XML, copied immediately and validated by build- Returns:
- this builder
- Throws:
InvalidLetterException- for duplicate tags or absent bytes
-
build
Reads and validates every registered font and creates an independent reusable generator. Only TrueType files with TrueType outlines are accepted. Every custom family must includeFontVariant.REGULAR; other faces must be registered if document styles use them. Later file changes or builder registrations do not alter the returned generator.- Returns:
- a generator owning the loaded font snapshot
- Throws:
InvalidLetterException- if a source cannot be read, is not a supported font, has a blank family or null variant, duplicates a face, overrides a built-in family, or belongs to a family without a regular face
-