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