props

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package props contain the public properties of paper.

Index

Constants

View Source
const (
	DefaultWatermarkSize  = 48.0
	DefaultWatermarkAlpha = 0.12
	DefaultWatermarkAngle = 45.0
)

Watermark default values applied by NormalizeWatermark.

Variables

View Source
var (
	// WhiteColor is a Color with all values in 255.
	WhiteColor = Color{Red: 255, Green: 255, Blue: 255}
	// BlackColor is a Color with all values in 0.
	BlackColor = Color{Red: 0, Green: 0, Blue: 0}
	// RedColor is a Color with only Red in 255.
	RedColor = Color{Red: 255, Green: 0, Blue: 0}
	// GreenColor is a Color with only Green in 255.
	GreenColor = Color{Red: 0, Green: 255, Blue: 0}
	// BlueColor is a Color with only Blue in 255.
	BlueColor = Color{Red: 0, Green: 0, Blue: 255}
)

Functions

This section is empty.

Types

type Barcode

type Barcode struct {
	// Left is the space between the left cell boundary to the barcode, if center is false.
	Left float64
	// Top is space between the upper cell limit to the barcode, if center is false.
	Top float64
	// Percent is how much the barcode will occupy the cell,
	// ex 100%: The barcode will fulfill the entire cell
	// ex 50%: The greater side from the barcode will have half the size of the cell.
	Percent float64
	// Proportion is the proportion between size of the barcode.
	// Ex: 16x9, 4x3...
	Proportion Proportion
	// Center define that the barcode will be vertically and horizontally centralized.
	Center bool
	// Type represents the barcode type. Default: code128
	Type consts.BarcodeType
}

Barcode represents properties from a barcode inside a cell.

func NormalizeBarcode

func NormalizeBarcode(b Barcode) Barcode

NormalizeBarcode returns a defaulted copy of b.

func (*Barcode) MakeValid

func (b *Barcode) MakeValid()

MakeValid from Barcode will make the properties from a barcode reliable to fit inside a cell and define default values for a barcode.

func (*Barcode) ToMap

func (b *Barcode) ToMap() map[string]any

ToMap from Barcode will return a map representation from Barcode.

func (*Barcode) ToRectProp

func (b *Barcode) ToRectProp() *Rect

ToRectProp from Barcode will return a Rect representation from Barcode.

type Cell

type Cell struct {
	// BackgroundColor defines which color will be applied to a cell.
	// Default: nil
	BackgroundColor *Color
	// BorderColor defines which color will be applied to a border cell
	// Default: nil
	BorderColor *Color
	// BorderType defines which kind of border will be applied to a cell.
	// Default: border.None
	BorderType border.Type
	// BorderThickness defines the border thickness applied to a cell.
	// Default: 0.2
	BorderThickness float64
	// LineStyle defines which line style will be applied to a cell.
	// Default: Solid
	LineStyle consts.LineStyle

	// Per-side padding (mm). Applied by components to shift content inward.
	PaddingTop    float64
	PaddingRight  float64
	PaddingBottom float64
	PaddingLeft   float64

	// Per-side margin (mm). Applied by styled rows and columns to inset the
	// painted cell box and its content from the allocated grid cell.
	MarginTop    float64
	MarginRight  float64
	MarginBottom float64
	MarginLeft   float64

	// Per-side border colors (nil = no override; falls back to BorderColor).
	BorderTopColor    *Color
	BorderRightColor  *Color
	BorderBottomColor *Color
	BorderLeftColor   *Color

	// Per-side border thickness (0 = no border for that side).
	// When any of these is non-zero the PerSideBorderStyler activates and
	// draws raw Line calls instead of CellFormat borders.
	BorderTopThickness    float64
	BorderRightThickness  float64
	BorderBottomThickness float64
	BorderLeftThickness   float64

	// Per-side border line style ("solid", "dashed", "dotted"). Empty = solid.
	BorderTopStyle    consts.LineStyle
	BorderRightStyle  consts.LineStyle
	BorderBottomStyle consts.LineStyle
	BorderLeftStyle   consts.LineStyle

	// BackgroundGradient, when non-nil, paints a gradient behind the cell
	// (overrides BackgroundColor when both are set).
	BackgroundGradient *Gradient

	// BackgroundImage, when non-nil, paints an image behind the cell content.
	BackgroundImage *CellBackgroundImage

	// BoxShadow holds the shadows to paint behind the cell (up to 4).
	BoxShadow []Shadow

	// Outline fields. Outline is drawn OUTSIDE the cell box (does not affect layout).
	OutlineWidth  float64
	OutlineStyle  consts.LineStyle
	OutlineColor  *Color
	OutlineOffset float64 // mm; positive = further out, negative = inside border

	// BorderRadius is the uniform corner radius in mm. When per-corner radii
	// below are set, they override this uniform value for that corner.
	// When any radius is set, the borderRadiusStyler owns the entire border
	// render and per-side stroke thicknesses are averaged into a single width.
	BorderRadius float64

	// Per-corner border radius (mm). 0 = inherit from BorderRadius.
	BorderRadiusTopLeft     float64
	BorderRadiusTopRight    float64
	BorderRadiusBottomLeft  float64
	BorderRadiusBottomRight float64
}

