]> git.lyx.org Git - lyx.git/commitdiff
require file extension for included graphics
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Thu, 29 Apr 2004 09:24:29 +0000 (09:24 +0000)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Thu, 29 Apr 2004 09:24:29 +0000 (09:24 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8706 a592a061-630c-0410-9148-cb99ea01b6c8

development/FORMAT
lib/lyx2lyx/ChangeLog
lib/lyx2lyx/lyx_1_4.py
lib/lyx2lyx/parser_tools.py
src/ChangeLog
src/buffer.C
src/insets/ChangeLog
src/insets/insetgraphics.C

index ad24e10799c78ba8d44bcf53394f2cf3bbec8e9e..de32b9134b6cea82c07d3b41d31f0c29a7cf90cc 100644 (file)
@@ -1,6 +1,11 @@
 LyX file-format changes
 -----------------------
 
+2004-04-29  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
+
+       * format incremented to 233.
+       * insetgraphics does not allow filenames without extension anymore.
+       The complete filename has to be given.
 
 2004-03-29  Jürgen Spitzmüller  <j.spitzmueller@gmx.de>
 
index 2bd48692895181d537daec2640bb3714aeca9039..f9984032cbfaa5a6f14d035b3926a681982789fb 100644 (file)
@@ -1,3 +1,9 @@
+2004-04-29  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
+
+       * lyx_1_4.py (convert_graphics): new, convert graphics filenames
+       * lyx_1_4.py (revert, convert): handle format 233
+       * lyx2lyx: up the format to 233.
+
 2004-04-19  José Matos   <jamatos@lyx.orrg>
        * parser_tools.py (chain): fix the detection of the last format for
        revertions.
index 212805b338295b331db114da46988a84f733822c..058d3e9f7b14115a833236c15007523615984e63 100644 (file)
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 import re
+from os import access, F_OK
+import os.path
 from parser_tools import find_token, find_end_of_inset, get_next_paragraph, \
                          get_paragraph, get_value, del_token, is_nonempty_line,\
-                        find_tokens, find_end_of
+                        find_tokens, find_end_of, find_token2
+from sys import stdin
 from string import replace, split, find, strip, join
 
 ##
@@ -1115,6 +1118,46 @@ def revert_float(lines, opt):
         del_token(lines, 'sideways', i, j)
         i = i + 1
 
+def convert_graphics(lines, opt):
+    """ Add extension to filenames of insetgraphics if necessary.
+    """
+    if opt.input == stdin:
+       dir = ""
+    else:
+       dir = os.path.dirname(os.path.abspath(opt.input.name))
+    i = 0
+    while 1:
+        i = find_token(lines, "\\begin_inset Graphics", i)
+        if i == -1:
+            return
+
+       j = find_token2(lines, "filename", i)
+        if j == -1:
+            return
+        i = i + 1
+       filename = split(lines[j])[1]
+       absname = os.path.normpath(os.path.join(dir, filename))
+       if opt.input == stdin and not os.path.isabs(filename):
+           # We don't know the directory and cannot check the file.
+           # We could use a heuristic and take the current directory,
+           # and we could try to find out if filename has an extension,
+           # but that would be just guesses and could be wrong.
+           opt.warning("""Warning: Can not determine wether file
+         %s
+         needs an extension when reading from standard input.
+         You may need to correct the file manually or run
+         lyx2lyx again with the .lyx file as commandline argument.""" % filename)
+           continue
+       # This needs to be the same algorithm as in pre 233 insetgraphics
+       if access(absname, F_OK):
+           continue
+       if access(absname + ".ps", F_OK):
+           lines[j] = replace(lines[j], filename, filename + ".ps")
+           continue
+       if access(absname + ".eps", F_OK):
+           lines[j] = replace(lines[j], filename, filename + ".eps")
+
+
 ##
 # Convertion hub
 #
@@ -1177,8 +1220,17 @@ def convert(header, body, opt):
     if opt.format < 232:
         convert_bibtopic(header, opt)
        opt.format = 232
+    if opt.end == opt.format: return
+
+    if opt.format < 233:
+        convert_graphics(body, opt)
+       opt.format = 233
 
 def revert(header, body, opt):
+    if opt.format > 232:
+       opt.format = 232
+    if opt.end == opt.format: return
+
     if opt.format > 231:
         revert_bibtopic(header, opt)
        opt.format = 231
index 95f60d22fc802b311732fefba46b0dbc5c618c65..ac4651c4c380e162e055254d64d437f5447e2018 100644 (file)
@@ -242,7 +242,7 @@ def set_version(lines, version):
 format_re = re.compile(r"(\d)[\.,]?(\d\d)")
 fileformat = re.compile(r"\\lyxformat\s*(\S*)")
 lst_ft = [210, 215, 216, 217, 218, 220, 221, 223, 224, 225, 226, 227, 228, 229, 
-          230, 231, 232]
+          230, 231, 232, 233]
 
 format_relation = [("0_10",  [210], ["0.10.7","0.10"]),
                    ("0_12",  [215], ["0.12","0.12.1","0.12"]),
@@ -254,7 +254,7 @@ format_relation = [("0_10",  [210], ["0.10.7","0.10"]),
                    ("1_1_6fix3", [218], ["1.1.6fix3","1.1.6fix4","1.1"]),
                    ("1_2", [220], ["1.2.0","1.2.1","1.2.3","1.2.4","1.2"]),
                    ("1_3", [221], ["1.3.0","1.3.1","1.3.2","1.3.3","1.3.4","1.3"]),
-                   ("1_4", [223,224,225,226,227,228,229,230,231,232], ["1.4.0cvs","1.4"])]
+                   ("1_4", [223,224,225,226,227,228,229,230,231,232,233], ["1.4.0cvs","1.4"])]
 
 def lyxformat(format, opt):
     result = format_re.match(format)
