b=416018, upgrade cairo to 1.5.8-30-g80e11a8 ; r=me
authorvladimir@pobox.com
Wed, 13 Feb 2008 22:54:26 -0800
changeset 11708 a1060856b83a8988a0b9f8505fea5e13c8d09973
parent 11707 1c23af26cd7fa7157341773380d1118cd333b44f
child 11709 e9eba5274b5b5bbe821abc4a9f3fac2f7399e935
push idunknown
push userunknown
push dateunknown
reviewersme
bugs416018
milestone1.9b4pre
b=416018, upgrade cairo to 1.5.8-30-g80e11a8 ; r=me
gfx/cairo/README
gfx/cairo/cairo/src/cairo-array.c
gfx/cairo/cairo/src/cairo-atsui-font.c
gfx/cairo/cairo/src/cairo-base85-stream.c
gfx/cairo/cairo/src/cairo-bentley-ottmann.c
gfx/cairo/cairo/src/cairo-beos-surface.cpp
gfx/cairo/cairo/src/cairo-cache-private.h
gfx/cairo/cairo/src/cairo-cache.c
gfx/cairo/cairo/src/cairo-clip.c
gfx/cairo/cairo/src/cairo-debug.c
gfx/cairo/cairo/src/cairo-deflate-stream.c
gfx/cairo/cairo/src/cairo-deprecated.h
gfx/cairo/cairo/src/cairo-directfb.h
gfx/cairo/cairo/src/cairo-fixed-type-private.h
gfx/cairo/cairo/src/cairo-font-face.c
gfx/cairo/cairo/src/cairo-font-options.c
gfx/cairo/cairo/src/cairo-freelist-private.h
gfx/cairo/cairo/src/cairo-ft-font.c
gfx/cairo/cairo/src/cairo-gstate.c
gfx/cairo/cairo/src/cairo-hash.c
gfx/cairo/cairo/src/cairo-image-surface.c
gfx/cairo/cairo/src/cairo-lzw.c
gfx/cairo/cairo/src/cairo-matrix.c
gfx/cairo/cairo/src/cairo-meta-surface.c
gfx/cairo/cairo/src/cairo-mutex-private.h
gfx/cairo/cairo/src/cairo-mutex-type-private.h
gfx/cairo/cairo/src/cairo-os2-surface.c
gfx/cairo/cairo/src/cairo-os2.h
gfx/cairo/cairo/src/cairo-output-stream-private.h
gfx/cairo/cairo/src/cairo-output-stream.c
gfx/cairo/cairo/src/cairo-paginated-private.h
gfx/cairo/cairo/src/cairo-paginated-surface.c
gfx/cairo/cairo/src/cairo-path-fill.c
gfx/cairo/cairo/src/cairo-path-fixed-private.h
gfx/cairo/cairo/src/cairo-path-stroke.c
gfx/cairo/cairo/src/cairo-path.c
gfx/cairo/cairo/src/cairo-pattern.c
gfx/cairo/cairo/src/cairo-pdf-operators-private.h
gfx/cairo/cairo/src/cairo-pdf-operators.c
gfx/cairo/cairo/src/cairo-pdf-surface-private.h
gfx/cairo/cairo/src/cairo-pdf-surface.c
gfx/cairo/cairo/src/cairo-pen.c
gfx/cairo/cairo/src/cairo-png.c
gfx/cairo/cairo/src/cairo-ps-surface.c
gfx/cairo/cairo/src/cairo-ps.h
gfx/cairo/cairo/src/cairo-rectangle.c
gfx/cairo/cairo/src/cairo-region-private.h
gfx/cairo/cairo/src/cairo-region.c
gfx/cairo/cairo/src/cairo-scaled-font-subsets-private.h
gfx/cairo/cairo/src/cairo-scaled-font.c
gfx/cairo/cairo/src/cairo-slope.c
gfx/cairo/cairo/src/cairo-stroke-style.c
gfx/cairo/cairo/src/cairo-surface-fallback.c
gfx/cairo/cairo/src/cairo-surface.c
gfx/cairo/cairo/src/cairo-svg-surface.c
gfx/cairo/cairo/src/cairo-svg.h
gfx/cairo/cairo/src/cairo-traps.c
gfx/cairo/cairo/src/cairo-types-private.h
gfx/cairo/cairo/src/cairo-unicode.c
gfx/cairo/cairo/src/cairo-win32-font.c
gfx/cairo/cairo/src/cairo-win32-surface.c
gfx/cairo/cairo/src/cairo-xcb-surface.c
gfx/cairo/cairo/src/cairo-xlib-surface.c
gfx/cairo/cairo/src/cairo-xlib-xrender.h
gfx/cairo/cairo/src/cairo.c
gfx/cairo/cairo/src/cairo.h
gfx/cairo/cairo/src/cairoint.h
gfx/cairo/libpixman/src/pixman-compose-noaccessors.c
gfx/cairo/libpixman/src/pixman-edge-noaccessors.c
--- a/gfx/cairo/README
+++ b/gfx/cairo/README
@@ -2,17 +2,17 @@ Snapshots of cairo and glitz for mozilla
 
 We only include the relevant parts of each release (generally, src/*.[ch]),
 as we have Makefile.in's that integrate into the Mozilla build system.  For
 documentation and similar, please see the official tarballs at
 http://www.cairographics.org/.
 
 VERSIONS:
 
-  cairo (1.5.x - 1.5.6-75-gc621d8d)
+  cairo (1.5.x - 1.5.8-30-g80e11a8)
   pixman (0.9.x - pixman-0.9.6-34-g787cc57)
   glitz 0.5.2 (cvs - 2006-01-10)
 
 ***** NOTE FOR VISUAL C++ 6.0 *****
 
 VC6 is not supported.  Please upgrade to VC8.
 
 ==== Patches ====
--- a/gfx/cairo/cairo/src/cairo-array.c
+++ b/gfx/cairo/cairo/src/cairo-array.c
@@ -35,17 +35,17 @@
  *	Carl Worth <cworth@cworth.org>
  */
 
 #include "cairoint.h"
 
 /**
  * _cairo_array_init:
  *
- * Initialize a new cairo_array object to store objects each of size
+ * Initialize a new #cairo_array_t object to store objects each of size
  * @element_size.
  *
  * The #cairo_array_t object provides grow-by-doubling storage. It
  * never interprets the data passed to it, nor does it provide any
  * sort of callback mechanism for freeing resources held onto by
  * stored objects.
  *
  * When finished using the array, _cairo_array_fini() should be
@@ -172,17 +172,17 @@ void
  * _cairo_array_index:
  *
  * Return value: A pointer to object stored at @index. If the
  * resulting value is assigned to a pointer to an object of the same
  * element_size as initially passed to _cairo_array_init() then that
  * pointer may be used for further direct indexing with []. For
  * example:
  *
- * 	cairo_array_t array;
+ * 	#cairo_array_t array;
  *	double *values;
  *
  *	_cairo_array_init (&array, sizeof(double));
  *	... calls to _cairo_array_append() here ...
  *
  *	values = _cairo_array_index (&array, 0);
  *      for (i = 0; i < _cairo_array_num_elements (&array); i++)
  *	    ... use values[i] here ...
@@ -226,17 +226,17 @@ void
  *
  * Append a single item onto the array by growing the array by at
  * least one element, then copying element_size bytes from @element
  * into the array. The address of the resulting object within the
  * array can be determined with:
  *
  * _cairo_array_index (array, _cairo_array_num_elements (array) - 1);
  *
- * Return value: CAIRO_STATUS_SUCCESS if successful or
+ * Return value: %CAIRO_STATUS_SUCCESS if successful or
  * CAIRO_STATUS_NO_MEMORY if insufficient memory is available for the
  * operation.
  **/
 cairo_status_t
 _cairo_array_append (cairo_array_t	*array,
 		     const void		*element)
 {
     assert (! array->is_snapshot);
@@ -246,17 +246,17 @@ cairo_status_t
 
 /**
  * _cairo_array_append:
  *
  * Append one or more items onto the array by growing the array by
  * @num_elements, then copying @num_elements * element_size bytes from
  * @elements into the array.
  *
- * Return value: CAIRO_STATUS_SUCCESS if successful or
+ * Return value: %CAIRO_STATUS_SUCCESS if successful or
  * CAIRO_STATUS_NO_MEMORY if insufficient memory is available for the
  * operation.
  **/
 cairo_status_t
 _cairo_array_append_multiple (cairo_array_t	*array,
 			      const void	*elements,
 			      int		 num_elements)
 {
@@ -277,17 +277,17 @@ cairo_status_t
 /**
  * _cairo_array_allocate:
  *
  * Allocate space at the end of the array for @num_elements additional
  * elements, providing the address of the new memory chunk in
  * @elements. This memory will be unitialized, but will be accounted
  * for in the return value of _cairo_array_num_elements().
  *
- * Return value: CAIRO_STATUS_SUCCESS if successful or
+ * Return value: %CAIRO_STATUS_SUCCESS if successful or
  * CAIRO_STATUS_NO_MEMORY if insufficient memory is available for the
  * operation.
  **/
 cairo_status_t
 _cairo_array_allocate (cairo_array_t	 *array,
 		       unsigned int	  num_elements,
 		       void		**elements)
 {
@@ -326,17 +326,17 @@ int
  * space allocated in array.
  **/
 int
 _cairo_array_size (cairo_array_t *array)
 {
     return array->size;
 }
 
-/* cairo_user_data_array_t */
+/* #cairo_user_data_array_t */
 
 typedef struct {
     const cairo_user_data_key_t *key;
     void *user_data;
     cairo_destroy_func_t destroy;
 } cairo_user_data_slot_t;
 
 /**
--- a/gfx/cairo/cairo/src/cairo-atsui-font.c
+++ b/gfx/cairo/cairo/src/cairo-atsui-font.c
@@ -203,16 +203,17 @@ CreateSizedCopyOfStyle(ATSUStyle inStyle
 
     return err;
 }
 
 
 static cairo_status_t
 _cairo_atsui_font_set_metrics (cairo_atsui_font_t *font)
 {
+    cairo_status_t status;
     ATSFontRef atsFont;
     ATSFontMetrics metrics;
     OSStatus err;
 
     atsFont = FMGetATSFontRefFromFont(font->fontID);
 
     if (atsFont) {
         err = ATSFontGetHorizontalMetrics(atsFont, kATSOptionFlagsDefault, &metrics);
@@ -223,19 +224,19 @@ static cairo_status_t
             extents.ascent = metrics.ascent;
             extents.descent = -metrics.descent;
             extents.height = extents.ascent + extents.descent + metrics.leading;
             extents.max_x_advance = metrics.maxAdvanceWidth;
 
             /* The FT backend doesn't handle max_y_advance either, so we'll ignore it for now. */
             extents.max_y_advance = 0.0;
 
-	    _cairo_scaled_font_set_metrics (&font->base, &extents);
+	    status = _cairo_scaled_font_set_metrics (&font->base, &extents);
 
-            return CAIRO_STATUS_SUCCESS;
+            return status;
         }
     }
 
     return _cairo_error (CAIRO_STATUS_NULL_POINTER);
 }
 
 static cairo_status_t
 _cairo_atsui_font_create_scaled (cairo_font_face_t *font_face,
@@ -251,30 +252,43 @@ static cairo_status_t
     cairo_status_t status;
     double xscale = 1.0;
     double yscale = 1.0;
 
     font = malloc(sizeof(cairo_atsui_font_t));
     if (font == NULL)
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
+    memset (font, 0, sizeof(cairo_atsui_font_t));
+
     status = _cairo_scaled_font_init (&font->base,
 				      font_face, font_matrix, ctm, options,
 				      &cairo_atsui_scaled_font_backend);
     if (status) {
 	free (font);
 	return status;
     }
 
-    _cairo_matrix_compute_scale_factors (&font->base.scale, 
-					 &xscale, &yscale, 1);
+    status = _cairo_matrix_compute_scale_factors (&font->base.scale,
+						  &xscale, &yscale, 1);
+    if (status)
+	goto FAIL;
+
+    /* ATS can't handle 0-sized bits; we end up in an odd infinite loop
+     * if we send down a size of 0. */
+    if (xscale == 0.0) {
+	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
+	goto FAIL;
+    }
+
     font->font_matrix = CGAffineTransformMake (1., 0.,
 					       0., yscale/xscale,
 					       0., 0.);
     font->size = FloatToFixed (xscale);
+    font->style = NULL;
 
     err = CreateSizedCopyOfStyle (style, &font->size, &font->font_matrix, &font->style);
     if (err != noErr) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto FAIL;
     }
 
     {
@@ -301,16 +315,17 @@ static cairo_status_t
     status = _cairo_atsui_font_set_metrics (font);
 
     font->cgfref = 0;
   FAIL:
     if (status) {
 	if (font) {
 	    if (font->style)
 		ATSUDisposeStyle(font->style);
+	    _cairo_scaled_font_fini(font);
 	    free (font);
 	}
 
 	return status;
     }
 
     return CAIRO_STATUS_SUCCESS;
 }
@@ -461,16 +476,17 @@ static GlyphID
 	return kATSDeletedGlyphcode;
     return index;
 }
 
 static cairo_status_t
 _cairo_atsui_font_init_glyph_metrics (cairo_atsui_font_t *scaled_font,
 				      cairo_scaled_glyph_t *scaled_glyph)
 {
+    cairo_status_t status;
     cairo_text_extents_t extents = {0, 0, 0, 0, 0, 0};
     OSStatus err;
     ATSGlyphScreenMetrics metricsH;
     GlyphID theGlyph = _cairo_atsui_scaled_glyph_index (scaled_glyph);
     double xscale, yscale;
 
     if (theGlyph == kATSDeletedGlyphcode) {
 	_cairo_scaled_glyph_set_metrics (scaled_glyph,
@@ -484,18 +500,21 @@ static cairo_status_t
      */
     err = ATSUGlyphGetScreenMetrics (scaled_font->style,
 				     1, &theGlyph, 0, false,
 				     false, &metricsH);
     if (err != noErr)
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     /* Scale down to font units.*/
-    _cairo_matrix_compute_scale_factors (&scaled_font->base.scale,
-					 &xscale, &yscale, 1);
+    status = _cairo_matrix_compute_scale_factors (&scaled_font->base.scale,
+						  &xscale, &yscale, 1);
+    if (status)
+	return status;
+
     xscale = 1.0/xscale;
     yscale = 1.0/yscale;
 
     extents.x_advance = metricsH.deviceAdvance.x * xscale;
     extents.y_advance = 0;
     
     extents.x_bearing = metricsH.topLeft.x * xscale;
     extents.y_bearing = -metricsH.topLeft.y * yscale;
@@ -596,16 +615,17 @@ static OSStatus
 
     return noErr;
 }
 
 static cairo_status_t
 _cairo_atsui_scaled_font_init_glyph_path (cairo_atsui_font_t *scaled_font,
 					  cairo_scaled_glyph_t *scaled_glyph)
 {
+    cairo_status_t status;
     static ATSCubicMoveToUPP moveProc = NULL;
     static ATSCubicLineToUPP lineProc = NULL;
     static ATSCubicCurveToUPP curveProc = NULL;
     static ATSCubicClosePathUPP closePathProc = NULL;
     GlyphID theGlyph = _cairo_atsui_scaled_glyph_index (scaled_glyph);
     OSStatus err;
     cairo_atsui_scaled_path_t scaled_path;
     cairo_matrix_t *font_to_device = &scaled_font->base.scale;
@@ -620,17 +640,20 @@ static cairo_status_t
     if (theGlyph == kATSDeletedGlyphcode) {
 	_cairo_scaled_glyph_set_path (scaled_glyph, &scaled_font->base, 
 				      scaled_path.path);
 
 	return CAIRO_STATUS_SUCCESS;
     }
 
     /* extract the rotation/shear component of the scale matrix. */
-    _cairo_matrix_compute_scale_factors (font_to_device, &xscale, &yscale, 1);
+    status = _cairo_matrix_compute_scale_factors (font_to_device, &xscale, &yscale, 1);
+    if (status)
+	goto FAIL;
+
     cairo_matrix_init (&unscaled_font_to_device, 
 		      font_to_device->xx, 
 		      font_to_device->yx, 
 		      font_to_device->xy, 
 		      font_to_device->yy, 0., 0.);
     cairo_matrix_scale (&unscaled_font_to_device, 1.0/xscale, 1.0/yscale);
 
     scaled_path.scale = &unscaled_font_to_device;
@@ -644,24 +667,28 @@ static cairo_status_t
 
     err = ATSUGlyphGetCubicPaths(scaled_font->style,
 				 theGlyph,
 				 moveProc,
 				 lineProc,
 				 curveProc,
 				 closePathProc, (void *)&scaled_path, &err);
     if (err != noErr) {
-	_cairo_path_fixed_destroy (scaled_path.path);
-	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
+	goto FAIL;
     }
 
     _cairo_scaled_glyph_set_path (scaled_glyph, &scaled_font->base, 
 				  scaled_path.path);
 
     return CAIRO_STATUS_SUCCESS;
+
+  FAIL:
+    _cairo_path_fixed_destroy (scaled_path.path);
+    return status;
 }
 
 static cairo_status_t
 _cairo_atsui_scaled_font_init_glyph_surface (cairo_atsui_font_t *scaled_font,
 					     cairo_scaled_glyph_t *scaled_glyph)
 {
     OSStatus err;
     CGContextRef drawingContext;
@@ -676,17 +703,16 @@ static cairo_status_t
 
     GlyphID theGlyph = _cairo_atsui_scaled_glyph_index (scaled_glyph);
     ATSGlyphScreenMetrics metricsH;
     double left, bottom, width, height;
     double xscale, yscale;
     CGRect bbox;
     CGAffineTransform transform;
 
-
     if (theGlyph == kATSDeletedGlyphcode) {
 	surface = (cairo_image_surface_t *)cairo_image_surface_create (CAIRO_FORMAT_A8, 2, 2);
 	status = cairo_surface_status ((cairo_surface_t *)surface);
 	if (status)
 	    return status;
 
 	_cairo_scaled_glyph_set_surface (scaled_glyph,
 					 &base,
@@ -696,18 +722,21 @@ static cairo_status_t
 
     /* Compute a box to contain the glyph mask. The vertical
      * sizes come from the font extents; extra pixels are
      * added to account for fractional sizes.
      */
     height = extents.ascent + extents.descent + 2.0;
     bottom = -extents.descent - 1.0;
 
-    _cairo_matrix_compute_scale_factors (&base.scale,
-					&xscale, &yscale, 1);
+    status = _cairo_matrix_compute_scale_factors (&base.scale,
+						  &xscale, &yscale, 1);
+    if (status)
+	return status;
+
     bbox = CGRectApplyAffineTransform (CGRectMake (1.0, bottom, 1.0, height), CGAffineTransformMakeScale(xscale, yscale));
     bottom = CGRectGetMinY (bbox);
     height = bbox.size.height;
 
     /* Horizontal sizes come from the glyph typographic metrics.
      * It is possible that this might result in clipped text
      * in fonts where the typographic bounds don't cover the ink.
      * The width is recalculated, since metricsH.width is rounded.
@@ -729,18 +758,21 @@ static cairo_status_t
      * [1  0][xx yx][1  0]
      * [0 -1][xy yy][0 -1]
      */
     transform = CGAffineTransformMake (base.scale.xx, 
 				      -base.scale.yx, 
 				      -base.scale.xy, 
 				      base.scale.yy, 
 				      0., 0.);
-    _cairo_matrix_compute_scale_factors (&base.scale, 
-					&xscale, &yscale, 1);
+    status = _cairo_matrix_compute_scale_factors (&base.scale,
+						  &xscale, &yscale, 1);
+    if (status)
+	return status;
+
     transform = CGAffineTransformScale (transform, 1.0/xscale, 1.0/yscale);
 
     /* Rotate the bounding box. This computes the smallest CGRect
      * that would contain the bounding box after rotation.
      */
     bbox = CGRectApplyAffineTransform (CGRectMake (left, bottom, 
 						   width, height), transform);
     /* Compute the smallest CGRect with  integer coordinates
@@ -891,24 +923,29 @@ static cairo_int_status_t
 							kATSUDirectDataLayoutRecordATSLayoutRecordCurrent,
 							(void *)&layoutRecords,
 							&glyphCount);
     if (err != noErr) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto BAIL2;
     }
 
+    status = _cairo_matrix_compute_scale_factors (&font->base.ctm,
+						  &xscale, &yscale, 1);
+    if (status)
+	goto BAIL2;
+
     *num_glyphs = glyphCount - 1;
     *glyphs =
 	(cairo_glyph_t *) _cairo_malloc_ab(*num_glyphs, sizeof (cairo_glyph_t));
     if (*glyphs == NULL) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto BAIL1;
     }
-    _cairo_matrix_compute_scale_factors (&font->base.ctm, &xscale, &yscale, 1);
+
     device_to_user_scale = 
 	CGAffineTransformInvert (CGAffineTransformMake (xscale, 0,
 							0, yscale,
 							0, 0));
     for (i = 0; i < *num_glyphs; i++) {
 	(*glyphs)[i].index = layoutRecords[i].glyphID;
 	/* ATSLayoutRecord.realPos is in device units, convert to user units */
 	point = CGPointMake (FixedToFloat (layoutRecords[i].realPos), 0);
--- a/gfx/cairo/cairo/src/cairo-base85-stream.c
+++ b/gfx/cairo/cairo/src/cairo-base85-stream.c
@@ -20,18 +20,17 @@
  * Version 1.1 (the "License"); you may not use this file except in
  * compliance with the License. You may obtain a copy of the License at
  * http://www.mozilla.org/MPL/
  *
  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
  * OF ANY KIND, either express or implied. See the LGPL or the MPL for
  * the specific language governing rights and limitations.
  *
- * The Original Code is cairo_output_stream.c as distributed with the
- *   cairo graphics library.
+ * The Original Code is the cairo graphics library.
  *
  * The Initial Developer of the Original Code is Red Hat, Inc.
  *
  * Author(s):
  *	Kristian Høgsberg <krh@redhat.com>
  */
 
 #include "cairoint.h"
--- a/gfx/cairo/cairo/src/cairo-bentley-ottmann.c
+++ b/gfx/cairo/cairo/src/cairo-bentley-ottmann.c
@@ -124,17 +124,17 @@ typedef struct _cairo_bo_event_queue {
     cairo_skip_list_t intersection_queue;
 
     cairo_bo_event_t *startstop_events;
     cairo_bo_event_t **sorted_startstop_event_ptrs;
     unsigned next_startstop_event_index;
     unsigned num_startstop_events;
 } cairo_bo_event_queue_t;
 
-/* This structure extends cairo_skip_list_t, which must come first. */
+/* This structure extends #cairo_skip_list_t, which must come first. */
 typedef struct _cairo_bo_sweep_line {
     cairo_skip_list_t active_edges;
     cairo_bo_edge_t *head;
     cairo_bo_edge_t *tail;
     int32_t current_y;
 } cairo_bo_sweep_line_t;
 
 
@@ -380,17 +380,17 @@ cairo_bo_event_compare (cairo_bo_event_t
 	    return -1;
     }
 
     /* At this stage we are looking at two events of the same type at
      * the same point. The final sort key is a slope comparison. We
      * need a different sense for start and stop events based on the
      * shortening rule.
      *
-     * NOTE: Fortunately, we get to ignore errors in the relative
+     * Note: Fortunately, we get to ignore errors in the relative
      * ordering of intersection events. This means we don't even have
      * to look at e2 here, nor worry about which sense of the slope
      * comparison test is used for intersection events.
      */
     cmp = _slope_compare (a->e1, b->e1);
     if (cmp) {
 	if (a->type == CAIRO_BO_EVENT_TYPE_START)
 	    return cmp;
@@ -502,17 +502,17 @@ det64_128 (cairo_int64_t a,
     bc = _cairo_int64x64_128_mul (b, c);
 
     return _cairo_int128_sub (ad, bc);
 }
 
 /* Compute the intersection of two lines as defined by two edges. The
  * result is provided as a coordinate pair of 128-bit integers.
  *
- * Returns CAIRO_BO_STATUS_INTERSECTION if there is an intersection or
+ * Returns %CAIRO_BO_STATUS_INTERSECTION if there is an intersection or
  * CAIRO_BO_STATUS_PARALLEL if the two lines are exactly parallel.
  */
 static cairo_bo_status_t
 intersect_lines (cairo_bo_edge_t		*a,
 		 cairo_bo_edge_t		*b,
 		 cairo_bo_intersect_point_t	*intersection)
 {
     cairo_int64_t a_det, b_det;
@@ -633,20 +633,20 @@ static cairo_bool_t
 	return (_cairo_bo_intersect_ordinate_32_compare (point->x, edge->top.x) > 0);
     else /* cmp_bottom == 0 */
 	return (_cairo_bo_intersect_ordinate_32_compare (point->x, edge->bottom.x) < 0);
 }
 
 /* Compute the intersection of two edges. The result is provided as a
  * coordinate pair of 128-bit integers.
  *
- * Returns CAIRO_BO_STATUS_INTERSECTION if there is an intersection
- * that is within both edges, CAIRO_BO_STATUS_NO_INTERSECTION if the
+ * Returns %CAIRO_BO_STATUS_INTERSECTION if there is an intersection
+ * that is within both edges, %CAIRO_BO_STATUS_NO_INTERSECTION if the
  * intersection of the lines defined by the edges occurs outside of
- * one or both edges, and CAIRO_BO_STATUS_PARALLEL if the two edges
+ * one or both edges, and %CAIRO_BO_STATUS_PARALLEL if the two edges
  * are exactly parallel.
  *
  * Note that when determining if a candidate intersection is "inside"
  * an edge, we consider both the infinitesimal shortening and the
  * infinitesimal tilt rules described by John Hobby. Specifically, if
  * the intersection is exactly the same as an edge point, it is
  * effectively outside (no intersection is returned). Also, if the
  * intersection point has the same
@@ -1048,17 +1048,17 @@ print_state (const char			*msg,
 {
     printf ("%s\n", msg);
     _cairo_bo_event_queue_print (event_queue);
     _cairo_bo_sweep_line_print (sweep_line);
     printf ("\n");
 }
 #endif
 
-/* Adds the trapezoid, if any, of the left edge to the cairo_traps_t
+/* Adds the trapezoid, if any, of the left edge to the #cairo_traps_t
  * of bo_traps. */
 static cairo_status_t
 _cairo_bo_edge_end_trap (cairo_bo_edge_t	*left,
 			 int32_t		bot,
 			 cairo_bo_traps_t	*bo_traps)
 {
     cairo_fixed_t fixed_top, fixed_bot;
     cairo_bo_trap_t *trap = left->deferred_trap;
--- a/gfx/cairo/cairo/src/cairo-beos-surface.cpp
+++ b/gfx/cairo/cairo/src/cairo-beos-surface.cpp
@@ -959,17 +959,17 @@ cairo_beos_surface_create (BView* view)
  * @bmp: The bitmap to which the view is attached
  *
  * Creates a Cairo surface that draws onto a BeOS BView which is attached to a
  * BBitmap.
  * The caller must ensure that the view and the bitmap do not get deleted
  * before the surface.
  *
  * For views that draw to a bitmap (as opposed to a screen), use this function
- * rather than cairo_beos_surface_create. Not using this function WILL lead to
+ * rather than cairo_beos_surface_create(). Not using this function WILL lead to
  * incorrect behaviour.
  *
  * For now, only views that draw to the entire area of bmp are supported.
  * The view must already be attached to the bitmap.
  **/
 cairo_surface_t *
 cairo_beos_surface_create_for_bitmap (BView*   view,
 				      BBitmap* bmp)
--- a/gfx/cairo/cairo/src/cairo-cache-private.h
+++ b/gfx/cairo/cairo/src/cairo-cache-private.h
@@ -41,26 +41,26 @@
 
 #include "cairo-compiler-private.h"
 #include "cairo-types-private.h"
 
 /**
  * cairo_cache_entry_t:
  *
  * A #cairo_cache_entry_t contains both a key and a value for
- * cairo_cache_t. User-derived types for cairo_cache_entry_t must
- * have a cairo_cache_entry_t as their first field. For example:
+ * #cairo_cache_t. User-derived types for #cairo_cache_entry_t must
+ * have a #cairo_cache_entry_t as their first field. For example:
  *
  * 	typedef _my_entry {
  *	    cairo_cache_entry_t base;
  *	    ... Remainder of key and value fields here ..
  *	} my_entry_t;
  *
  * which then allows a pointer to my_entry_t to be passed to any of
- * the cairo_cache functions as follows without requiring a cast:
+ * the #cairo_cache_t functions as follows without requiring a cast:
  *
  *	_cairo_cache_insert (cache, &my_entry->base, size);
  *
  * IMPORTANT: The caller is responsible for initializing
  * my_entry->base.hash with a hash code derived from the key.  The
  * essential property of the hash code is that keys_equal must never
  * return %TRUE for two keys that have different hashes. The best hash
  * code will reduce the frequency of two keys with the same code for
@@ -73,17 +73,17 @@
  * entries are close to the same size, the simplest thing to do is to
  * just use units of "entries", (eg. set size==1 in all entries and
  * set max_size to the number of entries which you want to be saved
  * in the cache).
  *
  * Which parts of the entry make up the "key" and which part make up
  * the value are entirely up to the caller, (as determined by the
  * computation going into base.hash as well as the keys_equal
- * function). A few of the cairo_cache functions accept an entry which
+ * function). A few of the #cairo_cache_t functions accept an entry which
  * will be used exclusively as a "key", (indicated by a parameter name
  * of key). In these cases, the value-related fields of the entry need
  * not be initialized if so desired.
  **/
 typedef struct _cairo_cache_entry {
     unsigned long hash;
     unsigned long size;
 } cairo_cache_entry_t;
--- a/gfx/cairo/cairo/src/cairo-cache.c
+++ b/gfx/cairo/cairo/src/cairo-cache.c
@@ -92,17 +92,17 @@ static void
  * @keys_equal: a function to return %TRUE if two keys are equal
  * @entry_destroy: destroy notifier for cache entries
  * @max_size: the maximum size for this cache
  *
  * Creates a new cache using the keys_equal() function to determine
  * the equality of entries.
  *
  * Data is provided to the cache in the form of user-derived version
- * of cairo_cache_entry_t. A cache entry must be able to hold hash
+ * of #cairo_cache_entry_t. A cache entry must be able to hold hash
  * code, a size, and the key/value pair being stored in the
  * cache. Sometimes only the key will be necessary, (as in
  * _cairo_cache_lookup()), and in these cases the value portion of the
  * entry need not be initialized.
  *
  * The units for max_size can be chosen by the caller, but should be
  * consistent with the units of the size field of cache entries. When
  * adding an entry with _cairo_cache_insert() if the total size of
@@ -167,17 +167,17 @@ void
  * @cache: a cache with some precious entries in it (or about to be
  * added)
  *
  * Disable the automatic ejection of entries from the cache. For as
  * long as the cache is "frozen", calls to _cairo_cache_insert() will
  * add new entries to the cache regardless of how large the cache
  * grows. See _cairo_cache_thaw().
  *
- * NOTE: Multiple calls to _cairo_cache_freeze() will stack, in that
+ * Note: Multiple calls to _cairo_cache_freeze() will stack, in that
  * the cache will remain "frozen" until a corresponding number of
  * calls are made to _cairo_cache_thaw().
  **/
 void
 _cairo_cache_freeze (cairo_cache_t *cache)
 {
     assert (cache->freeze_count >= 0);
 
@@ -234,18 +234,18 @@ cairo_bool_t
 }
 
 /**
  * _cairo_cache_remove_random:
  * @cache: a cache
  *
  * Remove a random entry from the cache.
  *
- * Return value: CAIRO_STATUS_SUCCESS if an entry was successfully
- * removed. CAIRO_INT_STATUS_CACHE_EMPTY if there are no entries that
+ * Return value: %CAIRO_STATUS_SUCCESS if an entry was successfully
+ * removed. %CAIRO_INT_STATUS_CACHE_EMPTY if there are no entries that
  * can be removed.
  **/
 static cairo_int_status_t
 _cairo_cache_remove_random (cairo_cache_t *cache)
 {
     cairo_cache_entry_t *entry;
 
     entry = _cairo_hash_table_random_entry (cache->hash_table, NULL);
@@ -290,17 +290,17 @@ static void
  * _cairo_cache_insert:
  * @cache: a cache
  * @entry: an entry to be inserted
  *
  * Insert @entry into the cache. If an entry exists in the cache with
  * a matching key, then the old entry will be removed first, (and the
  * entry_destroy() callback will be called on it).
  *
- * Return value: CAIRO_STATUS_SUCCESS if successful or
+ * Return value: %CAIRO_STATUS_SUCCESS if successful or
  * CAIRO_STATUS_NO_MEMORY if insufficient memory is available.
  **/
 cairo_status_t
 _cairo_cache_insert (cairo_cache_t	 *cache,
 		     cairo_cache_entry_t *entry)
 {
     cairo_status_t status;
 
@@ -318,17 +318,17 @@ cairo_status_t
 
 /**
  * _cairo_cache_remove:
  * @cache: a cache
  * @entry: an entry that exists in the cache
  *
  * Remove an existing entry from the cache.
  *
- * (NOTE: If any caller wanted access to a non-static version of this
+ * (Note: If any caller wanted access to a non-static version of this
  * function, an improved version would require only a key rather than
  * an entry. Fixing that would require fixing _cairo_hash_table_remove
  * to return (a copy of?) the entry being removed.)
  **/
 static void
 _cairo_cache_remove (cairo_cache_t	 *cache,
 		     cairo_cache_entry_t *entry)
 {
--- a/gfx/cairo/cairo/src/cairo-clip.c
+++ b/gfx/cairo/cairo/src/cairo-clip.c
@@ -446,32 +446,62 @@ static cairo_status_t
 	status = CAIRO_STATUS_SUCCESS;
 	if (clip->surface != NULL)
 	    cairo_surface_destroy (clip->surface);
 	goto DONE;
     }
 
     _cairo_pattern_init_solid (&pattern.solid, CAIRO_COLOR_WHITE,
 			       CAIRO_CONTENT_COLOR);
+    /* The clipping operation should ideally be something like the following to
+     * avoid having to do as many passes over the data
+
+	if (clip->surface != NULL) {
+	    _cairo_pattern_init_for_surface (&pattern.surface, clip->surface);
+	} else {
+	    _cairo_pattern_init_solid (&pattern.solid, CAIRO_COLOR_WHITE,
+			       CAIRO_CONTENT_COLOR);
+	}
+	status = _cairo_surface_composite_trapezoids (CAIRO_OPERATOR_IN,
+						  &pattern.base,
+						  surface,
+						  antialias,
+						  0, 0,
+						  0, 0,
+						  surface_rect.width,
+						  surface_rect.height,
+						  traps->traps,
+						  traps->num_traps);
+
+	However this operation is not accelerated by pixman
+
+	I believe the best possible operation would probably an unbounded SRC
+	operator.  Using SRC we could potentially avoid having to initialize
+	the surface which would be ideal from an efficiency point of view.
+	However, _cairo_surface_composite_trapezoids (CAIRO_OPERATOR_SOURCE) is
+	bounded by the mask.
+
+    */
+
     surface = _cairo_surface_create_similar_solid (target,
 						   CAIRO_CONTENT_ALPHA,
 						   surface_rect.width,
 						   surface_rect.height,
-						   CAIRO_COLOR_WHITE,
+						   CAIRO_COLOR_TRANSPARENT,
 						   &pattern.base);
     if (surface->status) {
 	_cairo_pattern_fini (&pattern.base);
 	return surface->status;
     }
 
     /* Render the new clipping path into the new mask surface. */
 
     _cairo_traps_translate (traps, -surface_rect.x, -surface_rect.y);
 
-    status = _cairo_surface_composite_trapezoids (CAIRO_OPERATOR_IN,
+    status = _cairo_surface_composite_trapezoids (CAIRO_OPERATOR_ADD,
 						  &pattern.base,
 						  surface,
 						  antialias,
 						  0, 0,
 						  0, 0,
 						  surface_rect.width,
 						  surface_rect.height,
 						  traps->traps,
--- a/gfx/cairo/cairo/src/cairo-debug.c
+++ b/gfx/cairo/cairo/src/cairo-debug.c
@@ -39,19 +39,19 @@
  * cairo_debug_reset_static_data:
  *
  * Resets all static data within cairo to its original state,
  * (ie. identical to the state at the time of program invocation). For
  * example, all caches within cairo will be flushed empty.
  *
  * This function is intended to be useful when using memory-checking
  * tools such as valgrind. When valgrind's memcheck analyzes a
- * cairo-using program without a call to cairo_debug_reset_static_data,
+ * cairo-using program without a call to cairo_debug_reset_static_data(),
  * it will report all data reachable via cairo's static objects as
- * "still reachable". Calling cairo_debug_reset_static_data just prior
+ * "still reachable". Calling cairo_debug_reset_static_data() just prior
  * to program termination will make it easier to get squeaky clean
  * reports from valgrind.
  *
  * WARNING: It is only safe to call this function when there are no
  * active cairo objects remaining, (ie. the appropriate destroy
  * functions have been called as necessary). If there are active cairo
  * objects, this call is likely to cause a crash, (eg. an assertion
  * failure due to a hash table being destroyed when non-empty).
--- a/gfx/cairo/cairo/src/cairo-deflate-stream.c
+++ b/gfx/cairo/cairo/src/cairo-deflate-stream.c
@@ -20,18 +20,17 @@
  * Version 1.1 (the "License"); you may not use this file except in
  * compliance with the License. You may obtain a copy of the License at
  * http://www.mozilla.org/MPL/
  *
  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
  * OF ANY KIND, either express or implied. See the LGPL or the MPL for
  * the specific language governing rights and limitations.
  *
- * The Original Code is cairo_output_stream.c as distributed with the
- *   cairo graphics library.
+ * The Original Code is the cairo graphics library.
  *
  * The Initial Developer of the Original Code is Adrian Johnson.
  *
  * Author(s):
  *	Adrian Johnson <ajohnson@redneon.com>
  */
 
 #include "cairoint.h"
--- a/gfx/cairo/cairo/src/cairo-deprecated.h
+++ b/gfx/cairo/cairo/src/cairo-deprecated.h
@@ -31,17 +31,17 @@
  *
  * Contributor(s):
  *	Carl D. Worth <cworth@cworth.org>
  */
 
 #ifndef CAIRO_DEPRECATED_H
 #define CAIRO_DEPRECATED_H
 
-/* The CAIRO_FORMAT_RGB16_565 value was added in cairo 1.2.0 as part
+/* The %CAIRO_FORMAT_RGB16_565 value was added in cairo 1.2.0 as part
  * of fixing cairo's xlib backend to work with X servers advertising a
  * 16-bit, 565 visual. But as it turned out, adding this format to
  * #cairo_format_t was not necessary, and was a mistake, (cairo's xlib
  * backend can work fine with 16-bit visuals in the same way it works
  * with BGR visuals without any BGR formats in
  * #cairo_format_t).
  *
  * Additionally, the support for the RGB16_565 format was never
--- a/gfx/cairo/cairo/src/cairo-directfb.h
+++ b/gfx/cairo/cairo/src/cairo-directfb.h
@@ -32,20 +32,20 @@
  *
  * Contributor(s):
  *	Carl D. Worth <cworth@isi.edu>
  */
 
 /*
  * Environment variables affecting the backend:
  *
- *  CAIRO_DIRECTFB_NO_ACCEL (boolean)
+ *  %CAIRO_DIRECTFB_NO_ACCEL (boolean)
  *      if found, disables acceleration at all
  *
- *  CAIRO_DIRECTFB_ARGB_FONT (boolean)
+ *  %CAIRO_DIRECTFB_ARGB_FONT (boolean)
  *      if found, enables using ARGB fonts instead of A8
  */
 
 #ifndef CAIRO_DIRECTFB_H
 #define CAIRO_DIRECTFB_H
 
 #include <cairo.h>
 
--- a/gfx/cairo/cairo/src/cairo-fixed-type-private.h
+++ b/gfx/cairo/cairo/src/cairo-fixed-type-private.h
@@ -56,15 +56,15 @@ typedef cairo_int128_t	cairo_fixed_96_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	8
 
-/* A signed type CAIRO_FIXED_BITS in size; the main fixed point type */
+/* 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 */
+/* An unsigned type of the same size as #cairo_fixed_t */
 typedef uint32_t cairo_fixed_unsigned_t;
 
 #endif /* CAIRO_FIXED_TYPE_PRIVATE_H */
--- a/gfx/cairo/cairo/src/cairo-font-face.c
+++ b/gfx/cairo/cairo/src/cairo-font-face.c
@@ -40,17 +40,17 @@
 
 #include "cairoint.h"
 
 /* Forward declare so we can use it as an arbitrary backend for
  * _cairo_font_face_nil.
  */
 static const cairo_font_face_backend_t _cairo_toy_font_face_backend;
 
-/* cairo_font_face_t */
+/* #cairo_font_face_t */
 
 const cairo_font_face_t _cairo_font_face_nil = {
     { 0 },			/* hash_entry */
     CAIRO_STATUS_NO_MEMORY,	/* status */
     CAIRO_REFERENCE_COUNT_INVALID,	/* ref_count */
     { 0, 0, 0, NULL },		/* user_data */
     &_cairo_toy_font_face_backend
 };
@@ -251,20 +251,20 @@ cairo_font_face_set_user_data (cairo_fon
 
 static const cairo_font_face_backend_t _cairo_toy_font_face_backend;
 
 static int
 _cairo_toy_font_face_keys_equal (const void *key_a,
 				 const void *key_b);
 
 /* We maintain a hash table from family/weight/slant =>
- * cairo_font_face_t for cairo_toy_font_t. The primary purpose of
- * this mapping is to provide unique cairo_font_face_t values so that
- * our cache and mapping from cairo_font_face_t => cairo_scaled_font_t
- * works. Once the corresponding cairo_font_face_t objects fall out of
+ * #cairo_font_face_t for #cairo_toy_font_t. The primary purpose of
+ * this mapping is to provide unique #cairo_font_face_t values so that
+ * our cache and mapping from #cairo_font_face_t => #cairo_scaled_font_t
+ * works. Once the corresponding #cairo_font_face_t objects fall out of
  * downstream caches, we don't need them in this hash table anymore.
  *
  * Modifications to this hash table are protected by
  * _cairo_font_face_mutex.
  */
 static cairo_hash_table_t *cairo_toy_font_face_hash_table = NULL;
 
 static cairo_hash_table_t *
@@ -290,21 +290,21 @@ static void
 _cairo_toy_font_face_hash_table_unlock (void)
 {
     CAIRO_MUTEX_UNLOCK (_cairo_font_face_mutex);
 }
 
 /**
  * _cairo_toy_font_face_init_key:
  *
- * Initialize those portions of cairo_toy_font_face_t needed to use
+ * Initialize those portions of #cairo_toy_font_face_t needed to use
  * it as a hash table key, including the hash code buried away in
  * font_face->base.hash_entry. No memory allocation is performed here
  * so that no fini call is needed. We do this to make it easier to use
- * an automatic cairo_toy_font_face_t variable as a key.
+ * an automatic #cairo_toy_font_face_t variable as a key.
  **/
 static void
 _cairo_toy_font_face_init_key (cairo_toy_font_face_t *key,
 			       const char	     *family,
 			       cairo_font_slant_t     slant,
 			       cairo_font_weight_t    weight)
 {
     unsigned long hash;
--- a/gfx/cairo/cairo/src/cairo-font-options.c
+++ b/gfx/cairo/cairo/src/cairo-font-options.c
@@ -236,17 +236,17 @@ cairo_font_options_equal (const cairo_fo
 }
 slim_hidden_def (cairo_font_options_equal);
 
 /**
  * cairo_font_options_hash:
  * @options: a #cairo_font_options_t
  *
  * Compute a hash for the font options object; this value will
- * be useful when storing an object containing a cairo_font_options_t
+ * be useful when storing an object containing a #cairo_font_options_t
  * in a hash table.
  *
  * Return value: the hash value for the font options object.
  *   The return value can be cast to a 32-bit type if a
  *   32-bit hash value is needed.
  **/
 unsigned long
 cairo_font_options_hash (const cairo_font_options_t *options)
--- a/gfx/cairo/cairo/src/cairo-freelist-private.h
+++ b/gfx/cairo/cairo/src/cairo-freelist-private.h
@@ -45,24 +45,24 @@ cairo_private void
 
 /* Deallocate any nodes in the freelist. */
 cairo_private void
 _cairo_freelist_fini (cairo_freelist_t *freelist);
 
 /* Allocate a new node from the freelist.  If the freelist contains no
  * nodes, a new one will be allocated using malloc().  The caller is
  * responsible for calling _cairo_freelist_free() or free() on the
- * returned node.  Returns NULL on memory allocation error. */
+ * returned node.  Returns %NULL on memory allocation error. */
 cairo_private void *
 _cairo_freelist_alloc (cairo_freelist_t *freelist);
 
 /* Allocate a new node from the freelist.  If the freelist contains no
  * nodes, a new one will be allocated using calloc().  The caller is
  * responsible for calling _cairo_freelist_free() or free() on the
- * returned node.  Returns NULL on memory allocation error. */
+ * returned node.  Returns %NULL on memory allocation error. */
 cairo_private void *
 _cairo_freelist_calloc (cairo_freelist_t *freelist);
 
 /* Return a node to the freelist. This does not deallocate the memory,
  * but makes it available for later reuse by
  * _cairo_freelist_alloc(). */
 cairo_private void
 _cairo_freelist_free (cairo_freelist_t *freelist, void *node);
--- a/gfx/cairo/cairo/src/cairo-ft-font.c
+++ b/gfx/cairo/cairo/src/cairo-ft-font.c
@@ -139,21 +139,21 @@ struct _cairo_ft_font_face {
     cairo_ft_unscaled_font_t *unscaled;
     cairo_ft_options_t ft_options;
     cairo_ft_font_face_t *next;
 };
 
 static const cairo_unscaled_font_backend_t cairo_ft_unscaled_font_backend;
 
 /*
- * We maintain a hash table to map file/id => cairo_ft_unscaled_font_t.
+ * We maintain a hash table to map file/id => #cairo_ft_unscaled_font_t.
  * The hash table itself isn't limited in size. However, we limit the
  * number of FT_Face objects we keep around; when we've exceeded that
  * limit and need to create a new FT_Face, we dump the FT_Face from a
- * random cairo_ft_unscaled_font_t which has an unlocked FT_Face, (if
+ * random #cairo_ft_unscaled_font_t which has an unlocked FT_Face, (if
  * there are any).
  */
 
 typedef struct _cairo_ft_unscaled_font_map {
     cairo_hash_table_t *hash_table;
     FT_Library ft_library;
     int num_open_faces;
 } cairo_ft_unscaled_font_map_t;
@@ -294,31 +294,31 @@ static void
     hash += ((unsigned long) id) * 1607;
 
     key->base.hash_entry.hash = hash;
 }
 
 /**
  * _cairo_ft_unscaled_font_init:
  *
- * Initialize a cairo_ft_unscaled_font_t.
+ * Initialize a #cairo_ft_unscaled_font_t.
  *
- * There are two basic flavors of cairo_ft_unscaled_font_t, one
+ * There are two basic flavors of #cairo_ft_unscaled_font_t, one
  * created from an FT_Face and the other created from a filename/id
  * pair. These two flavors are identified as from_face and !from_face.
  *
- * To initialize a from_face font, pass filename==NULL, id=0 and the
+ * To initialize a from_face font, pass filename==%NULL, id=0 and the
  * desired face.
  *
  * To initialize a !from_face font, pass the filename/id as desired
- * and face==NULL.
+ * and face==%NULL.
  *
  * Note that the code handles these two flavors in very distinct
  * ways. For example there is a hash_table mapping
- * filename/id->cairo_unscaled_font_t in the !from_face case, but no
+ * filename/id->#cairo_unscaled_font_t in the !from_face case, but no
  * parallel in the from_face case, (where the calling code would have
  * to do its own mapping to ensure similar sharing).
  **/
 static cairo_status_t
 _cairo_ft_unscaled_font_init (cairo_ft_unscaled_font_t *unscaled,
 			      const char	       *filename,
 			      int			id,
 			      FT_Face			face)
@@ -357,20 +357,20 @@ cairo_bool_t
 _cairo_unscaled_font_is_ft (cairo_unscaled_font_t *unscaled_font)
 {
     return unscaled_font->backend == &cairo_ft_unscaled_font_backend;
 }
 
 /**
  * _cairo_ft_unscaled_font_fini:
  *
- * Free all data associated with a cairo_ft_unscaled_font_t.
+ * Free all data associated with a #cairo_ft_unscaled_font_t.
  *
- * CAUTION: The unscaled->face field must be NULL before calling this
- * function. This is because the cairo_ft_unscaled_font_map keeps a
+ * CAUTION: The unscaled->face field must be %NULL before calling this
+ * function. This is because the #cairo_ft_unscaled_font_t_map keeps a
  * count of these faces (font_map->num_open_faces) so it maintains the
  * unscaled->face field while it has its lock held. See
  * _font_map_release_face_lock_held().
  **/
 static void
 _cairo_ft_unscaled_font_fini (cairo_ft_unscaled_font_t *unscaled)
 {
     assert (unscaled->face == NULL);
@@ -389,17 +389,17 @@ static int
 {
     const cairo_ft_unscaled_font_t *unscaled_a = key_a;
     const cairo_ft_unscaled_font_t *unscaled_b = key_b;
 
     return (strcmp (unscaled_a->filename, unscaled_b->filename) == 0 &&
 	    unscaled_a->id == unscaled_b->id);
 }
 
-/* Finds or creates a cairo_ft_unscaled_font for the filename/id from
+/* Finds or creates a #cairo_ft_unscaled_font_t for the filename/id from
  * pattern.  Returns a new reference to the unscaled font.
  */
 static cairo_ft_unscaled_font_t *
 _cairo_ft_unscaled_font_create_for_pattern (FcPattern *pattern)
 {
     cairo_ft_unscaled_font_t key, *unscaled;
     cairo_ft_unscaled_font_map_t *font_map;
     cairo_status_t status;
@@ -588,70 +588,78 @@ void
     assert (unscaled->lock_count > 0);
 
     unscaled->lock_count--;
 
     CAIRO_MUTEX_UNLOCK (unscaled->mutex);
 }
 slim_hidden_def (cairo_ft_scaled_font_unlock_face);
 
-static void
+static cairo_status_t
 _compute_transform (cairo_ft_font_transform_t *sf,
 		    cairo_matrix_t      *scale)
 {
+    cairo_status_t status;
     cairo_matrix_t normalized = *scale;
 
     /* The font matrix has x and y "scale" components which we extract and
      * use as character scale values. These influence the way freetype
      * chooses hints, as well as selecting different bitmaps in
      * hand-rendered fonts. We also copy the normalized matrix to
      * freetype's transformation.
      */
 
-    _cairo_matrix_compute_scale_factors (&normalized,
-					 &sf->x_scale, &sf->y_scale,
-					 /* XXX */ 1);
+    status = _cairo_matrix_compute_scale_factors (&normalized,
+						  &sf->x_scale, &sf->y_scale,
+						  /* XXX */ 1);
+    if (status)
+	return status;
 
     if (sf->x_scale != 0 && sf->y_scale != 0) {
 	cairo_matrix_scale (&normalized, 1.0 / sf->x_scale, 1.0 / sf->y_scale);
 
 	_cairo_matrix_get_affine (&normalized,
 				  &sf->shape[0][0], &sf->shape[0][1],
 				  &sf->shape[1][0], &sf->shape[1][1],
 				  NULL, NULL);
     } else {
 	sf->shape[0][0] = sf->shape[1][1] = 1.0;
 	sf->shape[0][1] = sf->shape[1][0] = 0.0;
     }
+
+    return CAIRO_STATUS_SUCCESS;
 }
 
 /* Temporarily scales an unscaled font to the give scale. We catch
  * scaling to the same size, since changing a FT_Face is expensive.
  */
 static cairo_status_t
 _cairo_ft_unscaled_font_set_scale (cairo_ft_unscaled_font_t *unscaled,
 				   cairo_matrix_t	      *scale)
 {
+    cairo_status_t status;
     cairo_ft_font_transform_t sf;
     FT_Matrix mat;
     FT_Error error;
 
     assert (unscaled->face != NULL);
 
     if (unscaled->have_scale &&
 	scale->xx == unscaled->current_scale.xx &&
 	scale->yx == unscaled->current_scale.yx &&
 	scale->xy == unscaled->current_scale.xy &&
 	scale->yy == unscaled->current_scale.yy)
 	return CAIRO_STATUS_SUCCESS;
 
     unscaled->have_scale = TRUE;
     unscaled->current_scale = *scale;
 
-    _compute_transform (&sf, scale);
+    status = _compute_transform (&sf, scale);
+    if (status)
+	return status;
 
     unscaled->x_scale = sf.x_scale;
     unscaled->y_scale = sf.y_scale;
 
     mat.xx = DOUBLE_TO_16_16(sf.shape[0][0]);
     mat.yx = - DOUBLE_TO_16_16(sf.shape[0][1]);
     mat.xy = - DOUBLE_TO_16_16(sf.shape[1][0]);
     mat.yy = DOUBLE_TO_16_16(sf.shape[1][1]);
@@ -1252,17 +1260,17 @@ static cairo_status_t
 
 static const cairo_unscaled_font_backend_t cairo_ft_unscaled_font_backend = {
     _cairo_ft_unscaled_font_destroy,
 #if 0
     _cairo_ft_unscaled_font_create_glyph
 #endif
 };
 
-/* cairo_ft_scaled_font_t */
+/* #cairo_ft_scaled_font_t */
 
 typedef struct _cairo_ft_scaled_font {
     cairo_scaled_font_t base;
     cairo_ft_unscaled_font_t *unscaled;
     cairo_ft_options_t ft_options;
 } cairo_ft_scaled_font_t;
 
 const cairo_scaled_font_backend_t cairo_ft_scaled_font_backend;
@@ -1296,19 +1304,16 @@ static void
     /* disable antialiasing if requested */
     if (FcPatternGetBool (pattern,
 			  FC_ANTIALIAS, 0, &antialias) != FcResultMatch)
 	antialias = FcTrue;
     
     if (antialias) {
 	cairo_subpixel_order_t subpixel_order;
 
-	if (!bitmap)
-	    ft_options.load_flags |= FT_LOAD_NO_BITMAP;
-	
 	/* disable hinting if requested */
 	if (FcPatternGetBool (pattern,
 			      FC_HINTING, 0, &hinting) != FcResultMatch)
 	    hinting = FcTrue;
 
 	if (FcPatternGetInteger (pattern,
 				 FC_RGBA, 0, &rgba) != FcResultMatch)
 	    rgba = FC_RGBA_UNKNOWN;
@@ -1361,16 +1366,24 @@ static void
 	    ft_options.base.hint_style = CAIRO_HINT_STYLE_FULL;
 	    break;
 	}
 #else /* !FC_HINT_STYLE */
 	if (!hinting) {
 	    ft_options.base.hint_style = CAIRO_HINT_STYLE_NONE;
 	}
 #endif /* FC_HINT_STYLE */
+
+	/* Force embedded bitmaps off if no hinting requested */
+	if (ft_options.base.hint_style == CAIRO_HINT_STYLE_NONE)
+	  bitmap = FcFalse;
+
+	if (!bitmap)
+	    ft_options.load_flags |= FT_LOAD_NO_BITMAP;
+
     } else {
 	ft_options.base.antialias = CAIRO_ANTIALIAS_NONE;
     }
 
     /* force autohinting if requested */
     if (FcPatternGetBool (pattern,
 			  FC_AUTOHINT, 0, &autohint) != FcResultMatch)
 	autohint = FcFalse;
@@ -1521,18 +1534,23 @@ static cairo_status_t
     }
 
 
     metrics = &face->size->metrics;
 
     /*
      * Get to unscaled metrics so that the upper level can get back to
      * user space
+     *
+     * Also use this path for bitmap-only fonts.  The other branch uses
+     * face members that are only relevant for scalable fonts.  This is
+     * detected by simply checking for units_per_EM==0.
      */
-    if (scaled_font->base.options.hint_metrics != CAIRO_HINT_METRICS_OFF) {
+    if (scaled_font->base.options.hint_metrics != CAIRO_HINT_METRICS_OFF ||
+	face->units_per_EM == 0) {
 	double x_factor, y_factor;
 
 	if (unscaled->x_scale == 0)
 	    x_factor = 0;
 	else
 	    x_factor = 1 / unscaled->x_scale;
 
 	if (unscaled->y_scale == 0)
@@ -1560,17 +1578,17 @@ static cairo_status_t
 	    fs_metrics.max_x_advance = face->max_advance_width / scale;
 	    fs_metrics.max_y_advance = 0;
 	} else {
 	    fs_metrics.max_x_advance = 0;
 	    fs_metrics.max_y_advance = face->max_advance_height / scale;
 	}
     }
 
-    _cairo_scaled_font_set_metrics (&scaled_font->base, &fs_metrics);
+    status = _cairo_scaled_font_set_metrics (&scaled_font->base, &fs_metrics);
 
     *font_out = &scaled_font->base;
 
  FAIL:
     _cairo_ft_unscaled_font_unlock_face (unscaled);
 
     return status;
 }
@@ -2190,17 +2208,17 @@ const cairo_scaled_font_backend_t cairo_
     _cairo_ft_scaled_glyph_init,
     NULL,			/* text_to_glyphs */
     _cairo_ft_ucs4_to_index,
     NULL, 			/* show_glyphs */
     _cairo_ft_load_truetype_table,
     _cairo_ft_map_glyphs_to_unicode,
 };
 
-/* cairo_ft_font_face_t */
+/* #cairo_ft_font_face_t */
 
 static void
 _cairo_ft_font_face_destroy (void *abstract_face)
 {
     cairo_ft_font_face_t *font_face = abstract_face;
 
     cairo_ft_font_face_t *tmp_face = NULL;
     cairo_ft_font_face_t *last_face = NULL;
@@ -2604,17 +2622,17 @@ cairo_ft_scaled_font_lock_face (cairo_sc
     status = _cairo_ft_unscaled_font_set_scale (scaled_font->unscaled,
 				                &scaled_font->base.scale);
     if (status) {
 	_cairo_ft_unscaled_font_unlock_face (scaled_font->unscaled);
 	status = _cairo_scaled_font_set_error (&scaled_font->base, status);
 	return NULL;
     }
 
-    /* NOTE: We deliberately release the unscaled font's mutex here,
+    /* Note: We deliberately release the unscaled font's mutex here,
      * so that we are not holding a lock across two separate calls to
      * cairo function, (which would give the application some
      * opportunity for creating deadlock. This is obviously unsafe,
      * but as documented, the user must add manual locking when using
      * this function. */
      CAIRO_MUTEX_UNLOCK (scaled_font->unscaled->mutex);
 
     return face;
@@ -2632,17 +2650,17 @@ cairo_ft_scaled_font_lock_face (cairo_sc
 void
 cairo_ft_scaled_font_unlock_face (cairo_scaled_font_t *abstract_font)
 {
     cairo_ft_scaled_font_t *scaled_font = (cairo_ft_scaled_font_t *) abstract_font;
 
     if (scaled_font->base.status)
 	return;
 
-    /* NOTE: We released the unscaled font's mutex at the end of
+    /* Note: We released the unscaled font's mutex at the end of
      * cairo_ft_scaled_font_lock_face, so we have to acquire it again
      * as _cairo_ft_unscaled_font_unlock_face expects it to be held
      * when we call into it. */
     CAIRO_MUTEX_LOCK (scaled_font->unscaled->mutex);
 
     _cairo_ft_unscaled_font_unlock_face (scaled_font->unscaled);
 }
 
--- a/gfx/cairo/cairo/src/cairo-gstate.c
+++ b/gfx/cairo/cairo/src/cairo-gstate.c
@@ -121,17 +121,17 @@ cairo_status_t
 
     return CAIRO_STATUS_SUCCESS;
 }
 
 /**
  * _cairo_gstate_init_copy:
  *
  * Initialize @gstate by performing a deep copy of state fields from
- * @other. Note that gstate->next is not copied but is set to NULL by
+ * @other. Note that gstate->next is not copied but is set to %NULL by
  * this function.
  **/
 static cairo_status_t
 _cairo_gstate_init_copy (cairo_gstate_t *gstate, cairo_gstate_t *other)
 {
     cairo_status_t status;
 
     gstate->op = other->op;
@@ -210,24 +210,24 @@ static void
 	return;
 
     _cairo_gstate_fini (gstate);
     free (gstate);
 }
 
 /**
  * _cairo_gstate_clone:
- * @other: a #cairo_gstate_t to be copied, not NULL.
+ * @other: a #cairo_gstate_t to be copied, not %NULL.
  *
  * Create a new #cairo_gstate_t setting all graphics state parameters
  * to the same values as contained in @other. gstate->next will be set
- * to NULL and may be used by the caller to chain cairo_gstate_t
+ * to %NULL and may be used by the caller to chain #cairo_gstate_t
  * objects together.
  *
- * Return value: a new cairo_gstate_t or NULL if there is insufficient
+ * Return value: a new #cairo_gstate_t or %NULL if there is insufficient
  * memory.
  **/
 static cairo_gstate_t*
 _cairo_gstate_clone (cairo_gstate_t *other)
 {
     cairo_status_t status;
     cairo_gstate_t *gstate;
 
@@ -359,18 +359,18 @@ cairo_status_t
 
     return CAIRO_STATUS_SUCCESS;
 }
 
 /**
  * _cairo_gstate_is_redirected
  * @gstate: a #cairo_gstate_t
  *
- * Return value: TRUE if the gstate is redirected to a target
- * different than the original, FALSE otherwise.
+ * Return value: %TRUE if the gstate is redirected to a target
+ * different than the original, %FALSE otherwise.
  **/
 cairo_bool_t
 _cairo_gstate_is_redirected (cairo_gstate_t *gstate)
 {
     return (gstate->target != gstate->original_target);
 }
 
 /**
@@ -388,17 +388,17 @@ cairo_surface_t *
     return gstate->target;
 }
 
 /**
  * _cairo_gstate_get_parent_target:
  * @gstate: a #cairo_gstate_t
  *
  * Return the parent surface of the current drawing target surface;
- * if this particular gstate isn't a redirect gstate, this will return NULL.
+ * if this particular gstate isn't a redirect gstate, this will return %NULL.
  **/
 cairo_surface_t *
 _cairo_gstate_get_parent_target (cairo_gstate_t *gstate)
 {
     return gstate->parent_target;
 }
 
 /**
@@ -417,17 +417,17 @@ cairo_surface_t *
 {
     return gstate->original_target;
 }
 
 /**
  * _cairo_gstate_get_clip:
  * @gstate: a #cairo_gstate_t
  *
- * Return value: a pointer to the gstate's cairo_clip_t structure.
+ * Return value: a pointer to the gstate's #cairo_clip_t structure.
  */
 cairo_clip_t *
 _cairo_gstate_get_clip (cairo_gstate_t *gstate)
 {
     return &gstate->clip;
 }
 
 cairo_status_t
@@ -1146,23 +1146,25 @@ BAIL:
     _cairo_traps_fini (&traps);
 
     return status;
 }
 
 cairo_status_t
 _cairo_gstate_copy_page (cairo_gstate_t *gstate)
 {
-    return cairo_surface_copy_page (gstate->target);
+    cairo_surface_copy_page (gstate->target);
+    return cairo_surface_status (gstate->target);
 }
 
 cairo_status_t
 _cairo_gstate_show_page (cairo_gstate_t *gstate)
 {
-    return cairo_surface_show_page (gstate->target);
+    cairo_surface_show_page (gstate->target);
+    return cairo_surface_status (gstate->target);
 }
 
 static void
 _cairo_gstate_traps_extents_to_user_rectangle (cairo_gstate_t	  *gstate,
                                                cairo_traps_t      *traps,
                                                double *x1, double *y1,
                                                double *x2, double *y2)
 {
@@ -1462,17 +1464,17 @@ cairo_status_t
  *
  *   [ 12.0, 0.0, 0.0, 12.0, 0.0, 0.0 ]
  *
  * It is an affine matrix, like all cairo matrices, where its tx and ty
  * components are used to "nudging" fonts around and are handled in gstate
  * and then ignored by the "scaled-font" layer.
  *
  * In order to perform any action on a font, we must build an object
- * called a cairo_font_scale_t; this contains the central 2x2 matrix
+ * called a #cairo_font_scale_t; this contains the central 2x2 matrix
  * resulting from "font matrix * CTM" (sans the font matrix translation
  * components as stated in the previous paragraph).
  *
  * We pass this to the font when making requests of it, which causes it to
  * reply for a particular [user request, device] combination, under the CTM
  * (to accommodate the "zoom in" == "bigger fonts" issue above).
  *
  * The other terms in our communication with the font are therefore in
--- a/gfx/cairo/cairo/src/cairo-hash.c
+++ b/gfx/cairo/cairo/src/cairo-hash.c
@@ -37,24 +37,24 @@
  */
 
 #include "cairoint.h"
 
 /*
  * An entry can be in one of three states:
  *
  * FREE: Entry has never been used, terminates all searches.
- *       Appears in the table as a NULL pointer.
+ *       Appears in the table as a %NULL pointer.
  *
  * DEAD: Entry had been live in the past. A dead entry can be reused
  *       but does not terminate a search for an exact entry.
  *       Appears in the table as a pointer to DEAD_ENTRY.
  *
  * LIVE: Entry is currently being used.
- *       Appears in the table as any non-NULL, non-DEAD_ENTRY pointer.
+ *       Appears in the table as any non-%NULL, non-DEAD_ENTRY pointer.
  */
 
 static cairo_hash_entry_t dead_entry = { 0 };
 #define DEAD_ENTRY (&dead_entry)
 
 #define ENTRY_IS_FREE(entry) ((entry) == NULL)
 #define ENTRY_IS_DEAD(entry) ((entry) == DEAD_ENTRY)
 #define ENTRY_IS_LIVE(entry) ((entry) && ! ENTRY_IS_DEAD(entry))
@@ -124,29 +124,29 @@ struct _cairo_hash_table {
     cairo_hash_entry_t **entries;
 
     unsigned long live_entries;
     unsigned long iterating;   /* Iterating, no insert, no resize */
 };
 
 /**
  * _cairo_hash_table_create:
- * @keys_equal: a function to return TRUE if two keys are equal
+ * @keys_equal: a function to return %TRUE if two keys are equal
  *
  * Creates a new hash table which will use the keys_equal() function
  * to compare hash keys. Data is provided to the hash table in the
- * form of user-derived versions of cairo_hash_entry_t. A hash entry
+ * form of user-derived versions of #cairo_hash_entry_t. A hash entry
  * must be able to hold both a key (including a hash code) and a
  * value. Sometimes only the key will be necessary, (as in
  * _cairo_hash_table_remove), and other times both a key and a value
  * will be necessary, (as in _cairo_hash_table_insert).
  *
  * See #cairo_hash_entry_t for more details.
  *
- * Return value: the new hash table or NULL if out of memory.
+ * Return value: the new hash table or %NULL if out of memory.
  **/
 cairo_hash_table_t *
 _cairo_hash_table_create (cairo_hash_keys_equal_func_t keys_equal)
 {
     cairo_hash_table_t *hash_table;
 
     hash_table = malloc (sizeof (cairo_hash_table_t));
     if (hash_table == NULL) {
@@ -207,19 +207,19 @@ void
 }
 
 /**
  * _cairo_hash_table_lookup_internal:
  *
  * @hash_table: a #cairo_hash_table_t to search
  * @key: the key to search on
  * @hash_code: the hash_code for @key
- * @key_unique: If TRUE, then caller asserts that no key already
+ * @key_unique: If %TRUE, then caller asserts that no key already
  * exists that will compare equal to #key, so search can be
- * optimized. If unsure, set to FALSE and the code will always work.
+ * optimized. If unsure, set to %FALSE and the code will always work.
  *
  * Search the hashtable for a live entry for which
  * hash_table->keys_equal returns true. If no such entry exists then
  * return the first available (free or dead entry).
  *
  * If the key_unique flag is set, then the search will never call
  * hash_table->keys_equal and will act as if it always returned
  * false. This is useful as a performance optimization in special
@@ -290,17 +290,17 @@ static cairo_hash_entry_t **
 /**
  * _cairo_hash_table_resize:
  * @hash_table: a hash table
  *
  * Resize the hash table if the number of entries has gotten much
  * bigger or smaller than the ideal number of entries for the current
  * size.
  *
- * Return value: CAIRO_STATUS_SUCCESS if successful or
+ * Return value: %CAIRO_STATUS_SUCCESS if successful or
  * CAIRO_STATUS_NO_MEMORY if out of memory.
  **/
 static cairo_status_t
 _cairo_hash_table_resize  (cairo_hash_table_t *hash_table)
 {
     cairo_hash_table_t tmp;
     cairo_hash_entry_t **entry;
     unsigned long new_size, i;
@@ -356,19 +356,19 @@ static cairo_status_t
  * @hash_table: a hash table
  * @key: the key of interest
  * @entry_return: pointer for return value.
  *
  * Performs a lookup in @hash_table looking for an entry which has a
  * key that matches @key, (as determined by the keys_equal() function
  * passed to _cairo_hash_table_create).
  *
- * Return value: TRUE if there is an entry in the hash table that
- * matches the given key, (which will now be in *entry_return). FALSE
- * otherwise, (in which case *entry_return will be NULL).
+ * Return value: %TRUE if there is an entry in the hash table that
+ * matches the given key, (which will now be in *entry_return). %FALSE
+ * otherwise, (in which case *entry_return will be %NULL).
  **/
 cairo_bool_t
 _cairo_hash_table_lookup (cairo_hash_table_t *hash_table,
 			  cairo_hash_entry_t *key,
 			  cairo_hash_entry_t **entry_return)
 {
     cairo_hash_entry_t **entry;
 
@@ -381,32 +381,32 @@ cairo_bool_t
 
     *entry_return = NULL;
     return FALSE;
 }
 
 /**
  * _cairo_hash_table_random_entry:
  * @hash_table: a hash table
- * @predicate: a predicate function, or NULL for any entry.
+ * @predicate: a predicate function, or %NULL for any entry.
  *
  * Find a random entry in the hash table satisfying the given
- * @predicate. A NULL @predicate is taken as equivalent to a function
- * which always returns TRUE, (eg. any entry in the table will do).
+ * @predicate. A %NULL @predicate is taken as equivalent to a function
+ * which always returns %TRUE, (eg. any entry in the table will do).
  *
  * We use the same algorithm as the lookup algorithm to walk over the
  * entries in the hash table in a pseudo-random order. Walking
  * linearly would favor entries following gaps in the hash table. We
  * could also call rand() repeatedly, which works well for almost-full
  * tables, but degrades when the table is almost empty, or predicate
- * returns TRUE for most entries.
+ * returns %TRUE for most entries.
  *
- * Return value: a random live entry or NULL if there are no entries
+ * Return value: a random live entry or %NULL if there are no entries
  * that match the given predicate. In particular, if predicate is
- * NULL, a NULL return value indicates that the table is empty.
+ * NULL, a %NULL return value indicates that the table is empty.
  **/
 void *
 _cairo_hash_table_random_entry (cairo_hash_table_t	   *hash_table,
 				cairo_hash_predicate_func_t predicate)
 {
     cairo_hash_entry_t **entry;
     unsigned long hash;
     unsigned long table_size, i, idx, step;
@@ -453,17 +453,17 @@ void *
  *
  * WARNING: It is a fatal error to insert an element while
  * an iterator is running
  *
  * Instead of using insert to replace an entry, consider just editing
  * the entry obtained with _cairo_hash_table_lookup. Or if absolutely
  * necessary, use _cairo_hash_table_remove first.
  *
- * Return value: CAIRO_STATUS_SUCCESS if successful or
+ * Return value: %CAIRO_STATUS_SUCCESS if successful or
  * CAIRO_STATUS_NO_MEMORY if insufficient memory is available.
  **/
 cairo_status_t
 _cairo_hash_table_insert (cairo_hash_table_t *hash_table,
 			  cairo_hash_entry_t *key_and_value)
 {
     cairo_status_t status;
     cairo_hash_entry_t **entry;
@@ -498,17 +498,17 @@ cairo_status_t
  * _cairo_hash_table_remove:
  * @hash_table: a hash table
  * @key: key of entry to be removed
  *
  * Remove an entry from the hash table which has a key that matches
  * @key, if any (as determined by the keys_equal() function passed to
  * _cairo_hash_table_create).
  *
- * Return value: CAIRO_STATUS_SUCCESS if successful or
+ * Return value: %CAIRO_STATUS_SUCCESS if successful or
  * CAIRO_STATUS_NO_MEMORY if out of memory.
  **/
 void
 _cairo_hash_table_remove (cairo_hash_table_t *hash_table,
 			  cairo_hash_entry_t *key)
 {
     cairo_hash_entry_t **entry;
 
--- a/gfx/cairo/cairo/src/cairo-image-surface.c
+++ b/gfx/cairo/cairo/src/cairo-image-surface.c
@@ -275,17 +275,17 @@ void
 	break;
     }
 }
 
 
 /* XXX: This function really should be eliminated. We don't really
  * want to advertise a cairo image surface that supports any possible
  * format. A minimal step would be to replace this function with one
- * that accepts a cairo_internal_format_t rather than mask values. */
+ * that accepts a #cairo_internal_format_t rather than mask values. */
 cairo_surface_t *
 _cairo_image_surface_create_with_masks (unsigned char	       *data,
 					cairo_format_masks_t   *masks,
 					int			width,
 					int			height,
 					int			stride)
 {
     pixman_format_code_t pixman_format;
@@ -353,17 +353,17 @@ cairo_surface_t *
  *
  * Creates an image surface of the specified format and
  * dimensions. Initially the surface contents are all
  * 0. (Specifically, within each pixel, each color or alpha channel
  * belonging to format will be 0. The contents of bits within a pixel,
  * but not belonging to the given format are undefined).
  *
  * Return value: a pointer to the newly created surface. The caller
- * owns the surface and should call cairo_surface_destroy when done
+ * owns the surface and should call cairo_surface_destroy() when done
  * with it.
  *
  * This function always returns a valid pointer, but it will return a
  * pointer to a "nil" surface if an error such as out of memory
  * occurs. You can use cairo_surface_status() to check for this.
  **/
 cairo_surface_t *
 cairo_image_surface_create (cairo_format_t	format,
@@ -389,61 +389,111 @@ cairo_surface_t *
 {
     if (! CAIRO_CONTENT_VALID (content))
 	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_CONTENT));
 
     return cairo_image_surface_create (_cairo_format_from_content (content),
 				       width, height);
 }
 
+/* pixman required stride alignment in bytes.  should be power of two. */
+#define STRIDE_ALIGNMENT (sizeof (uint32_t))
+
+/**
+ * cairo_format_stride_for_width:
+ * @format: A #cairo_format_t value
+ * @width: The desired width of an image surface to be created.
+ *
+ * This function provides a stride value that will respect all
+ * alignment requirements of the accelerated image-rendering code
+ * within cairo. Typical usage will be of the form:
+ *
+ * <informalexample><programlisting>
+ * int stride;
+ * unsigned char *data;
+ * #cairo_surface_t *surface;
+ *
+ * stride = cairo_format_stride_for_width (format, width);
+ * data = malloc (stride * height);
+ * surface = cairo_image_surface_create_for_data (data, format,
+ *						  width, height);
+ * </programlisting></informalexample>
+ *
+ * Return value: the appropriate stride to use given the desired
+ * format and width.
+ *
+ * Since: 1.6
+ **/
+int
+cairo_format_stride_for_width (cairo_format_t	format,
+			       int		width)
+{
+    int bpp = _cairo_format_bits_per_pixel (format);
+
+    return ((bpp*width+7)/8 + STRIDE_ALIGNMENT-1) & ~(STRIDE_ALIGNMENT-1);
+}
+
 /**
  * cairo_image_surface_create_for_data:
- * @data: a pointer to a buffer supplied by the application
- *    in which to write contents.
+ * @data: a pointer to a buffer supplied by the application in which
+ *     to write contents. This pointer must be suitably aligned for any
+ *     kind of variable, (for example, a pointer returned by malloc).
  * @format: the format of pixels in the buffer
  * @width: the width of the image to be stored in the buffer
  * @height: the height of the image to be stored in the buffer
- * @stride: the number of bytes between the start of rows
- *   in the buffer. Having this be specified separate from @width
- *   allows for padding at the end of rows, or for writing
- *   to a subportion of a larger image.
+ * @stride: the number of bytes between the start of rows in the
+ *     buffer as allocated. This value should always be computed by
+ *     cairo_format_stride_for_width() before allocating the data
+ *     buffer.
  *
  * Creates an image surface for the provided pixel data. The output
  * buffer must be kept around until the #cairo_surface_t is destroyed
  * or cairo_surface_finish() is called on the surface.  The initial
  * contents of @buffer will be used as the initial image contents; you
  * must explicitly clear the buffer, using, for example,
  * cairo_rectangle() and cairo_fill() if you want it cleared.
  *
+ * Note that the stride may be larger than
+ * width*bytes_per_pixel to provide proper alignment for each pixel
+ * and row. This alignment is required to allow high-performance rendering
+ * within cairo. The correct way to obtain a legal stride value is to
+ * call cairo_format_stride_for_width() with the desired format and
+ * maximum image width value, and the use the resulting stride value
+ * to allocate the data and to create the image surface. See
+ * cairo_format_stride_for_width() for example code.
+ *
  * Return value: a pointer to the newly created surface. The caller
- * owns the surface and should call cairo_surface_destroy when done
+ * owns the surface and should call cairo_surface_destroy() when done
  * with it.
  *
  * This function always returns a valid pointer, but it will return a
- * pointer to a "nil" surface if an error such as out of memory
- * occurs. You can use cairo_surface_status() to check for this.
+ * pointer to a "nil" surface in the case of an error such as out of
+ * memory or an invalid stride value. In case of invalid stride value
+ * the error status of the returned surface will be
+ * %CAIRO_STATUS_INVALID_STRIDE.  You can use
+ * cairo_surface_status() to check for this.
  *
  * See cairo_surface_set_user_data() for a means of attaching a
  * destroy-notification fallback to the surface if necessary.
  **/
 cairo_surface_t *
 cairo_image_surface_create_for_data (unsigned char     *data,
 				     cairo_format_t	format,
 				     int		width,
 				     int		height,
 				     int		stride)
 {
     pixman_format_code_t pixman_format;
 
-    /* XXX pixman does not support images with arbitrary strides and
-     * attempting to create such surfaces will failure but we will interpret
-     * such failure as CAIRO_STATUS_NO_MEMORY.  */
-    if (! CAIRO_FORMAT_VALID (format) || stride % sizeof (uint32_t) != 0)
+    if (! CAIRO_FORMAT_VALID (format))
 	return _cairo_surface_create_in_error (_cairo_error(CAIRO_STATUS_INVALID_FORMAT));
 
+    if ((stride & (STRIDE_ALIGNMENT-1)) != 0)
+	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_STRIDE));
+
     pixman_format = _cairo_format_to_pixman_format_code (format);
 
     return _cairo_image_surface_create_with_pixman_format (data, pixman_format,
 							   width, height, stride);
 }
 slim_hidden_def (cairo_image_surface_create_for_data);
 
 cairo_surface_t *
@@ -463,17 +513,17 @@ cairo_surface_t *
 
 /**
  * cairo_image_surface_get_data:
  * @surface: a #cairo_image_surface_t
  *
  * Get a pointer to the data of the image surface, for direct
  * inspection or modification.
  *
- * Return value: a pointer to the image data of this surface or NULL
+ * Return value: a pointer to the image data of this surface or %NULL
  * if @surface is not an image surface.
  *
  * Since: 1.2
  **/
 unsigned char *
 cairo_image_surface_get_data (cairo_surface_t *surface)
 {
     cairo_image_surface_t *image_surface = (cairo_image_surface_t *) surface;
@@ -610,24 +660,24 @@ cairo_content_t
     case CAIRO_FORMAT_A1:
 	return CAIRO_CONTENT_ALPHA;
     }
 
     ASSERT_NOT_REACHED;
     return CAIRO_CONTENT_COLOR_ALPHA;
 }
 
-cairo_private cairo_format_t
-_cairo_format_width (cairo_format_t format)
+int
+_cairo_format_bits_per_pixel (cairo_format_t format)
 {
     switch (format) {
     case CAIRO_FORMAT_ARGB32:
 	return 32;
     case CAIRO_FORMAT_RGB24:
-	return 24;
+	return 32;
     case CAIRO_FORMAT_A8:
 	return 8;
     case CAIRO_FORMAT_A1:
 	return 1;
     default:
 	ASSERT_NOT_REACHED;
 	return 0;
     }
@@ -1195,17 +1245,17 @@ static cairo_status_t
 }
 
 /**
  * _cairo_surface_is_image:
  * @surface: a #cairo_surface_t
  *
  * Checks if a surface is an #cairo_image_surface_t
  *
- * Return value: TRUE if the surface is an image surface
+ * Return value: %TRUE if the surface is an image surface
  **/
 cairo_bool_t
 _cairo_surface_is_image (const cairo_surface_t *surface)
 {
     return surface->backend == &cairo_image_surface_backend;
 }
 
 const cairo_surface_backend_t cairo_image_surface_backend = {
--- a/gfx/cairo/cairo/src/cairo-lzw.c
+++ b/gfx/cairo/cairo/src/cairo-lzw.c
@@ -53,17 +53,17 @@ typedef struct _lzw_buf {
  *
  * To store objects into the lzw_buf_t, call _lzw_buf_store_bits and
  * when finished, call _lzw_buf_store_pending, (which flushes out the
  * last few bits that hadn't yet made a complete byte yet).
  *
  * Instead of returning failure from any functions, lzw_buf_t provides
  * a status value that the caller can query, (and should query at
  * least once when done with the object). The status value will be
- * either CAIRO_STATUS_SUCCESS or CAIRO_STATUS_NO_MEMORY;
+ * either %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY;
  */
 static void
 _lzw_buf_init (lzw_buf_t *buf, int size)
 {
     if (size == 0)
 	size = 16;
 
     buf->status = CAIRO_STATUS_SUCCESS;
@@ -77,17 +77,17 @@ static void
 	buf->data_size = 0;
 	buf->status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return;
     }
 }
 
 /* Increase the buffer size by doubling.
  *
- * Returns CAIRO_STATUS_SUCCESS or CAIRO_STATUS_NO_MEMORY
+ * Returns %CAIRO_STATUS_SUCCESS or CAIRO_STATUS_NO_MEMORY
  */
 static cairo_status_t
 _lzw_buf_grow (lzw_buf_t *buf)
 {
     int new_size = buf->data_size * 2;
     unsigned char *new_data;
 
     if (buf->status)
@@ -108,23 +108,23 @@ static cairo_status_t
     buf->data = new_data;
     buf->data_size = new_size;
 
     return CAIRO_STATUS_SUCCESS;
 }
 
 /* Store the lowest num_bits bits of values into buf.
  *
- * NOTE: The bits of value above size_in_bits must be 0, (so don't lie
+ * Note: The bits of value above size_in_bits must be 0, (so don't lie
  * about the size).
  *
  * See also _lzw_buf_store_pending which must be called after the last
  * call to _lzw_buf_store_bits.
  *
- * Sets buf->status to either CAIRO_STATUS_SUCCESS or CAIRO_STATUS_NO_MEMORY.
+ * Sets buf->status to either %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY.
  */
 static void
 _lzw_buf_store_bits (lzw_buf_t *buf, uint16_t value, int num_bits)
 {
     cairo_status_t status;
 
     assert (value <= (1 << num_bits) - 1);
 
@@ -142,20 +142,20 @@ static void
 	}
 	buf->data[buf->num_data++] = buf->pending >> (buf->pending_bits - 8);
 	buf->pending_bits -= 8;
     }
 }
 
 /* Store the last remaining pending bits into the buffer.
  *
- * NOTE: This function must be called after the last call to
+ * Note: This function must be called after the last call to
  * _lzw_buf_store_bits.
  *
- * Sets buf->status to either CAIRO_STATUS_SUCCESS or CAIRO_STATUS_NO_MEMORY.
+ * Sets buf->status to either %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY.
  */
 static void
 _lzw_buf_store_pending  (lzw_buf_t *buf)
 {
     cairo_status_t status;
 
     if (buf->status)
 	return;
@@ -229,21 +229,21 @@ static void
 _lzw_symbol_table_init (lzw_symbol_table_t *table)
 {
     memset (table->table, 0, LZW_SYMBOL_TABLE_SIZE * sizeof (lzw_symbol_t));
 }
 
 /* Lookup a symbol in the symbol table. The PREV and NEXT fields of
  * symbol form the key for the lookup.
  *
- * If successful, then this function returns TRUE and slot_ret will be
+ * If successful, then this function returns %TRUE and slot_ret will be
  * left pointing at the result that will have the CODE field of
  * interest.
  *
- * If the lookup fails, then this function returns FALSE and slot_ret
+ * If the lookup fails, then this function returns %FALSE and slot_ret
  * will be pointing at the location in the table to which a new CODE
  * value should be stored along with PREV and NEXT.
  */
 static cairo_bool_t
 _lzw_symbol_table_lookup (lzw_symbol_table_t	 *table,
 			  lzw_symbol_t		  symbol,
 			  lzw_symbol_t		**slot_ret)
 {
@@ -307,17 +307,17 @@ static cairo_bool_t
  *
  * This is an original implementation based on reading the
  * specification of the LZWDecode filter in the PostScript Language
  * Reference. The free parameters in the LZW algorithm are set to the
  * values mandated by PostScript, (symbols encoded with widths from 9
  * to 12 bits).
  *
  * This function returns a pointer to a newly allocated buffer holding
- * the compressed data, or NULL if an out-of-memory situation
+ * the compressed data, or %NULL if an out-of-memory situation
  * occurs.
  *
  * Notice that any one of the _lzw_buf functions called here could
  * trigger an out-of-memory condition. But lzw_buf_t uses cairo's
  * shutdown-on-error idiom, so it's safe to continue to call into
  * lzw_buf without having to check for errors, (until a final check at
  * the end).
  */
--- a/gfx/cairo/cairo/src/cairo-matrix.c
+++ b/gfx/cairo/cairo/src/cairo-matrix.c
@@ -63,17 +63,17 @@ cairo_matrix_init_identity (cairo_matrix
 		       1, 0,
 		       0, 1,
 		       0, 0);
 }
 slim_hidden_def(cairo_matrix_init_identity);
 
 /**
  * cairo_matrix_init:
- * @matrix: a cairo_matrix_t
+ * @matrix: a #cairo_matrix_t
  * @xx: xx component of the affine transformation
  * @yx: yx component of the affine transformation
  * @xy: xy component of the affine transformation
  * @yy: yy component of the affine transformation
  * @x0: X translation component of the affine transformation
  * @y0: Y translation component of the affine transformation
  *
  * Sets @matrix to be the affine transformation given by
@@ -132,17 +132,17 @@ void
     if (x0)
 	*x0 = matrix->x0;
     if (y0)
 	*y0 = matrix->y0;
 }
 
 /**
  * cairo_matrix_init_translate:
- * @matrix: a cairo_matrix_t
+ * @matrix: a #cairo_matrix_t
  * @tx: amount to translate in the X direction
  * @ty: amount to translate in the Y direction
  *
  * Initializes @matrix to a transformation that translates by @tx and
  * @ty in the X and Y dimensions, respectively.
  **/
 void
 cairo_matrix_init_translate (cairo_matrix_t *matrix,
@@ -152,17 +152,17 @@ cairo_matrix_init_translate (cairo_matri
 		       1, 0,
 		       0, 1,
 		       tx, ty);
 }
 slim_hidden_def(cairo_matrix_init_translate);
 
 /**
  * cairo_matrix_translate:
- * @matrix: a cairo_matrix_t
+ * @matrix: a #cairo_matrix_t
  * @tx: amount to translate in the X direction
  * @ty: amount to translate in the Y direction
  *
  * Applies a translation by @tx, @ty to the transformation in
  * @matrix. The effect of the new transformation is to first translate
  * the coordinates by @tx and @ty, then apply the original transformation
  * to the coordinates.
  **/
@@ -174,17 +174,17 @@ cairo_matrix_translate (cairo_matrix_t *
     cairo_matrix_init_translate (&tmp, tx, ty);
 
     cairo_matrix_multiply (matrix, &tmp, matrix);
 }
 slim_hidden_def (cairo_matrix_translate);
 
 /**
  * cairo_matrix_init_scale:
- * @matrix: a cairo_matrix_t
+ * @matrix: a #cairo_matrix_t
  * @sx: scale factor in the X direction
  * @sy: scale factor in the Y direction
  *
  * Initializes @matrix to a transformation that scales by @sx and @sy
  * in the X and Y dimensions, respectively.
  **/
 void
 cairo_matrix_init_scale (cairo_matrix_t *matrix,
@@ -215,17 +215,17 @@ cairo_matrix_scale (cairo_matrix_t *matr
     cairo_matrix_init_scale (&tmp, sx, sy);
 
     cairo_matrix_multiply (matrix, &tmp, matrix);
 }
 slim_hidden_def(cairo_matrix_scale);
 
 /**
  * cairo_matrix_init_rotate:
- * @matrix: a cairo_matrix_t
+ * @matrix: a #cairo_matrix_t
  * @radians: angle of rotation, in radians. The direction of rotation
  * is defined such that positive angles rotate in the direction from
  * the positive X axis toward the positive Y axis. With the default
  * axis orientation of cairo, positive angles rotate in a clockwise
  * direction.
  *
  * Initialized @matrix to a transformation that rotates by @radians.
  **/
@@ -509,25 +509,26 @@ void
 
     a = matrix->xx; b = matrix->yx;
     c = matrix->xy; d = matrix->yy;
 
     *det = a*d - b*c;
 }
 
 /* Compute the amount that each basis vector is scaled by. */
-void
+cairo_status_t
 _cairo_matrix_compute_scale_factors (const cairo_matrix_t *matrix,
 				     double *sx, double *sy, int x_major)
 {
     double det;
 
     _cairo_matrix_compute_determinant (matrix, &det);
 
-    assert (ISFINITE (det));
+    if (! ISFINITE (det))
+	return _cairo_error (CAIRO_STATUS_INVALID_MATRIX);
 
     if (det == 0)
     {
 	*sx = *sy = 0;
     }
     else
     {
 	double x = x_major != 0;
@@ -551,16 +552,18 @@ void
 	    *sy = minor;
 	}
 	else
 	{
 	    *sx = minor;
 	    *sy = major;
 	}
     }
+
+    return CAIRO_STATUS_SUCCESS;
 }
 
 cairo_bool_t
 _cairo_matrix_is_identity (const cairo_matrix_t *matrix)
 {
     return (matrix->xx == 1.0 && matrix->yx == 0.0 &&
 	    matrix->xy == 0.0 && matrix->yy == 1.0 &&
 	    matrix->x0 == 0.0 && matrix->y0 == 0.0);
--- a/gfx/cairo/cairo/src/cairo-meta-surface.c
+++ b/gfx/cairo/cairo/src/cairo-meta-surface.c
@@ -480,17 +480,17 @@ static cairo_int_status_t
  * _cairo_meta_surface_snapshot
  * @surface: a #cairo_surface_t which must be a meta surface
  *
  * Make an immutable copy of @surface. It is an error to call a
  * surface-modifying function on the result of this function.
  *
  * The caller owns the return value and should call
  * cairo_surface_destroy when finished with it. This function will not
- * return NULL, but will return a nil surface instead.
+ * return %NULL, but will return a nil surface instead.
  *
  * Return value: The snapshot surface.
  **/
 static cairo_surface_t *
 _cairo_meta_surface_snapshot (void *abstract_other)
 {
     cairo_meta_surface_t *other = abstract_other;
     cairo_meta_surface_t *meta;
@@ -578,17 +578,17 @@ static cairo_int_status_t
 }
 
 /**
  * _cairo_surface_is_meta:
  * @surface: a #cairo_surface_t
  *
  * Checks if a surface is a #cairo_meta_surface_t
  *
- * Return value: TRUE if the surface is a meta surface
+ * Return value: %TRUE if the surface is a meta surface
  **/
 cairo_bool_t
 _cairo_surface_is_meta (const cairo_surface_t *surface)
 {
     return surface->backend == &cairo_meta_surface_backend;
 }
 
 static const cairo_surface_backend_t cairo_meta_surface_backend = {
@@ -863,17 +863,17 @@ cairo_status_t
 {
     return _cairo_meta_surface_replay_internal (surface,
 						target,
 						CAIRO_META_REPLAY,
 						CAIRO_META_REGION_ALL);
 }
 
 /* Replay meta to surface. When the return status of each operation is
- * one of CAIRO_STATUS_SUCCESS, CAIRO_INT_STATUS_UNSUPPORTED, or
+ * one of %CAIRO_STATUS_SUCCESS, %CAIRO_INT_STATUS_UNSUPPORTED, or
  * CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY the status of each operation
  * will be stored in the meta surface. Any other status will abort the
  * replay and return the status.
  */
 cairo_status_t
 _cairo_meta_surface_replay_and_create_regions (cairo_surface_t *surface,
 					       cairo_surface_t *target)
 {
--- a/gfx/cairo/cairo/src/cairo-mutex-private.h
+++ b/gfx/cairo/cairo/src/cairo-mutex-private.h
@@ -71,17 +71,17 @@ CAIRO_BEGIN_DECLS
 
 /* make sure implementations don't fool us: we decide these ourself */
 #undef _CAIRO_MUTEX_USE_STATIC_INITIALIZER
 #undef _CAIRO_MUTEX_USE_STATIC_FINALIZER
 
 
 #ifdef CAIRO_MUTEX_INIT
 
-/* If CAIRO_MUTEX_INIT is defined, we may need to initialize all
+/* If %CAIRO_MUTEX_INIT is defined, we may need to initialize all
  * static mutex'es. */
 # ifndef CAIRO_MUTEX_INITIALIZE
 #  define CAIRO_MUTEX_INITIALIZE() do {	\
        if (!_cairo_mutex_initialized)	\
            _cairo_mutex_initialize ();	\
    } while(0)
 
    cairo_private void _cairo_mutex_initialize (void);
@@ -103,17 +103,17 @@ CAIRO_BEGIN_DECLS
       memcpy (&(mutex), &_tmp_mutex, sizeof (_tmp_mutex));	\
   } while (0)
 
 #endif /* CAIRO_MUTEX_INIT */
 
 
 #ifdef CAIRO_MUTEX_FINI
 
-/* If CAIRO_MUTEX_FINI is defined, we may need to finalize all
+/* If %CAIRO_MUTEX_FINI is defined, we may need to finalize all
  * static mutex'es. */
 # ifndef CAIRO_MUTEX_FINALIZE
 #  define CAIRO_MUTEX_FINALIZE() do {	\
        if (_cairo_mutex_initialized)	\
            _cairo_mutex_finalize ();	\
    } while(0)
 
    cairo_private void _cairo_mutex_finalize (void);
--- a/gfx/cairo/cairo/src/cairo-mutex-type-private.h
+++ b/gfx/cairo/cairo/src/cairo-mutex-type-private.h
@@ -60,17 +60,17 @@ CAIRO_BEGIN_DECLS
  *
  * Any new mutex implementation needs to do the following:
  *
  * - Condition on the right header or feature.  Headers are
  *   preferred as eg. you still can use win32 mutex implementation
  *   on a win32 system even if you do not compile the win32
  *   surface/backend.
  *
- * - typedef cairo_mutex_t to the proper mutex type on your target
+ * - typedef #cairo_mutex_t to the proper mutex type on your target
  *   system.  Note that you may or may not need to use a pointer,
  *   depending on what kinds of initialization your mutex
  *   implementation supports.  No trailing semicolon needed.
  *   You should be able to compile the following snippet (don't try
  *   running it):
  *
  *	cairo_mutex_t _cairo_some_mutex;
  *
@@ -80,66 +80,66 @@ CAIRO_BEGIN_DECLS
  *   initialized, and is-not-already-locked/is-locked,
  *   respectively.  Use the "do { ... } while (0)" idiom if necessary.
  *   No trailing semicolons are needed (in any macro you define here).
  *   You should be able to compile the following snippet:
  *
  *	cairo_mutex_t _cairo_some_mutex;
  *
  *      if (1)
- *          CAIRO_MUTEX_LOCK (_cairo_some_mutex);
+ *          %CAIRO_MUTEX_LOCK (_cairo_some_mutex);
  *      else
- *          CAIRO_MUTEX_UNLOCK (_cairo_some_mutex);
+ *          %CAIRO_MUTEX_UNLOCK (_cairo_some_mutex);
  *
- * - #define CAIRO_MUTEX_NIL_INITIALIZER to something that can
- *   initialize the cairo_mutex_t type you defined.  Most of the
- *   time one of 0, NULL, or {} works.  At this point
+ * - #define %CAIRO_MUTEX_NIL_INITIALIZER to something that can
+ *   initialize the #cairo_mutex_t type you defined.  Most of the
+ *   time one of 0, %NULL, or {} works.  At this point
  *   you should be able to compile the following snippet:
  *
  *	cairo_mutex_t _cairo_some_mutex = CAIRO_MUTEX_NIL_INITIALIZER;
  *
  *      if (1)
- *          CAIRO_MUTEX_LOCK (_cairo_some_mutex);
+ *          %CAIRO_MUTEX_LOCK (_cairo_some_mutex);
  *      else
- *          CAIRO_MUTEX_UNLOCK (_cairo_some_mutex);
+ *          %CAIRO_MUTEX_UNLOCK (_cairo_some_mutex);
  *
  * - If the above code is not enough to initialize a mutex on
  *   your platform, #define CAIRO_MUTEX_INIT(mutex) to statement
  *   to initialize the mutex (allocate resources, etc).  Such that
  *   you should be able to compile AND RUN the following snippet:
  *
  *	cairo_mutex_t _cairo_some_mutex = CAIRO_MUTEX_NIL_INITIALIZER;
  *
- *      CAIRO_MUTEX_INIT (_cairo_some_mutex);
+ *      %CAIRO_MUTEX_INIT (_cairo_some_mutex);
  *
  *      if (1)
- *          CAIRO_MUTEX_LOCK (_cairo_some_mutex);
+ *          %CAIRO_MUTEX_LOCK (_cairo_some_mutex);
  *      else
- *          CAIRO_MUTEX_UNLOCK (_cairo_some_mutex);
+ *          %CAIRO_MUTEX_UNLOCK (_cairo_some_mutex);
  *
  * - If you define CAIRO_MUTEX_INIT(mutex), cairo will use it to
  *   initialize all static mutex'es.  If for any reason that should
- *   not happen (eg. CAIRO_MUTEX_INIT is just a faster way than
- *   what cairo does using CAIRO_MUTEX_NIL_INITIALIZER), then
+ *   not happen (eg. %CAIRO_MUTEX_INIT is just a faster way than
+ *   what cairo does using %CAIRO_MUTEX_NIL_INITIALIZER), then
  *   #define CAIRO_MUTEX_INITIALIZE() CAIRO_MUTEX_NOOP
  *
  * - If your system supports freeing a mutex object (deallocating
  *   resources, etc), then #define CAIRO_MUTEX_FINI(mutex) to do
  *   that.
  *
  * - If you define CAIRO_MUTEX_FINI(mutex), cairo will use it to
  *   define a finalizer function to finalize all static mutex'es.
  *   However, it's up to you to call CAIRO_MUTEX_FINALIZE() at
  *   proper places, eg. when the system is unloading the cairo library.
  *   So, if for any reason finalizing static mutex'es is not needed
- *   (eg. you never call CAIRO_MUTEX_FINALIZE), then
+ *   (eg. you never call %CAIRO_MUTEX_FINALIZE), then
  *   #define CAIRO_MUTEX_FINALIZE() CAIRO_MUTEX_NOOP
  *
  * - That is all.  If for any reason you think the above API is
- *   not enough to implement cairo_mutex_t on your system, please
+ *   not enough to implement #cairo_mutex_t on your system, please
  *   stop and write to the cairo mailing list about it.  DO NOT
  *   poke around cairo-mutex-private.h for possible solutions.
  */
 
 #if CAIRO_NO_MUTEX
 
 /* No mutexes */
 
--- a/gfx/cairo/cairo/src/cairo-os2-surface.c
+++ b/gfx/cairo/cairo/src/cairo-os2-surface.c
@@ -81,32 +81,52 @@ DisableFPUException (void)
      * so to be sure, we disable Invalid Opcode FPU exception
      * before using FPU stuffs.
      */
     usCW = _control87 (0, 0);
     usCW = usCW | EM_INVALID | 0x80;
     _control87 (usCW, MCW_EM | 0x80);
 }
 
+/**
+ * cairo_os2_init:
+ *
+ * Initializes the Cairo library. This function is automatically called if
+ * Cairo was compiled to be a DLL (however it's not a problem if it's called
+ * multiple times). But if you link to Cairo statically, you have to call it
+ * once to set up Cairo's internal structures and mutexes.
+ *
+ * Since: 1.4
+ **/
 cairo_public void
 cairo_os2_init (void)
 {
     /* This may initialize some stuffs, like create mutex semaphores etc.. */
 
     cairo_os2_initialization_count++;
     if (cairo_os2_initialization_count > 1) return;
 
     DisableFPUException ();
 
     /* Initialize FontConfig */
     FcInit ();
 
     CAIRO_MUTEX_INITIALIZE ();
 }
 
+/**
+ * cairo_os2_fini:
+ *
+ * Uninitializes the Cairo library. This function is automatically called if
+ * Cairo was compiled to be a DLL (however it's not a problem if it's called
+ * multiple times). But if you link to Cairo statically, you have to call it
+ * once to shut down Cairo, to let it free all the resources it has allocated.
+ *
+ * Since: 1.4
+ **/
 cairo_public void
 cairo_os2_fini (void)
 {
     /* This has to uninitialize some stuffs, like destroy mutex semaphores etc.. */
 
     if (cairo_os2_initialization_count <= 0) return;
     cairo_os2_initialization_count--;
     if (cairo_os2_initialization_count > 0) return;
@@ -711,16 +731,36 @@ static cairo_int_status_t
     rectangle->x = 0;
     rectangle->y = 0;
     rectangle->width  = local_os2_surface->bitmap_info.cx;
     rectangle->height = local_os2_surface->bitmap_info.cy;
 
     return CAIRO_STATUS_SUCCESS;
 }
 
+/**
+ * cairo_os2_surface_create:
+ * @hps_client_window: the presentation handle to bind the surface to
+ * @width: the width of the surface
+ * @height: the height of the surface
+ *
+ * Create a Cairo surface which is bound to a given presentation space (HPS).
+ * The surface will be created to have the given size.
+ * By default every change to the surface will be made visible immediately by
+ * blitting it into the window. This can be changed with
+ * cairo_os2_surface_set_manual_window_refresh().
+ * Note that the surface will contain garbage when created, so the pixels have
+ * to be initialized by hand first. You can use the Cairo functions to fill it
+ * with black, or use cairo_surface_mark_dirty() to fill the surface with pixels
+ * from the window/HPS.
+ *
+ * Return value: the newly created surface
+ *
+ * Since: 1.4
+ **/
 cairo_surface_t *
 cairo_os2_surface_create (HPS hps_client_window,
                           int width,
                           int height)
 {
     cairo_os2_surface_t *local_os2_surface;
     cairo_status_t status;
     int rc;
@@ -809,16 +849,41 @@ cairo_os2_surface_create (HPS hps_client
     /* Initialize base surface */
     _cairo_surface_init (&local_os2_surface->base,
                          &cairo_os2_surface_backend,
                          _cairo_content_from_format (CAIRO_FORMAT_ARGB32));
 
     return (cairo_surface_t *)local_os2_surface;
 }
 
+/**
+ * cairo_os2_surface_set_size:
+ * @surface: the cairo surface to resize
+ * @new_width: the new width of the surface
+ * @new_height: the new height of the surface
+ * @timeout: timeout value in milliseconds
+ *
+ * When the client window is resized, call this API to set the new size in the
+ * underlying surface accordingly. This function will reallocate everything,
+ * so you'll have to redraw everything in the surface after this call.
+ * The surface will contain garbage after the resizing. So the notes of
+ * cairo_os2_surface_create() apply here, too.
+ *
+ * The timeout value specifies how long the function should wait on other parts
+ * of the program to release the buffers. It is necessary, because it can happen
+ * that Cairo is just drawing something into the surface while we want to
+ * destroy and recreate it.
+ *
+ * Return value: %CAIRO_STATUS_SUCCESS if the surface could be resized,
+ * %CAIRO_STATUS_SURFACE_TYPE_MISMATCH if the surface is not an OS/2 surface,
+ * %CAIRO_STATUS_NO_MEMORY if the new size could not be allocated, for invalid
+ * sizes, or if the timeout happened before all the buffers were released
+ *
+ * Since: 1.4
+ **/
 int
 cairo_os2_surface_set_size (cairo_surface_t *surface,
                             int              new_width,
                             int              new_height,
                             int              timeout)
 {
     cairo_os2_surface_t *local_os2_surface;
     unsigned char *pchNewPixels;
@@ -916,16 +981,41 @@ cairo_os2_surface_set_size (cairo_surfac
     /* Change bitmap2 structure */
     local_os2_surface->bitmap_info.cx = new_width;
     local_os2_surface->bitmap_info.cy = new_height;
 
     DosReleaseMutexSem (local_os2_surface->hmtx_use_private_fields);
     return CAIRO_STATUS_SUCCESS;
 }
 
+/**
+ * cairo_os2_surface_refresh_window:
+ * @surface: the cairo surface to refresh
+ * @hps_begin_paint: the presentation handle of the window to refresh
+ * @prcl_begin_paint_rect: the rectangle to redraw
+ *
+ * This function can be used to force a repaint of a given area of the client
+ * window. It should usually be called from the WM_PAINT processing of the
+ * window procedure. However, it can be called any time a given part of the
+ * window has to be updated.
+ *
+ * The HPS and RECTL to be passed can be taken from the usual WinBeginPaint call
+ * of the window procedure, but you can also get the HPS using WinGetPS, and you
+ * can assemble your own update rectangle by hand.
+ * If hps_begin_paint is %NULL, the function will use the HPS passed into
+ * cairo_os2_surface_create(). If @prcl_begin_paint_rect is %NULL, the function
+ * will query the current window size and repaint the whole window.
+ *
+ * Cairo assumes that if you set the HWND to the surface using
+ * cairo_os2_surface_set_hwnd(), this function will be called by the application
+ * every time it gets a WM_PAINT for that HWND. If the HWND is set in the
+ * surface, Cairo uses this function to handle dirty areas too.
+ *
+ * Since: 1.4
+ **/
 void
 cairo_os2_surface_refresh_window (cairo_surface_t *surface,
                                   HPS              hps_begin_paint,
                                   PRECTL           prcl_begin_paint_rect)
 {
     cairo_os2_surface_t *local_os2_surface;
     RECTL rclTemp;
 
@@ -1013,16 +1103,38 @@ static cairo_status_t
 
     /* The memory itself will be free'd by the cairo_surface_destroy ()
      * who called us.
      */
 
     return CAIRO_STATUS_SUCCESS;
 }
 
+/**
+ * cairo_os2_surface_set_hwnd:
+ * @surface: the cairo surface to associate with the window handle
+ * @hwnd_client_window: the window handle of the client window
+ *
+ * Sets window handle for surface. If Cairo wants to blit into the window
+ * because it is set to blit as the surface changes (see
+ * cairo_os2_surface_set_manual_window_refresh()), then there are two ways it
+ * can choose:
+ * If it knows the HWND of the surface, then it invalidates that area, so the
+ * application will get a WM_PAINT message and it can call
+ * cairo_os2_surface_refresh_window() to redraw that area. Otherwise cairo itself
+ * will use the HPS it got at surface creation time, and blit the pixels itself.
+ * It's also a solution, but experience shows that if this happens from a non-PM
+ * thread, then it can screw up PM internals.
+ *
+ * So, best solution is to set the HWND for the surface after the surface
+ * creation, so every blit will be done from application's message processing
+ * loop, which is the safest way to do.
+ *
+ * Since: 1.4
+ **/
 void
 cairo_os2_surface_set_hwnd (cairo_surface_t *surface,
                             HWND             hwnd_client_window)
 {
     cairo_os2_surface_t *local_os2_surface;
 
     local_os2_surface = (cairo_os2_surface_t *) surface;
     if ((!local_os2_surface) ||
@@ -1039,16 +1151,35 @@ cairo_os2_surface_set_hwnd (cairo_surfac
         return;
     }
 
     local_os2_surface->hwnd_client_window = hwnd_client_window;
 
     DosReleaseMutexSem (local_os2_surface->hmtx_use_private_fields);
 }
 
+/**
+ * cairo_os2_surface_set_manual_window_refresh:
+ * @surface: the cairo surface to set the refresh mode for
+ * @manual_refresh: the switch for manual surface refresh
+ *
+ * This API can tell Cairo if it should show every change to this surface
+ * immediately in the window or if it should be cached and will only be visible
+ * once the user calls cairo_os2_surface_refresh_window() explicitly. If the
+ * HWND was not set in the cairo surface, then the HPS will be used to blit the
+ * graphics. Otherwise it will invalidate the given window region so the user
+ * will get the WM_PAINT message to redraw that area of the window.
+ *
+ * So, if you're only interested in displaying the final result after several
+ * drawing operations, you might get better performance if you put the surface
+ * into manual refresh mode by passing a true value to this function. Then call
+ * cairo_os2_surface_refresh() whenever desired.
+ *
+ * Since: 1.4
+ **/
 void
 cairo_os2_surface_set_manual_window_refresh (cairo_surface_t *surface,
                                              cairo_bool_t     manual_refresh)
 {
     cairo_os2_surface_t *local_os2_surface;
 
     local_os2_surface = (cairo_os2_surface_t *) surface;
     if ((!local_os2_surface) ||
@@ -1056,16 +1187,24 @@ cairo_os2_surface_set_manual_window_refr
     {
         /* Invalid parameter (wrong surface)! */
         return;
     }
 
     local_os2_surface->blit_as_changes = !manual_refresh;
 }
 
+/**
+ * cairo_os2_surface_get_manual_window_refresh:
+ * @surface: the cairo surface to query the refresh mode from
+ *
+ * Return value: current refresh mode of the surface (true by default)
+ *
+ * Since: 1.4
+ **/
 cairo_bool_t
 cairo_os2_surface_get_manual_window_refresh (cairo_surface_t *surface)
 {
     cairo_os2_surface_t *local_os2_surface;
 
     local_os2_surface = (cairo_os2_surface_t *) surface;
     if ((!local_os2_surface) ||
         (local_os2_surface->base.backend != &cairo_os2_surface_backend))
--- a/gfx/cairo/cairo/src/cairo-os2.h
+++ b/gfx/cairo/cairo/src/cairo-os2.h
@@ -39,163 +39,48 @@
 #define _CAIRO_OS2_H_
 
 #include <cairo.h>
 
 CAIRO_BEGIN_DECLS
 
 /* The OS/2 Specific Cairo API */
 
-/* cairo_os2_init () :                                              */
-/*                                                                  */
-/* Initializes the Cairo library. This function is automatically    */
-/* called if Cairo was compiled to be a DLL (however it's not a     */
-/* problem if it's called multiple times), but if you link to       */
-/* Cairo statically, you have to call it once to set up Cairo's     */
-/* internal structures and mutexes.                                 */
-
 cairo_public void
 cairo_os2_init (void);
 
-/* cairo_os2_fini () :                                              */
-/*                                                                  */
-/* Uninitializes the Cairo library. This function is automatically  */
-/* called if Cairo was compiled to be a DLL (however it's not a     */
-/* problem if it's called multiple times), but if you link to       */
-/* Cairo statically, you have to call it once to shut down Cairo,   */
-/* to let it free all the resources it has allocated.               */
-
 cairo_public void
 cairo_os2_fini (void);
 
 #if CAIRO_HAS_OS2_SURFACE
 
-/* cairo_os2_surface_create () :                                    */
-/*                                                                  */
-/* Create a Cairo surface which is bounded to a given presentation  */
-/* space (HPS). The surface will be created to have the given       */
-/* size.                                                            */
-/* By default: Every change to the surface will be made visible     */
-/*             immediately by blitting it into the window. This     */
-/*             can be changed with the                              */
-/*             cairo_os2_surface_set_manual_window_refresh () API.  */
-/* Note that the surface will contain garbage when created, so the  */
-/* pixels have to be initialized by hand first. You can use the     */
-/* Cairo functions to fill it with black, or use the                */
-/* cairo_surface_mark_dirty () API to fill the surface with pixels  */
-/* from the window/HPS.                                             */
-
 cairo_public cairo_surface_t *
 cairo_os2_surface_create (HPS hps_client_window,
                           int width,
                           int height);
 
-/* cairo_os2_surface_set_hwnd () :                                  */
-/*                                                                  */
-/* Sets window handle for surface. If Cairo wants to blit into the  */
-/* window because it's set that it should blit as the surface       */
-/* changes (see cairo_os2_surface_set_manual_window_refresh () API),*/
-/* then there are two ways it can choose:                           */
-/* If it knows the HWND of the surface, then it invalidates that    */
-/* area, so the application will get a WM_PAINT message and it can  */
-/* call cairo_os2_surface_refresh_window () to redraw that area.    */
-/* Otherwise cairo itself will use the HPS it got at surface        */
-/* creation time, and blit the pixels itself.                       */
-/* It's also a solution, but experience shows that if this happens  */
-/* from a non-PM thread, then it can screw up PM internals.         */
-/*                                                                  */
-/* So, best solution is to set the HWND for the surface after the   */
-/* surface creation, so every blit will be done from application's  */
-/* message processing loop, which is the safest way to do.          */
-
 cairo_public void
 cairo_os2_surface_set_hwnd (cairo_surface_t *surface,
                             HWND             hwnd_client_window);
 
-/* cairo_os2_surface_set_size () :                                  */
-/*                                                                  */
-/* When the client window is resized, call this API so the          */
-/* underlaying surface will also be resized. This function will     */
-/* reallocate everything, so you'll have to redraw everything in    */
-/* the surface after this call.                                     */
-/* The surface will contain garbage after the resizing, just like   */
-/* after cairo_os2_surface_create (), so all those notes also apply */
-/* here, please read that!                                          */
-/*                                                                  */
-/* The timeout value is in milliseconds, and tells how much the     */
-/* function should wait on other parts of the program to release    */
-/* the buffers. It is necessary, because it can be that Cairo is    */
-/* just drawing something into the surface while we want to         */
-/* destroy and recreate it.                                         */
-/* Returns CAIRO_STATUS_SUCCESS if the surface could be resized,    */
-/* or returns other error code if                                   */
-/*  - the surface is not a real OS/2 Surface                        */
-/*  - there is not enough memory to resize the surface              */
-/*  - waiting for all the buffers to be released timed out          */
-
 cairo_public int
 cairo_os2_surface_set_size (cairo_surface_t *surface,
                             int              new_width,
                             int              new_height,
                             int              timeout);
 
-/* cairo_os2_surface_refresh_window () :                            */
-/*                                                                  */
-/* This function can be used to force a repaint of a given area     */
-/* of the client window. Most of the time it is called from the     */
-/* WM_PAINT processing of the window proc. However, it can be       */
-/* called anytime if a given part of the window has to be updated.  */
-/*                                                                  */
-/* The function expects a HPS of the window, and a RECTL to tell    */
-/* which part of the window should be redrawn.                      */
-/* The returned values of WinBeginPaint () is just perfect here,    */
-/* but you can also get the HPS by using the WinGetPS () function,  */
-/* and you can assemble your own update rect by hand.               */
-/* If the hps_begin_paint parameter is NULL, the function will use  */
-/* the HPS you passed in to cairo_os2_surface_create (). If the     */
-/* prcl_begin_paint_rect parameter is NULL, the function will query */
-/* the current window size and repaint the whole window.            */
-/*                                                                  */
-/* Cairo/2 assumes that if you told the HWND to the surface using   */
-/* the cairo_os2_surface_set_hwnd () API, then this function will   */
-/* be called by the application every time it gets a WM_PAINT for   */
-/* that HWND. If the HWND is told to the surface, Cairo uses this   */
-/* function to handle dirty areas too, so you were warned. :)       */
-
 cairo_public void
 cairo_os2_surface_refresh_window (cairo_surface_t *surface,
                                   HPS              hps_begin_paint,
                                   PRECTL           prcl_begin_paint_rect);
 
-/* cairo_os2_surface_set_manual_window_refresh () :                 */
-/*                                                                  */
-/* This API can tell Cairo if it should show every change to this   */
-/* surface immediately in the window, or if it should be cached     */
-/* and will only be visible if the user calls the                   */
-/* cairo_os2_surface_refresh_window () API explicitly.              */
-/* If the HWND was not told to Cairo, then it will use the HPS to   */
-/* blit the graphics. Otherwise it will invalidate the given        */
-/* window region so the user will get WM_PAINT to redraw that area  */
-/* of the window.                                                   */
-/*                                                                  */
-/* So, if you're only interested in displaying the final result     */
-/* after several drawing operations, you might get better           */
-/* performance if you  put the surface into a manual refresh mode   */
-/* by passing a true value to cairo_os2_surface_set_manual_refresh()*/
-/* and then calling cairo_os2_surface_refresh() whenever desired.   */
-
 cairo_public void
 cairo_os2_surface_set_manual_window_refresh (cairo_surface_t *surface,
                                              cairo_bool_t     manual_refresh);
 
-/* cairo_os2_surface_get_manual_window_refresh () :                 */
-/*                                                                  */
-/* This API can return the current mode of the surface. It is       */
-/* TRUE by default.                                                 */
-
 cairo_public cairo_bool_t
 cairo_os2_surface_get_manual_window_refresh (cairo_surface_t *surface);
 
 #else  /* CAIRO_HAS_OS2_SURFACE */
 # error Cairo was not compiled with support for the OS/2 backend
 #endif /* CAIRO_HAS_OS2_SURFACE */
 
 CAIRO_END_DECLS
--- a/gfx/cairo/cairo/src/cairo-output-stream-private.h
+++ b/gfx/cairo/cairo/src/cairo-output-stream-private.h
@@ -20,18 +20,17 @@
  * Version 1.1 (the "License"); you may not use this file except in
  * compliance with the License. You may obtain a copy of the License at
  * http://www.mozilla.org/MPL/
  *
  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
  * OF ANY KIND, either express or implied. See the LGPL or the MPL for
  * the specific language governing rights and limitations.
  *
- * The Original Code is cairo_output_stream.c as distributed with the
- *   cairo graphics library.
+ * The Original Code is the cairo graphics library.
  *
  * The Initial Developer of the Original Code is Red Hat, Inc.
  *
  * Author(s):
  *	Kristian Høgsberg <krh@redhat.com>
  */
 
 #ifndef CAIRO_OUTPUT_STREAM_PRIVATE_H
@@ -69,17 +68,17 @@ cairo_private cairo_status_t
 
 typedef cairo_status_t (*cairo_write_func_t) (void		  *closure,
 					      const unsigned char *data,
 					      unsigned int	   length);
 */
 typedef cairo_status_t (*cairo_close_func_t) (void *closure);
 
 
-/* This function never returns NULL. If an error occurs (NO_MEMORY)
+/* This function never returns %NULL. If an error occurs (NO_MEMORY)
  * while trying to create the output stream this function returns a
  * valid pointer to a nil output stream.
  *
  * Note that even with a nil surface, the close_func callback will be
  * called by a call to _cairo_output_stream_close or
  * _cairo_output_stream_destroy.
  */
 cairo_private cairo_output_stream_t *
@@ -123,28 +122,28 @@ cairo_private void
 			     const char *fmt, ...);
 
 cairo_private long
 _cairo_output_stream_get_position (cairo_output_stream_t *stream);
 
 cairo_private cairo_status_t
 _cairo_output_stream_get_status (cairo_output_stream_t *stream);
 
-/* This function never returns NULL. If an error occurs (NO_MEMORY or
+/* This function never returns %NULL. If an error occurs (NO_MEMORY or
  * WRITE_ERROR) while trying to create the output stream this function
  * returns a valid pointer to a nil output stream.
  *
- * NOTE: Even if a nil surface is returned, the caller should still
+ * Note: Even if a nil surface is returned, the caller should still
  * call _cairo_output_stream_destroy (or _cairo_output_stream_close at
  * least) in order to ensure that everything is properly cleaned up.
  */
 cairo_private cairo_output_stream_t *
 _cairo_output_stream_create_for_filename (const char *filename);
 
-/* This function never returns NULL. If an error occurs (NO_MEMORY or
+/* This function never returns %NULL. If an error occurs (NO_MEMORY or
  * WRITE_ERROR) while trying to create the output stream this function
  * returns a valid pointer to a nil output stream.
  *
  * The caller still "owns" file and is responsible for calling fclose
  * on it when finished. The stream will not do this itself.
  */
 cairo_private cairo_output_stream_t *
 _cairo_output_stream_create_for_file (FILE *file);
--- a/gfx/cairo/cairo/src/cairo-output-stream.c
+++ b/gfx/cairo/cairo/src/cairo-output-stream.c
@@ -20,18 +20,17 @@
  * Version 1.1 (the "License"); you may not use this file except in
  * compliance with the License. You may obtain a copy of the License at
  * http://www.mozilla.org/MPL/
  *
  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
  * OF ANY KIND, either express or implied. See the LGPL or the MPL for
  * the specific language governing rights and limitations.
  *
- * The Original Code is cairo_output_stream.c as distributed with the
- *   cairo graphics library.
+ * The Original Code is the cairo graphics library.
  *
  * The Initial Developer of the Original Code is Red Hat, Inc.
  *
  * Author(s):
  *	Kristian Høgsberg <krh@redhat.com>
  */
 
 #include "cairoint.h"
--- a/gfx/cairo/cairo/src/cairo-paginated-private.h
+++ b/gfx/cairo/cairo/src/cairo-paginated-private.h
@@ -36,17 +36,17 @@
 #ifndef CAIRO_PAGINATED_H
 #define CAIRO_PAGINATED_H
 
 #include "cairoint.h"
 
 struct _cairo_paginated_surface_backend {
     /* Optional. Will be called once for each page.
      *
-     * NOTE: With respect to the order of drawing operations as seen
+     * Note: With respect to the order of drawing operations as seen
      * by the target, this call will occur before any drawing
      * operations for the relevant page. However, with respect to the
      * function calls as made by the user, this call will be *after*
      * any drawing operations for the page, (that is, it will occur
      * during the user's call to cairo_show_page or cairo_copy_page).
      */
     cairo_warn cairo_int_status_t
     (*start_page)		(void			*surface);
@@ -64,40 +64,40 @@ struct _cairo_paginated_surface_backend 
      * on the page. Will be called at the end of the ANALYZE phase but
      * before the mode is changed to RENDER.
      */
     cairo_warn cairo_int_status_t
     (*set_bounding_box)	(void	   	*surface,
 			 cairo_box_t	*bbox);
 };
 
-/* A cairo_paginated_surface provides a very convenient wrapper that
+/* A #cairo_paginated_surface_t provides a very convenient wrapper that
  * is well-suited for doing the analysis common to most surfaces that
  * have paginated output, (that is, things directed at printers, or
  * for saving content in files such as PostScript or PDF files).
  *
  * To use the paginated surface, you'll first need to create your
- * 'real' surface using _cairo_surface_init and the standard
- * cairo_surface_backend_t. Then you also call
+ * 'real' surface using _cairo_surface_init() and the standard
+ * #cairo_surface_backend_t. Then you also call
  * _cairo_paginated_surface_create which takes its own, much simpler,
- * cairo_paginated_surface_backend. You are free to return the result
- * of _cairo_paginated_surface_create from your public
+ * #cairo_paginated_surface_backend_t. You are free to return the result
+ * of _cairo_paginated_surface_create() from your public
  * cairo_<foo>_surface_create. The paginated backend will be careful
  * to not let the user see that they really got a "wrapped"
  * surface. See test-paginated-surface.c for a fairly minimal example
  * of a paginated-using surface. That should be a reasonable example
  * to follow.
  *
  * What the paginated surface does is first save all drawing
  * operations for a page into a meta-surface. Then when the user calls
  * cairo_show_page, the paginated surface performs the following
  * sequence of operations (using the backend functions passed to
  * cairo_paginated_surface_create):
  *
- * 1. Calls start_page (if non NULL). At this point, it is appropriate
+ * 1. Calls start_page (if non %NULL). At this point, it is appropriate
  *    for the target to emit any page-specific header information into
  *    its output.
  *
  * 2. Calls set_paginated_mode with an argument of CAIRO_PAGINATED_MODE_ANALYZE
  *
  * 3. Replays the meta-surface to the target surface, (with an
  *    analysis surface inserted between which watches the return value
  *    from each operation). This analysis stage is used to decide which
@@ -116,23 +116,23 @@ struct _cairo_paginated_surface_backend 
  *    appropriate clip on the target, then paints the resulting image
  *    surface to the target.
  *
  * So, the target will see drawing operations during three separate
  * stages, (ANALYZE, RENDER and FALLBACK). During the ANALYZE phase
  * the target should not actually perform any rendering, (for example,
  * if performing output to a file, no output should be generated
  * during this stage). Instead the drawing functions simply need to
- * return CAIRO_STATUS_SUCCESS or CAIRO_INT_STATUS_UNSUPPORTED to
+ * return %CAIRO_STATUS_SUCCESS or %CAIRO_INT_STATUS_UNSUPPORTED to
  * indicate whether rendering would be supported. And it should do
  * this as quickly as possible. The FALLBACK phase allows the surface
  * to distinguish fallback images from native rendering in case they
  * need to be handled as a special case.
  *
- * NOTE: The paginated surface layer assumes that the target surface
+ * Note: The paginated surface layer assumes that the target surface
  * is "blank" by default at the beginning of each page, without any
  * need for an explicit erase operation, (as opposed to an image
  * surface, for example, which might have uninitialized content
  * originally). As such, it optimizes away CLEAR operations that
  * happen at the beginning of each page---the target surface will not
  * even see these operations.
  */
 cairo_private cairo_surface_t *
--- a/gfx/cairo/cairo/src/cairo-paginated-surface.c
+++ b/gfx/cairo/cairo/src/cairo-paginated-surface.c
@@ -157,18 +157,20 @@ cairo_status_t
 }
 
 static cairo_status_t
 _cairo_paginated_surface_finish (void *abstract_surface)
 {
     cairo_paginated_surface_t *surface = abstract_surface;
     cairo_status_t status = CAIRO_STATUS_SUCCESS;
 
-    if (surface->page_is_blank == FALSE || surface->page_num == 1)
-	status = cairo_surface_show_page (abstract_surface);
+    if (surface->page_is_blank == FALSE || surface->page_num == 1) {
+	cairo_surface_show_page (abstract_surface);
+	status = cairo_surface_status (abstract_surface);
+    }
 
     if (status == CAIRO_STATUS_SUCCESS) {
 	cairo_surface_finish (surface->target);
 	status = cairo_surface_status (surface->target);
     }
 
     if (status == CAIRO_STATUS_SUCCESS) {
 	cairo_surface_finish (surface->meta);
@@ -439,34 +441,36 @@ static cairo_int_status_t
 
     /* XXX: It might make sense to add some suport here for calling
      * cairo_surface_copy_page on the target surface. It would be an
      * optimization for the output, but the interaction with image
      * fallbacks gets tricky. For now, we just let the target see a
      * show_page and we implement the copying by simply not destroying
      * the meta-surface. */
 
-    return cairo_surface_show_page (surface->target);
+    cairo_surface_show_page (surface->target);
+    return cairo_surface_status (surface->target);
 }
 
 static cairo_int_status_t
 _cairo_paginated_surface_show_page (void *abstract_surface)
 {
     cairo_status_t status;
     cairo_paginated_surface_t *surface = abstract_surface;
 
     status = _start_page (surface);
     if (status)
 	return status;
 
     status = _paint_page (surface);
     if (status)
 	return status;
 
-    status = cairo_surface_show_page (surface->target);
+    cairo_surface_show_page (surface->target);
+    status = cairo_surface_status (surface->target);
     if (status)
 	return status;
 
     status = cairo_surface_status (surface->meta);
     if (status)
 	return status;
 
     cairo_surface_destroy (surface->meta);
--- a/gfx/cairo/cairo/src/cairo-path-fill.c
+++ b/gfx/cairo/cairo/src/cairo-path-fill.c
@@ -203,17 +203,17 @@ BAIL:
     return status;
 }
 
 /* This special-case filler supports only a path that describes a
  * device-axis aligned rectangle. It exists to avoid the overhead of
  * the general tessellator when drawing very common rectangles.
  *
  * If the path described anything but a device-axis aligned rectangle,
- * this function will return CAIRO_INT_STATUS_UNSUPPORTED.
+ * this function will return %CAIRO_INT_STATUS_UNSUPPORTED.
  */
 static cairo_int_status_t
 _cairo_path_fixed_fill_rectangle (cairo_path_fixed_t	*path,
 				  cairo_traps_t		*traps)
 {
     cairo_path_buf_t *buf = &path->buf_head.base;
     int final;
 
--- a/gfx/cairo/cairo/src/cairo-path-fixed-private.h
+++ b/gfx/cairo/cairo/src/cairo-path-fixed-private.h
@@ -40,17 +40,17 @@ enum cairo_path_op {
     CAIRO_PATH_OP_MOVE_TO = 0,
     CAIRO_PATH_OP_LINE_TO = 1,
     CAIRO_PATH_OP_CURVE_TO = 2,
     CAIRO_PATH_OP_CLOSE_PATH = 3
 };
 /* we want to make sure a single byte is used for thie enum */
 typedef char cairo_path_op_t;
 
-/* make cairo_path_fixed fit a 512 bytes.  about 50 items */
+/* make _cairo_path_fixed fit a 512 bytes.  about 50 items */
 #define CAIRO_PATH_BUF_SIZE ((512 - 4 * sizeof (void*) - sizeof (cairo_path_buf_t)) \
 			   / (2 * sizeof (cairo_point_t) + sizeof (cairo_path_op_t)))
 
 typedef struct _cairo_path_buf {
     struct _cairo_path_buf *next, *prev;
     int buf_size;
     int num_ops;
     int num_points;
--- a/gfx/cairo/cairo/src/cairo-path-stroke.c
+++ b/gfx/cairo/cairo/src/cairo-path-stroke.c
@@ -1,8 +1,9 @@
+/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */
 /* cairo - a vector graphics library with display and print output
  *
  * Copyright © 2002 University of Southern California
  *
  * This library is free software; you can redistribute it and/or
  * modify it either under the terms of the GNU Lesser General Public
  * License version 2.1 as published by the Free Software Foundation
  * (the "LGPL") or, at your option, under the terms of the Mozilla
@@ -38,16 +39,18 @@
 #include "cairo-path-fixed-private.h"
 
 typedef struct cairo_stroker {
     cairo_stroke_style_t	*style;
 
     cairo_matrix_t *ctm;
     cairo_matrix_t *ctm_inverse;
     double tolerance;
+    double ctm_determinant;
+    cairo_bool_t ctm_det_positive;
 
     cairo_traps_t *traps;
 
     cairo_pen_t	  pen;
 
     cairo_point_t current_point;
     cairo_point_t first_point;
 
@@ -59,16 +62,19 @@ typedef struct cairo_stroker {
     cairo_bool_t has_first_face;
     cairo_stroke_face_t first_face;
 
     cairo_bool_t dashed;
     unsigned int dash_index;
     cairo_bool_t dash_on;
     cairo_bool_t dash_starts_on;
     double dash_remain;
+
+    cairo_bool_t has_bounds;
+    cairo_box_t bounds;
 } cairo_stroker_t;
 
 /* private functions */
 static cairo_status_t
 _cairo_stroker_init (cairo_stroker_t		*stroker,
 		     cairo_stroke_style_t	*stroke_style,
 		     cairo_matrix_t		*ctm,
 		     cairo_matrix_t		*ctm_inverse,
@@ -158,31 +164,58 @@ static cairo_status_t
 {
     cairo_status_t status;
     stroker->style = stroke_style;
     stroker->ctm = ctm;
     stroker->ctm_inverse = ctm_inverse;
     stroker->tolerance = tolerance;
     stroker->traps = traps;
 
+    _cairo_matrix_compute_determinant (stroker->ctm, &stroker->ctm_determinant);
+    if (stroker->ctm_determinant >= 0.0)
+	stroker->ctm_det_positive = TRUE;
+    else
+	stroker->ctm_det_positive = FALSE;
+
     status = _cairo_pen_init (&stroker->pen,
 		              stroke_style->line_width / 2.0,
 			      tolerance, ctm);
     if (status)
 	return status;
 
     stroker->has_current_face = FALSE;
     stroker->has_first_face = FALSE;
     stroker->has_initial_sub_path = FALSE;
 
     if (stroker->style->dash)
 	_cairo_stroker_start_dash (stroker);
     else
 	stroker->dashed = FALSE;
 
+    stroker->has_bounds = _cairo_traps_get_limit (traps, &stroker->bounds);
+    if (stroker->has_bounds) {
+	/* Extend the bounds in each direction to account for the maximum area
+	 * we might generate trapezoids, to capture line segments that are outside
+	 * of the bounds but which might generate rendering that's within bounds.
+	 */
+	double dx, dy;
+	cairo_fixed_t fdx, fdy;
+
+	_cairo_stroke_style_max_distance_from_path (stroker->style, stroker->ctm, &dx, &dy);
+
+	fdx = _cairo_fixed_from_double (dx);
+	fdy = _cairo_fixed_from_double (dy);
+
+	stroker->bounds.p1.x -= fdx;
+	stroker->bounds.p2.x += fdx;
+
+	stroker->bounds.p1.y -= fdy;
+	stroker->bounds.p2.y += fdy;
+    }
+
     return CAIRO_STATUS_SUCCESS;
 }
 
 static void
 _cairo_stroker_fini (cairo_stroker_t *stroker)
 {
     _cairo_pen_fini (&stroker->pen);
 }
@@ -548,36 +581,72 @@ static cairo_status_t
 
 static cairo_status_t
 _cairo_stroker_add_trailing_cap (cairo_stroker_t     *stroker,
 				 cairo_stroke_face_t *face)
 {
     return _cairo_stroker_add_cap (stroker, face);
 }
 
+static inline cairo_bool_t
+_compute_normalized_device_slope (double *dx, double *dy, cairo_matrix_t *ctm_inverse, double *mag_out)
+{
+    double dx0 = *dx, dy0 = *dy;
+    double mag;
+
+    cairo_matrix_transform_distance (ctm_inverse, &dx0, &dy0);
+
+    if (dx0 == 0.0 && dy0 == 0.0) {
+	if (mag_out)
+	    *mag_out = 0.0;
+	return FALSE;
+    }
+
+    if (dx0 == 0.0) {
+	mag = dy0;
+	*dx = 0.0;
+	*dy = 1.0;
+    } else if (dy0 == 0.0) {
+	mag = dx0;
+	*dx = 1.0;
+	*dy = 0.0;
+    } else {
+	mag = sqrt (dx0 * dx0 + dy0 * dy0);
+	*dx = dx0 / mag;
+	*dy = dy0 / mag;
+    }
+
+    if (mag_out)
+	*mag_out = mag;
+
+    return TRUE;
+}
+
 static void
-_compute_face (cairo_point_t *point, cairo_slope_t *slope, cairo_stroker_t *stroker, cairo_stroke_face_t *face);
+_compute_face (cairo_point_t *point, double slope_dx, double slope_dy, cairo_stroker_t *stroker, cairo_stroke_face_t *face);
 
 static cairo_status_t
 _cairo_stroker_add_caps (cairo_stroker_t *stroker)
 {
     cairo_status_t status;
     /* check for a degenerative sub_path */
     if (stroker->has_initial_sub_path
 	&& !stroker->has_first_face
 	&& !stroker->has_current_face
 	&& stroker->style->line_cap == CAIRO_LINE_JOIN_ROUND)
     {
 	/* pick an arbitrary slope to use */
-	cairo_slope_t slope = {1, 0};
+	double dx = 1.0, dy = 0.0;
 	cairo_stroke_face_t face;
 
+	_compute_normalized_device_slope (&dx, &dy, stroker->ctm_inverse, NULL);
+
 	/* arbitrarily choose first_point
 	 * first_point and current_point should be the same */
-	_compute_face (&stroker->first_point, &slope, stroker, &face);
+	_compute_face (&stroker->first_point, dx, dy, stroker, &face);
 
 	status = _cairo_stroker_add_leading_cap (stroker, &face);
 	if (status)
 	    return status;
 	status = _cairo_stroker_add_trailing_cap (stroker, &face);
 	if (status)
 	    return status;
     }
@@ -593,60 +662,37 @@ static cairo_status_t
 	if (status)
 	    return status;
     }
 
     return CAIRO_STATUS_SUCCESS;
 }
 
 static void
-_compute_face (cairo_point_t *point, cairo_slope_t *slope, cairo_stroker_t *stroker, cairo_stroke_face_t *face)
+_compute_face (cairo_point_t *point, double slope_dx, double slope_dy, cairo_stroker_t *stroker, cairo_stroke_face_t *face)
 {
-    double mag, det;
-    double line_dx, line_dy;
     double face_dx, face_dy;
-    cairo_point_double_t usr_vector;
     cairo_point_t offset_ccw, offset_cw;
 
-    line_dx = _cairo_fixed_to_double (slope->dx);
-    line_dy = _cairo_fixed_to_double (slope->dy);
-
-    /* faces are normal in user space, not device space */
-    cairo_matrix_transform_distance (stroker->ctm_inverse, &line_dx, &line_dy);
-
-    mag = sqrt (line_dx * line_dx + line_dy * line_dy);
-    if (mag == 0) {
-	/* XXX: Can't compute other face points. Do we want a tag in the face for this case? */
-	return;
-    }
-
-    /* normalize to unit length */
-    line_dx /= mag;
-    line_dy /= mag;
-
-    usr_vector.x = line_dx;
-    usr_vector.y = line_dy;
-
     /*
      * rotate to get a line_width/2 vector along the face, note that
      * the vector must be rotated the right direction in device space,
      * but by 90° in user space. So, the rotation depends on
      * whether the ctm reflects or not, and that can be determined
      * by looking at the determinant of the matrix.
      */
-    _cairo_matrix_compute_determinant (stroker->ctm, &det);
-    if (det >= 0)
+    if (stroker->ctm_det_positive)
     {
-	face_dx = - line_dy * (stroker->style->line_width / 2.0);
-	face_dy = line_dx * (stroker->style->line_width / 2.0);
+	face_dx = - slope_dy * (stroker->style->line_width / 2.0);
+	face_dy = slope_dx * (stroker->style->line_width / 2.0);
     }
     else
     {
-	face_dx = line_dy * (stroker->style->line_width / 2.0);
-	face_dy = - line_dx * (stroker->style->line_width / 2.0);
+	face_dx = slope_dy * (stroker->style->line_width / 2.0);
+	face_dy = - slope_dx * (stroker->style->line_width / 2.0);
     }
 
     /* back to device space */
     cairo_matrix_transform_distance (stroker->ctm, &face_dx, &face_dy);
 
     offset_ccw.x = _cairo_fixed_from_double (face_dx);
     offset_ccw.y = _cairo_fixed_from_double (face_dy);
     offset_cw.x = -offset_ccw.x;
@@ -655,35 +701,36 @@ static void
     face->ccw = *point;
     _translate_point (&face->ccw, &offset_ccw);
 
     face->point = *point;
 
     face->cw = *point;
     _translate_point (&face->cw, &offset_cw);
 
-    face->usr_vector.x = usr_vector.x;
-    face->usr_vector.y = usr_vector.y;
+    face->usr_vector.x = slope_dx;
+    face->usr_vector.y = slope_dy;
 
-    face->dev_vector = *slope;
+    face->dev_vector.dx = _cairo_fixed_from_double (slope_dx);
+    face->dev_vector.dy = _cairo_fixed_from_double (slope_dy);
 }
 
 static cairo_status_t
 _cairo_stroker_add_sub_edge (cairo_stroker_t *stroker, cairo_point_t *p1, cairo_point_t *p2,
-			     cairo_slope_t *slope, cairo_stroke_face_t *start,
+			     double slope_dx, double slope_dy, cairo_stroke_face_t *start,
 			     cairo_stroke_face_t *end)
 {
     cairo_point_t rectangle[4];
 
-    _compute_face (p1, slope, stroker, start);
+    _compute_face (p1, slope_dx, slope_dy, stroker, start);
 
     /* XXX: This could be optimized slightly by not calling
        _compute_face again but rather  translating the relevant
        fields from start. */
-    _compute_face (p2, slope, stroker, end);
+    _compute_face (p2, slope_dx, slope_dy, stroker, end);
 
     if (p1->x == p2->x && p1->y == p2->y)
 	return CAIRO_STATUS_SUCCESS;
 
     rectangle[0] = start->cw;
     rectangle[1] = start->ccw;
     rectangle[2] = end->ccw;
     rectangle[3] = end->cw;
@@ -725,26 +772,28 @@ static cairo_status_t
 static cairo_status_t
 _cairo_stroker_line_to (void *closure, cairo_point_t *point)
 {
     cairo_status_t status;
     cairo_stroker_t *stroker = closure;
     cairo_stroke_face_t start, end;
     cairo_point_t *p1 = &stroker->current_point;
     cairo_point_t *p2 = point;
-    cairo_slope_t slope;
+    double slope_dx, slope_dy;
 
     stroker->has_initial_sub_path = TRUE;
 
     if (p1->x == p2->x && p1->y == p2->y)
 	return CAIRO_STATUS_SUCCESS;
 
-    _cairo_slope_init (&slope, p1, p2);
+    slope_dx = _cairo_fixed_to_double (p2->x - p1->x);
+    slope_dy = _cairo_fixed_to_double (p2->y - p1->y);
+    _compute_normalized_device_slope (&slope_dx, &slope_dy, stroker->ctm_inverse, NULL);
 
-    status = _cairo_stroker_add_sub_edge (stroker, p1, p2, &slope, &start, &end);
+    status = _cairo_stroker_add_sub_edge (stroker, p1, p2, slope_dx, slope_dy, &start, &end);
     if (status)
 	return status;
 
     if (stroker->has_current_face) {
 	/* Join with final face from previous segment */
 	status = _cairo_stroker_join (stroker, &stroker->current_face, &start);
 	if (status)
 	    return status;
@@ -765,101 +814,111 @@ static cairo_status_t
  * Dashed lines.  Cap each dash end, join around turns when on
  */
 static cairo_status_t
 _cairo_stroker_line_to_dashed (void *closure, cairo_point_t *point)
 {
     cairo_status_t status = CAIRO_STATUS_SUCCESS;
     cairo_stroker_t *stroker = closure;
     double mag, remain, step_length = 0;
-    double dx, dy;
+    double slope_dx, slope_dy;
     double dx2, dy2;
-    cairo_point_t fd1, fd2;
     cairo_stroke_face_t sub_start, sub_end;
     cairo_point_t *p1 = &stroker->current_point;
     cairo_point_t *p2 = point;
-    cairo_slope_t slope;
+    cairo_bool_t fully_in_bounds = TRUE;
+    cairo_line_t segment;
 
     stroker->has_initial_sub_path = stroker->dash_starts_on;
 
     if (p1->x == p2->x && p1->y == p2->y)
 	return CAIRO_STATUS_SUCCESS;
 
-    _cairo_slope_init (&slope, p1, p2);
-
-    dx = _cairo_fixed_to_double (p2->x - p1->x);
-    dy = _cairo_fixed_to_double (p2->y - p1->y);
+    if (stroker->has_bounds &&
+	(!_cairo_box_contains_point (&stroker->bounds, p1) ||
+	 !_cairo_box_contains_point (&stroker->bounds, p2)))
+    {
+	fully_in_bounds = FALSE;
+    }
 
-    cairo_matrix_transform_distance (stroker->ctm_inverse, &dx, &dy);
+    slope_dx = _cairo_fixed_to_double (p2->x - p1->x);
+    slope_dy = _cairo_fixed_to_double (p2->y - p1->y);
 
-    mag = sqrt (dx * dx + dy * dy);
+    if (!_compute_normalized_device_slope (&slope_dx, &slope_dy, stroker->ctm_inverse, &mag))
+	return CAIRO_STATUS_SUCCESS;
+
     remain = mag;
-    fd1 = *p1;
+    segment.p1 = *p1;
     while (remain) {
 	step_length = MIN (stroker->dash_remain, remain);
 	remain -= step_length;
-	dx2 = dx * (mag - remain)/mag;
-	dy2 = dy * (mag - remain)/mag;
+	dx2 = slope_dx * (mag - remain);
+	dy2 = slope_dy * (mag - remain);
 	cairo_matrix_transform_distance (stroker->ctm, &dx2, &dy2);
-	fd2.x = _cairo_fixed_from_double (dx2) + p1->x;
-	fd2.y = _cairo_fixed_from_double (dy2) + p1->y;
+	segment.p2.x = _cairo_fixed_from_double (dx2) + p1->x;
+	segment.p2.y = _cairo_fixed_from_double (dy2) + p1->y;
 
-	if (stroker->dash_on) {
-	    status = _cairo_stroker_add_sub_edge (stroker, &fd1, &fd2, &slope, &sub_start, &sub_end);
-	    if (status)
-		return status;
-
-	    if (stroker->has_current_face) {
-		/* Join with final face from previous segment */
-		status = _cairo_stroker_join (stroker, &stroker->current_face, &sub_start);
-		stroker->has_current_face = FALSE;
+	if (fully_in_bounds ||
+	    _cairo_box_intersects_line_segment (&stroker->bounds, &segment))
+	{
+	    if (stroker->dash_on) {
+		status = _cairo_stroker_add_sub_edge (stroker, &segment.p1, &segment.p2, slope_dx, slope_dy, &sub_start, &sub_end);
 		if (status)
 		    return status;
-	    } else if (!stroker->has_first_face && stroker->dash_starts_on) {
-		/* Save sub path's first face in case needed for closing join */
-		stroker->first_face = sub_start;
-		stroker->has_first_face = TRUE;
-	    } else {
-		/* Cap dash start if not connecting to a previous segment */
-		status = _cairo_stroker_add_leading_cap (stroker, &sub_start);
-		if (status)
-		    return status;
-	    }
+
+		if (stroker->has_current_face) {
+		    /* Join with final face from previous segment */
+		    status = _cairo_stroker_join (stroker, &stroker->current_face, &sub_start);
+		    stroker->has_current_face = FALSE;
+		    if (status)
+			return status;
+		} else if (!stroker->has_first_face && stroker->dash_starts_on) {
+		    /* Save sub path's first face in case needed for closing join */
+		    stroker->first_face = sub_start;
+		    stroker->has_first_face = TRUE;
+		} else {
+		    /* Cap dash start if not connecting to a previous segment */
+		    status = _cairo_stroker_add_leading_cap (stroker, &sub_start);
+		    if (status)
+			return status;
+		}
 
-	    if (remain) {
-		/* Cap dash end if not at end of segment */
-		status = _cairo_stroker_add_trailing_cap (stroker, &sub_end);
-		if (status)
-		    return status;
+		if (remain) {
+		    /* Cap dash end if not at end of segment */
+		    status = _cairo_stroker_add_trailing_cap (stroker, &sub_end);
+		    if (status)
+			return status;
+		} else {
+		    stroker->current_face = sub_end;
+		    stroker->has_current_face = TRUE;
+		}
 	    } else {
-		stroker->current_face = sub_end;
-		stroker->has_current_face = TRUE;
-	    }
-	} else {
-	    if (stroker->has_current_face) {
-		/* Cap final face from previous segment */
-		status = _cairo_stroker_add_trailing_cap (stroker, &stroker->current_face);
-		if (status)
-		    return status;
-		stroker->has_current_face = FALSE;
+		if (stroker->has_current_face) {
+		    /* Cap final face from previous segment */
+		    status = _cairo_stroker_add_trailing_cap (stroker, &stroker->current_face);
+		    if (status)
+			return status;
+		    stroker->has_current_face = FALSE;
+		}
 	    }
 	}
+
 	_cairo_stroker_step_dash (stroker, step_length);
-	fd1 = fd2;
+	segment.p1 = segment.p2;
     }
 
     if (stroker->dash_on && !stroker->has_current_face) {
 	/* This segment ends on a transition to dash_on, compute a new face
 	 * and add cap for the begining of the next dash_on step.
 	 *
 	 * Note: this will create a degenerate cap if this is not the last line
 	 * in the path. Whether this behaviour is desirable or not is debatable.
 	 * On one side these degnerate caps can not be reproduced with regular path stroking.
 	 * On the other side Acroread 7 also produces the degenerate caps. */
-	_compute_face (point, &slope, stroker, &stroker->current_face);
+	_compute_face (point, slope_dx, slope_dy, stroker, &stroker->current_face);
 	stroker->has_current_face = TRUE;
 	status = _cairo_stroker_add_leading_cap (stroker, &stroker->current_face);
 	if (status)
 	    return status;
     }
 
     stroker->current_point = *point;
 
@@ -874,27 +933,37 @@ static cairo_status_t
 {
     cairo_status_t status = CAIRO_STATUS_SUCCESS;
     cairo_stroker_t *stroker = closure;
     cairo_spline_t spline;
     cairo_pen_t pen;
     cairo_stroke_face_t start, end;
     cairo_point_t extra_points[4];
     cairo_point_t *a = &stroker->current_point;
+    double initial_slope_dx, initial_slope_dy;
+    double final_slope_dx, final_slope_dy;
 
     status = _cairo_spline_init (&spline, a, b, c, d);
     if (status == CAIRO_INT_STATUS_DEGENERATE)
 	return _cairo_stroker_line_to (closure, d);
 
     status = _cairo_pen_init_copy (&pen, &stroker->pen);
     if (status)
 	goto CLEANUP_SPLINE;
 
-    _compute_face (a, &spline.initial_slope, stroker, &start);
-    _compute_face (d, &spline.final_slope, stroker, &end);
+    initial_slope_dx = _cairo_fixed_to_double (spline.initial_slope.dx);
+    initial_slope_dy = _cairo_fixed_to_double (spline.initial_slope.dy);
+    final_slope_dx = _cairo_fixed_to_double (spline.final_slope.dx);
+    final_slope_dy = _cairo_fixed_to_double (spline.final_slope.dy);
+
+    if (_compute_normalized_device_slope (&initial_slope_dx, &initial_slope_dy, stroker->ctm_inverse, NULL))
+	_compute_face (a, initial_slope_dx, initial_slope_dy, stroker, &start);
+
+    if (_compute_normalized_device_slope (&final_slope_dx, &final_slope_dy, stroker->ctm_inverse, NULL))
+	_compute_face (d, final_slope_dx, final_slope_dy, stroker, &end);
 
     if (stroker->has_current_face) {
 	status = _cairo_stroker_join (stroker, &stroker->current_face, &start);
 	if (status)
 	    goto CLEANUP_PEN;
     } else if (!stroker->has_first_face) {
 	stroker->first_face = start;
 	stroker->has_first_face = TRUE;
--- a/gfx/cairo/cairo/src/cairo-path.c
+++ b/gfx/cairo/cairo/src/cairo-path.c
@@ -358,17 +358,17 @@ static cairo_path_t *
  * cairo_path_destroy:
  * @path: a path previously returned by either cairo_copy_path() or
  * cairo_copy_path_flat().
  *
  * Immediately releases all memory associated with @path. After a call
  * to cairo_path_destroy() the @path pointer is no longer valid and
  * should not be used further.
  *
- * NOTE: cairo_path_destroy function should only be called with a
+ * Note: cairo_path_destroy() should only be called with a
  * pointer to a #cairo_path_t returned by a cairo function. Any path
  * that is created manually (ie. outside of cairo) should be destroyed
  * manually as well.
  **/
 void
 cairo_path_destroy (cairo_path_t *path)
 {
     if (path == NULL || path == &_cairo_path_nil)
@@ -385,19 +385,19 @@ cairo_path_destroy (cairo_path_t *path)
  * @path: a fixed-point, device-space path to be converted and copied
  * @gstate: the current graphics state
  *
  * Creates a user-space #cairo_path_t copy of the given device-space
  * @path. The @gstate parameter provides the inverse CTM for the
  * conversion.
  *
  * Return value: the new copy of the path. If there is insufficient
- * memory a pointer to a special static cairo_path_nil will be
- * returned instead with status==CAIRO_STATUS_NO_MEMORY and
- * data==NULL.
+ * memory a pointer to a special static nil #cairo_path_t will be
+ * returned instead with status==%CAIRO_STATUS_NO_MEMORY and
+ * data==%NULL.
  **/
 cairo_path_t *
 _cairo_path_create (cairo_path_fixed_t *path,
 		    cairo_gstate_t     *gstate)
 {
     return _cairo_path_create_internal (path, gstate, FALSE);
 }
 
@@ -407,36 +407,36 @@ cairo_path_t *
  * @gstate: the current graphics state
  *
  * Creates a flattened, user-space #cairo_path_t copy of the given
  * device-space @path. The @gstate parameter provide the inverse CTM
  * for the conversion, as well as the tolerance value to control the
  * accuracy of the flattening.
  *
  * Return value: the flattened copy of the path. If there is insufficient
- * memory a pointer to a special static cairo_path_nil will be
- * returned instead with status==CAIRO_STATUS_NO_MEMORY and
- * data==NULL.
+ * memory a pointer to a special static nil #cairo_path_t will be
+ * returned instead with status==%CAIRO_STATUS_NO_MEMORY and
+ * data==%NULL.
  **/
 cairo_path_t *
 _cairo_path_create_flat (cairo_path_fixed_t *path,
 			 cairo_gstate_t     *gstate)
 {
     return _cairo_path_create_internal (path, gstate, TRUE);
 }
 
 /**
  * _cairo_path_append_to_context:
  * @path: the path data to be appended
  * @cr: a cairo context
  *
  * Append @path to the current path within @cr.
  *
- * Return value: CAIRO_STATUS_INVALID_PATH_DATA if the data in @path
- * is invalid, and CAIRO_STATUS_SUCCESS otherwise.
+ * Return value: %CAIRO_STATUS_INVALID_PATH_DATA if the data in @path
+ * is invalid, and %CAIRO_STATUS_SUCCESS otherwise.
  **/
 cairo_status_t
 _cairo_path_append_to_context (const cairo_path_t	*path,
 			       cairo_t			*cr)
 {
     int i;
     cairo_path_data_t *p;
     cairo_status_t status;
--- a/gfx/cairo/cairo/src/cairo-pattern.c
+++ b/gfx/cairo/cairo/src/cairo-pattern.c
@@ -384,17 +384,17 @@ static const cairo_pattern_t *
 }
 
 /**
  * cairo_pattern_create_rgb:
  * @red: red component of the color
  * @green: green component of the color
  * @blue: blue component of the color
  *
- * Creates a new cairo_pattern_t corresponding to an opaque color.  The
+ * Creates a new #cairo_pattern_t corresponding to an opaque color.  The
  * color components are floating point numbers in the range 0 to 1.
  * If the values passed in are outside that range, they will be
  * clamped.
  *
  * Return value: the newly created #cairo_pattern_t if successful, or
  * an error pattern in case of no memory.  The caller owns the
  * returned object and should call cairo_pattern_destroy() when
  * finished with it.
@@ -428,17 +428,17 @@ slim_hidden_def (cairo_pattern_create_rg
 
 /**
  * cairo_pattern_create_rgba:
  * @red: red component of the color
  * @green: green component of the color
  * @blue: blue component of the color
  * @alpha: alpha component of the color
  *
- * Creates a new cairo_pattern_t corresponding to a translucent color.
+ * Creates a new #cairo_pattern_t corresponding to a translucent color.
  * The color components are floating point numbers in the range 0 to
  * 1.  If the values passed in are outside that range, they will be
  * clamped.
  *
  * Return value: the newly created #cairo_pattern_t if successful, or
  * an error pattern in case of no memory.  The caller owns the
  * returned object and should call cairo_pattern_destroy() when
  * finished with it.
@@ -471,17 +471,17 @@ cairo_pattern_create_rgba (double red, d
     return pattern;
 }
 slim_hidden_def (cairo_pattern_create_rgba);
 
 /**
  * cairo_pattern_create_for_surface:
  * @surface: the surface
  *
- * Create a new cairo_pattern_t for the given surface.
+ * Create a new #cairo_pattern_t for the given surface.
  *
  * Return value: the newly created #cairo_pattern_t if successful, or
  * an error pattern in case of no memory.  The caller owns the
  * returned object and should call cairo_pattern_destroy() when
  * finished with it.
  *
  * This function will always return a valid pointer, but if an error
  * occurred the pattern status will be set to an error.  To inspect
@@ -514,17 +514,17 @@ slim_hidden_def (cairo_pattern_create_fo
 
 /**
  * cairo_pattern_create_linear:
  * @x0: x coordinate of the start point
  * @y0: y coordinate of the start point
  * @x1: x coordinate of the end point
  * @y1: y coordinate of the end point
  *
- * Create a new linear gradient cairo_pattern_t along the line defined
+ * Create a new linear gradient #cairo_pattern_t along the line defined
  * by (x0, y0) and (x1, y1).  Before using the gradient pattern, a
  * number of color stops should be defined using
  * cairo_pattern_add_color_stop_rgb() or
  * cairo_pattern_add_color_stop_rgba().
  *
  * Note: The coordinates here are in pattern space. For a new pattern,
  * pattern space is identical to user space, but the relationship
  * between the spaces can be changed with cairo_pattern_set_matrix().
@@ -560,17 +560,17 @@ cairo_pattern_create_linear (double x0, 
  * cairo_pattern_create_radial:
  * @cx0: x coordinate for the center of the start circle
  * @cy0: y coordinate for the center of the start circle
  * @radius0: radius of the start circle
  * @cx1: x coordinate for the center of the end circle
  * @cy1: y coordinate for the center of the end circle
  * @radius1: radius of the end circle
  *
- * Creates a new radial gradient cairo_pattern_t between the two
+ * Creates a new radial gradient #cairo_pattern_t between the two
  * circles defined by (cx0, cy0, radius0) and (cx1, cy1, radius1).  Before using the
  * gradient pattern, a number of color stops should be defined using
  * cairo_pattern_add_color_stop_rgb() or
  * cairo_pattern_add_color_stop_rgba().
  *
  * Note: The coordinates here are in pattern space. For a new pattern,
  * pattern space is identical to user space, but the relationship
  * between the spaces can be changed with cairo_pattern_set_matrix().
@@ -1045,16 +1045,27 @@ cairo_pattern_get_matrix (cairo_pattern_
 /**
  * cairo_pattern_set_filter:
  * @pattern: a #cairo_pattern_t
  * @filter: a #cairo_filter_t describing the filter to use for resizing
  * the pattern
  *
  * Sets the filter to be used for resizing when using this pattern.
  * See #cairo_filter_t for details on each filter.
+ *
+ * * Note that you might want to control filtering even when you do not
+ * have an explicit #cairo_pattern_t object, (for example when using
+ * cairo_set_source_surface()). In these cases, it is convenient to
+ * use cairo_get_source() to get access to the pattern that cairo
+ * creates implicitly. For example:
+ *
+ * <informalexample><programlisting>
+ * cairo_set_source_surface (cr, image, x, y);
+ * cairo_pattern_set_filter (cairo_get_source (cr), %CAIRO_FILTER_NEAREST);
+ * </programlisting></informalexample>
  **/
 void
 cairo_pattern_set_filter (cairo_pattern_t *pattern, cairo_filter_t filter)
 {
     if (pattern->status)
 	return;
 
     pattern->filter = filter;
--- a/gfx/cairo/cairo/src/cairo-pdf-operators-private.h
+++ b/gfx/cairo/cairo/src/cairo-pdf-operators-private.h
@@ -40,20 +40,19 @@
  */
 
 #ifndef CAIRO_PDF_OPERATORS_H
 #define CAIRO_PDF_OPERATORS_H
 
 #include "cairo-compiler-private.h"
 #include "cairo-types-private.h"
 
-typedef cairo_status_t
-(*cairo_pdf_operators_use_font_subset_t) (unsigned int  font_id,
-					  unsigned int  subset_id,
-					  void         *closure);
+typedef cairo_status_t (*cairo_pdf_operators_use_font_subset_t) (unsigned int  font_id,
+								 unsigned int  subset_id,
+								 void         *closure);
 
 typedef struct _cairo_pdf_operators {
     cairo_output_stream_t *stream;
     cairo_matrix_t cairo_to_pdf;
     cairo_scaled_font_subsets_t *font_subsets;
     cairo_pdf_operators_use_font_subset_t use_font_subset;
     void *use_font_subset_closure;
 } cairo_pdf_operators_t;
--- a/gfx/cairo/cairo/src/cairo-pdf-operators.c
+++ b/gfx/cairo/cairo/src/cairo-pdf-operators.c
@@ -273,17 +273,17 @@ static cairo_int_status_t
 	_cairo_output_stream_printf (pdf_operators->stream, "] %f d\r\n",
 				     style->dash_offset);
     } else {
 	_cairo_output_stream_printf (pdf_operators->stream, "[] 0.0 d\r\n");
     }
 
     _cairo_output_stream_printf (pdf_operators->stream,
 				 "%f M ",
-				 style->miter_limit);
+				 style->miter_limit < 1.0 ? 1.0 : style->miter_limit);
 
     return _cairo_output_stream_get_status (pdf_operators->stream);
 }
 
 
 cairo_int_status_t
 _cairo_pdf_operator_stroke (cairo_pdf_operators_t	*pdf_operators,
 			    cairo_path_fixed_t		*path,
--- a/gfx/cairo/cairo/src/cairo-pdf-surface-private.h
+++ b/gfx/cairo/cairo/src/cairo-pdf-surface-private.h
@@ -56,31 +56,35 @@ typedef struct _cairo_pdf_group_resource
     cairo_array_t alphas;
     cairo_array_t smasks;
     cairo_array_t patterns;
     cairo_array_t xobjects;
     cairo_array_t fonts;
 } cairo_pdf_group_resources_t;
 
 typedef struct _cairo_pdf_pattern {
+    double width;
+    double height;
     cairo_pattern_t *pattern;
     cairo_pdf_resource_t pattern_res;
     cairo_pdf_resource_t gstate_res;
 } cairo_pdf_pattern_t;
 
 typedef enum _cairo_pdf_operation {
     PDF_PAINT,
     PDF_MASK,
     PDF_FILL,
     PDF_STROKE,
     PDF_SHOW_GLYPHS
 } cairo_pdf_operation_t;
 
 typedef struct _cairo_pdf_smask_group
 {
+    double 		  width;
+    double 		  height;
     cairo_pdf_resource_t  group_res;
     cairo_pdf_operation_t operation;
     cairo_pattern_t	 *source;
     cairo_pdf_resource_t  source_res;
     cairo_pattern_t	 *mask;
     cairo_path_fixed_t	  path;
     cairo_fill_rule_t	  fill_rule;
     cairo_stroke_style_t *style;
--- a/gfx/cairo/cairo/src/cairo-pdf-surface.c
+++ b/gfx/cairo/cairo/src/cairo-pdf-surface.c
@@ -327,17 +327,17 @@ BAIL0:
  * @closure: the closure argument for @write_func
  * @width_in_points: width of the surface, in points (1 point == 1/72.0 inch)
  * @height_in_points: height of the surface, in points (1 point == 1/72.0 inch)
  *
  * Creates a PDF surface of the specified size in points to be written
  * incrementally to the stream represented by @write_func and @closure.
  *
  * Return value: a pointer to the newly created surface. The caller
- * owns the surface and should call cairo_surface_destroy when done
+ * owns the surface and should call cairo_surface_destroy() when done
  * with it.
  *
  * This function always returns a valid pointer, but it will return a
  * pointer to a "nil" surface if an error such as out of memory
  * occurs. You can use cairo_surface_status() to check for this.
  *
  * Since: 1.2
  */
@@ -363,17 +363,17 @@ cairo_pdf_surface_create_for_stream (cai
  * @filename: a filename for the PDF output (must be writable)
  * @width_in_points: width of the surface, in points (1 point == 1/72.0 inch)
  * @height_in_points: height of the surface, in points (1 point == 1/72.0 inch)
  *
  * Creates a PDF surface of the specified size in points to be written
  * to @filename.
  *
  * Return value: a pointer to the newly created surface. The caller
- * owns the surface and should call cairo_surface_destroy when done
+ * owns the surface and should call cairo_surface_destroy() when done
  * with it.
  *
  * This function always returns a valid pointer, but it will return a
  * pointer to a "nil" surface if an error such as out of memory
  * occurs. You can use cairo_surface_status() to check for this.
  *
  * Since: 1.2
  **/
@@ -396,17 +396,17 @@ cairo_pdf_surface_create (const char		*f
 static cairo_bool_t
 _cairo_surface_is_pdf (cairo_surface_t *surface)
 {
     return surface->backend == &cairo_pdf_surface_backend;
 }
 
 /* If the abstract_surface is a paginated surface, and that paginated
  * surface's target is a pdf_surface, then set pdf_surface to that
- * target. Otherwise return CAIRO_STATUS_SURFACE_TYPE_MISMATCH.
+ * target. Otherwise return %CAIRO_STATUS_SURFACE_TYPE_MISMATCH.
  */
 static cairo_status_t
 _extract_pdf_surface (cairo_surface_t		 *surface,
 		      cairo_pdf_surface_t	**pdf_surface)
 {
     cairo_surface_t *target;
 
     if (! _cairo_surface_is_paginated (surface))
@@ -419,17 +419,17 @@ static cairo_status_t
 
     *pdf_surface = (cairo_pdf_surface_t *) target;
 
     return CAIRO_STATUS_SUCCESS;
 }
 
 /**
  * cairo_pdf_surface_set_size:
- * @surface: a PDF cairo_surface_t
+ * @surface: a PDF #cairo_surface_t
  * @width_in_points: new surface width, in points (1 point == 1/72.0 inch)
  * @height_in_points: new surface height, in points (1 point == 1/72.0 inch)
  *
  * Changes the size of a PDF surface for the current (and
  * subsequent) pages.
  *
  * This function should only be called before any drawing operations
  * have been performed on the current page. The simplest way to do
@@ -722,16 +722,18 @@ static cairo_pdf_smask_group_t *
     }
 
     group->group_res = _cairo_pdf_surface_new_object (surface);
     if (group->group_res.id == 0) {
 	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
 	free (group);
 	return NULL;
     }
+    group->width = surface->width;
+    group->height = surface->height;
 
     return group;
 }
 
 static void
 _cairo_pdf_smask_group_destroy (cairo_pdf_smask_group_t *group)
 {
     if (group->operation == PDF_FILL ||	group->operation == PDF_STROKE)
@@ -795,16 +797,18 @@ static cairo_status_t
             pdf_pattern.gstate_res = _cairo_pdf_surface_new_object (surface);
 	    if (pdf_pattern.gstate_res.id == 0) {
 		cairo_pattern_destroy (pattern);
 		return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    }
         }
     }
 
+    pdf_pattern.width = surface->width;
+    pdf_pattern.height = surface->height;
     *pattern_res = pdf_pattern.pattern_res;
     *gstate_res = pdf_pattern.gstate_res;
 
     status = _cairo_array_append (&surface->patterns, &pdf_pattern);
     if (status) {
 	cairo_pattern_destroy (pattern);
 	return status;
     }
@@ -1240,19 +1244,26 @@ static cairo_int_status_t
     return CAIRO_STATUS_SUCCESS;
 }
 
 static void *
 compress_dup (const void *data, unsigned long data_size,
 	      unsigned long *compressed_size)
 {
     void *compressed;
+    unsigned long additional_size;
 
     /* Bound calculation taken from zlib. */
-    *compressed_size = data_size + (data_size >> 12) + (data_size >> 14) + 11;
+    additional_size = (data_size >> 12) + (data_size >> 14) + 11;
+    if (INT32_MAX - data_size <= additional_size) {
+	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
+	return NULL;
+    }
+
+    *compressed_size = data_size + additional_size;
     compressed = malloc (*compressed_size);
     if (compressed == NULL) {
 	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
 	return NULL;
     }
 
     if (compress (compressed, compressed_size, data, data_size) != Z_OK) {
 	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
@@ -1286,21 +1297,28 @@ static cairo_status_t
 
     /* This is the only image format we support, which simplifies things. */
     assert (image->format == CAIRO_FORMAT_ARGB32 ||
 	    image->format == CAIRO_FORMAT_A8 ||
 	    image->format == CAIRO_FORMAT_A1 );
 
     stream_ret->id = 0;
 
-    if (image->format == CAIRO_FORMAT_A1)
-	alpha_size = (image->height * image->width + 7)/8;
-    else
+    if (image->format == CAIRO_FORMAT_A1) {
+	/* We allocate using slightly different math so that we can get
+	 * the overflow checking from _cairo_malloc_ab, but alpha_size
+	 * needs to be the correct size for emitting the data in the PDF.
+	 */
+	alpha_size = (image->width*image->height + 7) / 8;
+	alpha = _cairo_malloc_ab ((image->width+7) / 8, image->height);
+    } else {
 	alpha_size = image->height * image->width;
-    alpha = malloc (alpha_size);
+	alpha = _cairo_malloc_ab (image->height, image->width);
+    }
+
     if (alpha == NULL) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto CLEANUP;
     }
 
     opaque = TRUE;
     i = 0;
     src_bit = 0;
@@ -1411,17 +1429,17 @@ static cairo_status_t
      * CONTENT_COLOR or CONTENT_COLOR_ALPHA.
      */
     assert (image->format == CAIRO_FORMAT_RGB24 ||
 	    image->format == CAIRO_FORMAT_ARGB32 ||
 	    image->format == CAIRO_FORMAT_A8 ||
 	    image->format == CAIRO_FORMAT_A1);
 
     rgb_size = image->height * image->width * 3;
-    rgb = malloc (rgb_size);
+    rgb = _cairo_malloc_abc (image->width, image->height, 3);
     if (rgb == NULL) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto CLEANUP;
     }
 
     i = 0;
     for (y = 0; y < image->height; y++) {
 	pixel = (uint32_t *) (image->data + y * image->stride);
@@ -2567,33 +2585,52 @@ static cairo_status_t
     }
 
     return _cairo_output_stream_get_status (surface->output);
 }
 
 static cairo_status_t
 _cairo_pdf_surface_emit_pattern (cairo_pdf_surface_t *surface, cairo_pdf_pattern_t *pdf_pattern)
 {
+    double old_width, old_height;
+    cairo_status_t status;
+
+    old_width = surface->width;
+    old_height = surface->height;
+    surface->width = pdf_pattern->width;
+    surface->height = pdf_pattern->height;
+
     switch (pdf_pattern->pattern->type) {
     case CAIRO_PATTERN_TYPE_SOLID:
 	ASSERT_NOT_REACHED;
+	status = _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH);
 	break;
 
     case CAIRO_PATTERN_TYPE_SURFACE:
-	return _cairo_pdf_surface_emit_surface_pattern (surface, pdf_pattern);
+	status = _cairo_pdf_surface_emit_surface_pattern (surface, pdf_pattern);
+	break;
 
     case CAIRO_PATTERN_TYPE_LINEAR:
-	return _cairo_pdf_surface_emit_linear_pattern (surface, pdf_pattern);
+	status = _cairo_pdf_surface_emit_linear_pattern (surface, pdf_pattern);
+	break;
 
     case CAIRO_PATTERN_TYPE_RADIAL:
-	return _cairo_pdf_surface_emit_radial_pattern (surface, pdf_pattern);
+	status = _cairo_pdf_surface_emit_radial_pattern (surface, pdf_pattern);
+	break;
+
+    default:
+	ASSERT_NOT_REACHED;
+	status = _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH);
+	break;
     }
 
-    ASSERT_NOT_REACHED;
-    return _cairo_error (CAIRO_STATUS_PATTERN_TYPE_MISMATCH);
+    surface->width = old_width;
+    surface->height = old_height;
+
+    return status;
 }
 
 static cairo_status_t
 _cairo_pdf_surface_select_pattern (cairo_pdf_surface_t *surface,
 				   cairo_pattern_t     *pattern,
 				   cairo_pdf_resource_t pattern_res,
 				   cairo_bool_t         is_stroke)
 {
@@ -3890,18 +3927,29 @@ static cairo_status_t
 
     return _cairo_output_stream_get_status (surface->output);
 }
 
 static cairo_status_t
 _cairo_pdf_surface_write_smask_group (cairo_pdf_surface_t     *surface,
 				      cairo_pdf_smask_group_t *group)
 {
+    double old_width, old_height;
+    cairo_matrix_t old_cairo_to_pdf;
     cairo_status_t status;
 
+    old_width = surface->width;
+    old_height = surface->height;
+    old_cairo_to_pdf = surface->cairo_to_pdf;
+    surface->width = group->width;
+    surface->height = group->height;
+    cairo_matrix_init (&surface->cairo_to_pdf, 1, 0, 0, -1, 0, surface->height);
+    _cairo_pdf_operators_set_cairo_to_pdf_matrix (&surface->pdf_operators,
+						  surface->cairo_to_pdf);
+
     /* _mask is a special case that requires two groups - source
      * and mask as well as a smask and gstate dictionary */
     if (group->operation == PDF_MASK)
 	return _cairo_pdf_surface_write_mask_group (surface, group);
 
     status = _cairo_pdf_surface_open_group (surface, &group->group_res);
     if (status)
 	return status;
@@ -3940,18 +3988,25 @@ static cairo_status_t
 						   group->num_glyphs,
 						   group->scaled_font);
 	break;
     }
     if (status)
 	return status;
 
     _cairo_pdf_surface_unselect_pattern (surface);
-
-    return _cairo_pdf_surface_close_group (surface, NULL);
+    status = _cairo_pdf_surface_close_group (surface, NULL);
+
+    surface->width = old_width;
+    surface->height = old_height;
+    surface->cairo_to_pdf = old_cairo_to_pdf;
+    _cairo_pdf_operators_set_cairo_to_pdf_matrix (&surface->pdf_operators,
+						  surface->cairo_to_pdf);
+
+    return status;
 }
 
 static cairo_status_t
 _cairo_pdf_surface_write_patterns_and_smask_groups (cairo_pdf_surface_t *surface)
 {
     cairo_pdf_pattern_t pattern;
     cairo_pdf_smask_group_t *group;
     int pattern_index, group_index;
--- a/gfx/cairo/cairo/src/cairo-pen.c
+++ b/gfx/cairo/cairo/src/cairo-pen.c
@@ -297,17 +297,17 @@ static void
 
 	_cairo_slope_init (&v->slope_cw, &prev->point, &v->point);
 	_cairo_slope_init (&v->slope_ccw, &v->point, &next->point);
     }
 }
 /*
  * Find active pen vertex for clockwise edge of stroke at the given slope.
  *
- * NOTE: The behavior of this function is sensitive to the sense of
+ * Note: The behavior of this function is sensitive to the sense of
  * the inequality within _cairo_slope_clockwise/_cairo_slope_counter_clockwise.
  *
  * The issue is that the slope_ccw member of one pen vertex will be
  * equivalent to the slope_cw member of the next pen vertex in a
  * counterclockwise order. However, for this function, we care
  * strongly about which vertex is returned.
  */
 void
@@ -331,17 +331,17 @@ void
     if (i == pen->num_vertices)
 	i = 0;
 
     *active = i;
 }
 
 /* Find active pen vertex for counterclockwise edge of stroke at the given slope.
  *
- * NOTE: The behavior of this function is sensitive to the sense of
+ * Note: The behavior of this function is sensitive to the sense of
  * the inequality within _cairo_slope_clockwise/_cairo_slope_counter_clockwise.
  */
 void
 _cairo_pen_find_active_ccw_vertex_index (cairo_pen_t *pen,
 					 cairo_slope_t *slope,
 					 int *active)
 {
     int i;
--- a/gfx/cairo/cairo/src/cairo-png.c
+++ b/gfx/cairo/cairo/src/cairo-png.c
@@ -79,17 +79,17 @@ convert_data_to_bytes (png_structp png, 
 	b[0] = (pixel & 0xff0000) >> 16;
 	b[1] = (pixel & 0x00ff00) >>  8;
 	b[2] = (pixel & 0x0000ff) >>  0;
 	b[3] = 0;
     }
 }
 
 /* Use a couple of simple error callbacks that do not print anything to
- * stderr and rely on the user to check for errors via the cairo_status_t
+ * stderr and rely on the user to check for errors via the #cairo_status_t
  * return.
  */
 static void
 png_simple_error_callback (png_structp png,
 	                   png_const_charp error_msg)
 {
     cairo_status_t *error = png_get_error_ptr (png);
 
@@ -255,21 +255,21 @@ stdio_write_func (png_structp png, png_b
 /**
  * cairo_surface_write_to_png:
  * @surface: a #cairo_surface_t with pixel contents
  * @filename: the name of a file to write to
  *
  * Writes the contents of @surface to a new file @filename as a PNG
  * image.
  *
- * Return value: CAIRO_STATUS_SUCCESS if the PNG file was written
- * successfully. Otherwise, CAIRO_STATUS_NO_MEMORY if memory could not
+ * Return value: %CAIRO_STATUS_SUCCESS if the PNG file was written
+ * successfully. Otherwise, %CAIRO_STATUS_NO_MEMORY if memory could not
  * be allocated for the operation or
  * CAIRO_STATUS_SURFACE_TYPE_MISMATCH if the surface does not have
- * pixel contents, or CAIRO_STATUS_WRITE_ERROR if an I/O error occurs
+ * pixel contents, or %CAIRO_STATUS_WRITE_ERROR if an I/O error occurs
  * while attempting to write the file.
  **/
 cairo_status_t
 cairo_surface_write_to_png (cairo_surface_t	*surface,
 			    const char		*filename)
 {
     FILE *fp;
     cairo_status_t status;
@@ -315,18 +315,18 @@ stream_write_func (png_structp png, png_
 /**
  * cairo_surface_write_to_png_stream:
  * @surface: a #cairo_surface_t with pixel contents
  * @write_func: a #cairo_write_func_t
  * @closure: closure data for the write function
  *
  * Writes the image surface to the write function.
  *
- * Return value: CAIRO_STATUS_SUCCESS if the PNG file was written
- * successfully.  Otherwise, CAIRO_STATUS_NO_MEMORY is returned if
+ * Return value: %CAIRO_STATUS_SUCCESS if the PNG file was written
+ * successfully.  Otherwise, %CAIRO_STATUS_NO_MEMORY is returned if
  * memory could not be allocated for the operation,
  * CAIRO_STATUS_SURFACE_TYPE_MISMATCH if the surface does not have
  * pixel contents.
  **/
 cairo_status_t
 cairo_surface_write_to_png_stream (cairo_surface_t	*surface,
 				   cairo_write_func_t	write_func,
 				   void			*closure)
--- a/gfx/cairo/cairo/src/cairo-ps-surface.c
+++ b/gfx/cairo/cairo/src/cairo-ps-surface.c
@@ -284,17 +284,17 @@ static cairo_status_t
 }
 
 /* The line cap value is needed to workaround the fact that PostScript
  * semantics for stroking degenerate sub-paths do not match cairo
  * semantics. (PostScript draws something for any line cap value,
  * while cairo draws something only for round caps).
  *
  * When using this function to emit a path to be filled, rather than
- * stroked, simply pass CAIRO_LINE_CAP_ROUND which will guarantee that
+ * stroked, simply pass %CAIRO_LINE_CAP_ROUND which will guarantee that
  * the stroke workaround will not modify the path being emitted.
  */
 static cairo_status_t
 _cairo_ps_surface_emit_path (cairo_ps_surface_t	   *surface,
 			     cairo_output_stream_t *stream,
 			     cairo_path_fixed_t    *path,
 			     cairo_line_cap_t	    line_cap)
 {
@@ -1027,17 +1027,17 @@ static cairo_surface_t *
  * written to @filename. See cairo_ps_surface_create_for_stream() for
  * a more flexible mechanism for handling the PostScript output than
  * simply writing it to a named file.
  *
  * Note that the size of individual pages of the PostScript output can
  * vary. See cairo_ps_surface_set_size().
  *
  * Return value: a pointer to the newly created surface. The caller
- * owns the surface and should call cairo_surface_destroy when done
+ * owns the surface and should call cairo_surface_destroy() when done
  * with it.
  *
  * This function always returns a valid pointer, but it will return a
  * pointer to a "nil" surface if an error such as out of memory
  * occurs. You can use cairo_surface_status() to check for this.
  *
  * Since: 1.2
  **/
@@ -1068,17 +1068,17 @@ cairo_ps_surface_create (const char		*fi
  * written incrementally to the stream represented by @write_func and
  * @closure. See cairo_ps_surface_create() for a more convenient way
  * to simply direct the PostScript output to a named file.
  *
  * Note that the size of individual pages of the PostScript
  * output can vary. See cairo_ps_surface_set_size().
  *
  * Return value: a pointer to the newly created surface. The caller
- * owns the surface and should call cairo_surface_destroy when done
+ * owns the surface and should call cairo_surface_destroy() when done
  * with it.
  *
  * This function always returns a valid pointer, but it will return a
  * pointer to a "nil" surface if an error such as out of memory
  * occurs. You can use cairo_surface_status() to check for this.
  *
  * Since: 1.2
  */
@@ -1102,17 +1102,17 @@ cairo_ps_surface_create_for_stream (cair
 static cairo_bool_t
 _cairo_surface_is_ps (cairo_surface_t *surface)
 {
     return surface->backend == &cairo_ps_surface_backend;
 }
 
 /* If the abstract_surface is a paginated surface, and that paginated
  * surface's target is a ps_surface, then set ps_surface to that
- * target. Otherwise return CAIRO_STATUS_SURFACE_TYPE_MISMATCH.
+ * target. Otherwise return %CAIRO_STATUS_SURFACE_TYPE_MISMATCH.
  */
 static cairo_status_t
 _extract_ps_surface (cairo_surface_t	 *surface,
 		     cairo_ps_surface_t **ps_surface)
 {
     cairo_surface_t *target;
 
     if (! _cairo_surface_is_paginated (surface))
@@ -1182,17 +1182,17 @@ cairo_ps_get_levels (cairo_ps_level_t co
 	*num_levels = CAIRO_PS_LEVEL_LAST;
 }
 
 /**
  * cairo_ps_level_to_string:
  * @level: a level id
  *
  * Get the string representation of the given @level id. This function
- * will return NULL if @level id isn't valid. See cairo_ps_get_levels()
+ * will return %NULL if @level id isn't valid. See cairo_ps_get_levels()
  * for a way to get the list of valid level ids.
  *
  * Return value: the string associated to given level.
  *
  * Since: 1.6
  **/
 const char *
 cairo_ps_level_to_string (cairo_ps_level_t level)
@@ -1200,26 +1200,26 @@ cairo_ps_level_to_string (cairo_ps_level
     if (level >= CAIRO_PS_LEVEL_LAST)
 	return NULL;
 
     return _cairo_ps_level_strings[level];
 }
 
 /**
  * cairo_ps_surface_set_eps:
- * @surface: a PostScript cairo_surface_t
- * @eps: TRUE to output EPS format PostScript
+ * @surface: a PostScript #cairo_surface_t
+ * @eps: %TRUE to output EPS format PostScript
  *
- * If @eps is TRUE, the PostScript surface will output Encapsulated
+ * If @eps is %TRUE, the PostScript surface will output Encapsulated
  * PostScript.
  *
  * This function should only be called before any drawing operations
  * have been performed on the current page. The simplest way to do
  * this is to call this function immediately after creating the
- * surface. An Encapsulated Postscript file should never contain more
+ * surface. An Encapsulated PostScript file should never contain more
  * than one page.
  *
  * Since: 1.6
  **/
 void
 cairo_ps_surface_set_eps (cairo_surface_t	*surface,
 			  cairo_bool_t           eps)
 {
@@ -1232,21 +1232,21 @@ cairo_ps_surface_set_eps (cairo_surface_
 	return;
     }
 
     ps_surface->eps = eps;
 }
 
 /**
  * cairo_ps_surface_get_eps:
- * @surface: a PostScript cairo_surface_t
+ * @surface: a PostScript #cairo_surface_t
  *
  * Check whether the PostScript surface will output Encapsulated PostScript.
  *
- * Return value: TRUE if the surface will output Encapsulated PostScript.
+ * Return value: %TRUE if the surface will output Encapsulated PostScript.
  *
  * Since: 1.6
  **/
 cairo_public cairo_bool_t
 cairo_ps_surface_get_eps (cairo_surface_t	*surface)
 {
     cairo_ps_surface_t *ps_surface = NULL;
     cairo_status_t status;
@@ -1257,17 +1257,17 @@ cairo_ps_surface_get_eps (cairo_surface_
 	return FALSE;
     }
 
     return ps_surface->eps;
 }
 
 /**
  * cairo_ps_surface_set_size:
- * @surface: a PostScript cairo_surface_t
+ * @surface: a PostScript #cairo_surface_t
  * @width_in_points: new surface width, in points (1 point == 1/72.0 inch)
  * @height_in_points: new surface height, in points (1 point == 1/72.0 inch)
  *
  * Changes the size of a PostScript surface for the current (and
  * subsequent) pages.
  *
  * This function should only be called before any drawing operations
  * have been performed on the current page. The simplest way to do
@@ -1297,17 +1297,17 @@ cairo_ps_surface_set_size (cairo_surface
 						width_in_points,
 						height_in_points);
     if (status)
 	status = _cairo_surface_set_error (surface, status);
 }
 
 /**
  * cairo_ps_surface_dsc_comment:
- * @surface: a PostScript cairo_surface_t
+ * @surface: a PostScript #cairo_surface_t
  * @comment: a comment string to be emitted into the PostScript output
  *
  * Emit a comment into the PostScript output for the given surface.
  *
  * The comment is expected to conform to the PostScript Language
  * Document Structuring Conventions (DSC). Please see that manual for
  * details on the available comments and their meanings. In
  * particular, the %%IncludeFeature comment allows a
@@ -1361,17 +1361,17 @@ cairo_ps_surface_set_size (cairo_surface
  * PageSetup section: %%BeginPageSetup, %%PageBoundingBox,
  * %%EndPageSetup.
  *
  * Other sections: %%BeginProlog, %%EndProlog, %%Page, %%Trailer, %%EOF
  *
  * Here is an example sequence showing how this function might be used:
  *
  * <informalexample><programlisting>
- * cairo_surface_t *surface = cairo_ps_surface_create (filename, width, height);
+ * #cairo_surface_t *surface = cairo_ps_surface_create (filename, width, height);
  * ...
  * cairo_ps_surface_dsc_comment (surface, "%%Title: My excellent document");
  * cairo_ps_surface_dsc_comment (surface, "%%Copyright: Copyright (C) 2006 Cairo Lover")
  * ...
  * cairo_ps_surface_dsc_begin_setup (surface);
  * cairo_ps_surface_dsc_comment (surface, "%%IncludeFeature: *MediaColor White");
  * ...
  * cairo_ps_surface_dsc_begin_page_setup (surface);
@@ -1425,17 +1425,17 @@ cairo_ps_surface_dsc_comment (cairo_surf
 	free (comment_copy);
 	status = _cairo_surface_set_error (surface, status);
 	return;
     }
 }
 
 /**
  * cairo_ps_surface_dsc_begin_setup:
- * @surface: a PostScript cairo_surface_t
+ * @surface: a PostScript #cairo_surface_t
  *
  * This function indicates that subsequent calls to
  * cairo_ps_surface_dsc_comment() should direct comments to the Setup
  * section of the PostScript output.
  *
  * This function should be called at most once per surface, and must
  * be called before any call to cairo_ps_surface_dsc_begin_page_setup()
  * and before any drawing is performed to the surface.
@@ -1459,17 +1459,17 @@ cairo_ps_surface_dsc_begin_setup (cairo_
     if (ps_surface->dsc_comment_target == &ps_surface->dsc_header_comments)
     {
 	ps_surface->dsc_comment_target = &ps_surface->dsc_setup_comments;
     }
 }
 
 /**
  * cairo_ps_surface_dsc_begin_page_setup:
- * @surface: a PostScript cairo_surface_t
+ * @surface: a PostScript #cairo_surface_t
  *
  * This function indicates that subsequent calls to
  * cairo_ps_surface_dsc_comment() should direct comments to the
  * PageSetup section of the PostScript output.
  *
  * This function call is only needed for the first page of a
  * surface. It should be called after any call to
  * cairo_ps_surface_dsc_begin_setup() and before any drawing is
@@ -1731,27 +1731,27 @@ static cairo_bool_t
     cairo_extend_t extend;
 
     if (surface->ps_level == CAIRO_PS_LEVEL_2)
 	return FALSE;
 
     surface->ps_level_used = CAIRO_PS_LEVEL_3;
     extend = cairo_pattern_get_extend (pattern);
 
-    if (extend == CAIRO_EXTEND_REPEAT ||
-        extend == CAIRO_EXTEND_REFLECT) {
-        return FALSE;
-    }
-
     /* Radial gradients are currently only supported when one circle
      * is inside the other. */
     if (pattern->type == CAIRO_PATTERN_TYPE_RADIAL) {
         double x1, y1, x2, y2, r1, r2, d;
         cairo_radial_pattern_t *radial = (cairo_radial_pattern_t *) pattern;
 
+	if (extend == CAIRO_EXTEND_REPEAT ||
+	    extend == CAIRO_EXTEND_REFLECT) {
+	    return FALSE;
+	}
+
         x1 = _cairo_fixed_to_double (radial->c1.x);
         y1 = _cairo_fixed_to_double (radial->c1.y);
         r1 = _cairo_fixed_to_double (radial->r1);
         x2 = _cairo_fixed_to_double (radial->c2.x);
         y2 = _cairo_fixed_to_double (radial->c2.y);
         r2 = _cairo_fixed_to_double (radial->r2);
 
         d = sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));
@@ -2090,25 +2090,25 @@ static cairo_status_t
     } else if (transparency == CAIRO_IMAGE_IS_OPAQUE) {
 	opaque_image = image;
 	use_mask = FALSE;
     } else {
 	use_mask = TRUE;
     }
 
     rgb_size = 3 * image->width * image->height;
-    rgb = malloc (rgb_size);
+    rgb = _cairo_malloc_abc (image->width, image->height, 3);
     if (rgb == NULL) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto bail1;
     }
 
     if (use_mask) {
 	mask_size = ((image->width+7) / 8) * image->height;
-	mask = malloc (mask_size);
+	mask = _cairo_malloc_ab ((image->width+7) / 8, image->height);
 	if (mask == NULL) {
 	    status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    goto bail2;
 	}
     }
 
     if (use_mask) {
 	int byte = 0;
@@ -2332,34 +2332,37 @@ static cairo_status_t
 
     old_content = surface->content;
     old_width = surface->width;
     old_height = surface->height;
     surface->width = meta_extents.width;
     surface->height = meta_extents.height;
     _cairo_output_stream_printf (surface->stream,
 				 "/CairoPattern {\n"
-				 "gsave\n");
+				 "  gsave\n"
+				 "  0 0 %f %f rectclip\n",
+				 surface->width,
+				 surface->height);
 
     if (cairo_surface_get_content (meta_surface) == CAIRO_CONTENT_COLOR) {
 	surface->content = CAIRO_CONTENT_COLOR;
 	_cairo_output_stream_printf (surface->stream,
-				     "0 G 0 0 %f %f rectfill\n",
+				     "  0 G 0 0 %f %f rectfill\n",
 				     surface->width,
 				     surface->height);
     }
 
     status = _cairo_meta_surface_replay_region (meta_surface, &surface->base,
 						CAIRO_META_REGION_NATIVE);
     assert (status != CAIRO_INT_STATUS_UNSUPPORTED);
     if (status)
 	return status;
 
     _cairo_output_stream_printf (surface->stream,
-				 "grestore\n"
+				 "  grestore\n"
 				 "} bind def\n");
     surface->content = old_content;
     surface->width = old_width;
     surface->height = old_height;
 
     return CAIRO_STATUS_SUCCESS;
 }
 
@@ -2474,104 +2477,136 @@ static cairo_status_t
 	 * add the surface extents unconditionally. We only
 	 * required an answer that's large enough, we don't really
 	 * care if it's not as tight as possible.*/
 	xstep = ystep = ceil ((x2 - x1) + (y2 - y1) +
 			      pattern_width + pattern_height);
 	break;
     }
     case CAIRO_EXTEND_REPEAT:
-    case CAIRO_EXTEND_REFLECT:
 	xstep = pattern_width;
 	ystep = pattern_height;
 	break;
+    case CAIRO_EXTEND_REFLECT:
+	xstep = pattern_width*2;
+	ystep = pattern_height*2;
+	break;
 	/* All the rest (if any) should have been analyzed away, so these
 	 * cases should be unreachable. */
     default:
 	ASSERT_NOT_REACHED;
 	xstep = 0;
 	ystep = 0;
     }
 
     _cairo_output_stream_printf (surface->stream,
 				 "<< /PatternType 1\n"
 				 "   /PaintType 1\n"
 				 "   /TilingType 1\n");
     _cairo_output_stream_printf (surface->stream,
-				 "   /BBox [0 0 %d %d]\n",
-				 pattern_width, pattern_height);
-    _cairo_output_stream_printf (surface->stream,
 				 "   /XStep %f /YStep %f\n",
 				 xstep, ystep);
+
+    if (pattern->base.extend == CAIRO_EXTEND_REFLECT) {
+	_cairo_output_stream_printf (surface->stream,
+				     "   /BBox [0 0 %d %d]\n"
+				     "   /PaintProc {\n"
+				     "      CairoPattern\n"
+				     "      [-1 0 0  1 %d 0] concat CairoPattern\n"
+				     "      [ 1 0 0 -1 0 %d] concat CairoPattern\n"
+				     "      [-1 0 0  1 %d 0] concat CairoPattern\n"
+				     "      CairoPattern\n"
+				     "   } bind\n",
+				     pattern_width*2, pattern_height*2,
+				     pattern_width*2,
+				     pattern_height*2,
+				     pattern_width*2);
+    } else {
+	_cairo_output_stream_printf (surface->stream,
+				     "   /BBox [0 0 %d %d]\n"
+				     "   /PaintProc { CairoPattern } bind\n",
+				     pattern_width, pattern_height);
+    }
+
     _cairo_output_stream_printf (surface->stream,
-				 "   /PaintProc { CairoPattern } bind\n"
 				 ">>\n");
+
     _cairo_output_stream_printf (surface->stream,
 				 "[ %f %f %f %f %f %f ]\n",
 				 inverse.xx, inverse.yx,
 				 inverse.xy, inverse.yy,
 				 inverse.x0, inverse.y0);
     _cairo_output_stream_printf (surface->stream,
 				 "makepattern setpattern\n");
 
     return CAIRO_STATUS_SUCCESS;
 }
 
 typedef struct _cairo_ps_color_stop {
     double offset;
-    double color[3];
+    double color[4];
 } cairo_ps_color_stop_t;
 
 static void
 _cairo_ps_surface_emit_linear_colorgradient (cairo_ps_surface_t     *surface,
 					     cairo_ps_color_stop_t  *stop1,
 					     cairo_ps_color_stop_t  *stop2)
 {
     _cairo_output_stream_printf (surface->stream,
-				 "<< /FunctionType 2\n"
-				 "   /Domain [ 0 1 ]\n"
-				 "   /C0 [ %f %f %f ]\n"
-				 "   /C1 [ %f %f %f ]\n"
-				 "   /N 1\n"
-				 ">>\n",
+				 "   << /FunctionType 2\n"
+				 "      /Domain [ 0 1 ]\n"
+				 "      /C0 [ %f %f %f ]\n"
+				 "      /C1 [ %f %f %f ]\n"
+				 "      /N 1\n"
+				 "   >>\n",
 				 stop1->color[0],
 				 stop1->color[1],
 				 stop1->color[2],
 				 stop2->color[0],
 				 stop2->color[1],
 				 stop2->color[2]);
 }
 
 static void
 _cairo_ps_surface_emit_stitched_colorgradient (cairo_ps_surface_t    *surface,
 					       unsigned int 	      n_stops,
 					       cairo_ps_color_stop_t  stops[])
 {
     unsigned int i;
 
     _cairo_output_stream_printf (surface->stream,
-				 "      << /FunctionType 3\n"
-				 "         /Domain [ 0 1 ]\n"
-				 "         /Functions [\n");
+				 "<< /FunctionType 3\n"
+				 "   /Domain [ 0 1 ]\n"
+				 "   /Functions [\n");
     for (i = 0; i < n_stops - 1; i++)
 	_cairo_ps_surface_emit_linear_colorgradient (surface, &stops[i], &stops[i+1]);
 
-    _cairo_output_stream_printf (surface->stream, "         ]\n");
-
-    _cairo_output_stream_printf (surface->stream, "         /Bounds [ ");
+    _cairo_output_stream_printf (surface->stream, "   ]\n");
+
+    _cairo_output_stream_printf (surface->stream, "   /Bounds [ ");
     for (i = 1; i < n_stops-1; i++)
 	_cairo_output_stream_printf (surface->stream, "%f ", stops[i].offset);
     _cairo_output_stream_printf (surface->stream, "]\n");
 
-    _cairo_output_stream_printf (surface->stream, "         /Encode [ ");
-    for (i = 1; i < n_stops; i++)
-	_cairo_output_stream_printf (surface->stream, "0 1 ");
-    _cairo_output_stream_printf (surface->stream,  "]\n");
-
-    _cairo_output_stream_printf (surface->stream, "      >>\n");
+    _cairo_output_stream_printf (surface->stream, "   /Encode [ 1 1 %d { pop 0 1 } for ]\n",
+				 n_stops - 1);
+
+    _cairo_output_stream_printf (surface->stream, ">>\n");
+}
+
+static void
+calc_gradient_color (cairo_ps_color_stop_t *new_stop,
+		     cairo_ps_color_stop_t *stop1,
+		     cairo_ps_color_stop_t *stop2)
+{
+    int i;
+    double offset = stop1->offset / (stop1->offset + 1.0 - stop2->offset);
+
+    for (i = 0; i < 4; i++)
+	new_stop->color[i] = stop1->color[i] + offset*(stop2->color[i] - stop1->color[i]);
 }
 
 #define COLOR_STOP_EPSILON 1e-6
 
 static cairo_status_t
 _cairo_ps_surface_emit_pattern_stops (cairo_ps_surface_t       *surface,
 				      cairo_gradient_pattern_t *pattern)
 {
@@ -2581,109 +2616,241 @@ static cairo_status_t
     allstops = _cairo_malloc_ab ((pattern->n_stops + 2), sizeof (cairo_ps_color_stop_t));
     if (allstops == NULL)
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     stops = &allstops[1];
     n_stops = pattern->n_stops;
 
     for (i = 0; i < n_stops; i++) {
+	cairo_gradient_stop_t *stop = &pattern->stops[i];
+
+	stops[i].color[0] = stop->color.red;
+	stops[i].color[1] = stop->color.green;
+	stops[i].color[2] = stop->color.blue;
+	stops[i].color[3] = stop->color.alpha;
+	stops[i].offset = _cairo_fixed_to_double (pattern->stops[i].x);
+    }
+
+    if (pattern->base.extend == CAIRO_EXTEND_REPEAT ||
+	pattern->base.extend == CAIRO_EXTEND_REFLECT) {
+	if (stops[0].offset > COLOR_STOP_EPSILON) {
+	    if (pattern->base.extend == CAIRO_EXTEND_REFLECT)
+		memcpy (allstops, stops, sizeof (cairo_ps_color_stop_t));
+	    else
+		calc_gradient_color (&allstops[0], &stops[0], &stops[n_stops-1]);
+	    stops = allstops;
+	    n_stops++;
+	}
+	stops[0].offset = 0.0;
+
+	if (stops[n_stops-1].offset < 1.0 - COLOR_STOP_EPSILON) {
+	    if (pattern->base.extend == CAIRO_EXTEND_REFLECT) {
+		memcpy (&stops[n_stops],
+			&stops[n_stops - 1],
+			sizeof (cairo_ps_color_stop_t));
+	    } else {
+		calc_gradient_color (&stops[n_stops], &stops[0], &stops[n_stops-1]);
+	    }
+	    n_stops++;
+	}
+	stops[n_stops-1].offset = 1.0;
+    }
+
+    for (i = 0; i < n_stops; i++) {
 	double red, green, blue;
-
-	_cairo_ps_surface_flatten_transparency (surface,
-						&pattern->stops[i].color,
+	cairo_color_t color;
+
+	_cairo_color_init_rgba (&color,
+				stops[i].color[0],
+				stops[i].color[1],
+				stops[i].color[2],
+				stops[i].color[3]);
+	_cairo_ps_surface_flatten_transparency (surface, &color,
 						&red, &green, &blue);
 	stops[i].color[0] = red;
 	stops[i].color[1] = green;
 	stops[i].color[2] = blue;
-	stops[i].offset = _cairo_fixed_to_double (pattern->stops[i].x);
     }
 
-    /* make sure first offset is 0.0 and last offset is 1.0 */
-    if (stops[0].offset > COLOR_STOP_EPSILON) {
-	memcpy (allstops, stops, sizeof (cairo_ps_color_stop_t));
-	stops = allstops;
-	n_stops++;
-    }
-    stops[0].offset = 0.0;
-
-    if (stops[n_stops-1].offset < 1.0 - COLOR_STOP_EPSILON) {
-	memcpy (&stops[n_stops],
-		&stops[n_stops - 1],
-		sizeof (cairo_ps_color_stop_t));
-	n_stops++;
-    }
-    stops[n_stops-1].offset = 1.0;
-
+    _cairo_output_stream_printf (surface->stream,
+				 "/CairoFunction\n");
     if (n_stops == 2) {
 	/* no need for stitched function */
 	_cairo_ps_surface_emit_linear_colorgradient (surface, &stops[0], &stops[1]);
     } else {
 	/* multiple stops: stitch. XXX possible optimization: regulary spaced
 	 * stops do not require stitching. XXX */
 	_cairo_ps_surface_emit_stitched_colorgradient (surface, n_stops,stops);
     }
+    _cairo_output_stream_printf (surface->stream,
+				 "def\n");
 
     free (allstops);
 
     return CAIRO_STATUS_SUCCESS;
 }
 
 static cairo_status_t
+_cairo_ps_surface_emit_repeating_function (cairo_ps_surface_t       *surface,
+					   cairo_gradient_pattern_t *pattern,
+					   int                       begin,
+					   int                       end)
+{
+    _cairo_output_stream_printf (surface->stream,
+				 "/CairoFunction\n"
+				 "<< /FunctionType 3\n"
+				 "   /Domain [ %d %d ]\n"
+				 "   /Functions [ %d {CairoFunction} repeat ]\n"
+				 "   /Bounds [ %d 1 %d {} for ]\n",
+				 begin,
+                                 end,
+				 end - begin,
+				 begin + 1,
+				 end - 1);
+
+    if (pattern->base.extend == CAIRO_EXTEND_REFLECT) {
+	_cairo_output_stream_printf (surface->stream, "   /Encode [ %d 1 %d { 2 mod 0 eq {0 1} {1 0} ifelse } for ]\n",
+				     begin,
+				     end - 1);
+    } else {
+	_cairo_output_stream_printf (surface->stream, "   /Encode [ %d 1 %d { pop 0 1 } for ]\n",
+				     begin,
+				     end - 1);
+    }
+
+    _cairo_output_stream_printf (surface->stream, ">> def\n");
+
+    return CAIRO_STATUS_SUCCESS;
+}
+
+static cairo_status_t
 _cairo_ps_surface_emit_linear_pattern (cairo_ps_surface_t     *surface,
 				       cairo_linear_pattern_t *pattern)
 {
     double x1, y1, x2, y2;
+    double _x1, _y1, _x2, _y2;
+    cairo_matrix_t pat_to_ps;
     cairo_extend_t extend;
     cairo_status_t status;
-    cairo_matrix_t inverse = pattern->base.base.matrix;
+    cairo_gradient_pattern_t *gradient = &pattern->base;
+    double first_stop, last_stop;
+    int repeat_begin = 0, repeat_end = 1;
 
     if (pattern->base.n_stops == 0)
         return CAIRO_INT_STATUS_NOTHING_TO_DO;
 
     extend = cairo_pattern_get_extend (&pattern->base.base);
 
-    status = cairo_matrix_invert (&inverse);
-    if (status)
-	return status;
-
+    pat_to_ps = pattern->base.base.matrix;
+    status = cairo_matrix_invert (&pat_to_ps);
+    /* cairo_pattern_set_matrix ensures the matrix is invertible */
+    assert (status == CAIRO_STATUS_SUCCESS);
+
+    first_stop = _cairo_fixed_to_double (gradient->stops[0].x);
+    last_stop = _cairo_fixed_to_double (gradient->stops[gradient->n_stops - 1].x);
+
+    if (pattern->base.base.extend == CAIRO_EXTEND_REPEAT ||
+	pattern->base.base.extend == CAIRO_EXTEND_REFLECT) {
+	double dx, dy;
+	int x_rep = 0, y_rep = 0;
+
+	x1 = _cairo_fixed_to_double (pattern->p1.x);
+	y1 = _cairo_fixed_to_double (pattern->p1.y);
+	cairo_matrix_transform_point (&pat_to_ps, &x1, &y1);
+
+	x2 = _cairo_fixed_to_double (pattern->p2.x);
+	y2 = _cairo_fixed_to_double (pattern->p2.y);
+	cairo_matrix_transform_point (&pat_to_ps, &x2, &y2);
+
+	dx = fabs (x2 - x1);
+	dy = fabs (y2 - y1);
+	if (dx > 1e-6)
+	    x_rep = (int) ceil (surface->width/dx);
+	if (dy > 1e-6)
+	    y_rep = (int) ceil (surface->height/dy);
+
+	repeat_end = MAX (x_rep, y_rep);
+	repeat_begin = -repeat_end;
+	first_stop = repeat_begin;
+	last_stop = repeat_end;
+    }
+
+    /* PS requires the first and last stop to be the same as the line
+     * coordinates. For repeating patterns this moves the line
+     * coordinates out to the begin/end of the repeating function. For
+     * non repeating patterns this may move the line coordinates in if
+     * there are not stops at offset 0 and 1. */
     x1 = _cairo_fixed_to_double (pattern->p1.x);
     y1 = _cairo_fixed_to_double (pattern->p1.y);
     x2 = _cairo_fixed_to_double (pattern->p2.x);
     y2 = _cairo_fixed_to_double (pattern->p2.y);
 
+    _x1 = x1 + (x2 - x1)*first_stop;
+    _y1 = y1 + (y2 - y1)*first_stop;
+    _x2 = x1 + (x2 - x1)*last_stop;
+    _y2 = y1 + (y2 - y1)*last_stop;
+
+    x1 = _x1;
+    x2 = _x2;
+    y1 = _y1;
+    y2 = _y2;
+
+    /* For EXTEND_NONE and EXTEND_PAD if there are only two stops a
+     * Type 2 function is used by itself without a stitching
+     * function. Type 2 functions always have the domain [0 1] */
+    if ((pattern->base.base.extend == CAIRO_EXTEND_NONE ||
+	 pattern->base.base.extend == CAIRO_EXTEND_PAD) &&
+	gradient->n_stops == 2) {
+	first_stop = 0.0;
+	last_stop = 1.0;
+    }
+
+    status = _cairo_ps_surface_emit_pattern_stops (surface,
+						   &pattern->base);
+    if (status)
+	return status;
+
+    if (pattern->base.base.extend == CAIRO_EXTEND_REPEAT ||
+	pattern->base.base.extend == CAIRO_EXTEND_REFLECT) {
+	status = _cairo_ps_surface_emit_repeating_function (surface,
+							    &pattern->base,
+							    repeat_begin,
+							    repeat_end);
+	if (status)
+	    return status;
+    }
+
     _cairo_output_stream_printf (surface->stream,
 				 "<< /PatternType 2\n"
 				 "   /Shading\n"
 				 "   << /ShadingType 2\n"
 				 "      /ColorSpace /DeviceRGB\n"
 				 "      /Coords [ %f %f %f %f ]\n"
-				 "      /Function\n",
-				 x1, y1, x2, y2);
-
-    status = _cairo_ps_surface_emit_pattern_stops (surface, &pattern->base);
-    if (status)
-	return status;
+                                 "      /Domain [ %f %f ]\r\n"
+				 "      /Function CairoFunction\n",
+				 x1, y1, x2, y2,
+				 first_stop, last_stop);
 
     if (extend == CAIRO_EXTEND_PAD) {
 	_cairo_output_stream_printf (surface->stream,
                                      "      /Extend [ true true ]\r\n");
     } else {
 	_cairo_output_stream_printf (surface->stream,
                                      "      /Extend [ false false ]\r\n");
     }
 
     _cairo_output_stream_printf (surface->stream,
 				 "   >>\n"
 				 ">>\n");
     _cairo_output_stream_printf (surface->stream,
 				 "[ %f %f %f %f %f %f ]\n",
-				 inverse.xx, inverse.yx,
-				 inverse.xy, inverse.yy,
-				 inverse.x0, inverse.y0);
+                                 pat_to_ps.xx, pat_to_ps.yx,
+                                 pat_to_ps.xy, pat_to_ps.yy,
+                                 pat_to_ps.x0, pat_to_ps.y0);
     _cairo_output_stream_printf (surface->stream,
 				 "makepattern setpattern\n");
 
     return status;
 }
 
 static cairo_status_t
 _cairo_ps_surface_emit_radial_pattern (cairo_ps_surface_t     *surface,
@@ -3084,17 +3251,17 @@ static cairo_int_status_t
 	_cairo_output_stream_printf (stream, "] %f setdash\n",
 				     dash_offset);
     }
     if (dash != style->dash)
 	free (dash);
 
     /* miter limit */
     _cairo_output_stream_printf (stream, "%f setmiterlimit\n",
-				 style->miter_limit);
+				 style->miter_limit < 1.0 ? 1.0 : style->miter_limit);
     _cairo_output_stream_printf (stream,
 				 "stroke\n");
     _cairo_output_stream_printf (stream,
 				 "grestore\n");
 
     return CAIRO_STATUS_SUCCESS;
 }
 
--- a/gfx/cairo/cairo/src/cairo-ps.h
+++ b/gfx/cairo/cairo/src/cairo-ps.h
@@ -43,17 +43,17 @@
 
 #include <stdio.h>
 
 CAIRO_BEGIN_DECLS
 
 /* PS-surface functions */
 
 /**
- * cairo_ps_level_t
+ * cairo_ps_level_t:
  * @CAIRO_PS_LEVEL_2: The language level 2 of the PostScript specification.
  * @CAIRO_PS_LEVEL_3: The language level 3 of the PostScript specification.
  *
  * #cairo_ps_level_t is used to describe the language level of the
  * PostScript Language Reference that a generated PostScript file will
  * conform to.
  */
 typedef enum _cairo_ps_level {
--- a/gfx/cairo/cairo/src/cairo-rectangle.c
+++ b/gfx/cairo/cairo/src/cairo-rectangle.c
@@ -1,8 +1,9 @@
+/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */
 /* cairo - a vector graphics library with display and print output
  *
  * Copyright © 2002 University of Southern California
  * Copyright © 2005 Red Hat, Inc.
  * Copyright © 2006 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it either under the terms of the GNU Lesser General Public
@@ -34,25 +35,25 @@
  *
  * Contributor(s):
  *	Carl D. Worth <cworth@cworth.org>
  */
 
 #include "cairoint.h"
 
 /* XXX We currently have a confusing mix of boxes and rectangles as
- * exemplified by this function.  A cairo_box_t is a rectangular area
+ * exemplified by this function.  A #cairo_box_t is a rectangular area
  * represented by the coordinates of the upper left and lower right
- * corners, expressed in fixed point numbers.  A cairo_rectangle_int_t is
+ * corners, expressed in fixed point numbers.  A #cairo_rectangle_int_t is
  * also a rectangular area, but represented by the upper left corner
  * and the width and the height, as integer numbers.
  *
- * This function converts a cairo_box_t to a cairo_rectangle_int_t by
+ * This function converts a #cairo_box_t to a #cairo_rectangle_int_t by
  * increasing the area to the nearest integer coordinates.  We should
- * standardize on cairo_rectangle_fixed_t and cairo_rectangle_int_t, and
+ * standardize on #cairo_rectangle_fixed_t and #cairo_rectangle_int_t, and
  * this function could be renamed to the more reasonable
  * _cairo_rectangle_fixed_round.
  */
 
 void
 _cairo_box_round_to_rectangle (cairo_box_t *box, cairo_rectangle_int_t *rectangle)
 {
     rectangle->x = _cairo_fixed_integer_floor (box->p1.x);
@@ -78,8 +79,107 @@ void
 	dest->height = 0;
     } else {
 	dest->x = x1;
 	dest->y = y1;
 	dest->width = x2 - x1;
 	dest->height = y2 - y1;
     }
 }
+
+
+#define P1x (line->p1.x)
+#define P1y (line->p1.y)
+#define P2x (line->p2.x)
+#define P2y (line->p2.y)
+#define B1x (box->p1.x)
+#define B1y (box->p1.y)
+#define B2x (box->p2.x)
+#define B2y (box->p2.y)
+
+/*
+ * Check whether any part of line intersects box.  This function essentially
+ * computes whether the ray starting at line->p1 in the direction of line->p2
+ * intersects the box before it reaches p2.  Normally, this is done
+ * by dividing by the lengths of the line projected onto each axis.  Because
+ * we're in fixed point, this function does a bit more work to avoid having to
+ * do the division -- we don't care about the actual intersection point, so
+ * it's of no interest to us.
+ */
+
+cairo_bool_t
+_cairo_box_intersects_line_segment (cairo_box_t *box, cairo_line_t *line)
+{
+    cairo_fixed_t t1, t2, t3, t4;
+    cairo_int64_t t1y, t2y, t3x, t4x;
+
+    cairo_fixed_t xlen, ylen;
+
+    if (_cairo_box_contains_point(box, &line->p1) ||
+	_cairo_box_contains_point(box, &line->p2))
+	return TRUE;
+
+    xlen = P2x - P1x;
+    ylen = P2y - P1y;
+
+    if (xlen) {
+	if (xlen > 0) {
+	    t1 = B1x - P1x;
+	    t2 = B2x - P1x;
+	} else {
+	    t1 = P1x - B2x;
+	    t2 = P1x - B1x;
+	    xlen = - xlen;
+	}
+
+	if ((t1 < 0 || t1 > xlen) &&
+	    (t2 < 0 || t2 > xlen))
+	    return FALSE;
+    } else {
+	/* Fully vertical line -- check that X is in bounds */
+	if (P1x < B1x || P1x > B2x)
+	    return FALSE;
+    }
+
+    if (ylen) {
+	if (ylen > 0) {
+	    t3 = B1y - P1y;
+	    t4 = B2y - P1y;
+	} else {
+	    t3 = P1y - B2y;
+	    t4 = P1y - B1y;
+	    ylen = - ylen;
+	}
+
+	if ((t3 < 0 || t3 > ylen) &&
+	    (t4 < 0 || t4 > ylen))
+	    return FALSE;
+    } else {
+	/* Fully horizontal line -- check Y */
+	if (P1y < B1y || P1y > B2y)
+	    return FALSE;
+    }
+
+    /* If we had a horizontal or vertical line, then it's already been checked */
+    if (P1x == P2x || P1y == P2y)
+	return TRUE;
+
+    /* Check overlap.  Note that t1 < t2 and t3 < t4 here. */
+    t1y = _cairo_int32x32_64_mul (t1, ylen);
+    t2y = _cairo_int32x32_64_mul (t2, ylen);
+    t3x = _cairo_int32x32_64_mul (t3, xlen);
+    t4x = _cairo_int32x32_64_mul (t4, xlen);
+
+    if (_cairo_int64_lt(t1y, t4x) &&
+	_cairo_int64_lt(t3x, t2y))
+	return TRUE;
+
+    return FALSE;
+}
+
+cairo_bool_t
+_cairo_box_contains_point (cairo_box_t *box, cairo_point_t *point)
+{
+    if (point->x < box->p1.x || point->x > box->p2.x ||
+	point->y < box->p1.y || point->y > box->p2.y)
+	return FALSE;
+    return TRUE;
+}
--- a/gfx/cairo/cairo/src/cairo-region-private.h
+++ b/gfx/cairo/cairo/src/cairo-region-private.h
@@ -36,17 +36,17 @@
 
 #ifndef CAIRO_REGION_PRIVATE_H
 #define CAIRO_REGION_PRIVATE_H
 
 #include <pixman.h>
 
 #include "cairo-compiler-private.h"
 
-/* cairo_region_t is defined in cairoint.h */
+/* #cairo_region_t is defined in cairoint.h */
 
 struct _cairo_region {
     pixman_region16_t rgn;
 };
 
 cairo_private void
 _cairo_region_init (cairo_region_t *region);
 
--- a/gfx/cairo/cairo/src/cairo-region.c
+++ b/gfx/cairo/cairo/src/cairo-region.c
@@ -144,17 +144,17 @@ void
     free (boxes);
 }
 
 /**
  * _cairo_region_get_extents:
  * @region: a #cairo_region_t
  * @rect: rectangle into which to store the extents
  *
- * Gets the bounding box of a region as a cairo_rectangle_int_t
+ * Gets the bounding box of a region as a #cairo_rectangle_int_t
  **/
 void
 _cairo_region_get_extents (cairo_region_t *region, cairo_rectangle_int_t *extents)
 {
     pixman_box16_t *pextents = pixman_region_extents (&region->rgn);
 
     extents->x = pextents->x1;
     extents->y = pextents->y1;
--- a/gfx/cairo/cairo/src/cairo-scaled-font-subsets-private.h
+++ b/gfx/cairo/cairo/src/cairo-scaled-font-subsets-private.h
@@ -47,19 +47,19 @@ typedef struct _cairo_scaled_font_subset
     cairo_bool_t is_composite;
     double       x_advance;
 } cairo_scaled_font_subsets_glyph_t;
 
 /**
  * _cairo_scaled_font_subsets_create_scaled:
  *
  * Create a new #cairo_scaled_font_subsets_t object which can be used
- * to create subsets of any number of cairo_scaled_font_t
+ * to create subsets of any number of #cairo_scaled_font_t
  * objects. This allows the (arbitrarily large and sparse) glyph
- * indices of a cairo_scaled_font to be mapped to one or more font
+ * indices of a #cairo_scaled_font_t to be mapped to one or more font
  * subsets with glyph indices packed into the range
  * [0 .. max_glyphs_per_subset).
  *
  * Return value: a pointer to the newly creates font subsets. The
  * caller owns this object and should call
  * _cairo_scaled_font_subsets_destroy() when done with it.
  **/
 cairo_private cairo_scaled_font_subsets_t *
@@ -69,17 +69,17 @@ cairo_private cairo_scaled_font_subsets_
  * _cairo_scaled_font_subsets_create_simple:
  *
  * Create a new #cairo_scaled_font_subsets_t object which can be used
  * to create font subsets suitable for embedding as Postscript or PDF
  * simple fonts.
  *
  * Glyphs with an outline path available will be mapped to one font
  * subset for each font face. Glyphs from bitmap fonts will mapped to
- * separate font subsets for each cairo_scaled_font_t object.
+ * separate font subsets for each #cairo_scaled_font_t object.
  *
  * The maximum number of glyphs per subset is 256. Each subset
  * reserves the first glyph for the .notdef glyph.
  *
  * Return value: a pointer to the newly creates font subsets. The
  * caller owns this object and should call
  * _cairo_scaled_font_subsets_destroy() when done with it.
  **/
@@ -93,17 +93,17 @@ cairo_private cairo_scaled_font_subsets_
  * to create font subsets suitable for embedding as Postscript or PDF
  * composite fonts.
  *
  * Glyphs with an outline path available will be mapped to one font
  * subset for each font face. Each unscaled subset has a maximum of
  * 65536 glyphs except for Type1 fonts which have a maximum of 256 glyphs.
  *
  * Glyphs from bitmap fonts will mapped to separate font subsets for
- * each cairo_scaled_font_t object. Each unscaled subset has a maximum
+ * each #cairo_scaled_font_t object. Each unscaled subset has a maximum
  * of 256 glyphs.
  *
  * Each subset reserves the first glyph for the .notdef glyph.
  *
  * Return value: a pointer to the newly creates font subsets. The
  * caller owns this object and should call
  * _cairo_scaled_font_subsets_destroy() when done with it.
  **/
@@ -162,28 +162,28 @@ cairo_private void
  * by one or more font subsets. Each subset is effectively a tuple of
  * (scaled_font, font_id, subset_id) and within each subset there
  * exists a mapping of scaled_glyph_font_index to subset_glyph_index.
  *
  * This final description of a font subset is the same representation
  * used by #cairo_scaled_font_subset_t as provided by
  * _cairo_scaled_font_subsets_foreach.
  *
- * The returned values in the cairo_scaled_font_subsets_glyph_t struct are:
+ * The returned values in the #cairo_scaled_font_subsets_glyph_t struct are:
  *
  * @font_id: The font ID of the mapped glyph
  * @subset_id : The subset ID of the mapped glyph within the @font_id
  * @subset_glyph_index: The index of the mapped glyph within the @subset_id subset
  * @is_scaled: If true, the mapped glyph is from a bitmap font, and separate font
  * subset is created for each font scale used. If false, the outline of the mapped glyph
  * is available. One font subset for each font face is created.
  * @x_advance: When @is_scaled is true, @x_advance contains the x_advance for the mapped glyph in device space.
  * When @is_scaled is false, @x_advance contains the x_advance for the the mapped glyph from an unhinted 1 point font.
  *
- * Return value: CAIRO_STATUS_SUCCESS if successful, or a non-zero
+ * Return value: %CAIRO_STATUS_SUCCESS if successful, or a non-zero
  * value indicating an error. Possible errors include
  * CAIRO_STATUS_NO_MEMORY.
  **/
 cairo_private cairo_status_t
 _cairo_scaled_font_subsets_map_glyph (cairo_scaled_font_subsets_t	*font_subsets,
 				      cairo_scaled_font_t		*scaled_font,
 				      unsigned long			 scaled_font_glyph_index,
                                       cairo_scaled_font_subsets_glyph_t *subset_glyph_ret);
@@ -213,17 +213,17 @@ typedef cairo_status_t
  * a mapping between subset glyph indices and the original scaled font
  * glyph indices.
  *
  * The index of the array corresponds to subset_glyph_index values
  * returned by _cairo_scaled_font_subsets_map_glyph() while the
  * values of the array correspond to the scaled_font_glyph_index
  * values passed as input to the same function.
  *
- * Return value: CAIRO_STATUS_SUCCESS if successful, or a non-zero
+ * Return value: %CAIRO_STATUS_SUCCESS if successful, or a non-zero
  * value indicating an error. Possible errors include
  * CAIRO_STATUS_NO_MEMORY.
  **/
 cairo_private cairo_status_t
 _cairo_scaled_font_subsets_foreach_scaled (cairo_scaled_font_subsets_t		    *font_subsets,
 				           cairo_scaled_font_subset_callback_func_t  font_subset_callback,
 				           void					    *closure);
 
@@ -248,36 +248,36 @@ cairo_private cairo_status_t
  * a mapping between subset glyph indices and the original scaled font
  * glyph indices.
  *
  * The index of the array corresponds to subset_glyph_index values
  * returned by _cairo_scaled_font_subsets_map_glyph() while the
  * values of the array correspond to the scaled_font_glyph_index
  * values passed as input to the same function.
  *
- * Return value: CAIRO_STATUS_SUCCESS if successful, or a non-zero
+ * Return value: %CAIRO_STATUS_SUCCESS if successful, or a non-zero
  * value indicating an error. Possible errors include
  * CAIRO_STATUS_NO_MEMORY.
  **/
 cairo_private cairo_status_t
 _cairo_scaled_font_subsets_foreach_unscaled (cairo_scaled_font_subsets_t              *font_subsets,
                                              cairo_scaled_font_subset_callback_func_t  font_subset_callback,
 				             void				      *closure);
 
 /**
  * _cairo_scaled_font_subset_create_glyph_names:
  * @font_subsets: a #cairo_scaled_font_subsets_t
  *
  * Create an array of strings containing the glyph name for each glyph
  * in @font_subsets. The array as store in font_subsets->glyph_names.
  *
- * Return value: CAIRO_STATUS_SUCCESS if successful,
+ * Return value: %CAIRO_STATUS_SUCCESS if successful,
  * CAIRO_INT_STATUS_UNSUPPORTED if the font backend does not support
  * mapping the glyph indices to unicode characters. Possible errors
- * include CAIRO_STATUS_NO_MEMORY.
+ * include %CAIRO_STATUS_NO_MEMORY.
  **/
 cairo_private cairo_int_status_t
 _cairo_scaled_font_subset_create_glyph_names (cairo_scaled_font_subset_t *subset);
 
 typedef struct _cairo_cff_subset {
     char *base_font;
     int *widths;
     long x_min, y_min, x_max, y_max;
@@ -287,25 +287,25 @@ typedef struct _cairo_cff_subset {
 } cairo_cff_subset_t;
 
 /**
  * _cairo_cff_subset_init:
  * @cff_subset: a #cairo_cff_subset_t to initialize
  * @font_subset: the #cairo_scaled_font_subset_t to initialize from
  *
  * If possible (depending on the format of the underlying
- * cairo_scaled_font_t and the font backend in use) generate a
+ * #cairo_scaled_font_t and the font backend in use) generate a
  * cff file corresponding to @font_subset and initialize
  * @cff_subset with information about the subset and the cff
  * data.
  *
- * Return value: CAIRO_STATUS_SUCCESS if successful,
+ * Return value: %CAIRO_STATUS_SUCCESS if successful,
  * CAIRO_INT_STATUS_UNSUPPORTED if the font can't be subset as a
  * cff file, or an non-zero value indicating an error.  Possible
- * errors include CAIRO_STATUS_NO_MEMORY.
+ * errors include %CAIRO_STATUS_NO_MEMORY.
  **/
 cairo_private cairo_status_t
 _cairo_cff_subset_init (cairo_cff_subset_t          *cff_subset,
                         const char                  *name,
                         cairo_scaled_font_subset_t  *font_subset);
 
 /**
  * _cairo_cff_subset_fini:
@@ -319,24 +319,24 @@ cairo_private void
 _cairo_cff_subset_fini (cairo_cff_subset_t *cff_subset);
 
 /**
  * _cairo_cff_fallback_init:
  * @cff_subset: a #cairo_cff_subset_t to initialize
  * @font_subset: the #cairo_scaled_font_subset_t to initialize from
  *
  * If possible (depending on the format of the underlying
- * cairo_scaled_font_t and the font backend in use) generate a cff
+ * #cairo_scaled_font_t and the font backend in use) generate a cff
  * file corresponding to @font_subset and initialize @cff_subset
  * with information about the subset and the cff data.
  *
- * Return value: CAIRO_STATUS_SUCCESS if successful,
+ * Return value: %CAIRO_STATUS_SUCCESS if successful,
  * CAIRO_INT_STATUS_UNSUPPORTED if the font can't be subset as a
  * cff file, or an non-zero value indicating an error.  Possible
- * errors include CAIRO_STATUS_NO_MEMORY.
+ * errors include %CAIRO_STATUS_NO_MEMORY.
  **/
 cairo_private cairo_status_t
 _cairo_cff_fallback_init (cairo_cff_subset_t          *cff_subset,
                           const char                  *name,
                           cairo_scaled_font_subset_t  *font_subset);
 
 /**
  * _cairo_cff_fallback_fini:
@@ -361,25 +361,25 @@ typedef struct _cairo_truetype_subset {
 } cairo_truetype_subset_t;
 
 /**
  * _cairo_truetype_subset_init:
  * @truetype_subset: a #cairo_truetype_subset_t to initialize
  * @font_subset: the #cairo_scaled_font_subset_t to initialize from
  *
  * If possible (depending on the format of the underlying
- * cairo_scaled_font_t and the font backend in use) generate a
+ * #cairo_scaled_font_t and the font backend in use) generate a
  * truetype file corresponding to @font_subset and initialize
  * @truetype_subset with information about the subset and the truetype
  * data.
  *
- * Return value: CAIRO_STATUS_SUCCESS if successful,
+ * Return value: %CAIRO_STATUS_SUCCESS if successful,
  * CAIRO_INT_STATUS_UNSUPPORTED if the font can't be subset as a
  * truetype file, or an non-zero value indicating an error.  Possible
- * errors include CAIRO_STATUS_NO_MEMORY.
+ * errors include %CAIRO_STATUS_NO_MEMORY.
  **/
 cairo_private cairo_status_t
 _cairo_truetype_subset_init (cairo_truetype_subset_t    *truetype_subset,
 			     cairo_scaled_font_subset_t	*font_subset);
 
 /**
  * _cairo_truetype_subset_fini:
  * @truetype_subset: a #cairo_truetype_subset_t
@@ -406,24 +406,24 @@ typedef struct _cairo_type1_subset {
 
 /**
  * _cairo_type1_subset_init:
  * @type1_subset: a #cairo_type1_subset_t to initialize
  * @font_subset: the #cairo_scaled_font_subset_t to initialize from
  * @hex_encode: if true the encrypted portion of the font is hex encoded
  *
  * If possible (depending on the format of the underlying
- * cairo_scaled_font_t and the font backend in use) generate a type1
+ * #cairo_scaled_font_t and the font backend in use) generate a type1
  * file corresponding to @font_subset and initialize @type1_subset
  * with information about the subset and the type1 data.
  *
- * Return value: CAIRO_STATUS_SUCCESS if successful,
+ * Return value: %CAIRO_STATUS_SUCCESS if successful,
  * CAIRO_INT_STATUS_UNSUPPORTED if the font can't be subset as a type1
  * file, or an non-zero value indicating an error.  Possible errors
- * include CAIRO_STATUS_NO_MEMORY.
+ * include %CAIRO_STATUS_NO_MEMORY.
  **/
 cairo_private cairo_status_t
 _cairo_type1_subset_init (cairo_type1_subset_t		*type_subset,
 			  const char			*name,
 			  cairo_scaled_font_subset_t	*font_subset,
                           cairo_bool_t                   hex_encode);
 
 /**
@@ -436,57 +436,57 @@ cairo_private cairo_status_t
  **/
 cairo_private void
 _cairo_type1_subset_fini (cairo_type1_subset_t *subset);
 
 /**
  * _cairo_type1_scaled_font_is_type1:
  * @scaled_font: a #cairo_scaled_font_t
  *
- * Return TRUE if @scaled_font is a Type 1 font, otherwise return FALSE.
+ * Return %TRUE if @scaled_font is a Type 1 font, otherwise return %FALSE.
  **/
 cairo_private cairo_bool_t
 _cairo_type1_scaled_font_is_type1 (cairo_scaled_font_t	*scaled_font);
 
 /**
  * _cairo_type1_fallback_init_binary:
  * @type1_subset: a #cairo_type1_subset_t to initialize
  * @font_subset: the #cairo_scaled_font_subset_t to initialize from
  *
  * If possible (depending on the format of the underlying
- * cairo_scaled_font_t and the font backend in use) generate a type1
+ * #cairo_scaled_font_t and the font backend in use) generate a type1
  * file corresponding to @font_subset and initialize @type1_subset
  * with information about the subset and the type1 data.  The encrypted
  * part of the font is binary encoded.
  *
- * Return value: CAIRO_STATUS_SUCCESS if successful,
+ * Return value: %CAIRO_STATUS_SUCCESS if successful,
  * CAIRO_INT_STATUS_UNSUPPORTED if the font can't be subset as a type1
  * file, or an non-zero value indicating an error.  Possible errors
- * include CAIRO_STATUS_NO_MEMORY.
+ * include %CAIRO_STATUS_NO_MEMORY.
  **/
 cairo_private cairo_status_t
 _cairo_type1_fallback_init_binary (cairo_type1_subset_t	      *type_subset,
                                    const char		      *name,
                                    cairo_scaled_font_subset_t *font_subset);
 
 /**
  * _cairo_type1_fallback_init_hexencode:
  * @type1_subset: a #cairo_type1_subset_t to initialize
  * @font_subset: the #cairo_scaled_font_subset_t to initialize from
  *
  * If possible (depending on the format of the underlying
- * cairo_scaled_font_t and the font backend in use) generate a type1
+ * #cairo_scaled_font_t and the font backend in use) generate a type1
  * file corresponding to @font_subset and initialize @type1_subset
  * with information about the subset and the type1 data. The encrypted
  * part of the font is hex encoded.
  *
- * Return value: CAIRO_STATUS_SUCCESS if successful,
+ * Return value: %CAIRO_STATUS_SUCCESS if successful,
  * CAIRO_INT_STATUS_UNSUPPORTED if the font can't be subset as a type1
  * file, or an non-zero value indicating an error.  Possible errors
- * include CAIRO_STATUS_NO_MEMORY.
+ * include %CAIRO_STATUS_NO_MEMORY.
  **/
 cairo_private cairo_status_t
 _cairo_type1_fallback_init_hex (cairo_type1_subset_t	   *type_subset,
                                 const char		   *name,
                                 cairo_scaled_font_subset_t *font_subset);
 
 /**
  * _cairo_type1_fallback_fini:
@@ -507,24 +507,24 @@ typedef struct _cairo_type2_charstrings 
 } cairo_type2_charstrings_t;
 
 /**
  * _cairo_type2_charstrings_init:
  * @type2_subset: a #cairo_type2_subset_t to initialize
  * @font_subset: the #cairo_scaled_font_subset_t to initialize from
  *
  * If possible (depending on the format of the underlying
- * cairo_scaled_font_t and the font backend in use) generate type2
+ * #cairo_scaled_font_t and the font backend in use) generate type2
  * charstrings to @font_subset and initialize @type2_subset
  * with information about the subset.
  *
- * Return value: CAIRO_STATUS_SUCCESS if successful,
+ * Return value: %CAIRO_STATUS_SUCCESS if successful,
  * CAIRO_INT_STATUS_UNSUPPORTED if the font can't be subset as a type2
  * charstrings, or an non-zero value indicating an error.  Possible errors
- * include CAIRO_STATUS_NO_MEMORY.
+ * include %CAIRO_STATUS_NO_MEMORY.
  **/
 cairo_private cairo_status_t
 _cairo_type2_charstrings_init (cairo_type2_charstrings_t   *charstrings,
                                cairo_scaled_font_subset_t  *font_subset);
 
 /**
  * _cairo_type2_charstrings_fini:
  * @subset: a #cairo_type2_charstrings_t
@@ -536,21 +536,21 @@ cairo_private cairo_status_t
 cairo_private void
 _cairo_type2_charstrings_fini (cairo_type2_charstrings_t *charstrings);
 
 /**
  * _cairo_truetype_create_glyph_to_unicode_map:
  * @font_subset: the #cairo_scaled_font_subset_t to initialize from
  *
  * If possible (depending on the format of the underlying
- * cairo_scaled_font_t and the font backend in use) assign
+ * #cairo_scaled_font_t and the font backend in use) assign
  * the unicode character of each glyph in font_subset to
  * fontsubset->to_unicode.
  *
- * Return value: CAIRO_STATUS_SUCCESS if successful,
+ * Return value: %CAIRO_STATUS_SUCCESS if successful,
  * CAIRO_INT_STATUS_UNSUPPORTED if the unicode encoding of
  * the glyphs is not available.  Possible  errors include
  * CAIRO_STATUS_NO_MEMORY.
  **/
 cairo_private cairo_int_status_t
 _cairo_truetype_create_glyph_to_unicode_map (cairo_scaled_font_subset_t	*font_subset);
 
 #endif /* CAIRO_SCALED_FONT_SUBSETS_PRIVATE_H */
--- a/gfx/cairo/cairo/src/cairo-scaled-font.c
+++ b/gfx/cairo/cairo/src/cairo-scaled-font.c
@@ -36,26 +36,26 @@
  *      Owen Taylor <otaylor@redhat.com>
  *      Behdad Esfahbod <behdad@behdad.org>
  */
 
 #include "cairoint.h"
 #include "cairo-scaled-font-private.h"
 
 /*
- *  NOTES:
+ *  Notes:
  *
  *  To store rasterizations of glyphs, we use an image surface and the
  *  device offset to represent the glyph origin.
  *
  *  A device_transform converts from device space (a conceptual space) to
  *  surface space.  For simple cases of translation only, it's called a
- *  device_offset and is public API (cairo_surface_[gs]et_device_offset).
+ *  device_offset and is public API (cairo_surface_[gs]et_device_offset()).
  *  A possibly better name for those functions could have been
- *  cairo_surface_[gs]et_origing.  So, that's what they do: they set where
+ *  cairo_surface_[gs]et_origin().  So, that's what they do: they set where
  *  the device-space origin (0,0) is in the surface.  If the origin is inside
  *  the surface, device_offset values are positive.  It may look like this:
  *
  *  Device space:
  *        (-x,-y) <-- negative numbers
  *           +----------------+
  *           |      .         |
  *           |      .         |
@@ -266,31 +266,31 @@ cairo_scaled_font_get_type (cairo_scaled
 cairo_status_t
 cairo_scaled_font_status (cairo_scaled_font_t *scaled_font)
 {
     return scaled_font->status;
 }
 slim_hidden_def (cairo_scaled_font_status);
 
 /* Here we keep a unique mapping from
- * cairo_font_face_t/matrix/ctm/options => cairo_scaled_font_t.
+ * font_face/matrix/ctm/font_options => #cairo_scaled_font_t.
  *
  * Here are the things that we want to map:
  *
- *  a) All otherwise referenced cairo_scaled_font_t's
- *  b) Some number of not otherwise referenced cairo_scaled_font_t's
+ *  a) All otherwise referenced #cairo_scaled_font_t's
+ *  b) Some number of not otherwise referenced #cairo_scaled_font_t's
  *
  * The implementation uses a hash table which covers (a)
  * completely. Then, for (b) we have an array of otherwise
  * unreferenced fonts (holdovers) which are expired in
  * least-recently-used order.
  *
- * The cairo_scaled_font_create code gets to treat this like a regular
+ * The cairo_scaled_font_create() code gets to treat this like a regular
  * hash table. All of the magic for the little holdover cache is in
- * cairo_scaled_font_reference and cairo_scaled_font_destroy.
+ * cairo_scaled_font_reference() and cairo_scaled_font_destroy().
  */
 
 /* This defines the size of the holdover array ... that is, the number
  * of scaled fonts we keep around even when not otherwise referenced
  */
 #define CAIRO_SCALED_FONT_MAX_HOLDOVERS 256
 
 typedef struct _cairo_scaled_font_map {
@@ -448,17 +448,17 @@ static cairo_bool_t
 /* XXX: This 256 number is arbitary---we've never done any measurement
  * of this. In fact, having a per-font glyph caches each managed
  * separately is probably not what we want anyway. Would probably be
  * much better to have a single cache for glyphs with random
  * replacement across all glyphs of all fonts. */
 #define MAX_GLYPHS_CACHED_PER_FONT 256
 
 /*
- * Basic cairo_scaled_font_t object management
+ * Basic #cairo_scaled_font_t object management
  */
 
 cairo_status_t
 _cairo_scaled_font_init (cairo_scaled_font_t               *scaled_font,
 			 cairo_font_face_t		   *font_face,
 			 const cairo_matrix_t              *font_matrix,
 			 const cairo_matrix_t              *ctm,
 			 const cairo_font_options_t	   *options,
@@ -539,36 +539,41 @@ void
 _cairo_scaled_font_reset_cache (cairo_scaled_font_t *scaled_font)
 {
     _cairo_cache_destroy (scaled_font->glyphs);
     scaled_font->glyphs = _cairo_cache_create (_cairo_scaled_glyph_keys_equal,
 					       _cairo_scaled_glyph_destroy,
 					       MAX_GLYPHS_CACHED_PER_FONT);
 }
 
-void
+cairo_status_t
 _cairo_scaled_font_set_metrics (cairo_scaled_font_t	    *scaled_font,
 				cairo_font_extents_t	    *fs_metrics)
 {
+    cairo_status_t status;
     double  font_scale_x, font_scale_y;
 
-    _cairo_matrix_compute_scale_factors (&scaled_font->font_matrix,
-					 &font_scale_x, &font_scale_y,
-					 /* XXX */ 1);
+    status = _cairo_matrix_compute_scale_factors (&scaled_font->font_matrix,
+						  &font_scale_x, &font_scale_y,
+						  /* XXX */ 1);
+    if (status)
+	return status;
 
     /*
      * The font responded in unscaled units, scale by the font
      * matrix scale factors to get to user space
      */
 
     scaled_font->extents.ascent = fs_metrics->ascent * font_scale_y;
     scaled_font->extents.descent = fs_metrics->descent * font_scale_y;
     scaled_font->extents.height = fs_metrics->height * font_scale_y;
     scaled_font->extents.max_x_advance = fs_metrics->max_x_advance * font_scale_x;
     scaled_font->extents.max_y_advance = fs_metrics->max_y_advance * font_scale_y;
+
+    return CAIRO_STATUS_SUCCESS;
 }
 
 void
 _cairo_scaled_font_fini (cairo_scaled_font_t *scaled_font)
 {
     if (scaled_font->font_face != NULL)
 	cairo_font_face_destroy (scaled_font->font_face);
 
@@ -699,17 +704,17 @@ cairo_scaled_font_create (cairo_font_fac
     }
 
     return scaled_font;
 }
 slim_hidden_def (cairo_scaled_font_create);
 
 /**
  * cairo_scaled_font_reference:
- * @scaled_font: a #cairo_scaled_font_t, (may be NULL in which case
+ * @scaled_font: a #cairo_scaled_font_t, (may be %NULL in which case
  * this function does nothing)
  *
  * Increases the reference count on @scaled_font by one. This prevents
  * @scaled_font from being destroyed until a matching call to
  * cairo_scaled_font_destroy() is made.
  *
  * The number of references to a #cairo_scaled_font_t can be get using
  * cairo_scaled_font_get_reference_count().
@@ -1265,17 +1270,18 @@ cairo_status_t
 		status = mask->status;
 		goto CLEANUP_MASK;
 	    }
 	}
 
 	/* If we have glyphs of different formats, we "upgrade" the mask
 	 * to the wider of the formats. */
 	if (glyph_surface->format != mask_format &&
-	    _cairo_format_width (mask_format) < _cairo_format_width (glyph_surface->format) )
+	    _cairo_format_bits_per_pixel (mask_format) <
+	    _cairo_format_bits_per_pixel (glyph_surface->format) )
 	{
 	    cairo_surface_t *new_mask;
 	    cairo_surface_pattern_t mask_pattern;
 
 	    switch (glyph_surface->format) {
 	    case CAIRO_FORMAT_ARGB32:
 	    case CAIRO_FORMAT_A8:
 	    case CAIRO_FORMAT_A1:
@@ -1449,17 +1455,17 @@ static cairo_status_t
     if (status)
 	return status;
 
     return CAIRO_STATUS_SUCCESS;
 }
 
 /**
  * _trace_mask_to_path:
- * @bitmap: An alpha mask (either CAIRO_FORMAT_A1 or _A8)
+ * @bitmap: An alpha mask (either %CAIRO_FORMAT_A1 or %CAIRO_FORMAT_A8)
  * @path: An initialized path to hold the result
  *
  * Given a mask surface, (an alpha image), fill out the provided path
  * so that when filled it would result in something that approximates
  * the mask.
  *
  * Note: The current tracing code here is extremely primitive. It
  * operates only on an A1 surface, (converting an A8 surface to A1 if
@@ -1696,29 +1702,29 @@ void
  * _cairo_scaled_glyph_lookup:
  * @scaled_font: a #cairo_scaled_font_t
  * @index: the glyph to create
  * @info: a #cairo_scaled_glyph_info_t marking which portions of
  * the glyph should be filled in.
  * @scaled_glyph_ret: a #cairo_scaled_glyph_t * where the glyph
  * is returned.
  *
- * Returns a glyph with the requested portions filled in. Glyph
+ * Returns: a glyph with the requested portions filled in. Glyph
  * lookup is cached and glyph will be automatically freed along
  * with the scaled_font so no explicit free is required.
  * @info can be one or more of:
  *  %CAIRO_SCALED_GLYPH_INFO_METRICS - glyph metrics and bounding box
  *  %CAIRO_SCALED_GLYPH_INFO_SURFACE - surface holding glyph image
  *  %CAIRO_SCALED_GLYPH_INFO_PATH - path holding glyph outline in device space
  *
  * If the desired info is not available, (for example, when trying to
  * get INFO_PATH with a bitmapped font), this function will return
  * CAIRO_INT_STATUS_UNSUPPORTED.
  *
- * NOTE: This function must be called with scaled_font->mutex held.
+ * Note: This function must be called with scaled_font->mutex held.
  **/
 cairo_int_status_t
 _cairo_scaled_glyph_lookup (cairo_scaled_font_t *scaled_font,
 			    unsigned long index,
 			    cairo_scaled_glyph_info_t info,
 			    cairo_scaled_glyph_t **scaled_glyph_ret)
 {
     cairo_status_t		status = CAIRO_STATUS_SUCCESS;
--- a/gfx/cairo/cairo/src/cairo-slope.c
+++ b/gfx/cairo/cairo/src/cairo-slope.c
@@ -83,17 +83,17 @@ int
 
 /* XXX: It might be cleaner to move away from usage of
    _cairo_slope_clockwise/_cairo_slope_counter_clockwise in favor of
    directly using _cairo_slope_compare.
 */
 
 /* Is a clockwise of b?
  *
- * NOTE: The strict equality here is not significant in and of itself,
+ * Note: The strict equality here is not significant in and of itself,
  * but there are functions up above that are sensitive to it,
  * (cf. _cairo_pen_find_active_cw_vertex_index).
  */
 int
 _cairo_slope_clockwise (cairo_slope_t *a, cairo_slope_t *b)
 {
     return _cairo_slope_compare (a, b) < 0;
 }
--- a/gfx/cairo/cairo/src/cairo-stroke-style.c
+++ b/gfx/cairo/cairo/src/cairo-stroke-style.c
@@ -79,8 +79,25 @@ void
 _cairo_stroke_style_fini (cairo_stroke_style_t *style)
 {
     if (style->dash) {
 	free (style->dash);
 	style->dash = NULL;
     }
     style->num_dashes = 0;
 }
+
+/*
+ * For a stroke in the given style, compute the maximum distance
+ * from the path that vertices could be generated.  In the case
+ * of rotation in the ctm, the distance will not be exact.
+ */
+void
+_cairo_stroke_style_max_distance_from_path (const cairo_stroke_style_t *style,
+                                            const cairo_matrix_t *ctm,
+                                            double *dx, double *dy)
+{
+    double style_expansion = MAX(style->line_cap == CAIRO_LINE_CAP_SQUARE ? M_SQRT1_2 : 0.5,
+                                 style->line_join == CAIRO_LINE_JOIN_MITER ? style->miter_limit : 0.5);
+
+    *dx = style->line_width * style_expansion * (fabs(ctm->xx) + fabs(ctm->xy));
+    *dy = style->line_width * style_expansion * (fabs(ctm->yy) + fabs(ctm->yx));
+}
--- a/gfx/cairo/cairo/src/cairo-surface-fallback.c
+++ b/gfx/cairo/cairo/src/cairo-surface-fallback.c
@@ -50,18 +50,18 @@ typedef struct {
 } fallback_state_t;
 
 /**
  * _fallback_init:
  *
  * Acquire destination image surface needed for an image-based
  * fallback.
  *
- * Return value: CAIRO_INT_STATUS_NOTHING_TO_DO if the extents are not
- * visible, CAIRO_STATUS_SUCCESS if some portion is visible and all
+ * Return value: %CAIRO_INT_STATUS_NOTHING_TO_DO if the extents are not
+ * visible, %CAIRO_STATUS_SUCCESS if some portion is visible and all
  * went well, or some error status otherwise.
  **/
 static cairo_int_status_t
 _fallback_init (fallback_state_t *state,
 		cairo_surface_t  *dst,
 		int               x,
 		int               y,
 		int               width,
@@ -268,17 +268,17 @@ static cairo_status_t
     _cairo_pattern_fini (&intermediate_pattern.base);
 
  CLEANUP_SURFACE:
     cairo_surface_destroy (intermediate);
 
     return status;
 }
 
-/* Handles compositing for CAIRO_OPERATOR_SOURCE, which is special; it's
+/* Handles compositing for %CAIRO_OPERATOR_SOURCE, which is special; it's
  * defined as (src IN mask IN clip) ADD (dst OUT (mask IN clip))
  */
 static cairo_status_t
 _clip_and_composite_source (cairo_clip_t                  *clip,
 			    cairo_pattern_t               *src,
 			    cairo_draw_func_t              draw_func,
 			    void                          *draw_closure,
 			    cairo_surface_t               *dst,
--- a/gfx/cairo/cairo/src/cairo-surface.c
+++ b/gfx/cairo/cairo/src/cairo-surface.c
@@ -81,16 +81,17 @@ const cairo_surface_t name = {					\
 static DEFINE_NIL_SURFACE(CAIRO_STATUS_NO_MEMORY, _cairo_surface_nil);
 static DEFINE_NIL_SURFACE(CAIRO_STATUS_INVALID_CONTENT, _cairo_surface_nil_invalid_content);
 static DEFINE_NIL_SURFACE(CAIRO_STATUS_INVALID_FORMAT, _cairo_surface_nil_invalid_format);
 static DEFINE_NIL_SURFACE(CAIRO_STATUS_INVALID_VISUAL, _cairo_surface_nil_invalid_visual);
 static DEFINE_NIL_SURFACE(CAIRO_STATUS_FILE_NOT_FOUND, _cairo_surface_nil_file_not_found);
 static DEFINE_NIL_SURFACE(CAIRO_STATUS_TEMP_FILE_ERROR, _cairo_surface_nil_temp_file_error);
 static DEFINE_NIL_SURFACE(CAIRO_STATUS_READ_ERROR, _cairo_surface_nil_read_error);
 static DEFINE_NIL_SURFACE(CAIRO_STATUS_WRITE_ERROR, _cairo_surface_nil_write_error);
+static DEFINE_NIL_SURFACE(CAIRO_STATUS_INVALID_STRIDE, _cairo_surface_nil_invalid_stride);
 
 static cairo_status_t
 _cairo_surface_copy_pattern_for_destination (const cairo_pattern_t *pattern,
 					     cairo_surface_t *destination,
 					     cairo_pattern_t **pattern_out);
 
 /**
  * _cairo_surface_set_error:
@@ -274,17 +275,17 @@ cairo_surface_t *
  * surface will also use the same backend as @other, unless that is
  * not possible for some reason. The type of the returned surface may
  * be examined with cairo_surface_get_type().
  *
  * Initially the surface contents are all 0 (transparent if contents
  * have transparency, black otherwise.)
  *
  * Return value: a pointer to the newly allocated surface. The caller
- * owns the surface and should call cairo_surface_destroy when done
+ * owns the surface and should call cairo_surface_destroy() when done
  * with it.
  *
  * This function always returns a valid pointer, but it will return a
  * pointer to a "nil" surface if @other is already in an error state
  * or any other error occurs.
  **/
 cairo_surface_t *
 cairo_surface_create_similar (cairo_surface_t  *other,
@@ -876,17 +877,17 @@ slim_hidden_def (cairo_surface_get_devic
  * Some examples of natively vector-oriented backends are the ps, pdf,
  * and svg backends.
  *
  * For backends that are natively raster-oriented, image fallbacks are
  * still possible, but they are always performed at the native
  * device resolution. So this function has no effect on those
  * backends.
  *
- * NOTE: The fallback resolution only takes effect at the time of
+ * Note: The fallback resolution only takes effect at the time of
  * completing a page (with cairo_show_page() or cairo_copy_page()) so
  * there is currently no way to have more than one fallback resolution
  * in effect on a single page.
  *
  * Since: 1.2
  **/
 void
 cairo_surface_set_fallback_resolution (cairo_surface_t	*surface,
@@ -966,17 +967,17 @@ void
 	surface->backend->release_source_image (surface, image, image_extra);
 }
 
 /**
  * _cairo_surface_acquire_dest_image:
  * @surface: a #cairo_surface_t
  * @interest_rect: area of @surface for which fallback drawing is being done.
  *    A value of %NULL indicates that the entire surface is desired.
- *    XXXX I'd like to get rid of being able to pass NULL here (nothing seems to)
+ *    XXXX I'd like to get rid of being able to pass %NULL here (nothing seems to)
  * @image_out: location to store a pointer to an image surface that includes at least
  *    the intersection of @interest_rect with the visible area of @surface.
  *    This surface could be @surface itself, a surface held internal to @surface,
  *    or it could be a new surface with a copy of the relevant portion of @surface.
  *    If a new surface is created, it should have the same channels and depth
  *    as @surface so that copying to and from it is exact.
  * @image_rect: location to store area of the original surface occupied
  *    by the surface stored in @image.
@@ -987,17 +988,17 @@ void
  * drawing operation draws the primitive to the surface stored in @image_out
  * then calls _cairo_surface_release_dest_image(),
  * which, if a temporary surface was created, copies the bits back to the
  * main surface and frees the temporary surface.
  *
  * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY.
  *  %CAIRO_INT_STATUS_UNSUPPORTED can be returned but this will mean that
  *  the backend can't draw with fallbacks. It's possible for the routine
- *  to store NULL in @local_out and return %CAIRO_STATUS_SUCCESS;
+ *  to store %NULL in @local_out and return %CAIRO_STATUS_SUCCESS;
  *  that indicates that no part of @interest_rect is visible, so no drawing
  *  is necessary. _cairo_surface_release_dest_image() should not be called in that
  *  case.
  **/
 cairo_status_t
 _cairo_surface_acquire_dest_image (cairo_surface_t         *surface,
 				   cairo_rectangle_int_t   *interest_rect,
 				   cairo_image_surface_t  **image_out,
@@ -1125,17 +1126,17 @@ cairo_status_t
  * _cairo_surface_snapshot
  * @surface: a #cairo_surface_t
  *
  * Make an immutable copy of @surface. It is an error to call a
  * surface-modifying function on the result of this function.
  *
  * The caller owns the return value and should call
  * cairo_surface_destroy when finished with it. This function will not
- * return NULL, but will return a nil surface instead.
+ * return %NULL, but will return a nil surface instead.
  *
  * Return value: The snapshot surface. Note that the return surface
  * may not necessarily be of the same type as @surface.
  **/
 cairo_surface_t *
 _cairo_surface_snapshot (cairo_surface_t *surface)
 {
     if (surface->finished)
@@ -1153,19 +1154,19 @@ cairo_surface_t *
  * @surface_b: a #cairo_surface_t
  * @content: a #cairo_content_t
  *
  * Find out whether the given surfaces share the same backend,
  * and if so, whether they can be considered similar.
  *
  * The definition of "similar" depends on the backend. In
  * general, it means that the surface is equivalent to one
- * that would have been generated by a call to cairo_surface_create_similar.
+ * that would have been generated by a call to cairo_surface_create_similar().
  *
- * Return value: TRUE if the surfaces are similar.
+ * Return value: %TRUE if the surfaces are similar.
  **/
 cairo_bool_t
 _cairo_surface_is_similar (cairo_surface_t *surface_a,
 	                   cairo_surface_t *surface_b,
 			   cairo_content_t content)
 {
     if (surface_a->backend != surface_b->backend)
 	return FALSE;
@@ -1644,80 +1645,83 @@ cairo_status_t
 							  src_x, src_y,
 							  dst_x, dst_y,
 							  width, height,
 							  traps, num_traps));
 }
 
 /**
  * cairo_surface_copy_page:
- * @suface: a #cairo_surface_t
+ * @surface: a #cairo_surface_t
  *
  * Emits the current page for backends that support multiple pages,
  * but doesn't clear it, so that the contents of the current page will
  * be retained for the next page.  Use cairo_surface_show_page() if you
  * want to get an empty page after the emission.
  *
  * Since: 1.6
  */
-cairo_status_t
+void
 cairo_surface_copy_page (cairo_surface_t *surface)
 {
     assert (! surface->is_snapshot);
 
     if (surface->status)
-	return surface->status;
+	return;
 
-    if (surface->finished)
-	return _cairo_surface_set_error (surface,CAIRO_STATUS_SURFACE_FINISHED);
+    if (surface->finished) {
+	_cairo_surface_set_error (surface,CAIRO_STATUS_SURFACE_FINISHED);
+	return;
+    }
 
     /* It's fine if some backends don't implement copy_page */
     if (surface->backend->copy_page == NULL)
-	return CAIRO_STATUS_SUCCESS;
+	return;
 
-    return _cairo_surface_set_error (surface,
-	                             surface->backend->copy_page (surface));
+    _cairo_surface_set_error (surface,
+			      surface->backend->copy_page (surface));
 }
 slim_hidden_def (cairo_surface_copy_page);
 
 /**
  * cairo_surface_show_page:
  * @surface: a #cairo_Surface_t
  *
  * Emits and clears the current page for backends that support multiple
  * pages.  Use cairo_surface_copy_page() if you don't want to clear the page.
  *
  * Since: 1.6
  **/
-
-cairo_status_t
+void
 cairo_surface_show_page (cairo_surface_t *surface)
 {
     assert (! surface->is_snapshot);
 
     if (surface->status)
-	return surface->status;
+	return;
 
-    if (surface->finished)
-	return _cairo_surface_set_error (surface,CAIRO_STATUS_SURFACE_FINISHED);
+    if (surface->finished) {
+	_cairo_surface_set_error (surface,CAIRO_STATUS_SURFACE_FINISHED);
+	return;
+    }
 
     /* It's fine if some backends don't implement show_page */
     if (surface->backend->show_page == NULL)
-	return CAIRO_STATUS_SUCCESS;
+	return;
 
-    return _cairo_surface_set_error (surface,
-	                             surface->backend->show_page (surface));
+    _cairo_surface_set_error (surface,
+			      surface->backend->show_page (surface));
 }
 slim_hidden_def (cairo_surface_show_page);
 
 /**
  * _cairo_surface_get_current_clip_serial:
  * @surface: the #cairo_surface_t to return the serial number for
  *
- * Returns the serial number associated with the current
+ * Returns: the serial number associated with the current
  * clip in the surface.  All gstate functions must
  * verify that the correct clip is set in the surface before
  * invoking any surface drawing function
  */
 unsigned int
 _cairo_surface_get_current_clip_serial (cairo_surface_t *surface)
 {
     return surface->current_clip_serial;
@@ -1996,20 +2000,20 @@ cairo_status_t
  * possibly be recorded, in other words, it is the maximum extent of
  * potentially usable coordinates.
  *
  * For vector surfaces, (PDF, PS, SVG and meta-surfaces), the surface
  * might be conceived as unbounded, but we force the user to provide a
  * maximum size at the time of surface_create. So get_extents uses
  * that size.
  *
- * NOTE: The coordinates returned are in "backend" space rather than
+ * Note: The coordinates returned are in "backend" space rather than
  * "surface" space. That is, they are relative to the true (0,0)
  * origin rather than the device_transform origin. This might seem a
- * bit inconsistent with other cairo_surface interfaces, but all
+ * bit inconsistent with other #cairo_surface_t interfaces, but all
  * current callers are within the surface layer where backend space is
  * desired.
  *
  * This behavior would have to be changed is we ever exported a public
  * variant of this function.
  */
 cairo_status_t
 _cairo_surface_get_extents (cairo_surface_t         *surface,
@@ -2021,17 +2025,17 @@ cairo_status_t
     if (surface->finished)
 	return _cairo_surface_set_error (surface,CAIRO_STATUS_SURFACE_FINISHED);
 
     return _cairo_surface_set_error (surface,
 	    surface->backend->get_extents (surface, rectangle));
 }
 
 /* Note: the backends may modify the contents of the glyph array as long as
- * they do not return CAIRO_STATUS_UNSUPPORTED. This makes it possible to
+ * they do not return %CAIRO_STATUS_UNSUPPORTED. This makes it possible to
  * avoid copying the array again and again, and edit it in-place.
  * Backends are in fact free to use the array as a generic buffer as they
  * see fit.
  * See commits 5a9642c5746fd677aed35ce620ce90b1029b1a0c and
  * 1781e6018c17909311295a9cc74b70500c6b4d0a for the rationale.
  */
 cairo_status_t
 _cairo_surface_show_glyphs (cairo_surface_t	*surface,
@@ -2422,16 +2426,18 @@ cairo_surface_t *
     case CAIRO_STATUS_READ_ERROR:
 	return (cairo_surface_t *) &_cairo_surface_nil_read_error;
     case CAIRO_STATUS_WRITE_ERROR:
 	return (cairo_surface_t *) &_cairo_surface_nil_write_error;
     case CAIRO_STATUS_FILE_NOT_FOUND:
 	return (cairo_surface_t *) &_cairo_surface_nil_file_not_found;
     case CAIRO_STATUS_TEMP_FILE_ERROR:
 	return (cairo_surface_t *) &_cairo_surface_nil_temp_file_error;
+    case CAIRO_STATUS_INVALID_STRIDE:
+	return (cairo_surface_t *) &_cairo_surface_nil_invalid_stride;
     default:
 	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
 	return (cairo_surface_t *) &_cairo_surface_nil;
     }
 }
 
 /*  LocalWords:  rasterized
  */
--- a/gfx/cairo/cairo/src/cairo-svg-surface.c
+++ b/gfx/cairo/cairo/src/cairo-svg-surface.c
@@ -154,17 +154,17 @@ static const cairo_paginated_surface_bac
  * @closure: the closure argument for @write_func
  * @width_in_points: width of the surface, in points (1 point == 1/72.0 inch)
  * @height_in_points: height of the surface, in points (1 point == 1/72.0 inch)
  *
  * Creates a SVG surface of the specified size in points to be written
  * incrementally to the stream represented by @write_func and @closure.
  *
  * Return value: a pointer to the newly created surface. The caller
- * owns the surface and should call cairo_surface_destroy when done
+ * owns the surface and should call cairo_surface_destroy() when done
  * with it.
  *
  * This function always returns a valid pointer, but it will return a
  * pointer to a "nil" surface if an error such as out of memory
  * occurs. You can use cairo_surface_status() to check for this.
  *
  * Since: 1.2
  */
@@ -188,17 +188,17 @@ cairo_svg_surface_create_for_stream (cai
  * @filename: a filename for the SVG output (must be writable)
  * @width_in_points: width of the surface, in points (1 point == 1/72.0 inch)
  * @height_in_points: height of the surface, in points (1 point == 1/72.0 inch)
  *
  * Creates a SVG surface of the specified size in points to be written
  * to @filename.
  *
  * Return value: a pointer to the newly created surface. The caller
- * owns the surface and should call cairo_surface_destroy when done
+ * owns the surface and should call cairo_surface_destroy() when done
  * with it.
  *
  * This function always returns a valid pointer, but it will return a
  * pointer to a "nil" surface if an error such as out of memory
  * occurs. You can use cairo_surface_status() to check for this.
  *
  * Since: 1.2
  **/
@@ -219,17 +219,17 @@ cairo_svg_surface_create (const char	*fi
 static cairo_bool_t
 _cairo_surface_is_svg (cairo_surface_t *surface)
 {
     return surface->backend == &cairo_svg_surface_backend;
 }
 
 /* If the abstract_surface is a paginated surface, and that paginated
  * surface's target is a svg_surface, then set svg_surface to that
- * target. Otherwise return CAIRO_STATUS_SURFACE_TYPE_MISMATCH.
+ * target. Otherwise return %CAIRO_STATUS_SURFACE_TYPE_MISMATCH.
  */
 static cairo_status_t
 _extract_svg_surface (cairo_surface_t		 *surface,
 		      cairo_svg_surface_t	**svg_surface)
 {
     cairo_surface_t *target;
 
     if (! _cairo_surface_is_paginated (surface))
@@ -298,17 +298,17 @@ cairo_svg_get_versions (cairo_svg_versio
 	*num_versions = CAIRO_SVG_VERSION_LAST;
 }
 
 /**
  * cairo_svg_version_to_string:
  * @version: a version id
  *
  * Get the string representation of the given @version id. This function
- * will return NULL if @version isn't valid. See cairo_svg_get_versions()
+ * will return %NULL if @version isn't valid. See cairo_svg_get_versions()
  * for a way to get the list of valid version ids.
  *
  * Return value: the string associated to given version.
  *
  * Since: 1.2
  **/
 const char *
 cairo_svg_version_to_string (cairo_svg_version_t version)
@@ -1040,17 +1040,18 @@ static cairo_status_t
 
     status = _cairo_meta_surface_replay (&meta->base, paginated_surface);
     if (status) {
 	cairo_surface_destroy (&meta->base);
 	cairo_surface_destroy (paginated_surface);
 	return status;
     }
 
-    status = cairo_surface_show_page (paginated_surface);
+    cairo_surface_show_page (paginated_surface);
+    status = cairo_surface_status (paginated_surface);
     if (status) {
 	cairo_surface_destroy (&meta->base);
 	cairo_surface_destroy (paginated_surface);
 	return status;
     }
 
     new_snapshot.meta = meta;
     new_snapshot.id = svg_surface->id;
@@ -1128,17 +1129,17 @@ static cairo_status_t
 						cairo_surface_pattern_t	*pattern,
 						int			 pattern_id,
 						const char		*extra_attributes)
 {
     cairo_svg_document_t *document = surface->document;
     cairo_meta_surface_t *meta_surface;
     cairo_matrix_t p2u;
     cairo_status_t status;
-    int id;
+    int id = 0;
 
     p2u = pattern->base.matrix;
     status = cairo_matrix_invert (&p2u);
     /* cairo_pattern_set_matrix ensures the matrix is invertible */
     assert (status == CAIRO_STATUS_SUCCESS);
 
     meta_surface = (cairo_meta_surface_t *) pattern->surface;
 
--- a/gfx/cairo/cairo/src/cairo-svg.h
+++ b/gfx/cairo/cairo/src/cairo-svg.h
@@ -34,17 +34,17 @@
 
 #include <cairo.h>
 
 #if CAIRO_HAS_SVG_SURFACE
 
 CAIRO_BEGIN_DECLS
 
 /**
- * cairo_svg_version_t
+ * cairo_svg_version_t:
  * @CAIRO_SVG_VERSION_1_1: The version 1.1 of the SVG specification.
  * @CAIRO_SVG_VERSION_1_2: The version 1.2 of the SVG specification.
  *
  * #cairo_svg_version_t is used to describe the version number of the SVG
  * specification that a generated SVG file will conform to.
  */
 typedef enum _cairo_svg_version {
     CAIRO_SVG_VERSION_1_1,
--- a/gfx/cairo/cairo/src/cairo-traps.c
+++ b/gfx/cairo/cairo/src/cairo-traps.c
@@ -29,17 +29,17 @@
  * The Original Code is the cairo graphics library.
  *
  * The Initial Developer of the Original Code is Keith Packard
  *
  * Contributor(s):
  *	Keith R. Packard <keithp@keithp.com>
  *	Carl D. Worth <cworth@cworth.org>
  *
- * 2002-07-15: Converted from XRenderCompositeDoublePoly to cairo_trap. Carl D. Worth
+ * 2002-07-15: Converted from XRenderCompositeDoublePoly to #cairo_trap_t. Carl D. Worth
  */
 
 #include "cairoint.h"
 
 /* private functions */
 
 static cairo_status_t
 _cairo_traps_grow (cairo_traps_t *traps);
@@ -70,16 +70,24 @@ void
 _cairo_traps_limit (cairo_traps_t	*traps,
 		    cairo_box_t		*limits)
 {
     traps->has_limits = TRUE;
 
     traps->limits = *limits;
 }
 
+cairo_bool_t
+_cairo_traps_get_limit (cairo_traps_t *traps,
+			cairo_box_t   *limits)
+{
+    *limits = traps->limits;
+    return traps->has_limits;
+}
+
 void
 _cairo_traps_fini (cairo_traps_t *traps)
 {
     if (traps->traps && traps->traps != traps->traps_embedded)
 	free (traps->traps);
 
     traps->traps = NULL;
     traps->traps_size = 0;
@@ -87,17 +95,17 @@ void
 }
 
 /**
  * _cairo_traps_init_box:
  * @traps: a #cairo_traps_t
  * @box: a box that will be converted to a single trapezoid
  *       to store in @traps.
  *
- * Initializes a cairo_traps_t to contain a single rectangular
+ * Initializes a #cairo_traps_t to contain a single rectangular
  * trapezoid.
  **/
 cairo_status_t
 _cairo_traps_init_box (cairo_traps_t *traps,
 		       cairo_box_t   *box)
 {
     _cairo_traps_init (traps);
 
--- a/gfx/cairo/cairo/src/cairo-types-private.h
+++ b/gfx/cairo/cairo/src/cairo-types-private.h
@@ -56,42 +56,42 @@ typedef struct _cairo_scaled_font_backen
 typedef struct _cairo_font_face_backend     cairo_font_face_backend_t;
 typedef struct _cairo_xlib_screen_info cairo_xlib_screen_info_t;
 typedef cairo_array_t cairo_user_data_array_t;
 
 /**
  * cairo_hash_entry_t:
  *
  * A #cairo_hash_entry_t contains both a key and a value for
- * cairo_hash_table_t. User-derived types for cairo_hash_entry_t must
+ * #cairo_hash_table_t. User-derived types for #cairo_hash_entry_t must
  * be type-compatible with this structure (eg. they must have an
  * unsigned long as the first parameter. The easiest way to get this
  * is to use:
  *
  * 	typedef _my_entry {
  *	    cairo_hash_entry_t base;
  *	    ... Remainder of key and value fields here ..
  *	} my_entry_t;
  *
  * which then allows a pointer to my_entry_t to be passed to any of
- * the cairo_hash_table functions as follows without requiring a cast:
+ * the #cairo_hash_table_t functions as follows without requiring a cast:
  *
  *	_cairo_hash_table_insert (hash_table, &my_entry->base);
  *
  * IMPORTANT: The caller is reponsible for initializing
  * my_entry->base.hash with a hash code derived from the key. The
  * essential property of the hash code is that keys_equal must never
- * return TRUE for two keys that have different hashes. The best hash
+ * return %TRUE for two keys that have different hashes. The best hash
  * code will reduce the frequency of two keys with the same code for
- * which keys_equal returns FALSE.
+ * which keys_equal returns %FALSE.
  *
  * Which parts of the entry make up the "key" and which part make up
  * the value are entirely up to the caller, (as determined by the
  * computation going into base.hash as well as the keys_equal
- * function). A few of the cairo_hash_table functions accept an entry
+ * function). A few of the #cairo_hash_table_t functions accept an entry
  * which will be used exclusively as a "key", (indicated by a
  * parameter name of key). In these cases, the value-related fields of
  * the entry need not be initialized if so desired.
  **/
 struct _cairo_hash_entry {
     unsigned long hash;
 };
 
--- a/gfx/cairo/cairo/src/cairo-unicode.c
+++ b/gfx/cairo/cairo/src/cairo-unicode.c
@@ -25,18 +25,17 @@
  * Version 1.1 (the "License"); you may not use this file except in
  * compliance with the License. You may obtain a copy of the License at
  * http://www.mozilla.org/MPL/
  *
  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
  * OF ANY KIND, either express or implied. See the LGPL or the MPL for
  * the specific language governing rights and limitations.
  *
- * The Original Code is cairo_unicode.c as distributed with the
- *   cairo graphics library.
+ * The Original Code is the cairo graphics library.
  *
  * The Initial Developer of the Original Code is Tom Tromey.
  *  and Red Hat, Inc.
  *
  * Contributor(s):
  *	Owen Taylor <otaylor@redhat.com>
  */
 
--- a/gfx/cairo/cairo/src/cairo-win32-font.c
+++ b/gfx/cairo/cairo/src/cairo-win32-font.c
@@ -125,17 +125,17 @@ static cairo_status_t
                                              cairo_scaled_glyph_t      *scaled_glyph);
 
 static cairo_status_t
 _cairo_win32_scaled_font_init_glyph_path (cairo_win32_scaled_font_t *scaled_font,
 					  cairo_scaled_glyph_t      *scaled_glyph);
 
 #define NEARLY_ZERO(d) (fabs(d) < (1. / 65536.))
 
-static void
+static cairo_status_t
 _compute_transform (cairo_win32_scaled_font_t *scaled_font,
 		    cairo_matrix_t            *sc)
 {
     cairo_status_t status;
 
     if (NEARLY_ZERO (sc->yx) && NEARLY_ZERO (sc->xy)) {
 	scaled_font->preserve_axes = TRUE;
 	scaled_font->x_scale = sc->xx;
@@ -170,33 +170,37 @@ static void
 
     /* The font matrix has x and y "scale" components which we extract and
      * use as character scale values.
      */
     cairo_matrix_init (&scaled_font->logical_to_device,
 		       sc->xx, sc->yx, sc->xy, sc->yy, 0, 0);
 
     if (!scaled_font->preserve_axes) {
-	_cairo_matrix_compute_scale_factors (&scaled_font->logical_to_device,
-					     &scaled_font->x_scale, &scaled_font->y_scale,
-					     TRUE);	/* XXX: Handle vertical text */
+	status = _cairo_matrix_compute_scale_factors (&scaled_font->logical_to_device,
+						      &scaled_font->x_scale, &scaled_font->y_scale,
+						      TRUE);	/* XXX: Handle vertical text */
+	if (status)
+	    return status;
 
 	scaled_font->logical_size = _cairo_lround (WIN32_FONT_LOGICAL_SCALE *
                                                    scaled_font->y_scale);
 	scaled_font->logical_scale = WIN32_FONT_LOGICAL_SCALE * scaled_font->y_scale;
     }
 
     cairo_matrix_scale (&scaled_font->logical_to_device,
 			1.0 / scaled_font->logical_scale, 1.0 / scaled_font->logical_scale);
 
     scaled_font->device_to_logical = scaled_font->logical_to_device;
 
     status = cairo_matrix_invert (&scaled_font->device_to_logical);
     if (status)
 	cairo_matrix_init_identity (&scaled_font->device_to_logical);
+
+    return CAIRO_STATUS_SUCCESS;
 }
 
 static cairo_bool_t
 _have_cleartype_quality (void)
 {
     OSVERSIONINFO version_info;
 
     version_info.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
@@ -235,17 +239,17 @@ static BYTE
 	}
 
 	return ANTIALIASED_QUALITY;
     } else {
 	return DEFAULT_QUALITY;
     }
 }
 
-/* If face_hfont is non-NULL then font_matrix must be a simple scale by some
+/* If face_hfont is non-%NULL then font_matrix must be a simple scale by some
  * factor S, ctm must be the identity, logfont->lfHeight must be -S,
  * logfont->lfWidth, logfont->lfEscapement, logfont->lfOrientation must
  * all be 0, and face_hfont is the result of calling CreateFontIndirectW on
  * logfont.
  */
 static cairo_status_t
 _win32_scaled_font_create (LOGFONTW                   *logfont,
 			   HFONT                      face_hfont,
@@ -307,17 +311,19 @@ static cairo_status_t
          * _win32_scaled_font_get_scaled_hfont would create it.
          */
         f->scaled_hfont = face_hfont;
     }
     /* don't delete the hfont if we're using the one passed in to us */
     f->delete_scaled_hfont = !f->scaled_hfont;
 
     cairo_matrix_multiply (&scale, font_matrix, ctm);
-    _compute_transform (f, &scale);
+    status = _compute_transform (f, &scale);
+    if (status)
+	goto FAIL;
 
     status = _cairo_scaled_font_init (&f->base, font_face,
 				      font_matrix, ctm, options,
 				      &cairo_win32_scaled_font_backend);
     if (status)
 	goto FAIL;
 
     status = _cairo_win32_scaled_font_set_metrics (f);
@@ -867,19 +873,17 @@ static cairo_status_t
     {
 	 if ((GetFontData (hdc, CMAP_TAG, 0, NULL, 0) == GDI_ERROR) &&
 	     (GetFontData (hdc, 0, 0, NULL, 0) != GDI_ERROR))
 	 {
 	      scaled_font->is_type1 = TRUE;
 	 }
     }
 
-    _cairo_scaled_font_set_metrics (&scaled_font->base, &extents);
-
-    return CAIRO_STATUS_SUCCESS;
+    return _cairo_scaled_font_set_metrics (&scaled_font->base, &extents);
 }
 
 static cairo_status_t
 _cairo_win32_scaled_font_init_glyph_metrics (cairo_win32_scaled_font_t *scaled_font,
 					     cairo_scaled_glyph_t      *scaled_glyph)
 {
     static const MAT2 matrix = { { 0, 1 }, { 0, 0 }, { 0, 0 }, { 0, 1 } };
     GLYPHMETRICS metrics;
@@ -1758,21 +1762,21 @@ const cairo_scaled_font_backend_t cairo_
     _cairo_win32_scaled_font_glyph_init,
     _cairo_win32_scaled_font_text_to_glyphs,
     NULL,			/* ucs4_to_index */
     _cairo_win32_scaled_font_show_glyphs,
     _cairo_win32_scaled_font_load_truetype_table,
     _cairo_win32_scaled_font_map_glyphs_to_unicode,
 };
 
-/* cairo_win32_font_face_t */
+/* #cairo_win32_font_face_t */
 
 typedef struct _cairo_win32_font_face cairo_win32_font_face_t;
 
-/* If hfont is non-NULL then logfont->lfHeight must be -S for some S,
+/* If hfont is non-%NULL then logfont->lfHeight must be -S for some S,
  * logfont->lfWidth, logfont->lfEscapement, logfont->lfOrientation must
  * all be 0, and hfont is the result of calling CreateFontIndirectW on
  * logfont.
  */
 struct _cairo_win32_font_face {
     cairo_font_face_t base;
     LOGFONTW logfont;
     HFONT hfont;
--- a/gfx/cairo/cairo/src/cairo-win32-surface.c
+++ b/gfx/cairo/cairo/src/cairo-win32-surface.c
@@ -200,17 +200,17 @@ static cairo_status_t
     bitmap_info->bmiHeader.biYPelsPerMeter = PELS_72DPI; /* unused here */
     bitmap_info->bmiHeader.biPlanes = 1;
 
     switch (format) {
     /* We can't create real RGB24 bitmaps because something seems to
      * break if we do, especially if we don't set up an image
      * fallback.  It could be a bug with using a 24bpp pixman image
      * (and creating one with masks).  So treat them like 32bpp.
-     * NOTE: This causes problems when using BitBlt/AlphaBlend/etc!
+     * Note: This causes problems when using BitBlt/AlphaBlend/etc!
      * see end of file.
      */
     case CAIRO_FORMAT_RGB24:
     case CAIRO_FORMAT_ARGB32:
 	bitmap_info->bmiHeader.biBitCount = 32;
 	bitmap_info->bmiHeader.biCompression = BI_RGB;
 	bitmap_info->bmiHeader.biClrUsed = 0;	/* unused */
 	bitmap_info->bmiHeader.biClrImportant = 0;
@@ -1256,17 +1256,17 @@ UNSUPPORTED:
     }
 
     return CAIRO_INT_STATUS_UNSUPPORTED;
 }
 
 /* This big function tells us how to optimize operators for the
  * case of solid destination and constant-alpha source
  *
- * NOTE: This function needs revisiting if we add support for
+ * Note: This function needs revisiting if we add support for
  *       super-luminescent colors (a == 0, r,g,b > 0)
  */
 static enum { DO_CLEAR, DO_SOURCE, DO_NOTHING, DO_UNSUPPORTED }
 categorize_solid_dest_operator (cairo_operator_t op,
 				unsigned short   alpha)
 {
     enum { SOURCE_TRANSPARENT, SOURCE_LIGHT, SOURCE_SOLID, SOURCE_OTHER } source;
 
@@ -1839,20 +1839,20 @@ int
 {
     return surface->backend == &cairo_win32_surface_backend;
 }
 
 /**
  * cairo_win32_surface_get_dc
  * @surface: a #cairo_surface_t
  *
- * Returns the HDC associated with this surface, or NULL if none.
- * Also returns NULL if the surface is not a win32 surface.
+ * Returns the HDC associated with this surface, or %NULL if none.
+ * Also returns %NULL if the surface is not a win32 surface.
  *
- * Return value: HDC or NULL if no HDC available.
+ * Return value: HDC or %NULL if no HDC available.
  *
  * Since: 1.2
  **/
 HDC
 cairo_win32_surface_get_dc (cairo_surface_t *surface)
 {
     cairo_win32_surface_t *winsurf;
 
@@ -1866,20 +1866,20 @@ cairo_win32_surface_get_dc (cairo_surfac
 }
 
 /**
  * cairo_win32_surface_get_image
  * @surface: a #cairo_surface_t
  *
  * Returns a #cairo_surface_t image surface that refers to the same bits
  * as the DIB of the Win32 surface.  If the passed-in win32 surface
- * is not a DIB surface, NULL is returned.
+ * is not a DIB surface, %NULL is returned.
  *
- * Return value: a #cairo_surface_t (owned by the win32 cairo_surface_t),
- * or NULL if the win32 surface is not a DIB.
+ * Return value: a #cairo_surface_t (owned by the win32 #cairo_surface_t),
+ * or %NULL if the win32 surface is not a DIB.
  *
  * Since: 1.4
  */
 cairo_surface_t *
 cairo_win32_surface_get_image (cairo_surface_t *surface)
 {
     if (!_cairo_surface_is_win32(surface))
 	return NULL;
@@ -2031,17 +2031,16 @@ cairo_int_status_t
     surface->clip_rect.height = rect.bottom - rect.top;
 
     surface->initial_clip_rgn = NULL;
     surface->had_simple_clip = FALSE;
 
     if (clipBoxType == COMPLEXREGION) {
 	surface->initial_clip_rgn = CreateRectRgn (0, 0, 0, 0);
 	if (GetClipRgn (hdc, surface->initial_clip_rgn) <= 0) {
-	    /* this should never happen */
 	    DeleteObject(surface->initial_clip_rgn);
 	    surface->initial_clip_rgn = NULL;
 	}
     } else if (clipBoxType == SIMPLEREGION) {
 	surface->had_simple_clip = TRUE;
     }
 
     if (gm == GM_ADVANCED)
--- a/gfx/cairo/cairo/src/cairo-xcb-surface.c
+++ b/gfx/cairo/cairo/src/cairo-xcb-surface.c
@@ -1849,17 +1849,17 @@ static xcb_screen_t *
  *          Currently, only TrueColor visuals are fully supported.
  * @width: the current width of @drawable.
  * @height: the current height of @drawable.
  *
  * Creates an XCB surface that draws to the given drawable.
  * The way that colors are represented in the drawable is specified
  * by the provided visual.
  *
- * NOTE: If @drawable is a window, then the function
+ * Note: If @drawable is a window, then the function
  * cairo_xcb_surface_set_size must be called whenever the size of the
  * window changes.
  *
  * Return value: the newly created surface
  **/
 cairo_surface_t *
 cairo_xcb_surface_create (xcb_connection_t *c,
 			  xcb_drawable_t	 drawable,
@@ -1881,17 +1881,17 @@ cairo_xcb_surface_create (xcb_connection
  * cairo_xcb_surface_create_for_bitmap:
  * @c: an XCB connection
  * @bitmap: an XCB Pixmap (a depth-1 pixmap)
  * @screen: an XCB Screen
  * @width: the current width of @bitmap
  * @height: the current height of @bitmap
  *
  * Creates an XCB surface that draws to the given bitmap.
- * This will be drawn to as a CAIRO_FORMAT_A1 object.
+ * This will be drawn to as a %CAIRO_FORMAT_A1 object.
  *
  * Return value: the newly created surface
  **/
 cairo_surface_t *
 cairo_xcb_surface_create_for_bitmap (xcb_connection_t     *c,
 				     xcb_pixmap_t		bitmap,
 				     xcb_screen_t	       *screen,
 				     int		width,
@@ -1911,17 +1911,17 @@ cairo_xcb_surface_create_for_bitmap (xcb
  *          depth of @format mush match the depth of the drawable.
  * @width: the current width of @drawable
  * @height: the current height of @drawable
  *
  * Creates an XCB surface that draws to the given drawable.
  * The way that colors are represented in the drawable is specified
  * by the provided picture format.
  *
- * NOTE: If @drawable is a Window, then the function
+ * Note: If @drawable is a Window, then the function
  * cairo_xcb_surface_set_size must be called whenever the size of the
  * window changes.
  *
  * Return value: the newly created surface.
  **/
 cairo_surface_t *
 cairo_xcb_surface_create_with_xrender_format (xcb_connection_t	    *c,
 					      xcb_drawable_t	     drawable,
--- a/gfx/cairo/cairo/src/cairo-xlib-surface.c
+++ b/gfx/cairo/cairo/src/cairo-xlib-surface.c
@@ -163,17 +163,17 @@ static cairo_surface_t *
      * the most elementary RENDER operation, then we're better off
      * using image surfaces for all temporary operations, so return NULL
      * and let the fallback code happen.
      */
     if (!CAIRO_SURFACE_RENDER_HAS_COMPOSITE(src)) {
 	return NULL;
     }
 
-    pix = XCreatePixmap (dpy, RootWindowOfScreen (src->screen),
+    pix = XCreatePixmap (dpy, src->drawable,
 			 width <= 0 ? 1 : width, height <= 0 ? 1 : height,
 			 depth);
 
     surface = (cairo_xlib_surface_t *)
 	cairo_xlib_surface_create_with_xrender_format (dpy, pix, src->screen,
 						       xrender_format,
 						       width, height);
     if (surface->base.status) {
@@ -241,17 +241,17 @@ static cairo_surface_t *
 	return _cairo_xlib_surface_create_similar_with_format (abstract_src,
 							       _cairo_format_from_content (content),
 							       width, height);
     }
 
     /* We've got a compatible XRenderFormat now, which means the
      * similar surface will match the existing surface as closely in
      * visual/depth etc. as possible. */
-    pix = XCreatePixmap (src->dpy, RootWindowOfScreen (src->screen),
+    pix = XCreatePixmap (src->dpy, src->drawable,
 			 width <= 0 ? 1 : width, height <= 0 ? 1 : height,
 			 xrender_format->depth);
 
     surface = (cairo_xlib_surface_t *)
 	cairo_xlib_surface_create_with_xrender_format (src->dpy, pix,
 						       src->screen,
 						       xrender_format,
 						       width, height);
@@ -2065,17 +2065,17 @@ static Screen *
  *          Currently, only TrueColor visuals are fully supported.
  * @width: the current width of @drawable.
  * @height: the current height of @drawable.
  *
  * Creates an Xlib surface that draws to the given drawable.
  * The way that colors are represented in the drawable is specified
  * by the provided visual.
  *
- * NOTE: If @drawable is a Window, then the function
+ * Note: If @drawable is a Window, then the function
  * cairo_xlib_surface_set_size must be called whenever the size of the
  * window changes.
  *
  * When @drawable is a Window containing child windows then drawing to
  * the created surface will be clipped by those child windows.  When
  * the created surface is used as a source, the contents of the
  * children will be included.
  *
@@ -2103,17 +2103,17 @@ cairo_xlib_surface_create (Display     *
  * cairo_xlib_surface_create_for_bitmap:
  * @dpy: an X Display
  * @bitmap: an X Drawable, (a depth-1 Pixmap)
  * @screen: the X Screen associated with @bitmap
  * @width: the current width of @bitmap.
  * @height: the current height of @bitmap.
  *
  * Creates an Xlib surface that draws to the given bitmap.
- * This will be drawn to as a CAIRO_FORMAT_A1 object.
+ * This will be drawn to as a %CAIRO_FORMAT_A1 object.
  *
  * Return value: the newly created surface
  **/
 cairo_surface_t *
 cairo_xlib_surface_create_for_bitmap (Display  *dpy,
 				      Pixmap	bitmap,
 				      Screen   *screen,
 				      int	width,
@@ -2135,17 +2135,17 @@ cairo_xlib_surface_create_for_bitmap (Di
  *          of @format must match the depth of the drawable.
  * @width: the current width of @drawable.
  * @height: the current height of @drawable.
  *
  * Creates an Xlib surface that draws to the given drawable.
  * The way that colors are represented in the drawable is specified
  * by the provided picture format.
  *
- * NOTE: If @drawable is a Window, then the function
+ * Note: If @drawable is a Window, then the function
  * cairo_xlib_surface_set_size must be called whenever the size of the
  * window changes.
  *
  * Return value: the newly created surface
  **/
 cairo_surface_t *
 cairo_xlib_surface_create_with_xrender_format (Display		    *dpy,
 					       Drawable		    drawable,
@@ -2155,16 +2155,45 @@ cairo_xlib_surface_create_with_xrender_f
 					       int		    height)
 {
     CAIRO_MUTEX_INITIALIZE ();
 
     return _cairo_xlib_surface_create_internal (dpy, drawable, screen,
 						NULL, format, width, height, 0);
 }
 slim_hidden_def (cairo_xlib_surface_create_with_xrender_format);
+
+/**
+ * cairo_xlib_surface_get_xrender_format:
+ * @surface: an xlib surface
+ *
+ * Gets the X Render picture format that @surface uses for rendering with the
+ * X Render extension. If the surface was created by
+ * cairo_xlib_surface_create_with_xrender_format() originally, the return
+ * value is the format passed to that constructor.
+ *
+ * Return value: the XRenderPictFormat* associated with @surface,
+ * or %NULL if the surface is not an xlib surface
+ * or if the X Render extension is not available.
+ *
+ * Since: 1.6
+ **/
+XRenderPictFormat *
+cairo_xlib_surface_get_xrender_format (cairo_surface_t *surface)
+{
+    cairo_xlib_surface_t *xlib_surface = (cairo_xlib_surface_t *) surface;
+
+    /* Throw an error for a non-xlib surface */
+    if (! _cairo_surface_is_xlib (surface)) {
+	_cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
+	return NULL;
+    }
+
+    return xlib_surface->xrender_format;
+}
 #endif
 
 /**
  * cairo_xlib_surface_set_size:
  * @surface: a #cairo_surface_t for the XLib backend
  * @width: the new width of the surface
  * @height: the new height of the surface
  *
@@ -2829,34 +2858,34 @@ typedef void (*cairo_xrender_composite_t
 	       _Xconst XRenderPictFormat    *maskFormat,
 	       int                          xSrc,
 	       int                          ySrc,
 	       int                          xDst,
 	       int                          yDst,
 	       _Xconst XGlyphElt8           *elts,
 	       int                          nelt);
 
-/* Build a struct of the same size of cairo_glyph_t that can be used both as
+/* Build a struct of the same size of #cairo_glyph_t that can be used both as
  * an input glyph with double coordinates, and as "working" glyph with
  * integer from-current-point offsets. */
 typedef struct {
   unsigned long index;
   union {
     struct {
       double x;
       double y;
     } d;
     struct {
       int x;
       int y;
     } i;
   } p;
 } cairo_xlib_glyph_t;
 
-/* compile-time assert that cairo_xlib_glyph_t is the same size as cairo_glyph_t */
+/* compile-time assert that #cairo_xlib_glyph_t is the same size as #cairo_glyph_t */
 typedef int cairo_xlib_glyph_t_size_assertion [sizeof (cairo_xlib_glyph_t) == sizeof (cairo_glyph_t) ? 1 : -1];
 
 #define GLYPH_INDEX_SKIP ((unsigned long) -1)
 
 static cairo_status_t
 _cairo_xlib_surface_emit_glyphs_chunk (cairo_xlib_surface_t *dst,
 				       cairo_xlib_glyph_t *glyphs,
 				       int num_glyphs,
--- a/gfx/cairo/cairo/src/cairo-xlib-xrender.h
+++ b/gfx/cairo/cairo/src/cairo-xlib-xrender.h
@@ -49,15 +49,18 @@ CAIRO_BEGIN_DECLS
 cairo_public cairo_surface_t *
 cairo_xlib_surface_create_with_xrender_format (Display		 *dpy,
                                                Drawable		  drawable,
 					       Screen		 *screen,
                                                XRenderPictFormat *format,
                                                int		  width,
                                                int		  height);
 
+cairo_public XRenderPictFormat *
+cairo_xlib_surface_get_xrender_format (cairo_surface_t *surface);
+
 CAIRO_END_DECLS
 
 #else  /* CAIRO_HAS_XLIB_XRENDER_SURFACE */
 # error Cairo was not compiled with support for the xlib XRender backend
 #endif /* CAIRO_HAS_XLIB_XRENDER_SURFACE */
 
 #endif /* CAIRO_XLIB_XRENDER_H */
--- a/gfx/cairo/cairo/src/cairo.c
+++ b/gfx/cairo/cairo/src/cairo.c
@@ -58,21 +58,21 @@ static const cairo_t _cairo_nil = {
     FALSE,			/* has_current_point */
     FALSE,			/* has_curve_to */
     NULL, {{NULL}}		/* buf_tail, buf_head */
   }}
 };
 
 #include <assert.h>
 
-/* This has to be updated whenever cairo_status_t is extended.  That's
+/* This has to be updated whenever #cairo_status_t is extended.  That's
  * a bit of a pain, but it should be easy to always catch as long as
  * one adds a new test case to test a trigger of the new status value.
  */
-#define CAIRO_STATUS_LAST_STATUS CAIRO_STATUS_TEMP_FILE_ERROR
+#define CAIRO_STATUS_LAST_STATUS CAIRO_STATUS_INVALID_STRIDE
 
 /**
  * _cairo_error:
  * @status: a status value indicating an error, (eg. not
  * CAIRO_STATUS_SUCCESS)
  *
  * Checks that status is an error status, but does nothing else.
  *
@@ -120,17 +120,17 @@ static void
 
     status = _cairo_error (status);
 }
 
 /**
  * cairo_version:
  *
  * Returns the version of the cairo library encoded in a single
- * integer as per CAIRO_VERSION_ENCODE. The encoding ensures that
+ * integer as per %CAIRO_VERSION_ENCODE. The encoding ensures that
  * later versions compare greater than earlier versions.
  *
  * A run-time comparison to check that cairo's version is greater than
  * or equal to version X.Y.Z could be performed as follows:
  *
  * <informalexample><programlisting>
  * if (cairo_version() >= CAIRO_VERSION_ENCODE(X,Y,Z)) {...}
  * </programlisting></informalexample>
@@ -167,17 +167,17 @@ slim_hidden_def (cairo_version_string);
 /**
  * cairo_create:
  * @target: target surface for the context
  *
  * Creates a new #cairo_t with all graphics state parameters set to
  * default values and with @target as a target surface. The target
  * surface should be constructed with a backend-specific function such
  * as cairo_image_surface_create() (or any other
- * <literal>cairo_&lt;backend&gt;_surface_create</literal> variant).
+ * cairo_<emphasis>backend</emphasis>_surface_create variant).
  *
  * This function references @target, so you can immediately
  * call cairo_surface_destroy() on it if you don't need to
  * maintain a separate reference to it.
  *
  * Return value: a newly allocated #cairo_t with a reference
  *  count of 1. The initial reference count should be released
  *  with cairo_destroy() when you are done using the #cairo_t.
@@ -456,17 +456,17 @@ cairo_push_group (cairo_t *cr)
 {
     cairo_push_group_with_content (cr, CAIRO_CONTENT_COLOR_ALPHA);
 }
 slim_hidden_def(cairo_push_group);
 
 /**
  * cairo_push_group_with_content:
  * @cr: a cairo context
- * @content: a %cairo_content_t indicating the type of group that
+ * @content: a %#cairo_content_t indicating the type of group that
  *           will be created
  *
  * Temporarily redirects drawing to an intermediate surface known as a
  * group. The redirection lasts until the group is completed by a call
  * to cairo_pop_group() or cairo_pop_group_to_source(). These calls
  * provide the result of any drawing to the group as a pattern,
  * (either as an explicit object, or set as the source pattern).
  *
@@ -600,17 +600,17 @@ slim_hidden_def(cairo_pop_group);
  * Terminates the redirection begun by a call to cairo_push_group() or
  * cairo_push_group_with_content() and installs the resulting pattern
  * as the source pattern in the given cairo context.
  *
  * The behavior of this function is equivalent to the sequence of
  * operations:
  *
  * <informalexample><programlisting>
- * cairo_pattern_t *group = cairo_pop_group (cr);
+ * #cairo_pattern_t *group = cairo_pop_group (cr);
  * cairo_set_source (cr, group);
  * cairo_pattern_destroy (group);
  * </programlisting></informalexample>
  *
  * but is more convenient as their is no need for a variable to store
  * the short-lived pointer to the pattern.
  *
  * The cairo_pop_group() function calls cairo_restore(), (balancing a
@@ -1016,32 +1016,32 @@ cairo_set_line_join (cairo_t *cr, cairo_
  * Sets the dash pattern to be used by cairo_stroke(). A dash pattern
  * is specified by @dashes, an array of positive values. Each value
  * provides the length of alternate "on" and "off" portions of the
  * stroke. The @offset specifies an offset into the pattern at which
  * the stroke begins.
  *
  * Each "on" segment will have caps applied as if the segment were a
  * separate sub-path. In particular, it is valid to use an "on" length
- * of 0.0 with CAIRO_LINE_CAP_ROUND or CAIRO_LINE_CAP_SQUARE in order
+ * of 0.0 with %CAIRO_LINE_CAP_ROUND or %CAIRO_LINE_CAP_SQUARE in order
  * to distributed dots or squares along a path.
  *
  * Note: The length values are in user-space units as evaluated at the
  * time of stroking. This is not necessarily the same as the user
  * space at the time of cairo_set_dash().
  *
  * If @num_dashes is 0 dashing is disabled.
  *
  * If @num_dashes is 1 a symmetric pattern is assumed with alternating
  * on and off portions of the size specified by the single value in
  * @dashes.
  *
  * If any value in @dashes is negative, or if all values are 0, then
- * @cairo_t will be put into an error state with a status of
- * #CAIRO_STATUS_INVALID_DASH.
+ * @cr will be put into an error state with a status of
+ * #%CAIRO_STATUS_INVALID_DASH.
  **/
 void
 cairo_set_dash (cairo_t	     *cr,
 		const double *dashes,
 		int	      num_dashes,
 		double	      offset)
 {
     cairo_status_t status;
@@ -1140,17 +1140,17 @@ cairo_set_miter_limit (cairo_t *cr, doub
  * cairo_translate:
  * @cr: a cairo context
  * @tx: amount to translate in the X direction
  * @ty: amount to translate in the Y direction
  *
  * Modifies the current transformation matrix (CTM) by translating the
  * user-space origin by (@tx, @ty). This offset is interpreted as a
  * user-space coordinate according to the CTM in place before the new
- * call to cairo_translate. In other words, the translation of the
+ * call to cairo_translate(). In other words, the translation of the
  * user-space origin takes place after any existing transformation.
  **/
 void
 cairo_translate (cairo_t *cr, double tx, double ty)
 {
     cairo_status_t status;
 
     if (cr->status)
@@ -1839,20 +1839,20 @@ cairo_stroke_to_path (cairo_t *cr)
  * current point will be at the joined endpoint of the sub-path.
  *
  * The behavior of cairo_close_path() is distinct from simply calling
  * cairo_line_to() with the equivalent coordinate in the case of
  * stroking. When a closed sub-path is stroked, there are no caps on
  * the ends of the sub-path. Instead, there is a line join connecting
  * the final and initial segments of the sub-path.
  *
- * If there is no current point before the call to cairo_close_path,
+ * If there is no current point before the call to cairo_close_path(),
  * this function will have no effect.
  *
- * Note: As of cairo version 1.2.4 any call to cairo_close_path will
+ * Note: As of cairo version 1.2.4 any call to cairo_close_path() will
  * place an explicit MOVE_TO element into the path immediately after
  * the CLOSE_PATH element, (which can be seen in cairo_copy_path() for
  * example). This can simplify path processing in some cases as it may
  * not be necessary to save the "last move_to point" during processing
  * as the MOVE_TO immediately after the CLOSE_PATH will provide that
  * point.
  **/
 void
@@ -1882,35 +1882,45 @@ slim_hidden_def(cairo_close_path);
  * an empty rectangle ((0,0), (0,0)). Stroke parameters, fill rule,
  * surface dimensions and clipping are not taken into account.
  *
  * Contrast with cairo_fill_extents() and cairo_stroke_extents() which
  * return the extents of only the area that would be "inked" by
  * the corresponding drawing operations.
  *
  * The result of cairo_path_extents() is defined as equivalent to the
- * limit of cairo_stroke_extents() with CAIRO_LINE_CAP_ROUND as the
+ * limit of cairo_stroke_extents() with %CAIRO_LINE_CAP_ROUND as the
  * line width approaches 0.0, (but never reaching the empty-rectangle
  * returned by cairo_stroke_extents() for a line width of 0.0).
  *
  * Specifically, this means that zero-area sub-paths such as
  * cairo_move_to();cairo_line_to() segments, (even degenerate cases
  * where the coordinates to both calls are identical), will be
  * considered as contributing to the extents. However, a lone
  * cairo_move_to() will not contribute to the results of
  * cairo_path_extents().
  *
  * Since: 1.6
  **/
 void
 cairo_path_extents (cairo_t *cr,
 		    double *x1, double *y1, double *x2, double *y2)
 {
-    if (cr->status)
+    if (cr->status) {
+	if (x1)
+	    *x1 = 0.0;
+	if (y1)
+	    *y1 = 0.0;
+	if (x2)
+	    *x2 = 0.0;
+	if (y2)
+	    *y2 = 0.0;
+
 	return;
+    }
 
     _cairo_gstate_path_extents (cr->gstate,
 				cr->path,
 				x1, y1, x2, y2);
 }
 slim_hidden_def (cairo_path_extents);
 
 /**
@@ -2054,47 +2064,47 @@ cairo_mask_surface (cairo_t         *cr,
  * cairo_set_line_cap(), cairo_set_dash(), and
  * cairo_stroke_preserve().
  *
  * Note: Degenerate segments and sub-paths are treated specially and
  * provide a useful result. These can result in two different
  * situations:
  *
  * 1. Zero-length "on" segments set in cairo_set_dash(). If the cap
- * style is CAIRO_LINE_CAP_ROUND or CAIRO_LINE_CAP_SQUARE then these
+ * style is %CAIRO_LINE_CAP_ROUND or %CAIRO_LINE_CAP_SQUARE then these
  * segments will be drawn as circular dots or squares respectively. In
- * the case of CAIRO_LINE_CAP_SQUARE, the orientation of the squares
+ * the case of %CAIRO_LINE_CAP_SQUARE, the orientation of the squares
  * is determined by the direction of the underlying path.
  *
  * 2. A sub-path created by cairo_move_to() followed by either a
  * cairo_close_path() or one or more calls to cairo_line_to() to the
  * same coordinate as the cairo_move_to(). If the cap style is
  * CAIRO_LINE_CAP_ROUND then these sub-paths will be drawn as circular
- * dots. Note that in the case of CAIRO_LINE_CAP_SQUARE a degenerate
+ * dots. Note that in the case of %CAIRO_LINE_CAP_SQUARE a degenerate
  * sub-path will not be drawn at all, (since the correct orientation
  * is indeterminate).
  *
- * In no case will a cap style of CAIRO_LINE_CAP_BUTT cause anything
+ * In no case will a cap style of %CAIRO_LINE_CAP_BUTT cause anything
  * to be drawn in the case of either degenerate segments or sub-paths.
  **/
 void
 cairo_stroke (cairo_t *cr)
 {
     cairo_stroke_preserve (cr);
 
     cairo_new_path (cr);
 }
 
 /**
  * cairo_stroke_preserve:
  * @cr: a cairo context
  *
  * A drawing operator that strokes the current path according to the
  * current line width, line join, line cap, and dash settings. Unlike
- * cairo_stroke(), cairo_stroke_preserve preserves the path within the
+ * cairo_stroke(), cairo_stroke_preserve() preserves the path within the
  * cairo context.
  *
  * See cairo_set_line_width(), cairo_set_line_join(),
  * cairo_set_line_cap(), cairo_set_dash(), and
  * cairo_stroke_preserve().
  **/
 void
 cairo_stroke_preserve (cairo_t *cr)
@@ -2111,17 +2121,17 @@ cairo_stroke_preserve (cairo_t *cr)
 slim_hidden_def(cairo_stroke_preserve);
 
 /**
  * cairo_fill:
  * @cr: a cairo context
  *
  * A drawing operator that fills the current path according to the
  * current fill rule, (each sub-path is implicitly closed before being
- * filled). After cairo_fill, the current path will be cleared from
+ * filled). After cairo_fill(), the current path will be cleared from
  * the cairo context. See cairo_set_fill_rule() and
  * cairo_fill_preserve().
  **/
 void
 cairo_fill (cairo_t *cr)
 {
     cairo_fill_preserve (cr);
 
@@ -2129,17 +2139,17 @@ cairo_fill (cairo_t *cr)
 }
 
 /**
  * cairo_fill_preserve:
  * @cr: a cairo context
  *
  * A drawing operator that fills the current path according to the
  * current fill rule, (each sub-path is implicitly closed before being
- * filled). Unlike cairo_fill(), cairo_fill_preserve preserves the
+ * filled). Unlike cairo_fill(), cairo_fill_preserve() preserves the
  * path within the cairo context.
  *
  * See cairo_set_fill_rule() and cairo_fill().
  **/
 void
 cairo_fill_preserve (cairo_t *cr)
 {
     cairo_status_t status;
@@ -2296,18 +2306,28 @@ cairo_in_fill (cairo_t *cr, double x, do
  * cairo_stroke_preserve().
  **/
 void
 cairo_stroke_extents (cairo_t *cr,
                       double *x1, double *y1, double *x2, double *y2)
 {
     cairo_status_t status;
 
-    if (cr->status)
+    if (cr->status) {
+	if (x1)
+	    *x1 = 0.0;
+	if (y1)
+	    *y1 = 0.0;
+	if (x2)
+	    *x2 = 0.0;
+	if (y2)
+	    *y2 = 0.0;
+
 	return;
+    }
 
     status = _cairo_gstate_stroke_extents (cr->gstate,
 					   cr->path,
 					   x1, y1, x2, y2);
     if (status)
 	_cairo_set_error (cr, status);
 }
 
@@ -2332,35 +2352,45 @@ cairo_stroke_extents (cairo_t *cr,
  * See cairo_fill(), cairo_set_fill_rule() and cairo_fill_preserve().
  **/
 void
 cairo_fill_extents (cairo_t *cr,
                     double *x1, double *y1, double *x2, double *y2)
 {
     cairo_status_t status;
 
-    if (cr->status)
+    if (cr->status) {
+	if (x1)
+	    *x1 = 0.0;
+	if (y1)
+	    *y1 = 0.0;
+	if (x2)
+	    *x2 = 0.0;
+	if (y2)
+	    *y2 = 0.0;
+
 	return;
+    }
 
     status = _cairo_gstate_fill_extents (cr->gstate,
 					 cr->path,
 					 x1, y1, x2, y2);
     if (status)
 	_cairo_set_error (cr, status);
 }
 
 /**
  * cairo_clip:
  * @cr: a cairo context
  *
  * Establishes a new clip region by intersecting the current clip
  * region with the current path as it would be filled by cairo_fill()
  * and according to the current fill rule (see cairo_set_fill_rule()).
  *
- * After cairo_clip, the current path will be cleared from the cairo
+ * After cairo_clip(), the current path will be cleared from the cairo
  * context.
  *
  * The current clip region affects all drawing operations by
  * effectively masking out any changes to the surface that are outside
  * the current clip region.
  *
  * Calling cairo_clip() can only make the clip region smaller, never
  * larger. But the current clip is part of the graphics state, so a
@@ -2380,17 +2410,17 @@ cairo_clip (cairo_t *cr)
 /**
  * cairo_clip_preserve:
  * @cr: a cairo context
  *
  * Establishes a new clip region by intersecting the current clip
  * region with the current path as it would be filled by cairo_fill()
  * and according to the current fill rule (see cairo_set_fill_rule()).
  *
- * Unlike cairo_clip(), cairo_clip_preserve preserves the path within
+ * Unlike cairo_clip(), cairo_clip_preserve() preserves the path within
  * the cairo context.
  *
  * The current clip region affects all drawing operations by
  * effectively masking out any changes to the surface that are outside
  * the current clip region.
  *
  * Calling cairo_clip() can only make the clip region smaller, never
  * larger. But the current clip is part of the graphics state, so a
@@ -2457,18 +2487,28 @@ cairo_reset_clip (cairo_t *cr)
  **/
 void
 cairo_clip_extents (cairo_t *cr,
 		    double *x1, double *y1,
 		    double *x2, double *y2)
 {
     cairo_status_t status;
 
-    if (cr->status)
+    if (cr->status) {
+	if (x1)
+	    *x1 = 0.0;
+	if (y1)
+	    *y1 = 0.0;
+	if (x2)
+	    *x2 = 0.0;
+	if (y2)
+	    *y2 = 0.0;
+
 	return;
+    }
 
     status = _cairo_gstate_clip_extents (cr->gstate, x1, y1, x2, y2);
     if (status)
 	_cairo_set_error (cr, status);
 }
 
 static cairo_rectangle_list_t *
 _cairo_rectangle_list_create_in_error (cairo_status_t status)
@@ -2492,25 +2532,23 @@ static cairo_rectangle_list_t *
 
 /**
  * cairo_copy_clip_rectangle_list:
  * @cr: a cairo context
  *
  * Gets the current clip region as a list of rectangles in user coordinates.
  * Never returns %NULL.
  *
- * The status in the list may be CAIRO_STATUS_CLIP_NOT_REPRESENTABLE to
+ * The status in the list may be %CAIRO_STATUS_CLIP_NOT_REPRESENTABLE to
  * indicate that the clip region cannot be represented as a list of
  * user-space rectangles. The status may have other values to indicate
  * other errors.
  *
- * The caller must always call cairo_rectangle_list_destroy on the result of
- * this function.
- *
- * Returns: the current clip region as a list of rectangles in user coordinates.
+ * Returns: the current clip region as a list of rectangles in user coordinates,
+ * which should be destroyed using cairo_rectangle_list_destroy().
  *
  * Since: 1.4
  **/
 cairo_rectangle_list_t *
 cairo_copy_clip_rectangle_list (cairo_t *cr)
 {
     if (cr->status)
         return _cairo_rectangle_list_create_in_error (cr->status);
@@ -2558,16 +2596,22 @@ cairo_select_font_face (cairo_t         
  * Gets the font extents for the currently selected font.
  **/
 void
 cairo_font_extents (cairo_t              *cr,
 		    cairo_font_extents_t *extents)
 {
     cairo_status_t status;
 
+    extents->ascent = 0.0;
+    extents->descent = 0.0;
+    extents->height = 0.0;
+    extents->max_x_advance = 0.0;
+    extents->max_y_advance = 0.0;
+
     if (cr->status)
 	return;
 
     status = _cairo_gstate_get_font_extents (cr->gstate, extents);
     if (status)
 	_cairo_set_error (cr, status);
 }
 
@@ -2605,17 +2649,17 @@ cairo_set_font_face (cairo_t           *
  * cairo_font_face_reference.
  *
  * This function never returns %NULL. If memory cannot be allocated, a
  * special "nil" #cairo_font_face_t object will be returned on which
  * cairo_font_face_status() returns %CAIRO_STATUS_NO_MEMORY. Using
  * this nil object will cause its error state to propagate to other
  * objects it is passed to, (for example, calling
  * cairo_set_font_face() with a nil font will trigger an error that
- * will shutdown the cairo_t object).
+ * will shutdown the #cairo_t object).
  **/
 cairo_font_face_t *
 cairo_get_font_face (cairo_t *cr)
 {
     cairo_status_t status;
     cairo_font_face_t *font_face;
 
     if (cr->status)
@@ -2811,17 +2855,17 @@ BAIL:
  * cairo_scaled_font_reference().
  *
  * This function never returns %NULL. If memory cannot be allocated, a
  * special "nil" #cairo_scaled_font_t object will be returned on which
  * cairo_scaled_font_status() returns %CAIRO_STATUS_NO_MEMORY. Using
  * this nil object will cause its error state to propagate to other
  * objects it is passed to, (for example, calling
  * cairo_set_scaled_font() with a nil font will trigger an error that
- * will shutdown the cairo_t object).
+ * will shutdown the #cairo_t object).
  *
  * Since: 1.4
  **/
 cairo_scaled_font_t *
 cairo_get_scaled_font (cairo_t *cr)
 {
     cairo_status_t status;
     cairo_scaled_font_t *scaled_font;
@@ -2956,17 +3000,17 @@ cairo_glyph_extents (cairo_t            
  * glyph.
  *
  * After this call the current point is moved to the origin of where
  * the next glyph would be placed in this same progression. That is,
  * the current point will be at the origin of the final glyph offset
  * by its advance values. This allows for easy display of a single
  * logical string with multiple calls to cairo_show_text().
  *
- * NOTE: The cairo_show_text() function call is part of what the cairo
+ * Note: The cairo_show_text() function call is part of what the cairo
  * designers call the "toy" text API. It is convenient for short demos
  * and simple programs, but it is not expected to be adequate for
  * serious text-using applications. See cairo_show_glyphs() for the
  * "real" text display API in cairo.
  **/
 void
 cairo_show_text (cairo_t *cr, const char *utf8)
 {
@@ -3055,17 +3099,17 @@ cairo_show_glyphs (cairo_t *cr, const ca
  *
  * Like cairo_show_text(), After this call the current point is
  * moved to the origin of where the next glyph would be placed in
  * this same progression.  That is, the current point will be at
  * the origin of the final glyph offset by its advance values.
  * This allows for chaining multiple calls to to cairo_text_path()
  * without having to set current point in between.
  *
- * NOTE: The cairo_text_path() function call is part of what the cairo
+ * Note: The cairo_text_path() function call is part of what the cairo
  * designers call the "toy" text API. It is convenient for short demos
  * and simple programs, but it is not expected to be adequate for
  * serious text-using applications. See cairo_glyph_path() for the
  * "real" text path API in cairo.
  **/
 void
 cairo_text_path  (cairo_t *cr, const char *utf8)
 {
@@ -3196,27 +3240,48 @@ cairo_get_antialias (cairo_t *cr)
 {
     if (cr->status)
 	return (cairo_antialias_t) 0;
 
     return _cairo_gstate_get_antialias (cr->gstate);
 }
 
 /**
+ * cairo_has_current_point:
+ * @cr: a cairo context
+ *
+ * Returns whether a current point is defined on the current path.
+ * See cairo_get_current_point() for details on the current point.
+ *
+ * Return value: whether a current point is defined.
+ *
+ * Since: 1.6
+ **/
+cairo_bool_t
+cairo_has_current_point (cairo_t *cr)
+{
+    if (cr->status)
+    return FALSE;
+
+    return cr->path->has_current_point;
+}
+
+/**
  * cairo_get_current_point:
  * @cr: a cairo context
  * @x: return value for X coordinate of the current point
  * @y: return value for Y coordinate of the current point
  *
  * Gets the current point of the current path, which is
  * conceptually the final point reached by the path so far.
  *
  * The current point is returned in the user-space coordinate
- * system. If there is no defined current point then @x and @y will
- * both be set to 0.0.
+ * system. If there is no defined current point or if @cr is in an
+ * error status, @x and @y will both be set to 0.0. It is possible to
+ * check this in advance with cairo_has_current_point().
  *
  * Most path construction functions alter the current point. See the
  * following for details on how they affect the current point:
  * cairo_new_path(), cairo_new_sub_path(),
  * cairo_append_path(), cairo_close_path(),
  * cairo_move_to(), cairo_line_to(), cairo_curve_to(),
  * cairo_rel_move_to(), cairo_rel_line_to(), cairo_rel_curve_to(),
  * cairo_arc(), cairo_arc_negative(), cairo_rectangle(),
@@ -3420,17 +3485,17 @@ cairo_get_group_target (cairo_t *cr)
  * cairo_copy_path:
  * @cr: a cairo context
  *
  * Creates a copy of the current path and returns it to the user as a
  * #cairo_path_t. See #cairo_path_data_t for hints on how to iterate
  * over the returned data structure.
  *
  * This function will always return a valid pointer, but the result
- * will have no data (<literal>data==NULL</literal> and
+ * will have no data (<literal>data==%NULL</literal> and
  * <literal>num_data==0</literal>), if either of the following
  * conditions hold:
  *
  * <orderedlist>
  * <listitem>If there is insufficient memory to copy the path. In this
  *     case <literal>path->status</literal> will be set to
  *     %CAIRO_STATUS_NO_MEMORY.</listitem>
  * <listitem>If @cr is already in an error state. In this case
@@ -3466,17 +3531,17 @@ cairo_copy_path (cairo_t *cr)
  * This function is like cairo_copy_path() except that any curves
  * in the path will be approximated with piecewise-linear
  * approximations, (accurate to within the current tolerance
  * value). That is, the result is guaranteed to not have any elements
  * of type %CAIRO_PATH_CURVE_TO which will instead be replaced by a
  * series of %CAIRO_PATH_LINE_TO elements.
  *
  * This function will always return a valid pointer, but the result
- * will have no data (<literal>data==NULL</literal> and
+ * will have no data (<literal>data==%NULL</literal> and
  * <literal>num_data==0</literal>), if either of the following
  * conditions hold:
  *
  * <orderedlist>
  * <listitem>If there is insufficient memory to copy the path. In this
  *     case <literal>path->status</literal> will be set to
  *     %CAIRO_STATUS_NO_MEMORY.</listitem>
  * <listitem>If @cr is already in an error state. In this case
@@ -3546,32 +3611,32 @@ cairo_append_path (cairo_t		*cr,
 }
 
 /**
  * cairo_status:
  * @cr: a cairo context
  *
  * Checks whether an error has previously occurred for this context.
  *
- * Returns the current status of this context, see #cairo_status_t
+ * Returns: the current status of this context, see #cairo_status_t
  **/
 cairo_status_t
 cairo_status (cairo_t *cr)
 {
     return cr->status;
 }
 slim_hidden_def (cairo_status);
 
 /**
  * cairo_status_to_string:
  * @status: a cairo status
  *
  * Provides a human-readable description of a #cairo_status_t.
  *
- * Returns a string representation of the status
+ * Returns: a string representation of the status
  */
 const char *
 cairo_status_to_string (cairo_status_t status)
 {
     switch (status) {
     case CAIRO_STATUS_SUCCESS:
 	return "success";
     case CAIRO_STATUS_NO_MEMORY:
@@ -3615,16 +3680,18 @@ cairo_status_to_string (cairo_status_t s
     case CAIRO_STATUS_INVALID_DSC_COMMENT:
 	return "invalid value for a DSC comment";
     case CAIRO_STATUS_INVALID_INDEX:
 	return "invalid index passed to getter";
     case CAIRO_STATUS_CLIP_NOT_REPRESENTABLE:
         return "clip region not representable in desired format";
     case CAIRO_STATUS_TEMP_FILE_ERROR:
 	return "error creating or writing to a temporary file";
+    case CAIRO_STATUS_INVALID_STRIDE:
+	return "invalid value for stride";
     }
 
     return "<unknown error status>";
 }
 
 void
 _cairo_restrict_value (double *value, double min, double max)
 {
--- a/gfx/cairo/cairo/src/cairo.h
+++ b/gfx/cairo/cairo/src/cairo.h
@@ -135,19 +135,19 @@ typedef struct _cairo_matrix {
  * cairo_pattern_t:
  *
  * A #cairo_pattern_t represents a source when drawing onto a
  * surface. There are different subtypes of #cairo_pattern_t,
  * for different types of sources; for example,
  * cairo_pattern_create_rgb() creates a pattern for a solid
  * opaque color.
  *
- * Other than various cairo_pattern_create_<emphasis>type</emphasis>
+ * Other than various cairo_pattern_create_<emphasis>type</emphasis>()
  * functions, some of the pattern types can be implicitly created
- * using vairous cairo_set_source_<emphasis>type</emphasis> functions;
+ * using various cairo_set_source_<emphasis>type</emphasis>() functions;
  * for example cairo_set_source_rgb().
  *
  * The type of a pattern can be queried with cairo_pattern_get_type().
  *
  * Memory management of #cairo_pattern_t is done with
  * cairo_pattern_reference() and cairo_pattern_destroy().
  **/
 typedef struct _cairo_pattern cairo_pattern_t;
@@ -172,41 +172,42 @@ typedef void (*cairo_destroy_func_t) (vo
  * address of a #cairo_data_key_t object is used.  Typically, you
  * would just use the address of a static #cairo_data_key_t object.
  **/
 typedef struct _cairo_user_data_key {
     int unused;
 } cairo_user_data_key_t;
 
 /**
- * cairo_status_t
+ * cairo_status_t:
  * @CAIRO_STATUS_SUCCESS: no error has occurred
  * @CAIRO_STATUS_NO_MEMORY: out of memory
- * @CAIRO_STATUS_INVALID_RESTORE: cairo_restore without matching cairo_save
+ * @CAIRO_STATUS_INVALID_RESTORE: cairo_restore() called without matching cairo_save()
  * @CAIRO_STATUS_INVALID_POP_GROUP: no saved group to pop
  * @CAIRO_STATUS_NO_CURRENT_POINT: no current point defined
  * @CAIRO_STATUS_INVALID_MATRIX: invalid matrix (not invertible)
- * @CAIRO_STATUS_INVALID_STATUS: invalid value for an input cairo_status_t
- * @CAIRO_STATUS_NULL_POINTER: NULL pointer
+ * @CAIRO_STATUS_INVALID_STATUS: invalid value for an input #cairo_status_t
+ * @CAIRO_STATUS_NULL_POINTER: %NULL pointer
  * @CAIRO_STATUS_INVALID_STRING: input string not valid UTF-8
  * @CAIRO_STATUS_INVALID_PATH_DATA: input path data not valid
  * @CAIRO_STATUS_READ_ERROR: error while reading from input stream
  * @CAIRO_STATUS_WRITE_ERROR: error while writing to output stream
  * @CAIRO_STATUS_SURFACE_FINISHED: target surface has been finished
  * @CAIRO_STATUS_SURFACE_TYPE_MISMATCH: the surface type is not appropriate for the operation
  * @CAIRO_STATUS_PATTERN_TYPE_MISMATCH: the pattern type is not appropriate for the operation
- * @CAIRO_STATUS_INVALID_CONTENT: invalid value for an input cairo_content_t
- * @CAIRO_STATUS_INVALID_FORMAT: invalid value for an input cairo_format_t
+ * @CAIRO_STATUS_INVALID_CONTENT: invalid value for an input #cairo_content_t
+ * @CAIRO_STATUS_INVALID_FORMAT: invalid value for an input #cairo_format_t
  * @CAIRO_STATUS_INVALID_VISUAL: invalid value for an input Visual*
  * @CAIRO_STATUS_FILE_NOT_FOUND: file not found
  * @CAIRO_STATUS_INVALID_DASH: invalid value for a dash setting
  * @CAIRO_STATUS_INVALID_DSC_COMMENT: invalid value for a DSC comment (Since 1.2)
  * @CAIRO_STATUS_INVALID_INDEX: invalid index passed to getter (Since 1.4)
  * @CAIRO_STATUS_CLIP_NOT_REPRESENTABLE: clip region not representable in desired format (Since 1.4)
  * @CAIRO_STATUS_TEMP_FILE_ERROR: error creating or writing to a temporary file (Since 1.6)
+ * @CAIRO_STATUS_INVALID_STRIDE: invalid value for stride (Since 1.6)
  *
  * #cairo_status_t is used to indicate errors that can occur when
  * using Cairo. In some cases it is returned directly by functions.
  * but when using #cairo_t, the last error, if any, is stored in
  * the context and can be retrieved with cairo_status().
  *
  * New entries may be added in future versions.  Use cairo_status_to_string()
  * to get a human-readable representation of an error message.
@@ -230,32 +231,33 @@ typedef enum _cairo_status {
     CAIRO_STATUS_INVALID_CONTENT,
     CAIRO_STATUS_INVALID_FORMAT,
     CAIRO_STATUS_INVALID_VISUAL,
     CAIRO_STATUS_FILE_NOT_FOUND,
     CAIRO_STATUS_INVALID_DASH,
     CAIRO_STATUS_INVALID_DSC_COMMENT,
     CAIRO_STATUS_INVALID_INDEX,
     CAIRO_STATUS_CLIP_NOT_REPRESENTABLE,
-    CAIRO_STATUS_TEMP_FILE_ERROR
+    CAIRO_STATUS_TEMP_FILE_ERROR,
+    CAIRO_STATUS_INVALID_STRIDE
     /* after adding a new error: update CAIRO_STATUS_LAST_STATUS in cairo.c */
 } cairo_status_t;
 
 /**
- * cairo_content_t
+ * cairo_content_t:
  * @CAIRO_CONTENT_COLOR: The surface will hold color content only.
  * @CAIRO_CONTENT_ALPHA: The surface will hold alpha content only.
  * @CAIRO_CONTENT_COLOR_ALPHA: The surface will hold color and alpha content.
  *
  * #cairo_content_t is used to describe the content that a surface will
  * contain, whether color information, alpha information (translucence
  * vs. opacity), or both.
  *
- * Note: The large values here are designed to keep cairo_content_t
- * values distinct from cairo_format_t values so that the
+ * Note: The large values here are designed to keep #cairo_content_t
+ * values distinct from #cairo_format_t values so that the
  * implementation can detect the error if users confuse the two types.
  **/
 typedef enum _cairo_content {
     CAIRO_CONTENT_COLOR		= 0x1000,
     CAIRO_CONTENT_ALPHA		= 0x2000,
     CAIRO_CONTENT_COLOR_ALPHA	= 0x3000
 } cairo_content_t;
 
@@ -281,17 +283,17 @@ typedef cairo_status_t (*cairo_write_fun
 
 /**
  * cairo_read_func_t:
  * @closure: the input closure
  * @data: the buffer into which to read the data
  * @length: the amount of data to read
  *
  * #cairo_read_func_t is the type of function which is called when a
- * backend needs to read data from an intput stream.  It is passed the
+ * backend needs to read data from an input stream.  It is passed the
  * closure which was specified by the user at the time the read
  * function was registered, the buffer to read the data into and the
  * length of the data in bytes.  The read function should return
  * CAIRO_STATUS_SUCCESS if all the data was successfully read,
  * CAIRO_STATUS_READ_ERROR otherwise.
  *
  * Returns: the status code of the read operation
  **/
@@ -337,16 +339,58 @@ cairo_push_group_with_content (cairo_t *
 cairo_public cairo_pattern_t *
 cairo_pop_group (cairo_t *cr);
 
 cairo_public void
 cairo_pop_group_to_source (cairo_t *cr);
 
 /* Modify state */
 
+/**
+ * cairo_operator_t:
+ * @CAIRO_OPERATOR_CLEAR: clear destination layer (bounded)
+ * @CAIRO_OPERATOR_SOURCE: replace destination layer (bounded)
+ * @CAIRO_OPERATOR_OVER: draw source layer on top of destination layer
+ * (bounded)
+ * @CAIRO_OPERATOR_IN: draw source where there was destination content
+ * (unbounded)
+ * @CAIRO_OPERATOR_OUT: draw source where there was no destination
+ * content (unbounded)
+ * @CAIRO_OPERATOR_ATOP: draw source on top of destination content and
+ * only there
+ * @CAIRO_OPERATOR_DEST: ignore the source
+ * @CAIRO_OPERATOR_DEST_OVER: draw destination on top of source
+ * @CAIRO_OPERATOR_DEST_IN: leave destination only where there was
+ * source content (unbounded)
+ * @CAIRO_OPERATOR_DEST_OUT: leave destination only where there was no
+ * source content
+ * @CAIRO_OPERATOR_DEST_ATOP: leave destination on top of source content
+ * and only there (unbounded)
+ * @CAIRO_OPERATOR_XOR: source and destination are shown where there is only
+ * one of them
+ * @CAIRO_OPERATOR_ADD: source and destination layers are accumulated
+ * @CAIRO_OPERATOR_SATURATE: like over, but assuming source and dest are
+ * disjoint geometries
+ *
+ * #cairo_operator_t is used to set the compositing operator for all cairo
+ * drawing operations.
+ *
+ * The operators marked as <firstterm>unbounded</firstterm> modify their
+ * destination even outside of the mask layer (that is, their effect is not
+ * bound by the mask layer).  However, their effect can still be limited by
+ * way of clipping.
+ *
+ * To keep things simple, the operator descriptions here
+ * document the behavior for when both source and destination are either fully
+ * transparent or fully opaque.  The actual implementation works for
+ * translucent layers too.
+ * For a more detailed explanation of the effects of each operator, including
+ * the mathematical definitions, see
+ * <ulink url="http://cairographics.org/operators/">http://cairographics.org/operators/</ulink>.
+ **/
 typedef enum _cairo_operator {
     CAIRO_OPERATOR_CLEAR,
 
     CAIRO_OPERATOR_SOURCE,
     CAIRO_OPERATOR_OVER,
     CAIRO_OPERATOR_IN,
     CAIRO_OPERATOR_OUT,
     CAIRO_OPERATOR_ATOP,
@@ -404,17 +448,17 @@ typedef enum _cairo_antialias {
     CAIRO_ANTIALIAS_GRAY,
     CAIRO_ANTIALIAS_SUBPIXEL
 } cairo_antialias_t;
 
 cairo_public void
 cairo_set_antialias (cairo_t *cr, cairo_antialias_t antialias);
 
 /**
- * cairo_fill_rule_t
+ * cairo_fill_rule_t:
  * @CAIRO_FILL_RULE_WINDING: If the path crosses the ray from
  * left-to-right, counts +1. If the path crosses the ray
  * from right to left, counts -1. (Left and right are determined
  * from the perspective of looking along the ray from the starting
  * point.) If the total count is non-zero, the point will be filled.
  * @CAIRO_FILL_RULE_EVEN_ODD: Counts the total number of
  * intersections, without regard to the orientation of the contour. If
  * the total number of intersections is odd, the point will be
@@ -438,34 +482,34 @@ typedef enum _cairo_fill_rule {
 
 cairo_public void
 cairo_set_fill_rule (cairo_t *cr, cairo_fill_rule_t fill_rule);
 
 cairo_public void
 cairo_set_line_width (cairo_t *cr, double width);
 
 /**
- * cairo_line_cap_t
+ * cairo_line_cap_t:
  * @CAIRO_LINE_CAP_BUTT: start(stop) the line exactly at the start(end) point
  * @CAIRO_LINE_CAP_ROUND: use a round ending, the center of the circle is the end point
  * @CAIRO_LINE_CAP_SQUARE: use squared ending, the center of the square is the end point
  *
  * Specifies how to render the endpoint of a line when stroking.
  **/
 typedef enum _cairo_line_cap {
     CAIRO_LINE_CAP_BUTT,
     CAIRO_LINE_CAP_ROUND,
     CAIRO_LINE_CAP_SQUARE
 } cairo_line_cap_t;
 
 cairo_public void
 cairo_set_line_cap (cairo_t *cr, cairo_line_cap_t line_cap);
 
 /**
- * cairo_line_join_t
+ * cairo_line_join_t:
  * @CAIRO_LINE_JOIN_MITER: use a sharp (angled) corner, see
  * cairo_set_miter_limit()
  * @CAIRO_LINE_JOIN_ROUND: use a rounded join, the center of the circle is the
  * joint point
  * @CAIRO_LINE_JOIN_BEVEL: use a cut-off join, the join is cut off at half
  * the line width from the joint point
  *
  * Specifies how to render the junction of two lines when stroking.
@@ -697,17 +741,17 @@ cairo_public void
 cairo_rectangle_list_destroy (cairo_rectangle_list_t *rectangle_list);
 
 /* Font/Text functions */
 
 /**
  * cairo_scaled_font_t:
  *
  * A #cairo_scaled_font_t is a font scaled to a particular size and device
- * resolution. A cairo_scaled_font_t is most useful for low-level font
+ * resolution. A #cairo_scaled_font_t is most useful for low-level font
  * usage where a library or application wants to cache a reference
  * to a scaled font to speed up the computation of metrics.
  *
  * There are various types of scaled fonts, depending on the
  * <firstterm>font backend</firstterm> they use. The type of a
  * scaled font can be queried using cairo_scaled_font_get_type().
  *
  * Memory management of #cairo_scaled_font_t is done with
@@ -1095,43 +1139,43 @@ cairo_font_face_destroy (cairo_font_face
 
 cairo_public unsigned int
 cairo_font_face_get_reference_count (cairo_font_face_t *font_face);
 
 cairo_public cairo_status_t
 cairo_font_face_status (cairo_font_face_t *font_face);
 
 /**
- * cairo_font_type_t
+ * cairo_font_type_t:
  * @CAIRO_FONT_TYPE_TOY: The font was created using cairo's toy font api
  * @CAIRO_FONT_TYPE_FT: The font is of type FreeType
  * @CAIRO_FONT_TYPE_WIN32: The font is of type Win32
  * @CAIRO_FONT_TYPE_ATSUI: The font is of type ATSUI
  *
  * #cairo_font_type_t is used to describe the type of a given font
  * face or scaled font. The font types are also known as "font
  * backends" within cairo.
  *
  * The type of a font face is determined by the function used to
  * create it, which will generally be of the form
  * cairo_<emphasis>type</emphasis>_font_face_create. The font face type can be queried
  * with cairo_font_face_get_type()
  *
- * The various cairo_font_face functions can be used with a font face
+ * The various #cairo_font_face_t functions can be used with a font face
  * of any type.
  *
  * The type of a scaled font is determined by the type of the font
- * face passed to cairo_scaled_font_create. The scaled font type can
+ * face passed to cairo_scaled_font_create(). The scaled font type can
  * be queried with cairo_scaled_font_get_type()
  *
- * The various cairo_scaled_font functions can be used with scaled
+ * The various #cairo_scaled_font_t functions can be used with scaled
  * fonts of any type, but some font backends also provide
  * type-specific functions that must only be called with a scaled font
  * of the appropriate type. These functions have names that begin with
- * cairo_<emphasis>type</emphasis>_scaled_font such as cairo_ft_scaled_font_lock_face.
+ * cairo_<emphasis>type</emphasis>_scaled_font such as cairo_ft_scaled_font_lock_face().
  *
  * The behavior of calling a type-specific function with a scaled font
  * of the wrong type is undefined.
  *
  * New entries may be added in future versions.
  *
  * Since: 1.2
  **/
@@ -1227,16 +1271,19 @@ cairo_public cairo_pattern_t *
 cairo_get_source (cairo_t *cr);
 
 cairo_public double
 cairo_get_tolerance (cairo_t *cr);
 
 cairo_public cairo_antialias_t
 cairo_get_antialias (cairo_t *cr);
 
+cairo_public cairo_bool_t
+cairo_has_current_point (cairo_t *cr);
+
 cairo_public void
 cairo_get_current_point (cairo_t *cr, double *x, double *y);
 
 cairo_public cairo_fill_rule_t
 cairo_get_fill_rule (cairo_t *cr);
 
 cairo_public double
 cairo_get_line_width (cairo_t *cr);
@@ -1309,36 +1356,36 @@ typedef enum _cairo_path_data_type {
  * The semantics and ordering of the coordinate values are consistent
  * with cairo_move_to(), cairo_line_to(), cairo_curve_to(), and
  * cairo_close_path().
  *
  * Here is sample code for iterating through a #cairo_path_t:
  *
  * <informalexample><programlisting>
  *      int i;
- *      cairo_path_t *path;
- *      cairo_path_data_t *data;
+ *      #cairo_path_t *path;
+ *      #cairo_path_data_t *data;
  * &nbsp;
  *      path = cairo_copy_path (cr);
  * &nbsp;
  *      for (i=0; i < path->num_data; i += path->data[i].header.length) {
  *          data = &amp;path->data[i];
  *          switch (data->header.type) {
- *          case CAIRO_PATH_MOVE_TO:
+ *          case %CAIRO_PATH_MOVE_TO:
  *              do_move_to_things (data[1].point.x, data[1].point.y);
  *              break;
- *          case CAIRO_PATH_LINE_TO:
+ *          case %CAIRO_PATH_LINE_TO:
  *              do_line_to_things (data[1].point.x, data[1].point.y);
  *              break;
- *          case CAIRO_PATH_CURVE_TO:
+ *          case %CAIRO_PATH_CURVE_TO:
  *              do_curve_to_things (data[1].point.x, data[1].point.y,
  *                                  data[2].point.x, data[2].point.y,
  *                                  data[3].point.x, data[3].point.y);
  *              break;
- *          case CAIRO_PATH_CLOSE_PATH:
+ *          case %CAIRO_PATH_CLOSE_PATH:
  *              do_close_path_things ();
  *              break;
  *          }
  *      }
  *      cairo_path_destroy (path);
  * </programlisting></informalexample>
  *
  * As of cairo 1.4, cairo does not mind if there are more elements in
@@ -1425,17 +1472,17 @@ cairo_surface_destroy (cairo_surface_t *
 
 cairo_public unsigned int
 cairo_surface_get_reference_count (cairo_surface_t *surface);
 
 cairo_public cairo_status_t
 cairo_surface_status (cairo_surface_t *surface);
 
 /**
- * cairo_surface_type_t
+ * cairo_surface_type_t:
  * @CAIRO_SURFACE_TYPE_IMAGE: The surface is of type image
  * @CAIRO_SURFACE_TYPE_PDF: The surface is of type pdf
  * @CAIRO_SURFACE_TYPE_PS: The surface is of type ps
  * @CAIRO_SURFACE_TYPE_XLIB: The surface is of type xlib
  * @CAIRO_SURFACE_TYPE_XCB: The surface is of type xcb
  * @CAIRO_SURFACE_TYPE_GLITZ: The surface is of type glitz
  * @CAIRO_SURFACE_TYPE_QUARTZ: The surface is of type quartz
  * @CAIRO_SURFACE_TYPE_WIN32: The surface is of type win32
@@ -1445,22 +1492,22 @@ cairo_surface_status (cairo_surface_t *s
  * @CAIRO_SURFACE_TYPE_OS2: The surface is of type os2
  * @CAIRO_SURFACE_TYPE_WIN32_PRINTING: The surface is a win32 printing surface
  *
  * #cairo_surface_type_t is used to describe the type of a given
  * surface. The surface types are also known as "backends" or "surface
  * backends" within cairo.
  *
  * The type of a surface is determined by the function used to create
- * it, which will generally be of the form cairo_<emphasis>type</emphasis>_surface_create,
- * (though see cairo_surface_create_similar as well).
+ * it, which will generally be of the form cairo_<emphasis>type</emphasis>_surface_create(),
+ * (though see cairo_surface_create_similar() as well).
  *
  * The surface type can be queried with cairo_surface_get_type()
  *
- * The various cairo_surface functions can be used with surfaces of
+ * The various #cairo_surface_t functions can be used with surfaces of
  * any type, but some backends also provide type-specific functions
  * that must only be called with a surface of the appropriate
  * type. These functions have names that begin with
  * cairo_<emphasis>type</emphasis>_surface such as cairo_image_surface_get_width().
  *
  * The behavior of calling a type-specific function with a surface of
  * the wrong type is undefined.
  *
@@ -1541,26 +1588,26 @@ cairo_surface_get_device_offset (cairo_s
 				 double          *x_offset,
 				 double          *y_offset);
 
 cairo_public void
 cairo_surface_set_fallback_resolution (cairo_surface_t	*surface,
 				       double		 x_pixels_per_inch,
 				       double		 y_pixels_per_inch);
 
-cairo_public cairo_status_t
+cairo_public void
 cairo_surface_copy_page (cairo_surface_t *surface);
 
-cairo_public cairo_status_t
+cairo_public void
 cairo_surface_show_page (cairo_surface_t *surface);
 
 /* Image-surface functions */
 
 /**
- * cairo_format_t
+ * cairo_format_t:
  * @CAIRO_FORMAT_ARGB32: each pixel is a 32-bit quantity, with
  *   alpha in the upper 8 bits, then red, then green, then blue.
  *   The 32-bit quantities are stored native-endian. Pre-multiplied
  *   alpha is used. (That is, 50% transparent red is 0x80800000,
  *   not 0x80ff0000.)
  * @CAIRO_FORMAT_RGB24: each pixel is a 32-bit quantity, with
  *   the upper 8 bits unused. Red, Green, and Blue are stored
  *   in the remaining 24 bits in that order.
@@ -1592,16 +1639,20 @@ typedef enum _cairo_format {
     */
 } cairo_format_t;
 
 cairo_public cairo_surface_t *
 cairo_image_surface_create (cairo_format_t	format,
 			    int			width,
 			    int			height);
 
+cairo_public int
+cairo_format_stride_for_width (cairo_format_t	format,
+			       int		width);
+
 cairo_public cairo_surface_t *
 cairo_image_surface_create_for_data (unsigned char	       *data,
 				     cairo_format_t		format,
 				     int			width,
 				     int			height,
 				     int			stride);
 
 cairo_public unsigned char *
@@ -1668,34 +1719,34 @@ cairo_pattern_get_user_data (cairo_patte
 
 cairo_public cairo_status_t
 cairo_pattern_set_user_data (cairo_pattern_t		 *pattern,
 			     const cairo_user_data_key_t *key,
 			     void			 *user_data,
 			     cairo_destroy_func_t	  destroy);
 
 /**
- * cairo_pattern_type_t
+ * cairo_pattern_type_t:
  * @CAIRO_PATTERN_TYPE_SOLID: The pattern is a solid (uniform)
  * color. It may be opaque or translucent.
  * @CAIRO_PATTERN_TYPE_SURFACE: The pattern is a based on a surface (an image).
  * @CAIRO_PATTERN_TYPE_LINEAR: The pattern is a linear gradient.
  * @CAIRO_PATTERN_TYPE_RADIAL: The pattern is a radial gradient.
  *
  * #cairo_pattern_type_t is used to describe the type of a given pattern.
  *
  * The type of a pattern is determined by the function used to create
  * it. The cairo_pattern_create_rgb() and cairo_pattern_create_rgba()
  * functions create SOLID patterns. The remaining
  * cairo_pattern_create functions map to pattern types in obvious
  * ways.
  *
  * The pattern type can be queried with cairo_pattern_get_type()
  *
- * Most cairo_pattern functions can be called with a pattern of any
+ * Most #cairo_pattern_t functions can be called with a pattern of any
  * type, (though trying to change the extend or filter for a solid
  * pattern will have no effect). A notable exception is
  * cairo_pattern_add_color_stop_rgb() and
  * cairo_pattern_add_color_stop_rgba() which must only be called with
  * gradient patterns (either LINEAR or RADIAL). Otherwise the pattern
  * will be shutdown and put into an error state.
  *
  * New entries may be added in future versions.
@@ -1727,17 +1778,17 @@ cairo_public void
 cairo_pattern_set_matrix (cairo_pattern_t      *pattern,
 			  const cairo_matrix_t *matrix);
 
 cairo_public void
 cairo_pattern_get_matrix (cairo_pattern_t *pattern,
 			  cairo_matrix_t  *matrix);
 
 /**
- * cairo_extend_t
+ * cairo_extend_t:
  * @CAIRO_EXTEND_NONE: pixels outside of the source pattern
  *   are fully transparent
  * @CAIRO_EXTEND_REPEAT: the pattern is tiled by repeating
  * @CAIRO_EXTEND_REFLECT: the pattern is tiled by reflecting
  *   at the edges (not implemented for surface patterns currently)
  * @CAIRO_EXTEND_PAD: pixels outside of the pattern copy
  *   the closest pixel from the source (Since 1.2; not implemented
  *   for surface patterns currently)
@@ -1755,16 +1806,34 @@ typedef enum _cairo_extend {
 } cairo_extend_t;
 
 cairo_public void
 cairo_pattern_set_extend (cairo_pattern_t *pattern, cairo_extend_t extend);
 
 cairo_public cairo_extend_t
 cairo_pattern_get_extend (cairo_pattern_t *pattern);
 
+/**
+ * cairo_filter_t:
+ * @CAIRO_FILTER_FAST: A high-performance filter, with quality similar
+ *     to %CAIRO_FILTER_NEAREST
+ * @CAIRO_FILTER_GOOD: A reasonable-performance filter, with quality
+ *     similar to %CAIRO_FILTER_BILINEAR
+ * @CAIRO_FILTER_BEST: The highest-quality available, performance may
+ *     not be suitable for interactive use.
+ * @CAIRO_FILTER_NEAREST: Nearest-neighbor filtering
+ * @CAIRO_FILTER_BILINEAR: Linear interpolation in two dimensions
+ * @CAIRO_FILTER_GAUSSIAN: This filter value is currently
+ *     unimplemented, and should not be used in current code.
+ *
+ * #cairo_filter_t is used to indicate what filtering should be
+ * applied when reading pixel values from patterns. See
+ * cairo_pattern_set_source() for indicating the desired filter to be
+ * used with a particular pattern.
+ */
 typedef enum _cairo_filter {
     CAIRO_FILTER_FAST,
     CAIRO_FILTER_GOOD,
     CAIRO_FILTER_BEST,
     CAIRO_FILTER_NEAREST,
     CAIRO_FILTER_BILINEAR,
     CAIRO_FILTER_GAUSSIAN
 } cairo_filter_t;
--- a/gfx/cairo/cairo/src/cairoint.h
+++ b/gfx/cairo/cairo/src/cairoint.h
@@ -100,16 +100,20 @@ cairo_private FILE *
     do { if (!(expr)) fprintf(stderr, "Assertion failed at %s:%d: %s\n", \
           __FILE__, __LINE__, #expr); } while (0)
 #endif
 
 #ifndef M_SQRT2
 #define M_SQRT2 1.41421356237309504880
 #endif
 
+#ifndef M_SQRT1_2
+#define M_SQRT1_2 0.707106781186547524400844362104849039
+#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))
@@ -181,16 +185,22 @@ be32_to_cpu(uint32_t v)
 #include "cairo-reference-count-private.h"
 
 cairo_private void
 _cairo_box_round_to_rectangle (cairo_box_t *box, cairo_rectangle_int_t *rectangle);
 
 cairo_private void
 _cairo_rectangle_intersect (cairo_rectangle_int_t *dest, cairo_rectangle_int_t *src);
 
+cairo_private cairo_bool_t
+_cairo_box_intersects_line_segment (cairo_box_t *box, cairo_line_t *line);
+
+cairo_private cairo_bool_t
+_cairo_box_contains_point (cairo_box_t *box, cairo_point_t *point);
+
 /* cairo_array.c structures and functions */
 
 cairo_private void
 _cairo_array_init (cairo_array_t *array, int element_size);
 
 cairo_private void
 _cairo_array_init_snapshot (cairo_array_t	*array,
 			    const cairo_array_t *other);
@@ -246,17 +256,17 @@ cairo_private cairo_status_t
 				 cairo_destroy_func_t	      destroy);
 
 cairo_private unsigned long
 _cairo_hash_string (const char *c);
 
 typedef struct _cairo_unscaled_font_backend cairo_unscaled_font_backend_t;
 
 /*
- * A cairo_unscaled_font_t is just an opaque handle we use in the
+ * A #cairo_unscaled_font_t is just an opaque handle we use in the
  * glyph cache.
  */
 typedef struct _cairo_unscaled_font {
     cairo_hash_entry_t			 hash_entry;
     cairo_reference_count_t		 ref_count;
     const cairo_unscaled_font_backend_t	*backend;
 } cairo_unscaled_font_t;
 
@@ -293,17 +303,17 @@ cairo_private void
 _cairo_ft_font_reset_static_data (void);
 
 /* the font backend interface */
 
 struct _cairo_unscaled_font_backend {
     void (*destroy)     	    (void		             *unscaled_font);
 };
 
-/* cairo_toy_font_face_t - simple family/slant/weight font faces used for
+/* #cairo_toy_font_face_t - simple family/slant/weight font faces used for
  * the built-in font API
  */
 
 typedef struct _cairo_toy_font_face {
     cairo_font_face_t base;
     const char *family;
     cairo_bool_t owns_family;
     cairo_font_slant_t slant;
@@ -703,17 +713,17 @@ struct _cairo_image_surface {
     int stride;
     int depth;
 
     pixman_image_t *pixman_image;
 };
 
 extern const cairo_private cairo_surface_backend_t cairo_image_surface_backend;
 
-/* XXX: Right now, the cairo_color structure puts unpremultiplied
+/* XXX: Right now, the _cairo_color structure puts unpremultiplied
    color in the doubles and premultiplied color in the shorts. Yes,
    this is crazy insane, (but at least we don't export this
    madness). I'm still working on a cleaner API, but in the meantime,
    at least this does prevent precision loss in color when changing
    alpha. */
 struct _cairo_color {
     double red;
     double green;
@@ -1397,17 +1407,17 @@ cairo_private cairo_status_t
 cairo_private cairo_status_t
 _cairo_scaled_font_init (cairo_scaled_font_t               *scaled_font,
 			 cairo_font_face_t		   *font_face,
 			 const cairo_matrix_t              *font_matrix,
 			 const cairo_matrix_t              *ctm,
 			 const cairo_font_options_t	   *options,
 			 const cairo_scaled_font_backend_t *backend);
 
-cairo_private void
+cairo_private cairo_status_t
 _cairo_scaled_font_set_metrics (cairo_scaled_font_t	    *scaled_font,
 				cairo_font_extents_t	    *fs_metrics);
 
 cairo_private void
 _cairo_scaled_font_fini (cairo_scaled_font_t *scaled_font);
 
 cairo_private cairo_status_t
 _cairo_scaled_font_font_extents (cairo_scaled_font_t  *scaled_font,
@@ -1478,16 +1488,21 @@ cairo_private void
 
 cairo_private cairo_status_t
 _cairo_stroke_style_init_copy (cairo_stroke_style_t *style,
 			       cairo_stroke_style_t *other);
 
 cairo_private void
 _cairo_stroke_style_fini (cairo_stroke_style_t *style);
 
+cairo_private void
+_cairo_stroke_style_max_distance_from_path (const cairo_stroke_style_t *style,
+                                            const cairo_matrix_t *ctm,
+                                            double *dx, double *dy);
+
 /* cairo-surface.c */
 
 cairo_private cairo_surface_t *
 _cairo_surface_create_in_error (cairo_status_t status);
 
 cairo_private cairo_status_t
 _cairo_surface_set_error (cairo_surface_t	*surface,
 			  cairo_status_t	 status);
@@ -1758,72 +1773,72 @@ cairo_private void
 				 double		  sx,
 				 double		  sy);
 
 cairo_private cairo_bool_t
 _cairo_surface_has_device_transform (cairo_surface_t *surface);
 
 /* cairo_image_surface.c */
 
-/* XXX: In cairo 1.2.0 we added a new CAIRO_FORMAT_RGB16_565 but
+/* XXX: In cairo 1.2.0 we added a new %CAIRO_FORMAT_RGB16_565 but
  * neglected to adjust this macro. The net effect is that it's
  * impossible to externally create an image surface with this
  * format. This is perhaps a good thing since we also neglected to fix
- * up things like cairo_surface_write_to_png for the new format
+ * up things like cairo_surface_write_to_png() for the new format
  * (-Wswitch-enum will tell you where). Is it obvious that format was
  * added in haste?
  *
  * The reason for the new format was to allow the xlib backend to be
  * used on X servers with a 565 visual. So the new format did its job
  * for that, even without being considered "valid" for the sake of
- * things like cairo_image_surface_create.
+ * things like cairo_image_surface_create().
  *
  * Since 1.2.0 we ran into the same situtation with X servers with BGR
- * visuals. This time we invented cairo_internal_format_t instead,
+ * visuals. This time we invented #cairo_internal_format_t instead,
  * (see it for more discussion).
  *
- * The punchline is that CAIRO_FORMAT_VALID must not conside any
+ * The punchline is that %CAIRO_FORMAT_VALID must not conside any
  * internal format to be valid. Also we need to decide if the
  * RGB16_565 should be moved to instead be an internal format. If so,
  * this macro need not change for it. (We probably will need to leave
  * an RGB16_565 value in the header files for the sake of code that
  * might have that value in it.)
  *
  * If we do decide to start fully supporting RGB16_565 as an external
- * format, then CAIRO_FORMAT_VALID needs to be adjusted to include
+ * format, then %CAIRO_FORMAT_VALID needs to be adjusted to include
  * it. But that should not happen before all necessary code is fixed
- * to support it (at least cairo_surface_write_to_png and a few spots
+ * to support it (at least cairo_surface_write_to_png() and a few spots
  * in cairo-xlib-surface.c--again see -Wswitch-enum).
  */
 #define CAIRO_FORMAT_INVALID ((unsigned int) -1)
 #define CAIRO_FORMAT_VALID(format) ((format) <= CAIRO_FORMAT_A1)
 
 #define CAIRO_CONTENT_VALID(content) ((content) && 			         \
 				      (((content) & ~(CAIRO_CONTENT_COLOR |      \
 						      CAIRO_CONTENT_ALPHA |      \
 						      CAIRO_CONTENT_COLOR_ALPHA))\
 				       == 0))
 
-cairo_private cairo_format_t
-_cairo_format_width (cairo_format_t format);
+cairo_private int
+_cairo_format_bits_per_pixel (cairo_format_t format);
 
 cairo_private cairo_format_t
 _cairo_format_from_content (cairo_content_t content);
 
 cairo_private cairo_content_t
 _cairo_content_from_format (cairo_format_t format);
 
 cairo_private cairo_surface_t *
 _cairo_image_surface_create_for_pixman_image (pixman_image_t		*pixman_image,
 					      pixman_format_code_t	 pixman_format);
 
 cairo_private pixman_format_code_t
 _pixman_format_from_masks (cairo_format_masks_t *masks);
 
-void
+cairo_private void
 _pixman_format_to_masks (pixman_format_code_t	 pixman_format,
 			 uint32_t		*bpp,
 			 uint32_t		*red,
 			 uint32_t		*green,
 			 uint32_t		*blue);
 
 cairo_private cairo_surface_t *
 _cairo_image_surface_create_with_pixman_format (unsigned char		*data,
@@ -1969,17 +1984,17 @@ cairo_private void
 				      cairo_bool_t *is_tight);
 
 cairo_private cairo_bool_t
 _cairo_matrix_is_invertible (const cairo_matrix_t *matrix);
 
 cairo_private void
 _cairo_matrix_compute_determinant (const cairo_matrix_t *matrix, double *det);
 
-cairo_private void
+cairo_private cairo_status_t
 _cairo_matrix_compute_scale_factors (const cairo_matrix_t *matrix,
 				     double *sx, double *sy, int x_major);
 
 cairo_private cairo_bool_t
 _cairo_matrix_is_identity (const cairo_matrix_t *matrix);
 
 cairo_private cairo_bool_t
 _cairo_matrix_is_translation (const cairo_matrix_t *matrix);
@@ -1998,16 +2013,20 @@ cairo_private void
 /* cairo_traps.c */
 cairo_private void
 _cairo_traps_init (cairo_traps_t *traps);
 
 cairo_private void
 _cairo_traps_limit (cairo_traps_t	*traps,
 		    cairo_box_t		*limits);
 
+cairo_private cairo_bool_t
+_cairo_traps_get_limit (cairo_traps_t *traps,
+                        cairo_box_t   *limits);
+
 cairo_private cairo_status_t
 _cairo_traps_init_box (cairo_traps_t *traps,
 		       cairo_box_t   *box);
 
 cairo_private void
 _cairo_traps_fini (cairo_traps_t *traps);
 
 cairo_private cairo_status_t
deleted file mode 100644
--- a/gfx/cairo/libpixman/src/pixman-compose-noaccessors.c
+++ /dev/null
@@ -1,4 +0,0 @@
-
-#undef PIXMAN_FB_ACCESSORS
-
-#include "pixman-compose.c"
deleted file mode 100644
--- a/gfx/cairo/libpixman/src/pixman-edge-noaccessors.c
+++ /dev/null
@@ -1,4 +0,0 @@
-
-#undef PIXMAN_FB_ACCESSORS
-
-#include "pixman-edge.c"