Code

API change: render methods now take a cairo_t (not yet used)
[inkscape.git] / src / extension / internal / ps.cpp
index a5208cfeeb935992eee029a3992e31583d8ba01d..a4eac8b67e1e39fad4b7d53a5f3f78b00851d964 100644 (file)
@@ -69,6 +69,7 @@
 #include <string>
 #include <iostream>
 #include <fstream>
+
 using namespace std;
 
 namespace Inkscape {
@@ -111,19 +112,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);
 
-    GtkWidget *dlg = gtk_dialog_new_with_buttons(_("Print Destination"),
+    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,
-            GTK_STOCK_PRINT,
+            destination ? GTK_STOCK_GO_FORWARD : GTK_STOCK_PRINT,
             GTK_RESPONSE_OK,
             NULL);
 
@@ -179,30 +182,31 @@ PrintPS::setup(Inkscape::Extension::Print * mod)
     GtkWidget *l = gtk_label_new(_("Resolution:"));
     gtk_box_pack_end(GTK_BOX(hb), l, FALSE, FALSE, 0);
 
-    /* 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);
+        // 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);
 
@@ -217,15 +221,19 @@ 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);
-        /* 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); */
 
+        /* 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);
-        mod->set_param_string("destination", (gchar *)fn);
         ret = TRUE;
     }
 
@@ -430,10 +438,12 @@ PrintPS::begin(Inkscape::Extension::Print *mod, SPDocument *doc)
                << d.x0 << " "
                << (_height - d.y0) << " "
                << d.x1 << "\n";
-            os << "%%DocumentMedia: plain "
-               << (int) ceil(_height) << " "
-               << (int) ceil(_width) << " "
-               << "0 () ()\n";
+            if (!epsexport) {
+                os << "%%DocumentMedia: plain "
+                   << (int) ceil(_height) << " "
+                   << (int) ceil(_width) << " "
+                   << "0 () ()\n";
+            }
         } else {
             os << "%%Orientation: Portrait\n";
             os << "%%BoundingBox: " << (int) d.x0 << " "
@@ -444,10 +454,12 @@ PrintPS::begin(Inkscape::Extension::Print *mod, SPDocument *doc)
                << d.y0 << " "
                << d.x1 << " "
                << d.y1 << "\n";
-            os << "%%DocumentMedia: plain "
-               << (int) ceil(_width) << " "
-               << (int) ceil(_height) << " "
-               << "0 () ()\n";
+            if (!epsexport) {
+                               os << "%%DocumentMedia: plain "
+                                  << (int) ceil(_width) << " "
+                  << (int) ceil(_height) << " "
+                  << "0 () ()\n";
+                       }
         }
 
         os << "%%EndComments\n";
@@ -544,7 +556,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;
@@ -577,12 +589,14 @@ PrintPS::finish(Inkscape::Extension::Print *mod)
        {
            while((c = fgetc(_stream))!=EOF) fputc(c, _begin_stream);
        }
-       fclose(_begin_stream);
+       fclose(_stream);
+       _stream = _begin_stream;
     }
 
     /* fixme: should really use pclose for popen'd streams */
     fclose(_stream);
-    _stream = 0;
+    _stream = NULL;
+
     _latin1_encoded_fonts.clear();
 
     g_tree_destroy(_fonts);
@@ -1333,10 +1347,16 @@ PrintPS::text(Inkscape::Extension::Print *mod, char const *text, NR::Point p,
                        "definefont} def\n";      // create the new font and leave it on the stack, define the proc
                _newlatin1font_proc_defined = true;
                }
-               os << "/" << fn << "-ISOLatin1 /" << fn << " newlatin1font\n";
+               if(strchr(fn, ' ') == NULL)
+                       os << "/" << fn << "-ISOLatin1 /" << fn << " newlatin1font\n";
+               else
+                       os << "(/" << fn << "-ISOLatin1) (/" << fn << ") newlatin1font\n";
                _latin1_encoded_fonts.insert(fn);
        } else
-               os << "/" << fn << "-ISOLatin1 findfont\n";
+               if(strchr(fn, ' ') == NULL)
+                       os << "/" << fn << "-ISOLatin1 findfont\n";
+               else
+                       os << "(/" << fn << "-ISOLatin1) findfont\n";
     }
     os << style->font_size.computed << " scalefont\n";
     os << "setfont\n";