stbtt

package
v0.0.0-...-c17e622 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	STBTT_vmove = iota + 1
	STBTT_vline
	STBTT_vcurve
	STBTT_vcubic
)
View Source
const (
	STBTT_MACSTYLE_DONTCARE   = 0
	STBTT_MACSTYLE_BOLD       = 1
	STBTT_MACSTYLE_ITALIC     = 2
	STBTT_MACSTYLE_UNDERSCORE = 4
	STBTT_MACSTYLE_NONE       = 8 // <= not same as 0, this makes us check the bitfield is 0
)
View Source
const (
	STBTT_PLATFORM_ID_UNICODE   = 0
	STBTT_PLATFORM_ID_MAC       = 1
	STBTT_PLATFORM_ID_ISO       = 2
	STBTT_PLATFORM_ID_MICROSOFT = 3
)
View Source
const (
	STBTT_UNICODE_EID_UNICODE_1_0      = 0
	STBTT_UNICODE_EID_UNICODE_1_1      = 1
	STBTT_UNICODE_EID_ISO_10646        = 2
	STBTT_UNICODE_EID_UNICODE_2_0_BMP  = 3
	STBTT_UNICODE_EID_UNICODE_2_0_FULL = 4
)
View Source
const (
	STBTT_MS_EID_SYMBOL       = 0
	STBTT_MS_EID_UNICODE_BMP  = 1
	STBTT_MS_EID_SHIFTJIS     = 2
	STBTT_MS_EID_UNICODE_FULL = 10
)
View Source
const (
	STBTT_MAC_EID_ROMAN        = 0
	STBTT_MAC_EID_ARABIC       = 4
	STBTT_MAC_EID_JAPANESE     = 1
	STBTT_MAC_EID_HEBREW       = 5
	STBTT_MAC_EID_CHINESE_TRAD = 2
	STBTT_MAC_EID_GREEK        = 6
	STBTT_MAC_EID_KOREAN       = 3
	STBTT_MAC_EID_RUSSIAN      = 7
)
View Source
const (
	// problematic because there are e.g. 16 english LCIDs and 16 arabic LCIDs
	STBTT_MS_LANG_ENGLISH  = 0x0409
	STBTT_MS_LANG_ITALIAN  = 0x0410
	STBTT_MS_LANG_CHINESE  = 0x0804
	STBTT_MS_LANG_JAPANESE = 0x0411
	STBTT_MS_LANG_DUTCH    = 0x0413
	STBTT_MS_LANG_KOREAN   = 0x0412
	STBTT_MS_LANG_FRENCH   = 0x040c
	STBTT_MS_LANG_RUSSIAN  = 0x0419
	STBTT_MS_LANG_GERMAN   = 0x0407
	STBTT_MS_LANG_SPANISH  = 0x0409
	STBTT_MS_LANG_HEBREW   = 0x040d
	STBTT_MS_LANG_SWEDISH  = 0x041D
)
View Source
const (
	STBTT_MAC_LANG_ENGLISH            = 0
	STBTT_MAC_LANG_JAPANESE           = 11
	STBTT_MAC_LANG_ARABIC             = 12
	STBTT_MAC_LANG_KOREAN             = 23
	STBTT_MAC_LANG_DUTCH              = 4
	STBTT_MAC_LANG_RUSSIAN            = 32
	STBTT_MAC_LANG_FRENCH             = 1
	STBTT_MAC_LANG_SPANISH            = 6
	STBTT_MAC_LANG_GERMAN             = 2
	STBTT_MAC_LANG_SWEDISH            = 5
	STBTT_MAC_LANG_HEBREW             = 10
	STBTT_MAC_LANG_CHINESE_SIMPLIFIED = 33
	STBTT_MAC_LANG_ITALIAN            = 3
	STBTT_MAC_LANG_CHINESE_TRAD       = 19
)
View Source
const STBTT_MAX_OVERSAMPLE = 8
View Source
const STBTT_RASTERIZER_VERSION = 2
View Source
const STBTT__OVER_MASK = STBTT_MAX_OVERSAMPLE - 1

Variables

This section is empty.

Functions

func FindGlyphIndex

func FindGlyphIndex(info *FontInfo, unicode_codepoint int) int

If you're going to perform multiple operations on the same character and you want a speed-up, call this function with the character you're going to process, then use glyph-based functions instead of the codepoint-based functions. Returns 0 if the character codepoint is not defined in the font.

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.

func GetFontVMetrics

func GetFontVMetrics(info *FontInfo, ascent, descent, lineGap *int)

ascent is the coordinate above the baseline the font extends; descent is the coordinate below the baseline the font extends (i.e. it is typically negative) lineGap is the spacing between one row's descent and the next row's ascent... so you should advance the vertical position by "*ascent - *descent + *lineGap"

these are expressed in unscaled coordinates, so you must multiply by
the scale factor for a given size

func GetGlyphBitmapBoxSubpixel

func GetGlyphBitmapBoxSubpixel(font *FontInfo, glyph int, scale_x, scale_y, shift_x, shift_y float, ix0, iy0, ix1, iy1 *int)

