frontend

package
v0.0.0-...-3435f2a Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2023 License: BSD-3-Clause Imports: 32 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// CallbackPostLinebreak gets called right after the line break algorithm
	// finishes.
	CallbackPostLinebreak callbackType = iota
)
View Source
const (
	// HangingPunctuationAllowEnd allows hanging punctuation at the end of a
	// line.
	HangingPunctuationAllowEnd = 1
)

Variables

View Source
var (
	// ErrEmptyFF is returned when requesting a font from an empty font family.
	ErrEmptyFF = fmt.Errorf("no face defined in the font family yet")
	// ErrUnfulfilledFamilyRequest is returned when the GetFace method does
	// cannot find the exact family member but has to chose another member.
	ErrUnfulfilledFamilyRequest = fmt.Errorf("the font family does not have the exact requested member")
)

Functions

func DebugText

func DebugText(ts *Text) string

DebugText returns an XML representation of the Text structure.

func DebugTextToFile

func DebugTextToFile(filename string, ts *Text) error

DebugTextToFile writes an XML representation of the Text to the filename. It overwrites the file if it already exists.

func GetLanguage

func GetLanguage(langname string) (*lang.Lang, error)

GetLanguage returns a language object for the language.

func Hyphenate

func Hyphenate(nodelist node.Node, defaultLang *lang.Lang)

Hyphenate inserts hyphenation points in to the list.

Types

type BorderStyle

type BorderStyle uint

BorderStyle represents the HTML border styles such as solid, dashed, ...

const (
	// BorderStyleNone is no border
	BorderStyleNone BorderStyle = iota
	// BorderStyleSolid is a solid line
	BorderStyleSolid
)

type ColSpec

type ColSpec struct {
	ColumnWidth *node.Glue
}

ColSpec represents common traits for a column such as width.

type Document

type Document struct {
	FontFamilies    map[string]*FontFamily
	Doc             *document.PDFDocument
	DefaultFeatures []harfbuzz.Feature
	// contains filtered or unexported fields
}

Document holds convenience functions.

func New

func New(filename string) (*Document, error)

New creates a new PDF file. After Doc.Finish() is called, the file is closed.

func (*Document) AddDataToFontsource

func (fe *Document) AddDataToFontsource(fs *FontSource, fontname string) error

AddDataToFontsource adds the font data to the font source.

func (*Document) BuildNodelistFromString

func (fe *Document) BuildNodelistFromString(ts TypesettingSettings, str string) (node.Node, error)

BuildNodelistFromString returns a node list containing glyphs from the string with the settings in ts.

func (*Document) BuildTable

func (fe *Document) BuildTable(tbl *Table) ([]*node.VList, error)

BuildTable creates one or more vertical lists to be placed into the PDF.

func (*Document) CSSPropertiesToValues

func (d *Document) CSSPropertiesToValues(p HTMLProperties) HTMLValues

CSSPropertiesToValues converts CSS values to the HTMLValues struct.

func (*Document) DefineColor

func (d *Document) DefineColor(name string, col *color.Color)

DefineColor associates a color with a name for later use.

func (*Document) DefineFontFamilyAlias

func (fe *Document) DefineFontFamilyAlias(ff *FontFamily, alias string)

DefineFontFamilyAlias defines the font family with the new name.

func (*Document) FindFontFamily

func (fe *Document) FindFontFamily(name string) *FontFamily

FindFontFamily returns the font family with the given name or nil if there is no font family with this name.

func (*Document) Finish

func (fe *Document) Finish() error

Finish writes all necessary objects for the PDF.

func (*Document) FormatParagraph

func (fe *Document) FormatParagraph(te *Text, hsize bag.ScaledPoint, opts ...TypesettingOption) (*node.VList, []*node.Breakpoint, error)

FormatParagraph creates a rectangular text from the data stored in the Paragraph.

func (*Document) GetColor

func (d *Document) GetColor(s string) *color.Color

GetColor returns a color. The string can be a predefined color name or an HTML / CSS color definition such as #FAF or rgb(0.5.,0.5,0.5).

func (*Document) HTMLBorder

func (d *Document) HTMLBorder(vl *node.VList, hv HTMLValues) *node.VList

HTMLBorder returns two string with a HTML border. The first string is part of a prefix for a possible background string and the second string renders the border.

func (*Document) LoadFace

func (fe *Document) LoadFace(fs *FontSource) (*pdf.Face, error)

LoadFace loads a font from a TrueType or OpenType collection. It takes the face from the cache if the face has been loaded.

func (*Document) LoadIncludedFonts

func (fe *Document) LoadIncludedFonts() error

LoadIncludedFonts creates the font families monospace, sans and serif for default fonts.

func (*Document) Mknodes

func (fe *Document) Mknodes(ts *Text) (head node.Node, tail node.Node, err error)

Mknodes creates a list of nodes which which can be formatted to a given width. The returned head and the tail are the beginning and the end of the node list.

func (*Document) NewFontFamily

func (fe *Document) NewFontFamily(name string) *FontFamily

NewFontFamily creates a new font family for bundling fonts.

func (*Document) RegisterCallback

func (fe *Document) RegisterCallback(cb callbackType, fn any) error

RegisterCallback adds the callback fn to the cb slice.

func (*Document) SetSuppressInfo

func (fe *Document) SetSuppressInfo(si bool)

SetSuppressInfo sets the suppressinfo flag.

type FontFamily

type FontFamily struct {
	ID   int
	Name string
	// contains filtered or unexported fields
}

FontFamily is a struct that keeps font with different weights and styles together.

func (*FontFamily) AddMember

func (ff *FontFamily) AddMember(fontsource *FontSource, weight FontWeight, style FontStyle) error

AddMember adds a member to the font family.

func (*FontFamily) GetFontSource

func (ff *FontFamily) GetFontSource(weight FontWeight, style FontStyle) (*FontSource, error)

GetFontSource tries to get the face closest to the requested face.

func (FontFamily) String

func (ff FontFamily) String() string

type FontSource

type FontSource struct {
	Name         string
	FontFeatures []string
	Location     string
	Data         []byte
	SizeAdjust   float64 // 1 - SizeAdjust is the relative adjustment.
	// The sub font index within the font file.
	Index int
	// contains filtered or unexported fields
}

FontSource defines a mapping of name to a font source including the font features.

func (*FontSource) String

func (fs *FontSource) String() string

type FontStyle

type FontStyle int

FontStyle is the type which represents different font styles such as italic or oblique.

const (
	// FontStyleNormal is an upright font.
	FontStyleNormal FontStyle = iota
	// FontStyleItalic is an italicized font.
	FontStyleItalic
	// FontStyleOblique is an upright font tilted by an angle.
	FontStyleOblique
)

func ResolveFontStyle

func ResolveFontStyle(fs string) FontStyle

ResolveFontStyle parses the string fs and returns a font style.

func (FontStyle) String

func (fs FontStyle) String() string

type FontWeight

type FontWeight int

FontWeight is the type which represents different font weights.

const (
	// FontWeight100 is commonly named “Thin”.
	FontWeight100 FontWeight = 100
	// FontWeight200 is commonly named “Extra Light”.
	FontWeight200 FontWeight = 200
	// FontWeight300 is commonly named “Light”.
	FontWeight300 FontWeight = 300
	// FontWeight400 is commonly named “Normal”.
	FontWeight400 FontWeight = 400
	// FontWeight500 is commonly named “Medium”.
	FontWeight500 FontWeight = 500
	// FontWeight600 is commonly named “Semi Bold”.
	FontWeight600 FontWeight = 600
	// FontWeight700 is commonly named Bold”.
	FontWeight700 FontWeight = 700
	// FontWeight800 is commonly named “Ultra Bold”.
	FontWeight800 FontWeight = 800
	// FontWeight900 is commonly named “Black”.
	FontWeight900 FontWeight = 900
)

func ResolveFontWeight

func ResolveFontWeight(fw string, inheritedValue FontWeight) FontWeight

ResolveFontWeight returns a FontWeight based on the string fw. For example bold is converted to font weight 700.

func (FontWeight) String

func (fw FontWeight) String() string

type FormatToVList

type FormatToVList func(bag.ScaledPoint) (*node.VList, error)

FormatToVList is a function that gets collects typesetting material and gets executed when the hsize is known.

type HTMLProperties

type HTMLProperties map[string]string

HTMLProperties contains css values

type HTMLValues

type HTMLValues struct {
	BackgroundColor         *color.Color
	BorderTopWidth          bag.ScaledPoint
	BorderRightWidth        bag.ScaledPoint
	BorderBottomWidth       bag.ScaledPoint
	BorderLeftWidth         bag.ScaledPoint
	BorderTopLeftRadius     bag.ScaledPoint
	BorderTopRightRadius    bag.ScaledPoint
	BorderBottomLeftRadius  bag.ScaledPoint
	BorderBottomRightRadius bag.ScaledPoint
	BorderTopColor          *color.Color
	BorderRightColor        *color.Color
	BorderBottomColor       *color.Color
	BorderLeftColor         *color.Color
	BorderTopStyle          BorderStyle
	BorderRightStyle        BorderStyle
	BorderBottomStyle       BorderStyle
	BorderLeftStyle         BorderStyle
	MarginTop               bag.ScaledPoint
	MarginRight             bag.ScaledPoint
	MarginBottom            bag.ScaledPoint
	MarginLeft              bag.ScaledPoint
	PaddingTop              bag.ScaledPoint
	PaddingRight            bag.ScaledPoint
	PaddingBottom           bag.ScaledPoint
	PaddingLeft             bag.ScaledPoint
}

HTMLValues contains margin, padding and border values for a rectangular area.

func SettingsToValues

func SettingsToValues(s TypesettingSettings) HTMLValues

type HangingPunctuation

type HangingPunctuation uint8

HangingPunctuation determines if the right or the left side should have hanging punctuation. Values should be or'ed together.

type HorizontalAlignment

type HorizontalAlignment int

HorizontalAlignment is the horizontal alignment.

const (
	// HAlignDefault is an undefined alignment.
	HAlignDefault HorizontalAlignment = iota
	// HAlignLeft makes text ragged right.
	HAlignLeft
	// HAlignRight makes text ragged left.
	HAlignRight
	// HAlignCenter has ragged left and right alignment.
	HAlignCenter
	// HAlignJustified makes text left and right aligned.
	HAlignJustified
)

type Options

type Options struct {
	Alignment  HorizontalAlignment
	Fontfamily *FontFamily
	Fontsize   bag.ScaledPoint

	IndentLeft     bag.ScaledPoint
	IndentLeftRows int
	Language       *lang.Lang
	Leading        bag.ScaledPoint
	// contains filtered or unexported fields
}

Options collects the TypesettingOption for FormatParagraph.

type PostLinebreakCallbackFunc

type PostLinebreakCallbackFunc func(*node.VList) *node.VList

PostLinebreakCallbackFunc gets a vertical list and returns a vertical list that replaces the line break list. If nil is returned the list is discarded.

type SettingType

type SettingType int

SettingType represents a setting such as font weight or color.

const (
	// SettingDummy is a no op.
	SettingDummy SettingType = iota
	// SettingBox signals that this text element contains items that should be arranged vertically.
	SettingBox
	// SettingBackgroundColor sets the background color.
	SettingBackgroundColor
	// SettingBorderBottomWidth sets the bottom border width.
	SettingBorderBottomWidth
	// SettingBorderLeftWidth sets the left border width.
	SettingBorderLeftWidth
	// SettingBorderRightWidth sets the right border width.
	SettingBorderRightWidth
	// SettingBorderTopWidth sets the top border width.
	SettingBorderTopWidth
	// SettingBorderBottomColor sets the bottom border color.
	SettingBorderBottomColor
	// SettingBorderLeftColor sets the left border color.
	SettingBorderLeftColor
	// SettingBorderRightColor sets the right border color.
	SettingBorderRightColor
	// SettingBorderTopColor sets the top border color.
	SettingBorderTopColor
	// SettingBorderBottomStyle sets the bottom border style.
	SettingBorderBottomStyle
	// SettingBorderLeftStyle sets the left border style.
	SettingBorderLeftStyle
	// SettingBorderRightStyle sets the right border style.
	SettingBorderRightStyle
	// SettingBorderTopStyle sets the top border style.
	SettingBorderTopStyle
	// SettingBorderTopLeftRadius sets the top left radius (x and y are the same).
	SettingBorderTopLeftRadius
	// SettingBorderTopRightRadius sets the top right radius (x and y are the same).
	SettingBorderTopRightRadius
	// SettingBorderBottomLeftRadius sets the bottom left radius (x and y are the same).
	SettingBorderBottomLeftRadius
	// SettingBorderBottomRightRadius sets the bottom right radius (x and y are the same).
	SettingBorderBottomRightRadius
	// SettingColor sets a predefined color.
	SettingColor
	// SettingDebug can contain debugging information
	SettingDebug
	// SettingFontExpansion is the amount of expansion / shrinkage allowed. Value is a float between 0 (no expansion) and 1 (100% of the glyph width).
	SettingFontExpansion
	// SettingFontFamily selects a font family.
	SettingFontFamily
	// SettingFontWeight represents a font weight setting.
	SettingFontWeight
	// SettingHAlign sets the horizontal alignment of the paragraph.
	SettingHAlign
	// SettingHangingPunctuation sets the margin protrusion.
	SettingHangingPunctuation
	// SettingHeight sets the height of a box if it should be vertically aligned.
	SettingHeight
	// SettingHyperlink defines an external hyperlink.
	SettingHyperlink
	// SettingIndentLeft inserts a left margin
	SettingIndentLeft
	// SettingIndentLeftRows determines the number of rows to be indented (positive value), or the number of rows not indented (negative values). 0 means all rows.
	SettingIndentLeftRows
	// SettingLeading determines the distance between two base lines (line height).
	SettingLeading
	// SettingMarginBottom sets the bottom margin.
	SettingMarginBottom
	// SettingMarginLeft sets the left margin.
	SettingMarginLeft
	// SettingMarginRight sets the right margin.
	SettingMarginRight
	// SettingMarginTop sets the top margin.
	SettingMarginTop
	// SettingOpenTypeFeature allows the user to (de)select OpenType features such as ligatures.
	SettingOpenTypeFeature
	// SettingPaddingBottom is the bottom padding.
	SettingPaddingBottom
	// SettingPaddingLeft is the left hand padding.
	SettingPaddingLeft
	// SettingPaddingRight is the right hand padding.
	SettingPaddingRight
	// SettingPaddingTop is the top padding.
	SettingPaddingTop
	// SettingPrepend contains a node list which should be prepended to the list.
	SettingPrepend
	// SettingPreserveWhitespace makes a monospace paragraph with newlines.
	SettingPreserveWhitespace
	// SettingSize sets the font size.
	SettingSize
	// SettingStyle represents a font style such as italic or normal.
	SettingStyle
	// SettingTabSizeSpaces is the amount of spaces for a tab.
	SettingTabSizeSpaces
	// SettingTabSize is the tab width.
	SettingTabSize
	// SettingTextDecorationLine sets underline
	SettingTextDecorationLine
	// SettingWidth sets alternative widths for the text.
	SettingWidth
	// SettingVAlign sets the vertical alignment. A height should be set.
	SettingVAlign
	// SettingYOffset shifts the glyph.
	SettingYOffset
)

func (SettingType) String

func (st SettingType) String() string

type Table

