Exemplo n.º 1
0
svgint_status_t
_svg_str_parse_all_csv_doubles (const char *str, double **value, int *num_values, const char **end)
{
    static const int growth=5;
    svgint_status_t status;
    int size = 0;
    *num_values = 0;
    *value = NULL;

    while (1) {
	if (*num_values >= size) {
	    size = *num_values + growth;
	    *value = realloc(*value, size * sizeof(double));
	    if (*value == NULL)
		status = SVG_STATUS_NO_MEMORY;
	}

	status = _svg_str_parse_csv_doubles (str, *value + *num_values, 1, end);
	if (status)
	    break;

	(*num_values)++;
	str = *end;
    }

    if (status == SVGINT_STATUS_ARGS_EXHAUSTED)
	status = SVG_STATUS_SUCCESS;
    
    return status;
}
Exemplo n.º 2
0
static svg_status_t
_svg_parser_parse_polyline (svg_parser_t	*parser,
			    const char	**attributes,
			    svg_element_t	**path_element)
{
    svg_status_t status;
    const char *points;
    const char *p, *next;
    svg_path_t *path;
    double pt[2];
    int first;

    _svg_attribute_get_string (attributes, "points", &points, NULL);

    if (points == NULL)
		return SVG_STATUS_PARSE_ERROR;

    status = _svg_parser_new_leaf_element (parser,
										   path_element,
										   SVG_ELEMENT_TYPE_PATH);
    if (status)
		return status;
    path = &(*path_element)->e.path;

    first = 1;
    p = points;
    while (*p) {
		status = _svg_str_parse_csv_doubles (p, pt, 2, &next);
		if (status)
			return SVG_STATUS_PARSE_ERROR;
		
		if (first) {
			_svg_path_move_to (path, pt[0], pt[1]);
			first = 0;
		} else {
			_svg_path_line_to (path, pt[0], pt[1]);
		}

		p = next;
		_svg_str_skip_space (&p);
    }

    return SVG_STATUS_SUCCESS;
}