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