]> git.lyx.org Git - features.git/commitdiff
Move readBB_from_PSFile() out of support (no code change),
authorGeorg Baum <georg.baum@post.rwth-aachen.de>
Wed, 15 Feb 2012 20:50:52 +0000 (20:50 +0000)
committerGeorg Baum <georg.baum@post.rwth-aachen.de>
Wed, 15 Feb 2012 20:50:52 +0000 (20:50 +0000)
since it soon will need to use the Formats class.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@40757 a592a061-630c-0410-9148-cb99ea01b6c8

src/Makefile.am
src/frontends/qt4/GuiExternal.cpp
src/frontends/qt4/GuiGraphics.cpp
src/graphics/epstools.cpp [new file with mode: 0644]
src/graphics/epstools.h [new file with mode: 0644]
src/insets/InsetGraphicsParams.cpp
src/support/filetools.cpp
src/support/filetools.h

index 84f4e85b71d97f2dfa1f736f415ffa9ae731feaf..a96472fb7037a333f27c9639843e41be7638c837 100644 (file)
@@ -339,6 +339,8 @@ liblyxcore_a_DEPENDENCIES = $(MOCEDFILES)
 noinst_LIBRARIES += liblyxgraphics.a
 
 liblyxgraphics_a_SOURCES = \
+       graphics/epstools.h \
+       graphics/epstools.cpp \
        graphics/GraphicsCache.h \
        graphics/GraphicsCache.cpp \
        graphics/GraphicsCacheItem.h \
index 94decc7b3b9978f3c69dc3c980c14f054fc17c08..d944bc07933097d037486b8bb3898e24db0919f6 100644 (file)
@@ -23,6 +23,7 @@
 #include "insets/ExternalTemplate.h"
 #include "insets/InsetExternal.h"
 
+#include "graphics/epstools.h"
 #include "graphics/GraphicsCache.h"
 #include "graphics/GraphicsCacheItem.h"
 #include "graphics/GraphicsImage.h"
@@ -299,7 +300,7 @@ void GuiExternal::getbbClicked()
        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;
index 465ffcea34406d8d5e0804b8962e1fe3838e9526..99cf2d85e203524146366a6b81c1435d08098fa5 100644 (file)
@@ -25,6 +25,7 @@
 #include "Length.h"
 #include "LyXRC.h"
 
+#include "graphics/epstools.h"
 #include "graphics/GraphicsCache.h"
 #include "graphics/GraphicsCacheItem.h"
 #include "graphics/GraphicsImage.h"
@@ -806,7 +807,7 @@ string GuiGraphics::readBoundingBox(string const & file)
 
        // 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;
 
diff --git a/src/graphics/epstools.cpp b/src/graphics/epstools.cpp
new file mode 100644 (file)
index 0000000..44d577c
--- /dev/null
@@ -0,0 +1,90 @@
+/**
+ * \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
diff --git a/src/graphics/epstools.h b/src/graphics/epstools.h
new file mode 100644 (file)
index 0000000..043d6bb
--- /dev/null
@@ -0,0 +1,32 @@
+// -*- 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
index 4f0266ccf885d1a28ca14303bc130ed37e17dfd1..f4cd119f6e34ffd762e24c1bf3b8ce52d8a2ced4 100644 (file)
 #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"
@@ -262,7 +262,7 @@ graphics::Params InsetGraphicsParams::as_grfxParams() const
                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));
index 0dcb2edc575ff7ad0c83d137b28faf47f3b23d31..4f681b009e90c7014f55e6f03780306ca8c13569 100644 (file)
@@ -1016,55 +1016,6 @@ FileName const findtexfile(string const & fil, string const & /*format*/)
 }
 
 
-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
index 48ebbd6046c5c174034b408cecdd415b7f95ab35..92c6eb57e7ec8b50edac51e06051cfb282e40067 100644 (file)
@@ -275,9 +275,6 @@ bool readLink(FileName const & file, FileName & link);
 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,