Modding Civ5 bitmapped fonts

Pazyryk

Deity
Joined
Jun 13, 2008
Messages
3,584
This is about the 5th thread on this topic (including 3 others by me), but I thought I'd describe what can and can't be done and the key blocking step, in case someone can solve that. This will become a tutorial if anyone can solve the dds problem.

The blocking step is simply that no one, as far as I know, has been able to open the bitmap dds files. You have 10 per font size:

twcenmt18.dds
twcenmt18-index.dds
twcenmt18base.dds
twcenmt18base-index.dds
twcenmt18shadow.dds
twcenmt18shadow-index.dds
twcenmt18stroke.dds
twcenmt18stroke-index.dds
twcenmt18 soft.dds
twcenmt18 soft-index.dds

The "-index 2 file" format appears for many art resources. For all others (I think) the CivDdsUnpacker.exe works to convert to a png file, allowing you to edit and make your own dss files from it. But the unpacker throws a "fail!" message and skips the font files. I've messed around with header info in a hex editor, but no success. Presumably the maker of CivDdsUnpacker.exe understood the file format to some extent. But this is not something I know enough about to make any headway.

You can learn something about these font dds files from the ggxml files. They are all 512 x 512 images, although the mapping (u, v) of individual fonts is slightly different for the different font sizes. There are several rows at the bottom open to potentially add fonts. Or, presumably, you could make the 512 x 512 bigger to add as many as you want. For font icons, the "ch=" tag links to a value you supply in the IconFontMapping table. For fonts, they correspond to Unicode character decimal representation (e.g., see "& #32" in this table). According to the ggxml file we have Unicode 32-126, 160-255, 338, 339, 344 & 335. Sort of a random expansion on the basic Latin set: we have Řř for some reason (the last 2) but not Čč. You can prove this in game by adding "ŘřČčŘřČčŘřČčŘřČč" to some TXT_KEY. The file itself "understands" these because they are all UTF-8. But you will see "Řř Řř Řř Řř " in the game because there is no representation of Č or č in the bitmap. The images for those letters were never made (there is no gap in spacing from 255 to 338). But there is no reason a modder couldn't add them. Except that we can't open and edit font dds files.


On the DB side, you can add your own fonts and use them from a UI XML file, although (annoyingly) you can't replace the core game fonts with your own that have names TwCenMT14, TwCenMT16, etc.

So, you can do this:
  1. Add the 10 files above plus TwCenMT18.ggxml to your mod with VFS=true.
  2. Open TwCenMT18.ggxml and change "TwCenMT" to "EaFont" everywhere it occurs (capitalization does matter here, I think).
  3. Change "TwCenMT" to "EaFont" in the name of all 9 files (capitals don't seem to matter in the dds file names).
  4. Now, add GameSetupScreen.xml to your mod with VFS=true to replace the core UI file.
  5. Edit GameSetupScreen.xml to replace TwCenMT22 in all occurrences to EaFont18.
  6. Run mod and look at setup screen. You have successfully replaced TwCenMT22 fonts with the smaller EaFont18 fonts.

To do that I had to change the name of the font in the UI XML file. That's doable for me (my total conversion mod has edited most of the UI files anyway) but not modular at all. Can you replace the core font dds and ggxml files with VFS=true. Sadly, no. I've tried this extensively, but TwCenMT22 in an XML UI file will always reference the core installed ggxml and dds files rather than "same-named" files you have added to your mod. One or both of these files are not replaced (you would need both to be replaced since they have to have the same name). Perhaps BNW will change this: there appears to be flexibility now in the UI styles, but I don't know if that will affect fonts at all. In any case, this is not a stopper (for me). It's the dds problem that is stopping me from adding any new letters.
 
Top Bottom