package font

Import Path
	golang.org/x/image/font (on go.dev)

Dependency Relation
	imports 5 packages, and imported by 5 packages

Involved Source Files Package font defines an interface for font faces, for drawing text on an image. Other packages provide font face implementations. For example, a truetype package would provide one based on .ttf font files.
Package-Level Type Names (total 7)
/* sort by: | */
Drawer draws text on a destination image. A Drawer is not safe for concurrent use by multiple goroutines, since its Face is not. Dot is the baseline location to draw the next glyph. The majority of the affected pixels will be above and to the right of the dot, but some may be below or to the left. For example, drawing a 'j' in an italic face may affect pixels below and to the left of the dot. Dst is the destination image. Face provides the glyph mask images. Src is the source image. BoundBytes returns the bounding box of s, drawn at the drawer dot, as well as the advance. It is equivalent to BoundBytes(string(s)) but may be more efficient. BoundString returns the bounding box of s, drawn at the drawer dot, as well as the advance. DrawBytes draws s at the dot and advances the dot's location. It is equivalent to DrawString(string(s)) but may be more efficient. DrawString draws s at the dot and advances the dot's location. MeasureBytes returns how far dot would advance by drawing s. It is equivalent to MeasureString(string(s)) but may be more efficient. MeasureString returns how far dot would advance by drawing s.
Face is a font face. Its glyphs are often derived from a font file, such as "Comic_Sans_MS.ttf", but a face has a specific size, style, weight and hinting. For example, the 12pt and 18pt versions of Comic Sans are two different faces, even if derived from the same font file. A Face is not safe for concurrent use by multiple goroutines, as its methods may re-use implementation-specific caches and mask image buffers. To create a Face, look to other packages that implement specific font file formats. ( Face) Close() error Glyph returns the draw.DrawMask parameters (dr, mask, maskp) to draw r's glyph at the sub-pixel destination location dot, and that glyph's advance width. It returns !ok if the face does not contain a glyph for r. This includes returning !ok for a fallback glyph (such as substituting a U+FFFD glyph or OpenType's .notdef glyph), in which case the other return values may still be non-zero. The contents of the mask image returned by one Glyph call may change after the next Glyph call. Callers that want to cache the mask must make a copy. GlyphAdvance returns the advance width of r's glyph. It returns !ok if the face does not contain a glyph for r. This includes returning !ok for a fallback glyph (such as substituting a U+FFFD glyph or OpenType's .notdef glyph), in which case the other return values may still be non-zero. GlyphBounds returns the bounding box of r's glyph, drawn at a dot equal to the origin, and that glyph's advance width. It returns !ok if the face does not contain a glyph for r. This includes returning !ok for a fallback glyph (such as substituting a U+FFFD glyph or OpenType's .notdef glyph), in which case the other return values may still be non-zero. The glyph's ascent and descent are equal to -bounds.Min.Y and +bounds.Max.Y. The glyph's left-side and right-side bearings are equal to bounds.Min.X and advance-bounds.Max.X. A visual depiction of what these metrics are is at https://developer.apple.com/library/archive/documentation/TextFonts/Conceptual/CocoaTextArchitecture/Art/glyphterms_2x.png Kern returns the horizontal adjustment for the kerning pair (r0, r1). A positive kern means to move the glyphs further apart. Metrics returns the metrics for this Face. *golang.org/x/image/font/opentype.Face Face : github.com/prometheus/common/expfmt.Closer Face : io.Closer func golang.org/x/image/font/opentype.NewFace(f *opentype.Font, opts *opentype.FaceOptions) (Face, error) func github.com/golang/freetype/truetype.NewFace(f *truetype.Font, opts *truetype.Options) Face func gonum.org/v1/plot/font.(*Face).FontFace(dpi float64) Face func BoundBytes(f Face, s []byte) (bounds fixed.Rectangle26_6, advance fixed.Int26_6) func BoundString(f Face, s string) (bounds fixed.Rectangle26_6, advance fixed.Int26_6) func MeasureBytes(f Face, s []byte) (advance fixed.Int26_6) func MeasureString(f Face, s string) (advance fixed.Int26_6) func oss.terrastruct.com/d2/lib/textmeasure.NewAtlas(face Face, runeSets ...[]rune) *textmeasure.atlas
Hinting selects how to quantize a vector font's glyph nodes. Not all fonts support hinting. func golang.org/x/image/font/sfnt.(*Font).Bounds(b *sfnt.Buffer, ppem fixed.Int26_6, h Hinting) (fixed.Rectangle26_6, error) func golang.org/x/image/font/sfnt.(*Font).GlyphAdvance(b *sfnt.Buffer, x sfnt.GlyphIndex, ppem fixed.Int26_6, h Hinting) (fixed.Int26_6, error) func golang.org/x/image/font/sfnt.(*Font).GlyphBounds(b *sfnt.Buffer, x sfnt.GlyphIndex, ppem fixed.Int26_6, h Hinting) (bounds fixed.Rectangle26_6, advance fixed.Int26_6, err error) func golang.org/x/image/font/sfnt.(*Font).Kern(b *sfnt.Buffer, x0, x1 sfnt.GlyphIndex, ppem fixed.Int26_6, h Hinting) (fixed.Int26_6, error) func golang.org/x/image/font/sfnt.(*Font).Metrics(b *sfnt.Buffer, ppem fixed.Int26_6, h Hinting) (Metrics, error) func github.com/golang/freetype/truetype.(*GlyphBuf).Load(f *truetype.Font, scale fixed.Int26_6, i truetype.Index, h Hinting) error const HintingFull const HintingNone const HintingVertical
Metrics holds the metrics for a Face. A visual depiction is at https://developer.apple.com/library/mac/documentation/TextFonts/Conceptual/CocoaTextArchitecture/Art/glyph_metrics_2x.png Ascent is the distance from the top of a line to its baseline. CapHeight is the distance from the top of uppercase letters to the baseline. CaretSlope is the slope of a caret as a vector with the Y axis pointing up. The slope {0, 1} is the vertical caret. Descent is the distance from the bottom of a line to its baseline. The value is typically positive, even though a descender goes below the baseline. Height is the recommended amount of vertical space between two lines of text. XHeight is the distance from the top of non-ascending lowercase letters to the baseline. func Face.Metrics() Metrics func golang.org/x/image/font/opentype.(*Face).Metrics() Metrics func golang.org/x/image/font/sfnt.(*Font).Metrics(b *sfnt.Buffer, ppem fixed.Int26_6, h Hinting) (Metrics, error)
Stretch selects a normal, condensed, or expanded face. Not all fonts support stretches. const StretchCondensed const StretchExpanded const StretchExtraCondensed const StretchExtraExpanded const StretchNormal const StretchSemiCondensed const StretchSemiExpanded const StretchUltraCondensed const StretchUltraExpanded
Style selects a normal, italic, or oblique face. Not all fonts support styles. const StyleItalic const StyleNormal const StyleOblique
Weight selects a normal, light or bold face. Not all fonts support weights. The named Weight constants (e.g. WeightBold) correspond to CSS' common weight names (e.g. "Bold"), but the numerical values differ, so that in Go, the zero value means to use a normal weight. For the CSS names and values, see https://developer.mozilla.org/en/docs/Web/CSS/font-weight const WeightBlack const WeightBold const WeightExtraBold const WeightExtraLight const WeightLight const WeightMedium const WeightNormal const WeightSemiBold const WeightThin
Package-Level Functions (total 4)
BoundBytes returns the bounding box of s with f, drawn at a dot equal to the origin, as well as the advance. It is equivalent to BoundString(string(s)) but may be more efficient.
BoundString returns the bounding box of s with f, drawn at a dot equal to the origin, as well as the advance.
MeasureBytes returns how far dot would advance by drawing s with f. It is equivalent to MeasureString(string(s)) but may be more efficient.
MeasureString returns how far dot would advance by drawing s with f.
Package-Level Constants (total 24)
const HintingFull Hinting = 2
const HintingNone Hinting = 0
const StyleItalic Style = 1
const StyleNormal Style = 0
const StyleOblique Style = 2
const WeightBlack Weight = 5 // CSS font-weight value 900.
const WeightBold Weight = 3 // CSS font-weight value 700.
const WeightExtraBold Weight = 4 // CSS font-weight value 800.
const WeightExtraLight Weight = -2 // CSS font-weight value 200.
const WeightLight Weight = -1 // CSS font-weight value 300.
const WeightMedium Weight = 1 // CSS font-weight value 500.
const WeightNormal Weight = 0 // CSS font-weight value 400.
const WeightSemiBold Weight = 2 // CSS font-weight value 600.
const WeightThin Weight = -3 // CSS font-weight value 100.