]> git.lyx.org Git - features.git/commitdiff
InsetGraphics: use totalheight for height output
authorJuergen Spitzmueller <spitz@lyx.org>
Wed, 14 Aug 2019 14:55:43 +0000 (16:55 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Jun 2020 13:48:43 +0000 (15:48 +0200)
Graphics "height" is only the height above the baseline and thus not
what most people will expect. Also, using height can result in a
division by zero with rotation.

Use totalheight now since this means "height of the figure" (independent
of the baseline).

The custom options field can be used if height is really desired.
We handle this in conversion/reversion, respectively, so document
output will not change.

Hence, file format change.

Fixes: #9676
development/FORMAT
lib/lyx2lyx/lyx_2_4.py
src/insets/InsetGraphics.cpp
src/tex2lyx/text.cpp
src/version.h

index ffecd54693332b84e2d640b0a7888e83e097b7f4..93c0043f3571f767111e6ca4fb9a18d14e9b6d52 100644 (file)
@@ -7,8 +7,11 @@ changes happened in particular if possible. A good example would be
 
 -----------------------
 
+2019-08-14 Jürgen Spitzmüller <spitz@lyx.org>
+       * Format incremented to 589: Height now is totalheight in graphics.
+
 2019-08-12 Jürgen Spitzmüller <spitz@lyx.org>
-       * Format incremented to 588: 
+       * Format incremented to 588:
         - Support \theendnotes of endnotes package via a faked float list.
         - Support enotez package via enotez and foottoenotez modules.
 
index 65b8df5560e1dd205466d807e1d4a731c4c02a95..97a3f3092e34339157ad8a13209fed0eb263125d 100644 (file)
@@ -3470,7 +3470,116 @@ def revert_memoir_endnotes(document):
         else:
             document.body[i : j + 1] = put_cmd_in_ert("\\printpagenotes")
         add_to_preamble(document, ["\\makepagenote"])
-    
+
+
+def revert_totalheight(document):
+    " Reverts graphics height parameter from totalheight to height "
+
+    i = 0
+    while (True):
+        i = find_token(document.body, "\\begin_inset Graphics", i)
+        if i == -1:
+            break
+        j = find_end_of_inset(document.body, i)
+        if j == -1:
+            document.warning("Can't find end of graphics inset at line %d!!" %(i))
+            i += 1
+            continue
+
+        rx = re.compile(r'\s*special\s*(\S+)$')
+        k = find_re(document.body, rx, i, j)
+        special = ""
+        oldheight = ""
+        if k != -1:
+            m = rx.match(document.body[k])
+            if m:
+                special = m.group(1)
+            mspecial = special.split(',')
+            for spc in mspecial:
+                if spc[:7] == "height=":
+                    oldheight = spc.split('=')[1]
+                    mspecial.remove(spc)
+                    break
+            if len(mspecial) > 0:
+                special = ",".join(mspecial)
+            else:
+                special = ""
+
+        rx = re.compile(r'(\s*height\s*)(\S+)$')
+        kk = find_re(document.body, rx, i, j)
+        if kk != -1:
+            m = rx.match(document.body[kk])
+            val = ""
+            if m:
+                val = m.group(2)
+                if k != -1:
+                    if special != "":
+                        val = val + "," + special
+                    document.body[k] = "\tspecial " + "totalheight=" + val
+                else:
+                    document.body.insert(kk, "\tspecial totalheight=" + val) 
+                if oldheight != "":
+                    document.body[kk] = m.group(1) + oldheight
+                else:
+                    del document.body[kk]
+        elif oldheight != "":
+            document.body.insert(k, "\theight " + oldheight) 
+        i = j + 1
+
+
+def convert_totalheight(document):
+    " Converts graphics height parameter from totalheight to height "
+
+    i = 0
+    while (True):
+        i = find_token(document.body, "\\begin_inset Graphics", i)
+        if i == -1:
+            break
+        j = find_end_of_inset(document.body, i)
+        if j == -1:
+            document.warning("Can't find end of graphics inset at line %d!!" %(i))
+            i += 1
+            continue
+
+        rx = re.compile(r'\s*special\s*(\S+)$')
+        k = find_re(document.body, rx, i, j)
+        special = ""
+        newheight = ""
+        if k != -1:
+            m = rx.match(document.body[k])
+            if m:
+                special = m.group(1)
+            mspecial = special.split(',')
+            for spc in mspecial:
+                if spc[:12] == "totalheight=":
+                    newheight = spc.split('=')[1]
+                    mspecial.remove(spc)
+                    break
+            if len(mspecial) > 0:
+                special = ",".join(mspecial)
+            else:
+                special = ""
+
+        rx = re.compile(r'(\s*height\s*)(\S+)$')
+        kk = find_re(document.body, rx, i, j)
+        if kk != -1:
+            m = rx.match(document.body[kk])
+            val = ""
+            if m:
+                val = m.group(2)
+                if k != -1:
+                    if special != "":
+                        val = val + "," + special
+                    document.body[k] = "\tspecial " + "height=" + val
+                else:
+                    document.body.insert(kk + 1, "\tspecial height=" + val) 
+                if newheight != "":
+                    document.body[kk] = m.group(1) + newheight
+                else:
+                    del document.body[kk]
+        elif newheight != "":
+            document.body.insert(k, "\theight " + newheight) 
+        i = j + 1
 
 ##
 # Conversion hub
@@ -3521,10 +3630,12 @@ convert = [
            [585, [convert_pagesizes]],
            [586, []],
            [587, [convert_pagesizenames]],
-           [588, []]
+           [588, []],
+           [589, [convert_totalheight]]
           ]
 
-revert =  [[587, [revert_memoir_endnotes,revert_enotez,revert_theendnotes]],
+revert =  [[588, [revert_totalheight]],
+           [587, [revert_memoir_endnotes,revert_enotez,revert_theendnotes]],
            [586, [revert_pagesizenames]],
            [585, [revert_dupqualicites]],
            [584, [revert_pagesizes,revert_komafontsizes]],
index 04edf265a87ecf7e8bef12754baf30becde15a1f..ab997e1ea4053b8b6e8c5581add40a8fe48d30db 100644 (file)
@@ -399,7 +399,7 @@ string InsetGraphics::createLatexOptions(bool const ps) const
                if (!params().width.zero())
                        size << "width=" << params().width.asLatexString() << ',';
                if (!params().height.zero())
-                       size << "height=" << params().height.asLatexString() << ',';
+                       size << "totalheight=" << params().height.asLatexString() << ',';
                if (params().keepAspectRatio)
                        size << "keepaspectratio,";
        }
index 764cffa9884bd3fd714bc4aa83cc79f291bf521c..9dc589d5e356a6e82940a615f2298bd857ed803e 100644 (file)
@@ -3733,9 +3733,9 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        if (opts.find("width") != opts.end())
                                os << "\twidth "
                                   << translate_len(opts["width"]) << '\n';
-                       if (opts.find("height") != opts.end())
+                       if (opts.find("totalheight") != opts.end())
                                os << "\theight "
-                                  << translate_len(opts["height"]) << '\n';
+                                  << translate_len(opts["totalheight"]) << '\n';
                        if (opts.find("scale") != opts.end()) {
                                istringstream iss(opts["scale"]);
                                double val;
@@ -3751,7 +3751,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                vector<string>::const_iterator s =
                                        find(keys.begin(), keys.end(), "width");
                                if (s == keys.end())
-                                       s = find(keys.begin(), keys.end(), "height");
+                                       s = find(keys.begin(), keys.end(), "totalheight");
                                if (s == keys.end())
                                        s = find(keys.begin(), keys.end(), "scale");
                                if (s != keys.end() && distance(s, a) > 0)
@@ -3812,8 +3812,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                special << "trim,";
                        if (opts.find("viewport") != opts.end())
                                special << "viewport=" << opts["viewport"] << ',';
-                       if (opts.find("totalheight") != opts.end())
-                               special << "totalheight=" << opts["totalheight"] << ',';
+                       if (opts.find("height") != opts.end())
+                               special << "height=" << opts["height"] << ',';
                        if (opts.find("type") != opts.end())
                                special << "type=" << opts["type"] << ',';
                        if (opts.find("ext") != opts.end())
index 110ba804cb4dc48654b5beba60f73ea3f9394dcf..4c964166f0c88873836c9b075542c3cc4aa11eef 100644 (file)
@@ -32,8 +32,8 @@ extern char const * const lyx_version_info;
 
 // Do not remove the comment below, so we get merge conflict in
 // independent branches. Instead add your own.
-#define LYX_FORMAT_LYX 588 // spitz: support \theendnotes
-#define LYX_FORMAT_TEX2LYX 588
+#define LYX_FORMAT_LYX 589 // spitz: height > totalheight
+#define LYX_FORMAT_TEX2LYX 589
 
 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
 #ifndef _MSC_VER