Code

Warning cleanup (including OFFSET_OF warning)
[inkscape.git] / src / extension / internal / ps.cpp
index c1c8bf49173d1977dca70cd67849a7306fe4111d..fedde86a2020989542902721f35c67641d61e89f 100644 (file)
@@ -34,6 +34,7 @@
 #include <libnr/n-art-bpath.h>
 
 #include <glib/gmem.h>
+#include <glib/gstrfuncs.h>
 #include <gtk/gtkstock.h>
 #include <gtk/gtkvbox.h>
 #include <gtk/gtkframe.h>
@@ -43,8 +44,6 @@
 #include <gtk/gtkentry.h>
 #include <gtk/gtktooltips.h>
 
-#include <gtk/gtkprintunixdialog.h>
-
 #include <glibmm/i18n.h>
 #include "display/nr-arena-item.h"
 #include "display/canvas-bpath.h"
 #include <string>
 #include <iostream>
 #include <fstream>
+#include <cstring>
+#include <cstdio>
+#include <cstdlib>
+#include <cmath>
 
+/*
+using std::atof;
+using std::ceil;
+using std::fclose;
+using std::ferror;
+using std::fflush;
+using std::fgetc;
+using std::fprintf;  --> this line will result  'std::libintl_fprintf' has not been declared
+using std::fputc;
+using std::fseek;
+using std::ifstream;
+using std::ios;
+using std::memset;
+using std::strchr;
+using std::strcmp;
+using std::strerror;
+using std::tmpfile;
+*/
 using namespace std;
 
 namespace Inkscape {
@@ -104,59 +125,6 @@ PrintPS::~PrintPS(void)
     return;
 }
 
