Jump to content
Official BF Editor Forums
Sign in to follow this  
Harry

Creating your own fonts (ingame only)

Recommended Posts

Font tutorial:

First we select our font we want ingame, here I used the astronaut font.

Not really a good choice since it isnt very handy for small sizes but ok.

Then we make an image out of it. Type all characters the font set needs and make a screendump out of it.

9af965a776068a920f41eefa42c3a0c8.th.png

I think DICE used a generator for this but since I dont have on at hand I used paint. Itll do just fine in this case. Rearrange the characters so you leave ATLEAST one blank line around each char and to make it use the least space as possible. Every bytes counts, altough it seems these days it doesnt really matter anymore, whatever.

Make sure you leave a blank edge to the right and bottom.

Now we have the image, we convert it to .dds. Now note that the dds file doesn NOT have to be a power of 2 each axis since we do not use mipmaps. The NVDXT.EXE tool will complain but continue on happily.

I use my wrapper tool to run NVDXT since the output will stay on the screen w/o much trouble, and its pretty flexible (hint hint). Set Format the -u8888, file to point to your file that has your font as an alpha channel (where the letters are white and the BG is black) and plain white for colorchannels.

Save it as MyFont.dds

99dfd0e94c48125bbb53f4c25a4e75f5.th.png

Now we have the fontimage done, we need to go on to the hard work: translating it to work ingame. BF reads the .dif file first and uses its data to turn the characters in the image into "glyphs". The dif file gives the coordinates of a character and the spacing of the character.

The .dif file consists of 3 main parts:

The header

