[WIP] Replacing default font

The place to discuss scripting and game modifications for X4: Foundations.

Moderators: Scripting / Modding Moderators, Moderators for English X Forum

quarren
Posts: 128
Joined: Sat, 9. Nov 02, 12:40
x4

[WIP] Replacing default font

Post by quarren »

Hi guys,

has anyone figured out how to alter the default font for the game (the one used in basically all menus). While I like that it's clean-looking, it's a bit _too_ bland for me. I guess it's Arial? Reminds me of Excel. :D

Best regards,
quarren
Last edited by quarren on Wed, 5. Dec 18, 16:46, edited 1 time in total.
User avatar
alt3rn1ty
Posts: 3299
Joined: Thu, 26. Jan 06, 19:45
x4

Re: Replacing default font?

Post by alt3rn1ty »

Personally I am hoping Egosoft give us the option, the default small writing on a laptop 1360 x 768 screen gives me headaches. Way too small even with reading glasses on.
Spec's@2025-05-17 - Laptop - Acer Predator Helios Neo 16 AI - Win 11 x64
CPU - Intel Core Ultra 9 275HX 2.7-5.4ghz, RAM - 32gb DDR5 6400(OC),
Discrete GPU - NVidia Geforce RTX 5070 Ti, VRAM 12gb GDDR7,
SSD - M.2 PCIe NVME 1Tb
, OLED WQXGA 2560x1600.
:goner: Seeker of Sohnen. Long live Queen Polypheides. :boron:
quarren
Posts: 128
Joined: Sat, 9. Nov 02, 12:40
x4

Re: Replacing default font?

Post by quarren »

alt3rn1ty wrote: Sun, 2. Dec 18, 19:40 Personally I am hoping Egosoft give us the option, the default small writing on a laptop 1360 x 768 screen gives me headaches. Way too small even with reading glasses on.
Yeah, the default font size is a bit too small for me as well. At least you can increase "UI scale" in the game options to remedy that though.

--

I went ahead and looked around the game files a bit. There is a config file at /libraries/fonts.xml and there are some .abc and .dds files under /assets. Anyone got ideas on what to do with those? :D
hhr
Posts: 61
Joined: Fri, 6. Oct 06, 15:18
x4

Re: Replacing default font?

Post by hhr »

I once understood the font format in X Rebirth. One person with the help of these scripts remade localized fonts.

In X4, the format has slightly changed, and the most important difference is that instead of several dozen textures with fonts of different sizes, only one is used with the help of the Signed Distance Field technology. I figured out the format itself, it remains to learn how to generate textures in the required format.
quarren
Posts: 128
Joined: Sat, 9. Nov 02, 12:40
x4

Re: Replacing default font?

Post by quarren »

hhr wrote: Mon, 3. Dec 18, 16:07 I once understood the font format in X Rebirth. One person with the help of these scripts remade localized fonts.

In X4, the format has slightly changed, and the most important difference is that instead of several dozen textures with fonts of different sizes, only one is used with the help of the Signed Distance Field technology. I figured out the format itself, it remains to learn how to generate textures in the required format.
Interesting! So your LUA script for X-Rebirth takes .fnt files as input and outputs them in the .abc format - and what's left to do is figure out how to generate the .dds? Looking forward to see what comes of this. :-)

Is font usage for certain menus referenced anywhere in the UI code (the lua part of it that is moddable, I mean) or does X4 only have one "global" font that is used everywhere?
hhr
Posts: 61
Joined: Fri, 6. Oct 06, 15:18
x4

Re: Replacing default font?

Post by hhr »

example.

