Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multilingual font rendering #1991

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Multilingual font rendering #1991

wants to merge 3 commits into from

Conversation

YuanBaian
Copy link

put your ttf file into "3rdparty\extras\xash-extras\gfx\fonts"

change cl_font.c
FONT_COUNT
g_FontsPath
g_FontsSize


put your ttf file into "3rdparty\extras\xash-extras\gfx\fonts\"

change cl_font.c
FONT_COUNT
g_FontsPath
g_FontsSize
@@ -619,17 +619,71 @@ Convert utf char to current font's single-byte encoding
*/
int Con_UtfProcessCharForce( int in )
{
// TODO: get rid of global state where possible
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you did that?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can accurately process characters, as previous functions were unable to handle them correctly

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I haven't read Q-DecodeUTF8 function. If Con-UtfProcessCharForce is not modified, the Chinese will become "?"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q_DecodeUTF8 must be able to decode Chinese symbols (as long as they're encoded in UTF-8). If it doesn't, it's a bug in Q_DecodeUTF8, and not in this function.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
image
After this setting, Chinese can be displayed normally

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I have a better solution for this problem.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, setting it up to zero is absolutely fine for what we're trying to achieve here.

This code will be removed once engine will completely draw text on it's own, without relying on provided bitmap fonts (which are often in CP1251 or CP1252, thus the logic)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the core issue now is whether the implementation of my code is correct. Currently, multilingual rendering in the engine does not appear to be inherently difficult. Let’s prioritize finalizing this feature as soon as possible XD

Copy link
Member

@a1batross a1batross Feb 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is absolutely no need to hurry. I didn't even start on the thing that your code doesn't even compile.

// skip setting rendermode, it was changed for this string already
draw_len += CL_DrawCharacter( x + draw_len, y, (byte)*s, current_color, font, flags | FONT_DRAW_NORENDERMODE );
if( ch )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also absolutely don't have to do this.

If you don't try to override CL_DrawCharacter with your own function (i.e. Font_DrawChar) it will actually decode UTF-8 for you.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a good approach. When I ported this part of the code to Font_DrawChar, it didn't produce the correct results. Additionally, CL_DrawCharacter is often called independently, and performing Con_UtfProcessChar operations within it would likely introduce performance overhead
image

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
The number parameter in CL_DrawCharacter may receive a Chinese character. If CL_DrawCharacter is not called from CL_DrawString, it may fail to display Chinese characters

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
cs16-client called CL_DrawCharacter

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a valid concern actually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants