-void readBB_lyxerrMessage(FileName const & file, bool & zipped,
- string const & message)
-{
- LYXERR(Debug::GRAPHICS, "[readBB_from_PSFile] " << message);
- // FIXME: Why is this func deleting a file? (Lgb)
- if (zipped)
- file.removeFile();
-}
-
-
-string const readBB_from_PSFile(FileName 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.
- bool zipped = file.isZippedFile();
- FileName const file_ = zipped ? unzipFile(file) : file;
- string const format = file_.guessFormatFromContents();
-
- if (format != "eps" && format != "ps") {
- readBB_lyxerrMessage(file_, zipped,"no(e)ps-format");
- return string();
- }
-
- static lyx::regex bbox_re(
- "^%%BoundingBox:\\s*([[:digit:]]+)\\s+([[:digit:]]+)\\s+([[:digit:]]+)\\s+([[:digit:]]+)");
- ifstream is(file_.toFilesystemEncoding().c_str());
- while (is) {
- string s;
- getline(is,s);
- lyx::smatch what;
- if (regex_match(s, what, bbox_re)) {
- // Our callers expect the tokens in the string
- // separated by single spaces.
- // FIXME: change return type from string to something
- // sensible
- ostringstream os;
- os << what.str(1) << ' ' << what.str(2) << ' '
- << what.str(3) << ' ' << what.str(4);
- string const bb = os.str();
- readBB_lyxerrMessage(file_, zipped, bb);
- return bb;
- }
- }
- readBB_lyxerrMessage(file_, zipped, "no bb found");
- return string();
-}
-
-