\ui\addons\ego_gameoptions\gameoptions.lua:
local config = {
--
fontBold = "Zekton bold outlined",
--


\libraries\fonts.xml:
<font name="Zekton Bold">
<fontsize size="32" yoffset="0" />
</font>
<alias name="Zekton Bold Outlined" ref="Zekton Bold" material="zekton Bold outlined" />


\libraries\material_library.xml:
<material name="zekton bold outlined_32" shader="XU_ui_unlit_sdf_outline.fx" blendmode="ALPHA8_ANARK" preview="none" priority="1">
<properties>
<property type="BitMap" preload="1" name="diffuse_map" value="assets\fx\gui\fonts\textures\Zekton Bold_32" />
</properties>
</material>


so, Zekton bold outlined in Lua-scripts is assets\fx\gui\fonts\textures\Zekton Bold_32.dds.
quarren
Posts: 128
Joined: Sat, 9. Nov 02, 12:40
x4

Re: Replacing default font?

Post by quarren »

Okay, so it seems in most places Helper.standardFont (which is "Zekton" per default)is used in the lua scripts. The thing is... X4 doesn't seem to use Zekton at all? Zekton has a pretty distinct look to it and is used in X Rebirth... so where does X4 get its font from? :D
User avatar
nonnex
Posts: 366
Joined: Wed, 28. Aug 13, 12:42
x4

Re: Replacing default font?

Post by nonnex »

Hm, X4 is using a tiled based image (the oldschool way of making fancy text fonts ;)) for his fonts and not supporting TTF I guess. Not sure about it, but I saw such a file yesterday somewere in the container stucture that lead me to that guess.

Search for a single image with a set of characters.
quarren
Posts: 128
Joined: Sat, 9. Nov 02, 12:40
x4

Re: Replacing default font?

Post by quarren »

nonnex wrote: Tue, 4. Dec 18, 10:48 Hm, X4 is using a tiled based image (the oldschool way of making fancy text fonts ;)) for his fonts and not supporting TTF I guess. Not sure about it, but I saw such a file yesterday somewere in the container stucture that lead me to that guess.

Search for a single image with a set of characters.
Yeah, that would be the .dds under "assets/fx/gui/fonts/textures/". I took a quick look at that in gimp as well.

I'm still unsure if X4 even cares about all the definitions in fonts.xml etc. though. Because as far as I can see Zekton isn't even used anywhere? Could that be a relic from X Rebirth?
User avatar
nonnex
Posts: 366
Joined: Wed, 28. Aug 13, 12:42
x4

Re: Replacing default font?

Post by nonnex »

Could very well be a relic, yes.

Maybe the engine is capable of using TTF fonts too. But i would guess it's not possible to change that now easily throu scripting.
quarren
Posts: 128
Joined: Sat, 9. Nov 02, 12:40
x4

Re: Replacing default font?

Post by quarren »

So, looking at the texture "Zekton Bold_32.dds" at least explains why it looks the way it does (as in: nothing like Zekton at all):

https://i.imgur.com/oQoZZvN.png

Pretty much looks like your default sans serif font.

@hhr: Have you figured out how to generate fonts in the new format yet? :-)
User avatar
nonnex
Posts: 366
Joined: Wed, 28. Aug 13, 12:42
x4

Re: Replacing default font?

Post by nonnex »

Any "Bitmap Font" creation tool would make it.

For example http://www.codehead.co.uk/cbfg/
Or whatever You prefer.

Just keep the x y coordinates for each char where X4 expects em to be.
Ah good old times... 8)

Wonder how non smothed (aliased) fonts would look like. Maybe not good when doing UI scaling.
hhr
Posts: 61
Joined: Fri, 6. Oct 06, 15:18
x4

Re: Replacing default font?

Post by hhr »

quarren wrote: Tue, 4. Dec 18, 15:49@hhr: Have you figured out how to generate fonts in the new format yet? :-)
I wrote instructions for generating new fonts, but it is in Russian ;) I am not ready to translate it entirely, therefore I will give the main steps.

header logo ;)
Image

ready result (animated WebP):
original
Show
modified
Show
another font
Show
Image

1) Source for most files and scripts - https://github.com/hhrhhr/Lua-utils-for-X-Rebirth

2) The game uses SDF technology, so first we need to get a texture with all the characters and enough space between them (to generate the distance field). The larger the texture, the better the result. So, all values in BMFont must be

3) some variables
SCALE = 4 (can be 8 or 16, if you have enough RAM ;)
FONT = rufont (for bold - "rufont Bold", for English/German/ other latin use "Zekton" and "Zekton Bold")

4) Start BMFont, load config file FONT_32.bmfc, select additional chars (or unselect unneeded). The font should not be much elongated in height. Font size must be 50-55 * SCALE px, padding - 5-6 * SCALE px, spacing - 5-6 px.
Start preview and change texture size if not all characters fit on one page. Save result with name FONT_32.fnt

