From 4cea47d1eb082ed2e957cfe381fe4cdfd951453e Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Thu, 12 Jan 2017 10:27:41 +0100 Subject: [PATCH 1/3] Implement mathClass() for \big and friends The information here is obtained by reading LaTeX sources. --- src/mathed/InsetMathBig.cpp | 23 +++++++++++++++++++++-- src/mathed/InsetMathBig.h | 2 ++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/mathed/InsetMathBig.cpp b/src/mathed/InsetMathBig.cpp index eeaf96514b..889f8d4f97 100644 --- a/src/mathed/InsetMathBig.cpp +++ b/src/mathed/InsetMathBig.cpp @@ -39,6 +39,25 @@ docstring InsetMathBig::name() const } +MathClass InsetMathBig::mathClass() const +{ + /* The class of the delimiter depends on the type (l, m, r, nothing). + * For example, the definition of \bigl in LaTeX sources is + * \def\bigl{\mathopen\big} + */ + switch(name_.back()) { + case 'l': + return MC_OPEN; + case 'm': + return MC_REL; + case 'r': + return MC_CLOSE; + default: + return MC_ORD; + } +} + + Inset * InsetMathBig::clone() const { return new InsetMathBig(*this); @@ -49,9 +68,9 @@ InsetMathBig::size_type InsetMathBig::size() const { // order: big Big bigg Bigg biggg Biggg // 0 1 2 3 4 5 - char_type const c = name_[name_.size() - 1]; + char_type const c = name_.back(); int const base_size = (c == 'l' || c == 'm' || c == 'r') ? 4 : 3; - return name_[0] == 'B' ? + return name_.front() == 'B' ? 2 * (name_.size() - base_size) + 1: 2 * (name_.size() - base_size); } diff --git a/src/mathed/InsetMathBig.h b/src/mathed/InsetMathBig.h index 996a30a39d..83010a9260 100644 --- a/src/mathed/InsetMathBig.h +++ b/src/mathed/InsetMathBig.h @@ -24,6 +24,8 @@ public: InsetMathBig(docstring const & name, docstring const & delim); /// docstring name() const; + /// class is different for l(eft), r(ight) and m(iddle) + MathClass mathClass() const; /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// From 8361fb603eb92fa54b84a49b3996b382804a5f20 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Thu, 12 Jan 2017 11:22:51 +0100 Subject: [PATCH 2/3] Rename InsetMathNest::metrics to cellsMetrics Re-using the name of a virtual method with different semantics is not a good idea anyway. --- src/mathed/InsetMathCancelto.cpp | 2 +- src/mathed/InsetMathNest.cpp | 6 +++--- src/mathed/InsetMathNest.h | 13 ++----------- src/mathed/InsetMathRoot.cpp | 2 +- 4 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/mathed/InsetMathCancelto.cpp b/src/mathed/InsetMathCancelto.cpp index f3ead3cd3a..cf6b006d44 100644 --- a/src/mathed/InsetMathCancelto.cpp +++ b/src/mathed/InsetMathCancelto.cpp @@ -42,7 +42,7 @@ Inset * InsetMathCancelto::clone() const void InsetMathCancelto::metrics(MetricsInfo & mi, Dimension & dim) const { Changer dummy = mi.base.changeEnsureMath(); - InsetMathNest::metrics(mi); + cellsMetrics(mi); Dimension const & dim0 = cell(0).dimension(*mi.base.bv); Dimension const & dim1 = cell(1).dimension(*mi.base.bv); dim.asc = max(dim0.ascent() + 2, dim0.ascent() + dim1.ascent()) + 2 + 8; diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp index 1da75468d2..3460cdca35 100644 --- a/src/mathed/InsetMathNest.cpp +++ b/src/mathed/InsetMathNest.cpp @@ -176,12 +176,12 @@ void InsetMathNest::cursorPos(BufferView const & bv, } -void InsetMathNest::metrics(MetricsInfo const & mi) const +void InsetMathNest::cellsMetrics(MetricsInfo const & mi) const { MetricsInfo m = mi; - for (idx_type i = 0, n = nargs(); i != n; ++i) { + for (auto const & cell : cells_) { Dimension dim; - cell(i).metrics(m, dim); + cell.metrics(m, dim); } } diff --git a/src/mathed/InsetMathNest.h b/src/mathed/InsetMathNest.h index 06668c9d2a..f1426350c3 100644 --- a/src/mathed/InsetMathNest.h +++ b/src/mathed/InsetMathNest.h @@ -33,17 +33,8 @@ public: /// void setBuffer(Buffer &); - // The method below hides inset::metrics() intentionally! - // We have to tell clang not to be fussy about that. -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Woverloaded-virtual" -#endif - /// the size is usually some sort of convex hull of the cells - void metrics(MetricsInfo const & mi) const; -#ifdef __clang__ -#pragma clang diagnostic pop -#endif + /// Update the cells metrics + void cellsMetrics(MetricsInfo const & mi) const; /// draw background if locked void draw(PainterInfo & pi, int x, int y) const; /// draw selection background diff --git a/src/mathed/InsetMathRoot.cpp b/src/mathed/InsetMathRoot.cpp index f8f36d8214..f61db16e8f 100644 --- a/src/mathed/InsetMathRoot.cpp +++ b/src/mathed/InsetMathRoot.cpp @@ -42,7 +42,7 @@ Inset * InsetMathRoot::clone() const void InsetMathRoot::metrics(MetricsInfo & mi, Dimension & dim) const { Changer dummy = mi.base.changeEnsureMath(); - InsetMathNest::metrics(mi); + cellsMetrics(mi); Dimension const & dim0 = cell(0).dimension(*mi.base.bv); Dimension const & dim1 = cell(1).dimension(*mi.base.bv); dim.asc = max(dim0.ascent() + 5, dim1.ascent()) + 2; From cdc847fd304019a19425a0d5d9d42a556a937097 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Thu, 12 Jan 2017 12:15:17 +0100 Subject: [PATCH 3/3] Fix drawing of empty boxes They were actually bigger than their metrics. --- src/mathed/MathRow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mathed/MathRow.cpp b/src/mathed/MathRow.cpp index cfb41642d4..9465b32690 100644 --- a/src/mathed/MathRow.cpp +++ b/src/mathed/MathRow.cpp @@ -289,7 +289,7 @@ void MathRow::draw(PainterInfo & pi, int x, int const y) const // 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(), d.height(), e.color); + d.width() - 1, d.height() - 1, e.color); x += d.wid + e.before + e.after; break; }