Fix bug #3016: tex2lyx fails to convert xfig figures to Xfig insets

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36833 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Georg Baum 2010-12-11 18:22:47 +00:00
parent 14cbb6cb3d
commit cb1fc51b9c

View File

@ -2412,7 +2412,6 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
&& p.next_token().asInput() == "*")
name += p.get_token().asInput();
context.check_layout(os);
begin_inset(os, "Include ");
string filename(normalize_filename(p.getArg('{', '}')));
string const path = getMasterFilePath();
// We want to preserve relative / absolute filenames,
@ -2427,27 +2426,53 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
if (!tex_name.empty())
filename = tex_name;
}
bool xfig = false;
string outname;
if (makeAbsPath(filename, path).exists()) {
string const abstexname =
makeAbsPath(filename, path).absFileName();
string const abslyxname =
changeExtension(abstexname, ".lyx");
string const absfigname =
changeExtension(abstexname, ".fig");
fix_relative_filename(filename);
string const lyxname =
changeExtension(filename, ".lyx");
if (t.cs() != "verbatiminput" &&
if (t.cs() == "input" && FileName(absfigname).exists()) {
FileName const absepsname(
changeExtension(abstexname, ".eps"));
FileName const abspdfname(
changeExtension(abstexname, ".pdf"));
string const ext = getExtension(abstexname);
bool const xfigpdf =
abspdfname.exists() && ext == "pdftex_t";
bool const xfigeps =
absepsname.exists() && ext == "pstex_t";
xfig = xfigpdf || xfigeps;
}
if (xfig) {
outname = changeExtension(filename, ".fig");
} else if (t.cs() != "verbatiminput" &&
tex2lyx(abstexname, FileName(abslyxname),
p.getEncoding())) {
os << name << '{' << lyxname << "}\n";
outname = lyxname;
} else {
os << name << '{' << filename << "}\n";
outname = filename;
}
} else {
cerr << "Warning: Could not find included file '"
<< filename << "'." << endl;
os << name << '{' << filename << "}\n";
outname = filename;
}
if (xfig) {
begin_inset(os, "External\n");
os << "\ttemplate XFig\n"
<< "\tfilename " << outname << '\n';
} else {
begin_inset(os, "Include ");
os << name << '{' << outname
<< "}\npreview false\n";
}
os << "preview false\n";
end_inset(os);
}