Code

output test.tex instead of test.pdf.tex which does not work well. strip path from...
authorJohan Engelen <goejendaagh@zonnet.nl>
Sun, 21 Feb 2010 10:21:18 +0000 (11:21 +0100)
committerJohan Engelen <goejendaagh@zonnet.nl>
Sun, 21 Feb 2010 10:21:18 +0000 (11:21 +0100)
src/extension/internal/cairo-renderer-pdf-out.cpp
src/extension/internal/pdflatex-renderer.cpp

index f308f58ca82f601fa6f04c0416ad6bae283a3511..594389c60f7f83cf6e7dba105d5c7172c0f8f2bb 100644 (file)
@@ -256,7 +256,9 @@ CairoRendererPdfOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc,
     // Create LaTeX file (if requested)
     if (new_textToLaTeX) {
         gchar * tex_filename;
-        tex_filename = g_strdup_printf("%s.tex", filename);
+        //strip filename of ".pdf", do not add ".tex" here.
+        gsize n = g_str_has_suffix(filename, ".pdf") ? strlen(filename)-4 : strlen(filename);
+        tex_filename = g_strndup(filename, n);
         ret = latex_render_document_text_to_file(doc, tex_filename, new_exportId, new_exportDrawing, new_exportCanvas);
         g_free(tex_filename);
 
index 60b960ddb86c7e953e7e8e4bf5bcefafe2b07ba3..0d2ffcc94e2a02956b0d3d7253defbcbfbe08894 100644 (file)
@@ -139,14 +139,17 @@ PDFLaTeXRenderer::setTargetFile(gchar const *filename) {
         while (isspace(*filename)) filename += 1;
         
         _filename = g_strdup(filename);
-        Inkscape::IO::dump_fopen_call(filename, "K");
-        FILE *osf = Inkscape::IO::fopen_utf8name(filename, "w+");
+
+        gchar *filename_ext = g_strdup_printf("%s.tex", filename);
+        Inkscape::IO::dump_fopen_call(filename_ext, "K");
+        FILE *osf = Inkscape::IO::fopen_utf8name(filename_ext, "w+");
         if (!osf) {
             fprintf(stderr, "inkscape: fopen(%s): %s\n",
-                    filename, strerror(errno));
+                    filename_ext, strerror(errno));
             return false;
         }
         _stream = osf;
+        g_free(filename_ext);
     }
 
     if (_stream) {
@@ -158,6 +161,7 @@ PDFLaTeXRenderer::setTargetFile(gchar const *filename) {
 
     fprintf(_stream, "%%%% Creator: Inkscape %s, www.inkscape.org\n", PACKAGE_STRING);
     fprintf(_stream, "%%%% PDF + LaTeX output extension by Johan Engelen, 2010\n");
+    fprintf(_stream, "%%%% Accompanies %s.pdf\n", _filename);
     /* flush this to test output stream as early as possible */
     if (fflush(_stream)) {
         if (ferror(_stream)) {
@@ -274,8 +278,14 @@ PDFLaTeXRenderer::writePostamble()
 {
     fprintf(_stream, "%s", postamble1);
 
-    // TODO: strip path from filename on Windows
-    fprintf(_stream, "      \\put(0,0){\\includegraphics{%s.pdf}}%%\n", _filename);
+    // strip pathname on windows, as it is probably desired. It is not possible to work without paths on windows yet. (bug)
+#ifdef WIN32
+    gchar *figurefile = g_path_get_basename(_filename);
+#else
+    gchar *figurefile = g_strdup(_filename);
+#endif
+    fprintf(_stream, "      \\put(0,0){\\includegraphics{%s.pdf}}%%\n", figurefile);
+    g_free(figurefile);
 
     fprintf(_stream, "%s", postamble2);
 }