3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * parts Copyright 1985, 1990, 1993 Free Software Foundation, Inc.
8 * \author Ivan Schreter
9 * \author Dirk Niggemann
10 * \author Asger Alstrup
11 * \author Lars Gullik Bjønnes
12 * \author Jean-Marc Lasgouttes
13 * \author Angus Leeming
17 * Full author contact details are available in file CREDITS.
19 * Utilities for manipulation of Encapsulated Postscript files
24 #include "graphics/epstools.h"
28 #include "support/debug.h"
29 #include "support/docstream.h"
30 #include "support/filetools.h"
31 #include "support/FileName.h"
32 #include "support/regex.h"
35 using namespace lyx::support;
41 string const readBB_from_PSFile(FileName const & file)
43 // in a (e)ps-file it's an entry like %%BoundingBox:23 45 321 345
44 // It seems that every command in the header has an own line,
45 // getline() should work for all files.
46 // On the other hand some plot programs write the bb at the
47 // end of the file. Than we have in the header:
48 // %%BoundingBox: (atend)
49 // In this case we must check the end.
50 bool const zipped = theFormats().isZippedFile(file);
51 FileName const file_ = zipped ? unzipFile(file) : file;
52 string const format = theFormats().getFormatFromFile(file_);
54 if (!Formats::isPostScriptFileFormat(format)) {
55 LYXERR(Debug::GRAPHICS, "[readBB_from_PSFile] no(e)ps-format");
61 static lyx::regex bbox_re("^%%BoundingBox:\\s*([-]*[[:digit:]]+)"
62 "\\s+([-]*[[:digit:]]+)\\s+([-]*[[:digit:]]+)\\s+([-]*[[:digit:]]+)");
63 ifstream is(file_.toFilesystemEncoding().c_str());
68 if (regex_match(s, what, bbox_re)) {
69 // Our callers expect the tokens in the string
70 // separated by single spaces.
71 // FIXME: change return type from string to something
74 os << what.str(1) << ' ' << what.str(2) << ' '
75 << what.str(3) << ' ' << what.str(4);
76 string const bb = os.str();
77 LYXERR(Debug::GRAPHICS, "[readBB_from_PSFile] " << bb);
83 LYXERR(Debug::GRAPHICS, "[readBB_from_PSFile] no bb found");
90 } // namespace graphics