Class LetterPdfGenerator.Builder

java.lang.Object
com.nsdev.lettergenerator.LetterPdfGenerator.Builder
Enclosing class:
LetterPdfGenerator

public static final class LetterPdfGenerator.Builder extends Object
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 Details

    • registerFont

      public LetterPdfGenerator.Builder registerFont(String family, FontVariant variant, Path path)
      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 styles
      variant - non-null face represented by the file
      path - non-null trusted local font file, read when build() is called
      Returns:
      this builder
      Throws:
      InvalidLetterException - if path is 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 styles
      variant - non-null face represented by the resource
      resourcePath - nonblank classpath resource name, resolved by build()
      Returns:
      this builder
    • hyphenationPatterns

      public LetterPdfGenerator.Builder hyphenationPatterns(String languageTag, byte[] trustedXml)
      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 tag
      trustedXml - pattern XML, copied immediately and validated by build
      Returns:
      this builder
      Throws:
      InvalidLetterException - for duplicate tags or absent bytes
    • build

      public LetterPdfGenerator 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 include FontVariant.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