mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-20 22:33:02 +01:00
Use FontConfig to find suitable TrueType fonts on Linux and OS X. Fixes #2537.
This commit is contained in:
@@ -161,6 +161,11 @@ if (UNIX)
|
|||||||
list(APPEND RCT2_SECTIONS "${CMAKE_BINARY_DIR}/openrct2_data_section.o" "${CMAKE_BINARY_DIR}/openrct2_text_section.o")
|
list(APPEND RCT2_SECTIONS "${CMAKE_BINARY_DIR}/openrct2_data_section.o" "${CMAKE_BINARY_DIR}/openrct2_text_section.o")
|
||||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-T,\"${CMAKE_CURRENT_SOURCE_DIR}/distribution/linux/ld_script.xc\"")
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-T,\"${CMAKE_CURRENT_SOURCE_DIR}/distribution/linux/ld_script.xc\"")
|
||||||
endif (APPLE)
|
endif (APPLE)
|
||||||
|
|
||||||
|
# FontConfig for TrueType fonts.
|
||||||
|
find_path(FONTCONFIG_INCLUDE_DIR fontconfig/fontconfig.h)
|
||||||
|
find_library(FONTCONFIG_LIBRARY NAMES fontconfig)
|
||||||
|
TARGET_LINK_LIBRARIES(${PROJECT} ${FONTCONFIG_LIBRARY})
|
||||||
endif (UNIX)
|
endif (UNIX)
|
||||||
|
|
||||||
# install into ${CMAKE_INSTALL_PREFIX}/bin/
|
# install into ${CMAKE_INSTALL_PREFIX}/bin/
|
||||||
|
|||||||
@@ -888,8 +888,11 @@ bool ttf_initialise()
|
|||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
TTFFontDescriptor *fontDesc = &(gCurrentTTFFontSet->size[i]);
|
TTFFontDescriptor *fontDesc = &(gCurrentTTFFontSet->size[i]);
|
||||||
|
|
||||||
utf8 fontPath[MAX_PATH] = "C:\\Windows\\Fonts\\";
|
utf8 fontPath[MAX_PATH];
|
||||||
strcat(fontPath, fontDesc->filename);
|
if (!platform_get_font_path(fontDesc, fontPath)) {
|
||||||
|
log_error("Unable to load font '%s'", fontDesc->font_name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
fontDesc->font = TTF_OpenFont(fontPath, fontDesc->ptSize);
|
fontDesc->font = TTF_OpenFont(fontPath, fontDesc->ptSize);
|
||||||
if (fontDesc->font == NULL) {
|
if (fontDesc->font == NULL) {
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
|
|
||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
|
#include "../drawing/font.h"
|
||||||
|
|
||||||
#ifndef MAX_PATH
|
#ifndef MAX_PATH
|
||||||
#define MAX_PATH 260
|
#define MAX_PATH 260
|
||||||
@@ -161,6 +162,7 @@ uint8 platform_get_locale_currency();
|
|||||||
uint16 platform_get_locale_language();
|
uint16 platform_get_locale_language();
|
||||||
uint8 platform_get_locale_measurement_format();
|
uint8 platform_get_locale_measurement_format();
|
||||||
uint8 platform_get_locale_temperature_format();
|
uint8 platform_get_locale_temperature_format();
|
||||||
|
bool platform_get_font_path(TTFFontDescriptor *font, utf8 *buffer);
|
||||||
|
|
||||||
bool platform_check_steam_overlay_attached();
|
bool platform_check_steam_overlay_attached();
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,7 @@
|
|||||||
#include <fnmatch.h>
|
#include <fnmatch.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include "fontconfig/fontconfig.h"
|
||||||
|
|
||||||
// The name of the mutex used to prevent multiple instances of the game from running
|
// The name of the mutex used to prevent multiple instances of the game from running
|
||||||
#define SINGLE_INSTANCE_MUTEX_NAME "RollerCoaster Tycoon 2_GSKMUTEX"
|
#define SINGLE_INSTANCE_MUTEX_NAME "RollerCoaster Tycoon 2_GSKMUTEX"
|
||||||
@@ -757,4 +758,31 @@ uint8 platform_get_locale_temperature_format(){
|
|||||||
return TEMPERATURE_FORMAT_C;
|
return TEMPERATURE_FORMAT_C;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool platform_get_font_path(TTFFontDescriptor *font, utf8 *buffer)
|
||||||
|
{
|
||||||
|
FcConfig* config = FcInitLoadConfigAndFonts();
|
||||||
|
FcPattern* pat = FcNameParse((const FcChar8*) font->font_name);
|
||||||
|
|
||||||
|
FcConfigSubstitute(config, pat, FcMatchPattern);
|
||||||
|
FcDefaultSubstitute(pat);
|
||||||
|
|
||||||
|
bool found = false;
|
||||||
|
FcResult result = FcResultNoMatch;
|
||||||
|
FcPattern* match = FcFontMatch(config, pat, &result);
|
||||||
|
|
||||||
|
if (match)
|
||||||
|
{
|
||||||
|
FcChar8* filename = NULL;
|
||||||
|
if (FcPatternGetString(match, FC_FILE, 0, &filename) == FcResultMatch)
|
||||||
|
{
|
||||||
|
found = true;
|
||||||
|
strcpy(buffer, (utf8*) filename);
|
||||||
|
}
|
||||||
|
FcPatternDestroy(match);
|
||||||
|
}
|
||||||
|
|
||||||
|
FcPatternDestroy(pat);
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -897,4 +897,12 @@ void platform_get_exe_path(utf8 *outPath)
|
|||||||
_wfullpath(exePath, tempPath, MAX_PATH);
|
_wfullpath(exePath, tempPath, MAX_PATH);
|
||||||
WideCharToMultiByte(CP_UTF8, 0, exePath, countof(exePath), outPath, MAX_PATH, NULL, NULL);
|
WideCharToMultiByte(CP_UTF8, 0, exePath, countof(exePath), outPath, MAX_PATH, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void platform_get_font_path(TTFFontDescriptor *font, utf8 *buffer)
|
||||||
|
{
|
||||||
|
strcpy(buffer, "C:\\Windows\\Fonts\\");
|
||||||
|
strcat(buffer, font->filename);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user