Fonts
by David Everhart · in Torque X 2D · 11/21/2007 (2:55 pm) · 10 replies
I have looked around but dont seem to see much if anything in regards to valid font names. I know in the XNA refresh they have a sprite font you can use, and in the System.Drawing class there is a font class, but the GUITextStyle control seems to want a string like "arial16". I have a custom font which I already put in my data/fonts folder, and wanted to use it.
The documentation shows:
"The font to use for rendering the text. The default engine font is specified in the project TorqueEngineData. When using the default engine font, it is not necessary to provide a relative path or file extension: style.FontType = "arial16"; Other projects may also provide additional fonts. When using fonts other than the default engine font the relative path needs to be provided: style.FontType = "data/fonts/myfont";"
I have tried:
textStyle.FontType = "data/fonts/Exocet"; // This did not work
textStyle.FontType = "Exocet"; // this did not work
I also tried creating a sprite font. Any ideas?
The documentation shows:
"The font to use for rendering the text. The default engine font is specified in the project TorqueEngineData. When using the default engine font, it is not necessary to provide a relative path or file extension: style.FontType = "arial16"; Other projects may also provide additional fonts. When using fonts other than the default engine font the relative path needs to be provided: style.FontType = "data/fonts/myfont";"
I have tried:
textStyle.FontType = "data/fonts/Exocet"; // This did not work
textStyle.FontType = "Exocet"; // this did not work
I also tried creating a sprite font. Any ideas?
#2
11/21/2007 (4:46 pm)
Just tried that Viktor with no success :(
#3
I am doing something similar; I set my font type as follows:
I now get a file not found IO error for the following file data\images\fontTest_font.xml, which of course is not there since I haven't created it. I am not sure what needs to go in this file but I assume some sort of configuration. I don't have pro or else I would look it up in the source. Does anyone have an example of what needs to go in this_font.xml file??
Ves
11/22/2007 (6:28 am)
I am working on trying to get fonts to work as well..I am doing something similar; I set my font type as follows:
textStyle.FontType = @"../../../data/images/fontTest.bmp";
I now get a file not found IO error for the following file data\images\fontTest_font.xml, which of course is not there since I haven't created it. I am not sure what needs to go in this file but I assume some sort of configuration. I don't have pro or else I would look it up in the source. Does anyone have an example of what needs to go in this
Ves
#4
11/22/2007 (8:44 am)
I got that same thing ves, and wonder if it is supposed to be a sprite font. Makes me wonder if there is a torque conversion of some sort for it. Here is a spritefont xml file:<?xml version="1.0" encoding="utf-8"?>
<!--
This file contains an xml description of a font, and will be read by the XNA
Framework Content Pipeline. Follow the comments to customize the appearance
of the font in your game, and to change the characters which are available to draw
with.
-->
<XnaContent xmlns:Graphics="Microsoft.Xna.Framework.Content.Pipeline.Graphics">
<Asset Type="Graphics:FontDescription">
<!--
Modify this string to change the font that will be imported.
-->
<FontName>Exocet</FontName>
<!--
Size is a float value, measured in points. Modify this value to change
the size of the font.
-->
<Size>18</Size>
<!--
Spacing is a float value, measured in pixels. Modify this value to change
the amount of spacing in between characters.
-->
<Spacing>2</Spacing>
<!--
Style controls the style of the font. Valid entries are "Regular", "Bold", "Italic",
and "Bold, Italic", and are case sensitive.
-->
<Style>Regular</Style>
<!--
CharacterRegions control what letters are available in the font. Every
character from Start to End will be built and made available for drawing. The
default range is from 32, (ASCII space), to 126, ('~'), covering the basic Latin
character set. The characters are ordered according to the Unicode standard.
See the documentation for more information.
-->
<CharacterRegions>
<CharacterRegion>
<Start> </Start>
<End>~</End>
</CharacterRegion>
</CharacterRegions>
</Asset>
</XnaContent>
#5
I am still investigating and will post more once I dig more into it and figure out how to add a custom font either at designtime or runtime.
11/22/2007 (5:18 pm)
Well, I went ahead and got a license , and checked out the code. It looks like the fonttype string it is looking for is used to lookup a xml file, generate a garageGames.Torque.GFX.Font and add it to an internal resource list. The font it is looking up is defined in two parts, a png file that contains the font, and a xml file that contains the breakdown of the png (in terms of glyphs, kernpairs, and where the png is). The actual string is used as the name of the two peices, so for arial16, there is arial16.png, and arial16_font.xml. I am still investigating and will post more once I dig more into it and figure out how to add a custom font either at designtime or runtime.
#6
11/22/2007 (5:19 pm)
This is an example of the xml file:<?xml version="1.0" encoding="UTF-8" ?> <font name="arial12" base="15" height="18" face="Arial" size="12"> <bitmaps> <bitmap id="0" name="arial12.png" size="256x256" /> </bitmaps> <glyphs> <glyph ch=" " code="0020" bm="0" origin="0,0" size="0x0" aw="4" lsb="0" /> <-- a ton more glyph, too many to post --> <glyph ch="~" code="007e" bm="0" origin="69,54" size="10x18" aw="9" lsb="0" /> </glyphs> <kernpairs> <kernpair left="1" right="1" adjust="-1" /> <-- a ton more kernpairs, too many to post --> <kernpair left="y" right="." adjust="-1" /> </kernpairs> </font>
#7
http://blogs.msdn.com/garykac/articles/749188.aspx
Once you get it, you just need to put the png and the xml somewhere in your project, and then reference it like:
The two files mine created was Exocet.xml, and Exocet-0.png. I renamed my Exocet.xml to Exocet_Font.xml (I realize now I should have just done it from the utility).The Execet-0 name can be kept as is, it justs need to match what is in the xml file. I put both files in my data/fonts directory. In the properties for each file, I changed the "Copy To Output" to Copy If newer. Hopefully this helps others.
11/22/2007 (10:03 pm)
Ok, I figured it out. I found a utility that converts a system font to a png image and the xml format needed. It is in the XNAextras pack, and allows you to run a command line utility that will generate your files for you. The url to get it is at:http://blogs.msdn.com/garykac/articles/749188.aspx
Once you get it, you just need to put the png and the xml somewhere in your project, and then reference it like:
GUITextStyle textStyle = new GUITextStyle();
textStyle.TextColor = Microsoft.Xna.Framework.Graphics.Color.Blue;
textStyle.FontType = @"data\fonts\Exocet";
textStyle.SizeToText = true;The two files mine created was Exocet.xml, and Exocet-0.png. I renamed my Exocet.xml to Exocet_Font.xml (I realize now I should have just done it from the utility).The Execet-0 name can be kept as is, it justs need to match what is in the xml file. I put both files in my data/fonts directory. In the properties for each file, I changed the "Copy To Output" to Copy If newer. Hopefully this helps others.
#8
I ended up getting a pro license as well (I just can't figure this stuff out without source). I got as far as figuring out the format (from the arialXX;s in buried in the source), took one look and realised there must be a tool out there that generates that xml file. I thought I was on the right track with the XNA fontsample tutorial I downloaded but your XNA resource was really what I needed.
You saved me a good deal of time there.
Ves
11/22/2007 (11:15 pm)
Awesome, thanks David!I ended up getting a pro license as well (I just can't figure this stuff out without source). I got as far as figuring out the format (from the arialXX;s in buried in the source), took one look and realised there must be a tool out there that generates that xml file. I thought I was on the right track with the XNA fontsample tutorial I downloaded but your XNA resource was really what I needed.
You saved me a good deal of time there.
Ves
#9
11/23/2007 (1:52 pm)
Hey np :) Figure while I wait on torque 3d, I will work on my gui since my character itemization technique doesnt seem possible in 2d :( Having the source will make things a lot easier :D
#10
Don't forget to add both files as normal assests in the project (add existing inside XNA studio). And especially the part about setting them to "copy if newer". There is pain to be saved from the wisdom inside this thread ;-)....
Ves
11/23/2007 (2:34 pm)
Just to reiterate,Don't forget to add both files as normal assests in the project (add existing inside XNA studio). And especially the part about setting them to "copy if newer". There is pain to be saved from the wisdom inside this thread ;-)....
Ves
Torque Owner Viktor Rumanuk