Commit 4c58a536 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Fix Bug 436880 - Kmail ignores right-to-left text direction

BUG: 436880
FIXED-IN: 17.04.2
parent 5313b673
Pipeline #61691 passed with stage
in 3 minutes and 36 seconds
......@@ -121,7 +121,8 @@ public:
@param left The left margin of the new paragraph.
@param right The right margin of the new paragraph.
*/
virtual void beginParagraph(Qt::Alignment a = Qt::AlignLeft, qreal top = 0.0, qreal bottom = 0.0, qreal left = 0.0, qreal right = 0.0) = 0;
virtual void
beginParagraph(Qt::Alignment a = Qt::AlignLeft, qreal top = 0.0, qreal bottom = 0.0, qreal left = 0.0, qreal right = 0.0, bool leftToRightText = false) = 0;
/** Close the paragraph in the markup. */
virtual void endParagraph() = 0;
......
......@@ -920,8 +920,8 @@ void TextHTMLBuilderTest::testBug436880()
md->processDocument(doc);
auto result = hb->getResult();
qDebug() << " result " << result;
auto regex = QRegularExpression(QStringLiteral("^<p dir='rtl' style=\"margin-top:12;margin-bottom:12;margin-left:0;margin-right:0;\">test</p>\n"));
// qDebug() << " result " << result;
auto regex = QRegularExpression(QStringLiteral("^<p style=\"margin-top:12;margin-bottom:12;margin-left:0;margin-right:0;\" dir='rtl'>test</p>\n"));
QVERIFY(regex.match(result).hasMatch());
delete md;
......
......@@ -46,6 +46,7 @@ QTextFrame::iterator MarkupDirector::processBlockContents(QTextFrame::iterator f
const auto blockFormat = block.blockFormat();
const auto blockAlignment = blockFormat.alignment();
const bool leftToRightText = block.textDirection() == Qt::RightToLeft;
// TODO: decide when to use <h1> etc.
#ifdef ADD_HEADER_SUPPORT
......@@ -86,7 +87,12 @@ QTextFrame::iterator MarkupDirector::processBlockContents(QTextFrame::iterator f
// an action for them yet,
// So users can't edit them. See bug
// https://bugs.kde.org/show_bug.cgi?id=160600
m_builder->beginParagraph(blockAlignment, blockFormat.topMargin(), blockFormat.bottomMargin(), blockFormat.leftMargin(), blockFormat.rightMargin());
m_builder->beginParagraph(blockAlignment,
blockFormat.topMargin(),
blockFormat.bottomMargin(),
blockFormat.leftMargin(),
blockFormat.rightMargin(),
leftToRightText);
}
while (!it.atEnd()) {
......
......@@ -361,9 +361,10 @@ QString PlainTextMarkupBuilder::getResult()
return ret;
}
void PlainTextMarkupBuilder::beginParagraph(Qt::Alignment a, qreal top, qreal bottom, qreal left, qreal right)
void PlainTextMarkupBuilder::beginParagraph(Qt::Alignment a, qreal top, qreal bottom, qreal left, qreal right, bool leftToRightText)
{
Q_UNUSED(a)
Q_UNUSED(leftToRightText)
Q_D(PlainTextMarkupBuilder);
if (isQuoteBlock(top, bottom, left, right)) {
d->m_text.append(d->m_quoteprefix);
......
......@@ -41,7 +41,8 @@ public:
void endAnchor() override;
void beginParagraph(Qt::Alignment a = Qt::AlignLeft, qreal top = 0.0, qreal bottom = 0.0, qreal left = 0.0, qreal right = 0.0) override;
void beginParagraph(Qt::Alignment a = Qt::AlignLeft, qreal top = 0.0, qreal bottom = 0.0, qreal left = 0.0, qreal right = 0.0, bool leftToRightText = false)
override;
void endParagraph() override;
void addNewline() override;
......
......@@ -160,7 +160,7 @@ void TextHTMLBuilder::endFontPointSize()
d->m_text.append(QStringLiteral("</span>"));
}
void TextHTMLBuilder::beginParagraph(Qt::Alignment al, qreal topMargin, qreal bottomMargin, qreal leftMargin, qreal rightMargin)
void TextHTMLBuilder::beginParagraph(Qt::Alignment al, qreal topMargin, qreal bottomMargin, qreal leftMargin, qreal rightMargin, bool leftToRightText)
{
Q_D(TextHTMLBuilder);
// Don't put paragraph tags inside li tags. Qt bug reported.
......@@ -191,6 +191,9 @@ void TextHTMLBuilder::beginParagraph(Qt::Alignment al, qreal topMargin, qreal bo
if (!styleString.isEmpty()) {
d->m_text.append(QStringLiteral(" style=\"") + styleString + QLatin1Char('"'));
}
if (leftToRightText) {
d->m_text.append(QStringLiteral(" dir='rtl'"));
}
d->m_text.append(QLatin1Char('>'));
// }
}
......
......@@ -130,8 +130,12 @@ public:
@param leftMargin The new paragraph leftMargin
@param rightMargin The new paragraph rightMargin
*/
void
beginParagraph(Qt::Alignment al = Qt::AlignLeft, qreal topMargin = 0.0, qreal bottomMargin = 0.0, qreal leftMargin = 0.0, qreal rightMargin = 0.0) override;
void beginParagraph(Qt::Alignment al = Qt::AlignLeft,
qreal topMargin = 0.0,
qreal bottomMargin = 0.0,
qreal leftMargin = 0.0,
qreal rightMargin = 0.0,
bool leftToRightText = false) override;
/**
Begin a new header element.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment