Introduction
LuciadCPillar offers a range of fonts that can be used out of the box. The Fonts
class
documentation lists which ones are available. You can also use that Fonts
class to register new fonts.
After a font has been registered, you can use the font name in the same manner as any of the already available fonts on classes
such as the TextStyle::Builder
.
Choosing between bitmap fonts and vector fonts
It’s typically better to use fonts based on vectors, also known as outline fonts, than bitmap fonts. Vector-based fonts can scale to any desired size and tend to look better too. Bitmap fonts, and their halos, inherently look more pixelated.
Loading vector fonts
You load a new vector font by registering its name and path with Fonts::RegisterFont
.
Loading bitmap fonts
Bitmap fonts rely on a list of bitmaps for each font size. Sometimes, multiple sizes are embedded in a single file. In that case, you can register the font similarly to a vector font.
However, you may also have a file for each size.
If that’s the case, you can use the FontConfig
class to associate multiple
files with one font.
Using bitmap fonts has downsides:
|
When you’re using bitmap fonts in your application, make sure to always use a size supported by your font.
std::string fontName = "Almonte"; std::string bdf16 = "fonts/Almonte-16.bdf"; std::string bdf20 = "fonts/Almonte-20.bdf"; std::string bdf24 = "fonts/Almonte-24.bdf"; auto fontConfig = FontConfig::newBuilder().name(fontName).file(bdf16).file(bdf20).file(bdf24).build(); Fonts::registerFont(fontConfig); //... auto size16 = TextStyle::newBuilder().fontName("Almonte").fontSize(16).build(); auto size24 = TextStyle::newBuilder().fontName("Almonte").fontSize(24).build();