Cell is the representation of a cell in the grid system. This can be applied to Col or Row.

func CloneCell

func CloneCell(c *Cell) *Cell

CloneCell returns an independent copy of c.

func (*Cell) EffectiveRadii

func (c *Cell) EffectiveRadii() (float64, float64, float64, float64)

EffectiveRadii returns the four corner radii (top-left, top-right, bottom-right, bottom-left) applying the precedence: per-corner > uniform > 0.

func (*Cell) HasBorderRadius

func (c *Cell) HasBorderRadius() bool

HasBorderRadius reports whether any uniform or per-corner radius is non-zero.

func (*Cell) HasPerSideBorders

func (c *Cell) HasPerSideBorders() bool

HasPerSideBorders reports whether any per-side border thickness is set.

func (*Cell) ToMap

func (c *Cell) ToMap() map[string]any

ToMap adds the Cell fields to the map.

type CellBackgroundImage

type CellBackgroundImage struct {
	Bytes     []byte
	Extension extension.Type
	Rect      Rect
	Size      string
	Position  string
	Repeat    string
}

CellBackgroundImage is a resolved image background for a styled cell.

type Checkbox

type Checkbox struct {
	// Checked defines whether the checkbox is marked.
	Checked bool
	// Top is the amount of space between the upper cell limit and the checkbox.
	Top float64
	// Left is the amount of space between the left cell boundary and the checkbox.
	Left float64
	// Size is the size of the checkbox square in mm.
	Size float64
}

Checkbox represents properties from a Checkbox inside a cell.

func NormalizeCheckbox

func NormalizeCheckbox(c Checkbox) Checkbox

NormalizeCheckbox returns a defaulted copy of c.

func (*Checkbox) MakeValid

func (c *Checkbox) MakeValid()

MakeValid from Checkbox define default values for a Checkbox.

func (*Checkbox) ToMap

func (c *Checkbox) ToMap() map[string]any

ToMap converts a Checkbox to a map.

type Color

type Color struct {
	// Red is the amount of red
	Red int
	// Green is the amount of red
	Green int
	// Blue is the amount of red
	Blue int
	// Alpha is the translucency in [0, 1]; nil = fully opaque (default).
	Alpha *float64
}

Color represents a color in the RGB (Red, Green, Blue) space, is possible mix values, when all values are 0 the result color is black when all values are 255 the result color is white.

Alpha controls translucency on render paths that honor it (gofpdf SetAlpha via core.AlphaProvider). It is a pointer so existing zero-value literals (Color{Red,Green,Blue}) remain opaque and byte-identical to prior output. nil = opaque; non-nil values in [0, 1] activate the alpha pipeline. Render paths that read this field:

  • cellwriter/fillcolorstyler.go (background fills)
  • cellwriter/bordercolorstyler.go (border strokes)
  • cellwriter/borderradius.go (rounded fill+stroke)
  • components/richtext (text color)

