Merge branch 'stb-truetype-static' of https://github.com/ocornut/stb into work2
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Sean Barrett · committed by Sean Barrett · parents 1e57bcd, 45fec17 · 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
025ca3f- Tree
26d7b8d- Author
Sean Barrett <sean2@nothings.org>- Committer
Sean Barrett <sean2@nothings.org>- Parent 1
1e57bcd- Parent 2
45fec17
1 file changed+95 added−89 removed
modified:stb_truetype.h+95 added-89 removed
375 unmodified lines376 377 typedef char stbtt__check_size32[sizeof(stbtt_int32)==4 ? 1 : -1];378 typedef char stbtt__check_size16[sizeof(stbtt_int16)==2 ? 1 : -1];379 380+ #ifdef STBTT_STATIC381+ #define STBTT_DEF static382+ #else383+ #define STBTT_DEF extern384+ #endif385+386 // #define your own STBTT_sort() to override this to avoid qsort387 #ifndef STBTT_sort388 #include <stdlib.h>389 #define STBTT_sort(data,num_items,item_size,compare_func) qsort(data,num_items,item_size,compare_func)61 unmodified lines451 unsigned short x0,y0,x1,y1; // coordinates of bbox in bitmap452 float xoff,yoff,xadvance;453 } stbtt_bakedchar;454 449-extern int stbtt_BakeFontBitmap(const unsigned char *data, int offset, // font location (use offset=0 for plain .ttf)455+STBTT_DEF int stbtt_BakeFontBitmap(const unsigned char *data, int offset, // font location (use offset=0 for plain .ttf)456 float pixel_height, // height of font in pixels457 unsigned char *pixels, int pw, int ph, // bitmap to be filled in458 int first_char, int num_chars, // characters to bake459 stbtt_bakedchar *chardata); // you allocate this, it's num_chars long7 unmodified lines467 float x0,y0,s0,t0; // top-left468 float x1,y1,s1,t1; // bottom-right469 } stbtt_aligned_quad;470 465-extern void stbtt_GetBakedQuad(stbtt_bakedchar *chardata, int pw, int ph, // same data as above471+STBTT_DEF void stbtt_GetBakedQuad(stbtt_bakedchar *chardata, int pw, int ph, // same data as above472 int char_index, // character to display473 float *xpos, float *ypos, // pointers to current position in screen pixel space474 stbtt_aligned_quad *q, // output: quad to draw475 int opengl_fillrule); // true if opengl fill rule; false if DX9 or earlier24 unmodified lines500 } stbtt_packedchar;501 502 typedef struct stbtt_pack_context stbtt_pack_context;503 498-extern int stbtt_PackBegin(stbtt_pack_context *spc, unsigned char *pixels, int width, int height, int stride_in_bytes, int padding, void *alloc_context);504+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);505 // Initializes a packing context stored in the passed-in stbtt_pack_context.506 // Future calls using this context will pack characters into the bitmap passed507 // in here: a 1-channel bitmap that is weight x height. stride_in_bytes is508 // the distance from one row to the next (or 0 to mean they are packed tightly2 unmodified lines511 // bilinear filtering).512 //513 // Returns 0 on failure, 1 on success.514 509-extern void stbtt_PackEnd (stbtt_pack_context *spc);515+STBTT_DEF void stbtt_PackEnd (stbtt_pack_context *spc);516 // Cleans up the packing context and frees all memory.517 518 #define STBTT_POINT_SIZE(x) (-(x))519 514-extern int stbtt_PackFontRange(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, float font_size,520+STBTT_DEF int stbtt_PackFontRange(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, float font_size,521 int first_unicode_char_in_range, int num_chars_in_range, stbtt_packedchar *chardata_for_range);522 // Creates character bitmaps from the font_index'th font found in fontdata (use523 // font_index=0 if you don't know what that is). It creates num_chars_in_range524 // bitmaps for characters with unicode values starting at first_unicode_char_in_range14 unmodified lines539 int num_chars_in_range;540 stbtt_packedchar *chardata_for_range; // output541 } stbtt_pack_range;542 537-extern int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges);543+STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges);544 // Creates character bitmaps from multiple ranges of characters stored in545 // ranges. This will usually create a better-packed bitmap than multiple546 // calls to stbtt_PackFontRange.547 548 543-extern void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h_oversample, unsigned int v_oversample);549+STBTT_DEF void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h_oversample, unsigned int v_oversample);550 // Oversampling a font increases the quality by allowing higher-quality subpixel551 // positioning, and is especially valuable at smaller text sizes.552 //553 // This function sets the amount of oversampling for all following calls to3 unmodified lines557 // oversampling requires 4x the storage of 1x1. For best results, render558 // oversampled textures with bilinear filtering. Look at the readme in559 // stb/tests/oversample for information about oversampled fonts560 555-extern void stbtt_GetPackedQuad(stbtt_packedchar *chardata, int pw, int ph, // same data as above561+STBTT_DEF void stbtt_GetPackedQuad(stbtt_packedchar *chardata, int pw, int ph, // same data as above562 int char_index, // character to display563 float *xpos, float *ypos, // pointers to current position in screen pixel space564 stbtt_aligned_quad *q, // output: quad to draw565 int align_to_integer);17 unmodified lines583 // FONT LOADING584 //585 //586 581-extern int stbtt_GetFontOffsetForIndex(const unsigned char *data, int index);587+STBTT_DEF int stbtt_GetFontOffsetForIndex(const unsigned char *data, int index);588 // Each .ttf/.ttc file may have more than one font. Each font has a sequential589 // index number starting from 0. Call this function to get the font offset for590 // a given index; it returns -1 if the index is out of range. A regular .ttf591 // file will only define one font and it always be at offset 0, so it will15 unmodified lines607 int index_map; // a cmap mapping for our chosen character encoding608 int indexToLocFormat; // format needed to map from glyph index to glyph609 } stbtt_fontinfo;610 605-extern int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data, int offset);611+STBTT_DEF int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data, int offset);612 // Given an offset into the file that defines a font, this function builds613 // the necessary cached info for the rest of the system. You must allocate614 // the stbtt_fontinfo yourself, and stbtt_InitFont will fill it out. You don't615 // need to do anything special to free it, because the contents are pure3 unmodified lines619 //////////////////////////////////////////////////////////////////////////////620 //621 // CHARACTER TO GLYPH-INDEX CONVERSIOn622 617-int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codepoint);623+STBTT_DEF int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codepoint);624 // If you're going to perform multiple operations on the same character625 // and you want a speed-up, call this function with the character you're626 // going to process, then use glyph-based functions instead of the627 // codepoint-based functions.3 unmodified lines631 //632 // CHARACTER PROPERTIES633 //634 629-extern float stbtt_ScaleForPixelHeight(const stbtt_fontinfo *info, float pixels);635+STBTT_DEF float stbtt_ScaleForPixelHeight(const stbtt_fontinfo *info, float pixels);636 // computes a scale factor to produce a font whose "height" is 'pixels' tall.637 // Height is measured as the distance from the highest ascender to the lowest638 // descender; in other words, it's equivalent to calling stbtt_GetFontVMetrics639 // and computing:640 // scale = pixels / (ascent - descent)641 // so if you prefer to measure height by the ascent only, use a similar calculation.642 637-extern float stbtt_ScaleForMappingEmToPixels(const stbtt_fontinfo *info, float pixels);643+STBTT_DEF float stbtt_ScaleForMappingEmToPixels(const stbtt_fontinfo *info, float pixels);644 // computes a scale factor to produce a font whose EM size is mapped to645 // 'pixels' tall. This is probably what traditional APIs compute, but646 // I'm not positive.647 642-extern void stbtt_GetFontVMetrics(const stbtt_fontinfo *info, int *ascent, int *descent, int *lineGap);648+STBTT_DEF void stbtt_GetFontVMetrics(const stbtt_fontinfo *info, int *ascent, int *descent, int *lineGap);649 // ascent is the coordinate above the baseline the font extends; descent650 // is the coordinate below the baseline the font extends (i.e. it is typically negative)651 // lineGap is the spacing between one row's descent and the next row's ascent...652 // so you should advance the vertical position by "*ascent - *descent + *lineGap"653 // these are expressed in unscaled coordinates, so you must multiply by654 // the scale factor for a given size655 650-extern void stbtt_GetFontBoundingBox(const stbtt_fontinfo *info, int *x0, int *y0, int *x1, int *y1);656+STBTT_DEF void stbtt_GetFontBoundingBox(const stbtt_fontinfo *info, int *x0, int *y0, int *x1, int *y1);657 // the bounding box around all possible characters658 653-extern void stbtt_GetCodepointHMetrics(const stbtt_fontinfo *info, int codepoint, int *advanceWidth, int *leftSideBearing);659+STBTT_DEF void stbtt_GetCodepointHMetrics(const stbtt_fontinfo *info, int codepoint, int *advanceWidth, int *leftSideBearing);660 // leftSideBearing is the offset from the current horizontal position to the left edge of the character661 // advanceWidth is the offset from the current horizontal position to the next horizontal position662 // these are expressed in unscaled coordinates663 658-extern int stbtt_GetCodepointKernAdvance(const stbtt_fontinfo *info, int ch1, int ch2);664+STBTT_DEF int stbtt_GetCodepointKernAdvance(const stbtt_fontinfo *info, int ch1, int ch2);665 // an additional amount to add to the 'advance' value between ch1 and ch2666 661-extern int stbtt_GetCodepointBox(const stbtt_fontinfo *info, int codepoint, int *x0, int *y0, int *x1, int *y1);667+STBTT_DEF int stbtt_GetCodepointBox(const stbtt_fontinfo *info, int codepoint, int *x0, int *y0, int *x1, int *y1);668 // Gets the bounding box of the visible part of the glyph, in unscaled coordinates669 664-extern void stbtt_GetGlyphHMetrics(const stbtt_fontinfo *info, int glyph_index, int *advanceWidth, int *leftSideBearing);665-extern int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2);666-extern int stbtt_GetGlyphBox(const stbtt_fontinfo *info, int glyph_index, int *x0, int *y0, int *x1, int *y1);670+STBTT_DEF void stbtt_GetGlyphHMetrics(const stbtt_fontinfo *info, int glyph_index, int *advanceWidth, int *leftSideBearing);671+STBTT_DEF int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2);672+STBTT_DEF int stbtt_GetGlyphBox(const stbtt_fontinfo *info, int glyph_index, int *x0, int *y0, int *x1, int *y1);673 // as above, but takes one or more glyph indices for greater efficiency674 675 676 //////////////////////////////////////////////////////////////////////////////19 unmodified lines696 unsigned char type,padding;697 } stbtt_vertex;698 #endif699 694-extern int stbtt_IsGlyphEmpty(const stbtt_fontinfo *info, int glyph_index);700+STBTT_DEF int stbtt_IsGlyphEmpty(const stbtt_fontinfo *info, int glyph_index);701 // returns non-zero if nothing is drawn for this glyph702 697-extern int stbtt_GetCodepointShape(const stbtt_fontinfo *info, int unicode_codepoint, stbtt_vertex **vertices);698-extern int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, stbtt_vertex **vertices);703+STBTT_DEF int stbtt_GetCodepointShape(const stbtt_fontinfo *info, int unicode_codepoint, stbtt_vertex **vertices);704+STBTT_DEF int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, stbtt_vertex **vertices);705 // returns # of vertices and fills *vertices with the pointer to them706 // these are expressed in "unscaled" coordinates707 //708 // The shape is a series of countours. Each one starts with2 unmodified lines711 // draws a line from previous endpoint to its x,y; a curveto712 // draws a quadratic bezier from previous endpoint to713 // its x,y, using cx,cy as the bezier control point.714 709-extern void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *vertices);715+STBTT_DEF void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *vertices);716 // frees the data allocated above717 718 //////////////////////////////////////////////////////////////////////////////719 //720 // BITMAP RENDERING721 //722 717-extern void stbtt_FreeBitmap(unsigned char *bitmap, void *userdata);723+STBTT_DEF void stbtt_FreeBitmap(unsigned char *bitmap, void *userdata);724 // frees the bitmap allocated below725 720-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);726+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);727 // allocates a large-enough single-channel 8bpp bitmap and renders the728 // specified character/glyph at the specified scale into it, with729 // antialiasing. 0 is no coverage (transparent), 255 is fully covered (opaque).730 // *width & *height are filled out with the width & height of the bitmap,731 // which is stored left-to-right, top-to-bottom.732 //733 // xoff/yoff are the offset it pixel space from the glyph origin to the top-left of the bitmap734 729-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);735+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);736 // the same as stbtt_GetCodepoitnBitmap, but you can specify a subpixel737 // shift for the character738 733-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);739+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);740 // the same as stbtt_GetCodepointBitmap, but you pass in storage for the bitmap741 // in the form of 'output', with row spacing of 'out_stride' bytes. the bitmap742 // is clipped to out_w/out_h bytes. Call stbtt_GetCodepointBitmapBox to get the743 // width and height and positioning info for it first.744 739-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);745+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);746 // same as stbtt_MakeCodepointBitmap, but you can specify a subpixel747 // shift for the character748 743-extern void stbtt_GetCodepointBitmapBox(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1);749+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);750 // get the bbox of the bitmap centered around the glyph origin; so the751 // bitmap width is ix1-ix0, height is iy1-iy0, and location to place752 // the bitmap top left is (leftSideBearing*scale,iy0).753 // (Note that the bitmap uses y-increases-down, but the shape uses754 // y-increases-up, so CodepointBitmapBox and CodepointBox are inverted.)755 750-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);756+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);757 // same as stbtt_GetCodepointBitmapBox, but you can specify a subpixel758 // shift for the character759 760 // the following functions are equivalent to the above functions, but operate761 // on glyph indices instead of Unicode codepoints (for efficiency)756-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);757-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);758-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);759-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);760-extern void stbtt_GetGlyphBitmapBox(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1);761-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);762+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);763+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);764+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);765+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);766+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);767+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);768 769 770 // @TODO: don't expose this structure771 typedef struct1 unmodified line773 int w,h,stride;774 unsigned char *pixels;775 } stbtt__bitmap;776 771-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);777+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);778 779 //////////////////////////////////////////////////////////////////////////////780 //781 // Finding the right font...15 unmodified lines797 // from the file yourself and do your own comparisons on them.798 // You have to have called stbtt_InitFont() first.799 800 795-extern int stbtt_FindMatchingFont(const unsigned char *fontdata, const char *name, int flags);801+STBTT_DEF int stbtt_FindMatchingFont(const unsigned char *fontdata, const char *name, int flags);802 // returns the offset (not index) of the font that matches, or -1 if none803 // if you use STBTT_MACSTYLE_DONTCARE, use a font name like "Arial Bold".804 // if you use any other flag, use a font name like "Arial"; this checks805 // the 'macStyle' header field; i don't know if fonts set this consistently2 unmodified lines808 #define STBTT_MACSTYLE_ITALIC 2809 #define STBTT_MACSTYLE_UNDERSCORE 4810 #define STBTT_MACSTYLE_NONE 8 // <= not same as 0, this makes us check the bitfield is 0811 806-extern int stbtt_CompareUTF8toUTF16_bigendian(const char *s1, int len1, const char *s2, int len2);812+STBTT_DEF int stbtt_CompareUTF8toUTF16_bigendian(const char *s1, int len1, const char *s2, int len2);813 // returns 1/0 whether the first string interpreted as utf8 is identical to814 // the second string interpreted as big-endian utf16... useful for strings from next func815 810-extern const char *stbtt_GetFontNameString(const stbtt_fontinfo *font, int *length, int platformID, int encodingID, int languageID, int nameID);816+STBTT_DEF const char *stbtt_GetFontNameString(const stbtt_fontinfo *font, int *length, int platformID, int encodingID, int languageID, int nameID);817 // returns the string (which may be big-endian double byte, e.g. for unicode)818 // and puts the length in bytes in *length.819 //820 // some of the values for the IDs are below; for more see the truetype spec:90 unmodified lines911 #define ttLONG(p) (* (stbtt_int32 *) (p))912 913 #else914 909- stbtt_uint16 ttUSHORT(const stbtt_uint8 *p) { return p[0]*256 + p[1]; }910- stbtt_int16 ttSHORT(const stbtt_uint8 *p) { return p[0]*256 + p[1]; }911- stbtt_uint32 ttULONG(const stbtt_uint8 *p) { return (p[0]<<24) + (p[1]<<16) + (p[2]<<8) + p[3]; }912- stbtt_int32 ttLONG(const stbtt_uint8 *p) { return (p[0]<<24) + (p[1]<<16) + (p[2]<<8) + p[3]; }915+ static stbtt_uint16 ttUSHORT(const stbtt_uint8 *p) { return p[0]*256 + p[1]; }916+ static stbtt_int16 ttSHORT(const stbtt_uint8 *p) { return p[0]*256 + p[1]; }917+ static stbtt_uint32 ttULONG(const stbtt_uint8 *p) { return (p[0]<<24) + (p[1]<<16) + (p[2]<<8) + p[3]; }918+ static stbtt_int32 ttLONG(const stbtt_uint8 *p) { return (p[0]<<24) + (p[1]<<16) + (p[2]<<8) + p[3]; }919 920 #endif921 922 #define stbtt_tag4(p,c0,c1,c2,c3) ((p)[0] == (c0) && (p)[1] == (c1) && (p)[2] == (c2) && (p)[3] == (c3))22 unmodified lines945 }946 return 0;947 }948 943-int stbtt_GetFontOffsetForIndex(const unsigned char *font_collection, int index)949+STBTT_DEF int stbtt_GetFontOffsetForIndex(const unsigned char *font_collection, int index)950 {951 // if it's just a font, there's only one valid index952 if (stbtt__isfont(font_collection))953 return index == 0 ? 0 : -1;10 unmodified lines964 }965 return -1;966 }967 962-int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data2, int fontstart)968+STBTT_DEF int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data2, int fontstart)969 {970 stbtt_uint8 *data = (stbtt_uint8 *) data2;971 stbtt_uint32 cmap, t;972 stbtt_int32 i,numTables;48 unmodified lines1021 info->indexToLocFormat = ttUSHORT(data+info->head + 50);1022 return 1;1023 }1024 1019-int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codepoint)1025+STBTT_DEF int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codepoint)1026 {1027 stbtt_uint8 *data = info->data;1028 stbtt_uint32 index_map = info->index_map;1029 83 unmodified lines1113 STBTT_assert(0);1114 return 0;1115 }1116 1111-int stbtt_GetCodepointShape(const stbtt_fontinfo *info, int unicode_codepoint, stbtt_vertex **vertices)1117+STBTT_DEF int stbtt_GetCodepointShape(const stbtt_fontinfo *info, int unicode_codepoint, stbtt_vertex **vertices)1118 {1119 return stbtt_GetGlyphShape(info, stbtt_FindGlyphIndex(info, unicode_codepoint), vertices);1120 }1121 23 unmodified lines1145 1146 return g1==g2 ? -1 : g1; // if length is 0, return -11147 }1148 1143-int stbtt_GetGlyphBox(const stbtt_fontinfo *info, int glyph_index, int *x0, int *y0, int *x1, int *y1)1149+STBTT_DEF int stbtt_GetGlyphBox(const stbtt_fontinfo *info, int glyph_index, int *x0, int *y0, int *x1, int *y1)1150 {1151 int g = stbtt__GetGlyfOffset(info, glyph_index);1152 if (g < 0) return 0;1153 3 unmodified lines1157 if (y1) *y1 = ttSHORT(info->data + g + 8);1158 return 1;1159 }1160 1155-int stbtt_GetCodepointBox(const stbtt_fontinfo *info, int codepoint, int *x0, int *y0, int *x1, int *y1)1161+STBTT_DEF int stbtt_GetCodepointBox(const stbtt_fontinfo *info, int codepoint, int *x0, int *y0, int *x1, int *y1)1162 {1163 return stbtt_GetGlyphBox(info, stbtt_FindGlyphIndex(info,codepoint), x0,y0,x1,y1);1164 }1165 1160-int stbtt_IsGlyphEmpty(const stbtt_fontinfo *info, int glyph_index)1166+STBTT_DEF int stbtt_IsGlyphEmpty(const stbtt_fontinfo *info, int glyph_index)1167 {1168 stbtt_int16 numberOfContours;1169 int g = stbtt__GetGlyfOffset(info, glyph_index);1170 if (g < 0) return 1;16 unmodified lines1187 }1188 return num_vertices;1189 }1190 1185-int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, stbtt_vertex **pvertices)1191+STBTT_DEF int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, stbtt_vertex **pvertices)1192 {1193 stbtt_int16 numberOfContours;1194 stbtt_uint8 *endPtsOfContours;1195 stbtt_uint8 *data = info->data;217 unmodified lines1413 *pvertices = vertices;1414 return num_vertices;1415 }1416 1411-void stbtt_GetGlyphHMetrics(const stbtt_fontinfo *info, int glyph_index, int *advanceWidth, int *leftSideBearing)1417+STBTT_DEF void stbtt_GetGlyphHMetrics(const stbtt_fontinfo *info, int glyph_index, int *advanceWidth, int *leftSideBearing)1418 {1419 stbtt_uint16 numOfLongHorMetrics = ttUSHORT(info->data+info->hhea + 34);1420 if (glyph_index < numOfLongHorMetrics) {1421 if (advanceWidth) *advanceWidth = ttSHORT(info->data + info->hmtx + 4*glyph_index);3 unmodified lines1425 if (leftSideBearing) *leftSideBearing = ttSHORT(info->data + info->hmtx + 4*numOfLongHorMetrics + 2*(glyph_index - numOfLongHorMetrics));1426 }1427 }1428 1423-int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2)1429+STBTT_DEF int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2)1430 {1431 stbtt_uint8 *data = info->data + info->kern;1432 stbtt_uint32 needle, straw;1433 int l, r, m;21 unmodified lines1455 }1456 return 0;1457 }1458 1453-int stbtt_GetCodepointKernAdvance(const stbtt_fontinfo *info, int ch1, int ch2)1459+STBTT_DEF int stbtt_GetCodepointKernAdvance(const stbtt_fontinfo *info, int ch1, int ch2)1460 {1461 if (!info->kern) // if no kerning table, don't waste time looking up both codepoint->glyphs1462 return 0;1463 return stbtt_GetGlyphKernAdvance(info, stbtt_FindGlyphIndex(info,ch1), stbtt_FindGlyphIndex(info,ch2));1464 }1465 1460-void stbtt_GetCodepointHMetrics(const stbtt_fontinfo *info, int codepoint, int *advanceWidth, int *leftSideBearing)1466+STBTT_DEF void stbtt_GetCodepointHMetrics(const stbtt_fontinfo *info, int codepoint, int *advanceWidth, int *leftSideBearing)1467 {1468 stbtt_GetGlyphHMetrics(info, stbtt_FindGlyphIndex(info,codepoint), advanceWidth, leftSideBearing);1469 }1470 1465-void stbtt_GetFontVMetrics(const stbtt_fontinfo *info, int *ascent, int *descent, int *lineGap)1471+STBTT_DEF void stbtt_GetFontVMetrics(const stbtt_fontinfo *info, int *ascent, int *descent, int *lineGap)1472 {1473 if (ascent ) *ascent = ttSHORT(info->data+info->hhea + 4);1474 if (descent) *descent = ttSHORT(info->data+info->hhea + 6);1475 if (lineGap) *lineGap = ttSHORT(info->data+info->hhea + 8);1476 }1477 1472-void stbtt_GetFontBoundingBox(const stbtt_fontinfo *info, int *x0, int *y0, int *x1, int *y1)1478+STBTT_DEF void stbtt_GetFontBoundingBox(const stbtt_fontinfo *info, int *x0, int *y0, int *x1, int *y1)1479 {1480 *x0 = ttSHORT(info->data + info->head + 36);1481 *y0 = ttSHORT(info->data + info->head + 38);1482 *x1 = ttSHORT(info->data + info->head + 40);1483 *y1 = ttSHORT(info->data + info->head + 42);1484 }1485 1480-float stbtt_ScaleForPixelHeight(const stbtt_fontinfo *info, float height)1486+STBTT_DEF float stbtt_ScaleForPixelHeight(const stbtt_fontinfo *info, float height)1487 {1488 int fheight = ttSHORT(info->data + info->hhea + 4) - ttSHORT(info->data + info->hhea + 6);1489 return (float) height / fheight;1490 }1491 1486-float stbtt_ScaleForMappingEmToPixels(const stbtt_fontinfo *info, float pixels)1492+STBTT_DEF float stbtt_ScaleForMappingEmToPixels(const stbtt_fontinfo *info, float pixels)1493 {1494 int unitsPerEm = ttUSHORT(info->data + info->head + 18);1495 return pixels / unitsPerEm;1496 }1497 1492-void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *v)1498+STBTT_DEF void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *v)1499 {1500 STBTT_free(v, info->userdata);1501 }1502 1 unmodified line1504 //1505 // antialiasing software rasterizer1506 //1507 1502-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+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)1509 {1510 int x0,y0,x1,y1;1511 if (!stbtt_GetGlyphBox(font, glyph, &x0,&y0,&x1,&y1)) {1512 // e.g. space character9 unmodified lines1522 if (iy1) *iy1 = STBTT_iceil (-y0 * scale_y + shift_y);1523 }1524 }1525 1520-void stbtt_GetGlyphBitmapBox(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1)1526+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)1527 {1528 stbtt_GetGlyphBitmapBoxSubpixel(font, glyph, scale_x, scale_y,0.0f,0.0f, ix0, iy0, ix1, iy1);1529 }1530 1525-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+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)1532 {1533 stbtt_GetGlyphBitmapBoxSubpixel(font, stbtt_FindGlyphIndex(font,codepoint), scale_x, scale_y,shift_x,shift_y, ix0,iy0,ix1,iy1);1534 }1535 1530-void stbtt_GetCodepointBitmapBox(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1)1536+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)1537 {1538 stbtt_GetCodepointBitmapBoxSubpixel(font, codepoint, scale_x, scale_y,0.0f,0.0f, ix0,iy0,ix1,iy1);1539 }1540 272 unmodified lines1813 return 1;1814 }1815 1816 // returns number of contours1811-stbtt__point *stbtt_FlattenCurves(stbtt_vertex *vertices, int num_verts, float objspace_flatness, int **contour_lengths, int *num_contours, void *userdata)1817+static stbtt__point *stbtt_FlattenCurves(stbtt_vertex *vertices, int num_verts, float objspace_flatness, int **contour_lengths, int *num_contours, void *userdata)1818 {1819 stbtt__point *points=0;1820 int num_points=0;1821 60 unmodified lines1882 *num_contours = 0;1883 return NULL;1884 }1885 1880-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+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)1887 {1888 float scale = scale_x > scale_y ? scale_y : scale_x;1889 int winding_count, *winding_lengths;1890 stbtt__point *windings = stbtt_FlattenCurves(vertices, num_verts, flatness_in_pixels / scale, &winding_lengths, &winding_count, userdata);3 unmodified lines1894 STBTT_free(windings, userdata);1895 }1896 }1897 1892-void stbtt_FreeBitmap(unsigned char *bitmap, void *userdata)1898+STBTT_DEF void stbtt_FreeBitmap(unsigned char *bitmap, void *userdata)1899 {1900 STBTT_free(bitmap, userdata);1901 }1902 1897-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+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)1904 {1905 int ix0,iy0,ix1,iy1;1906 stbtt__bitmap gbm;1907 stbtt_vertex *vertices; 28 unmodified lines1936 STBTT_free(vertices, info->userdata);1937 return gbm.pixels;1938 } 1939 1934-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+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)1941 {1942 return stbtt_GetGlyphBitmapSubpixel(info, scale_x, scale_y, 0.0f, 0.0f, glyph, width, height, xoff, yoff);1943 }1944 1939-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+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)1946 {1947 int ix0,iy0;1948 stbtt_vertex *vertices;1949 int num_verts = stbtt_GetGlyphShape(info, glyph, &vertices);10 unmodified lines1960 1961 STBTT_free(vertices, info->userdata);1962 }1963 1958-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+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)1965 {1966 stbtt_MakeGlyphBitmapSubpixel(info, output, out_w, out_h, out_stride, scale_x, scale_y, 0.0f,0.0f, glyph);1967 }1968 1963-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+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)1970 {1971 return stbtt_GetGlyphBitmapSubpixel(info, scale_x, scale_y,shift_x,shift_y, stbtt_FindGlyphIndex(info,codepoint), width,height,xoff,yoff);1972 } 1973 1968-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+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)1975 {1976 stbtt_MakeGlyphBitmapSubpixel(info, output, out_w, out_h, out_stride, scale_x, scale_y, shift_x, shift_y, stbtt_FindGlyphIndex(info,codepoint));1977 }1978 1973-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+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)1980 {1981 return stbtt_GetCodepointBitmapSubpixel(info, scale_x, scale_y, 0.0f,0.0f, codepoint, width,height,xoff,yoff);1982 } 1983 1978-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+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)1985 {1986 stbtt_MakeCodepointBitmapSubpixel(info, output, out_w, out_h, out_stride, scale_x, scale_y, 0.0f,0.0f, codepoint);1987 }1988 2 unmodified lines1991 // bitmap baking1992 //1993 // This is SUPER-CRAPPY packing to keep source code small1994 1989-extern int stbtt_BakeFontBitmap(const unsigned char *data, int offset, // font location (use offset=0 for plain .ttf)1995+STBTT_DEF int stbtt_BakeFontBitmap(const unsigned char *data, int offset, // font location (use offset=0 for plain .ttf)1996 float pixel_height, // height of font in pixels1997 unsigned char *pixels, int pw, int ph, // bitmap to be filled in1998 int first_char, int num_chars, // characters to bake1999 stbtt_bakedchar *chardata)36 unmodified lines2036 }2037 return bottom_y;2038 }2039 2034-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+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)2041 {2042 float d3d_bias = opengl_fillrule ? 0 : -0.5f;2043 float ipw = 1.0f / pw, iph = 1.0f / ph;2044 stbtt_bakedchar *b = chardata + char_index;94 unmodified lines2139 //2140 // This is SUPER-AWESOME (tm Ryan Gordon) packing using stb_rect_pack.h. If2141 // stb_rect_pack.h isn't available, it uses the BakeFontBitmap strategy.2142 2137-int stbtt_PackBegin(stbtt_pack_context *spc, unsigned char *pixels, int pw, int ph, int stride_in_bytes, int padding, void *alloc_context)2143+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)2144 {2145 stbrp_context *context = (stbrp_context *) STBTT_malloc(sizeof(*context) ,alloc_context);2146 int num_nodes = pw - padding;2147 stbrp_node *nodes = (stbrp_node *) STBTT_malloc(sizeof(*nodes ) * num_nodes,alloc_context);21 unmodified lines2169 2170 return 1;2171 }2172 2167-void stbtt_PackEnd (stbtt_pack_context *spc)2173+STBTT_DEF void stbtt_PackEnd (stbtt_pack_context *spc)2174 {2175 STBTT_free(spc->nodes , spc->user_allocator_context);2176 STBTT_free(spc->pack_info, spc->user_allocator_context);2177 }2178 2173-void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h_oversample, unsigned int v_oversample)2179+STBTT_DEF void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h_oversample, unsigned int v_oversample)2180 {2181 STBTT_assert(h_oversample <= STBTT_MAX_OVERSAMPLE);2182 STBTT_assert(v_oversample <= STBTT_MAX_OVERSAMPLE);2183 if (h_oversample <= STBTT_MAX_OVERSAMPLE)123 unmodified lines2307 // direction to counter this.2308 return (float)-(oversample - 1) / (2.0f * (float)oversample);2309 }2310 2305-int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges)2311+STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges)2312 {2313 stbtt_fontinfo info;2314 float recip_h = 1.0f / spc->h_oversample;2315 float recip_v = 1.0f / spc->v_oversample;100 unmodified lines2416 2417 return return_value;2418 }2419 2414-int stbtt_PackFontRange(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, float font_size,2420+STBTT_DEF int stbtt_PackFontRange(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, float font_size,2421 int first_unicode_char_in_range, int num_chars_in_range, stbtt_packedchar *chardata_for_range)2422 {2423 stbtt_pack_range range;2424 range.first_unicode_char_in_range = first_unicode_char_in_range;2 unmodified lines2427 range.font_size = font_size;2428 return stbtt_PackFontRanges(spc, fontdata, font_index, &range, 1);2429 }2430 2425-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+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)2432 {2433 float ipw = 1.0f / pw, iph = 1.0f / ph;2434 stbtt_packedchar *b = chardata + char_index;2435 64 unmodified lines2500 }2501 return i;2502 }2503 2498-int stbtt_CompareUTF8toUTF16_bigendian(const char *s1, int len1, const char *s2, int len2) 2504+STBTT_DEF int stbtt_CompareUTF8toUTF16_bigendian(const char *s1, int len1, const char *s2, int len2) 2505 {2506 return len1 == stbtt__CompareUTF8toUTF16_bigendian_prefix((const stbtt_uint8*) s1, len1, (const stbtt_uint8*) s2, len2);2507 }2508 2509 // returns results in whatever encoding you request... but note that 2-byte encodings2510 // will be BIG-ENDIAN... use stbtt_CompareUTF8toUTF16_bigendian() to compare2505-const char *stbtt_GetFontNameString(const stbtt_fontinfo *font, int *length, int platformID, int encodingID, int languageID, int nameID)2511+STBTT_DEF const char *stbtt_GetFontNameString(const stbtt_fontinfo *font, int *length, int platformID, int encodingID, int languageID, int nameID)2512 {2513 stbtt_int32 i,count,stringOffset;2514 stbtt_uint8 *fc = font->data;2515 stbtt_uint32 offset = font->fontstart;88 unmodified lines2604 2605 return 0;2606 }2607 2602-int stbtt_FindMatchingFont(const unsigned char *font_collection, const char *name_utf8, stbtt_int32 flags)2608+STBTT_DEF int stbtt_FindMatchingFont(const unsigned char *font_collection, const char *name_utf8, stbtt_int32 flags)2609 {2610 stbtt_int32 i;2611 for (i=0;;++i) {2612 stbtt_int32 off = stbtt_GetFontOffsetForIndex(font_collection, i);7 unmodified lines