From b8cae8e735959a11f956ab44d20e5a1774ba6f09 Mon Sep 17 00:00:00 2001
From: spherallic <spherallic@gmail.com>
Date: Fri, 4 Feb 2022 13:36:27 +0100
Subject: [PATCH] Add kerning option to fontdefs, rename width and height.

---
 src/hu_stuff.c | 10 ++++++----
 src/hu_stuff.h |  5 +++--
 src/v_video.c  | 18 +++++++++---------
 3 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/src/hu_stuff.c b/src/hu_stuff.c
index 072bfaa475..74bea75722 100644
--- a/src/hu_stuff.c
+++ b/src/hu_stuff.c
@@ -206,11 +206,13 @@ void HU_LoadGraphics(void)
 			tny_font.chars[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX);
 	}
 
-	hu_font.width = 8;
-	hu_font.height = 12;
+	hu_font.kerning = 0;
+	hu_font.spacewidth = 4;
+	hu_font.linespacing = 12;
 
-	tny_font.width = 5;
-	tny_font.height = 12;
+	tny_font.kerning = 0;
+	tny_font.spacewidth = 2;
+	tny_font.linespacing = 12;
 
 	j = LT_FONTSTART;
 	for (i = 0; i < LT_FONTSIZE; i++)
diff --git a/src/hu_stuff.h b/src/hu_stuff.h
index 054e8be5d7..0e6710220f 100644
--- a/src/hu_stuff.h
+++ b/src/hu_stuff.h
@@ -49,8 +49,9 @@ extern char english_shiftxform[];
 typedef struct
 {
 	patch_t *chars[HU_FONTSIZE];
-	INT32 width;
-	INT32 height;
+	INT32 kerning;
+	UINT32 spacewidth;
+	UINT32 linespacing;
 } fontdef_t;
 
 extern fontdef_t hu_font, tny_font;
diff --git a/src/v_video.c b/src/v_video.c
index 7534ad8e42..5dec382c3a 100644
--- a/src/v_video.c
+++ b/src/v_video.c
@@ -2166,7 +2166,7 @@ void V_DrawFontStringAtFixed(fixed_t x, fixed_t y, INT32 option, fixed_t pscale,
 	INT32 w, c, dupx, dupy, scrwidth, center = 0, left = 0;
 	const char *ch = string;
 	INT32 charflags = (option & V_CHARCOLORMASK);
-	INT32 spacewidth = font.width/2, charwidth = 0;
+	INT32 spacewidth = font.spacewidth, charwidth = 0;
 
 	INT32 lowercase = (option & V_ALLOWLOWERCASE);
 	option &= ~V_FLIP; // which is also shared with V_ALLOWLOWERCASE...
@@ -2192,10 +2192,10 @@ void V_DrawFontStringAtFixed(fixed_t x, fixed_t y, INT32 option, fixed_t pscale,
 	switch (option & V_SPACINGMASK) // TODO: drop support for these crusty flags in the next major update
 	{
 		case V_MONOSPACE:
-			spacewidth = font.width;
+			spacewidth = font.spacewidth*2;
 			/* FALLTHRU */
 		case V_OLDSPACING:
-			charwidth = font.width;
+			charwidth = font.spacewidth*2;
 			break;
 		case V_6WIDTHSPACE:
 			spacewidth = 6;
@@ -2221,7 +2221,7 @@ void V_DrawFontStringAtFixed(fixed_t x, fixed_t y, INT32 option, fixed_t pscale,
 			if (option & V_RETURN8)
 				cy += FixedMul((8<<FRACBITS), dupy);
 			else
-				cy += FixedMul((font.height<<FRACBITS), dupy);
+				cy += FixedMul((font.linespacing<<FRACBITS), dupy);
 
 			continue;
 		}
@@ -2255,7 +2255,7 @@ void V_DrawFontStringAtFixed(fixed_t x, fixed_t y, INT32 option, fixed_t pscale,
 
 		V_DrawStretchyFixedPatch(cx + center, cy, pscale, vscale, option, font.chars[c], V_GetStringColormap(charflags));
 
-		cx += w;
+		cx += w + (font.kerning<<FRACBITS);
 	}
 }
 
@@ -2742,16 +2742,16 @@ INT16 V_LevelActNumWidth(UINT8 num)
 INT32 V_FontStringWidth(const char *string, INT32 option, fontdef_t font)
 {
 	INT32 c, w = 0;
-	INT32 spacewidth = font.width/2, charwidth = 0;
+	INT32 spacewidth = font.spacewidth, charwidth = 0;
 	size_t i;
 
 	switch (option & V_SPACINGMASK)
 	{
 		case V_MONOSPACE:
-			spacewidth = font.width;
+			spacewidth = font.spacewidth*2;
 			/* FALLTHRU */
 		case V_OLDSPACING:
-			charwidth = font.width;
+			charwidth = font.spacewidth*2;
 			break;
 		case V_6WIDTHSPACE:
 			spacewidth = 6;
@@ -2767,7 +2767,7 @@ INT32 V_FontStringWidth(const char *string, INT32 option, fontdef_t font)
 		if (c < 0 || c >= HU_FONTSIZE || !font.chars[c])
 			w += spacewidth;
 		else
-			w += (charwidth ? charwidth : (font.chars[c]->width));
+			w += (charwidth ? charwidth : (font.chars[c]->width)) + font.kerning;
 	}
 
 	if (option & (V_NOSCALESTART|V_NOSCALEPATCH))
-- 
GitLab