Fix text alignment when using stb_unicode
This commit is contained in:
parent
8aaef0e95c
commit
38d2febba5
|
@ -66,6 +66,13 @@ typedef struct
|
||||||
unsigned usage_counter;
|
unsigned usage_counter;
|
||||||
} stb_unicode_font_renderer_t;
|
} stb_unicode_font_renderer_t;
|
||||||
|
|
||||||
|
/* Ugly little thing... */
|
||||||
|
static int INLINE round_away_from_zero(float f)
|
||||||
|
{
|
||||||
|
double round = (f < 0.0) ? floor((double)f) : ceil((double)f);
|
||||||
|
return (int)round;
|
||||||
|
}
|
||||||
|
|
||||||
static struct font_atlas *font_renderer_stb_unicode_get_atlas(void *data)
|
static struct font_atlas *font_renderer_stb_unicode_get_atlas(void *data)
|
||||||
{
|
{
|
||||||
stb_unicode_font_renderer_t *self = (stb_unicode_font_renderer_t*)data;
|
stb_unicode_font_renderer_t *self = (stb_unicode_font_renderer_t*)data;
|
||||||
|
@ -153,10 +160,10 @@ static const struct font_glyph *font_renderer_stb_unicode_get_glyph(
|
||||||
|
|
||||||
atlas_slot->glyph.width = self->max_glyph_width;
|
atlas_slot->glyph.width = self->max_glyph_width;
|
||||||
atlas_slot->glyph.height = self->max_glyph_height;
|
atlas_slot->glyph.height = self->max_glyph_height;
|
||||||
atlas_slot->glyph.advance_x = advance_width * self->scale_factor;
|
atlas_slot->glyph.advance_x = round_away_from_zero((float)advance_width * self->scale_factor);
|
||||||
/* atlas_slot->glyph.advance_y = 0 ; */
|
atlas_slot->glyph.advance_y = 0;
|
||||||
atlas_slot->glyph.draw_offset_x = x0 * self->scale_factor;
|
atlas_slot->glyph.draw_offset_x = round_away_from_zero((float)x0 * self->scale_factor);
|
||||||
atlas_slot->glyph.draw_offset_y = -y1 * self->scale_factor;
|
atlas_slot->glyph.draw_offset_y = round_away_from_zero((float)(-y1) * self->scale_factor);
|
||||||
|
|
||||||
self->atlas.dirty = true;
|
self->atlas.dirty = true;
|
||||||
atlas_slot->last_used = self->usage_counter++;
|
atlas_slot->last_used = self->usage_counter++;
|
||||||
|
@ -177,7 +184,7 @@ static bool font_renderer_stb_unicode_create_atlas(
|
||||||
self->atlas.height = self->max_glyph_height * STB_UNICODE_ATLAS_ROWS;
|
self->atlas.height = self->max_glyph_height * STB_UNICODE_ATLAS_ROWS;
|
||||||
|
|
||||||
self->atlas.buffer = (uint8_t*)
|
self->atlas.buffer = (uint8_t*)
|
||||||
calloc(self->atlas.width * self->atlas.height, 1);
|
calloc(self->atlas.width * self->atlas.height, sizeof(uint8_t));
|
||||||
|
|
||||||
if (!self->atlas.buffer)
|
if (!self->atlas.buffer)
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue