go-sdl2: github.com/veandco/go-sdl2/ttf Index | Files

package ttf

import "github.com/veandco/go-sdl2/ttf"

Package ttf is a TrueType font rendering library that is used with the SDL library, and almost as portable. It depends on freetype2 to handle the TrueType font data. It allows a programmer to use multiple TrueType fonts without having to code a font rendering routine themselves. With the power of outline fonts and antialiasing, high quality text output can be obtained without much effort.

Index

Package Files

sdl_ttf.go sdl_ttf_cgo.go

Constants

const (
    HINTING_NORMAL = int(C.TTF_HINTING_NORMAL)
    HINTING_LIGHT  = int(C.TTF_HINTING_LIGHT)
    HINTING_MONO   = int(C.TTF_HINTING_MONO)
    HINTING_NONE   = int(C.TTF_HINTING_NONE)
)

Hinting settings.

const (
    STYLE_NORMAL        = 0
    STYLE_BOLD          = 0x01
    STYLE_ITALIC        = 0x02
    STYLE_UNDERLINE     = 0x04
    STYLE_STRIKETHROUGH = 0x08
)

Font rendering styles.

func ByteSwappedUnicode Uses

func ByteSwappedUnicode(swap bool)

ByteSwappedUnicode tells SDL_ttf whether UNICODE (Uint16 per character) text is generally byteswapped. (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_20.html)

func GetError Uses

func GetError() error

GetError returns the last error that occurred, or an empty string if there hasn't been an error message set since the last call to sdl.ClearError(). (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_12.html)

func Init Uses

func Init() error

Init initializes the truetype font API. This must be called before using other functions in this library, except ttf.WasInit(). SDL does not have to be initialized before this call. (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_8.html)

func Quit Uses

func Quit()

Quit shuts down and cleanups the truetype font API. After calling this the SDL_ttf functions should not be used, excepting ttf.WasInit(). You may, of course, use ttf.Init() to use the functionality again. (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_10.html)

func SetError Uses

func SetError(err string)

SetError sets the SDL error message to the specified string. (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_11.html)

func WasInit Uses

func WasInit() bool

WasInit reports whether the truetype font API is initialized. Use this before ttf.Init() to avoid initializing twice in a row. Or use this to determine if you need to call ttf.Quit(). (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_9.html)

type Font Uses

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

Font contains font information.

func OpenFont Uses

func OpenFont(file string, size int) (*Font, error)

OpenFont loads file for use as a font, at the specified size. This is actually OpenFontIndex(file, size, 0). This can load TTF and FON files. (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_14.html)

func OpenFontIndex Uses

func OpenFontIndex(file string, size int, index int) (*Font, error)

OpenFontIndex loads file, face index, for use as a font, at the specified size. This is actually OpenFontIndexRW(RWFromFile(file), size, index), but checks that the RWops it creates is not NULL. This can load TTF and FON files. (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_16.html)

func OpenFontIndexRW Uses

func OpenFontIndexRW(src *sdl.RWops, freesrc, size, index int) (*Font, error)

OpenFontIndexRW loads src, face index, for use as a font, at the specified size. This can load TTF and FON formats. Using SDL_RWops is not covered here, but they enable you to load from almost any source. (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_17.html)

func OpenFontRW Uses

func OpenFontRW(src *sdl.RWops, freesrc, size int) (*Font, error)

OpenFontRW loads src for use as a font, at specified size. This is actually OpenFontIndexRW(src, freesrc, size, 0). This can load TTF and FON formats. Using SDL_RWops is not covered here, but they enable you to load from almost any source. (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_15.html)

func (*Font) Ascent Uses

func (f *Font) Ascent() int

Ascent returns the maximum pixel ascent of all glyphs of the loaded font. This can also be interpreted as the distance from the top of the font to the baseline. (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_30.html)

func (*Font) Close Uses

func (f *Font) Close()

Close frees the memory used by font, and frees font itself as well. Do not use font after this without loading a new font to it. (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_18.html)

func (*Font) Descent Uses

func (f *Font) Descent() int

Descent returns the maximum pixel descent of all glyphs of the loaded font. This can also be interpreted as the distance from the baseline to the bottom of the font. (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_31.html)

func (*Font) FaceFamilyName Uses

func (f *Font) FaceFamilyName() string

FaceFamilyName returns the current font face family name from the loaded font. (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_35.html)

func (*Font) FaceIsFixedWidth Uses

func (f *Font) FaceIsFixedWidth() bool

