summaryrefslogtreecommitdiffstats
path: root/src/svg
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2015-02-02 20:08:49 +0000
committerJabiertxof <jtx@jtx.marker.es>2015-02-02 20:08:49 +0000
commit1d3b98e5f5311479cd87f20e3656b0133bff73bd (patch)
tree95eea2fcac18f236b31053e4d1493aa644760df0 /src/svg
parentupdate to trunk (diff)
parentTranslations. Arabic translation update. (diff)
downloadinkscape-1d3b98e5f5311479cd87f20e3656b0133bff73bd.tar.gz
inkscape-1d3b98e5f5311479cd87f20e3656b0133bff73bd.zip
update to trunk
(bzr r13645.1.4)
Diffstat (limited to 'src/svg')
-rw-r--r--src/svg/stringstream-test.h6
-rw-r--r--src/svg/svg-affine-test.h14
-rw-r--r--src/svg/svg-affine.cpp157
-rw-r--r--src/svg/svg-angle.cpp4
-rw-r--r--src/svg/svg-color.cpp2
-rw-r--r--src/svg/svg-length-test.h14
-rw-r--r--src/svg/svg-length.cpp5
-rw-r--r--src/svg/svg-length.h1
8 files changed, 127 insertions, 76 deletions
diff --git a/src/svg/stringstream-test.h b/src/svg/stringstream-test.h
index ce32683f8..305cf6b8d 100644
--- a/src/svg/stringstream-test.h
+++ b/src/svg/stringstream-test.h
@@ -37,9 +37,9 @@ public:
svg_test_float(-0.0625, "-0.0625");
svg_test_float(30.0, "30");
svg_test_float(12345678.0, "12345678");
- svg_test_float(3e9, "3e+09");
- svg_test_float(-3.5e9, "-3.5e+09");
- svg_test_float(32768e9, "3.2768e+13");
+ svg_test_float(3e9, "3e+009");
+ svg_test_float(-3.5e9, "-3.5e+009");
+ svg_test_float(32768e9, "3.2768e+013");
svg_test_float(-10.5, "-10.5");
}
diff --git a/src/svg/svg-affine-test.h b/src/svg/svg-affine-test.h
index 11b9012a8..af670a3a8 100644
--- a/src/svg/svg-affine-test.h
+++ b/src/svg/svg-affine-test.h
@@ -34,8 +34,8 @@ private:
static char const * const read_fail_tests[25];
static test_t const write_matrix_tests[2];
static test_t const write_translate_tests[3];
- static test_t const write_scale_tests[2];
- static test_t const write_rotate_tests[2];
+ static test_t const write_scale_tests[3];
+ static test_t const write_rotate_tests[3];
static test_t const write_skew_tests[3];
public:
SvgAffineTest() {
@@ -238,16 +238,18 @@ SvgAffineTest::test_t const SvgAffineTest::write_translate_tests[3] = {
{"translate(1,1)",Geom::Affine(1,0,0,1,1,1)},
{"translate(1)",Geom::Affine(1,0,0,1,1,0)},
{"translate(-1345,0.123)",Geom::Affine(1,0,0,1,-1.345e3,.123)}};
-SvgAffineTest::test_t const SvgAffineTest::write_scale_tests[2] = {
+SvgAffineTest::test_t const SvgAffineTest::write_scale_tests[3] = {
{"scale(0)",Geom::Affine(0,0,0,0,0,0)},
+ {"scale(7)",Geom::Affine(7,0,0,7,0,0)},
{"scale(2,3)",Geom::Affine(2,0,0,3,0,0)}};
-SvgAffineTest::test_t const SvgAffineTest::write_rotate_tests[2] = {
+SvgAffineTest::test_t const SvgAffineTest::write_rotate_tests[3] = {
{"rotate(13)",Geom::Affine(cos(13.*DEGREE),sin(13.*DEGREE),-sin(13.*DEGREE),cos(13.*DEGREE),0,0)},
- {"rotate(-13,7,11)",Geom::Affine(cos(-13.*DEGREE),sin(-13.*DEGREE),-sin(-13.*DEGREE),cos(-13.*DEGREE),(1-cos(-13.*DEGREE))*7+sin(-13.*DEGREE)*11,(1-cos(-13.*DEGREE))*11-sin(-13.*DEGREE)*7)}};
+ {"rotate(-13,7,11)",Geom::Affine(cos(-13.*DEGREE),sin(-13.*DEGREE),-sin(-13.*DEGREE),cos(-13.*DEGREE),(1-cos(-13.*DEGREE))*7+sin(-13.*DEGREE)*11,(1-cos(-13.*DEGREE))*11-sin(-13.*DEGREE)*7)},
+ {"rotate(-34.5,6.7,89)",Geom::Affine(cos(-34.5*DEGREE),sin(-34.5*DEGREE),-sin(-34.5*DEGREE),cos(-34.5*DEGREE),(1-cos(-34.5*DEGREE))*6.7+sin(-34.5*DEGREE)*89,(1-cos(-34.5*DEGREE))*89-sin(-34.5*DEGREE)*6.7)}};
SvgAffineTest::test_t const SvgAffineTest::write_skew_tests[3] = {
{"skewX(30)",Geom::Affine(1,0,tan(30.*DEGREE),1,0,0)},
{"skewX(-30)",Geom::Affine(1,0,tan(-30.*DEGREE),1,0,0)},
- {"skewY(390)",Geom::Affine(1,tan(30.*DEGREE),0,1,0,0)}};
+ {"skewY(30)",Geom::Affine(1,tan(30.*DEGREE),0,1,0,0)}};
/*
Local Variables:
diff --git a/src/svg/svg-affine.cpp b/src/svg/svg-affine.cpp
index 44567a2bd..c853f9930 100644
--- a/src/svg/svg-affine.cpp
+++ b/src/svg/svg-affine.cpp
@@ -162,65 +162,105 @@ sp_svg_transform_write(Geom::Affine const &transform)
int prec = prefs->getInt("/options/svgoutput/numericprecision", 8);
int min_exp = prefs->getInt("/options/svgoutput/minimumexponent", -8);
- /* fixme: We could use t1 * t1 + t2 * t2 here instead */
- if ( Geom::are_near(transform[1], 0.0, e) && Geom::are_near (transform[2], 0.0, e)) {
- if (Geom::are_near (transform[4], 0.0, e) && Geom::are_near (transform[5], 0.0, e)) {
- if (Geom::are_near (transform[0], 1.0, e) && Geom::are_near (transform[3], 1.0, e)) {
- /* We are more or less identity */
- return NULL;
- } else {
- /* We are more or less scale */
- gchar c[256];
- unsigned p = 0;
- strcpy (c + p, "scale(");
- p += 6;
- p += sp_svg_number_write_de( c + p, sizeof(c) - p, transform[0], prec, min_exp );
- c[p++] = ',';
- p += sp_svg_number_write_de( c + p, sizeof(c) - p, transform[3], prec, min_exp );
- c[p++] = ')';
- c[p] = '\000';
- g_assert( p <= sizeof(c) );
- return g_strdup(c);
- }
+ // Special case: when all fields of the affine are zero,
+ // the optimized transformation is scale(0)
+ if (transform[0] == 0 && transform[1] == 0 && transform[2] == 0 &&
+ transform[3] == 0 && transform[4] == 0 && transform[5] == 0)
+ {
+ return g_strdup("scale(0)");
+ }
+
+ // FIXME legacy C code!
+ // the function sp_svg_number_write_de is stopping me from using a proper C++ string
+
+ gchar c[256]; // string buffer
+ unsigned p = 0; // position in the buffer
+
+ if (transform.isIdentity()) {
+ // We are more or less identity, so no transform attribute needed:
+ return NULL;
+ } else if (transform.isScale()) {
+ // We are more or less a uniform scale
+ strcpy (c + p, "scale(");
+ p += 6;
+ p += sp_svg_number_write_de( c + p, sizeof(c) - p, transform[0], prec, min_exp );
+ if (Geom::are_near(transform[0], transform[3], e)) {
+ c[p++] = ')';
+ c[p] = '\000';
} else {
- if (Geom::are_near (transform[0], 1.0, e) && Geom::are_near (transform[3], 1.0, e)) {
- /* We are more or less translate */
- gchar c[256];
- unsigned p = 0;
- strcpy (c + p, "translate(");
- p += 10;
- p += sp_svg_number_write_de( c + p, sizeof(c) - p, transform[4], prec, min_exp );
- c[p++] = ',';
- p += sp_svg_number_write_de( c + p, sizeof(c) - p, transform[5], prec, min_exp );
- c[p++] = ')';
- c[p] = '\000';
- g_assert( p <= sizeof(c) );
- return g_strdup(c);
- } else {
- gchar c[256];
- unsigned p = 0;
- strcpy (c + p, "matrix(");
- p += 7;
- p += sp_svg_number_write_de( c + p, sizeof(c) - p, transform[0], prec, min_exp );
- c[p++] = ',';
- p += sp_svg_number_write_de( c + p, sizeof(c) - p, transform[1], prec, min_exp );
- c[p++] = ',';
- p += sp_svg_number_write_de( c + p, sizeof(c) - p, transform[2], prec, min_exp );
- c[p++] = ',';
- p += sp_svg_number_write_de( c + p, sizeof(c) - p, transform[3], prec, min_exp );
- c[p++] = ',';
- p += sp_svg_number_write_de( c + p, sizeof(c) - p, transform[4], prec, min_exp );
- c[p++] = ',';
- p += sp_svg_number_write_de( c + p, sizeof(c) - p, transform[5], prec, min_exp );
- c[p++] = ')';
- c[p] = '\000';
- g_assert( p <= sizeof(c) );
- return g_strdup(c);
- }
+ c[p++] = ',';
+ p += sp_svg_number_write_de( c + p, sizeof(c) - p, transform[3], prec, min_exp );
+ c[p++] = ')';
+ c[p] = '\000';
}
+ } else if (transform.isTranslation()) {
+ // We are more or less a pure translation
+ strcpy (c + p, "translate(");
+ p += 10;
+ p += sp_svg_number_write_de( c + p, sizeof(c) - p, transform[4], prec, min_exp );
+ if (Geom::are_near(transform[5], 0.0, e)) {
+ c[p++] = ')';
+ c[p] = '\000';
+ } else {
+ c[p++] = ',';
+ p += sp_svg_number_write_de( c + p, sizeof(c) - p, transform[5], prec, min_exp );
+ c[p++] = ')';
+ c[p] = '\000';
+ }
+ } else if (transform.isRotation()) {
+ // We are more or less a pure rotation
+ strcpy(c + p, "rotate(");
+ p += 7;
+
+ double angle = std::atan2(transform[1], transform[0]) * (180 / M_PI);
+ p += sp_svg_number_write_de(c + p, sizeof(c) - p, angle, prec, min_exp);
+
+ c[p++] = ')';
+ c[p] = '\000';
+ } else if (transform.withoutTranslation().isRotation()) {
+ // Solution found by Johan Engelen
+ // Refer to the matrix in svg-affine-test.h
+
+ // We are a rotation about a special axis
+ strcpy(c + p, "rotate(");
+ p += 7;
+
+ double angle = std::atan2(transform[1], transform[0]) * (180 / M_PI);
+ p += sp_svg_number_write_de(c + p, sizeof(c) - p, angle, prec, min_exp);
+ c[p++] = ',';
+
+ Geom::Affine const& m = transform;
+ double tx = (m[2]*m[5]+m[4]-m[4]*m[3]) / (1-m[3]-m[0]+m[0]*m[3]-m[2]*m[1]);
+ p += sp_svg_number_write_de(c + p, sizeof(c) - p, tx, prec, min_exp);
+
+ c[p++] = ',';
+
+ double ty = (m[1]*tx + m[5]) / (1 - m[3]);
+ p += sp_svg_number_write_de(c + p, sizeof(c) - p, ty, prec, min_exp);
+
+ c[p++] = ')';
+ c[p] = '\000';
+ } else if (transform.isHShear()) {
+ // We are more or less a pure skewX
+ strcpy(c + p, "skewX(");
+ p += 6;
+
+ double angle = atan(transform[2]) * (180 / M_PI);
+ p += sp_svg_number_write_de(c + p, sizeof(c) - p, angle, prec, min_exp);
+
+ c[p++] = ')';
+ c[p] = '\000';
+ } else if (transform.isVShear()) {
+ // We are more or less a pure skewY
+ strcpy(c + p, "skewY(");
+ p += 6;
+
+ double angle = atan(transform[1]) * (180 / M_PI);
+ p += sp_svg_number_write_de(c + p, sizeof(c) - p, angle, prec, min_exp);
+
+ c[p++] = ')';
+ c[p] = '\000';
} else {
- gchar c[256];
- unsigned p = 0;
strcpy (c + p, "matrix(");
p += 7;
p += sp_svg_number_write_de( c + p, sizeof(c) - p, transform[0], prec, min_exp );
@@ -236,9 +276,10 @@ sp_svg_transform_write(Geom::Affine const &transform)
p += sp_svg_number_write_de( c + p, sizeof(c) - p, transform[5], prec, min_exp );
c[p++] = ')';
c[p] = '\000';
- g_assert( p <= sizeof(c) );
- return g_strdup(c);
}
+
+ assert(p <= sizeof(c));
+ return g_strdup(c);
}
diff --git a/src/svg/svg-angle.cpp b/src/svg/svg-angle.cpp
index 63152368e..ed5ccd45e 100644
--- a/src/svg/svg-angle.cpp
+++ b/src/svg/svg-angle.cpp
@@ -104,15 +104,19 @@ static bool sp_svg_angle_read_lff(gchar const *str, SVGAngle::Unit &unit, float
} else {
if (strncmp(e, "deg", 3) == 0) {
unit = SVGAngle::DEG;
+ val = v;
computed = v;
} else if (strncmp(e, "grad", 4) == 0) {
unit = SVGAngle::GRAD;
+ val = v;
computed = Inkscape::Util::Quantity::convert(v, "grad", "°");
} else if (strncmp(e, "rad", 3) == 0) {
unit = SVGAngle::RAD;
+ val = v;
computed = Inkscape::Util::Quantity::convert(v, "rad", "°");
} else if (strncmp(e, "turn", 4) == 0) {
unit = SVGAngle::TURN;
+ val = v;
computed = Inkscape::Util::Quantity::convert(v, "turn", "°");
} else {
return false;
diff --git a/src/svg/svg-color.cpp b/src/svg/svg-color.cpp
index c9f22f8a4..693094048 100644
--- a/src/svg/svg-color.cpp
+++ b/src/svg/svg-color.cpp
@@ -32,8 +32,8 @@
#include "svg-color.h"
#include "svg-icc-color.h"
-#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
#include "color.h"
+#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
#include "color-profile.h"
#include "document.h"
#include "inkscape.h"
diff --git a/src/svg/svg-length-test.h b/src/svg/svg-length-test.h
index 81a28c9e7..796943e45 100644
--- a/src/svg/svg-length-test.h
+++ b/src/svg/svg-length-test.h
@@ -164,13 +164,13 @@ SvgLengthTest::test_t const SvgLengthTest::absolute_tests[12] = {
{"1.00001", SVGLength::NONE, 1.00001 , 1.00001},
{"1px", SVGLength::PX , 1 , 1},
{".1px", SVGLength::PX , 0.1 , 0.1},
- {"100pt", SVGLength::PT , 100 , 125},
- {"1e2pt", SVGLength::PT , 100 , 125},
- {"3pc", SVGLength::PC , 3 , 45},
- {"-3.5pc", SVGLength::PC , -3.5 , -3.5*15.},
- {"1.2345678mm", SVGLength::MM , 1.2345678, 1.2345678*3.543307}, // TODO: More precise constants? (a 7 digit constant when the default precision is 8 digits?)
- {"123.45678cm", SVGLength::CM , 123.45678 , 123.45678*35.43307},
- {"73.162987in", SVGLength::INCH, 73.162987 , 73.162987*90}};
+ {"100pt", SVGLength::PT , 100 , 400.0/3.0},
+ {"1e2pt", SVGLength::PT , 100 , 400.0/3.0},
+ {"3pc", SVGLength::PC , 3 , 48},
+ {"-3.5pc", SVGLength::PC , -3.5 , -3.5*16.0},
+ {"1.2345678mm", SVGLength::MM , 1.2345678, 1.2345678f*96.0/25.4}, // TODO: More precise constants? (a 7 digit constant when the default precision is 8 digits?)
+ {"123.45678cm", SVGLength::CM , 123.45678 , 123.45678f*96.0/2.54}, // Note that svg_length_read is casting the result from g_ascii_strtod to float.
+ {"73.162987in", SVGLength::INCH, 73.162987 , 73.162987f*96.0/1.00}};
SvgLengthTest::test_t const SvgLengthTest::relative_tests[3] = {
{"123em", SVGLength::EM, 123, 123. * 7.},
{"123ex", SVGLength::EX, 123, 123. * 13.},
diff --git a/src/svg/svg-length.cpp b/src/svg/svg-length.cpp
index b9b475f4b..ea235b2e4 100644
--- a/src/svg/svg-length.cpp
+++ b/src/svg/svg-length.cpp
@@ -520,7 +520,8 @@ gchar const *sp_svg_length_get_css_units(SVGLength::Unit unit)
case SVGLength::MM: return "mm";
case SVGLength::CM: return "cm";
case SVGLength::INCH: return "in";
- case SVGLength::FOOT: return ""; // Does not have a "foot" unit string in the SVG spec
+ case SVGLength::FOOT: return ""; // Not in SVG/CSS specification.
+ case SVGLength::MITRE: return ""; // Not in SVG/CSS specification.
case SVGLength::EM: return "em";
case SVGLength::EX: return "ex";
case SVGLength::PERCENT: return "%";
@@ -539,6 +540,8 @@ std::string sp_svg_length_write_with_units(SVGLength const &length)
os << 100*length.value << sp_svg_length_get_css_units(length.unit);
} else if (length.unit == SVGLength::FOOT) {
os << 12*length.value << sp_svg_length_get_css_units(SVGLength::INCH);
+ } else if (length.unit == SVGLength::MITRE) {
+ os << 100*length.value << sp_svg_length_get_css_units(SVGLength::CM);
} else {
os << length.value << sp_svg_length_get_css_units(length.unit);
}
diff --git a/src/svg/svg-length.h b/src/svg/svg-length.h
index c34905d07..1e6b4c96c 100644
--- a/src/svg/svg-length.h
+++ b/src/svg/svg-length.h
@@ -28,6 +28,7 @@ public:
CM,
INCH,
FOOT,
+ MITRE,
EM,
EX,
PERCENT,