Logo Search packages:      
Sourcecode: inkscape version File versions

gchar const* sp_object_get_style_property ( SPObject const *  object,
gchar const *  key,
gchar const *  def 

Returns an object style property.

fixme: Use proper CSS parsing. The current version is buggy in a number of situations where key is a substring of the style string other than as a property name (including where key is a substring of a property name), and is also buggy in its handling of inheritance for properties that aren't inherited by default. It also doesn't allow for the case where the property is specified but with an invalid value (in which case I believe the CSS2 error-handling behaviour applies, viz. behave as if the property hadn't been specified). Also, the current code doesn't use CRSelEng stuff to take a value from stylesheets. Also, we aren't setting any hooks to force an update for changes in any of the inputs (i.e., in any of the elements that this function queries).
Given that the default value for a property depends on what property it is (e.g., whether to inherit or not), and given the above comment about ignoring invalid values, and that the repr parent isn't necessarily the right element to inherit from (e.g., maybe we need to inherit from the referencing <use> element instead), we should probably make the caller responsible for ascending the repr tree as necessary.

Definition at line 1512 of file sp-object.cpp.

References SPObject::parent, sp_object_get_style_property(), and SPObject::style.

Referenced by sp_object_get_style_property(), sp_stop_get_color(), sp_stop_get_rgba32(), and sp_stop_set().

    g_return_val_if_fail(object != NULL, NULL);
    g_return_val_if_fail(SP_IS_OBJECT(object), NULL);
    g_return_val_if_fail(key != NULL, NULL);

    gchar const *style = object->repr->attribute("style");
    if (style) {
        size_t const len = strlen(key);
        char const *p;
        while ( (p = strstr(style, key))
                != NULL )
            p += len;
            while ((*p <= ' ') && *p) p++;
            if (*p++ != ':') break;
            while ((*p <= ' ') && *p) p++;
            size_t const inherit_len = sizeof("inherit") - 1;
            if (*p
                && !(strneq(p, "inherit", inherit_len)
                     && (p[inherit_len] == '\0'
                         || p[inherit_len] == ';'
                         || g_ascii_isspace(p[inherit_len])))) {
                return p;
    gchar const *val = object->repr->attribute(key);
    if (val && !streq(val, "inherit")) {
        return val;
    if (object->parent) {
        return sp_object_get_style_property(object->parent, key, def);

    return def;

Generated by  Doxygen 1.6.0   Back to index