b=411224, r=vlad: 411224-cairo-upgrade-fixes.patch
authorvladimir@pobox.com
Fri, 18 Jan 2008 13:46:33 -0800
changeset 10415 99224b77f8026554900a9991c3369da59651083b
parent 10414 df253072d285f862886ea681a0e040445a7fefde
child 10416 2c54db7939751c878349931f6d1282a1156c69d7
push idunknown
push userunknown
push dateunknown
reviewersvlad
bugs411224
milestone1.9b3pre
b=411224, r=vlad: 411224-cairo-upgrade-fixes.patch
gfx/cairo/README
gfx/cairo/cairo/src/Makefile.in
gfx/cairo/cairo/src/cairo-fixed-private.h
gfx/cairo/cairo/src/cairo-ft-font.c
gfx/cairo/cairo/src/cairo-quartz-surface.c
gfx/cairo/cairo/src/cairo-rename.h
gfx/cairo/cairo/src/cairo-win32-private.h
gfx/cairo/cairo/src/cairoint.h
gfx/cairo/fixed-24-8.patch
gfx/cairo/libpixman/src/pixman-private.h
gfx/cairo/mac-runtime-linkage.patch
gfx/cairo/max-font-size.patch
gfx/cairo/nonfatal-assertions.patch
--- a/gfx/cairo/README
+++ b/gfx/cairo/README
@@ -21,8 +21,12 @@ Some specific things:
 
 max-font-size.patch: Clamp freetype font size to 1000 to avoid overflow issues
 
 win32-logical-font-scale.patch: set CAIRO_WIN32_LOGICAL_FONT_SCALE to 1
 
 nonfatal-assertions.patch: Make assertions non-fatal
 
 endian.patch: include cairo-platform.h for endian macros
+
+fixed-24-8.patch: Switch fixed point mode from 16.16 to 24.8
+
+mac-runtime-linkage.patch: Do some runtime dlsym lookups instead of relying on gcc attributes
--- a/gfx/cairo/cairo/src/Makefile.in
+++ b/gfx/cairo/cairo/src/Makefile.in
@@ -116,19 +116,20 @@ CSRCS   = \
         cairo-surface-fallback.c \
         cairo-traps.c \
         cairo-unicode.c \
         cairo-wideint.c \
         $(NULL)
 
 EXPORTS = cairo.h cairo-features.h cairo-platform.h cairo-deprecated.h cairo-rename.h
 
+# cairo-type1-subset.c should be here, but it's only supported on freetype platforms
+
 PSPDF_BASE_CSRCS = \
 	cairo-base85-stream.c \
-	cairo-type1-subset.c \
 	cairo-type1-fallback.c \
 	cairo-truetype-subset.c \
 	cairo-cff-subset.c \
 	$(NULL)
 
 PDF_CSRCS = \
 	cairo-pdf-surface.c \
 	cairo-pdf-operators.c \
@@ -179,17 +180,17 @@ endif
 ifdef MOZ_X11
 CSRCS   += cairo-xlib-surface.c \
 	   cairo-xlib-screen.c \
 	   cairo-xlib-display.c
 EXPORTS += cairo-xlib.h cairo-xlib-xrender.h
 endif
 
 ifdef MOZ_ENABLE_CAIRO_FT
-CSRCS   += cairo-ft-font.c
+CSRCS   += cairo-ft-font.c cairo-type1-subset.c
 EXPORTS += cairo-ft.h
 OS_INCLUDES += $(CAIRO_FT_CFLAGS)
 endif
 
 
 ifdef MOZ_ENABLE_GLITZ
 REQUIRES += glitz
 CSRCS    += cairo-glitz-surface.c
--- a/gfx/cairo/cairo/src/cairo-fixed-private.h
+++ b/gfx/cairo/cairo/src/cairo-fixed-private.h
@@ -54,17 +54,17 @@ typedef cairo_int128_t	cairo_fixed_96_32
  * size of a fixed type.  For now, it must be 32.
  */
 #define CAIRO_FIXED_BITS	32
 
 /* The number of fractional bits.  Changing this involves
  * making sure that you compute a double-to-fixed magic number.
  * (see below).
  */
