Documentation ¶
Overview ¶
This library processes TrueType files:
- parse files
- extract glyph metrics
- extract glyph shapes
- render glyphs to one-channel bitmaps with antialiasing (box filter)
Index ¶
- Constants
- func FlattenCurves(vertices []Vertex, objspaceFlatness float64) ([]point, []int, int)
- func GetFontOffsetForIndex(data []byte, index int) int
- func Rasterize(result *Bitmap, flatnessInPixels float64, vertices []Vertex, ...)
- type AlignedQuad
- type BakedChar
- type Bitmap
- type Edge
- type Edges
- type FontInfo
- func (font *FontInfo) FindGlyphIndex(unicodeCodepoint int) int
- func (font *FontInfo) GetCodepointBitmap(scaleX, scaleY float64, codePoint, xoff, yoff int) ([]byte, int, int)
- func (font *FontInfo) GetCodepointBitmapBox(codepoint int, scaleX, scaleY float64) (int, int, int, int)
- func (font *FontInfo) GetCodepointBitmapBoxSubpixel(codepoint int, scaleX, scaleY, shiftX, shiftY float64) (int, int, int, int)
- func (font *FontInfo) GetCodepointBitmapSubpixel(scaleX, scaleY, shiftX, shiftY float64, codePoint, xoff, yoff int) ([]byte, int, int)
- func (font *FontInfo) GetCodepointHMetrics(codepoint int) (int, int)
- func (font *FontInfo) GetCodepointKernAdvance(ch1, ch2 int) int
- func (font *FontInfo) GetFontBoundingBox() (int, int, int, int)
- func (font *FontInfo) GetFontVMetrics() (int, int, int)
- func (font *FontInfo) GetGlyphBitmapBox(glyph int, scaleX, scaleY float64) (int, int, int, int)
- func (font *FontInfo) GetGlyphBitmapBoxSubpixel(glyph int, scaleX, scaleY, shiftX, shiftY float64) (ix0, iy0, ix1, iy1 int)
- func (font *FontInfo) GetGlyphBitmapSubpixel(scaleX, scaleY, shiftX, shiftY float64, glyph, xoff, yoff int) ([]byte, int, int)
- func (font *FontInfo) GetGlyphBox(glyph int) (result bool, x0, y0, x1, y1 int)
- func (font *FontInfo) GetGlyphHMetrics(glyphIndex int) (int, int)
- func (font *FontInfo) GetGlyphKernAdvance(glyph1, glyph2 int) int
- func (font *FontInfo) GetGlyphOffset(glyphIndex int) int
- func (font *FontInfo) GetGlyphShape(glyphIndex int) []Vertex
- func (font *FontInfo) MakeCodepointBitmap(output []byte, outW, outH, outStride int, scaleX, scaleY float64, ...) []byte
- func (font *FontInfo) MakeCodepointBitmapSubpixel(output []byte, outW, outH, outStride int, ...) []byte
- func (font *FontInfo) MakeGlyphBitmap(output []byte, outW, outH, outStride int, scaleX, scaleY float64, glyph int) []byte
- func (font *FontInfo) MakeGlyphBitmapSubpixel(output []byte, outW, outH, outStride int, ...) []byte
- func (font *FontInfo) ScaleForPixelHeight(height float64) float64
- type Vertex
Constants ¶
const ( PLATFORM_ID_UNICODE int = iota PLATFORM_ID_MAC PLATFORM_ID_ISO PLATFORM_ID_MICROSOFT )
const ( MS_EID_SYMBOL int = 0 MS_EID_UNICODE_BMP = 1 MS_EID_SHIFTJIS = 2 MS_EID_UNICODE_FULL = 10 )
Variables ¶
This section is empty.
Functions ¶
func FlattenCurves ¶
func GetFontOffsetForIndex ¶
Each .ttf/.ttc file may have more than one font. Each font has a sequential index number starting from 0. Call this function to get the font offset for a given index; it returns -1 if the index is out of range. A regular .ttf file will only define one font and it always be at offset 0, so it will return '0' for index 0, and -1 for all other indices. You can just skip this step if you know it's that kind of font.
Types ¶
type AlignedQuad ¶
type AlignedQuad struct {
X0, Y0, S0, T0 float32 // top-left
X1, Y1, S1, T1 float32 // bottom-right
}
func GetBakedQuad ¶
func GetBakedQuad(chardata []*BakedChar, pw, ph, charIndex int, xpos, ypos float64, openglFillRule bool) (float64, *AlignedQuad)
Call GetBakedQuad with charIndex = 'character - firstChar', and it creates the quad you need to draw and advances the current position.
The coordinate system used assumes y increases downwards.
Characters will extend both above and below the current position.
type BakedChar ¶
type BakedChar struct {
// contains filtered or unexported fields
}
func BakeFontBitmap ¶
func BakeFontBitmap(data []byte, offset int, pixelHeight float64, pixels []byte, pw, ph, firstChar, numChars int) (chardata []*BakedChar, err error, bottomY int, rtPixels []byte)
offset is the font location (use offset=0 for plain .ttf), pixelHeight is the height of font in pixels. pixels is the bitmap to be filled in characters to bake. This uses a very crappy packing.
type FontInfo ¶
type FontInfo struct {
// contains filtered or unexported fields
}
FontInfo is defined publically so you can declare on on the stack or as a global or etc, but you should treat it as opaque.
func InitFont ¶
Given an offset into the file that defines a font, this function builds the necessary cached info for the rest of the system.