Commit: a94069ef6880bb38404ea965314b0b35d9995118
Parent: 9cb3db74548335e838c72cc0f9cca44a0514ed9f
Author: Randy Palamar
Date: Tue, 10 Sep 2024 19:59:59 -0600
remove remaining stb_truetype malloc/free references
malloc and free are no longer linked into our program (check objdump -T).
Diffstat:
2 files changed, 30 insertions(+), 275 deletions(-)
diff --git a/build.sh b/build.sh
@@ -18,9 +18,6 @@ if [ $debug ]; then
cflags="$cflags -D_DEBUG -Wno-unused-function -Wno-undefined-internal"
#cflags="$cflags -fsanitize=address,undefined"
- # NOTE: determine which stb_truetype functions are calling malloc/free
- #cflags="$cflags -DTRACK_MALLOC"
-
libcflags="$cflags -ggdb -O0 -fPIC"
libldflags="$ldflags -shared"
diff --git a/extern/stb_truetype.h b/extern/stb_truetype.h
@@ -133,7 +133,7 @@
// where multiple shapes overlap, in which case it overestimates the AA pixel
// coverage. Thus, anti-aliasing of intersecting shapes may look wrong. If
// this turns out to be a problem, you can re-enable the old rasterizer with
-// #define STBTT_RASTERIZER_VERSION 1
+// #define STBTT_RASTERIZER_VERSION 1 (removed)
// which will incur about a 15% speed hit.
//
// ADDITIONAL DOCUMENTATION
@@ -311,16 +311,6 @@
#define STBTT_fabs(x) fabs(x)
#endif
- // #define your own functions "STBTT_malloc" / "STBTT_free" to avoid malloc.h
- #include <stdlib.h>
- #ifdef TRACK_MALLOC
- #define STBTT_malloc(x, u) (fprintf(stderr, "calling malloc: %s\n", __FUNCTION__), (void)(u),malloc(x))
- #define STBTT_free(x, u) (fprintf(stderr, "calling free: %s\n", __FUNCTION__), (void)(u),free(x))
- #else
- #define STBTT_malloc(x, u) ((void)(u),malloc(x))
- #define STBTT_free(x, u) ((void)(u),free(x))
- #endif
-
#define STBTT_assert(x) ASSERT(x)
#ifndef STBTT_strlen
@@ -431,7 +421,8 @@ typedef struct stbtt_fontinfo stbtt_fontinfo;
typedef struct stbrp_rect stbrp_rect;
#endif
-STBTT_DEF int stbtt_PackBegin(stbtt_pack_context *spc, unsigned char *pixels, int width, int height, int stride_in_bytes, int padding, void *alloc_context);
+STBTT_DEF int stbtt_PackBegin(Arena *a, stbtt_pack_context *spc, unsigned char *pixels,
+ int width, int height, int stride_in_bytes, int padding);
// Initializes a packing context stored in the passed-in stbtt_pack_context.
// Future calls using this context will pack characters into the bitmap passed
// in here: a 1-channel bitmap that is width * height. stride_in_bytes is
@@ -442,9 +433,6 @@ STBTT_DEF int stbtt_PackBegin(stbtt_pack_context *spc, unsigned char *pixels, i
//
// Returns 0 on failure, 1 on success.
-STBTT_DEF void stbtt_PackEnd (stbtt_pack_context *spc);
-// Cleans up the packing context and frees all memory.
-
#define STBTT_POINT_SIZE(x) (-(x))
STBTT_DEF int stbtt_PackFontRange(Arena a, stbtt_pack_context *spc, unsigned char *fontdata,
@@ -524,7 +512,6 @@ STBTT_DEF int stbtt_PackFontRangesRenderIntoRects(Arena a, stbtt_pack_context *
// this is an opaque structure that you shouldn't mess with which holds
// all the context needed from PackBegin to PackEnd.
struct stbtt_pack_context {
- void *user_allocator_context;
void *pack_info;
int width;
int height;
@@ -560,7 +547,6 @@ STBTT_DEF int stbtt_GetFontOffsetForIndex(unsigned char *data, int index);
// the stack or as a global or etc, but you should treat it as opaque.
struct stbtt_fontinfo
{
- void * userdata;
unsigned char * data; // pointer to .ttf file
int fontstart; // offset of start of font
@@ -697,9 +683,6 @@ STBTT_DEF int stbtt_GetGlyphShape(Arena *a, const stbtt_fontinfo *info, int glyp
// draws a quadratic bezier from previous endpoint to
// its x,y, using cx,cy as the bezier control point.
-STBTT_DEF void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *vertices);
-// frees the data allocated above
-
STBTT_DEF unsigned char *stbtt_FindSVGDoc(const stbtt_fontinfo *info, int gl);
STBTT_DEF int stbtt_GetGlyphSVG(const stbtt_fontinfo *info, int gl, const char **svg);
// fills svg with the character's SVG data.
@@ -762,16 +745,12 @@ STBTT_DEF void stbtt_Rasterize(Arena a, stbtt__bitmap *result, // 1-chann
float scale_x, float scale_y, // scale applied to input vertices
float shift_x, float shift_y, // translation applied to input vertices
int x_off, int y_off, // another translation applied to input
- int invert, // if non-zero, vertically flip shape
- void *userdata); // context for to STBTT_MALLOC
+ int invert); // if non-zero, vertically flip shape
//////////////////////////////////////////////////////////////////////////////
//
// Signed Distance Function (or Field) rendering
-STBTT_DEF void stbtt_FreeSDF(unsigned char *bitmap, void *userdata);
-// frees the SDF bitmap allocated below
-
STBTT_DEF unsigned char * stbtt_GetGlyphSDF(Arena *a, const stbtt_fontinfo *info, float scale,
int glyph, int padding, unsigned char onedge_value,
float pixel_dist_scale, int *width, int *height,
@@ -1683,17 +1662,10 @@ static int stbtt__GetGlyphShapeTT(Arena *a, const stbtt_fontinfo *info, int glyp
v->cy = (stbtt_vertex_type)(n * (mtx[1]*x + mtx[3]*y + mtx[5]));
}
// Append vertices.
- tmp = (stbtt_vertex*)STBTT_malloc((num_vertices+comp_num_verts)*sizeof(stbtt_vertex), info->userdata);
- if (!tmp) {
- if (vertices) STBTT_free(vertices, info->userdata);
- if (comp_verts) STBTT_free(comp_verts, info->userdata);
- return 0;
- }
+ tmp = alloc(a, stbtt_vertex, num_vertices + comp_num_verts);
if (num_vertices > 0 && vertices) STBTT_memcpy(tmp, vertices, num_vertices*sizeof(stbtt_vertex));
STBTT_memcpy(tmp+num_vertices, comp_verts, comp_num_verts*sizeof(stbtt_vertex));
- if (vertices) STBTT_free(vertices, info->userdata);
vertices = tmp;
- STBTT_free(comp_verts, info->userdata);
num_vertices += comp_num_verts;
}
// More components ?
@@ -2079,13 +2051,13 @@ static int stbtt__run_charstring(const stbtt_fontinfo *info, int glyph_index, st
#undef STBTT__CSERR
}
-static int stbtt__GetGlyphShapeT2(const stbtt_fontinfo *info, int glyph_index, stbtt_vertex **pvertices)
+static int stbtt__GetGlyphShapeT2(Arena *a, const stbtt_fontinfo *info, int glyph_index, stbtt_vertex **pvertices)
{
// runs the charstring twice, once to count and once to output (to avoid realloc)
stbtt__csctx count_ctx = STBTT__CSCTX_INIT(1);
stbtt__csctx output_ctx = STBTT__CSCTX_INIT(0);
if (stbtt__run_charstring(info, glyph_index, &count_ctx)) {
- *pvertices = (stbtt_vertex*)STBTT_malloc(count_ctx.num_vertices*sizeof(stbtt_vertex), info->userdata);
+ *pvertices = alloc(a, stbtt_vertex, count_ctx.num_vertices);
output_ctx.pvertices = *pvertices;
if (stbtt__run_charstring(info, glyph_index, &output_ctx)) {
STBTT_assert(output_ctx.num_vertices == count_ctx.num_vertices);
@@ -2109,10 +2081,8 @@ static int stbtt__GetGlyphInfoT2(const stbtt_fontinfo *info, int glyph_index, in
STBTT_DEF int stbtt_GetGlyphShape(Arena *a, const stbtt_fontinfo *info, int glyph_index, stbtt_vertex **pvertices)
{
- if (!info->cff.size)
- return stbtt__GetGlyphShapeTT(a, info, glyph_index, pvertices);
- else
- return stbtt__GetGlyphShapeT2(info, glyph_index, pvertices);
+ if (!info->cff.size) return stbtt__GetGlyphShapeTT(a, info, glyph_index, pvertices);
+ else return stbtt__GetGlyphShapeT2(a, info, glyph_index, pvertices);
}
STBTT_DEF void stbtt_GetGlyphHMetrics(const stbtt_fontinfo *info, int glyph_index, int *advanceWidth, int *leftSideBearing)
@@ -2470,11 +2440,6 @@ STBTT_DEF float stbtt_ScaleForMappingEmToPixels(const stbtt_fontinfo *info, floa
return pixels / unitsPerEm;
}
-STBTT_DEF void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *v)
-{
- STBTT_free(v, info->userdata);
-}
-
STBTT_DEF stbtt_uint8 *stbtt_FindSVGDoc(const stbtt_fontinfo *info, int gl)
{
int i;
@@ -2587,11 +2552,7 @@ typedef struct stbtt__edge {
typedef struct stbtt__active_edge
{
struct stbtt__active_edge *next;
- #if STBTT_RASTERIZER_VERSION==1
- int x,dx;
- float ey;
- int direction;
- #elif STBTT_RASTERIZER_VERSION==2
+ #if STBTT_RASTERIZER_VERSION == 2
float fx,fdx,fdy;
float direction;
float sy;
@@ -2601,33 +2562,7 @@ typedef struct stbtt__active_edge
#endif
} stbtt__active_edge;
-#if STBTT_RASTERIZER_VERSION == 1
-#define STBTT_FIXSHIFT 10
-#define STBTT_FIX (1 << STBTT_FIXSHIFT)
-#define STBTT_FIXMASK (STBTT_FIX-1)
-
-static stbtt__active_edge *stbtt__new_active(stbtt__hheap *hh, stbtt__edge *e, int off_x, float start_point, void *userdata)
-{
- stbtt__active_edge *z = (stbtt__active_edge *) stbtt__hheap_alloc(hh, sizeof(*z), userdata);
- float dxdy = (e->x1 - e->x0) / (e->y1 - e->y0);
- STBTT_assert(z != NULL);
- if (!z) return z;
-
- // round dx down to avoid overshooting
- if (dxdy < 0)
- z->dx = -STBTT_ifloor(STBTT_FIX * -dxdy);
- else
- z->dx = STBTT_ifloor(STBTT_FIX * dxdy);
-
- z->x = STBTT_ifloor(STBTT_FIX * e->x0 + z->dx * (start_point - e->y0)); // use z->dx so when we offset later it's by the same amount
- z->x -= off_x * STBTT_FIX;
-
- z->ey = e->y1;
- z->next = 0;
- z->direction = e->invert ? 1 : -1;
- return z;
-}
-#elif STBTT_RASTERIZER_VERSION == 2
+#if STBTT_RASTERIZER_VERSION == 2
static stbtt__active_edge *stbtt__new_active(Arena *a, stbtt__hheap *hh, stbtt__edge *e, int off_x, float start_point)
{
stbtt__active_edge *z = (stbtt__active_edge *) stbtt__hheap_alloc(a, hh, sizeof(*z));
@@ -2645,155 +2580,6 @@ static stbtt__active_edge *stbtt__new_active(Arena *a, stbtt__hheap *hh, stbtt__
z->next = 0;
return z;
}
-#else
-#error "Unrecognized value of STBTT_RASTERIZER_VERSION"
-#endif
-
-#if STBTT_RASTERIZER_VERSION == 1
-// note: this routine clips fills that extend off the edges... ideally this
-// wouldn't happen, but it could happen if the truetype glyph bounding boxes
-// are wrong, or if the user supplies a too-small bitmap
-static void stbtt__fill_active_edges(unsigned char *scanline, int len, stbtt__active_edge *e, int max_weight)
-{
- // non-zero winding fill
- int x0=0, w=0;
-
- while (e) {
- if (w == 0) {
- // if we're currently at zero, we need to record the edge start point
- x0 = e->x; w += e->direction;
- } else {
- int x1 = e->x; w += e->direction;
- // if we went to zero, we need to draw
- if (w == 0) {
- int i = x0 >> STBTT_FIXSHIFT;
- int j = x1 >> STBTT_FIXSHIFT;
-
- if (i < len && j >= 0) {
- if (i == j) {
- // x0,x1 are the same pixel, so compute combined coverage
- scanline[i] = scanline[i] + (stbtt_uint8) ((x1 - x0) * max_weight >> STBTT_FIXSHIFT);
- } else {
- if (i >= 0) // add antialiasing for x0
- scanline[i] = scanline[i] + (stbtt_uint8) (((STBTT_FIX - (x0 & STBTT_FIXMASK)) * max_weight) >> STBTT_FIXSHIFT);
- else
- i = -1; // clip
-
- if (j < len) // add antialiasing for x1
- scanline[j] = scanline[j] + (stbtt_uint8) (((x1 & STBTT_FIXMASK) * max_weight) >> STBTT_FIXSHIFT);
- else
- j = len; // clip
-
- for (++i; i < j; ++i) // fill pixels between x0 and x1
- scanline[i] = scanline[i] + (stbtt_uint8) max_weight;
- }
- }
- }
- }
-
- e = e->next;
- }
-}
-
-static void stbtt__rasterize_sorted_edges(stbtt__bitmap *result, stbtt__edge *e, int n, int vsubsample, int off_x, int off_y, void *userdata)
-{
- stbtt__hheap hh = { 0, 0, 0 };
- stbtt__active_edge *active = NULL;
- int y,j=0;
- int max_weight = (255 / vsubsample); // weight per vertical scanline
- int s; // vertical subsample index
- unsigned char scanline_data[512], *scanline;
-
- if (result->w > 512)
- scanline = (unsigned char *) STBTT_malloc(result->w, userdata);
- else
- scanline = scanline_data;
-
- y = off_y * vsubsample;
- e[n].y0 = (off_y + result->h) * (float) vsubsample + 1;
-
- while (j < result->h) {
- STBTT_memset(scanline, 0, result->w);
- for (s=0; s < vsubsample; ++s) {
- // find center of pixel for this scanline
- float scan_y = y + 0.5f;
- stbtt__active_edge **step = &active;
-
- // update all active edges;
- // remove all active edges that terminate before the center of this scanline
- while (*step) {
- stbtt__active_edge * z = *step;
- if (z->ey <= scan_y) {
- *step = z->next; // delete from list
- STBTT_assert(z->direction);
- z->direction = 0;
- stbtt__hheap_free(&hh, z);
- } else {
- z->x += z->dx; // advance to position for current scanline
- step = &((*step)->next); // advance through list
- }
- }
-
- // resort the list if needed
- for(;;) {
- int changed=0;
- step = &active;
- while (*step && (*step)->next) {
- if ((*step)->x > (*step)->next->x) {
- stbtt__active_edge *t = *step;
- stbtt__active_edge *q = t->next;
-
- t->next = q->next;
- q->next = t;
- *step = q;
- changed = 1;
- }
- step = &(*step)->next;
- }
- if (!changed) break;
- }
-
- // insert all edges that start before the center of this scanline -- omit ones that also end on this scanline
- while (e->y0 <= scan_y) {
- if (e->y1 > scan_y) {
- stbtt__active_edge *z = stbtt__new_active(&hh, e, off_x, scan_y, userdata);
- if (z != NULL) {
- // find insertion point
- if (active == NULL)
- active = z;
- else if (z->x < active->x) {
- // insert at front
- z->next = active;
- active = z;
- } else {
- // find thing to insert AFTER
- stbtt__active_edge *p = active;
- while (p->next && p->next->x < z->x)
- p = p->next;
- // at this point, p->next->x is NOT < z->x
- z->next = p->next;
- p->next = z;
- }
- }
- }
- ++e;
- }
-
- // now process all active edges in XOR fashion
- if (active)
- stbtt__fill_active_edges(scanline, result->w, active, max_weight);
-
- ++y;
- }
- STBTT_memcpy(result->pixels + j * result->stride, scanline, result->w);
- ++j;
- }
-
- if (scanline != scanline_data)
- STBTT_free(scanline, userdata);
-}
-
-#elif STBTT_RASTERIZER_VERSION == 2
// the edge passed in here does not cross the vertical line at x or the vertical line at x+1
// (i.e. it has already been clipped to those)
@@ -3066,7 +2852,7 @@ static void stbtt__fill_active_edges_new(float *scanline, float *scanline_fill,
}
// directly AA rasterize edges w/o supersampling
-static void stbtt__rasterize_sorted_edges(Arena *a, stbtt__bitmap *result, stbtt__edge *e, int n, int vsubsample, int off_x, int off_y, void *userdata)
+static void stbtt__rasterize_sorted_edges(Arena *a, stbtt__bitmap *result, stbtt__edge *e, int n, int vsubsample, int off_x, int off_y)
{
stbtt__hheap hh = { 0, 0, 0 };
stbtt__active_edge *active = NULL;
@@ -3075,10 +2861,8 @@ static void stbtt__rasterize_sorted_edges(Arena *a, stbtt__bitmap *result, stbtt
STBTT__NOTUSED(vsubsample);
- if (result->w > 64)
- scanline = (float *) STBTT_malloc((result->w*2+1) * sizeof(float), userdata);
- else
- scanline = scanline_data;
+ if (result->w > 64) scanline = alloc(a, float, result->w * 2 + 1);
+ else scanline = scanline_data;
scanline2 = scanline + result->w;
@@ -3156,9 +2940,6 @@ static void stbtt__rasterize_sorted_edges(Arena *a, stbtt__bitmap *result, stbtt
++y;
++j;
}
-
- if (scanline != scanline_data)
- STBTT_free(scanline, userdata);
}
#else
#error "Unrecognized value of STBTT_RASTERIZER_VERSION"
@@ -3254,14 +3035,12 @@ static void stbtt__sort_edges(stbtt__edge *p, int n)
typedef v2 stbtt__point;
-static void stbtt__rasterize(Arena *a, stbtt__bitmap *result, stbtt__point *pts, int *wcount, int windings, float scale_x, float scale_y, float shift_x, float shift_y, int off_x, int off_y, int invert, void *userdata)
+static void stbtt__rasterize(Arena *a, stbtt__bitmap *result, stbtt__point *pts, int *wcount, int windings, float scale_x, float scale_y, float shift_x, float shift_y, int off_x, int off_y, int invert)
{
float y_scale_inv = invert ? -scale_y : scale_y;
stbtt__edge *e;
int n,i,j,k,m;
-#if STBTT_RASTERIZER_VERSION == 1
- int vsubsample = result->h < 8 ? 15 : 5;
-#elif STBTT_RASTERIZER_VERSION == 2
+#if STBTT_RASTERIZER_VERSION == 2
int vsubsample = 1;
#else
#error "Unrecognized value of STBTT_RASTERIZER_VERSION"
@@ -3305,7 +3084,7 @@ static void stbtt__rasterize(Arena *a, stbtt__bitmap *result, stbtt__point *pts,
stbtt__sort_edges(e, n);
// now, traverse the scanlines and find the intersections on each scanline, use xor winding rule
- stbtt__rasterize_sorted_edges(a, result, e, n, vsubsample, off_x, off_y, userdata);
+ stbtt__rasterize_sorted_edges(a, result, e, n, vsubsample, off_x, off_y);
}
static void stbtt__add_point(stbtt__point *points, int n, float x, float y)
@@ -3379,7 +3158,7 @@ static void stbtt__tesselate_cubic(stbtt__point *points, int *num_points, float
}
// returns number of contours
-static stbtt__point *stbtt_FlattenCurves(Arena *a, stbtt_vertex *vertices, int num_verts, float objspace_flatness, int **contour_lengths, int *num_contours, void *userdata)
+static stbtt__point *stbtt_FlattenCurves(Arena *a, stbtt_vertex *vertices, int num_verts, float objspace_flatness, int **contour_lengths, int *num_contours)
{
stbtt__point *points=0;
int num_points=0;
@@ -3444,14 +3223,14 @@ static stbtt__point *stbtt_FlattenCurves(Arena *a, stbtt_vertex *vertices, int n
return points;
}
-STBTT_DEF void stbtt_Rasterize(Arena a, stbtt__bitmap *result, float flatness_in_pixels, stbtt_vertex *vertices, int num_verts, float scale_x, float scale_y, float shift_x, float shift_y, int x_off, int y_off, int invert, void *userdata)
+STBTT_DEF void stbtt_Rasterize(Arena a, stbtt__bitmap *result, float flatness_in_pixels, stbtt_vertex *vertices, int num_verts, float scale_x, float scale_y, float shift_x, float shift_y, int x_off, int y_off, int invert)
{
float scale = scale_x > scale_y ? scale_y : scale_x;
int winding_count = 0;
int *winding_lengths = NULL;
- stbtt__point *windings = stbtt_FlattenCurves(&a, vertices, num_verts, flatness_in_pixels / scale, &winding_lengths, &winding_count, userdata);
+ stbtt__point *windings = stbtt_FlattenCurves(&a, vertices, num_verts, flatness_in_pixels / scale, &winding_lengths, &winding_count);
if (windings)
- stbtt__rasterize(&a, result, windings, winding_lengths, winding_count, scale_x, scale_y, shift_x, shift_y, x_off, y_off, invert, userdata);
+ stbtt__rasterize(&a, result, windings, winding_lengths, winding_count, scale_x, scale_y, shift_x, shift_y, x_off, y_off, invert);
}
STBTT_DEF void stbtt_MakeGlyphBitmapSubpixel(Arena a, const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int glyph)
@@ -3468,7 +3247,7 @@ STBTT_DEF void stbtt_MakeGlyphBitmapSubpixel(Arena a, const stbtt_fontinfo *info
gbm.stride = out_stride;
if (gbm.w && gbm.h)
- stbtt_Rasterize(a, &gbm, 0.35f, vertices, num_verts, scale_x, scale_y, shift_x, shift_y, ix0,iy0, 1, info->userdata);
+ stbtt_Rasterize(a, &gbm, 0.35f, vertices, num_verts, scale_x, scale_y, shift_x, shift_y, ix0,iy0, 1);
}
STBTT_DEF void stbtt_MakeGlyphBitmap(Arena a, const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int glyph)
@@ -3491,7 +3270,6 @@ STBTT_DEF int stbtt_BakeFontBitmap(Arena a, unsigned char *data, int offset, //
float scale;
int x,y,bottom_y, i;
stbtt_fontinfo f;
- f.userdata = NULL;
if (!stbtt_InitFont(&f, data, offset))
return -1;
STBTT_memset(pixels, 0, pw*ph); // background of 0 around pixels
@@ -3626,19 +3404,13 @@ static void stbrp_pack_rects(stbrp_context *con, stbrp_rect *rects, int num_rect
// This is SUPER-AWESOME (tm Ryan Gordon) packing using stb_rect_pack.h. If
// stb_rect_pack.h isn't available, it uses the BakeFontBitmap strategy.
-STBTT_DEF int stbtt_PackBegin(stbtt_pack_context *spc, unsigned char *pixels, int pw, int ph, int stride_in_bytes, int padding, void *alloc_context)
+STBTT_DEF int stbtt_PackBegin(Arena *a, stbtt_pack_context *spc, unsigned char *pixels, int pw, int ph, int stride_in_bytes, int padding)
{
- stbrp_context *context = (stbrp_context *) STBTT_malloc(sizeof(*context) ,alloc_context);
- int num_nodes = pw - padding;
- stbrp_node *nodes = (stbrp_node *) STBTT_malloc(sizeof(*nodes ) * num_nodes,alloc_context);
- if (context == NULL || nodes == NULL) {
- if (context != NULL) STBTT_free(context, alloc_context);
- if (nodes != NULL) STBTT_free(nodes , alloc_context);
- return 0;
- }
+ stbrp_context *context = alloc(a, stbrp_context, 1);
+ int num_nodes = pw - padding;
+ stbrp_node *nodes = alloc(a, stbrp_node, num_nodes);
- spc->user_allocator_context = alloc_context;
spc->width = pw;
spc->height = ph;
spc->pixels = pixels;
@@ -3658,10 +3430,8 @@ STBTT_DEF int stbtt_PackBegin(stbtt_pack_context *spc, unsigned char *pixels, in
return 1;
}
-STBTT_DEF void stbtt_PackEnd (stbtt_pack_context *spc)
+STBTT_DEF void stbtt_PackEnd(stbtt_pack_context *spc)
{
- STBTT_free(spc->nodes , spc->user_allocator_context);
- STBTT_free(spc->pack_info, spc->user_allocator_context);
}
STBTT_DEF void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h_oversample, unsigned int v_oversample)
@@ -3990,11 +3760,7 @@ STBTT_DEF int stbtt_PackFontRanges(Arena a, stbtt_pack_context *spc, unsigned ch
for (i=0; i < num_ranges; ++i)
n += ranges[i].num_chars;
- rects = (stbrp_rect *) STBTT_malloc(sizeof(*rects) * n, spc->user_allocator_context);
- if (rects == NULL)
- return 0;
-
- info.userdata = spc->user_allocator_context;
+ rects = alloc(&a, stbrp_rect, n);
stbtt_InitFont(&info, fontdata, stbtt_GetFontOffsetForIndex(fontdata,font_index));
n = stbtt_PackFontRangesGatherRects(spc, &info, ranges, num_ranges, rects);
@@ -4003,7 +3769,6 @@ STBTT_DEF int stbtt_PackFontRanges(Arena a, stbtt_pack_context *spc, unsigned ch
return_value = stbtt_PackFontRangesRenderIntoRects(a, spc, &info, ranges, num_ranges, rects);
- STBTT_free(rects, spc->user_allocator_context);
return return_value;
}
@@ -4282,8 +4047,8 @@ STBTT_DEF unsigned char *stbtt_GetGlyphSDF(Arena *a, const stbtt_fontinfo *info,
float *precompute;
stbtt_vertex *verts;
int num_verts = stbtt_GetGlyphShape(a, info, glyph, &verts);
- data = (unsigned char *) STBTT_malloc(w * h, info->userdata);
- precompute = (float *) STBTT_malloc(num_verts * sizeof(float), info->userdata);
+ data = alloc(a, unsigned char, w * h);
+ precompute = alloc(a, float, num_verts);
for (i=0,j=num_verts-1; i < num_verts; j=i++) {
if (verts[i].type == STBTT_vline) {
@@ -4425,17 +4190,10 @@ STBTT_DEF unsigned char *stbtt_GetGlyphSDF(Arena *a, const stbtt_fontinfo *info,
data[(y-iy0)*w+(x-ix0)] = (unsigned char) val;
}
}
- STBTT_free(precompute, info->userdata);
- STBTT_free(verts, info->userdata);
}
return data;
}
-STBTT_DEF void stbtt_FreeSDF(unsigned char *bitmap, void *userdata)
-{
- STBTT_free(bitmap, userdata);
-}
-
//////////////////////////////////////////////////////////////////////////////
//
// font name matching -- recommended not to use this