-#define CAIRO_FIXED_FRAC_BITS	16
+#define CAIRO_FIXED_FRAC_BITS	8
 
 /* A signed type CAIRO_FIXED_BITS in size; the main fixed point type */
 typedef int32_t cairo_fixed_t;
 
 /* An unsigned type of the same size as cairo_fixed_t */
 typedef uint32_t cairo_fixed_unsigned_t;
 
 /*
--- a/gfx/cairo/cairo/src/cairo-ft-font.c
+++ b/gfx/cairo/cairo/src/cairo-ft-font.c
@@ -59,16 +59,20 @@
 #define DOUBLE_FROM_26_6(t) ((double)(t) / 64.0)
 #define DOUBLE_TO_16_16(d) ((FT_Fixed)((d) * 65536.0))
 #define DOUBLE_FROM_16_16(t) ((double)(t) / 65536.0)
 
 /* This is the max number of FT_face objects we keep open at once
  */
 #define MAX_OPEN_FACES 10
 
+/* This is the maximum font size we allow to be passed to FT_Set_Char_Size
+ */
+#define MAX_FONT_SIZE 1000
+
 /*
  * The simple 2x2 matrix is converted into separate scale and shape
  * factors so that hinting works right
  */
 
 typedef struct _cairo_ft_font_transform {
     double  x_scale, y_scale;
     double  shape[2][2];
@@ -661,19 +665,28 @@ static cairo_status_t
     cairo_matrix_init (&unscaled->current_shape,
 		       sf.shape[0][0], sf.shape[0][1],
 		       sf.shape[1][0], sf.shape[1][1],
 		       0.0, 0.0);
 
     FT_Set_Transform(unscaled->face, &mat, NULL);
 
     if ((unscaled->face->face_flags & FT_FACE_FLAG_SCALABLE) != 0) {
+        double x_scale = sf.x_scale;
+        double y_scale = sf.y_scale;
+        if (x_scale > MAX_FONT_SIZE) {
+            x_scale = MAX_FONT_SIZE;
+        }
+        if (y_scale > MAX_FONT_SIZE) {
+            y_scale = MAX_FONT_SIZE;
+        }
+
 	error = FT_Set_Char_Size (unscaled->face,
-				  sf.x_scale * 64.0,
-				  sf.y_scale * 64.0,
+				  x_scale * 64.0,
+				  y_scale * 64.0,
 				  0, 0);
 	if (error)
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
     } else {
 	double min_distance = DBL_MAX;
 	int i;
 	int best_i = 0;
 
--- a/gfx/cairo/cairo/src/cairo-quartz-surface.c
+++ b/gfx/cairo/cairo/src/cairo-quartz-surface.c
@@ -29,16 +29,18 @@
  * The Original Code is the cairo graphics library.
  *
  * The Initial Developer of the Original Code is Mozilla Corporation.
  *
  * Contributor(s):
  *	Vladimir Vukicevic <vladimir@mozilla.com>
  */
 
+#include <dlfcn.h>
+
 #include "cairoint.h"
 
 #include "cairo-quartz-private.h"
 
 /* The 10.5 SDK includes a funky new definition of FloatToFixed which
  * causes all sorts of breakage; so reset to old-style definition
  */
 #ifdef FloatToFixed
@@ -95,35 +97,48 @@ CG_EXTERN CGSize CGContextGetPatternPhas
 
 typedef uint32_t CGBitmapInfo;
 
 /* public in 10.4, present in 10.3.9 */
 CG_EXTERN void CGContextReplacePathWithStrokedPath (CGContextRef);
 CG_EXTERN CGImageRef CGBitmapContextCreateImage (CGContextRef);
 #endif
 
-/* missing in 10.3.9 */
-extern void CGContextClipToMask (CGContextRef, CGRect, CGImageRef) __attribute__((weak_import));
+/* Only present in 10.4+ */
+static void (*CGContextClipToMaskPtr) (CGContextRef, CGRect, CGImageRef) = NULL;
+/* Only present in 10.5+ */
+static void (*CGContextDrawTiledImagePtr) (CGContextRef, CGRect, CGImageRef) = NULL;
 
-/* 10.5-only optimization */
-extern void CGContextDrawTiledImage (CGContextRef, CGRect, CGImageRef) __attribute__((weak_import));
+static cairo_bool_t _cairo_quartz_symbol_lookup_done = FALSE;
 
 /*
  * Utility functions
  */
 
 static void quartz_surface_to_png (cairo_quartz_surface_t *nq, char *dest);
 static void quartz_image_to_png (CGImageRef, char *dest);
 
 static cairo_quartz_surface_t *
 _cairo_quartz_surface_create_internal (CGContextRef cgContext,
 				       cairo_content_t content,
 				       unsigned int width,
 				       unsigned int height);
 
+/* Load all extra symbols */
+static void quartz_ensure_symbols()
+{
+    if (_cairo_quartz_symbol_lookup_done)
+	return;
+
+    CGContextClipToMaskPtr = dlsym(RTLD_DEFAULT, "CGContextClipToMask");
+    CGContextDrawTiledImagePtr = dlsym(RTLD_DEFAULT, "CGContextDrawTiledImage");
+
+    _cairo_quartz_symbol_lookup_done = TRUE;
+}
+
 /* CoreGraphics limitation with flipped CTM surfaces: height must be less than signed 16-bit max */
 
 #define CG_MAX_HEIGHT   SHRT_MAX
 #define CG_MAX_WIDTH    USHRT_MAX
 
 /* is the desired size of the surface within bounds? */
 static cairo_bool_t verify_surface_size(int width, int height)
 {
@@ -756,17 +771,17 @@ static cairo_quartz_action_t
 	cairo_linear_pattern_t *lpat = (cairo_linear_pattern_t *)source;
 	return _cairo_quartz_setup_linear_source (surface, lpat);
 
     } else if (source->type == CAIRO_PATTERN_TYPE_RADIAL) {
 	cairo_radial_pattern_t *rpat = (cairo_radial_pattern_t *)source;
 	return _cairo_quartz_setup_radial_source (surface, rpat);
 
     } else if (source->type == CAIRO_PATTERN_TYPE_SURFACE &&
-	       (source->extend == CAIRO_EXTEND_NONE || (CGContextDrawTiledImage && source->extend == CAIRO_EXTEND_REPEAT)))
+	       (source->extend == CAIRO_EXTEND_NONE || (CGContextDrawTiledImagePtr && source->extend == CAIRO_EXTEND_REPEAT)))
     {
 	    cairo_surface_pattern_t *spat = (cairo_surface_pattern_t *) source;
 	    cairo_surface_t *pat_surf = spat->surface;
 	    cairo_quartz_surface_t *quartz_surf;
 	    CGImageRef img;
 	    cairo_matrix_t m = spat->base.matrix;
 	    cairo_rectangle_int_t extents;
 	    cairo_status_t status;
@@ -1293,17 +1308,17 @@ static cairo_int_status_t
 	if (cairo_surface_get_type(pat_surf) == CAIRO_SURFACE_TYPE_QUARTZ) {
 	    CGContextTranslateCTM (surface->cgContext, 0, CGImageGetHeight(surface->sourceImage));
 	    CGContextScaleCTM (surface->cgContext, 1, -1);
 	}
 
 	if (action == DO_IMAGE)
 	    CGContextDrawImage (surface->cgContext, surface->sourceImageRect, surface->sourceImage);
 	else
-	    CGContextDrawTiledImage (surface->cgContext, surface->sourceImageRect, surface->sourceImage);
+	    CGContextDrawTiledImagePtr (surface->cgContext, surface->sourceImageRect, surface->sourceImage);
 	CGContextRestoreGState (surface->cgContext);
     } else if (action != DO_NOTHING) {
 	rv = CAIRO_INT_STATUS_UNSUPPORTED;
     }
 
     _cairo_quartz_teardown_source (surface, source);
 
     ND((stderr, "-- paint\n"));
@@ -1383,17 +1398,17 @@ static cairo_int_status_t
 	if (cairo_surface_get_type(pat_surf) == CAIRO_SURFACE_TYPE_QUARTZ) {
 	    CGContextTranslateCTM (surface->cgContext, 0, CGImageGetHeight(surface->sourceImage));
 	    CGContextScaleCTM (surface->cgContext, 1, -1);
 	}
 
 	if (action == DO_IMAGE)
 	    CGContextDrawImage (surface->cgContext, surface->sourceImageRect, surface->sourceImage);
 	else
-	    CGContextDrawTiledImage (surface->cgContext, surface->sourceImageRect, surface->sourceImage);
+	    CGContextDrawTiledImagePtr (surface->cgContext, surface->sourceImageRect, surface->sourceImage);
     } else if (action != DO_NOTHING) {
 	rv = CAIRO_INT_STATUS_UNSUPPORTED;
     }
 
   BAIL:
     _cairo_quartz_teardown_source (surface, source);
 
     CGContextRestoreGState (surface->cgContext);
