GUI/Fonts/New Fonts

From TDN

Contents

Introduction

This little guide will give you a quick and easy way to add new fonts to your game.



How to use new fonts in Torque

Torque uses Unicode Fonts, which means that it can pretty much take any fonts and use them as long as they are Unicode.

To use a new font for your game, the simplest way to do so is to install the font you would like to use into the windows font folder. You will then need to define a profile that uses your font and hey presto you're in business.

NOTE: The True Type font you use has to have Unicode support.

What happens is the Torque Engine uses the font from your system and then creates a cache file (.utf). It places it in the default font folder (common\ui\cache), and uses this file from this point on. This way you can release a game with a font that the user doesn't have on his/her local machine.


Font Data Structure

The font folder is defined through the defaultProfiles.cs in the common/ui folder. This of course can be overriden by your customprofiles.cs in your mod folder. The line to look for is the following:

// The fonts folder
$Gui::fontCacheDirectory = expandFilename("./font");

By Default, the font folder is defined to common/ui/cache/ - If you wish to change this, you can add the line above into your mod's customprofile.cs.

The next step is to make sure that your game uses the font correctly. If you want the font to act only on a specific area of your GUI, you need to specify a new profile. The profile below will work on the main menu, where the buttons are set to follow the GuiMenuButtonProfile and therefore won't affect the rest of the menu's GUI. Simply changing the font name will cause Torque to load up the font from the defined font folder. Simple expansions of the current profiles can be done using the code below.

// MENU BUTTONS
if(!isObject(GuiMenuButtonProfile)) new GuiControlProfile (GuiMenuButtonProfile)
{
   opaque = true;
   border = true;
   // fontColor = "7 9 169";
   fontColor = "255 255 255";
   fontColorHL = "100 100 100";
   fillColor = "232 232 232 0";
   fixedExtent = true;
   justify = "center";
	canKeyFocus = false;
   border = false;

// font
   fontType = "Libel Suit";
   fontSize = 25;
   fontCharset = CHINESEBIG5;
};

if(!isObject(GuiBorderMenuButtonProfile)) new GuiControlProfile (GuiBorderMenuButtonProfile)
{
   fontColorHL = "0 0 0";
};