Code

r19076@shi: ted | 2008-04-21 15:42:45 -0700
[inkscape.git] / src / extension / internal / ps-out.cpp
1 /*
2  * A quick hack to use the print output to write out a file.  This
3  * then makes 'save as...' Postscript.
4  *
5  * Authors:
6  *   Ted Gould <ted@gould.cx>
7  *
8  * Copyright (C) 2004 Authors
9  *
10  * Released under GNU GPL, read the file 'COPYING' for more information
11  */
13 #ifdef HAVE_CONFIG_H
14 # include <config.h>
15 #endif
16 #include "ps-out.h"
17 #include <print.h>
18 #include "extension/system.h"
19 #include "extension/db.h"
20 #include "extension/output.h"
22 namespace Inkscape {
23 namespace Extension {
24 namespace Internal {
26 bool
27 PsOutput::check( Inkscape::Extension::Extension * /*module*/ )
28 {
29     if (NULL == Inkscape::Extension::db.get(SP_MODULE_KEY_PRINT_PS))
30         return FALSE;
32     return TRUE;
33 }
35 /**
36     \brief  This function calls the print system with the filename
37         \param  mod   unused
38         \param  doc   Document to be saved
39     \param  uri   Filename to save to (probably will end in .ps)
41         The most interesting thing that this function does is just attach
42         an '>' on the front of the filename.  This is the syntax used to
43         tell the printing system to save to file.
44 */
45 void
46 PsOutput::save (Inkscape::Extension::Output *mod, SPDocument *doc, const gchar *uri)
47 {
48     Inkscape::Extension::Extension * ext;
50     ext = Inkscape::Extension::db.get(SP_MODULE_KEY_PRINT_PS);
51     if (ext == NULL)
52         return;
54     bool old_textToPath  = ext->get_param_bool("textToPath");
55     bool new_val         = mod->get_param_bool("textToPath");
56     ext->set_param_bool("textToPath", new_val);
58         gchar * final_name;
59         final_name = g_strdup_printf("> %s", uri);
60         sp_print_document_to_file(doc, final_name);
61         g_free(final_name);
63     ext->set_param_bool("textToPath", old_textToPath);
65         return;
66 }
68 #include "clear-n_.h"
70 /**
71         \brief   A function allocate a copy of this function.
73         This is the definition of postscript out.  This function just
74         calls the extension system with the memory allocated XML that
75         describes the data.
76 */
77 void
78 PsOutput::init (void)
79 {
80         Inkscape::Extension::build_from_mem(
81                 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
82                         "<name>" N_("Postscript Output") "</name>\n"
83                         "<id>org.inkscape.output.ps</id>\n"
84                         "<param name=\"textToPath\" gui-text=\"" N_("Convert texts to paths") "\" type=\"boolean\">true</param>\n"
85                         "<param name=\"fontEmbedded\" gui-text=\"" N_("Embed fonts (Type 1 only)") "\" type=\"boolean\">false</param>\n"
86                         "<output>\n"
87                                 "<extension>.ps</extension>\n"
88                                 "<mimetype>application/postscript</mimetype>\n"
89                                 "<filetypename>" N_("PostScript (*.ps)") "</filetypename>\n"
90                                 "<filetypetooltip>" N_("PostScript File") "</filetypetooltip>\n"
91                         "</output>\n"
92                 "</inkscape-extension>", new PsOutput());
94         return;
95 }
97 } } }  /* namespace Inkscape, Extension, Implementation */