func GetPackedQuad

func GetPackedQuad(chardata []PackedChar, pw, ph,
	char_index int,
	xpos, ypos *float,
	q *AlignedQuad,
	align_to_integer int)

func InitFont

func InitFont(info *FontInfo, data []byte, offset int) int

Given an offset into the file that defines a font, this function builds the necessary cached info for the rest of the system. You must allocate the stbtt_fontinfo yourself, and InitFont will fill it out. You don't need to do anything special to free it, because the contents are pure value data with no additional data structures. Returns 0 on failure.

func PackBegin

func PackBegin(spc *PackContext, pixels []byte, width, height, stride_in_bytes, padding int, alloc_context any) int

Initializes a packing context stored in the passed-in stbtt_pack_context. Future calls using this context will pack characters into the bitmap passed in here: a 1-channel bitmap that is width * height. stride_in_bytes is the distance from one row to the next (or 0 to mean they are packed tightly together). "padding" is the amount of padding to leave between each character (normally you want '1' for bitmaps you'll use as textures with bilinear filtering).

Returns 0 on failure, 1 on success.

func PackFontRangesRenderIntoRects

func PackFontRangesRenderIntoRects(spc *PackContext, info *FontInfo, ranges []PackRange, num_ranges int, rects []stbrp.Rect) int

func PackSetOversampling

func PackSetOversampling(spc *PackContext, h_oversample, v_oversample uint)

Oversampling a font increases the quality by allowing higher-quality subpixel positioning, and is especially valuable at smaller text sizes.

This function sets the amount of oversampling for all following calls to stbtt_PackFontRange(s) or stbtt_PackFontRangesGatherRects for a given pack context. The default (no oversampling) is achieved by h_oversample=1 and v_oversample=1. The total number of pixels required is h_oversample*v_oversample larger than the default; for example, 2x2 oversampling requires 4x the storage of 1x1. For best results, render oversampled textures with bilinear filtering. Look at the readme in stb/tests/oversample for information about oversampled fonts

To use with PackFontRangesGather etc., you must set it before calls call to PackFontRangesGatherRects.

func STBTT_GPOS_TODO_assert

func STBTT_GPOS_TODO_assert(x bool)

func STBTT_POINT_SIZE

func STBTT_POINT_SIZE(x int) int

func STBTT__COMPARE

func STBTT__COMPARE(a, b *stbtt__edge) int

func STBTT_acos

func STBTT_acos(x float32) float32

func STBTT_assert

func STBTT_assert(x bool)

func STBTT_cos

func STBTT_cos(x float32) float32

func STBTT_fabs

func STBTT_fabs(x float32) float32

func STBTT_fmod

func STBTT_fmod(x, y float32) float32

func STBTT_iceil

func STBTT_iceil(x float32) int

func STBTT_ifloor

func STBTT_ifloor(x float32) int

func STBTT_max

func STBTT_max(a, b int) int

func STBTT_maxf

func STBTT_maxf(a, b float) float

func STBTT_min

func STBTT_min(a, b int) int

func STBTT_minf

func STBTT_minf(a, b float) float

func STBTT_pow

func STBTT_pow(x, y float32) float32

func STBTT_sqrt

func STBTT_sqrt(x float32) float32

func STBTT_strlen

func STBTT_strlen(str string) int

func ScaleForMappingEmToPixels

func ScaleForMappingEmToPixels(info *FontInfo, pixels float) float

computes a scale factor to produce a font whose EM size is mapped to 'pixels' tall. This is probably what traditional APIs compute, but I'm not positive.

func ScaleForPixelHeight

func ScaleForPixelHeight(info *FontInfo, pixels float) float

computes a scale factor to produce a font whose "height" is 'pixels' tall. Height is measured as the distance from the highest ascender to the lowest descender; in other words, it's equivalent to calling stbtt_GetFontVMetrics and computing:

scale = pixels / (ascent - descent)

so if you prefer to measure height by the ascent only, use a similar calculation.

Types

type AlignedQuad

type AlignedQuad struct {
	X0, Y0, S0, T0 float // top-left
	X1, Y1, S1, T1 float // bottom-right
}

type FontInfo

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

The following structure is defined publicly so you can declare one on the stack or as a global or etc, but you should treat it as opaque.

type PackContext

type PackContext struct {
	PackInfo any

	Height int

	Pixels []byte
	// contains filtered or unexported fields
}

this is an opaque structure that you shouldn't mess with which holds all the context needed from PackBegin to PackEnd.

type PackRange

type PackRange struct {
	FontSize                     float
	FirstUnicodeCodepointInRange int   // if non-zero, then the chars are continuous, and this is the first codepoint
	ArrayOfUnicodeCodepoints     []int // if non-zero, then this is an array of unicode codepoints
	NumChars                     int
	ChardataForRange             []PackedChar // output

	Oversample struct {
		H, V byte
	}
}

type PackedChar

type PackedChar struct {
	AdvanceX float
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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