ratlas

package module
v0.0.0-...-ec72f08 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2017 License: MIT Imports: 12 Imported by: 0

README

ratlas

Generates rune atlas images given a TTF font.

img1

Usage Examples

To build the examples, enter the example directory and type:

go build create-runeatlas.go
go build fontdraw-simple.go

See the source of each sample application for detailed example usage.

The pattern for the atlas creation function is as follows:

func New(ttfData *[]byte, fontPt float64, imgWidth, imgHeight, pad int, runes []rune) Atlas

This will create a ratlas.Atlas from the given font bytedata, at the given font size, on images of the specified dimensions, using the runes specified.

License

MIT, see LICENSE.md for details.

Documentation

Overview

Package ratlas generates rune atlas images given a slice of runes and a TTF font. Atlas and atlas item information can also be saved and loaded. Values are stored as float32 for ease of use with OpenGL.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Atlas

type Atlas struct {
	Face   font.Face
	FontPt float64
	Pad    int

	Items  map[rune]*AtlasItem
	Images []draw.Image
}

func New

func New(ttfData *[]byte, fontPt float64, imgWidth, imgHeight, pad int, runes []rune) Atlas

New returns a Atlas of a given TTF data, image dimensions, and a given slice of runes.

func (*Atlas) Ascent

func (atlas *Atlas) Ascent() float32

Ascent returns a float32 of the distance from the top of a line to its baseline.

func (*Atlas) Descent

func (atlas *Atlas) Descent() float32

Descent returns a float32 of the distance from the bottom of a line to its baseline.

func (*Atlas) GobDecode

func (atlas *Atlas) GobDecode(buf []byte) error

func (*Atlas) GobEncode

func (atlas *Atlas) GobEncode() ([]byte, error)

func (*Atlas) Height

func (atlas *Atlas) Height() float32

Height returns a float32 of the recommended amount of vertical space between two lines of text.

func (*Atlas) Kern

func (atlas *Atlas) Kern(a, b rune) float32

Kern returns a float32 of the kern distance between two runes.

func (*Atlas) LoadGobFile

func (atlas *Atlas) LoadGobFile(fileName string) error

LoadGobFile populates an empty atlas per the contents of an exported gob file.

func (*Atlas) LoadImageFiles

func (atlas *Atlas) LoadImageFiles(imageFilenames []string) error

LoadImageFiles loads a slice of strings that point to image files to load into the atlas.

func (*Atlas) ReloadFont

func (atlas *Atlas) ReloadFont(ttfData *[]byte) error

ReloadFont parses TTF data in order to generate a font.Face for the atlas.

func (*Atlas) SaveGobFile

func (atlas *Atlas) SaveGobFile(fileName string) error

SaveGobFile dumps atlas info to a gob file.

func (*Atlas) SaveImageFiles

func (atlas *Atlas) SaveImageFiles(name string) error

SaveImageFiles dumps all generated atlas images to disk.

func (*Atlas) ScaleNumbers

func (atlas *Atlas) ScaleNumbers(v float32)

ScaleNumbers scales the numbers within an Atlas and its AtlasItem(s), for example, if a loaded image was scaled since saving the atlas info.

type AtlasItem

type AtlasItem struct {
	Rune          rune
	Advance       float32
	BearingX      float32
	Descent       float32
	PercentPosX   float32
	PercentPosY   float32
	PercentWidth  float32
	PercentHeight float32
	Width         int
	Height        int
	Node          *node
	ImageIndex    int
}

AtlasItem contains all the information needed to draw a specific rune within an Atlas.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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