fix glyph background dimensions, attempt color correction
This commit is contained in:
@@ -92,13 +92,16 @@ ALLEGRO_FONT *al_load_ttf_font_f(ALLEGRO_FILE *file,
|
|||||||
|
|
||||||
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, rh = 0;
|
||||||
while (i < len) {
|
while (i < len) {
|
||||||
SFT_Glyph glyph;
|
SFT_Glyph glyph;
|
||||||
SFT_GMetrics geom;
|
SFT_GMetrics geom;
|
||||||
if (0 > sft_lookup(&sft, cache_text_str[i], &glyph)) goto glyph_measure_fail;
|
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 (0 > sft_gmetrics(&sft, glyph, &geom)) goto glyph_measure_fail;
|
||||||
if (lh < geom.minHeight) lh = geom.minHeight;
|
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;
|
i++; continue;
|
||||||
|
|
||||||
glyph_measure_fail:
|
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_lookup(&sft, cache_text_str[i], &glyph)) goto glyph_lookup_fail;
|
||||||
if (0 > sft_gmetrics(&sft, glyph, &geom)) goto glyph_lookup_fail;
|
if (0 > sft_gmetrics(&sft, glyph, &geom)) goto glyph_lookup_fail;
|
||||||
if ((wmax - woff) < geom.minWidth + 1) {
|
if ((wmax - woff) < geom.minWidth + 1) {
|
||||||
hoff += lh + 1;
|
hoff += rh + 1;
|
||||||
woff = 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");
|
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);
|
||||||
@@ -133,7 +136,13 @@ 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
|
al_draw_filled_rectangle(
|
||||||
|
woff,
|
||||||
|
hoff,
|
||||||
|
woff + geom.minWidth,
|
||||||
|
hoff + rh,
|
||||||
|
al_map_rgba(0, 0, 0, 255)
|
||||||
|
);
|
||||||
block =
|
block =
|
||||||
al_lock_bitmap_region(gtex, woff, hoff + (geom.yOffset + lh), geom.minWidth, geom.minHeight,
|
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);
|
||||||
@@ -152,6 +161,22 @@ ALLEGRO_FONT *al_load_ttf_font_f(ALLEGRO_FILE *file,
|
|||||||
al_unlock_bitmap(gtex);
|
al_unlock_bitmap(gtex);
|
||||||
ALLEGRO_INFO("blit raster to vram\n");
|
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;
|
woff += geom.minWidth + 1;
|
||||||
i++; continue;
|
i++; continue;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user