Common lengths.
const ( Inch Length = 72 Centimeter = Inch / 2.54 Millimeter = Centimeter / 10 )
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(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 (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 (c *Cache) GobDecode([]byte) error
func (c *Cache) GobEncode() ([]byte, error)
func (c *Cache) Has(fnt Font) bool
Has returns whether the cache contains the exact font descriptor.
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.
Collection is a collection of fonts, regrouped under a common typeface.
type Collection []Face
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 }
Face holds a font descriptor and the associated font face.
type Face struct { Font Font Face *opentype.Font }
func (f *Face) Extents() Extents
Extents returns the FontExtents for a font.
func (f *Face) FontFace(dpi float64) font.Face
FontFace returns the opentype font face for the requested dots-per-inch resolution.
func (f *Face) Name() string
Name returns a fully qualified name for the given font.
func (f *Face) Width(s string) Length
Width returns width of a string when drawn using the 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(fnt Font, size Length) Font
From returns a copy of the provided font with its size set.
func (f *Font) Name() string
Name returns a fully qualified name for the given font.
Length is a unit-independent representation of length. Internally, the length is stored in postscript points.
type Length float64
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(pt float64) Length
Points returns a length for the given number of points.
func (l Length) Dots(dpi float64) float64
Dots returns the length in dots for the given resolution.
func (l Length) Points() float64
Points returns the length in postscript points.
Typeface identifies a particular typeface design. The empty string denotes the default typeface.
type Typeface string
Variant denotes a typeface variant, such as "Mono", "Smallcaps" or "Math".
type Variant string
Name | Synopsis |
---|---|
.. | |
liberation | Package liberation exports the Liberation fonts as a font.Collection. |