image: golang.org/x/image/font/sfnt Index | Files

package sfnt

import "golang.org/x/image/font/sfnt"

Package sfnt implements a decoder for SFNT font file formats, including TrueType and OpenType.

Index

Package Files

cmap.go data.go postscript.go sfnt.go truetype.go

Variables

var (
    // ErrColoredGlyph indicates that the requested glyph is not a monochrome
    // vector glyph, such as a colored (bitmap or vector) emoji glyph.
    ErrColoredGlyph = errors.New("sfnt: colored glyph")
    // ErrNotFound indicates that the requested value was not found.
    ErrNotFound = errors.New("sfnt: not found")
)

type Buffer Uses

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

Buffer holds re-usable buffers that can reduce the total memory allocation of repeated Font method calls.

See the Font type's documentation comment for more details.

type Collection Uses

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

Collection is a collection of one or more fonts.

All of the Collection methods are safe to call concurrently.

func ParseCollection Uses

func ParseCollection(src []byte) (*Collection, error)

ParseCollection parses an SFNT 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.

func ParseCollectionReaderAt Uses

func ParseCollectionReaderAt(src io.ReaderAt) (*Collection, error)

ParseCollectionReaderAt parses an SFNT 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.

func (*Collection) Font Uses

func (c *Collection) Font(i int) (*Font, error)

Font returns the i'th font in the collection.

func (*Collection) NumFonts Uses

func (c *Collection) NumFonts() int

NumFonts returns the number of fonts in the collection.

type Font Uses

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

Font is an SFNT font.

Many of its methods take a *Buffer argument, as re-using buffers can reduce the total memory allocation of repeated Font method calls, such as measuring and rasterizing every unique glyph in a string of text. If efficiency is not a concern, passing a nil *Buffer is valid, and implies using a temporary buffer for a single call.

It is valid to re-use a *Buffer with multiple Font method calls, even with different *Font receivers, as long as they are not concurrent calls.

All of the Font methods are safe to call concurrently, as long as each call has a different *Buffer (or nil).

The Font methods that don't take a *Buffer argument are always safe to call concurrently.

Some methods provide lengths or coordinates, e.g. bounds, font metrics and control points. All of these methods take a ppem parameter, which is the number of pixels in 1 em, expressed as a 26.6 fixed point value. For example, if 1 em is 10 pixels then ppem is fixed.I(10), which equals fixed.Int26_6(10 << 6).

To get those lengths or coordinates in terms of font units instead of pixels, use ppem = fixed.Int26_6(f.UnitsPerEm()) and if those methods take a font.Hinting parameter, use font.HintingNone. The return values will have type fixed.Int26_6, but those numbers can be converted back to Units with no further scaling necessary.

func Parse Uses

func Parse(src []byte) (*Font, error)

Parse parses an SFNT font, such as TTF or OTF data, from a []byte data source.

func ParseReaderAt Uses

func ParseReaderAt(src io.ReaderAt) (*Font, error)

ParseReaderAt parses an SFNT font, such as TTF or OTF data, from an io.ReaderAt data source.

func (*Font) Bounds Uses

func (f *Font) Bounds(b *Buffer, ppem fixed.Int26_6, h font.Hinting) (fixed.Rectangle26_6, error)

Bounds returns the union of a Font's glyphs' bounds.

In the returned Rectangle26_6's (x, y) coordinates, the Y axis increases down.

func (*Font) GlyphAdvance Uses

func (f *Font) GlyphAdvance(b *Buffer, x GlyphIndex, ppem fixed.Int26_6, h font.Hinting) (fixed.Int26_6, error)

GlyphAdvance returns the advance width for the x'th glyph. ppem is the number of pixels in 1 em.

It returns ErrNotFound if the glyph index is out of range.

func (*Font) GlyphIndex Uses

func (f *Font) GlyphIndex(b *Buffer, r rune) (GlyphIndex, error)

GlyphIndex returns the glyph index for the given rune.

It returns (0, nil) if there is no glyph for r. https://www.microsoft.com/typography/OTSPEC/cmap.htm says that "Character codes that do not correspond to any glyph in the font should be mapped to glyph index 0. The glyph at this location must be a special glyph representing a missing character, commonly known as .notdef."

func (*Font) GlyphName Uses

func (f *Font) GlyphName(b *Buffer, x GlyphIndex) (string, error)

GlyphName returns the name of the x'th glyph.

Not every font contains glyph names. If not present, GlyphName will return ("", nil).

