bug 1171117 - Fix cairo to build on iOS. r=jrmuizel
authorTed Mielczarek <ted@mielczarek.org>
Wed, 11 Feb 2015 15:13:24 -0500
changeset 248701 beb4dcffcc0f1690cd9a4129b8836919ee2c7986
parent 248700 63a19a690fea4feaaeb6fcdd597eb975539bc224
child 248702 fd35f12f37d63e8f149f6107593343b18eea188d
push id61045
push usertmielczarek@mozilla.com
push dateSat, 13 Jun 2015 19:03:28 +0000
treeherdermozilla-inbound@9fa312e065e1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1171117
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 1171117 - Fix cairo to build on iOS. r=jrmuizel Cherry-pick cairo upstream rev 70cc8f250b5669e757b4f044571ba0f71e3dea9e and add CoreText include for iOS
gfx/cairo/cairo/src/cairo-quartz-font.c
gfx/cairo/cairo/src/cairo-quartz-image.h
gfx/cairo/cairo/src/cairo-quartz-surface.c
gfx/cairo/cairo/src/cairo-quartz.h
gfx/cairo/cairo/src/moz.build
--- a/gfx/cairo/cairo/src/cairo-quartz-font.c
+++ b/gfx/cairo/cairo/src/cairo-quartz-font.c
@@ -71,19 +71,16 @@ static bool (*CGFontGetGlyphAdvancesPtr)
 static bool (*CGFontGetGlyphBBoxesPtr) (CGFontRef, const CGGlyph[], size_t, CGRect[]) = NULL;
 static CGRect (*CGFontGetFontBBoxPtr) (CGFontRef) = NULL;
 
 /* Not public, but present */
 static void (*CGFontGetGlyphsForUnicharsPtr) (CGFontRef, const UniChar[], const CGGlyph[], size_t) = NULL;
 static void (*CGContextSetAllowsFontSmoothingPtr) (CGContextRef, bool) = NULL;
 static bool (*CGContextGetAllowsFontSmoothingPtr) (CGContextRef) = NULL;
 
-/* Not public in the least bit */
-static CGPathRef (*CGFontGetGlyphPathPtr) (CGFontRef fontRef, CGAffineTransform *textTransform, int unknown, CGGlyph glyph) = NULL;
-
 /* CGFontGetHMetrics isn't public, but the other functions are public/present in 10.5 */
 typedef struct {
     int ascent;
     int descent;
     int leading;
 } quartz_CGFontMetrics;
 static quartz_CGFontMetrics* (*CGFontGetHMetricsPtr) (CGFontRef fontRef) = NULL;
 static int (*CGFontGetAscentPtr) (CGFontRef fontRef) = NULL;
@@ -116,34 +113,32 @@ quartz_font_ensure_symbols(void)
 
     /* We just need one of these two */
     CGFontCreateWithFontNamePtr = dlsym(RTLD_DEFAULT, "CGFontCreateWithFontName");
     CGFontCreateWithNamePtr = dlsym(RTLD_DEFAULT, "CGFontCreateWithName");
 
     /* These have the same name in 10.4 and 10.5 */
     CGFontGetUnitsPerEmPtr = dlsym(RTLD_DEFAULT, "CGFontGetUnitsPerEm");
     CGFontGetGlyphAdvancesPtr = dlsym(RTLD_DEFAULT, "CGFontGetGlyphAdvances");
-    CGFontGetGlyphPathPtr = dlsym(RTLD_DEFAULT, "CGFontGetGlyphPath");
 
     CGFontGetHMetricsPtr = dlsym(RTLD_DEFAULT, "CGFontGetHMetrics");
     CGFontGetAscentPtr = dlsym(RTLD_DEFAULT, "CGFontGetAscent");
     CGFontGetDescentPtr = dlsym(RTLD_DEFAULT, "CGFontGetDescent");
     CGFontGetLeadingPtr = dlsym(RTLD_DEFAULT, "CGFontGetLeading");
 
     CGContextGetAllowsFontSmoothingPtr = dlsym(RTLD_DEFAULT, "CGContextGetAllowsFontSmoothing");
     CGContextSetAllowsFontSmoothingPtr = dlsym(RTLD_DEFAULT, "CGContextSetAllowsFontSmoothing");
 
     CTFontCreateWithGraphicsFontPtr = dlsym(RTLD_DEFAULT, "CTFontCreateWithGraphicsFont");
 
     if ((CGFontCreateWithFontNamePtr || CGFontCreateWithNamePtr) &&
 	CGFontGetGlyphBBoxesPtr &&
 	CGFontGetGlyphsForUnicharsPtr &&
 	CGFontGetUnitsPerEmPtr &&
 	CGFontGetGlyphAdvancesPtr &&
-	CGFontGetGlyphPathPtr &&
 	(CGFontGetHMetricsPtr || (CGFontGetAscentPtr && CGFontGetDescentPtr && CGFontGetLeadingPtr)))
 	_cairo_quartz_font_symbols_present = TRUE;
 
     _cairo_quartz_font_symbol_lookup_done = TRUE;
 }
 
 typedef struct _cairo_quartz_font_face cairo_quartz_font_face_t;
 typedef struct _cairo_quartz_scaled_font cairo_quartz_scaled_font_t;
