pdf-input.cpp revision 400b8d183ba7c4109e8134ffdd44bf9cb9fa159e
/*
* Native PDF import using libpoppler.
*
* 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
#include "pdf-input.h"
#ifdef HAVE_POPPLER
#include <poppler/ErrorCodes.h>
#include <poppler/GlobalParams.h>
#ifdef HAVE_POPPLER_CAIRO
#endif
#include <gtkmm/alignment.h>
#include <gtkmm/comboboxtext.h>
#include <gtkmm/drawingarea.h>
#include "svg-builder.h"
#include "pdf-parser.h"
#include "document-private.h"
#include "document-undo.h"
#include "inkscape.h"
#include "dialogs/dialog-events.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")
};
{
#ifdef HAVE_POPPLER_CAIRO
_poppler_doc = NULL;
#endif // HAVE_POPPLER_CAIRO
// Page number
#if WITH_GTKMM_3_0
Glib::RefPtr<Gtk::Adjustment> _pageNumberSpin_adj = Gtk::Adjustment::create(1, 1, _pdf_doc->getNumPages(), 1, 10, 0);
#else
_pageNumberSpin = Gtk::manage(new class Inkscape::UI::Widget::SpinButton(*_pageNumberSpin_adj, 1, 1));
#endif
// 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.")));
#if WITH_GTKMM_3_0
#else
#endif
// 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);
_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);
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);
cancelbutton->show();
_labelSelect->show();
_pageNumberSpin->show();
_labelTotalPages->show();
_cropCheck->show();
_cropTypeCombo->show();
_labelPrecision->show();
_labelText->show();
_localFontsCheck->show();
_previewArea->show();
// Connect signals
#if WITH_GTKMM_3_0
#else
_previewArea->signal_expose_event().connect(sigc::mem_fun(*this, &PdfImportDialog::_onExposePreview));
#endif
_pageNumberSpin_adj->signal_value_changed().connect(sigc::mem_fun(*this, &PdfImportDialog::_onPageNumberChanged));
_fallbackPrecisionSlider_adj->signal_value_changed().connect(sigc::mem_fun(*this, &PdfImportDialog::_onPrecisionChanged));
_render_thumb = false;
#ifdef HAVE_POPPLER_CAIRO
_render_thumb = true;
// Create PopplerDocument
if (doc_uri) {
}
#endif
// Set default preview size
_preview_width = 200;
_preview_height = 300;
// Init preview
_thumb_data = NULL;
_current_page = 1;
set_default (*okbutton);
}
#ifdef HAVE_POPPLER_CAIRO
if (_cairo_surface) {
}
if (_poppler_doc) {
}
#endif
if (_thumb_data) {
if (_render_thumb) {
delete _thumb_data;
} else {
}
}
}
bool PdfImportDialog::showDialog() {
show();
hide();
if ( b == Gtk::RESPONSE_OK ) {
return TRUE;
} else {
return FALSE;
}
}
int PdfImportDialog::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 PdfImportDialog::_onPrecisionChanged() {
};
}
void PdfImportDialog::_onToggleCropping() {
}
void PdfImportDialog::_onPageNumberChanged() {
}
#ifdef HAVE_POPPLER_CAIRO
/**
* \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++;
}
}
}
#endif
/**
* \brief Updates the preview area with the previously rendered thumbnail
*/
#if !WITH_GTKMM_3_0
}
#endif
// 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) {
}
#ifdef HAVE_POPPLER_CAIRO
// Copy the thumbnail image from the Cairo surface
if (_render_thumb) {
}
#endif
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) {
_thumb_data = NULL;
}
return;
}
// Redraw preview area
return;
}
#ifdef HAVE_POPPLER_CAIRO
// Get page size by accounting for rotation
} else {
}
// 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
#endif
}
////////////////////////////////////////////////////////////////////////////////
bool
PdfInput::wasCancelled () {
return _cancelled;
}
/**
* Parses the selected page of the given PDF document using PdfParser.
*/
_cancelled = false;
// Initialize the globalParams variable for poppler
if (!globalParams) {
globalParams = new GlobalParams();
}
// poppler does not use glib g_open. So on win32 we must use unicode call. code was copied from glib gstdio.c
#ifndef WIN32
//delete filename_goo;
#else
return NULL;
}
PDFDoc *pdf_doc = new PDFDoc(wfilename, wcslen(wfilename), NULL, NULL, NULL); // TODO: Could ask for password
#endif
delete pdf_doc;
if (error == errEncrypted) {
g_message("Document is encrypted.");
} else if (error == errOpenFile) {
g_message("couldn't open the PDF file.");
} else if (error == errBadCatalog) {
g_message("couldn't read the page catalog.");
} else if (error == errDamaged) {
g_message("PDF file was damaged and couldn't be repaired.");
} else if (error == errHighlightFile) {
g_message("nonexistent or invalid highlight file.");
} else if (error == errBadPrinter) {
g_message("invalid printer.");
} else if (error == errPrinting) {
g_message("Error during printing.");
} else if (error == errPermission) {
g_message("PDF file does not allow that operation.");
} else if (error == errBadPageNum) {
g_message("invalid page number.");
g_message("file IO error.");
} else {
}
return NULL;
}
if (inkscape_use_gui()) {
if (!dlg->showDialog()) {
_cancelled = true;
delete dlg;
delete pdf_doc;
return NULL;
}
}
// Get needed page
int page_num;
if (dlg)
else
page_num = 1;
// Create builder
if (dot) {
*dot = 0;
}
// Get preferences
if (dlg)
// Apply crop settings
double crop_setting;
int crop_choice = (int)crop_setting;
switch (crop_choice) {
case 0: // Media box
break;
case 1: // Crop box
break;
case 2: // Bleed box
break;
case 3: // Trim box
break;
case 4: // Art box
break;
default:
break;
}
}
// Create parser
// Set up approximation precision for parser
double color_delta;
if ( color_delta <= 0.0 ) {
} else {
}
for ( int i = 1 ; i <= pdfNumShadingTypes ; i++ ) {
}
// Parse the document structure
}
// Cleanup
delete pdf_parser;
delete builder;
delete pdf_doc;
delete dlg;
// Restore undo
return doc;
}
#include "../clear-n_.h"
/* PDF in */
"<id>org.inkscape.input.pdf</id>\n"
"<input>\n"
"<extension>.pdf</extension>\n"
"<mimetype>application/pdf</mimetype>\n"
"</input>\n"
"</inkscape-extension>", new PdfInput());
/* AI in */
"<id>org.inkscape.input.ai</id>\n"
"<input>\n"
"<extension>.ai</extension>\n"
"<mimetype>image/x-adobe-illustrator</mimetype>\n"
"<filetypetooltip>" N_("Open files saved in Adobe Illustrator 9.0 and newer versions") "</filetypetooltip>\n"
"</input>\n"
"</inkscape-extension>", new PdfInput());
} // init
} } } /* namespace Inkscape, Extension, Implementation */
#endif /* HAVE_POPPLER */
/*
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 :