If present, the glyph name, provided by the font, is assumed to follow the Adobe Glyph List Specification: https://github.com/adobe-type-tools/agl-specification/blob/master/README.md

This is also known as the "Adobe Glyph Naming convention", the "Adobe document [for] Unicode and Glyph Names" or "PostScript glyph names".

It returns ErrNotFound if the glyph index is out of range.

func (*Font) Kern Uses

func (f *Font) Kern(b *Buffer, x0, x1 GlyphIndex, ppem fixed.Int26_6, h font.Hinting) (fixed.Int26_6, error)

Kern returns the horizontal adjustment for the kerning pair (x0, x1). A positive kern means to move the glyphs further apart. ppem is the number of pixels in 1 em.

It returns ErrNotFound if either glyph index is out of range.

func (*Font) LoadGlyph Uses

func (f *Font) LoadGlyph(b *Buffer, x GlyphIndex, ppem fixed.Int26_6, opts *LoadGlyphOptions) ([]Segment, error)

LoadGlyph returns the vector segments for the x'th glyph. ppem is the number of pixels in 1 em.

If b is non-nil, the segments become invalid to use once b is re-used.

In the returned Segments' (x, y) coordinates, the Y axis increases down.

It returns ErrNotFound if the glyph index is out of range. It returns ErrColoredGlyph if the glyph is not a monochrome vector glyph, such as a colored (bitmap or vector) emoji glyph.

func (*Font) Metrics Uses

func (f *Font) Metrics(b *Buffer, ppem fixed.Int26_6, h font.Hinting) (font.Metrics, error)

Metrics returns the metrics of this font.

func (*Font) Name Uses

func (f *Font) Name(b *Buffer, id NameID) (string, error)

Name returns the name value keyed by the given NameID.

It returns ErrNotFound if there is no value for that key.

func (*Font) NumGlyphs Uses

func (f *Font) NumGlyphs() int

NumGlyphs returns the number of glyphs in f.

func (*Font) UnitsPerEm Uses

func (f *Font) UnitsPerEm() Units

UnitsPerEm returns the number of units per em for f.

type GlyphIndex Uses

type GlyphIndex uint16

GlyphIndex is a glyph index in a Font.

type LoadGlyphOptions Uses

type LoadGlyphOptions struct {
}

LoadGlyphOptions are the options to the Font.LoadGlyph method.

type NameID Uses

type NameID uint16

NameID identifies a name table entry.

See the "Name IDs" section of https://www.microsoft.com/typography/otspec/name.htm

const (
    NameIDCopyright                  NameID = 0
    NameIDFamily                            = 1
    NameIDSubfamily                         = 2
    NameIDUniqueIdentifier                  = 3
    NameIDFull                              = 4
    NameIDVersion                           = 5
    NameIDPostScript                        = 6
    NameIDTrademark                         = 7
    NameIDManufacturer                      = 8
    NameIDDesigner                          = 9
    NameIDDescription                       = 10
    NameIDVendorURL                         = 11
    NameIDDesignerURL                       = 12
    NameIDLicense                           = 13
    NameIDLicenseURL                        = 14
    NameIDTypographicFamily                 = 16
    NameIDTypographicSubfamily              = 17
    NameIDCompatibleFull                    = 18
    NameIDSampleText                        = 19
    NameIDPostScriptCID                     = 20
    NameIDWWSFamily                         = 21
    NameIDWWSSubfamily                      = 22
    NameIDLightBackgroundPalette            = 23
    NameIDDarkBackgroundPalette             = 24
    NameIDVariationsPostScriptPrefix        = 25
)

type Segment Uses

type Segment struct {
    // Op is the operator.
    Op  SegmentOp
    // Args is up to three (x, y) coordinates. The Y axis increases down.
    Args [3]fixed.Point26_6
}

Segment is a segment of a vector path.

type SegmentOp Uses

type SegmentOp uint32

SegmentOp is a vector path segment's operator.

const (
    SegmentOpMoveTo SegmentOp = iota
    SegmentOpLineTo
    SegmentOpQuadTo
    SegmentOpCubeTo
)

type Units Uses

type Units int32

Units are an integral number of abstract, scalable "font units". The em square is typically 1000 or 2048 "font units". This would map to a certain number (e.g. 30 pixels) of physical pixels, depending on things like the display resolution (DPI) and font size (e.g. a 12 point font).

Package sfnt imports 8 packages (graph). Updated 2017-10-13. Refresh now. Tools for package owners.