Documentation ¶
Index ¶
- func AppendLineEndAfter(head, n Node) (Node, Node)
- func Debug(n Node)
- func DebugToFile(n Node, fn string) error
- func DebugToString(n Node) string
- func Dimensions(start Node, stop Node, dir Direction) bag.ScaledPoint
- func GetAttribute(n Node, attr string) (any, bool)
- func IsNode(arg any) bool
- func Linebreak(n Node, settings *LinebreakSettings) (*VList, []*Breakpoint)
- func SetAttribute(n Node, attr string, val any)
- func String(n Node) string
- func StringValue(n Node) string
- type ActionType
- type Breakpoint
- type Direction
- type Disc
- type Glue
- type GlueOrder
- type GlueSubtype
- type Glyph
- type H
- type HList
- type HpackOption
- type Image
- type Kern
- type Lang
- type LinebreakSettings
- type Node
- type PDFDataOutput
- type Penalty
- type Rule
- type StartStop
- func (d *StartStop) Copy() Node
- func (d *StartStop) GetID() int
- func (d *StartStop) Name() string
- func (d *StartStop) Next() Node
- func (d *StartStop) Prev() Node
- func (d *StartStop) SetNext(n Node)
- func (d *StartStop) SetPrev(n Node)
- func (d *StartStop) String() string
- func (d *StartStop) Type() Type
- type StartStopFunc
- type Type
- type VList
- type VerticalAlignment
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendLineEndAfter ¶
AppendLineEndAfter adds a penalty 10000, glue 0pt plus 1fil, penalty -10000 after n (the node lists starting with head). It returns the new head (if head is nil) and the penalty node (the tail of the list).
func DebugToFile ¶
DebugToFile writes an XML file with the node list.
func DebugToString ¶
DebugToString returns node list debug output.
func Dimensions ¶
func Dimensions(start Node, stop Node, dir Direction) bag.ScaledPoint
Dimensions returns the width of the node list starting at n. If dir is Horizontal, then calculate in horizontal mode, otherwise in vertical mode.
func GetAttribute ¶
GetAttribute returns the value of the attribute attr and true or nil and false if the attribute does not exist.
func Linebreak ¶
func Linebreak(n Node, settings *LinebreakSettings) (*VList, []*Breakpoint)
Linebreak breaks the node list starting at n into lines. Returns a VList of HLists and information about each line.
func SetAttribute ¶
SetAttribute sets the attribute attr on the node n.
func StringValue ¶
StringValue returns a short string representation of the node list starting at n.
Types ¶
type ActionType ¶
type ActionType int
ActionType represents a start/stop action such as a PDF link.
const ( // ActionNone represents no special action ActionNone ActionType = iota // ActionHyperlink represents a hyperlink. ActionHyperlink // ActionDest insets a PDF destination. ActionDest // ActionUserSetting allows user defined settings. ActionUserSetting )
func (ActionType) String ¶
func (at ActionType) String() string
type Breakpoint ¶
type Breakpoint struct { Position Node Pre Node Line int Fitness int Width bag.ScaledPoint R float64 Demerits int // contains filtered or unexported fields }
Breakpoint is a feasible break point.
func (*Breakpoint) String ¶
func (bp *Breakpoint) String() string
type Direction ¶
type Direction bool
Direction represents the direction of the node list. This can be horizontal or vertical.
type Disc ¶
type Disc struct { Pre Node Post Node Replace Node Penalty int // Added to the hyphen penalty // contains filtered or unexported fields }
A Disc represents a hyphenation point. Currently only the Penalty field is used.
func NewDiscWithContents ¶
NewDiscWithContents creates an initialized Disc node with the given contents
type Glue ¶
type Glue struct { Subtype GlueSubtype Width bag.ScaledPoint // The natural width of the glue. Stretch bag.ScaledPoint // The stretchability of the glue, where width plus stretch = maximum width. Shrink bag.ScaledPoint // The shrinkability of the glue, where width minus shrink = minimum width. StretchOrder GlueOrder // The order of infinity of stretching. ShrinkOrder GlueOrder // The order of infinity of shrinking. // contains filtered or unexported fields }
A Glue node has the value of a shrinking and stretching space
type GlueSubtype ¶
type GlueSubtype int
GlueSubtype is set wherever the glue comes from.
const ( // GlueDefault when no subtype is set GlueDefault GlueSubtype = iota // GlueLineStart is inserted left of the hlist during the line breaking GlueLineStart // GlueLineEnd is added at the end of each line in a paragraph so that copy // and paste works in PDF. GlueLineEnd )
type Glyph ¶
type Glyph struct { Font *font.Font // The font specific glyph id Codepoint int // A codepoint can contain more than one rune, for example a fi ligature // contains f + i. Filling the components string is optional. Components string // The advance width of the box. Width bag.ScaledPoint // The height is the length above the base line. Height bag.ScaledPoint // The Depth is the length below the base line. For example the letter g has // a depth > 0. Depth bag.ScaledPoint // Vertical displacement. Positive values move the glyph towards the top of // the page. YOffset bag.ScaledPoint // This allows the glyph to be part of word hyphenation. Hyphenate bool // contains filtered or unexported fields }
Glyph nodes represents a single visible entity such as a letter or a ligature.
type HList ¶
type HList struct { Width bag.ScaledPoint Height bag.ScaledPoint Depth bag.ScaledPoint Badness int GlueSet float64 // The ratio of the glue. Positive means stretching, negative shrinking. GlueSign uint8 // 0 = normal, 1 = stretching, 2 = shrinking GlueOrder GlueOrder // The level of infinity Shift bag.ScaledPoint // The displacement perpendicular to the progressing direction. Not used. List Node // The list itself. VAlign VerticalAlignment // contains filtered or unexported fields }
A HList is a container for a list which items are placed horizontally next to each other. The most convenient way to create a hlist is using node.HPack. The width, height, depth, badness and the glue settings are calculated when using node.HPack.
func HpackTo ¶
func HpackTo(firstNode Node, width bag.ScaledPoint) *HList
HpackTo returns a HList node with the node list as its list. The width is the desired width.
func HpackToWithEnd ¶
func HpackToWithEnd(firstNode Node, lastNode Node, width bag.ScaledPoint, opts ...HpackOption) *HList
HpackToWithEnd returns a HList node with nl as its list. The width is the desired width. The list stops at lastNode (including lastNode).
type HpackOption ¶
type HpackOption func(*hpackSetting)
HpackOption controls the packaging of the box.
func FontExpansion ¶
func FontExpansion(amount float64) HpackOption
FontExpansion sets the allowed font expansion (0-1).
type Image ¶
type Image struct { Width bag.ScaledPoint Height bag.ScaledPoint Img *image.Image // contains filtered or unexported fields }
An Image contains a reference to the image object.
type Kern ¶
type Kern struct { // The displacement in progression direction. Kern bag.ScaledPoint // contains filtered or unexported fields }
A Kern is a small space between glyphs.
type Lang ¶
type Lang struct { Lang *lang.Lang // The language setting for the following nodes. // contains filtered or unexported fields }
A Lang is a node that sets the current language.
func NewLangWithContents ¶
NewLangWithContents creates an initialized Lang node with the given contents
type LinebreakSettings ¶
type LinebreakSettings struct { DemeritsFitness int DoublehyphenDemerits int HangingPunctuationEnd bool FontExpansion float64 HSize bag.ScaledPoint Hyphenpenalty int Indent bag.ScaledPoint IndentRows int LineEndGlue *Glue LineHeight bag.ScaledPoint LineStartGlue *Glue OmitLastLeading bool Tolerance float64 }
LinebreakSettings controls the line breaking algorithm.
func NewLinebreakSettings ¶
func NewLinebreakSettings() *LinebreakSettings
NewLinebreakSettings returns a settings struct with defaults initialized.
type Node ¶
type Node interface { Next() Node Prev() Node SetNext(Node) SetPrev(Node) GetID() int Type() Type Name() string Copy() Node }
Node represents any kind of node
func DeleteFromList ¶
DeleteFromList removes the node cur from the list starting at head. The possible new head is returned.
func InsertAfter ¶
InsertAfter inserts the node insert right after cur. If cur is nil then insert is the new head. This method returns the head node.
func InsertBefore ¶
InsertBefore inserts the node insert before the current not cur. It returns the (perhaps) new head node.
type PDFDataOutput ¶
type PDFDataOutput int
PDFDataOutput defines the location of inserted PDF data.
const ( // PDFOutputNone ignores any movement commands. PDFOutputNone PDFDataOutput = iota // PDFOutputHere inserts ET and moves to current position before inserting // the PDF data. PDFOutputHere // PDFOutputDirect inserts the PDF data without leaving the text mode with ET. PDFOutputDirect // PDFOutputPage inserts ET before writing the PDF data. PDFOutputPage // PDFOutputLowerLeft moves to the lower left corner before inserting the // PDF data. PDFOutputLowerLeft )
type Penalty ¶
type Penalty struct { Penalty int // Value Width bag.ScaledPoint // Width of the penalty // contains filtered or unexported fields }
A Penalty is a valid horizontal or vertical break point. The higher the penalty the less likely the break occurs at this penalty. Anything below or equal -10000 is considered a forced break, anything higher than or equal to 10000 is considered a disallowed break.
func IsPenalty ¶
IsPenalty returns the value of the element and true, if the element is a Penalty node.
type Rule ¶
type Rule struct { // PDF code that gets output before the rule. Pre string // PDF Code after drawing the rule. Post string // Hide makes the rule invisible, no colored area is drawn. Used to make Pre // and Post appear in the output with the given dimensions. Hide bool Width bag.ScaledPoint Height bag.ScaledPoint Depth bag.ScaledPoint // contains filtered or unexported fields }
A Rule is a node represents a colored rectangular area.
type StartStop ¶
type StartStop struct { Action ActionType StartNode *StartStop Position PDFDataOutput ShipoutCallback StartStopFunc // Value contains action specific contents Value any // contains filtered or unexported fields }
A StartStop is a paired node type used for color switches, hyperlinks and such.
type StartStopFunc ¶
StartStopFunc is the type of the callback when this node is encountered in the node list. The returned string (if not empty) gets written to the PDF.
type Type ¶
type Type int
Type is the type of node.
const ( // TypeUnknown is a node which type is unknown. TypeUnknown Type = iota // TypeDisc is a Disc node. TypeDisc // TypeGlue is a Glue node. TypeGlue // TypeGlyph is a Glyph node. TypeGlyph // TypeHList is a HList node. TypeHList // TypeImage is a Image node. TypeImage // TypeKern is a Kern node. TypeKern // TypeLang is a Lang node. TypeLang // TypePenalty is a Penalty node. TypePenalty // TypeRule is a Rule node. TypeRule // TypeStartStop marks the beginning and end of a something interesting. TypeStartStop // TypeVList is a VList node. TypeVList )
type VList ¶
type VList struct { Width bag.ScaledPoint Height bag.ScaledPoint Depth bag.ScaledPoint GlueSet float64 GlueSign uint8 ShiftX bag.ScaledPoint List Node // contains filtered or unexported fields }
A VList is a vertical list.
type VerticalAlignment ¶
type VerticalAlignment uint
VerticalAlignment sets the alignment in horizontal lists (hlist). The default alignment is VAlignBaseline which means that all items in the hlist have the same base line.
const ( // VAlignBaseline is the default alignment in hlists which has all items // aligned at the base line. VAlignBaseline VerticalAlignment = 0 // VAlignTop has all items in a hlist hanging down from the top like // stalactites in a cave. VAlignTop = 1 )