summaryrefslogtreecommitdiffstats
path: root/src/ui
diff options
context:
space:
mode:
authorKees Cook <kees@outflux.net>2007-12-10 05:29:23 +0000
committerkeescook <keescook@users.sourceforge.net>2007-12-10 05:29:23 +0000
commit3bbfb29347465809918421d6dafcd5c0816935e1 (patch)
treeeb280d39803051efd86b1f496bfe130afa42787f /src/ui
parentalways build cairo backend; add interface for setting cairo surface to renderer (diff)
downloadinkscape-3bbfb29347465809918421d6dafcd5c0816935e1.tar.gz
inkscape-3bbfb29347465809918421d6dafcd5c0816935e1.zip
Implement cross-architecture print dialog using cairo and PNG backends.
(bzr r4199)
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/dialog/Makefile_insert2
-rw-r--r--src/ui/dialog/print.cpp170
-rw-r--r--src/ui/dialog/print.h66
-rw-r--r--src/ui/widget/Makefile_insert2
-rw-r--r--src/ui/widget/rendering-options.cpp101
-rw-r--r--src/ui/widget/rendering-options.h55
6 files changed, 396 insertions, 0 deletions
diff --git a/src/ui/dialog/Makefile_insert b/src/ui/dialog/Makefile_insert
index 64b8a3b04..f72838c7f 100644
--- a/src/ui/dialog/Makefile_insert
+++ b/src/ui/dialog/Makefile_insert
@@ -46,6 +46,8 @@ ui_dialog_libuidialog_a_SOURCES = \
ui/dialog/memory.h \
ui/dialog/messages.cpp \
ui/dialog/messages.h \
+ ui/dialog/print.cpp \
+ ui/dialog/print.h \
ui/dialog/scriptdialog.cpp \
ui/dialog/scriptdialog.h \
ui/dialog/text-properties.cpp \
diff --git a/src/ui/dialog/print.cpp b/src/ui/dialog/print.cpp
new file mode 100644
index 000000000..979b0522d
--- /dev/null
+++ b/src/ui/dialog/print.cpp
@@ -0,0 +1,170 @@
+/**
+ * \brief Print dialog
+ *
+ * Authors:
+ * Kees Cook <kees@outflux.net>
+ *
+ * Copyright (C) 2007 Kees Cook
+ *
+ * Released under GNU GPL. Read the file 'COPYING' for more information.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <gtkmm/stock.h>
+#include "print.h"
+
+#include "extension/internal/cairo-render-context.h"
+#include "extension/internal/cairo-renderer.h"
+#include "ui/widget/rendering-options.h"
+
+#include "unit-constants.h"
+#include "helper/png-write.h"
+#include "svg/svg-color.h"
+
+namespace Inkscape {
+namespace UI {
+namespace Dialog {
+
+void
+Print::_draw_page (const Glib::RefPtr<Gtk::PrintContext> &context,
+ int page_nr)
+{
+ if (_tab.as_bitmap()) {
+ // Render as exported PNG
+ gdouble width = sp_document_width(_doc);
+ gdouble height = sp_document_height(_doc);
+ gdouble dpi = _tab.bitmap_dpi();
+ std::string tmp_png;
+ std::string tmp_base = "inkscape-print-png-XXXXXX";
+
+ int tmp_fd;
+ if ( (tmp_fd = Glib::file_open_tmp (tmp_png, tmp_base)) >= 0) {
+ close(tmp_fd);
+
+ guint32 bgcolor = 0x00000000;
+ Inkscape::XML::Node *nv = sp_repr_lookup_name (_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,
+ width, height,
+ (unsigned long)width * dpi / PX_PER_IN,
+ (unsigned long)height * dpi / PX_PER_IN,
+ dpi, dpi, bgcolor, NULL, NULL, true, NULL);
+
+ // This doesn't seem to work:
+ //context->set_cairo_context ( Cairo::Context::create (Cairo::ImageSurface::create_from_png (tmp_png) ), dpi, dpi );
+ //
+ // so we'll use a surface pattern blat instead...
+ //
+ // but the C++ interface isn't implemented in cairomm:
+ //context->get_cairo_context ()->set_source_surface(Cairo::ImageSurface::create_from_png (tmp_png) );
+ //
+ // so do it in C:
+ {
+ Cairo::RefPtr<Cairo::ImageSurface> png = Cairo::ImageSurface::create_from_png (tmp_png);
+ cairo_t *cr = context->get_cairo_context ()->cobj();
+ // FIXME: why is the origin offset??
+ cairo_set_source_surface(cr, png->cobj(), -20.0, -20.0);
+ }
+ context->get_cairo_context ()->paint ();
+
+ // Clean up
+ unlink (tmp_png.c_str());
+ }
+ else {
+ g_warning(_("Could not open temporary PNG for bitmap printing"));
+ }
+ }
+ else {
+ // 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);
+ if (ret) {
+ ret = renderer.setupDocument (ctx, _doc);
+ if (ret) {
+ renderer.renderItem(ctx, _base);
+ ret = ctx->finish();
+ }
+ else {
+ g_warning(_("Could not set up Document"));
+ }
+ }
+ else {
+ g_warning(_("Failed to set CairoRenderContext"));
+ }
+
+ // Clean up
+ renderer.destroyContext(ctx);
+ }
+
+}
+
+Gtk::Widget *
+Print::_create_custom_widget ()
+{
+ return &_tab;
+}
+
+void
+Print::_custom_widget_apply (Gtk::Widget *widget)
+{
+ g_warning (_("custom widget apply"));
+}
+
+Print::Print(SPDocument *doc, SPItem *base) :
+ _doc (doc),
+ _base (base),
+ _tab ()
+{
+ g_assert (_doc);
+ g_assert (_base);
+
+ _printop = Gtk::PrintOperation::create();
+
+ // set up dialog title, based on document name
+ gchar *jobname = _doc->name ? _doc->name : _("SVG Document");
+ Glib::ustring title = _("Print");
+ title += " ";
+ title += jobname;
+ _printop->set_job_name (title);
+ _printop->set_n_pages (1);
+
+ // set up paper size to match the document size
+ Glib::RefPtr<Gtk::PageSetup> page_setup = Gtk::PageSetup::create();
+ 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);
+ _printop->set_default_page_setup (page_setup);
+
+ // build custom preferences tab
+ _printop->set_custom_tab_label (Glib::ustring(_("Rendering")));
+ _printop->signal_create_custom_widget().connect(sigc::mem_fun(*this, &Print::_create_custom_widget));
+// _printop->signal_custom_widget_apply().connect(sigc::mem_fun(*this, &Print::_custom_widget_apply));
+
+ // register actual page surface drawing callback
+ _printop->signal_draw_page().connect(sigc::mem_fun(*this, &Print::_draw_page));
+
+}
+
+Gtk::PrintOperationResult
+Print::run(Gtk::PrintOperationAction action)
+{
+ Gtk::PrintOperationResult res;
+ res = _printop->run (action);
+ return res;
+}
+
+
+} // namespace Dialog
+} // namespace UI
+} // namespace Inkscape
+
diff --git a/src/ui/dialog/print.h b/src/ui/dialog/print.h
new file mode 100644
index 000000000..d893efbf1
--- /dev/null
+++ b/src/ui/dialog/print.h
@@ -0,0 +1,66 @@
+/**
+ * \brief Print dialog
+ *
+ * Authors:
+ * Kees Cook <kees@outflux.net>
+ *
+ * Copyright (C) 2007 Kees Cook
+ *
+ * Released under GNU GPL. Read the file 'COPYING' for more information.
+ */
+
+#ifndef INKSCAPE_UI_DIALOG_PRINT_H
+#define INKSCAPE_UI_DIALOG_PRINT_H
+
+#include <glibmm/i18n.h>
+#include <gtkmm/printoperation.h> // GtkMM
+#include <gtk/gtkprintoperation.h> // Gtk
+
+#include "desktop.h"
+#include "sp-item.h"
+
+#include "ui/widget/rendering-options.h"
+
+
+namespace Inkscape {
+namespace UI {
+namespace Dialog {
+
+class Print {
+public:
+ Print(SPDocument *doc, SPItem *base);
+
+ Gtk::PrintOperationResult run(Gtk::PrintOperationAction action);
+ //GtkPrintOperationResult run(GtkPrintOperationAction action);
+
+protected:
+ Glib::RefPtr<Gtk::PrintOperation> _printop;
+ //GtkPrintOperation *_printop;
+
+ Gtk::Widget *_create_custom_widget ();
+ void _custom_widget_apply (Gtk::Widget *widget);
+ void _draw_page (const Glib::RefPtr<Gtk::PrintContext> &context,
+ int page_nr);
+
+private:
+ SPDocument *_doc;
+ SPItem *_base;
+ Inkscape::UI::Widget::RenderingOptions _tab;
+};
+
+} // namespace Dialog
+} // namespace UI
+} // namespace Inkscape
+
+#endif // INKSCAPE_UI_DIALOG_PRINT_H
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
diff --git a/src/ui/widget/Makefile_insert b/src/ui/widget/Makefile_insert
index c5bde795a..cfe163681 100644
--- a/src/ui/widget/Makefile_insert
+++ b/src/ui/widget/Makefile_insert
@@ -52,6 +52,8 @@ ui_widget_libuiwidget_a_SOURCES = \
ui/widget/registered-enums.h \
ui/widget/registry.cpp \
ui/widget/registry.h \
+ ui/widget/rendering-options.cpp \
+ ui/widget/rendering-options.h \
ui/widget/rotateable.h \
ui/widget/rotateable.cpp \
ui/widget/ruler.cpp \
diff --git a/src/ui/widget/rendering-options.cpp b/src/ui/widget/rendering-options.cpp
new file mode 100644
index 000000000..8a00bcc5d
--- /dev/null
+++ b/src/ui/widget/rendering-options.cpp
@@ -0,0 +1,101 @@
+/**
+ * \brief Rendering options widget
+ *
+ * Author:
+ * Kees Cook <kees@outflux.net>
+ *
+ * Copyright (C) 2007 Kees Cook
+ * Copyright (C) 2004 Bryce Harrington
+ *
+ * Released under GNU GPL. Read the file 'COPYING' for more information
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <glibmm/i18n.h>
+
+#include "unit-constants.h"
+#include "rendering-options.h"
+
+namespace Inkscape {
+namespace UI {
+namespace Widget {
+
+/**
+ * Construct a Rendering Options widget
+ *
+ */
+
+RenderingOptions::RenderingOptions () :
+ Gtk::VBox (),
+ //Labelled(label, tooltip, new Gtk::VBox(), suffix, icon, mnemonic),
+ _radio_cairo ( new Gtk::RadioButton () ),
+ //_radio_bitmap( new Gtk::RadioButton (_radio_cairo->get_group ()),
+ _radio_bitmap( new Gtk::RadioButton () ),
+ _widget_cairo( Glib::ustring(_("_Cairo")),
+ Glib::ustring(_("Render using Cairo vector operations. The resulting image is usually smaller in file "
+ "size and can be arbitrarily scaled, but some "
+ "filter effects will not be correctly rendered.")),
+ _radio_cairo,
+ Glib::ustring(""), Glib::ustring(""),
+ true),
+ _widget_bitmap(Glib::ustring(_("_Bitmap")),
+ Glib::ustring(_("Render everything as bitmap. The resulting image "
+ "is usually larger in file size and cannot be "
+ "arbitrarily scaled without quality loss, but all "
+ "objects will be rendered exactly as displayed.")),
+ _radio_bitmap,
+ Glib::ustring(""), Glib::ustring(""),
+ true),
+ _dpi( _("DPI"), Glib::ustring(_("Preferred resolution of rendering, in dots per inch.")),
+ 1,
+ Glib::ustring(""), Glib::ustring(""),
+ false)
+{
+ set_border_width(2);
+
+ // default to cairo operations
+ _radio_cairo->set_active (true);
+ Gtk::RadioButtonGroup group = _radio_cairo->get_group ();
+ _radio_bitmap->set_group (group);
+
+ // configure default DPI
+ _dpi.setRange(PT_PER_IN,2400.0);
+ _dpi.setValue(PT_PER_IN);
+
+ // fill up container
+ add (_widget_cairo);
+ add (_widget_bitmap);
+ add (_dpi);
+
+ show_all_children ();
+}
+
+bool
+RenderingOptions::as_bitmap ()
+{
+ return _radio_bitmap->get_active();
+}
+
+double
+RenderingOptions::bitmap_dpi ()
+{
+ return _dpi.getValue();
+}
+
+} // namespace Widget
+} // namespace UI
+} // namespace Inkscape
+
+/*
+ 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:encoding=utf-8:textwidth=99 :
diff --git a/src/ui/widget/rendering-options.h b/src/ui/widget/rendering-options.h
new file mode 100644
index 000000000..41134b814
--- /dev/null
+++ b/src/ui/widget/rendering-options.h
@@ -0,0 +1,55 @@
+/**
+ * \brief Rendering Options Widget - A container for selecting rendering options
+ *
+ * Author:
+ * Kees Cook <kees@outflux.net>
+ *
+ * Copyright (C) 2007 Kees Cook
+ * Copyright (C) 2004 Bryce Harrington
+ *
+ * Released under GNU GPL. Read the file 'COPYING' for more information.
+ */
+
+#ifndef INKSCAPE_UI_WIDGET_RENDERING_OPTIONS_H
+#define INKSCAPE_UI_WIDGET_RENDERING_OPTIONS_H
+
+#include "labelled.h"
+#include "scalar.h"
+
+namespace Inkscape {
+namespace UI {
+namespace Widget {
+
+class RenderingOptions : public Gtk::VBox
+{
+public:
+ RenderingOptions();
+
+ bool as_bitmap(); // should we render as a bitmap?
+ double bitmap_dpi(); // at what DPI should we render the bitmap?
+
+protected:
+ // Radio buttons to select desired rendering
+ Gtk::RadioButton *_radio_cairo;
+ Gtk::RadioButton *_radio_bitmap;
+ Labelled _widget_cairo;
+ Labelled _widget_bitmap;
+ Scalar _dpi; // DPI of bitmap to render
+};
+
+} // namespace Widget
+} // namespace UI
+} // namespace Inkscape
+
+#endif // INKSCAPE_UI_WIDGET_RENDERING_OPTIONS_H
+
+/*
+ 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:encoding=utf-8:textwidth=99 :