text

package
v0.0.0-...-a112006 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2017 License: BSD-2-Clause Imports: 15 Imported by: 0

Documentation

Overview

Package text implements text font support.

Index

Constants

View Source
const (
	HintingNone     = font.HintingNone
	HintingVertical = font.HintingVertical
	HintingFull     = font.HintingFull
)

Variables

This section is empty.

Functions

func Color4NRGBA

func Color4NRGBA(c *math32.Color4) color.NRGBA

Color4NRGBA converts a math32.Color4 to Go's image/color.NRGBA NON pre-multiplied alpha.

func StrCount

func StrCount(s string) int

strCount returns the number of runes in the specified string

func StrFind

func StrFind(s string, pos int) (start, length int)

StrFind returns the start and length of the rune at the specified position in the string

func StrInsert

func StrInsert(s, data string, col int) string

StrInsert inserts a string at the specified character position

func StrPrefix

func StrPrefix(text string, pos int) string

StrPrefix returns the prefix of the specified string up to the specified character position

func StrRemove

func StrRemove(s string, col int) string

StrRemove removes the rune from the specified string and position

Types

type Atlas

type Atlas struct {
	Chars   []CharInfo
	Image   *image.RGBA
	Height  int // Recommended vertical space between two lines of text
	Ascent  int // Distance from the top of a line to its base line
	Descent int // Distance from the bottom of a line to its baseline
}

func NewAtlas

func NewAtlas(font *Font, first, last rune) *Atlas

func (*Atlas) SavePNG

func (a *Atlas) SavePNG(filename string) error

SavePNG saves the current atlas image as a PNG image file

type Canvas

type Canvas struct {
	RGBA *image.RGBA
	// contains filtered or unexported fields
}

Canvas is an image to draw text

func NewCanvas

func NewCanvas(width, height int, bgColor *math32.Color4) *Canvas

NewCanvas creates and returns a pointer to a new canvas with the specified width and height in pixels and background color

func (Canvas) DrawText

func (c Canvas) DrawText(x, y int, text string, f *Font)

DrawText draws text at the specified position (in pixels) of this canvas, using the specified font. The supplied text string can contain line break escape sequences (\n).

func (Canvas) DrawTextCaret

func (c Canvas) DrawTextCaret(x, y int, text string, f *Font, line, col int) error

DrawTextCaret draws text at the specified position (in pixels) of this canvas, using the specified font, and also a caret at the specified line and column. The supplied text string can contain line break escape sequences (\n).

type CharInfo

type CharInfo struct {
	X      int // Position X in pixels in the sheet image from left to right
	Y      int // Position Y in pixels in the sheet image from top to bottom
	Width  int // Char width in pixels
	Height int // Char heigh in pixels
	// Normalized position of char in the image
	OffsetX float32
	OffsetY float32
	RepeatX float32
	RepeatY float32
}

type Font

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

func NewFont

func NewFont(fontfile string) (*Font, error)

NewFont creates and returns a new font object using the specified truetype font file

func NewFontFromData

func NewFontFromData(fontData []byte) (*Font, error)

NewFontFromData creates and returns a new font object from the specified data

func (*Font) BgColor4

func (f *Font) BgColor4() math32.Color4

BgColor returns the current background color

func (*Font) DPI

func (f *Font) DPI() float64

DPI returns the current font DPI

func (*Font) FgColor4

func (f *Font) FgColor4() math32.Color4

FgColor returns the current foreground color

func (*Font) MeasureText

func (f *Font) MeasureText(text string) (int, int)

MeasureText returns the maximum width and height in pixels necessary for an image to contain the specified text. The supplied text string can contain line break escape sequences (\n).

func (*Font) Metrics

func (f *Font) Metrics() font.Metrics

func (*Font) SetBgColor

func (f *Font) SetBgColor(color *math32.Color)

SetBgColor sets the current foreground color of the font The alpha value is set to 1 (opaque)

func (*Font) SetBgColor4

func (f *Font) SetBgColor4(color *math32.Color4)

SetBgColor sets the current background color of the font

func (*Font) SetDPI

func (f *Font) SetDPI(dpi float64)

SetDPI sets the current DPI for the font

func (*Font) SetFgColor

func (f *Font) SetFgColor(color *math32.Color)

SetFgColor sets the current foreground color of the font The alpha value is set to 1 (opaque)

func (*Font) SetFgColor4

func (f *Font) SetFgColor4(color *math32.Color4)

SetFgColor4 sets the current foreground color of the font

func (*Font) SetHinting

func (f *Font) SetHinting(hinting font.Hinting)

SetHinting sets the hinting type

func (*Font) SetLineSpacing

func (f *Font) SetLineSpacing(spacing float64)

SetLineSpacing sets the spacing between lines

func (*Font) SetSize

func (f *Font) SetSize(size float64)

SetSize sets the size of the font

func (*Font) Size

func (f *Font) Size() float64

Size returns the current font size

Jump to

Keyboard shortcuts

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