diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/graphics/font.c | 11 | ||||
-rw-r--r-- | src/window/window.c | 2 |
2 files changed, 11 insertions, 2 deletions
diff --git a/src/graphics/font.c b/src/graphics/font.c index b6ceaf5..40fe641 100644 --- a/src/graphics/font.c +++ b/src/graphics/font.c @@ -4,6 +4,8 @@ #define STB_TRUETYPE_IMPLEMENTATION #include "../../external/stb_truetype.h" +/* TODO: Show a rectangle for unsupported glyphs or if |self| is NULL */ + /* Need padding so filtering doesn't touch pixels in another glyphs area */ #define GLYPH_PADDING 2 #define GLYPH_UPSAMPLE 1 @@ -125,6 +127,9 @@ static void mgl_font_handle_new_render_position(mgl_font *self, int glyph_width) } int mgl_font_get_glyph(mgl_font *self, uint32_t codepoint, mgl_font_glyph *glyph) { + if(!self) + return -1; + if(self->font_atlas.width == 0) { if(self->texture.id == 0 && mgl_texture_init(&self->texture) != 0) return -1; @@ -136,7 +141,9 @@ int mgl_font_get_glyph(mgl_font *self, uint32_t codepoint, mgl_font_glyph *glyph .pixel_coordinates = true }; - if(mgl_texture_load_from_memory(&self->texture, NULL, initial_atlas_size, initial_atlas_size, MGL_IMAGE_FORMAT_ALPHA, &load_options) == 0) { + if(mgl_texture_load_from_memory(&self->texture, NULL, initial_atlas_size, initial_atlas_size, MGL_IMAGE_FORMAT_ALPHA, &load_options) != 0) { + return -1; + } else { /*fprintf(stderr, "Error: failed to create font atlas texture, error: mgl_texture_load_from_memory failed\n");*/ self->font_atlas.width = initial_atlas_size; self->font_atlas.height = initial_atlas_size; @@ -230,5 +237,7 @@ int mgl_font_get_glyph(mgl_font *self, uint32_t codepoint, mgl_font_glyph *glyph } float mgl_font_get_kerning(const mgl_font *self, uint32_t prev_codepoint, uint32_t codepoint) { + if(!self || self->texture.id == 0) + return 0.0f; return stbtt_GetCodepointKernAdvance(self->font_info, prev_codepoint, codepoint) * stbtt_ScaleForPixelHeight(self->font_info, self->character_size); } diff --git a/src/window/window.c b/src/window/window.c index 8ed68e7..13bb4ba 100644 --- a/src/window/window.c +++ b/src/window/window.c @@ -581,7 +581,7 @@ static void mgl_window_on_receive_event(mgl_window *self, XEvent *xev, mgl_event } case ConfigureNotify: { while(XCheckTypedWindowEvent(context->connection, self->window, ConfigureNotify, xev)) {} - if(xev->xconfigure.width != self->size.x || xev->xconfigure.height != self->size.x) { + if(xev->xconfigure.width != self->size.x || xev->xconfigure.height != self->size.y) { mgl_window_on_resize(self, xev->xconfigure.width, xev->xconfigure.height); event->type = MGL_EVENT_RESIZED; |