font

package
v1.0.1-fix Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package font supplies font face wrappers for monospaced fonts, for use with github.com/ezrec/ebiten_tcell.

Index

Constants

View Source
const (
	FontStyleNormal     = FontStyle(iota) // Normal font style.
	FontStyleBold                         // Bold font style.
	FontStyleItalic                       // Italic font style.
	FontStyleBoldItalic                   // Bold & Italic font style.
)

Variables

View Source
var ErrFontType = errors.New("unknown font source type")

Functions

This section is empty.

Types

type CacheFont

type CacheFont struct {
	FontMetrics ebiten_text.Metrics
	Cache       map[rune](*ebiten.Image)
	Width       int // Nominal cell width.
	Height      int // Nominal cell height.
	// contains filtered or unexported fields
}

Implements Face

func (*CacheFont) Empty

func (mf *CacheFont) Empty() *ebiten.Image

Empty() returns the empty image.

func (*CacheFont) Glyph

func (mf *CacheFont) Glyph(character rune, style FontStyle) (glyph *ebiten.Image, is_empty bool)

Glyph returns a glyph for a rune. Rune glyphs are cached on their first access.

func (*CacheFont) HasGlyph

func (mf *CacheFont) HasGlyph(character rune, style FontStyle) (has bool)

HasGlyph returns true if a rune is in the font, in the specified style.

func (*CacheFont) Metrics

func (mf *CacheFont) Metrics() ebiten_text.Metrics

Metrics returns the font metrics.

func (*CacheFont) SetGlyph

func (mf *CacheFont) SetGlyph(character rune, glyph *ebiten.Image)

SetGlyph() sets a glyph into the cache.

func (*CacheFont) Size

func (mf *CacheFont) Size() (width, height int)

Size of a cache-font cell.

type Face

type Face interface {
	Metrics() (metrics ebiten_text.Metrics)
	Size() (width, height int) // Character cell size, in pixels.
	Glyph(character rune, style FontStyle) (glyph *ebiten.Image, is_empty bool)
	Empty() (empty_glyph *ebiten.Image)
}

Face provides an interace to the font properties.

type FaceWithBackup

type FaceWithBackup struct {
	Face
	Backup Face
}

FaceWithBackup allows a font be the 'backup' for another font, if the primary font doesn't have the right runes. Implements Face

func (*FaceWithBackup) Glyph

func (fm *FaceWithBackup) Glyph(character rune, style FontStyle) (glyph *ebiten.Image, is_empty bool)

Glyph returns the image for the rune, using the backup font if needed.

type FaceWithOnlyRunes

type FaceWithOnlyRunes struct {
	Face
	Runes []rune
	// contains filtered or unexported fields
}

FaceWithOnlyRunes limits the font to only the specified runes.

func (*FaceWithOnlyRunes) Glyph

func (fm *FaceWithOnlyRunes) Glyph(character rune, style FontStyle) (glyph *ebiten.Image, is_empty bool)

Glyph returns the image for the rune, so long as it is in the mapping.

type FaceWithRuneMapping

type FaceWithRuneMapping struct {
	Face
	RuneMapping map[rune]rune
}

FaceWithRuneMapping applies a rune mapping to a font. Implements Face

func (*FaceWithRuneMapping) Glyph

func (fm *FaceWithRuneMapping) Glyph(character rune, style FontStyle) (glyph *ebiten.Image, is_empty bool)

Glyph returns the image for the rune, mapped by the rune-to-rune mapping.

type FaceWithStyle

type FaceWithStyle struct {
	StyleMap map[FontStyle]Face
}

FaceWithStyle has alternate fonts for bold or italic styles.

FontStyleNormal must be mapped to a valid face. Implements Face

func (*FaceWithStyle) Empty

func (fm *FaceWithStyle) Empty() (glyph *ebiten.Image)

Empty returns the empty glyph

func (*FaceWithStyle) Glyph

func (fm *FaceWithStyle) Glyph(character rune, style FontStyle) (glyph *ebiten.Image, is_empty bool)

Glyph returns the image for the rune, using the appropriate style font. FontStyleBoldItalic falls back to FontStyleBold FontStyleItalic falls back to FontStyleNormal FontStyleBold falls back to FontStyleNormal

FontStyleNormal must be mapped.

Style hints are passed unchanged to the underlying font.

func (*FaceWithStyle) Metrics

func (fm *FaceWithStyle) Metrics() ebiten_text.Metrics

Metrics returns the font metrics.

func (*FaceWithStyle) Size

func (fm *FaceWithStyle) Size() (width, height int)

Size returns the font size.

type FontStyle

type FontStyle int

FontStyle selects which font style with which to render a rune.

type MonoFont

type MonoFont struct {
	CacheFont
	Face ebiten_text.Face
	// contains filtered or unexported fields
}

Implements Face

func NewMonoFont

func NewMonoFont(source any) (mf *MonoFont, err error)

NewMonoFont() creates a new monospaced font face. Takes any of the following types:

  • image_font.Face
  • ebiten_text.Face
  • nil (assumes GoMono TTF, size 11)

func NewMonoFontFromTTF

func NewMonoFontFromTTF(source any, size float64) (mf *MonoFont, err error)

NewMonoFontFromTTF creates a new monospaced font face from a TTF font. Takes any of the following types: - io.Reader (to a TTF source) - []byte (of a TTF blob) - nil (assumes GoMono TTF)

func (*MonoFont) Glyph

func (mf *MonoFont) Glyph(character rune, style FontStyle) (glyph *ebiten.Image, is_empty bool)

Glyph returns a glyph for a rune. Rune glyphs are cached on their first access.

func (*MonoFont) HasGlyph

func (mf *MonoFont) HasGlyph(character rune, style FontStyle) (has bool)

HasGlyph returns true if a rune is in the font, in the specified style.

Jump to

Keyboard shortcuts

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