Skip to content
Myr

allow font ranges with first_char = 0;

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

fix divide by 0 for exactly-vertical edges; fix possible divide by 0 for exactly-horizontal edges add documentation for stbtt_Rasterize;

authored by Sean Barrett · committed by Sean Barrett · parent 54b1879 · Browse files · 2 files+25 added−9 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+25 added−9 removed

  • tests:+12 added−0 removed
  • other:+13 added−9 removed

2 files+25 added−9 removed

modified:tests/test_truetype.c+12 added
22 unmodified lines
23#define BITMAP_H 51224unsigned char temp_bitmap[BITMAP_H][BITMAP_W];25stbtt_bakedchar cdata[256*2]; // ASCII 32..126 is 95 glyphs26stbtt_packedchar pdata[256*2];2728int main(int argc, char **argv)29{30 stbtt_fontinfo font;31 unsigned char *bitmap;
3 unmodified lines
3536 // @TODO: why is minglui.ttc failing? 37 fread(ttf_buffer, 1, 1<<25, fopen(argc > 3 ? argv[3] : "c:/windows/fonts/mingliu.ttc", "rb"));3839 //fread(ttf_buffer, 1, 1<<25, fopen(argc > 3 ? argv[3] : "c:/x/DroidSansMono.ttf", "rb"));40 {41 static stbtt_pack_context pc;42 static stbtt_packedchar cd[256];43 static unsigned char atlas[1024*1024];4445 stbtt_PackBegin(&pc, atlas, 1024,1024,1024,1,NULL);46 stbtt_PackFontRange(&pc, ttf_buffer, 0, 32.0, 0, 256, cd);47 stbtt_PackEnd(&pc);48 }4950#if 051 stbtt_BakeFontBitmap(ttf_buffer,stbtt_GetFontOffsetForIndex(ttf_buffer,0), 40.0, temp_bitmap[0],BITMAP_W,BITMAP_H, 32,96, cdata); // no guarantee this fits!52 stbi_write_png("fonttest1.png", BITMAP_W, BITMAP_H, 1, temp_bitmap, 0);53
42 unmodified lines
modified:stb_truetype.h+13 added-9 removed
39 unmodified lines
40// github:aloucks41// Peter LaValle42// Sergey Popov43// Giumo X. Clanjor44// Higor Euripedes45//46// Misc other:47// Ryan Gordon48//49// VERSION HISTORY50//50// 1.08 (2015-09-13) document stbtt_Rasterize()51// 1.08 (2015-09-13) document stbtt_Rasterize(); fixes for vertical & horizontal edges52// 1.07 (2015-08-01) allow PackFontRanges to accept arrays of sparse codepoints;53// variant PackFontRanges to pack and render in separate phases;54// fix stbtt_GetFontOFfsetForIndex (never worked for non-0 input?);55// fixed an assert() bug in the new rasterizer
1639 unmodified lines
1695 float dxdy = (e->x1 - e->x0) / (e->y1 - e->y0);1696 //STBTT_assert(e->y0 <= start_point);1697 if (!z) return z;1698 z->fdx = dxdy;1698 z->fdy = (1/dxdy);1699 z->fdy = dxdy != 0.0f ? (1.0f/dxdy) : 0.0f;1700 z->fx = e->x0 + dxdy * (start_point - e->y0);1701 z->fx -= off_x;1702 z->direction = e->invert ? 1.0f : -1.0f;1703 z->sy = e->y0;
394 unmodified lines
2098 }20992100 // insert all edges that start before the bottom of this scanline2101 while (e->y0 <= scan_y_bottom) {2102 if (e->y0 != e->y1) {2101 stbtt__active_edge *z = stbtt__new_active(&hh, e, off_x, scan_y_top, userdata);2102 STBTT_assert(z->ey >= scan_y_top);2103 // insert at front2104 z->next = active;2105 active = z;2103 stbtt__active_edge *z = stbtt__new_active(&hh, e, off_x, scan_y_top, userdata);2104 STBTT_assert(z->ey >= scan_y_top);2105 // insert at front2106 z->next = active;2107 active = z;2108 }2109 ++e;2110 }21112112 // now process all active edges
734 unmodified lines
2847 ranges[i].h_oversample = (unsigned char) spc->h_oversample;2848 ranges[i].v_oversample = (unsigned char) spc->v_oversample;2849 for (j=0; j < ranges[i].num_chars; ++j) {2850 int x0,y0,x1,y1;2848 int codepoint = ranges[i].first_unicode_codepoint_in_range ? ranges[i].first_unicode_codepoint_in_range + j : ranges[i].array_of_unicode_codepoints[j];2851 int codepoint = ranges[i].array_of_unicode_codepoints == NULL ? ranges[i].first_unicode_codepoint_in_range + j : ranges[i].array_of_unicode_codepoints[j];2852 int glyph = stbtt_FindGlyphIndex(info, codepoint);2853 stbtt_GetGlyphBitmapBoxSubpixel(info,glyph,2854 scale * spc->h_oversample,2855 scale * spc->v_oversample,
32 unmodified lines
2888 stbrp_rect *r = &rects[k];2889 if (r->was_packed) {2890 stbtt_packedchar *bc = &ranges[i].chardata_for_range[j];2891 int advance, lsb, x0,y0,x1,y1;2889 int codepoint = ranges[i].first_unicode_codepoint_in_range ? ranges[i].first_unicode_codepoint_in_range + j : ranges[i].array_of_unicode_codepoints[j];2892 int codepoint = ranges[i].array_of_unicode_codepoints == NULL ? ranges[i].first_unicode_codepoint_in_range + j : ranges[i].array_of_unicode_codepoints[j];2893 int glyph = stbtt_FindGlyphIndex(info, codepoint);2894 stbrp_coord pad = (stbrp_coord) spc->padding;28952896 // pad on left and top
294 unmodified lines
319131923193// FULL VERSION HISTORY3194//3195// 1.08 (2015-09-13) document stbtt_Rasterize(); fixes for vertical & horizontal edges3196// 1.07 (2015-08-01) allow PackFontRanges to accept arrays of sparse codepoints;3197// allow PackFontRanges to pack and render in separate phases;3198// fix stbtt_GetFontOFfsetForIndex (never worked for non-0 input?);3199// fixed an assert() bug in the new rasterizer
36 unmodified lines