Font modding

From Hearts of Iron 4 Wiki
Jump to navigation Jump to search

Creating a New Font[edit]

Making a new font requires the program BMFont, which is used to generate the font page and descriptor file from a font.

Once BMFont is installed, open it up and open the options menu then font settings, import your font file then select the font from the dropdown menu (font files can be found and downloaded at google fonts) After that is done, you can begin to configure the font settings

Font Settings[edit]

Having imported your font, it is time to setup how you want the font to look. To do this, open the Font Settings menu again. Below are the fields you need to change:

  • Charset: set this to Unicode.
  • Size: this is the font size for your font, set this to your desired size. (Note that higher values might make your file too large to be read by the game)
  • Match char height: tick this so each character has the same height.
  • Font smoothing: tick this if your font may look overly sharp in game.
  • Outline thickness: if you want your font to have an outline, set the desired thickness here.

After this is complete press "OK" to save your changes

Export Options[edit]

Having setup your font, it is now time to setup how you want the font exported. To do this, open the Export Options menu. Below are the fields you may want to change:

  • Padding: controls the padding between each character in the font image. Only needed if you intend to manually edit the font file and don't want the characters too close together.
  • Bit depth: Set this to 32
  • Spacing: controls the minimum space between character in the the font image. Set this to 1-1, or higher if you experience bleeding between characters.
  • Width: controls the width of the font image. Adjust this so that all the characters don't fit on one image. (Note that higher values might make your file too large to be read by the game)
  • Height: controls the height of the font image. Adjust this so that if all the characters don't fit on one image. (Note that higher values might make your file too large to be read by the game)
  • Channels: controls how the characters are composited. Set them all to glyph unless you have specified an outline, in which case set the alpha channel (A) to outline, with the rest as glyph.
  • Presets: Pick any one that fits your text, but only pick ones with alpha
  • Font descriptor: needs to be set to text.
  • Textures: should be set to .dds

After this is complete press "OK" to save your changes

Selecting Font Characters[edit]

To the right are checkboxes for different types of characters, if a character is used which is not in the font it will show as a question mark of a box, choose whichever ones fit what you're using the font for remembering that the font files can be too large to be read by the game

Recommended characters are:

* Latin + Latin Supplement
* Latin Extended A
* Latin Extended B
* Latin Extended Additional
* General Punctuation

Saving the Font[edit]

Having setup the font as you would like it, check that the characters all fit on one page by clicking on the Visualize button in the Options menu. If they don't you need to increase the size of the font image width and height.

Save the font by clicking "Save bitmap font as..." in the options menu.

Both the image and text file should be named the exact same

Fonts are stored in the gfx\fonts folder (hoi_mapfont4 is the map font)


Many fonts will not be exported with kerning information included in the font descriptor file. This can lead to character overlaps ingame which can be unsightly. To fix this, you need to add kerning information to your font descriptor file.

To do this, open your font descriptor file and add a new line following this format for each kerning pair:

kerning first=<symbol position> second=<symbol position> amount=<pixel width>

A symbol's position within a font can be seen in BMFont by looking in the lower right at the status bar when hovering over a symbol in the font canvas.

The pixel amount is the space between the first and second symbol.

You may have realized that manually creating each kerning pair is not very feasible. It is best to use a programming language (such as Python) to generate the kerning lines for you. Below is an example script you can use in Python 3.x or above:

    file = open( "kerning.txt", "wt" )

    # Add the symbol positions of the blank symbol slots here.
    exclude = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 , 15, 16, 17, 18, 19, 20, 21, 22, 23, 25, 26,
                27, 28, 29, 30, 31, 127, 129, 141, 143, 144, 156, 173, 181]

    for x in range( 1, 255 ):
        for y in range(1, 255):
            if x not in exclude:
                if y not in exclude:
                    file.write( "kerning first={0}  second={1}  amount=1\n".format( x, y ) )