Kaydet (Commit) 0d9ddccd authored tarafından Zolnai Tamás's avatar Zolnai Tamás

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
üst d5fd6bd3
......@@ -121,6 +121,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,8 +160,13 @@ 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:
......
......@@ -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; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment