summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/modules/font
diff options
context:
space:
mode:
author arbee <rb6502@users.noreply.github.com>2020-04-08 22:39:56 -0400
committer arbee <rb6502@users.noreply.github.com>2020-04-08 22:39:56 -0400
commit6a59756b318ffc3e7df1a06d6a0df16e062f8b59 (patch)
treea2f3fcbcc68a0451a2af36dca48403bda0b4bd3e /src/osd/modules/font
parente8b2462f5551b33dc9756a5b211ad31953517ca9 (diff)
Mac: Use Arial Unicode MS as the default font (fixes missing glyphs in many layouts) and fixed deprecation warnings [R. Belmont]
Diffstat (limited to 'src/osd/modules/font')
-rw-r--r--src/osd/modules/font/font_osx.cpp26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/osd/modules/font/font_osx.cpp b/src/osd/modules/font/font_osx.cpp
index e621a715675..c03b8c79fab 100644
--- a/src/osd/modules/font/font_osx.cpp
+++ b/src/osd/modules/font/font_osx.cpp
@@ -55,7 +55,19 @@ 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);
- CFStringRef const font_name(CFStringCreateWithCString(nullptr, name.c_str(), kCFStringEncodingUTF8));
+
+ CFStringRef font_name;
+ if (!strcmp(name.c_str(), "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");
@@ -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 >= __MAC_10_11
+ 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 >= __MAC_10_9
+ 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);
}