font

package
v0.14.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2023 License: BSD-3-Clause Imports: 9 Imported by: 57

Documentation

Overview

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

Index

Constants

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

Common lengths.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache collects font faces.

var DefaultCache *Cache = NewCache(nil)

DefaultCache is the global cache for fonts.

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

type Collection []Face

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

type Extents

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
}

Extents contains font metric information.

type Face

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

Face holds a font descriptor and the associated font face.

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

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
}

Font represents a font face.

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

type Length float64

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

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:

  • mm (millimeter)
  • cm (centimeter)
  • in (inch)
  • pt (point)

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

type Typeface string

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

type Variant

type Variant string

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

Directories

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL