字体修改

本页面所适用的版本可能已经过时,最后更新于1.25

Fonts are applied to textual elements in the interface. All fonts are found and should be placed in the /Europa Universalis IV/gfx/fonts/ folder.

Creating a New Font


754/5000 要创建新字体,您需要下载一个名为BMFont的程序,该程序用于从字体生成字体页和描述符文件。

安装BMFont之后,将其打开并导入字体。 为此,请单击选项菜单按钮,然后单击字体设置按钮。 在“字体设置”菜单中,添加您的字体文件。

这将使用所选字体支持的所有符号填充字体画布。 您的所有符号都应突出显示,以使其包含在字体文件中,因此,您可以通过不突出显示它们来选择不包括某些符号,无论是通过侧边栏还是手动选择它们。 除非您需要将字体设置为特定大小,否则这不是必需的。

Font Settings 字体设置

导入字体之后,就可以设置字体的外观了。为此,再次打开字体设置菜单。下面是你需要更改的字段:

  • Charset:设置为OEM-ANSI。
  • Size:这是您的字体的字体大小,将其设置为所需的大小。
  • Match char height:勾选此项,以便每个字符都具有相同的高度。
  • Font smoothing:如果您的字体在游戏中看起来过于清晰,请勾选此项。
  • Outline thickness:如果您希望字体具有轮廓,请在此处设置所需的粗细。

Export Options 导出选项

设置字体后,现在该设置如何导出字体了。 为此,请打开“导出选项”菜单。 以下是您可能想要更改的字段:

Padding:控制字体图像中每个字符之间的填充。 仅当您打算手动编辑字体文件并且不希望字符靠得太近时才需要。

Spacing:控制字体图像中字符之间的最小间距。 将此设置为1-1或更高(如果您遇到字符间出血)。

Width:控制字体图像的宽度。 如果所有字符都不适合一张图像,请提高此值。

Height:控制字体图像的高度。 如果所有字符都不适合一张图像,请提高此值。

Channels:控制字符的合成方式。 除非已指定轮廓,否则将它们全部设置为glyph,然后将Alpha通道设置为outline,其余部分设置为glyph。

Font descriptor:需要设置为text。

Textures:应设置为.tga或.dds

Saving the Font 保存字体

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.

Using a New Font 使用新字体

保存新字体后,您现在应该拥有两个文件,一个字体图像文件(即my_font.tga)和一个字体描述符(即my_font.fnt)。 打开字体描述符文件,因为需要进行编辑以与Hearts of Iron IV兼容。

打开后,您需要更改以下几行:

  • size:将值设为正数。
  • unicode:删除键和值。
  • outline:如果您的字体不使用轮廓,则删除键和值。
  • pages = 1:删除键和值。
  • packed = 0:删除键和值。
  • alphaChnl = 0:删除键和值。
  • redChnl = 0:删除键和值。
  • greenChnl = 0:删除键和值。
  • blueChnl = 0:删除键和值。
  • page id = 0:删除键和值。
  • file =“ x.tga”:删除键和值。
  • 字符数= 216:删除键和值。
  • chnl = 15:删除每个字符的键和值。

完成此操作后,保存字体描述符文件。 现在可以在《钢铁雄心IV》中使用它了。

To make your new font available you need to add a .gfx definition for it in your mod files. Here is an example:

bitmapfonts = { 
    bitmapfont = {
        name = "monofonto_tooltip"
        path = "gfx/fonts/monofonto_tooltip"   
        color = 0xffffffff
    }
}

Note you can change the localization color symbols effects by including the textcolors scope within your font:

bitmapfonts = { 
    bitmapfont = {
        name = "monofonto_tooltip"
        path = "gfx/fonts/monofonto_tooltip"   
        color = 0xffffffff
        textcolors = {
           G = { 86 172 91 }
           R = { 222 86 70 }
           Y = { 238 201 35 }
           H = { 238 203 35 }
           T = { 255 255 255 }
       }
    }
}

If you want to change the map font, you need to override the tahoma_60 font definition with your own font.

Kerning

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 ) )

    file.close()