/* very simplistic CSS style parser */ static void svg_parse_gradient_stop_style (SvgStop *stop, const gchar *style) { const gchar *end; const gchar *sep; while (*style) { while (g_ascii_isspace (*style)) style++; for (end = style; *end && *end != ';'; end++) /* do nothing */; for (sep = style; sep < end && *sep != ':'; sep++) /* do nothing */; if (end > sep && sep > style) { gchar *name = g_strndup (style, sep - style); gchar *value = g_strndup (++sep, end - sep - (*end == ';' ? 1 : 0)); svg_parse_gradient_stop_style_prop (stop, name, value); g_free (value); g_free (name); } style = end; if (*style == ';') style++; } }
static SvgStop * svg_parse_gradient_stop (const gchar **names, const gchar **values) { SvgStop *stop = g_slice_new0 (SvgStop); gimp_rgb_set_alpha (&stop->color, 1.0); while (*names && *values) { if (strcmp (*names, "offset") == 0) { gchar *end; stop->offset = g_ascii_strtod (*values, &end); if (end && *end == '%') stop->offset /= 100.0; stop->offset = CLAMP (stop->offset, 0.0, 1.0); } else if (strcmp (*names, "style") == 0) { svg_parse_gradient_stop_style (stop, *values); } else { svg_parse_gradient_stop_style_prop (stop, *names, *values); } names++; values++; } return stop; }