Code

Export. Fix PS/EPS export (Bug #698340, PS Level Restriction reversed.
[inkscape.git] / src / extension / internal / cairo-ps-out.cpp
index 737bb2885a25cdcd6e261dd5a318a8694d4556af..a5b7b32377e46d13b71982a2dfee2a0488845a1e 100644 (file)
@@ -6,6 +6,8 @@
  *   Ted Gould <ted@gould.cx>
  *   Ulf Erikson <ulferikson@users.sf.net>
  *   Adib Taraben <theAdib@yahoo.com>
+ *   Jon A. Cruz <jon@joncruz.org>
+ *   Abhishek Sharma
  *
  * Copyright (C) 2004-2006 Authors
  *
@@ -21,6 +23,7 @@
 #include "cairo-ps-out.h"
 #include "cairo-render-context.h"
 #include "cairo-renderer.h"
+#include "latex-text-renderer.h"
 #include <print.h>
 #include "extension/system.h"
 #include "extension/print.h"
@@ -61,9 +64,10 @@ bool CairoEpsOutput::check (Inkscape::Extension::Extension * /*module*/)
 }
 
 static bool
-ps_print_document_to_file(SPDocument *doc, gchar const *filename, unsigned int level, bool texttopath, bool filtertobitmap, int resolution, const gchar * const exportId, bool exportDrawing, bool exportCanvas, bool eps = false)
+ps_print_document_to_file(SPDocument *doc, gchar const *filename, unsigned int level, bool texttopath, bool omittext,
+                          bool filtertobitmap, int resolution, const gchar * const exportId, bool exportDrawing, bool exportCanvas, bool eps = false)
 {
-    sp_document_ensure_up_to_date(doc);
+    doc->ensureUpToDate();
 
     SPItem *base = NULL;
 
@@ -75,7 +79,7 @@ ps_print_document_to_file(SPDocument *doc, gchar const *filename, unsigned int l
     }
     else {
         // we want to export the entire document from root
-        base = SP_ITEM(sp_document_root(doc));
+        base = SP_ITEM(doc->getRoot());
         pageBoundingBox = !exportDrawing;
     }
 
@@ -84,8 +88,8 @@ ps_print_document_to_file(SPDocument *doc, gchar const *filename, unsigned int l
 
     /* Create new arena */
     NRArena *arena = NRArena::create();
-    unsigned dkey = sp_item_display_key_new(1);
-    sp_item_invoke_show(base, arena, dkey, SP_ITEM_SHOW_DISPLAY);
+    unsigned dkey = SPItem::display_key_new(1);
+    base->invoke_show(arena, dkey, SP_ITEM_SHOW_DISPLAY);
 
     /* Create renderer and context */
     CairoRenderer *renderer = new CairoRenderer();
@@ -93,6 +97,7 @@ ps_print_document_to_file(SPDocument *doc, gchar const *filename, unsigned int l
     ctx->setPSLevel(level);
     ctx->setEPS(eps);
     ctx->setTextToPath(texttopath);
+    renderer->_omitText = omittext;
     ctx->setFilterToBitmap(filtertobitmap);
     ctx->setBitmapResolution(resolution);
 
@@ -107,7 +112,7 @@ ps_print_document_to_file(SPDocument *doc, gchar const *filename, unsigned int l
     }
 
     /* Release arena */
-    sp_item_invoke_hide(base, dkey);
+    base->invoke_hide(dkey);
     nr_object_unref((NRObject *) arena);
 
     renderer->destroyContext(ctx);
@@ -137,7 +142,7 @@ CairoPsOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar con
     int level = CAIRO_PS_LEVEL_2;
     try {
         new_level = mod->get_param_enum("PSlevel");
-        if((new_level != NULL) && !(g_ascii_strcasecmp("PS3", new_level) == 0))
+        if((new_level != NULL) && (g_ascii_strcasecmp("PS3", new_level) == 0))
             level = CAIRO_PS_LEVEL_3;
     } catch(...) {}
 
@@ -146,6 +151,14 @@ CairoPsOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar con
         new_textToPath  = mod->get_param_bool("textToPath");
     } catch(...) {}
 
+    bool new_textToLaTeX  = FALSE;
+    try {
+        new_textToLaTeX  = mod->get_param_bool("textToLaTeX");
+    }
+    catch(...) {
+        g_warning("Parameter <textToLaTeX> might not exist");
+    }
+
     bool new_blurToBitmap  = FALSE;
     try {
         new_blurToBitmap  = mod->get_param_bool("blurToBitmap");
@@ -171,13 +184,24 @@ CairoPsOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar con
         new_exportId = mod->get_param_string("exportId");
     } catch(...) {}
 
-       gchar * final_name;
-       final_name = g_strdup_printf("> %s", filename);
-       ret = ps_print_document_to_file(doc, final_name, level, new_textToPath, new_blurToBitmap, new_bitmapResolution, new_exportId, new_areaDrawing, new_areaPage);
-       g_free(final_name);
+    // Create PS
+    {
+        gchar * final_name;
+        final_name = g_strdup_printf("> %s", filename);
+        ret = ps_print_document_to_file(doc, final_name, level, new_textToPath, new_textToLaTeX, new_blurToBitmap, new_bitmapResolution, new_exportId, new_areaDrawing, new_areaPage);
+        g_free(final_name);
 
-       if (!ret)
-           throw Inkscape::Extension::Output::save_failed();
+        if (!ret)
+            throw Inkscape::Extension::Output::save_failed();
+    }
+
+    // Create LaTeX file (if requested)
+    if (new_textToLaTeX) {
+        ret = latex_render_document_text_to_file(doc, filename, new_exportId, new_areaDrawing, new_areaPage, false);
+
+        if (!ret)
+            throw Inkscape::Extension::Output::save_failed();
+    }
 }
 
 
@@ -201,7 +225,7 @@ CairoEpsOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar co
     int level = CAIRO_PS_LEVEL_2;
     try {
         new_level = mod->get_param_enum("PSlevel");
-        if((new_level != NULL) && !(g_ascii_strcasecmp("PS3", new_level) == 0))
+        if((new_level != NULL) && (g_ascii_strcasecmp("PS3", new_level) == 0))
             level = CAIRO_PS_LEVEL_3;
     } catch(...) {}
 
@@ -210,6 +234,14 @@ CairoEpsOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar co
         new_textToPath  = mod->get_param_bool("textToPath");
     } catch(...) {}
 
