1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_editeng.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <editeng/txtrange.hxx> 32*cdf0e10cSrcweir #include <math.h> 33*cdf0e10cSrcweir #include <tools/poly.hxx> 34*cdf0e10cSrcweir #include <tools/debug.hxx> 35*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx> 36*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir /************************************************************************* 39*cdf0e10cSrcweir |* 40*cdf0e10cSrcweir |* TextRanger::TextRanger() 41*cdf0e10cSrcweir |* 42*cdf0e10cSrcweir |* Beschreibung 43*cdf0e10cSrcweir |* Ersterstellung 20.01.97 44*cdf0e10cSrcweir |* Letzte Aenderung 20.01.97 AMA 45*cdf0e10cSrcweir |* 46*cdf0e10cSrcweir *************************************************************************/ 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir TextRanger::TextRanger( const basegfx::B2DPolyPolygon& rPolyPolygon, const basegfx::B2DPolyPolygon* pLinePolyPolygon, 49*cdf0e10cSrcweir sal_uInt16 nCacheSz, sal_uInt16 nLft, sal_uInt16 nRght, sal_Bool bSimpl, sal_Bool bInnr, 50*cdf0e10cSrcweir sal_Bool bVert ) : 51*cdf0e10cSrcweir pBound( NULL ), 52*cdf0e10cSrcweir nCacheSize( nCacheSz ), 53*cdf0e10cSrcweir nCacheIdx( 0 ), 54*cdf0e10cSrcweir nRight( nRght ), 55*cdf0e10cSrcweir nLeft( nLft ), 56*cdf0e10cSrcweir nUpper( 0 ), 57*cdf0e10cSrcweir nLower( 0 ), 58*cdf0e10cSrcweir nPointCount( 0 ), 59*cdf0e10cSrcweir bSimple( bSimpl ), 60*cdf0e10cSrcweir bInner( bInnr ), 61*cdf0e10cSrcweir bVertical( bVert ) 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir #ifdef DBG_UTIL 64*cdf0e10cSrcweir bFlag3 = bFlag4 = bFlag5 = bFlag6 = bFlag7 = sal_False; 65*cdf0e10cSrcweir #endif 66*cdf0e10cSrcweir pRangeArr = new Range[ nCacheSize ]; 67*cdf0e10cSrcweir pCache = new SvLongsPtr[ nCacheSize ]; 68*cdf0e10cSrcweir memset( pRangeArr, 0, nCacheSize * sizeof( Range ) ); 69*cdf0e10cSrcweir memset( pCache, 0, nCacheSize * sizeof( SvLongsPtr ) ); 70*cdf0e10cSrcweir sal_uInt32 nCount(rPolyPolygon.count()); 71*cdf0e10cSrcweir mpPolyPolygon = new PolyPolygon( (sal_uInt16)nCount ); 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir for(sal_uInt32 i(0L); i < nCount; i++) 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir const basegfx::B2DPolygon aCandidate(rPolyPolygon.getB2DPolygon(i).getDefaultAdaptiveSubdivision()); 76*cdf0e10cSrcweir nPointCount += aCandidate.count(); 77*cdf0e10cSrcweir mpPolyPolygon->Insert( Polygon(aCandidate), (sal_uInt16)i ); 78*cdf0e10cSrcweir } 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir if( pLinePolyPolygon ) 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir nCount = pLinePolyPolygon->count(); 83*cdf0e10cSrcweir mpLinePolyPolygon = new PolyPolygon(); 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir for(sal_uInt32 i(0L); i < nCount; i++) 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir const basegfx::B2DPolygon aCandidate(pLinePolyPolygon->getB2DPolygon(i).getDefaultAdaptiveSubdivision()); 88*cdf0e10cSrcweir nPointCount += aCandidate.count(); 89*cdf0e10cSrcweir mpLinePolyPolygon->Insert( Polygon(aCandidate), (sal_uInt16)i ); 90*cdf0e10cSrcweir } 91*cdf0e10cSrcweir } 92*cdf0e10cSrcweir else 93*cdf0e10cSrcweir mpLinePolyPolygon = NULL; 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir /************************************************************************* 97*cdf0e10cSrcweir |* 98*cdf0e10cSrcweir |* TextRanger::~TextRanger() 99*cdf0e10cSrcweir |* 100*cdf0e10cSrcweir |* Beschreibung 101*cdf0e10cSrcweir |* Ersterstellung 20.01.97 102*cdf0e10cSrcweir |* Letzte Aenderung 20.01.97 AMA 103*cdf0e10cSrcweir |* 104*cdf0e10cSrcweir *************************************************************************/ 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir TextRanger::~TextRanger() 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir for( sal_uInt16 i = 0; i < nCacheSize; ++i ) 109*cdf0e10cSrcweir delete pCache[i]; 110*cdf0e10cSrcweir delete[] pCache; 111*cdf0e10cSrcweir delete[] pRangeArr; 112*cdf0e10cSrcweir delete mpPolyPolygon; 113*cdf0e10cSrcweir delete mpLinePolyPolygon; 114*cdf0e10cSrcweir } 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir /*-----------------17.11.00 09:49------------------- 117*cdf0e10cSrcweir * TextRanger::SetVertical(..) 118*cdf0e10cSrcweir * If there's is a change in the writing direction, 119*cdf0e10cSrcweir * the cache has to be cleared. 120*cdf0e10cSrcweir * --------------------------------------------------*/ 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir void TextRanger::SetVertical( sal_Bool bNew ) 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir if( IsVertical() != bNew ) 125*cdf0e10cSrcweir { 126*cdf0e10cSrcweir bVertical = bNew; 127*cdf0e10cSrcweir for( sal_uInt16 i = 0; i < nCacheSize; ++i ) 128*cdf0e10cSrcweir delete pCache[i]; 129*cdf0e10cSrcweir memset( pRangeArr, 0, nCacheSize * sizeof( Range ) ); 130*cdf0e10cSrcweir memset( pCache, 0, nCacheSize * sizeof( SvLongsPtr ) ); 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir /************************************************************************* 135*cdf0e10cSrcweir |* 136*cdf0e10cSrcweir |* SvxBoundArgs 137*cdf0e10cSrcweir |* 138*cdf0e10cSrcweir |* Beschreibung 139*cdf0e10cSrcweir |* Ersterstellung 20.01.97 140*cdf0e10cSrcweir |* Letzte Aenderung 20.01.97 AMA 141*cdf0e10cSrcweir |* 142*cdf0e10cSrcweir *************************************************************************/ 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir class SvxBoundArgs 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir SvBools aBoolArr; 147*cdf0e10cSrcweir SvLongs *pLongArr; 148*cdf0e10cSrcweir TextRanger *pTextRanger; 149*cdf0e10cSrcweir long nMin; 150*cdf0e10cSrcweir long nMax; 151*cdf0e10cSrcweir long nTop; 152*cdf0e10cSrcweir long nBottom; 153*cdf0e10cSrcweir long nUpDiff; 154*cdf0e10cSrcweir long nLowDiff; 155*cdf0e10cSrcweir long nUpper; 156*cdf0e10cSrcweir long nLower; 157*cdf0e10cSrcweir long nStart; 158*cdf0e10cSrcweir long nEnd; 159*cdf0e10cSrcweir sal_uInt16 nCut; 160*cdf0e10cSrcweir sal_uInt16 nLast; 161*cdf0e10cSrcweir sal_uInt16 nNext; 162*cdf0e10cSrcweir sal_uInt8 nAct; 163*cdf0e10cSrcweir sal_uInt8 nFirst; 164*cdf0e10cSrcweir sal_Bool bClosed : 1; 165*cdf0e10cSrcweir sal_Bool bInner : 1; 166*cdf0e10cSrcweir sal_Bool bMultiple : 1; 167*cdf0e10cSrcweir sal_Bool bConcat : 1; 168*cdf0e10cSrcweir sal_Bool bRotate : 1; 169*cdf0e10cSrcweir void NoteRange( sal_Bool bToggle ); 170*cdf0e10cSrcweir long Cut( long nY, const Point& rPt1, const Point& rPt2 ); 171*cdf0e10cSrcweir void Add(); 172*cdf0e10cSrcweir void _NoteFarPoint( long nPx, long nPyDiff, long nDiff ); 173*cdf0e10cSrcweir void NoteFarPoint( long nPx, long nPyDiff, long nDiff ) 174*cdf0e10cSrcweir { if( nDiff ) _NoteFarPoint( nPx, nPyDiff, nDiff ); } 175*cdf0e10cSrcweir long CalcMax( const Point& rPt1, const Point& rPt2, long nRange, long nFar ); 176*cdf0e10cSrcweir void CheckCut( const Point& rLst, const Point& rNxt ); 177*cdf0e10cSrcweir inline long A( const Point& rP ) const { return bRotate ? rP.Y() : rP.X(); } 178*cdf0e10cSrcweir inline long B( const Point& rP ) const { return bRotate ? rP.X() : rP.Y(); } 179*cdf0e10cSrcweir public: 180*cdf0e10cSrcweir SvxBoundArgs( TextRanger* pRanger, SvLongs *pLong, const Range& rRange ); 181*cdf0e10cSrcweir void NotePoint( const long nA ) { NoteMargin( nA - nStart, nA + nEnd ); } 182*cdf0e10cSrcweir void NoteMargin( const long nL, const long nR ) 183*cdf0e10cSrcweir { if( nMin > nL ) nMin = nL; if( nMax < nR ) nMax = nR; } 184*cdf0e10cSrcweir sal_uInt16 Area( const Point& rPt ); 185*cdf0e10cSrcweir void NoteUpLow( long nA, const sal_uInt8 nArea ); 186*cdf0e10cSrcweir void Calc( const PolyPolygon& rPoly ); 187*cdf0e10cSrcweir void Concat( const PolyPolygon* pPoly ); 188*cdf0e10cSrcweir // inlines 189*cdf0e10cSrcweir void NoteLast() { if( bMultiple ) NoteRange( nAct == nFirst ); } 190*cdf0e10cSrcweir void SetClosed( const sal_Bool bNew ){ bClosed = bNew; } 191*cdf0e10cSrcweir sal_Bool IsClosed() const { return bClosed; } 192*cdf0e10cSrcweir void SetConcat( const sal_Bool bNew ){ bConcat = bNew; } 193*cdf0e10cSrcweir sal_Bool IsConcat() const { return bConcat; } 194*cdf0e10cSrcweir sal_uInt8 GetAct() const { return nAct; } 195*cdf0e10cSrcweir }; 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir SvxBoundArgs::SvxBoundArgs( TextRanger* pRanger, SvLongs *pLong, 198*cdf0e10cSrcweir const Range& rRange ) 199*cdf0e10cSrcweir : pLongArr( pLong ), pTextRanger( pRanger ), 200*cdf0e10cSrcweir nTop( rRange.Min() ), nBottom( rRange.Max() ), 201*cdf0e10cSrcweir bInner( pRanger->IsInner() ), bMultiple( bInner || !pRanger->IsSimple() ), 202*cdf0e10cSrcweir bConcat( sal_False ), bRotate( pRanger->IsVertical() ) 203*cdf0e10cSrcweir { 204*cdf0e10cSrcweir if( bRotate ) 205*cdf0e10cSrcweir { 206*cdf0e10cSrcweir nStart = pRanger->GetUpper(); 207*cdf0e10cSrcweir nEnd = pRanger->GetLower(); 208*cdf0e10cSrcweir nLowDiff = pRanger->GetLeft(); 209*cdf0e10cSrcweir nUpDiff = pRanger->GetRight(); 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir else 212*cdf0e10cSrcweir { 213*cdf0e10cSrcweir nStart = pRanger->GetLeft(); 214*cdf0e10cSrcweir nEnd = pRanger->GetRight(); 215*cdf0e10cSrcweir nLowDiff = pRanger->GetUpper(); 216*cdf0e10cSrcweir nUpDiff = pRanger->GetLower(); 217*cdf0e10cSrcweir } 218*cdf0e10cSrcweir nUpper = nTop - nUpDiff; 219*cdf0e10cSrcweir nLower = nBottom + nLowDiff; 220*cdf0e10cSrcweir pLongArr->Remove( 0, pLongArr->Count() ); 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir long SvxBoundArgs::CalcMax( const Point& rPt1, const Point& rPt2, 224*cdf0e10cSrcweir long nRange, long nFarRange ) 225*cdf0e10cSrcweir { 226*cdf0e10cSrcweir double nDa = Cut( nRange, rPt1, rPt2 ) - Cut( nFarRange, rPt1, rPt2 ); 227*cdf0e10cSrcweir double nB; 228*cdf0e10cSrcweir if( nDa < 0 ) 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir nDa = -nDa; 231*cdf0e10cSrcweir nB = nEnd; 232*cdf0e10cSrcweir } 233*cdf0e10cSrcweir else 234*cdf0e10cSrcweir nB = nStart; 235*cdf0e10cSrcweir nB *= nB; 236*cdf0e10cSrcweir nB += nDa * nDa; 237*cdf0e10cSrcweir nB = nRange + nDa * ( nFarRange - nRange ) / sqrt( nB ); 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir sal_Bool bNote; 240*cdf0e10cSrcweir if( nB < B(rPt2) ) 241*cdf0e10cSrcweir bNote = nB > B(rPt1); 242*cdf0e10cSrcweir else 243*cdf0e10cSrcweir bNote = nB < B(rPt1); 244*cdf0e10cSrcweir if( bNote ) 245*cdf0e10cSrcweir return( long( nB ) ); 246*cdf0e10cSrcweir return 0; 247*cdf0e10cSrcweir } 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir void SvxBoundArgs::CheckCut( const Point& rLst, const Point& rNxt ) 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir if( nCut & 1 ) 252*cdf0e10cSrcweir NotePoint( Cut( nBottom, rLst, rNxt ) ); 253*cdf0e10cSrcweir if( nCut & 2 ) 254*cdf0e10cSrcweir NotePoint( Cut( nTop, rLst, rNxt ) ); 255*cdf0e10cSrcweir if( rLst.X() != rNxt.X() && rLst.Y() != rNxt.Y() ) 256*cdf0e10cSrcweir { 257*cdf0e10cSrcweir long nYps; 258*cdf0e10cSrcweir if( nLowDiff && ( ( nCut & 1 ) || nLast == 1 || nNext == 1 ) ) 259*cdf0e10cSrcweir { 260*cdf0e10cSrcweir nYps = CalcMax( rLst, rNxt, nBottom, nLower ); 261*cdf0e10cSrcweir if( nYps ) 262*cdf0e10cSrcweir _NoteFarPoint( Cut( nYps, rLst, rNxt ), nLower-nYps, nLowDiff ); 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir if( nUpDiff && ( ( nCut & 2 ) || nLast == 2 || nNext == 2 ) ) 265*cdf0e10cSrcweir { 266*cdf0e10cSrcweir nYps = CalcMax( rLst, rNxt, nTop, nUpper ); 267*cdf0e10cSrcweir if( nYps ) 268*cdf0e10cSrcweir _NoteFarPoint( Cut( nYps, rLst, rNxt ), nYps-nUpper, nUpDiff ); 269*cdf0e10cSrcweir } 270*cdf0e10cSrcweir } 271*cdf0e10cSrcweir } 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir void SvxBoundArgs::_NoteFarPoint( long nPa, long nPbDiff, long nDiff ) 274*cdf0e10cSrcweir { 275*cdf0e10cSrcweir long nTmpA; 276*cdf0e10cSrcweir double nQuot = 2 * nDiff - nPbDiff; 277*cdf0e10cSrcweir nQuot *= nPbDiff; 278*cdf0e10cSrcweir nQuot = sqrt( nQuot ); 279*cdf0e10cSrcweir nQuot /= nDiff; 280*cdf0e10cSrcweir nTmpA = nPa - long( nStart * nQuot ); 281*cdf0e10cSrcweir nPbDiff = nPa + long( nEnd * nQuot ); 282*cdf0e10cSrcweir NoteMargin( nTmpA, nPbDiff ); 283*cdf0e10cSrcweir } 284*cdf0e10cSrcweir 285*cdf0e10cSrcweir void SvxBoundArgs::NoteRange( sal_Bool bToggle ) 286*cdf0e10cSrcweir { 287*cdf0e10cSrcweir DBG_ASSERT( nMax >= nMin || bInner, "NoteRange: Min > Max?"); 288*cdf0e10cSrcweir if( nMax < nMin ) 289*cdf0e10cSrcweir return; 290*cdf0e10cSrcweir if( !bClosed ) 291*cdf0e10cSrcweir bToggle = sal_False; 292*cdf0e10cSrcweir sal_uInt16 nIdx = 0; 293*cdf0e10cSrcweir sal_uInt16 nCount = pLongArr->Count(); 294*cdf0e10cSrcweir DBG_ASSERT( nCount == 2 * aBoolArr.size(), "NoteRange: Incompatible Sizes" ); 295*cdf0e10cSrcweir while( nIdx < nCount && (*pLongArr)[ nIdx ] < nMin ) 296*cdf0e10cSrcweir ++nIdx; 297*cdf0e10cSrcweir sal_Bool bOdd = nIdx % 2 ? sal_True : sal_False; 298*cdf0e10cSrcweir // Kein Ueberlappung mit vorhandenen Intervallen? 299*cdf0e10cSrcweir if( nIdx == nCount || ( !bOdd && nMax < (*pLongArr)[ nIdx ] ) ) 300*cdf0e10cSrcweir { // Dann wird ein neues eingefuegt ... 301*cdf0e10cSrcweir pLongArr->Insert( nMin, nIdx ); 302*cdf0e10cSrcweir pLongArr->Insert( nMax, nIdx + 1 ); 303*cdf0e10cSrcweir aBoolArr.insert( aBoolArr.begin() + nIdx / 2, bToggle ); 304*cdf0e10cSrcweir } 305*cdf0e10cSrcweir else 306*cdf0e10cSrcweir { // ein vorhandes Intervall erweitern ... 307*cdf0e10cSrcweir sal_uInt16 nMaxIdx = nIdx; 308*cdf0e10cSrcweir // Wenn wir auf einer linken Intervallgrenze gelandet sind, muss diese 309*cdf0e10cSrcweir // auf nMin gesenkt werden. 310*cdf0e10cSrcweir if( bOdd ) 311*cdf0e10cSrcweir --nIdx; 312*cdf0e10cSrcweir else 313*cdf0e10cSrcweir (*pLongArr)[ nIdx ] = nMin; 314*cdf0e10cSrcweir while( nMaxIdx < nCount && (*pLongArr)[ nMaxIdx ] < nMax ) 315*cdf0e10cSrcweir ++nMaxIdx; 316*cdf0e10cSrcweir DBG_ASSERT( nMaxIdx > nIdx || nMin == nMax, "NoteRange: Funny Situation." ); 317*cdf0e10cSrcweir if( nMaxIdx ) 318*cdf0e10cSrcweir --nMaxIdx; 319*cdf0e10cSrcweir if( nMaxIdx < nIdx ) 320*cdf0e10cSrcweir nMaxIdx = nIdx; 321*cdf0e10cSrcweir // Wenn wir auf einer rechten Intervallgrenze landen, muss diese 322*cdf0e10cSrcweir // auf nMax angehoben werden. 323*cdf0e10cSrcweir if( nMaxIdx % 2 ) 324*cdf0e10cSrcweir (*pLongArr)[ nMaxIdx-- ] = nMax; 325*cdf0e10cSrcweir // Jetzt werden eventuell noch Intervalle verschmolzen 326*cdf0e10cSrcweir sal_uInt16 nDiff = nMaxIdx - nIdx; 327*cdf0e10cSrcweir nMaxIdx = nIdx / 2; // Ab hier ist nMaxIdx der Index im BoolArray. 328*cdf0e10cSrcweir if( nDiff ) 329*cdf0e10cSrcweir { 330*cdf0e10cSrcweir (*pLongArr).Remove( nIdx + 1, nDiff ); 331*cdf0e10cSrcweir nDiff /= 2; 332*cdf0e10cSrcweir sal_uInt16 nStop = nMaxIdx + nDiff; 333*cdf0e10cSrcweir for( sal_uInt16 i = nMaxIdx; i < nStop; ++i ) 334*cdf0e10cSrcweir bToggle ^= aBoolArr[ i ]; 335*cdf0e10cSrcweir aBoolArr.erase( aBoolArr.begin() + nMaxIdx, aBoolArr.begin() + (nMaxIdx + nDiff) ); 336*cdf0e10cSrcweir } 337*cdf0e10cSrcweir DBG_ASSERT( nMaxIdx < aBoolArr.size(), "NoteRange: Too much deleted" ); 338*cdf0e10cSrcweir aBoolArr[ nMaxIdx ] ^= bToggle; 339*cdf0e10cSrcweir } 340*cdf0e10cSrcweir } 341*cdf0e10cSrcweir 342*cdf0e10cSrcweir void SvxBoundArgs::Calc( const PolyPolygon& rPoly ) 343*cdf0e10cSrcweir { 344*cdf0e10cSrcweir sal_uInt16 nCount; 345*cdf0e10cSrcweir nAct = 0; 346*cdf0e10cSrcweir for( sal_uInt16 i = 0; i < rPoly.Count(); ++i ) 347*cdf0e10cSrcweir { 348*cdf0e10cSrcweir const Polygon& rPol = rPoly[ i ]; 349*cdf0e10cSrcweir nCount = rPol.GetSize(); 350*cdf0e10cSrcweir if( nCount ) 351*cdf0e10cSrcweir { 352*cdf0e10cSrcweir const Point& rNull = rPol[ 0 ]; 353*cdf0e10cSrcweir SetClosed( IsConcat() || ( rNull == rPol[ nCount - 1 ] ) ); 354*cdf0e10cSrcweir nLast = Area( rNull ); 355*cdf0e10cSrcweir if( nLast & 12 ) 356*cdf0e10cSrcweir { 357*cdf0e10cSrcweir nFirst = 3; 358*cdf0e10cSrcweir if( bMultiple ) 359*cdf0e10cSrcweir nAct = 0; 360*cdf0e10cSrcweir } 361*cdf0e10cSrcweir else 362*cdf0e10cSrcweir { 363*cdf0e10cSrcweir // Der erste Punkt des Polygons liegt innerhalb der Zeile. 364*cdf0e10cSrcweir if( nLast ) 365*cdf0e10cSrcweir { 366*cdf0e10cSrcweir if( bMultiple || !nAct ) 367*cdf0e10cSrcweir { 368*cdf0e10cSrcweir nMin = USHRT_MAX; 369*cdf0e10cSrcweir nMax = 0; 370*cdf0e10cSrcweir } 371*cdf0e10cSrcweir if( nLast & 1 ) 372*cdf0e10cSrcweir NoteFarPoint( A(rNull), nLower - B(rNull), nLowDiff ); 373*cdf0e10cSrcweir else 374*cdf0e10cSrcweir NoteFarPoint( A(rNull), B(rNull) - nUpper, nUpDiff ); 375*cdf0e10cSrcweir } 376*cdf0e10cSrcweir else 377*cdf0e10cSrcweir { 378*cdf0e10cSrcweir if( bMultiple || !nAct ) 379*cdf0e10cSrcweir { 380*cdf0e10cSrcweir nMin = A(rNull); 381*cdf0e10cSrcweir nMax = nMin + nEnd; 382*cdf0e10cSrcweir nMin -= nStart; 383*cdf0e10cSrcweir } 384*cdf0e10cSrcweir else 385*cdf0e10cSrcweir NotePoint( A(rNull) ); 386*cdf0e10cSrcweir } 387*cdf0e10cSrcweir nFirst = 0; // In welcher Richtung wird die Zeile verlassen? 388*cdf0e10cSrcweir nAct = 3; // Wir sind z.Z. innerhalb der Zeile. 389*cdf0e10cSrcweir } 390*cdf0e10cSrcweir if( nCount > 1 ) 391*cdf0e10cSrcweir { 392*cdf0e10cSrcweir sal_uInt16 nIdx = 1; 393*cdf0e10cSrcweir while( sal_True ) 394*cdf0e10cSrcweir { 395*cdf0e10cSrcweir const Point& rLast = rPol[ nIdx - 1 ]; 396*cdf0e10cSrcweir if( nIdx == nCount ) 397*cdf0e10cSrcweir nIdx = 0; 398*cdf0e10cSrcweir const Point& rNext = rPol[ nIdx ]; 399*cdf0e10cSrcweir nNext = Area( rNext ); 400*cdf0e10cSrcweir nCut = nNext ^ nLast; 401*cdf0e10cSrcweir sal_uInt16 nOldAct = nAct; 402*cdf0e10cSrcweir if( nAct ) 403*cdf0e10cSrcweir CheckCut( rLast, rNext ); 404*cdf0e10cSrcweir if( nCut & 4 ) 405*cdf0e10cSrcweir { 406*cdf0e10cSrcweir NoteUpLow( Cut( nLower, rLast, rNext ), 2 ); 407*cdf0e10cSrcweir if( nAct && nAct != nOldAct ) 408*cdf0e10cSrcweir { 409*cdf0e10cSrcweir nOldAct = nAct; 410*cdf0e10cSrcweir CheckCut( rLast, rNext ); 411*cdf0e10cSrcweir } 412*cdf0e10cSrcweir } 413*cdf0e10cSrcweir if( nCut & 8 ) 414*cdf0e10cSrcweir { 415*cdf0e10cSrcweir NoteUpLow( Cut( nUpper, rLast, rNext ), 1 ); 416*cdf0e10cSrcweir if( nAct && nAct != nOldAct ) 417*cdf0e10cSrcweir CheckCut( rLast, rNext ); 418*cdf0e10cSrcweir } 419*cdf0e10cSrcweir if( !nIdx ) 420*cdf0e10cSrcweir { 421*cdf0e10cSrcweir if( !( nNext & 12 ) ) 422*cdf0e10cSrcweir NoteLast(); 423*cdf0e10cSrcweir break; 424*cdf0e10cSrcweir } 425*cdf0e10cSrcweir if( !( nNext & 12 ) ) 426*cdf0e10cSrcweir { 427*cdf0e10cSrcweir if( !nNext ) 428*cdf0e10cSrcweir NotePoint( A(rNext) ); 429*cdf0e10cSrcweir else if( nNext & 1 ) 430*cdf0e10cSrcweir NoteFarPoint( A(rNext), nLower-B(rNext), nLowDiff ); 431*cdf0e10cSrcweir else 432*cdf0e10cSrcweir NoteFarPoint( A(rNext), B(rNext)-nUpper, nUpDiff ); 433*cdf0e10cSrcweir } 434*cdf0e10cSrcweir nLast = nNext; 435*cdf0e10cSrcweir if( ++nIdx == nCount && !IsClosed() ) 436*cdf0e10cSrcweir { 437*cdf0e10cSrcweir if( !( nNext & 12 ) ) 438*cdf0e10cSrcweir NoteLast(); 439*cdf0e10cSrcweir break; 440*cdf0e10cSrcweir } 441*cdf0e10cSrcweir } 442*cdf0e10cSrcweir } 443*cdf0e10cSrcweir if( bMultiple && IsConcat() ) 444*cdf0e10cSrcweir { 445*cdf0e10cSrcweir Add(); 446*cdf0e10cSrcweir nAct = 0; 447*cdf0e10cSrcweir } 448*cdf0e10cSrcweir } 449*cdf0e10cSrcweir } 450*cdf0e10cSrcweir if( !bMultiple ) 451*cdf0e10cSrcweir { 452*cdf0e10cSrcweir DBG_ASSERT( pLongArr->Count() == 0, "I said: Simple!" ); 453*cdf0e10cSrcweir if( nAct ) 454*cdf0e10cSrcweir { 455*cdf0e10cSrcweir if( bInner ) 456*cdf0e10cSrcweir { 457*cdf0e10cSrcweir long nTmpMin, nTmpMax; 458*cdf0e10cSrcweir { 459*cdf0e10cSrcweir nTmpMin = nMin + 2 * nStart; 460*cdf0e10cSrcweir nTmpMax = nMax - 2 * nEnd; 461*cdf0e10cSrcweir if( nTmpMin <= nTmpMax ) 462*cdf0e10cSrcweir { 463*cdf0e10cSrcweir pLongArr->Insert( nTmpMin, 0 ); 464*cdf0e10cSrcweir pLongArr->Insert( nTmpMax, 1 ); 465*cdf0e10cSrcweir } 466*cdf0e10cSrcweir } 467*cdf0e10cSrcweir } 468*cdf0e10cSrcweir else 469*cdf0e10cSrcweir { 470*cdf0e10cSrcweir pLongArr->Insert( nMin, 0 ); 471*cdf0e10cSrcweir pLongArr->Insert( nMax, 1 ); 472*cdf0e10cSrcweir } 473*cdf0e10cSrcweir } 474*cdf0e10cSrcweir } 475*cdf0e10cSrcweir else if( !IsConcat() ) 476*cdf0e10cSrcweir Add(); 477*cdf0e10cSrcweir } 478*cdf0e10cSrcweir 479*cdf0e10cSrcweir void SvxBoundArgs::Add() 480*cdf0e10cSrcweir { 481*cdf0e10cSrcweir sal_uInt16 nLongIdx = 1; 482*cdf0e10cSrcweir size_t nCount = aBoolArr.size(); 483*cdf0e10cSrcweir if( nCount && ( !bInner || !pTextRanger->IsSimple() ) ) 484*cdf0e10cSrcweir { 485*cdf0e10cSrcweir sal_Bool bDelete = aBoolArr.front(); 486*cdf0e10cSrcweir if( bInner ) 487*cdf0e10cSrcweir bDelete = !bDelete; 488*cdf0e10cSrcweir for( size_t nBoolIdx = 1; nBoolIdx < nCount; ++nBoolIdx ) 489*cdf0e10cSrcweir { 490*cdf0e10cSrcweir if( bDelete ) 491*cdf0e10cSrcweir { 492*cdf0e10cSrcweir sal_uInt16 next = 2; 493*cdf0e10cSrcweir while( nBoolIdx < nCount && !aBoolArr[ nBoolIdx++ ] && 494*cdf0e10cSrcweir (!bInner || nBoolIdx < nCount ) ) 495*cdf0e10cSrcweir next += 2; 496*cdf0e10cSrcweir pLongArr->Remove( nLongIdx, next ); 497*cdf0e10cSrcweir next /= 2; 498*cdf0e10cSrcweir nBoolIdx = nBoolIdx - next; 499*cdf0e10cSrcweir nCount = nCount - next; 500*cdf0e10cSrcweir aBoolArr.erase( aBoolArr.begin() + nBoolIdx, aBoolArr.begin() + (nBoolIdx + next) ); 501*cdf0e10cSrcweir if( nBoolIdx ) 502*cdf0e10cSrcweir aBoolArr[ nBoolIdx - 1 ] = sal_False; 503*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 504*cdf0e10cSrcweir else 505*cdf0e10cSrcweir ++next; 506*cdf0e10cSrcweir #endif 507*cdf0e10cSrcweir } 508*cdf0e10cSrcweir bDelete = nBoolIdx < nCount && aBoolArr[ nBoolIdx ]; 509*cdf0e10cSrcweir nLongIdx += 2; 510*cdf0e10cSrcweir DBG_ASSERT( nLongIdx == 2*nBoolIdx+1, "BoundArgs: Array-Idx Confusion" ); 511*cdf0e10cSrcweir DBG_ASSERT( aBoolArr.size()*2 == pLongArr->Count(), 512*cdf0e10cSrcweir "BoundArgs: Array-Count: Confusion" ); 513*cdf0e10cSrcweir } 514*cdf0e10cSrcweir } 515*cdf0e10cSrcweir if( 0 != ( nCount = pLongArr->Count() ) ) 516*cdf0e10cSrcweir { 517*cdf0e10cSrcweir if( bInner ) 518*cdf0e10cSrcweir { 519*cdf0e10cSrcweir pLongArr->Remove( 0, 1 ); 520*cdf0e10cSrcweir pLongArr->Remove( pLongArr->Count() - 1, 1 ); 521*cdf0e10cSrcweir 522*cdf0e10cSrcweir // Hier wird die Zeile beim "einfachen" Konturumfluss im Innern 523*cdf0e10cSrcweir // in ein grosses Rechteck zusammengefasst. 524*cdf0e10cSrcweir // Zur Zeit (April 1999) wertet die EditEngine nur das erste Rechteck 525*cdf0e10cSrcweir // aus, falls sie eines Tages in der Lage ist, eine Zeile in mehreren 526*cdf0e10cSrcweir // Teilen auszugeben, kann es sinnvoll sein, die folgenden Zeilen 527*cdf0e10cSrcweir // zu loeschen. 528*cdf0e10cSrcweir if( pTextRanger->IsSimple() && pLongArr->Count() > 2 ) 529*cdf0e10cSrcweir pLongArr->Remove( 1, pLongArr->Count() - 2 ); 530*cdf0e10cSrcweir 531*cdf0e10cSrcweir } 532*cdf0e10cSrcweir } 533*cdf0e10cSrcweir } 534*cdf0e10cSrcweir 535*cdf0e10cSrcweir void SvxBoundArgs::Concat( const PolyPolygon* pPoly ) 536*cdf0e10cSrcweir { 537*cdf0e10cSrcweir SetConcat( sal_True ); 538*cdf0e10cSrcweir DBG_ASSERT( pPoly, "Nothing to do?" ); 539*cdf0e10cSrcweir SvLongs *pOld = pLongArr; 540*cdf0e10cSrcweir pLongArr = new SvLongs( 2, 8 ); 541*cdf0e10cSrcweir aBoolArr.clear(); 542*cdf0e10cSrcweir bInner = sal_False; 543*cdf0e10cSrcweir Calc( *pPoly ); 544*cdf0e10cSrcweir sal_uInt16 nCount = pLongArr->Count(); 545*cdf0e10cSrcweir sal_uInt16 nIdx = 0; 546*cdf0e10cSrcweir sal_uInt16 i = 0; 547*cdf0e10cSrcweir sal_Bool bSubtract = pTextRanger->IsInner(); 548*cdf0e10cSrcweir while( i < nCount ) 549*cdf0e10cSrcweir { 550*cdf0e10cSrcweir sal_uInt16 nOldCount = pOld->Count(); 551*cdf0e10cSrcweir if( nIdx == nOldCount ) 552*cdf0e10cSrcweir { // Am Ende des alten Arrays angelangt... 553*cdf0e10cSrcweir if( !bSubtract ) 554*cdf0e10cSrcweir pOld->Insert( pLongArr, nIdx, i, USHRT_MAX ); 555*cdf0e10cSrcweir break; 556*cdf0e10cSrcweir } 557*cdf0e10cSrcweir long nLeft = (*pLongArr)[ i++ ]; 558*cdf0e10cSrcweir long nRight = (*pLongArr)[ i++ ]; 559*cdf0e10cSrcweir sal_uInt16 nLeftPos = nIdx + 1; 560*cdf0e10cSrcweir while( nLeftPos < nOldCount && nLeft > (*pOld)[ nLeftPos ] ) 561*cdf0e10cSrcweir nLeftPos += 2; 562*cdf0e10cSrcweir if( nLeftPos >= nOldCount ) 563*cdf0e10cSrcweir { // Das aktuelle Intervall gehoert ans Ende des alten Arrays... 564*cdf0e10cSrcweir if( !bSubtract ) 565*cdf0e10cSrcweir pOld->Insert( pLongArr, nOldCount, i - 2, USHRT_MAX ); 566*cdf0e10cSrcweir break; 567*cdf0e10cSrcweir } 568*cdf0e10cSrcweir sal_uInt16 nRightPos = nLeftPos - 1; 569*cdf0e10cSrcweir while( nRightPos < nOldCount && nRight >= (*pOld)[ nRightPos ] ) 570*cdf0e10cSrcweir nRightPos += 2; 571*cdf0e10cSrcweir if( nRightPos < nLeftPos ) 572*cdf0e10cSrcweir { // Das aktuelle Intervall gehoert zwischen zwei alte Intervalle 573*cdf0e10cSrcweir if( !bSubtract ) 574*cdf0e10cSrcweir pOld->Insert( pLongArr, nRightPos, i - 2, i ); 575*cdf0e10cSrcweir nIdx = nRightPos + 2; 576*cdf0e10cSrcweir } 577*cdf0e10cSrcweir else if( bSubtract ) // Subtrahieren ggf. Trennen 578*cdf0e10cSrcweir { 579*cdf0e10cSrcweir long nOld; 580*cdf0e10cSrcweir if( nLeft > ( nOld = (*pOld)[ nLeftPos - 1 ] ) ) 581*cdf0e10cSrcweir { // Jetzt spalten wir den linken Teil ab... 582*cdf0e10cSrcweir if( nLeft - 1 > nOld ) 583*cdf0e10cSrcweir { 584*cdf0e10cSrcweir pOld->Insert( nOld, nLeftPos - 1 ); 585*cdf0e10cSrcweir pOld->Insert( nLeft - 1, nLeftPos ); 586*cdf0e10cSrcweir nLeftPos += 2; 587*cdf0e10cSrcweir nRightPos += 2; 588*cdf0e10cSrcweir } 589*cdf0e10cSrcweir } 590*cdf0e10cSrcweir if( nRightPos - nLeftPos > 1 ) 591*cdf0e10cSrcweir pOld->Remove( nLeftPos, nRightPos - nLeftPos - 1 ); 592*cdf0e10cSrcweir if( ++nRight >= ( nOld = (*pOld)[ nLeftPos ] ) ) 593*cdf0e10cSrcweir pOld->Remove( nLeftPos - 1, 2 ); 594*cdf0e10cSrcweir else 595*cdf0e10cSrcweir (*pOld)[ nLeftPos - 1 ] = nRight; 596*cdf0e10cSrcweir } 597*cdf0e10cSrcweir else // Verschmelzen 598*cdf0e10cSrcweir { 599*cdf0e10cSrcweir if( nLeft < (*pOld)[ nLeftPos - 1 ] ) 600*cdf0e10cSrcweir (*pOld)[ nLeftPos - 1 ] = nLeft; 601*cdf0e10cSrcweir if( nRight > (*pOld)[ nRightPos - 1 ] ) 602*cdf0e10cSrcweir (*pOld)[ nRightPos - 1 ] = nRight; 603*cdf0e10cSrcweir if( nRightPos - nLeftPos > 1 ) 604*cdf0e10cSrcweir pOld->Remove( nLeftPos, nRightPos - nLeftPos - 1 ); 605*cdf0e10cSrcweir 606*cdf0e10cSrcweir } 607*cdf0e10cSrcweir nIdx = nLeftPos - 1; 608*cdf0e10cSrcweir } 609*cdf0e10cSrcweir delete pLongArr; 610*cdf0e10cSrcweir } 611*cdf0e10cSrcweir 612*cdf0e10cSrcweir /************************************************************************* 613*cdf0e10cSrcweir * SvxBoundArgs::Area ermittelt den Bereich, in dem sich der Punkt befindet 614*cdf0e10cSrcweir * 0 = innerhalb der Zeile 615*cdf0e10cSrcweir * 1 = unterhalb, aber innerhalb der oberen Randes 616*cdf0e10cSrcweir * 2 = oberhalb, aber innerhalb der unteren Randes 617*cdf0e10cSrcweir * 5 = unterhalb des oberen Randes 618*cdf0e10cSrcweir *10 = oberhalb des unteren Randes 619*cdf0e10cSrcweir *************************************************************************/ 620*cdf0e10cSrcweir 621*cdf0e10cSrcweir sal_uInt16 SvxBoundArgs::Area( const Point& rPt ) 622*cdf0e10cSrcweir { 623*cdf0e10cSrcweir long nB = B( rPt ); 624*cdf0e10cSrcweir if( nB >= nBottom ) 625*cdf0e10cSrcweir { 626*cdf0e10cSrcweir if( nB >= nLower ) 627*cdf0e10cSrcweir return 5; 628*cdf0e10cSrcweir return 1; 629*cdf0e10cSrcweir } 630*cdf0e10cSrcweir if( nB <= nTop ) 631*cdf0e10cSrcweir { 632*cdf0e10cSrcweir if( nB <= nUpper ) 633*cdf0e10cSrcweir return 10; 634*cdf0e10cSrcweir return 2; 635*cdf0e10cSrcweir } 636*cdf0e10cSrcweir return 0; 637*cdf0e10cSrcweir } 638*cdf0e10cSrcweir 639*cdf0e10cSrcweir /************************************************************************* 640*cdf0e10cSrcweir * lcl_Cut berechnet die X-Koordinate der Strecke (Pt1-Pt2) auf der 641*cdf0e10cSrcweir * Y-Koordinate nY. 642*cdf0e10cSrcweir * Vorausgesetzt wird, dass einer der Punkte oberhalb und der andere 643*cdf0e10cSrcweir * unterhalb der Y-Koordinate liegt. 644*cdf0e10cSrcweir *************************************************************************/ 645*cdf0e10cSrcweir 646*cdf0e10cSrcweir long SvxBoundArgs::Cut( long nB, const Point& rPt1, const Point& rPt2 ) 647*cdf0e10cSrcweir { 648*cdf0e10cSrcweir if( pTextRanger->IsVertical() ) 649*cdf0e10cSrcweir { 650*cdf0e10cSrcweir double nQuot = nB - rPt1.X(); 651*cdf0e10cSrcweir nQuot /= ( rPt2.X() - rPt1.X() ); 652*cdf0e10cSrcweir nQuot *= ( rPt2.Y() - rPt1.Y() ); 653*cdf0e10cSrcweir return long( rPt1.Y() + nQuot ); 654*cdf0e10cSrcweir } 655*cdf0e10cSrcweir double nQuot = nB - rPt1.Y(); 656*cdf0e10cSrcweir nQuot /= ( rPt2.Y() - rPt1.Y() ); 657*cdf0e10cSrcweir nQuot *= ( rPt2.X() - rPt1.X() ); 658*cdf0e10cSrcweir return long( rPt1.X() + nQuot ); 659*cdf0e10cSrcweir } 660*cdf0e10cSrcweir 661*cdf0e10cSrcweir void SvxBoundArgs::NoteUpLow( long nA, const sal_uInt8 nArea ) 662*cdf0e10cSrcweir { 663*cdf0e10cSrcweir if( nAct ) 664*cdf0e10cSrcweir { 665*cdf0e10cSrcweir NoteMargin( nA, nA ); 666*cdf0e10cSrcweir if( bMultiple ) 667*cdf0e10cSrcweir { 668*cdf0e10cSrcweir NoteRange( nArea != nAct ); 669*cdf0e10cSrcweir nAct = 0; 670*cdf0e10cSrcweir } 671*cdf0e10cSrcweir if( !nFirst ) 672*cdf0e10cSrcweir nFirst = nArea; 673*cdf0e10cSrcweir } 674*cdf0e10cSrcweir else 675*cdf0e10cSrcweir { 676*cdf0e10cSrcweir nAct = nArea; 677*cdf0e10cSrcweir nMin = nA; 678*cdf0e10cSrcweir nMax = nA; 679*cdf0e10cSrcweir } 680*cdf0e10cSrcweir } 681*cdf0e10cSrcweir 682*cdf0e10cSrcweir SvLongsPtr TextRanger::GetTextRanges( const Range& rRange ) 683*cdf0e10cSrcweir { 684*cdf0e10cSrcweir DBG_ASSERT( rRange.Min() || rRange.Max(), "Zero-Range not allowed, Bye Bye" ); 685*cdf0e10cSrcweir sal_uInt16 nIndex = 0; 686*cdf0e10cSrcweir while( nIndex < nCacheSize && rRange != pRangeArr[ nIndex ] ) 687*cdf0e10cSrcweir ++nIndex; 688*cdf0e10cSrcweir if( nIndex >= nCacheSize ) 689*cdf0e10cSrcweir { 690*cdf0e10cSrcweir ++nCacheIdx; 691*cdf0e10cSrcweir nCacheIdx %= nCacheSize; 692*cdf0e10cSrcweir pRangeArr[ nCacheIdx ] = rRange; 693*cdf0e10cSrcweir if( !pCache[ nCacheIdx ] ) 694*cdf0e10cSrcweir pCache[ nCacheIdx ] = new SvLongs( 2, 8 ); 695*cdf0e10cSrcweir nIndex = nCacheIdx; 696*cdf0e10cSrcweir SvxBoundArgs aArg( this, pCache[ nCacheIdx ], rRange ); 697*cdf0e10cSrcweir aArg.Calc( *mpPolyPolygon ); 698*cdf0e10cSrcweir if( mpLinePolyPolygon ) 699*cdf0e10cSrcweir aArg.Concat( mpLinePolyPolygon ); 700*cdf0e10cSrcweir } 701*cdf0e10cSrcweir return pCache[ nIndex ]; 702*cdf0e10cSrcweir } 703*cdf0e10cSrcweir 704*cdf0e10cSrcweir const Rectangle& TextRanger::_GetBoundRect() 705*cdf0e10cSrcweir { 706*cdf0e10cSrcweir DBG_ASSERT( 0 == pBound, "Don't call twice." ); 707*cdf0e10cSrcweir pBound = new Rectangle( mpPolyPolygon->GetBoundRect() ); 708*cdf0e10cSrcweir return *pBound; 709*cdf0e10cSrcweir } 710*cdf0e10cSrcweir 711*cdf0e10cSrcweir 712