From f4e26656e4425f7cc83bedb7cc7aa15ca5e6e0b0 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Fri, 29 Jul 2016 21:11:49 -0700 Subject: [PATCH] PSP2: Use PGF fonts --- CHANGES | 1 + src/platform/psp2/CMakeLists.txt | 2 +- src/platform/psp2/gui-font.c | 25 +++++++++---------------- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/CHANGES b/CHANGES index 8620dd36e..1015a1321 100644 --- a/CHANGES +++ b/CHANGES @@ -26,6 +26,7 @@ Misc: - 3DS: Allow UTF-16 filenames - 3DS: Port to using citro3D - 3DS: Use system font for menus + - PSP2: Use system font for menus 0.4.1: (2016-07-11) Bugfixes: diff --git a/src/platform/psp2/CMakeLists.txt b/src/platform/psp2/CMakeLists.txt index 71d696a09..bb0f2b12d 100644 --- a/src/platform/psp2/CMakeLists.txt +++ b/src/platform/psp2/CMakeLists.txt @@ -15,7 +15,7 @@ source_group("PS Vita-specific code" FILES ${OS_SRC}) list(APPEND CORE_VFS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/sce-vfs.c) set(CORE_VFS_SRC ${CORE_VFS_SRC} PARENT_SCOPE) -set(OS_LIB -lvita2d -lSceCtrl_stub -lSceGxm_stub -lSceDisplay_stub -lSceAudio_stub -lSceCommonDialog_stub -lSceMotion_stub -lScePower_stub -lSceSysmodule_stub -lSceTouch_stub -l${M_LIBRARY}) +set(OS_LIB -lvita2d -lSceCtrl_stub -lScePgf_stub -lSceGxm_stub -lSceDisplay_stub -lSceAudio_stub -lSceCommonDialog_stub -lSceMotion_stub -lScePower_stub -lSceSysmodule_stub -lSceTouch_stub -l${M_LIBRARY}) set(OBJCOPY_CMD ${OBJCOPY} -I binary -O elf32-littlearm -B arm) list(APPEND GUI_SRC ${CMAKE_CURRENT_SOURCE_DIR}/gui-font.c) diff --git a/src/platform/psp2/gui-font.c b/src/platform/psp2/gui-font.c index aa1e6cdc1..b6452dd5f 100644 --- a/src/platform/psp2/gui-font.c +++ b/src/platform/psp2/gui-font.c @@ -10,13 +10,12 @@ #define CELL_HEIGHT 32 #define CELL_WIDTH 32 -#define GLYPH_HEIGHT 24 +#define FONT_SIZE 1.2f -extern const uint8_t _binary_font2x_png_start[]; extern const uint8_t _binary_icons2x_png_start[]; struct GUIFont { - vita2d_texture* tex; + vita2d_pgf* pgf; vita2d_texture* icons; }; @@ -25,28 +24,27 @@ struct GUIFont* GUIFontCreate(void) { if (!font) { return 0; } - font->tex = vita2d_load_PNG_buffer(_binary_font2x_png_start); + font->pgf = vita2d_load_default_pgf(); font->icons = vita2d_load_PNG_buffer(_binary_icons2x_png_start); return font; } void GUIFontDestroy(struct GUIFont* font) { - vita2d_free_texture(font->tex); + vita2d_free_pgf(font->pgf); vita2d_free_texture(font->icons); free(font); } unsigned GUIFontHeight(const struct GUIFont* font) { - UNUSED(font); - return GLYPH_HEIGHT; + return vita2d_pgf_text_height(font->pgf, FONT_SIZE, "M") + 8; } unsigned GUIFontGlyphWidth(const struct GUIFont* font, uint32_t glyph) { - UNUSED(font); if (glyph > 0x7F) { glyph = '?'; } - return defaultFontMetrics[glyph].width * 2; + char base[5] = { glyph }; + return vita2d_pgf_text_width(font->pgf, FONT_SIZE, base); } void GUIFontIconMetrics(const struct GUIFont* font, enum GUIIcon icon, unsigned* w, unsigned* h) { @@ -72,13 +70,8 @@ void GUIFontDrawGlyph(const struct GUIFont* font, int x, int y, uint32_t color, if (glyph > 0x7F) { glyph = '?'; } - struct GUIFontGlyphMetric metric = defaultFontMetrics[glyph]; - vita2d_draw_texture_tint_part(font->tex, x, y - GLYPH_HEIGHT + metric.padding.top * 2, - (glyph & 15) * CELL_WIDTH + metric.padding.left * 2, - (glyph >> 4) * CELL_HEIGHT + metric.padding.top * 2, - CELL_WIDTH - (metric.padding.left + metric.padding.right) * 2, - CELL_HEIGHT - (metric.padding.top + metric.padding.bottom) * 2, - color); + char base[5] = { glyph }; + vita2d_pgf_draw_text(font->pgf, x, y, color, FONT_SIZE, base); } void GUIFontDrawIcon(const struct GUIFont* font, int x, int y, enum GUIAlignment align, enum GUIOrientation orient, uint32_t color, enum GUIIcon icon) {