From c8f7274297e51586aad149a51a5719972199fbce Mon Sep 17 00:00:00 2001 From: Brett Bergstrom Date: Sun, 13 Sep 2026 01:33:10 -0500 Subject: [PATCH] h --- glue.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/glue.c b/glue.c index 91ebaeb..6f6a807 100644 --- a/glue.c +++ b/glue.c @@ -14,6 +14,8 @@ #include +#include "../primitives/allegro5/allegro_primitives.h" + ALLEGRO_DEBUG_CHANNEL("font") #define CANI_ALLEGRO_SCHRIFT_VER 1 @@ -85,9 +87,25 @@ ALLEGRO_FONT *al_load_ttf_font_f(ALLEGRO_FILE *file, gtex = al_create_bitmap(wmax, hmax); al_set_target_bitmap(gtex); al_clear_to_color(al_map_rgba(0, 0, 0, 0)); // todo invert alpha at final pass + unsigned int i = 0; const unsigned int len = strlen(cache_text_str); unsigned int lh = 0; + while (i < len) { + SFT_Glyph glyph; + SFT_GMetrics geom; + if (0 > sft_lookup(&sft, cache_text_str[i], &glyph)) goto glyph_measure_fail; + if (0 > sft_gmetrics(&sft, glyph, &geom)) goto glyph_measure_fail; + if (lh < geom.minHeight) lh = geom.minHeight; + i++; continue; + + glyph_measure_fail: + ALLEGRO_ERROR("Failure generating glyph %c in %s!\n", cache_text_str[i], filename); + FAIL; + } + ALLEGRO_INFO("scanned all glyphs for font height %u", lh); + + i = 0; while (i < len) { ALLEGRO_INFO("generating glyph for %c\n", cache_text_str[i]); SFT_Glyph glyph; @@ -96,15 +114,12 @@ ALLEGRO_FONT *al_load_ttf_font_f(ALLEGRO_FILE *file, ALLEGRO_LOCKED_REGION *block = NULL; if (0 > sft_lookup(&sft, cache_text_str[i], &glyph)) goto glyph_lookup_fail; - ALLEGRO_INFO("got glyph\n"); if (0 > sft_gmetrics(&sft, glyph, &geom)) goto glyph_lookup_fail; - ALLEGRO_INFO("got geom\n"); - if (lh < geom.minHeight) lh = geom.minHeight; - if ((wmax - woff) < geom.minWidth) { + if ((wmax - woff) < geom.minWidth + 1) { hoff += lh + 1; woff = 1; } - if ((hmax - hoff) < (geom.minHeight + abs(geom.yOffset))) { + if ((hmax - hoff) < (geom.minHeight + abs(geom.yOffset)) + 1) { ALLEGRO_WARN("ran out of room! growing glyph texture\n"); gtex = grow_bitmap(gtex, hmax); al_set_target_bitmap(gtex); @@ -116,16 +131,16 @@ ALLEGRO_FONT *al_load_ttf_font_f(ALLEGRO_FILE *file, if (!img.pixels) goto glyph_lookup_oom; if (0 > sft_render(&sft, glyph, img)) goto glyph_lookup_fail; ALLEGRO_INFO("got raster\n"); + //al_draw_filled_rectangle(woff, hoff, woff + geom.minWidth, hoff + geom.minHeight, al_map_rgba(0, 0, 0, 255)); // fixme block = - al_lock_bitmap_region(gtex, woff, hoff, geom.minWidth, geom.minHeight + abs(geom.yOffset), + al_lock_bitmap_region(gtex, woff, hoff + (geom.yOffset + lh), geom.minWidth, geom.minHeight, ALLEGRO_PIXEL_FORMAT_SINGLE_CHANNEL_8, ALLEGRO_LOCK_WRITEONLY); assert(block->pixel_size == 1); ALLEGRO_INFO("got vram lock\n"); int row = 0; // should not be signed!!!!! C programmers are fucking assholes! - uint8_t* dest = (uint8_t*)block->data + block->pitch * (geom.minHeight+geom.yOffset); while (row < img.height) { memcpy( - dest + block->pitch * row, + (uint8_t*)block->data + block->pitch * row, (uint8_t*)img.pixels + img.width * row, img.width );