diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2015-03-18 18:17:44 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx.marker.es> | 2015-03-18 18:17:44 +0000 |
| commit | 71508f76c3ddc33c41664599f9c10bf84d994d62 (patch) | |
| tree | 68f69fd8c5b36c4f5a288bb8b2521405724cf9ce /src | |
| parent | update to trunk (diff) | |
| parent | Latvian translation update (diff) | |
| download | inkscape-71508f76c3ddc33c41664599f9c10bf84d994d62.tar.gz inkscape-71508f76c3ddc33c41664599f9c10bf84d994d62.zip | |
update to trunk
(bzr r13879.1.11)
Diffstat (limited to 'src')
274 files changed, 2827 insertions, 3825 deletions
diff --git a/src/2geom/sbasis-to-bezier.cpp b/src/2geom/sbasis-to-bezier.cpp index 0525be04b..a2e4253d2 100644 --- a/src/2geom/sbasis-to-bezier.cpp +++ b/src/2geom/sbasis-to-bezier.cpp @@ -37,6 +37,7 @@ #include <2geom/choose.h> #include <2geom/path-sink.h> #include <2geom/exception.h> +#include <2geom/convex-cover.h> #include <iostream> @@ -203,11 +204,8 @@ void sbasis_to_cubic_bezier (std::vector<Point> & bz, D2<SBasis> const& sb) THROW_RANGEERROR("size of sb is too small"); } - bz.resize(4, Point(0,0)); - bz[0][X] = sb[X][0][0]; - bz[0][Y] = sb[Y][0][0]; - bz[3][X] = sb[X][0][1]; - bz[3][Y] = sb[Y][0][1]; + sbasis_to_bezier(bz, sb, 4); // zeroth-order estimate + Geom::ConvexHull bezhull(bz); // calculate first derivatives of x and y wrt t @@ -231,17 +229,23 @@ void sbasis_to_cubic_bezier (std::vector<Point> & bz, D2<SBasis> const& sb) midx += (sb[X][i][0] + sb[X][i][1])/div; div *= 4; } - midx = 8*midx - 4*bz[0][X] - 4*bz[3][X]; div = 2; for (size_t i = 0; i < sb[Y].size(); ++i) { midy += (sb[Y][i][0] + sb[Y][i][1])/div; div *= 4; } - midy = 8*midy - 4*bz[0][Y] - 4*bz[3][Y]; + +// is midpoint in hull: if not, the solution will be ill-conditioned, LP Bug 1428683 + + if (!bezhull.contains_point(Geom::Point(midx, midy))) + return; // calculate Bezier control arms + midx = 8*midx - 4*bz[0][X] - 4*bz[3][X]; // re-define relative to center + midy = 8*midy - 4*bz[0][Y] - 4*bz[3][Y]; + if ((std::abs(xprime[0]) < EPSILON) && (std::abs(yprime[0]) < EPSILON) && ((std::abs(xprime[1]) > EPSILON) || (std::abs(yprime[1]) > EPSILON))) { // degenerate handle at 0 : use distance of closest approach numer = midx*xprime[1] + midy*yprime[1]; @@ -258,7 +262,8 @@ void sbasis_to_cubic_bezier (std::vector<Point> & bz, D2<SBasis> const& sb) dely[0] = yprime[0]*numer/denom; delx[1] = 0; dely[1] = 0; - } else if (std::abs(xprime[1]*yprime[0] - yprime[1]*xprime[0]) > EPSILON) { // general case : fit mid fxn value + } else if (std::abs(xprime[1]*yprime[0] - yprime[1]*xprime[0]) > // general case : fit mid fxn value + 0.002 * std::abs(xprime[1]*xprime[0] + yprime[1]*yprime[0])) { // approx. 0.1 degree of angle denom = xprime[1]*yprime[0] - yprime[1]*xprime[0]; for (int i = 0; i < 2; ++i) { numer = xprime[1 - i]*midy - yprime[1 - i]*midx; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 617e9dce1..6659e8c0a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,6 +19,7 @@ set(sp_SRC sp-defs.cpp sp-desc.cpp sp-ellipse.cpp + sp-factory.cpp sp-filter-primitive.cpp sp-filter-reference.cpp sp-filter.cpp @@ -46,8 +47,8 @@ set(sp_SRC sp-lpe-item.cpp sp-marker.cpp sp-mask.cpp + sp-mesh.cpp sp-mesh-array.cpp - sp-mesh-gradient.cpp sp-mesh-patch.cpp sp-mesh-row.cpp sp-metadata.cpp @@ -133,8 +134,8 @@ set(sp_SRC sp-marker.h sp-marker-loc.h sp-mask.h + sp-mesh.h sp-mesh-array.h - sp-mesh-gradient.h sp-mesh-patch.h sp-mesh-row.h sp-metadata.h @@ -194,7 +195,6 @@ set(inkscape_SRC document-subset.cpp document-undo.cpp document.cpp - doxygen-main.cpp ege-color-prof-tracker.cpp event-log.cpp extract-uri.cpp @@ -491,6 +491,7 @@ add_subdirectory(2geom) add_subdirectory(libavoid) add_subdirectory(libcola) add_subdirectory(libcroco) +add_subdirectory(inkgc) add_subdirectory(libgdl) add_subdirectory(libuemf) add_subdirectory(libvpsc) diff --git a/src/Makefile.am b/src/Makefile.am index 8fb7e23ef..cfbbd4015 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -23,15 +23,18 @@ endif noinst_LIBRARIES = \ + libinkscape.a \ libcroco/libcroco.a \ libavoid/libavoid.a \ $(internal_GDL) \ libuemf/libuemf.a \ libcola/libcola.a \ + inkgc/libinkgc.a \ libvpsc/libvpsc.a \ livarot/libvarot.a \ 2geom/lib2geom.a \ libdepixelize/libdepixelize.a \ + util/libutil.a \ libinkversion.a all_libs = \ @@ -114,6 +117,7 @@ include filters/Makefile_insert include helper/Makefile_insert include io/Makefile_insert include libcroco/Makefile_insert +include inkgc/Makefile_insert include libgdl/Makefile_insert include libnrtype/Makefile_insert include libavoid/Makefile_insert @@ -194,13 +198,13 @@ DISTCLEANFILES = \ # ################################################ # this should speed up the build -#libinkscape_a_SOURCES = $(ink_common_sources) +libinkscape_a_SOURCES = $(ink_common_sources) -inkscape_SOURCES += main.cpp $(ink_common_sources) $(win32_sources) +inkscape_SOURCES += main.cpp $(win32_sources) inkscape_LDADD = $(all_libs) inkscape_LDFLAGS = $(kdeldflags) $(mwindows) -inkview_SOURCES += inkview.cpp $(ink_common_sources) $(win32_sources) +inkview_SOURCES += inkview.cpp $(win32_sources) inkview_LDADD = $(all_libs) inkview_LDFLAGS = $(mwindows) diff --git a/src/Makefile_insert b/src/Makefile_insert index b07541109..800752df4 100644 --- a/src/Makefile_insert +++ b/src/Makefile_insert @@ -35,23 +35,16 @@ ink_common_sources += \ document.cpp document.h document-private.h \ document-subset.cpp document-subset.h \ document-undo.cpp document-undo.h \ - doxygen-main.cpp \ ege-color-prof-tracker.cpp ege-color-prof-tracker.h \ enums.h \ event-log.cpp event-log.h event.h \ extract-uri.cpp extract-uri.h \ - factory.h \ file.cpp file.h \ fill-or-stroke.h \ filter-chemistry.cpp filter-chemistry.h \ filter-enums.cpp filter-enums.h \ - gc-alloc.h \ - gc-anchored.h gc-anchored.cpp \ - gc-core.h \ - gc.cpp \ - gc-finalized.h gc-finalized.cpp \ - gc-managed.h \ - gc-soft-ptr.h \ + gc-anchored.cpp gc-anchored.h \ + gc-finalized.cpp gc-finalized.h \ gradient-chemistry.cpp gradient-chemistry.h \ gradient-drag.cpp gradient-drag.h \ graphlayout.cpp graphlayout.h \ @@ -124,7 +117,7 @@ ink_common_sources += \ sp-defs.cpp sp-defs.h \ sp-desc.cpp sp-desc.h \ sp-ellipse.cpp sp-ellipse.h \ - sp-factory.h \ + sp-factory.h sp-factory.cpp \ sp-filter.cpp sp-filter.h number-opt-number.h \ sp-filter-primitive.cpp sp-filter-primitive.h \ sp-filter-reference.cpp sp-filter-reference.h \ @@ -161,8 +154,8 @@ ink_common_sources += \ sp-marker-loc.h \ sp-mask.cpp sp-mask.h \ sp-metadata.cpp sp-metadata.h \ + sp-mesh.cpp sp-mesh.h \ sp-mesh-array.cpp sp-mesh-array.h \ - sp-mesh-gradient.cpp sp-mesh-gradient.h \ sp-mesh-patch.cpp sp-mesh-patch.h \ sp-mesh-row.cpp sp-mesh-row.h \ sp-missing-glyph.cpp sp-missing-glyph.h \ diff --git a/src/attributes-test.h b/src/attributes-test.h index ba34717ea..7379e4e85 100644 --- a/src/attributes-test.h +++ b/src/attributes-test.h @@ -38,6 +38,8 @@ public: attindex.html lacks attributeName, begin, additive, font, marker; I've added these manually. + + SVG 2: white-space, shape-inside, shape-outside, shape-padding, shape-margin */ struct {char const *attr; bool supported;} const all_attrs[] = { {"attributeName", true}, @@ -163,7 +165,7 @@ struct {char const *attr; bool supported;} const all_attrs[] = { {"keySplines", true}, {"keyTimes", true}, {"lang", true}, - {"lengthAdjust", false}, + {"lengthAdjust", true}, {"letter-spacing", true}, {"lighting-color", true}, {"limitingConeAngle", true}, @@ -246,6 +248,10 @@ struct {char const *attr; bool supported;} const all_attrs[] = { {"ry", true}, {"scale", true}, {"seed", true}, + {"shape-inside", true}, + {"shape-margin", true}, + {"shape-outside", true}, + {"shape-padding", true}, {"shape-rendering", true}, {"slope", true}, {"spacing", false}, @@ -285,7 +291,7 @@ struct {char const *attr; bool supported;} const all_attrs[] = { {"text-indent", true}, {"text-rendering", true}, {"text-transform", true}, - {"textLength", false}, + {"textLength", true}, {"title", false}, {"to", true}, {"transform", true}, @@ -310,6 +316,7 @@ struct {char const *attr; bool supported;} const all_attrs[] = { {"viewBox", true}, {"viewTarget", false}, {"visibility", true}, + {"white-space", true}, {"width", true}, {"widths", true}, {"word-spacing", true}, diff --git a/src/attributes.cpp b/src/attributes.cpp index 0b18b80cf..568f0528a 100644 --- a/src/attributes.cpp +++ b/src/attributes.cpp @@ -291,7 +291,7 @@ static SPStyleProp const props[] = { {SP_ATTR_FY, "fy"}, /* SPMeshPatch */ {SP_ATTR_TENSOR, "tensor"}, - {SP_ATTR_SMOOTH, "smooth"}, + //{SP_ATTR_TYPE, "type"}, /* SPPattern */ {SP_ATTR_PATTERNUNITS, "patternUnits"}, {SP_ATTR_PATTERNCONTENTUNITS, "patternContentUnits"}, diff --git a/src/attributes.h b/src/attributes.h index 645aad00b..91c8868f9 100644 --- a/src/attributes.h +++ b/src/attributes.h @@ -293,7 +293,7 @@ enum SPAttributeEnum { SP_ATTR_FY, /* SPMeshPatch */ SP_ATTR_TENSOR, - SP_ATTR_SMOOTH, + //SP_ATTR_TYPE, /* SPPattern */ SP_ATTR_PATTERNUNITS, SP_ATTR_PATTERNCONTENTUNITS, diff --git a/src/box3d-side.cpp b/src/box3d-side.cpp index 3058eab2d..93d55232e 100644 --- a/src/box3d-side.cpp +++ b/src/box3d-side.cpp @@ -28,16 +28,6 @@ static void box3d_side_compute_corner_ids(Box3DSide *side, unsigned int corners[4]); -#include "sp-factory.h" - -namespace { - SPObject* createBox3DSide() { - return new Box3DSide(); - } - - bool box3DSideRegistered = SPFactory::instance().registerObject("inkscape:box3dside", createBox3DSide); -} - Box3DSide::Box3DSide() : SPPolygon() { this->dir1 = Box3D::NONE; this->dir2 = Box3D::NONE; diff --git a/src/box3d.cpp b/src/box3d.cpp index 86f99049b..dc04a2eb6 100644 --- a/src/box3d.cpp +++ b/src/box3d.cpp @@ -44,16 +44,6 @@ static void box3d_ref_changed(SPObject *old_ref, SPObject *ref, SPBox3D *box); static gint counter = 0; -#include "sp-factory.h" - -namespace { - SPObject* createBox3D() { - return new SPBox3D(); - } - - bool box3DRegistered = SPFactory::instance().registerObject("inkscape:box3d", createBox3D); -} - SPBox3D::SPBox3D() : SPGroup() { this->my_counter = 0; this->swapped = Box3D::NONE; diff --git a/src/color-profile.cpp b/src/color-profile.cpp index 28550b75d..85a6fa876 100644 --- a/src/color-profile.cpp +++ b/src/color-profile.cpp @@ -185,17 +185,6 @@ cmsHPROFILE ColorProfileImpl::getNULLProfile() { #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) - -#include "sp-factory.h" - -namespace { - SPObject* createColorProfile() { - return new Inkscape::ColorProfile(); - } - - bool rectRegistered = SPFactory::instance().registerObject("svg:color-profile", createColorProfile); -} - ColorProfile::ColorProfile() : SPObject() { this->impl = new ColorProfileImpl(); diff --git a/src/composite-undo-stack-observer.h b/src/composite-undo-stack-observer.h index c93a2338b..33afda48d 100644 --- a/src/composite-undo-stack-observer.h +++ b/src/composite-undo-stack-observer.h @@ -10,7 +10,7 @@ #ifndef SEEN_COMPOSITE_UNDO_COMMIT_OBSERVER_H #define SEEN_COMPOSITE_UNDO_COMMIT_OBSERVER_H -#include "gc-alloc.h" +#include "inkgc/gc-alloc.h" #include "undo-stack-observer.h" #include <list> diff --git a/src/debug/demangle.cpp b/src/debug/demangle.cpp index 2b00fb8e9..1d94f0eb9 100644 --- a/src/debug/demangle.cpp +++ b/src/debug/demangle.cpp @@ -14,7 +14,7 @@ #include <map> #include "debug/demangle.h" #include "util/format.h" -#include "gc-alloc.h" +#include "inkgc/gc-alloc.h" namespace Inkscape { diff --git a/src/debug/gc-heap.h b/src/debug/gc-heap.h index 957f2067a..d120ddba9 100644 --- a/src/debug/gc-heap.h +++ b/src/debug/gc-heap.h @@ -12,7 +12,7 @@ #ifndef SEEN_INKSCAPE_DEBUG_GC_HEAP_H #define SEEN_INKSCAPE_DEBUG_GC_HEAP_H -#include "gc-core.h" +#include "inkgc/gc-core.h" #include "debug/heap.h" namespace Inkscape { diff --git a/src/debug/heap.cpp b/src/debug/heap.cpp index 8e7a920ba..0135a9ceb 100644 --- a/src/debug/heap.cpp +++ b/src/debug/heap.cpp @@ -13,7 +13,7 @@ # include "config.h" #endif -#include "gc-alloc.h" +#include "inkgc/gc-alloc.h" #include "debug/gc-heap.h" #include "debug/sysv-heap.h" #include <vector> diff --git a/src/debug/logger.cpp b/src/debug/logger.cpp index 485dbc365..2eb81a0ba 100644 --- a/src/debug/logger.cpp +++ b/src/debug/logger.cpp @@ -15,7 +15,7 @@ #include "inkscape-version.h" #include "debug/logger.h" #include "debug/simple-event.h" -#include "gc-alloc.h" +#include "inkgc/gc-alloc.h" namespace Inkscape { diff --git a/src/debug/simple-event.h b/src/debug/simple-event.h index 506ee1b03..03ce5d326 100644 --- a/src/debug/simple-event.h +++ b/src/debug/simple-event.h @@ -16,7 +16,7 @@ #include <vector> #include <glib.h> // g_assert() -#include "gc-alloc.h" +#include "inkgc/gc-alloc.h" #include "debug/event.h" namespace Inkscape { diff --git a/src/desktop-events.cpp b/src/desktop-events.cpp index 5dbe0f8dc..e80e5f6c1 100644 --- a/src/desktop-events.cpp +++ b/src/desktop-events.cpp @@ -17,13 +17,19 @@ #endif #include <map> #include <string> + #include "ui/dialog/guides.h" +#include "desktop-events.h" + +#if WITH_GTKMM_3_0 +# include <gdkmm/devicemanager.h> +#endif + #include <2geom/line.h> #include <2geom/angle.h> #include <glibmm/i18n.h> #include "desktop.h" -#include "desktop-events.h" #include "ui/dialog-events.h" #include "display/canvas-axonomgrid.h" @@ -611,36 +617,35 @@ static GdkInputSource lastType = GDK_SOURCE_MOUSE; static void init_extended() { - std::string avoidName = "pad"; + Glib::ustring avoidName("pad"); + Glib::RefPtr<Gdk::Display> display = Gdk::Display::get_default(); #if GTK_CHECK_VERSION(3,0,0) - GdkDisplay *display = gdk_display_get_default(); - GdkDeviceManager *dm = gdk_display_get_device_manager(display); - GList* devices = gdk_device_manager_list_devices(dm, GDK_DEVICE_TYPE_SLAVE); + Glib::RefPtr<const Gdk::DeviceManager> dm = display->get_device_manager(); + std::vector< Glib::RefPtr<const Gdk::Device> > devices = dm->list_devices(Gdk::DEVICE_TYPE_SLAVE); #else - GList* devices = gdk_devices_list(); + std::vector< Glib::RefPtr<const Gdk::Device> > devices = display->list_devices(); #endif - if ( devices ) { - for ( GList* curr = devices; curr; curr = g_list_next(curr) ) { - GdkDevice* dev = reinterpret_cast<GdkDevice*>(curr->data); - gchar const *devName = gdk_device_get_name(dev); - GdkInputSource devSrc = gdk_device_get_source(dev); + if ( !devices.empty() ) { + for ( std::vector< Glib::RefPtr<const Gdk::Device> >::const_iterator dev = devices.begin(); dev != devices.end(); ++dev ) { + Glib::ustring const devName = (*dev)->get_name(); + Gdk::InputSource devSrc = (*dev)->get_source(); - if ( devName + if ( !devName.empty() && (avoidName != devName) - && (devSrc != GDK_SOURCE_MOUSE) ) { + && (devSrc != Gdk::SOURCE_MOUSE) ) { // g_message("Adding '%s' as [%d]", devName, devSrc); // Set the initial tool for the device switch ( devSrc ) { - case GDK_SOURCE_PEN: + case Gdk::SOURCE_PEN: toolToUse[devName] = TOOLS_CALLIGRAPHIC; break; - case GDK_SOURCE_ERASER: + case Gdk::SOURCE_ERASER: toolToUse[devName] = TOOLS_ERASER; break; - case GDK_SOURCE_CURSOR: + case Gdk::SOURCE_CURSOR: toolToUse[devName] = TOOLS_SELECT; break; default: @@ -651,10 +656,6 @@ static void init_extended() } } } - -#if GTK_CHECK_VERSION(3,0,0) - g_list_free(devices); -#endif } diff --git a/src/desktop-events.h b/src/desktop-events.h index dc85e563b..8dae9b406 100644 --- a/src/desktop-events.h +++ b/src/desktop-events.h @@ -13,6 +13,8 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include <glib.h> + class SPDesktop; struct SPDesktopWidget; struct SPCanvasItem; diff --git a/src/desktop-style.cpp b/src/desktop-style.cpp index ee9fa39ec..c713e0d61 100644 --- a/src/desktop-style.cpp +++ b/src/desktop-style.cpp @@ -1031,7 +1031,7 @@ objects_query_fontnumbers (GSList *objects, SPStyle *style_res) letterspacing_normal = true; } } else { - letterspacing += style->letter_spacing.computed; /// \todo FIXME: we assume non-% units here + letterspacing += style->letter_spacing.computed * Geom::Affine(item->i2dt_affine()).descrim(); /// \todo FIXME: we assume non-% units here letterspacing_normal = false; } @@ -1040,7 +1040,7 @@ objects_query_fontnumbers (GSList *objects, SPStyle *style_res) wordspacing_normal = true; } } else { - wordspacing += style->word_spacing.computed; /// \todo FIXME: we assume non-% units here + wordspacing += style->word_spacing.computed * Geom::Affine(item->i2dt_affine()).descrim(); /// \todo FIXME: we assume non-% units here wordspacing_normal = false; } diff --git a/src/desktop.cpp b/src/desktop.cpp index cdf8f276c..1152184c9 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -687,7 +687,7 @@ void SPDesktop::set_event_context2(const std::string& toolName) } } - Inkscape::UI::Tools::ToolBase* new_tool = ToolFactory::instance().createObject(toolName); + Inkscape::UI::Tools::ToolBase* new_tool = ToolFactory::createObject(toolName); new_tool->desktop = this; new_tool->message_context = new Inkscape::MessageContext(this->messageStack()); event_context = new_tool; diff --git a/src/device-manager.cpp b/src/device-manager.cpp index 610173d3d..aa3874da8 100644 --- a/src/device-manager.cpp +++ b/src/device-manager.cpp @@ -12,37 +12,48 @@ #include <set> #include "preferences.h" -#include <gtk/gtk.h> +#include <gdkmm/display.h> +#include <gtkmm/accelkey.h> + +#if WITH_GTKMM_3_0 +# include <gdkmm/devicemanager.h> +#endif + #include <glibmm/regex.h> +#include <gtk/gtk.h> + #define noDEBUG_VERBOSE 1 // This is a copy of the private fields of the GdkDevice object, used in order // to create a list of "fake" devices. struct GdkDeviceFake { - gchar *name; - GdkInputSource source; - GdkInputMode mode; - gboolean has_cursor; - gint num_axes; - gint num_keys; + Glib::ustring name; + Gdk::InputSource source; + Gdk::InputMode mode; + bool has_cursor; + int num_axes; + int num_keys; }; static void createFakeList(); -GdkDeviceFake fakeout[5]; -static GList* fakeList = 0; +static std::vector<GdkDeviceFake> fakeList; -static bool isValidDevice(GdkDevice *device) +static bool isValidDevice(Glib::RefPtr<Gdk::Device> device) { bool valid = true; - for (size_t i = 0; (i < G_N_ELEMENTS(fakeout)) && valid; i++) { - gboolean name_matches = (g_strcmp0 (gdk_device_get_name (device), fakeout[i].name) == 0); - gboolean source_matches = (gdk_device_get_source (device) == fakeout[i].source); - gboolean mode_matches = (gdk_device_get_mode (device) == fakeout[i].mode); - gboolean num_axes_matches = (gdk_device_get_n_axes (device) == fakeout[i].num_axes); - gboolean num_keys_matches = (gdk_device_get_n_keys (device) == fakeout[i].num_keys); + for (std::vector<GdkDeviceFake>::iterator it = fakeList.begin(); it != fakeList.end() && valid; ++it) { + const bool name_matches = (device->get_name() == (*it).name); + const bool source_matches = (device->get_source() == (*it).source); + const bool mode_matches = (device->get_mode() == (*it).mode); + const bool num_axes_matches = (device->get_n_axes() == (*it).num_axes); +#if WITH_GTKMM_3_0 + const bool num_keys_matches = (device->get_n_keys() == (*it).num_keys); +#else + const bool num_keys_matches = (gdk_device_get_n_keys(device->gobj()) == (*it).num_keys); +#endif if (name_matches && source_matches && mode_matches && num_axes_matches && num_keys_matches) @@ -157,19 +168,22 @@ InputDevice::~InputDevice() {} class InputDeviceImpl : public InputDevice { public: - InputDeviceImpl(GdkDevice* device, std::set<Glib::ustring> &knownIDs); + InputDeviceImpl(Glib::RefPtr<Gdk::Device> device, std::set<Glib::ustring> &knownIDs); virtual ~InputDeviceImpl() {} virtual Glib::ustring getId() const {return id;} virtual Glib::ustring getName() const {return name;} virtual Gdk::InputSource getSource() const {return source;} - virtual Gdk::InputMode getMode() const {return static_cast<Gdk::InputMode>(gdk_device_get_mode (device));} - virtual gint getNumAxes() const {return gdk_device_get_n_axes (device);} - virtual bool hasCursor() const {return gdk_device_get_has_cursor (device);} + virtual Gdk::InputMode getMode() const {return (device->get_mode());} + virtual gint getNumAxes() const {return device->get_n_axes();} + virtual bool hasCursor() const {return device->get_has_cursor();} + +#if WITH_GTKMM_3_0 + virtual int getNumKeys() const {return device->get_n_keys();} +#else + virtual int getNumKeys() const {return gdk_device_get_n_keys(device->gobj());} +#endif - virtual gint getNumKeys() const { - return gdk_device_get_n_keys (device); - } virtual Glib::ustring getLink() const {return link;} virtual void setLink( Glib::ustring const& link ) {this->link = link;} virtual gint getLiveAxes() const {return liveAxes;} @@ -178,7 +192,7 @@ public: virtual void setLiveButtons(gint buttons) {liveButtons = buttons;} // internal methods not on public superclass: - virtual GdkDevice *getDevice() { return device; } + virtual Glib::RefPtr<Gdk::Device> getDevice() {return device;} private: InputDeviceImpl(InputDeviceImpl const &); // no copy @@ -186,7 +200,7 @@ private: static Glib::ustring createId(Glib::ustring const &id, Gdk::InputSource source, std::set<Glib::ustring> &knownIDs); - GdkDevice* device; + Glib::RefPtr<Gdk::Device> device; Glib::ustring id; Glib::ustring name; Gdk::InputSource source; @@ -213,12 +227,12 @@ private: Glib::ustring const& target; }; -InputDeviceImpl::InputDeviceImpl(GdkDevice* device, std::set<Glib::ustring> &knownIDs) +InputDeviceImpl::InputDeviceImpl(Glib::RefPtr<Gdk::Device> device, std::set<Glib::ustring> &knownIDs) : InputDevice(), device(device), id(), - name(gdk_device_get_name (device) ? gdk_device_get_name (device) : ""), - source(static_cast<Gdk::InputSource>(gdk_device_get_source (device))), + name(!device->get_name().empty() ? device->get_name() : ""), + source(device->get_source()), link(), liveAxes(0), liveButtons(0) @@ -312,28 +326,26 @@ DeviceManagerImpl::DeviceManagerImpl() : DeviceManager(), devices() { -#if GTK_CHECK_VERSION(3,0,0) - GdkDisplay *display = gdk_display_get_default(); - GdkDeviceManager *dm = gdk_display_get_device_manager(display); - GList* devList = gdk_device_manager_list_devices(dm, GDK_DEVICE_TYPE_SLAVE); + Glib::RefPtr<Gdk::Display> display = Gdk::Display::get_default(); + +#if WITH_GTKMM_3_0 + Glib::RefPtr<Gdk::DeviceManager> dm = display->get_device_manager(); + std::vector< Glib::RefPtr<Gdk::Device> > devList = dm->list_devices(Gdk::DEVICE_TYPE_SLAVE); #else - GList* devList = gdk_devices_list(); + std::vector< Glib::RefPtr<Gdk::Device> > devList = display->list_devices(); #endif - if ( !fakeList ) { + if (fakeList.empty()) { createFakeList(); } //devList = fakeList; std::set<Glib::ustring> knownIDs; - for ( GList* curr = devList; curr; curr = g_list_next(curr) ) { - GdkDevice* dev = reinterpret_cast<GdkDevice*>(curr->data); - if (dev) { - -#if GTK_CHECK_VERSION(3,0,0) + for ( std::vector< Glib::RefPtr<Gdk::Device> >::iterator dev = devList.begin(); dev != devList.end(); ++dev ) { +#if WITH_GTKMM_3_0 // GTK+ 3 has added keyboards to the list of supported devices. - if(gdk_device_get_source(dev) != GDK_SOURCE_KEYBOARD) { + if((*dev)->get_source() != Gdk::SOURCE_KEYBOARD) { #endif #if DEBUG_VERBOSE @@ -341,20 +353,14 @@ DeviceManagerImpl::DeviceManagerImpl() : dev->has_cursor?"Yes":"no", dev->num_axes, dev->num_keys); #endif - InputDeviceImpl* device = new InputDeviceImpl(dev, knownIDs); + InputDeviceImpl* device = new InputDeviceImpl(*dev, knownIDs); device->reference(); devices.push_back(Glib::RefPtr<InputDeviceImpl>(device)); -#if GTK_CHECK_VERSION(3,0,0) +#if WITH_GTKMM_3_0 } #endif - - } } - -#if GTK_CHECK_VERSION(3,0,0) - g_list_free(devList); -#endif } void DeviceManagerImpl::loadConfig() @@ -420,8 +426,8 @@ void DeviceManagerImpl::saveConfig() if (i > 0) { tmp += ";"; } - GdkDevice *device = (*it)->getDevice(); - tmp += getAxisToString()[static_cast<Gdk::AxisUse>(gdk_device_get_axis_use (device, i))]; + Glib::RefPtr<Gdk::Device> device = (*it)->getDevice(); + tmp += getAxisToString()[device->get_axis_use(i)]; } prefs->setString( path + "/axes", tmp ); @@ -430,11 +436,12 @@ void DeviceManagerImpl::saveConfig() if (i > 0) { tmp += ";"; } - GdkDevice *device = (*it)->getDevice(); + Glib::RefPtr<Gdk::Device> device = (*it)->getDevice(); guint keyval; - GdkModifierType modifiers; - gdk_device_get_key (device, i, &keyval, &modifiers); - tmp += gtk_accelerator_name(keyval, modifiers); + Gdk::ModifierType modifiers; + device->get_key(i, keyval, modifiers); + Gtk::AccelKey accelkey(keyval, modifiers); + tmp += accelkey.get_abbrev(); } prefs->setString( path + "/keys", tmp ); } @@ -454,8 +461,9 @@ void DeviceManagerImpl::setMode( Glib::ustring const & id, Gdk::InputMode mode ) { std::list<Glib::RefPtr<InputDeviceImpl> >::iterator it = std::find_if(devices.begin(), devices.end(), IdMatcher(id)); if ( it != devices.end() ) { - if (isValidDevice((*it)->getDevice()) && ((*it)->getMode() != mode) ) { - bool success = gdk_device_set_mode((*it)->getDevice(), static_cast<GdkInputMode>(mode)); + Glib::RefPtr<Gdk::Device> device = (*it)->getDevice(); + if (isValidDevice(device) && ((*it)->getMode() != mode) ) { + bool success = device->set_mode(mode); if (success) { signalDeviceChangedPriv.emit(*it); } else { @@ -471,10 +479,10 @@ void DeviceManagerImpl::setAxisUse( Glib::ustring const & id, guint index, Gdk:: if ( it != devices.end() ) { if (isValidDevice((*it)->getDevice())) { if (static_cast<gint>(index) <= (*it)->getNumAxes()) { - GdkDevice *device = (*it)->getDevice(); + Glib::RefPtr<Gdk::Device> device = (*it)->getDevice(); - if (gdk_device_get_axis_use (device, index) != static_cast<GdkAxisUse>(use)) { - gdk_device_set_axis_use(device, index, static_cast<GdkAxisUse>(use)); + if (device->get_axis_use(index) != use) { + device->set_axis_use(index, use); signalDeviceChangedPriv.emit(*it); } } else { @@ -492,7 +500,8 @@ void DeviceManagerImpl::setKey( Glib::ustring const & id, guint index, guint key std::list<Glib::RefPtr<InputDeviceImpl> >::iterator it = std::find_if(devices.begin(), devices.end(), IdMatcher(id)); if ( it != devices.end() ) { if (isValidDevice((*it)->getDevice())) { - gdk_device_set_key((*it)->getDevice(), index, keyval, static_cast<GdkModifierType>(mods)); + Glib::RefPtr<Gdk::Device> device = (*it)->getDevice(); + device->set_key(index, keyval, mods); signalDeviceChangedPriv.emit(*it); } } @@ -628,78 +637,76 @@ DeviceManager& DeviceManager::getManager() { static void createFakeList() { - if ( !fakeList ) { - fakeout[0].name = g_strdup("pad"); - fakeout[0].source = GDK_SOURCE_PEN; - fakeout[0].mode = GDK_MODE_SCREEN; - fakeout[0].has_cursor = TRUE; - fakeout[0].num_axes = 6; - fakeout[0].num_keys = 8; - - fakeout[1].name = g_strdup("eraser"); - fakeout[1].source = GDK_SOURCE_ERASER; - fakeout[1].mode = GDK_MODE_SCREEN; - fakeout[1].has_cursor = TRUE; - fakeout[1].num_axes = 6; - fakeout[1].num_keys = 7; - - fakeout[2].name = g_strdup("cursor"); - fakeout[2].source = GDK_SOURCE_CURSOR; - fakeout[2].mode = GDK_MODE_SCREEN; - fakeout[2].has_cursor = TRUE; - fakeout[2].num_axes = 6; - fakeout[2].num_keys = 7; - - fakeout[3].name = g_strdup("stylus"); - fakeout[3].source = GDK_SOURCE_PEN; - fakeout[3].mode = GDK_MODE_SCREEN; - fakeout[3].has_cursor = TRUE; - fakeout[3].num_axes = 6; - fakeout[3].num_keys = 7; + if (fakeList.empty()) { + fakeList.resize(5); + fakeList[0].name = "pad"; + fakeList[0].source = Gdk::SOURCE_PEN; + fakeList[0].mode = Gdk::MODE_SCREEN; + fakeList[0].has_cursor = true; + fakeList[0].num_axes = 6; + fakeList[0].num_keys = 8; + + fakeList[1].name = "eraser"; + fakeList[1].source = Gdk::SOURCE_ERASER; + fakeList[1].mode = Gdk::MODE_SCREEN; + fakeList[1].has_cursor = true; + fakeList[1].num_axes = 6; + fakeList[1].num_keys = 7; + + fakeList[2].name = "cursor"; + fakeList[2].source = Gdk::SOURCE_CURSOR; + fakeList[2].mode = Gdk::MODE_SCREEN; + fakeList[2].has_cursor = true; + fakeList[2].num_axes = 6; + fakeList[2].num_keys = 7; + + fakeList[3].name = "stylus"; + fakeList[3].source = Gdk::SOURCE_PEN; + fakeList[3].mode = Gdk::MODE_SCREEN; + fakeList[3].has_cursor = true; + fakeList[3].num_axes = 6; + fakeList[3].num_keys = 7; // try to find the first *real* core pointer -#if GTK_CHECK_VERSION(3,0,0) - GdkDisplay *display = gdk_display_get_default(); - GdkDeviceManager *dm = gdk_display_get_device_manager(display); - GList* devList = gdk_device_manager_list_devices(dm, GDK_DEVICE_TYPE_SLAVE); + Glib::RefPtr<Gdk::Display> display = Gdk::Display::get_default(); +#if WITH_GTKMM_3_0 + Glib::RefPtr<Gdk::DeviceManager> dm = display->get_device_manager(); + std::vector< Glib::RefPtr<Gdk::Device> > devList = dm->list_devices(Gdk::DEVICE_TYPE_SLAVE); #else - GList* devList = gdk_devices_list(); + std::vector< Glib::RefPtr<Gdk::Device> > devList = display->list_devices(); #endif + // Set iterator to point at beginning of device list + std::vector< Glib::RefPtr<Gdk::Device> >::iterator dev = devList.begin(); + // Skip past any items in the device list that are not mice - while ( devList && devList->data && (gdk_device_get_source ((GdkDevice*)devList->data) != GDK_SOURCE_MOUSE)) { - devList = g_list_next(devList); + while (dev != devList.end() && (*dev)->get_source() != Gdk::SOURCE_MOUSE) { + ++dev; } - if ( devList && devList->data ) { - GdkDevice *device = (GdkDevice*)devList->data; - fakeout[4].name = g_strdup(gdk_device_get_name (device)); - fakeout[4].source = gdk_device_get_source (device); - fakeout[4].mode = gdk_device_get_mode (device); - fakeout[4].has_cursor = gdk_device_get_has_cursor (device); - fakeout[4].num_axes = gdk_device_get_n_axes (device); - fakeout[4].num_keys = gdk_device_get_n_keys (device); + if (dev != devList.end()) { + Glib::RefPtr<Gdk::Device> device = *dev; + fakeList[4].name = device->get_name(); + fakeList[4].source = device->get_source(); + fakeList[4].mode = device->get_mode(); + fakeList[4].has_cursor = device->get_has_cursor(); + fakeList[4].num_axes = device->get_n_axes(); +#if WITH_GTKMM_3_0 + fakeList[4].num_keys = device->get_n_keys(); +#else + fakeList[4].num_keys = gdk_device_get_n_keys(device->gobj()); +#endif } else { - fakeout[4].name = g_strdup("Core Pointer"); - fakeout[4].source = GDK_SOURCE_MOUSE; - fakeout[4].mode = GDK_MODE_SCREEN; - fakeout[4].has_cursor = TRUE; - fakeout[4].num_axes = 2; - fakeout[4].num_keys = 0; - } - - for ( guint pos = 0; pos < G_N_ELEMENTS(fakeout); pos++) { - fakeList = g_list_append(fakeList, &(fakeout[pos])); + fakeList[4].name = "Core Pointer"; + fakeList[4].source = Gdk::SOURCE_MOUSE; + fakeList[4].mode = Gdk::MODE_SCREEN; + fakeList[4].has_cursor = true; + fakeList[4].num_axes = 2; + fakeList[4].num_keys = 0; } - -#if GTK_CHECK_VERSION(3,0,0) - g_list_free(devList); -#endif } - } - /* Local Variables: mode:c++ diff --git a/src/display/CMakeLists.txt b/src/display/CMakeLists.txt index 800c4d0d4..d4f8c16ff 100644 --- a/src/display/CMakeLists.txt +++ b/src/display/CMakeLists.txt @@ -42,7 +42,6 @@ set(display_SRC nr-filter-tile.cpp nr-filter-turbulence.cpp nr-filter-units.cpp - nr-filter-utils.cpp nr-filter.cpp nr-light.cpp nr-style.cpp diff --git a/src/display/Makefile_insert b/src/display/Makefile_insert index 2355c3653..20e498981 100644 --- a/src/display/Makefile_insert +++ b/src/display/Makefile_insert @@ -90,7 +90,6 @@ ink_common_sources += \ display/nr-filter-types.h \ display/nr-filter-units.cpp \ display/nr-filter-units.h \ - display/nr-filter-utils.cpp \ display/nr-filter-utils.h \ display/nr-light.cpp \ display/nr-light.h \ diff --git a/src/display/canvas-axonomgrid.cpp b/src/display/canvas-axonomgrid.cpp index 88c23bf62..a2df86823 100644 --- a/src/display/canvas-axonomgrid.cpp +++ b/src/display/canvas-axonomgrid.cpp @@ -50,7 +50,7 @@ #include "svg/svg-color.h" #include "2geom/line.h" #include "2geom/angle.h" -#include "util/mathfns.h" +#include "helper/mathfns.h" #include "round.h" #include "util/units.h" diff --git a/src/display/canvas-grid.cpp b/src/display/canvas-grid.cpp index 0f58096ce..9b9f64529 100644 --- a/src/display/canvas-grid.cpp +++ b/src/display/canvas-grid.cpp @@ -35,7 +35,7 @@ #include "ui/widget/registered-widget.h" #include "desktop.h" #include "sp-canvas-util.h" -#include "util/mathfns.h" +#include "helper/mathfns.h" #include "display/cairo-utils.h" #include "display/canvas-axonomgrid.h" @@ -50,7 +50,7 @@ #include "sp-root.h" #include "svg/svg-color.h" #include "svg/stringstream.h" -#include "util/mathfns.h" +#include "helper/mathfns.h" #include "xml/node-event-vector.h" #include "verbs.h" #include "display/sp-canvas.h" diff --git a/src/display/drawing.cpp b/src/display/drawing.cpp index 6e728b03d..eadd7e528 100644 --- a/src/display/drawing.cpp +++ b/src/display/drawing.cpp @@ -210,9 +210,9 @@ Drawing::_pickItemsForCaching() } std::set<DrawingItem*> to_cache; - for (i = _candidate_items.begin(); i != _candidate_items.end(); ++i) { - i->item->setCached(true); - to_cache.insert(i->item); + for (CandidateList::iterator j = _candidate_items.begin(); j != i; ++j) { + j->item->setCached(true); + to_cache.insert(j->item); } // Everything which is now in _cached_items but not in to_cache must be uncached // Note that calling setCached on an item modifies _cached_items diff --git a/src/display/nr-filter-utils.cpp b/src/display/nr-filter-utils.cpp deleted file mode 100644 index 1ba341791..000000000 --- a/src/display/nr-filter-utils.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "nr-filter-utils.h" - -namespace Inkscape { -namespace Filters { - -/* Everything moved to .h, because they were short functions that should - * get inlined */ - -} /* namespace Filters */ -} /* namespace Inkscape */ - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/display/nr-filter.h b/src/display/nr-filter.h index 9a30efabd..211d8ddd9 100644 --- a/src/display/nr-filter.h +++ b/src/display/nr-filter.h @@ -18,7 +18,7 @@ #include "display/nr-filter-types.h" #include "svg/svg-length.h" #include "sp-filter-units.h" -#include "gc-managed.h" +#include "inkgc/gc-managed.h" namespace Inkscape { class DrawingContext; diff --git a/src/display/snap-indicator.cpp b/src/display/snap-indicator.cpp index bcce81f0b..8c0c8163f 100644 --- a/src/display/snap-indicator.cpp +++ b/src/display/snap-indicator.cpp @@ -256,7 +256,7 @@ SnapIndicator::set_new_snaptarget(Inkscape::SnappedPoint const &p, bool pre_snap "shape", SP_KNOT_SHAPE_CROSS, NULL ); - const int timeout_val = 1200; // TODO add preference for snap indicator timeout? + const int timeout_val = 4000; SP_CTRL(canvasitem)->moveto(p.getPoint()); _snaptarget = _desktop->add_temporary_canvasitem(canvasitem, timeout_val); diff --git a/src/document-subset.h b/src/document-subset.h index 298b7872d..2799ff173 100644 --- a/src/document-subset.h +++ b/src/document-subset.h @@ -14,7 +14,7 @@ #include <sigc++/connection.h> #include <sigc++/functors/slot.h> -#include "gc-managed.h" +#include "inkgc/gc-managed.h" #include "gc-anchored.h" class SPObject; diff --git a/src/document.cpp b/src/document.cpp index 2caefb4ed..62e2f5b46 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -368,7 +368,7 @@ SPDocument *SPDocument::createDoc(Inkscape::XML::Document *rdoc, // Create SPRoot element const std::string typeString = NodeTraits::get_type_string(*rroot); - SPObject* rootObj = SPFactory::instance().createObject(typeString); + SPObject* rootObj = SPFactory::createObject(typeString); document->root = dynamic_cast<SPRoot*>(rootObj); if (document->root == 0) { @@ -611,7 +611,25 @@ Inkscape::Util::Unit const& SPDocument::getSVGUnit() const return nv ? nv->getSVGUnit() : *unit_table.getUnit("px"); } -/// Returns document scale as defined by width/height and viewBox (real world to user-units). +/// Sets document scale (by changing viewBox) +void SPDocument::setDocumentScale( double scaleX, double scaleY ) { + + root->viewBox = Geom::Rect::from_xywh( + root->viewBox.left(), + root->viewBox.top(), + root->width.computed * scaleX, + root->height.computed * scaleY ); + root->viewBox_set = true; + root->updateRepr(); +} + +/// Sets document scale (by changing viewBox, x and y scaling equal) +void SPDocument::setDocumentScale( double scale ) { + setDocumentScale( scale, scale ); +} + +/// Returns document scale as defined by width/height (in pixels) and viewBox (real world to +/// user-units). Geom::Scale SPDocument::getDocumentScale() const { Geom::Scale scale; @@ -637,7 +655,11 @@ void SPDocument::setWidthAndHeight(const Inkscape::Util::Quantity &width, const Inkscape::Util::Unit const *old_width_units = unit_table.getUnit("px"); if (root->width.unit) old_width_units = unit_table.getUnit(root->width.unit); - gdouble old_width_converted = Inkscape::Util::Quantity::convert(root->width.value, old_width_units, width.unit); + gdouble old_width_converted; // old width converted to new units + if (root->width.unit == SVGLength::PERCENT) + old_width_converted = Inkscape::Util::Quantity::convert(root->width.computed, "px", width.unit); + else + old_width_converted = Inkscape::Util::Quantity::convert(root->width.value, old_width_units, width.unit); root->width.computed = width.value("px"); root->width.value = width.quantity; @@ -646,16 +668,22 @@ void SPDocument::setWidthAndHeight(const Inkscape::Util::Quantity &width, const Inkscape::Util::Unit const *old_height_units = unit_table.getUnit("px"); if (root->height.unit) old_height_units = unit_table.getUnit(root->height.unit); - gdouble old_height_converted = Inkscape::Util::Quantity::convert(root->height.value, old_height_units, height.unit); + gdouble old_height_converted; // old height converted to new units + if (root->height.unit == SVGLength::PERCENT) + old_height_converted = Inkscape::Util::Quantity::convert(root->height.computed, "px", height.unit); + else + old_height_converted = Inkscape::Util::Quantity::convert(root->height.value, old_height_units, height.unit); root->height.computed = height.value("px"); root->height.value = height.quantity; root->height.unit = (SVGLength::Unit) height.unit->svgUnit(); - if (root->viewBox_set && changeSize) + // viewBox scaled by relative change in page size (maintains document scale). + if (root->viewBox_set && changeSize) { root->viewBox.setMax(Geom::Point( root->viewBox.left() + (root->width.value / old_width_converted ) * root->viewBox.width(), root->viewBox.top() + (root->height.value / old_height_converted) * root->viewBox.height())); + } root->updateRepr(); } @@ -678,17 +706,21 @@ Inkscape::Util::Quantity SPDocument::getWidth() const void SPDocument::setWidth(const Inkscape::Util::Quantity &width, bool changeSize) { - Inkscape::Util::Unit const *old_units = unit_table.getUnit("px"); + Inkscape::Util::Unit const *old_width_units = unit_table.getUnit("px"); if (root->width.unit) - old_units = unit_table.getUnit(root->width.unit); - gdouble old_converted = Inkscape::Util::Quantity::convert(root->width.value, old_units, width.unit); + old_width_units = unit_table.getUnit(root->width.unit); + gdouble old_width_converted; // old width converted to new units + if (root->width.unit == SVGLength::PERCENT) + old_width_converted = Inkscape::Util::Quantity::convert(root->width.computed, "px", width.unit); + else + old_width_converted = Inkscape::Util::Quantity::convert(root->width.value, old_width_units, width.unit); root->width.computed = width.value("px"); root->width.value = width.quantity; root->width.unit = (SVGLength::Unit) width.unit->svgUnit(); if (root->viewBox_set && changeSize) - root->viewBox.setMax(Geom::Point(root->viewBox.left() + (root->width.value / old_converted) * root->viewBox.width(), root->viewBox.bottom())); + root->viewBox.setMax(Geom::Point(root->viewBox.left() + (root->width.value / old_width_converted) * root->viewBox.width(), root->viewBox.bottom())); root->updateRepr(); } @@ -713,17 +745,21 @@ Inkscape::Util::Quantity SPDocument::getHeight() const void SPDocument::setHeight(const Inkscape::Util::Quantity &height, bool changeSize) { - Inkscape::Util::Unit const *old_units = unit_table.getUnit("px"); + Inkscape::Util::Unit const *old_height_units = unit_table.getUnit("px"); if (root->height.unit) - old_units = unit_table.getUnit(root->height.unit); - gdouble old_converted = Inkscape::Util::Quantity::convert(root->height.value, old_units, height.unit); + old_height_units = unit_table.getUnit(root->height.unit); + gdouble old_height_converted; // old height converted to new units + if (root->height.unit == SVGLength::PERCENT) + old_height_converted = Inkscape::Util::Quantity::convert(root->height.computed, "px", height.unit); + else + old_height_converted = Inkscape::Util::Quantity::convert(root->height.value, old_height_units, height.unit); root->height.computed = height.value("px"); root->height.value = height.quantity; root->height.unit = (SVGLength::Unit) height.unit->svgUnit(); if (root->viewBox_set && changeSize) - root->viewBox.setMax(Geom::Point(root->viewBox.right(), root->viewBox.top() + (root->height.value / old_converted) * root->viewBox.height())); + root->viewBox.setMax(Geom::Point(root->viewBox.right(), root->viewBox.top() + (root->height.value / old_height_converted) * root->viewBox.height())); root->updateRepr(); } @@ -761,7 +797,7 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins) double const old_height = getHeight().value("px"); Inkscape::Util::Unit const *nv_units = unit_table.getUnit("px"); - if (root->height.unit) + if (root->height.unit && (root->height.unit != SVGLength::PERCENT)) nv_units = unit_table.getUnit(root->height.unit); SPNamedView *nv = sp_document_namedview(this, NULL); diff --git a/src/document.h b/src/document.h index 22c341eae..ed19d123b 100644 --- a/src/document.h +++ b/src/document.h @@ -21,7 +21,7 @@ #include <sigc++/sigc++.h> #include "libcroco/cr-cascade.h" #include <2geom/forward.h> -#include "gc-managed.h" +#include "inkgc/gc-managed.h" #include "gc-finalized.h" #include "gc-anchored.h" #include <glibmm/ustring.h> @@ -242,6 +242,8 @@ public: SPDocument *doUnref(); Inkscape::Util::Unit const* getDisplayUnit() const; Inkscape::Util::Unit const& getSVGUnit() const; + void setDocumentScale( const double scaleX, const double scaleY ); + void setDocumentScale( const double scale ); Geom::Scale getDocumentScale() const; Inkscape::Util::Quantity getWidth() const; Inkscape::Util::Quantity getHeight() const; diff --git a/src/doxygen-main.cpp b/src/doxygen-main.dox index 6a5723bfd..6a5723bfd 100644 --- a/src/doxygen-main.cpp +++ b/src/doxygen-main.dox diff --git a/src/extension/internal/cairo-render-context.cpp b/src/extension/internal/cairo-render-context.cpp index d76c187a2..2d6619e1e 100644 --- a/src/extension/internal/cairo-render-context.cpp +++ b/src/extension/internal/cairo-render-context.cpp @@ -42,6 +42,7 @@ #include "sp-hatch.h" #include "sp-linear-gradient.h" #include "sp-radial-gradient.h" +#include "sp-mesh.h" #include "sp-pattern.h" #include "sp-mask.h" #include "sp-clippath.h" @@ -1259,6 +1260,10 @@ CairoRenderContext::_createPatternForPaintServer(SPPaintServer const *const pain sp_color_get_rgb_floatv(&rg->vector.stops[i].color, rgb); cairo_pattern_add_color_stop_rgba(pattern, rg->vector.stops[i].offset, rgb[0], rgb[1], rgb[2], rg->vector.stops[i].opacity * alpha); } + } else if (SP_IS_MESH (paintserver)) { + SPMesh *mg = SP_MESH(paintserver); + + pattern = mg->pattern_new(_cr, pbox, 1.0); } else if (SP_IS_PATTERN (paintserver)) { pattern = _createPatternPainter(paintserver, pbox); } else if ( dynamic_cast<SPHatch const *>(paintserver) ) { diff --git a/src/extension/internal/cairo-renderer.cpp b/src/extension/internal/cairo-renderer.cpp index 1f48d2097..7fbdc4296 100644 --- a/src/extension/internal/cairo-renderer.cpp +++ b/src/extension/internal/cairo-renderer.cpp @@ -517,7 +517,7 @@ static void sp_item_invoke_render(SPItem *item, CairoRenderContext *ctx) SPStyle* style = item->style; if((ctx->getFilterToBitmap() == TRUE) && (style->filter.set != 0)) { - sp_asbitmap_render(item, ctx); + return sp_asbitmap_render(item, ctx); } SPRoot *root = dynamic_cast<SPRoot *>(item); diff --git a/src/extension/internal/emf-inout.cpp b/src/extension/internal/emf-inout.cpp index 4b070cbaa..31e69706f 100644 --- a/src/extension/internal/emf-inout.cpp +++ b/src/extension/internal/emf-inout.cpp @@ -45,8 +45,8 @@ #include "display/drawing-item.h" #include "clear-n_.h" #include "svg/svg.h" -#include "util/units.h" // even though it is included indirectly by wmf-inout.h -#include "inkscape.h" // even though it is included indirectly by wmf-inout.h +#include "util/units.h" // even though it is included indirectly by emf-inout.h +#include "inkscape.h" // even though it is included indirectly by emf-inout.h #include "emf-print.h" #include "emf-inout.h" @@ -188,7 +188,7 @@ double Emf::current_scale(PEMF_CALLBACK_DATA d){ "matrix(a,b,c,d,e,f)" (WITH the double quotes) */ std::string Emf::current_matrix(PEMF_CALLBACK_DATA d, double x, double y, int useoffset){ - std::stringstream cxform; + SVGOStringStream cxform; double scale = current_scale(d); cxform << "\"matrix("; cxform << d->dc[d->level].worldTransform.eM11/scale; cxform << ","; @@ -1058,7 +1058,7 @@ Emf::snap_to_faraway_pair(double *x, double *y) Since exclude clip can go through here, it calls snap_to_faraway_pair for numerical stability. */ std::string Emf::pix_to_xy(PEMF_CALLBACK_DATA d, double x, double y){ - std::stringstream cxform; + SVGOStringStream cxform; double tx = pix_to_x_point(d,x,y); double ty = pix_to_y_point(d,x,y); snap_to_faraway_pair(&tx,&ty); @@ -1515,6 +1515,9 @@ void Emf::common_image_extraction(PEMF_CALLBACK_DATA d, void *pEmr, int dibparams = U_BI_UNKNOWN; // type of image not yet determined tmp_image << "\n\t <image\n"; + if (d->dc[d->level].clip_id){ + tmp_image << "\tclip-path=\"url(#clipEmfPath" << d->dc[d->level].clip_id << ")\"\n"; + } tmp_image << " y=\"" << dy << "\"\n x=\"" << dx <<"\"\n "; MEMPNG mempng; // PNG in memory comes back in this @@ -1727,21 +1730,23 @@ std::cout << "BEFORE DRAW" ) ){ // std::cout << "PATH DRAW at TOP path" << *(d->path) << std::endl; - d->outsvg += " <path "; // this is the ONLY place <path should be used!!! One exception, gradientfill. - if(d->drawtype){ // explicit draw type EMR record - output_style(d, d->drawtype); - } - else if(d->mask & U_DRAW_CLOSED){ // implicit draw type - output_style(d, U_EMR_STROKEANDFILLPATH); - } - else { - output_style(d, U_EMR_STROKEPATH); + if(!(d->path.empty())){ + d->outsvg += " <path "; // this is the ONLY place <path should be used!!! One exception, gradientfill. + if(d->drawtype){ // explicit draw type EMR record + output_style(d, d->drawtype); + } + else if(d->mask & U_DRAW_CLOSED){ // implicit draw type + output_style(d, U_EMR_STROKEANDFILLPATH); + } + else { + output_style(d, U_EMR_STROKEPATH); + } + d->outsvg += "\n\t"; + d->outsvg += "\n\td=\""; // this is the ONLY place d=" should be used!!!! One exception, gradientfill. + d->outsvg += d->path; + d->outsvg += " \" /> \n"; + d->path = ""; } - d->outsvg += "\n\t"; - d->outsvg += "\n\td=\""; // this is the ONLY place d=" should be used!!!! One exception, gradientfill. - d->outsvg += d->path; - d->outsvg += " \" /> \n"; - d->path = ""; // reset the flags d->mask = 0; d->drawtype = 0; @@ -3418,7 +3423,11 @@ std::cout << "BEFORE DRAW" tmp_rectangle << "\n\tz\""; tmp_rectangle << "\n\tstyle=\"stroke:none;fill:url(#"; tmp_rectangle << d->gradients.strings[fill_idx]; - tmp_rectangle << ");\"\n/>\n"; + tmp_rectangle << ");\"\n"; + if (d->dc[d->level].clip_id){ + tmp_rectangle << "\tclip-path=\"url(#clipEmfPath" << d->dc[d->level].clip_id << ")\"\n"; + } + tmp_rectangle << "/>\n"; } d->outsvg += tmp_rectangle.str().c_str(); } @@ -3538,7 +3547,7 @@ Emf::open( Inkscape::Extension::Input * /*mod*/, const gchar *uri ) d.tri = trinfo_release_except_FC(d.tri); - setViewBoxIfMissing(doc); + // in earlier versions no viewbox was generated and a call to setViewBoxIfMissing() was needed here. return doc; } diff --git a/src/extension/internal/emf-print.cpp b/src/extension/internal/emf-print.cpp index f7b6626c4..67a9242bc 100644 --- a/src/extension/internal/emf-print.cpp +++ b/src/extension/internal/emf-print.cpp @@ -251,7 +251,11 @@ unsigned int PrintEmf::begin(Inkscape::Extension::Print *mod, SPDocument *doc) g_error("Fatal programming error in PrintEmf::begin at textcomment_set 1"); } + char *oldlocale = g_strdup(setlocale(LC_NUMERIC, NULL)); + setlocale(LC_NUMERIC, "C"); snprintf(buff, sizeof(buff) - 1, "Drawing=%.1lfx%.1lfpx, %.1lfx%.1lfmm", _width, _height, Inkscape::Util::Quantity::convert(dwInchesX, "in", "mm"), Inkscape::Util::Quantity::convert(dwInchesY, "in", "mm")); + setlocale(LC_NUMERIC, oldlocale); + g_free(oldlocale); rec = textcomment_set(buff); if (!rec || emf_append((PU_ENHMETARECORD)rec, et, U_REC_FREE)) { g_error("Fatal programming error in PrintEmf::begin at textcomment_set 1"); @@ -706,7 +710,7 @@ int PrintEmf::create_pen(SPStyle const *style, const Geom::Affine &transform) n_dash = style->stroke_dasharray.values.size(); dash = new uint32_t[n_dash]; for (i = 0; i < n_dash; i++) { - dash[i] = (uint32_t)(Inkscape::Util::Quantity::convert(1, "mm", "px") * style->stroke_dasharray.values[i]); + dash[i] = style->stroke_dasharray.values[i]; } } } diff --git a/src/extension/internal/filter/color.h b/src/extension/internal/filter/color.h index 19af6e969..c3c26bf8b 100644 --- a/src/extension/internal/filter/color.h +++ b/src/extension/internal/filter/color.h @@ -3,13 +3,14 @@ /* Change the 'COLOR' above to be your file name */ /* - * Copyright (C) 2013 Authors: + * Copyright (C) 2013-2015 Authors: * Ivan Louette (filters) * Nicolas Dufour (UI) <nicoduf@yahoo.fr> * * Color filters * Brilliance * Channel painting + * Color blindness * Color shift * Colorize * Component transfer @@ -231,6 +232,80 @@ ChannelPaint::get_filter_text (Inkscape::Extension::Extension * ext) }; /* Channel Painting filter */ /** + \brief Custom predefined Color Blindness filter. + + Color Blindness filter. + Based on https://openclipart.org/detail/22299/Color%20Blindness%20filters + + Filter's parameters: + * Blindness type (enum, default Achromatomaly) -> colormatrix +*/ +class ColorBlindness : public Inkscape::Extension::Internal::Filter::Filter { +protected: + virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext); + +public: + ColorBlindness ( ) : Filter() { }; + virtual ~ColorBlindness ( ) { if (_filter != NULL) g_free((void *)_filter); return; } + + static void init (void) { + Inkscape::Extension::build_from_mem( + "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n" + "<name>" N_("Color Blindness") "</name>\n" + "<id>org.inkscape.effect.filter.ColorBlindness</id>\n" + "<param name=\"tab\" type=\"notebook\">\n" + "<page name=\"optionstab\" _gui-text=\"Options\">\n" + "<param name=\"type\" gui-text=\"" N_("Blindness type:") "\" type=\"enum\">\n" + "<_item value=\"0.618 0.32 0.062 0 0 0.163 0.775 0.062 0 0 0.163 0.32 0.516 0 0 0 0 0 1 0 \">" N_("Rod monochromacy (atypical achromatopsia)") "</_item>\n" + "<_item value=\"0.299 0.587 0.114 0 0 0.299 0.587 0.114 0 0 0.299 0.587 0.114 0 0 0 0 0 1 0 \">" N_("Cone monochromacy (typical achromatopsia)") "</_item>\n" + "<_item value=\"0.8 0.2 0 0 0 0.2583 0.74167 0 0 0 0 0.14167 0.85833 0 0 0 0 0 1 0 \">" N_("Geen weak (deuteranomaly)") "</_item>\n" + "<_item value=\"0.625 0.375 0 0 0 0.7 0.3 0 0 0 0 0.3 0.7 0 0 0 0 0 1 0 \">" N_("Green blind (deuteranopia)") "</_item>\n" + "<_item value=\"0.8166 0.1833 0 0 0 0.333 0.666 0 0 0 0 0.125 0.875 0 0 0 0 0 1 0 \">" N_("Red weak (protanomaly)") "</_item>\n" + "<_item value=\"0.566 0.43333 0 0 0 0.55833 0.4416 0 0 0 0 0.24167 0.75833 0 0 0 0 0 1 0 \">" N_("Red blind (protanopia)") "</_item>\n" + "<_item value=\"0.966 0.033 0 0 0 0 0.733 0.266 0 0 0 0.1833 0.816 0 0 0 0 0 1 0 \">" N_("Blue weak (tritanomaly)") "</_item>\n" + "<_item value=\"0.95 0.05 0 0 0 0.2583 0.4333 0.5667 0 0 0 0.475 0.525 0 0 0 0 0 1 0 \">" N_("Blue blind (tritanopia)") "</_item>\n" + "</param>\n" + "</page>\n" + "<page name=\"helptab\" _gui-text=\"Help\">\n" + "<param name=\"help\" xml:space=\"preserve\" type=\"description\">\n" +"Filters based on https://openclipart.org/detail/22299/Color%20Blindness%20filters\n" +"\n" +"These filters don't correctly reflect actual color blindness for two main reasons:\n" +" * Everyone is different, and is not affected exactly the same way.\n" +" * The filters are in the RGB color space, and ignore confusion lines.\n" + "</param>\n" + "</page>\n" + "</param>\n" + "<effect>\n" + "<object-type>all</object-type>\n" + "<effects-menu>\n" + "<submenu name=\"" N_("Filters") "\">\n" + "<submenu name=\"" N_("Color") "\"/>\n" + "</submenu>\n" + "</effects-menu>\n" + "<menu-tip>" N_("Simulate color blindness") "</menu-tip>\n" + "</effect>\n" + "</inkscape-extension>\n", new ColorBlindness()); + }; +}; + +gchar const * +ColorBlindness::get_filter_text (Inkscape::Extension::Extension * ext) +{ + if (_filter != NULL) g_free((void *)_filter); + + std::ostringstream type; + type << ext->get_param_enum("type"); + + _filter = g_strdup_printf( + "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" style=\"color-interpolation-filters:sRGB;\" height=\"1\" width=\"1\" y=\"0\" x=\"0\" inkscape:label=\"Color Blindness\">\n" + "<feColorMatrix values=\"%s\" type=\"matrix\" result=\"colormatrix1\" />\n" + "</filter>\n", type.str().c_str()); + + return _filter; +}; /* Color Blindness filter */ + +/** \brief Custom predefined Color shift filter. Rotate and desaturate hue diff --git a/src/extension/internal/filter/filter-all.cpp b/src/extension/internal/filter/filter-all.cpp index 0273d1669..35504d37f 100644 --- a/src/extension/internal/filter/filter-all.cpp +++ b/src/extension/internal/filter/filter-all.cpp @@ -54,6 +54,7 @@ Filter::filters_all (void ) // Color Brilliance::init(); ChannelPaint::init(); + ColorBlindness::init(); ColorShift::init(); Colorize::init(); ComponentTransfer::init(); diff --git a/src/extension/internal/pdfinput/pdf-parser.cpp b/src/extension/internal/pdfinput/pdf-parser.cpp index 812fa373f..cc0b38515 100644 --- a/src/extension/internal/pdfinput/pdf-parser.cpp +++ b/src/extension/internal/pdfinput/pdf-parser.cpp @@ -2586,24 +2586,12 @@ void PdfParser::opShowSpaceText(Object args[], int /*numArgs*/) } } - - -/* - * The `POPPLER_NEW_GFXFONT' stuff is for the change to GfxFont's getNextChar() call. - * Thanks to tsdgeos for the fix. - * Miklos, does this look ok? - */ - void PdfParser::doShowText(GooString *s) { GfxFont *font; int wMode; double riseX, riseY; CharCode code; -#ifdef POPPLER_NEW_GFXFONT Unicode *u = NULL; -#else - Unicode u[8]; -#endif double x, y, dx, dy, tdx, tdy; double originX, originY, tOriginX, tOriginY; double oldCTM[6], newCTM[6]; @@ -2651,11 +2639,7 @@ void PdfParser::doShowText(GooString *s) { len = s->getLength(); while (len > 0) { n = font->getNextChar(p, len, &code, -#ifdef POPPLER_NEW_GFXFONT &u, &uLen, /* TODO: This looks like a memory leak for u. */ -#else - u, (int)(sizeof(u) / sizeof(Unicode)), &uLen, -#endif &dx, &dy, &originX, &originY); dx = dx * state->getFontSize() + state->getCharSpace(); if (n == 1 && *p == ' ') { @@ -2708,11 +2692,7 @@ void PdfParser::doShowText(GooString *s) { len = s->getLength(); while (len > 0) { n = font->getNextChar(p, len, &code, -#ifdef POPPLER_NEW_GFXFONT &u, &uLen, /* TODO: This looks like a memory leak for u. */ -#else - u, (int)(sizeof(u) / sizeof(Unicode)), &uLen, -#endif &dx, &dy, &originX, &originY); if (wMode) { diff --git a/src/extension/internal/text_reassemble.c b/src/extension/internal/text_reassemble.c index 4dfc49420..d3aafef12 100644 --- a/src/extension/internal/text_reassemble.c +++ b/src/extension/internal/text_reassemble.c @@ -67,11 +67,11 @@ Optional compiler switches for development: File: text_reassemble.c -Version: 0.0.15 -Date: 24-JUL-2014 +Version: 0.0.16 +Date: 25-FEB-2015 Author: David Mathog, Biology Division, Caltech email: mathog@caltech.edu -Copyright: 2014 David Mathog and California Institute of Technology (Caltech) +Copyright: 2015 David Mathog and California Institute of Technology (Caltech) */ #ifdef __cplusplus @@ -80,6 +80,7 @@ extern "C" { #include "text_reassemble.h" #include <libuemf/uemf_utf.h> /* For a couple of text functions. Exact copy from libUEMF. */ +#include <locale.h> #include <float.h> /* Code generated by make_ucd_mn_table.c using: @@ -1936,6 +1937,15 @@ void TR_layout_2_svg(TR_INFO *tri){ double newx,newy,tmpx; uint32_t utmp; + /* copy the current numeric locale, make a copy because setlocale may stomp on + the memory it points to. Then change it because SVG needs decimal points, + not commas, in floats. Restore on exit from this routine. + */ + char *prev_locale = setlocale(LC_NUMERIC,NULL); + char *hold_locale = malloc(sizeof(char) * (strlen(prev_locale) + 1)); + strcpy(hold_locale,prev_locale); + (void) setlocale(LC_NUMERIC,"POSIX"); + /* #define DBG_TR_PARA 0 #define DBG_TR_INPUT 1 @@ -2232,6 +2242,10 @@ void TR_layout_2_svg(TR_INFO *tri){ } /* end of j loop */ TRPRINT(tri,"</tspan></text>\n"); } /* end of i loop */ + + /* restore locale and free memory. */ + (void) setlocale(LC_NUMERIC,hold_locale); + free(hold_locale); } /** diff --git a/src/extension/internal/wmf-inout.cpp b/src/extension/internal/wmf-inout.cpp index 72c1c8bd3..503a93418 100644 --- a/src/extension/internal/wmf-inout.cpp +++ b/src/extension/internal/wmf-inout.cpp @@ -176,7 +176,7 @@ double Wmf::current_scale(PWMF_CALLBACK_DATA /*d*/){ /* WMF has no worldTransform, so this always returns an Identity rotation matrix, but the offsets may have values.*/ std::string Wmf::current_matrix(PWMF_CALLBACK_DATA d, double x, double y, int useoffset){ - std::stringstream cxform; + SVGOStringStream cxform; double scale = current_scale(d); cxform << "\"matrix("; cxform << 1.0/scale; cxform << ","; @@ -948,7 +948,7 @@ Wmf::pix_to_abs_size(PWMF_CALLBACK_DATA d, double px) /* returns "x,y" (without the quotes) in inkscape coordinates for a pair of WMF x,y coordinates */ std::string Wmf::pix_to_xy(PWMF_CALLBACK_DATA d, double x, double y){ - std::stringstream cxform; + SVGOStringStream cxform; cxform << pix_to_x_point(d,x,y); cxform << ","; cxform << pix_to_y_point(d,x,y); @@ -1308,6 +1308,9 @@ void Wmf::common_dib_to_image(PWMF_CALLBACK_DATA d, const char *dib, int dibparams = U_BI_UNKNOWN; // type of image not yet determined tmp_image << "\n\t <image\n"; + if (d->dc[d->level].clip_id){ + tmp_image << "\tclip-path=\"url(#clipWmfPath" << d->dc[d->level].clip_id << ")\"\n"; + } tmp_image << " y=\"" << dy << "\"\n x=\"" << dx <<"\"\n "; MEMPNG mempng; // PNG in memory comes back in this @@ -1405,6 +1408,9 @@ void Wmf::common_bm16_to_image(PWMF_CALLBACK_DATA d, U_BITMAP16 Bm16, const char SVGOStringStream tmp_image; tmp_image << "\n\t <image\n"; + if (d->dc[d->level].clip_id){ + tmp_image << "\tclip-path=\"url(#clipWmfPath" << d->dc[d->level].clip_id << ")\"\n"; + } tmp_image << " y=\"" << dy << "\"\n x=\"" << dx <<"\"\n "; MEMPNG mempng; // PNG in memory comes back in this @@ -1752,13 +1758,15 @@ std::cout << "BEFORE DRAW" ) ){ // std::cout << "PATH DRAW at TOP <<+++++++++++++++++++++++++++++++++++++" << std::endl; - d->outsvg += " <path "; // this is the ONLY place <path should be used!!!! - output_style(d); - d->outsvg += "\n\t"; - d->outsvg += "\n\td=\""; // this is the ONLY place d=" should be used!!!! - d->outsvg += d->path; - d->outsvg += " \" /> \n"; - d->path = ""; //reset the path + if(!(d->path.empty())){ + d->outsvg += " <path "; // this is the ONLY place <path should be used!!!! + output_style(d); + d->outsvg += "\n\t"; + d->outsvg += "\n\td=\""; // this is the ONLY place d=" should be used!!!! + d->outsvg += d->path; + d->outsvg += " \" /> \n"; + d->path = ""; //reset the path + } // reset the flags d->mask = 0; d->drawtype = 0; @@ -2600,9 +2608,9 @@ std::cout << "BEFORE DRAW" if(status==-1){ // change of escapement, emit what we have and reset TR_layout_analyze(d->tri); if (d->dc[d->level].clip_id){ - SVGOStringStream tmp_clip; - tmp_clip << "\n<g\n\tclip-path=\"url(#clipWmfPath" << d->dc[d->level].clip_id << ")\"\n>"; - d->outsvg += tmp_clip.str().c_str(); + SVGOStringStream tmp_clip; + tmp_clip << "\n<g\n\tclip-path=\"url(#clipWmfPath" << d->dc[d->level].clip_id << ")\"\n>"; + d->outsvg += tmp_clip.str().c_str(); } TR_layout_2_svg(d->tri); ts << d->tri->out; @@ -2610,7 +2618,7 @@ std::cout << "BEFORE DRAW" d->tri = trinfo_clear(d->tri); (void) trinfo_load_textrec(d->tri, &tsp, tsp.ori,TR_EMFBOT); // ignore return status, it must work if (d->dc[d->level].clip_id){ - d->outsvg += "\n</g>\n"; + d->outsvg += "\n</g>\n"; } } @@ -3113,7 +3121,7 @@ Wmf::open( Inkscape::Extension::Input * /*mod*/, const gchar *uri ) d.tri = trinfo_release_except_FC(d.tri); - setViewBoxIfMissing(doc); + // in earlier versions no viewbox was generated and a call to setViewBoxIfMissing() was needed here. return doc; } diff --git a/src/extension/internal/wmf-print.cpp b/src/extension/internal/wmf-print.cpp index e5ff34009..567f9f366 100644 --- a/src/extension/internal/wmf-print.cpp +++ b/src/extension/internal/wmf-print.cpp @@ -366,11 +366,12 @@ int PrintWmf::create_brush(SPStyle const *style, U_COLORREF *fcolor) if (!fcolor && style) { if (style->fill.isColor()) { fill_mode = DRAW_PAINT; + /* Dead assignment: Value stored to 'opacity' is never read float opacity = SP_SCALE24_TO_FLOAT(style->fill_opacity.value); if (opacity <= 0.0) { opacity = 0.0; // basically the same as no fill } - + */ sp_color_get_rgb_floatv(&style->fill.value.color, rgb); hatchColor = U_RGB(255 * rgb[0], 255 * rgb[1], 255 * rgb[2]); diff --git a/src/extension/param/radiobutton.cpp b/src/extension/param/radiobutton.cpp index f9515197c..740acf1d1 100644 --- a/src/extension/param/radiobutton.cpp +++ b/src/extension/param/radiobutton.cpp @@ -249,28 +249,35 @@ void ParamRadioButtonWdg::changed(void) class ComboWdg : public Gtk::ComboBoxText { +private: + ParamRadioButton* _base; + SPDocument* _doc; + Inkscape::XML::Node* _node; + sigc::signal<void> * _changeSignal; + public: - ComboWdg(ParamRadioButton* base, SPDocument * doc, Inkscape::XML::Node * node) : - Gtk::ComboBoxText(), - base(base), - doc(doc), - node(node) + ComboWdg(ParamRadioButton* base, SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal) : + _base(base), + _doc(doc), + _node(node), + _changeSignal(changeSignal) { + this->signal_changed().connect(sigc::mem_fun(this, &ComboWdg::changed)); } virtual ~ComboWdg() {} + void changed (void); +}; -protected: - ParamRadioButton* base; - SPDocument* doc; - Inkscape::XML::Node* node; - - virtual void on_changed() { - if ( base ) { - Glib::ustring value = base->value_from_label(get_active_text()); - base->set(value.c_str(), doc, node); - } +void ComboWdg::changed(void) +{ + if ( _base ) { + Glib::ustring value = _base->value_from_label(get_active_text()); + _base->set(value.c_str(), _doc, _node); } -}; + if (_changeSignal != NULL) { + _changeSignal->emit(); + } +} /** * Returns the value for the options label parameter @@ -317,7 +324,7 @@ Gtk::Widget * ParamRadioButton::get_widget(SPDocument * doc, Inkscape::XML::Node Gtk::ComboBoxText* cbt = 0; bool comboSet = false; if (_mode == MINIMAL) { - cbt = Gtk::manage(new ComboWdg(this, doc, node)); + cbt = Gtk::manage(new ComboWdg(this, doc, node, changeSignal)); cbt->show(); vbox->pack_start(*cbt, false, false); } diff --git a/src/factory.h b/src/factory.h deleted file mode 100644 index c1288b460..000000000 --- a/src/factory.h +++ /dev/null @@ -1,123 +0,0 @@ -/** @file - * Generic Factory - *//* - * Authors: - * Markus Engel - * - * Copyright (C) 2013 Authors - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#ifndef FACTORY_H_SEEN -#define FACTORY_H_SEEN - -#include <exception> -#include <map> -#include <string> -#include "xml/node.h" - -/** - * A simple singleton implementation. - */ -template <class T> -struct Singleton { - static T &instance() { - static T inst; - return inst; - } -}; - -namespace FactoryExceptions { -class TypeNotRegistered : public std::exception { -public: - TypeNotRegistered(std::string const &type) - : std::exception() - , _type_string(type) { - } - - virtual ~TypeNotRegistered() throw() { - } - - char const *what() const throw() { - return _type_string.c_str(); - } - -private: - std::string const _type_string; -}; -} // namespace FactoryExceptions - -/** - * A Factory for creating objects which can be identified by strings. - */ -template <class BaseObject> -class Factory { -public: - typedef BaseObject *CreateFunction(); - - bool registerObject(std::string const &id, CreateFunction *creator) { - return this->_object_map.insert(std::make_pair(id, creator)).second; - } - - BaseObject *createObject(std::string const &id) const { - typename std::map<std::string const, CreateFunction *>::const_iterator it = this->_object_map.find(id); - - if (it == this->_object_map.end()) { - //throw FactoryExceptions::TypeNotRegistered(id); - if (!(id.empty() // comments, usually - || id == "rdf:RDF" // no SP node yet - || id == "inkscape:clipboard" // SP node not necessary - || id == "inkscape:_templateinfo")) { - g_warning("unknown type: %s", id.c_str()); - } - return NULL; - } - - return it->second(); - } - -private: - std::map<std::string const, CreateFunction *> _object_map; -}; - - -struct NodeTraits { - static std::string get_type_string(Inkscape::XML::Node const &node) { - std::string name; - - switch (node.type()) { - case Inkscape::XML::TEXT_NODE: - name = "string"; - break; - - case Inkscape::XML::ELEMENT_NODE: { - char const *const sptype = node.attribute("sodipodi:type"); - - if (sptype) { - name = sptype; - } else { - name = node.name(); - } - break; - } - default: - name = ""; - break; - } - - return name; - } -}; - -#endif - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/file.cpp b/src/file.cpp index 72516d776..f9e259fe2 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -288,6 +288,12 @@ bool sp_file_open(const Glib::ustring &uri, } if (doc) { + // Set viewBox if it doesn't exist + if (!doc->getRoot()->viewBox_set) { + DocumentUndo::setUndoSensitive(doc, false); + doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().value(doc->getDisplayUnit()), doc->getHeight().value(doc->getDisplayUnit()))); + DocumentUndo::setUndoSensitive(doc, true); + } SPDocument *existing = desktop ? desktop->getDocument() : NULL; diff --git a/src/filters/blend.cpp b/src/filters/blend.cpp index ca1d5bf96..6e92ef50f 100644 --- a/src/filters/blend.cpp +++ b/src/filters/blend.cpp @@ -13,10 +13,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include <string.h> #include "sp-filter.h" @@ -30,16 +26,6 @@ #include "display/nr-filter-blend.h" #include "display/nr-filter-types.h" -#include "sp-factory.h" - -namespace { - SPObject* createBlend() { - return new SPFeBlend(); - } - - bool blendRegistered = SPFactory::instance().registerObject("svg:feBlend", createBlend); -} - SPFeBlend::SPFeBlend() : SPFilterPrimitive(), blend_mode(Inkscape::Filters::BLEND_NORMAL), in2(Inkscape::Filters::NR_FILTER_SLOT_NOT_SET) diff --git a/src/filters/colormatrix.cpp b/src/filters/colormatrix.cpp index 58f601a65..a7f0296c2 100644 --- a/src/filters/colormatrix.cpp +++ b/src/filters/colormatrix.cpp @@ -14,10 +14,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include <string.h> #include "attributes.h" @@ -29,16 +25,6 @@ #include "display/nr-filter.h" #include "display/nr-filter-colormatrix.h" -#include "sp-factory.h" - -namespace { - SPObject* createColorMatrix() { - return new SPFeColorMatrix(); - } - - bool colorMatrixRegistered = SPFactory::instance().registerObject("svg:feColorMatrix", createColorMatrix); -} - SPFeColorMatrix::SPFeColorMatrix() : SPFilterPrimitive(), type(Inkscape::Filters::COLORMATRIX_MATRIX), value(0) { diff --git a/src/filters/componenttransfer-funcnode.cpp b/src/filters/componenttransfer-funcnode.cpp index d8c5b0d49..76e99a648 100644 --- a/src/filters/componenttransfer-funcnode.cpp +++ b/src/filters/componenttransfer-funcnode.cpp @@ -13,10 +13,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include <glib.h> #include "attributes.h" @@ -31,32 +27,6 @@ #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::Channel channel) : SPObject(), type(Inkscape::Filters::COMPONENTTRANSFER_TYPE_IDENTITY), diff --git a/src/filters/componenttransfer.cpp b/src/filters/componenttransfer.cpp index 610b3dd02..3d0264390 100644 --- a/src/filters/componenttransfer.cpp +++ b/src/filters/componenttransfer.cpp @@ -12,10 +12,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include <string.h> #include "document.h" @@ -27,16 +23,6 @@ #include "display/nr-filter.h" #include "display/nr-filter-component-transfer.h" -#include "sp-factory.h" - -namespace { - SPObject* createComponentTransfer() { - return new SPFeComponentTransfer(); - } - - bool componentTransferRegistered = SPFactory::instance().registerObject("svg:feComponentTransfer", createComponentTransfer); -} - SPFeComponentTransfer::SPFeComponentTransfer() : SPFilterPrimitive(), renderer(NULL) { diff --git a/src/filters/composite.cpp b/src/filters/composite.cpp index e600b6d20..3e651a778 100644 --- a/src/filters/composite.cpp +++ b/src/filters/composite.cpp @@ -12,10 +12,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include "attributes.h" #include "svg/svg.h" #include "filters/composite.h" @@ -25,16 +21,6 @@ #include "display/nr-filter-composite.h" #include "sp-filter.h" -#include "sp-factory.h" - -namespace { - SPObject* createComposite() { - return new SPFeComposite(); - } - - bool compositeRegistered = SPFactory::instance().registerObject("svg:feComposite", createComposite); -} - SPFeComposite::SPFeComposite() : SPFilterPrimitive(), composite_operator(COMPOSITE_DEFAULT), k1(0), k2(0), k3(0), k4(0), in2(Inkscape::Filters::NR_FILTER_SLOT_NOT_SET) diff --git a/src/filters/convolvematrix.cpp b/src/filters/convolvematrix.cpp index bd710b116..3a443bebc 100644 --- a/src/filters/convolvematrix.cpp +++ b/src/filters/convolvematrix.cpp @@ -13,10 +13,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include <string.h> #include <math.h> #include <vector> @@ -28,16 +24,6 @@ #include "display/nr-filter.h" #include "display/nr-filter-convolve-matrix.h" -#include "sp-factory.h" - -namespace { - SPObject* createConvolveMatrix() { - return new SPFeConvolveMatrix(); - } - - bool convolveMatrixRegistered = SPFactory::instance().registerObject("svg:feConvolveMatrix", createConvolveMatrix); -} - SPFeConvolveMatrix::SPFeConvolveMatrix() : SPFilterPrimitive() { this->bias = 0; this->divisorIsSet = 0; diff --git a/src/filters/diffuselighting.cpp b/src/filters/diffuselighting.cpp index 09179a69d..120c058d2 100644 --- a/src/filters/diffuselighting.cpp +++ b/src/filters/diffuselighting.cpp @@ -14,10 +14,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include "strneq.h" #include "attributes.h" @@ -36,16 +32,6 @@ /* FeDiffuseLighting base class */ static void sp_feDiffuseLighting_children_modified(SPFeDiffuseLighting *sp_diffuselighting); -#include "sp-factory.h" - -namespace { - SPObject* createDiffuseLighting() { - return new SPFeDiffuseLighting(); - } - - bool diffuseLightingRegistered = SPFactory::instance().registerObject("svg:feDiffuseLighting", createDiffuseLighting); -} - SPFeDiffuseLighting::SPFeDiffuseLighting() : SPFilterPrimitive() { this->surfaceScale = 1; this->diffuseConstant = 1; diff --git a/src/filters/displacementmap.cpp b/src/filters/displacementmap.cpp index 7dedfc031..1dbea67ff 100644 --- a/src/filters/displacementmap.cpp +++ b/src/filters/displacementmap.cpp @@ -12,10 +12,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include "attributes.h" #include "svg/svg.h" #include "filters/displacementmap.h" @@ -25,16 +21,6 @@ #include "display/nr-filter.h" #include "display/nr-filter-displacement-map.h" -#include "sp-factory.h" - -namespace { - SPObject* createDisplacementMap() { - return new SPFeDisplacementMap(); - } - - bool displacementMapRegistered = SPFactory::instance().registerObject("svg:feDisplacementMap", createDisplacementMap); -} - SPFeDisplacementMap::SPFeDisplacementMap() : SPFilterPrimitive() { this->scale=0; this->xChannelSelector = DISPLACEMENTMAP_CHANNEL_ALPHA; diff --git a/src/filters/distantlight.cpp b/src/filters/distantlight.cpp index bd8bd2797..fb7380174 100644 --- a/src/filters/distantlight.cpp +++ b/src/filters/distantlight.cpp @@ -13,10 +13,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include <glib.h> #include "attributes.h" @@ -30,17 +26,6 @@ #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/filters/flood.cpp b/src/filters/flood.cpp index 134492d34..94ca61b98 100644 --- a/src/filters/flood.cpp +++ b/src/filters/flood.cpp @@ -12,10 +12,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include "strneq.h" #include "attributes.h" @@ -27,16 +23,6 @@ #include "display/nr-filter.h" #include "display/nr-filter-flood.h" -#include "sp-factory.h" - -namespace { - SPObject* createFlood() { - return new SPFeFlood(); - } - - bool floodRegistered = SPFactory::instance().registerObject("svg:feFlood", createFlood); -} - SPFeFlood::SPFeFlood() : SPFilterPrimitive() { this->color = 0; diff --git a/src/filters/gaussian-blur.cpp b/src/filters/gaussian-blur.cpp index fc1e65925..43a1f6dfb 100644 --- a/src/filters/gaussian-blur.cpp +++ b/src/filters/gaussian-blur.cpp @@ -27,19 +27,6 @@ #include "display/nr-filter-gaussian.h" #include "display/nr-filter-types.h" -//#define SP_MACROS_SILENT -//#include "macros.h" - -#include "sp-factory.h" - -namespace { - SPObject* createGaussianBlur() { - return new SPGaussianBlur(); - } - - bool gaussianBlurRegistered = SPFactory::instance().registerObject("svg:feGaussianBlur", createGaussianBlur); -} - SPGaussianBlur::SPGaussianBlur() : SPFilterPrimitive() { } diff --git a/src/filters/image.cpp b/src/filters/image.cpp index 116939e0f..62e8b76b9 100644 --- a/src/filters/image.cpp +++ b/src/filters/image.cpp @@ -14,10 +14,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include <sigc++/bind.h> #include "display/nr-filter-image.h" #include "uri.h" @@ -31,16 +27,6 @@ #include "display/nr-filter.h" -#include "sp-factory.h" - -namespace { - SPObject* createImage() { - return new SPFeImage(); - } - - bool imageRegistered = SPFactory::instance().registerObject("svg:feImage", createImage); -} - SPFeImage::SPFeImage() : SPFilterPrimitive() { this->href = NULL; this->from_element = 0; diff --git a/src/filters/merge.cpp b/src/filters/merge.cpp index 882ab36dd..68f671b11 100644 --- a/src/filters/merge.cpp +++ b/src/filters/merge.cpp @@ -11,10 +11,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include "attributes.h" #include "svg/svg.h" #include "xml/repr.h" @@ -24,16 +20,6 @@ #include "display/nr-filter.h" #include "display/nr-filter-merge.h" -#include "sp-factory.h" - -namespace { - SPObject* createMerge() { - return new SPFeMerge(); - } - - bool mergeRegistered = SPFactory::instance().registerObject("svg:feMerge", createMerge); -} - SPFeMerge::SPFeMerge() : SPFilterPrimitive() { } diff --git a/src/filters/mergenode.cpp b/src/filters/mergenode.cpp index ba237c776..691184eb5 100644 --- a/src/filters/mergenode.cpp +++ b/src/filters/mergenode.cpp @@ -13,26 +13,12 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include "attributes.h" #include "xml/repr.h" #include "filters/mergenode.h" #include "filters/merge.h" #include "display/nr-filter-types.h" -#include "sp-factory.h" - -namespace { - SPObject* createMergeNode() { - return new SPFeMergeNode(); - } - - bool mergeNodeRegistered = SPFactory::instance().registerObject("svg:feMergeNode", createMergeNode); -} - SPFeMergeNode::SPFeMergeNode() : SPObject(), input(Inkscape::Filters::NR_FILTER_SLOT_NOT_SET) { } diff --git a/src/filters/morphology.cpp b/src/filters/morphology.cpp index d3611b081..326c9b7a6 100644 --- a/src/filters/morphology.cpp +++ b/src/filters/morphology.cpp @@ -13,10 +13,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include <string.h> #include "attributes.h" @@ -26,16 +22,6 @@ #include "display/nr-filter.h" #include "display/nr-filter-morphology.h" -#include "sp-factory.h" - -namespace { - SPObject* createMorphology() { - return new SPFeMorphology(); - } - - bool morphologyRegistered = SPFactory::instance().registerObject("svg:feMorphology", createMorphology); -} - SPFeMorphology::SPFeMorphology() : SPFilterPrimitive() { this->Operator = Inkscape::Filters::MORPHOLOGY_OPERATOR_ERODE; diff --git a/src/filters/offset.cpp b/src/filters/offset.cpp index 234a1a964..c35649dcc 100644 --- a/src/filters/offset.cpp +++ b/src/filters/offset.cpp @@ -13,10 +13,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include "attributes.h" #include "svg/svg.h" #include "filters/offset.h" @@ -25,16 +21,6 @@ #include "display/nr-filter.h" #include "display/nr-filter-offset.h" -#include "sp-factory.h" - -namespace { - SPObject* createOffset() { - return new SPFeOffset(); - } - - bool offsetRegistered = SPFactory::instance().registerObject("svg:feOffset", createOffset); -} - SPFeOffset::SPFeOffset() : SPFilterPrimitive() { this->dx = 0; this->dy = 0; diff --git a/src/filters/pointlight.cpp b/src/filters/pointlight.cpp index 1c7532b4e..dd3a78f4c 100644 --- a/src/filters/pointlight.cpp +++ b/src/filters/pointlight.cpp @@ -13,10 +13,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include <glib.h> #include "attributes.h" @@ -29,16 +25,6 @@ #define SP_MACROS_SILENT #include "macros.h" -#include "sp-factory.h" - -namespace { - SPObject* createPointLight() { - return new SPFePointLight(); - } - - bool pointLightRegistered = SPFactory::instance().registerObject("svg:fePointLight", createPointLight); -} - SPFePointLight::SPFePointLight() : SPObject(), x(0), x_set(FALSE), y(0), y_set(FALSE), z(0), z_set(FALSE) { } diff --git a/src/filters/specularlighting.cpp b/src/filters/specularlighting.cpp index 6cdd5d9ba..bda1a0f30 100644 --- a/src/filters/specularlighting.cpp +++ b/src/filters/specularlighting.cpp @@ -14,10 +14,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include "strneq.h" #include "attributes.h" @@ -36,16 +32,6 @@ /* FeSpecularLighting base class */ static void sp_feSpecularLighting_children_modified(SPFeSpecularLighting *sp_specularlighting); -#include "sp-factory.h" - -namespace { - SPObject* createSpecularLighting() { - return new SPFeSpecularLighting(); - } - - bool specularLightingRegistered = SPFactory::instance().registerObject("svg:feSpecularLighting", createSpecularLighting); -} - SPFeSpecularLighting::SPFeSpecularLighting() : SPFilterPrimitive() { this->surfaceScale = 1; this->specularConstant = 1; diff --git a/src/filters/spotlight.cpp b/src/filters/spotlight.cpp index c0344067c..2e55d39d0 100644 --- a/src/filters/spotlight.cpp +++ b/src/filters/spotlight.cpp @@ -13,10 +13,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include <glib.h> #include "attributes.h" @@ -29,16 +25,6 @@ #define SP_MACROS_SILENT #include "macros.h" -#include "sp-factory.h" - -namespace { - SPObject* createSpotLight() { - return new SPFeSpotLight(); - } - - bool spotLightRegistered = SPFactory::instance().registerObject("svg:feSpotLight", createSpotLight); -} - SPFeSpotLight::SPFeSpotLight() : SPObject(), x(0), x_set(FALSE), y(0), y_set(FALSE), z(0), z_set(FALSE), pointsAtX(0), pointsAtX_set(FALSE), pointsAtY(0), pointsAtY_set(FALSE), pointsAtZ(0), pointsAtZ_set(FALSE), diff --git a/src/filters/tile.cpp b/src/filters/tile.cpp index 19e96f47d..623f3ab37 100644 --- a/src/filters/tile.cpp +++ b/src/filters/tile.cpp @@ -11,10 +11,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include "attributes.h" #include "svg/svg.h" #include "filters/tile.h" @@ -22,16 +18,6 @@ #include "display/nr-filter.h" #include "display/nr-filter-tile.h" -#include "sp-factory.h" - -namespace { - SPObject* createTile() { - return new SPFeTile(); - } - - bool tileRegistered = SPFactory::instance().registerObject("svg:feTile", createTile); -} - SPFeTile::SPFeTile() : SPFilterPrimitive() { } diff --git a/src/filters/turbulence.cpp b/src/filters/turbulence.cpp index d33667a8c..7541175ed 100644 --- a/src/filters/turbulence.cpp +++ b/src/filters/turbulence.cpp @@ -14,10 +14,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include "attributes.h" #include "svg/svg.h" #include "turbulence.h" @@ -28,16 +24,6 @@ #include "display/nr-filter.h" #include "display/nr-filter-turbulence.h" -#include "sp-factory.h" - -namespace { - SPObject* createTurbulence() { - return new SPFeTurbulence(); - } - - bool turbulenceRegistered = SPFactory::instance().registerObject("svg:feTurbulence", createTurbulence); -} - SPFeTurbulence::SPFeTurbulence() : SPFilterPrimitive() { this->stitchTiles = 0; this->seed = 0; diff --git a/src/gc-allocator.h b/src/gc-allocator.h deleted file mode 100644 index e69de29bb..000000000 --- a/src/gc-allocator.h +++ /dev/null diff --git a/src/gc-anchored.h b/src/gc-anchored.h index 99b78c784..33305df5c 100644 --- a/src/gc-anchored.h +++ b/src/gc-anchored.h @@ -9,7 +9,7 @@ #ifndef SEEN_INKSCAPE_GC_ANCHORED_H #define SEEN_INKSCAPE_GC_ANCHORED_H -#include "gc-managed.h" +#include "inkgc/gc-managed.h" namespace Inkscape { diff --git a/src/gc-finalized.h b/src/gc-finalized.h index 814a2af18..d39338643 100644 --- a/src/gc-finalized.h +++ b/src/gc-finalized.h @@ -18,7 +18,7 @@ #include <new> #include <cstddef> -#include "gc-core.h" +#include "inkgc/gc-core.h" namespace Inkscape { diff --git a/src/gradient-chemistry.cpp b/src/gradient-chemistry.cpp index cf75f6cf0..aecf1aa35 100644 --- a/src/gradient-chemistry.cpp +++ b/src/gradient-chemistry.cpp @@ -41,7 +41,7 @@ #include "sp-gradient-vector.h" #include "sp-linear-gradient.h" #include "sp-radial-gradient.h" -#include "sp-mesh-gradient.h" +#include "sp-mesh.h" #include "sp-stop.h" #include "gradient-drag.h" #include "gradient-chemistry.h" @@ -151,7 +151,7 @@ static SPGradient *sp_gradient_get_private_normalized(SPDocument *document, SPGr repr = xml_doc->createElement("svg:radialGradient"); } else { // Rows/patches added in sp_gradient_reset_to_userspace for new meshes. - repr = xml_doc->createElement("svg:meshGradient"); + repr = xml_doc->createElement("svg:mesh"); } // privates are garbage-collectable @@ -413,7 +413,7 @@ SPGradient *sp_gradient_reset_to_userspace(SPGradient *gr, SPItem *item) // IN SPMeshNodeArray::create() //sp_repr_set_svg_double(repr, "x", bbox->min()[Geom::X]); //sp_repr_set_svg_double(repr, "y", bbox->min()[Geom::Y]); - SPMeshGradient* mg = SP_MESHGRADIENT( gr ); + SPMesh* mg = SP_MESH( gr ); mg->array.create( mg, item, bbox ); } @@ -758,10 +758,10 @@ guint32 sp_item_gradient_stop_query_style(SPItem *item, GrPointType point_type, break; } return 0; - } else if (SP_IS_MESHGRADIENT(gradient)) { + } else if (SP_IS_MESH(gradient)) { // Mesh gradient - SPMeshGradient *mg = SP_MESHGRADIENT(gradient); + SPMesh *mg = SP_MESH(gradient); switch (point_type) { case POINT_MG_CORNER: { @@ -859,7 +859,7 @@ void sp_item_gradient_stop_set_style(SPItem *item, GrPointType point_type, guint } else { // Mesh gradient - SPMeshGradient *mg = SP_MESHGRADIENT(gradient); + SPMesh *mg = SP_MESH(gradient); bool changed = false; switch (point_type) { @@ -1209,8 +1209,8 @@ void sp_item_gradient_set_coords(SPItem *item, GrPointType point_type, guint poi gradient->requestModified(SP_OBJECT_MODIFIED_FLAG); } } - } else if (SP_IS_MESHGRADIENT(gradient)) { - SPMeshGradient *mg = SP_MESHGRADIENT(gradient); + } else if (SP_IS_MESH(gradient)) { + SPMesh *mg = SP_MESH(gradient); //Geom::Affine new_transform; //bool transform_set = false; @@ -1240,7 +1240,7 @@ void sp_item_gradient_set_coords(SPItem *item, GrPointType point_type, guint poi } if( write_repr ) { //std::cout << "Write mesh repr" << std::endl; - sp_meshgradient_repr_write( mg ); + sp_mesh_repr_write( mg ); } } @@ -1346,8 +1346,8 @@ Geom::Point getGradientCoords(SPItem *item, GrPointType point_type, guint point_ g_warning( "Bad radial gradient handle type" ); break; } - } else if (SP_IS_MESHGRADIENT(gradient)) { - SPMeshGradient *mg = SP_MESHGRADIENT(gradient); + } else if (SP_IS_MESH(gradient)) { + SPMesh *mg = SP_MESH(gradient); switch (point_type) { case POINT_MG_CORNER: diff --git a/src/gradient-drag.cpp b/src/gradient-drag.cpp index 154b7339b..cb2bd737f 100644 --- a/src/gradient-drag.cpp +++ b/src/gradient-drag.cpp @@ -43,7 +43,7 @@ #include "knot.h" #include "sp-linear-gradient.h" #include "sp-radial-gradient.h" -#include "sp-mesh-gradient.h" +#include "sp-mesh.h" #include "sp-mesh-row.h" #include "sp-mesh-patch.h" #include "gradient-chemistry.h" @@ -414,7 +414,7 @@ SPStop *GrDrag::addStopNearPoint(SPItem *item, Geom::Point mouse_p, double toler //r1_knot = false; } } - } else if (SP_IS_MESHGRADIENT(gradient)) { + } else if (SP_IS_MESH(gradient)) { // add_stop_near_point() // Find out which curve pointer is over and use that curve to determine @@ -422,7 +422,7 @@ SPStop *GrDrag::addStopNearPoint(SPItem *item, Geom::Point mouse_p, double toler // This is silly as we already should know which line we are over... // but that information is not saved (sp_gradient_context_is_over_line). - SPMeshGradient *mg = SP_MESHGRADIENT(gradient); + SPMesh *mg = SP_MESH(gradient); Geom::Affine transform = Geom::Affine(mg->gradientTransform)*(Geom::Affine)item->i2dt_affine(); guint rows = mg->array.patch_rows(); @@ -550,7 +550,7 @@ SPStop *GrDrag::addStopNearPoint(SPItem *item, Geom::Point mouse_p, double toler } else { - SPMeshGradient *mg = SP_MESHGRADIENT(gradient); + SPMesh *mg = SP_MESH(gradient); if( divide_row > -1 ) { mg->array.split_row( divide_row, divide_coord ); @@ -559,7 +559,7 @@ SPStop *GrDrag::addStopNearPoint(SPItem *item, Geom::Point mouse_p, double toler } // Update repr - sp_meshgradient_repr_write( mg ); + sp_mesh_repr_write( mg ); mg->array.built = false; mg->ensureArray(); // How do we do this? @@ -1349,7 +1349,7 @@ GrDragger::updateHandles ( Geom::Point pc_old, MeshNodeOperation op ) // Must be a mesh gradient SPGradient *gradient = getGradient(draggable->item, draggable->fill_or_stroke); - if ( !SP_IS_MESHGRADIENT( gradient ) ) continue; + if ( !SP_IS_MESH( gradient ) ) continue; selected_corners[ gradient ].push_back( draggable->point_i ); } @@ -1374,8 +1374,8 @@ GrDragger::updateHandles ( Geom::Point pc_old, MeshNodeOperation op ) // Must be a mesh gradient SPGradient *gradient = getGradient(item, fill_or_stroke); - if ( !SP_IS_MESHGRADIENT( gradient ) ) continue; - SPMeshGradient *mg = SP_MESHGRADIENT( gradient ); + if ( !SP_IS_MESH( gradient ) ) continue; + SPMesh *mg = SP_MESH( gradient ); // pc_old is the old corner position in desktop coordinates, we need it in gradient coordinate. gradient = sp_gradient_convert_to_userspace (gradient, item, (fill_or_stroke == Inkscape::FOR_FILL) ? "fill" : "stroke"); @@ -1958,7 +1958,7 @@ void GrDrag::addDraggersLinear(SPLinearGradient *lg, SPItem *item, Inkscape::Pai /** *Add draggers for the mesh gradient mg on item */ -void GrDrag::addDraggersMesh(SPMeshGradient *mg, SPItem *item, Inkscape::PaintTarget fill_or_stroke) +void GrDrag::addDraggersMesh(SPMesh *mg, SPItem *item, Inkscape::PaintTarget fill_or_stroke) { std::vector< std::vector< SPMeshNode* > > nodes = mg->array.nodes; @@ -1977,7 +1977,7 @@ void GrDrag::addDraggersMesh(SPMeshGradient *mg, SPItem *item, Inkscape::PaintTa // Make sure we have at least one patch defined. if( mg->array.patch_rows() == 0 || mg->array.patch_columns() == 0 ) { - std::cout << "Empty Mesh Gradient, No Draggers to Add" << std::endl; + std::cout << "Empty Mesh, No Draggers to Add" << std::endl; return; } @@ -2032,7 +2032,7 @@ void GrDrag::addDraggersMesh(SPMeshGradient *mg, SPItem *item, Inkscape::PaintTa } default: - std::cout << "Bad Mesh Gradient draggable type" << std::endl; + std::cout << "Bad Mesh draggable type" << std::endl; break; } } @@ -2097,8 +2097,8 @@ void GrDrag::updateDraggers() addDraggersLinear( SP_LINEARGRADIENT(server), item, Inkscape::FOR_FILL ); } else if ( SP_IS_RADIALGRADIENT(server) ) { addDraggersRadial( SP_RADIALGRADIENT(server), item, Inkscape::FOR_FILL ); - } else if ( SP_IS_MESHGRADIENT(server) ) { - addDraggersMesh( SP_MESHGRADIENT(server), item, Inkscape::FOR_FILL ); + } else if ( SP_IS_MESH(server) ) { + addDraggersMesh( SP_MESH(server), item, Inkscape::FOR_FILL ); } } } @@ -2113,8 +2113,8 @@ void GrDrag::updateDraggers() addDraggersLinear( SP_LINEARGRADIENT(server), item, Inkscape::FOR_STROKE ); } else if ( SP_IS_RADIALGRADIENT(server) ) { addDraggersRadial( SP_RADIALGRADIENT(server), item, Inkscape::FOR_STROKE ); - } else if ( SP_IS_MESHGRADIENT(server) ) { - addDraggersMesh( SP_MESHGRADIENT(server), item, Inkscape::FOR_STROKE ); + } else if ( SP_IS_MESH(server) ) { + addDraggersMesh( SP_MESH(server), item, Inkscape::FOR_STROKE ); } } } @@ -2169,9 +2169,9 @@ void GrDrag::updateLines() Geom::Point center = getGradientCoords(item, POINT_RG_CENTER, 0, Inkscape::FOR_FILL); addLine(item, center, getGradientCoords(item, POINT_RG_R1, 0, Inkscape::FOR_FILL), Inkscape::FOR_FILL); addLine(item, center, getGradientCoords(item, POINT_RG_R2, 0, Inkscape::FOR_FILL), Inkscape::FOR_FILL); - } else if ( SP_IS_MESHGRADIENT(server) ) { + } else if ( SP_IS_MESH(server) ) { - SPMeshGradient *mg = SP_MESHGRADIENT(server); + SPMesh *mg = SP_MESH(server); guint rows = mg->array.patch_rows(); guint columns = mg->array.patch_columns(); @@ -2231,10 +2231,10 @@ void GrDrag::updateLines() Geom::Point center = getGradientCoords(item, POINT_RG_CENTER, 0, Inkscape::FOR_STROKE); addLine(item, center, getGradientCoords(item, POINT_RG_R1, 0, Inkscape::FOR_STROKE), Inkscape::FOR_STROKE); addLine(item, center, getGradientCoords(item, POINT_RG_R2, 0, Inkscape::FOR_STROKE), Inkscape::FOR_STROKE); - } else if ( SP_IS_MESHGRADIENT(server) ) { + } else if ( SP_IS_MESH(server) ) { // MESH FIXME: TURN ROUTINE INTO FUNCTION AND CALL FOR BOTH FILL AND STROKE. - SPMeshGradient *mg = SP_MESHGRADIENT(server); + SPMesh *mg = SP_MESH(server); guint rows = mg->array.patch_rows(); guint columns = mg->array.patch_columns(); diff --git a/src/gradient-drag.h b/src/gradient-drag.h index 964ea8093..da264b4bb 100644 --- a/src/gradient-drag.h +++ b/src/gradient-drag.h @@ -33,7 +33,7 @@ class SPKnot; class SPDesktop; class SPCSSAttr; class SPLinearGradient; -class SPMeshGradient; +class SPMesh; class SPItem; class SPObject; class SPRadialGradient; @@ -206,7 +206,7 @@ private: void addDraggersRadial(SPRadialGradient *rg, SPItem *item, Inkscape::PaintTarget fill_or_stroke); void addDraggersLinear(SPLinearGradient *lg, SPItem *item, Inkscape::PaintTarget fill_or_stroke); - void addDraggersMesh( SPMeshGradient *mg, SPItem *item, Inkscape::PaintTarget fill_or_stroke); + void addDraggersMesh( SPMesh *mg, SPItem *item, Inkscape::PaintTarget fill_or_stroke); bool styleSet( const SPCSSAttr *css ); diff --git a/src/helper/CMakeLists.txt b/src/helper/CMakeLists.txt index b0e473ddd..74ce2c85d 100644 --- a/src/helper/CMakeLists.txt +++ b/src/helper/CMakeLists.txt @@ -32,6 +32,7 @@ set(helper_SRC geom-nodetype.h geom.h gnome-utils.h + mathfns.h pixbuf-ops.h png-write.h stock-items.h diff --git a/src/helper/Makefile_insert b/src/helper/Makefile_insert index 4c6437f13..5cb4cea8d 100644 --- a/src/helper/Makefile_insert +++ b/src/helper/Makefile_insert @@ -14,6 +14,7 @@ ink_common_sources += \ helper/geom-nodetype.h \ helper/gnome-utils.cpp \ helper/gnome-utils.h \ + helper/mathfns.h \ helper/png-write.cpp \ helper/png-write.h \ helper/sp-marshal.cpp \ diff --git a/src/helper/geom.cpp b/src/helper/geom.cpp index 6eba6e949..91689375f 100644 --- a/src/helper/geom.cpp +++ b/src/helper/geom.cpp @@ -556,6 +556,55 @@ pathv_to_linear( Geom::PathVector const &pathv, double /*maxdisp*/) return output; } +/* + * Converts all segments in all paths to Geom Cubic bezier. + * This is used in lattice2 LPE, maybe is better move the function to the effect + * But maybe could be usable by others, so i put here. + * The straight curve part is needed as it for the effect to work apropiately + */ +Geom::PathVector +pathv_to_cubicbezier( Geom::PathVector const &pathv) +{ + Geom::PathVector output; + double cubicGap = 0.01; + for (Geom::PathVector::const_iterator pit = pathv.begin(); pit != pathv.end(); ++pit) { + output.push_back( Geom::Path() ); + output.back().start( pit->initialPoint() ); + output.back().close( pit->closed() ); + bool end_open = false; + if (pit->closed()) { + const Geom::Curve &closingline = pit->back_closed(); + if (!are_near(closingline.initialPoint(), closingline.finalPoint())) { + end_open = true; + } + } + Geom::Path pitCubic = (Geom::Path)(*pit); + if(end_open && pit->closed()){ + pitCubic.close(false); + pitCubic.appendNew<Geom::LineSegment>( pitCubic.initialPoint() ); + pitCubic.close(true); + } + for (Geom::Path::const_iterator cit = pitCubic.begin(); cit != pitCubic.end_open(); ++cit) { + if (is_straight_curve(*cit)) { + Geom::CubicBezier b(cit->initialPoint(), cit->pointAt(0.3334) + Geom::Point(cubicGap,cubicGap), cit->finalPoint(), cit->finalPoint()); + output.back().append(b); + } else { + Geom::BezierCurve const *curve = dynamic_cast<Geom::BezierCurve const *>(&*cit); + if (curve && curve->order() == 3) { + Geom::CubicBezier b((*curve)[0], (*curve)[1], (*curve)[2], (*curve)[3]); + output.back().append(b); + } else { + // convert all other curve types to cubicbeziers + Geom::Path cubicbezier_path = Geom::cubicbezierpath_from_sbasis(cit->toSBasis(), 0.1); + output.back().append(cubicbezier_path); + } + } + } + } + + return output; +} + // The next routine is modified from curv4_div::recursive_bezier from file agg_curves.cpp //---------------------------------------------------------------------------- // Anti-Grain Geometry (AGG) - Version 2.5 diff --git a/src/helper/geom.h b/src/helper/geom.h index caff95733..3232d9fd5 100644 --- a/src/helper/geom.h +++ b/src/helper/geom.h @@ -27,6 +27,7 @@ void pathv_matrix_point_bbox_wind_distance ( Geom::PathVector const & pathv, Geo Geom::PathVector pathv_to_linear_and_cubic_beziers( Geom::PathVector const &pathv ); Geom::PathVector pathv_to_linear( Geom::PathVector const &pathv, double maxdisp ); +Geom::PathVector pathv_to_cubicbezier( Geom::PathVector const &pathv); void recursive_bezier4(const double x1, const double y1, const double x2, const double y2, const double x3, const double y3, const double x4, const double y4, std::vector<Geom::Point> &pointlist, diff --git a/src/util/mathfns.h b/src/helper/mathfns.h index 830e159da..8fb88dc26 100644 --- a/src/util/mathfns.h +++ b/src/helper/mathfns.h @@ -1,5 +1,5 @@ /* - * Inkscape::Util::... some mathmatical functions + * ... some mathmatical functions * * Authors: * Johan Engelen <goejendaagh@zonnet.nl> @@ -65,7 +65,6 @@ inline double round_to_upper_multiple_plus(double x, double const c1, double con return ceil((x - c0) / c1) * c1 + c0; } - } } diff --git a/src/inkgc/CMakeLists.txt b/src/inkgc/CMakeLists.txt new file mode 100644 index 000000000..22dd464e1 --- /dev/null +++ b/src/inkgc/CMakeLists.txt @@ -0,0 +1,15 @@ + +set(libgc_SRC + gc.cpp + + # ------- + # Headers + gc-alloc.h + gc-anchored.h + gc-core.h + gc-managed.h + gc-soft-ptr.h +) + +add_inkscape_lib(gc_LIB "${libgc_SRC}") +# add_inkscape_source("${libgc_SRC}") diff --git a/src/inkgc/Makefile_insert b/src/inkgc/Makefile_insert new file mode 100644 index 000000000..58aa39bb9 --- /dev/null +++ b/src/inkgc/Makefile_insert @@ -0,0 +1,13 @@ +## Makefile.am fragment sourced by src/Makefile.am. + +inkgc/all: inkgc/libinkgc.a + +inkgc/clean: + rm -f inkgc/libinkgc.a $(inkgc_libinkgc_a_OBJECTS) + +inkgc_libinkgc_a_SOURCES = \ + inkgc/gc.cpp \ + inkgc/gc-alloc.h \ + inkgc/gc-core.h \ + inkgc/gc-managed.h \ + inkgc/gc-soft-ptr.h diff --git a/src/gc-alloc.h b/src/inkgc/gc-alloc.h index ba672ae2c..917ee972d 100644 --- a/src/gc-alloc.h +++ b/src/inkgc/gc-alloc.h @@ -17,7 +17,7 @@ #include <limits> #include <cstddef> -#include "gc-core.h" +#include "inkgc/gc-core.h" namespace Inkscape { diff --git a/src/gc-core.h b/src/inkgc/gc-core.h index d9d0bf4ff..d9d0bf4ff 100644 --- a/src/gc-core.h +++ b/src/inkgc/gc-core.h diff --git a/src/gc-managed.h b/src/inkgc/gc-managed.h index 74d224c9b..f435d7802 100644 --- a/src/gc-managed.h +++ b/src/inkgc/gc-managed.h @@ -14,7 +14,7 @@ #ifndef SEEN_INKSCAPE_GC_MANAGED_H #define SEEN_INKSCAPE_GC_MANAGED_H -#include "gc-core.h" +#include "inkgc/gc-core.h" namespace Inkscape { diff --git a/src/gc-soft-ptr.h b/src/inkgc/gc-soft-ptr.h index 9e7304939..45a3ddcf7 100644 --- a/src/gc-soft-ptr.h +++ b/src/inkgc/gc-soft-ptr.h @@ -13,7 +13,7 @@ #ifndef SEEN_INKSCAPE_GC_SOFT_PTR_H #define SEEN_INKSCAPE_GC_SOFT_PTR_H -#include "gc-core.h" +#include "inkgc/gc-core.h" namespace Inkscape { diff --git a/src/gc.cpp b/src/inkgc/gc.cpp index 280a8b1dc..90c02d9c8 100644 --- a/src/gc.cpp +++ b/src/inkgc/gc.cpp @@ -9,7 +9,7 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "gc-core.h" +#include "inkgc/gc-core.h" #include <stdexcept> #include <cstring> #include <string> diff --git a/src/inkview.cpp b/src/inkview.cpp index 0b7b4d35c..2c667237e 100644 --- a/src/inkview.cpp +++ b/src/inkview.cpp @@ -47,7 +47,7 @@ #include <gdk/gdkkeysyms.h> #include <gtk/gtk.h> -#include "gc-core.h" +#include "inkgc/gc-core.h" #include "preferences.h" #include <glibmm/i18n.h> diff --git a/src/knotholder.cpp b/src/knotholder.cpp index f46daa09e..a2d1cf017 100644 --- a/src/knotholder.cpp +++ b/src/knotholder.cpp @@ -165,7 +165,8 @@ KnotHolder::knot_clicked_handler(SPKnot *knot, guint state) if (saved_item) { //increasingly aggressive sanity checks if (saved_item->document) { - if (object_verb <= SP_VERB_LAST && object_verb >= SP_VERB_INVALID) { + // enum is unsigned so can't be less than SP_VERB_INVALID + if (object_verb <= SP_VERB_LAST) { DocumentUndo::done(saved_item->document, object_verb, _("Change handle")); } diff --git a/src/layer-manager.cpp b/src/layer-manager.cpp index b1e365fe2..3bbc831d5 100644 --- a/src/layer-manager.cpp +++ b/src/layer-manager.cpp @@ -11,7 +11,7 @@ #include <set> #include <sigc++/functors/mem_fun.h> #include <sigc++/adaptors/hide.h> -#include "gc-managed.h" +#include "inkgc/gc-managed.h" #include "gc-finalized.h" #include "document.h" #include "desktop.h" diff --git a/src/layer-manager.h b/src/layer-manager.h index 9eea68004..a304929c6 100644 --- a/src/layer-manager.h +++ b/src/layer-manager.h @@ -15,7 +15,7 @@ #include "document-subset.h" #include "gc-finalized.h" -#include "gc-soft-ptr.h" +#include "inkgc/gc-soft-ptr.h" class SPDesktop; class SPDocument; diff --git a/src/libcroco/cr-statement.c b/src/libcroco/cr-statement.c index fb8df867f..4666f26ec 100644 --- a/src/libcroco/cr-statement.c +++ b/src/libcroco/cr-statement.c @@ -2011,7 +2011,7 @@ cr_statement_ruleset_set_sel_list (CRStatement * a_this, * cr_statement_ruleset_get_declarations: * *@a_this: the current instance of #CRStatement. - *@a_decl_list: out parameter. A pointer to the the returned + *@a_decl_list: out parameter. A pointer to the returned *list of declaration. Must not be NULL. * *Gets a pointer to the list of declaration contained diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 48fc788fa..572d4c35c 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -368,6 +368,10 @@ Effect::Effect(LivePathEffectObject *lpeobject) show_orig_path(false), lpeobj(lpeobject), concatenate_before_pwd2(false), + sp_lpe_item(NULL), + defaultUnit("px"), + current_zoom(1), + sp_curve(NULL), provides_own_flash_paths(true), // is automatically set to false if providesOwnFlashPaths() is not overridden is_ready(false) // is automatically set to false if providesOwnFlashPaths() is not overridden { @@ -455,7 +459,7 @@ void Effect::doOnRemove (SPLPEItem const* /*lpeitem*/) void Effect::doOnApply_impl(SPLPEItem const* lpeitem) { sp_lpe_item = const_cast<SPLPEItem *>(lpeitem); - defaultUnit = &sp_lpe_item->document->getDisplayUnit()->abbr; + defaultUnit = sp_lpe_item->document->getDisplayUnit()->abbr; /*sp_curve = SP_SHAPE(sp_lpe_item)->getCurve(); pathvector_before_effect = sp_curve->get_pathvector();*/ doOnApply(lpeitem); @@ -464,11 +468,13 @@ void Effect::doOnApply_impl(SPLPEItem const* lpeitem) void Effect::doBeforeEffect_impl(SPLPEItem const* lpeitem) { sp_lpe_item = const_cast<SPLPEItem *>(lpeitem); - defaultUnit = &sp_lpe_item->document->getDisplayUnit()->abbr; + defaultUnit = sp_lpe_item->document->getDisplayUnit()->abbr; //printf("(SPLPEITEM*) %p\n", sp_lpe_item); - sp_curve = SP_SHAPE(sp_lpe_item)->getCurve(); - pathvector_before_effect = sp_curve->get_pathvector(); - + SPShape * shape = dynamic_cast<SPShape *>(sp_lpe_item); + if(shape){ + sp_curve = shape->getCurve(); + pathvector_before_effect = sp_curve->get_pathvector(); + } doBeforeEffect(lpeitem); } diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 7da76b267..ac1f0b8dc 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -159,7 +159,7 @@ protected: bool concatenate_before_pwd2; SPLPEItem * sp_lpe_item; // these get stored in doBeforeEffect_impl, and derived classes may do as they please with them. - Glib::ustring const * defaultUnit; // these get stored in doBeforeEffect_impl, and derived classes may do as they please with them. + Glib::ustring defaultUnit; // these get stored in doBeforeEffect_impl, and derived classes may do as they please with them. double current_zoom; std::vector<Geom::Point> selectedNodesPoints; SPCurve * sp_curve; diff --git a/src/live_effects/lpe-bspline.cpp b/src/live_effects/lpe-bspline.cpp index 2bed90139..b924d8a23 100644 --- a/src/live_effects/lpe-bspline.cpp +++ b/src/live_effects/lpe-bspline.cpp @@ -54,20 +54,17 @@ const double defaultEndPower = 0.6667; LPEBSpline::LPEBSpline(LivePathEffectObject *lpeobject) : Effect(lpeobject), - // initialise your parameters here: - //testpointA(_("Test Point A"), _("Test A"), "ptA", &wr, this, - //Geom::Point(100,100)), steps(_("Steps with CTRL:"), _("Change number of steps with CTRL pressed"), "steps", &wr, this, 2), + helper_size(_("Helper size:"), _("Helper size"), "helper_size", &wr, this, 0), ignoreCusp(_("Ignore cusp nodes"), _("Change ignoring cusp nodes"), "ignoreCusp", &wr, this, true), onlySelected(_("Change only selected nodes"), _("Change only selected nodes"), "onlySelected", &wr, this, false), - showHelper(_("Show helper paths"), _("Show helper paths"), "showHelper", &wr, this, false), weight(_("Change weight:"), _("Change weight of the effect"), "weight", &wr, this, defaultStartPower) { - registerParameter(dynamic_cast<Parameter *>(&weight)); - registerParameter(dynamic_cast<Parameter *>(&steps)); - registerParameter(dynamic_cast<Parameter *>(&ignoreCusp)); - registerParameter(dynamic_cast<Parameter *>(&onlySelected)); - registerParameter(dynamic_cast<Parameter *>(&showHelper)); + registerParameter(&weight); + registerParameter(&steps); + registerParameter(&helper_size); + registerParameter(&ignoreCusp); + registerParameter(&onlySelected); weight.param_set_range(noPower, 1); weight.param_set_increments(0.1, 0.1); @@ -76,6 +73,10 @@ LPEBSpline::LPEBSpline(LivePathEffectObject *lpeobject) steps.param_set_range(1, 10); steps.param_set_increments(1, 1); steps.param_set_digits(0); + + helper_size.param_set_range(0.0, 999.0); + helper_size.param_set_increments(5, 5); + helper_size.param_set_digits(2); } LPEBSpline::~LPEBSpline() {} @@ -106,9 +107,7 @@ void LPEBSpline::doEffect(SPCurve *curve) // Make copy of old path as it is changed during processing Geom::PathVector const original_pathv = curve->get_pathvector(); curve->reset(); - double radiusHelperNodes = 6.0; - radiusHelperNodes /= current_zoom; - radiusHelperNodes = Inkscape::Util::Quantity::convert(radiusHelperNodes, "px", *defaultUnit); + for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { if (path_it->empty()) @@ -236,8 +235,8 @@ void LPEBSpline::doEffect(SPCurve *curve) } nCurve->curveto(pointAt1, pointAt2, node); } - if(!are_near(node,curve_it1->finalPoint()) && showHelper){ - drawHandle(node, radiusHelperNodes); + if(!are_near(node,curve_it1->finalPoint()) && helper_size > 0.0){ + drawHandle(node, helper_size); } ++curve_it1; ++curve_it2; @@ -250,21 +249,21 @@ void LPEBSpline::doEffect(SPCurve *curve) nCurve->reset(); delete nCurve; } - if(showHelper){ + if(helper_size > 0.0){ Geom::PathVector const pathv = curve->get_pathvector(); hp.push_back(pathv[0]); } } void -LPEBSpline::drawHandle(Geom::Point p, double radiusHelperNodes) +LPEBSpline::drawHandle(Geom::Point p, double helper_size) { char const * svgd = "M 1,0.5 A 0.5,0.5 0 0 1 0.5,1 0.5,0.5 0 0 1 0,0.5 0.5,0.5 0 0 1 0.5,0 0.5,0.5 0 0 1 1,0.5 Z"; Geom::PathVector pathv = sp_svg_read_pathv(svgd); Geom::Affine aff = Geom::Affine(); - aff *= Geom::Scale(radiusHelperNodes); + aff *= Geom::Scale(helper_size); pathv *= aff; - pathv += p - Geom::Point(0.5*radiusHelperNodes, 0.5*radiusHelperNodes); + pathv += p - Geom::Point(0.5*helper_size, 0.5*helper_size); hp.push_back(pathv[0]); } @@ -356,11 +355,13 @@ void LPEBSpline::toWeight() void LPEBSpline::changeWeight(double weightValue) { - SPPath *path = SP_PATH(sp_lpe_item); - SPCurve *curve = path->get_curve_for_edit(); - LPEBSpline::doBSplineFromWidget(curve, weightValue); - gchar *str = sp_svg_write_path(curve->get_pathvector()); - path->getRepr()->setAttribute("inkscape:original-d", str); + SPPath *path = dynamic_cast<SPPath *>(sp_lpe_item); + if(path){ + SPCurve *curve = path->get_curve_for_edit(); + LPEBSpline::doBSplineFromWidget(curve, weightValue); + gchar *str = sp_svg_write_path(curve->get_pathvector()); + path->getRepr()->setAttribute("inkscape:original-d", str); + } } void LPEBSpline::doBSplineFromWidget(SPCurve *curve, double weightValue) diff --git a/src/live_effects/lpe-bspline.h b/src/live_effects/lpe-bspline.h index a17c0c4ac..642562b24 100644 --- a/src/live_effects/lpe-bspline.h +++ b/src/live_effects/lpe-bspline.h @@ -38,9 +38,9 @@ public: ScalarParam steps; private: + ScalarParam helper_size; BoolParam ignoreCusp; BoolParam onlySelected; - BoolParam showHelper; ScalarParam weight; Geom::PathVector hp; diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 0fa2ebedc..fd9b853d5 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -69,7 +69,7 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : registerParameter(&rotation_angle); registerParameter(&num_copies); registerParameter(&origin); - + num_copies.param_make_integer(true); num_copies.param_set_range(0, 1000); } @@ -88,6 +88,7 @@ LPECopyRotate::doOnApply(SPLPEItem const* lpeitem) A = Point(boundingbox_X.min(), boundingbox_Y.middle()); B = Point(boundingbox_X.middle(), boundingbox_Y.middle()); origin.param_setValue(A); + origin.param_update_default(A); dist_angle_handle = L2(B - A); dir = unit_vector(B - A); } diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index d2bdf2d8d..c8458b8cb 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -223,7 +223,7 @@ void LPEFilletChamfer::updateFillet() { double power = 0; if (!flexible) { - power = Inkscape::Util::Quantity::convert(radius, unit.get_abbreviation(), *defaultUnit) * -1; + power = Inkscape::Util::Quantity::convert(radius, unit.get_abbreviation(), defaultUnit) * -1; } else { power = radius; } diff --git a/src/live_effects/lpe-knot.cpp b/src/live_effects/lpe-knot.cpp index 3876aa24b..820221abf 100644 --- a/src/live_effects/lpe-knot.cpp +++ b/src/live_effects/lpe-knot.cpp @@ -404,7 +404,7 @@ LPEKnot::doEffect_path (std::vector<Geom::Path> const &path_in) for (unsigned comp=0; comp<path_in.size(); comp++){ //find the relevant path component in gpaths (required to allow groups!) - //Q: do we always recieve the group members in the same order? can we rest on that? + //Q: do we always receive the group members in the same order? can we rest on that? unsigned i0 = 0; for (i0=0; i0<gpaths.size(); i0++){ if (path_in[comp]==gpaths[i0]) break; diff --git a/src/live_effects/lpe-lattice.cpp b/src/live_effects/lpe-lattice.cpp index a241a8a2e..c05bae7e1 100644 --- a/src/live_effects/lpe-lattice.cpp +++ b/src/live_effects/lpe-lattice.cpp @@ -236,6 +236,21 @@ LPELattice::resetDefaults(SPItem const* item) grid_point15[Geom::X] = 2.0/3*boundingbox_X.max()+1.0/3*boundingbox_X.min(); grid_point15[Geom::Y] = 2.0/3*boundingbox_Y.max()+1.0/3*boundingbox_Y.min(); + grid_point1.param_update_default(grid_point1); + grid_point2.param_update_default(grid_point2); + grid_point3.param_update_default(grid_point3); + grid_point4.param_update_default(grid_point4); + grid_point5.param_update_default(grid_point5); + grid_point6.param_update_default(grid_point6); + grid_point7.param_update_default(grid_point7); + grid_point8.param_update_default(grid_point8); + grid_point9.param_update_default(grid_point9); + grid_point10.param_update_default(grid_point10); + grid_point11.param_update_default(grid_point11); + grid_point12.param_update_default(grid_point12); + grid_point13.param_update_default(grid_point13); + grid_point14.param_update_default(grid_point14); + grid_point15.param_update_default(grid_point15); } /** diff --git a/src/live_effects/lpe-lattice2.cpp b/src/live_effects/lpe-lattice2.cpp index e1cd91340..08bbbd504 100644 --- a/src/live_effects/lpe-lattice2.cpp +++ b/src/live_effects/lpe-lattice2.cpp @@ -23,18 +23,17 @@ #include "sp-path.h" #include "display/curve.h" #include "svg/svg.h" - +#include "helper/geom.h" +#include <2geom/path.h> #include <2geom/sbasis.h> #include <2geom/sbasis-2d.h> +#include "helper/geom-curves.h" #include <2geom/sbasis-geometric.h> #include <2geom/bezier-to-sbasis.h> #include <2geom/sbasis-to-bezier.h> #include <2geom/d2.h> #include <2geom/piecewise.h> #include <2geom/transforms.h> -#include "ui/tools-switch.h" - -#include "desktop.h" // TODO: should be factored out (see below) using namespace Geom; @@ -43,61 +42,63 @@ namespace LivePathEffect { LPELattice2::LPELattice2(LivePathEffectObject *lpeobject) : Effect(lpeobject), - // initialise your parameters here: - grid_point0(_("Control handle 0:"), _("Control handle 0 - Ctrl+Alt+Click to reset"), "gridpoint0", &wr, this), - grid_point1(_("Control handle 1:"), _("Control handle 1 - Ctrl+Alt+Click to reset"), "gridpoint1", &wr, this), - grid_point2(_("Control handle 2:"), _("Control handle 2 - Ctrl+Alt+Click to reset"), "gridpoint2", &wr, this), - grid_point3(_("Control handle 3:"), _("Control handle 3 - Ctrl+Alt+Click to reset"), "gridpoint3", &wr, this), - grid_point4(_("Control handle 4:"), _("Control handle 4 - Ctrl+Alt+Click to reset"), "gridpoint4", &wr, this), - grid_point5(_("Control handle 5:"), _("Control handle 5 - Ctrl+Alt+Click to reset"), "gridpoint5", &wr, this), - grid_point6(_("Control handle 6:"), _("Control handle 6 - Ctrl+Alt+Click to reset"), "gridpoint6", &wr, this), - grid_point7(_("Control handle 7:"), _("Control handle 7 - Ctrl+Alt+Click to reset"), "gridpoint7", &wr, this), - grid_point8x9(_("Control handle 8x9:"), _("Control handle 8x9 - Ctrl+Alt+Click to reset"), "gridpoint8x9", &wr, this), - grid_point10x11(_("Control handle 10x11:"), _("Control handle 10x11 - Ctrl+Alt+Click to reset"), "gridpoint10x11", &wr, this), - grid_point12(_("Control handle 12:"), _("Control handle 12 - Ctrl+Alt+Click to reset"), "gridpoint12", &wr, this), - grid_point13(_("Control handle 13:"), _("Control handle 13 - Ctrl+Alt+Click to reset"), "gridpoint13", &wr, this), - grid_point14(_("Control handle 14:"), _("Control handle 14 - Ctrl+Alt+Click to reset"), "gridpoint14", &wr, this), - grid_point15(_("Control handle 15:"), _("Control handle 15 - Ctrl+Alt+Click to reset"), "gridpoint15", &wr, this), - grid_point16(_("Control handle 16:"), _("Control handle 16 - Ctrl+Alt+Click to reset"), "gridpoint16", &wr, this), - grid_point17(_("Control handle 17:"), _("Control handle 17 - Ctrl+Alt+Click to reset"), "gridpoint17", &wr, this), - grid_point18(_("Control handle 18:"), _("Control handle 18 - Ctrl+Alt+Click to reset"), "gridpoint18", &wr, this), - grid_point19(_("Control handle 19:"), _("Control handle 19 - Ctrl+Alt+Click to reset"), "gridpoint19", &wr, this), - grid_point20x21(_("Control handle 20x21:"), _("Control handle 20x21 - Ctrl+Alt+Click to reset"), "gridpoint20x21", &wr, this), - grid_point22x23(_("Control handle 22x23:"), _("Control handle 22x23 - Ctrl+Alt+Click to reset"), "gridpoint22x23", &wr, this), - grid_point24x26(_("Control handle 24x26:"), _("Control handle 24x26 - Ctrl+Alt+Click to reset"), "gridpoint24x26", &wr, this), - grid_point25x27(_("Control handle 25x27:"), _("Control handle 25x27 - Ctrl+Alt+Click to reset"), "gridpoint25x27", &wr, this), - grid_point28x30(_("Control handle 28x30:"), _("Control handle 28x30 - Ctrl+Alt+Click to reset"), "gridpoint28x30", &wr, this), - grid_point29x31(_("Control handle 29x31:"), _("Control handle 29x31 - Ctrl+Alt+Click to reset"), "gridpoint29x31", &wr, this), - grid_point32x33x34x35(_("Control handle 32x33x34x35:"), _("Control handle 32x33x34x35 - Ctrl+Alt+Click to reset"), "gridpoint32x33x34x35", &wr, this) - - + horizontalMirror(_("Mirror movements in horizontal"), _("Mirror movements in horizontal"), "horizontalMirror", &wr, this, false), + verticalMirror(_("Mirror movements in vertical"), _("Mirror movements in vertical"), "verticalMirror", &wr, this, false), + grid_point0(_("Control 0:"), _("Control 0 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint0", &wr, this), + grid_point1(_("Control 1:"), _("Control 1 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint1", &wr, this), + grid_point2(_("Control 2:"), _("Control 2 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint2", &wr, this), + grid_point3(_("Control 3:"), _("Control 3 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint3", &wr, this), + grid_point4(_("Control 4:"), _("Control 4 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint4", &wr, this), + grid_point5(_("Control 5:"), _("Control 5 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint5", &wr, this), + grid_point6(_("Control 6:"), _("Control 6 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint6", &wr, this), + grid_point7(_("Control 7:"), _("Control 7 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint7", &wr, this), + grid_point8x9(_("Control 8x9:"), _("Control 8x9 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint8x9", &wr, this), + grid_point10x11(_("Control 10x11:"), _("Control 10x11 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint10x11", &wr, this), + grid_point12(_("Control 12:"), _("Control 12 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint12", &wr, this), + grid_point13(_("Control 13:"), _("Control 13 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint13", &wr, this), + grid_point14(_("Control 14:"), _("Control 14 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint14", &wr, this), + grid_point15(_("Control 15:"), _("Control 15 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint15", &wr, this), + grid_point16(_("Control 16:"), _("Control 16 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint16", &wr, this), + grid_point17(_("Control 17:"), _("Control 17 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint17", &wr, this), + grid_point18(_("Control 18:"), _("Control 18 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint18", &wr, this), + grid_point19(_("Control 19:"), _("Control 19 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint19", &wr, this), + grid_point20x21(_("Control 20x21:"), _("Control 20x21 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint20x21", &wr, this), + grid_point22x23(_("Control 22x23:"), _("Control 22x23 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint22x23", &wr, this), + grid_point24x26(_("Control 24x26:"), _("Control 24x26 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint24x26", &wr, this), + grid_point25x27(_("Control 25x27:"), _("Control 25x27 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint25x27", &wr, this), + grid_point28x30(_("Control 28x30:"), _("Control 28x30 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint28x30", &wr, this), + grid_point29x31(_("Control 29x31:"), _("Control 29x31 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint29x31", &wr, this), + grid_point32x33x34x35(_("Control 32x33x34x35:"), _("Control 32x33x34x35 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint32x33x34x35", &wr, this), + expanded(false) { // register all your parameters here, so Inkscape knows which parameters this effect has: - registerParameter( dynamic_cast<Parameter *>(&grid_point0) ); - registerParameter( dynamic_cast<Parameter *>(&grid_point1) ); - registerParameter( dynamic_cast<Parameter *>(&grid_point2) ); - registerParameter( dynamic_cast<Parameter *>(&grid_point3) ); - registerParameter( dynamic_cast<Parameter *>(&grid_point4) ); - registerParameter( dynamic_cast<Parameter *>(&grid_point5) ); - registerParameter( dynamic_cast<Parameter *>(&grid_point6) ); - registerParameter( dynamic_cast<Parameter *>(&grid_point7) ); - registerParameter( dynamic_cast<Parameter *>(&grid_point8x9) ); - registerParameter( dynamic_cast<Parameter *>(&grid_point10x11) ); - registerParameter( dynamic_cast<Parameter *>(&grid_point12) ); - registerParameter( dynamic_cast<Parameter *>(&grid_point13) ); - registerParameter( dynamic_cast<Parameter *>(&grid_point14) ); - registerParameter( dynamic_cast<Parameter *>(&grid_point15) ); - registerParameter( dynamic_cast<Parameter *>(&grid_point16) ); - registerParameter( dynamic_cast<Parameter *>(&grid_point17) ); - registerParameter( dynamic_cast<Parameter *>(&grid_point18) ); - registerParameter( dynamic_cast<Parameter *>(&grid_point19) ); - registerParameter( dynamic_cast<Parameter *>(&grid_point20x21) ); - registerParameter( dynamic_cast<Parameter *>(&grid_point22x23) ); - registerParameter( dynamic_cast<Parameter *>(&grid_point24x26) ); - registerParameter( dynamic_cast<Parameter *>(&grid_point25x27) ); - registerParameter( dynamic_cast<Parameter *>(&grid_point28x30) ); - registerParameter( dynamic_cast<Parameter *>(&grid_point29x31) ); - registerParameter( dynamic_cast<Parameter *>(&grid_point32x33x34x35) ); + registerParameter(&horizontalMirror); + registerParameter(&verticalMirror); + registerParameter(&grid_point0); + registerParameter(&grid_point1); + registerParameter(&grid_point2); + registerParameter(&grid_point3); + registerParameter(&grid_point4); + registerParameter(&grid_point5); + registerParameter(&grid_point6); + registerParameter(&grid_point7); + registerParameter(&grid_point8x9); + registerParameter(&grid_point10x11); + registerParameter(&grid_point12); + registerParameter(&grid_point13); + registerParameter(&grid_point14); + registerParameter(&grid_point15); + registerParameter(&grid_point16); + registerParameter(&grid_point17); + registerParameter(&grid_point18); + registerParameter(&grid_point19); + registerParameter(&grid_point20x21); + registerParameter(&grid_point22x23); + registerParameter(&grid_point24x26); + registerParameter(&grid_point25x27); + registerParameter(&grid_point28x30); + registerParameter(&grid_point29x31); + registerParameter(&grid_point32x33x34x35); } LPELattice2::~LPELattice2() @@ -107,6 +108,10 @@ LPELattice2::~LPELattice2() Geom::Piecewise<Geom::D2<Geom::SBasis> > LPELattice2::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in) { + PathVector pathv = path_from_piecewise(pwd2_in,0.001); + //this is because strange problems whith sb2 and LineSegment + PathVector cubic = pathv_to_cubicbezier(pathv); + Geom::Piecewise<Geom::D2<Geom::SBasis> > const &pwd2_in_linear_and_cubic = paths_to_pw(cubic); D2<SBasis2d> sb2; //Initialisation of the sb2 @@ -118,44 +123,45 @@ LPELattice2::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd } //Grouping the point params in a convenient vector - std::vector<Geom::Point *> handles(36); + + std::vector<Geom::Point > handles(36); - handles[0] = &grid_point0; - handles[1] = &grid_point1; - handles[2] = &grid_point2; - handles[3] = &grid_point3; - handles[4] = &grid_point4; - handles[5] = &grid_point5; - handles[6] = &grid_point6; - handles[7] = &grid_point7; - handles[8] = &grid_point8x9; - handles[9] = &grid_point8x9; - handles[10] = &grid_point10x11; - handles[11] = &grid_point10x11; - handles[12] = &grid_point12; - handles[13] = &grid_point13; - handles[14] = &grid_point14; - handles[15] = &grid_point15; - handles[16] = &grid_point16; - handles[17] = &grid_point17; - handles[18] = &grid_point18; - handles[19] = &grid_point19; - handles[20] = &grid_point20x21; - handles[21] = &grid_point20x21; - handles[22] = &grid_point22x23; - handles[23] = &grid_point22x23; - handles[24] = &grid_point24x26; - handles[25] = &grid_point25x27; - handles[26] = &grid_point24x26; - handles[27] = &grid_point25x27; - handles[28] = &grid_point28x30; - handles[29] = &grid_point29x31; - handles[30] = &grid_point28x30; - handles[31] = &grid_point29x31; - handles[32] = &grid_point32x33x34x35; - handles[33] = &grid_point32x33x34x35; - handles[34] = &grid_point32x33x34x35; - handles[35] = &grid_point32x33x34x35; + handles[0] = grid_point0; + handles[1] = grid_point1; + handles[2] = grid_point2; + handles[3] = grid_point3; + handles[4] = grid_point4; + handles[5] = grid_point5; + handles[6] = grid_point6; + handles[7] = grid_point7; + handles[8] = grid_point8x9; + handles[9] = grid_point8x9; + handles[10] = grid_point10x11; + handles[11] = grid_point10x11; + handles[12] = grid_point12; + handles[13] = grid_point13; + handles[14] = grid_point14; + handles[15] = grid_point15; + handles[16] = grid_point16; + handles[17] = grid_point17; + handles[18] = grid_point18; + handles[19] = grid_point19; + handles[20] = grid_point20x21; + handles[21] = grid_point20x21; + handles[22] = grid_point22x23; + handles[23] = grid_point22x23; + handles[24] = grid_point24x26; + handles[25] = grid_point25x27; + handles[26] = grid_point24x26; + handles[27] = grid_point25x27; + handles[28] = grid_point28x30; + handles[29] = grid_point29x31; + handles[30] = grid_point28x30; + handles[31] = grid_point29x31; + handles[32] = grid_point32x33x34x35; + handles[33] = grid_point32x33x34x35; + handles[34] = grid_point32x33x34x35; + handles[35] = grid_point32x33x34x35; Geom::Point origin = Geom::Point(boundingbox_X.min(),boundingbox_Y.min()); @@ -185,7 +191,7 @@ LPELattice2::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd // i = Upperleft corner of the considerated rectangle // corner = actual corner of the rectangle // origin = Upperleft point - double dl = dot((*handles[corner+4*i] - (base + origin)), dir)/dot(dir,dir); + double dl = dot((handles[corner+4*i] - (base + origin)), dir)/dot(dir,dir); sb2[dim][i][corner] = dl/( dim ? height : width )*pow(4.0,ui+vi); } } @@ -195,8 +201,8 @@ LPELattice2::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd Piecewise<D2<SBasis> > output; output.push_cut(0.); - for(unsigned i = 0; i < pwd2_in.size(); i++) { - D2<SBasis> B = pwd2_in[i]; + for(unsigned i = 0; i < pwd2_in_linear_and_cubic.size(); i++) { + D2<SBasis> B = pwd2_in_linear_and_cubic[i]; B[Geom::X] -= origin[Geom::X]; B[Geom::X]*= 1/width; B[Geom::Y] -= origin[Geom::Y]; @@ -211,6 +217,7 @@ LPELattice2::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd return output; } + Gtk::Widget * LPELattice2::newWidget() { @@ -218,12 +225,17 @@ LPELattice2::newWidget() Gtk::VBox * vbox = Gtk::manage( new Gtk::VBox(Effect::newWidget()) ); vbox->set_border_width(5); - Gtk::Button* resetButton = Gtk::manage(new Gtk::Button(Glib::ustring(_("Reset grid")))); - resetButton->set_alignment(0.0, 0.5); + vbox->set_homogeneous(false); + vbox->set_spacing(6); + Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false,0)); + Gtk::VBox * vboxExpander = Gtk::manage( new Gtk::VBox(Effect::newWidget()) ); + vboxExpander->set_border_width(0); + vboxExpander->set_spacing(2); + Gtk::Button * resetButton = Gtk::manage(new Gtk::Button(Glib::ustring(_("Reset grid")))); resetButton->signal_clicked().connect(sigc::mem_fun (*this,&LPELattice2::resetGrid)); - Gtk::Widget* resetButtonWidget = dynamic_cast<Gtk::Widget *>(resetButton); - resetButtonWidget->set_tooltip_text("Reset grid"); - vbox->pack_start(*resetButtonWidget, true, true,2); + resetButton->set_size_request(140,30); + vbox->pack_start(*hbox, true,true,2); + hbox->pack_start(*resetButton, false, false,2); std::vector<Parameter *>::iterator it = param_vector.begin(); while (it != param_vector.end()) { if ((*it)->widget_is_visible) { @@ -234,7 +246,11 @@ LPELattice2::newWidget() } Glib::ustring * tip = param->param_getTooltip(); if (widg) { - vbox->pack_start(*widg, true, true, 2); + if (param->param_key == "horizontalMirror" || param->param_key == "verticalMirror") { + vbox->pack_start(*widg, true, true, 2); + } else { + vboxExpander->pack_start(*widg, true, true, 2); + } if (tip) { widg->set_tooltip_text(*tip); } else { @@ -246,14 +262,96 @@ LPELattice2::newWidget() ++it; } + + expander = Gtk::manage(new Gtk::Expander(Glib::ustring(_("Show Points")))); + expander->add(*vboxExpander); + expander->set_expanded(expanded); + vbox->pack_start(*expander, true, true, 2); + expander->property_expanded().signal_changed().connect(sigc::mem_fun(*this, &LPELattice2::on_expander_changed) ); return dynamic_cast<Gtk::Widget *>(vbox); } void +LPELattice2::on_expander_changed() +{ + expanded = expander->get_expanded(); + if(expander->get_expanded()){ + expander->set_label (Glib::ustring(_("Hide Points"))); + } else { + expander->set_label (Glib::ustring(_("Show Points"))); + } +} +void +LPELattice2::vertical(PointParam ¶mA, PointParam ¶mB, Geom::Line vert){ + Geom::Point A = paramA; + Geom::Point B = paramB; + double Y = (A[Geom::Y] + B[Geom::Y])/2; + A[Geom::Y] = Y; + B[Geom::Y] = Y; + Geom::Point nearest = vert.pointAt(vert.nearestPoint(A)); + double distA = Geom::distance(A,nearest); + double distB = Geom::distance(B,nearest); + double distanceMed = (distA + distB)/2; + if(A[Geom::X] > B[Geom::X]){ + distanceMed *= -1; + } + A[Geom::X] = nearest[Geom::X] - distanceMed; + B[Geom::X] = nearest[Geom::X] + distanceMed; + paramA.param_setValue(A, true); + paramB.param_setValue(B, true); +} + +void +LPELattice2::horizontal(PointParam ¶mA, PointParam ¶mB, Geom::Line horiz){ + Geom::Point A = paramA; + Geom::Point B = paramB; + double X = (A[Geom::X] + B[Geom::X])/2; + A[Geom::X] = X; + B[Geom::X] = X; + Geom::Point nearest = horiz.pointAt(horiz.nearestPoint(A)); + double distA = Geom::distance(A,nearest); + double distB = Geom::distance(B,nearest); + double distanceMed = (distA + distB)/2; + if(A[Geom::Y] > B[Geom::Y]){ + distanceMed *= -1; + } + A[Geom::Y] = nearest[Geom::Y] - distanceMed; + B[Geom::Y] = nearest[Geom::Y] + distanceMed; + paramA.param_setValue(A, true); + paramB.param_setValue(B, true); +} + +void LPELattice2::doBeforeEffect (SPLPEItem const* lpeitem) { original_bbox(lpeitem); setDefaults(); + Geom::Line vert(grid_point8x9.param_get_default(),grid_point10x11.param_get_default()); + Geom::Line horiz(grid_point24x26.param_get_default(),grid_point25x27.param_get_default()); + if(verticalMirror){ + vertical(grid_point0, grid_point1,vert); + vertical(grid_point2, grid_point3,vert); + vertical(grid_point4, grid_point5,vert); + vertical(grid_point6, grid_point7,vert); + vertical(grid_point12, grid_point13,vert); + vertical(grid_point14, grid_point15,vert); + vertical(grid_point16, grid_point17,vert); + vertical(grid_point18, grid_point19,vert); + vertical(grid_point24x26, grid_point25x27,vert); + vertical(grid_point28x30, grid_point29x31,vert); + } + if(horizontalMirror){ + horizontal(grid_point0, grid_point2,horiz); + horizontal(grid_point1, grid_point3,horiz); + horizontal(grid_point4, grid_point6,horiz); + horizontal(grid_point5, grid_point7,horiz); + horizontal(grid_point8x9, grid_point10x11,horiz); + horizontal(grid_point12, grid_point14,horiz); + horizontal(grid_point13, grid_point15,horiz); + horizontal(grid_point16, grid_point18,horiz); + horizontal(grid_point17, grid_point19,horiz); + horizontal(grid_point20x21, grid_point22x23,horiz); + } SPLPEItem * item = const_cast<SPLPEItem*>(lpeitem); item->apply_to_clippath(item); item->apply_to_mask(item); @@ -367,36 +465,31 @@ LPELattice2::setDefaults() void LPELattice2::resetGrid() { - grid_point0.param_set_and_write_default(); - grid_point1.param_set_and_write_default(); - grid_point2.param_set_and_write_default(); - grid_point3.param_set_and_write_default(); - grid_point4.param_set_and_write_default(); - grid_point5.param_set_and_write_default(); - grid_point6.param_set_and_write_default(); - grid_point7.param_set_and_write_default(); - grid_point8x9.param_set_and_write_default(); - grid_point10x11.param_set_and_write_default(); - grid_point12.param_set_and_write_default(); - grid_point13.param_set_and_write_default(); - grid_point14.param_set_and_write_default(); - grid_point15.param_set_and_write_default(); - grid_point16.param_set_and_write_default(); - grid_point17.param_set_and_write_default(); - grid_point18.param_set_and_write_default(); - grid_point19.param_set_and_write_default(); - grid_point20x21.param_set_and_write_default(); - grid_point22x23.param_set_and_write_default(); - grid_point24x26.param_set_and_write_default(); - grid_point25x27.param_set_and_write_default(); - grid_point28x30.param_set_and_write_default(); - grid_point29x31.param_set_and_write_default(); - grid_point32x33x34x35.param_set_and_write_default(); - //todo:this hack is only to reposition the knots on reser grid button - //Better update path effect in LPEITEM - SPDesktop * desktop = SP_ACTIVE_DESKTOP; - tools_switch(desktop, TOOLS_SELECT); - tools_switch(desktop, TOOLS_NODES); + grid_point0.param_set_default(); + grid_point1.param_set_default(); + grid_point2.param_set_default(); + grid_point3.param_set_default(); + grid_point4.param_set_default(); + grid_point5.param_set_default(); + grid_point6.param_set_default(); + grid_point7.param_set_default(); + grid_point8x9.param_set_default(); + grid_point10x11.param_set_default(); + grid_point12.param_set_default(); + grid_point13.param_set_default(); + grid_point14.param_set_default(); + grid_point15.param_set_default(); + grid_point16.param_set_default(); + grid_point17.param_set_default(); + grid_point18.param_set_default(); + grid_point19.param_set_default(); + grid_point20x21.param_set_default(); + grid_point22x23.param_set_default(); + grid_point24x26.param_set_default(); + grid_point25x27.param_set_default(); + grid_point28x30.param_set_default(); + grid_point29x31.param_set_default(); + grid_point32x33x34x35.param_set_default(); } void diff --git a/src/live_effects/lpe-lattice2.h b/src/live_effects/lpe-lattice2.h index 461f835c6..086bdab7e 100644 --- a/src/live_effects/lpe-lattice2.h +++ b/src/live_effects/lpe-lattice2.h @@ -18,10 +18,10 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ - +#include <gtkmm.h> #include "live_effects/parameter/enum.h" #include "live_effects/effect.h" -#include "live_effects/parameter/pointreseteable.h" +#include "live_effects/parameter/point.h" #include "live_effects/lpegroupbbox.h" namespace Inkscape { @@ -43,8 +43,14 @@ public: virtual void calculateCurve(Geom::Point a,Geom::Point b, SPCurve *c, bool horizontal, bool move); + virtual void vertical(PointParam ¶mA,PointParam ¶mB, Geom::Line vert); + + virtual void horizontal(PointParam ¶mA,PointParam ¶mB,Geom::Line horiz); + virtual void setDefaults(); + virtual void on_expander_changed(); + virtual void resetGrid(); //virtual void original_bbox(SPLPEItem const* lpeitem, bool absolute = false); @@ -56,31 +62,36 @@ protected: void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector<Geom::PathVector> &hp_vec); private: - PointReseteableParam grid_point0; - PointReseteableParam grid_point1; - PointReseteableParam grid_point2; - PointReseteableParam grid_point3; - PointReseteableParam grid_point4; - PointReseteableParam grid_point5; - PointReseteableParam grid_point6; - PointReseteableParam grid_point7; - PointReseteableParam grid_point8x9; - PointReseteableParam grid_point10x11; - PointReseteableParam grid_point12; - PointReseteableParam grid_point13; - PointReseteableParam grid_point14; - PointReseteableParam grid_point15; - PointReseteableParam grid_point16; - PointReseteableParam grid_point17; - PointReseteableParam grid_point18; - PointReseteableParam grid_point19; - PointReseteableParam grid_point20x21; - PointReseteableParam grid_point22x23; - PointReseteableParam grid_point24x26; - PointReseteableParam grid_point25x27; - PointReseteableParam grid_point28x30; - PointReseteableParam grid_point29x31; - PointReseteableParam grid_point32x33x34x35; + BoolParam horizontalMirror; + BoolParam verticalMirror; + PointParam grid_point0; + PointParam grid_point1; + PointParam grid_point2; + PointParam grid_point3; + PointParam grid_point4; + PointParam grid_point5; + PointParam grid_point6; + PointParam grid_point7; + PointParam grid_point8x9; + PointParam grid_point10x11; + PointParam grid_point12; + PointParam grid_point13; + PointParam grid_point14; + PointParam grid_point15; + PointParam grid_point16; + PointParam grid_point17; + PointParam grid_point18; + PointParam grid_point19; + PointParam grid_point20x21; + PointParam grid_point22x23; + PointParam grid_point24x26; + PointParam grid_point25x27; + PointParam grid_point28x30; + PointParam grid_point29x31; + PointParam grid_point32x33x34x35; + + bool expanded; + Gtk::Expander * expander; LPELattice2(const LPELattice2&); LPELattice2& operator=(const LPELattice2&); diff --git a/src/live_effects/lpe-offset.cpp b/src/live_effects/lpe-offset.cpp index dc91775b7..ba7179476 100644 --- a/src/live_effects/lpe-offset.cpp +++ b/src/live_effects/lpe-offset.cpp @@ -42,7 +42,9 @@ LPEOffset::~LPEOffset() void LPEOffset::doOnApply(SPLPEItem const* lpeitem) { - offset_pt.param_set_and_write_new_value(*(SP_SHAPE(lpeitem)->_curve->first_point())); + Geom::Point offset = *(SP_SHAPE(lpeitem)->_curve->first_point()); + offset_pt.param_update_default(offset); + offset_pt.param_setValue(offset,true); } static void append_half_circle(Geom::Piecewise<Geom::D2<Geom::SBasis> > &pwd2, diff --git a/src/live_effects/lpe-parallel.cpp b/src/live_effects/lpe-parallel.cpp index bb37fd42c..aa7405607 100644 --- a/src/live_effects/lpe-parallel.cpp +++ b/src/live_effects/lpe-parallel.cpp @@ -72,8 +72,9 @@ LPEParallel::doOnApply (SPLPEItem const* lpeitem) A = *(curve->first_point()); B = *(curve->last_point()); dir = unit_vector(B - A); - - offset_pt.param_set_and_write_new_value((A + B)/2 + dir.ccw() * 100); + Geom::Point offset = (A + B)/2 + dir.ccw() * 100; + offset_pt.param_update_default(offset); + offset_pt.param_setValue(offset, true); } Geom::Piecewise<Geom::D2<Geom::SBasis> > diff --git a/src/live_effects/lpe-perspective-envelope.cpp b/src/live_effects/lpe-perspective-envelope.cpp index b5ef26e2f..d60a13c23 100644 --- a/src/live_effects/lpe-perspective-envelope.cpp +++ b/src/live_effects/lpe-perspective-envelope.cpp @@ -19,9 +19,7 @@ #include "helper/geom.h" #include "display/curve.h" #include "svg/svg.h" -#include "ui/tools-switch.h" #include <gsl/gsl_linalg.h> -#include "desktop.h" using namespace Geom; @@ -44,10 +42,10 @@ LPEPerspectiveEnvelope::LPEPerspectiveEnvelope(LivePathEffectObject *lpeobject) Effect(lpeobject), // initialise your parameters here: deform_type(_("Type"), _("Select the type of deformation"), "deform_type", DeformationTypeConverter, &wr, this, DEFORMATION_PERSPECTIVE), - Up_Left_Point(_("Top Left"), _("Top Left - Ctrl+Alt+Click to reset"), "Up_Left_Point", &wr, this), - Up_Right_Point(_("Top Right"), _("Top Right - Ctrl+Alt+Click to reset"), "Up_Right_Point", &wr, this), - Down_Left_Point(_("Down Left"), _("Down Left - Ctrl+Alt+Click to reset"), "Down_Left_Point", &wr, this), - Down_Right_Point(_("Down Right"), _("Down Right - Ctrl+Alt+Click to reset"), "Down_Right_Point", &wr, this) + Up_Left_Point(_("Top Left"), _("Top Left - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "Up_Left_Point", &wr, this), + Up_Right_Point(_("Top Right"), _("Top Right - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "Up_Right_Point", &wr, this), + Down_Left_Point(_("Down Left"), _("Down Left - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "Down_Left_Point", &wr, this), + Down_Right_Point(_("Down Right"), _("Down Right - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "Down_Right_Point", &wr, this) { // register all your parameters here, so Inkscape knows which parameters this effect has: registerParameter( dynamic_cast<Parameter *>(&deform_type)); @@ -298,7 +296,7 @@ LPEPerspectiveEnvelope::newWidget() Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false,0)); Gtk::Button* resetButton = Gtk::manage(new Gtk::Button(Gtk::Stock::CLEAR)); resetButton->signal_clicked().connect(sigc::mem_fun (*this,&LPEPerspectiveEnvelope::resetGrid)); - resetButton->set_size_request(140,45); + resetButton->set_size_request(140,30); vbox->pack_start(*hbox, true,true,2); hbox->pack_start(*resetButton, false, false,2); return dynamic_cast<Gtk::Widget *>(vbox); @@ -331,15 +329,10 @@ LPEPerspectiveEnvelope::setDefaults() void LPEPerspectiveEnvelope::resetGrid() { - Up_Left_Point.param_set_and_write_default(); - Up_Right_Point.param_set_and_write_default(); - Down_Right_Point.param_set_and_write_default(); - Down_Left_Point.param_set_and_write_default(); - //todo:this hack is only to reposition the knots on reser grid button - //Better update path effect in LPEITEM - SPDesktop * desktop = SP_ACTIVE_DESKTOP; - tools_switch(desktop, TOOLS_SELECT); - tools_switch(desktop, TOOLS_NODES); + Up_Left_Point.param_set_default(); + Up_Right_Point.param_set_default(); + Down_Right_Point.param_set_default(); + Down_Left_Point.param_set_default(); } void @@ -347,8 +340,8 @@ LPEPerspectiveEnvelope::resetDefaults(SPItem const* item) { Effect::resetDefaults(item); original_bbox(SP_LPE_ITEM(item)); - setDefaults(); resetGrid(); + setDefaults(); } void diff --git a/src/live_effects/lpe-perspective-envelope.h b/src/live_effects/lpe-perspective-envelope.h index 2f253882e..d3ff76445 100644 --- a/src/live_effects/lpe-perspective-envelope.h +++ b/src/live_effects/lpe-perspective-envelope.h @@ -19,7 +19,7 @@ #include "live_effects/parameter/enum.h" #include "live_effects/effect.h" -#include "live_effects/parameter/pointreseteable.h" +#include "live_effects/parameter/point.h" #include "live_effects/lpegroupbbox.h" namespace Inkscape { @@ -55,10 +55,10 @@ protected: private: EnumParam<unsigned> deform_type; - PointReseteableParam Up_Left_Point; - PointReseteableParam Up_Right_Point; - PointReseteableParam Down_Left_Point; - PointReseteableParam Down_Right_Point; + PointParam Up_Left_Point; + PointParam Up_Right_Point; + PointParam Down_Left_Point; + PointParam Down_Right_Point; LPEPerspectiveEnvelope(const LPEPerspectiveEnvelope&); LPEPerspectiveEnvelope& operator=(const LPEPerspectiveEnvelope&); diff --git a/src/live_effects/lpe-simplify.cpp b/src/live_effects/lpe-simplify.cpp index 2b2efb1a9..1fe18dd5e 100644 --- a/src/live_effects/lpe-simplify.cpp +++ b/src/live_effects/lpe-simplify.cpp @@ -20,6 +20,7 @@ #include <2geom/generic-rect.h> #include <2geom/interval.h> #include "ui/icon-names.h" +#include "util/units.h" namespace Inkscape { namespace LivePathEffect { @@ -28,32 +29,37 @@ LPESimplify::LPESimplify(LivePathEffectObject *lpeobject) : Effect(lpeobject), steps(_("Steps:"),_("Change number of simplify steps "), "steps", &wr, this,1), threshold(_("Roughly threshold:"), _("Roughly threshold:"), "threshold", &wr, this, 0.003), - helper_size(_("Helper size:"), _("Helper size"), "helper_size", &wr, this, 2.), - nodes(_("Helper nodes"), _("Show helper nodes"), "nodes", &wr, this, false, - "", INKSCAPE_ICON("on"), INKSCAPE_ICON("off")), - handles(_("Helper handles"), _("Show helper handles"), "handles", &wr, this, false, - "", INKSCAPE_ICON("on"), INKSCAPE_ICON("off")), + smooth_angles(_("Smooth angles:"), _("Max degree difference on handles to preform a smooth"), "smooth_angles", &wr, this, 20.), + helper_size(_("Helper size:"), _("Helper size"), "helper_size", &wr, this, 5), simplifyindividualpaths(_("Paths separately"), _("Simplifying paths (separately)"), "simplifyindividualpaths", &wr, this, false, "", INKSCAPE_ICON("on"), INKSCAPE_ICON("off")), simplifyJustCoalesce(_("Just coalesce"), _("Simplify just coalesce"), "simplifyJustCoalesce", &wr, this, false, "", INKSCAPE_ICON("on"), INKSCAPE_ICON("off")) { - registerParameter(dynamic_cast<Parameter *>(&steps)); - registerParameter(dynamic_cast<Parameter *>(&threshold)); - registerParameter(dynamic_cast<Parameter *>(&helper_size)); - registerParameter(dynamic_cast<Parameter *>(&nodes)); - registerParameter(dynamic_cast<Parameter *>(&handles)); - registerParameter(dynamic_cast<Parameter *>(&simplifyindividualpaths)); - registerParameter(dynamic_cast<Parameter *>(&simplifyJustCoalesce)); + registerParameter(&steps); + registerParameter(&threshold); + registerParameter(&smooth_angles); + registerParameter(&helper_size); + registerParameter(&simplifyindividualpaths); + registerParameter(&simplifyJustCoalesce); + threshold.param_set_range(0.0001, Geom::infinity()); threshold.param_set_increments(0.0001, 0.0001); threshold.param_set_digits(6); + steps.param_set_range(0, 100); steps.param_set_increments(1, 1); steps.param_set_digits(0); - helper_size.param_set_range(0.1, 100); - helper_size.param_set_increments(1, 1); - helper_size.param_set_digits(1); + + smooth_angles.param_set_range(0.0, 365.0); + smooth_angles.param_set_increments(10, 10); + smooth_angles.param_set_digits(2); + + helper_size.param_set_range(0.0, 999.0); + helper_size.param_set_increments(5, 5); + helper_size.param_set_digits(2); + + radiusHelperNodes = 6.0; } LPESimplify::~LPESimplify() {} @@ -66,9 +72,9 @@ LPESimplify::doBeforeEffect (SPLPEItem const* lpeitem) } bbox = SP_ITEM(lpeitem)->visualBounds(); SPLPEItem * item = const_cast<SPLPEItem*>(lpeitem); + radiusHelperNodes = helper_size; item->apply_to_clippath(item); item->apply_to_mask(item); - } Gtk::Widget * @@ -81,7 +87,6 @@ LPESimplify::newWidget() vbox->set_spacing(2); std::vector<Parameter *>::iterator it = param_vector.begin(); Gtk::HBox * buttons = Gtk::manage(new Gtk::HBox(true,0)); - Gtk::HBox * buttonsTwo = Gtk::manage(new Gtk::HBox(true,0)); while (it != param_vector.end()) { if ((*it)->widget_is_visible) { Parameter * param = *it; @@ -91,19 +96,6 @@ LPESimplify::newWidget() { Glib::ustring * tip = param->param_getTooltip(); if (widg) { - buttonsTwo->pack_start(*widg, true, true, 2); - if (tip) { - widg->set_tooltip_text(*tip); - } else { - widg->set_tooltip_text(""); - widg->set_has_tooltip(false); - } - } - } else if (param->param_key == "nodes" || - param->param_key == "handles") - { - Glib::ustring * tip = param->param_getTooltip(); - if (widg) { buttons->pack_start(*widg, true, true, 2); if (tip) { widg->set_tooltip_text(*tip); @@ -112,7 +104,7 @@ LPESimplify::newWidget() widg->set_has_tooltip(false); } } - }else{ + } else{ Glib::ustring * tip = param->param_getTooltip(); if (widg) { Gtk::HBox * scalarParameter = dynamic_cast<Gtk::HBox *>(widg); @@ -133,7 +125,6 @@ LPESimplify::newWidget() ++it; } vbox->pack_start(*buttons,true, true, 2); - vbox->pack_start(*buttonsTwo,true, true, 2); return dynamic_cast<Gtk::Widget *>(vbox); } @@ -154,9 +145,9 @@ LPESimplify::doEffect(SPCurve *curve) { pathliv->Simplify(threshold * size); } } - Geom::PathVector outres = Geom::parse_svg_path(pathliv->svg_dump_path()); - generateHelperPath(outres); - curve->set_pathvector(outres); + Geom::PathVector result = Geom::parse_svg_path(pathliv->svg_dump_path()); + generateHelperPathAndSmooth(result); + curve->set_pathvector(result); SPDesktop* desktop = SP_ACTIVE_DESKTOP; if(desktop && INK_IS_NODE_TOOL(desktop->event_context)){ Inkscape::UI::Tools::NodeTool *nt = static_cast<Inkscape::UI::Tools::NodeTool*>(desktop->event_context); @@ -165,16 +156,12 @@ LPESimplify::doEffect(SPCurve *curve) { } void -LPESimplify::generateHelperPath(Geom::PathVector result) +LPESimplify::generateHelperPathAndSmooth(Geom::PathVector &result) { - if(!handles && !nodes){ - return; - } - if(steps < 1){ return; } - + Geom::PathVector tmpPath; Geom::CubicBezier const *cubic = NULL; for (Geom::PathVector::iterator path_it = result.begin(); path_it != result.end(); ++path_it) { //Si está vacÃo... @@ -183,11 +170,9 @@ LPESimplify::generateHelperPath(Geom::PathVector result) } //Itreadores Geom::Path::const_iterator curve_it1 = path_it->begin(); // incoming curve - Geom::Path::const_iterator curve_it2 = - ++(path_it->begin()); // outgoing curve - Geom::Path::const_iterator curve_endit = - path_it->end_default(); // this determines when the loop has to stop - + Geom::Path::const_iterator curve_it2 = ++(path_it->begin());// outgoing curve + Geom::Path::const_iterator curve_endit = path_it->end_default(); // this determines when the loop has to stop + SPCurve *nCurve = new SPCurve(); if (path_it->closed()) { // if the path is closed, maybe we have to stop a bit earlier because the // closing line segment has zerolength. @@ -202,13 +187,50 @@ LPESimplify::generateHelperPath(Geom::PathVector result) curve_endit = path_it->end_open(); } } - if(nodes){ + if(helper_size > 0){ drawNode(curve_it1->initialPoint()); } + nCurve->moveto(curve_it1->initialPoint()); + Geom::Point start = Geom::Point(0,0); while (curve_it1 != curve_endit) { cubic = dynamic_cast<Geom::CubicBezier const *>(&*curve_it1); + Geom::Point pointAt1 = curve_it1->initialPoint(); + Geom::Point pointAt2 = curve_it1->finalPoint(); + Geom::Point pointAt3 = curve_it1->finalPoint(); + Geom::Point pointAt4 = curve_it1->finalPoint(); + if (cubic) { + pointAt1 = (*cubic)[1]; + pointAt2 = (*cubic)[2]; + } + if(start == Geom::Point(0,0)){ + start = pointAt1; + } + + if(path_it->closed() && curve_it2 == curve_endit){ + pointAt4 = start; + } + if(curve_it2 != curve_endit){ + cubic = dynamic_cast<Geom::CubicBezier const *>(&*curve_it2); + if (cubic) { + pointAt4 = (*cubic)[1]; + } + } + Geom::Ray ray1(pointAt2, pointAt3); + Geom::Ray ray2(pointAt3, pointAt4); + double angle1 = Geom::rad_to_deg(ray1.angle()); + double angle2 = Geom::rad_to_deg(ray2.angle()); + if((smooth_angles >= angle2 - angle1) && !are_near(pointAt4,pointAt3) && !are_near(pointAt2,pointAt3)){ + double dist = Geom::distance(pointAt2,pointAt3); + Geom::Angle angleFixed = ray2.angle(); + angleFixed -= Geom::Angle::from_degrees(180.0); + pointAt2 = Geom::Point::polar(angleFixed,dist) + pointAt3; + } + nCurve->curveto(pointAt1, pointAt2, curve_it1->finalPoint()); + cubic = dynamic_cast<Geom::CubicBezier const *>(nCurve->last_segment()); if (cubic) { - if(handles) { + pointAt1 = (*cubic)[1]; + pointAt2 = (*cubic)[2]; + if(helper_size > 0) { if(!are_near((*cubic)[0],(*cubic)[1])){ drawHandle((*cubic)[1]); drawHandleLine((*cubic)[0],(*cubic)[1]); @@ -219,21 +241,26 @@ LPESimplify::generateHelperPath(Geom::PathVector result) } } } - if(nodes) { + if(helper_size > 0) { drawNode(curve_it1->finalPoint()); } ++curve_it1; - if(curve_it2 != curve_endit){ - ++curve_it2; - } + ++curve_it2; + } + if (path_it->closed()) { + nCurve->closepath_current(); } + tmpPath.push_back(nCurve->get_pathvector()[0]); + nCurve->reset(); + delete nCurve; } + result = tmpPath; } void LPESimplify::drawNode(Geom::Point p) { - double r = helper_size/0.67; + double r = radiusHelperNodes; char const * svgd; svgd = "M 0.55,0.5 A 0.05,0.05 0 0 1 0.5,0.55 0.05,0.05 0 0 1 0.45,0.5 0.05,0.05 0 0 1 0.5,0.45 0.05,0.05 0 0 1 0.55,0.5 Z M 0,0 1,0 1,1 0,1 Z"; Geom::PathVector pathv = sp_svg_read_pathv(svgd); @@ -246,7 +273,7 @@ LPESimplify::drawNode(Geom::Point p) void LPESimplify::drawHandle(Geom::Point p) { - double r = helper_size/0.67; + double r = radiusHelperNodes; char const * svgd; svgd = "M 0.7,0.35 A 0.35,0.35 0 0 1 0.35,0.7 0.35,0.35 0 0 1 0,0.35 0.35,0.35 0 0 1 0.35,0 0.35,0.35 0 0 1 0.7,0.35 Z"; Geom::PathVector pathv = sp_svg_read_pathv(svgd); @@ -261,8 +288,8 @@ LPESimplify::drawHandleLine(Geom::Point p,Geom::Point p2) { Geom::Path path; path.start( p ); - double diameter = helper_size/0.67; - if(helper_size > 0.0 && Geom::distance(p,p2) > (diameter * 0.35)){ + double diameter = radiusHelperNodes; + if(helper_size > 0 && Geom::distance(p,p2) > (diameter * 0.35)){ Geom::Ray ray2(p, p2); p2 = p2 - Geom::Point::polar(ray2.angle(),(diameter * 0.35)); } diff --git a/src/live_effects/lpe-simplify.h b/src/live_effects/lpe-simplify.h index 6acf2f2d4..c18c3ecdf 100644 --- a/src/live_effects/lpe-simplify.h +++ b/src/live_effects/lpe-simplify.h @@ -24,7 +24,7 @@ public: virtual void doBeforeEffect (SPLPEItem const* lpeitem); - virtual void generateHelperPath(Geom::PathVector result); + virtual void generateHelperPathAndSmooth(Geom::PathVector &result); virtual Gtk::Widget * newWidget(); @@ -40,12 +40,12 @@ protected: private: ScalarParam steps; ScalarParam threshold; + ScalarParam smooth_angles; ScalarParam helper_size; - ToggleButtonParam nodes; - ToggleButtonParam handles; ToggleButtonParam simplifyindividualpaths; ToggleButtonParam simplifyJustCoalesce; + double radiusHelperNodes; Geom::PathVector hp; Geom::OptRect bbox; diff --git a/src/live_effects/lpe-sketch.cpp b/src/live_effects/lpe-sketch.cpp index 8ad0e616f..551dbe16a 100644 --- a/src/live_effects/lpe-sketch.cpp +++ b/src/live_effects/lpe-sketch.cpp @@ -240,7 +240,7 @@ LPESketch::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_ for (unsigned i = 0; i<nbiter_approxstrokes; i++){ //Basic steps: - //- Choose a rdm seg [s0,s1], find coresponding [t0,t1], + //- Choose a rdm seg [s0,s1], find corresponding [t0,t1], //- Pick a rdm perturbation delta(s), collect 'piece(t)+delta(s(t))' over [t0,t1] into output. // pick a point where to start the stroke (s0 = dist from start). diff --git a/src/live_effects/lpe-test-doEffect-stack.cpp b/src/live_effects/lpe-test-doEffect-stack.cpp index 03e3e7997..c6787aae1 100644 --- a/src/live_effects/lpe-test-doEffect-stack.cpp +++ b/src/live_effects/lpe-test-doEffect-stack.cpp @@ -28,6 +28,7 @@ LPEdoEffectStackTest::LPEdoEffectStackTest(LivePathEffectObject *lpeobject) : registerParameter( dynamic_cast<Parameter *>(&path) ); point.set_oncanvas_looks(SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR, 0x00ff0000); + point.param_setValue(point,true); } LPEdoEffectStackTest::~LPEdoEffectStackTest() diff --git a/src/live_effects/lpeobject.cpp b/src/live_effects/lpeobject.cpp index d92c94d01..8e5ae568f 100644 --- a/src/live_effects/lpeobject.cpp +++ b/src/live_effects/lpeobject.cpp @@ -20,16 +20,6 @@ //#define LIVEPATHEFFECT_VERBOSE -#include "sp-factory.h" - -namespace { - SPObject* createLivepatheffect() { - return new LivePathEffectObject(); - } - - bool livepatheffectRegistered = SPFactory::instance().registerObject("inkscape:path-effect", createLivepatheffect); -} - static void livepatheffect_on_repr_attr_changed (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive, void * data); static Inkscape::XML::NodeEventVector const livepatheffect_repr_events = { diff --git a/src/live_effects/parameter/Makefile_insert b/src/live_effects/parameter/Makefile_insert index f990f41c7..bd1c5b600 100644 --- a/src/live_effects/parameter/Makefile_insert +++ b/src/live_effects/parameter/Makefile_insert @@ -11,8 +11,6 @@ ink_common_sources += \ live_effects/parameter/random.h \ live_effects/parameter/point.cpp \ live_effects/parameter/point.h \ - live_effects/parameter/pointreseteable.cpp \ - live_effects/parameter/pointreseteable.h \ live_effects/parameter/enum.h \ live_effects/parameter/path-reference.cpp \ live_effects/parameter/path-reference.h \ diff --git a/src/live_effects/parameter/filletchamferpointarray.cpp b/src/live_effects/parameter/filletchamferpointarray.cpp index 2ebe11b4b..e9d375b93 100644 --- a/src/live_effects/parameter/filletchamferpointarray.cpp +++ b/src/live_effects/parameter/filletchamferpointarray.cpp @@ -354,7 +354,7 @@ void FilletChamferPointArrayParam::set_pwd2( last_pwd2_normal = pwd2_normal_in; } -void FilletChamferPointArrayParam::set_document_unit(Glib::ustring const * value_document_unit) +void FilletChamferPointArrayParam::set_document_unit(Glib::ustring value_document_unit) { documentUnit = value_document_unit; } diff --git a/src/live_effects/parameter/filletchamferpointarray.h b/src/live_effects/parameter/filletchamferpointarray.h index 6e5cce353..7849d5afb 100644 --- a/src/live_effects/parameter/filletchamferpointarray.h +++ b/src/live_effects/parameter/filletchamferpointarray.h @@ -53,7 +53,7 @@ public: virtual void set_helper_size(int hs); virtual void set_use_distance(bool use_knot_distance); virtual void set_chamfer_steps(int value_chamfer_steps); - virtual void set_document_unit(Glib::ustring const * value_document_unit); + virtual void set_document_unit(Glib::ustring value_document_unit); virtual void set_unit(const gchar *abbr); virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector<Geom::PathVector> &hp_vec); @@ -90,7 +90,7 @@ private: int chamfer_steps; bool use_distance; const gchar *unit; - Glib::ustring const * documentUnit; + Glib::ustring documentUnit; Geom::PathVector hp; Geom::Piecewise<Geom::D2<Geom::SBasis> > last_pwd2; diff --git a/src/live_effects/parameter/point.cpp b/src/live_effects/parameter/point.cpp index 302818e55..4c4d2cd9c 100644 --- a/src/live_effects/parameter/point.cpp +++ b/src/live_effects/parameter/point.cpp @@ -26,7 +26,9 @@ namespace LivePathEffect { PointParam::PointParam( const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, Effect* effect, const gchar *htip, Geom::Point default_value) - : Geom::Point(default_value), Parameter(label, tip, key, wr, effect), defvalue(default_value) + : Parameter(label, tip, key, wr, effect), + defvalue(default_value), + knoth(NULL) { knot_shape = SP_KNOT_SHAPE_DIAMOND; knot_mode = SP_KNOT_MODE_XOR; @@ -43,7 +45,34 @@ PointParam::~PointParam() void PointParam::param_set_default() { - param_setValue(defvalue); + param_setValue(defvalue,true); +} + +Geom::Point +PointParam::param_get_default() const{ + return defvalue; +} + +void +PointParam::param_update_default(Geom::Point newpoint) +{ + defvalue = newpoint; +} + +void +PointParam::param_setValue(Geom::Point newpoint, bool write) +{ + *dynamic_cast<Geom::Point *>( this ) = newpoint; + if(write){ + Inkscape::SVGOStringStream os; + os << newpoint; + gchar * str = g_strdup(os.str().c_str()); + param_write_to_repr(str); + g_free(str); + } + if(knoth){ + knoth->update_knots(); + } } bool @@ -70,6 +99,12 @@ PointParam::param_getSVGValue() const return str; } +void +PointParam::param_transform_multiply(Geom::Affine const& postmul, bool /*set*/) +{ + param_setValue( (*this) * postmul, true); +} + Gtk::Widget * PointParam::param_newWidget() { @@ -96,29 +131,6 @@ PointParam::param_newWidget() } void -PointParam::param_setValue(Geom::Point newpoint) -{ - *dynamic_cast<Geom::Point *>( this ) = newpoint; -} - -void -PointParam::param_set_and_write_new_value (Geom::Point newpoint) -{ - Inkscape::SVGOStringStream os; - os << newpoint; - gchar * str = g_strdup(os.str().c_str()); - param_write_to_repr(str); - g_free(str); -} - -void -PointParam::param_transform_multiply(Geom::Affine const& postmul, bool /*set*/) -{ - param_set_and_write_new_value( (*this) * postmul ); -} - - -void PointParam::set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color) { knot_shape = shape; @@ -129,7 +141,7 @@ PointParam::set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint class PointParamKnotHolderEntity : public KnotHolderEntity { public: PointParamKnotHolderEntity(PointParam *p) { this->pparam = p; } - virtual ~PointParamKnotHolderEntity() {} + virtual ~PointParamKnotHolderEntity() { this->pparam->knoth = NULL;} virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); virtual Geom::Point knot_get() const; @@ -140,11 +152,25 @@ private: }; void -PointParamKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state) +PointParamKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point const &origin, guint state) { - Geom::Point const s = snap_knot_position(p, state); - pparam->param_setValue(s); - sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); + Geom::Point s = snap_knot_position(p, state); + if (state & GDK_CONTROL_MASK) { + Geom::Point A(origin[Geom::X],p[Geom::Y]); + Geom::Point B(p[Geom::X],origin[Geom::Y]); + double distanceA = Geom::distance(A,p); + double distanceB = Geom::distance(B,p); + if(distanceA > distanceB){ + s = B; + } else { + s = A; + } + } + pparam->param_setValue(s, true); + SPLPEItem * splpeitem = dynamic_cast<SPLPEItem *>(item); + if(splpeitem){ + sp_lpe_item_update_patheffect(splpeitem, false, false); + } } Geom::Point @@ -154,19 +180,27 @@ PointParamKnotHolderEntity::knot_get() const } void -PointParamKnotHolderEntity::knot_click(guint /*state*/) +PointParamKnotHolderEntity::knot_click(guint state) { - g_print ("This is the handle associated to parameter '%s'\n", pparam->param_key.c_str()); + if (state & GDK_CONTROL_MASK) { + if (state & GDK_MOD1_MASK) { + this->pparam->param_set_default(); + SPLPEItem * splpeitem = dynamic_cast<SPLPEItem *>(item); + if(splpeitem){ + sp_lpe_item_update_patheffect(splpeitem, false, false); + } + } + } } void PointParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { + knoth = knotholder; PointParamKnotHolderEntity *e = new PointParamKnotHolderEntity(this); // TODO: can we ditch handleTip() etc. because we have access to handle_tip etc. itself??? e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, handleTip(), knot_shape, knot_mode, knot_color); knotholder->add(e); - } } /* namespace LivePathEffect */ diff --git a/src/live_effects/parameter/point.h b/src/live_effects/parameter/point.h index 319835bb3..471fbc993 100644 --- a/src/live_effects/parameter/point.h +++ b/src/live_effects/parameter/point.h @@ -20,6 +20,7 @@ namespace Inkscape { namespace LivePathEffect { +class PointParamKnotHolderEntity; class PointParam : public Geom::Point, public Parameter { public: @@ -37,12 +38,10 @@ public: bool param_readSVGValue(const gchar * strvalue); gchar * param_getSVGValue() const; inline const gchar *handleTip() const { return handle_tip ? handle_tip : param_tooltip.c_str(); } - - void param_setValue(Geom::Point newpoint); + void param_setValue(Geom::Point newpoint, bool write = false); void param_set_default(); - - void param_set_and_write_new_value(Geom::Point newpoint); - + Geom::Point param_get_default() const; + void param_update_default(Geom::Point newpoint); virtual void param_transform_multiply(Geom::Affine const& /*postmul*/, bool /*set*/); void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); @@ -50,12 +49,12 @@ public: virtual bool providesKnotHolderEntities() const { return true; } virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); + friend class PointParamKnotHolderEntity; private: PointParam(const PointParam&); PointParam& operator=(const PointParam&); - Geom::Point defvalue; - + KnotHolder *knoth; SPKnotShapeType knot_shape; SPKnotModeType knot_mode; guint32 knot_color; diff --git a/src/live_effects/parameter/pointreseteable.cpp b/src/live_effects/parameter/pointreseteable.cpp deleted file mode 100644 index c0f8858b8..000000000 --- a/src/live_effects/parameter/pointreseteable.cpp +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl> - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "ui/widget/registered-widget.h" -#include "live_effects/parameter/pointreseteable.h" -#include "live_effects/effect.h" -#include "svg/svg.h" -#include "svg/stringstream.h" -#include "ui/widget/point.h" -#include "widgets/icon.h" -#include "inkscape.h" -#include "verbs.h" -#include "knotholder.h" -#include <glibmm/i18n.h> -#include "ui/tools-switch.h" -#include "ui/tools/node-tool.h" - -// needed for on-canvas editting: -#include "desktop.h" - -namespace Inkscape { - -namespace LivePathEffect { - -PointReseteableParam::PointReseteableParam( const Glib::ustring& label, const Glib::ustring& tip, - const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, - Effect* effect, const gchar *htip, Geom::Point default_value) - : Geom::Point(default_value), Parameter(label, tip, key, wr, effect), defvalue(default_value) -{ - knot_shape = SP_KNOT_SHAPE_DIAMOND; - knot_mode = SP_KNOT_MODE_XOR; - knot_color = 0xffffff00; - handle_tip = g_strdup(htip); -} - -PointReseteableParam::~PointReseteableParam() -{ - if (handle_tip) - g_free(handle_tip); -} - -void -PointReseteableParam::param_set_default() -{ - param_setValue(defvalue); -} - -void -PointReseteableParam::param_set_and_write_default() -{ - param_set_and_write_new_value(defvalue); -} - -void -PointReseteableParam::param_update_default(Geom::Point newpoint) -{ - this->defvalue = newpoint; -} - -bool -PointReseteableParam::param_readSVGValue(const gchar * strvalue) -{ - gchar ** strarray = g_strsplit(strvalue, ",", 2); - double newx, newy; - unsigned int success = sp_svg_number_read_d(strarray[0], &newx); - success += sp_svg_number_read_d(strarray[1], &newy); - g_strfreev (strarray); - if (success == 2) { - param_setValue( Geom::Point(newx, newy) ); - return true; - } - return false; -} - -gchar * -PointReseteableParam::param_getSVGValue() const -{ - Inkscape::SVGOStringStream os; - os << *dynamic_cast<Geom::Point const *>( this ); - gchar * str = g_strdup(os.str().c_str()); - return str; -} - -Gtk::Widget * -PointReseteableParam::param_newWidget() -{ - Inkscape::UI::Widget::RegisteredTransformedPoint * pointwdg = Gtk::manage( - new Inkscape::UI::Widget::RegisteredTransformedPoint( param_label, - param_tooltip, - param_key, - *param_wr, - param_effect->getRepr(), - param_effect->getSPDoc() ) ); - // TODO: fix to get correct desktop (don't use SP_ACTIVE_DESKTOP) - SPDesktop *desktop = SP_ACTIVE_DESKTOP; - Geom::Affine transf = desktop->doc2dt(); - pointwdg->setTransform(transf); - pointwdg->setValue( *this ); - pointwdg->clearProgrammatically(); - pointwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change point parameter")); - - Gtk::HBox * hbox = Gtk::manage( new Gtk::HBox() ); - static_cast<Gtk::HBox*>(hbox)->pack_start(*pointwdg, true, true); - static_cast<Gtk::HBox*>(hbox)->show_all_children(); - - return dynamic_cast<Gtk::Widget *> (hbox); -} - -void -PointReseteableParam::param_setValue(Geom::Point newpoint) -{ - *dynamic_cast<Geom::Point *>( this ) = newpoint; - if(SP_ACTIVE_DESKTOP){ - SPDesktop* desktop = SP_ACTIVE_DESKTOP; - if (tools_isactive( desktop, TOOLS_NODES)) { - Inkscape::UI::Tools::NodeTool *nt = static_cast<Inkscape::UI::Tools::NodeTool*>( desktop->event_context); - nt->update_helperpath(); - } - } -} - -void -PointReseteableParam::param_set_and_write_new_value (Geom::Point newpoint) -{ - Inkscape::SVGOStringStream os; - os << newpoint; - gchar * str = g_strdup(os.str().c_str()); - param_write_to_repr(str); - g_free(str); -} - -void -PointReseteableParam::param_transform_multiply(Geom::Affine const& postmul, bool /*set*/) -{ - param_set_and_write_new_value( (*this) * postmul ); -} - - -void -PointReseteableParam::set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color) -{ - knot_shape = shape; - knot_mode = mode; - knot_color = color; -} - -class PointReseteableParamKnotHolderEntity : public KnotHolderEntity { -public: - PointReseteableParamKnotHolderEntity(PointReseteableParam *p) { this->pparam = p; } - virtual ~PointReseteableParamKnotHolderEntity() {} - - virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); - virtual Geom::Point knot_get() const; - virtual void knot_click(guint state); - -private: - PointReseteableParam *pparam; -}; - -void -PointReseteableParamKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state) -{ - Geom::Point const s = snap_knot_position(p, state); - pparam->param_setValue(s); - sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); -} - -Geom::Point -PointReseteableParamKnotHolderEntity::knot_get() const -{ - return *pparam; -} - -void -PointReseteableParamKnotHolderEntity::knot_click(guint state) -{ - if (state & GDK_CONTROL_MASK) { - if (state & GDK_MOD1_MASK) { - this->pparam->param_set_default(); - sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); - } - } -} - -void -PointReseteableParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) -{ - PointReseteableParamKnotHolderEntity *e = new PointReseteableParamKnotHolderEntity(this); - // TODO: can we ditch handleTip() etc. because we have access to handle_tip etc. itself??? - e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, handleTip(), knot_shape, knot_mode, knot_color); - knotholder->add(e); -} - -} /* namespace LivePathEffect */ - -} /* namespace Inkscape */ - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/pointreseteable.h b/src/live_effects/parameter/pointreseteable.h deleted file mode 100644 index 5ae1fdf02..000000000 --- a/src/live_effects/parameter/pointreseteable.h +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_POINT_RESETEABLE_H -#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_POINT_RESETEABLE_H - -/* - * Inkscape::LivePathEffectParameters - * -* Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl> - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include <glib.h> -#include <2geom/point.h> - -#include "live_effects/parameter/parameter.h" - -#include "knot-holder-entity.h" - -namespace Inkscape { - -namespace LivePathEffect { - -class PointReseteableParamKnotHolderEntity; - -class PointReseteableParam : public Geom::Point, public Parameter { -public: - PointReseteableParam( const Glib::ustring& label, - const Glib::ustring& tip, - const Glib::ustring& key, - Inkscape::UI::Widget::Registry* wr, - Effect* effect, - const gchar *handle_tip = NULL, - Geom::Point default_value = Geom::Point(0,0) ); // tip for automatically associated on-canvas handle - virtual ~PointReseteableParam(); - - virtual Gtk::Widget * param_newWidget(); - - bool param_readSVGValue(const gchar * strvalue); - gchar * param_getSVGValue() const; - inline const gchar *handleTip() const { return handle_tip ? handle_tip : param_tooltip.c_str(); } - - void param_setValue(Geom::Point newpoint); - void param_set_default(); - void param_set_and_write_default(); - void param_update_default(Geom::Point newpoint); - - void param_set_and_write_new_value(Geom::Point newpoint); - - virtual void param_transform_multiply(Geom::Affine const& /*postmul*/, bool /*set*/); - - void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); - - virtual bool providesKnotHolderEntities() const { return true; } - virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); - - friend class PointReseteableParamKnotHolderEntity; -private: - PointReseteableParam(const PointReseteableParam&); - PointReseteableParam& operator=(const PointReseteableParam&); - - Geom::Point defvalue; - - SPKnotShapeType knot_shape; - SPKnotModeType knot_mode; - guint32 knot_color; - gchar *handle_tip; -}; - - -} //namespace LivePathEffect - -} //namespace Inkscape - -#endif diff --git a/src/main.cpp b/src/main.cpp index 15576109d..415118407 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -52,7 +52,7 @@ #include <glib-object.h> #include <gtk/gtk.h> -#include "gc-core.h" +#include "inkgc/gc-core.h" #ifdef AND #undef AND diff --git a/src/message-stack.h b/src/message-stack.h index 42bf4e8a7..ed0315cf5 100644 --- a/src/message-stack.h +++ b/src/message-stack.h @@ -22,7 +22,7 @@ #include <glibmm/ustring.h> #include <sigc++/sigc++.h> -#include "gc-managed.h" +#include "inkgc/gc-managed.h" #include "gc-finalized.h" #include "gc-anchored.h" #include "message.h" diff --git a/src/object-test.h b/src/object-test.h index d6a9dbbd3..06363c372 100644 --- a/src/object-test.h +++ b/src/object-test.h @@ -208,6 +208,7 @@ public: end = clock(); std::cout << "Took " << double(end - begin) / double(CLOCKS_PER_SEC) << " seconds to ungroup a <g> with " << num_elements << " elements\n"; + std::cout << " Note: sp_item_group_ungroup_handle_clones() is responsible\n for most of the time as it is linear in number of elements\n which results in quadratic behavior for ungrouping." << std::endl; begin = clock(); // Remove those elements diff --git a/src/persp3d.cpp b/src/persp3d.cpp index c761947ad..dc0975d12 100644 --- a/src/persp3d.cpp +++ b/src/persp3d.cpp @@ -34,16 +34,6 @@ static void persp3d_on_repr_attr_changed (Inkscape::XML::Node * repr, const gcha static int global_counter = 0; -#include "sp-factory.h" - -namespace { - SPObject* createPersp3D() { - return new Persp3D(); - } - - bool persp3DRegistered = SPFactory::instance().registerObject("inkscape:persp3d", createPersp3D); -} - /* Constructor/destructor for the internal class */ Persp3DImpl::Persp3DImpl() { diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index c9837aabe..5e8fd5e07 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -202,7 +202,7 @@ void SelectionHelper::selectSameStrokeColor(SPDesktop *dt) void SelectionHelper::selectSameStrokeStyle(SPDesktop *dt) { - sp_select_same_stroke_style(dt); + sp_select_same_fill_stroke_style(dt, false, false, true); } void SelectionHelper::selectSameObjectType(SPDesktop *dt) @@ -1321,6 +1321,25 @@ void sp_selection_paste_size_separately(SPDesktop *desktop, bool apply_x, bool a } } +/** + * Ensures that the clones of objects are not modified when moving objects between layers. + * Calls the same function as ungroup + */ +void sp_selection_change_layer_maintain_clones(GSList const *items,SPObject *where) +{ + for (const GSList *i = items; i != NULL; i = i->next) { + SPItem *item = dynamic_cast<SPItem *>(SP_OBJECT(i->data)); + if (item) { + SPItem *oldparent = dynamic_cast<SPItem *>(item->parent); + SPItem *newparent = dynamic_cast<SPItem *>(where); + sp_item_group_ungroup_handle_clones(item, + (oldparent->i2doc_affine()) + *((newparent->i2doc_affine()).inverse())); + } + } +} + + void sp_selection_to_next_layer(SPDesktop *dt, bool suppressDone) { Inkscape::Selection *selection = dt->getSelection(); @@ -1336,6 +1355,7 @@ void sp_selection_to_next_layer(SPDesktop *dt, bool suppressDone) bool no_more = false; // Set to true, if no more layers above SPObject *next=Inkscape::next_layer(dt->currentRoot(), dt->currentLayer()); if (next) { + sp_selection_change_layer_maintain_clones(items,next); GSList *temp_clip = NULL; sp_selection_copy_impl(items, &temp_clip, dt->doc()->getReprDoc()); sp_selection_delete_impl(items, false, false); @@ -1381,6 +1401,7 @@ void sp_selection_to_prev_layer(SPDesktop *dt, bool suppressDone) bool no_more = false; // Set to true, if no more layers below SPObject *next=Inkscape::previous_layer(dt->currentRoot(), dt->currentLayer()); if (next) { + sp_selection_change_layer_maintain_clones(items,next); GSList *temp_clip = NULL; sp_selection_copy_impl(items, &temp_clip, dt->doc()->getReprDoc()); // we're in the same doc, so no need to copy defs sp_selection_delete_impl(items, false, false); @@ -1424,6 +1445,7 @@ void sp_selection_to_layer(SPDesktop *dt, SPObject *moveto, bool suppressDone) GSList const *items = g_slist_copy(const_cast<GSList *>(selection->itemList())); if (moveto) { + sp_selection_change_layer_maintain_clones(items,moveto); GSList *temp_clip = NULL; sp_selection_copy_impl(items, &temp_clip, dt->doc()->getReprDoc()); // we're in the same doc, so no need to copy defs sp_selection_delete_impl(items, false, false); @@ -1857,16 +1879,17 @@ void sp_select_same_fill_stroke_style(SPDesktop *desktop, gboolean fill, gboolea for (GSList const* sel_iter = selection->itemList(); sel_iter; sel_iter = sel_iter->next) { SPItem *sel = dynamic_cast<SPItem *>(static_cast<SPObject *>(sel_iter->data)); GSList *matches = all_list; - if (fill) { - matches = sp_get_same_fill_or_stroke_color(sel, matches, SP_FILL_COLOR); + if (fill && stroke && style) { + matches = sp_get_same_style(sel, matches); + } + else if (fill) { + matches = sp_get_same_style(sel, matches, SP_FILL_COLOR); } - if (stroke) { - matches = sp_get_same_fill_or_stroke_color(sel, matches, SP_STROKE_COLOR); + else if (stroke) { + matches = sp_get_same_style(sel, matches, SP_STROKE_COLOR); } - if (style) { - matches = sp_get_same_stroke_style(sel, matches, SP_STROKE_STYLE_WIDTH); - matches = sp_get_same_stroke_style(sel, matches, SP_STROKE_STYLE_DASHES); - matches = sp_get_same_stroke_style(sel, matches, SP_STROKE_STYLE_MARKERS); + else if (style) { + matches = sp_get_same_style(sel, matches,SP_STROKE_STYLE_ALL); } all_matches = g_slist_concat (all_matches, matches); } @@ -1927,49 +1950,7 @@ void sp_select_same_object_type(SPDesktop *desktop) } } -/* - * Selects all the visible items with the same stroke style as the items in the current selection - * - * Params: - * desktop - set the selection on this desktop - */ -void sp_select_same_stroke_style(SPDesktop *desktop) -{ - if (!desktop) { - return; - } - - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - bool onlyvisible = prefs->getBool("/options/kbselection/onlyvisible", true); - bool onlysensitive = prefs->getBool("/options/kbselection/onlysensitive", true); - bool ingroups = TRUE; - GSList *all_list = get_all_items(NULL, desktop->currentRoot(), desktop, onlyvisible, onlysensitive, ingroups, NULL); - GSList *matches = all_list; - - Inkscape::Selection *selection = desktop->getSelection(); - - for (GSList const* sel_iter = selection->itemList(); sel_iter; sel_iter = sel_iter->next) { - SPItem *sel = dynamic_cast<SPItem *>(static_cast<SPObject *>(sel_iter->data)); - if (sel) { - matches = sp_get_same_stroke_style(sel, matches, SP_STROKE_STYLE_WIDTH); - matches = sp_get_same_stroke_style(sel, matches, SP_STROKE_STYLE_DASHES); - matches = sp_get_same_stroke_style(sel, matches, SP_STROKE_STYLE_MARKERS); - } else { - g_assert_not_reached(); - } - } - - selection->clear(); - selection->setList(matches); - - if (matches) { - g_slist_free(matches); - } - if (all_list) { - g_slist_free(all_list); - } -} /* * Find all items in src list that have the same fill or stroke style as sel @@ -2079,7 +2060,7 @@ GSList *sp_get_same_object_type(SPItem *sel, GSList *src) for (GSList *i = src; i != NULL; i = i->next) { SPItem *item = dynamic_cast<SPItem *>(static_cast<SPObject *>(i->data)); - if (item && item_type_match(sel, item)) { + if (item && item_type_match(sel, item) && !item->cloned) { matches = g_slist_prepend (matches, item); } } @@ -2087,19 +2068,24 @@ GSList *sp_get_same_object_type(SPItem *sel, GSList *src) return matches; } +GSList *sp_get_same_fill_or_stroke_color(SPItem *sel, GSList *src, SPSelectStrokeStyleType type); + /* * Find all items in src list that have the same stroke style as sel by type * Return the list of matching items */ -GSList *sp_get_same_stroke_style(SPItem *sel, GSList *src, SPSelectStrokeStyleType type) +GSList *sp_get_same_style(SPItem *sel, GSList *src, SPSelectStrokeStyleType type) { GSList *matches = NULL; - gboolean match = false; + bool match = false; SPStyle *sel_style = sel->style; - if (type == SP_FILL_COLOR || type == SP_STROKE_COLOR) { - return sp_get_same_fill_or_stroke_color(sel, src, type); + if (type == SP_FILL_COLOR || type == SP_STYLE_ALL) { + src = sp_get_same_fill_or_stroke_color(sel, src, SP_FILL_COLOR); + } + if (type == SP_STROKE_COLOR || type == SP_STYLE_ALL) { + src = sp_get_same_fill_or_stroke_color(sel, src, SP_STROKE_COLOR); } /* @@ -2108,19 +2094,20 @@ GSList *sp_get_same_stroke_style(SPItem *sel, GSList *src, SPSelectStrokeStyleTy */ GSList *objects = NULL; SPStyle *sel_style_for_width = NULL; - if (type == SP_STROKE_STYLE_WIDTH) { + if (type == SP_STROKE_STYLE_WIDTH || type == SP_STROKE_STYLE_ALL || type==SP_STYLE_ALL ) { objects = g_slist_prepend(objects, sel); sel_style_for_width = new SPStyle(SP_ACTIVE_DOCUMENT); objects_query_strokewidth (objects, sel_style_for_width); } - + bool match_g; for (GSList *i = src; i != NULL; i = i->next) { SPItem *iter = dynamic_cast<SPItem *>(static_cast<SPObject *>(i->data)); if (iter) { + match_g=true; SPStyle *iter_style = iter->style; - match = false; + match = true; - if (type == SP_STROKE_STYLE_WIDTH) { + if (type == SP_STROKE_STYLE_WIDTH|| type == SP_STROKE_STYLE_ALL|| type==SP_STYLE_ALL) { match = (sel_style->stroke_width.set == iter_style->stroke_width.set); if (sel_style->stroke_width.set && iter_style->stroke_width.set) { GSList *objects = NULL; @@ -2134,13 +2121,15 @@ GSList *sp_get_same_stroke_style(SPItem *sel, GSList *src, SPSelectStrokeStyleTy g_slist_free(objects); } } - else if (type == SP_STROKE_STYLE_DASHES ) { + match_g = match_g && match; + if (type == SP_STROKE_STYLE_DASHES|| type == SP_STROKE_STYLE_ALL || type==SP_STYLE_ALL) { match = (sel_style->stroke_dasharray.set == iter_style->stroke_dasharray.set); if (sel_style->stroke_dasharray.set && iter_style->stroke_dasharray.set) { match = (sel_style->stroke_dasharray.values == iter_style->stroke_dasharray.values); } } - else if (type == SP_STROKE_STYLE_MARKERS) { + match_g = match_g && match; + if (type == SP_STROKE_STYLE_MARKERS|| type == SP_STROKE_STYLE_ALL|| type==SP_STYLE_ALL) { match = true; int len = sizeof(sel_style->marker)/sizeof(SPIString); for (int i = 0; i < len; i++) { @@ -2152,8 +2141,9 @@ GSList *sp_get_same_stroke_style(SPItem *sel, GSList *src, SPSelectStrokeStyleTy } } } - - if (match) { + match_g = match_g && match; + if (match_g) { + while (iter->cloned) iter=dynamic_cast<SPItem *>(iter->parent); matches = g_slist_prepend(matches, iter); } } else { diff --git a/src/selection-chemistry.h b/src/selection-chemistry.h index d86906548..4ee7a5200 100644 --- a/src/selection-chemistry.h +++ b/src/selection-chemistry.h @@ -136,14 +136,14 @@ enum SPSelectStrokeStyleType { SP_STROKE_COLOR = 1, SP_STROKE_STYLE_WIDTH = 2, SP_STROKE_STYLE_DASHES = 3, - SP_STROKE_STYLE_MARKERS = 4 + SP_STROKE_STYLE_MARKERS = 4, + SP_STROKE_STYLE_ALL = 5, + SP_STYLE_ALL = 6 }; void sp_select_same_fill_stroke_style(SPDesktop *desktop, gboolean fill, gboolean strok, gboolean style); -void sp_select_same_stroke_style(SPDesktop *desktop); void sp_select_same_object_type(SPDesktop *desktop); -GSList *sp_get_same_fill_or_stroke_color(SPItem *sel, GSList *src, SPSelectStrokeStyleType type); -GSList *sp_get_same_stroke_style(SPItem *sel, GSList *src, SPSelectStrokeStyleType type); +GSList *sp_get_same_style(SPItem *sel, GSList *src, SPSelectStrokeStyleType type=SP_STYLE_ALL); GSList *sp_get_same_object_type(SPItem *sel, GSList *src); void scroll_to_show_item(SPDesktop *desktop, SPItem *item); diff --git a/src/selection-describer.cpp b/src/selection-describer.cpp index f7814fd57..2386a731e 100644 --- a/src/selection-describer.cpp +++ b/src/selection-describer.cpp @@ -233,8 +233,8 @@ void SelectionDescriber::_updateMessageFromSelection(Inkscape::Selection *select int n_terms = count_terms((GSList *)items); gchar *objects_str = g_strdup_printf(ngettext( - "<b>%i</b> objects selected of type %s", - "<b>%i</b> objects selected of types %s", n_terms), + "<b>%1$i</b> objects selected of type %2$s", + "<b>%1$i</b> objects selected of types %2$s", n_terms), objcount, terms); g_free(terms); diff --git a/src/selection.h b/src/selection.h index 5964b20e8..19e2ae1fd 100644 --- a/src/selection.h +++ b/src/selection.h @@ -19,10 +19,10 @@ #include <stddef.h> #include <sigc++/sigc++.h> -#include "gc-managed.h" +#include "inkgc/gc-managed.h" #include "gc-finalized.h" #include "gc-anchored.h" -#include "gc-soft-ptr.h" +#include "inkgc/gc-soft-ptr.h" #include "sp-item.h" diff --git a/src/snap.cpp b/src/snap.cpp index 8138e4546..96b5ab53c 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -33,7 +33,7 @@ #include "sp-guide.h" #include "preferences.h" #include "ui/tools/tool-base.h" -#include "util/mathfns.h" +#include "helper/mathfns.h" using std::vector; using Inkscape::Util::round_to_upper_multiple_plus; using Inkscape::Util::round_to_lower_multiple_plus; diff --git a/src/sp-anchor.cpp b/src/sp-anchor.cpp index 7b558bf08..78ba10c13 100644 --- a/src/sp-anchor.cpp +++ b/src/sp-anchor.cpp @@ -13,10 +13,6 @@ #define noSP_ANCHOR_VERBOSE -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include <glibmm/i18n.h> #include "xml/quote.h" #include "xml/repr.h" @@ -25,16 +21,6 @@ #include "ui/view/view.h" #include "document.h" -#include "sp-factory.h" - -namespace { - SPObject* createAnchor() { - return new SPAnchor(); - } - - bool anchorRegistered = SPFactory::instance().registerObject("svg:a", createAnchor); -} - SPAnchor::SPAnchor() : SPGroup() { this->href = NULL; } diff --git a/src/sp-clippath.cpp b/src/sp-clippath.cpp index 5065f25c3..3c6167438 100644 --- a/src/sp-clippath.cpp +++ b/src/sp-clippath.cpp @@ -40,16 +40,6 @@ struct SPClipPathView { static SPClipPathView* sp_clippath_view_new_prepend(SPClipPathView *list, unsigned int key, Inkscape::DrawingItem *arenaitem); static SPClipPathView* sp_clippath_view_list_remove(SPClipPathView *list, SPClipPathView *view); -#include "sp-factory.h" - -namespace { - SPObject* createClipPath() { - return new SPClipPath(); - } - - bool clipPathRegistered = SPFactory::instance().registerObject("svg:clipPath", createClipPath); -} - SPClipPath::SPClipPath() : SPObjectGroup() { this->clipPathUnits_set = FALSE; this->clipPathUnits = SP_CONTENT_UNITS_USERSPACEONUSE; diff --git a/src/sp-defs.cpp b/src/sp-defs.cpp index 334570076..8dd695867 100644 --- a/src/sp-defs.cpp +++ b/src/sp-defs.cpp @@ -20,16 +20,6 @@ #include "xml/repr.h" #include "document.h" -#include "sp-factory.h" - -namespace { - SPObject* createDefs() { - return new SPDefs(); - } - - bool defsRegistered = SPFactory::instance().registerObject("svg:defs", createDefs); -} - SPDefs::SPDefs() : SPObject() { } diff --git a/src/sp-desc.cpp b/src/sp-desc.cpp index 199ae0176..3c75d087a 100644 --- a/src/sp-desc.cpp +++ b/src/sp-desc.cpp @@ -9,23 +9,9 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include "sp-desc.h" #include "xml/repr.h" -#include "sp-factory.h" - -namespace { - SPObject* createDesc() { - return new SPDesc(); - } - - bool descRegistered = SPFactory::instance().registerObject("svg:desc", createDesc); -} - SPDesc::SPDesc() : SPObject() { } diff --git a/src/sp-ellipse.cpp b/src/sp-ellipse.cpp index a74d4687d..932a3a1b7 100644 --- a/src/sp-ellipse.cpp +++ b/src/sp-ellipse.cpp @@ -34,35 +34,6 @@ #include "svg/path-string.h" #include "xml/repr.h" -#include "sp-factory.h" - -namespace { -SPObject *create_ellipse() -{ - SPGenericEllipse *ellipse = new SPGenericEllipse(); - ellipse->type = SP_GENERIC_ELLIPSE_ELLIPSE; - return ellipse; -} - -SPObject *create_circle() -{ - SPGenericEllipse *circle = new SPGenericEllipse(); - circle->type = SP_GENERIC_ELLIPSE_CIRCLE; - return circle; -} - -SPObject *create_arc() -{ - SPGenericEllipse *arc = new SPGenericEllipse(); - arc->type = SP_GENERIC_ELLIPSE_ARC; - return arc; -} - -bool ellipse_registered = SPFactory::instance().registerObject("svg:ellipse", create_ellipse); -bool circle_registered = SPFactory::instance().registerObject("svg:circle", create_circle); -bool arc_registered = SPFactory::instance().registerObject("arc", create_arc); -} - #ifndef M_PI #define M_PI 3.14159265358979323846 @@ -124,6 +95,10 @@ void SPGenericEllipse::build(SPDocument *document, Inkscape::XML::Node *repr) std::cerr << "SPGenericEllipse::build() unknown defined type." << std::endl; } + // std::cout << " cx: " << cx.write() << std::endl; + // std::cout << " cy: " << cy.write() << std::endl; + // std::cout << " rx: " << rx.write() << std::endl; + // std::cout << " ry: " << ry.write() << std::endl; SPShape::build(document, repr); } @@ -132,29 +107,41 @@ void SPGenericEllipse::set(unsigned int key, gchar const *value) // There are multiple ways to set internal cx, cy, rx, and ry (via SVG attributes or Sodipodi // attributes) thus we don't want to unset them if a read fails (e.g., when we explicitly clear // an attribute by setting it to NULL). + + // We must update the SVGLengths immediately or nodes may be misplaced after they are moved. + double const w = viewport.width(); + double const h = viewport.height(); + double const d = hypot(w, h) / sqrt(2); // diagonal + double const em = style->font_size.computed; + double const ex = em * 0.5; + SVGLength t; switch (key) { case SP_ATTR_CX: case SP_ATTR_SODIPODI_CX: if( t.read(value) ) cx = t; + cx.update( em, ex, w ); this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; case SP_ATTR_CY: case SP_ATTR_SODIPODI_CY: if( t.read(value) ) cy = t; + cy.update( em, ex, h ); this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; case SP_ATTR_RX: case SP_ATTR_SODIPODI_RX: - if( t.read(value) && t.value > 0.0 ) this->rx = t; + if( t.read(value) && t.value > 0.0 ) rx = t; + rx.update( em, ex, w ); this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; case SP_ATTR_RY: case SP_ATTR_SODIPODI_RY: - if( t.read(value) && t.value > 0.0 ) this->ry = t; + if( t.read(value) && t.value > 0.0 ) ry = t; + ry.update( em, ex, h ); this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; @@ -162,6 +149,8 @@ void SPGenericEllipse::set(unsigned int key, gchar const *value) if( t.read(value) && t.value > 0.0 ) { this->ry = this->rx = t; } + rx.update( em, ex, d ); + ry.update( em, ex, d ); this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; @@ -225,7 +214,7 @@ Inkscape::XML::Node *SPGenericEllipse::write(Inkscape::XML::Document *xml_doc, I // << ")" << std::endl; GenericEllipseType new_type = SP_GENERIC_ELLIPSE_UNDEFINED; - if (this->_isSlice() || hasPathEffect() ) { + if (_isSlice() || hasPathEffect() ) { new_type = SP_GENERIC_ELLIPSE_ARC; } else if ( rx.computed == ry.computed ) { new_type = SP_GENERIC_ELLIPSE_CIRCLE; @@ -275,10 +264,10 @@ Inkscape::XML::Node *SPGenericEllipse::write(Inkscape::XML::Document *xml_doc, I } // std::cout << " type: " << g_quark_to_string( repr->code() ) << std::endl; - // std::cout << " cx: " << cx.computed - // << " cy: " << cy.computed - // << " rx: " << rx.computed - // << " ry: " << ry.computed << std::endl; + // std::cout << " cx: " << cx.write() << " " << cx.computed + // << " cy: " << cy.write() << " " << cy.computed + // << " rx: " << rx.write() << " " << rx.computed + // << " ry: " << ry.write() << " " << ry.computed << std::endl; switch ( type ) { case SP_GENERIC_ELLIPSE_UNDEFINED: @@ -293,17 +282,17 @@ Inkscape::XML::Node *SPGenericEllipse::write(Inkscape::XML::Document *xml_doc, I if (flags & SP_OBJECT_WRITE_EXT) { repr->setAttribute("sodipodi:type", "arc"); - sp_repr_set_svg_double(repr, "sodipodi:cx", this->cx.computed); - sp_repr_set_svg_double(repr, "sodipodi:cy", this->cy.computed); - sp_repr_set_svg_double(repr, "sodipodi:rx", this->rx.computed); - sp_repr_set_svg_double(repr, "sodipodi:ry", this->ry.computed); + sp_repr_set_svg_length(repr, "sodipodi:cx", cx); + sp_repr_set_svg_length(repr, "sodipodi:cy", cy); + sp_repr_set_svg_length(repr, "sodipodi:rx", rx); + sp_repr_set_svg_length(repr, "sodipodi:ry", ry); // write start and end only if they are non-trivial; otherwise remove - if (this->_isSlice()) { - sp_repr_set_svg_double(repr, "sodipodi:start", this->start); - sp_repr_set_svg_double(repr, "sodipodi:end", this->end); + if (_isSlice()) { + sp_repr_set_svg_double(repr, "sodipodi:start", start); + sp_repr_set_svg_double(repr, "sodipodi:end", end); - repr->setAttribute("sodipodi:open", (!this->_closed) ? "true" : NULL); + repr->setAttribute("sodipodi:open", (!_closed) ? "true" : NULL); } else { repr->setAttribute("sodipodi:end", NULL); repr->setAttribute("sodipodi:start", NULL); @@ -312,13 +301,13 @@ Inkscape::XML::Node *SPGenericEllipse::write(Inkscape::XML::Document *xml_doc, I } // write d= - this->set_elliptical_path_attribute(repr); + set_elliptical_path_attribute(repr); break; case SP_GENERIC_ELLIPSE_CIRCLE: - sp_repr_set_svg_double(repr, "cx", this->cx.computed); - sp_repr_set_svg_double(repr, "cy", this->cy.computed); - sp_repr_set_svg_double(repr, "r", this->rx.computed); + sp_repr_set_svg_length(repr, "cx", cx); + sp_repr_set_svg_length(repr, "cy", cy); + sp_repr_set_svg_length(repr, "r", rx); repr->setAttribute("rx", NULL ); repr->setAttribute("ry", NULL ); repr->setAttribute("sodipodi:cx", NULL ); @@ -333,10 +322,10 @@ Inkscape::XML::Node *SPGenericEllipse::write(Inkscape::XML::Document *xml_doc, I break; case SP_GENERIC_ELLIPSE_ELLIPSE: - sp_repr_set_svg_double(repr, "cx", this->cx.computed); - sp_repr_set_svg_double(repr, "cy", this->cy.computed); - sp_repr_set_svg_double(repr, "rx", this->rx.computed); - sp_repr_set_svg_double(repr, "ry", this->ry.computed); + sp_repr_set_svg_length(repr, "cx", cx); + sp_repr_set_svg_length(repr, "cy", cy); + sp_repr_set_svg_length(repr, "rx", rx); + sp_repr_set_svg_length(repr, "ry", ry); repr->setAttribute("r", NULL ); repr->setAttribute("sodipodi:cx", NULL ); repr->setAttribute("sodipodi:cy", NULL ); @@ -353,11 +342,10 @@ Inkscape::XML::Node *SPGenericEllipse::write(Inkscape::XML::Document *xml_doc, I std::cerr << "SPGenericEllipse::write: unknown type." << std::endl; } - this->set_shape(); // evaluate SPCurve + set_shape(); // evaluate SPCurve SPShape::write(xml_doc, repr, flags); - // std::cout << "SPGenericEllipse::write: Exit: " << g_quark_to_string(repr->code()) << "\n" << std::endl; return repr; } @@ -368,8 +356,8 @@ const char *SPGenericEllipse::displayName() const case SP_GENERIC_ELLIPSE_UNDEFINED: case SP_GENERIC_ELLIPSE_ARC: - if (this->_isSlice()) { - if (this->_closed) { + if (_isSlice()) { + if (_closed) { return _("Segment"); } else { return _("Arc"); @@ -509,11 +497,11 @@ Geom::Affine SPGenericEllipse::set_transform(Geom::Affine const &xform) } if (this->rx._set) { - this->rx = this->rx.computed * sw; + this->rx.scale( sw ); } if (this->ry._set) { - this->ry = this->ry.computed * sh; + this->ry.scale( sh ); } /* Find start in item coords */ @@ -657,10 +645,10 @@ bool SPGenericEllipse::set_elliptical_path_attribute(Inkscape::XML::Node *repr) void SPGenericEllipse::position_set(gdouble x, gdouble y, gdouble rx, gdouble ry) { - this->cx.computed = x; - this->cy.computed = y; - this->rx.computed = rx; - this->ry.computed = ry; + this->cx = x; + this->cy = y; + this->rx = rx; + this->ry = ry; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); diff --git a/src/sp-factory.cpp b/src/sp-factory.cpp new file mode 100644 index 000000000..e48646f8d --- /dev/null +++ b/src/sp-factory.cpp @@ -0,0 +1,337 @@ +/* + * Factory for SPObject tree + * + * Authors: + * Markus Engel + * + * Copyright (C) 2013 Authors + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "sp-factory.h" + +// primary +#include "box3d.h" +#include "box3d-side.h" +#include "color-profile.h" +#include "persp3d.h" +#include "sp-anchor.h" +#include "sp-clippath.h" +#include "sp-defs.h" +#include "sp-desc.h" +#include "sp-ellipse.h" +#include "sp-filter.h" +#include "sp-flowdiv.h" +#include "sp-flowregion.h" +#include "sp-flowtext.h" +#include "sp-font.h" +#include "sp-font-face.h" +#include "sp-glyph.h" +#include "sp-guide.h" +#include "sp-hatch.h" +#include "sp-hatch-path.h" +#include "sp-image.h" +#include "sp-item-group.h" +#include "sp-line.h" +#include "sp-linear-gradient.h" +#include "sp-marker.h" +#include "sp-mask.h" +#include "sp-mesh.h" +#include "sp-mesh-patch.h" +#include "sp-mesh-row.h" +#include "sp-metadata.h" +#include "sp-missing-glyph.h" +#include "sp-namedview.h" +#include "sp-object.h" +#include "sp-offset.h" +#include "sp-path.h" +#include "sp-pattern.h" +#include "sp-polygon.h" +#include "sp-polyline.h" +#include "sp-radial-gradient.h" +#include "sp-rect.h" +#include "sp-root.h" +#include "sp-script.h" +#include "sp-solid-color.h" +#include "sp-spiral.h" +#include "sp-star.h" +#include "sp-stop.h" +#include "sp-string.h" +#include "sp-style-elem.h" +#include "sp-switch.h" +#include "sp-symbol.h" +#include "sp-tag.h" +#include "sp-tag-use.h" +#include "sp-text.h" +#include "sp-textpath.h" +#include "sp-title.h" +#include "sp-tref.h" +#include "sp-tspan.h" +#include "sp-use.h" +#include "live_effects/lpeobject.h" + +// filters +#include "filters/blend.h" +#include "filters/colormatrix.h" +#include "filters/componenttransfer.h" +#include "filters/componenttransfer-funcnode.h" +#include "filters/composite.h" +#include "filters/convolvematrix.h" +#include "filters/diffuselighting.h" +#include "filters/displacementmap.h" +#include "filters/distantlight.h" +#include "filters/flood.h" +#include "filters/gaussian-blur.h" +#include "filters/image.h" +#include "filters/merge.h" +#include "filters/mergenode.h" +#include "filters/morphology.h" +#include "filters/offset.h" +#include "filters/pointlight.h" +#include "filters/specularlighting.h" +#include "filters/spotlight.h" +#include "filters/tile.h" +#include "filters/turbulence.h" + +SPObject *SPFactory::createObject(std::string const& id) +{ + SPObject *ret = NULL; + + if (id == "inkscape:box3d") + ret = new SPBox3D; + else if (id == "inkscape:box3dside") + ret = new Box3DSide; + else if (id == "svg:color-profile") + ret = new Inkscape::ColorProfile; + else if (id == "inkscape:persp3d") + ret = new Persp3D; + else if (id == "svg:a") + ret = new SPAnchor; + else if (id == "svg:clipPath") + ret = new SPClipPath; + else if (id == "svg:defs") + ret = new SPDefs; + else if (id == "svg:desc") + ret = new SPDesc; + else if (id == "svg:ellipse") { + SPGenericEllipse *e = new SPGenericEllipse; + e->type = SP_GENERIC_ELLIPSE_ELLIPSE; + ret = e; + } else if (id == "svg:circle") { + SPGenericEllipse *c = new SPGenericEllipse; + c->type = SP_GENERIC_ELLIPSE_CIRCLE; + ret = c; + } else if (id == "arc") { + SPGenericEllipse *a = new SPGenericEllipse; + a->type = SP_GENERIC_ELLIPSE_ARC; + ret = a; + } + else if (id == "svg:filter") + ret = new SPFilter; + else if (id == "svg:flowDiv") + ret = new SPFlowdiv; + else if (id == "svg:flowSpan") + ret = new SPFlowtspan; + else if (id == "svg:flowPara") + ret = new SPFlowpara; + else if (id == "svg:flowLine") + ret = new SPFlowline; + else if (id == "svg:flowRegionBreak") + ret = new SPFlowregionbreak; + else if (id == "svg:flowRegion") + ret = new SPFlowregion; + else if (id == "svg:flowRegionExclude") + ret = new SPFlowregionExclude; + else if (id == "svg:flowRoot") + ret = new SPFlowtext; + else if (id == "svg:font") + ret = new SPFont; + else if (id == "svg:font-face") + ret = new SPFontFace; + else if (id == "svg:glyph") + ret = new SPGlyph; + else if (id == "sodipodi:guide") + ret = new SPGuide; + else if (id == "svg:hatch") + ret = new SPHatch; + else if (id == "svg:hatchPath") + ret = new SPHatchPath; + else if (id == "svg:image") + ret = new SPImage; + else if (id == "svg:g") + ret = new SPGroup; + else if (id == "svg:line") + ret = new SPLine; + else if (id == "svg:linearGradient") + ret = new SPLinearGradient; + else if (id == "svg:marker") + ret = new SPMarker; + else if (id == "svg:mask") + ret = new SPMask; + else if (id == "svg:mesh") + ret = new SPMesh; + else if (id == "svg:meshpatch") + ret = new SPMeshpatch; + else if (id == "svg:meshrow") + ret = new SPMeshrow; + else if (id == "svg:metadata") + ret = new SPMetadata; + else if (id == "svg:missing-glyph") + ret = new SPMissingGlyph; + else if (id == "sodipodi:namedview") + ret = new SPNamedView; + else if (id == "inkscape:offset") + ret = new SPOffset; + else if (id == "svg:path") + ret = new SPPath; + else if (id == "svg:pattern") + ret = new SPPattern; + else if (id == "svg:polygon") + ret = new SPPolygon; + else if (id == "svg:polyline") + ret = new SPPolyLine; + else if (id == "svg:radialGradient") + ret = new SPRadialGradient; + else if (id == "svg:rect") + ret = new SPRect; + else if (id == "svg:svg") + ret = new SPRoot; + else if (id == "svg:script") + ret = new SPScript; + else if (id == "svg:solidColor") + ret = new SPSolidColor; + else if (id == "spiral") + ret = new SPSpiral; + else if (id == "star") + ret = new SPStar; + else if (id == "svg:stop") + ret = new SPStop; + else if (id == "string") + ret = new SPString; + else if (id == "svg:style") + ret = new SPStyleElem; + else if (id == "svg:switch") + ret = new SPSwitch; + else if (id == "svg:symbol") + ret = new SPSymbol; + else if (id == "inkscape:tag") + ret = new SPTag; + else if (id == "inkscape:tagref") + ret = new SPTagUse; + else if (id == "svg:text") + ret = new SPText; + else if (id == "svg:title") + ret = new SPTitle; + else if (id == "svg:tref") + ret = new SPTRef; + else if (id == "svg:tspan") + ret = new SPTSpan; + else if (id == "svg:textPath") + ret = new SPTextPath; + else if (id == "svg:use") + ret = new SPUse; + else if (id == "inkscape:path-effect") + ret = new LivePathEffectObject; + + + // filters + else if (id == "svg:feBlend") + ret = new SPFeBlend; + else if (id == "svg:feColorMatrix") + ret = new SPFeColorMatrix; + else if (id == "svg:feComponentTransfer") + ret = new SPFeComponentTransfer; + else if (id == "svg:feFuncR") + ret = new SPFeFuncNode(SPFeFuncNode::R); + else if (id == "svg:feFuncG") + ret = new SPFeFuncNode(SPFeFuncNode::G); + else if (id == "svg:feFuncB") + ret = new SPFeFuncNode(SPFeFuncNode::B); + else if (id == "svg:feFuncA") + ret = new SPFeFuncNode(SPFeFuncNode::A); + else if (id == "svg:feComposite") + ret = new SPFeComposite; + else if (id == "svg:feConvolveMatrix") + ret = new SPFeConvolveMatrix; + else if (id == "svg:feDiffuseLighting") + ret = new SPFeDiffuseLighting; + else if (id == "svg:feDisplacementMap") + ret = new SPFeDisplacementMap; + else if (id == "svg:feDistantLight") + ret = new SPFeDistantLight; + else if (id == "svg:feFlood") + ret = new SPFeFlood; + else if (id == "svg:feGaussianBlur") + ret = new SPGaussianBlur; + else if (id == "svg:feImage") + ret = new SPFeImage; + else if (id == "svg:feMerge") + ret = new SPFeMerge; + else if (id == "svg:feMergeNode") + ret = new SPFeMergeNode; + else if (id == "svg:feMorphology") + ret = new SPFeMorphology; + else if (id == "svg:feOffset") + ret = new SPFeOffset; + else if (id == "svg:fePointLight") + ret = new SPFePointLight; + else if (id == "svg:feSpecularLighting") + ret = new SPFeSpecularLighting; + else if (id == "svg:feSpotLight") + ret = new SPFeSpotLight; + else if (id == "svg:feTile") + ret = new SPFeTile; + else if (id == "svg:feTurbulence") + ret = new SPFeTurbulence; + else if (id == "inkscape:grid") + ret = new SPObject; // TODO wtf + else if (id == "rdf:RDF") // no SP node yet + {} + else if (id == "inkscape:clipboard") // SP node not necessary + {} + else if (id.empty()) // comments + {} + else { + fprintf(stderr, "WARNING: unknown type: %s", id.c_str()); + } + + return ret; +} + +std::string NodeTraits::get_type_string(Inkscape::XML::Node const &node) +{ + std::string name; + + switch (node.type()) { + case Inkscape::XML::TEXT_NODE: + name = "string"; + break; + + case Inkscape::XML::ELEMENT_NODE: { + char const *const sptype = node.attribute("sodipodi:type"); + + if (sptype) { + name = sptype; + } else { + name = node.name(); + } + break; + } + default: + name = ""; + break; + } + + return name; +} + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/sp-factory.h b/src/sp-factory.h index 0621f77ba..040fd14ae 100644 --- a/src/sp-factory.h +++ b/src/sp-factory.h @@ -1,6 +1,6 @@ -/** @file +/* * Factory for SPObject tree - *//* + * * Authors: * Markus Engel * @@ -11,11 +11,23 @@ #ifndef SP_FACTORY_SEEN #define SP_FACTORY_SEEN -#include "factory.h" +#include <string> class SPObject; -typedef Singleton< Factory<SPObject> > SPFactory; +namespace Inkscape { +namespace XML { +class Node; +} +} + +struct SPFactory { + static SPObject *createObject(std::string const& id); +}; + +struct NodeTraits { + static std::string get_type_string(Inkscape::XML::Node const &node); +}; #endif diff --git a/src/sp-filter.cpp b/src/sp-filter.cpp index 9cb33a6f3..a70fbd5bb 100644 --- a/src/sp-filter.cpp +++ b/src/sp-filter.cpp @@ -41,15 +41,6 @@ using std::pair; static void filter_ref_changed(SPObject *old_ref, SPObject *ref, SPFilter *filter); static void filter_ref_modified(SPObject *href, guint flags, SPFilter *filter); -#include "sp-factory.h" - -namespace { - SPObject* createFilter() { - return new SPFilter(); - } - - bool filterRegistered = SPFactory::instance().registerObject("svg:filter", createFilter); -} SPFilter::SPFilter() : SPObject(), filterUnits(SP_FILTER_UNITS_OBJECTBOUNDINGBOX), filterUnits_set(FALSE), diff --git a/src/sp-flowdiv.cpp b/src/sp-flowdiv.cpp index 00ba48b06..8d9c51ab8 100644 --- a/src/sp-flowdiv.cpp +++ b/src/sp-flowdiv.cpp @@ -1,45 +1,11 @@ /* */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include "xml/repr.h" #include "sp-flowdiv.h" #include "sp-string.h" #include "document.h" -#include "sp-factory.h" - -namespace { - SPObject* createFlowdiv() { - return new SPFlowdiv(); - } - - SPObject* createFlowtspan() { - return new SPFlowtspan(); - } - - SPObject* createFlowpara() { - return new SPFlowpara(); - } - - SPObject* createFlowline() { - return new SPFlowline(); - } - - SPObject* createFlowregionbreak() { - return new SPFlowregionbreak(); - } - - bool flowdivRegistered = SPFactory::instance().registerObject("svg:flowDiv", createFlowdiv); - bool flowtspanRegistered = SPFactory::instance().registerObject("svg:flowSpan", createFlowtspan); - bool flowparaRegistered = SPFactory::instance().registerObject("svg:flowPara", createFlowpara); - bool flowlineRegistered = SPFactory::instance().registerObject("svg:flowLine", createFlowline); - bool flowregionbreakRegistered = SPFactory::instance().registerObject("svg:flowRegionBreak", createFlowregionbreak); -} - SPFlowdiv::SPFlowdiv() : SPItem() { } diff --git a/src/sp-flowregion.cpp b/src/sp-flowregion.cpp index 580945d74..5715e5eb1 100644 --- a/src/sp-flowregion.cpp +++ b/src/sp-flowregion.cpp @@ -23,20 +23,6 @@ #include "livarot/Path.h" #include "livarot/Shape.h" -#include "sp-factory.h" - -namespace { - SPObject* createFlowregion() { - return new SPFlowregion(); - } - - SPObject* createFlowregionExclude() { - return new SPFlowregionExclude(); - } - - bool flowregionRegistered = SPFactory::instance().registerObject("svg:flowRegion", createFlowregion); - bool flowregionExcludeRegistered = SPFactory::instance().registerObject("svg:flowRegionExclude", createFlowregionExclude); -} static void GetDest(SPObject* child,Shape **computed); diff --git a/src/sp-flowtext.cpp b/src/sp-flowtext.cpp index 6d2385aff..cac3cc61d 100644 --- a/src/sp-flowtext.cpp +++ b/src/sp-flowtext.cpp @@ -34,16 +34,6 @@ #include "display/drawing-text.h" -#include "sp-factory.h" - -namespace { - SPObject* createFlowtext() { - return new SPFlowtext(); - } - - bool flowtextRegistered = SPFactory::instance().registerObject("svg:flowRoot", createFlowtext); -} - SPFlowtext::SPFlowtext() : SPItem() { this->par_indent = 0; } diff --git a/src/sp-font-face.cpp b/src/sp-font-face.cpp index 9782f0c83..afd2a9dee 100644 --- a/src/sp-font-face.cpp +++ b/src/sp-font-face.cpp @@ -259,16 +259,6 @@ static std::vector<FontFaceStretchType> sp_read_fontFaceStretchType(gchar const return v; } -#include "sp-factory.h" - -namespace { - SPObject* createFontFace() { - return new SPFontFace(); - } - - bool fontFaceRegistered = SPFactory::instance().registerObject("svg:font-face", createFontFace); -} - SPFontFace::SPFontFace() : SPObject() { std::vector<FontFaceStyleType> style; style.push_back(SP_FONTFACE_STYLE_ALL); diff --git a/src/sp-font.cpp b/src/sp-font.cpp index 62cf521d3..341a6159f 100644 --- a/src/sp-font.cpp +++ b/src/sp-font.cpp @@ -23,15 +23,6 @@ #include "display/nr-svgfonts.h" -#include "sp-factory.h" - -namespace { - SPObject* createFont() { - return new SPFont(); - } - - bool fontRegistered = SPFactory::instance().registerObject("svg:font", createFont); -} //I think we should have extra stuff here and in the set method in order to set default value as specified at http://www.w3.org/TR/SVG/fonts.html diff --git a/src/sp-glyph.cpp b/src/sp-glyph.cpp index eaa69d486..4829aae51 100644 --- a/src/sp-glyph.cpp +++ b/src/sp-glyph.cpp @@ -20,15 +20,6 @@ #include "document.h" #include <cstring> -#include "sp-factory.h" - -namespace { - SPObject* createGlyph() { - return new SPGlyph(); - } - bool glyphRegistered = SPFactory::instance().registerObject("svg:glyph", createGlyph); -} - SPGlyph::SPGlyph() : SPObject() //TODO: correct these values: diff --git a/src/sp-gradient.cpp b/src/sp-gradient.cpp index b3e885560..854d53dc4 100644 --- a/src/sp-gradient.cpp +++ b/src/sp-gradient.cpp @@ -1,6 +1,6 @@ /** \file * SPGradient, SPStop, SPLinearGradient, SPRadialGradient, - * SPMeshGradient, SPMeshRow, SPMeshPatch + * SPMesh, SPMeshRow, SPMeshPatch */ /* * Authors: @@ -44,7 +44,7 @@ #include "sp-gradient-reference.h" #include "sp-linear-gradient.h" #include "sp-radial-gradient.h" -#include "sp-mesh-gradient.h" +#include "sp-mesh.h" #include "sp-mesh-row.h" #include "sp-mesh-patch.h" #include "sp-stop.h" @@ -121,7 +121,7 @@ bool SPGradient::isEquivalent(SPGradient *that) else if ( (SP_IS_LINEARGRADIENT(this) && SP_IS_LINEARGRADIENT(that)) || (SP_IS_RADIALGRADIENT(this) && SP_IS_RADIALGRADIENT(that)) || - (SP_IS_MESHGRADIENT(this) && SP_IS_MESHGRADIENT(that))) { + (SP_IS_MESH(this) && SP_IS_MESH(that))) { if(!this->isAligned(that))break; } else { break; } // this should never happen, some unhandled type of gradient @@ -206,9 +206,9 @@ bool SPGradient::isAligned(SPGradient *that) (sg->fy.computed != tg->fy.computed) ) { break; } } else if( sg->cx._set || sg->cy._set || sg->fx._set || sg->fy._set || sg->r._set ) { break; } // some mix of set and not set // none set? assume aligned and fall through - } else if (SP_IS_MESHGRADIENT(this) && SP_IS_MESHGRADIENT(that)) { - SPMeshGradient *sg=SP_MESHGRADIENT(this); - SPMeshGradient *tg=SP_MESHGRADIENT(that); + } else if (SP_IS_MESH(this) && SP_IS_MESH(that)) { + SPMesh *sg=SP_MESH(this); + SPMesh *tg=SP_MESH(that); if( sg->x._set != !tg->x._set) { break; } if( sg->y._set != !tg->y._set) { break; } @@ -508,9 +508,9 @@ void SPGradient::modified(guint flags) if (flags & SP_OBJECT_CHILD_MODIFIED_FLAG) { // CPPIFY // This comparison has never worked (i. e. always evaluated to false), - // the right value would have been SP_TYPE_MESHGRADIENT + // the right value would have been SP_TYPE_MESH //if( this->get_type() != SP_GRADIENT_TYPE_MESH ) { -// if (!SP_IS_MESHGRADIENT(this)) { +// if (!SP_IS_MESH(this)) { // this->invalidateVector(); // } else { // this->invalidateArray(); @@ -522,7 +522,7 @@ void SPGradient::modified(guint flags) // CPPIFY // see above //if( this->get_type() != SP_GRADIENT_TYPE_MESH ) { -// if (!SP_IS_MESHGRADIENT(this)) { +// if (!SP_IS_MESH(this)) { // this->ensureVector(); // } else { // this->ensureArray(); @@ -1014,12 +1014,12 @@ void SPGradient::rebuildArray() { // std::cout << "SPGradient::rebuildArray()" << std::endl; - if( !SP_IS_MESHGRADIENT(this) ) { + if( !SP_IS_MESH(this) ) { g_warning( "SPGradient::rebuildArray() called for non-mesh gradient" ); return; } - array.read( SP_MESHGRADIENT( this ) ); + array.read( SP_MESH( this ) ); has_patches = false; for ( SPObject *ro = firstChild() ; ro ; ro = ro->getNext() ) { @@ -1139,7 +1139,7 @@ sp_gradient_create_preview_pattern(SPGradient *gr, double width) // CPPIFY //if( gr->get_type() != SP_GRADIENT_TYPE_MESH ) { - if (!SP_IS_MESHGRADIENT(gr)) { + if (!SP_IS_MESH(gr)) { gr->ensureVector(); pat = cairo_pattern_create_linear(0, 0, width, 0); diff --git a/src/sp-gradient.h b/src/sp-gradient.h index f80d806fc..ab45d6f08 100644 --- a/src/sp-gradient.h +++ b/src/sp-gradient.h @@ -39,12 +39,6 @@ enum SPGradientType { SP_GRADIENT_TYPE_MESH }; -enum SPGradientMeshType { - SP_GRADIENT_MESH_TYPE_UNKNOWN, - SP_GRADIENT_MESH_TYPE_NORMAL, - SP_GRADIENT_MESH_TYPE_CONICAL -}; - enum SPGradientState { SP_GRADIENT_STATE_UNKNOWN, SP_GRADIENT_STATE_VECTOR, @@ -216,7 +210,7 @@ sp_gradient_pattern_common_setup(cairo_pattern_t *cp, void sp_gradient_repr_write_vector(SPGradient *gr); void sp_gradient_repr_clear_vector(SPGradient *gr); -void sp_meshgradient_repr_write(SPMeshGradient *mg); +void sp_mesh_repr_write(SPMesh *mg); cairo_pattern_t *sp_gradient_create_preview_pattern(SPGradient *gradient, double width); diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp index 08b055508..4e1c5913d 100644 --- a/src/sp-guide.cpp +++ b/src/sp-guide.cpp @@ -47,16 +47,6 @@ using Inkscape::DocumentUndo; using std::vector; -#include "sp-factory.h" - -namespace { - SPObject* createGuide() { - return new SPGuide(); - } - - bool guideRegistered = SPFactory::instance().registerObject("sodipodi:guide", createGuide); -} - SPGuide::SPGuide() : SPObject() , label(NULL) diff --git a/src/sp-hatch-path.cpp b/src/sp-hatch-path.cpp index bc95c246e..32a514dcb 100644 --- a/src/sp-hatch-path.cpp +++ b/src/sp-hatch-path.cpp @@ -12,10 +12,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include <cstring> #include <string> #include <2geom/path.h> @@ -37,19 +33,6 @@ #include "svg/css-ostringstream.h" #include "xml/repr.h" -#include "sp-factory.h" - -namespace { - -SPObject* createHatchPath() -{ - return new SPHatchPath(); -} - -bool hatchRegistered = SPFactory::instance().registerObject("svg:hatchPath", createHatchPath); - -} // namespace - SPHatchPath::SPHatchPath() : offset(), _display(), diff --git a/src/sp-hatch.cpp b/src/sp-hatch.cpp index dfecb2250..ea4c5865a 100644 --- a/src/sp-hatch.cpp +++ b/src/sp-hatch.cpp @@ -12,10 +12,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include <cstring> #include <string> #include <2geom/transforms.h> @@ -35,18 +31,6 @@ #include "sp-hatch-path.h" #include "xml/repr.h" -#include "sp-factory.h" - -namespace { - -SPObject* createHatch() { - return new SPHatch(); -} - -bool hatchRegistered = SPFactory::instance().registerObject("svg:hatch", createHatch); - -} // namespace - SPHatch::SPHatch() : SPPaintServer(), href(), diff --git a/src/sp-image.cpp b/src/sp-image.cpp index b6177fae6..bf5b9ebcd 100644 --- a/src/sp-image.cpp +++ b/src/sp-image.cpp @@ -42,7 +42,6 @@ #include "snap-candidate.h" #include "preferences.h" #include "io/sys.h" -#include "sp-factory.h" #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) #include "cms-system.h" @@ -112,14 +111,6 @@ extern guint update_in_progress; #define DEBUG_MESSAGE_SCISLAC(key, ...) #endif // DEBUG_LCMS -namespace { -SPObject* createImage() { - return new SPImage(); -} - -bool imageRegistered = SPFactory::instance().registerObject("svg:image", createImage); -} - SPImage::SPImage() : SPItem(), SPViewBox() { this->x.unset(); diff --git a/src/sp-item-group.cpp b/src/sp-item-group.cpp index b1ba37de2..55857dacf 100644 --- a/src/sp-item-group.cpp +++ b/src/sp-item-group.cpp @@ -58,16 +58,6 @@ using Inkscape::DocumentUndo; static void sp_group_perform_patheffect(SPGroup *group, SPGroup *topgroup, bool write); -#include "sp-factory.h" - -namespace { - SPObject* createGroup() { - return new SPGroup(); - } - - bool groupRegistered = SPFactory::instance().registerObject("svg:g", createGroup); -} - SPGroup::SPGroup() : SPLPEItem() { this->_layer_mode = SPGroup::GROUP; } @@ -399,6 +389,22 @@ void SPGroup::snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape: } } +void sp_item_group_ungroup_handle_clones(SPItem *parent, Geom::Affine const g) +{ + for(std::list<SPObject*>::const_iterator refd=parent->hrefList.begin();refd!=parent->hrefList.end();refd++){ + SPItem *citem = dynamic_cast<SPItem *>(*refd); + if (citem) { + SPUse *useitem = dynamic_cast<SPUse *>(citem); + if (useitem && useitem->get_original() == parent) { + Geom::Affine ctrans; + ctrans = g.inverse() * citem->transform; + gchar *affinestr = sp_svg_transform_write(ctrans); + citem->setAttribute("transform", affinestr); + g_free(affinestr); + } + } + } +} void sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done) @@ -435,8 +441,14 @@ sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done) /* Step 1 - generate lists of children objects */ GSList *items = NULL; GSList *objects = NULL; - for (SPObject *child = group->firstChild() ; child; child = child->getNext() ) { + Geom::Affine const g(group->transform); + + for (SPObject *child = group->firstChild() ; child; child = child->getNext() ) + if (SPItem *citem = dynamic_cast<SPItem *>(child)) + sp_item_group_ungroup_handle_clones(citem,g); + + for (SPObject *child = group->firstChild() ; child; child = child->getNext() ) { SPItem *citem = dynamic_cast<SPItem *>(child); if (citem) { /* Merging of style */ @@ -472,13 +484,6 @@ sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done) // Merging transform Geom::Affine ctrans; - Geom::Affine const g(group->transform); - SPUse *useitem = dynamic_cast<SPUse *>(citem); - if (useitem && useitem->get_original() && - useitem->get_original()->parent == dynamic_cast<SPObject *>(group)) { - // make sure a clone's effective transform is the same as was under group - ctrans = g.inverse() * citem->transform * g; - } else { // We should not apply the group's transformation to both a linked offset AND to its source if (dynamic_cast<SPOffset *>(citem)) { // Do we have an offset at hand (whether it's dynamic or linked)? SPItem *source = sp_offset_get_source(dynamic_cast<SPOffset *>(citem)); @@ -497,7 +502,6 @@ sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done) } else { ctrans = citem->transform * g; } - } // FIXME: constructing a transform that would fully preserve the appearance of a // textpath if it is ungrouped with its path seems to be impossible in general @@ -709,21 +713,16 @@ void SPGroup::scaleChildItemsRec(Geom::Scale const &sc, Geom::Point const &p, bo subItem = dynamic_cast<SPItem *>(item->clip_ref->getObject()->firstChild()); } if (subItem != NULL) { - Geom::Affine tdoc2dt = Geom::Scale(1, -1) * Geom::Translate(p); // re-create doc2dt() - Geom::Affine ti2doc = item->i2doc_affine(); - subItem->set_i2d_affine(ti2doc * sc * ti2doc.inverse() * tdoc2dt); - subItem->doWriteTransform(subItem->getRepr(), subItem->transform, NULL, true); + subItem->doWriteTransform(subItem->getRepr(), subItem->transform*sc, NULL, true); } subItem = NULL; if (item->mask_ref->getObject()) { subItem = dynamic_cast<SPItem *>(item->mask_ref->getObject()->firstChild()); } if (subItem != NULL) { - Geom::Affine tdoc2dt = Geom::Scale(1, -1) * Geom::Translate(p); // re-create doc2dt() - Geom::Affine ti2doc = item->i2doc_affine(); - subItem->set_i2d_affine(ti2doc * sc * ti2doc.inverse() * tdoc2dt); - subItem->doWriteTransform(item->getRepr(), item->transform, NULL, true); + subItem->doWriteTransform(subItem->getRepr(), subItem->transform*sc, NULL, true); } + item->doWriteTransform(item->getRepr(), sc.inverse()*item->transform*sc, NULL, true); group->scaleChildItemsRec(sc, p, false); } } else { @@ -777,8 +776,7 @@ void SPGroup::scaleChildItemsRec(Geom::Scale const &sc, Geom::Point const &p, bo Geom::Affine move = final.inverse() * item->transform * final; item->doWriteTransform(item->getRepr(), move, &move, true); } else { - item->set_i2d_affine(item->i2dt_affine() * final); - item->doWriteTransform(item->getRepr(), item->transform, NULL, true); + item->doWriteTransform(item->getRepr(), item->transform*sc, NULL, true); } if (conn_type != NULL) { @@ -845,7 +843,7 @@ void SPGroup::update_patheffect(bool write) { LivePathEffectObject *lpeobj = (*it)->lpeobject; if (lpeobj && lpeobj->get_lpe()) { - lpeobj->get_lpe()->doBeforeEffect(this); + lpeobj->get_lpe()->doBeforeEffect_impl(this); } } diff --git a/src/sp-item-group.h b/src/sp-item-group.h index 15bb58f22..f9a8b88f5 100644 --- a/src/sp-item-group.h +++ b/src/sp-item-group.h @@ -95,6 +95,15 @@ public: virtual void update_patheffect(bool write); }; +/** + * finds clones of a child of the group going out of the group; and inverse the group transform on its clones + * Also called when moving objects between different layers + * @param group current group + * @param parent original parent + * @param g transform + */ +void sp_item_group_ungroup_handle_clones(SPItem *parent, Geom::Affine const g); + void sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done = true); diff --git a/src/sp-item-transform.cpp b/src/sp-item-transform.cpp index 86beee907..767f0ed91 100644 --- a/src/sp-item-transform.cpp +++ b/src/sp-item-transform.cpp @@ -181,7 +181,9 @@ Geom::Affine get_scale_transform_for_uniform_stroke(Geom::Rect const &bbox_visua if (B*B - 4*A*C < 0) { g_message("stroke scaling error : %d, %f, %f, %f, %f, %f", preserve, r0, w0, h0, w1, h1); } else { - r1 = fabs((-B - sqrt(B*B - 4*A*C))/(2*A)); + r1 = -C/B; + if (!Geom::are_near(A*C/B/B, 0.0, Geom::EPSILON)) + r1 = fabs((-B - sqrt(B*B - 4*A*C))/(2*A)); // If w1 < 0 then the scale will be wrong if we just assume that scale_x = (w1 - r1)/(w0 - r0); // Therefore we here need the absolute values of w0, w1, h0, h1, and r0, as taken care of earlier scale_x = (w1 - r1)/(w0 - r0); @@ -339,7 +341,9 @@ Geom::Affine get_scale_transform_for_variable_stroke(Geom::Rect const &bbox_visu if (B*B - 4*A*C < 0) { g_message("variable stroke scaling error : %d, %d, %f, %f, %f, %f, %f, %f", transform_stroke, preserve, r0w, r0h, w0, h0, w1, h1); } else { - gdouble det = (-B + sqrt(B*B - 4*A*C))/(2*A); + gdouble det = -C/B; + if (!Geom::are_near(A*C/B/B, 0.0, Geom::EPSILON)) + det = (-B + sqrt(B*B - 4*A*C))/(2*A); r1w = r0w*det; r1h = r0h*det; // If w1 < 0 then the scale will be wrong if we just assume that scale_x = (w1 - r1)/(w0 - r0); diff --git a/src/sp-item.cpp b/src/sp-item.cpp index 5d181b80a..8c99e9bcf 100644 --- a/src/sp-item.cpp +++ b/src/sp-item.cpp @@ -75,18 +75,6 @@ static SPItemView* sp_item_view_list_remove(SPItemView *list, SPItem::SPItem() : SPObject() { - this->sensitive = 0; - this->clip_ref = NULL; - this->avoidRef = NULL; - this->_is_evaluated = false; - this->stop_paint = 0; - this->_evaluated_status = StatusUnknown; - this->bbox_valid = 0; - this->freeze_stroke_width = false; - this->transform_center_x = 0; - this->transform_center_y = 0; - this->display = NULL; - this->mask_ref = NULL; sensitive = TRUE; bbox_valid = FALSE; @@ -96,12 +84,13 @@ SPItem::SPItem() : SPObject() { transform_center_x = 0; transform_center_y = 0; + freeze_stroke_width = false; + _is_evaluated = true; _evaluated_status = StatusUnknown; transform = Geom::identity(); - doc_bbox = Geom::OptRect(); - freeze_stroke_width = false; + // doc_bbox = Geom::OptRect(); display = NULL; @@ -670,54 +659,56 @@ void SPItem::stroke_ps_ref_changed(SPObject *old_ps, SPObject *ps, SPItem *item) } } -void SPItem::update(SPCtx* /*ctx*/, guint flags) { - SPItem *item = this; - SPItem* object = item; +void SPItem::update(SPCtx* ctx, guint flags) { -// SPObject::onUpdate(ctx, flags); + SPItemCtx const *ictx = reinterpret_cast<SPItemCtx const *>(ctx); - // any of the modifications defined in sp-object.h might change bbox, + // Any of the modifications defined in sp-object.h might change bbox, // so we invalidate it unconditionally - item->bbox_valid = FALSE; + bbox_valid = FALSE; + + viewport = ictx->viewport; // Cache viewport - if (flags & (SP_OBJECT_CHILD_MODIFIED_FLAG | SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG)) { + if (flags & (SP_OBJECT_CHILD_MODIFIED_FLAG | + SP_OBJECT_MODIFIED_FLAG | + SP_OBJECT_STYLE_MODIFIED_FLAG) ) { if (flags & SP_OBJECT_MODIFIED_FLAG) { - for (SPItemView *v = item->display; v != NULL; v = v->next) { - v->arenaitem->setTransform(item->transform); + for (SPItemView *v = display; v != NULL; v = v->next) { + v->arenaitem->setTransform(transform); } } - SPClipPath *clip_path = item->clip_ref ? item->clip_ref->getObject() : NULL; - SPMask *mask = item->mask_ref ? item->mask_ref->getObject() : NULL; + SPClipPath *clip_path = clip_ref ? clip_ref->getObject() : NULL; + SPMask *mask = mask_ref ? mask_ref->getObject() : NULL; if ( clip_path || mask ) { - Geom::OptRect bbox = item->geometricBounds(); + Geom::OptRect bbox = geometricBounds(); if (clip_path) { - for (SPItemView *v = item->display; v != NULL; v = v->next) { + for (SPItemView *v = display; v != NULL; v = v->next) { clip_path->setBBox(v->arenaitem->key(), bbox); } } if (mask) { - for (SPItemView *v = item->display; v != NULL; v = v->next) { + for (SPItemView *v = display; v != NULL; v = v->next) { mask->sp_mask_set_bbox(v->arenaitem->key(), bbox); } } } if (flags & SP_OBJECT_STYLE_MODIFIED_FLAG) { - for (SPItemView *v = item->display; v != NULL; v = v->next) { - v->arenaitem->setOpacity(SP_SCALE24_TO_FLOAT(object->style->opacity.value)); - v->arenaitem->setAntialiasing(object->style->shape_rendering.computed != SP_CSS_SHAPE_RENDERING_CRISPEDGES); - v->arenaitem->setIsolation( object->style->isolation.value ); - v->arenaitem->setBlendMode( object->style->mix_blend_mode.value ); - v->arenaitem->setVisible(!item->isHidden()); + for (SPItemView *v = display; v != NULL; v = v->next) { + v->arenaitem->setOpacity(SP_SCALE24_TO_FLOAT(style->opacity.value)); + v->arenaitem->setAntialiasing(style->shape_rendering.computed != SP_CSS_SHAPE_RENDERING_CRISPEDGES); + v->arenaitem->setIsolation( style->isolation.value ); + v->arenaitem->setBlendMode( style->mix_blend_mode.value ); + v->arenaitem->setVisible(!isHidden()); } } } /* Update bounding box in user space, used for filter and objectBoundingBox units */ - if (item->style->filter.set && item->display) { - Geom::OptRect item_bbox = item->geometricBounds(); - SPItemView *itemview = item->display; + if (style->filter.set && display) { + Geom::OptRect item_bbox = geometricBounds(); + SPItemView *itemview = display; do { if (itemview->arenaitem) itemview->arenaitem->setItemBounds(item_bbox); @@ -725,8 +716,8 @@ void SPItem::update(SPCtx* /*ctx*/, guint flags) { } // Update libavoid with item geometry (for connector routing). - if (item->avoidRef) - item->avoidRef->handleSettingChange(); + if (avoidRef) + avoidRef->handleSettingChange(); } void SPItem::modified(unsigned int /*flags*/) diff --git a/src/sp-item.h b/src/sp-item.h index b9d71c551..bdc6a0ad9 100644 --- a/src/sp-item.h +++ b/src/sp-item.h @@ -145,6 +145,7 @@ public: Geom::Affine transform; mutable Geom::OptRect doc_bbox; + Geom::Rect viewport; // Cache viewport information SPClipPathReference *clip_ref; SPMaskReference *mask_ref; diff --git a/src/sp-line.cpp b/src/sp-line.cpp index 8af95b4ce..cf21be912 100644 --- a/src/sp-line.cpp +++ b/src/sp-line.cpp @@ -11,9 +11,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif #include "attributes.h" #include "style.h" #include "sp-line.h" @@ -24,16 +21,6 @@ #include "document.h" #include "inkscape.h" -#include "sp-factory.h" - -namespace { - SPObject* createLine() { - return new SPLine(); - } - - bool lineRegistered = SPFactory::instance().registerObject("svg:line", createLine); -} - SPLine::SPLine() : SPShape() { this->x1.unset(); this->y1.unset(); diff --git a/src/sp-linear-gradient.cpp b/src/sp-linear-gradient.cpp index 6e9f5e6dd..29579b617 100644 --- a/src/sp-linear-gradient.cpp +++ b/src/sp-linear-gradient.cpp @@ -5,17 +5,6 @@ #include "attributes.h" #include "xml/repr.h" -#include "sp-factory.h" - -namespace { - SPObject* createLinearGradient() { - return new SPLinearGradient(); - } - - bool linearGradientRegistered = SPFactory::instance().registerObject("svg:linearGradient", createLinearGradient); -} - - /* * Linear Gradient */ diff --git a/src/sp-lpe-item.cpp b/src/sp-lpe-item.cpp index f059ab531..12d85b3ed 100644 --- a/src/sp-lpe-item.cpp +++ b/src/sp-lpe-item.cpp @@ -263,7 +263,7 @@ bool SPLPEItem::performPathEffect(SPCurve *curve) { } if (!SP_IS_GROUP(this)) { lpe->doAfterEffect(this); - } + } } } } diff --git a/src/sp-marker.cpp b/src/sp-marker.cpp index 371a6c35c..d3cf50fa7 100644 --- a/src/sp-marker.cpp +++ b/src/sp-marker.cpp @@ -43,16 +43,6 @@ public: std::vector<Inkscape::DrawingItem *> items; }; -#include "sp-factory.h" - -namespace { - SPObject* createMarker() { - return new SPMarker(); - } - - bool markerRegistered = SPFactory::instance().registerObject("svg:marker", createMarker); -} - SPMarker::SPMarker() : SPGroup(), SPViewBox() { this->markerUnits = 0; diff --git a/src/sp-mask.cpp b/src/sp-mask.cpp index 9707c9d8e..d60473e1d 100644 --- a/src/sp-mask.cpp +++ b/src/sp-mask.cpp @@ -37,16 +37,6 @@ struct SPMaskView { SPMaskView *sp_mask_view_new_prepend (SPMaskView *list, unsigned int key, Inkscape::DrawingItem *arenaitem); SPMaskView *sp_mask_view_list_remove (SPMaskView *list, SPMaskView *view); -#include "sp-factory.h" - -namespace { - SPObject* createMask() { - return new SPMask(); - } - - bool maskRegistered = SPFactory::instance().registerObject("svg:mask", createMask); -} - SPMask::SPMask() : SPObjectGroup() { this->maskUnits_set = FALSE; this->maskUnits = SP_CONTENT_UNITS_OBJECTBOUNDINGBOX; diff --git a/src/sp-mesh-array.cpp b/src/sp-mesh-array.cpp index e2d654f2f..445c9a8f6 100644 --- a/src/sp-mesh-array.cpp +++ b/src/sp-mesh-array.cpp @@ -46,8 +46,8 @@ #include "document.h" #include "sp-root.h" +#include "sp-mesh.h" #include "sp-mesh-array.h" -#include "sp-mesh-gradient.h" #include "sp-mesh-row.h" #include "sp-mesh-patch.h" #include "sp-stop.h" @@ -289,7 +289,7 @@ bool SPMeshPatchI::tensorIsSet() { /** Return if tensor control point for "corner" i is set. */ -bool SPMeshPatchI::tensorIsSet( guint i ) { +bool SPMeshPatchI::tensorIsSet( unsigned int i ) { assert( i < 4 ); @@ -574,7 +574,7 @@ void SPMeshPatchI::setOpacity( guint i, gdouble opacity ) { }; -SPMeshNodeArray::SPMeshNodeArray( SPMeshGradient *mg ) { +SPMeshNodeArray::SPMeshNodeArray( SPMesh *mg ) { read( mg ); @@ -621,7 +621,7 @@ SPMeshNodeArray& SPMeshNodeArray::operator=( const SPMeshNodeArray& rhs ) { }; -void SPMeshNodeArray::read( SPMeshGradient *mg_in ) { +void SPMeshNodeArray::read( SPMesh *mg_in ) { mg = mg_in; @@ -641,7 +641,7 @@ void SPMeshNodeArray::read( SPMeshGradient *mg_in ) { if (SP_IS_MESHPATCH(po)) { - SPMeshPatch *patch = SP_MESHPATCH(po); + SPMeshpatch *patch = SP_MESHPATCH(po); // std::cout << "SPMeshNodeArray::read: row size: " << nodes.size() << std::endl; SPMeshPatchI new_patch( &nodes, irow, icolumn ); // Adds new nodes. @@ -838,7 +838,7 @@ void SPMeshNodeArray::read( SPMeshGradient *mg_in ) { /** Write repr using our array. */ -void SPMeshNodeArray::write( SPMeshGradient *mg ) { +void SPMeshNodeArray::write( SPMesh *mg ) { // std::cout << "SPMeshNodeArray::write: entrance:" << std::endl; // print(); @@ -889,14 +889,14 @@ void SPMeshNodeArray::write( SPMeshGradient *mg ) { for( guint i = 0; i < rows; ++i ) { // Write row - Inkscape::XML::Node *row = xml_doc->createElement("svg:meshRow"); + Inkscape::XML::Node *row = xml_doc->createElement("svg:meshrow"); mesh->appendChild( row ); // No attributes guint columns = array->patch_columns(); for( guint j = 0; j < columns; ++j ) { // Write patch - Inkscape::XML::Node *patch = xml_doc->createElement("svg:meshPatch"); + Inkscape::XML::Node *patch = xml_doc->createElement("svg:meshpatch"); SPMeshPatchI patchi( &(array->nodes), i, j ); @@ -967,10 +967,10 @@ void SPMeshNodeArray::write( SPMeshGradient *mg ) { break; case 'z': case 'Z': - std::cout << "sp_meshgradient_repr_write: bad path type" << path_type << std::endl; + std::cout << "sp_mesh_repr_write: bad path type" << path_type << std::endl; break; default: - std::cout << "sp_meshgradient_repr_write: unhandled path type" << path_type << std::endl; + std::cout << "sp_mesh_repr_write: unhandled path type" << path_type << std::endl; } stop->setAttribute("path", is.str().c_str()); // std::cout << "SPMeshNodeArray::write: path: " << is.str().c_str() << std::endl; @@ -1039,7 +1039,7 @@ static SPColor default_color( SPItem *item ) { /** Create a default mesh. */ -void SPMeshNodeArray::create( SPMeshGradient *mg, SPItem *item, Geom::OptRect bbox ) { +void SPMeshNodeArray::create( SPMesh *mg, SPItem *item, Geom::OptRect bbox ) { // std::cout << "SPMeshNodeArray::create: Entrance" << std::endl; @@ -1077,10 +1077,10 @@ void SPMeshNodeArray::create( SPMeshGradient *mg, SPItem *item, Geom::OptRect bb guint prows = prefs->getInt("/tools/mesh/mesh_rows", 1); guint pcols = prefs->getInt("/tools/mesh/mesh_cols", 1); - SPGradientMeshType mesh_type = - (SPGradientMeshType) prefs->getInt("/tools/mesh/mesh_type", SP_GRADIENT_MESH_TYPE_NORMAL); + SPMeshGeometry mesh_type = + (SPMeshGeometry) prefs->getInt("/tools/mesh/mesh_geometry", SP_MESH_GEOMETRY_NORMAL); - if( mesh_type == SP_GRADIENT_MESH_TYPE_CONICAL ) { + if( mesh_type == SP_MESH_GEOMETRY_CONICAL ) { // Conical gradient.. for any shape/path using geometric bounding box. @@ -1424,133 +1424,7 @@ void SPMeshNodeArray::print() { -// Find the slopes at start and end for Hermite interpolation. -// Smooth using Hermite interpolation. -// Inputs are: -// pb: color value before patch -// p0: color value start of patch -// p1: color value end of patch -// pa: color value after patch -// lb0: distance between points b and 0 -// l01: distance between points 0 and 1 -// l1a: distance between points 1 and a -// is_first: If first patch in row/column -// is_last: If last patch in row/column -// type: Type of smoothing -// Output: -// m0: slope of Hermite function at start. -// m1: slope of Hermite function at end. -void find_slopes( const double &pb, const double &p0, const double &p1, const double &pa, - const double &lb0, const double &l01, const double &l1a, - const bool &is_first, const bool &is_last, const SPMeshSmooth type, - double &m0, double &m1 ) { - - // We use Hermite interpolation. We have end points, we need tangents. - - // Try various ways of finding tangents m0, m1 - - // Default to Catmul-Rom (assumes pb and pa already calculatedd) - m0 = (p1 - pb)/2.0; - m1 = (pa - p0)/2.0; - - // Finite differences - if( lb0 > 0 && l01 > 0 ) - m0 = 0.5 * ((p0 - pb )/lb0 + (p1 - p0)/l01) * l01; - if( l01 > 0 && l1a > 0 ) - m1 = 0.5 * ((p1 - p0 )/l01 + (pa - p1)/l1a) * l01; - - bool parabolic = false; // Require end patches to be parabolic - switch (type) { - case SP_MESH_SMOOTH_SMOOTH1: - // Flat - m0 = 0.0; - m1 = 0.0; - break; - case SP_MESH_SMOOTH_SMOOTH2: - // Catmul-Rom, standard end treatment. Double first/last point. - if( is_first ) { - m0 = (p1-p0)/2.0; - } - if( is_last ) { - m1 = (p1-p0)/2.0; - } - break; - case SP_MESH_SMOOTH_SMOOTH3: - // Catmul-Rom, standard end treatment. Reflect first/last point. - if( is_first ) { - m0 = (p1-p0); - } - if( is_last ) { - m1 = (p1-p0); - } - break; - case SP_MESH_SMOOTH_SMOOTH4: - // Catmul-Rom, Parabolic ends - parabolic = true; - break; - case SP_MESH_SMOOTH_SMOOTH5: - // Catmul-Rom, Parabolic ends, no color min/max in middle of patch. - parabolic = true; - - if( (pb > p0 && p1 > p0) || - (pb < p0 && p1 < p0) ) { - // tangents flat at min/max - m0 = 0; - } else { - // https://en.wikipedia.org/wiki/Monotone_cubic_interpolation - // ensure we don't overshoot - if( fabs(m0) > fabs(3*(p1-p0)) ) { - m0 = 3*(p1-p0); - } - if( fabs(m0) > fabs(3*(p0-pb)) * l01 / lb0 ) { - m0 = 3*(p0-pb) * l01 / lb0; - } - } - if( (p0 > p1 && pa > p1) || - (p0 < p1 && pa < p1) ) { - // tangents flat at min/max - m1 = 0; - } else { - // ensure we don't overshoot - if( fabs(m1) > fabs(3*(pa-p1) * l01 / l1a) ) { - m1 = 3*(pa-p1) * l01 / l1a; - } - if( fabs(m1) > fabs(3*(p1-p0)) ) { - m1 = 3*(p1-p0); - } - } - break; - case SP_MESH_SMOOTH_NONE: - default: - std::cerr << "find_slopes() Invalid smoothing type." << std::endl; - break; - } - - // Force end patches to be parabolic - if( parabolic ) { - if( is_first ) { - // Constraint for parabola - m0 = 2.0*(p1-p0) - m1; - if ( ((p1-p0) < 0 && m0 > 0) || ((p1-p0) > 0 && m0 < 0 ) ) { - m0 = 0; // Prevent overshooting start value; - } - } else if( is_last ) { - // Constraint for parabola - m1 = 2.0*(p1-p0) - m0; - if ( ((p1-p0) < 0 && m1 > 0) || ((p1-p0) > 0 && m1 < 0 ) ) { - m1 = 0; // Prevent overshooting end value; - } - } - } - - // std::cout << " pb: " << pb - // << " p0: " << p0 - // << " p1: " << p1 - // << " pa: " << pa - // << " m0: " << m0 - // << " m1: " << m1 << std::endl; -} - +/* double hermite( const double p0, const double p1, const double m0, const double m1, const double t ) { double t2 = t*t; double t3 = t2*t; @@ -1562,178 +1436,7 @@ double hermite( const double p0, const double p1, const double m0, const double return result; } - - -/** - Fill 'smooth' with a smoothed version of the array by subdividing each patch into smaller patches. */ -void SPMeshNodeArray::smooth( SPMeshNodeArray* smooth, SPMeshSmooth type ) { - - *smooth = *this; // Deep copy via copy assignment constructor, smooth cleared before copy - // std::cout << "SPMeshNodeArray::smooth(): " << this->patch_rows() << " " << smooth->patch_rows() << std::endl; - // std::cout << " " << smooth << " " << this << std::endl; - // Next split each patch into 8x8 smaller patches. - - // Do rows first. - - // Split each row into eight rows. - // Must do it from end so inserted rows don't mess up indexing - for( int i = smooth->patch_rows() - 1; i >= 0; --i ) { - smooth->split_row( i, unsigned(8) ); - } - - // Update color values (every third node is a corner) - for( unsigned i = 0; i < this->patch_rows(); ++i ) { // i is orignal patch index - - bool is_first_row = (i == 0); - bool is_last_row = (i == this->patch_rows() - 1 ); - //std::cout << " last row: " << smooth->patch_rows()/8 - 1 << " " << is_last_row << std::endl; - for( unsigned j = 0; j < smooth->patch_columns()+1; ++j ) { // j is smooth patch index - - // Can't use guint32 since delta can be negative - float pb[3]; // Point before patch - float p0[3]; // Point at start of patch - float p1[3]; // Point at end of patch - float pa[3]; // Point after patch - float result[3][8]; - sp_color_get_rgb_floatv( &this->nodes[ i *3 ][ j*3 ]->color, p0 ); - sp_color_get_rgb_floatv( &this->nodes[ (i+1)*3 ][ j*3 ]->color, p1 ); - - // Use linear distance to avoid calculation overhead of calculating true path length - Geom::Point *ptb = NULL; - Geom::Point *pt0 = &this->nodes[ i *3 ][ j*3 ]->p; - Geom::Point *pt1 = &this->nodes[ (i+1)*3 ][ j*3 ]->p; - Geom::Point *pta = NULL; - - double lb0 = 0.0; - double l01 = Geom::distance( *pt0, *pt1 ); - double l1a = 0.0; - - if( !is_first_row ) { - sp_color_get_rgb_floatv( &this->nodes[ (i-1)*3 ][ j*3 ]->color, pb ); - ptb = &this->nodes[ (i-1)*3 ][ j*3 ]->p; - lb0 = Geom::distance( *ptb, *pt0 ); - } else { - pb[0] = 2.0*p0[0] - p1[0]; - pb[1] = 2.0*p0[1] - p1[1]; - pb[2] = 2.0*p0[2] - p1[2]; - } - if( !is_last_row ) { - sp_color_get_rgb_floatv( &this->nodes[ (i+2)*3 ][ j*3 ]->color, pa ); - pta = &this->nodes[ (i+2)*3 ][ j*3 ]->p; - l1a = Geom::distance( *pt1, *pta ); - } else { - pa[0] = 2.0*p1[0] - p0[0]; - pa[1] = 2.0*p1[1] - p0[1]; - pa[2] = 2.0*p1[2] - p0[2]; - } - - for( unsigned n = 0; n < 3; ++n ) { // Loop over colors - - // We use Hermite interpolation. We have end points, we need tangents. - double m0 = 0; - double m1 = 0; - find_slopes( pb[n], p0[n], p1[n], pa[n], - lb0, l01, l1a, - is_first_row, is_last_row, type, m0, m1 ); - - for( unsigned k = 1; k < 8; ++k ) { - double t = k/8.0; - // Cubic Hermite (four constraints) - result[n][k] = hermite( p0[n], p1[n], m0, m1, t ); - // Clamp to allowed values - if( result[n][k] > 1.0 ) - result[n][k] = 1.0; - if( result[n][k] < 0.0 ) - result[n][k] = 0.0; - } - } - - for( unsigned k = 1; k < 8; ++k ) { - smooth->nodes[ (i*8+k)*3 ][ j*3 ]->color.set( result[0][k], result[1][k], result[2][k] ); - } - } - } - - // Split each column into eight columns. - // Must do it from end so inserted columns don't mess up indexing - for( int i = smooth->patch_columns() - 1; i >= 0; --i ) { - smooth->split_column( i, (unsigned)8 ); - } - - // Update color values (every third node is a corner) - for( unsigned i = 0; i < this->patch_columns(); ++i ) { // i is orignal patch index - - bool is_first_column = (i == 0); - bool is_last_column = (i == this->patch_columns() - 1 ); - //std::cout << " last column: " << smooth->patch_columns()/8 - 1 << " " << is_last_column << std::endl; - for( unsigned j = 0; j < smooth->patch_rows()+1; ++j ) { // j is smooth patch index - - // Can't use guint32 since delta can be negative - float pb[3]; // Point before patch - float p0[3]; // Point at start of patch - float p1[3]; // Point at end of patch - float pa[3]; // Point after patch - float result[3][8]; - sp_color_get_rgb_floatv( &smooth->nodes[ j*3 ][ i *3*8 ]->color, p0 ); - sp_color_get_rgb_floatv( &smooth->nodes[ j*3 ][ (i+1)*3*8 ]->color, p1 ); - - // Use linear distance to avoid calculation overhead of calculating true path length - Geom::Point *ptb = NULL; - Geom::Point *pt0 = &smooth->nodes[ j*3 ][ i *3*8 ]->p; - Geom::Point *pt1 = &smooth->nodes[ j*3 ][ (i+1)*3*8 ]->p; - Geom::Point *pta = NULL; - - double lb0 = 0.0; - double l01 = Geom::distance( *pt0, *pt1 ); - double l1a = 0.0; - - if( !is_first_column ) { - sp_color_get_rgb_floatv( &smooth->nodes[ j*3 ][ (i-1)*3*8 ]->color, pb ); - ptb = &smooth->nodes[ j*3 ][ (i-1)*3*8 ]->p; - lb0 = Geom::distance( *ptb, *pt0 ); - } else { - pb[0] = 2.0*p0[0] - p1[0]; - pb[1] = 2.0*p0[1] - p1[1]; - pb[2] = 2.0*p0[2] - p1[2]; - } - if( !is_last_column ) { - sp_color_get_rgb_floatv( &smooth->nodes[ j*3 ][ (i+2)*3*8 ]->color, pa ); - pta = &smooth->nodes[ j*3 ][ (i+2)*3*8 ]->p; - l1a = Geom::distance( *pt1, *pta ); - } else { - pa[0] = 2.0*p1[0] - p0[0]; - pa[1] = 2.0*p1[1] - p0[1]; - pa[2] = 2.0*p1[2] - p0[2]; - } - - for( unsigned n = 0; n < 3; ++n ) { // Loop over colors - - // We use Hermite interpolation. We have end points, we need tangents. - double m0 = 0; - double m1 = 0; - find_slopes( pb[n], p0[n], p1[n], pa[n], - lb0, l01, l1a, - is_first_column, is_last_column, type, m0, m1 ); - - for( unsigned k = 1; k < 8; ++k ) { - double t = k/8.0; - // Cubic Hermite (four constraints) - result[n][k] = hermite( p0[n], p1[n], m0, m1, t ); - // Clamp to allowed values - if( result[n][k] > 1.0 ) - result[n][k] = 1.0; - if( result[n][k] < 0.0 ) - result[n][k] = 0.0; - } - } - - for( unsigned k = 1; k < 8; ++k ) { - smooth->nodes[ j*3 ][ (i*8+k)*3 ]->color.set( result[0][k], result[1][k], result[2][k] ); - } - } - } -} class SPMeshSmoothCorner { @@ -1792,6 +1495,7 @@ double find_slope1( const double &p0, const double &p1, const double &p2, }; +/* // Find slope at point 0 given values at previous and next points // TO DO: TAKE DISTANCE BETWEEN POINTS INTO ACCOUNT double find_slope2( double pmm, double ppm, double pmp, double ppp, double p0 ) { @@ -1819,6 +1523,7 @@ double find_slope2( double pmm, double ppm, double pmp, double ppp, double p0 ) } return slope; } +*/ // https://en.wikipedia.org/wiki/Bicubic_interpolation void invert( const double v[16], double alpha[16] ) { @@ -1883,7 +1588,7 @@ double sum( const double alpha[16], const double& x, const double& y ) { /** Fill 'smooth' with a smoothed version of the array by subdividing each patch into smaller patches. */ -void SPMeshNodeArray::smooth2( SPMeshNodeArray* smooth, SPMeshSmooth type ) { +void SPMeshNodeArray::bicubic( SPMeshNodeArray* smooth, SPMeshType type ) { *smooth = *this; // Deep copy via copy assignment constructor, smooth cleared before copy @@ -1911,40 +1616,29 @@ void SPMeshNodeArray::smooth2( SPMeshNodeArray* smooth, SPMeshSmooth type ) { for( unsigned i = 0; i < d.size(); ++i ) { for( unsigned j = 0; j < d[i].size(); ++j ) { for( unsigned k = 0; k < 3; ++k ) { // Loop over colors - if( type == SP_MESH_SMOOTH_SMOOTH7 || type == SP_MESH_SMOOTH_SMOOTH ) { - // dx - if( i != 0 && i != d.size()-1 ) { - double lm = Geom::distance( d[i-1][j].p, d[i][j].p ); - double lp = Geom::distance( d[i+1][j].p, d[i][j].p ); - d[i][j].g[k][1] = find_slope1( d[i-1][j].g[k][0], d[i][j].g[k][0], d[i+1][j].g[k][0], lm, lp ); - } + // dx - // dy - if( j != 0 && j != d[i].size()-1 ) { - double lm = Geom::distance( d[i][j-1].p, d[i][j].p ); - double lp = Geom::distance( d[i][j+1].p, d[i][j].p ); - d[i][j].g[k][2] = find_slope1( d[i][j-1].g[k][0], d[i][j].g[k][0], d[i][j+1].g[k][0], lm, lp ); - } - - // dxdy if needed, need to take lengths into account - // if( i != 0 && i != d.size()-1 && j != 0 && j != d[i].size()-1 ) { - // d[i][j].g[k][3] = find_slope2( d[i-1][j-1].g[k][0], d[i+1][j-1].g[k][0], - // d[i-1][j+1].g[k][0], d[i-1][j-1].g[k][0], - // d[i][j].g[k][0] ); - // } + if( i != 0 && i != d.size()-1 ) { + double lm = Geom::distance( d[i-1][j].p, d[i][j].p ); + double lp = Geom::distance( d[i+1][j].p, d[i][j].p ); + d[i][j].g[k][1] = find_slope1( d[i-1][j].g[k][0], d[i][j].g[k][0], d[i+1][j].g[k][0], lm, lp ); + } - } else { - // Catmul-Rom - if( i != 0 && i != d.size()-1 ) { - double d2 = Geom::distance( d[i-1][j].p, d[i+1][j].p ); - d[i][j].g[k][1] = (d[i+1][j].g[k][0] - d[i-1][j].g[k][0])/d2; - } - if( j != 0 && j != d[i].size()-1 ) { - double d2 = Geom::distance( d[i][j-1].p, d[i][j+1].p ); - d[i][j].g[k][2] = (d[i][j+1].g[k][0] - d[i][j-1].g[k][0])/d2; - } + // dy + if( j != 0 && j != d[i].size()-1 ) { + double lm = Geom::distance( d[i][j-1].p, d[i][j].p ); + double lp = Geom::distance( d[i][j+1].p, d[i][j].p ); + d[i][j].g[k][2] = find_slope1( d[i][j-1].g[k][0], d[i][j].g[k][0], d[i][j+1].g[k][0], lm, lp ); } + + // dxdy if needed, need to take lengths into account + // if( i != 0 && i != d.size()-1 && j != 0 && j != d[i].size()-1 ) { + // d[i][j].g[k][3] = find_slope2( d[i-1][j-1].g[k][0], d[i+1][j-1].g[k][0], + // d[i-1][j+1].g[k][0], d[i-1][j-1].g[k][0], + // d[i][j].g[k][0] ); + // } + } } } @@ -1954,80 +1648,42 @@ void SPMeshNodeArray::smooth2( SPMeshNodeArray* smooth, SPMeshSmooth type ) { // have the non-exterior derivative calculated for finding the parabola. for( unsigned j = 0; j< d[0].size(); ++j ) { for( unsigned k = 0; k < 3; ++k ) { // Loop over colors - unsigned z = d.size()-1; - if( type == SP_MESH_SMOOTH_SMOOTH7 || type == SP_MESH_SMOOTH_SMOOTH ) { - - // Parabolic - double d0 = Geom::distance( d[1][j].p, d[0 ][j].p ); - if( d0 > 0 ) { - d[0][j].g[k][1] = 2.0*(d[1][j].g[k][0] - d[0 ][j].g[k][0])/d0 - d[1][j].g[k][1]; - } else { - d[0][j].g[k][1] = 0; - } - - double dz = Geom::distance( d[z][j].p, d[z-1][j].p ); - if( dz > 0 ) { - d[z][j].g[k][1] = 2.0*(d[z][j].g[k][0] - d[z-1][j].g[k][0])/dz - d[z-1][j].g[k][1]; - } else { - d[z][j].g[k][1] = 0; - } + // Parabolic + double d0 = Geom::distance( d[1][j].p, d[0 ][j].p ); + if( d0 > 0 ) { + d[0][j].g[k][1] = 2.0*(d[1][j].g[k][0] - d[0 ][j].g[k][0])/d0 - d[1][j].g[k][1]; } else { + d[0][j].g[k][1] = 0; + } - // Catmul-Rom - double d0 = Geom::distance( d[1][j].p, d[0 ][j].p ); - if( d0 > 0 ) { - d[0][j].g[k][1] = (d[1][j].g[k][0] - d[0 ][j].g[k][0])/d0; - } else { - d[0][j].g[k][1] = 0; - } - - double dz = Geom::distance( d[z][j].p, d[z-1][j].p ); - if( dz > 0 ) { - d[z][j].g[k][1] = (d[z][j].g[k][0] - d[z-1][j].g[k][0])/dz; - } else { - d[z][j].g[k][1] = 0; - } + unsigned z = d.size()-1; + double dz = Geom::distance( d[z][j].p, d[z-1][j].p ); + if( dz > 0 ) { + d[z][j].g[k][1] = 2.0*(d[z][j].g[k][0] - d[z-1][j].g[k][0])/dz - d[z-1][j].g[k][1]; + } else { + d[z][j].g[k][1] = 0; } } } for( unsigned i = 0; i< d.size(); ++i ) { for( unsigned k = 0; k < 3; ++k ) { // Loop over colors - unsigned z = d[0].size()-1; - if( type == SP_MESH_SMOOTH_SMOOTH7 || type == SP_MESH_SMOOTH_SMOOTH ) { - - // Parabolic - double d0 = Geom::distance( d[i][1].p, d[i][0 ].p ); - if( d0 > 0 ) { - d[i][0].g[k][2] = 2.0*(d[i][1].g[k][0] - d[i][0 ].g[k][0])/d0 - d[i][1].g[k][2]; - } else { - d[i][0].g[k][2] = 0; - } - double dz = Geom::distance( d[i][z].p, d[i][z-1].p ); - if( dz > 0 ) { - d[i][z].g[k][2] = 2.0*(d[i][z].g[k][0] - d[i][z-1].g[k][0])/dz - d[i][z-1].g[k][2]; - } else { - d[i][z].g[k][2] = 0; - } - + // Parabolic + double d0 = Geom::distance( d[i][1].p, d[i][0 ].p ); + if( d0 > 0 ) { + d[i][0].g[k][2] = 2.0*(d[i][1].g[k][0] - d[i][0 ].g[k][0])/d0 - d[i][1].g[k][2]; } else { + d[i][0].g[k][2] = 0; + } - // Catmul-Rom - double d0 = Geom::distance( d[i][1].p, d[i][0 ].p ); - if( d0 > 0 ) { - d[i][0].g[k][2] = (d[i][1].g[k][0] - d[i][0 ].g[k][0])/d0; - } else { - d[i][0].g[k][2] = 0; - } - - double dz = Geom::distance( d[i][z].p, d[i][z-1].p ); - if( dz > 0 ) { - d[i][z].g[k][2] = (d[i][z].g[k][0] - d[i][z-1].g[k][0])/dz; - } else { - d[i][z].g[k][2] = 0; - } + unsigned z = d[0].size()-1; + double dz = Geom::distance( d[i][z].p, d[i][z-1].p ); + if( dz > 0 ) { + d[i][z].g[k][2] = 2.0*(d[i][z].g[k][0] - d[i][z-1].g[k][0])/dz - d[i][z-1].g[k][2]; + } else { + d[i][z].g[k][2] = 0; } } } @@ -2964,7 +2620,7 @@ guint32 average_color(guint32 c1, guint32 c2, gdouble p); /** Split a row into n equal parts. */ -void SPMeshNodeArray::split_row( guint row, guint n ) { +void SPMeshNodeArray::split_row( unsigned int row, unsigned int n ) { double nn = n; if( n > 1 ) split_row( row, (nn-1)/nn ); @@ -2974,7 +2630,7 @@ void SPMeshNodeArray::split_row( guint row, guint n ) { /** Split a column into n equal parts. */ -void SPMeshNodeArray::split_column( guint col, guint n ) { +void SPMeshNodeArray::split_column( unsigned int col, unsigned int n ) { double nn = n; if( n > 1 ) split_column( col, (nn-1)/nn ); @@ -2984,7 +2640,7 @@ void SPMeshNodeArray::split_column( guint col, guint n ) { /** Split a row into two rows at coord (fraction of row height). */ -void SPMeshNodeArray::split_row( guint row, double coord ) { +void SPMeshNodeArray::split_row( unsigned int row, double coord ) { // std::cout << "Splitting row: " << row << " at " << coord << std::endl; // print(); @@ -3107,7 +2763,7 @@ void SPMeshNodeArray::split_row( guint row, double coord ) { /** Split a column into two columns at coord (fraction of column width). */ -void SPMeshNodeArray::split_column( guint col, double coord ) { +void SPMeshNodeArray::split_column( unsigned int col, double coord ) { // std::cout << "Splitting column: " << col << " at " << coord << std::endl; // print(); diff --git a/src/sp-mesh-array.h b/src/sp-mesh-array.h index 19f8634f8..b078b221e 100644 --- a/src/sp-mesh-array.h +++ b/src/sp-mesh-array.h @@ -45,16 +45,14 @@ // For color picking #include "sp-item.h" -enum SPMeshSmooth { - SP_MESH_SMOOTH_NONE, - SP_MESH_SMOOTH_SMOOTH, - SP_MESH_SMOOTH_SMOOTH1, - SP_MESH_SMOOTH_SMOOTH2, - SP_MESH_SMOOTH_SMOOTH3, - SP_MESH_SMOOTH_SMOOTH4, - SP_MESH_SMOOTH_SMOOTH5, - SP_MESH_SMOOTH_SMOOTH6, - SP_MESH_SMOOTH_SMOOTH7 +enum SPMeshType { + SP_MESH_TYPE_COONS, + SP_MESH_TYPE_BICUBIC +}; + +enum SPMeshGeometry { + SP_MESH_GEOMETRY_NORMAL, + SP_MESH_GEOMETRY_CONICAL }; enum NodeType { @@ -137,14 +135,14 @@ public: void setOpacity( unsigned int i, double o ); }; -class SPMeshGradient; +class SPMesh; // An array of mesh nodes. class SPMeshNodeArray { // Should be private public: - SPMeshGradient *mg; + SPMesh *mg; std::vector< std::vector< SPMeshNode* > > nodes; public: @@ -159,22 +157,21 @@ public: friend class SPMeshPatchI; SPMeshNodeArray() { built = false; mg = NULL; drag_valid = false; }; - SPMeshNodeArray( SPMeshGradient *mg ); + SPMeshNodeArray( SPMesh *mg ); SPMeshNodeArray( const SPMeshNodeArray& rhs ); SPMeshNodeArray& operator=(const SPMeshNodeArray& rhs); ~SPMeshNodeArray() { clear(); }; bool built; - void read( SPMeshGradient *mg ); - void write( SPMeshGradient *mg ); - void create( SPMeshGradient *mg, SPItem *item, Geom::OptRect bbox ); + void read( SPMesh *mg ); + void write( SPMesh *mg ); + void create( SPMesh *mg, SPItem *item, Geom::OptRect bbox ); void clear(); void print(); // Fill 'smooth' with a smoothed version by subdividing each patch. - void smooth( SPMeshNodeArray* smooth, SPMeshSmooth type); - void smooth2( SPMeshNodeArray* smooth, SPMeshSmooth type); + void bicubic( SPMeshNodeArray* smooth, SPMeshType type); // Get size of patch unsigned int patch_rows(); diff --git a/src/sp-mesh-gradient.cpp b/src/sp-mesh-gradient.cpp deleted file mode 100644 index 5c6a2f9da..000000000 --- a/src/sp-mesh-gradient.cpp +++ /dev/null @@ -1,310 +0,0 @@ -#include <glibmm.h> - -#include "attributes.h" -#include "display/cairo-utils.h" -#include "xml/repr.h" - -#include "sp-mesh-gradient.h" - -#include "sp-factory.h" - -namespace { - SPObject* createMeshGradient() { - return new SPMeshGradient(); - } - - bool meshGradientRegistered = SPFactory::instance().registerObject("svg:meshGradient", createMeshGradient); -} - - -/* - * Mesh Gradient - */ -//#define MESH_DEBUG -SPMeshGradient::SPMeshGradient() : SPGradient(), smooth(SP_MESH_SMOOTH_NONE), smooth_set(false) { - // Start coordinate of mesh - this->x.unset(SVGLength::NONE, 0.0, 0.0); - this->y.unset(SVGLength::NONE, 0.0, 0.0); -} - -SPMeshGradient::~SPMeshGradient() { -} - -void SPMeshGradient::build(SPDocument *document, Inkscape::XML::Node *repr) { - SPGradient::build(document, repr); - - // Start coordinate of mesh - this->readAttr( "x" ); - this->readAttr( "y" ); - - this->readAttr( "smooth" ); -} - - -void SPMeshGradient::set(unsigned key, gchar const *value) { - switch (key) { - case SP_ATTR_X: - if (!this->x.read(value)) { - this->x.unset(SVGLength::NONE, 0.0, 0.0); - } - - this->requestModified(SP_OBJECT_MODIFIED_FLAG); - break; - - case SP_ATTR_Y: - if (!this->y.read(value)) { - this->y.unset(SVGLength::NONE, 0.0, 0.0); - } - - this->requestModified(SP_OBJECT_MODIFIED_FLAG); - break; - - case SP_ATTR_SMOOTH: - if (value) { - if (!strcmp(value, "none")) { - this->smooth = SP_MESH_SMOOTH_NONE; - } else if (!strcmp(value, "smooth")) { - this->smooth = SP_MESH_SMOOTH_SMOOTH; - } else if (!strcmp(value, "smooth1")) { - this->smooth = SP_MESH_SMOOTH_SMOOTH1; - } else if (!strcmp(value, "smooth2")) { - this->smooth = SP_MESH_SMOOTH_SMOOTH2; - } else if (!strcmp(value, "smooth3")) { - this->smooth = SP_MESH_SMOOTH_SMOOTH3; - } else if (!strcmp(value, "smooth4")) { - this->smooth = SP_MESH_SMOOTH_SMOOTH4; - } else if (!strcmp(value, "smooth5")) { - this->smooth = SP_MESH_SMOOTH_SMOOTH5; - } else if (!strcmp(value, "smooth6")) { - this->smooth = SP_MESH_SMOOTH_SMOOTH6; - } else if (!strcmp(value, "smooth7")) { - this->smooth = SP_MESH_SMOOTH_SMOOTH7; - } else { - std::cout << "SPMeshGradient::set(): invalid value " << value << std::endl; - } - this->smooth_set = TRUE; - } else { - // std::cout << "SPMeshGradient::set() No value " << std::endl; - this->smooth = SP_MESH_SMOOTH_NONE; - this->smooth_set = FALSE; - } - - this->requestModified(SP_OBJECT_MODIFIED_FLAG); - break; - - default: - SPGradient::set(key, value); - break; - } -} - -/** - * Write mesh gradient attributes to associated repr. - */ -Inkscape::XML::Node* SPMeshGradient::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { -#ifdef MESH_DEBUG - std::cout << "sp_meshgradient_write() ***************************" << std::endl; -#endif - - if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { - repr = xml_doc->createElement("svg:meshGradient"); - } - - if ((flags & SP_OBJECT_WRITE_ALL) || this->x._set) { - sp_repr_set_svg_double(repr, "x", this->x.computed); - } - - if ((flags & SP_OBJECT_WRITE_ALL) || this->y._set) { - sp_repr_set_svg_double(repr, "y", this->y.computed); - } - - if ((flags & SP_OBJECT_WRITE_ALL) || this->smooth_set) { - switch (this->smooth) { - case SP_MESH_SMOOTH_SMOOTH: - repr->setAttribute("smooth", "smooth"); - break; - case SP_MESH_SMOOTH_SMOOTH1: - repr->setAttribute("smooth", "smooth1"); - break; - case SP_MESH_SMOOTH_SMOOTH2: - repr->setAttribute("smooth", "smooth2"); - break; - case SP_MESH_SMOOTH_SMOOTH3: - repr->setAttribute("smooth", "smooth3"); - break; - case SP_MESH_SMOOTH_SMOOTH4: - repr->setAttribute("smooth", "smooth4"); - break; - case SP_MESH_SMOOTH_SMOOTH5: - repr->setAttribute("smooth", "smooth5"); - break; - case SP_MESH_SMOOTH_SMOOTH6: - repr->setAttribute("smooth", "smooth6"); - break; - case SP_MESH_SMOOTH_SMOOTH7: - repr->setAttribute("smooth", "smooth7"); - break; - case SP_MESH_SMOOTH_NONE: - repr->setAttribute("smooth", "none"); - break; - default: - // Do nothing - break; - } - } - - SPGradient::write(xml_doc, repr, flags); - - return repr; -} - -void -sp_meshgradient_repr_write(SPMeshGradient *mg) -{ - mg->array.write( mg ); -} - - -cairo_pattern_t* SPMeshGradient::pattern_new(cairo_t * /*ct*/, -#if defined(MESH_DEBUG) || (CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 11, 4)) - Geom::OptRect const &bbox, - double opacity -#else - Geom::OptRect const & /*bbox*/, - double /*opacity*/ -#endif - ) -{ - using Geom::X; - using Geom::Y; - -#ifdef MESH_DEBUG - std::cout << "sp_meshgradient_create_pattern: (" << bbox->x0 << "," << bbox->y0 << ") (" << bbox->x1 << "," << bbox->y1 << ") " << opacity << std::endl; -#endif - - this->ensureArray(); - - cairo_pattern_t *cp = NULL; - -#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 11, 4) - SPMeshNodeArray* my_array = &array; - - if( smooth_set ) { - switch (smooth) { - case SP_MESH_SMOOTH_NONE: - // std::cout << "SPMeshGradient::pattern_new: no smoothing" << std::endl; - break; - case SP_MESH_SMOOTH_SMOOTH1: - case SP_MESH_SMOOTH_SMOOTH2: - case SP_MESH_SMOOTH_SMOOTH3: - case SP_MESH_SMOOTH_SMOOTH4: - case SP_MESH_SMOOTH_SMOOTH5: - // std::cout << "SPMeshGradient::pattern_new: calling array.smooth" << std::endl; - array.smooth( &array_smoothed, smooth ); - my_array = &array_smoothed; - break; - case SP_MESH_SMOOTH_SMOOTH: - case SP_MESH_SMOOTH_SMOOTH6: - case SP_MESH_SMOOTH_SMOOTH7: - // std::cout << "SPMeshGradient::pattern_new: calling array.smooth2" << std::endl; - array.smooth2( &array_smoothed, smooth ); - my_array = &array_smoothed; - break; - } - } - - cp = cairo_pattern_create_mesh(); - - for( unsigned int i = 0; i < my_array->patch_rows(); ++i ) { - for( unsigned int j = 0; j < my_array->patch_columns(); ++j ) { - - SPMeshPatchI patch( &(my_array->nodes), i, j ); - - cairo_mesh_pattern_begin_patch( cp ); - cairo_mesh_pattern_move_to( cp, patch.getPoint( 0, 0 )[X], patch.getPoint( 0, 0 )[Y] ); - - for( unsigned int k = 0; k < 4; ++k ) { -#ifdef DEBUG_MESH - std::cout << i << " " << j << " " - << patch.getPathType( k ) << " ("; - for( int p = 0; p < 4; ++p ) { - std::cout << patch.getPoint( k, p ); - } - std::cout << ") " - << patch.getColor( k ).toString() << std::endl; -#endif - - switch ( patch.getPathType( k ) ) { - case 'l': - case 'L': - case 'z': - case 'Z': - cairo_mesh_pattern_line_to( cp, - patch.getPoint( k, 3 )[X], - patch.getPoint( k, 3 )[Y] ); - break; - case 'c': - case 'C': - { - std::vector< Geom::Point > pts = patch.getPointsForSide( k ); - cairo_mesh_pattern_curve_to( cp, - pts[1][X], pts[1][Y], - pts[2][X], pts[2][Y], - pts[3][X], pts[3][Y] ); - break; - } - default: - // Shouldn't happen - std::cout << "sp_meshgradient_create_pattern: path error" << std::endl; - } - - if( patch.tensorIsSet(k) ) { - // Tensor point defined relative to corner. - Geom::Point t = patch.getTensorPoint(k); - cairo_mesh_pattern_set_control_point( cp, k, t[X], t[Y] ); - //std::cout << " sp_meshgradient_create_pattern: tensor " << k - // << " set to " << t << "." << std::endl; - } else { - // Geom::Point t = patch.coonsTensorPoint(k); - //std::cout << " sp_meshgradient_create_pattern: tensor " << k - // << " calculated as " << t << "." <<std::endl; - } - - cairo_mesh_pattern_set_corner_color_rgba( - cp, k, - patch.getColor( k ).v.c[0], - patch.getColor( k ).v.c[1], - patch.getColor( k ).v.c[2], - patch.getOpacity( k ) * opacity ); - } - - cairo_mesh_pattern_end_patch( cp ); - } - } - - // set pattern matrix - Geom::Affine gs2user = this->gradientTransform; - if (this->getUnits() == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) { - Geom::Affine bbox2user(bbox->width(), 0, 0, bbox->height(), bbox->left(), bbox->top()); - gs2user *= bbox2user; - } - ink_cairo_pattern_set_matrix(cp, gs2user.inverse()); - -#else - static bool shown = false; - if( !shown ) { - std::cout << "sp_meshgradient_create_pattern: needs cairo >= 1.11.4, using " - << cairo_version_string() << std::endl; - shown = true; - } -#endif - -/* - cairo_pattern_t *cp = cairo_pattern_create_radial( - rg->fx.computed, rg->fy.computed, 0, - rg->cx.computed, rg->cy.computed, rg->r.computed); - sp_gradient_pattern_common_setup(cp, gr, bbox, opacity); -*/ - - return cp; -} diff --git a/src/sp-mesh-patch.cpp b/src/sp-mesh-patch.cpp index 216de8270..834c09935 100644 --- a/src/sp-mesh-patch.cpp +++ b/src/sp-mesh-patch.cpp @@ -20,19 +20,9 @@ #include "attributes.h" #include "xml/repr.h" -#include "sp-factory.h" - -namespace { - SPObject* createMeshPatch() { - return new SPMeshPatch(); - } - - bool meshPatchRegistered = SPFactory::instance().registerObject("svg:meshPatch", createMeshPatch); -} - -SPMeshPatch* SPMeshPatch::getNextMeshPatch() +SPMeshpatch* SPMeshpatch::getNextMeshpatch() { - SPMeshPatch *result = 0; + SPMeshpatch *result = 0; for (SPObject* obj = getNext(); obj && !result; obj = obj->getNext()) { if (SP_IS_MESHPATCH(obj)) { @@ -43,19 +33,19 @@ SPMeshPatch* SPMeshPatch::getNextMeshPatch() return result; } -SPMeshPatch* SPMeshPatch::getPrevMeshPatch() +SPMeshpatch* SPMeshpatch::getPrevMeshpatch() { - SPMeshPatch *result = 0; + SPMeshpatch *result = 0; for (SPObject* obj = getPrev(); obj; obj = obj->getPrev()) { - // The closest previous SPObject that is an SPMeshPatch *should* be ourself. + // The closest previous SPObject that is an SPMeshpatch *should* be ourself. if (SP_IS_MESHPATCH(obj)) { - SPMeshPatch* meshpatch = SP_MESHPATCH(obj); + SPMeshpatch* meshpatch = SP_MESHPATCH(obj); // Sanity check to ensure we have a proper sibling structure. - if (meshpatch->getNextMeshPatch() == this) { + if (meshpatch->getNextMeshpatch() == this) { result = meshpatch; } else { - g_warning("SPMeshPatch previous/next relationship broken"); + g_warning("SPMeshpatch previous/next relationship broken"); } break; } @@ -69,14 +59,14 @@ SPMeshPatch* SPMeshPatch::getPrevMeshPatch() * Mesh Patch */ -SPMeshPatch::SPMeshPatch() : SPObject() { +SPMeshpatch::SPMeshpatch() : SPObject() { this->tensor_string = NULL; } -SPMeshPatch::~SPMeshPatch() { +SPMeshpatch::~SPMeshpatch() { } -void SPMeshPatch::build(SPDocument* doc, Inkscape::XML::Node* repr) { +void SPMeshpatch::build(SPDocument* doc, Inkscape::XML::Node* repr) { SPObject::build(doc, repr); this->readAttr( "tensor" ); @@ -86,7 +76,7 @@ void SPMeshPatch::build(SPDocument* doc, Inkscape::XML::Node* repr) { * Virtual build: set meshpatch attributes from its associated XML node. */ -void SPMeshPatch::set(unsigned int key, const gchar* value) { +void SPMeshpatch::set(unsigned int key, const gchar* value) { switch (key) { case SP_ATTR_TENSOR: { if (value) { @@ -105,9 +95,9 @@ void SPMeshPatch::set(unsigned int key, const gchar* value) { * Virtual set: set attribute to value. */ -Inkscape::XML::Node* SPMeshPatch::write(Inkscape::XML::Document* xml_doc, Inkscape::XML::Node* repr, guint flags) { +Inkscape::XML::Node* SPMeshpatch::write(Inkscape::XML::Document* xml_doc, Inkscape::XML::Node* repr, guint flags) { if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { - repr = xml_doc->createElement("svg:meshPatch"); + repr = xml_doc->createElement("svg:meshpatch"); } SPObject::write(xml_doc, repr, flags); diff --git a/src/sp-mesh-patch.h b/src/sp-mesh-patch.h index e57ad1699..88d6325c3 100644 --- a/src/sp-mesh-patch.h +++ b/src/sp-mesh-patch.h @@ -2,7 +2,7 @@ #define SEEN_SP_MESHPATCH_H /** \file - * SPMeshPatch: SVG <meshpatch> implementation. + * SPMeshpatch: SVG <meshpatch> implementation. */ /* * Authors: Tavmjong Bah @@ -15,17 +15,17 @@ #include <glibmm/ustring.h> #include "sp-object.h" -#define SP_MESHPATCH(obj) (dynamic_cast<SPMeshPatch*>((SPObject*)obj)) -#define SP_IS_MESHPATCH(obj) (dynamic_cast<const SPMeshPatch*>((SPObject*)obj) != NULL) +#define SP_MESHPATCH(obj) (dynamic_cast<SPMeshpatch*>((SPObject*)obj)) +#define SP_IS_MESHPATCH(obj) (dynamic_cast<const SPMeshpatch*>((SPObject*)obj) != NULL) -/** Gradient MeshPatch. */ -class SPMeshPatch : public SPObject { +/** Gradient Meshpatch. */ +class SPMeshpatch : public SPObject { public: - SPMeshPatch(); - virtual ~SPMeshPatch(); + SPMeshpatch(); + virtual ~SPMeshpatch(); - SPMeshPatch* getNextMeshPatch(); - SPMeshPatch* getPrevMeshPatch(); + SPMeshpatch* getNextMeshpatch(); + SPMeshpatch* getPrevMeshpatch(); Glib::ustring * tensor_string; //SVGLength tx[4]; // Tensor points //SVGLength ty[4]; // Tensor points diff --git a/src/sp-mesh-row.cpp b/src/sp-mesh-row.cpp index 07747f7f5..dd7948bdf 100644 --- a/src/sp-mesh-row.cpp +++ b/src/sp-mesh-row.cpp @@ -1,5 +1,5 @@ /** @file - * @gradient meshpatch class. + * @gradient meshrow class. */ /* Authors: * Lauris Kaplinski <lauris@kaplinski.com> @@ -19,19 +19,9 @@ #include "xml/repr.h" -#include "sp-factory.h" - -namespace { - SPObject* createMeshRow() { - return new SPMeshRow(); - } - - bool meshRowRegistered = SPFactory::instance().registerObject("svg:meshRow", createMeshRow); -} - -SPMeshRow* SPMeshRow::getNextMeshRow() +SPMeshrow* SPMeshrow::getNextMeshrow() { - SPMeshRow *result = 0; + SPMeshrow *result = 0; for (SPObject* obj = getNext(); obj && !result; obj = obj->getNext()) { if (SP_IS_MESHROW(obj)) { @@ -42,19 +32,19 @@ SPMeshRow* SPMeshRow::getNextMeshRow() return result; } -SPMeshRow* SPMeshRow::getPrevMeshRow() +SPMeshrow* SPMeshrow::getPrevMeshrow() { - SPMeshRow *result = 0; + SPMeshrow *result = 0; for (SPObject* obj = getPrev(); obj; obj = obj->getPrev()) { - // The closest previous SPObject that is an SPMeshRow *should* be ourself. + // The closest previous SPObject that is an SPMeshrow *should* be ourself. if (SP_IS_MESHROW(obj)) { - SPMeshRow* meshrow = SP_MESHROW(obj); + SPMeshrow* meshrow = SP_MESHROW(obj); // Sanity check to ensure we have a proper sibling structure. - if (meshrow->getNextMeshRow() == this) { + if (meshrow->getNextMeshrow() == this) { result = meshrow; } else { - g_warning("SPMeshRow previous/next relationship broken"); + g_warning("SPMeshrow previous/next relationship broken"); } break; } @@ -67,13 +57,13 @@ SPMeshRow* SPMeshRow::getPrevMeshRow() /* * Mesh Row */ -SPMeshRow::SPMeshRow() : SPObject() { +SPMeshrow::SPMeshrow() : SPObject() { } -SPMeshRow::~SPMeshRow() { +SPMeshrow::~SPMeshrow() { } -void SPMeshRow::build(SPDocument* doc, Inkscape::XML::Node* repr) { +void SPMeshrow::build(SPDocument* doc, Inkscape::XML::Node* repr) { SPObject::build(doc, repr); } @@ -81,16 +71,16 @@ void SPMeshRow::build(SPDocument* doc, Inkscape::XML::Node* repr) { * Virtual build: set meshrow attributes from its associated XML node. */ -void SPMeshRow::set(unsigned int /*key*/, const gchar* /*value*/) { +void SPMeshrow::set(unsigned int /*key*/, const gchar* /*value*/) { } /** * Virtual set: set attribute to value. */ -Inkscape::XML::Node* SPMeshRow::write(Inkscape::XML::Document* xml_doc, Inkscape::XML::Node* repr, guint flags) { +Inkscape::XML::Node* SPMeshrow::write(Inkscape::XML::Document* xml_doc, Inkscape::XML::Node* repr, guint flags) { if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { - repr = xml_doc->createElement("svg:meshRow"); + repr = xml_doc->createElement("svg:meshrow"); } SPObject::write(xml_doc, repr, flags); diff --git a/src/sp-mesh-row.h b/src/sp-mesh-row.h index 793b5a645..ffb3efa6b 100644 --- a/src/sp-mesh-row.h +++ b/src/sp-mesh-row.h @@ -2,7 +2,7 @@ #define SEEN_SP_MESHROW_H /** \file - * SPMeshRow: SVG <meshRow> implementation. + * SPMeshrow: SVG <meshrow> implementation. */ /* * Authors: Tavmjong Bah @@ -13,17 +13,17 @@ #include "sp-object.h" -#define SP_MESHROW(obj) (dynamic_cast<SPMeshRow*>((SPObject*)obj)) -#define SP_IS_MESHROW(obj) (dynamic_cast<const SPMeshRow*>((SPObject*)obj) != NULL) +#define SP_MESHROW(obj) (dynamic_cast<SPMeshrow*>((SPObject*)obj)) +#define SP_IS_MESHROW(obj) (dynamic_cast<const SPMeshrow*>((SPObject*)obj) != NULL) -/** Gradient MeshRow. */ -class SPMeshRow : public SPObject { +/** Gradient Meshrow. */ +class SPMeshrow : public SPObject { public: - SPMeshRow(); - virtual ~SPMeshRow(); + SPMeshrow(); + virtual ~SPMeshrow(); - SPMeshRow* getNextMeshRow(); - SPMeshRow* getPrevMeshRow(); + SPMeshrow* getNextMeshrow(); + SPMeshrow* getPrevMeshrow(); protected: virtual void build(SPDocument* doc, Inkscape::XML::Node* repr); diff --git a/src/sp-mesh.cpp b/src/sp-mesh.cpp new file mode 100644 index 000000000..e04c29e8e --- /dev/null +++ b/src/sp-mesh.cpp @@ -0,0 +1,252 @@ +#include <glibmm.h> + +#include "attributes.h" +#include "display/cairo-utils.h" +#include "xml/repr.h" + +#include "sp-mesh.h" + +/* + * Mesh Gradient + */ +//#define MESH_DEBUG +SPMesh::SPMesh() : SPGradient(), type( SP_MESH_TYPE_COONS ), type_set(false) { + // Start coordinate of mesh + this->x.unset(SVGLength::NONE, 0.0, 0.0); + this->y.unset(SVGLength::NONE, 0.0, 0.0); +} + +SPMesh::~SPMesh() { +} + +void SPMesh::build(SPDocument *document, Inkscape::XML::Node *repr) { + SPGradient::build(document, repr); + + // Start coordinate of mesh + this->readAttr( "x" ); + this->readAttr( "y" ); + + this->readAttr( "type" ); +} + + +void SPMesh::set(unsigned key, gchar const *value) { + switch (key) { + case SP_ATTR_X: + if (!this->x.read(value)) { + this->x.unset(SVGLength::NONE, 0.0, 0.0); + } + + this->requestModified(SP_OBJECT_MODIFIED_FLAG); + break; + + case SP_ATTR_Y: + if (!this->y.read(value)) { + this->y.unset(SVGLength::NONE, 0.0, 0.0); + } + + this->requestModified(SP_OBJECT_MODIFIED_FLAG); + break; + + case SP_ATTR_TYPE: + if (value) { + if (!strcmp(value, "coons")) { + this->type = SP_MESH_TYPE_COONS; + } else if (!strcmp(value, "bicubic")) { + this->type = SP_MESH_TYPE_BICUBIC; + } else { + std::cerr << "SPMesh::set(): invalid value " << value << std::endl; + } + this->type_set = TRUE; + } else { + // std::cout << "SPMesh::set() No value " << std::endl; + this->type = SP_MESH_TYPE_COONS; + this->type_set = FALSE; + } + + this->requestModified(SP_OBJECT_MODIFIED_FLAG); + break; + + default: + SPGradient::set(key, value); + break; + } +} + +/** + * Write mesh gradient attributes to associated repr. + */ +Inkscape::XML::Node* SPMesh::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { +#ifdef MESH_DEBUG + std::cout << "sp_mesh_write() ***************************" << std::endl; +#endif + + if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { + repr = xml_doc->createElement("svg:mesh"); + } + + if ((flags & SP_OBJECT_WRITE_ALL) || this->x._set) { + sp_repr_set_svg_double(repr, "x", this->x.computed); + } + + if ((flags & SP_OBJECT_WRITE_ALL) || this->y._set) { + sp_repr_set_svg_double(repr, "y", this->y.computed); + } + + if ((flags & SP_OBJECT_WRITE_ALL) || this->type_set) { + switch (this->type) { + case SP_MESH_TYPE_COONS: + repr->setAttribute("type", "coons"); + break; + case SP_MESH_TYPE_BICUBIC: + repr->setAttribute("type", "bicubic"); + break; + default: + // Do nothing + break; + } + } + + SPGradient::write(xml_doc, repr, flags); + + return repr; +} + +void +sp_mesh_repr_write(SPMesh *mg) +{ + mg->array.write( mg ); +} + + +cairo_pattern_t* SPMesh::pattern_new(cairo_t * /*ct*/, +#if defined(MESH_DEBUG) || (CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 11, 4)) + Geom::OptRect const &bbox, + double opacity +#else + Geom::OptRect const & /*bbox*/, + double /*opacity*/ +#endif + ) +{ + using Geom::X; + using Geom::Y; + +#ifdef MESH_DEBUG + std::cout << "sp_mesh_create_pattern: (" << bbox->x0 << "," << bbox->y0 << ") (" << bbox->x1 << "," << bbox->y1 << ") " << opacity << std::endl; +#endif + + this->ensureArray(); + + cairo_pattern_t *cp = NULL; + +#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 11, 4) + SPMeshNodeArray* my_array = &array; + + if( type_set ) { + switch (type) { + case SP_MESH_TYPE_COONS: + // std::cout << "SPMesh::pattern_new: Coons" << std::endl; + break; + case SP_MESH_TYPE_BICUBIC: + array.bicubic( &array_smoothed, type ); + my_array = &array_smoothed; + break; + } + } + + cp = cairo_pattern_create_mesh(); + + for( unsigned int i = 0; i < my_array->patch_rows(); ++i ) { + for( unsigned int j = 0; j < my_array->patch_columns(); ++j ) { + + SPMeshPatchI patch( &(my_array->nodes), i, j ); + + cairo_mesh_pattern_begin_patch( cp ); + cairo_mesh_pattern_move_to( cp, patch.getPoint( 0, 0 )[X], patch.getPoint( 0, 0 )[Y] ); + + for( unsigned int k = 0; k < 4; ++k ) { +#ifdef DEBUG_MESH + std::cout << i << " " << j << " " + << patch.getPathType( k ) << " ("; + for( int p = 0; p < 4; ++p ) { + std::cout << patch.getPoint( k, p ); + } + std::cout << ") " + << patch.getColor( k ).toString() << std::endl; +#endif + + switch ( patch.getPathType( k ) ) { + case 'l': + case 'L': + case 'z': + case 'Z': + cairo_mesh_pattern_line_to( cp, + patch.getPoint( k, 3 )[X], + patch.getPoint( k, 3 )[Y] ); + break; + case 'c': + case 'C': + { + std::vector< Geom::Point > pts = patch.getPointsForSide( k ); + cairo_mesh_pattern_curve_to( cp, + pts[1][X], pts[1][Y], + pts[2][X], pts[2][Y], + pts[3][X], pts[3][Y] ); + break; + } + default: + // Shouldn't happen + std::cout << "sp_mesh_create_pattern: path error" << std::endl; + } + + if( patch.tensorIsSet(k) ) { + // Tensor point defined relative to corner. + Geom::Point t = patch.getTensorPoint(k); + cairo_mesh_pattern_set_control_point( cp, k, t[X], t[Y] ); + //std::cout << " sp_mesh_create_pattern: tensor " << k + // << " set to " << t << "." << std::endl; + } else { + // Geom::Point t = patch.coonsTensorPoint(k); + //std::cout << " sp_mesh_create_pattern: tensor " << k + // << " calculated as " << t << "." <<std::endl; + } + + cairo_mesh_pattern_set_corner_color_rgba( + cp, k, + patch.getColor( k ).v.c[0], + patch.getColor( k ).v.c[1], + patch.getColor( k ).v.c[2], + patch.getOpacity( k ) * opacity ); + } + + cairo_mesh_pattern_end_patch( cp ); + } + } + + // set pattern matrix + Geom::Affine gs2user = this->gradientTransform; + if (this->getUnits() == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) { + Geom::Affine bbox2user(bbox->width(), 0, 0, bbox->height(), bbox->left(), bbox->top()); + gs2user *= bbox2user; + } + ink_cairo_pattern_set_matrix(cp, gs2user.inverse()); + +#else + static bool shown = false; + if( !shown ) { + std::cout << "sp_mesh_create_pattern: needs cairo >= 1.11.4, using " + << cairo_version_string() << std::endl; + shown = true; + } +#endif + + /* + cairo_pattern_t *cp = cairo_pattern_create_radial( + rg->fx.computed, rg->fy.computed, 0, + rg->cx.computed, rg->cy.computed, rg->r.computed); + sp_gradient_pattern_common_setup(cp, gr, bbox, opacity); + */ + + return cp; +} diff --git a/src/sp-mesh-gradient.h b/src/sp-mesh.h index 343cae840..6f992d034 100644 --- a/src/sp-mesh-gradient.h +++ b/src/sp-mesh.h @@ -1,26 +1,26 @@ -#ifndef SP_MESH_GRADIENT_H -#define SP_MESH_GRADIENT_H +#ifndef SP_MESH_H +#define SP_MESH_H /** \file - * SPMeshGradient: SVG <meshgradient> implementation. + * SPMesh: SVG <mesh> implementation. */ #include "svg/svg-length.h" #include "sp-gradient.h" -#define SP_MESHGRADIENT(obj) (dynamic_cast<SPMeshGradient*>((SPObject*)obj)) -#define SP_IS_MESHGRADIENT(obj) (dynamic_cast<const SPMeshGradient*>((SPObject*)obj) != NULL) +#define SP_MESH(obj) (dynamic_cast<SPMesh*>((SPObject*)obj)) +#define SP_IS_MESH(obj) (dynamic_cast<const SPMesh*>((SPObject*)obj) != NULL) /** Mesh gradient. */ -class SPMeshGradient : public SPGradient { +class SPMesh : public SPGradient { public: - SPMeshGradient(); - virtual ~SPMeshGradient(); + SPMesh(); + virtual ~SPMesh(); SVGLength x; // Upper left corner of mesh SVGLength y; // Upper right corner of mesh - SPMeshSmooth smooth; - bool smooth_set; + SPMeshType type; + bool type_set; virtual cairo_pattern_t* pattern_new(cairo_t *ct, Geom::OptRect const &bbox, double opacity); protected: @@ -29,7 +29,7 @@ protected: virtual Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, unsigned int flags); }; -#endif /* !SP_MESH_GRADIENT_H */ +#endif /* !SP_MESH_H */ /* Local Variables: diff --git a/src/sp-metadata.cpp b/src/sp-metadata.cpp index bf4ce27a1..6bdc2f0b9 100644 --- a/src/sp-metadata.cpp +++ b/src/sp-metadata.cpp @@ -33,16 +33,6 @@ /* Metadata base class */ -#include "sp-factory.h" - -namespace { - SPObject* createMetadata() { - return new SPMetadata(); - } - - bool metadataRegistered = SPFactory::instance().registerObject("svg:metadata", createMetadata); -} - SPMetadata::SPMetadata() : SPObject() { } diff --git a/src/sp-missing-glyph.cpp b/src/sp-missing-glyph.cpp index 06b741165..75de55693 100644 --- a/src/sp-missing-glyph.cpp +++ b/src/sp-missing-glyph.cpp @@ -19,16 +19,6 @@ #include "sp-missing-glyph.h" #include "document.h" -#include "sp-factory.h" - -namespace { - SPObject* createMissingGlyph() { - return new SPMissingGlyph(); - } - - bool missingGlyphRegistered = SPFactory::instance().registerObject("svg:missing-glyph", createMissingGlyph); -} - SPMissingGlyph::SPMissingGlyph() : SPObject() { //TODO: correct these values: this->d = NULL; diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index dc36e68b9..3154c9e7b 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -56,16 +56,6 @@ static void sp_namedview_show_single_guide(SPGuide* guide, bool show); static gboolean sp_str_to_bool(const gchar *str); static gboolean sp_nv_read_opacity(const gchar *str, guint32 *color); -#include "sp-factory.h" - -namespace { - SPObject* createNamedView() { - return new SPNamedView(); - } - - bool namedViewRegistered = SPFactory::instance().registerObject("sodipodi:namedview", createNamedView); -} - SPNamedView::SPNamedView() : SPObjectGroup(), snap_manager(this) { this->zoom = 0; this->guidecolor = 0; @@ -271,6 +261,8 @@ void SPNamedView::build(SPDocument *document, Inkscape::XML::Node *repr) { Geom::Rect viewbox = document->getRoot()->viewBox; double factor = svgwidth.value(unit_table.primary(Inkscape::Util::UNIT_TYPE_LINEAR)) / viewbox.width(); svg_units = unit_table.findUnit(factor, Inkscape::Util::UNIT_TYPE_LINEAR); + } else { // force the document units to be px + repr->setAttribute("inkscape:document-units", "px"); } } @@ -561,7 +553,7 @@ void SPNamedView::set(unsigned int key, const gchar* value) { static Inkscape::Util::Unit const *px = unit_table.getUnit("px"); Inkscape::Util::Unit const *new_unit = px; - if (value) { + if (value && document->getRoot()->viewBox_set) { Inkscape::Util::Unit const *const req_unit = unit_table.getUnit(value); if ( !unit_table.hasUnit(value) ) { g_warning("Unrecognized unit `%s'", value); diff --git a/src/sp-object.cpp b/src/sp-object.cpp index 7d24a978e..343db435e 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -61,14 +61,6 @@ using std::strstr; # define debug(f, a...) /* */ #endif -namespace { - SPObject* createObject() { - return new SPObject(); - } - - bool gridRegistered = SPFactory::instance().registerObject("inkscape:grid", createObject); -} - guint update_in_progress = 0; // guard against update-during-update Inkscape::XML::NodeEventVector object_event_vector = { @@ -115,7 +107,7 @@ static gchar *sp_object_get_unique_id(SPObject *object, SPObject::SPObject() : cloned(0), uflags(0), mflags(0), hrefcount(0), _total_hrefcount(0), document(NULL), parent(NULL), children(NULL), _last_child(NULL), - next(NULL), id(NULL), repr(NULL), refCount(1), + next(NULL), id(NULL), repr(NULL), refCount(1),hrefList(std::list<SPObject*>()), _successor(NULL), _collection_policy(SPObject::COLLECT_WITH_PARENT), _label(NULL), _default_label(NULL) { @@ -254,7 +246,7 @@ SPObject *sp_object_unref(SPObject *object, SPObject *owner) return NULL; } -SPObject *sp_object_href(SPObject *object, gpointer /*owner*/) +SPObject *sp_object_href(SPObject *object, SPObject* owner) { g_return_val_if_fail(object != NULL, NULL); g_return_val_if_fail(SP_IS_OBJECT(object), NULL); @@ -262,10 +254,13 @@ SPObject *sp_object_href(SPObject *object, gpointer /*owner*/) object->hrefcount++; object->_updateTotalHRefCount(1); + if(owner) + object->hrefList.push_front(owner); + return object; } -SPObject *sp_object_hunref(SPObject *object, gpointer /*owner*/) +SPObject *sp_object_hunref(SPObject *object, SPObject* owner) { g_return_val_if_fail(object != NULL, NULL); g_return_val_if_fail(SP_IS_OBJECT(object), NULL); @@ -274,6 +269,9 @@ SPObject *sp_object_hunref(SPObject *object, gpointer /*owner*/) object->hrefcount--; object->_updateTotalHRefCount(-1); + if(owner) + object->hrefList.remove(owner); + return NULL; } @@ -623,7 +621,7 @@ void SPObject::child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) const std::string type_string = NodeTraits::get_type_string(*child); - SPObject* ochild = SPFactory::instance().createObject(type_string); + SPObject* ochild = SPFactory::createObject(type_string); if (ochild == NULL) { // Currenty, there are many node types that do not have // corresponding classes in the SPObject tree. @@ -682,7 +680,7 @@ void SPObject::build(SPDocument *document, Inkscape::XML::Node *repr) { for (Inkscape::XML::Node *rchild = repr->firstChild() ; rchild != NULL; rchild = rchild->next()) { const std::string typeString = NodeTraits::get_type_string(*rchild); - SPObject* child = SPFactory::instance().createObject(typeString); + SPObject* child = SPFactory::createObject(typeString); if (child == NULL) { // Currenty, there are many node types that do not have // corresponding classes in the SPObject tree. diff --git a/src/sp-object.h b/src/sp-object.h index ff80eaefc..ab0b444b6 100644 --- a/src/sp-object.h +++ b/src/sp-object.h @@ -157,7 +157,7 @@ SPObject *sp_object_unref(SPObject *object, SPObject *owner=NULL); * \pre object points to real object * @todo need to move this to be a member of SPObject. */ -SPObject *sp_object_href(SPObject *object, void* owner); +SPObject *sp_object_href(SPObject *object, SPObject* owner); /** * Decrease weak refcount. @@ -169,7 +169,7 @@ SPObject *sp_object_href(SPObject *object, void* owner); * \pre object points to real object and hrefcount>0 * @todo need to move this to be a member of SPObject. */ -SPObject *sp_object_hunref(SPObject *object, void* owner); +SPObject *sp_object_hunref(SPObject *object, SPObject* owner); /** * SPObject is an abstract base class of all of the document nodes at the @@ -218,6 +218,7 @@ private: Inkscape::XML::Node *repr; /* Our xml representation */ public: int refCount; + std::list<SPObject*> hrefList; /** * Returns the objects current ID string. diff --git a/src/sp-offset.cpp b/src/sp-offset.cpp index 3aa1e4eb6..15d3821c7 100644 --- a/src/sp-offset.cpp +++ b/src/sp-offset.cpp @@ -43,16 +43,6 @@ class SPDocument; -#include "sp-factory.h" - -namespace { - SPObject* createOffset() { - return new SPOffset(); - } - - bool offsetRegistered = SPFactory::instance().registerObject("inkscape:offset", createOffset); -} - #define noOFFSET_VERBOSE /** \note diff --git a/src/sp-path.cpp b/src/sp-path.cpp index 0fef57698..42883588b 100644 --- a/src/sp-path.cpp +++ b/src/sp-path.cpp @@ -51,16 +51,6 @@ #define noPATH_VERBOSE -#include "sp-factory.h" - -namespace { - SPObject* createPath() { - return new SPPath(); - } - - bool pathRegistered = SPFactory::instance().registerObject("svg:path", createPath); -} - gint SPPath::nodesInPath() const { return _curve ? _curve->nodes_in_path() : 0; @@ -140,10 +130,29 @@ void SPPath::build(SPDocument *document, Inkscape::XML::Node *repr) { SPShape::build(document, repr); - // this->readAttr( "inkscape:original-d" ); // lp1299948 + // this->readAttr( "inkscape:original-d" ); // bug #1299948 + // Why we take the long way of doing this probably needs some explaining: + // + // Normally upon being built, reading the inkscape:original-d attribute + // will cause the path to actually _write to its repr_ in response to this. + // This is bad, bad news if the attached effect refers to a path which + // hasn't been constructed yet. + // + // What will happen is the effect parameter will cause the effect to + // recalculate with a completely different value due to the parameter being + // "empty" -- even worse, an undo event might be created with the bad value, + // and undoing the current action could cause it to revert to the "bad" + // state. (After that, the referred object will be constructed and the + // reference will trigger the path effect to update and commit the right + // value to "d".) + // + // This mild nastiness here (don't recalculate effects on build) prevents a + // plethora of issues with effects with linked parameters doing wild and + // stupid things on new documents upon a mere undo. + if (gchar const* s = this->getRepr()->attribute("inkscape:original-d")) { - // write it to XML, and to my curve, but don't update patheffects + // Write the value to _curve_before_lpe, do not recalculate effects Geom::PathVector pv = sp_svg_read_pathv(s); SPCurve *curve = new SPCurve(pv); @@ -158,10 +167,17 @@ void SPPath::build(SPDocument *document, Inkscape::XML::Node *repr) { this->readAttr( "d" ); /* d is a required attribute */ - gchar const *d = this->getAttribute("d", NULL); + char const *d = this->getAttribute("d", NULL); if (d == NULL) { - this->setKeyValue( sp_attribute_lookup("d"), ""); + // First see if calculating the path effect will generate "d": + this->update_patheffect(true); + d = this->getAttribute("d", NULL); + + // I guess that didn't work, now we have nothing useful to write ("") + if (d == NULL) { + this->setKeyValue( sp_attribute_lookup("d"), ""); + } } } diff --git a/src/sp-pattern.cpp b/src/sp-pattern.cpp index 961ab0f84..987a86fe4 100644 --- a/src/sp-pattern.cpp +++ b/src/sp-pattern.cpp @@ -45,16 +45,6 @@ static void pattern_ref_changed(SPObject *old_ref, SPObject *ref, SPPattern *pat); static void pattern_ref_modified (SPObject *ref, guint flags, SPPattern *pattern); -#include "sp-factory.h" - -namespace { - SPObject* createPattern() { - return new SPPattern(); - } - - bool patternRegistered = SPFactory::instance().registerObject("svg:pattern", createPattern); -} - SPPattern::SPPattern() : SPPaintServer(), SPViewBox() { this->href = NULL; diff --git a/src/sp-polygon.cpp b/src/sp-polygon.cpp index 302905a62..af71280d5 100644 --- a/src/sp-polygon.cpp +++ b/src/sp-polygon.cpp @@ -11,8 +11,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "config.h" - #include "attributes.h" #include "sp-polygon.h" #include "display/curve.h" @@ -25,16 +23,6 @@ #include "xml/repr.h" #include "document.h" -#include "sp-factory.h" - -namespace { - SPObject* createPolygon() { - return new SPPolygon(); - } - - bool polygonRegistered = SPFactory::instance().registerObject("svg:polygon", createPolygon); -} - SPPolygon::SPPolygon() : SPShape() { } diff --git a/src/sp-polyline.cpp b/src/sp-polyline.cpp index c80190097..a12f927b5 100644 --- a/src/sp-polyline.cpp +++ b/src/sp-polyline.cpp @@ -20,16 +20,6 @@ #include "xml/repr.h" #include "document.h" -#include "sp-factory.h" - -namespace { - SPObject* createPolyLine() { - return new SPPolyLine(); - } - - bool polyLineRegistered = SPFactory::instance().registerObject("svg:polyline", createPolyLine); -} - SPPolyLine::SPPolyLine() : SPShape() { } diff --git a/src/sp-radial-gradient.cpp b/src/sp-radial-gradient.cpp index 2c2b17b7d..8fb230ba7 100644 --- a/src/sp-radial-gradient.cpp +++ b/src/sp-radial-gradient.cpp @@ -5,17 +5,7 @@ #include "attributes.h" #include "xml/repr.h" -#include "2geom/transforms.h" - -#include "sp-factory.h" - -namespace { - SPObject* createRadialGradient() { - return new SPRadialGradient(); - } - - bool radialGradientRegistered = SPFactory::instance().registerObject("svg:radialGradient", createRadialGradient); -} +#include <2geom/transforms.h> /* * Radial Gradient diff --git a/src/sp-rect.cpp b/src/sp-rect.cpp index af3e2bfb4..e17d7373c 100644 --- a/src/sp-rect.cpp +++ b/src/sp-rect.cpp @@ -31,16 +31,6 @@ #define noRECT_VERBOSE -#include "sp-factory.h" - -namespace { - SPObject* createRect() { - return new SPRect(); - } - - bool rectRegistered = SPFactory::instance().registerObject("svg:rect", createRect); -} - SPRect::SPRect() : SPShape() { } @@ -62,22 +52,30 @@ void SPRect::build(SPDocument* doc, Inkscape::XML::Node* repr) { void SPRect::set(unsigned key, gchar const *value) { /* fixme: We need real error processing some time */ + // We must update the SVGLengths immediately or nodes may be misplaced after they are moved. + double const w = viewport.width(); + double const h = viewport.height(); + double const em = style->font_size.computed; + double const ex = em * 0.5; + switch (key) { case SP_ATTR_X: - this->x.readOrUnset(value); - this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + this->x.readOrUnset(value); + this->x.update( ex, em, w ); + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; case SP_ATTR_Y: - this->y.readOrUnset(value); - this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + this->y.readOrUnset(value); + this->y.update( ex, em, h ); + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; case SP_ATTR_WIDTH: if (!this->width.read(value) || this->width.value < 0.0) { this->width.unset(); } - + this->width.update( ex, em, w ); this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; @@ -85,7 +83,7 @@ void SPRect::set(unsigned key, gchar const *value) { if (!this->height.read(value) || this->height.value < 0.0) { this->height.unset(); } - + this->height.update( ex, em, h ); this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; @@ -93,7 +91,7 @@ void SPRect::set(unsigned key, gchar const *value) { if (!this->rx.read(value) || this->rx.value <= 0.0) { this->rx.unset(); } - + this->rx.update( ex, em, w ); this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; @@ -101,7 +99,7 @@ void SPRect::set(unsigned key, gchar const *value) { if (!this->ry.read(value) || this->ry.value <= 0.0) { this->ry.unset(); } - + this->ry.update( ex, em, h ); this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; @@ -139,19 +137,19 @@ Inkscape::XML::Node * SPRect::write(Inkscape::XML::Document *xml_doc, Inkscape:: repr = xml_doc->createElement("svg:rect"); } - sp_repr_set_svg_double(repr, "width", this->width.computed); - sp_repr_set_svg_double(repr, "height", this->height.computed); + sp_repr_set_svg_length(repr, "width", this->width); + sp_repr_set_svg_length(repr, "height", this->height); if (this->rx._set) { - sp_repr_set_svg_double(repr, "rx", this->rx.computed); + sp_repr_set_svg_length(repr, "rx", this->rx); } if (this->ry._set) { - sp_repr_set_svg_double(repr, "ry", this->ry.computed); + sp_repr_set_svg_length(repr, "ry", this->ry); } - sp_repr_set_svg_double(repr, "x", this->x.computed); - sp_repr_set_svg_double(repr, "y", this->y.computed); + sp_repr_set_svg_length(repr, "x", this->x); + sp_repr_set_svg_length(repr, "y", this->y); this->set_shape(); // evaluate SPCurve SPShape::write(xml_doc, repr, flags); @@ -245,29 +243,29 @@ void SPRect::set_shape() { /* fixme: Think (Lauris) */ void SPRect::setPosition(gdouble x, gdouble y, gdouble width, gdouble height) { - this->x.computed = x; - this->y.computed = y; - this->width.computed = width; - this->height.computed = height; + this->x = x; + this->y = y; + this->width = width; + this->height = height; this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } void SPRect::setRx(bool set, gdouble value) { - this->rx._set = set; + this->rx._set = set; if (set) { - this->rx.computed = value; + this->rx = value; } this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } void SPRect::setRy(bool set, gdouble value) { - this->ry._set = set; + this->ry._set = set; if (set) { - this->ry.computed = value; + this->ry = value; } this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); @@ -299,16 +297,16 @@ Geom::Affine SPRect::set_transform(Geom::Affine const& xform) { ret[3] = 1.0; } - /* fixme: Would be nice to preserve units here */ - this->width = this->width.computed * sw; - this->height = this->height.computed * sh; + /* Preserve units */ + this->width.scale( sw ); + this->height.scale( sh ); if (this->rx._set) { - this->rx = this->rx.computed * sw; + this->rx.scale( sw ); } if (this->ry._set) { - this->ry = this->ry.computed * sh; + this->ry.scale( sh ); } /* Find start in item coords */ @@ -346,15 +344,12 @@ gdouble SPRect::vectorStretch(Geom::Point p0, Geom::Point p1, Geom::Affine xform void SPRect::setVisibleRx(gdouble rx) { if (rx == 0) { - this->rx.computed = 0; - this->rx._set = false; + this->rx.unset(); } else { - this->rx.computed = rx / SPRect::vectorStretch( + this->rx = rx / SPRect::vectorStretch( Geom::Point(this->x.computed + 1, this->y.computed), Geom::Point(this->x.computed, this->y.computed), - this->transform); - - this->rx._set = true; + this->i2doc_affine()); } this->updateRepr(); @@ -362,15 +357,12 @@ void SPRect::setVisibleRx(gdouble rx) { void SPRect::setVisibleRy(gdouble ry) { if (ry == 0) { - this->ry.computed = 0; - this->ry._set = false; + this->ry.unset(); } else { - this->ry.computed = ry / SPRect::vectorStretch( + this->ry = ry / SPRect::vectorStretch( Geom::Point(this->x.computed, this->y.computed + 1), Geom::Point(this->x.computed, this->y.computed), - this->transform); - - this->ry._set = true; + this->i2doc_affine()); } this->updateRepr(); @@ -384,7 +376,7 @@ gdouble SPRect::getVisibleRx() const { return this->rx.computed * SPRect::vectorStretch( Geom::Point(this->x.computed + 1, this->y.computed), Geom::Point(this->x.computed, this->y.computed), - this->transform); + this->i2doc_affine()); } gdouble SPRect::getVisibleRy() const { @@ -395,7 +387,7 @@ gdouble SPRect::getVisibleRy() const { return this->ry.computed * SPRect::vectorStretch( Geom::Point(this->x.computed, this->y.computed + 1), Geom::Point(this->x.computed, this->y.computed), - this->transform); + this->i2doc_affine()); } Geom::Rect SPRect::getRect() const { @@ -428,37 +420,33 @@ void SPRect::compensateRxRy(Geom::Affine xform) { // This is needed because if we just set them the same length in SVG, they might end up unequal because of transform if ((this->rx._set && !this->ry._set) || (this->ry._set && !this->rx._set)) { gdouble r = MAX(this->rx.computed, this->ry.computed); - this->rx.computed = r / eX; - this->ry.computed = r / eY; + this->rx = r / eX; + this->ry = r / eY; } else { - this->rx.computed = this->rx.computed / eX; - this->ry.computed = this->ry.computed / eY; + this->rx = this->rx.computed / eX; + this->ry = this->ry.computed / eY; } // Note that a radius may end up larger than half-side if the rect is scaled down; // that's ok because this preserves the intended radii in case the rect is enlarged again, // and set_shape will take care of trimming too large radii when generating d= - - this->rx._set = this->ry._set = true; } void SPRect::setVisibleWidth(gdouble width) { - this->width.computed = width / SPRect::vectorStretch( + this->width = width / SPRect::vectorStretch( Geom::Point(this->x.computed + 1, this->y.computed), Geom::Point(this->x.computed, this->y.computed), - this->transform); + this->i2doc_affine()); - this->width._set = true; - this->updateRepr(); + this->updateRepr(); } void SPRect::setVisibleHeight(gdouble height) { - this->height.computed = height / SPRect::vectorStretch( + this->height = height / SPRect::vectorStretch( Geom::Point(this->x.computed, this->y.computed + 1), Geom::Point(this->x.computed, this->y.computed), - this->transform); + this->i2doc_affine()); - this->height._set = true; this->updateRepr(); } @@ -470,7 +458,7 @@ gdouble SPRect::getVisibleWidth() const { return this->width.computed * SPRect::vectorStretch( Geom::Point(this->x.computed + 1, this->y.computed), Geom::Point(this->x.computed, this->y.computed), - this->transform); + this->i2doc_affine()); } gdouble SPRect::getVisibleHeight() const { @@ -481,7 +469,7 @@ gdouble SPRect::getVisibleHeight() const { return this->height.computed * SPRect::vectorStretch( Geom::Point(this->x.computed, this->y.computed + 1), Geom::Point(this->x.computed, this->y.computed), - this->transform); + this->i2doc_affine()); } void SPRect::snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs) const { diff --git a/src/sp-root.cpp b/src/sp-root.cpp index 85582e209..8bedec0a5 100644 --- a/src/sp-root.cpp +++ b/src/sp-root.cpp @@ -13,10 +13,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include <string> #include <2geom/transforms.h> @@ -30,17 +26,7 @@ #include "svg/stringstream.h" #include "svg/svg.h" #include "xml/repr.h" - -#include "sp-factory.h" - -namespace { -SPObject *createRoot() -{ - return new SPRoot(); -} - -bool rootRegistered = SPFactory::instance().registerObject("svg:svg", createRoot); -} +#include "util/units.h" SPRoot::SPRoot() : SPGroup(), SPViewBox() { @@ -298,7 +284,7 @@ void SPRoot::update(SPCtx *ctx, guint flags) SPItemCtx rctx = *ictx; rctx.viewport = Geom::Rect::from_xywh( this->x.computed, this->y.computed, this->width.computed, this->height.computed ); - rctx = get_rctx( &rctx ); + rctx = get_rctx( &rctx, Inkscape::Util::Quantity::convert(1, this->document->getDisplayUnit(), "px") ); /* And invoke parent method */ SPGroup::update((SPCtx *) &rctx, flags); diff --git a/src/sp-script.cpp b/src/sp-script.cpp index 260b3dcfd..f1ea9c9bd 100644 --- a/src/sp-script.cpp +++ b/src/sp-script.cpp @@ -16,16 +16,6 @@ #include <cstring> #include "document.h" -#include "sp-factory.h" - -namespace { - SPObject* createScript() { - return new SPScript(); - } - - bool scriptRegistered = SPFactory::instance().registerObject("svg:script", createScript); -} - SPScript::SPScript() : SPObject() { this->xlinkhref = NULL; } diff --git a/src/sp-shape.cpp b/src/sp-shape.cpp index 16f9ec13b..78135d459 100644 --- a/src/sp-shape.cpp +++ b/src/sp-shape.cpp @@ -47,7 +47,7 @@ #include "bad-uri-exception.h" #include "xml/repr.h" -#include "util/mathfns.h" // for triangle_area() +#include "helper/mathfns.h" // for triangle_area() #include "splivarot.h" // for bounding box calculation diff --git a/src/sp-solid-color.cpp b/src/sp-solid-color.cpp index 72569d8c0..f319410b0 100644 --- a/src/sp-solid-color.cpp +++ b/src/sp-solid-color.cpp @@ -16,18 +16,9 @@ #include "style.h" #include "xml/repr.h" -#include "sp-factory.h" #include "sp-item.h" #include "style-internal.h" -namespace { - SPObject* createSolidColor() { - return new SPSolidColor(); - } - - bool solidColorRegistered = SPFactory::instance().registerObject("svg:solidColor", createSolidColor); -} - /* * Solid Color diff --git a/src/sp-spiral.cpp b/src/sp-spiral.cpp index 9ef73d56d..5dbd7dfa0 100644 --- a/src/sp-spiral.cpp +++ b/src/sp-spiral.cpp @@ -28,16 +28,6 @@ #include "sp-spiral.h" -#include "sp-factory.h" - -namespace { - SPObject* createSpiral() { - return new SPSpiral(); - } - - bool spiralRegistered = SPFactory::instance().registerObject("spiral", createSpiral); -} - SPSpiral::SPSpiral() : SPShape() , cx(0) diff --git a/src/sp-star.cpp b/src/sp-star.cpp index 97a690520..51d5e6254 100644 --- a/src/sp-star.cpp +++ b/src/sp-star.cpp @@ -32,16 +32,6 @@ #include "sp-star.h" -#include "sp-factory.h" - -namespace { - SPObject* createStar() { - return new SPStar(); - } - - bool starRegistered = SPFactory::instance().registerObject("star", createStar); -} - SPStar::SPStar() : SPPolygon() { this->sides = 5; this->center = Geom::Point(0, 0); diff --git a/src/sp-stop.cpp b/src/sp-stop.cpp index 3ee467322..5e8fed86c 100644 --- a/src/sp-stop.cpp +++ b/src/sp-stop.cpp @@ -24,16 +24,6 @@ #include "svg/css-ostringstream.h" #include "xml/repr.h" -#include "sp-factory.h" - -namespace { - SPObject* createStop() { - return new SPStop(); - } - - bool stopRegistered = SPFactory::instance().registerObject("svg:stop", createStop); -} - SPStop::SPStop() : SPObject() { this->path_string = NULL; diff --git a/src/sp-string.cpp b/src/sp-string.cpp index b561187d0..26bb44006 100644 --- a/src/sp-string.cpp +++ b/src/sp-string.cpp @@ -22,30 +22,13 @@ * */ - - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - - #include "sp-string.h" #include "style.h" #include "xml/repr.h" -#include "sp-factory.h" - #include <iostream> -namespace { - SPObject* createString() { - return new SPString(); - } - - bool stringRegistered = SPFactory::instance().registerObject("string", createString); -} - /*##################################################### # SPSTRING #####################################################*/ diff --git a/src/sp-style-elem.cpp b/src/sp-style-elem.cpp index 668780272..80e45677c 100644 --- a/src/sp-style-elem.cpp +++ b/src/sp-style-elem.cpp @@ -7,16 +7,6 @@ #include "style.h" using Inkscape::XML::TEXT_NODE; -#include "sp-factory.h" - -namespace { - SPObject* createStyle() { - return new SPStyleElem(); - } - - bool styleRegistered = SPFactory::instance().registerObject("svg:style", createStyle); -} - SPStyleElem::SPStyleElem() : SPObject() { media_set_all(this->media); this->is_css = false; diff --git a/src/sp-switch.cpp b/src/sp-switch.cpp index db6db9909..66cec3637 100644 --- a/src/sp-switch.cpp +++ b/src/sp-switch.cpp @@ -12,10 +12,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include <glibmm/i18n.h> #include "sp-switch.h" @@ -25,16 +21,6 @@ #include <sigc++/functors/ptr_fun.h> #include <sigc++/adaptors/bind.h> -#include "sp-factory.h" - -namespace { - SPObject* createSwitch() { - return new SPSwitch(); - } - - bool switchRegistered = SPFactory::instance().registerObject("svg:switch", createSwitch); -} - SPSwitch::SPSwitch() : SPGroup() { this->_cached_item = 0; } diff --git a/src/sp-symbol.cpp b/src/sp-symbol.cpp index 3156680b3..62fb232a3 100644 --- a/src/sp-symbol.cpp +++ b/src/sp-symbol.cpp @@ -26,16 +26,6 @@ #include "sp-symbol.h" #include "document.h" -#include "sp-factory.h" - -namespace { - SPObject* createSymbol() { - return new SPSymbol(); - } - - bool symbolRegistered = SPFactory::instance().registerObject("svg:symbol", createSymbol); -} - SPSymbol::SPSymbol() : SPGroup(), SPViewBox() { } diff --git a/src/sp-tag-use-reference.cpp b/src/sp-tag-use-reference.cpp index 50c011812..220cd16d1 100644 --- a/src/sp-tag-use-reference.cpp +++ b/src/sp-tag-use-reference.cpp @@ -20,16 +20,6 @@ #include "sp-text.h" #include "uri.h" -#if 0 -namespace { - SPObject* createTagUseReference() { - return new SPTag(); - } - bool tagUseReferencesRegistered = SPFactory::instance().registerObject("inkscape:tag", createTag); -} -// this SPObject doesn't need to be registered -#endif - bool SPTagUseReference::_acceptObject(SPObject * const obj) const { diff --git a/src/sp-tag-use.cpp b/src/sp-tag-use.cpp index 5851598f2..935f7429e 100644 --- a/src/sp-tag-use.cpp +++ b/src/sp-tag-use.cpp @@ -10,10 +10,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - #include <cstring> #include <string> @@ -30,13 +26,6 @@ #include "sp-tag-use.h" #include "sp-tag-use-reference.h" -namespace { - SPObject* createTagUse() { - return new SPTagUse(); - } - bool tagUseRegistered = SPFactory::instance().registerObject("inkscape:tagref", createTagUse); -} - SPTagUse::SPTagUse() { href = NULL; @@ -173,7 +162,7 @@ SPTagUse::href_changed(SPObject */*old_ref*/, SPObject */*ref*/) Inkscape::XML::Node *childrepr = refobj->getRepr(); const std::string typeString = NodeTraits::get_type_string(*childrepr); - SPObject* child_ = SPFactory::instance().createObject(typeString); + SPObject* child_ = SPFactory::createObject(typeString); if (child_) { child = child_; attach(child_, lastChild()); diff --git a/src/sp-tag.cpp b/src/sp-tag.cpp index c4b40417f..d331e6b18 100644 --- a/src/sp-tag.cpp +++ b/src/sp-tag.cpp @@ -10,23 +10,11 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include "attributes.h" -#include "sp-factory.h" #include "sp-tag.h" #include "xml/repr.h" #include <cstring> -namespace { - SPObject* createTag() { - return new SPTag(); - } - bool tagsRegistered = SPFactory::instance().registerObject("inkscape:tag", createTag); -} - /* * Move this SPItem into or after another SPItem in the doc * \param target - the SPItem to move into or after diff --git a/src/sp-text.cpp b/src/sp-text.cpp index e40661824..0dca42bb4 100644 --- a/src/sp-text.cpp +++ b/src/sp-text.cpp @@ -23,10 +23,6 @@ * */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include <2geom/affine.h> #include <libnrtype/FontFactory.h> #include <libnrtype/font-instance.h> @@ -55,22 +51,12 @@ #include "text-editing.h" -#include "sp-factory.h" - // For SVG 2 text flow #include "livarot/Path.h" #include "livarot/Shape.h" #include "sp-shape.h" #include "display/curve.h" -namespace { - SPObject* createText() { - return new SPText(); - } - - bool textRegistered = SPFactory::instance().registerObject("svg:text", createText); -} - /*##################################################### # SPTEXT #####################################################*/ diff --git a/src/sp-title.cpp b/src/sp-title.cpp index 4ecfcfa8e..ba5ae754a 100644 --- a/src/sp-title.cpp +++ b/src/sp-title.cpp @@ -9,23 +9,9 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include "sp-title.h" #include "xml/repr.h" -#include "sp-factory.h" - -namespace { - SPObject* createTitle() { - return new SPTitle(); - } - - bool titleRegistered = SPFactory::instance().registerObject("svg:title", createTitle); -} - SPTitle::SPTitle() : SPObject() { } diff --git a/src/sp-tref.cpp b/src/sp-tref.cpp index 6a229e170..aef18462a 100644 --- a/src/sp-tref.cpp +++ b/src/sp-tref.cpp @@ -16,10 +16,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #include <glibmm/i18n.h> #include "attributes.h" @@ -35,14 +31,6 @@ #include "xml/node.h" #include "xml/repr.h" -namespace { - SPObject* createTRef() { - return new SPTRef(); - } - - bool trefRegistered = SPFactory::instance().registerObject("svg:tref", createTRef); -} - //#define DEBUG_TREF #ifdef DEBUG_TREF # define debug(f, a...) { g_message("%s(%d) %s:", \ @@ -413,7 +401,7 @@ void sp_tref_update_text(SPTRef *tref) Inkscape::XML::Document *xml_doc = tref->document->getReprDoc(); Inkscape::XML::Node *newStringRepr = xml_doc->createTextNode(charData.c_str()); - tref->stringChild = SPFactory::instance().createObject(NodeTraits::get_type_string(*newStringRepr)); + tref->stringChild = SPFactory::createObject(NodeTraits::get_type_string(*newStringRepr)); // Add this SPString as a child of the tref tref->attach(tref->stringChild, tref->lastChild()); diff --git a/src/sp-tspan.cpp b/src/sp-tspan.cpp index 147efff33..7582cb9e6 100644 --- a/src/sp-tspan.cpp +++ b/src/sp-tspan.cpp @@ -44,21 +44,6 @@ #include "document.h" #include "2geom/transforms.h" -#include "sp-factory.h" - -namespace { - SPObject* createTSpan() { - return new SPTSpan(); - } - - SPObject* createTextPath() { - return new SPTextPath(); - } - - bool tspanRegistered = SPFactory::instance().registerObject("svg:tspan", createTSpan); - bool textPathRegistered = SPFactory::instance().registerObject("svg:textPath", createTextPath); -} - /*##################################################### # SPTSPAN #####################################################*/ diff --git a/src/sp-use.cpp b/src/sp-use.cpp index 7e02de3c1..239f487a4 100644 --- a/src/sp-use.cpp +++ b/src/sp-use.cpp @@ -13,10 +13,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - #include <cstring> #include <string> @@ -42,14 +38,6 @@ #include "sp-text.h" #include "sp-flowtext.h" -namespace { - SPObject* createUse() { - return new SPUse(); - } - - bool useRegistered = SPFactory::instance().registerObject("svg:use", createUse); -} - SPUse::SPUse() : SPItem(), child(NULL), @@ -482,7 +470,7 @@ void SPUse::href_changed() { if (refobj) { Inkscape::XML::Node *childrepr = refobj->getRepr(); - SPObject* obj = SPFactory::instance().createObject(NodeTraits::get_type_string(*childrepr)); + SPObject* obj = SPFactory::createObject(NodeTraits::get_type_string(*childrepr)); SPItem *item = dynamic_cast<SPItem *>(obj); if (item) { diff --git a/src/splivarot.cpp b/src/splivarot.cpp index 8bb3e9897..46279cbce 100644 --- a/src/splivarot.cpp +++ b/src/splivarot.cpp @@ -1727,7 +1727,9 @@ void sp_selected_path_create_offset_object(SPDesktop *desktop, int expand, bool if ( !updating ) { // delete original, apply the transform to the offset + const char *n_id = item->getRepr()->attribute("id"); item->deleteObject(false); + repr->setAttribute("id", n_id); nitem->doWriteTransform(repr, transform); } diff --git a/src/svg/svg-length-test.h b/src/svg/svg-length-test.h index 796943e45..0dac4854a 100644 --- a/src/svg/svg-length-test.h +++ b/src/svg/svg-length-test.h @@ -102,7 +102,10 @@ public: for ( int i = (static_cast<int>(SVGLength::NONE) + 1); i <= static_cast<int>(SVGLength::LAST_UNIT); i++ ) { SVGLength::Unit target = static_cast<SVGLength::Unit>(i); // PX is a special case where we don't have a unit string - if ( (target != SVGLength::PX) && (target != SVGLength::FOOT) ) { + // FOOT and MITRE are not CSS/SVG Units + if ( (target != SVGLength::PX) && + (target != SVGLength::FOOT) && + (target != SVGLength::MITRE) ) { gchar const* val = sp_svg_length_get_css_units(target); TSM_ASSERT_DIFFERS(i, val, ""); } diff --git a/src/svg/svg-length.cpp b/src/svg/svg-length.cpp index ea235b2e4..edbc59c36 100644 --- a/src/svg/svg-length.cpp +++ b/src/svg/svg-length.cpp @@ -14,6 +14,7 @@ #include <cstring> #include <string> #include <glib.h> +#include <iostream> #include "svg.h" #include "stringstream.h" @@ -462,6 +463,51 @@ unsigned int sp_svg_length_read_ldd(gchar const *str, SVGLength::Unit *unit, dou return r; } +std::string const SVGLength::write() +{ + return sp_svg_length_write_with_units(*this); +} + +void SVGLength::set(SVGLength::Unit u, float v) +{ + _set = true; + unit = u; + Glib::ustring hack("px"); + switch( unit ) { + case NONE: + case PX: + case EM: + case EX: + case PERCENT: + break; + case PT: + hack = "pt"; + break; + case PC: + hack = "pc"; + break; + case MM: + hack = "pt"; + break; + case CM: + hack = "pt"; + break; + case INCH: + hack = "pt"; + break; + case FOOT: + hack = "pt"; + break; + case MITRE: + hack = "m"; + break; + default: + break; + } + value = v; + computed = Inkscape::Util::Quantity::convert(v, hack, "px"); +} + void SVGLength::set(SVGLength::Unit u, float v, float c) { _set = true; @@ -478,6 +524,12 @@ void SVGLength::unset(SVGLength::Unit u, float v, float c) computed = c; } +void SVGLength::scale(double scale) +{ + value *= scale; + computed *= scale; +} + void SVGLength::update(double em, double ex, double scale) { if (unit == EM) { diff --git a/src/svg/svg-length.h b/src/svg/svg-length.h index 1e6b4c96c..84056dd5f 100644 --- a/src/svg/svg-length.h +++ b/src/svg/svg-length.h @@ -57,9 +57,13 @@ public: bool read(char const *str); void readOrUnset(char const *str, Unit u = NONE, float v = 0, float c = 0); bool readAbsolute(char const *str); - void set(Unit u, float v, float c); + std::string const write(); + // To set 'v' use '=' + void set(Unit u, float v); // Sets computed value based on u and v. + void set(Unit u, float v, float c); // Sets all three values. void unset(Unit u = NONE, float v = 0, float c = 0); - void update(double em, double ex, double scale); + void scale(double scale); // Scales length (value, computed), leaving unit alone. + void update(double em, double ex, double scale); // Updates computed value }; #endif // SEEN_SP_SVG_LENGTH_H diff --git a/src/trace/potrace/inkscape-potrace.cpp b/src/trace/potrace/inkscape-potrace.cpp index 69138463d..e9e708f52 100644 --- a/src/trace/potrace/inkscape-potrace.cpp +++ b/src/trace/potrace/inkscape-potrace.cpp @@ -430,7 +430,7 @@ std::vector<TracingEngineResult> PotraceTracingEngine::traceSingle(GdkPixbuf * t if (!grayMap) return results; - long nodeCount; + long nodeCount = 0L; std::string d = grayMapToPath(grayMap, &nodeCount); grayMap->destroy(grayMap); @@ -456,7 +456,7 @@ std::vector<TracingEngineResult> PotraceTracingEngine::traceGrayMap(GrayMap *gra brightnessFloor = 0.0; //important to set this - long nodeCount; + long nodeCount = 0L; std::string d = grayMapToPath(grayMap, &nodeCount); char const *style = "fill:#000000"; @@ -489,7 +489,7 @@ std::vector<TracingEngineResult> PotraceTracingEngine::traceBrightnessMulti(GdkP brightnessThreshold += delta) { GrayMap *grayMap = filter(*this, thePixbuf); if ( grayMap ) { - long nodeCount; + long nodeCount = 0L; std::string d = grayMapToPath(grayMap, &nodeCount); grayMap->destroy(grayMap); @@ -558,7 +558,7 @@ std::vector<TracingEngineResult> PotraceTracingEngine::traceQuant(GdkPixbuf * th } //## Now we have a traceable graymap - long nodeCount; + long nodeCount = 0L; std::string d = grayMapToPath(gm, &nodeCount); if ( !d.empty() ) { diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 98a5a224c..674254686 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -8,6 +8,7 @@ set(ui_SRC object-edit.cpp previewholder.cpp shape-editor.cpp + tool-factory.cpp tools-switch.cpp uxmanager.cpp diff --git a/src/ui/Makefile_insert b/src/ui/Makefile_insert index 7aeb4a83d..f94cba4e9 100644 --- a/src/ui/Makefile_insert +++ b/src/ui/Makefile_insert @@ -21,6 +21,7 @@ ink_common_sources += \ ui/previewholder.h \ ui/shape-editor.cpp \ ui/shape-editor.h \ + ui/tool-factory.cpp \ ui/tool-factory.h \ ui/tools-switch.cpp \ ui/tools-switch.h \ diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index 94a1eb2dc..f1d0ff576 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -32,7 +32,7 @@ #include <glibmm/ustring.h> #include <glibmm/i18n.h> #include <glib/gstdio.h> // for g_file_set_contents etc., used in _onGet and paste -#include "gc-core.h" +#include "inkgc/gc-core.h" #include "xml/repr.h" #include "inkscape.h" #include "io/stringstream.h" @@ -685,10 +685,18 @@ void ClipboardManagerImpl::_copySelection(Inkscape::Selection *selection) sp_repr_css_set(obj_copy, css, "style"); sp_repr_css_attr_unref(css); + Geom::Affine transform=item->i2doc_affine(); + // write the complete accumulated transform passed to us // (we're dealing with unattached representations, so we write to their attributes // instead of using sp_item_set_transform) - gchar *transform_str = sp_svg_transform_write(item->i2doc_affine()); + SPUse *use=dynamic_cast<SPUse *>(item); + if( use && selection->includes(use->get_original()) ){//we are copying something whose parent is also copied (!) + transform = ((SPItem*)(use->get_original()->parent))->i2doc_affine().inverse() * transform; + } + gchar *transform_str = sp_svg_transform_write(transform ); + + obj_copy->setAttribute("transform", transform_str); g_free(transform_str); } diff --git a/src/ui/dialog/clonetiler.cpp b/src/ui/dialog/clonetiler.cpp index fede30b26..bd3ad0254 100644 --- a/src/ui/dialog/clonetiler.cpp +++ b/src/ui/dialog/clonetiler.cpp @@ -2409,7 +2409,7 @@ void CloneTiler::clonetiler_apply(GtkWidget */*widget*/, GtkWidget *dlg) // Note: We create a clone at 0,0 too, right over the original, in case our clones are colored // Get transform from symmetry, shift, scale, rotation - Geom::Affine t = clonetiler_get_transform (type, i, j, center[Geom::X], center[Geom::Y], w, h, + Geom::Affine orig_t = clonetiler_get_transform (type, i, j, center[Geom::X], center[Geom::Y], w, h, shiftx_per_i, shifty_per_i, shiftx_per_j, shifty_per_j, shiftx_rand, shifty_rand, @@ -2428,7 +2428,8 @@ void CloneTiler::clonetiler_apply(GtkWidget */*widget*/, GtkWidget *dlg) rotate_rand, rotate_alternatei, rotate_alternatej, rotate_cumulatei, rotate_cumulatej ); - + Geom::Affine parent_transform = (((SPItem*)item->parent)->i2doc_affine())*(item->document->getRoot()->c2p.inverse()); + Geom::Affine t = parent_transform*orig_t*parent_transform.inverse(); cur = center * t - center; if (fillrect) { if ((cur[Geom::X] > fillwidth) || (cur[Geom::Y] > fillheight)) { // off limits @@ -2562,7 +2563,9 @@ void CloneTiler::clonetiler_apply(GtkWidget */*widget*/, GtkWidget *dlg) } } if (pick_to_size) { - t = Geom::Translate(-center[Geom::X], -center[Geom::Y]) * Geom::Scale (val, val) * Geom::Translate(center[Geom::X], center[Geom::Y]) * t; + t = parent_transform * Geom::Translate(-center[Geom::X], -center[Geom::Y]) + * Geom::Scale (val, val) * Geom::Translate(center[Geom::X], center[Geom::Y]) + * parent_transform.inverse() * t; } if (pick_to_opacity) { opacity *= val; @@ -2590,7 +2593,7 @@ void CloneTiler::clonetiler_apply(GtkWidget */*widget*/, GtkWidget *dlg) Geom::Point new_center; bool center_set = false; if (obj_repr->attribute("inkscape:transform-center-x") || obj_repr->attribute("inkscape:transform-center-y")) { - new_center = scale_units*desktop->dt2doc(item->getCenter()) * t; + new_center = scale_units*desktop->dt2doc(item->getCenter()) * orig_t; center_set = true; } diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp index af7ca678a..c381ed755 100644 --- a/src/ui/dialog/document-properties.cpp +++ b/src/ui/dialog/document-properties.cpp @@ -87,6 +87,13 @@ static Inkscape::XML::NodeEventVector const _repr_events = { NULL // order_changed }; +static void docprops_style_button(Gtk::Button& btn, char const* iconName) +{ + GtkWidget *child = sp_icon_new(Inkscape::ICON_SIZE_SMALL_TOOLBAR, iconName); + gtk_widget_show( child ); + btn.add(*Gtk::manage(Glib::wrap(child))); + btn.set_relief(Gtk::RELIEF_NONE); +} DocumentProperties& DocumentProperties::getInstance() { @@ -615,22 +622,10 @@ void DocumentProperties::build_cms() label_avail->set_markup (_("<b>Available Color Profiles:</b>")); _link_btn.set_tooltip_text(_("Link Profile")); -#if WITH_GTKMM_3_10 - _link_btn.set_image_from_icon_name(INKSCAPE_ICON("list-add"), Gtk::ICON_SIZE_SMALL_TOOLBAR); -#else - Gtk::Image *image_link = Gtk::manage(new Gtk::Image()); - image_link->set_from_icon_name(INKSCAPE_ICON("list-add"), Gtk::ICON_SIZE_SMALL_TOOLBAR); - _link_btn.set_image(*image_link); -#endif + docprops_style_button(_link_btn, INKSCAPE_ICON("list-add")); _unlink_btn.set_tooltip_text(_("Unlink Profile")); -#if WITH_GTKMM_3_10 - _unlink_btn.set_image_from_icon_name(INKSCAPE_ICON("list-remove"), Gtk::ICON_SIZE_SMALL_TOOLBAR); -#else - Gtk::Image *image_unlink = Gtk::manage(new Gtk::Image()); - image_unlink->set_from_icon_name(INKSCAPE_ICON("list-remove"), Gtk::ICON_SIZE_SMALL_TOOLBAR); - _unlink_btn.set_image(*image_unlink); -#endif + docprops_style_button(_unlink_btn, INKSCAPE_ICON("list-remove")); _page_cms->set_spacing(4); gint row = 0; @@ -752,22 +747,10 @@ void DocumentProperties::build_scripting() label_external->set_markup (_("<b>External script files:</b>")); _external_add_btn.set_tooltip_text(_("Add the current file name or browse for a file")); -#if WITH_GTKMM_3_10 - _external_add_btn.set_image_from_icon_name(INKSCAPE_ICON("list-add"), Gtk::ICON_SIZE_SMALL_TOOLBAR); -#else - Gtk::Image *image_ext_add = Gtk::manage(new Gtk::Image()); - image_ext_add->set_from_icon_name(INKSCAPE_ICON("list-add"), Gtk::ICON_SIZE_SMALL_TOOLBAR); - _external_add_btn.set_image(*image_ext_add); -#endif + docprops_style_button(_external_add_btn, INKSCAPE_ICON("list-add")); _external_remove_btn.set_tooltip_text(_("Remove")); -#if WITH_GTKMM_3_10 - _external_remove_btn.set_image_from_icon_name(INKSCAPE_ICON("list-remove"), Gtk::ICON_SIZE_SMALL_TOOLBAR); -#else - Gtk::Image *image_ext_rm = Gtk::manage(new Gtk::Image()); - image_ext_rm->set_from_icon_name(INKSCAPE_ICON("list-remove"), Gtk::ICON_SIZE_SMALL_TOOLBAR); - _external_remove_btn.set_image(*image_ext_rm); -#endif + docprops_style_button(_external_remove_btn, INKSCAPE_ICON("list-remove")); _page_external_scripts->set_spacing(4); gint row = 0; @@ -841,22 +824,10 @@ void DocumentProperties::build_scripting() label_embedded->set_markup (_("<b>Embedded script files:</b>")); _embed_new_btn.set_tooltip_text(_("New")); -#if WITH_GTKMM_3_10 - _embed_new_btn.set_image_from_icon_name(INKSCAPE_ICON("list-add"), Gtk::ICON_SIZE_SMALL_TOOLBAR); -#else - Gtk::Image *image_embed_new = Gtk::manage(new Gtk::Image()); - image_embed_new->set_from_icon_name(INKSCAPE_ICON("list-add"), Gtk::ICON_SIZE_SMALL_TOOLBAR); - _embed_new_btn.set_image(*image_embed_new); -#endif + docprops_style_button(_embed_new_btn, INKSCAPE_ICON("list-add")); _embed_remove_btn.set_tooltip_text(_("Remove")); -#if WITH_GTKMM_3_10 - _embed_remove_btn.set_image_from_icon_name(INKSCAPE_ICON("list-remove"), Gtk::ICON_SIZE_SMALL_TOOLBAR); -#else - Gtk::Image *image_embed_rm = Gtk::manage(new Gtk::Image()); - image_embed_rm->set_from_icon_name(INKSCAPE_ICON("list-remove"), Gtk::ICON_SIZE_SMALL_TOOLBAR); - _embed_remove_btn.set_image(*image_embed_rm); -#endif + docprops_style_button(_embed_remove_btn, INKSCAPE_ICON("list-remove")); #if !WITH_GTKMM_3_0 // TODO: This has been removed from Gtkmm 3.0. Check that @@ -1502,6 +1473,7 @@ void DocumentProperties::update() } _page_sizer.setDim(Inkscape::Util::Quantity(doc_w, doc_w_unit), Inkscape::Util::Quantity(doc_h, doc_h_unit)); _page_sizer.updateFitMarginsUI(nv->getRepr()); + _page_sizer.updateScaleUI(); //-----------------------------------------------------------guide page @@ -1684,6 +1656,8 @@ void DocumentProperties::onRemoveGrid() } /** Callback for document unit change. */ +/* This should not effect anything in the SVG tree (other than "inkscape:document-units"). + This should only effect values displayed in the GUI. */ void DocumentProperties::onDocUnitChange() { SPDocument *doc = SP_ACTIVE_DOCUMENT; @@ -1709,6 +1683,8 @@ void DocumentProperties::onDocUnitChange() os << doc_unit->abbr; repr->setAttribute("inkscape:document-units", os.str().c_str()); + _page_sizer.updateScaleUI(); + // Disable changing of SVG Units. The intent here is to change the units in the UI, not the units in SVG. // This code should be moved (and fixed) once we have an "SVG Units" setting that sets what units are used in SVG data. #if 0 diff --git a/src/ui/dialog/filedialog.cpp b/src/ui/dialog/filedialog.cpp index 00ed09551..4e4b0278a 100644 --- a/src/ui/dialog/filedialog.cpp +++ b/src/ui/dialog/filedialog.cpp @@ -19,7 +19,7 @@ #include "filedialogimpl-gtkmm.h" #include "filedialog.h" -#include "gc-core.h" +#include "inkgc/gc-core.h" #include "ui/dialog-events.h" #include "extension/output.h" #include "preferences.h" diff --git a/src/ui/dialog/filedialogimpl-win32.cpp b/src/ui/dialog/filedialogimpl-win32.cpp index ee6a0ef3a..cafc3be4f 100644 --- a/src/ui/dialog/filedialogimpl-win32.cpp +++ b/src/ui/dialog/filedialogimpl-win32.cpp @@ -44,6 +44,7 @@ #include "filedialog.h" #include "sp-root.h" +#include "preferences.h" #include <zlib.h> #include <cairomm/win32_surface.h> @@ -272,6 +273,9 @@ void FileOpenDialogImplWin32::createFilterMenu() } if (dialogType != EXE_TYPES) { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + _show_preview = prefs->getBool("/dialogs/open/enable_preview", true); + // Compose the filter string Inkscape::Extension::DB::InputList extension_list; Inkscape::Extension::db.get_input_list(extension_list); @@ -842,6 +846,10 @@ LRESULT CALLBACK FileOpenDialogImplWin32::preview_wnd_proc(HWND hwnd, UINT uMsg, void FileOpenDialogImplWin32::enable_preview(bool enable) { + if (_show_preview != enable) { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setBool("/dialogs/open/enable_preview", enable); + } _show_preview = enable; // Relayout the dialog @@ -1949,7 +1957,7 @@ UINT_PTR CALLBACK FileSaveDialogImplWin32::GetSaveFileName_hookproc( pImpl = reinterpret_cast<FileSaveDialogImplWin32*>(ofn->lCustData); // Create the Title label and edit control - pImpl->_title_label = CreateWindowEx(0, "STATIC", "Title:", + pImpl->_title_label = CreateWindowEx(0, "STATIC", _("Title:"), WS_VISIBLE|WS_CHILD, CW_USEDEFAULT, CW_USEDEFAULT, rCB1.left-rST.left, rST.bottom-rST.top, hParentWnd, NULL, hInstance, NULL); diff --git a/src/ui/dialog/filedialogimpl-win32.h b/src/ui/dialog/filedialogimpl-win32.h index f77249abd..8c3b6bad6 100644 --- a/src/ui/dialog/filedialogimpl-win32.h +++ b/src/ui/dialog/filedialogimpl-win32.h @@ -24,7 +24,7 @@ #include "filedialogimpl-gtkmm.h" -#include "gc-core.h" +#include "inkgc/gc-core.h" // define WINVER high enough so we get the correct OPENFILENAMEW size #ifndef WINVER #define WINVER 0x0500 diff --git a/src/ui/dialog/find.cpp b/src/ui/dialog/find.cpp index 6d8d64607..951cb01ea 100644 --- a/src/ui/dialog/find.cpp +++ b/src/ui/dialog/find.cpp @@ -37,6 +37,7 @@ #include "preferences.h" #include "sp-text.h" #include "sp-flowtext.h" +#include "sp-flowdiv.h" #include "text-editing.h" #include "sp-tspan.h" #include "sp-tref.h" @@ -693,7 +694,10 @@ bool Find::item_type_match (SPItem *item) } else if (dynamic_cast<SPPath *>(item) || dynamic_cast<SPLine *>(item) || dynamic_cast<SPPolyLine *>(item)) { return (all || check_paths.get_active()); - } else if (dynamic_cast<SPText *>(item) || dynamic_cast<SPTSpan *>(item) || dynamic_cast<SPTRef *>(item) || dynamic_cast<SPString *>(item)) { + } else if (dynamic_cast<SPText *>(item) || dynamic_cast<SPTSpan *>(item) || + dynamic_cast<SPTRef *>(item) || dynamic_cast<SPString *>(item) || + dynamic_cast<SPFlowtext *>(item) || dynamic_cast<SPFlowdiv *>(item) || + dynamic_cast<SPFlowtspan *>(item) || dynamic_cast<SPFlowpara *>(item)) { return (all || check_texts.get_active()); } else if (dynamic_cast<SPGroup *>(item) && !desktop->isLayer(item) ) { // never select layers! diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index 9f86158aa..3b0731953 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -529,14 +529,14 @@ void InkscapePreferences::initPageUI() _("English/Canada (en_CA)"), _("English/Great Britain (en_GB)"), _("Pig Latin (en_US@piglatin)"), _("Esperanto (eo)"), _("Estonian (et)"), _("Farsi (fa)"), _("Finnish (fi)"), _("French (fr)"), _("Irish (ga)"), _("Galician (gl)"), _("Hebrew (he)"), _("Hungarian (hu)"), - _("Indonesian (id)"), _("Italian (it)"), _("Japanese (ja)"), _("Khmer (km)"), _("Kinyarwanda (rw)"), _("Korean (ko)"), _("Lithuanian (lt)"), _("Latvian (lv)"), _("Macedonian (mk)"), + _("Indonesian (id)"), _("Icelandic (is)"), _("Italian (it)"), _("Japanese (ja)"), _("Khmer (km)"), _("Kinyarwanda (rw)"), _("Korean (ko)"), _("Lithuanian (lt)"), _("Latvian (lv)"), _("Macedonian (mk)"), _("Mongolian (mn)"), _("Nepali (ne)"), _("Norwegian BokmÃ¥l (nb)"), _("Norwegian Nynorsk (nn)"), _("Panjabi (pa)"), _("Polish (pl)"), _("Portuguese (pt)"), _("Portuguese/Brazil (pt_BR)"), _("Romanian (ro)"), _("Russian (ru)"), _("Serbian (sr)"), _("Serbian in Latin script (sr@latin)"), _("Slovak (sk)"), _("Slovenian (sl)"), _("Spanish (es)"), _("Spanish/Mexico (es_MX)"), _("Swedish (sv)"),_("Telugu (te)"), _("Thai (th)"), _("Turkish (tr)"), _("Ukrainian (uk)"), _("Vietnamese (vi)")}; Glib::ustring langValues[] = {"", "sq", "am", "ar", "hy", "az", "eu", "be", "bg", "bn", "bn_BD", "br", "ca", "ca@valencia", "zh_CN", "zh_TW", "hr", "cs", "da", "nl", "dz", "de", "el", "en", "en_AU", "en_CA", "en_GB", "en_US@piglatin", "eo", "et", "fa", "fi", "fr", "ga", - "gl", "he", "hu", "id", "it", "ja", "km", "rw", "ko", "lt", "lv", "mk", "mn", "ne", "nb", "nn", "pa", + "gl", "he", "hu", "id", "is", "it", "ja", "km", "rw", "ko", "lt", "lv", "mk", "mn", "ne", "nb", "nn", "pa", "pl", "pt", "pt_BR", "ro", "ru", "sr", "sr@latin", "sk", "sl", "es", "es_MX", "sv", "te", "th", "tr", "uk", "vi" }; { diff --git a/src/ui/dialog/livepatheffect-editor.cpp b/src/ui/dialog/livepatheffect-editor.cpp index 3b87597c8..422ec10ae 100644 --- a/src/ui/dialog/livepatheffect-editor.cpp +++ b/src/ui/dialog/livepatheffect-editor.cpp @@ -27,6 +27,7 @@ #include "document.h" #include "document-undo.h" #include "gtkmm/widget.h" +#include "helper/action.h" #include "inkscape.h" #include "live_effects/effect.h" #include "live_effects/lpeobject.h" @@ -44,6 +45,7 @@ #include "ui/icon-names.h" #include "ui/widget/imagetoggler.h" #include "verbs.h" +#include "widgets/icon.h" #include "xml/node.h" #include "livepatheffect-add.h" @@ -68,6 +70,14 @@ static void lpeeditor_selection_modified (Inkscape::Selection * selection, guint lpeeditor->onSelectionChanged(selection); } +static void lpe_style_button(Gtk::Button& btn, char const* iconName) +{ + GtkWidget *child = sp_icon_new(Inkscape::ICON_SIZE_SMALL_TOOLBAR, iconName); + gtk_widget_show( child ); + btn.add(*Gtk::manage(Glib::wrap(child))); + btn.set_relief(Gtk::RELIEF_NONE); +} + /* * LivePathEffectEditor @@ -107,43 +117,19 @@ LivePathEffectEditor::LivePathEffectEditor() effectcontrol_frame.add(effectcontrol_vbox); button_add.set_tooltip_text(_("Add path effect")); -#if WITH_GTKMM_3_10 - button_add.set_image_from_icon_name(INKSCAPE_ICON("list-add"), Gtk::ICON_SIZE_SMALL_TOOLBAR); -#else - Gtk::Image *image_add = Gtk::manage(new Gtk::Image()); - image_add->set_from_icon_name(INKSCAPE_ICON("list-add"), Gtk::ICON_SIZE_SMALL_TOOLBAR); - button_add.set_image(*image_add); -#endif + lpe_style_button(button_add, INKSCAPE_ICON("list-add")); button_add.set_relief(Gtk::RELIEF_NONE); button_remove.set_tooltip_text(_("Delete current path effect")); -#if WITH_GTKMM_3_10 - button_remove.set_image_from_icon_name(INKSCAPE_ICON("list-remove"), Gtk::ICON_SIZE_SMALL_TOOLBAR); -#else - Gtk::Image *image_remove = Gtk::manage(new Gtk::Image()); - image_remove->set_from_icon_name(INKSCAPE_ICON("list-remove"), Gtk::ICON_SIZE_SMALL_TOOLBAR); - button_remove.set_image(*image_remove); -#endif + lpe_style_button(button_remove, INKSCAPE_ICON("list-remove")); button_remove.set_relief(Gtk::RELIEF_NONE); button_up.set_tooltip_text(_("Raise the current path effect")); -#if WITH_GTKMM_3_10 - button_up.set_image_from_icon_name(INKSCAPE_ICON("go-up"), Gtk::ICON_SIZE_SMALL_TOOLBAR); -#else - Gtk::Image *image_up = Gtk::manage(new Gtk::Image()); - image_up->set_from_icon_name(INKSCAPE_ICON("go-up"), Gtk::ICON_SIZE_SMALL_TOOLBAR); - button_up.set_image(*image_up); -#endif + lpe_style_button(button_up, INKSCAPE_ICON("go-up")); button_up.set_relief(Gtk::RELIEF_NONE); button_down.set_tooltip_text(_("Lower the current path effect")); -#if WITH_GTKMM_3_10 - button_down.set_image_from_icon_name(INKSCAPE_ICON("go-down"), Gtk::ICON_SIZE_SMALL_TOOLBAR); -#else - Gtk::Image *image_down = Gtk::manage(new Gtk::Image()); - image_down->set_from_icon_name(INKSCAPE_ICON("go-down"), Gtk::ICON_SIZE_SMALL_TOOLBAR); - button_down.set_image(*image_down); -#endif + lpe_style_button(button_down, INKSCAPE_ICON("go-down")); button_down.set_relief(Gtk::RELIEF_NONE); // Add toolbar items to toolbar diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp index b318933a7..7e5c17133 100644 --- a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp +++ b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp @@ -129,7 +129,7 @@ void FilletChamferPropertiesDialog::showDialog( const gchar *unit, bool use_distance, bool aprox_radius, - Glib::ustring const * documentUnit) + Glib::ustring documentUnit) { FilletChamferPropertiesDialog *dialog = new FilletChamferPropertiesDialog(); @@ -172,7 +172,7 @@ void FilletChamferPropertiesDialog::_apply() } d_pos = _index + (d_pos / 100); } else { - d_pos = Inkscape::Util::Quantity::convert(d_pos, unit, *document_unit); + d_pos = Inkscape::Util::Quantity::convert(d_pos, unit, document_unit); d_pos = d_pos * -1; } _knotpoint->knot_set_offset(Geom::Point(d_pos, d_width)); @@ -226,7 +226,7 @@ void FilletChamferPropertiesDialog::_set_knot_point(Geom::Point knotpoint) _fillet_chamfer_position_label.set_label(_(posConcat.c_str())); position = knotpoint[Geom::X] * -1; - position = Inkscape::Util::Quantity::convert(position, *document_unit, unit); + position = Inkscape::Util::Quantity::convert(position, document_unit, unit); } _fillet_chamfer_position_numeric.set_value(position); if (knotpoint.y() == 1) { @@ -256,7 +256,7 @@ void FilletChamferPropertiesDialog::_set_unit(const gchar *abbr) unit = abbr; } -void FilletChamferPropertiesDialog::_set_document_unit(Glib::ustring const *abbr) +void FilletChamferPropertiesDialog::_set_document_unit(Glib::ustring abbr) { document_unit = abbr; } diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.h b/src/ui/dialog/lpe-fillet-chamfer-properties.h index 3807e98c8..870a1734f 100644 --- a/src/ui/dialog/lpe-fillet-chamfer-properties.h +++ b/src/ui/dialog/lpe-fillet-chamfer-properties.h @@ -33,7 +33,7 @@ public: const gchar *unit, bool use_distance, bool aprox_radius, - Glib::ustring const * documentUnit); + Glib::ustring documentUnit); protected: @@ -69,14 +69,14 @@ protected: void _set_pt(const Inkscape::LivePathEffect:: FilletChamferPointArrayParamKnotHolderEntity *pt); void _set_unit(const gchar *abbr); - void _set_document_unit(Glib::ustring const * abbr); + void _set_document_unit(Glib::ustring abbr); void _set_use_distance(bool use_knot_distance); void _set_aprox(bool aprox_radius); void _apply(); void _close(); bool _flexible; const gchar *unit; - Glib::ustring const * document_unit; + Glib::ustring document_unit; bool use_distance; bool aprox; void _set_knot_point(Geom::Point knotpoint); diff --git a/src/ui/dialog/memory.cpp b/src/ui/dialog/memory.cpp index 0008eb284..c0bc884fa 100644 --- a/src/ui/dialog/memory.cpp +++ b/src/ui/dialog/memory.cpp @@ -20,7 +20,7 @@ #include <gtkmm/liststore.h> #include <gtkmm/treeview.h> -#include "gc-core.h" +#include "inkgc/gc-core.h" #include "debug/heap.h" #include "verbs.h" diff --git a/src/ui/dialog/objects.cpp b/src/ui/dialog/objects.cpp index c95529a56..9db0285d7 100644 --- a/src/ui/dialog/objects.cpp +++ b/src/ui/dialog/objects.cpp @@ -231,15 +231,13 @@ public: /** * Stylizes a button using the given icon name and tooltip */ -void ObjectsPanel::_styleButton( Gtk::Button& btn, char const* iconName, char const* tooltip ) +void ObjectsPanel::_styleButton(Gtk::Button& btn, char const* iconName, char const* tooltip) { GtkWidget *child = sp_icon_new( Inkscape::ICON_SIZE_SMALL_TOOLBAR, iconName ); gtk_widget_show( child ); btn.add( *Gtk::manage(Glib::wrap(child)) ); btn.set_relief(Gtk::RELIEF_NONE); - btn.set_tooltip_text (tooltip); - } /** @@ -1799,29 +1797,14 @@ ObjectsPanel::ObjectsPanel() : //Add object/layer Gtk::Button* btn = Gtk::manage( new Gtk::Button() ); - btn->set_tooltip_text(_("Add layer...")); -#if GTK_CHECK_VERSION(3,10,0) - btn->set_image_from_icon_name(INKSCAPE_ICON("list-add"), Gtk::ICON_SIZE_SMALL_TOOLBAR); -#else - Gtk::Image *image_add = Gtk::manage(new Gtk::Image()); - image_add->set_from_icon_name(INKSCAPE_ICON("list-add"), Gtk::ICON_SIZE_SMALL_TOOLBAR); - btn->set_image(*image_add); -#endif + _styleButton(*btn, INKSCAPE_ICON("list-add"), _("Add layer...")); btn->set_relief(Gtk::RELIEF_NONE); btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &ObjectsPanel::_takeAction), (int)BUTTON_NEW) ); _buttonsSecondary.pack_start(*btn, Gtk::PACK_SHRINK); - //Remove object btn = Gtk::manage( new Gtk::Button() ); - btn->set_tooltip_text(_("Remove object")); -#if GTK_CHECK_VERSION(3,10,0) - btn->set_image_from_icon_name(INKSCAPE_ICON("list-remove"), Gtk::ICON_SIZE_SMALL_TOOLBAR); -#else - Gtk::Image *image_remove = Gtk::manage(new Gtk::Image()); - image_remove->set_from_icon_name(INKSCAPE_ICON("list-remove"), Gtk::ICON_SIZE_SMALL_TOOLBAR); - btn->set_image(*image_remove); -#endif + _styleButton(*btn, INKSCAPE_ICON("list-remove"), _("Remove object")); btn->set_relief(Gtk::RELIEF_NONE); btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &ObjectsPanel::_takeAction), (int)BUTTON_DELETE) ); _watching.push_back( btn ); @@ -1829,14 +1812,7 @@ ObjectsPanel::ObjectsPanel() : //Move to bottom btn = Gtk::manage( new Gtk::Button() ); - btn->set_tooltip_text(_("Move To Bottom")); -#if GTK_CHECK_VERSION(3,10,0) - btn->set_image_from_icon_name(INKSCAPE_ICON("go-bottom"), Gtk::ICON_SIZE_SMALL_TOOLBAR); -#else - image_remove = Gtk::manage(new Gtk::Image()); - image_remove->set_from_icon_name(INKSCAPE_ICON("go-bottom"), Gtk::ICON_SIZE_SMALL_TOOLBAR); - btn->set_image(*image_remove); -#endif + _styleButton(*btn, INKSCAPE_ICON("go-bottom"), _("Move To Bottom")); btn->set_relief(Gtk::RELIEF_NONE); btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &ObjectsPanel::_takeAction), (int)BUTTON_BOTTOM) ); _watchingNonBottom.push_back( btn ); @@ -1844,14 +1820,7 @@ ObjectsPanel::ObjectsPanel() : //Move down btn = Gtk::manage( new Gtk::Button() ); - btn->set_tooltip_text(_("Move Down")); -#if GTK_CHECK_VERSION(3,10,0) - btn->set_image_from_icon_name(INKSCAPE_ICON("go-down"), Gtk::ICON_SIZE_SMALL_TOOLBAR); -#else - image_remove = Gtk::manage(new Gtk::Image()); - image_remove->set_from_icon_name(INKSCAPE_ICON("go-down"), Gtk::ICON_SIZE_SMALL_TOOLBAR); - btn->set_image(*image_remove); -#endif + _styleButton(*btn, INKSCAPE_ICON("go-down"), _("Move Down")); btn->set_relief(Gtk::RELIEF_NONE); btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &ObjectsPanel::_takeAction), (int)BUTTON_DOWN) ); _watchingNonBottom.push_back( btn ); @@ -1859,14 +1828,7 @@ ObjectsPanel::ObjectsPanel() : //Move up btn = Gtk::manage( new Gtk::Button() ); - btn->set_tooltip_text(_("Move Up")); -#if GTK_CHECK_VERSION(3,10,0) - btn->set_image_from_icon_name(INKSCAPE_ICON("go-up"), Gtk::ICON_SIZE_SMALL_TOOLBAR); -#else - image_remove = Gtk::manage(new Gtk::Image()); - image_remove->set_from_icon_name(INKSCAPE_ICON("go-up"), Gtk::ICON_SIZE_SMALL_TOOLBAR); - btn->set_image(*image_remove); -#endif + _styleButton(*btn, INKSCAPE_ICON("go-up"), _("Move Up")); btn->set_relief(Gtk::RELIEF_NONE); btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &ObjectsPanel::_takeAction), (int)BUTTON_UP) ); _watchingNonTop.push_back( btn ); @@ -1874,14 +1836,7 @@ ObjectsPanel::ObjectsPanel() : //Move to top btn = Gtk::manage( new Gtk::Button() ); - btn->set_tooltip_text(_("Move To Top")); -#if GTK_CHECK_VERSION(3,10,0) - btn->set_image_from_icon_name(INKSCAPE_ICON("go-top"), Gtk::ICON_SIZE_SMALL_TOOLBAR); -#else - image_remove = Gtk::manage(new Gtk::Image()); - image_remove->set_from_icon_name(INKSCAPE_ICON("go-top"), Gtk::ICON_SIZE_SMALL_TOOLBAR); - btn->set_image(*image_remove); -#endif + _styleButton(*btn, INKSCAPE_ICON("go-top"), _("Move To Top")); btn->set_relief(Gtk::RELIEF_NONE); btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &ObjectsPanel::_takeAction), (int)BUTTON_TOP) ); _watchingNonTop.push_back( btn ); @@ -1889,14 +1844,7 @@ ObjectsPanel::ObjectsPanel() : //Collapse all btn = Gtk::manage( new Gtk::Button() ); - btn->set_tooltip_text(_("Collapse All")); -#if GTK_CHECK_VERSION(3,10,0) - btn->set_image_from_icon_name(INKSCAPE_ICON("gtk-unindent-ltr"), Gtk::ICON_SIZE_SMALL_TOOLBAR); -#else - image_remove = Gtk::manage(new Gtk::Image()); - image_remove->set_from_icon_name(INKSCAPE_ICON("gtk-unindent-ltr"), Gtk::ICON_SIZE_SMALL_TOOLBAR); - btn->set_image(*image_remove); -#endif + _styleButton(*btn, INKSCAPE_ICON("format-indent-less"), _("Collapse All")); btn->set_relief(Gtk::RELIEF_NONE); btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &ObjectsPanel::_takeAction), (int)BUTTON_COLLAPSE_ALL) ); _watchingNonBottom.push_back( btn ); diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index c4dd9df98..a1c7d41bd 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -26,7 +26,7 @@ #include "path-prefix.h" #include "filedialogimpl-gtkmm.h" #include "ui/interface.h" -#include "gc-core.h" +#include "inkgc/gc-core.h" #include "ui/dialog-events.h" #include "io/sys.h" #include "preferences.h" diff --git a/src/ui/dialog/print.cpp b/src/ui/dialog/print.cpp index a015d28f9..ad979b570 100644 --- a/src/ui/dialog/print.cpp +++ b/src/ui/dialog/print.cpp @@ -126,30 +126,13 @@ static void draw_page( cairo_surface_t *surface = cairo_get_target(cr); cairo_matrix_t ctm; cairo_get_matrix(cr, &ctm); -#ifdef WIN32 - //Gtk+ does not take the non printable area into account - //http://bugzilla.gnome.org/show_bug.cgi?id=381371 - // - // This workaround translates the origin from the top left of the - // printable area to the top left of the page. - GtkPrintSettings *settings = gtk_print_operation_get_print_settings(operation); - const gchar *printerName = gtk_print_settings_get_printer(settings); - HDC hdc = CreateDC("WINSPOOL", printerName, NULL, NULL); - if (hdc) { - cairo_matrix_t mat; - int x_off = GetDeviceCaps (hdc, PHYSICALOFFSETX); - int y_off = GetDeviceCaps (hdc, PHYSICALOFFSETY); - cairo_matrix_init_translate(&mat, -x_off, -y_off); - cairo_matrix_multiply (&ctm, &ctm, &mat); - DeleteDC(hdc); - } -#endif + bool ret = ctx->setSurfaceTarget (surface, true, &ctm); if (ret) { ret = renderer.setupDocument (ctx, junk->_doc, TRUE, 0., NULL); if (ret) { renderer.renderItem(ctx, junk->_base); - ret = ctx->finish(); + ctx->finish(); } else { g_warning("%s", _("Could not set up Document")); diff --git a/src/ui/dialog/tags.cpp b/src/ui/dialog/tags.cpp index 8a104d137..7d3edaffb 100644 --- a/src/ui/dialog/tags.cpp +++ b/src/ui/dialog/tags.cpp @@ -145,31 +145,12 @@ public: int _actionCode; }; -void TagsPanel::_styleButton( Gtk::Button& btn, SPDesktop *desktop, unsigned int code, char const* iconName, char const* tooltip ) +void TagsPanel::_styleButton(Gtk::Button& btn, char const* iconName, char const* tooltip) { - bool set = false; - - if ( iconName ) { - GtkWidget *child = sp_icon_new( Inkscape::ICON_SIZE_SMALL_TOOLBAR, iconName ); - gtk_widget_show( child ); - btn.add( *manage(Glib::wrap(child)) ); - btn.set_relief(Gtk::RELIEF_NONE); - set = true; - } - - if ( desktop ) { - Verb *verb = Verb::get( code ); - if ( verb ) { - SPAction *action = verb->get_action(desktop); - if ( !set && action && action->image ) { - GtkWidget *child = sp_icon_new( Inkscape::ICON_SIZE_SMALL_TOOLBAR, action->image ); - gtk_widget_show( child ); - btn.add( *manage(Glib::wrap(child)) ); - set = true; - } - } - } - + GtkWidget *child = sp_icon_new(Inkscape::ICON_SIZE_SMALL_TOOLBAR, iconName); + gtk_widget_show(child); + btn.add(*manage(Glib::wrap(child))); + btn.set_relief(Gtk::RELIEF_NONE); btn.set_tooltip_text (tooltip); } @@ -1013,7 +994,7 @@ TagsPanel::TagsPanel() : SPDesktop* targetDesktop = getDesktop(); Gtk::Button* btn = manage( new Gtk::Button() ); - _styleButton( *btn, targetDesktop, SP_VERB_TAG_NEW, GTK_STOCK_ADD, _("Add a new selection set") ); + _styleButton(*btn, "list-add", _("Add a new selection set") ); btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &TagsPanel::_takeAction), (int)BUTTON_NEW) ); _buttonsSecondary.pack_start(*btn, Gtk::PACK_SHRINK); @@ -1022,7 +1003,7 @@ TagsPanel::TagsPanel() : // _buttonsRow.add( *btn ); btn = manage( new Gtk::Button() ); - _styleButton( *btn, targetDesktop, SP_VERB_LAYER_DELETE, GTK_STOCK_REMOVE, _("Remove Item/Set") ); + _styleButton( *btn, "list-remove", _("Remove Item/Set") ); btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &TagsPanel::_takeAction), (int)BUTTON_DELETE) ); _watching.push_back( btn ); _buttonsSecondary.pack_start(*btn, Gtk::PACK_SHRINK); diff --git a/src/ui/dialog/tags.h b/src/ui/dialog/tags.h index d35dfba01..3576bd111 100644 --- a/src/ui/dialog/tags.h +++ b/src/ui/dialog/tags.h @@ -62,7 +62,7 @@ private: TagsPanel(TagsPanel const &); // no copy TagsPanel &operator=(TagsPanel const &); // no assign - void _styleButton( Gtk::Button& btn, SPDesktop *desktop, unsigned int code, char const* iconName, char const* tooltip ); + void _styleButton( Gtk::Button& btn, char const* iconName, char const* tooltip ); void _fireAction( unsigned int code ); Gtk::MenuItem& _addPopupItem( SPDesktop *desktop, unsigned int code, char const* iconName, char const* fallback, int id ); diff --git a/src/ui/dialog/xml-tree.cpp b/src/ui/dialog/xml-tree.cpp index c02520218..99a4acc69 100644 --- a/src/ui/dialog/xml-tree.cpp +++ b/src/ui/dialog/xml-tree.cpp @@ -71,10 +71,10 @@ XmlTree::XmlTree (void) : xml_text_new_button ( _("New text node")), xml_node_delete_button ( Q_("nodeAsInXMLdialogTooltip|Delete node")), xml_node_duplicate_button ( _("Duplicate node")), - unindent_node_button (Gtk::Stock::UNINDENT), - indent_node_button (Gtk::Stock::INDENT), - raise_node_button (Gtk::Stock::GO_UP), - lower_node_button (Gtk::Stock::GO_DOWN), + unindent_node_button(), + indent_node_button(), + raise_node_button(), + lower_node_button(), attr_toolbar(), xml_attribute_delete_button (_("Delete attribute")), text_container (), @@ -149,21 +149,29 @@ XmlTree::XmlTree (void) : tree_toolbar.add(separator2); + unindent_node_button.set_icon_widget(*Gtk::manage(Glib::wrap( + sp_icon_new (Inkscape::ICON_SIZE_LARGE_TOOLBAR, INKSCAPE_ICON("format-indent-less"))))); unindent_node_button.set_label(_("Unindent node")); unindent_node_button.set_tooltip_text(_("Unindent node")); unindent_node_button.set_sensitive(false); tree_toolbar.add(unindent_node_button); + indent_node_button.set_icon_widget(*Gtk::manage(Glib::wrap( + sp_icon_new (Inkscape::ICON_SIZE_LARGE_TOOLBAR, INKSCAPE_ICON("format-indent-more"))))); indent_node_button.set_label(_("Indent node")); indent_node_button.set_tooltip_text(_("Indent node")); indent_node_button.set_sensitive(false); tree_toolbar.add(indent_node_button); + raise_node_button.set_icon_widget(*Gtk::manage(Glib::wrap( + sp_icon_new (Inkscape::ICON_SIZE_LARGE_TOOLBAR, INKSCAPE_ICON("go-up"))))); raise_node_button.set_label(_("Raise node")); raise_node_button.set_tooltip_text(_("Raise node")); raise_node_button.set_sensitive(false); tree_toolbar.add(raise_node_button); + lower_node_button.set_icon_widget(*Gtk::manage(Glib::wrap( + sp_icon_new (Inkscape::ICON_SIZE_LARGE_TOOLBAR, INKSCAPE_ICON("go-down"))))); lower_node_button.set_label(_("Lower node")); lower_node_button.set_tooltip_text(_("Lower node")); lower_node_button.set_sensitive(false); diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp index 28a65e0b4..87438ac01 100644 --- a/src/ui/interface.cpp +++ b/src/ui/interface.cpp @@ -1815,7 +1815,7 @@ void ContextMenu::SelectSameStrokeColor(void) void ContextMenu::SelectSameStrokeStyle(void) { - sp_select_same_stroke_style(_desktop); + sp_select_same_fill_stroke_style(_desktop, false, false, true); } void ContextMenu::SelectSameObjectType(void) diff --git a/src/ui/object-edit.cpp b/src/ui/object-edit.cpp index fb99dfd59..0a6c792dc 100644 --- a/src/ui/object-edit.cpp +++ b/src/ui/object-edit.cpp @@ -154,12 +154,9 @@ RectKnotHolderEntityRX::knot_set(Geom::Point const &p, Geom::Point const &/*orig if (state & GDK_CONTROL_MASK) { gdouble temp = MIN(rect->height.computed, rect->width.computed) / 2.0; - rect->rx.computed = rect->ry.computed = CLAMP(rect->x.computed + rect->width.computed - s[Geom::X], 0.0, temp); - rect->rx._set = rect->ry._set = true; - + rect->rx = rect->ry = CLAMP(rect->x.computed + rect->width.computed - s[Geom::X], 0.0, temp); } else { - rect->rx.computed = CLAMP(rect->x.computed + rect->width.computed - s[Geom::X], 0.0, rect->width.computed / 2.0); - rect->rx._set = true; + rect->rx = CLAMP(rect->x.computed + rect->width.computed - s[Geom::X], 0.0, rect->width.computed / 2.0); } update_knot(); @@ -207,20 +204,17 @@ RectKnotHolderEntityRY::knot_set(Geom::Point const &p, Geom::Point const &/*orig if (state & GDK_CONTROL_MASK) { // When holding control then rx will be kept equal to ry, // resulting in a perfect circle (and not an ellipse) gdouble temp = MIN(rect->height.computed, rect->width.computed) / 2.0; - rect->rx.computed = rect->ry.computed = CLAMP(s[Geom::Y] - rect->y.computed, 0.0, temp); - rect->ry._set = rect->rx._set = true; + rect->rx = rect->ry = CLAMP(s[Geom::Y] - rect->y.computed, 0.0, temp); } else { if (!rect->rx._set || rect->rx.computed == 0) { - rect->ry.computed = CLAMP(s[Geom::Y] - rect->y.computed, - 0.0, - MIN(rect->height.computed / 2.0, rect->width.computed / 2.0)); + rect->ry = CLAMP(s[Geom::Y] - rect->y.computed, + 0.0, + MIN(rect->height.computed / 2.0, rect->width.computed / 2.0)); } else { - rect->ry.computed = CLAMP(s[Geom::Y] - rect->y.computed, - 0.0, - rect->height.computed / 2.0); + rect->ry = CLAMP(s[Geom::Y] - rect->y.computed, + 0.0, + rect->height.computed / 2.0); } - - rect->ry._set = true; } update_knot(); @@ -250,12 +244,10 @@ static void sp_rect_clamp_radii(SPRect *rect) { // clamp rounding radii so that they do not exceed width/height if (2 * rect->rx.computed > rect->width.computed) { - rect->rx.computed = 0.5 * rect->width.computed; - rect->rx._set = true; + rect->rx = 0.5 * rect->width.computed; } if (2 * rect->ry.computed > rect->height.computed) { - rect->ry.computed = 0.5 * rect->height.computed; - rect->ry._set = true; + rect->ry = 0.5 * rect->height.computed; } } @@ -296,44 +288,45 @@ RectKnotHolderEntityWH::set_internal(Geom::Point const &p, Geom::Point const &or // closer to the diagonal and in same-sign quarters, change both using ratio s = snap_knot_position_constrained(p, Inkscape::Snapper::SnapConstraint(p_handle, Geom::Point(-ratio, -1)), state); minx = s[Geom::X] - origin[Geom::X]; - miny = s[Geom::Y] - origin[Geom::Y]; - rect->height.computed = MAX(h_orig + minx / ratio, 0); + // Dead assignment: Value stored to 'miny' is never read + //miny = s[Geom::Y] - origin[Geom::Y]; + rect->height = MAX(h_orig + minx / ratio, 0); } else { // closer to the horizontal, change only width, height is h_orig s = snap_knot_position_constrained(p, Inkscape::Snapper::SnapConstraint(p_handle, Geom::Point(-1, 0)), state); minx = s[Geom::X] - origin[Geom::X]; - miny = s[Geom::Y] - origin[Geom::Y]; - rect->height.computed = MAX(h_orig, 0); + // Dead assignment: Value stored to 'miny' is never read + //miny = s[Geom::Y] - origin[Geom::Y]; + rect->height = MAX(h_orig, 0); } - rect->width.computed = MAX(w_orig + minx, 0); + rect->width = MAX(w_orig + minx, 0); } else { // snap to vertical or diagonal if (miny != 0 && fabs(minx/miny) > 0.5 * ratio && (SGN(minx) == SGN(miny))) { // closer to the diagonal and in same-sign quarters, change both using ratio s = snap_knot_position_constrained(p, Inkscape::Snapper::SnapConstraint(p_handle, Geom::Point(-ratio, -1)), state); - minx = s[Geom::X] - origin[Geom::X]; + // Dead assignment: Value stored to 'minx' is never read + //minx = s[Geom::X] - origin[Geom::X]; miny = s[Geom::Y] - origin[Geom::Y]; - rect->width.computed = MAX(w_orig + miny * ratio, 0); + rect->width = MAX(w_orig + miny * ratio, 0); } else { // closer to the vertical, change only height, width is w_orig s = snap_knot_position_constrained(p, Inkscape::Snapper::SnapConstraint(p_handle, Geom::Point(0, -1)), state); - minx = s[Geom::X] - origin[Geom::X]; + // Dead assignment: Value stored to 'minx' is never read + //minx = s[Geom::X] - origin[Geom::X]; miny = s[Geom::Y] - origin[Geom::Y]; - rect->width.computed = MAX(w_orig, 0); + rect->width = MAX(w_orig, 0); } - rect->height.computed = MAX(h_orig + miny, 0); + rect->height = MAX(h_orig + miny, 0); } - rect->width._set = rect->height._set = true; - } else { // move freely s = snap_knot_position(p, state); - rect->width.computed = MAX(s[Geom::X] - rect->x.computed, 0); - rect->height.computed = MAX(s[Geom::Y] - rect->y.computed, 0); - rect->width._set = rect->height._set = true; + rect->width = MAX(s[Geom::X] - rect->x.computed, 0); + rect->height = MAX(s[Geom::Y] - rect->y.computed, 0); } sp_rect_clamp_radii(rect); @@ -388,53 +381,54 @@ RectKnotHolderEntityXY::knot_set(Geom::Point const &p, Geom::Point const &origin // closer to the diagonal and in same-sign quarters, change both using ratio s = snap_knot_position_constrained(p, Inkscape::Snapper::SnapConstraint(p_handle, Geom::Point(-ratio, -1)), state); minx = s[Geom::X] - origin[Geom::X]; - miny = s[Geom::Y] - origin[Geom::Y]; - rect->y.computed = MIN(origin[Geom::Y] + minx / ratio, opposite_y); - rect->height.computed = MAX(h_orig - minx / ratio, 0); + // Dead assignment: Value stored to 'miny' is never read + //miny = s[Geom::Y] - origin[Geom::Y]; + rect->y = MIN(origin[Geom::Y] + minx / ratio, opposite_y); + rect->height = MAX(h_orig - minx / ratio, 0); } else { // closer to the horizontal, change only width, height is h_orig s = snap_knot_position_constrained(p, Inkscape::Snapper::SnapConstraint(p_handle, Geom::Point(-1, 0)), state); minx = s[Geom::X] - origin[Geom::X]; - miny = s[Geom::Y] - origin[Geom::Y]; - rect->y.computed = MIN(origin[Geom::Y], opposite_y); - rect->height.computed = MAX(h_orig, 0); + // Dead assignment: Value stored to 'miny' is never read + //miny = s[Geom::Y] - origin[Geom::Y]; + rect->y = MIN(origin[Geom::Y], opposite_y); + rect->height = MAX(h_orig, 0); } - rect->x.computed = MIN(s[Geom::X], opposite_x); - rect->width.computed = MAX(w_orig - minx, 0); + rect->x = MIN(s[Geom::X], opposite_x); + rect->width = MAX(w_orig - minx, 0); } else { // snap to vertical or diagonal if (miny != 0 && fabs(minx/miny) > 0.5 *ratio && (SGN(minx) == SGN(miny))) { // closer to the diagonal and in same-sign quarters, change both using ratio s = snap_knot_position_constrained(p, Inkscape::Snapper::SnapConstraint(p_handle, Geom::Point(-ratio, -1)), state); - minx = s[Geom::X] - origin[Geom::X]; + // Dead assignment: Value stored to 'minx' is never read + //minx = s[Geom::X] - origin[Geom::X]; miny = s[Geom::Y] - origin[Geom::Y]; - rect->x.computed = MIN(origin[Geom::X] + miny * ratio, opposite_x); - rect->width.computed = MAX(w_orig - miny * ratio, 0); + rect->x = MIN(origin[Geom::X] + miny * ratio, opposite_x); + rect->width = MAX(w_orig - miny * ratio, 0); } else { // closer to the vertical, change only height, width is w_orig s = snap_knot_position_constrained(p, Inkscape::Snapper::SnapConstraint(p_handle, Geom::Point(0, -1)), state); - minx = s[Geom::X] - origin[Geom::X]; + // Dead assignment: Value stored to 'minx' is never read + //minx = s[Geom::X] - origin[Geom::X]; miny = s[Geom::Y] - origin[Geom::Y]; - rect->x.computed = MIN(origin[Geom::X], opposite_x); - rect->width.computed = MAX(w_orig, 0); + rect->x = MIN(origin[Geom::X], opposite_x); + rect->width = MAX(w_orig, 0); } - rect->y.computed = MIN(s[Geom::Y], opposite_y); - rect->height.computed = MAX(h_orig - miny, 0); + rect->y = MIN(s[Geom::Y], opposite_y); + rect->height = MAX(h_orig - miny, 0); } - rect->width._set = rect->height._set = rect->x._set = rect->y._set = true; - } else { // move freely s = snap_knot_position(p, state); minx = s[Geom::X] - origin[Geom::X]; miny = s[Geom::Y] - origin[Geom::Y]; - rect->x.computed = MIN(s[Geom::X], opposite_x); - rect->width.computed = MAX(w_orig - minx, 0); - rect->y.computed = MIN(s[Geom::Y], opposite_y); - rect->height.computed = MAX(h_orig - miny, 0); - rect->width._set = rect->height._set = rect->x._set = rect->y._set = true; + rect->x = MIN(s[Geom::X], opposite_x); + rect->y = MIN(s[Geom::Y], opposite_y); + rect->width = MAX(w_orig - minx, 0); + rect->height = MAX(h_orig - miny, 0); } sp_rect_clamp_radii(rect); @@ -909,10 +903,10 @@ ArcKnotHolderEntityRX::knot_set(Geom::Point const &p, Geom::Point const &/*origi Geom::Point const s = snap_knot_position(p, state); - ge->rx.computed = fabs( ge->cx.computed - s[Geom::X] ); + ge->rx = fabs( ge->cx.computed - s[Geom::X] ); if ( state & GDK_CONTROL_MASK ) { - ge->ry.computed = ge->rx.computed; + ge->ry = ge->rx.computed; } item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); @@ -934,7 +928,7 @@ ArcKnotHolderEntityRX::knot_click(unsigned int state) g_assert(ge != NULL); if (state & GDK_CONTROL_MASK) { - ge->ry.computed = ge->rx.computed; + ge->ry = ge->rx.computed; ge->updateRepr(); } } @@ -947,10 +941,10 @@ ArcKnotHolderEntityRY::knot_set(Geom::Point const &p, Geom::Point const &/*origi Geom::Point const s = snap_knot_position(p, state); - ge->ry.computed = fabs( ge->cy.computed - s[Geom::Y] ); + ge->ry = fabs( ge->cy.computed - s[Geom::Y] ); if ( state & GDK_CONTROL_MASK ) { - ge->rx.computed = ge->ry.computed; + ge->rx = ge->ry.computed; } item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); @@ -972,7 +966,7 @@ ArcKnotHolderEntityRY::knot_click(unsigned int state) g_assert(ge != NULL); if (state & GDK_CONTROL_MASK) { - ge->rx.computed = ge->ry.computed; + ge->rx = ge->ry.computed; ge->updateRepr(); } } diff --git a/src/ui/tool-factory.cpp b/src/ui/tool-factory.cpp new file mode 100644 index 000000000..700bd40ce --- /dev/null +++ b/src/ui/tool-factory.cpp @@ -0,0 +1,102 @@ +/* + * Factory for ToolBase tree + * + * Authors: + * Markus Engel + * + * Copyright (C) 2013 Authors + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "tool-factory.h" + +#include "ui/tools/arc-tool.h" +#include "ui/tools/box3d-tool.h" +#include "ui/tools/calligraphic-tool.h" +#include "ui/tools/connector-tool.h" +#include "ui/tools/dropper-tool.h" +#include "ui/tools/eraser-tool.h" +#include "ui/tools/flood-tool.h" +#include "ui/tools/gradient-tool.h" +#include "ui/tools/lpe-tool.h" +#include "ui/tools/measure-tool.h" +#include "ui/tools/mesh-tool.h" +#include "ui/tools/node-tool.h" +#include "ui/tools/pencil-tool.h" +#include "ui/tools/pen-tool.h" +#include "ui/tools/rect-tool.h" +#include "ui/tools/select-tool.h" +#include "ui/tools/spiral-tool.h" +#include "ui/tools/spray-tool.h" +#include "ui/tools/star-tool.h" +#include "ui/tools/text-tool.h" +#include "ui/tools/tool-base.h" +#include "ui/tools/tweak-tool.h" +#include "ui/tools/zoom-tool.h" + +using namespace Inkscape::UI::Tools; + +ToolBase *ToolFactory::createObject(std::string const& id) +{ + ToolBase *tool = NULL; + + if (id == "/tools/shapes/arc") + tool = new ArcTool; + else if (id == "/tools/shapes/3dbox") + tool = new Box3dTool; + else if (id == "/tools/calligraphic") + tool = new CalligraphicTool; + else if (id == "/tools/connector") + tool = new ConnectorTool; + else if (id == "/tools/dropper") + tool = new DropperTool; + else if (id == "/tools/eraser") + tool = new EraserTool; + else if (id == "/tools/paintbucket") + tool = new FloodTool; + else if (id == "/tools/gradient") + tool = new GradientTool; + else if (id == "/tools/lpetool") + tool = new LpeTool; + else if (id == "/tools/measure") + tool = new MeasureTool; + else if (id == "/tools/mesh") + tool = new MeshTool; + else if (id == "/tools/nodes") + tool = new NodeTool; + else if (id == "/tools/freehand/pencil") + tool = new PencilTool; + else if (id == "/tools/freehand/pen") + tool = new PenTool; + else if (id == "/tools/shapes/rect") + tool = new RectTool; + else if (id == "/tools/select") + tool = new SelectTool; + else if (id == "/tools/shapes/spiral") + tool = new SpiralTool; + else if (id == "/tools/spray") + tool = new SprayTool; + else if (id == "/tools/shapes/star") + tool = new StarTool; + else if (id == "/tools/text") + tool = new TextTool; + else if (id == "/tools/tweak") + tool = new TweakTool; + else if (id == "/tools/zoom") + tool = new ZoomTool; + else + fprintf(stderr, "WARNING: unknown tool: %s", id.c_str()); + + return tool; +} + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/ui/tool-factory.h b/src/ui/tool-factory.h index 726706732..3b041fec5 100644 --- a/src/ui/tool-factory.h +++ b/src/ui/tool-factory.h @@ -1,6 +1,6 @@ -/** @file +/* * Factory for ToolBase tree - *//* + * * Authors: * Markus Engel * @@ -11,7 +11,7 @@ #ifndef TOOL_FACTORY_SEEN #define TOOL_FACTORY_SEEN -#include "factory.h" +#include <string> namespace Inkscape { namespace UI { @@ -23,7 +23,9 @@ class ToolBase; } } -typedef Singleton< Factory<Inkscape::UI::Tools::ToolBase> > ToolFactory; +struct ToolFactory { + static Inkscape::UI::Tools::ToolBase *createObject(std::string const& id); +}; #endif diff --git a/src/ui/tools/arc-tool.cpp b/src/ui/tools/arc-tool.cpp index b9206407a..c6a9bb23a 100644 --- a/src/ui/tools/arc-tool.cpp +++ b/src/ui/tools/arc-tool.cpp @@ -48,20 +48,10 @@ using Inkscape::DocumentUndo; -#include "ui/tool-factory.h" - namespace Inkscape { namespace UI { namespace Tools { -namespace { - ToolBase* createArcContext() { - return new ArcTool(); - } - - bool arcContextRegistered = ToolFactory::instance().registerObject("/tools/shapes/arc", createArcContext); -} - const std::string& ArcTool::getPrefsPath() { return ArcTool::prefsPath; } diff --git a/src/ui/tools/box3d-tool.cpp b/src/ui/tools/box3d-tool.cpp index f8ae685c4..538e0c7e2 100644 --- a/src/ui/tools/box3d-tool.cpp +++ b/src/ui/tools/box3d-tool.cpp @@ -52,20 +52,10 @@ using Inkscape::DocumentUndo; -#include "ui/tool-factory.h" - namespace Inkscape { namespace UI { namespace Tools { -namespace { - ToolBase* createBox3dTool() { - return new Box3dTool(); - } - - bool Box3dToolRegistered = ToolFactory::instance().registerObject("/tools/shapes/3dbox", createBox3dTool); -} - const std::string& Box3dTool::getPrefsPath() { return Box3dTool::prefsPath; } diff --git a/src/ui/tools/calligraphic-tool.cpp b/src/ui/tools/calligraphic-tool.cpp index 151ab5f89..15e6527a3 100644 --- a/src/ui/tools/calligraphic-tool.cpp +++ b/src/ui/tools/calligraphic-tool.cpp @@ -82,22 +82,12 @@ using Inkscape::DocumentUndo; #define DYNA_MIN_WIDTH 1.0e-6 -#include "ui/tool-factory.h" - namespace Inkscape { namespace UI { namespace Tools { static void add_cap(SPCurve *curve, Geom::Point const &from, Geom::Point const &to, double rounding); -namespace { - ToolBase* createCalligraphicContext() { - return new CalligraphicTool(); - } - - bool calligraphicContextRegistered = ToolFactory::instance().registerObject("/tools/calligraphic", createCalligraphicContext); -} - const std::string& CalligraphicTool::getPrefsPath() { return CalligraphicTool::prefsPath; } diff --git a/src/ui/tools/connector-tool.cpp b/src/ui/tools/connector-tool.cpp index 26a4eadd5..d76b0d142 100644 --- a/src/ui/tools/connector-tool.cpp +++ b/src/ui/tools/connector-tool.cpp @@ -109,8 +109,6 @@ using Inkscape::DocumentUndo; -#include "ui/tool-factory.h" - namespace Inkscape { namespace UI { namespace Tools { @@ -147,14 +145,6 @@ static Inkscape::XML::NodeEventVector layer_repr_events = { NULL /* order_changed */ }; -namespace { - ToolBase* createConnectorContext() { - return new ConnectorTool(); - } - - bool connectorContextRegistered = ToolFactory::instance().registerObject("/tools/connector", createConnectorContext); -} - const std::string& ConnectorTool::getPrefsPath() { return ConnectorTool::prefsPath; } diff --git a/src/ui/tools/dropper-tool.cpp b/src/ui/tools/dropper-tool.cpp index 9038628ee..bda9d8e8a 100644 --- a/src/ui/tools/dropper-tool.cpp +++ b/src/ui/tools/dropper-tool.cpp @@ -52,20 +52,10 @@ using Inkscape::DocumentUndo; static GdkCursor *cursor_dropper_fill = NULL; static GdkCursor *cursor_dropper_stroke = NULL; -#include "ui/tool-factory.h" - namespace Inkscape { namespace UI { namespace Tools { -namespace { - ToolBase* createDropperContext() { - return new DropperTool(); - } - - bool dropperContextRegistered = ToolFactory::instance().registerObject("/tools/dropper", createDropperContext); -} - const std::string& DropperTool::getPrefsPath() { return DropperTool::prefsPath; } diff --git a/src/ui/tools/eraser-tool.cpp b/src/ui/tools/eraser-tool.cpp index 1b4dcfe25..af0cbcb78 100644 --- a/src/ui/tools/eraser-tool.cpp +++ b/src/ui/tools/eraser-tool.cpp @@ -84,20 +84,10 @@ using Inkscape::DocumentUndo; #define DRAG_DEFAULT 1.0 #define DRAG_MAX 1.0 -#include "ui/tool-factory.h" - namespace Inkscape { namespace UI { namespace Tools { -namespace { - ToolBase* createEraserContext() { - return new EraserTool(); - } - - bool eraserContextRegistered = ToolFactory::instance().registerObject("/tools/eraser", createEraserContext); -} - const std::string& EraserTool::getPrefsPath() { return EraserTool::prefsPath; } diff --git a/src/ui/tools/flood-tool.cpp b/src/ui/tools/flood-tool.cpp index e4c4e855d..bb8782dfa 100644 --- a/src/ui/tools/flood-tool.cpp +++ b/src/ui/tools/flood-tool.cpp @@ -74,20 +74,10 @@ using Inkscape::Display::ExtractARGB32; using Inkscape::Display::ExtractRGB32; using Inkscape::Display::AssembleARGB32; -#include "ui/tool-factory.h" - namespace Inkscape { namespace UI { namespace Tools { -namespace { - ToolBase* createPaintbucketContext() { - return new FloodTool(); - } - - bool paintbucketContextRegistered = ToolFactory::instance().registerObject("/tools/paintbucket", createPaintbucketContext); -} - const std::string& FloodTool::getPrefsPath() { return FloodTool::prefsPath; } @@ -1097,8 +1087,8 @@ bool FloodTool::item_handler(SPItem* item, GdkEvent* event) { desktop->applyCurrentOrToolStyle(item, "/tools/paintbucket", false); DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_PAINTBUCKET, _("Set style on object")); - - ret = TRUE; + // Dead assignment: Value stored to 'ret' is never read + //ret = TRUE; } break; diff --git a/src/ui/tools/gradient-tool.cpp b/src/ui/tools/gradient-tool.cpp index 5da30da7b..5be84eb76 100644 --- a/src/ui/tools/gradient-tool.cpp +++ b/src/ui/tools/gradient-tool.cpp @@ -51,22 +51,12 @@ using Inkscape::DocumentUndo; -#include "ui/tool-factory.h" - namespace Inkscape { namespace UI { namespace Tools { static void sp_gradient_drag(GradientTool &rc, Geom::Point const pt, guint state, guint32 etime); -namespace { - ToolBase* createGradientContext() { - return new GradientTool(); - } - - bool gradientContextRegistered = ToolFactory::instance().registerObject("/tools/gradient", createGradientContext); -} - const std::string& GradientTool::getPrefsPath() { return GradientTool::prefsPath; } diff --git a/src/ui/tools/lpe-tool.cpp b/src/ui/tools/lpe-tool.cpp index c9b656397..c0517578d 100644 --- a/src/ui/tools/lpe-tool.cpp +++ b/src/ui/tools/lpe-tool.cpp @@ -58,23 +58,12 @@ SubtoolEntry lpesubtools[] = { {Inkscape::LivePathEffect::MIRROR_SYMMETRY, "draw-geometry-mirror"} }; - -#include "ui/tool-factory.h" - namespace Inkscape { namespace UI { namespace Tools { void sp_lpetool_context_selection_changed(Inkscape::Selection *selection, gpointer data); -namespace { - ToolBase* createLPEToolContext() { - return new LpeTool(); - } - - bool lpetoolContextRegistered = ToolFactory::instance().registerObject("/tools/lpetool", createLPEToolContext); -} - const std::string& LpeTool::getPrefsPath() { return LpeTool::prefsPath; } diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index b7e54b9c8..0875c29e0 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -49,22 +49,12 @@ using Inkscape::ControlManager; using Inkscape::CTLINE_SECONDARY; using Inkscape::Util::unit_table; -#include "ui/tool-factory.h" - namespace Inkscape { namespace UI { namespace Tools { std::vector<Inkscape::Display::TemporaryItem*> measure_tmp_items; -namespace { - ToolBase* createMeasureContext() { - return new MeasureTool(); - } - - bool measureContextRegistered = ToolFactory::instance().registerObject("/tools/measure", createMeasureContext); -} - const std::string& MeasureTool::getPrefsPath() { return MeasureTool::prefsPath; } diff --git a/src/ui/tools/mesh-tool.cpp b/src/ui/tools/mesh-tool.cpp index d333b932e..67ed7aef1 100644 --- a/src/ui/tools/mesh-tool.cpp +++ b/src/ui/tools/mesh-tool.cpp @@ -48,27 +48,17 @@ // Mesh specific #include "ui/tools/mesh-tool.h" -#include "sp-mesh-gradient.h" +#include "sp-mesh.h" #include "display/sp-ctrlcurve.h" using Inkscape::DocumentUndo; -#include "ui/tool-factory.h" - namespace Inkscape { namespace UI { namespace Tools { static void sp_mesh_drag(MeshTool &rc, Geom::Point const pt, guint state, guint32 etime); -namespace { - ToolBase* createMeshContext() { - return new MeshTool(); - } - - bool meshContextRegistered = ToolFactory::instance().registerObject("/tools/mesh", createMeshContext); -} - const std::string& MeshTool::getPrefsPath() { return MeshTool::prefsPath; } @@ -172,9 +162,9 @@ void MeshTool::selection_changed(Inkscape::Selection* /*sel*/) { // if (style && (style->fill.isPaintserver())) { // SPPaintServer *server = item->style->getFillPaintServer(); - // if ( SP_IS_MESHGRADIENT(server) ) { + // if ( SP_IS_MESH(server) ) { - // SPMeshGradient *mg = SP_MESHGRADIENT(server); + // SPMesh *mg = SP_MESH(server); // guint rows = 0;//mg->array.patches.size(); // for ( guint i = 0; i < rows; ++i ) { @@ -337,8 +327,8 @@ sp_mesh_context_corner_operation (MeshTool *rc, MeshCornerOperation operation ) SPDocument *doc = NULL; GrDrag *drag = rc->_grdrag; - std::map<SPMeshGradient*, std::vector<guint> > points; - std::map<SPMeshGradient*, SPItem*> items; + std::map<SPMesh*, std::vector<guint> > points; + std::map<SPMesh*, SPItem*> items; // Get list of selected draggers for each mesh. // For all selected draggers @@ -352,7 +342,7 @@ sp_mesh_context_corner_operation (MeshTool *rc, MeshCornerOperation operation ) if( d->point_type != POINT_MG_CORNER ) continue; // Find the gradient - SPMeshGradient *gradient = SP_MESHGRADIENT( getGradient (d->item, d->fill_or_stroke) ); + SPMesh *gradient = SP_MESH( getGradient (d->item, d->fill_or_stroke) ); // Collect points together for same gradient points[gradient].push_back( d->point_i ); @@ -361,8 +351,8 @@ sp_mesh_context_corner_operation (MeshTool *rc, MeshCornerOperation operation ) } // Loop over meshes. - for( std::map<SPMeshGradient*, std::vector<guint> >::const_iterator iter = points.begin(); iter != points.end(); ++iter) { - SPMeshGradient *mg = SP_MESHGRADIENT( iter->first ); + for( std::map<SPMesh*, std::vector<guint> >::const_iterator iter = points.begin(); iter != points.end(); ++iter) { + SPMesh *mg = SP_MESH( iter->first ); if( iter->second.size() > 0 ) { guint noperation = 0; switch (operation) { diff --git a/src/ui/tools/node-tool.cpp b/src/ui/tools/node-tool.cpp index caec901a6..f8045a029 100644 --- a/src/ui/tools/node-tool.cpp +++ b/src/ui/tools/node-tool.cpp @@ -107,20 +107,10 @@ using Inkscape::ControlManager; -#include "ui/tool-factory.h" - namespace Inkscape { namespace UI { namespace Tools { -namespace { - ToolBase* createNodesContext() { - return new NodeTool(); - } - - bool nodesContextRegistered = ToolFactory::instance().registerObject("/tools/nodes", createNodesContext); -} - const std::string& NodeTool::getPrefsPath() { return NodeTool::prefsPath; } diff --git a/src/ui/tools/pen-tool.cpp b/src/ui/tools/pen-tool.cpp index 5174775c9..d28b7c27a 100644 --- a/src/ui/tools/pen-tool.cpp +++ b/src/ui/tools/pen-tool.cpp @@ -73,8 +73,6 @@ #include "live_effects/lpe-bspline.h" #include <2geom/nearest-point.h> -#include "ui/tool-factory.h" - #include "live_effects/effect.h" @@ -88,13 +86,6 @@ static Geom::Point pen_drag_origin_w(0, 0); static bool pen_within_tolerance = false; static int pen_last_paraxial_dir = 0; // last used direction in horizontal/vertical mode; 0 = horizontal, 1 = vertical const double handleCubicGap = 0.01; -namespace { - ToolBase* createPenContext() { - return new PenTool(); - } - - bool penContextRegistered = ToolFactory::instance().registerObject("/tools/freehand/pen", createPenContext); -} const std::string& PenTool::getPrefsPath() { return PenTool::prefsPath; diff --git a/src/ui/tools/pencil-tool.cpp b/src/ui/tools/pencil-tool.cpp index 28fed3a8f..db24c7432 100644 --- a/src/ui/tools/pencil-tool.cpp +++ b/src/ui/tools/pencil-tool.cpp @@ -43,7 +43,6 @@ #include "display/sp-canvas.h" #include "display/curve.h" #include "livarot/Path.h" -#include "ui/tool-factory.h" #include "ui/tool/event-utils.h" namespace Inkscape { @@ -55,14 +54,6 @@ static bool pencil_within_tolerance = false; static bool in_svg_plane(Geom::Point const &p) { return Geom::LInfty(p) < 1e18; } -namespace { - ToolBase* createPencilContext() { - return new PencilTool(); - } - - bool pencilContextRegistered = ToolFactory::instance().registerObject("/tools/freehand/pencil", createPencilContext); -} - const std::string& PencilTool::getPrefsPath() { return PencilTool::prefsPath; } diff --git a/src/ui/tools/rect-tool.cpp b/src/ui/tools/rect-tool.cpp index 9476ff624..62a9006ea 100644 --- a/src/ui/tools/rect-tool.cpp +++ b/src/ui/tools/rect-tool.cpp @@ -46,20 +46,10 @@ using Inkscape::DocumentUndo; -#include "ui/tool-factory.h" - namespace Inkscape { namespace UI { namespace Tools { -namespace { - ToolBase* createRectContext() { - return new RectTool(); - } - - bool rectContextRegistered = ToolFactory::instance().registerObject("/tools/shapes/rect", createRectContext); -} - const std::string& RectTool::getPrefsPath() { return RectTool::prefsPath; } diff --git a/src/ui/tools/select-tool.cpp b/src/ui/tools/select-tool.cpp index 939b1a0b3..40b994968 100644 --- a/src/ui/tools/select-tool.cpp +++ b/src/ui/tools/select-tool.cpp @@ -49,7 +49,6 @@ #include "display/sp-canvas.h" #include "display/sp-canvas-item.h" #include "display/drawing-item.h" -#include "ui/tool-factory.h" using Inkscape::DocumentUndo; @@ -65,14 +64,6 @@ static GdkCursor *CursorSelectDragging = NULL; static gint rb_escaped = 0; // if non-zero, rubberband was canceled by esc, so the next button release should not deselect static gint drag_escaped = 0; // if non-zero, drag was canceled by esc -namespace { - ToolBase* createSelectContext() { - return new SelectTool(); - } - - bool selectContextRegistered = ToolFactory::instance().registerObject("/tools/select", createSelectContext); -} - const std::string& SelectTool::getPrefsPath() { return SelectTool::prefsPath; } diff --git a/src/ui/tools/spiral-tool.cpp b/src/ui/tools/spiral-tool.cpp index f208e1c43..833fef18d 100644 --- a/src/ui/tools/spiral-tool.cpp +++ b/src/ui/tools/spiral-tool.cpp @@ -45,20 +45,10 @@ using Inkscape::DocumentUndo; -#include "ui/tool-factory.h" - namespace Inkscape { namespace UI { namespace Tools { -namespace { - ToolBase* createSpiralContext() { - return new SpiralTool(); - } - - bool spiralContextRegistered = ToolFactory::instance().registerObject("/tools/shapes/spiral", createSpiralContext); -} - const std::string& SpiralTool::getPrefsPath() { return SpiralTool::prefsPath; } diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index a01c5c55b..ec7d10e13 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -84,20 +84,10 @@ using namespace std; // Please enable again when working on 1.0 #define ENABLE_SPRAY_MODE_SINGLE_PATH -#include "ui/tool-factory.h" - namespace Inkscape { namespace UI { namespace Tools { -namespace { - ToolBase* createSprayContext() { - return new SprayTool(); - } - - bool sprayContextRegistered = ToolFactory::instance().registerObject("/tools/spray", createSprayContext); -} - const std::string& SprayTool::getPrefsPath() { return SprayTool::prefsPath; } @@ -449,39 +439,41 @@ static bool sp_spray_recursive(SPDesktop *desktop, } i++; } - SPDocument *doc = parent_item->document; - Inkscape::XML::Document* xml_doc = doc->getReprDoc(); - Inkscape::XML::Node *old_repr = parent_item->getRepr(); - Inkscape::XML::Node *parent = old_repr->parent(); - - Geom::OptRect a = parent_item->documentVisualBounds(); - if (a) { - if (_fid <= population) { // Rules the population of objects sprayed - // Duplicates the parent item - Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc); - parent->appendChild(copy); - SPObject *new_obj = doc->getObjectByRepr(copy); - item_copied = dynamic_cast<SPItem *>(new_obj); - - // Move around the cursor - Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); - - Geom::Point center = parent_item->getCenter(); - sp_spray_scale_rel(center, desktop, item_copied, Geom::Scale(_scale, _scale)); - sp_spray_scale_rel(center, desktop, item_copied, Geom::Scale(scale, scale)); - sp_spray_rotate_rel(center, desktop, item_copied, Geom::Rotate(angle)); - sp_item_move_rel(item_copied, Geom::Translate(move[Geom::X], -move[Geom::Y])); - - // Union and duplication - selection->clear(); - selection->add(item_copied); - if (unionResult) { // No need to add the very first item (initialized with NULL). - selection->add(unionResult); + if (parent_item) { + SPDocument *doc = parent_item->document; + Inkscape::XML::Document* xml_doc = doc->getReprDoc(); + Inkscape::XML::Node *old_repr = parent_item->getRepr(); + Inkscape::XML::Node *parent = old_repr->parent(); + + Geom::OptRect a = parent_item->documentVisualBounds(); + if (a) { + if (_fid <= population) { // Rules the population of objects sprayed + // Duplicates the parent item + Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc); + parent->appendChild(copy); + SPObject *new_obj = doc->getObjectByRepr(copy); + item_copied = dynamic_cast<SPItem *>(new_obj); + + // Move around the cursor + Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); + + Geom::Point center = parent_item->getCenter(); + sp_spray_scale_rel(center, desktop, item_copied, Geom::Scale(_scale, _scale)); + sp_spray_scale_rel(center, desktop, item_copied, Geom::Scale(scale, scale)); + sp_spray_rotate_rel(center, desktop, item_copied, Geom::Rotate(angle)); + sp_item_move_rel(item_copied, Geom::Translate(move[Geom::X], -move[Geom::Y])); + + // Union and duplication + selection->clear(); + selection->add(item_copied); + if (unionResult) { // No need to add the very first item (initialized with NULL). + selection->add(unionResult); + } + sp_selected_path_union_skip_undo(selection, selection->desktop()); + selection->add(parent_item); + Inkscape::GC::release(copy); + did = true; } - sp_selected_path_union_skip_undo(selection, selection->desktop()); - selection->add(parent_item); - Inkscape::GC::release(copy); - did = true; } } #endif diff --git a/src/ui/tools/star-tool.cpp b/src/ui/tools/star-tool.cpp index df311f2d8..9190ae57b 100644 --- a/src/ui/tools/star-tool.cpp +++ b/src/ui/tools/star-tool.cpp @@ -49,20 +49,10 @@ using Inkscape::DocumentUndo; -#include "ui/tool-factory.h" - namespace Inkscape { namespace UI { namespace Tools { -namespace { - ToolBase* createStarContext() { - return new StarTool(); - } - - bool starContextRegistered = ToolFactory::instance().registerObject("/tools/shapes/star", createStarContext); -} - const std::string& StarTool::getPrefsPath() { return StarTool::prefsPath; } diff --git a/src/ui/tools/text-tool.cpp b/src/ui/tools/text-tool.cpp index df0583d67..a2c0c81ae 100644 --- a/src/ui/tools/text-tool.cpp +++ b/src/ui/tools/text-tool.cpp @@ -52,7 +52,6 @@ #include "xml/node-event-vector.h" #include "xml/repr.h" #include <gtk/gtk.h> -#include "ui/tool-factory.h" using Inkscape::ControlManager; using Inkscape::DocumentUndo; @@ -71,14 +70,6 @@ static gint sptc_focus_in(GtkWidget *widget, GdkEventFocus *event, TextTool *tc) static gint sptc_focus_out(GtkWidget *widget, GdkEventFocus *event, TextTool *tc); static void sptc_commit(GtkIMContext *imc, gchar *string, TextTool *tc); -namespace { - ToolBase* createTextContext() { - return new TextTool(); - } - - bool textContextRegistered = ToolFactory::instance().registerObject("/tools/text", createTextContext); -} - const std::string& TextTool::getPrefsPath() { return TextTool::prefsPath; } diff --git a/src/ui/tools/tweak-tool.cpp b/src/ui/tools/tweak-tool.cpp index 5e53fdb93..80b52fba6 100644 --- a/src/ui/tools/tweak-tool.cpp +++ b/src/ui/tools/tweak-tool.cpp @@ -91,20 +91,10 @@ using Inkscape::DocumentUndo; #define DYNA_MIN_WIDTH 1.0e-6 -#include "ui/tool-factory.h" - namespace Inkscape { namespace UI { namespace Tools { -namespace { - ToolBase* createTweakContext() { - return new TweakTool(); - } - - bool tweakContextRegistered = ToolFactory::instance().registerObject("/tools/tweak", createTweakContext); -} - const std::string& TweakTool::getPrefsPath() { return TweakTool::prefsPath; } diff --git a/src/ui/tools/zoom-tool.cpp b/src/ui/tools/zoom-tool.cpp index b3fb78c8f..6a4d4dbbd 100644 --- a/src/ui/tools/zoom-tool.cpp +++ b/src/ui/tools/zoom-tool.cpp @@ -25,20 +25,11 @@ #include "selection-chemistry.h" #include "ui/tools/zoom-tool.h" -#include "ui/tool-factory.h" namespace Inkscape { namespace UI { namespace Tools { -namespace { - ToolBase* createZoomContext() { - return new ZoomTool(); - } - - bool zoomContextRegistered = ToolFactory::instance().registerObject("/tools/zoom", createZoomContext); -} - const std::string& ZoomTool::getPrefsPath() { return ZoomTool::prefsPath; } diff --git a/src/ui/view/view.h b/src/ui/view/view.h index 48f4d2549..21a5d0dfc 100644 --- a/src/ui/view/view.h +++ b/src/ui/view/view.h @@ -15,7 +15,7 @@ #include <stddef.h> #include <sigc++/connection.h> #include "message.h" -#include "gc-managed.h" +#include "inkgc/gc-managed.h" #include "gc-finalized.h" #include "gc-anchored.h" #include <2geom/forward.h> diff --git a/src/ui/widget/addtoicon.cpp b/src/ui/widget/addtoicon.cpp index 0798d1c98..f15d7abf7 100644 --- a/src/ui/widget/addtoicon.cpp +++ b/src/ui/widget/addtoicon.cpp @@ -23,6 +23,7 @@ #include "widgets/icon.h" #include "widgets/toolbox.h" #include "ui/icon-names.h" +#include "preferences.h" #include "layertypeicon.h" #include "addtoicon.h" @@ -39,6 +40,7 @@ AddToIcon::AddToIcon() : { property_mode() = Gtk::CELL_RENDERER_MODE_ACTIVATABLE; phys = sp_icon_get_phys_size((int)Inkscape::ICON_SIZE_BUTTON); + // Glib::RefPtr<Gtk::IconTheme> icon_theme = Gtk::IconTheme::get_default(); // // if (!icon_theme->has_icon(_pixAddName)) { @@ -50,7 +52,8 @@ AddToIcon::AddToIcon() : // // _property_pixbuf_add = Gtk::Widget:: - property_stock_id() = GTK_STOCK_ADD; + //property_stock_id() = GTK_STOCK_ADD; + set_pixbuf(); } @@ -118,7 +121,7 @@ void AddToIcon::render_vfunc( const Glib::RefPtr<Gdk::Drawable>& window, Gtk::CellRendererState flags ) #endif { - property_stock_id() = property_active().get_value() ? GTK_STOCK_ADD : GTK_STOCK_DELETE; + set_pixbuf(); #if WITH_GTKMM_3_0 Gtk::CellRendererPixbuf::render_vfunc( cr, widget, background_area, cell_area, flags ); @@ -137,6 +140,14 @@ bool AddToIcon::activate_vfunc(GdkEvent* /*event*/, return false; } +void AddToIcon::set_pixbuf() +{ + bool active = property_active().get_value(); + + GdkPixbuf *pixbuf = sp_pixbuf_new(Inkscape::ICON_SIZE_BUTTON, active ? INKSCAPE_ICON("list-add") : INKSCAPE_ICON("edit-delete")); + property_pixbuf() = Glib::wrap(pixbuf); +} + } // namespace Widget } // namespace UI @@ -152,5 +163,3 @@ bool AddToIcon::activate_vfunc(GdkEvent* /*event*/, End: */ // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : - - diff --git a/src/ui/widget/addtoicon.h b/src/ui/widget/addtoicon.h index 9c134d231..a8d900d1f 100644 --- a/src/ui/widget/addtoicon.h +++ b/src/ui/widget/addtoicon.h @@ -74,7 +74,7 @@ private: Glib::Property<bool> _property_active; // Glib::Property< Glib::RefPtr<Gdk::Pixbuf> > _property_pixbuf_add; - + void set_pixbuf(); }; diff --git a/src/ui/widget/licensor.cpp b/src/ui/widget/licensor.cpp index 7429bb07e..d21e848f2 100644 --- a/src/ui/widget/licensor.cpp +++ b/src/ui/widget/licensor.cpp @@ -69,7 +69,7 @@ void LicenseItem::on_toggled() SPDocument *doc = SP_ACTIVE_DOCUMENT; rdf_set_license (doc, _lic->details ? _lic : 0); if (doc->priv->sensitive) { - DocumentUndo::done(doc, SP_VERB_NONE, "Document license updated"); + DocumentUndo::done(doc, SP_VERB_NONE, _("Document license updated")); } _wr.setUpdating (false); static_cast<Gtk::Entry*>(_eep->_packable)->set_text (_lic->uri); diff --git a/src/ui/widget/page-sizer.cpp b/src/ui/widget/page-sizer.cpp index 8c3b44bf5..8e647ebb4 100644 --- a/src/ui/widget/page-sizer.cpp +++ b/src/ui/widget/page-sizer.cpp @@ -26,6 +26,7 @@ #include <cmath> #include <string> #include <string.h> +#include <sstream> #include <vector> #include <glibmm/i18n.h> @@ -240,6 +241,8 @@ PageSizer::PageSizer(Registry & _wr) _marginRight( _("Ri_ght:"), _("Right margin"), "fit-margin-right", _wr), _marginBottom( _("Botto_m:"), _("Bottom margin"), "fit-margin-bottom", _wr), _lockMarginUpdate(false), + _scaleX(_("Scale _x:"), _("Scale X"), "scale-x", _wr), + _lockScaleUpdate(false), _widgetRegistry(&_wr) { // set precision of scalar entry boxes @@ -250,6 +253,8 @@ PageSizer::PageSizer(Registry & _wr) _marginLeft.setDigits(5); _marginRight.setDigits(5); _marginBottom.setDigits(5); + _scaleX.setDigits(5); + _scaleX.setRange( 0.00001, 100000 ); _wr.setUpdating (false); //# Set up the Paper Size combo box @@ -318,6 +323,7 @@ PageSizer::PageSizer(Registry & _wr) } _wr.setUpdating (false); + //## Set up custom size frame _customFrame.set_label(_("Custom size")); pack_start (_customFrame, false, false, 0); @@ -419,6 +425,34 @@ PageSizer::PageSizer(Registry & _wr) _fitPageButton.set_label(_("_Resize page to drawing or selection")); _fitPageButton.set_tooltip_text(_("Resize the page to fit the current selection, or the entire drawing if there is no selection")); + _scaleFrame.set_label(_("Scale")); + pack_start (_scaleFrame, false, false, 0); + _scaleFrame.add(_scaleTable); + + _scaleTable.set_border_width(4); + +#if WITH_GTKMM_3_0 + _scaleTable.set_row_spacing(4); + _scaleTable.set_column_spacing(4); + + _dimensionWidth.set_hexpand(); + _dimensionWidth.set_vexpand(); + _scaleTable.attach(_scaleX, 0, 0, 1, 1); + + _dimensionUnits.set_hexpand(); + _dimensionUnits.set_vexpand(); + _scaleTable.attach(_scaleLabel, 1, 0, 1, 1); +#else + _scaleTable.resize(2, 1); + _scaleTable.set_row_spacings(4); + _scaleTable.set_col_spacings(4); + _scaleTable.attach(_scaleX, 0,1, 0,1); + _scaleTable.attach(_scaleLabel, 1,2, 0,1); +#endif + + _wr.setUpdating (true); + updateScaleUI(); + _wr.setUpdating (false); } @@ -444,7 +478,7 @@ PageSizer::init () _changedh_connection = _dimensionHeight.signal_value_changed().connect (sigc::mem_fun (*this, &PageSizer::on_value_changed)); _changedu_connection = _dimensionUnits.getUnitMenu()->signal_changed().connect (sigc::mem_fun (*this, &PageSizer::on_units_changed)); _fitPageButton.signal_clicked().connect(sigc::mem_fun(*this, &PageSizer::fire_fit_canvas_to_selection_or_drawing)); - + _changeds_connection = _scaleX.signal_value_changed().connect (sigc::mem_fun (*this, &PageSizer::on_scale_changed)); show_all_children(); } @@ -512,6 +546,7 @@ PageSizer::setDim (Inkscape::Util::Quantity w, Inkscape::Util::Quantity h, bool _dimensionHeight.setUnit(h.unit->abbr); _dimensionHeight.setValue (h.quantity); + _paper_size_list_connection.unblock(); _landscape_connection.unblock(); _portrait_connection.unblock(); @@ -701,6 +736,60 @@ PageSizer::on_landscape() } } + +/** + * Update scale widgets + */ +void +PageSizer::updateScaleUI() +{ + + if (_lockScaleUpdate) { + return; + } + + static bool _called = false; + if (_called) { + return; + } + + _called = true; + + _changeds_connection.block(); + + SPDesktop *dt = SP_ACTIVE_DESKTOP; + if (dt) { + SPDocument *doc = dt->getDocument(); + Geom::Scale scale = doc->getDocumentScale(); + + SPNamedView *nv = dt->getNamedView(); + + std::stringstream ss; + ss << _("User units per ") << nv->display_units->abbr << "." ; + _scaleLabel.set_text( ss.str() ); + + double scaleX_inv = + Inkscape::Util::Quantity::convert( scale[Geom::X], "px", nv->display_units ); + if( scaleX_inv > 0 ) { + _scaleX.setValue(1.0/scaleX_inv); + } else { + // Should never happen + std::cerr << "PageSizer::updateScaleUI(): Invalid scale value: " << scaleX_inv << std::endl; + _scaleX.setValue(1.0); + } + + } else { + // Should never happen + std::cerr << "PageSizer::updateScaleUI(): No active desktop." << std::endl; + _scaleLabel.set_text( "Unknown scale" ); + } + + _changeds_connection.unblock(); + + _called = false; +} + + /** * Callback for the dimension widgets */ @@ -722,6 +811,32 @@ PageSizer::on_units_changed() true, false); } +/** + * Callback for scale widgets + */ +void +PageSizer::on_scale_changed() +{ + if (_widgetRegistry->isUpdating()) return; + + double value = _scaleX.getValue(); + if( value > 0 ) { + + SPDesktop *dt = SP_ACTIVE_DESKTOP; + if (dt) { + SPDocument *doc = dt->getDocument(); + SPNamedView *nv = dt->getNamedView(); + + double scaleX_inv = Inkscape::Util::Quantity(1.0/value, nv->display_units ).value("px"); + + _lockScaleUpdate = true; + doc->setDocumentScale( 1.0/scaleX_inv ); + _lockScaleUpdate = false; + DocumentUndo::done(doc, SP_VERB_NONE, _("Set page scale")); + } + } +} + } // namespace Widget } // namespace UI } // namespace Inkscape diff --git a/src/ui/widget/page-sizer.h b/src/ui/widget/page-sizer.h index bed117e5a..f9a72d9f3 100644 --- a/src/ui/widget/page-sizer.h +++ b/src/ui/widget/page-sizer.h @@ -169,6 +169,11 @@ public: */ void updateFitMarginsUI(Inkscape::XML::Node *nv_repr); + /** + * Updates the scale widgets. (Just changes the values of the ui widgets.) + */ + void updateScaleUI(); + protected: /** @@ -250,12 +255,26 @@ protected: Gtk::Button _fitPageButton; bool _lockMarginUpdate; + // Document scale + Gtk::Frame _scaleFrame; +#if WITH_GTKMM_3_0 + Gtk::Grid _scaleTable; +#else + Gtk::Table _scaleTable; +#endif + + Gtk::Label _scaleLabel; + RegisteredScalar _scaleX; + bool _lockScaleUpdate; + //callback void on_value_changed(); void on_units_changed(); + void on_scale_changed(); sigc::connection _changedw_connection; sigc::connection _changedh_connection; sigc::connection _changedu_connection; + sigc::connection _changeds_connection; Registry *_widgetRegistry; diff --git a/src/ui/widget/selected-style.cpp b/src/ui/widget/selected-style.cpp index 1fc67dcef..9e283fc64 100644 --- a/src/ui/widget/selected-style.cpp +++ b/src/ui/widget/selected-style.cpp @@ -25,8 +25,8 @@ #include "desktop-style.h" #include "sp-namedview.h" #include "sp-linear-gradient.h" -#include "sp-mesh-gradient.h" #include "sp-radial-gradient.h" +#include "sp-mesh.h" #include "sp-pattern.h" #include "ui/dialog/dialog-manager.h" #include "ui/dialog/fill-and-stroke.h" @@ -1045,7 +1045,7 @@ SelectedStyle::update() place->set_tooltip_text(__rgradient[i]); _mode[i] = SS_RGRADIENT; #ifdef WITH_MESH - } else if (SP_IS_MESHGRADIENT(server)) { + } else if (SP_IS_MESH(server)) { SPGradient *vector = SP_GRADIENT(server)->getVector(); sp_gradient_image_set_gradient(SP_GRADIENT_IMAGE(_gradient_preview_m[i]), vector); place->add(_gradient_box_m[i]); diff --git a/src/undo-stack-observer.h b/src/undo-stack-observer.h index 1057ace8f..dadb4764e 100644 --- a/src/undo-stack-observer.h +++ b/src/undo-stack-observer.h @@ -10,7 +10,7 @@ #ifndef SEEN_UNDO_COMMIT_OBSERVER_H #define SEEN_UNDO_COMMIT_OBSERVER_H -#include "gc-managed.h" +#include "inkgc/gc-managed.h" namespace Inkscape { diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index 732e01b0c..8fd8c8c66 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -31,7 +31,6 @@ set(util_SRC list.h longest-common-suffix.h map-list.h - mathfns.h reference.h reverse-list.h share.h @@ -43,5 +42,5 @@ set(util_SRC ziptool.h ) -# add_inkscape_lib(util_LIB "${util_SRC}") -add_inkscape_source("${util_SRC}") +add_inkscape_lib(util_LIB "${util_SRC}") +# add_inkscape_source("${util_SRC}") diff --git a/src/util/Makefile_insert b/src/util/Makefile_insert index 6d2e63278..c23dffbca 100644 --- a/src/util/Makefile_insert +++ b/src/util/Makefile_insert @@ -1,8 +1,13 @@ ## Makefile.am fragment sourced by src/Makefile.am. -ink_common_sources += \ - util/ziptool.h \ - util/ziptool.cpp \ +util/all: util/libutil.a + +util/clean: + rm -f util/libutil.a $(util_libutil_a_OBJECTS) + +util_libutil_a_SOURCES = \ + util/ziptool.h \ + util/ziptool.cpp \ util/accumulators.h \ util/compose.hpp \ util/copy.h \ @@ -26,7 +31,6 @@ ink_common_sources += \ util/list-copy.h \ util/longest-common-suffix.h \ util/map-list.h \ - util/mathfns.h \ util/reference.h \ util/reverse-list.h \ util/share.h \ diff --git a/src/util/list.h b/src/util/list.h index de5a458e9..563b6091c 100644 --- a/src/util/list.h +++ b/src/util/list.h @@ -12,7 +12,7 @@ #include <cstddef> #include <iterator> -#include "gc-managed.h" +#include "inkgc/gc-managed.h" #include "util/reference.h" namespace Inkscape { diff --git a/src/util/share.h b/src/util/share.h index 6b5e6a4ef..8f1e7045a 100644 --- a/src/util/share.h +++ b/src/util/share.h @@ -12,7 +12,7 @@ #ifndef SEEN_INKSCAPE_UTIL_SHARE_H #define SEEN_INKSCAPE_UTIL_SHARE_H -#include "gc-core.h" +#include "inkgc/gc-core.h" #include <cstring> #include <cstddef> diff --git a/src/viewbox.cpp b/src/viewbox.cpp index 91f05668e..e1da23efa 100644 --- a/src/viewbox.cpp +++ b/src/viewbox.cpp @@ -14,9 +14,6 @@ #include <2geom/transforms.h> -#include "inkscape.h" -#include "document.h" -#include "util/units.h" #include "viewbox.h" #include "attributes.h" #include "enums.h" @@ -164,21 +161,20 @@ void SPViewBox::set_preserveAspectRatio(const gchar* value) { } // Apply scaling from viewbox -void SPViewBox::apply_viewbox(const Geom::Rect& in) { +void SPViewBox::apply_viewbox(const Geom::Rect& in, double scale_none) { /* Determine actual viewbox in viewport coordinates */ + // scale_none is the scale that would apply if the viewbox and page size are same size + // it is passed here because it is a double-precision variable, while 'in' is originally float double x = 0.0; double y = 0.0; double scale_x = in.width() / this->viewBox.width(); double scale_y = in.height() / this->viewBox.height(); double scale_uniform = 1.0; // used only if scaling is uniform - double scale_none = 1.0; // used only if viewbox and page size are same size if (Geom::are_near(scale_x / scale_y, 1.0, Geom::EPSILON)) { // scaling is already uniform, reduce numerical error scale_uniform = (scale_x + scale_y)/2.0; - if (SP_ACTIVE_DOCUMENT) - scale_none = Inkscape::Util::Quantity::convert(1, SP_ACTIVE_DOCUMENT->getDisplayUnit(), "px"); if (Geom::are_near(scale_uniform / scale_none, 1.0, Geom::EPSILON)) scale_uniform = scale_none; // objects are same size, reduce numerical error scale_x = scale_uniform; @@ -243,7 +239,7 @@ void SPViewBox::apply_viewbox(const Geom::Rect& in) { this->c2p = q * this->c2p; } -SPItemCtx SPViewBox::get_rctx(const SPItemCtx* ictx) { +SPItemCtx SPViewBox::get_rctx(const SPItemCtx* ictx, double scale_none) { /* Create copy of item context */ SPItemCtx rctx = *ictx; @@ -254,7 +250,7 @@ SPItemCtx SPViewBox::get_rctx(const SPItemCtx* ictx) { if (this->viewBox_set) { // Adjusts c2p for viewbox - apply_viewbox( rctx.viewport ); + apply_viewbox( rctx.viewport, scale_none ); } rctx.i2doc = this->c2p * rctx.i2doc; diff --git a/src/viewbox.h b/src/viewbox.h index 1898cd98f..c71abb610 100644 --- a/src/viewbox.h +++ b/src/viewbox.h @@ -41,9 +41,9 @@ public: void set_preserveAspectRatio(const gchar* value); /* Adjusts c2p for viewbox */ - void apply_viewbox(const Geom::Rect& in); + void apply_viewbox(const Geom::Rect& in, double scale_none = 1.0); - SPItemCtx get_rctx( const SPItemCtx* ictx); + SPItemCtx get_rctx( const SPItemCtx* ictx, double scale_none = 1.0); }; diff --git a/src/widgets/box3d-toolbar.cpp b/src/widgets/box3d-toolbar.cpp index 26e914070..31b897ced 100644 --- a/src/widgets/box3d-toolbar.cpp +++ b/src/widgets/box3d-toolbar.cpp @@ -193,15 +193,15 @@ static void box3d_toolbox_selection_changed(Inkscape::Selection *selection, GObj Inkscape::GC::anchor(persp_repr); sp_repr_add_listener(persp_repr, &box3d_persp_tb_repr_events, tbl); sp_repr_synthesize_events(persp_repr, &box3d_persp_tb_repr_events, tbl); - } - SP_ACTIVE_DOCUMENT->setCurrentPersp3D(persp3d_get_from_repr(persp_repr)); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setString("/tools/shapes/3dbox/persp", persp_repr->attribute("id")); + SP_ACTIVE_DOCUMENT->setCurrentPersp3D(persp3d_get_from_repr(persp_repr)); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setString("/tools/shapes/3dbox/persp", persp_repr->attribute("id")); - g_object_set_data(tbl, "freeze", GINT_TO_POINTER(TRUE)); - box3d_resync_toolbar(persp_repr, tbl); - g_object_set_data(tbl, "freeze", GINT_TO_POINTER(FALSE)); + g_object_set_data(tbl, "freeze", GINT_TO_POINTER(TRUE)); + box3d_resync_toolbar(persp_repr, tbl); + g_object_set_data(tbl, "freeze", GINT_TO_POINTER(FALSE)); + } } } diff --git a/src/widgets/gradient-selector.cpp b/src/widgets/gradient-selector.cpp index a5e16aed2..42e59cbfe 100644 --- a/src/widgets/gradient-selector.cpp +++ b/src/widgets/gradient-selector.cpp @@ -30,6 +30,7 @@ #include "helper/action.h" #include "helper/action-context.h" #include "preferences.h" +#include "widgets/icon.h" #include <glibmm/i18n.h> #include <xml/repr.h> @@ -101,6 +102,15 @@ static void sp_gradient_selector_class_init(SPGradientSelectorClass *klass) object_class->dispose = sp_gradient_selector_dispose; } +static void gradsel_style_button(GtkWidget *gtkbtn, char const *iconName) +{ + Gtk::Button *btn = Glib::wrap(GTK_BUTTON(gtkbtn)); + GtkWidget *child = sp_icon_new(Inkscape::ICON_SIZE_SMALL_TOOLBAR, iconName); + gtk_widget_show(child); + btn->add(*manage(Glib::wrap(child))); + btn->set_relief(Gtk::RELIEF_NONE); +} + static void sp_gradient_selector_init(SPGradientSelector *sel) { sel->safelyInit = true; @@ -179,13 +189,8 @@ static void sp_gradient_selector_init(SPGradientSelector *sel) //sel->nonsolid.push_back(hb); gtk_box_pack_start( GTK_BOX(sel), hb, FALSE, FALSE, 0 ); -#if GTK_CHECK_VERSION(3,10,0) - sel->add = gtk_button_new_from_icon_name(INKSCAPE_ICON("list-add"), GTK_ICON_SIZE_SMALL_TOOLBAR); -#else - sel->add = gtk_button_new (); - GtkWidget *img = gtk_image_new_from_icon_name(INKSCAPE_ICON("list-add"), GTK_ICON_SIZE_SMALL_TOOLBAR); - gtk_button_set_image(GTK_BUTTON(sel->add), img); -#endif + sel->add = gtk_button_new(); + gradsel_style_button(sel->add, INKSCAPE_ICON("list-add")); sel->nonsolid.push_back(sel->add); gtk_box_pack_start (GTK_BOX (hb), sel->add, FALSE, FALSE, 0); @@ -196,13 +201,8 @@ static void sp_gradient_selector_init(SPGradientSelector *sel) gtk_widget_set_tooltip_text( sel->add, _("Create a duplicate gradient")); // FIXME: Probably better to either use something from the icon naming spec or ship our own "edit-gradient" icon -#if GTK_CHECK_VERSION(3,10,0) - sel->edit = gtk_button_new_from_icon_name(INKSCAPE_ICON("gtk-edit"), GTK_ICON_SIZE_SMALL_TOOLBAR); -#else - sel->edit = gtk_button_new (); - img = gtk_image_new_from_icon_name(INKSCAPE_ICON("gtk-edit"), GTK_ICON_SIZE_SMALL_TOOLBAR); - gtk_button_set_image(GTK_BUTTON(sel->edit), img); -#endif + sel->edit = gtk_button_new(); + gradsel_style_button(sel->edit, INKSCAPE_ICON("gtk-edit")); sel->nonsolid.push_back(sel->edit); gtk_box_pack_start (GTK_BOX (hb), sel->edit, FALSE, FALSE, 0); @@ -211,13 +211,8 @@ static void sp_gradient_selector_init(SPGradientSelector *sel) gtk_button_set_relief(GTK_BUTTON(sel->edit), GTK_RELIEF_NONE); gtk_widget_set_tooltip_text( sel->edit, _("Edit gradient")); -#if GTK_CHECK_VERSION(3,10,0) - sel->del = gtk_button_new_from_icon_name(INKSCAPE_ICON("list-remove"), GTK_ICON_SIZE_SMALL_TOOLBAR); -#else sel->del = gtk_button_new (); - img = gtk_image_new_from_icon_name(INKSCAPE_ICON("list-remove"), GTK_ICON_SIZE_SMALL_TOOLBAR); - gtk_button_set_image(GTK_BUTTON(sel->del), img); -#endif + gradsel_style_button(sel->del, INKSCAPE_ICON("list-remove")); sel->swatch_widgets.push_back(sel->del); gtk_box_pack_start (GTK_BOX (hb), sel->del, FALSE, FALSE, 0); @@ -227,8 +222,6 @@ static void sp_gradient_selector_init(SPGradientSelector *sel) gtk_widget_set_tooltip_text( sel->del, _("Delete swatch")); gtk_widget_show_all(hb); - - } static void sp_gradient_selector_dispose(GObject *object) diff --git a/src/widgets/gradient-toolbar.cpp b/src/widgets/gradient-toolbar.cpp index ea009c048..7ce04403b 100644 --- a/src/widgets/gradient-toolbar.cpp +++ b/src/widgets/gradient-toolbar.cpp @@ -167,13 +167,15 @@ gboolean gr_vector_list(GtkWidget *combo_box, SPDesktop *desktop, bool selection if (gr_selected == NULL) { gtk_list_store_append(store, &iter); gtk_list_store_set(store, &iter, 0, _("No gradient"), 1, NULL, 2, NULL, -1); - sensitive = FALSE; + // Dead assignment: Value stored to 'sensitive' is never read + //sensitive = FALSE; } if (gr_multi) { gtk_list_store_append(store, &iter); gtk_list_store_set(store, &iter, 0, _("Multiple gradients"), 1, NULL, 2, NULL, -1); - sensitive = FALSE; + // Dead assignment: Value stored to 'sensitive' is never read + //sensitive = FALSE; } guint idx = 0; @@ -786,7 +788,8 @@ static gboolean update_stop_list( GtkWidget *stop_combo, SPGradient *gradient, S gtk_list_store_append(store, &iter); gtk_list_store_set(store, &iter, 0, label.c_str(), 1, pb, 2, stop, -1); - sensitive = FALSE; + // Dead assignment: Value stored to 'sensitive' is never read + //sensitive = FALSE; } } diff --git a/src/widgets/mesh-toolbar.cpp b/src/widgets/mesh-toolbar.cpp index 3d549047a..bf406e632 100644 --- a/src/widgets/mesh-toolbar.cpp +++ b/src/widgets/mesh-toolbar.cpp @@ -44,7 +44,7 @@ #include "ui/tools/gradient-tool.h" #include "ui/tools/mesh-tool.h" #include "gradient-drag.h" -#include "sp-mesh-gradient.h" +#include "sp-mesh.h" #include "gradient-chemistry.h" #include "gradient-selector.h" #include "selection.h" @@ -77,15 +77,15 @@ static bool blocked = false; * Get the current selection and dragger status from the desktop */ void ms_read_selection( Inkscape::Selection *selection, - SPMeshGradient *&ms_selected, + SPMesh *&ms_selected, bool &ms_selected_multi, - SPMeshSmooth &ms_smooth, - bool &ms_smooth_multi ) + SPMeshType &ms_type, + bool &ms_type_multi ) { // Read desktop selection bool first = true; - ms_smooth = SP_MESH_SMOOTH_NONE; + ms_type = SP_MESH_TYPE_COONS; for (GSList const* i = selection->itemList(); i; i = i->next) { SPItem *item = SP_ITEM(i->data); @@ -93,10 +93,10 @@ void ms_read_selection( Inkscape::Selection *selection, if (style && (style->fill.isPaintserver())) { SPPaintServer *server = item->style->getFillPaintServer(); - if ( SP_IS_MESHGRADIENT(server) ) { + if ( SP_IS_MESH(server) ) { - SPMeshGradient *gradient = SP_MESHGRADIENT(server); // ->getVector(); - SPMeshSmooth smooth = gradient->smooth; + SPMesh *gradient = SP_MESH(server); // ->getVector(); + SPMeshType type = gradient->type; if (gradient != ms_selected) { if (ms_selected) { @@ -105,11 +105,11 @@ void ms_read_selection( Inkscape::Selection *selection, ms_selected = gradient; } } - if( smooth != ms_smooth ) { - if (ms_smooth != SP_MESH_SMOOTH_NONE && !first) { - ms_smooth_multi = true; + if( type != ms_type ) { + if (ms_type != SP_MESH_TYPE_COONS && !first) { + ms_type_multi = true; } else { - ms_smooth = smooth; + ms_type = type; } } first = false; @@ -118,10 +118,10 @@ void ms_read_selection( Inkscape::Selection *selection, if (style && (style->stroke.isPaintserver())) { SPPaintServer *server = item->style->getStrokePaintServer(); - if ( SP_IS_MESHGRADIENT(server) ) { + if ( SP_IS_MESH(server) ) { - SPMeshGradient *gradient = SP_MESHGRADIENT(server); // ->getVector(); - SPMeshSmooth smooth = gradient->smooth; + SPMesh *gradient = SP_MESH(server); // ->getVector(); + SPMeshType type = gradient->type; if (gradient != ms_selected) { if (ms_selected) { @@ -130,11 +130,11 @@ void ms_read_selection( Inkscape::Selection *selection, ms_selected = gradient; } } - if( smooth != ms_smooth ) { - if (ms_smooth != SP_MESH_SMOOTH_NONE && !first) { - ms_smooth_multi = true; + if( type != ms_type ) { + if (ms_type != SP_MESH_TYPE_COONS && !first) { + ms_type_multi = true; } else { - ms_smooth = smooth; + ms_type = type; } } first = false; @@ -170,18 +170,18 @@ static void ms_tb_selection_changed(Inkscape::Selection * /*selection*/, gpointe // // Hide/show handles? // } - SPMeshGradient *ms_selected = 0; - SPMeshSmooth ms_smooth = SP_MESH_SMOOTH_NONE; + SPMesh *ms_selected = 0; + SPMeshType ms_type = SP_MESH_TYPE_COONS; bool ms_selected_multi = false; - bool ms_smooth_multi = false; - ms_read_selection( selection, ms_selected, ms_selected_multi, ms_smooth, ms_smooth_multi ); - // std::cout << " smooth: " << ms_smooth << std::endl; + bool ms_type_multi = false; + ms_read_selection( selection, ms_selected, ms_selected_multi, ms_type, ms_type_multi ); + // std::cout << " type: " << ms_type << std::endl; - EgeSelectOneAction* smooth = (EgeSelectOneAction *) g_object_get_data(G_OBJECT(widget), "mesh_select_smooth_action"); - gtk_action_set_sensitive( GTK_ACTION(smooth), (ms_selected && !ms_selected_multi) ); + EgeSelectOneAction* type = (EgeSelectOneAction *) g_object_get_data(G_OBJECT(widget), "mesh_select_type_action"); + gtk_action_set_sensitive( GTK_ACTION(type), (ms_selected && !ms_selected_multi) ); if (ms_selected) { blocked = TRUE; - ege_select_one_action_set_active( smooth, ms_smooth ); + ege_select_one_action_set_active( type, ms_type ); blocked = FALSE; } } @@ -209,9 +209,9 @@ static void ms_defs_modified(SPObject * /*defs*/, guint /*flags*/, GObject *widg ms_tb_selection_changed(NULL, widget); } -void ms_get_dt_selected_gradient(Inkscape::Selection *selection, SPMeshGradient *&ms_selected) +void ms_get_dt_selected_gradient(Inkscape::Selection *selection, SPMesh *&ms_selected) { - SPMeshGradient *gradient = 0; + SPMesh *gradient = 0; for (GSList const* i = selection->itemList(); i; i = i->next) { SPItem *item = SP_ITEM(i->data); // get the items gradient, not the getVector() version @@ -225,8 +225,8 @@ void ms_get_dt_selected_gradient(Inkscape::Selection *selection, SPMeshGradient server = item->style->getStrokePaintServer(); } - if ( SP_IS_MESHGRADIENT(server) ) { - gradient = SP_MESHGRADIENT(server); + if ( SP_IS_MESH(server) ) { + gradient = SP_MESH(server); } } @@ -240,11 +240,11 @@ void ms_get_dt_selected_gradient(Inkscape::Selection *selection, SPMeshGradient * Callback functions for user actions */ -static void ms_new_type_changed( EgeSelectOneAction *act, GObject * /*tbl*/ ) +static void ms_new_geometry_changed( EgeSelectOneAction *act, GObject * /*tbl*/ ) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - gint typemode = ege_select_one_action_get_active( act ) == 0 ? SP_GRADIENT_MESH_TYPE_NORMAL : SP_GRADIENT_MESH_TYPE_CONICAL; - prefs->setInt("/tools/mesh/mesh_type", typemode); + gint geometrymode = ege_select_one_action_get_active( act ) == 0 ? SP_MESH_GEOMETRY_NORMAL : SP_MESH_GEOMETRY_CONICAL; + prefs->setInt("/tools/mesh/mesh_geometry", geometrymode); } static void ms_new_fillstroke_changed( EgeSelectOneAction *act, GObject * /*tbl*/ ) @@ -288,27 +288,27 @@ static void ms_col_changed(GtkAdjustment *adj, GObject * /*tbl*/ ) blocked = FALSE; } -static void ms_smooth_changed(EgeSelectOneAction *act, GtkWidget *widget) +static void ms_type_changed(EgeSelectOneAction *act, GtkWidget *widget) { - // std::cout << "ms_smooth_changed" << std::endl; + // std::cout << "ms_type_changed" << std::endl; if (blocked) { return; } SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data(G_OBJECT(widget), "desktop")); Inkscape::Selection *selection = desktop->getSelection(); - SPMeshGradient *gradient = 0; + SPMesh *gradient = 0; ms_get_dt_selected_gradient(selection, gradient); if (gradient) { - SPMeshSmooth smooth = (SPMeshSmooth) ege_select_one_action_get_active(act); - // std::cout << " smooth: " << smooth << std::endl; - gradient->smooth = smooth; - gradient->smooth_set = true; + SPMeshType type = (SPMeshType) ege_select_one_action_get_active(act); + // std::cout << " type: " << type << std::endl; + gradient->type = type; + gradient->type_set = true; gradient->updateRepr(); DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_GRADIENT, - _("Set mesh smoothing")); + _("Set mesh type")); } } @@ -349,9 +349,9 @@ void sp_mesh_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, GObj ege_select_one_action_set_tooltip_column( act, 1 ); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - gint mode = prefs->getInt("/tools/mesh/mesh_type", SP_GRADIENT_MESH_TYPE_NORMAL) != SP_GRADIENT_MESH_TYPE_NORMAL; + gint mode = prefs->getInt("/tools/mesh/mesh_geometry", SP_MESH_GEOMETRY_NORMAL) != SP_MESH_GEOMETRY_NORMAL; ege_select_one_action_set_active( act, mode ); - g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(ms_new_type_changed), holder ); + g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(ms_new_geometry_changed), holder ); } /* New gradient on fill or stroke*/ @@ -460,51 +460,30 @@ void sp_mesh_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, GObj /* Warning */ { GtkAction* act = gtk_action_new( "MeshWarningAction", - _("WARNING: Mesh SVG Syntax Subject to Change, Smoothing Experimental"), NULL, NULL ); + _("WARNING: Mesh SVG Syntax Subject to Change"), NULL, NULL ); gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } - /* Smoothing method */ + /* Typeing method */ { GtkListStore* model = gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_INT ); GtkTreeIter iter; gtk_list_store_append( model, &iter ); - gtk_list_store_set( model, &iter, 0, C_("Smoothing", "None"), 1, SP_MESH_SMOOTH_NONE, -1 ); + gtk_list_store_set( model, &iter, 0, C_("Type", "Coons"), 1, SP_MESH_TYPE_COONS, -1 ); gtk_list_store_append( model, &iter ); - gtk_list_store_set( model, &iter, 0, _("Default"), 1, SP_MESH_SMOOTH_SMOOTH, -1 ); + gtk_list_store_set( model, &iter, 0, _("Bicubic"), 1, SP_MESH_TYPE_BICUBIC, -1 ); - gtk_list_store_append( model, &iter ); - gtk_list_store_set( model, &iter, 0, _("Smooth1"), 1, SP_MESH_SMOOTH_SMOOTH1, -1 ); - - gtk_list_store_append( model, &iter ); - gtk_list_store_set( model, &iter, 0, _("Smooth2"), 1, SP_MESH_SMOOTH_SMOOTH2, -1 ); - - gtk_list_store_append( model, &iter ); - gtk_list_store_set( model, &iter, 0, _("Smooth3"), 1, SP_MESH_SMOOTH_SMOOTH3, -1 ); - - gtk_list_store_append( model, &iter ); - gtk_list_store_set( model, &iter, 0, _("Smooth4"), 1, SP_MESH_SMOOTH_SMOOTH4, -1 ); - - gtk_list_store_append( model, &iter ); - gtk_list_store_set( model, &iter, 0, _("Smooth5"), 1, SP_MESH_SMOOTH_SMOOTH5, -1 ); - - gtk_list_store_append( model, &iter ); - gtk_list_store_set( model, &iter, 0, _("Smooth6"), 1, SP_MESH_SMOOTH_SMOOTH6, -1 ); - - gtk_list_store_append( model, &iter ); - gtk_list_store_set( model, &iter, 0, _("Smooth7"), 1, SP_MESH_SMOOTH_SMOOTH7, -1 ); - - EgeSelectOneAction* act = ege_select_one_action_new( "MeshSmoothAction", _("None"), - _("If the mesh should be smoothed across patch boundaries."), + EgeSelectOneAction* act = ege_select_one_action_new( "MeshSmoothAction", _("Coons"), + _("Coons: no smoothing. Bicubic: smoothing across patch boundaries."), NULL, GTK_TREE_MODEL(model) ); g_object_set( act, "short_label", _("Smoothing:"), NULL ); ege_select_one_action_set_appearance( act, "compact" ); gtk_action_set_sensitive( GTK_ACTION(act), FALSE ); - g_signal_connect( G_OBJECT(act), "changed", G_CALLBACK(ms_smooth_changed), holder ); + g_signal_connect( G_OBJECT(act), "changed", G_CALLBACK(ms_type_changed), holder ); gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); - g_object_set_data( holder, "mesh_select_smooth_action", act ); + g_object_set_data( holder, "mesh_select_type_action", act ); } } diff --git a/src/widgets/paint-selector.cpp b/src/widgets/paint-selector.cpp index 6ef910f61..948c80db3 100644 --- a/src/widgets/paint-selector.cpp +++ b/src/widgets/paint-selector.cpp @@ -37,8 +37,8 @@ #include "sp-color-notebook.h" #include "sp-linear-gradient.h" -#include "sp-mesh-gradient.h" #include "sp-radial-gradient.h" +#include "sp-mesh.h" /* fixme: Move it from dialogs to here */ #include "gradient-selector.h" #include <inkscape.h> @@ -777,7 +777,7 @@ static void sp_paint_selector_set_mode_gradient(SPPaintSelector *psel, SPPaintSe } #ifdef WITH_MESH else { - SP_GRADIENT_SELECTOR(gsel)->setMode(SPGradientSelector::MODE_RADIAL); + SP_GRADIENT_SELECTOR(gsel)->setMode(SPGradientSelector::MODE_MESH); gtk_label_set_markup(GTK_LABEL(psel->label), _("<b>Mesh gradient</b>")); } #endif @@ -1244,7 +1244,7 @@ SPPaintSelector::Mode SPPaintSelector::getModeForStyle(SPStyle const & style, Fi } else if (SP_IS_RADIALGRADIENT(server)) { mode = MODE_GRADIENT_RADIAL; #ifdef WITH_MESH - } else if (SP_IS_MESHGRADIENT(server)) { + } else if (SP_IS_MESH(server)) { mode = MODE_GRADIENT_MESH; #endif } else if (SP_IS_PATTERN(server)) { diff --git a/src/widgets/rect-toolbar.cpp b/src/widgets/rect-toolbar.cpp index 016aa4987..46f6d1c23 100644 --- a/src/widgets/rect-toolbar.cpp +++ b/src/widgets/rect-toolbar.cpp @@ -109,7 +109,7 @@ static void sp_rtb_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const * for (GSList const *items = selection->itemList(); items != NULL; items = items->next) { if (SP_IS_RECT(items->data)) { if (gtk_adjustment_get_value(adj) != 0) { - (SP_RECT(items->data)->*setter)(Quantity::convert(gtk_adjustment_get_value(adj), unit, desktop->getNamedView()->svg_units)); + (SP_RECT(items->data)->*setter)(Quantity::convert(gtk_adjustment_get_value(adj), unit, "px")); } else { SP_OBJECT(items->data)->getRepr()->setAttribute(value_name, NULL); } @@ -181,7 +181,6 @@ static void rect_tb_event_attr_changed(Inkscape::XML::Node * /*repr*/, gchar con UnitTracker* tracker = reinterpret_cast<UnitTracker*>( g_object_get_data( tbl, "tracker" ) ); Unit const *unit = tracker->getActiveUnit(); - Unit const *svg_unit = SP_ACTIVE_DESKTOP->getNamedView()->svg_units; g_return_if_fail(unit != NULL); gpointer item = g_object_get_data( tbl, "item" ); @@ -190,28 +189,28 @@ static void rect_tb_event_attr_changed(Inkscape::XML::Node * /*repr*/, gchar con GtkAdjustment *adj = GTK_ADJUSTMENT( g_object_get_data( tbl, "rx" ) ); gdouble rx = SP_RECT(item)->getVisibleRx(); - gtk_adjustment_set_value(adj, Quantity::convert(rx, svg_unit, unit)); + gtk_adjustment_set_value(adj, Quantity::convert(rx, "px", unit)); } { GtkAdjustment *adj = GTK_ADJUSTMENT( g_object_get_data( tbl, "ry" ) ); gdouble ry = SP_RECT(item)->getVisibleRy(); - gtk_adjustment_set_value(adj, Quantity::convert(ry, svg_unit, unit)); + gtk_adjustment_set_value(adj, Quantity::convert(ry, "px", unit)); } { GtkAdjustment *adj = GTK_ADJUSTMENT( g_object_get_data( tbl, "width" ) ); gdouble width = SP_RECT(item)->getVisibleWidth(); - gtk_adjustment_set_value(adj, Quantity::convert(width, svg_unit, unit)); + gtk_adjustment_set_value(adj, Quantity::convert(width, "px", unit)); } { GtkAdjustment *adj = GTK_ADJUSTMENT( g_object_get_data( tbl, "height" ) ); gdouble height = SP_RECT(item)->getVisibleHeight(); - gtk_adjustment_set_value(adj, Quantity::convert(height, svg_unit, unit)); + gtk_adjustment_set_value(adj, Quantity::convert(height, "px", unit)); } } @@ -307,7 +306,7 @@ void sp_rect_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR); //tracker->addUnit( SP_UNIT_PERCENT, 0 ); // fixme: add % meaning per cent of the width/height - tracker->setActiveUnit( desktop->getNamedView()->display_units ); + tracker->setActiveUnit(unit_table.getUnit("px")); g_object_set_data( holder, "tracker", tracker ); /* W */ diff --git a/src/widgets/ruler.cpp b/src/widgets/ruler.cpp index 8e818843d..ab486eeeb 100644 --- a/src/widgets/ruler.cpp +++ b/src/widgets/ruler.cpp @@ -144,7 +144,8 @@ static gboolean sp_ruler_expose (GtkWidget *widget, GdkEventExpose *event); #endif static void sp_ruler_draw_ticks (SPRuler *ruler); -static void sp_ruler_draw_pos (SPRuler *ruler); +static void sp_ruler_draw_pos (SPRuler *ruler, + cairo_t *cr); static void sp_ruler_make_pixmap (SPRuler *ruler); static PangoLayout * sp_ruler_get_layout (GtkWidget *widget, @@ -710,7 +711,7 @@ sp_ruler_draw (GtkWidget *widget, cairo_set_source_surface(cr, priv->backing_store, 0, 0); cairo_paint(cr); - sp_ruler_draw_pos (ruler); + sp_ruler_draw_pos (ruler, cr); return FALSE; } @@ -735,7 +736,8 @@ sp_ruler_make_pixmap (SPRuler *ruler) } static void -sp_ruler_draw_pos (SPRuler *ruler) +sp_ruler_draw_pos (SPRuler *ruler, + cairo_t *cr) { GtkWidget *widget = GTK_WIDGET (ruler); @@ -797,25 +799,31 @@ sp_ruler_draw_pos (SPRuler *ruler) if ((bs_width > 0) && (bs_height > 0)) { - cairo_t *cr = gdk_cairo_create (gtk_widget_get_window (widget)); gdouble lower; gdouble upper; gdouble position; gdouble increment; - cairo_rectangle (cr, - allocation.x, allocation.y, - allocation.width, allocation.height); - cairo_clip (cr); - - cairo_translate (cr, allocation.x, allocation.y); - - /* If a backing store exists, restore the ruler */ - if (priv->backing_store) + if (! cr) + { + cr = gdk_cairo_create (gtk_widget_get_window (widget)); + cairo_translate (cr, allocation.x, allocation.y); + cairo_rectangle (cr, allocation.x, allocation.y, allocation.width, allocation.height); + cairo_clip (cr); + + cairo_translate (cr, allocation.x, allocation.y); + + /* If a backing store exists, restore the ruler */ + if (priv->backing_store) + { + cairo_set_source_surface (cr, priv->backing_store, 0, 0); + cairo_rectangle (cr, priv->xsrc, priv->ysrc, bs_width, bs_height); + cairo_fill (cr); + } + } + else { - cairo_set_source_surface (cr, priv->backing_store, 0, 0); - cairo_rectangle (cr, priv->xsrc, priv->ysrc, bs_width, bs_height); - cairo_fill (cr); + cairo_reference (cr); } position = sp_ruler_get_position (ruler); @@ -1126,7 +1134,7 @@ sp_ruler_set_position (SPRuler *ruler, priv->position = position; g_object_notify (G_OBJECT (ruler), "position"); - sp_ruler_draw_pos (ruler); + sp_ruler_draw_pos (ruler, NULL); } } diff --git a/src/xml/attribute-record.h b/src/xml/attribute-record.h index a61329b83..7caeab6b6 100644 --- a/src/xml/attribute-record.h +++ b/src/xml/attribute-record.h @@ -6,7 +6,7 @@ #define SEEN_XML_SP_REPR_ATTR_H #include <glib.h> -#include "gc-managed.h" +#include "inkgc/gc-managed.h" #include "util/share.h" #define SP_REPR_ATTRIBUTE_KEY(a) g_quark_to_string((a)->key) diff --git a/src/xml/composite-node-observer.h b/src/xml/composite-node-observer.h index 3e4b1673a..6e93a57da 100644 --- a/src/xml/composite-node-observer.h +++ b/src/xml/composite-node-observer.h @@ -15,7 +15,7 @@ #ifndef SEEN_INKSCAPE_XML_COMPOSITE_NODE_OBSERVER_H #define SEEN_INKSCAPE_XML_COMPOSITE_NODE_OBSERVER_H -#include "gc-managed.h" +#include "inkgc/gc-managed.h" #include "xml/node-observer.h" #include "util/list-container.h" diff --git a/src/xml/event.h b/src/xml/event.h index d25ea0e07..73e68daeb 100644 --- a/src/xml/event.h +++ b/src/xml/event.h @@ -24,7 +24,7 @@ typedef unsigned int GQuark; #include <iterator> #include "util/share.h" #include "util/forward-pointer-iterator.h" -#include "gc-managed.h" +#include "inkgc/gc-managed.h" #include "xml/node.h" namespace Inkscape { diff --git a/src/xml/log-builder.h b/src/xml/log-builder.h index aa8f2c1c6..e94dd1daa 100644 --- a/src/xml/log-builder.h +++ b/src/xml/log-builder.h @@ -14,7 +14,7 @@ #ifndef SEEN_INKSCAPE_XML_LOG_BUILDER_H #define SEEN_INKSCAPE_XML_LOG_BUILDER_H -#include "gc-managed.h" +#include "inkgc/gc-managed.h" #include "xml/node-observer.h" namespace Inkscape { diff --git a/src/xml/repr-util.cpp b/src/xml/repr-util.cpp index 12280ea5a..7c5d2d6fc 100644 --- a/src/xml/repr-util.cpp +++ b/src/xml/repr-util.cpp @@ -32,6 +32,7 @@ #include <2geom/point.h> #include "svg/stringstream.h" #include "svg/css-ostringstream.h" +#include "svg/svg-length.h" #include "xml/repr.h" #include "xml/repr-sorting.h" @@ -502,6 +503,20 @@ unsigned int sp_repr_set_svg_double(Inkscape::XML::Node *repr, gchar const *key, return true; } +/** + * For attributes where an exponent is allowed. + * + * Not suitable for property attributes. + */ +unsigned int sp_repr_set_svg_length(Inkscape::XML::Node *repr, gchar const *key, SVGLength &val) +{ + g_return_val_if_fail(repr != NULL, FALSE); + g_return_val_if_fail(key != NULL, FALSE); + + repr->setAttribute(key, val.write()); + return true; +} + unsigned sp_repr_set_point(Inkscape::XML::Node *repr, gchar const *key, Geom::Point const & val) { g_return_val_if_fail(repr != NULL, FALSE); diff --git a/src/xml/repr.h b/src/xml/repr.h index e1d7fdfd6..c3ba40e45 100644 --- a/src/xml/repr.h +++ b/src/xml/repr.h @@ -30,6 +30,7 @@ #define SP_DC_NS_URI "http://purl.org/dc/elements/1.1/" class SPCSSAttr; +class SVGLength; namespace Inkscape { namespace IO { @@ -115,6 +116,7 @@ unsigned sp_repr_set_boolean(Inkscape::XML::Node *repr, char const *key, unsigne unsigned sp_repr_set_int(Inkscape::XML::Node *repr, char const *key, int val); unsigned sp_repr_set_css_double(Inkscape::XML::Node *repr, char const *key, double val); unsigned sp_repr_set_svg_double(Inkscape::XML::Node *repr, char const *key, double val); +unsigned sp_repr_set_svg_length(Inkscape::XML::Node *repr, char const *key, SVGLength &val); unsigned sp_repr_set_point(Inkscape::XML::Node *repr, char const *key, Geom::Point const & val); unsigned sp_repr_get_point(Inkscape::XML::Node *repr, char const *key, Geom::Point *val); diff --git a/src/xml/subtree.h b/src/xml/subtree.h index 11bf515f1..bc6ae913a 100644 --- a/src/xml/subtree.h +++ b/src/xml/subtree.h @@ -15,7 +15,7 @@ #ifndef SEEN_INKSCAPE_XML_SUBTREE_H #define SEEN_INKSCAPE_XML_SUBTREE_H -#include "gc-managed.h" +#include "inkgc/gc-managed.h" #include "xml/composite-node-observer.h" namespace Inkscape { |
