Logo Search packages:      
Sourcecode: inkscape version File versions  Download package

static void change_clashing_ids ( SPDocument imported_doc,
SPDocument current_doc,
SPObject elem,
const refmap_type *  refmap,
id_changelist_type *  id_changes 
) [static]

Change any IDs that clash with IDs in the current document, and make a list of those changes that will require fixing up references.

Definition at line 180 of file id-clash.cpp.

Referenced by prevent_id_clashes().

{
    const gchar *id = SP_OBJECT_ID(elem);

    if (id && current_doc->getObjectById(id)) {
        // Choose a new ID.
        // To try to preserve any meaningfulness that the original ID
        // may have had, the new ID is the old ID followed by a hyphen
        // and one or more digits.
        std::string old_id(id);
        std::string new_id(old_id + '-');
        for (;;) {
            new_id += "0123456789"[std::rand() % 10];
            const char *str = new_id.c_str();
            if (current_doc->getObjectById(str) == NULL &&
                imported_doc->getObjectById(str) == NULL) break;
        }
        // Change to the new ID
        SP_OBJECT_REPR(elem)->setAttribute("id", new_id.c_str());
        // Make a note of this change, if we need to fix up refs to it
        if (refmap->find(old_id) != refmap->end())
            id_changes->push_back(id_changeitem_type(elem, old_id));
    }

    /* recurse */
    for (SPObject *child = sp_object_first_child(elem);
         child; child = SP_OBJECT_NEXT(child) )
    {
        change_clashing_ids(imported_doc, current_doc, child, refmap, id_changes);
    }
}

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index