Commit: ae74142b9ce0ebdd3eb686ab4b7b3aaef3bff540
Parent: 9edc6ee7e1c1f6d74063db4a5b2268dc7d19cccc
Author: Randy Palamar
Date: Thu, 24 Oct 2024 07:06:54 -0600
delete font baking from stb_truetype.h
no need to bloat things up with code we will never use
Diffstat:
M | extern/stb_truetype.h | | | 594 | +------------------------------------------------------------------------------ |
1 file changed, 6 insertions(+), 588 deletions(-)
diff --git a/extern/stb_truetype.h b/extern/stb_truetype.h
@@ -100,18 +100,6 @@
// To make the implementation private to the file that generates the implementation,
// #define STBTT_STATIC
//
-// Simple 3D API (don't ship this, but it's fine for tools and quick start)
-// stbtt_BakeFontBitmap() -- bake a font to a bitmap for use as texture
-// stbtt_GetBakedQuad() -- compute quad to draw for a given char
-//
-// Improved 3D API (more shippable):
-// #include "stb_rect_pack.h" -- optional, but you really want it
-// stbtt_PackBegin()
-// stbtt_PackSetOversampling() -- for improved quality on small fonts
-// stbtt_PackFontRanges() -- pack and renders
-// stbtt_PackEnd()
-// stbtt_GetPackedQuad()
-//
// "Load" a font file from a memory buffer (you have to keep the buffer loaded)
// stbtt_InitFont()
// stbtt_GetFontOffsetForIndex() -- indexing for TTC font collections
@@ -338,49 +326,6 @@ typedef struct
int size;
} stbtt__buf;
-//////////////////////////////////////////////////////////////////////////////
-//
-// TEXTURE BAKING API
-//
-// If you use this API, you only have to call two functions ever.
-//
-
-typedef struct
-{
- unsigned short x0,y0,x1,y1; // coordinates of bbox in bitmap
- float xoff,yoff,xadvance;
-} stbtt_bakedchar;
-
-STBTT_DEF int stbtt_BakeFontBitmap(Arena a, 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
- stbtt_bakedchar *chardata); // you allocate this, it's num_chars long
-// if return is positive, the first unused row of the bitmap
-// if return is negative, returns the negative of the number of characters that fit
-// if return is 0, no characters fit and no rows were used
-// This uses a very crappy packing.
-
-typedef struct
-{
- float x0,y0,s0,t0; // top-left
- float x1,y1,s1,t1; // bottom-right
-} stbtt_aligned_quad;
-
-STBTT_DEF void stbtt_GetBakedQuad(const stbtt_bakedchar *chardata, int pw, int ph, // same data as above
- int char_index, // character to display
- float *xpos, float *ypos, // pointers to current position in screen pixel space
- stbtt_aligned_quad *q, // output: quad to draw
- int opengl_fillrule); // true if opengl fill rule; false if DX9 or earlier
-// Call GetBakedQuad with char_index = 'character - first_char', and it
-// creates the quad you need to draw and advances the current position.
-//
-// The coordinate system used assumes y increases downwards.
-//
-// Characters will extend both above and below the current position;
-// see discussion of "BASELINE" above.
-//
-// It's inefficient; you might want to c&p it and optimize it.
STBTT_DEF void stbtt_GetScaledFontVMetrics(unsigned char *fontdata, int index, float size, float *ascent, float *descent, float *lineGap);
// Query the font vertical metrics without having to create a font first.
@@ -388,128 +333,6 @@ STBTT_DEF void stbtt_GetScaledFontVMetrics(unsigned char *fontdata, int index, f
//////////////////////////////////////////////////////////////////////////////
//
-// NEW TEXTURE BAKING API
-//
-// This provides options for packing multiple fonts into one atlas, not
-// perfectly but better than nothing.
-
-typedef struct
-{
- unsigned short x0,y0,x1,y1; // coordinates of bbox in bitmap
- float xoff,yoff,xadvance;
- float xoff2,yoff2;
-} stbtt_packedchar;
-
-typedef struct stbtt_pack_context stbtt_pack_context;
-typedef struct stbtt_fontinfo stbtt_fontinfo;
-#ifndef STB_RECT_PACK_VERSION
-typedef struct stbrp_rect stbrp_rect;
-#endif
-
-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
-// the distance from one row to the next (or 0 to mean they are packed tightly
-// together). "padding" is the amount of padding to leave between each
-// character (normally you want '1' for bitmaps you'll use as textures with
-// bilinear filtering).
-//
-// Returns 0 on failure, 1 on success.
-
-#define STBTT_POINT_SIZE(x) (-(x))
-
-STBTT_DEF int stbtt_PackFontRange(Arena a, stbtt_pack_context *spc, unsigned char *fontdata,
- int font_index, float font_size, int first_unicode_char_in_range,
- int num_chars_in_range, stbtt_packedchar *chardata_for_range);
-// Creates character bitmaps from the font_index'th font found in fontdata (use
-// font_index=0 if you don't know what that is). It creates num_chars_in_range
-// bitmaps for characters with unicode values starting at first_unicode_char_in_range
-// and increasing. Data for how to render them is stored in chardata_for_range;
-// pass these to stbtt_GetPackedQuad to get back renderable quads.
-//
-// font_size is the full height of the character from ascender to descender,
-// as computed by stbtt_ScaleForPixelHeight. To use a point size as computed
-// by stbtt_ScaleForMappingEmToPixels, wrap the point size in STBTT_POINT_SIZE()
-// and pass that result as 'font_size':
-// ..., 20 , ... // font max minus min y is 20 pixels tall
-// ..., STBTT_POINT_SIZE(20), ... // 'M' is 20 pixels tall
-
-typedef struct
-{
- float font_size;
- int first_unicode_codepoint_in_range; // if non-zero, then the chars are continuous, and this is the first codepoint
- int *array_of_unicode_codepoints; // if non-zero, then this is an array of unicode codepoints
- int num_chars;
- stbtt_packedchar *chardata_for_range; // output
- unsigned char h_oversample, v_oversample; // don't set these, they're used internally
-} stbtt_pack_range;
-
-STBTT_DEF int stbtt_PackFontRanges(Arena a, stbtt_pack_context *spc, unsigned char *fontdata,
- int font_index, stbtt_pack_range *ranges, int num_ranges);
-// Creates character bitmaps from multiple ranges of characters stored in
-// ranges. This will usually create a better-packed bitmap than multiple
-// calls to stbtt_PackFontRange. Note that you can call this multiple
-// times within a single PackBegin/PackEnd.
-
-STBTT_DEF void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h_oversample, unsigned int v_oversample);
-// Oversampling a font increases the quality by allowing higher-quality subpixel
-// positioning, and is especially valuable at smaller text sizes.
-//
-// This function sets the amount of oversampling for all following calls to
-// stbtt_PackFontRange(s) or stbtt_PackFontRangesGatherRects for a given
-// pack context. The default (no oversampling) is achieved by h_oversample=1
-// and v_oversample=1. The total number of pixels required is
-// h_oversample*v_oversample larger than the default; for example, 2x2
-// oversampling requires 4x the storage of 1x1. For best results, render
-// oversampled textures with bilinear filtering. Look at the readme in
-// stb/tests/oversample for information about oversampled fonts
-//
-// To use with PackFontRangesGather etc., you must set it before calls
-// call to PackFontRangesGatherRects.
-
-STBTT_DEF void stbtt_PackSetSkipMissingCodepoints(stbtt_pack_context *spc, int skip);
-// If skip != 0, this tells stb_truetype to skip any codepoints for which
-// there is no corresponding glyph. If skip=0, which is the default, then
-// codepoints without a glyph recived the font's "missing character" glyph,
-// typically an empty box by convention.
-
-STBTT_DEF void stbtt_GetPackedQuad(const stbtt_packedchar *chardata, int pw, int ph, // same data as above
- int char_index, // character to display
- float *xpos, float *ypos, // pointers to current position in screen pixel space
- stbtt_aligned_quad *q, // output: quad to draw
- int align_to_integer);
-
-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(Arena a, 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
-// at the source to of stbtt_PackFontRanges() and create a custom version
-// using these functions, e.g. call GatherRects multiple times,
-// building up a single array of rects, then call PackRects once,
-// then call RenderIntoRects repeatedly. This may result in a
-// better packing than calling PackFontRanges multiple times
-// (or it may not).
-
-// 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 *pack_info;
- int width;
- int height;
- int stride_in_bytes;
- int padding;
- int skip_missing;
- unsigned int h_oversample, v_oversample;
- unsigned char *pixels;
- void *nodes;
-};
-
-//////////////////////////////////////////////////////////////////////////////
-//
// FONT LOADING
//
//
@@ -530,8 +353,7 @@ STBTT_DEF int stbtt_GetFontOffsetForIndex(unsigned char *data, int index);
// The following structure is defined publicly so you can declare one on
// the stack or as a global or etc, but you should treat it as opaque.
-struct stbtt_fontinfo
-{
+typedef struct {
unsigned char * data; // pointer to .ttf file
int fontstart; // offset of start of font
@@ -547,7 +369,7 @@ struct stbtt_fontinfo
stbtt__buf subrs; // private charstring subroutines index
stbtt__buf fontdicts; // array of font dicts
stbtt__buf fdselect; // map from glyph to fontdict
-};
+} stbtt_fontinfo;
STBTT_DEF int stbtt_InitFont(stbtt_fontinfo *info, unsigned char *data, int offset);
// Given an offset into the file that defines a font, this function builds
@@ -699,21 +521,17 @@ STBTT_DEF void stbtt_MakeGlyphBitmapSubpixelPrefilter(Arena a, const stbtt_fonti
float shift_x, float shift_y, int oversample_x,
int oversample_y, float *sub_x, float *sub_y,
int glyph);
-// same as stbtt_MakeGlyphBitmapSubpixel, but prefiltering is performed (see stbtt_PackSetOversampling)
+// same as stbtt_MakeGlyphBitmapSubpixel, but prefiltering is performed for improved quality on small fonts
-STBTT_DEF void stbtt_GetGlyphBitmapBox(const stbtt_fontinfo *font, int glyph, float scale_x,
- float scale_y, int *ix0, int *iy0, int *ix1, int *iy1);
+STBTT_DEF void stbtt_GetGlyphBitmapBoxSubpixel(const stbtt_fontinfo *font, int glyph, float scale_x,
+ float scale_y,float shift_x, float shift_y,
+ int *ix0, int *iy0, int *ix1, int *iy1);
// get the bbox of the bitmap centered around the glyph origin; so the
// bitmap width is ix1-ix0, height is iy1-iy0, and location to place
// the bitmap top left is (leftSideBearing*scale,iy0).
// (Note that the bitmap uses y-increases-down, but the shape uses
// y-increases-up, so GlyphBitmapBox and GlyphBox are inverted.)
-STBTT_DEF void stbtt_GetGlyphBitmapBoxSubpixel(const stbtt_fontinfo *font, int glyph, float scale_x,
- float scale_y,float shift_x, float shift_y,
- int *ix0, int *iy0, int *ix1, int *iy1);
-// same as stbtt_GetGlyphBitmapBox, but you can specify a subpixel shift for the character
-
// @TODO: don't expose this structure
typedef struct
@@ -2485,11 +2303,6 @@ STBTT_DEF void stbtt_GetGlyphBitmapBoxSubpixel(const stbtt_fontinfo *font, int g
}
}
-STBTT_DEF void stbtt_GetGlyphBitmapBox(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1)
-{
- stbtt_GetGlyphBitmapBoxSubpixel(font, glyph, scale_x, scale_y,0.0f,0.0f, ix0, iy0, ix1, iy1);
-}
-
//////////////////////////////////////////////////////////////////////////////
//
// Rasterizer
@@ -3243,200 +3056,6 @@ STBTT_DEF void stbtt_MakeGlyphBitmap(Arena a, const stbtt_fontinfo *info, unsign
stbtt_MakeGlyphBitmapSubpixel(a, info, output, out_w, out_h, out_stride, scale_x, scale_y, 0.0f,0.0f, glyph);
}
-//////////////////////////////////////////////////////////////////////////////
-//
-// bitmap baking
-//
-// This is SUPER-CRAPPY packing to keep source code small
-
-STBTT_DEF int stbtt_BakeFontBitmap(Arena a, 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
- stbtt_bakedchar *chardata)
-{
- float scale;
- int x,y,bottom_y, i;
- stbtt_fontinfo f;
- if (!stbtt_InitFont(&f, data, offset))
- return -1;
- mem_clear(pixels, 0, pw*ph); // background of 0 around pixels
- x=y=1;
- bottom_y = 1;
-
- scale = stbtt_ScaleForPixelHeight(&f, pixel_height);
-
- for (i=0; i < num_chars; ++i) {
- int advance, lsb, x0,y0,x1,y1,gw,gh;
- int g = stbtt_FindGlyphIndex(&f, first_char + i);
- stbtt_GetGlyphHMetrics(&f, g, &advance, &lsb);
- stbtt_GetGlyphBitmapBox(&f, g, scale,scale, &x0,&y0,&x1,&y1);
- gw = x1-x0;
- gh = y1-y0;
- if (x + gw + 1 >= pw)
- y = bottom_y, x = 1; // advance to next row
- if (y + gh + 1 >= ph) // check if it fits vertically AFTER potentially moving to next row
- return -i;
- STBTT_assert(x+gw < pw);
- STBTT_assert(y+gh < ph);
- stbtt_MakeGlyphBitmap(a, &f, pixels+x+y*pw, gw,gh,pw, scale,scale, g);
- chardata[i].x0 = (stbtt_int16) x;
- chardata[i].y0 = (stbtt_int16) y;
- chardata[i].x1 = (stbtt_int16) (x + gw);
- chardata[i].y1 = (stbtt_int16) (y + gh);
- chardata[i].xadvance = scale * advance;
- chardata[i].xoff = (float) x0;
- chardata[i].yoff = (float) y0;
- x = x + gw + 1;
- if (y+gh+1 > bottom_y)
- bottom_y = y+gh+1;
- }
- return bottom_y;
-}
-
-STBTT_DEF void stbtt_GetBakedQuad(const stbtt_bakedchar *chardata, int pw, int ph, int char_index, float *xpos, float *ypos, stbtt_aligned_quad *q, int opengl_fillrule)
-{
- float d3d_bias = opengl_fillrule ? 0 : -0.5f;
- float ipw = 1.0f / pw, iph = 1.0f / ph;
- const stbtt_bakedchar *b = chardata + char_index;
- int round_x = STBTT_ifloor((*xpos + b->xoff) + 0.5f);
- int round_y = STBTT_ifloor((*ypos + b->yoff) + 0.5f);
-
- q->x0 = round_x + d3d_bias;
- q->y0 = round_y + d3d_bias;
- q->x1 = round_x + b->x1 - b->x0 + d3d_bias;
- q->y1 = round_y + b->y1 - b->y0 + d3d_bias;
-
- q->s0 = b->x0 * ipw;
- q->t0 = b->y0 * iph;
- q->s1 = b->x1 * ipw;
- q->t1 = b->y1 * iph;
-
- *xpos += b->xadvance;
-}
-
-//////////////////////////////////////////////////////////////////////////////
-//
-// rectangle packing replacement routines if you don't have stb_rect_pack.h
-//
-
-#ifndef STB_RECT_PACK_VERSION
-
-typedef int stbrp_coord;
-
-////////////////////////////////////////////////////////////////////////////////////
-// //
-// //
-// COMPILER WARNING ?!?!? //
-// //
-// //
-// if you get a compile warning due to these symbols being defined more than //
-// once, move #include "stb_rect_pack.h" before #include "stb_truetype.h" //
-// //
-////////////////////////////////////////////////////////////////////////////////////
-
-typedef struct
-{
- int width,height;
- int x,y,bottom_y;
-} stbrp_context;
-
-typedef struct
-{
- unsigned char x;
-} stbrp_node;
-
-struct stbrp_rect
-{
- stbrp_coord x,y;
- int id,w,h,was_packed;
-};
-
-static void stbrp_init_target(stbrp_context *con, int pw, int ph, stbrp_node *nodes, int num_nodes)
-{
- con->width = pw;
- con->height = ph;
- con->x = 0;
- con->y = 0;
- con->bottom_y = 0;
- STBTT__NOTUSED(nodes);
- STBTT__NOTUSED(num_nodes);
-}
-
-static void stbrp_pack_rects(stbrp_context *con, stbrp_rect *rects, int num_rects)
-{
- int i;
- for (i=0; i < num_rects; ++i) {
- if (con->x + rects[i].w > con->width) {
- con->x = 0;
- con->y = con->bottom_y;
- }
- if (con->y + rects[i].h > con->height)
- break;
- rects[i].x = con->x;
- rects[i].y = con->y;
- rects[i].was_packed = 1;
- con->x += rects[i].w;
- if (con->y + rects[i].h > con->bottom_y)
- con->bottom_y = con->y + rects[i].h;
- }
- for ( ; i < num_rects; ++i)
- rects[i].was_packed = 0;
-}
-#endif
-
-//////////////////////////////////////////////////////////////////////////////
-//
-// bitmap baking
-//
-// 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(Arena *a, stbtt_pack_context *spc, unsigned char *pixels, int pw, int ph, int stride_in_bytes, int padding)
-{
-
- stbrp_context *context = alloc(a, stbrp_context, 1);
- int num_nodes = pw - padding;
- stbrp_node *nodes = alloc(a, stbrp_node, num_nodes);
-
- spc->width = pw;
- spc->height = ph;
- spc->pixels = pixels;
- spc->pack_info = context;
- spc->nodes = nodes;
- spc->padding = padding;
- spc->stride_in_bytes = stride_in_bytes != 0 ? stride_in_bytes : pw;
- spc->h_oversample = 1;
- spc->v_oversample = 1;
- spc->skip_missing = 0;
-
- stbrp_init_target(context, pw-padding, ph-padding, nodes, num_nodes);
-
- if (pixels)
- mem_clear(pixels, 0, pw*ph); // background of 0 around pixels
-
- return 1;
-}
-
-STBTT_DEF void stbtt_PackEnd(stbtt_pack_context *spc)
-{
-}
-
-STBTT_DEF void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h_oversample, unsigned int v_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)
- spc->v_oversample = v_oversample;
-}
-
-STBTT_DEF void stbtt_PackSetSkipMissingCodepoints(stbtt_pack_context *spc, int skip)
-{
- spc->skip_missing = skip;
-}
-
#define STBTT__OVER_MASK (STBTT_MAX_OVERSAMPLE-1)
static void stbtt__h_prefilter(unsigned char *pixels, int w, int h, int stride_in_bytes, unsigned int kernel_width)
@@ -3573,42 +3192,6 @@ static float stbtt__oversample_shift(int oversample)
return (float)-(oversample - 1) / (2.0f * (float)oversample);
}
-// rects array must be big enough to accommodate all characters in the given ranges
-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;
- int missing_glyph_added = 0;
-
- k=0;
- for (i=0; i < num_ranges; ++i) {
- float fh = ranges[i].font_size;
- float scale = fh > 0 ? stbtt_ScaleForPixelHeight(info, fh) : stbtt_ScaleForMappingEmToPixels(info, -fh);
- ranges[i].h_oversample = (unsigned char) spc->h_oversample;
- ranges[i].v_oversample = (unsigned char) spc->v_oversample;
- for (j=0; j < ranges[i].num_chars; ++j) {
- int x0,y0,x1,y1;
- int codepoint = ranges[i].array_of_unicode_codepoints == NULL ? ranges[i].first_unicode_codepoint_in_range + j : ranges[i].array_of_unicode_codepoints[j];
- int glyph = stbtt_FindGlyphIndex(info, codepoint);
- if (glyph == 0 && (spc->skip_missing || missing_glyph_added)) {
- rects[k].w = rects[k].h = 0;
- } else {
- stbtt_GetGlyphBitmapBoxSubpixel(info,glyph,
- scale * spc->h_oversample,
- scale * spc->v_oversample,
- 0,0,
- &x0,&y0,&x1,&y1);
- rects[k].w = (stbrp_coord) (x1-x0 + spc->padding + spc->h_oversample-1);
- rects[k].h = (stbrp_coord) (y1-y0 + spc->padding + spc->v_oversample-1);
- if (glyph == 0)
- missing_glyph_added = 1;
- }
- ++k;
- }
- }
-
- return k;
-}
-
STBTT_DEF void stbtt_MakeGlyphBitmapSubpixelPrefilter(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 prefilter_x, int prefilter_y, float *sub_x, float *sub_y, int glyph)
{
stbtt_MakeGlyphBitmapSubpixel(a, info,
@@ -3632,144 +3215,6 @@ STBTT_DEF void stbtt_MakeGlyphBitmapSubpixelPrefilter(Arena a, const stbtt_fonti
*sub_y = stbtt__oversample_shift(prefilter_y);
}
-// rects array must be big enough to accommodate all characters in the given ranges
-STBTT_DEF int stbtt_PackFontRangesRenderIntoRects(Arena a, stbtt_pack_context *spc, const stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects)
-{
- int i,j,k, missing_glyph = -1, return_value = 1;
-
- // save current values
- int old_h_over = spc->h_oversample;
- int old_v_over = spc->v_oversample;
-
- k = 0;
- for (i=0; i < num_ranges; ++i) {
- float fh = ranges[i].font_size;
- float scale = fh > 0 ? stbtt_ScaleForPixelHeight(info, fh) : stbtt_ScaleForMappingEmToPixels(info, -fh);
- float recip_h,recip_v,sub_x,sub_y;
- spc->h_oversample = ranges[i].h_oversample;
- spc->v_oversample = ranges[i].v_oversample;
- recip_h = 1.0f / spc->h_oversample;
- recip_v = 1.0f / spc->v_oversample;
- sub_x = stbtt__oversample_shift(spc->h_oversample);
- sub_y = stbtt__oversample_shift(spc->v_oversample);
- for (j=0; j < ranges[i].num_chars; ++j) {
- stbrp_rect *r = &rects[k];
- if (r->was_packed && r->w != 0 && r->h != 0) {
- stbtt_packedchar *bc = &ranges[i].chardata_for_range[j];
- int advance, lsb, x0,y0,x1,y1;
- int codepoint = ranges[i].array_of_unicode_codepoints == NULL ? ranges[i].first_unicode_codepoint_in_range + j : ranges[i].array_of_unicode_codepoints[j];
- int glyph = stbtt_FindGlyphIndex(info, codepoint);
- stbrp_coord pad = (stbrp_coord) spc->padding;
-
- // pad on left and top
- r->x += pad;
- r->y += pad;
- r->w -= pad;
- r->h -= pad;
- stbtt_GetGlyphHMetrics(info, glyph, &advance, &lsb);
- stbtt_GetGlyphBitmapBox(info, glyph,
- scale * spc->h_oversample,
- scale * spc->v_oversample,
- &x0,&y0,&x1,&y1);
- stbtt_MakeGlyphBitmapSubpixel(a, info,
- spc->pixels + r->x + r->y*spc->stride_in_bytes,
- r->w - spc->h_oversample+1,
- r->h - spc->v_oversample+1,
- spc->stride_in_bytes,
- scale * spc->h_oversample,
- scale * spc->v_oversample,
- 0,0,
- glyph);
-
- if (spc->h_oversample > 1)
- stbtt__h_prefilter(spc->pixels + r->x + r->y*spc->stride_in_bytes,
- r->w, r->h, spc->stride_in_bytes,
- spc->h_oversample);
-
- if (spc->v_oversample > 1)
- stbtt__v_prefilter(spc->pixels + r->x + r->y*spc->stride_in_bytes,
- r->w, r->h, spc->stride_in_bytes,
- spc->v_oversample);
-
- bc->x0 = (stbtt_int16) r->x;
- bc->y0 = (stbtt_int16) r->y;
- bc->x1 = (stbtt_int16) (r->x + r->w);
- bc->y1 = (stbtt_int16) (r->y + r->h);
- bc->xadvance = scale * advance;
- bc->xoff = (float) x0 * recip_h + sub_x;
- bc->yoff = (float) y0 * recip_v + sub_y;
- bc->xoff2 = (x0 + r->w) * recip_h + sub_x;
- bc->yoff2 = (y0 + r->h) * recip_v + sub_y;
-
- if (glyph == 0)
- missing_glyph = j;
- } else if (spc->skip_missing) {
- return_value = 0;
- } else if (r->was_packed && r->w == 0 && r->h == 0 && missing_glyph >= 0) {
- ranges[i].chardata_for_range[j] = ranges[i].chardata_for_range[missing_glyph];
- } else {
- return_value = 0; // if any fail, report failure
- }
-
- ++k;
- }
- }
-
- // restore original values
- spc->h_oversample = old_h_over;
- spc->v_oversample = old_v_over;
-
- return return_value;
-}
-
-STBTT_DEF void stbtt_PackFontRangesPackRects(stbtt_pack_context *spc, stbrp_rect *rects, int num_rects)
-{
- stbrp_pack_rects((stbrp_context *) spc->pack_info, rects, num_rects);
-}
-
-STBTT_DEF int stbtt_PackFontRanges(Arena a, stbtt_pack_context *spc, unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges)
-{
- stbtt_fontinfo info;
- int i,j,n, return_value = 1;
- //stbrp_context *context = (stbrp_context *) spc->pack_info;
- stbrp_rect *rects;
-
- // flag all characters as NOT packed
- for (i=0; i < num_ranges; ++i)
- for (j=0; j < ranges[i].num_chars; ++j)
- ranges[i].chardata_for_range[j].x0 =
- ranges[i].chardata_for_range[j].y0 =
- ranges[i].chardata_for_range[j].x1 =
- ranges[i].chardata_for_range[j].y1 = 0;
-
- n = 0;
- for (i=0; i < num_ranges; ++i)
- n += ranges[i].num_chars;
-
- rects = alloc(&a, stbrp_rect, n);
- stbtt_InitFont(&info, fontdata, stbtt_GetFontOffsetForIndex(fontdata,font_index));
-
- n = stbtt_PackFontRangesGatherRects(spc, &info, ranges, num_ranges, rects);
-
- stbtt_PackFontRangesPackRects(spc, rects, n);
-
- return_value = stbtt_PackFontRangesRenderIntoRects(a, spc, &info, ranges, num_ranges, rects);
-
- return return_value;
-}
-
-STBTT_DEF int stbtt_PackFontRange(Arena a, stbtt_pack_context *spc, unsigned char *fontdata, int font_index, float font_size,
- int first_unicode_codepoint_in_range, int num_chars_in_range, stbtt_packedchar *chardata_for_range)
-{
- stbtt_pack_range range;
- range.first_unicode_codepoint_in_range = first_unicode_codepoint_in_range;
- range.array_of_unicode_codepoints = NULL;
- range.num_chars = num_chars_in_range;
- range.chardata_for_range = chardata_for_range;
- range.font_size = font_size;
- return stbtt_PackFontRanges(a, spc, fontdata, font_index, &range, 1);
-}
-
STBTT_DEF void stbtt_GetScaledFontVMetrics(unsigned char *fontdata, int index, float size, float *ascent, float *descent, float *lineGap)
{
int i_ascent, i_descent, i_lineGap;
@@ -3783,33 +3228,6 @@ STBTT_DEF void stbtt_GetScaledFontVMetrics(unsigned char *fontdata, int index, f
*lineGap = (float) i_lineGap * scale;
}
-STBTT_DEF void stbtt_GetPackedQuad(const stbtt_packedchar *chardata, int pw, int ph, int char_index, float *xpos, float *ypos, stbtt_aligned_quad *q, int align_to_integer)
-{
- float ipw = 1.0f / pw, iph = 1.0f / ph;
- const stbtt_packedchar *b = chardata + char_index;
-
- if (align_to_integer) {
- float x = (float) STBTT_ifloor((*xpos + b->xoff) + 0.5f);
- float y = (float) STBTT_ifloor((*ypos + b->yoff) + 0.5f);
- q->x0 = x;
- q->y0 = y;
- q->x1 = x + b->xoff2 - b->xoff;
- q->y1 = y + b->yoff2 - b->yoff;
- } else {
- q->x0 = *xpos + b->xoff;
- q->y0 = *ypos + b->yoff;
- q->x1 = *xpos + b->xoff2;
- q->y1 = *ypos + b->yoff2;
- }
-
- q->s0 = b->x0 * ipw;
- q->t0 = b->y0 * iph;
- q->s1 = b->x1 * ipw;
- q->t1 = b->y1 * iph;
-
- *xpos += b->xadvance;
-}
-
//////////////////////////////////////////////////////////////////////////////
//
// sdf computation