/** \brief Create a dependency using an XML definition \param in_repr XML definition of the dependency This function mostly looks for the 'location' and 'type' attributes and turns them into the enums of the same name. This makes things a little bit easier to use later. Also, a pointer to the core content is pulled out -- also to make things easier. */ Dependency::Dependency (Inkscape::XML::Node * in_repr) { _type = TYPE_FILE; _location = LOCATION_PATH; _repr = in_repr; _string = NULL; _description = NULL; Inkscape::GC::anchor(_repr); const gchar * location = _repr->attribute("location"); for (int i = 0; i < LOCATION_CNT && location != NULL; i++) { if (!strcmp(location, _location_str[i])) { _location = (location_t)i; break; } } const gchar * type = _repr->attribute("type"); for (int i = 0; i < TYPE_CNT && type != NULL; i++) { if (!strcmp(type, _type_str[i])) { _type = (type_t)i; break; } } _string = sp_repr_children(_repr)->content(); _description = _repr->attribute("description"); if (_description == NULL) _description = _repr->attribute("_description"); return; }
/** \return None \brief Builds a SPModuleOutput object from a XML description \param module The module to be initialized \param repr The XML description in a Inkscape::XML::Node tree Okay, so you want to build a SPModuleOutput object. This function first takes and does the build of the parent class, which is SPModule. Then, it looks for the <output> section of the XML description. Under there should be several fields which describe the output module to excruciating detail. Those are parsed, copied, and put into the structure that is passed in as module. Overall, there are many levels of indentation, just to handle the levels of indentation in the XML file. */ Output::Output (Inkscape::XML::Node * in_repr, Implementation::Implementation * in_imp) : Extension(in_repr, in_imp) { mimetype = NULL; extension = NULL; filetypename = NULL; filetypetooltip = NULL; dataloss = TRUE; if (repr != NULL) { Inkscape::XML::Node * child_repr; child_repr = sp_repr_children(repr); while (child_repr != NULL) { if (!strcmp(child_repr->name(), INKSCAPE_EXTENSION_NS "output")) { child_repr = sp_repr_children(child_repr); while (child_repr != NULL) { char const * chname = child_repr->name(); if (!strncmp(chname, INKSCAPE_EXTENSION_NS_NC, strlen(INKSCAPE_EXTENSION_NS_NC))) { chname += strlen(INKSCAPE_EXTENSION_NS); } if (chname[0] == '_') /* Allow _ for translation of tags */ chname++; if (!strcmp(chname, "extension")) { g_free (extension); extension = g_strdup(sp_repr_children(child_repr)->content()); } if (!strcmp(chname, "mimetype")) { g_free (mimetype); mimetype = g_strdup(sp_repr_children(child_repr)->content()); } if (!strcmp(chname, "filetypename")) { g_free (filetypename); filetypename = g_strdup(sp_repr_children(child_repr)->content()); } if (!strcmp(chname, "filetypetooltip")) { g_free (filetypetooltip); filetypetooltip = g_strdup(sp_repr_children(child_repr)->content()); } if (!strcmp(chname, "dataloss")) { if (!strcmp(sp_repr_children(child_repr)->content(), "false")) { dataloss = FALSE; } } child_repr = sp_repr_next(child_repr); } break; } child_repr = sp_repr_next(child_repr); } } }
/** \brief Use the superclass' allocator and set the \c _value */ ParamFloat::ParamFloat (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext), _value(0.0), _min(0.0), _max(10.0) { const gchar * defaultval = NULL; if (sp_repr_children(xml) != NULL) defaultval = sp_repr_children(xml)->content(); if (defaultval != NULL) { _value = g_ascii_strtod (defaultval,NULL); } const char * maxval = xml->attribute("max"); if (maxval != NULL) _max = g_ascii_strtod (maxval,NULL); const char * minval = xml->attribute("min"); if (minval != NULL) _min = g_ascii_strtod (minval,NULL); _precision = 1; const char * precision = xml->attribute("precision"); if (precision != NULL) _precision = atoi(precision); /* We're handling this by just killing both values */ if (_max < _min) { _max = 10.0; _min = 0.0; } gchar * pref_name = this->pref_name(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); _value = prefs->getDouble(extension_pref_root + pref_name, _value); g_free(pref_name); // std::cout << "New Float:: value: " << _value << " max: " << _max << " min: " << _min << std::endl; if (_value > _max) _value = _max; if (_value < _min) _value = _min; return; }
Effect::Effect (Inkscape::XML::Node * in_repr, Implementation::Implementation * in_imp) : Extension(in_repr, in_imp), _id_noprefs(Glib::ustring(get_id()) + ".noprefs"), _name_noprefs(Glib::ustring(_(get_name())) + _(" (No preferences)")), _verb(get_id(), get_name(), NULL, NULL, this, true), _verb_nopref(_id_noprefs.c_str(), _name_noprefs.c_str(), NULL, NULL, this, false), _menu_node(NULL), _workingDialog(true), _prefDialog(NULL) { Inkscape::XML::Node * local_effects_menu = NULL; // This is a weird hack if (!strcmp(this->get_id(), "org.inkscape.filter.dropshadow")) return; bool hidden = false; no_doc = false; no_live_preview = false; if (repr != NULL) { for (Inkscape::XML::Node *child = sp_repr_children(repr); child != NULL; child = child->next()) { if (!strcmp(child->name(), INKSCAPE_EXTENSION_NS "effect")) { if (child->attribute("needs-document") && !strcmp(child->attribute("needs-document"), "false")) { no_doc = true; } if (child->attribute("needs-live-preview") && !strcmp(child->attribute("needs-live-preview"), "false")) { no_live_preview = true; } for (Inkscape::XML::Node *effect_child = sp_repr_children(child); effect_child != NULL; effect_child = effect_child->next()) { if (!strcmp(effect_child->name(), INKSCAPE_EXTENSION_NS "effects-menu")) { // printf("Found local effects menu in %s\n", this->get_name()); local_effects_menu = sp_repr_children(effect_child); if (effect_child->attribute("hidden") && !strcmp(effect_child->attribute("hidden"), "true")) { hidden = true; } } if (!strcmp(effect_child->name(), INKSCAPE_EXTENSION_NS "menu-name") || !strcmp(effect_child->name(), INKSCAPE_EXTENSION_NS "_menu-name")) { // printf("Found local effects menu in %s\n", this->get_name()); _verb.set_name(sp_repr_children(effect_child)->content()); } if (!strcmp(effect_child->name(), INKSCAPE_EXTENSION_NS "menu-tip") || !strcmp(effect_child->name(), INKSCAPE_EXTENSION_NS "_menu-tip")) { // printf("Found local effects menu in %s\n", this->get_name()); _verb.set_tip(sp_repr_children(effect_child)->content()); } } // children of "effect" break; // there can only be one effect } // find "effect" } // children of "inkscape-extension" } // if we have an XML file if (INKSCAPE != NULL) { if (_effects_list == NULL) _effects_list = find_menu(inkscape_get_menus(INKSCAPE), EFFECTS_LIST); if (_filters_list == NULL) _filters_list = find_menu(inkscape_get_menus(INKSCAPE), FILTERS_LIST); } if ((_effects_list != NULL || _filters_list != NULL)) { Inkscape::XML::Document *xml_doc; xml_doc = _effects_list->document(); _menu_node = xml_doc->createElement("verb"); _menu_node->setAttribute("verb-id", this->get_id(), false); if (!hidden) { if (_filters_list && local_effects_menu && local_effects_menu->attribute("name") && !strcmp(local_effects_menu->attribute("name"), ("Filters"))) { merge_menu(_filters_list->parent(), _filters_list, sp_repr_children(local_effects_menu), _menu_node); } else if (_effects_list) { merge_menu(_effects_list->parent(), _effects_list, local_effects_menu, _menu_node); } } } return; }
ParamRadioButton::ParamRadioButton (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml, AppearanceMode mode) : Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext), _value(0), _mode(mode), choices(0) { // Read XML tree to add enumeration items: // printf("Extension Constructor: "); if (xml != NULL) { Inkscape::XML::Node *child_repr = sp_repr_children(xml); while (child_repr != NULL) { char const * chname = child_repr->name(); if (!strcmp(chname, INKSCAPE_EXTENSION_NS "option") || !strcmp(chname, INKSCAPE_EXTENSION_NS "_option")) { Glib::ustring * newguitext = NULL; Glib::ustring * newvalue = NULL; const char * contents = sp_repr_children(child_repr)->content(); if (contents != NULL) // don't translate when 'option' but do translate when '_option' newguitext = new Glib::ustring( !strcmp(chname, INKSCAPE_EXTENSION_NS "_option") ? _(contents) : contents ); else continue; const char * val = child_repr->attribute("value"); if (val != NULL) newvalue = new Glib::ustring(val); else newvalue = new Glib::ustring(contents); if ( (newguitext) && (newvalue) ) { // logical error if this is not true here choices = g_slist_append( choices, new optionentry(newvalue, newguitext) ); } } child_repr = sp_repr_next(child_repr); } } // Initialize _value with the default value from xml // for simplicity : default to the contents of the first xml-child const char * defaultval = NULL; if (choices) defaultval = ((optionentry*) choices->data)->value->c_str(); gchar * pref_name = this->pref_name(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); Glib::ustring paramval = prefs->getString(extension_pref_root + pref_name); g_free(pref_name); if (!paramval.empty()) defaultval = paramval.data(); if (defaultval != NULL) _value = g_strdup(defaultval); // allocate space for _value return; }
/** * \return The built module * \brief Creates a module from a Inkscape::XML::Document describing the module * \param doc The XML description of the module * * This function basically has two segments. The first is that it goes through the Repr tree * provided, and determines what kind of of module this is, and what kind of implementation to use. * All of these are then stored in two enums that are defined in this function. This makes it * easier to add additional types (which will happen in the future, I'm sure). * * Second, there is case statements for these enums. The first one is the type of module. This is * the one where the module is actually created. After that, then the implementation is applied to * get the load and unload functions. If there is no implementation then these are not set. This * case could apply to modules that are built in (like the SVG load/save functions). */ static Extension * build_from_reprdoc(Inkscape::XML::Document *doc, Implementation::Implementation *in_imp) { enum { MODULE_EXTENSION, MODULE_XSLT, /* MODULE_PLUGIN, */ MODULE_UNKNOWN_IMP } module_implementation_type = MODULE_UNKNOWN_IMP; enum { MODULE_INPUT, MODULE_OUTPUT, MODULE_FILTER, MODULE_PRINT, MODULE_PATH_EFFECT, MODULE_UNKNOWN_FUNC } module_functional_type = MODULE_UNKNOWN_FUNC; g_return_val_if_fail(doc != NULL, NULL); Inkscape::XML::Node *repr = doc->root(); /* sp_repr_print(repr); */ if (strcmp(repr->name(), INKSCAPE_EXTENSION_NS "inkscape-extension")) { g_warning("Extension definition started with <%s> instead of <" INKSCAPE_EXTENSION_NS "inkscape-extension>. Extension will not be created. See http://wiki.inkscape.org/wiki/index.php/Extensions for reference.\n", repr->name()); return NULL; } Inkscape::XML::Node *child_repr = sp_repr_children(repr); while (child_repr != NULL) { char const *element_name = child_repr->name(); /* printf("Child: %s\n", child_repr->name()); */ if (!strcmp(element_name, INKSCAPE_EXTENSION_NS "input")) { module_functional_type = MODULE_INPUT; } else if (!strcmp(element_name, INKSCAPE_EXTENSION_NS "output")) { module_functional_type = MODULE_OUTPUT; } else if (!strcmp(element_name, INKSCAPE_EXTENSION_NS "effect")) { module_functional_type = MODULE_FILTER; } else if (!strcmp(element_name, INKSCAPE_EXTENSION_NS "print")) { module_functional_type = MODULE_PRINT; } else if (!strcmp(element_name, INKSCAPE_EXTENSION_NS "path-effect")) { module_functional_type = MODULE_PATH_EFFECT; } else if (!strcmp(element_name, INKSCAPE_EXTENSION_NS "script")) { module_implementation_type = MODULE_EXTENSION; } else if (!strcmp(element_name, INKSCAPE_EXTENSION_NS "xslt")) { module_implementation_type = MODULE_XSLT; #if 0 } else if (!strcmp(element_name, "plugin")) { module_implementation_type = MODULE_PLUGIN; #endif } //Inkscape::XML::Node *old_repr = child_repr; child_repr = sp_repr_next(child_repr); //Inkscape::GC::release(old_repr); } Implementation::Implementation *imp; if (in_imp == NULL) { switch (module_implementation_type) { case MODULE_EXTENSION: { Implementation::Script *script = new Implementation::Script(); imp = static_cast<Implementation::Implementation *>(script); break; } case MODULE_XSLT: { Implementation::XSLT *xslt = new Implementation::XSLT(); imp = static_cast<Implementation::Implementation *>(xslt); break; } #if 0 case MODULE_PLUGIN: { Implementation::Plugin *plugin = new Implementation::Plugin(); imp = static_cast<Implementation::Implementation *>(plugin); break; } #endif default: { imp = NULL; break; } } } else { imp = in_imp; } Extension *module = NULL; switch (module_functional_type) { case MODULE_INPUT: { module = new Input(repr, imp); break; } case MODULE_OUTPUT: { module = new Output(repr, imp); break; } case MODULE_FILTER: { module = new Effect(repr, imp); break; } case MODULE_PRINT: { module = new Print(repr, imp); break; } case MODULE_PATH_EFFECT: { module = new PathEffect(repr, imp); break; } default: { break; } } return module; }