node

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: 13 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendLineEndAfter

func AppendLineEndAfter(head, n Node) (Node, Node)

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 Debug

func Debug(n Node)

Debug shows node list debug output.

func DebugToFile

func DebugToFile(n Node, fn string) error

DebugToFile writes an XML file with the node list.

func DebugToString

func DebugToString(n Node) string

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

func GetAttribute(n Node, attr string) (any, bool)

GetAttribute returns the value of the attribute attr and true or nil and false if the attribute does not exist.

func IsNode

func IsNode(arg any) bool

IsNode returns true if the argument is a Node.

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

func SetAttribute(n Node, attr string, val any)

SetAttribute sets the attribute attr on the node n.

func String

func String(n Node) string

String returns a string representation of the node n and the previous and next node.

func StringValue

func StringValue(n Node) string

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.

const (
	// Horizontal is the direction from left to right or from right to left.
	Horizontal Direction = true
	// Vertical is the direction from top to bottom or from bottom to top.
	Vertical Direction = false
)

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 IsDisc

func IsDisc(elt Node) (*Disc, bool)

IsDisc returns the value of the element and true, if the element is a Disc node.

func NewDisc

func NewDisc() *Disc

NewDisc creates an initialized Disc node

func NewDiscWithContents

func NewDiscWithContents(n *Disc) *Disc

NewDiscWithContents creates an initialized Disc node with the given contents

func (*Disc) Copy

func (d *Disc) Copy() Node

Copy creates a deep copy of the node.

func (*Disc) GetID

func (d *Disc) GetID() int

GetID returns the node id

func (*Disc) Name

func (d *Disc) Name() string

Name returns the name of the node

func (*Disc) Next

func (d *Disc) Next() Node

Next returns the following node or nil if no such node exists.

func (*Disc) Prev

func (d *Disc) Prev() Node

Prev returns the node preceding this node or nil if no such node exists.

func (*Disc) SetNext

func (d *Disc) SetNext(n Node)

SetNext sets the following node.

func (*Disc) SetPrev

func (d *Disc) SetPrev(n Node)

SetPrev sets the preceding node.

func (*Disc) String

func (d *Disc) String() string

func (*Disc) Type

func (d *Disc) Type() Type

Type returns the type of the node

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

func IsGlue

func IsGlue(elt Node) (*Glue, bool)

IsGlue returns the value of the element and true, if the element is a Glue node.

func NewGlue

func NewGlue() *Glue

NewGlue creates an initialized Glue node

func (*Glue) Copy

func (g *Glue) Copy() Node

Copy creates a deep copy of the node.

func (*Glue) GetID

func (g *Glue) GetID() int

GetID returns the node id

func (*Glue) Name

func (g *Glue) Name() string

Name returns the name of the node

func (*Glue) Next

func (g *Glue) Next() Node

Next returns the following node or nil if no such node exists.

func (*Glue) Prev

func (g *Glue) Prev() Node

Prev returns the node preceding this node or nil if no such node exists.

func (*Glue) SetNext

func (g *Glue) SetNext(n Node)

SetNext sets the following node.

func (*Glue) SetPrev

func (g *Glue) SetPrev(n Node)

SetPrev sets the preceding node.

func (*Glue) String

func (g *Glue) String() string

func (*Glue) Type

func (g *Glue) Type() Type

Type returns the type of the node

type GlueOrder

type GlueOrder int

GlueOrder represents the stretch and shrink priority.

const (
	// StretchNormal means no stretching
	StretchNormal GlueOrder = iota
	// StretchFil is the first order infinity
	StretchFil
	// StretchFill is the second order infinity
	StretchFill
	// StretchFilll is the third order infinity
	StretchFilll
)

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.

func IsGlyph

func IsGlyph(elt Node) (*Glyph, bool)

IsGlyph returns the value of the element and true, if the element is a Glyph node.

func NewGlyph

func NewGlyph() *Glyph

NewGlyph returns an initialized Glyph

func (*Glyph) Copy

func (g *Glyph) Copy() Node

Copy creates a deep copy of the node.

func (*Glyph) GetID

func (g *Glyph) GetID() int

GetID returns the node id

func (*Glyph) Name

func (g *Glyph) Name() string

Name returns the name of the node

func (*Glyph) Next

func (g *Glyph) Next() Node

Next returns the following node or nil if no such node exists.

func (*Glyph) Prev

func (g *Glyph) Prev() Node

Prev returns the node preceding this node or nil if no such node exists.

func (*Glyph) SetNext

func (g *Glyph) SetNext(n Node)

SetNext sets the following node.

func (*Glyph) SetPrev

func (g *Glyph) SetPrev(n Node)

SetPrev sets the preceding node.

func (*Glyph) String

func (g *Glyph) String() string

func (*Glyph) Type

func (g *Glyph) Type() Type

