Generating and modifying JK2 fonts

Guides and how to's on anything related to JK2, whether it's about modding or in-game topics.
Post Reply
User avatar
fau
Staff
Posts: 404
Joined: 16 Aug 2015, 01:01
Location: Warsaw / Poland
Contact:

Generating and modifying JK2 fonts

Post by fau » 01 Mar 2016, 21:51

Creating new font for your mod

Get this modified version of Font Builder: https://github.com/aufau/fontbuilder/tree/jedi-knight

Compile (on Linux type `qmake && make`) and launch FontBuilder from bin/ directory.
fontbuilder-layout.png
Layout tab
fontbuilder-layout.png (59.6 KiB) Viewed 2730 times
Go to Characters tab and load "jk2-characters.txt" from main fontbuilder directory.

Go to Layout tab and set it like this:
fontbuilder.png
Main window
fontbuilder.png (72.81 KiB) Viewed 2730 times
Go to Output tab, select png image format and "Jedi Knight - fontdat" description format (select "description checkbox"):
fontbuilder-output.png
Output tab
fontbuilder-output.png (65.78 KiB) Viewed 2730 times
Load your chosen font file, set size, find hinting setting you like and click "Write font".

You will get two files with .png and .fontdat extensions. Put them in fonts/ directory of your mod. You can register and use them either in cgame/ui mod, or in .menu files. For examples refer to jk2 sdk cgame/ui source code and main.menu from original assets.

If you wish to support jk2mv's high resolution fonts (coming soon), you will need to generate few more fonts in larger sizes which will together constitute a font face. If you use scales ranging from 1.0 to 1.5, I recommend following steps (just multiply your font size by them and round towards 0):

Code: Select all

1.0 1.5 2.0 3.0 4.0
Example:
Assume you generate a font of size 19, called myfont.png and myfont.fontdat. Next step is to generate the same font with size [1.5 * 19] = 28 and call it myfont_sharp1.png, myfont_sharp1.fontdat. Then goes size 2.0 * 19 = 38, call it myfont_sharp2.png and myfont_sharp2.fontdat etc. Refer to assetsmv.pk3 for an examplary font face.

That's all, not that hard. If for some reason you need to replace existing font like I had to… you're screwed :D Fear not, I will lead you through the struggle laying ahead of you in next section.

Replacing existing font, modifying font data

These two tasks go hand in hand because in order to replace existing font you will surely need to modify font data of newly generated replacement.

First question: what kind of data does .fontdat file contain? A little C program I wrote, which you can find in fontbuilder main directory, will print .fontdat file in human-readable format. You can compile it using following command: `gcc -std=c99 jk2fontdat.c -o jk2fontdat` or with any other C compiler. Run it with .fontdat file as an argument. Example output:

Code: Select all

File: ergoec.fontdat

Global parameters:

mPointSize: 20 mHeight: 22 mAscender: 17 mDescender: 5 mKoreanHack: 0

Glyph parameters:

