From 26439254e81b8a27f84fca911820f4a8ca1f6a02 Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Wed, 10 Dec 2014 00:27:11 -0800 Subject: [PATCH] fix use of stbrp_coord if no stb_rect_pack; fix a few assert()s that weren't STBTT_asserts(); fix missing cast for C++ fix typo in C++ test compilation that prevented it from trying to compile stb_truetype --- stb_truetype.h | 15 +++++++++------ tests/stretch_test.c | 4 ++++ tests/test_cpp_compilation.cpp | 4 ++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/stb_truetype.h b/stb_truetype.h index b1c22c9..2cf598f 100644 --- a/stb_truetype.h +++ b/stb_truetype.h @@ -2062,6 +2062,8 @@ void stbtt_GetBakedQuad(stbtt_bakedchar *chardata, int pw, int ph, int char_inde #define STBTT__NOTUSED(v) (void)sizeof(v) #endif +typedef int stbrp_coord; + //////////////////////////////////////////////////////////////////////////////////// // // // // @@ -2086,7 +2088,8 @@ typedef struct typedef struct { - int id,w,h,x,y,was_packed; + stbrp_coord x,y; + int id,w,h,was_packed; } stbrp_rect; static void stbrp_init_target(stbrp_context *con, int pw, int ph, stbrp_node *nodes, int num_nodes) @@ -2167,8 +2170,8 @@ void stbtt_PackEnd (stbtt_pack_context *spc) void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h_oversample, unsigned int v_oversample) { - assert(h_oversample <= STBTT_MAX_OVERSAMPLE); - assert(v_oversample <= STBTT_MAX_OVERSAMPLE); + STBTT_assert(h_oversample <= STBTT_MAX_OVERSAMPLE); + STBTT_assert(v_oversample <= STBTT_MAX_OVERSAMPLE); if (h_oversample <= STBTT_MAX_OVERSAMPLE) spc->h_oversample = h_oversample; if (v_oversample <= STBTT_MAX_OVERSAMPLE) @@ -2222,7 +2225,7 @@ static void stbtt__h_prefilter(unsigned char *pixels, int w, int h, int stride_i } for (; i < w; ++i) { - assert(pixels[i] == 0); + STBTT_assert(pixels[i] == 0); total -= buffer[i & STBTT__OVER_MASK]; pixels[i] = (unsigned char) (total / kernel_width); } @@ -2276,7 +2279,7 @@ static void stbtt__v_prefilter(unsigned char *pixels, int w, int h, int stride_i } for (; i < h; ++i) { - assert(pixels[i*stride_in_bytes] == 0); + STBTT_assert(pixels[i*stride_in_bytes] == 0); total -= buffer[i & STBTT__OVER_MASK]; pixels[i*stride_in_bytes] = (unsigned char) (total / kernel_width); } @@ -2320,7 +2323,7 @@ int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontdata, int f for (i=0; i < num_ranges; ++i) n += ranges[i].num_chars_in_range; - rects = STBTT_malloc(sizeof(*rects) * n, spc->user_allocator_context); + rects = (stbrp_rect *) STBTT_malloc(sizeof(*rects) * n, spc->user_allocator_context); if (rects == NULL) return 0; diff --git a/tests/stretch_test.c b/tests/stretch_test.c index 2c097bd..8caf43f 100644 --- a/tests/stretch_test.c +++ b/tests/stretch_test.c @@ -1,3 +1,7 @@ +// check that stb_truetype compiles with no stb_rect_pack.h +#define STB_TRUETYPE_IMPLEMENTATION +#include "stb_truetype.h" + #include "stretchy_buffer.h" #include diff --git a/tests/test_cpp_compilation.cpp b/tests/test_cpp_compilation.cpp index 20a2eb7..bc31a76 100644 --- a/tests/test_cpp_compilation.cpp +++ b/tests/test_cpp_compilation.cpp @@ -1,4 +1,4 @@ -#define STB_TRUETYPE_IMPLEMENTATIOn +#define STB_TRUETYPE_IMPLEMENTATION #define STB_PERLIN_IMPLEMENTATION #define STB_IMAGE_WRITE_IMPLEMENTATION #define STB_DXT_IMPLEMENATION @@ -8,6 +8,7 @@ #define STB_HERRINGBONE_WANG_TILE_IMPLEMENTATION #define STB_RECT_PACK_IMPLEMENTATION +#include "stb_rect_pack.h" #include "stb_truetype.h" #include "stb_image_write.h" #include "stb_perlin.h" @@ -16,7 +17,6 @@ #include "stb_divide.h" #include "stb_image.h" #include "stb_herringbone_wang_tile.h" -#include "stb_rect_pack.h" #define STBTE_DRAW_RECT(x0,y0,x1,y1,color) do ; while(0) #define STBTE_DRAW_TILE(x,y,id,highlight,data) do ; while(0)