dplug.graphics.stb_truetype

D translation of stb_truetype v0.7 by Sean Barrett More information on http://nothings.org/stb/stb_truetype.h Removed: - texture baking API - font finding in the TTF itself. Make sure there is only one font in the TTF.

Members

Functions

stbtt_FindGlyphIndex
int stbtt_FindGlyphIndex(const(stbtt_fontinfo)* info, int unicode_codepoint)

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.

stbtt_FreeBitmap
void stbtt_FreeBitmap(ubyte* bitmap)

Frees the allocated bitmap.

stbtt_FreeShape
void stbtt_FreeShape(const stbtt_fontinfo* info, stbtt_vertex* v)
stbtt_GetCodepointBitmap
ubyte* stbtt_GetCodepointBitmap(const stbtt_fontinfo* info, float scale_x, float scale_y, int codepoint, int* width, int* height, int* xoff, int* yoff)

Allocates a large-enough single-channel 8bpp bitmap and renders the specified character/glyph at the specified scale into it, with antialiasing. 0 is no coverage (transparent), 255 is fully covered (opaque). *width & *height are filled out with the width & height of the bitmap, which is stored left-to-right, top-to-bottom.

stbtt_GetCodepointBitmapBox
void stbtt_GetCodepointBitmapBox(const stbtt_fontinfo* font, int codepoint, float scale_x, float scale_y, int* ix0, int* iy0, int* ix1, int* iy1)

Gets the bbox of the bitmap centered around the glyph origin; so the bitmap width is ix1-ix0, height is iy1-iy0, and location to place the bitmap top left is (leftSideBearing*scale,iy0). (Note that the bitmap uses y-increases-down, but the shape uses y-increases-up, so CodepointBitmapBox and CodepointBox are inverted.)

stbtt_GetCodepointBitmapBoxSubpixel
void stbtt_GetCodepointBitmapBoxSubpixel(const stbtt_fontinfo* font, int codepoint, float scale_x, float scale_y, float shift_x, float shift_y, int* ix0, int* iy0, int* ix1, int* iy1)

Same as stbtt_GetCodepointBitmapBox, but you can specify a subpixel shift for the character.

stbtt_GetCodepointBitmapSubpixel
ubyte* stbtt_GetCodepointBitmapSubpixel(const stbtt_fontinfo* info, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint, int* width, int* height, int* xoff, int* yoff)

The same as stbtt_GetCodepoitnBitmap, but you can specify a subpixel shift for the character.

stbtt_GetCodepointBox
int stbtt_GetCodepointBox(const stbtt_fontinfo* info, int codepoint, int* x0, int* y0, int* x1, int* y1)

Gets the bounding box of the visible part of the glyph, in unscaled coordinates

stbtt_GetCodepointHMetrics
void stbtt_GetCodepointHMetrics(const stbtt_fontinfo* info, int codepoint, int* advanceWidth, int* leftSideBearing)

leftSideBearing is the offset from the current horizontal position to the left edge of the character advanceWidth is the offset from the current horizontal position to the next horizontal position these are expressed in unscaled coordinates

stbtt_GetCodepointKernAdvance
int stbtt_GetCodepointKernAdvance(const stbtt_fontinfo* info, int ch1, int ch2)

an additional amount to add to the 'advance' value between ch1 and ch2 @TODO; for now always returns 0!

stbtt_GetCodepointShape
int stbtt_GetCodepointShape(const stbtt_fontinfo* info, int unicode_codepoint, stbtt_vertex** vertices)
stbtt_GetFontBoundingBox
void stbtt_GetFontBoundingBox(const stbtt_fontinfo* info, int* x0, int* y0, int* x1, int* y1)

the bounding box around all possible characters

stbtt_GetFontOffsetForIndex
int stbtt_GetFontOffsetForIndex(const(ubyte)* font_collection, int index)

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.

stbtt_GetFontVMetrics
void stbtt_GetFontVMetrics(const stbtt_fontinfo* info, int* ascent, int* descent, int* lineGap)

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

stbtt_GetGlyphBitmapBoxSubpixel
void stbtt_GetGlyphBitmapBoxSubpixel(const stbtt_fontinfo* font, int glyph, float scale_x, float scale_y, float shift_x, float shift_y, int* ix0, int* iy0, int* ix1, int* iy1)
stbtt_GetGlyphBox
int stbtt_GetGlyphBox(const stbtt_fontinfo* info, int glyph_index, int* x0, int* y0, int* x1, int* y1)

As above, but takes one or more glyph indices for greater efficiency

stbtt_GetGlyphShape
int stbtt_GetGlyphShape(const stbtt_fontinfo* info, int glyph_index, stbtt_vertex** pvertices)
stbtt_InitFont
int stbtt_InitFont(stbtt_fontinfo* info, const(ubyte)* data2, int fontstart)

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 stbtt_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.

stbtt_IsGlyphEmpty
int stbtt_IsGlyphEmpty(const stbtt_fontinfo* info, int glyph_index)
stbtt_MakeCodepointBitmap
void stbtt_MakeCodepointBitmap(const stbtt_fontinfo* info, ubyte* output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int codepoint)

The same as stbtt_GetCodepointBitmap, but you pass in storage for the bitmap in the form of 'output', with row spacing of 'out_stride' bytes. the bitmap is clipped to out_w/out_h bytes. Call stbtt_GetCodepointBitmapBox to get the width and height and positioning info for it first.

stbtt_MakeCodepointBitmapSubpixel
void stbtt_MakeCodepointBitmapSubpixel(const stbtt_fontinfo* info, ubyte* output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint)

Same as stbtt_MakeCodepointBitmap, but you can specify a subpixel shift for the character.

stbtt_ScaleForMappingEmToPixels
float stbtt_ScaleForMappingEmToPixels(const stbtt_fontinfo* info, float pixels)

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.

stbtt_ScaleForPixelHeight
float stbtt_ScaleForPixelHeight(const stbtt_fontinfo* info, float height)

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.

Structs

stbtt_fontinfo
struct stbtt_fontinfo

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

Meta