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

« back to all changes in this revision

Viewing changes to src/extension/internal/pdf-input-cairo.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
 * Simple PDF import extension using libpoppler and Cairo's SVG surface.
 
3
 *
 
4
 * Authors:
 
5
 *   miklos erdelyi
 
6
 *
 
7
 * Copyright (C) 2007 Authors
 
8
 *
 
9
 * Released under GNU GPL, read the file 'COPYING' for more information
 
10
 *
 
11
 */
 
12
 
 
13
#ifdef HAVE_CONFIG_H
 
14
# include <config.h>
 
15
#endif
 
16
 
 
17
#ifdef HAVE_POPPLER_GLIB
 
18
 
 
19
#include "pdf-input-cairo.h"
 
20
#include "extension/system.h"
 
21
#include "extension/input.h"
 
22
#include "document.h"
 
23
 
 
24
#include <cairo-svg.h>
 
25
#include <poppler/glib/poppler.h>
 
26
#include <poppler/glib/poppler-document.h>
 
27
#include <poppler/glib/poppler-page.h>
 
28
 
 
29
namespace Inkscape {
 
30
namespace Extension {
 
31
namespace Internal {
 
32
 
 
33
static cairo_status_t _write_ustring_cb(void *closure, const unsigned char *data, unsigned int length);
 
34
 
 
35
SPDocument *
 
36
PdfInputCairo::open(Inkscape::Extension::Input * mod, const gchar * uri) {
 
37
 
 
38
    printf("Attempting to open using PdfInputCairo\n");
 
39
 
 
40
    gchar* filename_uri = g_filename_to_uri(uri, NULL, NULL);
 
41
 
 
42
    PopplerDocument* document = poppler_document_new_from_file(filename_uri, NULL, NULL);
 
43
    if (document == NULL)
 
44
        return NULL;
 
45
 
 
46
    double width, height;
 
47
    PopplerPage* page = poppler_document_get_page(document, 0);
 
48
    poppler_page_get_size(page, &width, &height);
 
49
 
 
50
    Glib::ustring* output = new Glib::ustring("");
 
51
    cairo_surface_t* surface = cairo_svg_surface_create_for_stream(Inkscape::Extension::Internal::_write_ustring_cb,
 
52
                                                                   output, width, height);
 
53
    cairo_t* cr = cairo_create(surface);
 
54
 
 
55
    poppler_page_render(page, cr);
 
56
    cairo_show_page(cr);
 
57
 
 
58
    cairo_destroy(cr);
 
59
    cairo_surface_destroy(surface);
 
60
 
 
61
    SPDocument * doc = sp_document_new_from_mem(output->c_str(), output->length(), TRUE);
 
62
 
 
63
    delete output;
 
64
    g_object_unref(page);
 
65
    g_object_unref(document);
 
66
 
 
67
    return doc;
 
68
}
 
69
 
 
70
static cairo_status_t
 
71
        _write_ustring_cb(void *closure, const unsigned char *data, unsigned int length)
 
72
{
 
73
    Glib::ustring* stream = (Glib::ustring*)closure;
 
74
    stream->append((const char*)data, length);
 
75
 
 
76
    return CAIRO_STATUS_SUCCESS;
 
77
}
 
78
 
 
79
 
 
80
#include "clear-n_.h"
 
81
 
 
82
void
 
83
PdfInputCairo::init(void) {
 
84
    Inkscape::Extension::Extension * ext;
 
85
 
 
86
    ext = Inkscape::Extension::build_from_mem(
 
87
        "<inkscape-extension>\n"
 
88
            "<name>PDF Input</name>\n"
 
89
            "<id>org.inkscape.input.pdf</id>\n"
 
90
            "<input>\n"
 
91
                "<extension>.pdf</extension>\n"
 
92
                "<mimetype>application/pdf</mimetype>\n"
 
93
                "<filetypename>Adobe PDF (*.pdf)</filetypename>\n"
 
94
                "<filetypetooltip>PDF Document</filetypetooltip>\n"
 
95
            "</input>\n"
 
96
        "</inkscape-extension>", new PdfInputCairo());
 
97
} // init
 
98
 
 
99
} } }  /* namespace Inkscape, Extension, Implementation */
 
100
 
 
101
#endif /* HAVE_POPPLER_GLIB */
 
102
 
 
103
/*
 
104
  Local Variables:
 
105
  mode:c++
 
106
  c-file-style:"stroustrup"
 
107
  c-file-offsets:((innamespace . 0)(inline-open . 0))
 
108
  indent-tabs-mode:nil
 
109
  fill-column:99
 
110
  End:
 
111
*/
 
112
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :