summaryrefslogtreecommitdiff
path: root/src/os/macosx/font_osx.cpp
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2021-02-13 23:08:02 +0100
committerMichael Lutz <michi@icosahedron.de>2021-02-14 11:48:58 +0100
commitb66e977acd6790d2e7c26d39f17ac5158b499167 (patch)
treed8f6f5cdb5de974faf34479a623dae614fa1f719 /src/os/macosx/font_osx.cpp
parent6755ff63e168dca62d16f3797a1a9dd5ceba307a (diff)
downloadopenttd-b66e977acd6790d2e7c26d39f17ac5158b499167.tar.xz
Change: [OSX] When auto-detecting a font, try for sans-serif first.
On a display, especially with small fonts or low pixel sizes, sans-serif fonts are usually easier to read than serif fonts.
Diffstat (limited to 'src/os/macosx/font_osx.cpp')
-rw-r--r--src/os/macosx/font_osx.cpp67
1 files changed, 37 insertions, 30 deletions
diff --git a/src/os/macosx/font_osx.cpp b/src/os/macosx/font_osx.cpp
index 4ce2b24e0..0a1b9e99a 100644
--- a/src/os/macosx/font_osx.cpp
+++ b/src/os/macosx/font_osx.cpp
@@ -101,36 +101,43 @@ bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, i
CFAutoRelease<CFArrayRef> descs(CTFontDescriptorCreateMatchingFontDescriptors(lang_desc.get(), mandatory_attribs.get()));
bool result = false;
- for (CFIndex i = 0; descs.get() != nullptr && i < CFArrayGetCount(descs.get()); i++) {
- CTFontDescriptorRef font = (CTFontDescriptorRef)CFArrayGetValueAtIndex(descs.get(), i);
-
- /* Get font traits. */
- CFAutoRelease<CFDictionaryRef> traits((CFDictionaryRef)CTFontDescriptorCopyAttribute(font, kCTFontTraitsAttribute));
- CTFontSymbolicTraits symbolic_traits;
- CFNumberGetValue((CFNumberRef)CFDictionaryGetValue(traits.get(), kCTFontSymbolicTrait), kCFNumberIntType, &symbolic_traits);
-
- /* Skip symbol fonts and vertical fonts. */
- if ((symbolic_traits & kCTFontClassMaskTrait) == (CTFontStylisticClass)kCTFontSymbolicClass || (symbolic_traits & kCTFontVerticalTrait)) continue;
- /* Skip bold fonts (especially Arial Bold, which looks worse than regular Arial). */
- if (symbolic_traits & kCTFontBoldTrait) continue;
- /* Select monospaced fonts if asked for. */
- if (((symbolic_traits & kCTFontMonoSpaceTrait) == kCTFontMonoSpaceTrait) != callback->Monospace()) continue;
-
- /* Get font name. */
- char name[128];
- CFAutoRelease<CFStringRef> font_name((CFStringRef)CTFontDescriptorCopyAttribute(font, kCTFontDisplayNameAttribute));
- CFStringGetCString(font_name.get(), name, lengthof(name), kCFStringEncodingUTF8);
-
- /* There are some special fonts starting with an '.' and the last
- * resort font that aren't usable. Skip them. */
- if (name[0] == '.' || strncmp(name, "LastResort", 10) == 0) continue;
-
- /* Save result. */
- callback->SetFontNames(settings, name);
- if (!callback->FindMissingGlyphs()) {
- DEBUG(freetype, 2, "CT-Font for %s: %s", language_isocode, name);
- result = true;
- break;
+ for (int tries = 0; tries < 2; tries++) {
+ for (CFIndex i = 0; descs.get() != nullptr && i < CFArrayGetCount(descs.get()); i++) {
+ CTFontDescriptorRef font = (CTFontDescriptorRef)CFArrayGetValueAtIndex(descs.get(), i);
+
+ /* Get font traits. */
+ CFAutoRelease<CFDictionaryRef> traits((CFDictionaryRef)CTFontDescriptorCopyAttribute(font, kCTFontTraitsAttribute));
+ CTFontSymbolicTraits symbolic_traits;
+ CFNumberGetValue((CFNumberRef)CFDictionaryGetValue(traits.get(), kCTFontSymbolicTrait), kCFNumberIntType, &symbolic_traits);
+
+ /* Skip symbol fonts and vertical fonts. */
+ if ((symbolic_traits & kCTFontClassMaskTrait) == (CTFontStylisticClass)kCTFontSymbolicClass || (symbolic_traits & kCTFontVerticalTrait)) continue;
+ /* Skip bold fonts (especially Arial Bold, which looks worse than regular Arial). */
+ if (symbolic_traits & kCTFontBoldTrait) continue;
+ /* Select monospaced fonts if asked for. */
+ if (((symbolic_traits & kCTFontMonoSpaceTrait) == kCTFontMonoSpaceTrait) != callback->Monospace()) continue;
+
+ /* Get font name. */
+ char name[128];
+ CFAutoRelease<CFStringRef> font_name((CFStringRef)CTFontDescriptorCopyAttribute(font, kCTFontDisplayNameAttribute));
+ CFStringGetCString(font_name.get(), name, lengthof(name), kCFStringEncodingUTF8);
+
+ /* Serif fonts usually look worse on-screen with only small
+ * font sizes. As such, we try for a sans-serif font first.
+ * If we can't find one in the first try, try all fonts. */
+ if (tries == 0 && (symbolic_traits & kCTFontClassMaskTrait) != (CTFontStylisticClass)kCTFontSansSerifClass) continue;
+
+ /* There are some special fonts starting with an '.' and the last
+ * resort font that aren't usable. Skip them. */
+ if (name[0] == '.' || strncmp(name, "LastResort", 10) == 0) continue;
+
+ /* Save result. */
+ callback->SetFontNames(settings, name);
+ if (!callback->FindMissingGlyphs()) {
+ DEBUG(freetype, 2, "CT-Font for %s: %s", language_isocode, name);
+ result = true;
+ break;
+ }
}
}