diff options
author | Matteo Casalin <matteo.casalin@yahoo.com> | 2014-08-23 11:22:26 +0200 |
---|---|---|
committer | Matteo Casalin <matteo.casalin@yahoo.com> | 2014-09-06 12:08:55 +0200 |
commit | 120486c83f26ec2119cde8e5f66e8921f39dfb52 (patch) | |
tree | b563dece0a01e9fb4abb00053adad1ae0c8fc255 /sw/source/core/txtnode | |
parent | 80343757c6e1c732c2abbba4528f23e6c1e6ec58 (diff) |
Group some more common code and reduce casts
Change-Id: Ib2f23f098377a07237cdba973edd8e854db05625
Diffstat (limited to 'sw/source/core/txtnode')
-rw-r--r-- | sw/source/core/txtnode/fntcache.cxx | 48 |
1 files changed, 13 insertions, 35 deletions
diff --git a/sw/source/core/txtnode/fntcache.cxx b/sw/source/core/txtnode/fntcache.cxx index 5b5d07113e5a..29149e623203 100644 --- a/sw/source/core/txtnode/fntcache.cxx +++ b/sw/source/core/txtnode/fntcache.cxx @@ -72,7 +72,7 @@ OutputDevice* SwFntObj::pPixOut = NULL; namespace { -sal_uInt16 GetDefaultFontHeight( SwDrawTextInfo &rInf ) +long EvalGridWidthAdd( const SwTextGridItem *const pGrid, const SwDrawTextInfo &rInf ) { SwDocShell* pDocShell = rInf.GetShell()->GetDoc()->GetDocShell(); SfxStyleSheetBasePool* pBasePool = pDocShell->GetStyleSheetPool(); @@ -82,7 +82,13 @@ sal_uInt16 GetDefaultFontHeight( SwDrawTextInfo &rInf ) SfxStyleSheetBase* pStyle = pBasePool->Find(sString, (SfxStyleFamily)SFX_STYLE_FAMILY_PARA); SfxItemSet& aTmpSet = pStyle->GetItemSet(); SvxFontHeightItem &aDefaultFontItem = (SvxFontHeightItem&)aTmpSet.Get(RES_CHRATR_CJK_FONTSIZE); - return (sal_uInt16)aDefaultFontItem.GetHeight(); + + const SwDoc* pDoc = rInf.GetShell()->GetDoc(); + const long nGridWidthAdd = GetGridWidth(*pGrid, *pDoc) - aDefaultFontItem.GetHeight(); + if( SW_LATIN == rInf.GetFont()->GetActual() ) + return nGridWidthAdd / 2; + + return nGridWidthAdd; } } @@ -996,14 +1002,7 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf ) 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); - if( SW_LATIN == rInf.GetFont()->GetActual() ) - nGridWidthAdd = ( nGridWidthAdd - nDefaultFontHeight ) / 2; - else - nGridWidthAdd = nGridWidthAdd - nDefaultFontHeight; + const long nGridWidthAdd = EvalGridWidthAdd( pGrid, rInf ); long* pKernArray = new long[rInf.GetLen()]; @@ -1833,14 +1832,7 @@ Size SwFntObj::GetTextSize( SwDrawTextInfo& rInf ) 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); - if( SW_LATIN == rInf.GetFont()->GetActual() ) - nGridWidthAdd = ( nGridWidthAdd - nDefaultFontHeight ) / 2; - else - nGridWidthAdd = nGridWidthAdd - nDefaultFontHeight; + const long nGridWidthAdd = EvalGridWidthAdd( pGrid, rInf ); OutputDevice* pOutDev; if ( pPrinter ) { @@ -1853,7 +1845,7 @@ Size SwFntObj::GetTextSize( SwDrawTextInfo& rInf ) aTxtSize.Width() = pOutDev->GetTextWidth( rInf.GetText(), rInf.GetIdx(), nLn ); aTxtSize.Height() = pOutDev->GetTextHeight() + GetFontLeading( rInf.GetShell(), rInf.GetOut() ); - aTxtSize.Width() += (nLn) * long( nGridWidthAdd ); + aTxtSize.Width() += nLn * nGridWidthAdd; //if ( rInf.GetKern() && nLn ) // aTxtSize.Width() += ( nLn ) * long( rInf.GetKern() ); @@ -2107,14 +2099,7 @@ sal_Int32 SwFntObj::GetCrsrOfst( SwDrawTextInfo &rInf ) 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); - if( SW_LATIN == rInf.GetFont()->GetActual() ) - nGridWidthAdd = ( nGridWidthAdd - nDefaultFontHeight ) / 2; - else - nGridWidthAdd = nGridWidthAdd - nDefaultFontHeight; + const long nGridWidthAdd = EvalGridWidthAdd( pGrid, rInf ); for(sal_Int32 j = 0; j < rInf.GetLen(); j++) { @@ -2356,14 +2341,7 @@ sal_Int32 SwFont::GetTxtBreak( SwDrawTextInfo& rInf, long nTextWidth ) 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); - if( SW_LATIN == rInf.GetFont()->GetActual() ) - nGridWidthAdd = ( nGridWidthAdd - nDefaultFontHeight ) / 2 ; - else - nGridWidthAdd = nGridWidthAdd - nDefaultFontHeight; + const long nGridWidthAdd = EvalGridWidthAdd( pGrid, rInf ); long* pKernArray = new long[rInf.GetLen()]; rInf.GetOut().GetTextArray( rInf.GetText(), pKernArray, |