Adding Custom Fonts – Arma 3

From Bohemia Interactive Community
Jump to navigation Jump to search
(page added.)
 
m (Text replacement - "{{Link|https://community.bistudio.com/wiki/" to "{{Link|")
Line 6: Line 6:
== The things you need ==
== The things you need ==
# Arma 3
# Arma 3
# {{Link|https://community.bistudio.com/wiki/Arma_3:_Tools_Launcher|Arma 3 Tools Launcher}} (from Steam)
# {{Link|Arma_3:_Tools_Launcher|Arma 3 Tools Launcher}} (from Steam)
# a Windows machine capable of running Powershell scripts
# a Windows machine capable of running Powershell scripts
# this unofficial Powershell script: https://github.com/Nelis75733126/Arma_3_FontToTGA_Helper/
# this unofficial Powershell script: https://github.com/Nelis75733126/Arma_3_FontToTGA_Helper/
Line 16: Line 16:
! term !! meaning
! term !! meaning
|-
|-
| Arma 3 Tools || {{Link|https://community.bistudio.com/wiki/Arma_3:_Tools_Launcher|Arma 3 Tools Launcher}}
| Arma 3 Tools || {{Link|Arma_3:_Tools_Launcher|Arma 3 Tools Launcher}}
|-
|-
| CfgFontFamilies || this refers to a <syntaxhighlight lang="cpp" inline>class</syntaxhighlight> type that can be put inside a {{Link|https://community.bistudio.com/wiki/Config.cpp/bin_File_Format|config.cpp}} file.
| CfgFontFamilies || this refers to a <syntaxhighlight lang="cpp" inline>class</syntaxhighlight> type that can be put inside a {{Link|Config.cpp/bin_File_Format|config.cpp}} file.
|-
|-
| .tga file format || Used for textures. In this context, TGA files are used to store all characters of a font.
| .tga file format || Used for textures. In this context, TGA files are used to store all characters of a font.
Line 34: Line 34:
== Some context ==
== Some context ==
The idea is that fonts (TTF or OTF) can be converted into TGA files by <syntaxhighlight lang="cpp" inline>FontToTGA.exe</syntaxhighlight>. Every time <syntaxhighlight lang="cpp" inline>FontToTGA.exe</syntaxhighlight> is called, one of the required parameters is a specific font size in <syntaxhighlight lang="cpp" inline>pt</syntaxhighlight> size format.<br>
The idea is that fonts (TTF or OTF) can be converted into TGA files by <syntaxhighlight lang="cpp" inline>FontToTGA.exe</syntaxhighlight>. Every time <syntaxhighlight lang="cpp" inline>FontToTGA.exe</syntaxhighlight> is called, one of the required parameters is a specific font size in <syntaxhighlight lang="cpp" inline>pt</syntaxhighlight> size format.<br>
<syntaxhighlight lang="cpp" inline>FontToTGA.exe</syntaxhighlight> will then generate <syntaxhighlight lang="cpp" inline>.fxy</syntaxhighlight> files and <syntaxhighlight lang="cpp" inline>.tga</syntaxhighlight> files. Then, <syntaxhighlight lang="cpp" inline>ImageToPAA.exe</syntaxhighlight> can convert the TGA files created by <syntaxhighlight lang="cpp" inline>FontToTGA.exe</syntaxhighlight> into PAA files. Then the <syntaxhighlight lang="cpp" inline>.fxy</syntaxhighlight> and <syntaxhighlight lang="cpp" inline>.paa</syntaxhighlight> files should be moved into an Addon. {{Link|https://community.bistudio.com/wiki/Arma_3:_Creating_an_Addon|Learn how to make one here}}.<br>
<syntaxhighlight lang="cpp" inline>FontToTGA.exe</syntaxhighlight> will then generate <syntaxhighlight lang="cpp" inline>.fxy</syntaxhighlight> files and <syntaxhighlight lang="cpp" inline>.tga</syntaxhighlight> files. Then, <syntaxhighlight lang="cpp" inline>ImageToPAA.exe</syntaxhighlight> can convert the TGA files created by <syntaxhighlight lang="cpp" inline>FontToTGA.exe</syntaxhighlight> into PAA files. Then the <syntaxhighlight lang="cpp" inline>.fxy</syntaxhighlight> and <syntaxhighlight lang="cpp" inline>.paa</syntaxhighlight> files should be moved into an Addon. {{Link|Arma_3:_Creating_an_Addon|Learn how to make one here}}.<br>
Then, inside of the config.cpp of that addon, there should be an entry for each font you want to add, so that Arma 3 knows what to look for. Here is an example of that config.cpp:
Then, inside of the config.cpp of that addon, there should be an entry for each font you want to add, so that Arma 3 knows what to look for. Here is an example of that config.cpp:
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">

Revision as of 11:06, 16 May 2024

Tutorial: how to import a font into Arma 3

This tutorial will provide you will all the required details on how to get a font into Arma 3.

This page contains references to unofficial third-party code

The things you need

  1. Arma 3
  2. Arma 3 Tools Launcher (from Steam)
  3. a Windows machine capable of running Powershell scripts
  4. this unofficial Powershell script: https://github.com/Nelis75733126/Arma_3_FontToTGA_Helper/
  5. a mouse and keyboard might be handy :P :P

definitions

term meaning
Arma 3 Tools Arma 3 Tools Launcher
CfgFontFamilies this refers to a class type that can be put inside a config.cpp file.
.tga file format Used for textures. In this context, TGA files are used to store all characters of a font.
.paa file format Also used for textures. Arma 3 uses TGA files converted into PAA files to display text.
.fxy file format This contains information about where each character of a font is placed in a particular texture file.
FontToTGA.exe A command-line tool included with Arma 3 Tools. It converts fonts into TGA files. More details here: FontToTga
ImageToPAA.exe A tool also included in Arma 3 Tools which can be used to convert TGA files into PAA files. More details here: ImageToPAA

Some context

The idea is that fonts (TTF or OTF) can be converted into TGA files by FontToTGA.exe. Every time FontToTGA.exe is called, one of the required parameters is a specific font size in pt size format.
FontToTGA.exe will then generate .fxy files and .tga files. Then, ImageToPAA.exe can convert the TGA files created by FontToTGA.exe into PAA files. Then the .fxy and .paa files should be moved into an Addon. Learn how to make one here.
Then, inside of the config.cpp of that addon, there should be an entry for each font you want to add, so that Arma 3 knows what to look for. Here is an example of that config.cpp:

class CfgPatches
	{
		class PREFIX_Custom_Fonts
			{
				name = "SOMETHING - UI fonts";
				author = "your name";
				url = "https://github.com/yourname";
				requiredVersion = 0;
				requiredAddons[] = {};
				units[] = {};
				weapons[] = {};
				skipWhenMissingDependcies = 0;
			};
	};
class CfgFontFamilies
	{
        class BebasNeue
            {
                fonts[] =
                    {
                        /*
                            these are just four examples to make this example shorter.
                            normally, there would be a lot more entries in here. will be explained later in this tutorial.
                        */
                        "PREFIX_Custom_Fonts\Fonts\BebasNeue\BebasNeue10", // the number at the end refers to the size of the font in pt
                        "PREFIX_Custom_Fonts\Fonts\BebasNeue\BebasNeue11",
                        "PREFIX_Custom_Fonts\Fonts\BebasNeue\BebasNeue12",
                        "PREFIX_Custom_Fonts\Fonts\BebasNeue\BebasNeue100" // it can go higher than that, but 100 is pretty big :)
                    };
            };
	};


So for each font you want to add, you add a class theNameOfTheFont inside of the brackets from class CfgFontFamilies. If you want to add multiple fonts, simply do it like so:

class CfgFontFamilies
    {
        class SomeReallyNiceFont
            {
                fonts[]={}; // should be filled with strings 
            };
        class MonoSpaceFontMaybe
            {
                fonts[]={}; // should be filled with strings
            };
        // and so on.... add as much as you like.
    };


The name you use as the class will be the exact name that you later will use in the font = "fontName"; property to get that font to appear in UI elements of Arma 3.

It makes no difference what you make this name to be, as long as it is different than any other font installed into Arma 3.
Thanks to the creator of the Powershell script (as linked earlier), there is no need for you to write the config yourself. It will generate it for you. The only thing you need to do is copy it and paste it in the right place.

about the fonts[]={};

This will all be generated by the Powershell script :)
It is a list of strings where each string refers to the path of each size of the font that was generated. If you want really big text in the game, then the appropriate size in pt has to be generated.
If the text inside of a UI element is much larger than the biggest available texture, the text will look ugly. Simply because Arma 3 will scale the texture up to the size requested.
By default, the Powershell script will generate a bunch of sizes to make sure that the font will look good through a wide range of sizes.
But, the script is capable of using custom font sizes that you define if you wish to provide them. It is ok if you just leave it up to the script.
It is very likely those default sizes will suit your needs just fine.
If you only want a very specific size of the font, you can use the Powershell script to get that. The script itself will instruct you on how.

The process

  • Read the instructions for the Powershell script. Then execute that script.
  • Once done, you should have a bunch of .fxy and .tga files inside the Fonts folder of where FontToTGA.exe is located. Unless you provided another location to the Powershell script.
  • Now it is time to let ImageToPAA.exe convert all the .tga files into .paa files. Start it up and just look at the interface to see how it works. It is pretty straightforward.
  • Once all PAA images are generated, copy the .fxy and .paa files into a directory where you can let Addon_Builder (also included in Arma 3 Tools) make a PBO from. The instructions on how to use Addon_Builder can be found elsewhere.
  • Now pay close attention to the config for class CfgFontFamilies that was generated by the Powershell script: each string in the fonts[]={}; list will contain the path to where the .fxy and .paa files should be placed.

An example:

fonts[] =
    {
        "PREFIX_Custom_Fonts\Fonts\BebasNeue\BebasNeue10"
    };

The PREFIX_Custom_Fonts is a reference to the class used inside class CfgPatches of the config.cpp belonging to the addon in which you wish to place the fonts.
So in the example above, there should be a folder called Fonts in the same folder where the config.cpp is.
Create it if missing, and then take the folder with the name of the font (the one inside the Fonts folder of FontToTGA.exe) and put it in there.

It is up to you if you want to keep or delete the .tga files.


  • Double-check everything and make sure the config.cpp for your addon has been set right. If so, build it using Addon_Builder.
  • Add it to the launch options of the game. Instructions for that can be found elsewhere.
  • Start the game, go into the 3DEN editor, open the config viewer, double-click on configFile.
  • Type cfgFontFamilies. It should scroll the list to where it is.
  • Double-click it and it should show the font you have added :)
  • If so, then your font is ready to be used in the game. To see it, make sure any Dialog/Display control with a text property has font = "theFontYouAdded"; in it and you should be able to view the font!