summaryrefslogtreecommitdiff
path: root/src/ui/text.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/text.c')
-rw-r--r--src/ui/text.c52
1 files changed, 4 insertions, 48 deletions
diff --git a/src/ui/text.c b/src/ui/text.c
index 34e20bf1..9532e35a 100644
--- a/src/ui/text.c
+++ b/src/ui/text.c
@@ -496,12 +496,6 @@ static SDL_Surface *rasterizeGlyph_Font_(const iFont *d, uint32_t glyphIndex, fl
496#endif 496#endif
497} 497}
498 498
499#if 0
500iLocalDef SDL_Rect sdlRect_(const iRect rect) {
501 return (SDL_Rect){ rect.pos.x, rect.pos.y, rect.size.x, rect.size.y };
502}
503#endif
504
505iLocalDef iCacheRow *cacheRow_Text_(iText *d, int height) { 499iLocalDef iCacheRow *cacheRow_Text_(iText *d, int height) {
506 return at_Array(&d->cacheRows, (height - 1) / d->cacheRowAllocStep); 500 return at_Array(&d->cacheRows, (height - 1) / d->cacheRowAllocStep);
507} 501}
@@ -547,32 +541,6 @@ static void allocate_Font_(iFont *d, iGlyph *glyph, int hoff) {
547 } 541 }
548} 542}
549 543
550#if 0
551static iBool cache_Font_(const iFont *d, iGlyph *glyph, int hoff) {
552 iText * txt = &text_;
553 SDL_Renderer *render = txt->render;
554 SDL_Texture * tex = NULL;
555 SDL_Surface * surface = NULL;
556 iRect * glRect = &glyph->rect[hoff];
557 /* Rasterize the glyph using stbtt. */
558 iAssert(!isRasterized_Glyph_(glyph, hoff));
559 surface = rasterizeGlyph_Font_(d, glyph->glyphIndex, hoff * 0.5f);
560 tex = SDL_CreateTextureFromSurface(render, surface);
561 iAssert(isEqual_I2(glRect->size, init_I2(surface->w, surface->h)));
562 if (tex) {
563 SDL_SetTextureBlendMode(tex, SDL_BLENDMODE_NONE);
564 const SDL_Rect dstRect = sdlRect_(*glRect);
565 SDL_RenderCopy(render, tex, &(SDL_Rect){ 0, 0, dstRect.w, dstRect.h }, &dstRect);
566 SDL_DestroyTexture(tex);
567 setRasterized_Glyph_(glyph, hoff);
568 }
569 if (surface) {
570 SDL_FreeSurface(surface);
571 }
572 return isRasterized_Glyph_(glyph, hoff);
573}
574#endif
575
576iLocalDef iFont *characterFont_Font_(iFont *d, iChar ch, uint32_t *glyphIndex) { 544iLocalDef iFont *characterFont_Font_(iFont *d, iChar ch, uint32_t *glyphIndex) {
577 if ((*glyphIndex = glyphIndex_Font_(d, ch)) != 0) { 545 if ((*glyphIndex = glyphIndex_Font_(d, ch)) != 0) {
578 return d; 546 return d;
@@ -629,20 +597,6 @@ iLocalDef iFont *characterFont_Font_(iFont *d, iChar ch, uint32_t *glyphIndex) {
629 return font; 597 return font;
630} 598}
631 599
632#if 0
633static void doRaster_Font_(const iFont *font, iGlyph *glyph) {
634 SDL_Texture *oldTarget = SDL_GetRenderTarget(text_.render);
635 SDL_SetRenderTarget(text_.render, text_.cache);
636 if (!isRasterized_Glyph_(glyph, 0)) {
637 cache_Font_(font, glyph, 0);
638 }
639 if (!isRasterized_Glyph_(glyph, 1)) {
640 cache_Font_(font, glyph, 1); /* half-pixel offset */
641 }
642 SDL_SetRenderTarget(text_.render, oldTarget);
643}
644#endif
645
646static iGlyph *glyph_Font_(iFont *d, iChar ch) { 600static iGlyph *glyph_Font_(iFont *d, iChar ch) {
647 iGlyph * glyph; 601 iGlyph * glyph;
648 uint32_t glyphIndex = 0; 602 uint32_t glyphIndex = 0;
@@ -784,7 +738,7 @@ void cacheTextGlyphs_Font_(iFont *d, const iRangecc text) {
784 oldTarget = SDL_GetRenderTarget(text_.render); 738 oldTarget = SDL_GetRenderTarget(text_.render);
785 SDL_SetRenderTarget(text_.render, text_.cache); 739 SDL_SetRenderTarget(text_.render, text_.cache);
786 } 740 }
787 //printf("copying %d rasters\n", size_Array(rasters)); fflush(stdout); 741// printf("copying %zu rasters from %p\n", size_Array(rasters), bufTex); fflush(stdout);
788 iConstForEach(Array, i, rasters) { 742 iConstForEach(Array, i, rasters) {
789 const iRasterGlyph *rg = i.value; 743 const iRasterGlyph *rg = i.value;
790// iAssert(isEqual_I2(rg->rect.size, rg->glyph->rect[rg->hoff].size)); 744// iAssert(isEqual_I2(rg->rect.size, rg->glyph->rect[rg->hoff].size));
@@ -794,6 +748,7 @@ void cacheTextGlyphs_Font_(iFont *d, const iRangecc text) {
794 (const SDL_Rect *) &rg->rect, 748 (const SDL_Rect *) &rg->rect,
795 (const SDL_Rect *) glRect); 749 (const SDL_Rect *) glRect);
796 setRasterized_Glyph_(rg->glyph, rg->hoff); 750 setRasterized_Glyph_(rg->glyph, rg->hoff);
751// printf(" - %u\n", rg->glyph->glyphIndex);
797 } 752 }
798 SDL_DestroyTexture(bufTex); 753 SDL_DestroyTexture(bufTex);
799 /* Resume with an empty buffer. */ 754 /* Resume with an empty buffer. */
@@ -1019,8 +974,9 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) {
1019 int x1 = iMax(xpos, xposExtend); 974 int x1 = iMax(xpos, xposExtend);
1020 /* Which half of the pixel the glyph falls on? */ 975 /* Which half of the pixel the glyph falls on? */
1021 const int hoff = enableHalfPixelGlyphs_Text ? (xpos - x1 > 0.5f ? 1 : 0) : 0; 976 const int hoff = enableHalfPixelGlyphs_Text ? (xpos - x1 > 0.5f ? 1 : 0) : 0;
1022 if (mode & draw_RunMode && !isRasterized_Glyph_(glyph, hoff)) { 977 if (mode & draw_RunMode && ch != 0x20 && ch != 0 && !isRasterized_Glyph_(glyph, hoff)) {
1023 /* Need to pause here and make sure all glyphs have been cached in the text. */ 978 /* Need to pause here and make sure all glyphs have been cached in the text. */
979// printf("[Text] missing from cache: %lc (%x)\n", (int) ch, ch);
1024 cacheTextGlyphs_Font_(d, args->text); 980 cacheTextGlyphs_Font_(d, args->text);
1025 glyph = glyph_Font_(d, ch); /* cache may have been reset */ 981 glyph = glyph_Font_(d, ch); /* cache may have been reset */
1026 } 982 }