+    bool new_textToLaTeX  = FALSE;
+    try {
+        new_textToLaTeX  = mod->get_param_bool("textToLaTeX");
+    }
+    catch(...) {
+        g_warning("Parameter <textToLaTeX> might not exist");
+    }
+
     bool new_blurToBitmap  = FALSE;
     try {
         new_blurToBitmap  = mod->get_param_bool("blurToBitmap");
@@ -235,13 +267,24 @@ CairoEpsOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar co
         new_exportId = mod->get_param_string("exportId");
     } catch(...) {}
 
-       gchar * final_name;
-       final_name = g_strdup_printf("> %s", filename);
-       ret = ps_print_document_to_file(doc, final_name, level, new_textToPath, new_blurToBitmap, new_bitmapResolution, new_exportId, new_areaDrawing, new_areaPage, true);
-       g_free(final_name);
+    // Create EPS
+    {
+        gchar * final_name;
+        final_name = g_strdup_printf("> %s", filename);
+        ret = ps_print_document_to_file(doc, final_name, level, new_textToPath, new_textToLaTeX, new_blurToBitmap, new_bitmapResolution, new_exportId, new_areaDrawing, new_areaPage, true);
+        g_free(final_name);
 
-       if (!ret)
-           throw Inkscape::Extension::Output::save_failed();
+        if (!ret)
+            throw Inkscape::Extension::Output::save_failed();
+    }
+
+    // Create LaTeX file (if requested)
+    if (new_textToLaTeX) {
+        ret = latex_render_document_text_to_file(doc, filename, new_exportId, new_areaDrawing, new_areaPage, false);
+
+        if (!ret)
+            throw Inkscape::Extension::Output::save_failed();
+    }
 }
 
 
@@ -273,18 +316,19 @@ CairoPsOutput::init (void)
                "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
                        "<name>" N_("PostScript") "</name>\n"
                        "<id>" SP_MODULE_KEY_PRINT_CAIRO_PS "</id>\n"
