package opentype

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

Dependency Relation
	imports 7 packages, and imported by one package

Involved Source Files Package opentype implements a glyph rasterizer for TTF (TrueType Fonts) and OTF (OpenType Fonts). This package provides a high-level API, centered on the NewFace function, implementing the golang.org/x/image/font.Face interface. The sibling golang.org/x/image/font/sfnt package provides a low-level API.
Code Examples package main import ( "fmt" "image" "image/color" "log" "os" "golang.org/x/image/font" "golang.org/x/image/font/gofont/goitalic" "golang.org/x/image/font/opentype" "golang.org/x/image/math/fixed" ) func main() { const ( width = 72 height = 36 startingDotX = 6 startingDotY = 28 ) f, err := opentype.Parse(goitalic.TTF) if err != nil { log.Fatalf("Parse: %v", err) } face, err := opentype.NewFace(f, &opentype.FaceOptions{ Size: 32, DPI: 72, Hinting: font.HintingNone, }) if err != nil { log.Fatalf("NewFace: %v", err) } dst := image.NewGray(image.Rect(0, 0, width, height)) d := font.Drawer{ Dst: dst, Src: image.White, Face: face, Dot: fixed.P(startingDotX, startingDotY), } fmt.Printf("The dot is at %v\n", d.Dot) d.DrawString("jel") fmt.Printf("The dot is at %v\n", d.Dot) d.Src = image.NewUniform(color.Gray{0x7F}) d.DrawString("ly") fmt.Printf("The dot is at %v\n", d.Dot) const asciiArt = ".++8" buf := make([]byte, 0, height*(width+1)) for y := 0; y < height; y++ { for x := 0; x < width; x++ { c := asciiArt[dst.GrayAt(x, y).Y>>6] if c != '.' { // No-op. } else if x == startingDotX-1 { c = ']' } else if y == startingDotY-1 { c = '_' } buf = append(buf, c) } buf = append(buf, '\n') } os.Stdout.Write(buf) }
Package-Level Type Names (total 4)
/* sort by: | */
Collection is a collection of one or more fonts. All of the Collection methods are safe to call concurrently.
Face implements the font.Face interface for Font values. A Face is not safe to use concurrently. Close satisfies the font.Face interface. Glyph satisfies the font.Face interface. GlyphAdvance satisfies the font.Face interface. GlyphBounds satisfies the font.Face interface. Kern satisfies the font.Face interface. Metrics satisfies the font.Face interface. *Face : golang.org/x/image/font.Face *Face : github.com/prometheus/common/expfmt.Closer *Face : io.Closer
FaceOptions describes the possible options given to NewFace when creating a new font.Face from a Font. // DPI is the dots per inch resolution // Hinting selects how to quantize a vector font's glyph nodes // Size is the font size in points func NewFace(f *Font, opts *FaceOptions) (font.Face, error)
Font is an OpenType font, also known as an SFNT font. All of the Font methods are safe to call concurrently, as long as each call has a different *sfnt.Buffer (or nil). The Font methods that don't take a *sfnt.Buffer argument are always safe to call concurrently.
Package-Level Functions (total 5)
NewFace returns a new font.Face for the given Font. If opts is nil, sensible defaults will be used.
Parse parses an OpenType font, such as TTF or OTF data, from a []byte data source.
ParseCollection parses an OpenType font collection, such as TTC or OTC data, from a []byte data source. If passed data for a single font, a TTF or OTF instead of a TTC or OTC, it will return a collection containing 1 font.
ParseCollectionReaderAt parses an OpenType collection, such as TTC or OTC data, from an io.ReaderAt data source. If passed data for a single font, a TTF or OTF instead of a TTC or OTC, it will return a collection containing 1 font.
ParseReaderAt parses an OpenType font, such as TTF or OTF data, from an io.ReaderAt data source.