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

Cata ImGui can't get font size of zh_CN correctly #78837

Open
EliadOArias opened this issue Dec 29, 2024 · 17 comments
Open

Cata ImGui can't get font size of zh_CN correctly #78837

EliadOArias opened this issue Dec 29, 2024 · 17 comments
Labels
(S1 - Need confirmation) Report waiting on confirmation of reproducibility

Comments

@EliadOArias
Copy link

Describe the bug

image
Cata ImGui can't get font size of zh_CN correctly, which is one time wider then English font .

Attach save file

N/A

Steps to reproduce

  1. Select zh_CN.
  2. Open game and select any items and view item info.

Expected behavior

Works as normal fonts do.

Screenshots

image
So bad.

Versions and configuration

  • OS: Windows
    • OS Version: 10.0.22631.4460 (23H2)
  • Game Version: 25aabc1 [64-bit]
  • Graphics Version: Tiles
  • Game Language: zh_CN
  • Mods loaded: [
    [dda],
    [no_npc_food],
    [personal_portal_storms],
    [no_fungal_growth]
    ]

Additional context

No response

@EliadOArias EliadOArias added the (S1 - Need confirmation) Report waiting on confirmation of reproducibility label Dec 29, 2024
@NH4HCr2O7
Copy link

I got the same problem and I tried to change the font of the game, it turns out the format becomes better, but longer description text still goes out of the line.
image
and this seems also happening in Japanese and other double byte character sets, but much rarer when using unifont.
image

@db48x
Copy link
Contributor

db48x commented Dec 29, 2024

What fonts are configured in your fonts.json config file?

@db48x
Copy link
Contributor

db48x commented Dec 29, 2024

Also, if you could go the main menu → settings → ImGui Demo Screen, then select the from the Tools menu → the Style Editor. In the Style Editor there is a tab for Fonts. If you expand the first level of details for the two fonts, it will tell you exactly which font files it used for each of them. And if you show the font atlas, you’ll be able to see all of the characters that ImGui can draw without help. A screenshot of that information would be very helpful.

@EliadOArias
Copy link
Author

Totally vanilla and both 4 options in config/fonts.json are same(default) like:

"typeface": [
  "data/font/Terminus.ttf", 
  "data/font/unifont.ttf"
],

For the screenshot, I am sorry that I'm not at home now and for my mobile phone(Android) seems impossible to use Imgui Demo Screen. I'll send screenshot later when I got home.

@db48x
Copy link
Contributor

db48x commented Dec 30, 2024

Ok, so your gui_typeface is probably also set to Terminus followed by Unifont too. Since Terminus doesn’t have any Chinese or Japanese characters that’s probably the source of the problem. When it can’t find the characters the usual way it falls back to another way of drawing characters that is slower but can access all the fonts on your computer. It doesn’t necessarily pick the best font for the job, and apparently it can’t always measure the characters correctly.

Can you try editing the fonts.json file to add a Chinese or Japanese font of your choosing to the beginning of the list?

@EliadOArias
Copy link
Author

I try a lot of Chinese and Japanese support font and most of them not performance so well.
Some of them:
image
image
image

They mixed big and small character; I don't know why.
image
It seems difficult to find a correct font(I have not found one till now in fact), and, for most players they don't know what to do. If possible, we should provide a easy access to have a normal game experience.

@db48x
Copy link
Contributor

db48x commented Dec 30, 2024

Can you show me more detail? I need to see the font details, the font atlas, and the rendering problems all for the same font at the same time. Show them all in the same screenshot if you can, or just group the screenshots together in a logical way.

Try picking a single one of those fonts, then taking a screenshot with the font settings and glyph atlas visible, then another with the bug visible. It would be best if you could show the whole game window rather than cropping it down; I am having trouble reproducing the problem locally and it might just be because I am looking at a different thing than you are.

@NH4HCr2O7
Copy link

I had the font mixing problem as @EliadOArias too, and I think it's caused by configuration in both ./config/fonts.json and ./data/fontdata.json, it seems that if they are set to different font, or if one of them is missing the line "gui_typeface" in case the game is updated from an older version, the texts in imgui will be shown as mixing font characters.
It's quite strange to have two files configuring the font in game though, and pure English texts seem to be fine even when one of the configuration files is missing.

@EliadOArias
Copy link
Author

First example(Third Part):
image
image
image
Next one(Default):
image
image
Though this looks much more normal, it only handle half of the actually width, you can see this in follow picture:
image
image

@db48x
Copy link
Contributor

db48x commented Dec 30, 2024

Ok. You still didn’t show the font atlas, and you cropped everything when I asked you not to, but maybe I understand. I think the fonts you’re choosing still don’t have all of the necessary characters. For example, look at the item info in the second screenshot. The name on the first line ends with “(井)”, but that character is larger than most of the others. I think the font you chose doesn’t have that character, and it is falling back to a different font with different metrics. Go to the style editor and look for that character. It’s character number 0x4E95, so expand the font settings until you see the 4E00…4EFF block and see if 4E95 has a glyph there. If not, then we know it is a replacement character.

In your last few screenshots you’re using only fonts that have no Chinese characters, so every Chinese character is using the fallback path. So it miscounts the size of every single character.

