package font
import "gonum.org/v1/plot/font"
Package font provides types to describe and select text font faces.
Index ¶
- Constants
- type Cache
- func NewCache(coll Collection) *Cache
- func (c *Cache) Add(coll Collection)
- func (c *Cache) GobDecode([]byte) error
- func (c *Cache) GobEncode() ([]byte, error)
- func (c *Cache) Has(fnt Font) bool
- func (c *Cache) Lookup(fnt Font, size Length) Face
- type Collection
- type Extents
- type Face
- func (f *Face) Extents() Extents
- func (f *Face) FontFace(dpi float64) font.Face
- func (f *Face) Name() string
- func (f *Face) Width(s string) Length
- type Font
- type Length
- func ParseLength(value string) (Length, error)
- func Points(pt float64) Length
- func (l Length) Dots(dpi float64) float64
- func (l Length) Points() float64
- type Typeface
- type Variant
Constants ¶
const ( Inch Length = 72 Centimeter = Inch / 2.54 Millimeter = Centimeter / 10 )
Common lengths.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache collects font faces.
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 (*Cache) GobEncode ¶
func (*Cache) Has ¶
Has returns whether the cache contains the exact font descriptor.
func (*Cache) Lookup ¶
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 ¶
Face holds a font descriptor and the associated font face.
func (*Face) Extents ¶
Extents returns the FontExtents for a font.
func (*Face) FontFace ¶
FontFace returns the opentype font face for the requested dots-per-inch resolution.
func (*Face) Name ¶
Name returns a fully qualified name for the given font.
func (*Face) Width ¶
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 ¶
From returns a copy of the provided font with its size set.
func (*Font) Name ¶
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 ¶
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 ¶
Points returns a length for the given number of points.
func (Length) Dots ¶
Dots returns the length in dots for the given resolution.
func (Length) Points ¶
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".
Source Files ¶
doc.go font.go len.go
Directories ¶
Path | Synopsis |
---|---|
font/liberation | Package liberation exports the Liberation fonts as a font.Collection. |
- Version
- v0.15.0 (latest)
- Published
- Oct 22, 2024
- Platform
- linux/amd64
- Imports
- 9 packages
- Last checked
- 1 week ago –
Tools for package owners.