I did some experimentations and I have a mostly working TrueType font rendering system for FSO. It uses
NanoVG to render the font which is using
Freetype to process the fonts.
Github branch:
https://github.com/asarium/fs2open.github.com/tree/feature/ttf-nvgTest builds:
http://www.mediafire.com/download/cpie4xe49h28n6p/FSO-TTF.7zExample mod:
http://www.mediafire.com/download/3nymujuxfglnxrj/fontTest.7zWhen could you be interested by this? This patch offers the ability to use
TrueType which is a widely used font standard so you can use any TrueType font you can find for usage in FSO when using this patch. Other reasons why you may want to test this build:
- You want to use more than 5 interface fonts
- You want to have more control over the way the text is drawn
- You want to scale the font to different sizes at run-time
The patch only includes project file updates for Visual Studio 2010 so I would be grateful if somebody could give me an updated version of the project files for earlier versions of MSVS. I also got confirmation that an earlier version of this patch compiled and ran of Linux but it would be great if someone could confirm if this is still the case.
Warning: The patch was created against Antipodes and the test builds are also Antipodes builds
To use TrueType fonts you will first have to move the .ttf file into the data/fonts directory of you mod (create it if it doesn't exist) then you will have to edit the fonts.tbl table or if you don't have one then you can use the newly added -fnt.tbm modular table type.
General table structure:
#Fonts
<font entries>
#End
Old fonts can be specified with "$Font" and the filename of the font file. As the new system can also use names for identifying fonts instead of only indexes you can specify a name using "+Name" and some string value.
Example:
$Font: font01.vf
+Name: Font 1
These fonts also support the "+Top offset" and "+Bottom offset" options which allow to specify a pixel-offset which should be applied before and after a line of text is drawn.
TrueType fonts can be added using the "$TrueType" option:
This option takes a filename of a TrueType font as its argument. Nothing more is needed for a basic setup, every following option is entirely optional.
You can again specify a name for easier identification using "+Name" like with the old fonts, if this option is not present then a name is generated (resulting in a name like "<filename>-<fontsize>"). The name has to be unique!
The next option would be "+Size" where you can specify the point size of this font which is the same as in every text editing program. Default is 8.
You can also specify a top and bottom offset for a TrueType font which can be set with "+Top offset" and "+Bottom offset". This will result in a line like the following:
||+Top offset||
<line of text>
||+Bottom offset||
||+Top offset||
<line of text>
||+Bottom offset||
This can be used to space out the lines of the fonts without having to change the font itself. The value for both options is given in pixels and the default value is zero in both cases.
You can use "+Tab width" to specify the width of tab characters. This width is given in multiples of spaces where 1.0 would be one space character. Default is 1.0.
The next option is
+Letter spacing which can be used to change space between to letters.
+Special Character Font: This can be used to specify an old font file which should be used to draw special characters, you should only specify this if you know that you really need it.
Example:
$TrueType: arial.ttf
+Name: Arial
+Size: 12
I'd also be very happy if someone with better OpenGL knowledge could take a look at the rendering of these fonts as I'm a complete noob when it comes to OpenGL.
The sequence in which the fonts appear is also important. The first three fonts are used by FSO by default for interface rendering.
This patch also removes the fixed limit of a maximum of 5 fonts so you can now have an unlimited number of fonts.
This is a full example of a fnts.tbl file which includes the three default fonts and a TrueType font:
#Fonts
$Font: font01.vf
$Font: font02.vf
$Font: font03.vf
$TrueType: arial.ttf
+Name: Arial
+Size: 12
#End
I tested the patch but there may still be some bugs and/or visual inconsistencies so please test it and report those here.
I also took the liberty to change the "$Font" option in Hud_Gauges.tbl to also accept the name of a font as its value.
Regards,
m!m