Difference between revisions of "Font Tutorial"

From Oldunreal-Wiki
Jump to navigation Jump to search
m (Reverted edits by Smirftsch (Talk) to last revision by Skaarj ZR)
 
(20 intermediate revisions by 5 users not shown)
Line 1: Line 1:
=Creating Localized Fonts=
=Creating Fonts=
==Bitmap Fonts==
==Bitmap Fonts==
===Base===
===Creating Custom Font===
Create texture that corresponds Unreal texture rules, it should be size MxN, where M or M  is power of two(2, 4, 8, 16, 32, 64, 128, 256, 512, 1024) and image should be indexed(8-bit color)
Download reference textures (at the bottom of this page) and draw your fonts in order like on MedFont texture.
 
NOTE: empty cells in grid are characters too
 
All chars should be in grid like on reference textures.
Make sure that grid's color is last (255th, if count from zero) color in image palette. Make it light green or something like that, but be sure not to use this color in your font!
First (zero) color in palette is masked color. This color will be transparent in game.
Save file as pcx or bmp
 
====Using in Game====
Export font in your class:
 
#exec Font Import File=Textures\MyFont.pcx Name=MyFont
 
TODO: Write how to draw text
 
===Creating Localized Fonts===
 
First, you need base fonts to make yours.
First, you need base fonts to make yours.


Line 12: Line 31:
NOTE: Grid might be incorrect, report if you find mistake.
NOTE: Grid might be incorrect, report if you find mistake.


===Editing===
====Editing====
You need to explore which position corresponds each character from your charset. And just substitute glyph with your symbol's glyph. But obey order!
You need to explore which position corresponds each character from your charset. And just substitute glyph with your symbol's glyph. But obey order!


===Importing===
====Importing====
Save this text in text file and place it into your System/ directory.
Save this text in text file and place it into your System/ directory.
Remember to change it for your purposes.
Remember to change it for your purposes.


  Font Import File=texture0.pcx PACKAGE="Engine" Name=SmallFont
Font Import File=texture0.pcx PACKAGE="MyFonts" Name=SmallFont
  Font Import File=texture1.pcx PACKAGE="Engine" Name=MedFont
Font Import File=texture1.pcx PACKAGE="MyFonts" Name=MedFont
  Font Import File=texture2.pcx PACKAGE="Engine" Name=LargeFont
Font Import File=texture2.pcx PACKAGE="MyFonts" Name=LargeFont
  Font Import File=texture3.pcx PACKAGE="Engine" Name=BigFont
Font Import File=texture3.pcx PACKAGE="MyFonts" Name=BigFont
  OBJ SAVEPACKAGE PACKAGE="Engine" FILE="Engine.u"
Font Import File=texture7.pcx PACKAGE="MyFonts" Name=WhiteFont
  Font Import File=texture7.pcx PACKAGE="UnrealShare" Name=WhiteFont
OBJ SAVEPACKAGE PACKAGE="MyFonts" FILE="..\Textures\MyFonts.utx"
  OBJ SAVEPACKAGE PACKAGE="UnrealShare" FILE="UnrealShare.u"


When type exec <you_file_name>.txt in UnrealEd to import fonts into Unreal!
When type exec <you_file_name>.txt in UnrealEd to import fonts into Unreal!


===Known Problems===
====Using in game (227g+ only)====
LargeFont(and BigFont?) doesn't work when language is not int.
Find section [Fonts] in your Engine.??t and replace fonts with yours.
 
Importing in that way is incompatible with network game.
I found a way how to use fonts(except WhiteFont) and leave game compatible with net.
 
Workaround:
 
Make new directory in your Unreal folder. Name it MyFonts, for example. Inside this directory make new directories Classes and Textures.
 
Create file MyCanvas.uc in Classes directory.


MyCanvas.uc should contain code like that:<br>
Example:


  class MyCanvas extends Canvas;
[Fonts]
 
WhiteFont=MyFonts.WhiteFont
  #exec Font Import File=Textures\SmallFont.pcx Name=SmallFont
MedFont=MyFonts.MedFont
  #exec Font Import File=Textures\MedFont.pcx  Name=MedFont
