internal

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package internal provides internal implementation details for the builder package. It must not be imported by external packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExportedMetadata

func ExportedMetadata(title, author string) metadata

ExportedMetadata constructs a metadata value from the builder config. This is the only way for the builder package to create an internal metadata struct while keeping the type unexported within the package.

Types

type FontBridge

type FontBridge struct {
	// contains filtered or unexported fields
}

FontBridge implements layout.FontResolver by delegating to creator's font subsystem. It bridges between the layout engine (which uses FontRef) and the creator package (which has Standard 14 fonts and CustomFont).

Standard 14 font families are resolved by mapping FontRef.Family to creator.FontName constants. Custom fonts registered via WithFont/WithFontFile are looked up by family name in the customFonts map.

func NewFontBridge

func NewFontBridge(customFonts map[string]*creator.CustomFont) *FontBridge

NewFontBridge creates a FontBridge with the given custom font map. The map may be empty; Standard 14 fonts are always available.

func (*FontBridge) Ascender

func (fb *FontBridge) Ascender(font layout.FontRef, size float64) float64

Ascender implements layout.FontResolver. Returns the ascender height above the baseline in PDF points.

func (*FontBridge) Descender

func (fb *FontBridge) Descender(font layout.FontRef, size float64) float64

Descender implements layout.FontResolver. Returns the magnitude of the descender below the baseline in PDF points. Always returns a positive value.

func (*FontBridge) LineBreak

func (fb *FontBridge) LineBreak(font layout.FontRef, text string, size float64, maxWidth float64) []string

LineBreak implements layout.FontResolver. It splits text into lines that each fit within maxWidth points, wrapping at word boundaries. CJK characters are treated as their own break opportunities.

The algorithm:

  1. Split text into words on whitespace.
  2. Accumulate words into a line until the next word would exceed maxWidth.
  3. For words wider than maxWidth (single long token), split at the character level.
  4. Handle CJK: any CJK rune is a valid break opportunity.

func (*FontBridge) LineHeight

func (fb *FontBridge) LineHeight(font layout.FontRef, size float64) float64

LineHeight implements layout.FontResolver. Returns the total line height (ascender + |descender|) in PDF points.

func (*FontBridge) MeasureString

func (fb *FontBridge) MeasureString(font layout.FontRef, text string, size float64) float64

MeasureString implements layout.FontResolver. Returns the width of text in PDF points at the given font and size.

type PDFRenderer

type PDFRenderer struct {
	// contains filtered or unexported fields
}

PDFRenderer walks a slice of layout.PageLayout values and emits PDF content by calling creator methods. It bridges the layout coordinate system (top-down, Y=0 at top) to the PDF coordinate system (bottom-up, Y=0 at bottom).

Coordinate conversion:

pdfY = pageHeight - layoutY

The renderer is stateless across pages; each page creates a new creator.Page.

func NewPDFRenderer

func NewPDFRenderer(cr *creator.Creator, customFonts map[string]*creator.CustomFont) *PDFRenderer

NewPDFRenderer creates a PDFRenderer using the given Creator and custom fonts.

func (*PDFRenderer) RenderDocument

func (r *PDFRenderer) RenderDocument(pages []layout.PageLayout, meta metadata) error

RenderDocument walks all PageLayouts, creating one creator.Page per layout page and rendering every Block tree onto it. If pages is empty (e.g. no content was added), a single blank A4 page is created so that the creator validation (which requires at least one page) does not fail.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL