~valavanisalex/ubuntu/oneiric/inkscape/inkscape_0.48.1-2ubuntu4

« back to all changes in this revision

Viewing changes to src/extension/internal/cairo-pdf-out.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook, Ted Gould, Kees Cook
  • Date: 2009-06-24 14:00:43 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20090624140043-07stp20mry48hqup
Tags: 0.47~pre0-0ubuntu1
* New upstream release

[ Ted Gould ]
* debian/control: Adding libgsl0 and removing version specifics on boost

[ Kees Cook ]
* debian/watch: updated to run uupdate and mangle pre-release versions.
* Dropped patches that have been taken upstream:
  - 01_mips
  - 02-poppler-0.8.3
  - 03-chinese-inkscape
  - 05_fix_latex_patch
  - 06_gcc-4.4
  - 07_cdr2svg
  - 08_skip-bad-utf-on-pdf-import
  - 09_gtk-clist
  - 10_belarussian
  - 11_libpng
  - 12_desktop
  - 13_slider
  - 100_svg_import_improvements
  - 102_sp_pattern_painter_free
  - 103_bitmap_type_print

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * A quick hack to use the print output to write out a file.  This
3
 
 * then makes 'save as...' PDF.
4
 
 *
5
 
 * Authors:
6
 
 *   Ted Gould <ted@gould.cx>
7
 
 *   Ulf Erikson <ulferikson@users.sf.net>
8
 
 *
9
 
 * Copyright (C) 2004-2006 Authors
10
 
 *
11
 
 * Released under GNU GPL, read the file 'COPYING' for more information
12
 
 */
13
 
 
14
 
#ifdef HAVE_CONFIG_H
15
 
# include <config.h>
16
 
#endif
17
 
 
18
 
#ifdef HAVE_CAIRO_PDF
19
 
 
20
 
#include "cairo-pdf-out.h"
21
 
#include <print.h>
22
 
#include "extension/system.h"
23
 
#include "extension/print.h"
24
 
#include "extension/db.h"
25
 
#include "extension/output.h"
26
 
#include "display/nr-arena.h"
27
 
#include "display/nr-arena-item.h"
28
 
#include "sp-path.h"
29
 
 
30
 
