summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJabiertxof <jtx@jtx>2016-12-28 20:26:03 +0000
committerJabiertxof <jtx@jtx>2016-12-28 20:26:03 +0000
commit36860450a9792a2c03f681da06ab06ce902a4223 (patch)
treed1ef15f97c03e365f034ea02f4cefd4b1f0a437b /src
parentadd missing files (diff)
parentFixing scale (diff)
downloadinkscape-36860450a9792a2c03f681da06ab06ce902a4223.tar.gz
inkscape-36860450a9792a2c03f681da06ab06ce902a4223.zip
Some fixes on translations and make legacy compatible
(bzr r15356.1.3)
Diffstat (limited to 'src')
-rw-r--r--src/live_effects/lpe-clone-original.cpp211
-rw-r--r--src/live_effects/lpe-clone-original.h8
-rw-r--r--src/sp-object.cpp1
3 files changed, 122 insertions, 98 deletions
diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp
index be8bc9e0d..7072ad161 100644
--- a/src/live_effects/lpe-clone-original.cpp
+++ b/src/live_effects/lpe-clone-original.cpp
@@ -8,7 +8,6 @@
#include "display/curve.h"
#include "svg/path-string.h"
#include "svg/svg.h"
-#include <boost/algorithm/string.hpp>
#include "xml/sp-css-attr.h"
// TODO due to internal breakage in glibmm headers, this must be last:
@@ -19,25 +18,30 @@ namespace LivePathEffect {
LPECloneOriginal::LPECloneOriginal(LivePathEffectObject *lpeobject) :
Effect(lpeobject),
+ linked_path("LEGACY FALLBACK", "LEGACY FALLBACK", "linkedpath", &wr, this),
linked_item(_("Linked Item:"), _("Item from which to take the original data"), "linked_item", &wr, this),
+ scale(_("Scale %"), _("Scale item %"), "scale", &wr, this, 100.0),
preserve_position(_("Preserve position"), _("Preserve position"), "preserve_position", &wr, this, false),
attributes("Attributes linked", "Attributes linked", "attributes", &wr, this,""),
style_attributes("Style attributes linked", "Style attributes linked", "style_attributes", &wr, this,"")
{
+ registerParameter(&linked_path);
registerParameter(&linked_item);
+ registerParameter(&scale);
registerParameter(&attributes);
registerParameter(&style_attributes);
registerParameter(&preserve_position);
+ scale.param_set_range(0.01, 999999.0);
+ scale.param_set_increments(1, 1);
+ scale.param_set_digits(2);
attributes.param_hide_canvas_text();
style_attributes.param_hide_canvas_text();
apply_to_clippath_and_mask = true;
}
void
-LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * first_attribute, ...)
+LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * attributes, const char * style_attributes)
{
- va_list args;
- va_start(args, first_attribute);
SPDocument * document = SP_ACTIVE_DOCUMENT;
if ( SP_IS_GROUP(origin) && SP_IS_GROUP(dest) && SP_GROUP(origin)->getItemCount() == SP_GROUP(dest)->getItemCount() ) {
std::vector< SPObject * > childs = origin->childList(true);
@@ -45,103 +49,100 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co
for (std::vector<SPObject * >::iterator obj_it = childs.begin();
obj_it != childs.end(); ++obj_it) {
SPObject *dest_child = dest->nthChild(index);
- cloneAttrbutes(*obj_it, dest_child, live, first_attribute, args);
+ cloneAttrbutes(*obj_it, dest_child, live, attributes, style_attributes);
index++;
}
}
+ //Attributes
SPShape * shape_origin = SP_SHAPE(origin);
SPShape * shape_dest = SP_SHAPE(dest);
- for (const char* att = first_attribute; att != NULL; att = va_arg(args, const char*)) {
- std::vector<std::string> elems;
- boost::split(elems, att, boost::is_any_of(","));
- for (std::vector<std::string>::const_iterator atts = elems.begin();
- atts != elems.end(); ++atts) {
- const char* attribute = (*atts).c_str();
- if ( std::strcmp(attribute, "transform") == 0 ) {
- Geom::Affine affine_dest = Geom::identity();
- sp_svg_transform_read(SP_ITEM(dest)->getAttribute("transform"), &affine_dest);
- dest->getRepr()->setAttribute(attribute, origin->getRepr()->attribute(attribute));
- if (preserve_position) {
- Geom::Affine affine_origin = Geom::identity();
- sp_svg_transform_read(SP_ITEM(origin)->getAttribute("transform"), &affine_origin);
- SP_ITEM(dest)->transform = Geom::Translate(affine_dest.translation()) * Geom::Translate(affine_origin.translation()).inverse() * affine_origin;
- }
- } else if ( shape_dest && shape_origin && live && (std::strcmp(attribute, "d") == 0 || std::strcmp(attribute, "inkscape:original-d") == 0)) {
- SPCurve *c = NULL;
- if (std::strcmp(attribute, "d") == 0) {
- c = shape_origin->getCurve();
- } else {
- c = shape_origin->getCurveBeforeLPE();
- }
- if (c) {
- Geom::PathVector c_pv = c->get_pathvector();
+ gchar ** attarray = g_strsplit(attributes, ",", 0);
+ gchar ** iter = attarray;
+ while (*iter != NULL) {
+ const char* attribute = (*iter);
+ if ( std::strcmp(attribute, "transform") == 0 ) {
+ Geom::Affine affine_dest = SP_ITEM(dest)->transform;
+ Geom::Affine affine_origin = SP_ITEM(origin)->transform;
+ //dest->getRepr()->setAttribute(attribute, origin->getRepr()->attribute(attribute));
+ if (preserve_position) {
+ SP_ITEM(dest)->transform = Geom::Translate(affine_dest.translation()) * Geom::Translate(affine_origin.translation()).inverse() * affine_origin ;
+ } else {
+ SP_ITEM(dest)->transform = affine_origin ;
+ }
+ } else if ( shape_dest && shape_origin && live && (std::strcmp(attribute, "d") == 0 || std::strcmp(attribute, "inkscape:original-d") == 0)) {
+ SPCurve *c = NULL;
+ if (std::strcmp(attribute, "d") == 0) {
+ c = shape_origin->getCurve();
+ } else {
+ c = shape_origin->getCurveBeforeLPE();
+ }
+ if (c) {
+ Geom::PathVector c_pv = c->get_pathvector();
+ Geom::OptRect orig_bbox = SP_ITEM(origin)->geometricBounds();
+ if (orig_bbox) {
+ if (scale != 100.0) {
+ double scale_affine = scale/100.0;
+ Geom::Scale scale = Geom::Scale(scale_affine);
+ c_pv *= Geom::Translate((*orig_bbox).midpoint()).inverse();
+ c_pv *= scale;
+ c_pv *= Geom::Translate((*orig_bbox).midpoint());
+ }
if (preserve_position) {
- Geom::OptRect orig_bbox = SP_ITEM(origin)->geometricBounds();
- if (orig_bbox) {
- c_pv *= Geom::Translate(Geom::Point(boundingbox_X.min(), boundingbox_Y.min()) - (*orig_bbox).corner(0));
- }
+ c_pv *= Geom::Translate(Geom::Point(boundingbox_X.middle(), boundingbox_Y.middle()) - (*orig_bbox).midpoint());
}
- c->set_pathvector(c_pv);
- shape_dest->setCurveInsync(c, TRUE);
- dest->getRepr()->setAttribute(attribute, sp_svg_write_path(c_pv));
- c->unref();
- } else {
- dest->getRepr()->setAttribute(attribute, NULL);
}
+ c->set_pathvector(c_pv);
+ shape_dest->setCurveInsync(c, TRUE);
+ dest->getRepr()->setAttribute(attribute, sp_svg_write_path(c_pv));
+ c->unref();
} else {
- dest->getRepr()->setAttribute(attribute, origin->getRepr()->attribute(attribute));
+ dest->getRepr()->setAttribute(attribute, NULL);
}
+ } else {
+ dest->getRepr()->setAttribute(attribute, origin->getRepr()->attribute(attribute));
}
+ iter++;
}
- va_end(args);
-}
+ g_strfreev (attarray);
-void
-LPECloneOriginal::cloneStyleAttrbutes(SPObject *origin, SPObject *dest, const char * first_attribute, ...)
-{
- va_list args;
- va_start(args, first_attribute);
-
- if ( SP_IS_GROUP(origin) && SP_IS_GROUP(dest) && SP_GROUP(origin)->getItemCount() == SP_GROUP(dest)->getItemCount() ) {
- std::vector< SPObject * > childs = origin->childList(true);
- size_t index = 0;
- for (std::vector<SPObject * >::iterator obj_it = childs.begin();
- obj_it != childs.end(); ++obj_it) {
- SPObject *dest_child = dest->nthChild(index);
- cloneStyleAttrbutes(*obj_it, dest_child, first_attribute, args);
- index++;
- }
- }
+ //Style Attributes
SPCSSAttr *css_origin = sp_repr_css_attr_new();
sp_repr_css_attr_add_from_string(css_origin, origin->getRepr()->attribute("style"));
SPCSSAttr *css_dest = sp_repr_css_attr_new();
sp_repr_css_attr_add_from_string(css_dest, dest->getRepr()->attribute("style"));
- for (const char* att = first_attribute; att != NULL; att = va_arg(args, const char*)) {
- std::vector<std::string> elems;
- boost::split(elems, att, boost::is_any_of(","));
- for (std::vector<std::string>::const_iterator atts = elems.begin();
- atts != elems.end(); ++atts) {
- const char* attribute = (*atts).c_str();
- const char* origin_attribute = sp_repr_css_property(css_origin, attribute, "");
- if (origin_attribute == "") {
- sp_repr_css_set_property (css_dest, attribute, NULL);
- } else {
- sp_repr_css_set_property (css_dest, attribute, origin_attribute);
- }
+ gchar ** styleattarray = g_strsplit(style_attributes, ",", 0);
+ gchar ** styleiter = styleattarray;
+ while (*styleiter != NULL) {
+ const char* attribute = (*styleiter);
+ const char* origin_attribute = sp_repr_css_property(css_origin, attribute, "");
+ if (origin_attribute == "") {
+ sp_repr_css_set_property (css_dest, attribute, NULL);
+ } else {
+ sp_repr_css_set_property (css_dest, attribute, origin_attribute);
}
- Glib::ustring css_str;
- sp_repr_css_write_string(css_dest,css_str);
- dest->getRepr()->setAttribute("style", css_str.c_str());
+ styleiter++;
}
- va_end(args);
+ g_strfreev (styleattarray);
+ Glib::ustring css_str;
+ sp_repr_css_write_string(css_dest,css_str);
+ dest->getRepr()->setAttribute("style", css_str.c_str());
}
void
LPECloneOriginal::doBeforeEffect (SPLPEItem const* lpeitem){
original_bbox(lpeitem);
- if (linked_item.linksToItem() && sp_lpe_item) {
- cloneAttrbutes(linked_item.getObject(), SP_OBJECT(sp_lpe_item), true, attributes.param_getSVGValue(), NULL); //NULL required
- cloneStyleAttrbutes(linked_item.getObject(), SP_OBJECT(sp_lpe_item), style_attributes.param_getSVGValue(), NULL); //NULL required
+ if (linked_path.linksToPath()) { //Legacy staff
+ Glib::ustring attributes_value("d");
+ attributes.param_setValue(attributes_value);
+ attributes.write_to_SVG();
+ Glib::ustring style_attributes_value("");
+ style_attributes.param_setValue(style_attributes_value);
+ style_attributes.write_to_SVG();
+ linked_item.param_readSVGValue(linked_path.param_getSVGValue());
+ linked_path.param_readSVGValue("");
+ }
+ if (linked_item.linksToItem()) {
+ cloneAttrbutes(linked_item.getObject(), SP_OBJECT(sp_lpe_item), true, attributes.param_getSVGValue(), style_attributes.param_getSVGValue());
SPShape * shape = dynamic_cast<SPShape *>(sp_lpe_item);
if(shape){
this->setSPCurve(shape->getCurve());
@@ -149,6 +150,44 @@ LPECloneOriginal::doBeforeEffect (SPLPEItem const* lpeitem){
}
}
+
+Gtk::Widget *
+LPECloneOriginal::newWidget()
+{
+ // use manage here, because after deletion of Effect object, others might
+ // still be pointing to this widget.
+ Gtk::VBox *vbox = Gtk::manage(new Gtk::VBox(Effect::newWidget()));
+ vbox->set_border_width(5);
+ vbox->set_homogeneous(false);
+ vbox->set_spacing(2);
+
+ std::vector<Parameter *>::iterator it = param_vector.begin();
+ while (it != param_vector.end()) {
+ if ((*it)->widget_is_visible) {
+ Parameter * param = *it;
+ if (param->param_key == "linkedpath") {
+ ++it;
+ continue;
+ }
+ Gtk::Widget * widg = param->param_newWidget();
+ Glib::ustring * tip = param->param_getTooltip();
+ if (widg) {
+ vbox->pack_start(*widg, true, true, 2);
+ if (tip) {
+ widg->set_tooltip_text(*tip);
+ } else {
+ widg->set_tooltip_text("");
+ widg->set_has_tooltip(false);
+ }
+ }
+ }
+
+ ++it;
+ }
+ this->upd_params = false;
+ return dynamic_cast<Gtk::Widget *>(vbox);
+}
+
void
LPECloneOriginal::doOnApply(SPLPEItem const* lpeitem){
Glib::ustring attributes_value("d,transform");
@@ -159,10 +198,6 @@ LPECloneOriginal::doOnApply(SPLPEItem const* lpeitem){
style_attributes.write_to_SVG();
}
-void
-LPECloneOriginal::doAfterEffect (SPLPEItem const* lpeitem){
-}
-
LPECloneOriginal::~LPECloneOriginal()
{
@@ -170,20 +205,6 @@ LPECloneOriginal::~LPECloneOriginal()
void LPECloneOriginal::doEffect (SPCurve * curve)
{
-// std::vector<std::string> elems;
-// const char * attrs = attributes.param_getSVGValue();
-// boost::split(elems, attrs, boost::is_any_of(","));
-// bool has_d = false;
-// for (std::vector<std::string>::const_iterator atts = elems.begin();
-// atts != elems.end(); ++atts) {
-// const char* attribute = (*atts).c_str();
-// if (std::strcmp(attribute, "d") == 0) {
-// has_d = true;
-// }
-// }
-// if (linked_item.linksToItem() && has_d) {
-// curve->reset();
-// }
curve->set_pathvector(pathvector_before_effect);
}
diff --git a/src/live_effects/lpe-clone-original.h b/src/live_effects/lpe-clone-original.h
index 148590695..e232135eb 100644
--- a/src/live_effects/lpe-clone-original.h
+++ b/src/live_effects/lpe-clone-original.h
@@ -11,6 +11,7 @@
#include "live_effects/effect.h"
#include "live_effects/parameter/originalitem.h"
+#include "live_effects/parameter/originalpath.h"
#include "live_effects/parameter/parameter.h"
#include "live_effects/parameter/point.h"
#include "live_effects/parameter/text.h"
@@ -26,13 +27,14 @@ public:
virtual void doEffect (SPCurve * curve);
virtual void doBeforeEffect (SPLPEItem const* lpeitem);
- virtual void doAfterEffect (SPLPEItem const* lpeitem);
virtual void doOnApply(SPLPEItem const* lpeitem);
- void cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * first_attribute, ...);
- void cloneStyleAttrbutes(SPObject *origin, SPObject *dest, const char * first_attribute, ...);
+ virtual Gtk::Widget * newWidget();
+ void cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * attributes, const char * style_attributes);
private:
+ OriginalPathParam linked_path;
OriginalItemParam linked_item;
+ ScalarParam scale;
BoolParam preserve_position;
TextParam attributes;
TextParam style_attributes;
diff --git a/src/sp-object.cpp b/src/sp-object.cpp
index c2122e109..222626162 100644
--- a/src/sp-object.cpp
+++ b/src/sp-object.cpp
@@ -782,6 +782,7 @@ SPObject* SPObject::nthChild(unsigned index) {
if (counter == index) {
return &child;
}
+ counter++;
}
}
return NULL;