Lines Matching refs:stash
102 int fonsResetAtlas(FONScontext* stash, int width, int height);
131 int fonsTextIterInit(FONScontext* stash, FONStextIter* iter, float x, float y, const char* str, con…
132 int fonsTextIterNext(FONScontext* stash, FONStextIter* iter, struct FONSquad* quad);
135 const unsigned char* fonsGetTextureData(FONScontext* stash, int* width, int* height);
461 FONScontext* stash = (FONScontext*)up;
466 if (stash->nscratch+(int)size > FONS_SCRATCH_BUF_SIZE) {
467 if (stash->handleError)
468 stash->handleError(stash->errorUptr, FONS_SCRATCH_FULL, stash->nscratch+(int)size);
471 ptr = stash->scratch + stash->nscratch;
472 stash->nscratch += (int)size;
706 static void fons__addWhiteRect(FONScontext* stash, int w, int h)
710 if (fons__atlasAddRect(stash->atlas, w, h, &gx, &gy) == 0)
714 dst = &stash->texData[gx + gy * stash->params.width];
718 dst += stash->params.width;
721 stash->dirtyRect[0] = fons__mini(stash->dirtyRect[0], gx);
722 stash->dirtyRect[1] = fons__mini(stash->dirtyRect[1], gy);
723 stash->dirtyRect[2] = fons__maxi(stash->dirtyRect[2], gx+w);
724 stash->dirtyRect[3] = fons__maxi(stash->dirtyRect[3], gy+h);
729 FONScontext* stash = NULL;
732 stash = (FONScontext*)malloc(sizeof(FONScontext));
733 if (stash == NULL) goto error;
734 memset(stash, 0, sizeof(FONScontext));
736 stash->params = *params;
739 stash->scratch = (unsigned char*)malloc(FONS_SCRATCH_BUF_SIZE);
740 if (stash->scratch == NULL) goto error;
743 if (!fons__tt_init(stash)) goto error;
745 if (stash->params.renderCreate != NULL) {
746 …if (stash->params.renderCreate(stash->params.userPtr, stash->params.width, stash->params.height) =…
750 stash->atlas = fons__allocAtlas(stash->params.width, stash->params.height, FONS_INIT_ATLAS_NODES);
751 if (stash->atlas == NULL) goto error;
754 stash->fonts = (FONSfont**)malloc(sizeof(FONSfont*) * FONS_INIT_FONTS);
755 if (stash->fonts == NULL) goto error;
756 memset(stash->fonts, 0, sizeof(FONSfont*) * FONS_INIT_FONTS);
757 stash->cfonts = FONS_INIT_FONTS;
758 stash->nfonts = 0;
761 stash->itw = 1.0f/stash->params.width;
762 stash->ith = 1.0f/stash->params.height;
763 stash->texData = (unsigned char*)malloc(stash->params.width * stash->params.height);
764 if (stash->texData == NULL) goto error;
765 memset(stash->texData, 0, stash->params.width * stash->params.height);
767 stash->dirtyRect[0] = stash->params.width;
768 stash->dirtyRect[1] = stash->params.height;
769 stash->dirtyRect[2] = 0;
770 stash->dirtyRect[3] = 0;
773 fons__addWhiteRect(stash, 2,2);
775 fonsPushState(stash);
776 fonsClearState(stash);
778 return stash;
781 fonsDeleteInternal(stash);
785 static FONSstate* fons__getState(FONScontext* stash)
787 return &stash->states[stash->nstates-1];
790 int fonsAddFallbackFont(FONScontext* stash, int base, int fallback)
792 FONSfont* baseFont = stash->fonts[base];
800 void fonsResetFallbackFont(FONScontext* stash, int base)
804 FONSfont* baseFont = stash->fonts[base];
811 void fonsSetSize(FONScontext* stash, float size)
813 fons__getState(stash)->size = size;
816 void fonsSetColor(FONScontext* stash, unsigned int color)
818 fons__getState(stash)->color = color;
821 void fonsSetSpacing(FONScontext* stash, float spacing)
823 fons__getState(stash)->spacing = spacing;
826 void fonsSetBlur(FONScontext* stash, float blur)
828 fons__getState(stash)->blur = blur;
831 void fonsSetAlign(FONScontext* stash, int align)
833 fons__getState(stash)->align = align;
836 void fonsSetFont(FONScontext* stash, int font)
838 fons__getState(stash)->font = font;
841 void fonsPushState(FONScontext* stash)
843 if (stash->nstates >= FONS_MAX_STATES) {
844 if (stash->handleError)
845 stash->handleError(stash->errorUptr, FONS_STATES_OVERFLOW, 0);
848 if (stash->nstates > 0)
849 memcpy(&stash->states[stash->nstates], &stash->states[stash->nstates-1], sizeof(FONSstate));
850 stash->nstates++;
853 void fonsPopState(FONScontext* stash)
855 if (stash->nstates <= 1) {
856 if (stash->handleError)
857 stash->handleError(stash->errorUptr, FONS_STATES_UNDERFLOW, 0);
860 stash->nstates--;
863 void fonsClearState(FONScontext* stash)
865 FONSstate* state = fons__getState(stash);
882 static int fons__allocFont(FONScontext* stash)
885 if (stash->nfonts+1 > stash->cfonts) {
886 stash->cfonts = stash->cfonts == 0 ? 8 : stash->cfonts * 2;
887 stash->fonts = (FONSfont**)realloc(stash->fonts, sizeof(FONSfont*) * stash->cfonts);
888 if (stash->fonts == NULL)
900 stash->fonts[stash->nfonts++] = font;
901 return stash->nfonts-1;
909 int fonsAddFont(FONScontext* stash, const char* name, const char* path, int fontIndex)
929 return fonsAddFontMem(stash, name, data, dataSize, 1, fontIndex);
937 int fonsAddFontMem(FONScontext* stash, const char* name, unsigned char* data, int dataSize, int fre…
942 int idx = fons__allocFont(stash);
946 font = stash->fonts[idx];
961 stash->nscratch = 0;
962 if (!fons__tt_loadFont(stash, &font->font, data, dataSize, fontIndex)) goto error;
977 stash->nfonts--;
1050 static void fons__blur(FONScontext* stash, unsigned char* dst, int w, int h, int dstStride, int blu…
1054 (void)stash;
1069 static FONSglyph* fons__getGlyph(FONScontext* stash, FONSfont* font, unsigned int codepoint,
1087 stash->nscratch = 0;
1109 FONSfont* fallbackFont = stash->fonts[font->fallbacks[i]];
1128 added = fons__atlasAddRect(stash->atlas, gw, gh, &gx, &gy);
1129 if (added == 0 && stash->handleError != NULL) {
1131 stash->handleError(stash->errorUptr, FONS_ATLAS_FULL, 0);
1132 added = fons__atlasAddRect(stash->atlas, gw, gh, &gx, &gy);
1167 dst = &stash->texData[(glyph->x0+pad) + (glyph->y0+pad) * stash->params.width];
1168 …fons__tt_renderGlyphBitmap(&renderFont->font, dst, gw-pad*2,gh-pad*2, stash->params.width, scale, …
1171 dst = &stash->texData[glyph->x0 + glyph->y0 * stash->params.width];
1173 dst[y*stash->params.width] = 0;
1174 dst[gw-1 + y*stash->params.width] = 0;
1178 dst[x + (gh-1)*stash->params.width] = 0;
1193 stash->nscratch = 0;
1194 bdst = &stash->texData[glyph->x0 + glyph->y0 * stash->params.width];
1195 fons__blur(stash, bdst, gw, gh, stash->params.width, iblur);
1198 stash->dirtyRect[0] = fons__mini(stash->dirtyRect[0], glyph->x0);
1199 stash->dirtyRect[1] = fons__mini(stash->dirtyRect[1], glyph->y0);
1200 stash->dirtyRect[2] = fons__maxi(stash->dirtyRect[2], glyph->x1);
1201 stash->dirtyRect[3] = fons__maxi(stash->dirtyRect[3], glyph->y1);
1206 static void fons__getQuad(FONScontext* stash, FONSfont* font,
1227 if (stash->params.flags & FONS_ZERO_TOPLEFT) {
1236 q->s0 = x0 * stash->itw;
1237 q->t0 = y0 * stash->ith;
1238 q->s1 = x1 * stash->itw;
1239 q->t1 = y1 * stash->ith;
1249 q->s0 = x0 * stash->itw;
1250 q->t0 = y0 * stash->ith;
1251 q->s1 = x1 * stash->itw;
1252 q->t1 = y1 * stash->ith;
1258 static void fons__flush(FONScontext* stash)
1261 if (stash->dirtyRect[0] < stash->dirtyRect[2] && stash->dirtyRect[1] < stash->dirtyRect[3]) {
1262 if (stash->params.renderUpdate != NULL)
1263 stash->params.renderUpdate(stash->params.userPtr, stash->dirtyRect, stash->texData);
1265 stash->dirtyRect[0] = stash->params.width;
1266 stash->dirtyRect[1] = stash->params.height;
1267 stash->dirtyRect[2] = 0;
1268 stash->dirtyRect[3] = 0;
1272 if (stash->nverts > 0) {
1273 if (stash->params.renderDraw != NULL)
1274 …stash->params.renderDraw(stash->params.userPtr, stash->verts, stash->tcoords, stash->colors, stash…
1275 stash->nverts = 0;
1279 static __inline void fons__vertex(FONScontext* stash, float x, float y, float s, float t, unsigned …
1281 stash->verts[stash->nverts*2+0] = x;
1282 stash->verts[stash->nverts*2+1] = y;
1283 stash->tcoords[stash->nverts*2+0] = s;
1284 stash->tcoords[stash->nverts*2+1] = t;
1285 stash->colors[stash->nverts] = c;
1286 stash->nverts++;
1289 static float fons__getVertAlign(FONScontext* stash, FONSfont* font, int align, short isize)
1291 if (stash->params.flags & FONS_ZERO_TOPLEFT) {
1315 float fonsDrawText(FONScontext* stash,
1319 FONSstate* state = fons__getState(stash);
1331 if (stash == NULL) return x;
1332 if (state->font < 0 || state->font >= stash->nfonts) return x;
1333 font = stash->fonts[state->font];
1345 width = fonsTextBounds(stash, x,y, str, end, NULL);
1348 width = fonsTextBounds(stash, x,y, str, end, NULL);
1352 y += fons__getVertAlign(stash, font, state->align, isize);
1357 glyph = fons__getGlyph(stash, font, codepoint, isize, iblur, FONS_GLYPH_BITMAP_REQUIRED);
1359 fons__getQuad(stash, font, prevGlyphIndex, glyph, scale, state->spacing, &x, &y, &q);
1361 if (stash->nverts+6 > FONS_VERTEX_COUNT)
1362 fons__flush(stash);
1364 fons__vertex(stash, q.x0, q.y0, q.s0, q.t0, state->color);
1365 fons__vertex(stash, q.x1, q.y1, q.s1, q.t1, state->color);
1366 fons__vertex(stash, q.x1, q.y0, q.s1, q.t0, state->color);
1368 fons__vertex(stash, q.x0, q.y0, q.s0, q.t0, state->color);
1369 fons__vertex(stash, q.x0, q.y1, q.s0, q.t1, state->color);
1370 fons__vertex(stash, q.x1, q.y1, q.s1, q.t1, state->color);
1374 fons__flush(stash);
1379 int fonsTextIterInit(FONScontext* stash, FONStextIter* iter,
1382 FONSstate* state = fons__getState(stash);
1387 if (stash == NULL) return 0;
1388 if (state->font < 0 || state->font >= stash->nfonts) return 0;
1389 iter->font = stash->fonts[state->font];
1400 width = fonsTextBounds(stash, x,y, str, end, NULL);
1403 width = fonsTextBounds(stash, x,y, str, end, NULL);
1407 y += fons__getVertAlign(stash, iter->font, state->align, iter->isize);
1425 int fonsTextIterNext(FONScontext* stash, FONStextIter* iter, FONSquad* quad)
1441 …glyph = fons__getGlyph(stash, iter->font, iter->codepoint, iter->isize, iter->iblur, iter->bitmapO…
1444 …fons__getQuad(stash, iter->font, iter->prevGlyphIndex, glyph, iter->scale, iter->spacing, &iter->n…
1453 void fonsDrawDebug(FONScontext* stash, float x, float y)
1456 int w = stash->params.width;
1457 int h = stash->params.height;
1461 if (stash->nverts+6+6 > FONS_VERTEX_COUNT)
1462 fons__flush(stash);
1465 fons__vertex(stash, x+0, y+0, u, v, 0x0fffffff);
1466 fons__vertex(stash, x+w, y+h, u, v, 0x0fffffff);
1467 fons__vertex(stash, x+w, y+0, u, v, 0x0fffffff);
1469 fons__vertex(stash, x+0, y+0, u, v, 0x0fffffff);
1470 fons__vertex(stash, x+0, y+h, u, v, 0x0fffffff);
1471 fons__vertex(stash, x+w, y+h, u, v, 0x0fffffff);
1474 fons__vertex(stash, x+0, y+0, 0, 0, 0xffffffff);
1475 fons__vertex(stash, x+w, y+h, 1, 1, 0xffffffff);
1476 fons__vertex(stash, x+w, y+0, 1, 0, 0xffffffff);
1478 fons__vertex(stash, x+0, y+0, 0, 0, 0xffffffff);
1479 fons__vertex(stash, x+0, y+h, 0, 1, 0xffffffff);
1480 fons__vertex(stash, x+w, y+h, 1, 1, 0xffffffff);
1483 for (i = 0; i < stash->atlas->nnodes; i++) {
1484 FONSatlasNode* n = &stash->atlas->nodes[i];
1486 if (stash->nverts+6 > FONS_VERTEX_COUNT)
1487 fons__flush(stash);
1489 fons__vertex(stash, x+n->x+0, y+n->y+0, u, v, 0xc00000ff);
1490 fons__vertex(stash, x+n->x+n->width, y+n->y+1, u, v, 0xc00000ff);
1491 fons__vertex(stash, x+n->x+n->width, y+n->y+0, u, v, 0xc00000ff);
1493 fons__vertex(stash, x+n->x+0, y+n->y+0, u, v, 0xc00000ff);
1494 fons__vertex(stash, x+n->x+0, y+n->y+1, u, v, 0xc00000ff);
1495 fons__vertex(stash, x+n->x+n->width, y+n->y+1, u, v, 0xc00000ff);
1498 fons__flush(stash);
1501 float fonsTextBounds(FONScontext* stash,
1506 FONSstate* state = fons__getState(stash);
1519 if (stash == NULL) return 0;
1520 if (state->font < 0 || state->font >= stash->nfonts) return 0;
1521 font = stash->fonts[state->font];
1527 y += fons__getVertAlign(stash, font, state->align, isize);
1539 glyph = fons__getGlyph(stash, font, codepoint, isize, iblur, FONS_GLYPH_BITMAP_OPTIONAL);
1541 fons__getQuad(stash, font, prevGlyphIndex, glyph, scale, state->spacing, &x, &y, &q);
1544 if (stash->params.flags & FONS_ZERO_TOPLEFT) {
1578 void fonsVertMetrics(FONScontext* stash,
1582 FONSstate* state = fons__getState(stash);
1585 if (stash == NULL) return;
1586 if (state->font < 0 || state->font >= stash->nfonts) return;
1587 font = stash->fonts[state->font];
1599 void fonsLineBounds(FONScontext* stash, float y, float* miny, float* maxy)
1602 FONSstate* state = fons__getState(stash);
1605 if (stash == NULL) return;
1606 if (state->font < 0 || state->font >= stash->nfonts) return;
1607 font = stash->fonts[state->font];
1611 y += fons__getVertAlign(stash, font, state->align, isize);
1613 if (stash->params.flags & FONS_ZERO_TOPLEFT) {
1622 const unsigned char* fonsGetTextureData(FONScontext* stash, int* width, int* height)
1625 *width = stash->params.width;
1627 *height = stash->params.height;
1628 return stash->texData;
1631 int fonsValidateTexture(FONScontext* stash, int* dirty)
1633 if (stash->dirtyRect[0] < stash->dirtyRect[2] && stash->dirtyRect[1] < stash->dirtyRect[3]) {
1634 dirty[0] = stash->dirtyRect[0];
1635 dirty[1] = stash->dirtyRect[1];
1636 dirty[2] = stash->dirtyRect[2];
1637 dirty[3] = stash->dirtyRect[3];
1639 stash->dirtyRect[0] = stash->params.width;
1640 stash->dirtyRect[1] = stash->params.height;
1641 stash->dirtyRect[2] = 0;
1642 stash->dirtyRect[3] = 0;
1648 void fonsDeleteInternal(FONScontext* stash)
1651 if (stash == NULL) return;
1653 if (stash->params.renderDelete)
1654 stash->params.renderDelete(stash->params.userPtr);
1656 for (i = 0; i < stash->nfonts; ++i)
1657 fons__freeFont(stash->fonts[i]);
1659 if (stash->atlas) fons__deleteAtlas(stash->atlas);
1660 if (stash->fonts) free(stash->fonts);
1661 if (stash->texData) free(stash->texData);
1662 if (stash->scratch) free(stash->scratch);
1663 free(stash);
1664 fons__tt_done(stash);
1667 void fonsSetErrorCallback(FONScontext* stash, void (*callback)(void* uptr, int error, int val), voi…
1669 if (stash == NULL) return;
1670 stash->handleError = callback;
1671 stash->errorUptr = uptr;
1674 void fonsGetAtlasSize(FONScontext* stash, int* width, int* height)
1676 if (stash == NULL) return;
1677 *width = stash->params.width;
1678 *height = stash->params.height;
1681 int fonsExpandAtlas(FONScontext* stash, int width, int height)
1685 if (stash == NULL) return 0;
1687 width = fons__maxi(width, stash->params.width);
1688 height = fons__maxi(height, stash->params.height);
1690 if (width == stash->params.width && height == stash->params.height)
1694 fons__flush(stash);
1697 if (stash->params.renderResize != NULL) {
1698 if (stash->params.renderResize(stash->params.userPtr, width, height) == 0)
1705 for (i = 0; i < stash->params.height; i++) {
1707 unsigned char* src = &stash->texData[i*stash->params.width];
1708 memcpy(dst, src, stash->params.width);
1709 if (width > stash->params.width)
1710 memset(dst+stash->params.width, 0, width - stash->params.width);
1712 if (height > stash->params.height)
1713 memset(&data[stash->params.height * width], 0, (height - stash->params.height) * width);
1715 free(stash->texData);
1716 stash->texData = data;
1719 fons__atlasExpand(stash->atlas, width, height);
1722 for (i = 0; i < stash->atlas->nnodes; i++)
1723 maxy = fons__maxi(maxy, stash->atlas->nodes[i].y);
1724 stash->dirtyRect[0] = 0;
1725 stash->dirtyRect[1] = 0;
1726 stash->dirtyRect[2] = stash->params.width;
1727 stash->dirtyRect[3] = maxy;
1729 stash->params.width = width;
1730 stash->params.height = height;
1731 stash->itw = 1.0f/stash->params.width;
1732 stash->ith = 1.0f/stash->params.height;
1737 int fonsResetAtlas(FONScontext* stash, int width, int height)
1740 if (stash == NULL) return 0;
1743 fons__flush(stash);
1746 if (stash->params.renderResize != NULL) {
1747 if (stash->params.renderResize(stash->params.userPtr, width, height) == 0)
1752 fons__atlasReset(stash->atlas, width, height);
1755 stash->texData = (unsigned char*)realloc(stash->texData, width * height);
1756 if (stash->texData == NULL) return 0;
1757 memset(stash->texData, 0, width * height);
1760 stash->dirtyRect[0] = width;
1761 stash->dirtyRect[1] = height;
1762 stash->dirtyRect[2] = 0;
1763 stash->dirtyRect[3] = 0;
1766 for (i = 0; i < stash->nfonts; i++) {
1767 FONSfont* font = stash->fonts[i];
1773 stash->params.width = width;
1774 stash->params.height = height;
1775 stash->itw = 1.0f/stash->params.width;
1776 stash->ith = 1.0f/stash->params.height;
1779 fons__addWhiteRect(stash, 2,2);