From 48f5db4710f8e06462dcac31aa2bc84e3db8f787 Mon Sep 17 00:00:00 2001 From: Johan Engelen Date: Sun, 21 Feb 2010 11:21:18 +0100 Subject: [PATCH] output test.tex instead of test.pdf.tex which does not work well. strip path from filename on windows --- .../internal/cairo-renderer-pdf-out.cpp | 4 +++- src/extension/internal/pdflatex-renderer.cpp | 20 ++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/extension/internal/cairo-renderer-pdf-out.cpp b/src/extension/internal/cairo-renderer-pdf-out.cpp index f308f58ca..594389c60 100644 --- a/src/extension/internal/cairo-renderer-pdf-out.cpp +++ b/src/extension/internal/cairo-renderer-pdf-out.cpp @@ -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); diff --git a/src/extension/internal/pdflatex-renderer.cpp b/src/extension/internal/pdflatex-renderer.cpp index 60b960ddb..0d2ffcc94 100644 --- a/src/extension/internal/pdflatex-renderer.cpp +++ b/src/extension/internal/pdflatex-renderer.cpp @@ -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); } -- 2.30.2