font

package
v0.0.0-...-e1c21c9 Latest Latest
Warning

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

Go to latest
Published: May 10, 2019 License: Zlib Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateTextSize

func CalculateTextSize(text string, font Font, fontSize float32) f32.Vec2

func LoadTrueType

func LoadTrueType(r io.Reader, lc TTFConfig) (*fontAtlas, error)

LoadTrueType loads a truetype fontAtlas from the given stream and applies the given fontAtlas scale in points.

The low and high values determine the lower and upper rune limits we should load for this Font. For standard ASCII this would be:32, 127.

func Pow2Image

func Pow2Image(src image.Image) image.Image

Pow2Image returns the given image, scaled to the smallest power-of-two dimensions larger or equal to the input dimensions. It preserves the image format and contents.

This is useful if an image is to be used as an OpenGL Texture. These often require image data to have power-of-two dimensions.

func Wrap

func Wrap(font Font, text string, wrap, fontSize float32) (n int, lines string)

Types

type Direction

type Direction uint8

Direction represents the direction in which strings should be rendered.

const (
	LeftToRight Direction = iota // E.g.: Latin
	RightToLeft                  // E.g.: Arabic
	TopToBottom                  // E.g.: Old-Chinese
)

Known directions.

type Directional

type Directional interface {
	Direction() Direction
}

type Disposer

type Disposer interface {
	Dispose()
}

type Font

type Font interface {
	Tex2D() (uint16, *bk.Texture2D)
	Glyph(rune rune) (g Glyph, ok bool)
	Bounds() (gw, gh float32)
	Frame(rune rune) (x1, y1, x2, y2 float32)
}

Font provides all the information needed to render a Rune.

Tex2D returns the low-level bk-texture. Glyph returns the matrix of rune. Bounds returns the largest width and height for any of the glyphs in the fontAtlas. SizeOf measure the text and returns the width and height.

func LoadBitmap

func LoadBitmap(img, config io.Reader, scale int) (Font, error)

LoadBitmap loads a bitmap (raster) fontAtlas from the given sprite sheet and config files. It is optionally scaled by the given scale factor.

A scale factor of 1 retains the original size. A factor of 2 doubles the fontAtlas size, etc. A scale factor of 0 is not valid and will default to 1.

Supported image formats are 32-bit RGBA as PNG, JPEG.

type Glyph

type Glyph struct {
	Rune rune

	X      float32
	Y      float32
	Width  float32
	Height float32

	XOffset float32
	YOffset float32

	Advance int
}

A Glyph describes metrics for a single Font glyph. These indicate which area of a given image contains the glyph data and how the glyph should be spaced in a rendered string.

Advance determines the distance to the next glyph. This is used to properly align non-monospaced fonts.

type Point

type Point struct {
	X, Y float32
}

type TTFConfig

type TTFConfig interface {
	FontSize() int
	Runes() []rune
}

func ASCII

func ASCII(size int) TTFConfig

func NewTTFConfig

func NewTTFConfig(size int, runes []rune) TTFConfig

Jump to

Keyboard shortcuts

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