Type returns the type of the node

type H

type H map[string]any

H is a shortcut for map[string]any

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 Hpack

func Hpack(firstNode Node) *HList

Hpack returns a HList node with the node list as its list

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).

func IsHList

func IsHList(elt Node) (*HList, bool)

IsHList returns the value of the element and true, if the element is a HList node.

func NewHList

func NewHList() *HList

NewHList creates an initialized HList node

func (*HList) Copy

func (h *HList) Copy() Node

Copy creates a deep copy of the node.

func (*HList) GetID

func (h *HList) GetID() int

GetID returns the node id

func (*HList) Name

func (h *HList) Name() string

Name returns the name of the node

func (*HList) Next

func (h *HList) Next() Node

Next returns the following node or nil if no such node exists.

func (*HList) Prev

func (h *HList) Prev() Node

Prev returns the node preceding this node or nil if no such node exists.

func (*HList) SetNext

func (h *HList) SetNext(n Node)

SetNext sets the following node.

func (*HList) SetPrev

func (h *HList) SetPrev(n Node)

SetPrev sets the preceding node.

func (*HList) String

func (h *HList) String() string

func (*HList) Type

func (h *HList) Type() Type

Type returns the type of the node

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.

func IsImage

func IsImage(elt Node) (*Image, bool)

IsImage returns the value of the element and true, if the element is a Image node.

func NewImage

func NewImage() *Image

NewImage creates an initialized Image node

func (*Image) Copy

func (img *Image) Copy() Node

Copy creates a deep copy of the node.

func (*Image) GetID

func (img *Image) GetID() int

GetID returns the node id

func (*Image) Name

func (img *Image) Name() string

Name returns the name of the node

func (*Image) Next

func (img *Image) Next() Node

Next returns the following node or nil if no such node exists.

func (*Image) Prev

func (img *Image) Prev() Node

Prev returns the node preceding this node or nil if no such node exists.

func (*Image) SetNext

func (img *Image) SetNext(n Node)

SetNext sets the following node.

func (*Image) SetPrev

func (img *Image) SetPrev(n Node)

SetPrev sets the preceding node.

func (*Image) String

func (img *Image) String() string

func (*Image) Type

func (img *Image) Type() Type

Type returns the type of the node

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.

func IsKern

func IsKern(elt Node) (*Kern, bool)

IsKern returns the value of the element and true, if the element is a Kern node.

func NewKern

func NewKern() *Kern

NewKern creates an initialized Kern node

func (*Kern) Copy

func (k *Kern) Copy() Node

Copy creates a deep copy of the node.

func (*Kern) GetID

func (k *Kern) GetID() int

GetID returns the node id

func (*Kern) Name

func (k *Kern) Name() string

Name returns the name of the node

func (*Kern) Next

func (k *Kern) Next() Node

Next returns the following node or nil if no such node exists.

func (*Kern) Prev

func (k *Kern) Prev() Node

Prev returns the node preceding this node or nil if no such node exists.

func (*Kern) SetNext

func (k *Kern) SetNext(n Node)

SetNext sets the following node.

func (*Kern) SetPrev

func (k *Kern) SetPrev(n Node)

SetPrev sets the preceding node.

func (*Kern) String

func (k *Kern) String() string

func (*Kern) Type

func (k *Kern) Type() Type

Type returns the type of the node

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 IsLang

func IsLang(elt Node) (*Lang, bool)

IsLang returns the value of the element and true, if the element is a Lang node.

func NewLang

func NewLang() *Lang

NewLang creates an initialized Lang node

func NewLangWithContents

func NewLangWithContents(n *Lang) *Lang

NewLangWithContents creates an initialized Lang node with the given contents

func (*Lang) Copy

func (l *Lang) Copy() Node

Copy creates a deep copy of the node.

func (*Lang) GetID

func (l *Lang) GetID() int

GetID returns the node id

func (*Lang) Name

func (l *Lang) Name() string

Name returns the name of the node

func (*Lang) Next

func (l *Lang) Next() Node

Next returns the following node or nil if no such node exists.

func (*Lang) Prev

func (l *Lang) Prev() Node

Prev returns the node preceding this node or nil if no such node exists.

func (*Lang) SetNext

func (l *Lang) SetNext(n Node)

SetNext sets the following node.

func (*Lang) SetPrev

func (l *Lang) SetPrev(n Node)

SetPrev sets the preceding node.

func (*Lang) String

func (l *Lang) String() string

func (*Lang) Type

func (l *Lang) Type() Type

Type returns the type of the node

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 Boxit

func Boxit(n Node) Node

Boxit draws a thin rectangle around the box.

func CopyList

func CopyList(nl Node) Node

CopyList makes a deep copy of the list starting at nl.

func DeleteFromList

func DeleteFromList(head, cur Node) Node

DeleteFromList removes the node cur from the list starting at head. The possible new head is returned.

