]> git.lyx.org Git - features.git/commitdiff
(Herbert): move readBB from ControlGraphics to support/filetools.
authorAngus Leeming <leeming@lyx.org>
Mon, 8 Apr 2002 14:55:52 +0000 (14:55 +0000)
committerAngus Leeming <leeming@lyx.org>
Mon, 8 Apr 2002 14:55:52 +0000 (14:55 +0000)
(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

src/frontends/controllers/ChangeLog
src/frontends/controllers/ControlGraphics.C
src/support/ChangeLog
src/support/filetools.C
src/support/filetools.h

index fc898d6e00de13d42c85bf01d60f7294a23b791c..28c0c339c4f7eaea97ad872a7ed4aae752709fe7 100644 (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
index 6c42c5f5cbca2249debc00ea54f023a6e77bf319..5487afba3a541dcf4398b48d188ea3169bb4c8db 100644 (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()));
 }
 
 
index 6b14f8c1bacc876a26416bd6efb60ba0c95643fe..8628a65484da8859076aa95645f319a6e560f3aa 100644 (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
index a17b9158ab13db20fbdcc059750a0617a050ca87..04ef9bb01cc43b44246a3450cd9f8d1d833b5b61 100644 (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();
+}
+
index c04180ae58b5e7cff3d99604f16e1be6e3247891..322cdeab3507799a8fc139d7592abcd40811d3c9 100644 (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