func Black

func Black() Color

Black returns an independent black Color value.

func Blue

func Blue() Color

Blue returns an independent blue Color value.

func CloneColor

func CloneColor(c *Color) *Color

CloneColor returns an independent copy of c.

func Red

func Red() Color

Red returns an independent red Color value.

func White

func White() Color

White returns an independent white Color value.

func (*Color) ToString

func (c *Color) ToString() string

ToString returns a string representation of the Color, including Alpha when it has been set (non-nil pointer). Opaque colours use the legacy RGB(...) form for backward compatibility with snapshot tests.

type Font

type Font struct {
	// Family of the text, ex: constf.Arial, helvetica and etc.
	Family string
	// Style of the text, ex: constf.Normal, bold and etc.
	Style fontstyle.Type
	// Size of the text.
	Size float64
	// Color define the font color.
	Color *Color
}

Font represents properties from a text.

func NormalizeFont

func NormalizeFont(f Font, defaultFamily string) Font

NormalizeFont returns a defaulted copy of f.

func (*Font) AppendMap

func (f *Font) AppendMap(m map[string]any) map[string]any

AppendMap appends the font fields to a map.

func (*Font) MakeValid

func (f *Font) MakeValid(defaultFamily string)

MakeValid from Font define default values for a Signature.

func (*Font) ToTextProp

func (f *Font) ToTextProp(align consts.Align, top float64, verticalPadding float64) *Text

ToTextProp from Font return a Text based on Font.

type Gradient

type Gradient struct {
	Kind     GradientKind
	AngleDeg float64        // linear angle or conic starting angle
	Circle   bool           // radial only
	CX, CY   float64        // radial/conic centre (0–1 fractions)
	Stops    []GradientStop // at least 2, positions in [0,1]
}

Gradient holds the resolved gradient parameters ready for the renderer.

type GradientKind

type GradientKind int

GradientKind distinguishes supported CSS gradient families.

const (
	GradientLinear GradientKind = iota
	GradientRadial
	GradientConic
)

type GradientStop

type GradientStop struct {
	Color    Color
	Position float64
}

GradientStop is a color + position (0.0-1.0) in a gradient.

type Line

type Line struct {
	// Color define the line color.
	Color *Color
	// Style define the line style (solid or dashed).
	Style consts.LineStyle
	// Thickness define the line thicknesl.
	Thickness float64
	// Orientation define if line would be horizontal or vertical.
	Orientation consts.Orientation
	// OffsetPercent define where the line would be placed, 0 is the start of cell, 50 the middle and 100 the end.
	OffsetPercent float64
	// SizePercent define the size of the line inside cell.
	SizePercent float64
}

Line represents properties from a Line inside a cell.

func NormalizeLine

func NormalizeLine(l Line) Line

NormalizeLine returns a defaulted copy of l.

func (*Line) MakeValid

func (l *Line) MakeValid()

MakeValid from Line define default values for a Line.

func (*Line) ToMap

func (l *Line) ToMap() map[string]any

ToMap returns a map with the Line fields.

type Outline added in v0.2.0

type Outline struct {
	// Title is the text shown in the outline panel. When empty, the
	// component's own text content is used.
	Title string
	// Level is the nesting depth of the entry: 0 is the top level, 1 is
	// nested under the previous level-0 entry, and so on. Negative values
	// are treated as 0.
	Level int
}

Outline marks a component as an entry in the PDF document outline (the bookmark sidebar shown by PDF viewers).

func CloneOutline added in v0.2.0

func CloneOutline(o *Outline) *Outline

CloneOutline returns a deep copy of o, or nil when o is nil.

func (*Outline) NormalizedLevel added in v0.2.0

func (o *Outline) NormalizedLevel() int

