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.
This commit is contained in:
Lephe 2020-10-20 15:08:29 +02:00
parent e63ff8351b
commit 3a15340335
No known key found for this signature in database
GPG key ID: 1BBA026E13FC0495
3 changed files with 9 additions and 9 deletions

View file

@ -123,7 +123,7 @@ $(call src2obj,../src/font8x9.png): ../src/font8x9.png
$(call cmd_m,fxconv,font8x9.png) fxconv -f $< -o $@ \ $(call cmd_m,fxconv,font8x9.png) fxconv -f $< -o $@ \
--cg --toolchain=$(CONFIG.TOOLCHAIN) name:gint_font8x9 \ --cg --toolchain=$(CONFIG.TOOLCHAIN) name:gint_font8x9 \
charset:print grid.size:8x11 grid.padding:1 grid.border:0 \ 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 # Version symbol. ld generates a .stack section for unknown reasons; I remove
# it in the linker script. # it in the linker script.

View file

@ -114,10 +114,10 @@ void dtext_opt(int x, int y, int fg, int bg, int halign, int valign,
int w, h; int w, h;
dsize(str, topti_font, &w, &h); dsize(str, topti_font, &w, &h);
if(halign == DTEXT_RIGHT) x -= w; if(halign == DTEXT_RIGHT) x -= w - 1;
if(halign == DTEXT_CENTER) x -= ((w+1) >> 1); if(halign == DTEXT_CENTER) x -= (w >> 1);
if(valign == DTEXT_BOTTOM) y -= h; if(valign == DTEXT_BOTTOM) y -= h - 1;
if(valign == DTEXT_MIDDLE) y -= ((h+1) >> 1); if(valign == DTEXT_MIDDLE) y -= (h >> 1);
} }
topti_render(x, y, str, topti_font, fg, bg); topti_render(x, y, str, topti_font, fg, bg);

View file

@ -186,10 +186,10 @@ void dtext_opt(int x, int y, int fg, int bg, int halign, int valign,
int w, h; int w, h;
dsize(str, topti_font, &w, &h); dsize(str, topti_font, &w, &h);
if(halign == DTEXT_RIGHT) x -= w; if(halign == DTEXT_RIGHT) x -= w - 1;
if(halign == DTEXT_CENTER) x -= ((w+1) >> 1); if(halign == DTEXT_CENTER) x -= (w >> 1);
if(valign == DTEXT_BOTTOM) y -= h; if(valign == DTEXT_BOTTOM) y -= h - 1;
if(valign == DTEXT_MIDDLE) y -= ((h+1) >> 1); if(valign == DTEXT_MIDDLE) y -= (h >> 1);
} }
topti_render(x, y, str, topti_font, topti_asm_text[fg], topti_render(x, y, str, topti_font, topti_asm_text[fg],