Adding Custom Fonts – Arma 3

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "{{Link|https://community.bistudio.com/wiki/" to "{{Link|")
m ("Some" wiki formatting)
 
Line 1: Line 1:
= Tutorial: how to import a font into Arma 3 =
{{TOC|side}}
This tutorial will provide you will all the required details on how to get a font into Arma 3.<br>
This tutorial explains how to get a font into {{arma3}}.


{{Feature|informative|This page contains references to unofficial third-party code}}
{{Feature|UnsupportedTool}}


== The things you need ==
# Arma 3
# {{Link|Arma_3:_Tools_Launcher|Arma 3 Tools Launcher}} (from Steam)
# a Windows machine capable of running Powershell scripts
# this unofficial Powershell script: https://github.com/Nelis75733126/Arma_3_FontToTGA_Helper/
# a mouse and keyboard might be handy :P :P


== definitions ==
== Requirements ==
 
* {{arma3}}
* {{Link|Arma 3 Tools Launcher}} (from [[Steam]])
* a Windows machine capable of running Powershell scripts
* this unofficial Powershell script: https://github.com/Nelis75733126/Arma_3_FontToTGA_Helper/
* a mouse and keyboard might be handy :P :P
 
 
== Definitions ==
 
{| class="wikitable"
{| class="wikitable"
|-
|-
! term !! meaning
! Term !! Meaning
|-
|-
| Arma 3 Tools || {{Link|Arma_3:_Tools_Launcher|Arma 3 Tools Launcher}}
| Arma 3 Tools || {{Link|Arma 3 Tools Launcher}}
|-
|-
| 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.
| <syntaxhighlight lang="cpp" inline>CfgFontFamilies</syntaxhighlight> || this refers to a {{hl|class}} 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.
| {{hl|.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.
| {{hl|.paa}} file format || Also used for textures. {{arma3}} 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.
| {{hl|.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]]
| FontToTGA.exe || A command-line tool included with Arma 3 Tools. It converts fonts into TGA files. More details here: [[FontToTga]]
Line 32: Line 36:
|}
|}


== 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>
== Steps ==
<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:
The idea is that fonts (TTF or OTF) can be converted into TGA files by {{hl|FontToTGA.exe}}.
<syntaxhighlight lang="cpp">
Every time {{hl|FontToTGA.exe}} is called, one of the required parameters is a specific font size in {{hl|pt}} size format.
 
# {{hl|FontToTGA.exe}} will then generate {{hl|.fxy}} files and {{hl|.tga}} files.
# Then, ImageToPAA.exe can convert the TGA files created by FontToTGA.exe into PAA files.
# Then the {{hl|.fxy}} and {{hl|.paa}} files should be moved into an Addon. See {{Link|Arma 3: Creating an Addon}} to learn how to make one.
# Then, inside of the addon's config.cpp, there should be an entry for each font you want to add, so that the game knows for what to look. Here is an example of that {{hl|config.cpp}}:<syntaxhighlight lang="cpp">
class CfgPatches
class CfgPatches
{
class TAG_Custom_Fonts
{
{
class PREFIX_Custom_Fonts
name = "SOMETHING - UI fonts";
{
author = "your name";
name = "SOMETHING - UI fonts";
url = "https://github.com/yourname";
author = "your name";
requiredVersion = 0;
url = "https://github.com/yourname";
requiredAddons[] = {};
requiredVersion = 0;
units[] = {};
requiredAddons[] = {};
weapons[] = {};
units[] = {};
skipWhenMissingDependcies = 0;
weapons[] = {};
skipWhenMissingDependcies = 0;
};
};
};
};
class CfgFontFamilies
class CfgFontFamilies
{
class BebasNeue
{
{
        class BebasNeue
fonts[] =
            {
{
                fonts[] =
/*
                    {
these are just four examples to make this example shorter.
                        /*
normally, there would be a lot more entries in here as explained below.
                            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.
"TAG_Custom_Fonts\Fonts\BebasNeue\BebasNeue10", // the number at the end refers to the size of the font in pt
                        */
"TAG_Custom_Fonts\Fonts\BebasNeue\BebasNeue11",
                        "PREFIX_Custom_Fonts\Fonts\BebasNeue\BebasNeue10", // the number at the end refers to the size of the font in pt
"TAG_Custom_Fonts\Fonts\BebasNeue\BebasNeue12",
                        "PREFIX_Custom_Fonts\Fonts\BebasNeue\BebasNeue11",
"TAG_Custom_Fonts\Fonts\BebasNeue\BebasNeue100" // it can go higher than that, but 100 is pretty big :)
                        "PREFIX_Custom_Fonts\Fonts\BebasNeue\BebasNeue12",
};
                        "PREFIX_Custom_Fonts\Fonts\BebasNeue\BebasNeue100" // it can go higher than that, but 100 is pretty big :)
                    };
            };
};
};
</syntaxhighlight><br>
};
</syntaxhighlight>
 


So for each font you want to add, you add a <syntaxhighlight lang="cpp" inline>class theNameOfTheFont</syntaxhighlight> inside of the brackets from <syntaxhighlight lang="cpp" inline>class CfgFontFamilies</syntaxhighlight>.
== Config ==
 
Each added font requires a <syntaxhighlight lang="cpp" inline>class theNameOfTheFont</syntaxhighlight> in the <syntaxhighlight lang="cpp" inline>class CfgFontFamilies</syntaxhighlight> brackets.
If you want to add multiple fonts, simply do it like so:
If you want to add multiple fonts, simply do it like so:
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">
class CfgFontFamilies
class CfgFontFamilies
    {
{
        class SomeReallyNiceFont
class SomeReallyNiceFont
            {
{
                fonts[]={}; // should be filled with strings  
fonts[] = {}; // should be filled with strings  
            };
};
        class MonoSpaceFontMaybe
 
            {
class MonoSpaceFontMaybe
                fonts[]={}; // should be filled with strings
{
            };
fonts[] = {}; // should be filled with strings
        // and so on.... add as much as you like.
};
    };
 
</syntaxhighlight><br>
// and so on - add as much as you like
};
</syntaxhighlight>
 
{{Feature|informative|The classname you use will be the exact name that you later will use in the <syntaxhighlight lang="cpp" inline>font = "fontName";</syntaxhighlight> property to get that font to appear in UI elements.}}


{{Feature|informative|The name you use as the <syntaxhighlight lang="cpp" inline>class</syntaxhighlight> will be the exact name that you later will use in the <syntaxhighlight lang="cpp" inline>font = "fontName";</syntaxhighlight> property to get that font to appear in UI elements of Arma 3.<br>}}
The name itself makes no difference as long as it does not conflict with an existing font.
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.<br>
Thanks to the creator of the Powershell script (as linked earlier), the config is generated for you.
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.<br>
The only thing you need to do is copy it and paste it in the right place.
 
=== Fonts Array ===


== about the fonts[]={}; ==
This will all be generated by the Powershell script :)<br>
This will all be generated by the Powershell script :)<br>
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.<br>
It is a list of strings where each string refers to the path of each size of the font that was 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.<br>
If you want really big text in the game, then the appropriate size in pt has to be generated.<br>
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.<br>
If the text inside of a UI element is much larger than the biggest available texture, the text will look ugly simply because the game will scale the texture up to the requested size.<br>
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.<br>
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;
It is very likely those default sizes will suit your needs just fine.<br>
but it is also capable of using provided custom sizes. Using the default values is fine.<br>
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.
If you only want a very specific size of the font, you can use the Powershell script to get that. The script itself tells you how.
 


