]> git.lyx.org Git - features.git/commitdiff
Draw display math numbering outside of inset
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 2 Apr 2019 09:05:19 +0000 (11:05 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Jun 2020 13:48:36 +0000 (15:48 +0200)
This is the first (easiest) step in fixing bugs 10668 and 11333.

The numbering is now drawn outside of the insets, which solves the
alignment problems and make editing easier.

What does not work yet:

- long labels will overwrite equations. To fix this, we need to
  implement the same algorithm as LaTeX and put labels on their own
  row when required.

- previews may need to be adapted similarly to fit the whole screen width

src/MetricsInfo.cpp
src/MetricsInfo.h
src/TextMetrics.cpp
src/mathed/InsetMathHull.cpp

index 547d14c86072f21e5e1163ee465c5c3c42b3bead..3ec1529ba642827e69424243f59014367c70d67a 100644 (file)
@@ -132,7 +132,8 @@ MetricsInfo::MetricsInfo(BufferView * bv, FontInfo font, int textwidth,
 
 PainterInfo::PainterInfo(BufferView * bv, lyx::frontend::Painter & painter)
        : pain(painter), ltr_pos(false), change_(), selected(false),
-       do_spellcheck(true), full_repaint(true), background_color(Color_background)
+         do_spellcheck(true), full_repaint(true), background_color(Color_background),
+         leftx(0), rightx(0)
 {
        base.bv = bv;
 }
index 7fe72405bfd72fc5bd585e24b47bb96473bff925..08efedb9f651208a3efe7adb1284d734b992637e 100644 (file)
@@ -142,6 +142,8 @@ public:
        bool full_repaint;
        /// Current background color
        ColorCode background_color;
+       /// Useful for drawing display math numbering
+       int leftx, rightx;
 };
 
 class TextMetricsInfo {};
index d07c5500eec47f5d51c1de2f5a2e41b5b7476a5a..65a1aa7945eaebac5eebc0ffb0615a3dcc64f3fd 100644 (file)
@@ -48,6 +48,8 @@
 #include "support/convert.h"
 #include "support/debug.h"
 #include "support/lassert.h"
+#include "support/lyxlib.h"
+#include "support/RefChanger.h"
 
 #include <stdlib.h>
 #include <cmath>
@@ -1818,6 +1820,9 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type const pit, int const
        if (pm.rows().empty())
                return;
        size_t const nrows = pm.rows().size();
+       // Remember left and right margin for drawing math numbers
+       Changer changeleft = make_change(pi.leftx, x + leftMargin(pit));
+       Changer changeright = make_change(pi.rightx, x + width() - rightMargin(pit));
 
        // Use fast lane in nodraw stage.
        if (pi.pain.isNull()) {
@@ -1864,6 +1869,9 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type const pit, int const
                }
        }
 
+       if (text_->isRTL(pit))
+               swap(pi.leftx, pi.rightx);
+
        for (size_t i = 0; i != nrows; ++i) {
 
                Row const & row = pm.rows()[i];
index a90d409ff14e434f3de08c33a08d60ac5cc776b2..79a56be6dd8dd30929b2fcbdfac07795d6da53c1 100644 (file)
@@ -560,17 +560,6 @@ void InsetMathHull::metrics(MetricsInfo & mi, Dimension & dim) const
                dim.des += display_margin;
        }
 
-       if (numberedType()) {
-               Changer dummy = mi.base.changeFontSet("mathrm");
-               int l = 0;
-               for (row_type row = 0; row < nrows(); ++row)
-                       l = max(l, mathed_string_width(mi.base.font, nicelabel(row)));
-
-               if (l)
-                       // Value was hardcoded to 30 pixels
-                       dim.wid += mi.base.bv->zoomedPixels(30) + l;
-       }
-
        // reserve some space for marker.
        dim.wid += 2;
 }
@@ -647,45 +636,33 @@ void InsetMathHull::draw(PainterInfo & pi, int x, int y) const
                return;
        }
 
+       // First draw the numbers
        ColorCode color = pi.selected && lyxrc.use_system_colors
                                ? Color_selectiontext : standardColor();
        bool const really_change_color = pi.base.font.color() == Color_none;
        Changer dummy0 = really_change_color ? pi.base.font.changeColor(color)
                : Changer();
-       Changer dummy1 = pi.base.changeFontSet(standardFont());
-       Changer dummy2 = pi.base.font.changeStyle(display() ? DISPLAY_STYLE
-                                                           : TEXT_STYLE);
-
-       int xmath = x;
-       BufferParams::MathNumber const math_number = buffer().params().getMathNumber();
-       if (numberedType() && math_number == BufferParams::LEFT) {
-               Changer dummy = pi.base.changeFontSet("mathrm");
-               int l = 0;
-               for (row_type row = 0; row < nrows(); ++row)
-                       l = max(l, mathed_string_width(pi.base.font, nicelabel(row)));
-
-               if (l)
-                       // Value was hardcoded to 30 pixels
-                       xmath += pi.base.bv->zoomedPixels(30) + l;
-       }
-
-       InsetMathGrid::draw(pi, xmath + 1, y);
-       drawMarkers(pi, x, y);
-
-       if (numberedType()) {
-               Changer dummy = pi.base.changeFontSet("mathrm");
+       if (pi.full_repaint && numberedType()) {
+               BufferParams::MathNumber const math_number = buffer().params().getMathNumber();
                for (row_type row = 0; row < nrows(); ++row) {
                        int const yy = y + rowinfo(row).offset;
                        docstring const nl = nicelabel(row);
-                       if (math_number == BufferParams::LEFT)
-                               pi.draw(x, yy, nl);
-                       else {
-                               int l = mathed_string_width(pi.base.font, nl);
-                               pi.draw(x + dim.wid - l, yy, nl);
+                       if (math_number == BufferParams::LEFT) {
+                               pi.draw(pi.leftx, yy, nl);
+                       else {
+                               int const l = mathed_string_width(pi.base.font, nl);
+                               pi.draw(pi.rightx - l, yy, nl);
                        }
                }
        }
 
+       // Then the equations
+       Changer dummy1 = pi.base.changeFontSet(standardFont());
+       Changer dummy2 = pi.base.font.changeStyle(display() ? DISPLAY_STYLE
+                                                           : TEXT_STYLE);
+       InsetMathGrid::draw(pi, x + 1, y);
+       drawMarkers(pi, x, y);
+
        // drawing change line
        if (canPaintChange(*bv))
                pi.change_.paintCue(pi, x + 1, y + 1 - dim.asc,