The glyphs (http://www.thefreedictionary.com/Glyphs)

The kerning (http://www.webopedia.com/TERM/K/kerning.html)

(here I'm using digitalNumbers.dif, this font is very small since it only contains, yes you guessed it, only numbers and 2 other chars)

First the header:

Headers could look like this:

header	<- Tell the engine we define the header

2	<- Absolutely no idea, seems not to affect anything, just leave it at 2 for the time, if anyone figures it out, ill upadte this.

Arial	<- Name of the font. Obviously DICE usead Arial as the template

64	<- Horzontal size of the .dds file

22	<- vertical size of the .dds file (see no power of 2 here)

10	<- Size of cursor/font in pixels. Change the one of the font used in the chat and see what happens.

Glyph sections could look like this:

glyphs	<- Tell the engine were going to define the glyphs     	 

12	<- Tell the engine how many glpyphs were going to define

45	1	7	1	0	48	11	53	21	<- Define a glyph

48	1	7	1	0	32	0	39	10	<- and another one

(...)	<- even more here, i skipped some for readability

58	1	7	1	0	39	11	46	21	<-defining the last one

No lots of numbers in the definitions, but easy once you know what they are. We take the first row as an example

45	1	7	1	0	48	11	53	21

The 45 is the DECIMAL number of the character in the system. 45 DECIMAL is 2D HEXADECIMAL. Look 2D up in the unicode table (like in charmap for example (start->run->charmap)) and you find its a dash. Wooptiedo

1	7	1

define the space taken by the character in pixels horizontally. As long as the sum is equal your good to go (ill test some more later).

The 0 definel the vertical offset of the character in pixels from the top. Handy when dealing with the underscore for example (just to train yourself, the underscore hexadecimal is 5F, what would the value be in the .dif file?).

48	11	53	21

define the location in the .dds file. 48 is the leftmost pixel of the character on the x-axis, 11 is the topmost pixel of the y-axis, 53 the rightmost pixel on the x-axis and 21 the bottom pixel of the y-axis. As you cna sum up here, the glyph would be 5x10 pixels in size.

The kerning section could look like this:

kerning	<- Tell the engine were going to define kerning

1	<-Tell the engine how many kerning combinations were going to make

49	49	-1	<-A kerning combination.

Take this combination for example:

49	49	-1

1st 49 tells what the left character is (a '1' in this case), the 2nd the right character and the -1 the space-offset in pixels. As you can see a 1 next to a 1 is put one pixel back.

Now were going to add our chars into the .dif file. Make your headers like it should be and start adding the glyphs. Take the upperleft corerner for the first coördinate and the pixel BELOW the lowerleft corner for you 2nd coördinate. You need to leave an extra blank edge to the right and bottom of your char for it to work correctly(and you should have that line if you did stuff right in the beginning)

0018081cb24573fd5217ef81f0c8a905.th.png

(notice how I use the coordinates from WTV in the titlebar and I zoomed alot to make it easier)

That concludes the .dif file. Save it as MyFont.dif

Were now ready to implement our little font.

The font will be put in Fonts_client.zip, so put both MyFont.dds and MyFont.dif into the main folder of Fonts_client.zip. Next thing is to change the HUD to display my font. I'll add it to the hud of the M1A2.

Open up menu_server.zip and browse to HUD/HudSetup/Vehicles/ and open HudElementsM1A2Driver.con (change the readonly flag if its set). Lets add that wierd little rangething back.

Remove the beginrem and endrem lines.

Now we will let the textnode point to our little font, so we change

hudBuilder.createTextNode  M1A2Hud M1A2RangeLabel 275 492 101 10

hudBuilder.setTextNodeStyle  Fonts/vehicleHudFont_6.dif 2

hudBuilder.setTextNodeStringVariable	TargetDistanceString

hudBuilder.setNodeColor 	 0 0.8 0 0.9

into

hudBuilder.createTextNode  M1A2Hud M1A2RangeLabel 275 492 101 10

hudBuilder.setTextNodeStyle  Fonts/MyFont.dif 1

hudBuilder.setTextNodeStringVariable	TargetDistanceString

hudBuilder.setNodeColor 	 0 0.8 0 0.9

Change the color of you like but green is good w/ me (this is the reason why it should be white in the .dds file, if it werent some colors would not be available, so never save your file in a color, but plain white).

Now you may wonder why I changed the little 2 into a 1. If DICE made that 2 a 0 it would have been easier to guess: Its an boolean telling if outline should be used or not, and if its not 1, its off (Hooray another one of those common mistakes the programmers made, but like all others it aint bad and goes unnoticed)

Now in this case outlining may not give any effect at all since the rangefinder is located on the black part of the texture surrounding the view of the M1A2.

Open up the .tweak file of the M1A2 to allow us to see the rangefinder. Add this in the weaponhud component if not present of the main barrel weapon:

objectTemplate.weaponHud.hasRangeFinder 1

Done. Start your game in the debugger first if you have it to see if your font is ok. If not, well, you get errors and alot of em*. As soon as you get one and it wont go away click Retry to end the game, or your log file gets all clogged up, being able to take all the harddiskspace you had :P

Heres what my results are:

95476ef78f247fb8ed5a0fc0deb5e8f9.th.png

This is the stuff i came up with. Note the the .dif file has not been setup very carefully, I set spacing for every character to 15, altough it could use some finetuning.

http://desert-conflict.org/harry/MyFont.tga

http://desert-conflict.org/harry/MyFont.dif

http://desert-conflict.org/harry/MyFont.dds

*The only one im aware of at this point is this one:

Module: GameMenu

File: D:DiceCanada_Xpack_PatchCodeBF2MenuGameMenuDifFontRenderer.cpp

Line: 89



Expression: 0

Text: Glyph for Unicode [DECIMAL,0xHEXADECIMAL] does not exist in MyFont font. faceType MyFont   	 



Current confile:

Its telling you the HUD-object wants to show a character which does not exist in the font it uses. Please check the Glyphs section of your .dif file to see if you really have added all the characters you need.

Share this post


Link to post
Share on other sites
Guest

Sweet man, I gotta give that ago.

Oh btw, in the screen shot.... "Range to target" is that only in an American version or somthing? I never get that in-game.

Share this post


Link to post
Share on other sites

2Harry:

I'm going to make small national localization -- I'd like all gamers could write in chat in Russian... There is not EA localization for Russian players...

Could you explain me a bit how to do that? We will be able to build our own fonts and glyfs... BTW, do you know anything about what kind of font table is using in the BF2 -- with Ascii or Unicode?

Is there any other settings to get BF2 to write in Russian? Shall I point somewhere the Russian codepage (1251) ?

Thanks!

Share this post


Link to post
Share on other sites

Yes, thanks... But a bit more details -- what files are responsible for localization and how and what I have to modify in settings to get BF2 displaying the national characters? Except the modified fonts?

Share this post


Link to post
Share on other sites

For the localisation:

In the Registery there is this key that holds the value BF2 will atempt to use as localisation, it is:

[HKEY_LOCAL_MACHINESOFTWAREElectronic ArtsEA GamesBattlefield 2]

"Language"="English"

"Locale"="en_US"

(thats a straight rip the an exported key)

As you cna see the language is english. Now I havent tested it but I suppose that changing it to Russian will allow for localisation, if it werent already. BF2 will now look for the folder "Russian" (be it case sensitive or not, just play safe). I know of some of em: In the sounds folder (common_client.zip) ((french and german ppl are lucky, they have localised sounds, I bet you can do the same w/ russian), in the localisation folder (unzip, main mod folder) and for you: In the Fonts_client.zip.

Now heres the approach:

I _think_ bf first exracts the main contents out of Fonts_client.zip into virtual "Fonts" folder. Then it extracts the folder w/ localised fonts w/ current localisation name (here that would be english) into the same folder. This way unlocalised fonts get overwritten by localised fonts. Make your own "Russian" folder inside Fonts_client.zip and put all fonts in there that need to be overwritten or are needed by ingame. For example, you may want to overwrite both ingameChatFontOutline_8.dif (used by chat when put on the screen) AND ingameChatFontLocalOutline_8.dif (used when typing in the chat). The last font is only to be found in the localised folders and not the main folder. So be sure you atleast include all localised fonts in your Russian folder and only those fonts fro mthe main folder that need to be overwritten. (DigitalNumbers for example can be left like it is, atleast, if the russian characters arent different :P).

Plz do note that if you type with a russian font in the chatbox and it uses a font that supports a previously unknow character (some wierd Russian unicode) but the fotn that shows it after pressing enter doesnt, you can get into problems, so be sure you cover everything in all folders when it comes to typing by people. Standart texts that are static (non-chat) only have to have a font that supports the characters they display.

I think I might have been a little vague here, but I hope you get what I mean. I havent tried it myself, mainly since I only use standart western characters ;)

(oof glad this page was found, I was afraid it got lost at some point :P)

Share this post


Link to post
Share on other sites

For me pictiger was somewhat faster than imageshack, that one caused the red cross on me :P

I guess you had a bad moment, they all work.

(else try "Show image" or whatever it was)

Share this post


Link to post
Share on other sites

You missed out a number in the glyph specification :)

As far as I've worked out, the format is:

ascii glyph_left glyph_width glyph_right yoffset sx sy ex ey

i also wrote a renderer and automatic generation script... :)

bf2_fonts3.png

Share this post


Link to post
Share on other sites

Very nice work [FH]ctz!

So the code for the character should be in ascii code (1-255)? Or unicode?

So far I got the words in chat like "Say squad", "Say Team", "Say All" in Russian... But when I'm trying to type the message in Russian I see nothing! I definitely see English characters from my hand-made font but not Russian ones... And this draw me crazy... LOL.

Do you have any ideas what it could be? :roll:

P.S. Are you from Forgotten Hope guys? Nice to meet you! We periodically get news from your team and some news from Taranov ))

