engine: github.com/g3n/engine/text Index | Files

package text

import "github.com/g3n/engine/text"

Package text implements text font support.

Index

Package Files

atlas.go doc.go font.go str.go

Constants

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

Font Hinting types.

func Color4RGBA Uses

func Color4RGBA(c *math32.Color4) color.RGBA

Color4RGBA converts a math32.Color4 to Go's color.RGBA.

func StrCount Uses

func StrCount(s string) int

StrCount returns the number of runes in the specified string

func StrFind Uses

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 Uses

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

StrInsert inserts a string at the specified character position

func StrPrefix Uses

func StrPrefix(text string, pos int) string

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

func StrRemove Uses

func StrRemove(s string, col int) string

StrRemove removes the rune from the specified string and position

type Atlas Uses

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
}

Atlas represents an image containing characters and the information about their location in the image

func NewAtlas Uses

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

NewAtlas returns a pointer to a new Atlas object

func (*Atlas) SavePNG Uses

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

SavePNG saves the current atlas image as a PNG image file

type Canvas Uses

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

Canvas is an image to draw on.

func NewCanvas Uses

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 Uses

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 Uses

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). TODO Implement caret as a gui.Panel in gui.Edit

type CharInfo Uses

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
}

CharInfo contains the information to locate a character in an Atlas

type Font Uses

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

Font represents a TrueType font face. Attributes must be set prior to drawing.

func NewFont Uses

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

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

func NewFontFromData Uses

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

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

func (*Font) DrawText Uses

func (f *Font) DrawText(text string) *image.RGBA

DrawText draws the specified text on a new, tightly fitting image, and returns a pointer to the image.

func (*Font) DrawTextOnImage Uses

func (f *Font) DrawTextOnImage(text string, x, y int, dst *image.RGBA)

DrawTextOnImage draws the specified text on the specified image at the specified coordinates.

func (*Font) MeasureText Uses

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

MeasureText returns the minimum 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 Uses

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

Metrics returns the font metrics.

func (*Font) SetAttributes Uses

func (f *Font) SetAttributes(fa *FontAttributes)

SetAttributes sets the font attributes.

func (*Font) SetBgColor Uses

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

SetBgColor sets the background color.

func (*Font) SetColor Uses

func (f *Font) SetColor(fg *math32.Color4)

SetColor sets the text color to the specified value and makes the background color transparent. Note that for perfect transparency in the anti-aliased region it's important that the RGB components of the text and background colors match. This method handles that for the user.

func (*Font) SetDPI Uses

func (f *Font) SetDPI(dpi float64)

SetDPI sets the resolution of the font in dots per inches (DPI).

func (*Font) SetFgColor Uses

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

SetFgColor sets the text color.

func (*Font) SetHinting Uses

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

SetHinting sets the hinting type.

func (*Font) SetLineSpacing Uses

func (f *Font) SetLineSpacing(spacing float64)

SetLineSpacing sets the amount of spacing between lines (in terms of font height).

func (*Font) SetPointSize Uses

func (f *Font) SetPointSize(size float64)

SetPointSize sets the point size of the font.

type FontAttributes Uses

type FontAttributes struct {
    PointSize   float64      // Point size of the font
    DPI         float64      // Resolution of the font in dots per inch
    LineSpacing float64      // Spacing between lines (in terms of font height)
    Hinting     font.Hinting // Font hinting
}

FontAttributes contains tunable attributes of a font.

Package text imports 14 packages (graph) and is imported by 5 packages. Updated 2018-06-11. Refresh now. Tools for package owners.