All pastes #605222 Raw Edit

Stuff

public text v1 · immutable
·published 2007-07-06 01:10 UTC
rendered paste body
SPString * sp_tref_convert_to_tspan(SPTRef *tref)
{
    SPObject * new_string_child = NULL;
    
    if (tref && tref->stringChild) {
        debug("");
        
        Glib::ustring tref_content = SP_STRING(tref->stringChild)->string;
        
        Inkscape::XML::Node *tref_repr = SP_OBJECT_REPR(tref);
        Inkscape::XML::Node *tref_parent = sp_repr_parent(tref_repr);
        
        SPDocument *document = SP_OBJECT(tref)->document;
        Inkscape::XML::Document *xml_doc = sp_document_repr_doc(document);
        
        Inkscape::XML::Node *new_tspan_repr = xml_doc->createElement("svg:tspan");
        
        // Add the new tspan element just after the current tref
        tref_parent->addChild(new_tspan_repr, tref_repr);
        Inkscape::GC::release(new_tspan_repr);
        
        SPObject *new_tspan = document->getObjectByRepr(new_tspan_repr);
        
        
        // Create a new string child for the tspan
        //Inkscape::XML::Node *new_string_repr = xml_doc->createTextNode(tref_content.c_str());
        
        Inkscape::XML::Node *new_string_repr = SP_OBJECT_REPR(tref->stringChild)->duplicate(xml_doc);
        new_tspan_repr->addChild(new_string_repr, NULL);
        
        
        new_string_child = document->getObjectByRepr(new_string_repr);
        
        
        // Merge style from the tref
        SPStyle *new_tspan_sty = SP_OBJECT_STYLE(new_tspan);
        SPStyle const *tref_sty = SP_OBJECT_STYLE(tref);
        sp_style_merge_from_dying_parent(new_tspan_sty, tref_sty);
        sp_style_merge_from_parent(new_tspan_sty, new_tspan->parent->style);
        
        
        SP_OBJECT(new_tspan)->updateRepr();
        
        // Hold onto our SPObject and repr for now.
        sp_object_ref(SP_OBJECT(tref), NULL);
        Inkscape::GC::anchor(tref_repr);
        
        // Remove ourselves, not propagating delete events to avoid a
        // chain-reaction with other elements that might reference us.
        SP_OBJECT(tref)->deleteObject(false);
        
        // Give the copy our old id and let go of our old repr.
        new_tspan_repr->setAttribute("id", tref_repr->attribute("id"));
        Inkscape::GC::release(tref_repr);
        
        // Establish the succession and let go of our object.
        SP_OBJECT(tref)->setSuccessor(new_tspan);
        sp_object_unref(SP_OBJECT(tref), NULL);
    }
    
    if (new_string_child)
        return SP_STRING(new_string_child);
    else
        return NULL;
}