Code

d9db73fe6948f811a4ede122600af2b53071a2a5
[inkscape.git] / src / extension / internal / latex-pstricks-out.cpp
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, const gchar *uri)
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", (gchar *)uri);
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     nr_arena_item_unref (mod->root);
81     mod->root = NULL;
82     nr_object_unref ((NRObject *) mod->arena);
83     mod->arena = NULL;
84     /* end */
86     mod->set_param_string("destination", oldoutput);
87     g_free(oldoutput);
89     return;
90 }
92 /**
93     \brief   A function allocate a copy of this function.
95     This is the definition of postscript out.  This function just
96     calls the extension system with the memory allocated XML that
97     describes the data.
98 */
99 void
100 LatexOutput::init (void)
102     Inkscape::Extension::build_from_mem(
103         "<inkscape-extension>\n"
104             "<name>LaTeX Output</name>\n"
105             "<id>org.inkscape.output.latex</id>\n"
106             "<output>\n"
107                 "<extension>.tex</extension>\n"
108                 "<mimetype>text/plain</mimetype>\n"
109                 "<filetypename>LaTeX With PSTricks macros (*.tex)</filetypename>\n"
110                 "<filetypetooltip>LaTeX PSTricks File</filetypetooltip>\n"
111             "</output>\n"
112         "</inkscape-extension>", new LatexOutput());
114     return;
117 } } }  /* namespace Inkscape, Extension, Implementation */
119 /*
120   Local Variables:
121   mode:cpp
122   c-file-style:"stroustrup"
123   c-file-offsets:((innamespace . 0)(inline-open . 0))
124   indent-tabs-mode:nil
125   fill-column:99
126   End:
127 */
128 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :