summaryrefslogtreecommitdiffstats
path: root/src/sp-ellipse.cpp
diff options
context:
space:
mode:
authorMatthew Petroff <matthew@mpetroff.net>2013-09-02 19:51:04 +0000
committerMatthew Petroff <matthew@mpetroff.net>2013-09-02 19:51:04 +0000
commit632414c7cdd5f8992c6d6439d25128b82e93d499 (patch)
treecf5b544e03b0b165e8c6fe68e9345d6259f73e62 /src/sp-ellipse.cpp
parentForgot to remove "share/ui/units.txt" from "share/ui/Makefile.am". (diff)
downloadinkscape-632414c7cdd5f8992c6d6439d25128b82e93d499.tar.gz
inkscape-632414c7cdd5f8992c6d6439d25128b82e93d499.zip
Fix bug that added transforms to new objects.
(bzr r12475.1.11)
Diffstat (limited to 'src/sp-ellipse.cpp')
-rw-r--r--src/sp-ellipse.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/sp-ellipse.cpp b/src/sp-ellipse.cpp
index bf019fb13..52c5cd07c 100644
--- a/src/sp-ellipse.cpp
+++ b/src/sp-ellipse.cpp
@@ -67,6 +67,7 @@ static double sp_round(double x, double y)
static void sp_genericellipse_update(SPObject *object, SPCtx *ctx, guint flags);
static void sp_genericellipse_snappoints(SPItem const *item, std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs);
+static Geom::Affine sp_genericellipse_set_transform(SPItem *item, Geom::Affine const &xform);
static void sp_genericellipse_set_shape(SPShape *shape);
static void sp_genericellipse_update_patheffect (SPLPEItem *lpeitem, bool write);
@@ -89,6 +90,7 @@ static void sp_genericellipse_class_init(SPGenericEllipseClass *klass)
sp_object_class->write = sp_genericellipse_write;
item_class->snappoints = sp_genericellipse_snappoints;
+ item_class->set_transform = sp_genericellipse_set_transform;
shape_class->set_shape = sp_genericellipse_set_shape;
lpe_item_class->update_patheffect = sp_genericellipse_update_patheffect;
@@ -314,6 +316,64 @@ static void sp_genericellipse_snappoints(SPItem const *item, std::vector<Inkscap
}
}
+static Geom::Affine sp_genericellipse_set_transform(SPItem *item, Geom::Affine const &xform)
+{
+ g_assert(item != NULL);
+ g_assert(SP_IS_GENERICELLIPSE(item));
+
+ SPGenericEllipse *ellipse = SP_GENERICELLIPSE(item);
+
+ /* Calculate ellipse start in parent coords. */
+ Geom::Point pos( Geom::Point(ellipse->cx.computed, ellipse->cy.computed) * xform );
+
+ /* This function takes care of translation and scaling, we return whatever parts we can't
+ handle. */
+ Geom::Affine ret(Geom::Affine(xform).withoutTranslation());
+ gdouble const sw = hypot(ret[0], ret[1]);
+ gdouble const sh = hypot(ret[2], ret[3]);
+ if (sw > 1e-9) {
+ ret[0] /= sw;
+ ret[1] /= sw;
+ } else {
+ ret[0] = 1.0;
+ ret[1] = 0.0;
+ }
+ if (sh > 1e-9) {
+ ret[2] /= sh;
+ ret[3] /= sh;
+ } else {
+ ret[2] = 0.0;
+ ret[3] = 1.0;
+ }
+
+ if (ellipse->rx._set) {
+ ellipse->rx = ellipse->rx.computed * sw;
+ }
+ if (ellipse->ry._set) {
+ ellipse->ry = ellipse->ry.computed * sh;
+ }
+
+ /* Find start in item coords */
+ pos = pos * ret.inverse();
+ ellipse->cx = pos[Geom::X];
+ ellipse->cy = pos[Geom::Y];
+
+ sp_genericellipse_set_shape(ellipse);
+
+ // Adjust stroke width
+ item->adjust_stroke(sqrt(fabs(sw * sh)));
+
+ // Adjust pattern fill
+ item->adjust_pattern(xform * ret.inverse());
+
+ // Adjust gradient fill
+ item->adjust_gradient(xform * ret.inverse());
+
+ item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
+
+ return ret;
+}
+
void
sp_genericellipse_normalize(SPGenericEllipse *ellipse)
{