Quartz backend on iOS/iPhone

Guido Lorenz <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <[email protected]>
Hi,

I'd like to share a small patch that allowed me to build the Quartz backend for iOS/iPhone. [1]

One part of the patch fixes the configure script which did look for the correct framework (CoreGraphics on iOS, instead of ApplicationServices on Mac OS X), but did not set use_quartz back to "yes" (after the failed search for ApplicationServices set it to "no").

The other part conditionally includes the CoreGraphics header instead of ApplicationServices in cairo-quartz.h. It also disables cairo_quartz_font_face_create_for_atsu_font_id() -- I'm not sure if ATSUI is available on iOS (afaik it is at least deprecated), so using an "ifdef" was the easiest solution.

I have only tested it a little, but it seems to work for me.

Cheers,
Guido

---
[1] These are the environment variables and configure flags I used:

export DEVROOT=/Developer/Platforms/iPhoneOS.platform/Developer
export SDKROOT=$DEVROOT/SDKs/iPhoneOS4.3.sdk
export CFLAGS="-arch armv7 -pipe -no-cpp-precomp -isysroot $SDKROOT -miphoneos-version-min=3.2 -I$SDKROOT/usr/include/"
export CC="$DEVROOT/usr/bin/gcc-4.2"
export LD=$DEVROOT/usr/bin/ld
export AR=$DEVROOT/usr/bin/ar
export AS=$DEVROOT/usr/bin/as
export NM=$DEVROOT/usr/bin/nm
export RANLIB=$DEVROOT/usr/bin/ranlib
export LDFLAGS="-L$SDKROOT/usr/lib/"

./autogen.sh --host=arm-apple-darwin7 --enable-shared=no --enable-xlib=no --enable-xlib-xrender=no --enable-ft=no --enable-fc=no

--
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
0001-Allow-building-the-Quartz-backend-for-iOS-iPhone.patch (application/octet-stream, 2.9 KB)
From fad6f567ec05074571e64698c53cc2c875efee51 Mon Sep 17 00:00:00 2001
From: Guido Lorenz <[email protected]>
Date: Thu, 11 Aug 2011 15:37:01 +0200
Subject: [PATCH] Allow building the Quartz backend for iOS (iPhone)

On iOS, Quartz requires the CoreGraphics framework.
The configure script will now find it correctly and
cairo-quartz.h will include it instead of
ApplicationServices when built for iOS.

I am not sure whether ATSUI is available on iOS, so
I disabled the ATSUI-related function, like when
building 64-bit.
---
 configure.ac            |    4 ++--
 src/cairo-quartz-font.c |    2 +-
 src/cairo-quartz.h      |   10 ++++++++--
 3 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/configure.ac b/configure.ac
index 8e6bc4d..187dc70 100644
--- a/configure.ac
+++ b/configure.ac
@@ -147,10 +147,10 @@ dnl ===========================================================================
 
 CAIRO_ENABLE_SURFACE_BACKEND(quartz, Quartz, auto, [
   dnl There is no pkgconfig for quartz; lets do a header check
-  AC_CHECK_HEADER(ApplicationServices/ApplicationServices.h, , [use_quartz="no (requires ApplicationServices framework)"])
+  AC_CHECK_HEADER(ApplicationServices/ApplicationServices.h, , [use_quartz="no (requires ApplicationServices or CoreGraphics framework)"])
   if test "x$use_quartz" != "xyes" ; then
     dnl check for CoreGraphics as a separate framework
-    AC_CHECK_HEADER(CoreGraphics/CoreGraphics.h, , [use_quartz="no (requires CoreGraphics framework)"])
+    AC_CHECK_HEADER(CoreGraphics/CoreGraphics.h, [use_quartz="yes"], [use_quartz="no (requires ApplicationServices or CoreGraphics framework)"])
     quartz_LIBS="-Xlinker -framework -Xlinker CoreGraphics"
   else
     quartz_LIBS="-Xlinker -framework -Xlinker ApplicationServices"
diff --git a/src/cairo-quartz-font.c b/src/cairo-quartz-font.c
index f529fc9..4574f43 100644
--- a/src/cairo-quartz-font.c
+++ b/src/cairo-quartz-font.c
@@ -802,7 +802,7 @@ _cairo_quartz_scaled_font_get_cg_font_ref (cairo_scaled_font_t *abstract_font)
     return ffont->cgFont;
 }
 
-#ifndef __LP64__
+#if !(defined( __LP64__ ) || TARGET_OS_IPHONE)
 /*
  * compat with old ATSUI backend
  */
diff --git a/src/cairo-quartz.h b/src/cairo-quartz.h
index 8d001c5..97f66ef 100644
--- a/src/cairo-quartz.h
+++ b/src/cairo-quartz.h
@@ -40,7 +40,13 @@
 
 #if CAIRO_HAS_QUARTZ_SURFACE
 
-#include <ApplicationServices/ApplicationServices.h>
+#include "TargetConditionals.h"
+
+#if TARGET_OS_IPHONE
+# include <CoreGraphics/CoreGraphics.h>
+#else
+# include <ApplicationServices/ApplicationServices.h>
+#endif
 
 CAIRO_BEGIN_DECLS
 
@@ -66,7 +72,7 @@ cairo_quartz_surface_get_cg_context (cairo_surface_t *surface);
 cairo_public cairo_font_face_t *
 cairo_quartz_font_face_create_for_cgfont (CGFontRef font);
 
-#ifndef __LP64__
+#if !(defined( __LP64__ ) || TARGET_OS_IPHONE)
 cairo_public cairo_font_face_t *
 cairo_quartz_font_face_create_for_atsu_font_id (ATSUFontID font_id);
 #endif
-- 
1.7.6
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.