commit dea245d5409fb47af7efb5248f1b43e15d6563d3
Author: Jean-Marc Lasgouttes <[email protected]>
Date: Tue Apr 2 11:05:19 2019 +0200
Draw display math numbering outside of inset
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 | 3 +-
src/MetricsInfo.h | 2 +
src/TextMetrics.cpp | 8 ++++++
src/mathed/InsetMathHull.cpp | 53 ++++++++++++------------------------------
4 files changed, 27 insertions(+), 39 deletions(-)
diff --git a/src/MetricsInfo.cpp b/src/MetricsInfo.cpp
index 547d14c..3ec1529 100644
--- a/src/MetricsInfo.cpp
+++ b/src/MetricsInfo.cpp
@@ -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;
}
diff --git a/src/MetricsInfo.h b/src/MetricsInfo.h
index 7fe7240..08efedb 100644
--- a/src/MetricsInfo.h
+++ b/src/MetricsInfo.h
@@ -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 {};
diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp
index d07c550..65a1aa7 100644
--- a/src/TextMetrics.cpp
+++ b/src/TextMetrics.cpp
@@ -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];
diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp
index a90d409..79a56be 100644
--- a/src/mathed/InsetMathHull.cpp
+++ b/src/mathed/InsetMathHull.cpp
@@ -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,