1 /*
2 * Authors:
3 * Michael Forbes <miforbes@mbhs.edu>
4 * Jon A. Cruz <jon@joncruz.org>
5 * Abhishek Sharma
6 *
7 * Copyright (C) 2004 Authors
8 *
9 * Released under GNU GPL, read the file 'COPYING' for more information
10 */
12 #ifdef HAVE_CONFIG_H
13 # include <config.h>
14 #endif
15 #include "latex-pstricks-out.h"
16 #include "sp-path.h"
17 #include <print.h>
18 #include "extension/system.h"
19 #include "extension/print.h"
20 #include "extension/db.h"
21 #include "display/nr-arena.h"
22 #include "display/nr-arena-item.h"
28 namespace Inkscape {
29 namespace Extension {
30 namespace Internal {
32 LatexOutput::LatexOutput (void) // The null constructor
33 {
34 return;
35 }
37 LatexOutput::~LatexOutput (void) //The destructor
38 {
39 return;
40 }
42 bool
43 LatexOutput::check (Inkscape::Extension::Extension * module)
44 {
45 if (NULL == Inkscape::Extension::db.get("org.inkscape.print.latex"))
46 return FALSE;
47 return TRUE;
48 }
51 void
52 LatexOutput::save(Inkscape::Extension::Output *mod2, SPDocument *doc, gchar const *filename)
53 {
54 Inkscape::Extension::Print *mod;
55 SPPrintContext context;
56 const gchar * oldconst;
57 gchar * oldoutput;
58 unsigned int ret;
60 doc->ensureUpToDate();
62 mod = Inkscape::Extension::get_print(SP_MODULE_KEY_PRINT_LATEX);
63 oldconst = mod->get_param_string("destination");
64 oldoutput = g_strdup(oldconst);
65 mod->set_param_string("destination", filename);
67 /* Start */
68 context.module = mod;
69 /* fixme: This has to go into module constructor somehow */
70 /* Create new arena */
71 mod->base = SP_ITEM(doc->getRoot());
72 mod->arena = NRArena::create();
73 mod->dkey = SPItem::display_key_new (1);
74 mod->root = (mod->base)->invoke_show (mod->arena, mod->dkey, SP_ITEM_SHOW_DISPLAY);
75 /* Print document */
76 ret = mod->begin (doc);
77 (mod->base)->invoke_print (&context);
78 ret = mod->finish ();
79 /* Release arena */
80 (mod->base)->invoke_hide (mod->dkey);
81 mod->base = NULL;
82 mod->root = NULL;
83 nr_object_unref ((NRObject *) mod->arena);
84 mod->arena = NULL;
85 /* end */
87 mod->set_param_string("destination", oldoutput);
88 g_free(oldoutput);
90 return;
91 }
93 #include "clear-n_.h"
95 /**
96 \brief A function allocate a copy of this function.
98 This is the definition of postscript out. This function just
99 calls the extension system with the memory allocated XML that
100 describes the data.
101 */
102 void
103 LatexOutput::init (void)
104 {
105 Inkscape::Extension::build_from_mem(
106 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
107 "<name>" N_("LaTeX Output") "</name>\n"
108 "<id>org.inkscape.output.latex</id>\n"
109 "<output>\n"
110 "<extension>.tex</extension>\n"
111 "<mimetype>text/x-tex</mimetype>\n"
112 "<filetypename>" N_("LaTeX With PSTricks macros (*.tex)") "</filetypename>\n"
113 "<filetypetooltip>" N_("LaTeX PSTricks File") "</filetypetooltip>\n"
114 "</output>\n"
115 "</inkscape-extension>", new LatexOutput());
117 return;
118 }
120 } } } /* namespace Inkscape, Extension, Implementation */
122 /*
123 Local Variables:
124 mode:cpp
125 c-file-style:"stroustrup"
126 c-file-offsets:((innamespace . 0)(inline-open . 0))
127 indent-tabs-mode:nil
128 fill-column:99
129 End:
130 */
131 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :