(Herbert): move readBB from ControlGraphics to support/filetools.

(Angus): re-format getExtFromContents a little and remove replicated "sgi"
entry.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3946 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2002-04-08 14:55:52 +00:00
parent 29730d15a1
commit 36415c9131
5 changed files with 71 additions and 50 deletions

View File

@ -1,3 +1,7 @@
2002-04-07 Herbert Voss <voss@perce.de>
* ControlGraphics.[C]: move readBB as readBB_from_PSFile into filetools
2002-04-05 Angus Leeming <a.leeming@ic.ac.uk>
* ControlGraphics.C (readBB): sigh. Make sure that the correct path is

View File

@ -104,37 +104,7 @@ string const ControlGraphics::Browse(string const & in_name)
string const ControlGraphics::readBB(string const & file)
{
// in a file it's an entry like %%BoundingBox:23 45 321 345
// The first number can following without a space, so we have
// to be a little careful.
// On the other hand some plot programs write the bb at the
// end of the file. Than we have in the header:
// %%BoundingBox: (atend)
// In this case we must check the end.
string file_ = MakeAbsPath(file, lv_.buffer()->filePath());
if (zippedFile(file_))
file_ = unzipFile(file_);
string const format = getExtFromContents(file_);
if (format != "eps" && format != "ps")
return string();
std::ifstream is(file_.c_str());
while (is) {
string s;
is >> s;
if (contains(s,"%%BoundingBox:")) {
string a, b, c, d;
is >> a >> b >> c >> d;
if (is && !contains(a,"atend")) { // bb at the end?
if (s != "%%BoundingBox:")
return (s.substr(14)+" "+a+" "+b+" "+c+" ");
else
return (a+" "+b+" "+c+" "+d+" ");
}
}
}
return string();
return readBB_from_PSFile(MakeAbsPath(file, lv_.buffer()->filePath()));
}

View File

@ -1,3 +1,13 @@
2002-04-08 Angus Leeming <a.leeming@ic.ac.uk>
* filetools.C (getExtFromContents): re-format a little and remove
replicated "sgi" entry.
2002-04-07 Herbert Voss <voss@perce.de>
* filetools.[Ch]: add readBB_from_PSFile() to make bb available
for the lyx-view in graphics (moved from ControlGraphics)
2002-04-07 Herbert Voss <voss@perce.de>
* filetools.C: fix bug for eps. scans now a whole line

View File

@ -1043,7 +1043,7 @@ string const getExtFromContents(string const & filename)
break;
}
getline(ifs, str);
std::getline(ifs, str);
lyxerr[Debug::GRAPHICS] << "Scanstring: " << str << endl;
string const stamp = str.substr(0,2);
@ -1052,25 +1052,26 @@ string const getExtFromContents(string const & filename)
// information is saved in the first bytes of the file!
// also some graphic formats which save the information
// in the first line, too.
if (prefixIs(str, gzipStamp))
if (prefixIs(str, gzipStamp)) {
format = "gzip";
else if (stamp == zipStamp)
} else if (stamp == zipStamp) {
format = "zip";
else if (stamp == compressStamp)
} else if (stamp == compressStamp) {
format = "compress";
// the graphics part
else if (stamp == "BM")
} else if (stamp == "BM") {
format = "bmp";
else if (stamp == "\001\332")
} else if (stamp == "\001\332") {
format = "sgi";
// PBM family
// Don't need to use str.at(0), str.at(1) because
// we already know that str.size() >= 2
else if (str[0] == 'P') {
} else if (str[0] == 'P') {
switch (str[1]) {
case '1':
case '4':
@ -1085,21 +1086,27 @@ string const getExtFromContents(string const & filename)
format = "ppm";
}
break;
} else if ((stamp == "II") || (stamp == "MM")) {
format = "tiff";
} else if (str == "%TGIF") {
format = "tgif";
} else if (prefixIs(str,"GIF")) {
format = "gif";
} else if (str.size() > 3) {
int const c = ((str[0] << 24) & (str[1] << 16) &
(str[2] << 8) & str[3]);
if (c == 105) {
format = "xwd";
}
}
if (stamp == "\001\332")
format = "sgi";
else if ((stamp == "II") || (stamp == "MM"))
format = "tiff";
else if (str == "%TGIF")
format = "tgif";
else if (prefixIs(str,"GIF"))
format = "gif";
else if (str.size() > 3) // get long
if (((str[0] << 24) + (str[1] << 16) +
(str[2] << 8) + str[3]) == 105)
format = "xwd";
firstLine = false;
}
if (!format.empty())
break;
else if (contains(str,"EPSF"))
@ -1344,3 +1351,30 @@ void removeAutosaveFile(string const & filename)
}
}
}
string const readBB_from_PSFile(string const & file)
{
// in a (e)ps-file it's an entry like %%BoundingBox:23 45 321 345
// It seems that every command in the header has an own line,
// getline() should work for all files.
// On the other hand some plot programs write the bb at the
// end of the file. Than we have in the header:
// %%BoundingBox: (atend)
// In this case we must check the end.
string const file_ = zippedFile(file) ?
string(unzipFile(file)) : string(file);
string const format = getExtFromContents(file_);
if (format != "eps" && format != "ps")
return string();
std::ifstream is(file_.c_str());
while (is) {
string s;
std::getline(is,s);
if (contains(s,"%%BoundingBox:") && !contains(s,"atend"))
return (frontStrip(s.substr(14)));
}
return string();
}

View File

@ -206,5 +206,8 @@ string const findtexfile(string const & fil, string const & format);
/// remove the autosave-file and give a Message if it can't be done
void removeAutosaveFile(string const & filename);
/// read the BoundingBox entry from a ps/eps/pdf-file
string const readBB_from_PSFile(string const & file);
#endif