]> git.lyx.org Git - lyx.git/blobdiff - src/insets/ExternalSupport.cpp
Fix trailing whitespace in cpp files.
[lyx.git] / src / insets / ExternalSupport.cpp
index 6d009a5dd2b13814d9bd7c0c3fdc092d860e7476..177ce4d60d9ea77284c9d8d5f4200a8bd2170e11 100644 (file)
@@ -22,6 +22,7 @@
 #include "Exporter.h"
 #include "Format.h"
 #include "Mover.h"
+#include "texstream.h"
 
 #include "frontends/alert.h"
 
@@ -50,8 +51,8 @@ Template const * getTemplatePtr(InsetExternalParams const & params)
 
 void editExternal(InsetExternalParams const & params, Buffer const & buffer)
 {
-       formats.edit(buffer, params.filename, 
-               formats.getFormatFromFile(params.filename));
+       theFormats().edit(buffer, params.filename,
+               theFormats().getFormatFromFile(params.filename));
 }
 
 
@@ -83,6 +84,21 @@ string const doSubstitution(InsetExternalParams const & params,
                            bool external_in_tmpdir,
                            Substitute what)
 {
+       string result = s;
+       if (what != PATHS && contains(result, "$$pngOrjpg")) {
+               // This is for raster images and pdflatex:
+               // Since pdflatex supports both jpg and png, we choose the best format:
+               // jpg if the original file is jpg to retain the compression, else png.
+               string format = theFormats().getFormatFromFile(params.filename);
+               if (format == "jpg")
+                       result = subst(result, "$$pngOrjpg", "jpg");
+               else
+                       result = subst(result, "$$pngOrjpg", "png");
+       }
+
+       if (what == FORMATS)
+               return result;
+
        Buffer const * masterBuffer = buffer.masterBuffer();
        string const parentpath = external_in_tmpdir ?
                masterBuffer->temppath() :
@@ -94,7 +110,6 @@ string const doSubstitution(InsetExternalParams const & params,
                        onlyFileName(filename), string());
        string const absname = makeAbsPath(filename, parentpath).absFileName();
 
-       string result = s;
        if (what != ALL_BUT_PATHS) {
                string const filepath = onlyPath(filename);
                string const abspath = onlyPath(absname);
@@ -185,7 +200,7 @@ string const doSubstitution(InsetExternalParams const & params,
 
                size_t const pos = result.find("$$Contents(\"");
                size_t const end = result.find("\")", pos);
-               result.replace(pos, end + 2, contents);
+               result.replace(pos, end + 2- pos, contents);
        }
 
        return result;
@@ -230,12 +245,13 @@ void updateExternal(InsetExternalParams const & params,
                        return; // NOT_NEEDED
 
                // Try and ascertain the file format from its contents.
-               from_format = formats.getFormatFromFile(params.filename);
+               from_format = theFormats().getFormatFromFile(params.filename);
                if (from_format.empty())
                        return; // FAILURE
        }
 
-       string const to_format = outputFormat.updateFormat;
+       string const to_format = doSubstitution(params, buffer,
+               outputFormat.updateFormat, false, external_in_tmpdir, FORMATS);
        if (to_format.empty())
                return; // NOT_NEEDED
 
@@ -245,10 +261,11 @@ void updateExternal(InsetExternalParams const & params,
 
        // We copy the source file to the temp dir and do the conversion
        // there if necessary
+       bool const isDir = params.filename.isDirectory();
        FileName const temp_file(
                makeAbsPath(params.filename.mangledFileName(),
                                     masterBuffer->temppath()));
-       if (!params.filename.empty() && !params.filename.isDirectory()) {
+       if (!params.filename.empty() && !isDir) {
                unsigned long const from_checksum = params.filename.checksum();
                unsigned long const temp_checksum = temp_file.checksum();
 
@@ -305,7 +322,8 @@ void updateExternal(InsetExternalParams const & params,
 
        // Do we need to perform the conversion?
        // Yes if to_file does not exist or if from_file is newer than to_file
-       if (compare_timestamps(temp_file, abs_to_file) < 0)
+       // or if from_file is a directory (bug 9925)
+       if (!isDir && compare_timestamps(temp_file, abs_to_file) < 0)
                return; // SUCCESS
 
        // FIXME (Abdel 12/08/06): Is there a need to show these errors?
@@ -417,7 +435,7 @@ string const substituteIt<TransformCommand>(string const & input,
        else if (id == Resize)
                ptr = store.getCommandTransformer(params.resizedata);
 
-       if (!ptr.get())
+       if (!ptr)
                return input;
 
        string result =
@@ -456,7 +474,7 @@ string const substituteIt<TransformOption>(string const & input,
                break;
        }
 
-       if (!ptr.get())
+       if (!ptr)
                return input;
 
        return subst(input, ptr->placeholder(), ptr->option());