Important note: do not remove the "¤" character from the character set (code 164, Unicode U+00A4). It is used as a fallback character for missing glyphs.

5) Convert the .fnt file to the game format (.abc):

Code: Select all

lua x4_fnt2abc.lua "FONT_32" SCALE
6) Using Imagemagick, it generates a signed distance field from our texture and scale it to the working size (for Windows, remove all slashes from this command.):

Code: Select all

magick convert "FONT_32_0.png" \
\( +clone -negate -morphology Distance Euclidean:4 -level 50%,-50% \) \
-morphology Distance Euclidean:4 -compose Plus -composite \
-level 47%,53% -negate -filter Jinc -resize 25% "FONT_32.png"
Here the most important parameter is -level 47%,53%. If you reduce the first digit and similarly increase the second, then the font will turn out with soft, blurred edges. otherwise, the edges will be very contrasting, which is bad for displaying small sizes.

7) Now it remains to convert png to dds.

Code: Select all

nvdxt.exe -file rufont_32.png -a8 -nomipmap
8) Repeat the process for bold (in the BMFont set the appropriate option).

9) Copy files "FONT_32.dds" and "FONT_32.abc" to game folder (..\assets\fx\gui\fonts\textures\) or pack it to extension.

p.s.
If the instruction is useful, then I ask for help with the "correct" translation into English.
quarren
Posts: 128
Joined: Sat, 9. Nov 02, 12:40
x4

Re: Replacing default font?

Post by quarren »

I wrote instructions for generating new fonts, but it is in Russian ;) I am not ready to translate it entirely, therefore I will give the main steps.
Wooooooow. Thanks a lot hhr! The instructions seem concise enough to me - I'm gonna try my hand at converting a font in the next few days (probably the "proper" Zekton font used in X:R). :-)

Edit: Oh, one question... it seems nvdxt.exe is available from your github repo. Imagemagick I will have to download seperately for the 'magick' command to work, right?
hhr
Posts: 61
Joined: Fri, 6. Oct 06, 15:18
x4

Re: Replacing default font?

Post by hhr »

quarren wrote: Wed, 5. Dec 18, 08:56it seems nvdxt.exe is available from your github repo. Imagemagick I will have to download seperately for the 'magick' command to work, right?
All utilities can be downloaded from their "home" sites.

BMFont — http://www.angelcode.com/products/bmfont/ (64bit executable for v1.14 beta)
nvdxt — https://developer.nvidia.com/gameworksd ... ities-8-31 (DDS Utilities 8.31)
Lua — https://sourceforge.net/projects/luabin ... ecutables/ (lua-5.3.4_Win64_bin)
Imagemagick — https://www.imagemagick.org/script/download.php#windows (ImageMagick-7.0.8-15-Q16-x64-dll)
quarren
Posts: 128
Joined: Sat, 9. Nov 02, 12:40
x4

Re: Replacing default font?

Post by quarren »

hhr wrote: Wed, 5. Dec 18, 15:34
quarren wrote: Wed, 5. Dec 18, 08:56it seems nvdxt.exe is available from your github repo. Imagemagick I will have to download seperately for the 'magick' command to work, right?
All utilities can be downloaded from their "home" sites.

[...]
Hi hhr,

thank you for your excellent guide! I managed to replace the default font, it looks a bit less bland and a bit more sci-fi now (not as readable, but I might be able to fix that somehow):

https://imgur.com/a/L9GYHEw

A weird artifact can be seen in the second screenshot - seems like the letters have some kind of weird black border around them. It's only visible above NPC heads. Do you have an idea what could be causing this?

Another issue I have is that it works like I've shown above when I just drop the files into "X4 Foundations\assets\fx\gui\fonts\textures" and load the game with "-prefersinglefiles". When I try to make an extension out of it with the following entry to material_library.xml however, I only get a weird-looking jumbled mess (see below):

Code: Select all

