Skip to content

Commit

Permalink
Add Font into MacOS bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
dr3mro committed Jun 12, 2024
1 parent c9da17c commit 05305fd
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Sources/Common/CommonApple.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma once

#include <wx/wxprec.h>

#ifndef WX_PRECOMP
Expand All @@ -7,7 +9,7 @@

#include <CoreFoundation/CoreFoundation.h>

wxString getResourcesDirectoryPath() {
inline wxString getResourcesDirectoryPath() {
wxString resourcesPath;
CFBundleRef mainBundle = CFBundleGetMainBundle();
if (mainBundle) {
Expand Down
13 changes: 12 additions & 1 deletion Sources/FontAwesome/FontAwesomeHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,32 @@
#include "Resources/FontAwesome.hpp"

#define FONT_FACE_NAME "Font Awesome 6 Pro Regular"
#define TTF_FILE_NAME "fa_regular_400.ttf"
#define TTF_FILE_NAME "fa-regular-400.ttf"
#define TTF_ARRAY arr_fa_regular_400_ttf

#ifdef __APPLE__
#include "Common/CommonApple.hpp"
#endif

FontAwesomeHandler::FontAwesomeHandler()
{
#ifdef __APPLE__
wxFileName fontFileName(getResourcesDirectoryPath().Append("/Fonts/"), TTF_FILE_NAME);
fontFilePath = fontFileName.GetFullPath();
#else
wxStandardPaths& stdPaths = wxStandardPaths::Get();
wxFileName fontFileName(stdPaths.GetTempDir(), TTF_FILE_NAME);
fontFilePath = fontFileName.GetFullPath();
#endif
}

wxFont FontAwesomeHandler::LoadFontAwesome()
{
#ifndef __APPLE__
if (!DumpFontToTempFile()) {
return wxNullFont;
}
#endif
wxFont font;
if (wxFileExists(fontFilePath) && wxFont::AddPrivateFont(fontFilePath)) {
font = wxFont(14, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxT(FONT_FACE_NAME));
Expand Down
2 changes: 2 additions & 0 deletions Sources/SoundEffects/SoundEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
bool SoundEffects::Play(SoundEffect _sound)
{
#ifdef __APPLE__
(void)_sound;

wxString resourcePath = getResourcesDirectoryPath();

if (resourcePath.empty()) {
Expand Down
7 changes: 6 additions & 1 deletion cmake/MacOs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@ CPMAddPackage(
set(MACOSX_BUNDLE_ICON_FILE ${CMAKE_CURRENT_SOURCE_DIR}/Bundle/icon.icns)
# Set the wns wave file path
set(MACOSX_BUNDLE_WNS_WAV_FILE ${CMAKE_CURRENT_SOURCE_DIR}/Bundle/wns.wav)
# Set the Font Awesome file path
set(MACOSX_BUNDLE_FA_FONT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/Bundle/fa-regular-400.ttf)

# Specify the icon file as a resource
set_source_files_properties(${MACOSX_BUNDLE_ICON_FILE} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")

# Specify the wav file as a resource
set_source_files_properties(${MACOSX_BUNDLE_WNS_WAV_FILE} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")

# Specify the Font Awesome file as a resource
set_source_files_properties(${MACOSX_BUNDLE_FA_FONT_FILE} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources/Fonts")

# Add the source files for your project
add_executable(${Target} MACOSX_BUNDLE ${MACOSX_BUNDLE_ICON_FILE} ${MACOSX_BUNDLE_WNS_WAV_FILE} ${SOURCES})
add_executable(${Target} MACOSX_BUNDLE ${MACOSX_BUNDLE_ICON_FILE} ${MACOSX_BUNDLE_WNS_WAV_FILE} ${MACOSX_BUNDLE_FA_FONT_FILE} ${SOURCES})

# Link wxWidgets to your project
target_link_libraries(${Target} PRIVATE wx::net wx::core wx::base)
Expand Down

0 comments on commit 05305fd

Please sign in to comment.