Check out our discord at https://discord.gg/3u69jMa 

True-Type Font Importing: Difference between revisions

From SWRC Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 36: Line 36:
<code>#exec new TrueTypeFontFactory Name=Tahoma30 FontName="Tahoma" Height=30 AntiAlias=1 CharactersPerPage=32</code>
<code>#exec new TrueTypeFontFactory Name=Tahoma30 FontName="Tahoma" Height=30 AntiAlias=1 CharactersPerPage=32</code>


 
<pre>
The Name parameter specifies the name of the font.  In this case, I can refer to the font as Font'Tahoma30' from Script.
The Name parameter specifies the name of the font.  In this case, I can refer to the font as Font'Tahoma30' from Script.
The FontName parameter specifies the Windows name of the font to be imported.  For example "Comic Sans MS", "Arial" or "Earth Normal".
The FontName parameter specifies the Windows name of the font to be imported.  For example "Comic Sans MS", "Arial" or "Earth Normal".
The Height parameter is the height of the font in pixels, which I give to Windows' CreateFont() API call.
The Height parameter is the height of the font in pixels, which I give to Windows' CreateFont() API call.
If AntiAlias is 1, the TTF importer requests an anti-aliased font from Windows with the ANTIALIASED_QUALITY flag to CreateFont().  If it is 0, I pass NONANTIALIASED_QUALITY.  See below for limitations of importing fonts with anti-aliasing.
If AntiAlias is 1, the TTF importer requests an anti-aliased font from Windows with the ANTIALIASED_QUALITY flag to CreateFont().  If it is 0, I pass NONANTIALIASED_QUALITY.  See below for limitations of importing fonts with anti-aliasing.
The CharactersPerPage parameter specifies the number of characters per 256x256 pixel font texture.  The default is 64.  The TTF importer will give you an error if it runs out of space when drawing characters on the font pages.  If you get the error "Font vertical size exceeded maximum of 256", you should half the CharactersPerPage parameter.
The CharactersPerPage parameter specifies the number of characters per 256x256 pixel font texture.  The default is 64.  The TTF importer will give you an error if it runs out of space when drawing characters on the font pages.  If you get the error "Font vertical size exceeded maximum of 256", you should half the CharactersPerPage parameter.
Two other parameters - XPad and YPad, add extra space between characters.  These default to 1.  Some fonts require extra space between characters, as Windows doesn't report their actual spacing requirement correctly.
Two other parameters - XPad and YPad, add extra space between characters.  These default to 1.  Some fonts require extra space between characters, as Windows doesn't report their actual spacing requirement correctly.
</pre>


=== Importing Anti-aliased Fonts ===
=== Importing Anti-aliased Fonts ===

Revision as of 02:14, 18 May 2024

Copied from wayback machine, original source long gone!

Original Source: http://unreal.epicgames.com/TTFImport.htm

Wayback: http://web.archive.org/web/20090603183120/unreal.epicgames.com/TTFImport.htm


Jack Porter

Epic Games, Inc.

http://www.epicgames.com/


Audience: Licensees and mod-makers wanting to use Windows true-type fonts in the Unreal engine.

Last Updated: 08/10/99

Introduction

The TTF importer allows you to convert a Windows true-type font of a particular size into an Unreal font which you can then use to draw in-game text. The Unreal engine now has support for rendering anti-aliased fonts, and the TTF importer allows you to import the anti-aliasing from a Windows font.

Unreal has had the ability to import true-type fonts for use in-game since version 224, although there was a bug in the 224 font importer code which meant all the fonts you imported ended up as MS Sans Serif. Be sure you're using Unreal 225f or later, or you may have problems.

Importing Fonts into a .u File

You can import regular Unreal font textures into .u files using a #exec command, which instructs ucc make to import the font as the .u package is created. For example:

#exec Font Import File=Textures\MedFont.pcx Name=MedFont

Once the font is imported, you can refer to it as Font'MedFont' from inside UnrealScript.


To import a TTF, the true-type font first needs to be installed and accessible as a Windows font. If you've got a *.TTF file, you'll have to start by copying the font file into the Fonts control panel. Once this is done, you can import that TTF into a .u file, when ucc make creates the .u package, also by using a #exec command:

#exec new TrueTypeFontFactory Name=Tahoma30 FontName="Tahoma" Height=30 AntiAlias=1 CharactersPerPage=32

The Name parameter specifies the name of the font.  In this case, I can refer to the font as Font'Tahoma30' from Script.
The FontName parameter specifies the Windows name of the font to be imported.   For example "Comic Sans MS", "Arial" or "Earth Normal".
The Height parameter is the height of the font in pixels, which I give to Windows' CreateFont() API call.
If AntiAlias is 1, the TTF importer requests an anti-aliased font from Windows with the ANTIALIASED_QUALITY flag to CreateFont().  If it is 0, I pass NONANTIALIASED_QUALITY.   See below for limitations of importing fonts with anti-aliasing.
The CharactersPerPage parameter specifies the number of characters per 256x256 pixel font texture.  The default is 64.  The TTF importer will give you an error if it runs out of space when drawing characters on the font pages.  If you get the error "Font vertical size exceeded maximum of 256", you should half the CharactersPerPage parameter.
Two other parameters - XPad and YPad, add extra space between characters.  These default to 1.  Some fonts require extra space between characters, as Windows doesn't report their actual spacing requirement correctly.

Importing Anti-aliased Fonts

I've found that Windows only honors the ANTIALIASED_QUALITY parameter to CreateFont() when the following conditions are met:

   Running Windows NT4.  I don't know why.  The ANTIALIASED_QUALITY flag is undocumented.
   Running in 16-bit or 32-bit color depth
   Specifying a Height above a certain size

This last limitation is apparently coded into the TTF file in a table called the GASP Table. I found this program which removes the GASP table from a TTF file, and allows you to request an anti-aliased font at any font size. But with some fonts, the letter i disappears to nothing at small font sizes. Anti-aliasing looks best with large fonts.