Creating text nodes
What are nodes?
Text data structure
- Hierarchical structure
func NewText() *Texttype Text struct {
Settings TypesettingSettings
Items []any
}Text can be a nested structure. Think of
<em>this is <u>emphasized and underlined</u></em>where you can consider the underlined part as a child of the emphasized part.
ul := NewText()
ul.Settings[]
ul.Items = append(ul.Items,"emphasized and underlined")
em := NewText()
em.Settings...
em.Items = append(em.Items, "this is ")
em.Items = append(em.Items, ulFormat a paragraph
- font family needed
This breaks a paragraph into lines:
func (fe *Document) FormatParagraph(te *Text, hsize bag.ScaledPoint, opts ...TypesettingOption) (*node.VList, *ParagraphInfo, error)hsize is the desired horizontal size.
format paragraph calls mknodes
func (fe *Document) Mknodes(ts *Text) (head node.Node, tail node.Node, err error)which creates a list of nodes from a nested Text data structure.
Typesetting options
The FormatParagraph() method takes a typesetting options as the last argument.
type TypesettingOption func(*Options)| Option | Description |
|---|---|
Leading(leading bag.ScaledPoint) |
Set the vertical distance between two baselines |
Language(language *lang.Lang) |
Set the language used for hyphenation |
FontSize(size bag.ScaledPoint) |
Set the font size for the paragraph |
IndentLeft(size bag.ScaledPoint, rows int) |
Set the text indent |
HorizontalAlign(a HorizontalAlignment) |
Sets the horizontal alignment for a paragraph |