summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZolnai Tamás <zolnaitamas2000@gmail.com>2013-07-28 12:44:52 +0200
committerZolnai Tamás <zolnaitamas2000@gmail.com>2013-08-02 16:27:14 +0200
commit0d9ddccd8810a81a6f4d737870969d0dcf367d23 (patch)
tree4b7e94a7976dd67fcaa8dbb0a576c03dd626e29d
parentd5fd6bd3571a519784c98055b75807554ed0f47f (diff)
CharBrd 4.1: merge borders of text portions
If two neighbouring text portion has the same height and same border then the left/right border between them will be removed. Change-Id: Id91ed33acbd8d052dc8d5248c0caf0822303bce7
-rw-r--r--sw/source/core/text/itratr.cxx71
-rw-r--r--sw/source/core/text/itratr.hxx21
2 files changed, 87 insertions, 5 deletions
diff --git a/sw/source/core/text/itratr.cxx b/sw/source/core/text/itratr.cxx
index fba4898bbf84..249f1325c161 100644
--- a/sw/source/core/text/itratr.cxx
+++ b/sw/source/core/text/itratr.cxx
@@ -122,6 +122,12 @@ SwTxtAttr *SwAttrIter::GetAttr( const xub_StrLen nPosition ) const
sal_Bool SwAttrIter::SeekAndChgAttrIter( const xub_StrLen nNewPos, OutputDevice* pOut )
{
+ sal_Bool bRet = ImplSeekAndChgAttrIter(nNewPos, pOut);
+ return MergeCharBorder(false) || bRet;
+}
+
+sal_Bool SwAttrIter::ImplSeekAndChgAttrIter( const xub_StrLen nNewPos, OutputDevice* pOut )
+{
sal_Bool bChg = nStartIndex && nNewPos == nPos ? pFnt->IsFntChg() : Seek( nNewPos );
if ( pLastOut != pOut )
{
@@ -138,6 +144,7 @@ sal_Bool SwAttrIter::SeekAndChgAttrIter( const xub_StrLen nNewPos, OutputDevice*
aFntIdx[ pFnt->GetActual() ], pFnt->GetActual() );
pFnt->ChgPhysFnt( pShell, *pOut );
}
+
return bChg;
}
@@ -153,9 +160,14 @@ sal_Bool SwAttrIter::IsSymbol( const xub_StrLen nNewPos )
/*************************************************************************
* SwAttrIter::SeekStartAndChg()
*************************************************************************/
-
sal_Bool SwAttrIter::SeekStartAndChgAttrIter( OutputDevice* pOut, const sal_Bool bParaFont )
{
+ sal_Bool bRet = ImplSeekStartAndChgAttrIter( pOut, bParaFont );
+ return bParaFont ? bRet : MergeCharBorder(true) || bRet;
+}
+
+sal_Bool SwAttrIter::ImplSeekStartAndChgAttrIter( OutputDevice* pOut, const sal_Bool bParaFont )
+{
if ( pRedln && pRedln->ExtOn() )
pRedln->LeaveExtend( *pFnt, 0 );
@@ -246,6 +258,7 @@ void SwAttrIter::SeekFwd( const xub_StrLen nNewPos )
while ( ( nStartIndex < pHints->GetStartCount() ) &&
(*(pTxtAttr=pHints->GetStart(nStartIndex))->GetStart()<=nNewPos))
{
+
// oeffne die TextAttribute, deren Ende hinter der neuen Position liegt
if ( *pTxtAttr->GetAnyEnd() > nNewPos ) Chg( pTxtAttr );
nStartIndex++;
@@ -353,6 +366,62 @@ xub_StrLen SwAttrIter::GetNextAttr( ) const
return nNext;
}
+static bool lcl_HasMergeableBorder(const SwFont& rFirst, const SwFont& rSecond)
+{
+ return
+ rFirst.GetTopBorder() == rSecond.GetTopBorder() &&
+ rFirst.GetBottomBorder() == rSecond.GetBottomBorder() &&
+ rFirst.GetLeftBorder() == rSecond.GetLeftBorder() &&
+ rFirst.GetRightBorder() == rSecond.GetRightBorder();
+}
+
+bool SwAttrIter::MergeCharBorder( const bool bStart )
+{
+ const xub_StrLen nActPos = nPos;
+ bool bRemoveLeft = false;
+ bool bRemoveRight = false;
+ SwFont aTmpFont = *pFnt;
+ const sal_Int32 nTmpStart = nStartIndex;
+
+ // Check whether next neightbour has same border and height
+ if( aTmpFont.GetRightBorder() && pHints && nTmpStart < pHints->GetStartCount() )
+ {
+ ImplSeekAndChgAttrIter(GetNextAttr(), pLastOut);
+ if( aTmpFont.GetHeight(pShell, *pLastOut) == pFnt->GetHeight(pShell, *pLastOut) &&
+ lcl_HasMergeableBorder(aTmpFont, *pFnt) )
+ {
+ bRemoveRight = true;
+ }
+ }
+
+ // Check whether previous neightbour has same border and height
+ if( aTmpFont.GetLeftBorder() && nTmpStart > 1)
+ {
+ ImplSeekAndChgAttrIter(nActPos-1, pLastOut);
+ if( aTmpFont.GetHeight(pShell, *pLastOut) == pFnt->GetHeight(pShell, *pLastOut) &&
+ lcl_HasMergeableBorder(aTmpFont, *pFnt) )
+ {
+ bRemoveLeft = true;
+ }
+ }
+
+ // If the iterator changed its position, than we have to reset it.
+ if( nPos != nActPos )
+ {
+ if( bStart )
+ ImplSeekStartAndChgAttrIter(pLastOut, false);
+ else
+ ImplSeekAndChgAttrIter(nActPos, pLastOut);
+ }
+
+ if( bRemoveRight )
+ pFnt->SetRightBorder(0);
+ if( bRemoveLeft )
+ pFnt->SetLeftBorder(0);
+
+ return bRemoveLeft || bRemoveRight;
+}
+
class SwMinMaxArgs
{
public:
diff --git a/sw/source/core/text/itratr.hxx b/sw/source/core/text/itratr.hxx
index a4a7fbc536a5..317e59d40cfa 100644
--- a/sw/source/core/text/itratr.hxx
+++ b/sw/source/core/text/itratr.hxx
@@ -72,6 +72,9 @@ protected:
aMagicNo[SW_LATIN] = aMagicNo[SW_CJK] = aMagicNo[SW_CTL] = NULL;
}
+ /// Implementation of the considering public methods (to avoid recursion)
+ sal_Bool ImplSeekAndChgAttrIter( const xub_StrLen nNewPos, OutputDevice* pOut );
+ sal_Bool ImplSeekStartAndChgAttrIter( OutputDevice* pOut, const sal_Bool bParaFont );
public:
// Constructor, destructor
inline SwAttrIter( SwTxtNode& rTxtNode, SwScriptInfo& rScrInf )
@@ -83,19 +86,29 @@ public:
inline SwRedlineItr *GetRedln() { return pRedln; }
// The parameter returns the position of the next change before or at the
// char position.
- // Returns sal_False, if there's no change before or at the positon,
- // else sal_True.
xub_StrLen GetNextAttr( ) const;
- // Enables the attributes used at char pos nPos in the logical font
+ /// Enables the attributes used at char pos nPos in the logical font
sal_Bool Seek( const xub_StrLen nPos );
// Creates the font at the specified position via Seek() and checks
// if it's a symbol font.
sal_Bool IsSymbol( const xub_StrLen nPos );
- // Executes ChgPhysFnt if Seek() returns sal_True
+ /** Executes ChgPhysFnt if Seek() returns sal_True
+ * and change font to merge character border with neighbours.
+ **/
sal_Bool SeekAndChgAttrIter( const xub_StrLen nPos, OutputDevice* pOut );
sal_Bool SeekStartAndChgAttrIter( OutputDevice* pOut, const sal_Bool bParaFont = sal_False );
+ /** Merge character border with removing left/right border of the font if the
+ * the neighbours of the current position (nPos) has the same height
+ * and same kind of border.
+ * @param bStart true if it is called from SeekStartAndChgAttrIter
+ * false, otherwise
+ * @return true, if font change (removing some of its borders)
+ * false, otherwise
+ **/
+ bool MergeCharBorder( const bool bStart );
+
// Do we have an attribute change at all?
inline sal_Bool HasHints() const { return 0 != pHints; }