Skip to content

Fonts and font families#

Font families#

A font family is a collection of faces that appear in different font weight and styles:

type FontFamily struct {
    ID   int
    Name string

You can add faces to the font family:

func (ff *FontFamily) AddMember(fontsource *FontSource, weight FontWeight, style FontStyle) error

where the font source is:

type FontSource struct {
    Name         string
    FontFeatures []string
    Location     string
    Data         []byte
    SizeAdjust   float64 // 1 - SizeAdjust is the relative adjustment.
    // The sub font index within the font file.
    Index int

and the weight is a number between 100 and 900 or a predefined name FontWeight100, FontWeight200, ..., FontWeight900 and the style is FontStyleNormal, FontStyleItalic or FontStyleOblique.

You can retrieve a font source with

func (ff *FontFamily) GetFontSource(weight FontWeight, style FontStyle) (*FontSource, error)

which will give you the closest match.

Converting font weight and style from string#

To get a font weight or a font style from a string you can use these two functions:

func ResolveFontWeight(fw string, inheritedValue FontWeight) FontWeight
func ResolveFontStyle(fs string) FontStyle

The inherited value for the font weight is used when the string is “bolder”.