commit fa2dcd37a2ce34a7202477cc529f0055557d2503
Author: Jean-Marc Lasgouttes <[email protected]>
Date: Tue Apr 11 13:03:34 2017 +0200
Show properly on screen "indented" maths.
This is done by two things:
1/ the equation returns LefAlign as display() value
2/ Inset::indent() return a value (in general 0) that should be added
on the left (or right in rtl) of the inset when it is flushed.
The code that uses these values is in TextMetrics::computeRowMetrics.
---
src/TextMetrics.cpp | 16 +++++++++++++---
src/insets/Inset.h | 2 ++
src/mathed/InsetMathHull.cpp | 21 ++++++++++++++++++++-
src/mathed/InsetMathHull.h | 2 ++
4 files changed, 37 insertions(+), 4 deletions(-)
diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp
index c577b47..52cbcef 100644
--- a/src/TextMetrics.cpp
+++ b/src/TextMetrics.cpp
@@ -627,15 +627,25 @@ void TextMetrics::computeRowMetrics(Row & row, int width)
const
row.dimension().wid += w;
}
break;
+ case LYX_ALIGN_LEFT:
+ // a displayed inset that is flushed
+ if (Inset const * inset = par.getInset(row.pos()))
+ row.left_margin += inset->indent(*bv_);
+ break;
case LYX_ALIGN_RIGHT:
- row.left_margin += w;
- row.dimension().wid += w;
+ if (Inset const * inset = par.getInset(row.pos())) {
+ int const new_w = max(w - inset->indent(*bv_),
0);
+ row.left_margin += new_w;
+ row.dimension().wid += new_w;
+ } else {
+ row.left_margin += w;
+ row.dimension().wid += w;
+ }
break;
case LYX_ALIGN_CENTER:
row.dimension().wid += w / 2;
row.left_margin += w / 2;
break;
- case LYX_ALIGN_LEFT:
case LYX_ALIGN_NONE:
case LYX_ALIGN_LAYOUT:
case LYX_ALIGN_SPECIAL:
diff --git a/src/insets/Inset.h b/src/insets/Inset.h
index 3d93904..9ba8945 100644
--- a/src/insets/Inset.h
+++ b/src/insets/Inset.h
@@ -460,6 +460,8 @@ public:
/// should we have a non-filled line before this inset?
virtual DisplayType display() const { return Inline; }
+ /// indentation before this inset (only needed for displayed hull
insets with fleqn option)
+ virtual int indent(BufferView const &) const { return 0; }
///
virtual LyXAlignment contentAlignment() const { return LYX_ALIGN_NONE; }
/// should we break lines after this inset?
diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp
index 38cdd26..3e897df 100644
--- a/src/mathed/InsetMathHull.cpp
+++ b/src/mathed/InsetMathHull.cpp
@@ -993,12 +993,31 @@ Inset::DisplayType InsetMathHull::display() const
case hullEquation:
case hullMultline:
case hullGather:
- return AlignCenter;
+ if (buffer().params().is_math_indent)
+ return AlignLeft;
+ else
+ return AlignCenter;
}
// avoid warning
return AlignCenter;
}
+
+int InsetMathHull::indent(BufferView const & bv) const
+{
+ // FIXME: set this in the textclass. This value is what the article
class uses.
+ static Length default_indent(2.5, Length::EM);
+ if (buffer().params().is_math_indent) {
+ Length const & len = buffer().params().getMathIndent();
+ if (len.empty())
+ return bv.inPixels(default_indent);
+ else
+ return bv.inPixels(len);
+ } else
+ return Inset::indent(bv);
+}
+
+
bool InsetMathHull::numberedType() const
{
switch (type_) {
diff --git a/src/mathed/InsetMathHull.h b/src/mathed/InsetMathHull.h
index bae2653..1b3eef3 100644
--- a/src/mathed/InsetMathHull.h
+++ b/src/mathed/InsetMathHull.h
@@ -294,6 +294,8 @@ public:
Inset * editXY(Cursor & cur, int x, int y);
///
DisplayType display() const;
+ ///
+ int indent(BufferView const &) const;
protected:
///