summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2014-12-26 18:49:12 +0000
committertavmjong-free <tavmjong@free.fr>2014-12-26 18:49:12 +0000
commit74f6d0cf39c974ca1980a7be7742f2154d2025f2 (patch)
treef98b503be33ccc32c1074c5c670a0cd9b5fb5332 /src
parentDocumentation. Fix for bug #1405653 (Outdated links in hacking doc). (diff)
parentSPStyle ref counting clean up. (diff)
downloadinkscape-74f6d0cf39c974ca1980a7be7742f2154d2025f2.tar.gz
inkscape-74f6d0cf39c974ca1980a7be7742f2154d2025f2.zip
Replace sp_style_xxx functions with SPStyle member functions.
Fix a bunch of memory leaks. One leak still remaining in Layout::appendText. (bzr r13824)
Diffstat (limited to 'src')
-rw-r--r--src/desktop-style.cpp7
-rw-r--r--src/display/drawing-item.cpp10
-rw-r--r--src/display/nr-filter-primitive.cpp8
-rw-r--r--src/gradient-chemistry.cpp3
-rw-r--r--src/libnrtype/Layout-TNG-Input.cpp2
-rw-r--r--src/libnrtype/font-lister.cpp19
-rw-r--r--src/path-chemistry.cpp28
-rw-r--r--src/selection-chemistry.cpp9
-rw-r--r--src/sp-clippath.cpp2
-rw-r--r--src/sp-flowtext.cpp8
-rw-r--r--src/sp-hatch-path.cpp2
-rw-r--r--src/sp-hatch.cpp2
-rw-r--r--src/sp-item-group.cpp7
-rw-r--r--src/sp-item.cpp2
-rw-r--r--src/sp-object.cpp40
-rw-r--r--src/sp-solid-color.cpp2
-rw-r--r--src/sp-stop.cpp6
-rw-r--r--src/sp-style-elem.cpp13
-rw-r--r--src/sp-tref.cpp8
-rw-r--r--src/sp-use.cpp7
-rw-r--r--src/style-test.h123
-rw-r--r--src/style.cpp313
-rw-r--r--src/style.h31
-rw-r--r--src/text-editing.cpp39
-rw-r--r--src/ui/dialog/glyphs.cpp9
-rw-r--r--src/ui/dialog/swatches.cpp24
-rw-r--r--src/ui/dialog/text-edit.cpp31
-rw-r--r--src/ui/tools/freehand-base.cpp19
-rw-r--r--src/ui/widget/object-composite-settings.cpp16
-rw-r--r--src/ui/widget/selected-style.cpp26
-rw-r--r--src/ui/widget/style-swatch.cpp9
-rw-r--r--src/widgets/dash-selector.cpp12
-rw-r--r--src/widgets/fill-style.cpp23
-rw-r--r--src/widgets/stroke-style.cpp24
-rw-r--r--src/widgets/text-toolbar.cpp139
35 files changed, 420 insertions, 603 deletions
diff --git a/src/desktop-style.cpp b/src/desktop-style.cpp
index 3eb11bea6..ee9fa39ec 100644
--- a/src/desktop-style.cpp
+++ b/src/desktop-style.cpp
@@ -428,10 +428,9 @@ sp_desktop_get_font_size_tool(SPDesktop *desktop)
double ret = 12;
if (!style_str.empty()) {
- SPStyle *style = sp_style_new(SP_ACTIVE_DOCUMENT);
- sp_style_merge_from_style_string(style, style_str.data());
- ret = style->font_size.computed;
- sp_style_unref(style);
+ SPStyle style(SP_ACTIVE_DOCUMENT);
+ style.mergeString(style_str.data());
+ ret = style.font_size.computed;
}
return ret;
}
diff --git a/src/display/drawing-item.cpp b/src/display/drawing-item.cpp
index 83d4744c9..89ca66dc4 100644
--- a/src/display/drawing-item.cpp
+++ b/src/display/drawing-item.cpp
@@ -366,10 +366,12 @@ DrawingItem::setStyle(SPStyle *style, SPStyle *context_style)
// std::cout << "DrawingItem::setStyle: " << name() << " " << style
// << " " << context_style << std::endl;
- if (style) sp_style_ref(style);
- if (_style) sp_style_unref(_style);
- _style = style;
-
+ if( style != _style ) {
+ if (style) sp_style_ref(style);
+ if (_style) sp_style_unref(_style);
+ _style = style;
+ }
+
if (style && style->filter.set && style->getFilter()) {
if (!_filter) {
int primitives = sp_filter_primitive_count(SP_FILTER(style->getFilter()));
diff --git a/src/display/nr-filter-primitive.cpp b/src/display/nr-filter-primitive.cpp
index 3033118e4..c8b569036 100644
--- a/src/display/nr-filter-primitive.cpp
+++ b/src/display/nr-filter-primitive.cpp
@@ -171,9 +171,11 @@ Geom::Rect FilterPrimitive::filter_primitive_area(FilterUnits const &units)
void FilterPrimitive::setStyle(SPStyle *style)
{
- if (style) sp_style_ref(style);
- if (_style) sp_style_unref(_style);
- _style = style;
+ if( style != _style ) {
+ if (style) sp_style_ref(style);
+ if (_style) sp_style_unref(_style);
+ _style = style;
+ }
}
diff --git a/src/gradient-chemistry.cpp b/src/gradient-chemistry.cpp
index 0701a9d49..cf75f6cf0 100644
--- a/src/gradient-chemistry.cpp
+++ b/src/gradient-chemistry.cpp
@@ -868,9 +868,8 @@ void sp_item_gradient_stop_set_style(SPItem *item, GrPointType point_type, guint
gchar const* color_str = sp_repr_css_property( stop, "stop-color", NULL );
if( color_str ) {
SPColor color( 0 );
- SPStyle* style = sp_style_new(0);
SPIPaint paint;
- paint.read( color_str, *style );
+ paint.read( color_str );
if( paint.isColor() ) {
color = paint.value.color;
}
diff --git a/src/libnrtype/Layout-TNG-Input.cpp b/src/libnrtype/Layout-TNG-Input.cpp
index fa1e8c11b..cd9179c5f 100644
--- a/src/libnrtype/Layout-TNG-Input.cpp
+++ b/src/libnrtype/Layout-TNG-Input.cpp
@@ -325,7 +325,7 @@ PangoFontDescription *Layout::InputStreamTextSource::styleGetFontDescription() c
Layout::InputStreamTextSource::~InputStreamTextSource()
{
- sp_style_unref(style);
+ sp_style_unref(style);
}
}//namespace Text
diff --git a/src/libnrtype/font-lister.cpp b/src/libnrtype/font-lister.cpp
index fad06cd00..a6ab3b239 100644
--- a/src/libnrtype/font-lister.cpp
+++ b/src/libnrtype/font-lister.cpp
@@ -385,27 +385,27 @@ std::pair<Glib::ustring, Glib::ustring> FontLister::selection_update()
#endif
// Get fontspec from a selection, preferences, or thin air.
Glib::ustring fontspec;
- SPStyle *query = sp_style_new(SP_ACTIVE_DOCUMENT);
+ SPStyle query(SP_ACTIVE_DOCUMENT);
// Directly from stored font specification.
int result =
- sp_desktop_query_style(SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONT_SPECIFICATION);
+ sp_desktop_query_style(SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONT_SPECIFICATION);
//std::cout << " Attempting selected style" << std::endl;
- if (result != QUERY_STYLE_NOTHING && query->font_specification.set) {
- fontspec = query->font_specification.value;
+ if (result != QUERY_STYLE_NOTHING && query.font_specification.set) {
+ fontspec = query.font_specification.value;
//std::cout << " fontspec from query :" << fontspec << ":" << std::endl;
}
// From style
if (fontspec.empty()) {
//std::cout << " Attempting desktop style" << std::endl;
- int rfamily = sp_desktop_query_style(SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTFAMILY);
- int rstyle = sp_desktop_query_style(SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTSTYLE);
+ int rfamily = sp_desktop_query_style(SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTFAMILY);
+ int rstyle = sp_desktop_query_style(SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTSTYLE);
// Must have text in selection
if (rfamily != QUERY_STYLE_NOTHING && rstyle != QUERY_STYLE_NOTHING) {
- fontspec = fontspec_from_style(query);
+ fontspec = fontspec_from_style(&query);
}
//std::cout << " fontspec from style :" << fontspec << ":" << std::endl;
}
@@ -413,11 +413,10 @@ std::pair<Glib::ustring, Glib::ustring> FontLister::selection_update()
// From preferences
if (fontspec.empty()) {
//std::cout << " Attempting preferences" << std::endl;
- sp_style_read_from_prefs(query, "/tools/text");
- fontspec = fontspec_from_style(query);
+ query.readFromPrefs("/tools/text");
+ fontspec = fontspec_from_style(&query);
//std::cout << " fontspec from prefs :" << fontspec << ":" << std::endl;
}
- sp_style_unref(query);
// From thin air
if (fontspec.empty()) {
diff --git a/src/path-chemistry.cpp b/src/path-chemistry.cpp
index 238527465..5f6e1495b 100644
--- a/src/path-chemistry.cpp
+++ b/src/path-chemistry.cpp
@@ -500,11 +500,12 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 /*text_grouping_policy*/)
/* Rotation center */
g_repr->setAttribute("inkscape:transform-center-x", item->getRepr()->attribute("inkscape:transform-center-x"), false);
g_repr->setAttribute("inkscape:transform-center-y", item->getRepr()->attribute("inkscape:transform-center-y"), false);
+
/* Whole text's style */
- gchar *style_str = sp_style_write_difference(item->style,
- item->parent ? item->parent->style : NULL); // TODO investigate posibility
- g_repr->setAttribute("style", style_str);
- g_free(style_str);
+ Glib::ustring style_str =
+ item->style->write( SP_STYLE_FLAG_IFDIFF, item->parent ? item->parent->style : NULL); // TODO investigate posibility
+ g_repr->setAttribute("style", style_str.c_str());
+
Inkscape::Text::Layout::iterator iter = te_get_layout(item)->begin();
do {
Inkscape::Text::Layout::iterator iter_next = iter;
@@ -522,19 +523,17 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 /*text_grouping_policy*/)
while (dynamic_cast<SPString const *>(pos_obj) && pos_obj->parent) {
pos_obj = pos_obj->parent; // SPStrings don't have style
}
- gchar *style_str = sp_style_write_difference(pos_obj->style,
- pos_obj->parent ? pos_obj->parent->style : NULL); // TODO investigate posibility
+ Glib::ustring style_str =
+ pos_obj->style->write( SP_STYLE_FLAG_IFDIFF, pos_obj->parent ? pos_obj->parent->style : NULL); // TODO investigate posibility
// get path from iter to iter_next:
SPCurve *curve = te_get_layout(item)->convertToCurves(iter, iter_next);
iter = iter_next; // shift to next glyph
if (!curve) { // error converting this glyph
- g_free (style_str);
continue;
}
if (curve->is_empty()) { // whitespace glyph?
curve->unref();
- g_free (style_str);
continue;
}
@@ -545,8 +544,7 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 /*text_grouping_policy*/)
g_free(def_str);
curve->unref();
- p_repr->setAttribute("style", style_str);
- g_free(style_str);
+ p_repr->setAttribute("style", style_str.c_str());
g_repr->appendChild(p_repr);
Inkscape::GC::release(p_repr);
@@ -565,7 +563,7 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 /*text_grouping_policy*/)
if (shape) {
curve = shape->getCurve();
}
- }
+ }
if (!curve)
return NULL;
@@ -581,11 +579,11 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 /*text_grouping_policy*/)
Inkscape::XML::Node *repr = xml_doc->createElement("svg:path");
/* Transformation */
repr->setAttribute("transform", item->getRepr()->attribute("transform"));
+
/* Style */
- gchar *style_str = sp_style_write_difference(item->style,
- item->parent ? item->parent->style : NULL); // TODO investigate posibility
- repr->setAttribute("style", style_str);
- g_free(style_str);
+ Glib::ustring style_str =
+ item->style->write( SP_STYLE_FLAG_IFDIFF, item->parent ? item->parent->style : NULL); // TODO investigate posibility
+ repr->setAttribute("style", style_str.c_str());
/* Mask */
gchar *mask_str = (gchar *) item->getRepr()->attribute("mask");
diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp
index 98ebd1f61..c9837aabe 100644
--- a/src/selection-chemistry.cpp
+++ b/src/selection-chemistry.cpp
@@ -2110,7 +2110,7 @@ GSList *sp_get_same_stroke_style(SPItem *sel, GSList *src, SPSelectStrokeStyleTy
SPStyle *sel_style_for_width = NULL;
if (type == SP_STROKE_STYLE_WIDTH) {
objects = g_slist_prepend(objects, sel);
- sel_style_for_width = sp_style_new (SP_ACTIVE_DOCUMENT);
+ sel_style_for_width = new SPStyle(SP_ACTIVE_DOCUMENT);
objects_query_strokewidth (objects, sel_style_for_width);
}
@@ -2125,11 +2125,11 @@ GSList *sp_get_same_stroke_style(SPItem *sel, GSList *src, SPSelectStrokeStyleTy
if (sel_style->stroke_width.set && iter_style->stroke_width.set) {
GSList *objects = NULL;
objects = g_slist_prepend(objects, iter);
- SPStyle *iter_style_for_width = sp_style_new (SP_ACTIVE_DOCUMENT);
- objects_query_strokewidth (objects, iter_style_for_width);
+ SPStyle tmp_style(SP_ACTIVE_DOCUMENT);
+ objects_query_strokewidth (objects, &tmp_style);
if (sel_style_for_width) {
- match = (sel_style_for_width->stroke_width.computed == iter_style_for_width->stroke_width.computed);
+ match = (sel_style_for_width->stroke_width.computed == tmp_style.stroke_width.computed);
}
g_slist_free(objects);
}
@@ -2161,6 +2161,7 @@ GSList *sp_get_same_stroke_style(SPItem *sel, GSList *src, SPSelectStrokeStyleTy
}
}
+ if( sel_style_for_width != NULL ) delete sel_style_for_width;
g_slist_free(objects);
return matches;
diff --git a/src/sp-clippath.cpp b/src/sp-clippath.cpp
index 8e2e7d7a6..5065f25c3 100644
--- a/src/sp-clippath.cpp
+++ b/src/sp-clippath.cpp
@@ -103,7 +103,7 @@ void SPClipPath::set(unsigned int key, const gchar* value) {
break;
default:
if (SP_ATTRIBUTE_IS_CSS(key)) {
- sp_style_read_from_object(this->style, this);
+ this->style->readFromObject( this );
this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
} else {
SPObjectGroup::set(key, value);
diff --git a/src/sp-flowtext.cpp b/src/sp-flowtext.cpp
index 8d9f87037..6d2385aff 100644
--- a/src/sp-flowtext.cpp
+++ b/src/sp-flowtext.cpp
@@ -525,10 +525,10 @@ Inkscape::XML::Node *SPFlowtext::getAsText()
Glib::ustring::iterator span_text_start_iter;
this->layout.getSourceOfCharacter(it, &rawptr, &span_text_start_iter);
SPObject *source_obj = reinterpret_cast<SPObject *>(rawptr);
- gchar *style_text = sp_style_write_difference((dynamic_cast<SPString *>(source_obj) ? source_obj->parent : source_obj)->style, this->style);
- if (style_text && *style_text) {
- span_tspan->setAttribute("style", style_text);
- g_free(style_text);
+
+ Glib::ustring style_text = (dynamic_cast<SPString *>(source_obj) ? source_obj->parent : source_obj)->style->write( SP_STYLE_FLAG_IFDIFF, this->style);
+ if (!style_text.empty()) {
+ span_tspan->setAttribute("style", style_text.c_str());
}
SPString *str = dynamic_cast<SPString *>(source_obj);
diff --git a/src/sp-hatch-path.cpp b/src/sp-hatch-path.cpp
index 8558b67f2..bc95c246e 100644
--- a/src/sp-hatch-path.cpp
+++ b/src/sp-hatch-path.cpp
@@ -128,7 +128,7 @@ void SPHatchPath::set(unsigned int key, const gchar* value)
default:
if (SP_ATTRIBUTE_IS_CSS(key)) {
- sp_style_read_from_object(style, this);
+ style->readFromObject( this );
requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
} else {
SPObject::set(key, value);
diff --git a/src/sp-hatch.cpp b/src/sp-hatch.cpp
index 4a8707e08..dfecb2250 100644
--- a/src/sp-hatch.cpp
+++ b/src/sp-hatch.cpp
@@ -238,7 +238,7 @@ void SPHatch::set(unsigned int key, const gchar* value)
default:
if (SP_ATTRIBUTE_IS_CSS(key)) {
- sp_style_read_from_object(style, this);
+ style->readFromObject( this );
requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
} else {
SPPaintServer::set(key, value);
diff --git a/src/sp-item-group.cpp b/src/sp-item-group.cpp
index 45e5747d6..acf8b2012 100644
--- a/src/sp-item-group.cpp
+++ b/src/sp-item-group.cpp
@@ -444,7 +444,7 @@ sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done)
// it here _before_ the new transform is set, so as to use the pre-transform bbox
citem->adjust_paint_recursive (Geom::identity(), Geom::identity(), false);
- sp_style_merge_from_dying_parent(child->style, group->style);
+ child->style->merge( group->style );
/*
* fixme: We currently make no allowance for the case where child is cloned
* and the group has any style settings.
@@ -453,9 +453,8 @@ sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done)
* version of inkscape without using the XML editor: we usually apply group
* style changes to children rather than to the group itself.)
*
- * If the group has no style settings, then
- * sp_style_merge_from_dying_parent should be a no-op. Otherwise (i.e. if
- * we change the child's style to compensate for its parent going away)
+ * If the group has no style settings, then style->merge() should be a no-op. Otherwise
+ * (i.e. if we change the child's style to compensate for its parent going away)
* then those changes will typically be reflected in any clones of child,
* whereas we'd prefer for Ungroup not to affect the visual appearance.
*
diff --git a/src/sp-item.cpp b/src/sp-item.cpp
index dbb0380ea..fbb76e971 100644
--- a/src/sp-item.cpp
+++ b/src/sp-item.cpp
@@ -555,7 +555,7 @@ void SPItem::set(unsigned int key, gchar const* value) {
}
default:
if (SP_ATTRIBUTE_IS_CSS(key)) {
- sp_style_read_from_object(object->style, object);
+ style->readFromObject( this );
object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
} else {
SPObject::set(key, value);
diff --git a/src/sp-object.cpp b/src/sp-object.cpp
index 776b020d2..059fa8093 100644
--- a/src/sp-object.cpp
+++ b/src/sp-object.cpp
@@ -130,7 +130,7 @@ SPObject::SPObject()
// vg, g, defs, desc, title, symbol, use, image, switch, path, rect, circle, ellipse, line, polyline,
// polygon, text, tspan, tref, textPath, altGlyph, glyphRef, marker, linearGradient, radialGradient,
// stop, pattern, clipPath, mask, filter, feImage, a, font, glyph, missing-glyph, foreignObject
- this->style = sp_style_new_from_object(this);
+ this->style = new SPStyle( NULL, this ); // Is it necessary to call with "this"?
this->context_style = NULL;
}
@@ -145,6 +145,19 @@ SPObject::~SPObject() {
sp_object_unref(this->_successor, NULL);
this->_successor = NULL;
}
+
+ if( style == NULL ) {
+ // style pointer could be NULL if unreffed too many times.
+ // Conjecture: style pointer is never NULL.
+ std::cerr << "SPObject::~SPObject(): style pointer is NULL" << std::endl;
+ } else if( style->refCount() > 1 ) {
+ // Several classes ref style.
+ // Conjecture: style pointer should be unreffed by other classes before reaching here.
+ std::cerr << "SPObject::~SPObject(): someone else still holding ref to style" << std::endl;
+ sp_style_unref( this->style );
+ } else {
+ delete this->style;
+ }
}
// CPPIFY: make pure virtual
@@ -796,9 +809,10 @@ void SPObject::releaseReferences() {
g_assert(!this->id);
}
- if (this->style) {
- this->style = sp_style_unref(this->style);
- }
+ // style belongs to SPObject, we should not need to unref here.
+ // if (this->style) {
+ // this->style = sp_style_unref(this->style);
+ // }
this->document = NULL;
this->repr = NULL;
@@ -915,7 +929,7 @@ void SPObject::set(unsigned int key, gchar const* value) {
object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
break;
case SP_ATTR_STYLE:
- sp_style_read_from_object(object->style, object);
+ object->style->readFromObject( object );
object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
break;
default:
@@ -1007,9 +1021,8 @@ Inkscape::XML::Node* SPObject::write(Inkscape::XML::Document *doc, Inkscape::XML
repr->setAttribute("inkscape:collect", NULL);
}
- SPStyle const *const obj_style = this->style;
- if (obj_style) {
- gchar *s = sp_style_write_string(obj_style, SP_STYLE_FLAG_IFSET);
+ if (style) {
+ Glib::ustring s = style->write(SP_STYLE_FLAG_IFSET);
// Check for valid attributes. This may be time consuming.
// It is useful, though, for debugging Inkscape code.
@@ -1017,17 +1030,14 @@ Inkscape::XML::Node* SPObject::write(Inkscape::XML::Document *doc, Inkscape::XML
if( prefs->getBool("/options/svgoutput/check_on_editing") ) {
unsigned int flags = sp_attribute_clean_get_prefs();
- Glib::ustring s_cleaned = sp_attribute_clean_style( repr, s, flags );
- g_free( s );
- s = (s_cleaned.empty() ? NULL : g_strdup (s_cleaned.c_str()));
+ Glib::ustring s_cleaned = sp_attribute_clean_style( repr, s.c_str(), flags );
}
- if( s == NULL || strcmp(s,"") == 0 ) {
+ if( s.empty() ) {
repr->setAttribute("style", NULL);
} else {
- repr->setAttribute("style", s);
+ repr->setAttribute("style", s.c_str());
}
- g_free(s);
} else {
/** \todo I'm not sure what to do in this case. Bug #1165868
@@ -1149,7 +1159,7 @@ void SPObject::updateDisplay(SPCtx *ctx, unsigned int flags)
*/
if ((flags & SP_OBJECT_STYLE_MODIFIED_FLAG) && (flags & SP_OBJECT_PARENT_MODIFIED_FLAG)) {
if (this->style && this->parent) {
- sp_style_merge_from_parent(this->style, this->parent->style);
+ style->cascade( this->parent->style );
}
}
diff --git a/src/sp-solid-color.cpp b/src/sp-solid-color.cpp
index 0d6b96b62..72569d8c0 100644
--- a/src/sp-solid-color.cpp
+++ b/src/sp-solid-color.cpp
@@ -53,7 +53,7 @@ void SPSolidColor::build(SPDocument* doc, Inkscape::XML::Node* repr) {
void SPSolidColor::set(unsigned int key, const gchar* value) {
if (SP_ATTRIBUTE_IS_CSS(key)) {
- sp_style_read_from_object(this->style, this);
+ style->readFromObject( this );
this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);
} else {
SPPaintServer::set(key, value);
diff --git a/src/sp-stop.cpp b/src/sp-stop.cpp
index d644a9b4b..3ee467322 100644
--- a/src/sp-stop.cpp
+++ b/src/sp-stop.cpp
@@ -210,16 +210,14 @@ SPStop* SPStop::getPrevStop() {
SPColor SPStop::readStopColor(Glib::ustring const &styleStr, guint32 dfl) {
SPColor color(dfl);
- SPStyle* style = sp_style_new(0);
SPIPaint paint;
- paint.read( styleStr.c_str(), *style );
+
+ paint.read( styleStr.c_str() );
if ( paint.isColor() ) {
color = paint.value.color;
}
- sp_style_unref(style);
-
return color;
}
diff --git a/src/sp-style-elem.cpp b/src/sp-style-elem.cpp
index da17b08d9..668780272 100644
--- a/src/sp-style-elem.cpp
+++ b/src/sp-style-elem.cpp
@@ -319,13 +319,14 @@ void SPStyleElem::read_content() {
//requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
// Style references via class= do not, and actually cannot, use autoupdating URIReferences.
- // Therefore, if an object refers to a stylesheet which has not yet loaded when the object is being loaded
- // (e.g. if the stylesheet is below or inside the object in XML), its class= has no effect (bug 1491639).
- // Below is a partial hack that fixes this for a single case: when the <style> is a child of the object
- // that uses a style from it. It just forces the parent of <style> to reread its style as soon as the stylesheet
- // is fully loaded. Naturally, this won't work if the user of the stylesheet is its grandparent or precedent.
+ // Therefore, if an object refers to a stylesheet which has not yet loaded when the object is
+ // being loaded (e.g. if the stylesheet is below or inside the object in XML), its class= has
+ // no effect (bug 1491639). Below is a partial hack that fixes this for a single case: when
+ // the <style> is a child of the object that uses a style from it. It just forces the parent of
+ // <style> to reread its style as soon as the stylesheet is fully loaded. Naturally, this won't
+ // work if the user of the stylesheet is its grandparent or precedent.
if ( parent ) {
- sp_style_read_from_object(parent->style, parent);
+ parent->style->readFromObject( parent );
}
}
diff --git a/src/sp-tref.cpp b/src/sp-tref.cpp
index 0f6eb106f..6a229e170 100644
--- a/src/sp-tref.cpp
+++ b/src/sp-tref.cpp
@@ -492,12 +492,8 @@ sp_tref_convert_to_tspan(SPObject *obj)
//SPObject * new_string_child = document->getObjectByRepr(new_string_repr);
// Merge style from the tref
- SPStyle *new_tspan_sty = new_tspan->style;
- SPStyle const *tref_sty = tref->style;
- sp_style_merge_from_dying_parent(new_tspan_sty, tref_sty);
- sp_style_merge_from_parent(new_tspan_sty, new_tspan->parent->style);
-
-
+ new_tspan->style->merge( tref->style );
+ new_tspan->style->cascade( new_tspan->parent->style );
new_tspan->updateRepr();
// Hold onto our SPObject and repr for now.
diff --git a/src/sp-use.cpp b/src/sp-use.cpp
index ba3f4a9d7..9b38a91c5 100644
--- a/src/sp-use.cpp
+++ b/src/sp-use.cpp
@@ -664,11 +664,8 @@ SPItem *SPUse::unlink() {
SPObject *unlinked = document->getObjectByRepr(copy);
// Merge style from the use.
- SPStyle *unli_sty = unlinked->style;
- SPStyle const *use_sty = this->style;
- sp_style_merge_from_dying_parent(unli_sty, use_sty);
- sp_style_merge_from_parent(unli_sty, unlinked->parent->style);
-
+ unlinked->style->merge( this->style );
+ unlinked->style->cascade( unlinked->parent->style );
unlinked->updateRepr();
// Hold onto our SPObject and repr for now.
diff --git a/src/style-test.h b/src/style-test.h
index e14ed4db7..cd6769b24 100644
--- a/src/style-test.h
+++ b/src/style-test.h
@@ -214,32 +214,25 @@ public:
for ( gint i = 0; cases[i].src; i++ ) {
// std::cout << "Test one: " << i << std::endl;
- SPStyle *style = sp_style_new(_doc);
- TS_ASSERT(style);
- if ( style ) {
- sp_style_merge_from_style_string( style, cases[i].src );
-
- if ( cases[i].uri ) {
- TSM_ASSERT( cases[i].src, style->fill.value.href );
- if ( style->fill.value.href ) {
- TS_ASSERT_EQUALS( style->fill.value.href->getURI()->toString(), std::string(cases[i].uri) );
- }
- } else {
- TS_ASSERT( !style->fill.value.href || !style->fill.value.href->getObject() );
+ SPStyle style(_doc);
+ style.mergeString( cases[i].src );
+ if ( cases[i].uri ) {
+ TSM_ASSERT( cases[i].src, style.fill.value.href );
+ if ( style.fill.value.href ) {
+ TS_ASSERT_EQUALS( style.fill.value.href->getURI()->toString(), std::string(cases[i].uri) );
}
+ } else {
+ TS_ASSERT( !style.fill.value.href || !style.fill.value.href->getObject() );
+ }
- gchar *str0_set = sp_style_write_string( style, SP_STYLE_FLAG_IFSET );
- //printf("<<%s>>\n", str0_set);
- if ( cases[i].dst ) {
- // std::cout << " " << std::string(str0_set) << " " << std::string(cases[i].dst) << std::endl;
- TS_ASSERT_EQUALS( std::string(str0_set), std::string(cases[i].dst) );
- } else {
- // std::cout << " " << std::string(str0_set) << " " << std::string(cases[i].src) << std::endl;
- TS_ASSERT_EQUALS( std::string(str0_set), std::string(cases[i].src) );
- }
+ std::string str0_set = style.write(SP_STYLE_FLAG_IFSET );
- g_free(str0_set);
- sp_style_unref(style);
+ if ( cases[i].dst ) {
+ // std::cout << " " << str0_set << " " << std::string(cases[i].dst) << std::endl;
+ TS_ASSERT_EQUALS( str0_set, std::string(cases[i].dst) );
+ } else {
+ // std::cout << " " << str0_set << " " << std::string(cases[i].src) << std::endl;
+ TS_ASSERT_EQUALS( str0_set, std::string(cases[i].src) );
}
}
}
@@ -366,26 +359,22 @@ public:
};
for ( gint i = 0; cases[i].src; i++ ) {
// std::cout << "Test two: " << i << std::endl;
- SPStyle *style_src = sp_style_new(_doc);
- TS_ASSERT(style_src);
- SPStyle *style_dst = sp_style_new(_doc);
- TS_ASSERT(style_dst);
-
- if ( style_src && style_dst ) {
- sp_style_merge_from_style_string( style_src, cases[i].src );
- sp_style_merge_from_style_string( style_dst, cases[i].dst );
- // std::cout << "Test:" << std::endl;
- // std::cout << " C: |" << cases[i].src << "| |" << cases[i].dst << "|" << std::endl;
- // std::cout << " S: |" << style_src->write( SP_STYLE_FLAG_IFSET, NULL ) << "| |"
- // << style_dst->write( SP_STYLE_FLAG_IFSET, NULL ) << "|" <<std::endl;
- TS_ASSERT( (*style_src == *style_dst) == cases[i].match );
- sp_style_unref(style_src);
- sp_style_unref(style_dst);
- // std::cout << "End Test\n" << std::endl;
- }
+ SPStyle style_src(_doc);
+ SPStyle style_dst(_doc);
+
+ style_src.mergeString( cases[i].src );
+ style_dst.mergeString( cases[i].dst );
+
+ // std::cout << "Test:" << std::endl;
+ // std::cout << " C: |" << cases[i].src << "| |" << cases[i].dst << "|" << std::endl;
+ // std::cout << " S: |" << style_src.write( SP_STYLE_FLAG_IFSET, NULL ) << "| |"
+ // << style_dst.write( SP_STYLE_FLAG_IFSET, NULL ) << "|" <<std::endl;
+ TS_ASSERT( (style_src == style_dst) == cases[i].match );
+ // std::cout << "End Test\n" << std::endl;
}
}
+
// Test of cascade
void testThree()
{
@@ -477,37 +466,29 @@ public:
};
for ( gint i = 0; cases[i].parent; i++ ) {
// std::cout << "Test three: " << i << std::endl;
- SPStyle *style_parent = sp_style_new(_doc);
- TS_ASSERT(style_parent);
- SPStyle *style_child = sp_style_new(_doc);
- TS_ASSERT(style_child);
- SPStyle *style_result = sp_style_new(_doc);
- TS_ASSERT(style_result);
-
- if ( style_parent && style_child && style_result ) {
- sp_style_merge_from_style_string( style_parent, cases[i].parent );
- sp_style_merge_from_style_string( style_child, cases[i].child );
- sp_style_merge_from_style_string( style_result, cases[i].result );
- // std::cout << "Test:" << std::endl;
- // std::cout << " Input: ";
- // std::cout << " Parent: " << cases[i].parent
- // << " Child: " << cases[i].child
- // << " Result: " << cases[i].result << std::endl;
- // std::cout << " Write: ";
- // std::cout << " Parent: " << style_parent->write( SP_STYLE_FLAG_IFSET )
- // << " Child: " << style_child->write( SP_STYLE_FLAG_IFSET )
- // << " Result: " << style_result->write( SP_STYLE_FLAG_IFSET ) << std::endl;
-
- //sp_style_merge_from_parent( style_child, style_parent );
- style_child->cascade( style_parent );
-
- TS_ASSERT(*style_child == *style_result );
-
- sp_style_unref(style_child);
- sp_style_unref(style_parent);
- sp_style_unref(style_result);
- // std::cout << "End Test: *************\n" << std::endl;
- }
+ SPStyle style_parent(_doc);
+ SPStyle style_child( _doc);
+ SPStyle style_result(_doc);
+
+ style_parent.mergeString( cases[i].parent );
+ style_child.mergeString( cases[i].child );
+ style_result.mergeString( cases[i].result );
+
+ // std::cout << "Test:" << std::endl;
+ // std::cout << " Input: ";
+ // std::cout << " Parent: " << cases[i].parent
+ // << " Child: " << cases[i].child
+ // << " Result: " << cases[i].result << std::endl;
+ // std::cout << " Write: ";
+ // std::cout << " Parent: " << style_parent.write( SP_STYLE_FLAG_IFSET )
+ // << " Child: " << style_child.write( SP_STYLE_FLAG_IFSET )
+ // << " Result: " << style_result.write( SP_STYLE_FLAG_IFSET ) << std::endl;
+
+ style_child.cascade( &style_parent );
+
+ TS_ASSERT(style_child == style_result );
+
+ // std::cout << "End Test: *************\n" << std::endl;
}
}
diff --git a/src/style.cpp b/src/style.cpp
index a7e50b17a..0772a4bce 100644
--- a/src/style.cpp
+++ b/src/style.cpp
@@ -458,7 +458,14 @@ SPStyle::~SPStyle() {
_properties.clear();
- // std::cout << "SPStyle::~SPstyle(): Exit\n" << std::endl;
+ // Conjecture: all this SPStyle ref counting is not needed. SPObject creates an instance of
+ // SPStyle when it is constructed and deletes it when it is destructed. The refcount is
+ // incremented and decremented only in the files: display/drawing-item.cpp,
+ // display/nr-filter-primitive.cpp, and libnrtype/Layout-TNG-Input.cpp.
+ if( _refcount > 1 ) {
+ std::cerr << "SPStyle::~SPStyle: ref count greater than 1! " << _refcount << std::endl;
+ }
+ // std::cout << "SPStyle::~SPStyle(): Exit\n" << std::endl;
}
// Used in SPStyle::clear()
@@ -476,7 +483,7 @@ SPStyle::clear() {
// (this->*(i->second)).clear();
// }
- // Release connection to object, created in sp_style_new_from_object()
+ // Release connection to object, created in constructor.
release_connection.disconnect();
// href->detach() called in fill->clear()...
@@ -576,7 +583,13 @@ SPStyle::read( SPObject *object, Inkscape::XML::Node *repr ) {
}
}
-// Matches void sp_style_read_from_object(SPStyle *style, SPObject *object);
+/**
+ * Read style properties from object's repr.
+ *
+ * 1. Reset existing object style
+ * 2. Load current effective object style
+ * 3. Load i attributes from immediate parent (which has to be up-to-date)
+ */
void
SPStyle::readFromObject( SPObject *object ) {
@@ -591,6 +604,34 @@ SPStyle::readFromObject( SPObject *object ) {
read( object, repr );
}
+/**
+ * Read style properties from preferences.
+ * @param path Preferences directory from which the style should be read
+ */
+void
+SPStyle::readFromPrefs(Glib::ustring const &path) {
+
+ g_return_if_fail(!path.empty());
+
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+
+ // not optimal: we reconstruct the node based on the prefs, then pass it to
+ // sp_style_read for actual processing.
+ Inkscape::XML::SimpleDocument *tempdoc = new Inkscape::XML::SimpleDocument;
+ Inkscape::XML::Node *tempnode = tempdoc->createElement("prefs");
+
+ std::vector<Inkscape::Preferences::Entry> attrs = prefs->getAllEntries(path);
+ for (std::vector<Inkscape::Preferences::Entry>::iterator i = attrs.begin(); i != attrs.end(); ++i) {
+ tempnode->setAttribute(i->getEntryName().data(), i->getString().data());
+ }
+
+ read( NULL, tempnode );
+
+ Inkscape::GC::release(tempnode);
+ Inkscape::GC::release(tempdoc);
+ delete tempdoc;
+}
+
// Matches sp_style_merge_property(SPStyle *style, gint id, gchar const *val)
void
SPStyle::readIfUnset( gint id, gchar const *val ) {
@@ -868,6 +909,19 @@ SPStyle::readIfUnset( gint id, gchar const *val ) {
}
}
+/**
+ * Outputs the style to a CSS string.
+ *
+ * Use with SP_STYLE_FLAG_ALWAYS for copying an object's complete cascaded style to
+ * style_clipboard.
+ *
+ * Use with SP_STYLE_FLAG_IFDIFF and a pointer to the parent class when you need a CSS string for
+ * an object in the document tree.
+ *
+ * \pre flags in {IFSET, ALWAYS, IFDIFF}.
+ * \pre base.
+ * \post ret != NULL.
+ */
Glib::ustring
SPStyle::write( guint const flags, SPStyle const *const base ) const {
@@ -897,9 +951,20 @@ SPStyle::write( guint const flags, SPStyle const *const base ) const {
}
// Corresponds to sp_style_merge_from_parent()
+/**
+ * Sets computed values in \a style, which may involve inheriting from (or in some other way
+ * calculating from) corresponding computed values of \a parent.
+ *
+ * References: http://www.w3.org/TR/SVG11/propidx.html shows what properties inherit by default.
+ * http://www.w3.org/TR/SVG11/styling.html#Inheritance gives general rules as to what it means to
+ * inherit a value. http://www.w3.org/TR/REC-CSS2/cascade.html#computed-value is more precise
+ * about what the computed value is (not obvious for lengths).
+ *
+ * \pre \a parent's computed values are already up-to-date.
+ */
void
SPStyle::cascade( SPStyle const *const parent ) {
- // std::cout << "SPStyle::cascade" << std::endl;
+ // std::cout << "SPStyle::cascade: " << (object->getId()?object->getId():"null") << std::endl;
for(std::vector<SPIBase*>::size_type i = 0; i != _properties.size(); ++i) {
_properties[i]->cascade( parent->_properties[i] );
}
@@ -909,6 +974,23 @@ SPStyle::cascade( SPStyle const *const parent ) {
}
// Corresponds to sp_style_merge_from_dying_parent()
+/**
+ * Combine \a style and \a parent style specifications into a single style specification that
+ * preserves (as much as possible) the effect of the existing \a style being a child of \a parent.
+ *
+ * Called when the parent repr is to be removed (e.g. the parent is a \<use\> element that is being
+ * unlinked), in which case we copy/adapt property values that are explicitly set in \a parent,
+ * trying to retain the same visual appearance once the parent is removed. Interesting cases are
+ * when there is unusual interaction with the parent's value (opacity, display) or when the value
+ * can be specified as relative to the parent computed value (font-size, font-weight etc.).
+ *
+ * Doesn't update computed values of \a style. For correctness, you should subsequently call
+ * sp_style_merge_from_parent against the new parent (presumably \a parent's parent) even if \a
+ * style was previously up-to-date wrt \a parent.
+ *
+ * \pre \a parent's computed values are already up-to-date.
+ * (\a style's computed values needn't be up-to-date.)
+ */
void
SPStyle::merge( SPStyle const *const parent ) {
// std::cout << "SPStyle::merge" << std::endl;
@@ -920,6 +1002,14 @@ SPStyle::merge( SPStyle const *const parent ) {
// }
}
+/**
+ * Parses a style="..." string and merges it with an existing SPStyle.
+ */
+void
+SPStyle::mergeString( gchar const *const p ) {
+ _mergeString( p );
+}
+
// Mostly for unit testing
bool
SPStyle::operator==(const SPStyle& rhs) {
@@ -1142,35 +1232,6 @@ sp_style_stroke_paint_server_ref_changed(SPObject *old_ref, SPObject *ref, SPSty
sp_style_paint_server_ref_modified(ref, 0, style);
}
-// Called in: desktop-style.cpp, gradient-chemistry.cpp, sp-object.cpp, sp-stop.cpp, style.cpp
-// text-editing.cpp, libnrtype/font-lister.cpp, widgets/dash-selector.cpp, widgets/fill-style.cpp,
-// widgets/stroke-style.cpp, widgets/text-toolbar.cpp, ui/dialog/glyphs.cpp, ui/dialog/swatches.cpp,
-// ui/dialog/swatches.cpp, ui/dialog/text-edit.cpp. ui/tools/freehand-base.cpp,
-// ui/widget/object-composite-settings.cpp, ui/widget/selected-style.cpp, ui/widget/style-swatch.cpp
-/**
- * Returns a new SPStyle object with default settings.
- */
-SPStyle *
-sp_style_new(SPDocument *document)
-{
- SPStyle *const style = new SPStyle( document );
- return style;
-}
-
-// Called in: sp-object.cpp
-/**
- * Creates a new SPStyle object, and attaches it to the specified SPObject.
- */
-SPStyle *
-sp_style_new_from_object(SPObject *object)
-{
- g_return_val_if_fail(object != NULL, NULL);
- g_return_val_if_fail(SP_IS_OBJECT(object), NULL);
-
- SPStyle *const style = new SPStyle( NULL, object );
- return style;
-}
-
// Called in display/drawing-item.cpp, display/nr-filter-primitive.cpp, libnrtype/Layout-TNG-Input.cpp
/**
* Increase refcount of style.
@@ -1180,13 +1241,12 @@ sp_style_ref(SPStyle *style)
{
g_return_val_if_fail(style != NULL, NULL);
- style->ref(); // Increase ref count
+ style->style_ref(); // Increase ref count
return style;
}
-// Called in style.cpp, desktop-style.cpp, sp-object.cpp, sp-stop.cpp, text-editing.cpp
-// display/drawing-group.cpp, ...
+// Called in display/drawing-item.cpp, display/nr-filter-primitive.cpp, libnrtype/Layout-TNG-Input.cpp
/**
* Decrease refcount of style with possible destruction.
*/
@@ -1194,71 +1254,13 @@ SPStyle *
sp_style_unref(SPStyle *style)
{
g_return_val_if_fail(style != NULL, NULL);
- if (style->unref() < 1) {
+ if (style->style_unref() < 1) {
delete style;
return NULL;
}
return style;
}
-
-
-// Called in: sp-clippath.cpp, sp-item.cpp (suspicious), sp-object.cpp, sp-style-elem.cpp
-/**
- * Read style properties from object's repr.
- *
- * 1. Reset existing object style
- * 2. Load current effective object style
- * 3. Load i attributes from immediate parent (which has to be up-to-date)
- */
-void
-sp_style_read_from_object(SPStyle *style, SPObject *object)
-{
- // std::cout << "sp_style_read_from_object: " << (object->getId()?object->getId():"null") << std::endl;
- g_return_if_fail(style != NULL);
- g_return_if_fail(object != NULL);
- g_return_if_fail(SP_IS_OBJECT(object));
-
- Inkscape::XML::Node *repr = object->getRepr();
- g_return_if_fail(repr != NULL);
-
- style->read( object, repr );
-}
-
-// Called in: libnrtype/font-lister.cpp, widgets/dash-selector.cpp, widgets/text-toolbar.cpp,
-// ui/dialog/text-edit.cpp
-// Why is this called when draging a gradient handle?
-/**
- * Read style properties from preferences.
- * @param style The style to write to
- * @param path Preferences directory from which the style should be read
- */
-void
-sp_style_read_from_prefs(SPStyle *style, Glib::ustring const &path)
-{
- g_return_if_fail(style != NULL);
- g_return_if_fail(path != "");
-
- Inkscape::Preferences *prefs = Inkscape::Preferences::get();
-
- // not optimal: we reconstruct the node based on the prefs, then pass it to
- // sp_style_read for actual processing.
- Inkscape::XML::SimpleDocument *tempdoc = new Inkscape::XML::SimpleDocument;
- Inkscape::XML::Node *tempnode = tempdoc->createElement("prefs");
-
- std::vector<Inkscape::Preferences::Entry> attrs = prefs->getAllEntries(path);
- for (std::vector<Inkscape::Preferences::Entry>::iterator i = attrs.begin(); i != attrs.end(); ++i) {
- tempnode->setAttribute(i->getEntryName().data(), i->getString().data());
- }
-
- style->read( NULL, tempnode );
-
- Inkscape::GC::release(tempnode);
- Inkscape::GC::release(tempdoc);
- delete tempdoc;
-}
-
-
static CRSelEng *
sp_repr_sel_eng()
{
@@ -1282,81 +1284,9 @@ sp_repr_sel_eng()
return ret;
}
-
-// Called in text-editting.cpp, ui/tools/frehand-base.cpp, ui/widget/style-swatch.cpp
-/**
- * Parses a style="..." string and merges it with an existing SPStyle.
- */
-void
-sp_style_merge_from_style_string(SPStyle *const style, gchar const *const p)
-{
- // std::cout << "sp_style_merge_from_style_string: " << (p?p:"null") <<std::endl;
- /*
- * Reference: http://www.w3.org/TR/SVG11/styling.html#StyleAttribute:
- * ``When CSS styling is used, CSS inline style is specified by including
- * semicolon-separated property declarations of the form "name : value"
- * within the style attribute''.
- *
- * That's fairly ambiguous. Is a `value' allowed to contain semicolons?
- * Why does it say "including", what else is allowed in the style
- * attribute value?
- */
- style->_mergeString( p );
-}
-
/** Indexed by SP_CSS_FONT_SIZE_blah. These seem a bit small */
static float const font_size_table[] = {6.0, 8.0, 10.0, 12.0, 14.0, 18.0, 24.0};
-// Called in sp-object.cpp, sp-tref.cpp, sp-use.cpp
-/**
- * Sets computed values in \a style, which may involve inheriting from (or in some other way
- * calculating from) corresponding computed values of \a parent.
- *
- * References: http://www.w3.org/TR/SVG11/propidx.html shows what properties inherit by default.
- * http://www.w3.org/TR/SVG11/styling.html#Inheritance gives general rules as to what it means to
- * inherit a value. http://www.w3.org/TR/REC-CSS2/cascade.html#computed-value is more precise
- * about what the computed value is (not obvious for lengths).
- *
- * \pre \a parent's computed values are already up-to-date.
- */
-void
-sp_style_merge_from_parent(SPStyle *const style, SPStyle const *const parent)
-{
- // std::cout << "sp_style_merge_from_parent" << std::endl;
- g_return_if_fail(style != NULL);
-
- if (!parent)
- return;
-
- style->cascade( parent );
- return;
-}
-
-// Called in: sp-use.cpp, sp-tref.cpp, sp-item.cpp
-/**
- * Combine \a style and \a parent style specifications into a single style specification that
- * preserves (as much as possible) the effect of the existing \a style being a child of \a parent.
- *
- * Called when the parent repr is to be removed (e.g. the parent is a \<use\> element that is being
- * unlinked), in which case we copy/adapt property values that are explicitly set in \a parent,
- * trying to retain the same visual appearance once the parent is removed. Interesting cases are
- * when there is unusual interaction with the parent's value (opacity, display) or when the value
- * can be specified as relative to the parent computed value (font-size, font-weight etc.).
- *
- * Doesn't update computed values of \a style. For correctness, you should subsequently call
- * sp_style_merge_from_parent against the new parent (presumably \a parent's parent) even if \a
- * style was previously up-to-date wrt \a parent.
- *
- * \pre \a parent's computed values are already up-to-date.
- * (\a style's computed values needn't be up-to-date.)
- */
-void
-sp_style_merge_from_dying_parent(SPStyle *const style, SPStyle const *const parent)
-{
- // std::cout << "sp_style_merge_from_dying_parent" << std::endl;
- style->merge( parent );
-}
-
// The following functions should be incorporated into SPIPaint. FIXME
// Called in: style.cpp, style-internal.cpp
void
@@ -1473,50 +1403,6 @@ sp_style_css_size_units_to_px(double size, int unit)
return size * (size / sp_style_css_size_px_to_units(size, unit));;
}
-// Called in style.cpp, text-editing.cpp
-/**
- * Dumps the style to a CSS string, with either SP_STYLE_FLAG_IFSET or
- * SP_STYLE_FLAG_ALWAYS flags. Used with Always for copying an object's
- * complete cascaded style to style_clipboard. When you need a CSS string
- * for an object in the document tree, you normally call
- * sp_style_write_difference instead to take into account the object's parent.
- *
- * \pre style != NULL.
- * \pre flags in {IFSET, ALWAYS}.
- * \post ret != NULL.
- */
-gchar *
-sp_style_write_string(SPStyle const *const style, guint const flags)
-{
- /** \todo
- * Merge with write_difference, much duplicate code!
- */
- g_return_val_if_fail(style != NULL, NULL);
- g_return_val_if_fail(((flags == SP_STYLE_FLAG_IFSET) ||
- (flags == SP_STYLE_FLAG_ALWAYS) ),
- NULL);
-
- return g_strdup( style->write( flags ).c_str() );
-}
-
-
-// Called in style.cpp, path-chemistry, NOT in text-editting.cpp (because of bug)
-/**
- * Dumps style to CSS string, see sp_style_write_string()
- *
- * \pre from != NULL.
- * \pre to != NULL.
- * \post ret != NULL.
- */
-gchar *
-sp_style_write_difference(SPStyle const *const from, SPStyle const *const to)
-{
- g_return_val_if_fail(from != NULL, NULL);
- g_return_val_if_fail(to != NULL, NULL);
-
- return g_strdup( from->write( SP_STYLE_FLAG_IFDIFF, to ).c_str() );
-}
-
// FIXME: Everything below this line belongs in a different file - css-chemistry?
@@ -1677,10 +1563,9 @@ sp_css_attr_from_style(SPStyle const *const style, guint const flags)
g_return_val_if_fail(((flags == SP_STYLE_FLAG_IFSET) ||
(flags == SP_STYLE_FLAG_ALWAYS) ),
NULL);
- gchar *style_str = sp_style_write_string(style, flags);
+ Glib::ustring style_str = style->write(flags);
SPCSSAttr *css = sp_repr_css_attr_new();
- sp_repr_css_attr_add_from_string(css, style_str);
- g_free(style_str);
+ sp_repr_css_attr_add_from_string(css, style_str.c_str());
return css;
}
diff --git a/src/style.h b/src/style.h
index 1b1596458..3f21f37db 100644
--- a/src/style.h
+++ b/src/style.h
@@ -51,18 +51,19 @@ public:
void readFromObject(SPObject *object);
void readFromPrefs(Glib::ustring const &path);
void readIfUnset( int id, char const *val );
- Glib::ustring write( unsigned int const flags, SPStyle const *const base = NULL ) const;
+ Glib::ustring write( unsigned int const flags = SP_STYLE_FLAG_IFSET,
+ SPStyle const *const base = NULL ) const;
void cascade( SPStyle const *const parent );
void merge( SPStyle const *const parent );
+ void mergeString( char const *const p );
bool operator==(const SPStyle& rhs);
- int ref() { ++_refcount; return _refcount; }
- int unref() { --_refcount; return _refcount; }
+ int style_ref() { ++_refcount; return _refcount; }
+ int style_unref() { --_refcount; return _refcount; }
+ int refCount() { return _refcount; }
-//FIXME: Make private
-public:
- void _mergeString( char const *const p ); // Rename to readFromString?
private:
+ void _mergeString( char const *const p );
void _mergeDeclList( CRDeclaration const *const decl_list );
void _mergeDecl( CRDeclaration const *const decl );
void _mergeProps( CRPropList *const props );
@@ -282,28 +283,10 @@ public:
char const *getStrokeURI() const { return (stroke.value.href) ? stroke.value.href->getURI()->toString() : NULL; }
};
-SPStyle *sp_style_new(SPDocument *document); // SPStyle::SPStyle( SPDocument *document = NULL );
-
-SPStyle *sp_style_new_from_object(SPObject *object); // SPStyle::SPStyle( SPObject *object );
-
SPStyle *sp_style_ref(SPStyle *style); // SPStyle::ref();
SPStyle *sp_style_unref(SPStyle *style); // SPStyle::unref();
-void sp_style_read_from_object(SPStyle *style, SPObject *object); //SPStyle::read( SPObject * object);
-
-void sp_style_read_from_prefs(SPStyle *style, Glib::ustring const &path); // SPStyle::read( ... );
-
-void sp_style_merge_from_style_string(SPStyle *style, char const *p); // SPStyle::merge( ... );?
-
-void sp_style_merge_from_parent(SPStyle *style, SPStyle const *parent); // SPStyle::cascade( ... );
-
-void sp_style_merge_from_dying_parent(SPStyle *style, SPStyle const *parent); // SPStyle::merge( ... )
-
-char *sp_style_write_string(SPStyle const *style, unsigned int flags = SP_STYLE_FLAG_IFSET);//SPStyle::write
-
-char *sp_style_write_difference(SPStyle const *from, SPStyle const *to); // SPStyle::write
-
void sp_style_set_to_uri_string (SPStyle *style, bool isfill, const char *uri); // ?
char const *sp_style_get_css_unit_string(int unit); // No change?
diff --git a/src/text-editing.cpp b/src/text-editing.cpp
index 47964880c..4a962ab4c 100644
--- a/src/text-editing.cpp
+++ b/src/text-editing.cpp
@@ -1321,23 +1321,23 @@ static unsigned char_index_of_iterator(Glib::ustring const &string, Glib::ustrin
return n;
}
+// Move to style.h?
/** applies the given style string on top of the existing styles for \a item,
as opposed to sp_style_merge_from_style_string which merges its parameter
underneath the existing styles (ie ignoring already set properties). */
static void overwrite_style_with_string(SPObject *item, gchar const *style_string)
{
- SPStyle *new_style = sp_style_new(item->document);
- sp_style_merge_from_style_string(new_style, style_string);
+ SPStyle style(item->document);
+ style.mergeString(style_string);
gchar const *item_style_string = item->getRepr()->attribute("style");
if (item_style_string && *item_style_string) {
- sp_style_merge_from_style_string(new_style, item_style_string);
+ style.mergeString(item_style_string);
}
- gchar *new_style_string = sp_style_write_string(new_style);
- sp_style_unref(new_style);
- item->getRepr()->setAttribute("style", new_style_string && *new_style_string ? new_style_string : NULL);
- g_free(new_style_string);
+ Glib::ustring new_style_string = style.write();
+ item->getRepr()->setAttribute("style", new_style_string.empty() ? NULL : new_style_string.c_str());
}
+// Move to style.h?
/** Returns true if the style of \a parent and the style of \a child are
equivalent (and hence the children of both will appear the same). It is a
limitation of the current implementation that \a parent must be a (not
@@ -1349,14 +1349,14 @@ static bool objects_have_equal_style(SPObject const *parent, SPObject const *chi
// implications too large for me to feel safe fixing, but mainly because the css spec
// requires that the computed value is inherited, not the specified value.
g_assert(parent->isAncestorOf(child));
- gchar *parent_style = sp_style_write_string(parent->style, SP_STYLE_FLAG_ALWAYS);
+
+ Glib::ustring parent_style = parent->style->write( SP_STYLE_FLAG_ALWAYS );
+
// we have to write parent_style then read it again, because some properties format their values
// differently depending on whether they're set or not (*cough*dash-offset*cough*)
- SPStyle *parent_spstyle = sp_style_new(parent->document);
- sp_style_merge_from_style_string(parent_spstyle, parent_style);
- g_free(parent_style);
- parent_style = sp_style_write_string(parent_spstyle, SP_STYLE_FLAG_ALWAYS);
- sp_style_unref(parent_spstyle);
+ SPStyle parent_spstyle(parent->document);
+ parent_spstyle.mergeString(parent_style.c_str());
+ parent_style = parent_spstyle.write(SP_STYLE_FLAG_ALWAYS);
Glib::ustring child_style_construction;
while (child != parent) {
@@ -1369,13 +1369,12 @@ static bool objects_have_equal_style(SPObject const *parent, SPObject const *chi
child = child->parent;
}
child_style_construction.insert(0, parent_style);
- SPStyle *child_spstyle = sp_style_new(parent->document);
- sp_style_merge_from_style_string(child_spstyle, child_style_construction.c_str());
- gchar *child_style = sp_style_write_string(child_spstyle, SP_STYLE_FLAG_ALWAYS);
- sp_style_unref(child_spstyle);
- bool equal = !strcmp(child_style, parent_style);
- g_free(child_style);
- g_free(parent_style);
+
+ SPStyle child_spstyle(parent->document);
+ child_spstyle.mergeString(child_style_construction.c_str());
+ Glib::ustring child_style = child_spstyle.write(SP_STYLE_FLAG_ALWAYS);
+
+ bool equal = (child_style == parent_style); // Glib::ustring overloads == operator
return equal;
}
diff --git a/src/ui/dialog/glyphs.cpp b/src/ui/dialog/glyphs.cpp
index 9bad90e7c..2b9053da9 100644
--- a/src/ui/dialog/glyphs.cpp
+++ b/src/ui/dialog/glyphs.cpp
@@ -709,13 +709,12 @@ void GlyphsPanel::readSelection( bool updateStyle, bool /*updateContent*/ )
calcCanInsert();
if (targetDesktop && updateStyle) {
- //SPStyle *query = sp_style_new(SP_ACTIVE_DOCUMENT);
+ //SPStyle query(SP_ACTIVE_DOCUMENT);
- //int result_family = sp_desktop_query_style(targetDesktop, query, QUERY_STYLE_PROPERTY_FONTFAMILY);
- //int result_style = sp_desktop_query_style(targetDesktop, query, QUERY_STYLE_PROPERTY_FONTSTYLE);
- //int result_numbers = sp_desktop_query_style(targetDesktop, query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
+ //int result_family = sp_desktop_query_style(targetDesktop, &query, QUERY_STYLE_PROPERTY_FONTFAMILY);
+ //int result_style = sp_desktop_query_style(targetDesktop, &query, QUERY_STYLE_PROPERTY_FONTSTYLE);
+ //int result_numbers = sp_desktop_query_style(targetDesktop, &query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
- //sp_style_unref(query);
}
}
diff --git a/src/ui/dialog/swatches.cpp b/src/ui/dialog/swatches.cpp
index 772217fcd..8759039c3 100644
--- a/src/ui/dialog/swatches.cpp
+++ b/src/ui/dialog/swatches.cpp
@@ -125,12 +125,12 @@ static void editGradientImpl( SPDesktop* desktop, SPGradient* gr )
Inkscape::Selection *selection = desktop->getSelection();
GSList const *items = selection->itemList();
if (items) {
- SPStyle *query = sp_style_new( desktop->doc() );
- int result = objects_query_fillstroke(const_cast<GSList *>(items), query, true);
+ SPStyle query( desktop->doc() );
+ int result = objects_query_fillstroke(const_cast<GSList *>(items), &query, true);
if ( (result == QUERY_STYLE_MULTIPLE_SAME) || (result == QUERY_STYLE_SINGLE) ) {
// could be pertinent
- if (query->fill.isPaintserver()) {
- SPPaintServer* server = query->getFillPaintServer();
+ if (query.fill.isPaintserver()) {
+ SPPaintServer* server = query.getFillPaintServer();
if ( SP_IS_GRADIENT(server) ) {
SPGradient* grad = SP_GRADIENT(server);
if ( grad->isSwatch() && grad->getId() == gr->getId()) {
@@ -140,7 +140,6 @@ static void editGradientImpl( SPDesktop* desktop, SPGradient* gr )
}
}
}
- sp_style_unref(query);
}
}
@@ -1061,15 +1060,15 @@ void SwatchesPanel::_updateFromSelection()
Glib::ustring fillId;
Glib::ustring strokeId;
- SPStyle *tmpStyle = sp_style_new(_currentDesktop->getDocument());
- int result = sp_desktop_query_style( _currentDesktop, tmpStyle, QUERY_STYLE_PROPERTY_FILL );
+ SPStyle tmpStyle(_currentDesktop->getDocument());
+ int result = sp_desktop_query_style( _currentDesktop, &tmpStyle, QUERY_STYLE_PROPERTY_FILL );
switch (result) {
case QUERY_STYLE_SINGLE:
case QUERY_STYLE_MULTIPLE_AVERAGED:
case QUERY_STYLE_MULTIPLE_SAME:
{
- if (tmpStyle->fill.set && tmpStyle->fill.isPaintserver()) {
- SPPaintServer* server = tmpStyle->getFillPaintServer();
+ if (tmpStyle.fill.set && tmpStyle.fill.isPaintserver()) {
+ SPPaintServer* server = tmpStyle.getFillPaintServer();
if ( SP_IS_GRADIENT(server) ) {
SPGradient* target = 0;
SPGradient* grad = SP_GRADIENT(server);
@@ -1095,14 +1094,14 @@ void SwatchesPanel::_updateFromSelection()
}
}
- result = sp_desktop_query_style( _currentDesktop, tmpStyle, QUERY_STYLE_PROPERTY_STROKE );
+ result = sp_desktop_query_style( _currentDesktop, &tmpStyle, QUERY_STYLE_PROPERTY_STROKE );
switch (result) {
case QUERY_STYLE_SINGLE:
case QUERY_STYLE_MULTIPLE_AVERAGED:
case QUERY_STYLE_MULTIPLE_SAME:
{
- if (tmpStyle->stroke.set && tmpStyle->stroke.isPaintserver()) {
- SPPaintServer* server = tmpStyle->getStrokePaintServer();
+ if (tmpStyle.stroke.set && tmpStyle.stroke.isPaintserver()) {
+ SPPaintServer* server = tmpStyle.getStrokePaintServer();
if ( SP_IS_GRADIENT(server) ) {
SPGradient* target = 0;
SPGradient* grad = SP_GRADIENT(server);
@@ -1126,7 +1125,6 @@ void SwatchesPanel::_updateFromSelection()
break;
}
}
- sp_style_unref(tmpStyle);
for ( boost::ptr_vector<ColorItem>::iterator it = docPalette->_colors.begin(); it != docPalette->_colors.end(); ++it ) {
ColorItem* item = &*it;
diff --git a/src/ui/dialog/text-edit.cpp b/src/ui/dialog/text-edit.cpp
index 229e82af4..a8be8b543 100644
--- a/src/ui/dialog/text-edit.cpp
+++ b/src/ui/dialog/text-edit.cpp
@@ -325,18 +325,18 @@ void TextEdit::onReadSelection ( gboolean dostyle, gboolean /*docontent*/ )
if (dostyle) {
// create temporary style
- SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT);
+ SPStyle query(SP_ACTIVE_DOCUMENT);
// query style from desktop into it. This returns a result flag and fills query with the style of subselection, if any, or selection
- //int result_fontspec = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONT_SPECIFICATION);
- int result_family = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTFAMILY);
- int result_style = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTSTYLE);
- int result_numbers = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
+ //int result_fontspec = sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONT_SPECIFICATION);
+ int result_family = sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTFAMILY);
+ int result_style = sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTSTYLE);
+ int result_numbers = sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
// If querying returned nothing, read the style from the text tool prefs (default style for new texts)
// (Ok to not get a font specification - must just rely on the family and style in that case)
if (result_family == QUERY_STYLE_NOTHING || result_style == QUERY_STYLE_NOTHING
|| result_numbers == QUERY_STYLE_NOTHING) {
- sp_style_read_from_prefs(query, "/tools/text");
+ query.readFromPrefs("/tools/text");
}
// FIXME: process result_family/style == QUERY_STYLE_MULTIPLE_DIFFERENT by showing "Many" in the lists
@@ -351,40 +351,39 @@ void TextEdit::onReadSelection ( gboolean dostyle, gboolean /*docontent*/ )
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT);
- double size = sp_style_css_size_px_to_units(query->font_size.computed, unit);
+ double size = sp_style_css_size_px_to_units(query.font_size.computed, unit);
sp_font_selector_set_fontspec(fsel, fontspec, size );
setPreviewText (fontspec, phrase);
- if (query->text_anchor.computed == SP_CSS_TEXT_ANCHOR_START) {
- if (query->text_align.computed == SP_CSS_TEXT_ALIGN_JUSTIFY) {
+ if (query.text_anchor.computed == SP_CSS_TEXT_ANCHOR_START) {
+ if (query.text_align.computed == SP_CSS_TEXT_ALIGN_JUSTIFY) {
align_justify.set_active();
} else {
align_left.set_active();
}
- } else if (query->text_anchor.computed == SP_CSS_TEXT_ANCHOR_MIDDLE) {
+ } else if (query.text_anchor.computed == SP_CSS_TEXT_ANCHOR_MIDDLE) {
align_center.set_active();
} else {
align_right.set_active();
}
- if (query->writing_mode.computed == SP_CSS_WRITING_MODE_LR_TB) {
+ if (query.writing_mode.computed == SP_CSS_WRITING_MODE_LR_TB) {
text_horizontal.set_active();
} else {
text_vertical.set_active();
}
double height;
- if (query->line_height.normal) height = Inkscape::Text::Layout::LINE_HEIGHT_NORMAL;
- else if (query->line_height.unit == SP_CSS_UNIT_PERCENT)
- height = query->line_height.value;
- else height = query->line_height.computed;
+ if (query.line_height.normal) height = Inkscape::Text::Layout::LINE_HEIGHT_NORMAL;
+ else if (query.line_height.unit == SP_CSS_UNIT_PERCENT)
+ height = query.line_height.value;
+ else height = query.line_height.computed;
gchar *sstr = g_strdup_printf ("%d%%", (int) floor(height * 100 + 0.5));
gtk_entry_set_text ((GtkEntry *) gtk_bin_get_child ((GtkBin *) spacing_combo), sstr);
g_free(sstr);
- sp_style_unref(query);
}
blocked = false;
}
diff --git a/src/ui/tools/freehand-base.cpp b/src/ui/tools/freehand-base.cpp
index c9fe37135..0f14d7534 100644
--- a/src/ui/tools/freehand-base.cpp
+++ b/src/ui/tools/freehand-base.cpp
@@ -247,11 +247,9 @@ static void spdc_apply_powerstroke_shape(const std::vector<Geom::Point> & points
char const *style_str = NULL;
style_str = repr->attribute("style");
if (style_str) {
- SPStyle *style = sp_style_new(SP_ACTIVE_DOCUMENT);
- sp_style_merge_from_style_string(style, style_str);
- stroke_width = style->stroke_width.computed;
- style->stroke_width.computed = 0;
- sp_style_unref(style);
+ SPStyle style(SP_ACTIVE_DOCUMENT);
+ style.mergeString(style_str);
+ stroke_width = style.stroke_width.computed;
}
std::ostringstream s;
@@ -821,14 +819,11 @@ void spdc_create_single_dot(ToolBase *ec, Geom::Point const &pt, char const *too
// find out stroke width (TODO: is there an easier way??)
double stroke_width = 3.0;
- gchar const *style_str = NULL;
- style_str = repr->attribute("style");
+ gchar const *style_str = repr->attribute("style");
if (style_str) {
- SPStyle *style = sp_style_new(SP_ACTIVE_DOCUMENT);
- sp_style_merge_from_style_string(style, style_str);
- stroke_width = style->stroke_width.computed;
- style->stroke_width.computed = 0;
- sp_style_unref(style);
+ SPStyle style(SP_ACTIVE_DOCUMENT);
+ style.mergeString(style_str);
+ stroke_width = style.stroke_width.computed;
}
// unset stroke and set fill color to former stroke color
diff --git a/src/ui/widget/object-composite-settings.cpp b/src/ui/widget/object-composite-settings.cpp
index 7439a402c..00a74c4fe 100644
--- a/src/ui/widget/object-composite-settings.cpp
+++ b/src/ui/widget/object-composite-settings.cpp
@@ -219,8 +219,8 @@ ObjectCompositeSettings::_subjectChanged() {
return;
_blocked = true;
- SPStyle *query = sp_style_new (desktop->getDocument());
- int result = _subject->queryStyle(query, QUERY_STYLE_PROPERTY_MASTEROPACITY);
+ SPStyle query(desktop->getDocument());
+ int result = _subject->queryStyle(&query, QUERY_STYLE_PROPERTY_MASTEROPACITY);
switch (result) {
case QUERY_STYLE_NOTHING:
@@ -231,19 +231,19 @@ ObjectCompositeSettings::_subjectChanged() {
case QUERY_STYLE_MULTIPLE_AVERAGED: // TODO: treat this slightly differently
case QUERY_STYLE_MULTIPLE_SAME:
_opacity_vbox.set_sensitive(true);
- _opacity_scale.get_adjustment()->set_value(100 * SP_SCALE24_TO_FLOAT(query->opacity.value));
+ _opacity_scale.get_adjustment()->set_value(100 * SP_SCALE24_TO_FLOAT(query.opacity.value));
break;
}
//query now for current filter mode and average blurring of selection
- const int blend_result = _subject->queryStyle(query, QUERY_STYLE_PROPERTY_BLEND);
+ const int blend_result = _subject->queryStyle(&query, QUERY_STYLE_PROPERTY_BLEND);
switch(blend_result) {
case QUERY_STYLE_NOTHING:
_fe_cb.set_sensitive(false);
break;
case QUERY_STYLE_SINGLE:
case QUERY_STYLE_MULTIPLE_SAME:
- _fe_cb.set_blend_mode(query->filter_blend_mode.value);
+ _fe_cb.set_blend_mode(query.filter_blend_mode.value);
_fe_cb.set_sensitive(true);
break;
case QUERY_STYLE_MULTIPLE_DIFFERENT:
@@ -253,7 +253,7 @@ ObjectCompositeSettings::_subjectChanged() {
}
if(blend_result == QUERY_STYLE_SINGLE || blend_result == QUERY_STYLE_MULTIPLE_SAME) {
- int blur_result = _subject->queryStyle(query, QUERY_STYLE_PROPERTY_BLUR);
+ int blur_result = _subject->queryStyle(&query, QUERY_STYLE_PROPERTY_BLUR);
switch (blur_result) {
case QUERY_STYLE_NOTHING: //no blurring
_fe_cb.set_blur_sensitive(false);
@@ -266,7 +266,7 @@ ObjectCompositeSettings::_subjectChanged() {
double perimeter = bbox->dimensions()[Geom::X] + bbox->dimensions()[Geom::Y]; // fixme: this is only half the perimeter, is that correct?
_fe_cb.set_blur_sensitive(true);
//update blur widget value
- float radius = query->filter_gaussianBlur_deviation.value;
+ float radius = query.filter_gaussianBlur_deviation.value;
float percent = radius * 400 / perimeter; // so that for a square, 100% == half side
_fe_cb.set_blur_value(percent);
}
@@ -274,8 +274,6 @@ ObjectCompositeSettings::_subjectChanged() {
}
}
- sp_style_unref(query);
-
_blocked = false;
}
diff --git a/src/ui/widget/selected-style.cpp b/src/ui/widget/selected-style.cpp
index 93b4893f2..1fc67dcef 100644
--- a/src/ui/widget/selected-style.cpp
+++ b/src/ui/widget/selected-style.cpp
@@ -977,7 +977,7 @@ SelectedStyle::update()
return;
// create temporary style
- SPStyle *query = sp_style_new (_desktop->getDocument());
+ SPStyle query(_desktop->getDocument());
for (int i = SS_FILL; i <= SS_STROKE; i++) {
Gtk::EventBox *place = (i == SS_FILL)? &_fill_place : &_stroke_place;
@@ -995,7 +995,7 @@ SelectedStyle::update()
_popup_copy[i].set_sensitive(false);
// query style from desktop. This returns a result flag and fills query with the style of subselection, if any, or selection
- int result = sp_desktop_query_style (_desktop, query,
+ int result = sp_desktop_query_style (_desktop, &query,
(i == SS_FILL)? QUERY_STYLE_PROPERTY_FILL : QUERY_STYLE_PROPERTY_STROKE);
switch (result) {
case QUERY_STYLE_NOTHING:
@@ -1020,12 +1020,12 @@ SelectedStyle::update()
}
SPIPaint *paint;
if (i == SS_FILL) {
- paint = &(query->fill);
+ paint = &(query.fill);
} else {
- paint = &(query->stroke);
+ paint = &(query.stroke);
}
if (paint->set && paint->isPaintserver()) {
- SPPaintServer *server = (i == SS_FILL)? SP_STYLE_FILL_SERVER (query) : SP_STYLE_STROKE_SERVER (query);
+ SPPaintServer *server = (i == SS_FILL)? SP_STYLE_FILL_SERVER (&query) : SP_STYLE_STROKE_SERVER (&query);
if ( server ) {
Inkscape::XML::Node *srepr = server->getRepr();
_paintserver_id[i] += "url(#";
@@ -1062,7 +1062,7 @@ SelectedStyle::update()
}
} else if (paint->set && paint->isColor()) {
guint32 color = paint->value.color.toRGBA32(
- SP_SCALE24_TO_FLOAT ((i == SS_FILL)? query->fill_opacity.value : query->stroke_opacity.value));
+ SP_SCALE24_TO_FLOAT ((i == SS_FILL)? query.fill_opacity.value : query.stroke_opacity.value));
_lastselected[i] = _thisselected[i];
_thisselected[i] = color; // include opacity
((Inkscape::UI::Widget::ColorPreview*)_color_preview[i])->setRgba32 (color);
@@ -1105,7 +1105,7 @@ SelectedStyle::update()
clearTooltip(_opacity_place);
clearTooltip(_opacity_sb);
- int result = sp_desktop_query_style (_desktop, query, QUERY_STYLE_PROPERTY_MASTEROPACITY);
+ int result = sp_desktop_query_style (_desktop, &query, QUERY_STYLE_PROPERTY_MASTEROPACITY);
switch (result) {
case QUERY_STYLE_NOTHING:
@@ -1122,16 +1122,16 @@ SelectedStyle::update()
_opacity_blocked = true;
_opacity_sb.set_sensitive(true);
#if WITH_GTKMM_3_0
- _opacity_adjustment->set_value(SP_SCALE24_TO_FLOAT(query->opacity.value) * 100);
+ _opacity_adjustment->set_value(SP_SCALE24_TO_FLOAT(query.opacity.value) * 100);
#else
- _opacity_adjustment.set_value(SP_SCALE24_TO_FLOAT(query->opacity.value) * 100);
+ _opacity_adjustment.set_value(SP_SCALE24_TO_FLOAT(query.opacity.value) * 100);
#endif
_opacity_blocked = false;
break;
}
// Now query stroke_width
- int result_sw = sp_desktop_query_style (_desktop, query, QUERY_STYLE_PROPERTY_STROKEWIDTH);
+ int result_sw = sp_desktop_query_style (_desktop, &query, QUERY_STYLE_PROPERTY_STROKEWIDTH);
switch (result_sw) {
case QUERY_STYLE_NOTHING:
_stroke_width.set_markup("");
@@ -1143,9 +1143,9 @@ SelectedStyle::update()
{
double w;
if (_sw_unit) {
- w = Inkscape::Util::Quantity::convert(query->stroke_width.computed, "px", _sw_unit);
+ w = Inkscape::Util::Quantity::convert(query.stroke_width.computed, "px", _sw_unit);
} else {
- w = query->stroke_width.computed;
+ w = query.stroke_width.computed;
}
current_stroke_width = w;
@@ -1168,8 +1168,6 @@ SelectedStyle::update()
default:
break;
}
-
- sp_style_unref(query);
}
void SelectedStyle::opacity_0(void) {_opacity_sb.set_value(0);}
diff --git a/src/ui/widget/style-swatch.cpp b/src/ui/widget/style-swatch.cpp
index 157fd2ad9..fa8543c46 100644
--- a/src/ui/widget/style-swatch.cpp
+++ b/src/ui/widget/style-swatch.cpp
@@ -260,13 +260,12 @@ void StyleSwatch::setStyle(SPCSSAttr *css)
Glib::ustring css_string;
sp_repr_css_write_string (_css, css_string);
- SPStyle *temp_spstyle = sp_style_new(SP_ACTIVE_DOCUMENT);
+
+ SPStyle style(SP_ACTIVE_DOCUMENT);
if (!css_string.empty()) {
- sp_style_merge_from_style_string (temp_spstyle, css_string.c_str());
+ style.mergeString(css_string.c_str());
}
-
- setStyle (temp_spstyle);
- sp_style_unref (temp_spstyle);
+ setStyle (&style);
}
void StyleSwatch::setStyle(SPStyle *query)
diff --git a/src/widgets/dash-selector.cpp b/src/widgets/dash-selector.cpp
index 479895022..9d591d33d 100644
--- a/src/widgets/dash-selector.cpp
+++ b/src/widgets/dash-selector.cpp
@@ -118,18 +118,18 @@ void SPDashSelector::init_dashes() {
int pos = 0;
if (!dash_prefs.empty()) {
- SPStyle *style = sp_style_new (NULL);
+ SPStyle style;
dashes = g_new (double *, dash_prefs.size() + 2); // +1 for custom slot, +1 for terminator slot
for (std::vector<Glib::ustring>::iterator i = dash_prefs.begin(); i != dash_prefs.end(); ++i) {
- sp_style_read_from_prefs(style, *i);
+ style.readFromPrefs( *i );
- if (!style->stroke_dasharray.values.empty()) {
- dashes[pos] = g_new (double, style->stroke_dasharray.values.size() + 1);
+ if (!style.stroke_dasharray.values.empty()) {
+ dashes[pos] = g_new (double, style.stroke_dasharray.values.size() + 1);
double *d = dashes[pos];
unsigned i = 0;
- for (; i < style->stroke_dasharray.values.size(); i++) {
- d[i] = style->stroke_dasharray.values[i];
+ for (; i < style.stroke_dasharray.values.size(); i++) {
+ d[i] = style.stroke_dasharray.values[i];
}
d[i] = -1;
} else {
diff --git a/src/widgets/fill-style.cpp b/src/widgets/fill-style.cpp
index fcdc9a36b..d60a92b8b 100644
--- a/src/widgets/fill-style.cpp
+++ b/src/widgets/fill-style.cpp
@@ -252,13 +252,13 @@ void FillNStroke::performUpdate()
update = true;
// create temporary style
- SPStyle *query = sp_style_new(desktop->doc());
+ SPStyle query(desktop->doc());
// query style from desktop into it. This returns a result flag and fills query with the style of subselection, if any, or selection
- int result = sp_desktop_query_style(desktop, query, (kind == FILL) ? QUERY_STYLE_PROPERTY_FILL : QUERY_STYLE_PROPERTY_STROKE);
+ int result = sp_desktop_query_style(desktop, &query, (kind == FILL) ? QUERY_STYLE_PROPERTY_FILL : QUERY_STYLE_PROPERTY_STROKE);
- SPIPaint &targPaint = (kind == FILL) ? query->fill : query->stroke;
- SPIScale24 &targOpacity = (kind == FILL) ? query->fill_opacity : query->stroke_opacity;
+ SPIPaint &targPaint = (kind == FILL) ? query.fill : query.stroke;
+ SPIScale24 &targOpacity = (kind == FILL) ? query.fill_opacity : query.stroke_opacity;
switch (result) {
case QUERY_STYLE_NOTHING:
@@ -272,11 +272,11 @@ void FillNStroke::performUpdate()
case QUERY_STYLE_MULTIPLE_AVERAGED: // TODO: treat this slightly differently, e.g. display "averaged" somewhere in paint selector
case QUERY_STYLE_MULTIPLE_SAME:
{
- SPPaintSelector::Mode pselmode = SPPaintSelector::getModeForStyle(*query, kind);
+ SPPaintSelector::Mode pselmode = SPPaintSelector::getModeForStyle(query, kind);
psel->setMode(pselmode);
if (kind == FILL) {
- psel->setFillrule(query->fill_rule.computed == ART_WIND_RULE_NONZERO?
+ psel->setFillrule(query.fill_rule.computed == ART_WIND_RULE_NONZERO?
SPPaintSelector::FILLRULE_NONZERO : SPPaintSelector::FILLRULE_EVENODD);
}
@@ -284,7 +284,7 @@ void FillNStroke::performUpdate()
psel->setColorAlpha(targPaint.value.color, SP_SCALE24_TO_FLOAT(targOpacity.value));
} else if (targPaint.set && targPaint.isPaintserver()) {
- SPPaintServer *server = (kind == FILL) ? query->getFillPaintServer() : query->getStrokePaintServer();
+ SPPaintServer *server = (kind == FILL) ? query.getFillPaintServer() : query.getStrokePaintServer();
if (server && SP_IS_GRADIENT(server) && SP_GRADIENT(server)->getVector()->isSwatch()) {
SPGradient *vector = SP_GRADIENT(server)->getVector();
@@ -318,8 +318,6 @@ void FillNStroke::performUpdate()
}
}
- sp_style_unref(query);
-
update = false;
}
@@ -562,10 +560,10 @@ void FillNStroke::updateFromPaint()
if (!vector) {
/* No vector in paint selector should mean that we just changed mode */
- SPStyle *query = sp_style_new(desktop->doc());
- int result = objects_query_fillstroke(const_cast<GSList *>(items), query, kind == FILL);
+ SPStyle query(desktop->doc());
+ int result = objects_query_fillstroke(const_cast<GSList *>(items), &query, kind == FILL);
if (result == QUERY_STYLE_MULTIPLE_SAME) {
- SPIPaint &targPaint = (kind == FILL) ? query->fill : query->stroke;
+ SPIPaint &targPaint = (kind == FILL) ? query.fill : query.stroke;
SPColor common;
if (!targPaint.isColor()) {
common = sp_desktop_get_color(desktop, kind == FILL);
@@ -577,7 +575,6 @@ void FillNStroke::updateFromPaint()
vector->setSwatch();
}
}
- sp_style_unref(query);
for (GSList const *i = items; i != NULL; i = i->next) {
//FIXME: see above
diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp
index 755489e12..5ca06a795 100644
--- a/src/widgets/stroke-style.cpp
+++ b/src/widgets/stroke-style.cpp
@@ -815,13 +815,13 @@ StrokeStyle::updateLine()
FillOrStroke kind = GPOINTER_TO_INT(get_data("kind")) ? FILL : STROKE;
// create temporary style
- SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT);
+ SPStyle query(SP_ACTIVE_DOCUMENT);
// query into it
- int result_sw = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_STROKEWIDTH);
- int result_ml = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_STROKEMITERLIMIT);
- int result_cap = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_STROKECAP);
- int result_join = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_STROKEJOIN);
- SPIPaint &targPaint = (kind == FILL) ? query->fill : query->stroke;
+ int result_sw = sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_STROKEWIDTH);
+ int result_ml = sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_STROKEMITERLIMIT);
+ int result_cap = sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_STROKECAP);
+ int result_join = sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_STROKEJOIN);
+ SPIPaint &targPaint = (kind == FILL) ? query.fill : query.stroke;
if (!sel || sel->isEmpty()) {
// Nothing selected, grey-out all controls in the stroke-style dialog
@@ -846,7 +846,7 @@ StrokeStyle::updateLine()
Inkscape::Util::Unit const *unit = unitSelector->getUnit();
if (unit->type == Inkscape::Util::UNIT_TYPE_LINEAR) {
- double avgwidth = Inkscape::Util::Quantity::convert(query->stroke_width.computed, "px", unit);
+ double avgwidth = Inkscape::Util::Quantity::convert(query.stroke_width.computed, "px", unit);
#if WITH_GTKMM_3_0
(*widthAdj)->set_value(avgwidth);
#else
@@ -879,27 +879,25 @@ StrokeStyle::updateLine()
if (result_ml != QUERY_STYLE_NOTHING)
#if WITH_GTKMM_3_0
- (*miterLimitAdj)->set_value(query->stroke_miterlimit.value); // TODO: reflect averagedness?
+ (*miterLimitAdj)->set_value(query.stroke_miterlimit.value); // TODO: reflect averagedness?
#else
- miterLimitAdj->set_value(query->stroke_miterlimit.value); // TODO: reflect averagedness?
+ miterLimitAdj->set_value(query.stroke_miterlimit.value); // TODO: reflect averagedness?
#endif
if (result_join != QUERY_STYLE_MULTIPLE_DIFFERENT &&
result_join != QUERY_STYLE_NOTHING ) {
- setJoinType(query->stroke_linejoin.value);
+ setJoinType(query.stroke_linejoin.value);
} else {
setJoinButtons(NULL);
}
if (result_cap != QUERY_STYLE_MULTIPLE_DIFFERENT &&
result_cap != QUERY_STYLE_NOTHING ) {
- setCapType (query->stroke_linecap.value);
+ setCapType (query.stroke_linecap.value);
} else {
setCapButtons(NULL);
}
- sp_style_unref(query);
-
if (!sel || sel->isEmpty())
return;
diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp
index d113d5c28..3d2e6eef8 100644
--- a/src/widgets/text-toolbar.cpp
+++ b/src/widgets/text-toolbar.cpp
@@ -220,9 +220,9 @@ static void sp_text_fontsize_value_changed( Ink_ComboBoxEntry_Action *act, GObje
sp_desktop_set_style (desktop, css, true, true);
// If no selected objects, set default.
- SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT);
+ SPStyle query(SP_ACTIVE_DOCUMENT);
int result_numbers =
- sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
+ sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
if (result_numbers == QUERY_STYLE_NOTHING)
{
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
@@ -233,8 +233,6 @@ static void sp_text_fontsize_value_changed( Ink_ComboBoxEntry_Action *act, GObje
_("Text: Change font size"));
}
- sp_style_unref(query);
-
sp_repr_css_attr_unref (css);
g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
@@ -292,8 +290,8 @@ static void sp_text_script_changed( InkToggleAction* act, GObject *tbl )
#endif
// Query baseline
- SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT);
- int result_baseline = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_BASELINES);
+ SPStyle query(SP_ACTIVE_DOCUMENT);
+ int result_baseline = sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_BASELINES);
bool setSuper = false;
bool setSub = false;
@@ -307,14 +305,14 @@ static void sp_text_script_changed( InkToggleAction* act, GObject *tbl )
}
} else {
// Superscript
- gboolean superscriptSet = (query->baseline_shift.set &&
- query->baseline_shift.type == SP_BASELINE_SHIFT_LITERAL &&
- query->baseline_shift.literal == SP_CSS_BASELINE_SHIFT_SUPER );
+ gboolean superscriptSet = (query.baseline_shift.set &&
+ query.baseline_shift.type == SP_BASELINE_SHIFT_LITERAL &&
+ query.baseline_shift.literal == SP_CSS_BASELINE_SHIFT_SUPER );
// Subscript
- gboolean subscriptSet = (query->baseline_shift.set &&
- query->baseline_shift.type == SP_BASELINE_SHIFT_LITERAL &&
- query->baseline_shift.literal == SP_CSS_BASELINE_SHIFT_SUB );
+ gboolean subscriptSet = (query.baseline_shift.set &&
+ query.baseline_shift.type == SP_BASELINE_SHIFT_LITERAL &&
+ query.baseline_shift.literal == SP_CSS_BASELINE_SHIFT_SUB );
setSuper = !superscriptSet && prop == 0;
setSub = !subscriptSet && prop == 1;
@@ -473,10 +471,9 @@ static void sp_text_align_mode_changed( EgeSelectOneAction *act, GObject *tbl )
}
}
- SPStyle *query =
- sp_style_new (SP_ACTIVE_DOCUMENT);
+ SPStyle query(SP_ACTIVE_DOCUMENT);
int result_numbers =
- sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
+ sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
// If querying returned nothing, update default style.
if (result_numbers == QUERY_STYLE_NOTHING)
@@ -485,8 +482,6 @@ static void sp_text_align_mode_changed( EgeSelectOneAction *act, GObject *tbl )
prefs->mergeStyle("/tools/text/style", css);
}
- sp_style_unref(query);
-
sp_desktop_set_style (desktop, css, true, true);
if (result_numbers != QUERY_STYLE_NOTHING)
{
@@ -538,15 +533,14 @@ static void sp_text_lineheight_value_changed( GtkAdjustment *adj, GObject *tbl )
}
// If no selected objects, set default.
- SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT);
+ SPStyle query(SP_ACTIVE_DOCUMENT);
int result_numbers =
- sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
+ sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
if (result_numbers == QUERY_STYLE_NOTHING)
{
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
prefs->mergeStyle("/tools/text/style", css);
}
- sp_style_unref(query);
sp_repr_css_attr_unref (css);
@@ -573,9 +567,9 @@ static void sp_text_wordspacing_value_changed( GtkAdjustment *adj, GObject *tbl
sp_desktop_set_style (desktop, css, true, false);
// If no selected objects, set default.
- SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT);
+ SPStyle query(SP_ACTIVE_DOCUMENT);
int result_numbers =
- sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
+ sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
if (result_numbers == QUERY_STYLE_NOTHING)
{
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
@@ -585,7 +579,6 @@ static void sp_text_wordspacing_value_changed( GtkAdjustment *adj, GObject *tbl
DocumentUndo::maybeDone(SP_ACTIVE_DESKTOP->getDocument(), "ttb:word-spacing", SP_VERB_NONE,
_("Text: Change word-spacing"));
}
- sp_style_unref(query);
sp_repr_css_attr_unref (css);
@@ -612,9 +605,9 @@ static void sp_text_letterspacing_value_changed( GtkAdjustment *adj, GObject *tb
sp_desktop_set_style (desktop, css, true, false);
// If no selected objects, set default.
- SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT);
+ SPStyle query(SP_ACTIVE_DOCUMENT);
int result_numbers =
- sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
+ sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
if (result_numbers == QUERY_STYLE_NOTHING)
{
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
@@ -627,8 +620,6 @@ static void sp_text_letterspacing_value_changed( GtkAdjustment *adj, GObject *tb
_("Text: Change letter-spacing"));
}
- sp_style_unref(query);
-
sp_repr_css_attr_unref (css);
g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
@@ -765,10 +756,9 @@ static void sp_text_orientation_mode_changed( EgeSelectOneAction *act, GObject *
}
}
- SPStyle *query =
- sp_style_new (SP_ACTIVE_DOCUMENT);
+ SPStyle query(SP_ACTIVE_DOCUMENT);
int result_numbers =
- sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
+ sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
// If querying returned nothing, update default style.
if (result_numbers == QUERY_STYLE_NOTHING)
@@ -892,11 +882,11 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/
* Numbers (font-size, letter-spacing, word-spacing, line-height, text-anchor, writing-mode)
* Font specification (Inkscape private attribute)
*/
- SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT);
- int result_family = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTFAMILY);
- int result_style = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTSTYLE);
- int result_numbers = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
- int result_baseline = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_BASELINES);
+ SPStyle query(SP_ACTIVE_DOCUMENT);
+ int result_family = sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTFAMILY);
+ int result_style = sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTSTYLE);
+ int result_numbers = sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
+ int result_baseline = sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_BASELINES);
/*
* If no text in selection (querying returned nothing), read the style from
@@ -905,14 +895,13 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/
*/
if (result_family == QUERY_STYLE_NOTHING || result_style == QUERY_STYLE_NOTHING || result_numbers == QUERY_STYLE_NOTHING) {
// There are no texts in selection, read from preferences.
- sp_style_read_from_prefs(query, "/tools/text");
+ query.readFromPrefs("/tools/text");
#ifdef DEBUG_TEXT
std::cout << " read style from prefs:" << std::endl;
- sp_print_font( query );
+ sp_print_font( &query );
#endif
if (g_object_get_data(tbl, "text_style_from_prefs")) {
// Do not reset the toolbar style from prefs if we already did it last time
- sp_style_unref(query);
g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
#ifdef DEBUG_TEXT
std::cout << " text_style_from_prefs: toolbar already set" << std:: endl;
@@ -937,7 +926,7 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/
// Size (average of text selected)
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT);
- double size = sp_style_css_size_px_to_units(query->font_size.computed, unit);
+ double size = sp_style_css_size_px_to_units(query.font_size.computed, unit);
//gchar size_text[G_ASCII_DTOSTR_BUF_SIZE];
//g_ascii_dtostr (size_text, sizeof (size_text), size);
@@ -961,9 +950,9 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/
// Superscript
gboolean superscriptSet =
((result_baseline == QUERY_STYLE_SINGLE || result_baseline == QUERY_STYLE_MULTIPLE_SAME ) &&
- query->baseline_shift.set &&
- query->baseline_shift.type == SP_BASELINE_SHIFT_LITERAL &&
- query->baseline_shift.literal == SP_CSS_BASELINE_SHIFT_SUPER );
+ query.baseline_shift.set &&
+ query.baseline_shift.type == SP_BASELINE_SHIFT_LITERAL &&
+ query.baseline_shift.literal == SP_CSS_BASELINE_SHIFT_SUPER );
InkToggleAction* textSuperscriptAction = INK_TOGGLE_ACTION( g_object_get_data( tbl, "TextSuperscriptAction" ) );
gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(textSuperscriptAction), superscriptSet );
@@ -972,9 +961,9 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/
// Subscript
gboolean subscriptSet =
((result_baseline == QUERY_STYLE_SINGLE || result_baseline == QUERY_STYLE_MULTIPLE_SAME ) &&
- query->baseline_shift.set &&
- query->baseline_shift.type == SP_BASELINE_SHIFT_LITERAL &&
- query->baseline_shift.literal == SP_CSS_BASELINE_SHIFT_SUB );
+ query.baseline_shift.set &&
+ query.baseline_shift.type == SP_BASELINE_SHIFT_LITERAL &&
+ query.baseline_shift.literal == SP_CSS_BASELINE_SHIFT_SUB );
InkToggleAction* textSubscriptAction = INK_TOGGLE_ACTION( g_object_get_data( tbl, "TextSubscriptAction" ) );
gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(textSubscriptAction), subscriptSet );
@@ -1001,26 +990,26 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/
// ege_select_one_action_set_sensitive( textAlignAction, 3, isFlow );
int activeButton = 0;
- if (query->text_align.computed == SP_CSS_TEXT_ALIGN_JUSTIFY)
+ if (query.text_align.computed == SP_CSS_TEXT_ALIGN_JUSTIFY)
{
activeButton = 3;
} else {
- if (query->text_anchor.computed == SP_CSS_TEXT_ANCHOR_START) activeButton = 0;
- if (query->text_anchor.computed == SP_CSS_TEXT_ANCHOR_MIDDLE) activeButton = 1;
- if (query->text_anchor.computed == SP_CSS_TEXT_ANCHOR_END) activeButton = 2;
+ if (query.text_anchor.computed == SP_CSS_TEXT_ANCHOR_START) activeButton = 0;
+ if (query.text_anchor.computed == SP_CSS_TEXT_ANCHOR_MIDDLE) activeButton = 1;
+ if (query.text_anchor.computed == SP_CSS_TEXT_ANCHOR_END) activeButton = 2;
}
ege_select_one_action_set_active( textAlignAction, activeButton );
// Line height (spacing)
double height;
- if (query->line_height.normal) {
+ if (query.line_height.normal) {
height = Inkscape::Text::Layout::LINE_HEIGHT_NORMAL;
} else {
- if (query->line_height.unit == SP_CSS_UNIT_PERCENT) {
- height = query->line_height.value;
+ if (query.line_height.unit == SP_CSS_UNIT_PERCENT) {
+ height = query.line_height.value;
} else {
- height = query->line_height.computed;
+ height = query.line_height.computed;
}
}
@@ -1032,8 +1021,8 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/
// Word spacing
double wordSpacing;
- if (query->word_spacing.normal) wordSpacing = 0.0;
- else wordSpacing = query->word_spacing.computed; // Assume no units (change in desktop-style.cpp)
+ if (query.word_spacing.normal) wordSpacing = 0.0;
+ else wordSpacing = query.word_spacing.computed; // Assume no units (change in desktop-style.cpp)
GtkAction* wordSpacingAction = GTK_ACTION( g_object_get_data( tbl, "TextWordSpacingAction" ) );
GtkAdjustment *wordSpacingAdjustment =
@@ -1043,8 +1032,8 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/
// Letter spacing
double letterSpacing;
- if (query->letter_spacing.normal) letterSpacing = 0.0;
- else letterSpacing = query->letter_spacing.computed; // Assume no units (change in desktop-style.cpp)
+ if (query.letter_spacing.normal) letterSpacing = 0.0;
+ else letterSpacing = query.letter_spacing.computed; // Assume no units (change in desktop-style.cpp)
GtkAction* letterSpacingAction = GTK_ACTION( g_object_get_data( tbl, "TextLetterSpacingAction" ) );
GtkAdjustment *letterSpacingAdjustment =
@@ -1053,7 +1042,7 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/
// Orientation
- int activeButton2 = (query->writing_mode.computed == SP_CSS_WRITING_MODE_LR_TB ? 0 : 1);
+ int activeButton2 = (query.writing_mode.computed == SP_CSS_WRITING_MODE_LR_TB ? 0 : 1);
EgeSelectOneAction* textOrientationAction =
EGE_SELECT_ONE_ACTION( g_object_get_data( tbl, "TextOrientationAction" ) );
@@ -1064,27 +1053,25 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/
#ifdef DEBUG_TEXT
std::cout << " GUI: fontfamily.value: "
- << (query->font_family.value ? query->font_family.value : "No value")
+ << (query.font_family.value ? query.font_family.value : "No value")
<< std::endl;
- std::cout << " GUI: font_size.computed: " << query->font_size.computed << std::endl;
- std::cout << " GUI: font_weight.computed: " << query->font_weight.computed << std::endl;
- std::cout << " GUI: font_style.computed: " << query->font_style.computed << std::endl;
- std::cout << " GUI: text_anchor.computed: " << query->text_anchor.computed << std::endl;
- std::cout << " GUI: text_align.computed: " << query->text_align.computed << std::endl;
- std::cout << " GUI: line_height.computed: " << query->line_height.computed
- << " line_height.value: " << query->line_height.value
- << " line_height.unit: " << query->line_height.unit << std::endl;
- std::cout << " GUI: word_spacing.computed: " << query->word_spacing.computed
- << " word_spacing.value: " << query->word_spacing.value
- << " word_spacing.unit: " << query->word_spacing.unit << std::endl;
- std::cout << " GUI: letter_spacing.computed: " << query->letter_spacing.computed
- << " letter_spacing.value: " << query->letter_spacing.value
- << " letter_spacing.unit: " << query->letter_spacing.unit << std::endl;
- std::cout << " GUI: writing_mode.computed: " << query->writing_mode.computed << std::endl;
+ std::cout << " GUI: font_size.computed: " << query.font_size.computed << std::endl;
+ std::cout << " GUI: font_weight.computed: " << query.font_weight.computed << std::endl;
+ std::cout << " GUI: font_style.computed: " << query.font_style.computed << std::endl;
+ std::cout << " GUI: text_anchor.computed: " << query.text_anchor.computed << std::endl;
+ std::cout << " GUI: text_align.computed: " << query.text_align.computed << std::endl;
+ std::cout << " GUI: line_height.computed: " << query.line_height.computed
+ << " line_height.value: " << query.line_height.value
+ << " line_height.unit: " << query.line_height.unit << std::endl;
+ std::cout << " GUI: word_spacing.computed: " << query.word_spacing.computed
+ << " word_spacing.value: " << query.word_spacing.value
+ << " word_spacing.unit: " << query.word_spacing.unit << std::endl;
+ std::cout << " GUI: letter_spacing.computed: " << query.letter_spacing.computed
+ << " letter_spacing.value: " << query.letter_spacing.value
+ << " letter_spacing.unit: " << query.letter_spacing.unit << std::endl;
+ std::cout << " GUI: writing_mode.computed: " << query.writing_mode.computed << std::endl;
#endif
- sp_style_unref(query);
-
// Kerning (xshift), yshift, rotation. NB: These are not CSS attributes.
if( SP_IS_TEXT_CONTEXT((SP_ACTIVE_DESKTOP)->event_context) ) {
Inkscape::UI::Tools::TextTool *const tc = SP_TEXT_CONTEXT((SP_ACTIVE_DESKTOP)->event_context);