Skip to content

Commit 0a710f7

Browse files
committed
Make font loading optional
1 parent 50dbc9e commit 0a710f7

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

src/core/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ include(${PROJECT_SOURCE_DIR}/cmake/StaticAnalyzers.cmake)
55
add_library(${NAME} STATIC
66
Core/Log.cpp Core/Log.hpp Core/Debug/Instrumentor.hpp
77
Core/Application.cpp Core/Application.hpp Core/Window.cpp Core/Window.hpp
8-
Core/Resources.hpp Core/DPIHandler.hpp)
8+
Core/Resources.hpp Core/Resources.cpp
9+
Core/DPIHandler.hpp)
910

1011
# Define set of OS specific files to include
1112
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")

src/core/Core/Application.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,13 @@ ExitStatus App::Application::run() {
6666
const float font_size{18.0F * font_scaling_factor};
6767
const std::string font_path{Resources::font_path("Manrope.ttf").generic_string()};
6868

69-
io.Fonts->AddFontFromFileTTF(font_path.c_str(), font_size);
70-
io.FontDefault = io.Fonts->AddFontFromFileTTF(font_path.c_str(), font_size);
69+
if (Resources::exists(font_path)) {
70+
io.Fonts->AddFontFromFileTTF(font_path.c_str(), font_size);
71+
io.FontDefault = io.Fonts->AddFontFromFileTTF(font_path.c_str(), font_size);
72+
} else {
73+
APP_WARN("Could not find font file under: {}", font_path.c_str());
74+
}
75+
7176
DPIHandler::set_global_font_scaling(&io);
7277

7378
// Setup Platform/Renderer backends

src/core/Core/Resources.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include "Core/Resources.hpp"
2+
3+
#include <sys/stat.h>
4+
5+
#include <filesystem>
6+
7+
#include "Core/Debug/Instrumentor.hpp"
8+
9+
namespace App {
10+
11+
bool Resources::exists(const std::filesystem::path& pathname) {
12+
APP_PROFILE_FUNCTION();
13+
14+
struct stat buffer;
15+
return (stat(pathname.generic_string().c_str(), &buffer) == 0);
16+
}
17+
18+
} // namespace App

src/core/Core/Resources.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class Resources {
99
public:
1010
[[nodiscard]] static std::filesystem::path resource_path(const std::filesystem::path& file_path);
1111
[[nodiscard]] static std::filesystem::path font_path(const std::string_view& font_file);
12+
[[nodiscard]] static bool exists(const std::filesystem::path& pathname);
1213
};
1314

1415
} // namespace App

0 commit comments

Comments
 (0)