summaryrefslogtreecommitdiffstats
path: root/src/xml/repr-css.cpp
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2018-12-04 12:40:43 +0000
committerTavmjong Bah <tavmjong@free.fr>2018-12-04 12:40:43 +0000
commitb0be54c82565f7e476187365ccb6c65d0729810d (patch)
treec0b8133fa3a57934f4b57a5e5aaa5da0697864b0 /src/xml/repr-css.cpp
parentMinor comment/alignment changes. (diff)
downloadinkscape-b0be54c82565f7e476187365ccb6c65d0729810d.tar.gz
inkscape-b0be54c82565f7e476187365ccb6c65d0729810d.zip
Add a few useful lookup functions.
Diffstat (limited to 'src/xml/repr-css.cpp')
-rw-r--r--src/xml/repr-css.cpp29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/xml/repr-css.cpp b/src/xml/repr-css.cpp
index 5db698406..d035b9a4b 100644
--- a/src/xml/repr-css.cpp
+++ b/src/xml/repr-css.cpp
@@ -61,7 +61,7 @@ protected:
SimpleNode *_duplicate(Document* doc) const override { return new SPCSSAttrImpl(*this, doc); }
};
-static void sp_repr_css_add_components(SPCSSAttr *css, Node *repr, gchar const *attr);
+static void sp_repr_css_add_components(SPCSSAttr *css, Node const *repr, gchar const *attr);
/**
* Creates an empty SPCSSAttr (a class for manipulating CSS style properties).
@@ -90,7 +90,7 @@ void sp_repr_css_attr_unref(SPCSSAttr *css)
* string is parsed by libcroco which returns a CRDeclaration list (a typical C linked list) of
* properties and values. This list is then used to fill the attributes of the new SPCSSAttr.
*/
-SPCSSAttr *sp_repr_css_attr(Node *repr, gchar const *attr)
+SPCSSAttr *sp_repr_css_attr(Node const *repr, gchar const *attr)
{
g_assert(repr != nullptr);
g_assert(attr != nullptr);
@@ -174,9 +174,9 @@ SPCSSAttr *sp_repr_css_attr_parse_color_to_fill(const Glib::ustring &text)
/**
* Adds an attribute to an existing SPCSAttr with the cascaded value including all parents.
*/
-static void sp_repr_css_attr_inherited_recursive(SPCSSAttr *css, Node *repr, gchar const *attr)
+static void sp_repr_css_attr_inherited_recursive(SPCSSAttr *css, Node const *repr, gchar const *attr)
{
- Node *parent = repr->parent();
+ const Node *parent = repr->parent();
// read the ancestors from root down, using head recursion, so that children override parents
if (parent) {
@@ -188,7 +188,7 @@ static void sp_repr_css_attr_inherited_recursive(SPCSSAttr *css, Node *repr, gch
/**
* Creates a new SPCSSAttr with one attribute whose value is determined by cascading.
*/
-SPCSSAttr *sp_repr_css_attr_inherited(Node *repr, gchar const *attr)
+SPCSSAttr *sp_repr_css_attr_inherited(Node const *repr, gchar const *attr)
{
g_assert(repr != nullptr);
g_assert(attr != nullptr);
@@ -205,7 +205,7 @@ SPCSSAttr *sp_repr_css_attr_inherited(Node *repr, gchar const *attr)
* (nominally a style attribute).
*
*/
-static void sp_repr_css_add_components(SPCSSAttr *css, Node *repr, gchar const *attr)
+static void sp_repr_css_add_components(SPCSSAttr *css, Node const *repr, gchar const *attr)
{
g_assert(css != nullptr);
g_assert(repr != nullptr);
@@ -231,6 +231,23 @@ char const *sp_repr_css_property(SPCSSAttr *css, gchar const *name, gchar const
}
/**
+ * Returns a character string of the value of a given style property or a default value if the
+ * attribute is not found.
+ */
+Glib::ustring sp_repr_css_property(SPCSSAttr *css, Glib::ustring const &name, Glib::ustring const &defval)
+{
+ g_assert(css != nullptr);
+
+ Glib::ustring retval = defval;
+ char const *attr = ((Node *)css)->attribute(name.c_str());
+ if (attr) {
+ retval = attr;
+ }
+
+ return retval;
+}
+
+/**
* Returns true if a style property is present and its value is unset.
*/
bool sp_repr_css_property_is_unset(SPCSSAttr *css, gchar const *name)