type Table struct {
	MaxWidth   bag.ScaledPoint
	Stretch    bool
	FontFamily *FontFamily
	FontSize   bag.ScaledPoint
	Leading    bag.ScaledPoint
	Rows       TableRows
	ColSpec    []ColSpec
	// contains filtered or unexported fields
}

Table represents tabular material to be typeset.

func (*Table) MatrixString

func (tbl *Table) MatrixString() string

MatrixString returns the debug string of the table matrix.

type TableCell

type TableCell struct {
	BorderTopWidth    bag.ScaledPoint
	BorderBottomWidth bag.ScaledPoint
	BorderLeftWidth   bag.ScaledPoint
	BorderRightWidth  bag.ScaledPoint
	BorderTopColor    *color.Color
	BorderBottomColor *color.Color
	BorderLeftColor   *color.Color
	BorderRightColor  *color.Color
	CalculatedWidth   bag.ScaledPoint
	CalculatedHeight  bag.ScaledPoint
	HAlign            HorizontalAlignment
	VAlign            VerticalAlignment
	Contents          []any
	ExtraColspan      int
	ExtraRowspan      int
	PaddingTop        bag.ScaledPoint
	PaddingBottom     bag.ScaledPoint
	PaddingLeft       bag.ScaledPoint
	PaddingRight      bag.ScaledPoint
	// contains filtered or unexported fields
}

TableCell represents a table cell

func (*TableCell) String

func (cell *TableCell) String() string

type TableRow

type TableRow struct {
	Cells            []*TableCell
	CalculatedHeight bag.ScaledPoint
	VAlign           VerticalAlignment
	// contains filtered or unexported fields
}

TableRow represents a row in a table.

type TableRows

type TableRows []*TableRow

TableRows is a collection of table rows.

type Text

type Text struct {
	Settings TypesettingSettings
	Items    []any
}

Text associates all items with the given settings. Items can be text (string), images, other instances of Text or nodes. Text behaves like a span in HTML or it just contains a collection of Go strings.

func NewText

func NewText() *Text

NewText returns an initialized text element.

func (*Text) String

func (ts *Text) String() string

type TextDecorationLine

type TextDecorationLine int

TextDecorationLine sets the underline type

const (
	// TextDecorationLineNone means no underline
	TextDecorationLineNone TextDecorationLine = iota
	// TextDecorationUnderline is a simple underlining
	TextDecorationUnderline
	// TextDecorationOverline has a line above
	TextDecorationOverline
	// TextDecorationLineThrough is a strike out
	TextDecorationLineThrough
)

type TypesettingOption

type TypesettingOption func(*Options)

TypesettingOption controls the formatting of the paragraph.

func Family

func Family(fam *FontFamily) TypesettingOption

Family sets the font family for the paragraph.

func FontSize

func FontSize(size bag.ScaledPoint) TypesettingOption

FontSize sets the font size for the paragraph.

func HorizontalAlign

func HorizontalAlign(a HorizontalAlignment) TypesettingOption

HorizontalAlign sets the horizontal alignment for a paragraph.

func IndentLeft

func IndentLeft(size bag.ScaledPoint, rows int) TypesettingOption

IndentLeft sets the left indent.

func Language

func Language(language *lang.Lang) TypesettingOption

Language sets the default language for the whole paragraph (used for hyphenation).

func Leading

func Leading(leading bag.ScaledPoint) TypesettingOption

Leading sets the distance between two baselines in a paragraph.

type TypesettingSettings

type TypesettingSettings map[SettingType]any

TypesettingSettings is a set of settings for text rendering.

type VerticalAlignment

type VerticalAlignment int

VerticalAlignment is the vertical alignment.

const (
	// VAlignDefault is an undefined vertical alignment.
	VAlignDefault VerticalAlignment = iota
	// VAlignTop aligns the contents at the top of the surrounding box.
	VAlignTop
	// VAlignMiddle aligns the contents in the vertical middle of the surrounding box.
	VAlignMiddle
	// VAlignBottom aligns the contents at the bottom of the surrounding box.
	VAlignBottom
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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