From 3a15340335050918e5758c50e5066a50cb592f2a Mon Sep 17 00:00:00 2001 From: Lephe Date: Tue, 20 Oct 2020 15:08:29 +0200 Subject: [PATCH] topti: improve text positioning * Specify a line height for the default fx-CG 50 font so that the height returned by dsize() is correctly 9, not 11. * Adjust vertical and horizontal alignment in dtext_opt() and dprint_opt() by a full pixel (DTEXT_BOTTOM, DTEXT_RIGHT) and half a pixel (DTEXT_MIDDLE, DTEXT_CENTER) to make sure that the specified position is within rendered text (as in DTEXT_LEFT and TEXT_TOP) and to improve centering of strings with odd width or odd height, for which there is only one valid position. --- make/Makefile | 2 +- src/render-cg/topti.c | 8 ++++---- src/render-fx/topti.c | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/make/Makefile b/make/Makefile index f86f81f..70a4e7d 100755 --- a/make/Makefile +++ b/make/Makefile @@ -123,7 +123,7 @@ $(call src2obj,../src/font8x9.png): ../src/font8x9.png $(call cmd_m,fxconv,font8x9.png) fxconv -f $< -o $@ \ --cg --toolchain=$(CONFIG.TOOLCHAIN) name:gint_font8x9 \ charset:print grid.size:8x11 grid.padding:1 grid.border:0 \ - proportional:true + proportional:true height:9 # Version symbol. ld generates a .stack section for unknown reasons; I remove # it in the linker script. diff --git a/src/render-cg/topti.c b/src/render-cg/topti.c index ef8c73d..e703cf4 100644 --- a/src/render-cg/topti.c +++ b/src/render-cg/topti.c @@ -114,10 +114,10 @@ void dtext_opt(int x, int y, int fg, int bg, int halign, int valign, int w, h; dsize(str, topti_font, &w, &h); - if(halign == DTEXT_RIGHT) x -= w; - if(halign == DTEXT_CENTER) x -= ((w+1) >> 1); - if(valign == DTEXT_BOTTOM) y -= h; - if(valign == DTEXT_MIDDLE) y -= ((h+1) >> 1); + if(halign == DTEXT_RIGHT) x -= w - 1; + if(halign == DTEXT_CENTER) x -= (w >> 1); + if(valign == DTEXT_BOTTOM) y -= h - 1; + if(valign == DTEXT_MIDDLE) y -= (h >> 1); } topti_render(x, y, str, topti_font, fg, bg); diff --git a/src/render-fx/topti.c b/src/render-fx/topti.c index f9db890..e9f9cd4 100644 --- a/src/render-fx/topti.c +++ b/src/render-fx/topti.c @@ -186,10 +186,10 @@ void dtext_opt(int x, int y, int fg, int bg, int halign, int valign, int w, h; dsize(str, topti_font, &w, &h); - if(halign == DTEXT_RIGHT) x -= w; - if(halign == DTEXT_CENTER) x -= ((w+1) >> 1); - if(valign == DTEXT_BOTTOM) y -= h; - if(valign == DTEXT_MIDDLE) y -= ((h+1) >> 1); + if(halign == DTEXT_RIGHT) x -= w - 1; + if(halign == DTEXT_CENTER) x -= (w >> 1); + if(valign == DTEXT_BOTTOM) y -= h - 1; + if(valign == DTEXT_MIDDLE) y -= (h >> 1); } topti_render(x, y, str, topti_font, topti_asm_text[fg],