Inkscape
Vector Graphics Editor
|
Utility class used for loading and launching script extensions. More...
#include <script.h>
Classes | |
class | file_listener |
struct | interpreter_t |
A definition of an interpreter, which can be specified in the INX file, but we need to know what to call. More... | |
Public Member Functions | |
Script () | |
This function creates a script object and sets up the variables. More... | |
~Script () override | |
Destructor. More... | |
bool | load (Inkscape::Extension::Extension *module) override |
This function 'loads' an extension, basically it determines the full command for the extension and stores that. More... | |
void | unload (Inkscape::Extension::Extension *module) override |
Unload this puppy! More... | |
bool | check (Inkscape::Extension::Extension *module) override |
Check every dependency that was given to make sure we should keep this extension. More... | |
SPDocument * | new_from_template (Inkscape::Extension::Template *module) override |
Create a new document based on the given template. More... | |
void | resize_to_template (Inkscape::Extension::Template *tmod, SPDocument *doc, SPPage *page) override |
Take an existing document and selected page and resize or add items as needed. More... | |
SPDocument * | open (Inkscape::Extension::Input *module, gchar const *filename) override |
This function uses a filename that is put in, and calls the extension's command to create an SVG file which is returned. More... | |
void | save (Inkscape::Extension::Output *module, SPDocument *doc, gchar const *filename) override |
This function uses an extension to save a document. It first creates an SVG file of the document, and then runs it through the script. More... | |
void | export_raster (Inkscape::Extension::Output *module, const SPDocument *doc, std::string const &png_file, gchar const *filename) override |
void | effect (Inkscape::Extension::Effect *module, SPDesktop *desktop, ImplementationDocumentCache *docCache) override |
This function uses an extension as an effect on a document. More... | |
void | effect (Inkscape::Extension::Effect *module, SPDocument *document) override |
Pure document version for calling an extension from the command line. More... | |
bool | cancelProcessing () override |
Public Member Functions inherited from Inkscape::Extension::Implementation::Implementation | |
Implementation ()=default | |
virtual | ~Implementation ()=default |
virtual bool | load (Inkscape::Extension::Extension *) |
virtual void | unload (Inkscape::Extension::Extension *) |
virtual ImplementationDocumentCache * | newDocCache (Inkscape::Extension::Extension *, SPDesktop *) |
Create a new document cache object. More... | |
virtual bool | check (Inkscape::Extension::Extension *) |
Verify any dependencies. More... | |
virtual bool | cancelProcessing () |
virtual void | commitDocument () |
virtual SPDocument * | new_from_template (Inkscape::Extension::Template *) |
virtual void | get_template_presets (const Template *tmod, TemplatePresets &presets) const |
virtual void | resize_to_template (Inkscape::Extension::Template *tmod, SPDocument *doc, SPPage *page) |
virtual bool | match_template_size (Inkscape::Extension::Template *tmod, double width, double height) |
virtual SPDocument * | open (Inkscape::Extension::Input *, gchar const *) |
virtual void | save (Inkscape::Extension::Output *, SPDocument *, gchar const *) |
Find out information about the file. More... | |
virtual void | export_raster (Inkscape::Extension::Output *, const SPDocument *, std::string const &, gchar const *) |
virtual Gtk::Widget * | prefs_effect (Inkscape::Extension::Effect *module, SPDesktop *desktop, sigc::signal< void()> *changeSignal, ImplementationDocumentCache *docCache) |
Find out information about the file. More... | |
virtual void | effect (Inkscape::Extension::Effect *, SPDesktop *, ImplementationDocumentCache *) |
virtual void | effect (Inkscape::Extension::Effect *, SPDocument *document) |
virtual bool | apply_filter (Inkscape::Extension::Effect *module, SPItem *item) |
virtual unsigned | setup (Inkscape::Extension::Print *) |
virtual unsigned | set_preview (Inkscape::Extension::Print *) |
virtual unsigned | begin (Inkscape::Extension::Print *, SPDocument *) |
virtual unsigned | finish (Inkscape::Extension::Print *) |
virtual bool | textToPath (Inkscape::Extension::Print *) |
Tell the printing engine whether text should be text or path. More... | |
virtual bool | fontEmbedded (Inkscape::Extension::Print *) |
Get "fontEmbedded" param, i.e. More... | |
virtual unsigned | bind (Inkscape::Extension::Print *, Geom::Affine const &, float) |
virtual unsigned | release (Inkscape::Extension::Print *) |
virtual unsigned | fill (Inkscape::Extension::Print *, Geom::PathVector const &, Geom::Affine const &, SPStyle const *, Geom::OptRect const &, Geom::OptRect const &, Geom::OptRect const &) |
virtual unsigned | stroke (Inkscape::Extension::Print *, Geom::PathVector const &, Geom::Affine const &, SPStyle const *, Geom::OptRect const &, Geom::OptRect const &, Geom::OptRect const &) |
virtual unsigned | image (Inkscape::Extension::Print *, unsigned char *, unsigned int, unsigned int, unsigned int, Geom::Affine const &, SPStyle const *) |
virtual unsigned | text (Inkscape::Extension::Print *, char const *, Geom::Point const &, SPStyle const *) |
virtual void | processPath (Inkscape::XML::Node *) |
virtual void | setDetachBase (bool detach) |
If detach = true, when saving to a file, don't store URIs relative to the filename. More... | |
Private Member Functions | |
void | _change_extension (Inkscape::Extension::Extension *mod, SPDocument *doc, std::list< std::string > ¶ms, bool ignore_stderr) |
Internally, any modification of an existing document, used by effect and resize_page extensions. More... | |
void | showPopupError (Glib::ustring const &filename, Gtk::MessageType type, Glib::ustring const &message) |
This function checks the stderr file, and if it has data, shows it in a warning dialog to the user. More... | |
int | execute (const std::list< std::string > &in_command, const std::list< std::string > &in_params, const Glib::ustring &filein, file_listener &fileout, bool ignore_stderr=false) |
This is the core of the extension file as it actually does the execution of the extension. More... | |
void | pump_events () |
Make GTK+ events continue to come through a little bit. More... | |
std::string | resolveInterpreterExecutable (const Glib::ustring &interpNameArg) |
Look up an interpreter name, and translate to something that is executable. More... | |
Private Attributes | |
bool | _canceled |
Glib::Pid | _pid |
Glib::RefPtr< Glib::MainLoop > | _main_loop |
std::list< std::string > | command |
The command that has been derived from the configuration file with appropriate directories. More... | |
Glib::ustring | helper_extension |
This is the extension that will be used as the helper to read in or write out the data. More... | |
Gtk::Window * | parent_window |
The window which should be considered as "parent window" of the script execution, e.g. More... | |
Static Private Attributes | |
static const std::map< std::string, interpreter_t > | interpreterTab |
A table of what interpreters to call for a given language. More... | |
Utility class used for loading and launching script extensions.
Inkscape::Extension::Implementation::Script::Script | ( | ) |
This function creates a script object and sets up the variables.
This function just sets the command to NULL. It should get built officially in the load function. This allows for less allocation of memory in the unloaded state.
Definition at line 156 of file script.cpp.
|
overridedefault |
Destructor.
|
private |
Internally, any modification of an existing document, used by effect and resize_page extensions.
Definition at line 591 of file script.cpp.
References command, Inkscape::Extension::db, execute(), Inkscape::Extension::FILE_SAVE_METHOD_TEMPORARY, Inkscape::Preferences::get(), Inkscape::Extension::Extension::get_execution_env(), Inkscape::UI::gui_warning(), Inkscape::Extension::Extension::paramListString(), parent_window, pump_events(), SPDocument::rebase(), Inkscape::Extension::save(), Inkscape::Extension::Extension::set_environment(), Inkscape::Preferences::setBool(), sp_repr_read_file(), and Inkscape::Extension::Implementation::Script::file_listener::toFile().
Referenced by effect(), and resize_to_template().
|
overridevirtual |
Reimplemented from Inkscape::Extension::Implementation::Implementation.
Definition at line 670 of file script.cpp.
References _canceled, _main_loop, and _pid.
|
overridevirtual |
Check every dependency that was given to make sure we should keep this extension.
module | The Extension in question |
Reimplemented from Inkscape::Extension::Implementation::Implementation.
Definition at line 255 of file script.cpp.
References Inkscape::XML::Node::content(), Inkscape::Extension::db, Inkscape::XML::Node::firstChild(), Inkscape::Extension::Extension::get_repr(), Inkscape::XML::Node::name(), and Inkscape::XML::Node::next().
|
overridevirtual |
This function uses an extension as an effect on a document.
module | Extension to effect with. |
desktop | Desktop this extensions run on. |
doc | Document to run through the effect. |
This function is a little bit trickier than the previous two. It needs two temporary files to get its work done. Both of these files have random names created for them using the Glib::file_open_temp function with the ink_ext_ prefix in the temporary directory. Like the other functions, the temporary files are deleted at the end.
To save/load the two temporary documents (both are SVG) the internal modules for SVG load and save are used. They are both used through the module system function by passing their keys into the functions.
The command itself is built a little bit differently than in other functions because the effect support selections. So on the command line a list of all the ids that are selected is included. Currently, this only works for a single selected object, but there will be more. The command string is filled with the data, and then after the execution it is freed.
The execute function is used at the core of this function to execute the Script on the two SVG documents (actually only one exists at the time, the other is created by that script). At that point both should be full, and the second one is loaded.
Reimplemented from Inkscape::Extension::Implementation::Implementation.
Definition at line 533 of file script.cpp.
References _change_extension(), build_menu(), Inkscape::ObjectSet::clear(), command, execute(), Inkscape::Extension::Extension::get_id(), SPDesktop::getDocument(), SPDesktop::getSelection(), Inkscape::Extension::Effect::ignore_stderr, Inkscape::Extension::Effect::no_doc, Inkscape::Extension::Extension::paramListString(), Inkscape::Selection::params, Inkscape::Extension::refresh_user_extensions(), Inkscape::Extension::Extension::set_environment(), and sp_namedview_document_from_window().
|
overridevirtual |
Pure document version for calling an extension from the command line.
Reimplemented from Inkscape::Extension::Implementation::Implementation.
Definition at line 582 of file script.cpp.
References _change_extension(), and Geom::mod().
|
private |
This is the core of the extension file as it actually does the execution of the extension.
in_command | The command to be executed |
filein | Filename coming in |
fileout | Filename of the out file |
The first thing that this function does is build the command to be executed. This consists of the first string (in_command) and then the filename for input (filein). This file is put on the command line.
The next thing that this function does is open a pipe to the command and get the file handle in the ppipe variable. It then opens the output file with the output file handle. Both of these operations are checked extensively for errors.
After both are opened, then the data is copied from the output of the pipe into the file out using fread and fwrite. These two functions are used because of their primitive nature - they make no assumptions about the data. A buffer is used in the transfer, but the output of fread is stored so the exact number of bytes is handled gracefully.
At the very end (after the data has been copied) both of the files are closed, and we return to what we were doing.
Definition at line 708 of file script.cpp.
References _canceled, _main_loop, _pid, ActionsEdit::copy(), create, Inkscape::Extension::Implementation::Script::file_listener::init(), Inkscape::Extension::Implementation::Script::file_listener::isDead(), Inkscape::Extension::Implementation::Script::file_listener::read(), showPopupError(), and Inkscape::Extension::Implementation::Script::file_listener::string().
Referenced by _change_extension(), effect(), export_raster(), new_from_template(), open(), and save().
|
overridevirtual |
Reimplemented from Inkscape::Extension::Implementation::Implementation.
Definition at line 477 of file script.cpp.
References command, execute(), Inkscape::Extension::Output::is_raster(), Inkscape::Extension::Extension::paramListString(), Inkscape::Extension::Extension::set_environment(), and Inkscape::Extension::Implementation::Script::file_listener::toFile().
|
overridevirtual |
This function 'loads' an extension, basically it determines the full command for the extension and stores that.
module | The extension to be loaded. |
The most difficult part about this function is finding the actual command through all of the Reprs. Basically it is hidden down a couple of layers, and so the code has to move down too. When the command is actually found, it has its relative directory solved.
At that point all of the loops are exited, and there is an if statement to make sure they didn't exit because of not finding the command. If that's the case, the extension doesn't get loaded and should error out at a higher level.
Reimplemented from Inkscape::Extension::Implementation::Implementation.
Definition at line 188 of file script.cpp.
References Inkscape::XML::Node::attribute(), command, Inkscape::XML::Node::content(), Inkscape::XML::Node::firstChild(), Inkscape::Extension::Extension::get_dependency_location(), Inkscape::Extension::Extension::get_repr(), helper_extension, Inkscape::Extension::Extension::loaded(), Inkscape::XML::Node::name(), Inkscape::XML::Node::next(), and resolveInterpreterExecutable().
|
overridevirtual |
Create a new document based on the given template.
Reimplemented from Inkscape::Extension::Implementation::Implementation.
Definition at line 291 of file script.cpp.
References command, SPDocument::createDoc(), execute(), SPDocument::get_new_doc_number(), Inkscape::Extension::Template::get_template_filename(), Inkscape::Extension::Extension::paramListString(), Inkscape::Extension::Extension::set_environment(), sp_repr_read_mem(), and Inkscape::Extension::Implementation::Script::file_listener::string().
|
overridevirtual |
This function uses a filename that is put in, and calls the extension's command to create an SVG file which is returned.
module | Extension to use. |
filename | File to open. |
First things first, this function needs a temporary file name. To create one of those the function Glib::file_open_tmp is used with the header of ink_ext_.
The extension is then executed using the 'execute' function with the filename assigned and then the temporary filename. After execution the SVG should be in the temporary file.
Finally, the temporary file is opened using the SVG input module and a document is returned. That document has its filename set to the incoming filename (so that it's not the temporary filename). That document is then returned from this function.
Reimplemented from Inkscape::Extension::Implementation::Implementation.
Definition at line 351 of file script.cpp.
References SPDocument::changeFilenameAndHrefs(), command, Inkscape::Extension::db, execute(), helper_extension, Inkscape::Extension::open(), Inkscape::Extension::Extension::paramListString(), Inkscape::Extension::Extension::set_environment(), SPDocument::setDocumentBase(), and Inkscape::Extension::Implementation::Script::file_listener::toFile().
|
private |
Make GTK+ events continue to come through a little bit.
This just keeps coming the events through so that we'll make the GUI update and look pretty.
Definition at line 71 of file script.cpp.
Referenced by _change_extension().
|
overridevirtual |
Take an existing document and selected page and resize or add items as needed.
Reimplemented from Inkscape::Extension::Implementation::Implementation.
Definition at line 314 of file script.cpp.
References _change_extension(), SPObject::getId(), SPDocument::getRoot(), and page.
|
private |
Look up an interpreter name, and translate to something that is executable.
interpNameArg | The name of the interpreter that we're looking for, should be an entry in interpreterTab |
Definition at line 109 of file script.cpp.
References ActionsEdit::copy(), Inkscape::Preferences::get(), and interpreterTab.
Referenced by load().
|
overridevirtual |
This function uses an extension to save a document. It first creates an SVG file of the document, and then runs it through the script.
module | Extension to be used |
doc | Document to be saved |
filename | The name to save the final file as |
Well, at some point people need to save - it is really what makes the entire application useful. And, it is possible that someone would want to use an extension for this, so we need a function to do that, eh?
First things first, the document is saved to a temporary file that is an SVG file. To get the temporary filename Glib::file_open_tmp is used with ink_ext_ as a prefix. Don't worry, this file gets deleted at the end of the function.
After we have the SVG file, then Script::execute is called with the temporary file name and the final output filename. This should put the output of the script into the final output file. We then delete the temporary file.
Reimplemented from Inkscape::Extension::Implementation::Implementation.
Definition at line 426 of file script.cpp.
References command, Inkscape::Extension::db, execute(), Inkscape::Extension::FILE_SAVE_METHOD_TEMPORARY, helper_extension, Inkscape::Extension::Extension::paramListString(), Inkscape::Extension::save(), Inkscape::Extension::Extension::set_environment(), and Inkscape::Extension::Implementation::Script::file_listener::toFile().
|
private |
This function checks the stderr file, and if it has data, shows it in a warning dialog to the user.
filename | Filename of the stderr file |
Definition at line 640 of file script.cpp.
References data, Inkscape::UI::dialog_run(), Inkscape::UI::pack_start(), parent_window, and sp_transientize().
Referenced by execute().
|
overridevirtual |
Unload this puppy!
module | Extension to be unloaded. |
This function just sets the module to unloaded. It free's the command if it has been allocated.
Reimplemented from Inkscape::Extension::Implementation::Implementation.
Definition at line 240 of file script.cpp.
References command, and helper_extension.
|
private |
Definition at line 71 of file script.h.
Referenced by cancelProcessing(), and execute().
|
private |
Definition at line 73 of file script.h.
Referenced by cancelProcessing(), execute(), and Inkscape::Extension::Implementation::Script::file_listener::read().
|
private |
Definition at line 72 of file script.h.
Referenced by cancelProcessing(), and execute().
|
private |
The command that has been derived from the configuration file with appropriate directories.
Definition at line 81 of file script.h.
Referenced by _change_extension(), effect(), export_raster(), load(), new_from_template(), open(), save(), and unload().
|
private |
|
staticprivate |
A table of what interpreters to call for a given language.
This table is used to keep track of all the programs to execute a given script. It also tracks the preference to use to overwrite the given interpreter to a custom one per user.
Definition at line 132 of file script.h.
Referenced by resolveInterpreterExecutable().
|
private |
The window which should be considered as "parent window" of the script execution, e.g.
when showin warning messages
If set to NULL the main window of the currently active document is used.
Definition at line 96 of file script.h.
Referenced by _change_extension(), and showPopupError().