truetype

package
v0.0.0-...-e742af8 Latest Latest
Warning

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

Go to latest
Published: May 19, 2020 License: Zlib Imports: 5 Imported by: 0

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

View Source
const (
	PLATFORM_ID_UNICODE int = iota
	PLATFORM_ID_MAC
	PLATFORM_ID_ISO
	PLATFORM_ID_MICROSOFT
)
View Source
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 FlattenCurves(vertices []Vertex, objspaceFlatness float64) ([]point, []int, int)

func GetFontOffsetForIndex

func GetFontOffsetForIndex(data []byte, index int) int

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.

func Rasterize

func Rasterize(result *Bitmap, flatnessInPixels float64, vertices []Vertex, scaleX, scaleY, shiftX, shiftY float64, xOff, yOff int, invert bool)

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 Bitmap

type Bitmap struct {
	W      int
	H      int
	Stride int
	Pixels []byte
}

type Edge

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

type Edges

type Edges []Edge

func (Edges) Len

func (e Edges) Len() int

func (Edges) Less

func (e Edges) Less(i, j int) bool

func (Edges) Swap

func (e Edges) Swap(i, j int)

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

func InitFont(data []byte, offset int) (font *FontInfo, err error)

Given an offset into the file that defines a font, this function builds the necessary cached info for the rest of the system.

func (*FontInfo) FindGlyphIndex

func (font *FontInfo) FindGlyphIndex(unicodeCodepoint int) int

func (*FontInfo) GetCodepointBitmap

func (font *FontInfo) GetCodepointBitmap(scaleX, scaleY float64, codePoint, xoff, yoff int) ([]byte, int, int)

func (*FontInfo) GetCodepointBitmapBox

func (font *FontInfo) GetCodepointBitmapBox(codepoint int, scaleX, scaleY float64) (int, int, int, int)

func (*FontInfo) GetCodepointBitmapBoxSubpixel

func (font *FontInfo) GetCodepointBitmapBoxSubpixel(codepoint int, scaleX, scaleY, shiftX, shiftY float64) (int, int, int, int)

func (*FontInfo) GetCodepointBitmapSubpixel

func (font *FontInfo) GetCodepointBitmapSubpixel(scaleX, scaleY, shiftX, shiftY float64, codePoint, xoff, yoff int) ([]byte, int, int)

func (*FontInfo) GetCodepointHMetrics

func (font *FontInfo) GetCodepointHMetrics(codepoint int) (int, int)

func (*FontInfo) GetCodepointKernAdvance

func (font *FontInfo) GetCodepointKernAdvance(ch1, ch2 int) int

func (*FontInfo) GetFontBoundingBox

func (font *FontInfo) GetFontBoundingBox() (int, int, int, int)

func (*FontInfo) GetFontVMetrics

func (font *FontInfo) GetFontVMetrics() (int, int, int)

func (*FontInfo) GetGlyphBitmapBox

func (font *FontInfo) GetGlyphBitmapBox(glyph int, scaleX, scaleY float64) (int, int, int, int)

func (*FontInfo) GetGlyphBitmapBoxSubpixel

func (font *FontInfo) GetGlyphBitmapBoxSubpixel(glyph int, scaleX, scaleY, shiftX, shiftY float64) (ix0, iy0, ix1, iy1 int)

func (*FontInfo) GetGlyphBitmapSubpixel

func (font *FontInfo) GetGlyphBitmapSubpixel(scaleX, scaleY, shiftX, shiftY float64, glyph, xoff, yoff int) ([]byte, int, int)

func (*FontInfo) GetGlyphBox

func (font *FontInfo) GetGlyphBox(glyph int) (result bool, x0, y0, x1, y1 int)

func (*FontInfo) GetGlyphHMetrics

func (font *FontInfo) GetGlyphHMetrics(glyphIndex int) (int, int)

func (*FontInfo) GetGlyphKernAdvance

func (font *FontInfo) GetGlyphKernAdvance(glyph1, glyph2 int) int

func (*FontInfo) GetGlyphOffset

func (font *FontInfo) GetGlyphOffset(glyphIndex int) int

func (*FontInfo) GetGlyphShape

func (font *FontInfo) GetGlyphShape(glyphIndex int) []Vertex

func (*FontInfo) MakeCodepointBitmap

func (font *FontInfo) MakeCodepointBitmap(output []byte, outW, outH, outStride int, scaleX, scaleY float64, codepoint int) []byte

func (*FontInfo) MakeCodepointBitmapSubpixel

func (font *FontInfo) MakeCodepointBitmapSubpixel(output []byte, outW, outH, outStride int, scaleX, scaleY, shiftX, shiftY float64, codepoint int) []byte

func (*FontInfo) MakeGlyphBitmap

func (font *FontInfo) MakeGlyphBitmap(output []byte, outW, outH, outStride int, scaleX, scaleY float64, glyph int) []byte

func (*FontInfo) MakeGlyphBitmapSubpixel

func (font *FontInfo) MakeGlyphBitmapSubpixel(output []byte, outW, outH, outStride int, scaleX, scaleY, shiftX, shiftY float64, glyph int) []byte

func (*FontInfo) ScaleForPixelHeight

func (font *FontInfo) ScaleForPixelHeight(height float64) float64

type Vertex

type Vertex struct {
	X       int
	Y       int
	CX      int
	CY      int
	Type    uint8
	Padding byte
}

Jump to

Keyboard shortcuts

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