@EliadOArias
Copy link
Author

I

Ok. You still didn’t show the font atlas, and you cropped everything when I asked you not to, but maybe I understand. I think the fonts you’re choosing still don’t have all of the necessary characters. For example, look at the item info in the second screenshot. The name on the first line ends with “(井)”, but that character is larger than most of the others. I think the font you chose doesn’t have that character, and it is falling back to a different font with different metrics. Go to the style editor and look for that character. It’s character number 0x4E95, so expand the font settings until you see the 4E00…4EFF block and see if 4E95 has a glyph there. If not, then we know it is a replacement character.

In your last few screenshots you’re using only fonts that have no Chinese characters, so every Chinese character is using the fallback path. So it miscounts the size of every single character.

Thank for your tolerance, and now I think I select a font have enough characters:
屏幕截图 2024-12-30 232250
image
It performs much better. But as most words are wrapped, some text still missing.
Here is all text:
image
Text, like "而设计的,在" is disappear. This seems because of another issue?

@NH4HCr2O7
Copy link

Well Chinese characters are way more than a screenshot can show, with over 20000 characters in unicode, there are also simplified and traditional, I don't think the atlas can show all of them, and I don't think any Chinese font will be missing characters like “这”“几”“腿”“盖”...... maybe you can try using the same font as I did in my screenshot which is Dengb.ttf (等线 粗体) so we could compare.

@EliadOArias
Copy link
Author

Screenshot_20241230_235705_com cleverraven cataclysmdda experimental
I find "dengb.otf" and it also has some missing character, though I set them in both fontdata.json and font.json
And I totally agree no Chinese font will miss "这", which is similar to "this" in English.

Well Chinese characters are way more than a screenshot can show, with over 20000 characters in unicode, there are also simplified and traditional, I don't think the atlas can show all of them, and I don't think any Chinese font will be missing characters like “这”“几”“腿”“盖”...... maybe you can try using the same font as I did in my screenshot which is Dengb.ttf (等线 粗体) so we could compare.

@NH4HCr2O7
Copy link

image
I don't have randomly placed characters here, so I guess the bug is not from the font, could you try to delete those two files and let the game generate a new one? I fixed this problem after that. My settings are
{ "typeface": [ "data/font/consola.ttf", "data/font/Dengb.ttf", "data/font/Terminus.ttf", "data/font/unifont.ttf" ], "gui_typeface": [ "data/font/consola.ttf", "data/font/Dengb.ttf", "data/font/Terminus.ttf", "data/font/unifont.ttf" ], "map_typeface": [ "data/font/consola.ttf", "data/font/Dengb.ttf", "data/font/Terminus.ttf", "data/font/unifont.ttf" ], "overmap_typeface": [ "data/font/consola.ttf", "data/font/Dengb.ttf", "data/font/Terminus.ttf", "data/font/unifont.ttf" ] }
And perhaps you should copy and paste the font file from windows font folder to ./data/font/.
We have one thing in common, the description text goes out of imgui border and a part of them can't be seen.

@db48x
Copy link
Contributor

db48x commented Dec 30, 2024

Well Chinese characters are way more than a screenshot can show, with over 20000 characters in unicode, there are also simplified and traditional, I don't think the atlas can show all of them

Yes, it is a lot but computers can count that high.

And I totally agree no Chinese font will miss "这", which is similar to "this" in English.

Can you double check? That is character 8FD9.

It’s missing from mine, as you can see:

Screenshot From 2024-12-30 08-36-43

I am hovering over 8FD4 which is the nearest glyph that I do have.

On the other hand, this font does have 4E95:

Screenshot From 2024-12-30 09-38-56

@EliadOArias
Copy link
Author

base typeface( Yell a sentence ):
image
imgui typeface( Item info ):
屏幕截图 2024-12-31 220713
image
@db48x Please have a look:
As I use same third-part font, they perform different.

  • Original have all characters( which convince there is no problems in the font ). All of them is big and not system font.
  • Imgui have big and small at same time, and all of them is not system font.

It seems imgui calculate gui_typeface font in a small way, and when something wrong happen, it use base typeface, which is calculated in a big way. Though they are same font "NotoSansSC-Regular.ttf", they were displayed differently, while base game have big only, imgui mix big and small.

To prove all of them is not system font, here is a comparision:
System:
image
Third-part:
屏幕截图 2024-12-31 222257

I had the font mixing problem as @EliadOArias too, and I think it's caused by configuration in both ./config/fonts.json and ./data/fontdata.json, it seems that if they are set to different font, or if one of them is missing the line "gui_typeface" in case the game is updated from an older version, the texts in imgui will be shown as mixing font characters. It's quite strange to have two files configuring the font in game though, and pure English texts seem to be fine even when one of the configuration files is missing.

Besides, I check font_loader.cpp and find fontdata.json is actually not working when we have font.json. Here is:
image

@EliadOArias
Copy link
Author

EliadOArias commented Dec 31, 2024

Can you double check? That is character 8FD9.

In the font file, here is:
image
And in imgui it missing, and as previous speaking, use a big style instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
(S1 - Need confirmation) Report waiting on confirmation of reproducibility
Projects
None yet
Development

No branches or pull requests

3 participants