From ac25f7827cc250eb47eedf1bd3aa5ec8438fc0e5 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 7 Jun 2016 01:35:26 +0200 Subject: Add measure Over Item by a vlada idea on IRC (bzr r14957.1.1) --- src/ui/tools/measure-tool.cpp | 112 ++++++++++++++++++++++++++++++++++++++++++ src/ui/tools/measure-tool.h | 9 ++++ 2 files changed, 121 insertions(+) (limited to 'src') diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index 287828d32..8b2a734ff 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -394,6 +394,10 @@ MeasureTool::~MeasureTool() sp_canvas_item_destroy(measure_tmp_items[idx]); } measure_tmp_items.clear(); + for (size_t idx = 0; idx < measure_item.size(); ++idx) { + sp_canvas_item_destroy(measure_item[idx]); + } + measure_item.clear(); for (size_t idx = 0; idx < measure_phantom_items.size(); ++idx) { sp_canvas_item_destroy(measure_phantom_items[idx]); } @@ -608,6 +612,12 @@ bool MeasureTool::root_handler(GdkEvent* event) snap_manager.preSnap(scp); snap_manager.unSetup(); } + Geom::Point const motion_w(event->motion.x, event->motion.y); + if(event->motion.state & GDK_SHIFT_MASK) { + showInfoBox(motion_w, true); + } else { + showInfoBox(motion_w, false); + } } else { ret = TRUE; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -1128,6 +1138,108 @@ void MeasureTool::setMeasureCanvasControlLine(Geom::Point start, Geom::Point end } } +void MeasureTool::showItemInfoText(Geom::Point pos, gchar *measure_str, double fontsize) +{ + SPCanvasText *canvas_tooltip = sp_canvastext_new(desktop->getTempGroup(), + desktop, + pos, + measure_str); + sp_canvastext_set_fontsize(canvas_tooltip, fontsize); + canvas_tooltip->rgba = 0xffffffff; + canvas_tooltip->outline = false; + canvas_tooltip->background = true; + canvas_tooltip->anchor_position = TEXT_ANCHOR_LEFT; + canvas_tooltip->rgba_background = 0x00000099; + measure_item.push_back(SP_CANVAS_ITEM(canvas_tooltip)); + sp_canvas_item_show(SP_CANVAS_ITEM(canvas_tooltip)); +} + +void MeasureTool::showInfoBox(Geom::Point cursor, bool into_groups) +{ + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + Inkscape::Util::Unit const * unit = desktop->getNamedView()->getDisplayUnit(); + for (size_t idx = 0; idx < measure_item.size(); ++idx) { + sp_canvas_item_destroy(measure_item[idx]); + } + measure_item.clear(); + + SPItem *newover = desktop->getItemAtPoint(cursor, into_groups); + if (newover) { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + double fontsize = prefs->getDouble("/tools/measure/fontsize", 10.0); + double scale = prefs->getDouble("/tools/measure/scale", 100.0) / 100.0; + int precision = prefs->getInt("/tools/measure/precision", 2); + Glib::ustring unit_name = prefs->getString("/tools/measure/unit"); + if (!unit_name.compare("")) { + unit_name = "px"; + } + Geom::Scale zoom = Geom::Scale(Inkscape::Util::Quantity::convert(desktop->current_zoom(), "px", unit->abbr)).inverse(); + if(newover != over){ + over = newover; + Preferences *prefs = Preferences::get(); + int prefs_bbox = prefs->getBool("/tools/bounding_box", 0); + SPItem::BBoxType bbox_type = !prefs_bbox ? SPItem::VISUAL_BBOX : SPItem::GEOMETRIC_BBOX; + Geom::OptRect bbox = over->bounds(bbox_type); + if (bbox) { + + item_width = Inkscape::Util::Quantity::convert((*bbox).width() * scale, unit->abbr, unit_name); + item_height = Inkscape::Util::Quantity::convert((*bbox).height() * scale, unit->abbr, unit_name); + item_x = Inkscape::Util::Quantity::convert((*bbox).left(), unit->abbr, unit_name); + Geom::Point y_point(0,Inkscape::Util::Quantity::convert((*bbox).bottom() * scale, unit->abbr, "px")); + y_point *= desktop->doc2dt(); + item_y = Inkscape::Util::Quantity::convert(y_point[Geom::Y] * scale, "px", unit_name); + if (SP_IS_SHAPE(over)) { + Geom::PathVector shape = SP_SHAPE(over)->getCurve()->get_pathvector(); + item_length = Geom::length(paths_to_pw(shape)); + item_length = Inkscape::Util::Quantity::convert(item_length * scale, unit->abbr, unit_name); + } + } + } + gchar *measure_str = NULL; + std::stringstream precision_str; + precision_str.imbue(std::locale::classic()); + double origin = Inkscape::Util::Quantity::convert(14, "px", unit->abbr); + Geom::Point rel_position = Geom::Point(origin, origin); + Geom::Point pos = desktop->w2d(cursor); + double gap = Inkscape::Util::Quantity::convert(7 + fontsize, "px", unit->abbr); + if (SP_IS_SHAPE(over)) { + precision_str << _("Lenght") << ": %." << precision << "f %s"; + measure_str = g_strdup_printf(precision_str.str().c_str(), item_length, unit_name.c_str()); + precision_str.str(""); + showItemInfoText(pos + (rel_position * zoom),measure_str,fontsize); + rel_position = Geom::Point(rel_position[Geom::X], rel_position[Geom::Y] + gap); + } else if (SP_IS_GROUP(over)) { + measure_str = _("Shift to measure into group"); + showItemInfoText(pos + (rel_position * zoom),measure_str,fontsize); + rel_position = Geom::Point(rel_position[Geom::X], rel_position[Geom::Y] + gap); + } + + precision_str << "Y: %." << precision << "f %s"; + measure_str = g_strdup_printf(precision_str.str().c_str(), item_y, unit_name.c_str()); + precision_str.str(""); + showItemInfoText(pos + (rel_position * zoom),measure_str,fontsize); + rel_position = Geom::Point(rel_position[Geom::X], rel_position[Geom::Y] + gap); + + precision_str << "X: %." << precision << "f %s"; + measure_str = g_strdup_printf(precision_str.str().c_str(), item_x, unit_name.c_str()); + precision_str.str(""); + showItemInfoText(pos + (rel_position * zoom),measure_str,fontsize); + rel_position = Geom::Point(rel_position[Geom::X], rel_position[Geom::Y] + gap); + + precision_str << _("Height") << ": %." << precision << "f %s"; + measure_str = g_strdup_printf(precision_str.str().c_str(), item_height, unit_name.c_str()); + precision_str.str(""); + showItemInfoText(pos + (rel_position * zoom),measure_str,fontsize); + rel_position = Geom::Point(rel_position[Geom::X], rel_position[Geom::Y] + gap); + + precision_str << _("Width") << ": %." << precision << "f %s"; + measure_str = g_strdup_printf(precision_str.str().c_str(), item_width, unit_name.c_str()); + precision_str.str(""); + showItemInfoText(pos + (rel_position * zoom),measure_str,fontsize); + g_free(measure_str); + } +} + void MeasureTool::showCanvasItems(bool to_guides, bool to_item, bool to_phantom, Inkscape::XML::Node *measure_repr) { SPDesktop *desktop = SP_ACTIVE_DESKTOP; diff --git a/src/ui/tools/measure-tool.h b/src/ui/tools/measure-tool.h index 14fc9f81a..42122dca1 100644 --- a/src/ui/tools/measure-tool.h +++ b/src/ui/tools/measure-tool.h @@ -54,6 +54,8 @@ public: virtual void setMarker(bool isStart); virtual const std::string& getPrefsPath(); Geom::Point readMeasurePoint(bool is_start); + void showInfoBox(Geom::Point cursor, bool into_groups); + void showItemInfoText(Geom::Point pos, gchar *measure_str, double fontsize); void writeMeasurePoint(Geom::Point point, bool is_start); void setGuide(Geom::Point origin, double angle, const char *label); void setPoint(Geom::Point origin, Inkscape::XML::Node *measure_repr); @@ -77,6 +79,13 @@ private: Geom::Point end_p; std::vector measure_tmp_items; std::vector measure_phantom_items; + std::vector measure_item; + double item_width; + double item_height; + double item_x; + double item_y; + double item_length; + SPItem *over; sigc::connection _knot_start_moved_connection; sigc::connection _knot_start_ungrabbed_connection; sigc::connection _knot_start_click_connection; -- cgit v1.2.3 From 6d5d7e5421a5ac585814bde11866d796d81653cd Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 11 Jun 2016 14:04:09 +0200 Subject: Fix a typo pointed by CR (bzr r14957.1.2) --- src/ui/tools/measure-tool.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index 8b2a734ff..900274afc 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -1203,7 +1203,7 @@ void MeasureTool::showInfoBox(Geom::Point cursor, bool into_groups) Geom::Point pos = desktop->w2d(cursor); double gap = Inkscape::Util::Quantity::convert(7 + fontsize, "px", unit->abbr); if (SP_IS_SHAPE(over)) { - precision_str << _("Lenght") << ": %." << precision << "f %s"; + precision_str << _("Length") << ": %." << precision << "f %s"; measure_str = g_strdup_printf(precision_str.str().c_str(), item_length, unit_name.c_str()); precision_str.str(""); showItemInfoText(pos + (rel_position * zoom),measure_str,fontsize); -- cgit v1.2.3 From e7afb49bd67284227bf5df1df22f9993b1bfa581 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 21 Jul 2016 21:05:55 +0200 Subject: =?UTF-8?q?This=20for=20you=20CR=20=C2=B7=20Measure=20line,=20show?= =?UTF-8?q?=20the=20distance=20on=20rect=20lines=20CAD=20like=20with=20aut?= =?UTF-8?q?o=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (bzr r15017.1.1) --- src/live_effects/CMakeLists.txt | 4 + src/live_effects/Makefile_insert | 2 + src/live_effects/effect-enum.h | 1 + src/live_effects/effect.cpp | 6 ++ src/live_effects/lpe-measure-line.cpp | 45 +++++++++++ src/live_effects/lpe-measure-line.h | 48 ++++++++++++ src/live_effects/parameter/texttopath.cpp | 125 ++++++++++++++++++++++++++++++ src/live_effects/parameter/texttopath.h | 87 +++++++++++++++++++++ 8 files changed, 318 insertions(+) create mode 100644 src/live_effects/lpe-measure-line.cpp create mode 100644 src/live_effects/lpe-measure-line.h create mode 100644 src/live_effects/parameter/texttopath.cpp create mode 100644 src/live_effects/parameter/texttopath.h (limited to 'src') diff --git a/src/live_effects/CMakeLists.txt b/src/live_effects/CMakeLists.txt index 9a2f06a76..ed66dd2d9 100644 --- a/src/live_effects/CMakeLists.txt +++ b/src/live_effects/CMakeLists.txt @@ -27,6 +27,7 @@ set(live_effects_SRC lpe-lattice.cpp lpe-lattice2.cpp lpe-line_segment.cpp + lpe-measure-line.cpp lpe-mirror_symmetry.cpp lpe-offset.cpp lpe-parallel.cpp @@ -68,6 +69,7 @@ set(live_effects_SRC parameter/powerstrokepointarray.cpp parameter/random.cpp parameter/text.cpp + parameter/texttopath.cpp parameter/togglebutton.cpp parameter/transformedpoint.cpp parameter/unit.cpp @@ -105,6 +107,7 @@ set(live_effects_SRC lpe-lattice.h lpe-lattice2.h lpe-line_segment.h + lpe-measure-line.h lpe-mirror_symmetry.h lpe-offset.h lpe-parallel.h @@ -148,6 +151,7 @@ set(live_effects_SRC parameter/powerstrokepointarray.h parameter/random.h parameter/text.h + parameter/texttopath.h parameter/togglebutton.h parameter/transformedpoint.h parameter/unit.h diff --git a/src/live_effects/Makefile_insert b/src/live_effects/Makefile_insert index b5bee55c8..d227d379d 100644 --- a/src/live_effects/Makefile_insert +++ b/src/live_effects/Makefile_insert @@ -70,6 +70,8 @@ ink_common_sources += \ live_effects/lpe-perspective_path.h \ live_effects/lpe-perspective-envelope.cpp \ live_effects/lpe-perspective-envelope.h \ + live_effects/lpe-measure-line.cpp \ + live_effects/lpe-measure-line.h \ live_effects/lpe-mirror_symmetry.cpp \ live_effects/lpe-mirror_symmetry.h \ live_effects/lpe-circle_3pts.cpp \ diff --git a/src/live_effects/effect-enum.h b/src/live_effects/effect-enum.h index eea26184c..3682aa1bd 100644 --- a/src/live_effects/effect-enum.h +++ b/src/live_effects/effect-enum.h @@ -36,6 +36,7 @@ enum EffectType { CONSTRUCT_GRID, PERP_BISECTOR, TANGENT_TO_CURVE, + MEASURE_LINE, MIRROR_SYMMETRY, CIRCLE_3PTS, TRANSFORM_2PTS, diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 1868ca43b..d01312ca7 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -40,6 +40,7 @@ #include "live_effects/lpe-lattice2.h" #include "live_effects/lpe-lattice.h" #include "live_effects/lpe-line_segment.h" +#include "live_effects/lpe-measure-line.h" #include "live_effects/lpe-mirror_symmetry.h" #include "live_effects/lpe-offset.h" #include "live_effects/lpe-parallel.h" @@ -151,6 +152,8 @@ const Util::EnumData LPETypeData[] = { {FILL_BETWEEN_MANY, N_("Fill between many"), "fill_between_many"}, {ELLIPSE_5PTS, N_("Ellipse by 5 points"), "ellipse_5pts"}, {BOUNDING_BOX, N_("Bounding Box"), "bounding_box"}, +/* 9.93 */ + {MEASURE_LINE, N_("Measure Line"), "measure-line"}, }; const Util::EnumDataConverter LPETypeConverter(LPETypeData, sizeof(LPETypeData)/sizeof(*LPETypeData)); @@ -319,6 +322,9 @@ Effect::New(EffectType lpenr, LivePathEffectObject *lpeobj) case TRANSFORM_2PTS: neweffect = static_cast ( new LPETransform2Pts(lpeobj) ); break; + case MEASURE_LINE: + neweffect = static_cast ( new LPEMeasureLine(lpeobj) ); + break; default: g_warning("LivePathEffect::Effect::New called with invalid patheffect type (%d)", lpenr); neweffect = NULL; diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp new file mode 100644 index 000000000..d6fe02afd --- /dev/null +++ b/src/live_effects/lpe-measure-line.cpp @@ -0,0 +1,45 @@ +/* + * Author(s): + * Jabiertxo Arraiza Cenoz + * + * Copyright (C) 2014 Author(s) + + * Released under GNU GPL, read the file 'COPYING' for more information + */ +#include "live_effects/lpe-measure-line.h" + +// TODO due to internal breakage in glibmm headers, this must be last: +#include + +using namespace Geom; +namespace Inkscape { +namespace LivePathEffect { + +LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : + Effect(lpeobject), + text(_("text:"), _("text"), "text", &wr, this, "This is a labelXXX") +{ + registerParameter(&text); +} + +LPEMeasureLine::~LPEMeasureLine() {} + +Geom::PathVector +LPEMeasureLine::doEffect_path(Geom::PathVector const &path_in) +{ + return path_in; +} + +}; //namespace LivePathEffect +}; /* namespace Inkscape */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offset:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h new file mode 100644 index 000000000..5ba1ff8c6 --- /dev/null +++ b/src/live_effects/lpe-measure-line.h @@ -0,0 +1,48 @@ +#ifndef INKSCAPE_LPE_MEASURE_LINE_H +#define INKSCAPE_LPE_MEASURE_LINE_H + +/* + * Author(s): + * Jabiertxo Arraiza Cenoz + * + * Copyright (C) 2014 Author(s) + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ +#include "live_effects/parameter/texttopath.h" +#include "live_effects/effect.h" + +namespace Inkscape { +namespace LivePathEffect { + +class LPEMeasureLine : public Effect { +public: + LPEMeasureLine(LivePathEffectObject *lpeobject); + virtual ~LPEMeasureLine(); + + virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); + +private: + + TextToPathParam text; + + LPEMeasureLine(const LPEMeasureLine &); + LPEMeasureLine &operator=(const LPEMeasureLine &); + +}; + +} //namespace LivePathEffect +} //namespace Inkscape + +#endif + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/texttopath.cpp b/src/live_effects/parameter/texttopath.cpp new file mode 100644 index 000000000..8625e4d71 --- /dev/null +++ b/src/live_effects/parameter/texttopath.cpp @@ -0,0 +1,125 @@ +/* + * Copyright (C) Maximilian Albert 2008 + * + * Authors: + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "ui/widget/registered-widget.h" +#include + +#include "live_effects/parameter/texttopath.h" +#include "live_effects/effect.h" +#include "svg/svg.h" +#include "svg/stringstream.h" +#include "widgets/icon.h" +#include "inkscape.h" +#include "verbs.h" +#include "display/canvas-text.h" + +#include <2geom/sbasis-geometric.h> + +namespace Inkscape { + +namespace LivePathEffect { + +TextToPathParam::TextToPathParam( const Glib::ustring& label, const Glib::ustring& tip, + const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, + Effect* effect, const Glib::ustring default_value ) + : Parameter(label, tip, key, wr, effect), + value(default_value), + defvalue(default_value) +{ + SPDesktop *desktop = SP_ACTIVE_DESKTOP; // FIXME: we shouldn't use this! + canvas_text = (SPCanvasText *) sp_canvastext_new(desktop->getTempGroup(), desktop, Geom::Point(0,0), ""); + sp_canvastext_set_text (canvas_text, default_value.c_str()); + sp_canvastext_set_coords (canvas_text, 0, 0); +} + +void +TextToPathParam::param_set_default() +{ + param_setValue(defvalue); +} + +void +TextToPathParam::setPos(Geom::Point pos) +{ + sp_canvastext_set_coords (canvas_text, pos); +} + +void +TextToPathParam::setPosAndAnchor(const Geom::Piecewise > &pwd2, + const double t, const double length, bool /*use_curvature*/) +{ + using namespace Geom; + + Piecewise > pwd2_reparam = arc_length_parametrization(pwd2, 2 , 0.1); + double t_reparam = pwd2_reparam.cuts.back() * t; + Point pos = pwd2_reparam.valueAt(t_reparam); + Point dir = unit_vector(derivative(pwd2_reparam).valueAt(t_reparam)); + Point n = -rot90(dir); + double angle = Geom::angle_between(dir, Point(1,0)); + + sp_canvastext_set_coords(canvas_text, pos + n * length); + sp_canvastext_set_anchor_manually(canvas_text, std::sin(angle), -std::cos(angle)); +} + +void +TextToPathParam::setAnchor(double x_value, double y_value) +{ + anchor_x = x_value; + anchor_y = y_value; + sp_canvastext_set_anchor_manually (canvas_text, anchor_x, anchor_y); +} + +bool +TextToPathParam::param_readSVGValue(const gchar * strvalue) +{ + param_setValue(strvalue); + return true; +} + +gchar * +TextToPathParam::param_getSVGValue() const +{ + return g_strdup(value.c_str()); +} + +Gtk::Widget * +TextToPathParam::param_newWidget() +{ + Inkscape::UI::Widget::RegisteredText *rsu = Gtk::manage(new Inkscape::UI::Widget::RegisteredText( + param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc())); + + rsu->setText(value.c_str()); + rsu->setProgrammatically = false; + + rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change text parameter")); + + return dynamic_cast (rsu); +} + +void +TextToPathParam::param_setValue(const Glib::ustring newvalue) +{ + value = newvalue; + + sp_canvastext_set_text (canvas_text, newvalue.c_str()); +} + +} /* namespace LivePathEffect */ + +} /* namespace Inkscape */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/texttopath.h b/src/live_effects/parameter/texttopath.h new file mode 100644 index 000000000..9a0ee38e2 --- /dev/null +++ b/src/live_effects/parameter/texttopath.h @@ -0,0 +1,87 @@ +#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_TEXT_TO_PATH_H +#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_TEXT_TO_PATH_H + +/* + * Inkscape::LivePathEffectParameters + * + * Authors: + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include + +#include "display/canvas-bpath.h" +#include "live_effects/parameter/parameter.h" + +struct SPCanvasText; + +namespace Inkscape { + +namespace LivePathEffect { + +class TextToPathParam : public Parameter { +public: + TextToPathParam( const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + Inkscape::UI::Widget::Registry* wr, + Effect* effect, + const Glib::ustring default_value = ""); + virtual ~TextToPathParam() {} + + virtual Gtk::Widget * param_newWidget(); + + virtual bool param_readSVGValue(const gchar * strvalue); + virtual gchar * param_getSVGValue() const; + + void param_setValue(const Glib::ustring newvalue); + virtual void param_set_default(); + void setPos(Geom::Point pos); + void setPosAndAnchor(const Geom::Piecewise > &pwd2, + const double t, const double length, bool use_curvature = false); + void setAnchor(double x_value, double y_value); + + const Glib::ustring get_value() const { return defvalue; }; + +private: + TextToPathParam(const TextToPathParam&); + TextToPathParam& operator=(const TextToPathParam&); + double anchor_x; + double anchor_y; + + Glib::ustring value; + Glib::ustring defvalue; + + SPCanvasText *canvas_text; +}; + +/* + * This parameter does not display a widget in the LPE dialog; LPEs can use it to display on-canvas + * text that should not be settable by the user. Note that since no widget is provided, the + * parameter must be initialized differently than usual (only with a pointer to the parent effect; + * no label, no tooltip, etc.). + */ +class TextToPathParamInternal : public TextToPathParam { +public: + TextToPathParamInternal(Effect* effect) : + TextToPathParam("", "", "", NULL, effect) {} + + virtual Gtk::Widget * param_newWidget() { return NULL; } +}; + +} //namespace LivePathEffect + +} //namespace Inkscape + +#endif + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : -- cgit v1.2.3 From a5d6c9a27683820be3d84eea73c2d6f161ce0e8e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 24 Jul 2016 18:49:11 +0200 Subject: Add Text tag and update widgets code (bzr r15017.1.2) --- src/knotholder.cpp | 7 +- src/knotholder.h | 2 +- src/live_effects/CMakeLists.txt | 4 +- src/live_effects/effect.cpp | 3 +- src/live_effects/effect.h | 1 + src/live_effects/lpe-measure-line.cpp | 91 +++++++++++++++++++- src/live_effects/lpe-measure-line.h | 15 ++-- src/live_effects/lpe-transform_2pts.cpp | 1 - src/live_effects/parameter/font.cpp | 126 ++++++++++++++++++++++++++++ src/live_effects/parameter/font.h | 77 +++++++++++++++++ src/live_effects/parameter/point.cpp | 2 +- src/live_effects/parameter/point.h | 1 - src/live_effects/parameter/texttopath.cpp | 125 --------------------------- src/live_effects/parameter/texttopath.h | 87 ------------------- src/live_effects/parameter/togglebutton.cpp | 8 ++ src/selection.cpp | 5 ++ src/selection.h | 5 ++ src/ui/CMakeLists.txt | 2 + src/ui/dialog/livepatheffect-editor.cpp | 31 +++++-- src/ui/dialog/livepatheffect-editor.h | 5 +- src/ui/widget/Makefile_insert | 2 + src/ui/widget/font-selector.cpp | 115 +++++++++++++++++++++++++ src/ui/widget/font-selector.h | 81 ++++++++++++++++++ src/ui/widget/registered-widget.cpp | 44 ++++++++++ src/ui/widget/registered-widget.h | 18 ++++ src/widgets/font-selector.cpp | 26 +----- src/widgets/font-selector.h | 27 +++++- 27 files changed, 649 insertions(+), 262 deletions(-) create mode 100644 src/live_effects/parameter/font.cpp create mode 100644 src/live_effects/parameter/font.h delete mode 100644 src/live_effects/parameter/texttopath.cpp delete mode 100644 src/live_effects/parameter/texttopath.h create mode 100644 src/ui/widget/font-selector.cpp create mode 100644 src/ui/widget/font-selector.h (limited to 'src') diff --git a/src/knotholder.cpp b/src/knotholder.cpp index a2d1cf017..86ae8f0b8 100644 --- a/src/knotholder.cpp +++ b/src/knotholder.cpp @@ -17,6 +17,7 @@ #include "document.h" #include "document-undo.h" +#include "selection.h" #include "sp-shape.h" #include "knot.h" #include "knotholder.h" @@ -202,7 +203,7 @@ KnotHolder::knot_moved_handler(SPKnot *knot, Geom::Point const &p, guint state) } void -KnotHolder::knot_ungrabbed_handler(SPKnot */*knot*/, guint) +KnotHolder::knot_ungrabbed_handler(SPKnot */*knot*/, guint /*state*/) { this->dragging = false; @@ -226,8 +227,12 @@ KnotHolder::knot_ungrabbed_handler(SPKnot */*knot*/, guint) // write the ones that were changed? Inkscape::LivePathEffect::Effect *lpe = lpeItem->getCurrentLPE(); if (lpe) { + lpe->upd_params = true; LivePathEffectObject *lpeobj = lpe->getLPEObj(); lpeobj->updateRepr(); + //Force redraw for update widgets + Inkscape::Selection *selection = desktop->getSelection(); + selection ->emitModified(); } } diff --git a/src/knotholder.h b/src/knotholder.h index f1bacebe5..f055a163a 100644 --- a/src/knotholder.h +++ b/src/knotholder.h @@ -51,7 +51,7 @@ public: void knot_moved_handler(SPKnot *knot, Geom::Point const &p, unsigned int state); void knot_clicked_handler(SPKnot *knot, unsigned int state); - void knot_ungrabbed_handler(SPKnot *knot, unsigned int); + void knot_ungrabbed_handler(SPKnot *knot, unsigned int state); void add(KnotHolderEntity *e); diff --git a/src/live_effects/CMakeLists.txt b/src/live_effects/CMakeLists.txt index ed66dd2d9..c3d740862 100644 --- a/src/live_effects/CMakeLists.txt +++ b/src/live_effects/CMakeLists.txt @@ -69,7 +69,7 @@ set(live_effects_SRC parameter/powerstrokepointarray.cpp parameter/random.cpp parameter/text.cpp - parameter/texttopath.cpp + parameter/font.cpp parameter/togglebutton.cpp parameter/transformedpoint.cpp parameter/unit.cpp @@ -151,7 +151,7 @@ set(live_effects_SRC parameter/powerstrokepointarray.h parameter/random.h parameter/text.h - parameter/texttopath.h + parameter/font.h parameter/togglebutton.h parameter/transformedpoint.h parameter/unit.h diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index d01312ca7..a62e8b62b 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -370,6 +370,7 @@ Effect::Effect(LivePathEffectObject *lpeobject) concatenate_before_pwd2(false), sp_lpe_item(NULL), current_zoom(1), + upd_params(true), sp_curve(NULL), provides_own_flash_paths(true), // is automatically set to false if providesOwnFlashPaths() is not overridden is_ready(false) // is automatically set to false if providesOwnFlashPaths() is not overridden @@ -697,7 +698,7 @@ Effect::newWidget() ++it; } - + upd_params = false; return dynamic_cast(vbox); } diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 898e089b7..e0a7cbe6b 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -122,6 +122,7 @@ public: void editNextParamOncanvas(SPItem * item, SPDesktop * desktop); bool apply_to_clippath_and_mask; + bool upd_params; protected: Effect(LivePathEffectObject *lpeobject); diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index d6fe02afd..7b823b072 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -7,6 +7,11 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ #include "live_effects/lpe-measure-line.h" +#include "inkscape.h" +#include "uri.h" +#include "uri-references.h" +#include "desktop.h" +#include "document.h" // TODO due to internal breakage in glibmm headers, this must be last: #include @@ -17,16 +22,98 @@ namespace LivePathEffect { LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : Effect(lpeobject), - text(_("text:"), _("text"), "text", &wr, this, "This is a labelXXX") + fontselector(_("Font Selector:"), _("Font Selector"), "fontselector", &wr, this, " ") { - registerParameter(&text); + registerParameter(&fontselector); + rtext = NULL; + fontlister = Inkscape::FontLister::get_instance(); } LPEMeasureLine::~LPEMeasureLine() {} +void +LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) +{ + if (SP_ACTIVE_DESKTOP) { + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_mlsize").c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *rtspan = NULL; + if (elemref = SVGElemRef->getObject()) { + rtext = elemref->getRepr(); + sp_repr_set_svg_double(rtext, "x", 0); + sp_repr_set_svg_double(rtext, "y", 0); + } else { + rtext = xml_doc->createElement("svg:text"); + rtext->setAttribute("xml:space", "preserve"); + rtext->setAttribute("id", ((Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_mlsize").c_str()); + /* Set style */ + sp_repr_set_svg_double(rtext, "x", 0); + sp_repr_set_svg_double(rtext, "y", 0); + /* Create */ + rtspan = xml_doc->createElement("svg:tspan"); + rtspan->setAttribute("sodipodi:role", "line"); + } + SPCSSAttr *css = sp_repr_css_attr_new(); + Glib::ustring fontspec = fontselector.param_readFontSpec(fontselector.param_getSVGValue()); + double fontsize = fontselector.param_readFontSize(fontselector.param_getSVGValue()); + fontlister->fill_css( css, fontspec ); + std::stringstream font_size; + font_size.imbue(std::locale::classic()); + font_size << fontsize << "pt"; + sp_repr_css_set_property (css, "font-size", font_size.str().c_str()); + sp_repr_css_set_property (css, "font-style", "normal"); + sp_repr_css_set_property (css, "font-weight", "normal"); + sp_repr_css_set_property (css, "line-height", "125%"); + sp_repr_css_set_property (css, "letter-spacing", "0"); + sp_repr_css_set_property (css, "word-spacing", "0"); + sp_repr_css_set_property (css, "text-align", "center"); + sp_repr_css_set_property (css, "text-anchor", "middle"); + sp_repr_css_set_property (css, "fill", "#000000"); + sp_repr_css_set_property (css, "fill-opacity", "1"); + sp_repr_css_set_property (css, "stroke", "none"); + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + if (!rtspan) { + rtspan = rtext->firstChild(); + } + rtspan->setAttribute("style", css_str.c_str()); + sp_repr_css_attr_unref (css); + if (!elemref) { + rtext->addChild(rtspan, NULL); + Inkscape::GC::release(rtspan); + } + /* Create TEXT */ + std::stringstream lenghtstr; + lenghtstr.imbue(std::locale::classic()); + lenghtstr << lenght; + Inkscape::XML::Node *rstring = NULL; + if (!elemref) { + rstring = xml_doc->createTextNode(lenghtstr.str().c_str()); + rtspan->addChild(rstring, NULL); + Inkscape::GC::release(rstring); + } else { + rstring = rtspan->firstChild(); + rstring->setContent(lenghtstr.str().c_str()); + } + SPObject * text_obj = NULL; + if (!elemref) { + text_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(rtext)); + Inkscape::GC::release(rtext); + } else { + text_obj = desktop->currentLayer()->get_child_by_repr(rtext); + } + text_obj->updateRepr(); + } +} + Geom::PathVector LPEMeasureLine::doEffect_path(Geom::PathVector const &path_in) { + lenght = Geom::distance(path_in.initialPoint(), path_in.finalPoint()); return path_in; } diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 5ba1ff8c6..7e576ffe6 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -9,8 +9,11 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "live_effects/parameter/texttopath.h" +#include "live_effects/parameter/font.h" #include "live_effects/effect.h" +#include +#include "xml/node.h" + namespace Inkscape { namespace LivePathEffect { @@ -19,13 +22,13 @@ class LPEMeasureLine : public Effect { public: LPEMeasureLine(LivePathEffectObject *lpeobject); virtual ~LPEMeasureLine(); - + virtual void doBeforeEffect (SPLPEItem const* lpeitem); virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); - private: - - TextToPathParam text; - + double lenght; + FontParam fontselector; + Inkscape::FontLister *fontlister; + Inkscape::XML::Node *rtext; LPEMeasureLine(const LPEMeasureLine &); LPEMeasureLine &operator=(const LPEMeasureLine &); diff --git a/src/live_effects/lpe-transform_2pts.cpp b/src/live_effects/lpe-transform_2pts.cpp index 3c4ce0708..d32cf42fc 100644 --- a/src/live_effects/lpe-transform_2pts.cpp +++ b/src/live_effects/lpe-transform_2pts.cpp @@ -90,7 +90,6 @@ LPETransform2Pts::doOnApply(SPLPEItem const* lpeitem) { using namespace Geom; original_bbox(lpeitem); - point_a = Point(boundingbox_X.min(), boundingbox_Y.middle()); point_b = Point(boundingbox_X.max(), boundingbox_Y.middle()); SPLPEItem * splpeitem = const_cast(lpeitem); diff --git a/src/live_effects/parameter/font.cpp b/src/live_effects/parameter/font.cpp new file mode 100644 index 000000000..174b66152 --- /dev/null +++ b/src/live_effects/parameter/font.cpp @@ -0,0 +1,126 @@ +/* + * Authors: + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + + +#include "ui/widget/registered-widget.h" +#include "live_effects/parameter/font.h" +#include "live_effects/effect.h" +#include "ui/widget/font-selector.h" +#include "svg/svg.h" +#include "svg/stringstream.h" +#include "verbs.h" + +#include + +namespace Inkscape { + +namespace LivePathEffect { + +FontParam::FontParam( const Glib::ustring& label, const Glib::ustring& tip, + const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, + Effect* effect, const Glib::ustring default_value ) + : Parameter(label, tip, key, wr, effect), + value(default_value), + defvalue(default_value) +{ +} + +void +FontParam::param_set_default() +{ + param_setValue(defvalue); +} + + +Glib::ustring +FontParam::param_readFontSpec(const gchar * strvalue) +{ + Glib::ustring result; + gchar ** strarray = g_strsplit(strvalue, " @ ", 2); + double fontsize; + if (strarray[1]) { + unsigned int success = sp_svg_number_read_d(strarray[1], &fontsize); + if (success == 1) { + result = (Glib::ustring)strarray[0]; + g_strfreev (strarray); + return result; + } + } + g_strfreev (strarray); + return result; +} + +double +FontParam::param_readFontSize(const gchar * strvalue) +{ + gchar ** strarray = g_strsplit(strvalue, " @ ", 2); + double fontsize = 0; + if (strarray[1]) { + unsigned int success = sp_svg_number_read_d(strarray[1], &fontsize); + if (success == 1) { + g_strfreev (strarray); + return fontsize; + } + } + g_strfreev (strarray); + return fontsize; +} + +bool +FontParam::param_readSVGValue(const gchar * strvalue) +{ + double fontsize = param_readFontSize(strvalue); + Glib::ustring fontspec = param_readFontSpec(strvalue); + Inkscape::SVGOStringStream os; + os << fontspec << " @ " << fontsize; + param_setValue((Glib::ustring)os.str()); + return true; +} + +gchar * +FontParam::param_getSVGValue() const +{ + return g_strdup(value.c_str()); +} + +Gtk::Widget * +FontParam::param_newWidget() +{ + Inkscape::UI::Widget::RegisteredFontSelector * fontselectorwdg = Gtk::manage( + new Inkscape::UI::Widget::RegisteredFontSelector( param_label, + param_tooltip, + param_key, + *param_wr, + param_effect->getRepr(), + param_effect->getSPDoc() ) ); + double fontsize = param_readFontSize(param_getSVGValue()); + Glib::ustring fontspec = param_readFontSpec(param_getSVGValue()); + fontselectorwdg->setValue( fontspec, fontsize ); + fontselectorwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change font selector parameter")); + + return dynamic_cast (fontselectorwdg); +} + +void +FontParam::param_setValue(const Glib::ustring newvalue) +{ + value = newvalue; +} + +} /* namespace LivePathEffect */ + +} /* namespace Inkscape */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/font.h b/src/live_effects/parameter/font.h new file mode 100644 index 000000000..e7bcc59d2 --- /dev/null +++ b/src/live_effects/parameter/font.h @@ -0,0 +1,77 @@ +#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_FONT_H +#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_FONT_H + +/* + * Inkscape::LivePathEffectParameters + * + * Authors: + * Released under GNU GPL, read the file 'COPYING' for more information + */ +#include +#include +#include "live_effects/parameter/parameter.h" + +namespace Inkscape { + +namespace LivePathEffect { + +class FontParam : public Parameter { +public: + FontParam( const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + Inkscape::UI::Widget::Registry* wr, + Effect* effect, + const Glib::ustring default_value = ""); + virtual ~FontParam() {} + + virtual Gtk::Widget * param_newWidget(); + virtual bool param_readSVGValue(const gchar * strvalue); + double param_readFontSize(const gchar * strvalue); + Glib::ustring param_readFontSpec(const gchar * strvalue); + virtual gchar * param_getSVGValue() const; + + void param_setValue(const Glib::ustring newvalue); + + virtual void param_set_default(); + + const Glib::ustring get_value() const { return defvalue; }; + +private: + FontParam(const FontParam&); + FontParam& operator=(const FontParam&); + Glib::ustring value; + Glib::ustring defvalue; + +}; + +/* + * This parameter does not display a widget in the LPE dialog; LPEs can use it to display on-canvas + * text that should not be settable by the user. Note that since no widget is provided, the + * parameter must be initialized differently than usual (only with a pointer to the parent effect; + * no label, no tooltip, etc.). + */ +class FontParamInternal : public FontParam { +public: + FontParamInternal(Effect* effect) : + FontParam("", "", "", NULL, effect) {} + + virtual Gtk::Widget * param_newWidget() { return NULL; } +}; + +} //namespace LivePathEffect + +} //namespace Inkscape + +#endif + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/point.cpp b/src/live_effects/parameter/point.cpp index ca3471b29..b4f2c7758 100644 --- a/src/live_effects/parameter/point.cpp +++ b/src/live_effects/parameter/point.cpp @@ -134,7 +134,7 @@ PointParam::param_newWidget() Gtk::HBox * hbox = Gtk::manage( new Gtk::HBox() ); static_cast(hbox)->pack_start(*pointwdg, true, true); static_cast(hbox)->show_all_children(); - + param_effect->upd_params = false; return dynamic_cast (hbox); } diff --git a/src/live_effects/parameter/point.h b/src/live_effects/parameter/point.h index 4329e0bcd..06773c80e 100644 --- a/src/live_effects/parameter/point.h +++ b/src/live_effects/parameter/point.h @@ -11,7 +11,6 @@ #include #include <2geom/point.h> - #include "live_effects/parameter/parameter.h" #include "knot-holder-entity.h" diff --git a/src/live_effects/parameter/texttopath.cpp b/src/live_effects/parameter/texttopath.cpp deleted file mode 100644 index 8625e4d71..000000000 --- a/src/live_effects/parameter/texttopath.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (C) Maximilian Albert 2008 - * - * Authors: - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "ui/widget/registered-widget.h" -#include - -#include "live_effects/parameter/texttopath.h" -#include "live_effects/effect.h" -#include "svg/svg.h" -#include "svg/stringstream.h" -#include "widgets/icon.h" -#include "inkscape.h" -#include "verbs.h" -#include "display/canvas-text.h" - -#include <2geom/sbasis-geometric.h> - -namespace Inkscape { - -namespace LivePathEffect { - -TextToPathParam::TextToPathParam( const Glib::ustring& label, const Glib::ustring& tip, - const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, - Effect* effect, const Glib::ustring default_value ) - : Parameter(label, tip, key, wr, effect), - value(default_value), - defvalue(default_value) -{ - SPDesktop *desktop = SP_ACTIVE_DESKTOP; // FIXME: we shouldn't use this! - canvas_text = (SPCanvasText *) sp_canvastext_new(desktop->getTempGroup(), desktop, Geom::Point(0,0), ""); - sp_canvastext_set_text (canvas_text, default_value.c_str()); - sp_canvastext_set_coords (canvas_text, 0, 0); -} - -void -TextToPathParam::param_set_default() -{ - param_setValue(defvalue); -} - -void -TextToPathParam::setPos(Geom::Point pos) -{ - sp_canvastext_set_coords (canvas_text, pos); -} - -void -TextToPathParam::setPosAndAnchor(const Geom::Piecewise > &pwd2, - const double t, const double length, bool /*use_curvature*/) -{ - using namespace Geom; - - Piecewise > pwd2_reparam = arc_length_parametrization(pwd2, 2 , 0.1); - double t_reparam = pwd2_reparam.cuts.back() * t; - Point pos = pwd2_reparam.valueAt(t_reparam); - Point dir = unit_vector(derivative(pwd2_reparam).valueAt(t_reparam)); - Point n = -rot90(dir); - double angle = Geom::angle_between(dir, Point(1,0)); - - sp_canvastext_set_coords(canvas_text, pos + n * length); - sp_canvastext_set_anchor_manually(canvas_text, std::sin(angle), -std::cos(angle)); -} - -void -TextToPathParam::setAnchor(double x_value, double y_value) -{ - anchor_x = x_value; - anchor_y = y_value; - sp_canvastext_set_anchor_manually (canvas_text, anchor_x, anchor_y); -} - -bool -TextToPathParam::param_readSVGValue(const gchar * strvalue) -{ - param_setValue(strvalue); - return true; -} - -gchar * -TextToPathParam::param_getSVGValue() const -{ - return g_strdup(value.c_str()); -} - -Gtk::Widget * -TextToPathParam::param_newWidget() -{ - Inkscape::UI::Widget::RegisteredText *rsu = Gtk::manage(new Inkscape::UI::Widget::RegisteredText( - param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc())); - - rsu->setText(value.c_str()); - rsu->setProgrammatically = false; - - rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change text parameter")); - - return dynamic_cast (rsu); -} - -void -TextToPathParam::param_setValue(const Glib::ustring newvalue) -{ - value = newvalue; - - sp_canvastext_set_text (canvas_text, newvalue.c_str()); -} - -} /* namespace LivePathEffect */ - -} /* namespace Inkscape */ - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/texttopath.h b/src/live_effects/parameter/texttopath.h deleted file mode 100644 index 9a0ee38e2..000000000 --- a/src/live_effects/parameter/texttopath.h +++ /dev/null @@ -1,87 +0,0 @@ -#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_TEXT_TO_PATH_H -#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_TEXT_TO_PATH_H - -/* - * Inkscape::LivePathEffectParameters - * - * Authors: - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include - -#include "display/canvas-bpath.h" -#include "live_effects/parameter/parameter.h" - -struct SPCanvasText; - -namespace Inkscape { - -namespace LivePathEffect { - -class TextToPathParam : public Parameter { -public: - TextToPathParam( const Glib::ustring& label, - const Glib::ustring& tip, - const Glib::ustring& key, - Inkscape::UI::Widget::Registry* wr, - Effect* effect, - const Glib::ustring default_value = ""); - virtual ~TextToPathParam() {} - - virtual Gtk::Widget * param_newWidget(); - - virtual bool param_readSVGValue(const gchar * strvalue); - virtual gchar * param_getSVGValue() const; - - void param_setValue(const Glib::ustring newvalue); - virtual void param_set_default(); - void setPos(Geom::Point pos); - void setPosAndAnchor(const Geom::Piecewise > &pwd2, - const double t, const double length, bool use_curvature = false); - void setAnchor(double x_value, double y_value); - - const Glib::ustring get_value() const { return defvalue; }; - -private: - TextToPathParam(const TextToPathParam&); - TextToPathParam& operator=(const TextToPathParam&); - double anchor_x; - double anchor_y; - - Glib::ustring value; - Glib::ustring defvalue; - - SPCanvasText *canvas_text; -}; - -/* - * This parameter does not display a widget in the LPE dialog; LPEs can use it to display on-canvas - * text that should not be settable by the user. Note that since no widget is provided, the - * parameter must be initialized differently than usual (only with a pointer to the parent effect; - * no label, no tooltip, etc.). - */ -class TextToPathParamInternal : public TextToPathParam { -public: - TextToPathParamInternal(Effect* effect) : - TextToPathParam("", "", "", NULL, effect) {} - - virtual Gtk::Widget * param_newWidget() { return NULL; } -}; - -} //namespace LivePathEffect - -} //namespace Inkscape - -#endif - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/togglebutton.cpp b/src/live_effects/parameter/togglebutton.cpp index 47a8b5615..5977a5114 100644 --- a/src/live_effects/parameter/togglebutton.cpp +++ b/src/live_effects/parameter/togglebutton.cpp @@ -12,6 +12,7 @@ #include "live_effects/effect.h" #include "svg/svg.h" #include "svg/stringstream.h" +#include "selection.h" #include "widgets/icon.h" #include "inkscape.h" #include "verbs.h" @@ -106,6 +107,7 @@ ToggleButtonParam::param_newWidget() }else{ gtk_box_pack_start (GTK_BOX(boxButton), labelButton, false, false, 1); } + param_effect->upd_params = false; checkwdg->add(*Gtk::manage(Glib::wrap(boxButton))); checkwdg->setActive(value); checkwdg->setProgrammatically = false; @@ -157,6 +159,12 @@ ToggleButtonParam::param_setValue(bool newvalue) void ToggleButtonParam::toggled() { + //Force redraw for update widgets + param_effect->upd_params = true; + if (SP_ACTIVE_DESKTOP) { + Inkscape::Selection *selection = SP_ACTIVE_DESKTOP->getSelection(); + selection ->emitModified(); + } _signal_toggled.emit(); } diff --git a/src/selection.cpp b/src/selection.cpp index 6fc426be7..91d6d2634 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -282,6 +282,11 @@ void Selection::clear() { _emitChanged(); } +void Selection::emitModified() +{ + _emitChanged(); +} + std::vector const &Selection::list() { if(!_objs_vector.empty()) return _objs_vector; diff --git a/src/selection.h b/src/selection.h index 952dde51d..bf6acb015 100644 --- a/src/selection.h +++ b/src/selection.h @@ -191,6 +191,11 @@ public: */ void clear(); + /** + * Emmit modified signal + */ + void emitModified(); + /** * Returns true if no items are selected. */ diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 587974b90..62f341962 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -128,6 +128,7 @@ set(ui_SRC widget/entity-entry.cpp widget/entry.cpp widget/filter-effect-chooser.cpp + widget/font-selector.cpp widget/font-variants.cpp widget/frame.cpp widget/gimpcolorwheel.c @@ -312,6 +313,7 @@ set(ui_SRC widget/entity-entry.h widget/entry.h widget/filter-effect-chooser.h + widget/font-selector.h widget/font-variants.h widget/frame.h widget/gimpspinscale.h diff --git a/src/ui/dialog/livepatheffect-editor.cpp b/src/ui/dialog/livepatheffect-editor.cpp index 422ec10ae..7205beaa8 100644 --- a/src/ui/dialog/livepatheffect-editor.cpp +++ b/src/ui/dialog/livepatheffect-editor.cpp @@ -61,7 +61,7 @@ void lpeeditor_selection_changed (Inkscape::Selection * selection, gpointer data { LivePathEffectEditor *lpeeditor = static_cast(data); lpeeditor->lpe_list_locked = false; - lpeeditor->onSelectionChanged(selection); + lpeeditor->onSelectionChanged(selection, true); } static void lpeeditor_selection_modified (Inkscape::Selection * selection, guint /*flags*/, gpointer data) @@ -98,7 +98,8 @@ LivePathEffectEditor::LivePathEffectEditor() button_up(), button_down(), current_desktop(NULL), - current_lpeitem(NULL) + current_lpeitem(NULL), + current_lperef(NULL) { Gtk::Box *contents = _getContents(); contents->set_spacing(4); @@ -206,6 +207,10 @@ LivePathEffectEditor::~LivePathEffectEditor() void LivePathEffectEditor::showParams(LivePathEffect::Effect& effect) { + if ( ! effect.upd_params ) { + return; + } + if (effectwidget) { effectcontrol_vbox.remove(*effectwidget); delete effectwidget; @@ -265,9 +270,8 @@ LivePathEffectEditor::set_sensitize_all(bool sensitive) button_down.set_sensitive(sensitive); } - void -LivePathEffectEditor::onSelectionChanged(Inkscape::Selection *sel) +LivePathEffectEditor::onSelectionChanged(Inkscape::Selection *sel, bool upd_params) { if (lpe_list_locked) { // this was triggered by selecting a row in the list, so skip reloading @@ -291,6 +295,9 @@ LivePathEffectEditor::onSelectionChanged(Inkscape::Selection *sel) if ( lpeitem->hasPathEffect() ) { Inkscape::LivePathEffect::Effect *lpe = lpeitem->getCurrentLPE(); if (lpe) { + if (upd_params) { + lpe->upd_params = true; + } showParams(*lpe); lpe_list_locked = true; selectInList(lpe); @@ -494,6 +501,12 @@ LivePathEffectEditor::onRemove() SPItem *item = sel->singleItem(); SPLPEItem *lpeitem = dynamic_cast(item); if ( lpeitem ) { + if (current_lperef && current_lperef->lpeobject) { + LivePathEffect::Effect * effect = current_lperef->lpeobject->get_lpe(); + if (effect) { + effect->upd_params = true; + } + } lpeitem->removeCurrentPathEffect(false); DocumentUndo::done( current_desktop->getDocument(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, @@ -548,11 +561,17 @@ void LivePathEffectEditor::on_effect_selection_changed() Gtk::TreeModel::iterator it = sel->get_selected(); LivePathEffect::LPEObjectReference * lperef = (*it)[columns.lperef]; - if (lperef && current_lpeitem) { + if (lperef && current_lpeitem && current_lperef != lperef) { + //The last condition ignore Gtk::TreeModel may occasionally be changed emitted when nothing has happened if (lperef->lpeobject->get_lpe()) { lpe_list_locked = true; // prevent reload of the list which would lose selection current_lpeitem->setCurrentPathEffect(lperef); - showParams(*lperef->lpeobject->get_lpe()); + current_lperef = lperef; + LivePathEffect::Effect * effect = lperef->lpeobject->get_lpe(); + if (effect) { + effect->upd_params = true; + showParams(*effect); + } } } } diff --git a/src/ui/dialog/livepatheffect-editor.h b/src/ui/dialog/livepatheffect-editor.h index 4aac25eaa..b7ec1eeec 100644 --- a/src/ui/dialog/livepatheffect-editor.h +++ b/src/ui/dialog/livepatheffect-editor.h @@ -45,7 +45,8 @@ public: static LivePathEffectEditor &getInstance() { return *new LivePathEffectEditor(); } - void onSelectionChanged(Inkscape::Selection *sel); + void onSelectionChanged(Inkscape::Selection *sel, bool upd_params = false); + void onSelectionModified(Inkscape::Selection *sel); virtual void on_effect_selection_changed(); void setDesktop(SPDesktop *desktop); @@ -126,6 +127,8 @@ private: SPLPEItem * current_lpeitem; + LivePathEffect::LPEObjectReference * current_lperef; + friend void lpeeditor_selection_changed (Inkscape::Selection * selection, gpointer data); LivePathEffectEditor(LivePathEffectEditor const &d); diff --git a/src/ui/widget/Makefile_insert b/src/ui/widget/Makefile_insert index eb98e6872..bb833e5ec 100644 --- a/src/ui/widget/Makefile_insert +++ b/src/ui/widget/Makefile_insert @@ -33,6 +33,8 @@ ink_common_sources += \ ui/widget/entry.h \ ui/widget/filter-effect-chooser.h \ ui/widget/filter-effect-chooser.cpp \ + ui/widget/font-selector.h \ + ui/widget/font-selector.cpp \ ui/widget/font-variants.h \ ui/widget/font-variants.cpp \ ui/widget/gimpspinscale.c \ diff --git a/src/ui/widget/font-selector.cpp b/src/ui/widget/font-selector.cpp new file mode 100644 index 000000000..77bf83fe1 --- /dev/null +++ b/src/ui/widget/font-selector.cpp @@ -0,0 +1,115 @@ +/* + * + * Released under GNU GPL. Read the file 'COPYING' for more information. + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "font-selector.h" +#include "widgets/icon.h" +#include + +namespace Inkscape { +namespace UI { +namespace Widget { + +FontSelector::FontSelector(Glib::ustring const &label, Glib::ustring const &tooltip, + Glib::ustring const &suffix, + Glib::ustring const &icon, + bool mnemonic) + :_widget(new Gtk::HBox()), expanded(true) +{ + Gtk::VBox * vbox_expander = Gtk::manage( new Gtk::VBox() ); + GtkWidget *fontsel = sp_font_selector_new(); + gtk_widget_set_size_request (fontsel, 290, 150); + fsel = SP_FONT_SELECTOR(fontsel); + Gtk::Widget* pIcon = Gtk::manage( sp_icon_get_icon( "on", Inkscape::ICON_SIZE_BUTTON) ); + Gtk::Button * pButton = Gtk::manage(new Gtk::Button()); + pButton->set_relief(Gtk::RELIEF_NONE); + pIcon->show(); + pButton->add(*pIcon); + pButton->show(); + pButton->signal_clicked().connect(sigc::mem_fun(*this, &FontSelector::onFontSelectorSave)); + pButton->set_tooltip_text(_("Save the changes to font selector")); + vbox_expander->pack_start(*Gtk::manage(Glib::wrap(fontsel)), true, true); + vbox_expander->pack_start(*pButton, true, true); + expander = Gtk::manage(new Gtk::Expander(Glib::ustring(_("Font Selector:")))); + expander->add(*vbox_expander); + expander->set_expanded(expanded); + expander->set_spacing(5); + expander->set_use_markup(true); + onExpanderChanged(); + _widget->set_tooltip_text(tooltip); + expander->property_expanded().signal_changed().connect(sigc::mem_fun(*this, &FontSelector::onExpanderChanged) ); + pack_start(*expander, true, true); + pack_start(*Gtk::manage(_widget), true, true); +} + +void +FontSelector::onExpanderChanged() +{ + expanded = expander->get_expanded(); + if(expanded) { + expander->set_label (Glib::ustring(_("Font Selector:"))); + } else { + expander->set_label (Glib::ustring(_("Font Selector: hided"))); + } +} + +Glib::ustring FontSelector::getFontSpec() const +{ + return _fontspec; +} + +void FontSelector::setFontSpec(Glib::ustring fontspec) +{ + _fontspec = fontspec; +} + +double FontSelector::getFontSize() const +{ + return _fontsize; +} + +void FontSelector::setFontSize(double fontsize) +{ + _fontsize = fontsize; +} + +void FontSelector::setValue (Glib::ustring fontspec, double fontsize) +{ + if (_fontsize != fontsize || _fontspec != fontspec) { + setFontSize(fontsize); + setFontSpec(fontspec); + sp_font_selector_set_fontspec(fsel, fontspec, fontsize); + } +} + +void +FontSelector::onFontSelectorSave() +{ + if (_fontspec != sp_font_selector_get_fontspec(fsel) || _fontsize != sp_font_selector_get_size(fsel)) { + setFontSpec(sp_font_selector_get_fontspec(fsel)); + setFontSize(sp_font_selector_get_size(fsel)); + signal_fontselupd.emit(); + onExpanderChanged(); + } +} + + +} // namespace Widget +} // namespace UI +} // namespace Inkscape + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/ui/widget/font-selector.h b/src/ui/widget/font-selector.h new file mode 100644 index 000000000..cfea54bde --- /dev/null +++ b/src/ui/widget/font-selector.h @@ -0,0 +1,81 @@ +/* + * + * Copyright (C) 2007 Author + * + * Released under GNU GPL. Read the file 'COPYING' for more information. + */ + +#ifndef INKSCAPE_UI_WIDGET_FONT_SELECTOR_H +#define INKSCAPE_UI_WIDGET_FONT_SELECTOR_H + +#include +#include "widgets/font-selector.h" + +struct SPFontSelector; +namespace Inkscape { +namespace UI { +namespace Widget { + +/** + * A labelled text box, with spin buttons and optional + * icon or suffix, for entering arbitrary number values. It adds an extra + * number called "startseed", that is not UI edittable, but should be put in SVG. + * This does NOT generate a random number, but provides merely the saving of + * the startseed value. + */ +class FontSelector : public Gtk::HBox +{ +public: + + /** + * Construct a FontSelector Widget. + * + * @param label Label. + * @param suffix Suffix, placed after the widget (defaults to ""). + * @param icon Icon filename, placed before the label (defaults to ""). + * @param mnemonic Mnemonic toggle; if true, an underscore (_) in the label + * indicates the next character should be used for the + * mnemonic accelerator key (defaults to false). + */ + FontSelector( Glib::ustring const &label, + Glib::ustring const &tooltip, + Glib::ustring const &suffix = "", + Glib::ustring const &icon = "", + bool mnemonic = true); + + Glib::ustring getFontSpec() const; + void onExpanderChanged(); + void setFontSpec(Glib::ustring fontspec); + double getFontSize() const; + void setFontSize(double fontsize); + void setValue (Glib::ustring fontspec, double fontsize); + sigc::signal signal_fontselupd; + +protected: + Gtk::Widget *_widget; + bool expanded; + Gtk::Expander * expander; + SPFontSelector *fsel; + Glib::ustring _fontspec; + double _fontsize; + +private: + void onFontSelectorSave(); +}; + +} // namespace Widget +} // namespace UI +} // namespace Inkscape + +#endif // INKSCAPE_UI_WIDGET_RANDOM_H + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/ui/widget/registered-widget.cpp b/src/ui/widget/registered-widget.cpp index 298377af3..7abab25c9 100644 --- a/src/ui/widget/registered-widget.cpp +++ b/src/ui/widget/registered-widget.cpp @@ -25,6 +25,7 @@ #include "ui/widget/scalar-unit.h" #include "ui/widget/point.h" #include "ui/widget/random.h" +#include "ui/widget/font-selector.h" #include "widgets/spinbutton-events.h" #include "xml/repr.h" @@ -805,6 +806,49 @@ RegisteredRandom::on_value_changed() _wr->setUpdating (false); } +/*######################################### + * Registered FONT-SELECTOR + */ + +RegisteredFontSelector::~RegisteredFontSelector() +{ + _value_changed_connection.disconnect(); +} + +RegisteredFontSelector::RegisteredFontSelector ( const Glib::ustring& label, const Glib::ustring& tip, + const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in, + SPDocument* doc_in ) + : RegisteredWidget (label, tip) +{ + init_parent(key, wr, repr_in, doc_in); + _value_changed_connection = signal_fontselupd.connect (sigc::mem_fun (*this, &RegisteredFontSelector::on_value_changed)); +} + +void +RegisteredFontSelector::setValue (Glib::ustring fontspec, double fontsize) +{ + if (fontsize != 0) { //have value in the effect + FontSelector::setValue (fontspec, fontsize); + } +} + +void +RegisteredFontSelector::on_value_changed() +{ + + if (_wr->isUpdating()) + return; + + _wr->setUpdating (true); + + Inkscape::SVGOStringStream os; + os << getFontSpec() << " @ " << getFontSize(); + + write_to_xml(os.str().c_str()); + + _wr->setUpdating (false); +} + } // namespace Dialog } // namespace UI } // namespace Inkscape diff --git a/src/ui/widget/registered-widget.h b/src/ui/widget/registered-widget.h index 9d2489712..17c04de9f 100644 --- a/src/ui/widget/registered-widget.h +++ b/src/ui/widget/registered-widget.h @@ -22,6 +22,7 @@ #include "ui/widget/text.h" #include "ui/widget/random.h" #include "ui/widget/unit-menu.h" +#include "ui/widget/font-selector.h" #include "ui/widget/color-picker.h" #include "inkscape.h" @@ -419,6 +420,23 @@ protected: void on_value_changed(); }; +class RegisteredFontSelector : public RegisteredWidget { +public: + virtual ~RegisteredFontSelector(); + RegisteredFontSelector ( const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + Registry& wr, + Inkscape::XML::Node* repr_in = NULL, + SPDocument *doc_in = NULL); + + void setValue (Glib::ustring fontspec, double fontsize); + +protected: + sigc::connection _value_changed_connection; + void on_value_changed(); +}; + } // namespace Widget } // namespace UI } // namespace Inkscape diff --git a/src/widgets/font-selector.cpp b/src/widgets/font-selector.cpp index aefcb2e81..eeb80ab28 100644 --- a/src/widgets/font-selector.cpp +++ b/src/widgets/font-selector.cpp @@ -19,9 +19,6 @@ # include "config.h" #endif -#include -#include - #include <2geom/transforms.h> #include @@ -34,29 +31,7 @@ /* SPFontSelector */ -struct SPFontSelector -{ -#if GTK_CHECK_VERSION(3,0,0) - GtkBox hbox; -#else - GtkHBox hbox; -#endif - unsigned int block_emit : 1; - - GtkWidget *family; - GtkWidget *style; - GtkWidget *size; - - GtkWidget *family_treeview; - GtkWidget *style_treeview; - - NRNameList families; - NRStyleList styles; - gfloat fontsize; - bool fontsize_dirty; - Glib::ustring *fontspec; -}; struct SPFontSelectorClass @@ -274,6 +249,7 @@ static void sp_font_selector_dispose(GObject *object) if (fsel->fontspec) { delete fsel->fontspec; + fsel->fontspec = 0; } if (fsel->families.length > 0) { diff --git a/src/widgets/font-selector.h b/src/widgets/font-selector.h index ff5472d2d..2d55a87ab 100644 --- a/src/widgets/font-selector.h +++ b/src/widgets/font-selector.h @@ -15,10 +15,33 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ - +#include +#include #include -struct SPFontSelector; +struct SPFontSelector +{ +#if GTK_CHECK_VERSION(3,0,0) + GtkBox hbox; +#else + GtkHBox hbox; +#endif + + unsigned int block_emit : 1; + + GtkWidget *family; + GtkWidget *style; + GtkWidget *size; + + GtkWidget *family_treeview; + GtkWidget *style_treeview; + + NRNameList families; + NRStyleList styles; + gfloat fontsize; + bool fontsize_dirty; + Glib::ustring *fontspec; +}; #define SP_TYPE_FONT_SELECTOR (sp_font_selector_get_type ()) #define SP_FONT_SELECTOR(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), SP_TYPE_FONT_SELECTOR, SPFontSelector)) -- cgit v1.2.3 From 066d5189a44b52d9bb4f75633e6748b73bfc2a8a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 24 Jul 2016 19:00:29 +0200 Subject: Fix a var name bug (bzr r15017.1.4) --- src/live_effects/parameter/togglebutton.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/live_effects/parameter/togglebutton.cpp b/src/live_effects/parameter/togglebutton.cpp index b30a5a3d2..dd1717b40 100644 --- a/src/live_effects/parameter/togglebutton.cpp +++ b/src/live_effects/parameter/togglebutton.cpp @@ -110,7 +110,7 @@ ToggleButtonParam::param_newWidget() gtk_box_pack_start (GTK_BOX(box_button), label_button, false, false, 1); } - checkwdg->add(*Gtk::manage(Glib::wrap(boxButton))); + checkwdg->add(*Gtk::manage(Glib::wrap(box_button))); checkwdg->setActive(value); checkwdg->setProgrammatically = false; checkwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change togglebutton parameter")); -- cgit v1.2.3 From 10790202dbd81463005cc3ae7cdb6f2068003adb Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 25 Jul 2016 01:43:33 +0200 Subject: Add strore parameters (bzr r15017.1.5) --- src/live_effects/lpe-measure-line.cpp | 265 ++++++++++++++++++++++--------- src/live_effects/lpe-measure-line.h | 18 ++- src/live_effects/parameter/bool.cpp | 6 + src/live_effects/parameter/bool.h | 2 +- src/live_effects/parameter/font.cpp | 7 +- src/live_effects/parameter/font.h | 1 + src/live_effects/parameter/parameter.cpp | 7 + src/live_effects/parameter/parameter.h | 1 + src/live_effects/parameter/point.cpp | 4 +- src/live_effects/parameter/point.h | 2 +- src/live_effects/parameter/unit.cpp | 6 + src/live_effects/parameter/unit.h | 1 + 12 files changed, 239 insertions(+), 81 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 7b823b072..dc5d856cf 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -10,6 +10,13 @@ #include "inkscape.h" #include "uri.h" #include "uri-references.h" +#include "preferences.h" +#include "util/units.h" +#include "svg/svg-length.h" +#include "display/curve.h" +#include "sp-root.h" +#include "sp-shape.h" +#include "sp-path.h" #include "desktop.h" #include "document.h" @@ -22,99 +29,209 @@ namespace LivePathEffect { LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : Effect(lpeobject), - fontselector(_("Font Selector:"), _("Font Selector"), "fontselector", &wr, this, " ") + fontselector(_("Font Selector:"), _("Font Selector"), "fontselector", &wr, this, " "), + scale(_("Scale:"), _("Scaling factor"), "scale", &wr, this, 1.0), + precision(_("Number precision"), _("Number precision"), "precision", &wr, this, 2), + unit(_("Unit:"), _("Unit"), "unit", &wr, this), + reverse(_("To other side"), _("To other side"), "reverse", &wr, this, false), + pos(0,0), + angle(0) { registerParameter(&fontselector); + registerParameter(&scale); + registerParameter(&precision); + registerParameter(&unit); + registerParameter(&reverse); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + fontselector.param_update_default(prefs->getString("/live_effects/measure-line/fontselector")); + scale.param_update_default(prefs->getDouble("/live_effects/measure-line/scale", 1.0)); + precision.param_update_default(prefs->getInt("/live_effects/measure-line/precision", 2)); + unit.param_update_default(prefs->getString("/live_effects/measure-line/unit")); + reverse.param_update_default(prefs->getBool("/live_effects/measure-line/reverse")); rtext = NULL; + precision.param_set_range(0, 100); + precision.param_set_increments(1, 1); + precision.param_set_digits(0); + precision.param_make_integer(true); fontlister = Inkscape::FontLister::get_instance(); } LPEMeasureLine::~LPEMeasureLine() {} +void +LPEMeasureLine::doOnApply(SPLPEItem const* lpeitem) +{ + if (!SP_IS_SHAPE(lpeitem)) { + g_warning("LPE measure line can only be applied to shapes (not groups)."); + SPLPEItem * item = const_cast(lpeitem); + item->removeCurrentPathEffect(false); + } +} + void LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) { - if (SP_ACTIVE_DESKTOP) { - SPDesktop *desktop = SP_ACTIVE_DESKTOP; - Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_mlsize").c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - Inkscape::XML::Node *rtspan = NULL; - if (elemref = SVGElemRef->getObject()) { - rtext = elemref->getRepr(); - sp_repr_set_svg_double(rtext, "x", 0); - sp_repr_set_svg_double(rtext, "y", 0); - } else { - rtext = xml_doc->createElement("svg:text"); - rtext->setAttribute("xml:space", "preserve"); - rtext->setAttribute("id", ((Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_mlsize").c_str()); - /* Set style */ - sp_repr_set_svg_double(rtext, "x", 0); - sp_repr_set_svg_double(rtext, "y", 0); - /* Create */ - rtspan = xml_doc->createElement("svg:tspan"); - rtspan->setAttribute("sodipodi:role", "line"); + SPLPEItem * splpeitem = const_cast(lpeitem); + SPPath *sp_path = dynamic_cast(splpeitem); + if (sp_path) { + Geom::PathVector pathvector = sp_path->get_original_curve()->get_pathvector(); + if (SP_ACTIVE_DESKTOP) { + Geom::Point s = pathvector.initialPoint(); + Geom::Point e = pathvector.finalPoint(); + pos = Geom::middle_point(s,e); + Geom::Ray ray(s,e); + angle = ray.angle(); + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + doc_unit = Inkscape::Util::unit_table.getUnit(desktop->doc()->getRoot()->height.unit)->abbr; + if (reverse) { + angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); + if (angle < 0) angle += 2*M_PI; + } + Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); + if (angle_cross < 0) angle_cross += 2*M_PI; + Geom::Point newpos = pos - Point::polar(angle_cross, 10); + Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_mlsize").c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *rtspan = NULL; + if (elemref = SVGElemRef->getObject()) { + rtext = elemref->getRepr(); + sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); + sp_repr_set_svg_double(rtext, "y", newpos[Geom::Y]); + } else { + rtext = xml_doc->createElement("svg:text"); + rtext->setAttribute("xml:space", "preserve"); + rtext->setAttribute("id", ((Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_mlsize").c_str()); + /* Set style */ + sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); + sp_repr_set_svg_double(rtext, "y", newpos[Geom::Y]); + /* Create */ + rtspan = xml_doc->createElement("svg:tspan"); + rtspan->setAttribute("sodipodi:role", "line"); + } + SPCSSAttr *css = sp_repr_css_attr_new(); + Glib::ustring fontspec = fontselector.param_readFontSpec(fontselector.param_getSVGValue()); + double fontsize = fontselector.param_readFontSize(fontselector.param_getSVGValue()); + fontlister->fill_css( css, fontspec ); + std::stringstream font_size; + font_size.imbue(std::locale::classic()); + font_size << fontsize << "pt"; + sp_repr_css_set_property (css, "font-size", font_size.str().c_str()); + sp_repr_css_set_property (css, "font-style", "normal"); + sp_repr_css_set_property (css, "font-weight", "normal"); + sp_repr_css_set_property (css, "line-height", "125%"); + sp_repr_css_set_property (css, "letter-spacing", "0"); + sp_repr_css_set_property (css, "word-spacing", "0"); + sp_repr_css_set_property (css, "text-align", "center"); + sp_repr_css_set_property (css, "text-anchor", "middle"); + sp_repr_css_set_property (css, "fill", "#000000"); + sp_repr_css_set_property (css, "fill-opacity", "1"); + sp_repr_css_set_property (css, "stroke", "none"); + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + if (!rtspan) { + rtspan = rtext->firstChild(); + } + rtspan->setAttribute("style", css_str.c_str()); + sp_repr_css_attr_unref (css); + if (!elemref) { + rtext->addChild(rtspan, NULL); + Inkscape::GC::release(rtspan); + } + /* Create TEXT */ + length = Inkscape::Util::Quantity::convert(length, doc_unit.c_str(), unit.get_abbreviation()); + std::stringstream length_str; + length_str.imbue(std::locale::classic()); + length_str << "%." << precision << "f %s"; + gchar *lengthchar = g_strdup_printf(length_str.str().c_str(), length, unit.get_abbreviation()); + Inkscape::XML::Node *rstring = NULL; + if (!elemref) { + rstring = xml_doc->createTextNode(lengthchar); + rtspan->addChild(rstring, NULL); + Inkscape::GC::release(rstring); + } else { + rstring = rtspan->firstChild(); + rstring->setContent(lengthchar); + } + SPObject * text_obj = NULL; + if (!elemref) { + text_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(rtext)); + Inkscape::GC::release(rtext); + } else { + text_obj = desktop->currentLayer()->get_child_by_repr(rtext); + } + Geom::Affine affine = Geom::Affine(Geom::Translate(newpos).inverse()); + affine *= Geom::Rotate(angle); + affine *= Geom::Translate(newpos); + SP_ITEM(text_obj)->transform = affine; + text_obj->updateRepr(); } - SPCSSAttr *css = sp_repr_css_attr_new(); - Glib::ustring fontspec = fontselector.param_readFontSpec(fontselector.param_getSVGValue()); - double fontsize = fontselector.param_readFontSize(fontselector.param_getSVGValue()); - fontlister->fill_css( css, fontspec ); - std::stringstream font_size; - font_size.imbue(std::locale::classic()); - font_size << fontsize << "pt"; - sp_repr_css_set_property (css, "font-size", font_size.str().c_str()); - sp_repr_css_set_property (css, "font-style", "normal"); - sp_repr_css_set_property (css, "font-weight", "normal"); - sp_repr_css_set_property (css, "line-height", "125%"); - sp_repr_css_set_property (css, "letter-spacing", "0"); - sp_repr_css_set_property (css, "word-spacing", "0"); - sp_repr_css_set_property (css, "text-align", "center"); - sp_repr_css_set_property (css, "text-anchor", "middle"); - sp_repr_css_set_property (css, "fill", "#000000"); - sp_repr_css_set_property (css, "fill-opacity", "1"); - sp_repr_css_set_property (css, "stroke", "none"); - Glib::ustring css_str; - sp_repr_css_write_string(css,css_str); - if (!rtspan) { - rtspan = rtext->firstChild(); - } - rtspan->setAttribute("style", css_str.c_str()); - sp_repr_css_attr_unref (css); - if (!elemref) { - rtext->addChild(rtspan, NULL); - Inkscape::GC::release(rtspan); - } - /* Create TEXT */ - std::stringstream lenghtstr; - lenghtstr.imbue(std::locale::classic()); - lenghtstr << lenght; - Inkscape::XML::Node *rstring = NULL; - if (!elemref) { - rstring = xml_doc->createTextNode(lenghtstr.str().c_str()); - rtspan->addChild(rstring, NULL); - Inkscape::GC::release(rstring); - } else { - rstring = rtspan->firstChild(); - rstring->setContent(lenghtstr.str().c_str()); - } - SPObject * text_obj = NULL; - if (!elemref) { - text_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(rtext)); - Inkscape::GC::release(rtext); - } else { - text_obj = desktop->currentLayer()->get_child_by_repr(rtext); + } +} + +Gtk::Widget *LPEMeasureLine::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::iterator it = param_vector.begin(); + Gtk::HBox * button1 = Gtk::manage(new Gtk::HBox(true,0)); + while (it != param_vector.end()) { + if ((*it)->widget_is_visible) { + Parameter *param = *it; + Gtk::Widget *widg = dynamic_cast(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); + } + } } - text_obj->updateRepr(); + + ++it; } + Gtk::Button *save_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Save as default")))); + save_default->signal_clicked().connect(sigc::mem_fun(*this, &LPEMeasureLine::saveDefault)); + button1->pack_start(*save_default, true, true, 2); + vbox->pack_start(*button1, true, true, 2); + return dynamic_cast(vbox); } Geom::PathVector LPEMeasureLine::doEffect_path(Geom::PathVector const &path_in) { - lenght = Geom::distance(path_in.initialPoint(), path_in.finalPoint()); - return path_in; + + length = Geom::distance(path_in.initialPoint(), path_in.finalPoint()) * scale; + Geom::Path path; + Geom::Point s = path_in.initialPoint(); + Geom::Point e = path_in.finalPoint(); + path.start( s ); + path.appendNew( e ); + Geom::PathVector output; + output.push_back(path); + return output; +} + +void +LPEMeasureLine::saveDefault() +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setString("/live_effects/measure-line/fontselector", (Glib::ustring)fontselector.param_getSVGValue()); + prefs->setDouble("/live_effects/measure-line/scale", scale); + prefs->setInt("/live_effects/measure-line/precision", precision); + prefs->setString("/live_effects/measure-line/unit", (Glib::ustring)unit.get_abbreviation()); + prefs->setInt("/live_effects/measure-line/reverse", reverse); } }; //namespace LivePathEffect diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 7e576ffe6..3b05cb18c 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -11,7 +11,13 @@ */ #include "live_effects/parameter/font.h" #include "live_effects/effect.h" +#include "live_effects/parameter/text.h" +#include "live_effects/parameter/unit.h" +#include "live_effects/parameter/bool.h" #include +#include <2geom/angle.h> +#include <2geom/ray.h> +#include <2geom/point.h> #include "xml/node.h" @@ -23,12 +29,22 @@ public: LPEMeasureLine(LivePathEffectObject *lpeobject); virtual ~LPEMeasureLine(); virtual void doBeforeEffect (SPLPEItem const* lpeitem); + virtual void doOnApply(SPLPEItem const* lpeitem); virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); + void saveDefault(); + virtual Gtk::Widget *newWidget(); private: - double lenght; + double length; FontParam fontselector; Inkscape::FontLister *fontlister; Inkscape::XML::Node *rtext; + Geom::Point pos; + Geom::Coord angle; + ScalarParam scale; + ScalarParam precision; + UnitParam unit; + BoolParam reverse; + Glib::ustring doc_unit; LPEMeasureLine(const LPEMeasureLine &); LPEMeasureLine &operator=(const LPEMeasureLine &); diff --git a/src/live_effects/parameter/bool.cpp b/src/live_effects/parameter/bool.cpp index 9ecadbdeb..af99ef362 100644 --- a/src/live_effects/parameter/bool.cpp +++ b/src/live_effects/parameter/bool.cpp @@ -36,6 +36,12 @@ BoolParam::param_set_default() param_setValue(defvalue); } +void +BoolParam::param_update_default(bool const default_value) +{ + defvalue = default_value; +} + bool BoolParam::param_readSVGValue(const gchar * strvalue) { diff --git a/src/live_effects/parameter/bool.h b/src/live_effects/parameter/bool.h index 403dd0b87..7ad8a9368 100644 --- a/src/live_effects/parameter/bool.h +++ b/src/live_effects/parameter/bool.h @@ -36,7 +36,7 @@ public: void param_setValue(bool newvalue); virtual void param_set_default(); - + void param_update_default(bool const default_value); bool get_value() const { return value; }; inline operator bool() const { return value; }; diff --git a/src/live_effects/parameter/font.cpp b/src/live_effects/parameter/font.cpp index 174b66152..8f89ee5c4 100644 --- a/src/live_effects/parameter/font.cpp +++ b/src/live_effects/parameter/font.cpp @@ -33,7 +33,10 @@ FontParam::param_set_default() { param_setValue(defvalue); } - +void +FontParam::param_update_default(const Glib::ustring default_value){ + defvalue = default_value; +} Glib::ustring FontParam::param_readFontSpec(const gchar * strvalue) @@ -100,7 +103,7 @@ FontParam::param_newWidget() Glib::ustring fontspec = param_readFontSpec(param_getSVGValue()); fontselectorwdg->setValue( fontspec, fontsize ); fontselectorwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change font selector parameter")); - + param_effect->upd_params = false; return dynamic_cast (fontselectorwdg); } diff --git a/src/live_effects/parameter/font.h b/src/live_effects/parameter/font.h index e7bcc59d2..3909ea424 100644 --- a/src/live_effects/parameter/font.h +++ b/src/live_effects/parameter/font.h @@ -28,6 +28,7 @@ public: virtual Gtk::Widget * param_newWidget(); virtual bool param_readSVGValue(const gchar * strvalue); double param_readFontSize(const gchar * strvalue); + void param_update_default(const Glib::ustring defvalue); Glib::ustring param_readFontSpec(const gchar * strvalue); virtual gchar * param_getSVGValue() const; diff --git a/src/live_effects/parameter/parameter.cpp b/src/live_effects/parameter/parameter.cpp index d4e213948..ae55c84e9 100644 --- a/src/live_effects/parameter/parameter.cpp +++ b/src/live_effects/parameter/parameter.cpp @@ -101,6 +101,12 @@ ScalarParam::param_set_default() param_set_value(defvalue); } +void +ScalarParam::param_update_default(gdouble default_value) +{ + defvalue = default_value; +} + void ScalarParam::param_set_value(gdouble val) { @@ -169,6 +175,7 @@ ScalarParam::param_newWidget() if(!overwrite_widget){ rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change scalar parameter")); } + param_effect->upd_params = false; return dynamic_cast (rsu); } else { return NULL; diff --git a/src/live_effects/parameter/parameter.h b/src/live_effects/parameter/parameter.h index 0ef28650a..8556b0d9a 100644 --- a/src/live_effects/parameter/parameter.h +++ b/src/live_effects/parameter/parameter.h @@ -110,6 +110,7 @@ public: virtual gchar * param_getSVGValue() const; virtual void param_set_default(); + void param_update_default(gdouble default_value); void param_set_value(gdouble val); void param_make_integer(bool yes = true); void param_set_range(gdouble min, gdouble max); diff --git a/src/live_effects/parameter/point.cpp b/src/live_effects/parameter/point.cpp index b4f2c7758..90a5b252b 100644 --- a/src/live_effects/parameter/point.cpp +++ b/src/live_effects/parameter/point.cpp @@ -62,9 +62,9 @@ PointParam::param_get_default() const{ } void -PointParam::param_update_default(Geom::Point newpoint) +PointParam::param_update_default(const Geom::Point default_point) { - defvalue = newpoint; + defvalue = default_point; } void diff --git a/src/live_effects/parameter/point.h b/src/live_effects/parameter/point.h index 06773c80e..d41e8a710 100644 --- a/src/live_effects/parameter/point.h +++ b/src/live_effects/parameter/point.h @@ -42,7 +42,7 @@ public: void param_set_default(); Geom::Point param_get_default() const; void param_set_liveupdate(bool live_update); - void param_update_default(Geom::Point newpoint); + void param_update_default(const Geom::Point default_point); virtual void param_transform_multiply(Geom::Affine const& /*postmul*/, bool /*set*/); void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); diff --git a/src/live_effects/parameter/unit.cpp b/src/live_effects/parameter/unit.cpp index 0ee553e2c..b6ea99bfe 100644 --- a/src/live_effects/parameter/unit.cpp +++ b/src/live_effects/parameter/unit.cpp @@ -54,6 +54,12 @@ UnitParam::param_set_default() param_set_value(*defunit); } +void +UnitParam::param_update_default(const Glib::ustring default_unit) +{ + defunit = unit_table.getUnit(default_unit); +} + void UnitParam::param_set_value(Inkscape::Util::Unit const &val) { diff --git a/src/live_effects/parameter/unit.h b/src/live_effects/parameter/unit.h index 59a483018..ae58cf956 100644 --- a/src/live_effects/parameter/unit.h +++ b/src/live_effects/parameter/unit.h @@ -33,6 +33,7 @@ public: virtual gchar * param_getSVGValue() const; virtual void param_set_default(); void param_set_value(Inkscape::Util::Unit const &val); + void param_update_default(const Glib::ustring default_unit); const gchar *get_abbreviation() const; virtual Gtk::Widget * param_newWidget(); -- cgit v1.2.3 From d7bdf3ed2d198c0027babed217dfec32f5f4f389 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 26 Jul 2016 00:10:01 +0200 Subject: Add gap,offset,insensitive transforms, and delete on lpe remove (bzr r15017.1.6) --- src/live_effects/lpe-measure-line.cpp | 101 +++++++++++++++++++++++++++++++--- src/live_effects/lpe-measure-line.h | 8 +++ src/ui/widget/font-selector.cpp | 2 +- 3 files changed, 103 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index dc5d856cf..3d5cd8591 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -13,8 +13,12 @@ #include "preferences.h" #include "util/units.h" #include "svg/svg-length.h" +#include "svg/svg-color.h" #include "display/curve.h" +#include <2geom/affine.h> +#include "style.h" #include "sp-root.h" +#include "sp-item.h" #include "sp-shape.h" #include "sp-path.h" #include "desktop.h" @@ -32,27 +36,57 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : fontselector(_("Font Selector:"), _("Font Selector"), "fontselector", &wr, this, " "), scale(_("Scale:"), _("Scaling factor"), "scale", &wr, this, 1.0), precision(_("Number precision"), _("Number precision"), "precision", &wr, this, 2), + offset_right_left(_("Offset right left"), _("Offset right left"), "offset_right_left", &wr, this, 0), + offset_top_bottom(_("Offset top bottom"), _("Offset top bottom"), "offset_top_bottom", &wr, this, 10), + gap_start(_("Gap to line from origin"), _("Gap to line from origin, without affecting measure"), "gap_start", &wr, this, 0), + gap_end(_("Gap to line from end"), _("Gap to line from end, without affecting measure"), "gap_end", &wr, this, 0), unit(_("Unit:"), _("Unit"), "unit", &wr, this), reverse(_("To other side"), _("To other side"), "reverse", &wr, this, false), + color_as_line(_("Measure color as line"), _("Measure color as line"), "color_as_line", &wr, this, false), + scale_insensitive(_("Scale insensitive"), _("Scale insensitive to transforms in element, parents..."), "scale_insensitive", &wr, this, true), pos(0,0), angle(0) { registerParameter(&fontselector); registerParameter(&scale); registerParameter(&precision); + registerParameter(&offset_right_left); + registerParameter(&offset_top_bottom); + registerParameter(&gap_start); + registerParameter(&gap_end); registerParameter(&unit); registerParameter(&reverse); + registerParameter(&color_as_line); + registerParameter(&scale_insensitive); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); fontselector.param_update_default(prefs->getString("/live_effects/measure-line/fontselector")); scale.param_update_default(prefs->getDouble("/live_effects/measure-line/scale", 1.0)); precision.param_update_default(prefs->getInt("/live_effects/measure-line/precision", 2)); + offset_right_left.param_update_default(prefs->getDouble("/live_effects/measure-line/offset_right_left", 0.0)); + offset_top_bottom.param_update_default(prefs->getDouble("/live_effects/measure-line/offset_top_bottom", 10.0)); + gap_start.param_update_default(prefs->getDouble("/live_effects/measure-line/gap_start", 0.0)); + gap_end.param_update_default(prefs->getDouble("/live_effects/measure-line/gap_end", 0.0)); unit.param_update_default(prefs->getString("/live_effects/measure-line/unit")); reverse.param_update_default(prefs->getBool("/live_effects/measure-line/reverse")); + color_as_line.param_update_default(prefs->getBool("/live_effects/measure-line/color_as_line")); + scale_insensitive.param_update_default(prefs->getBool("/live_effects/measure-line/scale_insensitive")); rtext = NULL; precision.param_set_range(0, 100); precision.param_set_increments(1, 1); precision.param_set_digits(0); precision.param_make_integer(true); + offset_right_left.param_set_range(-999999.0, 999999.0); + offset_right_left.param_set_increments(1, 1); + offset_right_left.param_set_digits(2); + offset_top_bottom.param_set_range(-999999.0, 999999.0); + offset_top_bottom.param_set_increments(1, 1); + offset_top_bottom.param_set_digits(2); + gap_start.param_set_range(-999999.0, 999999.0); + gap_start.param_set_increments(1, 1); + gap_start.param_set_digits(2); + gap_end.param_set_range(-999999.0, 999999.0); + gap_end.param_set_increments(1, 1); + gap_end.param_set_digits(2); fontlister = Inkscape::FontLister::get_instance(); } @@ -75,21 +109,22 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) SPPath *sp_path = dynamic_cast(splpeitem); if (sp_path) { Geom::PathVector pathvector = sp_path->get_original_curve()->get_pathvector(); - if (SP_ACTIVE_DESKTOP) { + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { Geom::Point s = pathvector.initialPoint(); Geom::Point e = pathvector.finalPoint(); + length = Geom::distance(path_in.initialPoint(), path_in.finalPoint()) * scale; pos = Geom::middle_point(s,e); Geom::Ray ray(s,e); angle = ray.angle(); - SPDesktop *desktop = SP_ACTIVE_DESKTOP; doc_unit = Inkscape::Util::unit_table.getUnit(desktop->doc()->getRoot()->height.unit)->abbr; if (reverse) { angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); if (angle < 0) angle += 2*M_PI; } + Geom::Point newpos = pos - Point::polar(angle, offset_right_left); Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); if (angle_cross < 0) angle_cross += 2*M_PI; - Geom::Point newpos = pos - Point::polar(angle_cross, 10); + newpos = newpos - Point::polar(angle_cross, offset_top_bottom); Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_mlsize").c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); @@ -103,6 +138,7 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } else { rtext = xml_doc->createElement("svg:text"); rtext->setAttribute("xml:space", "preserve"); + rtext->setAttribute("sodipodi:insensitive", "true"); rtext->setAttribute("id", ((Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_mlsize").c_str()); /* Set style */ sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); @@ -126,7 +162,30 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) sp_repr_css_set_property (css, "word-spacing", "0"); sp_repr_css_set_property (css, "text-align", "center"); sp_repr_css_set_property (css, "text-anchor", "middle"); - sp_repr_css_set_property (css, "fill", "#000000"); + if (color_as_line) { + if (lpeitem->style) { + if (lpeitem->style->stroke.isPaintserver()) { + SPPaintServer * server = lpeitem->style->getStrokePaintServer(); + if (server) { + Glib::ustring str; + str += "url(#"; + str += server->getId(); + str += ")"; + sp_repr_css_set_property (css, "fill", str.c_str()); + } + } else if (lpeitem->style->stroke.isColor()) { + gchar c[64]; + sp_svg_write_color (c, sizeof(c), lpeitem->style->stroke.value.color.toRGBA32(SP_SCALE24_TO_FLOAT(lpeitem->style->stroke_opacity.value))); + sp_repr_css_set_property (css, "fill", c); + } else { + sp_repr_css_set_property (css, "fill", "#000000"); + } + } else { + sp_repr_css_unset_property (css, "#000000"); + } + } else { + sp_repr_css_set_property (css, "fill", "#000000"); + } sp_repr_css_set_property (css, "fill-opacity", "1"); sp_repr_css_set_property (css, "stroke", "none"); Glib::ustring css_str; @@ -141,6 +200,10 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) Inkscape::GC::release(rtspan); } /* Create TEXT */ + if (!scale_insensitive) { + Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); + length *= (affinetransform.expansionX() + affinetransform.expansionY()) / 2.0; + } length = Inkscape::Util::Quantity::convert(length, doc_unit.c_str(), unit.get_abbreviation()); std::stringstream length_str; length_str.imbue(std::locale::classic()); @@ -165,12 +228,24 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) Geom::Affine affine = Geom::Affine(Geom::Translate(newpos).inverse()); affine *= Geom::Rotate(angle); affine *= Geom::Translate(newpos); - SP_ITEM(text_obj)->transform = affine; + SP_ITEM(text_obj)->transform = affine * i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); text_obj->updateRepr(); } } } +void LPEMeasureLine::doOnRemove (SPLPEItem const* /*lpeitem*/) +{ + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { + rtext->setAttribute("sodipodi:insensitive", NULL); + SPObject * text_obj = desktop->currentLayer()->get_child_by_repr(rtext); + if (text_obj) { + text_obj->updateRepr(); + text_obj->deleteObject(); + } + } +} + Gtk::Widget *LPEMeasureLine::newWidget() { // use manage here, because after deletion of Effect object, others might @@ -211,11 +286,17 @@ Gtk::Widget *LPEMeasureLine::newWidget() Geom::PathVector LPEMeasureLine::doEffect_path(Geom::PathVector const &path_in) { - - length = Geom::distance(path_in.initialPoint(), path_in.finalPoint()) * scale; Geom::Path path; Geom::Point s = path_in.initialPoint(); Geom::Point e = path_in.finalPoint(); + if (reverse) { + angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); + if (angle < 0) angle += 2*M_PI; + } + s = s - Point::polar(angle, gap_start); + angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); + if (angle < 0) angle += 2*M_PI; + e = e - Point::polar(angle, gap_end); path.start( s ); path.appendNew( e ); Geom::PathVector output; @@ -230,8 +311,14 @@ LPEMeasureLine::saveDefault() prefs->setString("/live_effects/measure-line/fontselector", (Glib::ustring)fontselector.param_getSVGValue()); prefs->setDouble("/live_effects/measure-line/scale", scale); prefs->setInt("/live_effects/measure-line/precision", precision); + prefs->setDouble("/live_effects/measure-line/offset_right_left", offset_right_left); + prefs->setDouble("/live_effects/measure-line/offset_top_bottom", offset_top_bottom); + prefs->setDouble("/live_effects/measure-line/gap_start", gap_start); + prefs->setDouble("/live_effects/measure-line/gap_end", gap_end); prefs->setString("/live_effects/measure-line/unit", (Glib::ustring)unit.get_abbreviation()); prefs->setInt("/live_effects/measure-line/reverse", reverse); + prefs->setInt("/live_effects/measure-line/color_as_line", color_as_line); + prefs->setInt("/live_effects/measure-line/scale_insensitive", scale_insensitive); } }; //namespace LivePathEffect diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 3b05cb18c..ba24aa404 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -30,6 +30,7 @@ public: virtual ~LPEMeasureLine(); virtual void doBeforeEffect (SPLPEItem const* lpeitem); virtual void doOnApply(SPLPEItem const* lpeitem); + virtual void doOnRemove (SPLPEItem const* /*lpeitem*/); virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); void saveDefault(); virtual Gtk::Widget *newWidget(); @@ -42,9 +43,16 @@ private: Geom::Coord angle; ScalarParam scale; ScalarParam precision; + ScalarParam offset_right_left; + ScalarParam offset_top_bottom; + ScalarParam gap_start; + ScalarParam gap_end; UnitParam unit; BoolParam reverse; + BoolParam color_as_line; + BoolParam scale_insensitive; Glib::ustring doc_unit; +/* Geom::Affine affine_over;*/ LPEMeasureLine(const LPEMeasureLine &); LPEMeasureLine &operator=(const LPEMeasureLine &); diff --git a/src/ui/widget/font-selector.cpp b/src/ui/widget/font-selector.cpp index 77bf83fe1..6b0bdca36 100644 --- a/src/ui/widget/font-selector.cpp +++ b/src/ui/widget/font-selector.cpp @@ -19,7 +19,7 @@ FontSelector::FontSelector(Glib::ustring const &label, Glib::ustring const &tool Glib::ustring const &suffix, Glib::ustring const &icon, bool mnemonic) - :_widget(new Gtk::HBox()), expanded(true) + :_widget(new Gtk::HBox()), expanded(false) { Gtk::VBox * vbox_expander = Gtk::manage( new Gtk::VBox() ); GtkWidget *fontsel = sp_font_selector_new(); -- cgit v1.2.3 From bc46160cc69e4597d94ae6dd0c70428341a4d4f2 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 28 Jul 2016 00:55:05 +0200 Subject: Add optional linked path (bzr r15017.1.8) --- src/live_effects/lpe-measure-line.cpp | 58 ++++++++++++++++++++++++++++++----- src/live_effects/lpe-measure-line.h | 8 ++++- 2 files changed, 57 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 3d5cd8591..638d60464 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -14,6 +14,7 @@ #include "util/units.h" #include "svg/svg-length.h" #include "svg/svg-color.h" +#include "svg/svg.h" #include "display/curve.h" #include <2geom/affine.h> #include "style.h" @@ -34,10 +35,13 @@ namespace LivePathEffect { LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : Effect(lpeobject), fontselector(_("Font Selector:"), _("Font Selector"), "fontselector", &wr, this, " "), + origin(_("Optional Origin:"), _("Optional origin"), "origin", &wr, this), + curve_linked(_("Curve on optional origin:"), _("Curve on optional origin, set 0 to start/end"), "curve_linked", &wr, this, 1), + line_offset(_("Optional origin offset"), _("Optional origin offset"), "line_offset", &wr, this, 5), scale(_("Scale:"), _("Scaling factor"), "scale", &wr, this, 1.0), precision(_("Number precision"), _("Number precision"), "precision", &wr, this, 2), offset_right_left(_("Offset right left"), _("Offset right left"), "offset_right_left", &wr, this, 0), - offset_top_bottom(_("Offset top bottom"), _("Offset top bottom"), "offset_top_bottom", &wr, this, 10), + offset_top_bottom(_("Offset top bottom"), _("Offset top bottom"), "offset_top_bottom", &wr, this, 5), gap_start(_("Gap to line from origin"), _("Gap to line from origin, without affecting measure"), "gap_start", &wr, this, 0), gap_end(_("Gap to line from end"), _("Gap to line from end, without affecting measure"), "gap_end", &wr, this, 0), unit(_("Unit:"), _("Unit"), "unit", &wr, this), @@ -48,6 +52,9 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : angle(0) { registerParameter(&fontselector); + registerParameter(&origin); + registerParameter(&curve_linked); + registerParameter(&line_offset); registerParameter(&scale); registerParameter(&precision); registerParameter(&offset_right_left); @@ -63,9 +70,8 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : scale.param_update_default(prefs->getDouble("/live_effects/measure-line/scale", 1.0)); precision.param_update_default(prefs->getInt("/live_effects/measure-line/precision", 2)); offset_right_left.param_update_default(prefs->getDouble("/live_effects/measure-line/offset_right_left", 0.0)); - offset_top_bottom.param_update_default(prefs->getDouble("/live_effects/measure-line/offset_top_bottom", 10.0)); - gap_start.param_update_default(prefs->getDouble("/live_effects/measure-line/gap_start", 0.0)); - gap_end.param_update_default(prefs->getDouble("/live_effects/measure-line/gap_end", 0.0)); + offset_top_bottom.param_update_default(prefs->getDouble("/live_effects/measure-line/offset_top_bottom", 5.0)); + line_offset.param_update_default(prefs->getDouble("/live_effects/measure-line/line_offset", 5.0)); unit.param_update_default(prefs->getString("/live_effects/measure-line/unit")); reverse.param_update_default(prefs->getBool("/live_effects/measure-line/reverse")); color_as_line.param_update_default(prefs->getBool("/live_effects/measure-line/color_as_line")); @@ -75,12 +81,20 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : precision.param_set_increments(1, 1); precision.param_set_digits(0); precision.param_make_integer(true); + curve_linked.param_set_range(1, 999); + curve_linked.param_set_increments(1, 1); + curve_linked.param_set_digits(0); + curve_linked.param_make_integer(true); + precision.param_make_integer(true); offset_right_left.param_set_range(-999999.0, 999999.0); offset_right_left.param_set_increments(1, 1); offset_right_left.param_set_digits(2); offset_top_bottom.param_set_range(-999999.0, 999999.0); offset_top_bottom.param_set_increments(1, 1); offset_top_bottom.param_set_digits(2); + line_offset.param_set_range(-999999.0, 999999.0); + line_offset.param_set_increments(1, 1); + line_offset.param_set_digits(2); gap_start.param_set_range(-999999.0, 999999.0); gap_start.param_set_increments(1, 1); gap_start.param_set_digits(2); @@ -110,9 +124,39 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) if (sp_path) { Geom::PathVector pathvector = sp_path->get_original_curve()->get_pathvector(); if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { + Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); Geom::Point s = pathvector.initialPoint(); Geom::Point e = pathvector.finalPoint(); - length = Geom::distance(path_in.initialPoint(), path_in.finalPoint()) * scale; + if (origin.linksToPath() && origin.getObject() && !origin.get_pathvector().empty()) { + pathvector = origin.get_pathvector(); + size_t ncurves = pathvector.curveCount(); + curve_linked.param_set_range(1, ncurves); + if(previous_ncurves != ncurves) { + this->upd_params = true; + previous_ncurves = ncurves; + } + s = pathvector.pointAt(curve_linked -1); + e = pathvector.pointAt(curve_linked); + Geom::Ray ray(s,e); + angle = ray.angle(); + if (reverse) { + angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); + if (angle < 0) angle += 2*M_PI; + } + Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); + if (angle_cross < 0) angle_cross += 2*M_PI; + s = s - Point::polar(angle_cross, line_offset); + e = e - Point::polar(angle_cross, line_offset); + Geom::Path path; + path.start( s ); + path.appendNew( e ); + Geom::PathVector line_upd; + line_upd.push_back(path); + Inkscape::XML::Node *line = SP_OBJECT(sp_path)->getRepr(); + gchar *str = sp_svg_write_path(line_upd); + line->setAttribute("inkscape:original-d", str); + } + length = Geom::distance(s, e) * scale; pos = Geom::middle_point(s,e); Geom::Ray ray(s,e); angle = ray.angle(); @@ -125,7 +169,6 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); if (angle_cross < 0) angle_cross += 2*M_PI; newpos = newpos - Point::polar(angle_cross, offset_top_bottom); - Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_mlsize").c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); SVGElemRef->attach(SVGElem_uri); @@ -313,8 +356,7 @@ LPEMeasureLine::saveDefault() prefs->setInt("/live_effects/measure-line/precision", precision); prefs->setDouble("/live_effects/measure-line/offset_right_left", offset_right_left); prefs->setDouble("/live_effects/measure-line/offset_top_bottom", offset_top_bottom); - prefs->setDouble("/live_effects/measure-line/gap_start", gap_start); - prefs->setDouble("/live_effects/measure-line/gap_end", gap_end); + prefs->setDouble("/live_effects/measure-line/line_offset", line_offset); prefs->setString("/live_effects/measure-line/unit", (Glib::ustring)unit.get_abbreviation()); prefs->setInt("/live_effects/measure-line/reverse", reverse); prefs->setInt("/live_effects/measure-line/color_as_line", color_as_line); diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index ba24aa404..b03a44705 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -9,11 +9,13 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "live_effects/parameter/font.h" + #include "live_effects/effect.h" +#include "live_effects/parameter/font.h" #include "live_effects/parameter/text.h" #include "live_effects/parameter/unit.h" #include "live_effects/parameter/bool.h" +#include "live_effects/parameter/originalpath.h" #include #include <2geom/angle.h> #include <2geom/ray.h> @@ -41,12 +43,16 @@ private: Inkscape::XML::Node *rtext; Geom::Point pos; Geom::Coord angle; + OriginalPathParam origin; + ScalarParam curve_linked; + ScalarParam line_offset; ScalarParam scale; ScalarParam precision; ScalarParam offset_right_left; ScalarParam offset_top_bottom; ScalarParam gap_start; ScalarParam gap_end; + size_t previous_ncurves; UnitParam unit; BoolParam reverse; BoolParam color_as_line; -- cgit v1.2.3 From 5c04358b2fd79db36b8064ad5e7a9fd8bbe314bb Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 28 Jul 2016 12:30:52 +0200 Subject: Finish linked path and add local number format (bzr r15017.1.9) --- src/live_effects/lpe-measure-line.cpp | 96 ++++++++++++++++++++++------------- src/live_effects/lpe-measure-line.h | 4 +- src/ui/widget/font-selector.cpp | 8 +-- src/ui/widget/font-selector.h | 1 + 4 files changed, 69 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 638d60464..31b1db7c2 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -24,6 +24,7 @@ #include "sp-path.h" #include "desktop.h" #include "document.h" +#include // TODO due to internal breakage in glibmm headers, this must be last: #include @@ -34,27 +35,28 @@ namespace LivePathEffect { LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : Effect(lpeobject), - fontselector(_("Font Selector:"), _("Font Selector"), "fontselector", &wr, this, " "), - origin(_("Optional Origin:"), _("Optional origin"), "origin", &wr, this), - curve_linked(_("Curve on optional origin:"), _("Curve on optional origin, set 0 to start/end"), "curve_linked", &wr, this, 1), - line_offset(_("Optional origin offset"), _("Optional origin offset"), "line_offset", &wr, this, 5), - scale(_("Scale:"), _("Scaling factor"), "scale", &wr, this, 1.0), - precision(_("Number precision"), _("Number precision"), "precision", &wr, this, 2), - offset_right_left(_("Offset right left"), _("Offset right left"), "offset_right_left", &wr, this, 0), - offset_top_bottom(_("Offset top bottom"), _("Offset top bottom"), "offset_top_bottom", &wr, this, 5), + fontselector(_("Font Selector*"), _("Font Selector"), "fontselector", &wr, this, " "), + origin(_("Optional Origin"), _("Optional origin"), "origin", &wr, this), + curve_linked(_("Curve on optional origin*"), _("Curve on optional origin, set 0 to start/end"), "curve_linked", &wr, this, 1), + origin_offset(_("Optional origin offset*"), _("Optional origin offset"), "origin_offset", &wr, this, 5), + scale(_("Scale*"), _("Scaling factor"), "scale", &wr, this, 1.0), + precision(_("Number precision*"), _("Number precision"), "precision", &wr, this, 2), + offset_right_left(_("Offset right left*"), _("Offset right left"), "offset_right_left", &wr, this, 0), + offset_top_bottom(_("Offset top bottom*"), _("Offset top bottom"), "offset_top_bottom", &wr, this, 5), gap_start(_("Gap to line from origin"), _("Gap to line from origin, without affecting measure"), "gap_start", &wr, this, 0), gap_end(_("Gap to line from end"), _("Gap to line from end, without affecting measure"), "gap_end", &wr, this, 0), - unit(_("Unit:"), _("Unit"), "unit", &wr, this), - reverse(_("To other side"), _("To other side"), "reverse", &wr, this, false), - color_as_line(_("Measure color as line"), _("Measure color as line"), "color_as_line", &wr, this, false), - scale_insensitive(_("Scale insensitive"), _("Scale insensitive to transforms in element, parents..."), "scale_insensitive", &wr, this, true), + unit(_("Unit*"), _("Unit"), "unit", &wr, this), + reverse(_("To other side*"), _("To other side"), "reverse", &wr, this, false), + color_as_line(_("Measure color as line*"), _("Measure color as line"), "color_as_line", &wr, this, false), + scale_insensitive(_("Scale insensitive*"), _("Scale insensitive to transforms in element, parents..."), "scale_insensitive", &wr, this, true), + local_locale(_("Local Number Format*"), _("Local number format"), "local_locale", &wr, this, true), pos(0,0), angle(0) { registerParameter(&fontselector); registerParameter(&origin); registerParameter(&curve_linked); - registerParameter(&line_offset); + registerParameter(&origin_offset); registerParameter(&scale); registerParameter(&precision); registerParameter(&offset_right_left); @@ -65,17 +67,19 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : registerParameter(&reverse); registerParameter(&color_as_line); registerParameter(&scale_insensitive); + registerParameter(&local_locale); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); fontselector.param_update_default(prefs->getString("/live_effects/measure-line/fontselector")); scale.param_update_default(prefs->getDouble("/live_effects/measure-line/scale", 1.0)); precision.param_update_default(prefs->getInt("/live_effects/measure-line/precision", 2)); offset_right_left.param_update_default(prefs->getDouble("/live_effects/measure-line/offset_right_left", 0.0)); offset_top_bottom.param_update_default(prefs->getDouble("/live_effects/measure-line/offset_top_bottom", 5.0)); - line_offset.param_update_default(prefs->getDouble("/live_effects/measure-line/line_offset", 5.0)); + origin_offset.param_update_default(prefs->getDouble("/live_effects/measure-line/origin_offset", 5.0)); unit.param_update_default(prefs->getString("/live_effects/measure-line/unit")); reverse.param_update_default(prefs->getBool("/live_effects/measure-line/reverse")); color_as_line.param_update_default(prefs->getBool("/live_effects/measure-line/color_as_line")); scale_insensitive.param_update_default(prefs->getBool("/live_effects/measure-line/scale_insensitive")); + local_locale.param_update_default(prefs->getBool("/live_effects/measure-line/local_locale")); rtext = NULL; precision.param_set_range(0, 100); precision.param_set_increments(1, 1); @@ -92,9 +96,9 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : offset_top_bottom.param_set_range(-999999.0, 999999.0); offset_top_bottom.param_set_increments(1, 1); offset_top_bottom.param_set_digits(2); - line_offset.param_set_range(-999999.0, 999999.0); - line_offset.param_set_increments(1, 1); - line_offset.param_set_digits(2); + origin_offset.param_set_range(-999999.0, 999999.0); + origin_offset.param_set_increments(1, 1); + origin_offset.param_set_digits(2); gap_start.param_set_range(-999999.0, 999999.0); gap_start.param_set_increments(1, 1); gap_start.param_set_digits(2); @@ -104,6 +108,8 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : fontlister = Inkscape::FontLister::get_instance(); } +bool LPEMeasureLine::alerts_off = false; + LPEMeasureLine::~LPEMeasureLine() {} void @@ -113,6 +119,18 @@ LPEMeasureLine::doOnApply(SPLPEItem const* lpeitem) g_warning("LPE measure line can only be applied to shapes (not groups)."); SPLPEItem * item = const_cast(lpeitem); item->removeCurrentPathEffect(false); + } else { + if(!alerts_off) { + char *msg = _("The \"measure line\" path effect could update original path on the object you are applying it to if link it to other path. If this is not what you want, click Cancel."); + Gtk::MessageDialog dialog(msg, false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_OK_CANCEL, true); + gint response = dialog.run(); + alerts_off = true; + if(response == GTK_RESPONSE_CANCEL) { + SPLPEItem* item = const_cast(lpeitem); + item->removeCurrentPathEffect(false); + return; + } + } } } @@ -145,8 +163,8 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); if (angle_cross < 0) angle_cross += 2*M_PI; - s = s - Point::polar(angle_cross, line_offset); - e = e - Point::polar(angle_cross, line_offset); + s = s - Point::polar(angle_cross, origin_offset); + e = e - Point::polar(angle_cross, origin_offset); Geom::Path path; path.start( s ); path.appendNew( e ); @@ -249,17 +267,22 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } length = Inkscape::Util::Quantity::convert(length, doc_unit.c_str(), unit.get_abbreviation()); std::stringstream length_str; - length_str.imbue(std::locale::classic()); - length_str << "%." << precision << "f %s"; - gchar *lengthchar = g_strdup_printf(length_str.str().c_str(), length, unit.get_abbreviation()); + length_str.setf(std::ios::fixed, std::ios::floatfield); + length_str.precision(precision); + if (local_locale) { + length_str.imbue(std::locale("")); + } else { + length_str.imbue(std::locale::classic()); + } + length_str << length << unit.get_abbreviation(); Inkscape::XML::Node *rstring = NULL; if (!elemref) { - rstring = xml_doc->createTextNode(lengthchar); + rstring = xml_doc->createTextNode(length_str.str().c_str()); rtspan->addChild(rstring, NULL); Inkscape::GC::release(rstring); } else { rstring = rtspan->firstChild(); - rstring->setContent(lengthchar); + rstring->setContent(length_str.str().c_str()); } SPObject * text_obj = NULL; if (!elemref) { @@ -280,11 +303,13 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) void LPEMeasureLine::doOnRemove (SPLPEItem const* /*lpeitem*/) { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - rtext->setAttribute("sodipodi:insensitive", NULL); - SPObject * text_obj = desktop->currentLayer()->get_child_by_repr(rtext); - if (text_obj) { - text_obj->updateRepr(); - text_obj->deleteObject(); + if (rtext) { + rtext->setAttribute("sodipodi:insensitive", NULL); + SPObject * text_obj = desktop->currentLayer()->get_child_by_repr(rtext); + if (text_obj) { + text_obj->updateRepr(); + text_obj->deleteObject(); + } } } } @@ -297,7 +322,7 @@ Gtk::Widget *LPEMeasureLine::newWidget() vbox->set_border_width(5); vbox->set_homogeneous(false); - vbox->set_spacing(6); + vbox->set_spacing(2); std::vector::iterator it = param_vector.begin(); Gtk::HBox * button1 = Gtk::manage(new Gtk::HBox(true,0)); @@ -319,7 +344,7 @@ Gtk::Widget *LPEMeasureLine::newWidget() ++it; } - Gtk::Button *save_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Save as default")))); + Gtk::Button *save_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Save '*' as default")))); save_default->signal_clicked().connect(sigc::mem_fun(*this, &LPEMeasureLine::saveDefault)); button1->pack_start(*save_default, true, true, 2); vbox->pack_start(*button1, true, true, 2); @@ -356,11 +381,12 @@ LPEMeasureLine::saveDefault() prefs->setInt("/live_effects/measure-line/precision", precision); prefs->setDouble("/live_effects/measure-line/offset_right_left", offset_right_left); prefs->setDouble("/live_effects/measure-line/offset_top_bottom", offset_top_bottom); - prefs->setDouble("/live_effects/measure-line/line_offset", line_offset); + prefs->setDouble("/live_effects/measure-line/origin_offset", origin_offset); prefs->setString("/live_effects/measure-line/unit", (Glib::ustring)unit.get_abbreviation()); - prefs->setInt("/live_effects/measure-line/reverse", reverse); - prefs->setInt("/live_effects/measure-line/color_as_line", color_as_line); - prefs->setInt("/live_effects/measure-line/scale_insensitive", scale_insensitive); + prefs->setBool("/live_effects/measure-line/reverse", reverse); + prefs->setBool("/live_effects/measure-line/color_as_line", color_as_line); + prefs->setBool("/live_effects/measure-line/scale_insensitive", scale_insensitive); + prefs->setBool("/live_effects/measure-line/local_locale", local_locale); } }; //namespace LivePathEffect diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index b03a44705..75faee45d 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -45,7 +45,7 @@ private: Geom::Coord angle; OriginalPathParam origin; ScalarParam curve_linked; - ScalarParam line_offset; + ScalarParam origin_offset; ScalarParam scale; ScalarParam precision; ScalarParam offset_right_left; @@ -57,7 +57,9 @@ private: BoolParam reverse; BoolParam color_as_line; BoolParam scale_insensitive; + BoolParam local_locale; Glib::ustring doc_unit; + static bool alerts_off; /* Geom::Affine affine_over;*/ LPEMeasureLine(const LPEMeasureLine &); LPEMeasureLine &operator=(const LPEMeasureLine &); diff --git a/src/ui/widget/font-selector.cpp b/src/ui/widget/font-selector.cpp index 6b0bdca36..0fcb307eb 100644 --- a/src/ui/widget/font-selector.cpp +++ b/src/ui/widget/font-selector.cpp @@ -19,7 +19,7 @@ FontSelector::FontSelector(Glib::ustring const &label, Glib::ustring const &tool Glib::ustring const &suffix, Glib::ustring const &icon, bool mnemonic) - :_widget(new Gtk::HBox()), expanded(false) + :_widget(new Gtk::HBox()), expanded(false), _label(label) { Gtk::VBox * vbox_expander = Gtk::manage( new Gtk::VBox() ); GtkWidget *fontsel = sp_font_selector_new(); @@ -35,7 +35,7 @@ FontSelector::FontSelector(Glib::ustring const &label, Glib::ustring const &tool pButton->set_tooltip_text(_("Save the changes to font selector")); vbox_expander->pack_start(*Gtk::manage(Glib::wrap(fontsel)), true, true); vbox_expander->pack_start(*pButton, true, true); - expander = Gtk::manage(new Gtk::Expander(Glib::ustring(_("Font Selector:")))); + expander = Gtk::manage(new Gtk::Expander(label)); expander->add(*vbox_expander); expander->set_expanded(expanded); expander->set_spacing(5); @@ -52,9 +52,9 @@ FontSelector::onExpanderChanged() { expanded = expander->get_expanded(); if(expanded) { - expander->set_label (Glib::ustring(_("Font Selector:"))); + expander->set_label (Glib::ustring(_label)); } else { - expander->set_label (Glib::ustring(_("Font Selector: hided"))); + expander->set_label (Glib::ustring(_label + _(" hided"))); } } diff --git a/src/ui/widget/font-selector.h b/src/ui/widget/font-selector.h index cfea54bde..8146bc370 100644 --- a/src/ui/widget/font-selector.h +++ b/src/ui/widget/font-selector.h @@ -54,6 +54,7 @@ public: protected: Gtk::Widget *_widget; bool expanded; + Glib::ustring _label; Gtk::Expander * expander; SPFontSelector *fsel; Glib::ustring _fontspec; -- cgit v1.2.3 From 4450066e940f3751d1a69fdfc0efc8428dedfab2 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 28 Jul 2016 13:16:04 +0200 Subject: Fix little typo (bzr r15017.1.10) --- src/live_effects/lpe-measure-line.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 31b1db7c2..69d1619d8 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -37,7 +37,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : Effect(lpeobject), fontselector(_("Font Selector*"), _("Font Selector"), "fontselector", &wr, this, " "), origin(_("Optional Origin"), _("Optional origin"), "origin", &wr, this), - curve_linked(_("Curve on optional origin*"), _("Curve on optional origin, set 0 to start/end"), "curve_linked", &wr, this, 1), + curve_linked(_("Curve on optional origin"), _("Curve on optional origin, set 0 to start/end"), "curve_linked", &wr, this, 1), origin_offset(_("Optional origin offset*"), _("Optional origin offset"), "origin_offset", &wr, this, 5), scale(_("Scale*"), _("Scaling factor"), "scale", &wr, this, 1.0), precision(_("Number precision*"), _("Number precision"), "precision", &wr, this, 2), -- cgit v1.2.3 From 881b103a91e5668c1f7333ac989e4a968aa92aed Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 29 Jul 2016 12:06:16 +0200 Subject: Improvements to widget redraw (bzr r15017.1.11) --- src/knotholder.cpp | 4 ---- src/live_effects/lpe-ellipse_5pts.cpp | 2 +- src/live_effects/lpe-extrude.cpp | 2 +- src/live_effects/lpe-knot.cpp | 4 ++-- src/live_effects/parameter/parameter.cpp | 38 +++++++++++++++++++++----------- src/live_effects/parameter/parameter.h | 2 ++ src/live_effects/parameter/point.cpp | 31 ++++++++++++++------------ src/live_effects/parameter/point.h | 2 ++ 8 files changed, 50 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/knotholder.cpp b/src/knotholder.cpp index 86ae8f0b8..eed358001 100644 --- a/src/knotholder.cpp +++ b/src/knotholder.cpp @@ -227,12 +227,8 @@ KnotHolder::knot_ungrabbed_handler(SPKnot */*knot*/, guint /*state*/) // write the ones that were changed? Inkscape::LivePathEffect::Effect *lpe = lpeItem->getCurrentLPE(); if (lpe) { - lpe->upd_params = true; LivePathEffectObject *lpeobj = lpe->getLPEObj(); lpeobj->updateRepr(); - //Force redraw for update widgets - Inkscape::Selection *selection = desktop->getSelection(); - selection ->emitModified(); } } diff --git a/src/live_effects/lpe-ellipse_5pts.cpp b/src/live_effects/lpe-ellipse_5pts.cpp index 4c953bcda..088d24b9c 100644 --- a/src/live_effects/lpe-ellipse_5pts.cpp +++ b/src/live_effects/lpe-ellipse_5pts.cpp @@ -171,7 +171,7 @@ LPEEllipse5Pts::doEffect_path (Geom::PathVector const & path_in) // figure out if we have a slice, guarding against rounding errors - Path p(Geom::Point(cos(0), sin(0))); + Geom::Path p(Geom::Point(cos(0), sin(0))); double end = 2 * M_PI; for (s = 0; s < end; s += M_PI_2) { diff --git a/src/live_effects/lpe-extrude.cpp b/src/live_effects/lpe-extrude.cpp index 8b3f4714a..dd1a8c824 100644 --- a/src/live_effects/lpe-extrude.cpp +++ b/src/live_effects/lpe-extrude.cpp @@ -66,7 +66,7 @@ LPEExtrude::doEffect_pwd2 (Geom::Piecewise > const & pwd2 using namespace Geom; // generate connecting lines (the 'sides' of the extrusion) - Path path(Point(0.,0.)); + Geom::Path path(Point(0.,0.)); path.appendNew( extrude_vector.getVector() ); Piecewise > connector = path.toPwSb(); diff --git a/src/live_effects/lpe-knot.cpp b/src/live_effects/lpe-knot.cpp index a033a6c4a..09f35f05e 100644 --- a/src/live_effects/lpe-knot.cpp +++ b/src/live_effects/lpe-knot.cpp @@ -101,7 +101,7 @@ findShadowedTime(Geom::Path const &patha, std::vector const &pt_and Affine mat = from_basis( T, N, pt_and_dir[0] ); mat = mat.inverse(); - Path p = patha * mat; + Geom::Path p = patha * mat; std::vector times; @@ -484,7 +484,7 @@ LPEKnot::doEffect_path (Geom::PathVector const &path_in) // std::cout<<"fusing first and last component\n"; ++beg_comp; --end_comp; - Path first = gpaths[i0].portion(dom.back()); + Geom::Path first = gpaths[i0].portion(dom.back()); //FIXME: stitching should not be necessary (?!?) first.setStitching(true); first.append(gpaths[i0].portion(dom.front())); diff --git a/src/live_effects/parameter/parameter.cpp b/src/live_effects/parameter/parameter.cpp index ae55c84e9..3f8fced4b 100644 --- a/src/live_effects/parameter/parameter.cpp +++ b/src/live_effects/parameter/parameter.cpp @@ -4,8 +4,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "ui/widget/registered-widget.h" -#include #include "live_effects/parameter/parameter.h" #include "live_effects/effect.h" @@ -16,6 +14,8 @@ #include "verbs.h" +#include + #define noLPEREALPARAM_DEBUG namespace Inkscape { @@ -66,7 +66,8 @@ ScalarParam::ScalarParam( const Glib::ustring& label, const Glib::ustring& tip, inc_page(1), add_slider(false), overwrite_widget(false), - hide_widget(no_widget) + hide_widget(no_widget), + _rsu(NULL) { } @@ -117,6 +118,9 @@ ScalarParam::param_set_value(gdouble val) value = max; if (value < min) value = min; + if (_rsu) { + _rsu->setValue(val); + } } void @@ -138,7 +142,9 @@ ScalarParam::param_set_range(gdouble min, gdouble max) } else { this->max = SCALARPARAM_G_MAXDOUBLE; } - + if (_rsu) { + _rsu->setRange(this->min, this->max); + } param_set_value(value); // reset value to see whether it is in ranges } @@ -161,22 +167,22 @@ Gtk::Widget * ScalarParam::param_newWidget() { if(!hide_widget){ - Inkscape::UI::Widget::RegisteredScalar *rsu = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalar( + _rsu = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalar( param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc() ) ); - rsu->setValue(value); - rsu->setDigits(digits); - rsu->setIncrements(inc_step, inc_page); - rsu->setRange(min, max); - rsu->setProgrammatically = false; + _rsu->setValue(value); + _rsu->setDigits(digits); + _rsu->setIncrements(inc_step, inc_page); + _rsu->setRange(min, max); + _rsu->setProgrammatically = false; if (add_slider) { - rsu->addSlider(); + _rsu->addSlider(); } if(!overwrite_widget){ - rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change scalar parameter")); + _rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change scalar parameter")); } param_effect->upd_params = false; - return dynamic_cast (rsu); + return dynamic_cast (_rsu); } else { return NULL; } @@ -186,6 +192,9 @@ void ScalarParam::param_set_digits(unsigned digits) { this->digits = digits; + if (_rsu) { + _rsu->setDigits(this->digits); + } } void @@ -193,6 +202,9 @@ ScalarParam::param_set_increments(double step, double page) { inc_step = step; inc_page = page; + if (_rsu) { + _rsu->setIncrements(inc_step, inc_page); + } } diff --git a/src/live_effects/parameter/parameter.h b/src/live_effects/parameter/parameter.h index 8556b0d9a..63c55203e 100644 --- a/src/live_effects/parameter/parameter.h +++ b/src/live_effects/parameter/parameter.h @@ -12,6 +12,7 @@ #include #include <2geom/forward.h> #include <2geom/pathvector.h> +#include "ui/widget/registered-widget.h" // In gtk2, this wasn't an issue; we could toss around // G_MAXDOUBLE and not worry about size allocations. But @@ -140,6 +141,7 @@ protected: private: ScalarParam(const ScalarParam&); ScalarParam& operator=(const ScalarParam&); + Inkscape::UI::Widget::RegisteredScalar *_rsu; }; } //namespace LivePathEffect diff --git a/src/live_effects/parameter/point.cpp b/src/live_effects/parameter/point.cpp index 90a5b252b..3442fd851 100644 --- a/src/live_effects/parameter/point.cpp +++ b/src/live_effects/parameter/point.cpp @@ -4,7 +4,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "ui/widget/registered-widget.h" #include "live_effects/parameter/point.h" #include "live_effects/effect.h" #include "svg/svg.h" @@ -30,7 +29,8 @@ PointParam::PointParam( const Glib::ustring& label, const Glib::ustring& tip, : Parameter(label, tip, key, wr, effect), defvalue(default_value), liveupdate(live_update), - knoth(NULL) + knoth(NULL), + _pointwdg(NULL) { knot_shape = SP_KNOT_SHAPE_DIAMOND; knot_mode = SP_KNOT_MODE_XOR; @@ -81,6 +81,9 @@ PointParam::param_setValue(Geom::Point newpoint, bool write) if(knoth && liveupdate){ knoth->update_knots(); } + if (_pointwdg) { + _pointwdg->setValue( newpoint ); + } } bool @@ -116,7 +119,7 @@ PointParam::param_transform_multiply(Geom::Affine const& postmul, bool /*set*/) Gtk::Widget * PointParam::param_newWidget() { - Inkscape::UI::Widget::RegisteredTransformedPoint * pointwdg = Gtk::manage( + _pointwdg = Gtk::manage( new Inkscape::UI::Widget::RegisteredTransformedPoint( param_label, param_tooltip, param_key, @@ -126,13 +129,13 @@ PointParam::param_newWidget() // TODO: fix to get correct desktop (don't use SP_ACTIVE_DESKTOP) SPDesktop *desktop = SP_ACTIVE_DESKTOP; Geom::Affine transf = desktop->doc2dt(); - pointwdg->setTransform(transf); - pointwdg->setValue( *this ); - pointwdg->clearProgrammatically(); - pointwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change point parameter")); + _pointwdg->setTransform(transf); + _pointwdg->setValue( *this ); + _pointwdg->clearProgrammatically(); + _pointwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change point parameter")); Gtk::HBox * hbox = Gtk::manage( new Gtk::HBox() ); - static_cast(hbox)->pack_start(*pointwdg, true, true); + static_cast(hbox)->pack_start(*_pointwdg, true, true); static_cast(hbox)->show_all_children(); param_effect->upd_params = false; return dynamic_cast (hbox); @@ -191,13 +194,13 @@ void PointParamKnotHolderEntity::knot_click(guint state) { if (state & GDK_CONTROL_MASK) { - if (state & GDK_MOD1_MASK) { - this->pparam->param_set_default(); - SPLPEItem * splpeitem = dynamic_cast(item); - if(splpeitem){ - sp_lpe_item_update_patheffect(splpeitem, false, false); - } + if (state & GDK_MOD1_MASK) { + this->pparam->param_set_default(); + SPLPEItem * splpeitem = dynamic_cast(item); + if(splpeitem){ + sp_lpe_item_update_patheffect(splpeitem, false, false); } + } } } diff --git a/src/live_effects/parameter/point.h b/src/live_effects/parameter/point.h index d41e8a710..62c6fb83d 100644 --- a/src/live_effects/parameter/point.h +++ b/src/live_effects/parameter/point.h @@ -11,6 +11,7 @@ #include #include <2geom/point.h> +#include "ui/widget/registered-widget.h" #include "live_effects/parameter/parameter.h" #include "knot-holder-entity.h" @@ -61,6 +62,7 @@ private: SPKnotModeType knot_mode; guint32 knot_color; gchar *handle_tip; + Inkscape::UI::Widget::RegisteredTransformedPoint * _pointwdg; }; -- cgit v1.2.3 From 53500549df51879d6a7aaec5a0c8c37ca7087817 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 29 Jul 2016 20:28:00 +0200 Subject: Add orientation and alow unsort combobox enum widget (bzr r15017.1.12) --- src/live_effects/lpe-measure-line.cpp | 437 ++++++++++++++++++++++------------ src/live_effects/lpe-measure-line.h | 19 +- src/live_effects/parameter/enum.h | 8 +- src/ui/widget/combo-enums.h | 9 +- src/ui/widget/registered-enums.h | 6 +- src/ui/widget/registered-widget.h | 2 + 6 files changed, 313 insertions(+), 168 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 69d1619d8..6145f7592 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -8,6 +8,7 @@ */ #include "live_effects/lpe-measure-line.h" #include "inkscape.h" +#include "xml/node.h" #include "uri.h" #include "uri-references.h" #include "preferences.h" @@ -33,9 +34,21 @@ using namespace Geom; namespace Inkscape { namespace LivePathEffect { +static const Util::EnumData OrientationMethodData[] = { + { OM_HORIZONTAL, N_("Horizontal"), "horizontal" }, + { OM_VERTICAL, N_("Vertical"), "vertical" }, + { OM_PARALLEL, N_("Parallel"), "parallel" }, + { OM_PARALLEL_VERTICAL, N_("Parallel and vertical,"), "parallel_vertical" }, + { OM_PARALLEL_HORIZONTAL, N_("Parallel and horizontal"), "parallel_horizontal" }, + { OM_VERTICAL_HORIZONTAL, N_("Vertical and horizontal"), "vertical_horizontal" }, + { OM_PARALLEL_VERTICAL_HORIZONTAL, N_("Parallel, vertical and horizontal"), "parallel_vertical_horizontal" } +}; +static const Util::EnumDataConverter OMConverter(OrientationMethodData, OM_END); + LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : Effect(lpeobject), fontselector(_("Font Selector*"), _("Font Selector"), "fontselector", &wr, this, " "), + orientation(_("Orientation"), _("Orientation method"), "orientation", OMConverter, &wr, this, OM_PARALLEL, false), origin(_("Optional Origin"), _("Optional origin"), "origin", &wr, this), curve_linked(_("Curve on optional origin"), _("Curve on optional origin, set 0 to start/end"), "curve_linked", &wr, this, 1), origin_offset(_("Optional origin offset*"), _("Optional origin offset"), "origin_offset", &wr, this, 5), @@ -49,11 +62,10 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : reverse(_("To other side*"), _("To other side"), "reverse", &wr, this, false), color_as_line(_("Measure color as line*"), _("Measure color as line"), "color_as_line", &wr, this, false), scale_insensitive(_("Scale insensitive*"), _("Scale insensitive to transforms in element, parents..."), "scale_insensitive", &wr, this, true), - local_locale(_("Local Number Format*"), _("Local number format"), "local_locale", &wr, this, true), - pos(0,0), - angle(0) + local_locale(_("Local Number Format*"), _("Local number format"), "local_locale", &wr, this, true) { registerParameter(&fontselector); + registerParameter(&orientation); registerParameter(&origin); registerParameter(&curve_linked); registerParameter(&origin_offset); @@ -80,7 +92,6 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : color_as_line.param_update_default(prefs->getBool("/live_effects/measure-line/color_as_line")); scale_insensitive.param_update_default(prefs->getBool("/live_effects/measure-line/scale_insensitive")); local_locale.param_update_default(prefs->getBool("/live_effects/measure-line/local_locale")); - rtext = NULL; precision.param_set_range(0, 100); precision.param_set_increments(1, 1); precision.param_set_digits(0); @@ -143,175 +154,279 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) Geom::PathVector pathvector = sp_path->get_original_curve()->get_pathvector(); if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); - Geom::Point s = pathvector.initialPoint(); - Geom::Point e = pathvector.finalPoint(); - if (origin.linksToPath() && origin.getObject() && !origin.get_pathvector().empty()) { - pathvector = origin.get_pathvector(); - size_t ncurves = pathvector.curveCount(); - curve_linked.param_set_range(1, ncurves); - if(previous_ncurves != ncurves) { - this->upd_params = true; - previous_ncurves = ncurves; + std::vector orientations; + std::vector orientations_remove; + if ( orientation == OM_HORIZONTAL || + orientation == OM_PARALLEL_VERTICAL_HORIZONTAL || + orientation == OM_PARALLEL_HORIZONTAL || + orientation == OM_VERTICAL_HORIZONTAL) + { + orientations.push_back(OM_HORIZONTAL); + } else { + orientations_remove.push_back(OM_HORIZONTAL); + } + if ( orientation == OM_VERTICAL || + orientation == OM_PARALLEL_VERTICAL_HORIZONTAL || + orientation == OM_PARALLEL_VERTICAL || + orientation == OM_VERTICAL_HORIZONTAL) + { + orientations.push_back(OM_VERTICAL); + } else { + orientations_remove.push_back(OM_VERTICAL); + } + if ( orientation == OM_PARALLEL || + orientation == OM_PARALLEL_VERTICAL_HORIZONTAL || + orientation == OM_PARALLEL_VERTICAL || + orientation == OM_PARALLEL_HORIZONTAL) + { + orientations.push_back(OM_PARALLEL); + } else { + orientations_remove.push_back(OM_PARALLEL); + } + for (std::vector::const_iterator om_it = orientations.begin(); om_it != orientations.end(); ++om_it) { + Geom::Point s = pathvector.initialPoint(); + Geom::Point e = pathvector.finalPoint(); + Glib::ustring orientation_str; + Inkscape::XML::Node *rtext = NULL; + if (*om_it == OM_VERTICAL) { + orientation_str = "vertical"; + } + if (*om_it == OM_HORIZONTAL) { + orientation_str = "horizontal"; } - s = pathvector.pointAt(curve_linked -1); - e = pathvector.pointAt(curve_linked); + if (*om_it == OM_PARALLEL) { + orientation_str = "parallel"; + } + if (origin.linksToPath() && origin.getObject() && !origin.get_pathvector().empty()) { + pathvector = origin.get_pathvector(); + size_t ncurves = pathvector.curveCount(); + curve_linked.param_set_range(1, ncurves); + if(previous_ncurves != ncurves) { + this->upd_params = true; + previous_ncurves = ncurves; + } + s = pathvector.pointAt(curve_linked -1); + e = pathvector.pointAt(curve_linked); + if(*om_it == OM_VERTICAL) { + Coord xpos = std::max(s[Geom::X],e[Geom::X]); + if (reverse) { + xpos = std::min(s[Geom::X],e[Geom::X]); + } + s[Geom::X] = xpos; + e[Geom::X] = xpos; + } + if(*om_it == OM_HORIZONTAL) { + Coord ypos = std::max(s[Geom::Y],e[Geom::Y]); + if (reverse) { + ypos = std::min(s[Geom::Y],e[Geom::Y]); + } + s[Geom::Y] = ypos; + e[Geom::Y] = ypos; + } + Geom::Ray ray(s,e); + Geom::Coord angle = ray.angle(); + if (reverse) { + angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); + if (angle < 0) angle += 2*M_PI; + } + Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); + if (angle_cross < 0) angle_cross += 2*M_PI; + s = s - Point::polar(angle_cross, origin_offset); + e = e - Point::polar(angle_cross, origin_offset); + Geom::Path path; + path.start( s ); + path.appendNew( e ); + Geom::PathVector line_upd; + line_upd.push_back(path); + Inkscape::XML::Node *line = SP_OBJECT(sp_path)->getRepr(); + gchar *str = sp_svg_write_path(line_upd); + line->setAttribute("inkscape:original-d", str); + } else { + if(*om_it == OM_VERTICAL) { + Coord xpos = std::max(s[Geom::X],e[Geom::X]); + if (reverse) { + xpos = std::min(s[Geom::X],e[Geom::X]); + } + s[Geom::X] = xpos; + e[Geom::X] = xpos; + } + if(*om_it == OM_HORIZONTAL) { + Coord ypos = std::max(s[Geom::Y],e[Geom::Y]); + if (reverse) { + ypos = std::min(s[Geom::Y],e[Geom::Y]); + } + s[Geom::Y] = ypos; + e[Geom::Y] = ypos; + } + } + double length = Geom::distance(s, e) * scale; + Geom::Point pos = Geom::middle_point(s,e); Geom::Ray ray(s,e); - angle = ray.angle(); + Geom::Coord angle = ray.angle(); + doc_unit = Inkscape::Util::unit_table.getUnit(desktop->doc()->getRoot()->height.unit)->abbr; if (reverse) { angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); if (angle < 0) angle += 2*M_PI; } + Geom::Point newpos = pos - Point::polar(angle, offset_right_left); Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); if (angle_cross < 0) angle_cross += 2*M_PI; - s = s - Point::polar(angle_cross, origin_offset); - e = e - Point::polar(angle_cross, origin_offset); - Geom::Path path; - path.start( s ); - path.appendNew( e ); - Geom::PathVector line_upd; - line_upd.push_back(path); - Inkscape::XML::Node *line = SP_OBJECT(sp_path)->getRepr(); - gchar *str = sp_svg_write_path(line_upd); - line->setAttribute("inkscape:original-d", str); - } - length = Geom::distance(s, e) * scale; - pos = Geom::middle_point(s,e); - Geom::Ray ray(s,e); - angle = ray.angle(); - doc_unit = Inkscape::Util::unit_table.getUnit(desktop->doc()->getRoot()->height.unit)->abbr; - if (reverse) { - angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); - if (angle < 0) angle += 2*M_PI; - } - Geom::Point newpos = pos - Point::polar(angle, offset_right_left); - Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); - if (angle_cross < 0) angle_cross += 2*M_PI; - newpos = newpos - Point::polar(angle_cross, offset_top_bottom); - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_mlsize").c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - Inkscape::XML::Node *rtspan = NULL; - if (elemref = SVGElemRef->getObject()) { - rtext = elemref->getRepr(); - sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); - sp_repr_set_svg_double(rtext, "y", newpos[Geom::Y]); - } else { - rtext = xml_doc->createElement("svg:text"); - rtext->setAttribute("xml:space", "preserve"); - rtext->setAttribute("sodipodi:insensitive", "true"); - rtext->setAttribute("id", ((Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_mlsize").c_str()); - /* Set style */ - sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); - sp_repr_set_svg_double(rtext, "y", newpos[Geom::Y]); - /* Create */ - rtspan = xml_doc->createElement("svg:tspan"); - rtspan->setAttribute("sodipodi:role", "line"); - } - SPCSSAttr *css = sp_repr_css_attr_new(); - Glib::ustring fontspec = fontselector.param_readFontSpec(fontselector.param_getSVGValue()); - double fontsize = fontselector.param_readFontSize(fontselector.param_getSVGValue()); - fontlister->fill_css( css, fontspec ); - std::stringstream font_size; - font_size.imbue(std::locale::classic()); - font_size << fontsize << "pt"; - sp_repr_css_set_property (css, "font-size", font_size.str().c_str()); - sp_repr_css_set_property (css, "font-style", "normal"); - sp_repr_css_set_property (css, "font-weight", "normal"); - sp_repr_css_set_property (css, "line-height", "125%"); - sp_repr_css_set_property (css, "letter-spacing", "0"); - sp_repr_css_set_property (css, "word-spacing", "0"); - sp_repr_css_set_property (css, "text-align", "center"); - sp_repr_css_set_property (css, "text-anchor", "middle"); - if (color_as_line) { - if (lpeitem->style) { - if (lpeitem->style->stroke.isPaintserver()) { - SPPaintServer * server = lpeitem->style->getStrokePaintServer(); - if (server) { - Glib::ustring str; - str += "url(#"; - str += server->getId(); - str += ")"; - sp_repr_css_set_property (css, "fill", str.c_str()); + newpos = newpos - Point::polar(angle_cross, offset_top_bottom); + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_DINnumber_" + orientation_str).c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *rtspan = NULL; + if (elemref = SVGElemRef->getObject()) { + rtext = elemref->getRepr(); + sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); + sp_repr_set_svg_double(rtext, "y", newpos[Geom::Y]); + } else { + rtext = xml_doc->createElement("svg:text"); + rtext->setAttribute("xml:space", "preserve"); + rtext->setAttribute("sodipodi:insensitive", "true"); + rtext->setAttribute("id", ((Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_DINnumber_" + orientation_str).c_str()); + /* Set style */ + sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); + sp_repr_set_svg_double(rtext, "y", newpos[Geom::Y]); + /* Create */ + rtspan = xml_doc->createElement("svg:tspan"); + rtspan->setAttribute("sodipodi:role", "line"); + } + SPCSSAttr *css = sp_repr_css_attr_new(); + Glib::ustring fontspec = fontselector.param_readFontSpec(fontselector.param_getSVGValue()); + double fontsize = fontselector.param_readFontSize(fontselector.param_getSVGValue()); + fontlister->fill_css( css, fontspec ); + std::stringstream font_size; + font_size.imbue(std::locale::classic()); + font_size << fontsize << "pt"; + sp_repr_css_set_property (css, "font-size", font_size.str().c_str()); + sp_repr_css_set_property (css, "font-style", "normal"); + sp_repr_css_set_property (css, "font-weight", "normal"); + sp_repr_css_set_property (css, "line-height", "125%"); + sp_repr_css_set_property (css, "letter-spacing", "0"); + sp_repr_css_set_property (css, "word-spacing", "0"); + sp_repr_css_set_property (css, "text-align", "center"); + sp_repr_css_set_property (css, "text-anchor", "middle"); + if (color_as_line) { + if (lpeitem->style) { + if (lpeitem->style->stroke.isPaintserver()) { + SPPaintServer * server = lpeitem->style->getStrokePaintServer(); + if (server) { + Glib::ustring str; + str += "url(#"; + str += server->getId(); + str += ")"; + sp_repr_css_set_property (css, "fill", str.c_str()); + } + } else if (lpeitem->style->stroke.isColor()) { + gchar c[64]; + sp_svg_write_color (c, sizeof(c), lpeitem->style->stroke.value.color.toRGBA32(SP_SCALE24_TO_FLOAT(lpeitem->style->stroke_opacity.value))); + sp_repr_css_set_property (css, "fill", c); + } else { + sp_repr_css_set_property (css, "fill", "#000000"); } - } else if (lpeitem->style->stroke.isColor()) { - gchar c[64]; - sp_svg_write_color (c, sizeof(c), lpeitem->style->stroke.value.color.toRGBA32(SP_SCALE24_TO_FLOAT(lpeitem->style->stroke_opacity.value))); - sp_repr_css_set_property (css, "fill", c); } else { - sp_repr_css_set_property (css, "fill", "#000000"); + sp_repr_css_unset_property (css, "#000000"); } } else { - sp_repr_css_unset_property (css, "#000000"); + sp_repr_css_set_property (css, "fill", "#000000"); } - } else { - sp_repr_css_set_property (css, "fill", "#000000"); - } - sp_repr_css_set_property (css, "fill-opacity", "1"); - sp_repr_css_set_property (css, "stroke", "none"); - Glib::ustring css_str; - sp_repr_css_write_string(css,css_str); - if (!rtspan) { - rtspan = rtext->firstChild(); - } - rtspan->setAttribute("style", css_str.c_str()); - sp_repr_css_attr_unref (css); - if (!elemref) { - rtext->addChild(rtspan, NULL); - Inkscape::GC::release(rtspan); - } - /* Create TEXT */ - if (!scale_insensitive) { - Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); - length *= (affinetransform.expansionX() + affinetransform.expansionY()) / 2.0; - } - length = Inkscape::Util::Quantity::convert(length, doc_unit.c_str(), unit.get_abbreviation()); - std::stringstream length_str; - length_str.setf(std::ios::fixed, std::ios::floatfield); - length_str.precision(precision); - if (local_locale) { - length_str.imbue(std::locale("")); - } else { - length_str.imbue(std::locale::classic()); - } - length_str << length << unit.get_abbreviation(); - Inkscape::XML::Node *rstring = NULL; - if (!elemref) { - rstring = xml_doc->createTextNode(length_str.str().c_str()); - rtspan->addChild(rstring, NULL); - Inkscape::GC::release(rstring); - } else { - rstring = rtspan->firstChild(); - rstring->setContent(length_str.str().c_str()); + sp_repr_css_set_property (css, "fill-opacity", "1"); + sp_repr_css_set_property (css, "stroke", "none"); + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + if (!rtspan) { + rtspan = rtext->firstChild(); + } + rtspan->setAttribute("style", css_str.c_str()); + sp_repr_css_attr_unref (css); + if (!elemref) { + rtext->addChild(rtspan, NULL); + Inkscape::GC::release(rtspan); + } + /* Create TEXT */ + if (!scale_insensitive) { + Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); + length *= (affinetransform.expansionX() + affinetransform.expansionY()) / 2.0; + } + length = Inkscape::Util::Quantity::convert(length, doc_unit.c_str(), unit.get_abbreviation()); + std::stringstream length_str; + length_str.setf(std::ios::fixed, std::ios::floatfield); + length_str.precision(precision); + if (local_locale) { + length_str.imbue(std::locale("")); + } else { + length_str.imbue(std::locale::classic()); + } + length_str << length << unit.get_abbreviation(); + Inkscape::XML::Node *rstring = NULL; + if (!elemref) { + rstring = xml_doc->createTextNode(length_str.str().c_str()); + rtspan->addChild(rstring, NULL); + Inkscape::GC::release(rstring); + } else { + rstring = rtspan->firstChild(); + rstring->setContent(length_str.str().c_str()); + } + SPObject * text_obj = NULL; + if (!elemref) { + text_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(rtext)); + Inkscape::GC::release(rtext); + } else { + text_obj = desktop->currentLayer()->get_child_by_repr(rtext); + } + Geom::Affine affine = Geom::Affine(Geom::Translate(newpos).inverse()); + affine *= Geom::Rotate(angle); + affine *= Geom::Translate(newpos); + SP_ITEM(text_obj)->transform = affine * i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); + text_obj->updateRepr(); } - SPObject * text_obj = NULL; - if (!elemref) { - text_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(rtext)); - Inkscape::GC::release(rtext); - } else { - text_obj = desktop->currentLayer()->get_child_by_repr(rtext); + for (std::vector::const_iterator omdel_it = orientations_remove.begin(); omdel_it != orientations_remove.end(); ++omdel_it) { + Glib::ustring orientation_str; + if (*omdel_it == OM_VERTICAL) { + orientation_str = "vertical"; + } + if (*omdel_it == OM_HORIZONTAL) { + orientation_str = "horizontal"; + } + if (*omdel_it == OM_PARALLEL) { + orientation_str = "parallel"; + } + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_DINnumber_" + orientation_str).c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + if (elemref = SVGElemRef->getObject()) { + elemref->deleteObject(); + } } - Geom::Affine affine = Geom::Affine(Geom::Translate(newpos).inverse()); - affine *= Geom::Rotate(angle); - affine *= Geom::Translate(newpos); - SP_ITEM(text_obj)->transform = affine * i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); - text_obj->updateRepr(); } } } void LPEMeasureLine::doOnRemove (SPLPEItem const* /*lpeitem*/) { - if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - if (rtext) { - rtext->setAttribute("sodipodi:insensitive", NULL); - SPObject * text_obj = desktop->currentLayer()->get_child_by_repr(rtext); - if (text_obj) { - text_obj->updateRepr(); - text_obj->deleteObject(); - } - } - } +// if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { +// if (horizontal_text) { +// SPObject * text_obj = desktop->currentLayer()->get_child_by_repr(horizontal_text); +// if (text_obj) { +// text_obj->deleteObject(); +// } +// } +// if (vertical_text) { +// SPObject * text_obj = desktop->currentLayer()->get_child_by_repr(vertical_text); +// if (text_obj) { +// text_obj->deleteObject(); +// } +// } +// if (parallel_text) { +// SPObject * text_obj = desktop->currentLayer()->get_child_by_repr(parallel_text); +// if (text_obj) { +// text_obj->deleteObject(); +// } +// } +// } } Gtk::Widget *LPEMeasureLine::newWidget() @@ -357,6 +472,8 @@ LPEMeasureLine::doEffect_path(Geom::PathVector const &path_in) Geom::Path path; Geom::Point s = path_in.initialPoint(); Geom::Point e = path_in.finalPoint(); + Geom::Ray ray(s,e); + Geom::Coord angle = ray.angle(); if (reverse) { angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); if (angle < 0) angle += 2*M_PI; @@ -365,6 +482,22 @@ LPEMeasureLine::doEffect_path(Geom::PathVector const &path_in) angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); if (angle < 0) angle += 2*M_PI; e = e - Point::polar(angle, gap_end); + if(orientation == OM_VERTICAL) { + Coord xpos = std::max(s[Geom::X],e[Geom::X]); + if (reverse) { + xpos = std::min(s[Geom::X],e[Geom::X]); + } + s[Geom::X] = xpos; + e[Geom::X] = xpos; + } + if(orientation == OM_HORIZONTAL) { + Coord ypos = std::max(s[Geom::Y],e[Geom::Y]); + if (reverse) { + ypos = std::min(s[Geom::Y],e[Geom::Y]); + } + s[Geom::Y] = ypos; + e[Geom::Y] = ypos; + } path.start( s ); path.appendNew( e ); Geom::PathVector output; diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 75faee45d..67d27408a 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -11,6 +11,7 @@ */ #include "live_effects/effect.h" +#include "live_effects/parameter/enum.h" #include "live_effects/parameter/font.h" #include "live_effects/parameter/text.h" #include "live_effects/parameter/unit.h" @@ -20,12 +21,21 @@ #include <2geom/angle.h> #include <2geom/ray.h> #include <2geom/point.h> -#include "xml/node.h" - namespace Inkscape { namespace LivePathEffect { +enum OrientationMethod { + OM_HORIZONTAL, + OM_VERTICAL, + OM_PARALLEL, + OM_PARALLEL_VERTICAL, + OM_PARALLEL_HORIZONTAL, + OM_VERTICAL_HORIZONTAL, + OM_PARALLEL_VERTICAL_HORIZONTAL, + OM_END +}; + class LPEMeasureLine : public Effect { public: LPEMeasureLine(LivePathEffectObject *lpeobject); @@ -37,12 +47,9 @@ public: void saveDefault(); virtual Gtk::Widget *newWidget(); private: - double length; FontParam fontselector; Inkscape::FontLister *fontlister; - Inkscape::XML::Node *rtext; - Geom::Point pos; - Geom::Coord angle; + EnumParam orientation; OriginalPathParam origin; ScalarParam curve_linked; ScalarParam origin_offset; diff --git a/src/live_effects/parameter/enum.h b/src/live_effects/parameter/enum.h index 2340663c3..dbfc68623 100644 --- a/src/live_effects/parameter/enum.h +++ b/src/live_effects/parameter/enum.h @@ -27,12 +27,14 @@ public: const Util::EnumDataConverter& c, Inkscape::UI::Widget::Registry* wr, Effect* effect, - E default_value) + E default_value, + bool sort = true) : Parameter(label, tip, key, wr, effect) { enumdataconv = &c; defvalue = default_value; value = defvalue; + sorted = sort; }; virtual ~EnumParam() { }; @@ -40,12 +42,11 @@ public: virtual Gtk::Widget * param_newWidget() { Inkscape::UI::Widget::RegisteredEnum *regenum = Gtk::manage ( new Inkscape::UI::Widget::RegisteredEnum( param_label, param_tooltip, - param_key, *enumdataconv, *param_wr, param_effect->getRepr(), param_effect->getSPDoc() ) ); + param_key, *enumdataconv, *param_wr, param_effect->getRepr(), param_effect->getSPDoc(), sorted ) ); regenum->set_active_by_id(value); regenum->combobox()->setProgrammatically = false; regenum->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change enumeration parameter")); - return dynamic_cast (regenum); }; @@ -86,6 +87,7 @@ private: E value; E defvalue; + bool sorted; const Util::EnumDataConverter * enumdataconv; }; diff --git a/src/ui/widget/combo-enums.h b/src/ui/widget/combo-enums.h index 4678ab83b..e7524ac71 100644 --- a/src/ui/widget/combo-enums.h +++ b/src/ui/widget/combo-enums.h @@ -16,7 +16,6 @@ #include #include "attr-widget.h" #include "util/enums.h" - #include namespace Inkscape { @@ -190,9 +189,11 @@ public: const Util::EnumDataConverter& c, Glib::ustring const &suffix = "", Glib::ustring const &icon = "", - bool mnemonic = true) - : Labelled(label, tooltip, new ComboBoxEnum(c), suffix, icon, mnemonic) - { } + bool mnemonic = true, + bool sorted = true) + : Labelled(label, tooltip, new ComboBoxEnum(c, SP_ATTR_INVALID, sorted), suffix, icon, mnemonic) + { + } ComboBoxEnum* getCombobox() { return static_cast< ComboBoxEnum* > (_widget); diff --git a/src/ui/widget/registered-enums.h b/src/ui/widget/registered-enums.h index 9e1682c7d..1d5074836 100644 --- a/src/ui/widget/registered-enums.h +++ b/src/ui/widget/registered-enums.h @@ -33,11 +33,11 @@ public: const Util::EnumDataConverter& c, Registry& wr, Inkscape::XML::Node* repr_in = NULL, - SPDocument *doc_in = NULL ) - : RegisteredWidget< LabelledComboBoxEnum >(label, tip, c) + SPDocument *doc_in = NULL, + bool sorted = true ) + : RegisteredWidget< LabelledComboBoxEnum >(label, tip, c, (const Glib::ustring &)"", (const Glib::ustring &)"", true, sorted) { RegisteredWidget< LabelledComboBoxEnum >::init_parent(key, wr, repr_in, doc_in); - _changed_connection = combobox()->signal_changed().connect (sigc::mem_fun (*this, &RegisteredEnum::on_changed)); } diff --git a/src/ui/widget/registered-widget.h b/src/ui/widget/registered-widget.h index 3c8205058..2b4d98b88 100644 --- a/src/ui/widget/registered-widget.h +++ b/src/ui/widget/registered-widget.h @@ -78,6 +78,8 @@ protected: RegisteredWidget( A& a, B& b, C c, D d ): W( a, b, c, d ) { construct(); } template< typename A, typename B, typename C, typename D, typename E , typename F> RegisteredWidget( A& a, B& b, C c, D& d, E& e, F* f): W( a, b, c, d, e, f) { construct(); } + template< typename A, typename B, typename C, typename D, typename E , typename F, typename G> + RegisteredWidget( A& a, B& b, C& c, D& d, E& e, F f, G& g): W( a, b, c, d, e, f, g) { construct(); } virtual ~RegisteredWidget() {}; -- cgit v1.2.3 From d60fb000cfc3717ef51b716d9ccb9b63ecb38aa8 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 30 Jul 2016 01:44:17 +0200 Subject: Remove font-Dialog and useGtk::FontSelector instead (bzr r15017.1.13) --- src/live_effects/CMakeLists.txt | 4 +- src/live_effects/lpe-measure-line.cpp | 27 +++--- src/live_effects/lpe-measure-line.h | 5 +- src/live_effects/parameter/Makefile_insert | 2 + src/live_effects/parameter/font.cpp | 129 ----------------------------- src/live_effects/parameter/font.h | 78 ----------------- src/live_effects/parameter/fontbutton.cpp | 92 ++++++++++++++++++++ src/live_effects/parameter/fontbutton.h | 62 ++++++++++++++ src/ui/CMakeLists.txt | 4 +- src/ui/widget/Makefile_insert | 4 +- src/ui/widget/font-button.cpp | 58 +++++++++++++ src/ui/widget/font-button.h | 63 ++++++++++++++ src/ui/widget/font-selector.cpp | 115 ------------------------- src/ui/widget/font-selector.h | 82 ------------------ src/ui/widget/registered-widget.cpp | 24 +++--- src/ui/widget/registered-widget.h | 12 +-- 16 files changed, 316 insertions(+), 445 deletions(-) delete mode 100644 src/live_effects/parameter/font.cpp delete mode 100644 src/live_effects/parameter/font.h create mode 100644 src/live_effects/parameter/fontbutton.cpp create mode 100644 src/live_effects/parameter/fontbutton.h create mode 100644 src/ui/widget/font-button.cpp create mode 100644 src/ui/widget/font-button.h delete mode 100644 src/ui/widget/font-selector.cpp delete mode 100644 src/ui/widget/font-selector.h (limited to 'src') diff --git a/src/live_effects/CMakeLists.txt b/src/live_effects/CMakeLists.txt index c3d740862..784317090 100644 --- a/src/live_effects/CMakeLists.txt +++ b/src/live_effects/CMakeLists.txt @@ -69,7 +69,7 @@ set(live_effects_SRC parameter/powerstrokepointarray.cpp parameter/random.cpp parameter/text.cpp - parameter/font.cpp + parameter/fontbutton.cpp parameter/togglebutton.cpp parameter/transformedpoint.cpp parameter/unit.cpp @@ -151,7 +151,7 @@ set(live_effects_SRC parameter/powerstrokepointarray.h parameter/random.h parameter/text.h - parameter/font.h + parameter/fontbutton.h parameter/togglebutton.h parameter/transformedpoint.h parameter/unit.h diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 6145f7592..5df3d499e 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -7,6 +7,8 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ #include "live_effects/lpe-measure-line.h" +#include +#include #include "inkscape.h" #include "xml/node.h" #include "uri.h" @@ -47,13 +49,13 @@ static const Util::EnumDataConverter OMConverter(OrientationM LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : Effect(lpeobject), - fontselector(_("Font Selector*"), _("Font Selector"), "fontselector", &wr, this, " "), + fontbutton(_("Font*"), _("Font Selector"), "fontbutton", &wr, this), orientation(_("Orientation"), _("Orientation method"), "orientation", OMConverter, &wr, this, OM_PARALLEL, false), origin(_("Optional Origin"), _("Optional origin"), "origin", &wr, this), curve_linked(_("Curve on optional origin"), _("Curve on optional origin, set 0 to start/end"), "curve_linked", &wr, this, 1), origin_offset(_("Optional origin offset*"), _("Optional origin offset"), "origin_offset", &wr, this, 5), scale(_("Scale*"), _("Scaling factor"), "scale", &wr, this, 1.0), - precision(_("Number precision*"), _("Number precision"), "precision", &wr, this, 2), + precision(_("Precision*"), _("Precision"), "precision", &wr, this, 2), offset_right_left(_("Offset right left*"), _("Offset right left"), "offset_right_left", &wr, this, 0), offset_top_bottom(_("Offset top bottom*"), _("Offset top bottom"), "offset_top_bottom", &wr, this, 5), gap_start(_("Gap to line from origin"), _("Gap to line from origin, without affecting measure"), "gap_start", &wr, this, 0), @@ -64,7 +66,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : scale_insensitive(_("Scale insensitive*"), _("Scale insensitive to transforms in element, parents..."), "scale_insensitive", &wr, this, true), local_locale(_("Local Number Format*"), _("Local number format"), "local_locale", &wr, this, true) { - registerParameter(&fontselector); + registerParameter(&fontbutton); registerParameter(&orientation); registerParameter(&origin); registerParameter(&curve_linked); @@ -81,7 +83,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : registerParameter(&scale_insensitive); registerParameter(&local_locale); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - fontselector.param_update_default(prefs->getString("/live_effects/measure-line/fontselector")); + fontbutton.param_update_default(prefs->getString("/live_effects/measure-line/fontbutton")); scale.param_update_default(prefs->getDouble("/live_effects/measure-line/scale", 1.0)); precision.param_update_default(prefs->getInt("/live_effects/measure-line/precision", 2)); offset_right_left.param_update_default(prefs->getDouble("/live_effects/measure-line/offset_right_left", 0.0)); @@ -116,7 +118,6 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : gap_end.param_set_range(-999999.0, 999999.0); gap_end.param_set_increments(1, 1); gap_end.param_set_digits(2); - fontlister = Inkscape::FontLister::get_instance(); } bool LPEMeasureLine::alerts_off = false; @@ -294,15 +295,14 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) rtspan->setAttribute("sodipodi:role", "line"); } SPCSSAttr *css = sp_repr_css_attr_new(); - Glib::ustring fontspec = fontselector.param_readFontSpec(fontselector.param_getSVGValue()); - double fontsize = fontselector.param_readFontSize(fontselector.param_getSVGValue()); - fontlister->fill_css( css, fontspec ); + Pango::FontDescription fontdesc((Glib::ustring)fontbutton.param_getSVGValue()); + double fontsize = fontdesc.get_size()/Pango::SCALE; + Inkscape::FontLister *fontlister = Inkscape::FontLister::get_instance(); + fontlister->fill_css( css, (Glib::ustring)fontbutton.param_getSVGValue() ); std::stringstream font_size; font_size.imbue(std::locale::classic()); font_size << fontsize << "pt"; sp_repr_css_set_property (css, "font-size", font_size.str().c_str()); - sp_repr_css_set_property (css, "font-style", "normal"); - sp_repr_css_set_property (css, "font-weight", "normal"); sp_repr_css_set_property (css, "line-height", "125%"); sp_repr_css_set_property (css, "letter-spacing", "0"); sp_repr_css_set_property (css, "word-spacing", "0"); @@ -352,14 +352,15 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } length = Inkscape::Util::Quantity::convert(length, doc_unit.c_str(), unit.get_abbreviation()); std::stringstream length_str; - length_str.setf(std::ios::fixed, std::ios::floatfield); length_str.precision(precision); + length_str.setf(std::ios::fixed, std::ios::floatfield); if (local_locale) { length_str.imbue(std::locale("")); } else { length_str.imbue(std::locale::classic()); } - length_str << length << unit.get_abbreviation(); + length_str << std::fixed << length; + length_str << unit.get_abbreviation(); Inkscape::XML::Node *rstring = NULL; if (!elemref) { rstring = xml_doc->createTextNode(length_str.str().c_str()); @@ -509,7 +510,7 @@ void LPEMeasureLine::saveDefault() { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setString("/live_effects/measure-line/fontselector", (Glib::ustring)fontselector.param_getSVGValue()); + prefs->setString("/live_effects/measure-line/fontbutton", (Glib::ustring)fontbutton.param_getSVGValue()); prefs->setDouble("/live_effects/measure-line/scale", scale); prefs->setInt("/live_effects/measure-line/precision", precision); prefs->setDouble("/live_effects/measure-line/offset_right_left", offset_right_left); diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 67d27408a..15831e231 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -12,7 +12,7 @@ #include "live_effects/effect.h" #include "live_effects/parameter/enum.h" -#include "live_effects/parameter/font.h" +#include "live_effects/parameter/fontbutton.h" #include "live_effects/parameter/text.h" #include "live_effects/parameter/unit.h" #include "live_effects/parameter/bool.h" @@ -47,8 +47,7 @@ public: void saveDefault(); virtual Gtk::Widget *newWidget(); private: - FontParam fontselector; - Inkscape::FontLister *fontlister; + FontButtonParam fontbutton; EnumParam orientation; OriginalPathParam origin; ScalarParam curve_linked; diff --git a/src/live_effects/parameter/Makefile_insert b/src/live_effects/parameter/Makefile_insert index bd1c5b600..d9cd5b3c1 100644 --- a/src/live_effects/parameter/Makefile_insert +++ b/src/live_effects/parameter/Makefile_insert @@ -11,6 +11,8 @@ ink_common_sources += \ live_effects/parameter/random.h \ live_effects/parameter/point.cpp \ live_effects/parameter/point.h \ + live_effects/parameter/fontbutton.cpp \ + live_effects/parameter/fontbutton.h \ live_effects/parameter/enum.h \ live_effects/parameter/path-reference.cpp \ live_effects/parameter/path-reference.h \ diff --git a/src/live_effects/parameter/font.cpp b/src/live_effects/parameter/font.cpp deleted file mode 100644 index 8f89ee5c4..000000000 --- a/src/live_effects/parameter/font.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Authors: - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - - -#include "ui/widget/registered-widget.h" -#include "live_effects/parameter/font.h" -#include "live_effects/effect.h" -#include "ui/widget/font-selector.h" -#include "svg/svg.h" -#include "svg/stringstream.h" -#include "verbs.h" - -#include - -namespace Inkscape { - -namespace LivePathEffect { - -FontParam::FontParam( const Glib::ustring& label, const Glib::ustring& tip, - const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, - Effect* effect, const Glib::ustring default_value ) - : Parameter(label, tip, key, wr, effect), - value(default_value), - defvalue(default_value) -{ -} - -void -FontParam::param_set_default() -{ - param_setValue(defvalue); -} -void -FontParam::param_update_default(const Glib::ustring default_value){ - defvalue = default_value; -} - -Glib::ustring -FontParam::param_readFontSpec(const gchar * strvalue) -{ - Glib::ustring result; - gchar ** strarray = g_strsplit(strvalue, " @ ", 2); - double fontsize; - if (strarray[1]) { - unsigned int success = sp_svg_number_read_d(strarray[1], &fontsize); - if (success == 1) { - result = (Glib::ustring)strarray[0]; - g_strfreev (strarray); - return result; - } - } - g_strfreev (strarray); - return result; -} - -double -FontParam::param_readFontSize(const gchar * strvalue) -{ - gchar ** strarray = g_strsplit(strvalue, " @ ", 2); - double fontsize = 0; - if (strarray[1]) { - unsigned int success = sp_svg_number_read_d(strarray[1], &fontsize); - if (success == 1) { - g_strfreev (strarray); - return fontsize; - } - } - g_strfreev (strarray); - return fontsize; -} - -bool -FontParam::param_readSVGValue(const gchar * strvalue) -{ - double fontsize = param_readFontSize(strvalue); - Glib::ustring fontspec = param_readFontSpec(strvalue); - Inkscape::SVGOStringStream os; - os << fontspec << " @ " << fontsize; - param_setValue((Glib::ustring)os.str()); - return true; -} - -gchar * -FontParam::param_getSVGValue() const -{ - return g_strdup(value.c_str()); -} - -Gtk::Widget * -FontParam::param_newWidget() -{ - Inkscape::UI::Widget::RegisteredFontSelector * fontselectorwdg = Gtk::manage( - new Inkscape::UI::Widget::RegisteredFontSelector( param_label, - param_tooltip, - param_key, - *param_wr, - param_effect->getRepr(), - param_effect->getSPDoc() ) ); - double fontsize = param_readFontSize(param_getSVGValue()); - Glib::ustring fontspec = param_readFontSpec(param_getSVGValue()); - fontselectorwdg->setValue( fontspec, fontsize ); - fontselectorwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change font selector parameter")); - param_effect->upd_params = false; - return dynamic_cast (fontselectorwdg); -} - -void -FontParam::param_setValue(const Glib::ustring newvalue) -{ - value = newvalue; -} - -} /* namespace LivePathEffect */ - -} /* namespace Inkscape */ - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/font.h b/src/live_effects/parameter/font.h deleted file mode 100644 index 3909ea424..000000000 --- a/src/live_effects/parameter/font.h +++ /dev/null @@ -1,78 +0,0 @@ -#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_FONT_H -#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_FONT_H - -/* - * Inkscape::LivePathEffectParameters - * - * Authors: - * Released under GNU GPL, read the file 'COPYING' for more information - */ -#include -#include -#include "live_effects/parameter/parameter.h" - -namespace Inkscape { - -namespace LivePathEffect { - -class FontParam : public Parameter { -public: - FontParam( const Glib::ustring& label, - const Glib::ustring& tip, - const Glib::ustring& key, - Inkscape::UI::Widget::Registry* wr, - Effect* effect, - const Glib::ustring default_value = ""); - virtual ~FontParam() {} - - virtual Gtk::Widget * param_newWidget(); - virtual bool param_readSVGValue(const gchar * strvalue); - double param_readFontSize(const gchar * strvalue); - void param_update_default(const Glib::ustring defvalue); - Glib::ustring param_readFontSpec(const gchar * strvalue); - virtual gchar * param_getSVGValue() const; - - void param_setValue(const Glib::ustring newvalue); - - virtual void param_set_default(); - - const Glib::ustring get_value() const { return defvalue; }; - -private: - FontParam(const FontParam&); - FontParam& operator=(const FontParam&); - Glib::ustring value; - Glib::ustring defvalue; - -}; - -/* - * This parameter does not display a widget in the LPE dialog; LPEs can use it to display on-canvas - * text that should not be settable by the user. Note that since no widget is provided, the - * parameter must be initialized differently than usual (only with a pointer to the parent effect; - * no label, no tooltip, etc.). - */ -class FontParamInternal : public FontParam { -public: - FontParamInternal(Effect* effect) : - FontParam("", "", "", NULL, effect) {} - - virtual Gtk::Widget * param_newWidget() { return NULL; } -}; - -} //namespace LivePathEffect - -} //namespace Inkscape - -#endif - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/fontbutton.cpp b/src/live_effects/parameter/fontbutton.cpp new file mode 100644 index 000000000..ff8ab76a0 --- /dev/null +++ b/src/live_effects/parameter/fontbutton.cpp @@ -0,0 +1,92 @@ +/* + * Authors: + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + + +#include "ui/widget/registered-widget.h" +#include "live_effects/parameter/fontbutton.h" +#include "live_effects/effect.h" +#include "ui/widget/font-button.h" +#include "svg/svg.h" +#include "svg/stringstream.h" +#include "verbs.h" + +#include + +namespace Inkscape { + +namespace LivePathEffect { + +FontButtonParam::FontButtonParam( const Glib::ustring& label, const Glib::ustring& tip, + const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, + Effect* effect, const Glib::ustring default_value ) + : Parameter(label, tip, key, wr, effect), + value(default_value), + defvalue(default_value) +{ +} + +void +FontButtonParam::param_set_default() +{ + param_setValue(defvalue); +} +void +FontButtonParam::param_update_default(const Glib::ustring default_value){ + defvalue = default_value; +} + +bool +FontButtonParam::param_readSVGValue(const gchar * strvalue) +{ + Inkscape::SVGOStringStream os; + os << strvalue; + param_setValue((Glib::ustring)os.str()); + return true; +} + +gchar * +FontButtonParam::param_getSVGValue() const +{ + return g_strdup(value.c_str()); +} + +Gtk::Widget * +FontButtonParam::param_newWidget() +{ + Inkscape::UI::Widget::RegisteredFontButton * fontbuttonwdg = Gtk::manage( + new Inkscape::UI::Widget::RegisteredFontButton( param_label, + param_tooltip, + param_key, + *param_wr, + param_effect->getRepr(), + param_effect->getSPDoc() ) ); + Glib::ustring fontspec = param_getSVGValue(); + fontbuttonwdg->setValue( fontspec); + fontbuttonwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change font button parameter")); + param_effect->upd_params = false; + return dynamic_cast (fontbuttonwdg); +} + +void +FontButtonParam::param_setValue(const Glib::ustring newvalue) +{ + value = newvalue; +} + +} /* namespace LivePathEffect */ + +} /* namespace Inkscape */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/fontbutton.h b/src/live_effects/parameter/fontbutton.h new file mode 100644 index 000000000..387ad130b --- /dev/null +++ b/src/live_effects/parameter/fontbutton.h @@ -0,0 +1,62 @@ +#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_FONT_H +#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_FONT_H + +/* + * Inkscape::LivePathEffectParameters + * + * Authors: + * Released under GNU GPL, read the file 'COPYING' for more information + */ +#include +#include +#include "live_effects/parameter/parameter.h" + +namespace Inkscape { + +namespace LivePathEffect { + +class FontButtonParam : public Parameter { +public: + FontButtonParam( const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + Inkscape::UI::Widget::Registry* wr, + Effect* effect, + const Glib::ustring default_value = ""); + virtual ~FontButtonParam() {} + + virtual Gtk::Widget * param_newWidget(); + virtual bool param_readSVGValue(const gchar * strvalue); + void param_update_default(const Glib::ustring defvalue); + virtual gchar * param_getSVGValue() const; + + void param_setValue(const Glib::ustring newvalue); + + virtual void param_set_default(); + + const Glib::ustring get_value() const { return defvalue; }; + +private: + FontButtonParam(const FontButtonParam&); + FontButtonParam& operator=(const FontButtonParam&); + Glib::ustring value; + Glib::ustring defvalue; + +}; + +} //namespace LivePathEffect + +} //namespace Inkscape + +#endif + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 62f341962..af375f1f9 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -128,7 +128,7 @@ set(ui_SRC widget/entity-entry.cpp widget/entry.cpp widget/filter-effect-chooser.cpp - widget/font-selector.cpp + widget/font-button.cpp widget/font-variants.cpp widget/frame.cpp widget/gimpcolorwheel.c @@ -313,7 +313,7 @@ set(ui_SRC widget/entity-entry.h widget/entry.h widget/filter-effect-chooser.h - widget/font-selector.h + widget/font-button.h widget/font-variants.h widget/frame.h widget/gimpspinscale.h diff --git a/src/ui/widget/Makefile_insert b/src/ui/widget/Makefile_insert index bb833e5ec..b5d8a74f6 100644 --- a/src/ui/widget/Makefile_insert +++ b/src/ui/widget/Makefile_insert @@ -33,8 +33,8 @@ ink_common_sources += \ ui/widget/entry.h \ ui/widget/filter-effect-chooser.h \ ui/widget/filter-effect-chooser.cpp \ - ui/widget/font-selector.h \ - ui/widget/font-selector.cpp \ + ui/widget/font-button.h \ + ui/widget/font-button.cpp \ ui/widget/font-variants.h \ ui/widget/font-variants.cpp \ ui/widget/gimpspinscale.c \ diff --git a/src/ui/widget/font-button.cpp b/src/ui/widget/font-button.cpp new file mode 100644 index 000000000..2c79347b2 --- /dev/null +++ b/src/ui/widget/font-button.cpp @@ -0,0 +1,58 @@ +/* + * + * Released under GNU GPL. Read the file 'COPYING' for more information. + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "font-button.h" +#include + +namespace Inkscape { +namespace UI { +namespace Widget { + +FontButton::FontButton(Glib::ustring const &label, Glib::ustring const &tooltip, + Glib::ustring const &suffix, + Glib::ustring const &icon, + bool mnemonic) + : Labelled(label, tooltip, new Gtk::FontButton("sans"), suffix, icon, mnemonic) +{ +} + +Glib::ustring FontButton::getValue() const +{ + g_assert(_widget != NULL); + return static_cast(_widget)->get_font_name(); +} + + +void FontButton::setValue (Glib::ustring fontspec) +{ + g_assert(_widget != NULL); + static_cast(_widget)->set_font_name(fontspec); +} + +Glib::SignalProxy0 FontButton::signal_font_value_changed() +{ + g_assert(_widget != NULL); + return static_cast(_widget)->signal_font_set(); +} + + +} // namespace Widget +} // namespace UI +} // namespace Inkscape + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/ui/widget/font-button.h b/src/ui/widget/font-button.h new file mode 100644 index 000000000..1f1ad2d01 --- /dev/null +++ b/src/ui/widget/font-button.h @@ -0,0 +1,63 @@ +/* + * + * Copyright (C) 2007 Author + * + * Released under GNU GPL. Read the file 'COPYING' for more information. + */ + +#ifndef INKSCAPE_UI_WIDGET_FONT_BUTTON_H +#define INKSCAPE_UI_WIDGET_FONT_BUTTON_H + +#include +#include "labelled.h" + +namespace Inkscape { +namespace UI { +namespace Widget { + +/** + * A labelled font button for entering font values + */ +class FontButton : public Labelled +{ +public: + /** + * Construct a FontButton Widget. + * + * @param label Label. + * @param suffix Suffix, placed after the widget (defaults to ""). + * @param icon Icon filename, placed before the label (defaults to ""). + * @param mnemonic Mnemonic toggle; if true, an underscore (_) in the label + * indicates the next character should be used for the + * mnemonic accelerator key (defaults to false). + */ + FontButton( Glib::ustring const &label, + Glib::ustring const &tooltip, + Glib::ustring const &suffix = "", + Glib::ustring const &icon = "", + bool mnemonic = true); + + Glib::ustring getValue() const; + void setValue (Glib::ustring fontspec); + /** + * Signal raised when the font button's value changes. + */ + Glib::SignalProxy0 signal_font_value_changed(); +}; + +} // namespace Widget +} // namespace UI +} // namespace Inkscape + +#endif // INKSCAPE_UI_WIDGET_RANDOM_H + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/ui/widget/font-selector.cpp b/src/ui/widget/font-selector.cpp deleted file mode 100644 index 0fcb307eb..000000000 --- a/src/ui/widget/font-selector.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* - * - * Released under GNU GPL. Read the file 'COPYING' for more information. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "font-selector.h" -#include "widgets/icon.h" -#include - -namespace Inkscape { -namespace UI { -namespace Widget { - -FontSelector::FontSelector(Glib::ustring const &label, Glib::ustring const &tooltip, - Glib::ustring const &suffix, - Glib::ustring const &icon, - bool mnemonic) - :_widget(new Gtk::HBox()), expanded(false), _label(label) -{ - Gtk::VBox * vbox_expander = Gtk::manage( new Gtk::VBox() ); - GtkWidget *fontsel = sp_font_selector_new(); - gtk_widget_set_size_request (fontsel, 290, 150); - fsel = SP_FONT_SELECTOR(fontsel); - Gtk::Widget* pIcon = Gtk::manage( sp_icon_get_icon( "on", Inkscape::ICON_SIZE_BUTTON) ); - Gtk::Button * pButton = Gtk::manage(new Gtk::Button()); - pButton->set_relief(Gtk::RELIEF_NONE); - pIcon->show(); - pButton->add(*pIcon); - pButton->show(); - pButton->signal_clicked().connect(sigc::mem_fun(*this, &FontSelector::onFontSelectorSave)); - pButton->set_tooltip_text(_("Save the changes to font selector")); - vbox_expander->pack_start(*Gtk::manage(Glib::wrap(fontsel)), true, true); - vbox_expander->pack_start(*pButton, true, true); - expander = Gtk::manage(new Gtk::Expander(label)); - expander->add(*vbox_expander); - expander->set_expanded(expanded); - expander->set_spacing(5); - expander->set_use_markup(true); - onExpanderChanged(); - _widget->set_tooltip_text(tooltip); - expander->property_expanded().signal_changed().connect(sigc::mem_fun(*this, &FontSelector::onExpanderChanged) ); - pack_start(*expander, true, true); - pack_start(*Gtk::manage(_widget), true, true); -} - -void -FontSelector::onExpanderChanged() -{ - expanded = expander->get_expanded(); - if(expanded) { - expander->set_label (Glib::ustring(_label)); - } else { - expander->set_label (Glib::ustring(_label + _(" hided"))); - } -} - -Glib::ustring FontSelector::getFontSpec() const -{ - return _fontspec; -} - -void FontSelector::setFontSpec(Glib::ustring fontspec) -{ - _fontspec = fontspec; -} - -double FontSelector::getFontSize() const -{ - return _fontsize; -} - -void FontSelector::setFontSize(double fontsize) -{ - _fontsize = fontsize; -} - -void FontSelector::setValue (Glib::ustring fontspec, double fontsize) -{ - if (_fontsize != fontsize || _fontspec != fontspec) { - setFontSize(fontsize); - setFontSpec(fontspec); - sp_font_selector_set_fontspec(fsel, fontspec, fontsize); - } -} - -void -FontSelector::onFontSelectorSave() -{ - if (_fontspec != sp_font_selector_get_fontspec(fsel) || _fontsize != sp_font_selector_get_size(fsel)) { - setFontSpec(sp_font_selector_get_fontspec(fsel)); - setFontSize(sp_font_selector_get_size(fsel)); - signal_fontselupd.emit(); - onExpanderChanged(); - } -} - - -} // namespace Widget -} // namespace UI -} // namespace Inkscape - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/ui/widget/font-selector.h b/src/ui/widget/font-selector.h deleted file mode 100644 index 8146bc370..000000000 --- a/src/ui/widget/font-selector.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * - * Copyright (C) 2007 Author - * - * Released under GNU GPL. Read the file 'COPYING' for more information. - */ - -#ifndef INKSCAPE_UI_WIDGET_FONT_SELECTOR_H -#define INKSCAPE_UI_WIDGET_FONT_SELECTOR_H - -#include -#include "widgets/font-selector.h" - -struct SPFontSelector; -namespace Inkscape { -namespace UI { -namespace Widget { - -/** - * A labelled text box, with spin buttons and optional - * icon or suffix, for entering arbitrary number values. It adds an extra - * number called "startseed", that is not UI edittable, but should be put in SVG. - * This does NOT generate a random number, but provides merely the saving of - * the startseed value. - */ -class FontSelector : public Gtk::HBox -{ -public: - - /** - * Construct a FontSelector Widget. - * - * @param label Label. - * @param suffix Suffix, placed after the widget (defaults to ""). - * @param icon Icon filename, placed before the label (defaults to ""). - * @param mnemonic Mnemonic toggle; if true, an underscore (_) in the label - * indicates the next character should be used for the - * mnemonic accelerator key (defaults to false). - */ - FontSelector( Glib::ustring const &label, - Glib::ustring const &tooltip, - Glib::ustring const &suffix = "", - Glib::ustring const &icon = "", - bool mnemonic = true); - - Glib::ustring getFontSpec() const; - void onExpanderChanged(); - void setFontSpec(Glib::ustring fontspec); - double getFontSize() const; - void setFontSize(double fontsize); - void setValue (Glib::ustring fontspec, double fontsize); - sigc::signal signal_fontselupd; - -protected: - Gtk::Widget *_widget; - bool expanded; - Glib::ustring _label; - Gtk::Expander * expander; - SPFontSelector *fsel; - Glib::ustring _fontspec; - double _fontsize; - -private: - void onFontSelectorSave(); -}; - -} // namespace Widget -} // namespace UI -} // namespace Inkscape - -#endif // INKSCAPE_UI_WIDGET_RANDOM_H - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/ui/widget/registered-widget.cpp b/src/ui/widget/registered-widget.cpp index c58e599ee..38bb7f7cc 100644 --- a/src/ui/widget/registered-widget.cpp +++ b/src/ui/widget/registered-widget.cpp @@ -25,7 +25,7 @@ #include "ui/widget/scalar-unit.h" #include "ui/widget/point.h" #include "ui/widget/random.h" -#include "ui/widget/font-selector.h" +#include "ui/widget/font-button.h" #include "widgets/spinbutton-events.h" #include "xml/repr.h" @@ -805,33 +805,31 @@ RegisteredRandom::on_value_changed() } /*######################################### - * Registered FONT-SELECTOR + * Registered FONT-BUTTON */ -RegisteredFontSelector::~RegisteredFontSelector() +RegisteredFontButton::~RegisteredFontButton() { - _value_changed_connection.disconnect(); + _signal_font_set.disconnect(); } -RegisteredFontSelector::RegisteredFontSelector ( const Glib::ustring& label, const Glib::ustring& tip, +RegisteredFontButton::RegisteredFontButton ( const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in, SPDocument* doc_in ) - : RegisteredWidget (label, tip) + : RegisteredWidget(label, tip) { init_parent(key, wr, repr_in, doc_in); - _value_changed_connection = signal_fontselupd.connect (sigc::mem_fun (*this, &RegisteredFontSelector::on_value_changed)); + _signal_font_set = signal_font_value_changed().connect (sigc::mem_fun (*this, &RegisteredFontButton::on_value_changed)); } void -RegisteredFontSelector::setValue (Glib::ustring fontspec, double fontsize) +RegisteredFontButton::setValue (Glib::ustring fontspec) { - if (fontsize != 0) { //have value in the effect - FontSelector::setValue (fontspec, fontsize); - } + FontButton::setValue(fontspec); } void -RegisteredFontSelector::on_value_changed() +RegisteredFontButton::on_value_changed() { if (_wr->isUpdating()) @@ -840,7 +838,7 @@ RegisteredFontSelector::on_value_changed() _wr->setUpdating (true); Inkscape::SVGOStringStream os; - os << getFontSpec() << " @ " << getFontSize(); + os << getValue(); write_to_xml(os.str().c_str()); diff --git a/src/ui/widget/registered-widget.h b/src/ui/widget/registered-widget.h index 2b4d98b88..d410dbfe6 100644 --- a/src/ui/widget/registered-widget.h +++ b/src/ui/widget/registered-widget.h @@ -22,7 +22,7 @@ #include "ui/widget/text.h" #include "ui/widget/random.h" #include "ui/widget/unit-menu.h" -#include "ui/widget/font-selector.h" +#include "ui/widget/font-button.h" #include "ui/widget/color-picker.h" #include "inkscape.h" @@ -421,20 +421,20 @@ protected: void on_value_changed(); }; -class RegisteredFontSelector : public RegisteredWidget { +class RegisteredFontButton : public RegisteredWidget { public: - virtual ~RegisteredFontSelector(); - RegisteredFontSelector ( const Glib::ustring& label, + virtual ~RegisteredFontButton(); + RegisteredFontButton ( const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in = NULL, SPDocument *doc_in = NULL); - void setValue (Glib::ustring fontspec, double fontsize); + void setValue (Glib::ustring fontspec); protected: - sigc::connection _value_changed_connection; + sigc::connection _signal_font_set; void on_value_changed(); }; -- cgit v1.2.3 From f391d1cb5c644cd325f64a88d6d3a9da73fdb9de Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 30 Jul 2016 02:50:36 +0200 Subject: Fixes positions of labels (bzr r15017.1.14) --- src/live_effects/lpe-measure-line.cpp | 113 +++++++++++++++++++++++----------- src/live_effects/lpe-measure-line.h | 2 +- src/ui/widget/font-button.cpp | 2 +- 3 files changed, 78 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 5df3d499e..d0252aea9 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -215,6 +215,9 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } s[Geom::X] = xpos; e[Geom::X] = xpos; + if (s[Geom::Y] > e[Geom::Y]) { + swap(s,e); + } } if(*om_it == OM_HORIZONTAL) { Coord ypos = std::max(s[Geom::Y],e[Geom::Y]); @@ -223,6 +226,9 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } s[Geom::Y] = ypos; e[Geom::Y] = ypos; + if (s[Geom::X] < e[Geom::X]) { + swap(s,e); + } } Geom::Ray ray(s,e); Geom::Coord angle = ray.angle(); @@ -250,6 +256,9 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } s[Geom::X] = xpos; e[Geom::X] = xpos; + if (s[Geom::Y] > e[Geom::Y]) { + swap(s,e); + } } if(*om_it == OM_HORIZONTAL) { Coord ypos = std::max(s[Geom::Y],e[Geom::Y]); @@ -258,6 +267,9 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } s[Geom::Y] = ypos; e[Geom::Y] = ypos; + if (s[Geom::X] < e[Geom::X]) { + swap(s,e); + } } } double length = Geom::distance(s, e) * scale; @@ -406,28 +418,55 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } } -void LPEMeasureLine::doOnRemove (SPLPEItem const* /*lpeitem*/) +void LPEMeasureLine::doOnRemove (SPLPEItem const* lpeitem) { -// if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { -// if (horizontal_text) { -// SPObject * text_obj = desktop->currentLayer()->get_child_by_repr(horizontal_text); -// if (text_obj) { -// text_obj->deleteObject(); -// } -// } -// if (vertical_text) { -// SPObject * text_obj = desktop->currentLayer()->get_child_by_repr(vertical_text); -// if (text_obj) { -// text_obj->deleteObject(); -// } -// } -// if (parallel_text) { -// SPObject * text_obj = desktop->currentLayer()->get_child_by_repr(parallel_text); -// if (text_obj) { -// text_obj->deleteObject(); -// } -// } -// } + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { + SPLPEItem * splpeitem = const_cast(lpeitem); + std::vector orientations; + std::vector orientations_remove; + if ( orientation == OM_HORIZONTAL || + orientation == OM_PARALLEL_VERTICAL_HORIZONTAL || + orientation == OM_PARALLEL_HORIZONTAL || + orientation == OM_VERTICAL_HORIZONTAL) + { + orientations.push_back(OM_HORIZONTAL); + } + if ( orientation == OM_VERTICAL || + orientation == OM_PARALLEL_VERTICAL_HORIZONTAL || + orientation == OM_PARALLEL_VERTICAL || + orientation == OM_VERTICAL_HORIZONTAL) + { + orientations.push_back(OM_VERTICAL); + } + if ( orientation == OM_PARALLEL || + orientation == OM_PARALLEL_VERTICAL_HORIZONTAL || + orientation == OM_PARALLEL_VERTICAL || + orientation == OM_PARALLEL_HORIZONTAL) + { + orientations.push_back(OM_PARALLEL); + } + for (std::vector::const_iterator om_it = orientations.begin(); om_it != orientations.end(); ++om_it) { + Glib::ustring orientation_str; + Inkscape::XML::Node *rtext = NULL; + if (*om_it == OM_VERTICAL) { + orientation_str = "vertical"; + } + if (*om_it == OM_HORIZONTAL) { + orientation_str = "horizontal"; + } + if (*om_it == OM_PARALLEL) { + orientation_str = "parallel"; + } + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_DINnumber_" + orientation_str).c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *rtspan = NULL; + if (elemref = SVGElemRef->getObject()) { + elemref->deleteObject(); + } + } + } } Gtk::Widget *LPEMeasureLine::newWidget() @@ -483,22 +522,22 @@ LPEMeasureLine::doEffect_path(Geom::PathVector const &path_in) angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); if (angle < 0) angle += 2*M_PI; e = e - Point::polar(angle, gap_end); - if(orientation == OM_VERTICAL) { - Coord xpos = std::max(s[Geom::X],e[Geom::X]); - if (reverse) { - xpos = std::min(s[Geom::X],e[Geom::X]); - } - s[Geom::X] = xpos; - e[Geom::X] = xpos; - } - if(orientation == OM_HORIZONTAL) { - Coord ypos = std::max(s[Geom::Y],e[Geom::Y]); - if (reverse) { - ypos = std::min(s[Geom::Y],e[Geom::Y]); - } - s[Geom::Y] = ypos; - e[Geom::Y] = ypos; - } +// if(orientation == OM_VERTICAL) { +// Coord xpos = std::max(s[Geom::X],e[Geom::X]); +// if (reverse) { +// xpos = std::min(s[Geom::X],e[Geom::X]); +// } +// s[Geom::X] = xpos; +// e[Geom::X] = xpos; +// } +// if(orientation == OM_HORIZONTAL) { +// Coord ypos = std::max(s[Geom::Y],e[Geom::Y]); +// if (reverse) { +// ypos = std::min(s[Geom::Y],e[Geom::Y]); +// } +// s[Geom::Y] = ypos; +// e[Geom::Y] = ypos; +// } path.start( s ); path.appendNew( e ); Geom::PathVector output; diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 15831e231..05f9b2f73 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -42,7 +42,7 @@ public: virtual ~LPEMeasureLine(); virtual void doBeforeEffect (SPLPEItem const* lpeitem); virtual void doOnApply(SPLPEItem const* lpeitem); - virtual void doOnRemove (SPLPEItem const* /*lpeitem*/); + virtual void doOnRemove (SPLPEItem const* lpeitem); virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); void saveDefault(); virtual Gtk::Widget *newWidget(); diff --git a/src/ui/widget/font-button.cpp b/src/ui/widget/font-button.cpp index 2c79347b2..a472ac6a4 100644 --- a/src/ui/widget/font-button.cpp +++ b/src/ui/widget/font-button.cpp @@ -18,7 +18,7 @@ FontButton::FontButton(Glib::ustring const &label, Glib::ustring const &tooltip, Glib::ustring const &suffix, Glib::ustring const &icon, bool mnemonic) - : Labelled(label, tooltip, new Gtk::FontButton("sans"), suffix, icon, mnemonic) + : Labelled(label, tooltip, new Gtk::FontButton("Sans 10"), suffix, icon, mnemonic) { } -- cgit v1.2.3 From 7f16afbb515eceed9c63afacec73cd528a662327 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 30 Jul 2016 19:04:34 +0200 Subject: Full rewrite on working mode now no linked paths necesary (bzr r15017.1.15) --- src/knotholder.cpp | 3 +- src/knotholder.h | 2 +- src/live_effects/effect.cpp | 4 +- src/live_effects/effect.h | 2 +- src/live_effects/lpe-measure-line.cpp | 528 +++++++++++-------------------- src/live_effects/lpe-measure-line.h | 9 +- src/live_effects/parameter/parameter.cpp | 43 +-- src/live_effects/parameter/parameter.h | 2 - src/ui/dialog/livepatheffect-editor.cpp | 8 + src/ui/widget/registered-widget.cpp | 1 - src/ui/widget/scalar.cpp | 6 +- src/ui/widget/scalar.h | 2 +- 12 files changed, 213 insertions(+), 397 deletions(-) (limited to 'src') diff --git a/src/knotholder.cpp b/src/knotholder.cpp index eed358001..a2d1cf017 100644 --- a/src/knotholder.cpp +++ b/src/knotholder.cpp @@ -17,7 +17,6 @@ #include "document.h" #include "document-undo.h" -#include "selection.h" #include "sp-shape.h" #include "knot.h" #include "knotholder.h" @@ -203,7 +202,7 @@ KnotHolder::knot_moved_handler(SPKnot *knot, Geom::Point const &p, guint state) } void -KnotHolder::knot_ungrabbed_handler(SPKnot */*knot*/, guint /*state*/) +KnotHolder::knot_ungrabbed_handler(SPKnot */*knot*/, guint) { this->dragging = false; diff --git a/src/knotholder.h b/src/knotholder.h index f055a163a..f1bacebe5 100644 --- a/src/knotholder.h +++ b/src/knotholder.h @@ -51,7 +51,7 @@ public: void knot_moved_handler(SPKnot *knot, Geom::Point const &p, unsigned int state); void knot_clicked_handler(SPKnot *knot, unsigned int state); - void knot_ungrabbed_handler(SPKnot *knot, unsigned int state); + void knot_ungrabbed_handler(SPKnot *knot, unsigned int); void add(KnotHolderEntity *e); diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index a62e8b62b..7efc1a711 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -454,7 +454,9 @@ void Effect::doAfterEffect (SPLPEItem const* /*lpeitem*/) void Effect::doOnRemove (SPLPEItem const* /*lpeitem*/) { } - +void Effect::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) +{ +} //secret impl methods (shhhh!) void Effect::doOnApply_impl(SPLPEItem const* lpeitem) { diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index e0a7cbe6b..f54624302 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -66,7 +66,7 @@ public: virtual void doAfterEffect (SPLPEItem const* lpeitem); virtual void doOnRemove (SPLPEItem const* lpeitem); - + virtual void doOnVisibilityToggled(SPLPEItem const* lpeitem); void writeParamsToSVG(); virtual void acceptParamPath (SPPath const* param_path); diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index d0252aea9..6d58e2b7d 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -39,11 +39,7 @@ namespace LivePathEffect { static const Util::EnumData OrientationMethodData[] = { { OM_HORIZONTAL, N_("Horizontal"), "horizontal" }, { OM_VERTICAL, N_("Vertical"), "vertical" }, - { OM_PARALLEL, N_("Parallel"), "parallel" }, - { OM_PARALLEL_VERTICAL, N_("Parallel and vertical,"), "parallel_vertical" }, - { OM_PARALLEL_HORIZONTAL, N_("Parallel and horizontal"), "parallel_horizontal" }, - { OM_VERTICAL_HORIZONTAL, N_("Vertical and horizontal"), "vertical_horizontal" }, - { OM_PARALLEL_VERTICAL_HORIZONTAL, N_("Parallel, vertical and horizontal"), "parallel_vertical_horizontal" } + { OM_PARALLEL, N_("Parallel"), "parallel" } }; static const Util::EnumDataConverter OMConverter(OrientationMethodData, OM_END); @@ -51,9 +47,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : Effect(lpeobject), fontbutton(_("Font*"), _("Font Selector"), "fontbutton", &wr, this), orientation(_("Orientation"), _("Orientation method"), "orientation", OMConverter, &wr, this, OM_PARALLEL, false), - origin(_("Optional Origin"), _("Optional origin"), "origin", &wr, this), - curve_linked(_("Curve on optional origin"), _("Curve on optional origin, set 0 to start/end"), "curve_linked", &wr, this, 1), - origin_offset(_("Optional origin offset*"), _("Optional origin offset"), "origin_offset", &wr, this, 5), + curve_linked(_("Curve on origin"), _("Curve on origin, set 0 to start/end"), "curve_linked", &wr, this, 1), scale(_("Scale*"), _("Scaling factor"), "scale", &wr, this, 1.0), precision(_("Precision*"), _("Precision"), "precision", &wr, this, 2), offset_right_left(_("Offset right left*"), _("Offset right left"), "offset_right_left", &wr, this, 0), @@ -68,9 +62,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : { registerParameter(&fontbutton); registerParameter(&orientation); - registerParameter(&origin); registerParameter(&curve_linked); - registerParameter(&origin_offset); registerParameter(&scale); registerParameter(&precision); registerParameter(&offset_right_left); @@ -88,7 +80,6 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : precision.param_update_default(prefs->getInt("/live_effects/measure-line/precision", 2)); offset_right_left.param_update_default(prefs->getDouble("/live_effects/measure-line/offset_right_left", 0.0)); offset_top_bottom.param_update_default(prefs->getDouble("/live_effects/measure-line/offset_top_bottom", 5.0)); - origin_offset.param_update_default(prefs->getDouble("/live_effects/measure-line/origin_offset", 5.0)); unit.param_update_default(prefs->getString("/live_effects/measure-line/unit")); reverse.param_update_default(prefs->getBool("/live_effects/measure-line/reverse")); color_as_line.param_update_default(prefs->getBool("/live_effects/measure-line/color_as_line")); @@ -98,7 +89,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : precision.param_set_increments(1, 1); precision.param_set_digits(0); precision.param_make_integer(true); - curve_linked.param_set_range(1, 999); + curve_linked.param_set_range(0, 999); curve_linked.param_set_increments(1, 1); curve_linked.param_set_digits(0); curve_linked.param_make_integer(true); @@ -109,9 +100,6 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : offset_top_bottom.param_set_range(-999999.0, 999999.0); offset_top_bottom.param_set_increments(1, 1); offset_top_bottom.param_set_digits(2); - origin_offset.param_set_range(-999999.0, 999999.0); - origin_offset.param_set_increments(1, 1); - origin_offset.param_set_digits(2); gap_start.param_set_range(-999999.0, 999999.0); gap_start.param_set_increments(1, 1); gap_start.param_set_digits(2); @@ -120,8 +108,6 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : gap_end.param_set_digits(2); } -bool LPEMeasureLine::alerts_off = false; - LPEMeasureLine::~LPEMeasureLine() {} void @@ -131,16 +117,24 @@ LPEMeasureLine::doOnApply(SPLPEItem const* lpeitem) g_warning("LPE measure line can only be applied to shapes (not groups)."); SPLPEItem * item = const_cast(lpeitem); item->removeCurrentPathEffect(false); - } else { - if(!alerts_off) { - char *msg = _("The \"measure line\" path effect could update original path on the object you are applying it to if link it to other path. If this is not what you want, click Cancel."); - Gtk::MessageDialog dialog(msg, false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_OK_CANCEL, true); - gint response = dialog.run(); - alerts_off = true; - if(response == GTK_RESPONSE_CANCEL) { - SPLPEItem* item = const_cast(lpeitem); - item->removeCurrentPathEffect(false); - return; + } +} + +void +LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) +{ + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)this->getRepr()->attribute("id") + (Glib::ustring)"_text").c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *rtext = NULL; + if (elemref = SVGElemRef->getObject()) { + rtext = elemref->getRepr(); + if (!this->isVisible()) { + rtext->setAttribute("style", "display:none"); + } else { + rtext->setAttribute("style", NULL); } } } @@ -154,266 +148,166 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) if (sp_path) { Geom::PathVector pathvector = sp_path->get_original_curve()->get_pathvector(); if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); - std::vector orientations; - std::vector orientations_remove; - if ( orientation == OM_HORIZONTAL || - orientation == OM_PARALLEL_VERTICAL_HORIZONTAL || - orientation == OM_PARALLEL_HORIZONTAL || - orientation == OM_VERTICAL_HORIZONTAL) - { - orientations.push_back(OM_HORIZONTAL); - } else { - orientations_remove.push_back(OM_HORIZONTAL); - } - if ( orientation == OM_VERTICAL || - orientation == OM_PARALLEL_VERTICAL_HORIZONTAL || - orientation == OM_PARALLEL_VERTICAL || - orientation == OM_VERTICAL_HORIZONTAL) - { - orientations.push_back(OM_VERTICAL); - } else { - orientations_remove.push_back(OM_VERTICAL); + size_t ncurves = pathvector.curveCount(); + curve_linked.param_set_range(0, ncurves); + Geom::Point s = pathvector.initialPoint(); + Geom::Point e = pathvector.finalPoint(); + if (curve_linked) { //0 start-end nodes + s = pathvector.pointAt(curve_linked -1); + e = pathvector.pointAt(curve_linked); } - if ( orientation == OM_PARALLEL || - orientation == OM_PARALLEL_VERTICAL_HORIZONTAL || - orientation == OM_PARALLEL_VERTICAL || - orientation == OM_PARALLEL_HORIZONTAL) - { - orientations.push_back(OM_PARALLEL); - } else { - orientations_remove.push_back(OM_PARALLEL); - } - for (std::vector::const_iterator om_it = orientations.begin(); om_it != orientations.end(); ++om_it) { - Geom::Point s = pathvector.initialPoint(); - Geom::Point e = pathvector.finalPoint(); - Glib::ustring orientation_str; - Inkscape::XML::Node *rtext = NULL; - if (*om_it == OM_VERTICAL) { - orientation_str = "vertical"; - } - if (*om_it == OM_HORIZONTAL) { - orientation_str = "horizontal"; + Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); + Glib::ustring orientation_str; + Inkscape::XML::Node *rtext = NULL; + if (orientation == OM_VERTICAL) { + orientation_str = "vertical"; + Coord xpos = std::max(s[Geom::X],e[Geom::X]); + if (reverse) { + xpos = std::min(s[Geom::X],e[Geom::X]); } - if (*om_it == OM_PARALLEL) { - orientation_str = "parallel"; + s[Geom::X] = xpos; + e[Geom::X] = xpos; + if (s[Geom::Y] > e[Geom::Y]) { + swap(s,e); } - if (origin.linksToPath() && origin.getObject() && !origin.get_pathvector().empty()) { - pathvector = origin.get_pathvector(); - size_t ncurves = pathvector.curveCount(); - curve_linked.param_set_range(1, ncurves); - if(previous_ncurves != ncurves) { - this->upd_params = true; - previous_ncurves = ncurves; - } - s = pathvector.pointAt(curve_linked -1); - e = pathvector.pointAt(curve_linked); - if(*om_it == OM_VERTICAL) { - Coord xpos = std::max(s[Geom::X],e[Geom::X]); - if (reverse) { - xpos = std::min(s[Geom::X],e[Geom::X]); - } - s[Geom::X] = xpos; - e[Geom::X] = xpos; - if (s[Geom::Y] > e[Geom::Y]) { - swap(s,e); - } - } - if(*om_it == OM_HORIZONTAL) { - Coord ypos = std::max(s[Geom::Y],e[Geom::Y]); - if (reverse) { - ypos = std::min(s[Geom::Y],e[Geom::Y]); - } - s[Geom::Y] = ypos; - e[Geom::Y] = ypos; - if (s[Geom::X] < e[Geom::X]) { - swap(s,e); - } - } - Geom::Ray ray(s,e); - Geom::Coord angle = ray.angle(); - if (reverse) { - angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); - if (angle < 0) angle += 2*M_PI; - } - Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); - if (angle_cross < 0) angle_cross += 2*M_PI; - s = s - Point::polar(angle_cross, origin_offset); - e = e - Point::polar(angle_cross, origin_offset); - Geom::Path path; - path.start( s ); - path.appendNew( e ); - Geom::PathVector line_upd; - line_upd.push_back(path); - Inkscape::XML::Node *line = SP_OBJECT(sp_path)->getRepr(); - gchar *str = sp_svg_write_path(line_upd); - line->setAttribute("inkscape:original-d", str); - } else { - if(*om_it == OM_VERTICAL) { - Coord xpos = std::max(s[Geom::X],e[Geom::X]); - if (reverse) { - xpos = std::min(s[Geom::X],e[Geom::X]); - } - s[Geom::X] = xpos; - e[Geom::X] = xpos; - if (s[Geom::Y] > e[Geom::Y]) { - swap(s,e); - } - } - if(*om_it == OM_HORIZONTAL) { - Coord ypos = std::max(s[Geom::Y],e[Geom::Y]); - if (reverse) { - ypos = std::min(s[Geom::Y],e[Geom::Y]); - } - s[Geom::Y] = ypos; - e[Geom::Y] = ypos; - if (s[Geom::X] < e[Geom::X]) { - swap(s,e); - } - } - } - double length = Geom::distance(s, e) * scale; - Geom::Point pos = Geom::middle_point(s,e); - Geom::Ray ray(s,e); - Geom::Coord angle = ray.angle(); - doc_unit = Inkscape::Util::unit_table.getUnit(desktop->doc()->getRoot()->height.unit)->abbr; + } + if (orientation == OM_HORIZONTAL) { + orientation_str = "horizontal"; + Coord ypos = std::max(s[Geom::Y],e[Geom::Y]); if (reverse) { - angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); - if (angle < 0) angle += 2*M_PI; + ypos = std::min(s[Geom::Y],e[Geom::Y]); } - Geom::Point newpos = pos - Point::polar(angle, offset_right_left); - Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); - if (angle_cross < 0) angle_cross += 2*M_PI; - newpos = newpos - Point::polar(angle_cross, offset_top_bottom); - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_DINnumber_" + orientation_str).c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - Inkscape::XML::Node *rtspan = NULL; - if (elemref = SVGElemRef->getObject()) { - rtext = elemref->getRepr(); - sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); - sp_repr_set_svg_double(rtext, "y", newpos[Geom::Y]); - } else { - rtext = xml_doc->createElement("svg:text"); - rtext->setAttribute("xml:space", "preserve"); - rtext->setAttribute("sodipodi:insensitive", "true"); - rtext->setAttribute("id", ((Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_DINnumber_" + orientation_str).c_str()); - /* Set style */ - sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); - sp_repr_set_svg_double(rtext, "y", newpos[Geom::Y]); - /* Create */ - rtspan = xml_doc->createElement("svg:tspan"); - rtspan->setAttribute("sodipodi:role", "line"); + s[Geom::Y] = ypos; + e[Geom::Y] = ypos; + if (s[Geom::X] < e[Geom::X]) { + swap(s,e); } - SPCSSAttr *css = sp_repr_css_attr_new(); - Pango::FontDescription fontdesc((Glib::ustring)fontbutton.param_getSVGValue()); - double fontsize = fontdesc.get_size()/Pango::SCALE; - Inkscape::FontLister *fontlister = Inkscape::FontLister::get_instance(); - fontlister->fill_css( css, (Glib::ustring)fontbutton.param_getSVGValue() ); - std::stringstream font_size; - font_size.imbue(std::locale::classic()); - font_size << fontsize << "pt"; - sp_repr_css_set_property (css, "font-size", font_size.str().c_str()); - sp_repr_css_set_property (css, "line-height", "125%"); - sp_repr_css_set_property (css, "letter-spacing", "0"); - sp_repr_css_set_property (css, "word-spacing", "0"); - sp_repr_css_set_property (css, "text-align", "center"); - sp_repr_css_set_property (css, "text-anchor", "middle"); - if (color_as_line) { - if (lpeitem->style) { - if (lpeitem->style->stroke.isPaintserver()) { - SPPaintServer * server = lpeitem->style->getStrokePaintServer(); - if (server) { - Glib::ustring str; - str += "url(#"; - str += server->getId(); - str += ")"; - sp_repr_css_set_property (css, "fill", str.c_str()); - } - } else if (lpeitem->style->stroke.isColor()) { - gchar c[64]; - sp_svg_write_color (c, sizeof(c), lpeitem->style->stroke.value.color.toRGBA32(SP_SCALE24_TO_FLOAT(lpeitem->style->stroke_opacity.value))); - sp_repr_css_set_property (css, "fill", c); - } else { - sp_repr_css_set_property (css, "fill", "#000000"); + } + if (orientation == OM_PARALLEL) { + orientation_str = "parallel"; + } + double length = Geom::distance(s, e) * scale; + Geom::Point pos = Geom::middle_point(s,e); + Geom::Ray ray(s,e); + Geom::Coord angle = ray.angle(); + doc_unit = Inkscape::Util::unit_table.getUnit(desktop->doc()->getRoot()->height.unit)->abbr; + if (reverse) { + angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); + if (angle < 0) angle += 2*M_PI; + } + Geom::Point newpos = pos - Point::polar(angle, offset_right_left); + Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); + if (angle_cross < 0) angle_cross += 2*M_PI; + newpos = newpos - Point::polar(angle_cross, offset_top_bottom); + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)this->getRepr()->attribute("id") + (Glib::ustring)"_text").c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *rtspan = NULL; + if (elemref = SVGElemRef->getObject()) { + rtext = elemref->getRepr(); + sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); + sp_repr_set_svg_double(rtext, "y", newpos[Geom::Y]); + } else { + rtext = xml_doc->createElement("svg:text"); + rtext->setAttribute("xml:space", "preserve"); + rtext->setAttribute("sodipodi:insensitive", "true"); + rtext->setAttribute("id", ((Glib::ustring)this->getRepr()->attribute("id") + (Glib::ustring)"_text").c_str()); + /* Set style */ + sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); + sp_repr_set_svg_double(rtext, "y", newpos[Geom::Y]); + /* Create */ + rtspan = xml_doc->createElement("svg:tspan"); + rtspan->setAttribute("sodipodi:role", "line"); + } + SPCSSAttr *css = sp_repr_css_attr_new(); + Pango::FontDescription fontdesc((Glib::ustring)fontbutton.param_getSVGValue()); + double fontsize = fontdesc.get_size()/Pango::SCALE; + Inkscape::FontLister *fontlister = Inkscape::FontLister::get_instance(); + fontlister->fill_css( css, (Glib::ustring)fontbutton.param_getSVGValue() ); + std::stringstream font_size; + font_size.imbue(std::locale::classic()); + font_size << fontsize << "pt"; + sp_repr_css_set_property (css, "font-size", font_size.str().c_str()); + sp_repr_css_set_property (css, "line-height", "125%"); + sp_repr_css_set_property (css, "letter-spacing", "0"); + sp_repr_css_set_property (css, "word-spacing", "0"); + sp_repr_css_set_property (css, "text-align", "center"); + sp_repr_css_set_property (css, "text-anchor", "middle"); + if (color_as_line) { + if (lpeitem->style) { + if (lpeitem->style->stroke.isPaintserver()) { + SPPaintServer * server = lpeitem->style->getStrokePaintServer(); + if (server) { + Glib::ustring str; + str += "url(#"; + str += server->getId(); + str += ")"; + sp_repr_css_set_property (css, "fill", str.c_str()); } + } else if (lpeitem->style->stroke.isColor()) { + gchar c[64]; + sp_svg_write_color (c, sizeof(c), lpeitem->style->stroke.value.color.toRGBA32(SP_SCALE24_TO_FLOAT(lpeitem->style->stroke_opacity.value))); + sp_repr_css_set_property (css, "fill", c); } else { - sp_repr_css_unset_property (css, "#000000"); + sp_repr_css_set_property (css, "fill", "#000000"); } } else { - sp_repr_css_set_property (css, "fill", "#000000"); - } - sp_repr_css_set_property (css, "fill-opacity", "1"); - sp_repr_css_set_property (css, "stroke", "none"); - Glib::ustring css_str; - sp_repr_css_write_string(css,css_str); - if (!rtspan) { - rtspan = rtext->firstChild(); - } - rtspan->setAttribute("style", css_str.c_str()); - sp_repr_css_attr_unref (css); - if (!elemref) { - rtext->addChild(rtspan, NULL); - Inkscape::GC::release(rtspan); - } - /* Create TEXT */ - if (!scale_insensitive) { - Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); - length *= (affinetransform.expansionX() + affinetransform.expansionY()) / 2.0; - } - length = Inkscape::Util::Quantity::convert(length, doc_unit.c_str(), unit.get_abbreviation()); - std::stringstream length_str; - length_str.precision(precision); - length_str.setf(std::ios::fixed, std::ios::floatfield); - if (local_locale) { - length_str.imbue(std::locale("")); - } else { - length_str.imbue(std::locale::classic()); - } - length_str << std::fixed << length; - length_str << unit.get_abbreviation(); - Inkscape::XML::Node *rstring = NULL; - if (!elemref) { - rstring = xml_doc->createTextNode(length_str.str().c_str()); - rtspan->addChild(rstring, NULL); - Inkscape::GC::release(rstring); - } else { - rstring = rtspan->firstChild(); - rstring->setContent(length_str.str().c_str()); + sp_repr_css_unset_property (css, "#000000"); } - SPObject * text_obj = NULL; - if (!elemref) { - text_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(rtext)); - Inkscape::GC::release(rtext); - } else { - text_obj = desktop->currentLayer()->get_child_by_repr(rtext); - } - Geom::Affine affine = Geom::Affine(Geom::Translate(newpos).inverse()); - affine *= Geom::Rotate(angle); - affine *= Geom::Translate(newpos); - SP_ITEM(text_obj)->transform = affine * i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); - text_obj->updateRepr(); + } else { + sp_repr_css_set_property (css, "fill", "#000000"); } - for (std::vector::const_iterator omdel_it = orientations_remove.begin(); omdel_it != orientations_remove.end(); ++omdel_it) { - Glib::ustring orientation_str; - if (*omdel_it == OM_VERTICAL) { - orientation_str = "vertical"; - } - if (*omdel_it == OM_HORIZONTAL) { - orientation_str = "horizontal"; - } - if (*omdel_it == OM_PARALLEL) { - orientation_str = "parallel"; - } - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_DINnumber_" + orientation_str).c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - if (elemref = SVGElemRef->getObject()) { - elemref->deleteObject(); - } + sp_repr_css_set_property (css, "fill-opacity", "1"); + sp_repr_css_set_property (css, "stroke", "none"); + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + if (!rtspan) { + rtspan = rtext->firstChild(); + } + rtspan->setAttribute("style", css_str.c_str()); + sp_repr_css_attr_unref (css); + if (!elemref) { + rtext->addChild(rtspan, NULL); + Inkscape::GC::release(rtspan); + } + /* Create TEXT */ + if (!scale_insensitive) { + Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); + length *= (affinetransform.expansionX() + affinetransform.expansionY()) / 2.0; + } + length = Inkscape::Util::Quantity::convert(length, doc_unit.c_str(), unit.get_abbreviation()); + std::stringstream length_str; + length_str.precision(precision); + length_str.setf(std::ios::fixed, std::ios::floatfield); + if (local_locale) { + length_str.imbue(std::locale("")); + } else { + length_str.imbue(std::locale::classic()); } + length_str << std::fixed << length; + length_str << unit.get_abbreviation(); + Inkscape::XML::Node *rstring = NULL; + if (!elemref) { + rstring = xml_doc->createTextNode(length_str.str().c_str()); + rtspan->addChild(rstring, NULL); + Inkscape::GC::release(rstring); + } else { + rstring = rtspan->firstChild(); + rstring->setContent(length_str.str().c_str()); + } + SPObject * text_obj = NULL; + if (!elemref) { + text_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(rtext)); + Inkscape::GC::release(rtext); + } else { + text_obj = desktop->currentLayer()->get_child_by_repr(rtext); + } + Geom::Affine affine = Geom::Affine(Geom::Translate(newpos).inverse()); + affine *= Geom::Rotate(angle); + affine *= Geom::Translate(newpos); + SP_ITEM(text_obj)->transform = affine * i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); + text_obj->updateRepr(); } } } @@ -422,49 +316,13 @@ void LPEMeasureLine::doOnRemove (SPLPEItem const* lpeitem) { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { SPLPEItem * splpeitem = const_cast(lpeitem); - std::vector orientations; - std::vector orientations_remove; - if ( orientation == OM_HORIZONTAL || - orientation == OM_PARALLEL_VERTICAL_HORIZONTAL || - orientation == OM_PARALLEL_HORIZONTAL || - orientation == OM_VERTICAL_HORIZONTAL) - { - orientations.push_back(OM_HORIZONTAL); - } - if ( orientation == OM_VERTICAL || - orientation == OM_PARALLEL_VERTICAL_HORIZONTAL || - orientation == OM_PARALLEL_VERTICAL || - orientation == OM_VERTICAL_HORIZONTAL) - { - orientations.push_back(OM_VERTICAL); - } - if ( orientation == OM_PARALLEL || - orientation == OM_PARALLEL_VERTICAL_HORIZONTAL || - orientation == OM_PARALLEL_VERTICAL || - orientation == OM_PARALLEL_HORIZONTAL) - { - orientations.push_back(OM_PARALLEL); - } - for (std::vector::const_iterator om_it = orientations.begin(); om_it != orientations.end(); ++om_it) { - Glib::ustring orientation_str; - Inkscape::XML::Node *rtext = NULL; - if (*om_it == OM_VERTICAL) { - orientation_str = "vertical"; - } - if (*om_it == OM_HORIZONTAL) { - orientation_str = "horizontal"; - } - if (*om_it == OM_PARALLEL) { - orientation_str = "parallel"; - } - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_DINnumber_" + orientation_str).c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - Inkscape::XML::Node *rtspan = NULL; - if (elemref = SVGElemRef->getObject()) { - elemref->deleteObject(); - } + Inkscape::URI SVGElem_uri(((Glib::ustring)this->getRepr()->attribute("id") + (Glib::ustring)"_text").c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *rtspan = NULL; + if (elemref = SVGElemRef->getObject()) { + elemref->deleteObject(); } } } @@ -509,40 +367,7 @@ Gtk::Widget *LPEMeasureLine::newWidget() Geom::PathVector LPEMeasureLine::doEffect_path(Geom::PathVector const &path_in) { - Geom::Path path; - Geom::Point s = path_in.initialPoint(); - Geom::Point e = path_in.finalPoint(); - Geom::Ray ray(s,e); - Geom::Coord angle = ray.angle(); - if (reverse) { - angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); - if (angle < 0) angle += 2*M_PI; - } - s = s - Point::polar(angle, gap_start); - angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); - if (angle < 0) angle += 2*M_PI; - e = e - Point::polar(angle, gap_end); -// if(orientation == OM_VERTICAL) { -// Coord xpos = std::max(s[Geom::X],e[Geom::X]); -// if (reverse) { -// xpos = std::min(s[Geom::X],e[Geom::X]); -// } -// s[Geom::X] = xpos; -// e[Geom::X] = xpos; -// } -// if(orientation == OM_HORIZONTAL) { -// Coord ypos = std::max(s[Geom::Y],e[Geom::Y]); -// if (reverse) { -// ypos = std::min(s[Geom::Y],e[Geom::Y]); -// } -// s[Geom::Y] = ypos; -// e[Geom::Y] = ypos; -// } - path.start( s ); - path.appendNew( e ); - Geom::PathVector output; - output.push_back(path); - return output; + return path_in; } void @@ -554,7 +379,6 @@ LPEMeasureLine::saveDefault() prefs->setInt("/live_effects/measure-line/precision", precision); prefs->setDouble("/live_effects/measure-line/offset_right_left", offset_right_left); prefs->setDouble("/live_effects/measure-line/offset_top_bottom", offset_top_bottom); - prefs->setDouble("/live_effects/measure-line/origin_offset", origin_offset); prefs->setString("/live_effects/measure-line/unit", (Glib::ustring)unit.get_abbreviation()); prefs->setBool("/live_effects/measure-line/reverse", reverse); prefs->setBool("/live_effects/measure-line/color_as_line", color_as_line); diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 05f9b2f73..834194841 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -29,10 +29,6 @@ enum OrientationMethod { OM_HORIZONTAL, OM_VERTICAL, OM_PARALLEL, - OM_PARALLEL_VERTICAL, - OM_PARALLEL_HORIZONTAL, - OM_VERTICAL_HORIZONTAL, - OM_PARALLEL_VERTICAL_HORIZONTAL, OM_END }; @@ -43,29 +39,26 @@ public: virtual void doBeforeEffect (SPLPEItem const* lpeitem); virtual void doOnApply(SPLPEItem const* lpeitem); virtual void doOnRemove (SPLPEItem const* lpeitem); + virtual void doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/); virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); void saveDefault(); virtual Gtk::Widget *newWidget(); private: FontButtonParam fontbutton; EnumParam orientation; - OriginalPathParam origin; ScalarParam curve_linked; - ScalarParam origin_offset; ScalarParam scale; ScalarParam precision; ScalarParam offset_right_left; ScalarParam offset_top_bottom; ScalarParam gap_start; ScalarParam gap_end; - size_t previous_ncurves; UnitParam unit; BoolParam reverse; BoolParam color_as_line; BoolParam scale_insensitive; BoolParam local_locale; Glib::ustring doc_unit; - static bool alerts_off; /* Geom::Affine affine_over;*/ LPEMeasureLine(const LPEMeasureLine &); LPEMeasureLine &operator=(const LPEMeasureLine &); diff --git a/src/live_effects/parameter/parameter.cpp b/src/live_effects/parameter/parameter.cpp index 3f8fced4b..befac4df1 100644 --- a/src/live_effects/parameter/parameter.cpp +++ b/src/live_effects/parameter/parameter.cpp @@ -5,8 +5,8 @@ */ -#include "live_effects/parameter/parameter.h" #include "live_effects/effect.h" +#include "live_effects/parameter/parameter.h" #include "svg/svg.h" #include "xml/repr.h" @@ -66,8 +66,7 @@ ScalarParam::ScalarParam( const Glib::ustring& label, const Glib::ustring& tip, inc_page(1), add_slider(false), overwrite_widget(false), - hide_widget(no_widget), - _rsu(NULL) + hide_widget(no_widget) { } @@ -111,6 +110,7 @@ ScalarParam::param_update_default(gdouble default_value) void ScalarParam::param_set_value(gdouble val) { + param_effect->upd_params = true; value = val; if (integer) value = round(value); @@ -118,9 +118,6 @@ ScalarParam::param_set_value(gdouble val) value = max; if (value < min) value = min; - if (_rsu) { - _rsu->setValue(val); - } } void @@ -131,7 +128,7 @@ ScalarParam::param_set_range(gdouble min, gdouble max) // Once again, in gtk2, this is not a problem. But in gtk3, // widgets get allocated the amount of size they ask for, // leading to excessively long widgets. - + param_effect->upd_params = true; if (min >= -SCALARPARAM_G_MAXDOUBLE) { this->min = min; } else { @@ -140,10 +137,7 @@ ScalarParam::param_set_range(gdouble min, gdouble max) if (max <= SCALARPARAM_G_MAXDOUBLE) { this->max = max; } else { - this->max = SCALARPARAM_G_MAXDOUBLE; - } - if (_rsu) { - _rsu->setRange(this->min, this->max); + this->max = SCALARPARAM_G_MAXDOUBLE; } param_set_value(value); // reset value to see whether it is in ranges } @@ -151,6 +145,7 @@ ScalarParam::param_set_range(gdouble min, gdouble max) void ScalarParam::param_make_integer(bool yes) { + param_effect->upd_params = true; integer = yes; digits = 0; inc_step = 1; @@ -167,22 +162,22 @@ Gtk::Widget * ScalarParam::param_newWidget() { if(!hide_widget){ - _rsu = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalar( + Inkscape::UI::Widget::RegisteredScalar *rsu = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalar( param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc() ) ); - _rsu->setValue(value); - _rsu->setDigits(digits); - _rsu->setIncrements(inc_step, inc_page); - _rsu->setRange(min, max); - _rsu->setProgrammatically = false; + rsu->setValue(value); + rsu->setDigits(digits); + rsu->setIncrements(inc_step, inc_page); + rsu->setRange(min, max); + rsu->setProgrammatically = false; if (add_slider) { - _rsu->addSlider(); + rsu->addSlider(); } if(!overwrite_widget){ - _rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change scalar parameter")); + rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change scalar parameter")); } param_effect->upd_params = false; - return dynamic_cast (_rsu); + return dynamic_cast (rsu); } else { return NULL; } @@ -191,20 +186,16 @@ ScalarParam::param_newWidget() void ScalarParam::param_set_digits(unsigned digits) { + param_effect->upd_params = true; this->digits = digits; - if (_rsu) { - _rsu->setDigits(this->digits); - } } void ScalarParam::param_set_increments(double step, double page) { + param_effect->upd_params = true; inc_step = step; inc_page = page; - if (_rsu) { - _rsu->setIncrements(inc_step, inc_page); - } } diff --git a/src/live_effects/parameter/parameter.h b/src/live_effects/parameter/parameter.h index 63c55203e..3658bded8 100644 --- a/src/live_effects/parameter/parameter.h +++ b/src/live_effects/parameter/parameter.h @@ -117,7 +117,6 @@ public: void param_set_range(gdouble min, gdouble max); void param_set_digits(unsigned digits); void param_set_increments(double step, double page); - void addSlider(bool add_slider_widget) { add_slider = add_slider_widget; }; void param_overwrite_widget(bool overwrite_widget); @@ -141,7 +140,6 @@ protected: private: ScalarParam(const ScalarParam&); ScalarParam& operator=(const ScalarParam&); - Inkscape::UI::Widget::RegisteredScalar *_rsu; }; } //namespace LivePathEffect diff --git a/src/ui/dialog/livepatheffect-editor.cpp b/src/ui/dialog/livepatheffect-editor.cpp index 7205beaa8..e177ae01e 100644 --- a/src/ui/dialog/livepatheffect-editor.cpp +++ b/src/ui/dialog/livepatheffect-editor.cpp @@ -589,6 +589,14 @@ void LivePathEffectEditor::on_visibility_toggled( Glib::ustring const& str ) /* FIXME: this explicit writing to SVG is wrong. The lpe_item should have a method to disable/enable an effect within its stack. * So one can call: lpe_item->setActive(lpeobjref->lpeobject); */ lpeobjref->lpeobject->get_lpe()->getRepr()->setAttribute("is_visible", newValue ? "true" : "false"); + Inkscape::Selection *sel = _getSelection(); + if ( sel && !sel->isEmpty() ) { + SPItem *item = sel->singleItem(); + SPLPEItem *lpeitem = dynamic_cast(item); + if ( lpeitem ) { + lpeobjref->lpeobject->get_lpe()->doOnVisibilityToggled(lpeitem); + } + } DocumentUndo::done( current_desktop->getDocument(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, newValue ? _("Activate path effect") : _("Deactivate path effect")); } diff --git a/src/ui/widget/registered-widget.cpp b/src/ui/widget/registered-widget.cpp index 38bb7f7cc..923949b72 100644 --- a/src/ui/widget/registered-widget.cpp +++ b/src/ui/widget/registered-widget.cpp @@ -298,7 +298,6 @@ RegisteredScalar::on_value_changed() setProgrammatically = false; return; } - if (_wr->isUpdating()) { return; } diff --git a/src/ui/widget/scalar.cpp b/src/ui/widget/scalar.cpp index fca8a7974..80a2454b0 100644 --- a/src/ui/widget/scalar.cpp +++ b/src/ui/widget/scalar.cpp @@ -126,10 +126,12 @@ void Scalar::setRange(double min, double max) static_cast(_widget)->set_range(min, max); } -void Scalar::setValue(double value) +void Scalar::setValue(double value, bool setProg) { g_assert(_widget != NULL); - setProgrammatically = true; // callback is supposed to reset back, if it cares + if (setProg) { + setProgrammatically = true; // callback is supposed to reset back, if it cares + } static_cast(_widget)->set_value(value); } diff --git a/src/ui/widget/scalar.h b/src/ui/widget/scalar.h index 86d7aee28..9cceeaa1f 100644 --- a/src/ui/widget/scalar.h +++ b/src/ui/widget/scalar.h @@ -139,7 +139,7 @@ public: /** * Sets the value of the spin button. */ - void setValue(double value); + void setValue(double value, bool setProg = true); /** * Manually forces an update of the spin button. -- cgit v1.2.3 From 6ac79a669ea08356806bd130d1426871473b0b71 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 31 Jul 2016 16:02:08 +0200 Subject: Add options to fit on DIN (bzr r15017.1.16) --- src/live_effects/lpe-measure-line.cpp | 515 +++++++++++++++++++++++----------- src/live_effects/lpe-measure-line.h | 18 +- src/live_effects/parameter/text.cpp | 36 ++- src/live_effects/parameter/text.h | 4 +- 4 files changed, 387 insertions(+), 186 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 6d58e2b7d..c2a502e00 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -1,7 +1,8 @@ /* * Author(s): * Jabiertxo Arraiza Cenoz - * + * Some code and ideas migrated from dimensioning.py by + * Johannes B. Rutzmoser, johannes.rutzmoser (at) googlemail (dot) com * Copyright (C) 2014 Author(s) * Released under GNU GPL, read the file 'COPYING' for more information @@ -22,6 +23,7 @@ #include <2geom/affine.h> #include "style.h" #include "sp-root.h" +#include "sp-defs.h" #include "sp-item.h" #include "sp-shape.h" #include "sp-path.h" @@ -50,41 +52,52 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : curve_linked(_("Curve on origin"), _("Curve on origin, set 0 to start/end"), "curve_linked", &wr, this, 1), scale(_("Scale*"), _("Scaling factor"), "scale", &wr, this, 1.0), precision(_("Precision*"), _("Precision"), "precision", &wr, this, 2), - offset_right_left(_("Offset right left*"), _("Offset right left"), "offset_right_left", &wr, this, 0), - offset_top_bottom(_("Offset top bottom*"), _("Offset top bottom"), "offset_top_bottom", &wr, this, 5), - gap_start(_("Gap to line from origin"), _("Gap to line from origin, without affecting measure"), "gap_start", &wr, this, 0), - gap_end(_("Gap to line from end"), _("Gap to line from end, without affecting measure"), "gap_end", &wr, this, 0), + position(_("Positon*"), _("Positon"), "position", &wr, this, 5), + text_distance(_("Text distance*"), _("Text distance"), "text_distance", &wr, this, 12), + helpline_distance(_("Helpline distance*"), _("Helpline distance"), "helpline_distance", &wr, this, 0.0), + helpline_overlap(_("Helpline overlap*"), _("Helpline overlap"), "helpline_overlap", &wr, this, 2.0), unit(_("Unit*"), _("Unit"), "unit", &wr, this), - reverse(_("To other side*"), _("To other side"), "reverse", &wr, this, false), - color_as_line(_("Measure color as line*"), _("Measure color as line"), "color_as_line", &wr, this, false), + format(_("Format*"), _("Format the number ex:measure+ +unit"), "format", &wr, this, "measure+unit"), + arrows_outside(_("Arrows outside"), _("Arrows outside"), "arrows_outside", &wr, this, false), + flip_side(_("Flip side*"), _("Flip side"), "flip_side", &wr, this, false), scale_insensitive(_("Scale insensitive*"), _("Scale insensitive to transforms in element, parents..."), "scale_insensitive", &wr, this, true), - local_locale(_("Local Number Format*"), _("Local number format"), "local_locale", &wr, this, true) + local_locale(_("Local Number Format*"), _("Local number format"), "local_locale", &wr, this, true), + line_group_05(_("Line Group 0.5*"), _("Line Group 0.5, from 0.7"), "line_group_05", &wr, this, true), + rotate_anotation(_("Rotate Anotation*"), _("Rotate Anotation"), "rotate_anotation", &wr, this, true) { registerParameter(&fontbutton); registerParameter(&orientation); registerParameter(&curve_linked); registerParameter(&scale); registerParameter(&precision); - registerParameter(&offset_right_left); - registerParameter(&offset_top_bottom); - registerParameter(&gap_start); - registerParameter(&gap_end); + registerParameter(&position); + registerParameter(&text_distance); + registerParameter(&helpline_distance); + registerParameter(&helpline_overlap); registerParameter(&unit); - registerParameter(&reverse); - registerParameter(&color_as_line); + registerParameter(&format); + registerParameter(&arrows_outside); + registerParameter(&flip_side); registerParameter(&scale_insensitive); registerParameter(&local_locale); + registerParameter(&line_group_05); + registerParameter(&rotate_anotation); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); fontbutton.param_update_default(prefs->getString("/live_effects/measure-line/fontbutton")); scale.param_update_default(prefs->getDouble("/live_effects/measure-line/scale", 1.0)); precision.param_update_default(prefs->getInt("/live_effects/measure-line/precision", 2)); - offset_right_left.param_update_default(prefs->getDouble("/live_effects/measure-line/offset_right_left", 0.0)); - offset_top_bottom.param_update_default(prefs->getDouble("/live_effects/measure-line/offset_top_bottom", 5.0)); + position.param_update_default(prefs->getDouble("/live_effects/measure-line/position", 10.0)); + text_distance.param_update_default(prefs->getDouble("/live_effects/measure-line/text_distance", 5.0)); + helpline_distance.param_update_default(prefs->getDouble("/live_effects/measure-line/helpline_distance", 0.0)); + helpline_overlap.param_update_default(prefs->getDouble("/live_effects/measure-line/helpline_overlap", 0.0)); unit.param_update_default(prefs->getString("/live_effects/measure-line/unit")); - reverse.param_update_default(prefs->getBool("/live_effects/measure-line/reverse")); - color_as_line.param_update_default(prefs->getBool("/live_effects/measure-line/color_as_line")); + format.param_update_default(prefs->getString("/live_effects/measure-line/format")); + flip_side.param_update_default(prefs->getBool("/live_effects/measure-line/flip_side")); scale_insensitive.param_update_default(prefs->getBool("/live_effects/measure-line/scale_insensitive")); local_locale.param_update_default(prefs->getBool("/live_effects/measure-line/local_locale")); + line_group_05.param_update_default(prefs->getBool("/live_effects/measure-line/line_group_05")); + rotate_anotation.param_update_default(prefs->getBool("/live_effects/measure-line/rotate_anotation")); + format.param_hide_canvas_text(); precision.param_set_range(0, 100); precision.param_set_increments(1, 1); precision.param_set_digits(0); @@ -94,18 +107,18 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : curve_linked.param_set_digits(0); curve_linked.param_make_integer(true); precision.param_make_integer(true); - offset_right_left.param_set_range(-999999.0, 999999.0); - offset_right_left.param_set_increments(1, 1); - offset_right_left.param_set_digits(2); - offset_top_bottom.param_set_range(-999999.0, 999999.0); - offset_top_bottom.param_set_increments(1, 1); - offset_top_bottom.param_set_digits(2); - gap_start.param_set_range(-999999.0, 999999.0); - gap_start.param_set_increments(1, 1); - gap_start.param_set_digits(2); - gap_end.param_set_range(-999999.0, 999999.0); - gap_end.param_set_increments(1, 1); - gap_end.param_set_digits(2); + position.param_set_range(-999999.0, 999999.0); + position.param_set_increments(1, 1); + position.param_set_digits(2); + text_distance.param_set_range(-999999.0, 999999.0); + text_distance.param_set_increments(1, 1); + text_distance.param_set_digits(2); + helpline_distance.param_set_range(-999999.0, 999999.0); + helpline_distance.param_set_increments(1, 1); + helpline_distance.param_set_digits(2); + helpline_overlap.param_set_range(-999999.0, 999999.0); + helpline_overlap.param_set_increments(1, 1); + helpline_overlap.param_set_digits(2); } LPEMeasureLine::~LPEMeasureLine() {} @@ -124,7 +137,7 @@ void LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)this->getRepr()->attribute("id") + (Glib::ustring)"_text").c_str()); + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); SVGElemRef->attach(SVGElem_uri); SPObject *elemref = NULL; @@ -140,6 +153,213 @@ LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) } } +void +LPEMeasureLine::createArrowMarker(Glib::ustring mode) +{ + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { + Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + mode).c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *arrow = NULL; + if (!(elemref = SVGElemRef->getObject())) { + arrow = xml_doc->createElement("svg:marker"); + arrow->setAttribute("id", mode.c_str()); + arrow->setAttribute("inkscape:stockid", mode.c_str()); + arrow->setAttribute("orient", "auto"); + arrow->setAttribute("refX", "0.0"); + arrow->setAttribute("refY", "0.0"); + arrow->setAttribute("style", "overflow:visible"); + /* Create */ + Inkscape::XML::Node *arrow_path = xml_doc->createElement("svg:path"); + if (mode == (Glib::ustring)"ArrowDIN-start") { + arrow_path->setAttribute("d", "M -8,0 8,-2.11 8,2.11 z"); + } else if (mode == (Glib::ustring)"ArrowDIN-end") { + arrow_path->setAttribute("d", "M 8,0 -8,2.11 -8,-2.11 z"); + } else if (mode == (Glib::ustring)"ArrowDINout-start") { + arrow_path->setAttribute("d", "M 0,0 -16,2.11 -16,0.5 -26,0.5 -26,-0.5 -16,-0.5 -16,-2.11 z"); + } else { + arrow_path->setAttribute("d", "M 0,0 16,2.11 16,0.5 26,0.5 26,-0.5 16,-0.5 16,-2.11 z"); + } + arrow_path->setAttribute("id", (mode + (Glib::ustring)"_path").c_str()); + arrow_path->setAttribute("style", "fill:#000000;stroke:none"); + arrow->addChild(arrow_path, NULL); + Inkscape::GC::release(arrow_path); + SPObject * arrow_obj = SP_OBJECT(desktop->getDocument()->getDefs()->appendChildRepr(arrow)); + Inkscape::GC::release(arrow); + } + } +} + +void +LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angle, double fontsize, bool remove) +{ + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { + Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); + Inkscape::XML::Node *rtext = NULL; + doc_unit = Inkscape::Util::unit_table.getUnit(desktop->doc()->getRoot()->height.unit)->abbr; + if (doc_unit.empty()) { + doc_unit = "px"; + } + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *rtspan = NULL; + if (elemref = SVGElemRef->getObject()) { + if (remove) { + elemref->deleteObject(); + return; + } + rtext = elemref->getRepr(); + sp_repr_set_svg_double(rtext, "x", pos[Geom::X]); + sp_repr_set_svg_double(rtext, "y", pos[Geom::Y]); + } else { + if (remove) { + return; + } + rtext = xml_doc->createElement("svg:text"); + rtext->setAttribute("xml:space", "preserve"); + rtext->setAttribute("id", ( (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + sp_repr_set_svg_double(rtext, "x", pos[Geom::X]); + sp_repr_set_svg_double(rtext, "y", pos[Geom::Y]); + rtspan = xml_doc->createElement("svg:tspan"); + rtspan->setAttribute("sodipodi:role", "line"); + } + gchar * transform; + if (rotate_anotation) { + Geom::Affine affine = Geom::Affine(Geom::Translate(pos).inverse()); + affine *= Geom::Rotate(angle); + affine *= Geom::Translate(pos); + transform = sp_svg_transform_write(affine); + } else { + transform = NULL; + } + rtext->setAttribute("transform", transform); + SPCSSAttr *css = sp_repr_css_attr_new(); + Inkscape::FontLister *fontlister = Inkscape::FontLister::get_instance(); + fontlister->fill_css( css, (Glib::ustring)fontbutton.param_getSVGValue() ); + std::stringstream font_size; + font_size.imbue(std::locale::classic()); + font_size << fontsize << "pt"; + sp_repr_css_set_property (css, "font-size", font_size.str().c_str()); + sp_repr_css_set_property (css, "line-height", "125%"); + sp_repr_css_set_property (css, "letter-spacing", "0"); + sp_repr_css_set_property (css, "word-spacing", "0"); + sp_repr_css_set_property (css, "text-align", "center"); + sp_repr_css_set_property (css, "text-anchor", "middle"); + sp_repr_css_set_property (css, "fill", "#000000"); + sp_repr_css_set_property (css, "fill-opacity", "1"); + sp_repr_css_set_property (css, "stroke", "none"); + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + if (!rtspan) { + rtspan = rtext->firstChild(); + } + rtspan->setAttribute("style", css_str.c_str()); + sp_repr_css_attr_unref (css); + if (!elemref) { + rtext->addChild(rtspan, NULL); + Inkscape::GC::release(rtspan); + } + length = Inkscape::Util::Quantity::convert(length, doc_unit.c_str(), unit.get_abbreviation()); + std::stringstream length_str; + length_str.precision(precision); + length_str.setf(std::ios::fixed, std::ios::floatfield); + if (local_locale) { + length_str.imbue(std::locale("")); + } else { + length_str.imbue(std::locale::classic()); + } + length_str << std::fixed << length; + length_str << unit.get_abbreviation(); + Inkscape::XML::Node *rstring = NULL; + if (!elemref) { + rstring = xml_doc->createTextNode(length_str.str().c_str()); + rtspan->addChild(rstring, NULL); + Inkscape::GC::release(rstring); + } else { + rstring = rtspan->firstChild(); + rstring->setContent(length_str.str().c_str()); + } + SPObject * text_obj = NULL; + if (!elemref) { + text_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(rtext)); + Inkscape::GC::release(rtext); + } + } +} + +void +LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, bool main, bool remove) +{ + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { + Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + id).c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *line = NULL; + if (!main) { + Geom::Ray ray(start, end); + Geom::Coord angle = ray.angle(); + start = start + Point::polar(angle, helpline_distance ); + end = end + Point::polar(angle, helpline_overlap ); + } + Geom::Path line_path; + line_path.start(start); + line_path.appendNew(end); + Geom::PathVector line_pathv; + line_pathv.push_back(line_path); + gchar * line_str = sp_svg_write_path( line_pathv ); + line_pathv.clear(); + if (elemref = SVGElemRef->getObject()) { + if (remove) { + elemref->deleteObject(); + return; + } + line = elemref->getRepr(); + line->setAttribute("d" , line_str); + } else { + if (remove) { + return; + } + line = xml_doc->createElement("svg:path"); + line->setAttribute("id", id.c_str()); + line->setAttribute("d" , line_str); + } + Glib::ustring style = (Glib::ustring)"stroke:#000000;fill:none;"; + if (main) { + line->setAttribute("inkscape:label", "dinline"); + if (arrows_outside) { + style = style + (Glib::ustring)"marker-start:url(#ArrowDINout-start);marker-end:url(#ArrowDINout-end);"; + } else { + style = style + (Glib::ustring)"marker-start:url(#ArrowDIN-start);marker-end:url(#ArrowDIN-end);"; + } + } else { + line->setAttribute("inkscape:label", "dinhelpline"); + } + std::stringstream stroke_w; + stroke_w.imbue(std::locale::classic()); + if (line_group_05) { + double stroke_width = Inkscape::Util::Quantity::convert(0.25, "mm", doc_unit.c_str()); + stroke_w << stroke_width; + style = style + (Glib::ustring)"stroke-width:" + (Glib::ustring)stroke_w.str(); + } else { + double stroke_width = Inkscape::Util::Quantity::convert(0.35, "mm", doc_unit.c_str()); + stroke_w << stroke_width; + style = style + (Glib::ustring)"stroke-width:" + (Glib::ustring)stroke_w.str(); + } + line->setAttribute("style", style.c_str()); + SPObject * line_obj = NULL; + if (!elemref) { + line_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(line)); + Inkscape::GC::release(line); + } + } +} + void LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) { @@ -147,167 +367,99 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) SPPath *sp_path = dynamic_cast(splpeitem); if (sp_path) { Geom::PathVector pathvector = sp_path->get_original_curve()->get_pathvector(); + if (arrows_outside) { + createArrowMarker((Glib::ustring)"ArrowDINout-start"); + createArrowMarker((Glib::ustring)"ArrowDINout-end"); + } else { + createArrowMarker((Glib::ustring)"ArrowDIN-start"); + createArrowMarker((Glib::ustring)"ArrowDIN-end"); + } if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { size_t ncurves = pathvector.curveCount(); curve_linked.param_set_range(0, ncurves); - Geom::Point s = pathvector.initialPoint(); - Geom::Point e = pathvector.finalPoint(); - if (curve_linked) { //0 start-end nodes - s = pathvector.pointAt(curve_linked -1); - e = pathvector.pointAt(curve_linked); + Geom::Point start = pathvector.initialPoint(); + Geom::Point end = pathvector.finalPoint(); + if (curve_linked) { //!0 + start = pathvector.pointAt(curve_linked -1); + end = pathvector.pointAt(curve_linked); + } + Geom::Point hstart = start; + Geom::Point hend = end; + bool remove = false; + if (Geom::are_near(hstart, hend)) { + remove = true; } - Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); - Glib::ustring orientation_str; - Inkscape::XML::Node *rtext = NULL; if (orientation == OM_VERTICAL) { - orientation_str = "vertical"; - Coord xpos = std::max(s[Geom::X],e[Geom::X]); - if (reverse) { - xpos = std::min(s[Geom::X],e[Geom::X]); + Coord xpos = std::max(hstart[Geom::X],hend[Geom::X]); + if (flip_side) { + xpos = std::min(hstart[Geom::X],hend[Geom::X]); } - s[Geom::X] = xpos; - e[Geom::X] = xpos; - if (s[Geom::Y] > e[Geom::Y]) { - swap(s,e); + hstart[Geom::X] = xpos; + hend[Geom::X] = xpos; + if (hstart[Geom::Y] > hend[Geom::Y]) { + swap(hstart,hend); + swap(start,end); + } + if (Geom::are_near(hstart[Geom::Y], hend[Geom::Y])) { + remove = true; } } if (orientation == OM_HORIZONTAL) { - orientation_str = "horizontal"; - Coord ypos = std::max(s[Geom::Y],e[Geom::Y]); - if (reverse) { - ypos = std::min(s[Geom::Y],e[Geom::Y]); + Coord ypos = std::max(hstart[Geom::Y],hend[Geom::Y]); + if (flip_side) { + ypos = std::min(hstart[Geom::Y],hend[Geom::Y]); } - s[Geom::Y] = ypos; - e[Geom::Y] = ypos; - if (s[Geom::X] < e[Geom::X]) { - swap(s,e); + hstart[Geom::Y] = ypos; + hend[Geom::Y] = ypos; + if (hstart[Geom::X] < hend[Geom::X]) { + swap(hstart,hend); + swap(start,end); + } + if (Geom::are_near(hstart[Geom::X], hend[Geom::X])) { + remove = true; } } - if (orientation == OM_PARALLEL) { - orientation_str = "parallel"; - } - double length = Geom::distance(s, e) * scale; - Geom::Point pos = Geom::middle_point(s,e); - Geom::Ray ray(s,e); + double length = Geom::distance(start,end) * scale; + Geom::Point pos = Geom::middle_point(hstart,hend); + Geom::Ray ray(hstart,hend); Geom::Coord angle = ray.angle(); - doc_unit = Inkscape::Util::unit_table.getUnit(desktop->doc()->getRoot()->height.unit)->abbr; - if (reverse) { + if (flip_side) { angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); if (angle < 0) angle += 2*M_PI; } - Geom::Point newpos = pos - Point::polar(angle, offset_right_left); Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); if (angle_cross < 0) angle_cross += 2*M_PI; - newpos = newpos - Point::polar(angle_cross, offset_top_bottom); - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)this->getRepr()->attribute("id") + (Glib::ustring)"_text").c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - Inkscape::XML::Node *rtspan = NULL; - if (elemref = SVGElemRef->getObject()) { - rtext = elemref->getRepr(); - sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); - sp_repr_set_svg_double(rtext, "y", newpos[Geom::Y]); - } else { - rtext = xml_doc->createElement("svg:text"); - rtext->setAttribute("xml:space", "preserve"); - rtext->setAttribute("sodipodi:insensitive", "true"); - rtext->setAttribute("id", ((Glib::ustring)this->getRepr()->attribute("id") + (Glib::ustring)"_text").c_str()); - /* Set style */ - sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); - sp_repr_set_svg_double(rtext, "y", newpos[Geom::Y]); - /* Create */ - rtspan = xml_doc->createElement("svg:tspan"); - rtspan->setAttribute("sodipodi:role", "line"); - } - SPCSSAttr *css = sp_repr_css_attr_new(); + //We get the font size to offset the text to the middle Pango::FontDescription fontdesc((Glib::ustring)fontbutton.param_getSVGValue()); double fontsize = fontdesc.get_size()/Pango::SCALE; - Inkscape::FontLister *fontlister = Inkscape::FontLister::get_instance(); - fontlister->fill_css( css, (Glib::ustring)fontbutton.param_getSVGValue() ); - std::stringstream font_size; - font_size.imbue(std::locale::classic()); - font_size << fontsize << "pt"; - sp_repr_css_set_property (css, "font-size", font_size.str().c_str()); - sp_repr_css_set_property (css, "line-height", "125%"); - sp_repr_css_set_property (css, "letter-spacing", "0"); - sp_repr_css_set_property (css, "word-spacing", "0"); - sp_repr_css_set_property (css, "text-align", "center"); - sp_repr_css_set_property (css, "text-anchor", "middle"); - if (color_as_line) { - if (lpeitem->style) { - if (lpeitem->style->stroke.isPaintserver()) { - SPPaintServer * server = lpeitem->style->getStrokePaintServer(); - if (server) { - Glib::ustring str; - str += "url(#"; - str += server->getId(); - str += ")"; - sp_repr_css_set_property (css, "fill", str.c_str()); - } - } else if (lpeitem->style->stroke.isColor()) { - gchar c[64]; - sp_svg_write_color (c, sizeof(c), lpeitem->style->stroke.value.color.toRGBA32(SP_SCALE24_TO_FLOAT(lpeitem->style->stroke_opacity.value))); - sp_repr_css_set_property (css, "fill", c); - } else { - sp_repr_css_set_property (css, "fill", "#000000"); - } - } else { - sp_repr_css_unset_property (css, "#000000"); - } - } else { - sp_repr_css_set_property (css, "fill", "#000000"); - } - sp_repr_css_set_property (css, "fill-opacity", "1"); - sp_repr_css_set_property (css, "stroke", "none"); - Glib::ustring css_str; - sp_repr_css_write_string(css,css_str); - if (!rtspan) { - rtspan = rtext->firstChild(); - } - rtspan->setAttribute("style", css_str.c_str()); - sp_repr_css_attr_unref (css); - if (!elemref) { - rtext->addChild(rtspan, NULL); - Inkscape::GC::release(rtspan); - } - /* Create TEXT */ + pos = pos - Point::polar(angle_cross, (position + text_distance) - fontsize/2.0); if (!scale_insensitive) { Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); length *= (affinetransform.expansionX() + affinetransform.expansionY()) / 2.0; } - length = Inkscape::Util::Quantity::convert(length, doc_unit.c_str(), unit.get_abbreviation()); - std::stringstream length_str; - length_str.precision(precision); - length_str.setf(std::ios::fixed, std::ios::floatfield); - if (local_locale) { - length_str.imbue(std::locale("")); - } else { - length_str.imbue(std::locale::classic()); + createTextLabel(pos, length, angle, fontsize, remove); + //LINE + double arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.35, "mm", doc_unit.c_str()); + if (line_group_05) { + arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.25, "mm", doc_unit.c_str()); } - length_str << std::fixed << length; - length_str << unit.get_abbreviation(); - Inkscape::XML::Node *rstring = NULL; - if (!elemref) { - rstring = xml_doc->createTextNode(length_str.str().c_str()); - rtspan->addChild(rstring, NULL); - Inkscape::GC::release(rstring); - } else { - rstring = rtspan->firstChild(); - rstring->setContent(length_str.str().c_str()); + if (flip_side) { + arrow_gap *= -1; } - SPObject * text_obj = NULL; - if (!elemref) { - text_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(rtext)); - Inkscape::GC::release(rtext); - } else { - text_obj = desktop->currentLayer()->get_child_by_repr(rtext); + angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); + if (angle_cross < 0) angle_cross += 2*M_PI; + hstart = hstart - Point::polar(angle_cross, position); + Glib::ustring id = (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id"); + createLine(start, hstart, id, false, remove); + hend = hend - Point::polar(angle_cross, position); + id = (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id"); + createLine(end, hend, id, false, remove); + if (!arrows_outside) { + hstart = hstart + Point::polar(angle, arrow_gap); + hend = hend - Point::polar(angle, arrow_gap ); } - Geom::Affine affine = Geom::Affine(Geom::Translate(newpos).inverse()); - affine *= Geom::Rotate(angle); - affine *= Geom::Translate(newpos); - SP_ITEM(text_obj)->transform = affine * i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); - text_obj->updateRepr(); + id = (Glib::ustring)"infoline-" + (Glib::ustring)this->getRepr()->attribute("id"); + createLine(hstart, hend, id, true, remove); } } } @@ -316,11 +468,28 @@ void LPEMeasureLine::doOnRemove (SPLPEItem const* lpeitem) { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { SPLPEItem * splpeitem = const_cast(lpeitem); - Inkscape::URI SVGElem_uri(((Glib::ustring)this->getRepr()->attribute("id") + (Glib::ustring)"_text").c_str()); + Inkscape::URI SVGElem_uri(( (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); SVGElemRef->attach(SVGElem_uri); SPObject *elemref = NULL; - Inkscape::XML::Node *rtspan = NULL; + if (elemref = SVGElemRef->getObject()) { + elemref->deleteObject(); + } + Inkscape::URI SVGElem_uri2(( (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + SVGElemRef->attach(SVGElem_uri2); + elemref = NULL; + if (elemref = SVGElemRef->getObject()) { + elemref->deleteObject(); + } + Inkscape::URI SVGElem_uri3(( (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + SVGElemRef->attach(SVGElem_uri3); + elemref = NULL; + if (elemref = SVGElemRef->getObject()) { + elemref->deleteObject(); + } + Inkscape::URI SVGElem_uri4(( (Glib::ustring)"infoline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + SVGElemRef->attach(SVGElem_uri4); + elemref = NULL; if (elemref = SVGElemRef->getObject()) { elemref->deleteObject(); } @@ -377,13 +546,17 @@ LPEMeasureLine::saveDefault() prefs->setString("/live_effects/measure-line/fontbutton", (Glib::ustring)fontbutton.param_getSVGValue()); prefs->setDouble("/live_effects/measure-line/scale", scale); prefs->setInt("/live_effects/measure-line/precision", precision); - prefs->setDouble("/live_effects/measure-line/offset_right_left", offset_right_left); - prefs->setDouble("/live_effects/measure-line/offset_top_bottom", offset_top_bottom); + prefs->setDouble("/live_effects/measure-line/position", position); + prefs->setDouble("/live_effects/measure-line/text_distance", text_distance); + prefs->setDouble("/live_effects/measure-line/helpline_distance", helpline_distance); + prefs->setDouble("/live_effects/measure-line/helpline_overlap", helpline_overlap); prefs->setString("/live_effects/measure-line/unit", (Glib::ustring)unit.get_abbreviation()); - prefs->setBool("/live_effects/measure-line/reverse", reverse); - prefs->setBool("/live_effects/measure-line/color_as_line", color_as_line); + prefs->setString("/live_effects/measure-line/format", (Glib::ustring)format.param_getSVGValue()); + prefs->setBool("/live_effects/measure-line/flip_side", flip_side); prefs->setBool("/live_effects/measure-line/scale_insensitive", scale_insensitive); prefs->setBool("/live_effects/measure-line/local_locale", local_locale); + prefs->setBool("/live_effects/measure-line/line_group_05", line_group_05); + prefs->setBool("/live_effects/measure-line/rotate_anotation", rotate_anotation); } }; //namespace LivePathEffect diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 834194841..d54859f8c 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -41,6 +41,9 @@ public: virtual void doOnRemove (SPLPEItem const* lpeitem); virtual void doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/); virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); + void createLine(Geom::Point start,Geom::Point end,Glib::ustring id, bool main, bool remove); + void createTextLabel(Geom::Point pos, double length, Geom::Coord angle, double fontsize, bool remove); + void createArrowMarker(Glib::ustring mode); void saveDefault(); virtual Gtk::Widget *newWidget(); private: @@ -49,15 +52,18 @@ private: ScalarParam curve_linked; ScalarParam scale; ScalarParam precision; - ScalarParam offset_right_left; - ScalarParam offset_top_bottom; - ScalarParam gap_start; - ScalarParam gap_end; + ScalarParam position; + ScalarParam text_distance; + ScalarParam helpline_distance; + ScalarParam helpline_overlap; UnitParam unit; - BoolParam reverse; - BoolParam color_as_line; + TextParam format; + BoolParam arrows_outside; + BoolParam flip_side; BoolParam scale_insensitive; BoolParam local_locale; + BoolParam line_group_05; + BoolParam rotate_anotation; Glib::ustring doc_unit; /* Geom::Affine affine_over;*/ LPEMeasureLine(const LPEMeasureLine &); diff --git a/src/live_effects/parameter/text.cpp b/src/live_effects/parameter/text.cpp index 234a6174d..e51cf93ab 100644 --- a/src/live_effects/parameter/text.cpp +++ b/src/live_effects/parameter/text.cpp @@ -31,7 +31,8 @@ TextParam::TextParam( const Glib::ustring& label, const Glib::ustring& tip, Effect* effect, const Glib::ustring default_value ) : Parameter(label, tip, key, wr, effect), value(default_value), - defvalue(default_value) + defvalue(default_value), + _hide_canvas_text(false) { SPDesktop *desktop = SP_ACTIVE_DESKTOP; // FIXME: we shouldn't use this! canvas_text = (SPCanvasText *) sp_canvastext_new(desktop->getTempGroup(), desktop, Geom::Point(0,0), ""); @@ -45,10 +46,25 @@ TextParam::param_set_default() param_setValue(defvalue); } +void +TextParam::param_update_default(Glib::ustring default_value) +{ + defvalue = default_value; +} + +void +TextParam::param_hide_canvas_text() +{ + _hide_canvas_text = true; + sp_canvastext_set_text (canvas_text,""); +} + void TextParam::setPos(Geom::Point pos) { - sp_canvastext_set_coords (canvas_text, pos); + if (!_hide_canvas_text) { + sp_canvastext_set_coords (canvas_text, pos); + } } void @@ -63,9 +79,10 @@ TextParam::setPosAndAnchor(const Geom::Piecewise > &pwd2, Point dir = unit_vector(derivative(pwd2_reparam).valueAt(t_reparam)); Point n = -rot90(dir); double angle = Geom::angle_between(dir, Point(1,0)); - - sp_canvastext_set_coords(canvas_text, pos + n * length); - sp_canvastext_set_anchor_manually(canvas_text, std::sin(angle), -std::cos(angle)); + if (!_hide_canvas_text) { + sp_canvastext_set_coords(canvas_text, pos + n * length); + sp_canvastext_set_anchor_manually(canvas_text, std::sin(angle), -std::cos(angle)); + } } void @@ -73,7 +90,9 @@ TextParam::setAnchor(double x_value, double y_value) { anchor_x = x_value; anchor_y = y_value; - sp_canvastext_set_anchor_manually (canvas_text, anchor_x, anchor_y); + if (!_hide_canvas_text) { + sp_canvastext_set_anchor_manually (canvas_text, anchor_x, anchor_y); + } } bool @@ -107,8 +126,9 @@ void TextParam::param_setValue(const Glib::ustring newvalue) { value = newvalue; - - sp_canvastext_set_text (canvas_text, newvalue.c_str()); + if (!_hide_canvas_text) { + sp_canvastext_set_text (canvas_text, newvalue.c_str()); + } } } /* namespace LivePathEffect */ diff --git a/src/live_effects/parameter/text.h b/src/live_effects/parameter/text.h index 62de70eec..553c84c0a 100644 --- a/src/live_effects/parameter/text.h +++ b/src/live_effects/parameter/text.h @@ -40,7 +40,9 @@ public: virtual gchar * param_getSVGValue() const; void param_setValue(const Glib::ustring newvalue); + void param_hide_canvas_text(); virtual void param_set_default(); + void param_update_default(Glib::ustring default_value); void setPos(Geom::Point pos); void setPosAndAnchor(const Geom::Piecewise > &pwd2, const double t, const double length, bool use_curvature = false); @@ -53,7 +55,7 @@ private: TextParam& operator=(const TextParam&); double anchor_x; double anchor_y; - + bool _hide_canvas_text; Glib::ustring value; Glib::ustring defvalue; -- cgit v1.2.3 From cbbb526d842570fb993598537204ba7b6394d68e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 31 Jul 2016 17:34:33 +0200 Subject: Font and lenght problems in diferent display units solved, also handle uniform scale viewbox (bzr r15017.1.18) --- src/live_effects/lpe-measure-line.cpp | 40 +++++++++++++++++++++++++++-------- src/live_effects/lpe-measure-line.h | 3 ++- 2 files changed, 33 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index c2a502e00..716f15a5e 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -198,9 +198,30 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); Inkscape::XML::Node *rtext = NULL; - doc_unit = Inkscape::Util::unit_table.getUnit(desktop->doc()->getRoot()->height.unit)->abbr; - if (doc_unit.empty()) { - doc_unit = "px"; + double doc_w = desktop->getDocument()->getRoot()->width.value; +// Glib::ustring doc_unit = unit_table.getUnit(desktop->getDocument()->getRoot()->width.unit)->abbr; +// if (doc_unit == "") { +// doc_unit = "px"; +// } else if (doc_unit == "%" && desktop->getDocument()->getRoot()->viewBox_set) { +// doc_w_unit = "px"; +// doc_w = desktop->getDocument()->getRoot()->viewBox.width(); +// } +// doc_unit = Inkscape::Util::unit_table.getUnit(desktop->doc()->getRoot()->height.unit)->abbr; +// if (doc_unit.empty()) { +// doc_unit = "px"; +// } + Geom::Scale scale = desktop->getDocument()->getDocumentScale(); + SPNamedView *nv = desktop->getNamedView(); + Glib::ustring display_unit = nv->display_units->abbr; + if (display_unit.empty()) { + display_unit = "px"; + } + //only check constrain viewbox on X + doc_scale = Inkscape::Util::Quantity::convert( scale[Geom::X], "px", nv->display_units ); + if( doc_scale > 0 ) { + doc_scale= 1.0/doc_scale; + } else { + doc_scale = 1.0; } Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); @@ -263,7 +284,7 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl rtext->addChild(rtspan, NULL); Inkscape::GC::release(rtspan); } - length = Inkscape::Util::Quantity::convert(length, doc_unit.c_str(), unit.get_abbreviation()); + length = Inkscape::Util::Quantity::convert(length / doc_scale, display_unit.c_str(), unit.get_abbreviation()); std::stringstream length_str; length_str.precision(precision); length_str.setf(std::ios::fixed, std::ios::floatfield); @@ -343,11 +364,11 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, std::stringstream stroke_w; stroke_w.imbue(std::locale::classic()); if (line_group_05) { - double stroke_width = Inkscape::Util::Quantity::convert(0.25, "mm", doc_unit.c_str()); + double stroke_width = Inkscape::Util::Quantity::convert(0.25 / doc_scale, "mm", display_unit.c_str()); stroke_w << stroke_width; style = style + (Glib::ustring)"stroke-width:" + (Glib::ustring)stroke_w.str(); } else { - double stroke_width = Inkscape::Util::Quantity::convert(0.35, "mm", doc_unit.c_str()); + double stroke_width = Inkscape::Util::Quantity::convert(0.35 / doc_scale, "mm", display_unit.c_str()); stroke_w << stroke_width; style = style + (Glib::ustring)"stroke-width:" + (Glib::ustring)stroke_w.str(); } @@ -419,7 +440,7 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) remove = true; } } - double length = Geom::distance(start,end) * scale; + double length = Geom::distance(hstart,hend) * scale; Geom::Point pos = Geom::middle_point(hstart,hend); Geom::Ray ray(hstart,hend); Geom::Coord angle = ray.angle(); @@ -432,6 +453,7 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) //We get the font size to offset the text to the middle Pango::FontDescription fontdesc((Glib::ustring)fontbutton.param_getSVGValue()); double fontsize = fontdesc.get_size()/Pango::SCALE; + fontsize *= desktop->doc()->getRoot()->c2p.inverse().expansionX(); pos = pos - Point::polar(angle_cross, (position + text_distance) - fontsize/2.0); if (!scale_insensitive) { Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); @@ -439,9 +461,9 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } createTextLabel(pos, length, angle, fontsize, remove); //LINE - double arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.35, "mm", doc_unit.c_str()); + double arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.35 / doc_scale, "mm", display_unit.c_str()); if (line_group_05) { - arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.25, "mm", doc_unit.c_str()); + arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.25 / doc_scale, "mm", display_unit.c_str()); } if (flip_side) { arrow_gap *= -1; diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index d54859f8c..581bbb7e4 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -64,7 +64,8 @@ private: BoolParam local_locale; BoolParam line_group_05; BoolParam rotate_anotation; - Glib::ustring doc_unit; + Glib::ustring display_unit; + double doc_scale; /* Geom::Affine affine_over;*/ LPEMeasureLine(const LPEMeasureLine &); LPEMeasureLine &operator=(const LPEMeasureLine &); -- cgit v1.2.3 From 5697c9788ff67d3382d9df31107daa9b7d2aacd2 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 31 Jul 2016 18:57:35 +0200 Subject: Rotate the text label on down position 180 degree (bzr r15017.1.19) --- src/live_effects/lpe-measure-line.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 716f15a5e..b4ad45092 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -56,7 +56,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : text_distance(_("Text distance*"), _("Text distance"), "text_distance", &wr, this, 12), helpline_distance(_("Helpline distance*"), _("Helpline distance"), "helpline_distance", &wr, this, 0.0), helpline_overlap(_("Helpline overlap*"), _("Helpline overlap"), "helpline_overlap", &wr, this, 2.0), - unit(_("Unit*"), _("Unit"), "unit", &wr, this), + unit(_("Unit*"), _("Unit"), "unit", &wr, this, "px"), format(_("Format*"), _("Format the number ex:measure+ +unit"), "format", &wr, this, "measure+unit"), arrows_outside(_("Arrows outside"), _("Arrows outside"), "arrows_outside", &wr, this, false), flip_side(_("Flip side*"), _("Flip side"), "flip_side", &wr, this, false), @@ -251,7 +251,11 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl gchar * transform; if (rotate_anotation) { Geom::Affine affine = Geom::Affine(Geom::Translate(pos).inverse()); - affine *= Geom::Rotate(angle); + if (std::abs(angle) > rad_from_deg(90) && std::abs(angle) < rad_from_deg(270)) { + angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); + if (angle < 0) angle += 2*M_PI; + } + affine *= Geom::Rotate(std::abs(angle)); affine *= Geom::Translate(pos); transform = sp_svg_transform_write(affine); } else { @@ -448,13 +452,17 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); if (angle < 0) angle += 2*M_PI; } - Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); - if (angle_cross < 0) angle_cross += 2*M_PI; //We get the font size to offset the text to the middle Pango::FontDescription fontdesc((Glib::ustring)fontbutton.param_getSVGValue()); double fontsize = fontdesc.get_size()/Pango::SCALE; fontsize *= desktop->doc()->getRoot()->c2p.inverse().expansionX(); - pos = pos - Point::polar(angle_cross, (position + text_distance) - fontsize/2.0); + Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); + if (angle_cross < 0) angle_cross += 2*M_PI; + if (std::abs(angle) > rad_from_deg(90) && std::abs(angle) < rad_from_deg(270)) { + pos = pos - Point::polar(angle_cross, (position - text_distance) + fontsize/2.0); + } else { + pos = pos - Point::polar(angle_cross, (position + text_distance) - fontsize/2.0); + } if (!scale_insensitive) { Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); length *= (affinetransform.expansionX() + affinetransform.expansionY()) / 2.0; -- cgit v1.2.3 From 372309acc2c71ec2153f58f8ee6917ecf4d5d341 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 31 Jul 2016 19:34:59 +0200 Subject: Fix label positioning (bzr r15017.1.20) --- src/live_effects/lpe-measure-line.cpp | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index b4ad45092..97da89fd1 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -199,17 +199,6 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); Inkscape::XML::Node *rtext = NULL; double doc_w = desktop->getDocument()->getRoot()->width.value; -// Glib::ustring doc_unit = unit_table.getUnit(desktop->getDocument()->getRoot()->width.unit)->abbr; -// if (doc_unit == "") { -// doc_unit = "px"; -// } else if (doc_unit == "%" && desktop->getDocument()->getRoot()->viewBox_set) { -// doc_w_unit = "px"; -// doc_w = desktop->getDocument()->getRoot()->viewBox.width(); -// } -// doc_unit = Inkscape::Util::unit_table.getUnit(desktop->doc()->getRoot()->height.unit)->abbr; -// if (doc_unit.empty()) { -// doc_unit = "px"; -// } Geom::Scale scale = desktop->getDocument()->getDocumentScale(); SPNamedView *nv = desktop->getNamedView(); Glib::ustring display_unit = nv->display_units->abbr; @@ -251,11 +240,13 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl gchar * transform; if (rotate_anotation) { Geom::Affine affine = Geom::Affine(Geom::Translate(pos).inverse()); - if (std::abs(angle) > rad_from_deg(90) && std::abs(angle) < rad_from_deg(270)) { + angle = std::fmod(angle, 2*M_PI); + if (angle < 0) angle += 2*M_PI; + if (angle >= rad_from_deg(90) && angle < rad_from_deg(270)) { angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); if (angle < 0) angle += 2*M_PI; } - affine *= Geom::Rotate(std::abs(angle)); + affine *= Geom::Rotate(angle); affine *= Geom::Translate(pos); transform = sp_svg_transform_write(affine); } else { @@ -458,7 +449,9 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) fontsize *= desktop->doc()->getRoot()->c2p.inverse().expansionX(); Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); if (angle_cross < 0) angle_cross += 2*M_PI; - if (std::abs(angle) > rad_from_deg(90) && std::abs(angle) < rad_from_deg(270)) { + angle = std::fmod(angle, 2*M_PI); + if (angle < 0) angle += 2*M_PI; + if (angle >= rad_from_deg(90) && angle < rad_from_deg(270)) { pos = pos - Point::polar(angle_cross, (position - text_distance) + fontsize/2.0); } else { pos = pos - Point::polar(angle_cross, (position + text_distance) - fontsize/2.0); -- cgit v1.2.3 From 28d25258de5d2274382dbb592f62e21ca8f91729 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 1 Aug 2016 00:47:38 +0200 Subject: Fix text param and alow run from commandline (bzr r15017.1.21) --- src/live_effects/lpe-measure-line.cpp | 32 ++++++++++++++++++++++++-------- src/live_effects/parameter/text.cpp | 20 ++++++++++++-------- src/ui/widget/registered-widget.cpp | 13 ++++--------- src/ui/widget/text.cpp | 6 +++--- src/ui/widget/text.h | 4 ++-- 5 files changed, 45 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 97da89fd1..fc2ff0f8b 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -57,7 +57,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : helpline_distance(_("Helpline distance*"), _("Helpline distance"), "helpline_distance", &wr, this, 0.0), helpline_overlap(_("Helpline overlap*"), _("Helpline overlap"), "helpline_overlap", &wr, this, 2.0), unit(_("Unit*"), _("Unit"), "unit", &wr, this, "px"), - format(_("Format*"), _("Format the number ex:measure+ +unit"), "format", &wr, this, "measure+unit"), + format(_("Format*"), _("Format the number ex:{measure} {unit}, return to save"), "format", &wr, this,"measure unit"), arrows_outside(_("Arrows outside"), _("Arrows outside"), "arrows_outside", &wr, this, false), flip_side(_("Flip side*"), _("Flip side"), "flip_side", &wr, this, false), scale_insensitive(_("Scale insensitive*"), _("Scale insensitive to transforms in element, parents..."), "scale_insensitive", &wr, this, true), @@ -83,15 +83,27 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : registerParameter(&line_group_05); registerParameter(&rotate_anotation); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - fontbutton.param_update_default(prefs->getString("/live_effects/measure-line/fontbutton")); + Glib::ustring fontbutton_value = prefs->getString("/live_effects/measure-line/fontbutton"); + if(fontbutton_value.empty()){ + fontbutton_value = "Sans 10"; + } + fontbutton.param_update_default(fontbutton_value); scale.param_update_default(prefs->getDouble("/live_effects/measure-line/scale", 1.0)); precision.param_update_default(prefs->getInt("/live_effects/measure-line/precision", 2)); position.param_update_default(prefs->getDouble("/live_effects/measure-line/position", 10.0)); text_distance.param_update_default(prefs->getDouble("/live_effects/measure-line/text_distance", 5.0)); helpline_distance.param_update_default(prefs->getDouble("/live_effects/measure-line/helpline_distance", 0.0)); helpline_overlap.param_update_default(prefs->getDouble("/live_effects/measure-line/helpline_overlap", 0.0)); - unit.param_update_default(prefs->getString("/live_effects/measure-line/unit")); - format.param_update_default(prefs->getString("/live_effects/measure-line/format")); + Glib::ustring unit_value = prefs->getString("/live_effects/measure-line/unit"); + if(unit_value.empty()){ + unit_value = "px"; + } + unit.param_update_default(unit_value); + Glib::ustring format_value = prefs->getString("/live_effects/measure-line/format"); + if(format_value.empty()){ + format_value = "{measure}{unit}"; + } + format.param_update_default(format_value); flip_side.param_update_default(prefs->getBool("/live_effects/measure-line/flip_side")); scale_insensitive.param_update_default(prefs->getBool("/live_effects/measure-line/scale_insensitive")); local_locale.param_update_default(prefs->getBool("/live_effects/measure-line/local_locale")); @@ -391,6 +403,10 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) createArrowMarker((Glib::ustring)"ArrowDIN-end"); } if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { + if (((Glib::ustring)format.param_getSVGValue()).empty()) { + format.param_setValue((Glib::ustring)"{measure}{unit}"); + this->upd_params = true; + } size_t ncurves = pathvector.curveCount(); curve_linked.param_set_range(0, ncurves); Geom::Point start = pathvector.initialPoint(); @@ -491,26 +507,26 @@ void LPEMeasureLine::doOnRemove (SPLPEItem const* lpeitem) { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { SPLPEItem * splpeitem = const_cast(lpeitem); - Inkscape::URI SVGElem_uri(( (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); SVGElemRef->attach(SVGElem_uri); SPObject *elemref = NULL; if (elemref = SVGElemRef->getObject()) { elemref->deleteObject(); } - Inkscape::URI SVGElem_uri2(( (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + Inkscape::URI SVGElem_uri2(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); SVGElemRef->attach(SVGElem_uri2); elemref = NULL; if (elemref = SVGElemRef->getObject()) { elemref->deleteObject(); } - Inkscape::URI SVGElem_uri3(( (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + Inkscape::URI SVGElem_uri3(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); SVGElemRef->attach(SVGElem_uri3); elemref = NULL; if (elemref = SVGElemRef->getObject()) { elemref->deleteObject(); } - Inkscape::URI SVGElem_uri4(( (Glib::ustring)"infoline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + Inkscape::URI SVGElem_uri4(((Glib::ustring)"#" + (Glib::ustring)"infoline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); SVGElemRef->attach(SVGElem_uri4); elemref = NULL; if (elemref = SVGElemRef->getObject()) { diff --git a/src/live_effects/parameter/text.cpp b/src/live_effects/parameter/text.cpp index e51cf93ab..0650b7e66 100644 --- a/src/live_effects/parameter/text.cpp +++ b/src/live_effects/parameter/text.cpp @@ -34,10 +34,13 @@ TextParam::TextParam( const Glib::ustring& label, const Glib::ustring& tip, defvalue(default_value), _hide_canvas_text(false) { - SPDesktop *desktop = SP_ACTIVE_DESKTOP; // FIXME: we shouldn't use this! - canvas_text = (SPCanvasText *) sp_canvastext_new(desktop->getTempGroup(), desktop, Geom::Point(0,0), ""); - sp_canvastext_set_text (canvas_text, default_value.c_str()); - sp_canvastext_set_coords (canvas_text, 0, 0); + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { // FIXME: we shouldn't use this! + canvas_text = (SPCanvasText *) sp_canvastext_new(desktop->getTempGroup(), desktop, Geom::Point(0,0), ""); + sp_canvastext_set_text (canvas_text, default_value.c_str()); + sp_canvastext_set_coords (canvas_text, 0, 0); + } else { + _hide_canvas_text = true; + } } void @@ -55,8 +58,10 @@ TextParam::param_update_default(Glib::ustring default_value) void TextParam::param_hide_canvas_text() { - _hide_canvas_text = true; - sp_canvastext_set_text (canvas_text,""); + if (!_hide_canvas_text) { + sp_canvastext_set_text(canvas_text, " "); + _hide_canvas_text = true; + } } void @@ -113,8 +118,7 @@ TextParam::param_newWidget() { Inkscape::UI::Widget::RegisteredText *rsu = Gtk::manage(new Inkscape::UI::Widget::RegisteredText( param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc())); - - rsu->setText(value.c_str()); + rsu->setText(value); rsu->setProgrammatically = false; rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change text parameter")); diff --git a/src/ui/widget/registered-widget.cpp b/src/ui/widget/registered-widget.cpp index 923949b72..8b8bdc8e4 100644 --- a/src/ui/widget/registered-widget.cpp +++ b/src/ui/widget/registered-widget.cpp @@ -331,8 +331,6 @@ RegisteredText::RegisteredText ( const Glib::ustring& label, const Glib::ustring init_parent(key, wr, repr_in, doc_in); setProgrammatically = false; - - setText(""); _activate_connection = signal_activate().connect (sigc::mem_fun (*this, &RegisteredText::on_activate)); } @@ -348,16 +346,13 @@ RegisteredText::on_activate() return; } _wr->setUpdating (true); - - Inkscape::SVGOStringStream os; - os << getText(); - + Glib::ustring str(getText()); set_sensitive(false); + Inkscape::SVGOStringStream os; + os << str; write_to_xml(os.str().c_str()); - set_sensitive(true); - setText(os.str().c_str()); - + set_sensitive(true); _wr->setUpdating (false); } diff --git a/src/ui/widget/text.cpp b/src/ui/widget/text.cpp index ec58d5bb4..e6795b138 100644 --- a/src/ui/widget/text.cpp +++ b/src/ui/widget/text.cpp @@ -28,13 +28,13 @@ Text::Text(Glib::ustring const &label, Glib::ustring const &tooltip, { } -const char *Text::getText() const +Glib::ustring const Text::getText() const { g_assert(_widget != NULL); - return static_cast(_widget)->get_text().c_str(); + return static_cast(_widget)->get_text(); } -void Text::setText(const char* text) +void Text::setText(Glib::ustring const text) { g_assert(_widget != NULL); setProgrammatically = true; // callback is supposed to reset back, if it cares diff --git a/src/ui/widget/text.h b/src/ui/widget/text.h index b90788940..593875b23 100644 --- a/src/ui/widget/text.h +++ b/src/ui/widget/text.h @@ -44,12 +44,12 @@ public: /** * Get the text in the entry. */ - const char* getText() const; + Glib::ustring const getText() const; /** * Sets the text of the text entry. */ - void setText(const char* text); + void setText(Glib::ustring const text); void update(); -- cgit v1.2.3 From c10966d3ebdac9c920d6329aa4eaca4d450c84da Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 1 Aug 2016 10:50:36 +0200 Subject: Finish format text label (bzr r15017.1.22) --- src/live_effects/lpe-measure-line.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index fc2ff0f8b..ad8a050ea 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -301,15 +301,23 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl length_str.imbue(std::locale::classic()); } length_str << std::fixed << length; - length_str << unit.get_abbreviation(); + Glib::ustring label_value = Glib::ustring(format.param_getSVGValue()); + size_t s = label_value.find((Glib::ustring)"{measure}",0); + if(s < label_value.length()) { + label_value.replace(s,s+9,length_str.str()); + } + s = label_value.find((Glib::ustring)"{unit}",0); + if(s < label_value.length()) { + label_value.replace(s,s+6,unit.get_abbreviation()); + } Inkscape::XML::Node *rstring = NULL; if (!elemref) { - rstring = xml_doc->createTextNode(length_str.str().c_str()); + rstring = xml_doc->createTextNode(label_value.c_str()); rtspan->addChild(rstring, NULL); Inkscape::GC::release(rstring); } else { rstring = rtspan->firstChild(); - rstring->setContent(length_str.str().c_str()); + rstring->setContent(label_value.c_str()); } SPObject * text_obj = NULL; if (!elemref) { -- cgit v1.2.3 From a456c94f4b7e0e385c8a5e89247065804f0abf93 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 1 Aug 2016 16:25:45 +0200 Subject: Add css override style and order widgets (bzr r15017.1.23) --- src/live_effects/lpe-measure-line.cpp | 105 ++++++++++++++++++++++++++++++---- src/live_effects/lpe-measure-line.h | 11 +++- 2 files changed, 102 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index ad8a050ea..1755f0232 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -47,34 +47,39 @@ static const Util::EnumDataConverter OMConverter(OrientationM LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : Effect(lpeobject), + unit(_("Unit*"), _("Unit"), "unit", &wr, this, "px"), fontbutton(_("Font*"), _("Font Selector"), "fontbutton", &wr, this), orientation(_("Orientation"), _("Orientation method"), "orientation", OMConverter, &wr, this, OM_PARALLEL, false), curve_linked(_("Curve on origin"), _("Curve on origin, set 0 to start/end"), "curve_linked", &wr, this, 1), - scale(_("Scale*"), _("Scaling factor"), "scale", &wr, this, 1.0), precision(_("Precision*"), _("Precision"), "precision", &wr, this, 2), position(_("Positon*"), _("Positon"), "position", &wr, this, 5), text_distance(_("Text distance*"), _("Text distance"), "text_distance", &wr, this, 12), helpline_distance(_("Helpline distance*"), _("Helpline distance"), "helpline_distance", &wr, this, 0.0), helpline_overlap(_("Helpline overlap*"), _("Helpline overlap"), "helpline_overlap", &wr, this, 2.0), - unit(_("Unit*"), _("Unit"), "unit", &wr, this, "px"), + scale(_("Scale*"), _("Scaling factor"), "scale", &wr, this, 1.0), format(_("Format*"), _("Format the number ex:{measure} {unit}, return to save"), "format", &wr, this,"measure unit"), arrows_outside(_("Arrows outside"), _("Arrows outside"), "arrows_outside", &wr, this, false), flip_side(_("Flip side*"), _("Flip side"), "flip_side", &wr, this, false), scale_insensitive(_("Scale insensitive*"), _("Scale insensitive to transforms in element, parents..."), "scale_insensitive", &wr, this, true), local_locale(_("Local Number Format*"), _("Local number format"), "local_locale", &wr, this, true), line_group_05(_("Line Group 0.5*"), _("Line Group 0.5, from 0.7"), "line_group_05", &wr, this, true), - rotate_anotation(_("Rotate Anotation*"), _("Rotate Anotation"), "rotate_anotation", &wr, this, true) + rotate_anotation(_("Rotate Anotation*"), _("Rotate Anotation"), "rotate_anotation", &wr, this, true), + dimline_format(_("CSS DIN line*"), _("Override CSS to DIN line, return to save, empty to reset to DIM"), "dimline_format", &wr, this,""), + helperlines_format(_("CSS helpers*"), _("Override CSS to helper lines, return to save, empty to reset to DIM"), "helperlines_format", &wr, this,""), + anotation_format(_("CSS anotation*"), _("Override CSS to anotation text, return to save, empty to reset to DIM"), "anotation_format", &wr, this,""), + arrows_format(_("CSS arrows*"), _("Override CSS to arrows, return to save, empty to reset DIM"), "arrows_format", &wr, this,""), + expanded(false) { + registerParameter(&unit); registerParameter(&fontbutton); registerParameter(&orientation); registerParameter(&curve_linked); - registerParameter(&scale); registerParameter(&precision); registerParameter(&position); registerParameter(&text_distance); registerParameter(&helpline_distance); registerParameter(&helpline_overlap); - registerParameter(&unit); + registerParameter(&scale); registerParameter(&format); registerParameter(&arrows_outside); registerParameter(&flip_side); @@ -82,6 +87,10 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : registerParameter(&local_locale); registerParameter(&line_group_05); registerParameter(&rotate_anotation); + registerParameter(&dimline_format); + registerParameter(&helperlines_format); + registerParameter(&anotation_format); + registerParameter(&arrows_format); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); Glib::ustring fontbutton_value = prefs->getString("/live_effects/measure-line/fontbutton"); if(fontbutton_value.empty()){ @@ -104,6 +113,10 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : format_value = "{measure}{unit}"; } format.param_update_default(format_value); + dimline_format.param_update_default(prefs->getString("/live_effects/measure-line/dimline_format")); + helperlines_format.param_update_default(prefs->getString("/live_effects/measure-line/helperlines_format")); + anotation_format.param_update_default(prefs->getString("/live_effects/measure-line/anotation_format")); + arrows_format.param_update_default(prefs->getString("/live_effects/measure-line/arrows_format")); flip_side.param_update_default(prefs->getBool("/live_effects/measure-line/flip_side")); scale_insensitive.param_update_default(prefs->getBool("/live_effects/measure-line/scale_insensitive")); local_locale.param_update_default(prefs->getBool("/live_effects/measure-line/local_locale")); @@ -195,11 +208,31 @@ LPEMeasureLine::createArrowMarker(Glib::ustring mode) arrow_path->setAttribute("d", "M 0,0 16,2.11 16,0.5 26,0.5 26,-0.5 16,-0.5 16,-2.11 z"); } arrow_path->setAttribute("id", (mode + (Glib::ustring)"_path").c_str()); - arrow_path->setAttribute("style", "fill:#000000;stroke:none"); + SPCSSAttr *css = sp_repr_css_attr_new(); + sp_repr_css_set_property (css, "fill","#000000"); + sp_repr_css_set_property (css, "stroke","none" ); + sp_repr_css_attr_add_from_string(css, arrows_format.param_getSVGValue()); + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + arrow_path->setAttribute("style", css_str.c_str()); arrow->addChild(arrow_path, NULL); Inkscape::GC::release(arrow_path); SPObject * arrow_obj = SP_OBJECT(desktop->getDocument()->getDefs()->appendChildRepr(arrow)); Inkscape::GC::release(arrow); + } else { + Inkscape::XML::Node *arrow= elemref->getRepr(); + if (arrow) { + Inkscape::XML::Node *arrow_data = arrow->firstChild(); + if (arrow_data) { + SPCSSAttr *css = sp_repr_css_attr_new(); + sp_repr_css_set_property (css, "fill","#000000"); + sp_repr_css_set_property (css, "stroke","none" ); + sp_repr_css_attr_add_from_string(css, arrows_format.param_getSVGValue()); + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + arrow_data->setAttribute("style", css_str.c_str()); + } + } } } } @@ -266,26 +299,29 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl } rtext->setAttribute("transform", transform); SPCSSAttr *css = sp_repr_css_attr_new(); + sp_repr_css_attr_add_from_string(css, anotation_format.param_getSVGValue()); Inkscape::FontLister *fontlister = Inkscape::FontLister::get_instance(); fontlister->fill_css( css, (Glib::ustring)fontbutton.param_getSVGValue() ); std::stringstream font_size; font_size.imbue(std::locale::classic()); font_size << fontsize << "pt"; - sp_repr_css_set_property (css, "font-size", font_size.str().c_str()); - sp_repr_css_set_property (css, "line-height", "125%"); - sp_repr_css_set_property (css, "letter-spacing", "0"); + + sp_repr_css_set_property (css, "font-size",font_size.str().c_str()); + sp_repr_css_set_property (css, "line-height","125%"); + sp_repr_css_set_property (css, "letter-spacing","0"); sp_repr_css_set_property (css, "word-spacing", "0"); sp_repr_css_set_property (css, "text-align", "center"); sp_repr_css_set_property (css, "text-anchor", "middle"); sp_repr_css_set_property (css, "fill", "#000000"); sp_repr_css_set_property (css, "fill-opacity", "1"); sp_repr_css_set_property (css, "stroke", "none"); + sp_repr_css_attr_add_from_string(css, anotation_format.param_getSVGValue()); Glib::ustring css_str; sp_repr_css_write_string(css,css_str); if (!rtspan) { rtspan = rtext->firstChild(); } - rtspan->setAttribute("style", css_str.c_str()); + rtext->setAttribute("style", css_str.c_str()); sp_repr_css_attr_unref (css); if (!elemref) { rtext->addChild(rtspan, NULL); @@ -387,7 +423,16 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, stroke_w << stroke_width; style = style + (Glib::ustring)"stroke-width:" + (Glib::ustring)stroke_w.str(); } - line->setAttribute("style", style.c_str()); + SPCSSAttr *css = sp_repr_css_attr_new(); + sp_repr_css_attr_add_from_string(css, style.c_str()); + if (main) { + sp_repr_css_attr_add_from_string(css, dimline_format.param_getSVGValue()); + } else { + sp_repr_css_attr_add_from_string(css, helperlines_format.param_getSVGValue()); + } + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + line->setAttribute("style", css_str.c_str()); SPObject * line_obj = NULL; if (!elemref) { line_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(line)); @@ -490,6 +535,12 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) if (line_group_05) { arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.25 / doc_scale, "mm", display_unit.c_str()); } + SPCSSAttr *css = sp_repr_css_attr_new(); + sp_repr_css_attr_add_from_string(css, dimline_format.param_getSVGValue()); + gchar const * width_line = sp_repr_css_property(css,"stroke-width","-1"); + if (width_line != "-1") { + arrow_gap = 8 * atof(width_line); + } if (flip_side) { arrow_gap *= -1; } @@ -555,13 +606,23 @@ Gtk::Widget *LPEMeasureLine::newWidget() std::vector::iterator it = param_vector.begin(); Gtk::HBox * button1 = Gtk::manage(new Gtk::HBox(true,0)); + Gtk::VBox * vbox_expander = Gtk::manage( new Gtk::VBox(Effect::newWidget()) ); + vbox_expander->set_border_width(0); + vbox_expander->set_spacing(2); while (it != param_vector.end()) { if ((*it)->widget_is_visible) { Parameter *param = *it; Gtk::Widget *widg = dynamic_cast(param->param_newWidget()); Glib::ustring *tip = param->param_getTooltip(); if (widg) { - vbox->pack_start(*widg, true, true, 2); + if (param->param_key != "dimline_format" && + param->param_key != "helperlines_format" && + param->param_key != "arrows_format" && + param->param_key != "anotation_format") { + vbox->pack_start(*widg, true, true, 2); + } else { + vbox_expander->pack_start(*widg, true, true, 2); + } if (tip) { widg->set_tooltip_text(*tip); } else { @@ -576,10 +637,26 @@ Gtk::Widget *LPEMeasureLine::newWidget() Gtk::Button *save_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Save '*' as default")))); save_default->signal_clicked().connect(sigc::mem_fun(*this, &LPEMeasureLine::saveDefault)); button1->pack_start(*save_default, true, true, 2); + expander = Gtk::manage(new Gtk::Expander(Glib::ustring(_("Show DIM CSS style override")))); + expander->add(*vbox_expander); + expander->set_expanded(expanded); + expander->property_expanded().signal_changed().connect(sigc::mem_fun(*this, &LPEMeasureLine::onExpanderChanged) ); + vbox->pack_start(*expander, true, true, 2); vbox->pack_start(*button1, true, true, 2); return dynamic_cast(vbox); } +void +LPEMeasureLine::onExpanderChanged() +{ + expanded = expander->get_expanded(); + if(expanded) { + expander->set_label (Glib::ustring(_("Hide DIM CSS style override"))); + } else { + expander->set_label (Glib::ustring(_("Show DIM CSS style override"))); + } +} + Geom::PathVector LPEMeasureLine::doEffect_path(Geom::PathVector const &path_in) { @@ -599,6 +676,10 @@ LPEMeasureLine::saveDefault() prefs->setDouble("/live_effects/measure-line/helpline_overlap", helpline_overlap); prefs->setString("/live_effects/measure-line/unit", (Glib::ustring)unit.get_abbreviation()); prefs->setString("/live_effects/measure-line/format", (Glib::ustring)format.param_getSVGValue()); + prefs->setString("/live_effects/measure-line/dimline_format", (Glib::ustring)dimline_format.param_getSVGValue()); + prefs->setString("/live_effects/measure-line/helperlines_format", (Glib::ustring)helperlines_format.param_getSVGValue()); + prefs->setString("/live_effects/measure-line/anotation_format", (Glib::ustring)anotation_format.param_getSVGValue()); + prefs->setString("/live_effects/measure-line/arrows_format", (Glib::ustring)arrows_format.param_getSVGValue()); prefs->setBool("/live_effects/measure-line/flip_side", flip_side); prefs->setBool("/live_effects/measure-line/scale_insensitive", scale_insensitive); prefs->setBool("/live_effects/measure-line/local_locale", local_locale); diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 581bbb7e4..7e9bfabc7 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -43,20 +43,21 @@ public: virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); void createLine(Geom::Point start,Geom::Point end,Glib::ustring id, bool main, bool remove); void createTextLabel(Geom::Point pos, double length, Geom::Coord angle, double fontsize, bool remove); + void onExpanderChanged(); void createArrowMarker(Glib::ustring mode); void saveDefault(); virtual Gtk::Widget *newWidget(); private: + UnitParam unit; FontButtonParam fontbutton; EnumParam orientation; ScalarParam curve_linked; - ScalarParam scale; ScalarParam precision; ScalarParam position; ScalarParam text_distance; ScalarParam helpline_distance; ScalarParam helpline_overlap; - UnitParam unit; + ScalarParam scale; TextParam format; BoolParam arrows_outside; BoolParam flip_side; @@ -64,7 +65,13 @@ private: BoolParam local_locale; BoolParam line_group_05; BoolParam rotate_anotation; + TextParam dimline_format; + TextParam helperlines_format; + TextParam anotation_format; + TextParam arrows_format; Glib::ustring display_unit; + bool expanded; + Gtk::Expander * expander; double doc_scale; /* Geom::Affine affine_over;*/ LPEMeasureLine(const LPEMeasureLine &); -- cgit v1.2.3 From fcfd11a606e3951121e2ff1cee46c60ce8d02c9b Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 1 Aug 2016 16:50:33 +0200 Subject: Hide canvas text from some text input (bzr r15017.1.24) --- src/live_effects/lpe-measure-line.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 1755f0232..b84169480 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -123,6 +123,10 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : line_group_05.param_update_default(prefs->getBool("/live_effects/measure-line/line_group_05")); rotate_anotation.param_update_default(prefs->getBool("/live_effects/measure-line/rotate_anotation")); format.param_hide_canvas_text(); + dimline_format.param_hide_canvas_text(); + helperlines_format.param_hide_canvas_text(); + anotation_format.param_hide_canvas_text(); + arrows_format.param_hide_canvas_text(); precision.param_set_range(0, 100); precision.param_set_increments(1, 1); precision.param_set_digits(0); -- cgit v1.2.3 From b7556c8456244e9cc884f721d8a728c1377d565e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 1 Aug 2016 18:11:45 +0200 Subject: Noumerous bug fixes, font size, stroke with arroow position, and text input response (bzr r15017.1.25) --- src/live_effects/lpe-measure-line.cpp | 11 +++++++---- src/ui/widget/registered-widget.cpp | 1 - 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index b84169480..80d8cb645 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -518,7 +518,7 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } //We get the font size to offset the text to the middle Pango::FontDescription fontdesc((Glib::ustring)fontbutton.param_getSVGValue()); - double fontsize = fontdesc.get_size()/Pango::SCALE; + double fontsize = fontdesc.get_size()/(double)Pango::SCALE; fontsize *= desktop->doc()->getRoot()->c2p.inverse().expansionX(); Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); if (angle_cross < 0) angle_cross += 2*M_PI; @@ -541,13 +541,16 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } SPCSSAttr *css = sp_repr_css_attr_new(); sp_repr_css_attr_add_from_string(css, dimline_format.param_getSVGValue()); - gchar const * width_line = sp_repr_css_property(css,"stroke-width","-1"); - if (width_line != "-1") { - arrow_gap = 8 * atof(width_line); + std::setlocale(LC_NUMERIC, std::locale::classic().name().c_str()); + double width_line = atof(sp_repr_css_property(css,"stroke-width","-1")); + std::setlocale(LC_NUMERIC, std::locale("").name().c_str()); + if (width_line > -0.0001) { + arrow_gap = 8 * Inkscape::Util::Quantity::convert(width_line/ doc_scale, "mm", display_unit.c_str()); } if (flip_side) { arrow_gap *= -1; } + std::cout << arrow_gap << "arrow_gap\n"; angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); if (angle_cross < 0) angle_cross += 2*M_PI; hstart = hstart - Point::polar(angle_cross, position); diff --git a/src/ui/widget/registered-widget.cpp b/src/ui/widget/registered-widget.cpp index 8b8bdc8e4..dc2e4e14a 100644 --- a/src/ui/widget/registered-widget.cpp +++ b/src/ui/widget/registered-widget.cpp @@ -351,7 +351,6 @@ RegisteredText::on_activate() Inkscape::SVGOStringStream os; os << str; write_to_xml(os.str().c_str()); - setText(os.str().c_str()); set_sensitive(true); _wr->setUpdating (false); } -- cgit v1.2.3 From 149d77a628b55077399365b420c27e7edc36d6ec Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 1 Aug 2016 18:17:30 +0200 Subject: Remove a helper cout (bzr r15017.1.26) --- src/live_effects/lpe-measure-line.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 80d8cb645..c78475fe8 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -550,7 +550,6 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) if (flip_side) { arrow_gap *= -1; } - std::cout << arrow_gap << "arrow_gap\n"; angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); if (angle_cross < 0) angle_cross += 2*M_PI; hstart = hstart - Point::polar(angle_cross, position); -- cgit v1.2.3 From 2bf9d069f2861ed7dce253a04c2df21a7e387b29 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 1 Aug 2016 18:27:21 +0200 Subject: Fix to hidde all elements when hide the effect (bzr r15017.1.27) --- src/live_effects/lpe-measure-line.cpp | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index c78475fe8..792b0a512 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -179,6 +179,45 @@ LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) rtext->setAttribute("style", NULL); } } + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *rtext = NULL; + if (elemref = SVGElemRef->getObject()) { + rtext = elemref->getRepr(); + if (!this->isVisible()) { + rtext->setAttribute("style", "display:none"); + } else { + rtext->setAttribute("style", NULL); + } + } + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *rtext = NULL; + if (elemref = SVGElemRef->getObject()) { + rtext = elemref->getRepr(); + if (!this->isVisible()) { + rtext->setAttribute("style", "display:none"); + } else { + rtext->setAttribute("style", NULL); + } + } + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"infoline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *rtext = NULL; + if (elemref = SVGElemRef->getObject()) { + rtext = elemref->getRepr(); + if (!this->isVisible()) { + rtext->setAttribute("style", "display:none"); + } else { + rtext->setAttribute("style", NULL); + } + } } } -- cgit v1.2.3 From e4f398171b8da1b990125dfc44277c886212702c Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 1 Aug 2016 18:34:14 +0200 Subject: Fixed compiling bug (bzr r15017.1.28) --- src/live_effects/lpe-measure-line.cpp | 53 +++++++++++++++++------------------ 1 file changed, 25 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 792b0a512..5e638c4e4 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -170,52 +170,49 @@ LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); SVGElemRef->attach(SVGElem_uri); SPObject *elemref = NULL; - Inkscape::XML::Node *rtext = NULL; + Inkscape::XML::Node *node = NULL; if (elemref = SVGElemRef->getObject()) { - rtext = elemref->getRepr(); + node = elemref->getRepr(); if (!this->isVisible()) { - rtext->setAttribute("style", "display:none"); + node->setAttribute("style", "display:none"); } else { - rtext->setAttribute("style", NULL); + node->setAttribute("style", NULL); } } - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - Inkscape::XML::Node *rtext = NULL; + Inkscape::URI SVGElem_uri2(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + SVGElemRef->attach(SVGElem_uri2); + elemref = NULL; + node = NULL; if (elemref = SVGElemRef->getObject()) { - rtext = elemref->getRepr(); + node = elemref->getRepr(); if (!this->isVisible()) { - rtext->setAttribute("style", "display:none"); + node->setAttribute("style", "display:none"); } else { - rtext->setAttribute("style", NULL); + node->setAttribute("style", NULL); } } - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - Inkscape::XML::Node *rtext = NULL; + Inkscape::URI SVGElem_uri3(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + SVGElemRef->attach(SVGElem_uri3); + elemref = NULL; + node = NULL; if (elemref = SVGElemRef->getObject()) { - rtext = elemref->getRepr(); + node = elemref->getRepr(); if (!this->isVisible()) { - rtext->setAttribute("style", "display:none"); + node->setAttribute("style", "display:none"); } else { - rtext->setAttribute("style", NULL); + node->setAttribute("style", NULL); } } - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"infoline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - Inkscape::XML::Node *rtext = NULL; + Inkscape::URI SVGElem_uri4(((Glib::ustring)"#" + (Glib::ustring)"infoline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + SVGElemRef->attach(SVGElem_uri4); + elemref = NULL; + node = NULL; if (elemref = SVGElemRef->getObject()) { - rtext = elemref->getRepr(); + node = elemref->getRepr(); if (!this->isVisible()) { - rtext->setAttribute("style", "display:none"); + node->setAttribute("style", "display:none"); } else { - rtext->setAttribute("style", NULL); + node->setAttribute("style", NULL); } } } -- cgit v1.2.3 From dd30b0318f3f943bab0613d8284cf8c8ad2a089a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 1 Aug 2016 18:58:17 +0200 Subject: Attem to fix the locale error (bzr r15017.1.29) --- src/live_effects/lpe-measure-line.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 5e638c4e4..fb4530abd 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -29,6 +29,7 @@ #include "sp-path.h" #include "desktop.h" #include "document.h" +#include #include // TODO due to internal breakage in glibmm headers, this must be last: -- cgit v1.2.3 From 390ac12b6a0e6bbc89e34125692d60c44546e94a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 1 Aug 2016 19:15:46 +0200 Subject: Fix set locale to some compilers folowing su_v help (bzr r15017.1.30) --- src/live_effects/lpe-measure-line.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index fb4530abd..e9e2183e7 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -29,7 +29,6 @@ #include "sp-path.h" #include "desktop.h" #include "document.h" -#include #include // TODO due to internal breakage in glibmm headers, this must be last: @@ -578,9 +577,9 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } SPCSSAttr *css = sp_repr_css_attr_new(); sp_repr_css_attr_add_from_string(css, dimline_format.param_getSVGValue()); - std::setlocale(LC_NUMERIC, std::locale::classic().name().c_str()); + setlocale(LC_NUMERIC, std::locale::classic().name().c_str()); double width_line = atof(sp_repr_css_property(css,"stroke-width","-1")); - std::setlocale(LC_NUMERIC, std::locale("").name().c_str()); + setlocale(LC_NUMERIC, std::locale("").name().c_str()); if (width_line > -0.0001) { arrow_gap = 8 * Inkscape::Util::Quantity::convert(width_line/ doc_scale, "mm", display_unit.c_str()); } -- cgit v1.2.3 From 3b643ec9eff097b88dc4658a9652e67734f3d803 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 1 Aug 2016 19:36:57 +0200 Subject: Credits improvements (bzr r15017.1.31) --- src/live_effects/lpe-measure-line.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index e9e2183e7..ddce17cdf 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -3,6 +3,7 @@ * Jabiertxo Arraiza Cenoz * Some code and ideas migrated from dimensioning.py by * Johannes B. Rutzmoser, johannes.rutzmoser (at) googlemail (dot) com + * https://github.com/Rutzmoser/inkscape_dimensioning * Copyright (C) 2014 Author(s) * Released under GNU GPL, read the file 'COPYING' for more information -- cgit v1.2.3 From 7275e687fcaee5608b7e53481b73cb0b3d254dbe Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 2 Aug 2016 11:19:13 +0200 Subject: Add split DIN line if anottation over (bzr r15017.1.32) --- src/live_effects/lpe-measure-line.cpp | 112 ++++++++++++++++++++++------------ src/live_effects/lpe-measure-line.h | 9 ++- 2 files changed, 79 insertions(+), 42 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index ddce17cdf..393961a13 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -54,7 +54,8 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : curve_linked(_("Curve on origin"), _("Curve on origin, set 0 to start/end"), "curve_linked", &wr, this, 1), precision(_("Precision*"), _("Precision"), "precision", &wr, this, 2), position(_("Positon*"), _("Positon"), "position", &wr, this, 5), - text_distance(_("Text distance*"), _("Text distance"), "text_distance", &wr, this, 12), + text_top_bottom(_("Text top/bottom*"), _("Text top/bottom"), "text_top_bottom", &wr, this, 0), + text_right_left(_("Text right/left*"), _("Text right/left"), "text_right_left", &wr, this, 0), helpline_distance(_("Helpline distance*"), _("Helpline distance"), "helpline_distance", &wr, this, 0.0), helpline_overlap(_("Helpline overlap*"), _("Helpline overlap"), "helpline_overlap", &wr, this, 2.0), scale(_("Scale*"), _("Scaling factor"), "scale", &wr, this, 1.0), @@ -65,6 +66,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : local_locale(_("Local Number Format*"), _("Local number format"), "local_locale", &wr, this, true), line_group_05(_("Line Group 0.5*"), _("Line Group 0.5, from 0.7"), "line_group_05", &wr, this, true), rotate_anotation(_("Rotate Anotation*"), _("Rotate Anotation"), "rotate_anotation", &wr, this, true), + hide_back(_("Hide if label over*"), _("Hide DIN line if label over"), "hide_back", &wr, this, true), dimline_format(_("CSS DIN line*"), _("Override CSS to DIN line, return to save, empty to reset to DIM"), "dimline_format", &wr, this,""), helperlines_format(_("CSS helpers*"), _("Override CSS to helper lines, return to save, empty to reset to DIM"), "helperlines_format", &wr, this,""), anotation_format(_("CSS anotation*"), _("Override CSS to anotation text, return to save, empty to reset to DIM"), "anotation_format", &wr, this,""), @@ -77,7 +79,8 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : registerParameter(&curve_linked); registerParameter(&precision); registerParameter(&position); - registerParameter(&text_distance); + registerParameter(&text_top_bottom); + registerParameter(&text_right_left); registerParameter(&helpline_distance); registerParameter(&helpline_overlap); registerParameter(&scale); @@ -88,6 +91,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : registerParameter(&local_locale); registerParameter(&line_group_05); registerParameter(&rotate_anotation); + registerParameter(&hide_back); registerParameter(&dimline_format); registerParameter(&helperlines_format); registerParameter(&anotation_format); @@ -101,7 +105,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : scale.param_update_default(prefs->getDouble("/live_effects/measure-line/scale", 1.0)); precision.param_update_default(prefs->getInt("/live_effects/measure-line/precision", 2)); position.param_update_default(prefs->getDouble("/live_effects/measure-line/position", 10.0)); - text_distance.param_update_default(prefs->getDouble("/live_effects/measure-line/text_distance", 5.0)); + text_top_bottom.param_update_default(prefs->getDouble("/live_effects/measure-line/text_top_bottom", 5.0)); helpline_distance.param_update_default(prefs->getDouble("/live_effects/measure-line/helpline_distance", 0.0)); helpline_overlap.param_update_default(prefs->getDouble("/live_effects/measure-line/helpline_overlap", 0.0)); Glib::ustring unit_value = prefs->getString("/live_effects/measure-line/unit"); @@ -123,6 +127,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : local_locale.param_update_default(prefs->getBool("/live_effects/measure-line/local_locale")); line_group_05.param_update_default(prefs->getBool("/live_effects/measure-line/line_group_05")); rotate_anotation.param_update_default(prefs->getBool("/live_effects/measure-line/rotate_anotation")); + hide_back.param_update_default(prefs->getBool("/live_effects/measure-line/hide_back")); format.param_hide_canvas_text(); dimline_format.param_hide_canvas_text(); helperlines_format.param_hide_canvas_text(); @@ -140,9 +145,12 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : position.param_set_range(-999999.0, 999999.0); position.param_set_increments(1, 1); position.param_set_digits(2); - text_distance.param_set_range(-999999.0, 999999.0); - text_distance.param_set_increments(1, 1); - text_distance.param_set_digits(2); + text_top_bottom.param_set_range(-999999.0, 999999.0); + text_top_bottom.param_set_increments(1, 1); + text_top_bottom.param_set_digits(2); + text_right_left.param_set_range(-999999.0, 999999.0); + text_right_left.param_set_increments(1, 1); + text_right_left.param_set_digits(2); helpline_distance.param_set_range(-999999.0, 999999.0); helpline_distance.param_set_increments(1, 1); helpline_distance.param_set_digits(2); @@ -182,8 +190,6 @@ LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) } Inkscape::URI SVGElem_uri2(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); SVGElemRef->attach(SVGElem_uri2); - elemref = NULL; - node = NULL; if (elemref = SVGElemRef->getObject()) { node = elemref->getRepr(); if (!this->isVisible()) { @@ -194,8 +200,6 @@ LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) } Inkscape::URI SVGElem_uri3(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); SVGElemRef->attach(SVGElem_uri3); - elemref = NULL; - node = NULL; if (elemref = SVGElemRef->getObject()) { node = elemref->getRepr(); if (!this->isVisible()) { @@ -206,8 +210,6 @@ LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) } Inkscape::URI SVGElem_uri4(((Glib::ustring)"#" + (Glib::ustring)"infoline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); SVGElemRef->attach(SVGElem_uri4); - elemref = NULL; - node = NULL; if (elemref = SVGElemRef->getObject()) { node = elemref->getRepr(); if (!this->isVisible()) { @@ -258,7 +260,7 @@ LPEMeasureLine::createArrowMarker(Glib::ustring mode) arrow_path->setAttribute("style", css_str.c_str()); arrow->addChild(arrow_path, NULL); Inkscape::GC::release(arrow_path); - SPObject * arrow_obj = SP_OBJECT(desktop->getDocument()->getDefs()->appendChildRepr(arrow)); + elemref = SP_OBJECT(desktop->getDocument()->getDefs()->appendChildRepr(arrow)); Inkscape::GC::release(arrow); } else { Inkscape::XML::Node *arrow= elemref->getRepr(); @@ -279,7 +281,7 @@ LPEMeasureLine::createArrowMarker(Glib::ustring mode) } void -LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angle, double fontsize, bool remove) +LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angle, bool remove) { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); @@ -324,16 +326,16 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl rtspan->setAttribute("sodipodi:role", "line"); } gchar * transform; - if (rotate_anotation) { - Geom::Affine affine = Geom::Affine(Geom::Translate(pos).inverse()); - angle = std::fmod(angle, 2*M_PI); + Geom::Affine affine = Geom::Affine(Geom::Translate(pos).inverse()); + angle = std::fmod(angle, 2*M_PI); + if (angle < 0) angle += 2*M_PI; + if (angle >= rad_from_deg(90) && angle < rad_from_deg(270)) { + angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); if (angle < 0) angle += 2*M_PI; - if (angle >= rad_from_deg(90) && angle < rad_from_deg(270)) { - angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); - if (angle < 0) angle += 2*M_PI; - } - affine *= Geom::Rotate(angle); - affine *= Geom::Translate(pos); + } + affine *= Geom::Rotate(angle); + affine *= Geom::Translate(pos); + if (rotate_anotation) { transform = sp_svg_transform_write(affine); } else { transform = NULL; @@ -363,6 +365,7 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl rtspan = rtext->firstChild(); } rtext->setAttribute("style", css_str.c_str()); + rtspan->setAttribute("style", NULL); sp_repr_css_attr_unref (css); if (!elemref) { rtext->addChild(rtspan, NULL); @@ -396,11 +399,21 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl rstring = rtspan->firstChild(); rstring->setContent(label_value.c_str()); } - SPObject * text_obj = NULL; if (!elemref) { - text_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(rtext)); + elemref = SP_OBJECT(desktop->currentLayer()->appendChildRepr(rtext)); Inkscape::GC::release(rtext); } + Inkscape::XML::Node *tmp_node = rtext->duplicate(xml_doc); + affine = Geom::Affine(Geom::Scale(1.1)); + tmp_node->setAttribute("transform", sp_svg_transform_write(affine)); + SPObject * tmp_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(tmp_node)); + Inkscape::GC::release(tmp_node); + tmp_obj->updateRepr(); + Geom::OptRect bounds = SP_ITEM(tmp_obj)->bounds(SPItem::GEOMETRIC_BBOX); + if (bounds) { + anotation_width = bounds->width(); + } + tmp_obj->deleteObject(); } } @@ -420,11 +433,33 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, start = start + Point::polar(angle, helpline_distance ); end = end + Point::polar(angle, helpline_overlap ); } - Geom::Path line_path; - line_path.start(start); - line_path.appendNew(end); Geom::PathVector line_pathv; - line_pathv.push_back(line_path); + if (main && std::abs(text_top_bottom) < fontsize/1.5 && hide_back){ + Geom::Path line_path; + double k = 0; + if (flip_side) { + k = (Geom::distance(start,end)/2.0) + arrow_gap - (anotation_width/2.0); + } else { + k = (Geom::distance(start,end)/2.0) - arrow_gap - (anotation_width/2.0); + } + if (Geom::distance(start,end) < anotation_width){ + return; + } + Geom::Ray ray(end, start); + Geom::Coord angle = ray.angle(); + line_path.start(start); + line_path.appendNew(start - Point::polar(angle, k)); + line_pathv.push_back(line_path); + line_path.clear(); + line_path.start(end + Point::polar(angle, k)); + line_path.appendNew(end); + line_pathv.push_back(line_path); + } else { + Geom::Path line_path; + line_path.start(start); + line_path.appendNew(end); + line_pathv.push_back(line_path); + } gchar * line_str = sp_svg_write_path( line_pathv ); line_pathv.clear(); if (elemref = SVGElemRef->getObject()) { @@ -474,9 +509,8 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, Glib::ustring css_str; sp_repr_css_write_string(css,css_str); line->setAttribute("style", css_str.c_str()); - SPObject * line_obj = NULL; if (!elemref) { - line_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(line)); + elemref = SP_OBJECT(desktop->currentLayer()->appendChildRepr(line)); Inkscape::GC::release(line); } } @@ -555,24 +589,24 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } //We get the font size to offset the text to the middle Pango::FontDescription fontdesc((Glib::ustring)fontbutton.param_getSVGValue()); - double fontsize = fontdesc.get_size()/(double)Pango::SCALE; + fontsize = fontdesc.get_size()/(double)Pango::SCALE; fontsize *= desktop->doc()->getRoot()->c2p.inverse().expansionX(); Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); if (angle_cross < 0) angle_cross += 2*M_PI; angle = std::fmod(angle, 2*M_PI); if (angle < 0) angle += 2*M_PI; if (angle >= rad_from_deg(90) && angle < rad_from_deg(270)) { - pos = pos - Point::polar(angle_cross, (position - text_distance) + fontsize/2.0); + pos = pos - Point::polar(angle_cross, (position - text_top_bottom) + fontsize/2.5); } else { - pos = pos - Point::polar(angle_cross, (position + text_distance) - fontsize/2.0); + pos = pos - Point::polar(angle_cross, (position + text_top_bottom) - fontsize/2.5); } if (!scale_insensitive) { Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); length *= (affinetransform.expansionX() + affinetransform.expansionY()) / 2.0; } - createTextLabel(pos, length, angle, fontsize, remove); + createTextLabel(pos, length, angle, remove); //LINE - double arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.35 / doc_scale, "mm", display_unit.c_str()); + arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.35 / doc_scale, "mm", display_unit.c_str()); if (line_group_05) { arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.25 / doc_scale, "mm", display_unit.c_str()); } @@ -618,19 +652,16 @@ void LPEMeasureLine::doOnRemove (SPLPEItem const* lpeitem) } Inkscape::URI SVGElem_uri2(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); SVGElemRef->attach(SVGElem_uri2); - elemref = NULL; if (elemref = SVGElemRef->getObject()) { elemref->deleteObject(); } Inkscape::URI SVGElem_uri3(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); SVGElemRef->attach(SVGElem_uri3); - elemref = NULL; if (elemref = SVGElemRef->getObject()) { elemref->deleteObject(); } Inkscape::URI SVGElem_uri4(((Glib::ustring)"#" + (Glib::ustring)"infoline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); SVGElemRef->attach(SVGElem_uri4); - elemref = NULL; if (elemref = SVGElemRef->getObject()) { elemref->deleteObject(); } @@ -714,7 +745,7 @@ LPEMeasureLine::saveDefault() prefs->setDouble("/live_effects/measure-line/scale", scale); prefs->setInt("/live_effects/measure-line/precision", precision); prefs->setDouble("/live_effects/measure-line/position", position); - prefs->setDouble("/live_effects/measure-line/text_distance", text_distance); + prefs->setDouble("/live_effects/measure-line/text_top_bottom", text_top_bottom); prefs->setDouble("/live_effects/measure-line/helpline_distance", helpline_distance); prefs->setDouble("/live_effects/measure-line/helpline_overlap", helpline_overlap); prefs->setString("/live_effects/measure-line/unit", (Glib::ustring)unit.get_abbreviation()); @@ -728,6 +759,7 @@ LPEMeasureLine::saveDefault() prefs->setBool("/live_effects/measure-line/local_locale", local_locale); prefs->setBool("/live_effects/measure-line/line_group_05", line_group_05); prefs->setBool("/live_effects/measure-line/rotate_anotation", rotate_anotation); + prefs->setBool("/live_effects/measure-line/hide_back", hide_back); } }; //namespace LivePathEffect diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 7e9bfabc7..7819a94d7 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -42,7 +42,7 @@ public: virtual void doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/); virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); void createLine(Geom::Point start,Geom::Point end,Glib::ustring id, bool main, bool remove); - void createTextLabel(Geom::Point pos, double length, Geom::Coord angle, double fontsize, bool remove); + void createTextLabel(Geom::Point pos, double length, Geom::Coord angle, bool remove); void onExpanderChanged(); void createArrowMarker(Glib::ustring mode); void saveDefault(); @@ -54,7 +54,8 @@ private: ScalarParam curve_linked; ScalarParam precision; ScalarParam position; - ScalarParam text_distance; + ScalarParam text_top_bottom; + ScalarParam text_right_left; ScalarParam helpline_distance; ScalarParam helpline_overlap; ScalarParam scale; @@ -65,6 +66,7 @@ private: BoolParam local_locale; BoolParam line_group_05; BoolParam rotate_anotation; + BoolParam hide_back; TextParam dimline_format; TextParam helperlines_format; TextParam anotation_format; @@ -73,6 +75,9 @@ private: bool expanded; Gtk::Expander * expander; double doc_scale; + double fontsize; + double anotation_width; + double arrow_gap; /* Geom::Affine affine_over;*/ LPEMeasureLine(const LPEMeasureLine &); LPEMeasureLine &operator=(const LPEMeasureLine &); -- cgit v1.2.3 From af36c60d5f160f314640b6402769779e18d9b2ef Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 2 Aug 2016 13:41:58 +0200 Subject: Add houz improvement text right/left with line out (bzr r15017.1.33) --- src/live_effects/lpe-measure-line.cpp | 62 ++++++++++++++++++++++++++++++----- src/live_effects/lpe-measure-line.h | 2 +- 2 files changed, 54 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 393961a13..04085015c 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -218,6 +218,16 @@ LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) node->setAttribute("style", NULL); } } + Inkscape::URI SVGElem_uri5(((Glib::ustring)"#" + (Glib::ustring)"downline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + SVGElemRef->attach(SVGElem_uri5); + if (elemref = SVGElemRef->getObject()) { + node = elemref->getRepr(); + if (!this->isVisible()) { + node->setAttribute("style", "display:none"); + } else { + node->setAttribute("style", NULL); + } + } } } @@ -305,6 +315,7 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl SVGElemRef->attach(SVGElem_uri); SPObject *elemref = NULL; Inkscape::XML::Node *rtspan = NULL; + pos = pos - Point::polar(angle, text_right_left); if (elemref = SVGElemRef->getObject()) { if (remove) { elemref->deleteObject(); @@ -404,7 +415,7 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl Inkscape::GC::release(rtext); } Inkscape::XML::Node *tmp_node = rtext->duplicate(xml_doc); - affine = Geom::Affine(Geom::Scale(1.1)); + affine = Geom::Affine(Geom::Scale(1.4)); tmp_node->setAttribute("transform", sp_svg_transform_write(affine)); SPObject * tmp_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(tmp_node)); Inkscape::GC::release(tmp_node); @@ -418,7 +429,7 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl } void -LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, bool main, bool remove) +LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, bool main, bool overflow, bool remove, bool arrows) { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); @@ -434,7 +445,7 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, end = end + Point::polar(angle, helpline_overlap ); } Geom::PathVector line_pathv; - if (main && std::abs(text_top_bottom) < fontsize/1.5 && hide_back){ + if (main && std::abs(text_top_bottom) < fontsize/1.5 && hide_back && !overflow){ Geom::Path line_path; double k = 0; if (flip_side) { @@ -478,7 +489,9 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, line->setAttribute("d" , line_str); } Glib::ustring style = (Glib::ustring)"stroke:#000000;fill:none;"; - if (main) { + if (overflow && !arrows) { + line->setAttribute("inkscape:label", "downline"); + } else if (main) { line->setAttribute("inkscape:label", "dinline"); if (arrows_outside) { style = style + (Glib::ustring)"marker-start:url(#ArrowDINout-start);marker-end:url(#ArrowDINout-end);"; @@ -605,6 +618,34 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) length *= (affinetransform.expansionX() + affinetransform.expansionY()) / 2.0; } createTextLabel(pos, length, angle, remove); + bool overflow = false; + if ((anotation_width/2) + std::abs(text_right_left) > Geom::distance(start,end)/2.0) { + Geom::Point sstart = end - Point::polar(angle_cross, position); + Geom::Point send = end - Point::polar(angle_cross, position); + if (text_right_left < 0 && flip_side || text_right_left > 0 && !flip_side) { + sstart = start - Point::polar(angle_cross, position); + send = start - Point::polar(angle_cross, position); + } + Geom::Point prog_end = Geom::Point(); + if (std::abs(text_top_bottom) < fontsize/1.5 && hide_back) { + if (text_right_left > 0 ) { + prog_end = sstart - Point::polar(angle, std::abs(text_right_left) - (anotation_width/1.9) - (Geom::distance(start,end)/2.0)); + } else { + prog_end = sstart + Point::polar(angle, std::abs(text_right_left) - (anotation_width/1.9) - (Geom::distance(start,end)/2.0)); + } + } else { + if (text_right_left > 0 ) { + prog_end = sstart - Point::polar(angle,(anotation_width/2) + std::abs(text_right_left) - (Geom::distance(start,end)/2.0)); + } else { + prog_end = sstart + Point::polar(angle,(anotation_width/2) + std::abs(text_right_left) - (Geom::distance(start,end)/2.0)); + } + } + overflow = true; + createLine(sstart, prog_end, (Glib::ustring)"downline-" + (Glib::ustring)this->getRepr()->attribute("id"), true, overflow, false, false); + } else { + //erase it + createLine(Geom::Point(),Geom::Point(), (Glib::ustring)"downline-" + (Glib::ustring)this->getRepr()->attribute("id"), true, overflow, true, false); + } //LINE arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.35 / doc_scale, "mm", display_unit.c_str()); if (line_group_05) { @@ -621,20 +662,18 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) if (flip_side) { arrow_gap *= -1; } - angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); - if (angle_cross < 0) angle_cross += 2*M_PI; hstart = hstart - Point::polar(angle_cross, position); Glib::ustring id = (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id"); - createLine(start, hstart, id, false, remove); + createLine(start, hstart, id, false, false, remove); hend = hend - Point::polar(angle_cross, position); id = (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id"); - createLine(end, hend, id, false, remove); + createLine(end, hend, id, false, false, remove); if (!arrows_outside) { hstart = hstart + Point::polar(angle, arrow_gap); hend = hend - Point::polar(angle, arrow_gap ); } id = (Glib::ustring)"infoline-" + (Glib::ustring)this->getRepr()->attribute("id"); - createLine(hstart, hend, id, true, remove); + createLine(hstart, hend, id, true, overflow, remove, true); } } } @@ -665,6 +704,11 @@ void LPEMeasureLine::doOnRemove (SPLPEItem const* lpeitem) if (elemref = SVGElemRef->getObject()) { elemref->deleteObject(); } + Inkscape::URI SVGElem_uri5(((Glib::ustring)"#" + (Glib::ustring)"downline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + SVGElemRef->attach(SVGElem_uri5); + if (elemref = SVGElemRef->getObject()) { + elemref->deleteObject(); + } } } diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 7819a94d7..f9c925ef3 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -41,7 +41,7 @@ public: virtual void doOnRemove (SPLPEItem const* lpeitem); virtual void doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/); virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); - void createLine(Geom::Point start,Geom::Point end,Glib::ustring id, bool main, bool remove); + void createLine(Geom::Point start,Geom::Point end,Glib::ustring id, bool main, bool overflow, bool remove, bool arrows = false); void createTextLabel(Geom::Point pos, double length, Geom::Coord angle, bool remove); void onExpanderChanged(); void createArrowMarker(Glib::ustring mode); -- cgit v1.2.3 From 6efece51f99980b824b199bbeb6452f03e6736c6 Mon Sep 17 00:00:00 2001 From: Dmitry Zhulanov Date: Tue, 27 Sep 2016 00:23:14 +0700 Subject: add x-verbs support (bzr r15136.1.1) --- src/CMakeLists.txt | 2 + src/main-cmdlineact.cpp | 35 ++++ src/main-cmdlineact.h | 9 +- src/main-cmdlinexact.cpp | 526 +++++++++++++++++++++++++++++++++++++++++++++++ src/main-cmdlinexact.h | 52 +++++ src/main.cpp | 22 ++ 6 files changed, 644 insertions(+), 2 deletions(-) create mode 100644 src/main-cmdlinexact.cpp create mode 100644 src/main-cmdlinexact.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9928f9694..6875eaa38 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -221,6 +221,7 @@ set(inkscape_SRC line-geometry.cpp line-snapper.cpp main-cmdlineact.cpp + main-cmdlinexact.cpp media.cpp message-context.cpp message-stack.cpp @@ -337,6 +338,7 @@ set(inkscape_SRC line-snapper.h macros.h main-cmdlineact.h + main-cmdlinexact.h media.h menus-skeleton.h message-context.h diff --git a/src/main-cmdlineact.cpp b/src/main-cmdlineact.cpp index c1b756ad5..2d0a5cfd6 100644 --- a/src/main-cmdlineact.cpp +++ b/src/main-cmdlineact.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include @@ -22,6 +23,7 @@ namespace Inkscape { std::list CmdLineAction::_list; +bool CmdLineAction::_requestQuit = false; CmdLineAction::CmdLineAction (bool isVerb, gchar const * arg) : _isVerb(isVerb), _arg(NULL) { if (arg != NULL) { @@ -39,10 +41,34 @@ CmdLineAction::~CmdLineAction () { } } +bool +CmdLineAction::isExtended() { + return false; +} + +void +CmdLineAction::doItX (ActionContext const & context) +{ + (void)context; + printf("CmdLineAction::doItX() %s\n", _arg); +} + void CmdLineAction::doIt (ActionContext const & context) { //printf("Doing: %s\n", _arg); if (_isVerb) { + if (isExtended()) { + //printf("Is extended\n"); + + doItX(context); + return; + } + + static std::string quit_verb_name = "FileQuit"; + if (quit_verb_name == _arg) { + _requestQuit = true; + return; + } Inkscape::Verb * verb = Inkscape::Verb::getbyid(_arg); if (verb == NULL) { printf(_("Unable to find verb ID '%s' specified on the command line.\n"), _arg); @@ -69,10 +95,19 @@ CmdLineAction::doIt (ActionContext const & context) { bool CmdLineAction::doList (ActionContext const & context) { bool hasActions = !_list.empty(); + if (!hasActions && _requestQuit) { + sp_file_exit(); + return true; + } + for (std::list::iterator i = _list.begin(); i != _list.end(); ++i) { CmdLineAction * entry = *i; entry->doIt(context); + if (_requestQuit) { + sp_file_exit(); + return true; + } } return hasActions; } diff --git a/src/main-cmdlineact.h b/src/main-cmdlineact.h index b8ec4403b..f50e70e5a 100644 --- a/src/main-cmdlineact.h +++ b/src/main-cmdlineact.h @@ -21,15 +21,20 @@ class ActionContext; class CmdLineAction { bool _isVerb; - char * _arg; - static std::list _list; + static bool _requestQuit; + +protected: + char * _arg; public: CmdLineAction (bool isVerb, char const * arg); virtual ~CmdLineAction (); + virtual bool isExtended(); + virtual void doItX (ActionContext const & context); void doIt (ActionContext const & context); + /** Return true if any actions were performed */ static bool doList (ActionContext const & context); static bool idle (void); diff --git a/src/main-cmdlinexact.cpp b/src/main-cmdlinexact.cpp new file mode 100644 index 000000000..9efbfe8cd --- /dev/null +++ b/src/main-cmdlinexact.cpp @@ -0,0 +1,526 @@ +/* + * Authors: + * Dmitry Zhulanov + * + * Copyright (C) 2016 Authors + * + * Released under GNU GPL v2, read the file 'COPYING' for more information + * + * Format of xverbs.yaml + * + * verbose: yes # only "verbose: yes" enable logging + * run: + * # open document to process + * - xverb-id: XFileOpen, gfx_sources/loading_screen/sandclock_atlas.svg + * - xverb-id: XUndoLabel, fresh_document # set label for UndoToLabel xverb works + * # note: if something wrong with undo labels use verb EditUndo instead of XUndoLabel and UndoToLabel at all + * + * # select element to handle + * - xverb-id: XSelectElement, top_sand + * + * # verbs + * - verb-id: EditInvertInAllLayers + * - verb-id: EditDelete + * - verb-id: FitCanvasToDrawing + * + * # save element to separated svg document + * - xverb-id: XFileSaveAs, output/thegame/linux/data/gfx/loading_screen/top_sand.svg + * + * # also save png preview + * - xverb-id: XFileExportPNG, output/thegame/linux/data/gfx_preview/loading_screen/top_sand.png + * + * # return to the fresh_state of document + * - xverb-id: UndoToLabel, fresh_document + * + * # do any other handling + * + * # inkscape have a lot of useful verbs + * - verb-id: FileQuit + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include "main-cmdlinexact.h" +#include "yaml.h" +#include "extension/system.h" +#include "file.h" +#include +#include "sp-root.h" +#include "document-undo.h" +#include "util/units.h" +#include "sp-namedview.h" +#include "resource-manager.h" +#include "ui/dialog/font-substitution.h" +#include "extension/db.h" +#include "preferences.h" +#include "helper/png-write.h" +#include +#include +#include + +#define DPI_BASE Inkscape::Util::Quantity::convert(1, "in", "px") + +namespace +{ +bool s_verbose = false; + +bool createDirForFilename( const std::string &filename ) +{ + size_t found = filename.find_last_of("/\\"); + std::string output_directory = filename.substr(0,found); + + if( output_directory == filename ) + return true; + + if (g_mkdir_with_parents(output_directory.c_str(), 0755)) + { + printf("Can't create directory %s\n", output_directory.c_str()); + fflush(stdout); + + return false; + } + + return true; +} + +void xFileOpen( const Glib::ustring &uri ) +{ + if (s_verbose) { + printf("open %s\n", uri.c_str()); + fflush(stdout); + } + + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + if (desktop) { + SPDocument *old_document = desktop->getDocument(); + desktop->setWaitingCursor(); + Inkscape::DocumentUndo::clearRedo(old_document); + } + + SPDocument *doc = NULL; + Inkscape::Extension::Extension *key = NULL; + try { + doc = Inkscape::Extension::open(key, uri.c_str()); + } catch (std::exception &e) { + doc = NULL; + std::string exeption_mgs = e.what(); + printf("Error: open %s:%s\n",uri.c_str(), exeption_mgs.c_str() ); + fflush(stdout); + } + + // Set viewBox if it doesn't exist + if (!doc->getRoot()->viewBox_set + && (doc->getRoot()->width.unit != SVGLength::PERCENT) + && (doc->getRoot()->height.unit != SVGLength::PERCENT)) { + doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().value(doc->getDisplayUnit()), doc->getHeight().value(doc->getDisplayUnit()))); + } + + desktop->change_document(doc); + doc->emitResizedSignal(doc->getWidth().value("px"), doc->getHeight().value("px")); + if(desktop) + desktop->clearWaitingCursor(); + + doc->virgin = FALSE; + + // everyone who cares now has a reference, get rid of our`s + doc->doUnref(); + + // resize the window to match the document properties + sp_namedview_window_from_document(desktop); + sp_namedview_update_layers_from_document(desktop); + + if ( INKSCAPE.use_gui() ) { + // Perform a fixup pass for hrefs. + if ( Inkscape::ResourceManager::getManager().fixupBrokenLinks(doc) ) { + Glib::ustring msg = _("Broken links have been changed to point to existing files."); + desktop->showInfoDialog(msg); + } + + // Check for font substitutions + Inkscape::UI::Dialog::FontSubstitution::getInstance().checkFontSubstitutions(doc); + } +} + +void xFileSaveAs( Inkscape::ActionContext const & context, const Glib::ustring &uri ) +{ + SPDocument *doc = context.getDocument(); + if (s_verbose) { + printf("save as %s\n", uri.c_str()); + fflush(stdout); + } + + if( createDirForFilename( uri )) { + Inkscape::Extension::save( + Inkscape::Extension::db.get("org.inkscape.output.svg.inkscape"), + doc, uri.c_str(), false, false, true, Inkscape::Extension::FILE_SAVE_METHOD_SAVE_AS); + if (s_verbose) { + printf("save done: %s\n", uri.c_str() ); + fflush(stdout); + } + } + else + { + printf("can't create dirs for filename %s\n", uri.c_str() ); + fflush(stdout); + } +} + +void xFileExportPNG( Inkscape::ActionContext const & context, const Glib::ustring &uri ) +{ + if (s_verbose) { + printf("export png %s\n", uri.c_str()); + fflush(stdout); + } + + SPDocument *doc = context.getDocument(); + + gdouble dpi = 200.0; + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + dpi = prefs->getDouble("/dialogs/export/defaultxdpi/value", DPI_BASE); + + gdouble width = doc->getWidth().value(doc->getDisplayUnit()); + gdouble height = doc->getHeight().value(doc->getDisplayUnit()); + + gdouble bmwidth = (width) * dpi / DPI_BASE; + gdouble bmheight = (height) * dpi / DPI_BASE; + + int png_width = (int)(0.5 + bmwidth); + int png_height = (int)(0.5 + bmheight); + + SPNamedView *nv = desktop->getNamedView(); + + ExportResult status = sp_export_png_file(doc, uri.c_str(), + Geom::Rect(Geom::Point(0,0), Geom::Point(width, height)), png_width, png_height, dpi, dpi, + nv->pagecolor, 0, 0, TRUE); +} + +void xSelectElement( Inkscape::ActionContext const & context, const Glib::ustring &uri ) +{ + if (context.getDocument() == NULL || context.getSelection() == NULL) { return; } + + if (s_verbose) { + printf("select element: %s\n", uri.c_str()); + fflush(stdout); + } + + SPDocument * doc = context.getDocument(); + SPObject * obj = doc->getObjectById(uri); + + if (obj == NULL) { + printf(_("Unable to find node ID: '%s'\n"), uri.c_str()); + fflush(stdout); + return; + } + + Inkscape::Selection * selection = context.getSelection(); + selection->add(obj); + + if (s_verbose) { + printf("select done %s\n", uri.c_str()); + fflush(stdout); + } +} + +} // end of unnamed namespace + +namespace Inkscape { + +CmdLineXAction::CmdLineXAction (gchar const * arg, xaction_args_values_map_t &values_map): + CmdLineAction(true, arg), _values_map(values_map) { + this->arg = (char *)arg; + return; +} + +bool +CmdLineXAction::isExtended() { + return true; +} + +void +CmdLineXAction::doItX (ActionContext const & context) { + (void)(context); + + if( arg == "XFileSaveAs") + xFileSaveAs( context, _values_map["filename"] ); + else if (arg == "XFileOpen") + xFileOpen( _values_map["filename"] ); + else if (arg == "XFileExportPNG") + xFileExportPNG( context, _values_map["png_filename"] ); + else if (arg == "XSelectElement") + xSelectElement( context, _values_map["element-id"] ); + else + { + printf("unknown xverb: %s", arg.c_str()); + fflush(stdout); + } + + return; +} + +enum parser_state_t{ HANDLING_ROOT, + HANDLING_VERBOSE, // options + HANDLING_RUN, HANDLING_RUN_LIST, HANDLING_RUN_LIST_ENTRY }; // run entries + +struct verb_info_t +{ + bool xverb; + std::vector args; +}; + +typedef std::list verbs_list_t; + +static void tokenize(const std::string& str, std::vector& tokens, const std::string& delimiters = ",") +{ + // Skip delimiters at beginning. + std::string::size_type lastPos = str.find_first_not_of(delimiters, 0); + + // Find first non-delimiter. + std::string::size_type pos = str.find_first_of(delimiters, lastPos); + + while (std::string::npos != pos || std::string::npos != lastPos) { + // Found a token, add it to the vector. + tokens.push_back(str.substr(lastPos, pos - lastPos)); + + // Skip delimiters. + lastPos = str.find_first_not_of(delimiters, pos); + + // Find next non-delimiter. + pos = str.find_first_of(delimiters, lastPos); + } +} + +void +CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) { + FILE *fh = fopen(yaml_filename, "r"); + if(fh == NULL) { + printf("Failed to open file!\n"); + fflush(stdout); + return; + } + + yaml_parser_t parser; + if(!yaml_parser_initialize(&parser)) { + printf("Failed to initialize parser!\n"); + fflush(stdout); + return; + } + + /* Set input file */ + yaml_parser_set_input_file(&parser, fh); + + parser_state_t state = HANDLING_ROOT; + + + bool handling_key = false; + bool handling_value = false; + + std::string key; + verbs_list_t verbs_list; + + // parse + yaml_token_t token; + do { + yaml_parser_scan(&parser, &token); + switch(token.type) + { + // avoid "warning: enumeration value", "-Wswitch" + case YAML_NO_TOKEN: break; + case YAML_STREAM_START_TOKEN: break; + case YAML_STREAM_END_TOKEN: break; + case YAML_VERSION_DIRECTIVE_TOKEN: break; + case YAML_TAG_DIRECTIVE_TOKEN: break; + case YAML_DOCUMENT_START_TOKEN: break; + case YAML_DOCUMENT_END_TOKEN: break; + case YAML_FLOW_SEQUENCE_START_TOKEN: break; + case YAML_FLOW_SEQUENCE_END_TOKEN: break; + case YAML_FLOW_MAPPING_START_TOKEN: break; + case YAML_FLOW_MAPPING_END_TOKEN: break; + case YAML_FLOW_ENTRY_TOKEN: break; + case YAML_ALIAS_TOKEN: break; + case YAML_ANCHOR_TOKEN: break; + case YAML_TAG_TOKEN: break; + + /* Token types (read before actual token) */ + case YAML_KEY_TOKEN: + handling_key = true; + handling_value = false; + break; + case YAML_VALUE_TOKEN: + handling_key = false; + handling_value = true; + break; + + /* Block delimeters */ + case YAML_BLOCK_SEQUENCE_START_TOKEN: + if( state == HANDLING_ROOT ) + { + if( key == "run" ) + state = HANDLING_RUN; + } + break; + case YAML_BLOCK_ENTRY_TOKEN: + if( state == HANDLING_RUN ) + state = HANDLING_RUN_LIST; + else if( state == HANDLING_RUN_LIST ) + state = HANDLING_RUN_LIST_ENTRY; + else if( state == HANDLING_VERBOSE ) + state = HANDLING_ROOT; + break; + case YAML_BLOCK_END_TOKEN: + if( state == HANDLING_RUN_LIST_ENTRY ) + state = HANDLING_RUN_LIST; + else if( state == HANDLING_RUN_LIST ) + state = HANDLING_RUN; + else if( state == HANDLING_VERBOSE ) + state = HANDLING_ROOT; + else if( state == HANDLING_RUN ) + state = HANDLING_ROOT; + break; + + /* Data */ + case YAML_BLOCK_MAPPING_START_TOKEN: + break; + case YAML_SCALAR_TOKEN: + if( handling_key ) + key = (char *)token.data.scalar.value; + else if ( handling_value ) + { + if(state == HANDLING_RUN_LIST) + { + if(key == "xverb-id") + { + verb_info_t verb; + verb.xverb = true; + + std::string values = (char *)token.data.scalar.value; + tokenize(values, verb.args); + for( size_t i = 0; i < verb.args.size(); ++i ) + { + verb.args[i].erase(0, verb.args[i].find_first_not_of(' ')); //prefixing spaces + verb.args[i].erase(verb.args[i].find_last_not_of(' ')+1); //surfixing spaces + } + verbs_list.push_back(verb); + } + else if(key == "verb-id") + { + verb_info_t verb; + verb.xverb = false; + verb.args.push_back((char *)token.data.scalar.value); + verbs_list.push_back(verb); + } + else + { + printf("unknown verb type [%s]\n", key.c_str()); + fflush(stdout); + } + } + else if(state == HANDLING_ROOT) + { + std::string value = (char *)token.data.scalar.value; + if( (key == "verbose") && (value == "yes") ) + s_verbose = true; + } + } + break; + } + } while(token.type != YAML_STREAM_END_TOKEN); + + /* Cleanup */ + yaml_token_delete(&token); + yaml_parser_delete(&parser); + fclose(fh); + + typedef std::map undo_labels_map_t; + undo_labels_map_t undo_labels_map; + int undo_counter = 0; + + verbs_list_t::iterator iter = verbs_list.begin(); + for( ; iter != verbs_list.end(); ++iter ) + { + verb_info_t &verb = *iter; + std::string &verb_word = verb.args[0]; + if( s_verbose ) + printf("handle %s and args count is %d\n", verb_word.c_str(), (int)verb.args.size()); + + if( verb.args.size() == 2 ) + { + xaction_args_values_map_t values_map; + if (verb_word == "XFileSaveAs" || verb_word == "XFileOpen") + { + std::string &filename = verb.args[1]; + values_map["filename"] = filename; + new CmdLineXAction(verb_word.c_str(), values_map); + } + else if (verb_word == "XUndoLabel") + undo_labels_map[verb.args[1]] = undo_counter; + else if (verb_word == "UndoToLabel") + { + undo_labels_map_t::iterator iter = undo_labels_map.find(verb.args[1]); + if(iter != undo_labels_map.end()) + { + int counter = undo_counter - iter->second; + if( counter > 0 ) + { + for(int i = 0; i < counter; ++i) + new CmdLineAction(true, "EditUndo"); + undo_counter -= counter; + } + } + } + else if (verb_word == "XSelectElement") + { + ++undo_counter; + values_map["element-id"] = verb.args[1]; + new CmdLineXAction(verb_word.c_str(), values_map); + } + else if (verb_word == "XFileExportPNG") + { + std::string &png_filename = verb.args[1]; + values_map["png_filename"] = png_filename; + if(createDirForFilename( png_filename )) { + new CmdLineXAction(verb_word.c_str(), values_map); + } + } + } + else if(!verb.xverb) + { + ++undo_counter; + new CmdLineAction(true, verb.args[0].c_str()); + } + + else + { + printf("Unhadled verb %s\n", verb.args[0].c_str()); + fflush(stdout); + } + } + + fflush(stdout); + return; +} + + +} // Inkscape + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/main-cmdlinexact.h b/src/main-cmdlinexact.h new file mode 100644 index 000000000..1ac630e55 --- /dev/null +++ b/src/main-cmdlinexact.h @@ -0,0 +1,52 @@ + +#ifndef __INK_MAIN_CMD_LINE_XACTIONS_H__ +#define __INK_MAIN_CMD_LINE_XACTIONS_H__ + +/** \file + * Extended actions that can be queued at the yaml file + */ + +/* + * Authors: + * Dmitry Zhulanov + * + * Copyright (C) 2016 Authors + * + * Released under GNU GPL v2.x, read the file 'COPYING' for more information + */ + +#include "main-cmdlineact.h" +#include + +namespace Inkscape { + +typedef std::map xaction_args_values_map_t; + +class CmdLineXAction : public CmdLineAction { + std::string arg; + xaction_args_values_map_t _values_map; +public: + CmdLineXAction (gchar const * arg, xaction_args_values_map_t &values_map); + + virtual void doItX (ActionContext const & context); + virtual bool isExtended(); + + static void createActionsFromYAML( gchar const *filename ); +}; + +} // Inkscape + + + +#endif /* __INK_MAIN_CMD_LINE_XACTIONS_H__ */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/main.cpp b/src/main.cpp index 004d96191..d9f11ed8b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -112,6 +112,7 @@ #endif #include "main-cmdlineact.h" +#include "main-cmdlinexact.h" #include "widgets/icon.h" #include @@ -127,6 +128,7 @@ enum { SP_ARG_NOGUI, SP_ARG_GUI, SP_ARG_FILE, + SP_ARG_XVERBS, SP_ARG_PRINT, SP_ARG_EXPORT_PNG, SP_ARG_EXPORT_DPI, @@ -227,6 +229,9 @@ static gchar *sp_export_png_utf8 = NULL; static gchar *sp_export_svg_utf8 = NULL; static gchar *sp_global_printer_utf8 = NULL; +static gchar *sp_xverbs_yaml_utf8 = NULL; +static gchar *sp_xverbs_yaml = NULL; + /** * Reset variables to default values. @@ -301,6 +306,11 @@ struct poptOption options[] = { N_("Open specified document(s) (option string may be excluded)"), N_("FILENAME")}, + {"xverbs", 'B', + POPT_ARG_STRING, &sp_xverbs_yaml, SP_ARG_XVERBS, + N_("xverbs command"), + N_("XVERBS_FILENAME")}, + {"print", 'p', POPT_ARG_STRING, &sp_global_printer, SP_ARG_PRINT, N_("Print document(s) to specified output file (use '| program' for pipe)"), @@ -881,6 +891,7 @@ static int sp_common_main( int argc, char const **argv, GSList **flDest ) fixupSingleFilename( &sp_export_png, &sp_export_png_utf8 ); fixupSingleFilename( &sp_export_svg, &sp_export_svg_utf8 ); fixupSingleFilename( &sp_global_printer, &sp_global_printer_utf8 ); + fixupSingleFilename( &sp_xverbs_yaml, &sp_xverbs_yaml_utf8 ); } else { @@ -890,6 +901,9 @@ static int sp_common_main( int argc, char const **argv, GSList **flDest ) sp_export_svg_utf8 = g_strdup( sp_export_svg ); if ( sp_global_printer ) sp_global_printer_utf8 = g_strdup( sp_global_printer ); + if ( sp_xverbs_yaml ) + sp_xverbs_yaml_utf8 = g_strdup( sp_xverbs_yaml ); + } #ifdef WITH_DBUS @@ -2131,6 +2145,14 @@ sp_process_args(poptContext ctx) } break; } + case SP_ARG_XVERBS: { + gchar const *fn = poptGetOptArg(ctx); + if (fn != NULL) { + sp_xverbs_yaml = g_strdup(fn); + Inkscape::CmdLineXAction::createActionsFromYAML((const char *)sp_xverbs_yaml); + } + break; + } case SP_ARG_VERSION: { printf("Inkscape %s (%s)\n", Inkscape::version_string, __DATE__); exit(0); -- cgit v1.2.3 From 38cd1793fb8ac7983c001834193d41b5b5b4e660 Mon Sep 17 00:00:00 2001 From: Dmitry Zhulanov Date: Tue, 27 Sep 2016 21:17:03 +0700 Subject: update intends and brackets (bzr r15136.1.3) --- src/main-cmdlinexact.cpp | 661 +++++++++++++++++++++++------------------------ 1 file changed, 320 insertions(+), 341 deletions(-) (limited to 'src') diff --git a/src/main-cmdlinexact.cpp b/src/main-cmdlinexact.cpp index 9efbfe8cd..940abfca4 100644 --- a/src/main-cmdlinexact.cpp +++ b/src/main-cmdlinexact.cpp @@ -7,6 +7,7 @@ * Released under GNU GPL v2, read the file 'COPYING' for more information * * Format of xverbs.yaml + * using: $ inkscape -B xverbs.yaml * * verbose: yes # only "verbose: yes" enable logging * run: @@ -80,29 +81,28 @@ bool createDirForFilename( const std::string &filename ) std::string output_directory = filename.substr(0,found); if( output_directory == filename ) - return true; + return true; - if (g_mkdir_with_parents(output_directory.c_str(), 0755)) - { - printf("Can't create directory %s\n", output_directory.c_str()); - fflush(stdout); + if (g_mkdir_with_parents(output_directory.c_str(), 0755)) { + printf("Can't create directory %s\n", output_directory.c_str()); + fflush(stdout); - return false; - } + return false; + } return true; } void xFileOpen( const Glib::ustring &uri ) { - if (s_verbose) { - printf("open %s\n", uri.c_str()); - fflush(stdout); - } + if (s_verbose) { + printf("open %s\n", uri.c_str()); + fflush(stdout); + } SPDesktop *desktop = SP_ACTIVE_DESKTOP; if (desktop) { - SPDocument *old_document = desktop->getDocument(); + SPDocument *old_document = desktop->getDocument(); desktop->setWaitingCursor(); Inkscape::DocumentUndo::clearRedo(old_document); } @@ -114,123 +114,122 @@ void xFileOpen( const Glib::ustring &uri ) } catch (std::exception &e) { doc = NULL; std::string exeption_mgs = e.what(); - printf("Error: open %s:%s\n",uri.c_str(), exeption_mgs.c_str() ); - fflush(stdout); + printf("Error: open %s:%s\n",uri.c_str(), exeption_mgs.c_str() ); + fflush(stdout); } - // Set viewBox if it doesn't exist - if (!doc->getRoot()->viewBox_set - && (doc->getRoot()->width.unit != SVGLength::PERCENT) - && (doc->getRoot()->height.unit != SVGLength::PERCENT)) { - doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().value(doc->getDisplayUnit()), doc->getHeight().value(doc->getDisplayUnit()))); - } - - desktop->change_document(doc); - doc->emitResizedSignal(doc->getWidth().value("px"), doc->getHeight().value("px")); - if(desktop) - desktop->clearWaitingCursor(); - - doc->virgin = FALSE; - - // everyone who cares now has a reference, get rid of our`s - doc->doUnref(); - - // resize the window to match the document properties - sp_namedview_window_from_document(desktop); - sp_namedview_update_layers_from_document(desktop); - - if ( INKSCAPE.use_gui() ) { - // Perform a fixup pass for hrefs. - if ( Inkscape::ResourceManager::getManager().fixupBrokenLinks(doc) ) { - Glib::ustring msg = _("Broken links have been changed to point to existing files."); - desktop->showInfoDialog(msg); - } - - // Check for font substitutions - Inkscape::UI::Dialog::FontSubstitution::getInstance().checkFontSubstitutions(doc); - } + // Set viewBox if it doesn't exist + if (!doc->getRoot()->viewBox_set + && (doc->getRoot()->width.unit != SVGLength::PERCENT) + && (doc->getRoot()->height.unit != SVGLength::PERCENT)) { + doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().value(doc->getDisplayUnit()), doc->getHeight().value(doc->getDisplayUnit()))); + } + + desktop->change_document(doc); + doc->emitResizedSignal(doc->getWidth().value("px"), doc->getHeight().value("px")); + if(desktop) + desktop->clearWaitingCursor(); + + doc->virgin = FALSE; + + // everyone who cares now has a reference, get rid of our`s + doc->doUnref(); + + // resize the window to match the document properties + sp_namedview_window_from_document(desktop); + sp_namedview_update_layers_from_document(desktop); + + if ( INKSCAPE.use_gui() ) { + // Perform a fixup pass for hrefs. + if ( Inkscape::ResourceManager::getManager().fixupBrokenLinks(doc) ) { + Glib::ustring msg = _("Broken links have been changed to point to existing files."); + desktop->showInfoDialog(msg); + } + + // Check for font substitutions + Inkscape::UI::Dialog::FontSubstitution::getInstance().checkFontSubstitutions(doc); + } } void xFileSaveAs( Inkscape::ActionContext const & context, const Glib::ustring &uri ) { - SPDocument *doc = context.getDocument(); - if (s_verbose) { - printf("save as %s\n", uri.c_str()); - fflush(stdout); - } - - if( createDirForFilename( uri )) { - Inkscape::Extension::save( - Inkscape::Extension::db.get("org.inkscape.output.svg.inkscape"), - doc, uri.c_str(), false, false, true, Inkscape::Extension::FILE_SAVE_METHOD_SAVE_AS); - if (s_verbose) { - printf("save done: %s\n", uri.c_str() ); - fflush(stdout); - } - } - else - { - printf("can't create dirs for filename %s\n", uri.c_str() ); - fflush(stdout); - } + SPDocument *doc = context.getDocument(); + if (s_verbose) { + printf("save as %s\n", uri.c_str()); + fflush(stdout); + } + + if( createDirForFilename( uri )) { + Inkscape::Extension::save( + Inkscape::Extension::db.get("org.inkscape.output.svg.inkscape"), + doc, uri.c_str(), false, false, true, Inkscape::Extension::FILE_SAVE_METHOD_SAVE_AS); + if (s_verbose) { + printf("save done: %s\n", uri.c_str() ); + fflush(stdout); + } + } + else { + printf("can't create dirs for filename %s\n", uri.c_str() ); + fflush(stdout); + } } void xFileExportPNG( Inkscape::ActionContext const & context, const Glib::ustring &uri ) { - if (s_verbose) { - printf("export png %s\n", uri.c_str()); - fflush(stdout); - } - - SPDocument *doc = context.getDocument(); - - gdouble dpi = 200.0; - SPDesktop *desktop = SP_ACTIVE_DESKTOP; - - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - dpi = prefs->getDouble("/dialogs/export/defaultxdpi/value", DPI_BASE); - - gdouble width = doc->getWidth().value(doc->getDisplayUnit()); - gdouble height = doc->getHeight().value(doc->getDisplayUnit()); - - gdouble bmwidth = (width) * dpi / DPI_BASE; - gdouble bmheight = (height) * dpi / DPI_BASE; - - int png_width = (int)(0.5 + bmwidth); - int png_height = (int)(0.5 + bmheight); - - SPNamedView *nv = desktop->getNamedView(); - - ExportResult status = sp_export_png_file(doc, uri.c_str(), - Geom::Rect(Geom::Point(0,0), Geom::Point(width, height)), png_width, png_height, dpi, dpi, - nv->pagecolor, 0, 0, TRUE); + if (s_verbose) { + printf("export png %s\n", uri.c_str()); + fflush(stdout); + } + + SPDocument *doc = context.getDocument(); + + gdouble dpi = 200.0; + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + dpi = prefs->getDouble("/dialogs/export/defaultxdpi/value", DPI_BASE); + + gdouble width = doc->getWidth().value(doc->getDisplayUnit()); + gdouble height = doc->getHeight().value(doc->getDisplayUnit()); + + gdouble bmwidth = (width) * dpi / DPI_BASE; + gdouble bmheight = (height) * dpi / DPI_BASE; + + int png_width = (int)(0.5 + bmwidth); + int png_height = (int)(0.5 + bmheight); + + SPNamedView *nv = desktop->getNamedView(); + + ExportResult status = sp_export_png_file(doc, uri.c_str(), + Geom::Rect(Geom::Point(0,0), Geom::Point(width, height)), png_width, png_height, dpi, dpi, + nv->pagecolor, 0, 0, TRUE); } void xSelectElement( Inkscape::ActionContext const & context, const Glib::ustring &uri ) { - if (context.getDocument() == NULL || context.getSelection() == NULL) { return; } + if (context.getDocument() == NULL || context.getSelection() == NULL) { return; } - if (s_verbose) { - printf("select element: %s\n", uri.c_str()); - fflush(stdout); - } + if (s_verbose) { + printf("select element: %s\n", uri.c_str()); + fflush(stdout); + } - SPDocument * doc = context.getDocument(); - SPObject * obj = doc->getObjectById(uri); + SPDocument * doc = context.getDocument(); + SPObject * obj = doc->getObjectById(uri); - if (obj == NULL) { - printf(_("Unable to find node ID: '%s'\n"), uri.c_str()); - fflush(stdout); - return; - } + if (obj == NULL) { + printf(_("Unable to find node ID: '%s'\n"), uri.c_str()); + fflush(stdout); + return; + } - Inkscape::Selection * selection = context.getSelection(); - selection->add(obj); + Inkscape::Selection * selection = context.getSelection(); + selection->add(obj); - if (s_verbose) { - printf("select done %s\n", uri.c_str()); - fflush(stdout); - } + if (s_verbose) { + printf("select done %s\n", uri.c_str()); + fflush(stdout); + } } } // end of unnamed namespace @@ -238,45 +237,44 @@ void xSelectElement( Inkscape::ActionContext const & context, const Glib::ustrin namespace Inkscape { CmdLineXAction::CmdLineXAction (gchar const * arg, xaction_args_values_map_t &values_map): - CmdLineAction(true, arg), _values_map(values_map) { - this->arg = (char *)arg; - return; + CmdLineAction(true, arg), _values_map(values_map) { + this->arg = (char *)arg; + return; } bool CmdLineXAction::isExtended() { - return true; + return true; } void CmdLineXAction::doItX (ActionContext const & context) { - (void)(context); - - if( arg == "XFileSaveAs") - xFileSaveAs( context, _values_map["filename"] ); - else if (arg == "XFileOpen") - xFileOpen( _values_map["filename"] ); - else if (arg == "XFileExportPNG") - xFileExportPNG( context, _values_map["png_filename"] ); - else if (arg == "XSelectElement") - xSelectElement( context, _values_map["element-id"] ); - else - { - printf("unknown xverb: %s", arg.c_str()); - fflush(stdout); - } - - return; + (void)(context); + + if( arg == "XFileSaveAs") + xFileSaveAs( context, _values_map["filename"] ); + else if (arg == "XFileOpen") + xFileOpen( _values_map["filename"] ); + else if (arg == "XFileExportPNG") + xFileExportPNG( context, _values_map["png_filename"] ); + else if (arg == "XSelectElement") + xSelectElement( context, _values_map["element-id"] ); + else { + printf("unknown xverb: %s", arg.c_str()); + fflush(stdout); + } + + return; } enum parser_state_t{ HANDLING_ROOT, - HANDLING_VERBOSE, // options - HANDLING_RUN, HANDLING_RUN_LIST, HANDLING_RUN_LIST_ENTRY }; // run entries + HANDLING_VERBOSE, // options + HANDLING_RUN, HANDLING_RUN_LIST, HANDLING_RUN_LIST_ENTRY }; // run entries struct verb_info_t { - bool xverb; - std::vector args; + bool xverb; + std::vector args; }; typedef std::list verbs_list_t; @@ -303,212 +301,193 @@ static void tokenize(const std::string& str, std::vector& tokens, c void CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) { - FILE *fh = fopen(yaml_filename, "r"); - if(fh == NULL) { - printf("Failed to open file!\n"); - fflush(stdout); - return; - } - - yaml_parser_t parser; - if(!yaml_parser_initialize(&parser)) { - printf("Failed to initialize parser!\n"); - fflush(stdout); - return; - } - - /* Set input file */ - yaml_parser_set_input_file(&parser, fh); - - parser_state_t state = HANDLING_ROOT; - - - bool handling_key = false; - bool handling_value = false; - - std::string key; - verbs_list_t verbs_list; - - // parse - yaml_token_t token; - do { - yaml_parser_scan(&parser, &token); - switch(token.type) - { - // avoid "warning: enumeration value", "-Wswitch" - case YAML_NO_TOKEN: break; - case YAML_STREAM_START_TOKEN: break; - case YAML_STREAM_END_TOKEN: break; - case YAML_VERSION_DIRECTIVE_TOKEN: break; - case YAML_TAG_DIRECTIVE_TOKEN: break; - case YAML_DOCUMENT_START_TOKEN: break; - case YAML_DOCUMENT_END_TOKEN: break; - case YAML_FLOW_SEQUENCE_START_TOKEN: break; - case YAML_FLOW_SEQUENCE_END_TOKEN: break; - case YAML_FLOW_MAPPING_START_TOKEN: break; - case YAML_FLOW_MAPPING_END_TOKEN: break; - case YAML_FLOW_ENTRY_TOKEN: break; - case YAML_ALIAS_TOKEN: break; - case YAML_ANCHOR_TOKEN: break; - case YAML_TAG_TOKEN: break; - - /* Token types (read before actual token) */ - case YAML_KEY_TOKEN: - handling_key = true; - handling_value = false; - break; - case YAML_VALUE_TOKEN: - handling_key = false; - handling_value = true; - break; - - /* Block delimeters */ - case YAML_BLOCK_SEQUENCE_START_TOKEN: - if( state == HANDLING_ROOT ) - { - if( key == "run" ) - state = HANDLING_RUN; - } - break; - case YAML_BLOCK_ENTRY_TOKEN: - if( state == HANDLING_RUN ) - state = HANDLING_RUN_LIST; - else if( state == HANDLING_RUN_LIST ) - state = HANDLING_RUN_LIST_ENTRY; - else if( state == HANDLING_VERBOSE ) - state = HANDLING_ROOT; - break; - case YAML_BLOCK_END_TOKEN: - if( state == HANDLING_RUN_LIST_ENTRY ) - state = HANDLING_RUN_LIST; - else if( state == HANDLING_RUN_LIST ) - state = HANDLING_RUN; - else if( state == HANDLING_VERBOSE ) - state = HANDLING_ROOT; - else if( state == HANDLING_RUN ) - state = HANDLING_ROOT; - break; - - /* Data */ - case YAML_BLOCK_MAPPING_START_TOKEN: - break; - case YAML_SCALAR_TOKEN: - if( handling_key ) - key = (char *)token.data.scalar.value; - else if ( handling_value ) - { - if(state == HANDLING_RUN_LIST) - { - if(key == "xverb-id") - { - verb_info_t verb; - verb.xverb = true; - - std::string values = (char *)token.data.scalar.value; - tokenize(values, verb.args); - for( size_t i = 0; i < verb.args.size(); ++i ) - { - verb.args[i].erase(0, verb.args[i].find_first_not_of(' ')); //prefixing spaces - verb.args[i].erase(verb.args[i].find_last_not_of(' ')+1); //surfixing spaces - } - verbs_list.push_back(verb); - } - else if(key == "verb-id") - { - verb_info_t verb; - verb.xverb = false; - verb.args.push_back((char *)token.data.scalar.value); - verbs_list.push_back(verb); - } - else - { - printf("unknown verb type [%s]\n", key.c_str()); - fflush(stdout); - } - } - else if(state == HANDLING_ROOT) - { - std::string value = (char *)token.data.scalar.value; - if( (key == "verbose") && (value == "yes") ) - s_verbose = true; - } - } - break; - } - } while(token.type != YAML_STREAM_END_TOKEN); - - /* Cleanup */ - yaml_token_delete(&token); - yaml_parser_delete(&parser); - fclose(fh); - - typedef std::map undo_labels_map_t; - undo_labels_map_t undo_labels_map; - int undo_counter = 0; - - verbs_list_t::iterator iter = verbs_list.begin(); - for( ; iter != verbs_list.end(); ++iter ) - { - verb_info_t &verb = *iter; - std::string &verb_word = verb.args[0]; - if( s_verbose ) - printf("handle %s and args count is %d\n", verb_word.c_str(), (int)verb.args.size()); - - if( verb.args.size() == 2 ) - { - xaction_args_values_map_t values_map; - if (verb_word == "XFileSaveAs" || verb_word == "XFileOpen") - { - std::string &filename = verb.args[1]; - values_map["filename"] = filename; - new CmdLineXAction(verb_word.c_str(), values_map); - } - else if (verb_word == "XUndoLabel") - undo_labels_map[verb.args[1]] = undo_counter; - else if (verb_word == "UndoToLabel") - { - undo_labels_map_t::iterator iter = undo_labels_map.find(verb.args[1]); - if(iter != undo_labels_map.end()) - { - int counter = undo_counter - iter->second; - if( counter > 0 ) - { - for(int i = 0; i < counter; ++i) - new CmdLineAction(true, "EditUndo"); - undo_counter -= counter; - } - } - } - else if (verb_word == "XSelectElement") - { - ++undo_counter; - values_map["element-id"] = verb.args[1]; - new CmdLineXAction(verb_word.c_str(), values_map); - } - else if (verb_word == "XFileExportPNG") - { - std::string &png_filename = verb.args[1]; - values_map["png_filename"] = png_filename; - if(createDirForFilename( png_filename )) { - new CmdLineXAction(verb_word.c_str(), values_map); - } - } - } - else if(!verb.xverb) - { - ++undo_counter; - new CmdLineAction(true, verb.args[0].c_str()); - } - - else - { - printf("Unhadled verb %s\n", verb.args[0].c_str()); - fflush(stdout); - } - } - - fflush(stdout); - return; + FILE *fh = fopen(yaml_filename, "r"); + if(fh == NULL) { + printf("Failed to open file!\n"); + fflush(stdout); + return; + } + + yaml_parser_t parser; + if(!yaml_parser_initialize(&parser)) { + printf("Failed to initialize parser!\n"); + fflush(stdout); + return; + } + + /* Set input file */ + yaml_parser_set_input_file(&parser, fh); + + parser_state_t state = HANDLING_ROOT; + + + bool handling_key = false; + bool handling_value = false; + + std::string key; + verbs_list_t verbs_list; + + // parse + yaml_token_t token; + do { + yaml_parser_scan(&parser, &token); + switch(token.type) + { + // avoid "warning: enumeration value", "-Wswitch" + case YAML_NO_TOKEN: break; + case YAML_STREAM_START_TOKEN: break; + case YAML_STREAM_END_TOKEN: break; + case YAML_VERSION_DIRECTIVE_TOKEN: break; + case YAML_TAG_DIRECTIVE_TOKEN: break; + case YAML_DOCUMENT_START_TOKEN: break; + case YAML_DOCUMENT_END_TOKEN: break; + case YAML_FLOW_SEQUENCE_START_TOKEN: break; + case YAML_FLOW_SEQUENCE_END_TOKEN: break; + case YAML_FLOW_MAPPING_START_TOKEN: break; + case YAML_FLOW_MAPPING_END_TOKEN: break; + case YAML_FLOW_ENTRY_TOKEN: break; + case YAML_ALIAS_TOKEN: break; + case YAML_ANCHOR_TOKEN: break; + case YAML_TAG_TOKEN: break; + + /* Token types (read before actual token) */ + case YAML_KEY_TOKEN: + handling_key = true; + handling_value = false; + break; + case YAML_VALUE_TOKEN: + handling_key = false; + handling_value = true; + break; + + /* Block delimeters */ + case YAML_BLOCK_SEQUENCE_START_TOKEN: + if( state == HANDLING_ROOT ) { + if( key == "run" ) + state = HANDLING_RUN; + } + break; + case YAML_BLOCK_ENTRY_TOKEN: + if( state == HANDLING_RUN ) + state = HANDLING_RUN_LIST; + else if( state == HANDLING_RUN_LIST ) + state = HANDLING_RUN_LIST_ENTRY; + else if( state == HANDLING_VERBOSE ) + state = HANDLING_ROOT; + break; + case YAML_BLOCK_END_TOKEN: + if( state == HANDLING_RUN_LIST_ENTRY ) + state = HANDLING_RUN_LIST; + else if( state == HANDLING_RUN_LIST ) + state = HANDLING_RUN; + else if( state == HANDLING_VERBOSE ) + state = HANDLING_ROOT; + else if( state == HANDLING_RUN ) + state = HANDLING_ROOT; + break; + + /* Data */ + case YAML_BLOCK_MAPPING_START_TOKEN: + break; + case YAML_SCALAR_TOKEN: + if( handling_key ) + key = (char *)token.data.scalar.value; + else if ( handling_value ) { + if(state == HANDLING_RUN_LIST) { + if(key == "xverb-id") { + verb_info_t verb; + verb.xverb = true; + + std::string values = (char *)token.data.scalar.value; + tokenize(values, verb.args); + for( size_t i = 0; i < verb.args.size(); ++i ) { + verb.args[i].erase(0, verb.args[i].find_first_not_of(' ')); //prefixing spaces + verb.args[i].erase(verb.args[i].find_last_not_of(' ')+1); //surfixing spaces + } + verbs_list.push_back(verb); + } + else if(key == "verb-id") { + verb_info_t verb; + verb.xverb = false; + verb.args.push_back((char *)token.data.scalar.value); + verbs_list.push_back(verb); + } + else { + printf("unknown verb type [%s]\n", key.c_str()); + fflush(stdout); + } + } + else if(state == HANDLING_ROOT) { + std::string value = (char *)token.data.scalar.value; + if( (key == "verbose") && (value == "yes") ) + s_verbose = true; + } + } + break; + } + } while(token.type != YAML_STREAM_END_TOKEN); + + /* Cleanup */ + yaml_token_delete(&token); + yaml_parser_delete(&parser); + fclose(fh); + + typedef std::map undo_labels_map_t; + undo_labels_map_t undo_labels_map; + int undo_counter = 0; + + verbs_list_t::iterator iter = verbs_list.begin(); + for( ; iter != verbs_list.end(); ++iter ) { + verb_info_t &verb = *iter; + std::string &verb_word = verb.args[0]; + if( s_verbose ) + printf("handle %s and args count is %d\n", verb_word.c_str(), (int)verb.args.size()); + + if( verb.args.size() == 2 ) { + xaction_args_values_map_t values_map; + if (verb_word == "XFileSaveAs" || verb_word == "XFileOpen") { + std::string &filename = verb.args[1]; + values_map["filename"] = filename; + new CmdLineXAction(verb_word.c_str(), values_map); + } + else if (verb_word == "XUndoLabel") + undo_labels_map[verb.args[1]] = undo_counter; + else if (verb_word == "UndoToLabel") { + undo_labels_map_t::iterator iter = undo_labels_map.find(verb.args[1]); + if(iter != undo_labels_map.end()) { + int counter = undo_counter - iter->second; + if( counter > 0 ) { + for(int i = 0; i < counter; ++i) + new CmdLineAction(true, "EditUndo"); + undo_counter -= counter; + } + } + } + else if (verb_word == "XSelectElement") { + ++undo_counter; + values_map["element-id"] = verb.args[1]; + new CmdLineXAction(verb_word.c_str(), values_map); + } + else if (verb_word == "XFileExportPNG") { + std::string &png_filename = verb.args[1]; + values_map["png_filename"] = png_filename; + if(createDirForFilename( png_filename )) { + new CmdLineXAction(verb_word.c_str(), values_map); + } + } + } + else if(!verb.xverb) { + ++undo_counter; + new CmdLineAction(true, verb.args[0].c_str()); + } + else { + printf("Unhadled verb %s\n", verb.args[0].c_str()); + fflush(stdout); + } + } + + fflush(stdout); + return; } -- cgit v1.2.3 From 10476bfa9f215afe2d5ea368269c44eebe5d0628 Mon Sep 17 00:00:00 2001 From: Dmitry Zhulanov Date: Tue, 27 Sep 2016 21:25:42 +0700 Subject: fix indention (bzr r15136.1.4) --- src/main-cmdlineact.cpp | 144 ++++++++++++++++++++++++------------------------ 1 file changed, 72 insertions(+), 72 deletions(-) (limited to 'src') diff --git a/src/main-cmdlineact.cpp b/src/main-cmdlineact.cpp index 2d0a5cfd6..cea1291c7 100644 --- a/src/main-cmdlineact.cpp +++ b/src/main-cmdlineact.cpp @@ -26,106 +26,106 @@ std::list CmdLineAction::_list; bool CmdLineAction::_requestQuit = false; CmdLineAction::CmdLineAction (bool isVerb, gchar const * arg) : _isVerb(isVerb), _arg(NULL) { - if (arg != NULL) { - _arg = g_strdup(arg); - } + if (arg != NULL) { + _arg = g_strdup(arg); + } - _list.insert(_list.end(), this); + _list.insert(_list.end(), this); - return; + return; } CmdLineAction::~CmdLineAction () { - if (_arg != NULL) { - g_free(_arg); - } + if (_arg != NULL) { + g_free(_arg); + } } bool CmdLineAction::isExtended() { - return false; + return false; } void CmdLineAction::doItX (ActionContext const & context) { - (void)context; - printf("CmdLineAction::doItX() %s\n", _arg); + (void)context; + printf("CmdLineAction::doItX() %s\n", _arg); } void CmdLineAction::doIt (ActionContext const & context) { - //printf("Doing: %s\n", _arg); - if (_isVerb) { - if (isExtended()) { - //printf("Is extended\n"); - - doItX(context); - return; - } - - static std::string quit_verb_name = "FileQuit"; - if (quit_verb_name == _arg) { - _requestQuit = true; - return; - } - Inkscape::Verb * verb = Inkscape::Verb::getbyid(_arg); - if (verb == NULL) { - printf(_("Unable to find verb ID '%s' specified on the command line.\n"), _arg); - return; - } - SPAction * action = verb->get_action(context); - sp_action_perform(action, NULL); - } else { - if (context.getDocument() == NULL || context.getSelection() == NULL) { return; } - - SPDocument * doc = context.getDocument(); - SPObject * obj = doc->getObjectById(_arg); - if (obj == NULL) { - printf(_("Unable to find node ID: '%s'\n"), _arg); - return; - } - - Inkscape::Selection * selection = context.getSelection(); - selection->add(obj); - } - return; + //printf("Doing: %s\n", _arg); + if (_isVerb) { + if (isExtended()) { + //printf("Is extended\n"); + + doItX(context); + return; + } + + static std::string quit_verb_name = "FileQuit"; + if (quit_verb_name == _arg) { + _requestQuit = true; + return; + } + Inkscape::Verb * verb = Inkscape::Verb::getbyid(_arg); + if (verb == NULL) { + printf(_("Unable to find verb ID '%s' specified on the command line.\n"), _arg); + return; + } + SPAction * action = verb->get_action(context); + sp_action_perform(action, NULL); + } else { + if (context.getDocument() == NULL || context.getSelection() == NULL) { return; } + + SPDocument * doc = context.getDocument(); + SPObject * obj = doc->getObjectById(_arg); + if (obj == NULL) { + printf(_("Unable to find node ID: '%s'\n"), _arg); + return; + } + + Inkscape::Selection * selection = context.getSelection(); + selection->add(obj); + } + return; } bool CmdLineAction::doList (ActionContext const & context) { bool hasActions = !_list.empty(); - if (!hasActions && _requestQuit) { - sp_file_exit(); - return true; - } - - for (std::list::iterator i = _list.begin(); - i != _list.end(); ++i) { - CmdLineAction * entry = *i; - entry->doIt(context); - if (_requestQuit) { - sp_file_exit(); - return true; - } - } + if (!hasActions && _requestQuit) { + sp_file_exit(); + return true; + } + + for (std::list::iterator i = _list.begin(); + i != _list.end(); ++i) { + CmdLineAction * entry = *i; + entry->doIt(context); + if (_requestQuit) { + sp_file_exit(); + return true; + } + } return hasActions; } bool CmdLineAction::idle (void) { - std::list desktops; - INKSCAPE.get_all_desktops(desktops); - - // We're going to assume one desktop per document, because no one - // should have had time to make more at this point. - for (std::list::iterator i = desktops.begin(); - i != desktops.end(); ++i) { - SPDesktop * desktop = *i; - //Inkscape::UI::View::View * view = dynamic_cast(desktop); - doList(ActionContext(desktop)); - } - return false; + std::list desktops; + INKSCAPE.get_all_desktops(desktops); + + // We're going to assume one desktop per document, because no one + // should have had time to make more at this point. + for (std::list::iterator i = desktops.begin(); + i != desktops.end(); ++i) { + SPDesktop * desktop = *i; + //Inkscape::UI::View::View * view = dynamic_cast(desktop); + doList(ActionContext(desktop)); + } + return false; } } // Inkscape -- cgit v1.2.3 From ef6e004b46469da3419554758bd0c0ed47df286f Mon Sep 17 00:00:00 2001 From: Dmitry Zhulanov Date: Tue, 27 Sep 2016 21:38:32 +0700 Subject: no need to FileQuit verb checking (bzr r15136.1.5) --- src/main-cmdlineact.cpp | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'src') diff --git a/src/main-cmdlineact.cpp b/src/main-cmdlineact.cpp index cea1291c7..fc0f50cd4 100644 --- a/src/main-cmdlineact.cpp +++ b/src/main-cmdlineact.cpp @@ -23,7 +23,6 @@ namespace Inkscape { std::list CmdLineAction::_list; -bool CmdLineAction::_requestQuit = false; CmdLineAction::CmdLineAction (bool isVerb, gchar const * arg) : _isVerb(isVerb), _arg(NULL) { if (arg != NULL) { @@ -64,11 +63,6 @@ CmdLineAction::doIt (ActionContext const & context) { return; } - static std::string quit_verb_name = "FileQuit"; - if (quit_verb_name == _arg) { - _requestQuit = true; - return; - } Inkscape::Verb * verb = Inkscape::Verb::getbyid(_arg); if (verb == NULL) { printf(_("Unable to find verb ID '%s' specified on the command line.\n"), _arg); @@ -95,19 +89,10 @@ CmdLineAction::doIt (ActionContext const & context) { bool CmdLineAction::doList (ActionContext const & context) { bool hasActions = !_list.empty(); - if (!hasActions && _requestQuit) { - sp_file_exit(); - return true; - } - for (std::list::iterator i = _list.begin(); i != _list.end(); ++i) { CmdLineAction * entry = *i; entry->doIt(context); - if (_requestQuit) { - sp_file_exit(); - return true; - } } return hasActions; } -- cgit v1.2.3 From 2de5e2452a8cd319e195eb77099e5a3a8898c94f Mon Sep 17 00:00:00 2001 From: Dmitry Zhulanov Date: Tue, 27 Sep 2016 23:25:28 +0700 Subject: ignore additional arguments of x-verbs (bzr r15136.1.6) --- src/main-cmdlinexact.cpp | 98 +++++++++++++++++++++++++++++++----------------- 1 file changed, 64 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/main-cmdlinexact.cpp b/src/main-cmdlinexact.cpp index 940abfca4..a498f8425 100644 --- a/src/main-cmdlinexact.cpp +++ b/src/main-cmdlinexact.cpp @@ -437,44 +437,74 @@ CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) { int undo_counter = 0; verbs_list_t::iterator iter = verbs_list.begin(); - for( ; iter != verbs_list.end(); ++iter ) { + for (;iter != verbs_list.end(); ++iter) { verb_info_t &verb = *iter; std::string &verb_word = verb.args[0]; - if( s_verbose ) + if (s_verbose) printf("handle %s and args count is %d\n", verb_word.c_str(), (int)verb.args.size()); - if( verb.args.size() == 2 ) { - xaction_args_values_map_t values_map; - if (verb_word == "XFileSaveAs" || verb_word == "XFileOpen") { - std::string &filename = verb.args[1]; - values_map["filename"] = filename; - new CmdLineXAction(verb_word.c_str(), values_map); - } - else if (verb_word == "XUndoLabel") - undo_labels_map[verb.args[1]] = undo_counter; - else if (verb_word == "UndoToLabel") { - undo_labels_map_t::iterator iter = undo_labels_map.find(verb.args[1]); - if(iter != undo_labels_map.end()) { - int counter = undo_counter - iter->second; - if( counter > 0 ) { - for(int i = 0; i < counter; ++i) - new CmdLineAction(true, "EditUndo"); - undo_counter -= counter; - } - } - } - else if (verb_word == "XSelectElement") { - ++undo_counter; - values_map["element-id"] = verb.args[1]; - new CmdLineXAction(verb_word.c_str(), values_map); - } - else if (verb_word == "XFileExportPNG") { - std::string &png_filename = verb.args[1]; - values_map["png_filename"] = png_filename; - if(createDirForFilename( png_filename )) { - new CmdLineXAction(verb_word.c_str(), values_map); - } - } + if (verb_word == "XFileOpen") { + if( verb.args.size() < 2 ) + { + printf("bad arguments for XFileOpen\n"); + continue; + } + + xaction_args_values_map_t values_map; + values_map["filename"] = verb.args[1]; + new CmdLineXAction(verb_word.c_str(), values_map); + } else if (verb_word == "XFileSaveAs") + { + if (verb.args.size() < 2) { + printf("bad arguments for XFileSaveAs\n"); + continue; + } + + xaction_args_values_map_t values_map; + values_map["filename"] = verb.args[1]; + new CmdLineXAction(verb_word.c_str(), values_map); + } else if (verb_word == "XUndoLabel") { + if (verb.args.size() < 2) { + printf("bad arguments for XUndoLabel\n"); + continue; + } + undo_labels_map[verb.args[1]] = undo_counter; + } else if (verb_word == "UndoToLabel") { + if (verb.args.size() < 2) { + printf("bad arguments for UndoToLabel\n"); + continue; + } + + undo_labels_map_t::iterator iter = undo_labels_map.find(verb.args[1]); + if(iter != undo_labels_map.end()) { + int counter = undo_counter - iter->second; + if( counter > 0 ) { + for(int i = 0; i < counter; ++i) + new CmdLineAction(true, "EditUndo"); + undo_counter -= counter; + } + } + } else if (verb_word == "XSelectElement") { + if (verb.args.size() < 2) { + printf("bad arguments for XSelectElement\n"); + continue; + } + ++undo_counter; + + xaction_args_values_map_t values_map; + values_map["element-id"] = verb.args[1]; + new CmdLineXAction(verb_word.c_str(), values_map); + } else if (verb_word == "XFileExportPNG") { + if (verb.args.size() < 2) { + printf("bad arguments for XFileExportPNG\n"); + continue; + } + + xaction_args_values_map_t values_map; + std::string &png_filename = verb.args[1]; + values_map["png_filename"] = png_filename; + if(createDirForFilename( png_filename )) + new CmdLineXAction(verb_word.c_str(), values_map); } else if(!verb.xverb) { ++undo_counter; -- cgit v1.2.3 From d9c220b750654b229096a9f62f24480e100c8aa8 Mon Sep 17 00:00:00 2001 From: Dmitry Zhulanov Date: Thu, 29 Sep 2016 21:47:23 +0700 Subject: allow optional args for xverbs (bzr r15136.1.7) --- src/main-cmdlinexact.cpp | 185 ++++++++++++++++++++++++----------------------- src/verbs.cpp | 8 +- src/verbs.h | 2 +- 3 files changed, 102 insertions(+), 93 deletions(-) (limited to 'src') diff --git a/src/main-cmdlinexact.cpp b/src/main-cmdlinexact.cpp index a498f8425..ddf8a73eb 100644 --- a/src/main-cmdlinexact.cpp +++ b/src/main-cmdlinexact.cpp @@ -68,6 +68,7 @@ #include #include #include +#include #define DPI_BASE Inkscape::Util::Quantity::convert(1, "in", "px") @@ -93,6 +94,35 @@ bool createDirForFilename( const std::string &filename ) return true; } +std::vector vectorFromString(const std::string &csv) +{ + std::vector result; + + std::string delimiters = ","; + + // Skip delimiters at beginning. + std::string::size_type lastPos = csv.find_first_not_of(delimiters, 0); + + // Find first non-delimiter. + std::string::size_type pos = csv.find_first_of(delimiters, lastPos); + + while (std::string::npos != pos || std::string::npos != lastPos) { + // Found a token, add it to the vector. + std::string token = csv.substr(lastPos, pos - lastPos); + token.erase(0, token.find_first_not_of(' ')); //prefixing spaces + token.erase(token.find_last_not_of(' ')+1); //surfixing spaces + result.push_back(token); + + // Skip delimiters. + lastPos = csv.find_first_not_of(delimiters, pos); + + // Find next non-delimiter. + pos = csv.find_first_of(delimiters, lastPos); + } + + return result; +} + void xFileOpen( const Glib::ustring &uri ) { if (s_verbose) { @@ -279,25 +309,6 @@ struct verb_info_t typedef std::list verbs_list_t; -static void tokenize(const std::string& str, std::vector& tokens, const std::string& delimiters = ",") -{ - // Skip delimiters at beginning. - std::string::size_type lastPos = str.find_first_not_of(delimiters, 0); - - // Find first non-delimiter. - std::string::size_type pos = str.find_first_of(delimiters, lastPos); - - while (std::string::npos != pos || std::string::npos != lastPos) { - // Found a token, add it to the vector. - tokens.push_back(str.substr(lastPos, pos - lastPos)); - - // Skip delimiters. - lastPos = str.find_first_not_of(delimiters, pos); - - // Find next non-delimiter. - pos = str.find_first_of(delimiters, lastPos); - } -} void CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) { @@ -397,19 +408,15 @@ CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) { if(key == "xverb-id") { verb_info_t verb; verb.xverb = true; - - std::string values = (char *)token.data.scalar.value; - tokenize(values, verb.args); - for( size_t i = 0; i < verb.args.size(); ++i ) { - verb.args[i].erase(0, verb.args[i].find_first_not_of(' ')); //prefixing spaces - verb.args[i].erase(verb.args[i].find_last_not_of(' ')+1); //surfixing spaces - } + verb.args = vectorFromString((char *)token.data.scalar.value); + if ((verb.args.size() > 1) && Verb::getbyid((char *)token.data.scalar.value)) + verb.xverb = false; verbs_list.push_back(verb); } else if(key == "verb-id") { verb_info_t verb; verb.xverb = false; - verb.args.push_back((char *)token.data.scalar.value); + verb.args = vectorFromString((char *)token.data.scalar.value); verbs_list.push_back(verb); } else { @@ -443,68 +450,68 @@ CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) { if (s_verbose) printf("handle %s and args count is %d\n", verb_word.c_str(), (int)verb.args.size()); - if (verb_word == "XFileOpen") { - if( verb.args.size() < 2 ) - { - printf("bad arguments for XFileOpen\n"); - continue; - } - - xaction_args_values_map_t values_map; - values_map["filename"] = verb.args[1]; - new CmdLineXAction(verb_word.c_str(), values_map); - } else if (verb_word == "XFileSaveAs") - { - if (verb.args.size() < 2) { - printf("bad arguments for XFileSaveAs\n"); - continue; - } - - xaction_args_values_map_t values_map; - values_map["filename"] = verb.args[1]; - new CmdLineXAction(verb_word.c_str(), values_map); - } else if (verb_word == "XUndoLabel") { - if (verb.args.size() < 2) { - printf("bad arguments for XUndoLabel\n"); - continue; - } - undo_labels_map[verb.args[1]] = undo_counter; - } else if (verb_word == "UndoToLabel") { - if (verb.args.size() < 2) { - printf("bad arguments for UndoToLabel\n"); - continue; - } - - undo_labels_map_t::iterator iter = undo_labels_map.find(verb.args[1]); - if(iter != undo_labels_map.end()) { - int counter = undo_counter - iter->second; - if( counter > 0 ) { - for(int i = 0; i < counter; ++i) - new CmdLineAction(true, "EditUndo"); - undo_counter -= counter; - } - } - } else if (verb_word == "XSelectElement") { - if (verb.args.size() < 2) { - printf("bad arguments for XSelectElement\n"); - continue; - } - ++undo_counter; - - xaction_args_values_map_t values_map; - values_map["element-id"] = verb.args[1]; - new CmdLineXAction(verb_word.c_str(), values_map); - } else if (verb_word == "XFileExportPNG") { - if (verb.args.size() < 2) { - printf("bad arguments for XFileExportPNG\n"); - continue; - } - - xaction_args_values_map_t values_map; - std::string &png_filename = verb.args[1]; - values_map["png_filename"] = png_filename; - if(createDirForFilename( png_filename )) - new CmdLineXAction(verb_word.c_str(), values_map); + if (verb_word == "XFileOpen") { + if( verb.args.size() < 2 ) + { + printf("bad arguments for XFileOpen\n"); + continue; + } + + xaction_args_values_map_t values_map; + values_map["filename"] = verb.args[1]; + new CmdLineXAction(verb_word.c_str(), values_map); + } else if (verb_word == "XFileSaveAs") + { + if (verb.args.size() < 2) { + printf("bad arguments for XFileSaveAs\n"); + continue; + } + + xaction_args_values_map_t values_map; + values_map["filename"] = verb.args[1]; + new CmdLineXAction(verb_word.c_str(), values_map); + } else if (verb_word == "XUndoLabel") { + if (verb.args.size() < 2) { + printf("bad arguments for XUndoLabel\n"); + continue; + } + undo_labels_map[verb.args[1]] = undo_counter; + } else if (verb_word == "UndoToLabel") { + if (verb.args.size() < 2) { + printf("bad arguments for UndoToLabel\n"); + continue; + } + + undo_labels_map_t::iterator iter = undo_labels_map.find(verb.args[1]); + if(iter != undo_labels_map.end()) { + int counter = undo_counter - iter->second; + if( counter > 0 ) { + for(int i = 0; i < counter; ++i) + new CmdLineAction(true, "EditUndo"); + undo_counter -= counter; + } + } + } else if (verb_word == "XSelectElement") { + if (verb.args.size() < 2) { + printf("bad arguments for XSelectElement\n"); + continue; + } + ++undo_counter; + + xaction_args_values_map_t values_map; + values_map["element-id"] = verb.args[1]; + new CmdLineXAction(verb_word.c_str(), values_map); + } else if (verb_word == "XFileExportPNG") { + if (verb.args.size() < 2) { + printf("bad arguments for XFileExportPNG\n"); + continue; + } + + xaction_args_values_map_t values_map; + std::string &png_filename = verb.args[1]; + values_map["png_filename"] = png_filename; + if(createDirForFilename( png_filename )) + new CmdLineXAction(verb_word.c_str(), values_map); } else if(!verb.xverb) { ++undo_counter; diff --git a/src/verbs.cpp b/src/verbs.cpp index 5130f1701..72708a7c0 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -817,7 +817,7 @@ Verb *Verb::get_search(unsigned int code) * * @param id Which id to search for. */ -Verb *Verb::getbyid(gchar const *id) +Verb *Verb::getbyid(gchar const *id, bool verbose) { Verb *verb = NULL; VerbIDTable::iterator verb_found = _verb_ids.find(id); @@ -833,8 +833,10 @@ Verb *Verb::getbyid(gchar const *id) && strcmp(id, "SelectionTrace") != 0 && strcmp(id, "PaintBucketPrefs") != 0 #endif - ) - printf("Unable to find: %s\n", id); + ) { + if (verbose) + printf("Unable to find: %s\n", id); + } return verb; } diff --git a/src/verbs.h b/src/verbs.h index 16f88c408..e9ae10ba5 100644 --- a/src/verbs.h +++ b/src/verbs.h @@ -553,7 +553,7 @@ public: SPAction * get_action(Inkscape::ActionContext const & context); private: - static Verb * get_search (unsigned int code); + static Verb * get_search (unsigned int code, bool verbose = true); public: /** -- cgit v1.2.3 From 06f90c27b6e17397b03f20fe92fd0fb31d55332c Mon Sep 17 00:00:00 2001 From: Dmitry Zhulanov Date: Thu, 29 Sep 2016 23:08:29 +0700 Subject: allow to use verbs as xverbs (bzr r15136.1.8) --- src/main-cmdlinexact.cpp | 7 ++++++- src/verbs.h | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main-cmdlinexact.cpp b/src/main-cmdlinexact.cpp index ddf8a73eb..a3c9436bd 100644 --- a/src/main-cmdlinexact.cpp +++ b/src/main-cmdlinexact.cpp @@ -517,8 +517,13 @@ CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) { ++undo_counter; new CmdLineAction(true, verb.args[0].c_str()); } + else if( Verb::getbyid(verb.args[0].c_str()) != NULL ) + { + ++undo_counter; + new CmdLineAction(true, verb.args[0].c_str()); + } else { - printf("Unhadled verb %s\n", verb.args[0].c_str()); + printf("Unhadled xverb %s\n", verb.args[0].c_str()); fflush(stdout); } } diff --git a/src/verbs.h b/src/verbs.h index e9ae10ba5..a273fe76e 100644 --- a/src/verbs.h +++ b/src/verbs.h @@ -553,7 +553,7 @@ public: SPAction * get_action(Inkscape::ActionContext const & context); private: - static Verb * get_search (unsigned int code, bool verbose = true); + static Verb * get_search (unsigned int code); public: /** @@ -575,7 +575,7 @@ public: return get_search(code); } } - static Verb * getbyid (gchar const * id); + static Verb * getbyid (gchar const * id, bool verbose = true); /** * Print a message to stderr indicating that this verb needs a GUI to run -- cgit v1.2.3 From 81364db0bc98b01319dc5ecb835a4e37b906bad2 Mon Sep 17 00:00:00 2001 From: Dmitry Zhulanov Date: Sat, 1 Oct 2016 13:05:10 +0700 Subject: disable xverb feature if WITH_YAML defined (bzr r15136.1.9) --- src/main-cmdlinexact.cpp | 10 ++++++++-- src/main.cpp | 15 +++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/main-cmdlinexact.cpp b/src/main-cmdlinexact.cpp index a3c9436bd..3dc83bc8f 100644 --- a/src/main-cmdlinexact.cpp +++ b/src/main-cmdlinexact.cpp @@ -52,7 +52,10 @@ #include #include "main-cmdlinexact.h" +#ifdef WITH_YAML #include "yaml.h" +#endif // WITH_YAML + #include "extension/system.h" #include "file.h" #include @@ -312,6 +315,9 @@ typedef std::list verbs_list_t; void CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) { +#ifndef WITH_YAML + return; +#else // WITH_YAML FILE *fh = fopen(yaml_filename, "r"); if(fh == NULL) { printf("Failed to open file!\n"); @@ -409,7 +415,7 @@ CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) { verb_info_t verb; verb.xverb = true; verb.args = vectorFromString((char *)token.data.scalar.value); - if ((verb.args.size() > 1) && Verb::getbyid((char *)token.data.scalar.value)) + if ((verb.args.size() > 1) && Verb::getbyid((char *)token.data.scalar.value, false)) verb.xverb = false; verbs_list.push_back(verb); } @@ -529,7 +535,7 @@ CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) { } fflush(stdout); - return; +#endif // WITH_YAML } diff --git a/src/main.cpp b/src/main.cpp index d9f11ed8b..5b7dcc5ef 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -229,8 +229,10 @@ static gchar *sp_export_png_utf8 = NULL; static gchar *sp_export_svg_utf8 = NULL; static gchar *sp_global_printer_utf8 = NULL; +#ifdef WITH_YAML static gchar *sp_xverbs_yaml_utf8 = NULL; static gchar *sp_xverbs_yaml = NULL; +#endif // WITH_YAML /** @@ -305,12 +307,12 @@ struct poptOption options[] = { POPT_ARG_STRING, NULL, SP_ARG_FILE, N_("Open specified document(s) (option string may be excluded)"), N_("FILENAME")}, - - {"xverbs", 'B', +#ifdef WITH_YAML + {"xverbs", 0, POPT_ARG_STRING, &sp_xverbs_yaml, SP_ARG_XVERBS, N_("xverbs command"), N_("XVERBS_FILENAME")}, - +#endif // WITH_YAML {"print", 'p', POPT_ARG_STRING, &sp_global_printer, SP_ARG_PRINT, N_("Print document(s) to specified output file (use '| program' for pipe)"), @@ -891,7 +893,9 @@ static int sp_common_main( int argc, char const **argv, GSList **flDest ) fixupSingleFilename( &sp_export_png, &sp_export_png_utf8 ); fixupSingleFilename( &sp_export_svg, &sp_export_svg_utf8 ); fixupSingleFilename( &sp_global_printer, &sp_global_printer_utf8 ); +#ifdef WITH_YAML fixupSingleFilename( &sp_xverbs_yaml, &sp_xverbs_yaml_utf8 ); +#endif // WITH_YAML } else { @@ -901,9 +905,10 @@ static int sp_common_main( int argc, char const **argv, GSList **flDest ) sp_export_svg_utf8 = g_strdup( sp_export_svg ); if ( sp_global_printer ) sp_global_printer_utf8 = g_strdup( sp_global_printer ); +#ifdef WITH_YAML if ( sp_xverbs_yaml ) sp_xverbs_yaml_utf8 = g_strdup( sp_xverbs_yaml ); - +#endif // WITH_YAML } #ifdef WITH_DBUS @@ -2145,6 +2150,7 @@ sp_process_args(poptContext ctx) } break; } +#ifdef WITH_YAML case SP_ARG_XVERBS: { gchar const *fn = poptGetOptArg(ctx); if (fn != NULL) { @@ -2153,6 +2159,7 @@ sp_process_args(poptContext ctx) } break; } +#endif // WITH_YAML case SP_ARG_VERSION: { printf("Inkscape %s (%s)\n", Inkscape::version_string, __DATE__); exit(0); -- cgit v1.2.3 From ea38e86ebfbcc53d86433fddbffffbfb5403c9fc Mon Sep 17 00:00:00 2001 From: Dmitry Zhulanov Date: Sat, 1 Oct 2016 16:01:18 +0700 Subject: fix indent (bzr r15136.1.10) --- src/main-cmdlinexact.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main-cmdlinexact.cpp b/src/main-cmdlinexact.cpp index 3dc83bc8f..f29d22377 100644 --- a/src/main-cmdlinexact.cpp +++ b/src/main-cmdlinexact.cpp @@ -316,8 +316,8 @@ typedef std::list verbs_list_t; void CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) { #ifndef WITH_YAML - return; -#else // WITH_YAML + return; +#else // WITH_YAML FILE *fh = fopen(yaml_filename, "r"); if(fh == NULL) { printf("Failed to open file!\n"); @@ -527,7 +527,7 @@ CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) { { ++undo_counter; new CmdLineAction(true, verb.args[0].c_str()); - } + } else { printf("Unhadled xverb %s\n", verb.args[0].c_str()); fflush(stdout); -- cgit v1.2.3 From 017616c4fc99883323c2a0d6e44b88f7cd16ce2d Mon Sep 17 00:00:00 2001 From: Dmitry Zhulanov Date: Sat, 1 Oct 2016 17:08:49 +0700 Subject: fix cmake warning and remove whole xverbs code from compilation without yaml (bzr r15136.1.11) --- src/main-cmdlinexact.cpp | 11 ++++------- src/main-cmdlinexact.h | 4 +++- 2 files changed, 7 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/main-cmdlinexact.cpp b/src/main-cmdlinexact.cpp index f29d22377..f5db522ae 100644 --- a/src/main-cmdlinexact.cpp +++ b/src/main-cmdlinexact.cpp @@ -38,7 +38,7 @@ * # inkscape have a lot of useful verbs * - verb-id: FileQuit */ - +#ifdef WITH_YAML #include #include #include @@ -52,9 +52,8 @@ #include #include "main-cmdlinexact.h" -#ifdef WITH_YAML + #include "yaml.h" -#endif // WITH_YAML #include "extension/system.h" #include "file.h" @@ -315,9 +314,6 @@ typedef std::list verbs_list_t; void CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) { -#ifndef WITH_YAML - return; -#else // WITH_YAML FILE *fh = fopen(yaml_filename, "r"); if(fh == NULL) { printf("Failed to open file!\n"); @@ -535,12 +531,13 @@ CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) { } fflush(stdout); -#endif // WITH_YAML } } // Inkscape +#endif // WITH_YAML + /* Local Variables: mode:c++ diff --git a/src/main-cmdlinexact.h b/src/main-cmdlinexact.h index 1ac630e55..8634f3875 100644 --- a/src/main-cmdlinexact.h +++ b/src/main-cmdlinexact.h @@ -2,6 +2,8 @@ #ifndef __INK_MAIN_CMD_LINE_XACTIONS_H__ #define __INK_MAIN_CMD_LINE_XACTIONS_H__ +#ifdef WITH_YAML + /** \file * Extended actions that can be queued at the yaml file */ @@ -37,7 +39,7 @@ public: } // Inkscape - +#endif // WITH_YAML #endif /* __INK_MAIN_CMD_LINE_XACTIONS_H__ */ /* -- cgit v1.2.3 From 745dd3ffab16bdadc91beb6d3b0da81594f539fa Mon Sep 17 00:00:00 2001 From: Dmitry Zhulanov Date: Sun, 2 Oct 2016 11:02:44 +0700 Subject: split big function (bzr r15136.1.12) --- src/main-cmdlinexact.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/main-cmdlinexact.cpp b/src/main-cmdlinexact.cpp index f5db522ae..2f7afe9fa 100644 --- a/src/main-cmdlinexact.cpp +++ b/src/main-cmdlinexact.cpp @@ -311,21 +311,23 @@ struct verb_info_t typedef std::list verbs_list_t; +static verbs_list_t +parseVerbsYAMLFile(gchar const *yaml_filename) +{ + verbs_list_t verbs_list; -void -CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) { FILE *fh = fopen(yaml_filename, "r"); if(fh == NULL) { printf("Failed to open file!\n"); fflush(stdout); - return; + return verbs_list; } yaml_parser_t parser; if(!yaml_parser_initialize(&parser)) { printf("Failed to initialize parser!\n"); fflush(stdout); - return; + return verbs_list; } /* Set input file */ @@ -333,12 +335,10 @@ CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) { parser_state_t state = HANDLING_ROOT; - bool handling_key = false; bool handling_value = false; std::string key; - verbs_list_t verbs_list; // parse yaml_token_t token; @@ -441,6 +441,14 @@ CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) { yaml_parser_delete(&parser); fclose(fh); + return verbs_list; +} + +void +CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) +{ + verbs_list_t verbs_list = parseVerbsYAMLFile(yaml_filename); + typedef std::map undo_labels_map_t; undo_labels_map_t undo_labels_map; int undo_counter = 0; -- cgit v1.2.3 From 647462662a4267c58306e49ec841abe92a958cca Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Mon, 3 Oct 2016 15:29:34 +0200 Subject: Prevent a crash if a mesh is defined in bounding box coordinates. (bzr r15144) --- src/gradient-chemistry.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/gradient-chemistry.cpp b/src/gradient-chemistry.cpp index 061fadbaa..cf5cda180 100644 --- a/src/gradient-chemistry.cpp +++ b/src/gradient-chemistry.cpp @@ -434,6 +434,11 @@ SPGradient *sp_gradient_convert_to_userspace(SPGradient *gr, SPItem *item, gchar return gr; } + // FIXME Transforming a mesh gradient is more complicated... probably need to add function to SPMeshArray.wq + if ( gr && SP_IS_MESHGRADIENT( gr ) ) { + return gr; + } + // First, fork it if it is shared gr = sp_gradient_fork_private_if_necessary(gr, gr->getVector(), SP_IS_RADIALGRADIENT(gr) ? SP_GRADIENT_TYPE_RADIAL : SP_GRADIENT_TYPE_LINEAR, item); -- cgit v1.2.3 From 62fc42f0bceab46b06f0d535a235d8bfe4c851a2 Mon Sep 17 00:00:00 2001 From: Dmitry Zhulanov Date: Mon, 3 Oct 2016 21:38:19 +0700 Subject: butify idents (bzr r15136.1.13) --- src/main-cmdlinexact.cpp | 108 +++++++++++++++++++++++++++-------------------- 1 file changed, 63 insertions(+), 45 deletions(-) (limited to 'src') diff --git a/src/main-cmdlinexact.cpp b/src/main-cmdlinexact.cpp index 2f7afe9fa..99f0c699b 100644 --- a/src/main-cmdlinexact.cpp +++ b/src/main-cmdlinexact.cpp @@ -8,11 +8,11 @@ * * Format of xverbs.yaml * using: $ inkscape -B xverbs.yaml - * + * * verbose: yes # only "verbose: yes" enable logging * run: * # open document to process - * - xverb-id: XFileOpen, gfx_sources/loading_screen/sandclock_atlas.svg + * - xverb-id: XFileOpen, gfx_sources/loading_screen/sandclock_atlas.svg * - xverb-id: XUndoLabel, fresh_document # set label for UndoToLabel xverb works * # note: if something wrong with undo labels use verb EditUndo instead of XUndoLabel and UndoToLabel at all * @@ -31,7 +31,7 @@ * - xverb-id: XFileExportPNG, output/thegame/linux/data/gfx_preview/loading_screen/top_sand.png * * # return to the fresh_state of document - * - xverb-id: UndoToLabel, fresh_document + * - xverb-id: UndoToLabel, fresh_document * * # do any other handling * @@ -82,10 +82,10 @@ bool createDirForFilename( const std::string &filename ) { size_t found = filename.find_last_of("/\\"); std::string output_directory = filename.substr(0,found); - + if( output_directory == filename ) return true; - + if (g_mkdir_with_parents(output_directory.c_str(), 0755)) { printf("Can't create directory %s\n", output_directory.c_str()); fflush(stdout); @@ -138,7 +138,7 @@ void xFileOpen( const Glib::ustring &uri ) desktop->setWaitingCursor(); Inkscape::DocumentUndo::clearRedo(old_document); } - + SPDocument *doc = NULL; Inkscape::Extension::Extension *key = NULL; try { @@ -152,8 +152,8 @@ void xFileOpen( const Glib::ustring &uri ) // Set viewBox if it doesn't exist if (!doc->getRoot()->viewBox_set - && (doc->getRoot()->width.unit != SVGLength::PERCENT) - && (doc->getRoot()->height.unit != SVGLength::PERCENT)) { + && (doc->getRoot()->width.unit != SVGLength::PERCENT) + && (doc->getRoot()->height.unit != SVGLength::PERCENT)) { doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().value(doc->getDisplayUnit()), doc->getHeight().value(doc->getDisplayUnit()))); } @@ -193,7 +193,7 @@ void xFileSaveAs( Inkscape::ActionContext const & context, const Glib::ustring & if( createDirForFilename( uri )) { Inkscape::Extension::save( - Inkscape::Extension::db.get("org.inkscape.output.svg.inkscape"), + Inkscape::Extension::db.get("org.inkscape.output.svg.inkscape"), doc, uri.c_str(), false, false, true, Inkscape::Extension::FILE_SAVE_METHOD_SAVE_AS); if (s_verbose) { printf("save done: %s\n", uri.c_str() ); @@ -220,26 +220,28 @@ void xFileExportPNG( Inkscape::ActionContext const & context, const Glib::ustrin Inkscape::Preferences *prefs = Inkscape::Preferences::get(); dpi = prefs->getDouble("/dialogs/export/defaultxdpi/value", DPI_BASE); - + gdouble width = doc->getWidth().value(doc->getDisplayUnit()); gdouble height = doc->getHeight().value(doc->getDisplayUnit()); - + gdouble bmwidth = (width) * dpi / DPI_BASE; gdouble bmheight = (height) * dpi / DPI_BASE; - + int png_width = (int)(0.5 + bmwidth); int png_height = (int)(0.5 + bmheight); - + SPNamedView *nv = desktop->getNamedView(); ExportResult status = sp_export_png_file(doc, uri.c_str(), - Geom::Rect(Geom::Point(0,0), Geom::Point(width, height)), png_width, png_height, dpi, dpi, - nv->pagecolor, 0, 0, TRUE); + Geom::Rect(Geom::Point(0,0), Geom::Point(width, height)), png_width, png_height, dpi, dpi, + nv->pagecolor, 0, 0, TRUE); } void xSelectElement( Inkscape::ActionContext const & context, const Glib::ustring &uri ) { - if (context.getDocument() == NULL || context.getSelection() == NULL) { return; } + if (context.getDocument() == NULL || context.getSelection() == NULL) { + return; + } if (s_verbose) { printf("select element: %s\n", uri.c_str()); @@ -281,7 +283,7 @@ CmdLineXAction::isExtended() { void CmdLineXAction::doItX (ActionContext const & context) { - (void)(context); + (void)(context); if( arg == "XFileSaveAs") xFileSaveAs( context, _values_map["filename"] ); @@ -299,9 +301,10 @@ CmdLineXAction::doItX (ActionContext const & context) { return; } -enum parser_state_t{ HANDLING_ROOT, - HANDLING_VERBOSE, // options - HANDLING_RUN, HANDLING_RUN_LIST, HANDLING_RUN_LIST_ENTRY }; // run entries +enum parser_state_t { HANDLING_ROOT, + HANDLING_VERBOSE, // options + HANDLING_RUN, HANDLING_RUN_LIST, HANDLING_RUN_LIST_ENTRY + }; // run entries struct verb_info_t { @@ -314,7 +317,7 @@ typedef std::list verbs_list_t; static verbs_list_t parseVerbsYAMLFile(gchar const *yaml_filename) { - verbs_list_t verbs_list; + verbs_list_t verbs_list; FILE *fh = fopen(yaml_filename, "r"); if(fh == NULL) { @@ -346,24 +349,39 @@ parseVerbsYAMLFile(gchar const *yaml_filename) yaml_parser_scan(&parser, &token); switch(token.type) { - // avoid "warning: enumeration value", "-Wswitch" - case YAML_NO_TOKEN: break; - case YAML_STREAM_START_TOKEN: break; - case YAML_STREAM_END_TOKEN: break; - case YAML_VERSION_DIRECTIVE_TOKEN: break; - case YAML_TAG_DIRECTIVE_TOKEN: break; - case YAML_DOCUMENT_START_TOKEN: break; - case YAML_DOCUMENT_END_TOKEN: break; - case YAML_FLOW_SEQUENCE_START_TOKEN: break; - case YAML_FLOW_SEQUENCE_END_TOKEN: break; - case YAML_FLOW_MAPPING_START_TOKEN: break; - case YAML_FLOW_MAPPING_END_TOKEN: break; - case YAML_FLOW_ENTRY_TOKEN: break; - case YAML_ALIAS_TOKEN: break; - case YAML_ANCHOR_TOKEN: break; - case YAML_TAG_TOKEN: break; - - /* Token types (read before actual token) */ + // avoid "warning: enumeration value", "-Wswitch" + case YAML_NO_TOKEN: + break; + case YAML_STREAM_START_TOKEN: + break; + case YAML_STREAM_END_TOKEN: + break; + case YAML_VERSION_DIRECTIVE_TOKEN: + break; + case YAML_TAG_DIRECTIVE_TOKEN: + break; + case YAML_DOCUMENT_START_TOKEN: + break; + case YAML_DOCUMENT_END_TOKEN: + break; + case YAML_FLOW_SEQUENCE_START_TOKEN: + break; + case YAML_FLOW_SEQUENCE_END_TOKEN: + break; + case YAML_FLOW_MAPPING_START_TOKEN: + break; + case YAML_FLOW_MAPPING_END_TOKEN: + break; + case YAML_FLOW_ENTRY_TOKEN: + break; + case YAML_ALIAS_TOKEN: + break; + case YAML_ANCHOR_TOKEN: + break; + case YAML_TAG_TOKEN: + break; + + /* Token types (read before actual token) */ case YAML_KEY_TOKEN: handling_key = true; handling_value = false; @@ -373,12 +391,12 @@ parseVerbsYAMLFile(gchar const *yaml_filename) handling_value = true; break; - /* Block delimeters */ + /* Block delimeters */ case YAML_BLOCK_SEQUENCE_START_TOKEN: if( state == HANDLING_ROOT ) { if( key == "run" ) state = HANDLING_RUN; - } + } break; case YAML_BLOCK_ENTRY_TOKEN: if( state == HANDLING_RUN ) @@ -399,7 +417,7 @@ parseVerbsYAMLFile(gchar const *yaml_filename) state = HANDLING_ROOT; break; - /* Data */ + /* Data */ case YAML_BLOCK_MAPPING_START_TOKEN: break; case YAML_SCALAR_TOKEN: @@ -441,7 +459,7 @@ parseVerbsYAMLFile(gchar const *yaml_filename) yaml_parser_delete(&parser); fclose(fh); - return verbs_list; + return verbs_list; } void @@ -454,7 +472,7 @@ CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) int undo_counter = 0; verbs_list_t::iterator iter = verbs_list.begin(); - for (;iter != verbs_list.end(); ++iter) { + for (; iter != verbs_list.end(); ++iter) { verb_info_t &verb = *iter; std::string &verb_word = verb.args[0]; if (s_verbose) @@ -516,7 +534,7 @@ CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename ) printf("bad arguments for XFileExportPNG\n"); continue; } - + xaction_args_values_map_t values_map; std::string &png_filename = verb.args[1]; values_map["png_filename"] = png_filename; -- cgit v1.2.3 From f9a55c6269f20bfe98e1eeb0dd07f5bb3036b7ab Mon Sep 17 00:00:00 2001 From: Dmitry Zhulanov Date: Mon, 3 Oct 2016 22:19:23 +0700 Subject: beautify idents (bzr r15136.1.14) --- src/main-cmdlineact.cpp | 2 -- src/main.cpp | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'src') diff --git a/src/main-cmdlineact.cpp b/src/main-cmdlineact.cpp index fc0f50cd4..f5c6e52eb 100644 --- a/src/main-cmdlineact.cpp +++ b/src/main-cmdlineact.cpp @@ -57,8 +57,6 @@ CmdLineAction::doIt (ActionContext const & context) { //printf("Doing: %s\n", _arg); if (_isVerb) { if (isExtended()) { - //printf("Is extended\n"); - doItX(context); return; } diff --git a/src/main.cpp b/src/main.cpp index 5b7dcc5ef..0d5f35797 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -308,7 +308,7 @@ struct poptOption options[] = { N_("Open specified document(s) (option string may be excluded)"), N_("FILENAME")}, #ifdef WITH_YAML - {"xverbs", 0, + {"xverbs", 0, POPT_ARG_STRING, &sp_xverbs_yaml, SP_ARG_XVERBS, N_("xverbs command"), N_("XVERBS_FILENAME")}, -- cgit v1.2.3 From d43d0384c8f95baa781beaaca79b938e680b727a Mon Sep 17 00:00:00 2001 From: Dmitry Zhulanov Date: Mon, 3 Oct 2016 22:25:41 +0700 Subject: beautify idents (bzr r15136.1.15) --- src/main-cmdlineact.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/main-cmdlineact.cpp b/src/main-cmdlineact.cpp index f5c6e52eb..03bf4083c 100644 --- a/src/main-cmdlineact.cpp +++ b/src/main-cmdlineact.cpp @@ -86,13 +86,12 @@ CmdLineAction::doIt (ActionContext const & context) { bool CmdLineAction::doList (ActionContext const & context) { - bool hasActions = !_list.empty(); - for (std::list::iterator i = _list.begin(); - i != _list.end(); ++i) { + bool hasActions = !_list.empty(); + for (std::list::iterator i = _list.begin(); i != _list.end(); ++i) { CmdLineAction * entry = *i; entry->doIt(context); } - return hasActions; + return hasActions; } bool -- cgit v1.2.3 From e1d0c1cb00f84b66b38af6eec563cf60df7ba726 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 3 Oct 2016 18:08:29 +0200 Subject: Fix a bug on eraser mode when previous clip are shapes not paths (bzr r15145) --- src/ui/tools/eraser-tool.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ui/tools/eraser-tool.cpp b/src/ui/tools/eraser-tool.cpp index 38c72cac0..12686160b 100644 --- a/src/ui/tools/eraser-tool.cpp +++ b/src/ui/tools/eraser-tool.cpp @@ -766,9 +766,17 @@ void EraserTool::set_to_accumulated() { if (bbox && bbox->intersects(*eraserBbox)) { SPClipPath *clip_path = item->clip_ref->getObject(); if (clip_path) { - SPPath *clip_data = SP_PATH(clip_path->firstChild()); + std::vector selected; + selected.push_back(SP_ITEM(clip_path->firstChild())); + std::vector to_select; + std::vector items(selected); + sp_item_list_to_curves(items, selected, to_select); + Inkscape::XML::Node * clip_data = SP_ITEM(clip_path->firstChild())->getRepr(); + if (!clip_data && !to_select.empty()) { + clip_data = *(to_select.begin()); + } if (clip_data) { - Inkscape::XML::Node *dup_clip = SP_OBJECT(clip_data)->getRepr()->duplicate(xml_doc); + Inkscape::XML::Node *dup_clip = clip_data->duplicate(xml_doc); if (dup_clip) { SPItem * dup_clip_obj = SP_ITEM(item_repr->parent->appendChildRepr(dup_clip)); if (dup_clip_obj) { -- cgit v1.2.3 From 67fa2b7c2a26e909b1adb5fb188285367dfba7e4 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 3 Oct 2016 23:35:23 +0200 Subject: Fix merge bugs (bzr r15017.1.36) --- src/live_effects/lpe-measure-line.cpp | 5 +++++ src/widgets/font-selector.cpp | 7 ------- src/widgets/font-selector.h | 24 +----------------------- 3 files changed, 6 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 04085015c..6e77931b0 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -161,6 +161,11 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : LPEMeasureLine::~LPEMeasureLine() {} +void swap(Geom::Point &A, Geom::Point &B){ + Geom::Point tmp = A; + A = B; + B = tmp; +} void LPEMeasureLine::doOnApply(SPLPEItem const* lpeitem) { diff --git a/src/widgets/font-selector.cpp b/src/widgets/font-selector.cpp index e9cf66621..f400de89c 100644 --- a/src/widgets/font-selector.cpp +++ b/src/widgets/font-selector.cpp @@ -19,10 +19,6 @@ #include #endif -#include <2geom/transforms.h> - -#include - #include #include @@ -33,7 +29,6 @@ /* SPFontSelector */ - struct SPFontSelector { GtkBox hbox; @@ -55,7 +50,6 @@ struct SPFontSelector }; - struct SPFontSelectorClass { GtkBoxClass parent_class; @@ -251,7 +245,6 @@ static void sp_font_selector_dispose(GObject *object) if (fsel->fontspec) { delete fsel->fontspec; - fsel->fontspec = 0; } if (fsel->families.length > 0) { diff --git a/src/widgets/font-selector.h b/src/widgets/font-selector.h index e8e0af079..ff5472d2d 100644 --- a/src/widgets/font-selector.h +++ b/src/widgets/font-selector.h @@ -18,29 +18,7 @@ #include -struct SPFontSelector -{ -#if GTK_CHECK_VERSION(3,0,0) - GtkBox hbox; -#else - GtkHBox hbox; -#endif - - unsigned int block_emit : 1; - - GtkWidget *family; - GtkWidget *style; - GtkWidget *size; - - GtkWidget *family_treeview; - GtkWidget *style_treeview; - - NRNameList families; - NRStyleList styles; - gfloat fontsize; - bool fontsize_dirty; - Glib::ustring *fontspec; -}; +struct SPFontSelector; #define SP_TYPE_FONT_SELECTOR (sp_font_selector_get_type ()) #define SP_FONT_SELECTOR(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), SP_TYPE_FONT_SELECTOR, SPFontSelector)) -- cgit v1.2.3 From 5a0f38c94489c344e66b0a4441668ea02e3361d8 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 4 Oct 2016 17:32:38 +0200 Subject: Fix scaling bug (bzr r15017.1.37) --- src/live_effects/lpe-measure-line.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 6e77931b0..57e67ab3a 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -541,6 +541,9 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) SPPath *sp_path = dynamic_cast(splpeitem); if (sp_path) { Geom::PathVector pathvector = sp_path->get_original_curve()->get_pathvector(); + SPDocument * doc = SP_ACTIVE_DOCUMENT; + Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(doc->getRoot())); + pathvector *= affinetransform; if (arrows_outside) { createArrowMarker((Glib::ustring)"ArrowDINout-start"); createArrowMarker((Glib::ustring)"ArrowDINout-end"); @@ -618,9 +621,8 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } else { pos = pos - Point::polar(angle_cross, (position + text_top_bottom) - fontsize/2.5); } - if (!scale_insensitive) { - Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); - length *= (affinetransform.expansionX() + affinetransform.expansionY()) / 2.0; + if (scale_insensitive) { + length *= (affinetransform.inverse().expansionX() + affinetransform.inverse().expansionY()) / 2.0; } createTextLabel(pos, length, angle, remove); bool overflow = false; -- cgit v1.2.3 From 98f6a39975eef4b0d711e13b6743e494347d8ae0 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 5 Oct 2016 00:08:23 +0200 Subject: add lock (bzr r15017.1.39) --- src/live_effects/lpe-measure-line.cpp | 62 +++++++++++++++-------------------- src/live_effects/lpe-measure-line.h | 2 +- 2 files changed, 28 insertions(+), 36 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 4780fb817..434dc484c 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -67,7 +67,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : line_group_05(_("Line Group 0.5*"), _("Line Group 0.5, from 0.7"), "line_group_05", &wr, this, true), rotate_anotation(_("Rotate Anotation*"), _("Rotate Anotation"), "rotate_anotation", &wr, this, true), hide_back(_("Hide if label over*"), _("Hide DIN line if label over"), "hide_back", &wr, this, true), - lock_measure(_("Lock measure data"), _("Lock measure data to avoid problems on transforms"), "lock_measure", &wr, this, true), + unlock_measure(_("Unlock measure data"), _("Unlock measure data maybe give problems on transforms"), "unlock_measure", &wr, this, false), dimline_format(_("CSS DIN line*"), _("Override CSS to DIN line, return to save, empty to reset to DIM"), "dimline_format", &wr, this,""), helperlines_format(_("CSS helpers*"), _("Override CSS to helper lines, return to save, empty to reset to DIM"), "helperlines_format", &wr, this,""), anotation_format(_("CSS anotation*"), _("Override CSS to anotation text, return to save, empty to reset to DIM"), "anotation_format", &wr, this,""), @@ -93,7 +93,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : registerParameter(&line_group_05); registerParameter(&rotate_anotation); registerParameter(&hide_back); - registerParameter(&lock_measure); + registerParameter(&unlock_measure); registerParameter(&dimline_format); registerParameter(&helperlines_format); registerParameter(&anotation_format); @@ -256,10 +256,10 @@ LPEMeasureLine::createArrowMarker(Glib::ustring mode) arrow->setAttribute("refX", "0.0"); arrow->setAttribute("refY", "0.0"); arrow->setAttribute("style", "overflow:visible"); - if (lock_measure) { - arrow->setAttribute("sodipodi:insensitive", "true"); - } else { + if (unlock_measure) { arrow->setAttribute("sodipodi:insensitive", NULL); + } else { + arrow->setAttribute("sodipodi:insensitive", "true"); } /* Create */ Inkscape::XML::Node *arrow_path = xml_doc->createElement("svg:path"); @@ -288,10 +288,10 @@ LPEMeasureLine::createArrowMarker(Glib::ustring mode) } else { Inkscape::XML::Node *arrow= elemref->getRepr(); if (arrow) { - if (lock_measure) { - arrow->setAttribute("sodipodi:insensitive", "true"); - } else { + if (unlock_measure) { arrow->setAttribute("sodipodi:insensitive", NULL); + } else { + arrow->setAttribute("sodipodi:insensitive", "true"); } Inkscape::XML::Node *arrow_data = arrow->firstChild(); if (arrow_data) { @@ -339,16 +339,14 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl elemref->deleteObject(); return; } -// Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(elemref)->parent, SP_OBJECT(desktop->doc()->getRoot())); -// pos *= affinetransform; pos = pos - Point::polar(angle, text_right_left); rtext = elemref->getRepr(); sp_repr_set_svg_double(rtext, "x", pos[Geom::X]); sp_repr_set_svg_double(rtext, "y", pos[Geom::Y]); - if (lock_measure) { - rtext->setAttribute("sodipodi:insensitive", "true"); - } else { + if (unlock_measure) { rtext->setAttribute("sodipodi:insensitive", NULL); + } else { + rtext->setAttribute("sodipodi:insensitive", "true"); } } else { if (remove) { @@ -357,10 +355,10 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl rtext = xml_doc->createElement("svg:text"); rtext->setAttribute("xml:space", "preserve"); rtext->setAttribute("id", ( (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); - if (lock_measure) { - rtext->setAttribute("sodipodi:insensitive", "true"); - } else { + if (unlock_measure) { rtext->setAttribute("sodipodi:insensitive", NULL); + } else { + rtext->setAttribute("sodipodi:insensitive", "true"); } pos = pos - Point::polar(angle, text_right_left); sp_repr_set_svg_double(rtext, "x", pos[Geom::X]); @@ -477,11 +475,7 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, end = end + Point::polar(angle, helpline_overlap ); } Geom::PathVector line_pathv; - SPDocument * doc = SP_ACTIVE_DOCUMENT; - Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(sp_lpe_item)->parent, SP_OBJECT(doc->getRoot())); - double parents_scale = (affinetransform.inverse().expansionX() + affinetransform.inverse().expansionY()) / 2.0; - double current_text_top_bottom = text_top_bottom / parents_scale; - if (main && std::abs(current_text_top_bottom) < fontsize/1.5 && hide_back && !overflow){ + if (main && std::abs(text_top_bottom) < fontsize/1.5 && hide_back && !overflow){ Geom::Path line_path; double k = 0; if (flip_side) { @@ -526,10 +520,10 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, gchar * line_str = sp_svg_write_path( line_pathv ); line->setAttribute("d" , line_str); } - if (lock_measure) { - line->setAttribute("sodipodi:insensitive", "true"); - } else { + if (unlock_measure) { line->setAttribute("sodipodi:insensitive", NULL); + } else { + line->setAttribute("sodipodi:insensitive", "true"); } line_pathv.clear(); @@ -583,8 +577,6 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) SPDocument * doc = SP_ACTIVE_DOCUMENT; Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem)->parent, SP_OBJECT(doc->getRoot())); double parents_scale = (affinetransform.inverse().expansionX() + affinetransform.inverse().expansionY()) / 2.0; - double current_text_top_bottom = text_top_bottom / parents_scale; - double current_position = position / parents_scale; Geom::PathVector pathvector = sp_path->get_original_curve()->get_pathvector(); pathvector *= affinetransform; @@ -661,9 +653,9 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) angle = std::fmod(angle, 2*M_PI); if (angle < 0) angle += 2*M_PI; if (angle >= rad_from_deg(90) && angle < rad_from_deg(270)) { - pos = pos - Point::polar(angle_cross, (current_position - current_text_top_bottom) + fontsize/2.5); + pos = pos - Point::polar(angle_cross, (position - text_top_bottom) + fontsize/2.5); } else { - pos = pos - Point::polar(angle_cross, (current_position + current_text_top_bottom) - fontsize/2.5); + pos = pos - Point::polar(angle_cross, (position + text_top_bottom) - fontsize/2.5); } if (scale_insensitive) { length *= parents_scale; @@ -671,14 +663,14 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) createTextLabel(pos, length, angle, remove); bool overflow = false; if ((anotation_width/2) + std::abs(text_right_left) > Geom::distance(start,end)/2.0) { - Geom::Point sstart = end - Point::polar(angle_cross, current_position); - Geom::Point send = end - Point::polar(angle_cross, current_position); + Geom::Point sstart = end - Point::polar(angle_cross, position); + Geom::Point send = end - Point::polar(angle_cross, position); if (text_right_left < 0 && flip_side || text_right_left > 0 && !flip_side) { - sstart = start - Point::polar(angle_cross, current_position); - send = start - Point::polar(angle_cross, current_position); + sstart = start - Point::polar(angle_cross, position); + send = start - Point::polar(angle_cross, position); } Geom::Point prog_end = Geom::Point(); - if (std::abs(current_text_top_bottom) < fontsize/1.5 && hide_back) { + if (std::abs(text_top_bottom) < fontsize/1.5 && hide_back) { if (text_right_left > 0 ) { prog_end = sstart - Point::polar(angle, std::abs(text_right_left) - (anotation_width/1.9) - (Geom::distance(start,end)/2.0)); } else { @@ -713,10 +705,10 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) if (flip_side) { arrow_gap *= -1; } - hstart = hstart - Point::polar(angle_cross, current_position); + hstart = hstart - Point::polar(angle_cross, position); Glib::ustring id = (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id"); createLine(start, hstart, id, false, false, remove); - hend = hend - Point::polar(angle_cross, current_position); + hend = hend - Point::polar(angle_cross, position); id = (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id"); createLine(end, hend, id, false, false, remove); if (!arrows_outside) { diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 83fef26b8..999d53af0 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -67,7 +67,7 @@ private: BoolParam line_group_05; BoolParam rotate_anotation; BoolParam hide_back; - BoolParam lock_measure; + BoolParam unlock_measure; TextParam dimline_format; TextParam helperlines_format; TextParam anotation_format; -- cgit v1.2.3 From 124c2b96d76984dd9fe7a4db0f9b8738ea3ba657 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 5 Oct 2016 18:51:40 +0200 Subject: add button to release measures (bzr r15017.1.40) --- src/live_effects/lpe-measure-line.cpp | 85 +++++++++++++++++++++++------------ src/live_effects/lpe-measure-line.h | 3 +- src/live_effects/lpeobject.h | 10 ++++- 3 files changed, 67 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 434dc484c..e8ceb7e51 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -10,6 +10,7 @@ */ #include "live_effects/lpe-measure-line.h" #include +#include "ui/dialog/livepatheffect-editor.h" #include #include "inkscape.h" #include "xml/node.h" @@ -21,7 +22,7 @@ #include "svg/svg-color.h" #include "svg/svg.h" #include "display/curve.h" -#include <2geom/affine.h> +#include "2geom/affine.h" #include "style.h" #include "sp-root.h" #include "sp-defs.h" @@ -67,7 +68,6 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : line_group_05(_("Line Group 0.5*"), _("Line Group 0.5, from 0.7"), "line_group_05", &wr, this, true), rotate_anotation(_("Rotate Anotation*"), _("Rotate Anotation"), "rotate_anotation", &wr, this, true), hide_back(_("Hide if label over*"), _("Hide DIN line if label over"), "hide_back", &wr, this, true), - unlock_measure(_("Unlock measure data"), _("Unlock measure data maybe give problems on transforms"), "unlock_measure", &wr, this, false), dimline_format(_("CSS DIN line*"), _("Override CSS to DIN line, return to save, empty to reset to DIM"), "dimline_format", &wr, this,""), helperlines_format(_("CSS helpers*"), _("Override CSS to helper lines, return to save, empty to reset to DIM"), "helperlines_format", &wr, this,""), anotation_format(_("CSS anotation*"), _("Override CSS to anotation text, return to save, empty to reset to DIM"), "anotation_format", &wr, this,""), @@ -93,7 +93,6 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : registerParameter(&line_group_05); registerParameter(&rotate_anotation); registerParameter(&hide_back); - registerParameter(&unlock_measure); registerParameter(&dimline_format); registerParameter(&helperlines_format); registerParameter(&anotation_format); @@ -159,6 +158,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : helpline_overlap.param_set_range(-999999.0, 999999.0); helpline_overlap.param_set_increments(1, 1); helpline_overlap.param_set_digits(2); + erase = true; } LPEMeasureLine::~LPEMeasureLine() {} @@ -256,11 +256,7 @@ LPEMeasureLine::createArrowMarker(Glib::ustring mode) arrow->setAttribute("refX", "0.0"); arrow->setAttribute("refY", "0.0"); arrow->setAttribute("style", "overflow:visible"); - if (unlock_measure) { - arrow->setAttribute("sodipodi:insensitive", NULL); - } else { - arrow->setAttribute("sodipodi:insensitive", "true"); - } + arrow->setAttribute("sodipodi:insensitive", "true"); /* Create */ Inkscape::XML::Node *arrow_path = xml_doc->createElement("svg:path"); if (mode == (Glib::ustring)"ArrowDIN-start") { @@ -288,11 +284,7 @@ LPEMeasureLine::createArrowMarker(Glib::ustring mode) } else { Inkscape::XML::Node *arrow= elemref->getRepr(); if (arrow) { - if (unlock_measure) { - arrow->setAttribute("sodipodi:insensitive", NULL); - } else { - arrow->setAttribute("sodipodi:insensitive", "true"); - } + arrow->setAttribute("sodipodi:insensitive", "true"); Inkscape::XML::Node *arrow_data = arrow->firstChild(); if (arrow_data) { SPCSSAttr *css = sp_repr_css_attr_new(); @@ -343,11 +335,7 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl rtext = elemref->getRepr(); sp_repr_set_svg_double(rtext, "x", pos[Geom::X]); sp_repr_set_svg_double(rtext, "y", pos[Geom::Y]); - if (unlock_measure) { - rtext->setAttribute("sodipodi:insensitive", NULL); - } else { - rtext->setAttribute("sodipodi:insensitive", "true"); - } + rtext->setAttribute("sodipodi:insensitive", "true"); } else { if (remove) { return; @@ -355,11 +343,7 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl rtext = xml_doc->createElement("svg:text"); rtext->setAttribute("xml:space", "preserve"); rtext->setAttribute("id", ( (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); - if (unlock_measure) { - rtext->setAttribute("sodipodi:insensitive", NULL); - } else { - rtext->setAttribute("sodipodi:insensitive", "true"); - } + rtext->setAttribute("sodipodi:insensitive", "true"); pos = pos - Point::polar(angle, text_right_left); sp_repr_set_svg_double(rtext, "x", pos[Geom::X]); sp_repr_set_svg_double(rtext, "y", pos[Geom::Y]); @@ -520,11 +504,7 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, gchar * line_str = sp_svg_write_path( line_pathv ); line->setAttribute("d" , line_str); } - if (unlock_measure) { - line->setAttribute("sodipodi:insensitive", NULL); - } else { - line->setAttribute("sodipodi:insensitive", "true"); - } + line->setAttribute("sodipodi:insensitive", "true"); line_pathv.clear(); Glib::ustring style = (Glib::ustring)"stroke:#000000;fill:none;"; @@ -723,6 +703,8 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) void LPEMeasureLine::doOnRemove (SPLPEItem const* lpeitem) { + if (!erase) return; + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); @@ -754,6 +736,48 @@ void LPEMeasureLine::doOnRemove (SPLPEItem const* lpeitem) } } +void LPEMeasureLine::toObjects() +{ + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { + + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + if (elemref = SVGElemRef->getObject()) { + elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); + } + Inkscape::URI SVGElem_uri2(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + SVGElemRef->attach(SVGElem_uri2); + if (elemref = SVGElemRef->getObject()) { + elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); + } + Inkscape::URI SVGElem_uri3(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + SVGElemRef->attach(SVGElem_uri3); + if (elemref = SVGElemRef->getObject()) { + elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); + } + Inkscape::URI SVGElem_uri4(((Glib::ustring)"#" + (Glib::ustring)"infoline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + SVGElemRef->attach(SVGElem_uri4); + if (elemref = SVGElemRef->getObject()) { + elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); + } + Inkscape::URI SVGElem_uri5(((Glib::ustring)"#" + (Glib::ustring)"downline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + SVGElemRef->attach(SVGElem_uri5); + if (elemref = SVGElemRef->getObject()) { + elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); + } + erase = false; + sp_lpe_item->removeCurrentPathEffect(true); + //TODO: find better way to refresh effect list + if (SP_IS_OBJECT(sp_lpe_item)){ + Inkscape::Selection *selection = SP_ACTIVE_DESKTOP->getSelection(); + selection->remove(SP_OBJECT(sp_lpe_item)); + selection->add(SP_OBJECT(sp_lpe_item)); + } + } +} + Gtk::Widget *LPEMeasureLine::newWidget() { // use manage here, because after deletion of Effect object, others might @@ -766,6 +790,7 @@ Gtk::Widget *LPEMeasureLine::newWidget() std::vector::iterator it = param_vector.begin(); Gtk::HBox * button1 = Gtk::manage(new Gtk::HBox(true,0)); + Gtk::HBox * button2 = Gtk::manage(new Gtk::HBox(true,0)); Gtk::VBox * vbox_expander = Gtk::manage( new Gtk::VBox(Effect::newWidget()) ); vbox_expander->set_border_width(0); vbox_expander->set_spacing(2); @@ -797,12 +822,16 @@ Gtk::Widget *LPEMeasureLine::newWidget() Gtk::Button *save_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Save '*' as default")))); save_default->signal_clicked().connect(sigc::mem_fun(*this, &LPEMeasureLine::saveDefault)); button1->pack_start(*save_default, true, true, 2); + Gtk::Button *remove = Gtk::manage(new Gtk::Button(Glib::ustring(_("Convert to objects")))); + remove->signal_clicked().connect(sigc::mem_fun(*this, &LPEMeasureLine::toObjects)); + button2->pack_start(*remove, true, true, 2); expander = Gtk::manage(new Gtk::Expander(Glib::ustring(_("Show DIM CSS style override")))); expander->add(*vbox_expander); expander->set_expanded(expanded); expander->property_expanded().signal_changed().connect(sigc::mem_fun(*this, &LPEMeasureLine::onExpanderChanged) ); vbox->pack_start(*expander, true, true, 2); vbox->pack_start(*button1, true, true, 2); + vbox->pack_start(*button2, true, true, 2); return dynamic_cast(vbox); } diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 999d53af0..2fab9dbb9 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -44,6 +44,7 @@ public: void createLine(Geom::Point start,Geom::Point end,Glib::ustring id, bool main, bool overflow, bool remove, bool arrows = false); void createTextLabel(Geom::Point pos, double length, Geom::Coord angle, bool remove); void onExpanderChanged(); + void toObjects(); void createArrowMarker(Glib::ustring mode); void saveDefault(); virtual Gtk::Widget *newWidget(); @@ -67,7 +68,6 @@ private: BoolParam line_group_05; BoolParam rotate_anotation; BoolParam hide_back; - BoolParam unlock_measure; TextParam dimline_format; TextParam helperlines_format; TextParam anotation_format; @@ -79,6 +79,7 @@ private: double fontsize; double anotation_width; double arrow_gap; + bool erase; /* Geom::Affine affine_over;*/ LPEMeasureLine(const LPEMeasureLine &); LPEMeasureLine &operator=(const LPEMeasureLine &); diff --git a/src/live_effects/lpeobject.h b/src/live_effects/lpeobject.h index 2e62707e3..087223947 100644 --- a/src/live_effects/lpeobject.h +++ b/src/live_effects/lpeobject.h @@ -38,8 +38,14 @@ public: /* Note that the returned pointer can be NULL in a valid LivePathEffectObject contained in a valid list of lpeobjects in an lpeitem! * So one should always check whether the returned value is NULL or not */ - Inkscape::LivePathEffect::Effect * get_lpe() { return lpe; }; - Inkscape::LivePathEffect::Effect const * get_lpe() const { return lpe; }; + Inkscape::LivePathEffect::Effect * get_lpe() { + if(this) return lpe; + else return NULL; + } + Inkscape::LivePathEffect::Effect const * get_lpe() const { + if(this) return lpe; + else return NULL; + }; Inkscape::LivePathEffect::Effect *lpe; // this can be NULL in a valid LivePathEffectObject -- cgit v1.2.3 From b1d8ece63b0bdfcc2595a97af9e69147c2d37a37 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 6 Oct 2016 19:50:17 +0200 Subject: Fix on delete line (bzr r15017.1.41) --- src/sp-lpe-item.cpp | 7 +++++-- src/sp-object.cpp | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/sp-lpe-item.cpp b/src/sp-lpe-item.cpp index d83593b31..936594679 100644 --- a/src/sp-lpe-item.cpp +++ b/src/sp-lpe-item.cpp @@ -73,6 +73,7 @@ void SPLPEItem::build(SPDocument *document, Inkscape::XML::Node *repr) { void SPLPEItem::release() { // disconnect all modified listeners: + for (std::list::iterator mod_it = this->lpe_modified_connection_list->begin(); mod_it != this->lpe_modified_connection_list->end(); ++mod_it) { @@ -83,7 +84,7 @@ void SPLPEItem::release() { this->lpe_modified_connection_list = NULL; PathEffectList::iterator it = this->path_effect_list->begin(); - + while ( it != this->path_effect_list->end() ) { // unlink and delete all references in the list (*it)->unlink(); @@ -121,8 +122,10 @@ void SPLPEItem::set(unsigned int key, gchar const* value) { while ( it != this->path_effect_list->end() ) { + LivePathEffectObject *lpeobj = (*it)->lpeobject; + lpeobj->get_lpe()->doOnRemove(this); (*it)->unlink(); - delete *it; + delete (*it); it = this->path_effect_list->erase(it); } diff --git a/src/sp-object.cpp b/src/sp-object.cpp index da4367d5b..cbd7aa969 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -485,13 +485,16 @@ void SPObject::_sendDeleteSignalRecursive() { void SPObject::deleteObject(bool propagate, bool propagate_descendants) { sp_object_ref(this, NULL); + if ( SP_IS_LPE_ITEM(this) ) { + SP_LPE_ITEM(this)->removeAllPathEffects(false); + } if (propagate) { _delete_signal.emit(this); } if (propagate_descendants) { this->_sendDeleteSignalRecursive(); } - + Inkscape::XML::Node *repr = getRepr(); if (repr && repr->parent()) { sp_repr_unparent(repr); -- cgit v1.2.3 From eb4b3b8d4823f7a9cef4e623080e3d1e4b7426eb Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 7 Oct 2016 20:03:23 +0200 Subject: Fix bug:1630821 on LPE selected nodes Fixed bugs: - https://launchpad.net/bugs/1630821 (bzr r15149) --- src/ui/tools/node-tool.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/ui/tools/node-tool.cpp b/src/ui/tools/node-tool.cpp index 2bd4fdea3..f3679b40f 100644 --- a/src/ui/tools/node-tool.cpp +++ b/src/ui/tools/node-tool.cpp @@ -285,13 +285,11 @@ void NodeTool::update_helperpath () { if (SP_IS_LPE_ITEM(selection->singleItem())) { Inkscape::LivePathEffect::Effect *lpe = SP_LPE_ITEM(selection->singleItem())->getCurrentLPE(); if (lpe && lpe->isVisible()/* && lpe->showOrigPath()*/) { - Inkscape::UI::ControlPointSelection::Set &selectionNodes = _selected_nodes->allPoints(); + Inkscape::UI::ControlPointSelection *selectionNodes = _selected_nodes; std::vector selectedNodesPositions; - for (Inkscape::UI::ControlPointSelection::Set::iterator i = selectionNodes.begin(); i != selectionNodes.end(); ++i) { - if ((*i)->selected()) { - Inkscape::UI::Node *n = dynamic_cast(*i); - selectedNodesPositions.push_back(n->position()); - } + for (Inkscape::UI::ControlPointSelection::iterator i = selectionNodes->begin(); i != selectionNodes->end(); ++i) { + Inkscape::UI::Node *n = dynamic_cast(*i); + selectedNodesPositions.push_back(n->position()); } lpe->setSelectedNodePoints(selectedNodesPositions); lpe->setCurrentZoom(this->desktop->current_zoom()); @@ -470,6 +468,7 @@ bool NodeTool::root_handler(GdkEvent* event) { switch (event->type) { case GDK_MOTION_NOTIFY: { + update_helperpath(); combine_motion_events(desktop->canvas, event->motion, 0); SPItem *over_item = sp_event_context_find_item (desktop, event_point(event->button), FALSE, TRUE); -- cgit v1.2.3 From 60688fe72a9a75ac54d895a7aa61d3a0518ca8ab Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 7 Oct 2016 20:48:31 +0200 Subject: Fix bug:1630796 on flatten button Fixed bugs: - https://launchpad.net/bugs/1630796 (bzr r15150) --- src/ui/dialog/livepatheffect-editor.h | 5 ++--- src/widgets/pencil-toolbar.cpp | 6 +++++- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/livepatheffect-editor.h b/src/ui/dialog/livepatheffect-editor.h index 489e9564d..8e9e66435 100644 --- a/src/ui/dialog/livepatheffect-editor.h +++ b/src/ui/dialog/livepatheffect-editor.h @@ -49,6 +49,8 @@ public: void onSelectionModified(Inkscape::Selection *sel); virtual void on_effect_selection_changed(); void setDesktop(SPDesktop *desktop); + // void add_entry(const char* name ); + void effect_list_reload(SPLPEItem *lpeitem); private: @@ -70,9 +72,6 @@ private: void showText(Glib::ustring const &str); void selectInList(LivePathEffect::Effect* effect); - // void add_entry(const char* name ); - void effect_list_reload(SPLPEItem *lpeitem); - // callback methods for buttons on grids page. void onAdd(); void onRemove(); diff --git a/src/widgets/pencil-toolbar.cpp b/src/widgets/pencil-toolbar.cpp index 582fb66ba..b177c42b4 100644 --- a/src/widgets/pencil-toolbar.cpp +++ b/src/widgets/pencil-toolbar.cpp @@ -50,6 +50,7 @@ #include "live_effects/lpe-powerstroke.h" #include "live_effects/lpeobject.h" #include "live_effects/lpeobject-reference.h" +#include "ui/dialog/livepatheffect-editor.h" using Inkscape::UI::UXManager; using Inkscape::UI::ToolboxFactory; @@ -242,7 +243,7 @@ static void sp_simplify_flatten(GtkWidget * /*widget*/, GObject *obj) SPLPEItem* lpeitem = dynamic_cast(*it); if (lpeitem && lpeitem->hasPathEffect()){ PathEffectList lpelist = lpeitem->getEffectList(); - std::list::iterator i; + PathEffectList::iterator i; for (i = lpelist.begin(); i != lpelist.end(); ++i) { LivePathEffectObject *lpeobj = (*i)->lpeobject; if (lpeobj) { @@ -260,7 +261,10 @@ static void sp_simplify_flatten(GtkWidget * /*widget*/, GObject *obj) lpeitem->removeCurrentPathEffect(false); shape->setCurve(c,0); } + Inkscape::UI::Dialog::LivePathEffectEditor *lpeeditor = new Inkscape::UI::Dialog::LivePathEffectEditor(); + lpeeditor->effect_list_reload(lpeitem); break; + } } } -- cgit v1.2.3 From 4265fc5086c2a7467de2b8d1c26efac1412a5089 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 7 Oct 2016 22:58:19 +0200 Subject: Fix bug:1605334 FeImage X and Y position Fixed bugs: - https://launchpad.net/bugs/1605334 (bzr r15151) --- src/ui/dialog/filter-effects-dialog.cpp | 46 ++++++++++++++++++++++++++++++++- src/ui/dialog/filter-effects-dialog.h | 8 ++++++ 2 files changed, 53 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ui/dialog/filter-effects-dialog.cpp b/src/ui/dialog/filter-effects-dialog.cpp index a0cd786dc..f657e1b76 100644 --- a/src/ui/dialog/filter-effects-dialog.cpp +++ b/src/ui/dialog/filter-effects-dialog.cpp @@ -860,6 +860,17 @@ public: return dss; } + // SpinButton + SpinButtonAttr* add_spinbutton(double defalt_value, const SPAttributeEnum attr, const Glib::ustring& label, + const double lo, const double hi, const double step_inc, + const double climb, const int digits, char* tip = NULL) + { + SpinButtonAttr* sb = new SpinButtonAttr(lo, hi, step_inc, climb, digits, attr, defalt_value, tip); + add_widget(sb, label); + add_attr_widget(sb); + return sb; + } + // DualSpinButton DualSpinButton* add_dualspinbutton(char* defalt_value, const SPAttributeEnum attr, const Glib::ustring& label, const double lo, const double hi, const double step_inc, @@ -2785,8 +2796,14 @@ void FilterEffectsDialog::init_settings_widgets() _settings->type(NR_FILTER_IMAGE); _settings->add_fileorelement(SP_ATTR_XLINK_HREF, _("Source of Image:")); - + _image_x = _settings->add_entry(SP_ATTR_X,_("X"),_("X")); + _image_x->signal_attr_changed().connect(sigc::mem_fun(*this, &FilterEffectsDialog::image_x_changed)); + //This commented because we want the default empty value of X or Y and couldent get it from SpinButton + //_image_y = _settings->add_spinbutton(0, SP_ATTR_Y, _("Y:"), -DBL_MAX, DBL_MAX, 1, 1, 5, _("Y")); + _image_y = _settings->add_entry(SP_ATTR_Y,_("Y"),_("Y")); + _image_y->signal_attr_changed().connect(sigc::mem_fun(*this, &FilterEffectsDialog::image_y_changed)); _settings->type(NR_FILTER_OFFSET); + _settings->add_checkbutton(false, SP_ATTR_PRESERVEALPHA, _("Preserve Alpha"), "true", "false", _("If set, the alpha channel won't be altered by this filter primitive.")); _settings->add_spinscale(0, SP_ATTR_DX, _("Delta X:"), -100, 100, 1, 0.01, 1, _("This is how far the input image gets shifted to the right")); _settings->add_spinscale(0, SP_ATTR_DY, _("Delta Y:"), -100, 100, 1, 0.01, 1, _("This is how far the input image gets shifted downwards")); @@ -2926,6 +2943,33 @@ void FilterEffectsDialog::convolve_order_changed() _convolve_target->get_spinbuttons()[1]->get_adjustment()->set_upper(_convolve_order->get_spinbutton2().get_value() - 1); } +bool number_or_empy(const Glib::ustring& text) { + if (text.empty()) { + return true; + } + double n = atof( text.c_str() ); + if (n == 0.0 && strcmp(text.c_str(), "0") != 0 && strcmp(text.c_str(), "0.0") != 0) { + return false; + } + else { + return true; + } +} + +void FilterEffectsDialog::image_x_changed() +{ + if (number_or_empy(_image_x->get_text())) { + _image_x->set_from_attribute(_primitive_list.get_selected()); + } +} + +void FilterEffectsDialog::image_y_changed() +{ + if (number_or_empy(_image_y->get_text())) { + _image_y->set_from_attribute(_primitive_list.get_selected()); + } +} + void FilterEffectsDialog::set_attr_direct(const AttrWidget* input) { set_attr(_primitive_list.get_selected(), input->get_attribute(), input->get_as_attribute().c_str()); diff --git a/src/ui/dialog/filter-effects-dialog.h b/src/ui/dialog/filter-effects-dialog.h index eae0fc317..32fabb741 100644 --- a/src/ui/dialog/filter-effects-dialog.h +++ b/src/ui/dialog/filter-effects-dialog.h @@ -35,6 +35,8 @@ namespace Inkscape { namespace UI { namespace Dialog { +class EntryAttr; +//class SpinButtonAttr; class DualSpinButton; class MultiSpinButton; class FilterEffectsDialog : public UI::Widget::Panel { @@ -258,6 +260,8 @@ private: void remove_primitive(); void duplicate_primitive(); void convolve_order_changed(); + void image_x_changed(); + void image_y_changed(); void set_attr_direct(const UI::Widget::AttrWidget*); void set_child_attr_direct(const UI::Widget::AttrWidget*); @@ -308,6 +312,10 @@ private: DualSpinButton* _convolve_order; MultiSpinButton* _convolve_target; + // Image + EntryAttr* _image_x; + EntryAttr* _image_y; + // For controlling setting sensitivity Gtk::Widget* _k1, *_k2, *_k3, *_k4; -- cgit v1.2.3 From 3fb11a7eb8d066e2b16bddb98de9b4c03e28ba56 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 8 Oct 2016 01:46:38 +0200 Subject: Fix bug:1630796 on flatten button. Attemp 2 Fixed bugs: - https://launchpad.net/bugs/1630796 (bzr r15152) --- src/ui/dialog/livepatheffect-editor.h | 5 +++-- src/widgets/pencil-toolbar.cpp | 10 ++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/livepatheffect-editor.h b/src/ui/dialog/livepatheffect-editor.h index 8e9e66435..a7c749ef3 100644 --- a/src/ui/dialog/livepatheffect-editor.h +++ b/src/ui/dialog/livepatheffect-editor.h @@ -49,8 +49,6 @@ public: void onSelectionModified(Inkscape::Selection *sel); virtual void on_effect_selection_changed(); void setDesktop(SPDesktop *desktop); - // void add_entry(const char* name ); - void effect_list_reload(SPLPEItem *lpeitem); private: @@ -66,6 +64,9 @@ private: sigc::connection selection_changed_connection; sigc::connection selection_modified_connection; + // void add_entry(const char* name ); + void effect_list_reload(SPLPEItem *lpeitem); + void set_sensitize_all(bool sensitive); void showParams(LivePathEffect::Effect& effect); diff --git a/src/widgets/pencil-toolbar.cpp b/src/widgets/pencil-toolbar.cpp index b177c42b4..c3a2ab946 100644 --- a/src/widgets/pencil-toolbar.cpp +++ b/src/widgets/pencil-toolbar.cpp @@ -239,8 +239,9 @@ static void sp_simplify_flatten(GtkWidget * /*widget*/, GObject *obj) { SPDesktop *desktop = static_cast(g_object_get_data(obj, "desktop")); auto selected = desktop->getSelection()->items(); + SPLPEItem* lpeitem = NULL; for (auto it(selected.begin()); it != selected.end(); ++it){ - SPLPEItem* lpeitem = dynamic_cast(*it); + lpeitem = dynamic_cast(*it); if (lpeitem && lpeitem->hasPathEffect()){ PathEffectList lpelist = lpeitem->getEffectList(); PathEffectList::iterator i; @@ -261,16 +262,17 @@ static void sp_simplify_flatten(GtkWidget * /*widget*/, GObject *obj) lpeitem->removeCurrentPathEffect(false); shape->setCurve(c,0); } - Inkscape::UI::Dialog::LivePathEffectEditor *lpeeditor = new Inkscape::UI::Dialog::LivePathEffectEditor(); - lpeeditor->effect_list_reload(lpeitem); break; - } } } } } } + if (lpeitem) { + desktop->getSelection()->remove(lpeitem->getRepr()); + desktop->getSelection()->add(lpeitem->getRepr()); + } } static void sp_pencil_tb_tolerance_value_changed(GtkAdjustment *adj, GObject *tbl) -- cgit v1.2.3 From be44e8e6202cd88cfb5b8d7e8938ae9734d27f1c Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 8 Oct 2016 01:49:29 +0200 Subject: Remove unnecesary header from last push (bzr r15153) --- src/widgets/pencil-toolbar.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/widgets/pencil-toolbar.cpp b/src/widgets/pencil-toolbar.cpp index c3a2ab946..96733cb22 100644 --- a/src/widgets/pencil-toolbar.cpp +++ b/src/widgets/pencil-toolbar.cpp @@ -50,7 +50,6 @@ #include "live_effects/lpe-powerstroke.h" #include "live_effects/lpeobject.h" #include "live_effects/lpeobject-reference.h" -#include "ui/dialog/livepatheffect-editor.h" using Inkscape::UI::UXManager; using Inkscape::UI::ToolboxFactory; -- cgit v1.2.3 From e64d416e42f8361036d9a31dff5b646810f69e97 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 8 Oct 2016 02:03:08 +0200 Subject: Fix bug:1622321 on powerstroke Fixed bugs: - https://launchpad.net/bugs/1622321 (bzr r15154) --- src/live_effects/lpe-powerstroke.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/live_effects/lpe-powerstroke.cpp b/src/live_effects/lpe-powerstroke.cpp index 0de668847..329a00756 100644 --- a/src/live_effects/lpe-powerstroke.cpp +++ b/src/live_effects/lpe-powerstroke.cpp @@ -609,11 +609,12 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in) // find time values for which x lies outside path domain // and only take portion of x and y that lies within those time values std::vector< double > rtsmin = roots (x - pwd2_in.domain().min()); - std::vector< double > rtsmax = roots (x - pwd2_in.domain().max()); + std::vector< double > rtsmax = roots (x + pwd2_in.domain().max()); if ( !rtsmin.empty() && !rtsmax.empty() ) { x = portion(x, rtsmin.at(0), rtsmax.at(0)); y = portion(y, rtsmin.at(0), rtsmax.at(0)); } + LineJoinType jointype = static_cast(linejoin_type.get_value()); Piecewise > pwd2_out = compose(pwd2_in,x) + y*compose(n,x); -- cgit v1.2.3 From 7be3086bf70ba9bf28c5cfe06fd7a8e28e719bcc Mon Sep 17 00:00:00 2001 From: sandra-snan Date: Sat, 8 Oct 2016 08:16:53 +0200 Subject: [Bug #770681] KEY MAPPING: Comma and period hijacked by scaling. Fixed bugs: - https://launchpad.net/bugs/770681 (bzr r15155) --- src/ui/tools/select-tool.cpp | 32 +----------------------------- src/verbs.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++ src/verbs.h | 6 ++++++ 3 files changed, 53 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/ui/tools/select-tool.cpp b/src/ui/tools/select-tool.cpp index 86a2dbed3..0cdeda0b6 100644 --- a/src/ui/tools/select-tool.cpp +++ b/src/ui/tools/select-tool.cpp @@ -1045,37 +1045,7 @@ bool SelectTool::root_handler(GdkEvent* event) { ret = TRUE; break; - - case GDK_KEY_less: - case GDK_KEY_comma: - if (MOD__ALT(event)) { - gint mul = 1 + gobble_key_events(get_group0_keyval(&event->key), 0); // with any mask - sp_selection_scale_screen(selection, -2*mul); - } else if (MOD__CTRL(event)) { - sp_selection_scale_times(selection, 0.5); - } else { - gint mul = 1 + gobble_key_events(get_group0_keyval(&event->key), 0); // with any mask - sp_selection_scale(selection, -offset*mul); - } - - ret = TRUE; - break; - - case GDK_KEY_greater: - case GDK_KEY_period: - if (MOD__ALT(event)) { - gint mul = 1 + gobble_key_events(get_group0_keyval(&event->key), 0); // with any mask - sp_selection_scale_screen(selection, 2*mul); - } else if (MOD__CTRL(event)) { - sp_selection_scale_times(selection, 2); - } else { - gint mul = 1 + gobble_key_events(get_group0_keyval(&event->key), 0); // with any mask - sp_selection_scale(selection, offset*mul); - } - - ret = TRUE; - break; - + case GDK_KEY_Return: if (MOD__CTRL_ONLY(event)) { if (selection->singleItem()) { diff --git a/src/verbs.cpp b/src/verbs.cpp index 72708a7c0..e061eaab6 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -1101,6 +1101,7 @@ void SelectionVerb::perform(SPAction *action, void *data) { Inkscape::Selection *selection = sp_action_get_selection(action); SPDesktop *dt = sp_action_get_desktop(action); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); // Some of these operations have been modified so they work in command-line mode! // In this case, all we need is a selection @@ -1128,6 +1129,38 @@ void SelectionVerb::perform(SPAction *action, void *data) case SP_VERB_SELECTION_SLICE: sp_selected_path_slice(selection, dt); break; + case SP_VERB_SELECTION_GROW: + { + // FIXME these and the other grow/shrink they should use gobble_key_events. + // the problem is how to get access to which key, if any, to gobble. + sp_selection_scale(selection, prefs->getDoubleLimited("/options/defaultscale/value", 2, 0, 1000)); + break; + } + case SP_VERB_SELECTION_GROW_SCREEN: + { + sp_selection_scale_screen(selection, 2); + break; + } + case SP_VERB_SELECTION_GROW_DOUBLE: + { + sp_selection_scale_times(selection, 2); + break; + } + case SP_VERB_SELECTION_SHRINK: + { + sp_selection_scale(selection, -prefs->getDoubleLimited("/options/defaultscale/value", 2, 0, 1000)); + break; + } + case SP_VERB_SELECTION_SHRINK_SCREEN: + { + sp_selection_scale_screen(selection, -2); + break; + } + case SP_VERB_SELECTION_SHRINK_HALVE: + { + sp_selection_scale_times(selection, 0.5); + break; + } case SP_VERB_SELECTION_TO_FRONT: sp_selection_raise_to_top(selection, dt); break; @@ -1858,6 +1891,7 @@ void ZoomVerb::perform(SPAction *action, void *data) { gint mul = 1 + Inkscape::UI::Tools::gobble_key_events( GDK_KEY_KP_Add, 0); // with any mask + // FIXME what if zoom out is bound to something other than subtract? // While drawing with the pen/pencil tool, zoom towards the end of the unfinished path if (tools_isactive(dt, TOOLS_FREEHAND_PENCIL) || tools_isactive(dt, TOOLS_FREEHAND_PEN)) { SPCurve *rc = SP_DRAW_CONTEXT(ec)->red_curve; @@ -2587,6 +2621,18 @@ Verb *Verb::_base_verbs[] = { // Advanced tutorial for more info new SelectionVerb(SP_VERB_SELECTION_SLICE, "SelectionCutPath", N_("Cut _Path"), N_("Cut the bottom path's stroke into pieces, removing fill"), INKSCAPE_ICON("path-cut")), + new SelectionVerb(SP_VERB_SELECTION_GROW, "SelectionGrow", N_("_Grow"), + N_("Make selected objects bigger"), INKSCAPE_ICON("selection-grow")), + new SelectionVerb(SP_VERB_SELECTION_GROW_SCREEN, "SelectionGrowScreen", N_("_Grow on screen"), + N_("Make selected objects bigger relative to screen"), INKSCAPE_ICON("selection-grow-screen")), + new SelectionVerb(SP_VERB_SELECTION_GROW_DOUBLE, "SelectionGrowDouble", N_("_Double size"), + N_("Double the size of selected objects"), INKSCAPE_ICON("selection-grow-double")), + new SelectionVerb(SP_VERB_SELECTION_SHRINK, "SelectionShrink", N_("_Shrink"), + N_("Make selected objects smaller"), INKSCAPE_ICON("selection-shrink")), + new SelectionVerb(SP_VERB_SELECTION_SHRINK_SCREEN, "SelectionShrinkScreen", N_("_Shrink on screen"), + N_("Make selected objects smaller relative to screen"), INKSCAPE_ICON("selection-shrink-screen")), + new SelectionVerb(SP_VERB_SELECTION_SHRINK_HALVE, "SelectionShrinkHalve", N_("_Halve size"), + N_("Halve the size of selected objects"), INKSCAPE_ICON("selection-shrink-halve")), // TRANSLATORS: "outset": expand a shape by offsetting the object's path, // i.e. by displacing it perpendicular to the path in each point. // See also the Advanced Tutorial for explanation. diff --git a/src/verbs.h b/src/verbs.h index a273fe76e..1780e0ebf 100644 --- a/src/verbs.h +++ b/src/verbs.h @@ -126,6 +126,12 @@ enum { SP_VERB_SELECTION_SYMDIFF, SP_VERB_SELECTION_CUT, SP_VERB_SELECTION_SLICE, + SP_VERB_SELECTION_GROW, + SP_VERB_SELECTION_GROW_SCREEN, + SP_VERB_SELECTION_GROW_DOUBLE, + SP_VERB_SELECTION_SHRINK, + SP_VERB_SELECTION_SHRINK_SCREEN, + SP_VERB_SELECTION_SHRINK_HALVE, SP_VERB_SELECTION_OFFSET, SP_VERB_SELECTION_OFFSET_SCREEN, SP_VERB_SELECTION_OFFSET_SCREEN_10, -- cgit v1.2.3