* Loads the freetype font. * First try to load the fontname as if it were a path. If that fails, * try to resolve the filename of the font using fontconfig, where the * format is 'font family name' or 'font family name, font style'. * @param fs The font size to load. */
| 227 | * @param fs The font size to load. |
| 228 | */ |
| 229 | std::unique_ptr<FontCache> LoadFont(FontSize fs, FontType fonttype) const override |
| 230 | { |
| 231 | if (fonttype != FontType::TrueType) return nullptr; |
| 232 | |
| 233 | FontCacheSubSetting *settings = GetFontCacheSubSetting(fs); |
| 234 | |
| 235 | std::string font = GetFontCacheFontName(fs); |
| 236 | if (font.empty()) return nullptr; |
| 237 | |
| 238 | if (_ft_library == nullptr) { |
| 239 | if (FT_Init_FreeType(&_ft_library) != FT_Err_Ok) { |
| 240 | ShowInfo("Unable to initialize FreeType, using sprite fonts instead"); |
| 241 | return nullptr; |
| 242 | } |
| 243 | |
| 244 | Debug(fontcache, 2, "Initialized"); |
| 245 | } |
| 246 | |
| 247 | FT_Face face = nullptr; |
| 248 | |
| 249 | /* If font is an absolute path to a ttf, try loading that first. */ |
| 250 | int32_t index = 0; |
| 251 | if (settings->os_handle != nullptr) index = *static_cast<const int32_t *>(settings->os_handle); |
| 252 | FT_Error error = FT_New_Face(_ft_library, font.c_str(), index, &face); |
| 253 | |
| 254 | if (error != FT_Err_Ok) { |
| 255 | /* Check if font is a relative filename in one of our search-paths. */ |
| 256 | std::string full_font = FioFindFullPath(BASE_DIR, font); |
| 257 | if (!full_font.empty()) { |
| 258 | error = FT_New_Face(_ft_library, full_font.c_str(), 0, &face); |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | #ifdef WITH_FONTCONFIG |
| 263 | /* Try loading based on font face name (OS-wide fonts). */ |
| 264 | if (error != FT_Err_Ok) error = GetFontByFaceName(font, &face); |
| 265 | #endif /* WITH_FONTCONFIG */ |
| 266 | |
| 267 | if (error != FT_Err_Ok) { |
| 268 | FT_Done_Face(face); |
| 269 | return nullptr; |
| 270 | } |
| 271 | |
| 272 | return LoadFont(fs, face, font, GetFontCacheFontSize(fs)); |
| 273 | } |
| 274 | |
| 275 | bool FindFallbackFont(struct FontCacheSettings *settings, const std::string &language_isocode, class MissingGlyphSearcher *callback) const override |
| 276 | { |
nothing calls this directly
no test coverage detected