W dniu 6 kwietnia 2010 23:58 użytkownik Yann Papouin <yann.papouin@...400...> napisał:
Following is an example of what I'm applying in my software:
[SNIP]
In C++, I would do something like this. It's practically the same idea, but switch + fallthrough makes it clearer.
bool sp_document_upgrade(Inkscape::XML::Document *doc) { const int document_format = 7; int current_document_format = doc->root()->parseInt("inkscape:document-version"); bool ret = true;
switch (current_document_format) { case 0: fix_3dbox_coords(doc); fix_guide_coords(doc); case 1: add_flowtext_fallbacks(doc); case 2: rename_sodipodi_attributes(doc); case 3: convert_lpe_to_vector_effects(doc); // etc. for later versions case 7: break; // nothing more to do default: ret = false; // unrecognized version - offer to load as plain SVG }
doc->root()->setInt("inkscape:document-version", document_format); return ret; }
Note that when I'm applying the version_A -> version_B upgrade, I'm not relying on the core code, all is managed internally by the upgrade procedure in order to avoid upgrade fails that could occured due to a progressive refactoring (deletion, renaming, etc.)
This is somewhat like using only generic XML processing, instead of the SP tree.
Regardless of what this function will ultimately do, we'd need to create several test documents for every document format change, and verify that the conversion works correctly after every change to older portions of the update procedure.
Regards, Krzysztof