diff options
Diffstat (limited to 'src/osd/modules/font/font_osx.cpp')
-rw-r--r-- | src/osd/modules/font/font_osx.cpp | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/src/osd/modules/font/font_osx.cpp b/src/osd/modules/font/font_osx.cpp index 5074c1f4bcd..a020d51ddce 100644 --- a/src/osd/modules/font/font_osx.cpp +++ b/src/osd/modules/font/font_osx.cpp @@ -6,12 +6,12 @@ */ #include "font_module.h" -#include "modules/osdmodule.h" #ifdef SDLMAME_MACOSX -#include "corealloc.h" +#include "emucore.h" #include "fileio.h" +#include "osdcore.h" #include <ApplicationServices/ApplicationServices.h> #include <CoreFoundation/CoreFoundation.h> @@ -54,8 +54,20 @@ private: bool osd_font_osx::open(std::string const &font_path, std::string const &name, int &height) { - osd_printf_verbose("osd_font_osx::open: name=\"%s\"\n", name.c_str()); - CFStringRef const font_name(CFStringCreateWithCString(nullptr, name.c_str(), kCFStringEncodingUTF8)); + osd_printf_verbose("osd_font_osx::open: name=\"%s\"\n", name); + + CFStringRef font_name; + if (name == "default") + { + // Arial Unicode MS comes with Mac OS X 10.5 and later and is the only Mac default font with + // the Unicode characters used by the vgmplay and aristmk5 layouts. + font_name = CFStringCreateWithCString(nullptr, "Arial Unicode MS", kCFStringEncodingUTF8); + } + else + { + font_name = CFStringCreateWithCString(nullptr, name.c_str(), kCFStringEncodingUTF8); + } + if (!font_name) { osd_printf_verbose("osd_font_osx::open: failed to create CFString from font name (invalid UTF-8?)\n"); @@ -73,7 +85,7 @@ bool osd_font_osx::open(std::string const &font_path, std::string const &name, i CFRelease(font_name); if (!font_descriptor) { - osd_printf_verbose("osd_font_osx::open: failed to create CoreText font descriptor for \"%s\"\n", name.c_str()); + osd_printf_verbose("osd_font_osx::open: failed to create CoreText font descriptor for \"%s\"\n", name); return false; } @@ -81,7 +93,7 @@ bool osd_font_osx::open(std::string const &font_path, std::string const &name, i CFRelease(font_descriptor); if (!ct_font) { - osd_printf_verbose("osd_font_osx::open: failed to create CoreText font for \"%s\"\n", name.c_str()); + osd_printf_verbose("osd_font_osx::open: failed to create CoreText font for \"%s\"\n", name); return false; } @@ -141,9 +153,16 @@ bool osd_font_osx::get_bitmap(char32_t chnum, bitmap_argb32 &bitmap, std::int32_ osd_printf_verbose("osd_font_osd::get_bitmap: failed to get glyph for U+%04X\n", unsigned(chnum)); // try to get glyph metrics + #if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100 + CGRect const bounds(CTFontGetBoundingRectsForGlyphs(m_font, kCTFontOrientationHorizontal, &glyph, nullptr, count)); + CGSize advance(CGSizeZero); + CTFontGetAdvancesForGlyphs(m_font, kCTFontOrientationHorizontal, &glyph, &advance, count); + #else CGRect const bounds(CTFontGetBoundingRectsForGlyphs(m_font, kCTFontHorizontalOrientation, &glyph, nullptr, count)); CGSize advance(CGSizeZero); CTFontGetAdvancesForGlyphs(m_font, kCTFontHorizontalOrientation, &glyph, &advance, count); + #endif + // CGNullRect can indicate failure, but it's also a valid rectangle for spaces in some fonts (e.g. Hiragino family) if (CGRectEqualToRect(bounds, CGRectNull) && CGSizeEqualToSize(advance, CGSizeZero)) @@ -171,7 +190,12 @@ bool osd_font_osx::get_bitmap(char32_t chnum, bitmap_argb32 &bitmap, std::int32_ CGContextSetRGBFillColor(context_ref, 1.0, 1.0, 1.0, 1.0); CGContextSetFont(context_ref, font_ref); CGContextSetFontSize(context_ref, POINT_SIZE); + #if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090 + CGPoint pos = CGPointMake(0, 0); + CTFontDrawGlyphs(m_font, &glyph, &pos, 1, context_ref); + #else CGContextShowGlyphs(context_ref, &glyph, count); + #endif CGFontRelease(font_ref); CGContextRelease(context_ref); } @@ -187,7 +211,7 @@ class font_osx : public osd_module, public font_module public: font_osx() : osd_module(OSD_FONT_PROVIDER, "osx"), font_module() { } - virtual int init(const osd_options &options) override { return 0; } + virtual int init(osd_interface &osd, const osd_options &options) override { return 0; } virtual osd_font::ptr font_alloc() override { return std::make_unique<osd_font_osx>(); } virtual bool get_font_families(std::string const &font_path, std::vector<std::pair<std::string, std::string> > &result) override; @@ -218,8 +242,8 @@ private: bool font_osx::get_font_families(std::string const &font_path, std::vector<std::pair<std::string, std::string> > &result) { CFStringRef keys[] = { kCTFontCollectionRemoveDuplicatesOption }; - std::uintptr_t values[ARRAY_LENGTH(keys)] = { 1 }; - CFDictionaryRef const options = CFDictionaryCreate(kCFAllocatorDefault, (void const **)keys, (void const **)values, ARRAY_LENGTH(keys), &kCFTypeDictionaryKeyCallBacks, nullptr); + std::uintptr_t values[std::size(keys)] = { 1 }; + CFDictionaryRef const options = CFDictionaryCreate(kCFAllocatorDefault, (void const **)keys, (void const **)values, std::size(keys), &kCFTypeDictionaryKeyCallBacks, nullptr); CTFontCollectionRef const collection = CTFontCollectionCreateFromAvailableFonts(nullptr); CFRelease(options); if (!collection) return false; |