提交 97037461 编写于 作者: S Sean Barrett

stb_truetype:

   STBTT_POINT_SIZE
   documentation for above

stb_rect_pack:
   STBRP_ASSERT
上级 27974c42
......@@ -22,6 +22,7 @@
//
// Version history:
//
// 0.05: added STBRP_ASSERT to allow replacing assert
// 0.04: fixed minor bug in STBRP_LARGE_RECTS support
// 0.01: initial release
......@@ -169,7 +170,11 @@ struct stbrp_context
#ifdef STB_RECT_PACK_IMPLEMENTATION
#include <stdlib.h>
#ifndef STBRP_ASSERT
#include <assert.h>
#define STBRP_ASSERT assert
#endif
enum
{
......@@ -180,11 +185,11 @@ STBRP_DEF void stbrp_setup_heuristic(stbrp_context *context, int heuristic)
{
switch (context->init_mode) {
case STBRP__INIT_skyline:
assert(heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight || heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight);
STBRP_ASSERT(heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight || heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight);
context->heuristic = heuristic;
break;
default:
assert(0);
STBRP_ASSERT(0);
}
}
......@@ -212,7 +217,7 @@ STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height,
{
int i;
#ifndef STBRP_LARGE_RECTS
assert(width <= 0xffff && height <= 0xffff);
STBRP_ASSERT(width <= 0xffff && height <= 0xffff);
#endif
for (i=0; i < num_nodes-1; ++i)
......@@ -246,17 +251,17 @@ static int stbrp__skyline_find_min_y(stbrp_context *c, stbrp_node *first, int x0
stbrp_node *node = first;
int x1 = x0 + width;
int min_y, visited_width, waste_area;
assert(first->x <= x0);
STBRP_ASSERT(first->x <= x0);
#if 0
// skip in case we're past the node
while (node->next->x <= x0)
++node;
#else
assert(node->next->x > x0); // we ended up handling this in the caller for efficiency
STBRP_ASSERT(node->next->x > x0); // we ended up handling this in the caller for efficiency
#endif
assert(node->x <= x0);
STBRP_ASSERT(node->x <= x0);
min_y = 0;
waste_area = 0;
......@@ -303,7 +308,7 @@ static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int widt
// align to multiple of c->align
width = (width + c->align - 1);
width -= width % c->align;
assert(width % c->align == 0);
STBRP_ASSERT(width % c->align == 0);
node = c->active_head;
prev = &c->active_head;
......@@ -360,19 +365,19 @@ static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int widt
while (tail) {
int xpos = tail->x - width;
int y,waste;
assert(xpos >= 0);
STBRP_ASSERT(xpos >= 0);
// find the left position that matches this
while (node->next->x <= xpos) {
prev = &node->next;
node = node->next;
}
assert(node->next->x > xpos && node->x <= xpos);
STBRP_ASSERT(node->next->x > xpos && node->x <= xpos);
y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste);
if (y + height < c->height) {
if (y <= best_y) {
if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) {
best_x = xpos;
assert(y <= best_y);
STBRP_ASSERT(y <= best_y);
best_y = y;
best_waste = waste;
best = prev;
......@@ -444,10 +449,10 @@ static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, i
#ifdef _DEBUG
cur = context->active_head;
while (cur->x < context->width) {
assert(cur->x < cur->next->x);
STBRP_ASSERT(cur->x < cur->next->x);
cur = cur->next;
}
assert(cur->next == NULL);
STBRP_ASSERT(cur->next == NULL);
{
stbrp_node *L1 = NULL, *L2 = NULL;
......@@ -464,7 +469,7 @@ static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, i
cur = cur->next;
++count;
}
assert(count == context->num_nodes+2);
STBRP_ASSERT(count == context->num_nodes+2);
}
#endif
......@@ -514,7 +519,7 @@ STBRP_DEF void stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int n
for (i=0; i < num_rects; ++i) {
rects[i].was_packed = i;
#ifndef STBRP_LARGE_RECTS
assert(rects[i].w <= 0xffff && rects[i].h <= 0xffff);
STBRP_ASSERT(rects[i].w <= 0xffff && rects[i].h <= 0xffff);
#endif
}
......
......@@ -40,6 +40,8 @@
//
// VERSION HISTORY
//
// 1.01 (2014-12-08) fix subpixel position when oversampling to exactly match
// non-oversampled; STBTT_POINT_SIZE for packed case only
// 1.00 (2014-12-06) add new PackBegin etc. API, w/ support for oversampling
// 0.99 (2014-09-18) fix multiple bugs with subpixel rendering (ryg)
// 0.9 (2014-08-07) support certain mac/iOS fonts without an MS platformID
......@@ -490,13 +492,6 @@ typedef struct
} stbtt_packedchar;
typedef struct stbtt_pack_context stbtt_pack_context;
typedef struct
{
float font_size;
int first_unicode_char_in_range;
int num_chars_in_range;
stbtt_packedchar *chardata_for_range; // output
} stbtt_pack_range;
extern int stbtt_PackBegin(stbtt_pack_context *spc, unsigned char *pixels, int width, int height, int stride_in_bytes, int padding, void *alloc_context);
// Initializes a packing context stored in the passed-in stbtt_pack_context.
......@@ -512,13 +507,30 @@ extern int stbtt_PackBegin(stbtt_pack_context *spc, unsigned char *pixels, int
extern void stbtt_PackEnd (stbtt_pack_context *spc);
// Cleans up the packing context and frees all memory.
extern int stbtt_PackFontRange(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, float pixel_height,
#define STBTT_POINT_SIZE(x) (-(x))
extern int stbtt_PackFontRange(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_char_in_range;
int num_chars_in_range;
stbtt_packedchar *chardata_for_range; // output
} stbtt_pack_range;
extern int stbtt_PackFontRanges(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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册