<diff>
  <!-- Replace Default Font -->
  <replace sel="/materiallibrary/collection[@name='anark']/material[@name='zekton_32']/properties/property[@name='diffuse_map']">
    <property type="BitMap" name="diffuse_map" value="extensions\fontreplacer\assets\fx\gui\fonts\textures\Zekton_32"></property>
  </replace>
  <replace sel="/materiallibrary/collection[@name='anark']/material[@name='zekton bold_32']/properties/property[@name='diffuse_map']">
    <property type="BitMap" name="diffuse_map" value="extensions\fontreplacer\assets\fx\gui\fonts\textures\Zekton Bold_32"></property>
  </replace>
  <replace sel="/materiallibrary/collection[@name='anark']/material[@name='zekton outlined_32']/properties/property[@name='diffuse_map']">
    <property type="BitMap" name="diffuse_map" value="extensions\fontreplacer\assets\fx\gui\fonts\textures\Zekton_32"></property>
  </replace>
  <replace sel="/materiallibrary/collection[@name='anark']/material[@name='zekton bold outlined_32']/properties/property[@name='diffuse_map']">
    <property type="BitMap" name="diffuse_map" value="extensions\fontreplacer\assets\fx\gui\fonts\textures\Zekton Bold_32"></property>
  </replace>
</diff>
Screenshot of jumbled mess
Show
Image

Thanks a lot,
quarren
quarren
Posts: 128
Joined: Sat, 9. Nov 02, 12:40
x4

Re: [WIP] Replacing default font

Post by quarren »

The debug log shows the following errors, is that why it's not working?

Code: Select all

[=ERROR=] 0.00 File I/O: Could not find file '.\extensions\fontreplacer\libraries\material_library.xml.sig'
[General] 0.00 ======================================
[General] 0.00 File I/O: Failed to verify the file signature for file '.\extensions\fontreplacer\libraries\material_library.xml' (error: 14)
[=ERROR=] 12.99 File I/O: Could not find file '.\extensions\fontreplacer\assets\fx\gui\fonts\textures\zekton_32.dds.sig'
[General] 12.99 ======================================
[General] 13.00 File I/O: Failed to verify the file signature for file '.\extensions\fontreplacer\assets\fx\gui\fonts\textures\zekton_32.dds' (error: 14)
[General] 13.02 ======================================
[=ERROR=] 13.02 File I/O: Could not find file '.\extensions\fontreplacer\assets\fx\gui\fonts\textures\zekton bold_32.dds.sig'
[General] 13.02 ======================================
[General] 13.03 File I/O: Failed to verify the file signature for file '.\extensions\fontreplacer\assets\fx\gui\fonts\textures\zekton bold_32.dds' (error: 14)
hhr
Posts: 61
Joined: Fri, 6. Oct 06, 15:18
x4

Re: [WIP] Replacing default font

Post by hhr »

I only get a weird-looking jumbled mess
I think you extension named ext_##. In this case, many files are not replaced by modified ones. In your case, a new texture has been applied, but the font descriptor (.abc) uses the original one.
You probably need to rename the extension to subst_## and not use any xml files. only 2 .abc and 2 .dds.
seems like the letters have some kind of weird black border around them
Maybe editing the texture will help (before converting to dds), slightly change the gamma or contrast. By trial and error, something happens.
Font characters are drawn by shadergl\shaders\ui.v and shadergl\shaders\ui_unlit_sdf.f shaders. You can try to apply it in some shader editor to get the result without waiting for the game to load. I, unfortunately, do not know how.
quarren
Posts: 128
Joined: Sat, 9. Nov 02, 12:40
x4

Re: [WIP] Replacing default font

Post by quarren »

hhr wrote: Wed, 5. Dec 18, 23:35 I think you extension named ext_##. In this case, many files are not replaced by modified ones. In your case, a new texture has been applied, but the font descriptor (.abc) uses the original one.
You probably need to rename the extension to subst_## and not use any xml files. only 2 .abc and 2 .dds.
Thanks a lot, packaging the files into a subst_01.cat/dat worked! :-)

Now I only have to figure out how to get rid of the artifacts.

Best regards,
quarren
Misunderstood Wookie
Posts: 377
Joined: Mon, 15. Mar 04, 08:07
x4

Re: [WIP] Replacing default font

Post by Misunderstood Wookie »

Excuse me...
Image
*modified*
*X3 LiteCube User*
MOD GemFX Real Space Shaders
MOD Variety and Rebalance Overhaul Icon Pack
I lost my Hans and should not be flying Solo.
Image

Return to “X4: Foundations - Scripts and Modding”