pdf-input.cpp revision 3813663af1f94dff2fba7a0ab813fe79a2b3ecbe
/** \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"
#include "pdf-input.h"
#include "svg-builder.h"
#include "pdf-parser.h"
#include "document-private.h"
#include <gtk/gtkdialog.h>
namespace Inkscape {
namespace Extension {
namespace Internal {
/**
* \brief The PDF import dialog
*/
};
{
// 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 approximation for gradient meshes:")));
// Text options
_labelSelect->set_padding(0,0);
_labelSelect->set_line_wrap(false);
_labelSelect->set_use_markup(false);
_labelSelect->set_selectable(false);
_pageNumberSpin->set_numeric(true);
_pageNumberSpin->set_wrap(false);
_labelTotalPages->set_padding(0,0);
_labelTotalPages->set_line_wrap(false);
_labelTotalPages->set_use_markup(false);
_labelTotalPages->set_selectable(false);
_cropCheck->set_mode(true);
_cropCheck->set_active(false);
_labelPageSettings->set_padding(0,0);
_labelPageSettings->set_line_wrap(false);
_labelPageSettings->set_use_markup(true);
_labelPageSettings->set_selectable(false);
_labelPrecision->set_padding(0,0);
_labelPrecision->set_line_wrap(false);
_labelPrecision->set_use_markup(false);
_labelPrecision->set_selectable(false);
_fallbackPrecisionSlider->set_inverted(false);
_labelPrecisionComment->set_line_wrap(false);
_labelPrecisionComment->set_use_markup(false);
_labelPrecisionComment->set_selectable(false);
_labelText->set_padding(0,0);
_labelText->set_line_wrap(false);
_labelText->set_use_markup(false);
_labelText->set_selectable(false);
_embedImagesCheck->set_mode(true);
_embedImagesCheck->set_active(true);
_labelImportSettings->set_padding(0,0);
_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
// Create an OutputDev
_preview_output_dev = new CairoOutputDev();
_render_thumb = true;
#endif
// Set default preview size
_preview_width = 200;
_preview_height = 300;
// Init preview
_thumb_data = NULL;
}
#ifdef HAVE_POPPLER_CAIRO
if (_preview_output_dev) {
delete _preview_output_dev;
}
if (_cairo_surface) {
}
#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
72.0, 72.0, 0,
FALSE, /* useMediaBox */
TRUE, /* crop */
0, 0,
FALSE, /* printing */
_pdf_doc->getCatalog());
// 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();
}
delete pdf_doc;
if (error == errEncrypted) {
g_message("Document is encrypted.");
} 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"
"<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) [via poppler]</filetypename>\n"
"<filetypetooltip>Adobe Portable Document Format</filetypetooltip>\n"
"</input>\n"
"</inkscape-extension>", new PdfInput());
/* AI in */
"<inkscape-extension>\n"
"<name>AI Input</name>\n"
"<id>org.inkscape.input.ai</id>\n"
"<input>\n"
"<extension>.ai</extension>\n"
"<mimetype>image/x-adobe-illustrator</mimetype>\n"
"<filetypename>Adobe Illustrator (*.ai) [PDF-based]</filetypename>\n"
"<filetypetooltip>Open files saved with recent versions of Adobe Illustrator</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 :