[cairo-commit] cairo/src cairo-array.c, 1.7, 1.8 cairo-font-subset.c, 1.6, 1.7 cairo-meta-surface.c, 1.15, 1.16 cairo-pattern.c, 1.69, 1.70 cairoint.h, 1.226, 1.227

Carl Worth commit at pdx.freedesktop.org
Mon Nov 7 13:23:34 PST 2005


Committed by: cworth

Update of /cvs/cairo/cairo/src
In directory gabe:/tmp/cvs-serv25627/src

Modified Files:
	cairo-array.c cairo-font-subset.c cairo-meta-surface.c 
	cairo-pattern.c cairoint.h 
Log Message:

2005-11-07  Carl Worth  <cworth at cworth.org>

        * src/cairoint.h:
        * src/cairo-array.c: (_cairo_array_append_multiple),
        (_cairo_array_allocate): Add new _cairo_array_allocate function
        for growing the array and getting a pointer to the buffer of new
        data. This is intended to be used in place of the abuse of passing
        data=NULL to _cairo_array_append_multiple.

        * src/cairo-font-subset.c:
        (cairo_pdf_ft_font_allocate_write_buffer): Add new function to be
        used instead of the abuse of pasing data=NULL to
        cairo_pdf_ft_font_write.

        * src/cairo-font-subset.c: (cairo_pdf_ft_font_write): Just return
        a status now instead of a pointer to the written buffer, since
        cairo_pdf_ft_font_allocate_write_buffer should now be used
        instead when a pointer is needed.

        * src/cairo-font-subset.c:
        (cairo_pdf_ft_font_align_output),
        (cairo_pdf_ft_font_write_generic_table),
        (cairo_pdf_ft_font_write_glyf_table),
        (cairo_pdf_ft_font_write_hmtx_table),
        (cairo_pdf_ft_font_write_offset_table): Switch to use
        cairo_pdf_ft_font_allocate_write_buffer.

        * src/cairo-meta-surface.c: (_init_pattern_with_snapshot): Fix use
        of uninitialized status value.

        * src/cairo-pattern.c (_cairo_pattern_get_extents): Add (not
        strictly necessary) initialization just to keep the compiler quiet
        about possibly uninitialized variables.


Index: cairo-array.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-array.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- cairo-array.c	5 Nov 2005 00:13:31 -0000	1.7
+++ cairo-array.c	7 Nov 2005 21:23:32 -0000	1.8
@@ -169,10 +169,10 @@
 /**
  * _cairo_array_append:
  * 
- * Append 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:
+ * 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);
  *
@@ -192,10 +192,7 @@
  * 
  * 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. The address of the first data object
- * within the array can be determined with:
- *
- * _cairo_array_index (array, _cairo_array_num_elements (array) - num_elements);
+ * @elements into the array.
  *
  * Return value: CAIRO_STATUS_SUCCESS if successful or
  * CAIRO_STATUS_NO_MEMORY if insufficient memory is available for the
@@ -209,16 +206,43 @@
     cairo_status_t status;
     void *dest;
 
+    status = _cairo_array_allocate (array, num_elements, &dest);
+    if (status)
+	return status;
+
+    memcpy (dest, elements, num_elements * array->element_size);
+
+    return CAIRO_STATUS_SUCCESS;
+}
+
+/**
+ * _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
+ * CAIRO_STATUS_NO_MEMORY if insufficient memory is available for the
+ * operation.
+ **/
+cairo_status_t
+_cairo_array_allocate (cairo_array_t	 *array,
+		       int		  num_elements,
+		       void		**elements)
+{
+    cairo_status_t status;
+
     status = _cairo_array_grow_by (array, num_elements);
     if (status)
 	return status;
 
     assert (array->num_elements + num_elements <= array->size);
 
-    dest = &array->elements[array->num_elements * array->element_size];
-    array->num_elements += num_elements;
+    *elements = &array->elements[array->num_elements * array->element_size];
 
-    memcpy (dest, elements, num_elements * array->element_size);
+    array->num_elements += num_elements;
 
     return CAIRO_STATUS_SUCCESS;
 }

Index: cairo-font-subset.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-font-subset.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- cairo-font-subset.c	5 Nov 2005 00:13:31 -0000	1.6
+++ cairo-font-subset.c	7 Nov 2005 21:23:32 -0000	1.7
@@ -231,7 +231,21 @@
     free (font);
 }
 
-static void *
+static cairo_status_t
+cairo_pdf_ft_font_allocate_write_buffer (cairo_pdf_ft_font_t	 *font,
+					 size_t			  length,
+					 unsigned char		**buffer)
+{
+    cairo_status_t status;
+
+    status = _cairo_array_allocate (&font->output, length, (void **) buffer);
+    if (status)
+	return status;
+
+    return CAIRO_STATUS_SUCCESS;
+}
+
+static cairo_status_t
 cairo_pdf_ft_font_write (cairo_pdf_ft_font_t *font,
 			 const void *data, size_t length)
 {
@@ -239,10 +253,9 @@
 
     status = _cairo_array_append_multiple (&font->output, data, length);
     if (status)
-	return NULL;
+	return status;
 
-    return _cairo_array_index (&font->output,
-			       _cairo_array_num_elements (&font->output) - length);
+    return CAIRO_STATUS_SUCCESS;
 }
 
 static void
@@ -267,12 +280,15 @@
 static unsigned long
 cairo_pdf_ft_font_align_output (cairo_pdf_ft_font_t *font)
 {
-    int length, aligned;
-    static const char pad[4];
+    int length, aligned, pad;
+    unsigned char *ignored;
 
     length = _cairo_array_num_elements (&font->output);
     aligned = (length + 3) & ~3;
-    cairo_pdf_ft_font_write (font, pad, aligned - length);
+    pad = aligned - length;
+
+    if (pad)
+	cairo_pdf_ft_font_allocate_write_buffer (font, pad, &ignored);
 
     return aligned;
 }
@@ -306,12 +322,14 @@
 cairo_pdf_ft_font_write_generic_table (cairo_pdf_ft_font_t *font,
 				       unsigned long tag)
 {
+    cairo_status_t status;
     unsigned char *buffer;
     unsigned long size;
 
     size = 0;
     FT_Load_Sfnt_Table (font->face, tag, 0, NULL, &size);
-    buffer = cairo_pdf_ft_font_write (font, NULL, size);
+    status = cairo_pdf_ft_font_allocate_write_buffer (font, size, &buffer);
+    /* XXX: Need to check status here. */
     FT_Load_Sfnt_Table (font->face, tag, 0, buffer, &size);
     
     return 0;
@@ -377,6 +395,7 @@
 cairo_pdf_ft_font_write_glyf_table (cairo_pdf_ft_font_t *font,
 				    unsigned long tag)
 {
+    cairo_status_t status;
     unsigned long start_offset, index, size;
     TT_Header *header;
     unsigned long begin, end;
@@ -417,8 +436,8 @@
 
 	font->glyphs[i].location =
 	    cairo_pdf_ft_font_align_output (font) - start_offset;
-	buffer = cairo_pdf_ft_font_write (font, NULL, size);
-	if (buffer == NULL)
+	status = cairo_pdf_ft_font_allocate_write_buffer (font, size, &buffer);
+	if (status)
 	    break;
         if (size != 0) {
             FT_Load_Sfnt_Table (font->face, TTAG_glyf, begin, buffer, &size);
@@ -507,13 +526,16 @@
 cairo_pdf_ft_font_write_hmtx_table (cairo_pdf_ft_font_t *font,
 				    unsigned long tag)
 {
+    cairo_status_t status;
     unsigned long entry_size;
     short *p;
     int i;
 
     for (i = 0; i < font->base.num_glyphs; i++) {
 	entry_size = 2 * sizeof (short);
-	p = cairo_pdf_ft_font_write (font, NULL, entry_size);
+	status = cairo_pdf_ft_font_allocate_write_buffer (font, entry_size,
+							  (unsigned char **) &p);
+	/* XXX: Need to check status here. */
 	FT_Load_Sfnt_Table (font->face, TTAG_hmtx, 
 			    font->glyphs[i].parent_index * entry_size,
 			    (FT_Byte *) p, &entry_size);
@@ -598,6 +620,9 @@
 static cairo_status_t
 cairo_pdf_ft_font_write_offset_table (cairo_pdf_ft_font_t *font)
 {
+    cairo_status_t status;
+    unsigned char *table_buffer;
+    size_t table_buffer_length;
     unsigned short search_range, entry_selector, range_shift;
     int num_tables;
 
@@ -617,7 +642,14 @@
     cairo_pdf_ft_font_write_be16 (font, entry_selector);
     cairo_pdf_ft_font_write_be16 (font, range_shift);
 
-    cairo_pdf_ft_font_write (font, NULL, ARRAY_LENGTH (truetype_tables) * 16);
+    /* XXX: Why are we allocating a table here and then ignoring the
+     * returned buffer? This should result in garbage in the output
+     * file, correct? Is this just unfinished code? -cworth. */
+    table_buffer_length = ARRAY_LENGTH (truetype_tables) * 16;
+    status = cairo_pdf_ft_font_allocate_write_buffer (font, table_buffer_length,
+						      &table_buffer);
+    if (status)
+	return status;
 
     return font->status;
 }    

Index: cairo-meta-surface.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-meta-surface.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- cairo-meta-surface.c	5 Nov 2005 00:13:31 -0000	1.15
+++ cairo-meta-surface.c	7 Nov 2005 21:23:32 -0000	1.16
@@ -131,8 +131,6 @@
 _init_pattern_with_snapshot (cairo_pattern_t       *pattern,
 			     const cairo_pattern_t *other)
 {
-    cairo_status_t status;
-
     _cairo_pattern_init_copy (pattern, other);
 
     if (pattern->type == CAIRO_PATTERN_SURFACE) {
@@ -143,8 +141,8 @@
 
 	cairo_surface_destroy (surface);
 
-	if (status)
-	    return status;
+	if (surface_pattern->surface->status)
+	    return surface_pattern->surface->status;
     }
 
     return CAIRO_STATUS_SUCCESS;

Index: cairo-pattern.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-pattern.c,v
retrieving revision 1.69
retrieving revision 1.70
diff -u -d -r1.69 -r1.70
--- cairo-pattern.c	29 Oct 2005 03:49:59 -0000	1.69
+++ cairo-pattern.c	7 Nov 2005 21:23:32 -0000	1.70
@@ -1653,7 +1653,8 @@
 	cairo_surface_t *surface = surface_pattern->surface;
 	cairo_matrix_t imatrix;
 	double x, y;
-	int left, right, top, bottom;
+	/* Initialize to keep the compiler quiet. */
+	int left=0, right=0, top=0, bottom=0;
 	int lx, rx, ty, by;
 	int sx, sy;
 	cairo_bool_t set = FALSE;

Index: cairoint.h
===================================================================
RCS file: /cvs/cairo/cairo/src/cairoint.h,v
retrieving revision 1.226
retrieving revision 1.227
diff -u -d -r1.226 -r1.227
--- cairoint.h	7 Nov 2005 17:49:52 -0000	1.226
+++ cairoint.h	7 Nov 2005 21:23:32 -0000	1.227
@@ -336,8 +336,14 @@
 _cairo_array_append (cairo_array_t *array, const void *element);
 
 cairo_private cairo_status_t
-_cairo_array_append_multiple (cairo_array_t *array,
-			      const void *elements, int num_elements);
+_cairo_array_append_multiple (cairo_array_t	*array,
+			      const void	*elements,
+			      int		 num_elements);
+
+cairo_status_t
+_cairo_array_allocate (cairo_array_t	 *array,
+		       int		  num_elements,
+		       void		**elements);
 
 cairo_private void *
 _cairo_array_index (cairo_array_t *array, int index);



More information about the cairo-commit mailing list