index a6dddf70b80b066ddec3a2b730c4a3d71f916e63..05404ca962da4358944a7748fe6ed2b9e49787d3 100644 (file)
@@ -1,3 +1,7 @@
+2004-04-29  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
+
+       * buffer.C: increment format to 233.
+
 2004-04-28  Angus Leeming  <leeming@lyx.org>
 
        * BufferView.[Ch] (c-tor):
index e6e5d02a63cadc38f3243dd9b2aef4b5975395a1..054c7f0659b52cec0b71fa2c2c7545c474587e50 100644 (file)
@@ -135,7 +135,7 @@ extern BufferList bufferlist;
 
 namespace {
 
-const int LYX_FORMAT = 232;
+const int LYX_FORMAT = 233;
 
 } // namespace anon
 
index 3f3e4c711ddb75c6755add9e6527286a1d1ec5c0..e14530d5df46a09cf66fa09bb52c5e70b549cc9e 100644 (file)
@@ -1,3 +1,8 @@
+2004-04-29  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
+
+       * insetgraphics.C: require file extension (file format change!)
+       * insetgraphics.C (latex): handle zipped files for "nice" export
+
 2004-04-26  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
 
        * insetgraphics.C (latex): strip the extension and replace dots in
index 3f9f3465a3448c239c6e6fe04fdd1609fbf6f58b..288a645daf044281c8aea890843e13922c17dacd 100644 (file)
@@ -110,10 +110,6 @@ using std::ostringstream;
 
 namespace {
 
-///////////////////////////////////////////////////////////////////////////
-int const VersionNumber = 1;
-///////////////////////////////////////////////////////////////////////////
-
 // This function is a utility function
 // ... that should be with ChangeExtension ...
 inline
@@ -540,21 +536,12 @@ int InsetGraphics::latex(Buffer const & buf, ostream & os,
        string const relative_file =
                params().filename.relFilename(buf.filePath());
 
-       // A missing (e)ps-extension is no problem for LaTeX, so
-       // we have to test three different cases
-#ifdef WITH_WARNINGS
-#warning uh, but can our cache handle it ? no.
-#endif
        string const file_ = params().filename.absFilename();
-       bool const file_exists =
-               !file_.empty() &&
-               (IsFileReadable(file_) ||               // original
-                IsFileReadable(file_ + ".eps") ||      // original.eps
-                IsFileReadable(file_ + ".ps"));        // original.ps
+       bool const file_exists = !file_.empty() && IsFileReadable(file_);
        string const message = file_exists ?
                string() : string("bb = 0 0 200 100, draft, type=eps");
        // if !message.empty() than there was no existing file
-       // "filename(.(e)ps)" found. In this case LaTeX
+       // "filename" found. In this case LaTeX
        // draws only a rectangle with the above bb and the
        // not found filename in it.
        lyxerr[Debug::GRAPHICS]
@@ -596,7 +583,8 @@ int InsetGraphics::latex(Buffer const & buf, ostream & os,
                // Remove the extension so the LaTeX will use whatever
                // is appropriate (when there are several versions in
                // different formats)
-               if (!(IsFileReadable(file_ + ".eps") || IsFileReadable(file_ + ".ps")))
+               basename = RemoveExtension(basename);
+               if(params().filename.isZipped())
                        basename = RemoveExtension(basename);
                // This works only if the filename contains no dots besides
                // the just removed one. We can fool here by replacing all