From 55a36ac1e01205f2cd461cd2f89d92e3b64cddd2 Mon Sep 17 00:00:00 2001 From: Doug Zongker Date: Mon, 4 Mar 2013 15:49:02 -0800 Subject: recovery: change font for menus to be an image Instead of representing the font used for menus and log messages in the recovery binary, load it from a resource PNG image. This allows different devices to substitute their own font images. Change-Id: Ib36b86db3d01298aa7ae2b62a26ca29e6ef18014 --- minui/graphics.c | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) (limited to 'minui/graphics.c') diff --git a/minui/graphics.c b/minui/graphics.c index 747b2dbc6..ba68a9538 100644 --- a/minui/graphics.c +++ b/minui/graphics.c @@ -30,7 +30,6 @@ #include -#include "font_10x18.h" #include "minui.h" #if defined(RECOVERY_BGRA) @@ -47,7 +46,7 @@ #define NUM_BUFFERS 2 typedef struct { - GGLSurface texture; + GGLSurface* texture; unsigned cwidth; unsigned cheight; unsigned ascent; @@ -230,12 +229,14 @@ int gr_text(int x, int y, const char *s) GRFont *font = gr_font; unsigned off; + if (!font->texture) return x; + x += overscan_offset_x; y += overscan_offset_y; y -= font->ascent; - gl->bindTexture(gl, &font->texture); + gl->bindTexture(gl, font->texture); gl->texEnvi(gl, GGL_TEXTURE_ENV, GGL_TEXTURE_ENV_MODE, GGL_REPLACE); gl->texGeni(gl, GGL_S, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE); gl->texGeni(gl, GGL_T, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE); @@ -322,31 +323,21 @@ unsigned int gr_get_height(gr_surface surface) { static void gr_init_font(void) { - GGLSurface *ftex; - unsigned char *bits, *rle; - unsigned char *in, data; - gr_font = calloc(sizeof(*gr_font), 1); - ftex = &gr_font->texture; - - bits = malloc(font.width * font.height); - ftex->version = sizeof(*ftex); - ftex->width = font.width; - ftex->height = font.height; - ftex->stride = font.width; - ftex->data = (void*) bits; - ftex->format = GGL_PIXEL_FORMAT_A_8; - - in = font.rundata; - while((data = *in++)) { - memset(bits, (data & 0x80) ? 255 : 0, data & 0x7f); - bits += (data & 0x7f); + int res = res_create_surface("font", (void**)&(gr_font->texture)); + if (res != 0) { + printf("failed to read font: res=%d\n", res); + gr_font->texture = NULL; + return; } - gr_font->cwidth = font.cwidth; - gr_font->cheight = font.cheight; - gr_font->ascent = font.cheight - 2; + // interpret the grayscale as alpha + gr_font->texture->format = GGL_PIXEL_FORMAT_A_8; + + gr_font->cwidth = gr_font->texture->width / 96; + gr_font->cheight = gr_font->texture->height; + gr_font->ascent = gr_font->cheight - 2; } int gr_init(void) -- cgit v1.2.3