Chinese display issue

Add the corresponding Chinese font library file according to the document CastleSettings.ml, and after testing, all Chinese characters will be displayed?? This symbol


Forum posts cannot upload font files

  • Make sure freetype.dll is in the same directory with castle-editor.exe.
  • You should use “CustomFont” instead, by adding a new TCastleFont instance to “Non-Visual Components”.
  • Set “Url” property to point to your font.
  • Adds the Chinese characters you want to display to your CustomFont’s “LoadCharacters” property. This is important!
  • Assign your custom font to button’s “CustonFont” property.

image

Edit: If you still want to set the font in CastleSettings.xml, then make sure “sample_text” contains the Chinese characters you want to display.

This method has been tested, and my game is customizable by players. Many Chinese characters cannot be predicted, and the method of “Custom Font’s” LoadCharacters "does not meet my requirements

I am preparing TViewMain Update real-time loading of different Chinese characters FontC LoadCharacters to modify, I’m not sure if there are any performance issues

What you are looking for is adding all characters available in the font to the font. However, the approach I’m using myself is first code-only, and second much worse: deprecated. But let’s start here:

  CharList := TUnicodeCharList.Create;
  CharList.Add(AllChars);  
  FontSoniano90 := TCastleFont.Create('castle-data:/ui/fonts/soniano/soniano-sans-unicode.regular_fixed.ttf', 90, true, CharList);
  FreeAndNil(CharList); 

The above will load all the characters available in the font. This is not optimal, but in some edge-cases may be the only option you have.

Now looking for how to do that through CastleSettings.xml…

EDIT: Ok, unfortunately I can’t find this option neither from CastleSettings nor from the Editor, except providing all 149878 unicode characters as a string, which is not a good idea.

You can add all characters at once, either in code or via the editor, just like eugeneloza said.

I personally suggest you to make a custom component for the editor, which inherited TCastleFont and automatically load all Chinese characters when added.

I attached project file which demonstrate the idea. See “code/gamemycustomfont.pas”, which create a new custom component named “My Custom Font”, and preload all Japanese characters. When open the project via castle editor, make sure to choose “Yes” when the editor notify you about Rebuild and Restart Custom Editor.

Relevant link about custom component: Custom Components | Manual | Castle Game Engine

my-new-project.zip (3.7 MB)

Edit: I forgot to add gamemycustomfont to gameinitialize. Make sure to add it if you want to see the result when running the project.

Edit2: I forgot to press Save, so I reupload the project file.

2 Likes

Thank you very much for meeting my needs

Indeed, loading fixed characters is bad for game features that can accept user input. I tried adding 3,000 commonly used Chinese characters and that worked, but I’m thinking of that there may be an efficiency issue with this?however,i have no another idea but to do so. :sweat_smile:

It is practically OK to load a font with lots of glyphs, even 3000.

Our default FallbackFont used in UI (if you don’t specify any custom font) features now ~2000 Unicode characters ( Font improvements: default font includes international characters, less embedded font data by default, fixes for font rendering on ancient machines – Castle Game Engine ). And it is OK – though it is not with zero effect (font loading is slightly longer, and it would be important if we e.g. had 10 such fonts).

So, practically: new fonts (that you setup using TCastleFont) have by default just basic ASCII set because “usually” it is good enough. But if your game needs it, don’t be afraid to load thousands of glyphs from your font – it in practice works OK.

We have a TODO to do this in more automated way (to load on-demand groups of glyphs, e.g. load from font, on-demand, e.g. “all Chinese glyphs” if one uses a Chinese character). I think Unity is doing this, as an option (it has some font loading strategies).

1 Like

I added tens of thousands of Chinese characters, and when I enter the interface, it will lag for 2 seconds. However, it does not affect my use. I will create a game loading interface to load resources