font

package
v0.0.0-...-225857b Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2025 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package font is a lightweight wrapper around the Ebiten fonts API of the github.com/hajimehoshi/ebiten/v2/text/v2 package.

It provides several conveniences that are absent in the relatively low-level text/v2 package:

- A registry which caches loaded fonts. - Support for finding and using system fonts (provided by sysfont).

It still provides access to the low-level text/v2 representation for rendering.

Index

Constants

View Source
const (
	DirectionLeftToRight               = text.DirectionLeftToRight
	DirectionRightToLeft               = text.DirectionRightToLeft
	DirectionTopToBottomAndLeftToRight = text.DirectionTopToBottomAndLeftToRight
	DirectionTopToBottomAndRightToLeft = text.DirectionTopToBottomAndRightToLeft
)

Variables

This section is empty.

Functions

func RegisterSource

func RegisterSource(name string, s Source)

RegisterSource adds a source to the registry under the provided name.

Overrides any system fonts. Safe to call from multiple goroutines simultaneously.

Types

type Face

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

Face represents a configuration of the display of text.

func NewFace

func NewFace(src Source, size float64, opts ...Option) *Face

NewFace creates a new font face that can be used to draw text.

func (*Face) LineSize

func (f *Face) LineSize(lineSpacing float64) float64

LineSize is the amount of vertical or horizontal space (depending on the face's Direction) takes up on a line. lineSpacing is the relative amount of additional spacing to provide the line. For example, 0.0 is single-spaced and 1.0 is double-spaced. Negative lineSpacing reduces the line size.

func (*Face) Resize

func (f *Face) Resize(size float64) *Face

Resize returns a new Face with all the same features except with the font size changed to the provided size.

func (*Face) Size

func (f *Face) Size() float64

Size returns the size of the Face.

func (*Face) Source

func (f *Face) Source() Source

Source returns the Source for the Face.

func (*Face) TextFace

func (f *Face) TextFace() *text.GoTextFace

TextFace returns the underlying Ebiten GoTextFace.

Mutating the result will also mutate Face.

type Option

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

Option represents additional optional configuration for a Face.

func Direction

func Direction(d TextDirection) Option

Direction sets the Face's rendering direction.

func Language

func Language(t language.Tag) Option

Language sets the Face's language hint.

type Source

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

Source is a font source used to create Faces, which are used to draw text.

var DefaultSource Source

DefaultSource is a Source guaranteed to exist that may be used as a fallback.

func FindSource

func FindSource(name string) (Source, bool)

FindSource looks first for a pre-registered font source, registered by RegisterSource, and if that fails, searches the system for related fonts (via fuzzy match), then registers and returns that font source.

Safe to call from multiple goroutines simultaneously.

func NewSource

func NewSource(r io.Reader) (Source, error)

NewSource creates a new font source from an io.Reader whose stream must be an OTF or TTF-formatted file.

func NewSourceFromBytes

func NewSourceFromBytes(ttf []byte) (Source, error)

NewSourceFromBytes creates a new font source from the bytes of an OTF or TTF file.

func NewSourceFromFile

func NewSourceFromFile(filename string) (Source, error)

NewSourceFromFile create a new font source from an OTF or TTF file.

type TextDirection

type TextDirection = text.Direction

Jump to

Keyboard shortcuts

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