pdf-input.cpp revision b2c21717548a51f364ba57306cd3e32c2709e759
/** \file
* Native PDF import using libpoppler.
*
* 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
#include "goo/GooString.h"
#include "ErrorCodes.h"
#include "GlobalParams.h"
#include "PDFDoc.h"
#include "Page.h"
#include "Catalog.h"
#ifdef HAVE_POPPLER_CAIRO
#endif
#include "pdf-input.h"
#include "svg-builder.h"
#include "pdf-parser.h"
#include "document-private.h"
#include "dialogs/dialog-events.h"
#include <gtk/gtkdialog.h>
namespace Inkscape {
namespace Extension {
namespace Internal {
/**
* \brief The PDF import dialog
*/
};
{
#ifdef HAVE_POPPLER_CAIRO
_poppler_doc = NULL;
#endif // HAVE_POPPLER_CAIRO
// Page number
// 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
_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);
_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();
alignment4->show();
_previewArea->show();
// Connect signals
_previewArea->signal_expose_event().connect(sigc::mem_fun(*this, &PdfImportDialog::_onExposePreview));
_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 (_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
*/
// 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);
}
#ifdef HAVE_POPPLER_CAIRO
// Copy the thumbnail image from the Cairo surface
if (_render_thumb) {
}
#endif
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) {
_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
}
////////////////////////////////////////////////////////////////////////////////
/**
* Parses the selected page of the given PDF document using PdfParser.
*/
// 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 (!dlg->showDialog()) {
delete dlg;
delete pdf_doc;
return NULL;
}
// Get needed page
// Create builder
if (dot) {
*dot = 0;
}
// Get preferences
// 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;
// Restore undo
return doc;
}
#include "../clear-n_.h"
void
/* PDF in */
"<inkscape-extension>\n"
"<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 */
"<inkscape-extension>\n"
"<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 :