font

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2022 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package font provides a simple interface to render fonts. An implementation is allowed to store glyphs in any form (pixmap, vector) but must return them rendered in alpha channel of image.Image.

Index

Constants

View Source
const (
	// Nearest means nearest-neighbor scaling. Use if the pixelated look of the
	// scaled font is acceptable or desirable.
	Nearest = images.Nearest

	// Bilinear means bilinear interpolation. Use if the pixelated look of the
	// Nearest is undesirable.
	Bilinear = images.Bilinear
)

Scaling mode.

Variables

This section is empty.

Functions

This section is empty.

Types

type Face

type Face interface {
	// Size returns the font face height (interline spacing) and the ascent
	// (height above the baseline).
	Size() (height, ascent int)

	// Advance returns the glyph advance for the given rune. The advance
	// determines the x-distance on the baseline between the origin point of the
	// current character and the origin point of next character.
	Advance(r rune) int

	// Glyph returns the graphical representation of the given rune in the alpha
	// channel of returned image. The image is valid until the next Glyph call
	// which makes Face UNSAFE for concurrent use. The origin point is given in
	// the img coordinates, may be outside of the image bounds.
	Glyph(r rune) (img image.Image, origin image.Point, advance int)
}

Face converts an unicode codepoint (rune) to its graphical representation (glyph) in some font face. A font face represents a specific size, style and weight of a font.

The implementation of Face is allowed to be UNSAFE for concurrent use (see description of Glyph method). In such case a font repository should provide a way to request multiple independend Face instances that represents the same font face in the repository.

type Magnifier

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

Magnifier can wrap Face to scale it up at runtime by integer factor. It can be useful if the available fonts are too small for a display. Magnifier is UNSAFE for concurrent use. A goroutine should magnify the selected font face just before using it and should not share magnified faces with other goroutines.

func Magnify

func Magnify(face Face, sx, sy int, mode byte) *Magnifier

Magnify wraps face into Magnifier to scale it up by scale factor usind given scaling mode.

func (*Magnifier) Advance

func (p *Magnifier) Advance(r rune) int

Advance implements Face interface.

func (*Magnifier) Face

func (p *Magnifier) Face() Face

Face returns the base font face.

func (*Magnifier) Glyph

func (p *Magnifier) Glyph(r rune) (img image.Image, origin image.Point, advance int)

Glyph implements Face interface.

func (*Magnifier) Scale

func (p *Magnifier) Scale() (sx, sy int)

Scale returns current scaling factors.

func (*Magnifier) SetFace

func (p *Magnifier) SetFace(face Face)

SetFace sets the base font face.

func (*Magnifier) SetScale

func (p *Magnifier) SetScale(sx, sy int)

SetScale sets the scaling factor.

func (*Magnifier) Size

func (p *Magnifier) Size() (height, ascent int)

Size implements Face interface.

Directories

Path Synopsis
Package subfont defines a font as a collection of subfonts.
Package subfont defines a font as a collection of subfonts.
font9
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.
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.
gfxfont
TODO: Package gfxfont implements the Adafruit GFX subfont format.
TODO: Package gfxfont implements the Adafruit GFX subfont format.

Jump to

Keyboard shortcuts

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