summaryrefslogtreecommitdiffstats
path: root/minui/graphics.cpp
diff options
context:
space:
mode:
authorDamien Bargiacchi <drb@google.com>2016-09-09 16:14:08 +0200
committerDamien Bargiacchi <drb@google.com>2016-09-09 17:32:21 +0200
commitd00f5eb63a8e4690f9bef1e943d539d052444d9b (patch)
tree1f1b0ddc56860585a44820abd2df37480c5ea4d6 /minui/graphics.cpp
parentRemove debug log statement; fix build (diff)
downloadandroid_bootable_recovery-d00f5eb63a8e4690f9bef1e943d539d052444d9b.tar
android_bootable_recovery-d00f5eb63a8e4690f9bef1e943d539d052444d9b.tar.gz
android_bootable_recovery-d00f5eb63a8e4690f9bef1e943d539d052444d9b.tar.bz2
android_bootable_recovery-d00f5eb63a8e4690f9bef1e943d539d052444d9b.tar.lz
android_bootable_recovery-d00f5eb63a8e4690f9bef1e943d539d052444d9b.tar.xz
android_bootable_recovery-d00f5eb63a8e4690f9bef1e943d539d052444d9b.tar.zst
android_bootable_recovery-d00f5eb63a8e4690f9bef1e943d539d052444d9b.zip
Diffstat (limited to 'minui/graphics.cpp')
-rw-r--r--minui/graphics.cpp22
1 files changed, 15 insertions, 7 deletions
diff --git a/minui/graphics.cpp b/minui/graphics.cpp
index 43ec83f08..ab56a6fd6 100644
--- a/minui/graphics.cpp
+++ b/minui/graphics.cpp
@@ -264,33 +264,41 @@ unsigned int gr_get_height(GRSurface* surface) {
return surface->height;
}
-int gr_init_font(const char* name, GRFont* dest) {
- int res = res_create_alpha_surface(name, &(dest->texture));
+int gr_init_font(const char* name, GRFont** dest) {
+ GRFont* font = reinterpret_cast<GRFont*>(calloc(1, sizeof(*gr_font)));
+ if (font == nullptr) {
+ return -1;
+ }
+
+ int res = res_create_alpha_surface(name, &(font->texture));
if (res < 0) {
+ free(font);
return res;
}
// The font image should be a 96x2 array of character images. The
// columns are the printable ASCII characters 0x20 - 0x7f. The
// top row is regular text; the bottom row is bold.
- dest->char_width = dest->texture->width / 96;
- dest->char_height = dest->texture->height / 2;
+ font->char_width = font->texture->width / 96;
+ font->char_height = font->texture->height / 2;
+
+ *dest = font;
return 0;
}
static void gr_init_font(void)
{
- gr_font = reinterpret_cast<GRFont*>(calloc(sizeof(*gr_font), 1));
-
- int res = gr_init_font("font", gr_font);
+ int res = gr_init_font("font", &gr_font);
if (res == 0) {
return;
}
printf("failed to read font: res=%d\n", res);
+
// fall back to the compiled-in font.
+ gr_font = reinterpret_cast<GRFont*>(calloc(1, sizeof(*gr_font)));
gr_font->texture = reinterpret_cast<GRSurface*>(malloc(sizeof(*gr_font->texture)));
gr_font->texture->width = font.width;
gr_font->texture->height = font.height;