tdf#151968: Fix vertical position of RTL spelling wavy line

Second try. This time making sure start > end even for RTL text.

This also now works for horizontal, vertical and rotated Arabic text, in
Writer and Edit Engine.

Change-Id: I6fe1e9dbb9c071287054200a58d4ddddee073311
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152743
Tested-by: Jenkins
Reviewed-by: خالد حسني <khaled@libreoffice.org>
diff --git a/svx/source/svdraw/svdotextdecomposition.cxx b/svx/source/svdraw/svdotextdecomposition.cxx
index 138b709..726ee85 100644
--- a/svx/source/svdraw/svdotextdecomposition.cxx
+++ b/svx/source/svdraw/svdotextdecomposition.cxx
@@ -427,8 +427,12 @@ namespace
                        // full portion width
                        const double fTextWidth(aDXArray[aDXArray.size() - 1]);

                        fStart = fTextWidth - fStart;
                        fEnd = fTextWidth - fEnd;
                        // tdf#151968
                        // if start < end, OutputDevice::DrawWaveLine() will
                        // think it is a rotated line, so we swap fStart and
                        // fEnd to avoid this.
                        fStart = fTextWidth - fEnd;
                        fEnd = fTextWidth - fStart;
                    }

                    // need to take FontScaling out of values; it's already part of
diff --git a/sw/source/core/txtnode/fntcache.cxx b/sw/source/core/txtnode/fntcache.cxx
index e125906..bc5dd60 100644
--- a/sw/source/core/txtnode/fntcache.cxx
+++ b/sw/source/core/txtnode/fntcache.cxx
@@ -241,10 +241,20 @@ static void lcl_calcLinePos( const CalcLinePosData &rData,
        break;
    }

    // tdf#151968
    // if start < end, OutputDevice::DrawWaveLine() will think it is a rotated
    // line, so we swap nStart and nEnd to avoid this.
    if ( rData.bBidiPor )
        std::swap(rStart, rEnd);

    if ( rData.bSwitchL2R )
    {
        rData.rInf.GetFrame()->SwitchLTRtoRTL( rStart );
        rData.rInf.GetFrame()->SwitchLTRtoRTL( rEnd );

        // tdf#151968
        // We need to do this here as well for LTR text in a RTL paragraph.
        std::swap(rStart, rEnd);
    }

    if ( rData.bSwitchH2V )