1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-06 06:32:56 +01:00

Use Cocoa APIs for font detection on OS X. Moving FontConfig to Linux platform only.

This commit is contained in:
Aaron van Geffen
2015-12-25 02:52:33 +09:00
parent 8bdec9f68e
commit 474af5c204
3 changed files with 44 additions and 28 deletions

View File

@@ -24,6 +24,7 @@
#include <dlfcn.h>
#include <stdlib.h>
#include "../util/util.h"
#include "fontconfig/fontconfig.h"
// See http://syprog.blogspot.ru/2011/12/listing-loaded-shared-objects-in-linux.html
struct lmap {
@@ -163,4 +164,31 @@ int platform_open_common_file_dialog(int type, utf8 *title, utf8 *filename, utf8
return 0;
}
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

View File

@@ -172,4 +172,20 @@ int platform_open_common_file_dialog(int type, utf8 *title, utf8 *filename, utf8
}
}
bool platform_get_font_path(TTFFontDescriptor *font, utf8 *buffer)
{
@autoreleasepool
{
CTFontDescriptorRef fontRef = CTFontDescriptorCreateWithNameAndSize((CFStringRef)[NSString stringWithUTF8String:font->font_name], 0.0);
CFURLRef url = (CFURLRef)CTFontDescriptorCopyAttribute(fontRef, kCTFontURLAttribute);
if (url) {
NSString *fontPath = [NSString stringWithString:[(NSURL *)CFBridgingRelease(url) path]];
strcpy(buffer, fontPath.UTF8String);
return true;
} else {
return false;
}
}
}
#endif

View File

@@ -37,7 +37,6 @@
#include <fnmatch.h>
#include <locale.h>
#include <time.h>
#include "fontconfig/fontconfig.h"
// The name of the mutex used to prevent multiple instances of the game from running
#define SINGLE_INSTANCE_MUTEX_NAME "RollerCoaster Tycoon 2_GSKMUTEX"
@@ -758,31 +757,4 @@ uint8 platform_get_locale_temperature_format(){
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