-                       "<param name=\"PSlevel\" gui-text=\"" N_("Restrict to PS level") "\" type=\"enum\" >\n"
+                       "<param name=\"PSlevel\" gui-text=\"" N_("Restrict to PS level:") "\" type=\"enum\" >\n"
                                "<_item value='PS3'>" N_("PostScript level 3") "</_item>\n"
 #if (CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 5, 2))
                 "<_item value='PS2'>" N_("PostScript level 2") "</_item>\n"
 #endif
             "</param>\n"
                        "<param name=\"textToPath\" gui-text=\"" N_("Convert texts to paths") "\" type=\"boolean\">false</param>\n"
+                       "<param name=\"textToLaTeX\" gui-text=\"" N_("PS+LaTeX: Omit text in PS, and create LaTeX file") "\" type=\"boolean\">false</param>\n"
                        "<param name=\"blurToBitmap\" gui-text=\"" N_("Rasterize filter effects") "\" type=\"boolean\">true</param>\n"
-                       "<param name=\"resolution\" gui-text=\"" N_("Resolution for rasterization (dpi)") "\" type=\"int\" min=\"1\" max=\"10000\">90</param>\n"
+                       "<param name=\"resolution\" gui-text=\"" N_("Resolution for rasterization (dpi):") "\" type=\"int\" min=\"1\" max=\"10000\">90</param>\n"
                        "<param name=\"areaDrawing\" gui-text=\"" N_("Export area is drawing") "\" type=\"boolean\">true</param>\n"
                        "<param name=\"areaPage\" gui-text=\"" N_("Export area is page") "\" type=\"boolean\">true</param>\n"
-                       "<param name=\"exportId\" gui-text=\"" N_("Limit export to the object with ID") "\" type=\"string\"></param>\n"
+                       "<param name=\"exportId\" gui-text=\"" N_("Limit export to the object with ID:") "\" type=\"string\"></param>\n"
                        "<output>\n"
                                "<extension>.ps</extension>\n"
                                 "<mimetype>image/x-postscript</mimetype>\n"
@@ -310,18 +354,19 @@ CairoEpsOutput::init (void)
                "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
                        "<name>" N_("Encapsulated PostScript") "</name>\n"
                        "<id>" SP_MODULE_KEY_PRINT_CAIRO_EPS "</id>\n"
-                       "<param name=\"PSlevel\" gui-text=\"" N_("Restrict to PS level") "\" type=\"enum\" >\n"
+                       "<param name=\"PSlevel\" gui-text=\"" N_("Restrict to PS level:") "\" type=\"enum\" >\n"
                                "<_item value='PS3'>" N_("PostScript level 3") "</_item>\n"
 #if (CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 5, 2))
                 "<_item value='PS2'>" N_("PostScript level 2") "</_item>\n"
 #endif
             "</param>\n"
                        "<param name=\"textToPath\" gui-text=\"" N_("Convert texts to paths") "\" type=\"boolean\">false</param>\n"
+                       "<param name=\"textToLaTeX\" gui-text=\"" N_("EPS+LaTeX: Omit text in EPS, and create LaTeX file") "\" type=\"boolean\">false</param>\n"
                        "<param name=\"blurToBitmap\" gui-text=\"" N_("Rasterize filter effects") "\" type=\"boolean\">true</param>\n"
-                       "<param name=\"resolution\" gui-text=\"" N_("Resolution for rasterization (dpi)") "\" type=\"int\" min=\"1\" max=\"10000\">90</param>\n"
+                       "<param name=\"resolution\" gui-text=\"" N_("Resolution for rasterization (dpi):") "\" type=\"int\" min=\"1\" max=\"10000\">90</param>\n"
                        "<param name=\"areaDrawing\" gui-text=\"" N_("Export area is drawing") "\" type=\"boolean\">true</param>\n"
                        "<param name=\"areaPage\" gui-text=\"" N_("Export area is page") "\" type=\"boolean\">true</param>\n"
-                       "<param name=\"exportId\" gui-text=\"" N_("Limit export to the object with ID") "\" type=\"string\"></param>\n"
+                       "<param name=\"exportId\" gui-text=\"" N_("Limit export to the object with ID:") "\" type=\"string\"></param>\n"
                        "<output>\n"
                                "<extension>.eps</extension>\n"
                                 "<mimetype>image/x-e-postscript</mimetype>\n"