== The process ==
== Process ==
* Read the instructions for the Powershell script. Then execute that script.
* Once done, you should have a bunch of <syntaxhighlight lang="cpp" inline>.fxy</syntaxhighlight> and <syntaxhighlight lang="cpp" inline>.tga</syntaxhighlight> files inside the Fonts folder of where <syntaxhighlight lang="cpp" inline>FontToTGA.exe</syntaxhighlight> is located. Unless you provided another location to the Powershell script.
* Now it is time to let <syntaxhighlight lang="cpp" inline>ImageToPAA.exe</syntaxhighlight> convert all the <syntaxhighlight lang="cpp" inline>.tga</syntaxhighlight> files into <syntaxhighlight lang="cpp" inline>.paa</syntaxhighlight> 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 <syntaxhighlight lang="cpp" inline>.fxy</syntaxhighlight> and <syntaxhighlight lang="cpp" inline>.paa</syntaxhighlight> 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 <syntaxhighlight lang="cpp" inline>class CfgFontFamilies</syntaxhighlight> that was generated by the Powershell script: each string in the <syntaxhighlight lang="cpp" inline>fonts[]={};</syntaxhighlight> list will contain the path to where the <syntaxhighlight lang="cpp" inline>.fxy</syntaxhighlight> and <syntaxhighlight lang="cpp" inline>.paa</syntaxhighlight> files should be placed.<br>
An example:<br>


