summaryrefslogtreecommitdiffstats
path: root/minuitwrp
diff options
context:
space:
mode:
authorEthan Yonker <dees_troy@teamw.in>2015-10-05 17:16:27 +0200
committerDees Troy <dees_troy@teamw.in>2015-10-16 22:57:35 +0200
commitb7a54a30167f211647222c0a2f90b369e0e33e32 (patch)
treefa6464e7a16456936de1cfaa087fcfc2f9564ff2 /minuitwrp
parentUnion sepolicy within TWRP to make SELinux permissive (diff)
downloadandroid_bootable_recovery-b7a54a30167f211647222c0a2f90b369e0e33e32.tar
android_bootable_recovery-b7a54a30167f211647222c0a2f90b369e0e33e32.tar.gz
android_bootable_recovery-b7a54a30167f211647222c0a2f90b369e0e33e32.tar.bz2
android_bootable_recovery-b7a54a30167f211647222c0a2f90b369e0e33e32.tar.lz
android_bootable_recovery-b7a54a30167f211647222c0a2f90b369e0e33e32.tar.xz
android_bootable_recovery-b7a54a30167f211647222c0a2f90b369e0e33e32.tar.zst
android_bootable_recovery-b7a54a30167f211647222c0a2f90b369e0e33e32.zip
Diffstat (limited to '')
-rw-r--r--minuitwrp/graphics.c93
-rw-r--r--minuitwrp/minui.h4
-rw-r--r--minuitwrp/truetype.c15
3 files changed, 92 insertions, 20 deletions
diff --git a/minuitwrp/graphics.c b/minuitwrp/graphics.c
index 5cc560e2f..fb86c1450 100644
--- a/minuitwrp/graphics.c
+++ b/minuitwrp/graphics.c
@@ -33,6 +33,7 @@
#include <pixelflinger/pixelflinger.h>
#include "minui.h"
+#include "../gui/placement.h"
#ifdef RECOVERY_BGRA
#define PIXEL_FORMAT GGL_PIXEL_FORMAT_BGRA_8888
@@ -93,14 +94,14 @@ int overlay_display_frame(int fd, GGLubyte* data, size_t size);
#ifdef PRINT_SCREENINFO
static void print_fb_var_screeninfo()
{
- printf("vi.xres: %d\n", vi.xres);
- printf("vi.yres: %d\n", vi.yres);
- printf("vi.xres_virtual: %d\n", vi.xres_virtual);
- printf("vi.yres_virtual: %d\n", vi.yres_virtual);
- printf("vi.xoffset: %d\n", vi.xoffset);
- printf("vi.yoffset: %d\n", vi.yoffset);
- printf("vi.bits_per_pixel: %d\n", vi.bits_per_pixel);
- printf("vi.grayscale: %d\n", vi.grayscale);
+ printf("vi.xres: %d\n", vi.xres);
+ printf("vi.yres: %d\n", vi.yres);
+ printf("vi.xres_virtual: %d\n", vi.xres_virtual);
+ printf("vi.yres_virtual: %d\n", vi.yres_virtual);
+ printf("vi.xoffset: %d\n", vi.xoffset);
+ printf("vi.yoffset: %d\n", vi.yoffset);
+ printf("vi.bits_per_pixel: %d\n", vi.bits_per_pixel);
+ printf("vi.grayscale: %d\n", vi.grayscale);
}
#endif
@@ -221,20 +222,20 @@ static int get_framebuffer(GGLSurface *fb)
vi.transp.length = 8;
} else if (PIXEL_FORMAT == GGL_PIXEL_FORMAT_RGB_565) {
#ifdef RECOVERY_RGB_565
- fprintf(stderr, "Pixel format: RGB_565\n");
- vi.blue.offset = 0;
- vi.green.offset = 5;
- vi.red.offset = 11;
+ fprintf(stderr, "Pixel format: RGB_565\n");
+ vi.blue.offset = 0;
+ vi.green.offset = 5;
+ vi.red.offset = 11;
#else
fprintf(stderr, "Pixel format: BGR_565\n");
- vi.blue.offset = 11;
- vi.green.offset = 5;
- vi.red.offset = 0;
+ vi.blue.offset = 11;
+ vi.green.offset = 5;
+ vi.red.offset = 0;
#endif
- if (PIXEL_SIZE != 2) fprintf(stderr, "E: Pixel Size mismatch!\n");
- vi.blue.length = 5;
- vi.green.length = 6;
- vi.red.length = 5;
+ if (PIXEL_SIZE != 2) fprintf(stderr, "E: Pixel Size mismatch!\n");
+ vi.blue.length = 5;
+ vi.green.length = 6;
+ vi.red.length = 5;
vi.blue.msb_right = 0;
vi.green.msb_right = 0;
vi.red.msb_right = 0;
@@ -331,7 +332,7 @@ static int get_framebuffer(GGLSurface *fb)
}
#ifdef PRINT_SCREENINFO
- print_fb_var_screeninfo();
+ print_fb_var_screeninfo();
#endif
return fd;
@@ -433,6 +434,58 @@ int gr_textEx(int x, int y, const char *s, void* pFont)
return gr_ttf_textExWH(gl, x, y, s, pFont, -1, -1);
}
+int gr_textEx_scaleW(int x, int y, const char *s, void* pFont, int max_width, int placement, int scale)
+{
+ GGLContext *gl = gr_context;
+ void* vfont = pFont;
+ GRFont *font = (GRFont*) pFont;
+ unsigned off;
+ unsigned cwidth;
+ int y_scale = 0, measured_width, measured_height, ret, new_height;
+
+ if (!s || strlen(s) == 0 || !font)
+ return 0;
+
+ measured_height = gr_ttf_getMaxFontHeight(font);
+
+ if (scale) {
+ measured_width = gr_ttf_measureEx(s, vfont);
+ if (measured_width > max_width) {
+ // Adjust font size down until the text fits
+ void *new_font = gr_ttf_scaleFont(vfont, max_width, measured_width);
+ if (!new_font) {
+ printf("gr_textEx_scaleW new_font is NULL\n");
+ return 0;
+ }
+ measured_width = gr_ttf_measureEx(s, new_font);
+ // These next 2 lines adjust the y point based on the new font's height
+ new_height = gr_ttf_getMaxFontHeight(new_font);
+ y_scale = (measured_height - new_height) / 2;
+ vfont = new_font;
+ }
+ } else
+ measured_width = gr_ttf_measureEx(s, vfont);
+
+ int x_adj = measured_width;
+ if (measured_width > max_width)
+ x_adj = max_width;
+
+ if (placement != TOP_LEFT && placement != BOTTOM_LEFT && placement != TEXT_ONLY_RIGHT) {
+ if (placement == CENTER || placement == CENTER_X_ONLY)
+ x -= (x_adj / 2);
+ else
+ x -= x_adj;
+ }
+
+ if (placement != TOP_LEFT && placement != TOP_RIGHT) {
+ if (placement == CENTER || placement == TEXT_ONLY_RIGHT)
+ y -= (measured_height / 2);
+ else if (placement == BOTTOM_LEFT || placement == BOTTOM_RIGHT)
+ y -= measured_height;
+ }
+ return gr_ttf_textExWH(gl, x, y + y_scale, s, vfont, measured_width + x, -1);
+}
+
int gr_textExW(int x, int y, const char *s, void* pFont, int max_width)
{
GGLContext *gl = gr_context;
diff --git a/minuitwrp/minui.h b/minuitwrp/minui.h
index 1744928dd..25a785a5b 100644
--- a/minuitwrp/minui.h
+++ b/minuitwrp/minui.h
@@ -17,6 +17,8 @@
#ifndef _MINUI_H_
#define _MINUI_H_
+#include "../gui/placement.h"
+
typedef void* gr_surface;
typedef unsigned short gr_pixel;
@@ -40,6 +42,7 @@ void gr_line(int x0, int y0, int x1, int y1, int width);
gr_surface gr_render_circle(int radius, unsigned char r, unsigned char g, unsigned char b, unsigned char a);
int gr_textEx(int x, int y, const char *s, void* font);
+int gr_textEx_scaleW(int x, int y, const char *s, void* pFont, int max_width, int placement, int scale);
int gr_textExW(int x, int y, const char *s, void* font, int max_width);
int gr_textExWH(int x, int y, const char *s, void* pFont, int max_width, int max_height);
static inline int gr_text(int x, int y, const char *s) { return gr_textEx(x, y, s, NULL); }
@@ -50,6 +53,7 @@ int gr_maxExW(const char *s, void* font, int max_width);
int gr_getMaxFontHeight(void *font);
void *gr_ttf_loadFont(const char *filename, int size, int dpi);
+void *gr_ttf_scaleFont(void *font, int max_width, int measured_width);
void gr_ttf_freeFont(void *font);
int gr_ttf_textExWH(void *context, int x, int y, const char *s, void *pFont, int max_width, int max_height);
int gr_ttf_measureEx(const char *s, void *font);
diff --git a/minuitwrp/truetype.c b/minuitwrp/truetype.c
index 8f62ff26b..d9ed0198b 100644
--- a/minuitwrp/truetype.c
+++ b/minuitwrp/truetype.c
@@ -265,6 +265,21 @@ exit:
return res;
}
+void *gr_ttf_scaleFont(void *font, int max_width, int measured_width)
+{
+ if (!font)
+ return NULL;
+
+ TrueTypeFont *f = font;
+ float scale_value = (float)(max_width) / (float)(measured_width);
+ int new_size = ((int)((float)f->size * scale_value)) - 1;
+ if (new_size < 1)
+ new_size = 1;
+ const char* file = f->key->path;
+ int dpi = f->dpi;
+ return gr_ttf_loadFont(file, new_size, dpi);
+}
+
static bool gr_ttf_freeFontCache(void *key, void *value, void *context)
{
TrueTypeCacheEntry *e = value;