diff options
author | Zolnai Tamás <zolnaitamas2000@gmail.com> | 2013-07-22 22:21:54 +0200 |
---|---|---|
committer | Zolnai Tamás <zolnaitamas2000@gmail.com> | 2013-07-26 07:16:41 +0200 |
commit | f8a4c68588e3cd209fd6bba8671d8f42f1cc1ce9 (patch) | |
tree | 75a345bc33b760d35dd7f60c44f552403902a76e /sw | |
parent | 318bbbfc9bad8c0e04306faade2dec956ff89d28 (diff) |
CharBrd 3: painting of border for simple text
-Use the frame painting for character border
-Increase the size of the portion
(height, ascent and size)
-Shift the text drawing rectangle
-Make the text cursor to skip the borders
Change-Id: Ia40fed5d7a93f85b73b7fa019ec4ede9421d89d1
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/core/inc/frmtool.hxx | 4 | ||||
-rw-r--r-- | sw/source/core/layout/paintfrm.cxx | 86 | ||||
-rw-r--r-- | sw/source/core/text/guess.cxx | 6 | ||||
-rw-r--r-- | sw/source/core/text/inftxt.cxx | 84 | ||||
-rw-r--r-- | sw/source/core/text/inftxt.hxx | 19 | ||||
-rw-r--r-- | sw/source/core/text/itrcrsr.cxx | 12 | ||||
-rw-r--r-- | sw/source/core/text/portxt.cxx | 1 |
7 files changed, 187 insertions, 25 deletions
diff --git a/sw/source/core/inc/frmtool.hxx b/sw/source/core/inc/frmtool.hxx index 45b63bf62d8d..bd2e4955f615 100644 --- a/sw/source/core/inc/frmtool.hxx +++ b/sw/source/core/inc/frmtool.hxx @@ -26,6 +26,7 @@ #include "swcache.hxx" // #i96772# #include <editeng/lrspitem.hxx> +#include <swfont.hxx> class SwPageFrm; class SwFlyFrm; @@ -64,6 +65,9 @@ void SwAlignRect( SwRect &rRect, const ViewShell *pSh ); // Created declaration here to avoid <extern> declarations void SwAlignGrfRect( SwRect *pGrfRect, const OutputDevice &rOut ); +// Paint character border using frame painting code +void PaintCharacterBorder( const SwFont& rFont, const SwRect& rPaintArea); + // get Fly, if no List is given use the current shell // Implementation in feshview.cxx SwFlyFrm *GetFlyFromMarked( const SdrMarkList *pLst, ViewShell *pSh ); diff --git a/sw/source/core/layout/paintfrm.cxx b/sw/source/core/layout/paintfrm.cxx index 6d99fd383733..ca3fcd7ccb5e 100644 --- a/sw/source/core/layout/paintfrm.cxx +++ b/sw/source/core/layout/paintfrm.cxx @@ -4561,13 +4561,11 @@ static void lcl_MakeBorderLine(SwRect const& rRect, bool const isVerticalInModel, bool const isLeftOrTopBorderInModel, + bool const isVertical, SvxBorderLine const& rBorder, SvxBorderLine const*const pLeftOrTopNeighbour, SvxBorderLine const*const pRightOrBottomNeighbour) { - // fdo#44010: for vertical text lcl_PaintTopBottomLine produces vertical - // borders and lcl_PaintLeftRightLine horizontal ones. - bool const isVertical(rRect.Height() > rRect.Width()); bool const isLeftOrTopBorder((isVerticalInModel == isVertical) ? isLeftOrTopBorderInModel : (isLeftOrTopBorderInModel != isVertical)); @@ -4713,7 +4711,8 @@ static void lcl_PaintLeftRightLine( const bool _bLeft, if ( lcl_GetLineWidth( pLeftRightBorder ) > 0 ) { lcl_MakeBorderLine( - aRect, true, _bLeft, *pLeftRightBorder, pTopBorder, pBottomBorder); + aRect, true, _bLeft, aRect.Height() > aRect.Width(), + *pLeftRightBorder, pTopBorder, pBottomBorder); } } @@ -4759,7 +4758,84 @@ static void lcl_PaintTopBottomLine( const bool _bTop, if ( lcl_GetLineWidth( pTopBottomBorder ) > 0 ) { lcl_MakeBorderLine( - aRect, false, _bTop, *pTopBottomBorder, rBox.GetLeft(), rBox.GetRight()); + aRect, false, _bTop, aRect.Height() > aRect.Width(), + *pTopBottomBorder, rBox.GetLeft(), rBox.GetRight()); + } +} + +void PaintCharacterBorder( + const SwFont& rFont, + const SwRect& rPaintArea ) +{ + SwRect aAlignedRect(rPaintArea); + SwAlignRect(aAlignedRect, pGlobalShell); + + if( rFont.GetTopBorder() ) + { + Point aLeftTop ( + aAlignedRect.Left(), + aAlignedRect.Top()); + Point aRightBottom ( + aAlignedRect.Right(), + aAlignedRect.Top() + rFont.GetTopBorder().get().GetScaledWidth()); + + lcl_MakeBorderLine( + SwRect( aLeftTop, aRightBottom), + false, true, false, + rFont.GetTopBorder().get(), + rFont.GetLeftBorder().get_ptr(), + rFont.GetRightBorder().get_ptr()); + } + + if( rFont.GetBottomBorder() ) + { + Point aLeftTop ( + aAlignedRect.Left(), + aAlignedRect.Bottom() - rFont.GetBottomBorder().get().GetScaledWidth()); + Point aRightBottom ( + aAlignedRect.Right(), + aAlignedRect.Bottom()); + + lcl_MakeBorderLine( + SwRect( aLeftTop, aRightBottom), + false, false, false, + rFont.GetBottomBorder().get(), + rFont.GetLeftBorder().get_ptr(), + rFont.GetRightBorder().get_ptr()); + } + + if( rFont.GetLeftBorder() ) + { + Point aLeftTop ( + aAlignedRect.Left(), + aAlignedRect.Top()); + Point aRightBottom ( + aAlignedRect.Left() + rFont.GetLeftBorder().get().GetScaledWidth(), + aAlignedRect.Bottom()); + + lcl_MakeBorderLine( + SwRect( aLeftTop, aRightBottom), + true, true, true, + rFont.GetLeftBorder().get(), + rFont.GetTopBorder().get_ptr(), + rFont.GetBottomBorder().get_ptr()); + } + + if( rFont.GetRightBorder() ) + { + Point aLeftTop ( + aAlignedRect.Right() - rFont.GetRightBorder().get().GetScaledWidth(), + aAlignedRect.Top()); + Point aRightBottom ( + aAlignedRect.Right(), + aAlignedRect.Bottom()); + + lcl_MakeBorderLine( + SwRect( aLeftTop, aRightBottom), + true, false, true, + rFont.GetRightBorder().get(), + rFont.GetTopBorder().get_ptr(), + rFont.GetBottomBorder().get_ptr()); } } diff --git a/sw/source/core/text/guess.cxx b/sw/source/core/text/guess.cxx index 03628da8dc90..37baa9ec0368 100644 --- a/sw/source/core/text/guess.cxx +++ b/sw/source/core/text/guess.cxx @@ -112,6 +112,12 @@ sal_Bool SwTxtGuess::Guess( const SwTxtPortion& rPor, SwTxtFormatInfo &rInf, if ( nLineWidth < 0 ) nLineWidth = 0; } + // Decrease the line width with the right and left border width + if( rInf.GetFont()->GetRightBorder() ) + nLineWidth -= rInf.GetFont()->GetRightBorder().get().GetScaledWidth(); + if( rInf.GetFont()->GetLeftBorder() ) + nLineWidth -= rInf.GetFont()->GetLeftBorder().get().GetScaledWidth(); + const bool bUnbreakableNumberings = rInf.GetTxtFrm()->GetTxtNode()-> getIDocumentSettingAccess()->get(IDocumentSettingAccess::UNBREAKABLE_NUMBERINGS); diff --git a/sw/source/core/text/inftxt.cxx b/sw/source/core/text/inftxt.cxx index b2fc17ba45b9..39efe1f9e737 100644 --- a/sw/source/core/text/inftxt.cxx +++ b/sw/source/core/text/inftxt.cxx @@ -67,6 +67,7 @@ // #i12836# enhanced pdf export #include <EnhancedPDFExportHelper.hxx> #include <docufld.hxx> +#include <frmtool.hxx> #include <unomid.h> @@ -366,6 +367,52 @@ void SwTxtSizeInfo::NoteAnimation() const "SwTxtSizeInfo::NoteAnimation() changed m_pOut" ); } + +KSHORT SwTxtSizeInfo::GetAscent() const +{ + SAL_WARN_IF( !GetOut(), "sw.text.txtinfo", "SwTxtSizeInfo::GetAscent() without m_pOut" ); + + sal_uInt16 nAscent = ((SwFont*)GetFont())->GetAscent( m_pVsh, *GetOut() ); + + if( GetFont()->GetTopBorder() ) + nAscent += GetFont()->GetTopBorder().get().GetScaledWidth(); + + return nAscent; +} + +KSHORT SwTxtSizeInfo::GetTxtHeight() const +{ + SAL_WARN_IF( !GetOut(), "sw.text.txtinfo", "SwTxtSizeInfo::GetTxtHeight() without m_pOut" ); + + sal_uInt16 nHeight = ((SwFont*)GetFont())->GetHeight( m_pVsh, *GetOut() ); + + if( GetFont()->GetTopBorder() ) + nHeight += GetFont()->GetTopBorder().get().GetScaledWidth(); + if( GetFont()->GetBottomBorder() ) + nHeight += GetFont()->GetBottomBorder().get().GetScaledWidth(); + + return nHeight; +} + +static void lcl_IncreaseSizeWithBorders(SwPosSize& rSize, const SwFont& rFont) +{ + + sal_uInt16 nWidth = rSize.Width(); + sal_uInt16 nHeight = rSize.Height(); + + if( rFont.GetTopBorder() ) + nHeight += rFont.GetTopBorder().get().GetScaledWidth(); + if( rFont.GetBottomBorder() ) + nHeight += rFont.GetBottomBorder().get().GetScaledWidth(); + if( rFont.GetRightBorder() ) + nWidth += rFont.GetRightBorder().get().GetScaledWidth(); + if( rFont.GetLeftBorder() ) + nWidth += rFont.GetLeftBorder().get().GetScaledWidth(); + + rSize.Height(nHeight); + rSize.Width(nWidth); +} + SwPosSize SwTxtSizeInfo::GetTxtSize( OutputDevice* pOutDev, const SwScriptInfo* pSI, const XubString& rTxt, @@ -379,6 +426,7 @@ SwPosSize SwTxtSizeInfo::GetTxtSize( OutputDevice* pOutDev, aDrawInf.SetSnapToGrid( SnapToGrid() ); aDrawInf.SetKanaComp( nComp ); SwPosSize aSize = m_pFnt->_GetTxtSize( aDrawInf ); + lcl_IncreaseSizeWithBorders(aSize,*m_pFnt); return aSize; } @@ -400,7 +448,9 @@ SwPosSize SwTxtSizeInfo::GetTxtSize() const aDrawInf.SetFont( m_pFnt ); aDrawInf.SetSnapToGrid( SnapToGrid() ); aDrawInf.SetKanaComp( nComp ); - return m_pFnt->_GetTxtSize( aDrawInf ); + SwPosSize aSize = m_pFnt->_GetTxtSize( aDrawInf ); + lcl_IncreaseSizeWithBorders(aSize,*m_pFnt); + return aSize; } void SwTxtSizeInfo::GetTxtSize( const SwScriptInfo* pSI, const xub_StrLen nIndex, @@ -413,6 +463,7 @@ void SwTxtSizeInfo::GetTxtSize( const SwScriptInfo* pSI, const xub_StrLen nIndex aDrawInf.SetSnapToGrid( SnapToGrid() ); aDrawInf.SetKanaComp( nComp ); SwPosSize aSize = m_pFnt->_GetTxtSize( aDrawInf ); + lcl_IncreaseSizeWithBorders(aSize,*m_pFnt); nMaxSizeDiff = (sal_uInt16)aDrawInf.GetKanaDiff(); nMinSize = aSize.Width(); } @@ -610,8 +661,16 @@ void SwTxtPaintInfo::_DrawText( const XubString &rText, const SwLinePortion &rPo SwDrawTextInfo aDrawInf( m_pFrm->getRootFrm()->GetCurrShell(), *m_pOut, pSI, rText, nStart, nLength, rPor.Width(), bBullet ); - aDrawInf.SetLeft( GetPaintRect().Left() ); - aDrawInf.SetRight( GetPaintRect().Right() ); + if( m_pFnt->GetLeftBorder() ) + aDrawInf.SetLeft( GetPaintRect().Left() + m_pFnt->GetLeftBorder().get().GetScaledWidth() ); + else + aDrawInf.SetLeft( GetPaintRect().Left() ); + + if( m_pFnt->GetRightBorder() ) + aDrawInf.SetRight( GetPaintRect().Right() - m_pFnt->GetRightBorder().get().GetScaledWidth() ); + else + aDrawInf.SetRight( GetPaintRect().Right()); + aDrawInf.SetUnderFnt( m_pUnderFnt ); const long nSpaceAdd = ( rPor.IsBlankPortion() || rPor.IsDropPortion() || @@ -641,11 +700,16 @@ void SwTxtPaintInfo::_DrawText( const XubString &rText, const SwLinePortion &rPo rPor.GetPortion()->InFixMargGrp() || rPor.GetPortion()->IsHolePortion() ); + // Draw text next to the left border + Point aFontPos(aPos); + if( m_pFnt->GetLeftBorder() ) + aFontPos.X() += m_pFnt->GetLeftBorder().get().GetScaledWidth(); + if( GetTxtFly()->IsOn() ) { // aPos needs to be the TopLeft, because we cannot calculate the // ClipRects otherwise - const Point aPoint( aPos.X(), aPos.Y() - rPor.GetAscent() ); + const Point aPoint( aFontPos.X(), aFontPos.Y() - rPor.GetAscent() ); const Size aSize( rPor.Width(), rPor.Height() ); aDrawInf.SetPos( aPoint ); aDrawInf.SetSize( aSize ); @@ -658,7 +722,7 @@ void SwTxtPaintInfo::_DrawText( const XubString &rText, const SwLinePortion &rPo } else { - aDrawInf.SetPos( aPos ); + aDrawInf.SetPos( aFontPos ); if( bKern ) m_pFnt->_DrawStretchText( aDrawInf ); else @@ -1153,6 +1217,16 @@ void SwTxtPaintInfo::_DrawBackBrush( const SwLinePortion &rPor ) const } } +void SwTxtPaintInfo::DrawBorder( const SwLinePortion &rPor ) const +{ + SwRect aDrawArea; + CalcRect( rPor, &aDrawArea ); + if ( aDrawArea.HasArea() ) + { + PaintCharacterBorder(*m_pFnt, aDrawArea); + } +} + void SwTxtPaintInfo::DrawViewOpt( const SwLinePortion &rPor, const MSHORT nWhich ) const { diff --git a/sw/source/core/text/inftxt.hxx b/sw/source/core/text/inftxt.hxx index 38efa9ae0e95..c9d5d10985bb 100644 --- a/sw/source/core/text/inftxt.hxx +++ b/sw/source/core/text/inftxt.hxx @@ -267,7 +267,7 @@ public: inline sal_Unicode GetChar( const sal_Int32 nPos ) const { if (m_pTxt && !m_pTxt->isEmpty()) return (*m_pTxt)[ nPos ]; return 0; } - inline KSHORT GetTxtHeight() const; + KSHORT GetTxtHeight() const; // // GetTxtSize @@ -294,7 +294,7 @@ public: const sal_uInt16 nComp, xub_StrLen& rExtraCharPos ) const; - inline KSHORT GetAscent() const; + KSHORT GetAscent() const; inline sal_Int32 GetIdx() const { return m_nIdx; } inline void SetIdx( const sal_Int32 nNew ) { m_nIdx = nNew; } @@ -442,6 +442,8 @@ public: inline void DrawBackBrush( const SwLinePortion &rPor ) const { /* if( pFnt->GetBackColor() ) */ _DrawBackBrush( rPor ); } + void DrawBorder( const SwLinePortion &rPor ) const; + void DrawCheckBox( const SwFieldFormPortion &rPor, bool checked) const; inline void NotifyURL( const SwLinePortion &rPor ) const @@ -778,19 +780,6 @@ public: /************************************************************************* * Inline implementations of SwTxtSizeInfo *************************************************************************/ - -inline KSHORT SwTxtSizeInfo::GetAscent() const -{ - OSL_ENSURE( GetOut(), "SwTxtSizeInfo::GetAscent() without m_pOut" ); - return ((SwFont*)GetFont())->GetAscent( m_pVsh, *GetOut() ); -} - -inline KSHORT SwTxtSizeInfo::GetTxtHeight() const -{ - OSL_ENSURE( GetOut(), "SwTxtSizeInfo::GetTxtHeight() without m_pOut" ); - return ((SwFont*)GetFont())->GetHeight( m_pVsh, *GetOut() ); -} - inline SwPosSize SwTxtSizeInfo::GetTxtSize( const XubString &rTxt ) const { return GetTxtSize( m_pOut, 0, rTxt, 0, rTxt.Len(), 0 ); diff --git a/sw/source/core/text/itrcrsr.cxx b/sw/source/core/text/itrcrsr.cxx index 42ab844843de..17b76813fadb 100644 --- a/sw/source/core/text/itrcrsr.cxx +++ b/sw/source/core/text/itrcrsr.cxx @@ -922,6 +922,12 @@ void SwTxtCursor::_GetCharRect( SwRect* pOrig, const xub_StrLen nOfst, } } pPor->SetLen( nOldLen ); + + // Shift the cursor with the right border width + // Note: nX remains positive because GetTxtSize() also include the width of the right border + if( GetInfo().GetFont()->GetRightBorder() && aInf.GetIdx() < nOfst && nOfst < aInf.GetIdx() + pPor->GetLen() ) + nX -= GetInfo().GetFont()->GetRightBorder().get().GetScaledWidth(); + } bWidth = sal_False; break; @@ -1245,6 +1251,7 @@ sal_Bool SwTxtCursor::GetCharRect( SwRect* pOrig, const xub_StrLen nOfst, if( nOut > 0 ) pOrig->Pos().X() -= nOut + 10; } + return bRet; } @@ -1609,6 +1616,11 @@ xub_StrLen SwTxtCursor::GetCrsrOfst( SwPosition *pPos, const Point &rPoint, aSizeInf.GetTxt(), aSizeInf.GetIdx(), pPor->GetLen() ); + + // Shift the offset with the left border width + if( GetInfo().GetFont()->GetLeftBorder() ) + nX = std::max(0, nX - GetInfo().GetFont()->GetLeftBorder().get().GetScaledWidth()); + aDrawInf.SetOfst( nX ); if ( nSpaceAdd ) diff --git a/sw/source/core/text/portxt.cxx b/sw/source/core/text/portxt.cxx index e65e9a6c6382..254f93f43159 100644 --- a/sw/source/core/text/portxt.cxx +++ b/sw/source/core/text/portxt.cxx @@ -559,6 +559,7 @@ void SwTxtPortion::Paint( const SwTxtPaintInfo &rInf ) const else if( GetLen() ) { rInf.DrawBackBrush( *this ); + rInf.DrawBorder( *this ); // do we have to repaint a post it portion? if( rInf.OnWin() && pPortion && !pPortion->Width() ) |