revert to the old implementation that is ugly but should work more

2003-09-19  Sven Neumann  <sven@gimp.org>

	* app/vectors/gimpvectors-import.c (parse_svg_viewbox): revert to
	the old implementation that is ugly but should work more reliably
	in locales that use ',' as the decimal separator. Disable rendering
	of elements with a zero viewBox.
	(parse_svg_length): fixed handling of width and height parameters.
This commit is contained in:
Sven Neumann
2003-09-19 17:14:05 +00:00
committed by Sven Neumann
parent 2ff5fc7b72
commit dad3321ea6
2 changed files with 62 additions and 30 deletions

View File

@ -1,3 +1,11 @@
2003-09-19 Sven Neumann <sven@gimp.org>
* app/vectors/gimpvectors-import.c (parse_svg_viewbox): revert to
the old implementation that is ugly but should work more reliably
in locales that use ',' as the decimal separator. Disable rendering
of elements with a zero viewBox.
(parse_svg_length): fixed handling of width and height parameters.
2003-09-19 Sven Neumann <sven@gimp.org> 2003-09-19 Sven Neumann <sven@gimp.org>
* plug-ins/common/svg.c (load_image): do not rely on librsvg * plug-ins/common/svg.c (load_image): do not rely on librsvg

View File

@ -131,8 +131,8 @@ static gboolean parse_svg_length (const gchar *value,
gdouble *scale, gdouble *scale,
gdouble *length); gdouble *length);
static gboolean parse_svg_viewbox (const gchar *value, static gboolean parse_svg_viewbox (const gchar *value,
gdouble width, gdouble *width,
gdouble height, gdouble *height,
GimpMatrix3 *matrix); GimpMatrix3 *matrix);
static gboolean parse_svg_transform (const gchar *value, static gboolean parse_svg_transform (const gchar *value,
GimpMatrix3 *matrix); GimpMatrix3 *matrix);
@ -273,7 +273,8 @@ svg_parser_start_element (GMarkupParseContext *context,
handler = g_new0 (SvgHandler, 1); handler = g_new0 (SvgHandler, 1);
base = g_queue_peek_head (parser->stack); base = g_queue_peek_head (parser->stack);
if (!base->width || !base->height) /* if the element is not rendered, always use the generic handler */
if (base->width <= 0.0 || base->height <= 0.0)
i = G_N_ELEMENTS (svg_handlers); i = G_N_ELEMENTS (svg_handlers);
for (; i < G_N_ELEMENTS (svg_handlers); i++) for (; i < G_N_ELEMENTS (svg_handlers); i++)
@ -388,9 +389,6 @@ svg_handler_svg (SvgHandler *handler,
values++; values++;
} }
handler->width = w;
handler->height = h;
gimp_matrix3_scale (matrix, xscale, yscale); gimp_matrix3_scale (matrix, xscale, yscale);
if (x || y) if (x || y)
@ -402,8 +400,13 @@ svg_handler_svg (SvgHandler *handler,
gimp_matrix3_translate (matrix, x, y); gimp_matrix3_translate (matrix, x, y);
} }
if (viewbox && parse_svg_viewbox (viewbox, w, h, &box)) if (viewbox && parse_svg_viewbox (viewbox, &w, &h, &box))
gimp_matrix3_mult (&box, matrix); {
gimp_matrix3_mult (&box, matrix);
}
handler->width = w;
handler->height = h;
handler->transform = matrix; handler->transform = matrix;
} }
@ -544,7 +547,7 @@ parse_svg_length (const gchar *value,
default: default:
len = len / gimp_unit_get_factor (unit) * resolution; len = len / gimp_unit_get_factor (unit) * resolution;
case GIMP_UNIT_PIXEL: case GIMP_UNIT_PIXEL:
*scale = len / reference; *scale = 1.0;
*length = len; *length = len;
break; break;
} }
@ -554,36 +557,57 @@ parse_svg_length (const gchar *value,
static gboolean static gboolean
parse_svg_viewbox (const gchar *value, parse_svg_viewbox (const gchar *value,
gdouble width, gdouble *width,
gdouble height, gdouble *height,
GimpMatrix3 *matrix) GimpMatrix3 *matrix)
{ {
gdouble args[4]; gdouble x, y, w, h;
gchar *ptr; gchar *tok;
gint i; gchar *str = g_strdup (value);
gboolean success = FALSE;
for (i = 0; *value && i < 4; i++) x = y = w = h = 0;
tok = strtok (str, ", \t");
if (tok)
{ {
args[i] = g_ascii_strtod (value, &ptr); x = g_ascii_strtod (tok, NULL);
tok = strtok (NULL, ", \t");
while (*ptr == ',' || g_ascii_isspace (*ptr)) if (tok)
ptr++; {
y = g_ascii_strtod (tok, NULL);
value = ptr; tok = strtok (NULL, ", \t");
if (tok != NULL)
{
w = g_ascii_strtod (tok, NULL);
tok = strtok (NULL, ", \t");
if (tok)
{
h = g_ascii_strtod (tok, NULL);
success = TRUE;
}
}
}
} }
if (i < 4) g_free (str);
return FALSE;
gimp_matrix3_identity (matrix); if (success)
{
gimp_matrix3_identity (matrix);
gimp_matrix3_translate (matrix, x, y);
if (args[0] || args[1]) if (w > 0.0 && h > 0.0)
gimp_matrix3_translate (matrix, args[0], args[1]); {
gimp_matrix3_scale (matrix, *width / w, *height / h);
}
else /* disable rendering of the element */
{
*width = *height = 0.0;
}
}
if (args[2] && args[3]) return success;
gimp_matrix3_scale (matrix, width / args[2], height / args[3]);
return TRUE;
} }
gboolean gboolean