func InsertAfter

func InsertAfter(head, cur, insert Node) Node

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

func InsertBefore(head, cur, insert Node) Node

InsertBefore inserts the node insert before the current not cur. It returns the (perhaps) new head node.

func Tail

func Tail(nl Node) Node

Tail returns the last node of a node list.

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

func IsPenalty(elt Node) (*Penalty, bool)

IsPenalty returns the value of the element and true, if the element is a Penalty node.

func NewPenalty

func NewPenalty() *Penalty

NewPenalty creates an initialized Penalty node

func (*Penalty) Copy

func (p *Penalty) Copy() Node

Copy creates a deep copy of the node.

func (*Penalty) GetID

func (p *Penalty) GetID() int

GetID returns the node id

func (*Penalty) Name

func (p *Penalty) Name() string

Name returns the name of the node

func (*Penalty) Next

func (p *Penalty) Next() Node

Next returns the following node or nil if no such node exists.

func (*Penalty) Prev

func (p *Penalty) Prev() Node

Prev returns the node preceding this node or nil if no such node exists.

func (*Penalty) SetNext

func (p *Penalty) SetNext(n Node)

SetNext sets the following node.

func (*Penalty) SetPrev

func (p *Penalty) SetPrev(n Node)

SetPrev sets the preceding node.

func (*Penalty) String

func (p *Penalty) String() string

func (*Penalty) Type

func (p *Penalty) Type() Type

Type returns the type of the 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.

func IsRule

func IsRule(elt Node) (*Rule, bool)

IsRule returns the value of the element and true, if the element is a Rule node.

func NewRule

func NewRule() *Rule

NewRule creates an initialized Rule node

func (*Rule) Copy

func (r *Rule) Copy() Node

Copy creates a deep copy of the node.

func (*Rule) GetID

func (r *Rule) GetID() int

GetID returns the node id

func (*Rule) Name

func (r *Rule) Name() string

Name returns the name of the node

func (*Rule) Next

func (r *Rule) Next() Node

Next returns the following node or nil if no such node exists.

func (*Rule) Prev

func (r *Rule) Prev() Node

Prev returns the node preceding this node or nil if no such node exists.

func (*Rule) SetNext

func (r *Rule) SetNext(n Node)

SetNext sets the following node.

func (*Rule) SetPrev

func (r *Rule) SetPrev(n Node)

SetPrev sets the preceding node.

func (*Rule) String

func (r *Rule) String() string

func (*Rule) Type

func (r *Rule) Type() Type

Type returns the type of the node

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.

func NewStartStop

func NewStartStop() *StartStop

NewStartStop creates an initialized Start node

func (*StartStop) Copy

func (d *StartStop) Copy() Node

Copy creates a deep copy of the node.

func (*StartStop) GetID

func (d *StartStop) GetID() int

GetID returns the node id

func (*StartStop) Name

func (d *StartStop) Name() string

Name returns the name of the node

func (*StartStop) Next

func (d *StartStop) Next() Node

Next returns the following node or nil if no such node exists.

func (*StartStop) Prev

func (d *StartStop) Prev() Node

Prev returns the node preceding this node or nil if no such node exists.

func (*StartStop) SetNext

func (d *StartStop) SetNext(n Node)

SetNext sets the following node.

func (*StartStop) SetPrev

func (d *StartStop) SetPrev(n Node)

SetPrev sets the preceding node.

func (*StartStop) String

func (d *StartStop) String() string

func (*StartStop) Type

func (d *StartStop) Type() Type

Type returns the type of the node

type StartStopFunc

type StartStopFunc func(thisnode Node) string

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
)

func (Type) String

func (t Type) String() string

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.

func IsVList

func IsVList(elt Node) (*VList, bool)

IsVList returns the value of the element and true, if the element is a VList node.

func NewVList

func NewVList() *VList

NewVList creates an initialized VList node

func Vpack

func Vpack(firstNode Node) *VList

Vpack creates a list

func (*VList) Copy

func (v *VList) Copy() Node

Copy creates a deep copy of the node.

func (*VList) GetID

func (v *VList) GetID() int

GetID returns the node id

func (*VList) Name

func (v *VList) Name() string

Name returns the name of the node

func (*VList) Next

func (v *VList) Next() Node

Next returns the following node or nil if no such node exists.

func (*VList) Prev

func (v *VList) Prev() Node

Prev returns the node preceding this node or nil if no such node exists.

func (*VList) SetNext

func (v *VList) SetNext(n Node)

SetNext sets the following node.

func (*VList) SetPrev

func (v *VList) SetPrev(n Node)

SetPrev sets the preceding node.

func (*VList) String

func (v *VList) String() string

func (*VList) Type

func (v *VList) Type() Type

Type returns the type of the node

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
)

Jump to

Keyboard shortcuts

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