Merge branch 'num-fonts' of https://github.com/IntellectualKitty/stb into working
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Conflicts: stb_truetype.h
authored by Sean Barrett · committed by Sean Barrett · parents cca943e, 99fd236 · Browse files · 1 file·+33 added−6 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+33 added−6 removed
- other:+33 added−6 removed
Provenance
- Commit
4f2324c- Tree
ac3e4dd- Author
Sean Barrett <sean@nothings.org>- Committer
Sean Barrett <sean@nothings.org>- Parent 1
cca943e- Parent 2
99fd236
1 file changed+33 added−6 removed
modified:stb_truetype.h+33 added-6 removed
23 unmodified lines24 //25 // Misc other:26 // Ryan Gordon27 // Simon Glass28+// github:IntellectualKitty29 //30 // Bug/warning reports/fixes:31 // "Zer" on mollyrocket (with fix)32 // Cass Everitt16 unmodified lines49 // Giumo X. Clanjor50 // Higor Euripedes51 // Thomas Fields52 // Derek Vinyard52-// github:IntellectualKitty53 //54 // VERSION HISTORY55 //56-// 1.13 (2017-01-02) support OpenType fonts, certain Apple fonts,56+// 1.13 (2017-01-02) support OpenType fonts, certain Apple fonts, num-fonts-in-TTC function57 // 1.12 (2016-10-25) suppress warnings about casting away const with -Wcast-qual58 // 1.11 (2016-04-02) fix unused-variable warning59 // 1.10 (2016-04-02) user-defined fabs(); rare memory leak; remove duplicate typedef60 // 1.09 (2016-01-16) warning fix; avoid crash on outofmem; use allocation userdata properly36 unmodified lines97 // stbtt_GetPackedQuad()98 //99 // "Load" a font file from a memory buffer (you have to keep the buffer loaded)100 // stbtt_InitFont()101-// stbtt_GetFontOffsetForIndex() -- use for TTC font collections101+// stbtt_GetFontOffsetForIndex() -- indexing for TTC font collections102+// stbtt_GetNumberOfFonts() -- number of fonts for TTC font collections103 //104 // Render a unicode codepoint to a bitmap105 // stbtt_GetCodepointBitmap() -- allocates and returns a bitmap106 // stbtt_MakeCodepointBitmap() -- renders into bitmap you provide525 unmodified lines632 // FONT LOADING633 //634 //635 636+STBTT_DEF int stbtt_GetNumberOfFonts(const unsigned char *data);637+// This function will determine the number of fonts in a font file. TrueType638+// collection (.ttc) files may contain multiple fonts, while TrueType font639+// (.ttf) files only contain one font. The number of fonts can be used for640+// indexing with the previous function where the index is between zero and one641+// less than the total fonts. If an error occurs, -1 is returned.642+643 STBTT_DEF int stbtt_GetFontOffsetForIndex(const unsigned char *data, int index);644 // Each .ttf/.ttc file may have more than one font. Each font has a sequential645 // index number starting from 0. Call this function to get the font offset for646 // a given index; it returns -1 if the index is out of range. A regular .ttf647 // file will only define one font and it always be at offset 0, so it will640-// return '0' for index 0, and -1 for all other indices. You can just skip641-// this step if you know it's that kind of font.648+// return '0' for index 0, and -1 for all other indices.649 643-650 // The following structure is defined publically so you can declare one on651 // the stack or as a global or etc, but you should treat it as opaque.652 struct stbtt_fontinfo653 {531 unmodified lines1185 }1186 return -1;1187 }1188 1189+static int stbtt_GetNumberOfFonts_internal(unsigned char *font_collection)1190+{1191+ // if it's just a font, there's only one valid font1192+ if (stbtt__isfont(font_collection))1193+ return 1;1194+1195+ // check if it's a TTC1196+ if (stbtt_tag(font_collection, "ttcf")) {1197+ // version 1?1198+ if (ttULONG(font_collection+4) == 0x00010000 || ttULONG(font_collection+4) == 0x00020000) {1199+ return ttLONG(font_collection+8);1200+ }1201+ }1202+ return 0;1203+}1204+1205 static stbtt__buf stbtt__get_subrs(stbtt__buf cff, stbtt__buf fontdict)1206 {1207 stbtt_uint32 subrsoff = 0, private_loc[2] = { 0, 0 };1208 stbtt__buf pdict;2730 unmodified lines3939 {3940 return stbtt_GetFontOffsetForIndex_internal((unsigned char *) data, index); 3941 }3942 3943+STBTT_DEF int stbtt_GetNumberOfFonts(const unsigned char *data)3944+{3945+ return stbtt_GetNumberOfFonts_internal((unsigned char *) data);3946+}3947+3948 STBTT_DEF int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data, int offset)3949 {3950 return stbtt_InitFont_internal(info, (unsigned char *) data, offset);3951 }67 unmodified lines