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
Provenance
- Commit
45fec17- Tree
7cdff13- Author
ocornut <omarcornut@gmail.com>- Committer
ocornut <omarcornut@gmail.com>- Parent
80d5c4b
1 file changed+95 added−89 removed
modified:stb_truetype.h+95 added-89 removed
374 unmodified lines375 376 typedef char stbtt__check_size32[sizeof(stbtt_int32)==4 ? 1 : -1];377 typedef char stbtt__check_size16[sizeof(stbtt_int16)==2 ? 1 : -1];378 379+ #ifdef STBTT_STATIC380+ #define STBTT_DEF static381+ #else382+ #define STBTT_DEF extern383+ #endif384+385 // #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 lines450 unsigned short x0,y0,x1,y1; // coordinates of bbox in bitmap451 float xoff,yoff,xadvance;452 } stbtt_bakedchar;453 448-extern int stbtt_BakeFontBitmap(const unsigned char *data, int offset, // font location (use offset=0 for plain .ttf)454+STBTT_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 long7 unmodified lines466 float x0,y0,s0,t0; // top-left467 float x1,y1,s1,t1; // bottom-right468 } stbtt_aligned_quad;469 464-extern void stbtt_GetBakedQuad(stbtt_bakedchar *chardata, int pw, int ph, // same data as above470+STBTT_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 earlier24 unmodified lines499 } stbtt_packedchar;500 501 typedef struct stbtt_pack_context stbtt_pack_context;502 497-extern int stbtt_PackBegin(stbtt_pack_context *spc, unsigned char *pixels, int width, int height, int stride_in_bytes, int padding, void *alloc_context);503+STBTT_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 tightly2 unmodified lines510 // bilinear filtering).511 //512 // Returns 0 on failure, 1 on success.513 508-extern void stbtt_PackEnd (stbtt_pack_context *spc);514+STBTT_DEF void stbtt_PackEnd (stbtt_pack_context *spc);515 // Cleans up the packing context and frees all memory.516 517 #define STBTT_POINT_SIZE(x) (-(x))518 513-extern int stbtt_PackFontRange(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, float font_size,519+STBTT_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_range14 unmodified lines538 int num_chars_in_range;539 stbtt_packedchar *chardata_for_range; // output540 } stbtt_pack_range;541 536-extern int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges);542+STBTT_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.546 547 542-extern void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h_oversample, unsigned int v_oversample);548+STBTT_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 to3 unmodified lines556 // 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 fonts559 554-extern void stbtt_GetPackedQuad(stbtt_packedchar *chardata, int pw, int ph, // same data as above560+STBTT_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 lines582 // FONT LOADING583 //584 //585 580-extern int stbtt_GetFontOffsetForIndex(const unsigned char *data, int index);586+STBTT_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 will15 unmodified lines606 int index_map; // a cmap mapping for our chosen character encoding607 int indexToLocFormat; // format needed to map from glyph index to glyph608 } stbtt_fontinfo;609 604-extern int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data, int offset);610+STBTT_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 pure3 unmodified lines618 //////////////////////////////////////////////////////////////////////////////619 //620 // CHARACTER TO GLYPH-INDEX CONVERSIOn621 616-int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codepoint);622+STBTT_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 lines630 //631 // CHARACTER PROPERTIES632 //633 628-extern float stbtt_ScaleForPixelHeight(const stbtt_fontinfo *info, float pixels);634+STBTT_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.641 636-extern float stbtt_ScaleForMappingEmToPixels(const stbtt_fontinfo *info, float pixels);642+STBTT_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.646 641-extern void stbtt_GetFontVMetrics(const stbtt_fontinfo *info, int *ascent, int *descent, int *lineGap);647+STBTT_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 size654 649-extern void stbtt_GetFontBoundingBox(const stbtt_fontinfo *info, int *x0, int *y0, int *x1, int *y1);655+STBTT_DEF void stbtt_GetFontBoundingBox(const stbtt_fontinfo *info, int *x0, int *y0, int *x1, int *y1);656 // the bounding box around all possible characters657 652-extern void stbtt_GetCodepointHMetrics(const stbtt_fontinfo *info, int codepoint, int *advanceWidth, int *leftSideBearing);658+STBTT_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 coordinates662 657-extern int stbtt_GetCodepointKernAdvance(const stbtt_fontinfo *info, int ch1, int ch2);663+STBTT_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 ch2665 660-extern int stbtt_GetCodepointBox(const stbtt_fontinfo *info, int codepoint, int *x0, int *y0, int *x1, int *y1);666+STBTT_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 coordinates668 663-extern void stbtt_GetGlyphHMetrics(const stbtt_fontinfo *info, int glyph_index, int *advanceWidth, int *leftSideBearing);664-extern int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2);665-extern int stbtt_GetGlyphBox(const stbtt_fontinfo *info, int glyph_index, int *x0, int *y0, int *x1, int *y1);669+STBTT_DEF void stbtt_GetGlyphHMetrics(const stbtt_fontinfo *info, int glyph_index, int *advanceWidth, int *leftSideBearing);670+STBTT_DEF int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2);671+STBTT_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 efficiency673 674 675 //////////////////////////////////////////////////////////////////////////////19 unmodified lines695 unsigned char type,padding;696 } stbtt_vertex;697 #endif698 693-extern int stbtt_IsGlyphEmpty(const stbtt_fontinfo *info, int glyph_index);699+STBTT_DEF int stbtt_IsGlyphEmpty(const stbtt_fontinfo *info, int glyph_index);700 // returns non-zero if nothing is drawn for this glyph701 696-extern int stbtt_GetCodepointShape(const stbtt_fontinfo *info, int unicode_codepoint, stbtt_vertex **vertices);697-extern int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, stbtt_vertex **vertices);702+STBTT_DEF int stbtt_GetCodepointShape(const stbtt_fontinfo *info, int unicode_codepoint, stbtt_vertex **vertices);703+STBTT_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 with2 unmodified lines710 // 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.713 708-extern void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *vertices);714+STBTT_DEF void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *vertices);715 // frees the data allocated above716 717 //////////////////////////////////////////////////////////////////////////////718 //719 // BITMAP RENDERING720 //721 716-extern void stbtt_FreeBitmap(unsigned char *bitmap, void *userdata);722+STBTT_DEF void stbtt_FreeBitmap(unsigned char *bitmap, void *userdata);723 // frees the bitmap allocated below724 719-extern unsigned char *stbtt_GetCodepointBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int codepoint, int *width, int *height, int *xoff, int *yoff);725+STBTT_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 bitmap733 728-extern 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);734+STBTT_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 character737 732-extern 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);738+STBTT_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.743 738-extern 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);744+STBTT_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 character747 742-extern void stbtt_GetCodepointBitmapBox(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1);748+STBTT_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.)754 749-extern 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);755+STBTT_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 character758 759 // the following functions are equivalent to the above functions, but operate760 // on glyph indices instead of Unicode codepoints (for efficiency)755-extern unsigned char *stbtt_GetGlyphBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int glyph, int *width, int *height, int *xoff, int *yoff);756-extern 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);757-extern 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);758-extern 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);759-extern void stbtt_GetGlyphBitmapBox(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1);760-extern 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);761+STBTT_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);762+STBTT_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);763+STBTT_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);764+STBTT_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);765+STBTT_DEF void stbtt_GetGlyphBitmapBox(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1);766+STBTT_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);767 768 769 // @TODO: don't expose this structure770 typedef struct1 unmodified line772 int w,h,stride;773 unsigned char *pixels;774 } stbtt__bitmap;775 770-extern 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);776+STBTT_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);777 778 //////////////////////////////////////////////////////////////////////////////779 //780 // Finding the right font...15 unmodified lines796 // from the file yourself and do your own comparisons on them.797 // You have to have called stbtt_InitFont() first.798 799 794-extern int stbtt_FindMatchingFont(const unsigned char *fontdata, const char *name, int flags);800+STBTT_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 consistently2 unmodified lines807 #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 0810 805-extern int stbtt_CompareUTF8toUTF16_bigendian(const char *s1, int len1, const char *s2, int len2);811+STBTT_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 func814 809-extern const char *stbtt_GetFontNameString(const stbtt_fontinfo *font, int *length, int platformID, int encodingID, int languageID, int nameID);815+STBTT_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 lines910 #define ttLONG(p) (* (stbtt_int32 *) (p))911 912 #else913 908- 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]; }918 919 #endif920 921 #define stbtt_tag4(p,c0,c1,c2,c3) ((p)[0] == (c0) && (p)[1] == (c1) && (p)[2] == (c2) && (p)[3] == (c3))22 unmodified lines944 }945 return 0;946 }947 942-int stbtt_GetFontOffsetForIndex(const unsigned char *font_collection, int index)948+STBTT_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 lines963 }964 return -1;965 }966 961-int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data2, int fontstart)967+STBTT_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 lines1020 info->indexToLocFormat = ttUSHORT(data+info->head + 50);1021 return 1;1022 }1023 1018-int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codepoint)1024+STBTT_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 lines1112 STBTT_assert(0);1113 return 0;1114 }1115 1110-int stbtt_GetCodepointShape(const stbtt_fontinfo *info, int unicode_codepoint, stbtt_vertex **vertices)1116+STBTT_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 lines1144 1145 return g1==g2 ? -1 : g1; // if length is 0, return -11146 }1147 1142-int stbtt_GetGlyphBox(const stbtt_fontinfo *info, int glyph_index, int *x0, int *y0, int *x1, int *y1)1148+STBTT_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 lines1156 if (y1) *y1 = ttSHORT(info->data + g + 8);1157 return 1;1158 }1159 1154-int stbtt_GetCodepointBox(const stbtt_fontinfo *info, int codepoint, int *x0, int *y0, int *x1, int *y1)1160+STBTT_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 }1164 1159-int stbtt_IsGlyphEmpty(const stbtt_fontinfo *info, int glyph_index)1165+STBTT_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 lines1186 }1187 return num_vertices;1188 }1189 1184-int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, stbtt_vertex **pvertices)1190+STBTT_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 lines1412 *pvertices = vertices;1413 return num_vertices;1414 }1415 1410-void stbtt_GetGlyphHMetrics(const stbtt_fontinfo *info, int glyph_index, int *advanceWidth, int *leftSideBearing)1416+STBTT_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 lines1424 if (leftSideBearing) *leftSideBearing = ttSHORT(info->data + info->hmtx + 4*numOfLongHorMetrics + 2*(glyph_index - numOfLongHorMetrics));1425 }1426 }1427 1422-int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2)1428+STBTT_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 lines1454 }1455 return 0;1456 }1457 1452-int stbtt_GetCodepointKernAdvance(const stbtt_fontinfo *info, int ch1, int ch2)1458+STBTT_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 }1464 1459-void stbtt_GetCodepointHMetrics(const stbtt_fontinfo *info, int codepoint, int *advanceWidth, int *leftSideBearing)1465+STBTT_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 }1469 1464-void stbtt_GetFontVMetrics(const stbtt_fontinfo *info, int *ascent, int *descent, int *lineGap)1470+STBTT_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 }1476 1471-void stbtt_GetFontBoundingBox(const stbtt_fontinfo *info, int *x0, int *y0, int *x1, int *y1)1477+STBTT_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 }1484 1479-float stbtt_ScaleForPixelHeight(const stbtt_fontinfo *info, float height)1485+STBTT_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 }1490 1485-float stbtt_ScaleForMappingEmToPixels(const stbtt_fontinfo *info, float pixels)1491+STBTT_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 }1496 1491-void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *v)1497+STBTT_DEF void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *v)1498 {1499 STBTT_free(v, info->userdata);1500 }1501 1 unmodified line1503 //1504 // antialiasing software rasterizer1505 //1506 1501-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)1507+STBTT_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 character9 unmodified lines1521 if (iy1) *iy1 = STBTT_iceil (-y0 * scale_y + shift_y);1522 }1523 }1524 1519-void stbtt_GetGlyphBitmapBox(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1)1525+STBTT_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 }1529 1524-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)1530+STBTT_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 }1534 1529-void stbtt_GetCodepointBitmapBox(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1)1535+STBTT_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 lines1812 return 1;1813 }1814 1815 // returns number of contours1810-stbtt__point *stbtt_FlattenCurves(stbtt_vertex *vertices, int num_verts, float objspace_flatness, int **contour_lengths, int *num_contours, void *userdata)1816+static 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 lines1881 *num_contours = 0;1882 return NULL;1883 }1884 1879-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)1885+STBTT_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 lines1893 STBTT_free(windings, userdata);1894 }1895 }1896 1891-void stbtt_FreeBitmap(unsigned char *bitmap, void *userdata)1897+STBTT_DEF void stbtt_FreeBitmap(unsigned char *bitmap, void *userdata)1898 {1899 STBTT_free(bitmap, userdata);1900 }1901 1896-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)1902+STBTT_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 lines1935 STBTT_free(vertices, info->userdata);1936 return gbm.pixels;1937 } 1938 1933-unsigned char *stbtt_GetGlyphBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int glyph, int *width, int *height, int *xoff, int *yoff)1939+STBTT_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 }1943 1938-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)1944+STBTT_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 lines1959 1960 STBTT_free(vertices, info->userdata);1961 }1962 1957-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)1963+STBTT_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 }1967 1962-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)1968+STBTT_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 } 1972 1967-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)1973+STBTT_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 }1977 1972-unsigned char *stbtt_GetCodepointBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int codepoint, int *width, int *height, int *xoff, int *yoff)1978+STBTT_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 } 1982 1977-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)1983+STBTT_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 lines1990 // bitmap baking1991 //1992 // This is SUPER-CRAPPY packing to keep source code small1993 1988-extern int stbtt_BakeFontBitmap(const unsigned char *data, int offset, // font location (use offset=0 for plain .ttf)1994+STBTT_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 lines2035 }2036 return bottom_y;2037 }2038 2033-void stbtt_GetBakedQuad(stbtt_bakedchar *chardata, int pw, int ph, int char_index, float *xpos, float *ypos, stbtt_aligned_quad *q, int opengl_fillrule)2039+STBTT_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 lines2138 //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.2141 2136-int stbtt_PackBegin(stbtt_pack_context *spc, unsigned char *pixels, int pw, int ph, int stride_in_bytes, int padding, void *alloc_context)2142+STBTT_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 lines2168 2169 return 1;2170 }2171 2166-void stbtt_PackEnd (stbtt_pack_context *spc)2172+STBTT_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 }2177 2172-void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h_oversample, unsigned int v_oversample)2178+STBTT_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 lines2306 // direction to counter this.2307 return (float)-(oversample - 1) / (2.0f * (float)oversample);2308 }2309 2304-int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges)2310+STBTT_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 lines2415 2416 return return_value;2417 }2418 2413-int stbtt_PackFontRange(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, float font_size,2419+STBTT_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 lines2426 range.font_size = font_size;2427 return stbtt_PackFontRanges(spc, fontdata, font_index, &range, 1);2428 }2429 2424-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)2430+STBTT_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 lines2499 }2500 return i;2501 }2502 2497-int stbtt_CompareUTF8toUTF16_bigendian(const char *s1, int len1, const char *s2, int len2) 2503+STBTT_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 }2507 2508 // returns results in whatever encoding you request... but note that 2-byte encodings2509 // will be BIG-ENDIAN... use stbtt_CompareUTF8toUTF16_bigendian() to compare2504-const char *stbtt_GetFontNameString(const stbtt_fontinfo *font, int *length, int platformID, int encodingID, int languageID, int nameID)2510+STBTT_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 lines2603 2604 return 0;2605 }2606 2601-int stbtt_FindMatchingFont(const unsigned char *font_collection, const char *name_utf8, stbtt_int32 flags)2607+STBTT_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