commit d712c67be9231c84d6acf88e75a2cc08ba6a1b42
Author: Jean-Marc Lasgouttes <[email protected]>
Date:   Fri Jan 13 10:17:05 2017 +0100

    BOX tweak
    
    Add a pixel gap around boxes.
    
    When a box is invisible, its width should be null (but keep the weight
    to avoid drawing problems (think empty sqrt in a macro).
---
 src/mathed/MathRow.cpp |   22 ++++++++++++++--------
 1 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/src/mathed/MathRow.cpp b/src/mathed/MathRow.cpp
index 9465b32..0c6995a 100644
--- a/src/mathed/MathRow.cpp
+++ b/src/mathed/MathRow.cpp
@@ -51,10 +51,10 @@ MathRow::MathRow(MetricsInfo & mi, MathData const * ar)
        // Then insert the MathData argument
        bool const has_contents = ar->addToMathRow(*this, mi);
 
-       // empty arrays are visible when they are editable
-       // we reserve the necessary space anyway (even if nothing gets drawn)
+       // A MathRow should not be completely empty
        if (!has_contents) {
                Element e(mi, BOX, MC_ORD);
+               // empty arrays are visible when they are editable
                e.color = mi.base.macro_nesting == 0 ? Color_mathline : 
Color_none;
                push_back(e);
        }
@@ -175,7 +175,13 @@ void MathRow::metrics(MetricsInfo & mi, Dimension & dim) 
const
                        break;
                case BOX:
                        d = theFontMetrics(mi.base.font).dimension('I');
-                       d.wid += e.before + e.after;
+                       if (e.color != Color_none) {
+                               // allow for one pixel before/after the box.
+                               d.wid += e.before + e.after + 2;
+                       } else {
+                               // hide the box, but give it some height
+                               d.wid = 0;
+                       }
                        break;
                }
 
@@ -285,12 +291,12 @@ void MathRow::draw(PainterInfo & pi, int x, int const y) 
const
                                pi.pain.enterMonochromeMode(Color_mathbg, 
Color_mathmacroblend);
                        break;
                case BOX: {
+                       if (e.color == Color_none)
+                               break;
                        Dimension const d = 
theFontMetrics(pi.base.font).dimension('I');
-                       // the box is not visible in non-editable context 
(except for grey macro boxes).
-                       if (e.color != Color_none)
-                               pi.pain.rectangle(x + e.before, y - d.ascent(),
-                                                 d.width() - 1, d.height() - 
1, e.color);
-                       x += d.wid + e.before + e.after;
+                       pi.pain.rectangle(x + e.before + 1, y - d.ascent(),
+                                         d.width() - 1, d.height() - 1, 
e.color);
+                       x += d.wid + 2 + e.before + e.after;
                        break;
                }
                case DUMMY:

Reply via email to