MCPcopy Create free account
hub / github.com/arrayfire/forge / loadSystemFont

Method loadSystemFont

src/backend/opengl/font_impl.cpp:344–406  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

342}
343
344void font_impl::loadSystemFont(const char* const pName)
345{
346 std::string ttf_file_path;
347
348#if !defined(OS_WIN)
349 // use fontconfig to get the file
350 FcConfig* config = FcInitLoadConfigAndFonts();
351 if (!config) {
352 FG_ERROR("Fontconfig init failed", FG_ERR_FONTCONFIG_ERROR);
353 }
354 // configure the search pattern,
355 FcPattern* pat = FcNameParse((const FcChar8*)(pName));
356 if (!pat) {
357 FG_ERROR("Fontconfig name parse failed", FG_ERR_FONTCONFIG_ERROR);
358 }
359
360 FcConfigSubstitute(config, pat, FcMatchPattern);
361 FcDefaultSubstitute(pat);
362
363 // find the font
364 FcResult res;
365 FcPattern* font = FcFontMatch(config, pat, &res);
366
367 FcConfigSubstitute(config, pat, FcMatchPattern);
368 if (font) {
369 FcChar8* file = NULL;
370 if (FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch) {
371 // save the file to another std::string
372 ttf_file_path = (char*)file;
373 }
374 FcPatternDestroy(font);
375 }
376 // destroy fontconfig pattern object
377 FcPatternDestroy(pat);
378 // destroy Fc config object
379 FcConfigDestroy(config);
380#else
381 char buf[512];
382 GetWindowsDirectory(buf, 512);
383
384 std::regex fontRegex(std::string(pName), std::regex_constants::egrep | std::regex_constants::icase);
385 std::vector<std::string> fontFiles;
386 std::vector<std::string> matchedFontFiles;
387
388 getFontFilePaths(fontFiles, std::string(buf)+"\\Fonts\\", std::string("ttf"));
389 for (const auto &fontName : fontFiles) {
390 if (std::regex_search(fontName, fontRegex)) {
391 matchedFontFiles.push_back(fontName);
392 }
393 }
394 /* out of all the possible matches, we choose the
395 first possible match for given input font name parameter
396 */
397 if (matchedFontFiles.size()==0)
398 FT_THROW_ERROR("loadSystemFont failed to find the given font name", FG_ERR_FREETYPE_ERROR);
399
400 ttf_file_path = buf;
401 ttf_file_path += "\\Fonts\\";

Callers 2

chart_impl.cppFile · 0.45
window_implMethod · 0.45

Calls 2

getFontFilePathsFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected