diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2013-09-25 22:56:32 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx.marker.es> | 2013-09-25 22:56:32 +0000 |
| commit | 86c5f57796d973a949bf784a2a3decd451670f65 (patch) | |
| tree | 67ebaebe16b973bbec7bc3b5501dbfcd63477c8c | |
| parent | update to trunk (diff) | |
| parent | C++ify calling a few SPLPEItem functions, much more work than expected... slo... (diff) | |
| download | inkscape-86c5f57796d973a949bf784a2a3decd451670f65.tar.gz inkscape-86c5f57796d973a949bf784a2a3decd451670f65.zip | |
Update to trunk
(bzr r11950.1.148)
97 files changed, 1040 insertions, 380 deletions
diff --git a/.bzrignore b/.bzrignore index 5349f9ab6..17a1bbb63 100644 --- a/.bzrignore +++ b/.bzrignore @@ -97,6 +97,7 @@ share/Makefile share/Makefile.in share/attributes/Makefile share/attributes/Makefile.in +share/branding/Makefile share/clipart/Makefile share/clipart/Makefile.in share/examples/Makefile @@ -175,10 +176,12 @@ src/inkscape-version.cpp src/inkview src/io/makefile src/jabber_whiteboard/makefile +src/libavoid/makefile src/libcroco/makefile src/libgdl/makefile src/libnr/makefile src/libnrtype/makefile +src/libuemf/makefile src/livarot/makefile src/live_effects/makefile src/live_effects/parameter/makefile @@ -4245,7 +4245,7 @@ deleting, and getting and fixed toolboxes to be static with no warnings. -2005-03-26 Bryce <bryce@bryceharrington.com> +2005-03-26 Bryce <bryce@bryceharrington.org> * share/ui/keybindings.rc, share/ui/menus-bars.xml src/application/editor-impl.cpp, src/application/editor-impl.h, @@ -422,7 +422,7 @@ <rc command="${archutil}windres" file="${src}/inkscape.rc" - out="${build}/inkres.o"> + out="${build}/obj/inkres.o"> <flags> --include-dir=${src} </flags> @@ -506,7 +506,7 @@ <rc command="${archutil}windres" file="${src}/inkview.rc" - out="${build}/inkviewres.o"> + out="${build}/obj/inkviewres.o"> <flags> --include-dir=${src} </flags> diff --git a/inkscape.pod b/inkscape.pod index 62f637435..e5c241601 100644 --- a/inkscape.pod +++ b/inkscape.pod @@ -531,7 +531,7 @@ application sits: [% INCLUDE "AUTHORS" %] This man page was put together by Bryce Harrington -E<lt>brycehar@bryceharrington.comE<gt>. +E<lt>brycehar@bryceharrington.orgE<gt>. =head1 HISTORY diff --git a/inkscape.spec.in b/inkscape.spec.in index b25d80678..e1fc9c16b 100644 --- a/inkscape.spec.in +++ b/inkscape.spec.in @@ -105,7 +105,7 @@ rm -rf %{buildroot} - Added SMP flags so I can build faster - Added static build capability -* Sat Jul 17 2004 Bryce W. Harrington <bryce@bryceharrington.com> +* Sat Jul 17 2004 Bryce W. Harrington <bryce@bryceharrington.org> - Removing _libdir and TODO, updating description * Thu May 01 2003 Christian Schaller <uraeus@gnome.org> diff --git a/src/box3d-side.cpp b/src/box3d-side.cpp index d3d3b82a2..4d8b1e2d7 100644 --- a/src/box3d-side.cpp +++ b/src/box3d-side.cpp @@ -207,7 +207,7 @@ void Box3DSide::set_shape() { * This is very important for LPEs to work properly! (the bbox might be recalculated depending on the curve in shape)*/ this->setCurveInsync( c, TRUE); - if (sp_lpe_item_has_path_effect(this) && sp_lpe_item_path_effects_enabled(this)) { + if (hasPathEffect() && sp_lpe_item_path_effects_enabled(this)) { SPCurve *c_lpe = c->copy(); bool success = sp_lpe_item_perform_path_effect(this, c_lpe); diff --git a/src/display/nr-filter-slot.cpp b/src/display/nr-filter-slot.cpp index fe67972d6..755a30a74 100644 --- a/src/display/nr-filter-slot.cpp +++ b/src/display/nr-filter-slot.cpp @@ -83,11 +83,15 @@ cairo_surface_t *FilterSlot::getcairo(int slot_nr) switch (slot_nr) { case NR_FILTER_SOURCEGRAPHIC: { cairo_surface_t *tr = _get_transformed_source_graphic(); + // Assume all source graphics are sRGB + set_cairo_surface_ci( tr, SP_CSS_COLOR_INTERPOLATION_SRGB ); _set_internal(NR_FILTER_SOURCEGRAPHIC, tr); cairo_surface_destroy(tr); } break; case NR_FILTER_BACKGROUNDIMAGE: { cairo_surface_t *bg = _get_transformed_background(); + // Assume all backgrounds are sRGB + set_cairo_surface_ci( bg, SP_CSS_COLOR_INTERPOLATION_SRGB ); _set_internal(NR_FILTER_BACKGROUNDIMAGE, bg); cairo_surface_destroy(bg); } break; @@ -129,9 +133,6 @@ cairo_surface_t *FilterSlot::_get_transformed_source_graphic() if (trans.isTranslation()) { cairo_surface_reference(_source_graphic); - - // Assume all source graphics are sRGB - set_cairo_surface_ci( _source_graphic, SP_CSS_COLOR_INTERPOLATION_SRGB ); return _source_graphic; } @@ -148,8 +149,6 @@ cairo_surface_t *FilterSlot::_get_transformed_source_graphic() cairo_paint(tsg_ct); cairo_destroy(tsg_ct); - // Assume all source graphics are sRGB - set_cairo_surface_ci( tsg, SP_CSS_COLOR_INTERPOLATION_SRGB ); return tsg; } @@ -177,17 +176,15 @@ cairo_surface_t *FilterSlot::_get_transformed_background() tbg = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, _slot_w, _slot_h); } - // Assume all source graphics are sRGB - set_cairo_surface_ci( tbg, SP_CSS_COLOR_INTERPOLATION_SRGB ); - return tbg; } cairo_surface_t *FilterSlot::get_result(int res) { + cairo_surface_t *result = getcairo(res); + Geom::Affine trans = _units.get_matrix_pb2display(); if (trans.isIdentity()) { - cairo_surface_t *result = getcairo(res); cairo_surface_reference(result); return result; } @@ -196,12 +193,13 @@ cairo_surface_t *FilterSlot::get_result(int res) cairo_surface_get_content(_source_graphic), _source_graphic_area.width(), _source_graphic_area.height()); + copy_cairo_surface_ci( result, r ); cairo_t *r_ct = cairo_create(r); cairo_translate(r_ct, -_source_graphic_area.left(), -_source_graphic_area.top()); ink_cairo_transform(r_ct, trans); cairo_translate(r_ct, _slot_x, _slot_y); - cairo_set_source_surface(r_ct, getcairo(res), 0, 0); + cairo_set_source_surface(r_ct, result, 0, 0); cairo_set_operator(r_ct, CAIRO_OPERATOR_SOURCE); cairo_paint(r_ct); cairo_destroy(r_ct); diff --git a/src/document.cpp b/src/document.cpp index 5e59a0a0c..800f2f33d 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -450,11 +450,6 @@ SPDocument *SPDocument::createDoc(Inkscape::XML::Document *rdoc, document->setCurrentPersp3DImpl(persp_impl); } - // Set viewBox if it doesn't exist - if (!document->root->viewBox_set) { - document->setViewBox(Geom::Rect::from_xywh(0, 0, document->getWidth().quantity, document->getHeight().quantity)); - } - DocumentUndo::setUndoSensitive(document, true); // reset undo key when selection changes, so that same-key actions on different objects are not coalesced @@ -562,6 +557,7 @@ Inkscape::Util::Quantity SPDocument::getWidth() const SVGLength::Unit u = root->width.unit; if (root->width.unit == SVGLength::PERCENT && root->viewBox_set) { result = root->viewBox.width(); + u = SVGLength::PX; } if (u == SVGLength::NONE) { u = SVGLength::PX; @@ -571,25 +567,21 @@ Inkscape::Util::Quantity SPDocument::getWidth() const void SPDocument::setWidth(const Inkscape::Util::Quantity &width) { - if (root->width.unit == SVGLength::PERCENT && root->viewBox_set) { // set to viewBox= - root->viewBox.setMax(Geom::Point(root->viewBox.left() + width.value("px"), root->viewBox.bottom())); - } else { // set to width= - gdouble old_computed = root->width.computed; - root->width.computed = width.value("px"); - /* SVG does not support meters as a unit, so we must translate meters to - * cm when writing */ - if (*width.unit == unit_table.getUnit("m")) { - root->width.value = width.value("cm"); - root->width.unit = SVGLength::CM; - } else { - root->width.value = width.quantity; - root->width.unit = (SVGLength::Unit) width.unit->svgUnit(); - } - - if (root->viewBox_set) - root->viewBox.setMax(Geom::Point(root->viewBox.left() + (root->width.computed / old_computed) * root->viewBox.width(), root->viewBox.bottom())); + gdouble old_computed = root->width.computed; + root->width.computed = width.value("px"); + /* SVG does not support meters as a unit, so we must translate meters to + * cm when writing */ + if (*width.unit == unit_table.getUnit("m")) { + root->width.value = width.value("cm"); + root->width.unit = SVGLength::CM; + } else { + root->width.value = width.quantity; + root->width.unit = (SVGLength::Unit) width.unit->svgUnit(); } + if (root->viewBox_set) + root->viewBox.setMax(Geom::Point(root->viewBox.left() + (root->width.computed / old_computed) * root->viewBox.width(), root->viewBox.bottom())); + root->updateRepr(); } @@ -602,6 +594,7 @@ Inkscape::Util::Quantity SPDocument::getHeight() const SVGLength::Unit u = root->height.unit; if (root->height.unit == SVGLength::PERCENT && root->viewBox_set) { result = root->viewBox.height(); + u = SVGLength::PX; } if (u == SVGLength::NONE) { u = SVGLength::PX; @@ -611,25 +604,21 @@ Inkscape::Util::Quantity SPDocument::getHeight() const void SPDocument::setHeight(const Inkscape::Util::Quantity &height) { - if (root->height.unit == SVGLength::PERCENT && root->viewBox_set) { // set to viewBox= - root->viewBox.setMax(Geom::Point(root->viewBox.right(), root->viewBox.top() + height.value("px"))); - } else { // set to height= - gdouble old_computed = root->height.computed; - root->height.computed = height.value("px"); - /* SVG does not support meters as a unit, so we must translate meters to - * cm when writing */ - if (*height.unit == unit_table.getUnit("m")) { - root->height.value = height.value("cm"); - root->height.unit = SVGLength::CM; - } else { - root->height.value = height.quantity; - root->height.unit = (SVGLength::Unit) height.unit->svgUnit(); - } - - if (root->viewBox_set) - root->viewBox.setMax(Geom::Point(root->viewBox.right(), root->viewBox.top() + (root->height.computed / old_computed) * root->viewBox.height())); + gdouble old_computed = root->height.computed; + root->height.computed = height.value("px"); + /* SVG does not support meters as a unit, so we must translate meters to + * cm when writing */ + if (*height.unit == unit_table.getUnit("m")) { + root->height.value = height.value("cm"); + root->height.unit = SVGLength::CM; + } else { + root->height.value = height.quantity; + root->height.unit = (SVGLength::Unit) height.unit->svgUnit(); } + if (root->viewBox_set) + root->viewBox.setMax(Geom::Point(root->viewBox.right(), root->viewBox.top() + (root->height.computed / old_computed) * root->viewBox.height())); + root->updateRepr(); } diff --git a/src/draw-context.cpp b/src/draw-context.cpp index 1a4383664..37d2b0e56 100644 --- a/src/draw-context.cpp +++ b/src/draw-context.cpp @@ -591,7 +591,7 @@ static void spdc_flush_white(SPDrawContext *dc, SPCurve *gc) Inkscape::XML::Node *repr; if (dc->white_item) { repr = dc->white_item->getRepr(); - has_lpe = sp_lpe_item_has_path_effect_recursive(SP_LPE_ITEM(dc->white_item)); + has_lpe = SP_LPE_ITEM(dc->white_item)->hasPathEffectRecursive(); } else { repr = xml_doc->createElement("svg:path"); // Set style diff --git a/src/extension/internal/cdr-input.cpp b/src/extension/internal/cdr-input.cpp index e6c400fb5..517d6fb9c 100644 --- a/src/extension/internal/cdr-input.cpp +++ b/src/extension/internal/cdr-input.cpp @@ -51,6 +51,8 @@ #include "svg-view.h" #include "svg-view-widget.h" +#include "util/units.h" + namespace Inkscape { namespace Extension { namespace Internal { @@ -254,6 +256,10 @@ SPDocument *CdrInput::open(Inkscape::Extension::Input * /*mod*/, const gchar * u } SPDocument * doc = SPDocument::createNewDocFromMem(tmpSVGOutput[page_num-1].cstr(), strlen(tmpSVGOutput[page_num-1].cstr()), TRUE); + // Set viewBox if it doesn't exist + if (!doc->getRoot()->viewBox_set) { + doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().quantity, doc->getHeight().quantity)); + } return doc; } diff --git a/src/extension/internal/emf-inout.cpp b/src/extension/internal/emf-inout.cpp index ab8a1ab64..d9489af31 100644 --- a/src/extension/internal/emf-inout.cpp +++ b/src/extension/internal/emf-inout.cpp @@ -3483,6 +3483,11 @@ Emf::open( Inkscape::Extension::Input * /*mod*/, const gchar *uri ) d.tri = trinfo_release_except_FC(d.tri); + // Set viewBox if it doesn't exist + if (!doc->getRoot()->viewBox_set) { + doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().quantity, doc->getHeight().quantity)); + } + return doc; } diff --git a/src/extension/internal/gdkpixbuf-input.cpp b/src/extension/internal/gdkpixbuf-input.cpp index 87cf8a9cc..13267ee2b 100644 --- a/src/extension/internal/gdkpixbuf-input.cpp +++ b/src/extension/internal/gdkpixbuf-input.cpp @@ -102,6 +102,12 @@ GdkpixbufInput::open(Inkscape::Extension::Input *mod, char const *uri) doc->getRoot()->appendChildRepr(image_node); Inkscape::GC::release(image_node); fit_canvas_to_drawing(doc); + + // Set viewBox if it doesn't exist + if (!doc->getRoot()->viewBox_set) { + doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().quantity, doc->getHeight().quantity)); + } + // restore undo, as now this document may be shown to the user if a bitmap was opened DocumentUndo::setUndoSensitive(doc, saved); } else { diff --git a/src/extension/internal/image-resolution.cpp b/src/extension/internal/image-resolution.cpp index a9d33e831..b38b0ddc7 100644 --- a/src/extension/internal/image-resolution.cpp +++ b/src/extension/internal/image-resolution.cpp @@ -11,6 +11,7 @@ # include <config.h> #endif +#include "util/units.h" #include "image-resolution.h" #define IR_TRY_PNG 1 @@ -341,15 +342,9 @@ void ImageResolution::readmagick(char const *fn) { image.read(fn); } catch (...) {} Magick::Geometry geo = image.density(); - std::string type = image.magick(); - - if (type == "PNG") { // PNG only supports pixelspercentimeter - x_ = (double)geo.width() * 2.54; - y_ = (double)geo.height() * 2.54; - } else { - x_ = (double)geo.width(); - y_ = (double)geo.height(); - } + + x_ = Inkscape::Util::Quantity::convert((double)geo.width(), "pt", "px"); + y_ = Inkscape::Util::Quantity::convert((double)geo.height(), "pt", "px"); ok_ = true; } diff --git a/src/extension/internal/pdf-input-cairo.cpp b/src/extension/internal/pdf-input-cairo.cpp index 355a5784d..adac0d6c9 100644 --- a/src/extension/internal/pdf-input-cairo.cpp +++ b/src/extension/internal/pdf-input-cairo.cpp @@ -23,6 +23,10 @@ #include "extension/input.h" #include "dialogs/dialog-events.h" #include "document.h" +#include "sp-root.h" +#include "util/units.h" + +#include <2geom/rect.h> #include "inkscape.h" @@ -620,6 +624,11 @@ PdfInputCairo::open(Inkscape::Extension::Input * /*mod*/, const gchar * uri) { SPDocument * doc = SPDocument::createNewDocFromMem(output->c_str(), output->length(), TRUE); + // Set viewBox if it doesn't exist + if (!doc->getRoot()->viewBox_set) { + doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().quantity, doc->getHeight().quantity)); + } + delete output; g_object_unref(page); g_object_unref(document); diff --git a/src/extension/internal/pdfinput/pdf-input.cpp b/src/extension/internal/pdfinput/pdf-input.cpp index b04c9782f..213550688 100644 --- a/src/extension/internal/pdfinput/pdf-input.cpp +++ b/src/extension/internal/pdfinput/pdf-input.cpp @@ -46,6 +46,7 @@ #include "document-private.h" #include "document-undo.h" #include "inkscape.h" +#include "util/units.h" #include "dialogs/dialog-events.h" #include <gtk/gtk.h> @@ -747,6 +748,11 @@ PdfInput::open(::Inkscape::Extension::Input * /*mod*/, const gchar * uri) { delete pdf_doc; delete dlg; + // Set viewBox if it doesn't exist + if (!doc->getRoot()->viewBox_set) { + doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().quantity, doc->getHeight().quantity)); + } + // Restore undo DocumentUndo::setUndoSensitive(doc, saved); diff --git a/src/extension/internal/vsd-input.cpp b/src/extension/internal/vsd-input.cpp index 12e5150cb..42a9e3d41 100644 --- a/src/extension/internal/vsd-input.cpp +++ b/src/extension/internal/vsd-input.cpp @@ -39,6 +39,7 @@ #include "document-private.h" #include "document-undo.h" #include "inkscape.h" +#include "util/units.h" #include "dialogs/dialog-events.h" #include <gtk/gtk.h> @@ -254,6 +255,12 @@ SPDocument *VsdInput::open(Inkscape::Extension::Input * /*mod*/, const gchar * u } SPDocument * doc = SPDocument::createNewDocFromMem(tmpSVGOutput[page_num-1].cstr(), strlen(tmpSVGOutput[page_num-1].cstr()), TRUE); + + // Set viewBox if it doesn't exist + if (!doc->getRoot()->viewBox_set) { + doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().quantity, doc->getHeight().quantity)); + } + return doc; } diff --git a/src/extension/internal/wmf-inout.cpp b/src/extension/internal/wmf-inout.cpp index 373138187..e7dfa46d7 100644 --- a/src/extension/internal/wmf-inout.cpp +++ b/src/extension/internal/wmf-inout.cpp @@ -3171,6 +3171,11 @@ Wmf::open( Inkscape::Extension::Input * /*mod*/, const gchar *uri ) d.tri = trinfo_release_except_FC(d.tri); + // Set viewBox if it doesn't exist + if (!doc->getRoot()->viewBox_set) { + doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().quantity, doc->getHeight().quantity)); + } + return doc; } diff --git a/src/extension/internal/wpg-input.cpp b/src/extension/internal/wpg-input.cpp index cb1677547..ac86a6171 100644 --- a/src/extension/internal/wpg-input.cpp +++ b/src/extension/internal/wpg-input.cpp @@ -48,6 +48,8 @@ #include "extension/system.h" #include "extension/input.h" #include "document.h" +#include "sp-root.h" +#include "util/units.h" #include <cstring> // Take a guess and fallback to 0.1.x if no configure has run @@ -109,6 +111,12 @@ SPDocument *WpgInput::open(Inkscape::Extension::Input * /*mod*/, const gchar * u //printf("I've got a doc: \n%s", painter.document.c_str()); SPDocument * doc = SPDocument::createNewDocFromMem(output.cstr(), strlen(output.cstr()), TRUE); + + // Set viewBox if it doesn't exist + if (!doc->getRoot()->viewBox_set) { + doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().quantity, doc->getHeight().quantity)); + } + delete input; return doc; } diff --git a/src/file.cpp b/src/file.cpp index baa7b12b5..b19fe21ff 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -140,6 +140,11 @@ SPDesktop *sp_file_new(const std::string &templ) DocumentUndo::clearUndo(doc); } + // Set viewBox if it doesn't exist + if (!doc->getRoot()->viewBox_set) { + doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().quantity, doc->getHeight().quantity)); + } + SPDesktop *desktop = SP_ACTIVE_DESKTOP; if (desktop) desktop->setWaitingCursor(); diff --git a/src/filters/componenttransfer-funcnode.cpp b/src/filters/componenttransfer-funcnode.cpp index 7c5191700..7c7375802 100644 --- a/src/filters/componenttransfer-funcnode.cpp +++ b/src/filters/componenttransfer-funcnode.cpp @@ -30,10 +30,37 @@ #define SP_MACROS_SILENT #include "macros.h" + +#include "sp-factory.h" + +namespace { + SPObject* createFuncR() { + return new SPFeFuncNode(SPFeFuncNode::R); + } + + SPObject* createFuncG() { + return new SPFeFuncNode(SPFeFuncNode::G); + } + + SPObject* createFuncB() { + return new SPFeFuncNode(SPFeFuncNode::B); + } + + SPObject* createFuncA() { + return new SPFeFuncNode(SPFeFuncNode::A); + } + + bool funcRRegistered = SPFactory::instance().registerObject("svg:feFuncR", createFuncR); + bool funcGRegistered = SPFactory::instance().registerObject("svg:feFuncG", createFuncG); + bool funcBRegistered = SPFactory::instance().registerObject("svg:feFuncB", createFuncB); + bool funcARegistered = SPFactory::instance().registerObject("svg:feFuncA", createFuncA); +} + + /* FeFuncNode class */ -SPFeFuncNode::SPFeFuncNode() +SPFeFuncNode::SPFeFuncNode(SPFeFuncNode::Channel channel) : SPObject(), type(Inkscape::Filters::COMPONENTTRANSFER_TYPE_IDENTITY), - slope(1), intercept(0), amplitude(1), exponent(1), offset(0) { + slope(1), intercept(0), amplitude(1), exponent(1), offset(0), channel(channel) { } SPFeFuncNode::~SPFeFuncNode() { diff --git a/src/filters/componenttransfer-funcnode.h b/src/filters/componenttransfer-funcnode.h index a5f813e1e..4f9b8de2e 100644 --- a/src/filters/componenttransfer-funcnode.h +++ b/src/filters/componenttransfer-funcnode.h @@ -18,32 +18,15 @@ #include "sp-object.h" #include "display/nr-filter-component-transfer.h" -//#define SP_TYPE_FEFUNCR (sp_fefuncR_get_type()) -//#define SP_TYPE_FEFUNCG (sp_fefuncG_get_type()) -//#define SP_TYPE_FEFUNCB (sp_fefuncB_get_type()) -//#define SP_TYPE_FEFUNCA (sp_fefuncA_get_type()) - -// CPPIFY: Casting macros buggy, as these aren't classes. -//#define SP_IS_FEFUNCR(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), SP_TYPE_FEFUNCR)) -//#define SP_IS_FEFUNCG(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), SP_TYPE_FEFUNCG)) -//#define SP_IS_FEFUNCB(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), SP_TYPE_FEFUNCB)) -//#define SP_IS_FEFUNCA(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), SP_TYPE_FEFUNCA)) - #define SP_FEFUNCNODE(obj) (dynamic_cast<SPFeFuncNode*>((SPObject*)obj)) -//#define SP_IS_FEFUNCR(obj) (obj != NULL && static_cast<const SPObject*>(obj)->typeHierarchy.count(typeid(SPFeFuncNode))) -//#define SP_IS_FEFUNCG(obj) (obj != NULL && static_cast<const SPObject*>(obj)->typeHierarchy.count(typeid(SPFeFuncNode))) -//#define SP_IS_FEFUNCB(obj) (obj != NULL && static_cast<const SPObject*>(obj)->typeHierarchy.count(typeid(SPFeFuncNode))) -//#define SP_IS_FEFUNCA(obj) (obj != NULL && static_cast<const SPObject*>(obj)->typeHierarchy.count(typeid(SPFeFuncNode))) - -#define SP_IS_FEFUNCR(obj) (dynamic_cast<const SPFeFuncNode*>((SPObject*)obj) != NULL) -#define SP_IS_FEFUNCG(obj) (dynamic_cast<const SPFeFuncNode*>((SPObject*)obj) != NULL) -#define SP_IS_FEFUNCB(obj) (dynamic_cast<const SPFeFuncNode*>((SPObject*)obj) != NULL) -#define SP_IS_FEFUNCA(obj) (dynamic_cast<const SPFeFuncNode*>((SPObject*)obj) != NULL) - class SPFeFuncNode : public SPObject { public: - SPFeFuncNode(); + enum Channel { + R, G, B, A + }; + + SPFeFuncNode(Channel channel); virtual ~SPFeFuncNode(); Inkscape::Filters::FilterComponentTransferType type; @@ -53,6 +36,7 @@ public: double amplitude; double exponent; double offset; + Channel channel; protected: virtual void build(SPDocument* doc, Inkscape::XML::Node* repr); diff --git a/src/filters/componenttransfer.cpp b/src/filters/componenttransfer.cpp index 96d1ea0bf..610b3dd02 100644 --- a/src/filters/componenttransfer.cpp +++ b/src/filters/componenttransfer.cpp @@ -65,12 +65,26 @@ static void sp_feComponentTransfer_children_modified(SPFeComponentTransfer *sp_c bool set[4] = {false, false, false, false}; SPObject* node = sp_componenttransfer->children; for(;node;node=node->next){ - int i=4; - if (SP_IS_FEFUNCR(node)) i=0; - if (SP_IS_FEFUNCG(node)) i=1; - if (SP_IS_FEFUNCB(node)) i=2; - if (SP_IS_FEFUNCA(node)) i=3; - if (i==4) { + int i = 4; + + SPFeFuncNode *funcNode = SP_FEFUNCNODE(node); + + switch (funcNode->channel) { + case SPFeFuncNode::R: + i = 0; + break; + case SPFeFuncNode::G: + i = 1; + break; + case SPFeFuncNode::B: + i = 2; + break; + case SPFeFuncNode::A: + i = 3; + break; + } + + if (i == 4) { g_warning("Unrecognized channel for component transfer."); break; } diff --git a/src/filters/distantlight.cpp b/src/filters/distantlight.cpp index 8b6ef023b..bd8bd2797 100644 --- a/src/filters/distantlight.cpp +++ b/src/filters/distantlight.cpp @@ -29,6 +29,18 @@ #define SP_MACROS_SILENT #include "macros.h" + +#include "sp-factory.h" + +namespace { + SPObject* createDistantLight() { + return new SPFeDistantLight(); + } + + bool distantLightRegistered = SPFactory::instance().registerObject("svg:feDistantLight", createDistantLight); +} + + SPFeDistantLight::SPFeDistantLight() : SPObject(), azimuth(0), azimuth_set(FALSE), elevation(0), elevation_set(FALSE) { } diff --git a/src/gradient-drag.cpp b/src/gradient-drag.cpp index 096b2b47b..b3622107b 100644 --- a/src/gradient-drag.cpp +++ b/src/gradient-drag.cpp @@ -1417,7 +1417,7 @@ void GrDragger::updateTip() if (g_slist_length (this->draggables) == 1) { GrDraggable *draggable = (GrDraggable *) this->draggables->data; - char *item_desc = draggable->item->getDetailedDescription(); + char *item_desc = draggable->item->detailedDescription(); switch (draggable->point_type) { case POINT_LG_MID: case POINT_RG_MID1: diff --git a/src/interface.cpp b/src/interface.cpp index d18eb8063..e57092e2b 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -50,6 +50,7 @@ #include "sp-gradient.h" #include "sp-flowtext.h" #include "sp-namedview.h" +#include "sp-root.h" #include "ui/view/view.h" #include "helper/action.h" #include "helper/action-context.h" @@ -321,6 +322,10 @@ sp_ui_close_view(GtkWidget */*widget*/) if (desktops.size() == 1) { Glib::ustring templateUri = sp_file_default_template_uri(); SPDocument *doc = SPDocument::createNewDoc( templateUri.c_str() , TRUE, true ); + // Set viewBox if it doesn't exist + if (!doc->getRoot()->viewBox_set) { + doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().quantity, doc->getHeight().quantity)); + } dt->change_document(doc); sp_namedview_window_from_document(dt); sp_namedview_update_layers_from_document(dt); diff --git a/src/libdepixelize/CMakeLists.txt b/src/libdepixelize/CMakeLists.txt index e05849e29..895e16e85 100644 --- a/src/libdepixelize/CMakeLists.txt +++ b/src/libdepixelize/CMakeLists.txt @@ -7,14 +7,17 @@ set(libdepixelize_SRC kopftracer2011.h splines.h - priv/branchless.h + priv/branchless.h priv/colorspace.h + priv/curvature.h priv/homogeneoussplines.h + priv/integral priv/iterator.h + priv/optimization-kopf2011.h priv/pixelgraph.h priv/point.h priv/simplifiedvoronoi.h - priv/splines.h + priv/splines-kopf2011.h ) add_inkscape_lib(depixelize_LIB "${libdepixelize_SRC}") diff --git a/src/libdepixelize/Makefile_insert b/src/libdepixelize/Makefile_insert index 421d32439..8aed7244f 100644 --- a/src/libdepixelize/Makefile_insert +++ b/src/libdepixelize/Makefile_insert @@ -5,15 +5,18 @@ libdepixelize/all: libdepixelize/libdepixelize.a libdepixelize/clean: rm -f libdepixelize/libdepixelize.a $(libdepixelize_libdepixelize_a_OBJECTS) -libdepixelize_libdepixelize_a_SOURCES = \ - libdepixelize/kopftracer2011.cpp \ - libdepixelize/kopftracer2011.h \ - libdepixelize/splines.h \ - libdepixelize/priv/branchless.h \ - libdepixelize/priv/colorspace.h \ - libdepixelize/priv/homogeneoussplines.h \ - libdepixelize/priv/iterator.h \ - libdepixelize/priv/pixelgraph.h \ - libdepixelize/priv/point.h \ - libdepixelize/priv/simplifiedvoronoi.h \ - libdepixelize/priv/splines.h +libdepixelize_libdepixelize_a_SOURCES = \ + libdepixelize/kopftracer2011.cpp \ + libdepixelize/kopftracer2011.h \ + libdepixelize/splines.h \ + libdepixelize/priv/branchless.h \ + libdepixelize/priv/colorspace.h \ + libdepixelize/priv/curvature.h \ + libdepixelize/priv/homogeneoussplines.h \ + libdepixelize/priv/integral.h \ + libdepixelize/priv/iterator.h \ + libdepixelize/priv/optimization-kopf2011.h \ + libdepixelize/priv/pixelgraph.h \ + libdepixelize/priv/point.h \ + libdepixelize/priv/simplifiedvoronoi.h \ + libdepixelize/priv/splines-kopf2011.h diff --git a/src/libdepixelize/kopftracer2011.cpp b/src/libdepixelize/kopftracer2011.cpp index 26ad8863b..5e6e26048 100644 --- a/src/libdepixelize/kopftracer2011.cpp +++ b/src/libdepixelize/kopftracer2011.cpp @@ -37,7 +37,7 @@ #include "priv/colorspace.h" #include "priv/homogeneoussplines.h" #include "priv/branchless.h" -#include "priv/splines.h" +#include "priv/splines-kopf2011.h" #include "priv/iterator.h" namespace Tracer { @@ -146,6 +146,12 @@ SimplifiedVoronoi<T> Kopf2011::_voronoi(const Glib::RefPtr<Gdk::Pixbuf const> &b graph.checkConsistency(); #endif + _remove_puzzle_pattern(graph); + +#ifndef NDEBUG + graph.checkConsistency(); +#endif + return SimplifiedVoronoi<T>(graph); } @@ -309,6 +315,40 @@ void Kopf2011::_remove_crossing_edges_unsafe(PixelGraph &graph, } } +inline +void Kopf2011::_remove_puzzle_pattern(PixelGraph &graph) +{ + if ( graph.width() < 2 || graph.height() < 2 ) + return; + + PixelGraph::iterator it = graph.begin(); + for ( int i = 0 ; i + 1 != graph.height() ; ++i ) { + PixelGraph::iterator it2 = it; + for ( int j = 0 ; j + 1 != graph.width() ; ++j ) { + // Evil pattern currently not handled correctly in SimplifiedVoronoi + if ( it2->adj.right + it2->adj.bottom + + graph.nodeBottomRight(it2)->adj.left + + graph.nodeBottomRight(it2)->adj.top == 3 ) { + // We fake a new connection =) + it2->adj.right = true; + graph.nodeRight(it2)->adj.left = true; + + it2->adj.bottom = true; + graph.nodeBottom(it2)->adj.top = true; + + graph.nodeBottomRight(it2)->adj.left = true; + graph.nodeBottom(it2)->adj.right = true; + + graph.nodeBottomRight(it2)->adj.top = true; + graph.nodeRight(it2)->adj.bottom = true; + } + + it2 = graph.nodeRight(it2); + } + it = graph.nodeBottom(it); + } +} + inline int Heuristics::curves(const PixelGraph &graph, PixelGraph::const_iterator a, PixelGraph::const_iterator b) @@ -383,22 +423,25 @@ inline void Heuristics::SparsePixels::operator ()(const PixelGraph &graph, { unsigned x = graph.toX(diagonals[MAIN_DIAGONAL].first.first); unsigned y = graph.toY(diagonals[MAIN_DIAGONAL].first.first); - unsigned minor = std::min(x, y); unsigned displace = radius - 1; - if ( displace > minor ) { - displace = minor; - radius = displace + 1; + { + unsigned minor = std::min(x, y); + + if ( displace > minor ) { + displace = minor; + radius = displace + 1; + } } displace = radius; - if ( x + displace >= graph.width() ) { + if ( x + displace >= unsigned(graph.width()) ) { displace = unsigned(graph.width()) - x - 1; radius = displace; } - if ( y + displace >= graph.height() ) { + if ( y + displace >= unsigned(graph.height()) ) { displace = unsigned(graph.height()) - y - 1; radius = displace; } @@ -434,7 +477,6 @@ inline void Heuristics::SparsePixels::operator ()(const PixelGraph &graph, int minor = std::min(diagonals[0].second, diagonals[1].second); for ( int i = 0 ; i != 2 ; ++i ) diagonals[i].second -= minor; - std::swap(diagonals[0].second, diagonals[1].second); } diff --git a/src/libdepixelize/kopftracer2011.h b/src/libdepixelize/kopftracer2011.h index 73f3b7274..aff39d3d8 100644 --- a/src/libdepixelize/kopftracer2011.h +++ b/src/libdepixelize/kopftracer2011.h @@ -73,12 +73,17 @@ public: /** * # Exceptions * + * \p options.optimize and options.nthreads will be ignored + * * Glib::FileError * Gdk::PixbufError */ static Splines to_voronoi(const std::string &filename, const Options &options = Options()); + /* + * \p options.optimize and options.nthreads will be ignored + */ static Splines to_voronoi(const Glib::RefPtr<Gdk::Pixbuf const> &buf, const Options &options = Options()); @@ -95,7 +100,7 @@ public: const Options &options = Options()); private: - typedef double Precision; + typedef Geom::Coord Precision; template<class T> static SimplifiedVoronoi<T> _voronoi(const Glib::RefPtr<Gdk::Pixbuf const> &buf, @@ -105,6 +110,7 @@ private: static void _remove_crossing_edges_safe(PixelGraph &graph); static void _remove_crossing_edges_unsafe(PixelGraph &graph, const Options &options); + static void _remove_puzzle_pattern(PixelGraph &graph); }; } // namespace Tracer diff --git a/src/libdepixelize/priv/curvature.h b/src/libdepixelize/priv/curvature.h new file mode 100644 index 000000000..3a1af4197 --- /dev/null +++ b/src/libdepixelize/priv/curvature.h @@ -0,0 +1,115 @@ +/* This file is part of the libdepixelize project + Copyright (C) 2013 VinÃcius dos Santos Oliveira <vini.ipsmaker@gmail.com> + + GNU Lesser General Public License Usage + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2.1 of the License, or (at your + option) any later version. + You should have received a copy of the GNU Lesser General Public License + along with this library. If not, see <http://www.gnu.org/licenses/>. + + GNU General Public License Usage + Alternatively, this library may be used under the terms of the GNU General + Public License as published by the Free Software Foundation, either version + 2 of the License, or (at your option) any later version. + You should have received a copy of the GNU General Public License along with + this library. If not, see <http://www.gnu.org/licenses/>. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. +*/ + +#ifndef LIBDEPIXELIZE_TRACER_CURVATURE_H +#define LIBDEPIXELIZE_TRACER_CURVATURE_H + +#include "point.h" +#include <cmath> + +namespace Tracer { + +/** + * Curvature function for a quadratic Bézier curve where the points are know. + * Its main use is to numerically integrate the curvature function and then + * smooth the B-Splines generated by the Kopf-Lischinski algorithm. + */ +template<class T> +struct Curvature +{ + Curvature(Point<T> p0, Point<T> c1, Point<T> p2) : + p0(p0), c1(c1), p2(p2) + {} + + T operator()(T t) const; + + /** + * The derivative of x + */ + T xPrime(T t) const; + + /** + * The derivative of y + */ + T yPrime(T t) const; + + /** + * The second derivative of x + */ + T xPrimePrime() const; + + /** + * The second derivative of y + */ + T yPrimePrime() const; + + Point<T> p0, c1, p2; +}; + +template<class T> +T Curvature<T>::operator()(T t) const +{ + T num = xPrime(t) * yPrimePrime() - yPrime(t) * xPrimePrime(); + T den = std::pow(xPrime(t) * xPrime(t) + yPrime(t) * yPrime(t), T(3) / 2); + return num / den; +} + +template<class T> +T Curvature<T>::xPrime(T t) const +{ + return (1-t)*2*(c1.x-p0.x) + t*2*(p2.x-c1.x); +} + +template<class T> +T Curvature<T>::yPrime(T t) const +{ + return (1-t)*2*(c1.y-p0.y) + t*2*(p2.y-c1.y); +} + +template<class T> +T Curvature<T>::xPrimePrime() const +{ + return 2 * (p2.x - 2*c1.x + p0.x); +} + +template<class T> +T Curvature<T>::yPrimePrime() const +{ + return 2 * (p2.y - 2*c1.y + p0.y); +} + +} // namespace Tracer + +#endif // LIBDEPIXELIZE_TRACER_CURVATURE_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:encoding=utf-8:textwidth=99 : diff --git a/src/libdepixelize/priv/integral.h b/src/libdepixelize/priv/integral.h new file mode 100644 index 000000000..fc1a49f27 --- /dev/null +++ b/src/libdepixelize/priv/integral.h @@ -0,0 +1,61 @@ +/* This file is part of the libdepixelize project + Copyright (C) 2013 VinÃcius dos Santos Oliveira <vini.ipsmaker@gmail.com> + + GNU Lesser General Public License Usage + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2.1 of the License, or (at your + option) any later version. + You should have received a copy of the GNU Lesser General Public License + along with this library. If not, see <http://www.gnu.org/licenses/>. + + GNU General Public License Usage + Alternatively, this library may be used under the terms of the GNU General + Public License as published by the Free Software Foundation, either version + 2 of the License, or (at your option) any later version. + You should have received a copy of the GNU General Public License along with + this library. If not, see <http://www.gnu.org/licenses/>. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. +*/ + +#ifndef LIBDEPIXELIZE_TRACER_INTEGRAL_H +#define LIBDEPIXELIZE_TRACER_INTEGRAL_H + +#include <2geom/coord.h> + +namespace Tracer { + +/** + * Compute the integral numerically using Gaussian Quadrature rule with + * \p samples number of samples. + */ +template<class T, class F> +Geom::Coord integral(F f, T begin, T end, unsigned samples) +{ + T ret = 0; + const T width = (end - begin) / samples; + + for ( unsigned i = 0 ; i != samples ; ++i ) + ret += width * f(begin + width * (i + .5)); + + return ret; +} + +} // namespace Tracer + +#endif // LIBDEPIXELIZE_TRACER_INTEGRAL_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:encoding=utf-8:textwidth=99 : diff --git a/src/libdepixelize/priv/optimization-kopf2011.h b/src/libdepixelize/priv/optimization-kopf2011.h new file mode 100644 index 000000000..0c9011ca7 --- /dev/null +++ b/src/libdepixelize/priv/optimization-kopf2011.h @@ -0,0 +1,263 @@ +/* This file is part of the libdepixelize project + Copyright (C) 2013 VinÃcius dos Santos Oliveira <vini.ipsmaker@gmail.com> + + GNU Lesser General Public License Usage + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2.1 of the License, or (at your + option) any later version. + You should have received a copy of the GNU Lesser General Public License + along with this library. If not, see <http://www.gnu.org/licenses/>. + + GNU General Public License Usage + Alternatively, this library may be used under the terms of the GNU General + Public License as published by the Free Software Foundation, either version + 2 of the License, or (at your option) any later version. + You should have received a copy of the GNU General Public License along with + this library. If not, see <http://www.gnu.org/licenses/>. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. +*/ + +#ifndef LIBDEPIXELIZE_TRACER_OPTIMIZATION_KOPF2011_H +#define LIBDEPIXELIZE_TRACER_OPTIMIZATION_KOPF2011_H + +#include "curvature.h" +#include "integral.h" +#include <cmath> +#include <limits> + +namespace Tracer { + +/** + * m is angular coeficient + */ +template<class T> +bool is_valid_border_m(T a) +{ + if ( a < 0 ) + a *= -1; + + // TODO: alternative behaviour if has no infinity + return a == std::numeric_limits<T>::infinity() + || a == 3 || a == 1; +} + +/** + * Return true if the four points are considered a border. + */ +template<class T> +bool is_border(const Point<T> (&points)[4]) +{ + T dy[2]; + T dx[2]; + T m[2]; + if ( points[1].y == points[2].y ) { + dy[0] = points[1].y - points[0].y; + dy[1] = points[3].y - points[2].y; + + dx[0] = points[1].x - points[0].x; + dx[1] = points[3].x - points[2].x; + + m[0] = dy[0] / dx[0]; + m[1] = dy[1] / dx[1]; + } else if ( points[1].x == points[2].x ) { + // It's easier to have a unified logic, then we'll fake dx and dy + dy[0] = points[1].x - points[0].x; + dy[1] = points[3].x - points[2].x; + + dx[0] = points[1].y - points[0].y; + dx[1] = points[3].y - points[2].y; + + m[0] = dy[0] / dx[0]; + m[1] = dy[1] / dx[1]; + } else { + return false; + } + + return m[0] == -m[1] && is_valid_border_m(m[0]); +} + +template<class T> +typename std::vector< Point<T> >::iterator +skip1visible(typename std::vector< Point<T> >::iterator it, + typename std::vector< Point<T> >::iterator end) +{ + for ( ++it ; it != end ; ++it ) { + if ( it->visible ) + return it; + } + return end; +} + +/** + * Return how many elements should be skipped. + */ +template<class T> +typename std::vector< Point<T> >::difference_type +border_detection(typename std::vector< Point<T> >::iterator it, + typename std::vector< Point<T> >::iterator end) +{ + typename std::vector< Point<T> >::iterator begin = it; + + if ( end - it < 4 ) + return 0; + + Point<T> last[4]; + typename std::vector< Point<T> >::iterator prev = it; + + for ( int i = 0 ; i != 4 ; ++i ) { + if ( it == end ) + return 0; + last[i] = *it; + prev = it; + it = skip1visible<T>(it, end); + } + + if ( !is_border(last) ) + return 0; + + if ( it == end ) + return prev - begin; + + bool got_another = false; + for ( it = skip1visible<T>(it, end) ; it != end + ; it = skip1visible<T>(it, end) ) { + if ( !got_another ) { + last[0] = last[2]; + last[1] = last[3]; + last[2] = *it; + + got_another = true; + continue; + } + last[3] = *it; + + if ( !is_border(last) ) + return prev - begin; + prev = it; + } + + return prev - begin; +} + +template<class T> +T smoothness_energy(Point<T> c0, Point<T> c1, Point<T> c2) +{ + Point<T> p0 = midpoint(c0, c1); + Point<T> p2 = midpoint(c1, c2); + Curvature<T> cur(p0, c1, p2); + + return std::abs(integral<T>(cur, 0, 1, 16)); +} + +template<class T> +T positional_energy(Point<T> guess, Point<T> initial) +{ + using std::pow; + + return pow(pow(guess.x - initial.x, 2) + + pow(guess.y - initial.y, 2), 2); +} + +/** + * Kopf-Lischinski simple relaxation procedure: a random new offset position + * within a small radius around its current location. + * + * The small radius is not revealed. I chose the empirically determined value of + * 0.125. New tests can give a better value for "small". I believe this value + * showed up because the optimization sharply penalize larger deviations. + */ +template<class T> +Point<T> optimization_guess(Point<T> p) +{ + // See the value explanation in the function documentation. + T radius = 0.125; + + T d[] = { + (T(std::rand()) / RAND_MAX) * radius * 2 - radius, + (T(std::rand()) / RAND_MAX) * radius * 2 - radius + }; + + return p + Point<T>(d[0], d[1]); +} + +template<class T> +std::vector< Point<T> > optimize(const std::vector< Point<T> > &path) +{ + typedef std::vector< Point<T> > Path; + + Path ret = path; + + /* The number of vertices not constrained by optimization */ + unsigned n = 0; + + /* Values chosen by test + * TODO: make values configurable via function parameters. */ + const unsigned iterations = 4; + const unsigned nguess_per_iteration = 4; + + for ( unsigned i = 0 ; i != iterations ; ++i ) { + n = 0; + + /* This iteration bounds is not something to worry about, because the + * smallest path has size 4. */ + for ( typename Path::size_type j = 0 ; j != ret.size() ; ++j ) { + Point<T> prev = ( j == 0 ) ? ret.back() : ret[j-1]; + Point<T> next = ( j + 1 == ret.size() ) ? ret.front() : ret[j+1] ; + + if ( !ret[j].visible || !ret[j].smooth ) + continue; + + { + typename Path::iterator it = ret.begin() + j; + typename Path::difference_type skip + = border_detection<T>(it, ret.end()); + j += skip; + if ( j == ret.size() ) + break; + } + + ++n; + + for ( unsigned k = 0 ; k != nguess_per_iteration ; ++k ) { + Point<T> guess = optimization_guess(ret[j]); + + T s = smoothness_energy(prev, guess, next); + T p = positional_energy(guess, path[j]); + + T e = s + p; + + T prev_e = smoothness_energy(prev, ret[j], next) + + positional_energy(ret[j], path[j]); + + if ( prev_e > e ) { + // We don't want to screw other metadata, then we manually + // assign the new coords + ret[j].x = guess.x; + ret[j].y = guess.y; + } + } + } + } + + return ret; +} + +} // namespace Tracer + +#endif // LIBDEPIXELIZE_TRACER_OPTIMIZATION_KOPF2011_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:encoding=utf-8:textwidth=99 : diff --git a/src/libdepixelize/priv/pixelgraph.h b/src/libdepixelize/priv/pixelgraph.h index 32523d8ee..9e8c2124a 100644 --- a/src/libdepixelize/priv/pixelgraph.h +++ b/src/libdepixelize/priv/pixelgraph.h @@ -378,7 +378,7 @@ inline void PixelGraph::connectAllNeighbors() it = nodeRight(it); } - // After the previous loop, 'it' is poiting to the last node from + // After the previous loop, 'it' is pointing to the last node from // the row. // Go south, then first node in the row (increment 'it' by 1) // Go to the second node in the line (increment 'it' by 1) @@ -445,21 +445,34 @@ inline void PixelGraph::connectAllNeighbors() // ...and the 4 corner nodes { Node *const top_left = &(*this)[0][0]; - top_left->adj.right = 1; - top_left->adj.bottomright = 1; - top_left->adj.bottom = 1; + + if ( _width > 1 ) + top_left->adj.right = 1; + + if ( _width > 1 && _height > 1 ) + top_left->adj.bottomright = 1; + + if ( _height > 1 ) + top_left->adj.bottom = 1; } if ( _width > 1 ) { Node *const top_right = &(*this)[_width - 1][0]; - top_right->adj.bottom = 1; - top_right->adj.bottomleft = 1; + + if ( _height > 1 ) { + top_right->adj.bottom = 1; + top_right->adj.bottomleft = 1; + } + top_right->adj.left = 1; } if ( _height > 1 ) { Node *const down_left = &(*this)[0][_height - 1]; down_left->adj.top = 1; - down_left->adj.topright = 1; - down_left->adj.right = 1; + + if ( _width > 1 ) { + down_left->adj.topright = 1; + down_left->adj.right = 1; + } } if ( _width > 1 && _height > 1 ) { Node *const down_right = &(*this)[_width - 1][_height - 1]; diff --git a/src/libdepixelize/priv/point.h b/src/libdepixelize/priv/point.h index 6bea752ed..dc28a2b84 100644 --- a/src/libdepixelize/priv/point.h +++ b/src/libdepixelize/priv/point.h @@ -30,9 +30,9 @@ namespace Tracer { template<class T> struct Point { - Point() {} - Point(T x, T y) : x(x), y(y) {} - Point(T x, T y, bool smooth) : smooth(smooth), x(x), y(y) {} + Point() : visible(true) {} + Point(T x, T y) : visible(true), x(x), y(y) {} + Point(T x, T y, bool smooth) : smooth(smooth), visible(true), x(x), y(y) {} Point operator+(const Point &rhs) const { @@ -44,21 +44,58 @@ struct Point return Point(x / foo, y / foo); } + Point invisible() const + { + Point p = *this; + p.visible = false; + return p; + } + bool smooth; + /** + * By default, all points are visible, but the poor amount of information + * that B-Splines (libdepixelize-specific) allows us to represent forces us + * to create additional points. But... these additional points don't need to + * be visible. + */ + bool visible; + T x, y; }; template<class T> -inline bool operator==(const Point<T> &lhs, const Point<T> &rhs) +Point<T> midpoint(const Point<T> &a, const Point<T> &b) +{ + return Point<T>((a.x + b.x) / 2, (a.y + b.y) / 2); +} + +template<class T> +bool operator==(const Point<T> &lhs, const Point<T> &rhs) { return + /* + * Will make a better job identifying which points can be eliminated by + * cells union. + */ #ifndef LIBDEPIXELIZE_IS_VERY_WELL_TESTED lhs.smooth == rhs.smooth && #endif // LIBDEPIXELIZE_IS_VERY_WELL_TESTED lhs.x == rhs.x && lhs.y == rhs.y; } +template<class T> +bool weakly_equal(const Point<T> &a, const Point<T> &b) +{ + return a.x == b.x && a.y == b.y; +} + +template<class T> +Geom::Point to_geom_point(Point<T> p) +{ + return Geom::Point(p.x, p.y); +} + } // namespace Tracer #endif // LIBDEPIXELIZE_TRACER_POINT_H diff --git a/src/libdepixelize/priv/simplifiedvoronoi.h b/src/libdepixelize/priv/simplifiedvoronoi.h index a33695ff7..d5ebc36e5 100644 --- a/src/libdepixelize/priv/simplifiedvoronoi.h +++ b/src/libdepixelize/priv/simplifiedvoronoi.h @@ -124,11 +124,6 @@ private: typedef void (*PointTransform)(Point<T> &p, T dx, T dy); typedef bool (*NodeTransform)(PixelGraph::const_iterator); - static Point<T> _midpoint(const Point<T> &p1, const Point<T> p2) - { - return Point<T>((p1.x + p2.x) / 2, (p1.y + p2.y) / 2); - } - /** * Output is translated by -.5 in each axis. This function fixes this error. */ @@ -220,7 +215,7 @@ private: * code base 4 times smaller and bugs will be MUCH MUCH difficult to hide. * * Some maintainers may go mad because the level extra level of - * abstracation. + * abstraction. * * "All problems in computer science can be solved by another level of * indirection, except for the problem of too many layers of indirection." @@ -255,6 +250,11 @@ SimplifiedVoronoi<T>::SimplifiedVoronoi(const PixelGraph &graph) : if (!graph.size()) return; + /* + * The insertion order of cells is not a big deal. Here I just follow + * the order of PixelGraph arrangement. + */ + // ...the "center" cells first... if ( _width > 2 && _height > 2 ) { PixelGraph::const_iterator graph_it = graph.begin() + _width + 1; @@ -276,7 +276,7 @@ SimplifiedVoronoi<T>::SimplifiedVoronoi(const PixelGraph &graph) : // Bottom-left _complexBottomLeft(graph, graph_it, cells_it, j, i); } - // After the previous loop, 'it' is poiting to the last cell from + // After the previous loop, 'it' is pointing to the last cell from // the row. // Go south, then first node in the row (increment 'it' by 1) // Go to the second node in the line (increment 'it' by 1) @@ -794,13 +794,13 @@ SimplifiedVoronoi<T> PixelGraph::const_iterator d_it, Cell *const cells_it, int x, int y, PointTransform transform, - NodeTransform top, + NodeTransform, NodeTransform topright, NodeTransform right, NodeTransform bottomright, NodeTransform bottom, NodeTransform bottomleft, - NodeTransform left, + NodeTransform, NodeTransform topleft) { using colorspace::contour_edge; @@ -808,31 +808,36 @@ SimplifiedVoronoi<T> const Point<T> initial(x, y); + /* + * The insertion order of points within the cell is very important. You must + * follow current practice: Clockwise order. + */ + if ( bottomright(a_it) ) { // this and bottom-right are connected bool smooth[2] = { - same_color(a_it->rgba, d_it->rgba) + right(a_it), - same_color(a_it->rgba, d_it->rgba) + bottom(a_it) + same_color(a_it->rgba, d_it->rgba) || right(a_it), + same_color(a_it->rgba, d_it->rgba) || bottom(a_it) }; Point<T> borderMid = initial; { transform(borderMid, 1, 1); - borderMid = _midpoint(initial, borderMid); + borderMid = midpoint(initial, borderMid); } Point<T> vertices[2] = {initial, initial}; { transform(vertices[0], 1, 0); - vertices[0] = _adjust(_midpoint(borderMid, vertices[0]), smooth[0]); + vertices[0] = _adjust(midpoint(borderMid, vertices[0]), smooth[0]); transform(vertices[1], 0, 1); - vertices[1] = _adjust(_midpoint(borderMid, vertices[1]), smooth[1]); + vertices[1] = _adjust(midpoint(borderMid, vertices[1]), smooth[1]); } if ( !smooth[0] ) { - cells_it->vertices.push_back(vertices[0]); + cells_it->vertices.push_back(vertices[0].invisible()); { Point<T> another = vertices[0]; transform(another, @@ -841,7 +846,7 @@ SimplifiedVoronoi<T> // y - ( 0.5625 - ( topright(a_it) + topleft(b_it) ) * 0.1875 )); - cells_it->vertices.push_back(another); + cells_it->vertices.push_back(another.invisible()); } { Point<T> another = vertices[0]; @@ -862,7 +867,7 @@ SimplifiedVoronoi<T> // y 0.0625 + ( bottomright(b_it) - topright(d_it) ) * 0.0625); - cells_it->vertices.push_back(another); + cells_it->vertices.push_back(another.invisible()); } { transform(vertices[0], @@ -874,6 +879,7 @@ SimplifiedVoronoi<T> + ( topright(d_it) - topright(a_it) - topleft(b_it) - bottomright(b_it) ) * 0.03125 )); + vertices[0].visible = false; } } @@ -891,7 +897,7 @@ SimplifiedVoronoi<T> 0.0625 + ( bottomleft(a_it) - bottomleft(d_it) - topleft(c_it) - bottomright(c_it) ) * 0.03125); - cells_it->vertices.push_back(another); + cells_it->vertices.push_back(another.invisible()); } { Point<T> another = vertices[1]; @@ -901,7 +907,7 @@ SimplifiedVoronoi<T> // y 0.1875 - ( bottomright(c_it) + bottomleft(d_it) ) * 0.0625); - cells_it->vertices.push_back(another); + cells_it->vertices.push_back(another.invisible()); } { Point<T> another = vertices[1]; @@ -926,8 +932,9 @@ SimplifiedVoronoi<T> - ( 0.1875 - ( bottomleft(a_it) - topleft(c_it) ) * 0.1875 )); - cells_it->vertices.push_back(another); + cells_it->vertices.push_back(another.invisible()); } + vertices[1].visible = false; } cells_it->vertices.push_back(vertices[1]); @@ -936,7 +943,7 @@ SimplifiedVoronoi<T> Point<T> vertex = initial; transform(vertex, 1, 1); - vertex = _adjust(_midpoint(_midpoint(initial, vertex), initial), true); + vertex = _adjust(midpoint(midpoint(initial, vertex), initial), true); cells_it->vertices.push_back(vertex); } else { // Connections don't affect the shape of this squared-like @@ -944,7 +951,7 @@ SimplifiedVoronoi<T> Point<T> vertex = initial; transform(vertex, 1, 1); - vertex = _adjust(_midpoint(initial, vertex)); + vertex = _adjust(midpoint(initial, vertex)); // compute smoothness if ( right(a_it) ) { @@ -969,13 +976,13 @@ SimplifiedVoronoi<T> - ( ( bottomright(c_it) + topleft(c_it) ) * 0.03125 ); transform(another, - amount, amount); - cells_it->vertices.push_back(another); + cells_it->vertices.push_back(another.invisible()); } { Point<T> another = vertex; T amount = 0.0625 * bottomright(c_it); transform(another, amount, 0.25 - amount); - cells_it->vertices.push_back(another); + cells_it->vertices.push_back(another.invisible()); } { Point<T> another = vertex; @@ -990,8 +997,9 @@ SimplifiedVoronoi<T> T amount = 0.1875 * topleft(c_it); transform(another, - ( 0.75 - amount ), - amount); - cells_it->vertices.push_back(another); + cells_it->vertices.push_back(another.invisible()); } + vertex.visible = false; } else if ( twin_is_contour ) { T amount = 0.125 - ( ( bottomleft(d_it) + topright(d_it) ) @@ -1036,13 +1044,13 @@ SimplifiedVoronoi<T> if ( !vertex.smooth ) { if ( another_is_contour ) { - cells_it->vertices.push_back(vertex); + cells_it->vertices.push_back(vertex.invisible()); { Point<T> another = vertex; T amount = 0.1875 * topleft(b_it); transform(another, - amount, - ( 0.75 - amount )); - cells_it->vertices.push_back(another); + cells_it->vertices.push_back(another.invisible()); } { Point<T> another = vertex; @@ -1056,13 +1064,14 @@ SimplifiedVoronoi<T> Point<T> another = vertex; T amount = 0.0625 * bottomright(b_it); transform(another, 0.25 - amount, amount); - cells_it->vertices.push_back(another); + cells_it->vertices.push_back(another.invisible()); } { T amount = 0.125 - (bottomright(b_it) + topleft(b_it)) * 0.03125; transform(vertex, amount, - amount); + vertex.visible = false; } } else if ( twin_is_contour ) { T amount = 0.125 @@ -1115,13 +1124,13 @@ SimplifiedVoronoi<T> - ( topleft(c_it) + bottomright(c_it) ) * 0.03125; transform(another, - amount, amount); - cells_it->vertices.push_back(another); + cells_it->vertices.push_back(another.invisible()); } { Point<T> another = vertex; T amount = 0.0625 * bottomright(c_it); transform(another, amount, 0.25 - amount); - cells_it->vertices.push_back(another); + cells_it->vertices.push_back(another.invisible()); } { Point<T> another = vertex; @@ -1134,8 +1143,9 @@ SimplifiedVoronoi<T> Point<T> another = vertex; T amount = 0.1875 * topleft(c_it); transform(another, - ( 0.75 - amount ), - amount); - cells_it->vertices.push_back(another); + cells_it->vertices.push_back(another.invisible()); } + vertex.visible = false; } else { special = true; } @@ -1149,7 +1159,7 @@ SimplifiedVoronoi<T> } if ( special ) { - cells_it->vertices.push_back(vertex); + cells_it->vertices.push_back(vertex.invisible()); { Point<T> another = vertex; T amount = 0.1875; @@ -1159,7 +1169,7 @@ SimplifiedVoronoi<T> - ( 0.75 - ( topleft(b_it) + topright(a_it) ) * amount )); - cells_it->vertices.push_back(another); + cells_it->vertices.push_back(another.invisible()); } { Point<T> another = vertex; @@ -1181,7 +1191,7 @@ SimplifiedVoronoi<T> // y 0.25 - amount * ( bottomleft(d_it) + bottomright(c_it) )); - cells_it->vertices.push_back(another); + cells_it->vertices.push_back(another.invisible()); } { transform(vertex, @@ -1192,6 +1202,7 @@ SimplifiedVoronoi<T> ( topleft(b_it) - bottomleft(d_it) + topright(a_it) - bottomright(c_it) ) * 0.03125); + vertex.visible = false; } } } else if ( right(c_it) ) { @@ -1212,12 +1223,12 @@ SimplifiedVoronoi<T> if ( !vertex.smooth ) { if ( similar_neighbor_is_contour ) { - cells_it->vertices.push_back(vertex); + cells_it->vertices.push_back(vertex.invisible()); { Point<T> another = vertex; T amount = 0.1875 * topleft(b_it); transform(another, - amount, - ( 0.75 - amount )); - cells_it->vertices.push_back(another); + cells_it->vertices.push_back(another.invisible()); } { Point<T> another = vertex; @@ -1230,12 +1241,13 @@ SimplifiedVoronoi<T> Point<T> another = vertex; T amount = 0.0625 * bottomright(b_it); transform(another, 0.25 - amount, amount); - cells_it->vertices.push_back(another); + cells_it->vertices.push_back(another.invisible()); } { T amount = 0.125 - 0.03125 * (topleft(b_it) + bottomright(b_it)); transform(vertex, amount, - amount); + vertex.visible = false; } } else { special = true; @@ -1261,7 +1273,7 @@ SimplifiedVoronoi<T> - amount * ( topleft(c_it) + topright(d_it) - bottomleft(a_it) - bottomright(b_it) )); - cells_it->vertices.push_back(another); + cells_it->vertices.push_back(another.invisible()); } { Point<T> another = vertex; @@ -1272,7 +1284,7 @@ SimplifiedVoronoi<T> // y - amount * ( topright(d_it) - bottomright(b_it) )); - cells_it->vertices.push_back(another); + cells_it->vertices.push_back(another.invisible()); } { Point<T> another = vertex; @@ -1295,8 +1307,9 @@ SimplifiedVoronoi<T> // y - amount * ( topleft(c_it) - bottomleft(a_it) )); - cells_it->vertices.push_back(another); + cells_it->vertices.push_back(another.invisible()); } + vertex.visible = false; } } else { // there is a 4-color pattern, where the current node diff --git a/src/libdepixelize/priv/splines.h b/src/libdepixelize/priv/splines-kopf2011.h index c7ef2b492..eb84c3bfb 100644 --- a/src/libdepixelize/priv/splines.h +++ b/src/libdepixelize/priv/splines-kopf2011.h @@ -22,55 +22,65 @@ Lesser General Public License for more details. */ -#ifndef LIBDEPIXELIZE_TRACER_SPLINES_PRIV_H -#define LIBDEPIXELIZE_TRACER_SPLINES_PRIV_H +#ifndef LIBDEPIXELIZE_TRACER_SPLINES_KOPF2011_H +#define LIBDEPIXELIZE_TRACER_SPLINES_KOPF2011_H #include "../splines.h" #include "homogeneoussplines.h" +#include "optimization-kopf2011.h" namespace Tracer { +/** + * Maybe the pass-by-value and then move idiom should be more efficient. But all + * this is inlinable and we're not even in C++11 yet. + */ template<class T> -Geom::Point to_geom_point(Point<T> p) -{ - return Geom::Point(p.x, p.y); -} - -template<class T> -Geom::Path worker_helper(const std::vector< Point<T> > &source, bool optimize) +Geom::Path worker_helper(const std::vector< Point<T> > &source1, bool optimize) { typedef Geom::LineSegment Line; typedef Geom::QuadraticBezier Quad; typedef typename std::vector< Point<T> >::const_iterator iterator; - iterator it = source.begin(); - Geom::Path ret(to_geom_point((source.back() + *it) / 2)); + std::vector< Point<T> > source; - for ( iterator end = --source.end() ; it != end ; ++it ) { - Point<T> next = *(it + 1); - Point<T> middle = (*it + next) / 2; + if ( optimize ) + source = Tracer::optimize(source1); + else + source = source1; - if ( !it->smooth ) { - // TODO: remove redundant colinear points - ret.appendNew<Line>(Geom::Point(it->x, it->y)); - ret.appendNew<Line>(Geom::Point(middle.x, middle.y)); - } else { - ret.appendNew<Quad>(Geom::Point(it->x, it->y), - Geom::Point(middle.x, middle.y)); + iterator it = source.begin(); + Point<T> prev = source.back(); + Geom::Path ret(to_geom_point(midpoint(prev, *it))); + + for ( iterator end = source.end() ; it != end ; ++it ) { +#if LIBDEPIXELIZE_ENABLE_EXPERIMENTAL_FEATURES + // remove redundant points + if ( !it->visible ) { + prev = *it; + continue; + } +#endif // LIBDEPIXELIZE_ENABLE_EXPERIMENTAL_FEATURES + + if ( !prev.visible ) { + Geom::Point middle = to_geom_point(midpoint(prev, *it)); + if ( ret.finalPoint() != middle ) { + // All generated invisible points are straight lines + ret.appendNew<Line>(middle); + } } - } - { - Point<T> next = source.front(); - Point<T> middle = (*it + next) / 2; + Point<T> next = (it + 1 == end) ? source.front() : *(it + 1); + Point<T> middle = midpoint(*it, next); if ( !it->smooth ) { - ret.appendNew<Line>(Geom::Point(it->x, it->y)); - ret.appendNew<Line>(Geom::Point(middle.x, middle.y)); + ret.appendNew<Line>(to_geom_point(*it)); + ret.appendNew<Line>(to_geom_point(middle)); } else { - ret.appendNew<Quad>(Geom::Point(it->x, it->y), - Geom::Point(middle.x, middle.y)); + ret.appendNew<Quad>(to_geom_point(*it), to_geom_point(middle)); } + + prev = *it; } return ret; @@ -98,7 +108,9 @@ void worker(const typename HomogeneousSplines<T>::Polygon &source, } template<typename T> -Splines::Splines(const SimplifiedVoronoi<T> &diagram) +Splines::Splines(const SimplifiedVoronoi<T> &diagram) : + _width(diagram.width()), + _height(diagram.height()) { _paths.reserve(diagram.size()); @@ -141,7 +153,7 @@ Splines::Splines(const HomogeneousSplines<T> &homogeneousSplines, } // namespace Tracer -#endif // LIBDEPIXELIZE_TRACER_SPLINES_PRIV_H +#endif // LIBDEPIXELIZE_TRACER_SPLINES_KOPF2011_H /* Local Variables: diff --git a/src/main.cpp b/src/main.cpp index 9a365424c..1c0f4cee7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,7 +11,7 @@ * Michael Meeks <michael@helixcode.com> * Chema Celorio <chema@celorio.com> * Pawel Palucha - * Bryce Harrington <bryce@bryceharrington.com> + * Bryce Harrington <bryce@bryceharrington.org> * ... and various people who have worked with various projects * Jon A. Cruz <jon@oncruz.org> * Abhishek Sharma diff --git a/src/path-chemistry.cpp b/src/path-chemistry.cpp index e1924664b..52569dd21 100644 --- a/src/path-chemistry.cpp +++ b/src/path-chemistry.cpp @@ -628,7 +628,7 @@ sp_selected_path_reverse(SPDesktop *desktop) SPCurve *rcurve = path->get_curve_reference()->create_reverse(); gchar *str = sp_svg_write_path(rcurve->get_pathvector()); - if ( sp_lpe_item_has_path_effect_recursive(SP_LPE_ITEM(path)) ) { + if ( path->hasPathEffectRecursive() ) { path->getRepr()->setAttribute("inkscape:original-d", str); } else { path->getRepr()->setAttribute("d", str); diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 64ecd6e04..8a414eb4b 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -1182,9 +1182,10 @@ void sp_selection_paste_livepatheffect(SPDesktop *desktop) static void sp_selection_remove_livepatheffect_impl(SPItem *item) { - if ( item && SP_IS_LPE_ITEM(item) && - sp_lpe_item_has_path_effect(SP_LPE_ITEM(item))) { - sp_lpe_item_remove_all_path_effects(SP_LPE_ITEM(item), false); + if ( SPLPEItem *lpeitem = dynamic_cast<SPLPEItem*>(item) ) { + if ( lpeitem->hasPathEffect() ) { + sp_lpe_item_remove_all_path_effects(SP_LPE_ITEM(item), false); + } } } @@ -2318,9 +2319,9 @@ void sp_selection_next_patheffect_param(SPDesktop * dt) Inkscape::Selection *selection = sp_desktop_selection(dt); if ( selection && !selection->isEmpty() ) { SPItem *item = selection->singleItem(); - if ( item && SP_IS_SHAPE(item)) { - if (sp_lpe_item_has_path_effect(SP_LPE_ITEM(item))) { - sp_lpe_item_edit_next_param_oncanvas(SP_LPE_ITEM(item), dt); + if ( SPLPEItem *lpeitem = dynamic_cast<SPLPEItem*>(item) ) { + if (lpeitem->hasPathEffect()) { + sp_lpe_item_edit_next_param_oncanvas(lpeitem, dt); } else { dt->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("The selection has no applied path effect.")); } @@ -2679,7 +2680,7 @@ sp_select_clone_original(SPDesktop *desktop) original = SP_FLOWTEXT(item)->get_frame(NULL); // first frame only } else if (SP_IS_LPE_ITEM(item)) { // check if the applied LPE is Clone original, if so, go to the refered path - Inkscape::LivePathEffect::Effect* lpe = sp_lpe_item_has_path_effect_of_type(SP_LPE_ITEM(item), Inkscape::LivePathEffect::CLONE_ORIGINAL); + Inkscape::LivePathEffect::Effect* lpe = SP_LPE_ITEM(item)->getPathEffectOfType(Inkscape::LivePathEffect::CLONE_ORIGINAL); if (lpe) { Inkscape::LivePathEffect::Parameter *lpeparam = lpe->getParameter("linkedpath"); if (Inkscape::LivePathEffect::OriginalPathParam *pathparam = dynamic_cast<Inkscape::LivePathEffect::OriginalPathParam *>(lpeparam)) { diff --git a/src/selection-describer.cpp b/src/selection-describer.cpp index 96ef3d0d1..5dddb0832 100644 --- a/src/selection-describer.cpp +++ b/src/selection-describer.cpp @@ -39,21 +39,21 @@ #include "sp-spiral.h" // Returns a list of terms for the items to be used in the statusbar -const char* collect_terms (GSList *items) +char* collect_terms (GSList *items) { GSList *check = NULL; std::stringstream ss; bool first = true; for (GSList *i = (GSList *)items; i != NULL; i = i->next) { - const char *term = SP_ITEM(i->data)->display_name(); + const char *term = SP_ITEM(i->data)->displayName(); if (term != NULL && g_slist_find (check, term) == NULL) { check = g_slist_prepend (check, (void *) term); ss << (first ? "" : ", ") << "<b>" << term << "</b>"; first = false; } } - return ss.str().c_str(); + return g_strdup(ss.str().c_str()); } // Returns the number of filtered items in the list @@ -150,16 +150,16 @@ void SelectionDescriber::_updateMessageFromSelection(Inkscape::Selection *select else in_phrase = g_strdup_printf(_(" in group %s (%s)"), parent_name, layer_name); } else { - in_phrase = g_strdup_printf(ngettext(" in <b>%i</b> parents (%s)", " in <b>%i</b> parents (%s)", num_parents), num_parents, layer_name); + in_phrase = g_strdup_printf(ngettext(" in <b>%i</b> parent (%s)", " in <b>%i</b> parents (%s)", num_parents), num_parents, layer_name); } } else { - in_phrase = g_strdup_printf(ngettext(" in <b>%i</b> layers", " in <b>%i</b> layers", num_layers), num_layers); + in_phrase = g_strdup_printf(ngettext(" in <b>%i</b> layer", " in <b>%i</b> layers", num_layers), num_layers); } g_free (layer_name); g_free (parent_name); if (!items->next) { // one item - char *item_desc = item->getDetailedDescription(); + char *item_desc = item->detailedDescription(); if (SP_IS_USE(item) && SP_IS_SYMBOL(item->firstChild())) { _context.setF(Inkscape::NORMAL_MESSAGE, "%s%s. %s. %s.", @@ -187,12 +187,13 @@ void SelectionDescriber::_updateMessageFromSelection(Inkscape::Selection *select } g_free(item_desc); } else { // multiple items - int object_count = g_slist_length((GSList *)items); - const char *terms = collect_terms ((GSList *)items); + int objcount = g_slist_length((GSList *)items); + char *terms = collect_terms ((GSList *)items); - gchar *objects_str = - g_strdup_printf( "<b>%i</b> objects selected of types %s", - object_count, terms ); + gchar *objects_str = g_strdup_printf( + "<b>%i</b> objects selected of types %s", objcount, terms); + + g_free(terms); // indicate all, some, or none filtered gchar *filt_str = NULL; @@ -201,7 +202,7 @@ void SelectionDescriber::_updateMessageFromSelection(Inkscape::Selection *select filt_str = g_strdup_printf(ngettext("; <i>%d filtered object</i> ", "; <i>%d filtered objects</i> ", n_filt), n_filt); } else { - filt_str = g_strdup_printf("%s", ""); + filt_str = g_strdup(""); } _context.setF(Inkscape::NORMAL_MESSAGE, "%s%s%s. %s.", objects_str, filt_str, in_phrase, _when_selected); @@ -211,7 +212,7 @@ void SelectionDescriber::_updateMessageFromSelection(Inkscape::Selection *select } if (filt_str) { g_free(filt_str); - objects_str = 0; + filt_str = 0; } } diff --git a/src/selection.cpp b/src/selection.cpp index 1335c5fca..aea5f539c 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -238,14 +238,7 @@ void Selection::_remove(SPObject *obj) { void Selection::setList(GSList const *list) { _clear(); - - if ( list != NULL ) { - for ( GSList const *iter = list ; iter != NULL ; iter = iter->next ) { - _add(reinterpret_cast<SPObject *>(iter->data)); - } - } - - _emitChanged(); + addList(list); } void Selection::addList(GSList const *list) { @@ -257,9 +250,7 @@ void Selection::addList(GSList const *list) { for ( GSList const *iter = list ; iter != NULL ; iter = iter->next ) { SPObject *obj = reinterpret_cast<SPObject *>(iter->data); - if (includes(obj)) { - continue; - } + if (includes(obj)) continue; _add (obj); } diff --git a/src/sp-anchor.cpp b/src/sp-anchor.cpp index 3ed2c766c..a6a41bef3 100644 --- a/src/sp-anchor.cpp +++ b/src/sp-anchor.cpp @@ -115,7 +115,7 @@ Inkscape::XML::Node* SPAnchor::write(Inkscape::XML::Document *xml_doc, Inkscape: return repr; } -const char* SPAnchor::display_name() { +const char* SPAnchor::displayName() { return _("Link"); } diff --git a/src/sp-anchor.h b/src/sp-anchor.h index a88778132..39f6d0b7a 100644 --- a/src/sp-anchor.h +++ b/src/sp-anchor.h @@ -30,7 +30,7 @@ public: virtual void set(unsigned int key, gchar const* value); virtual Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); - virtual const char* display_name(); + virtual const char* displayName(); virtual gchar* description(); virtual gint event(SPEvent *event); }; diff --git a/src/sp-ellipse.cpp b/src/sp-ellipse.cpp index cb39ef0ec..2d73ff35f 100644 --- a/src/sp-ellipse.cpp +++ b/src/sp-ellipse.cpp @@ -144,7 +144,7 @@ void SPGenericEllipse::update_patheffect(bool write) { /* fixme: Think (Lauris) */ /* Can't we use arcto in this method? */ void SPGenericEllipse::set_shape() { - if (sp_lpe_item_has_broken_path_effect(this)) { + if (hasBrokenPathEffect()) { g_warning ("The ellipse shape has unknown LPE on it! Convert to path to make it editable preserving the appearance; editing it as ellipse will remove the bad LPE"); if (this->getRepr()->attribute("d")) { @@ -233,7 +233,7 @@ void SPGenericEllipse::set_shape() { this->setCurveInsync( curve, TRUE); this->setCurveBeforeLPE(curve); - if (sp_lpe_item_has_path_effect(this) && sp_lpe_item_path_effects_enabled(this)) { + if (hasPathEffect() && sp_lpe_item_path_effects_enabled(this)) { SPCurve *c_lpe = curve->copy(); bool success = sp_lpe_item_perform_path_effect(this, c_lpe); @@ -480,7 +480,7 @@ void SPEllipse::set(unsigned int key, gchar const* value) { } } -const char* SPEllipse::display_name() { +const char* SPEllipse::displayName() { return _("Ellipse"); } @@ -560,7 +560,7 @@ void SPCircle::set(unsigned int key, gchar const* value) { } } -const char* SPCircle::display_name() { +const char* SPCircle::displayName() { return _("Circle"); } @@ -734,7 +734,7 @@ void SPArc::modified(guint flags) { } -const char* SPArc::display_name() { +const char* SPArc::displayName() { gdouble len = fmod(this->end - this->start, SP_2PI); if (len < 0.0) { diff --git a/src/sp-ellipse.h b/src/sp-ellipse.h index b74beeae0..083f5847d 100644 --- a/src/sp-ellipse.h +++ b/src/sp-ellipse.h @@ -59,7 +59,7 @@ public: virtual void build(SPDocument *document, Inkscape::XML::Node *repr); virtual Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); virtual void set(unsigned int key, gchar const* value); - virtual const char* display_name(); + virtual const char* displayName(); }; void sp_ellipse_position_set (SPEllipse * ellipse, gdouble x, gdouble y, gdouble rx, gdouble ry); @@ -76,7 +76,7 @@ public: virtual void build(SPDocument *document, Inkscape::XML::Node *repr); virtual Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); virtual void set(unsigned int key, gchar const* value); - virtual const char* display_name(); + virtual const char* displayName(); }; /* <path sodipodi:type="arc"> element */ @@ -91,7 +91,7 @@ public: virtual void build(SPDocument *document, Inkscape::XML::Node *repr); virtual Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); virtual void set(unsigned int key, gchar const* value); - virtual const char* display_name(); + virtual const char* displayName(); virtual void modified(unsigned int flags); }; diff --git a/src/sp-flowregion.cpp b/src/sp-flowregion.cpp index caa6aef76..ed17f1948 100644 --- a/src/sp-flowregion.cpp +++ b/src/sp-flowregion.cpp @@ -188,7 +188,7 @@ Inkscape::XML::Node *SPFlowregion::write(Inkscape::XML::Document *xml_doc, Inksc return repr; } -const char* SPFlowregion::display_name() { +const char* SPFlowregion::displayName() { // TRANSLATORS: "Flow region" is an area where text is allowed to flow return _("Flow Region"); } @@ -335,7 +335,7 @@ Inkscape::XML::Node *SPFlowregionExclude::write(Inkscape::XML::Document *xml_doc return repr; } -const char* SPFlowregionExclude::display_name() { +const char* SPFlowregionExclude::displayName() { /* TRANSLATORS: A region "cut out of" a flow region; text is not allowed to flow inside the * flow excluded region. flowRegionExclude in SVG 1.2: see * http://www.w3.org/TR/2004/WD-SVG12-20041027/flow.html#flowRegion-elem and diff --git a/src/sp-flowregion.h b/src/sp-flowregion.h index 600b2aa6e..111a32c6c 100644 --- a/src/sp-flowregion.h +++ b/src/sp-flowregion.h @@ -31,7 +31,7 @@ public: virtual void update(SPCtx *ctx, unsigned int flags); virtual void modified(guint flags); virtual Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); - virtual const char* display_name(); + virtual const char* displayName(); }; class SPFlowregionExclude : public SPItem { @@ -48,7 +48,7 @@ public: virtual void update(SPCtx *ctx, unsigned int flags); virtual void modified(guint flags); virtual Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); - virtual const char* display_name(); + virtual const char* displayName(); }; #endif diff --git a/src/sp-flowtext.cpp b/src/sp-flowtext.cpp index d46a644cf..5e13218f5 100644 --- a/src/sp-flowtext.cpp +++ b/src/sp-flowtext.cpp @@ -204,7 +204,7 @@ void SPFlowtext::set(unsigned int key, const gchar* value) { if ( val == NULL ) { this->par_indent = 0.0; } else { - sp_repr_get_double((Inkscape::XML::Node*)opts, "par-indent", &this->par_indent); + this->par_indent = g_ascii_strtod(val, NULL); } } @@ -281,7 +281,7 @@ void SPFlowtext::print(SPPrintContext *ctx) { this->layout.print(ctx, pbox, dbox, bbox, ctm); } -const char* SPFlowtext::display_name() { +const char* SPFlowtext::displayName() { if (SP_FLOWTEXT(this)->has_internal_frame()) { return _("Flowed Text"); } else { diff --git a/src/sp-flowtext.h b/src/sp-flowtext.h index de328608f..f56cba3cd 100644 --- a/src/sp-flowtext.h +++ b/src/sp-flowtext.h @@ -73,7 +73,7 @@ public: virtual Geom::OptRect bbox(Geom::Affine const &transform, SPItem::BBoxType type); virtual void print(SPPrintContext *ctx); - virtual const char* display_name(); + virtual const char* displayName(); virtual gchar* description(); virtual Inkscape::DrawingItem* show(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags); virtual void hide(unsigned int key); diff --git a/src/sp-image.cpp b/src/sp-image.cpp index 38c749dd3..05dfb5f48 100644 --- a/src/sp-image.cpp +++ b/src/sp-image.cpp @@ -610,7 +610,7 @@ void SPImage::print(SPPrintContext *ctx) { } } -const char* SPImage::display_name() { +const char* SPImage::displayName() { return _("Image"); } diff --git a/src/sp-image.h b/src/sp-image.h index 85eceac20..b5834c988 100644 --- a/src/sp-image.h +++ b/src/sp-image.h @@ -64,7 +64,7 @@ public: virtual Geom::OptRect bbox(Geom::Affine const &transform, SPItem::BBoxType type); virtual void print(SPPrintContext *ctx); - virtual const char* display_name(); + virtual const char* displayName(); virtual gchar* description(); virtual Inkscape::DrawingItem* show(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags); virtual void snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs); diff --git a/src/sp-item-group.cpp b/src/sp-item-group.cpp index 720f6857a..bdcfe46d0 100644 --- a/src/sp-item-group.cpp +++ b/src/sp-item-group.cpp @@ -328,7 +328,7 @@ void SPGroup::print(SPPrintContext *ctx) { } } -const char *SPGroup::display_name() { +const char *SPGroup::displayName() { return _("Group"); } @@ -765,7 +765,7 @@ void SPGroup::update_patheffect(bool write) { } } - if (sp_lpe_item_has_path_effect(this) && sp_lpe_item_path_effects_enabled(this)) { + if (hasPathEffect() && sp_lpe_item_path_effects_enabled(this)) { for (PathEffectList::iterator it = this->path_effect_list->begin(); it != this->path_effect_list->end(); it++) { LivePathEffectObject *lpeobj = (*it)->lpeobject; diff --git a/src/sp-item-group.h b/src/sp-item-group.h index 24c24abbd..3954a5d21 100644 --- a/src/sp-item-group.h +++ b/src/sp-item-group.h @@ -76,7 +76,7 @@ public: virtual Geom::OptRect bbox(Geom::Affine const &transform, SPItem::BBoxType bboxtype); virtual void print(SPPrintContext *ctx); - virtual const char* display_name(); + virtual const char* displayName(); virtual gchar *description(); virtual Inkscape::DrawingItem *show (Inkscape::Drawing &drawing, unsigned int key, unsigned int flags); virtual void hide (unsigned int key); diff --git a/src/sp-item.cpp b/src/sp-item.cpp index b7ef68f7d..a99bf85cc 100644 --- a/src/sp-item.cpp +++ b/src/sp-item.cpp @@ -933,7 +933,7 @@ void SPItem::invoke_print(SPPrintContext *ctx) } } -const char* SPItem::display_name() { +const char* SPItem::displayName() { return _("Object"); } @@ -946,10 +946,10 @@ gchar* SPItem::description() { * * Must be freed by caller. */ -gchar *SPItem::getDetailedDescription() +gchar *SPItem::detailedDescription() { gchar* s = g_strdup_printf("<b>%s</b> %s", - this->display_name(), this->description()); + this->displayName(), this->description()); if (s && clip_ref->getObject()) { gchar *snew = g_strdup_printf (_("%s; <i>clipped</i>"), s); @@ -1287,7 +1287,7 @@ void SPItem::adjust_livepatheffect (Geom::Affine const &postmul, bool set) { if ( SP_IS_LPE_ITEM(this) ) { SPLPEItem *lpeitem = SP_LPE_ITEM (this); - if ( sp_lpe_item_has_path_effect(lpeitem) ) { + if ( lpeitem->hasPathEffect() ) { sp_lpe_item_fork_path_effects_if_necessary(lpeitem); // now that all LPEs are forked_if_necessary, we can apply the transform diff --git a/src/sp-item.h b/src/sp-item.h index 769af229e..ce5400e66 100644 --- a/src/sp-item.h +++ b/src/sp-item.h @@ -188,7 +188,7 @@ public: Geom::OptRect desktopBounds(BBoxType type) const; unsigned pos_in_parent(); - gchar *getDetailedDescription(); + gchar *detailedDescription(); int ifilt(); void invoke_print(SPPrintContext *ctx); static unsigned int display_key_new(unsigned int numkeys); @@ -236,7 +236,7 @@ public: virtual Geom::OptRect bbox(Geom::Affine const &transform, SPItem::BBoxType type); virtual void print(SPPrintContext *ctx); - virtual const char* display_name(); + virtual const char* displayName(); virtual gchar* description(); virtual Inkscape::DrawingItem* show(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags); virtual void hide(unsigned int key); diff --git a/src/sp-line.cpp b/src/sp-line.cpp index c3a0b13db..6b7df84f6 100644 --- a/src/sp-line.cpp +++ b/src/sp-line.cpp @@ -122,7 +122,7 @@ Inkscape::XML::Node* SPLine::write(Inkscape::XML::Document *xml_doc, Inkscape::X return repr; } -const char* SPLine::display_name() { +const char* SPLine::displayName() { return _("Line"); } diff --git a/src/sp-line.h b/src/sp-line.h index 7184b9401..f76c3449b 100644 --- a/src/sp-line.h +++ b/src/sp-line.h @@ -34,7 +34,7 @@ public: virtual Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); virtual void set(unsigned int key, gchar const* value); - virtual const char* display_name(); + virtual const char* displayName(); virtual Geom::Affine set_transform(Geom::Affine const &transform); virtual void convert_to_guides(); virtual void update(SPCtx* ctx, guint flags); diff --git a/src/sp-lpe-item.cpp b/src/sp-lpe-item.cpp index c86730048..b3e6182a4 100644 --- a/src/sp-lpe-item.cpp +++ b/src/sp-lpe-item.cpp @@ -181,7 +181,7 @@ void SPLPEItem::modified(unsigned int flags) { Inkscape::XML::Node* SPLPEItem::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { if (flags & SP_OBJECT_WRITE_EXT) { - if ( sp_lpe_item_has_path_effect(this) ) { + if ( hasPathEffect() ) { std::string href = patheffectlist_write_svg(*this->path_effect_list); repr->setAttribute("inkscape:path-effect", href.c_str()); } else { @@ -206,7 +206,7 @@ bool sp_lpe_item_perform_path_effect(SPLPEItem *lpeitem, SPCurve *curve) { return false; } - if (sp_lpe_item_has_path_effect(lpeitem) && sp_lpe_item_path_effects_enabled(lpeitem)) { + if (lpeitem->hasPathEffect() && sp_lpe_item_path_effects_enabled(lpeitem)) { for (PathEffectList::iterator it = lpeitem->path_effect_list->begin(); it != lpeitem->path_effect_list->end(); ++it) { LivePathEffectObject *lpeobj = (*it)->lpeobject; @@ -292,16 +292,16 @@ sp_lpe_item_update_patheffect (SPLPEItem *lpeitem, bool wholetree, bool write) } } - SPLPEItem *top; + SPLPEItem *top = NULL; if (wholetree) { - SPObject *prev_parent = lpeitem; - SPObject *parent = prev_parent->parent; - while (parent && SP_IS_LPE_ITEM(parent) && sp_lpe_item_has_path_effect_recursive(SP_LPE_ITEM(parent))) { + SPLPEItem *prev_parent = lpeitem; + SPLPEItem *parent = dynamic_cast<SPLPEItem*>(prev_parent->parent); + while (parent && parent->hasPathEffectRecursive()) { prev_parent = parent; - parent = prev_parent->parent; + parent = dynamic_cast<SPLPEItem*>(prev_parent->parent); } - top = SP_LPE_ITEM(prev_parent); + top = prev_parent; } else { top = lpeitem; @@ -356,8 +356,7 @@ sp_lpe_item_cleanup_original_path_recursive(SPLPEItem *lpeitem) } else if (SP_IS_PATH(lpeitem)) { Inkscape::XML::Node *repr = lpeitem->getRepr(); - if (!sp_lpe_item_has_path_effect_recursive(lpeitem) - && repr->attribute("inkscape:original-d")) { + if (!lpeitem->hasPathEffectRecursive() && repr->attribute("inkscape:original-d")) { repr->setAttribute("d", repr->attribute("inkscape:original-d")); repr->setAttribute("inkscape:original-d", NULL); } @@ -495,57 +494,58 @@ void sp_lpe_item_up_current_path_effect(SPLPEItem *lpeitem) } /** used for shapes so they can see if they should also disable shape calculation and read from d= */ -bool sp_lpe_item_has_broken_path_effect(SPLPEItem const *lpeitem) +bool SPLPEItem::hasBrokenPathEffect() const { - if (lpeitem->path_effect_list->empty()) + if (path_effect_list->empty()) { return false; + } // go through the list; if some are unknown or invalid, return true - PathEffectList const effect_list = sp_lpe_item_get_effect_list(lpeitem); - for (PathEffectList::const_iterator it = effect_list.begin(); it != effect_list.end(); ++it) + for (PathEffectList::const_iterator it = path_effect_list->begin(); it != path_effect_list->end(); ++it) { LivePathEffectObject *lpeobj = (*it)->lpeobject; - if (!lpeobj || !lpeobj->get_lpe()) + if (!lpeobj || !lpeobj->get_lpe()) { return true; + } } return false; } -bool sp_lpe_item_has_path_effect(SPLPEItem const *lpeitem) +bool SPLPEItem::hasPathEffect() const { - if (lpeitem->path_effect_list->empty()) + if (path_effect_list->empty()) { return false; + } // go through the list; if some are unknown or invalid, we are not an LPE item! - PathEffectList const effect_list = sp_lpe_item_get_effect_list(lpeitem); - for (PathEffectList::const_iterator it = effect_list.begin(); it != effect_list.end(); ++it) + for (PathEffectList::const_iterator it = path_effect_list->begin(); it != path_effect_list->end(); ++it) { LivePathEffectObject *lpeobj = (*it)->lpeobject; - if (!lpeobj || !lpeobj->get_lpe()) + if (!lpeobj || !lpeobj->get_lpe()) { return false; + } } return true; } -bool sp_lpe_item_has_path_effect_recursive(SPLPEItem const *lpeitem) +bool SPLPEItem::hasPathEffectRecursive() const { - SPObject const *parent = lpeitem->parent; if (parent && SP_IS_LPE_ITEM(parent)) { - return sp_lpe_item_has_path_effect(lpeitem) || sp_lpe_item_has_path_effect_recursive(SP_LPE_ITEM(parent)); + return hasPathEffect() || SP_LPE_ITEM(parent)->hasPathEffectRecursive(); } else { - return sp_lpe_item_has_path_effect(lpeitem); + return hasPathEffect(); } } Inkscape::LivePathEffect::Effect* -sp_lpe_item_has_path_effect_of_type(SPLPEItem *lpeitem, int type) +SPLPEItem::getPathEffectOfType(int type) { std::list<Inkscape::LivePathEffect::LPEObjectReference *>::iterator i; - for (i = lpeitem->path_effect_list->begin(); i != lpeitem->path_effect_list->end(); ++i) { + for (i = path_effect_list->begin(); i != path_effect_list->end(); ++i) { Inkscape::LivePathEffect::Effect* lpe = (*i)->lpeobject->get_lpe(); if (lpe && (lpe->effectType() == type)) { return lpe; @@ -560,8 +560,9 @@ bool sp_lpe_item_can_accept_freehand_shape(SPLPEItem *lpeitem) if (!SP_IS_PATH(lpeitem)) return false; - if (sp_lpe_item_has_path_effect_of_type(lpeitem, Inkscape::LivePathEffect::FREEHAND_SHAPE)) + if (lpeitem->getPathEffectOfType(Inkscape::LivePathEffect::FREEHAND_SHAPE)) { return false; + } return true; } @@ -577,7 +578,7 @@ void sp_lpe_item_edit_next_param_oncanvas(SPLPEItem *lpeitem, SPDesktop *dt) void SPLPEItem::child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) { SPItem::child_added(child, ref); - if (sp_lpe_item_has_path_effect_recursive(this)) { + if (this->hasPathEffectRecursive()) { SPObject *ochild = this->get_child_by_repr(child); if ( ochild && SP_IS_LPE_ITEM(ochild) ) { @@ -586,7 +587,7 @@ void SPLPEItem::child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *ref } } void SPLPEItem::remove_child(Inkscape::XML::Node * child) { - if (sp_lpe_item_has_path_effect_recursive(this)) { + if (this->hasPathEffectRecursive()) { SPObject *ochild = this->get_child_by_repr(child); if ( ochild && SP_IS_LPE_ITEM(ochild) ) { @@ -717,7 +718,7 @@ bool sp_lpe_item_fork_path_effects_if_necessary(SPLPEItem *lpeitem, unsigned int { bool forked = false; - if ( sp_lpe_item_has_path_effect(lpeitem) ) { + if ( lpeitem->hasPathEffect() ) { // If one of the path effects is used by 2 or more items, fork it // so that each object has its own independent copy of the effect. // Note: replacing path effects messes up the path effect list diff --git a/src/sp-lpe-item.h b/src/sp-lpe-item.h index 925ff34d8..81adb938a 100644 --- a/src/sp-lpe-item.h +++ b/src/sp-lpe-item.h @@ -69,6 +69,11 @@ public: virtual Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); virtual void update_patheffect(bool write); + + bool hasPathEffect() const; + bool hasPathEffectRecursive() const; + Inkscape::LivePathEffect::Effect* getPathEffectOfType(int type); + bool hasBrokenPathEffect() const; }; void sp_lpe_item_update_patheffect (SPLPEItem *lpeitem, bool wholetree, bool write); @@ -80,10 +85,6 @@ void sp_lpe_item_remove_all_path_effects(SPLPEItem *lpeitem, bool keep_paths); void sp_lpe_item_remove_current_path_effect(SPLPEItem *lpeitem, bool keep_paths); void sp_lpe_item_down_current_path_effect(SPLPEItem *lpeitem); void sp_lpe_item_up_current_path_effect(SPLPEItem *lpeitem); -bool sp_lpe_item_has_path_effect(SPLPEItem const *lpeitem); -bool sp_lpe_item_has_broken_path_effect(SPLPEItem const *lpeitem); -bool sp_lpe_item_has_path_effect_recursive(SPLPEItem const *lpeitem); -Inkscape::LivePathEffect::Effect* sp_lpe_item_has_path_effect_of_type(SPLPEItem *lpeitem, int type); bool sp_lpe_item_can_accept_freehand_shape(SPLPEItem *lpeitem); void sp_lpe_item_edit_next_param_oncanvas(SPLPEItem *lpeitem, SPDesktop *dt); PathEffectList sp_lpe_item_get_effect_list(SPLPEItem *lpeitem); diff --git a/src/sp-object.cpp b/src/sp-object.cpp index 8c7a24a2b..6fd4de43b 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -597,7 +597,9 @@ void SPObject::child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) ochild->invoke_build(object->document, child, object->cloned); } catch (const FactoryExceptions::TypeNotRegistered& e) { std::string node = e.what(); + // special cases + if (node.empty()) return; // comments, usually if (node == "rdf:RDF") return; // no SP node yet if (node == "inkscape:clipboard") return; // SP node not necessary @@ -646,27 +648,21 @@ void SPObject::build(SPDocument *document, Inkscape::XML::Node *repr) { object->readAttr("inkscape:collect"); for (Inkscape::XML::Node *rchild = repr->firstChild() ; rchild != NULL; rchild = rchild->next()) { -// GType type = sp_repr_type_lookup(rchild); -// if (!type) { -// continue; -// } -// SPObject *child = SP_OBJECT(g_object_new(type, 0)); - -// SPObject* child = SPFactory::instance().createObject(*rchild); -// if (!child) { -// continue; -// } - try { const std::string typeString = NodeTraits::get_type_string(*rchild); + // special cases + if (typeString.empty()) continue; // comments, usually + if (typeString == "rdf:RDF") continue; // no SP node yet + if (typeString == "inkscape:clipboard") continue; // SP node not necessary + SPObject* child = SPFactory::instance().createObject(typeString); object->attach(child, object->lastChild()); sp_object_unref(child, NULL); child->invoke_build(document, rchild, object->cloned); } catch (const FactoryExceptions::TypeNotRegistered& e) { - //g_warning("TypeNotRegistered exception: %s", e.what()); + g_warning("TypeNotRegistered exception: %s", e.what()); } } } diff --git a/src/sp-offset.cpp b/src/sp-offset.cpp index f9759cac1..f0b152d0e 100644 --- a/src/sp-offset.cpp +++ b/src/sp-offset.cpp @@ -339,7 +339,7 @@ void SPOffset::update(SPCtx *ctx, guint flags) { SPShape::update(ctx, flags); } -const char* SPOffset::display_name() { +const char* SPOffset::displayName() { if ( this->sourceHref ) { return _("Linked Offset"); } else { diff --git a/src/sp-offset.h b/src/sp-offset.h index 360bfbf94..b93a6846b 100644 --- a/src/sp-offset.h +++ b/src/sp-offset.h @@ -82,7 +82,7 @@ public: virtual void release(); virtual void snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs); - virtual const char* display_name(); + virtual const char* displayName(); virtual gchar* description(); virtual void set_shape(); diff --git a/src/sp-path.cpp b/src/sp-path.cpp index 49e40fd24..af2f02328 100644 --- a/src/sp-path.cpp +++ b/src/sp-path.cpp @@ -66,7 +66,7 @@ gint SPPath::nodesInPath() const return _curve ? _curve->nodes_in_path() : 0; } -const char* SPPath::display_name() { +const char* SPPath::displayName() { return _("Path"); } @@ -74,7 +74,7 @@ gchar* SPPath::description() { int count = this->nodesInPath(); char *lpe_desc = g_strdup(""); - if (sp_lpe_item_has_path_effect(this)) { + if (hasPathEffect()) { Glib::ustring s; PathEffectList effect_list = sp_lpe_item_get_effect_list(this); @@ -259,20 +259,20 @@ void SPPath::update(SPCtx *ctx, guint flags) { } Geom::Affine SPPath::set_transform(Geom::Affine const &transform) { - if (!this->_curve) { // 0 nodes, nothing to transform + if (!_curve) { // 0 nodes, nothing to transform return Geom::identity(); } // Transform the original-d path if this is a valid LPE this, other else the (ordinary) path - if (this->_curve_before_lpe && sp_lpe_item_has_path_effect_recursive(this)) { - if (sp_lpe_item_has_path_effect_of_type(this, Inkscape::LivePathEffect::CLONE_ORIGINAL)) { + if (_curve_before_lpe && hasPathEffectRecursive()) { + if (getPathEffectOfType(Inkscape::LivePathEffect::CLONE_ORIGINAL)) { // if path has the CLONE_ORIGINAL LPE applied, don't write the transform to the pathdata, but write it 'unoptimized' return transform; } else { - this->_curve_before_lpe->transform(transform); + _curve_before_lpe->transform(transform); } } else { - this->_curve->transform(transform); + _curve->transform(transform); } // Adjust stroke @@ -301,8 +301,8 @@ void SPPath::update_patheffect(bool write) { g_message("sp_path_update_patheffect"); #endif - if (this->_curve_before_lpe && sp_lpe_item_has_path_effect_recursive(this)) { - SPCurve *curve = this->_curve_before_lpe->copy(); + if (_curve_before_lpe && hasPathEffectRecursive()) { + SPCurve *curve = _curve_before_lpe->copy(); /* if a path has an lpeitem applied, then reset the curve to the _curve_before_lpe. * This is very important for LPEs to work properly! (the bbox might be recalculated depending on the curve in shape)*/ this->setCurveInsync(curve, TRUE); @@ -315,7 +315,7 @@ g_message("sp_path_update_patheffect"); g_message("sp_path_update_patheffect writes 'd' attribute"); #endif - if ( this->_curve != NULL ) { + if (_curve) { gchar *str = sp_svg_write_path(this->_curve->get_pathvector()); repr->setAttribute("d", str); g_free(str); @@ -385,7 +385,7 @@ SPCurve * SPPath::get_original_curve () const */ SPCurve* SPPath::get_curve_for_edit () const { - if (_curve_before_lpe && sp_lpe_item_has_path_effect_recursive(SP_LPE_ITEM(this))) { + if (_curve_before_lpe && hasPathEffectRecursive()) { return get_original_curve(); } else { return getCurve(); @@ -398,7 +398,7 @@ SPCurve* SPPath::get_curve_for_edit () const */ const SPCurve* SPPath::get_curve_reference () const { - if (_curve_before_lpe && sp_lpe_item_has_path_effect_recursive(SP_LPE_ITEM(this))) { + if (_curve_before_lpe && hasPathEffectRecursive()) { return _curve_before_lpe; } else { return _curve; @@ -411,7 +411,7 @@ const SPCurve* SPPath::get_curve_reference () const */ SPCurve* SPPath::get_curve () { - if (_curve_before_lpe && sp_lpe_item_has_path_effect_recursive(SP_LPE_ITEM(this))) { + if (_curve_before_lpe && hasPathEffectRecursive()) { return _curve_before_lpe; } else { return _curve; diff --git a/src/sp-path.h b/src/sp-path.h index ca25de33b..77c64a2cc 100644 --- a/src/sp-path.h +++ b/src/sp-path.h @@ -54,7 +54,7 @@ public: virtual void set(unsigned int key, gchar const* value); virtual Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); - virtual const char* display_name(); + virtual const char* displayName(); virtual gchar* description(); virtual Geom::Affine set_transform(Geom::Affine const &transform); virtual void convert_to_guides(); diff --git a/src/sp-rect.cpp b/src/sp-rect.cpp index 6d5119e4c..ff5e81f95 100644 --- a/src/sp-rect.cpp +++ b/src/sp-rect.cpp @@ -159,7 +159,7 @@ Inkscape::XML::Node * SPRect::write(Inkscape::XML::Document *xml_doc, Inkscape:: return repr; } -const char* SPRect::display_name() { +const char* SPRect::displayName() { return _("Rectangle"); } diff --git a/src/sp-rect.h b/src/sp-rect.h index e06833916..3219a3ace 100644 --- a/src/sp-rect.h +++ b/src/sp-rect.h @@ -55,7 +55,7 @@ public: virtual void update(SPCtx* ctx, unsigned int flags); virtual Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); - virtual const char* display_name(); + virtual const char* displayName(); virtual void set_shape(); virtual Geom::Affine set_transform(Geom::Affine const& xform); diff --git a/src/sp-shape.cpp b/src/sp-shape.cpp index 8f3d5117f..7efe28dd8 100644 --- a/src/sp-shape.cpp +++ b/src/sp-shape.cpp @@ -1003,7 +1003,7 @@ SPCurve * SPShape::getCurve() const */ SPCurve * SPShape::getCurveBeforeLPE() const { - if (sp_lpe_item_has_path_effect(this)) { + if (hasPathEffect()) { if (_curve_before_lpe) { return this->_curve_before_lpe->copy(); } diff --git a/src/sp-spiral.cpp b/src/sp-spiral.cpp index e4bfb8c76..e911e722c 100644 --- a/src/sp-spiral.cpp +++ b/src/sp-spiral.cpp @@ -226,7 +226,7 @@ void SPSpiral::update_patheffect(bool write) { shape->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } -const char* SPSpiral::display_name() { +const char* SPSpiral::displayName() { return _("Spiral"); } @@ -326,7 +326,7 @@ void SPSpiral::set_shape() { SPSpiral *spiral = this; SPSpiral* shape = spiral; - if (sp_lpe_item_has_broken_path_effect(SP_LPE_ITEM(shape))) { + if (hasBrokenPathEffect()) { g_warning ("The spiral shape has unknown LPE on it! Convert to path to make it editable preserving the appearance; editing it as spiral will remove the bad LPE"); if (shape->getRepr()->attribute("d")) { @@ -380,12 +380,12 @@ void SPSpiral::set_shape() { /* Reset the shape'scurve to the "original_curve" * This is very important for LPEs to work properly! (the bbox might be recalculated depending on the curve in shape)*/ - shape->setCurveInsync( c, TRUE); - shape->setCurveBeforeLPE( c ); + setCurveInsync( c, TRUE); + setCurveBeforeLPE( c ); - if (sp_lpe_item_has_path_effect(SP_LPE_ITEM(shape)) && sp_lpe_item_path_effects_enabled(SP_LPE_ITEM(shape))) { + if (hasPathEffect() && sp_lpe_item_path_effects_enabled(this)) { SPCurve *c_lpe = c->copy(); - bool success = sp_lpe_item_perform_path_effect(SP_LPE_ITEM (shape), c_lpe); + bool success = sp_lpe_item_perform_path_effect(this, c_lpe); if (success) { shape->setCurveInsync( c_lpe, TRUE); diff --git a/src/sp-spiral.h b/src/sp-spiral.h index a140d48f9..a81b4a3dd 100644 --- a/src/sp-spiral.h +++ b/src/sp-spiral.h @@ -72,7 +72,7 @@ public: virtual void set(unsigned int key, gchar const* value); virtual void snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs); - virtual const char* display_name(); + virtual const char* displayName(); virtual gchar* description(); virtual void set_shape(); diff --git a/src/sp-star.cpp b/src/sp-star.cpp index bc3155caf..c2c0883e5 100644 --- a/src/sp-star.cpp +++ b/src/sp-star.cpp @@ -251,7 +251,7 @@ void SPStar::update_patheffect(bool write) { this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } -const char* SPStar::display_name() { +const char* SPStar::displayName() { if (this->flatsided == false) return _("Star"); return _("Polygon"); @@ -378,7 +378,7 @@ void SPStar::set_shape() { // perhaps we should convert all our shapes into LPEs without source path // and with knotholders for parameters, then this situation will be handled automatically // by disabling the entire stack (including the shape LPE) - if (sp_lpe_item_has_broken_path_effect(SP_LPE_ITEM(this))) { + if (hasBrokenPathEffect()) { g_warning ("The star shape has unknown LPE on it! Convert to path to make it editable preserving the appearance; editing it as star will remove the bad LPE"); if (this->getRepr()->attribute("d")) { @@ -395,7 +395,6 @@ void SPStar::set_shape() { SPCurve *c = new SPCurve (); - gint sides = this->sides; bool not_rounded = (fabs (this->rounded) < 1e-4); // note that we pass randomized=true to sp_star_get_xy, because the curve must be randomized; @@ -461,9 +460,9 @@ void SPStar::set_shape() { this->setCurveInsync( c, TRUE); this->setCurveBeforeLPE( c ); - if (sp_lpe_item_has_path_effect(SP_LPE_ITEM(this)) && sp_lpe_item_path_effects_enabled(SP_LPE_ITEM(this))) { + if (hasPathEffect() && sp_lpe_item_path_effects_enabled(this)) { SPCurve *c_lpe = c->copy(); - bool success = sp_lpe_item_perform_path_effect(SP_LPE_ITEM (this), c_lpe); + bool success = sp_lpe_item_perform_path_effect(this, c_lpe); if (success) { this->setCurveInsync( c_lpe, TRUE); diff --git a/src/sp-star.h b/src/sp-star.h index 3096862cd..799880c42 100644 --- a/src/sp-star.h +++ b/src/sp-star.h @@ -50,7 +50,7 @@ public: virtual void set(unsigned int key, gchar const* value); virtual void update(SPCtx* ctx, guint flags); - virtual const char* display_name(); + virtual const char* displayName(); virtual gchar* description(); virtual void snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs); diff --git a/src/sp-switch.cpp b/src/sp-switch.cpp index c6dcf17e3..fa97cde91 100644 --- a/src/sp-switch.cpp +++ b/src/sp-switch.cpp @@ -71,7 +71,7 @@ GSList *SPSwitch::_childList(bool add_ref, SPObject::Action action) { return g_slist_prepend (NULL, child); } -const char *SPSwitch::display_name() { +const char *SPSwitch::displayName() { return _("Conditional Group"); } diff --git a/src/sp-switch.h b/src/sp-switch.h index 5627784cf..e6dc6f01f 100644 --- a/src/sp-switch.h +++ b/src/sp-switch.h @@ -41,7 +41,7 @@ public: virtual void child_added(Inkscape::XML::Node* child, Inkscape::XML::Node* ref); virtual void remove_child(Inkscape::XML::Node *child); virtual void order_changed(Inkscape::XML::Node *child, Inkscape::XML::Node *old_ref, Inkscape::XML::Node *new_ref); - virtual const char* display_name(); + virtual const char* displayName(); virtual gchar *description(); }; diff --git a/src/sp-text.cpp b/src/sp-text.cpp index 927536dde..72a5996d1 100644 --- a/src/sp-text.cpp +++ b/src/sp-text.cpp @@ -321,7 +321,7 @@ void SPText::hide(unsigned int key) { // SPItem::onHide(key); } -const char* SPText::display_name() { +const char* SPText::displayName() { return _("Text"); } diff --git a/src/sp-text.h b/src/sp-text.h index 9b8afea6d..a7149159a 100644 --- a/src/sp-text.h +++ b/src/sp-text.h @@ -84,7 +84,7 @@ public: virtual Geom::OptRect bbox(Geom::Affine const &transform, SPItem::BBoxType type); virtual void print(SPPrintContext *ctx); - virtual const char* display_name(); + virtual const char* displayName(); virtual gchar* description(); virtual Inkscape::DrawingItem* show(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags); virtual void hide(unsigned int key); diff --git a/src/sp-tref.cpp b/src/sp-tref.cpp index f0a4af667..4f9947a04 100644 --- a/src/sp-tref.cpp +++ b/src/sp-tref.cpp @@ -233,7 +233,7 @@ Geom::OptRect SPTRef::bbox(Geom::Affine const &transform, SPItem::BBoxType type) return bbox; } -const char* SPTRef::display_name() { +const char* SPTRef::displayName() { return _("Cloned Character Data"); } @@ -244,7 +244,7 @@ gchar* SPTRef::description() { char *child_desc; if (SP_IS_ITEM(referred)) { - child_desc = SP_ITEM(referred)->getDetailedDescription(); + child_desc = SP_ITEM(referred)->detailedDescription(); } else { child_desc = g_strdup(""); } diff --git a/src/sp-tref.h b/src/sp-tref.h index c82970a7f..6d43d679d 100644 --- a/src/sp-tref.h +++ b/src/sp-tref.h @@ -58,7 +58,7 @@ public: virtual Inkscape::XML::Node* write(Inkscape::XML::Document* doc, Inkscape::XML::Node* repr, guint flags); virtual Geom::OptRect bbox(Geom::Affine const &transform, SPItem::BBoxType type); - virtual const char* display_name(); + virtual const char* displayName(); virtual gchar* description(); }; diff --git a/src/sp-tspan.cpp b/src/sp-tspan.cpp index 43a9faa5e..21c5ee11f 100644 --- a/src/sp-tspan.cpp +++ b/src/sp-tspan.cpp @@ -216,7 +216,7 @@ Inkscape::XML::Node* SPTSpan::write(Inkscape::XML::Document *xml_doc, Inkscape:: return repr; } -const char* SPTSpan::display_name() { +const char* SPTSpan::displayName() { return _("Text Span"); } diff --git a/src/sp-tspan.h b/src/sp-tspan.h index ee05073cd..a7ae563bb 100644 --- a/src/sp-tspan.h +++ b/src/sp-tspan.h @@ -34,7 +34,7 @@ public: virtual Inkscape::XML::Node* write(Inkscape::XML::Document* doc, Inkscape::XML::Node* repr, guint flags); virtual Geom::OptRect bbox(Geom::Affine const &transform, SPItem::BBoxType type); - virtual const char* display_name(); + virtual const char* displayName(); }; #endif /* !INKSCAPE_SP_TSPAN_H */ diff --git a/src/sp-use.cpp b/src/sp-use.cpp index 05e1f0e66..56cac1981 100644 --- a/src/sp-use.cpp +++ b/src/sp-use.cpp @@ -226,7 +226,7 @@ void SPUse::print(SPPrintContext* ctx) { } } -const char* SPUse::display_name() { +const char* SPUse::displayName() { if(this->child && SP_IS_SYMBOL( this->child )) { return _("Symbol"); } @@ -250,7 +250,7 @@ gchar* SPUse::description() { } ++recursion_depth; - char *child_desc = SP_ITEM(this->child)->getDetailedDescription(); + char *child_desc = SP_ITEM(this->child)->detailedDescription(); --recursion_depth; char *ret = g_strdup_printf(_("of: %s"), child_desc); diff --git a/src/sp-use.h b/src/sp-use.h index 568b8f7da..0c53fd486 100644 --- a/src/sp-use.h +++ b/src/sp-use.h @@ -57,7 +57,7 @@ public: virtual void modified(unsigned int flags); virtual Geom::OptRect bbox(Geom::Affine const &transform, SPItem::BBoxType bboxtype); - virtual const char* display_name(); + virtual const char* displayName(); virtual gchar* description(); virtual void print(SPPrintContext *ctx); virtual Inkscape::DrawingItem* show(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags); diff --git a/src/style.cpp b/src/style.cpp index 03c90bc09..2807a7d9a 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -3170,9 +3170,7 @@ sp_style_clear(SPStyle *style) style->color_interpolation.value = style->color_interpolation.computed = SP_CSS_COLOR_INTERPOLATION_SRGB; style->color_interpolation_filters.set = FALSE; style->color_interpolation_filters.inherit = FALSE; - style->color_interpolation_filters.value = style->color_interpolation_filters.computed = SP_CSS_COLOR_INTERPOLATION_SRGB; - //this line changed because rendering issues: Bug lp:1127103 - //style->color_interpolation_filters.value = style->color_interpolation_filters.computed = SP_CSS_COLOR_INTERPOLATION_LINEARRGB; + style->color_interpolation_filters.value = style->color_interpolation_filters.computed = SP_CSS_COLOR_INTERPOLATION_LINEARRGB; style->fill.clear(); diff --git a/src/tweak-context.cpp b/src/tweak-context.cpp index 65106e651..cfd1effcc 100644 --- a/src/tweak-context.cpp +++ b/src/tweak-context.cpp @@ -636,7 +636,7 @@ sp_tweak_dilate_recursive (Inkscape::Selection *selection, SPItem *item, Geom::P if (newrepr) { newrepr->setAttribute("d", str); } else { - if (SP_IS_LPE_ITEM(item) && sp_lpe_item_has_path_effect_recursive(SP_LPE_ITEM(item))) { + if (SP_IS_LPE_ITEM(item) && SP_LPE_ITEM(item)->hasPathEffectRecursive()) { item->getRepr()->setAttribute("inkscape:original-d", str); } else { item->getRepr()->setAttribute("d", str); diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index 1d91a3b4d..ed28cabbd 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -724,7 +724,7 @@ void ClipboardManagerImpl::_copyUsedDefs(SPItem *item) // For lpe items, copy lpe stack if applicable if (SP_IS_LPE_ITEM(item)) { SPLPEItem *lpeitem = SP_LPE_ITEM (item); - if (sp_lpe_item_has_path_effect(lpeitem)) { + if (lpeitem->hasPathEffect()) { for (PathEffectList::iterator it = lpeitem->path_effect_list->begin(); it != lpeitem->path_effect_list->end(); ++it) { LivePathEffectObject *lpeobj = (*it)->lpeobject; diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp index ec04f6d98..37d0ce213 100644 --- a/src/ui/dialog/document-properties.cpp +++ b/src/ui/dialog/document-properties.cpp @@ -1440,15 +1440,21 @@ void DocumentProperties::update() if (nv->doc_units) _rum_deflt.setUnit (nv->doc_units->abbr); - double const doc_w = sp_desktop_document(dt)->getRoot()->width.value; + double doc_w = sp_desktop_document(dt)->getRoot()->width.value; Glib::ustring doc_w_unit = unit_table.getUnit(sp_desktop_document(dt)->getRoot()->width.unit).abbr; if (doc_w_unit == "") { doc_w_unit = "px"; + } else if (doc_w_unit == "%" && sp_desktop_document(dt)->getRoot()->viewBox_set) { + doc_w_unit = "px"; + doc_w = sp_desktop_document(dt)->getRoot()->viewBox.width(); } - double const doc_h = sp_desktop_document(dt)->getRoot()->height.value; + double doc_h = sp_desktop_document(dt)->getRoot()->height.value; Glib::ustring doc_h_unit = unit_table.getUnit(sp_desktop_document(dt)->getRoot()->height.unit).abbr; if (doc_h_unit == "") { doc_h_unit = "px"; + } else if (doc_h_unit == "%" && sp_desktop_document(dt)->getRoot()->viewBox_set) { + doc_h_unit = "px"; + doc_h = sp_desktop_document(dt)->getRoot()->viewBox.height(); } _page_sizer.setDim(Inkscape::Util::Quantity(doc_w, doc_w_unit), Inkscape::Util::Quantity(doc_h, doc_h_unit)); _page_sizer.updateFitMarginsUI(nv->getRepr()); diff --git a/src/ui/dialog/layer-properties.cpp b/src/ui/dialog/layer-properties.cpp index 3feed2afe..b9e5d4883 100644 --- a/src/ui/dialog/layer-properties.cpp +++ b/src/ui/dialog/layer-properties.cpp @@ -3,7 +3,7 @@ * Dialog for renaming layers. */ /* Author: - * Bryce W. Harrington <bryce@bryceharrington.com> + * Bryce W. Harrington <bryce@bryceharrington.org> * Andrius R. <knutux@gmail.com> * Abhishek Sharma * diff --git a/src/ui/dialog/layer-properties.h b/src/ui/dialog/layer-properties.h index d38b8edf5..d114c6ba5 100644 --- a/src/ui/dialog/layer-properties.h +++ b/src/ui/dialog/layer-properties.h @@ -2,7 +2,7 @@ * @brief Dialog for renaming layers */ /* Author: - * Bryce W. Harrington <bryce@bryceharrington.com> + * Bryce W. Harrington <bryce@bryceharrington.org> * * Copyright (C) 2004 Bryce Harrington * diff --git a/src/ui/dialog/livepatheffect-editor.cpp b/src/ui/dialog/livepatheffect-editor.cpp index 6dc9c1ee3..2319d2c70 100644 --- a/src/ui/dialog/livepatheffect-editor.cpp +++ b/src/ui/dialog/livepatheffect-editor.cpp @@ -279,7 +279,7 @@ LivePathEffectEditor::onSelectionChanged(Inkscape::Selection *sel) current_lpeitem = lpeitem; set_sensitize_all(true); - if ( sp_lpe_item_has_path_effect(lpeitem) ) { + if ( lpeitem->hasPathEffect() ) { Inkscape::LivePathEffect::Effect *lpe = sp_lpe_item_get_current_lpe(lpeitem); if (lpe) { showParams(*lpe); diff --git a/src/ui/dialog/pixelartdialog.cpp b/src/ui/dialog/pixelartdialog.cpp index e07cbccb5..ff527434e 100644 --- a/src/ui/dialog/pixelartdialog.cpp +++ b/src/ui/dialog/pixelartdialog.cpp @@ -129,7 +129,9 @@ private: Gtk::RadioButton voronoiRadioButton; Gtk::RadioButton noOptimizeRadioButton; +#if LIBDEPIXELIZE_INKSCAPE_ENABLE_SMOOTH Gtk::RadioButton optimizeRadioButton; +#endif // LIBDEPIXELIZE_INKSCAPE_ENABLE_SMOOTH SPDesktop *desktop; DesktopTracker deskTrack; @@ -247,12 +249,14 @@ PixelArtDialogImpl::PixelArtDialogImpl() : outputVBox.pack_start(noOptimizeRadioButton, false, false); +#if LIBDEPIXELIZE_INKSCAPE_ENABLE_SMOOTH optimizeRadioButton.set_label(_("_Smooth curves")); optimizeRadioButton.set_tooltip_text(_("The Kopf-Lischinski algorithm")); optimizeRadioButton.set_use_underline(true); optimizeRadioButton.set_group(outputGroup); outputVBox.pack_start(optimizeRadioButton, false, false); +#endif // LIBDEPIXELIZE_INKSCAPE_ENABLE_SMOOTH outputFrame.set_label(_("Output")); outputFrame.add(outputVBox); @@ -308,7 +312,11 @@ Tracer::Kopf2011::Options PixelArtDialogImpl::options() options.islandsWeight = islandsWeightSpinner.get_value_as_int(); options.sparsePixelsMultiplier = sparsePixelsMultiplierSpinner.get_value(); options.sparsePixelsRadius = sparsePixelsRadiusSpinner.get_value_as_int(); +#if LIBDEPIXELIZE_INKSCAPE_ENABLE_SMOOTH options.optimize = optimizeRadioButton.get_active(); +#else // LIBDEPIXELIZE_INKSCAPE_ENABLE_SMOOTH + options.optimize = false; +#endif // LIBDEPIXELIZE_INKSCAPE_ENABLE_SMOOTH options.nthreads = Inkscape::Preferences::get() ->getIntLimited("/options/threading/numthreads", @@ -450,7 +458,11 @@ void PixelArtDialogImpl::setDefaults() sparsePixelsMultiplierSpinner.set_value(Tracer::Kopf2011::Options ::SPARSE_PIXELS_MULTIPLIER); +#if LIBDEPIXELIZE_INKSCAPE_ENABLE_SMOOTH optimizeRadioButton.set_active(); +#else // LIBDEPIXELIZE_INKSCAPE_ENABLE_SMOOTH + noOptimizeRadioButton.set_active(); +#endif // LIBDEPIXELIZE_INKSCAPE_ENABLE_SMOOTH ignorePreview = false; diff --git a/src/ui/tool/path-manipulator.cpp b/src/ui/tool/path-manipulator.cpp index ea007dfee..e08a36e2e 100644 --- a/src/ui/tool/path-manipulator.cpp +++ b/src/ui/tool/path-manipulator.cpp @@ -1310,8 +1310,8 @@ void PathManipulator::_createGeometryFromControlPoints(bool alert_LPE) Geom::PathVector pathv = builder.peek() * (_edit_transform * _i2d_transform).inverse(); _spcurve->set_pathvector(pathv); if (alert_LPE) { - if (SP_IS_LPE_ITEM(_path) && sp_lpe_item_has_path_effect(SP_LPE_ITEM(_path))) { - PathEffectList effect_list = sp_lpe_item_get_effect_list(SP_LPE_ITEM(_path)); + if (_path->hasPathEffect()) { + PathEffectList effect_list = sp_lpe_item_get_effect_list(_path); LivePathEffect::LPEPowerStroke *lpe_pwr = dynamic_cast<LivePathEffect::LPEPowerStroke*>( effect_list.front()->lpeobject->get_lpe() ); if (lpe_pwr) { lpe_pwr->adjustForNewPath(pathv); diff --git a/src/ui/widget/page-sizer.cpp b/src/ui/widget/page-sizer.cpp index 051937c43..2379dc181 100644 --- a/src/ui/widget/page-sizer.cpp +++ b/src/ui/widget/page-sizer.cpp @@ -474,6 +474,8 @@ PageSizer::setDim (Inkscape::Util::Quantity w, Inkscape::Util::Quantity h, bool _changedw_connection.block(); _changedh_connection.block(); + _unit = w.unit->abbr; + if (SP_ACTIVE_DESKTOP && !_widgetRegistry->isUpdating()) { SPDocument *doc = sp_desktop_document(SP_ACTIVE_DESKTOP); Inkscape::Util::Quantity const old_height = doc->getHeight(); diff --git a/src/ui/widget/spinbutton.cpp b/src/ui/widget/spinbutton.cpp index 62c17f821..1114ff32b 100644 --- a/src/ui/widget/spinbutton.cpp +++ b/src/ui/widget/spinbutton.cpp @@ -65,7 +65,7 @@ int SpinButton::on_input(double* newvalue) bool SpinButton::on_my_focus_in_event(GdkEventFocus* /*event*/) { - on_focus_in_value = get_value(); + _on_focus_in_value = get_value(); return false; // do not consume the event } @@ -92,7 +92,7 @@ bool SpinButton::on_my_key_press_event(GdkEventKey* event) void SpinButton::undo() { - set_value(on_focus_in_value); + set_value(_on_focus_in_value); } diff --git a/src/ui/widget/spinbutton.h b/src/ui/widget/spinbutton.h index c772fe2a2..812b5f515 100644 --- a/src/ui/widget/spinbutton.h +++ b/src/ui/widget/spinbutton.h @@ -38,7 +38,9 @@ class SpinButton : public Gtk::SpinButton public: SpinButton(double climb_rate = 0.0, guint digits = 0) : Gtk::SpinButton(climb_rate, digits), - _unit_menu(NULL) + _unit_menu(NULL), + _unit_tracker(NULL), + _on_focus_in_value(0.) { connect_signals(); }; @@ -48,10 +50,11 @@ public: explicit SpinButton(Gtk::Adjustment& adjustment, double climb_rate = 0.0, guint digits = 0) #endif : Gtk::SpinButton(adjustment, climb_rate, digits), - _unit_menu(NULL) + _unit_menu(NULL), + _unit_tracker(NULL), + _on_focus_in_value(0.) { connect_signals(); - _unit_tracker = NULL; }; virtual ~SpinButton() {}; @@ -63,6 +66,7 @@ public: protected: UnitMenu *_unit_menu; /// Linked unit menu for unit conversion in entered expressions. UnitTracker *_unit_tracker; // Linked unit tracker for unit conversion in entered expressions. + double _on_focus_in_value; void connect_signals(); @@ -95,8 +99,6 @@ protected: */ void undo(); - double on_focus_in_value; - private: // noncopyable SpinButton(const SpinButton&); diff --git a/src/widgets/node-toolbar.cpp b/src/widgets/node-toolbar.cpp index c3e5b22ce..2348acc46 100644 --- a/src/widgets/node-toolbar.cpp +++ b/src/widgets/node-toolbar.cpp @@ -317,7 +317,7 @@ static void sp_node_toolbox_sel_changed(Inkscape::Selection *selection, GObject GtkAction* w = GTK_ACTION( g_object_get_data( tbl, "nodes_lpeedit" ) ); SPItem *item = selection->singleItem(); if (item && SP_IS_LPE_ITEM(item)) { - if (sp_lpe_item_has_path_effect(SP_LPE_ITEM(item))) { + if (SP_LPE_ITEM(item)->hasPathEffect()) { gtk_action_set_sensitive(w, TRUE); } else { gtk_action_set_sensitive(w, FALSE); diff --git a/src/widgets/spw-utilities.cpp b/src/widgets/spw-utilities.cpp index d0a3ed1c5..9c0c8d7c6 100644 --- a/src/widgets/spw-utilities.cpp +++ b/src/widgets/spw-utilities.cpp @@ -2,7 +2,7 @@ * Inkscape Widget Utilities * * Authors: - * Bryce W. Harrington <brycehar@bryceharrington.com> + * Bryce W. Harrington <brycehar@bryceharrington.org> * bulia byak <buliabyak@users.sf.net> * * Copyright (C) 2003 Bryce W. Harrington diff --git a/src/widgets/spw-utilities.h b/src/widgets/spw-utilities.h index d52cbd888..31f29e026 100644 --- a/src/widgets/spw-utilities.h +++ b/src/widgets/spw-utilities.h @@ -5,7 +5,7 @@ * Inkscape Widget Utilities * * Author: - * Bryce W. Harrington <brycehar@bryceharrington.com> + * Bryce W. Harrington <brycehar@bryceharrington.org> * * Copyright (C) 2003 Bryce Harrington * diff --git a/src/xml/repr-util.cpp b/src/xml/repr-util.cpp index 8c8425de0..12280ea5a 100644 --- a/src/xml/repr-util.cpp +++ b/src/xml/repr-util.cpp @@ -432,13 +432,11 @@ unsigned int sp_repr_get_int(Inkscape::XML::Node *repr, gchar const *key, int *v unsigned int sp_repr_get_double(Inkscape::XML::Node *repr, gchar const *key, double *val) { - gchar const *v; - g_return_val_if_fail(repr != NULL, FALSE); g_return_val_if_fail(key != NULL, FALSE); g_return_val_if_fail(val != NULL, FALSE); - v = repr->attribute(key); + gchar const *v = repr->attribute(key); if (v != NULL) { *val = g_ascii_strtod(v, NULL); |
