...

Package font

import "gonum.org/v1/plot/font"
Overview
Index
Subdirectories

Overview ▾

Package font provides types to describe and select text font faces.

Constants

Common lengths.

const (
    Inch       Length = 72
    Centimeter        = Inch / 2.54
    Millimeter        = Centimeter / 10
)

type Cache

Cache collects font faces.

type Cache struct {
    // contains filtered or unexported fields
}

DefaultCache is the global cache for fonts.

var DefaultCache *Cache = NewCache(nil)

func NewCache

func NewCache(coll Collection) *Cache

NewCache creates a new cache of fonts from the provided collection of font Faces. The first font Face in the collection is set to be the default one.

func (*Cache) Add

func (c *Cache) Add(coll Collection)

Add adds a whole collection of font Faces to the font cache. If the cache is empty, the first font Face in the collection is set to be the default one.

func (*Cache) GobDecode

func (c *Cache) GobDecode([]byte) error

func (*Cache) GobEncode

func (c *Cache) GobEncode() ([]byte, error)

func (*Cache) Has

func (c *Cache) Has(fnt Font) bool

Has returns whether the cache contains the exact font descriptor.

func (*Cache) Lookup

func (c *Cache) Lookup(fnt Font, size Length) Face

Lookup returns the font Face corresponding to the provided Font descriptor, with the provided font size set.

If no matching font Face could be found, the one corresponding to the default typeface is selected and returned.

type Collection

Collection is a collection of fonts, regrouped under a common typeface.

type Collection []Face

type Extents

Extents contains font metric information.

type Extents struct {
    // Ascent is the distance that the text
    // extends above the baseline.
    Ascent Length

    // Descent is the distance that the text
    // extends below the baseline. The descent
    // is given as a positive value.
    Descent Length

    // Height is the distance from the lowest
    // descending point to the highest ascending
    // point.
    Height Length
}

type Face

Face holds a font descriptor and the associated font face.

type Face struct {
    Font Font
    Face *opentype.Font
}

func (*Face) Extents

func (f *Face) Extents() Extents

Extents returns the FontExtents for a font.

func (*Face) FontFace

func (f *Face) FontFace(dpi float64) font.Face

FontFace returns the opentype font face for the requested dots-per-inch resolution.

func (*Face) Name

func (f *Face) Name() string

Name returns a fully qualified name for the given font.

func (*Face) Width

func (f *Face) Width(s string) Length

Width returns width of a string when drawn using the font.

type Font

Font represents a font face.

type Font struct {
    // Typeface identifies the Font.
    Typeface Typeface

    // Variant is the variant of a font, such as "Mono" or "Smallcaps".
    Variant Variant

    // Style is the style of a font, such as Regular or Italic.
    Style font.Style

    // Weight is the weight of a font, such as Normal or Bold.
    Weight font.Weight

    // Size is the size of the font.
    Size Length
}

func From

func From(fnt Font, size Length) Font

From returns a copy of the provided font with its size set.

func (*Font) Name

func (f *Font) Name() string

Name returns a fully qualified name for the given font.

type Length

Length is a unit-independent representation of length. Internally, the length is stored in postscript points.

type Length float64

func ParseLength

func ParseLength(value string) (Length, error)

ParseLength parses a Length string. A Length string is a possible signed floating number with a unit. e.g. "42cm" "2.4in" "66pt" If no unit was given, ParseLength assumes it was (postscript) points. Currently valid units are:

func Points

func Points(pt float64) Length

Points returns a length for the given number of points.

func (Length) Dots

func (l Length) Dots(dpi float64) float64

Dots returns the length in dots for the given resolution.

func (Length) Points

func (l Length) Points() float64

Points returns the length in postscript points.

type Typeface

Typeface identifies a particular typeface design. The empty string denotes the default typeface.

type Typeface string

type Variant

Variant denotes a typeface variant, such as "Mono", "Smallcaps" or "Math".

type Variant string

Subdirectories

Name Synopsis
..
liberation Package liberation exports the Liberation fonts as a font.Collection.