css

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package css parses the CSS properties supported by the engine.

Index

Constants

View Source
const PxToPt = 0.75

PxToPt converts CSS pixels to PDF points at 96 DPI.

View Source
const UAStylesheet = `` /* 500-byte string literal not displayed */

UAStylesheet contains the default styles for HTML elements.

Variables

This section is empty.

Functions

func ParseColor

func ParseColor(s string) (c [4]float64, ok bool)

ParseColor converts a supported CSS color to RGBA components in the range [0,1]. It returns false for invalid values and the transparent keyword. Colors without alpha use 1.

func ParsePageFooterStyle added in v1.3.2

func ParsePageFooterStyle(src string) ([]ContentChunk, PageFooterStyle, bool)

ParsePageFooterStyle reads the @bottom-center content and supported style.

func ParsePageRule

func ParsePageRule(src string) (w, h, margin float64, ok bool)

ParsePageRule reads the first @page rule and returns its width, height, and margin in points. A missing size returns 0,0; a missing margin returns -1. It returns false only when no @page rule exists.

Types

type ContentChunk

type ContentChunk struct {
	Literal string
	Counter string // "page" | "pages" ("" = literal)
}

ContentChunk is a literal or counter in a page footer's content.

func ParsePageFooter

func ParsePageFooter(src string) ([]ContentChunk, bool)

ParsePageFooter reads @bottom-center content from the first @page rule that defines it.

type Declarations

type Declarations map[string]string

Declarations contains normalized CSS properties and their values.

func ParseInlineStyle

func ParseInlineStyle(style string) (Declarations, error)

ParseInlineStyle parses inline CSS declarations and ignores invalid ones.

func ParseInlineStyleWithWarnings

func ParseInlineStyleWithWarnings(style string) (Declarations, []string, error)

ParseInlineStyleWithWarnings parses inline declarations and reports those it discards.

type FontFace

type FontFace struct {
	Family string
	Src    string
	Weight int
	Style  string
}

FontFace represents an @font-face rule with a family and unresolved src value.

func ParseFontFaces

func ParseFontFaces(src string) ([]FontFace, error)

ParseFontFaces returns @font-face rules in source order.

type PageFooterStyle added in v1.3.2

type PageFooterStyle struct {
	FontSize float64
	Color    [4]float64
	HasColor bool
}

PageFooterStyle contains the supported typography and color for @bottom-center.

type PageMargins

type PageMargins struct {
	Top, Right, Bottom, Left             float64
	TopPercent, RightPercent             bool
	BottomPercent, LeftPercent           bool
	HasTop, HasRight, HasBottom, HasLeft bool
}

PageMargins stores absolute values in points and percentage values in percent. Presence bits let layout inherit its default for omitted sides.

func (PageMargins) Resolve

func (m PageMargins) Resolve(width, height float64) PageMargins

Resolve converts percentage margins to points using the page-box axes.

type PageMarks

type PageMarks uint8

PageMarks selects printer registration marks from the CSS marks descriptor.

const (
	PageMarkCrop PageMarks = 1 << iota
	PageMarkCross
)

type PageRule

type PageRule struct {
	Selector     PageSelector
	Style        PageStyle
	Declarations Declarations
	MarginBoxes  map[string]Declarations
}

PageRule keeps each @page selector and its computed declarations in source order.

func ParsePageRules

func ParsePageRules(src string) []PageRule

ParsePageRules reads all @page rules, retaining selectors and source order.

func ResolvePageRule

func ResolvePageRule(rules []PageRule, name string, pageNumber int) PageRule

ResolvePageRule cascades descriptors and margin-box declarations for one page context.

type PageSelector

type PageSelector struct {
	Name   string
	Pseudo string
}

PageSelector identifies the named page and optional page pseudo-class.

type PageStyle

type PageStyle struct {
	Width, Height float64
	HasSize       bool
	Margins       PageMargins
	Background    [4]float64
	HasBackground bool
	Rotation      int // PDF page rotation in clockwise degrees.
	HasRotation   bool
	Bleed         float64
	HasBleed      bool
	Marks         PageMarks
	HasMarks      bool
}

PageStyle is the page-box geometry parsed from one @page rule.

func ParsePageStyle

func ParsePageStyle(src string) (PageStyle, bool)

ParsePageStyle reads page-box size and margins from the first @page rule.

func ResolvePageDefaults

func ResolvePageDefaults(rules []PageRule) PageStyle

ResolvePageDefaults cascades only unnamed, unqualified @page rules.

func ResolvePageStyle

func ResolvePageStyle(rules []PageRule, name string, pageNumber int) PageStyle

ResolvePageStyle applies matching @page rules in source order. Page numbers are one-based.

type Rule

type Rule struct {
	Selector string
	Decls    Declarations
	Order    int
}

Rule contains a selector, its declarations, and its order in the stylesheet.

func ParseStylesheet

func ParseStylesheet(src string) ([]Rule, error)

ParseStylesheet extracts selector rules in source order and ignores at-rules and invalid input.

Jump to

Keyboard shortcuts

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