Fonts

Fonts and Faces

The terms fonts and faces are borrowed from the Harfbuzz library: A face represents a font file like an OpenType font or a TrueType font and a font is a face in a specific size.

In order to put text into the PDF, you first load a face:

func (d *PDFDocument) LoadFace(filename string, index int) (*pdf.Face, error)

and from that face, you can create a font:

func NewFont(face *pdf.Face, size bag.ScaledPoint) *Font

Text shaping

Turning text into a series of glyph ids (code points) is the process of shaping. The harfbuzz.Feature slice is important. For example the text fish can be turned into different glyph ids depending on the liga feature.

â„šī¸
explain how to create the harfbuzz.Feature slice.
func (f *Font) Shape(text string, features []ot.Feature, variations map[string]float64) []Atom

The Shape() method returns a slice of Atoms which is the following type:

type Atom struct {
	Components string
	Advance    bag.ScaledPoint
	Height     bag.ScaledPoint
	Depth      bag.ScaledPoint
	XOffset    bag.ScaledPoint // Horizontal offset from GPOS positioning
	YOffset    bag.ScaledPoint // Vertical offset from GPOS positioning (e.g., mark attachment)
	Codepoint  int
	Kernafter  bag.ScaledPoint
	IsSpace    bool
	NoBreak    bool // Space that must not be a breakpoint (e.g. NBSP U+00A0)
	Hyphenate  bool
}
Name Description
Advance The width of the glyph
Height Height above the base line
Depth Height below the base line
Hyphenate Indicates that this is a Unicode category L (letter)
Codepoint The font codepoint (glyph id) that should be placed in the PDF
Kernafter The amount of kerning that should be applied after this glyph