From: Georg Baum Date: Fri, 14 Jan 2005 08:52:35 +0000 (+0000) Subject: fix export in insetgraphics and insetexternal X-Git-Tag: 1.6.10~14660 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=4d0cbd59af2bf8bdb7aa55ef57667469f34ad439;p=features.git fix export in insetgraphics and insetexternal git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9476 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 5a20dfe6cb..c44d432e24 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,11 @@ +2005-01-11 Georg Baum + + * 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 * ExternalTemplate.C: use support/package.h to provide the paths to the diff --git a/src/insets/ExternalSupport.C b/src/insets/ExternalSupport.C index 081520a24d..a1068f9d11 100644 --- a/src/insets/ExternalSupport.C +++ b/src/insets/ExternalSupport.C @@ -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); diff --git a/src/insets/ExternalSupport.h b/src/insets/ExternalSupport.h index 1e5bbc5583..aa6c9894be 100644 --- a/src/insets/ExternalSupport.h +++ b/src/insets/ExternalSupport.h @@ -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 &, diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index b33f48954b..9450a7b2f7 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -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 +