Share this post


Link to post
Share on other sites

the character code is in decimal, and is in unicode -- the default fonts define the “smartquotes” which are unicode for example: 8220 and 8221.

you'll notice in the original bf2 fonts that there are very many fonts, all used for various things. you can work out the font used by looking at the hud console files in menu_client.zip/hud/hudsetup/* -- the commands you're looking for are hudBuilder.setTextNodeStyle.

Share this post


Link to post
Share on other sites
ctz]You missed out a number in the glyph specification :)

As far as I've worked out, the format is:

ascii glyph_left glyph_width glyph_right yoffset sx sy ex ey

Which one did I miss? If you mean the 0, I typed it in instead of making a new code box, since a single 0 in a code box is kinda waste of page-space.

Oh and

glyph_left glyph_width glyph_right

practically all 3 do the same right? That is, move trhe cursor a bit. (If so, God knows why DICE made 3 instead of 1 :P)

Oh and if anyone ever gets to reading this, the bf42 MDT had a font generator too, seems to work nicely

Share this post


Link to post
Share on other sites

Sorry for reviving this thread but I need help here :)

Does anyone have a working font generator?

I tried the BF42 one and this is the result:

schrift.jpg

Any idea what makes the text this wavy?

Share this post


Link to post
Share on other sites

I'm guessing the positions are screwy, the same thing happens to me with the BF1942 Font Generator too.

EDIT: Looks like it'll be that fifth column of numbers. You can pretty much put them as 0 for all, but you'll notice probably the first one is zero, but all the others are all over the show. According to the first post, this is the vertical offset.

Edited by UberWazuSoldier

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×