text

package
v0.2.26 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2024 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
)

Font Hinting types.

Variables

This section is empty.

Functions

func Color4RGBA

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

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

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
}

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
	// contains filtered or unexported fields
}

Canvas is an image to draw on.

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, drawCaret bool, line, col, selStart, selEnd 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

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

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

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

func NewFont

func NewFont(ttfFile 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 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 break escape sequences (\n).

func (*Font) Metrics

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

Metrics returns the font metrics.

func (*Font) ScaleX

func (f *Font) ScaleX() float64

func (*Font) ScaleXY

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

func (*Font) ScaleY

func (f *Font) ScaleY() float64

func (*Font) SetAttributes

func (f *Font) SetAttributes(fa *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)

SetScale sets the ratio of actual pixel/GL point.

type FontAttributes

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.

Jump to

Keyboard shortcuts

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