From e85b6352e60bf65ccaa35128e80fbcad7bb7f9a9 Mon Sep 17 00:00:00 2001 From: keescook Date: Sun, 30 Dec 2007 00:45:38 +0000 Subject: [PATCH] rip out gtkmmification of print dialog, to temporarily solve LP: #176018 --- src/ui/dialog/print.cpp | 106 +++++++++++++++++++++++----------------- src/ui/dialog/print.h | 26 +++++++--- 2 files changed, 79 insertions(+), 53 deletions(-) diff --git a/src/ui/dialog/print.cpp b/src/ui/dialog/print.cpp index 3021b84b8..d1da36108 100644 --- a/src/ui/dialog/print.cpp +++ b/src/ui/dialog/print.cpp @@ -27,35 +27,21 @@ #include "helper/png-write.h" #include "svg/svg-color.h" -namespace Inkscape { -namespace UI { -namespace Dialog { - -void -Print::on_begin_print(const Glib::RefPtr &context) -{ - //printf("%s\n",__FUNCTION__); - set_n_pages (1); -} -bool -Print::on_paginate(const Glib::RefPtr &context) -{ - /* this should not be called since begin-print sets the n pages */ - //printf("%s\n",__FUNCTION__); - set_n_pages (1); - return false; -} - -void -Print::on_draw_page (const Glib::RefPtr &context, int page_nr) +static void +draw_page (GtkPrintOperation *operation, + GtkPrintContext *context, + gint page_nr, + gpointer user_data) { + struct workaround_gtkmm *junk = (struct workaround_gtkmm*)user_data; //printf("%s %d\n",__FUNCTION__, page_nr); - if (_tab.as_bitmap()) { + + if (junk->_tab->as_bitmap()) { // Render as exported PNG - gdouble width = sp_document_width(_doc); - gdouble height = sp_document_height(_doc); - gdouble dpi = _tab.bitmap_dpi(); + gdouble width = sp_document_width(junk->_doc); + gdouble height = sp_document_height(junk->_doc); + gdouble dpi = junk->_tab->bitmap_dpi(); std::string tmp_png; std::string tmp_base = "inkscape-print-png-XXXXXX"; @@ -64,13 +50,13 @@ Print::on_draw_page (const Glib::RefPtr &context, int page_nr close(tmp_fd); guint32 bgcolor = 0x00000000; - Inkscape::XML::Node *nv = sp_repr_lookup_name (_doc->rroot, "sodipodi:namedview"); + Inkscape::XML::Node *nv = sp_repr_lookup_name (junk->_doc->rroot, "sodipodi:namedview"); if (nv && nv->attribute("pagecolor")) bgcolor = sp_svg_read_color(nv->attribute("pagecolor"), 0xffffff00); if (nv && nv->attribute("inkscape:pageopacity")) bgcolor |= SP_COLOR_F_TO_U(sp_repr_get_double_attribute (nv, "inkscape:pageopacity", 1.0)); - sp_export_png_file(_doc, tmp_png.c_str(), 0.0, 0.0, + sp_export_png_file(junk->_doc, tmp_png.c_str(), 0.0, 0.0, width, height, (unsigned long)(width * dpi / PX_PER_IN), (unsigned long)(height * dpi / PX_PER_IN), @@ -87,11 +73,11 @@ Print::on_draw_page (const Glib::RefPtr &context, int page_nr // so do it in C: { Cairo::RefPtr png = Cairo::ImageSurface::create_from_png (tmp_png); - cairo_t *cr = context->get_cairo_context ()->cobj(); + cairo_t *cr = gtk_print_context_get_cairo_context (context); // FIXME: why is the origin offset?? cairo_set_source_surface(cr, png->cobj(), -16.0, -16.0); } - context->get_cairo_context ()->paint (); + cairo_paint(gtk_print_context_get_cairo_context (context)); // Clean up unlink (tmp_png.c_str()); @@ -104,11 +90,11 @@ Print::on_draw_page (const Glib::RefPtr &context, int page_nr // Render as vectors Inkscape::Extension::Internal::CairoRenderer renderer; Inkscape::Extension::Internal::CairoRenderContext *ctx = renderer.createContext(); - bool ret = ctx->setSurfaceTarget (context->get_cairo_context ()->get_target ()->cobj(), true); + bool ret = ctx->setSurfaceTarget (cairo_get_target (gtk_print_context_get_cairo_context (context)), true); if (ret) { - ret = renderer.setupDocument (ctx, _doc); + ret = renderer.setupDocument (ctx, junk->_doc); if (ret) { - renderer.renderItem(ctx, _base); + renderer.renderItem(ctx, junk->_base); ret = ctx->finish(); } else { @@ -125,40 +111,68 @@ Print::on_draw_page (const Glib::RefPtr &context, int page_nr } -Gtk::Widget * -Print::on_create_custom_widget () +static GObject* +create_custom_widget (GtkPrintOperation *operation, + gpointer user_data) { - return &_tab; + //printf("%s\n",__FUNCTION__); + return G_OBJECT(user_data); } +static void +begin_print (GtkPrintOperation *operation, + GtkPrintContext *context, + gpointer user_data) +{ + //printf("%s\n",__FUNCTION__); + gtk_print_operation_set_n_pages (operation, 1); +} + +namespace Inkscape { +namespace UI { +namespace Dialog { + Print::Print(SPDocument *doc, SPItem *base) : - Gtk::PrintOperation (), _doc (doc), - _base (base), - _tab () + _base (base) { g_assert (_doc); g_assert (_base); + _printop = gtk_print_operation_new (); + // set up dialog title, based on document name gchar *jobname = _doc->name ? _doc->name : _("SVG Document"); Glib::ustring title = _("Print"); title += " "; title += jobname; - set_job_name (title); - set_n_pages (1); + gtk_print_operation_set_job_name (_printop, title.c_str()); // set up paper size to match the document size - Glib::RefPtr page_setup = Gtk::PageSetup::create(); + GtkPageSetup *page_setup = gtk_page_setup_new(); gdouble doc_width = sp_document_width(_doc) * PT_PER_PX; gdouble doc_height = sp_document_height(_doc) * PT_PER_PX; - Gtk::PaperSize paper_size(Glib::ustring("custom"), Glib::ustring("custom"), - doc_width, doc_height, Gtk::UNIT_POINTS); - page_setup->set_paper_size (paper_size); - set_default_page_setup (page_setup); + GtkPaperSize *paper_size = gtk_paper_size_new_custom("custom", "custom", + doc_width, doc_height, GTK_UNIT_POINTS); + gtk_page_setup_set_paper_size (page_setup, paper_size); + gtk_print_operation_set_default_page_setup (_printop, page_setup); + + // set up signals + _workaround._doc = _doc; + _workaround._base = _base; + _workaround._tab = &_tab; + g_signal_connect (_printop, "create-custom-widget", G_CALLBACK (create_custom_widget), _tab.gobj()); + g_signal_connect (_printop, "begin-print", G_CALLBACK (begin_print), NULL); + g_signal_connect (_printop, "draw-page", G_CALLBACK (draw_page), &_workaround); // build custom preferences tab - set_custom_tab_label (Glib::ustring(_("Rendering"))); + gtk_print_operation_set_custom_tab_label (_printop, _("Rendering")); +} + +Gtk::PrintOperationResult Print::run(Gtk::PrintOperationAction, Gtk::Window&) +{ + gtk_print_operation_run (_printop, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, NULL, NULL); + return Gtk::PRINT_OPERATION_RESULT_APPLY; } diff --git a/src/ui/dialog/print.h b/src/ui/dialog/print.h index ee0d97da7..c8ef5e631 100644 --- a/src/ui/dialog/print.h +++ b/src/ui/dialog/print.h @@ -21,27 +21,39 @@ #include "ui/widget/rendering-options.h" +/* + * gtk 2.12.0 has a bug (http://bugzilla.gnome.org/show_bug.cgi?id=482089) + * where it fails to correctly deal with gtkmm signal management. As a result + * we have call gtk directly instead of doing a much cleaner version of + * this printing dialog, using full gtkmmification. (The bug was fixed + * in 2.12.1, so when the Inkscape gtk minimum version is bumped there, + * we can revert Inkscape commit 16865. + */ +struct workaround_gtkmm +{ + SPDocument *_doc; + SPItem *_base; + Inkscape::UI::Widget::RenderingOptions *_tab; +}; namespace Inkscape { namespace UI { namespace Dialog { -class Print : public Gtk::PrintOperation { +class Print { public: Print(SPDocument *doc, SPItem *base); + Gtk::PrintOperationResult run(Gtk::PrintOperationAction, Gtk::Window&); protected: - Gtk::Widget *on_create_custom_widget (); - - void on_begin_print(const Glib::RefPtr &context); - bool on_paginate(const Glib::RefPtr &context); - void on_draw_page (const Glib::RefPtr &context, - int page_nr); private: + GtkPrintOperation *_printop; SPDocument *_doc; SPItem *_base; Inkscape::UI::Widget::RenderingOptions _tab; + + struct workaround_gtkmm _workaround; }; } // namespace Dialog -- 2.30.2