Пример #1
0
/**
 * rsvg_css_parse_vbox
 * @vbox: The CSS viewBox
 * @x : The X output
 * @y: The Y output
 * @w: The Width output
 * @h: The Height output
 *
 * Returns: 
 */
RsvgViewBox
rsvg_css_parse_vbox (const char *vbox)
{
    RsvgViewBox vb;
    gdouble *list;
    guint list_len;
    vb.active = FALSE;

    vb.x = vb.y = 0;
    vb.w = vb.h = 0;

    list = rsvg_css_parse_number_list (vbox, &list_len);

    if (!(list && list_len))
        return vb;
    else if (list_len != 4) {
        g_free (list);
        return vb;
    } else {
        vb.x = list[0];
        vb.y = list[1];
        vb.w = list[2];
        vb.h = list[3];
        vb.active = TRUE;

        g_free (list);
        return vb;
    }
}
Пример #2
0
static cairo_path_t *
_rsvg_node_poly_build_path (const char *value,
                            gboolean close_path)
{
    double *pointlist;
    guint pointlist_len, i;
    RsvgPathBuilder builder;
    cairo_path_t *path;

    pointlist = rsvg_css_parse_number_list (value, &pointlist_len);
    if (pointlist == NULL)
        return NULL;

    if (pointlist_len < 2) {
        g_free (pointlist);
        return NULL;
    }

    /* Calculate the number of cairo_path_data_t we'll need:
     *
     *     pointlist_len / 2 -> number of commands
     *     pointlist_len / 2 -> number of points
     * +   1                 -> closepath
     * ---------------------------------------------
     *     pointlist_len + 1 -> total
     */
    rsvg_path_builder_init (&builder, pointlist_len + 1);

    rsvg_path_builder_move_to (&builder, pointlist[0], pointlist[1]);

    for (i = 2; i < pointlist_len; i += 2) {
        double x, y;

        x = pointlist[i];

        /* We expect points to come in coordinate pairs.  But if there is a
         * missing part of one pair in a corrupt SVG, we'll have an incomplete
         * list.  In that case, we reuse the last-known Y coordinate.
         */
        if (i + 1 < pointlist_len)
            y = pointlist[i + 1];
        else
            y = pointlist[i - 1];

        rsvg_path_builder_line_to (&builder, x, y);
    }

    if (close_path)
        rsvg_path_builder_close_path (&builder);

    path = rsvg_path_builder_finish (&builder);
    g_free (pointlist);

    return path;
}