~ubuntu-branches/debian/experimental/inkscape/experimental

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-09-09 23:29:02 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20080909232902-c50iujhk1w79u8e7
Tags: 0.46-2.1
* Non-maintainer upload.
* Add upstream patch fixing a crash in the open dialog
  in the zh_CN.utf8 locale. Closes: #487623.
  Thanks to Luca Bruno for the patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * A quick hack to use the Cairo renderer to write out a file.  This
 
3
 * then makes 'save as...' PNG.
 
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-png-out.h"
 
21
#include "cairo-render-context.h"
 
22
#include "cairo-renderer.h"
 
23
#include <print.h>
 
24
#include "extension/system.h"
 
25
#include "extension/print.h"
 
26
#include "extension/db.h"
 
27
#include "extension/output.h"
 
28
#include "display/nr-arena.h"
 
29
#include "display/nr-arena-item.h"
 
30
 
 
31
#include <libnr/n-art-bpath.h>
 
32
 
 
33
#include "display/curve.h"
 
34
#include "display/canvas-bpath.h"
 
35
#include "sp-item.h"
 
36
#include "style.h"
 
37
#include "sp-root.h"
 
38
#include "sp-shape.h"
 
39
 
 
40
#include "io/sys.h"
 
41
 
 
42
namespace Inkscape {
 
43
namespace Extension {
 
44
namespace Internal {
 
45
 
 
46
bool
 
47
CairoRendererOutput::check (Inkscape::Extension::Extension * module)
 
48
{
 
49
        return TRUE;
 
50
}
 
51
 
 
52
static bool
 
53
png_render_document_to_file(SPDocument *doc, gchar const *filename)
 
54
{
 
55
    CairoRenderer *renderer;
 
56
    CairoRenderContext *ctx;
 
57
 
 
58
    sp_document_ensure_up_to_date(doc);
 
59
 
 
60
/* Start */
 
61
    /* Create new arena */
 
62
    SPItem *base = SP_ITEM(sp_document_root(doc));
 
63
    NRArena *arena = NRArena::create();
 
64
    unsigned dkey = sp_item_display_key_new(1);
 
65
    NRArenaItem *root = sp_item_invoke_show(base, arena, dkey, SP_ITEM_SHOW_DISPLAY);
 
66
    
 
67
    /* Create renderer and context */
 
68
    renderer = new CairoRenderer();
 
69
    ctx = renderer->createContext();
 
70
 
 
71
    /* Render document */
 
72
    bool ret = renderer->setupDocument(ctx, doc);
 
73
    if (ret) {
 
74
        renderer->renderItem(ctx, base);
 
75
        ctx->saveAsPng(filename);
 
76
        ret = ctx->finish();
 
77
    }
 
78
    renderer->destroyContext(ctx);
 
79
 
 
80
    /* Release arena */
 
81
    sp_item_invoke_hide(base, dkey);
 
82
    nr_arena_item_unref(root);
 
83
    nr_object_unref((NRObject *) arena);
 
84
/* end */
 
85
    delete renderer;
 
86
 
 
87
    return ret;
 
88
}
 
89
 
 
90
 
 
91
/**
 
92
    \brief  This function calls the output module with the filename
 
93
        \param  mod   unused
 
94
        \param  doc   Document to be saved
 
95
    \param  uri   Filename to save to (probably will end in .png)
 
96
*/
 
97
void
 
98
CairoRendererOutput::save (Inkscape::Extension::Output *mod, SPDocument *doc, const gchar *uri)
 
99
{
 
100
    if (!png_render_document_to_file(doc, uri))
 
101
        throw Inkscape::Extension::Output::save_failed();
 
102
 
 
103
        return;
 
104
}
 
105
 
 
106
/**
 
107
        \brief   A function allocate a copy of this function.
 
108
 
 
109
        This is the definition of Cairo PNG out.  This function just
 
110
        calls the extension system with the memory allocated XML that
 
111
        describes the data.
 
112
*/
 
113
void
 
114
CairoRendererOutput::init (void)
 
115
{
 
116
        Inkscape::Extension::build_from_mem(
 
117
                "<inkscape-extension>\n"
 
118
                        "<name>Cairo PNG Output</name>\n"
 
119
                        "<id>org.inkscape.output.png.cairo</id>\n"
 
120
                        "<output>\n"
 
121
                                "<extension>.png</extension>\n"
 
122
                "<mimetype>image/png</mimetype>\n"
 
123
                                "<filetypename>Cairo PNG (*.png)</filetypename>\n"
 
124
                                "<filetypetooltip>PNG File</filetypetooltip>\n"
 
125
                        "</output>\n"
 
126
                "</inkscape-extension>", new CairoRendererOutput());
 
127
 
 
128
        return;
 
129
}
 
130
 
 
131
} } }  /* namespace Inkscape, Extension, Implementation */
 
132
 
 
133
#endif /* HAVE_CAIRO_PDF */