diff options
author | Nigel Hawkins <n.hawkins@gmx.com> | 2011-03-02 10:14:51 +0000 |
---|---|---|
committer | Nigel Hawkins <n.hawkins@gmx.com> | 2011-03-09 21:10:19 +0000 |
commit | a9170798a46315a3bc42fba92b757e6d4a524220 (patch) | |
tree | e8ddbbf75014fe4d549a939afdf7704a90e67f05 | |
parent | 78814afd05a9670724dc35af231f9c5d206c2c5f (diff) |
Remove use of SvLongs from txtrange.[ch]xx and refactor a bit.
Note that this commit forces changes onto writer as well.
-rw-r--r-- | editeng/inc/editeng/txtrange.hxx | 26 | ||||
-rw-r--r-- | editeng/source/editeng/impedit3.cxx | 8 | ||||
-rw-r--r-- | editeng/source/misc/txtrange.cxx | 118 |
3 files changed, 74 insertions, 78 deletions
diff --git a/editeng/inc/editeng/txtrange.hxx b/editeng/inc/editeng/txtrange.hxx index 71d04cb8f490..5aa0375087b2 100644 --- a/editeng/inc/editeng/txtrange.hxx +++ b/editeng/inc/editeng/txtrange.hxx @@ -29,12 +29,10 @@ #ifndef _MyTXTRANGE_HXX #define _MyTXTRANGE_HXX -#ifndef _TXTRANGE_HXX -#define _SVSTDARR_BOOLS -#define _SVSTDARR_LONGS -#include <svl/svstdarr.hxx> -#endif #include "editeng/editengdllapi.h" +#include "tools/solar.h" + +#include <deque> class PolyPolygon; class Range; @@ -44,7 +42,7 @@ namespace basegfx { class B2DPolyPolygon; } -typedef SvLongs* SvLongsPtr; +typedef std::deque<long>* LongDqPtr; /************************************************************************* |* @@ -53,13 +51,18 @@ typedef SvLongs* SvLongsPtr; *************************************************************************/ class EDITENG_DLLPUBLIC TextRanger { - Range *pRangeArr; - SvLongsPtr *pCache; + //! The RangeCache class is used to cache the result of a single range calculation. + struct RangeCache + { + const Range& range; //!< Range for which we calculated results. + std::deque<long> results; //!< Calculated results for the range. + inline RangeCache(const Range& rng) : range(rng) {}; + }; + std::deque<RangeCache> mRangeCache; //!< Cached range calculations. PolyPolygon *mpPolyPolygon; // Surface polygon PolyPolygon *mpLinePolyPolygon; // Line polygon Rectangle *pBound; // Comprehensive rectangle USHORT nCacheSize; // Cache-Size - USHORT nCacheIdx; // Cache-Index USHORT nRight; // Distance Contour-Text USHORT nLeft; // Distance Text-Contour USHORT nUpper; // Distance Contour-Text @@ -77,11 +80,12 @@ class EDITENG_DLLPUBLIC TextRanger TextRanger( const TextRanger& ); // not implemented const Rectangle& _GetBoundRect(); public: - TextRanger( const basegfx::B2DPolyPolygon& rPolyPolygon, const basegfx::B2DPolyPolygon* pLinePolyPolygon, + TextRanger( const basegfx::B2DPolyPolygon& rPolyPolygon, + const basegfx::B2DPolyPolygon* pLinePolyPolygon, USHORT nCacheSize, USHORT nLeft, USHORT nRight, BOOL bSimple, BOOL bInner, BOOL bVert = sal_False ); ~TextRanger(); - SvLongsPtr GetTextRanges( const Range& rRange ); + LongDqPtr GetTextRanges( const Range& rRange ); USHORT GetRight() const { return nRight; } USHORT GetLeft() const { return nLeft; } USHORT GetUpper() const { return nUpper; } diff --git a/editeng/source/editeng/impedit3.cxx b/editeng/source/editeng/impedit3.cxx index 9c47a54de83f..72902078aa22 100644 --- a/editeng/source/editeng/impedit3.cxx +++ b/editeng/source/editeng/impedit3.cxx @@ -824,7 +824,7 @@ sal_Bool ImpEditEngine::CreateLines( USHORT nPara, sal_uInt32 nStartPosY ) if ( nXWidth <= nTmpWidth ) // while muss 1x durchlaufen werden nXWidth = nTmpWidth+1; - SvLongsPtr pTextRanges = 0; + LongDqPtr pTextRanges = 0; long nTextExtraYOffset = 0; long nTextXOffset = 0; long nTextLineHeight = 0; @@ -871,11 +871,11 @@ sal_Bool ImpEditEngine::CreateLines( USHORT nPara, sal_uInt32 nStartPosY ) // Der breiteste Bereich koennte etwas verwirren, also // generell den ersten. Am besten mal richtig mit Luecken. // for ( sal_uInt16 n = 0; n < pTextRanges->Count(); ) - if ( pTextRanges->Count() ) + if ( pTextRanges->size() ) { sal_uInt16 n = 0; - long nA = pTextRanges->GetObject( n++ ); - long nB = pTextRanges->GetObject( n++ ); + long nA = pTextRanges->at(n++); + long nB = pTextRanges->at(n++); DBG_ASSERT( nA <= nB, "TextRange verdreht?" ); long nW = nB - nA; if ( nW > nMaxRangeWidth ) diff --git a/editeng/source/misc/txtrange.cxx b/editeng/source/misc/txtrange.cxx index e52a53f04170..1388153fe043 100644 --- a/editeng/source/misc/txtrange.cxx +++ b/editeng/source/misc/txtrange.cxx @@ -42,12 +42,12 @@ #pragma optimize ( "", off ) #endif -TextRanger::TextRanger( const basegfx::B2DPolyPolygon& rPolyPolygon, const basegfx::B2DPolyPolygon* pLinePolyPolygon, - USHORT nCacheSz, USHORT nLft, USHORT nRght, BOOL bSimpl, BOOL bInnr, - BOOL bVert ) : +TextRanger::TextRanger( const basegfx::B2DPolyPolygon& rPolyPolygon, + const basegfx::B2DPolyPolygon* pLinePolyPolygon, + USHORT nCacheSz, USHORT nLft, USHORT nRght, + BOOL bSimpl, BOOL bInnr, BOOL bVert ) : pBound( NULL ), nCacheSize( nCacheSz ), - nCacheIdx( 0 ), nRight( nRght ), nLeft( nLft ), nUpper( 0 ), @@ -60,10 +60,6 @@ TextRanger::TextRanger( const basegfx::B2DPolyPolygon& rPolyPolygon, const baseg #ifdef DBG_UTIL bFlag3 = bFlag4 = bFlag5 = bFlag6 = bFlag7 = FALSE; #endif - pRangeArr = new Range[ nCacheSize ]; - pCache = new SvLongsPtr[ nCacheSize ]; - memset( pRangeArr, 0, nCacheSize * sizeof( Range ) ); - memset( pCache, 0, nCacheSize * sizeof( SvLongsPtr ) ); sal_uInt32 nCount(rPolyPolygon.count()); mpPolyPolygon = new PolyPolygon( (sal_uInt16)nCount ); @@ -96,10 +92,7 @@ TextRanger::TextRanger( const basegfx::B2DPolyPolygon& rPolyPolygon, const baseg TextRanger::~TextRanger() { - for( USHORT i = 0; i < nCacheSize; ++i ) - delete pCache[i]; - delete[] pCache; - delete[] pRangeArr; + mRangeCache.clear(); delete mpPolyPolygon; delete mpLinePolyPolygon; } @@ -113,17 +106,16 @@ void TextRanger::SetVertical( BOOL bNew ) if( IsVertical() != bNew ) { bVertical = bNew; - for( USHORT i = 0; i < nCacheSize; ++i ) - delete pCache[i]; - memset( pRangeArr, 0, nCacheSize * sizeof( Range ) ); - memset( pCache, 0, nCacheSize * sizeof( SvLongsPtr ) ); + mRangeCache.clear(); } } +//! SvxBoundArgs is used to perform temporary calculations on a range array. +//! Temporary instances are created in TextRanger::GetTextRanges() class SvxBoundArgs { std::vector<bool> aBoolArr; - SvLongs *pLongArr; + LongDqPtr pLongArr; TextRanger *pTextRanger; long nMin; long nMax; @@ -156,7 +148,7 @@ class SvxBoundArgs 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(); } public: - SvxBoundArgs( TextRanger* pRanger, SvLongs *pLong, const Range& rRange ); + SvxBoundArgs( TextRanger* pRanger, LongDqPtr pLong, const Range& rRange ); void NotePoint( const long nA ) { NoteMargin( nA - nStart, nA + nEnd ); } void NoteMargin( const long nL, const long nR ) { if( nMin > nL ) nMin = nL; if( nMax < nR ) nMax = nR; } @@ -173,7 +165,7 @@ public: BYTE GetAct() const { return nAct; } }; -SvxBoundArgs::SvxBoundArgs( TextRanger* pRanger, SvLongs *pLong, +SvxBoundArgs::SvxBoundArgs( TextRanger* pRanger, LongDqPtr pLong, const Range& rRange ) : pLongArr( pLong ), pTextRanger( pRanger ), nTop( rRange.Min() ), nBottom( rRange.Max() ), @@ -196,7 +188,7 @@ SvxBoundArgs::SvxBoundArgs( TextRanger* pRanger, SvLongs *pLong, } nUpper = nTop - nUpDiff; nLower = nBottom + nLowDiff; - pLongArr->Remove( 0, pLongArr->Count() ); + pLongArr->clear(); } long SvxBoundArgs::CalcMax( const Point& rPt1, const Point& rPt2, @@ -269,7 +261,7 @@ void SvxBoundArgs::NoteRange( BOOL bToggle ) if( !bClosed ) bToggle = FALSE; USHORT nIdx = 0; - USHORT nCount = pLongArr->Count(); + USHORT nCount = pLongArr->size(); DBG_ASSERT( nCount == 2 * aBoolArr.size(), "NoteRange: Incompatible Sizes" ); while( nIdx < nCount && (*pLongArr)[ nIdx ] < nMin ) ++nIdx; @@ -277,8 +269,8 @@ void SvxBoundArgs::NoteRange( BOOL bToggle ) // No overlap with existing intervals? if( nIdx == nCount || ( !bOdd && nMax < (*pLongArr)[ nIdx ] ) ) { // Then a new one is inserted ... - pLongArr->Insert( nMin, nIdx ); - pLongArr->Insert( nMax, nIdx + 1 ); + pLongArr->insert( pLongArr->begin() + nIdx, nMin ); + pLongArr->insert( pLongArr->begin() + nIdx + 1, nMax ); aBoolArr.insert( aBoolArr.begin() + (nIdx/2), bToggle ); } else @@ -304,7 +296,7 @@ void SvxBoundArgs::NoteRange( BOOL bToggle ) nMaxIdx = nIdx / 2; // From here on is nMaxIdx the Index in BoolArray. if( nDiff ) { - (*pLongArr).Remove( nIdx + 1, nDiff ); + pLongArr->erase( pLongArr->begin() + nIdx + 1, pLongArr->begin() + nIdx + 1 + nDiff ); nDiff /= 2; USHORT nStop = nMaxIdx + nDiff; for( USHORT i = nMaxIdx; i < nStop; ++i ) @@ -437,15 +429,15 @@ void SvxBoundArgs::Calc( const PolyPolygon& rPoly ) nTmpMax = nMax - 2 * nEnd; if( nTmpMin <= nTmpMax ) { - pLongArr->Insert( nTmpMin, 0 ); - pLongArr->Insert( nTmpMax, 1 ); + pLongArr->push_front(nTmpMax); + pLongArr->push_front(nTmpMin); } } } else { - pLongArr->Insert( nMin, 0 ); - pLongArr->Insert( nMax, 1 ); + pLongArr->push_front(nMax); + pLongArr->push_front(nMin); } } } @@ -470,7 +462,7 @@ void SvxBoundArgs::Add() while( nBoolIdx < nCount && !aBoolArr[ nBoolIdx++ ] && (!bInner || nBoolIdx < nCount ) ) next += 2; - pLongArr->Remove( nLongIdx, next ); + pLongArr->erase( pLongArr->begin() + nLongIdx, pLongArr->begin() + nLongIdx + next ); next /= 2; nBoolIdx = nBoolIdx - next; nCount = nCount - next; @@ -489,19 +481,19 @@ void SvxBoundArgs::Add() "BoundArgs: Array-Count: Confusion" ); } } - if( 0 != ( nCount = pLongArr->Count() ) ) + if( 0 != ( nCount = pLongArr->size() ) ) { if( bInner ) { - pLongArr->Remove( 0, 1 ); - pLongArr->Remove( pLongArr->Count() - 1, 1 ); + pLongArr->pop_front(); + pLongArr->pop_back(); // 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. - if( pTextRanger->IsSimple() && pLongArr->Count() > 2 ) - pLongArr->Remove( 1, pLongArr->Count() - 2 ); + if( pTextRanger->IsSimple() && pLongArr->size() > 2 ) + pLongArr->erase( pLongArr->begin() + 1, pLongArr->end() - 1 ); } } @@ -511,22 +503,22 @@ void SvxBoundArgs::Concat( const PolyPolygon* pPoly ) { SetConcat( TRUE ); DBG_ASSERT( pPoly, "Nothing to do?" ); - SvLongs *pOld = pLongArr; - pLongArr = new SvLongs( 2, 8 ); + LongDqPtr pOld = pLongArr; + pLongArr = new std::deque<long>(); aBoolArr.clear(); bInner = FALSE; - Calc( *pPoly ); - USHORT nCount = pLongArr->Count(); + Calc( *pPoly ); // Note that this updates pLongArr, which is why we swapped it out earlier. + USHORT nCount = pLongArr->size(); USHORT nIdx = 0; USHORT i = 0; BOOL bSubtract = pTextRanger->IsInner(); while( i < nCount ) { - USHORT nOldCount = pOld->Count(); + ULONG nOldCount = pOld->size(); if( nIdx == nOldCount ) { // Reached the end of the old Array... if( !bSubtract ) - pOld->Insert( pLongArr, nIdx, i, USHRT_MAX ); + pOld->insert( pOld->begin() + nIdx, pLongArr->begin() + i, pLongArr->end() ); break; } long nLeft = (*pLongArr)[ i++ ]; @@ -537,7 +529,7 @@ void SvxBoundArgs::Concat( const PolyPolygon* pPoly ) if( nLeftPos >= nOldCount ) { // The current interval belongs to the end of the old array ... if( !bSubtract ) - pOld->Insert( pLongArr, nOldCount, i - 2, USHRT_MAX ); + pOld->insert( pOld->begin() + nOldCount, pLongArr->begin() + i - 2, pLongArr->end() ); break; } USHORT nRightPos = nLeftPos - 1; @@ -546,7 +538,7 @@ void SvxBoundArgs::Concat( const PolyPolygon* pPoly ) if( nRightPos < nLeftPos ) { // The current interval belongs between two old intervals if( !bSubtract ) - pOld->Insert( pLongArr, nRightPos, i - 2, i ); + pOld->insert( pOld->begin() + nRightPos, pLongArr->begin() + i - 2, pLongArr->begin() + i ); nIdx = nRightPos + 2; } else if( bSubtract ) // Subtract, if necessary separate @@ -556,16 +548,16 @@ void SvxBoundArgs::Concat( const PolyPolygon* pPoly ) { // Now we split the left part... if( nLeft - 1 > nOld ) { - pOld->Insert( nOld, nLeftPos - 1 ); - pOld->Insert( nLeft - 1, nLeftPos ); + pOld->insert( pOld->begin() + nLeftPos - 1, nOld ); + pOld->insert( pOld->begin() + nLeftPos, nLeft - 1 ); nLeftPos += 2; nRightPos += 2; } } if( nRightPos - nLeftPos > 1 ) - pOld->Remove( nLeftPos, nRightPos - nLeftPos - 1 ); + pOld->erase( pOld->begin() + nLeftPos, pOld->begin() + nRightPos - 1 ); if( ++nRight >= ( nOld = (*pOld)[ nLeftPos ] ) ) - pOld->Remove( nLeftPos - 1, 2 ); + pOld->erase( pOld->begin() + nLeftPos - 1, pOld->begin() + nLeftPos + 1 ); else (*pOld)[ nLeftPos - 1 ] = nRight; } @@ -576,7 +568,7 @@ void SvxBoundArgs::Concat( const PolyPolygon* pPoly ) if( nRight > (*pOld)[ nRightPos - 1 ] ) (*pOld)[ nRightPos - 1 ] = nRight; if( nRightPos - nLeftPos > 1 ) - pOld->Remove( nLeftPos, nRightPos - nLeftPos - 1 ); + pOld->erase( pOld->begin() + nLeftPos, pOld->begin() + nRightPos - 1 ); } nIdx = nLeftPos - 1; @@ -654,26 +646,26 @@ void SvxBoundArgs::NoteUpLow( long nA, const BYTE nArea ) } } -SvLongsPtr TextRanger::GetTextRanges( const Range& rRange ) +LongDqPtr TextRanger::GetTextRanges( const Range& rRange ) { DBG_ASSERT( rRange.Min() || rRange.Max(), "Zero-Range not allowed, Bye Bye" ); - USHORT nIndex = 0; - while( nIndex < nCacheSize && rRange != pRangeArr[ nIndex ] ) - ++nIndex; - if( nIndex >= nCacheSize ) + //Can we find the result we need in the cache? + for (std::deque<RangeCache>::iterator it = mRangeCache.begin(); it < mRangeCache.end(); ++it) { - ++nCacheIdx; - nCacheIdx %= nCacheSize; - pRangeArr[ nCacheIdx ] = rRange; - if( !pCache[ nCacheIdx ] ) - pCache[ nCacheIdx ] = new SvLongs( 2, 8 ); - nIndex = nCacheIdx; - SvxBoundArgs aArg( this, pCache[ nCacheIdx ], rRange ); - aArg.Calc( *mpPolyPolygon ); - if( mpLinePolyPolygon ) - aArg.Concat( mpLinePolyPolygon ); + if (it->range == rRange) + return &(it->results); } - return pCache[ nIndex ]; + //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); } const Rectangle& TextRanger::_GetBoundRect() |