2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2000-09-18 16:07:07 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-10 23:39:59 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2010-02-12 15:01:35 +01:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 23:39:59 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 23:39:59 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 23:39:59 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 23:39:59 +00:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 23:39:59 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-17 03:53:55 +00:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
2010-01-06 19:26:54 +01:00
|
|
|
#include "precompiled_editeng.hxx"
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2010-01-06 19:26:54 +01:00
|
|
|
#include <editeng/txtrange.hxx>
|
2000-09-18 16:07:07 +00:00
|
|
|
#include <math.h>
|
2004-01-06 14:30:22 +00:00
|
|
|
#include <tools/poly.hxx>
|
2000-09-18 16:07:07 +00:00
|
|
|
#include <tools/debug.hxx>
|
2004-11-03 09:36:51 +00:00
|
|
|
#include <basegfx/polygon/b2dpolygon.hxx>
|
|
|
|
#include <basegfx/polygon/b2dpolygontools.hxx>
|
|
|
|
|
2011-02-22 12:00:38 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
#ifdef WIN
|
|
|
|
#pragma optimize ( "", off )
|
|
|
|
#endif
|
|
|
|
|
2011-03-02 10:14:51 +00:00
|
|
|
TextRanger::TextRanger( const basegfx::B2DPolyPolygon& rPolyPolygon,
|
|
|
|
const basegfx::B2DPolyPolygon* pLinePolyPolygon,
|
|
|
|
USHORT nCacheSz, USHORT nLft, USHORT nRght,
|
|
|
|
BOOL bSimpl, BOOL bInnr, BOOL bVert ) :
|
2006-10-12 11:40:51 +00:00
|
|
|
pBound( NULL ),
|
|
|
|
nCacheSize( nCacheSz ),
|
|
|
|
nRight( nRght ),
|
|
|
|
nLeft( nLft ),
|
|
|
|
nUpper( 0 ),
|
|
|
|
nLower( 0 ),
|
|
|
|
nPointCount( 0 ),
|
|
|
|
bSimple( bSimpl ),
|
|
|
|
bInner( bInnr ),
|
|
|
|
bVertical( bVert )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2009-07-10 14:03:42 +02:00
|
|
|
#ifdef DBG_UTIL
|
2000-11-16 15:06:31 +00:00
|
|
|
bFlag3 = bFlag4 = bFlag5 = bFlag6 = bFlag7 = FALSE;
|
2000-09-18 16:07:07 +00:00
|
|
|
#endif
|
2006-11-14 12:17:43 +00:00
|
|
|
sal_uInt32 nCount(rPolyPolygon.count());
|
|
|
|
mpPolyPolygon = new PolyPolygon( (sal_uInt16)nCount );
|
|
|
|
|
|
|
|
for(sal_uInt32 i(0L); i < nCount; i++)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2008-08-19 21:57:09 +00:00
|
|
|
const basegfx::B2DPolygon aCandidate(rPolyPolygon.getB2DPolygon(i).getDefaultAdaptiveSubdivision());
|
2006-11-14 12:17:43 +00:00
|
|
|
nPointCount += aCandidate.count();
|
|
|
|
mpPolyPolygon->Insert( Polygon(aCandidate), (sal_uInt16)i );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
2006-11-14 12:17:43 +00:00
|
|
|
|
|
|
|
if( pLinePolyPolygon )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2006-11-14 12:17:43 +00:00
|
|
|
nCount = pLinePolyPolygon->count();
|
|
|
|
mpLinePolyPolygon = new PolyPolygon();
|
|
|
|
|
|
|
|
for(sal_uInt32 i(0L); i < nCount; i++)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2008-08-19 21:57:09 +00:00
|
|
|
const basegfx::B2DPolygon aCandidate(pLinePolyPolygon->getB2DPolygon(i).getDefaultAdaptiveSubdivision());
|
2006-11-14 12:17:43 +00:00
|
|
|
nPointCount += aCandidate.count();
|
|
|
|
mpLinePolyPolygon->Insert( Polygon(aCandidate), (sal_uInt16)i );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2006-11-14 12:17:43 +00:00
|
|
|
mpLinePolyPolygon = NULL;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef WIN
|
|
|
|
#pragma optimize ( "", on )
|
|
|
|
#endif
|
|
|
|
|
|
|
|
TextRanger::~TextRanger()
|
|
|
|
{
|
2011-03-02 10:14:51 +00:00
|
|
|
mRangeCache.clear();
|
2006-11-14 12:17:43 +00:00
|
|
|
delete mpPolyPolygon;
|
|
|
|
delete mpLinePolyPolygon;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2010-11-09 01:42:14 +05:00
|
|
|
/* TextRanger::SetVertical(..)
|
|
|
|
If there's is a change in the writing direction,
|
|
|
|
the cache has to be cleared.
|
|
|
|
*/
|
2000-11-17 08:45:51 +00:00
|
|
|
void TextRanger::SetVertical( BOOL bNew )
|
|
|
|
{
|
|
|
|
if( IsVertical() != bNew )
|
|
|
|
{
|
|
|
|
bVertical = bNew;
|
2011-03-02 10:14:51 +00:00
|
|
|
mRangeCache.clear();
|
2000-11-17 08:45:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-02 10:14:51 +00:00
|
|
|
//! SvxBoundArgs is used to perform temporary calculations on a range array.
|
|
|
|
//! Temporary instances are created in TextRanger::GetTextRanges()
|
2000-09-18 16:07:07 +00:00
|
|
|
class SvxBoundArgs
|
|
|
|
{
|
2011-02-22 12:00:38 +00:00
|
|
|
std::vector<bool> aBoolArr;
|
2011-03-02 10:14:51 +00:00
|
|
|
LongDqPtr pLongArr;
|
2000-09-18 16:07:07 +00:00
|
|
|
TextRanger *pTextRanger;
|
|
|
|
long nMin;
|
|
|
|
long nMax;
|
|
|
|
long nTop;
|
|
|
|
long nBottom;
|
|
|
|
long nUpDiff;
|
|
|
|
long nLowDiff;
|
|
|
|
long nUpper;
|
|
|
|
long nLower;
|
2000-11-16 15:06:31 +00:00
|
|
|
long nStart;
|
|
|
|
long nEnd;
|
2000-09-18 16:07:07 +00:00
|
|
|
USHORT nCut;
|
|
|
|
USHORT nLast;
|
|
|
|
USHORT nNext;
|
|
|
|
BYTE nAct;
|
|
|
|
BYTE nFirst;
|
|
|
|
BOOL bClosed : 1;
|
|
|
|
BOOL bInner : 1;
|
|
|
|
BOOL bMultiple : 1;
|
|
|
|
BOOL bConcat : 1;
|
2000-11-16 15:06:31 +00:00
|
|
|
BOOL bRotate : 1;
|
2000-09-18 16:07:07 +00:00
|
|
|
void NoteRange( BOOL bToggle );
|
|
|
|
long Cut( long nY, const Point& rPt1, const Point& rPt2 );
|
|
|
|
void Add();
|
|
|
|
void _NoteFarPoint( long nPx, long nPyDiff, long nDiff );
|
|
|
|
void NoteFarPoint( long nPx, long nPyDiff, long nDiff )
|
|
|
|
{ if( nDiff ) _NoteFarPoint( nPx, nPyDiff, nDiff ); }
|
|
|
|
long CalcMax( const Point& rPt1, const Point& rPt2, long nRange, long nFar );
|
|
|
|
void CheckCut( const Point& rLst, const Point& rNxt );
|
2000-11-16 15:06:31 +00:00
|
|
|
inline long A( const Point& rP ) const { return bRotate ? rP.Y() : rP.X(); }
|
|
|
|
inline long B( const Point& rP ) const { return bRotate ? rP.X() : rP.Y(); }
|
2000-09-18 16:07:07 +00:00
|
|
|
public:
|
2011-03-02 10:14:51 +00:00
|
|
|
SvxBoundArgs( TextRanger* pRanger, LongDqPtr pLong, const Range& rRange );
|
2000-11-16 15:06:31 +00:00
|
|
|
void NotePoint( const long nA ) { NoteMargin( nA - nStart, nA + nEnd ); }
|
2000-09-18 16:07:07 +00:00
|
|
|
void NoteMargin( const long nL, const long nR )
|
|
|
|
{ if( nMin > nL ) nMin = nL; if( nMax < nR ) nMax = nR; }
|
|
|
|
USHORT Area( const Point& rPt );
|
2000-11-16 15:06:31 +00:00
|
|
|
void NoteUpLow( long nA, const BYTE nArea );
|
2000-09-18 16:07:07 +00:00
|
|
|
void Calc( const PolyPolygon& rPoly );
|
|
|
|
void Concat( const PolyPolygon* pPoly );
|
|
|
|
// inlines
|
|
|
|
void NoteLast() { if( bMultiple ) NoteRange( nAct == nFirst ); }
|
|
|
|
void SetClosed( const BOOL bNew ){ bClosed = bNew; }
|
|
|
|
BOOL IsClosed() const { return bClosed; }
|
|
|
|
void SetConcat( const BOOL bNew ){ bConcat = bNew; }
|
|
|
|
BOOL IsConcat() const { return bConcat; }
|
|
|
|
BYTE GetAct() const { return nAct; }
|
|
|
|
};
|
|
|
|
|
2011-03-02 10:14:51 +00:00
|
|
|
SvxBoundArgs::SvxBoundArgs( TextRanger* pRanger, LongDqPtr pLong,
|
2000-11-16 15:06:31 +00:00
|
|
|
const Range& rRange )
|
2011-02-22 12:00:38 +00:00
|
|
|
: pLongArr( pLong ), pTextRanger( pRanger ),
|
2000-11-16 15:06:31 +00:00
|
|
|
nTop( rRange.Min() ), nBottom( rRange.Max() ),
|
|
|
|
bInner( pRanger->IsInner() ), bMultiple( bInner || !pRanger->IsSimple() ),
|
|
|
|
bConcat( FALSE ), bRotate( pRanger->IsVertical() )
|
|
|
|
{
|
|
|
|
if( bRotate )
|
|
|
|
{
|
|
|
|
nStart = pRanger->GetUpper();
|
|
|
|
nEnd = pRanger->GetLower();
|
|
|
|
nLowDiff = pRanger->GetLeft();
|
|
|
|
nUpDiff = pRanger->GetRight();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nStart = pRanger->GetLeft();
|
|
|
|
nEnd = pRanger->GetRight();
|
|
|
|
nLowDiff = pRanger->GetUpper();
|
|
|
|
nUpDiff = pRanger->GetLower();
|
|
|
|
}
|
|
|
|
nUpper = nTop - nUpDiff;
|
|
|
|
nLower = nBottom + nLowDiff;
|
2011-03-02 10:14:51 +00:00
|
|
|
pLongArr->clear();
|
2000-11-16 15:06:31 +00:00
|
|
|
}
|
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
long SvxBoundArgs::CalcMax( const Point& rPt1, const Point& rPt2,
|
|
|
|
long nRange, long nFarRange )
|
|
|
|
{
|
2000-11-16 15:06:31 +00:00
|
|
|
double nDa = Cut( nRange, rPt1, rPt2 ) - Cut( nFarRange, rPt1, rPt2 );
|
|
|
|
double nB;
|
|
|
|
if( nDa < 0 )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2000-11-16 15:06:31 +00:00
|
|
|
nDa = -nDa;
|
|
|
|
nB = nEnd;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
else
|
2000-11-16 15:06:31 +00:00
|
|
|
nB = nStart;
|
|
|
|
nB *= nB;
|
|
|
|
nB += nDa * nDa;
|
|
|
|
nB = nRange + nDa * ( nFarRange - nRange ) / sqrt( nB );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
BOOL bNote;
|
2000-11-16 15:06:31 +00:00
|
|
|
if( nB < B(rPt2) )
|
|
|
|
bNote = nB > B(rPt1);
|
2000-09-18 16:07:07 +00:00
|
|
|
else
|
2000-11-16 15:06:31 +00:00
|
|
|
bNote = nB < B(rPt1);
|
2000-09-18 16:07:07 +00:00
|
|
|
if( bNote )
|
2000-11-16 15:06:31 +00:00
|
|
|
return( long( nB ) );
|
2000-09-18 16:07:07 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SvxBoundArgs::CheckCut( const Point& rLst, const Point& rNxt )
|
|
|
|
{
|
|
|
|
if( nCut & 1 )
|
|
|
|
NotePoint( Cut( nBottom, rLst, rNxt ) );
|
|
|
|
if( nCut & 2 )
|
|
|
|
NotePoint( Cut( nTop, rLst, rNxt ) );
|
|
|
|
if( rLst.X() != rNxt.X() && rLst.Y() != rNxt.Y() )
|
|
|
|
{
|
|
|
|
long nYps;
|
|
|
|
if( nLowDiff && ( ( nCut & 1 ) || nLast == 1 || nNext == 1 ) )
|
|
|
|
{
|
|
|
|
nYps = CalcMax( rLst, rNxt, nBottom, nLower );
|
|
|
|
if( nYps )
|
|
|
|
_NoteFarPoint( Cut( nYps, rLst, rNxt ), nLower-nYps, nLowDiff );
|
|
|
|
}
|
|
|
|
if( nUpDiff && ( ( nCut & 2 ) || nLast == 2 || nNext == 2 ) )
|
|
|
|
{
|
|
|
|
nYps = CalcMax( rLst, rNxt, nTop, nUpper );
|
|
|
|
if( nYps )
|
|
|
|
_NoteFarPoint( Cut( nYps, rLst, rNxt ), nYps-nUpper, nUpDiff );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-11-16 15:06:31 +00:00
|
|
|
void SvxBoundArgs::_NoteFarPoint( long nPa, long nPbDiff, long nDiff )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2000-11-16 15:06:31 +00:00
|
|
|
long nTmpA;
|
|
|
|
double nQuot = 2 * nDiff - nPbDiff;
|
|
|
|
nQuot *= nPbDiff;
|
|
|
|
nQuot = sqrt( nQuot );
|
|
|
|
nQuot /= nDiff;
|
|
|
|
nTmpA = nPa - long( nStart * nQuot );
|
|
|
|
nPbDiff = nPa + long( nEnd * nQuot );
|
|
|
|
NoteMargin( nTmpA, nPbDiff );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SvxBoundArgs::NoteRange( BOOL bToggle )
|
|
|
|
{
|
|
|
|
DBG_ASSERT( nMax >= nMin || bInner, "NoteRange: Min > Max?");
|
|
|
|
if( nMax < nMin )
|
|
|
|
return;
|
|
|
|
if( !bClosed )
|
|
|
|
bToggle = FALSE;
|
|
|
|
USHORT nIdx = 0;
|
2011-03-02 10:14:51 +00:00
|
|
|
USHORT nCount = pLongArr->size();
|
2011-02-22 12:00:38 +00:00
|
|
|
DBG_ASSERT( nCount == 2 * aBoolArr.size(), "NoteRange: Incompatible Sizes" );
|
2000-09-18 16:07:07 +00:00
|
|
|
while( nIdx < nCount && (*pLongArr)[ nIdx ] < nMin )
|
|
|
|
++nIdx;
|
|
|
|
BOOL bOdd = nIdx % 2 ? TRUE : FALSE;
|
2011-02-16 16:34:02 -05:00
|
|
|
// No overlap with existing intervals?
|
2000-09-18 16:07:07 +00:00
|
|
|
if( nIdx == nCount || ( !bOdd && nMax < (*pLongArr)[ nIdx ] ) )
|
2011-02-16 16:34:02 -05:00
|
|
|
{ // Then a new one is inserted ...
|
2011-03-02 10:14:51 +00:00
|
|
|
pLongArr->insert( pLongArr->begin() + nIdx, nMin );
|
|
|
|
pLongArr->insert( pLongArr->begin() + nIdx + 1, nMax );
|
2011-02-22 12:00:38 +00:00
|
|
|
aBoolArr.insert( aBoolArr.begin() + (nIdx/2), bToggle );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
else
|
2011-02-16 16:34:02 -05:00
|
|
|
{ // expand an existing interval ...
|
2000-09-18 16:07:07 +00:00
|
|
|
USHORT nMaxIdx = nIdx;
|
2011-02-16 16:34:02 -05:00
|
|
|
// If we end up on a left interval boundary, it must be reduced to nMin.
|
2000-09-18 16:07:07 +00:00
|
|
|
if( bOdd )
|
|
|
|
--nIdx;
|
|
|
|
else
|
|
|
|
(*pLongArr)[ nIdx ] = nMin;
|
|
|
|
while( nMaxIdx < nCount && (*pLongArr)[ nMaxIdx ] < nMax )
|
|
|
|
++nMaxIdx;
|
|
|
|
DBG_ASSERT( nMaxIdx > nIdx || nMin == nMax, "NoteRange: Funny Situation." );
|
|
|
|
if( nMaxIdx )
|
|
|
|
--nMaxIdx;
|
|
|
|
if( nMaxIdx < nIdx )
|
|
|
|
nMaxIdx = nIdx;
|
2011-02-16 16:34:02 -05:00
|
|
|
// If we end up on a right interval boundary, it must be raised to nMax.
|
2000-09-18 16:07:07 +00:00
|
|
|
if( nMaxIdx % 2 )
|
|
|
|
(*pLongArr)[ nMaxIdx-- ] = nMax;
|
2011-02-16 16:34:02 -05:00
|
|
|
// Possible merge of intervals.
|
2000-09-18 16:07:07 +00:00
|
|
|
USHORT nDiff = nMaxIdx - nIdx;
|
2011-02-16 16:34:02 -05:00
|
|
|
nMaxIdx = nIdx / 2; // From here on is nMaxIdx the Index in BoolArray.
|
2000-09-18 16:07:07 +00:00
|
|
|
if( nDiff )
|
|
|
|
{
|
2011-03-02 10:14:51 +00:00
|
|
|
pLongArr->erase( pLongArr->begin() + nIdx + 1, pLongArr->begin() + nIdx + 1 + nDiff );
|
2000-09-18 16:07:07 +00:00
|
|
|
nDiff /= 2;
|
|
|
|
USHORT nStop = nMaxIdx + nDiff;
|
|
|
|
for( USHORT i = nMaxIdx; i < nStop; ++i )
|
|
|
|
bToggle ^= aBoolArr[ i ];
|
2011-02-22 12:00:38 +00:00
|
|
|
aBoolArr.erase(aBoolArr.begin() + nMaxIdx, aBoolArr.begin() + nMaxIdx + nDiff);
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
2011-02-22 12:00:38 +00:00
|
|
|
DBG_ASSERT( nMaxIdx < aBoolArr.size(), "NoteRange: Too much deleted" );
|
|
|
|
aBoolArr[ nMaxIdx ] = aBoolArr[ nMaxIdx ] ^ bToggle;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SvxBoundArgs::Calc( const PolyPolygon& rPoly )
|
|
|
|
{
|
|
|
|
USHORT nCount;
|
|
|
|
nAct = 0;
|
|
|
|
for( USHORT i = 0; i < rPoly.Count(); ++i )
|
|
|
|
{
|
|
|
|
const Polygon& rPol = rPoly[ i ];
|
|
|
|
nCount = rPol.GetSize();
|
|
|
|
if( nCount )
|
|
|
|
{
|
|
|
|
const Point& rNull = rPol[ 0 ];
|
|
|
|
SetClosed( IsConcat() || ( rNull == rPol[ nCount - 1 ] ) );
|
|
|
|
nLast = Area( rNull );
|
|
|
|
if( nLast & 12 )
|
|
|
|
{
|
|
|
|
nFirst = 3;
|
|
|
|
if( bMultiple )
|
|
|
|
nAct = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-02-16 16:34:02 -05:00
|
|
|
// The first point of the polygon is within the line.
|
2000-09-18 16:07:07 +00:00
|
|
|
if( nLast )
|
|
|
|
{
|
|
|
|
if( bMultiple || !nAct )
|
|
|
|
{
|
|
|
|
nMin = USHRT_MAX;
|
|
|
|
nMax = 0;
|
|
|
|
}
|
|
|
|
if( nLast & 1 )
|
2000-11-16 15:06:31 +00:00
|
|
|
NoteFarPoint( A(rNull), nLower - B(rNull), nLowDiff );
|
2000-09-18 16:07:07 +00:00
|
|
|
else
|
2000-11-16 15:06:31 +00:00
|
|
|
NoteFarPoint( A(rNull), B(rNull) - nUpper, nUpDiff );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( bMultiple || !nAct )
|
|
|
|
{
|
2000-11-17 08:45:51 +00:00
|
|
|
nMin = A(rNull);
|
|
|
|
nMax = nMin + nEnd;
|
|
|
|
nMin -= nStart;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
else
|
2000-11-16 15:06:31 +00:00
|
|
|
NotePoint( A(rNull) );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
2011-02-16 16:34:02 -05:00
|
|
|
nFirst = 0; // leaving the line in which direction?
|
|
|
|
nAct = 3; // we are within the line at the moment.
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
if( nCount > 1 )
|
|
|
|
{
|
|
|
|
USHORT nIdx = 1;
|
|
|
|
while( TRUE )
|
|
|
|
{
|
|
|
|
const Point& rLast = rPol[ nIdx - 1 ];
|
|
|
|
if( nIdx == nCount )
|
|
|
|
nIdx = 0;
|
|
|
|
const Point& rNext = rPol[ nIdx ];
|
|
|
|
nNext = Area( rNext );
|
|
|
|
nCut = nNext ^ nLast;
|
|
|
|
USHORT nOldAct = nAct;
|
|
|
|
if( nAct )
|
|
|
|
CheckCut( rLast, rNext );
|
|
|
|
if( nCut & 4 )
|
|
|
|
{
|
|
|
|
NoteUpLow( Cut( nLower, rLast, rNext ), 2 );
|
|
|
|
if( nAct && nAct != nOldAct )
|
|
|
|
{
|
|
|
|
nOldAct = nAct;
|
|
|
|
CheckCut( rLast, rNext );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( nCut & 8 )
|
|
|
|
{
|
|
|
|
NoteUpLow( Cut( nUpper, rLast, rNext ), 1 );
|
|
|
|
if( nAct && nAct != nOldAct )
|
|
|
|
CheckCut( rLast, rNext );
|
|
|
|
}
|
|
|
|
if( !nIdx )
|
|
|
|
{
|
|
|
|
if( !( nNext & 12 ) )
|
|
|
|
NoteLast();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if( !( nNext & 12 ) )
|
|
|
|
{
|
|
|
|
if( !nNext )
|
2000-11-16 15:06:31 +00:00
|
|
|
NotePoint( A(rNext) );
|
2000-09-18 16:07:07 +00:00
|
|
|
else if( nNext & 1 )
|
2000-11-16 15:06:31 +00:00
|
|
|
NoteFarPoint( A(rNext), nLower-B(rNext), nLowDiff );
|
2000-09-18 16:07:07 +00:00
|
|
|
else
|
2000-11-16 15:06:31 +00:00
|
|
|
NoteFarPoint( A(rNext), B(rNext)-nUpper, nUpDiff );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
nLast = nNext;
|
|
|
|
if( ++nIdx == nCount && !IsClosed() )
|
|
|
|
{
|
|
|
|
if( !( nNext & 12 ) )
|
|
|
|
NoteLast();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( bMultiple && IsConcat() )
|
|
|
|
{
|
|
|
|
Add();
|
|
|
|
nAct = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( !bMultiple )
|
|
|
|
{
|
|
|
|
DBG_ASSERT( pLongArr->Count() == 0, "I said: Simple!" );
|
|
|
|
if( nAct )
|
|
|
|
{
|
|
|
|
if( bInner )
|
|
|
|
{
|
|
|
|
long nTmpMin, nTmpMax;
|
|
|
|
{
|
2000-11-16 15:06:31 +00:00
|
|
|
nTmpMin = nMin + 2 * nStart;
|
|
|
|
nTmpMax = nMax - 2 * nEnd;
|
2000-09-18 16:07:07 +00:00
|
|
|
if( nTmpMin <= nTmpMax )
|
|
|
|
{
|
2011-03-02 10:14:51 +00:00
|
|
|
pLongArr->push_front(nTmpMax);
|
|
|
|
pLongArr->push_front(nTmpMin);
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-03-02 10:14:51 +00:00
|
|
|
pLongArr->push_front(nMax);
|
|
|
|
pLongArr->push_front(nMin);
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( !IsConcat() )
|
|
|
|
Add();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SvxBoundArgs::Add()
|
|
|
|
{
|
2011-02-22 12:00:38 +00:00
|
|
|
ULONG nLongIdx = 1;
|
|
|
|
ULONG nCount = aBoolArr.size();
|
2000-09-18 16:07:07 +00:00
|
|
|
if( nCount && ( !bInner || !pTextRanger->IsSimple() ) )
|
|
|
|
{
|
|
|
|
BOOL bDelete = aBoolArr[ 0 ];
|
|
|
|
if( bInner )
|
|
|
|
bDelete = !bDelete;
|
2011-02-22 12:00:38 +00:00
|
|
|
for( ULONG nBoolIdx = 1; nBoolIdx < nCount; ++nBoolIdx )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
if( bDelete )
|
|
|
|
{
|
2011-02-22 12:00:38 +00:00
|
|
|
ULONG next = 2;
|
2000-09-18 16:07:07 +00:00
|
|
|
while( nBoolIdx < nCount && !aBoolArr[ nBoolIdx++ ] &&
|
|
|
|
(!bInner || nBoolIdx < nCount ) )
|
2006-10-12 11:40:51 +00:00
|
|
|
next += 2;
|
2011-03-02 10:14:51 +00:00
|
|
|
pLongArr->erase( pLongArr->begin() + nLongIdx, pLongArr->begin() + nLongIdx + next );
|
2006-10-12 11:40:51 +00:00
|
|
|
next /= 2;
|
|
|
|
nBoolIdx = nBoolIdx - next;
|
|
|
|
nCount = nCount - next;
|
2011-02-22 12:00:38 +00:00
|
|
|
aBoolArr.erase( aBoolArr.begin() + nBoolIdx, aBoolArr.begin() + nBoolIdx + next );
|
2000-09-18 16:07:07 +00:00
|
|
|
if( nBoolIdx )
|
|
|
|
aBoolArr[ nBoolIdx - 1 ] = FALSE;
|
2003-04-15 16:30:07 +00:00
|
|
|
#if OSL_DEBUG_LEVEL > 1
|
2000-09-18 16:07:07 +00:00
|
|
|
else
|
2006-10-12 11:40:51 +00:00
|
|
|
++next;
|
2000-09-18 16:07:07 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
bDelete = nBoolIdx < nCount && aBoolArr[ nBoolIdx ];
|
|
|
|
nLongIdx += 2;
|
|
|
|
DBG_ASSERT( nLongIdx == 2*nBoolIdx+1, "BoundArgs: Array-Idx Confusion" );
|
2011-02-22 12:00:38 +00:00
|
|
|
DBG_ASSERT( aBoolArr.size()*2 == pLongArr->Count(),
|
2000-09-18 16:07:07 +00:00
|
|
|
"BoundArgs: Array-Count: Confusion" );
|
|
|
|
}
|
|
|
|
}
|
2011-03-02 10:14:51 +00:00
|
|
|
if( 0 != ( nCount = pLongArr->size() ) )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
if( bInner )
|
|
|
|
{
|
2011-03-02 10:14:51 +00:00
|
|
|
pLongArr->pop_front();
|
|
|
|
pLongArr->pop_back();
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2011-02-16 16:34:02 -05:00
|
|
|
// Here the line is held inside a large rectangle for "simple"
|
|
|
|
// contour wrap. Currently (April 1999) the EditEngine evaluates
|
|
|
|
// only the first rectangle. If it one day is able to output a line
|
|
|
|
// in several parts, it may be advisable to delete the following lines.
|
2011-03-02 10:14:51 +00:00
|
|
|
if( pTextRanger->IsSimple() && pLongArr->size() > 2 )
|
|
|
|
pLongArr->erase( pLongArr->begin() + 1, pLongArr->end() - 1 );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SvxBoundArgs::Concat( const PolyPolygon* pPoly )
|
|
|
|
{
|
|
|
|
SetConcat( TRUE );
|
|
|
|
DBG_ASSERT( pPoly, "Nothing to do?" );
|
2011-03-02 10:14:51 +00:00
|
|
|
LongDqPtr pOld = pLongArr;
|
|
|
|
pLongArr = new std::deque<long>();
|
2011-02-22 12:00:38 +00:00
|
|
|
aBoolArr.clear();
|
2000-09-18 16:07:07 +00:00
|
|
|
bInner = FALSE;
|
2011-03-02 10:14:51 +00:00
|
|
|
Calc( *pPoly ); // Note that this updates pLongArr, which is why we swapped it out earlier.
|
|
|
|
USHORT nCount = pLongArr->size();
|
2000-09-18 16:07:07 +00:00
|
|
|
USHORT nIdx = 0;
|
|
|
|
USHORT i = 0;
|
|
|
|
BOOL bSubtract = pTextRanger->IsInner();
|
|
|
|
while( i < nCount )
|
|
|
|
{
|
2011-03-02 10:14:51 +00:00
|
|
|
ULONG nOldCount = pOld->size();
|
2000-09-18 16:07:07 +00:00
|
|
|
if( nIdx == nOldCount )
|
2011-02-16 16:34:02 -05:00
|
|
|
{ // Reached the end of the old Array...
|
2000-09-18 16:07:07 +00:00
|
|
|
if( !bSubtract )
|
2011-03-02 10:14:51 +00:00
|
|
|
pOld->insert( pOld->begin() + nIdx, pLongArr->begin() + i, pLongArr->end() );
|
2000-09-18 16:07:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
long nLeft = (*pLongArr)[ i++ ];
|
|
|
|
long nRight = (*pLongArr)[ i++ ];
|
|
|
|
USHORT nLeftPos = nIdx + 1;
|
|
|
|
while( nLeftPos < nOldCount && nLeft > (*pOld)[ nLeftPos ] )
|
|
|
|
nLeftPos += 2;
|
|
|
|
if( nLeftPos >= nOldCount )
|
2011-02-16 16:34:02 -05:00
|
|
|
{ // The current interval belongs to the end of the old array ...
|
2000-09-18 16:07:07 +00:00
|
|
|
if( !bSubtract )
|
2011-03-02 10:14:51 +00:00
|
|
|
pOld->insert( pOld->begin() + nOldCount, pLongArr->begin() + i - 2, pLongArr->end() );
|
2000-09-18 16:07:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
USHORT nRightPos = nLeftPos - 1;
|
|
|
|
while( nRightPos < nOldCount && nRight >= (*pOld)[ nRightPos ] )
|
|
|
|
nRightPos += 2;
|
|
|
|
if( nRightPos < nLeftPos )
|
2011-02-16 16:34:02 -05:00
|
|
|
{ // The current interval belongs between two old intervals
|
2000-09-18 16:07:07 +00:00
|
|
|
if( !bSubtract )
|
2011-03-02 10:14:51 +00:00
|
|
|
pOld->insert( pOld->begin() + nRightPos, pLongArr->begin() + i - 2, pLongArr->begin() + i );
|
2000-09-18 16:07:07 +00:00
|
|
|
nIdx = nRightPos + 2;
|
|
|
|
}
|
2011-02-16 16:34:02 -05:00
|
|
|
else if( bSubtract ) // Subtract, if necessary separate
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
long nOld;
|
|
|
|
if( nLeft > ( nOld = (*pOld)[ nLeftPos - 1 ] ) )
|
2011-02-16 16:34:02 -05:00
|
|
|
{ // Now we split the left part...
|
2000-09-18 16:07:07 +00:00
|
|
|
if( nLeft - 1 > nOld )
|
|
|
|
{
|
2011-03-02 10:14:51 +00:00
|
|
|
pOld->insert( pOld->begin() + nLeftPos - 1, nOld );
|
|
|
|
pOld->insert( pOld->begin() + nLeftPos, nLeft - 1 );
|
2000-09-18 16:07:07 +00:00
|
|
|
nLeftPos += 2;
|
|
|
|
nRightPos += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( nRightPos - nLeftPos > 1 )
|
2011-03-02 10:14:51 +00:00
|
|
|
pOld->erase( pOld->begin() + nLeftPos, pOld->begin() + nRightPos - 1 );
|
2000-09-18 16:07:07 +00:00
|
|
|
if( ++nRight >= ( nOld = (*pOld)[ nLeftPos ] ) )
|
2011-03-02 10:14:51 +00:00
|
|
|
pOld->erase( pOld->begin() + nLeftPos - 1, pOld->begin() + nLeftPos + 1 );
|
2000-09-18 16:07:07 +00:00
|
|
|
else
|
|
|
|
(*pOld)[ nLeftPos - 1 ] = nRight;
|
|
|
|
}
|
2011-02-16 16:34:02 -05:00
|
|
|
else // Merge
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
if( nLeft < (*pOld)[ nLeftPos - 1 ] )
|
|
|
|
(*pOld)[ nLeftPos - 1 ] = nLeft;
|
|
|
|
if( nRight > (*pOld)[ nRightPos - 1 ] )
|
|
|
|
(*pOld)[ nRightPos - 1 ] = nRight;
|
|
|
|
if( nRightPos - nLeftPos > 1 )
|
2011-03-02 10:14:51 +00:00
|
|
|
pOld->erase( pOld->begin() + nLeftPos, pOld->begin() + nRightPos - 1 );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
nIdx = nLeftPos - 1;
|
|
|
|
}
|
|
|
|
delete pLongArr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2011-02-16 16:34:02 -05:00
|
|
|
* SvxBoundArgs::Area returns the area in which the point is located.
|
|
|
|
* 0 = within the line
|
|
|
|
* 1 = below, but within the upper edge
|
|
|
|
* 2 = above, but within the lower edge
|
|
|
|
* 5 = below the upper edge
|
|
|
|
*10 = above the lower edge
|
2000-09-18 16:07:07 +00:00
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
USHORT SvxBoundArgs::Area( const Point& rPt )
|
|
|
|
{
|
2000-11-16 15:06:31 +00:00
|
|
|
long nB = B( rPt );
|
|
|
|
if( nB >= nBottom )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2000-11-16 15:06:31 +00:00
|
|
|
if( nB >= nLower )
|
2000-09-18 16:07:07 +00:00
|
|
|
return 5;
|
|
|
|
return 1;
|
|
|
|
}
|
2000-11-16 15:06:31 +00:00
|
|
|
if( nB <= nTop )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2000-11-16 15:06:31 +00:00
|
|
|
if( nB <= nUpper )
|
2000-09-18 16:07:07 +00:00
|
|
|
return 10;
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2011-02-16 16:34:02 -05:00
|
|
|
* lcl_Cut calculates the X-Coordinate of the distance (Pt1-Pt2) at the
|
|
|
|
* Y-Coordinate nY.
|
|
|
|
* It is assumed that the one of the points are located above and the other
|
|
|
|
* one below the Y-Coordinate.
|
2000-09-18 16:07:07 +00:00
|
|
|
*************************************************************************/
|
|
|
|
|
2000-11-16 15:06:31 +00:00
|
|
|
long SvxBoundArgs::Cut( long nB, const Point& rPt1, const Point& rPt2 )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2000-11-16 15:06:31 +00:00
|
|
|
if( pTextRanger->IsVertical() )
|
|
|
|
{
|
|
|
|
double nQuot = nB - rPt1.X();
|
|
|
|
nQuot /= ( rPt2.X() - rPt1.X() );
|
|
|
|
nQuot *= ( rPt2.Y() - rPt1.Y() );
|
|
|
|
return long( rPt1.Y() + nQuot );
|
|
|
|
}
|
|
|
|
double nQuot = nB - rPt1.Y();
|
2000-09-18 16:07:07 +00:00
|
|
|
nQuot /= ( rPt2.Y() - rPt1.Y() );
|
|
|
|
nQuot *= ( rPt2.X() - rPt1.X() );
|
|
|
|
return long( rPt1.X() + nQuot );
|
|
|
|
}
|
|
|
|
|
2000-11-16 15:06:31 +00:00
|
|
|
void SvxBoundArgs::NoteUpLow( long nA, const BYTE nArea )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
if( nAct )
|
|
|
|
{
|
2000-11-16 15:06:31 +00:00
|
|
|
NoteMargin( nA, nA );
|
2000-09-18 16:07:07 +00:00
|
|
|
if( bMultiple )
|
|
|
|
{
|
|
|
|
NoteRange( nArea != nAct );
|
|
|
|
nAct = 0;
|
|
|
|
}
|
|
|
|
if( !nFirst )
|
|
|
|
nFirst = nArea;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nAct = nArea;
|
2000-11-16 15:06:31 +00:00
|
|
|
nMin = nA;
|
|
|
|
nMax = nA;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-02 10:14:51 +00:00
|
|
|
LongDqPtr TextRanger::GetTextRanges( const Range& rRange )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
DBG_ASSERT( rRange.Min() || rRange.Max(), "Zero-Range not allowed, Bye Bye" );
|
2011-03-02 10:14:51 +00:00
|
|
|
//Can we find the result we need in the cache?
|
|
|
|
for (std::deque<RangeCache>::iterator it = mRangeCache.begin(); it < mRangeCache.end(); ++it)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2011-03-02 10:14:51 +00:00
|
|
|
if (it->range == rRange)
|
|
|
|
return &(it->results);
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
2011-03-02 10:14:51 +00:00
|
|
|
//Calculate a new result
|
|
|
|
RangeCache rngCache(rRange);
|
|
|
|
SvxBoundArgs aArg( this, &(rngCache.results), rRange );
|
|
|
|
aArg.Calc( *mpPolyPolygon );
|
|
|
|
if( mpLinePolyPolygon )
|
|
|
|
aArg.Concat( mpLinePolyPolygon );
|
|
|
|
//Add new result to the cache
|
|
|
|
mRangeCache.push_back(rngCache);
|
|
|
|
if (mRangeCache.size() > nCacheSize)
|
|
|
|
mRangeCache.pop_front();
|
|
|
|
return &(mRangeCache.back().results);
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const Rectangle& TextRanger::_GetBoundRect()
|
|
|
|
{
|
|
|
|
DBG_ASSERT( 0 == pBound, "Don't call twice." );
|
2006-11-14 12:17:43 +00:00
|
|
|
pBound = new Rectangle( mpPolyPolygon->GetBoundRect() );
|
2000-09-18 16:07:07 +00:00
|
|
|
return *pBound;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-12 15:53:47 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|