use the lyxdot replacement mechanism also in insetexternal

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10162 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Georg Baum 2005-07-10 09:31:27 +00:00
parent 14d7a4424e
commit 1828d1b3f5
7 changed files with 78 additions and 20 deletions

View File

@ -1,3 +1,10 @@
2005-07-10 Georg Baum <Georg.Baum@post.rwth-aachen.de>
* ExternalSupport.C (subst_path): adjust to latex_path changes and
replace dots if appropriate
* insetgraphics.C (prepareFile): move lyxdot replacement to latex_path
* insetexternal.C (validate): require lyxdot
2005-07-08 Georg Baum <Georg.Baum@post.rwth-aachen.de>
* ExternalSupport.C (subst_path): new argument exclude_extension

View File

@ -67,12 +67,13 @@ string const subst_path(string const & input,
string const & placeholder,
string const & path,
bool use_latex_path,
bool exclude_extension = false)
support::latex_path_extension ext = support::PROTECT_EXTENSION,
support::latex_path_dots dots = support::LEAVE_DOTS)
{
if (input.find(placeholder) == string::npos)
return input;
string const path2 = use_latex_path ?
support::latex_path(path, exclude_extension) :
support::latex_path(path, ext, dots) :
support::os::external_path(path);
return support::subst(input, placeholder, path2);
}
@ -113,30 +114,50 @@ string const doSubstitution(InsetExternalParams const & params,
if (relToParentPath == "./")
relToParentPath.clear();
result = subst_path(result, "$$FPath", filepath, use_latex_path);
result = subst_path(result, "$$AbsPath", abspath, use_latex_path);
result = subst_path(result, "$$FPath", filepath,
use_latex_path,
support::PROTECT_EXTENSION,
support::ESCAPE_DOTS);
result = subst_path(result, "$$AbsPath", abspath,
use_latex_path,
support::PROTECT_EXTENSION,
support::ESCAPE_DOTS);
result = subst_path(result, "$$RelPathMaster",
relToMasterPath, use_latex_path);
relToMasterPath, use_latex_path,
support::PROTECT_EXTENSION,
support::ESCAPE_DOTS);
result = subst_path(result, "$$RelPathParent",
relToParentPath, use_latex_path);
relToParentPath, use_latex_path,
support::PROTECT_EXTENSION,
support::ESCAPE_DOTS);
if (support::AbsolutePath(filename)) {
result = subst_path(result, "$$AbsOrRelPathMaster",
abspath, use_latex_path);
abspath, use_latex_path,
support::PROTECT_EXTENSION,
support::ESCAPE_DOTS);
result = subst_path(result, "$$AbsOrRelPathParent",
abspath, use_latex_path);
abspath, use_latex_path,
support::PROTECT_EXTENSION,
support::ESCAPE_DOTS);
} else {
result = subst_path(result, "$$AbsOrRelPathMaster",
relToMasterPath, use_latex_path);
relToMasterPath, use_latex_path,
support::PROTECT_EXTENSION,
support::ESCAPE_DOTS);
result = subst_path(result, "$$AbsOrRelPathParent",
relToParentPath, use_latex_path);
relToParentPath, use_latex_path,
support::PROTECT_EXTENSION,
support::ESCAPE_DOTS);
}
}
if (what == PATHS)
return result;
result = subst_path(result, "$$FName", filename, use_latex_path, true);
result = subst_path(result, "$$Basename", basename, use_latex_path);
result = subst_path(result, "$$FName", filename, use_latex_path,
support::EXCLUDE_EXTENSION);
result = subst_path(result, "$$Basename", basename, use_latex_path,
support::PROTECT_EXTENSION, support::ESCAPE_DOTS);
result = subst_path(result, "$$Extension",
'.' + support::GetExtension(filename), use_latex_path);
result = subst_path(result, "$$Tempname", params.tempname(), use_latex_path);

View File

@ -755,6 +755,9 @@ void InsetExternal::validate(LaTeXFeatures & features) const
if (cit == et.formats.end())
return;
// FIXME: We don't need that always
features.require("lyxdot");
vector<string>::const_iterator it = cit->second.requirements.begin();
vector<string>::const_iterator end = cit->second.requirements.end();
for (; it != end; ++it)

View File

