From 64fb7253a1d2771c4f844d1c2266a90f328895b5 Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Wed, 30 Jul 2014 22:47:29 +0200 Subject: Limit the number of paths to be used as snap targets, to keep Inkscape responsive in very complex drawings Fixed bugs: - https://launchpad.net/bugs/1348959 (bzr r13483) --- src/object-snapper.cpp | 4 ++++ src/seltrans.cpp | 1 + 2 files changed, 5 insertions(+) (limited to 'src') diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index 3b8956bc8..0f7aa6368 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -147,6 +147,10 @@ void Inkscape::ObjectSnapper::_findCandidates(SPObject* parent, // For debugging: print the id of the candidate to the console // SPObject *obj = (SPObject*)item; // std::cout << "Snap candidate added: " << obj->getId() << std::endl; + if (_candidates->size() > 200) { // This makes Inkscape crawl already + std::cout << "Warning: limit of 200 snap target paths reached, some will be ignored" << std::endl; + break; + } } } } diff --git a/src/seltrans.cpp b/src/seltrans.cpp index 4b1a3a5fa..6b8cd19bb 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -304,6 +304,7 @@ void Inkscape::SelTrans::grab(Geom::Point const &p, gdouble x, gdouble y, bool s /* Snapping a huge number of nodes will take way too long, so limit the number of snappable nodes A typical user would rarely ever try to snap such a large number of nodes anyway, because (s)he would hardly be able to discern which node would be snapping */ + std::cout << "Warning: limit of 200 snap sources reached, some will be ignored" << std::endl; _snap_points.resize(200); // Unfortunately, by now we will have lost the font-baseline snappoints :-( } -- cgit v1.2.3 From 291925ef62d1068af1c4b7f3614c96d46f3c20f2 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Thu, 31 Jul 2014 16:31:01 +0200 Subject: Basic support for element (rendering only as a paint server). (bzr r13484) --- src/CMakeLists.txt | 2 ++ src/Makefile_insert | 1 + src/attributes.cpp | 2 ++ src/attributes.h | 2 ++ src/sp-solid-color.cpp | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/sp-solid-color.h | 46 ++++++++++++++++++++++++ src/style.cpp | 23 ++++++++++++ src/style.h | 5 +++ 8 files changed, 178 insertions(+) create mode 100644 src/sp-solid-color.cpp create mode 100644 src/sp-solid-color.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d40aad802..4a792af6b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -63,6 +63,7 @@ set(sp_SRC sp-root.cpp sp-script.cpp sp-shape.cpp + sp-solid-color.cpp sp-spiral.cpp sp-star.cpp sp-stop.cpp @@ -147,6 +148,7 @@ set(sp_SRC sp-root.h sp-script.h sp-shape.h + sp-solid-color.h sp-spiral.h sp-star.h sp-stop.h diff --git a/src/Makefile_insert b/src/Makefile_insert index 6d0d6b08c..f191839a1 100644 --- a/src/Makefile_insert +++ b/src/Makefile_insert @@ -192,6 +192,7 @@ ink_common_sources += \ sp-root.cpp sp-root.h \ sp-script.cpp sp-script.h \ sp-shape.cpp sp-shape.h \ + sp-solid-color.cpp sp-solid-color.h \ sp-spiral.cpp sp-spiral.h \ sp-star.cpp sp-star.h \ sp-stop.cpp sp-stop.h \ diff --git a/src/attributes.cpp b/src/attributes.cpp index ee2a80fd3..da7b25f03 100644 --- a/src/attributes.cpp +++ b/src/attributes.cpp @@ -475,6 +475,8 @@ static SPStyleProp const props[] = { {SP_PROP_MARKER_START, "marker-start"}, {SP_PROP_PAINT_ORDER, "paint-order" }, {SP_PROP_SHAPE_RENDERING, "shape-rendering"}, + {SP_PROP_SOLID_COLOR, "solid-color"}, + {SP_PROP_SOLID_OPACITY, "solid-opacity"}, {SP_PROP_STROKE, "stroke"}, {SP_PROP_STROKE_DASHARRAY, "stroke-dasharray"}, {SP_PROP_STROKE_DASHOFFSET, "stroke-dashoffset"}, diff --git a/src/attributes.h b/src/attributes.h index b8843fcb7..82e7ca8a6 100644 --- a/src/attributes.h +++ b/src/attributes.h @@ -476,6 +476,8 @@ enum SPAttributeEnum { SP_PROP_MARKER_START, SP_PROP_PAINT_ORDER, /* SVG2 */ SP_PROP_SHAPE_RENDERING, + SP_PROP_SOLID_COLOR, + SP_PROP_SOLID_OPACITY, SP_PROP_STROKE, SP_PROP_STROKE_DASHARRAY, SP_PROP_STROKE_DASHOFFSET, diff --git a/src/sp-solid-color.cpp b/src/sp-solid-color.cpp new file mode 100644 index 000000000..1f606d176 --- /dev/null +++ b/src/sp-solid-color.cpp @@ -0,0 +1,97 @@ +/** @file + * @solid color class. + */ +/* Authors: + * Tavmjong Bah + * + * Copyright (C) 2014 Tavmjong Bah + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ +#include "sp-solid-color.h" + +#include "attributes.h" +#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 + */ +SPSolidColor::SPSolidColor() : SPPaintServer() { +} + +SPSolidColor::~SPSolidColor() { +} + +void SPSolidColor::build(SPDocument* doc, Inkscape::XML::Node* repr) { + SPPaintServer::build(doc, repr); + + this->readAttr( "style" ); + this->readAttr( "solid-color" ); + this->readAttr( "solid-opacity" ); +} + +/** + * Virtual build: set solidcolor attributes from its associated XML node. + */ + +void SPSolidColor::set(unsigned int key, const gchar* value) { + + if (SP_ATTRIBUTE_IS_CSS(key)) { + sp_style_read_from_object(this->style, this); + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); + } else { + SPPaintServer::set(key, value); + } +} + +/** + * Virtual set: set attribute to value. + */ + +Inkscape::XML::Node* SPSolidColor::write(Inkscape::XML::Document* xml_doc, Inkscape::XML::Node* repr, guint flags) { + if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { + repr = xml_doc->createElement("svg:solidColor"); + } + + SPObject::write(xml_doc, repr, flags); + + return repr; +} + +cairo_pattern_t* SPSolidColor::pattern_new(cairo_t * /*ct*/, Geom::OptRect const &bbox, double opacity) { + + SPIColor *c = &(this->style->solid_color); + cairo_pattern_t *cp = cairo_pattern_create_rgba ( c->value.color.v.c[0], c->value.color.v.c[1], c->value.color.v.c[2], SP_SCALE24_TO_FLOAT(this->style->solid_opacity.value) * opacity ); + + return cp; +} + + +/** + * Virtual write: write object attributes to repr. + */ + +/* + 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-solid-color.h b/src/sp-solid-color.h new file mode 100644 index 000000000..0ff09762e --- /dev/null +++ b/src/sp-solid-color.h @@ -0,0 +1,46 @@ +#ifndef SEEN_SP_SOLIDCOLOR_H +#define SEEN_SP_SOLIDCOLOR_H + +/** \file + * SPSolidColor: SVG implementation. + */ +/* + * Authors: Tavmjong Bah + * Copyright (C) 2012 Tavmjong Bah + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include +#include "color.h" +#include "sp-paint-server.h" + +#define SP_SOLIDCOLOR(obj) (dynamic_cast((SPObject*)obj)) +#define SP_IS_SOLIDCOLOR(obj) (dynamic_cast((SPObject*)obj) != NULL) + +/** Gradient SolidColor. */ +class SPSolidColor : public SPPaintServer { +public: + SPSolidColor(); + virtual ~SPSolidColor(); + + virtual cairo_pattern_t* pattern_new(cairo_t *ct, Geom::OptRect const &bbox, double opacity); + +protected: + virtual void build(SPDocument* doc, Inkscape::XML::Node* repr); + virtual void set(unsigned int key, const gchar* value); + virtual Inkscape::XML::Node* write(Inkscape::XML::Document* doc, Inkscape::XML::Node* repr, guint flags); +}; + +#endif /* !SEEN_SP_SOLIDCOLOR_H */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/style.cpp b/src/style.cpp index 222155a0c..f0710e404 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -153,6 +153,10 @@ SPStyle::SPStyle(SPDocument *document_in, SPObject *object_in) : color_interpolation( "color-interpolation", enum_color_interpolation, SP_CSS_COLOR_INTERPOLATION_SRGB), color_interpolation_filters("color-interpolation-filters", enum_color_interpolation, SP_CSS_COLOR_INTERPOLATION_LINEARRGB), + // Solid color properties + solid_color( "solid-color" ), // SPIColor + solid_opacity( "solid-opacity", SP_SCALE24_MAX ), + // Fill properties fill( "fill" ), // SPIPaint fill_opacity( "fill-opacity", SP_SCALE24_MAX ), @@ -306,6 +310,9 @@ SPStyle::SPStyle(SPDocument *document_in, SPObject *object_in) : _properties.push_back( &color_interpolation ); _properties.push_back( &color_interpolation_filters ); + _properties.push_back( &solid_color ); + _properties.push_back( &solid_opacity ); + _properties.push_back( &fill ); _properties.push_back( &fill_opacity ); _properties.push_back( &fill_rule ); @@ -385,10 +392,14 @@ SPStyle::SPStyle(SPDocument *document_in, SPObject *object_in) : // _propmap.insert( std::make_pair( color_interpolation.name, reinterpret_cast(&SPStyle::color_interpolation ) ) ); // _propmap.insert( std::make_pair( color_interpolation_filters.name, reinterpret_cast(&SPStyle::color_interpolation_filters ) ) ); + // _propmap.insert( std::make_pair( solid_color.name, reinterpret_cast(&SPStyle::solid_color ) ) ); + // _propmap.insert( std::make_pair( solid_opacity.name, reinterpret_cast(&SPStyle::solid_opacity ) ) ); + // _propmap.insert( std::make_pair( fill.name, reinterpret_cast(&SPStyle::fill ) ) ); // _propmap.insert( std::make_pair( fill_opacity.name, reinterpret_cast(&SPStyle::fill_opacity ) ) ); // _propmap.insert( std::make_pair( fill_rule.name, reinterpret_cast(&SPStyle::fill_rule ) ) ); + // _propmap.insert( std::make_pair( stroke.name, reinterpret_cast(&SPStyle::stroke ) ) ); // _propmap.insert( std::make_pair( stroke_width.name, reinterpret_cast(&SPStyle::stroke_width ) ) ); // _propmap.insert( std::make_pair( stroke_linecap.name, reinterpret_cast(&SPStyle::stroke_linecap ) ) ); @@ -779,6 +790,12 @@ SPStyle::readIfUnset( gint id, gchar const *val ) { case SP_PROP_COLOR_RENDERING: color_rendering.readIfUnset( val ); break; + case SP_PROP_SOLID_COLOR: + solid_color.readIfUnset( val ); + break; + case SP_PROP_SOLID_OPACITY: + solid_opacity.readIfUnset( val ); + break; case SP_PROP_FILL: fill.readIfUnset( val ); break; @@ -1546,6 +1563,12 @@ sp_style_unset_property_attrs(SPObject *o) if (style->color_interpolation_filters.set) { repr->setAttribute("color-interpolation-filters", NULL); } + if (style->solid_color.set) { + repr->setAttribute("solid-color", NULL); + } + if (style->solid_opacity.set) { + repr->setAttribute("solid-opacity", NULL); + } if (style->fill.set) { repr->setAttribute("fill", NULL); } diff --git a/src/style.h b/src/style.h index 931dcc90e..eb8a3ed91 100644 --- a/src/style.h +++ b/src/style.h @@ -180,6 +180,11 @@ public: /** color-interpolation-filters */ SPIEnum color_interpolation_filters; + /** solid-color */ + SPIColor solid_color; + /** solid-opacity */ + SPIScale24 solid_opacity; + /** fill */ SPIPaint fill; /** fill-opacity */ -- cgit v1.2.3 From 97a4ef4fd8b0c841a90f3bb29dee13fd96edecb7 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Fri, 1 Aug 2014 11:04:51 +0200 Subject: Rename 'blend-mode' property to 'mix-blend-mode' per CSS spec. (bzr r13485) --- src/attributes.cpp | 2 +- src/attributes.h | 2 +- src/display/drawing-item.cpp | 14 +++++++------- src/display/drawing-item.h | 2 +- src/sp-item.cpp | 4 ++-- src/style.cpp | 10 +++++----- src/style.h | 3 +-- 7 files changed, 18 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/attributes.cpp b/src/attributes.cpp index da7b25f03..fec5d3af4 100644 --- a/src/attributes.cpp +++ b/src/attributes.cpp @@ -440,7 +440,7 @@ static SPStyleProp const props[] = { {SP_PROP_DISPLAY, "display"}, {SP_PROP_OVERFLOW, "overflow"}, {SP_PROP_VISIBILITY, "visibility"}, - {SP_PROP_BLEND_MODE, "mix-blend-mode"}, // CSS Blending and Compositing + {SP_PROP_MIX_BLEND_MODE, "mix-blend-mode"}, // CSS Blending and Compositing {SP_PROP_ISOLATION, "isolation"}, /* SVG */ /* Clip/Mask */ diff --git a/src/attributes.h b/src/attributes.h index 82e7ca8a6..3397e4034 100644 --- a/src/attributes.h +++ b/src/attributes.h @@ -441,7 +441,7 @@ enum SPAttributeEnum { SP_PROP_DISPLAY, SP_PROP_OVERFLOW, SP_PROP_VISIBILITY, - SP_PROP_BLEND_MODE, + SP_PROP_MIX_BLEND_MODE, SP_PROP_ISOLATION, /* SVG */ /* Clip/Mask */ diff --git a/src/display/drawing-item.cpp b/src/display/drawing-item.cpp index 0bfb00b62..80eb69546 100644 --- a/src/display/drawing-item.cpp +++ b/src/display/drawing-item.cpp @@ -127,7 +127,7 @@ DrawingItem::DrawingItem(Drawing &drawing) , _pick_children(0) , _antialias(1) , _isolation(SP_CSS_ISOLATION_AUTO) - , _blend_mode(SP_CSS_BLEND_NORMAL) + , _mix_blend_mode(SP_CSS_BLEND_NORMAL) {} DrawingItem::~DrawingItem() @@ -291,10 +291,10 @@ DrawingItem::setIsolation(unsigned isolation) } void -DrawingItem::setBlendMode(unsigned blend_mode) +DrawingItem::setBlendMode(unsigned mix_blend_mode) { - _blend_mode = blend_mode; - //if( blend_mode != 0 ) std::cout << "setBlendMode: " << blend_mode << std::endl; + _mix_blend_mode = mix_blend_mode; + //if( mix_blend_mode != 0 ) std::cout << "setBlendMode: " << mix_blend_mode << std::endl; _markForRendering(); } @@ -592,7 +592,7 @@ DrawingItem::render(DrawingContext &dc, Geom::IntRect const &area, unsigned flag if (_cached) { if (_cache) { _cache->prepare(); - set_cairo_blend_operator( dc, _blend_mode ); + set_cairo_blend_operator( dc, _mix_blend_mode ); _cache->paintFromCache(dc, carea); if (!carea) return RENDER_OK; @@ -622,7 +622,7 @@ DrawingItem::render(DrawingContext &dc, Geom::IntRect const &area, unsigned flag nir |= (_filter != NULL && render_filters); // 3. it has a filter nir |= needs_opacity; // 4. it is non-opaque nir |= (_cache != NULL); // 5. it is cached - nir |= (_blend_mode != SP_CSS_BLEND_NORMAL); // 6. Blend mode not normal + nir |= (_mix_blend_mode != SP_CSS_BLEND_NORMAL); // 6. Blend mode not normal nir |= (_isolation == SP_CSS_ISOLATION_ISOLATE); // 7. Explicit isolatiom /* How the rendering is done. @@ -735,7 +735,7 @@ DrawingItem::render(DrawingContext &dc, Geom::IntRect const &area, unsigned flag } dc.rectangle(*carea); dc.setSource(&intermediate); - set_cairo_blend_operator( dc, _blend_mode ); + set_cairo_blend_operator( dc, _mix_blend_mode ); dc.fill(); dc.setSource(0,0,0,0); // the call above is to clear a ref on the intermediate surface held by dc diff --git a/src/display/drawing-item.h b/src/display/drawing-item.h index d89299eeb..925bcbddb 100644 --- a/src/display/drawing-item.h +++ b/src/display/drawing-item.h @@ -209,7 +209,7 @@ protected: unsigned _antialias : 1; ///< Whether to use antialiasing unsigned _isolation : 1; - unsigned _blend_mode : 4; + unsigned _mix_blend_mode : 4; friend class Drawing; }; diff --git a/src/sp-item.cpp b/src/sp-item.cpp index a3f1a5d64..6c2ada9d7 100644 --- a/src/sp-item.cpp +++ b/src/sp-item.cpp @@ -602,7 +602,7 @@ void SPItem::update(SPCtx* /*ctx*/, guint flags) { 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->blend_mode.value ); + v->arenaitem->setBlendMode( object->style->mix_blend_mode.value ); v->arenaitem->setVisible(!item->isHidden()); } } @@ -1028,7 +1028,7 @@ Inkscape::DrawingItem *SPItem::invoke_show(Inkscape::Drawing &drawing, unsigned ai->setTransform(transform); ai->setOpacity(SP_SCALE24_TO_FLOAT(style->opacity.value)); ai->setIsolation( style->isolation.value ); - ai->setBlendMode( style->blend_mode.value ); + ai->setBlendMode( style->mix_blend_mode.value ); //ai->setCompositeOperator( style->composite_op.value ); ai->setVisible(!isHidden()); ai->setSensitive(sensitive); diff --git a/src/style.cpp b/src/style.cpp index f0710e404..abc928d76 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -144,7 +144,7 @@ SPStyle::SPStyle(SPDocument *document_in, SPObject *object_in) : opacity( "opacity", SP_SCALE24_MAX, false ), isolation( "isolation", enum_isolation, SP_CSS_ISOLATION_AUTO ), - blend_mode( "blend_mode", enum_blend_mode, SP_CSS_BLEND_NORMAL ), + mix_blend_mode( "mix-blend-mode", enum_blend_mode, SP_CSS_BLEND_NORMAL ), paint_order(), // SPIPaintOrder @@ -305,7 +305,7 @@ SPStyle::SPStyle(SPDocument *document_in, SPObject *object_in) : _properties.push_back( &opacity ); _properties.push_back( &isolation ); - _properties.push_back( &blend_mode ); + _properties.push_back( &mix_blend_mode ); _properties.push_back( &color_interpolation ); _properties.push_back( &color_interpolation_filters ); @@ -387,7 +387,7 @@ SPStyle::SPStyle(SPDocument *document_in, SPObject *object_in) : // _propmap.insert( std::make_pair( opacity.name, reinterpret_cast(&SPStyle::opacity ) ) ); // _propmap.insert( std::make_pair( isolation.name, reinterpret_cast(&SPStyle::isolation ) ) ); - // _propmap.insert( std::make_pair( blend_mode.name, reinterpret_cast(&SPStyle::blend_mode ) ) ); + // _propmap.insert( std::make_pair( mix_blend_mode.name, reinterpret_cast(&SPStyle::mix_blend_mode ) ) ); // _propmap.insert( std::make_pair( color_interpolation.name, reinterpret_cast(&SPStyle::color_interpolation ) ) ); // _propmap.insert( std::make_pair( color_interpolation_filters.name, reinterpret_cast(&SPStyle::color_interpolation_filters ) ) ); @@ -713,8 +713,8 @@ SPStyle::readIfUnset( gint id, gchar const *val ) { case SP_PROP_ISOLATION: isolation.readIfUnset( val ); break; - case SP_PROP_BLEND_MODE: - blend_mode.readIfUnset( val ); + case SP_PROP_MIX_BLEND_MODE: + mix_blend_mode.readIfUnset( val ); break; /* SVG */ diff --git a/src/style.h b/src/style.h index eb8a3ed91..3627b4ec2 100644 --- a/src/style.h +++ b/src/style.h @@ -168,8 +168,7 @@ public: /** mix-blend-mode: CSS Compositing and Blending Level 1 */ SPIEnum isolation; - // Could be shared with Filter blending mode - SPIEnum blend_mode; + SPIEnum mix_blend_mode; SPIPaintOrder paint_order; -- cgit v1.2.3 From d95b9fa8bd9aeacf16ab7075305edd19300bfe76 Mon Sep 17 00:00:00 2001 From: "Liam P. White" Date: Fri, 1 Aug 2014 10:20:42 -0400 Subject: Fix for #1348385 (filtered shape losing filter on conversion) Fixed bugs: - https://launchpad.net/bugs/1348385 (bzr r13486) --- src/style-internal.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/style-internal.cpp b/src/style-internal.cpp index ae70fc10d..2212f8fff 100644 --- a/src/style-internal.cpp +++ b/src/style-internal.cpp @@ -1395,7 +1395,8 @@ const Glib::ustring SPIFilter::write( guint const flags, SPIBase const *const /* // TODO: fix base //SPILength const *const my_base = dynamic_cast(base); if ( (flags & SP_STYLE_FLAG_ALWAYS) || - ((flags & SP_STYLE_FLAG_IFSET) && this->set)) + ((flags & SP_STYLE_FLAG_IFSET) && this->set) || + ((flags & SP_STYLE_FLAG_IFDIFF) && this->set)) { if (this->inherit) { return (name + ":inherit;"); -- cgit v1.2.3 From a0acffb60236ee6d8c6f8ccc2f29d36b5aa02dda Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 1 Aug 2014 10:28:31 -0400 Subject: Fix for #906794, #1246550 (live effects not showing helper paths) Fixed bugs: - https://launchpad.net/bugs/1246550 - https://launchpad.net/bugs/906794 (bzr r13487) --- src/ui/tools/node-tool.cpp | 46 +++++++++++++++++++++++++++++++++++++++++++++- src/ui/tools/node-tool.h | 2 ++ 2 files changed, 47 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ui/tools/node-tool.cpp b/src/ui/tools/node-tool.cpp index b1e11bd66..0778e3f3f 100644 --- a/src/ui/tools/node-tool.cpp +++ b/src/ui/tools/node-tool.cpp @@ -19,6 +19,7 @@ #include "display/curve.h" #include "display/sp-canvas.h" #include "document.h" +#include "live_effects/effect.h" #include "live_effects/lpeobject.h" #include "message-context.h" #include "selection.h" @@ -166,6 +167,9 @@ NodeTool::~NodeTool() { if (this->flash_tempitem) { this->desktop->remove_temporary_canvasitem(this->flash_tempitem); } + if (this->helperpath_tmpitem) { + this->desktop->remove_temporary_canvasitem(this->helperpath_tmpitem); + } this->_selection_changed_connection.disconnect(); //this->_selection_modified_connection.disconnect(); @@ -246,6 +250,7 @@ void NodeTool::setup() { ))) ); + this->helperpath_tmpitem = NULL; this->cursor_drag = false; this->show_transform_handles = true; this->single_node_transform_handles = false; @@ -278,6 +283,44 @@ void NodeTool::setup() { } this->desktop->emitToolSubselectionChanged(NULL); // sets the coord entry fields to inactive + this->update_helperpath(); +} + +// show helper paths of the applied LPE, if any +void NodeTool::update_helperpath () { + Inkscape::Selection *selection = sp_desktop_selection (this->desktop); + + if (this->helperpath_tmpitem) { + this->desktop->remove_temporary_canvasitem(this->helperpath_tmpitem); + this->helperpath_tmpitem = NULL; + } + + if (SP_IS_LPE_ITEM(selection->singleItem())) { + Inkscape::LivePathEffect::Effect *lpe = SP_LPE_ITEM(selection->singleItem())->getCurrentLPE(); + if (lpe && lpe->isVisible()/* && lpe->showOrigPath()*/) { + if (lpe) { + SPCurve *c = new SPCurve(); + SPCurve *cc = new SPCurve(); + std::vector cs = lpe->getCanvasIndicators(SP_LPE_ITEM(selection->singleItem())); + for (std::vector::iterator p = cs.begin(); p != cs.end(); ++p) { + cc->set_pathvector(*p); + c->append(cc, false); + cc->reset(); + } + if (!c->is_empty()) { + c->transform(selection->singleItem()->i2dt_affine()); + SPCanvasItem *helperpath = sp_canvas_bpath_new(sp_desktop_tempgroup(this->desktop), c); + sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(helperpath), + 0x0000ff9A, 1.0, + SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); + sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(helperpath), 0, SP_WIND_RULE_NONZERO); + this->helperpath_tmpitem = this->desktop->add_temporary_canvasitem(helperpath,0); + } + c->unref(); + cc->unref(); + } + } + } } void NodeTool::set(const Inkscape::Preferences::Entry& value) { @@ -392,7 +435,7 @@ void NodeTool::selection_changed(Inkscape::Selection *sel) { for (std::set::iterator i = shapes.begin(); i != shapes.end(); ++i) { ShapeRecord const &r = *i; - if ((SP_IS_SHAPE(r.item) || SP_IS_TEXT(r.item)) && + if ((SP_IS_SHAPE(r.item) || SP_IS_TEXT(r.item) || SP_IS_GROUP(r.item) || SP_IS_OBJECTGROUP(r.item)) && this->_shape_editors.find(r.item) == this->_shape_editors.end()) { ShapeEditor *si = new ShapeEditor(this->desktop); @@ -432,6 +475,7 @@ bool NodeTool::root_handler(GdkEvent* event) { switch (event->type) { case GDK_MOTION_NOTIFY: { + this->update_helperpath(); combine_motion_events(desktop->canvas, event->motion, 0); SPItem *over_item = sp_event_context_find_item (desktop, event_point(event->button), FALSE, TRUE); diff --git a/src/ui/tools/node-tool.h b/src/ui/tools/node-tool.h index 4d15ab70e..459ecd0a7 100644 --- a/src/ui/tools/node-tool.h +++ b/src/ui/tools/node-tool.h @@ -51,6 +51,7 @@ public: static const std::string prefsPath; virtual void setup(); + virtual void update_helperpath(); virtual void set(const Inkscape::Preferences::Entry& val); virtual bool root_handler(GdkEvent* event); @@ -62,6 +63,7 @@ private: sigc::connection _sizeUpdatedConn; SPItem *flashed_item; + Inkscape::Display::TemporaryItem *helperpath_tmpitem; Inkscape::Display::TemporaryItem *flash_tempitem; Inkscape::UI::Selector* _selector; Inkscape::UI::PathSharedData* _path_data; -- cgit v1.2.3 From acd8f135f2a901c5f046e51ad7783e442c43997a Mon Sep 17 00:00:00 2001 From: "Liam P. White" Date: Mon, 4 Aug 2014 12:10:37 -0400 Subject: Allow editing of fill and stroke patterns simultaneously. Fixes #601336, #604025, #486192 Fixed bugs: - https://launchpad.net/bugs/601336 - https://launchpad.net/bugs/604025 - https://launchpad.net/bugs/486192 (bzr r13489) --- src/knot-holder-entity.cpp | 18 +++++++++--------- src/knot-holder-entity.h | 10 ++++++++++ src/knotholder.cpp | 32 ++++++++++++++++++++++++++------ src/object-edit.cpp | 4 ++-- src/sp-item.cpp | 8 +++++--- src/sp-item.h | 9 ++++++++- 6 files changed, 60 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/knot-holder-entity.cpp b/src/knot-holder-entity.cpp index 6af5c6a56..b66156b09 100644 --- a/src/knot-holder-entity.cpp +++ b/src/knot-holder-entity.cpp @@ -158,7 +158,7 @@ static Geom::Point sp_pattern_extract_trans(SPPattern const *pat) void PatternKnotHolderEntityXY::knot_set(Geom::Point const &p, Geom::Point const &origin, guint state) { - SPPattern *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style)); + SPPattern *pat = _fill ? SP_PATTERN(item->style->getFillPaintServer()) : SP_PATTERN(item->style->getStrokePaintServer()); // FIXME: this snapping should be done together with knowing whether control was pressed. If GDK_CONTROL_MASK, then constrained snapping should be used. Geom::Point p_snapped = snap_knot_position(p, state); @@ -173,7 +173,7 @@ PatternKnotHolderEntityXY::knot_set(Geom::Point const &p, Geom::Point const &ori if (state) { Geom::Point const q = p_snapped - sp_pattern_extract_trans(pat); - item->adjust_pattern(Geom::Affine(Geom::Translate(q))); + item->adjust_pattern(Geom::Translate(q), false, _fill ? TRANSFORM_FILL : TRANSFORM_STROKE); } item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); @@ -182,14 +182,14 @@ PatternKnotHolderEntityXY::knot_set(Geom::Point const &p, Geom::Point const &ori Geom::Point PatternKnotHolderEntityXY::knot_get() const { - SPPattern const *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style)); + SPPattern *pat = _fill ? SP_PATTERN(item->style->getFillPaintServer()) : SP_PATTERN(item->style->getStrokePaintServer()); return sp_pattern_extract_trans(pat); } Geom::Point PatternKnotHolderEntityAngle::knot_get() const { - SPPattern const *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style)); + SPPattern *pat = _fill ? SP_PATTERN(item->style->getFillPaintServer()) : SP_PATTERN(item->style->getStrokePaintServer()); gdouble x = pattern_width(pat); gdouble y = 0; @@ -207,7 +207,7 @@ PatternKnotHolderEntityAngle::knot_set(Geom::Point const &p, Geom::Point const & Inkscape::Preferences *prefs = Inkscape::Preferences::get(); int const snaps = prefs->getInt("/options/rotationsnapsperpi/value", 12); - SPPattern *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style)); + SPPattern *pat = _fill ? SP_PATTERN(item->style->getFillPaintServer()) : SP_PATTERN(item->style->getStrokePaintServer()); // get the angle from pattern 0,0 to the cursor pos Geom::Point delta = p - sp_pattern_extract_trans(pat); @@ -223,14 +223,14 @@ PatternKnotHolderEntityAngle::knot_set(Geom::Point const &p, Geom::Point const & Geom::Point const t = sp_pattern_extract_trans(pat); rot[4] = t[Geom::X]; rot[5] = t[Geom::Y]; - item->adjust_pattern(rot, true); + item->adjust_pattern(rot, true, _fill ? TRANSFORM_FILL : TRANSFORM_STROKE); item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } void PatternKnotHolderEntityScale::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state) { - SPPattern *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style)); + SPPattern *pat = _fill ? SP_PATTERN(item->style->getFillPaintServer()) : SP_PATTERN(item->style->getStrokePaintServer()); // FIXME: this snapping should be done together with knowing whether control was pressed. If GDK_CONTROL_MASK, then constrained snapping should be used. Geom::Point p_snapped = snap_knot_position(p, state); @@ -257,7 +257,7 @@ PatternKnotHolderEntityScale::knot_set(Geom::Point const &p, Geom::Point const & Geom::Point const t = sp_pattern_extract_trans(pat); rot[4] = t[Geom::X]; rot[5] = t[Geom::Y]; - item->adjust_pattern(rot, true); + item->adjust_pattern(rot, true, _fill ? TRANSFORM_FILL : TRANSFORM_STROKE); item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } @@ -265,7 +265,7 @@ PatternKnotHolderEntityScale::knot_set(Geom::Point const &p, Geom::Point const & Geom::Point PatternKnotHolderEntityScale::knot_get() const { - SPPattern const *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style)); + SPPattern *pat = _fill ? SP_PATTERN(item->style->getFillPaintServer()) : SP_PATTERN(item->style->getStrokePaintServer()); gdouble x = pattern_width(pat); gdouble y = pattern_height(pat); diff --git a/src/knot-holder-entity.h b/src/knot-holder-entity.h index a9268d396..dde60f515 100644 --- a/src/knot-holder-entity.h +++ b/src/knot-holder-entity.h @@ -101,20 +101,30 @@ protected: class PatternKnotHolderEntityXY : public KnotHolderEntity { public: + PatternKnotHolderEntityXY(bool fill) : KnotHolderEntity(), _fill(fill) {} virtual Geom::Point knot_get() const; virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); +private: + // true if the entity tracks fill, false for stroke + bool _fill; }; class PatternKnotHolderEntityAngle : public KnotHolderEntity { public: + PatternKnotHolderEntityAngle(bool fill) : KnotHolderEntity(), _fill(fill) {} virtual Geom::Point knot_get() const; virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); +private: + bool _fill; }; class PatternKnotHolderEntityScale : public KnotHolderEntity { public: + PatternKnotHolderEntityScale(bool fill) : KnotHolderEntity(), _fill(fill) {} virtual Geom::Point knot_get() const; virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); +private: + bool _fill; }; #endif /* !SEEN_KNOT_HOLDER_ENTITY_H */ diff --git a/src/knotholder.cpp b/src/knotholder.cpp index cf87423d4..f0e69716b 100644 --- a/src/knotholder.cpp +++ b/src/knotholder.cpp @@ -247,12 +247,32 @@ void KnotHolder::add(KnotHolderEntity *e) void KnotHolder::add_pattern_knotholder() { - if ((item->style->fill.isPaintserver()) - && SP_IS_PATTERN(item->style->getFillPaintServer())) - { - PatternKnotHolderEntityXY *entity_xy = new PatternKnotHolderEntityXY(); - PatternKnotHolderEntityAngle *entity_angle = new PatternKnotHolderEntityAngle(); - PatternKnotHolderEntityScale *entity_scale = new PatternKnotHolderEntityScale(); + if ((item->style->fill.isPaintserver()) && SP_IS_PATTERN(item->style->getFillPaintServer())) { + PatternKnotHolderEntityXY *entity_xy = new PatternKnotHolderEntityXY(true); + PatternKnotHolderEntityAngle *entity_angle = new PatternKnotHolderEntityAngle(true); + PatternKnotHolderEntityScale *entity_scale = new PatternKnotHolderEntityScale(true); + entity_xy->create(desktop, item, this, Inkscape::CTRL_TYPE_POINT, + // TRANSLATORS: This refers to the pattern that's inside the object + _("Move the pattern fill inside the object"), + SP_KNOT_SHAPE_CROSS); + + entity_scale->create(desktop, item, this, Inkscape::CTRL_TYPE_SIZER, + _("Scale the pattern fill; uniformly if with Ctrl"), + SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR); + + entity_angle->create(desktop, item, this, Inkscape::CTRL_TYPE_ROTATE, + _("Rotate the pattern fill; with Ctrl to snap angle"), + SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR); + + entity.push_back(entity_xy); + entity.push_back(entity_angle); + entity.push_back(entity_scale); + } + + if ((item->style->stroke.isPaintserver()) && SP_IS_PATTERN(item->style->getStrokePaintServer())) { + PatternKnotHolderEntityXY *entity_xy = new PatternKnotHolderEntityXY(false); + PatternKnotHolderEntityAngle *entity_angle = new PatternKnotHolderEntityAngle(false); + PatternKnotHolderEntityScale *entity_scale = new PatternKnotHolderEntityScale(false); entity_xy->create(desktop, item, this, Inkscape::CTRL_TYPE_POINT, // TRANSLATORS: This refers to the pattern that's inside the object _("Move the pattern fill inside the object"), diff --git a/src/object-edit.cpp b/src/object-edit.cpp index e9b183eca..fe22f6c1c 100644 --- a/src/object-edit.cpp +++ b/src/object-edit.cpp @@ -79,8 +79,8 @@ KnotHolder *createKnotHolder(SPItem *item, SPDesktop *desktop) knotholder = new OffsetKnotHolder(desktop, item, NULL); } else if (SP_IS_FLOWTEXT(item) && SP_FLOWTEXT(item)->has_internal_frame()) { knotholder = new FlowtextKnotHolder(desktop, SP_FLOWTEXT(item)->get_frame(NULL), NULL); - } else if ((item->style->fill.isPaintserver()) - && SP_IS_PATTERN(item->style->getFillPaintServer())) { + } else if ((item->style->fill.isPaintserver() && SP_IS_PATTERN(item->style->getFillPaintServer())) || + (item->style->stroke.isPaintserver() && SP_IS_PATTERN(item->style->getStrokePaintServer()))) { knotholder = new KnotHolder(desktop, item, NULL); knotholder->add_pattern_knotholder(); } diff --git a/src/sp-item.cpp b/src/sp-item.cpp index 6c2ada9d7..780845deb 100644 --- a/src/sp-item.cpp +++ b/src/sp-item.cpp @@ -1109,9 +1109,10 @@ void SPItem::invoke_hide(unsigned key) // Adjusters -void SPItem::adjust_pattern (Geom::Affine const &postmul, bool set) +void SPItem::adjust_pattern(Geom::Affine const &postmul, bool set, PatternTransform pt) { - if (style && (style->fill.isPaintserver())) { + bool fill = (pt == TRANSFORM_FILL || pt == TRANSFORM_BOTH); + if (fill && style && (style->fill.isPaintserver())) { SPObject *server = style->getFillPaintServer(); if ( SP_IS_PATTERN(server) ) { SPPattern *pattern = sp_pattern_clone_if_necessary(this, SP_PATTERN(server), "fill"); @@ -1119,7 +1120,8 @@ void SPItem::adjust_pattern (Geom::Affine const &postmul, bool set) } } - if (style && (style->stroke.isPaintserver())) { + bool stroke = (pt == TRANSFORM_STROKE || pt == TRANSFORM_BOTH); + if (stroke && style && (style->stroke.isPaintserver())) { SPObject *server = style->getStrokePaintServer(); if ( SP_IS_PATTERN(server) ) { SPPattern *pattern = sp_pattern_clone_if_necessary(this, SP_PATTERN(server), "stroke"); diff --git a/src/sp-item.h b/src/sp-item.h index ce93b1d40..2880f4a8e 100644 --- a/src/sp-item.h +++ b/src/sp-item.h @@ -51,6 +51,13 @@ enum { SP_EVENT_MOUSEOUT }; +// TODO fix this +enum PatternTransform { + TRANSFORM_BOTH, + TRANSFORM_FILL, + TRANSFORM_STROKE +}; + /** * Event structure. * @@ -199,7 +206,7 @@ public: Inkscape::DrawingItem *invoke_show(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags); void invoke_hide(unsigned int key); void getSnappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs=0) const; - void adjust_pattern(/* Geom::Affine const &premul, */ Geom::Affine const &postmul, bool set = false); + void adjust_pattern(/* Geom::Affine const &premul, */ Geom::Affine const &postmul, bool set = false, PatternTransform = TRANSFORM_BOTH); void adjust_gradient(/* Geom::Affine const &premul, */ Geom::Affine const &postmul, bool set = false); void adjust_stroke(gdouble ex); void adjust_stroke_width_recursive(gdouble ex); -- cgit v1.2.3