@@ -1491,17 +1506,17 @@ static cairo_int_status_t
 	if (cairo_surface_get_type(((cairo_surface_pattern_t*)source)->surface) == CAIRO_SURFACE_TYPE_QUARTZ) {
 	    CGContextTranslateCTM (surface->cgContext, 0, CGImageGetHeight(surface->sourceImage));
 	    CGContextScaleCTM (surface->cgContext, 1, -1);
 	}
 
 	if (action == DO_IMAGE)
 	    CGContextDrawImage (surface->cgContext, surface->sourceImageRect, surface->sourceImage);
 	else
-	    CGContextDrawTiledImage (surface->cgContext, surface->sourceImageRect, surface->sourceImage);
+	    CGContextDrawTiledImagePtr (surface->cgContext, surface->sourceImageRect, surface->sourceImage);
     } else if (action == DO_SHADING) {
 	CGContextReplacePathWithStrokedPath (surface->cgContext);
 	CGContextClip (surface->cgContext);
 
 	CGContextDrawShading (surface->cgContext, surface->sourceShading);
     } else if (action != DO_NOTHING) {
 	rv = CAIRO_INT_STATUS_UNSUPPORTED;
     }
@@ -1650,17 +1665,17 @@ static cairo_int_status_t
 	if (cairo_surface_get_type(((cairo_surface_pattern_t*)source)->surface) == CAIRO_SURFACE_TYPE_QUARTZ) {
 	    CGContextTranslateCTM (surface->cgContext, 0, CGImageGetHeight(surface->sourceImage));
 	    CGContextScaleCTM (surface->cgContext, 1, -1);
 	}
 
 	if (action == DO_IMAGE)
 	    CGContextDrawImage (surface->cgContext, surface->sourceImageRect, surface->sourceImage);
 	else
