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

Michael Stahl mstahl at redhat.com
Fri Mar 7 08:07:54 PST 2014


 sw/inc/tgrditem.hxx                 |   77 ++++++++++---------
 sw/source/core/inc/pagefrm.hxx      |   11 +-
 sw/source/core/layout/atrfrm.cxx    |  141 +++++++++++++++++++-----------------
 sw/source/core/layout/flowfrm.cxx   |    2 
 sw/source/core/layout/pagechg.cxx   |   28 ++++++-
 sw/source/core/layout/paintfrm.cxx  |    4 -
 sw/source/core/text/frmpaint.cxx    |    2 
 sw/source/core/text/guess.cxx       |    3 
 sw/source/core/text/itrcrsr.cxx     |    3 
 sw/source/core/text/itrform2.cxx    |   20 ++---
 sw/source/core/text/itrpaint.cxx    |    2 
 sw/source/core/text/itrtxt.cxx      |    2 
 sw/source/core/text/pormulti.cxx    |    7 +
 sw/source/core/text/porrst.cxx      |    2 
 sw/source/core/text/txtfrm.cxx      |    4 -
 sw/source/core/txtnode/fntcache.cxx |   32 ++++----
 16 files changed, 190 insertions(+), 150 deletions(-)

New commits:
commit 955fd65a75c971b23ff552bbe627d3fd30aac907
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri Mar 7 16:49:52 2014 +0100

    sw: remove that GETGRID abomination
    
    Change-Id: Ib2299dae7c1aab2d9af992930c29381a1027141b

diff --git a/sw/source/core/inc/pagefrm.hxx b/sw/source/core/inc/pagefrm.hxx
index 67e3e50..1b6c1bf 100644
--- a/sw/source/core/inc/pagefrm.hxx
+++ b/sw/source/core/inc/pagefrm.hxx
@@ -430,13 +430,12 @@ inline sal_Bool SwPageFrm::IsInvalidFly() const
     return bInvalidFlyLayout || bInvalidFlyCntnt;
 }
 
-#define GETGRID( pPage ) const SwTextGridItem *pGrid = NULL; \
- {if( pPage && pPage->HasGrid() && GRID_NONE==(pGrid=(SwTextGridItem*)&pPage->\
-     GetPageDesc()->GetMaster().GetFmtAttr(RES_TEXTGRID))->GetGridType() ) \
-    pGrid = NULL;}
 
-#define GETGRIDWIDTH( pGrid , pDoc )  pDoc->IsSquaredPageMode() ? \
-    pGrid->GetBaseHeight(): pGrid->GetBaseWidth()
+class SwTextGridItem;
+
+SwTextGridItem const* GetGridItem(SwPageFrm const*const);
+
+sal_uInt16 GetGridWidth(SwTextGridItem const&, SwDoc const&);
 
 #endif // INCLUDED_SW_SOURCE_CORE_INC_PAGEFRM_HXX
 
