noinst_LIBRARIES += liblyxgraphics.a
liblyxgraphics_a_SOURCES = \
+ graphics/epstools.h \
+ graphics/epstools.cpp \
graphics/GraphicsCache.h \
graphics/GraphicsCache.cpp \
graphics/GraphicsCacheItem.h \
#include "insets/ExternalTemplate.h"
#include "insets/InsetExternal.h"
+#include "graphics/epstools.h"
#include "graphics/GraphicsCache.h"
#include "graphics/GraphicsCacheItem.h"
#include "graphics/GraphicsImage.h"
FileName const abs_file(support::makeAbsPath(filename, fromqstr(bufferFilePath())));
// try to get it from the file, if possible
- string bb = readBB_from_PSFile(abs_file);
+ string bb = graphics::readBB_from_PSFile(abs_file);
if (bb.empty()) {
// we don't, so ask the Graphics Cache if it has loaded the file
int width = 0;
#include "Length.h"
#include "LyXRC.h"
+#include "graphics/epstools.h"
#include "graphics/GraphicsCache.h"
#include "graphics/GraphicsCacheItem.h"
#include "graphics/GraphicsImage.h"
// try to get it from the file, if possible. Zipped files are
// unzipped in the readBB_from_PSFile-Function
- string const bb = readBB_from_PSFile(abs_file);
+ string const bb = graphics::readBB_from_PSFile(abs_file);
if (!bb.empty())
return bb;
--- /dev/null
+/**
+ * \file epstools.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * parts Copyright 1985, 1990, 1993 Free Software Foundation, Inc.
+ *
+ * \author Ivan Schreter
+ * \author Dirk Niggemann
+ * \author Asger Alstrup
+ * \author Lars Gullik Bjønnes
+ * \author Jean-Marc Lasgouttes
+ * \author Angus Leeming
+ * \author John Levon
+ * \author Herbert Voß
+ *
+ * Full author contact details are available in file CREDITS.
+ *
+ * Utilities for manipulation of Encapsulated Postscript files
+ */
+
+#include <config.h>
+
+#include "graphics/epstools.h"
+
+#include "Format.h"
+
+#include "support/debug.h"
+#include "support/filetools.h"
+#include "support/FileName.h"
+#include "support/regex.h"
+
+using namespace std;
+using namespace lyx::support;
+
+namespace lyx {
+namespace graphics {
+
+
+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") {
+ LYXERR(Debug::GRAPHICS, "[readBB_from_PSFile] no(e)ps-format");
+ if (zipped)
+ file_.removeFile();
+ 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();
+ LYXERR(Debug::GRAPHICS, "[readBB_from_PSFile] " << bb);
+ if (zipped)
+ file_.removeFile();
+ return bb;
+ }
+ }
+ LYXERR(Debug::GRAPHICS, "[readBB_from_PSFile] no bb found");
+ if (zipped)
+ file_.removeFile();
+ return string();
+}
+
+
+} // namespace graphics
+} // namespace lyx
--- /dev/null
+// -*- C++ -*-
+/**
+ * \file epstools.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Lars Gullik Bjønnes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef LYX_EPSTOOLS_H
+#define LYX_EPSTOOLS_H
+
+#include <string>
+
+namespace lyx {
+namespace support {
+
+class FileName;
+
+}
+
+namespace graphics {
+
+/// read the BoundingBox entry from a ps/eps-file
+std::string const readBB_from_PSFile(support::FileName const & file);
+
+} // namespace graphics
+} // namespace lyx
+
+#endif
#include "Lexer.h"
#include "LyXRC.h"
+#include "graphics/epstools.h"
#include "graphics/GraphicsParams.h"
#include "graphics/GraphicsTypes.h"
#include "support/convert.h"
#include "support/debug.h"
-#include "support/filetools.h"
#include "support/lyxlib.h"
#include "support/lstrings.h"
#include "support/Translator.h"
pars.bb = bb;
// Get the original Bounding Box from the file
- string const tmp = readBB_from_PSFile(filename);
+ string const tmp = graphics::readBB_from_PSFile(filename);
LYXERR(Debug::GRAPHICS, "BB_from_File: " << tmp);
if (!tmp.empty()) {
unsigned int const bb_orig_xl = convert<unsigned int>(token(tmp, ' ', 0));
}
-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") {
- LYXERR(Debug::GRAPHICS, "[readBB_from_PSFile] no(e)ps-format");
- if (zipped)
- file_.removeFile();
- 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();
- LYXERR(Debug::GRAPHICS, "[readBB_from_PSFile] " << bb);
- if (zipped)
- file_.removeFile();
- return bb;
- }
- }
- LYXERR(Debug::GRAPHICS, "[readBB_from_PSFile] no bb found");
- if (zipped)
- file_.removeFile();
- return string();
-}
-
-
int compare_timestamps(FileName const & file1, FileName const & file2)
{
// If the original is newer than the copy, then copy the original
FileName const findtexfile(std::string const & fil,
std::string const & format);
-/// read the BoundingBox entry from a ps/eps/pdf-file
-std::string const readBB_from_PSFile(FileName const & file);
-
/** \param file1, file2 the two files to be compared. Must have absolute paths.
* \returns 1 if \c file1 has a more recent timestamp than \c file2,
* 0 if their timestamps are the same,