From 3b4e451ace16cc3a4c62d2dfdc50587d4a8acf8c Mon Sep 17 00:00:00 2001 From: Tomasz Boczkowski Date: Mon, 26 May 2014 21:02:55 +0200 Subject: SPPattern c++-sification: replaced guint by bool and enum (bzr r13341.6.16) --- src/extension/internal/cairo-render-context.cpp | 4 +-- src/sp-pattern.cpp | 40 ++++++++++++------------- src/sp-pattern.h | 24 +++++++-------- 3 files changed, 34 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/extension/internal/cairo-render-context.cpp b/src/extension/internal/cairo-render-context.cpp index c09b8e9c8..2ace19ae5 100644 --- a/src/extension/internal/cairo-render-context.cpp +++ b/src/extension/internal/cairo-render-context.cpp @@ -1015,7 +1015,7 @@ CairoRenderContext::_createPatternPainter(SPPaintServer const *const paintserver TRACE(("%f x %f pattern\n", width, height)); - if (pbox && pattern_patternUnits(pat) == SP_PATTERN_UNITS_OBJECTBOUNDINGBOX) { + if (pbox && pattern_patternUnits(pat) == SPPattern::UNITS_OBJECTBOUNDINGBOX) { //Geom::Affine bbox2user (pbox->x1 - pbox->x0, 0.0, 0.0, pbox->y1 - pbox->y0, pbox->x0, pbox->y0); bbox_width_scaler = pbox->width(); bbox_height_scaler = pbox->height(); @@ -1048,7 +1048,7 @@ CairoRenderContext::_createPatternPainter(SPPaintServer const *const paintserver pcs2dev[3] = h / view_box.height(); pcs2dev[4] = x - view_box.left() * pcs2dev[0]; pcs2dev[5] = y - view_box.top() * pcs2dev[3]; - } else if (pbox && pattern_patternContentUnits(pat) == SP_PATTERN_UNITS_OBJECTBOUNDINGBOX) { + } else if (pbox && pattern_patternContentUnits(pat) == SPPattern::UNITS_OBJECTBOUNDINGBOX) { pcs2dev[0] = pbox->width(); pcs2dev[3] = pbox->height(); } diff --git a/src/sp-pattern.cpp b/src/sp-pattern.cpp index 9b7330a24..c5461d302 100644 --- a/src/sp-pattern.cpp +++ b/src/sp-pattern.cpp @@ -59,14 +59,14 @@ SPPattern::SPPattern() : SPPaintServer(), SPViewBox() { this->ref = new SPPatternReference(this); this->ref->changedSignal().connect(sigc::bind(sigc::ptr_fun(pattern_ref_changed), this)); - this->patternUnits = SP_PATTERN_UNITS_OBJECTBOUNDINGBOX; - this->patternUnits_set = FALSE; + this->patternUnits = UNITS_OBJECTBOUNDINGBOX; + this->patternUnits_set = false; - this->patternContentUnits = SP_PATTERN_UNITS_USERSPACEONUSE; - this->patternContentUnits_set = FALSE; + this->patternContentUnits = UNITS_USERSPACEONUSE; + this->patternContentUnits_set = false; this->patternTransform = Geom::identity(); - this->patternTransform_set = FALSE; + this->patternTransform_set = false; this->x.unset(); this->y.unset(); @@ -116,14 +116,14 @@ void SPPattern::set(unsigned int key, const gchar* value) { case SP_ATTR_PATTERNUNITS: if (value) { if (!strcmp (value, "userSpaceOnUse")) { - this->patternUnits = SP_PATTERN_UNITS_USERSPACEONUSE; + this->patternUnits = UNITS_USERSPACEONUSE; } else { - this->patternUnits = SP_PATTERN_UNITS_OBJECTBOUNDINGBOX; + this->patternUnits = UNITS_OBJECTBOUNDINGBOX; } - this->patternUnits_set = TRUE; + this->patternUnits_set = true; } else { - this->patternUnits_set = FALSE; + this->patternUnits_set = false; } this->requestModified(SP_OBJECT_MODIFIED_FLAG); @@ -132,14 +132,14 @@ void SPPattern::set(unsigned int key, const gchar* value) { case SP_ATTR_PATTERNCONTENTUNITS: if (value) { if (!strcmp (value, "userSpaceOnUse")) { - this->patternContentUnits = SP_PATTERN_UNITS_USERSPACEONUSE; + this->patternContentUnits = UNITS_USERSPACEONUSE; } else { - this->patternContentUnits = SP_PATTERN_UNITS_OBJECTBOUNDINGBOX; + this->patternContentUnits = UNITS_OBJECTBOUNDINGBOX; } - this->patternContentUnits_set = TRUE; + this->patternContentUnits_set = true; } else { - this->patternContentUnits_set = FALSE; + this->patternContentUnits_set = false; } this->requestModified(SP_OBJECT_MODIFIED_FLAG); @@ -150,10 +150,10 @@ void SPPattern::set(unsigned int key, const gchar* value) { if (value && sp_svg_transform_read (value, &t)) { this->patternTransform = t; - this->patternTransform_set = TRUE; + this->patternTransform_set = true; } else { this->patternTransform = Geom::identity(); - this->patternTransform_set = FALSE; + this->patternTransform_set = false; } this->requestModified(SP_OBJECT_MODIFIED_FLAG); @@ -399,7 +399,7 @@ sp_pattern_transform_multiply (SPPattern *pattern, Geom::Affine postmul, bool se } else { pattern->patternTransform = pattern_patternTransform(pattern) * postmul; } - pattern->patternTransform_set = TRUE; + pattern->patternTransform_set = true; gchar *c=sp_svg_transform_write(pattern->patternTransform); pattern->getRepr()->setAttribute("patternTransform", c); @@ -455,7 +455,7 @@ SPPattern *pattern_getroot(SPPattern *pat) // Access functions that look up fields up the chain of referenced patterns and return the first one which is set // FIXME: all of them must use chase_hrefs the same as in SPGradient, to avoid lockup on circular refs -guint pattern_patternUnits (SPPattern const *pat) +SPPattern::PatternUnits pattern_patternUnits (SPPattern const *pat) { for (SPPattern const *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { if (pat_i->patternUnits_set) @@ -464,7 +464,7 @@ guint pattern_patternUnits (SPPattern const *pat) return pat->patternUnits; } -guint pattern_patternContentUnits (SPPattern const *pat) +SPPattern::PatternUnits pattern_patternContentUnits (SPPattern const *pat) { for (SPPattern const *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { if (pat_i->patternContentUnits_set) @@ -603,7 +603,7 @@ cairo_pattern_t* SPPattern::pattern_new(cairo_t *base_ct, Geom::OptRect const &b double tile_y = pattern_y(this); double tile_width = pattern_width(this); double tile_height = pattern_height(this); - if ( bbox && (pattern_patternUnits(this) == SP_PATTERN_UNITS_OBJECTBOUNDINGBOX) ) { + if ( bbox && (pattern_patternUnits(this) == UNITS_OBJECTBOUNDINGBOX) ) { tile_x *= bbox->width(); tile_y *= bbox->height(); tile_width *= bbox->width(); @@ -625,7 +625,7 @@ cairo_pattern_t* SPPattern::pattern_new(cairo_t *base_ct, Geom::OptRect const &b } else { // Content to bbox - if (bbox && (pattern_patternContentUnits(this) == SP_PATTERN_UNITS_OBJECTBOUNDINGBOX) ) { + if (bbox && (pattern_patternContentUnits(this) == UNITS_OBJECTBOUNDINGBOX) ) { content2ps = Geom::Affine(bbox->width(), 0.0, 0.0, bbox->height(), 0,0); } } diff --git a/src/sp-pattern.h b/src/sp-pattern.h index eb34b6714..d836e7a42 100644 --- a/src/sp-pattern.h +++ b/src/sp-pattern.h @@ -33,6 +33,11 @@ class SPPatternReference; class SPPattern : public SPPaintServer, public SPViewBox { public: + enum PatternUnits { + UNITS_USERSPACEONUSE, + UNITS_OBJECTBOUNDINGBOX + }; + SPPattern(); virtual ~SPPattern(); @@ -41,13 +46,13 @@ public: SPPatternReference *ref; /* patternUnits and patternContentUnits attribute */ - guint patternUnits : 1; - guint patternUnits_set : 1; - guint patternContentUnits : 1; - guint patternContentUnits_set : 1; + PatternUnits patternUnits : 1; + bool patternUnits_set : 1; + PatternUnits patternContentUnits : 1; + bool patternContentUnits_set : 1; /* patternTransform attribute */ Geom::Affine patternTransform; - guint patternTransform_set : 1; + bool patternTransform_set : 1; /* Tile rectangle */ SVGLength x; SVGLength y; @@ -82,11 +87,6 @@ protected: } }; -enum { - SP_PATTERN_UNITS_USERSPACEONUSE, - SP_PATTERN_UNITS_OBJECTBOUNDINGBOX -}; - guint pattern_users (SPPattern *pattern); SPPattern *pattern_chain (SPPattern *pattern); SPPattern *sp_pattern_clone_if_necessary (SPItem *item, SPPattern *pattern, const gchar *property); @@ -96,8 +96,8 @@ const gchar *pattern_tile (GSList *reprs, Geom::Rect bounds, SPDocument *documen SPPattern *pattern_getroot (SPPattern *pat); -guint pattern_patternUnits (SPPattern const *pat); -guint pattern_patternContentUnits (SPPattern const *pat); +SPPattern::PatternUnits pattern_patternUnits (SPPattern const *pat); +SPPattern::PatternUnits pattern_patternContentUnits (SPPattern const *pat); Geom::Affine const &pattern_patternTransform(SPPattern const *pat); gdouble pattern_x (SPPattern const *pat); gdouble pattern_y (SPPattern const *pat); -- cgit v1.2.3 From 258b23eac6fadcd3c02053ac6e890b0be5819194 Mon Sep 17 00:00:00 2001 From: Tomasz Boczkowski Date: Mon, 26 May 2014 22:52:46 +0200 Subject: SPPattern c++-sification: replaced gchar* by Glib::ustring (bzr r13341.6.17) --- src/sp-pattern.cpp | 25 ++++++++++--------------- src/sp-pattern.h | 2 +- 2 files changed, 11 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/sp-pattern.cpp b/src/sp-pattern.cpp index c5461d302..59fbca435 100644 --- a/src/sp-pattern.cpp +++ b/src/sp-pattern.cpp @@ -54,8 +54,6 @@ namespace { } SPPattern::SPPattern() : SPPaintServer(), SPViewBox() { - this->href = NULL; - this->ref = new SPPatternReference(this); this->ref->changedSignal().connect(sigc::bind(sigc::ptr_fun(pattern_ref_changed), this)); @@ -190,15 +188,14 @@ void SPPattern::set(unsigned int key, const gchar* value) { break; case SP_ATTR_XLINK_HREF: - if ( value && this->href && ( strcmp(value, this->href) == 0 ) ) { + if ( value && this->href == value ) { /* Href unchanged, do nothing. */ } else { - g_free(this->href); - this->href = NULL; + this->href.clear(); if (value) { // First, set the href field; it's only used in the "unchanged" check above. - this->href = g_strdup(value); + this->href = value; // Now do the attaching, which emits the changed signal. if (value) { try { @@ -360,9 +357,8 @@ SPPattern *pattern_chain(SPPattern *pattern) Inkscape::XML::Node *repr = xml_doc->createElement("svg:pattern"); repr->setAttribute("inkscape:collect", "always"); - gchar *parent_ref = g_strconcat("#", pattern->getRepr()->attribute("id"), NULL); + Glib::ustring parent_ref = Glib::ustring::compose("#%1", pattern->getRepr()->attribute("id")); repr->setAttribute("xlink:href", parent_ref); - g_free (parent_ref); defsrepr->addChild(repr, NULL); const gchar *child_id = repr->attribute("id"); @@ -375,13 +371,14 @@ SPPattern *pattern_chain(SPPattern *pattern) SPPattern * sp_pattern_clone_if_necessary (SPItem *item, SPPattern *pattern, const gchar *property) { - if (!pattern->href || pattern->hrefcount > count_pattern_hrefs(item, pattern)) { + if (pattern->href.empty() || pattern->hrefcount > count_pattern_hrefs(item, pattern)) { pattern = pattern_chain (pattern); - gchar *href = g_strconcat("url(#", pattern->getRepr()->attribute("id"), ")", NULL); + Glib::ustring href = Glib::ustring::compose("url(#%1)", pattern->getRepr()->attribute("id")); SPCSSAttr *css = sp_repr_css_attr_new (); - sp_repr_css_set_property (css, property, href); + sp_repr_css_set_property (css, property, href.c_str()); sp_repr_css_change_recursive(item->getRepr(), css, "style"); + } return pattern; } @@ -401,9 +398,8 @@ sp_pattern_transform_multiply (SPPattern *pattern, Geom::Affine postmul, bool se } pattern->patternTransform_set = true; - gchar *c=sp_svg_transform_write(pattern->patternTransform); + Glib::ustring c=sp_svg_transform_write(pattern->patternTransform); pattern->getRepr()->setAttribute("patternTransform", c); - g_free(c); } const gchar *pattern_tile(GSList *reprs, Geom::Rect bounds, SPDocument *document, Geom::Affine transform, Geom::Affine move) @@ -416,9 +412,8 @@ const gchar *pattern_tile(GSList *reprs, Geom::Rect bounds, SPDocument *document sp_repr_set_svg_double(repr, "width", bounds.dimensions()[Geom::X]); sp_repr_set_svg_double(repr, "height", bounds.dimensions()[Geom::Y]); - gchar *t=sp_svg_transform_write(transform); + Glib::ustring t=sp_svg_transform_write(transform); repr->setAttribute("patternTransform", t); - g_free(t); defsrepr->appendChild(repr); const gchar *pat_id = repr->attribute("id"); diff --git a/src/sp-pattern.h b/src/sp-pattern.h index d836e7a42..422adb169 100644 --- a/src/sp-pattern.h +++ b/src/sp-pattern.h @@ -42,7 +42,7 @@ public: virtual ~SPPattern(); /* Reference (href) */ - gchar *href; + Glib::ustring href; SPPatternReference *ref; /* patternUnits and patternContentUnits attribute */ -- cgit v1.2.3 From 6508c429a4a678541bc51df10a8335bbb45f0128 Mon Sep 17 00:00:00 2001 From: Tomasz Boczkowski Date: Tue, 27 May 2014 19:13:09 +0200 Subject: SPPattern c++-sification: replaced GSList by std::list (bzr r13341.6.18) --- src/selection-chemistry.cpp | 6 ++---- src/sp-pattern.cpp | 41 +++++++++++++++++++++-------------------- src/sp-pattern.h | 21 ++++++++++++++------- 3 files changed, 37 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 868a9d743..19eba8ddd 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -3242,13 +3242,11 @@ sp_selection_tile(SPDesktop *desktop, bool apply) gint pos = SP_OBJECT(items->data)->getRepr()->position(); // create a list of duplicates - GSList *repr_copies = NULL; + std::list repr_copies; for (GSList *i = items; i != NULL; i = i->next) { Inkscape::XML::Node *dup = SP_OBJECT(i->data)->getRepr()->duplicate(xml_doc); - repr_copies = g_slist_prepend(repr_copies, dup); + repr_copies.push_back(dup); } - // restore the z-order after prepends - repr_copies = g_slist_reverse(repr_copies); Geom::Rect bbox(desktop->dt2doc(r->min()), desktop->dt2doc(r->max())); diff --git a/src/sp-pattern.cpp b/src/sp-pattern.cpp index 59fbca435..a3de09368 100644 --- a/src/sp-pattern.cpp +++ b/src/sp-pattern.cpp @@ -222,37 +222,34 @@ void SPPattern::set(unsigned int key, const gchar* value) { /* fixme: We need ::order_changed handler too (Lauris) */ -static GSList *pattern_getchildren(SPPattern *pat) +void pattern_getchildren(SPPattern *pat, std::list& l) { - GSList *l = NULL; - for (SPPattern *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { if (pat_i->firstChild()) { // find the first one with children for (SPObject *child = pat->firstChild() ; child ; child = child->getNext() ) { - l = g_slist_prepend (l, child); + l.push_back(child); } break; // do not go further up the chain if children are found } } - - return l; } void SPPattern::update(SPCtx* ctx, unsigned int flags) { - if (flags & SP_OBJECT_MODIFIED_FLAG) { + typedef std::list::iterator SPObjectIterator; + + if (flags & SP_OBJECT_MODIFIED_FLAG) { flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; } flags &= SP_OBJECT_MODIFIED_CASCADE; - GSList *l = pattern_getchildren (this); - l = g_slist_reverse (l); + std::list l; + pattern_getchildren (this, l); - while (l) { - SPObject *child = SP_OBJECT (l->data); + for (SPObjectIterator it = l.begin(); it != l.end(); it++) { + SPObject *child = *it; sp_object_ref (child, NULL); - l = g_slist_remove (l, child); if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { child->updateDisplay(ctx, flags); @@ -263,20 +260,21 @@ void SPPattern::update(SPCtx* ctx, unsigned int flags) { } void SPPattern::modified(unsigned int flags) { + typedef std::list::iterator SPObjectIterator; + if (flags & SP_OBJECT_MODIFIED_FLAG) { flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; } flags &= SP_OBJECT_MODIFIED_CASCADE; - GSList *l = pattern_getchildren (this); - l = g_slist_reverse (l); + std::list l; + pattern_getchildren (this, l); - while (l) { - SPObject *child = SP_OBJECT (l->data); + for (SPObjectIterator it = l.begin(); it != l.end(); it++) { + SPObject *child = *it; sp_object_ref (child, NULL); - l = g_slist_remove (l, child); if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { child->emitModified(flags); @@ -402,8 +400,11 @@ sp_pattern_transform_multiply (SPPattern *pattern, Geom::Affine postmul, bool se pattern->getRepr()->setAttribute("patternTransform", c); } -const gchar *pattern_tile(GSList *reprs, Geom::Rect bounds, SPDocument *document, Geom::Affine transform, Geom::Affine move) +const gchar *pattern_tile(const std::list &reprs, Geom::Rect bounds, + SPDocument *document, Geom::Affine transform, Geom::Affine move) { + typedef std::list::const_iterator NodePtrIterator; + Inkscape::XML::Document *xml_doc = document->getReprDoc(); Inkscape::XML::Node *defsrepr = document->getDefs()->getRepr(); @@ -419,8 +420,8 @@ const gchar *pattern_tile(GSList *reprs, Geom::Rect bounds, SPDocument *document const gchar *pat_id = repr->attribute("id"); SPObject *pat_object = document->getObjectById(pat_id); - for (GSList *i = reprs; i != NULL; i = i->next) { - Inkscape::XML::Node *node = (Inkscape::XML::Node *)(i->data); + for (NodePtrIterator i = reprs.begin(); i != reprs.end(); i++) { + Inkscape::XML::Node *node = *i; SPItem *copy = SP_ITEM(pat_object->appendChildRepr(node)); Geom::Affine dup_transform; diff --git a/src/sp-pattern.h b/src/sp-pattern.h index 422adb169..3f7433d62 100644 --- a/src/sp-pattern.h +++ b/src/sp-pattern.h @@ -13,22 +13,29 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include #include +#include +#include #include "sp-item.h" +#include "svg/svg-length.h" +#include "sp-paint-server.h" +#include "uri-references.h" +#include "viewbox.h" #define SP_PATTERN(obj) (dynamic_cast((SPObject*)obj)) #define SP_IS_PATTERN(obj) (dynamic_cast((SPObject*)obj) != NULL) class SPPatternReference; -#include "svg/svg-length.h" -#include "sp-paint-server.h" -#include "uri-references.h" -#include "viewbox.h" +namespace Inkscape { +namespace XML { -#include -#include +class Node; + +} +} class SPPattern : public SPPaintServer, public SPViewBox { @@ -92,7 +99,7 @@ SPPattern *pattern_chain (SPPattern *pattern); SPPattern *sp_pattern_clone_if_necessary (SPItem *item, SPPattern *pattern, const gchar *property); void sp_pattern_transform_multiply (SPPattern *pattern, Geom::Affine postmul, bool set); -const gchar *pattern_tile (GSList *reprs, Geom::Rect bounds, SPDocument *document, Geom::Affine transform, Geom::Affine move); +const gchar *pattern_tile (const std::list &reprs, Geom::Rect bounds, SPDocument *document, Geom::Affine transform, Geom::Affine move); SPPattern *pattern_getroot (SPPattern *pat); -- cgit v1.2.3 From 22db6068f172d060429f17a489bdce59e5836c69 Mon Sep 17 00:00:00 2001 From: Tomasz Boczkowski Date: Tue, 27 May 2014 21:57:33 +0200 Subject: SPPattern c++-sification: replacing pattern_ functions by methods pt1 (bzr r13341.6.19) --- src/extension/internal/cairo-render-context.cpp | 16 +++--- src/extension/internal/emf-print.cpp | 8 +-- src/extension/internal/wmf-print.cpp | 4 +- src/knot-holder-entity.cpp | 10 ++-- src/selection-chemistry.cpp | 7 +-- src/sp-pattern.cpp | 66 ++++++++++++------------- src/sp-pattern.h | 20 +++++--- 7 files changed, 68 insertions(+), 63 deletions(-) (limited to 'src') diff --git a/src/extension/internal/cairo-render-context.cpp b/src/extension/internal/cairo-render-context.cpp index 2ace19ae5..aac2c517a 100644 --- a/src/extension/internal/cairo-render-context.cpp +++ b/src/extension/internal/cairo-render-context.cpp @@ -1006,16 +1006,16 @@ CairoRenderContext::_createPatternPainter(SPPaintServer const *const paintserver ps2user = Geom::identity(); pcs2dev = Geom::identity(); - double x = pattern_x(pat); - double y = pattern_y(pat); - double width = pattern_width(pat); - double height = pattern_height(pat); + double x = pat->get_x(); + double y = pat->get_y(); + double width = pat->get_width(); + double height = pat->get_height(); double bbox_width_scaler; double bbox_height_scaler; TRACE(("%f x %f pattern\n", width, height)); - if (pbox && pattern_patternUnits(pat) == SPPattern::UNITS_OBJECTBOUNDINGBOX) { + if (pbox && pat->get_pattern_units() == SPPattern::UNITS_OBJECTBOUNDINGBOX) { //Geom::Affine bbox2user (pbox->x1 - pbox->x0, 0.0, 0.0, pbox->y1 - pbox->y0, pbox->x0, pbox->y0); bbox_width_scaler = pbox->width(); bbox_height_scaler = pbox->height(); @@ -1029,13 +1029,13 @@ CairoRenderContext::_createPatternPainter(SPPaintServer const *const paintserver } // apply pattern transformation - Geom::Affine pattern_transform(pattern_patternTransform(pat)); + Geom::Affine pattern_transform(pat->get_transform()); ps2user *= pattern_transform; Geom::Point ori (ps2user[4], ps2user[5]); // create pattern contents coordinate system if (pat->viewBox_set) { - Geom::Rect view_box = *pattern_viewBox(pat); + Geom::Rect view_box = *pat->get_viewbox(); double x, y, w, h; x = 0; @@ -1048,7 +1048,7 @@ CairoRenderContext::_createPatternPainter(SPPaintServer const *const paintserver pcs2dev[3] = h / view_box.height(); pcs2dev[4] = x - view_box.left() * pcs2dev[0]; pcs2dev[5] = y - view_box.top() * pcs2dev[3]; - } else if (pbox && pattern_patternContentUnits(pat) == SPPattern::UNITS_OBJECTBOUNDINGBOX) { + } else if (pbox && pat->get_pattern_content_units() == SPPattern::UNITS_OBJECTBOUNDINGBOX) { pcs2dev[0] = pbox->width(); pcs2dev[3] = pbox->height(); } diff --git a/src/extension/internal/emf-print.cpp b/src/extension/internal/emf-print.cpp index 9c68e40a4..2953efd7d 100644 --- a/src/extension/internal/emf-print.cpp +++ b/src/extension/internal/emf-print.cpp @@ -381,8 +381,8 @@ int PrintEmf::create_brush(SPStyle const *style, PU_COLORREF fcolor) } else if (SP_IS_PATTERN(SP_STYLE_FILL_SERVER(style))) { // must be paint-server SPPaintServer *paintserver = style->fill.value.href->getObject(); SPPattern *pat = SP_PATTERN(paintserver); - double dwidth = pattern_width(pat); - double dheight = pattern_height(pat); + double dwidth = pat->get_width(); + double dheight = pat->get_height(); width = dwidth; height = dheight; brush_classify(pat, 0, &pixbuf, &hatchType, &hatchColor, &bkColor); @@ -567,8 +567,8 @@ int PrintEmf::create_pen(SPStyle const *style, const Geom::Affine &transform) if (SP_IS_PATTERN(SP_STYLE_STROKE_SERVER(style))) { // must be paint-server SPPaintServer *paintserver = style->stroke.value.href->getObject(); SPPattern *pat = SP_PATTERN(paintserver); - double dwidth = pattern_width(pat); - double dheight = pattern_height(pat); + double dwidth = pat->get_width(); + double dheight = pat->get_height(); width = dwidth; height = dheight; brush_classify(pat, 0, &pixbuf, &hatchType, &hatchColor, &bkColor); diff --git a/src/extension/internal/wmf-print.cpp b/src/extension/internal/wmf-print.cpp index 55ad5da5f..8f3115693 100644 --- a/src/extension/internal/wmf-print.cpp +++ b/src/extension/internal/wmf-print.cpp @@ -378,8 +378,8 @@ int PrintWmf::create_brush(SPStyle const *style, U_COLORREF *fcolor) } else if (SP_IS_PATTERN(SP_STYLE_FILL_SERVER(style))) { // must be paint-server SPPaintServer *paintserver = style->fill.value.href->getObject(); SPPattern *pat = SP_PATTERN(paintserver); - double dwidth = pattern_width(pat); - double dheight = pattern_height(pat); + double dwidth = pat->get_width(); + double dheight = pat->get_height(); width = dwidth; height = dheight; brush_classify(pat, 0, &pixbuf, &hatchType, &hatchColor, &bkColor); diff --git a/src/knot-holder-entity.cpp b/src/knot-holder-entity.cpp index 6471124ec..7b79d86a8 100644 --- a/src/knot-holder-entity.cpp +++ b/src/knot-holder-entity.cpp @@ -187,7 +187,7 @@ PatternKnotHolderEntityAngle::knot_get() const { SPPattern const *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style)); - gdouble x = pattern_width(pat); + gdouble x = pat->get_width(); gdouble y = 0; Geom::Point delta = Geom::Point(x,y); Geom::Point scale = sp_pattern_extract_scale(pat); @@ -236,8 +236,8 @@ PatternKnotHolderEntityScale::knot_set(Geom::Point const &p, Geom::Point const & // Get the new scale from the position of the knotholder Geom::Point d = p_snapped - sp_pattern_extract_trans(pat); - gdouble pat_x = pattern_width(pat); - gdouble pat_y = pattern_height(pat); + gdouble pat_x = pat->get_width(); + gdouble pat_y = pat->get_height(); Geom::Scale scl(1); if ( state & GDK_CONTROL_MASK ) { // if ctrl is pressed: use 1:1 scaling @@ -263,8 +263,8 @@ PatternKnotHolderEntityScale::knot_get() const { SPPattern const *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style)); - gdouble x = pattern_width(pat); - gdouble y = pattern_height(pat); + gdouble x = pat->get_width(); + gdouble y = pat->get_height(); Geom::Point delta = Geom::Point(x,y); Geom::Affine a = pat->patternTransform; a[4] = 0; diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 19eba8ddd..9d07ec046 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -3344,12 +3344,13 @@ void sp_selection_untile(SPDesktop *desktop) did = true; - SPPattern *pattern = pattern_getroot(SP_PATTERN(server)); + SPPattern *pattern = SP_PATTERN(server); + SPPattern *pattern_root = pattern_getroot(pattern); - Geom::Affine pat_transform = pattern_patternTransform(SP_PATTERN(server)); + Geom::Affine pat_transform = pattern->get_transform(); pat_transform *= item->transform; - for (SPObject *child = pattern->firstChild() ; child != NULL; child = child->next ) { + for (SPObject *child = pattern_root->firstChild() ; child != NULL; child = child->next ) { if (SP_IS_ITEM(child)) { Inkscape::XML::Node *copy = child->getRepr()->duplicate(xml_doc); SPItem *i = SP_ITEM(desktop->currentLayer()->appendChildRepr(copy)); diff --git a/src/sp-pattern.cpp b/src/sp-pattern.cpp index a3de09368..81e11ecb2 100644 --- a/src/sp-pattern.cpp +++ b/src/sp-pattern.cpp @@ -392,7 +392,7 @@ sp_pattern_transform_multiply (SPPattern *pattern, Geom::Affine postmul, bool se if (set) { pattern->patternTransform = postmul; } else { - pattern->patternTransform = pattern_patternTransform(pattern) * postmul; + pattern->patternTransform = pattern->get_transform() * postmul; } pattern->patternTransform_set = true; @@ -451,73 +451,73 @@ SPPattern *pattern_getroot(SPPattern *pat) // Access functions that look up fields up the chain of referenced patterns and return the first one which is set // FIXME: all of them must use chase_hrefs the same as in SPGradient, to avoid lockup on circular refs -SPPattern::PatternUnits pattern_patternUnits (SPPattern const *pat) +SPPattern::PatternUnits SPPattern::get_pattern_units() const { - for (SPPattern const *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { + for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { if (pat_i->patternUnits_set) return pat_i->patternUnits; } - return pat->patternUnits; + return patternUnits; } -SPPattern::PatternUnits pattern_patternContentUnits (SPPattern const *pat) +SPPattern::PatternUnits SPPattern::get_pattern_content_units() const { - for (SPPattern const *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { + for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { if (pat_i->patternContentUnits_set) return pat_i->patternContentUnits; } - return pat->patternContentUnits; + return patternContentUnits; } -Geom::Affine const &pattern_patternTransform(SPPattern const *pat) +Geom::Affine const &SPPattern::get_transform() const { - for (SPPattern const *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { + for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { if (pat_i->patternTransform_set) return pat_i->patternTransform; } - return pat->patternTransform; + return patternTransform; } -gdouble pattern_x (SPPattern const *pat) +gdouble SPPattern::get_x() const { - for (SPPattern const *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { + for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { if (pat_i->x._set) return pat_i->x.computed; } return 0; } -gdouble pattern_y (SPPattern const *pat) +gdouble SPPattern::get_y() const { - for (SPPattern const *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { + for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { if (pat_i->y._set) return pat_i->y.computed; } return 0; } -gdouble pattern_width (SPPattern const* pat) +gdouble SPPattern::get_width() const { - for (SPPattern const *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { + for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { if (pat_i->width._set) return pat_i->width.computed; } return 0; } -gdouble pattern_height (SPPattern const *pat) +gdouble SPPattern::get_height() const { - for (SPPattern const *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { + for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { if (pat_i->height._set) return pat_i->height.computed; } return 0; } -Geom::OptRect pattern_viewBox (SPPattern const *pat) +Geom::OptRect SPPattern::get_viewbox() const { Geom::OptRect viewbox; - for (SPPattern const *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { + for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { if (pat_i->viewBox_set) { viewbox = pat_i->viewBox; break; @@ -526,10 +526,10 @@ Geom::OptRect pattern_viewBox (SPPattern const *pat) return viewbox; } -static bool pattern_hasItemChildren (SPPattern const *pat) +bool SPPattern::_has_item_children() const { bool hasChildren = false; - for (SPObject const *child = pat->firstChild() ; child && !hasChildren ; child = child->getNext() ) { + for (SPObject const *child = firstChild() ; child && !hasChildren ; child = child->getNext() ) { if (SP_IS_ITEM(child)) { hasChildren = true; } @@ -539,8 +539,8 @@ static bool pattern_hasItemChildren (SPPattern const *pat) bool SPPattern::isValid() const { - double tile_width = pattern_width(this); - double tile_height = pattern_height(this); + double tile_width = get_width(); + double tile_height = get_height(); if (tile_width <= 0 || tile_height <= 0) return false; @@ -561,7 +561,7 @@ cairo_pattern_t* SPPattern::pattern_new(cairo_t *base_ct, Geom::OptRect const &b for (SPPattern *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { // find the first one with item children - if (pat_i && SP_IS_OBJECT(pat_i) && pattern_hasItemChildren(pat_i)) { + if (pat_i && SP_IS_OBJECT(pat_i) && pat_i->_has_item_children()) { shown = pat_i; break; // do not go further up the chain if children are found } @@ -595,11 +595,11 @@ cairo_pattern_t* SPPattern::pattern_new(cairo_t *base_ct, Geom::OptRect const &b // * "x", "y", and "patternTransform" transform tile to user space after tile is generated. // These functions recursively search up the tree to find the values. - double tile_x = pattern_x(this); - double tile_y = pattern_y(this); - double tile_width = pattern_width(this); - double tile_height = pattern_height(this); - if ( bbox && (pattern_patternUnits(this) == UNITS_OBJECTBOUNDINGBOX) ) { + double tile_x = get_x(); + double tile_y = get_y(); + double tile_width = get_width(); + double tile_height = get_height(); + if ( bbox && (get_pattern_units() == UNITS_OBJECTBOUNDINGBOX) ) { tile_x *= bbox->width(); tile_y *= bbox->height(); tile_width *= bbox->width(); @@ -611,7 +611,7 @@ cairo_pattern_t* SPPattern::pattern_new(cairo_t *base_ct, Geom::OptRect const &b // Content to tile (pattern space) Geom::Affine content2ps; - Geom::OptRect effective_view_box = pattern_viewBox(this); + Geom::OptRect effective_view_box = get_viewbox(); if (effective_view_box) { // viewBox to pattern server (using SPViewBox) viewBox = *effective_view_box; @@ -621,14 +621,14 @@ cairo_pattern_t* SPPattern::pattern_new(cairo_t *base_ct, Geom::OptRect const &b } else { // Content to bbox - if (bbox && (pattern_patternContentUnits(this) == UNITS_OBJECTBOUNDINGBOX) ) { + if (bbox && (get_pattern_content_units() == UNITS_OBJECTBOUNDINGBOX) ) { content2ps = Geom::Affine(bbox->width(), 0.0, 0.0, bbox->height(), 0,0); } } // Tile (pattern space) to user. - Geom::Affine ps2user = Geom::Translate(tile_x,tile_y) * pattern_patternTransform(this); + Geom::Affine ps2user = Geom::Translate(tile_x,tile_y) * get_transform(); // Transform of object with pattern (includes screen scaling) diff --git a/src/sp-pattern.h b/src/sp-pattern.h index 3f7433d62..f1dcc7963 100644 --- a/src/sp-pattern.h +++ b/src/sp-pattern.h @@ -70,6 +70,15 @@ public: bool isValid() const; + gdouble get_x() const; + gdouble get_y() const; + gdouble get_width() const; + gdouble get_height() const; + Geom::OptRect get_viewbox() const; + SPPattern::PatternUnits get_pattern_units() const; + SPPattern::PatternUnits get_pattern_content_units() const; + Geom::Affine const &get_transform() const; + virtual cairo_pattern_t* pattern_new(cairo_t *ct, Geom::OptRect const &bbox, double opacity); protected: @@ -78,6 +87,9 @@ protected: virtual void set(unsigned int key, const gchar* value); virtual void update(SPCtx* ctx, unsigned int flags); virtual void modified(unsigned int flags); + +private: + bool _has_item_children() const; }; @@ -103,14 +115,6 @@ const gchar *pattern_tile (const std::list &reprs, Geom::R SPPattern *pattern_getroot (SPPattern *pat); -SPPattern::PatternUnits pattern_patternUnits (SPPattern const *pat); -SPPattern::PatternUnits pattern_patternContentUnits (SPPattern const *pat); -Geom::Affine const &pattern_patternTransform(SPPattern const *pat); -gdouble pattern_x (SPPattern const *pat); -gdouble pattern_y (SPPattern const *pat); -gdouble pattern_width (SPPattern const *pat); -gdouble pattern_height (SPPattern const *pat); -Geom::OptRect pattern_viewBox (SPPattern const *pat); #endif // SEEN_SP_PATTERN_H -- cgit v1.2.3 From 9f92d7370e6e3f456259f5774d3443ae763160d3 Mon Sep 17 00:00:00 2001 From: Tomasz Boczkowski Date: Tue, 27 May 2014 22:21:15 +0200 Subject: SPPattern c++-sification: removed unused declatations and includes (bzr r13341.6.20) --- src/sp-pattern.h | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/sp-pattern.h b/src/sp-pattern.h index f1dcc7963..f2a1e1c6c 100644 --- a/src/sp-pattern.h +++ b/src/sp-pattern.h @@ -1,9 +1,6 @@ -#ifndef SEEN_SP_PATTERN_H -#define SEEN_SP_PATTERN_H - -/* +/** @file * SVG implementation - * + *//* * Author: * Lauris Kaplinski * Abhishek Sharma @@ -13,21 +10,21 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#ifndef SEEN_SP_PATTERN_H +#define SEEN_SP_PATTERN_H + #include -#include #include +#include #include -#include "sp-item.h" #include "svg/svg-length.h" #include "sp-paint-server.h" #include "uri-references.h" #include "viewbox.h" -#define SP_PATTERN(obj) (dynamic_cast((SPObject*)obj)) -#define SP_IS_PATTERN(obj) (dynamic_cast((SPObject*)obj) != NULL) - class SPPatternReference; +class SPItem; namespace Inkscape { namespace XML { @@ -37,6 +34,8 @@ class Node; } } +#define SP_PATTERN(obj) (dynamic_cast((SPObject*)obj)) +#define SP_IS_PATTERN(obj) (dynamic_cast((SPObject*)obj) != NULL) class SPPattern : public SPPaintServer, public SPViewBox { public: @@ -106,7 +105,6 @@ protected: } }; -guint pattern_users (SPPattern *pattern); SPPattern *pattern_chain (SPPattern *pattern); SPPattern *sp_pattern_clone_if_necessary (SPItem *item, SPPattern *pattern, const gchar *property); void sp_pattern_transform_multiply (SPPattern *pattern, Geom::Affine postmul, bool set); -- cgit v1.2.3 From 4d75f1ecca2fcab4cbfec9fb84c5b1f3647dbc17 Mon Sep 17 00:00:00 2001 From: Tomasz Boczkowski Date: Wed, 28 May 2014 23:28:17 +0200 Subject: SPPattern c++-sification: replaced function by methods (bzr r13341.6.21) --- src/desktop-style.cpp | 4 ++-- src/selection-chemistry.cpp | 6 ++--- src/sp-item.cpp | 8 +++---- src/sp-pattern.cpp | 50 +++++++++++++++++------------------------- src/sp-pattern.h | 15 ++++++++----- src/widgets/fill-style.cpp | 4 ++-- src/widgets/paint-selector.cpp | 4 ++-- 7 files changed, 43 insertions(+), 48 deletions(-) (limited to 'src') diff --git a/src/desktop-style.cpp b/src/desktop-style.cpp index 37f537cc5..8c3dac382 100644 --- a/src/desktop-style.cpp +++ b/src/desktop-style.cpp @@ -538,8 +538,8 @@ objects_query_fillstroke (GSList *objects, SPStyle *style_res, bool const isfill if (!SP_IS_PATTERN(server)) return QUERY_STYLE_MULTIPLE_DIFFERENT; // different kind of server - SPPattern *pat = pattern_getroot (SP_PATTERN (server)); - SPPattern *pat_res = pattern_getroot (SP_PATTERN (server_res)); + SPPattern *pat = SP_PATTERN (server)->get_root(); + SPPattern *pat_res = SP_PATTERN (server_res)->get_root(); if (pat_res != pat) return QUERY_STYLE_MULTIPLE_DIFFERENT; // different pattern roots } diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 9d07ec046..069aa57bb 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -1945,8 +1945,8 @@ GSList *sp_get_same_fill_or_stroke_color(SPItem *sel, GSList *src, SPSelectStrok } } else if (SP_IS_PATTERN(sel_server) && SP_IS_PATTERN(iter_server)) { - SPPattern *sel_pat = pattern_getroot(SP_PATTERN(sel_server)); - SPPattern *iter_pat = pattern_getroot(SP_PATTERN(iter_server)); + SPPattern *sel_pat = SP_PATTERN(sel_server)->get_root(); + SPPattern *iter_pat = SP_PATTERN(iter_server)->get_root(); if (sel_pat == iter_pat) { match = true; } @@ -3345,7 +3345,7 @@ void sp_selection_untile(SPDesktop *desktop) did = true; SPPattern *pattern = SP_PATTERN(server); - SPPattern *pattern_root = pattern_getroot(pattern); + SPPattern *pattern_root = pattern->get_root(); Geom::Affine pat_transform = pattern->get_transform(); pat_transform *= item->transform; diff --git a/src/sp-item.cpp b/src/sp-item.cpp index b10aae1c6..b6a6e66ef 100644 --- a/src/sp-item.cpp +++ b/src/sp-item.cpp @@ -1113,16 +1113,16 @@ void SPItem::adjust_pattern (Geom::Affine const &postmul, bool set) if (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"); - sp_pattern_transform_multiply(pattern, postmul, set); + SPPattern *pattern = SP_PATTERN(server)->clone_if_necessary(this, "fill"); + pattern->transform_multiply(postmul, set); } } if (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"); - sp_pattern_transform_multiply(pattern, postmul, set); + SPPattern *pattern = SP_PATTERN(server)->clone_if_necessary(this, "stroke"); + pattern->transform_multiply(postmul, set); } } } diff --git a/src/sp-pattern.cpp b/src/sp-pattern.cpp index 81e11ecb2..bd24ab1bb 100644 --- a/src/sp-pattern.cpp +++ b/src/sp-pattern.cpp @@ -312,12 +312,7 @@ static void pattern_ref_modified (SPObject */*ref*/, guint /*flags*/, SPPattern // Conditional to avoid causing infinite loop if there's a cycle in the href chain. } - -/** -Count how many times pat is used by the styles of o and its descendants -*/ -static guint -count_pattern_hrefs(SPObject *o, SPPattern *pat) +guint SPPattern::_count_hrefs(SPObject *o) const { if (!o) return 1; @@ -328,34 +323,32 @@ count_pattern_hrefs(SPObject *o, SPPattern *pat) if (style && style->fill.isPaintserver() && SP_IS_PATTERN(SP_STYLE_FILL_SERVER(style)) - && SP_PATTERN(SP_STYLE_FILL_SERVER(style)) == pat) + && SP_PATTERN(SP_STYLE_FILL_SERVER(style)) == this) { i ++; } if (style && style->stroke.isPaintserver() && SP_IS_PATTERN(SP_STYLE_STROKE_SERVER(style)) - && SP_PATTERN(SP_STYLE_STROKE_SERVER(style)) == pat) + && SP_PATTERN(SP_STYLE_STROKE_SERVER(style)) == this) { i ++; } for ( SPObject *child = o->firstChild(); child != NULL; child = child->next ) { - i += count_pattern_hrefs(child, pat); + i += _count_hrefs(child); } return i; } -SPPattern *pattern_chain(SPPattern *pattern) -{ - SPDocument *document = pattern->document; - Inkscape::XML::Document *xml_doc = document->getReprDoc(); +SPPattern *SPPattern::_chain() const { + Inkscape::XML::Document *xml_doc = document->getReprDoc(); Inkscape::XML::Node *defsrepr = document->getDefs()->getRepr(); Inkscape::XML::Node *repr = xml_doc->createElement("svg:pattern"); repr->setAttribute("inkscape:collect", "always"); - Glib::ustring parent_ref = Glib::ustring::compose("#%1", pattern->getRepr()->attribute("id")); + Glib::ustring parent_ref = Glib::ustring::compose("#%1", getRepr()->attribute("id")); repr->setAttribute("xlink:href", parent_ref); defsrepr->addChild(repr, NULL); @@ -366,11 +359,10 @@ SPPattern *pattern_chain(SPPattern *pattern) return SP_PATTERN (child); } -SPPattern * -sp_pattern_clone_if_necessary (SPItem *item, SPPattern *pattern, const gchar *property) -{ - if (pattern->href.empty() || pattern->hrefcount > count_pattern_hrefs(item, pattern)) { - pattern = pattern_chain (pattern); +SPPattern *SPPattern::clone_if_necessary(SPItem *item, const gchar *property) { + SPPattern *pattern = this; + if (pattern->href.empty() || pattern->hrefcount > _count_hrefs(item)) { + pattern = _chain(); Glib::ustring href = Glib::ustring::compose("url(#%1)", pattern->getRepr()->attribute("id")); SPCSSAttr *css = sp_repr_css_attr_new (); @@ -381,23 +373,21 @@ sp_pattern_clone_if_necessary (SPItem *item, SPPattern *pattern, const gchar *pr return pattern; } -void -sp_pattern_transform_multiply (SPPattern *pattern, Geom::Affine postmul, bool set) -{ +void SPPattern::transform_multiply(Geom::Affine postmul, bool set) { // this formula is for a different interpretation of pattern transforms as described in (*) in sp-pattern.cpp // for it to work, we also need sp_object_read_attr( item, "transform"); //pattern->patternTransform = premul * item->transform * pattern->patternTransform * item->transform.inverse() * postmul; // otherwise the formula is much simpler if (set) { - pattern->patternTransform = postmul; + patternTransform = postmul; } else { - pattern->patternTransform = pattern->get_transform() * postmul; + patternTransform = get_transform() * postmul; } - pattern->patternTransform_set = true; + patternTransform_set = true; - Glib::ustring c=sp_svg_transform_write(pattern->patternTransform); - pattern->getRepr()->setAttribute("patternTransform", c); + Glib::ustring c=sp_svg_transform_write(patternTransform); + getRepr()->setAttribute("patternTransform", c); } const gchar *pattern_tile(const std::list &reprs, Geom::Rect bounds, @@ -436,14 +426,14 @@ const gchar *pattern_tile(const std::list &reprs, Geom::Re return pat_id; } -SPPattern *pattern_getroot(SPPattern *pat) +SPPattern *SPPattern::get_root() { - for (SPPattern *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { + for (SPPattern *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { if ( pat_i->firstChild() ) { // find the first one with children return pat_i; } } - return pat; // document is broken, we can't get to root; but at least we can return pat which is supposedly a valid pattern + return this; // document is broken, we can't get to root; but at least we can return pat which is supposedly a valid pattern } diff --git a/src/sp-pattern.h b/src/sp-pattern.h index f2a1e1c6c..0c468d8f7 100644 --- a/src/sp-pattern.h +++ b/src/sp-pattern.h @@ -77,6 +77,10 @@ public: SPPattern::PatternUnits get_pattern_units() const; SPPattern::PatternUnits get_pattern_content_units() const; Geom::Affine const &get_transform() const; + SPPattern *get_root(); //TODO: const + + SPPattern *clone_if_necessary(SPItem *item, const gchar *property); + void transform_multiply(Geom::Affine postmul, bool set); virtual cairo_pattern_t* pattern_new(cairo_t *ct, Geom::OptRect const &bbox, double opacity); @@ -89,6 +93,12 @@ protected: private: bool _has_item_children() const; + SPPattern *_chain() const; + + /** + Count how many times pat is used by the styles of o and its descendants + */ + guint _count_hrefs(SPObject* o) const; }; @@ -105,14 +115,9 @@ protected: } }; -SPPattern *pattern_chain (SPPattern *pattern); -SPPattern *sp_pattern_clone_if_necessary (SPItem *item, SPPattern *pattern, const gchar *property); -void sp_pattern_transform_multiply (SPPattern *pattern, Geom::Affine postmul, bool set); const gchar *pattern_tile (const std::list &reprs, Geom::Rect bounds, SPDocument *document, Geom::Affine transform, Geom::Affine move); -SPPattern *pattern_getroot (SPPattern *pat); - #endif // SEEN_SP_PATTERN_H diff --git a/src/widgets/fill-style.cpp b/src/widgets/fill-style.cpp index d1d318abe..27ab7156c 100644 --- a/src/widgets/fill-style.cpp +++ b/src/widgets/fill-style.cpp @@ -304,7 +304,7 @@ void FillNStroke::performUpdate() psel->setGradientProperties( rg->getUnits(), rg->getSpread() ); } else if (SP_IS_PATTERN(server)) { - SPPattern *pat = pattern_getroot(SP_PATTERN(server)); + SPPattern *pat = SP_PATTERN(server)->get_root(); psel->updatePatternList( pat ); } } @@ -663,7 +663,7 @@ void FillNStroke::updateFromPaint() SPPaintServer *server = (kind == FILL) ? selobj->style->getFillPaintServer() : selobj->style->getStrokePaintServer(); - if (SP_IS_PATTERN(server) && pattern_getroot(SP_PATTERN(server)) == pattern) + if (SP_IS_PATTERN(server) && SP_PATTERN(server)->get_root() == pattern) // only if this object's pattern is not rooted in our selected pattern, apply continue; } diff --git a/src/widgets/paint-selector.cpp b/src/widgets/paint-selector.cpp index 9466c875e..39336267b 100644 --- a/src/widgets/paint-selector.cpp +++ b/src/widgets/paint-selector.cpp @@ -803,7 +803,7 @@ ink_pattern_list_get (SPDocument *source) GSList *pl = NULL; GSList const *patterns = source->getResourceList("pattern"); for (GSList *l = const_cast(patterns); l != NULL; l = l->next) { - if (SP_PATTERN(l->data) == pattern_getroot(SP_PATTERN(l->data))) { // only if this is a root pattern + if (SP_PATTERN(l->data) == SP_PATTERN(l->data)->get_root()) { // only if this is a root pattern pl = g_slist_prepend(pl, l->data); } } @@ -1123,7 +1123,7 @@ SPPattern *SPPaintSelector::getPattern() } g_free(paturn); } else { - pat = pattern_getroot(SP_PATTERN(patid)); + pat = SP_PATTERN(patid)->get_root(); } if (pat && !SP_IS_PATTERN(pat)) { -- cgit v1.2.3 From 85840ae655411c47248cd794a19dedd9ea3a591f Mon Sep 17 00:00:00 2001 From: Tomasz Boczkowski Date: Thu, 29 May 2014 12:04:56 +0200 Subject: SPPattern c++-sification: replaced function by methods pt3 (bzr r13341.6.22) --- src/selection-chemistry.cpp | 2 +- src/sp-pattern.cpp | 39 ++++++++++----------------------------- src/sp-pattern.h | 24 +++++++++++++++++++----- 3 files changed, 30 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 069aa57bb..fa4589129 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -3265,7 +3265,7 @@ sp_selection_tile(SPDesktop *desktop, bool apply) int saved_compensation = prefs->getInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED); prefs->setInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED); - gchar const *pat_id = pattern_tile(repr_copies, bbox, doc, + gchar const *pat_id = SPPattern::produce(repr_copies, bbox, doc, ( Geom::Affine(Geom::Translate(desktop->dt2doc(Geom::Point(r->min()[Geom::X], r->max()[Geom::Y])))) * parent_transform.inverse() ), diff --git a/src/sp-pattern.cpp b/src/sp-pattern.cpp index bd24ab1bb..82e3cdacf 100644 --- a/src/sp-pattern.cpp +++ b/src/sp-pattern.cpp @@ -19,7 +19,8 @@ #include #include #include <2geom/transforms.h> -#include "macros.h" +#include + #include "svg/svg.h" #include "display/cairo-utils.h" #include "display/drawing-context.h" @@ -32,16 +33,6 @@ #include "style.h" #include "sp-pattern.h" #include "xml/repr.h" -#include "display/grayscale.h" - -#include -#include - -/* - * Pattern - */ -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" @@ -55,7 +46,7 @@ namespace { SPPattern::SPPattern() : SPPaintServer(), SPViewBox() { this->ref = new SPPatternReference(this); - this->ref->changedSignal().connect(sigc::bind(sigc::ptr_fun(pattern_ref_changed), this)); + this->ref->changedSignal().connect(sigc::mem_fun(this, &SPPattern::_on_ref_changed)); this->patternUnits = UNITS_OBJECTBOUNDINGBOX; this->patternUnits_set = false; @@ -284,31 +275,21 @@ void SPPattern::modified(unsigned int flags) { } } -/** -Gets called when the pattern is reattached to another -*/ -static void -pattern_ref_changed(SPObject *old_ref, SPObject *ref, SPPattern *pat) -{ +void SPPattern::_on_ref_changed(SPObject *old_ref, SPObject *ref) { if (old_ref) { - pat->modified_connection.disconnect(); + modified_connection.disconnect(); } if (SP_IS_PATTERN (ref)) { - pat->modified_connection = ref->connectModified(sigc::bind<2>(sigc::ptr_fun(&pattern_ref_modified), pat)); + modified_connection = ref->connectModified(sigc::mem_fun(this, &SPPattern::_on_ref_modified)); } - pattern_ref_modified (ref, 0, pat); + _on_ref_modified(ref, 0); } -/** -Gets called when the referenced is changed -*/ -static void pattern_ref_modified (SPObject */*ref*/, guint /*flags*/, SPPattern *pattern) +void SPPattern::_on_ref_modified(SPObject */*ref*/, guint /*flags*/) { - if ( SP_IS_OBJECT(pattern) ) { - pattern->requestModified(SP_OBJECT_MODIFIED_FLAG); - } + requestModified(SP_OBJECT_MODIFIED_FLAG); // Conditional to avoid causing infinite loop if there's a cycle in the href chain. } @@ -390,7 +371,7 @@ void SPPattern::transform_multiply(Geom::Affine postmul, bool set) { getRepr()->setAttribute("patternTransform", c); } -const gchar *pattern_tile(const std::list &reprs, Geom::Rect bounds, +const gchar *SPPattern::produce(const std::list &reprs, Geom::Rect bounds, SPDocument *document, Geom::Affine transform, Geom::Affine move) { typedef std::list::const_iterator NodePtrIterator; diff --git a/src/sp-pattern.h b/src/sp-pattern.h index 0c468d8f7..1eec0da7f 100644 --- a/src/sp-pattern.h +++ b/src/sp-pattern.h @@ -82,6 +82,14 @@ public: SPPattern *clone_if_necessary(SPItem *item, const gchar *property); void transform_multiply(Geom::Affine postmul, bool set); + /** + * @brief create a new pattern in XML tree + * @return created pattern id + */ + static const gchar *produce(const std::list &reprs, + Geom::Rect bounds, SPDocument *document, Geom::Affine transform, Geom::Affine move); + + virtual cairo_pattern_t* pattern_new(cairo_t *ct, Geom::OptRect const &bbox, double opacity); protected: @@ -96,9 +104,19 @@ private: SPPattern *_chain() const; /** - Count how many times pat is used by the styles of o and its descendants + Count how many times pattern is used by the styles of o and its descendants */ guint _count_hrefs(SPObject* o) const; + + /** + Gets called when the pattern is reattached to another + */ + void _on_ref_changed(SPObject *old_ref, SPObject *ref); + + /** + Gets called when the referenced is changed + */ + void _on_ref_modified(SPObject *ref, guint flags); }; @@ -115,10 +133,6 @@ protected: } }; - -const gchar *pattern_tile (const std::list &reprs, Geom::Rect bounds, SPDocument *document, Geom::Affine transform, Geom::Affine move); - - #endif // SEEN_SP_PATTERN_H /* -- cgit v1.2.3 From 35100d54d146fd0fcf702abca02311b0ef95152f Mon Sep 17 00:00:00 2001 From: Tomasz Boczkowski Date: Thu, 29 May 2014 12:35:19 +0200 Subject: SPPattern c++-sification: class fields are private (bzr r13341.6.23) --- src/knot-holder-entity.cpp | 8 ++++---- src/sp-pattern.cpp | 8 ++++---- src/sp-pattern.h | 37 ++++++++++++++++++------------------- 3 files changed, 26 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/knot-holder-entity.cpp b/src/knot-holder-entity.cpp index 7b79d86a8..c3e48cf49 100644 --- a/src/knot-holder-entity.cpp +++ b/src/knot-holder-entity.cpp @@ -136,19 +136,19 @@ KnotHolderEntity::snap_knot_position_constrained(Geom::Point const &p, Inkscape: static gdouble sp_pattern_extract_theta(SPPattern const *pat) { - Geom::Affine transf = pat->patternTransform; + Geom::Affine transf = pat->get_transform(); return Geom::atan2(transf.xAxis()); } static Geom::Point sp_pattern_extract_scale(SPPattern const *pat) { - Geom::Affine transf = pat->patternTransform; + Geom::Affine transf = pat->get_transform(); return Geom::Point( transf.expansionX(), transf.expansionY() ); } static Geom::Point sp_pattern_extract_trans(SPPattern const *pat) { - return Geom::Point(pat->patternTransform[4], pat->patternTransform[5]); + return Geom::Point(pat->get_transform()[4], pat->get_transform()[5]); } void @@ -266,7 +266,7 @@ PatternKnotHolderEntityScale::knot_get() const gdouble x = pat->get_width(); gdouble y = pat->get_height(); Geom::Point delta = Geom::Point(x,y); - Geom::Affine a = pat->patternTransform; + Geom::Affine a = pat->get_transform(); a[4] = 0; a[5] = 0; delta = delta * a; diff --git a/src/sp-pattern.cpp b/src/sp-pattern.cpp index 82e3cdacf..c2835eadd 100644 --- a/src/sp-pattern.cpp +++ b/src/sp-pattern.cpp @@ -213,8 +213,8 @@ void SPPattern::set(unsigned int key, const gchar* value) { /* fixme: We need ::order_changed handler too (Lauris) */ -void pattern_getchildren(SPPattern *pat, std::list& l) -{ +void SPPattern::_get_children(std::list& l) { + SPPattern *pat = this; for (SPPattern *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { if (pat_i->firstChild()) { // find the first one with children for (SPObject *child = pat->firstChild() ; child ; child = child->getNext() ) { @@ -235,7 +235,7 @@ void SPPattern::update(SPCtx* ctx, unsigned int flags) { flags &= SP_OBJECT_MODIFIED_CASCADE; std::list l; - pattern_getchildren (this, l); + _get_children(l); for (SPObjectIterator it = l.begin(); it != l.end(); it++) { SPObject *child = *it; @@ -260,7 +260,7 @@ void SPPattern::modified(unsigned int flags) { flags &= SP_OBJECT_MODIFIED_CASCADE; std::list l; - pattern_getchildren (this, l); + _get_children(l); for (SPObjectIterator it = l.begin(); it != l.end(); it++) { SPObject *child = *it; diff --git a/src/sp-pattern.h b/src/sp-pattern.h index 1eec0da7f..3fe0f53d8 100644 --- a/src/sp-pattern.h +++ b/src/sp-pattern.h @@ -51,24 +51,6 @@ public: Glib::ustring href; SPPatternReference *ref; - /* patternUnits and patternContentUnits attribute */ - PatternUnits patternUnits : 1; - bool patternUnits_set : 1; - PatternUnits patternContentUnits : 1; - bool patternContentUnits_set : 1; - /* patternTransform attribute */ - Geom::Affine patternTransform; - bool patternTransform_set : 1; - /* Tile rectangle */ - SVGLength x; - SVGLength y; - SVGLength width; - SVGLength height; - - sigc::connection modified_connection; - - bool isValid() const; - gdouble get_x() const; gdouble get_y() const; gdouble get_width() const; @@ -89,7 +71,7 @@ public: static const gchar *produce(const std::list &reprs, Geom::Rect bounds, SPDocument *document, Geom::Affine transform, Geom::Affine move); - + bool isValid() const; virtual cairo_pattern_t* pattern_new(cairo_t *ct, Geom::OptRect const &bbox, double opacity); protected: @@ -101,6 +83,7 @@ protected: private: bool _has_item_children() const; + void _get_children(std::list& l); SPPattern *_chain() const; /** @@ -117,6 +100,22 @@ private: Gets called when the referenced is changed */ void _on_ref_modified(SPObject *ref, guint flags); + + /* patternUnits and patternContentUnits attribute */ + PatternUnits patternUnits : 1; + bool patternUnits_set : 1; + PatternUnits patternContentUnits : 1; + bool patternContentUnits_set : 1; + /* patternTransform attribute */ + Geom::Affine patternTransform; + bool patternTransform_set : 1; + /* Tile rectangle */ + SVGLength x; + SVGLength y; + SVGLength width; + SVGLength height; + + sigc::connection modified_connection; }; -- cgit v1.2.3