summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/desktop-style.cpp4
-rw-r--r--src/selection-chemistry.cpp6
-rw-r--r--src/sp-item.cpp8
-rw-r--r--src/sp-pattern.cpp50
-rw-r--r--src/sp-pattern.h15
-rw-r--r--src/widgets/fill-style.cpp4
-rw-r--r--src/widgets/paint-selector.cpp4
7 files changed, 43 insertions, 48 deletions
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<Inkscape::XML::Node*> &reprs, Geom::Rect bounds,
@@ -436,14 +426,14 @@ const gchar *pattern_tile(const std::list<Inkscape::XML::Node*> &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<Inkscape::XML::Node*> &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<GSList *>(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)) {