NormalizedLevel returns the outline level clamped to >= 0.

func (*Outline) ResolveTitle added in v0.2.0

func (o *Outline) ResolveTitle(fallback string) string

ResolveTitle returns the explicit title, or fallback when no title is set.

func (*Outline) ToMap added in v0.2.0

func (o *Outline) ToMap(m map[string]any) map[string]any

ToMap appends outline attributes to a component attribute map.

type PageNumber

type PageNumber struct {
	// Pattern is the string pattern which will be used to apply the page count component.
	Pattern string
	// Place defines where the page count component will be placed.
	Place Place
	// Family defines which font family will be applied to page count.
	Family string
	// Style defines which font style will be applied to page count.
	Style fontstyle.Type
	// Size defines which font size will be applied to page count.
	Size float64
	// Color defines which will be applied to page count.
	Color *Color
}

PageNumber have attributes of page number.

func ClonePageNumber

func ClonePageNumber(p PageNumber) PageNumber

ClonePageNumber returns an independent copy of p.

func (*PageNumber) AppendMap

func (p *PageNumber) AppendMap(m map[string]any) map[string]any

AppendMap appends the font fields to a map.

func (*PageNumber) GetNumberTextProp

func (p *PageNumber) GetNumberTextProp(height float64) *Text

GetNumberTextProp returns the Text properties of the page number.

func (*PageNumber) GetPageString

func (p *PageNumber) GetPageString(current, total int) string

GetPageString returns the page string.

func (*PageNumber) WithFont

func (p *PageNumber) WithFont(font *Font)

WithFont apply font if not defined before.

type Place

type Place string

Place is the representation of a place in a page.

const (
	// LeftTop is the place in the left top of the page.
	LeftTop Place = "left_top"
	// Top is the place in the top of the page.
	Top Place = "top"
	// RightTop is the place in the right top of the page.
	RightTop Place = "right_top"
	// LeftBottom is the place in the left bottom of the page.
	LeftBottom Place = "left_bottom"
	// Bottom is the place in the bottom of the page.
	Bottom Place = "bottom"
	// RightBottom is the place in the right bottom of the page.
	RightBottom Place = "right_bottom"
)

func (Place) IsValid

func (p Place) IsValid() bool

IsValid checks if the place is valid.

type Proportion

type Proportion struct {
	// Width from the rectangle: Barcode, image and etc.
	Width float64
	// Height from the rectangle: Barcode, image and etc.
	Height float64
}

Proportion represents a proportion from a rectangle, example: 16x9, 4x3...

type Rect

type Rect struct {
	// Left is the space between the left cell boundary to the rectangle, if center is false.
	Left float64
	// Top is space between the upper cell limit to the barcode, if center is false.
	Top float64
	// Percent is how much the rectangle will occupy the cell,
	// ex 100%: The rectangle will fulfill the entire cell
	// ex 50%: The greater side from the rectangle will have half the size of the cell.
	Percent float64
	// indicate whether only the width should be used as a reference to calculate the component size, disregarding the height
	// ex true: The component will be scaled only based on the available width, disregarding the available height
	JustReferenceWidth bool
	// Center define that the barcode will be vertically and horizontally centralized.
	Center bool
	// ObjectFit defines how an image should fit into its content box.
	ObjectFit string
	// ObjectPosition defines the image alignment inside its content box.
	ObjectPosition string
}

Rect represents properties from a rectangle (Image, QrCode or Barcode) inside a cell.

func NormalizeRect

func NormalizeRect(r Rect) Rect

NormalizeRect returns a defaulted copy of r.

func (*Rect) MakeValid

func (r *Rect) MakeValid()

MakeValid from Rect will make the properties from a rectangle reliable to fit inside a cell and define default values for a rectangle.

func (*Rect) ToMap

func (r *Rect) ToMap() map[string]any

ToMap from Rect will return a map representation from Rect.

type RichImage

