]> granicus.if.org Git - libass/commitdiff
Support Core Text on earlier versions of Mac OS X
authorOleg Oshmyan <chortos@inbox.lv>
Thu, 26 Oct 2017 19:38:49 +0000 (22:38 +0300)
committerOleg Oshmyan <chortos@inbox.lv>
Tue, 31 Oct 2017 12:00:07 +0000 (14:00 +0200)
Loosely based on behdad/harfbuzz@b96af03c20e46105982b3608b608614403540661.

Prefer to link against ApplicationServices to maximize the
portability of binaries built on newer versions of macOS.

The symbol kCTFontURLAttribute, which is checked in this commit, was
introduced in Mac OS X 10.6, the latest of any Core Text symbols that
we use. It is essential to our Core Text font provider, so this is the
earliest version of Mac OS X where we can support this font provider.

The TARGET_OS_IPHONE conditional that this commit adds is necessary to
continue supporting iOS in addition to supporting old Mac OS X. On iOS,
CoreText.h *must* be included to use Core Text, whereas on old Mac OS X,
CoreText.h is not directly accessible and ApplicationServices.h must be
used. On modern macOS, either header works. This conditional is also
used in HarfBuzz.

configure.ac
libass/ass_coretext.c

index 8280beb208685507a68cc7ecd0afddadf7baf739..811533a48a1a4a29eb8232dba62b42a40adfed3e 100644 (file)
@@ -159,24 +159,33 @@ fi
 AM_CONDITIONAL([FONTCONFIG], [test x$fontconfig = xtrue])
 
 if test x$enable_coretext != xno; then
-OLDLIBS="$LIBS"
-# Linking to CoreText directly only works from Mountain Lion and iOS6. In
-# earlier OS releases CoreText was part of the ApplicationServices umbrella
-# framework.
-LIBS="$LIBS -framework CoreText -framework CoreFoundation"
+# Linking to CoreText directly only works from Mountain Lion and iOS.
+# In earlier OS X releases CoreText was part of the ApplicationServices
+# umbrella framework.
 AC_MSG_CHECKING([for CORETEXT])
-AC_LINK_IFELSE([
+AC_COMPILE_IFELSE([
   AC_LANG_PROGRAM(
-    [[#include <CoreText/CoreText.h>]],
-    [[CTFontCreateWithFontDescriptor(NULL, 0.0, NULL);]],)
+    [[#include <ApplicationServices/ApplicationServices.h>]],
+    [[CTFontDescriptorCopyAttribute(NULL, kCTFontURLAttribute);]])
   ], [
-    AC_DEFINE(CONFIG_CORETEXT, 1, [found CoreText in System library])
+    LIBS="$LIBS -framework ApplicationServices -framework CoreFoundation"
+    AC_DEFINE(CONFIG_CORETEXT, 1, [found CoreText in ApplicationServices framework])
     coretext=true
     AC_MSG_RESULT([yes])
   ], [
-    LIBS="$OLDLIBS"
-    coretext=false
-    AC_MSG_RESULT([no])
+    AC_COMPILE_IFELSE([
+      AC_LANG_PROGRAM(
+        [[#include <CoreText/CoreText.h>]],
+        [[CTFontDescriptorCopyAttribute(NULL, kCTFontURLAttribute);]])
+      ], [
+        LIBS="$LIBS -framework CoreText -framework CoreFoundation"
+        AC_DEFINE(CONFIG_CORETEXT, 1, [found CoreText framework])
+        coretext=true
+        AC_MSG_RESULT([yes])
+      ], [
+        coretext=false
+        AC_MSG_RESULT([no])
+      ])
   ])
 fi
 AM_CONDITIONAL([CORETEXT], [test x$coretext = xtrue])
index a52ead589a32718e198aa69e96dcd179d1ccf2e7..661b95c2a952d849b7905cf49b5d4ed530efc01b 100644 (file)
 #include "ass_compat.h"
 
 #include <CoreFoundation/CoreFoundation.h>
+#include <TargetConditionals.h>
+#if TARGET_OS_IPHONE
 #include <CoreText/CoreText.h>
+#else
+#include <ApplicationServices/ApplicationServices.h>
+#endif
 
 #include "ass_coretext.h"