summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDamien Bargiacchi <drb@google.com>2016-09-13 17:50:25 +0200
committerandroid-build-merger <android-build-merger@google.com>2016-09-13 17:50:25 +0200
commit8568d7e558f5aa1c4f05745eb764aeebb1d4da95 (patch)
tree9b1e9c9c2a8aeed5de497fae4825b97068c4cad9
parentsave uncrypt status to last_install am: e16e799dfd (diff)
parentHave gr_init_font alloc memory for the font (diff)
downloadandroid_bootable_recovery-8568d7e558f5aa1c4f05745eb764aeebb1d4da95.tar
android_bootable_recovery-8568d7e558f5aa1c4f05745eb764aeebb1d4da95.tar.gz
android_bootable_recovery-8568d7e558f5aa1c4f05745eb764aeebb1d4da95.tar.bz2
android_bootable_recovery-8568d7e558f5aa1c4f05745eb764aeebb1d4da95.tar.lz
android_bootable_recovery-8568d7e558f5aa1c4f05745eb764aeebb1d4da95.tar.xz
android_bootable_recovery-8568d7e558f5aa1c4f05745eb764aeebb1d4da95.tar.zst
android_bootable_recovery-8568d7e558f5aa1c4f05745eb764aeebb1d4da95.zip
-rw-r--r--minui/graphics.cpp22
-rw-r--r--minui/minui.h2
2 files changed, 16 insertions, 8 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;
diff --git a/minui/minui.h b/minui/minui.h
index f6b42c628..78890b84b 100644
--- a/minui/minui.h
+++ b/minui/minui.h
@@ -55,7 +55,7 @@ void gr_fill(int x1, int y1, int x2, int y2);
void gr_texticon(int x, int y, GRSurface* icon);
const GRFont* gr_sys_font();
-int gr_init_font(const char* name, GRFont* dest);
+int gr_init_font(const char* name, GRFont** dest);
void gr_text(const GRFont* font, int x, int y, const char *s, bool bold);
int gr_measure(const GRFont* font, const char *s);
void gr_font_size(const GRFont* font, int *x, int *y);