This commit is contained in:
@@ -1,10 +1,52 @@
|
||||
#include "font.h"
|
||||
#include "font.hpp"
|
||||
|
||||
#include "../log.hpp"
|
||||
|
||||
using namespace game::util;
|
||||
|
||||
namespace game::resource
|
||||
{
|
||||
Font::Font(const std::string& path, float size)
|
||||
Font::Font(const std::filesystem::path& path, float size)
|
||||
{
|
||||
internal = ImGui::GetIO().Fonts->AddFontFromFileTTF(path.c_str(), size);
|
||||
ImFontConfig config;
|
||||
config.FontDataOwnedByAtlas = false;
|
||||
|
||||
internal = ImGui::GetIO().Fonts->AddFontFromFileTTF(path.c_str(), size, &config);
|
||||
|
||||
if (internal)
|
||||
logger.info(std::format("Initialized font: {}", path.c_str()));
|
||||
else
|
||||
logger.error(std::format("Failed to initialize font: {}", path.c_str()));
|
||||
}
|
||||
|
||||
Font::Font(const physfs::Path& path, float size)
|
||||
{
|
||||
if (!path.is_valid())
|
||||
{
|
||||
logger.error(
|
||||
std::format("Failed to initialize font from PhysicsFS path: {} ({})", path.c_str(), physfs::error_get()));
|
||||
return;
|
||||
}
|
||||
|
||||
auto buffer = path.read();
|
||||
|
||||
if (buffer.empty())
|
||||
{
|
||||
logger.error(
|
||||
std::format("Failed to initialize font from PhysicsFS path: {} ({})", path.c_str(), physfs::error_get()));
|
||||
return;
|
||||
}
|
||||
|
||||
ImFontConfig config;
|
||||
config.FontDataOwnedByAtlas = false;
|
||||
|
||||
internal = ImGui::GetIO().Fonts->AddFontFromMemoryTTF(buffer.data(), (int)buffer.size(), size, &config);
|
||||
|
||||
if (internal)
|
||||
logger.info(std::format("Initialized font: {}", path.c_str()));
|
||||
else
|
||||
logger.error(std::format("Failed to initialize font: {}", path.c_str()));
|
||||
}
|
||||
|
||||
ImFont* Font::get() { return internal; };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user