summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorplanetmaker <planetmaker@openttd.org>2010-11-15 08:31:07 +0000
committerplanetmaker <planetmaker@openttd.org>2010-11-15 08:31:07 +0000
commitb7d8001202f73fc5cf58791ad66f99b78977154d (patch)
tree61a5acde2bcc985650c17ebe3d195a5e7659e335 /src
parent89592772c3e8a5427c8b1864b72bf3209d115b64 (diff)
downloadopenttd-b7d8001202f73fc5cf58791ad66f99b78977154d.tar.xz
(svn r21197) -Fix [FS#4001] (r17794): [OSX] Finding a fallback font failed when compiling for OSX 10.4 as it tried to match also OpenTTD-specific control characters
Diffstat (limited to 'src')
-rw-r--r--src/fontcache.cpp24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/fontcache.cpp b/src/fontcache.cpp
index 85d9fb9b6..9150141ed 100644
--- a/src/fontcache.cpp
+++ b/src/fontcache.cpp
@@ -46,6 +46,11 @@ static const byte SHADOW_COLOUR = 2;
* Get the font loaded into a Freetype face by using a font-name.
* If no appropiate font is found, the function returns an error
*/
+
+/* ========================================================================================
+ * Windows support
+ * ======================================================================================== */
+
#ifdef WIN32
#include <windows.h>
#include <shlobj.h> /* SHGetFolderPath */
@@ -371,7 +376,10 @@ bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, i
return ret == 0;
}
-#elif defined(__APPLE__)
+#elif defined(__APPLE__) /* end ifdef Win32 */
+/* ========================================================================================
+ * OSX support
+ * ======================================================================================== */
#include "os/macosx/macos.h"
#include <ApplicationServices/ApplicationServices.h>
@@ -497,8 +505,15 @@ bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, i
* ATSUI was deprecated with 10.6 and is only partially available in
* 64-bit mode. */
+ /* Remove all control characters in the range from SCC_CONTROL_START to
+ * SCC_CONTROL_END as well as all ASCII < 0x20 from the string as it will
+ * mess with the automatic font detection */
+ char buff[256]; // This length is enough to find a suitable replacement font
+ strecpy(buff, str, lastof(buff));
+ str_validate(buff, lastof(buff), true, false);
+
/* Extract a UniChar represenation of the sample string. */
- CFStringRef cf_str = CFStringCreateWithCString(kCFAllocatorDefault, str, kCFStringEncodingUTF8);
+ CFStringRef cf_str = CFStringCreateWithCString(kCFAllocatorDefault, buff, kCFStringEncodingUTF8);
if (cf_str == NULL) {
/* Something went wrong. Corrupt/invalid sample string? */
return false;
@@ -592,7 +607,10 @@ bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, i
return result;
}
-#elif defined(WITH_FONTCONFIG)
+#elif defined(WITH_FONTCONFIG) /* end ifdef __APPLE__ */
+/* ========================================================================================
+ * FontConfig (unix) support
+ * ======================================================================================== */
static FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
{
FT_Error err = FT_Err_Cannot_Open_Resource;