0x00       Height:   0 Ascent:   0 Descent:   0         Offset:   0 Width:   0 Advance:   0
0x01       Height:   0 Ascent:   0 Descent:   0         Offset:   0 Width:   0 Advance:   0
(…)
0x1f       Height:   0 Ascent:   0 Descent:   0         Offset:   0 Width:   0 Advance:   0
0x20 ' '   Height:   1 Ascent:   0 Descent:   1         Offset:   0 Width:   1 Advance:   6
0x21 '!'   Height:  14 Ascent:  13 Descent:   1         Offset:   1 Width:   4 Advance:   5
0x22 '"'   Height:   4 Ascent:  13 Descent:  -9         Offset:   0 Width:   7 Advance:   6
0x23 '#'   Height:  15 Ascent:  14 Descent:   1         Offset:  -1 Width:  13 Advance:  10
0x24 '$'   Height:  18 Ascent:  15 Descent:   3         Offset:   1 Width:   9 Advance:  10
0x25 '%'   Height:  15 Ascent:  14 Descent:   1         Offset:   0 Width:  15 Advance:  14
0x26 '&'   Height:  14 Ascent:  13 Descent:   1         Offset:   0 Width:  13 Advance:  12
0x27 '''   Height:   4 Ascent:  13 Descent:  -9         Offset:   0 Width:   5 Advance:   3
0x28 '('   Height:  17 Ascent:  13 Descent:   4         Offset:   1 Width:   5 Advance:   6
(…)
Unfortunately when replacing existing font (or generating high resolution versions) you will need to modify some of these values, so your replacement has exactly the same positioning and metrics.

For this task I wrote yet another tool, that is .fontdat editor built into jk2mvmp client. You can download patched jk2mv sources from here: https://github.com/aufau/jk2mv/tree/font-editor and compile them as usual.

Prepare your mod, launch the patched jk2mvmp and find a place where you can see your font on in game. Type /font_select <name> to edit fonts/<name>.fontdat. In order to modify font data use /font_transform command, you'll be able to see it's effects instantly. Here is help text it prints, I hope you can figure out the rest yourself by trial and error:

Code: Select all

  Usage: font_transform [x [y [advance [line-height [baseline ...]
Example: `font_transform 0 -1' lowers font by 1 point.
For more details on these variables' meaning, refer to comments in jk2fontdat.c source code.

When you're done, save changes you've made using font_save command (it won't modify .pk3 archive, but rather write .fontdat file in base/fonts directory).
editing-font.jpg
Transforming font
editing-font.jpg (115.22 KiB) Viewed 2730 times
I highly doubt anyone will ever again need or want to go this far, so let me end this tutorial with this optimistic consideration.

User avatar
ouned
Administrator
Posts: 574
Joined: 23 Feb 2015, 13:03
Location: Gliese581c

Re: Generating and modifying JK2 fonts

Post by ouned » 01 Mar 2016, 23:23

windows binaries in case you don't want to waste your time compiling it.
Attachments
FontBuilder.zip
(17.37 MiB) Downloaded 51 times

User avatar
fau
Staff
Posts: 404
Joined: 16 Aug 2015, 01:01
Location: Warsaw / Poland
Contact:

Re: Generating and modifying JK2 fonts

Post by fau » 02 Mar 2016, 00:59

Amazing, thanks.
I allowed myself to make a release on github and attach your binaries, hope it's ok: https://github.com/aufau/fontbuilder/re ... 2-20160302

User avatar
Boothand
Administrator
Posts: 944
Joined: 24 Feb 2015, 08:21
Contact:

Re: Generating and modifying JK2 fonts

Post by Boothand » 02 Mar 2016, 10:47

Really nice work! I'm sure someone will find this useful. Is this useful for JKA as well? In that case, I'd consider posting it on JKHub too, for the modding community.

Lomtvador
Posts: 2
Joined: 25 May 2017, 19:02

Re: Generating and modifying JK2 fonts

Post by Lomtvador » 25 May 2017, 19:22

Please, help. I'm trying to replace the console font. All fonts that are generated by this program don't work in JK2MV.
1.png
2.png
3.png
4.png
5.png
5.png (4.42 KiB) Viewed 1680 times
Attachments
fonts.pk3
(21.58 KiB) Downloaded 16 times

User avatar
fau
Staff
Posts: 404
Joined: 16 Aug 2015, 01:01
Location: Warsaw / Poland
Contact:

Re: Generating and modifying JK2 fonts

Post by fau » 25 May 2017, 20:55

Console fonts are different. They do not use .fontdat format, but rather a grid of 256 extended ascii characters. I've added a "grid" layout to fontbuilder too later on and but it's not available in ouned's binaries. You'll need to ask someone or compile it on your own for you operating system. It's available here: https://github.com/aufau/fontbuilder/co ... edi-knight

Then you need to select a "grid layout" in fontbulider, add width/32 padding to the right (256/32 = 8px for 256x256 font) and adjust font size. Name such grid font charsgrid_med.tga, pack in a pk3, in gfx/2d/charsgrid_med.tga and you're good to go. See original charsgrid_med.tga to see how it should look.

I may have a look at my fontbuilder patches, and update tutorial with screenshots for console fonts soon.

If you want high resolution console font then it's a bit more complicated, let me know when you succeed with basic 256x256.

edit: Also you can't really use ergoec for console font because it's not a monospace font. Technically you could but it's going to be extremely ugly.

Lomtvador
Posts: 2
Joined: 25 May 2017, 19:02

Re: Generating and modifying JK2 fonts

Post by Lomtvador » 26 May 2017, 09:59

Thanks for the answer. I'd rather stay with the standard fonts.

User avatar
fau
Staff
Posts: 404
Joined: 16 Aug 2015, 01:01
Location: Warsaw / Poland
Contact:

Re: Generating and modifying JK2 fonts

Post by fau » 26 May 2017, 13:13

hahaha, that's a good one :D
Nobody said it would be easy to replace fonts but it's possible. If you have some special request (need a monospace outline font) let me know, I may make one for you.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest

Created by Matti from StylesFactory.pl and Warlords of Draenor (modified by jk2.info)
Powered by phpBB® Forum Software © phpBB Limited
GZIP: On
 

 

cron