255 #ifdef STB_TRUETYPE_IMPLEMENTATION 258 typedef unsigned char stbtt_uint8;
259 typedef signed char stbtt_int8;
260 typedef unsigned short stbtt_uint16;
261 typedef signed short stbtt_int16;
262 typedef unsigned int stbtt_uint32;
263 typedef signed int stbtt_int32;
266 typedef char stbtt__check_size32[
sizeof(stbtt_int32)==4 ? 1 : -1];
267 typedef char stbtt__check_size16[
sizeof(stbtt_int16)==2 ? 1 : -1];
272 #define STBTT_ifloor(x) ((int) floor(x)) 273 #define STBTT_iceil(x) ((int) ceil(x)) 278 #define STBTT_sqrt(x) sqrt(x) 287 #ifndef __STB_INCLUDE_STB_TRUETYPE_H__ 288 #define __STB_INCLUDE_STB_TRUETYPE_H__ 291 #define STBTT_DEF STATIC 293 #define STBTT_DEF extern 313 unsigned char *
pixels,
int pw,
int ph,
314 int first_char,
int num_chars,
332 float *xpos,
float *ypos,
334 int opengl_fillrule);
354 unsigned short x0,y0,x1,
y1;
380 #define STBTT_POINT_SIZE(x) (-(x)) 383 int first_unicode_char_in_range,
int num_chars_in_range,
stbtt_packedchar *chardata_for_range);
434 float *xpos,
float *ypos,
436 int align_to_integer);
533 int codepoint,
int *advanceWidth,
int *leftSideBearing);
543 int *x0,
int *y0,
int *x1,
int *
y1);
548 int glyph_index,
int *advanceWidth,
int *leftSideBearing);
553 int glyph_index,
int *x0,
int *y0,
int *x1,
int *
y1);
572 #define stbtt_vertex_type short 622 float scale_x,
float scale_y,
float shift_x,
float shift_y,
int codepoint,
630 int out_w,
int out_h,
int out_stride,
float scale_x,
float scale_y,
int codepoint);
639 int out_w,
int out_h,
int out_stride,
float scale_x,
float scale_y,
float shift_x,
float shift_y,
int codepoint);
645 float scale_x,
float scale_y,
int *ix0,
int *iy0,
int *ix1,
int *iy1);
655 float scale_x,
float scale_y,
float shift_x,
float shift_y,
int *ix0,
int *iy0,
int *ix1,
int *iy1);
664 float scale_x,
float scale_y,
int glyph,
int *
width,
int *
height,
int *xoff,
int *yoff);
667 float scale_x,
float scale_y,
float shift_x,
float shift_y,
int glyph,
671 int out_w,
int out_h,
int out_stride,
float scale_x,
float scale_y,
int glyph);
674 int out_w,
int out_h,
int out_stride,
float scale_x,
float scale_y,
675 float shift_x,
float shift_y,
int glyph);
678 float scale_y,
int *ix0,
int *iy0,
int *ix1,
int *iy1);
681 float scale_x,
float scale_y,
float shift_x,
float shift_y,
int *ix0,
int *iy0,
int *ix1,
int *iy1);
693 float scale_x,
float scale_y,
float shift_x,
float shift_y,
int x_off,
int y_off,
int invert,
void *userdata);
724 #define STBTT_MACSTYLE_DONTCARE 0 725 #define STBTT_MACSTYLE_BOLD 1 726 #define STBTT_MACSTYLE_ITALIC 2 727 #define STBTT_MACSTYLE_UNDERSCORE 4 728 #define STBTT_MACSTYLE_NONE 8 737 int *
length,
int platformID,
int encodingID,
int languageID,
int nameID);
818 #ifdef STB_TRUETYPE_IMPLEMENTATION 820 #ifndef STBTT_MAX_OVERSAMPLE 821 #define STBTT_MAX_OVERSAMPLE 8 824 typedef int stbtt__test_oversample_pow2[(STBTT_MAX_OVERSAMPLE & (STBTT_MAX_OVERSAMPLE-1)) == 0 ? 1 : -1];
826 #ifndef STBTT_RASTERIZER_VERSION 827 #define STBTT_RASTERIZER_VERSION 2 836 #define ttBYTE(p) (* (stbtt_uint8 *) (p)) 837 #define ttCHAR(p) (* (stbtt_int8 *) (p)) 838 #define ttFixed(p) ttLONG(p) 840 #if defined(MSB_FIRST) && !defined(ALLOW_UNALIGNED_TRUETYPE) 842 #define ttUSHORT(p) (* (stbtt_uint16 *) (p)) 843 #define ttSHORT(p) (* (stbtt_int16 *) (p)) 844 #define ttULONG(p) (* (stbtt_uint32 *) (p)) 845 #define ttLONG(p) (* (stbtt_int32 *) (p)) 849 static stbtt_uint16 ttUSHORT(
const stbtt_uint8 *
p) {
return p[0]*256 +
p[1]; }
850 static stbtt_int16 ttSHORT(
const stbtt_uint8 *
p) {
return p[0]*256 +
p[1]; }
851 static stbtt_uint32 ttULONG(
const stbtt_uint8 *
p) {
return (
p[0]<<24) + (
p[1]<<16) + (
p[2]<<8) +
p[3]; }
852 static stbtt_int32 ttLONG(
const stbtt_uint8 *
p) {
return (
p[0]<<24) + (
p[1]<<16) + (
p[2]<<8) +
p[3]; }
856 #define stbtt_tag4(p,c0,c1,c2,c3) ((p)[0] == (c0) && (p)[1] == (c1) && (p)[2] == (c2) && (p)[3] == (c3)) 857 #define stbtt_tag(p,str) stbtt_tag4(p,str[0],str[1],str[2],str[3]) 859 static int stbtt__isfont(
const stbtt_uint8 *
font)
862 if (stbtt_tag4(
font,
'1',0,0,0))
864 if (stbtt_tag(
font,
"typ1"))
866 if (stbtt_tag(
font,
"OTTO"))
868 if (stbtt_tag4(
font, 0,1,0,0))
874 static stbtt_uint32 stbtt__find_table(stbtt_uint8 *
data, stbtt_uint32 fontstart,
const char *
tag)
877 stbtt_int32 num_tables = ttUSHORT(
data+fontstart+4);
878 stbtt_uint32 tabledir = fontstart + 12;
880 for (i=0; i < num_tables; ++i)
882 stbtt_uint32 loc = tabledir + 16*i;
883 if (stbtt_tag(
data+loc+0,
tag))
884 return ttULONG(
data+loc+8);
892 if (stbtt__isfont(font_collection))
893 return index == 0 ? 0 : -1;
896 if (stbtt_tag(font_collection,
"ttcf"))
899 if (ttULONG(font_collection+4) == 0x00010000 || ttULONG(font_collection+4) == 0x00020000)
901 stbtt_int32
n = ttLONG(font_collection+8);
904 return ttULONG(font_collection+12+
index*14);
912 stbtt_uint8 *
data = (stbtt_uint8 *) data2;
913 stbtt_uint32 cmap,
t;
914 stbtt_int32 i,numTables;
917 info->fontstart = fontstart;
919 cmap = stbtt__find_table(
data, fontstart,
"cmap");
920 info->loca = stbtt__find_table(
data, fontstart,
"loca");
921 info->head = stbtt__find_table(
data, fontstart,
"head");
922 info->glyf = stbtt__find_table(
data, fontstart,
"glyf");
923 info->hhea = stbtt__find_table(
data, fontstart,
"hhea");
924 info->hmtx = stbtt__find_table(
data, fontstart,
"hmtx");
925 info->kern = stbtt__find_table(
data, fontstart,
"kern");
930 t = stbtt__find_table(
data, fontstart,
"maxp");
934 info->numGlyphs = 0xffff;
940 numTables = ttUSHORT(
data + cmap + 2);
942 for (i=0; i < numTables; ++i)
944 stbtt_uint32 encoding_record = cmap + 4 + 8 * i;
948 switch(ttUSHORT(
data+encoding_record))
951 switch (ttUSHORT(
data+encoding_record+2))
956 info->index_map = cmap + ttULONG(
data+encoding_record+4);
964 info->index_map = cmap + ttULONG(
data+encoding_record+4);
968 if (
info->index_map == 0)
971 info->indexToLocFormat = ttUSHORT(
data+
info->head + 50);
978 stbtt_uint32 index_map =
info->index_map;
980 stbtt_uint16
format = ttUSHORT(
data + index_map + 0);
984 stbtt_int32 bytes = ttUSHORT(
data + index_map + 2);
985 if (unicode_codepoint < bytes-6)
986 return ttBYTE(
data + index_map + 6 + unicode_codepoint);
991 stbtt_uint32
first = ttUSHORT(
data + index_map + 6);
992 stbtt_uint32
count = ttUSHORT(
data + index_map + 8);
993 if ((stbtt_uint32) unicode_codepoint >=
first && (stbtt_uint32) unicode_codepoint <
first+
count)
994 return ttUSHORT(
data + index_map + 10 + (unicode_codepoint -
first)*2);
1005 stbtt_uint16 segcount = ttUSHORT(
data+index_map+6) >> 1;
1006 stbtt_uint16 searchRange = ttUSHORT(
data+index_map+8) >> 1;
1007 stbtt_uint16 entrySelector = ttUSHORT(
data+index_map+10);
1008 stbtt_uint16 rangeShift = ttUSHORT(
data+index_map+12) >> 1;
1011 stbtt_uint32 endCount = index_map + 14;
1012 stbtt_uint32 search = endCount;
1014 if (unicode_codepoint > 0xffff)
1019 if (unicode_codepoint >= ttUSHORT(
data + search + rangeShift*2))
1020 search += rangeShift*2;
1024 while (entrySelector)
1028 end = ttUSHORT(
data + search + searchRange*2);
1029 if (unicode_codepoint >
end)
1030 search += searchRange*2;
1037 stbtt_uint16 item = (stbtt_uint16) ((search - endCount) >> 1);
1040 start = ttUSHORT(
data + index_map + 14 + segcount*2 + 2 + 2*item);
1041 if (unicode_codepoint <
start)
1044 offset = ttUSHORT(
data + index_map + 14 + segcount*6 + 2 + 2*item);
1046 return (stbtt_uint16) (unicode_codepoint + ttSHORT(
data + index_map + 14 + segcount*4 + 2 + 2*item));
1048 return ttUSHORT(
data +
offset + (unicode_codepoint-
start)*2 + index_map + 14 + segcount*6 + 2 + 2*item);
1053 stbtt_uint32 ngroups = ttULONG(
data+index_map+12);
1054 stbtt_int32 low,high;
1055 low = 0; high = (stbtt_int32)ngroups;
1059 stbtt_int32 mid = low + ((high-low) >> 1);
1060 stbtt_uint32 start_char = ttULONG(
data+index_map+16+mid*12);
1061 stbtt_uint32 end_char = ttULONG(
data+index_map+16+mid*12+4);
1062 if ((stbtt_uint32) unicode_codepoint < start_char)
1064 else if ((stbtt_uint32) unicode_codepoint > end_char)
1067 stbtt_uint32 start_glyph = ttULONG(
data+index_map+16+mid*12+8);
1069 return start_glyph + unicode_codepoint-start_char;
1085 static void stbtt_setvertex(
stbtt_vertex *
v, stbtt_uint8
type, stbtt_int32
x, stbtt_int32
y, stbtt_int32 cx, stbtt_int32 cy)
1088 v->x = (stbtt_int16)
x;
1089 v->y = (stbtt_int16)
y;
1090 v->cx = (stbtt_int16) cx;
1091 v->cy = (stbtt_int16) cy;
1098 if (glyph_index >=
info->numGlyphs)
1100 if (
info->indexToLocFormat >= 2)
1103 if (
info->indexToLocFormat == 0)
1106 g2 =
info->glyf + ttUSHORT(
info->
data +
info->loca + glyph_index * 2 + 2) * 2;
1114 return g1==g2 ? -1 : g1;
1118 int glyph_index,
int *x0,
int *y0,
int *x1,
int *
y1)
1120 int g = stbtt__GetGlyfOffset(
info, glyph_index);
1121 if (
g < 0)
return 0;
1123 if (x0) *x0 = ttSHORT(
info->
data +
g + 2);
1124 if (y0) *y0 = ttSHORT(
info->
data +
g + 4);
1125 if (x1) *x1 = ttSHORT(
info->
data +
g + 6);
1131 int codepoint,
int *x0,
int *y0,
int *x1,
int *
y1)
1138 stbtt_int16 numberOfContours;
1139 int g = stbtt__GetGlyfOffset(
info, glyph_index);
1140 if (
g < 0)
return 1;
1141 numberOfContours = ttSHORT(
info->
data +
g);
1142 return numberOfContours == 0;
1145 static int stbtt__close_shape(
stbtt_vertex *vertices,
int num_vertices,
int was_off,
int start_off,
1146 stbtt_int32 sx, stbtt_int32 sy, stbtt_int32 scx, stbtt_int32 scy, stbtt_int32 cx, stbtt_int32 cy)
1150 stbtt_setvertex(&vertices[num_vertices++],
STBTT_vcurve, (cx+scx)>>1, (cy+scy)>>1, cx,cy);
1151 stbtt_setvertex(&vertices[num_vertices++],
STBTT_vcurve, sx,sy,scx,scy);
1154 stbtt_setvertex(&vertices[num_vertices++],
STBTT_vcurve,sx,sy,cx,cy);
1156 stbtt_setvertex(&vertices[num_vertices++],
STBTT_vline,sx,sy,0,0);
1158 return num_vertices;
1163 stbtt_int16 numberOfContours;
1164 stbtt_uint8 *endPtsOfContours;
1168 int g = stbtt__GetGlyfOffset(
info, glyph_index);
1172 if (
g < 0)
return 0;
1174 numberOfContours = ttSHORT(
data +
g);
1176 if (numberOfContours > 0) {
1177 stbtt_uint8
flags=0,flagcount;
1178 stbtt_int32 ins, i,
j=0,
m,
n, next_move, was_off=0, off, start_off=0;
1179 stbtt_int32
x,
y,cx,cy,sx,sy, scx,scy;
1181 endPtsOfContours = (
data +
g + 10);
1182 ins = ttUSHORT(
data +
g + 10 + numberOfContours * 2);
1183 points =
data +
g + 10 + numberOfContours * 2 + 2 + ins;
1185 n = 1+ttUSHORT(endPtsOfContours + numberOfContours*2-2);
1187 m =
n + 2*numberOfContours;
1204 for (i=0; i <
n; ++i)
1218 for (i=0; i <
n; ++i)
1223 stbtt_int16 dx = *
points++;
1224 x += (
flags & 16) ? dx : -dx;
1234 vertices[off+i].
x = (stbtt_int16)
x;
1239 for (i=0; i <
n; ++i)
1244 stbtt_int16 dy = *
points++;
1245 y += (
flags & 32) ? dy : -dy;
1249 if (!(
flags & 32)) {
1254 vertices[off+i].
y = (stbtt_int16)
y;
1259 sx = sy = cx = cy = scx = scy = 0;
1260 for (i=0; i <
n; ++i)
1263 x = (stbtt_int16) vertices[off+i].
x;
1264 y = (stbtt_int16) vertices[off+i].
y;
1269 num_vertices = stbtt__close_shape(vertices, num_vertices, was_off, start_off, sx,sy,scx,scy,cx,cy);
1272 start_off = !(
flags & 1);
1281 if (!(vertices[off+i+1].
type & 1))
1284 sx = (
x + (stbtt_int32) vertices[off+i+1].
x) >> 1;
1285 sy = (
y + (stbtt_int32) vertices[off+i+1].
y) >> 1;
1290 sx = (stbtt_int32) vertices[off+i+1].
x;
1291 sy = (stbtt_int32) vertices[off+i+1].
y;
1298 stbtt_setvertex(&vertices[num_vertices++],
STBTT_vmove,sx,sy,0,0);
1300 next_move = 1 + ttUSHORT(endPtsOfContours+
j*2);
1309 stbtt_setvertex(&vertices[num_vertices++],
STBTT_vcurve, (cx+
x)>>1, (cy+
y)>>1, cx, cy);
1317 stbtt_setvertex(&vertices[num_vertices++],
STBTT_vcurve,
x,
y, cx, cy);
1319 stbtt_setvertex(&vertices[num_vertices++],
STBTT_vline,
x,
y,0,0);
1324 num_vertices = stbtt__close_shape(vertices, num_vertices, was_off, start_off, sx,sy,scx,scy,cx,cy);
1326 else if (numberOfContours == -1)
1330 stbtt_uint8 *comp =
data +
g + 10;
1335 stbtt_uint16
flags, gidx;
1336 int comp_num_verts = 0, i;
1338 float mtx[6] = {1,0,0,1,0,0},
m,
n;
1340 flags = ttSHORT(comp); comp+=2;
1341 gidx = ttSHORT(comp); comp+=2;
1348 mtx[4] = ttSHORT(comp); comp+=2;
1349 mtx[5] = ttSHORT(comp); comp+=2;
1353 mtx[4] = ttCHAR(comp); comp+=1;
1354 mtx[5] = ttCHAR(comp); comp+=1;
1365 mtx[0] = mtx[3] = ttSHORT(comp)/16384.0f; comp+=2;
1366 mtx[1] = mtx[2] = 0;
1368 else if (
flags & (1<<6))
1371 mtx[0] = ttSHORT(comp)/16384.0f; comp+=2;
1372 mtx[1] = mtx[2] = 0;
1373 mtx[3] = ttSHORT(comp)/16384.0f; comp+=2;
1375 else if (
flags & (1<<7))
1378 mtx[0] = ttSHORT(comp)/16384.0f; comp+=2;
1379 mtx[1] = ttSHORT(comp)/16384.0f; comp+=2;
1380 mtx[2] = ttSHORT(comp)/16384.0f; comp+=2;
1381 mtx[3] = ttSHORT(comp)/16384.0f; comp+=2;
1385 m = (float) STBTT_sqrt(mtx[0]*mtx[0] + mtx[1]*mtx[1]);
1386 n = (float) STBTT_sqrt(mtx[2]*mtx[2] + mtx[3]*mtx[3]);
1390 if (comp_num_verts > 0)
1393 for (i = 0; i < comp_num_verts; ++i)
1415 if (num_vertices > 0)
1424 num_vertices += comp_num_verts;
1427 more =
flags & (1<<5);
1430 else if (numberOfContours < 0)
1440 *pvertices = vertices;
1441 return num_vertices;
1445 int glyph_index,
int *advanceWidth,
int *leftSideBearing)
1447 stbtt_uint16 numOfLongHorMetrics = ttUSHORT(
info->
data+
info->hhea + 34);
1448 if (glyph_index < numOfLongHorMetrics)
1451 *advanceWidth = ttSHORT(
info->
data +
info->hmtx + 4*glyph_index);
1452 if (leftSideBearing)
1453 *leftSideBearing = ttSHORT(
info->
data +
info->hmtx + 4*glyph_index + 2);
1458 *advanceWidth = ttSHORT(
info->
data +
info->hmtx + 4*(numOfLongHorMetrics-1));
1459 if (leftSideBearing)
1460 *leftSideBearing = ttSHORT(
info->
data +
info->hmtx + 4*numOfLongHorMetrics + 2*(glyph_index - numOfLongHorMetrics));
1467 stbtt_uint32 needle, straw;
1473 if (ttUSHORT(
data+2) < 1)
1475 if (ttUSHORT(
data+8) != 1)
1479 r = ttUSHORT(
data+10) - 1;
1480 needle = glyph1 << 16 | glyph2;
1483 straw = ttULONG(
data+18+(
m*6));
1486 else if (needle > straw)
1489 return ttSHORT(
data+22+(
m*6));
1502 int codepoint,
int *advanceWidth,
int *leftSideBearing)
1508 int *ascent,
int *descent,
int *lineGap)
1510 if (ascent ) *ascent = ttSHORT(
info->
data+
info->hhea + 4);
1511 if (descent) *descent = ttSHORT(
info->
data+
info->hhea + 6);
1512 if (lineGap) *lineGap = ttSHORT(
info->
data+
info->hhea + 8);
1516 int *x0,
int *y0,
int *x1,
int *
y1)
1527 return (
float)
height / fheight;
1532 int unitsPerEm = ttUSHORT(
info->
data +
info->head + 18);
1533 return pixels / unitsPerEm;
1544 int glyph,
float scale_x,
float scale_y,
float shift_x,
float shift_y,
1545 int *ix0,
int *iy0,
int *ix1,
int *iy1)
1560 if (ix0) *ix0 = STBTT_ifloor( x0 * scale_x + shift_x);
1561 if (iy0) *iy0 = STBTT_ifloor(-
y1 * scale_y + shift_y);
1562 if (ix1) *ix1 = STBTT_iceil ( x1 * scale_x + shift_x);
1563 if (iy1) *iy1 = STBTT_iceil (-y0 * scale_y + shift_y);
1568 int *ix0,
int *iy0,
int *ix1,
int *iy1)
1574 float shift_x,
float shift_y,
int *ix0,
int *iy0,
int *ix1,
int *iy1)
1576 stbtt_GetGlyphBitmapBoxSubpixel(
font,
stbtt_FindGlyphIndex(
font,
codepoint), scale_x, scale_y,shift_x,shift_y, ix0,iy0,ix1,iy1);
1580 int *ix0,
int *iy0,
int *ix1,
int *iy1)
1587 typedef struct stbtt__hheap_chunk
1589 struct stbtt__hheap_chunk *
next;
1590 } stbtt__hheap_chunk;
1592 typedef struct stbtt__hheap
1594 struct stbtt__hheap_chunk *
head;
1596 int num_remaining_in_head_chunk;
1599 static void *stbtt__hheap_alloc(stbtt__hheap *hh,
size_t size,
void *userdata)
1601 if (hh->first_free) {
1602 void *
p = hh->first_free;
1603 hh->first_free = * (
void **)
p;
1606 if (hh->num_remaining_in_head_chunk == 0) {
1608 stbtt__hheap_chunk *
c = (stbtt__hheap_chunk *)
1614 hh->num_remaining_in_head_chunk =
count;
1616 --hh->num_remaining_in_head_chunk;
1617 return (
char *) (hh->head) +
size * hh->num_remaining_in_head_chunk;
1621 static void stbtt__hheap_free(stbtt__hheap *hh,
void *
p)
1623 *(
void **)
p = hh->first_free;
1627 static void stbtt__hheap_cleanup(stbtt__hheap *hh,
void *userdata)
1629 stbtt__hheap_chunk *
c = hh->head;
1631 stbtt__hheap_chunk *
n =
c->next;
1637 typedef struct stbtt__edge {
1643 typedef struct stbtt__active_edge
1645 struct stbtt__active_edge *
next;
1646 #if STBTT_RASTERIZER_VERSION==1 1650 #elif STBTT_RASTERIZER_VERSION==2 1656 #error "Unrecognized value of STBTT_RASTERIZER_VERSION" 1658 } stbtt__active_edge;
1660 #if STBTT_RASTERIZER_VERSION == 1 1661 #define STBTT_FIXSHIFT 10 1662 #define STBTT_FIX (1 << STBTT_FIXSHIFT) 1663 #define STBTT_FIXMASK (STBTT_FIX-1) 1665 static stbtt__active_edge *stbtt__new_active(stbtt__hheap *hh, stbtt__edge *e,
int off_x,
float start_point,
void *userdata)
1667 stbtt__active_edge *
z = (stbtt__active_edge *) stbtt__hheap_alloc(hh,
sizeof(*
z), userdata);
1668 float dxdy = (e->x1 - e->x0) / (e->y1 - e->y0);
1673 z->dx = -STBTT_ifloor(STBTT_FIX * -dxdy);
1675 z->dx = STBTT_ifloor(STBTT_FIX * dxdy);
1677 z->x = STBTT_ifloor(STBTT_FIX * e->x0 +
z->dx * (start_point - e->y0));
1678 z->x -= off_x * STBTT_FIX;
1682 z->direction = e->invert ? 1 : -1;
1685 #elif STBTT_RASTERIZER_VERSION == 2 1686 static stbtt__active_edge *stbtt__new_active(stbtt__hheap *hh, stbtt__edge *e,
int off_x,
float start_point,
void *userdata)
1688 stbtt__active_edge *
z = (stbtt__active_edge *) stbtt__hheap_alloc(hh,
sizeof(*
z), userdata);
1689 float dxdy = (e->x1 - e->x0) / (e->y1 - e->y0);
1693 z->fx = e->x0 + dxdy * (start_point - e->y0);
1695 z->direction = e->invert ? 1.0f : -1.0f;
1702 #error "Unrecognized value of STBTT_RASTERIZER_VERSION" 1705 #if STBTT_RASTERIZER_VERSION == 1 1710 static void stbtt__fill_active_edges(
unsigned char *scanline,
int len, stbtt__active_edge *e,
int max_weight)
1720 x0 = e->x;
w += e->direction;
1724 int x1 = e->x;
w += e->direction;
1729 int i = x0 >> STBTT_FIXSHIFT;
1730 int j = x1 >> STBTT_FIXSHIFT;
1732 if (i < len && j >= 0) {
1735 scanline[i] = scanline[i] + (stbtt_uint8) ((x1 - x0) * max_weight >> STBTT_FIXSHIFT);
1738 scanline[i] = scanline[i] + (stbtt_uint8) (((STBTT_FIX - (x0 & STBTT_FIXMASK)) * max_weight) >> STBTT_FIXSHIFT);
1743 scanline[
j] = scanline[
j] + (stbtt_uint8) (((x1 & STBTT_FIXMASK) * max_weight) >> STBTT_FIXSHIFT);
1747 for (++i; i <
j; ++i)
1748 scanline[i] = scanline[i] + (stbtt_uint8) max_weight;
1759 int vsubsample,
int off_x,
int off_y,
void *userdata)
1761 unsigned char scanline_data[512], *scanline;
1762 stbtt__hheap hh = { 0 };
1763 stbtt__active_edge *active =
NULL;
1765 int max_weight = (255 / vsubsample);
1771 scanline = scanline_data;
1773 y = off_y * vsubsample;
1774 e[
n].y0 = (off_y +
result->h) * (
float) vsubsample + 1;
1778 for (
s=0;
s < vsubsample; ++
s) {
1780 float scan_y =
y + 0.5f;
1781 stbtt__active_edge **step = &active;
1786 stbtt__active_edge *
z = *step;
1787 if (
z->ey <= scan_y) {
1791 stbtt__hheap_free(&hh,
z);
1794 step = &((*step)->next);
1802 while (*step && (*step)->next) {
1803 if ((*step)->x > (*step)->next->x) {
1804 stbtt__active_edge *
t = *step;
1805 stbtt__active_edge *
q =
t->next;
1812 step = &(*step)->next;
1818 while (e->y0 <= scan_y) {
1819 if (e->y1 > scan_y) {
1820 stbtt__active_edge *
z = stbtt__new_active(&hh, e, off_x, scan_y, userdata);
1824 else if (
z->x < active->x) {
1830 stbtt__active_edge *
p = active;
1831 while (
p->next &&
p->next->x <
z->x)
1843 stbtt__fill_active_edges(scanline,
result->w, active, max_weight);
1851 stbtt__hheap_cleanup(&hh, userdata);
1853 if (scanline != scanline_data)
1857 #elif STBTT_RASTERIZER_VERSION == 2 1862 static void stbtt__handle_clipped_edge(
float *scanline,
int x, stbtt__active_edge *e,
1863 float x0,
float y0,
float x1,
float y1)
1865 if (y0 ==
y1)
return;
1867 assert(e->sy <= e->ey);
1868 if (y0 > e->ey)
return;
1871 x0 += (x1-x0) * (e->sy - y0) / (
y1-y0);
1875 x1 += (x1-x0) * (e->ey -
y1) / (
y1-y0);
1888 assert(x1 >=
x && x1 <=
x+1);
1890 if (x0 <=
x && x1 <=
x)
1891 scanline[
x] += e->direction * (
y1-y0);
1892 else if (x0 >=
x+1 && x1 >=
x+1)
1895 assert(x0 >=
x && x0 <= x+1 && x1 >=
x && x1 <=
x+1);
1896 scanline[
x] += e->direction * (
y1-y0) * (1-((x0-
x)+(x1-
x))/2);
1900 static void stbtt__fill_active_edges_new(
float *scanline,
float *scanline_fill,
1901 int len, stbtt__active_edge *e,
float y_top)
1903 float y_bottom = y_top+1;
1910 assert(e->ey >= y_top);
1916 stbtt__handle_clipped_edge(scanline,(
int) x0,e, x0,y_top, x0,y_bottom);
1917 stbtt__handle_clipped_edge(scanline_fill-1,(
int) x0+1,e, x0,y_top, x0,y_bottom);
1919 stbtt__handle_clipped_edge(scanline_fill-1,0,e, x0,y_top, x0,y_bottom);
1926 float x_top, x_bottom;
1929 assert(e->sy <= y_bottom && e->ey >= y_top);
1935 if (e->sy > y_top) {
1936 x_top = x0 + dx * (e->sy - y_top);
1942 if (e->ey < y_bottom) {
1943 x_bottom = x0 + dx * (e->ey - y_top);
1950 if (x_top >= 0 && x_bottom >= 0 && x_top <
len && x_bottom <
len)
1954 if ((
int) x_top == (int) x_bottom)
1959 int x = (int) x_top;
1961 assert(
x >= 0 &&
x <
len);
1962 scanline[
x] += e->direction * (1-((x_top -
x) + (x_bottom-
x))/2) *
height;
1963 scanline_fill[
x] += e->direction *
height;
1968 float y_crossing, step,
sign, area;
1971 if (x_top > x_bottom)
1975 y0 = y_bottom - (y0 - y_top);
1976 y1 = y_bottom - (
y1 - y_top);
1978 t = x_bottom, x_bottom = x_top, x_top =
t;
1981 t = x0, x0 = xb, xb =
t;
1985 x2 = (int) x_bottom;
1987 y_crossing = (x1+1 - x0) * dy + y_top;
1989 sign = e->direction;
1991 area =
sign * (y_crossing-y0);
1993 scanline[x1] += area * (1-((x_top - x1)+(x1+1-x1))/2);
1996 for (
x = x1+1;
x <
x2; ++
x)
1998 scanline[
x] += area + step/2;
2001 y_crossing += dy * (
x2 - (x1+1));
2003 assert(
fabs(area) <= 1.01
f);
2005 scanline[
x2] += area +
sign * (1-((
x2-
x2)+(x_bottom-
x2))/2) * (
y1-y_crossing);
2007 scanline_fill[
x2] +=
sign * (
y1-y0);
2028 float y_cur = y_top, x_cur = x0;
2030 y0 = (
x - x0) / dx + y_top;
2031 y1 = (
x+1 - x0) / dx + y_top;
2034 if (y0 > y_top && y0 < y_bottom) {
2035 stbtt__handle_clipped_edge(scanline,
x,e, x_cur,y_cur, (
float)
x,y0);
2039 if (
y1 >= y_cur &&
y1 < y_bottom) {
2040 stbtt__handle_clipped_edge(scanline,
x,e, x_cur,y_cur, (
float)
x+1,
y1);
2042 x_cur = (float)
x+1;
2045 if (
y1 >= y_cur &&
y1 < y_bottom) {
2046 stbtt__handle_clipped_edge(scanline,
x,e, x_cur,y_cur, (
float)
x+1,
y1);
2048 x_cur = (float)
x+1;
2050 if (y0 > y_top && y0 < y_bottom) {
2051 stbtt__handle_clipped_edge(scanline,
x,e, x_cur,y_cur, (
float)
x,y0);
2056 stbtt__handle_clipped_edge(scanline,
x,e, x_cur,y_cur, xb,y_bottom);
2066 int n,
int vsubsample,
int off_x,
int off_y,
void *userdata)
2068 stbtt__hheap hh = { 0 };
2069 stbtt__active_edge *active =
NULL;
2071 float scanline_data[129], *scanline, *scanline2;
2074 scanline = (
float *)
malloc((
result->w*2+1) *
sizeof(float));
2076 scanline = scanline_data;
2078 scanline2 = scanline +
result->w;
2081 e[
n].y0 = (float) (off_y +
result->h) + 1;
2085 float scan_y_top =
y + 0.0f;
2086 float scan_y_bottom =
y + 1.0f;
2087 stbtt__active_edge **step = &active;
2092 memset(scanline2, 0, (
result->w+1)*
sizeof(scanline[0]));
2098 stbtt__active_edge *
z = *step;
2099 if (
z->ey <= scan_y_top) {
2103 stbtt__hheap_free(&hh,
z);
2105 step = &((*step)->next);
2110 while (e->y0 <= scan_y_bottom)
2112 stbtt__active_edge *
z = stbtt__new_active(&hh, e, off_x, scan_y_top, userdata);
2113 assert(
z->ey >= scan_y_top);
2123 stbtt__fill_active_edges_new(scanline, scanline2+1,
result->w, active, scan_y_top);
2127 for (i=0; i <
result->w; ++i)
2131 sum += scanline2[i];
2132 k = scanline[i] + sum;
2133 k = (float)
fabs(k)*255 + 0.5f;
2135 if (
m > 255)
m = 255;
2146 stbtt__active_edge *
z = *step;
2148 step = &((*step)->next);
2155 stbtt__hheap_cleanup(&hh, userdata);
2157 if (scanline != scanline_data)
2161 #error "Unrecognized value of STBTT_RASTERIZER_VERSION" 2164 #define STBTT__COMPARE(a,b) ((a)->y0 < (b)->y0) 2166 static void stbtt__sort_edges_ins_sort(stbtt__edge *
p,
int n)
2169 for (i=1; i <
n; ++i) {
2170 stbtt__edge
t =
p[i], *
a = &
t;
2173 stbtt__edge *
b = &
p[
j-1];
2174 int c = STBTT__COMPARE(
a,
b);
2184 static void stbtt__sort_edges_quicksort(stbtt__edge *
p,
int n)
2189 int c01,c12,
c,
m,i,
j;
2193 c01 = STBTT__COMPARE(&
p[0],&
p[
m]);
2194 c12 = STBTT__COMPARE(&
p[
m],&
p[
n-1]);
2199 c = STBTT__COMPARE(&
p[0],&
p[
n-1]);
2202 z = (
c == c12) ? 0 :
n-1;
2220 if (!STBTT__COMPARE(&
p[i], &
p[0]))
break;
2223 if (!STBTT__COMPARE(&
p[0], &
p[
j]))
break;
2236 stbtt__sort_edges_quicksort(
p,
j);
2240 stbtt__sort_edges_quicksort(
p+i,
n-i);
2246 static void stbtt__sort_edges(stbtt__edge *
p,
int n)
2248 stbtt__sort_edges_quicksort(
p,
n);
2249 stbtt__sort_edges_ins_sort(
p,
n);
2257 static void stbtt__rasterize(
stbtt__bitmap *
result, stbtt__point *pts,
int *wcount,
int windings,
2258 float scale_x,
float scale_y,
float shift_x,
float shift_y,
2259 int off_x,
int off_y,
int invert,
void *userdata)
2261 float y_scale_inv =
invert ? -scale_y : scale_y;
2264 #if STBTT_RASTERIZER_VERSION == 1 2265 int vsubsample =
result->h < 8 ? 15 : 5;
2266 #elif STBTT_RASTERIZER_VERSION == 2 2269 #error "Unrecognized value of STBTT_RASTERIZER_VERSION" 2275 for (i=0; i < windings; ++i)
2278 e = (stbtt__edge *)
malloc(
sizeof(*e) * (
n+1));
2283 for (i=0; i < windings; ++i) {
2284 stbtt__point *
p = pts +
m;
2287 for (k=0; k < wcount[i];
j=k++) {
2290 if (
p[
j].
y ==
p[k].
y)
2298 e[
n].x0 =
p[
a].x * scale_x + shift_x;
2299 e[
n].y0 = (
p[
a].y * y_scale_inv + shift_y) * vsubsample;
2300 e[
n].x1 =
p[
b].x * scale_x + shift_x;
2301 e[
n].y1 = (
p[
b].y * y_scale_inv + shift_y) * vsubsample;
2307 stbtt__sort_edges(e,
n);
2311 stbtt__rasterize_sorted_edges(
result, e,
n, vsubsample, off_x, off_y, userdata);
2316 static void stbtt__add_point(stbtt__point *
points,
int n,
float x,
float y)
2324 static int stbtt__tesselate_curve(stbtt__point *
points,
int *num_points,
2325 float x0,
float y0,
float x1,
float y1,
float x2,
float y2,
float objspace_flatness_squared,
int n)
2328 float mx = (x0 + 2*x1 +
x2)/4;
2329 float my = (y0 + 2*
y1 +
y2)/4;
2331 float dx = (x0+
x2)/2 - mx;
2332 float dy = (y0+
y2)/2 - my;
2336 if (dx*dx+dy*dy > objspace_flatness_squared)
2339 stbtt__tesselate_curve(
points, num_points, x0,y0, (x0+x1)/2.0
f,(y0+
y1)/2.0
f, mx,my, objspace_flatness_squared,
n+1);
2340 stbtt__tesselate_curve(
points, num_points, mx,my, (x1+
x2)/2.0
f,(
y1+
y2)/2.0
f,
x2,
y2, objspace_flatness_squared,
n+1);
2345 *num_points = *num_points+1;
2351 static stbtt__point *stbtt_FlattenCurves(
stbtt_vertex *vertices,
int num_verts,
2352 float objspace_flatness,
int **contour_lengths,
int *num_contours,
void *userdata)
2357 float objspace_flatness_squared = objspace_flatness * objspace_flatness;
2361 for (i=0; i < num_verts; ++i)
2366 if (
n == 0)
return 0;
2368 *contour_lengths = (
int *)
malloc(
sizeof(**contour_lengths) *
n);
2370 if (*contour_lengths == 0) {
2376 for (pass=0; pass < 2; ++pass)
2388 for (i=0; i < num_verts; ++i)
2390 switch (vertices[i].
type)
2395 (*contour_lengths)[
n] = num_points -
start;
2399 x = vertices[i].
x,
y = vertices[i].
y;
2400 stbtt__add_point(
points, num_points++,
x,
y);
2403 x = vertices[i].
x,
y = vertices[i].
y;
2404 stbtt__add_point(
points, num_points++,
x,
y);
2407 stbtt__tesselate_curve(
points, &num_points,
x,
y,
2408 vertices[i].cx, vertices[i].cy,
2409 vertices[i].
x, vertices[i].
y,
2410 objspace_flatness_squared, 0);
2411 x = vertices[i].
x,
y = vertices[i].
y;
2415 (*contour_lengths)[
n] = num_points -
start;
2421 free(*contour_lengths);
2422 *contour_lengths = 0;
2428 stbtt_vertex *vertices,
int num_verts,
float scale_x,
float scale_y,
2429 float shift_x,
float shift_y,
int x_off,
int y_off,
int invert,
void *userdata)
2431 float scale = scale_x > scale_y ? scale_y : scale_x;
2432 int winding_count = 0;
2433 int *winding_lengths =
NULL;
2434 stbtt__point *windings = stbtt_FlattenCurves(vertices, num_verts, flatness_in_pixels /
scale, &winding_lengths, &winding_count, userdata);
2437 stbtt__rasterize(
result, windings, winding_lengths, winding_count, scale_x, scale_y, shift_x, shift_y, x_off, y_off,
invert, userdata);
2438 free(winding_lengths);
2449 float shift_x,
float shift_y,
int glyph,
int *
width,
int *
height,
int *xoff,
int *yoff)
2451 int ix0,iy0,ix1,iy1;
2456 if (scale_x == 0) scale_x = scale_y;
2467 gbm.
w = (ix1 - ix0);
2468 gbm.
h = (iy1 - iy0);
2473 if (xoff ) *xoff = ix0;
2474 if (yoff ) *yoff = iy0;
2483 stbtt_Rasterize(&gbm, 0.35
f, vertices, num_verts, scale_x, scale_y, shift_x, shift_y, ix0, iy0, 1,
info->userdata);
2492 int glyph,
int *
width,
int *
height,
int *xoff,
int *yoff)
2498 int out_w,
int out_h,
int out_stride,
2499 float scale_x,
float scale_y,
float shift_x,
float shift_y,
int glyph)
2513 stbtt_Rasterize(&gbm, 0.35
f, vertices, num_verts, scale_x, scale_y, shift_x, shift_y, ix0,iy0, 1,
info->userdata);
2519 int out_w,
int out_h,
int out_stride,
float scale_x,
float scale_y,
int glyph)
2525 float scale_x,
float scale_y,
float shift_x,
float shift_y,
int codepoint,
2533 int out_w,
int out_h,
int out_stride,
float scale_x,
float scale_y,
2534 float shift_x,
float shift_y,
int codepoint)
2546 unsigned char *
output,
int out_w,
int out_h,
2547 int out_stride,
float scale_x,
float scale_y,
int codepoint)
2550 out_stride, scale_x, scale_y, 0.0
f,0.0
f,
codepoint);
2561 unsigned char *
pixels,
int pw,
int ph,
2562 int first_char,
int num_chars,
2566 int x,
y,bottom_y, i;
2576 for (i=0; i < num_chars; ++i) {
2577 int advance, lsb, x0,y0,x1,
y1,gw,gh;
2583 if (
x + gw + 1 >= pw)
2584 y = bottom_y,
x = 1;
2585 if (
y + gh + 1 >= ph)
2590 chardata[i].
x0 = (stbtt_int16)
x;
2591 chardata[i].
y0 = (stbtt_int16)
y;
2592 chardata[i].
x1 = (stbtt_int16) (
x + gw);
2593 chardata[i].
y1 = (stbtt_int16) (
y + gh);
2595 chardata[i].
xoff = (float) x0;
2596 chardata[i].
yoff = (float) y0;
2598 if (
y+gh+1 > bottom_y)
2605 int char_index,
float *xpos,
float *ypos,
2608 float d3d_bias = opengl_fillrule ? 0 : -0.5f;
2609 float ipw = 1.0f / pw, iph = 1.0f / ph;
2611 int round_x = STBTT_ifloor((*xpos +
b->xoff) + 0.5f);
2612 int round_y = STBTT_ifloor((*ypos +
b->yoff) + 0.5f);
2614 q->x0 = round_x + d3d_bias;
2615 q->y0 = round_y + d3d_bias;
2616 q->x1 = round_x +
b->x1 -
b->x0 + d3d_bias;
2617 q->y1 = round_y +
b->y1 -
b->y0 + d3d_bias;
2619 q->s0 =
b->x0 * ipw;
2620 q->t0 =
b->y0 * iph;
2621 q->s1 =
b->x1 * ipw;
2622 q->t1 =
b->y1 * iph;
2624 *xpos +=
b->xadvance;
2629 #ifndef STB_RECT_PACK_VERSION 2631 #define STBTT__NOTUSED(v) (void)(v) 2633 #define STBTT__NOTUSED(v) (void)sizeof(v) 2659 int id,
w,
h,was_packed;
2670 STBTT__NOTUSED(nodes);
2671 STBTT__NOTUSED(num_nodes);
2678 for (i=0; i < num_rects; ++i)
2680 if (con->x + rects[i].w > con->
width)
2683 con->y = con->bottom_y;
2686 if (con->y + rects[i].h > con->
height)
2689 rects[i].
x = con->x;
2690 rects[i].
y = con->y;
2692 con->x += rects[i].
w;
2694 if (con->y + rects[i].h > con->bottom_y)
2695 con->bottom_y = con->y + rects[i].
h;
2697 for ( ; i < num_rects; ++i)
2698 rects[i].was_packed = 0;
2709 int pw,
int ph,
int stride_in_bytes,
int padding,
void *alloc_context)
2712 int num_nodes = pw - padding;
2715 if (context ==
NULL || nodes ==
NULL)
2717 if (context !=
NULL)
2749 unsigned int h_oversample,
unsigned int v_oversample)
2753 if (h_oversample <= STBTT_MAX_OVERSAMPLE)
2755 if (v_oversample <= STBTT_MAX_OVERSAMPLE)
2759 #define STBTT__OVER_MASK (STBTT_MAX_OVERSAMPLE-1) 2761 static void stbtt__h_prefilter(
unsigned char *
pixels,
int w,
int h,
2762 int stride_in_bytes,
unsigned int kernel_width)
2765 unsigned char buffer[STBTT_MAX_OVERSAMPLE];
2766 int safe_w =
w - kernel_width;
2768 for (
j=0;
j <
h; ++
j)
2778 switch (kernel_width) {
2780 for (i=0; i <= safe_w; ++i) {
2782 buffer[(i+kernel_width) & STBTT__OVER_MASK] =
pixels[i];
2783 pixels[i] = (
unsigned char) (total / 2);
2787 for (i=0; i <= safe_w; ++i) {
2789 buffer[(i+kernel_width) & STBTT__OVER_MASK] =
pixels[i];
2790 pixels[i] = (
unsigned char) (total / 3);
2794 for (i=0; i <= safe_w; ++i) {
2796 buffer[(i+kernel_width) & STBTT__OVER_MASK] =
pixels[i];
2797 pixels[i] = (
unsigned char) (total / 4);
2801 for (i=0; i <= safe_w; ++i) {
2803 buffer[(i+kernel_width) & STBTT__OVER_MASK] =
pixels[i];
2804 pixels[i] = (
unsigned char) (total / kernel_width);
2812 total -=
buffer[i & STBTT__OVER_MASK];
2813 pixels[i] = (
unsigned char) (total / kernel_width);
2816 pixels += stride_in_bytes;
2820 static void stbtt__v_prefilter(
unsigned char *
pixels,
int w,
int h,
int stride_in_bytes,
unsigned int kernel_width)
2823 unsigned char buffer[STBTT_MAX_OVERSAMPLE];
2824 int safe_h =
h - kernel_width;
2826 for (
j=0;
j <
w; ++
j)
2829 unsigned int total = 0;
2834 switch (kernel_width)
2837 for (i=0; i <= safe_h; ++i)
2839 total +=
pixels[i*stride_in_bytes] -
buffer[i & STBTT__OVER_MASK];
2840 buffer[(i+kernel_width) & STBTT__OVER_MASK] =
pixels[i*stride_in_bytes];
2841 pixels[i*stride_in_bytes] = (
unsigned char) (total / 2);
2845 for (i=0; i <= safe_h; ++i)
2847 total +=
pixels[i*stride_in_bytes] -
buffer[i & STBTT__OVER_MASK];
2848 buffer[(i+kernel_width) & STBTT__OVER_MASK] =
pixels[i*stride_in_bytes];
2849 pixels[i*stride_in_bytes] = (
unsigned char) (total / 3);
2853 for (i=0; i <= safe_h; ++i)
2855 total +=
pixels[i*stride_in_bytes] -
buffer[i & STBTT__OVER_MASK];
2856 buffer[(i+kernel_width) & STBTT__OVER_MASK] =
pixels[i*stride_in_bytes];
2857 pixels[i*stride_in_bytes] = (
unsigned char) (total / 4);
2861 for (i=0; i <= safe_h; ++i)
2863 total +=
pixels[i*stride_in_bytes] -
buffer[i & STBTT__OVER_MASK];
2864 buffer[(i+kernel_width) & STBTT__OVER_MASK] =
pixels[i*stride_in_bytes];
2865 pixels[i*stride_in_bytes] = (
unsigned char) (total / kernel_width);
2873 total -=
buffer[i & STBTT__OVER_MASK];
2874 pixels[i*stride_in_bytes] = (
unsigned char) (total / kernel_width);
2881 static float stbtt__oversample_shift(
int oversample)
2890 return (
float)-(oversample - 1) / (2.0
f * (
float)oversample);
2900 float sub_x = stbtt__oversample_shift(spc->
h_oversample);
2901 float sub_y = stbtt__oversample_shift(spc->
v_oversample);
2902 int i,
j,k,
n, return_value = 1;
2906 for (i=0; i < num_ranges; ++i)
2908 ranges[i].chardata_for_range[
j].x0 =
2909 ranges[i].chardata_for_range[
j].y0 =
2910 ranges[i].chardata_for_range[
j].x1 =
2911 ranges[i].chardata_for_range[
j].
y1 = 0;
2914 for (i=0; i < num_ranges; ++i)
2915 n += ranges[i].num_chars_in_range;
2923 for (i=0; i < num_ranges; ++i) {
2942 for (i=0; i < num_ranges; ++i) {
2950 int advance, lsb, x0,y0,x1,
y1;
2984 bc->
x0 = (stbtt_int16)
r->x;
2985 bc->
y0 = (stbtt_int16)
r->y;
2986 bc->
x1 = (stbtt_int16) (
r->x +
r->w);
2987 bc->
y1 = (stbtt_int16) (
r->y +
r->h);
2989 bc->
xoff = (float) x0 * recip_h + sub_x;
2990 bc->
yoff = (float) y0 * recip_v + sub_y;
2991 bc->
xoff2 = (x0 +
r->w) * recip_h + sub_x;
2992 bc->
yoff2 = (y0 +
r->h) * recip_v + sub_y;
3002 return return_value;
3006 int first_unicode_char_in_range,
int num_chars_in_range,
stbtt_packedchar *chardata_for_range)
3009 range.first_unicode_char_in_range = first_unicode_char_in_range;
3010 range.num_chars_in_range = num_chars_in_range;
3011 range.chardata_for_range = chardata_for_range;
3017 int ph,
int char_index,
float *xpos,
float *ypos,
3020 float ipw = 1.0f / pw, iph = 1.0f / ph;
3023 if (align_to_integer) {
3024 float x = (float) STBTT_ifloor((*xpos +
b->xoff) + 0.5f);
3025 float y = (float) STBTT_ifloor((*ypos +
b->yoff) + 0.5f);
3028 q->x1 =
x +
b->xoff2 -
b->xoff;
3029 q->y1 =
y +
b->yoff2 -
b->yoff;
3031 q->x0 = *xpos +
b->xoff;
3032 q->y0 = *ypos +
b->yoff;
3033 q->x1 = *xpos +
b->xoff2;
3034 q->y1 = *ypos +
b->yoff2;
3037 q->s0 =
b->x0 * ipw;
3038 q->t0 =
b->y0 * iph;
3039 q->s1 =
b->x1 * ipw;
3040 q->t1 =
b->y1 * iph;
3042 *xpos +=
b->xadvance;
3049 static stbtt_int32 stbtt__CompareUTF8toUTF16_bigendian_prefix(
const stbtt_uint8 *s1, stbtt_int32 len1,
const stbtt_uint8 *s2, stbtt_int32 len2)
3055 stbtt_uint16 ch = s2[0]*256 + s2[1];
3058 if (i >= len1)
return -1;
3059 if (s1[i++] != ch)
return -1;
3061 else if (ch < 0x800)
3063 if (i+1 >= len1)
return -1;
3064 if (s1[i++] != 0xc0 + (ch >> 6))
return -1;
3065 if (s1[i++] != 0x80 + (ch & 0x3f))
return -1;
3067 else if (ch >= 0xd800 && ch < 0xdc00)
3070 stbtt_uint16 ch2 = s2[2]*256 + s2[3];
3071 if (i+3 >= len1)
return -1;
3072 c = ((ch - 0xd800) << 10) + (ch2 - 0xdc00) + 0x10000;
3073 if (s1[i++] != 0xf0 + (
c >> 18))
return -1;
3074 if (s1[i++] != 0x80 + ((
c >> 12) & 0x3f))
return -1;
3075 if (s1[i++] != 0x80 + ((
c >> 6) & 0x3f))
return -1;
3076 if (s1[i++] != 0x80 + ((
c ) & 0x3f))
return -1;
3080 else if (ch >= 0xdc00 && ch < 0xe000)
3084 if (i+2 >= len1)
return -1;
3085 if (s1[i++] != 0xe0 + (ch >> 12))
return -1;
3086 if (s1[i++] != 0x80 + ((ch >> 6) & 0x3f))
return -1;
3087 if (s1[i++] != 0x80 + ((ch ) & 0x3f))
return -1;
3097 return len1 == stbtt__CompareUTF8toUTF16_bigendian_prefix((
const stbtt_uint8*) s1, len1, (
const stbtt_uint8*) s2, len2);
3103 int *
length,
int platformID,
int encodingID,
int languageID,
int nameID)
3105 stbtt_int32 i,
count,stringOffset;
3106 stbtt_uint8 *
fc =
font->data;
3108 stbtt_uint32 nm = stbtt__find_table(
fc,
offset,
"name");
3109 if (!nm)
return NULL;
3112 stringOffset = nm + ttUSHORT(
fc+nm+4);
3114 for (i=0; i <
count; ++i)
3116 stbtt_uint32 loc = nm + 6 + 12 * i;
3117 if (platformID == ttUSHORT(
fc+loc+0) && encodingID == ttUSHORT(
fc+loc+2)
3118 && languageID == ttUSHORT(
fc+loc+4) && nameID == ttUSHORT(
fc+loc+6))
3121 return (
const char *) (
fc+stringOffset+ttUSHORT(
fc+loc+10));
3127 static int stbtt__matchpair(stbtt_uint8 *
fc, stbtt_uint32 nm, stbtt_uint8 *
name,
3128 stbtt_int32 nlen, stbtt_int32 target_id, stbtt_int32 next_id)
3131 stbtt_int32
count = ttUSHORT(
fc+nm+2);
3132 stbtt_int32 stringOffset = nm + ttUSHORT(
fc+nm+4);
3134 for (i=0; i <
count; ++i)
3136 stbtt_uint32 loc = nm + 6 + 12 * i;
3137 stbtt_int32
id = ttUSHORT(
fc+loc+6);
3138 if (
id == target_id)
3141 stbtt_int32 platform = ttUSHORT(
fc+loc+0),
encoding = ttUSHORT(
fc+loc+2), language = ttUSHORT(
fc+loc+4);
3144 if (platform == 0 || (platform == 3 &&
encoding == 1) || (platform == 3 &&
encoding == 10))
3146 stbtt_int32
slen = ttUSHORT(
fc+loc+8);
3147 stbtt_int32 off = ttUSHORT(
fc+loc+10);
3150 stbtt_int32 matchlen = stbtt__CompareUTF8toUTF16_bigendian_prefix(
name, nlen,
fc+stringOffset+off,
slen);
3154 if (i+1 <
count && ttUSHORT(
fc+loc+12+6) == next_id
3155 && ttUSHORT(
fc+loc+12) == platform && ttUSHORT(
fc+loc+12+2) ==
encoding 3156 && ttUSHORT(
fc+loc+12+4) == language)
3158 slen = ttUSHORT(
fc+loc+12+8);
3159 off = ttUSHORT(
fc+loc+12+10);
3163 if (matchlen == nlen)
3166 else if (matchlen < nlen &&
name[matchlen] ==
' ')
3170 nlen-matchlen, (
char*)(
fc+stringOffset+off),
slen))
3177 if (matchlen == nlen)
3189 static int stbtt__matches(stbtt_uint8 *
fc, stbtt_uint32
offset, stbtt_uint8 *
name, stbtt_int32
flags)
3191 stbtt_int32 nlen = (stbtt_int32)
strlen((
char*)
name);
3199 hd = stbtt__find_table(
fc,
offset,
"head");
3200 if ((ttUSHORT(
fc+hd+44) & 7) != (
flags & 7))
return 0;
3203 nm = stbtt__find_table(
fc,
offset,
"name");
3210 if (stbtt__matchpair(
fc, nm,
name, nlen, 16, -1))
3212 if (stbtt__matchpair(
fc, nm,
name, nlen, 1, -1))
3214 if (stbtt__matchpair(
fc, nm,
name, nlen, 3, -1))
3219 if (stbtt__matchpair(
fc, nm,
name, nlen, 16, 17))
3221 if (stbtt__matchpair(
fc, nm,
name, nlen, 1, 2))
3223 if (stbtt__matchpair(
fc, nm,
name, nlen, 3, -1))
3231 const char *name_utf8, stbtt_int32
flags)
3239 if (stbtt__matches((stbtt_uint8 *) font_collection, off, (stbtt_uint8*) name_utf8,
flags))
struct nk_font * font
Definition: nk_common.c:40
STBTT_DEF void stbtt_MakeCodepointBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int codepoint)
struct stbtt_fontinfo stbtt_fontinfo
stbrp_coord y
Definition: stb_rect_pack.h:96
#define stbtt_vertex_type
Definition: stb_truetype.h:572
Definition: stb_truetype.h:793
GLuint const GLchar * name
Definition: glext.h:6671
Definition: stb_truetype.h:803
unsigned short y1
Definition: stb_truetype.h:354
unsigned char type
Definition: stb_truetype.h:577
const GLint * first
Definition: glext.h:6478
Definition: stb_truetype.h:574
STBTT_DEF void stbtt_GetBakedQuad(stbtt_bakedchar *chardata, int pw, int ph, int char_index, float *xpos, float *ypos, stbtt_aligned_quad *q, int opengl_fillrule)
Definition: stb_truetype.h:769
Definition: stb_truetype.h:399
Definition: stb_truetype.h:752
STBTT_DEF void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *vertices)
STBTT_DEF void stbtt_FreeBitmap(unsigned char *bitmap, void *userdata)
static const unsigned char tag[MAX_TESTS *3][16]
Definition: gcm.c:696
unsigned short x1
Definition: stb_truetype.h:354
stbtt_vertex_type x
Definition: stb_truetype.h:576
STBTT_DEF unsigned char * stbtt_GetCodepointBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int codepoint, int *width, int *height, int *xoff, int *yoff)
Definition: stb_truetype.h:759
stbrp_coord x
Definition: stb_rect_pack.h:96
static int codepoint(lua_State *L)
Definition: lutf8lib.c:100
GLuint start
Definition: glext.h:6292
Definition: stb_truetype.h:565
int index_map
Definition: stb_truetype.h:477
Definition: stb_truetype.h:760
GLfixed GLfixed x2
Definition: glsym_gl.h:1051
Definition: stb_truetype.h:778
JSON_Encoding encoding
Definition: jsonsax_full.h:274
Definition: libretro.h:2275
GLdouble GLdouble GLdouble r
Definition: glext.h:6406
GLdouble GLdouble t
Definition: glext.h:6398
GLsizei GLfixed GLfixed GLfixed GLfixed const GLubyte * bitmap
Definition: glsym_gl.h:1002
GLenum GLsizei len
Definition: glext.h:7389
GLenum GLint * range
Definition: glext.h:8206
STBTT_DEF unsigned char * stbtt_GetCodepointBitmapSubpixel(const stbtt_fontinfo *info, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint, int *width, int *height, int *xoff, int *yoff)
unsigned char * data
Definition: stb_truetype.h:471
static struct mg_connection * fc(struct mg_context *ctx)
Definition: civetweb.c:1933
static const float font_size
Definition: config.def.h:434
GLsizeiptr size
Definition: glext.h:6559
GLfloat f
Definition: glext.h:8207
STBTT_DEF void stbtt_GetFontVMetrics(const stbtt_fontinfo *info, int *ascent, int *descent, int *lineGap)
float y0
Definition: stb_truetype.h:325
GLenum GLuint id
Definition: glext.h:6233
STBTT_DEF const char * stbtt_GetFontNameString(const stbtt_fontinfo *font, int *length, int platformID, int encodingID, int languageID, int nameID)
int width
Definition: stb_truetype.h:444
Definition: stb_truetype.h:791
Definition: stb_truetype.h:802
GLenum GLenum GLenum GLenum GLenum scale
Definition: glext.h:9939
#define next(ls)
Definition: llex.c:32
GLdouble s
Definition: glext.h:6390
const struct retro_game_info * info
Definition: libretro.h:2121
int indexToLocFormat
Definition: stb_truetype.h:478
GLdouble GLdouble z
Definition: glext.h:6514
STBTT_DEF int stbtt_GetGlyphBox(const stbtt_fontinfo *info, int glyph_index, int *x0, int *y0, int *x1, int *y1)
int numGlyphs
Definition: stb_truetype.h:474
float yoff2
Definition: stb_truetype.h:356
STBTT_DEF void stbtt_GetCodepointHMetrics(const stbtt_fontinfo *info, int codepoint, int *advanceWidth, int *leftSideBearing)
float yoff
Definition: stb_truetype.h:307
STBTT_DEF int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data, int offset)
int height
Definition: stb_rect_pack.h:160
int h
Definition: stb_truetype.h:688
Definition: stb_truetype.h:804
int width
Definition: stb_rect_pack.h:159
Definition: stb_truetype.h:800
Definition: stb_truetype.h:789
float xadvance
Definition: stb_truetype.h:355
STBTT_DEF int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2)
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:6303
const GLubyte * c
Definition: glext.h:9812
GLboolean GLboolean GLboolean b
Definition: glext.h:6844
int padding
Definition: stb_truetype.h:447
unsigned int h_oversample
Definition: stb_truetype.h:448
int stride_in_bytes
Definition: stb_truetype.h:446
GLuint GLuint GLsizei count
Definition: glext.h:6292
Definition: stb_truetype.h:763
STBRP_DEF void stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects)
#define fabs(x)
Definition: math.h:27
STBTT_DEF int stbtt_GetFontOffsetForIndex(const unsigned char *data, int index)
int head
Definition: stb_truetype.h:476
unsigned char * pixels
Definition: stb_truetype.h:449
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: glext.h:6293
Definition: stb_truetype.h:794
int glyf
Definition: stb_truetype.h:476
unsigned short stbrp_coord
Definition: stb_rect_pack.h:64
STBTT_DEF unsigned char * stbtt_GetGlyphBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int glyph, int *width, int *height, int *xoff, int *yoff)
int hmtx
Definition: stb_truetype.h:476
Definition: stb_truetype.h:791
float xoff
Definition: stb_truetype.h:355
Definition: stb_truetype.h:564
float xadvance
Definition: stb_truetype.h:307
int was_packed
Definition: stb_rect_pack.h:97
#define NULL
Pointer to 0.
Definition: gctypes.h:65
GLenum type
Definition: glext.h:6233
Definition: stb_truetype.h:805
bool l
Definition: connect_wiiupro.c:37
float yoff
Definition: stb_truetype.h:355
Definition: stb_truetype.h:790
const void * data
Definition: libretro.h:2285
STBTT_DEF void stbtt_GetGlyphHMetrics(const stbtt_fontinfo *info, int glyph_index, int *advanceWidth, int *leftSideBearing)
Definition: stb_truetype.h:771
Definition: stb_truetype.h:799
STBTT_DEF void stbtt_GetCodepointBitmapBox(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1)
Definition: stb_truetype.h:794
STBTT_DEF void stbtt_Rasterize(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)
stbrp_coord h
Definition: stb_rect_pack.h:95
STBTT_DEF int stbtt_IsGlyphEmpty(const stbtt_fontinfo *info, int glyph_index)
GLsizei const GLfloat * points
Definition: glext.h:9015
size_t strlen(const char *str)
Definition: compat_ctype.c:152
Definition: stb_truetype.h:793
STBTT_DEF int stbtt_CompareUTF8toUTF16_bigendian(const char *s1, int len1, const char *s2, int len2)
STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes)
int kern
Definition: stb_truetype.h:476
Definition: stb_truetype.h:803
static l_noret error(LoadState *S, const char *why)
Definition: lundump.c:39
uint16_t x1
Definition: stb_truetype.h:306
GLfixed y1
Definition: glsym_gl.h:1051
stbtt_packedchar * chardata_for_range
Definition: stb_truetype.h:404
int stride
Definition: stb_truetype.h:688
Definition: stb_truetype.h:304
STBTT_DEF 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)
GLint GLint GLint GLint GLint GLint y
Definition: glext.h:6295
void * user_allocator_context
Definition: stb_truetype.h:442
Definition: stb_truetype.h:802
struct stbrp_node stbrp_node
Definition: stb_rect_pack.h:58
STBTT_DEF unsigned char * stbtt_GetGlyphBitmapSubpixel(const stbtt_fontinfo *info, float scale_x, float scale_y, float shift_x, float shift_y, int glyph, int *width, int *height, int *xoff, int *yoff)
#define STBTT_DEF
Definition: stb_truetype.h:293
GLint GLint GLint GLint GLint x
Definition: glext.h:6295
Definition: stb_truetype.h:790
static u64 changed
Definition: video.c:1347
GLuint64EXT * result
Definition: glext.h:12211
GLdouble GLdouble GLdouble GLdouble q
Definition: glext.h:6414
void * pack_info
Definition: stb_truetype.h:443
stbtt_vertex_type y
Definition: stb_truetype.h:576
Definition: stb_truetype.h:804
int hhea
Definition: stb_truetype.h:476
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)
STBTT_DEF int stbtt_BakeFontBitmap(const unsigned char *data, int offset, float pixel_height, unsigned char *pixels, int pw, int ph, int first_char, int num_chars, stbtt_bakedchar *chardata)
STBTT_DEF void stbtt_MakeGlyphBitmapSubpixel(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)
float xoff
Definition: stb_truetype.h:307
Definition: stb_truetype.h:772
GLfloat GLfloat p
Definition: glext.h:9809
#define retro_assert(cond)
Definition: retro_assert.h:34
int fontstart
Definition: stb_truetype.h:472
GLfixed GLfixed GLfixed y2
Definition: glsym_gl.h:1051
struct stbrp_rect stbrp_rect
Definition: stb_rect_pack.h:59
Definition: stb_truetype.h:468
Definition: stb_truetype.h:780
uint16_t y0
Definition: stb_truetype.h:306
void * userdata
Definition: stb_truetype.h:470
Definition: stb_truetype.h:770
Definition: stb_truetype.h:799
GLuint index
Definition: glext.h:6671
Definition: stb_truetype.h:800
uint16_t y1
Definition: stb_truetype.h:306
unsigned char * pixels
Definition: stb_truetype.h:689
int height
Definition: stb_truetype.h:445
const GLdouble * v
Definition: glext.h:6391
Definition: stb_truetype.h:792
struct stbrp_context stbrp_context
Definition: stb_rect_pack.h:57
STBTT_DEF void stbtt_GetCodepointBitmapBoxSubpixel(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, float shift_x, float shift_y, int *ix0, int *iy0, int *ix1, int *iy1)
unsigned short y0
Definition: stb_truetype.h:354
static const size_t slen[MAX_TESTS]
Definition: pkcs5.c:314
STBTT_DEF void stbtt_MakeCodepointBitmapSubpixel(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 codepoint)
Definition: stb_truetype.h:781
std::string output
Definition: Config.FromFile.cpp:44
Definition: stb_rect_pack.h:92
int w
Definition: stb_truetype.h:688
unsigned int v_oversample
Definition: stb_truetype.h:448
GLboolean GLboolean g
Definition: glext.h:6844
GLint j
Definition: nx_glsym.h:307
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: glext.h:6293
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)
GLint GLint GLsizei width
Definition: glext.h:6293
STBTT_DEF void stbtt_MakeGlyphBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int glyph)
STBTT_DEF void stbtt_GetPackedQuad(stbtt_packedchar *chardata, int pw, int ph, int char_index, float *xpos, float *ypos, stbtt_aligned_quad *q, int align_to_integer)
unsigned short x0
Definition: stb_truetype.h:354
STBTT_DEF int stbtt_GetCodepointShape(const stbtt_fontinfo *info, int unicode_codepoint, stbtt_vertex **vertices)
def sign()
Definition: build.py:201
Definition: stb_truetype.h:751
Definition: stb_truetype.h:753
Definition: stb_truetype.h:781
STBTT_DEF void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h_oversample, unsigned int v_oversample)
GLboolean invert
Definition: glext.h:6381
STBTT_DEF int stbtt_GetCodepointKernAdvance(const stbtt_fontinfo *info, int ch1, int ch2)
Definition: stb_truetype.h:563
Definition: stb_truetype.h:801
STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges)
Definition: stb_truetype.h:352
Definition: stb_truetype.h:750
Definition: stb_truetype.h:801
Definition: stb_rect_pack.h:157
Definition: stb_truetype.h:779
STBTT_DEF float stbtt_ScaleForPixelHeight(const stbtt_fontinfo *info, float pixels)
GLsizei stride
Definition: glext.h:6488
int loca
Definition: stb_truetype.h:476
vu8 head
Definition: keyboard.c:426
GLuint GLuint end
Definition: glext.h:6292
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)
Definition: stb_truetype.h:778
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:6742
Definition: stb_truetype.h:792
Definition: stb_truetype.h:761
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:8390
STBTT_DEF void stbtt_PackEnd(stbtt_pack_context *spc)
Definition: video4linux2.c:51
GLintptr offset
Definition: glext.h:6560
uint16_t x0
Definition: stb_truetype.h:306
GLbitfield flags
Definition: glext.h:7828
Definition: stb_truetype.h:686
unsigned short uint16_t
Definition: stdint.h:125
STBTT_DEF int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codepoint)
void * memset(void *b, int c, size_t len)
Definition: string.c:7
Definition: stb_truetype.h:440
STBTT_DEF int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, stbtt_vertex **vertices)
void * nodes
Definition: stb_truetype.h:450
Definition: stb_truetype.h:789
GLenum GLuint GLenum GLsizei length
Definition: glext.h:6233
GLdouble n
Definition: glext.h:8396
STBTT_DEF int stbtt_GetCodepointBox(const stbtt_fontinfo *info, int codepoint, int *x0, int *y0, int *x1, int *y1)
STBTT_DEF int stbtt_FindMatchingFont(const unsigned char *fontdata, const char *name, int flags)
float y1
Definition: stb_truetype.h:326
Definition: stb_truetype.h:780
const GLfloat * m
Definition: glext.h:11755
Definition: stb_truetype.h:323
Definition: stb_truetype.h:762
int first_unicode_char_in_range
Definition: stb_truetype.h:402
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6844
Definition: stb_rect_pack.h:151
GLint GLint GLsizei GLsizei height
Definition: glext.h:6293
float xoff2
Definition: stb_truetype.h:356
STBTT_DEF void stbtt_GetFontBoundingBox(const stbtt_fontinfo *info, int *x0, int *y0, int *x1, int *y1)
STBTT_DEF float stbtt_ScaleForMappingEmToPixels(const stbtt_fontinfo *info, float pixels)
Definition: stb_truetype.h:805
Definition: stb_truetype.h:779
int num_chars_in_range
Definition: stb_truetype.h:403
void * memcpy(void *dst, const void *src, size_t len)
Definition: string.c:26
float font_size
Definition: stb_truetype.h:401
stbrp_coord w
Definition: stb_rect_pack.h:95