Logo Search packages:      
Sourcecode: inkscape version File versions

SPCSSAttr* take_style_from_item ( SPItem item  ) 

Precondition:
item != NULL

Definition at line 908 of file selection-chemistry.cpp.

References SPObject::lastChild(), sp_css_attr_from_object(), sp_css_attr_scale(), sp_css_attr_unset_text(), and sp_item_i2doc_affine().

Referenced by Inkscape::UI::ClipboardManagerImpl::_copySelection().

{
    // write the complete cascaded style, context-free
    SPCSSAttr *css = sp_css_attr_from_object(SP_OBJECT(item), SP_STYLE_FLAG_ALWAYS);
    if (css == NULL)
        return NULL;

    if ((SP_IS_GROUP(item) && SP_OBJECT(item)->children) ||
        (SP_IS_TEXT(item) && SP_OBJECT(item)->children && SP_OBJECT(item)->children->next == NULL)) {
        // if this is a text with exactly one tspan child, merge the style of that tspan as well
        // If this is a group, merge the style of its topmost (last) child with style
        for (SPObject *last_element = item->lastChild(); last_element != NULL; last_element = SP_OBJECT_PREV(last_element)) {
            if (SP_OBJECT_STYLE(last_element) != NULL) {
                SPCSSAttr *temp = sp_css_attr_from_object(last_element, SP_STYLE_FLAG_IFSET);
                if (temp) {
                    sp_repr_css_merge(css, temp);
                    sp_repr_css_attr_unref(temp);
                }
                break;
            }
        }
    }
    if (!(SP_IS_TEXT(item) || SP_IS_TSPAN(item) || SP_IS_TREF(item) || SP_IS_STRING(item))) {
        // do not copy text properties from non-text objects, it's confusing
        css = sp_css_attr_unset_text(css);
    }

    // FIXME: also transform gradient/pattern fills, by forking? NO, this must be nondestructive
    double ex = to_2geom(sp_item_i2doc_affine(item)).descrim();
    if (ex != 1.0) {
        css = sp_css_attr_scale(css, ex);
    }

    return css;
}


Generated by  Doxygen 1.6.0   Back to index