Code

r19076@shi: ted | 2008-04-21 15:42:45 -0700
[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 #include "clear-n_.h"
94 /**
95     \brief   A function allocate a copy of this function.
97     This is the definition of postscript out.  This function just
98     calls the extension system with the memory allocated XML that
99     describes the data.
100 */
101 void
102 LatexOutput::init (void)
104     Inkscape::Extension::build_from_mem(
105         "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
106             "<name>" N_("LaTeX Output") "</name>\n"
107             "<id>org.inkscape.output.latex</id>\n"
108             "<output>\n"
109                 "<extension>.tex</extension>\n"
110                 "<mimetype>text/x-tex</mimetype>\n"
111                 "<filetypename>" N_("LaTeX With PSTricks macros (*.tex)") "</filetypename>\n"
112                 "<filetypetooltip>" N_("LaTeX PSTricks File") "</filetypetooltip>\n"
113             "</output>\n"
114         "</inkscape-extension>", new LatexOutput());
116     return;
119 } } }  /* namespace Inkscape, Extension, Implementation */
121 /*
122   Local Variables:
123   mode:cpp
124   c-file-style:"stroustrup"
125   c-file-offsets:((innamespace . 0)(inline-open . 0))
126   indent-tabs-mode:nil
127   fill-column:99
128   End:
129 */
130 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :