Ejemplo n.º 1
0
struct PrPath *prParseSvgPath(size_t length, const char *pathString)
{
    struct ParseData d;
    
    kvec_uchar_t commands;
    kvec_float_t coords;

    kv_init(commands);
    kv_init(coords);

    d.str = pathString;

    if (!setjmp(d.buf))
        parse(&d, &commands, &coords);
    else
        return NULL;

    struct PrPath *svgPath = (struct PrPath*)malloc(sizeof(struct PrPath));

    if (kv_empty(commands))
    {
        svgPath->numCommands = 0;
        svgPath->commands = NULL;
    }
    else
    {
        svgPath->numCommands = kv_size(commands);
        svgPath->commands = (unsigned char*)malloc(svgPath->numCommands * sizeof(unsigned char));
        memcpy(svgPath->commands, kv_data(commands), svgPath->numCommands * sizeof(unsigned char));
    }

    if (kv_empty(coords))
    {
        svgPath->numCoords = 0;
        svgPath->coords = NULL;
    }
    else
    {
        svgPath->numCoords = kv_size(coords);
        svgPath->coords = (float*)malloc(svgPath->numCoords * sizeof(float));
        memcpy(svgPath->coords, kv_data(coords), svgPath->numCoords * sizeof(float));
    }

    return svgPath;
}
Ejemplo n.º 2
0
void
kv_attr(struct writer *w, const char *tag, const char *descr, const char *value)
{
	if (!strcmp(tag, "name") || !strcmp(tag, "type")) {
		/* Special case for name, replace the last prefix */
		kv_end(w);
		kv_start(w, value, NULL);
	} else {
		kv_start(w, tag, NULL);
		kv_data(w, value);
		kv_end(w);
	}
}