Skip to content
Myr

stb_truetype: added STBTT_STATIC to make all implementation static

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Followed the structure used by stb_rectpack. Functions that had neither extern neither static got STBTT_DEF as well.

authored by ocornut · committed by ocornut · parent 80d5c4b · Browse files · 1 file+95 added−89 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+95 added−89 removed

  • other:+95 added−89 removed

1 file+95 added−89 removed

modified:stb_truetype.h+95 added-89 removed
374 unmodified lines
375376 typedef char stbtt__check_size32[sizeof(stbtt_int32)==4 ? 1 : -1];377 typedef char stbtt__check_size16[sizeof(stbtt_int16)==2 ? 1 : -1];378379 #ifdef STBTT_STATIC380 #define STBTT_DEF static381 #else382 #define STBTT_DEF extern383 #endif384385 // #define your own STBTT_sort() to override this to avoid qsort386 #ifndef STBTT_sort387 #include <stdlib.h>388 #define STBTT_sort(data,num_items,item_size,compare_func) qsort(data,num_items,item_size,compare_func)
61 unmodified lines
450 unsigned short x0,y0,x1,y1; // coordinates of bbox in bitmap451 float xoff,yoff,xadvance;452} stbtt_bakedchar;453448extern int stbtt_BakeFontBitmap(const unsigned char *data, int offset, // font location (use offset=0 for plain .ttf)454STBTT_DEF int stbtt_BakeFontBitmap(const unsigned char *data, int offset, // font location (use offset=0 for plain .ttf)455 float pixel_height, // height of font in pixels456 unsigned char *pixels, int pw, int ph, // bitmap to be filled in457 int first_char, int num_chars, // characters to bake458 stbtt_bakedchar *chardata); // you allocate this, it's num_chars long
7 unmodified lines
466 float x0,y0,s0,t0; // top-left467 float x1,y1,s1,t1; // bottom-right468} stbtt_aligned_quad;469464extern void stbtt_GetBakedQuad(stbtt_bakedchar *chardata, int pw, int ph, // same data as above470STBTT_DEF void stbtt_GetBakedQuad(stbtt_bakedchar *chardata, int pw, int ph, // same data as above471 int char_index, // character to display472 float *xpos, float *ypos, // pointers to current position in screen pixel space473 stbtt_aligned_quad *q, // output: quad to draw474 int opengl_fillrule); // true if opengl fill rule; false if DX9 or earlier
24 unmodified lines
499} stbtt_packedchar;500501typedef struct stbtt_pack_context stbtt_pack_context;502497extern int stbtt_PackBegin(stbtt_pack_context *spc, unsigned char *pixels, int width, int height, int stride_in_bytes, int padding, void *alloc_context);503STBTT_DEF int stbtt_PackBegin(stbtt_pack_context *spc, unsigned char *pixels, int width, int height, int stride_in_bytes, int padding, void *alloc_context);504// Initializes a packing context stored in the passed-in stbtt_pack_context.505// Future calls using this context will pack characters into the bitmap passed506// in here: a 1-channel bitmap that is weight x height. stride_in_bytes is507// the distance from one row to the next (or 0 to mean they are packed tightly
2 unmodified lines
510// bilinear filtering).511//512// Returns 0 on failure, 1 on success.513508extern void stbtt_PackEnd (stbtt_pack_context *spc);514STBTT_DEF void stbtt_PackEnd (stbtt_pack_context *spc);515// Cleans up the packing context and frees all memory.516517#define STBTT_POINT_SIZE(x) (-(x))518513extern int stbtt_PackFontRange(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, float font_size,519STBTT_DEF int stbtt_PackFontRange(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, float font_size,520 int first_unicode_char_in_range, int num_chars_in_range, stbtt_packedchar *chardata_for_range);521// Creates character bitmaps from the font_index'th font found in fontdata (use522// font_index=0 if you don't know what that is). It creates num_chars_in_range523// bitmaps for characters with unicode values starting at first_unicode_char_in_range
14 unmodified lines
538 int num_chars_in_range;539 stbtt_packedchar *chardata_for_range; // output540} stbtt_pack_range;541536extern int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges);542STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges);543// Creates character bitmaps from multiple ranges of characters stored in544// ranges. This will usually create a better-packed bitmap than multiple545// calls to stbtt_PackFontRange.546547542extern void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h_oversample, unsigned int v_oversample);548STBTT_DEF void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h_oversample, unsigned int v_oversample);549// Oversampling a font increases the quality by allowing higher-quality subpixel550// positioning, and is especially valuable at smaller text sizes.551//552// This function sets the amount of oversampling for all following calls to
3 unmodified lines
556// oversampling requires 4x the storage of 1x1. For best results, render557// oversampled textures with bilinear filtering. Look at the readme in558// stb/tests/oversample for information about oversampled fonts559554extern void stbtt_GetPackedQuad(stbtt_packedchar *chardata, int pw, int ph, // same data as above560STBTT_DEF void stbtt_GetPackedQuad(stbtt_packedchar *chardata, int pw, int ph, // same data as above561 int char_index, // character to display562 float *xpos, float *ypos, // pointers to current position in screen pixel space563 stbtt_aligned_quad *q, // output: quad to draw564 int align_to_integer);
17 unmodified lines
582// FONT LOADING583//584//585580extern int stbtt_GetFontOffsetForIndex(const unsigned char *data, int index);586STBTT_DEF int stbtt_GetFontOffsetForIndex(const unsigned char *data, int index);587// Each .ttf/.ttc file may have more than one font. Each font has a sequential588// index number starting from 0. Call this function to get the font offset for589// a given index; it returns -1 if the index is out of range. A regular .ttf590// file will only define one font and it always be at offset 0, so it will
15 unmodified lines
606 int index_map; // a cmap mapping for our chosen character encoding607 int indexToLocFormat; // format needed to map from glyph index to glyph608} stbtt_fontinfo;609604extern int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data, int offset);610STBTT_DEF int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data, int offset);611// Given an offset into the file that defines a font, this function builds612// the necessary cached info for the rest of the system. You must allocate613// the stbtt_fontinfo yourself, and stbtt_InitFont will fill it out. You don't614// need to do anything special to free it, because the contents are pure
3 unmodified lines
618//////////////////////////////////////////////////////////////////////////////619//620// CHARACTER TO GLYPH-INDEX CONVERSIOn621616int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codepoint);622STBTT_DEF int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codepoint);623// If you're going to perform multiple operations on the same character624// and you want a speed-up, call this function with the character you're625// going to process, then use glyph-based functions instead of the626// codepoint-based functions.
3 unmodified lines
630//631// CHARACTER PROPERTIES632//633628extern float stbtt_ScaleForPixelHeight(const stbtt_fontinfo *info, float pixels);634STBTT_DEF float stbtt_ScaleForPixelHeight(const stbtt_fontinfo *info, float pixels);635// computes a scale factor to produce a font whose "height" is 'pixels' tall.636// Height is measured as the distance from the highest ascender to the lowest637// descender; in other words, it's equivalent to calling stbtt_GetFontVMetrics638// and computing:639// scale = pixels / (ascent - descent)640// so if you prefer to measure height by the ascent only, use a similar calculation.641636extern float stbtt_ScaleForMappingEmToPixels(const stbtt_fontinfo *info, float pixels);642STBTT_DEF float stbtt_ScaleForMappingEmToPixels(const stbtt_fontinfo *info, float pixels);643// computes a scale factor to produce a font whose EM size is mapped to644// 'pixels' tall. This is probably what traditional APIs compute, but645// I'm not positive.646641extern void stbtt_GetFontVMetrics(const stbtt_fontinfo *info, int *ascent, int *descent, int *lineGap);647STBTT_DEF void stbtt_GetFontVMetrics(const stbtt_fontinfo *info, int *ascent, int *descent, int *lineGap);648// ascent is the coordinate above the baseline the font extends; descent649// is the coordinate below the baseline the font extends (i.e. it is typically negative)650// lineGap is the spacing between one row's descent and the next row's ascent...651// so you should advance the vertical position by "*ascent - *descent + *lineGap"652// these are expressed in unscaled coordinates, so you must multiply by653// the scale factor for a given size654649extern void stbtt_GetFontBoundingBox(const stbtt_fontinfo *info, int *x0, int *y0, int *x1, int *y1);655STBTT_DEF void stbtt_GetFontBoundingBox(const stbtt_fontinfo *info, int *x0, int *y0, int *x1, int *y1);656// the bounding box around all possible characters657652extern void stbtt_GetCodepointHMetrics(const stbtt_fontinfo *info, int codepoint, int *advanceWidth, int *leftSideBearing);658STBTT_DEF void stbtt_GetCodepointHMetrics(const stbtt_fontinfo *info, int codepoint, int *advanceWidth, int *leftSideBearing);659// leftSideBearing is the offset from the current horizontal position to the left edge of the character660// advanceWidth is the offset from the current horizontal position to the next horizontal position661// these are expressed in unscaled coordinates662657extern int stbtt_GetCodepointKernAdvance(const stbtt_fontinfo *info, int ch1, int ch2);663STBTT_DEF int stbtt_GetCodepointKernAdvance(const stbtt_fontinfo *info, int ch1, int ch2);664// an additional amount to add to the 'advance' value between ch1 and ch2665660extern int stbtt_GetCodepointBox(const stbtt_fontinfo *info, int codepoint, int *x0, int *y0, int *x1, int *y1);666STBTT_DEF int stbtt_GetCodepointBox(const stbtt_fontinfo *info, int codepoint, int *x0, int *y0, int *x1, int *y1);667// Gets the bounding box of the visible part of the glyph, in unscaled coordinates668663extern void stbtt_GetGlyphHMetrics(const stbtt_fontinfo *info, int glyph_index, int *advanceWidth, int *leftSideBearing);664extern int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2);665extern int stbtt_GetGlyphBox(const stbtt_fontinfo *info, int glyph_index, int *x0, int *y0, int *x1, int *y1);669STBTT_DEF void stbtt_GetGlyphHMetrics(const stbtt_fontinfo *info, int glyph_index, int *advanceWidth, int *leftSideBearing);670STBTT_DEF int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2);671STBTT_DEF int stbtt_GetGlyphBox(const stbtt_fontinfo *info, int glyph_index, int *x0, int *y0, int *x1, int *y1);672// as above, but takes one or more glyph indices for greater efficiency673674675//////////////////////////////////////////////////////////////////////////////
19 unmodified lines
695 unsigned char type,padding;696 } stbtt_vertex;697#endif698693extern int stbtt_IsGlyphEmpty(const stbtt_fontinfo *info, int glyph_index);699STBTT_DEF int stbtt_IsGlyphEmpty(const stbtt_fontinfo *info, int glyph_index);700// returns non-zero if nothing is drawn for this glyph701696extern int stbtt_GetCodepointShape(const stbtt_fontinfo *info, int unicode_codepoint, stbtt_vertex **vertices);697extern int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, stbtt_vertex **vertices);702STBTT_DEF int stbtt_GetCodepointShape(const stbtt_fontinfo *info, int unicode_codepoint, stbtt_vertex **vertices);703STBTT_DEF int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, stbtt_vertex **vertices);704// returns # of vertices and fills *vertices with the pointer to them705// these are expressed in "unscaled" coordinates706//707// The shape is a series of countours. Each one starts with
2 unmodified lines
710// draws a line from previous endpoint to its x,y; a curveto711// draws a quadratic bezier from previous endpoint to712// its x,y, using cx,cy as the bezier control point.713708extern void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *vertices);714STBTT_DEF void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *vertices);715// frees the data allocated above716717//////////////////////////////////////////////////////////////////////////////718//719// BITMAP RENDERING720//721716extern void stbtt_FreeBitmap(unsigned char *bitmap, void *userdata);722STBTT_DEF void stbtt_FreeBitmap(unsigned char *bitmap, void *userdata);723// frees the bitmap allocated below724719extern unsigned char *stbtt_GetCodepointBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int codepoint, int *width, int *height, int *xoff, int *yoff);725STBTT_DEF unsigned char *stbtt_GetCodepointBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int codepoint, int *width, int *height, int *xoff, int *yoff);726// allocates a large-enough single-channel 8bpp bitmap and renders the727// specified character/glyph at the specified scale into it, with728// antialiasing. 0 is no coverage (transparent), 255 is fully covered (opaque).729// *width & *height are filled out with the width & height of the bitmap,730// which is stored left-to-right, top-to-bottom.731//732// xoff/yoff are the offset it pixel space from the glyph origin to the top-left of the bitmap733728extern unsigned char *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);734STBTT_DEF unsigned char *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);735// the same as stbtt_GetCodepoitnBitmap, but you can specify a subpixel736// shift for the character737732extern void stbtt_MakeCodepointBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int codepoint);738STBTT_DEF void stbtt_MakeCodepointBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int codepoint);739// the same as stbtt_GetCodepointBitmap, but you pass in storage for the bitmap740// in the form of 'output', with row spacing of 'out_stride' bytes. the bitmap741// is clipped to out_w/out_h bytes. Call stbtt_GetCodepointBitmapBox to get the742// width and height and positioning info for it first.743738extern void stbtt_MakeCodepointBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint);744STBTT_DEF void stbtt_MakeCodepointBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint);745// same as stbtt_MakeCodepointBitmap, but you can specify a subpixel746// shift for the character747742extern void stbtt_GetCodepointBitmapBox(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1);748STBTT_DEF void stbtt_GetCodepointBitmapBox(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1);749// get the bbox of the bitmap centered around the glyph origin; so the750// bitmap width is ix1-ix0, height is iy1-iy0, and location to place751// the bitmap top left is (leftSideBearing*scale,iy0).752// (Note that the bitmap uses y-increases-down, but the shape uses753// y-increases-up, so CodepointBitmapBox and CodepointBox are inverted.)754749extern 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);755STBTT_DEF 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);756// same as stbtt_GetCodepointBitmapBox, but you can specify a subpixel757// shift for the character758759// the following functions are equivalent to the above functions, but operate760// on glyph indices instead of Unicode codepoints (for efficiency)755extern unsigned char *stbtt_GetGlyphBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int glyph, int *width, int *height, int *xoff, int *yoff);756extern unsigned char *stbtt_GetGlyphBitmapSubpixel(const stbtt_fontinfo *info, float scale_x, float scale_y, float shift_x, float shift_y, int glyph, int *width, int *height, int *xoff, int *yoff);757extern void stbtt_MakeGlyphBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int glyph);758extern void stbtt_MakeGlyphBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int glyph);759extern void stbtt_GetGlyphBitmapBox(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1);760extern 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);761STBTT_DEF unsigned char *stbtt_GetGlyphBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int glyph, int *width, int *height, int *xoff, int *yoff);762STBTT_DEF unsigned char *stbtt_GetGlyphBitmapSubpixel(const stbtt_fontinfo *info, float scale_x, float scale_y, float shift_x, float shift_y, int glyph, int *width, int *height, int *xoff, int *yoff);763STBTT_DEF void stbtt_MakeGlyphBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int glyph);764STBTT_DEF void stbtt_MakeGlyphBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int glyph);765STBTT_DEF void stbtt_GetGlyphBitmapBox(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1);766STBTT_DEF 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);767768769// @TODO: don't expose this structure770typedef struct
1 unmodified line
772 int w,h,stride;773 unsigned char *pixels;774} stbtt__bitmap;775770extern void stbtt_Rasterize(stbtt__bitmap *result, float flatness_in_pixels, stbtt_vertex *vertices, int num_verts, float scale_x, float scale_y, float shift_x, float shift_y, int x_off, int y_off, int invert, void *userdata);776STBTT_DEF void stbtt_Rasterize(stbtt__bitmap *result, float flatness_in_pixels, stbtt_vertex *vertices, int num_verts, float scale_x, float scale_y, float shift_x, float shift_y, int x_off, int y_off, int invert, void *userdata);777778//////////////////////////////////////////////////////////////////////////////779//780// Finding the right font...
15 unmodified lines
796// from the file yourself and do your own comparisons on them.797// You have to have called stbtt_InitFont() first.798799794extern int stbtt_FindMatchingFont(const unsigned char *fontdata, const char *name, int flags);800STBTT_DEF int stbtt_FindMatchingFont(const unsigned char *fontdata, const char *name, int flags);801// returns the offset (not index) of the font that matches, or -1 if none802// if you use STBTT_MACSTYLE_DONTCARE, use a font name like "Arial Bold".803// if you use any other flag, use a font name like "Arial"; this checks804// the 'macStyle' header field; i don't know if fonts set this consistently
2 unmodified lines
807#define STBTT_MACSTYLE_ITALIC 2808#define STBTT_MACSTYLE_UNDERSCORE 4809#define STBTT_MACSTYLE_NONE 8 // <= not same as 0, this makes us check the bitfield is 0810805extern int stbtt_CompareUTF8toUTF16_bigendian(const char *s1, int len1, const char *s2, int len2);811STBTT_DEF int stbtt_CompareUTF8toUTF16_bigendian(const char *s1, int len1, const char *s2, int len2);812// returns 1/0 whether the first string interpreted as utf8 is identical to813// the second string interpreted as big-endian utf16... useful for strings from next func814809extern const char *stbtt_GetFontNameString(const stbtt_fontinfo *font, int *length, int platformID, int encodingID, int languageID, int nameID);815STBTT_DEF const char *stbtt_GetFontNameString(const stbtt_fontinfo *font, int *length, int platformID, int encodingID, int languageID, int nameID);816// returns the string (which may be big-endian double byte, e.g. for unicode)817// and puts the length in bytes in *length.818//819// some of the values for the IDs are below; for more see the truetype spec:
90 unmodified lines
910 #define ttLONG(p) (* (stbtt_int32 *) (p))911912#else913908 stbtt_uint16 ttUSHORT(const stbtt_uint8 *p) { return p[0]*256 + p[1]; }909 stbtt_int16 ttSHORT(const stbtt_uint8 *p) { return p[0]*256 + p[1]; }910 stbtt_uint32 ttULONG(const stbtt_uint8 *p) { return (p[0]<<24) + (p[1]<<16) + (p[2]<<8) + p[3]; }911 stbtt_int32 ttLONG(const stbtt_uint8 *p) { return (p[0]<<24) + (p[1]<<16) + (p[2]<<8) + p[3]; }914 static stbtt_uint16 ttUSHORT(const stbtt_uint8 *p) { return p[0]*256 + p[1]; }915 static stbtt_int16 ttSHORT(const stbtt_uint8 *p) { return p[0]*256 + p[1]; }916 static stbtt_uint32 ttULONG(const stbtt_uint8 *p) { return (p[0]<<24) + (p[1]<<16) + (p[2]<<8) + p[3]; }917 static stbtt_int32 ttLONG(const stbtt_uint8 *p) { return (p[0]<<24) + (p[1]<<16) + (p[2]<<8) + p[3]; }918919#endif920921#define stbtt_tag4(p,c0,c1,c2,c3) ((p)[0] == (c0) && (p)[1] == (c1) && (p)[2] == (c2) && (p)[3] == (c3))
22 unmodified lines
944 }945 return 0;946}947942int stbtt_GetFontOffsetForIndex(const unsigned char *font_collection, int index)948STBTT_DEF int stbtt_GetFontOffsetForIndex(const unsigned char *font_collection, int index)949{950 // if it's just a font, there's only one valid index951 if (stbtt__isfont(font_collection))952 return index == 0 ? 0 : -1;
10 unmodified lines
963 }964 return -1;965}966961int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data2, int fontstart)967STBTT_DEF int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data2, int fontstart)968{969 stbtt_uint8 *data = (stbtt_uint8 *) data2;970 stbtt_uint32 cmap, t;971 stbtt_int32 i,numTables;
48 unmodified lines
1020 info->indexToLocFormat = ttUSHORT(data+info->head + 50);1021 return 1;1022}10231018int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codepoint)1024STBTT_DEF int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codepoint)1025{1026 stbtt_uint8 *data = info->data;1027 stbtt_uint32 index_map = info->index_map;1028
83 unmodified lines
1112 STBTT_assert(0);1113 return 0;1114}11151110int stbtt_GetCodepointShape(const stbtt_fontinfo *info, int unicode_codepoint, stbtt_vertex **vertices)1116STBTT_DEF int stbtt_GetCodepointShape(const stbtt_fontinfo *info, int unicode_codepoint, stbtt_vertex **vertices)1117{1118 return stbtt_GetGlyphShape(info, stbtt_FindGlyphIndex(info, unicode_codepoint), vertices);1119}1120
23 unmodified lines
11441145 return g1==g2 ? -1 : g1; // if length is 0, return -11146}11471142int stbtt_GetGlyphBox(const stbtt_fontinfo *info, int glyph_index, int *x0, int *y0, int *x1, int *y1)1148STBTT_DEF int stbtt_GetGlyphBox(const stbtt_fontinfo *info, int glyph_index, int *x0, int *y0, int *x1, int *y1)1149{1150 int g = stbtt__GetGlyfOffset(info, glyph_index);1151 if (g < 0) return 0;1152
3 unmodified lines
1156 if (y1) *y1 = ttSHORT(info->data + g + 8);1157 return 1;1158}11591154int stbtt_GetCodepointBox(const stbtt_fontinfo *info, int codepoint, int *x0, int *y0, int *x1, int *y1)1160STBTT_DEF int stbtt_GetCodepointBox(const stbtt_fontinfo *info, int codepoint, int *x0, int *y0, int *x1, int *y1)1161{1162 return stbtt_GetGlyphBox(info, stbtt_FindGlyphIndex(info,codepoint), x0,y0,x1,y1);1163}11641159int stbtt_IsGlyphEmpty(const stbtt_fontinfo *info, int glyph_index)1165STBTT_DEF int stbtt_IsGlyphEmpty(const stbtt_fontinfo *info, int glyph_index)1166{1167 stbtt_int16 numberOfContours;1168 int g = stbtt__GetGlyfOffset(info, glyph_index);1169 if (g < 0) return 1;
16 unmodified lines
1186 }1187 return num_vertices;1188}11891184int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, stbtt_vertex **pvertices)1190STBTT_DEF int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, stbtt_vertex **pvertices)1191{1192 stbtt_int16 numberOfContours;1193 stbtt_uint8 *endPtsOfContours;1194 stbtt_uint8 *data = info->data;
217 unmodified lines
1412 *pvertices = vertices;1413 return num_vertices;1414}14151410void stbtt_GetGlyphHMetrics(const stbtt_fontinfo *info, int glyph_index, int *advanceWidth, int *leftSideBearing)1416STBTT_DEF void stbtt_GetGlyphHMetrics(const stbtt_fontinfo *info, int glyph_index, int *advanceWidth, int *leftSideBearing)1417{1418 stbtt_uint16 numOfLongHorMetrics = ttUSHORT(info->data+info->hhea + 34);1419 if (glyph_index < numOfLongHorMetrics) {1420 if (advanceWidth) *advanceWidth = ttSHORT(info->data + info->hmtx + 4*glyph_index);
3 unmodified lines
1424 if (leftSideBearing) *leftSideBearing = ttSHORT(info->data + info->hmtx + 4*numOfLongHorMetrics + 2*(glyph_index - numOfLongHorMetrics));1425 }1426}14271422int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2)1428STBTT_DEF int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2)1429{1430 stbtt_uint8 *data = info->data + info->kern;1431 stbtt_uint32 needle, straw;1432 int l, r, m;
21 unmodified lines
1454 }1455 return 0;1456}14571452int stbtt_GetCodepointKernAdvance(const stbtt_fontinfo *info, int ch1, int ch2)1458STBTT_DEF int stbtt_GetCodepointKernAdvance(const stbtt_fontinfo *info, int ch1, int ch2)1459{1460 if (!info->kern) // if no kerning table, don't waste time looking up both codepoint->glyphs1461 return 0;1462 return stbtt_GetGlyphKernAdvance(info, stbtt_FindGlyphIndex(info,ch1), stbtt_FindGlyphIndex(info,ch2));1463}14641459void stbtt_GetCodepointHMetrics(const stbtt_fontinfo *info, int codepoint, int *advanceWidth, int *leftSideBearing)1465STBTT_DEF void stbtt_GetCodepointHMetrics(const stbtt_fontinfo *info, int codepoint, int *advanceWidth, int *leftSideBearing)1466{1467 stbtt_GetGlyphHMetrics(info, stbtt_FindGlyphIndex(info,codepoint), advanceWidth, leftSideBearing);1468}14691464void stbtt_GetFontVMetrics(const stbtt_fontinfo *info, int *ascent, int *descent, int *lineGap)1470STBTT_DEF void stbtt_GetFontVMetrics(const stbtt_fontinfo *info, int *ascent, int *descent, int *lineGap)1471{1472 if (ascent ) *ascent = ttSHORT(info->data+info->hhea + 4);1473 if (descent) *descent = ttSHORT(info->data+info->hhea + 6);1474 if (lineGap) *lineGap = ttSHORT(info->data+info->hhea + 8);1475}14761471void stbtt_GetFontBoundingBox(const stbtt_fontinfo *info, int *x0, int *y0, int *x1, int *y1)1477STBTT_DEF void stbtt_GetFontBoundingBox(const stbtt_fontinfo *info, int *x0, int *y0, int *x1, int *y1)1478{1479 *x0 = ttSHORT(info->data + info->head + 36);1480 *y0 = ttSHORT(info->data + info->head + 38);1481 *x1 = ttSHORT(info->data + info->head + 40);1482 *y1 = ttSHORT(info->data + info->head + 42);1483}14841479float stbtt_ScaleForPixelHeight(const stbtt_fontinfo *info, float height)1485STBTT_DEF float stbtt_ScaleForPixelHeight(const stbtt_fontinfo *info, float height)1486{1487 int fheight = ttSHORT(info->data + info->hhea + 4) - ttSHORT(info->data + info->hhea + 6);1488 return (float) height / fheight;1489}14901485float stbtt_ScaleForMappingEmToPixels(const stbtt_fontinfo *info, float pixels)1491STBTT_DEF float stbtt_ScaleForMappingEmToPixels(const stbtt_fontinfo *info, float pixels)1492{1493 int unitsPerEm = ttUSHORT(info->data + info->head + 18);1494 return pixels / unitsPerEm;1495}14961491void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *v)1497STBTT_DEF void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *v)1498{1499 STBTT_free(v, info->userdata);1500}1501
1 unmodified line
1503//1504// antialiasing software rasterizer1505//15061501void 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)1507STBTT_DEF 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)1508{1509 int x0,y0,x1,y1;1510 if (!stbtt_GetGlyphBox(font, glyph, &x0,&y0,&x1,&y1)) {1511 // e.g. space character
9 unmodified lines
1521 if (iy1) *iy1 = STBTT_iceil (-y0 * scale_y + shift_y);1522 }1523}15241519void stbtt_GetGlyphBitmapBox(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1)1525STBTT_DEF void stbtt_GetGlyphBitmapBox(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1)1526{1527 stbtt_GetGlyphBitmapBoxSubpixel(font, glyph, scale_x, scale_y,0.0f,0.0f, ix0, iy0, ix1, iy1);1528}15291524void 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)1530STBTT_DEF 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)1531{1532 stbtt_GetGlyphBitmapBoxSubpixel(font, stbtt_FindGlyphIndex(font,codepoint), scale_x, scale_y,shift_x,shift_y, ix0,iy0,ix1,iy1);1533}15341529void stbtt_GetCodepointBitmapBox(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1)1535STBTT_DEF void stbtt_GetCodepointBitmapBox(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1)1536{1537 stbtt_GetCodepointBitmapBoxSubpixel(font, codepoint, scale_x, scale_y,0.0f,0.0f, ix0,iy0,ix1,iy1);1538}1539
272 unmodified lines
1812 return 1;1813}18141815// returns number of contours1810stbtt__point *stbtt_FlattenCurves(stbtt_vertex *vertices, int num_verts, float objspace_flatness, int **contour_lengths, int *num_contours, void *userdata)1816static stbtt__point *stbtt_FlattenCurves(stbtt_vertex *vertices, int num_verts, float objspace_flatness, int **contour_lengths, int *num_contours, void *userdata)1817{1818 stbtt__point *points=0;1819 int num_points=0;1820
60 unmodified lines
1881 *num_contours = 0;1882 return NULL;1883}18841879void stbtt_Rasterize(stbtt__bitmap *result, float flatness_in_pixels, stbtt_vertex *vertices, int num_verts, float scale_x, float scale_y, float shift_x, float shift_y, int x_off, int y_off, int invert, void *userdata)1885STBTT_DEF void stbtt_Rasterize(stbtt__bitmap *result, float flatness_in_pixels, stbtt_vertex *vertices, int num_verts, float scale_x, float scale_y, float shift_x, float shift_y, int x_off, int y_off, int invert, void *userdata)1886{1887 float scale = scale_x > scale_y ? scale_y : scale_x;1888 int winding_count, *winding_lengths;1889 stbtt__point *windings = stbtt_FlattenCurves(vertices, num_verts, flatness_in_pixels / scale, &winding_lengths, &winding_count, userdata);
3 unmodified lines
1893 STBTT_free(windings, userdata);1894 }1895}18961891void stbtt_FreeBitmap(unsigned char *bitmap, void *userdata)1897STBTT_DEF void stbtt_FreeBitmap(unsigned char *bitmap, void *userdata)1898{1899 STBTT_free(bitmap, userdata);1900}19011896unsigned char *stbtt_GetGlyphBitmapSubpixel(const stbtt_fontinfo *info, float scale_x, float scale_y, float shift_x, float shift_y, int glyph, int *width, int *height, int *xoff, int *yoff)1902STBTT_DEF unsigned char *stbtt_GetGlyphBitmapSubpixel(const stbtt_fontinfo *info, float scale_x, float scale_y, float shift_x, float shift_y, int glyph, int *width, int *height, int *xoff, int *yoff)1903{1904 int ix0,iy0,ix1,iy1;1905 stbtt__bitmap gbm;1906 stbtt_vertex *vertices;
28 unmodified lines
1935 STBTT_free(vertices, info->userdata);1936 return gbm.pixels;1937} 19381933unsigned char *stbtt_GetGlyphBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int glyph, int *width, int *height, int *xoff, int *yoff)1939STBTT_DEF unsigned char *stbtt_GetGlyphBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int glyph, int *width, int *height, int *xoff, int *yoff)1940{1941 return stbtt_GetGlyphBitmapSubpixel(info, scale_x, scale_y, 0.0f, 0.0f, glyph, width, height, xoff, yoff);1942}19431938void stbtt_MakeGlyphBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int glyph)1944STBTT_DEF void stbtt_MakeGlyphBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int glyph)1945{1946 int ix0,iy0;1947 stbtt_vertex *vertices;1948 int num_verts = stbtt_GetGlyphShape(info, glyph, &vertices);
10 unmodified lines
19591960 STBTT_free(vertices, info->userdata);1961}19621957void stbtt_MakeGlyphBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int glyph)1963STBTT_DEF void stbtt_MakeGlyphBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int glyph)1964{1965 stbtt_MakeGlyphBitmapSubpixel(info, output, out_w, out_h, out_stride, scale_x, scale_y, 0.0f,0.0f, glyph);1966}19671962unsigned char *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)1968STBTT_DEF unsigned char *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)1969{1970 return stbtt_GetGlyphBitmapSubpixel(info, scale_x, scale_y,shift_x,shift_y, stbtt_FindGlyphIndex(info,codepoint), width,height,xoff,yoff);1971} 19721967void stbtt_MakeCodepointBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint)1973STBTT_DEF void stbtt_MakeCodepointBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint)1974{1975 stbtt_MakeGlyphBitmapSubpixel(info, output, out_w, out_h, out_stride, scale_x, scale_y, shift_x, shift_y, stbtt_FindGlyphIndex(info,codepoint));1976}19771972unsigned char *stbtt_GetCodepointBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int codepoint, int *width, int *height, int *xoff, int *yoff)1978STBTT_DEF unsigned char *stbtt_GetCodepointBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int codepoint, int *width, int *height, int *xoff, int *yoff)1979{1980 return stbtt_GetCodepointBitmapSubpixel(info, scale_x, scale_y, 0.0f,0.0f, codepoint, width,height,xoff,yoff);1981} 19821977void stbtt_MakeCodepointBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int codepoint)1983STBTT_DEF void stbtt_MakeCodepointBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int codepoint)1984{1985 stbtt_MakeCodepointBitmapSubpixel(info, output, out_w, out_h, out_stride, scale_x, scale_y, 0.0f,0.0f, codepoint);1986}1987
2 unmodified lines
1990// bitmap baking1991//1992// This is SUPER-CRAPPY packing to keep source code small19931988extern int stbtt_BakeFontBitmap(const unsigned char *data, int offset, // font location (use offset=0 for plain .ttf)1994STBTT_DEF int stbtt_BakeFontBitmap(const unsigned char *data, int offset, // font location (use offset=0 for plain .ttf)1995 float pixel_height, // height of font in pixels1996 unsigned char *pixels, int pw, int ph, // bitmap to be filled in1997 int first_char, int num_chars, // characters to bake1998 stbtt_bakedchar *chardata)
36 unmodified lines
2035 }2036 return bottom_y;2037}20382033void stbtt_GetBakedQuad(stbtt_bakedchar *chardata, int pw, int ph, int char_index, float *xpos, float *ypos, stbtt_aligned_quad *q, int opengl_fillrule)2039STBTT_DEF void stbtt_GetBakedQuad(stbtt_bakedchar *chardata, int pw, int ph, int char_index, float *xpos, float *ypos, stbtt_aligned_quad *q, int opengl_fillrule)2040{2041 float d3d_bias = opengl_fillrule ? 0 : -0.5f;2042 float ipw = 1.0f / pw, iph = 1.0f / ph;2043 stbtt_bakedchar *b = chardata + char_index;
94 unmodified lines
2138//2139// This is SUPER-AWESOME (tm Ryan Gordon) packing using stb_rect_pack.h. If2140// stb_rect_pack.h isn't available, it uses the BakeFontBitmap strategy.21412136int stbtt_PackBegin(stbtt_pack_context *spc, unsigned char *pixels, int pw, int ph, int stride_in_bytes, int padding, void *alloc_context)2142STBTT_DEF int stbtt_PackBegin(stbtt_pack_context *spc, unsigned char *pixels, int pw, int ph, int stride_in_bytes, int padding, void *alloc_context)2143{2144 stbrp_context *context = (stbrp_context *) STBTT_malloc(sizeof(*context) ,alloc_context);2145 int num_nodes = pw - padding;2146 stbrp_node *nodes = (stbrp_node *) STBTT_malloc(sizeof(*nodes ) * num_nodes,alloc_context);
21 unmodified lines
21682169 return 1;2170}21712166void stbtt_PackEnd (stbtt_pack_context *spc)2172STBTT_DEF void stbtt_PackEnd (stbtt_pack_context *spc)2173{2174 STBTT_free(spc->nodes , spc->user_allocator_context);2175 STBTT_free(spc->pack_info, spc->user_allocator_context);2176}21772172void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h_oversample, unsigned int v_oversample)2178STBTT_DEF void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h_oversample, unsigned int v_oversample)2179{2180 STBTT_assert(h_oversample <= STBTT_MAX_OVERSAMPLE);2181 STBTT_assert(v_oversample <= STBTT_MAX_OVERSAMPLE);2182 if (h_oversample <= STBTT_MAX_OVERSAMPLE)
123 unmodified lines
2306 // direction to counter this.2307 return (float)-(oversample - 1) / (2.0f * (float)oversample);2308}23092304int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges)2310STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges)2311{2312 stbtt_fontinfo info;2313 float recip_h = 1.0f / spc->h_oversample;2314 float recip_v = 1.0f / spc->v_oversample;
100 unmodified lines
24152416 return return_value;2417}24182413int stbtt_PackFontRange(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, float font_size,2419STBTT_DEF int stbtt_PackFontRange(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, float font_size,2420 int first_unicode_char_in_range, int num_chars_in_range, stbtt_packedchar *chardata_for_range)2421{2422 stbtt_pack_range range;2423 range.first_unicode_char_in_range = first_unicode_char_in_range;
2 unmodified lines
2426 range.font_size = font_size;2427 return stbtt_PackFontRanges(spc, fontdata, font_index, &range, 1);2428}24292424void stbtt_GetPackedQuad(stbtt_packedchar *chardata, int pw, int ph, int char_index, float *xpos, float *ypos, stbtt_aligned_quad *q, int align_to_integer)2430STBTT_DEF void stbtt_GetPackedQuad(stbtt_packedchar *chardata, int pw, int ph, int char_index, float *xpos, float *ypos, stbtt_aligned_quad *q, int align_to_integer)2431{2432 float ipw = 1.0f / pw, iph = 1.0f / ph;2433 stbtt_packedchar *b = chardata + char_index;2434
64 unmodified lines
2499 }2500 return i;2501}25022497int stbtt_CompareUTF8toUTF16_bigendian(const char *s1, int len1, const char *s2, int len2) 2503STBTT_DEF int stbtt_CompareUTF8toUTF16_bigendian(const char *s1, int len1, const char *s2, int len2) 2504{2505 return len1 == stbtt__CompareUTF8toUTF16_bigendian_prefix((const stbtt_uint8*) s1, len1, (const stbtt_uint8*) s2, len2);2506}25072508// returns results in whatever encoding you request... but note that 2-byte encodings2509// will be BIG-ENDIAN... use stbtt_CompareUTF8toUTF16_bigendian() to compare2504const char *stbtt_GetFontNameString(const stbtt_fontinfo *font, int *length, int platformID, int encodingID, int languageID, int nameID)2510STBTT_DEF const char *stbtt_GetFontNameString(const stbtt_fontinfo *font, int *length, int platformID, int encodingID, int languageID, int nameID)2511{2512 stbtt_int32 i,count,stringOffset;2513 stbtt_uint8 *fc = font->data;2514 stbtt_uint32 offset = font->fontstart;
88 unmodified lines
26032604 return 0;2605}26062601int stbtt_FindMatchingFont(const unsigned char *font_collection, const char *name_utf8, stbtt_int32 flags)2607STBTT_DEF int stbtt_FindMatchingFont(const unsigned char *font_collection, const char *name_utf8, stbtt_int32 flags)2608{2609 stbtt_int32 i;2610 for (i=0;;++i) {2611 stbtt_int32 off = stbtt_GetFontOffsetForIndex(font_collection, i);
7 unmodified lines