<syntaxhighlight lang="cpp">
# Read the instructions for the Powershell script, then execute that script.
# Once done, you should have a bunch of {{hl|.fxy}} and {{hl|.tga}} files inside the Fonts folder of where {{hl|FontToTGA.exe}} is located. Unless you provided another location to the Powershell script.
# Now it is time to let {{hl|ImageToPAA.exe}} convert all the {{hl|.tga}} files into {{hl|.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 {{hl|.fxy}} and {{hl|.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 {{Link|Arma 3: Creating an Addon#Addon Builder|here}}.
# Now pay close attention to the config for <syntaxhighlight lang="cpp" inline>class CfgFontFamilies</syntaxhighlight> that was generated by the Powershell script: each string in the <syntaxhighlight lang="cpp" inline>fonts[] = {};</syntaxhighlight> list will contain the path to where the {{hl|.fxy}} and {{hl|.paa}} files should be placed.<br><br>An example:<syntaxhighlight lang="cpp">
fonts[] =
fonts[] =
    {
{
        "PREFIX_Custom_Fonts\Fonts\BebasNeue\BebasNeue10"
"TAG_Custom_Fonts\Fonts\BebasNeue\BebasNeue10"
    };
};
</syntaxhighlight>
</syntaxhighlight><br><!--
The <syntaxhighlight lang="cpp" inline>PREFIX_Custom_Fonts</syntaxhighlight> is a reference to the <syntaxhighlight lang="cpp" inline>class</syntaxhighlight> used inside <syntaxhighlight lang="cpp" inline>class CfgPatches</syntaxhighlight> of the <syntaxhighlight lang="cpp" inline>config.cpp</syntaxhighlight> belonging to the addon in which you wish to place the fonts.<br>
 
So in the example above, there should be a folder called Fonts in the same folder where the <syntaxhighlight lang="cpp" inline>config.cpp</syntaxhighlight> is.<br>
-->The {{hl|TAG_Custom_Fonts}} is a reference to the class used inside the addon {{hl|config.cpp}}'s <syntaxhighlight lang="cpp" inline>class CfgPatches</syntaxhighlight>.<br><!--
Create it if missing, and then take the folder with the name of the font (the one inside the Fonts folder of <syntaxhighlight lang="cpp" inline>FontToTGA.exe</syntaxhighlight>) and put it in there.<br>
-->In the example above, there should be a folder called Fonts in the same folder as {{hl|config.cpp}}.<br><!--
-->Create it if missing, and then take the folder with the font's name (the one inside the {{hl|FontToTGA.exe}}'s Fonts folder) and put it in there.<!--


