From 2208f4f51990b10054fe83281a52eb67071629be Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Wed, 10 Jul 2019 14:50:08 +0200 Subject: [PATCH] Fix right and left layout alignment (in workarea) with RTL Fixes: #11606 (cherry picked from commit b6f0c1de3d31b33452ad87a3a416731907e3c52e) --- src/Paragraph.cpp | 18 ++++++++++++++++-- src/Paragraph.h | 4 +++- src/TextMetrics.cpp | 4 ++-- src/frontends/qt4/GuiParagraph.cpp | 8 +------- src/frontends/qt4/GuiParagraph.h | 2 -- src/output_latex.cpp | 12 ++++++------ status.23x | 2 ++ 7 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index 8c77f58767..9d1b9e6f1f 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -2032,15 +2032,29 @@ depth_type Paragraph::getMaxDepthAfter() const } -LyXAlignment Paragraph::getAlign() const +LyXAlignment Paragraph::getAlign(BufferParams const & bparams) const { if (d->params_.align() == LYX_ALIGN_LAYOUT) - return d->layout_->align; + return getDefaultAlign(bparams); else return d->params_.align(); } +LyXAlignment Paragraph::getDefaultAlign(BufferParams const & bparams) const +{ + LyXAlignment res = layout().align; + if (isRTL(bparams)) { + // Swap sides + if (res == LYX_ALIGN_LEFT) + res = LYX_ALIGN_RIGHT; + else if (res == LYX_ALIGN_RIGHT) + res = LYX_ALIGN_LEFT; + } + return res; +} + + docstring const & Paragraph::labelString() const { return d->params_.labelString(); diff --git a/src/Paragraph.h b/src/Paragraph.h index 34ae917f18..61cd05853e 100644 --- a/src/Paragraph.h +++ b/src/Paragraph.h @@ -312,7 +312,9 @@ public: /// Set label width string. void setLabelWidthString(docstring const & s); /// Actual paragraph alignment used - LyXAlignment getAlign() const; + LyXAlignment getAlign(BufferParams const &) const; + /// Default paragraph alignment as determined by layout + LyXAlignment getDefaultAlign(BufferParams const &) const; /// The nesting depth of a paragraph depth_type getDepth() const; /// The maximal possible depth of a paragraph after this one diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp index f7397f7b89..070a880e62 100644 --- a/src/TextMetrics.cpp +++ b/src/TextMetrics.cpp @@ -537,7 +537,7 @@ bool TextMetrics::redoParagraph(pit_type const pit) LyXAlignment TextMetrics::getAlign(Paragraph const & par, Row const & row) const { - LyXAlignment align = par.getAlign(); + LyXAlignment align = par.getAlign(bv_->buffer().params()); // handle alignment inside tabular cells Inset const & owner = text_->inset(); @@ -1749,7 +1749,7 @@ int TextMetrics::leftMargin(pit_type const pit, pos_type const pos) const if (!par.params().leftIndent().zero()) l_margin += par.params().leftIndent().inPixels(max_width_, lfm.em()); - LyXAlignment align = par.getAlign(); + LyXAlignment align = par.getAlign(bv_->buffer().params()); // set the correct parindent if (pos == 0 diff --git a/src/frontends/qt4/GuiParagraph.cpp b/src/frontends/qt4/GuiParagraph.cpp index 656e70f304..7b16fe9fda 100644 --- a/src/frontends/qt4/GuiParagraph.cpp +++ b/src/frontends/qt4/GuiParagraph.cpp @@ -122,7 +122,7 @@ void GuiParagraph::checkAlignmentRadioButtons() alignDefaultRB->setText(alignDefaultLabel_); else alignDefaultRB->setText(alignDefaultLabel_ + " (" - + labelMap_[alignDefault()] + ")"); + + labelMap_[bufferview()->cursor().innerParagraph().getDefaultAlign(buffer().params())] + ")"); } @@ -370,12 +370,6 @@ LyXAlignment GuiParagraph::alignPossible() const } -LyXAlignment GuiParagraph::alignDefault() const -{ - return bufferview()->cursor().innerParagraph().layout().align; -} - - bool GuiParagraph::hasLabelwidth() const { Layout layout = bufferview()->cursor().innerParagraph().layout(); diff --git a/src/frontends/qt4/GuiParagraph.h b/src/frontends/qt4/GuiParagraph.h index 735d58ca8f..7d9170b856 100644 --- a/src/frontends/qt4/GuiParagraph.h +++ b/src/frontends/qt4/GuiParagraph.h @@ -60,8 +60,6 @@ private: bool hasLabelwidth() const; /// LyXAlignment alignPossible() const; - /// - LyXAlignment alignDefault() const; private Q_SLOTS: /// diff --git a/src/output_latex.cpp b/src/output_latex.cpp index 3aa219b42f..91e9f60149 100644 --- a/src/output_latex.cpp +++ b/src/output_latex.cpp @@ -1328,20 +1328,20 @@ void TeXOnePar(Buffer const & buf, && !text.inset().getLayout().parbreakIsNewline() && style.latextype != LATEX_ITEM_ENVIRONMENT && style.latextype != LATEX_LIST_ENVIRONMENT - && style.align == par.getAlign() + && style.align == par.getAlign(bparams) && nextpar->getDepth() == par.getDepth() - && nextpar->getAlign() == par.getAlign()) + && nextpar->getAlign(bparams) == par.getAlign(bparams)) || (!next_layout.isEnvironment() && nextpar->getDepth() > par.getDepth() - && nextpar->getAlign() == next_layout.align) + && nextpar->getAlign(bparams) == next_layout.align) || (!style.isEnvironment() && next_layout.latextype == LATEX_ENVIRONMENT && nextpar->getDepth() < par.getDepth()) || (style.isCommand() && !next_layout.isEnvironment() - && style.align == par.getAlign() - && next_layout.align == nextpar->getAlign()) - || (style.align != par.getAlign() + && style.align == par.getAlign(bparams) + && next_layout.align == nextpar->getAlign(bparams)) + || (style.align != par.getAlign(bparams) && tclass.isDefaultLayout(next_layout))) { os << '\n'; } diff --git a/status.23x b/status.23x index e3c5522443..d29ff0a4ae 100644 --- a/status.23x +++ b/status.23x @@ -90,6 +90,8 @@ What's new - Preserve "all authors" state when switching citation style via context menu (bug 11439). +- Fix right and left layout alignment (in workarea) with RTL (bug 11606). + * INTERNALS