diff options
| -rw-r--r-- | src/knot-holder-entity.cpp | 11 | ||||
| -rw-r--r-- | src/object/sp-item-group.cpp | 18 | ||||
| -rw-r--r-- | src/object/sp-item.cpp | 34 | ||||
| -rw-r--r-- | src/object/sp-item.h | 5 |
4 files changed, 46 insertions, 22 deletions
diff --git a/src/knot-holder-entity.cpp b/src/knot-holder-entity.cpp index afa51a9ad..36d4053ef 100644 --- a/src/knot-holder-entity.cpp +++ b/src/knot-holder-entity.cpp @@ -352,8 +352,17 @@ void HatchKnotHolderEntityScale::knot_set(Geom::Point const &p, Geom::Point cons Geom::Point d = p_snapped * transform_inverse; Geom::Point d_origin = origin * transform_inverse; Geom::Point origin_dt; + gdouble hatch_pitch = hatch->pitch(); + if (state & GDK_CONTROL_MASK) { + // if ctrl is pressed: use 1:1 scaling + d = d_origin * (d.length() / d_origin.length()); + } + + Geom::Affine scale = Geom::Translate(-origin_dt) * Geom::Scale(d.x() / hatch_pitch, d.y() / hatch_pitch) * + Geom::Translate(origin_dt) * transform; - // TODO ??? + item->adjust_hatch(scale, true, _fill ? TRANSFORM_FILL : TRANSFORM_STROKE); + item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } /* Filter manipulation */ diff --git a/src/object/sp-item-group.cpp b/src/object/sp-item-group.cpp index 981308b0e..77608d4cb 100644 --- a/src/object/sp-item-group.cpp +++ b/src/object/sp-item-group.cpp @@ -486,7 +486,7 @@ sp_item_group_ungroup (SPGroup *group, std::vector<SPItem*> &children, bool do_d || !strcmp (grepr->name(), "svg:svg")); // this converts the gradient/pattern fill/stroke on the group, if any, to userSpaceOnUse - group->adjust_paint_recursive (Geom::identity(), Geom::identity(), false); + group->adjust_paint_recursive(Geom::identity(), Geom::identity()); SPItem *pitem = dynamic_cast<SPItem *>(group->parent); g_assert(pitem); @@ -518,7 +518,7 @@ sp_item_group_ungroup (SPGroup *group, std::vector<SPItem*> &children, bool do_d /* Merging of style */ // this converts the gradient/pattern fill/stroke, if any, to userSpaceOnUse; we need to do // it here _before_ the new transform is set, so as to use the pre-transform bbox - citem->adjust_paint_recursive (Geom::identity(), Geom::identity(), false); + citem->adjust_paint_recursive(Geom::identity(), Geom::identity()); child.style->merge( group->style ); /* @@ -613,7 +613,7 @@ sp_item_group_ungroup (SPGroup *group, std::vector<SPItem*> &children, bool do_d if (!objects.empty()) { Inkscape::XML::Node *last_def = defs->getRepr()->lastChild(); for (auto i=objects.rbegin();i!=objects.rend();++i) { - Inkscape::XML::Node *repr = *i; + Inkscape::XML::Node *repr = *i; if (!sp_repr_is_meta_element(repr)) { defs->getRepr()->addChild(repr, last_def); } @@ -753,7 +753,7 @@ void SPGroup::scaleChildItemsRec(Geom::Scale const &sc, Geom::Point const &p, bo } else if ( SPItem *item = dynamic_cast<SPItem *>(&o) ) { SPGroup *group = dynamic_cast<SPGroup *>(item); if (group && !dynamic_cast<SPBox3D *>(item)) { - /* Using recursion breaks clipping because transforms are applied + /* Using recursion breaks clipping because transforms are applied in coordinates for draws but nothing in defs is changed instead change the transform on the entire group, and the transform is applied after any references to clipping paths. However NOT using @@ -769,7 +769,7 @@ void SPGroup::scaleChildItemsRec(Geom::Scale const &sc, Geom::Point const &p, bo item->set_i2d_affine(tAff); tAff = item->transform; // Eliminate common rounding error affecting EMF/WMF input. - // When the rounding error persists it converts the simple + // When the rounding error persists it converts the simple // transform=scale() to transform=matrix(). if(std::abs(tAff[4]) < 1.0e-5 && std::abs(tAff[5]) < 1.0e-5){ tAff[4] = 0.0; @@ -801,7 +801,7 @@ void SPGroup::scaleChildItemsRec(Geom::Scale const &sc, Geom::Point const &p, bo // Scale item Geom::Translate const s(p); Geom::Affine final = s.inverse() * sc * s; - + gchar const *conn_type = nullptr; SPText *text_item = dynamic_cast<SPText *>(item); bool is_text_path = text_item && text_item->firstChild() && dynamic_cast<SPTextPath *>(text_item->firstChild()); @@ -825,7 +825,7 @@ void SPGroup::scaleChildItemsRec(Geom::Scale const &sc, Geom::Point const &p, bo } } } - + Persp3D *persp = dynamic_cast<Persp3D *>(item); if (persp) { persp3d_apply_affine_transformation(persp, final); @@ -848,11 +848,11 @@ void SPGroup::scaleChildItemsRec(Geom::Scale const &sc, Geom::Point const &p, bo } else { item->doWriteTransform(item->transform*sc, nullptr, true); } - + if (conn_type != nullptr) { item->setAttribute("inkscape:connector-type", conn_type); } - + if (item->isCenterSet() && !(final.isTranslation() || final.isIdentity())) { item->scaleCenter(sc); // All coordinates have been scaled, so also the center must be scaled item->updateRepr(); diff --git a/src/object/sp-item.cpp b/src/object/sp-item.cpp index 003562269..d12d8e465 100644 --- a/src/object/sp-item.cpp +++ b/src/object/sp-item.cpp @@ -1404,7 +1404,7 @@ sp_item_adjust_rects_recursive(SPItem *item, Geom::Affine advertized_transform) } } -void SPItem::adjust_paint_recursive (Geom::Affine advertized_transform, Geom::Affine t_ancestors, bool is_pattern) +void SPItem::adjust_paint_recursive(Geom::Affine advertized_transform, Geom::Affine t_ancestors, PaintServerType type) { // _Before_ full pattern/gradient transform: t_paint * t_item * t_ancestors // _After_ full pattern/gradient transform: t_paint_new * t_item * t_ancestors * advertised_transform @@ -1419,9 +1419,9 @@ void SPItem::adjust_paint_recursive (Geom::Affine advertized_transform, Geom::Af for (auto& o: children) { SPItem *item = dynamic_cast<SPItem *>(&o); if (item) { -// At the level of the transformed item, t_ancestors is identity; -// below it, it is the accumulated chain of transforms from this level to the top level - item->adjust_paint_recursive (advertized_transform, t_item * t_ancestors, is_pattern); + // At the level of the transformed item, t_ancestors is identity; + // below it, it is the accumulated chain of transforms from this level to the top level + item->adjust_paint_recursive(advertized_transform, t_item * t_ancestors, type); } } } @@ -1431,10 +1431,18 @@ void SPItem::adjust_paint_recursive (Geom::Affine advertized_transform, Geom::Af // and paintservers on leaves inheriting their values from ancestors could adjust themselves properly // before ancestors themselves are adjusted, probably differently (bug 1286535) - if (is_pattern) { - adjust_pattern(paint_delta); - } else { - adjust_gradient(paint_delta); + switch (type) { + case PATTERN: { + adjust_pattern(paint_delta); + break; + } + case HATCH: { + adjust_hatch(paint_delta); + break; + } + default: { + adjust_gradient(paint_delta); + } } } @@ -1483,16 +1491,20 @@ void SPItem::doWriteTransform(Geom::Affine const &transform, Geom::Affine const // recursively compensate pattern fill if it's not to be transformed if (!prefs->getBool("/options/transform/pattern", true)) { - adjust_paint_recursive (advertized_transform.inverse(), Geom::identity(), true); + adjust_paint_recursive(advertized_transform.inverse(), Geom::identity(), PATTERN); } + if (!prefs->getBool("/options/transform/hatch", true)) { + adjust_paint_recursive(advertized_transform.inverse(), Geom::identity(), HATCH); + } + /// \todo FIXME: add the same else branch as for gradients below, to convert patterns to userSpaceOnUse as well /// recursively compensate gradient fill if it's not to be transformed if (!prefs->getBool("/options/transform/gradient", true)) { - adjust_paint_recursive (advertized_transform.inverse(), Geom::identity(), false); + adjust_paint_recursive(advertized_transform.inverse(), Geom::identity(), GRADIENT); } else { // this converts the gradient/pattern fill/stroke, if any, to userSpaceOnUse; we need to do // it here _before_ the new transform is set, so as to use the pre-transform bbox - adjust_paint_recursive (Geom::identity(), Geom::identity(), false); + adjust_paint_recursive(Geom::identity(), Geom::identity(), GRADIENT); } } // endif(compensate) diff --git a/src/object/sp-item.h b/src/object/sp-item.h index 04f0f5fd7..37faf999b 100644 --- a/src/object/sp-item.h +++ b/src/object/sp-item.h @@ -137,6 +137,8 @@ public: VISUAL_BBOX }; + enum PaintServerType { PATTERN, HATCH, GRADIENT }; + SPItem(); ~SPItem() override; @@ -332,7 +334,8 @@ public: /** * Recursively compensate pattern or gradient transform. */ - void adjust_paint_recursive(Geom::Affine advertized_transform, Geom::Affine t_ancestors, bool is_pattern); + void adjust_paint_recursive(Geom::Affine advertized_transform, Geom::Affine t_ancestors, + PaintServerType type = GRADIENT); /** * Set a new transform on an object. |