namespace Inkscape {
31
 
namespace Extension {
32
 
namespace Internal {
33
 
 
34
 
bool
35
 
CairoPdfOutput::check (Inkscape::Extension::Extension * module)
36
 
{
37
 
        if (NULL == Inkscape::Extension::db.get(SP_MODULE_KEY_PRINT_CAIRO_PDF))
38
 
                return FALSE;
39
 
 
40
 
        return TRUE;
41
 
}
42
 
 
43
 
 
44
 
static unsigned int
45
 
pdf_print_document_to_file(SPDocument *doc, gchar const *filename, unsigned int pdf_level, bool texttopath, bool filtertobitmap)
46
 
{
47
 
    Inkscape::Extension::Print *mod;
48
 
    SPPrintContext context;
49
 
    gchar const *oldconst;
50
 
    gchar *oldoutput;
51
 
    unsigned int ret;
52
 
 
53
 
    sp_document_ensure_up_to_date(doc);
54
 
 
55
 
    mod = Inkscape::Extension::get_print(SP_MODULE_KEY_PRINT_CAIRO_PDF);
56
 
    oldconst = mod->get_param_string("destination");
57
 
    oldoutput = g_strdup(oldconst);
58
 
    mod->set_param_string("destination", (gchar *)filename);
59
 
 
60
 
/* Start */
61
 
    context.module = mod;
62
 
    /* fixme: This has to go into module constructor somehow */
63
 
    /* Create new arena */
64
 
    mod->base = SP_ITEM(sp_document_root(doc));
65
 
    mod->arena = NRArena::create();
66
 
    mod->dkey = sp_item_display_key_new(1);
67
 
    mod->root = sp_item_invoke_show(mod->base, mod->arena, mod->dkey, SP_ITEM_SHOW_DISPLAY);
68
 
 
69
 
    /* Print document */
70
 
    ret = mod->begin(doc);
71
 
    if (ret) {
72
 
        sp_item_invoke_print(mod->base, &context);
73
 
        ret = mod->finish();
74
 
    }
75
 
 
76
 
    /* Release arena */
77
 
    sp_item_invoke_hide(mod->base, mod->dkey);
78
 
    mod->base = NULL;
79
 
    nr_arena_item_unref(mod->root);
80
 
    mod->root = NULL;
81
 
    nr_object_unref((NRObject *) mod->arena);
82
 
    mod->arena = NULL;
83
 
/* end */
84
 
 
85
 
    mod->set_param_string("destination", oldoutput);
86
 
    g_free(oldoutput);
87
 
 
88
 
    return ret;
89
 
}
90
 
 
91
 
 
92
 
/**
93
 
    \brief  This function calls the print system with the filename
94
 
        \param  mod   unused
95
 
        \param  doc   Document to be saved
96
 
    \param  uri   Filename to save to (probably will end in .pdf)
97
 
 
98
 
        The most interesting thing that this function does is just attach
99
 
        an '>' on the front of the filename.  This is the syntax used to
100
 
        tell the printing system to save to file.
101
 
*/
102
 
void
103
 
CairoPdfOutput::save (Inkscape::Extension::Output *mod, SPDocument *doc, const gchar *uri)
104
 
{
105
 
    Inkscape::Extension::Extension * ext;
106
 
    unsigned int ret;
107
 
 
108
 
    ext = Inkscape::Extension::db.get(SP_MODULE_KEY_PRINT_CAIRO_PDF);
109
 
    if (ext == NULL)
110
 
        return;
111
 
 
112
 
    bool old_textToPath  = FALSE;
113
 
    bool new_textToPath  = FALSE;
114
 
    try {
115
 
        old_textToPath  = ext->get_param_bool("textToPath");
116
 
        new_textToPath  = mod->get_param_bool("textToPath");
117
 
        ext->set_param_bool("textToPath", new_textToPath);
118
 
    }
119
 
    catch(...) {
120
 
        g_warning("Parameter <textToPath> might not exists");
121
 
    }
122
 
 
123
 
        gchar * final_name;
124
 
        final_name = g_strdup_printf("> %s", uri);
125
 
        ret = pdf_print_document_to_file(doc, final_name, 0, new_textToPath, false);
126
 
        g_free(final_name);
127
 
 
128
 
    try {
129
 
        ext->set_param_bool("textToPath", old_textToPath);
130
 
    }
131
 
    catch(...) {
132
 
        g_warning("Parameter <textToPath> might not exists");
133
 
    }
134
 
 
135
 
        if (!ret)
136
 
            throw Inkscape::Extension::Output::save_failed();
137
 
 
138
 
        return;
139
 
}
140
 
 
141
 
#include "clear-n_.h"
142
 
/**
143
 
        \brief   A function allocate a copy of this function.
144
 
 
145
 
        This is the definition of PDF out.  This function just
146
 
        calls the extension system with the memory allocated XML that
147
 
        describes the data.
148
 
*/
149
 
void
150
 
CairoPdfOutput::init (void)
151
 
{
152
 
        Inkscape::Extension::build_from_mem(
153
 
                "<inkscape-extension>\n"
154
 
                        "<name>" N_("Cairo PDF Output") "</name>\n"
155
 
                        "<id>org.inkscape.output.pdf.cairo</id>\n"
156
 
                        "<param name=\"PDFversion\" gui-text=\"" N_("Restrict to PDF version") "\" type=\"enum\" >\n"
157
 
                                "<_item value='PDF14'>" N_("PDF 1.4") "</_item>\n"
158
 
            "</param>\n"
159
 
                        "<param name=\"textToPath\" gui-text=\"" N_("Convert texts to paths") "\" type=\"boolean\">false</param>\n"
160
 
            "<output>\n"
161
 
                                "<extension>.pdf</extension>\n"
162
 
                                "<mimetype>application/pdf</mimetype>\n"
163
 
                                "<filetypename>" N_("PDF via Cairo (*.pdf)") "</filetypename>\n"
164
 
                                "<filetypetooltip>" N_("PDF File") "</filetypetooltip>\n"
165
 
                        "</output>\n"
166
 
                "</inkscape-extension>", new CairoPdfOutput());
167
 
 
168
 
        return;
169
 
}
170
 
 
171
 
} } }  /* namespace Inkscape, Extension, Implementation */
172
 
 
173
 
#endif /* HAVE_CAIRO_PDF */