Font modding: Difference between revisions

本页面所适用的版本可能已经过时,最后更新于1.12
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 2: Line 2:
{{需要翻译|译者=霜泽图书馆}}
{{需要翻译|译者=霜泽图书馆}}


== Creating a new font ==
== 创建新字体 ==
{{SVersion|1.12}}
{{SVersion|1.12}}


Making a new font requires the program [http://www.angelcode.com/products/bmfont/ BMFont], which is used to generate the font page and descriptor file from a font.
制作新字体需要用到 [http://www.angelcode.com/products/bmfont/ BMFont] 程序,该程序可用于从字体生成字体页面和描述文件。


Once BMFont is installed, open it up and open the options menu then font settings, import your font file, and 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.
在BMFont 安装完毕后,启动程序,进入选项菜单并选择字体设置。导入你的字体文件后,从下拉菜单中选择字体(字体可以在Google Fonts-谷歌字体进行下载) 。在完成这些步骤后,即可开始配置字体设置。


=== Font settings ===
=== 字体设置 ===
{{SVersion|1.12}}
{{SVersion|1.12}}
Having imported your font, it is time to set up 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.
* 字符集 (Charset): 将其设定为统一码(Unicode)
* '''Size''': this is the size of each character in the outputted bitmap, set this to your desired size.
* 大小(Size): 这是输出页面的每个字体的大小,将其设定为你想要的尺寸。
** Note larger sizes will increase the final output's used space and may split your result between multiple bitmaps. The only way to use multiple bitmaps is through separately defined outputted font files, so keep as much as you can on one bitmap.
** 请注意,较大的字符尺寸会增加对于最终输出的空间占用,并可能将你的结果分散在多个位图中。如需使用多个位图,必须生成单独定义的字体文件,因此建议尽量将所有字体保留在一个位图中。(译者注:由于中文的表意方式与英语不同,将中文字符保留在一张位图里几乎不可能,如果你这么做,可能会导致严重的字符缺失等,建议参考https://www.bilibili.com/opus/710497357426327574)
* '''Match char height''': tick this so each character has the same height.
* 匹配字符高度(Match char height ):勾选此项以确保所有字符的高度一致。
* '''Font smoothing''': tick this if your font's edges look overly sharp in-game.
* 字体平滑(Font smoothing ):如果字体边缘在游戏中看起来过于锐利,请勾选此项。
* '''Outline thickness''': if you want your font to have an outline, set the desired thickness here.
* 轮廓厚度(Outline thickness ):如果希望字体带有轮廓,可在此设置所需的轮廓厚度。
** Note, this will increase the character size in the font's bitmap, thus taking more space.
** 请注意,这会导致字符在字体位图中的尺寸增加,因此会占据更多的空间。


After this is complete press "OK" to save your changes
完成设置后,点击" 确定" (OK)以保存更改。


=== Export options ===
=== 导出选项 ===
Having set up your font, it is time to set up how you want to export a font bitmap the game can read. To do this, open the Export Options menu. Below are the fields you may want to change:
设置完字体后,就可以配置导出游戏可识别的字体位图格式了。为此,打开导出选项菜单(Export Options)。以下是你可能需要调整的:


* '''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.
* 填充(Padding): 调整字体图像中每个字符边缘的内边距。仅在需要手动编制字体文件且希望字符之间保持一定距离时才需设置此项。
* '''Bit depth''': Set this to 32
* 色彩深度(Bit depth): 将其设置为32。
* '''Spacing''': controls the minimum space between characters in the font image. Set this to 1-1; set it higher if you experience characters bleeding into each other.
* 间距(Spacing): 控制字体图像中字符之间的最小间距。将此项设置为1-1 ;如果字符出现相互重叠的问题,请将其设置为更高的值。
* '''Width''' & '''Height''': the size of the exported font bitmap. Adjust this so that all the characters fit on one image.
* 宽高(Width & Height): 导出的字体位图的尺寸。调整此项以确保所有字符都能容纳在一张图上。(见上译者注)
** Note, increasing WxH drastically increases the file size. The game cannot process a single font graphic above 16 MB, with Paradox using 16,001KB at max for Chinese fonts. This limit is quickly reached without the heavier compression modes; you can work around this by [[Font modding#Defining bitmaps|defining multiple linked font bitmaps to one font]], as Paradox does with the 11 linked 14-16MB Chinese font bitmaps.
** 请注意,宽度与高度的增加会显著增加文件的大小。游戏无法处理超过16MB的单个字体图像文件,其中Paradox的中文字体最大文件大小为16,001KB 。在不使用较高强度的压缩的情况下,此限制很容易达到。您可以通过为[[Font modding#Defining bitmaps| 同一字体定义多个链接的位图]] 来规避这一限制,就像Paradox 使用的11个  14-16MB 中文字体位图链接一样。
* '''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'''.
* 通道(Channels): 控制字符的合成方式。若未设置轮廓,请将所有通道设为'''glyph''' ;若已设置轮廓,则将Alpha通道(A) 设为'''outline''' ,其余通道均设为'''glyph'''
* '''Presets''': Unnecessary if manually choosing channels above. Pick any that fits your text, but only pick ones with alpha.
* 预设(Presets): 若已手动选择上述通道,则此项可忽略。选择任何适合文本的预设即可,但需确保包含 Alpha 通道。
* '''Font descriptor''': needs to be set to text.
* 字体描述符(Font descriptor): 需设置为文本格式(text)。
* '''Textures''': needs to be set to .dds
* 材质(Textures): 应设置为.dds
* '''Compression''': select the form of compression the file uses. For DDS:
* 压缩(Compression): 选择文件所使用的压缩格式。如果使用DDS文件格式,请选择适当的压缩类型。
** None uses no compression, however, results in enormous file sizes and may prevent HoI4 from processing the bitmap. Use only on smaller font exports.
** 无压缩(None):选择此项即不进行压缩,但会导致文件体积巨大,并可能会阻止HOI4处理位图。仅应在较小的字体导出文件中使用。
** DXT1 is the highest compressed, worst quality, 1-or-0 transparency (no fading, opaque, or completely transparent).
** DXT1 是最高级的压缩选项,拥有最差的画质,仅支持1或0的透明度(没有渐变效果,像素要么完全不透明,要么完全透明)。
** DXT3 is moderately compressed, with higher quality transparency (supports fading).
** DXT3 是中等压缩,透明度质量较高,且支持渐变效果。
** DXT5 is lightly compressed, with the highest possible quality and transparency, with the lowest compression (aside from None).
** DXT5 是轻度压缩,具有最高的画质和透明度效果,是除“无压缩”外压缩率最低的选项。


After this is complete press "OK" to save your changes.
完成设置后,请点击 “确定”(OK)以保存更改。


=== Selecting font characters ===
=== 选择字体字符 ===
To the right are checkboxes for different types of characters, if a character is used that is not in the font it will show as a question mark in a box. Choose whichever ones fit what you're using the font for. Characters can be manually chosen by clicking the character's graphic on the left-hand window - this allows fine-tuning of what characters make it into the bitmap.
软件右侧提供了不同字符类型的复选框。如果使用了字体中不存在的字符,将显示为一个带问号的方框。请选择符合字体用途的字符类型。您还可以在左侧窗口中点击字符图标,手动选择字符,从而精确控制哪些字符会包含在位图中。


In every scenario, the 1-3 blank boxes from Latin and Latin-1 Supplement (the latter might not appear) '''must''' be chosen so spacing works properly. Otherwise, words will appear without spacing.
在任何情况下,都必须选择Latin和Latin-1 补充中的1-3 个空白框(Latin-1 可能不会出现) ,以确保间距正常运作。否则,文字将显示为无间隔的状态。


Recommended characters for tooltips are:
推荐在提示框上使用的字符包括:
* Latin + Latin-1 Supplement
* Latin + Latin-1 Supplement(拉丁+拉丁字母补充-1)
* Latin Extended-A + B
* Latin Extended-A + B(拉丁字母扩展-A + B)
* Latin Extended Additional
* Latin Extended Additional (拉丁字母扩展附加)
* General Punctuation
* General Punctuation (一般标点)


Recommended characters for map fonts depend on the language:
取决于语言的推荐地图字体字符:
* Latin Alphabet (symbols can be excluded):
* Latin Extended Additional - 拉丁字母(符号可省略)
** Latin + Latin-1 Supplement
** Latin + Latin-1 Supplement(拉丁+拉丁字母补充-1)
** Latin Extended-A + B
** Latin Extended-A + B(拉丁字母扩展-A + B)
** Latin Extended Additional
** Latin Extended Additional(拉丁字母扩展附加)


* Cyrillic Alphabet:
* Cyrillic Alphabet(西里尔字母):
** Latin + Latin-1 Supplement (blank spacing boxes)
** Latin + Latin-1 Supplement (blank spacing boxes)  - 拉丁+拉丁字母补充-1(包括空白间距框)
** Cyrillic + Cyrillic Supplement
** Cyrillic + Cyrillic Supplement(西里尔字母补充)
** Cyrillic Extended-B
** Cyrillic Extended-B (西里尔扩展-B)


=== Saving the font ===
=== 保存字体 ===
{{SVersion|1.12}}
{{SVersion|1.12}}


Having set the font as you would like it, check that the characters all fit on one page by clicking V on your keyboard. If they don't, and you don't plan on using multiple font bitmaps, you need to increase the size of the font image width and height or decrease the font size.
设置好字体后,按下键盘上的 V 键检查所有字符是否都能容纳在一页中。如果不能,且不打算使用多个字体位图,则需要增加字体图像的宽度和高度,或减小字体大小。


Save the font by clicking "Save bitmap font as..." (CTRL+S) in the options menu.
通过点击选项菜单中的“Save bitmap font as... ”(快捷键 CTRL+S )来保存字体。


'''Both the image and font file must be named the exact same''' except for the file's extension. While the *.fnt file provides which image file should be used, the game opts to use the file with the same name before the internally defined one. This can also be seen by the file extension lacking from the [[#Defining bitmaps|bitmapfont definition]]. The bitmapfont definition does not need the same name as the font files and can be customized.
''' 图像文件和字体文件的名称必须完全相同,''' 除了扩展名。虽然 *.fnt 文件指定了要使用的图像文件,但游戏会优先选择名称相同的文件,而非内部定义的文件。这一点在位图字体定义中省略文件扩展名时也能体现。此外,位图字体定义的名称无需与字体文件一致,可根据需求进行自定义。


The font's location is decided by the [[#Defining bitmaps|bitmapfont definition]], so it is not necessary to use the {{path|gfx/fonts/}} folder, however, the base game keeps all of its fonts there. The map font is the <code>tahoma_60</code> bitmapfont, which links to the {{path|gfx/fonts/hoi_mapfont4}} files by default, and the appropriate <code>../chinese/</code> and <code>../japanese/</code> folders.
字体的位置由[[#Defining bitmaps| 位图字体定义]] 决定,因此不必放在{{path|gfx/fonts/}} 文件夹中,尽管基础游戏将所有字体都保存在该文件夹中。地图字体是<code>tahoma_60</code> 位图字体,默认链接到{{path|gfx/fonts/hoi_mapfont4}} 文件,以及相应的<code>../chinese/</code> <code>../japanese/</code> 文件夹。


=== Quick check-list ===
=== 快速检查清单 ===
* Open BMFont and select a font.
* 打开 BMFont 并选择字体。
* Set the font settings appropriately and save changes.
* 选择适当的字体设定并保存更改。
* Export the font with proper settings and necessary character sets.
* 使用正确的设置和所需的字符集导出字体。
* '''Remove _0 from the end of the name of the resulting .dds file''' to make it have the same name as the file defining the font.
* ''' 从生成的 .dds 文件名称末尾去掉 "_0"''' ,使其与定义字体的文件名称保持一致。
* Add [[#Kerning|kerning]] to the font if necessary.
* 如有需要,为字体添加 [[#Kerning| 字距调整 (Kerning)]] 
* ''If adding a new font rather than editing an existing one'', add a [[#Defining bitmaps|bitmapfont = { ... } definition]].
* 如果是添加新字体而非编辑现有字体,需添加一个[[#Defining bitmaps|bitmapfont = { ... } 定义]].


== Kerning ==
== 字距调整 (Kerning) ==
{{SVersion|1.12}}
{{SVersion|1.12}}


While many do, some fonts will not be exported with kerning information included in the font file. You can confirm this by opening the *.fnt file, and checking for lines starting with <code>kerning first=</code>. This can lead to character overlaps in-game which can be unsightly. To fix this, you need to add kerning information to your font file.
尽管许多字体会包含字距调整信息,但有些字体在导出时不会将此信息包含在字体文件中。可以通过打开 *.fnt 文件并查找以 <code>kerning first=</code> 开头的行来确认。若缺少字距调整,可能会导致游戏中的字符重叠,影响视觉效果。要解决此问题,需在字体文件中手动添加字距调整信息。


To do this, open your font file and add a new line following this format for each kerning pair:
为此,打开字体文件,并为每对字距调整字符添加一行,格式如下:
<pre>
<pre>
kerning first=<symbol position> second=<symbol position> amount=<pixel width>
kerning first=<symbol position> second=<symbol position> amount=<pixel width>
</pre>
</pre>


A character's position within a font can be seen in BMFont by looking at the lower-right status bar when hovering over a character in the font canvas. The pixel amount is the space between the first and second character. Manually creating each kerning pair is not very feasible. Using a programming language (such as Python) to generate the kerning lines for you is much faster. Below is an example script you can use in Python 3.x or above:
BMFont 中,将鼠标悬停在字体编辑区上的字符上,可以通过右下角的状态栏查看该字符在字体中的位置。像素值表示第一个字符与第二个字符之间的间距。手动创建每个字距调整的效率较低,使用编程语言(如 Python )生成字距调整行则快捷得多。以下是一个可在 Python 3.x 或更高版本中使用的示例脚本:


<syntaxhighlight lang="Python">
<syntaxhighlight lang="Python">
Line 112: Line 112:
</syntaxhighlight>
</syntaxhighlight>


== Defining bitmaps ==
== 定义位图(Defining bitmaps ==
{{SVersion|1.12}}
{{SVersion|1.12}}
To link a new font in {{path|gfx/fonts}}, an entry must be created in a {{path|interface/*.gfx}} file. '''If editing an already existing font, this entry already exists and does not need to be modified.''' An example entry looks like the following:
要在  {{path|gfx/fonts}} 中链接新字体,必须在 {{path|interface/*.gfx}} file 文件中创建一个条目(entry)。''' 如果是编辑已有字体,则该条目已存在,且无需修改。''' 以下是一个示例条目:
<pre>bitmapfonts = {
<pre>bitmapfonts = {
    bitmapfont = {
    bitmapfont = {
Line 129: Line 129:
    }
    }
}</pre>
}</pre>
* <code>name</code> specifies the name of the font. This gets used for [[Interface modding|interface elements that use text]] to signify which font file gets used. '''This is everything that fonts are used for''', except for the map font, which is always <code>tahoma_60</code>. To find where a base game's bitmapfont is used, it is best to [[Modding#Search in files|search every *.gui file in the interface folder using a text editor]] and check the search results for a complete list.
* <code>name</code> 指定字体的名称,此名称用于指定 [[Interface modding| 界面元素]] 所使用的字体文件。所有字体用途都需要此名称,地图字体除外(始终为 <code>tahoma_60</code>)。要查找基础游戏中位图字体的使用位置,建议在文本编辑器中[[Modding#Search in files| 搜索 interface 文件夹中的所有 *.gui 文件,]] ,并检查搜索结果以获取完整列表。
* <code>fontfiles</code> provides the location of all bitmaps used in the font, which is the path to the {{path|gfx/fonts/*.fnt}} file without the .fnt extension. The files should have no overlapping characters defined. If a font uses one font file in total, <code>path = "gfx/fonts/my_font"</code> can be used instead.<br/>
* <code>fontfiles</code> 指定字体使用的所有位图的位置,即  {{path|gfx/fonts/*.fnt}} 文件的路径,但不包含 .fnt 扩展名。文件中不应定义重复的字符。如果字体只使用一个字体文件,可直接使用<code>path = "gfx/fonts/my_font"</code> <br/>
* <code>color</code> defines the colour of the font in hex code of the ARGB format. The first 2 characters after the <code>0x</code> define the transparency of the font, <code>00</code> meaning full transparency and <code>FF</code> meaning full opacity. The latter 6 characters provide the RGB hex code, each colour defined on the scale from <code>00</code> to <code>FF</code>.
* <code>color</code> 定义字体的颜色,其使用 ARGB 格式的十六进制代码。0x 后的前两个字符定义字体的透明度, <code>00</code>  表示完全透明,<code>FF</code> 表示完全不透明。接下来的六个字符为 RGB 代码,每种颜色值在 <code>00</code> <code>FF</code> 范围内。
* <code>textcolors</code> provides an override of [[Localisation#Formatting_characters|text colours]], allowing to change a particular text colour to give a different colour when used on this font compared to the default value.
* <code>textcolors</code> 提供 [[Localisation#Formatting_characters| 文本颜色]] 的覆盖功能,允许将特定文本颜色更改为不同于默认值的颜色,从而在此字体上呈现出不同的效果。


=== Overriding bitmaps ===
=== 覆盖位图(Overriding bitmaps ===
Additionally, it is possible to override a bitmapfont when the game is set to use a specific language. Primarily, fonts are overwritten for languages that don't use the Latin alphabet, and thus can't be small enough to fit into a 16 MB file (i.e. Simplified Chinese). By default, HoI4 has the necessary Cyrillic and Latin map font characters in one file, but the list of (Simplified) Chinese logographs is so enormous '''it must encompass 11 ~4096x4000 bitmaps''' with an override block in {{path|interface/code_chinese.gfx}}.
此外,可以在游戏设置为特定语言时覆盖位图字体。主要用于非拉丁字母的语言,因为这些字体通常过大,无法压缩到 16 MB 文件内(例如简体中文)。默认情况下,HoI4 已将必要的西里尔字母和拉丁字母的地图字体字符包含在一个文件中,但简体中文的汉字数量庞大,因此需要 '''11 个大约 为4096x4000 的位图文件''' ,并在{{path|interface/code_chinese.gfx}} 中使用override block来定义。


The aforementioned overwrite entries in a {{path|interface/*.gfx}} file looks like the following example:
上述在 {{path|interface/*.gfx}} 文件中的覆盖条目示例如下:
<pre>bitmapfonts = {
<pre>bitmapfonts = {
    bitmapfont_override = {
    bitmapfont_override = {
Line 148: Line 148:
    }
    }
}</pre>
}</pre>
* <code>path = "gfx/fonts/my_font"</code> may again be used instead of <code>fontfiles =</code> should you only use one bitmap.
* <code>path = "gfx/fonts/my_font"</code> 如果仅使用一个位图,可以再次使用它,而不必使用 <code>fontfiles =</code>
* <code>languages =</code> must equate to one of the supported languages in HoI4. All accepted languages have folders in {{path|localisation}}.
* <code>languages =</code> 必须等于 HoI4 支持的语言之一。所有支持的语言在 {{path|localisation}} 文件夹中都有对应的文件夹。


The work involved in generating multiple bitmaps is the only downside. However, using multiple bitmaps is an effective way to organize fonts between different alphabets. Should a mod use custom fonts in entirety, it also provides more space to use larger/higher quality characters and font designs without aliasing.
生成多个位图的工作量是唯一的缺点,但这是将不同字母表的字体分开组织的有效方法。如果一个 mod 完全采用自定义字体,这种方式还能提供更大的空间,以支持更大、更高质量的字符和字体设计,同时减少锯齿效果。


{{Modding navbox}}
{{Modding navbox}}
[[分类:Modding]]
[[分类:Modding]]

Latest revision as of 19:54, 4 February 2025

创建新字体

制作新字体需要用到 BMFont 程序,该程序可用于从字体生成字体页面和描述文件。

在BMFont 安装完毕后,启动程序,进入选项菜单并选择字体设置。导入你的字体文件后,从下拉菜单中选择字体(字体可以在Google Fonts-谷歌字体进行下载) 。在完成这些步骤后,即可开始配置字体设置。

字体设置

导入字体后便可以设置字体外观了。为此,再次打开字体设置菜单。以下是需要调整的:

  • 字符集 (Charset): 将其设定为统一码(Unicode)
  • 大小(Size):这是输出页面的每个字体的大小,将其设定为你想要的尺寸。
    • 请注意,较大的字符尺寸会增加对于最终输出的空间占用,并可能将你的结果分散在多个位图中。如需使用多个位图,必须生成单独定义的字体文件,因此建议尽量将所有字体保留在一个位图中。(译者注:由于中文的表意方式与英语不同,将中文字符保留在一张位图里几乎不可能,如果你这么做,可能会导致严重的字符缺失等,建议参考https://www.bilibili.com/opus/710497357426327574)
  • 匹配字符高度(Match char height):勾选此项以确保所有字符的高度一致。
  • 字体平滑(Font smoothing):如果字体边缘在游戏中看起来过于锐利,请勾选此项。
  • 轮廓厚度(Outline thickness):如果希望字体带有轮廓,可在此设置所需的轮廓厚度。
    • 请注意,这会导致字符在字体位图中的尺寸增加,因此会占据更多的空间。

完成设置后,点击"确定"(OK)以保存更改。

导出选项

设置完字体后,就可以配置导出游戏可识别的字体位图格式了。为此,打开导出选项菜单(Export Options)。以下是你可能需要调整的:

  • 填充(Padding):调整字体图像中每个字符边缘的内边距。仅在需要手动编制字体文件且希望字符之间保持一定距离时才需设置此项。
  • 色彩深度(Bit depth):将其设置为32。
  • 间距(Spacing):控制字体图像中字符之间的最小间距。将此项设置为1-1;如果字符出现相互重叠的问题,请将其设置为更高的值。
  • 宽高(Width & Height):导出的字体位图的尺寸。调整此项以确保所有字符都能容纳在一张图上。(见上译者注)
    • 请注意,宽度与高度的增加会显著增加文件的大小。游戏无法处理超过16MB的单个字体图像文件,其中Paradox的中文字体最大文件大小为16,001KB。在不使用较高强度的压缩的情况下,此限制很容易达到。您可以通过为同一字体定义多个链接的位图来规避这一限制,就像Paradox 使用的11个 14-16MB 中文字体位图链接一样。
  • 通道(Channels):控制字符的合成方式。若未设置轮廓,请将所有通道设为glyph;若已设置轮廓,则将Alpha通道(A)设为outline,其余通道均设为glyph
  • 预设(Presets):若已手动选择上述通道,则此项可忽略。选择任何适合文本的预设即可,但需确保包含 Alpha 通道。
  • 字体描述符(Font descriptor):需设置为文本格式(text)。
  • 材质(Textures):应设置为.dds。
  • 压缩(Compression):选择文件所使用的压缩格式。如果使用DDS文件格式,请选择适当的压缩类型。
    • 无压缩(None):选择此项即不进行压缩,但会导致文件体积巨大,并可能会阻止HOI4处理位图。仅应在较小的字体导出文件中使用。
    • DXT1 是最高级的压缩选项,拥有最差的画质,仅支持1或0的透明度(没有渐变效果,像素要么完全不透明,要么完全透明)。
    • DXT3 是中等压缩,透明度质量较高,且支持渐变效果。
    • DXT5是轻度压缩,具有最高的画质和透明度效果,是除“无压缩”外压缩率最低的选项。

完成设置后,请点击 “确定”(OK)以保存更改。

选择字体字符

软件右侧提供了不同字符类型的复选框。如果使用了字体中不存在的字符,将显示为一个带问号的方框。请选择符合字体用途的字符类型。您还可以在左侧窗口中点击字符图标,手动选择字符,从而精确控制哪些字符会包含在位图中。

在任何情况下,都必须选择Latin和Latin-1补充中的1-3个空白框(Latin-1可能不会出现),以确保间距正常运作。否则,文字将显示为无间隔的状态。

推荐在提示框上使用的字符包括:

  • Latin + Latin-1 Supplement(拉丁+拉丁字母补充-1)
  • Latin Extended-A + B(拉丁字母扩展-A + B)
  • Latin Extended Additional (拉丁字母扩展附加)
  • General Punctuation (一般标点)

取决于语言的推荐地图字体字符:

  • Latin Extended Additional - 拉丁字母(符号可省略):
    • Latin + Latin-1 Supplement(拉丁+拉丁字母补充-1)
    • Latin Extended-A + B(拉丁字母扩展-A + B)
    • Latin Extended Additional(拉丁字母扩展附加)
  • Cyrillic Alphabet(西里尔字母):
    • Latin + Latin-1 Supplement (blank spacing boxes) - 拉丁+拉丁字母补充-1(包括空白间距框)
    • Cyrillic + Cyrillic Supplement(西里尔字母补充)
    • Cyrillic Extended-B (西里尔扩展-B)

保存字体

设置好字体后,按下键盘上的 V 键检查所有字符是否都能容纳在一页中。如果不能,且不打算使用多个字体位图,则需要增加字体图像的宽度和高度,或减小字体大小。

通过点击选项菜单中的“Save bitmap font as...”(快捷键 CTRL+S)来保存字体。

图像文件和字体文件的名称必须完全相同,除了扩展名。虽然 *.fnt 文件指定了要使用的图像文件,但游戏会优先选择名称相同的文件,而非内部定义的文件。这一点在位图字体定义中省略文件扩展名时也能体现。此外,位图字体定义的名称无需与字体文件一致,可根据需求进行自定义。

字体的位置由位图字体定义决定,因此不必放在/Hearts of Iron IV/gfx/fonts/ 文件夹中,尽管基础游戏将所有字体都保存在该文件夹中。地图字体是tahoma_60位图字体,默认链接到/Hearts of Iron IV/gfx/fonts/hoi_mapfont4 文件,以及相应的../chinese/../japanese/ 文件夹。

快速检查清单

  • 打开 BMFont并选择字体。
  • 选择适当的字体设定并保存更改。
  • 使用正确的设置和所需的字符集导出字体。
  • 从生成的 .dds 文件名称末尾去掉 "_0",使其与定义字体的文件名称保持一致。
  • 如有需要,为字体添加 字距调整 (Kerning)
  • 如果是添加新字体而非编辑现有字体,需添加一个bitmapfont = { ... }定义.

字距调整 (Kerning)

尽管许多字体会包含字距调整信息,但有些字体在导出时不会将此信息包含在字体文件中。可以通过打开 *.fnt 文件并查找以 kerning first=开头的行来确认。若缺少字距调整,可能会导致游戏中的字符重叠,影响视觉效果。要解决此问题,需在字体文件中手动添加字距调整信息。

为此,打开字体文件,并为每对字距调整字符添加一行,格式如下:

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

在 BMFont 中,将鼠标悬停在字体编辑区上的字符上,可以通过右下角的状态栏查看该字符在字体中的位置。像素值表示第一个字符与第二个字符之间的间距。手动创建每个字距调整的效率较低,使用编程语言(如 Python)生成字距调整行则快捷得多。以下是一个可在 Python 3.x 或更高版本中使用的示例脚本:

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

定义位图(Defining bitmaps)

要在 /Hearts of Iron IV/gfx/fonts中链接新字体,必须在 /Hearts of Iron IV/interface/*.gfx file文件中创建一个条目(entry)。如果是编辑已有字体,则该条目已存在,且无需修改。以下是一个示例条目:

bitmapfonts = {
    bitmapfont = {
        name = "my_font"
        fontfiles = {
            "gfx/fonts/font_bitmap_1"
            "gfx/fonts/font_bitmap_2"
        }
        color = 0xffffffff

        textcolors = {
            G = { 86 172 91 }
        }
    }
}
  • name 指定字体的名称,此名称用于指定 界面元素所使用的字体文件。所有字体用途都需要此名称,地图字体除外(始终为 tahoma_60)。要查找基础游戏中位图字体的使用位置,建议在文本编辑器中搜索 interface 文件夹中的所有 *.gui 文件,,并检查搜索结果以获取完整列表。
  • fontfiles指定字体使用的所有位图的位置,即 /Hearts of Iron IV/gfx/fonts/*.fnt 文件的路径,但不包含 .fnt 扩展名。文件中不应定义重复的字符。如果字体只使用一个字体文件,可直接使用path = "gfx/fonts/my_font"
  • color 定义字体的颜色,其使用 ARGB 格式的十六进制代码。0x 后的前两个字符定义字体的透明度, 00 表示完全透明,FF 表示完全不透明。接下来的六个字符为 RGB 代码,每种颜色值在 00FF范围内。
  • textcolors 提供 文本颜色的覆盖功能,允许将特定文本颜色更改为不同于默认值的颜色,从而在此字体上呈现出不同的效果。

覆盖位图(Overriding bitmaps)

此外,可以在游戏设置为特定语言时覆盖位图字体。主要用于非拉丁字母的语言,因为这些字体通常过大,无法压缩到 16 MB 文件内(例如简体中文)。默认情况下,HoI4 已将必要的西里尔字母和拉丁字母的地图字体字符包含在一个文件中,但简体中文的汉字数量庞大,因此需要 11 个大约 为4096x4000 的位图文件,并在/Hearts of Iron IV/interface/code_chinese.gfx中使用override block来定义。

上述在 /Hearts of Iron IV/interface/*.gfx 文件中的覆盖条目示例如下:

bitmapfonts = {
    bitmapfont_override = {
        name = "my_font"
        fontfiles = {
            "gfx/fonts/font_bitmap_1"
            "gfx/fonts/font_bitmap_2"
        }
        languages = { "l_russian" "l_polish" }
    }
}
  • path = "gfx/fonts/my_font" 如果仅使用一个位图,可以再次使用它,而不必使用 fontfiles =
  • languages = 必须等于 HoI4 支持的语言之一。所有支持的语言在 /Hearts of Iron IV/localisation文件夹中都有对应的文件夹。

生成多个位图的工作量是唯一的缺点,但这是将不同字母表的字体分开组织的有效方法。如果一个 mod完全采用自定义字体,这种方式还能提供更大的空间,以支持更大、更高质量的字符和字体设计,同时减少锯齿效果。