commit 412a724aaf8a532adba71f8e8491c258f651a4e1
Author: Jean-Marc Lasgouttes <[email protected]>
Date: Sat Jul 18 00:07:30 2015 +0200
Some fixups to row margins
In breakRow set left and right margin properly for RTL paragraphs.
Remove corresponding code from ComputeRowMetrics.
In row painter, check the use of left and right margin depending on
context. The problem in the original text is that the various
leftMargin() methods actually represent right margin for RTL
paragraphs. This should be fixed eventually.
diff --git a/src/RowPainter.cpp b/src/RowPainter.cpp
index 412bdfc..9469012 100644
--- a/src/RowPainter.cpp
+++ b/src/RowPainter.cpp
@@ -460,13 +460,10 @@ void RowPainter::paintLabel() const
FontMetrics const & fm = theFontMetrics(font);
double x = x_;
- if (is_rtl) {
- x = width_ - row_.left_margin
- + fm.width(layout.labelsep);
- } else {
- x = x_ - fm.width(layout.labelsep)
- - fm.width(str);
- }
+ if (is_rtl)
+ x = width_ - row_.right_margin + fm.width(layout.labelsep);
+ else
+ x = x_ - fm.width(layout.labelsep) - fm.width(str);
pi_.pain.text(int(x), yo_, str, font);
}
@@ -500,12 +497,10 @@ void RowPainter::paintTopLevelLabel() const
double x = x_;
if (layout.labeltype == LABEL_CENTERED) {
- if (is_rtl)
- x = row_.left_margin;
- x += (width_ - text_metrics_.rightMargin(pm_) -
row_.left_margin) / 2;
+ x = row_.left_margin + (width_ - row_.left_margin -
row_.right_margin) / 2;
x -= fm.width(str) / 2;
} else if (is_rtl) {
- x = width_ - row_.left_margin - fm.width(str);
+ x = width_ - row_.right_margin - fm.width(str);
}
pi_.pain.text(int(x), yo_ - maxdesc - labeladdon, str, font);
}
@@ -580,7 +575,7 @@ void RowPainter::paintLast()
int const y = yo_ - size;
int const max_row_width = width_ - size -
Inset::TEXT_TO_INSET_OFFSET;
int x = is_rtl ? nestMargin() + changebarMargin()
- : max_row_width - text_metrics_.rightMargin(pm_);
+ : max_row_width - row_.right_margin;
// If needed, move the box a bit to avoid overlapping with text.
int const rem = max_row_width - row_.width();
diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp
index 07064b6..1c34d5d 100644
--- a/src/TextMetrics.cpp
+++ b/src/TextMetrics.cpp
@@ -569,12 +569,6 @@ void TextMetrics::computeRowMetrics(pit_type const pit,
// FIXME: put back this assertion when the crash on new doc is solved.
//LASSERT(w >= 0, /**/);
- bool const is_rtl = text_->isRTL(par);
- if (is_rtl)
- row.left_margin = rightMargin(pit);
- else
- row.left_margin = leftMargin(max_width_, pit, row.pos());
-
// is there a manual margin with a manual label
Layout const & layout = par.layout();
@@ -617,7 +611,7 @@ void TextMetrics::computeRowMetrics(pit_type const pit,
&& row.endpos() != par.size()) {
setSeparatorWidth(row, double(w) / ns);
row.dimension().wid = width;
- } else if (is_rtl) {
+ } else if (text_->isRTL(par)) {
row.dimension().wid = width;
row.left_margin += w;
}
@@ -785,13 +779,19 @@ void TextMetrics::breakRow(Row & row, int const
right_margin, pit_type const pit
Paragraph const & par = text_->getPar(pit);
pos_type const end = par.size();
pos_type const pos = row.pos();
- int const width = max_width_ - right_margin;
pos_type const body_pos = par.beginOfBody();
+ bool const is_rtl = text_->isRTL(par);
+
row.clear();
- // This make get changed in computeRowMetrics depending on RTL
row.left_margin = leftMargin(max_width_, pit, pos);
- row.dimension().wid = row.left_margin;
row.right_margin = right_margin;
+ if (is_rtl)
+ swap(row.left_margin, row.right_margin);
+ // Remember that the row width takes into account the left_margin
+ // but not the right_margin.
+ row.dimension().wid = row.left_margin;
+ // the width available for the row.
+ int const width = max_width_ - row.right_margin;
if (pos >= end || row.width() > width) {
row.endpos(end);
@@ -904,7 +904,7 @@ void TextMetrics::breakRow(Row & row, int const
right_margin, pit_type const pit
row.shortenIfNeeded(body_pos, width);
// make sure that the RTL elements are in reverse ordering
- row.reverseRTL(text_->isRTL(par));
+ row.reverseRTL(is_rtl);
}