{{Feature|informative|It is up to you if you want to keep or delete the <syntaxhighlight lang="cpp" inline>.tga</syntaxhighlight> files.}}<br>
-->{{Feature|informative|It is up to you if you want to keep or delete the {{hl|.tga}} files.}}
# Double-check everything and make sure the {{hl|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 {{hl|configFile}}.
# Type {{hl|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 <syntaxhighlight lang="cpp" inline>text</syntaxhighlight> property has <syntaxhighlight lang="cpp" inline>font = "theFontYouAdded";</syntaxhighlight> in it and you should be able to view the font!


* 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 <syntaxhighlight lang="cpp" inline>configFile</syntaxhighlight>.
* Type <syntaxhighlight lang="cpp" inline>cfgFontFamilies</syntaxhighlight>. 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 <syntaxhighlight lang="cpp" inline>text</syntaxhighlight> property has <syntaxhighlight lang="cpp" inline>font = "theFontYouAdded";</syntaxhighlight> in it and you should be able to view the font!


{{GameCategory|arma3|Tutorials}}
{{GameCategory|arma3|Tutorials}}

Latest revision as of 11:44, 16 May 2024

This tutorial explains how to get a font into Arma 3.

bi symbol white.png
Disclaimer: This page describes an unofficial tool created without permission or support of Bohemia Interactive.

The product itself and its usage may be violating rights of Bohemia Interactive and is in no way endorsed or recommended by Bohemia Interactive.

See also Official Tools.


Requirements


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


Steps

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.

  1. FontToTGA.exe will then generate .fxy files and .tga files.
  2. Then, ImageToPAA.exe can convert the TGA files created by FontToTGA.exe into PAA files.
  3. Then the .fxy and .paa files should be moved into an Addon. See Arma 3: Creating an Addon to learn how to make one.
  4. Then, inside of the addon's config.cpp, there should be an entry for each font you want to add, so that the game knows for what to look. Here is an example of that config.cpp:
    class CfgPatches
    {
    	class TAG_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 as explained below.
    			*/
    			"TAG_Custom_Fonts\Fonts\BebasNeue\BebasNeue10", // the number at the end refers to the size of the font in pt
    			"TAG_Custom_Fonts\Fonts\BebasNeue\BebasNeue11",
    			"TAG_Custom_Fonts\Fonts\BebasNeue\BebasNeue12",
    			"TAG_Custom_Fonts\Fonts\BebasNeue\BebasNeue100" // it can go higher than that, but 100 is pretty big :)
    		};
    	};
    };
    


Config

Each added font requires a class theNameOfTheFont in the class CfgFontFamilies brackets. 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 classname you use will be the exact name that you later will use in the font = "fontName"; property to get that font to appear in UI elements.

The name itself makes no difference as long as it does not conflict with an existing font. Thanks to the creator of the Powershell script (as linked earlier), the config is generated for you. The only thing you need to do is copy it and paste it in the right place.

Fonts Array

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 the game will scale the texture up to the requested size.
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 it is also capable of using provided custom sizes. Using the default values is fine.
If you only want a very specific size of the font, you can use the Powershell script to get that. The script itself tells you how.


Process

  1. Read the instructions for the Powershell script, then execute that script.
  2. 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.
  3. 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.
  4. 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 here.
  5. 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[] =
    {
    	"TAG_Custom_Fonts\Fonts\BebasNeue\BebasNeue10"
    };
    

    The TAG_Custom_Fonts is a reference to the class used inside the addon config.cpp's class CfgPatches.
    In the example above, there should be a folder called Fonts in the same folder as config.cpp.
    Create it if missing, and then take the folder with the font's name (the one inside the FontToTGA.exe's Fonts folder) and put it in there.
    It is up to you if you want to keep or delete the .tga files.
  6. Double-check everything and make sure the config.cpp for your addon has been set right. If so, build it using Addon Builder.
  7. Add it to the launch options of the game. Instructions for that can be found elsewhere.
  8. Start the game, go into the 3DEN editor, open the config viewer, double-click on configFile.
  9. Type CfgFontFamilies. It should scroll the list to where it is.
  10. Double-click it and it should show the font you have added :)
  11. 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!