type RichImage struct {
	Bytes          []byte
	Extension      extension.Type
	Width          float64
	Height         float64
	Alt            string
	ObjectFit      string
	ObjectPosition string
}

RichImage is an inline image embedded in a RichText paragraph. Width and Height are measured in millimetres.

type RichRun

type RichRun struct {
	Text          string
	Image         *RichImage
	Family        string
	Style         fontstyle.Type
	Size          float64
	SizeScale     float64 // multiplier applied after Size/default font resolution; 0 = unchanged
	Color         *Color
	Underline     bool
	Strikethrough bool
	Hyperlink     *string
	VerticalAlign string // "baseline" | "sub" | "super"
	Hidden        bool   // preserves layout but skips painting for CSS visibility:hidden

	// LetterSpacing is extra character spacing in mm (0 = default).
	LetterSpacing float64
	// Background, when non-nil, paints a filled rectangle behind the run before
	// drawing the text. Used by HTML <mark>, <kbd>, inline <code>.
	Background *Color
	// LocalAnchor, when non-empty, makes the run an internal PDF link target
	// to the named destination (registered via id="…" on a block element).
	// Takes precedence over Hyperlink.
	LocalAnchor string

	// TextShadow, when non-nil, draws a shadow behind the run text. Only the
	// first shadow is stored here for compatibility. TextShadows stores the full
	// CSS comma-separated list when available.
	TextShadow *Shadow
	// TextShadows, when non-empty, draws every shadow behind the run text in
	// order before the normal text is painted.
	TextShadows []Shadow
}

RichRun is a single styled segment within a RichText paragraph.

func CloneRichRuns

func CloneRichRuns(runs []RichRun) []RichRun

CloneRichRuns returns an independent copy of runs.

func NormalizeRichRun

func NormalizeRichRun(run RichRun, font *Font) RichRun

NormalizeRichRun returns a defaulted copy of run.

type RichText

type RichText struct {
	Top               float64
	Bottom            float64
	Left              float64
	Right             float64
	Align             consts.Align
	LineHeight        float64
	BreakLineStrategy consts.BreakLineStrategy
	FirstLineIndent   float64
	WhiteSpace        string

	// AnchorResolver, when non-nil, is called with a LocalAnchor name to
	// obtain the PDF link ID for per-run internal anchor rectangles. It is set
	// at render time by richtext.RichText.Render when the provider implements
	// core.LinkProvider and the component was built with an anchor registry.
	AnchorResolver func(name string) int

	// Outline, when set, adds this paragraph as an entry in the PDF document
	// outline (the bookmark sidebar). When Title is empty, the concatenated
	// run text is used.
	Outline *Outline
}

RichText holds paragraph-level properties for a RichText component.

func NormalizeRichText

func NormalizeRichText(r RichText, _ ...*Font) RichText

NormalizeRichText returns a defaulted copy of r.

func (*RichText) MakeValid

func (r *RichText) MakeValid(font *Font)

MakeValid fills in default values for RichText paragraph props.

type Shadow

type Shadow struct {
	OffsetX    float64 // mm
	OffsetY    float64 // mm
	BlurRadius float64 // mm (approximated as multi-rect overlay)
	Spread     float64 // mm (expands rect uniformly before blur)
	Color      *Color  // nil = use default black
	Inset      bool    // draw inside cell rather than behind it
}

Shadow holds the resolved parameters of a single CSS shadow entry.

func CloneShadow

func CloneShadow(shadow Shadow) Shadow

CloneShadow returns an independent copy of shadow.

type Signature

type Signature struct {
	// FontFamily of the text, ex: consts.Arial, helvetica and etc.
	FontFamily string
	// FontStyle of the text, ex: consts.Normal, bold and etc.
	FontStyle fontstyle.Type
	// FontSize of the text.
	FontSize float64
	// FontColor define the font color.
	FontColor *Color
	// LineColor define the line color.
	LineColor *Color
	// LineStyle define the line style (solid or dashed).
	LineStyle consts.LineStyle
	// LineThickness define the line thickness.
	LineThickness float64

	SafePadding float64
}

