Revert "tdf#144305 sw: fix rendering of ruby portions with...

...non-default ruby alignment"

Causing 301278b656e76b6f42af5cf8a6f5c6c02acfffeb will be
reverted in libreoffice-7-2.

This reverts commit 168065841250c190808261cf65afa00f9ecd52e7.

Change-Id: I9b23c9a1980c4ed06cc0c53086ad24f00e75053a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123086
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
diff --git a/sw/CppunitTest_sw_core_text.mk b/sw/CppunitTest_sw_core_text.mk
index 6f19ff6..cb4801a 100644
--- a/sw/CppunitTest_sw_core_text.mk
+++ b/sw/CppunitTest_sw_core_text.mk
@@ -40,7 +40,6 @@ $(eval $(call gb_CppunitTest_use_externals,sw_core_text,\
$(eval $(call gb_CppunitTest_set_include,sw_core_text,\
    -I$(SRCDIR)/sw/inc \
    -I$(SRCDIR)/sw/source/core/inc \
    -I$(SRCDIR)/sw/source/core/text \
    -I$(SRCDIR)/sw/source/uibase/inc \
    -I$(SRCDIR)/sw/qa/inc \
    $$(INCLUDE) \
diff --git a/sw/qa/core/text/data/ruby.fodt b/sw/qa/core/text/data/ruby.fodt
deleted file mode 100644
index b5a0e23..0000000
--- a/sw/qa/core/text/data/ruby.fodt
+++ /dev/null
@@ -1,25 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<office:document xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
  <office:font-face-decls>
  </office:font-face-decls>
  <office:styles>
  </office:styles>
  <office:automatic-styles>
    <style:style style:name="Ru1" style:family="ruby">
      <style:ruby-properties style:ruby-align="left" style:ruby-position="above" loext:ruby-position="above"/>
    </style:style>
    <style:style style:name="Ru2" style:family="ruby">
      <style:ruby-properties style:ruby-align="center" style:ruby-position="above" loext:ruby-position="above"/>
    </style:style>
    <style:style style:name="Ru3" style:family="ruby">
      <style:ruby-properties style:ruby-align="right" style:ruby-position="above" loext:ruby-position="above"/>
    </style:style>
  </office:automatic-styles>
  <office:master-styles>
  </office:master-styles>
  <office:body>
    <office:text>
      <text:p text:style-name="P1">Ruby test: <text:ruby text:style-name="Ru1"><text:ruby-base>base text</text:ruby-base><text:ruby-text text:style-name="Rubies">ruby (left)</text:ruby-text></text:ruby> <text:ruby text:style-name="Ru2"><text:ruby-base>base text</text:ruby-base><text:ruby-text>ruby (center)</text:ruby-text></text:ruby> <text:ruby text:style-name="Ru3"><text:ruby-base>base text</text:ruby-base><text:ruby-text>ruby (right)</text:ruby-text></text:ruby></text:p>
    </office:text>
  </office:body>
</office:document>
diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx
index 6832ad2c..be6406f 100644
--- a/sw/qa/core/text/text.cxx
+++ b/sw/qa/core/text/text.cxx
@@ -21,12 +21,6 @@
#include <docsh.hxx>
#include <unotxdoc.hxx>
#include <wrtsh.hxx>
#include <IDocumentLayoutAccess.hxx>
#include <rootfrm.hxx>
#include <txtfrm.hxx>

#include <porlay.hxx>
#include <pormulti.hxx>

constexpr OUStringLiteral DATA_DIRECTORY = u"/sw/qa/core/text/data/";

@@ -176,46 +170,6 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testLineWidth)
    CPPUNIT_ASSERT_GREATER(static_cast<sal_Int32>(65536), nNewLeft - nOldLeft);
}

CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testRuby)
{
    // Given a document with multiple ruby portions:
    SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "ruby.fodt");

    // When laying out that document:
    SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();

    // Then make sure that no unwanted margin portions are created, making the actual text
    // invisible:
    SwFrame* pPageFrame = pLayout->GetLower();
    SwFrame* pBodyFrame = pPageFrame->GetLower();
    SwFrame* pFrame = pBodyFrame->GetLower();
    CPPUNIT_ASSERT(pFrame->IsTextFrame());
    auto pTextFrame = static_cast<SwTextFrame*>(pFrame);
    SwParaPortion* pPara = pTextFrame->GetPara();
    bool bFirst = true;
    for (SwLinePortion* pPor = pPara->GetFirstPortion(); pPor; pPor = pPor->GetNextPortion())
    {
        // Look for multi-portions in the only paragraph of the document.
        if (pPor->GetWhichPor() != PortionType::Multi)
        {
            continue;
        }

        if (bFirst)
        {
            bFirst = false;
            continue;
        }

        // The second multi-portion has two lines, check the start of the second line.
        auto pMulti = static_cast<SwMultiPortion*>(pPor);
        // Without the accompanying fix in place, this test would have failed, as the portion was a
        // margin portion, not a text portion. The margin was so large that the actual text portion was
        // hidden. No margin is needed here at all.
        CPPUNIT_ASSERT(pMulti->GetRoot().GetNext()->GetFirstPortion()->IsTextPortion());
    }
}

CPPUNIT_PLUGIN_IMPLEMENT();

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/text/porlay.hxx b/sw/source/core/text/porlay.hxx
index bff0bd5..5234a53 100644
--- a/sw/source/core/text/porlay.hxx
+++ b/sw/source/core/text/porlay.hxx
@@ -75,7 +75,7 @@ public:

/// Collection of SwLinePortion instances, representing one line of text.
/// Typically owned by an SwParaPortion.
class SW_DLLPUBLIC SwLineLayout : public SwTextPortion
class SwLineLayout : public SwTextPortion
{
private:
    SwLineLayout *m_pNext;                // The next Line
diff --git a/sw/source/core/text/pormulti.cxx b/sw/source/core/text/pormulti.cxx
index 98b8df7..b94302b 100644
--- a/sw/source/core/text/pormulti.cxx
+++ b/sw/source/core/text/pormulti.cxx
@@ -630,7 +630,7 @@ SwRubyPortion::SwRubyPortion( const SwMultiCreator& rCreate, const SwFont& rFnt,
// If there is a tabulator in smaller line, no adjustment is possible.
void SwRubyPortion::Adjust_( SwTextFormatInfo &rInf )
{
    SwTwips nLineDiff = o3tl::narrowing<SwTwips>(GetRoot().Width()) - GetRoot().GetNext()->Width();
    SwTwips nLineDiff = GetRoot().Width() - GetRoot().GetNext()->Width();
    TextFrameIndex const nOldIdx = rInf.GetIdx();
    if( !nLineDiff )
        return;