font

package
v0.0.0-...-df128bb Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Atlas

type Atlas struct {
	Meta AtlasMeta `json:"atlas"`
	Variant
}

Atlas is a structure that holds the JSON exported by msdf-atlas-gen.

type AtlasMeta

type AtlasMeta struct {
	// Type is the atlas mask type. It must be "mtsdf".
	Type string `json:"type"`
	// DistanceRange is number of pixels over which the signed distance
	// field goes from fully opaque to fully transparent.
	DistanceRange float32 `json:"distanceRange"`
	// Size is the number of pixels in the sprite sheet per EM unit.
	Size float32 `json:"size"`
	// Width is the width of the sprite sheet in pixels.
	// It should be a power of 2.
	Width int `json:"width"`
	// Height is the height of the sprite sheet in pixels.
	// It should be a power of 2.
	Height int `json:"height"`
	// YOrigin is the side of the image that corresponds to y = 0.
	// It must be "bottom".
	YOrigin string `json:"yOrigin"`
}

AtlasMeta holds data about the generated texture sheet.

type Bounds

type Bounds struct {
	Left   float32 `json:"left"`
	Bottom float32 `json:"bottom"`
	Right  float32 `json:"right"`
	Top    float32 `json:"top"`
}

Bounds is the bounds of a rectangle.

type Font

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

func New

func New(sheet *gfx.Sheet, atlas *Atlas) *Font

NewFont prepares a font atlas for rendering.

These files are generated using msdf-atlas gen, which is available from https://github.com/Chlumsky/msdf-atlas-gen

An example of a command to generate an atlas:

msdf-atlas-gen -font /usr/share/fonts/truetype/dejavu/DejaVuSans.ttf \
    -fontname "DejaVu Sans" -charset charset.txt -emrange 0.2 \
    -potr -type mtsdf -format png -imageout text.png -json text.json

func NewMulti

func NewMulti(sheet *gfx.Sheet, atlas *MultiAtlas) []*Font

NewFonts prepares multiple font atlases for rendering.

The input to this function is what msdf-atlas-gen creates when passed the `-and` argument.

See NewFont for an example of a command that generates a single-font atlas.

func (*Font) Advance

func (f *Font) Advance(letter, next rune) float32

func (*Font) DrawBorder

func (f *Font) DrawBorder(b *gfx.Batch, text string, x, y, z, sx, sy float32, centered bool, tint, borderTint gfx.Color)

func (*Font) Glyph

func (f *Font) Glyph(letter rune) *gfx.Sprite

func (*Font) Width

func (f *Font) Width(text string) float32

type Glyph

type Glyph struct {
	Unicode rune    `json:"unicode"`
	Advance float32 `json:"advance"`
	Plane   *Bounds `json:"planeBounds,omitempty"`
	Atlas   *Bounds `json:"atlasBounds,omitempty"`
}

Glyph holds data about one glyph in the font atlas.

type KerningPair

type KerningPair struct {
	Unicode1 rune    `json:"unicode1"`
	Unicode2 rune    `json:"unicode2"`
	Advance  float32 `json:"advance"`
}

KerningPair holds data about the distance between specific characters when they are rendered next to each other.

type Metrics

type Metrics struct {
	EmSize             float32 `json:"emSize"`
	LineHeight         float32 `json:"lineHeight"`
	Ascender           float32 `json:"ascender"`
	Descender          float32 `json:"descender"`
	UnderlineY         float32 `json:"underlineY"`
	UnderlineThickness float32 `json:"underlineThickness"`
}

Metrics holds data about the font itself.

type MultiAtlas

type MultiAtlas struct {
	Meta     AtlasMeta `json:"atlas"`
	Variants []Variant `json:"variants"`
}

type Variant

type Variant struct {
	Name    string        `json:"name,omitempty"`
	Metrics Metrics       `json:"metrics"`
	Glyphs  []Glyph       `json:"glyphs"`
	Kerning []KerningPair `json:"kerning"`
}

Jump to

Keyboard shortcuts

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