-static void
-unix_print_complete (GtkPrintJob *print_job,
-                     gpointer user_data,
-                     GError *error)
-{
-    fprintf(stderr,"job finished: %s\n",error ? error->message : "no error");
-}
-
-static void
-unix_print_dialog (const gchar * ps_file, const gchar * jobname)
-{
-    GtkWidget* dlg = gtk_print_unix_dialog_new(_("Print"), NULL);
-
-/*
-    gtk_print_unix_dialog_add_custom_tab (GtkPrintUnixDialog *dialog,
-                                          GtkWidget *child,
-                                          GtkWidget *tab_label);
-*/
-
-    int const response = gtk_dialog_run(GTK_DIALOG(dlg));
-
-    if (response == GTK_RESPONSE_OK) {
-        GtkPrinter* printer = gtk_print_unix_dialog_get_selected_printer(GTK_PRINT_UNIX_DIALOG(dlg));
-
-        fprintf(stderr,"Selected printer '%s'\n",gtk_printer_get_name (printer));
-
-        if (gtk_printer_accepts_ps (printer)) {
-            GtkPrintJob* job = gtk_print_job_new  (jobname, printer,
-              gtk_print_unix_dialog_get_settings(GTK_PRINT_UNIX_DIALOG(dlg)),
-              gtk_print_unix_dialog_get_page_setup(GTK_PRINT_UNIX_DIALOG(dlg)));
-
-
-            GError * error = NULL;
-            if ( gtk_print_job_set_source_file (job, ps_file, &error)) {
-                fprintf(stderr,"sending...\n");
-                gtk_print_job_send (job, unix_print_complete, NULL, NULL);
-            }
-            else {
-                fprintf(stderr,"Could not set print source: %s\n",error ? error->message : "unknown error");
-            }
-        }
-        else {
-            fprintf(stderr,"Printer can't support PS output\n");
-        }
-    }
-    else if (response == GTK_RESPONSE_APPLY) {
-        fprintf(stderr,"preview not available\n");
-    }
-
-    gtk_widget_destroy(dlg);
-}
-
-
 unsigned int
 PrintPS::setup(Inkscape::Extension::Print * mod)
 {
@@ -167,27 +135,21 @@ PrintPS::setup(Inkscape::Extension::Print * mod)
 #endif
 
     unsigned int ret = FALSE;
+    gchar const *destination = mod->get_param_string("destination");
 
     /* Create dialog */
     GtkTooltips *tt = gtk_tooltips_new();
     g_object_ref((GObject *) tt);
     gtk_object_sink((GtkObject *) tt);
 
-#ifdef HAVE_GTK_UNIX_PRINT
-    GtkWidget *dlg = gtk_dialog_new_with_buttons(_("Print Configuration"),
-#else
-    GtkWidget *dlg = gtk_dialog_new_with_buttons(_("Print Destination"),
-#endif
+    GtkWidget *dlg = gtk_dialog_new_with_buttons(
+            destination ?  _("Print Configuration") : _("Print Destination"),
 //            SP_DT_WIDGET(SP_ACTIVE_DESKTOP)->window,
             NULL,
             (GtkDialogFlags) (GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT),
             GTK_STOCK_CANCEL,
             GTK_RESPONSE_CANCEL,
-#ifdef HAVE_GTK_UNIX_PRINT
-            GTK_STOCK_GO_FORWARD,
-#else
-            GTK_STOCK_PRINT,
-#endif
+            destination ? GTK_STOCK_GO_FORWARD : GTK_STOCK_PRINT,
             GTK_RESPONSE_OK,
             NULL);
 
@@ -243,32 +205,31 @@ PrintPS::setup(Inkscape::Extension::Print * mod)
     GtkWidget *l = gtk_label_new(_("Resolution:"));
     gtk_box_pack_end(GTK_BOX(hb), l, FALSE, FALSE, 0);
 
-#ifndef HAVE_GTK_UNIX_PRINT
-    /* Print destination frame */
-    f = gtk_frame_new(_("Print destination"));
-    gtk_box_pack_start(GTK_BOX(vbox), f, FALSE, FALSE, 4);
-    vb = gtk_vbox_new(FALSE, 4);
-    gtk_container_add(GTK_CONTAINER(f), vb);
-    gtk_container_set_border_width(GTK_CONTAINER(vb), 4);
-
-    l = gtk_label_new(_("Printer name (as given by lpstat -p);\n"
-                        "leave empty to use the system default printer.\n"
-                        "Use '> filename' to print to file.\n"
+    GtkWidget *e = NULL;
+    /* if the destination isn't already set, we must prompt for it */
+    if (!destination) {
+        /* Print destination frame */
+        f = gtk_frame_new(_("Print destination"));
+        gtk_box_pack_start(GTK_BOX(vbox), f, FALSE, FALSE, 4);
+        vb = gtk_vbox_new(FALSE, 4);
+        gtk_container_add(GTK_CONTAINER(f), vb);
+        gtk_container_set_border_width(GTK_CONTAINER(vb), 4);
+
+        l = gtk_label_new(_("Printer name (as given by lpstat -p);\n"
+                            "leave empty to use the system default printer.\n"
+                            "Use '> filename' to print to file.\n"
                         "Use '| prog arg...' to pipe to a program."));
-    gtk_box_pack_start(GTK_BOX(vb), l, FALSE, FALSE, 0);
+        gtk_box_pack_start(GTK_BOX(vb), l, FALSE, FALSE, 0);
 
-    GtkWidget *e = gtk_entry_new();
-    if (1) {
-        gchar const *val = mod->get_param_string("destination");
-        gtk_entry_set_text(GTK_ENTRY(e), ( val != NULL
-                                           ? val
+        e = gtk_entry_new();
+        gtk_entry_set_text(GTK_ENTRY(e), ( destination != NULL
+                                           ? destination
                                            : "" ));
-    }
-    gtk_box_pack_start(GTK_BOX(vb), e, FALSE, FALSE, 0);
+        gtk_box_pack_start(GTK_BOX(vb), e, FALSE, FALSE, 0);
 
-    // pressing enter in the destination field is the same as clicking Print:
-    gtk_entry_set_activates_default(GTK_ENTRY(e), TRUE);
-#endif
+        // pressing enter in the destination field is the same as clicking Print:
+        gtk_entry_set_activates_default(GTK_ENTRY(e), TRUE);
+    }
 
     gtk_widget_show_all(vbox);
 
@@ -283,24 +244,17 @@ PrintPS::setup(Inkscape::Extension::Print * mod)
         _bitmap = gtk_toggle_button_get_active((GtkToggleButton *) rb);
         sstr = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo)->entry));
         _dpi = (unsigned int) MAX((int)(atof(sstr)), 1);
-#ifndef HAVE_GTK_UNIX_PRINT
-        /* Arrgh, have to do something */
-        fn = gtk_entry_get_text(GTK_ENTRY(e));
-        /* skip leading whitespace, bug #1068483 */
-        while (fn && *fn==' ') { fn++; }
-        /* g_print("Printing to %s\n", fn); */
-
-        mod->set_param_string("destination", (gchar *)fn);
-#else
-        /* unix print dialog prints to a tempfile */
-        char * filename = strdup("/tmp/inkscape-ps-XXXXXX");
-        int tmpfd = mkstemp(filename);
-        close(tmpfd);
-        Glib::ustring dest = ">";
-        dest+=filename;
-        free(filename);
-        mod->set_param_string("destination", dest.c_str());
-#endif
+
+        /* if the destination was prompted for, record the new value */
+        if (e) {
+            /* Arrgh, have to do something */
+            fn = gtk_entry_get_text(GTK_ENTRY(e));
+            /* skip leading whitespace, bug #1068483 */
+            while (fn && *fn==' ') { fn++; }
+            /* g_print("Printing to %s\n", fn); */
+
+            mod->set_param_string("destination", (gchar *)fn);
+        }
         mod->set_param_bool("bitmap", _bitmap);
         mod->set_param_string("resolution", (gchar *)sstr);
         ret = TRUE;
@@ -342,7 +296,7 @@ PrintPS::begin(Inkscape::Extension::Print *mod, SPDocument *doc)
     if (fn != NULL) {
         if (*fn == '|') {
             fn += 1;
-            while (isspace(*fn)) fn += 1;
+            while (g_ascii_isspace(*fn)) fn += 1;
 #ifndef WIN32
             osp = popen(fn, "w");
 #else
@@ -359,7 +313,6 @@ PrintPS::begin(Inkscape::Extension::Print *mod, SPDocument *doc)
             epsexport = g_str_has_suffix(fn,".eps");
             while (isspace(*fn)) fn += 1;
             Inkscape::IO::dump_fopen_call(fn, "K");
-            _tmpfilename = fn;
             osf = Inkscape::IO::fopen_utf8name(fn, "w+");
             if (!osf) {
                 fprintf(stderr, "inkscape: fopen(%s): %s\n",
@@ -626,7 +579,7 @@ PrintPS::finish(Inkscape::Extension::Print *mod)
                                      bbox.x0, bbox.y0, bbox.x1, bbox.y1,
                                      (guchar*)px, 4 * width, FALSE, FALSE);
             memset(px, 0xff, 4 * width * 64);
-            nr_arena_item_invoke_render(mod->root, &bbox, &pb, 0);
+            nr_arena_item_invoke_render(NULL, mod->root, &bbox, &pb, 0);
             /* Blitter goes here */
             NRMatrix imgt;
             imgt.c[0] = (bbox.x1 - bbox.x0) / dots_per_pt;
@@ -663,15 +616,6 @@ PrintPS::finish(Inkscape::Extension::Print *mod)
        _stream = _begin_stream;
     }
 
-#ifdef HAVE_GTK_UNIX_PRINT
-    /* redirect output to new print dialog */
-    fseek(_stream, 0, SEEK_SET);
-    Glib::ustring output = _tmpfilename;
-    unix_print_dialog(output.c_str(),"job name");
-    unlink(output.c_str());
-    /* end redirected new print dialog */
-#endif
-
     /* fixme: should really use pclose for popen'd streams */
     fclose(_stream);
     _stream = NULL;
@@ -684,7 +628,7 @@ PrintPS::finish(Inkscape::Extension::Print *mod)
 }
 
 unsigned int
-PrintPS::bind(Inkscape::Extension::Print *mod, NRMatrix const *transform, float opacity)
+PrintPS::bind(Inkscape::Extension::Print */*mod*/, NRMatrix const *transform, float /*opacity*/)
 {
     if (!_stream) return 0;  // XXX: fixme, returning -1 as unsigned.
     if (_bitmap) return 0;
@@ -701,7 +645,7 @@ PrintPS::bind(Inkscape::Extension::Print *mod, NRMatrix const *transform, float
 }
 
 unsigned int
-PrintPS::release(Inkscape::Extension::Print *mod)
+PrintPS::release(Inkscape::Extension::Print */*mod*/)
 {
     if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned.
     if (_bitmap) return 0;
@@ -710,7 +654,7 @@ PrintPS::release(Inkscape::Extension::Print *mod)
 }
 
 unsigned int
-PrintPS::comment(Inkscape::Extension::Print *mod, char const *comment)
+PrintPS::comment(Inkscape::Extension::Print */*mod*/, char const *comment)
 {
     if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned.
     if (_bitmap) return 0;
@@ -721,18 +665,18 @@ PrintPS::comment(Inkscape::Extension::Print *mod, char const *comment)
 void
 PrintPS::print_fill_style(SVGOStringStream &os, SPStyle const *const style, NRRect const *pbox)
 {
-    g_return_if_fail( style->fill.type == SP_PAINT_TYPE_COLOR
-                      || ( style->fill.type == SP_PAINT_TYPE_PAINTSERVER
+    g_return_if_fail( style->fill.isColor()
+                      || ( style->fill.isPaintserver()
                            && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) ) );
 
-    if (style->fill.type == SP_PAINT_TYPE_COLOR) {
+    if (style->fill.isColor()) {
         float rgb[3];
         sp_color_get_rgb_floatv(&style->fill.value.color, rgb);
 
         os << rgb[0] << " " << rgb[1] << " " << rgb[2] << " setrgbcolor\n";
 
     } else {
-        g_assert( style->fill.type == SP_PAINT_TYPE_PAINTSERVER
+        g_assert( style->fill.isPaintserver()
                   && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) );
 
         if (SP_IS_LINEARGRADIENT(SP_STYLE_FILL_SERVER(style))) {
@@ -874,8 +818,8 @@ PrintPS::fill(Inkscape::Extension::Print *mod, NRBPath const *bpath, NRMatrix co
     if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned.
     if (_bitmap) return 0;
 
-    if ( style->fill.type == SP_PAINT_TYPE_COLOR
-         || ( style->fill.type == SP_PAINT_TYPE_PAINTSERVER
+    if ( style->fill.isColor()
+         || ( style->fill.isPaintserver()
               && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) ) )
     {
         Inkscape::SVGOStringStream os;
@@ -886,11 +830,11 @@ PrintPS::fill(Inkscape::Extension::Print *mod, NRBPath const *bpath, NRMatrix co
 
         print_bpath(os, bpath->path);
 
-        if (style->fill_rule.value == SP_WIND_RULE_EVENODD) {
-            if (style->fill.type == SP_PAINT_TYPE_COLOR) {
+        if (style->fill_rule.computed == SP_WIND_RULE_EVENODD) {
+            if (style->fill.isColor()) {
                 os << "eofill\n";
             } else {
-                g_assert( style->fill.type == SP_PAINT_TYPE_PAINTSERVER
+                g_assert( style->fill.isPaintserver()
                           && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) );
                 SPGradient const *g = SP_GRADIENT(SP_STYLE_FILL_SERVER(style));
                 os << "eoclip\n";
@@ -905,10 +849,10 @@ PrintPS::fill(Inkscape::Extension::Print *mod, NRBPath const *bpath, NRMatrix co
                 }
             }
         } else {
-            if (style->fill.type == SP_PAINT_TYPE_COLOR) {
+            if (style->fill.isColor()) {
                 os << "fill\n";
             } else {
-                g_assert( style->fill.type == SP_PAINT_TYPE_PAINTSERVER
+                g_assert( style->fill.isPaintserver()
                           && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) );
                 SPGradient const *g = SP_GRADIENT(SP_STYLE_FILL_SERVER(style));
                 os << "clip\n";
@@ -940,7 +884,7 @@ PrintPS::stroke(Inkscape::Extension::Print *mod, NRBPath const *bpath, NRMatrix
     if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned.
     if (_bitmap) return 0;
 
-    if (style->stroke.type == SP_PAINT_TYPE_COLOR) {
+    if (style->stroke.isColor()) {
         Inkscape::SVGOStringStream os;
 
         print_stroke_style(os, style);
@@ -1442,8 +1386,8 @@ PrintPS::text(Inkscape::Extension::Print *mod, char const *text, NR::Point p,
    //The commented line beneath causes Inkscape to crash under Linux but not under Windows
     //g_free((void*) fn);
 
-    if ( style->fill.type == SP_PAINT_TYPE_COLOR
-         || ( style->fill.type == SP_PAINT_TYPE_PAINTSERVER
+    if ( style->fill.isColor()
+         || ( style->fill.isPaintserver()
               && SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) ) )
     {
         // set fill style
@@ -1460,7 +1404,7 @@ PrintPS::text(Inkscape::Extension::Print *mod, char const *text, NR::Point p,
         os << ") show\n";
     }
 
-    if (style->stroke.type == SP_PAINT_TYPE_COLOR) {
+    if (style->stroke.isColor()) {
 
         // set stroke style
         print_stroke_style(os, style);