Class for loading and manipulating character fonts.
1 // Declare a new font 2 auto font = new Font(); 3 4 // Load it from a file 5 if (!font.loadFromFile("arial.ttf")) 6 { 7 // error... 8 } 9 10 // Create a text which uses our font 11 auto text1 = new Text(); 12 text1.setFont(font); 13 text1.setCharacterSize(30); 14 text1.setStyle(Text.Style.Regular); 15 16 // Create another text using the same font, but with different parameters 17 auto text2 = new Text(); 18 text2.setFont(font); 19 text2.setCharacterSize(50); 20 text2.setStyle(Text.Style.Italic);
$(PARA Apart from loading font files, and passing them to instances of $(TEXT_LINK), you should normally not have to deal directly with this class. However, it may be useful to access the font metrics or rasterized glyphs for advanced usage. Note that if the font is a bitmap font, it is not scalable, thus not all requested sizes will be available to use. This needs to be taken into consideration when using $(TEXT_LINK). If you need to display text of a certain size, make sure the corresponding bitmap font that supports that size is used.)
$(TEXT_LINK)
Fonts can be loaded from a file, from memory or from a custom stream, and supports the most common types of fonts. See the loadFromFile function for the complete list of supported formats.
Once it is loaded, a $(U Font) instance provides three types of information about the font:
$(PARA Fonts alone are not very useful: they hold the font data but cannot make anything useful of it. To do so you need to use the $(TEXT_LINK) class, which is able to properly output text with several options such as character size, style, color, position, rotation, etc. This separation allows more flexibility and better performances: indeed a & $(U Font) is a heavy resource, and any operation on it is slow (often too slow for real-time applications). On the other side, a $(TEXT_LINK) is a lightweight object which can combine the glyphs data and metrics of a $(U Font) to display any text on a render target. Note that it is also possible to bind several $(TEXT_LINK) instances to the same $(U Font). It is important to note that the $(TEXT_LINK) instance doesn't copy the font that it uses, it only keeps a reference to it. Thus, a $(U Font) must not be destructed while it is used by a $(TEXT_LINK).)