diff --git a/sw/source/core/layout/flowfrm.cxx b/sw/source/core/layout/flowfrm.cxx
index cdb913d..bbab257 100644
--- a/sw/source/core/layout/flowfrm.cxx
+++ b/sw/source/core/layout/flowfrm.cxx
@@ -1506,7 +1506,7 @@ SwTwips SwFlowFrm::_GetUpperSpaceAmountConsideredForPageGrid(
     if ( m_rThis.IsInDocBody() && m_rThis.GetAttrSet()->GetParaGrid().GetValue() )
     {
         const SwPageFrm* pPageFrm = m_rThis.FindPageFrm();
-        GETGRID( pPageFrm )
+        SwTextGridItem const*const pGrid(GetGridItem(pPageFrm));
         if( pGrid )
         {
             const SwFrm* pBodyFrm = pPageFrm->FindBodyCont();
diff --git a/sw/source/core/layout/pagechg.cxx b/sw/source/core/layout/pagechg.cxx
index 8e99d9e..b809700 100644
--- a/sw/source/core/layout/pagechg.cxx
+++ b/sw/source/core/layout/pagechg.cxx
@@ -113,7 +113,8 @@ void SwBodyFrm::Format( const SwBorderAttrs * )
     bool bNoGrid = true;
     if( GetUpper()->IsPageFrm() && ((SwPageFrm*)GetUpper())->HasGrid() )
     {
-        GETGRID( ((SwPageFrm*)GetUpper()) )
+        SwTextGridItem const*const pGrid(
+                GetGridItem(static_cast<SwPageFrm*>(GetUpper())));
         if( pGrid )
         {
             bNoGrid = false;
@@ -125,7 +126,7 @@ void SwBodyFrm::Format( const SwBorderAttrs * )
             {
                 //for textgrid refactor
                 SwDoc *pDoc = GetFmt()->GetDoc();
-                nBorder = nSize % (GETGRIDWIDTH(pGrid, pDoc));
+                nBorder = nSize % (GetGridWidth(*pGrid, *pDoc));
                 nSize -= nBorder;
                 nBorder /= 2;
             }
@@ -174,7 +175,7 @@ SwPageFrm::SwPageFrm( SwFrmFmt *pFmt, SwFrm* pSib, SwPageDesc *pPgDsc ) :
     if( pDesc )
     {
         bHasGrid = sal_True;
-        GETGRID( this )
+        SwTextGridItem const*const pGrid(GetGridItem(this));
         if( !pGrid )
             bHasGrid = sal_False;
     }
@@ -281,7 +282,7 @@ void SwPageFrm::CheckGrid( sal_Bool bInvalidate )
 {
     sal_Bool bOld = bHasGrid;
     bHasGrid = sal_True;
-    GETGRID( this )
+    SwTextGridItem const*const pGrid(GetGridItem(this));
     bHasGrid = 0 != pGrid;
     if( bInvalidate || bOld != bHasGrid )
     {
@@ -2279,4 +2280,23 @@ bool SwPageFrm::IsOverHeaderFooterArea( const Point& rPt, FrameControlType &rCon
     return false;
 }
 
+SwTextGridItem const* GetGridItem(SwPageFrm const*const pPage)
+{
+    if (pPage && pPage->HasGrid())
+    {
+        SwTextGridItem const& rGridItem(
+                pPage->GetPageDesc()->GetMaster().GetTextGrid());
+        if (GRID_NONE != rGridItem.GetGridType())
+        {
+            return &rGridItem;
+        }
+    }
+    return 0;
+}
+
+sal_uInt16 GetGridWidth(SwTextGridItem const& rG, SwDoc const& rDoc)
+{
+    return (rDoc.IsSquaredPageMode()) ? rG.GetBaseHeight() : rG.GetBaseWidth();
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/layout/paintfrm.cxx b/sw/source/core/layout/paintfrm.cxx
index b090ae1..097a025 100644
--- a/sw/source/core/layout/paintfrm.cxx
+++ b/sw/source/core/layout/paintfrm.cxx
@@ -5504,7 +5504,7 @@ void SwPageFrm::PaintGrid( OutputDevice* pOut, SwRect &rRect ) const
 {
     if( !bHasGrid || pRetoucheFly || pRetoucheFly2 )
         return;
-    GETGRID( this )
+    SwTextGridItem const*const pGrid(GetGridItem(this));
     if( pGrid && ( OUTDEV_PRINTER != pOut->GetOutDevType() ?
         pGrid->GetDisplayGrid() : pGrid->GetPrintGrid() ) )
     {
@@ -5522,7 +5522,7 @@ void SwPageFrm::PaintGrid( OutputDevice* pOut, SwRect &rRect ) const
                 bool bCell = GRID_LINES_CHARS == pGrid->GetGridType();
                 long nGrid = pGrid->GetBaseHeight();
                 const SwDoc* pDoc = GetFmt()->GetDoc();
-                long nGridWidth = GETGRIDWIDTH(pGrid,pDoc); //for textgrid refactor
+                long nGridWidth = GetGridWidth(*pGrid, *pDoc);
                 long nRuby = pGrid->GetRubyHeight();
                 long nSum = nGrid + nRuby;
                 const Color *pCol = &pGrid->GetColor();
diff --git a/sw/source/core/text/frmpaint.cxx b/sw/source/core/text/frmpaint.cxx
index 04d52b5..93a4170 100644
--- a/sw/source/core/text/frmpaint.cxx
+++ b/sw/source/core/text/frmpaint.cxx
@@ -527,7 +527,7 @@ bool SwTxtFrm::PaintEmpty( const SwRect &rRect, bool bCheck ) const
                 if ( GetTxtNode()->GetSwAttrSet().GetParaGrid().GetValue() &&
                      IsInDocBody() )
                 {
-                    GETGRID( FindPageFrm() )
+                    SwTextGridItem const*const pGrid(GetGridItem(FindPageFrm()));
                     if ( pGrid )
                     {
                         // center character in grid line
diff --git a/sw/source/core/text/guess.cxx b/sw/source/core/text/guess.cxx
index f911e6a..21b7121 100644
--- a/sw/source/core/text/guess.cxx
+++ b/sw/source/core/text/guess.cxx
@@ -94,7 +94,8 @@ bool SwTxtGuess::Guess( const SwTxtPortion& rPor, SwTxtFormatInfo &rInf,
         // do not add extra italic value if we have an active character grid
         if ( rInf.SnapToGrid() )
         {
-            GETGRID( rInf.GetTxtFrm()->FindPageFrm() )
+            SwTextGridItem const*const pGrid(
+                    GetGridItem(rInf.GetTxtFrm()->FindPageFrm()));
             bAddItalic = !pGrid || GRID_LINES_CHARS != pGrid->GetGridType();
         }
 
diff --git a/sw/source/core/text/itrcrsr.cxx b/sw/source/core/text/itrcrsr.cxx
index 033eb0b..df80a34 100644
--- a/sw/source/core/text/itrcrsr.cxx
+++ b/sw/source/core/text/itrcrsr.cxx
@@ -741,7 +741,8 @@ void SwTxtCursor::_GetCharRect( SwRect* pOrig, const sal_Int32 nOfst,
                         if( ((SwMultiPortion*)pPor)->IsDouble() )
                             SetPropFont( 50 );
 
-                        GETGRID( GetTxtFrm()->FindPageFrm() )
+                        SwTextGridItem const*const pGrid(
+                                GetGridItem(GetTxtFrm()->FindPageFrm()));
                         const bool bHasGrid = pGrid && GetInfo().SnapToGrid();
                         const sal_uInt16 nRubyHeight = bHasGrid ?
                                                    pGrid->GetRubyHeight() : 0;
diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx
index 08eca5e..602e645 100644
--- a/sw/source/core/text/itrform2.cxx
+++ b/sw/source/core/text/itrform2.cxx
@@ -409,13 +409,12 @@ void SwTxtFormatter::BuildPortions( SwTxtFormatInfo &rInf )
     SwLinePortion *pPor = NewPortion( rInf );
 
     // Asian grid stuff
-    GETGRID( pFrm->FindPageFrm() )
+    SwTextGridItem const*const pGrid(GetGridItem(pFrm->FindPageFrm()));
     const bool bHasGrid = pGrid && rInf.SnapToGrid() &&
                               GRID_LINES_CHARS == pGrid->GetGridType();
 
     const SwDoc *pDoc = rInf.GetTxtFrm()->GetNode()->GetDoc();
-    const sal_uInt16 nGridWidth = bHasGrid ?
-                                GETGRIDWIDTH(pGrid,pDoc) : 0;   //for textgrid refactor
+    const sal_uInt16 nGridWidth = (bHasGrid) ? GetGridWidth(*pGrid, *pDoc) : 0;
 
     // used for grid mode only:
     // the pointer is stored, because after formatting of non-asian text,
@@ -1057,7 +1056,8 @@ SwLinePortion *SwTxtFormatter::WhichFirstPortion(SwTxtFormatInfo &rInf)
         // 3. Kerning portions at beginning of line in grid mode
         if ( ! pPor && ! pCurr->GetPortion() )
         {
-            GETGRID( GetTxtFrm()->FindPageFrm() )
+            SwTextGridItem const*const pGrid(
+                    GetGridItem(GetTxtFrm()->FindPageFrm()));
             if ( pGrid )
                 pPor = new SwKernPortion( *pCurr );
         }
@@ -1116,7 +1116,8 @@ SwLinePortion *SwTxtFormatter::WhichFirstPortion(SwTxtFormatInfo &rInf)
         // 9. Kerning portions at beginning of line in grid mode
         if ( !pPor && !pCurr->GetPortion() )
         {
-            GETGRID( GetTxtFrm()->FindPageFrm() )
+            SwTextGridItem const*const pGrid(
+                    GetGridItem(GetTxtFrm()->FindPageFrm()));
             if ( pGrid )
                 pPor = new SwKernPortion( *pCurr );
         }
@@ -1268,7 +1269,8 @@ SwLinePortion *SwTxtFormatter::NewPortion( SwTxtFormatInfo &rInf )
 
                     if ( rInf.SnapToGrid() )
                     {
-                        GETGRID( GetTxtFrm()->FindPageFrm() )
+                        SwTextGridItem const*const pGrid(
+                                GetGridItem(GetTxtFrm()->FindPageFrm()));
                         if ( pGrid )
                         {
                             bRubyTop = ! pGrid->GetRubyTextBelow();
@@ -1716,7 +1718,7 @@ void SwTxtFormatter::CalcRealHeight( bool bNewLine )
     KSHORT nLineHeight = pCurr->Height();
     pCurr->SetClipping( false );
 
-    GETGRID( pFrm->FindPageFrm() )
+    SwTextGridItem const*const pGrid(GetGridItem(pFrm->FindPageFrm()));
     if ( pGrid && GetInfo().SnapToGrid() )
     {
         const sal_uInt16 nGridWidth = pGrid->GetBaseHeight();
@@ -2476,7 +2478,7 @@ void SwTxtFormatter::CalcFlyWidth( SwTxtFormatInfo &rInf )
         if( pFly->Fix() < rInf.Width() )
             rInf.Width( pFly->Fix() );
 
-        GETGRID( pFrm->FindPageFrm() )
+        SwTextGridItem const*const pGrid(GetGridItem(pFrm->FindPageFrm()));
         if ( pGrid )
         {
             const SwPageFrm* pPageFrm = pFrm->FindPageFrm();
@@ -2489,7 +2491,7 @@ void SwTxtFormatter::CalcFlyWidth( SwTxtFormatInfo &rInf )
                                     (pPageFrm->*fnRect->fnGetPrtLeft)();
 
             const SwDoc *pDoc = rInf.GetTxtFrm()->GetNode()->GetDoc();
-            const sal_uInt16 nGridWidth = GETGRIDWIDTH( pGrid, pDoc);   //For textgrid refactor
+            const sal_uInt16 nGridWidth = GetGridWidth(*pGrid, *pDoc);
 
             SwTwips nStartX = GetLeftMargin();
             if ( bVert )
diff --git a/sw/source/core/text/itrpaint.cxx b/sw/source/core/text/itrpaint.cxx
index 5ee8e9b..4bd2b0f 100644
--- a/sw/source/core/text/itrpaint.cxx
+++ b/sw/source/core/text/itrpaint.cxx
@@ -243,7 +243,7 @@ void SwTxtPainter::DrawTextLine( const SwRect &rPaint, SwSaveClip &rClip,
     // Baseline-Ausgabe auch bei nicht-TxtPortions (vgl. TabPor mit Fill)
     // if no special vertical alignment is used,
     // we calculate Y value for the whole line
-    GETGRID( GetTxtFrm()->FindPageFrm() )
+    SwTextGridItem const*const pGrid(GetGridItem(GetTxtFrm()->FindPageFrm()));
     const bool bAdjustBaseLine =
         GetLineInfo().HasSpecialAlign( GetTxtFrm()->IsVertical() ) ||
         ( 0 != pGrid );
diff --git a/sw/source/core/text/itrtxt.cxx b/sw/source/core/text/itrtxt.cxx
index de34d1f..aea80ef 100644
--- a/sw/source/core/text/itrtxt.cxx
+++ b/sw/source/core/text/itrtxt.cxx
@@ -284,7 +284,7 @@ sal_uInt16 SwTxtCursor::AdjustBaseLine( const SwLineLayout& rLine,
 
     sal_uInt16 nOfst = rLine.GetRealHeight() - rLine.Height();
 
-    GETGRID( pFrm->FindPageFrm() )
+    SwTextGridItem const*const pGrid(GetGridItem(pFrm->FindPageFrm()));
 
     if ( pGrid && GetInfo().SnapToGrid() )
     {
diff --git a/sw/source/core/text/pormulti.cxx b/sw/source/core/text/pormulti.cxx
index 5e03352..bd87c74 100644
--- a/sw/source/core/text/pormulti.cxx
+++ b/sw/source/core/text/pormulti.cxx
@@ -1341,7 +1341,7 @@ SwSpaceManipulator::~SwSpaceManipulator()
 void SwTxtPainter::PaintMultiPortion( const SwRect &rPaint,
     SwMultiPortion& rMulti, const SwMultiPortion* pEnvPor )
 {
-    GETGRID( pFrm->FindPageFrm() )
+    SwTextGridItem const*const pGrid(GetGridItem(pFrm->FindPageFrm()));
     const bool bHasGrid = pGrid && GetInfo().SnapToGrid();
     sal_uInt16 nRubyHeight = 0;
     bool bRubyTop = false;
@@ -1845,7 +1845,7 @@ bool SwTxtFormatter::BuildMultiPortion( SwTxtFormatInfo &rInf,
     SwLinePortion *pNextSecond = NULL;
     bool bRet = false;
 
-    GETGRID( pFrm->FindPageFrm() )
+    SwTextGridItem const*const pGrid(GetGridItem(pFrm->FindPageFrm()));
     const bool bHasGrid = pGrid && GRID_LINES_CHARS == pGrid->GetGridType();
 
     bool bRubyTop = false;
@@ -2293,7 +2293,8 @@ SwLinePortion* SwTxtFormatter::MakeRestPortion( const SwLineLayout* pLine,
 
             if ( GetInfo().SnapToGrid() )
             {
-                GETGRID( pFrm->FindPageFrm() )
+                SwTextGridItem const*const pGrid(
+                        GetGridItem(pFrm->FindPageFrm()));
                 if ( pGrid )
                 {
                     bRubyTop = ! pGrid->GetRubyTextBelow();
diff --git a/sw/source/core/text/porrst.cxx b/sw/source/core/text/porrst.cxx
index c39e0a7..a56dc41 100644
--- a/sw/source/core/text/porrst.cxx
+++ b/sw/source/core/text/porrst.cxx
@@ -325,7 +325,7 @@ bool SwTxtFrm::FormatEmpty()
     if ( GetTxtNode()->GetSwAttrSet().GetParaGrid().GetValue() &&
             IsInDocBody() )
     {
-        GETGRID( FindPageFrm() )
+        SwTextGridItem const*const pGrid(GetGridItem(FindPageFrm()));
         if ( pGrid )
             nHeight = pGrid->GetBaseHeight() + pGrid->GetRubyHeight();
     }
diff --git a/sw/source/core/text/txtfrm.cxx b/sw/source/core/text/txtfrm.cxx
index cef5612..d1fee29 100644
--- a/sw/source/core/text/txtfrm.cxx
+++ b/sw/source/core/text/txtfrm.cxx
@@ -1437,7 +1437,7 @@ void SwTxtFrm::Prepare( const PrepareHint ePrep, const void* pVoid,
                 if( GetTxtNode()->GetSwAttrSet().GetRegister().GetValue())
                     break;
 
-                GETGRID( FindPageFrm() )
+                SwTextGridItem const*const pGrid(GetGridItem(FindPageFrm()));
                 if ( pGrid && GetTxtNode()->GetSwAttrSet().GetParaGrid().GetValue() )
                     break;
 
@@ -1598,7 +1598,7 @@ void SwTxtFrm::Prepare( const PrepareHint ePrep, const void* pVoid,
         {
             if ( GetValidPrtAreaFlag() )
             {
-                GETGRID( FindPageFrm() )
+                SwTextGridItem const*const pGrid(GetGridItem(FindPageFrm()));
                 if ( pGrid && GetTxtNode()->GetSwAttrSet().GetParaGrid().GetValue() )
                     InvalidatePrt();
             }
diff --git a/sw/source/core/txtnode/fntcache.cxx b/sw/source/core/txtnode/fntcache.cxx
index 66efedb..c4af0ba 100644
--- a/sw/source/core/txtnode/fntcache.cxx
+++ b/sw/source/core/txtnode/fntcache.cxx
@@ -950,13 +950,13 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf )
     if ( rInf.GetFrm() && rInf.SnapToGrid() && rInf.GetFont() &&
          SW_CJK == rInf.GetFont()->GetActual() )
     {
-        GETGRID( rInf.GetFrm()->FindPageFrm() )
+        SwTextGridItem const*const pGrid(GetGridItem(rInf.GetFrm()->FindPageFrm()));
         if ( pGrid && GRID_LINES_CHARS == pGrid->GetGridType() && pGrid->IsSnapToChars())
         {
             //for textgrid refactor
             //const sal_uInt16 nGridWidth = pGrid->GetBaseHeight();
             const SwDoc* pDoc = rInf.GetShell()->GetDoc();
-            const sal_uInt16 nGridWidth = GETGRIDWIDTH(pGrid, pDoc);
+            const sal_uInt16 nGridWidth = GetGridWidth(*pGrid, *pDoc);
             sal_Int32* pKernArray = new sal_Int32[rInf.GetLen()];
 
             if ( pPrinter )
@@ -1040,14 +1040,14 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf )
     if ( rInf.GetFrm() && rInf.SnapToGrid() && rInf.GetFont() &&
          SW_CJK == rInf.GetFont()->GetActual() )
     {
-        GETGRID( rInf.GetFrm()->FindPageFrm() )
+        SwTextGridItem const*const pGrid(GetGridItem(rInf.GetFrm()->FindPageFrm()));
 
         if ( pGrid && GRID_LINES_CHARS == pGrid->GetGridType() && !pGrid->IsSnapToChars() )
         {
             const sal_uInt16  nDefaultFontHeight = GetDefaultFontHeight( rInf );
 
             const SwDoc* pDoc = rInf.GetShell()->GetDoc();
-            long nGridWidthAdd = GETGRIDWIDTH(pGrid, pDoc);
+            long nGridWidthAdd = GetGridWidth(*pGrid, *pDoc);
             if( SW_LATIN == rInf.GetFont()->GetActual() )
                 nGridWidthAdd = ( nGridWidthAdd - nDefaultFontHeight ) / 2;
             else
@@ -1822,11 +1822,11 @@ Size SwFntObj::GetTextSize( SwDrawTextInfo& rInf )
     if ( rInf.GetFrm() && nLn && rInf.SnapToGrid() && rInf.GetFont() &&
          SW_CJK == rInf.GetFont()->GetActual() )
     {
-        GETGRID( rInf.GetFrm()->FindPageFrm() )
+        SwTextGridItem const*const pGrid(GetGridItem(rInf.GetFrm()->FindPageFrm()));
         if ( pGrid && GRID_LINES_CHARS == pGrid->GetGridType() && pGrid->IsSnapToChars() )
         {
             const SwDoc* pDoc = rInf.GetShell()->GetDoc();
-            const sal_uInt16 nGridWidth = GETGRIDWIDTH(pGrid, pDoc);
+            const sal_uInt16 nGridWidth = GetGridWidth(*pGrid, *pDoc);
 
             OutputDevice* pOutDev;
 
@@ -1864,13 +1864,13 @@ Size SwFntObj::GetTextSize( SwDrawTextInfo& rInf )
     if ( rInf.GetFrm() && nLn && rInf.SnapToGrid() && rInf.GetFont() &&
          SW_CJK == rInf.GetFont()->GetActual() )
     {
-        GETGRID( rInf.GetFrm()->FindPageFrm() )
+        SwTextGridItem const*const pGrid(GetGridItem(rInf.GetFrm()->FindPageFrm()));
         if ( pGrid && GRID_LINES_CHARS == pGrid->GetGridType() && !pGrid->IsSnapToChars() )
         {
             const sal_uInt16 nDefaultFontHeight = GetDefaultFontHeight( rInf );
 
             const SwDoc* pDoc = rInf.GetShell()->GetDoc();
-            long nGridWidthAdd = GETGRIDWIDTH(pGrid, pDoc);
+            long nGridWidthAdd = GetGridWidth(*pGrid, *pDoc);
             if( SW_LATIN == rInf.GetFont()->GetActual() )
                 nGridWidthAdd = ( nGridWidthAdd - nDefaultFontHeight ) / 2;
             else
@@ -2110,11 +2110,11 @@ sal_Int32 SwFntObj::GetCrsrOfst( SwDrawTextInfo &rInf )
     if ( rInf.GetFrm() && rInf.GetLen() && rInf.SnapToGrid() &&
          rInf.GetFont() && SW_CJK == rInf.GetFont()->GetActual() )
     {
-        GETGRID( rInf.GetFrm()->FindPageFrm() )
+        SwTextGridItem const*const pGrid(GetGridItem(rInf.GetFrm()->FindPageFrm()));
         if ( pGrid && GRID_LINES_CHARS == pGrid->GetGridType() && pGrid->IsSnapToChars() )
         {
             const SwDoc* pDoc = rInf.GetShell()->GetDoc();
-            const sal_uInt16 nGridWidth = GETGRIDWIDTH(pGrid, pDoc);
+            const sal_uInt16 nGridWidth = GetGridWidth(*pGrid, *pDoc);
 
             long nWidthPerChar = pKernArray[ rInf.GetLen() - 1 ] / rInf.GetLen();
 
@@ -2137,14 +2137,14 @@ sal_Int32 SwFntObj::GetCrsrOfst( SwDrawTextInfo &rInf )
     if ( rInf.GetFrm() && rInf.GetLen() && rInf.SnapToGrid() &&
          rInf.GetFont() && SW_CJK == rInf.GetFont()->GetActual() )
     {
-        GETGRID( rInf.GetFrm()->FindPageFrm() )
+        SwTextGridItem const*const pGrid(GetGridItem(rInf.GetFrm()->FindPageFrm()));
         if ( pGrid && GRID_LINES_CHARS == pGrid->GetGridType() && !pGrid->IsSnapToChars() )
         {
 
             const sal_uInt16 nDefaultFontHeight = GetDefaultFontHeight( rInf );
 
             const SwDoc* pDoc = rInf.GetShell()->GetDoc();
-            long nGridWidthAdd = GETGRIDWIDTH(pGrid, pDoc);
+            long nGridWidthAdd = GetGridWidth(*pGrid, *pDoc);
             if( SW_LATIN == rInf.GetFont()->GetActual() )
                 nGridWidthAdd = ( nGridWidthAdd - nDefaultFontHeight ) / 2;
             else
@@ -2365,11 +2365,11 @@ sal_Int32 SwFont::GetTxtBreak( SwDrawTextInfo& rInf, long nTextWidth )
     if ( rInf.GetFrm() && nLn && rInf.SnapToGrid() &&
          rInf.GetFont() && SW_CJK == rInf.GetFont()->GetActual() )
     {
-        GETGRID( rInf.GetFrm()->FindPageFrm() )
+        SwTextGridItem const*const pGrid(GetGridItem(rInf.GetFrm()->FindPageFrm()));
         if ( pGrid && GRID_LINES_CHARS == pGrid->GetGridType() && pGrid->IsSnapToChars() )
         {
             const SwDoc* pDoc = rInf.GetShell()->GetDoc();
-            const sal_uInt16 nGridWidth = GETGRIDWIDTH(pGrid, pDoc);
+            const sal_uInt16 nGridWidth = GetGridWidth(*pGrid, *pDoc);
 
             sal_Int32* pKernArray = new sal_Int32[rInf.GetLen()];
             rInf.GetOut().GetTextArray( rInf.GetText(), pKernArray,
@@ -2399,13 +2399,13 @@ sal_Int32 SwFont::GetTxtBreak( SwDrawTextInfo& rInf, long nTextWidth )
     if ( rInf.GetFrm() && nLn && rInf.SnapToGrid() && rInf.GetFont() &&
          SW_CJK == rInf.GetFont()->GetActual() )
     {
-        GETGRID( rInf.GetFrm()->FindPageFrm() )
+        SwTextGridItem const*const pGrid(GetGridItem(rInf.GetFrm()->FindPageFrm()));
         if ( pGrid && GRID_LINES_CHARS == pGrid->GetGridType() && !pGrid->IsSnapToChars() )
         {
             const sal_uInt16 nDefaultFontHeight = GetDefaultFontHeight( rInf );
 
             const SwDoc* pDoc = rInf.GetShell()->GetDoc();
-            long nGridWidthAdd = GETGRIDWIDTH(pGrid, pDoc);
+            long nGridWidthAdd = GetGridWidth(*pGrid, *pDoc);
             if( SW_LATIN == rInf.GetFont()->GetActual() )
                 nGridWidthAdd = ( nGridWidthAdd - nDefaultFontHeight ) / 2 ;
             else
commit 2f91d6c40356038145861bb0459cf0d32c0e7ffe
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri Mar 7 16:14:16 2014 +0100

    sw: add prefix to SwTextGridItem members
    
    Change-Id: Ie086d56f01bc06de14c6fb1713a43aec8e6335f9

diff --git a/sw/inc/tgrditem.hxx b/sw/inc/tgrditem.hxx
index c137fcd..dd25833 100644
--- a/sw/inc/tgrditem.hxx
+++ b/sw/inc/tgrditem.hxx
@@ -31,18 +31,21 @@ enum SwTextGrid { GRID_NONE, GRID_LINES_ONLY, GRID_LINES_CHARS };
 
 class SW_DLLPUBLIC SwTextGridItem : public SfxPoolItem
 {
-    Color aColor;
-    sal_uInt16 nLines;
-    sal_uInt16 nBaseHeight, nRubyHeight;
-    SwTextGrid eGridType;
-    sal_Bool bRubyTextBelow;
-    sal_Bool bPrintGrid;
-    sal_Bool bDisplayGrid;
+private:
+    Color m_aColor;
+    sal_uInt16 m_nLines;
+    sal_uInt16 m_nBaseHeight;
+    sal_uInt16 m_nRubyHeight;
+    SwTextGrid m_eGridType;
+    sal_Bool m_bRubyTextBelow;
+    sal_Bool m_bPrintGrid;
+    sal_Bool m_bDisplayGrid;
 
     //for textgrid enhancement
-    sal_uInt16 nBaseWidth;
-    sal_Bool bSnapToChars;
-    sal_Bool bSquaredMode;
+    sal_uInt16 m_nBaseWidth;
+    sal_Bool m_bSnapToChars;
+    sal_Bool m_bSquaredMode;
+
 public:
     SwTextGridItem();
     virtual ~SwTextGridItem();
@@ -60,44 +63,44 @@ public:
 
     SwTextGridItem&  operator=( const SwTextGridItem& );
 
-    const Color& GetColor() const { return aColor; }
-    void SetColor( const Color& rCol )  { aColor = rCol; }
+    const Color& GetColor() const { return m_aColor; }
+    void SetColor( const Color& rCol )  { m_aColor = rCol; }
 
-    sal_uInt16 GetLines() const { return nLines; }
-    void SetLines( sal_uInt16 nNew ) { nLines = nNew; }
+    sal_uInt16 GetLines() const { return m_nLines; }
+    void SetLines( sal_uInt16 nNew ) { m_nLines = nNew; }
 
-    sal_uInt16 GetBaseHeight() const { return nBaseHeight; }
-    void SetBaseHeight( sal_uInt16 nNew ) { nBaseHeight = nNew; }
+    sal_uInt16 GetBaseHeight() const { return m_nBaseHeight; }
+    void SetBaseHeight( sal_uInt16 nNew ) { m_nBaseHeight = nNew; }
 
-    sal_uInt16 GetRubyHeight() const { return nRubyHeight; }
-    void SetRubyHeight( sal_uInt16 nNew ) { nRubyHeight = nNew; }
+    sal_uInt16 GetRubyHeight() const { return m_nRubyHeight; }
+    void SetRubyHeight( sal_uInt16 nNew ) { m_nRubyHeight = nNew; }
 
-    SwTextGrid GetGridType() const { return eGridType; }
-    void SetGridType( SwTextGrid eNew ) { eGridType = eNew; }
+    SwTextGrid GetGridType() const { return m_eGridType; }
+    void SetGridType( SwTextGrid eNew ) { m_eGridType = eNew; }
 
-    sal_Bool IsRubyTextBelow() const { return bRubyTextBelow; }
-    sal_Bool GetRubyTextBelow() const { return bRubyTextBelow; }
-    void SetRubyTextBelow( sal_Bool bNew ) { bRubyTextBelow = bNew; }
+    sal_Bool IsRubyTextBelow() const { return m_bRubyTextBelow; }
+    sal_Bool GetRubyTextBelow() const { return m_bRubyTextBelow; }
+    void SetRubyTextBelow( sal_Bool bNew ) { m_bRubyTextBelow = bNew; }
 
-    sal_Bool IsPrintGrid() const { return bPrintGrid; }
-    sal_Bool GetPrintGrid() const { return bPrintGrid; }
-    void SetPrintGrid( sal_Bool bNew ) { bPrintGrid = bNew; }
+    sal_Bool IsPrintGrid() const { return m_bPrintGrid; }
+    sal_Bool GetPrintGrid() const { return m_bPrintGrid; }
+    void SetPrintGrid( sal_Bool bNew ) { m_bPrintGrid = bNew; }
 
-    sal_Bool IsDisplayGrid() const { return bDisplayGrid; }
-    sal_Bool GetDisplayGrid() const { return bDisplayGrid; }
-    void SetDisplayGrid( sal_Bool bNew ) { bDisplayGrid = bNew; }
+    sal_Bool IsDisplayGrid() const { return m_bDisplayGrid; }
+    sal_Bool GetDisplayGrid() const { return m_bDisplayGrid; }
+    void SetDisplayGrid( sal_Bool bNew ) { m_bDisplayGrid = bNew; }
 
     //for textgrid enhancement
-    sal_uInt16 GetBaseWidth() const { return nBaseWidth;}
-    void SetBaseWidth( sal_uInt16 nNew ) { nBaseWidth = nNew; }
+    sal_uInt16 GetBaseWidth() const { return m_nBaseWidth;}
+    void SetBaseWidth( sal_uInt16 nNew ) { m_nBaseWidth = nNew; }
 
-    sal_Bool IsSnapToChars() const { return bSnapToChars; }
-    sal_Bool GetSnapToChars() const { return bSnapToChars; }
-    void SetSnapToChars( sal_Bool bNew ) { bSnapToChars = bNew; }
+    sal_Bool IsSnapToChars() const { return m_bSnapToChars; }
+    sal_Bool GetSnapToChars() const { return m_bSnapToChars; }
+    void SetSnapToChars( sal_Bool bNew ) { m_bSnapToChars = bNew; }
 
-    sal_Bool IsSquaredMode() const { return bSquaredMode; }
-    sal_Bool GetSquaredMode() const { return bSquaredMode; }
-    void SetSquaredMode( sal_Bool bNew ) { bSquaredMode = bNew; }
+    sal_Bool IsSquaredMode() const { return m_bSquaredMode; }
+    sal_Bool GetSquaredMode() const { return m_bSquaredMode; }
+    void SetSquaredMode( sal_Bool bNew ) { m_bSquaredMode = bNew; }
     void SwitchPaperMode(sal_Bool bNew );
 
     void Init();
diff --git a/sw/source/core/layout/atrfrm.cxx b/sw/source/core/layout/atrfrm.cxx
index f80cf38..f251813 100644
--- a/sw/source/core/layout/atrfrm.cxx
+++ b/sw/source/core/layout/atrfrm.cxx
@@ -2105,10 +2105,10 @@ bool SwFmtLineNumber::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
 // class SwTextGridItem
 
 SwTextGridItem::SwTextGridItem()
-    : SfxPoolItem( RES_TEXTGRID ), aColor( COL_LIGHTGRAY ), nLines( 20 ),
-      nBaseHeight( 400 ), nRubyHeight( 200 ), eGridType( GRID_NONE ),
-      bRubyTextBelow( 0 ), bPrintGrid( 1 ), bDisplayGrid( 1 ),
-      nBaseWidth(400), bSnapToChars( 1 ), bSquaredMode(1)
+    : SfxPoolItem( RES_TEXTGRID ), m_aColor( COL_LIGHTGRAY ), m_nLines( 20 )
+    , m_nBaseHeight( 400 ), m_nRubyHeight( 200 ), m_eGridType( GRID_NONE )
+    , m_bRubyTextBelow( 0 ), m_bPrintGrid( 1 ), m_bDisplayGrid( 1 )
+    , m_nBaseWidth(400), m_bSnapToChars( 1 ), m_bSquaredMode(1)
 {
 }
 
@@ -2119,17 +2119,18 @@ SwTextGridItem::~SwTextGridItem()
 bool SwTextGridItem::operator==( const SfxPoolItem& rAttr ) const
 {
     OSL_ENSURE( SfxPoolItem::operator==( rAttr ), "keine gleichen Attribute" );
-    return eGridType == ((SwTextGridItem&)rAttr).GetGridType() &&
-           nLines == ((SwTextGridItem&)rAttr).GetLines() &&
-           nBaseHeight == ((SwTextGridItem&)rAttr).GetBaseHeight() &&
-           nRubyHeight == ((SwTextGridItem&)rAttr).GetRubyHeight() &&
-           bRubyTextBelow == ((SwTextGridItem&)rAttr).GetRubyTextBelow() &&
-           bDisplayGrid == ((SwTextGridItem&)rAttr).GetDisplayGrid() &&
-           bPrintGrid == ((SwTextGridItem&)rAttr).GetPrintGrid() &&
-           aColor == ((SwTextGridItem&)rAttr).GetColor() &&
-           nBaseWidth == ((SwTextGridItem&)rAttr).GetBaseWidth() &&
-           bSnapToChars == ((SwTextGridItem&)rAttr).GetSnapToChars() &&
-           bSquaredMode == ((SwTextGridItem&)rAttr).GetSquaredMode();
+    SwTextGridItem const& rOther(static_cast<SwTextGridItem const&>(rAttr));
+    return m_eGridType == rOther.GetGridType()
+        && m_nLines == rOther.GetLines()
+        && m_nBaseHeight == rOther.GetBaseHeight()
+        && m_nRubyHeight == rOther.GetRubyHeight()
+        && m_bRubyTextBelow == rOther.GetRubyTextBelow()
+        && m_bDisplayGrid == rOther.GetDisplayGrid()
+        && m_bPrintGrid == rOther.GetPrintGrid()
+        && m_aColor == rOther.GetColor()
+        && m_nBaseWidth == rOther.GetBaseWidth()
+        && m_bSnapToChars == rOther.GetSnapToChars()
+        && m_bSquaredMode == rOther.GetSquaredMode();
 }
 
 SfxPoolItem* SwTextGridItem::Clone( SfxItemPool* ) const
@@ -2139,17 +2140,17 @@ SfxPoolItem* SwTextGridItem::Clone( SfxItemPool* ) const
 
 SwTextGridItem& SwTextGridItem::operator=( const SwTextGridItem& rCpy )
 {
-    aColor = rCpy.GetColor();
-    nLines = rCpy.GetLines();
-    nBaseHeight = rCpy.GetBaseHeight();
-    nRubyHeight = rCpy.GetRubyHeight();
-    eGridType = rCpy.GetGridType();
-    bRubyTextBelow = rCpy.GetRubyTextBelow();
-    bPrintGrid = rCpy.GetPrintGrid();
-    bDisplayGrid = rCpy.GetDisplayGrid();
-    nBaseWidth = rCpy.GetBaseWidth();
-    bSnapToChars = rCpy.GetSnapToChars();
-    bSquaredMode = rCpy.GetSquaredMode();
+    m_aColor = rCpy.GetColor();
+    m_nLines = rCpy.GetLines();
+    m_nBaseHeight = rCpy.GetBaseHeight();
+    m_nRubyHeight = rCpy.GetRubyHeight();
+    m_eGridType = rCpy.GetGridType();
+    m_bRubyTextBelow = rCpy.GetRubyTextBelow();
+    m_bPrintGrid = rCpy.GetPrintGrid();
+    m_bDisplayGrid = rCpy.GetDisplayGrid();
+    m_nBaseWidth = rCpy.GetBaseWidth();
+    m_bSnapToChars = rCpy.GetSnapToChars();
+    m_bSquaredMode = rCpy.GetSquaredMode();
 
     return *this;
 }
@@ -2167,28 +2168,28 @@ bool SwTextGridItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
             rVal <<= GetLines();
             break;
         case MID_GRID_RUBY_BELOW:
-            rVal.setValue( &bRubyTextBelow, ::getBooleanCppuType() );
+            rVal.setValue( &m_bRubyTextBelow, ::getBooleanCppuType() );
             break;
         case MID_GRID_PRINT:
-            rVal.setValue( &bPrintGrid, ::getBooleanCppuType() );
+            rVal.setValue( &m_bPrintGrid, ::getBooleanCppuType() );
             break;
         case MID_GRID_DISPLAY:
-            rVal.setValue( &bDisplayGrid, ::getBooleanCppuType() );
+            rVal.setValue( &m_bDisplayGrid, ::getBooleanCppuType() );
             break;
         case MID_GRID_BASEHEIGHT:
             OSL_ENSURE( (nMemberId & CONVERT_TWIPS) != 0,
                         "This value needs TWIPS-MM100 conversion" );
-            rVal <<= (sal_Int32) TWIP_TO_MM100_UNSIGNED(nBaseHeight);
+            rVal <<= (sal_Int32) TWIP_TO_MM100_UNSIGNED(m_nBaseHeight);
             break;
         case MID_GRID_BASEWIDTH:
             OSL_ENSURE( (nMemberId & CONVERT_TWIPS) != 0,
                         "This value needs TWIPS-MM100 conversion" );
-            rVal <<= (sal_Int32) TWIP_TO_MM100_UNSIGNED(nBaseWidth);
+            rVal <<= (sal_Int32) TWIP_TO_MM100_UNSIGNED(m_nBaseWidth);
             break;
         case MID_GRID_RUBYHEIGHT:
             OSL_ENSURE( (nMemberId & CONVERT_TWIPS) != 0,
                         "This value needs TWIPS-MM100 conversion" );
-            rVal <<= (sal_Int32)TWIP_TO_MM100_UNSIGNED(nRubyHeight);
+            rVal <<= (sal_Int32)TWIP_TO_MM100_UNSIGNED(m_nRubyHeight);
             break;
         case MID_GRID_TYPE:
             switch( GetGridType() )
@@ -2209,11 +2210,11 @@ bool SwTextGridItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
             }
             break;
         case MID_GRID_SNAPTOCHARS:
-            rVal.setValue( &bSnapToChars, ::getBooleanCppuType() );
+            rVal.setValue( &m_bSnapToChars, ::getBooleanCppuType() );
             break;
         case MID_GRID_STANDARD_MODE:
             {
-                sal_Bool bStandardMode = !bSquaredMode;
+                sal_Bool bStandardMode = !m_bSquaredMode;
                 rVal.setValue( &bStandardMode, ::getBooleanCppuType() );
             }
             break;
@@ -2333,62 +2334,62 @@ bool SwTextGridItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
 
 void SwTextGridItem::SwitchPaperMode(sal_Bool bNew)
 {
-    if( bNew == bSquaredMode )
+    if (bNew == m_bSquaredMode)
     {
         //same paper mode, not switch
         return;
     }
 
     // use default value when grid is disable
-    if( eGridType == GRID_NONE )
+    if (m_eGridType == GRID_NONE)
     {
-        bSquaredMode = bNew;
+        m_bSquaredMode = bNew;
         Init();
         return;
     }
 
-    if( bSquaredMode )
+    if (m_bSquaredMode)
     {
         //switch from "squared mode" to "standard mode"
-        nBaseWidth = nBaseHeight;
-        nBaseHeight = nBaseHeight + nRubyHeight;
-        nRubyHeight = 0;
+        m_nBaseWidth = m_nBaseHeight;
+        m_nBaseHeight = m_nBaseHeight + m_nRubyHeight;
+        m_nRubyHeight = 0;
     }
     else
     {
         //switch from "standard mode" to "squared mode"
-        nRubyHeight = nBaseHeight/3;
-        nBaseHeight = nBaseHeight - nRubyHeight;
-        nBaseWidth = nBaseHeight;
+        m_nRubyHeight = m_nBaseHeight/3;
+        m_nBaseHeight = m_nBaseHeight - m_nRubyHeight;
+        m_nBaseWidth = m_nBaseHeight;
     }
-    bSquaredMode = !bSquaredMode;
+    m_bSquaredMode = !m_bSquaredMode;
 }
 
 void SwTextGridItem::Init()
 {
-    if( bSquaredMode )
+    if (m_bSquaredMode)
     {
-        nLines = 20;
-        nBaseHeight = 400;
-        nRubyHeight = 200;
-        eGridType = GRID_NONE;
-        bRubyTextBelow = 0;
-        bPrintGrid = 1;
-        bDisplayGrid = 1;
-        bSnapToChars = 1;
-        nBaseWidth = 400;
+        m_nLines = 20;
+        m_nBaseHeight = 400;
+        m_nRubyHeight = 200;
+        m_eGridType = GRID_NONE;
+        m_bRubyTextBelow = 0;
+        m_bPrintGrid = 1;
+        m_bDisplayGrid = 1;
+        m_bSnapToChars = 1;
+        m_nBaseWidth = 400;
     }
     else
     {
-        nLines = 44;
-        nBaseHeight = 312;
-        nRubyHeight = 0;
-        eGridType = GRID_NONE;
-        bRubyTextBelow = 0;
-        bPrintGrid = 1;
-        bDisplayGrid = 1;
-        nBaseWidth = 210;
-        bSnapToChars = 1;
+        m_nLines = 44;
+        m_nBaseHeight = 312;
+        m_nRubyHeight = 0;
+        m_eGridType = GRID_NONE;
+        m_bRubyTextBelow = 0;
+        m_bPrintGrid = 1;
+        m_bDisplayGrid = 1;
+        m_nBaseWidth = 210;
+        m_bSnapToChars = 1;
     }
 }
 
commit 71b55cf57460aec3fec948676251448934ba31d1
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri Mar 7 15:56:37 2014 +0100

    rhbz#1043551: sw: avoid division-by-0 in Text Grid painting code
    
    Possible to trigger with a document containing:
        style:layout-grid-base-height="0cm"
    
    Change-Id: Id3bd1f29157b39e8a577be0b87b86236dbe5a50c

diff --git a/sw/source/core/layout/atrfrm.cxx b/sw/source/core/layout/atrfrm.cxx
index 51a0d53..f80cf38 100644
--- a/sw/source/core/layout/atrfrm.cxx
+++ b/sw/source/core/layout/atrfrm.cxx
@@ -2268,12 +2268,24 @@ bool SwTextGridItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
             bRet = (rVal >>= nTmp);
             nTmp = MM100_TO_TWIP( nTmp );
             if( bRet && (nTmp >= 0) && ( nTmp <= USHRT_MAX) )
+            {
+                // rhbz#1043551 round up to 5pt -- 0 causes divide-by-zero
+                // in layout; 1pt ties the painting code up in knots for
+                // minutes with bazillion lines...
+#define MIN_TEXTGRID_SIZE 100
                 if( (nMemberId & ~CONVERT_TWIPS) == MID_GRID_BASEHEIGHT )
+                {
+                    nTmp = std::max(nTmp, MIN_TEXTGRID_SIZE);
                     SetBaseHeight( (sal_uInt16)nTmp );
+                }
                 else if( (nMemberId & ~CONVERT_TWIPS) == MID_GRID_BASEWIDTH )
+                {
+                    nTmp = std::max(nTmp, MIN_TEXTGRID_SIZE);
                     SetBaseWidth( (sal_uInt16)nTmp );
+                }
                 else
                     SetRubyHeight( (sal_uInt16)nTmp );
+            }
             else
                 bRet = false;
         }


More information about the Libreoffice-commits mailing list