/* Linearize a box set of possibly multiple chunks into one big chunk and returns an array of boxes */
cairo_box_t* _cairo_boxes_to_array(const cairo_boxes_t *boxes, int *num_boxes)
/* Linearize a box set of possibly multiple chunks into one big chunk and returns an array of boxes */
cairo_box_t* _cairo_boxes_to_array(const cairo_boxes_t *boxes, int *num_boxes)
{
    const struct _cairo_boxes_chunk *chunk;
    cairo_box_t *box;
    int i, j;
    *num_boxes = boxes->num_boxes;
    box = _cairo_malloc_ab (boxes->num_boxes, sizeof (cairo_box_t));
    if (box == NULL) {
	_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
	return NULL;
    }
    j = 0;
    for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) {
	for (i = 0; i < chunk->count; i++)
	    box[j++] = chunk->base[i];
    }
    return box;
}