-	    CGContextDrawTiledImage (surface->cgContext, surface->sourceImageRect, surface->sourceImage);
+	    CGContextDrawTiledImagePtr (surface->cgContext, surface->sourceImageRect, surface->sourceImage);
     } else if (action == DO_SHADING) {
 	CGContextDrawShading (surface->cgContext, surface->sourceShading);
     }
 
 BAIL:
     if (cg_advances != &cg_advances_static[0]) {
 	free (cg_advances);
     }
@@ -1705,17 +1720,17 @@ static cairo_int_status_t
     img = CGBitmapContextCreateImage (quartz_surf->cgContext);
     if (!img) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto BAIL;
     }
 
     rect = CGRectMake (-mask->base.matrix.x0, -mask->base.matrix.y0, extents.width, extents.height);
     CGContextSaveGState (surface->cgContext);
-    CGContextClipToMask (surface->cgContext, rect, img);
+    CGContextClipToMaskPtr (surface->cgContext, rect, img);
     status = _cairo_quartz_surface_paint (surface, op, source);
 
     CGContextRestoreGState (surface->cgContext);
     CGImageRelease (img);
   BAIL:
     cairo_surface_destroy ((cairo_surface_t*) quartz_surf);
     return status;
 }
@@ -1734,17 +1749,17 @@ static cairo_int_status_t
     if (IS_EMPTY(surface))
 	return CAIRO_STATUS_SUCCESS;
 
     if (mask->type == CAIRO_PATTERN_TYPE_SOLID) {
 	/* This is easy; we just need to paint with the alpha. */
 	cairo_solid_pattern_t *solid_mask = (cairo_solid_pattern_t *) mask;
 
 	CGContextSetAlpha (surface->cgContext, solid_mask->color.alpha);
-    } else if (CGContextClipToMask &&
+    } else if (CGContextClipToMaskPtr &&
                mask->type == CAIRO_PATTERN_TYPE_SURFACE &&
 	       mask->extend == CAIRO_EXTEND_NONE) {
 	return _cairo_quartz_surface_mask_with_surface (surface, op, source, (cairo_surface_pattern_t *) mask);
     } else {
 	/* So, CGContextClipToMask is not present in 10.3.9, so we're
 	 * doomed; if we have imageData, we can do fallback, otherwise
 	 * just pretend success.
 	 */
@@ -1858,16 +1873,18 @@ static const struct _cairo_surface_backe
 cairo_quartz_surface_t *
 _cairo_quartz_surface_create_internal (CGContextRef cgContext,
 					cairo_content_t content,
 					unsigned int width,
 					unsigned int height)
 {
     cairo_quartz_surface_t *surface;
 
+    quartz_ensure_symbols();
+
     /* Init the base surface */
     surface = malloc(sizeof(cairo_quartz_surface_t));
     if (surface == NULL) {
 	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return NULL;
     }
 
     memset(surface, 0, sizeof(cairo_quartz_surface_t));
--- a/gfx/cairo/cairo/src/cairo-rename.h
+++ b/gfx/cairo/cairo/src/cairo-rename.h
@@ -147,21 +147,26 @@
 #define cairo_pattern_set_matrix _moz_cairo_pattern_set_matrix
 #define cairo_pattern_set_user_data _moz_cairo_pattern_set_user_data
 #define cairo_pattern_status _moz_cairo_pattern_status
 #define cairo_pdf_surface_create _moz_cairo_pdf_surface_create
 #define cairo_pdf_surface_create_for_stream _moz_cairo_pdf_surface_create_for_stream
 #define cairo_pdf_surface_set_size _moz_cairo_pdf_surface_set_size
 #define cairo_pop_group _moz_cairo_pop_group
 #define cairo_pop_group_to_source _moz_cairo_pop_group_to_source
+#define cairo_ps_get_levels _moz_cairo_ps_get_levels
+#define cairo_ps_level_to_string _moz_cairo_ps_level_to_string
 #define cairo_ps_surface_create _moz_cairo_ps_surface_create
 #define cairo_ps_surface_create_for_stream _moz_cairo_ps_surface_create_for_stream
 #define cairo_ps_surface_dsc_begin_page_setup _moz_cairo_ps_surface_dsc_begin_page_setup
 #define cairo_ps_surface_dsc_begin_setup _moz_cairo_ps_surface_dsc_begin_setup
 #define cairo_ps_surface_dsc_comment _moz_cairo_ps_surface_dsc_comment
+#define cairo_ps_surface_get_eps _moz_cairo_ps_surface_get_eps
+#define cairo_ps_surface_restrict_to_level _moz_cairo_ps_surface_restrict_to_level
+#define cairo_ps_surface_set_eps _moz_cairo_ps_surface_set_eps
 #define cairo_ps_surface_set_size _moz_cairo_ps_surface_set_size
 #define cairo_push_group _moz_cairo_push_group
 #define cairo_push_group_with_content _moz_cairo_push_group_with_content
 #define cairo_quartz_surface_create _moz_cairo_quartz_surface_create
 #define cairo_quartz_surface_create_for_cg_context _moz_cairo_quartz_surface_create_for_cg_context
 #define cairo_quartz_surface_get_cg_context _moz_cairo_quartz_surface_get_cg_context
 #define cairo_rectangle _moz_cairo_rectangle
 #define cairo_rectangle_list_destroy _moz_cairo_rectangle_list_destroy
@@ -251,16 +256,17 @@
 #define cairo_translate _moz_cairo_translate
 #define cairo_user_to_device _moz_cairo_user_to_device
 #define cairo_user_to_device_distance _moz_cairo_user_to_device_distance
 #define cairo_version _moz_cairo_version
 #define cairo_version_string _moz_cairo_version_string
 #define cairo_win32_font_face_create_for_hfont _moz_cairo_win32_font_face_create_for_hfont
 #define cairo_win32_font_face_create_for_logfontw _moz_cairo_win32_font_face_create_for_logfontw
 #define cairo_win32_font_face_create_for_logfontw_hfont _moz_cairo_win32_font_face_create_for_logfontw_hfont
+#define cairo_win32_printing_surface_create _moz_cairo_win32_printing_surface_create
 #define cairo_win32_scaled_font_done_font _moz_cairo_win32_scaled_font_done_font
 #define cairo_win32_scaled_font_get_device_to_logical _moz_cairo_win32_scaled_font_get_device_to_logical
 #define cairo_win32_scaled_font_get_logical_to_device _moz_cairo_win32_scaled_font_get_logical_to_device
 #define cairo_win32_scaled_font_get_metrics_factor _moz_cairo_win32_scaled_font_get_metrics_factor
 #define cairo_win32_scaled_font_select_font _moz_cairo_win32_scaled_font_select_font
 #define cairo_win32_surface_create _moz_cairo_win32_surface_create
 #define cairo_win32_surface_create_with_ddb _moz_cairo_win32_surface_create_with_ddb
 #define cairo_win32_surface_create_with_dib _moz_cairo_win32_surface_create_with_dib
--- a/gfx/cairo/cairo/src/cairo-win32-private.h
+++ b/gfx/cairo/cairo/src/cairo-win32-private.h
@@ -41,17 +41,17 @@
 
 #ifndef SHADEBLENDCAPS
 #define SHADEBLENDCAPS 120
 #endif
 #ifndef SB_NONE
 #define SB_NONE 0
 #endif
 
-#define WIN32_FONT_LOGICAL_SCALE 32
+#define WIN32_FONT_LOGICAL_SCALE 1
 
 typedef struct _cairo_win32_surface {
     cairo_surface_t base;
 
     cairo_format_t format;
 
     HDC dc;
 
--- a/gfx/cairo/cairo/src/cairoint.h
+++ b/gfx/cairo/cairo/src/cairoint.h
@@ -100,16 +100,23 @@ cairo_private FILE *
 #ifndef TRUE
 #define TRUE 1
 #endif
 
 #ifndef M_PI
 #define M_PI 3.14159265358979323846
 #endif
 
+#ifndef NDEBUG
+#undef assert
+#define assert(expr) \
+    do { if (!(expr)) fprintf(stderr, "Assertion failed at %s:%d: %s\n", \
+          __FILE__, __LINE__, #expr); } while (0)
+#endif
+
 #undef  ARRAY_LENGTH
 #define ARRAY_LENGTH(__array) ((int) (sizeof (__array) / sizeof (__array[0])))
 
 /* Size in bytes of buffer to use off the stack per functions.
  * Mostly used by text functions.  For larger allocations, they'll
  * malloc(). */
 #ifndef CAIRO_STACK_BUFFER_SIZE
 #define CAIRO_STACK_BUFFER_SIZE (512 * sizeof (int))
new file mode 100644
--- /dev/null
+++ b/gfx/cairo/fixed-24-8.patch
@@ -0,0 +1,12 @@
+diff --git a/gfx/cairo/cairo/src/cairo-fixed-private.h b/gfx/cairo/cairo/src/cairo-fixed-private.h
+--- a/cairo/src/cairo-fixed-private.h
++++ b/cairo/src/cairo-fixed-private.h
+@@ -59,7 +59,7 @@ typedef cairo_int128_t	cairo_fixed_96_32
+  * making sure that you compute a double-to-fixed magic number.
+  * (see below).
+  */
+-#define CAIRO_FIXED_FRAC_BITS	16
++#define CAIRO_FIXED_FRAC_BITS	8
+ 
+ /* A signed type CAIRO_FIXED_BITS in size; the main fixed point type */
+ typedef int32_t cairo_fixed_t;
--- a/gfx/cairo/libpixman/src/pixman-private.h
+++ b/gfx/cairo/libpixman/src/pixman-private.h
@@ -1,15 +1,17 @@
 #ifndef PACKAGE
 #  error config.h must be included before pixman-private.h
 #endif
 
 #ifndef PIXMAN_PRIVATE_H
 #define PIXMAN_PRIVATE_H
 
+#include "cairo-platform.h"
+
 #include "pixman.h"
 #include <time.h>
 
 #ifndef FALSE
 #define FALSE 0
 #endif
 
 #ifndef TRUE
new file mode 100644
--- /dev/null
+++ b/gfx/cairo/mac-runtime-linkage.patch
@@ -0,0 +1,120 @@
+diff --git a/gfx/cairo/cairo/src/cairo-quartz-surface.c b/gfx/cairo/cairo/src/cairo-quartz-surface.c
+--- a/gfx/cairo/cairo/src/cairo-quartz-surface.c
++++ b/gfx/cairo/cairo/src/cairo-quartz-surface.c
+@@ -33,6 +33,8 @@
+  * Contributor(s):
+  *	Vladimir Vukicevic <vladimir@mozilla.com>
+  */
++
++#include <dlfcn.h>
+ 
+ #include "cairoint.h"
+ 
+@@ -100,11 +102,12 @@ CG_EXTERN CGImageRef CGBitmapContextCrea
+ CG_EXTERN CGImageRef CGBitmapContextCreateImage (CGContextRef);
+ #endif
+ 
+-/* missing in 10.3.9 */
+-extern void CGContextClipToMask (CGContextRef, CGRect, CGImageRef) __attribute__((weak_import));
++/* Only present in 10.4+ */
++static void (*CGContextClipToMaskPtr) (CGContextRef, CGRect, CGImageRef) = NULL;
++/* Only present in 10.5+ */
++static void (*CGContextDrawTiledImagePtr) (CGContextRef, CGRect, CGImageRef) = NULL;
+ 
+-/* 10.5-only optimization */
+-extern void CGContextDrawTiledImage (CGContextRef, CGRect, CGImageRef) __attribute__((weak_import));
++static cairo_bool_t _cairo_quartz_symbol_lookup_done = FALSE;
+ 
+ /*
+  * Utility functions
+@@ -118,6 +121,18 @@ _cairo_quartz_surface_create_internal (C
+ 				       cairo_content_t content,
+ 				       unsigned int width,
+ 				       unsigned int height);
++
++/* Load all extra symbols */
++static void quartz_ensure_symbols()
++{
++    if (_cairo_quartz_symbol_lookup_done)
++	return;
++
++    CGContextClipToMaskPtr = dlsym(RTLD_DEFAULT, "CGContextClipToMask");
++    CGContextDrawTiledImagePtr = dlsym(RTLD_DEFAULT, "CGContextDrawTiledImage");
++
++    _cairo_quartz_symbol_lookup_done = TRUE;
++}
+ 
+ /* CoreGraphics limitation with flipped CTM surfaces: height must be less than signed 16-bit max */
+ 
+@@ -761,7 +776,7 @@ _cairo_quartz_setup_source (cairo_quartz
+ 	return _cairo_quartz_setup_radial_source (surface, rpat);
+ 
+     } else if (source->type == CAIRO_PATTERN_TYPE_SURFACE &&
+-	       (source->extend == CAIRO_EXTEND_NONE || (CGContextDrawTiledImage && source->extend == CAIRO_EXTEND_REPEAT)))
++	       (source->extend == CAIRO_EXTEND_NONE || (CGContextDrawTiledImagePtr && source->extend == CAIRO_EXTEND_REPEAT)))
+     {
+ 	    cairo_surface_pattern_t *spat = (cairo_surface_pattern_t *) source;
+ 	    cairo_surface_t *pat_surf = spat->surface;
+@@ -1298,7 +1313,7 @@ _cairo_quartz_surface_paint (void *abstr
+ 	if (action == DO_IMAGE)
+ 	    CGContextDrawImage (surface->cgContext, surface->sourceImageRect, surface->sourceImage);
+ 	else
+-	    CGContextDrawTiledImage (surface->cgContext, surface->sourceImageRect, surface->sourceImage);
++	    CGContextDrawTiledImagePtr (surface->cgContext, surface->sourceImageRect, surface->sourceImage);
+ 	CGContextRestoreGState (surface->cgContext);
+     } else if (action != DO_NOTHING) {
+ 	rv = CAIRO_INT_STATUS_UNSUPPORTED;
+@@ -1388,7 +1403,7 @@ _cairo_quartz_surface_fill (void *abstra
+ 	if (action == DO_IMAGE)
+ 	    CGContextDrawImage (surface->cgContext, surface->sourceImageRect, surface->sourceImage);
+ 	else
+-	    CGContextDrawTiledImage (surface->cgContext, surface->sourceImageRect, surface->sourceImage);
++	    CGContextDrawTiledImagePtr (surface->cgContext, surface->sourceImageRect, surface->sourceImage);
+     } else if (action != DO_NOTHING) {
+ 	rv = CAIRO_INT_STATUS_UNSUPPORTED;
+     }
+@@ -1496,7 +1511,7 @@ _cairo_quartz_surface_stroke (void *abst
+ 	if (action == DO_IMAGE)
+ 	    CGContextDrawImage (surface->cgContext, surface->sourceImageRect, surface->sourceImage);
+ 	else
+-	    CGContextDrawTiledImage (surface->cgContext, surface->sourceImageRect, surface->sourceImage);
++	    CGContextDrawTiledImagePtr (surface->cgContext, surface->sourceImageRect, surface->sourceImage);
+     } else if (action == DO_SHADING) {
+ 	CGContextReplacePathWithStrokedPath (surface->cgContext);
+ 	CGContextClip (surface->cgContext);
+@@ -1655,7 +1670,7 @@ _cairo_quartz_surface_show_glyphs (void 
+ 	if (action == DO_IMAGE)
+ 	    CGContextDrawImage (surface->cgContext, surface->sourceImageRect, surface->sourceImage);
+ 	else
+-	    CGContextDrawTiledImage (surface->cgContext, surface->sourceImageRect, surface->sourceImage);
++	    CGContextDrawTiledImagePtr (surface->cgContext, surface->sourceImageRect, surface->sourceImage);
+     } else if (action == DO_SHADING) {
+ 	CGContextDrawShading (surface->cgContext, surface->sourceShading);
+     }
+@@ -1710,7 +1725,7 @@ _cairo_quartz_surface_mask_with_surface 
+ 
+     rect = CGRectMake (-mask->base.matrix.x0, -mask->base.matrix.y0, extents.width, extents.height);
+     CGContextSaveGState (surface->cgContext);
+-    CGContextClipToMask (surface->cgContext, rect, img);
++    CGContextClipToMaskPtr (surface->cgContext, rect, img);
+     status = _cairo_quartz_surface_paint (surface, op, source);
+ 
+     CGContextRestoreGState (surface->cgContext);
+@@ -1739,7 +1754,7 @@ _cairo_quartz_surface_mask (void *abstra
+ 	cairo_solid_pattern_t *solid_mask = (cairo_solid_pattern_t *) mask;
+ 
+ 	CGContextSetAlpha (surface->cgContext, solid_mask->color.alpha);
+-    } else if (CGContextClipToMask &&
++    } else if (CGContextClipToMaskPtr &&
+                mask->type == CAIRO_PATTERN_TYPE_SURFACE &&
+ 	       mask->extend == CAIRO_EXTEND_NONE) {
+ 	return _cairo_quartz_surface_mask_with_surface (surface, op, source, (cairo_surface_pattern_t *) mask);
+@@ -1862,6 +1877,8 @@ _cairo_quartz_surface_create_internal (C
+ 					unsigned int height)
+ {
+     cairo_quartz_surface_t *surface;
++
++    quartz_ensure_symbols();
+ 
+     /* Init the base surface */
+     surface = malloc(sizeof(cairo_quartz_surface_t));
--- a/gfx/cairo/max-font-size.patch
+++ b/gfx/cairo/max-font-size.patch
@@ -1,12 +1,12 @@
 diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c
 index 59a5acb..8851387 100644
---- a/src/cairo-ft-font.c
-+++ b/src/cairo-ft-font.c
+--- a/cairo/src/cairo-ft-font.c
++++ b/cairo/src/cairo-ft-font.c
 @@ -62,6 +62,10 @@
   */
  #define MAX_OPEN_FACES 10
  
 +/* This is the maximum font size we allow to be passed to FT_Set_Char_Size
 + */
 +#define MAX_FONT_SIZE 1000
 +
--- a/gfx/cairo/nonfatal-assertions.patch
+++ b/gfx/cairo/nonfatal-assertions.patch
@@ -1,11 +1,11 @@
 diff -r b79d47dad1ea gfx/cairo/cairo/src/cairoint.h
---- a/gfx/cairo/cairo/src/cairoint.h	Fri Jun 08 18:09:53 2007 -0700
-+++ b/gfx/cairo/cairo/src/cairoint.h	Fri Jun 29 09:18:02 2007 +0200
+--- a/cairo/src/cairoint.h	Fri Jun 08 18:09:53 2007 -0700
++++ b/cairo/src/cairoint.h	Fri Jun 29 09:18:02 2007 +0200
 @@ -159,6 +159,13 @@ CAIRO_BEGIN_DECLS
  
  #ifndef M_PI
  #define M_PI 3.14159265358979323846
 +#endif
 +
 +#ifndef NDEBUG
 +#undef assert