Code

add option to exclude/omit text from the PDF when saving to pdf
authorJohan Engelen <goejendaagh@zonnet.nl>
Sat, 20 Feb 2010 21:01:12 +0000 (22:01 +0100)
committerJohan Engelen <goejendaagh@zonnet.nl>
Sat, 20 Feb 2010 21:01:12 +0000 (22:01 +0100)
src/extension/internal/cairo-renderer-pdf-out.cpp
src/extension/internal/cairo-renderer.cpp
src/extension/internal/cairo-renderer.h

index 0598c388adccaaa523c76bc8b4a6b64a0837ad82..a62d2cb14b3f853356c8768466149b7002925b5d 100644 (file)
@@ -48,7 +48,7 @@ CairoRendererPdfOutput::check (Inkscape::Extension::Extension * module)
 
 static bool
 pdf_render_document_to_file(SPDocument *doc, gchar const *filename, unsigned int level,
-                            bool texttopath, bool filtertobitmap, int resolution,
+                            bool texttopath, bool texttolatex, bool filtertobitmap, int resolution,
                             const gchar * const exportId, bool exportDrawing, bool exportCanvas)
 {
     sp_document_ensure_up_to_date(doc);
@@ -83,6 +83,7 @@ pdf_render_document_to_file(SPDocument *doc, gchar const *filename, unsigned int
     CairoRenderContext *ctx = renderer->createContext();
     ctx->setPDFLevel(level);
     ctx->setTextToPath(texttopath);
+    renderer->_omitText = texttolatex;
     ctx->setFilterToBitmap(filtertobitmap);
     ctx->setBitmapResolution(resolution);
 
@@ -146,6 +147,14 @@ CairoRendererPdfOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc,
         g_warning("Parameter <textToPath> might not exist");
     }
 
+    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");
@@ -189,7 +198,7 @@ CairoRendererPdfOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc,
     gchar * final_name;
     final_name = g_strdup_printf("> %s", filename);
     ret = pdf_render_document_to_file(doc, final_name, level,
-                                      new_textToPath, new_blurToBitmap, new_bitmapResolution,
+                                      new_textToPath, new_textToLaTeX, new_blurToBitmap, new_bitmapResolution,
                                       new_exportId, new_exportDrawing, new_exportCanvas);
     g_free(final_name);
 
@@ -217,6 +226,7 @@ CairoRendererPdfOutput::init (void)
                                "<_item value='PDF14'>" N_("PDF 1.4") "</_item>\n"
                        "</param>\n"
                        "<param name=\"textToPath\" gui-text=\"" N_("Convert texts to paths") "\" type=\"boolean\">false</param>\n"
+                       "<param name=\"textToLaTeX\" gui-text=\"" N_("Exclude text, 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=\"areaDrawing\" gui-text=\"" N_("Export area is drawing") "\" type=\"boolean\">false</param>\n"
index 0e68ae130a368c3013d97c0f56a2bf666f4d55de..6d75c1e5dc921d2a671a7425a64d01f145fb4a86 100644 (file)
@@ -103,6 +103,7 @@ namespace Extension {
 namespace Internal {
 
 CairoRenderer::CairoRenderer(void)
+  : _omitText(false)
 {}
 
 CairoRenderer::~CairoRenderer(void)
@@ -568,6 +569,11 @@ CairoRenderer::setStateForItem(CairoRenderContext *ctx, SPItem const *item)
 void
 CairoRenderer::renderItem(CairoRenderContext *ctx, SPItem *item)
 {
+    if ( _omitText && (SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item)) ) {
+        // skip text if _omitText is true
+        return;
+    }
+
     ctx->pushState();
     setStateForItem(ctx, item);
 
index ab5d4cf58bf6bcc690d4af9b22a638626c4e94b0..d69a607532bace1993ab3514568f0b435b5f5b04 100644 (file)
@@ -56,6 +56,10 @@ public:
 
     /** Traverses the object tree and invokes the render methods. */
     void renderItem(CairoRenderContext *ctx, SPItem *item);
+
+    /** If _omitText is true, no text will be output to the PDF document.
+        The PDF will be exactly the same as if the text was written to it and then erased. */
+    bool _omitText;
 };
 
 // FIXME: this should be a static method of CairoRenderer