@@ -555,31 +550,34 @@ static void
 static cairo_int_status_t
 _cairo_quartz_init_glyph_path (cairo_quartz_scaled_font_t *font,
 			       cairo_scaled_glyph_t *scaled_glyph)
 {
     cairo_quartz_font_face_t *font_face = _cairo_quartz_scaled_to_face(font);
     CGGlyph glyph = _cairo_quartz_scaled_glyph_index (scaled_glyph);
     CGAffineTransform textMatrix;
     CGPathRef glyphPath;
+    CTFontRef ctFont;
     cairo_path_fixed_t *path;
 
     if (glyph == INVALID_GLYPH) {
 	_cairo_scaled_glyph_set_path (scaled_glyph, &font->base, _cairo_path_fixed_create());
 	return CAIRO_STATUS_SUCCESS;
     }
 
     /* scale(1,-1) * font->base.scale */
     textMatrix = CGAffineTransformMake (font->base.scale.xx,
 					font->base.scale.yx,
 					-font->base.scale.xy,
 					-font->base.scale.yy,
 					0, 0);
 
-    glyphPath = CGFontGetGlyphPathPtr (font_face->cgFont, &textMatrix, 0, glyph);
+    ctFont = CTFontCreateWithGraphicsFont (font_face->cgFont, 0.0, NULL, NULL);
+    glyphPath = CTFontCreatePathForGlyph (ctFont, glyph, &textMatrix);
+    CFRelease (ctFont);
     if (!glyphPath)
 	return CAIRO_INT_STATUS_UNSUPPORTED;
 
     path = _cairo_path_fixed_create ();
     if (!path) {
 	CGPathRelease (glyphPath);
 	return _cairo_error(CAIRO_STATUS_NO_MEMORY);
     }
@@ -797,17 +795,17 @@ CGFontRef
 CTFontRef
 _cairo_quartz_scaled_font_get_ct_font_ref (cairo_scaled_font_t *abstract_font)
 {
     cairo_quartz_font_face_t *ffont = _cairo_quartz_scaled_to_face(abstract_font);
 
     return ffont->ctFont;
 }
 
-#ifndef __LP64__
+#if !defined(__LP64__) && !TARGET_OS_IPHONE
 /*
  * compat with old ATSUI backend
  */
 
 /**
  * cairo_quartz_font_face_create_for_atsu_font_id
  * @font_id: an ATSUFontID for the font.
  *
--- a/gfx/cairo/cairo/src/cairo-quartz-image.h
+++ b/gfx/cairo/cairo/src/cairo-quartz-image.h
@@ -34,18 +34,23 @@
  */
 
 #ifndef CAIRO_QUARTZ_IMAGE_H
 #define CAIRO_QUARTZ_IMAGE_H
 
 #include "cairo.h"
 
 #if CAIRO_HAS_QUARTZ_IMAGE_SURFACE
+#include "TargetConditionals.h"
 
+#if !TARGET_OS_IPHONE
 #include <Carbon/Carbon.h>
+#else
+#include <CoreGraphics/CoreGraphics.h>
+#endif
 
 CAIRO_BEGIN_DECLS
 
 cairo_public cairo_surface_t *
 cairo_quartz_image_surface_create (cairo_surface_t *image_surface);
 
 cairo_public cairo_surface_t *
 cairo_quartz_image_surface_get_image (cairo_surface_t *surface);
--- a/gfx/cairo/cairo/src/cairo-quartz-surface.c
+++ b/gfx/cairo/cairo/src/cairo-quartz-surface.c
@@ -29,17 +29,19 @@
  * The Original Code is the cairo graphics library.
  *
  * The Initial Developer of the Original Code is Mozilla Foundation.
  *
  * Contributor(s):
  *	Vladimir Vukicevic <vladimir@mozilla.com>
  */
 
+#ifndef _GNU_SOURCE
 #define _GNU_SOURCE /* required for RTLD_DEFAULT */
+#endif
 #include "cairoint.h"
 
 #include "cairo-quartz-private.h"
 
 #include "cairo-error-private.h"
 #include "cairo-surface-clipper-private.h"
 #include "cairo-gstate-private.h"
 #include "cairo-private.h"
@@ -172,20 +174,25 @@ static void quartz_ensure_symbols(void)
     CGContextSetShouldAntialiasFontsPtr = dlsym(RTLD_DEFAULT, "CGContextSetShouldAntialiasFonts");
     CGContextCopyPathPtr = dlsym(RTLD_DEFAULT, "CGContextCopyPath");
     CGContextGetAllowsFontSmoothingPtr = dlsym(RTLD_DEFAULT, "CGContextGetAllowsFontSmoothing");
     CGContextSetAllowsFontSmoothingPtr = dlsym(RTLD_DEFAULT, "CGContextSetAllowsFontSmoothing");
     CGContextGetAlphaPtr = dlsym(RTLD_DEFAULT, "CGContextGetAlpha");
 
     CTFontDrawGlyphsPtr = dlsym(RTLD_DEFAULT, "CTFontDrawGlyphs");
 
+#if !TARGET_OS_IPHONE
     if (Gestalt(gestaltSystemVersion, &_cairo_quartz_osx_version) != noErr) {
         // assume 10.5
         _cairo_quartz_osx_version = 0x1050;
     }
+#else
+    //TODO: this is not great
+    _cairo_quartz_osx_version = 0x1050;
+#endif
 
     _cairo_quartz_symbol_lookup_done = TRUE;
 }
 
 CGImageRef
 _cairo_quartz_create_cgimage (cairo_format_t format,
 			      unsigned int width,
 			      unsigned int height,
--- a/gfx/cairo/cairo/src/cairo-quartz.h
+++ b/gfx/cairo/cairo/src/cairo-quartz.h
@@ -34,18 +34,24 @@
  */
 
 #ifndef CAIRO_QUARTZ_H
 #define CAIRO_QUARTZ_H
 
 #include "cairo.h"
 
 #if CAIRO_HAS_QUARTZ_SURFACE
+#include "TargetConditionals.h"
 
+#if !TARGET_OS_IPHONE
 #include <ApplicationServices/ApplicationServices.h>
+#else
+#include <CoreGraphics/CoreGraphics.h>
+#include <CoreText/CoreText.h>
+#endif
 
 CAIRO_BEGIN_DECLS
 
 cairo_public cairo_surface_t *
 cairo_quartz_surface_create (cairo_format_t format,
                              unsigned int width,
                              unsigned int height);
 
@@ -83,17 +89,17 @@ cairo_quartz_surface_get_image (cairo_su
 
 /*
  * Quartz font support
  */
 
 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
 
 #endif /* CAIRO_HAS_QUARTZ_FONT */
 
 CAIRO_END_DECLS
 
--- a/gfx/cairo/cairo/src/moz.build
+++ b/gfx/cairo/cairo/src/moz.build
@@ -51,17 +51,17 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'wind
     DEFINES['DISABLE_SOME_FLOATING_POINT'] = True
     DEFINES['CAIRO_WIN32_STATIC_BUILD'] = True
     if CONFIG['NS_PRINTING']:
         SOURCES += [
             'cairo-win32-printing-surface.c',
         ]
     else:
         DEFINES['CAIRO_OMIT_WIN32_PRINTING'] = True
-elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
+elif CONFIG['MOZ_WIDGET_TOOLKIT'] in {'cocoa', 'uikit'}:
     EXPORTS.cairo += [
         'cairo-quartz-image.h',
         'cairo-quartz.h',
     ]
     SOURCES += [
         'cairo-quartz-font.c',
         'cairo-quartz-image-surface.c',
         'cairo-quartz-surface.c',