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
This commit is contained in:
Jean-Marc Lasgouttes 2019-04-02 11:05:19 +02:00
parent e6b54ea4d2
commit dea245d540
4 changed files with 27 additions and 39 deletions

View 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;
}

View 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 {};

View 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];

View 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,