LargeFont=MyFonts.LargeFont
  #exec Font Import File=Textures\LargeFont.pcx Name=LargeFont
BigFont=MyFonts.BigFont
  #exec Font Import File=Textures\BigFont.pcx  Name=BigFont
SmallFont=MyFonts.SmallFont
 
  defaultproperties
  {
  Z=1.000000
  Style=1
  DrawColor=(R=127,G=127,B=127)
  SmallFont=Font'MyFonts.SmallFont'
  MedFont=Font'MyFonts.MedFont'
  BigFont=Font'MyFonts.BigFont'
  LargeFont=Font'MyFonts.LargeFont'
  }
Copy your fonts to MyFonts/Textures directory. Note: font files must be named as in #exec block.


Add "EditPackages=MyFonts" line without quotes to [Editor.EditorEngine] block of your Unreal.ini
====Known Problems====
 
Some troubles with font mapping using UTF-16
Do "UCC.exe make" in your Unreal/System directory. Note: Output must not contain any errors or warnings.
 
Then edit [Engine.Engine] block of your Unreal.ini. Change "Canvas=Engine.Canvas" line to "Canvas=MyFonts.MyCanvas"
 
Now your fonts should work in game and you can play online!


==TrueType Fonts==
==TrueType Fonts==
Line 75: Line 67:


===Editing===
===Editing===
Edit fonts in font editor by copying your set of characters to first 255 entries.
Edit fonts in font editor by copying your set of characters to first 255 entries.<br><br>
 
With 227g you can edit the fonts while in editor; type in following command:
OBJ EXPORTFONT NAME="LargeFont"
That will create a folder in Unreal\System\LargeFont\... containing BMP files for all of the font textures used.<br>
Now you can edit the textures the way you want (make sure you do NOT rescale or change offsets of the characters).<br>
Once you're done you can go back to editor and type in following command again:
OBJ IMPORTFONT NAME="LargeFont" FORMAT="bmp"
That will update the font textures from the newly created folder.


TODO: Add Count overview
===Importing===
===Importing===
Use this script to import TrueType fonts to Unreal
Use this script to import TrueType fonts to Unreal
new TrueTypeFontFactory PACKAGE="UWindowFonts" Name=Tahoma10 FontName="Tahoma" Height=10 AntiAlias=0
new TrueTypeFontFactory PACKAGE="UWindowFonts" Name=Tahoma20 FontName="Tahoma" Height=20 AntiAlias=1
new TrueTypeFontFactory PACKAGE="UWindowFonts" Name=Tahoma30 FontName="Tahoma" Height=30 AntiAlias=1 CharactersPerPage=32
new TrueTypeFontFactory PACKAGE="UWindowFonts" Name=TahomaB10 FontName="Tahoma Bold" Height=10 AntiAlias=1
new TrueTypeFontFactory PACKAGE="UWindowFonts" Name=TahomaB20 FontName="Tahoma Bold" Height=20 AntiAlias=1 XPad=2
new TrueTypeFontFactory PACKAGE="UWindowFonts" Name=TahomaB30 FontName="Tahoma Bold" Height=30 AntiAlias=1 CharactersPerPage=32 XPad=2
new TrueTypeFontFactory PACKAGE="UWindowFonts" Name=UTFont12 FontName="Verdana" Height=12 AntiAlias=0
new TrueTypeFontFactory PACKAGE="UWindowFonts" Name=UTFont24 FontName="Arial Narrow" Height=24 AntiAlias=1
new TrueTypeFontFactory PACKAGE="UWindowFonts" Name=UTFont40 FontName="Arial Bold" Height=40 CharactersPerPage=32 AntiAlias=1
new TrueTypeFontFactory PACKAGE="UWindowFonts" Name=RedTahoma10 FontName="Tahoma" Height=10 AntiAlias=0 UseGlyphs=1 R=255 G=0 B=0
OBJ SAVEPACKAGE PACKAGE="UWindowFonts" FILE="..\Textures\UWindowFonts.utx"
* The Package parameter specifies the file font should go to.
* The Name parameter specifies the name of the font.
* 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.
* If AntiAlias is 1, the TTF importer requests an anti-aliased font from Windows with the ANTIALIASED_QUALITY flag to CreateFont().
* 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.
* '''v. 227g/h:''' For colored fonts: R, G and B. Valid values are between 0 and 255.




  new TrueTypeFontFactory PACKAGE="UWindowFonts" Name=Tahoma10 FontName="Tahoma" Height=10 AntiAlias=0
  new TrueTypeFontFactory PACKAGE="UWindowFonts" Name=Tahoma20 FontName="Tahoma" Height=20 AntiAlias=1
  new TrueTypeFontFactory PACKAGE="UWindowFonts" Name=Tahoma30 FontName="Tahoma" Height=30 AntiAlias=1 CharactersPerPage=32
  new TrueTypeFontFactory PACKAGE="UWindowFonts" Name=TahomaB10 FontName="Tahoma Bold" Height=10 AntiAlias=1
  new TrueTypeFontFactory PACKAGE="UWindowFonts" Name=TahomaB20 FontName="Tahoma Bold" Height=20 AntiAlias=1 XPad=2
  new TrueTypeFontFactory PACKAGE="UWindowFonts" Name=TahomaB30 FontName="Tahoma Bold" Height=30 AntiAlias=1 CharactersPerPage=32 XPad=2
  new TrueTypeFontFactory PACKAGE="UWindowFonts" Name=UTFont12 FontName="Verdana" Height=12 AntiAlias=0
  new TrueTypeFontFactory PACKAGE="UWindowFonts" Name=UTFont24 FontName="Arial Narrow" Height=24 AntiAlias=1
  new TrueTypeFontFactory PACKAGE="UWindowFonts" Name=UTFont40 FontName="Arial Bold" Height=40 CharactersPerPage=32 AntiAlias=1
  OBJ SAVEPACKAGE PACKAGE="UWindowFonts" FILE="..\Textures\UWindowFonts.utx"


