diff options
Diffstat (limited to 'src/extension/internal/pdfinput/pdf-input.cpp')
| -rw-r--r-- | src/extension/internal/pdfinput/pdf-input.cpp | 63 |
1 files changed, 40 insertions, 23 deletions
diff --git a/src/extension/internal/pdfinput/pdf-input.cpp b/src/extension/internal/pdfinput/pdf-input.cpp index d4fc6a8a2..3155ac098 100644 --- a/src/extension/internal/pdfinput/pdf-input.cpp +++ b/src/extension/internal/pdfinput/pdf-input.cpp @@ -32,6 +32,7 @@ #endif #include <gtkmm/alignment.h> +#include <gtkmm/checkbutton.h> #include <gtkmm/comboboxtext.h> #include <gtkmm/drawingarea.h> #include <gtkmm/frame.h> @@ -45,6 +46,7 @@ #include "document-private.h" #include "document-undo.h" #include "inkscape.h" +#include "util/units.h" #include "dialogs/dialog-events.h" #include <gtk/gtk.h> @@ -111,11 +113,7 @@ PdfImportDialog::PdfImportDialog(PDFDoc *doc, const gchar */*uri*/) _cropTypeCombo = Gtk::manage(new class Gtk::ComboBoxText()); int num_crop_choices = sizeof(crop_setting_choices) / sizeof(crop_setting_choices[0]); for ( int i = 0 ; i < num_crop_choices ; i++ ) { -#if WITH_GTKMM_2_24 _cropTypeCombo->append(_(crop_setting_choices[i])); -#else - _cropTypeCombo->append_text(_(crop_setting_choices[i])); -#endif } _cropTypeCombo->set_active_text(_(crop_setting_choices[0])); _cropTypeCombo->set_sensitive(false); @@ -128,7 +126,7 @@ PdfImportDialog::PdfImportDialog(PDFDoc *doc, const gchar */*uri*/) #if WITH_GTKMM_3_0 _fallbackPrecisionSlider_adj = Gtk::Adjustment::create(2, 1, 256, 1, 10, 10); - _fallbackPrecisionSlider = Gtk::manage(new class Gtk::HScale(_fallbackPrecisionSlider_adj)); + _fallbackPrecisionSlider = Gtk::manage(new class Gtk::Scale(_fallbackPrecisionSlider_adj)); #else _fallbackPrecisionSlider_adj = Gtk::manage(new class Gtk::Adjustment(2, 1, 256, 1, 10, 10)); _fallbackPrecisionSlider = Gtk::manage(new class Gtk::HScale(*_fallbackPrecisionSlider_adj)); @@ -140,11 +138,7 @@ PdfImportDialog::PdfImportDialog(PDFDoc *doc, const gchar */*uri*/) // Text options _labelText = Gtk::manage(new class Gtk::Label(_("Text handling:"))); _textHandlingCombo = Gtk::manage(new class Gtk::ComboBoxText()); -#if WITH_GTKMM_2_24 _textHandlingCombo->append(_("Import text as text")); -#else - _textHandlingCombo->append_text(_("Import text as text")); -#endif _textHandlingCombo->set_active_text(_("Import text as text")); _localFontsCheck = Gtk::manage(new class Gtk::CheckButton(_("Replace PDF fonts by closest-named installed fonts"))); @@ -248,12 +242,20 @@ PdfImportDialog::PdfImportDialog(PDFDoc *doc, const gchar */*uri*/) vbox1->pack_start(*_importSettingsFrame, Gtk::PACK_EXPAND_PADDING, 0); hbox1->pack_start(*vbox1); hbox1->pack_start(*_previewArea, Gtk::PACK_EXPAND_WIDGET, 4); + +#if WITH_GTKMM_3_0 + get_content_area()->set_homogeneous(false); + get_content_area()->set_spacing(0); + get_content_area()->pack_start(*hbox1); +#else this->get_vbox()->set_homogeneous(false); this->get_vbox()->set_spacing(0); this->get_vbox()->pack_start(*hbox1); +#endif + this->set_title(_("PDF Import Settings")); this->set_modal(true); - sp_transientize((GtkWidget *)this->gobj()); //Make transient + sp_transientize(GTK_WIDGET(this->gobj())); //Make transient this->property_window_position().set_value(Gtk::WIN_POS_NONE); this->set_resizable(true); this->property_destroy_with_parent().set_value(false); @@ -287,7 +289,12 @@ PdfImportDialog::PdfImportDialog(PDFDoc *doc, const gchar */*uri*/) hbox1->show(); // Connect signals +#if WITH_GTKMM_3_0 + _previewArea->signal_draw().connect(sigc::mem_fun(*this, &PdfImportDialog::_onDraw)); +#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)); _cropCheck->signal_toggled().connect(sigc::mem_fun(*this, &PdfImportDialog::_onToggleCropping)); _fallbackPrecisionSlider_adj->signal_value_changed().connect(sigc::mem_fun(*this, &PdfImportDialog::_onPrecisionChanged)); @@ -449,7 +456,7 @@ static void copy_cairo_surface_to_pixbuf (cairo_surface_t *surface, cairo_height = gdk_pixbuf_get_height (pixbuf); for (y = 0; y < cairo_height; y++) { - src = (unsigned int *) (cairo_data + y * cairo_rowstride); + src = reinterpret_cast<unsigned int *>(cairo_data + y * cairo_rowstride); dst = pixbuf_data + y * pixbuf_rowstride; for (x = 0; x < cairo_width; x++) { @@ -469,8 +476,14 @@ static void copy_cairo_surface_to_pixbuf (cairo_surface_t *surface, /** * \brief Updates the preview area with the previously rendered thumbnail */ -bool PdfImportDialog::_onExposePreview(GdkEventExpose */*event*/) { +#if !WITH_GTKMM_3_0 +bool PdfImportDialog::_onExposePreview(GdkEventExpose * /*event*/) { + Cairo::RefPtr<Cairo::Context> cr = _previewArea->get_window()->create_cairo_context(); + return _onDraw(cr); +} +#endif +bool PdfImportDialog::_onDraw(const Cairo::RefPtr<Cairo::Context>& cr) { // Check if we have a thumbnail at all if (!_thumb_data) { return true; @@ -478,6 +491,7 @@ bool PdfImportDialog::_onExposePreview(GdkEventExpose */*event*/) { // Create the pixbuf for the thumbnail Glib::RefPtr<Gdk::Pixbuf> thumb; + if (_render_thumb) { thumb = Gdk::Pixbuf::create(Gdk::COLORSPACE_RGB, true, 8, _thumb_width, _thumb_height); @@ -492,17 +506,8 @@ bool PdfImportDialog::_onExposePreview(GdkEventExpose */*event*/) { // Set background to white if (_render_thumb) { thumb->fill(0xffffffff); - Glib::RefPtr<Gdk::Pixmap> back_pixmap = Gdk::Pixmap::create( - _previewArea->get_window(), _thumb_width, _thumb_height, -1); - if (!back_pixmap) { - return true; - } - - Cairo::RefPtr<Cairo::Context> cr = back_pixmap->create_cairo_context(); Gdk::Cairo::set_source_pixbuf(cr, thumb, 0, 0); cr->paint(); - _previewArea->get_window()->set_back_pixmap(back_pixmap, false); - _previewArea->get_window()->clear(); } #ifdef HAVE_POPPLER_CAIRO // Copy the thumbnail image from the Cairo surface @@ -511,7 +516,6 @@ bool PdfImportDialog::_onExposePreview(GdkEventExpose */*event*/) { } #endif - Cairo::RefPtr<Cairo::Context> cr = _previewArea->get_window()->create_cairo_context(); Gdk::Cairo::set_source_pixbuf(cr, thumb, 0, _render_thumb ? 0 : 20); cr->paint(); return true; @@ -586,12 +590,19 @@ void PdfImportDialog::_setPreviewPage(int page) { //////////////////////////////////////////////////////////////////////////////// +bool +PdfInput::wasCancelled () { + return _cancelled; +} + /** * Parses the selected page of the given PDF document using PdfParser. */ SPDocument * PdfInput::open(::Inkscape::Extension::Input * /*mod*/, const gchar * uri) { + _cancelled = false; + // Initialize the globalParams variable for poppler if (!globalParams) { globalParams = new GlobalParams(); @@ -602,7 +613,7 @@ PdfInput::open(::Inkscape::Extension::Input * /*mod*/, const gchar * uri) { PDFDoc *pdf_doc = new PDFDoc(filename_goo, NULL, NULL, NULL); // TODO: Could ask for password //delete filename_goo; #else - wchar_t *wfilename = (wchar_t*)g_utf8_to_utf16 (uri, -1, NULL, NULL, NULL); + wchar_t *wfilename = reinterpret_cast<wchar_t*>(g_utf8_to_utf16 (uri, -1, NULL, NULL, NULL)); if (wfilename == NULL) { return NULL; @@ -646,6 +657,7 @@ PdfInput::open(::Inkscape::Extension::Input * /*mod*/, const gchar * uri) { if (inkscape_use_gui()) { dlg = new PdfImportDialog(pdf_doc, uri); if (!dlg->showDialog()) { + _cancelled = true; delete dlg; delete pdf_doc; return NULL; @@ -736,6 +748,11 @@ PdfInput::open(::Inkscape::Extension::Input * /*mod*/, const gchar * uri) { delete pdf_doc; delete dlg; + // Set viewBox if it doesn't exist + if (!doc->getRoot()->viewBox_set) { + doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().value(doc->getDefaultUnit()), doc->getHeight().value(doc->getDefaultUnit()))); + } + // Restore undo DocumentUndo::setUndoSensitive(doc, saved); |
