- // Georgia
- if (FT_New_Face(library, "/usr/share/fonts/truetype/msttcorefonts/Georgia.ttf", 0, &face))
- throw std::runtime_error("Face opening failed.");
- if (FT_Set_Char_Size(face, 0, 12 * 64, 96, 96))
- throw std::runtime_error("Size set failed.");
- fonts.push_back(face);
-
- // FreeSerif
- if (FT_New_Face(library, "/usr/share/fonts/truetype/freefont/FreeSerif.ttf", 0, &face)) {
- std::fprintf(stderr, "Warning: Couldn't open FreeSerif, some glyphs might not be available\n");
- } else {
- if (FT_Set_Char_Size(face, 0, 12 * 64, 96, 96))
- throw std::runtime_error("Size set failed.");
- fonts.push_back(face);
- }
-
- // Arial Unicode MS
- if (FT_New_Face(library, "arialuni.ttf", 0, &face)) {
- std::fprintf(stderr, "Warning: Couldn't open Arial Unicode MS, some glyphs might not be available\n");
- } else {
- if (FT_Set_Char_Size(face, 0, 12 * 64, 96, 96))
- throw std::runtime_error("Size set failed.");
- fonts.push_back(face);
+ // Preload all fonts.
+ for (std::map<std::string, std::string>::const_iterator it = config.begin();
+ it != config.end();
+ ++it) {
+ const std::string key = it->first;
+ if (key.size() <= 5 || key.substr(key.size() - 5) != ".font") {
+ continue;
+ }
+
+ std::vector<std::string> font_list = split(it->second, ';');
+ for (unsigned i = 0; i < font_list.size(); ++i) {
+ if (faces.count(font_list[i])) {
+ // Already preloaded.
+ continue;
+ }
+
+ FT_Face face;
+ if (FT_New_Face(library, font_list[i].c_str(), 0, &face)) {
+ fprintf(stderr, "Warning: Couldn't open '%s', some glyphs might not be available\n", font_list[i].c_str());
+ }
+ faces[font_list[i]] = face;
+ }