Add font loading functionality and refactor font handling in core
This commit is contained in:
@@ -16,7 +16,6 @@
|
|||||||
#include "imgui/backends/imgui_impl_sdl2.h"
|
#include "imgui/backends/imgui_impl_sdl2.h"
|
||||||
#include "imgui/backends/imgui_impl_sdlrenderer2.h"
|
#include "imgui/backends/imgui_impl_sdlrenderer2.h"
|
||||||
#include "imgui/imgui.h"
|
#include "imgui/imgui.h"
|
||||||
#include "imgui/imgui_internal.h"
|
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
namespace app {
|
namespace app {
|
||||||
@@ -180,7 +179,7 @@ absl::Status Controller::OnEntry(std::string filename) {
|
|||||||
#else
|
#else
|
||||||
platform_ = Platform::kUnknown;
|
platform_ = Platform::kUnknown;
|
||||||
#endif
|
#endif
|
||||||
RETURN_IF_ERROR(CreateSDL_Window())
|
RETURN_IF_ERROR(CreateWindow())
|
||||||
RETURN_IF_ERROR(CreateRenderer())
|
RETURN_IF_ERROR(CreateRenderer())
|
||||||
RETURN_IF_ERROR(CreateGuiContext())
|
RETURN_IF_ERROR(CreateGuiContext())
|
||||||
RETURN_IF_ERROR(LoadAudioDevice())
|
RETURN_IF_ERROR(LoadAudioDevice())
|
||||||
@@ -264,7 +263,7 @@ void Controller::OnExit() {
|
|||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
absl::Status Controller::CreateSDL_Window() {
|
absl::Status Controller::CreateWindow() {
|
||||||
auto sdl_flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER;
|
auto sdl_flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER;
|
||||||
if (flags()->kUseNewImGuiInput) {
|
if (flags()->kUseNewImGuiInput) {
|
||||||
sdl_flags |= SDL_INIT_GAMECONTROLLER;
|
sdl_flags |= SDL_INIT_GAMECONTROLLER;
|
||||||
@@ -273,25 +272,26 @@ absl::Status Controller::CreateSDL_Window() {
|
|||||||
if (SDL_Init(sdl_flags) != 0) {
|
if (SDL_Init(sdl_flags) != 0) {
|
||||||
return absl::InternalError(
|
return absl::InternalError(
|
||||||
absl::StrFormat("SDL_Init: %s\n", SDL_GetError()));
|
absl::StrFormat("SDL_Init: %s\n", SDL_GetError()));
|
||||||
} else {
|
|
||||||
SDL_DisplayMode displayMode;
|
|
||||||
SDL_GetCurrentDisplayMode(0, &displayMode);
|
|
||||||
int screenWidth = displayMode.w * 0.8;
|
|
||||||
int screenHeight = displayMode.h * 0.8;
|
|
||||||
|
|
||||||
window_ = std::unique_ptr<SDL_Window, core::SDL_Deleter>(
|
|
||||||
SDL_CreateWindow("Yet Another Zelda3 Editor", // window title
|
|
||||||
SDL_WINDOWPOS_UNDEFINED, // initial x position
|
|
||||||
SDL_WINDOWPOS_UNDEFINED, // initial y position
|
|
||||||
screenWidth, // width, in pixels
|
|
||||||
screenHeight, // height, in pixels
|
|
||||||
SDL_WINDOW_RESIZABLE),
|
|
||||||
core::SDL_Deleter());
|
|
||||||
if (window_ == nullptr) {
|
|
||||||
return absl::InternalError(
|
|
||||||
absl::StrFormat("SDL_CreateWindow: %s\n", SDL_GetError()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDL_DisplayMode display_mode;
|
||||||
|
SDL_GetCurrentDisplayMode(0, &display_mode);
|
||||||
|
int screen_width = display_mode.w * 0.8;
|
||||||
|
int screen_height = display_mode.h * 0.8;
|
||||||
|
|
||||||
|
window_ = std::unique_ptr<SDL_Window, core::SDL_Deleter>(
|
||||||
|
SDL_CreateWindow("Yet Another Zelda3 Editor", // window title
|
||||||
|
SDL_WINDOWPOS_UNDEFINED, // initial x position
|
||||||
|
SDL_WINDOWPOS_UNDEFINED, // initial y position
|
||||||
|
screen_width, // width, in pixels
|
||||||
|
screen_height, // height, in pixels
|
||||||
|
SDL_WINDOW_RESIZABLE),
|
||||||
|
core::SDL_Deleter());
|
||||||
|
if (window_ == nullptr) {
|
||||||
|
return absl::InternalError(
|
||||||
|
absl::StrFormat("SDL_CreateWindow: %s\n", SDL_GetError()));
|
||||||
|
}
|
||||||
|
|
||||||
return absl::OkStatus();
|
return absl::OkStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -305,22 +305,17 @@ absl::Status Controller::CreateGuiContext() {
|
|||||||
|
|
||||||
ImGuiIO &io = ImGui::GetIO();
|
ImGuiIO &io = ImGui::GetIO();
|
||||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
||||||
|
|
||||||
if (flags()->kUseNewImGuiInput) {
|
if (flags()->kUseNewImGuiInput) {
|
||||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
|
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize ImGui for SDL
|
// Initialize ImGui based on the backend
|
||||||
ImGui_ImplSDL2_InitForSDLRenderer(window_.get(),
|
ImGui_ImplSDL2_InitForSDLRenderer(window_.get(),
|
||||||
Renderer::GetInstance().renderer());
|
Renderer::GetInstance().renderer());
|
||||||
ImGui_ImplSDLRenderer2_Init(Renderer::GetInstance().renderer());
|
ImGui_ImplSDLRenderer2_Init(Renderer::GetInstance().renderer());
|
||||||
|
|
||||||
// Check if the assets/fonts directory exists in our CWD
|
|
||||||
// Otherwise, load the system fonts.
|
|
||||||
// const auto assets_path = std::filesystem::path("assets");
|
// const auto assets_path = std::filesystem::path("assets");
|
||||||
// if (std::filesystem::is_directory(assets_path)) {
|
|
||||||
RETURN_IF_ERROR(LoadFontFamilies());
|
RETURN_IF_ERROR(LoadFontFamilies());
|
||||||
// } else {
|
|
||||||
// #ifdef __APPLE__
|
// #ifdef __APPLE__
|
||||||
// LoadSystemFonts();
|
// LoadSystemFonts();
|
||||||
// #else
|
// #else
|
||||||
@@ -328,7 +323,6 @@ absl::Status Controller::CreateGuiContext() {
|
|||||||
// "Could not find assets/fonts directory in the current working "
|
// "Could not find assets/fonts directory in the current working "
|
||||||
// "directory");
|
// "directory");
|
||||||
// #endif
|
// #endif
|
||||||
//}
|
|
||||||
|
|
||||||
// Set the default style
|
// Set the default style
|
||||||
gui::ColorsYaze();
|
gui::ColorsYaze();
|
||||||
@@ -340,6 +334,32 @@ absl::Status Controller::CreateGuiContext() {
|
|||||||
return absl::OkStatus();
|
return absl::OkStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
absl::Status Controller::LoadFontFamilies() const {
|
||||||
|
// LoadSystemFonts();
|
||||||
|
return LoadPackageFonts();
|
||||||
|
}
|
||||||
|
|
||||||
|
absl::Status Controller::LoadAudioDevice() {
|
||||||
|
SDL_AudioSpec want, have;
|
||||||
|
SDL_memset(&want, 0, sizeof(want));
|
||||||
|
want.freq = audio_frequency_;
|
||||||
|
want.format = AUDIO_S16;
|
||||||
|
want.channels = 2;
|
||||||
|
want.samples = 2048;
|
||||||
|
want.callback = NULL; // Uses the queue
|
||||||
|
audio_device_ = SDL_OpenAudioDevice(NULL, 0, &want, &have, 0);
|
||||||
|
if (audio_device_ == 0) {
|
||||||
|
return absl::InternalError(
|
||||||
|
absl::StrFormat("Failed to open audio: %s\n", SDL_GetError()));
|
||||||
|
}
|
||||||
|
// audio_buffer_ = new int16_t[audio_frequency_ / 50 * 4];
|
||||||
|
audio_buffer_ = std::make_shared<int16_t>(audio_frequency_ / 50 * 4);
|
||||||
|
SDL_PauseAudioDevice(audio_device_, 0);
|
||||||
|
editor_manager_.emulator().set_audio_buffer(audio_buffer_.get());
|
||||||
|
editor_manager_.emulator().set_audio_device_id(audio_device_);
|
||||||
|
return absl::OkStatus();
|
||||||
|
}
|
||||||
|
|
||||||
absl::Status Controller::LoadConfigFiles() {
|
absl::Status Controller::LoadConfigFiles() {
|
||||||
// Create and load a dotfile for the application
|
// Create and load a dotfile for the application
|
||||||
// This will store the user's preferences and settings
|
// This will store the user's preferences and settings
|
||||||
@@ -368,124 +388,6 @@ absl::Status Controller::LoadConfigFiles() {
|
|||||||
return absl::OkStatus();
|
return absl::OkStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
absl::Status Controller::LoadFontFamilies() const {
|
|
||||||
ImGuiIO &io = ImGui::GetIO();
|
|
||||||
|
|
||||||
static const char *KARLA_REGULAR = "Karla-Regular.ttf";
|
|
||||||
static const char *ROBOTO_MEDIUM = "Roboto-Medium.ttf";
|
|
||||||
static const char *COUSINE_REGULAR = "Cousine-Regular.ttf";
|
|
||||||
static const char *DROID_SANS = "DroidSans.ttf";
|
|
||||||
static const char *NOTO_SANS_JP = "NotoSansJP.ttf";
|
|
||||||
static const char *IBM_PLEX_JP = "IBMPlexSansJP-Bold.ttf";
|
|
||||||
static const float FONT_SIZE_DEFAULT = 16.0f;
|
|
||||||
static const float FONT_SIZE_DROID_SANS = 18.0f;
|
|
||||||
static const float ICON_FONT_SIZE = 18.0f;
|
|
||||||
|
|
||||||
// Icon configuration
|
|
||||||
static const ImWchar icons_ranges[] = {ICON_MIN_MD, 0xf900, 0};
|
|
||||||
ImFontConfig icons_config;
|
|
||||||
icons_config.MergeMode = true;
|
|
||||||
icons_config.GlyphOffset.y = 5.0f;
|
|
||||||
icons_config.GlyphMinAdvanceX = 13.0f;
|
|
||||||
icons_config.PixelSnapH = true;
|
|
||||||
|
|
||||||
// Japanese font configuration
|
|
||||||
ImFontConfig japanese_font_config;
|
|
||||||
japanese_font_config.MergeMode = true;
|
|
||||||
icons_config.GlyphOffset.y = 5.0f;
|
|
||||||
icons_config.GlyphMinAdvanceX = 13.0f;
|
|
||||||
icons_config.PixelSnapH = true;
|
|
||||||
|
|
||||||
// List of fonts to be loaded
|
|
||||||
std::vector<const char *> font_paths = {
|
|
||||||
KARLA_REGULAR, ROBOTO_MEDIUM, COUSINE_REGULAR, IBM_PLEX_JP, DROID_SANS};
|
|
||||||
|
|
||||||
// Load fonts with associated icon and Japanese merges
|
|
||||||
for (const auto &font_path : font_paths) {
|
|
||||||
float font_size =
|
|
||||||
(font_path == DROID_SANS) ? FONT_SIZE_DROID_SANS : FONT_SIZE_DEFAULT;
|
|
||||||
|
|
||||||
std::string actual_font_path;
|
|
||||||
#ifdef __APPLE__
|
|
||||||
#if TARGET_OS_IOS == 1
|
|
||||||
const std::string kBundlePath = GetBundleResourcePath();
|
|
||||||
actual_font_path = kBundlePath + font_path;
|
|
||||||
#else
|
|
||||||
actual_font_path = absl::StrCat(GetBundleResourcePath(),
|
|
||||||
"Contents/Resources/font/", font_path);
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
actual_font_path = std::filesystem::absolute(font_path).string();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!io.Fonts->AddFontFromFileTTF(actual_font_path.data(), font_size)) {
|
|
||||||
return absl::InternalError(
|
|
||||||
absl::StrFormat("Failed to load font from %s", actual_font_path));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Merge icon set
|
|
||||||
std::string actual_icon_font_path = "";
|
|
||||||
const char *icon_font_path = FONT_ICON_FILE_NAME_MD;
|
|
||||||
#if defined(__APPLE__) && defined(__MACH__)
|
|
||||||
#if TARGET_OS_IOS == 1
|
|
||||||
const std::string kIconBundlePath = GetBundleResourcePath();
|
|
||||||
actual_icon_font_path = kIconBundlePath + "MaterialIcons-Regular.ttf";
|
|
||||||
#else
|
|
||||||
actual_icon_font_path =
|
|
||||||
absl::StrCat(GetBundleResourcePath(),
|
|
||||||
"Contents/Resources/font/MaterialIcons-Regular.ttf");
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
actual_icon_font_path = std::filesystem::absolute(icon_font_path).string();
|
|
||||||
#endif
|
|
||||||
io.Fonts->AddFontFromFileTTF(actual_icon_font_path.data(), ICON_FONT_SIZE,
|
|
||||||
&icons_config, icons_ranges);
|
|
||||||
|
|
||||||
// Merge Japanese font
|
|
||||||
std::string actual_japanese_font_path = "";
|
|
||||||
const char *japanese_font_path = NOTO_SANS_JP;
|
|
||||||
#if defined(__APPLE__) && defined(__MACH__)
|
|
||||||
#if TARGET_OS_IOS == 1
|
|
||||||
const std::string kJapaneseBundlePath = GetBundleResourcePath();
|
|
||||||
actual_japanese_font_path = kJapaneseBundlePath + japanese_font_path;
|
|
||||||
#else
|
|
||||||
actual_japanese_font_path =
|
|
||||||
absl::StrCat(GetBundleResourcePath(), "Contents/Resources/font/",
|
|
||||||
japanese_font_path);
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
actual_japanese_font_path =
|
|
||||||
std::filesystem::absolute(japanese_font_path).string();
|
|
||||||
#endif
|
|
||||||
io.Fonts->AddFontFromFileTTF(actual_japanese_font_path.data(), 18.0f,
|
|
||||||
&japanese_font_config,
|
|
||||||
io.Fonts->GetGlyphRangesJapanese());
|
|
||||||
}
|
|
||||||
|
|
||||||
return absl::OkStatus();
|
|
||||||
}
|
|
||||||
|
|
||||||
absl::Status Controller::LoadAudioDevice() {
|
|
||||||
SDL_AudioSpec want, have;
|
|
||||||
SDL_memset(&want, 0, sizeof(want));
|
|
||||||
want.freq = audio_frequency_;
|
|
||||||
want.format = AUDIO_S16;
|
|
||||||
want.channels = 2;
|
|
||||||
want.samples = 2048;
|
|
||||||
want.callback = NULL; // Uses the queue
|
|
||||||
audio_device_ = SDL_OpenAudioDevice(NULL, 0, &want, &have, 0);
|
|
||||||
if (audio_device_ == 0) {
|
|
||||||
return absl::InternalError(
|
|
||||||
absl::StrFormat("Failed to open audio: %s\n", SDL_GetError()));
|
|
||||||
}
|
|
||||||
// audio_buffer_ = new int16_t[audio_frequency_ / 50 * 4];
|
|
||||||
audio_buffer_ = std::make_shared<int16_t>(audio_frequency_ / 50 * 4);
|
|
||||||
SDL_PauseAudioDevice(audio_device_, 0);
|
|
||||||
editor_manager_.emulator().set_audio_buffer(audio_buffer_.get());
|
|
||||||
editor_manager_.emulator().set_audio_device_id(audio_device_);
|
|
||||||
return absl::OkStatus();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace core
|
} // namespace core
|
||||||
} // namespace app
|
} // namespace app
|
||||||
} // namespace yaze
|
} // namespace yaze
|
||||||
|
|||||||
@@ -5,16 +5,15 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "imgui/backends/imgui_impl_sdl2.h"
|
|
||||||
#include "imgui/backends/imgui_impl_sdlrenderer2.h"
|
|
||||||
#include "imgui/imconfig.h"
|
|
||||||
#include "imgui/imgui.h"
|
|
||||||
#include "imgui/imgui_internal.h"
|
|
||||||
#include "absl/status/status.h"
|
#include "absl/status/status.h"
|
||||||
#include "app/core/platform/renderer.h"
|
#include "app/core/platform/renderer.h"
|
||||||
#include "app/core/utils/file_util.h"
|
#include "app/core/utils/file_util.h"
|
||||||
#include "app/editor/editor_manager.h"
|
#include "app/editor/editor_manager.h"
|
||||||
#include "app/editor/utils/editor.h"
|
#include "app/editor/utils/editor.h"
|
||||||
|
#include "imgui/backends/imgui_impl_sdl2.h"
|
||||||
|
#include "imgui/backends/imgui_impl_sdlrenderer2.h"
|
||||||
|
#include "imgui/imconfig.h"
|
||||||
|
#include "imgui/imgui.h"
|
||||||
|
|
||||||
int main(int argc, char **argv);
|
int main(int argc, char **argv);
|
||||||
|
|
||||||
@@ -38,12 +37,12 @@ class Controller : public ExperimentFlags {
|
|||||||
void DoRender() const;
|
void DoRender() const;
|
||||||
void OnExit();
|
void OnExit();
|
||||||
|
|
||||||
absl::Status CreateSDL_Window();
|
absl::Status CreateWindow();
|
||||||
absl::Status CreateRenderer();
|
absl::Status CreateRenderer();
|
||||||
absl::Status CreateGuiContext();
|
absl::Status CreateGuiContext();
|
||||||
absl::Status LoadConfigFiles();
|
|
||||||
absl::Status LoadFontFamilies() const;
|
absl::Status LoadFontFamilies() const;
|
||||||
absl::Status LoadAudioDevice();
|
absl::Status LoadAudioDevice();
|
||||||
|
absl::Status LoadConfigFiles();
|
||||||
|
|
||||||
void SetupScreen(std::string filename = "") {
|
void SetupScreen(std::string filename = "") {
|
||||||
editor_manager_.SetupScreen(filename);
|
editor_manager_.SetupScreen(filename);
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ if(APPLE)
|
|||||||
list(APPEND YAZE_APP_CORE_SRC
|
list(APPEND YAZE_APP_CORE_SRC
|
||||||
app/core/platform/file_dialog.mm
|
app/core/platform/file_dialog.mm
|
||||||
app/core/platform/app_delegate.mm
|
app/core/platform/app_delegate.mm
|
||||||
|
app/core/platform/font_loader.cc
|
||||||
app/core/platform/font_loader.mm
|
app/core/platform/font_loader.mm
|
||||||
app/core/platform/clipboard.mm
|
app/core/platform/clipboard.mm
|
||||||
app/core/platform/file_path.mm
|
app/core/platform/file_path.mm
|
||||||
|
|||||||
@@ -4,17 +4,120 @@
|
|||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "absl/status/status.h"
|
||||||
|
#include "absl/strings/str_cat.h"
|
||||||
#include "absl/strings/str_format.h"
|
#include "absl/strings/str_format.h"
|
||||||
|
#include "app/core/platform/file_path.h"
|
||||||
#include "app/gui/icons.h"
|
#include "app/gui/icons.h"
|
||||||
#include "imgui/imgui.h"
|
#include "imgui/imgui.h"
|
||||||
|
|
||||||
|
namespace yaze {
|
||||||
|
namespace app {
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
absl::Status LoadPackageFonts() {
|
||||||
|
ImGuiIO &io = ImGui::GetIO();
|
||||||
|
|
||||||
|
static const char *KARLA_REGULAR = "Karla-Regular.ttf";
|
||||||
|
static const char *ROBOTO_MEDIUM = "Roboto-Medium.ttf";
|
||||||
|
static const char *COUSINE_REGULAR = "Cousine-Regular.ttf";
|
||||||
|
static const char *DROID_SANS = "DroidSans.ttf";
|
||||||
|
static const char *NOTO_SANS_JP = "NotoSansJP.ttf";
|
||||||
|
static const char *IBM_PLEX_JP = "IBMPlexSansJP-Bold.ttf";
|
||||||
|
static const float FONT_SIZE_DEFAULT = 16.0f;
|
||||||
|
static const float FONT_SIZE_DROID_SANS = 18.0f;
|
||||||
|
static const float ICON_FONT_SIZE = 18.0f;
|
||||||
|
|
||||||
|
// Icon configuration
|
||||||
|
static const ImWchar icons_ranges[] = {ICON_MIN_MD, 0xf900, 0};
|
||||||
|
ImFontConfig icons_config;
|
||||||
|
icons_config.MergeMode = true;
|
||||||
|
icons_config.GlyphOffset.y = 5.0f;
|
||||||
|
icons_config.GlyphMinAdvanceX = 13.0f;
|
||||||
|
icons_config.PixelSnapH = true;
|
||||||
|
|
||||||
|
// Japanese font configuration
|
||||||
|
ImFontConfig japanese_font_config;
|
||||||
|
japanese_font_config.MergeMode = true;
|
||||||
|
icons_config.GlyphOffset.y = 5.0f;
|
||||||
|
icons_config.GlyphMinAdvanceX = 13.0f;
|
||||||
|
icons_config.PixelSnapH = true;
|
||||||
|
|
||||||
|
// List of fonts to be loaded
|
||||||
|
std::vector<const char *> font_paths = {
|
||||||
|
KARLA_REGULAR, ROBOTO_MEDIUM, COUSINE_REGULAR, IBM_PLEX_JP, DROID_SANS};
|
||||||
|
|
||||||
|
// Load fonts with associated icon and Japanese merges
|
||||||
|
for (const auto &font_path : font_paths) {
|
||||||
|
float font_size =
|
||||||
|
(font_path == DROID_SANS) ? FONT_SIZE_DROID_SANS : FONT_SIZE_DEFAULT;
|
||||||
|
|
||||||
|
std::string actual_font_path;
|
||||||
|
#ifdef __APPLE__
|
||||||
|
#if TARGET_OS_IOS == 1
|
||||||
|
const std::string kBundlePath = GetBundleResourcePath();
|
||||||
|
actual_font_path = kBundlePath + font_path;
|
||||||
|
#else
|
||||||
|
actual_font_path = absl::StrCat(GetBundleResourcePath(),
|
||||||
|
"Contents/Resources/font/", font_path);
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
actual_font_path = std::filesystem::absolute(font_path).string();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (!io.Fonts->AddFontFromFileTTF(actual_font_path.data(), font_size)) {
|
||||||
|
return absl::InternalError(
|
||||||
|
absl::StrFormat("Failed to load font from %s", actual_font_path));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Merge icon set
|
||||||
|
std::string actual_icon_font_path = "";
|
||||||
|
const char *icon_font_path = FONT_ICON_FILE_NAME_MD;
|
||||||
|
#if defined(__APPLE__) && defined(__MACH__)
|
||||||
|
#if TARGET_OS_IOS == 1
|
||||||
|
const std::string kIconBundlePath = GetBundleResourcePath();
|
||||||
|
actual_icon_font_path = kIconBundlePath + "MaterialIcons-Regular.ttf";
|
||||||
|
#else
|
||||||
|
actual_icon_font_path =
|
||||||
|
absl::StrCat(GetBundleResourcePath(),
|
||||||
|
"Contents/Resources/font/MaterialIcons-Regular.ttf");
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
actual_icon_font_path = std::filesystem::absolute(icon_font_path).string();
|
||||||
|
#endif
|
||||||
|
io.Fonts->AddFontFromFileTTF(actual_icon_font_path.data(), ICON_FONT_SIZE,
|
||||||
|
&icons_config, icons_ranges);
|
||||||
|
|
||||||
|
// Merge Japanese font
|
||||||
|
std::string actual_japanese_font_path = "";
|
||||||
|
const char *japanese_font_path = NOTO_SANS_JP;
|
||||||
|
#if defined(__APPLE__) && defined(__MACH__)
|
||||||
|
#if TARGET_OS_IOS == 1
|
||||||
|
const std::string kJapaneseBundlePath = GetBundleResourcePath();
|
||||||
|
actual_japanese_font_path = kJapaneseBundlePath + japanese_font_path;
|
||||||
|
#else
|
||||||
|
actual_japanese_font_path =
|
||||||
|
absl::StrCat(GetBundleResourcePath(), "Contents/Resources/font/",
|
||||||
|
japanese_font_path);
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
actual_japanese_font_path =
|
||||||
|
std::filesystem::absolute(japanese_font_path).string();
|
||||||
|
#endif
|
||||||
|
io.Fonts->AddFontFromFileTTF(actual_japanese_font_path.data(), 18.0f,
|
||||||
|
&japanese_font_config,
|
||||||
|
io.Fonts->GetGlyphRangesJapanese());
|
||||||
|
}
|
||||||
|
return absl::OkStatus();
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
|
||||||
int CALLBACK EnumFontFamExProc(const LOGFONT* lpelfe, const TEXTMETRIC* lpntme,
|
int CALLBACK EnumFontFamExProc(const LOGFONT *lpelfe, const TEXTMETRIC *lpntme,
|
||||||
DWORD FontType, LPARAM lParam) {
|
DWORD FontType, LPARAM lParam) {
|
||||||
// Step 3: Load the font into ImGui
|
// Step 3: Load the font into ImGui
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO &io = ImGui::GetIO();
|
||||||
io.Fonts->AddFontFromFileTTF(lpelfe->lfFaceName, 16.0f);
|
io.Fonts->AddFontFromFileTTF(lpelfe->lfFaceName, 16.0f);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@@ -37,8 +140,8 @@ void LoadSystemFonts() {
|
|||||||
RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL, &valueCount,
|
RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL, &valueCount,
|
||||||
&maxValueNameSize, &maxValueDataSize, NULL, NULL);
|
&maxValueNameSize, &maxValueDataSize, NULL, NULL);
|
||||||
|
|
||||||
char* valueName = new char[maxValueNameSize + 1]; // +1 for null terminator
|
char *valueName = new char[maxValueNameSize + 1]; // +1 for null terminator
|
||||||
BYTE* valueData = new BYTE[maxValueDataSize + 1]; // +1 for null terminator
|
BYTE *valueData = new BYTE[maxValueDataSize + 1]; // +1 for null terminator
|
||||||
|
|
||||||
// Enumerate all font entries
|
// Enumerate all font entries
|
||||||
for (DWORD i = 0; i < valueCount; i++) {
|
for (DWORD i = 0; i < valueCount; i++) {
|
||||||
@@ -55,7 +158,7 @@ void LoadSystemFonts() {
|
|||||||
valueData, &valueDataSize) == ERROR_SUCCESS) {
|
valueData, &valueDataSize) == ERROR_SUCCESS) {
|
||||||
if (valueType == REG_SZ) {
|
if (valueType == REG_SZ) {
|
||||||
// Add the font file path to the vector
|
// Add the font file path to the vector
|
||||||
std::string fontPath(reinterpret_cast<char*>(valueData),
|
std::string fontPath(reinterpret_cast<char *>(valueData),
|
||||||
valueDataSize);
|
valueDataSize);
|
||||||
|
|
||||||
fontPaths.push_back(fontPath);
|
fontPaths.push_back(fontPath);
|
||||||
@@ -69,7 +172,7 @@ void LoadSystemFonts() {
|
|||||||
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO &io = ImGui::GetIO();
|
||||||
|
|
||||||
// List of common font face names
|
// List of common font face names
|
||||||
static const std::unordered_set<std::string> commonFontFaceNames = {
|
static const std::unordered_set<std::string> commonFontFaceNames = {
|
||||||
@@ -88,7 +191,7 @@ void LoadSystemFonts() {
|
|||||||
"Tahoma",
|
"Tahoma",
|
||||||
"Lucida Console"};
|
"Lucida Console"};
|
||||||
|
|
||||||
for (auto& fontPath : fontPaths) {
|
for (auto &fontPath : fontPaths) {
|
||||||
// Check if the font path has a "C:\" prefix
|
// Check if the font path has a "C:\" prefix
|
||||||
if (fontPath.substr(0, 2) != "C:") {
|
if (fontPath.substr(0, 2) != "C:") {
|
||||||
// Add "C:\Windows\Fonts\" prefix to the font path
|
// Add "C:\Windows\Fonts\" prefix to the font path
|
||||||
@@ -131,3 +234,7 @@ void LoadSystemFonts() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
} // namespace core
|
||||||
|
} // namespace app
|
||||||
|
} // namespace yaze
|
||||||
@@ -1,6 +1,17 @@
|
|||||||
#ifndef YAZE_APP_CORE_PLATFORM_FONTLOADER_H
|
#ifndef YAZE_APP_CORE_PLATFORM_FONTLOADER_H
|
||||||
#define YAZE_APP_CORE_PLATFORM_FONTLOADER_H
|
#define YAZE_APP_CORE_PLATFORM_FONTLOADER_H
|
||||||
|
|
||||||
void LoadSystemFonts();
|
#include "absl/status/status.h"
|
||||||
|
|
||||||
#endif // YAZE_APP_CORE_PLATFORM_FONTLOADER_H
|
namespace yaze {
|
||||||
|
namespace app {
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
void LoadSystemFonts();
|
||||||
|
absl::Status LoadPackageFonts();
|
||||||
|
|
||||||
|
} // namespace core
|
||||||
|
} // namespace app
|
||||||
|
} // namespace yaze
|
||||||
|
|
||||||
|
#endif // YAZE_APP_CORE_PLATFORM_FONTLOADER_H
|
||||||
|
|||||||
@@ -1,32 +1,20 @@
|
|||||||
// FontLoader.mm
|
|
||||||
#include "app/core/platform/font_loader.h"
|
#include "app/core/platform/font_loader.h"
|
||||||
|
|
||||||
#include "imgui/imgui.h"
|
#import <CoreText/CoreText.h>
|
||||||
|
|
||||||
#include "app/gui/icons.h"
|
|
||||||
|
|
||||||
#if defined(__APPLE__) && defined(__MACH__)
|
|
||||||
/* Apple OSX and iOS (Darwin). */
|
|
||||||
#include <TargetConditionals.h>
|
#include <TargetConditionals.h>
|
||||||
|
|
||||||
#import <CoreText/CoreText.h>
|
#include "app/gui/icons.h"
|
||||||
|
#include "imgui/imgui.h"
|
||||||
|
|
||||||
#if TARGET_IPHONE_SIMULATOR == 1
|
#if TARGET_OS_IPHONE == 1 || TARGET_IPHONE_SIMULATOR == 1
|
||||||
/* iOS in Xcode simulator */
|
|
||||||
void LoadSystemFonts() {}
|
|
||||||
|
|
||||||
#elif TARGET_OS_IPHONE == 1
|
|
||||||
/* iOS */
|
/* iOS */
|
||||||
void LoadSystemFonts() {}
|
void yaze::app::core::LoadSystemFonts() {}
|
||||||
|
|
||||||
#elif TARGET_OS_MAC == 1
|
#elif TARGET_OS_MAC == 1
|
||||||
/* macOS */
|
/* macOS */
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
// MacOS Implementation
|
void yaze::app::core::LoadSystemFonts() {
|
||||||
void LoadSystemFonts() {
|
|
||||||
// List of common macOS system fonts
|
|
||||||
NSArray *fontNames = @[ @"Helvetica", @"Times New Roman", @"Courier", @"Arial", @"Verdana" ];
|
NSArray *fontNames = @[ @"Helvetica", @"Times New Roman", @"Courier", @"Arial", @"Verdana" ];
|
||||||
|
|
||||||
for (NSString *fontName in fontNames) {
|
for (NSString *fontName in fontNames) {
|
||||||
@@ -67,8 +55,5 @@ void LoadSystemFonts() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
// Unsupported platform
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user