pdf-input-cairo.cpp revision 0f0f026a553fd84ffaaa90a368f87a842ecfcdd5
/*
* Simple PDF import extension using libpoppler and Cairo's SVG surface.
*
* Authors:
* miklos erdelyi
* Abhishek Sharma
*
* 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
#ifdef HAVE_POPPLER_CAIRO
#include "pdf-input-cairo.h"
#include "dialogs/dialog-events.h"
#include "document.h"
#include "inkscape.h"
#include <cairo-svg.h>
#include "ui/widget/spinbutton.h"
namespace Inkscape {
namespace Extension {
namespace Internal {
/**
* \brief The PDF import dialog
*/
static const gchar * crop_setting_choices[] = {
//TRANSLATORS: The following are document crop settings for PDF import
N_("media box"),
N_("crop box"),
N_("trim box"),
N_("bleed box"),
N_("art box")
};
{
// if there is no document, throw exception here
throw;
}
_poppler_doc = doc;
// Page number
Gtk::Adjustment *_pageNumberSpin_adj = Gtk::manage(new class Gtk::Adjustment(1, 1, num_pages, 1, 10, 0));
_pageNumberSpin = Gtk::manage(new class Inkscape::UI::Widget::SpinButton(*_pageNumberSpin_adj, 1, 1));
// Disable the page selector when there's only one page
if ( num_pages == 1 ) {
_pageNumberSpin->set_sensitive(false);
} else {
// Display total number of pages
}
// Crop settings
for ( int i = 0 ; i < num_crop_choices ; i++ ) {
}
_cropTypeCombo->set_sensitive(false);
_labelPrecision = Gtk::manage(new class Gtk::Label(_("Precision of approximating gradient meshes:")));
_labelPrecisionWarning = Gtk::manage(new class Gtk::Label(_("<b>Note</b>: setting the precision too high may result in a large SVG file and slow performance.")));
// Text options
_localFontsCheck = Gtk::manage(new class Gtk::CheckButton(_("Replace PDF fonts by closest-named installed fonts")));
_labelSelect->set_line_wrap(false);
_labelSelect->set_use_markup(false);
_labelSelect->set_selectable(false);
_pageNumberSpin->set_numeric(true);
_pageNumberSpin->set_wrap(false);
_labelTotalPages->set_line_wrap(false);
_labelTotalPages->set_use_markup(false);
_labelTotalPages->set_selectable(false);
_cropCheck->set_mode(true);
_cropCheck->set_active(false);
_labelPageSettings->set_line_wrap(false);
_labelPageSettings->set_use_markup(true);
_labelPageSettings->set_selectable(false);
_labelPrecision->set_line_wrap(true);
_labelPrecision->set_use_markup(false);
_labelPrecision->set_selectable(false);
_labelPrecisionWarning->set_line_wrap(true);
_labelPrecisionWarning->set_use_markup(true);
_labelPrecisionWarning->set_selectable(false);
_fallbackPrecisionSlider->set_inverted(false);
_labelPrecisionComment->set_line_wrap(false);
_labelPrecisionComment->set_use_markup(false);
_labelPrecisionComment->set_selectable(false);
_labelText->set_line_wrap(false);
_labelText->set_use_markup(false);
_labelText->set_selectable(false);
_localFontsCheck->set_mode(true);
_localFontsCheck->set_active(true);
_embedImagesCheck->set_mode(true);
_embedImagesCheck->set_active(true);
_labelImportSettings->set_line_wrap(false);
_labelImportSettings->set_use_markup(true);
_labelImportSettings->set_selectable(false);
this->get_vbox()->set_homogeneous(false);
this->get_vbox()->set_spacing(0);
this->set_title(_("PDF Import Settings"));
this->set_modal(true);
this->set_resizable(true);
this->property_destroy_with_parent().set_value(false);
this->set_has_separator(true);
cancelbutton->show();
_labelSelect->show();
_pageNumberSpin->show();
_labelTotalPages->show();
_cropCheck->show();
_cropTypeCombo->show();
alignment3->show();
_labelPrecision->show();
_labelText->show();
_localFontsCheck->show();
alignment4->show();
_previewArea->show();
// Connect signals
_previewArea->signal_expose_event().connect(sigc::mem_fun(*this, &PdfImportCairoDialog::_onExposePreview));
_pageNumberSpin_adj->signal_value_changed().connect(sigc::mem_fun(*this, &PdfImportCairoDialog::_onPageNumberChanged));
_cropCheck->signal_toggled().connect(sigc::mem_fun(*this, &PdfImportCairoDialog::_onToggleCropping));
_fallbackPrecisionSlider_adj->signal_value_changed().connect(sigc::mem_fun(*this, &PdfImportCairoDialog::_onPrecisionChanged));
_render_thumb = false;
_render_thumb = true;
// Set default preview size
_preview_width = 200;
_preview_height = 300;
// Init preview
_thumb_data = NULL;
_current_page = 1;
set_default (*okbutton);
}
if (_cairo_surface) {
}
if (_thumb_data) {
if (_render_thumb) {
delete _thumb_data;
} else {
// -->gfree(_thumb_data);
delete _thumb_data;
}
}
}
bool PdfImportCairoDialog::showDialog() {
show();
hide();
if ( b == Gtk::RESPONSE_OK ) {
return TRUE;
} else {
return FALSE;
}
}
int PdfImportCairoDialog::getSelectedPage() {
return _current_page;
}
/**
* \brief Retrieves the current settings into a repr which SvgBuilder will use
* for determining the behaviour desired by the user
*/
if (_cropCheck->get_active()) {
int i = 0;
for ( ; i < num_crop_choices ; i++ ) {
if ( current_choice == _(crop_setting_choices[i]) ) {
break;
}
}
} else {
}
if (_localFontsCheck->get_active()) {
} else {
}
if (_embedImagesCheck->get_active()) {
} else {
}
}
/**
* \brief Redisplay the comment on the current approximation precision setting
* Evenly divides the interval of possible values between the available labels.
*/
void PdfImportCairoDialog::_onPrecisionChanged() {
};
}
void PdfImportCairoDialog::_onToggleCropping() {
}
void PdfImportCairoDialog::_onPageNumberChanged() {
}
/**
* \brief Copies image data from a Cairo surface to a pixbuf
*
* Borrowed from libpoppler, from the file poppler-page.cc
* Copyright (C) 2005, Red Hat, Inc.
*
*/
unsigned char *data,
{
unsigned int *src;
int x, y;
cairo_data = data;
for (y = 0; y < cairo_height; y++)
{
for (x = 0; x < cairo_width; x++)
{
if (pixbuf_n_channels == 4)
dst += pixbuf_n_channels;
src++;
}
}
}
/**
* \brief Updates the preview area with the previously rendered thumbnail
*/
// Check if we have a thumbnail at all
if (!_thumb_data) {
return true;
}
// Create the pixbuf for the thumbnail
if (_render_thumb) {
} else {
}
if (!thumb) {
return true;
}
// Set background to white
if (_render_thumb) {
if (!back_pixmap) {
return true;
}
Gdk::RGB_DITHER_NONE, 0, 0);
}
// Copy the thumbnail image from the Cairo surface
if (_render_thumb) {
}
0, 0, 0, _render_thumb ? 0 : 20,
return true;
}
/**
* \brief Renders the given page's thumbnail using Cairo
*/
// Try to get a thumbnail from the PDF if possible
if (!_render_thumb) {
if (_thumb_data) {
// --> gfree(_thumb_data);
_thumb_data = NULL;
}
/*
--> if (!_previewed_page->loadThumb(&_thumb_data,
&_thumb_width, &_thumb_height, &_thumb_rowstride)) {
return;
}
*/
// Redraw preview area
return;
}
// Get page size by accounting for rotation
// --> int rotate = _previewed_page->getRotate();
int rotate = 0;
// --> height = _previewed_page->getCropWidth();
// --> width = _previewed_page->getCropHeight();
} else {
// --> width = _previewed_page->getCropWidth();
// --> height = _previewed_page->getCropHeight();
}
// Calculate the needed scaling for the page
// Create new Cairo surface
if (_thumb_data) {
delete _thumb_data;
}
if (_cairo_surface) {
}
// Render page
if (_poppler_doc != NULL) {
}
// Clean up
// Redraw preview area
}
static cairo_status_t _write_ustring_cb(void *closure, const unsigned char *data, unsigned int length);
g_message("Attempting to open using PdfInputCairo\n");
/// @todo handle passwort
/// @todo check if win32 unicode needs special attention
}
return NULL;
}
// create and show the import dialog
if (inkscape_use_gui()) {
if (!dlg->showDialog()) {
delete dlg;
return NULL;
}
}
// Get needed page
int page_num;
if (dlg) {
delete dlg;
}
else
page_num = 1;
cairo_surface_t* surface = cairo_svg_surface_create_for_stream(Inkscape::Extension::Internal::_write_ustring_cb,
delete output;
return doc;
}
static cairo_status_t
{
return CAIRO_STATUS_SUCCESS;
}
#include "clear-n_.h"
void
PdfInputCairo::init(void) {
"<name>PDF Input</name>\n"
"<id>org.inkscape.input.cairo-pdf</id>\n"
"<input>\n"
"<extension>.pdf</extension>\n"
"<mimetype>application/pdf</mimetype>\n"
"<filetypename>Adobe PDF via poppler-cairo (*.pdf)</filetypename>\n"
"<filetypetooltip>PDF Document</filetypetooltip>\n"
"</input>\n"
"</inkscape-extension>", new PdfInputCairo());
} // init
} } } /* namespace Inkscape, Extension, Implementation */
#endif /* HAVE_POPPLER_CAIRO */
#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 :