[dia] svg: improved viewBox interpretation
- From: Hans Breuer <hans src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia] svg: improved viewBox interpretation
- Date: Sun, 1 Sep 2013 13:13:00 +0000 (UTC)
commit dc61e85f3e7cf83a064e903900810ef44e5de282
Author: Hans Breuer <hans breuer org>
Date: Sun Sep 1 15:00:28 2013 +0200
svg: improved viewBox interpretation
- respect the viewBox attribute including floats and
typical SVG number separators
- improve round-trip by only using viewBox width and
height to calculate the user scale
plug-ins/svg/svg-import.c | 29 +++++++++++++++++++++++------
1 files changed, 23 insertions(+), 6 deletions(-)
---
diff --git a/plug-ins/svg/svg-import.c b/plug-ins/svg/svg-import.c
index 8193dc9..331fa7a 100644
--- a/plug-ins/svg/svg-import.c
+++ b/plug-ins/svg/svg-import.c
@@ -1184,17 +1184,34 @@ _node_read_viewbox (xmlNodePtr root, DiaMatrix **mat)
xmlChar *sviewbox = xmlGetProp(root, (const xmlChar *)"viewBox");
if (swidth && sheight && sviewbox) {
- real width = get_value_as_cm ((const char *)swidth, NULL);
- real height = get_value_as_cm ((const char *)sheight, NULL);
- gint x1 = 0, y1 = 0, x2 = 0, y2 = 0;
+ real width, height;
+ gchar *remains = NULL;
+ gboolean percent;
+ gchar **vals;
- if (4 == sscanf ((const char *)sviewbox, "%d %d %d %d", &x1, &y1, &x2, &y2)) {
+ width = get_value_as_cm ((const char *)swidth, &remains);
+ percent = (remains && *remains == '%');
+ height = get_value_as_cm ((const char *)sheight, &remains);
+ percent |= (remains && *remains == '%');
+ vals = g_regex_split_simple ("[\\s,;]+", (const char *)sviewbox, 0, 0);
+
+ if (vals && vals[0] && vals[1] && vals[2] && vals[3]) {
+ real x1, y1, x2, y2;
real xs, ys;
+ x1 = g_ascii_strtod (vals[0], NULL);
+ y1 = g_ascii_strtod (vals[1], NULL);
+ x2 = g_ascii_strtod (vals[2], NULL);
+ y2 = g_ascii_strtod (vals[3], NULL);
g_debug ("viewBox(%d %d %d %d) = (%f,%f)\n", x1, y1, x2, y2, width, height);
/* some basic sanity check */
if (x2 > x1 && y2 > y1 && width > 0 && height > 0) {
- xs = ((real)x2 - x1) / width;
- ys = ((real)y2 - y1) / height;
+ if (!percent) {
+ /* viwBox is x-min y-min width height - so only use the latter for scaling */
+ xs = (real)x2 / width;
+ ys = (real)y2 / height;
+ } else {
+ xs = ys = DEFAULT_SVG_SCALE * (100.0 / sqrt(width*height));
+ }
/* plausibility check, strictly speaking these are not required to be the same
* /or/ are they and Dia is writting a bogus viewBox?
*/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]