text

package
v0.2.66 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2024 License: BSD-2-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package text implements text font support.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 baseline
	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

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

NewAtlas returns a pointer to a new Atlas object

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
	BgColor math32.Color4
}

Canvas is an image to draw on.

func NewCanvas

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

NewCanvas creates a new Canvas with the specified width, height, and background color.

func (*Canvas) DrawText

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

DrawText draws text at the specified position of this canvas, using the specified font. The supplied text string can contain line breaks

func (*Canvas) DrawTextCaret

func (c *Canvas) DrawTextCaret(x, y int, text string, f *Font, drawCaret bool, line, col, selStart, selEnd int)

DrawTextCaret draws text and a caret at the specified position, in pixels, of this canvas. The supplied text string can contain line breaks.

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 height 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

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

Font represents a TrueType font face.

func NewFontFromData

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

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

func (*Font) DrawText

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

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

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 breaks.

func (*Font) Metrics

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

Metrics returns the font metrics.

func (*Font) SetAttributes

func (f *Font) SetAttributes(attrib FontAttributes)

SetAttributes sets the font attributes.

func (*Font) SetBgColor

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

SetBgColor sets the background color.

func (*Font) SetColor

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

func (f *Font) SetDPI(dpi float64)

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

func (*Font) SetFgColor

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

SetFgColor sets the text color.

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 amount of spacing between lines (in terms of font height).

func (*Font) SetPointSize

func (f *Font) SetPointSize(size float64)

SetPointSize sets the point size of the font.

func (*Font) SetScaleXY

func (f *Font) SetScaleXY(x, y float64)

SetScaleXY sets the ratio of actual pixel/GL point.

type FontAttributes

type FontAttributes struct {
	PointSize      float64
	DPI            float64
	ScaleX, ScaleY float64
	Hinting        font.Hinting
	LineSpacing    float64
}

FontAttributes contains tunable attributes of a font.

Jump to

Keyboard shortcuts

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