fuck
This commit is contained in:
@@ -19,6 +19,8 @@ add_our_addon_library(allegro_ttf
|
|||||||
"${FONT_LINK_WITH};${TTF_LIBRARIES}"
|
"${FONT_LINK_WITH};${TTF_LIBRARIES}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
#target_compile_options(allegro_ttf PRIVATE "-fsanitize=undefined" "-lasan")
|
||||||
|
|
||||||
install_our_headers(${TTF_INCLUDE_FILES})
|
install_our_headers(${TTF_INCLUDE_FILES})
|
||||||
|
|
||||||
add_addon(ttf)
|
add_addon(ttf)
|
||||||
|
|||||||
26
glue.c
26
glue.c
@@ -56,8 +56,8 @@ ALLEGRO_FONT *al_load_ttf_font_f(ALLEGRO_FILE *file,
|
|||||||
const char* cache_text_str =
|
const char* cache_text_str =
|
||||||
al_get_config_value(system_cfg, "ttf", "cache_text");
|
al_get_config_value(system_cfg, "ttf", "cache_text");
|
||||||
if (!cache_text_str) {
|
if (!cache_text_str) {
|
||||||
ALLEGRO_ERROR("No characters defined in cache_text, no glyphs to bake!\n", filename);
|
ALLEGRO_ERROR("No characters defined in cache_text! Using defaults\n");
|
||||||
FAIL;
|
cache_text_str = "fart";
|
||||||
}
|
}
|
||||||
|
|
||||||
// read font file
|
// read font file
|
||||||
@@ -71,8 +71,8 @@ ALLEGRO_FONT *al_load_ttf_font_f(ALLEGRO_FILE *file,
|
|||||||
|
|
||||||
offset += al_fread(file, (uint8_t*)filebuf + offset, chunksize);
|
offset += al_fread(file, (uint8_t*)filebuf + offset, chunksize);
|
||||||
}
|
}
|
||||||
sft.xScale = size;
|
sft.xScale = abs(size);
|
||||||
sft.yScale = size;
|
sft.yScale = abs(size);
|
||||||
sft.font = sft_loadmem(filebuf, filesize);
|
sft.font = sft_loadmem(filebuf, filesize);
|
||||||
if (!sft.font) {
|
if (!sft.font) {
|
||||||
ALLEGRO_ERROR("Can't load font %s: schrift error, is it a valid format?\n", filename);
|
ALLEGRO_ERROR("Can't load font %s: schrift error, is it a valid format?\n", filename);
|
||||||
@@ -80,12 +80,13 @@ ALLEGRO_FONT *al_load_ttf_font_f(ALLEGRO_FILE *file,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// convert glyphs into textures todo
|
// convert glyphs into textures todo
|
||||||
gtex = al_create_bitmap(2048, 2048);
|
uint16_t woff = 1, hoff = 0, hmax = 2048;
|
||||||
uint16_t woff = 1, hoff = 0;
|
gtex = al_create_bitmap(2048, hmax);
|
||||||
al_set_target_bitmap(gtex);
|
al_set_target_bitmap(gtex);
|
||||||
al_clear_to_color(al_map_rgba(0, 0, 0, 255));
|
al_clear_to_color(al_map_rgba(0, 0, 0, 255));
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
while (cache_text_str[i] != '\0') {
|
const unsigned int len = strlen(cache_text_str);
|
||||||
|
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;
|
||||||
SFT_GMetrics geom;
|
SFT_GMetrics geom;
|
||||||
@@ -96,14 +97,17 @@ ALLEGRO_FONT *al_load_ttf_font_f(ALLEGRO_FILE *file,
|
|||||||
ALLEGRO_INFO("got glyph\n");
|
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");
|
ALLEGRO_INFO("got geom\n");
|
||||||
|
//if ((hmax - hoff) < geom.minWidth) {
|
||||||
|
// todo wrap glyphs, grow bmp
|
||||||
|
//}
|
||||||
block =
|
block =
|
||||||
al_lock_bitmap_region(gtex, woff, hoff, geom.minWidth, geom.minHeight,
|
al_lock_bitmap_region(gtex, woff, hoff, geom.minWidth, geom.minHeight,
|
||||||
ALLEGRO_PIXEL_FORMAT_SINGLE_CHANNEL_8, ALLEGRO_LOCK_WRITEONLY);
|
ALLEGRO_PIXEL_FORMAT_ABGR_8888, ALLEGRO_LOCK_WRITEONLY);
|
||||||
ALLEGRO_INFO("got lock\n");
|
ALLEGRO_INFO("got lock\n");
|
||||||
img.width = geom.minWidth;
|
img.width = geom.minWidth;
|
||||||
img.height = geom.minHeight;
|
img.height = geom.minHeight;
|
||||||
img.pixels = block->data;
|
img.pixels = block->data;
|
||||||
if (0 > sft_render(&sft, glyph, img)) goto glyph_lookup_fail;
|
//if (0 > sft_render(&sft, glyph, img)) goto glyph_lookup_fail; // FIXME UB
|
||||||
ALLEGRO_INFO("got raster\n");
|
ALLEGRO_INFO("got raster\n");
|
||||||
al_unlock_bitmap(gtex);
|
al_unlock_bitmap(gtex);
|
||||||
ALLEGRO_INFO("unlock\n");
|
ALLEGRO_INFO("unlock\n");
|
||||||
@@ -128,8 +132,8 @@ ALLEGRO_FONT *al_load_ttf_font_f(ALLEGRO_FILE *file,
|
|||||||
i++; i++;
|
i++; i++;
|
||||||
}
|
}
|
||||||
f = al_grab_font_from_bitmap(gtex, ranges_size, ranges);
|
f = al_grab_font_from_bitmap(gtex, ranges_size, ranges);
|
||||||
f->dtor_item = _al_register_destructor(_al_dtor_list, "ttf_font", f,
|
//f->dtor_item = _al_register_destructor(_al_dtor_list, "ttf_font", f,
|
||||||
(void (*)(void *))al_destroy_font);
|
// (void (*)(void *))al_destroy_font);
|
||||||
ALLEGRO_DEBUG("Font %s loaded.\n", filename);
|
ALLEGRO_DEBUG("Font %s loaded.\n", filename);
|
||||||
|
|
||||||
CLEANUP;
|
CLEANUP;
|
||||||
|
|||||||
Reference in New Issue
Block a user