font9

package
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2023 License: BSD-3-Clause Imports: 11 Imported by: 1

Documentation

Overview

Package font9 implements the subfont format where characters are stored as a single image with the glyphs placed side-by-side on a common baseline.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalid     = Error{errors.New("invalid")}
	ErrUnsupported = Error{errors.New("unsupported")}
)

Functions

func Load

func Load(r io.Reader) (subfont.Data, error)

Load reads and parses the Plan9 subfont data. It supports 1, 2, 4 and 8 bit alpha colors.

Types

type Error

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

func (Error) Error

func (e Error) Error() string

func (Error) Unwrap

func (e Error) Unwrap() error

type Fixed

type Fixed struct {
	Left  int8
	Adv   uint8 // distance between two successive glyph origins when drawing
	Width uint8 // width of the glyph subimage
	Bits  Image // image holding the glyphs, the baseline is at y = 0
}

Fixed can hold data of a monospace font where all character subimages has the same width.

func (*Fixed) Advance

func (d *Fixed) Advance(i int) int

Advance implements fonts.Data interface

func (*Fixed) Glyph

func (d *Fixed) Glyph(i int) (img image.Image, origin image.Point, advance int)

Glyph implements fonts.Data interface

func (*Fixed) Num

func (d *Fixed) Num() int

Num returns the number of characters covered by d.

type Image

type Image interface {
	image.Image
	SubImage(r image.Rectangle) image.Image
}

Image is an image.Image with a SubImage method to obtain the portion of the image visible through r.

type Variable

type Variable struct {
	// Info stores information about N character subimagas in the N*4 + 2 bytes:
	// xlo0, xhi0, left0, advance0, ... , xloN, xhiN. The difference to the
	// original Plan 9 subfont is the lack of the top and bottom information.
	// Info is stored in a string to avoid being copied to RAM in the case of
	// systems that can leave read-only data in Flash. Use strings.Builder to
	// efficiently load/build it at runtime.
	Info string

	// Bits is an image holding the glyphs. The baseline is at y = 0.
	Bits Image
}

Variable can hold data of a monospace or proportional fonts. The character images can have different widths and origins.

func (*Variable) Advance

func (d *Variable) Advance(i int) int

Advance implements fonts.Data interface

func (*Variable) Glyph

func (d *Variable) Glyph(i int) (img image.Image, origin image.Point, advance int)

Glyph implements fonts.Data interface

func (*Variable) Num

func (d *Variable) Num() int

Num returns the number of characters covered by d.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL