Documentation ¶
Overview ¶
Package text implements text font support.
Index ¶
- Constants
- func Color4RGBA(c *math32.Color4) color.RGBA
- func StrCount(s string) int
- func StrFind(s string, pos int) (start, length int)
- func StrInsert(s, data string, col int) string
- func StrPrefix(text string, pos int) string
- func StrRemove(s string, col int) string
- type Atlas
- type Canvas
- type CharInfo
- type Font
- func (f *Font) DrawText(text string) *image.RGBA
- func (f *Font) DrawTextOnImage(text string, x, y int, dst *image.RGBA)
- func (f *Font) MeasureText(text string) (int, int)
- func (f *Font) Metrics() font.Metrics
- func (f *Font) ScaleX() float64
- func (f *Font) ScaleXY() (x, y float64)
- func (f *Font) ScaleY() float64
- func (f *Font) SetAttributes(fa *FontAttributes)
- func (f *Font) SetBgColor(color *math32.Color4)
- func (f *Font) SetColor(fg *math32.Color4)
- func (f *Font) SetDPI(dpi float64)
- func (f *Font) SetFgColor(color *math32.Color4)
- func (f *Font) SetHinting(hinting font.Hinting)
- func (f *Font) SetLineSpacing(spacing float64)
- func (f *Font) SetPointSize(size float64)
- func (f *Font) SetScaleXY(x, y float64)
- type FontAttributes
Constants ¶
const ( HintingNone = font.HintingNone HintingVertical = font.HintingVertical HintingFull = font.HintingFull )
Font Hinting types.
Variables ¶
This section is empty.
Functions ¶
func Color4RGBA ¶
Color4RGBA converts a math32.Color4 to Go's color.RGBA.
func StrFind ¶
StrFind returns the start and length of the rune at the specified position in the string
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
type Canvas ¶
Canvas is an image to draw on.
func NewCanvas ¶
NewCanvas creates and returns a pointer to a new canvas with the specified width and height in pixels and background color
func (Canvas) DrawText ¶
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 ¶
NewFont creates and returns a new font object using the specified TrueType font file.
func NewFontFromData ¶
NewFontFromData creates and returns a new font object from the specified TTF data.
func (*Font) DrawText ¶
DrawText draws the specified text on a new, tightly fitting image, and returns a pointer to the image.
func (*Font) DrawTextOnImage ¶
DrawTextOnImage draws the specified text on the specified image at the specified coordinates.
func (*Font) MeasureText ¶
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) SetAttributes ¶
func (f *Font) SetAttributes(fa *FontAttributes)
SetAttributes sets the font attributes.
func (*Font) SetBgColor ¶
SetBgColor sets the background color.
func (*Font) SetColor ¶
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) SetFgColor ¶
SetFgColor sets the text color.
func (*Font) SetHinting ¶
SetHinting sets the hinting type.
func (*Font) SetLineSpacing ¶
SetLineSpacing sets the amount of spacing between lines (in terms of font height).
func (*Font) SetPointSize ¶
SetPointSize sets the point size of the font.
func (*Font) SetScaleXY ¶ added in v0.3.4
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.