Signature represents properties from a signature.

func NormalizeSignature

func NormalizeSignature(s Signature, defaultFontFamily string) Signature

NormalizeSignature returns a defaulted copy of s.

func (*Signature) MakeValid

func (s *Signature) MakeValid(defaultFontFamily string)

MakeValid from Signature define default values for a Signature.

func (*Signature) ToFontProp

func (s *Signature) ToFontProp() *Font

ToFontProp from Signature return a Font based on Signature.

func (*Signature) ToLineProp

func (s *Signature) ToLineProp(offsetPercent float64) *Line

ToLineProp from Signature return a Line based on Signature.

func (*Signature) ToMap

func (s *Signature) ToMap() map[string]any

ToMap returns a map with the Signature fields.

func (*Signature) ToTextProp

func (s *Signature) ToTextProp(align consts.Align, top float64, verticalPadding float64) *Text

ToTextProp from Signature return a Text based on Signature.

type Text

type Text struct {
	// Top is the amount of space between the upper cell limit and the text.
	Top float64
	// Bottom is the amount of space between the lower cell limit and the text. (Used by auto row only)
	Bottom float64
	// Left is the minimal amount of space between the left cell boundary and the text.
	Left float64
	// Right is the minimal amount of space between the right cell boundary and the text.
	Right float64
	// Family of the text, ex: consts.Arial, helvetica and etc.
	Family string
	// Style of the text, ex: consts.Normal, bold and etc.
	Style fontstyle.Type
	// Size of the text.
	Size float64
	// Align of the text.
	Align consts.Align
	// BreakLineStrategy define the break line strategy.
	BreakLineStrategy consts.BreakLineStrategy
	// VerticalPadding define an additional space between linet.
	VerticalPadding float64
	// Color define the font style color.
	Color *Color
	// Hyperlink define a link to be opened when the text is clicked.
	Hyperlink *string
	// Outline, when set, adds this text as an entry in the PDF document
	// outline (the bookmark sidebar). Outline entries only survive
	// concurrent/low-memory generation when merged documents preserve them.
	Outline *Outline
}

Text represents properties from a Text inside a cell.

func NormalizeText

func NormalizeText(t Text, font *Font) Text

NormalizeText returns a defaulted copy of t.

func (*Text) MakeValid

func (t *Text) MakeValid(font *Font)

MakeValid from Text define default values for a Text.

func (*Text) ToMap

func (t *Text) ToMap() map[string]any

ToMap converts a Text to a map.

type Watermark added in v0.2.0

type Watermark struct {
	// Text is the watermark content, e.g. "DRAFT". Set via
	// config.WithWatermark.
	Text string
	// Family of the watermark font, ex: consts.FontFamilyArial.
	Family string
	// Style of the watermark font, ex: fontstyle.Bold.
	Style fontstyle.Type
	// Size is the font size in points (default 48). When the rendered text
	// would exceed the page diagonal, the size is scaled down to fit.
	Size float64
	// Color of the watermark text (default black; the low alpha keeps it
	// subtle).
	Color *Color
	// Alpha is the opacity in [0, 1] (default 0.12).
	Alpha float64
	// Angle is the counter-clockwise rotation in degrees around the page
	// center (default 45).
	Angle float64
}

Watermark configures the translucent diagonal text stamped on every page. The watermark is drawn under the page content (right after the background) so it never obscures text.

func CloneWatermark added in v0.2.0

func CloneWatermark(w *Watermark) *Watermark

CloneWatermark returns a deep copy of w, or nil when w is nil.

func NormalizeWatermark added in v0.2.0

func NormalizeWatermark(w Watermark) Watermark

NormalizeWatermark returns a defaulted, clamped copy of w.

func (*Watermark) ToMap added in v0.2.0

func (w *Watermark) ToMap(m map[string]any) map[string]any

ToMap appends watermark attributes to a config attribute map.

Jump to

Keyboard shortcuts

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