summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2015-02-01 10:48:53 +0000
committerJabiertxof <jtx@jtx.marker.es>2015-02-01 10:48:53 +0000
commit3581010e2f7021167ba0f4e577e0b3f8da2944b6 (patch)
treee6644dc31e58d21ff60a9ae7fe121287071e5566 /src
parentCreate a empty LPE (diff)
parentLatvian translation update (diff)
downloadinkscape-3581010e2f7021167ba0f4e577e0b3f8da2944b6.tar.gz
inkscape-3581010e2f7021167ba0f4e577e0b3f8da2944b6.zip
Effect done
(bzr r13879.1.2)
Diffstat (limited to 'src')
-rw-r--r--src/display/canvas-axonomgrid.cpp5
-rw-r--r--src/display/canvas-grid.cpp5
-rw-r--r--src/extension/internal/cairo-ps-out.cpp22
-rw-r--r--src/extension/internal/cairo-renderer-pdf-out.cpp11
-rw-r--r--src/live_effects/lpe-transform_2pts.cpp155
-rw-r--r--src/live_effects/lpe-transform_2pts.h26
-rw-r--r--src/sp-guide.cpp11
7 files changed, 212 insertions, 23 deletions
diff --git a/src/display/canvas-axonomgrid.cpp b/src/display/canvas-axonomgrid.cpp
index 05ba71a49..ac93f5c88 100644
--- a/src/display/canvas-axonomgrid.cpp
+++ b/src/display/canvas-axonomgrid.cpp
@@ -220,6 +220,11 @@ CanvasAxonomGrid::readRepr()
if( root->viewBox_set ) {
scale_x = root->width.computed / root->viewBox.width();
scale_y = root->height.computed / root->viewBox.height();
+ if (Geom::are_near(scale_x / scale_y, 1.0, Geom::EPSILON)) {
+ // scaling is uniform, try to reduce numerical error
+ scale_x = (scale_x + scale_y)/2.0;
+ scale_y = scale_x;
+ }
}
gchar const *value;
diff --git a/src/display/canvas-grid.cpp b/src/display/canvas-grid.cpp
index 1a284b46e..0a43ed8b7 100644
--- a/src/display/canvas-grid.cpp
+++ b/src/display/canvas-grid.cpp
@@ -544,6 +544,11 @@ CanvasXYGrid::readRepr()
if( root->viewBox_set ) {
scale_x = root->width.computed / root->viewBox.width();
scale_y = root->height.computed / root->viewBox.height();
+ if (Geom::are_near(scale_x / scale_y, 1.0, Geom::EPSILON)) {
+ // scaling is uniform, try to reduce numerical error
+ scale_x = (scale_x + scale_y)/2.0;
+ scale_y = scale_x;
+ }
}
gchar const *value;
diff --git a/src/extension/internal/cairo-ps-out.cpp b/src/extension/internal/cairo-ps-out.cpp
index f6790687c..5dc412301 100644
--- a/src/extension/internal/cairo-ps-out.cpp
+++ b/src/extension/internal/cairo-ps-out.cpp
@@ -146,12 +146,12 @@ CairoPsOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar con
bool new_textToPath = FALSE;
try {
- new_textToPath = mod->get_param_bool("textToPath");
+ new_textToPath = (strcmp(mod->get_param_optiongroup("textToPath"), "paths") == 0);
} catch(...) {}
bool new_textToLaTeX = FALSE;
try {
- new_textToLaTeX = mod->get_param_bool("textToLaTeX");
+ new_textToLaTeX = (strcmp(mod->get_param_optiongroup("textToPath"), "LaTeX") == 0);
}
catch(...) {
g_warning("Parameter <textToLaTeX> might not exist");
@@ -235,12 +235,12 @@ CairoEpsOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar co
bool new_textToPath = FALSE;
try {
- new_textToPath = mod->get_param_bool("textToPath");
+ new_textToPath = (strcmp(mod->get_param_optiongroup("textToPath"), "paths") == 0);
} catch(...) {}
bool new_textToLaTeX = FALSE;
try {
- new_textToLaTeX = mod->get_param_bool("textToLaTeX");
+ new_textToLaTeX = (strcmp(mod->get_param_optiongroup("textToPath"), "LaTeX") == 0);
}
catch(...) {
g_warning("Parameter <textToLaTeX> might not exist");
@@ -330,8 +330,11 @@ CairoPsOutput::init (void)
"<_item value='PS3'>" N_("PostScript level 3") "</_item>\n"
"<_item value='PS2'>" N_("PostScript level 2") "</_item>\n"
"</param>\n"
- "<param name=\"textToPath\" gui-text=\"" N_("Convert texts to paths") "\" type=\"boolean\">false</param>\n"
- "<param name=\"textToLaTeX\" gui-text=\"" N_("PS+LaTeX: Omit text in PS, and create LaTeX file") "\" type=\"boolean\">false</param>\n"
+ "<param name=\"textToPath\" gui-text=\"" N_("Text output options:") "\" type=\"optiongroup\">\n"
+ "<option value=\"embed\">" N_("Embed fonts") "</option>\n"
+ "<option value=\"paths\">" N_("Convert text to paths") "</option>\n"
+ "<option value=\"LaTeX\">" N_("Omit text in PDF and create LaTeX file") "</option>\n"
+ "</param>\n"
"<param name=\"blurToBitmap\" gui-text=\"" N_("Rasterize filter effects") "\" type=\"boolean\">true</param>\n"
"<param name=\"resolution\" gui-text=\"" N_("Resolution for rasterization (dpi):") "\" type=\"int\" min=\"1\" max=\"10000\">96</param>\n"
"<param name=\"area\" gui-text=\"" N_("Output page size") "\" type=\"optiongroup\" >\n"
@@ -369,8 +372,11 @@ CairoEpsOutput::init (void)
"<_item value='PS3'>" N_("PostScript level 3") "</_item>\n"
"<_item value='PS2'>" N_("PostScript level 2") "</_item>\n"
"</param>\n"
- "<param name=\"textToPath\" gui-text=\"" N_("Convert texts to paths") "\" type=\"boolean\">false</param>\n"
- "<param name=\"textToLaTeX\" gui-text=\"" N_("EPS+LaTeX: Omit text in EPS, and create LaTeX file") "\" type=\"boolean\">false</param>\n"
+ "<param name=\"textToPath\" gui-text=\"" N_("Text output options:") "\" type=\"optiongroup\">\n"
+ "<option value=\"embed\">" N_("Embed fonts") "</option>\n"
+ "<option value=\"paths\">" N_("Convert text to paths") "</option>\n"
+ "<option value=\"LaTeX\">" N_("Omit text in PDF and create LaTeX file") "</option>\n"
+ "</param>\n"
"<param name=\"blurToBitmap\" gui-text=\"" N_("Rasterize filter effects") "\" type=\"boolean\">true</param>\n"
"<param name=\"resolution\" gui-text=\"" N_("Resolution for rasterization (dpi):") "\" type=\"int\" min=\"1\" max=\"10000\">96</param>\n"
"<param name=\"area\" gui-text=\"" N_("Output page size") "\" type=\"optiongroup\" >\n"
diff --git a/src/extension/internal/cairo-renderer-pdf-out.cpp b/src/extension/internal/cairo-renderer-pdf-out.cpp
index 0c4ad4f0a..e5c9406c9 100644
--- a/src/extension/internal/cairo-renderer-pdf-out.cpp
+++ b/src/extension/internal/cairo-renderer-pdf-out.cpp
@@ -149,7 +149,7 @@ CairoRendererPdfOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc,
bool new_textToPath = FALSE;
try {
- new_textToPath = mod->get_param_bool("textToPath");
+ new_textToPath = (strcmp(mod->get_param_optiongroup("textToPath"), "paths") == 0);
}
catch(...) {
g_warning("Parameter <textToPath> might not exist");
@@ -157,7 +157,7 @@ CairoRendererPdfOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc,
bool new_textToLaTeX = FALSE;
try {
- new_textToLaTeX = mod->get_param_bool("textToLaTeX");
+ new_textToLaTeX = (strcmp(mod->get_param_optiongroup("textToPath"), "LaTeX") == 0);
}
catch(...) {
g_warning("Parameter <textToLaTeX> might not exist");
@@ -247,8 +247,11 @@ CairoRendererPdfOutput::init (void)
#endif
"<_item value='PDF-1.4'>" N_("PDF 1.4") "</_item>\n"
"</param>\n"
- "<param name=\"textToPath\" gui-text=\"" N_("Convert texts to paths") "\" type=\"boolean\">false</param>\n"
- "<param name=\"textToLaTeX\" gui-text=\"" N_("PDF+LaTeX: Omit text in PDF, and create LaTeX file") "\" type=\"boolean\">false</param>\n"
+ "<param name=\"textToPath\" gui-text=\"" N_("Text output options:") "\" type=\"optiongroup\">\n"
+ "<option value=\"embed\">" N_("Embed fonts") "</option>\n"
+ "<option value=\"paths\">" N_("Convert text to paths") "</option>\n"
+ "<option value=\"LaTeX\">" N_("Omit text in PDF and create LaTeX file") "</option>\n"
+ "</param>\n"
"<param name=\"blurToBitmap\" gui-text=\"" N_("Rasterize filter effects") "\" type=\"boolean\">true</param>\n"
"<param name=\"resolution\" gui-text=\"" N_("Resolution for rasterization (dpi):") "\" type=\"int\" min=\"1\" max=\"10000\">96</param>\n"
"<param name=\"area\" gui-text=\"" N_("Output page size:") "\" type=\"optiongroup\" >\n"
diff --git a/src/live_effects/lpe-transform_2pts.cpp b/src/live_effects/lpe-transform_2pts.cpp
index 95555b80e..142070578 100644
--- a/src/live_effects/lpe-transform_2pts.cpp
+++ b/src/live_effects/lpe-transform_2pts.cpp
@@ -4,32 +4,177 @@
/*
* Authors:
- *
+ * Jabier Arraiza Cenoz<jabier.arraiza@marker.es>
*
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <gtkmm.h>
+
#include "live_effects/lpe-transform_2pts.h"
+#include <glibmm/i18n.h>
+#include "display/curve.h"
+#include <2geom/transforms.h>
+#include <2geom/path.h>
+#include "sp-path.h"
+#include "ui/tools-switch.h"
+
+#include "inkscape.h"
namespace Inkscape {
namespace LivePathEffect {
LPETransform2Pts::LPETransform2Pts(LivePathEffectObject *lpeobject) :
- Effect(lpeobject)
+ Effect(lpeobject),
+ fromOriginalWidth(_("Use bounding box"), _("Use bounding box"), "fromOriginalWidth", &wr, this, false),
+ start(_("Start"), _("Start point"), "start", &wr, this, "Start point"),
+ end(_("End"), _("End point"), "end", &wr, this, "End point")
{
+ registerParameter(&fromOriginalWidth);
+ registerParameter(&start);
+ registerParameter(&end);
}
LPETransform2Pts::~LPETransform2Pts()
{
}
-std::vector<Geom::Path>
-LPETransform2Pts::doEffect_path (std::vector<Geom::Path> const & path_in)
+void
+LPETransform2Pts::doOnApply(SPLPEItem const* lpeitem)
+{
+ using namespace Geom;
+ original_bbox(lpeitem);
+
+ A = Point(boundingbox_X.min(), boundingbox_Y.middle());
+ B = Point(boundingbox_X.max(), boundingbox_Y.middle());
+ SPLPEItem* item = const_cast<SPLPEItem*>(lpeitem);
+ SPPath *path = dynamic_cast<SPPath *>(item);
+ if (path) {
+ SPCurve * c = NULL;
+ c = path->get_original_curve();
+ if(!c->is_closed() && c->first_path() == c->last_path()){
+ A = *(c->first_point());
+ B = *(c->last_point());
+ }
+ }
+ start.param_setValue(A);
+ end.param_setValue(B);
+}
+
+void
+LPETransform2Pts::doBeforeEffect (SPLPEItem const* lpeitem)
{
- return path_in;
+ using namespace Geom;
+ original_bbox(lpeitem);
+ SPLPEItem* item = const_cast<SPLPEItem*>(lpeitem);
+ SPPath *path = dynamic_cast<SPPath *>(item);
+ if(fromOriginalWidth || !path ){
+ A = Point(boundingbox_X.min(), boundingbox_Y.middle());
+ B = Point(boundingbox_X.max(), boundingbox_Y.middle());
+ }
+ if(path && !fromOriginalWidth){
+ SPCurve * c = NULL;
+ c = path->get_original_curve();
+ if(!c->is_closed()){
+ A = *(c->first_point());
+ B = *(c->last_point());
+ }
+ }
+ item->apply_to_clippath(item);
+ item->apply_to_mask(item);
}
+void
+LPETransform2Pts::reset ()
+{
+ start.param_update_default(A);
+ end.param_update_default(B);
+ start.param_set_and_write_default();
+ end.param_set_and_write_default();
+ SPDesktop * desktop = SP_ACTIVE_DESKTOP;
+ tools_switch(desktop, TOOLS_SELECT);
+ tools_switch(desktop, TOOLS_NODES);
+}
+
+Gtk::Widget *LPETransform2Pts::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(6);
+
+ std::vector<Parameter *>::iterator it = param_vector.begin();
+
+ while (it != param_vector.end()) {
+ if ((*it)->widget_is_visible) {
+ Parameter *param = *it;
+ Gtk::Widget *widg = dynamic_cast<Gtk::Widget *>(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;
+ }
+ Gtk::HBox * button = Gtk::manage(new Gtk::HBox(true,0));
+ Gtk::Button *reset = Gtk::manage(new Gtk::Button(Glib::ustring(_("Reset"))));
+ reset->signal_clicked().connect(sigc::mem_fun(*this, &LPETransform2Pts::reset));
+ reset->set_size_request(140,45);
+ button->pack_start(*reset, false, false, 2);
+ vbox->pack_start(*button, true, true, 2);
+ return dynamic_cast<Gtk::Widget *>(vbox);
+}
+
+Geom::Piecewise<Geom::D2<Geom::SBasis> >
+LPETransform2Pts::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in)
+{
+ Geom::Piecewise<Geom::D2<Geom::SBasis> > output;
+ double sca = Geom::distance((Geom::Point)start,(Geom::Point)end)/Geom::distance(A,B);
+ Geom::Ray original(A,B);
+ Geom::Ray transformed((Geom::Point)start,(Geom::Point)end);
+ double rot = transformed.angle() - original.angle();
+ Geom::Path helper;
+ helper.start(A);
+ helper.appendNew<Geom::LineSegment>(B);
+ Geom::Affine m;
+ m *= Geom::Scale(sca);
+ m *= Geom::Rotate(rot);
+ helper *= m;
+ m *= Geom::Translate((Geom::Point)start - helper.initialPoint());
+ output.concat(pwd2_in * m);
+
+ return output;
+}
+
+void
+LPETransform2Pts::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector<Geom::PathVector> &hp_vec)
+{
+ using namespace Geom;
+ hp_vec.clear();
+ Geom::Path hp;
+ hp.start((Geom::Point)start);
+ hp.appendNew<Geom::LineSegment>((Geom::Point)end);
+ Geom::PathVector pathv;
+ pathv.push_back(hp);
+ hp_vec.push_back(pathv);
+}
+
+
/* ######################## */
} //namespace LivePathEffect
diff --git a/src/live_effects/lpe-transform_2pts.h b/src/live_effects/lpe-transform_2pts.h
index a1a20535a..271dec191 100644
--- a/src/live_effects/lpe-transform_2pts.h
+++ b/src/live_effects/lpe-transform_2pts.h
@@ -14,20 +14,38 @@
*/
#include "live_effects/effect.h"
-#include "live_effects/parameter/parameter.h"
-#include "live_effects/parameter/point.h"
+#include "live_effects/parameter/pointreseteable.h"
+#include "live_effects/lpegroupbbox.h"
namespace Inkscape {
namespace LivePathEffect {
-class LPETransform2Pts : public Effect {
+class LPETransform2Pts : public Effect, GroupBBoxEffect {
public:
LPETransform2Pts(LivePathEffectObject *lpeobject);
virtual ~LPETransform2Pts();
- virtual std::vector<Geom::Path> doEffect_path (std::vector<Geom::Path> const & path_in);
+ virtual void doOnApply (SPLPEItem const* lpeitem);
+
+ virtual Geom::Piecewise<Geom::D2<Geom::SBasis> > doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in);
+
+ virtual void doBeforeEffect (SPLPEItem const* lpeitem);
+
+ virtual Gtk::Widget *newWidget();
+
+ virtual void reset();
+
+protected:
+ virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector<Geom::PathVector> &hp_vec);
private:
+ BoolParam fromOriginalWidth;
+ PointReseteableParam start;
+ PointReseteableParam end;
+
+ Geom::Point A;
+ Geom::Point B;
+
LPETransform2Pts(const LPETransform2Pts&);
LPETransform2Pts& operator=(const LPETransform2Pts&);
};
diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp
index 890c1f597..08b055508 100644
--- a/src/sp-guide.cpp
+++ b/src/sp-guide.cpp
@@ -156,8 +156,15 @@ void SPGuide::set(unsigned int key, const gchar *value) {
// If root viewBox set, interpret guides in terms of viewBox (90/96)
SPRoot *root = document->getRoot();
if( root->viewBox_set ) {
- newx = newx * root->width.computed / root->viewBox.width();
- newy = newy * root->height.computed / root->viewBox.height();
+ if(Geom::are_near((root->width.computed * root->viewBox.height()) / (root->viewBox.width() * root->height.computed), 1.0, Geom::EPSILON)) {
+ // for uniform scaling, try to reduce numerical error
+ double vbunit2px = (root->width.computed / root->viewBox.width() + root->height.computed / root->viewBox.height())/2.0;
+ newx = newx * vbunit2px;
+ newy = newy * vbunit2px;
+ } else {
+ newx = newx * root->width.computed / root->viewBox.width();
+ newy = newy * root->height.computed / root->viewBox.height();
+ }
}
this->point_on_line = Geom::Point(newx, newy);
} else if (success == 1) {