tdf#104349 remove the difference between MSO and LO highlight chars

Change-Id: I5daadef359260ea74b828567197228633bb972ca
Reviewed-on: https://gerrit.libreoffice.org/31783
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: jan iversen <jani@documentfoundation.org>
Tested-by: jan iversen <jani@documentfoundation.org>
diff --git a/sw/source/core/text/inftxt.cxx b/sw/source/core/text/inftxt.cxx
index d06ccd5..71b99b1 100644
--- a/sw/source/core/text/inftxt.cxx
+++ b/sw/source/core/text/inftxt.cxx
@@ -690,8 +690,8 @@ void SwTextPaintInfo::DrawText_( const OUString &rText, const SwLinePortion &rPo
        }
        if( aFontPos.X() < 0 )
            aFontPos.X() = 0;
        if( aFontPos.X() < 0 )
            aFontPos.X() = 0;
        if( aFontPos.Y() < 0 )
            aFontPos.Y() = 0;
    }

    if( GetTextFly().IsOn() )
@@ -1184,6 +1184,75 @@ void SwTextPaintInfo::DrawBackBrush( const SwLinePortion &rPor ) const
            aFillColor = *m_pFnt->GetBackColor();
        }

        // tdf#104349 do not hightlight portions of space chars before end of line
        bool           draw = false;
        bool           full = false;
        SwLinePortion *pPos = const_cast<SwLinePortion *>(&rPor);
        sal_Int32      nIdx = GetIdx();
        sal_Int32      nLen;

        do
        {
            nLen = pPos->GetLen();
            for ( int i = nIdx; i < (nIdx + nLen); ++i )
            {
                if ( GetText()[i] == CH_TXTATR_NEWLINE )
                {
                    if ( i >= (GetIdx() + rPor.GetLen()) )
                    {
                        goto drawcontinue;
                    }
                }
                if ( GetText()[i] != CH_BLANK )
                {
                    draw = true;
                    if ( i >= (GetIdx() + rPor.GetLen()) )
                    {
                        full = true;
                        goto drawcontinue;
                    }
                }
            }
            nIdx += nLen;
            pPos = pPos->GetPortion();
        } while ( pPos );

        drawcontinue:

        if ( !draw )
            return;

        if ( !full )
        {
            pPos = const_cast<SwLinePortion *>(&rPor);
            nIdx = GetIdx();

            nLen = pPos->GetLen();
            for ( int i = (nIdx + nLen - 1); i >= nIdx; --i )
            {
                if ( GetText()[i] == CH_TXTATR_NEWLINE )
                {
                    continue;
                }
                if ( GetText()[i] != CH_BLANK )
                {
                    sal_uInt16 nOldWidth = rPor.Width();
                    sal_uInt16 nNewWidth = GetTextSize( m_pOut, nullptr, GetText(), nIdx, (i + 1 - nIdx) ).Width();

                    const_cast<SwLinePortion&>(rPor).Width( nNewWidth );
                    CalcRect( rPor, nullptr, &aIntersect, true );
                    const_cast<SwLinePortion&>(rPor).Width( nOldWidth );

                    if ( ! aIntersect.HasArea() )
                    {
                        return;
                    }

                    break;
                }
            }
        }

        pTmpOut->Push( PushFlags::LINECOLOR | PushFlags::FILLCOLOR );

        pTmpOut->SetFillColor(aFillColor);