mirror of
https://github.com/nothings/stb
synced 2025-01-05 22:34:23 +03:00
Merge branch 'num-fonts' of https://github.com/IntellectualKitty/stb into working
Conflicts: stb_truetype.h
This commit is contained in:
commit
4f2324c6ad
@ -25,6 +25,7 @@
|
|||||||
// Misc other:
|
// Misc other:
|
||||||
// Ryan Gordon
|
// Ryan Gordon
|
||||||
// Simon Glass
|
// Simon Glass
|
||||||
|
// github:IntellectualKitty
|
||||||
//
|
//
|
||||||
// Bug/warning reports/fixes:
|
// Bug/warning reports/fixes:
|
||||||
// "Zer" on mollyrocket (with fix)
|
// "Zer" on mollyrocket (with fix)
|
||||||
@ -49,11 +50,10 @@
|
|||||||
// Higor Euripedes
|
// Higor Euripedes
|
||||||
// Thomas Fields
|
// Thomas Fields
|
||||||
// Derek Vinyard
|
// Derek Vinyard
|
||||||
// github:IntellectualKitty
|
|
||||||
//
|
//
|
||||||
// VERSION HISTORY
|
// VERSION HISTORY
|
||||||
//
|
//
|
||||||
// 1.13 (2017-01-02) support OpenType fonts, certain Apple fonts,
|
// 1.13 (2017-01-02) support OpenType fonts, certain Apple fonts, num-fonts-in-TTC function
|
||||||
// 1.12 (2016-10-25) suppress warnings about casting away const with -Wcast-qual
|
// 1.12 (2016-10-25) suppress warnings about casting away const with -Wcast-qual
|
||||||
// 1.11 (2016-04-02) fix unused-variable warning
|
// 1.11 (2016-04-02) fix unused-variable warning
|
||||||
// 1.10 (2016-04-02) user-defined fabs(); rare memory leak; remove duplicate typedef
|
// 1.10 (2016-04-02) user-defined fabs(); rare memory leak; remove duplicate typedef
|
||||||
@ -98,7 +98,8 @@
|
|||||||
//
|
//
|
||||||
// "Load" a font file from a memory buffer (you have to keep the buffer loaded)
|
// "Load" a font file from a memory buffer (you have to keep the buffer loaded)
|
||||||
// stbtt_InitFont()
|
// stbtt_InitFont()
|
||||||
// stbtt_GetFontOffsetForIndex() -- use for TTC font collections
|
// stbtt_GetFontOffsetForIndex() -- indexing for TTC font collections
|
||||||
|
// stbtt_GetNumberOfFonts() -- number of fonts for TTC font collections
|
||||||
//
|
//
|
||||||
// Render a unicode codepoint to a bitmap
|
// Render a unicode codepoint to a bitmap
|
||||||
// stbtt_GetCodepointBitmap() -- allocates and returns a bitmap
|
// stbtt_GetCodepointBitmap() -- allocates and returns a bitmap
|
||||||
@ -632,14 +633,19 @@ struct stbtt_pack_context {
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
|
||||||
|
STBTT_DEF int stbtt_GetNumberOfFonts(const unsigned char *data);
|
||||||
|
// This function will determine the number of fonts in a font file. TrueType
|
||||||
|
// collection (.ttc) files may contain multiple fonts, while TrueType font
|
||||||
|
// (.ttf) files only contain one font. The number of fonts can be used for
|
||||||
|
// indexing with the previous function where the index is between zero and one
|
||||||
|
// less than the total fonts. If an error occurs, -1 is returned.
|
||||||
|
|
||||||
STBTT_DEF int stbtt_GetFontOffsetForIndex(const unsigned char *data, int index);
|
STBTT_DEF int stbtt_GetFontOffsetForIndex(const unsigned char *data, int index);
|
||||||
// Each .ttf/.ttc file may have more than one font. Each font has a sequential
|
// Each .ttf/.ttc file may have more than one font. Each font has a sequential
|
||||||
// index number starting from 0. Call this function to get the font offset for
|
// index number starting from 0. Call this function to get the font offset for
|
||||||
// a given index; it returns -1 if the index is out of range. A regular .ttf
|
// a given index; it returns -1 if the index is out of range. A regular .ttf
|
||||||
// file will only define one font and it always be at offset 0, so it will
|
// file will only define one font and it always be at offset 0, so it will
|
||||||
// return '0' for index 0, and -1 for all other indices. You can just skip
|
// return '0' for index 0, and -1 for all other indices.
|
||||||
// this step if you know it's that kind of font.
|
|
||||||
|
|
||||||
|
|
||||||
// The following structure is defined publically so you can declare one on
|
// The following structure is defined publically so you can declare one on
|
||||||
// the stack or as a global or etc, but you should treat it as opaque.
|
// the stack or as a global or etc, but you should treat it as opaque.
|
||||||
@ -1180,6 +1186,22 @@ static int stbtt_GetFontOffsetForIndex_internal(unsigned char *font_collection,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int stbtt_GetNumberOfFonts_internal(unsigned char *font_collection)
|
||||||
|
{
|
||||||
|
// if it's just a font, there's only one valid font
|
||||||
|
if (stbtt__isfont(font_collection))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
// check if it's a TTC
|
||||||
|
if (stbtt_tag(font_collection, "ttcf")) {
|
||||||
|
// version 1?
|
||||||
|
if (ttULONG(font_collection+4) == 0x00010000 || ttULONG(font_collection+4) == 0x00020000) {
|
||||||
|
return ttLONG(font_collection+8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static stbtt__buf stbtt__get_subrs(stbtt__buf cff, stbtt__buf fontdict)
|
static stbtt__buf stbtt__get_subrs(stbtt__buf cff, stbtt__buf fontdict)
|
||||||
{
|
{
|
||||||
stbtt_uint32 subrsoff = 0, private_loc[2] = { 0, 0 };
|
stbtt_uint32 subrsoff = 0, private_loc[2] = { 0, 0 };
|
||||||
@ -3918,6 +3940,11 @@ STBTT_DEF int stbtt_GetFontOffsetForIndex(const unsigned char *data, int index)
|
|||||||
return stbtt_GetFontOffsetForIndex_internal((unsigned char *) data, index);
|
return stbtt_GetFontOffsetForIndex_internal((unsigned char *) data, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
STBTT_DEF int stbtt_GetNumberOfFonts(const unsigned char *data)
|
||||||
|
{
|
||||||
|
return stbtt_GetNumberOfFonts_internal((unsigned char *) data);
|
||||||
|
}
|
||||||
|
|
||||||
STBTT_DEF int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data, int offset)
|
STBTT_DEF int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data, int offset)
|
||||||
{
|
{
|
||||||
return stbtt_InitFont_internal(info, (unsigned char *) data, offset);
|
return stbtt_InitFont_internal(info, (unsigned char *) data, offset);
|
||||||
|
Loading…
Reference in New Issue
Block a user