settings

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package settings parses the renderSettings JSON accepted by the wasm entrypoint (cmd/wasm). It is a separate, build-tag-free package so the parsing logic can be unit-tested on the host toolchain.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Margins

type Margins struct {
	Top    float64 `json:"top"`
	Right  float64 `json:"right"`
	Bottom float64 `json:"bottom"`
	Left   float64 `json:"left"`
}

Margins holds page margins in PDF points. It unmarshals from either a single JSON number (applied to all four sides) or an object with any of top/right/bottom/left.

func (*Margins) UnmarshalJSON

func (m *Margins) UnmarshalJSON(b []byte) error

UnmarshalJSON accepts 36 or {"top":36,"left":18,...}.

type Settings

type Settings struct {
	PageSize    string   `json:"pageSize"`    // named size, e.g. "a4", "letter" (default letter)
	Orientation string   `json:"orientation"` // "portrait" (default) or "landscape"
	Margins     *Margins `json:"margins,omitempty"`

	MediaType            string `json:"mediaType"`
	PdfProfile           string `json:"pdfProfile"`
	PdfTitle             string `json:"pdfTitle"`
	PdfAuthor            string `json:"pdfAuthor,omitempty"`
	PdfSubject           string `json:"pdfSubject,omitempty"`
	PdfKeywords          string `json:"pdfKeywords,omitempty"`
	IgnoreResourceErrors bool   `json:"ignoreResourceErrors"`
	CssDpi               int    `json:"cssDpi"`
	Watermark            string `json:"watermark,omitempty"`  // optional watermark text
	HeaderHTML           string `json:"headerHtml,omitempty"` // HTML for page header
	FooterHTML           string `json:"footerHtml,omitempty"` // HTML for page footer

	// Asset / font resolution (issue #426).
	AllowAbsolutePaths bool   `json:"allowAbsolutePaths"`         // permit absolute OS paths in the document (default false)
	BaseDir            string `json:"baseDir,omitempty"`          // directory used as BaseFS root for relative asset paths
	FallbackFontPath   string `json:"fallbackFontPath,omitempty"` // Unicode fallback font path (BaseFS-relative or absolute)
	FallbackFontData   string `json:"fallbackFontData,omitempty"` // base64-encoded TTF/OTF used as the Unicode fallback font
}

Settings is the renderSettings JSON accepted by folioRender.

func Parse

func Parse(jsonStr string) (Settings, error)

Parse decodes the renderSettings JSON.

func (Settings) ApplyOptions

func (s Settings) ApplyOptions(opts *html.Options) error

ApplyOptions wires the asset-resolution settings into html.Options: baseDir becomes BaseFS (via os.DirFS), allowAbsolutePaths is passed through, and the fallback font is set from fallbackFontData (base64, takes precedence) or fallbackFontPath. Defaults stay safe: with no settings, BaseFS is nil and absolute paths are denied.

func (Settings) ResolvePageSize

func (s Settings) ResolvePageSize() document.PageSize

ResolvePageSize maps the named page size (defaulting to US Letter) and applies the orientation, swapping dimensions for landscape.

Jump to

Keyboard shortcuts

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