fix glyph background dimensions, attempt color correction

This commit is contained in:
2026-09-21 16:37:59 -05:00
parent b9de434ff4
commit f2052c3851

View File

@@ -92,13 +92,16 @@ ALLEGRO_FONT *al_load_ttf_font_f(ALLEGRO_FILE *file,
unsigned int i = 0;
const unsigned int len = strlen(cache_text_str);
unsigned int lh = 0;
unsigned int lh = 0, rh = 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;
const int glbottom = geom.yOffset + lh + geom.minHeight;
if (glbottom > 0 && rh < (unsigned)glbottom)
rh = glbottom;
i++; continue;
glyph_measure_fail:
@@ -118,10 +121,10 @@ ALLEGRO_FONT *al_load_ttf_font_f(ALLEGRO_FILE *file,
if (0 > sft_lookup(&sft, cache_text_str[i], &glyph)) goto glyph_lookup_fail;
if (0 > sft_gmetrics(&sft, glyph, &geom)) goto glyph_lookup_fail;
if ((wmax - woff) < geom.minWidth + 1) {
hoff += lh + 1;
hoff += rh + 1;
woff = 1;
}
if ((hmax - hoff) < (geom.minHeight + abs(geom.yOffset)) + 1) {
if ((hmax - hoff) < rh + 1) {
ALLEGRO_WARN("ran out of room! growing glyph texture\n");
gtex = grow_bitmap(gtex, hmax);
al_set_target_bitmap(gtex);
@@ -133,7 +136,13 @@ 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
al_draw_filled_rectangle(
woff,
hoff,
woff + geom.minWidth,
hoff + rh,
al_map_rgba(0, 0, 0, 255)
);
block =
al_lock_bitmap_region(gtex, woff, hoff + (geom.yOffset + lh), geom.minWidth, geom.minHeight,
ALLEGRO_PIXEL_FORMAT_SINGLE_CHANNEL_8, ALLEGRO_LOCK_WRITEONLY);
@@ -152,6 +161,22 @@ ALLEGRO_FONT *al_load_ttf_font_f(ALLEGRO_FILE *file,
al_unlock_bitmap(gtex);
ALLEGRO_INFO("blit raster to vram\n");
block = al_lock_bitmap(gtex, ALLEGRO_PIXEL_FORMAT_RGBA_8888, ALLEGRO_LOCK_WRITEONLY);
assert(block->pixel_size == 4);
const unsigned int gtexw = al_get_bitmap_width(gtex), gtexh = al_get_bitmap_height(gtex);
unsigned int pixiw = 0, pixih = 0, pixi = 0;
while (pixi < gtexh * gtexw) {
uint32_t* pixel = (uint32_t*)((uint8_t*)block->data + (block->pitch * pixih)) + pixiw; // fixme
*pixel = (*pixel & 0xffu) * 0x01010101u;
pixi++;
if (pixiw++ >= gtexw) {
pixiw = 0;
pixih++;
}
}
al_unlock_bitmap(gtex);
ALLEGRO_INFO("converted colors\n");
woff += geom.minWidth + 1;
i++; continue;