Skip to content

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.

TODO

explain how to create the harfbuzz.Feature slice.

func (f *Font) Shape(text string, features []harfbuzz.Feature) []Atom

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

type Atom struct {
    Advance    bag.ScaledPoint
    Height     bag.ScaledPoint
    Depth      bag.ScaledPoint
    IsSpace    bool
    Components string
    Codepoint  int
    Hyphenate  bool
    Kernafter  bag.ScaledPoint
}
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