Skip to content

gsKit_fontm_print_scaled: Alignment does not take into account special characters #45

@ticky

Description

@ticky

When printing characters in the JIS range using the \f prefix in the gsFontM module, centered or right-aligned text is measured based on the full string length including the four digit character code and the \f character.

i.e. a string of "\f0062 Enter" is treated as 11 characters long, rather than 7.

The same goes for the \e helper, though due to the variable lengths this one probably requires a more complex solution.

I haven't been able to build gsKit myself but I believe this patch would help, if my maths is right, presuming that the programmer didn't input an invalid character code:

diff --git a/ee/gs/src/gsFontM.c b/ee/gs/src/gsFontM.c
index 983e05e..0f189d7 100644
--- a/ee/gs/src/gsFontM.c
+++ b/ee/gs/src/gsFontM.c
@@ -357,6 +357,11 @@ void gsKit_fontm_print_scaled(GSGLOBAL *gsGlobal, GSFONTM *gsFontM, float X, flo
 			numlines++;
 			linechars[numlines] = 0;
 		}
+		else if(cur == '\f')
+		{
+			linechars[numlines]++;
+			pos += 4;
+		}
 		else if(cur == '\t' && gsFontM->Align != GSKIT_FALIGN_LEFT)
 		{
 			printf("WARNING: Tabs not supported in GSKIT_FALIGN_CENTER/RIGHT\n");

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions