[Libreoffice-commits] core.git: 4 commits - sw/source

Michael Stahl mstahl at redhat.com
Tue May 12 10:27:20 PDT 2015


 sw/source/core/text/porlay.cxx   |    6 +++---
 sw/source/core/text/pormulti.cxx |    2 +-
 sw/source/core/text/portxt.cxx   |    8 +++++---
 sw/source/core/text/portxt.hxx   |    2 +-
 sw/source/core/text/txthyph.cxx  |   17 ++++++++---------
 5 files changed, 18 insertions(+), 17 deletions(-)

New commits:
commit 21ab418859d5f8fc16730dc26f1dda149ee132fc
Author: Michael Stahl <mstahl at redhat.com>
Date:   Tue May 12 19:02:06 2015 +0200

    sw: replace that awful constructor that overloads SwTxtPortion copy-ctor
    
    ... with a CopyLinePortion function; how can you even...
    
    Change-Id: Ie7d459ee317522e35fdbbd3974afabe7a136fe62

diff --git a/sw/source/core/text/porlay.cxx b/sw/source/core/text/porlay.cxx
index 78572be..72845e8 100644
--- a/sw/source/core/text/porlay.cxx
+++ b/sw/source/core/text/porlay.cxx
@@ -139,7 +139,7 @@ SwLinePortion *SwLineLayout::Insert( SwLinePortion *pIns )
     {
         if( GetLen() )
         {
-            pPortion = new SwTxtPortion(*static_cast<SwLinePortion*>(this));
+            pPortion = SwTxtPortion::CopyLinePortion(*this);
             if( IsBlinking() && pBlink )
             {
                 SetBlinking( false );
@@ -161,7 +161,7 @@ SwLinePortion *SwLineLayout::Append( SwLinePortion *pIns )
     // First attribute change: copy mass and length from *pIns into the first
     // text portion
     if( !pPortion )
-        pPortion = new SwTxtPortion(*static_cast<SwLinePortion*>(this));
+        pPortion = SwTxtPortion::CopyLinePortion(*this);
     // Call with scope or we'll end up with recursion!
     return pPortion->SwLinePortion::Append( pIns );
 }
@@ -184,7 +184,7 @@ SwMarginPortion *SwLineLayout::CalcLeftMargin()
     SwMarginPortion *pLeft = (GetPortion() && GetPortion()->IsMarginPortion()) ?
         static_cast<SwMarginPortion *>(GetPortion()) : 0;
     if( !GetPortion() )
-         SetPortion(new SwTxtPortion(*static_cast<SwLinePortion*>(this)));
+         SetPortion(SwTxtPortion::CopyLinePortion(*this));
     if( !pLeft )
     {
         pLeft = new SwMarginPortion( 0 );
diff --git a/sw/source/core/text/pormulti.cxx b/sw/source/core/text/pormulti.cxx
index 6b24834..755869f 100644
--- a/sw/source/core/text/pormulti.cxx
+++ b/sw/source/core/text/pormulti.cxx
@@ -678,7 +678,7 @@ void SwRubyPortion::_Adjust( SwTxtFormatInfo &rInf )
     if( nLeft || nRight )
     {
         if( !pCurr->GetPortion() )
-            pCurr->SetPortion(new SwTxtPortion(*static_cast<SwLinePortion*>(pCurr)));
+            pCurr->SetPortion(SwTxtPortion::CopyLinePortion(*pCurr));
         if( nLeft )
         {
             SwMarginPortion *pMarg = new SwMarginPortion( 0 );
diff --git a/sw/source/core/text/portxt.cxx b/sw/source/core/text/portxt.cxx
index 691a716..4b78981 100644
--- a/sw/source/core/text/portxt.cxx
+++ b/sw/source/core/text/portxt.cxx
@@ -208,10 +208,12 @@ static sal_Int32 lcl_AddSpace( const SwTxtSizeInfo &rInf, const OUString* pStr,
     return nCnt;
 }
 
-SwTxtPortion::SwTxtPortion( const SwLinePortion &rPortion )
-  : SwLinePortion( rPortion )
+SwTxtPortion * SwTxtPortion::CopyLinePortion(const SwLinePortion &rPortion)
 {
-    SetWhichPor( POR_TXT );
+    SwTxtPortion *const pNew(new SwTxtPortion);
+    static_cast<SwLinePortion&>(*pNew) = rPortion;
+    pNew->SetWhichPor( POR_TXT ); // overwrite that!
+    return pNew;
 }
 
 void SwTxtPortion::BreakCut( SwTxtFormatInfo &rInf, const SwTxtGuess &rGuess )
diff --git a/sw/source/core/text/portxt.hxx b/sw/source/core/text/portxt.hxx
index 51ed3f1..3f30ba7 100644
--- a/sw/source/core/text/portxt.hxx
+++ b/sw/source/core/text/portxt.hxx
@@ -34,7 +34,7 @@ class SwTxtPortion : public SwLinePortion
 
 public:
     inline SwTxtPortion(){ SetWhichPor( POR_TXT ); }
-    SwTxtPortion( const SwLinePortion &rPortion );
+    static SwTxtPortion * CopyLinePortion(const SwLinePortion &rPortion);
     virtual void Paint( const SwTxtPaintInfo &rInf ) const SAL_OVERRIDE;
     virtual bool Format( SwTxtFormatInfo &rInf ) SAL_OVERRIDE;
     virtual void FormatEOL( SwTxtFormatInfo &rInf ) SAL_OVERRIDE;
commit ba587924b14d3e03f5c2bddf66d1da18089fc580
Author: Michael Stahl <mstahl at redhat.com>
Date:   Tue May 12 18:44:08 2015 +0200

    sw: let's try without a SwHyphPortion copy ctor
    
    It looks like it can be easily avoided.
    
    Change-Id: Ied8a047871c431b809569e1bbf232ce769d498ec

diff --git a/sw/source/core/text/txthyph.cxx b/sw/source/core/text/txthyph.cxx
index 9d73441..54316b9 100644
--- a/sw/source/core/text/txthyph.cxx
+++ b/sw/source/core/text/txthyph.cxx
@@ -296,8 +296,8 @@ bool SwTxtPortion::CreateHyphen( SwTxtFormatInfo &rInf, SwTxtGuess &rGuess )
     else
     {
         // second case: no alternative spelling
-        SwHyphPortion aHyphPor;
-        aHyphPor.SetLen( 1 );
+        pHyphPor = new SwHyphPortion;
+        pHyphPor->SetLen( 1 );
 
         static const void* pLastMagicNo = 0;
         static sal_uInt16 aMiniCacheH = 0, aMiniCacheW = 0;
@@ -306,15 +306,14 @@ bool SwTxtPortion::CreateHyphen( SwTxtFormatInfo &rInf, SwTxtGuess &rGuess )
         rInf.GetFont()->GetMagic( pTmpMagic, nFntIdx, rInf.GetFont()->GetActual() );
         if( !pLastMagicNo || pLastMagicNo != pTmpMagic ) {
             pLastMagicNo = pTmpMagic;
-            (SwPosSize&)aHyphPor = aHyphPor.GetTxtSize( rInf );
-            aMiniCacheH = aHyphPor.Height(), aMiniCacheW = aHyphPor.Width();
+            (SwPosSize&)(*pHyphPor) = pHyphPor->GetTxtSize( rInf );
+            aMiniCacheH = pHyphPor->Height();
+            aMiniCacheW = pHyphPor->Width();
         } else {
-            aHyphPor.Height( aMiniCacheH ), aHyphPor.Width( aMiniCacheW );
+            pHyphPor->Height( aMiniCacheH );
+            pHyphPor->Width( aMiniCacheW );
         }
-        aHyphPor.SetLen( 0 );
-        pHyphPor = new SwHyphPortion( aHyphPor );
-
-        pHyphPor->SetWhichPor( POR_HYPH );
+        pHyphPor->SetLen( 0 );
 
         // values required for this
         nPorEnd = xHyphWord->getHyphenPos() + 1 + rGuess.BreakStart()
commit 92a2445fcbdca5e1792b3579525ff40426700154
Author: Michael Stahl <mstahl at redhat.com>
Date:   Tue May 12 18:28:51 2015 +0200

    sw: fix another wrong call of SwTxtPortion copy-ctor
    
    Not sure what it should do, but given the parameter is SwLineLayout
    it will set POR_LAY on a SwTxtPortion which is wrong.
    
    Change-Id: I4296bcdf9e788338eb007ad09eae675a9fdc6a75

diff --git a/sw/source/core/text/pormulti.cxx b/sw/source/core/text/pormulti.cxx
index 2bb8217..6b24834 100644
--- a/sw/source/core/text/pormulti.cxx
+++ b/sw/source/core/text/pormulti.cxx
@@ -678,7 +678,7 @@ void SwRubyPortion::_Adjust( SwTxtFormatInfo &rInf )
     if( nLeft || nRight )
     {
         if( !pCurr->GetPortion() )
-            pCurr->SetPortion( new SwTxtPortion( *pCurr ) );
+            pCurr->SetPortion(new SwTxtPortion(*static_cast<SwLinePortion*>(pCurr)));
         if( nLeft )
         {
             SwMarginPortion *pMarg = new SwMarginPortion( 0 );
commit 8875c2e06ffd055f5e4637a71761457b1131a1c3
Author: Michael Stahl <mstahl at redhat.com>
Date:   Tue May 12 17:58:17 2015 +0200

    sw: fix crash in sw_unoapi due to calling wrong SwTxtPortion ctor
    
    Crash in sw.SwXTextRange because the SwTxtPortion copy ctor is
    invoked, which copies the portion type POR_LAY, but SwTxtPortion
    must have POR_TXT.
    
    (hilarious regression from 2db379e22a7854dc16cc0066af70f16d5662d7e8)
    
    Change-Id: I781191a60dafeba2257edf01699fafae78b45783

diff --git a/sw/source/core/text/porlay.cxx b/sw/source/core/text/porlay.cxx
index a450b2a..78572be 100644
--- a/sw/source/core/text/porlay.cxx
+++ b/sw/source/core/text/porlay.cxx
@@ -139,7 +139,7 @@ SwLinePortion *SwLineLayout::Insert( SwLinePortion *pIns )
     {
         if( GetLen() )
         {
-            pPortion = new SwTxtPortion(*this);
+            pPortion = new SwTxtPortion(*static_cast<SwLinePortion*>(this));
             if( IsBlinking() && pBlink )
             {
                 SetBlinking( false );
@@ -161,7 +161,7 @@ SwLinePortion *SwLineLayout::Append( SwLinePortion *pIns )
     // First attribute change: copy mass and length from *pIns into the first
     // text portion
     if( !pPortion )
-        pPortion = new SwTxtPortion(*this);
+        pPortion = new SwTxtPortion(*static_cast<SwLinePortion*>(this));
     // Call with scope or we'll end up with recursion!
     return pPortion->SwLinePortion::Append( pIns );
 }
@@ -184,7 +184,7 @@ SwMarginPortion *SwLineLayout::CalcLeftMargin()
     SwMarginPortion *pLeft = (GetPortion() && GetPortion()->IsMarginPortion()) ?
         static_cast<SwMarginPortion *>(GetPortion()) : 0;
     if( !GetPortion() )
-         SetPortion(new SwTxtPortion(*this));
+         SetPortion(new SwTxtPortion(*static_cast<SwLinePortion*>(this)));
     if( !pLeft )
     {
         pLeft = new SwMarginPortion( 0 );


More information about the Libreoffice-commits mailing list