vtgl

terminal emulator implemented in OpenGL
git clone anongit@rnpnr.xyz:vtgl.git
Log | Files | Refs | Feed | LICENSE

Commit: 0ec5ac0404faac569d1dac4f5d6a1b9d4a2ae112
Parent: a94069ef6880bb38404ea965314b0b35d9995118
Author: Randy Palamar
Date:   Tue, 10 Sep 2024 20:22:04 -0600

cleanup strlen from stb_truetype

No more linked strlen

Diffstat:
Mextern/stb_truetype.h | 92+++++++++++++++++++++++++++++++++++++++----------------------------------------
1 file changed, 45 insertions(+), 47 deletions(-)

diff --git a/extern/stb_truetype.h b/extern/stb_truetype.h @@ -313,11 +313,6 @@ #define STBTT_assert(x) ASSERT(x) - #ifndef STBTT_strlen - #include <string.h> - #define STBTT_strlen(x) strlen(x) - #endif - #ifndef STBTT_memcpy #include <string.h> #define STBTT_memcpy memcpy @@ -826,7 +821,7 @@ STBTT_DEF unsigned char * stbtt_GetGlyphSDF(Arena *a, const stbtt_fontinfo *info // You have to have called stbtt_InitFont() first. -STBTT_DEF int stbtt_FindMatchingFont(unsigned char *fontdata, char *name, int flags); +STBTT_DEF int stbtt_FindMatchingFont(unsigned char *fontdata, s8 name, int flags); // returns the offset (not index) of the font that matches, or -1 if none // if you use STBTT_MACSTYLE_DONTCARE, use a font name like "Arial Bold". // if you use any other flag, use a font name like "Arial"; this checks @@ -837,7 +832,7 @@ STBTT_DEF int stbtt_FindMatchingFont(unsigned char *fontdata, char *name, int fl #define STBTT_MACSTYLE_UNDERSCORE 4 #define STBTT_MACSTYLE_NONE 8 // <= not same as 0, this makes us check the bitfield is 0 -STBTT_DEF int stbtt_CompareUTF8toUTF16_bigendian(char *s1, int len1, char *s2, int len2); +STBTT_DEF int stbtt_CompareUTF8toUTF16_bigendian(s8 s1, s8 s2); // returns 1/0 whether the first string interpreted as utf8 is identical to // the second string interpreted as big-endian utf16... useful for strings from next func @@ -4200,48 +4195,48 @@ STBTT_DEF unsigned char *stbtt_GetGlyphSDF(Arena *a, const stbtt_fontinfo *info, // // check if a utf8 string contains a prefix which is the utf16 string; if so return length of matching utf8 string -static stbtt_int32 stbtt__CompareUTF8toUTF16_bigendian_prefix(stbtt_uint8 *s1, stbtt_int32 len1, stbtt_uint8 *s2, stbtt_int32 len2) +static stbtt_int32 stbtt__CompareUTF8toUTF16_bigendian_prefix(s8 s1, s8 s2) { stbtt_int32 i=0; // convert utf16 to utf8 and compare the results while converting - while (len2) { - stbtt_uint16 ch = s2[0]*256 + s2[1]; + while (s2.len) { + stbtt_uint16 ch = s2.data[0]*256 + s2.data[1]; if (ch < 0x80) { - if (i >= len1) return -1; - if (s1[i++] != ch) return -1; + if (i >= s1.len) return -1; + if (s1.data[i++] != ch) return -1; } else if (ch < 0x800) { - if (i+1 >= len1) return -1; - if (s1[i++] != 0xc0 + (ch >> 6)) return -1; - if (s1[i++] != 0x80 + (ch & 0x3f)) return -1; + if (i+1 >= s1.len) return -1; + if (s1.data[i++] != 0xc0 + (ch >> 6)) return -1; + if (s1.data[i++] != 0x80 + (ch & 0x3f)) return -1; } else if (ch >= 0xd800 && ch < 0xdc00) { stbtt_uint32 c; - stbtt_uint16 ch2 = s2[2]*256 + s2[3]; - if (i+3 >= len1) return -1; + stbtt_uint16 ch2 = s2.data[2]*256 + s2.data[3]; + if (i+3 >= s1.len) return -1; c = ((ch - 0xd800) << 10) + (ch2 - 0xdc00) + 0x10000; - if (s1[i++] != 0xf0 + (c >> 18)) return -1; - if (s1[i++] != 0x80 + ((c >> 12) & 0x3f)) return -1; - if (s1[i++] != 0x80 + ((c >> 6) & 0x3f)) return -1; - if (s1[i++] != 0x80 + ((c ) & 0x3f)) return -1; - s2 += 2; // plus another 2 below - len2 -= 2; + if (s1.data[i++] != 0xf0 + (c >> 18)) return -1; + if (s1.data[i++] != 0x80 + ((c >> 12) & 0x3f)) return -1; + if (s1.data[i++] != 0x80 + ((c >> 6) & 0x3f)) return -1; + if (s1.data[i++] != 0x80 + ((c ) & 0x3f)) return -1; + s2.data += 2; // plus another 2 below + s2.len -= 2; } else if (ch >= 0xdc00 && ch < 0xe000) { return -1; } else { - if (i+2 >= len1) return -1; - if (s1[i++] != 0xe0 + (ch >> 12)) return -1; - if (s1[i++] != 0x80 + ((ch >> 6) & 0x3f)) return -1; - if (s1[i++] != 0x80 + ((ch ) & 0x3f)) return -1; + if (i+2 >= s1.len) return -1; + if (s1.data[i++] != 0xe0 + (ch >> 12)) return -1; + if (s1.data[i++] != 0x80 + ((ch >> 6) & 0x3f)) return -1; + if (s1.data[i++] != 0x80 + ((ch ) & 0x3f)) return -1; } - s2 += 2; - len2 -= 2; + s2.data += 2; + s2.len -= 2; } return i; } -STBTT_DEF int stbtt_CompareUTF8toUTF16_bigendian(char *s1, int len1, char *s2, int len2) +STBTT_DEF int stbtt_CompareUTF8toUTF16_bigendian(s8 s1, s8 s2) { - return len1 == stbtt__CompareUTF8toUTF16_bigendian_prefix((stbtt_uint8*) s1, len1, (stbtt_uint8*) s2, len2); + return s1.len == stbtt__CompareUTF8toUTF16_bigendian_prefix(s1, s2); } // returns results in whatever encoding you request... but note that 2-byte encodings @@ -4267,7 +4262,7 @@ STBTT_DEF const char *stbtt_GetFontNameString(const stbtt_fontinfo *font, int *l return NULL; } -static int stbtt__matchpair(stbtt_uint8 *fc, stbtt_uint32 nm, stbtt_uint8 *name, stbtt_int32 nlen, stbtt_int32 target_id, stbtt_int32 next_id) +static int stbtt__matchpair(stbtt_uint8 *fc, stbtt_uint32 nm, s8 name, stbtt_int32 target_id, stbtt_int32 next_id) { stbtt_int32 i; stbtt_int32 count = ttUSHORT(fc+nm+2); @@ -4286,23 +4281,27 @@ static int stbtt__matchpair(stbtt_uint8 *fc, stbtt_uint32 nm, stbtt_uint8 *name, stbtt_int32 off = ttUSHORT(fc+loc+10); // check if there's a prefix match - stbtt_int32 matchlen = stbtt__CompareUTF8toUTF16_bigendian_prefix(name, nlen, fc+stringOffset+off,slen); + s8 cmp = {.len = slen, .data = fc + stringOffset + off}; + stbtt_int32 matchlen = stbtt__CompareUTF8toUTF16_bigendian_prefix(name, cmp); if (matchlen >= 0) { // check for target_id+1 immediately following, with same encoding & language if (i+1 < count && ttUSHORT(fc+loc+12+6) == next_id && ttUSHORT(fc+loc+12) == platform && ttUSHORT(fc+loc+12+2) == encoding && ttUSHORT(fc+loc+12+4) == language) { slen = ttUSHORT(fc+loc+12+8); off = ttUSHORT(fc+loc+12+10); if (slen == 0) { - if (matchlen == nlen) + if (matchlen == name.len) return 1; - } else if (matchlen < nlen && name[matchlen] == ' ') { + } else if (matchlen < name.len && name.data[matchlen] == ' ') { ++matchlen; - if (stbtt_CompareUTF8toUTF16_bigendian((char*) (name+matchlen), nlen-matchlen, (char*)(fc+stringOffset+off),slen)) + s8 n = name; + n.data += matchlen; + n.len -= matchlen; + if (stbtt_CompareUTF8toUTF16_bigendian(n, cmp)) return 1; } } else { // if nothing immediately following - if (matchlen == nlen) + if (matchlen == name.len) return 1; } } @@ -4314,9 +4313,8 @@ static int stbtt__matchpair(stbtt_uint8 *fc, stbtt_uint32 nm, stbtt_uint8 *name, return 0; } -static int stbtt__matches(stbtt_uint8 *fc, stbtt_uint32 offset, stbtt_uint8 *name, stbtt_int32 flags) +static int stbtt__matches(stbtt_uint8 *fc, stbtt_uint32 offset, s8 name, stbtt_int32 flags) { - stbtt_int32 nlen = (stbtt_int32) STBTT_strlen((char *) name); stbtt_uint32 nm,hd; if (!stbtt__isfont(fc+offset)) return 0; @@ -4331,25 +4329,25 @@ static int stbtt__matches(stbtt_uint8 *fc, stbtt_uint32 offset, stbtt_uint8 *nam if (flags) { // if we checked the macStyle flags, then just check the family and ignore the subfamily - if (stbtt__matchpair(fc, nm, name, nlen, 16, -1)) return 1; - if (stbtt__matchpair(fc, nm, name, nlen, 1, -1)) return 1; - if (stbtt__matchpair(fc, nm, name, nlen, 3, -1)) return 1; + if (stbtt__matchpair(fc, nm, name, 16, -1)) return 1; + if (stbtt__matchpair(fc, nm, name, 1, -1)) return 1; + if (stbtt__matchpair(fc, nm, name, 3, -1)) return 1; } else { - if (stbtt__matchpair(fc, nm, name, nlen, 16, 17)) return 1; - if (stbtt__matchpair(fc, nm, name, nlen, 1, 2)) return 1; - if (stbtt__matchpair(fc, nm, name, nlen, 3, -1)) return 1; + if (stbtt__matchpair(fc, nm, name, 16, 17)) return 1; + if (stbtt__matchpair(fc, nm, name, 1, 2)) return 1; + if (stbtt__matchpair(fc, nm, name, 3, -1)) return 1; } return 0; } -STBTT_DEF int stbtt_FindMatchingFont(unsigned char *font_collection, char *name_utf8, stbtt_int32 flags) +STBTT_DEF int stbtt_FindMatchingFont(unsigned char *font_collection, s8 name_utf8, stbtt_int32 flags) { stbtt_int32 i; for (i=0;;++i) { stbtt_int32 off = stbtt_GetFontOffsetForIndex(font_collection, i); if (off < 0) return off; - if (stbtt__matches((stbtt_uint8 *) font_collection, off, (stbtt_uint8*) name_utf8, flags)) + if (stbtt__matches((stbtt_uint8 *) font_collection, off, name_utf8, flags)) return off; } }