diff options
| author | Matthew Petroff <matthew@mpetroff.net> | 2013-09-02 19:51:04 +0000 |
|---|---|---|
| committer | Matthew Petroff <matthew@mpetroff.net> | 2013-09-02 19:51:04 +0000 |
| commit | 632414c7cdd5f8992c6d6439d25128b82e93d499 (patch) | |
| tree | cf5b544e03b0b165e8c6fe68e9345d6259f73e62 /src | |
| parent | Forgot to remove "share/ui/units.txt" from "share/ui/Makefile.am". (diff) | |
| download | inkscape-632414c7cdd5f8992c6d6439d25128b82e93d499.tar.gz inkscape-632414c7cdd5f8992c6d6439d25128b82e93d499.zip | |
Fix bug that added transforms to new objects.
(bzr r12475.1.11)
Diffstat (limited to 'src')
| -rw-r--r-- | src/arc-context.cpp | 1 | ||||
| -rw-r--r-- | src/connector-context.cpp | 2 | ||||
| -rw-r--r-- | src/draw-context.cpp | 1 | ||||
| -rw-r--r-- | src/dyna-draw-context.cpp | 2 | ||||
| -rw-r--r-- | src/rect-context.cpp | 1 | ||||
| -rw-r--r-- | src/sp-ellipse.cpp | 60 | ||||
| -rw-r--r-- | src/sp-spiral.cpp | 59 | ||||
| -rw-r--r-- | src/sp-star.cpp | 56 | ||||
| -rw-r--r-- | src/spiral-context.cpp | 1 | ||||
| -rw-r--r-- | src/text-context.cpp | 1 |
10 files changed, 184 insertions, 0 deletions
diff --git a/src/arc-context.cpp b/src/arc-context.cpp index 115f45493..ee79933bb 100644 --- a/src/arc-context.cpp +++ b/src/arc-context.cpp @@ -485,6 +485,7 @@ static void sp_arc_finish(SPArcContext *ac) SPDesktop *desktop = SP_EVENT_CONTEXT(ac)->desktop; SP_OBJECT(ac->item)->updateRepr(); + ac->item->doWriteTransform(ac->item->getRepr(), ac->item->transform, NULL, true); desktop->canvas->endForcedFullRedraws(); diff --git a/src/connector-context.cpp b/src/connector-context.cpp index 9468894a0..acff93360 100644 --- a/src/connector-context.cpp +++ b/src/connector-context.cpp @@ -1039,6 +1039,8 @@ spcc_flush_white(SPConnectorContext *cc, SPCurve *gc) cc->newconn->updateRepr(); } + cc->newconn->doWriteTransform(cc->newconn->getRepr(), cc->newconn->transform, NULL, true); + // Only set the selection after we are finished with creating the attributes of // the connector. Otherwise, the selection change may alter the defaults for // values like curvature in the connector context, preventing subsequent lookup diff --git a/src/draw-context.cpp b/src/draw-context.cpp index 869c1ae39..51d8ca3cd 100644 --- a/src/draw-context.cpp +++ b/src/draw-context.cpp @@ -646,6 +646,7 @@ static void spdc_flush_white(SPDrawContext *dc, SPCurve *gc) dc->selection->set(repr); Inkscape::GC::release(repr); item->transform = SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); + item->doWriteTransform(item->getRepr(), item->transform, NULL, true); item->updateRepr(); } diff --git a/src/dyna-draw-context.cpp b/src/dyna-draw-context.cpp index c37f9cb4b..98b0278ae 100644 --- a/src/dyna-draw-context.cpp +++ b/src/dyna-draw-context.cpp @@ -1008,6 +1008,8 @@ set_to_accumulated(SPDynaDrawContext *dc, bool unionize, bool subtract) sp_desktop_selection(desktop)->set(dc->repr); } } + SPItem *item=SP_ITEM(desktop->doc()->getObjectByRepr(dc->repr)); + item->doWriteTransform(item->getRepr(), item->transform, NULL, true); } else { if (dc->repr) { diff --git a/src/rect-context.cpp b/src/rect-context.cpp index 17675745f..a8bc69bff 100644 --- a/src/rect-context.cpp +++ b/src/rect-context.cpp @@ -532,6 +532,7 @@ static void sp_rect_finish(SPRectContext *rc) SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(rc); SP_OBJECT(rc->item)->updateRepr(); + rc->item->doWriteTransform(rc->item->getRepr(), rc->item->transform, NULL, true); desktop->canvas->endForcedFullRedraws(); 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) { diff --git a/src/sp-spiral.cpp b/src/sp-spiral.cpp index 43e552d68..6f3a63f6a 100644 --- a/src/sp-spiral.cpp +++ b/src/sp-spiral.cpp @@ -35,6 +35,7 @@ static void sp_spiral_update (SPObject *object, SPCtx *ctx, guint flags); static gchar * sp_spiral_description (SPItem * item); static void sp_spiral_snappoints(SPItem const *item, std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs); +static Geom::Affine sp_spiral_set_transform(SPItem *item, Geom::Affine const &xform); static void sp_spiral_set_shape (SPShape *shape); static void sp_spiral_update_patheffect (SPLPEItem *lpeitem, bool write); @@ -60,6 +61,7 @@ static void sp_spiral_class_init(SPSpiralClass *klass) item_class->description = sp_spiral_description; item_class->snappoints = sp_spiral_snappoints; + item_class->set_transform = sp_spiral_set_transform; lpe_item_class->update_patheffect = sp_spiral_update_patheffect; @@ -493,6 +495,63 @@ static void sp_spiral_snappoints(SPItem const *item, std::vector<Inkscape::SnapC } /** + * Set spiral transform + */ +static Geom::Affine sp_spiral_set_transform(SPItem *item, Geom::Affine const &xform) +{ + // Only set transform with proportional scaling + if (!xform.withoutTranslation().isUniformScale()) { + return xform; + } + + g_assert(item != NULL); + g_assert(SP_IS_SPIRAL(item)); + + SPSpiral *spiral = SP_SPIRAL(item); + + /* Calculate spiral start in parent coords. */ + Geom::Point pos( Geom::Point(spiral->cx, spiral->cy) * 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 s = hypot(ret[0], ret[1]); + if (s > 1e-9) { + ret[0] /= s; + ret[1] /= s; + ret[2] /= s; + ret[3] /= s; + } else { + ret[0] = 1.0; + ret[1] = 0.0; + ret[2] = 0.0; + ret[3] = 1.0; + } + + spiral->rad *= s; + + /* Find start in item coords */ + pos = pos * ret.inverse(); + spiral->cx = pos[Geom::X]; + spiral->cy = pos[Geom::Y]; + + sp_spiral_set_shape(spiral); + + // Adjust stroke width + item->adjust_stroke(s); + + // 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; +} + +/** * Return one of the points on the spiral. * * \param t specifies how far along the spiral. diff --git a/src/sp-star.cpp b/src/sp-star.cpp index af2420340..afc0b84d6 100644 --- a/src/sp-star.cpp +++ b/src/sp-star.cpp @@ -39,6 +39,7 @@ static void sp_star_update (SPObject *object, SPCtx *ctx, guint flags); static gchar * sp_star_description (SPItem * item); static void sp_star_snappoints(SPItem const *item, std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs); +static Geom::Affine sp_star_set_transform(SPItem *item, Geom::Affine const &xform); static void sp_star_set_shape (SPShape *shape); static void sp_star_update_patheffect (SPLPEItem *lpeitem, bool write); @@ -59,6 +60,7 @@ static void sp_star_class_init(SPStarClass *klass) item_class->description = sp_star_description; item_class->snappoints = sp_star_snappoints; + item_class->set_transform = sp_star_set_transform; lpe_item_class->update_patheffect = sp_star_update_patheffect; @@ -528,6 +530,60 @@ static void sp_star_snappoints(SPItem const *item, std::vector<Inkscape::SnapCan } } +static Geom::Affine sp_star_set_transform(SPItem *item, Geom::Affine const &xform) +{ + // Only set transform with proportional scaling + if (!xform.withoutTranslation().isUniformScale()) { + return xform; + } + + g_assert(item != NULL); + g_assert(SP_IS_STAR(item)); + + SPStar *star = SP_STAR(item); + + /* Calculate star start in parent coords. */ + Geom::Point pos( star->center * 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 s = hypot(ret[0], ret[1]); + if (s > 1e-9) { + ret[0] /= s; + ret[1] /= s; + ret[2] /= s; + ret[3] /= s; + } else { + ret[0] = 1.0; + ret[1] = 0.0; + ret[2] = 0.0; + ret[3] = 1.0; + } + + star->r[0] *= s; + star->r[1] *= s; + + /* Find start in item coords */ + pos = pos * ret.inverse(); + star->center = pos; + + sp_star_set_shape(star); + + // Adjust stroke width + item->adjust_stroke(s); + + // 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; +} + /** * sp_star_get_xy: Get X-Y value as item coordinate system * @star: star item diff --git a/src/spiral-context.cpp b/src/spiral-context.cpp index a6cdc6bc4..df3edae70 100644 --- a/src/spiral-context.cpp +++ b/src/spiral-context.cpp @@ -460,6 +460,7 @@ sp_spiral_finish(SPSpiralContext *sc) SP_SHAPE(spiral)->setShape(); SP_OBJECT(spiral)->updateRepr(SP_OBJECT_WRITE_EXT); + sc->item->doWriteTransform(sc->item->getRepr(), sc->item->transform, NULL, true); desktop->canvas->endForcedFullRedraws(); diff --git a/src/text-context.cpp b/src/text-context.cpp index 719a82156..1ba1bb68b 100644 --- a/src/text-context.cpp +++ b/src/text-context.cpp @@ -477,6 +477,7 @@ static void sp_text_context_setup_text(SPTextContext *tc) text_item->transform = SP_ITEM(ec->desktop->currentLayer())->i2doc_affine().inverse(); text_item->updateRepr(); + text_item->doWriteTransform(text_item->getRepr(), text_item->transform, NULL, true); DocumentUndo::done(sp_desktop_document(ec->desktop), SP_VERB_CONTEXT_TEXT, _("Create text")); } |