FaceIsFixedWidth reports whether the current font face of the loaded font is a fixed width font. Fixed width fonts are monospace, meaning every character that exists in the font is the same width, thus you can assume that a rendered string's width is going to be the result of a simple calculation: glyph_width * string_length. (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_34.html)

func (*Font) Faces Uses

func (f *Font) Faces() int

Faces returns the number of faces ("sub-fonts") available in the loaded font. (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_33.html)

func (*Font) GetHinting Uses

func (f *Font) GetHinting() int

GetHinting returns the current hinting setting of the loaded font. (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_25.html)

func (*Font) GetKerning Uses

func (f *Font) GetKerning() bool

GetKerning returns the current kerning setting of the loaded font. (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_27.html)

func (*Font) GetOutline Uses

func (f *Font) GetOutline() int

GetOutline returns the current outline size of the loaded font. (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_23.html)

func (*Font) GetStyle Uses

func (f *Font) GetStyle() int

GetStyle returns the rendering style of the loaded font. (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_21.html)

func (*Font) GlyphMetrics Uses

func (f *Font) GlyphMetrics(ch rune) (*GlyphMetrics, error)

GlyphMetrics returns the desired glyph metrics of the UNICODE char given in ch from the loaded font. (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_38.html)

func (*Font) Height Uses

func (f *Font) Height() int

Height returns the maximum pixel height of all glyphs of the loaded font. (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_29.html)

func (*Font) LineSkip Uses

func (f *Font) LineSkip() int

LineSkip returns the recommended pixel height of a rendered line of text of the loaded font. (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_32.html)

func (*Font) RenderUTF8Blended Uses

func (f *Font) RenderUTF8Blended(text string, color sdl.Color) (*sdl.Surface, error)

RenderUTF8Blended creates a 32-bit ARGB surface and render the given text at high quality, using alpha blending to dither the font with the given color. (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_52.html)

func (*Font) RenderUTF8BlendedWrapped Uses

func (f *Font) RenderUTF8BlendedWrapped(text string, fg sdl.Color, wrapLength int) (*sdl.Surface, error)

RenderUTF8BlendedWrapped creates a 32-bit ARGB surface and render the given text at high quality, using alpha blending to dither the font with the given color. Text is wrapped to multiple lines on line endings and on word boundaries if it extends beyond wrapLength in pixels.

func (*Font) RenderUTF8Shaded Uses

func (f *Font) RenderUTF8Shaded(text string, fg, bg sdl.Color) (*sdl.Surface, error)

RenderUTF8Shaded creates an 8-bit palettized surface and render the given text at high quality with the given font and colors. The 0 pixel is background, while other pixels have varying degrees of the foreground color. (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_48.html)

func (*Font) RenderUTF8Solid Uses

func (f *Font) RenderUTF8Solid(text string, color sdl.Color) (*sdl.Surface, error)

RenderUTF8Solid creates an 8-bit palettized surface and render the given text at fast quality with the given font and color. The 0 pixel is the colorkey, giving a transparent background, and the 1 pixel is set to the text color. (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_44.html)

func (*Font) SetHinting Uses

func (f *Font) SetHinting(hinting int)

SetHinting sets the hinting of the loaded font. (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_26.html)

func (*Font) SetKerning Uses

func (f *Font) SetKerning(allowed bool)

SetKerning sets whther to use kerning when rendering the loaded font. This has no effect on individual glyphs, but rather when rendering whole strings of characters, at least a word at a time. Perhaps the only time to disable this is when kerning is not working for a specific font, resulting in overlapping glyphs or abnormal spacing within words. (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_28.html)

func (*Font) SetOutline Uses

func (f *Font) SetOutline(outline int)

SetOutline sets the outline pixel width of the loaded font. (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_24.html)

func (*Font) SetStyle Uses

func (f *Font) SetStyle(style int)

SetStyle sets the rendering style of the loaded font. (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_22.html)

func (*Font) SizeUTF8 Uses

func (f *Font) SizeUTF8(text string) (int, int, error)

SizeUTF8 returns the resulting surface size (width and height) of the UTF8 encoded text rendered using font. No actual rendering is done, however correct kerning is done to get the actual width. The height returned in h is the same as you can get using ttf.Height(). (https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_40.html)

type GlyphMetrics Uses

type GlyphMetrics struct {
    MinX, MaxX int
    MinY, MaxY int
    Advance    int
}

GlyphMetrics contains glyph-specific rendering metrics.

Package ttf imports 4 packages (graph) and is imported by 30 packages. Updated 2018-11-19. Refresh now. Tools for package owners.