fix -Wcast-qual in stb_rect_pack, stb_textedit, stb_truetype
This commit is contained in:
parent
2f4166e91d
commit
5d9423f8fd
@ -510,8 +510,8 @@ static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, i
|
||||
|
||||
static int rect_height_compare(const void *a, const void *b)
|
||||
{
|
||||
stbrp_rect *p = (stbrp_rect *) a;
|
||||
stbrp_rect *q = (stbrp_rect *) b;
|
||||
const stbrp_rect *p = (const stbrp_rect *) a;
|
||||
const stbrp_rect *q = (const stbrp_rect *) b;
|
||||
if (p->h > q->h)
|
||||
return -1;
|
||||
if (p->h < q->h)
|
||||
@ -521,8 +521,8 @@ static int rect_height_compare(const void *a, const void *b)
|
||||
|
||||
static int rect_width_compare(const void *a, const void *b)
|
||||
{
|
||||
stbrp_rect *p = (stbrp_rect *) a;
|
||||
stbrp_rect *q = (stbrp_rect *) b;
|
||||
const stbrp_rect *p = (const stbrp_rect *) a;
|
||||
const stbrp_rect *q = (const stbrp_rect *) b;
|
||||
if (p->w > q->w)
|
||||
return -1;
|
||||
if (p->w < q->w)
|
||||
@ -532,8 +532,8 @@ static int rect_width_compare(const void *a, const void *b)
|
||||
|
||||
static int rect_original_order(const void *a, const void *b)
|
||||
{
|
||||
stbrp_rect *p = (stbrp_rect *) a;
|
||||
stbrp_rect *q = (stbrp_rect *) b;
|
||||
const stbrp_rect *p = (const stbrp_rect *) a;
|
||||
const stbrp_rect *q = (const stbrp_rect *) b;
|
||||
return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed);
|
||||
}
|
||||
|
||||
|
@ -671,9 +671,8 @@ static int stb_textedit_cut(STB_TEXTEDIT_STRING *str, STB_TexteditState *state)
|
||||
}
|
||||
|
||||
// API paste: replace existing selection with passed-in text
|
||||
static int stb_textedit_paste(STB_TEXTEDIT_STRING *str, STB_TexteditState *state, STB_TEXTEDIT_CHARTYPE const *ctext, int len)
|
||||
static int stb_textedit_paste_internal(STB_TEXTEDIT_STRING *str, STB_TexteditState *state, STB_TEXTEDIT_CHARTYPE *text, int len)
|
||||
{
|
||||
STB_TEXTEDIT_CHARTYPE *text = (STB_TEXTEDIT_CHARTYPE *) ctext;
|
||||
// if there's a selection, the paste should delete it
|
||||
stb_textedit_clamp(str, state);
|
||||
stb_textedit_delete_selection(str,state);
|
||||
@ -1312,4 +1311,19 @@ static void stb_textedit_initialize_state(STB_TexteditState *state, int is_singl
|
||||
{
|
||||
stb_textedit_clear_state(state, is_single_line);
|
||||
}
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wcast-qual"
|
||||
#endif
|
||||
|
||||
static int stb_textedit_paste(STB_TEXTEDIT_STRING *str, STB_TexteditState *state, STB_TEXTEDIT_CHARTYPE const *ctext, int len)
|
||||
{
|
||||
return stb_textedit_paste_internal(str, state, (STB_TEXTEDIT_CHARTYPE *) ctext, len);
|
||||
}
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
#endif//STB_TEXTEDIT_IMPLEMENTATION
|
||||
|
@ -593,9 +593,9 @@ STBTT_DEF void stbtt_GetPackedQuad(stbtt_packedchar *chardata, int pw, int ph,
|
||||
stbtt_aligned_quad *q, // output: quad to draw
|
||||
int align_to_integer);
|
||||
|
||||
STBTT_DEF int stbtt_PackFontRangesGatherRects(stbtt_pack_context *spc, stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects);
|
||||
STBTT_DEF int stbtt_PackFontRangesGatherRects(stbtt_pack_context *spc, const stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects);
|
||||
STBTT_DEF void stbtt_PackFontRangesPackRects(stbtt_pack_context *spc, stbrp_rect *rects, int num_rects);
|
||||
STBTT_DEF int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context *spc, stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects);
|
||||
STBTT_DEF int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context *spc, const stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects);
|
||||
// Calling these functions in sequence is roughly equivalent to calling
|
||||
// stbtt_PackFontRanges(). If you more control over the packing of multiple
|
||||
// fonts, or if you want to pack custom data into a font texture, take a look
|
||||
@ -968,26 +968,15 @@ typedef int stbtt__test_oversample_pow2[(STBTT_MAX_OVERSAMPLE & (STBTT_MAX_OVERS
|
||||
#define ttCHAR(p) (* (stbtt_int8 *) (p))
|
||||
#define ttFixed(p) ttLONG(p)
|
||||
|
||||
#if defined(STB_TRUETYPE_BIGENDIAN) && !defined(ALLOW_UNALIGNED_TRUETYPE)
|
||||
|
||||
#define ttUSHORT(p) (* (stbtt_uint16 *) (p))
|
||||
#define ttSHORT(p) (* (stbtt_int16 *) (p))
|
||||
#define ttULONG(p) (* (stbtt_uint32 *) (p))
|
||||
#define ttLONG(p) (* (stbtt_int32 *) (p))
|
||||
|
||||
#else
|
||||
|
||||
static stbtt_uint16 ttUSHORT(const stbtt_uint8 *p) { return p[0]*256 + p[1]; }
|
||||
static stbtt_int16 ttSHORT(const stbtt_uint8 *p) { return p[0]*256 + p[1]; }
|
||||
static stbtt_uint32 ttULONG(const stbtt_uint8 *p) { return (p[0]<<24) + (p[1]<<16) + (p[2]<<8) + p[3]; }
|
||||
static stbtt_int32 ttLONG(const stbtt_uint8 *p) { return (p[0]<<24) + (p[1]<<16) + (p[2]<<8) + p[3]; }
|
||||
|
||||
#endif
|
||||
static stbtt_uint16 ttUSHORT(stbtt_uint8 *p) { return p[0]*256 + p[1]; }
|
||||
static stbtt_int16 ttSHORT(stbtt_uint8 *p) { return p[0]*256 + p[1]; }
|
||||
static stbtt_uint32 ttULONG(stbtt_uint8 *p) { return (p[0]<<24) + (p[1]<<16) + (p[2]<<8) + p[3]; }
|
||||
static stbtt_int32 ttLONG(stbtt_uint8 *p) { return (p[0]<<24) + (p[1]<<16) + (p[2]<<8) + p[3]; }
|
||||
|
||||
#define stbtt_tag4(p,c0,c1,c2,c3) ((p)[0] == (c0) && (p)[1] == (c1) && (p)[2] == (c2) && (p)[3] == (c3))
|
||||
#define stbtt_tag(p,str) stbtt_tag4(p,str[0],str[1],str[2],str[3])
|
||||
|
||||
static int stbtt__isfont(const stbtt_uint8 *font)
|
||||
static int stbtt__isfont(stbtt_uint8 *font)
|
||||
{
|
||||
// check the version number
|
||||
if (stbtt_tag4(font, '1',0,0,0)) return 1; // TrueType 1
|
||||
@ -1011,7 +1000,7 @@ static stbtt_uint32 stbtt__find_table(stbtt_uint8 *data, stbtt_uint32 fontstart,
|
||||
return 0;
|
||||
}
|
||||
|
||||
STBTT_DEF int stbtt_GetFontOffsetForIndex(const unsigned char *font_collection, int index)
|
||||
static int stbtt_GetFontOffsetForIndex_internal(unsigned char *font_collection, int index)
|
||||
{
|
||||
// if it's just a font, there's only one valid index
|
||||
if (stbtt__isfont(font_collection))
|
||||
@ -1030,9 +1019,8 @@ STBTT_DEF int stbtt_GetFontOffsetForIndex(const unsigned char *font_collection,
|
||||
return -1;
|
||||
}
|
||||
|
||||
STBTT_DEF int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data2, int fontstart)
|
||||
static int stbtt_InitFont_internal(stbtt_fontinfo *info, unsigned char *data, int fontstart)
|
||||
{
|
||||
stbtt_uint8 *data = (stbtt_uint8 *) data2;
|
||||
stbtt_uint32 cmap, t;
|
||||
stbtt_int32 i,numTables;
|
||||
|
||||
@ -2532,7 +2520,7 @@ STBTT_DEF void stbtt_MakeCodepointBitmap(const stbtt_fontinfo *info, unsigned ch
|
||||
//
|
||||
// This is SUPER-CRAPPY packing to keep source code small
|
||||
|
||||
STBTT_DEF int stbtt_BakeFontBitmap(const unsigned char *data, int offset, // font location (use offset=0 for plain .ttf)
|
||||
static int stbtt_BakeFontBitmap_internal(unsigned char *data, int offset, // font location (use offset=0 for plain .ttf)
|
||||
float pixel_height, // height of font in pixels
|
||||
unsigned char *pixels, int pw, int ph, // bitmap to be filled in
|
||||
int first_char, int num_chars, // characters to bake
|
||||
@ -2862,7 +2850,7 @@ static float stbtt__oversample_shift(int oversample)
|
||||
}
|
||||
|
||||
// rects array must be big enough to accommodate all characters in the given ranges
|
||||
STBTT_DEF int stbtt_PackFontRangesGatherRects(stbtt_pack_context *spc, stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects)
|
||||
STBTT_DEF int stbtt_PackFontRangesGatherRects(stbtt_pack_context *spc, const stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects)
|
||||
{
|
||||
int i,j,k;
|
||||
|
||||
@ -2891,7 +2879,7 @@ STBTT_DEF int stbtt_PackFontRangesGatherRects(stbtt_pack_context *spc, stbtt_fon
|
||||
}
|
||||
|
||||
// rects array must be big enough to accommodate all characters in the given ranges
|
||||
STBTT_DEF int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context *spc, stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects)
|
||||
STBTT_DEF int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context *spc, const stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects)
|
||||
{
|
||||
int i,j,k, return_value = 1;
|
||||
|
||||
@ -3060,7 +3048,7 @@ STBTT_DEF void stbtt_GetPackedQuad(stbtt_packedchar *chardata, int pw, int ph, i
|
||||
//
|
||||
|
||||
// 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(const stbtt_uint8 *s1, stbtt_int32 len1, const stbtt_uint8 *s2, stbtt_int32 len2)
|
||||
static stbtt_int32 stbtt__CompareUTF8toUTF16_bigendian_prefix(stbtt_uint8 *s1, stbtt_int32 len1, stbtt_uint8 *s2, stbtt_int32 len2)
|
||||
{
|
||||
stbtt_int32 i=0;
|
||||
|
||||
@ -3099,9 +3087,9 @@ static stbtt_int32 stbtt__CompareUTF8toUTF16_bigendian_prefix(const stbtt_uint8
|
||||
return i;
|
||||
}
|
||||
|
||||
STBTT_DEF int stbtt_CompareUTF8toUTF16_bigendian(const char *s1, int len1, const char *s2, int len2)
|
||||
static int stbtt_CompareUTF8toUTF16_bigendian_internal(char *s1, int len1, char *s2, int len2)
|
||||
{
|
||||
return len1 == stbtt__CompareUTF8toUTF16_bigendian_prefix((const stbtt_uint8*) s1, len1, (const stbtt_uint8*) s2, len2);
|
||||
return len1 == stbtt__CompareUTF8toUTF16_bigendian_prefix((stbtt_uint8*) s1, len1, (stbtt_uint8*) s2, len2);
|
||||
}
|
||||
|
||||
// returns results in whatever encoding you request... but note that 2-byte encodings
|
||||
@ -3157,7 +3145,7 @@ static int stbtt__matchpair(stbtt_uint8 *fc, stbtt_uint32 nm, stbtt_uint8 *name,
|
||||
return 1;
|
||||
} else if (matchlen < nlen && name[matchlen] == ' ') {
|
||||
++matchlen;
|
||||
if (stbtt_CompareUTF8toUTF16_bigendian((char*) (name+matchlen), nlen-matchlen, (char*)(fc+stringOffset+off),slen))
|
||||
if (stbtt_CompareUTF8toUTF16_bigendian_internal((char*) (name+matchlen), nlen-matchlen, (char*)(fc+stringOffset+off),slen))
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
@ -3203,7 +3191,7 @@ static int stbtt__matches(stbtt_uint8 *fc, stbtt_uint32 offset, stbtt_uint8 *nam
|
||||
return 0;
|
||||
}
|
||||
|
||||
STBTT_DEF int stbtt_FindMatchingFont(const unsigned char *font_collection, const char *name_utf8, stbtt_int32 flags)
|
||||
static int stbtt_FindMatchingFont_internal(unsigned char *font_collection, char *name_utf8, stbtt_int32 flags)
|
||||
{
|
||||
stbtt_int32 i;
|
||||
for (i=0;;++i) {
|
||||
@ -3214,6 +3202,42 @@ STBTT_DEF int stbtt_FindMatchingFont(const unsigned char *font_collection, const
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wcast-qual"
|
||||
#endif
|
||||
|
||||
STBTT_DEF int stbtt_BakeFontBitmap(const unsigned char *data, int offset,
|
||||
float pixel_height, unsigned char *pixels, int pw, int ph,
|
||||
int first_char, int num_chars, stbtt_bakedchar *chardata)
|
||||
{
|
||||
return stbtt_BakeFontBitmap_internal((unsigned char *) data, offset, pixel_height, pixels, pw, ph, first_char, num_chars, chardata);
|
||||
}
|
||||
|
||||
STBTT_DEF int stbtt_GetFontOffsetForIndex(const unsigned char *data, int index)
|
||||
{
|
||||
return stbtt_GetFontOffsetForIndex_internal((unsigned char *) data, index);
|
||||
}
|
||||
|
||||
STBTT_DEF int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data, int offset)
|
||||
{
|
||||
return stbtt_InitFont_internal(info, (unsigned char *) data, offset);
|
||||
}
|
||||
|
||||
STBTT_DEF int stbtt_FindMatchingFont(const unsigned char *fontdata, const char *name, int flags)
|
||||
{
|
||||
return stbtt_FindMatchingFont_internal((unsigned char *) fontdata, (char *) name, flags);
|
||||
}
|
||||
|
||||
STBTT_DEF int stbtt_CompareUTF8toUTF16_bigendian(const char *s1, int len1, const char *s2, int len2)
|
||||
{
|
||||
return stbtt_CompareUTF8toUTF16_bigendian_internal((char *) s1, len1, (char *) s2, len2);
|
||||
}
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
#endif // STB_TRUETYPE_IMPLEMENTATION
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user