Save it as text file, launch UnrealEd and write in command field exec <text_file_name>.txt
Save it as text file, launch UnrealEd and write in command field exec <text_file_name>.txt


===Known Problems===
===Known Problems===
Fonts Tahoma and Arial Bold don't import, but succesfully import in Wine.
Fonts Tahoma and Arial Bold don't import on some System, but successfully import in Wine. TTFontImport in 227g should work correctly.
 
==Links==


Links
[http://necrovision.ru/mfiles/unreal/fonts/reference.tar.xz Reference Textures]


[http://unreal.epicgames.com/TTFImport.htm http://unreal.epicgames.com/TTFImport.htm]
[[Epic:True Type Font Import]]
[[Category:UnrealEd]]

Latest revision as of 14:03, 24 April 2012

Creating Fonts

Bitmap Fonts

Creating Custom Font

Create texture that corresponds Unreal texture rules, it should be size MxN, where M or M is power of two(2, 4, 8, 16, 32, 64, 128, 256, 512, 1024) and image should be indexed(8-bit color) Download reference textures (at the bottom of this page) and draw your fonts in order like on MedFont texture.

NOTE: empty cells in grid are characters too

All chars should be in grid like on reference textures. Make sure that grid's color is last (255th, if count from zero) color in image palette. Make it light green or something like that, but be sure not to use this color in your font! First (zero) color in palette is masked color. This color will be transparent in game. Save file as pcx or bmp

Using in Game

Export font in your class:

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

TODO: Write how to draw text

Creating Localized Fonts

First, you need base fonts to make yours.

I created fonts imported from Unreal with grid.

It's SmallFont, MedFont, BigFont, LargeFont and WhiteFont

Download Fonts

NOTE: Grid might be incorrect, report if you find mistake.

Editing

You need to explore which position corresponds each character from your charset. And just substitute glyph with your symbol's glyph. But obey order!

Importing

Save this text in text file and place it into your System/ directory. Remember to change it for your purposes.

Font Import File=texture0.pcx PACKAGE="MyFonts" Name=SmallFont
Font Import File=texture1.pcx PACKAGE="MyFonts" Name=MedFont
Font Import File=texture2.pcx PACKAGE="MyFonts" Name=LargeFont
Font Import File=texture3.pcx PACKAGE="MyFonts" Name=BigFont
Font Import File=texture7.pcx PACKAGE="MyFonts" Name=WhiteFont
OBJ SAVEPACKAGE PACKAGE="MyFonts" FILE="..\Textures\MyFonts.utx"

When type exec <you_file_name>.txt in UnrealEd to import fonts into Unreal!

Using in game (227g+ only)

Find section [Fonts] in your Engine.??t and replace fonts with yours.

Example:

[Fonts]
WhiteFont=MyFonts.WhiteFont
MedFont=MyFonts.MedFont
LargeFont=MyFonts.LargeFont
BigFont=MyFonts.BigFont
SmallFont=MyFonts.SmallFont

Known Problems

Some troubles with font mapping using UTF-16

TrueType Fonts

Base

You can use your system fonts as a base for in-game fonts.

Editing

Edit fonts in font editor by copying your set of characters to first 255 entries.

With 227g you can edit the fonts while in editor; type in following command:

OBJ EXPORTFONT NAME="LargeFont"

That will create a folder in Unreal\System\LargeFont\... containing BMP files for all of the font textures used.
Now you can edit the textures the way you want (make sure you do NOT rescale or change offsets of the characters).
Once you're done you can go back to editor and type in following command again:

OBJ IMPORTFONT NAME="LargeFont" FORMAT="bmp"

That will update the font textures from the newly created folder.

Importing

Use this script to import TrueType fonts to Unreal

new TrueTypeFontFactory PACKAGE="UWindowFonts" Name=Tahoma10 FontName="Tahoma" Height=10 AntiAlias=0
new TrueTypeFontFactory PACKAGE="UWindowFonts" Name=Tahoma20 FontName="Tahoma" Height=20 AntiAlias=1
new TrueTypeFontFactory PACKAGE="UWindowFonts" Name=Tahoma30 FontName="Tahoma" Height=30 AntiAlias=1 CharactersPerPage=32
new TrueTypeFontFactory PACKAGE="UWindowFonts" Name=TahomaB10 FontName="Tahoma Bold" Height=10 AntiAlias=1
new TrueTypeFontFactory PACKAGE="UWindowFonts" Name=TahomaB20 FontName="Tahoma Bold" Height=20 AntiAlias=1 XPad=2
new TrueTypeFontFactory PACKAGE="UWindowFonts" Name=TahomaB30 FontName="Tahoma Bold" Height=30 AntiAlias=1 CharactersPerPage=32 XPad=2
new TrueTypeFontFactory PACKAGE="UWindowFonts" Name=UTFont12 FontName="Verdana" Height=12 AntiAlias=0
new TrueTypeFontFactory PACKAGE="UWindowFonts" Name=UTFont24 FontName="Arial Narrow" Height=24 AntiAlias=1
new TrueTypeFontFactory PACKAGE="UWindowFonts" Name=UTFont40 FontName="Arial Bold" Height=40 CharactersPerPage=32 AntiAlias=1
new TrueTypeFontFactory PACKAGE="UWindowFonts" Name=RedTahoma10 FontName="Tahoma" Height=10 AntiAlias=0 UseGlyphs=1 R=255 G=0 B=0 
OBJ SAVEPACKAGE PACKAGE="UWindowFonts" FILE="..\Textures\UWindowFonts.utx"
  • The Package parameter specifies the file font should go to.
  • The Name parameter specifies the name of the font.
  • 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.
  • If AntiAlias is 1, the TTF importer requests an anti-aliased font from Windows with the ANTIALIASED_QUALITY flag to CreateFont().
  • 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.
  • v. 227g/h: For colored fonts: R, G and B. Valid values are between 0 and 255.


Save it as text file, launch UnrealEd and write in command field exec <text_file_name>.txt

Known Problems

Fonts Tahoma and Arial Bold don't import on some System, but successfully import in Wine. TTFontImport in 227g should work correctly.

Links

Reference Textures

Epic:True Type Font Import