This commit is contained in:
2026-09-13 01:33:10 -05:00
parent cc409912e6
commit c8f7274297

31
glue.c
View File

@@ -14,6 +14,8 @@
#include <stdlib.h> #include <stdlib.h>
#include "../primitives/allegro5/allegro_primitives.h"
ALLEGRO_DEBUG_CHANNEL("font") ALLEGRO_DEBUG_CHANNEL("font")
#define CANI_ALLEGRO_SCHRIFT_VER 1 #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); gtex = al_create_bitmap(wmax, hmax);
al_set_target_bitmap(gtex); al_set_target_bitmap(gtex);
al_clear_to_color(al_map_rgba(0, 0, 0, 0)); // todo invert alpha at final pass al_clear_to_color(al_map_rgba(0, 0, 0, 0)); // todo invert alpha at final pass
unsigned int i = 0; unsigned int i = 0;
const unsigned int len = strlen(cache_text_str); const unsigned int len = strlen(cache_text_str);
unsigned int lh = 0; 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) { while (i < len) {
ALLEGRO_INFO("generating glyph for %c\n", cache_text_str[i]); ALLEGRO_INFO("generating glyph for %c\n", cache_text_str[i]);
SFT_Glyph glyph; SFT_Glyph glyph;
@@ -96,15 +114,12 @@ ALLEGRO_FONT *al_load_ttf_font_f(ALLEGRO_FILE *file,
ALLEGRO_LOCKED_REGION *block = NULL; ALLEGRO_LOCKED_REGION *block = NULL;
if (0 > sft_lookup(&sft, cache_text_str[i], &glyph)) goto glyph_lookup_fail; 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; if (0 > sft_gmetrics(&sft, glyph, &geom)) goto glyph_lookup_fail;
ALLEGRO_INFO("got geom\n"); if ((wmax - woff) < geom.minWidth + 1) {
if (lh < geom.minHeight) lh = geom.minHeight;
if ((wmax - woff) < geom.minWidth) {
hoff += lh + 1; hoff += lh + 1;
woff = 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"); ALLEGRO_WARN("ran out of room! growing glyph texture\n");
gtex = grow_bitmap(gtex, hmax); gtex = grow_bitmap(gtex, hmax);
al_set_target_bitmap(gtex); 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 (!img.pixels) goto glyph_lookup_oom;
if (0 > sft_render(&sft, glyph, img)) goto glyph_lookup_fail; if (0 > sft_render(&sft, glyph, img)) goto glyph_lookup_fail;
ALLEGRO_INFO("got raster\n"); 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 = 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); ALLEGRO_PIXEL_FORMAT_SINGLE_CHANNEL_8, ALLEGRO_LOCK_WRITEONLY);
assert(block->pixel_size == 1); assert(block->pixel_size == 1);
ALLEGRO_INFO("got vram lock\n"); ALLEGRO_INFO("got vram lock\n");
int row = 0; // should not be signed!!!!! C programmers are fucking assholes! 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) { while (row < img.height) {
memcpy( memcpy(
dest + block->pitch * row, (uint8_t*)block->data + block->pitch * row,
(uint8_t*)img.pixels + img.width * row, (uint8_t*)img.pixels + img.width * row,
img.width img.width
); );