@ -528,10 +528,13 @@ string const stripExtensionIfPossible(string const & file)
// dots with a macro whose definition is just a dot ;-)
// The automatic format selection does not work if the file
// name is escaped.
string const latex_name = latex_path(file, true);
string const latex_name = latex_path(file,
lyx::support::EXCLUDE_EXTENSION);
if (contains(latex_name, '"'))
return latex_name;
return subst(latex_path(RemoveExtension(file)), ".", "\\lyxdot ");
return latex_path(RemoveExtension(file),
lyx::support::PROTECT_EXTENSION,
lyx::support::ESCAPE_DOTS);
}
@ -546,7 +549,7 @@ string const stripExtensionIfPossible(string const & file, string const & to)
(to_format == "eps" && file_format == "ps") ||
(to_format == "ps" && file_format == "eps"))
return stripExtensionIfPossible(file);
return latex_path(file, true);
return latex_path(file, lyx::support::EXCLUDE_EXTENSION);
}
} // namespace anon
@ -633,7 +636,8 @@ string const InsetGraphics::prepareFile(Buffer const & buf,
source_file, output_file);
// We can't strip the extension, because we don't know
// the unzipped file format
return latex_path(output_file, true);
return latex_path(output_file,
lyx::support::EXCLUDE_EXTENSION);
}
string const unzipped_temp_file = unzippedFileName(temp_file);

View File

@ -1,3 +1,8 @@
2005-07-10 Georg Baum <Georg.Baum@post.rwth-aachen.de>
* filetools.[Ch] (latex_path): convert boolean exclude_extension
argument to an enum and add argument to replace dots
2005-07-08 Georg Baum <Georg.Baum@post.rwth-aachen.de>
* filetools.[Ch] (latex_path): add exclude_extension argument

View File

@ -82,14 +82,16 @@ bool IsSGMLFilename(string const & filename)
}
string const latex_path(string const & original_path, bool exclude_extension)
string const latex_path(string const & original_path,
latex_path_extension extension,
latex_path_dots dots)
{
string path = subst(original_path, "\\", "/");
path = subst(path, "~", "\\string~");
if (path.find(' ') != string::npos)
// We can't use '"' because " is sometimes active (e.g. if
// babel is loaded with the "german" option)
if (exclude_extension) {
if (extension == EXCLUDE_EXTENSION) {
string const base = ChangeExtension(path, string());
string const ext = GetExtension(path);
// ChangeExtension calls os::internal_path internally
@ -97,6 +99,8 @@ string const latex_path(string const & original_path, bool exclude_extension)
path = "\\string\"" + base + "\\string\"." + ext;
} else
path = "\\string\"" + path + "\\string\"";
if (dots == ESCAPE_DOTS)
return subst(path, ".", "\\lyxdot ");
return path;
}

View File

@ -102,6 +102,16 @@ i18nLibFileSearch(std::string const & dir, std::string const & name,
*/
std::string const LibScriptSearch(std::string const & command);
enum latex_path_extension {
PROTECT_EXTENSION,
EXCLUDE_EXTENSION
};
enum latex_path_dots {
LEAVE_DOTS,
ESCAPE_DOTS
};
/** @param path a file path in internal_path format. Ie, directories
* are indicated by '/', not by '\'.
*
@ -112,14 +122,18 @@ std::string const LibScriptSearch(std::string const & command);
* If @c path contains spaces, then the returned path is enclosed in
* "-quotes. This last fix will lead to successful compiliation of the
* LaTeX file only if a sufficiently modern LaTeX compiler is used.
* If @c exclude_extension is true the extension is left outside the quotes.
* If @c ext == EXCLUDE_EXTENSION the extension is left outside the quotes.
* This is needed for pdfeTeX, Version 3.141592-1.21a-2.2 (Web2C 7.5.4)
* (format=pdflatex 2005.4.11) in combination with
* pdftex.def 2002/06/19 v0.03k graphics/color for pdftex:
* It does not recognize the file extension if it is inside the quotes.
* If @c dots == ESCAPE_DOTS dots in the filename are replaced by
* "\\lyxdot ". This is needed for the \\includegraphics command if the
* automatic format selection is used.
*/
std::string const latex_path(std::string const & path,
bool exclude_extension = false);
latex_path_extension extension = PROTECT_EXTENSION,
latex_path_dots dots = LEAVE_DOTS);
/// Substitutes active latex characters with underscores in filename
std::string const MakeLatexName(std::string const & file);