All pastes #606729 Raw Edit

Someone

public text v1 · immutable
·published 2007-07-07 01:37 UTC
rendered paste body
void sp_tref_update_text(SPTRef *tref)
{
    if (tref) {
        // Get the character data that will be used with this tref
        Glib::ustring charData = "";
        build_string_from_root(SP_OBJECT_REPR(tref->getObjectReferredTo()), &charData);
        
        // Create the node and SPString to be the tref's child (if it doesn't exist yet)
        if (!tref->stringChild) {
            Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_OBJECT_DOCUMENT(tref));
            
            Inkscape::XML::Node *newStringRepr = xml_doc->createTextNode(charData.c_str());
            tref->stringChild = SP_OBJECT(g_object_new(sp_repr_type_lookup(newStringRepr), NULL));
            
            // Add this SPString as a child of the tref
            sp_object_attach(SP_OBJECT(tref), tref->stringChild, tref->lastChild());
            sp_object_unref(tref->stringChild, NULL);
            sp_object_invoke_build(tref->stringChild, SP_OBJECT(tref)->document, newStringRepr, TRUE);
            
            Inkscape::GC::release(newStringRepr);
        }
        else {
            // Set the string content for the existing node
            Inkscape::XML::Node *stringRepr = SP_OBJECT_REPR(tref->stringChild);
            stringRepr->setContent(charData.c_str());
        }
    }
}