Skip to content
Myr

stb_truetype:

Before adoption: this commit came in with the history the project adopted, so no landing records it.

STBTT_POINT_SIZE documentation for above stb_rect_pack: STBRP_ASSERT

authored by Sean Barrett · committed by Sean Barrett · parent 27974c4 · Browse files · 2 files+39 added−22 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+39 added−22 removed

  • other:+39 added−22 removed

2 files+39 added−22 removed

modified:stb_rect_pack.h+19 added-14 removed
20 unmodified lines
21// function.22//23// Version history:24//25// 0.05: added STBRP_ASSERT to allow replacing assert26// 0.04: fixed minor bug in STBRP_LARGE_RECTS support27// 0.01: initial release2829//////////////////////////////////////////////////////////////////////////////
139 unmodified lines
169//170171#ifdef STB_RECT_PACK_IMPLEMENTATION172#include <stdlib.h>173174#ifndef STBRP_ASSERT175#include <assert.h>176#define STBRP_ASSERT assert177#endif178179enum180{181 STBRP__INIT_skyline = 1,
2 unmodified lines
184STBRP_DEF void stbrp_setup_heuristic(stbrp_context *context, int heuristic)185{186 switch (context->init_mode) {187 case STBRP__INIT_skyline:183 assert(heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight || heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight);188 STBRP_ASSERT(heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight || heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight);189 context->heuristic = heuristic;190 break;191 default:187 assert(0);192 STBRP_ASSERT(0);193 }194}195196STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_out_of_mem)
19 unmodified lines
216STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes)217{218 int i;219#ifndef STBRP_LARGE_RECTS215 assert(width <= 0xffff && height <= 0xffff);220 STBRP_ASSERT(width <= 0xffff && height <= 0xffff);221#endif222223 for (i=0; i < num_nodes-1; ++i)224 nodes[i].next = &nodes[i+1];
25 unmodified lines
250{251 stbrp_node *node = first;252 int x1 = x0 + width;253 int min_y, visited_width, waste_area;249 assert(first->x <= x0);254 STBRP_ASSERT(first->x <= x0);255256 #if 0257 // skip in case we're past the node258 while (node->next->x <= x0)259 ++node;260 #else256 assert(node->next->x > x0); // we ended up handling this in the caller for efficiency261 STBRP_ASSERT(node->next->x > x0); // we ended up handling this in the caller for efficiency262 #endif263259 assert(node->x <= x0);264 STBRP_ASSERT(node->x <= x0);265266 min_y = 0;267 waste_area = 0;268 visited_width = 0;
38 unmodified lines
307308 // align to multiple of c->align309 width = (width + c->align - 1);310 width -= width % c->align;306 assert(width % c->align == 0);311 STBRP_ASSERT(width % c->align == 0);312313 node = c->active_head;314 prev = &c->active_head;315 while (node->x + width <= c->width) {
48 unmodified lines
364 tail = tail->next;365 while (tail) {366 int xpos = tail->x - width;367 int y,waste;363 assert(xpos >= 0);368 STBRP_ASSERT(xpos >= 0);369 // find the left position that matches this370 while (node->next->x <= xpos) {371 prev = &node->next;372 node = node->next;373 }369 assert(node->next->x > xpos && node->x <= xpos);374 STBRP_ASSERT(node->next->x > xpos && node->x <= xpos);375 y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste);376 if (y + height < c->height) {377 if (y <= best_y) {378 if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) {379 best_x = xpos;375 assert(y <= best_y);380 STBRP_ASSERT(y <= best_y);381 best_y = y;382 best_waste = waste;383 best = prev;384 }
63 unmodified lines
448449#ifdef _DEBUG450 cur = context->active_head;451 while (cur->x < context->width) {447 assert(cur->x < cur->next->x);452 STBRP_ASSERT(cur->x < cur->next->x);453 cur = cur->next;454 }450 assert(cur->next == NULL);455 STBRP_ASSERT(cur->next == NULL);456457 {458 stbrp_node *L1 = NULL, *L2 = NULL;459 int count=0;
8 unmodified lines
468 L2 = cur;469 cur = cur->next;470 ++count;471 }467 assert(count == context->num_nodes+2);472 STBRP_ASSERT(count == context->num_nodes+2);473 }474#endif475476 return res;
41 unmodified lines
518 // we use the 'was_packed' field internally to allow sorting/unsorting519 for (i=0; i < num_rects; ++i) {520 rects[i].was_packed = i;521 #ifndef STBRP_LARGE_RECTS517 assert(rects[i].w <= 0xffff && rects[i].h <= 0xffff);522 STBRP_ASSERT(rects[i].w <= 0xffff && rects[i].h <= 0xffff);523 #endif524 }525526 // sort according to heuristic
20 unmodified lines
modified:stb_truetype.h+20 added-8 removed
38 unmodified lines
39// Ryan Gordon40//41// VERSION HISTORY42//43// 1.01 (2014-12-08) fix subpixel position when oversampling to exactly match44// non-oversampled; STBTT_POINT_SIZE for packed case only45// 1.00 (2014-12-06) add new PackBegin etc. API, w/ support for oversampling46// 0.99 (2014-09-18) fix multiple bugs with subpixel rendering (ryg)47// 0.9 (2014-08-07) support certain mac/iOS fonts without an MS platformID48// 0.8b (2014-07-07) fix a warning
442 unmodified lines
491 float xoff2,yoff2;492} stbtt_packedchar;493494typedef struct stbtt_pack_context stbtt_pack_context;493typedef struct494{495 float font_size;496 int first_unicode_char_in_range;497 int num_chars_in_range;498 stbtt_packedchar *chardata_for_range; // output499} stbtt_pack_range;495496extern int stbtt_PackBegin(stbtt_pack_context *spc, unsigned char *pixels, int width, int height, int stride_in_bytes, int padding, void *alloc_context);497// Initializes a packing context stored in the passed-in stbtt_pack_context.498// Future calls using this context will pack characters into the bitmap passed
7 unmodified lines
506507extern void stbtt_PackEnd (stbtt_pack_context *spc);508// Cleans up the packing context and frees all memory.509510#define STBTT_POINT_SIZE(x) (-(x))511515extern int stbtt_PackFontRange(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, float pixel_height,512extern int stbtt_PackFontRange(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, float font_size,513 int first_unicode_char_in_range, int num_chars_in_range, stbtt_packedchar *chardata_for_range);514// Creates character bitmaps from the font_index'th font found in fontdata (use515// font_index=0 if you don't know what that is). It creates num_chars_in_range516// bitmaps for characters with unicode values starting at first_unicode_char_in_range517// and increasing. Data for how to render them is stored in chardata_for_range;518// pass these to stbtt_GetPackedQuad to get back renderable quads.519//520// font_size is the full height of the character from ascender to descender,521// as computed by stbtt_ScaleForPixelHeight. To use a point size as computed522// by stbtt_ScaleForMappingEmToPixels, wrap the point size in STBTT_POINT_SIZE()523// and pass that result as 'font_size':524// ..., 20 , ... // font max minus min y is 20 pixels tall525// ..., STBTT_POINT_SIZE(20), ... // 'M' is 20 pixels tall526527typedef struct528{529 float font_size;530 int first_unicode_char_in_range;531 int num_chars_in_range;532 stbtt_packedchar *chardata_for_range; // output533} stbtt_pack_range;534535extern int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges);536// Creates character bitmaps from multiple ranges of characters stored in537// ranges. This will usually create a better-packed bitmap than multiple538// calls to stbtt_PackFontRange.
2071 unmodified lines