]> git.lyx.org Git - features.git/commitdiff
fix export in insetgraphics and insetexternal
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Fri, 14 Jan 2005 08:52:35 +0000 (08:52 +0000)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Fri, 14 Jan 2005 08:52:35 +0000 (08:52 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9476 a592a061-630c-0410-9148-cb99ea01b6c8

src/insets/ChangeLog
src/insets/ExternalSupport.C
src/insets/ExternalSupport.h
src/insets/insetgraphics.C

index 5a20dfe6cbf081e18a749db66721394e6ccad9a6..c44d432e24d7312497cd9c96713b0692baca4804 100644 (file)
@@ -1,3 +1,11 @@
+2005-01-11  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
+
+       * insetgraphics.C (prepareFile): add missing calls to addExternalFile
+       * updateExternal.[Ch] (doSubstitution): take a new parameter that
+       determines what variables are substituted
+       * updateExternal.C (updateExternal): fix substitution of
+       ReferencedFiles
+
 2005-01-10  Angus Leeming  <leeming@lyx.org>
 
        * ExternalTemplate.C: use support/package.h to provide the paths to the
index 081520a24d9d5fed0a210d86d606b066c087a822..a1068f9d11e62e7f4cebf3195d400f8b8986a864 100644 (file)
@@ -62,7 +62,8 @@ void editExternal(InsetExternalParams const & params, Buffer const & buffer)
 
 string const doSubstitution(InsetExternalParams const & params,
                            Buffer const & buffer, string const & s,
-                           bool external_in_tmpdir)
+                            bool external_in_tmpdir,
+                            Substitute what)
 {
        Buffer const * m_buffer = buffer.getMasterBuffer();
        string const parentpath = external_in_tmpdir ?
@@ -71,43 +72,52 @@ string const doSubstitution(InsetExternalParams const & params,
        string const filename = external_in_tmpdir ?
                params.filename.mangledFilename() :
                params.filename.outputFilename(parentpath);
-       string result;
        string const basename = support::ChangeExtension(
                        support::OnlyFilename(filename), string());
        string const absname = support::MakeAbsPath(filename, parentpath);
-       string const filepath = support::OnlyPath(filename);
-       string const abspath = support::OnlyPath(absname);
-       string const masterpath = external_in_tmpdir ?
-               m_buffer->temppath() :
-               m_buffer->filePath();
-       string relToMasterPath = support::OnlyPath(
-                       support::MakeRelPath(absname, masterpath));
-       if (relToMasterPath == "./")
-               relToMasterPath.clear();
-       string relToParentPath = support::OnlyPath(
-                       support::MakeRelPath(absname, parentpath));
-       if (relToParentPath == "./")
-               relToParentPath.clear();
-
-       result = support::subst(s, "$$FName", filename);
-       result = support::subst(result, "$$Basename", basename);
-       result = support::subst(result, "$$Extension",
-                       '.' + support::GetExtension(filename));
-       result = support::subst(result, "$$FPath", filepath);
-       result = support::subst(result, "$$AbsPath", abspath);
-       result = support::subst(result, "$$RelPathMaster", relToMasterPath);
-       result = support::subst(result, "$$RelPathParent", relToParentPath);
-       if (support::AbsolutePath(filename)) {
-               result = support::subst(result, "$$AbsOrRelPathMaster",
-                                       abspath);
-               result = support::subst(result, "$$AbsOrRelPathParent",
-                                       abspath);
-       } else {
-               result = support::subst(result, "$$AbsOrRelPathMaster",
+
+       string result = s;
+       if (what != ALL_BUT_PATHS) {
+               string const filepath = support::OnlyPath(filename);
+               string const abspath = support::OnlyPath(absname);
+               string const masterpath = external_in_tmpdir ?
+                       m_buffer->temppath() :
+                       m_buffer->filePath();
+               string relToMasterPath = support::OnlyPath(
+                               support::MakeRelPath(absname, masterpath));
+               if (relToMasterPath == "./")
+                       relToMasterPath.clear();
+               string relToParentPath = support::OnlyPath(
+                               support::MakeRelPath(absname, parentpath));
+               if (relToParentPath == "./")
+                       relToParentPath.clear();
+
+               result = support::subst(result, "$$FPath", filepath);
+               result = support::subst(result, "$$AbsPath", abspath);
+               result = support::subst(result, "$$RelPathMaster",
                                        relToMasterPath);
-               result = support::subst(result, "$$AbsOrRelPathParent",
+               result = support::subst(result, "$$RelPathParent",
                                        relToParentPath);
+               if (support::AbsolutePath(filename)) {
+                       result = support::subst(result, "$$AbsOrRelPathMaster",
+                                               abspath);
+                       result = support::subst(result, "$$AbsOrRelPathParent",
+                                               abspath);
+               } else {
+                       result = support::subst(result, "$$AbsOrRelPathMaster",
+                                               relToMasterPath);
+                       result = support::subst(result, "$$AbsOrRelPathParent",
+                                               relToParentPath);
+               }
        }
+
+       if (what == PATHS)
+               return result;
+
+       result = support::subst(result, "$$FName", filename);
+       result = support::subst(result, "$$Basename", basename);
+       result = support::subst(result, "$$Extension",
+                       '.' + support::GetExtension(filename));
        result = support::subst(result, "$$Tempname", params.tempname());
        result = support::subst(result, "$$Sysdir",
                                support::package().system_support());
@@ -139,8 +149,8 @@ string const doSubstitution(InsetExternalParams const & params,
 namespace {
 
 /** update the file represented by the template.
-    If \param external_in_tmpdir == true, then the generated file is
-    place in the buffer's temporary directory.
+    If \p external_in_tmpdir == true, then the generated file is
+    placed in the buffer's temporary directory.
 */
 void updateExternal(InsetExternalParams const & params,
                    string const & format,
@@ -238,9 +248,17 @@ void updateExternal(InsetExternalParams const & params,
                                        doSubstitution(params, buffer, *fit,
                                                       true),
                                        m_buffer->temppath());
-                       string const file = doSubstitution(params, buffer,
-                                                          *fit,
-                                                          external_in_tmpdir);
+                       // The path of the referenced file is never the
+                       // temp path, but the filename may be the mangled
+                       // or the real name. Therefore we substitute the
+                       // paths and names separately.
+                       string file = support::subst(*fit, "$$FName",
+                                       "$$FPath$$Basename$$Extension");
+                       file = doSubstitution(params, buffer, file, false,
+                                             PATHS);
+                       file = doSubstitution(params, buffer, file,
+                                             external_in_tmpdir,
+                                             ALL_BUT_PATHS);
                        // if file is a relative name, it is interpreted
                        // relative to the master document.
                        exportdata.addExternalFile(rit->first, source, file);
index 1e5bbc5583852f9b23ec176bc32f8f098b2bdf92..aa6c9894be2e3eb4a861d86fe3829dc25d8d5c82 100644 (file)
@@ -34,6 +34,12 @@ void editExternal(InsetExternalParams const & params,
                  Buffer const & buffer);
 
 
+enum Substitute {
+       ALL,
+       PATHS,
+       ALL_BUT_PATHS
+};
+
 /** Substitute meta-variables in string \p s, making use of \p params and
     \p buffer.
     If \p external_in_tmpdir is true, all files are assumed to be in the
@@ -44,12 +50,13 @@ void editExternal(InsetExternalParams const & params,
 std::string const doSubstitution(InsetExternalParams const & params,
                                 Buffer const & buffer,
                                  std::string const & s,
-                                 bool external_in_tmpdir = false);
+                                 bool external_in_tmpdir = false,
+                                 Substitute what = ALL);
 
 
 /** Write the output for a specific file format
     and generate any external data files.
-    If \param external_in_tmpdir == true, then the generated file is
+    If \p external_in_tmpdir == true, then the generated file is
     place in the buffer's temporary directory.
 */
 int writeExternal(InsetExternalParams const &,
index b33f48954b10a6730bc221859386b7c28f40c4c1..9450a7b2f70ac30095c380eda9cbee2c6ec8b2ba 100644 (file)
@@ -674,7 +674,12 @@ string const InsetGraphics::prepareFile(Buffer const & buf,
 
        // if no special converter defined, then we take the default one
        // from ImageMagic: convert from:inname.from to:outname.to
-       if (!converters.convert(&buf, temp_file, temp_file, from, to)) {
+       if (converters.convert(&buf, temp_file, temp_file, from, to)) {
+               runparams.exportdata->addExternalFile("latex",
+                               to_file, output_to_file);
+               runparams.exportdata->addExternalFile("dvi",
+                               to_file, output_to_file);
+       } else {
                string const command =
                        "sh " + LibFileSearch("scripts", "convertDefault.sh") +
                                ' ' + formats.extension(from) + ':' + temp_file +