MCPcopy Create free account
hub / github.com/OpenBoardView/OpenBoardView / load

Method load

src/openboardview/GUI/Fonts.cpp:19–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17constexpr const float Fonts::MAX_FONT_SIZE;
18
19std::string Fonts::load(std::string customFont) {
20 // Font selection
21 std::deque<std::string> fontList(
22 {"Roboto", "Liberation Sans", "DejaVu Sans", "Arial", "Helvetica", ""}); // Empty string = use system default font
23
24 if (!customFont.empty()) fontList.push_front(customFont);
25
26 ImGuiIO &io = ImGui::GetIO();
27
28 for (const auto &name : fontList) {
29#ifdef _WIN32
30 std::vector<char> ttf = load_font(name);
31
32 ImFontConfig font_cfg{};
33 std::strncpy(font_cfg.Name, name.c_str(), sizeof(font_cfg.Name));
34 font_cfg.Name[sizeof(font_cfg.Name) - 1] = '\0';
35 font_cfg.FontData = ttf.data();
36 font_cfg.FontDataSize = ttf.size();
37 font_cfg.FontDataOwnedByAtlas = false;
38
39 if (!ttf.empty()) {
40 if (io.Fonts->AddFont(&font_cfg) != nullptr) {
41 SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Loaded font: %s", name.c_str());
42 return name;
43 } else {
44 SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Cannot load font %s", name.c_str());
45 }
46 } else {
47 SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Cannot load font %s: not found", name.c_str());
48 }
49#else
50 const std::string fontpath = get_font_path(name);
51 if (fontpath.empty()) {
52 SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Cannot load font %s: not found", name.c_str());
53 continue;
54 }
55 // ImGui handles TrueType and OpenType fonts, exclude anything which has a different ext
56 if (check_fileext(fontpath, ".ttf") || check_fileext(fontpath, ".otf")) {
57 io.Fonts->AddFontFromFileTTF(fontpath.c_str());
58 SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Loaded font: %s, path: %s", name.c_str(), fontpath.c_str());
59 return name;
60 } else {
61 SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Cannot load font %s: file name %s does not have .ttf or .otf extension", name.c_str(), fontpath.c_str());
62 }
63#endif
64 }
65 return {};
66}
67
68std::string Fonts::reload(std::string customFont) {
69 ImGuiIO &io = ImGui::GetIO();

Callers 2

reloadMethod · 0.95
mainFunction · 0.80

Calls 3

load_fontFunction · 0.85
get_font_pathFunction · 0.85
check_fileextFunction · 0.85

Tested by

no test coverage detected