Back to index

lightning-sunbird  0.9+nobinonly
Classes | Typedefs | Functions | Variables
cairo-path-data.c File Reference
#include "cairo-path-data-private.h"
#include "cairo-path-fixed-private.h"
#include "cairo-gstate-private.h"

Go to the source code of this file.

Classes

struct  cairo_path_data_count
struct  cairo_path_data_populate

Typedefs

typedef struct
cairo_path_data_count 
cpdc_t
typedef struct
cairo_path_data_populate 
cpdp_t

Functions

static cairo_status_t _cpdc_move_to (void *closure, cairo_point_t *point)
static cairo_status_t _cpdc_line_to (void *closure, cairo_point_t *point)
static cairo_status_t _cpdc_curve_to (void *closure, cairo_point_t *p1, cairo_point_t *p2, cairo_point_t *p3)
static cairo_status_t _cpdc_curve_to_flatten (void *closure, cairo_point_t *p1, cairo_point_t *p2, cairo_point_t *p3)
static cairo_status_t _cpdc_close_path (void *closure)
static int _cairo_path_data_count (cairo_path_t *path, cairo_path_fixed_t *path_fixed, double tolerance, cairo_bool_t flatten)
static cairo_status_t _cpdp_move_to (void *closure, cairo_point_t *point)
static cairo_status_t _cpdp_line_to (void *closure, cairo_point_t *point)
static cairo_status_t _cpdp_curve_to (void *closure, cairo_point_t *p1, cairo_point_t *p2, cairo_point_t *p3)
static cairo_status_t _cpdp_curve_to_flatten (void *closure, cairo_point_t *p1, cairo_point_t *p2, cairo_point_t *p3)
static cairo_status_t _cpdp_close_path (void *closure)
static void _cairo_path_data_populate (cairo_path_t *path, cairo_path_fixed_t *path_fixed, cairo_gstate_t *gstate, cairo_bool_t flatten)
static cairo_path_t_cairo_path_data_create_real (cairo_path_fixed_t *path_fixed, cairo_gstate_t *gstate, cairo_bool_t flatten)
void cairo_path_destroy (cairo_path_t *path)
 cairo_path_destroy: : a path previously returned by either cairo_copy_path() or cairo_copy_path_flat().
cairo_path_t_cairo_path_data_create (cairo_path_fixed_t *path, cairo_gstate_t *gstate)
 _cairo_path_data_create: : a fixed-point, device-space path to be converted and copied : the current graphics state
cairo_path_t_cairo_path_data_create_flat (cairo_path_fixed_t *path, cairo_gstate_t *gstate)
 _cairo_path_data_create_flat: : a fixed-point, device-space path to be flattened, converted and copied : the current graphics state
cairo_status_t _cairo_path_data_append_to_context (cairo_path_t *path, cairo_t *cr)
 _cairo_path_data_append_to_context: : the path data to be appended : a cairo context

Variables

const cairo_path_t _cairo_path_nil = { CAIRO_STATUS_NO_MEMORY, NULL, 0 }

Class Documentation

struct cairo_path_data_count

Definition at line 43 of file cairo-path-data.c.

Collaboration diagram for cairo_path_data_count:
Class Members
int count
cairo_point_t current_point
double tolerance
struct cairo_path_data_populate

Definition at line 161 of file cairo-path-data.c.

Collaboration diagram for cairo_path_data_populate:
Class Members
cairo_point_t current_point
cairo_path_data_t * data
cairo_gstate_t * gstate

Typedef Documentation

typedef struct cairo_path_data_count cpdc_t

Function Documentation

_cairo_path_data_append_to_context: : the path data to be appended : a cairo context

Append to the current path within .

Return value: CAIRO_STATUS_INVALID_PATH_DATA if the data in is invalid, and CAIRO_STATUS_SUCCESS otherwise.

Definition at line 447 of file cairo-path-data.c.

{
    int i;
    cairo_path_data_t *p;

    for (i=0; i < path->num_data; i += path->data[i].header.length) {
       p = &path->data[i];
       switch (p->header.type) {
       case CAIRO_PATH_MOVE_TO:
           if (p->header.length != 2)
              return CAIRO_STATUS_INVALID_PATH_DATA;
           cairo_move_to (cr,
                        p[1].point.x, p[1].point.y);
           break;
       case CAIRO_PATH_LINE_TO:
           if (p->header.length != 2)
              return CAIRO_STATUS_INVALID_PATH_DATA;
           cairo_line_to (cr,
                        p[1].point.x, p[1].point.y);
           break;
       case CAIRO_PATH_CURVE_TO:
           if (p->header.length != 4)
              return CAIRO_STATUS_INVALID_PATH_DATA;
           cairo_curve_to (cr,
                         p[1].point.x, p[1].point.y,
                         p[2].point.x, p[2].point.y,
                         p[3].point.x, p[3].point.y);
           break;
       case CAIRO_PATH_CLOSE_PATH:
           if (p->header.length != 1)
              return CAIRO_STATUS_INVALID_PATH_DATA;
           cairo_close_path (cr);
           break;
       default:
           return CAIRO_STATUS_INVALID_PATH_DATA;
       }
    }

    return CAIRO_STATUS_SUCCESS;
}

Here is the caller graph for this function:

static int _cairo_path_data_count ( cairo_path_t path,
cairo_path_fixed_t *  path_fixed,
double  tolerance,
cairo_bool_t  flatten 
) [static]

Definition at line 135 of file cairo-path-data.c.

Here is the call graph for this function:

Here is the caller graph for this function:

cairo_path_t* _cairo_path_data_create ( cairo_path_fixed_t *  path,
cairo_gstate_t *  gstate 
)

_cairo_path_data_create: : a fixed-point, device-space path to be converted and copied : the current graphics state

Creates a user-space cairo_path_t copy of the given device-space . The 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.

Definition at line 408 of file cairo-path-data.c.

Here is the call graph for this function:

Here is the caller graph for this function:

cairo_path_t* _cairo_path_data_create_flat ( cairo_path_fixed_t *  path,
cairo_gstate_t *  gstate 
)

_cairo_path_data_create_flat: : a fixed-point, device-space path to be flattened, converted and copied : the current graphics state

Creates a flattened, user-space cairo_path_t copy of the given device-space . The 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.

Definition at line 430 of file cairo-path-data.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static cairo_path_t* _cairo_path_data_create_real ( cairo_path_fixed_t *  path_fixed,
cairo_gstate_t *  gstate,
cairo_bool_t  flatten 
) [static]

Definition at line 341 of file cairo-path-data.c.

{
    cairo_path_t *path;

    path = malloc (sizeof (cairo_path_t));
    if (path == NULL)
       return (cairo_path_t*) &_cairo_path_nil;

    path->num_data = _cairo_path_data_count (path, path_fixed,
                                        gstate->tolerance, flatten);

    path->data = malloc (path->num_data * sizeof (cairo_path_data_t));
    if (path->data == NULL) {
       free (path);
       return (cairo_path_t*) &_cairo_path_nil;
    }

    path->status = CAIRO_STATUS_SUCCESS;

    _cairo_path_data_populate (path, path_fixed,
                            gstate, flatten);

    return path;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void _cairo_path_data_populate ( cairo_path_t path,
cairo_path_fixed_t *  path_fixed,
cairo_gstate_t *  gstate,
cairo_bool_t  flatten 
) [static]

Definition at line 314 of file cairo-path-data.c.

{
    cpdp_t cpdp;

    cpdp.data = path->data;
    cpdp.gstate = gstate;
    cpdp.current_point.x = 0;
    cpdp.current_point.y = 0;

    _cairo_path_fixed_interpret (path_fixed,
                             CAIRO_DIRECTION_FORWARD,
                             _cpdp_move_to,
                             _cpdp_line_to,
                             flatten ?
                             _cpdp_curve_to_flatten :
                             _cpdp_curve_to,
                             _cpdp_close_path,
                             &cpdp);

    /* Sanity check the count */
    assert (cpdp.data - path->data == path->num_data);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static cairo_status_t _cpdc_close_path ( void closure) [static]

Definition at line 122 of file cairo-path-data.c.

{
    cpdc_t *cpdc = closure;

    cpdc->count += 1;

    cpdc->current_point.x = 0;
    cpdc->current_point.y = 0;

    return CAIRO_STATUS_SUCCESS;
}

Here is the caller graph for this function:

static cairo_status_t _cpdc_curve_to ( void closure,
cairo_point_t p1,
cairo_point_t p2,
cairo_point_t p3 
) [static]

Definition at line 74 of file cairo-path-data.c.

{
    cpdc_t *cpdc = closure;

    cpdc->count += 4;

    cpdc->current_point = *p3;

    return CAIRO_STATUS_SUCCESS;
}

Here is the caller graph for this function:

static cairo_status_t _cpdc_curve_to_flatten ( void closure,
cairo_point_t p1,
cairo_point_t p2,
cairo_point_t p3 
) [static]

Definition at line 89 of file cairo-path-data.c.

{
    cpdc_t *cpdc = closure;
    cairo_status_t status;
    cairo_spline_t spline;
    int i;

    cairo_point_t *p0 = &cpdc->current_point;

    status = _cairo_spline_init (&spline, p0, p1, p2, p3);
    if (status == CAIRO_INT_STATUS_DEGENERATE)
       return CAIRO_STATUS_SUCCESS;

    status = _cairo_spline_decompose (&spline, cpdc->tolerance);
    if (status)
      goto out;

    for (i=1; i < spline.num_points; i++)
       _cpdc_line_to (cpdc, &spline.points[i]);

    cpdc->current_point = *p3;

    status = CAIRO_STATUS_SUCCESS;

 out:
    _cairo_spline_fini (&spline);
    return status;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static cairo_status_t _cpdc_line_to ( void closure,
cairo_point_t point 
) [static]

Definition at line 62 of file cairo-path-data.c.

{
    cpdc_t *cpdc = closure;

    cpdc->count += 2;

    cpdc->current_point = *point;

    return CAIRO_STATUS_SUCCESS;
}

Here is the caller graph for this function:

static cairo_status_t _cpdc_move_to ( void closure,
cairo_point_t point 
) [static]

Definition at line 50 of file cairo-path-data.c.

{
    cpdc_t *cpdc = closure;

    cpdc->count += 2;

    cpdc->current_point = *point;

    return CAIRO_STATUS_SUCCESS;
}

Here is the caller graph for this function:

static cairo_status_t _cpdp_close_path ( void closure) [static]

Definition at line 297 of file cairo-path-data.c.

{
    cpdp_t *cpdp = closure;
    cairo_path_data_t *data = cpdp->data;

    data->header.type = CAIRO_PATH_CLOSE_PATH;
    data->header.length = 1;

    cpdp->data += data->header.length;

    cpdp->current_point.x = 0;
    cpdp->current_point.y = 0;

    return CAIRO_STATUS_SUCCESS;
}

Here is the caller graph for this function:

static cairo_status_t _cpdp_curve_to ( void closure,
cairo_point_t p1,
cairo_point_t p2,
cairo_point_t p3 
) [static]

Definition at line 220 of file cairo-path-data.c.

{
    cpdp_t *cpdp = closure;
    cairo_path_data_t *data = cpdp->data;
    double x1, y1;
    double x2, y2;
    double x3, y3;

    x1 = _cairo_fixed_to_double (p1->x);
    y1 = _cairo_fixed_to_double (p1->y);
    _cairo_gstate_backend_to_user (cpdp->gstate, &x1, &y1);

    x2 = _cairo_fixed_to_double (p2->x);
    y2 = _cairo_fixed_to_double (p2->y);
    _cairo_gstate_backend_to_user (cpdp->gstate, &x2, &y2);

    x3 = _cairo_fixed_to_double (p3->x);
    y3 = _cairo_fixed_to_double (p3->y);
    _cairo_gstate_backend_to_user (cpdp->gstate, &x3, &y3);

    data->header.type = CAIRO_PATH_CURVE_TO;
    data->header.length = 4;

    /* We index from 1 to leave room for data->header */
    data[1].point.x = x1;
    data[1].point.y = y1;

    data[2].point.x = x2;
    data[2].point.y = y2;

    data[3].point.x = x3;
    data[3].point.y = y3;

    cpdp->data += data->header.length;

    cpdp->current_point = *p3;

    return CAIRO_STATUS_SUCCESS;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static cairo_status_t _cpdp_curve_to_flatten ( void closure,
cairo_point_t p1,
cairo_point_t p2,
cairo_point_t p3 
) [static]

Definition at line 264 of file cairo-path-data.c.

{
    cpdp_t *cpdp = closure;
    cairo_status_t status;
    cairo_spline_t spline;
    int i;

    cairo_point_t *p0 = &cpdp->current_point;

    status = _cairo_spline_init (&spline, p0, p1, p2, p3);
    if (status == CAIRO_INT_STATUS_DEGENERATE)
       return CAIRO_STATUS_SUCCESS;

    status = _cairo_spline_decompose (&spline, cpdp->gstate->tolerance);
    if (status)
      goto out;

    for (i=1; i < spline.num_points; i++)
       _cpdp_line_to (cpdp, &spline.points[i]);

    cpdp->current_point = *p3;

    status = CAIRO_STATUS_SUCCESS;

 out:
    _cairo_spline_fini (&spline);
    return status;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static cairo_status_t _cpdp_line_to ( void closure,
cairo_point_t point 
) [static]

Definition at line 194 of file cairo-path-data.c.

{
    cpdp_t *cpdp = closure;
    cairo_path_data_t *data = cpdp->data;
    double x, y;

    x = _cairo_fixed_to_double (point->x);
    y = _cairo_fixed_to_double (point->y);

    _cairo_gstate_backend_to_user (cpdp->gstate, &x, &y);

    data->header.type = CAIRO_PATH_LINE_TO;
    data->header.length = 2;

    /* We index from 1 to leave room for data->header */
    data[1].point.x = x;
    data[1].point.y = y;

    cpdp->data += data->header.length;

    cpdp->current_point = *point;

    return CAIRO_STATUS_SUCCESS;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static cairo_status_t _cpdp_move_to ( void closure,
cairo_point_t point 
) [static]

Definition at line 168 of file cairo-path-data.c.

{
    cpdp_t *cpdp = closure;
    cairo_path_data_t *data = cpdp->data;
    double x, y;

    x = _cairo_fixed_to_double (point->x);
    y = _cairo_fixed_to_double (point->y);

    _cairo_gstate_backend_to_user (cpdp->gstate, &x, &y);

    data->header.type = CAIRO_PATH_MOVE_TO;
    data->header.length = 2;

    /* We index from 1 to leave room for data->header */
    data[1].point.x = x;
    data[1].point.y = y;

    cpdp->data += data->header.length;

    cpdp->current_point = *point;

    return CAIRO_STATUS_SUCCESS;
}

Here is the call graph for this function:

Here is the caller graph for this function:

cairo_path_destroy: : a path previously returned by either cairo_copy_path() or cairo_copy_path_flat().

Immediately releases all memory associated with . After a call to cairo_path_destroy() the pointer is no longer valid and should not be used further.

NOTE: cairo_path_destroy function 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.

Definition at line 383 of file cairo-path-data.c.

{
    if (path == NULL || path == &_cairo_path_nil)
       return;

    free (path->data);
    path->num_data = 0;
    free (path);
}

Variable Documentation

Definition at line 40 of file cairo-path-data.c.