diff options
Diffstat (limited to 'tools/source')
33 files changed, 4183 insertions, 844 deletions
diff --git a/tools/source/communi/geninfo.cxx b/tools/source/communi/geninfo.cxx index b4616e0bdf26..09abae555a2a 100644 --- a/tools/source/communi/geninfo.cxx +++ b/tools/source/communi/geninfo.cxx @@ -2,9 +2,9 @@ * * $RCSfile: geninfo.cxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: gh $ $Date: 2002-01-09 17:34:58 $ + * last change: $Author: hr $ $Date: 2003-03-27 17:03:45 $ * * Copyright according the GNU Public License. * @@ -254,24 +254,11 @@ ULONG GenericInformationList::InsertSorted( GenericInformation *pInfo, return 0; } - ByteString sKey( pInfo->GetBuffer()); - sKey.ToUpperAscii(); - - // Check to sppeed up reading a (partially) sorted list - if ( nStart == 0 && Count()-1 == nEnd ) - { - ByteString sCandidate( *GetObject( nEnd )); - if ( sCandidate.ToUpperAscii() < sKey ) - { - Insert( pInfo, LIST_APPEND ); - return nEnd+1; - } - } - // ### GH: dieser Block schein überflüssig zu sein + ByteString sKey( pInfo->GetBuffer()); if ( Count() == 1 ) { ByteString sCandidate( *GetObject( 0 )); - if ( sCandidate.ToUpperAscii() == sKey ) { + if ( sCandidate.ToUpperAscii() == sKey.ToUpperAscii()) { // key allready exists in list if ( bOverwrite ) Replace( pInfo, ULONG(0)); // ### Laut NF scheint hier ein Memory Leak zu sein @@ -291,7 +278,7 @@ ULONG GenericInformationList::InsertSorted( GenericInformation *pInfo, ULONG nActPos = nStart + (( nEnd - nStart ) / 2 ); ByteString sCandidate = ByteString( *GetObject( nActPos )); - if ( sCandidate.ToUpperAscii() == sKey ) { + if ( sCandidate.ToUpperAscii() == sKey.ToUpperAscii()) { // key allready exists in list if ( bOverwrite ) Replace( pInfo, nActPos ); // ### Laut NF scheint hier ein Memory Leak zu sein @@ -306,7 +293,7 @@ ULONG GenericInformationList::InsertSorted( GenericInformation *pInfo, } else { Insert( pInfo, nStart + 1 ); - return ( nStart + 1 ); + return ( nStart + 1 ); } } diff --git a/tools/source/communi/makefile.mk b/tools/source/communi/makefile.mk index 9f660bb450da..52f0ea6ced82 100644 --- a/tools/source/communi/makefile.mk +++ b/tools/source/communi/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.5 $ +# $Revision: 1.6 $ # -# last change: $Author: gh $ $Date: 2002-04-19 07:59:27 $ +# last change: $Author: hr $ $Date: 2003-03-27 17:03:47 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -76,7 +76,6 @@ TARGET=communi CXXFILES= simplecm.cxx bcst.cxx OBJFILES= \ - $(OBJ)$/SafePureVirtual.obj \ $(OBJ)$/tcpio.obj \ $(OBJ)$/packethandler.obj \ $(OBJ)$/simplecm.obj \ @@ -89,10 +88,8 @@ OBJFILES= \ $(OBJ)$/ssockcon.obj \ $(OBJ)$/parser.obj \ $(OBJ)$/geninfo.obj \ - $(OBJ)$/abthread.obj SLOFILES= \ - $(SLO)$/SafePureVirtual.obj \ $(SLO)$/tcpio.obj \ $(SLO)$/packethandler.obj \ $(SLO)$/simplecm.obj \ @@ -105,7 +102,6 @@ SLOFILES= \ $(SLO)$/ssockcon.obj \ $(SLO)$/parser.obj \ $(SLO)$/geninfo.obj \ - $(SLO)$/abthread.obj # --- Targets ------------------------------------------------------ diff --git a/tools/source/communi/parser.cxx b/tools/source/communi/parser.cxx index 6ace9aa612dd..890106083a16 100644 --- a/tools/source/communi/parser.cxx +++ b/tools/source/communi/parser.cxx @@ -2,9 +2,9 @@ * * $RCSfile: parser.cxx,v $ * - * $Revision: 1.9 $ + * $Revision: 1.10 $ * - * last change: $Author: gh $ $Date: 2002-05-27 14:42:42 $ + * last change: $Author: hr $ $Date: 2003-03-27 17:03:48 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -72,7 +72,7 @@ // class InformationParser // -#define cKeyLevelChar '\t' +const char InformationParser::cKeyLevelChars = '\t'; /*****************************************************************************/ InformationParser::InformationParser( BOOL bReplace ) @@ -109,25 +109,20 @@ ByteString &InformationParser::ReadLine() else { if ( !pActStream->IsEof()) { pActStream->ReadLine( sLine ); - ULONG nStart = 0; - ULONG nEnd = sLine.Len(); - BOOL bCopy = FALSE; - while ( nStart < nEnd && ( sLine.GetChar( nStart ) == ' ' || sLine.GetChar( nStart ) == 0x09 ) ) - { - nStart++; - bCopy = TRUE; - } - - while ( nStart < nEnd && ( sLine.GetChar( nEnd-1 ) == ' ' || sLine.GetChar( nEnd-1 ) == 0x09 ) ) - { - nEnd--; - bCopy = TRUE; - } - - if ( bCopy ) - sLine = sLine.Copy( nStart, nEnd - nStart ); - - if (( sLine.GetChar( 0 ) == '#' ) || ( !sLine.Len())) { + ULONG nLen; + do { + nLen = sLine.Len(); + sLine.EraseLeadingChars( 0x09 ); + sLine.EraseLeadingChars( ' ' ); + } while ( nLen != sLine.Len()); + + do { + nLen = sLine.Len(); + sLine.EraseTrailingChars( 0x09 ); + sLine.EraseTrailingChars( ' ' ); + } while ( nLen != sLine.Len()); + + if (( sLine.Search( "#" ) == 0 ) || ( !sLine.Len())) { if ( sCurrentComment.Len()) sCurrentComment += "\n"; sCurrentComment += sLine; @@ -135,21 +130,11 @@ ByteString &InformationParser::ReadLine() } else { if ( bReplaceVariables ) { - sLine.SearchAndReplaceAll( "%UPD", sUPD ); - sLine.SearchAndReplaceAll( "%VERSION", sVersion ); + while( sLine.SearchAndReplace( "%UPD", sUPD ) != (USHORT)-1 ); + while( sLine.SearchAndReplace( "%VERSION", sVersion ) != (USHORT)-1 ); } } } - else { - if ( nLevel ) { - sLine = "}"; - fprintf( stdout, "Reached EOF parsing %s. Suplying extra '}'\n",ByteString( sStreamName, gsl_getSystemTextEncoding()).GetBuffer() ); - // nErrorCode = IP_UNEXPECTED_EOF; - // nErrorLine = nActLine; - } - else - sLine = ""; - } sOldLine = sLine; nActLine++; @@ -230,11 +215,8 @@ GenericInformation *InformationParser::ReadKey( } else { Recover(); - if ( !sKey.Equals( "}" ) && !sKey.Equals( "{" ) ) - { - pInfo = new GenericInformation( sKey, sValue, pExistingList ); - pInfo->SetComment( sComment ); - } + pInfo = new GenericInformation( sKey, sValue, pExistingList ); + pInfo->SetComment( sComment ); } return pInfo; @@ -250,7 +232,7 @@ void InformationParser::Recover() /*****************************************************************************/ BOOL InformationParser::Save( SvStream &rOutStream, const GenericInformationList *pSaveList, - USHORT nLevel, BOOL bStripped ) + USHORT nLevel ) /*****************************************************************************/ { USHORT i; @@ -259,23 +241,19 @@ BOOL InformationParser::Save( SvStream &rOutStream, GenericInformation *pGenericInfo; GenericInformationList *pGenericInfoList; - static ByteString aKeyLevel; - aKeyLevel.Expand( nLevel, cKeyLevelChar ); - for ( nInfoListCount = 0; nInfoListCount < pSaveList->Count(); nInfoListCount++) { // Key-Value Paare schreiben pGenericInfo = pSaveList->GetObject( nInfoListCount ); sTmpStr = ""; - if ( !bStripped && nLevel ) - sTmpStr.Append( aKeyLevel.GetBuffer(), nLevel ); - - if ( !bStripped ) - for ( i = 0; i < pGenericInfo->GetComment().GetTokenCount( '\n' ); i++ ) { - sTmpStr += pGenericInfo->GetComment().GetToken( i, '\n' ); - sTmpStr += "\n"; - if ( nLevel ) - sTmpStr.Append( aKeyLevel.GetBuffer(), nLevel ); - } + for( ULONG j=0; j<nLevel; j++) + sTmpStr += cKeyLevelChars; + + for ( i = 0; i < pGenericInfo->GetComment().GetTokenCount( '\n' ); i++ ) { + sTmpStr += pGenericInfo->GetComment().GetToken( i, '\n' ); + sTmpStr += "\n"; + for( ULONG j=0; j<nLevel; j++) + sTmpStr += cKeyLevelChars; + } sTmpStr += pGenericInfo->GetBuffer(); sTmpStr += ' '; @@ -284,21 +262,21 @@ BOOL InformationParser::Save( SvStream &rOutStream, return FALSE; // wenn vorhanden, bearbeite recursive die Sublisten - if (( pGenericInfoList = pGenericInfo->GetSubList() ) != NULL ) { + if (( pGenericInfoList = pGenericInfo->GetSubList() ) != 0) { // oeffnende Klammer sTmpStr = ""; - if ( !bStripped && nLevel ) - sTmpStr.Append( aKeyLevel.GetBuffer(), nLevel ); + for( i=0; i<nLevel; i++) + sTmpStr += cKeyLevelChars; sTmpStr += '{'; if ( !rOutStream.WriteLine( sTmpStr ) ) return FALSE; // recursiv die sublist abarbeiten - if ( !Save( rOutStream, pGenericInfoList, nLevel+1, bStripped ) ) + if ( !Save( rOutStream, pGenericInfoList, nLevel+1 ) ) return FALSE; // schliessende Klammer sTmpStr = ""; - if ( !bStripped && nLevel ) - sTmpStr.Append( aKeyLevel.GetBuffer(), nLevel ); + for( i=0; i<nLevel; i++) + sTmpStr += cKeyLevelChars; sTmpStr += '}'; if ( !rOutStream.WriteLine( sTmpStr ) ) return FALSE; @@ -432,11 +410,8 @@ BOOL InformationParser::Save( SvFileStream &rSourceStream, const GenericInformationList *pSaveList ) /*****************************************************************************/ { - if ( !rSourceStream.IsOpen() || !Save( (SvStream &)rSourceStream, pSaveList, 0, FALSE )) - { - printf( "ERROR saving file \"%s\"\n",ByteString( rSourceStream.GetFileName(), gsl_getSystemTextEncoding()).GetBuffer() ); + if ( !rSourceStream.IsOpen() || !Save( (SvStream &)rSourceStream, pSaveList, 0 )) return FALSE; - } return TRUE; } @@ -446,11 +421,7 @@ BOOL InformationParser::Save( SvMemoryStream &rSourceStream, const GenericInformationList *pSaveList ) /*****************************************************************************/ { - Time a; - BOOL bRet = Save( (SvStream &)rSourceStream, pSaveList, 0, TRUE ); - Time b; - b = b - a; - return bRet; + return Save( (SvStream &)rSourceStream, pSaveList, 0 ); } /*****************************************************************************/ diff --git a/tools/source/datetime/datetime.cxx b/tools/source/datetime/datetime.cxx index 60d3e17d3b8f..442db222549d 100644 --- a/tools/source/datetime/datetime.cxx +++ b/tools/source/datetime/datetime.cxx @@ -2,9 +2,9 @@ * * $RCSfile: datetime.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: er $ $Date: 2000-11-10 17:54:10 $ + * last change: $Author: hr $ $Date: 2003-03-27 17:03:56 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -60,7 +60,7 @@ ************************************************************************/ #include <datetime.hxx> -#include <solmath.hxx> +#include <rtl/math.hxx> /************************************************************************* |* @@ -360,12 +360,12 @@ DateTime& DateTime::operator +=( double fTimeInDays ) double fInt, fFrac; if ( fTimeInDays < 0.0 ) { - fInt = SolarMath::ApproxCeil( fTimeInDays ); + fInt = ::rtl::math::approxCeil( fTimeInDays ); fFrac = fInt <= fTimeInDays ? 0.0 : fTimeInDays - fInt; } else { - fInt = SolarMath::ApproxFloor( fTimeInDays ); + fInt = ::rtl::math::approxFloor( fTimeInDays ); fFrac = fInt >= fTimeInDays ? 0.0 : fTimeInDays - fInt; } Date::operator+=( long(fInt) ); // full days diff --git a/tools/source/datetime/makefile.mk b/tools/source/datetime/makefile.mk index 5a53e0a0039f..ce417af258a5 100644 --- a/tools/source/datetime/makefile.mk +++ b/tools/source/datetime/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.1.1.1 $ +# $Revision: 1.2 $ # -# last change: $Author: hr $ $Date: 2000-09-18 17:03:06 $ +# last change: $Author: hr $ $Date: 2003-03-27 17:03:56 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -77,11 +77,9 @@ SLOFILES= $(SLO)$/tdate.obj \ $(SLO)$/ttime.obj \ $(SLO)$/datetime.obj -.IF "$(UPDATER)"!="" OBJFILES= $(OBJ)$/tdate.obj \ $(OBJ)$/ttime.obj \ $(OBJ)$/datetime.obj -.ENDIF # --- Targets ------------------------------------------------------ diff --git a/tools/source/datetime/ttime.cxx b/tools/source/datetime/ttime.cxx index 4f4bf7b341ed..86c64b0d6e04 100644 --- a/tools/source/datetime/ttime.cxx +++ b/tools/source/datetime/ttime.cxx @@ -2,9 +2,9 @@ * * $RCSfile: ttime.cxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: svesik $ $Date: 2002-09-03 13:13:59 $ + * last change: $Author: hr $ $Date: 2003-03-27 17:03:57 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -72,11 +72,10 @@ #elif defined( DOS ) #include <dos.h> #elif defined UNX -#include <limits.h> -#if defined( IRIX ) || defined( UNX ) #include <unistd.h> -#endif -#include <sys/times.h> +#include <limits.h> +#include <math.h> +#include <sys/time.h> #elif defined( MAC ) #include "mac_start.h" #ifndef __OSUTILS__ @@ -89,10 +88,6 @@ #include <time.h> #include <time.hxx> -#ifdef UNX -#include <math.h> -#endif - #ifndef WNT #ifndef localtime_r extern "C" { @@ -494,31 +489,15 @@ ULONG Time::GetSystemTicks() millisec = ( millisec + 500L ) / 1000L; return (ULONG)millisec; #else - static ULONG nImplTicksPerSecond = 0; - static double dImplTicksPerSecond; - static double dImplTicksULONGMAX; - struct tms aTms; - ULONG nTicks = (ULONG)times( &aTms ); - - if ( !nImplTicksPerSecond ) - { -#if defined( CLK_TCK ) - nImplTicksPerSecond = CLK_TCK; -#elif defined( _SC_CLK_TCK ) - nImplTicksPerSecond = sysconf(_SC_CLK_TCK); -#else -#error "I don't know how to get CLK_TCK." -#endif - dImplTicksPerSecond = nImplTicksPerSecond; - dImplTicksULONGMAX = (double)(ULONG)ULONG_MAX; - } + timeval tv; + gettimeofday (&tv, 0); - double fTicks = nTicks; + double fTicks = tv.tv_sec; fTicks *= 1000; - fTicks /= dImplTicksPerSecond; - fTicks = fmod (fTicks, dImplTicksULONGMAX); + fTicks += ((tv.tv_usec + 500) / 1000); - return (ULONG)fTicks; + fTicks = fmod (fTicks, double(ULONG_MAX)); + return ULONG(fTicks); #endif } diff --git a/tools/source/debug/makefile.mk b/tools/source/debug/makefile.mk index c21005fd0331..b03c82ecb16e 100644 --- a/tools/source/debug/makefile.mk +++ b/tools/source/debug/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.1.1.1 $ +# $Revision: 1.2 $ # -# last change: $Author: hr $ $Date: 2000-09-18 17:03:06 $ +# last change: $Author: hr $ $Date: 2003-03-27 17:03:59 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -79,10 +79,8 @@ CXXFILES= debug.cxx \ SLOFILES= $(SLO)$/debug.obj \ $(SLO)$/stcktree.obj -.IF "$(UPDATER)"!="" OBJFILES= $(OBJ)$/debug.obj \ $(OBJ)$/stcktree.obj -.ENDIF # --- Targets ------------------------------------------------------ diff --git a/tools/source/fsys/dirent.cxx b/tools/source/fsys/dirent.cxx index 1a5aee10c054..8aac59ab1408 100644 --- a/tools/source/fsys/dirent.cxx +++ b/tools/source/fsys/dirent.cxx @@ -2,8 +2,8 @@ * * $RCSfile: dirent.cxx,v $ * - * $Revision: 1.11 $ - * last change: $Author: hro $ $Date: 2001-07-27 08:03:57 $ + * $Revision: 1.12 $ + * last change: $Author: hr $ $Date: 2003-03-27 17:04:01 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -219,15 +219,15 @@ void FSysRedirector::Register( FSysRedirector *pRedirector ) BOOL FSysRedirector::DoRedirect( String &rPath ) { - ByteString aURL(rPath, osl_getThreadTextEncoding()); - String sURL = String(aURL, osl_getThreadTextEncoding()); + String aURL(rPath); + String sURL = aURL; // if redirection is disabled or not even registered do nothing if ( !_bEnabled || !pRedirectMutex ) return FALSE; // redirect only removable or remote volumes - if ( !IsRedirectable_Impl( aURL ) ) + if ( !IsRedirectable_Impl( ByteString( aURL, osl_getThreadTextEncoding() ) ) ) return FALSE; // Redirection is acessible only by one thread per time @@ -244,7 +244,7 @@ BOOL FSysRedirector::DoRedirect( String &rPath ) // convert to URL #ifndef UNX - for ( char *p = (char *) aURL.GetBuffer(); *p; ++p ) + for ( sal_Unicode *p = (sal_Unicode*)aURL.GetBuffer(); *p; ++p ) #ifndef MAC if ( '\\' == *p ) *p = '/'; else if ( ':' == *p ) *p = '|'; @@ -253,7 +253,7 @@ BOOL FSysRedirector::DoRedirect( String &rPath ) #endif #endif - aURL.Insert( "file:///", 0 ); + aURL.Insert( String("file:///", osl_getThreadTextEncoding()), 0 ); // do redirection Redirector(); @@ -262,10 +262,10 @@ BOOL FSysRedirector::DoRedirect( String &rPath ) // if redirected transform URL to file name if ( bRedirected ) { - rPath = String(aURL.Copy( 8 ), osl_getThreadTextEncoding()); - aURL = ByteString(rPath, osl_getThreadTextEncoding()); + rPath = aURL.Copy( 8 ); + aURL = rPath; #ifndef UNX - for ( char *p = (char *) aURL.GetBuffer(); *p; ++p ) + for ( sal_Unicode *p = (sal_Unicode *)aURL.GetBuffer(); *p; ++p ) #ifndef MAC if ( '/' == *p ) *p = '\\'; else if ( '|' == *p ) *p = ':'; @@ -469,7 +469,7 @@ FSysError DirEntry::ImpParseOs2Name( const ByteString& rPfad, FSysPathStyle eSty DBG_CHKTHIS( DirEntry, ImpCheckDirEntry ); // die einzelnen Namen auf einen Stack packen - ByteString aPfad( rPfad ); + String aPfad( rPfad, osl_getThreadTextEncoding() ); DirEntryStack aStack; do @@ -495,7 +495,7 @@ FSysError DirEntry::ImpParseOs2Name( const ByteString& rPfad, FSysPathStyle eSty for ( nPos = 2; aPfad.Len() > nPos; ++nPos ) if ( aPfad.GetChar(nPos) == '\\' || aPfad.GetChar(nPos) == '/' ) break; - aName = aPfad.Copy( 2, nPos-2 ); + aName = ByteString( aPfad.Copy( 2, nPos-2 ), osl_getThreadTextEncoding() ); aStack.Push( new DirEntry( aName, FSYS_FLAG_ABSROOT, eStyle ) ); } // ist der Name die Root des aktuellen Drives? @@ -510,7 +510,7 @@ FSysError DirEntry::ImpParseOs2Name( const ByteString& rPfad, FSysPathStyle eSty // ist der Name ein Drive? if ( nPos < aPfad.Len() && aPfad.GetChar(nPos) == ':' ) { - aName = aPfad.Copy( 0, nPos + 1 ); + aName = ByteString( aPfad.Copy( 0, nPos + 1 ), osl_getThreadTextEncoding() ); // ist der Name die Root des Drives if ( (nPos + 1) < aPfad.Len() && @@ -543,7 +543,7 @@ FSysError DirEntry::ImpParseOs2Name( const ByteString& rPfad, FSysPathStyle eSty else { // den Namen ohne Trenner abspalten - aName = aPfad.Copy( 0, nPos ); + aName = ByteString( aPfad.Copy( 0, nPos ), osl_getThreadTextEncoding() ); // stellt der Name die aktuelle Directory dar? if ( aName == "." ) @@ -661,16 +661,17 @@ FSysError DirEntry::ImpParseOs2Name( const ByteString& rPfad, FSysPathStyle eSty |* *************************************************************************/ -FSysError DirEntry::ImpParseName( const ByteString& rInitName, +FSysError DirEntry::ImpParseName( const ByteString& rbInitName, FSysPathStyle eStyle ) { + String rInitName( rbInitName, osl_getThreadTextEncoding() ); if ( eStyle == FSYS_STYLE_HOST ) eStyle = DEFSTYLE; // KI-Division of FSys if ( eStyle == FSYS_STYLE_DETECT ) { - char cFirst = rInitName.Copy(0,1).ToLowerAscii().GetChar(0); + sal_Unicode cFirst = rInitName.Copy(0,1).ToLowerAscii().GetChar(0); if ( rInitName.Len() == 2 && rInitName.GetChar(1) == ':' && cFirst >= 'a' && cFirst <= 'z' ) @@ -699,14 +700,14 @@ FSysError DirEntry::ImpParseName( const ByteString& rInitName, case FSYS_STYLE_HPFS: case FSYS_STYLE_NTFS: case FSYS_STYLE_NWFS: - return ImpParseOs2Name( rInitName, eStyle ); + return ImpParseOs2Name( rbInitName, eStyle ); case FSYS_STYLE_BSD: case FSYS_STYLE_SYSV: - return ImpParseUnixName( rInitName, eStyle ); + return ImpParseUnixName( rbInitName, eStyle ); case FSYS_STYLE_MAC: - return ImpParseMacName( rInitName ); + return ImpParseMacName( rbInitName ); default: return FSYS_ERR_UNKNOWN; @@ -1942,15 +1943,14 @@ BOOL DirEntry::ImpToRel( String aCurStr ) DirEntry aThis(*this); aThis.ToAbs(); - ByteString aThisStr( aThis.GetFull( FSYS_STYLE_HPFS ), osl_getThreadTextEncoding()); - ByteString bCurStr( aCurStr, osl_getThreadTextEncoding()); - aThisStr = CMP_LOWER( aThisStr ); - bCurStr = CMP_LOWER( bCurStr ); + String aThisStr( aThis.GetFull( FSYS_STYLE_HPFS ) ); + aThisStr = String( aThisStr ).ToLowerAscii(); + aCurStr = String( aCurStr ).ToLowerAscii(); // "Ubereinstimmung pr"ufen - USHORT nPos = aThisStr.Match( bCurStr ); - if ( nPos == STRING_MATCH && aThisStr.Len() != bCurStr.Len() ) - nPos = Min( aThisStr.Len(), bCurStr.Len() ); + USHORT nPos = aThisStr.Match( aCurStr ); + if ( nPos == STRING_MATCH && aThisStr.Len() != aCurStr.Len() ) + nPos = Min( aThisStr.Len(), aCurStr.Len() ); // Sonderfall, die DirEntries sind identisch if ( nPos == STRING_MATCH ) @@ -1972,15 +1972,15 @@ BOOL DirEntry::ImpToRel( String aCurStr ) while ( nPos > 0 && aThisStr.GetChar(nPos) != '\\' ) --nPos; aThisStr.Erase( 0, nPos + ( ( aThisStr.GetChar(nPos) == '\\' ) ? 1 : 0 ) ); - bCurStr.Erase( 0, nPos + ( ( bCurStr.GetChar(nPos) == '\\' ) ? 1 : 0 ) ); + aCurStr.Erase( 0, nPos + ( ( aCurStr.GetChar(nPos) == '\\' ) ? 1 : 0 ) ); // und fuellen mit dem Level der Directories auf - for ( nPos = 0; nPos < bCurStr.Len(); ++nPos ) - if ( bCurStr.GetChar(nPos) == '\\' ) - aThisStr.Insert( "..\\", 0 ); + for ( nPos = 0; nPos < aCurStr.Len(); ++nPos ) + if ( aCurStr.GetChar(nPos) == '\\' ) + aThisStr.Insert( String( "..\\", osl_getThreadTextEncoding() ), 0 ); // das ist dann unser relativer Pfad - *this = DirEntry( String(aThisStr, osl_getThreadTextEncoding()), FSYS_STYLE_HPFS ); + *this = DirEntry( aThisStr, FSYS_STYLE_HPFS ); return TRUE; } @@ -2435,7 +2435,7 @@ DirEntry DirEntry::TempName( DirEntryKind eKind ) const } } - delete ret_val; + delete[] ret_val; ret_val = 0; } @@ -3360,7 +3360,7 @@ FSysError DirEntry::Kill( FSysAction nActions ) const FileStat::SetReadOnlyFlag(*this, isReadOnly); } - delete pName; + delete[] pName; return eError; } diff --git a/tools/source/fsys/filecopy.cxx b/tools/source/fsys/filecopy.cxx index d73fca371c43..5ae157093430 100644 --- a/tools/source/fsys/filecopy.cxx +++ b/tools/source/fsys/filecopy.cxx @@ -2,9 +2,9 @@ * * $RCSfile: filecopy.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: ok $ $Date: 2001-08-28 09:46:22 $ + * last change: $Author: hr $ $Date: 2003-03-27 17:04:01 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -449,7 +449,7 @@ FSysError FileCopier::DoCopy_Impl( const DirEntry &rSource, const DirEntry &rTar // adjust the block-size if ( nBlockSize > nAllocSize ) { - delete pBuf; + delete[] pBuf; nAllocSize = nBlockSize; pBuf = new char[nAllocSize]; } @@ -465,7 +465,7 @@ FSysError FileCopier::DoCopy_Impl( const DirEntry &rSource, const DirEntry &rTar if ( nBytesCopied > nBytesTotal ) nBytesTotal = nBytesCopied; } - delete pBuf; + delete[] pBuf; } else eRet = Error( aTargetStream.GetError(), 0, &aTarget ); @@ -583,5 +583,3 @@ FSysError FileCopier::ExecuteExact( FSysAction nActions, FSysExact eExact ) // recursive copy return DoCopy_Impl( aAbsSource, aAbsTarget, TRUE ); } - - diff --git a/tools/source/fsys/makefile.mk b/tools/source/fsys/makefile.mk index a3d963cdd6e0..837340d3ee95 100644 --- a/tools/source/fsys/makefile.mk +++ b/tools/source/fsys/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.4 $ +# $Revision: 1.5 $ # -# last change: $Author: sb $ $Date: 2002-03-13 09:03:34 $ +# last change: $Author: hr $ $Date: 2003-03-27 17:04:02 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -71,6 +71,9 @@ TARGET=fsys # --- Files -------------------------------------------------------- +UNOUCROUT = $(OUT)$/inc +UNOTYPES = com.sun.star.util.XStringWidth + SLOFILES= \ $(SLO)$/tempfile.obj \ $(SLO)$/wldcrd.obj \ @@ -81,7 +84,6 @@ SLOFILES= \ $(SLO)$/tdir.obj \ $(SLO)$/urlobj.obj -.IF "$(UPDATER)"!="" OBJFILES= $(OBJ)$/wldcrd.obj \ $(OBJ)$/fstat.obj \ $(OBJ)$/comdep.obj \ @@ -89,7 +91,6 @@ OBJFILES= $(OBJ)$/wldcrd.obj \ $(OBJ)$/dirent.obj \ $(OBJ)$/tdir.obj \ $(OBJ)$/urlobj.obj -.ENDIF # --- Targets ------------------------------------------------------ diff --git a/tools/source/fsys/tdir.cxx b/tools/source/fsys/tdir.cxx index d065ca77f38c..d0d3290f6223 100644 --- a/tools/source/fsys/tdir.cxx +++ b/tools/source/fsys/tdir.cxx @@ -2,9 +2,9 @@ * * $RCSfile: tdir.cxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: hr $ $Date: 2002-03-05 14:02:33 $ + * last change: $Author: hr $ $Date: 2003-03-27 17:04:03 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -62,8 +62,7 @@ #define _DIR_CXX #include <stdlib.h> -#include <stdarg.h> // both stdarg.h and cstdarg are needed to satisfy all compilers -#include <cstdarg> // ugly, I know +#include <cstdarg> #include <limits.h> #ifndef _DEBUG_HXX diff --git a/tools/source/fsys/unx.cxx b/tools/source/fsys/unx.cxx index cbd4222335ba..af86ee343c15 100644 --- a/tools/source/fsys/unx.cxx +++ b/tools/source/fsys/unx.cxx @@ -2,9 +2,9 @@ * * $RCSfile: unx.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: svesik $ $Date: 2000-11-16 21:06:23 $ + * last change: $Author: hr $ $Date: 2003-03-27 17:04:04 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -73,9 +73,6 @@ #include <sys/mntctl.h> #include <sys/vmount.h> extern "C" int mntctl( int cmd, size_t size, char* buf ); -#elif defined S390 -#include <sys/mntent.h> -#define mnttab w_mntent #elif defined(NETBSD) #include <sys/mount.h> #elif defined(FREEBSD) || defined(MACOSX) @@ -111,9 +108,6 @@ DECLARE_LIST( FileStatList, FileStat* ) #define MNTTAB "/etc/mnttab" #define MOUNTSPECIAL mt_dev #define MOUNTPOINT mt_filsys -#elif defined S390 -#define MOUNTSPECIAL mnt_fsname -#define MOUNTPOINT mnt_mountpoint #else #define MOUNTSPECIAL mnt_fsname #define MOUNTPOINT mnt_dir @@ -190,7 +184,7 @@ static BOOL GetMountEntry(dev_t dev, struct mymnttab *mytab) return FALSE; struct mnttab mnt[1]; while (fread (&mnt, sizeof mnt, 1, fp) > 0) -#elif defined DECUNIX || defined AIX || defined S390 +#elif defined DECUNIX || defined AIX FILE *fp = NULL; if (! fp) return FALSE; diff --git a/tools/source/fsys/unx.hxx b/tools/source/fsys/unx.hxx index 2751289b7c2e..592079fb2560 100644 --- a/tools/source/fsys/unx.hxx +++ b/tools/source/fsys/unx.hxx @@ -2,9 +2,9 @@ * * $RCSfile: unx.hxx,v $ * - * $Revision: 1.1.1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: hr $ $Date: 2000-09-18 17:03:07 $ + * last change: $Author: hr $ $Date: 2003-03-27 17:04:05 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -65,11 +65,7 @@ #include <string.h> #include <sys/types.h> #include <sys/stat.h> - -#ifndef S390 #include <sys/param.h> -#endif - #include <dirent.h> #include <unistd.h> /* #include <sysent.h> */ diff --git a/tools/source/fsys/urlobj.cxx b/tools/source/fsys/urlobj.cxx index 050459ba04b5..5bc95190386f 100644 --- a/tools/source/fsys/urlobj.cxx +++ b/tools/source/fsys/urlobj.cxx @@ -2,9 +2,9 @@ * * $RCSfile: urlobj.cxx,v $ * - * $Revision: 1.35 $ + * $Revision: 1.36 $ * - * last change: $Author: sb $ $Date: 2002-11-08 12:55:18 $ + * last change: $Author: hr $ $Date: 2003-03-27 17:04:06 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -181,10 +181,11 @@ using namespace com::sun; segment = *(pchar / ";") - ; private (see RFC 1738) - news-url = "NEWS://" login ["/" (group / message)] - group = *uric - message = "<" *uric ">" + ; RFC 1738, RFC 2396, RFC 2732 + news-url = "NEWS:" grouppart + grouppart = "*" / group / article + group = alpha *(alphanum / "+" / "-" / "." / "_") + article = 1*(escaped / alphanum / "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / "-" / "." / "/" / ":" / ";" / "=" / "?" / "_" / "~") "@" host ; private @@ -271,7 +272,7 @@ using namespace com::sun; ; private - vnd-sun-star-pkg-url = "VND.SUN.STAR.PKG://" reg_name *("/" *pchar) + vnd-sun-star-pkg-url = "VND.SUN.STAR.PKG://" reg_name *("/" *pchar) ["?" *uric] reg_name = 1*(escaped / alphanum / "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / "-" / "." / ":" / ";" / "=" / "@" / "_" / "~") @@ -405,8 +406,8 @@ static INetURLObject::SchemeInfo const aSchemeInfoMap[INET_PROT_END] false, false, true }, { "vnd.sun.star.webdav", "vnd.sun.star.webdav://", 80, true, false, false, false, true, true, true, true }, - { "news", "news:", 119, true, true, false, true, true, true, - false, false }, + { "news", "news:", 0, false, false, false, false, false, false, false, + false }, { "private", "private:", 0, false, false, false, false, false, false, false, true }, { "vnd.sun.star.help", "vnd.sun.star.help://", 0, true, false, false, @@ -440,7 +441,7 @@ static INetURLObject::SchemeInfo const aSchemeInfoMap[INET_PROT_END] { ".component", ".component:", 0, false, false, false, false, false, false, false, true }, { "vnd.sun.star.pkg", "vnd.sun.star.pkg://", 0, true, false, false, - false, false, false, true, false }, + false, false, false, true, true }, { "ldap", "ldap://", 389, true, false, false, false, true, true, false, true }, { "db", "db:", 0, false, false, false, false, false, false, false, @@ -525,107 +526,108 @@ enum pX = INetURLObject::PART_UNO_PARAM_VALUE, pY = INetURLObject::PART_UNAMBIGUOUS, pZ = INetURLObject::PART_URIC_NO_SLASH, - p1 = INetURLObject::PART_HTTP_QUERY + p1 = INetURLObject::PART_HTTP_QUERY, + p2 = INetURLObject::PART_NEWS_ARTICLE_LOCALPART }; static sal_uInt32 const aMustEncodeMap[128] = { 0, 0, 0, 0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} */ pU+pV +pY, -/* ~ */ pA+pB+pC+pD+pE +pH+pI+pJ+pK+pL+pM+pN+pO+pP+pQ+pR+pS+pT+pU+pV+pW+pX+pY+pZ, +/* ~ */ pA+pB+pC+pD+pE +pH+pI+pJ+pK+pL+pM+pN+pO+pP+pQ+pR+pS+pT+pU+pV+pW+pX+pY+pZ +p2, 0 }; inline bool mustEncode(sal_uInt32 nUTF32, INetURLObject::Part ePart) @@ -1158,9 +1160,15 @@ bool INetURLObject::setAbsURIRef(UniString const & rTheAbsURIRef, } default: { + // For INET_PROT_FILE, allow an empty authority ("//") to be + // missing if the following path starts with an explicit "/" + // (Java is notorious in generating such file URLs, so be + // liberal here): if (pEnd - pPos >= 2 && pPos[0] == '/' && pPos[1] == '/') pPos += 2; - else if (!bSmart) + else if (!bSmart + && !(m_eScheme == INET_PROT_FILE + && pPos != pEnd && *pPos == '/')) { setInvalid(); return false; @@ -1354,7 +1362,7 @@ bool INetURLObject::setAbsURIRef(UniString const & rTheAbsURIRef, // Parse <path> UniString aSynPath; - if (!parsePath(&pPos, pEnd, bOctets, eMechanism, eCharset, + if (!parsePath(m_eScheme, &pPos, pEnd, bOctets, eMechanism, eCharset, bSkippedInitialSlash, nSegmentDelimiter, nAltSegmentDelimiter, getSchemeInfo().m_bQuery ? '?' : 0x80000000, @@ -2367,7 +2375,9 @@ bool INetURLObject::setHost(UniString const & rTheHost, bool bOctets, } //============================================================================ -bool INetURLObject::parsePath(sal_Unicode const ** pBegin, +// static +bool INetURLObject::parsePath(INetProtocol eScheme, + sal_Unicode const ** pBegin, sal_Unicode const * pEnd, bool bOctets, EncodeMechanism eMechanism, @@ -2382,12 +2392,10 @@ bool INetURLObject::parsePath(sal_Unicode const ** pBegin, DBG_ASSERT(pBegin && pSynPath, "INetURLObject::parsePath(): Null output param"); - sal_Char cEscapePrefix = getEscapePrefix(); - sal_Unicode const * pPos = *pBegin; UniString aTheSynPath; - switch (m_eScheme) + switch (eScheme) { case INET_PROT_NOT_VALID: return false; @@ -2395,18 +2403,15 @@ bool INetURLObject::parsePath(sal_Unicode const ** pBegin, case INET_PROT_FTP: case INET_PROT_IMAP: if (pPos < pEnd && *pPos != '/') - { - setInvalid(); return false; - } while (pPos < pEnd && *pPos != nFragmentDelimiter) { EscapeType eEscapeType; sal_uInt32 nUTF32 = getUTF32(pPos, pEnd, bOctets, - cEscapePrefix, eMechanism, + '%', eMechanism, eCharset, eEscapeType); appendUCS4(aTheSynPath, nUTF32, eEscapeType, bOctets, - PART_HTTP_PATH, cEscapePrefix, eCharset, true); + PART_HTTP_PATH, '%', eCharset, true); } if (aTheSynPath.Len() == 0) aTheSynPath = '/'; @@ -2416,19 +2421,16 @@ bool INetURLObject::parsePath(sal_Unicode const ** pBegin, case INET_PROT_VND_SUN_STAR_WEBDAV: case INET_PROT_HTTPS: if (pPos < pEnd && *pPos != '/') - { - setInvalid(); return false; - } while (pPos < pEnd && *pPos != nQueryDelimiter && *pPos != nFragmentDelimiter) { EscapeType eEscapeType; sal_uInt32 nUTF32 = getUTF32(pPos, pEnd, bOctets, - cEscapePrefix, eMechanism, + '%', eMechanism, eCharset, eEscapeType); appendUCS4(aTheSynPath, nUTF32, eEscapeType, bOctets, - PART_HTTP_PATH, cEscapePrefix, eCharset, true); + PART_HTTP_PATH, '%', eCharset, true); } if (aTheSynPath.Len() == 0) aTheSynPath = '/'; @@ -2442,15 +2444,12 @@ bool INetURLObject::parsePath(sal_Unicode const ** pBegin, else if (pPos < pEnd && *pPos != nSegmentDelimiter && *pPos != nAltSegmentDelimiter) - { - setInvalid(); return false; - } while (pPos < pEnd && *pPos != nFragmentDelimiter) { EscapeType eEscapeType; sal_uInt32 nUTF32 = getUTF32(pPos, pEnd, bOctets, - cEscapePrefix, eMechanism, + '%', eMechanism, eCharset, eEscapeType); if (eEscapeType == ESCAPE_NO) if (nUTF32 == nSegmentDelimiter @@ -2473,7 +2472,7 @@ bool INetURLObject::parsePath(sal_Unicode const ** pBegin, continue; } appendUCS4(aTheSynPath, nUTF32, eEscapeType, bOctets, - PART_PCHAR, cEscapePrefix, eCharset, true); + PART_PCHAR, '%', eCharset, true); } if (aTheSynPath.Len() == 0) aTheSynPath = '/'; @@ -2486,23 +2485,84 @@ bool INetURLObject::parsePath(sal_Unicode const ** pBegin, { EscapeType eEscapeType; sal_uInt32 nUTF32 = getUTF32(pPos, pEnd, bOctets, - cEscapePrefix, eMechanism, + '%', eMechanism, eCharset, eEscapeType); appendUCS4(aTheSynPath, nUTF32, eEscapeType, bOctets, - PART_MAILTO, cEscapePrefix, eCharset, true); + PART_MAILTO, '%', eCharset, true); } break; case INET_PROT_NEWS: + if (pPos == pEnd || *pPos == nQueryDelimiter + || *pPos == nFragmentDelimiter) + return false; + + // Match <"*">: + if (*pPos == '*' + && (pEnd - pPos == 1 || pPos[1] == nQueryDelimiter + || pPos[1] == nFragmentDelimiter)) + { + ++pPos; + aTheSynPath = '*'; + break; + } + + // Match <group>: + if (INetMIME::isAlpha(*pPos)) + for (sal_Unicode const * p = pPos + 1;; ++p) + if (p == pEnd || *p == nQueryDelimiter + || *p == nFragmentDelimiter) + { + aTheSynPath.Assign(pPos, p - pPos); + pPos = p; + goto done; + } + else if (!INetMIME::isAlphanumeric(*p) && *p != '+' + && *p != '-' && *p != '.' && *p != '_') + break; + + // Match <article>: + for (;;) + { + if (pPos == pEnd || *pPos == nQueryDelimiter + || *pPos == nFragmentDelimiter) + return false; + if (*pPos == '@') + break; + EscapeType eEscapeType; + sal_uInt32 nUTF32 = getUTF32(pPos, pEnd, bOctets, '%', + eMechanism, eCharset, eEscapeType); + appendUCS4(aTheSynPath, nUTF32, eEscapeType, bOctets, + PART_NEWS_ARTICLE_LOCALPART, '%', eCharset, true); + } + if (aTheSynPath.Len() == 0) + return false; + ++pPos; + aTheSynPath += '@'; + { + sal_Unicode const * p = pPos; + while (p < pEnd && *pPos != nQueryDelimiter + && *pPos != nFragmentDelimiter) + ++p; + UniString aCanonic; + if (!parseHost(pPos, p, bOctets, eMechanism, eCharset, + aCanonic)) + return false; + aTheSynPath += aCanonic; + } + + done: + break; + case INET_PROT_POP3: while (pPos < pEnd && *pPos != nFragmentDelimiter) { EscapeType eEscapeType; sal_uInt32 nUTF32 = getUTF32(pPos, pEnd, bOctets, - cEscapePrefix, eMechanism, + '%', eMechanism, eCharset, eEscapeType); appendUCS4(aTheSynPath, nUTF32, eEscapeType, bOctets, - PART_MESSAGE_ID_PATH, cEscapePrefix, eCharset, + PART_MESSAGE_ID_PATH, '%', eCharset, true); } break; @@ -2517,10 +2577,10 @@ bool INetURLObject::parsePath(sal_Unicode const ** pBegin, { EscapeType eEscapeType; sal_uInt32 nUTF32 = getUTF32(pPos, pEnd, bOctets, - cEscapePrefix, eMechanism, + '%', eMechanism, eCharset, eEscapeType); appendUCS4(aTheSynPath, nUTF32, eEscapeType, bOctets, - PART_PATH_BEFORE_QUERY, cEscapePrefix, eCharset, + PART_PATH_BEFORE_QUERY, '%', eCharset, true); } break; @@ -2533,17 +2593,11 @@ bool INetURLObject::parsePath(sal_Unicode const ** pBegin, else { if (*pPos++ != '/') - { - setInvalid(); return false; - } while (pPos < pEnd && *pPos != nQueryDelimiter && *pPos != nFragmentDelimiter) if (!INetMIME::isAlphanumeric(*pPos++)) - { - setInvalid(); return false; - } aTheSynPath = UniString(*pBegin, pPos - *pBegin); } break; @@ -2557,49 +2611,45 @@ bool INetURLObject::parsePath(sal_Unicode const ** pBegin, { EscapeType eEscapeType; sal_uInt32 nUTF32 = getUTF32(pPos, pEnd, bOctets, - cEscapePrefix, eMechanism, + '%', eMechanism, eCharset, eEscapeType); appendUCS4(aTheSynPath, nUTF32, eEscapeType, bOctets, - PART_URIC, cEscapePrefix, eCharset, true); + PART_URIC, '%', eCharset, true); } break; case INET_PROT_OUT: if (pEnd - pPos < 2 || *pPos++ != '/' || *pPos++ != '~') - { - setInvalid(); return false; - } aTheSynPath.AssignAscii(RTL_CONSTASCII_STRINGPARAM("/~")); while (pPos < pEnd && *pPos != nFragmentDelimiter) { EscapeType eEscapeType; sal_uInt32 nUTF32 = getUTF32(pPos, pEnd, bOctets, - cEscapePrefix, eMechanism, + '%', eMechanism, eCharset, eEscapeType); appendUCS4(aTheSynPath, nUTF32, eEscapeType, bOctets, - PART_URIC, cEscapePrefix, eCharset, true); + PART_URIC, '%', eCharset, true); } break; case INET_PROT_VND_SUN_STAR_HIER: case INET_PROT_VND_SUN_STAR_PKG: - if (pPos < pEnd && *pPos != '/') - { - setInvalid(); + if (pPos < pEnd && *pPos != '/' + && *pPos != nQueryDelimiter && *pPos != nFragmentDelimiter) return false; - } - while (pPos < pEnd && *pPos != nFragmentDelimiter) + while (pPos < pEnd && *pPos != nQueryDelimiter + && *pPos != nFragmentDelimiter) { EscapeType eEscapeType; sal_uInt32 nUTF32 = getUTF32(pPos, pEnd, bOctets, - cEscapePrefix, eMechanism, + '%', eMechanism, eCharset, eEscapeType); if (eEscapeType == ESCAPE_NO && nUTF32 == '/') aTheSynPath += '/'; else appendUCS4(aTheSynPath, nUTF32, eEscapeType, bOctets, - PART_PCHAR, cEscapePrefix, eCharset, false); + PART_PCHAR, '%', eCharset, false); } if (aTheSynPath.Len() == 0) aTheSynPath = '/'; @@ -2607,11 +2657,11 @@ bool INetURLObject::parsePath(sal_Unicode const ** pBegin, case INET_PROT_VIM: { +/* test had to be taken out to make parsePath static; ok since INET_PROT_VIM is + obsolete, anyway if (m_aUser.isEmpty()) - { - setInvalid(); return false; - } +*/ sal_Unicode const * pPathEnd = pPos; while (pPathEnd < pEnd && *pPathEnd != nFragmentDelimiter) ++pPathEnd; @@ -2619,22 +2669,19 @@ bool INetURLObject::parsePath(sal_Unicode const ** pBegin, if (pPos == pPathEnd) break; else if (*pPos++ != '/') - { - setInvalid(); return false; - } if (pPos == pPathEnd) break; while (pPos < pPathEnd && *pPos != '/') { EscapeType eEscapeType; sal_uInt32 nUTF32 = getUTF32(pPos, pPathEnd, bOctets, - cEscapePrefix, eMechanism, + '=', eMechanism, eCharset, eEscapeType); appendUCS4(aTheSynPath, eEscapeType == ESCAPE_NO ? INetMIME::toLowerCase(nUTF32) : nUTF32, - eEscapeType, bOctets, PART_VIM, cEscapePrefix, + eEscapeType, bOctets, PART_VIM, '=', eCharset, false); } bool bInbox; @@ -2643,18 +2690,12 @@ bool INetURLObject::parsePath(sal_Unicode const ** pBegin, else if (aTheSynPath.EqualsAscii("/newsgroups")) bInbox = false; else - { - setInvalid(); return false; - } aTheSynPath += '/'; if (pPos == pPathEnd) break; else if (*pPos++ != '/') - { - setInvalid(); return false; - } if (!bInbox) { bool bEmpty = true; @@ -2662,59 +2703,44 @@ bool INetURLObject::parsePath(sal_Unicode const ** pBegin, { EscapeType eEscapeType; sal_uInt32 nUTF32 = getUTF32(pPos, pPathEnd, bOctets, - cEscapePrefix, eMechanism, + '=', eMechanism, eCharset, eEscapeType); appendUCS4(aTheSynPath, nUTF32, eEscapeType, bOctets, - PART_VIM, cEscapePrefix, eCharset, false); + PART_VIM, '=', eCharset, false); bEmpty = false; } if (bEmpty) - { - setInvalid(); return false; - } aTheSynPath += '/'; if (pPos == pPathEnd) break; else if (*pPos++ != '/') - { - setInvalid(); return false; - } } bool bEmpty = true; while (pPos < pPathEnd && *pPos != ':') { EscapeType eEscapeType; sal_uInt32 nUTF32 = getUTF32(pPos, pPathEnd, bOctets, - cEscapePrefix, eMechanism, + '=', eMechanism, eCharset, eEscapeType); appendUCS4(aTheSynPath, nUTF32, eEscapeType, bOctets, - PART_VIM, cEscapePrefix, eCharset, false); + PART_VIM, '=', eCharset, false); bEmpty = false; } if (bEmpty) - { - setInvalid(); return false; - } if (pPos == pPathEnd) break; else if (*pPos++ != ':') - { - setInvalid(); return false; - } aTheSynPath += ':'; for (int i = 0; i < 3; ++i) { if (i != 0) { if (pPos == pPathEnd || *pPos++ != '.') - { - setInvalid(); return false; - } aTheSynPath += '.'; } bool bEmpty = true; @@ -2722,46 +2748,34 @@ bool INetURLObject::parsePath(sal_Unicode const ** pBegin, { EscapeType eEscapeType; sal_uInt32 nUTF32 = getUTF32(pPos, pPathEnd, bOctets, - cEscapePrefix, eMechanism, + '=', eMechanism, eCharset, eEscapeType); if (!INetMIME::isDigit(nUTF32)) - { - setInvalid(); return false; - } aTheSynPath += sal_Unicode(nUTF32); bEmpty = false; } if (bEmpty) - { - setInvalid(); return false; - } } if (pPos != pPathEnd) - { - setInvalid(); return false; - } break; } case INET_PROT_VND_SUN_STAR_CMD: { if (pPos == pEnd || *pPos == nFragmentDelimiter) - { - setInvalid(); return false; - } Part ePart = PART_URIC_NO_SLASH; while (pPos != pEnd && *pPos != nFragmentDelimiter) { EscapeType eEscapeType; sal_uInt32 nUTF32 = getUTF32(pPos, pEnd, bOctets, - cEscapePrefix, eMechanism, + '%', eMechanism, eCharset, eEscapeType); appendUCS4(aTheSynPath, nUTF32, eEscapeType, bOctets, ePart, - cEscapePrefix, eCharset, true); + '%', eCharset, true); ePart = PART_URIC; } break; @@ -2775,7 +2789,7 @@ bool INetURLObject::parsePath(sal_Unicode const ** pBegin, { EscapeType eEscapeType; sal_uInt32 nUTF32 = getUTF32(pPos, pEnd, bOctets, - cEscapePrefix, eMechanism, + '%', eMechanism, eCharset, eEscapeType); switch (eState) { @@ -2783,14 +2797,11 @@ bool INetURLObject::parsePath(sal_Unicode const ** pBegin, case STATE_COMMA: if (eEscapeType == ESCAPE_NO && (nUTF32 == '=' || nUTF32 == ',')) - { - setInvalid(); return false; - } eState = STATE_KEY; appendUCS4(aTheSynPath, INetMIME::toLowerCase(nUTF32), eEscapeType, bOctets, PART_UNO_PARAM_VALUE, - cEscapePrefix, eCharset, true); + '%', eCharset, true); break; case STATE_KEY: @@ -2802,13 +2813,10 @@ bool INetURLObject::parsePath(sal_Unicode const ** pBegin, break; } else if (nUTF32 == ',') - { - setInvalid(); return false; - } appendUCS4(aTheSynPath, INetMIME::toLowerCase(nUTF32), eEscapeType, bOctets, PART_UNO_PARAM_VALUE, - cEscapePrefix, eCharset, true); + '%', eCharset, true); break; case STATE_VALUE: @@ -2820,21 +2828,15 @@ bool INetURLObject::parsePath(sal_Unicode const ** pBegin, break; } else if (nUTF32 == '=') - { - setInvalid(); return false; - } appendUCS4(aTheSynPath, nUTF32, eEscapeType, bOctets, - PART_UNO_PARAM_VALUE, cEscapePrefix, eCharset, + PART_UNO_PARAM_VALUE, '%', eCharset, true); break; } } if (eState == STATE_COMMA || eState == STATE_KEY) - { - setInvalid(); return false; - } break; } @@ -2843,19 +2845,16 @@ bool INetURLObject::parsePath(sal_Unicode const ** pBegin, if (*pPos == '/') ++pPos; else - { - setInvalid(); return false; - } aTheSynPath = '/'; while (pPos < pEnd && *pPos != nFragmentDelimiter) { EscapeType eEscapeType; sal_uInt32 nUTF32 = getUTF32(pPos, pEnd, bOctets, - cEscapePrefix, eMechanism, + '%', eMechanism, eCharset, eEscapeType); appendUCS4(aTheSynPath, nUTF32, eEscapeType, bOctets, - PART_URIC_NO_SLASH, cEscapePrefix, eCharset, true); + PART_URIC_NO_SLASH, '%', eCharset, true); } break; @@ -2863,10 +2862,7 @@ bool INetURLObject::parsePath(sal_Unicode const ** pBegin, if (pPos < pEnd) { if (*pPos != '/' || pEnd - pPos > 1) - { - setInvalid(); return false; - } ++pPos; } aTheSynPath = '/'; @@ -2886,8 +2882,8 @@ bool INetURLObject::setPath(UniString const & rThePath, bool bOctets, UniString aSynPath; sal_Unicode const * p = rThePath.GetBuffer(); sal_Unicode const * pEnd = p + rThePath.Len(); - if (!parsePath(&p, pEnd, bOctets, eMechanism, eCharset, false, '/', - 0x80000000, 0x80000000, 0x80000000, &aSynPath) + if (!parsePath(m_eScheme, &p, pEnd, bOctets, eMechanism, eCharset, false, + '/', 0x80000000, 0x80000000, 0x80000000, &aSynPath) || p != pEnd) return false; sal_Int32 nDelta = m_aPath.set(m_aAbsURIRef, aSynPath); @@ -3248,165 +3244,6 @@ UniString INetURLObject::GetURLNoMark(DecodeMechanism eMechanism, return aTemp.GetMainURL(eMechanism, eCharset); } -#if SUPD < 642 -//============================================================================ -UniString INetURLObject::getAbbreviated(sal_Int32 nLength, - DecodeMechanism eMechanism, - rtl_TextEncoding eCharset) - const -{ - sal_Char cEscapePrefix = getEscapePrefix(); - rtl::OUStringBuffer aBuffer; - aBuffer.appendAscii(getSchemeInfo().m_pScheme); - aBuffer.append(static_cast< sal_Unicode >(':')); - OSL_ENSURE(m_aHost.isPresent() - || !(m_aUser.isPresent() - || m_aAuth.isPresent() - || m_aPort.isPresent()), - "unexpected situation"); // misusing host as authority... - if (m_aHost.isPresent()) - { - aBuffer.appendAscii(RTL_CONSTASCII_STRINGPARAM("//")); - OSL_ENSURE(m_aUser.isPresent() || !m_aAuth.isPresent(), - "unexpected situation"); - if (m_aUser.isPresent()) - { - aBuffer. - append(decode(m_aUser, cEscapePrefix, eMechanism, eCharset)); - if (m_aAuth.isPresent()) - { - if (getSchemeInfo().m_bAuth) - aBuffer.appendAscii(RTL_CONSTASCII_STRINGPARAM(";AUTH=")); - else - aBuffer.append(static_cast< sal_Unicode >(':')); - aBuffer.append(decode(m_aAuth, - cEscapePrefix, - eMechanism, - eCharset)); - } - aBuffer.append(static_cast< sal_Unicode >('@')); - } - aBuffer.append(decode(m_aHost, cEscapePrefix, eMechanism, eCharset)); - if (m_aPort.isPresent()) - { - aBuffer.append(static_cast< sal_Unicode >(':')); - aBuffer. - append(decode(m_aPort, cEscapePrefix, eMechanism, eCharset)); - } - } - bool bSegment = false; - if (getSchemeInfo().m_bHierarchical) - { - OSL_ENSURE(!m_aPath.isEmpty() - && m_aAbsURIRef.GetChar(m_aPath.getBegin()) == '/', - "unexpected situation"); - aBuffer.append(static_cast< sal_Unicode >('/')); - sal_Int32 nUsed - = aBuffer.getLength() - + (m_aQuery.isPresent() || m_aFragment.isPresent() ? 4 : 0); - sal_Int32 nSize = nUsed < nLength ? nLength - nUsed : 0; - bool bEllipsis = false; - rtl::OUStringBuffer aTrailer; - sal_Unicode const * pBegin = m_aAbsURIRef.GetBuffer() - + m_aPath.getBegin(); - sal_Unicode const * pEnd = pBegin + m_aPath.getLength(); - bool bPrefix = true; - bool bSuffix = true; - sal_Unicode const * pPrefixBegin = pBegin; - sal_Unicode const * pSuffixEnd = pEnd; - do - { - if (bSuffix) - { - sal_Unicode const * p = pSuffixEnd - 1; - while (*p != '/') - --p; - rtl::OUString aSegment(decode(p == pBegin ? p + 1 : p, - pSuffixEnd, - cEscapePrefix, - eMechanism, - eCharset)); - pSuffixEnd = p; - if (aSegment.getLength() <= nSize - && (pBegin == pSuffixEnd - || nSize - aSegment.getLength() >= 3)) - { - nSize -= aSegment.getLength(); - aTrailer.insert(0, aSegment); - bSegment = true; - pEnd = pSuffixEnd; - } - else - { - bEllipsis = true; - bSuffix = false; - } - if (pPrefixBegin == pSuffixEnd) - break; - } - if (bPrefix) - { - sal_Unicode const * p = pPrefixBegin + 1; - while (p != pSuffixEnd && *p != '/') - ++p; - rtl::OUString aSegment(decode(pPrefixBegin + 1, - p == pEnd ? p : p + 1, - cEscapePrefix, - eMechanism, - eCharset)); - pPrefixBegin = p; - if (aSegment.getLength() <= nSize - && (pPrefixBegin == pEnd - || nSize - aSegment.getLength() >= 3)) - { - nSize -= aSegment.getLength(); - aBuffer.append(aSegment); - bSegment = true; - pBegin = pPrefixBegin; - } - else - { - bEllipsis = true; - bPrefix = false; - } - if (pPrefixBegin == pSuffixEnd) - break; - } - } - while (bPrefix || bSuffix); - if (bSegment) - { - if (bEllipsis) - aBuffer.appendAscii(RTL_CONSTASCII_STRINGPARAM("...")); - aBuffer.append(aTrailer); - } - else - aBuffer.setLength(aBuffer.getLength() - 1); - // remove the initial '/' of the path again - } - if (!bSegment) - aBuffer.append(decode(m_aPath, cEscapePrefix, eMechanism, eCharset)); - if (m_aQuery.isPresent()) - { - aBuffer.append(static_cast< sal_Unicode >('?')); - aBuffer.append(decode(m_aQuery, cEscapePrefix, eMechanism, eCharset)); - } - if (m_aFragment.isPresent()) - { - aBuffer.append(static_cast< sal_Unicode >('#')); - aBuffer. - append(decode(m_aFragment, cEscapePrefix, eMechanism, eCharset)); - } - if (aBuffer.getLength() > nLength) - { - aBuffer.setLength(nLength < 3 ? 0 : nLength - 3); - aBuffer.appendAscii(RTL_CONSTASCII_STRINGPARAM("...")); - aBuffer.setLength(std::max< sal_Int32 >(nLength, 0)); - } - return aBuffer.makeStringAndClear(); -} -#endif // SUPD, 642 - //============================================================================ UniString INetURLObject::getAbbreviated( @@ -3817,21 +3654,16 @@ bool INetURLObject::ConcatData(INetProtocol eTheScheme, } } UniString aSynPath; - if (getSchemeInfo().m_bHierarchical - && (rThePath.Len() == 0 || rThePath.GetChar(0) != '/')) - aSynPath = '/'; - aSynPath += rThePath; - m_aPath.set(m_aAbsURIRef, - encodeText(aSynPath, false, - m_eScheme == INET_PROT_FILE - || m_eScheme == INET_PROT_VND_SUN_STAR_WFS ? - PART_PATH_SEGMENTS_EXTRA : - m_eScheme == INET_PROT_NEWS - || m_eScheme == INET_PROT_POP3 ? - PART_MESSAGE_ID_PATH : - PART_HTTP_PATH, - getEscapePrefix(), WAS_ENCODED, eCharset, true), - m_aAbsURIRef.Len()); + sal_Unicode const * p = rThePath.GetBuffer(); + sal_Unicode const * pEnd = p + rThePath.Len(); + if (!parsePath(m_eScheme, &p, pEnd, false, eMechanism, eCharset, false, '/', + 0x80000000, 0x80000000, 0x80000000, &aSynPath) + || p != pEnd) + { + setInvalid(); + return false; + } + m_aPath.set(m_aAbsURIRef, aSynPath, m_aAbsURIRef.Len()); return true; } @@ -5029,7 +4861,7 @@ UniString INetURLObject::getFSysPath(FSysStyle eStyle, //============================================================================ bool INetURLObject::HasMsgId() const { - if (m_eScheme != INET_PROT_NEWS && m_eScheme != INET_PROT_POP3) + if (m_eScheme != INET_PROT_POP3) return false; sal_Unicode const * p = m_aAbsURIRef.GetBuffer() + m_aPath.getBegin(); sal_Unicode const * pEnd = p + m_aPath.getLength(); @@ -5043,7 +4875,7 @@ bool INetURLObject::HasMsgId() const UniString INetURLObject::GetMsgId(DecodeMechanism eMechanism, rtl_TextEncoding eCharset) const { - if (m_eScheme != INET_PROT_NEWS && m_eScheme != INET_PROT_POP3) + if (m_eScheme != INET_PROT_POP3) return UniString(); sal_Unicode const * p = m_aAbsURIRef.GetBuffer() + m_aPath.getBegin(); sal_Unicode const * pEnd = p + m_aPath.getLength(); diff --git a/tools/source/generic/line.cxx b/tools/source/generic/line.cxx new file mode 100644 index 000000000000..8cf729af162f --- /dev/null +++ b/tools/source/generic/line.cxx @@ -0,0 +1,408 @@ +/************************************************************************* + * + * $RCSfile: line.cxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: hr $ $Date: 2003-03-27 17:04:14 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#define _LINE_CXX + +#ifndef _LINK_HXX +#include <link.hxx> +#endif + +#ifndef _LINE_HXX +#include <line.hxx> +#endif + +#ifndef _DEBUG_HXX +#include <debug.hxx> +#endif + +#include <cstdlib> +#include <cmath> + +inline long FRound( double fVal ) +{ + return( fVal > 0.0 ? (long) ( fVal + 0.5 ) : -(long) ( -fVal + 0.5 ) ); +} + +// -------- +// - Line - +// -------- + +double Line::GetLength() const +{ + return hypot( maStart.X() - maEnd.X(), maStart.Y() - maEnd.Y() ); +} + +// ------------------------------------------------------------------------ + +BOOL Line::Intersection( const Line& rLine, Point& rIntersection ) const +{ + double fX, fY; + BOOL bRet; + + if( Intersection( rLine, fX, fY ) ) + { + rIntersection.X() = FRound( fX ); + rIntersection.Y() = FRound( fY ); + bRet = TRUE; + } + else + bRet = FALSE; + + return bRet; +} + +// ------------------------------------------------------------------------ + +BOOL Line::Intersection( const Line& rLine, double& rIntersectionX, double& rIntersectionY ) const +{ + const double fAx = maEnd.X() - maStart.X(); + const double fAy = maEnd.Y() - maStart.Y(); + const double fBx = rLine.maStart.X() - rLine.maEnd.X(); + const double fBy = rLine.maStart.Y() - rLine.maEnd.Y(); + const double fDen = fAy * fBx - fAx * fBy; + BOOL bOk = FALSE; + + if( fDen != 0. ) + { + const double fCx = maStart.X() - rLine.maStart.X(); + const double fCy = maStart.Y() - rLine.maStart.Y(); + const double fA = fBy * fCx - fBx * fCy; + const BOOL bGreater = ( fDen > 0. ); + + bOk = TRUE; + + if ( bGreater ) + { + if ( ( fA < 0. ) || ( fA > fDen ) ) + bOk = FALSE; + } + else if ( ( fA > 0. ) || ( fA < fDen ) ) + bOk = FALSE; + + if ( bOk ) + { + const double fB = fAx * fCy - fAy * fCx; + + if ( bGreater ) + { + if ( ( fB < 0. ) || ( fB > fDen ) ) + bOk = FALSE; + } + else if ( ( fB > 0. ) || ( fB < fDen ) ) + bOk = FALSE; + + if( bOk ) + { + const double fAlpha = fA / fDen; + + rIntersectionX = ( maStart.X() + fAlpha * fAx ); + rIntersectionY = ( maStart.Y() + fAlpha * fAy ); + } + } + } + + return bOk; +} + +// ------------------------------------------------------------------------ + +BOOL Line::Intersection( const Rectangle& rRect, Line& rIntersection ) const +{ + const BOOL bStartInside = rRect.IsInside( maStart ); + const BOOL bEndInside = rRect.IsInside( maEnd ); + BOOL bRet = TRUE; + + if( bStartInside && bEndInside ) + { + // line completely inside rect + rIntersection.maStart = maStart; + rIntersection.maEnd = maEnd; + } + else + { + // calculate intersections + const Point aTL( rRect.TopLeft() ), aTR( rRect.TopRight() ); + const Point aBR( rRect.BottomRight() ), aBL( rRect.BottomLeft() ); + Point aIntersect1, aIntersect2; + Point* pCurIntersection = &aIntersect1; + + if( Intersection( Line( aTL, aTR ), *pCurIntersection ) ) + pCurIntersection = &aIntersect2; + + if( Intersection( Line( aTR, aBR ), *pCurIntersection ) ) + pCurIntersection = ( pCurIntersection == &aIntersect1 ) ? &aIntersect2 : NULL; + + if( pCurIntersection && Intersection( Line( aBR, aBL ), *pCurIntersection ) ) + pCurIntersection = ( pCurIntersection == &aIntersect1 ) ? &aIntersect2 : NULL; + + if( pCurIntersection && Intersection( Line( aBL, aTL ), *pCurIntersection ) ) + pCurIntersection = ( pCurIntersection == &aIntersect1 ) ? &aIntersect2 : NULL; + + if( !pCurIntersection ) + { + // two intersections + rIntersection.maStart = aIntersect1; + rIntersection.maEnd = aIntersect2; + } + else if( pCurIntersection == &aIntersect2 ) + { + // one intersection + rIntersection.maStart = aIntersect1; + + if( ( maStart != aIntersect1 ) && bStartInside ) + rIntersection.maEnd = maStart; + else if( ( maEnd != aIntersect1 ) && bEndInside ) + rIntersection.maEnd = maEnd; + else + rIntersection.maEnd = rIntersection.maStart; + } + else + bRet = FALSE; + } + + return bRet; +} + +// ------------------------------------------------------------------------ + +Point Line::NearestPoint( const Point& rPoint ) const +{ + Point aRetPt; + + if ( maStart != maEnd ) + { + const double fDistX = maEnd.X() - maStart.X(); + const double fDistY = maStart.Y() - maEnd.Y(); + const double fTau = ( ( maStart.Y() - rPoint.Y() ) * fDistY - + ( maStart.X() - rPoint.X() ) * fDistX ) / + ( fDistX * fDistX + fDistY * fDistY ); + + if( fTau < 0.0 ) + aRetPt = maStart; + else if( fTau <= 1.0 ) + { + aRetPt.X() = FRound( maStart.X() + fTau * fDistX ); + aRetPt.Y() = FRound( maStart.Y() - fTau * fDistY ); + } + else + aRetPt = maEnd; + } + else + aRetPt = maStart; + + return aRetPt; +} + +// ------------------------------------------------------------------------ + +double Line::GetDistance( const double& rPtX, const double& rPtY ) const +{ + double fDist; + + if( maStart != maEnd ) + { + const double fDistX = maEnd.X() - maStart.X(); + const double fDistY = maEnd.Y() - maStart.Y(); + const double fACX = maStart.X() - rPtX; + const double fACY = maStart.Y() - rPtY; + const double fL2 = fDistX * fDistX + fDistY * fDistY; + const double fR = ( fACY * -fDistY - fACX * fDistX ) / fL2; + const double fS = ( fACY * fDistX - fACX * fDistY ) / fL2; + + if( fR < 0.0 ) + { + fDist = hypot( maStart.X() - rPtX, maStart.Y() - rPtY ); + + if( fS < 0.0 ) + fDist *= -1.0; + } + else if( fR <= 1.0 ) + fDist = fS * sqrt( fL2 ); + else + { + fDist = hypot( maEnd.X() - rPtX, maEnd.Y() - rPtY ); + + if( fS < 0.0 ) + fDist *= -1.0; + } + } + else + fDist = hypot( maStart.X() - rPtX, maStart.Y() - rPtY ); + + return fDist; +} + +// ------------------------------------------------------------------------ + +void Line::Enum( const Link& rEnumLink ) +{ + DBG_ASSERT( rEnumLink.IsSet(), "This call doesn't make any sense with !rEnumLink.IsSet()" ); + + Point aEnum; + long nX; + long nY; + + if( maStart.X() == maEnd.X() ) + { + const long nEndY = maEnd.Y(); + + nX = maStart.X(); + nY = maStart.Y(); + + if( nEndY > nY ) + { + while( nY <= nEndY ) + { + aEnum.X() = nX; + aEnum.Y() = nY++; + rEnumLink.Call( &aEnum ); + } + } + else + { + while( nY >= nEndY ) + { + aEnum.X() = nX; + aEnum.Y() = nY--; + rEnumLink.Call( &aEnum ); + } + } + } + else if( maStart.Y() == maEnd.Y() ) + { + const long nEndX = maEnd.X(); + + nX = maStart.X(); + nY = maStart.Y(); + + if( nEndX > nX ) + { + while( nX <= nEndX ) + { + aEnum.X() = nX++; + aEnum.Y() = nY; + rEnumLink.Call( &aEnum ); + } + } + else + { + while( nX >= nEndX ) + { + aEnum.X() = nX--; + aEnum.Y() = nY; + rEnumLink.Call( &aEnum ); + } + } + } + else + { + const long nDX = labs( maEnd.X() - maStart.X() ); + const long nDY = labs( maEnd.Y() - maStart.Y() ); + const long nStartX = maStart.X(); + const long nStartY = maStart.Y(); + const long nEndX = maEnd.X(); + const long nEndY = maEnd.Y(); + const long nXInc = ( nStartX < nEndX ) ? 1L : -1L; + const long nYInc = ( nStartY < nEndY ) ? 1L : -1L; + + if( nDX >= nDY ) + { + const long nDYX = ( nDY - nDX ) << 1; + const long nDY2 = nDY << 1; + long nD = nDY2 - nDX; + + for( nX = nStartX, nY = nStartY; nX != nEndX; nX += nXInc ) + { + aEnum.X() = nX; + aEnum.Y() = nY; + rEnumLink.Call( &aEnum ); + + if( nD < 0L ) + nD += nDY2; + else + nD += nDYX, nY += nYInc; + } + } + else + { + const long nDYX = ( nDX - nDY ) << 1; + const long nDY2 = nDX << 1; + long nD = nDY2 - nDY; + + for( nX = nStartX, nY = nStartY; nY != nEndY; nY += nYInc ) + { + aEnum.X() = nX; + aEnum.Y() = nY; + rEnumLink.Call( &aEnum ); + + if( nD < 0L ) + nD += nDY2; + else + nD += nDYX, nX += nXInc; + } + } + + // last point + aEnum.X() = nEndX; + aEnum.Y() = nEndY; + rEnumLink.Call( &aEnum ); + } +} diff --git a/tools/source/generic/makefile.mk b/tools/source/generic/makefile.mk index 1fb916dd9da9..662f5a817891 100644 --- a/tools/source/generic/makefile.mk +++ b/tools/source/generic/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.4 $ +# $Revision: 1.5 $ # -# last change: $Author: rt $ $Date: 2002-01-10 13:51:08 $ +# last change: $Author: hr $ $Date: 2003-03-27 17:04:16 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -73,31 +73,33 @@ TARGET=gen # --- Files -------------------------------------------------------- +EXCEPTIONSFILES= $(SLO)$/poly.obj + SLOFILES= $(SLO)$/toolsin.obj \ $(SLO)$/link.obj \ $(SLO)$/bigint.obj \ $(SLO)$/fract.obj \ - $(SLO)$/solmath.obj \ $(SLO)$/color.obj \ $(SLO)$/l2txtenc.obj \ $(SLO)$/gen.obj \ $(SLO)$/config.obj \ - $(SLO)$/supd.obj - + $(SLO)$/supd.obj \ + $(SLO)$/poly.obj \ + $(SLO)$/poly2.obj \ + $(SLO)$/line.obj -.IF "$(UPDATER)"!="" OBJFILES= $(OBJ)$/toolsin.obj \ $(OBJ)$/link.obj \ $(OBJ)$/bigint.obj \ $(OBJ)$/fract.obj \ - $(OBJ)$/solmath.obj \ $(OBJ)$/color.obj \ $(OBJ)$/l2txtenc.obj \ $(OBJ)$/gen.obj \ $(OBJ)$/config.obj \ - $(OBJ)$/supd.obj - -.ENDIF + $(OBJ)$/supd.obj \ + $(OBJ)$/poly.obj \ + $(OBJ)$/poly2.obj \ + $(OBJ)$/line.obj # --- Targets ------------------------------------------------------ diff --git a/tools/source/generic/poly.cxx b/tools/source/generic/poly.cxx new file mode 100644 index 000000000000..a68ccb063e24 --- /dev/null +++ b/tools/source/generic/poly.cxx @@ -0,0 +1,2189 @@ +/************************************************************************* + * + * $RCSfile: poly.cxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: hr $ $Date: 2003-03-27 17:04:17 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <vector> +#include <iterator> +#include <algorithm> +#include <cstring> +#include <limits.h> +#include <cmath> + +#define _SV_POLY_CXX + +#ifndef _BIGINT_HXX +#include <bigint.hxx> +#endif +#ifndef _DEBUG_HXX +#include <debug.hxx> +#endif +#ifndef _STREAM_HXX +#include <stream.hxx> +#endif +#ifndef _VCOMPAT_HXX +#include <vcompat.hxx> +#endif +#ifndef _POLY_H +#include <poly.h> +#endif +#ifndef _LINE_HXX +#include <line.hxx> +#endif +#ifndef _VECTOR2D_H +#include <vector2d.hxx> +#endif +#define private public +#ifndef _POLY_HXX +#include <poly.hxx> +#endif +#undef private + +// ======================================================================= + +DBG_NAME( Polygon ); + +// ----------------------------------------------------------------------- + +#define EDGE_LEFT 1 +#define EDGE_TOP 2 +#define EDGE_RIGHT 4 +#define EDGE_BOTTOM 8 +#define EDGE_HORZ (EDGE_RIGHT | EDGE_LEFT) +#define EDGE_VERT (EDGE_TOP | EDGE_BOTTOM) +#define SMALL_DVALUE 0.0000001 +#define FSQRT2 1.4142135623730950488016887242097 + +// ----------------------------------------------------------------------- + +static ImplPolygonData aStaticImplPolygon = +{ + NULL, NULL, 0, 0 +}; + +// ======================================================================= + +ImplPolygon::ImplPolygon( USHORT nInitSize, BOOL bFlags ) +{ + if ( nInitSize ) + { + mpPointAry = (Point*)new char[(ULONG)nInitSize*sizeof(Point)]; + memset( mpPointAry, 0, (ULONG)nInitSize*sizeof(Point) ); + } + else + mpPointAry = NULL; + + if( bFlags ) + { + mpFlagAry = new BYTE[ nInitSize ]; + memset( mpPointAry, 0, nInitSize ); + } + else + mpFlagAry = NULL; + + mnRefCount = 1; + mnPoints = nInitSize; +} + +// ----------------------------------------------------------------------- + +ImplPolygon::ImplPolygon( const ImplPolygon& rImpPoly ) +{ + if ( rImpPoly.mnPoints ) + { + mpPointAry = (Point*)new char[(ULONG)rImpPoly.mnPoints*sizeof(Point)]; + memcpy( mpPointAry, rImpPoly.mpPointAry, (ULONG)rImpPoly.mnPoints*sizeof(Point) ); + + if( rImpPoly.mpFlagAry ) + { + mpFlagAry = new BYTE[ rImpPoly.mnPoints ]; + memcpy( mpFlagAry, rImpPoly.mpFlagAry, rImpPoly.mnPoints ); + } + else + mpFlagAry = NULL; + } + else + { + mpPointAry = NULL; + mpFlagAry = NULL; + } + + mnRefCount = 1; + mnPoints = rImpPoly.mnPoints; +} + +// ----------------------------------------------------------------------- + +ImplPolygon::ImplPolygon( USHORT nInitSize, const Point* pInitAry, const BYTE* pInitFlags ) +{ + if ( nInitSize ) + { + mpPointAry = (Point*)new char[(ULONG)nInitSize*sizeof(Point)]; + memcpy( mpPointAry, pInitAry, (ULONG)nInitSize*sizeof( Point ) ); + + if( pInitFlags ) + { + mpFlagAry = new BYTE[ nInitSize ]; + memcpy( mpFlagAry, pInitFlags, nInitSize ); + } + else + mpFlagAry = NULL; + } + else + { + mpPointAry = NULL; + mpFlagAry = NULL; + } + + mnRefCount = 1; + mnPoints = nInitSize; +} + +// ----------------------------------------------------------------------- + +ImplPolygon::~ImplPolygon() +{ + if ( mpPointAry ) + { + delete[] (char*) mpPointAry; + } + + if( mpFlagAry ) + delete[] mpFlagAry; +} + +// ----------------------------------------------------------------------- + +void ImplPolygon::ImplSetSize( USHORT nNewSize, BOOL bResize ) +{ + if( mnPoints == nNewSize ) + return; + + Point* pNewAry; + + if ( nNewSize ) + { + pNewAry = (Point*)new char[(ULONG)nNewSize*sizeof(Point)]; + + if ( bResize ) + { + // Alte Punkte kopieren + if ( mnPoints < nNewSize ) + { + // Neue Punkte mit 0 initialisieren + memset( pNewAry+mnPoints, 0, (ULONG)(nNewSize-mnPoints)*sizeof(Point) ); + if ( mpPointAry ) + memcpy( pNewAry, mpPointAry, mnPoints*sizeof(Point) ); + } + else + { + if ( mpPointAry ) + memcpy( pNewAry, mpPointAry, (ULONG)nNewSize*sizeof(Point) ); + } + } + } + else + pNewAry = NULL; + + if ( mpPointAry ) + delete[] (char*) mpPointAry; + + // ggf. FlagArray beruecksichtigen + if( mpFlagAry ) + { + BYTE* pNewFlagAry; + + if( nNewSize ) + { + pNewFlagAry = new BYTE[ nNewSize ]; + + if( bResize ) + { + // Alte Flags kopieren + if ( mnPoints < nNewSize ) + { + // Neue Punkte mit 0 initialisieren + memset( pNewFlagAry+mnPoints, 0, nNewSize-mnPoints ); + memcpy( pNewFlagAry, mpFlagAry, mnPoints ); + } + else + memcpy( pNewFlagAry, mpFlagAry, nNewSize ); + } + } + else + pNewFlagAry = NULL; + + delete[] mpFlagAry; + mpFlagAry = pNewFlagAry; + } + + mpPointAry = pNewAry; + mnPoints = nNewSize; +} + +// ----------------------------------------------------------------------- + +void ImplPolygon::ImplSplit( USHORT nPos, USHORT nSpace, ImplPolygon* pInitPoly ) +{ + const ULONG nSpaceSize = nSpace * sizeof( Point ); + const USHORT nNewSize = mnPoints + nSpace; + + if( nPos >= mnPoints ) + { + // Hinten anhaengen + nPos = mnPoints; + ImplSetSize( nNewSize, TRUE ); + + if( pInitPoly ) + { + memcpy( mpPointAry + nPos, pInitPoly->mpPointAry, nSpaceSize ); + + if( pInitPoly->mpFlagAry ) + memcpy( mpFlagAry + nPos, pInitPoly->mpFlagAry, nSpace ); + } + } + else + { + // PointArray ist in diesem Zweig immer vorhanden + const USHORT nSecPos = nPos + nSpace; + const USHORT nRest = mnPoints - nPos; + + Point* pNewAry = (Point*) new char[ (ULONG) nNewSize * sizeof( Point ) ]; + + memcpy( pNewAry, mpPointAry, nPos * sizeof( Point ) ); + + if( pInitPoly ) + memcpy( pNewAry + nPos, pInitPoly->mpPointAry, nSpaceSize ); + else + memset( pNewAry + nPos, 0, nSpaceSize ); + + memcpy( pNewAry + nSecPos, mpPointAry + nPos, nRest * sizeof( Point ) ); + delete[] (char*) mpPointAry; + + // ggf. FlagArray beruecksichtigen + if( mpFlagAry ) + { + BYTE* pNewFlagAry = new BYTE[ nNewSize ]; + + memcpy( pNewFlagAry, mpFlagAry, nPos ); + + if( pInitPoly && pInitPoly->mpFlagAry ) + memcpy( pNewFlagAry + nPos, pInitPoly->mpFlagAry, nSpace ); + else + memset( pNewFlagAry + nPos, 0, nSpace ); + + memcpy( pNewFlagAry + nSecPos, mpFlagAry + nPos, nRest ); + delete[] mpFlagAry; + mpFlagAry = pNewFlagAry; + } + + mpPointAry = pNewAry; + mnPoints = nNewSize; + } +} + +// ----------------------------------------------------------------------- + +void ImplPolygon::ImplRemove( USHORT nPos, USHORT nCount ) +{ + const USHORT nRemoveCount = Min( (USHORT) ( mnPoints - nPos ), (USHORT) nCount ); + + if( nRemoveCount ) + { + const USHORT nNewSize = mnPoints - nRemoveCount; + const USHORT nSecPos = nPos + nRemoveCount; + const USHORT nRest = mnPoints - nSecPos; + + Point* pNewAry = (Point*) new char[ (ULONG) nNewSize * sizeof( Point ) ]; + + memcpy( pNewAry, mpPointAry, nPos * sizeof( Point ) ); + memcpy( pNewAry + nPos, mpPointAry + nSecPos, nRest * sizeof( Point ) ); + + delete[] (char*) mpPointAry; + + // ggf. FlagArray beruecksichtigen + if( mpFlagAry ) + { + BYTE* pNewFlagAry = new BYTE[ nNewSize ]; + + memcpy( pNewFlagAry, mpFlagAry, nPos ); + memcpy( pNewFlagAry + nPos, mpFlagAry + nSecPos, nRest ); + delete[] mpFlagAry; + mpFlagAry = pNewFlagAry; + } + + mpPointAry = pNewAry; + mnPoints = nNewSize; + } +} + +// ----------------------------------------------------------------------- + +void ImplPolygon::ImplCreateFlagArray() +{ + if( !mpFlagAry ) + { + mpFlagAry = new BYTE[ mnPoints ]; + memset( mpFlagAry, 0, mnPoints ); + } +} + +// ======================================================================= + +inline void ImplMakeUnique( Polygon* p ) +{ + // Falls noch andere Referenzen bestehen, dann kopieren + if ( p->mpImplPolygon->mnRefCount != 1 ) + { + if ( p->mpImplPolygon->mnRefCount ) + p->mpImplPolygon->mnRefCount--; + p->mpImplPolygon = new ImplPolygon( *(p->mpImplPolygon) ); + } +} + +// ----------------------------------------------------------------------- + +inline double ImplGetAngle( const Point& rCenter, const Point& rPt ) +{ + const long nDX = rPt.X() - rCenter.X(); + return( atan2( -rPt.Y() + rCenter.Y(), ( ( nDX == 0L ) ? 0.000000001 : nDX ) ) ); +} + +// ----------------------------------------------------------------------- + +Polygon::Polygon() +{ + DBG_CTOR( Polygon, NULL ); + mpImplPolygon = (ImplPolygon*)(&aStaticImplPolygon); +} + +// ----------------------------------------------------------------------- + +Polygon::Polygon( USHORT nSize ) +{ + DBG_CTOR( Polygon, NULL ); + + if ( nSize ) + mpImplPolygon = new ImplPolygon( nSize ); + else + mpImplPolygon = (ImplPolygon*)(&aStaticImplPolygon); +} + +// ----------------------------------------------------------------------- + +Polygon::Polygon( USHORT nPoints, const Point* pPtAry, const BYTE* pFlagAry ) +{ + DBG_CTOR( Polygon, NULL ); + + if( nPoints ) + mpImplPolygon = new ImplPolygon( nPoints, pPtAry, pFlagAry ); + else + mpImplPolygon = (ImplPolygon*)(&aStaticImplPolygon); +} + +// ----------------------------------------------------------------------- + +Polygon::Polygon( const Polygon& rPoly ) +{ + DBG_CTOR( Polygon, NULL ); + DBG_CHKOBJ( &rPoly, Polygon, NULL ); + DBG_ASSERT( rPoly.mpImplPolygon->mnRefCount < 0xFFFE, "Polygon: RefCount overflow" ); + + mpImplPolygon = rPoly.mpImplPolygon; + if ( mpImplPolygon->mnRefCount ) + mpImplPolygon->mnRefCount++; +} + +// ----------------------------------------------------------------------- + +Polygon::Polygon( const Rectangle& rRect ) +{ + DBG_CTOR( Polygon, NULL ); + + if ( rRect.IsEmpty() ) + mpImplPolygon = (ImplPolygon*)(&aStaticImplPolygon); + else + { + mpImplPolygon = new ImplPolygon( 5 ); + mpImplPolygon->mpPointAry[0] = rRect.TopLeft(); + mpImplPolygon->mpPointAry[1] = rRect.TopRight(); + mpImplPolygon->mpPointAry[2] = rRect.BottomRight(); + mpImplPolygon->mpPointAry[3] = rRect.BottomLeft(); + mpImplPolygon->mpPointAry[4] = rRect.TopLeft(); + } +} + +// ----------------------------------------------------------------------- + +Polygon::Polygon( const Rectangle& rRect, ULONG nHorzRound, ULONG nVertRound ) +{ + DBG_CTOR( Polygon, NULL ); + + if ( rRect.IsEmpty() ) + mpImplPolygon = (ImplPolygon*)(&aStaticImplPolygon); + else + { + nHorzRound = Min( nHorzRound, (ULONG) labs( rRect.GetWidth() >> 1 ) ); + nVertRound = Min( nVertRound, (ULONG) labs( rRect.GetHeight() >> 1 ) ); + + if( !nHorzRound && !nVertRound ) + { + mpImplPolygon = new ImplPolygon( 5 ); + mpImplPolygon->mpPointAry[0] = rRect.TopLeft(); + mpImplPolygon->mpPointAry[1] = rRect.TopRight(); + mpImplPolygon->mpPointAry[2] = rRect.BottomRight(); + mpImplPolygon->mpPointAry[3] = rRect.BottomLeft(); + mpImplPolygon->mpPointAry[4] = rRect.TopLeft(); + } + else + { + const Point aTL( rRect.Left() + nHorzRound, rRect.Top() + nVertRound ); + const Point aTR( rRect.Right() - nHorzRound, rRect.Top() + nVertRound ); + const Point aBR( rRect.Right() - nHorzRound, rRect.Bottom() - nVertRound ); + const Point aBL( rRect.Left() + nHorzRound, rRect.Bottom() - nVertRound ); + Polygon* pEllipsePoly = new Polygon( Point(), nHorzRound, nVertRound ); + USHORT i, nEnd, nSize4 = pEllipsePoly->GetSize() >> 2; + + mpImplPolygon = new ImplPolygon( pEllipsePoly->GetSize() + 1 ); + + const Point* pSrcAry = pEllipsePoly->GetConstPointAry(); + Point* pDstAry = mpImplPolygon->mpPointAry; + + for( i = 0, nEnd = nSize4; i < nEnd; i++ ) + ( pDstAry[ i ] = pSrcAry[ i ] ) += aTR; + + for( nEnd += nSize4; i < nEnd; i++ ) + ( pDstAry[ i ] = pSrcAry[ i ] ) += aTL; + + for( nEnd += nSize4; i < nEnd; i++ ) + ( pDstAry[ i ] = pSrcAry[ i ] ) += aBL; + + for( nEnd += nSize4; i < nEnd; i++ ) + ( pDstAry[ i ] = pSrcAry[ i ] ) += aBR; + + pDstAry[ nEnd ] = pDstAry[ 0 ]; + delete pEllipsePoly; + } + } +} + +// ----------------------------------------------------------------------- + +Polygon::Polygon( const Point& rCenter, long nRadX, long nRadY, USHORT nPoints ) +{ + DBG_CTOR( Polygon, NULL ); + + if( nRadX && nRadY ) + { + // Default berechnen (abhaengig von Groesse) + if( !nPoints ) + { + nPoints = (USHORT) ( F_PI * ( 1.5 * ( nRadX + nRadY ) - + sqrt( (double) labs( nRadX * nRadY ) ) ) ); + + nPoints = (USHORT) MinMax( nPoints, 32, 256 ); + + if( ( nRadX > 32 ) && ( nRadY > 32 ) && ( nRadX + nRadY ) < 8192 ) + nPoints >>= 1; + } + + // Anzahl der Punkte auf durch 4 teilbare Zahl aufrunden + mpImplPolygon = new ImplPolygon( nPoints = (nPoints + 3) & ~3 ); + + Point* pPt; + USHORT i; + USHORT nPoints2 = nPoints >> 1; + USHORT nPoints4 = nPoints >> 2; + double nAngle; + double nAngleStep = F_PI2 / ( nPoints4 - 1 ); + + for( i=0, nAngle = 0.0; i < nPoints4; i++, nAngle += nAngleStep ) + { + long nX = FRound( nRadX * cos( nAngle ) ); + long nY = FRound( -nRadY * sin( nAngle ) ); + + pPt = &(mpImplPolygon->mpPointAry[i]); + pPt->X() = nX + rCenter.X(); + pPt->Y() = nY + rCenter.Y(); + pPt = &(mpImplPolygon->mpPointAry[nPoints2-i-1]); + pPt->X() = -nX + rCenter.X(); + pPt->Y() = nY + rCenter.Y(); + pPt = &(mpImplPolygon->mpPointAry[i+nPoints2]); + pPt->X() = -nX + rCenter.X(); + pPt->Y() = -nY + rCenter.Y(); + pPt = &(mpImplPolygon->mpPointAry[nPoints-i-1]); + pPt->X() = nX + rCenter.X(); + pPt->Y() = -nY + rCenter.Y(); + } + } + else + mpImplPolygon = (ImplPolygon*)(&aStaticImplPolygon); +} + +// ----------------------------------------------------------------------- + +Polygon::Polygon( const Rectangle& rBound, + const Point& rStart, const Point& rEnd, PolyStyle eStyle ) +{ + DBG_CTOR( Polygon, NULL ); + + const long nWidth = rBound.GetWidth(); + const long nHeight = rBound.GetHeight(); + + if( ( nWidth > 1 ) && ( nHeight > 1 ) ) + { + const Point aCenter( rBound.Center() ); + const long nRadX = aCenter.X() - rBound.Left(); + const long nRadY = aCenter.Y() - rBound.Top(); + USHORT nPoints; + + nPoints = (USHORT) ( F_PI * ( 1.5 * ( nRadX + nRadY ) - + sqrt( (double) labs( nRadX * nRadY ) ) ) ); + + nPoints = (USHORT) MinMax( nPoints, 32, 256 ); + + if( ( nRadX > 32 ) && ( nRadY > 32 ) && ( nRadX + nRadY ) < 8192 ) + nPoints >>= 1; + + // Winkel berechnen + const double fRadX = nRadX; + const double fRadY = nRadY; + const double fCenterX = aCenter.X(); + const double fCenterY = aCenter.Y(); + double fStart = ImplGetAngle( aCenter, rStart ); + double fEnd = ImplGetAngle( aCenter, rEnd ); + double fDiff = fEnd - fStart; + double fStep; + USHORT nStart; + USHORT nEnd; + + if( fDiff < 0. ) + fDiff += F_2PI; + + // Punktanzahl proportional verkleinern ( fDiff / (2PI) ); + // ist eingentlich nur fuer einen Kreis richtig; wir + // machen es hier aber trotzdem + nPoints = Max( (USHORT) ( ( fDiff * 0.1591549 ) * nPoints ), (USHORT) 16 ); + fStep = fDiff / ( nPoints - 1 ); + + if( POLY_PIE == eStyle ) + { + const Point aCenter( FRound( fCenterX ), FRound( fCenterY ) ); + + nStart = 1; + nEnd = nPoints + 1; + mpImplPolygon = new ImplPolygon( nPoints + 2 ); + mpImplPolygon->mpPointAry[ 0 ] = aCenter; + mpImplPolygon->mpPointAry[ nEnd ] = aCenter; + } + else + { + mpImplPolygon = new ImplPolygon( ( POLY_CHORD == eStyle ) ? ( nPoints + 1 ) : nPoints ); + nStart = 0; + nEnd = nPoints; + } + + for(; nStart < nEnd; nStart++, fStart += fStep ) + { + Point& rPt = mpImplPolygon->mpPointAry[ nStart ]; + + rPt.X() = FRound( fCenterX + fRadX * cos( fStart ) ); + rPt.Y() = FRound( fCenterY - fRadY * sin( fStart ) ); + } + + if( POLY_CHORD == eStyle ) + mpImplPolygon->mpPointAry[ nPoints ] = mpImplPolygon->mpPointAry[ 0 ]; + } + else + mpImplPolygon = (ImplPolygon*) &aStaticImplPolygon; +} + +// ----------------------------------------------------------------------- + +Polygon::Polygon( const Point& rBezPt1, const Point& rCtrlPt1, + const Point& rBezPt2, const Point& rCtrlPt2, + USHORT nPoints ) +{ + DBG_CTOR( Polygon, NULL ); + + nPoints = ( 0 == nPoints ) ? 25 : ( ( nPoints < 2 ) ? 2 : nPoints ); + + const double fInc = 1.0 / ( nPoints - 1 ); + double fK_1 = 0.0, fK1_1 = 1.0; + double fK_2, fK_3, fK1_2, fK1_3, fK12, fK21; + const double fX0 = rBezPt1.X(); + const double fY0 = rBezPt1.Y(); + const double fX1 = 3.0 * rCtrlPt1.X(); + const double fY1 = 3.0 * rCtrlPt1.Y(); + const double fX2 = 3.0 * rCtrlPt2.X();; + const double fY2 = 3.0 * rCtrlPt2.Y();; + const double fX3 = rBezPt2.X(); + const double fY3 = rBezPt2.Y(); + + mpImplPolygon = new ImplPolygon( nPoints ); + + for( USHORT i = 0; i < nPoints; i++, fK_1 += fInc, fK1_1 -= fInc ) + { + Point& rPt = mpImplPolygon->mpPointAry[ i ]; + + fK_2 = fK_1, fK_3 = ( fK_2 *= fK_1 ), fK_3 *= fK_1; + fK1_2 = fK1_1, fK1_3 = ( fK1_2 *= fK1_1 ), fK1_3 *= fK1_1; + fK12 = fK_1 * fK1_2, fK21 = fK_2 * fK1_1; + + rPt.X() = FRound( fK1_3 * fX0 + fK12 * fX1 + fK21 * fX2 + fK_3 * fX3 ); + rPt.Y() = FRound( fK1_3 * fY0 + fK12 * fY1 + fK21 * fY2 + fK_3 * fY3 ); + } +} + +// ----------------------------------------------------------------------- + +Polygon::~Polygon() +{ + DBG_DTOR( Polygon, NULL ); + + // Wenn es keine statischen ImpDaten sind, dann loeschen, wenn es + // die letzte Referenz ist, sonst Referenzcounter decrementieren + if ( mpImplPolygon->mnRefCount ) + { + if ( mpImplPolygon->mnRefCount > 1 ) + mpImplPolygon->mnRefCount--; + else + delete mpImplPolygon; + } +} + +// ----------------------------------------------------------------------- + +Point* Polygon::ImplGetPointAry() +{ + DBG_CHKTHIS( Polygon, NULL ); + + ImplMakeUnique( this ); + return (Point*)mpImplPolygon->mpPointAry; +} + +// ----------------------------------------------------------------------- + +BYTE* Polygon::ImplGetFlagAry() +{ + DBG_CHKTHIS( Polygon, NULL ); + + ImplMakeUnique( this ); + mpImplPolygon->ImplCreateFlagArray(); + return mpImplPolygon->mpFlagAry; +} + +// ----------------------------------------------------------------------- + +const Point* Polygon::GetConstPointAry() const +{ + DBG_CHKTHIS( Polygon, NULL ); + return (Point*)mpImplPolygon->mpPointAry; +} + +// ----------------------------------------------------------------------- + +const BYTE* Polygon::GetConstFlagAry() const +{ + DBG_CHKTHIS( Polygon, NULL ); + return mpImplPolygon->mpFlagAry; +} + +// ----------------------------------------------------------------------- + +void Polygon::SetPoint( const Point& rPt, USHORT nPos ) +{ + DBG_CHKTHIS( Polygon, NULL ); + DBG_ASSERT( nPos < mpImplPolygon->mnPoints, + "Polygon::SetPoint(): nPos >= nPoints" ); + + ImplMakeUnique( this ); + mpImplPolygon->mpPointAry[nPos] = rPt; +} + +// ----------------------------------------------------------------------- + +void Polygon::SetFlags( USHORT nPos, PolyFlags eFlags ) +{ + DBG_CHKTHIS( Polygon, NULL ); + DBG_ASSERT( nPos < mpImplPolygon->mnPoints, + "Polygon::SetFlags(): nPos >= nPoints" ); + + // we do only want to create the flag array if there + // is at least one flag different to POLY_NORMAL + if ( mpImplPolygon || ( eFlags != POLY_NORMAL ) ) + { + ImplMakeUnique( this ); + mpImplPolygon->ImplCreateFlagArray(); + mpImplPolygon->mpFlagAry[ nPos ] = (BYTE) eFlags; + } +} + +// ----------------------------------------------------------------------- + +const Point& Polygon::GetPoint( USHORT nPos ) const +{ + DBG_CHKTHIS( Polygon, NULL ); + DBG_ASSERT( nPos < mpImplPolygon->mnPoints, + "Polygon::GetPoint(): nPos >= nPoints" ); + + return mpImplPolygon->mpPointAry[nPos]; +} + +// ----------------------------------------------------------------------- + +PolyFlags Polygon::GetFlags( USHORT nPos ) const +{ + DBG_CHKTHIS( Polygon, NULL ); + DBG_ASSERT( nPos < mpImplPolygon->mnPoints, + "Polygon::GetFlags(): nPos >= nPoints" ); + return( mpImplPolygon->mpFlagAry ? + (PolyFlags) mpImplPolygon->mpFlagAry[ nPos ] : + POLY_NORMAL ); +} + +// ----------------------------------------------------------------------- + +sal_Bool Polygon::HasFlags() const +{ + return mpImplPolygon->mpFlagAry != NULL; +} + +// ----------------------------------------------------------------------- + +BOOL Polygon::IsControl(USHORT nPos) const +{ + DBG_CHKTHIS( Polygon, NULL ); + DBG_ASSERT( nPos < mpImplPolygon->mnPoints, + "Polygon::GetFlags(): nPos >= nPoints" ); + PolyFlags eFlags = mpImplPolygon->mpFlagAry ? + (PolyFlags) mpImplPolygon->mpFlagAry[ nPos ] : POLY_NORMAL; + + return( POLY_CONTROL == eFlags ); +} + +// ----------------------------------------------------------------------- + +BOOL Polygon::IsSmooth(USHORT nPos) const +{ + DBG_CHKTHIS( Polygon, NULL ); + DBG_ASSERT( nPos < mpImplPolygon->mnPoints, + "Polygon::GetFlags(): nPos >= nPoints" ); + PolyFlags eFlags = mpImplPolygon->mpFlagAry ? + (PolyFlags) mpImplPolygon->mpFlagAry[ nPos ] : POLY_NORMAL; + + return( ( POLY_SMOOTH == eFlags ) || ( POLY_SYMMTR == eFlags ) ); +} + +// ----------------------------------------------------------------------- + +BOOL Polygon::IsRect() const +{ + BOOL bIsRect = FALSE; + if ( mpImplPolygon->mpFlagAry == NULL ) + { + if ( ( ( mpImplPolygon->mnPoints == 5 ) && ( mpImplPolygon->mpPointAry[ 0 ] == mpImplPolygon->mpPointAry[ 4 ] ) ) || + ( mpImplPolygon->mnPoints == 4 ) ) + { + if ( ( mpImplPolygon->mpPointAry[ 0 ].X() == mpImplPolygon->mpPointAry[ 3 ].X() ) && + ( mpImplPolygon->mpPointAry[ 0 ].Y() == mpImplPolygon->mpPointAry[ 1 ].Y() ) && + ( mpImplPolygon->mpPointAry[ 1 ].X() == mpImplPolygon->mpPointAry[ 2 ].X() ) && + ( mpImplPolygon->mpPointAry[ 2 ].Y() == mpImplPolygon->mpPointAry[ 3 ].Y() ) ) + bIsRect = TRUE; + } + } + return bIsRect; +} + +// ----------------------------------------------------------------------- + +void Polygon::SetSize( USHORT nNewSize ) +{ + DBG_CHKTHIS( Polygon, NULL ); + + if( nNewSize != mpImplPolygon->mnPoints ) + { + ImplMakeUnique( this ); + mpImplPolygon->ImplSetSize( nNewSize ); + } +} + +// ----------------------------------------------------------------------- + +USHORT Polygon::GetSize() const +{ + DBG_CHKTHIS( Polygon, NULL ); + + return mpImplPolygon->mnPoints; +} + +// ----------------------------------------------------------------------- + +void Polygon::Clear() +{ + DBG_CHKTHIS( Polygon, NULL ); + + if ( mpImplPolygon->mnRefCount ) + { + if ( mpImplPolygon->mnRefCount > 1 ) + mpImplPolygon->mnRefCount--; + else + delete mpImplPolygon; + } + + mpImplPolygon = (ImplPolygon*)(&aStaticImplPolygon); +} + +// ----------------------------------------------------------------------- + +double Polygon::CalcDistance( USHORT nP1, USHORT nP2 ) +{ + DBG_ASSERT( nP1 < mpImplPolygon->mnPoints, + "Polygon::CalcDistance(): nPos1 >= nPoints" ); + DBG_ASSERT( nP2 < mpImplPolygon->mnPoints, + "Polygon::CalcDistance(): nPos2 >= nPoints" ); + + const Point& rP1 = mpImplPolygon->mpPointAry[ nP1 ]; + const Point& rP2 = mpImplPolygon->mpPointAry[ nP2 ]; + const double fDx = rP2.X() - rP1.X(); + const double fDy = rP2.Y() - rP1.Y(); + + return sqrt( fDx * fDx + fDy * fDy ); +} + +// ----------------------------------------------------------------------- + +void Polygon::Optimize( ULONG nOptimizeFlags, const PolyOptimizeData* pData ) +{ + DBG_CHKTHIS( Polygon, NULL ); + DBG_ASSERT( !mpImplPolygon->mpFlagAry, "Optimizing could fail with beziers!" ); + + USHORT nSize = mpImplPolygon->mnPoints; + + if( nOptimizeFlags && nSize ) + { + if( nOptimizeFlags & POLY_OPTIMIZE_EDGES ) + { + const Rectangle aBound( GetBoundRect() ); + const double fArea = ( aBound.GetWidth() + aBound.GetHeight() ) * 0.5; + const USHORT nPercent = pData ? pData->GetPercentValue() : 50; + + Optimize( POLY_OPTIMIZE_NO_SAME ); + ImplReduceEdges( *this, fArea, nPercent ); + } + else if( nOptimizeFlags & ( POLY_OPTIMIZE_REDUCE | POLY_OPTIMIZE_NO_SAME ) ) + { + Polygon aNewPoly; + const Point& rFirst = mpImplPolygon->mpPointAry[ 0 ]; + ULONG nReduce; + + if( nOptimizeFlags & ( POLY_OPTIMIZE_REDUCE ) ) + nReduce = pData ? pData->GetAbsValue() : 4UL; + else + nReduce = 0UL; + + while( nSize && ( mpImplPolygon->mpPointAry[ nSize - 1 ] == rFirst ) ) + nSize--; + + if( nSize > 1 ) + { + USHORT nLast = 0, nNewCount = 1; + + aNewPoly.SetSize( nSize ); + aNewPoly[ 0 ] = rFirst; + + for( USHORT i = 1; i < nSize; i++ ) + { + if( ( mpImplPolygon->mpPointAry[ i ] != mpImplPolygon->mpPointAry[ nLast ] ) && + ( !nReduce || ( nReduce < (ULONG) FRound( CalcDistance( nLast, i ) ) ) ) ) + { + aNewPoly[ nNewCount++ ] = mpImplPolygon->mpPointAry[ nLast = i ]; + } + } + + if( nNewCount == 1 ) + aNewPoly.Clear(); + else + aNewPoly.SetSize( nNewCount ); + } + + *this = aNewPoly; + } + + nSize = mpImplPolygon->mnPoints; + + if( nSize > 1 ) + { + if( ( nOptimizeFlags & POLY_OPTIMIZE_CLOSE ) && + ( mpImplPolygon->mpPointAry[ 0 ] != mpImplPolygon->mpPointAry[ nSize - 1 ] ) ) + { + SetSize( mpImplPolygon->mnPoints + 1 ); + mpImplPolygon->mpPointAry[ mpImplPolygon->mnPoints - 1 ] = mpImplPolygon->mpPointAry[ 0 ]; + } + else if( ( nOptimizeFlags & POLY_OPTIMIZE_OPEN ) && + ( mpImplPolygon->mpPointAry[ 0 ] == mpImplPolygon->mpPointAry[ nSize - 1 ] ) ) + { + const Point& rFirst = mpImplPolygon->mpPointAry[ 0 ]; + + while( nSize && ( mpImplPolygon->mpPointAry[ nSize - 1 ] == rFirst ) ) + nSize--; + + SetSize( nSize ); + } + } + } +} + +// ----------------------------------------------------------------------- + +void Polygon::GetSimple( Polygon& rResult, long nDelta ) const +{ + if( !mpImplPolygon->mpFlagAry ) + rResult = *this; + else + { + ::std::vector< Point > aPointVector; + + for( USHORT i = 0, nCount = GetSize(); i < nCount; ) + { + if( ( ( i + 3 ) < nCount ) && + ( POLY_NORMAL == mpImplPolygon->mpFlagAry[ i ] ) && + ( POLY_CONTROL == mpImplPolygon->mpFlagAry[ i + 1 ] ) && + ( POLY_CONTROL == mpImplPolygon->mpFlagAry[ i + 2 ] ) && + ( POLY_NORMAL == mpImplPolygon->mpFlagAry[ i + 3 ] ) ) + { + const USHORT nSegmentPoints = 25; + const Polygon aSegmentPoly( mpImplPolygon->mpPointAry[ i ], mpImplPolygon->mpPointAry[ i + 1 ], + mpImplPolygon->mpPointAry[ i + 3 ], mpImplPolygon->mpPointAry[ i + 2 ], + nSegmentPoints ); + const USHORT nSegmentSize = aSegmentPoly.GetSize(); + + if( nSegmentSize ) + { + const Point* pPointArray = aSegmentPoly.mpImplPolygon->mpPointAry; + const Point* pCur = pPointArray; + const Point* pLast; + + aPointVector.push_back( *( pLast = pCur ) ); + + for( USHORT j = 1; j < nSegmentSize; j++ ) + if( *( pCur = pPointArray + j ) != *pLast ) + aPointVector.push_back( *( pLast = pCur ) ); + } + + i += 3; + } + else + aPointVector.push_back( mpImplPolygon->mpPointAry[ i++ ] ); + } + + // fill result polygon + rResult = Polygon( aPointVector.size() ); + ::std::vector< Point >::iterator aIter( aPointVector.begin() ), aEnd( aPointVector.end() ); + Point* pPointArray = rResult.mpImplPolygon->mpPointAry; + + while( aIter != aEnd ) + *pPointArray++ = *aIter++; + } +} + +// ======================================================================= + +/* Recursively subdivide cubic bezier curve via deCasteljau. + + @param rPointIter + Output iterator, where the subdivided polylines are written to. + + @param d + Squared difference of curve to a straight line + + @param P* + Exactly four points, interpreted as support and control points of + a cubic bezier curve. Must be in device coordinates, since stop + criterion is based on the following assumption: the device has a + finite resolution, it is thus sufficient to stop subdivision if the + curve does not deviate more than one pixel from a straight line. + +*/ +static void ImplAdaptiveSubdivide( ::std::back_insert_iterator< ::std::vector< Point > >& rPointIter, + const double old_d2, + int recursionDepth, + const double d2, + const double P1x, const double P1y, + const double P2x, const double P2y, + const double P3x, const double P3y, + const double P4x, const double P4y ) +{ + // Hard limit on recursion depth, empiric number. + enum {maxRecursionDepth=128}; + + // Perform bezier flatness test (lecture notes from R. Schaback, + // Mathematics of Computer-Aided Design, Uni Goettingen, 2000) + // + // ||P(t) - L(t)|| <= max ||b_j - b_0 - j/n(b_n - b_0)|| + // 0<=j<=n + // + // What is calculated here is an upper bound to the distance from + // a line through b_0 and b_3 (P1 and P4 in our notation) and the + // curve. We can drop 0 and n from the running indices, since the + // argument of max becomes zero for those cases. + const double fJ1x( P2x - P1x - 1.0/3.0*(P4x - P1x) ); + const double fJ1y( P2y - P1y - 1.0/3.0*(P4y - P1y) ); + const double fJ2x( P3x - P1x - 2.0/3.0*(P4x - P1x) ); + const double fJ2y( P3y - P1y - 2.0/3.0*(P4y - P1y) ); + const double distance2( ::std::max( fJ1x*fJ1x + fJ1y*fJ1y, + fJ2x*fJ2x + fJ2y*fJ2y) ); + + // stop if error measure does not improve anymore. This is a + // safety guard against floating point inaccuracies. + // stop at recursion level 128. This is a safety guard against + // floating point inaccuracies. + // stop if distance from line is guaranteed to be bounded by d + if( old_d2 > d2 && + recursionDepth < maxRecursionDepth && + distance2 >= d2 ) + { + // deCasteljau bezier arc, split at t=0.5 + // Foley/vanDam, p. 508 + const double L1x( P1x ), L1y( P1y ); + const double L2x( (P1x + P2x)*0.5 ), L2y( (P1y + P2y)*0.5 ); + const double Hx ( (P2x + P3x)*0.5 ), Hy ( (P2y + P3y)*0.5 ); + const double L3x( (L2x + Hx)*0.5 ), L3y( (L2y + Hy)*0.5 ); + const double R4x( P4x ), R4y( P4y ); + const double R3x( (P3x + P4x)*0.5 ), R3y( (P3y + P4y)*0.5 ); + const double R2x( (Hx + R3x)*0.5 ), R2y( (Hy + R3y)*0.5 ); + const double R1x( (L3x + R2x)*0.5 ), R1y( (L3y + R2y)*0.5 ); + const double L4x( R1x ), L4y( R1y ); + + // subdivide further + ++recursionDepth; + ImplAdaptiveSubdivide(rPointIter, distance2, recursionDepth, d2, L1x, L1y, L2x, L2y, L3x, L3y, L4x, L4y); + ImplAdaptiveSubdivide(rPointIter, distance2, recursionDepth, d2, R1x, R1y, R2x, R2y, R3x, R3y, R4x, R4y); + } + else + { + // requested resolution reached. + // Add end points to output iterator. + // order is preserved, since this is so to say depth first traversal. + *rPointIter++ = Point( FRound(P1x), FRound(P1y) ); + } +} + +// ======================================================================= + +void Polygon::AdaptiveSubdivide( Polygon& rResult, const double d ) const +{ + if( !mpImplPolygon->mpFlagAry ) + { + rResult = *this; + } + else + { + USHORT i; + USHORT nPts( GetSize() ); + ::std::vector< Point > aPoints; + aPoints.reserve( nPts ); + ::std::back_insert_iterator< ::std::vector< Point > > aPointIter( aPoints ); + + for(i=0; i<nPts;) + { + if( ( i + 3 ) < nPts ) + { + BYTE P1( mpImplPolygon->mpFlagAry[ i ] ); + BYTE P4( mpImplPolygon->mpFlagAry[ i + 3 ] ); + + if( ( POLY_NORMAL == P1 || POLY_SMOOTH == P1 || POLY_SYMMTR == P1 ) && + ( POLY_CONTROL == mpImplPolygon->mpFlagAry[ i + 1 ] ) && + ( POLY_CONTROL == mpImplPolygon->mpFlagAry[ i + 2 ] ) && + ( POLY_NORMAL == P4 || POLY_SMOOTH == P4 || POLY_SYMMTR == P4 ) ) + { + ImplAdaptiveSubdivide( aPointIter, d*d+1.0, 0, d*d, + mpImplPolygon->mpPointAry[ i ].X(), mpImplPolygon->mpPointAry[ i ].Y(), + mpImplPolygon->mpPointAry[ i+1 ].X(), mpImplPolygon->mpPointAry[ i+1 ].Y(), + mpImplPolygon->mpPointAry[ i+2 ].X(), mpImplPolygon->mpPointAry[ i+2 ].Y(), + mpImplPolygon->mpPointAry[ i+3 ].X(), mpImplPolygon->mpPointAry[ i+3 ].Y() ); + i += 3; + continue; + } + } + + *aPointIter++ = mpImplPolygon->mpPointAry[ i++ ]; + } + + // fill result polygon + rResult = Polygon( aPoints.size() ); // ensure sufficient size for copy + ::std::copy(aPoints.begin(), aPoints.end(), rResult.mpImplPolygon->mpPointAry); + } +} + +// ----------------------------------------------------------------------- + +void Polygon::GetIntersection( const PolyPolygon& rPolyPoly, PolyPolygon& rResult ) const +{ + const PolyPolygon aTmp( *this ); + aTmp.GetIntersection( rPolyPoly, rResult ); +} + +// ----------------------------------------------------------------------- + +void Polygon::GetUnion( const PolyPolygon& rPolyPoly, PolyPolygon& rResult ) const +{ + const PolyPolygon aTmp( *this ); + aTmp.GetUnion( rPolyPoly, rResult ); +} + +// ----------------------------------------------------------------------- + +void Polygon::GetDifference( const PolyPolygon& rPolyPoly, PolyPolygon& rResult ) const +{ + const PolyPolygon aTmp( *this ); + aTmp.GetDifference( rPolyPoly, rResult ); +} + +// ----------------------------------------------------------------------- + +void Polygon::GetXOR( const PolyPolygon& rPolyPoly, PolyPolygon& rResult ) const +{ + const PolyPolygon aTmp( *this ); + aTmp.GetXOR( rPolyPoly, rResult ); +} + +// ----------------------------------------------------------------------- + +void Polygon::ImplReduceEdges( Polygon& rPoly, const double& rArea, USHORT nPercent ) +{ + const double fBound = 2000.0 * ( 100 - nPercent ) * 0.01; + USHORT nNumNoChange = 0, nNumRuns = 0; + + while( nNumNoChange < 2 ) + { + USHORT nPntCnt = rPoly.GetSize(), nNewPos = 0; + Polygon aNewPoly( nPntCnt ); + BOOL bChangeInThisRun = FALSE; + + for( USHORT n = 0; n < nPntCnt; n++ ) + { + BOOL bDeletePoint = FALSE; + + if( ( n + nNumRuns ) % 2 ) + { + USHORT nIndPrev = !n ? nPntCnt - 1 : n - 1; + USHORT nIndPrevPrev = !nIndPrev ? nPntCnt - 1 : nIndPrev - 1; + USHORT nIndNext = ( n == nPntCnt-1 ) ? 0 : n + 1; + USHORT nIndNextNext = ( nIndNext == nPntCnt - 1 ) ? 0 : nIndNext + 1; + Vector2D aVec1( rPoly[ nIndPrev ] ); aVec1 -= rPoly[ nIndPrevPrev ]; + Vector2D aVec2( rPoly[ n ] ); aVec2 -= rPoly[ nIndPrev ]; + Vector2D aVec3( rPoly[ nIndNext ] ); aVec3 -= rPoly[ n ]; + Vector2D aVec4( rPoly[ nIndNextNext ] ); aVec4 -= rPoly[ nIndNext ]; + double fDist1 = aVec1.GetLength(), fDist2 = aVec2.GetLength(); + double fDist3 = aVec3.GetLength(), fDist4 = aVec4.GetLength(); + double fTurnB = aVec2.Normalize().Scalar( aVec3.Normalize() ); + + if( fabs( fTurnB ) < ( 1.0 + SMALL_DVALUE ) && fabs( fTurnB ) > ( 1.0 - SMALL_DVALUE ) ) + bDeletePoint = TRUE; + else + { + Vector2D aVecB( rPoly[ nIndNext ] ); + double fDistB = ( aVecB -= rPoly[ nIndPrev ] ).GetLength(); + double fLenWithB = fDist2 + fDist3; + double fLenFact = ( fDistB != 0.0 ) ? fLenWithB / fDistB : 1.0; + double fTurnPrev = aVec1.Normalize().Scalar( aVec2 ); + double fTurnNext = aVec3.Scalar( aVec4.Normalize() ); + double fGradPrev, fGradB, fGradNext; + + if( fabs( fTurnPrev ) < ( 1.0 + SMALL_DVALUE ) && fabs( fTurnPrev ) > ( 1.0 - SMALL_DVALUE ) ) + fGradPrev = 0.0; + else + fGradPrev = acos( fTurnPrev ) / ( aVec1.IsNegative( aVec2 ) ? -F_PI180 : F_PI180 ); + + fGradB = acos( fTurnB ) / ( aVec2.IsNegative( aVec3 ) ? -F_PI180 : F_PI180 ); + + if( fabs( fTurnNext ) < ( 1.0 + SMALL_DVALUE ) && fabs( fTurnNext ) > ( 1.0 - SMALL_DVALUE ) ) + fGradNext = 0.0; + else + fGradNext = acos( fTurnNext ) / ( aVec3.IsNegative( aVec4 ) ? -F_PI180 : F_PI180 ); + + if( ( fGradPrev > 0.0 && fGradB < 0.0 && fGradNext > 0.0 ) || + ( fGradPrev < 0.0 && fGradB > 0.0 && fGradNext < 0.0 ) ) + { + if( ( fLenFact < ( FSQRT2 + SMALL_DVALUE ) ) && + ( ( ( fDist1 + fDist4 ) / ( fDist2 + fDist3 ) ) * 2000.0 ) > fBound ) + { + bDeletePoint = TRUE; + } + } + else + { + double fRelLen = 1.0 - sqrt( fDistB / rArea ); + + if( fRelLen < 0.0 ) + fRelLen = 0.0; + else if( fRelLen > 1.0 ) + fRelLen = 1.0; + + if( ( (UINT32) ( ( ( fLenFact - 1.0 ) * 1000000.0 ) + 0.5 ) < fBound ) && + ( fabs( fGradB ) <= ( fRelLen * fBound * 0.01 ) ) ) + { + bDeletePoint = TRUE; + } + } + } + } + + if( !bDeletePoint ) + aNewPoly[ nNewPos++ ] = rPoly[ n ]; + else + bChangeInThisRun = TRUE; + } + + if( bChangeInThisRun && nNewPos ) + { + aNewPoly.SetSize( nNewPos ); + rPoly = aNewPoly; + nNumNoChange = 0; + } + else + nNumNoChange++; + + nNumRuns++; + } +} + +// ----------------------------------------------------------------------- + +void Polygon::Move( long nHorzMove, long nVertMove ) +{ + DBG_CHKTHIS( Polygon, NULL ); + + // Diese Abfrage sollte man fuer die DrawEngine durchfuehren + if ( !nHorzMove && !nVertMove ) + return; + + ImplMakeUnique( this ); + + // Punkte verschieben + USHORT nCount = mpImplPolygon->mnPoints; + for ( USHORT i = 0; i < nCount; i++ ) + { + Point* pPt = &(mpImplPolygon->mpPointAry[i]); + pPt->X() += nHorzMove; + pPt->Y() += nVertMove; + } +} + +// ----------------------------------------------------------------------- + +void Polygon::Translate(const Point& rTrans) +{ + DBG_CHKTHIS( Polygon, NULL ); + ImplMakeUnique( this ); + + for ( USHORT i = 0, nCount = mpImplPolygon->mnPoints; i < nCount; i++ ) + mpImplPolygon->mpPointAry[ i ] += rTrans; +} + +// ----------------------------------------------------------------------- + +void Polygon::Scale( double fScaleX, double fScaleY ) +{ + DBG_CHKTHIS( Polygon, NULL ); + ImplMakeUnique( this ); + + for ( USHORT i = 0, nCount = mpImplPolygon->mnPoints; i < nCount; i++ ) + { + Point& rPnt = mpImplPolygon->mpPointAry[i]; + rPnt.X() = (long) ( fScaleX * rPnt.X() ); + rPnt.Y() = (long) ( fScaleY * rPnt.Y() ); + } +} + +// ----------------------------------------------------------------------- + +void Polygon::Rotate( const Point& rCenter, USHORT nAngle10 ) +{ + DBG_CHKTHIS( Polygon, NULL ); + nAngle10 %= 3600; + + if( nAngle10 ) + { + const double fAngle = F_PI1800 * nAngle10; + Rotate( rCenter, sin( fAngle ), cos( fAngle ) ); + } +} + +// ----------------------------------------------------------------------- + +void Polygon::Rotate( const Point& rCenter, double fSin, double fCos ) +{ + DBG_CHKTHIS( Polygon, NULL ); + ImplMakeUnique( this ); + + long nX, nY; + long nCenterX = rCenter.X(); + long nCenterY = rCenter.Y(); + + for( USHORT i = 0, nCount = mpImplPolygon->mnPoints; i < nCount; i++ ) + { + Point& rPt = mpImplPolygon->mpPointAry[ i ]; + + nX = rPt.X() - nCenterX; + nY = rPt.Y() - nCenterY; + rPt.X() = (long) FRound( fCos * nX + fSin * nY ) + nCenterX; + rPt.Y() = -(long) FRound( fSin * nX - fCos * nY ) + nCenterY; + } +} + +// ----------------------------------------------------------------------- + +void Polygon::SlantX( long nYRef, double fSin, double fCos ) +{ + DBG_CHKTHIS( Polygon, NULL ); + ImplMakeUnique( this ); + + for( USHORT i = 0, nCount = mpImplPolygon->mnPoints; i < nCount; i++ ) + { + Point& rPnt = mpImplPolygon->mpPointAry[ i ]; + const long nDy = rPnt.Y() - nYRef; + + rPnt.X() += (long)( fSin * nDy ); + rPnt.Y() = nYRef + (long)( fCos * nDy ); + } +} + +// ----------------------------------------------------------------------- + +void Polygon::SlantY( long nXRef, double fSin, double fCos ) +{ + DBG_CHKTHIS( Polygon, NULL ); + ImplMakeUnique( this ); + + for( USHORT i = 0, nCount = mpImplPolygon->mnPoints; i < nCount; i++ ) + { + Point& rPnt = mpImplPolygon->mpPointAry[ i ]; + const long nDx = rPnt.X() - nXRef; + + rPnt.X() = nXRef + (long)( fCos * nDx ); + rPnt.Y() -= (long)( fSin * nDx ); + } +} + +// ----------------------------------------------------------------------- + +void Polygon::Distort( const Rectangle& rRefRect, const Polygon& rDistortedRect ) +{ + DBG_CHKTHIS( Polygon, NULL ); + ImplMakeUnique( this ); + + long Xr, Wr, X1, X2, X3, X4; + long Yr, Hr, Y1, Y2, Y3, Y4; + double fTx, fTy, fUx, fUy; + + Xr = rRefRect.Left(); + Yr = rRefRect.Top(); + Wr = rRefRect.GetWidth(); + Hr = rRefRect.GetHeight(); + + if( Wr && Hr ) + { + DBG_ASSERT( rDistortedRect.mpImplPolygon->mnPoints >= 4, "Distort rect too small!" ); + + X1 = rDistortedRect[0].X(); + Y1 = rDistortedRect[0].Y(); + X2 = rDistortedRect[1].X(); + Y2 = rDistortedRect[1].Y(); + X3 = rDistortedRect[3].X(); + Y3 = rDistortedRect[3].Y(); + X4 = rDistortedRect[2].X(); + Y4 = rDistortedRect[2].Y(); + + for( USHORT i = 0, nCount = mpImplPolygon->mnPoints; i < nCount; i++ ) + { + Point& rPnt = mpImplPolygon->mpPointAry[ i ]; + + fTx = (double)( rPnt.X() - Xr) / Wr; + fTy = (double)( rPnt.Y() - Yr) / Hr; + fUx = 1.0 - fTx; + fUy = 1.0 - fTy; + + rPnt.X() = (long) ( fUy * (fUx * X1 + fTx * X2) + fTy * (fUx * X3 + fTx * X4) ); + rPnt.Y() = (long) ( fUx * (fUy * Y1 + fTy * Y3) + fTx * (fUy * Y2 + fTy * Y4) ); + } + } +} + +// ----------------------------------------------------------------------- + +class ImplPointFilter +{ +public: + virtual void LastPoint() = 0; + virtual void Input( const Point& rPoint ) = 0; +}; + +class ImplPolygonPointFilter : public ImplPointFilter +{ +public: + ImplPolygon* mpPoly; // Nicht loeschen, wird dem Polygon zugewiesen + USHORT mnSize; + + ImplPolygonPointFilter( USHORT nDestSize ) : + mnSize( 0 ) + { + mpPoly = new ImplPolygon( nDestSize ); + } + + virtual void LastPoint(); + virtual void Input( const Point& rPoint ); +}; + +void ImplPolygonPointFilter::Input( const Point& rPoint ) +{ + if ( !mnSize || (rPoint != mpPoly->mpPointAry[mnSize-1]) ) + { + mnSize++; + if ( mnSize > mpPoly->mnPoints ) + mpPoly->ImplSetSize( mnSize ); + mpPoly->mpPointAry[mnSize-1] = rPoint; + } +} + +void ImplPolygonPointFilter::LastPoint() +{ + if ( mnSize < mpPoly->mnPoints ) + mpPoly->ImplSetSize( mnSize ); +}; + +class ImplEdgePointFilter : public ImplPointFilter +{ + Point maFirstPoint; + Point maLastPoint; + ImplPointFilter& mrNextFilter; + const long mnLow; + const long mnHigh; + const int mnEdge; + int mnLastOutside; + BOOL mbFirst; + +public: + ImplEdgePointFilter( int nEdge, long nLow, long nHigh, + ImplPointFilter& rNextFilter ) : + mrNextFilter( rNextFilter ), + mnLow( nLow ), + mnHigh( nHigh ), + mnEdge( nEdge ), + mbFirst( TRUE ) + { + } + + Point EdgeSection( const Point& rPoint, int nEdge ) const; + int VisibleSide( const Point& rPoint ) const; + int IsPolygon() const + { return maFirstPoint == maLastPoint; } + + virtual void Input( const Point& rPoint ); + virtual void LastPoint(); +}; + +inline int ImplEdgePointFilter::VisibleSide( const Point& rPoint ) const +{ + if ( mnEdge & EDGE_HORZ ) + { + return rPoint.X() < mnLow ? EDGE_LEFT : + rPoint.X() > mnHigh ? EDGE_RIGHT : 0; + } + else + { + return rPoint.Y() < mnLow ? EDGE_TOP : + rPoint.Y() > mnHigh ? EDGE_BOTTOM : 0; + } +} + +Point ImplEdgePointFilter::EdgeSection( const Point& rPoint, int nEdge ) const +{ + long lx = maLastPoint.X(); + long ly = maLastPoint.Y(); + long md = rPoint.X() - lx; + long mn = rPoint.Y() - ly; + long nNewX; + long nNewY; + + if ( nEdge & EDGE_VERT ) + { + nNewY = (nEdge == EDGE_TOP) ? mnLow : mnHigh; + long dy = nNewY - ly; + if ( !md ) + nNewX = lx; + else if ( (LONG_MAX / Abs(md)) >= Abs(dy) ) + nNewX = (dy * md) / mn + lx; + else + { + BigInt ady = dy; + ady *= md; + if( ady.IsNeg() ) + if( mn < 0 ) + ady += mn/2; + else + ady -= (mn-1)/2; + else + if( mn < 0 ) + ady -= (mn+1)/2; + else + ady += mn/2; + ady /= mn; + nNewX = (long)ady + lx; + } + } + else + { + nNewX = (nEdge == EDGE_LEFT) ? mnLow : mnHigh; + long dx = nNewX - lx; + if ( !mn ) + nNewY = ly; + else if ( (LONG_MAX / Abs(mn)) >= Abs(dx) ) + nNewY = (dx * mn) / md + ly; + else + { + BigInt adx = dx; + adx *= mn; + if( adx.IsNeg() ) + if( md < 0 ) + adx += md/2; + else + adx -= (md-1)/2; + else + if( md < 0 ) + adx -= (md+1)/2; + else + adx += md/2; + adx /= md; + nNewX = (long)adx + ly; + } + } + + return Point( nNewX, nNewY ); +} + +void ImplEdgePointFilter::Input( const Point& rPoint ) +{ + int nOutside = VisibleSide( rPoint ); + + if ( mbFirst ) + { + maFirstPoint = rPoint; + mbFirst = FALSE; + if ( !nOutside ) + mrNextFilter.Input( rPoint ); + } + else if ( rPoint == maLastPoint ) + return; + else if ( !nOutside ) + { + if ( mnLastOutside ) + mrNextFilter.Input( EdgeSection( rPoint, mnLastOutside ) ); + mrNextFilter.Input( rPoint ); + } + else if ( !mnLastOutside ) + mrNextFilter.Input( EdgeSection( rPoint, nOutside ) ); + else if ( nOutside != mnLastOutside ) + { + mrNextFilter.Input( EdgeSection( rPoint, mnLastOutside ) ); + mrNextFilter.Input( EdgeSection( rPoint, nOutside ) ); + } + + maLastPoint = rPoint; + mnLastOutside = nOutside; +} + +void ImplEdgePointFilter::LastPoint() +{ + if ( !mbFirst ) + { + int nOutside = VisibleSide( maFirstPoint ); + + if ( nOutside != mnLastOutside ) + Input( maFirstPoint ); + mrNextFilter.LastPoint(); + } +} + +// ----------------------------------------------------------------------- + +void Polygon::Clip( const Rectangle& rRect, BOOL bPolygon ) +{ + // #105251# Justify rect befor edge filtering + Rectangle aJustifiedRect( rRect ); + aJustifiedRect.Justify(); + + USHORT nSourceSize = mpImplPolygon->mnPoints; + ImplPolygonPointFilter aPolygon( nSourceSize ); + ImplEdgePointFilter aHorzFilter( EDGE_HORZ, aJustifiedRect.Left(), aJustifiedRect.Right(), + aPolygon ); + ImplEdgePointFilter aVertFilter( EDGE_VERT, aJustifiedRect.Top(), aJustifiedRect.Bottom(), + aHorzFilter ); + + for ( USHORT i = 0; i < nSourceSize; i++ ) + aVertFilter.Input( mpImplPolygon->mpPointAry[i] ); + if ( bPolygon || aVertFilter.IsPolygon() ) + aVertFilter.LastPoint(); + else + aPolygon.LastPoint(); + + // Alte ImpPolygon-Daten loeschen und die vom ImpPolygonPointFilter + // zuweisen + if ( mpImplPolygon->mnRefCount ) + { + if ( mpImplPolygon->mnRefCount > 1 ) + mpImplPolygon->mnRefCount--; + else + delete mpImplPolygon; + } + mpImplPolygon = aPolygon.mpPoly; +} + +// ----------------------------------------------------------------------- + +Rectangle Polygon::GetBoundRect() const +{ + DBG_CHKTHIS( Polygon, NULL ); + DBG_ASSERT( !mpImplPolygon->mpFlagAry, "GetBoundRect could fail with beziers!" ); + + long nXMin, nXMax, nYMin, nYMax; + USHORT nCount = mpImplPolygon->mnPoints; + + for ( USHORT i = 0; i < nCount; i++ ) + { + const Point* pPt = &(mpImplPolygon->mpPointAry[i]); + + if ( !i ) + { + nXMin = nXMax = pPt->X(); + nYMin = nYMax = pPt->Y(); + } + else + { + if ( pPt->X() < nXMin ) + nXMin = pPt->X(); + if ( pPt->X() > nXMax ) + nXMax = pPt->X(); + if ( pPt->Y() < nYMin ) + nYMin = pPt->Y(); + if ( pPt->Y() > nYMax ) + nYMax = pPt->Y(); + } + } + + if ( nCount ) + return Rectangle( nXMin, nYMin, nXMax, nYMax ); + else + return Rectangle(); +} + +// ----------------------------------------------------------------------- + +double Polygon::GetArea() const +{ + const double fArea = GetSignedArea(); + return( ( fArea < 0.0 ) ? -fArea : fArea ); +} + +// ----------------------------------------------------------------------- + +double Polygon::GetSignedArea() const +{ + DBG_CHKTHIS( Polygon, NULL ); + DBG_ASSERT( !mpImplPolygon->mpFlagAry, "GetArea could fail with beziers!" ); + + double fArea = 0.0; + + if( mpImplPolygon->mnPoints > 2 ) + { + const USHORT nCount1 = mpImplPolygon->mnPoints - 1; + + for( USHORT i = 0; i < nCount1; ) + { + const Point& rPt = mpImplPolygon->mpPointAry[ i ]; + const Point& rPt1 = mpImplPolygon->mpPointAry[ ++i ]; + fArea += ( rPt.X() - rPt1.X() ) * ( rPt.Y() + rPt1.Y() ); + } + + const Point& rPt = mpImplPolygon->mpPointAry[ nCount1 ]; + const Point& rPt0 = mpImplPolygon->mpPointAry[ 0 ]; + fArea += ( rPt.X() - rPt0.X() ) * ( rPt.Y() + rPt0.Y() ); + } + + return fArea; +} + +// ----------------------------------------------------------------------- + +BOOL Polygon::IsInside( const Point& rPoint ) const +{ + DBG_CHKTHIS( Polygon, NULL ); + DBG_ASSERT( !mpImplPolygon->mpFlagAry, "IsInside could fail with beziers!" ); + + const Rectangle aBound( GetBoundRect() ); + const Line aLine( rPoint, Point( aBound.Right() + 100L, rPoint.Y() ) ); + USHORT nCount = mpImplPolygon->mnPoints; + USHORT nPCounter = 0; + + if ( ( nCount > 2 ) && aBound.IsInside( rPoint ) ) + { + Point aPt1( mpImplPolygon->mpPointAry[ 0 ] ); + Point aIntersection; + Point aLastIntersection; + + while ( ( aPt1 == mpImplPolygon->mpPointAry[ nCount - 1 ] ) && ( nCount > 3 ) ) + nCount--; + + for ( USHORT i = 1; i <= nCount; i++ ) + { + const Point& rPt2 = mpImplPolygon->mpPointAry[ ( i < nCount ) ? i : 0 ]; + + if ( aLine.Intersection( Line( aPt1, rPt2 ), aIntersection ) ) + { + // Hiermit verhindern wir das Einfuegen von + // doppelten Intersections, die gleich hintereinander folgen + if ( nPCounter ) + { + if ( aIntersection != aLastIntersection ) + { + aLastIntersection = aIntersection; + nPCounter++; + } + } + else + { + aLastIntersection = aIntersection; + nPCounter++; + } + } + + aPt1 = rPt2; + } + } + + // innerhalb, wenn die Anzahl der Schnittpunkte ungerade ist + return ( ( nPCounter & 1 ) == 1 ); +} + +// ----------------------------------------------------------------------- + +BOOL Polygon::IsRightOrientated() const +{ + DBG_CHKTHIS( Polygon, NULL ); + return GetSignedArea() >= 0.0; +} + +// ----------------------------------------------------------------------- + +void Polygon::Insert( USHORT nPos, const Point& rPt, PolyFlags eFlags ) +{ + DBG_CHKTHIS( Polygon, NULL ); + ImplMakeUnique( this ); + + if( nPos >= mpImplPolygon->mnPoints ) + nPos = mpImplPolygon->mnPoints; + + mpImplPolygon->ImplSplit( nPos, 1 ); + mpImplPolygon->mpPointAry[ nPos ] = rPt; + + if( POLY_NORMAL != eFlags ) + { + mpImplPolygon->ImplCreateFlagArray(); + mpImplPolygon->mpFlagAry[ nPos ] = (BYTE) eFlags; + } +} + +// ----------------------------------------------------------------------- + +void Polygon::Insert( USHORT nPos, const Polygon& rPoly ) +{ + DBG_CHKTHIS( Polygon, NULL ); + const USHORT nInsertCount = rPoly.mpImplPolygon->mnPoints; + + if( nInsertCount ) + { + ImplMakeUnique( this ); + + if( nPos >= mpImplPolygon->mnPoints ) + nPos = mpImplPolygon->mnPoints; + + if( rPoly.mpImplPolygon->mpFlagAry ) + mpImplPolygon->ImplCreateFlagArray(); + + mpImplPolygon->ImplSplit( nPos, nInsertCount, rPoly.mpImplPolygon ); + } +} + +// ----------------------------------------------------------------------- + +void Polygon::Remove( USHORT nPos, USHORT nCount ) +{ + DBG_CHKTHIS( Polygon, NULL ); + if( nCount && ( nPos < mpImplPolygon->mnPoints ) ) + { + ImplMakeUnique( this ); + mpImplPolygon->ImplRemove( nPos, nCount ); + } +} + +// ----------------------------------------------------------------------- + +Point& Polygon::operator[]( USHORT nPos ) +{ + DBG_CHKTHIS( Polygon, NULL ); + DBG_ASSERT( nPos < mpImplPolygon->mnPoints, "Polygon::[]: nPos >= nPoints" ); + + ImplMakeUnique( this ); + return mpImplPolygon->mpPointAry[nPos]; +} + +// ----------------------------------------------------------------------- + +Polygon& Polygon::operator=( const Polygon& rPoly ) +{ + DBG_CHKTHIS( Polygon, NULL ); + DBG_CHKOBJ( &rPoly, Polygon, NULL ); + DBG_ASSERT( rPoly.mpImplPolygon->mnRefCount < 0xFFFE, "Polygon: RefCount overflow" ); + + // Zuerst Referenzcounter erhoehen, damit man sich selbst zuweisen kann + // RefCount == 0 fuer statische Objekte + if ( rPoly.mpImplPolygon->mnRefCount ) + rPoly.mpImplPolygon->mnRefCount++; + + // Wenn es keine statischen ImpDaten sind, dann loeschen, wenn es + // die letzte Referenz ist, sonst Referenzcounter decrementieren + if ( mpImplPolygon->mnRefCount ) + { + if ( mpImplPolygon->mnRefCount > 1 ) + mpImplPolygon->mnRefCount--; + else + delete mpImplPolygon; + } + + mpImplPolygon = rPoly.mpImplPolygon; + return *this; +} + +// ----------------------------------------------------------------------- + +BOOL Polygon::operator==( const Polygon& rPoly ) const +{ + DBG_CHKTHIS( Polygon, NULL ); + DBG_CHKOBJ( &rPoly, Polygon, NULL ); + + if ( (rPoly.mpImplPolygon == mpImplPolygon) ) + return TRUE; + else + return FALSE; +} + +// ----------------------------------------------------------------------- + +sal_Bool Polygon::IsEqual( const Polygon& rPoly ) const +{ + sal_Bool bIsEqual = sal_True;; + sal_uInt16 i; + if ( GetSize() != rPoly.GetSize() ) + bIsEqual = sal_False; + else + { + for ( i = 0; i < GetSize(); i++ ) + { + if ( ( GetPoint( i ) != rPoly.GetPoint( i ) ) || + ( GetFlags( i ) != rPoly.GetFlags( i ) ) ) + { + bIsEqual = sal_False; + break; + } + } + } + return bIsEqual; +} + +// ----------------------------------------------------------------------- + +SvStream& operator>>( SvStream& rIStream, Polygon& rPoly ) +{ + DBG_CHKOBJ( &rPoly, Polygon, NULL ); + DBG_ASSERTWARNING( rIStream.GetVersion(), "Polygon::>> - Solar-Version not set on rIStream" ); + + USHORT i; + USHORT nStart; + USHORT nCurPoints; + USHORT nPoints; + unsigned char bShort; + short nShortX; + short nShortY; + long nLongX; + long nLongY; + + // Anzahl der Punkte einlesen und Array erzeugen + rIStream >> nPoints; + if ( rPoly.mpImplPolygon->mnRefCount != 1 ) + { + if ( rPoly.mpImplPolygon->mnRefCount ) + rPoly.mpImplPolygon->mnRefCount--; + rPoly.mpImplPolygon = new ImplPolygon( nPoints ); + } + else + rPoly.mpImplPolygon->ImplSetSize( nPoints, FALSE ); + + // Je nach CompressMode das Polygon einlesen + if ( rIStream.GetCompressMode() == COMPRESSMODE_FULL ) + { + i = 0; + while ( i < nPoints ) + { + rIStream >> bShort >> nCurPoints; + + if ( bShort ) + { + for ( nStart = i; i < nStart+nCurPoints; i++ ) + { + rIStream >> nShortX >> nShortY; + rPoly.mpImplPolygon->mpPointAry[i].X() = nShortX; + rPoly.mpImplPolygon->mpPointAry[i].Y() = nShortY; + } + } + else + { + for ( nStart = i; i < nStart+nCurPoints; i++ ) + { + rIStream >> nLongX >> nLongY; + rPoly.mpImplPolygon->mpPointAry[i].X() = nLongX; + rPoly.mpImplPolygon->mpPointAry[i].Y() = nLongY; + } + } + } + } + else + { + // Feststellen, ob ueber die Operatoren geschrieben werden muss +#if (__SIZEOFLONG) != 4 + if ( 1 ) +#else +#ifdef __BIGENDIAN + if ( rIStream.GetNumberFormatInt() != NUMBERFORMAT_INT_BIGENDIAN ) +#else + if ( rIStream.GetNumberFormatInt() != NUMBERFORMAT_INT_LITTLEENDIAN ) +#endif +#endif + { + for( i = 0; i < nPoints; i++ ) + { + rIStream >> rPoly.mpImplPolygon->mpPointAry[i].X() + >> rPoly.mpImplPolygon->mpPointAry[i].Y(); + } + } + else + rIStream.Read( rPoly.mpImplPolygon->mpPointAry, nPoints*sizeof(Point) ); + } + + return rIStream; +} + +// ----------------------------------------------------------------------- + +SvStream& operator<<( SvStream& rOStream, const Polygon& rPoly ) +{ + DBG_CHKOBJ( &rPoly, Polygon, NULL ); + DBG_ASSERTWARNING( rOStream.GetVersion(), "Polygon::<< - Solar-Version not set on rOStream" ); + + unsigned char bShort; + unsigned char bCurShort; + USHORT nStart; + USHORT i; + USHORT nPoints = rPoly.GetSize(); + + // Anzahl der Punkte rausschreiben + rOStream << nPoints; + + // Je nach CompressMode das Polygon rausschreiben + if ( rOStream.GetCompressMode() == COMPRESSMODE_FULL ) + { + i = 0; + while ( i < nPoints ) + { + nStart = i; + + // Feststellen, welcher Typ geschrieben werden soll + if ( ((rPoly.mpImplPolygon->mpPointAry[nStart].X() >= SHRT_MIN) && + (rPoly.mpImplPolygon->mpPointAry[nStart].X() <= SHRT_MAX)) && + ((rPoly.mpImplPolygon->mpPointAry[nStart].Y() >= SHRT_MIN) && + (rPoly.mpImplPolygon->mpPointAry[nStart].Y() <= SHRT_MAX)) ) + bShort = TRUE; + else + bShort = FALSE; + while ( i < nPoints ) + { + // Feststellen, welcher Typ geschrieben werden soll + if ( ((rPoly.mpImplPolygon->mpPointAry[nStart].X() >= SHRT_MIN) && + (rPoly.mpImplPolygon->mpPointAry[nStart].X() <= SHRT_MAX)) && + ((rPoly.mpImplPolygon->mpPointAry[nStart].Y() >= SHRT_MIN) && + (rPoly.mpImplPolygon->mpPointAry[nStart].Y() <= SHRT_MAX)) ) + bCurShort = TRUE; + else + bCurShort = FALSE; + + // Wenn sich die Werte in einen anderen Bereich begeben, + // muessen wir neu rausschreiben + if ( bCurShort != bShort ) + { + bShort = bCurShort; + break; + } + + i++; + } + + rOStream << bShort << (USHORT)(i-nStart); + + if ( bShort ) + { + for( ; nStart < i; nStart++ ) + { + rOStream << (short)rPoly.mpImplPolygon->mpPointAry[nStart].X() + << (short)rPoly.mpImplPolygon->mpPointAry[nStart].Y(); + } + } + else + { + for( ; nStart < i; nStart++ ) + { + rOStream << rPoly.mpImplPolygon->mpPointAry[nStart].X() + << rPoly.mpImplPolygon->mpPointAry[nStart].Y(); + } + } + } + } + else + { + // Feststellen, ob ueber die Operatoren geschrieben werden muss +#if (__SIZEOFLONG) != 4 + if ( 1 ) +#else +#ifdef __BIGENDIAN + if ( rOStream.GetNumberFormatInt() != NUMBERFORMAT_INT_BIGENDIAN ) +#else + if ( rOStream.GetNumberFormatInt() != NUMBERFORMAT_INT_LITTLEENDIAN ) +#endif +#endif + { + for( i = 0; i < nPoints; i++ ) + { + rOStream << rPoly.mpImplPolygon->mpPointAry[i].X() + << rPoly.mpImplPolygon->mpPointAry[i].Y(); + } + } + else + { + if ( nPoints ) + rOStream.Write( rPoly.mpImplPolygon->mpPointAry, nPoints*sizeof(Point) ); + } + } + + return rOStream; +} + +// ----------------------------------------------------------------------- + +void Polygon::ImplRead( SvStream& rIStream ) +{ + sal_uInt8 bHasPolyFlags; + + rIStream >> *this + >> bHasPolyFlags; + + if ( bHasPolyFlags ) + { + mpImplPolygon->mpFlagAry = new sal_uInt8[ mpImplPolygon->mnPoints ]; + rIStream.Read( mpImplPolygon->mpFlagAry, mpImplPolygon->mnPoints ); + } +} + +// ----------------------------------------------------------------------- + +void Polygon::Read( SvStream& rIStream ) +{ + VersionCompat aCompat( rIStream, STREAM_READ ); + + ImplRead( rIStream ); +} + +// ----------------------------------------------------------------------- + +void Polygon::ImplWrite( SvStream& rOStream ) const +{ + sal_uInt8 bHasPolyFlags = mpImplPolygon->mpFlagAry != NULL; + rOStream << *this + << bHasPolyFlags; + + if ( bHasPolyFlags ) + rOStream.Write( mpImplPolygon->mpFlagAry, mpImplPolygon->mnPoints ); +} + +// ----------------------------------------------------------------------- + +void Polygon::Write( SvStream& rOStream ) const +{ + VersionCompat aCompat( rOStream, STREAM_WRITE, 1 ); + + ImplWrite( rOStream ); +} diff --git a/tools/source/generic/poly2.cxx b/tools/source/generic/poly2.cxx new file mode 100644 index 000000000000..33020772da9f --- /dev/null +++ b/tools/source/generic/poly2.cxx @@ -0,0 +1,933 @@ +/************************************************************************* + * + * $RCSfile: poly2.cxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: hr $ $Date: 2003-03-27 17:04:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#define _SV_POLY2_CXX + +#ifndef __gpc_h +extern "C" +{ + #include <external/gpc/gpc.h> +} +#endif + +#include <cstring> +#include <cmath> +#ifndef _POLY_H +#include <poly.h> +#endif +#ifndef _POLY_HXX +#include <poly.hxx> +#endif +#ifndef _DEBUG_HXX //autogen +#include <debug.hxx> +#endif +#ifndef _STREAM_HXX //autogen +#include <stream.hxx> +#endif +#ifndef _VCOMPAT_HXX +#include <vcompat.hxx> +#endif + +// --------------- +// - PolyPolygon - +// --------------- + +DBG_NAME( PolyPolygon ); + +// ----------------------------------------------------------------------- + +ImplPolyPolygon::ImplPolyPolygon( USHORT nInitSize ) +{ + mnRefCount = 1; + mnCount = nInitSize; + mnSize = nInitSize; + mnResize = 16; + mpPolyAry = new SVPPOLYGON[ nInitSize ]; +} + +// ----------------------------------------------------------------------- + +ImplPolyPolygon::ImplPolyPolygon( const ImplPolyPolygon& rImplPolyPoly ) +{ + mnRefCount = 1; + mnCount = rImplPolyPoly.mnCount; + mnSize = rImplPolyPoly.mnSize; + mnResize = rImplPolyPoly.mnResize; + + if ( rImplPolyPoly.mpPolyAry ) + { + mpPolyAry = new SVPPOLYGON[mnSize]; + for ( USHORT i = 0; i < mnCount; i++ ) + mpPolyAry[i] = new Polygon( *rImplPolyPoly.mpPolyAry[i] ); + } + else + mpPolyAry = NULL; +} + +// ----------------------------------------------------------------------- + +ImplPolyPolygon::~ImplPolyPolygon() +{ + if ( mpPolyAry ) + { + for ( USHORT i = 0; i < mnCount; i++ ) + delete mpPolyAry[i]; + delete[] mpPolyAry; + } +} + +// ======================================================================= + +PolyPolygon::PolyPolygon( USHORT nInitSize, USHORT nResize ) +{ + DBG_CTOR( PolyPolygon, NULL ); + + if ( nInitSize > MAX_POLYGONS ) + nInitSize = MAX_POLYGONS; + else if ( !nInitSize ) + nInitSize = 1; + if ( nResize > MAX_POLYGONS ) + nResize = MAX_POLYGONS; + else if ( !nResize ) + nResize = 1; + mpImplPolyPolygon = new ImplPolyPolygon( nInitSize, nResize ); +} + +// ----------------------------------------------------------------------- + +PolyPolygon::PolyPolygon( const Polygon& rPoly ) +{ + DBG_CTOR( PolyPolygon, NULL ); + + if ( rPoly.GetSize() ) + { + mpImplPolyPolygon = new ImplPolyPolygon( 1 ); + mpImplPolyPolygon->mpPolyAry[0] = new Polygon( rPoly ); + } + else + mpImplPolyPolygon = new ImplPolyPolygon( 16, 16 ); +} + +// ----------------------------------------------------------------------- + +PolyPolygon::PolyPolygon( USHORT nPoly, const USHORT* pPointCountAry, + const Point* pPtAry ) +{ + DBG_CTOR( PolyPolygon, NULL ); + + if ( nPoly > MAX_POLYGONS ) + nPoly = MAX_POLYGONS; + + mpImplPolyPolygon = new ImplPolyPolygon( nPoly ); + for ( USHORT i = 0; i < nPoly; i++ ) + { + mpImplPolyPolygon->mpPolyAry[i] = new Polygon( *pPointCountAry, pPtAry ); + pPtAry += *pPointCountAry; + pPointCountAry++; + } +} + +// ----------------------------------------------------------------------- + +PolyPolygon::PolyPolygon( const PolyPolygon& rPolyPoly ) +{ + DBG_CTOR( PolyPolygon, NULL ); + DBG_CHKOBJ( &rPolyPoly, PolyPolygon, NULL ); + DBG_ASSERT( rPolyPoly.mpImplPolyPolygon->mnRefCount < 0xFFFE, "PolyPolygon: RefCount overflow" ); + + mpImplPolyPolygon = rPolyPoly.mpImplPolyPolygon; + mpImplPolyPolygon->mnRefCount++; +} + +// ----------------------------------------------------------------------- + +PolyPolygon::~PolyPolygon() +{ + DBG_DTOR( PolyPolygon, NULL ); + + if ( mpImplPolyPolygon->mnRefCount > 1 ) + mpImplPolyPolygon->mnRefCount--; + else + delete mpImplPolyPolygon; +} + +// ----------------------------------------------------------------------- + +void PolyPolygon::Insert( const Polygon& rPoly, USHORT nPos ) +{ + DBG_CHKTHIS( PolyPolygon, NULL ); + + if ( mpImplPolyPolygon->mnCount >= MAX_POLYGONS ) + return; + + if ( mpImplPolyPolygon->mnRefCount > 1 ) + { + mpImplPolyPolygon->mnRefCount--; + mpImplPolyPolygon = new ImplPolyPolygon( *mpImplPolyPolygon ); + } + + if ( nPos > mpImplPolyPolygon->mnCount ) + nPos = mpImplPolyPolygon->mnCount; + + if ( !mpImplPolyPolygon->mpPolyAry ) + mpImplPolyPolygon->mpPolyAry = new SVPPOLYGON[mpImplPolyPolygon->mnSize]; + else if ( mpImplPolyPolygon->mnCount == mpImplPolyPolygon->mnSize ) + { + USHORT nOldSize = mpImplPolyPolygon->mnSize; + USHORT nNewSize = nOldSize + mpImplPolyPolygon->mnResize; + SVPPOLYGON* pNewAry; + + if ( nNewSize >= MAX_POLYGONS ) + nNewSize = MAX_POLYGONS; + pNewAry = new SVPPOLYGON[nNewSize]; + memcpy( pNewAry, mpImplPolyPolygon->mpPolyAry, nPos*sizeof(SVPPOLYGON) ); + memcpy( pNewAry+nPos+1, mpImplPolyPolygon->mpPolyAry+nPos, + (nOldSize-nPos)*sizeof(SVPPOLYGON) ); + delete[] mpImplPolyPolygon->mpPolyAry; + mpImplPolyPolygon->mpPolyAry = pNewAry; + mpImplPolyPolygon->mnSize = nNewSize; + } + else if ( nPos < mpImplPolyPolygon->mnCount ) + { + memmove( mpImplPolyPolygon->mpPolyAry+nPos+1, + mpImplPolyPolygon->mpPolyAry+nPos, + (mpImplPolyPolygon->mnCount-nPos)*sizeof(SVPPOLYGON) ); + } + + mpImplPolyPolygon->mpPolyAry[nPos] = new Polygon( rPoly ); + mpImplPolyPolygon->mnCount++; +} + +// ----------------------------------------------------------------------- + +void PolyPolygon::Remove( USHORT nPos ) +{ + DBG_CHKTHIS( PolyPolygon, NULL ); + DBG_ASSERT( nPos < Count(), "PolyPolygon::Remove(): nPos >= nSize" ); + + if ( mpImplPolyPolygon->mnRefCount > 1 ) + { + mpImplPolyPolygon->mnRefCount--; + mpImplPolyPolygon = new ImplPolyPolygon( *mpImplPolyPolygon ); + } + + delete mpImplPolyPolygon->mpPolyAry[nPos]; + mpImplPolyPolygon->mnCount--; + memmove( mpImplPolyPolygon->mpPolyAry+nPos, + mpImplPolyPolygon->mpPolyAry+nPos+1, + (mpImplPolyPolygon->mnCount-nPos)*sizeof(SVPPOLYGON) ); +} + +// ----------------------------------------------------------------------- + +void PolyPolygon::Replace( const Polygon& rPoly, USHORT nPos ) +{ + DBG_CHKTHIS( PolyPolygon, NULL ); + DBG_ASSERT( nPos < Count(), "PolyPolygon::Replace(): nPos >= nSize" ); + + if ( mpImplPolyPolygon->mnRefCount > 1 ) + { + mpImplPolyPolygon->mnRefCount--; + mpImplPolyPolygon = new ImplPolyPolygon( *mpImplPolyPolygon ); + } + + delete mpImplPolyPolygon->mpPolyAry[nPos]; + mpImplPolyPolygon->mpPolyAry[nPos] = new Polygon( rPoly ); +} + +// ----------------------------------------------------------------------- + +const Polygon& PolyPolygon::GetObject( USHORT nPos ) const +{ + DBG_CHKTHIS( PolyPolygon, NULL ); + DBG_ASSERT( nPos < Count(), "PolyPolygon::GetObject(): nPos >= nSize" ); + + return *(mpImplPolyPolygon->mpPolyAry[nPos]); +} + +// ----------------------------------------------------------------------- + +BOOL PolyPolygon::IsRect() const +{ + BOOL bIsRect = FALSE; + if ( Count() == 1 ) + bIsRect = mpImplPolyPolygon->mpPolyAry[ 0 ]->IsRect(); + return bIsRect; +} + +// ----------------------------------------------------------------------- + +void PolyPolygon::Clear() +{ + DBG_CHKTHIS( PolyPolygon, NULL ); + + if ( mpImplPolyPolygon->mnRefCount > 1 ) + { + mpImplPolyPolygon->mnRefCount--; + mpImplPolyPolygon = new ImplPolyPolygon( mpImplPolyPolygon->mnResize, + mpImplPolyPolygon->mnResize ); + } + else + { + if ( mpImplPolyPolygon->mpPolyAry ) + { + for ( USHORT i = 0; i < mpImplPolyPolygon->mnCount; i++ ) + delete mpImplPolyPolygon->mpPolyAry[i]; + delete[] mpImplPolyPolygon->mpPolyAry; + mpImplPolyPolygon->mpPolyAry = NULL; + mpImplPolyPolygon->mnCount = 0; + mpImplPolyPolygon->mnSize = mpImplPolyPolygon->mnResize; + } + } +} + +// ----------------------------------------------------------------------- + +void PolyPolygon::Optimize( ULONG nOptimizeFlags, const PolyOptimizeData* pData ) +{ + DBG_CHKTHIS( PolyPolygon, NULL ); + + if( nOptimizeFlags ) + { + double fArea; + const BOOL bEdges = ( nOptimizeFlags & POLY_OPTIMIZE_EDGES ) == POLY_OPTIMIZE_EDGES; + USHORT nPercent; + + if( bEdges ) + { + const Rectangle aBound( GetBoundRect() ); + + fArea = ( aBound.GetWidth() + aBound.GetHeight() ) * 0.5; + nPercent = pData ? pData->GetPercentValue() : 50; + nOptimizeFlags &= ~POLY_OPTIMIZE_EDGES; + } + + // watch for ref counter + if( mpImplPolyPolygon->mnRefCount > 1 ) + { + mpImplPolyPolygon->mnRefCount--; + mpImplPolyPolygon = new ImplPolyPolygon( *mpImplPolyPolygon ); + } + + // Optimize polygons + for( USHORT i = 0, nPolyCount = mpImplPolyPolygon->mnCount; i < nPolyCount; i++ ) + { + if( bEdges ) + { + mpImplPolyPolygon->mpPolyAry[ i ]->Optimize( POLY_OPTIMIZE_NO_SAME ); + Polygon::ImplReduceEdges( *( mpImplPolyPolygon->mpPolyAry[ i ] ), fArea, nPercent ); + } + + if( nOptimizeFlags ) + mpImplPolyPolygon->mpPolyAry[ i ]->Optimize( nOptimizeFlags, pData ); + } + } +} + +// ----------------------------------------------------------------------- + +void PolyPolygon::GetSimple( PolyPolygon& rResult, long nDelta ) const +{ + DBG_CHKTHIS( PolyPolygon, NULL ); + + rResult.Clear(); + + Polygon aPolygon; + + for( USHORT i = 0; i < mpImplPolyPolygon->mnCount; i++ ) + { + mpImplPolyPolygon->mpPolyAry[ i ]->GetSimple( aPolygon, nDelta ); + rResult.Insert( aPolygon ); + } +} + +// ----------------------------------------------------------------------- + +void PolyPolygon::AdaptiveSubdivide( PolyPolygon& rResult, const double d ) const +{ + DBG_CHKTHIS( PolyPolygon, NULL ); + + rResult.Clear(); + + Polygon aPolygon; + + for( USHORT i = 0; i < mpImplPolyPolygon->mnCount; i++ ) + { + mpImplPolyPolygon->mpPolyAry[ i ]->AdaptiveSubdivide( aPolygon, d ); + rResult.Insert( aPolygon ); + } +} + +// ----------------------------------------------------------------------- + +void PolyPolygon::GetIntersection( const PolyPolygon& rPolyPoly, PolyPolygon& rResult ) const +{ + ImplDoOperation( rPolyPoly, rResult, GPC_INT ); +} + +// ----------------------------------------------------------------------- + +void PolyPolygon::GetUnion( const PolyPolygon& rPolyPoly, PolyPolygon& rResult ) const +{ + ImplDoOperation( rPolyPoly, rResult, GPC_UNION ); +} + +// ----------------------------------------------------------------------- + +void PolyPolygon::GetDifference( const PolyPolygon& rPolyPoly, PolyPolygon& rResult ) const +{ + ImplDoOperation( rPolyPoly, rResult, GPC_DIFF ); +} + +// ----------------------------------------------------------------------- + +void PolyPolygon::GetXOR( const PolyPolygon& rPolyPoly, PolyPolygon& rResult ) const +{ + ImplDoOperation( rPolyPoly, rResult, GPC_XOR ); +} + +// ----------------------------------------------------------------------- + +void* PolyPolygon::ImplCreateGPCPolygon() const +{ + gpc_polygon* pRet = new gpc_polygon; + + pRet->num_contours = 0; + pRet->hole = NULL; + pRet->contour = NULL; + + for( USHORT i = 0, nCount = Count(); i < nCount; i++ ) + { + const Polygon& rPoly = GetObject( i ); + const USHORT nSize = rPoly.GetSize(); + + if( nSize > 1 ) + { + gpc_vertex_list aVertexList; + gpc_vertex* pVertex; + + aVertexList.num_vertices = nSize; + aVertexList.vertex = pVertex = new gpc_vertex[ nSize ]; + + for( USHORT nPos = 0; nPos < nSize; nPos++, pVertex++ ) + { + const Point& rPoint = rPoly[ nPos ]; + pVertex->x = rPoint.X(); + pVertex->y = rPoint.Y(); + } + + gpc_add_contour( pRet, &aVertexList, 0 ); + delete[] aVertexList.vertex; + } + } + + return pRet; +} + +// ----------------------------------------------------------------------- + +void PolyPolygon::ImplDoOperation( const PolyPolygon& rPolyPoly, PolyPolygon& rResult, ULONG nOperation ) const +{ + gpc_polygon* pGPCPoly1 = (gpc_polygon*) ImplCreateGPCPolygon(); + gpc_polygon* pGPCPoly2 = (gpc_polygon*) rPolyPoly.ImplCreateGPCPolygon(); + gpc_polygon* pResult = new gpc_polygon; + + pResult->num_contours = 0; + pResult->hole = NULL; + pResult->contour = NULL; + + gpc_polygon_clip( (gpc_op) nOperation, pGPCPoly1, pGPCPoly2, pResult ); + + rResult.Clear(); + + for( int i = 0; i < pResult->num_contours; i++ ) + { + gpc_vertex_list& rVertexList = pResult->contour[ i ]; + Polygon aPoly( rVertexList.num_vertices ); + + for( int j = 0; j < rVertexList.num_vertices; j++ ) + { + Point& rPt = aPoly[ j ]; + rPt.X() = FRound( rVertexList.vertex[ j ].x ); + rPt.Y() = FRound( rVertexList.vertex[ j ].y ); + } + + rResult.Insert( aPoly ); + } + + gpc_free_polygon( pGPCPoly1 ); + delete pGPCPoly1; + + gpc_free_polygon( pGPCPoly2 ); + delete pGPCPoly2; + + gpc_free_polygon( pResult ); + delete pResult; +} + +// ----------------------------------------------------------------------- + +USHORT PolyPolygon::Count() const +{ + DBG_CHKTHIS( PolyPolygon, NULL ); + return mpImplPolyPolygon->mnCount; +} + +// ----------------------------------------------------------------------- + +void PolyPolygon::Move( long nHorzMove, long nVertMove ) +{ + DBG_CHKTHIS( PolyPolygon, NULL ); + + // Diese Abfrage sollte man fuer die DrawEngine durchfuehren + if( nHorzMove || nVertMove ) + { + // Referenzcounter beruecksichtigen + if ( mpImplPolyPolygon->mnRefCount > 1 ) + { + mpImplPolyPolygon->mnRefCount--; + mpImplPolyPolygon = new ImplPolyPolygon( *mpImplPolyPolygon ); + } + + // Punkte verschieben + USHORT nPolyCount = mpImplPolyPolygon->mnCount; + for ( USHORT i = 0; i < nPolyCount; i++ ) + mpImplPolyPolygon->mpPolyAry[i]->Move( nHorzMove, nVertMove ); + } +} + +// ----------------------------------------------------------------------- + +void PolyPolygon::Translate( const Point& rTrans ) +{ + DBG_CHKTHIS( PolyPolygon, NULL ); + + // Referenzcounter beruecksichtigen + if( mpImplPolyPolygon->mnRefCount > 1 ) + { + mpImplPolyPolygon->mnRefCount--; + mpImplPolyPolygon = new ImplPolyPolygon( *mpImplPolyPolygon ); + } + + // Punkte verschieben + for ( USHORT i = 0, nCount = mpImplPolyPolygon->mnCount; i < nCount; i++ ) + mpImplPolyPolygon->mpPolyAry[ i ]->Translate( rTrans ); +} + +// ----------------------------------------------------------------------- + +void PolyPolygon::Scale( double fScaleX, double fScaleY ) +{ + DBG_CHKTHIS( PolyPolygon, NULL ); + + // Referenzcounter beruecksichtigen + if( mpImplPolyPolygon->mnRefCount > 1 ) + { + mpImplPolyPolygon->mnRefCount--; + mpImplPolyPolygon = new ImplPolyPolygon( *mpImplPolyPolygon ); + } + + // Punkte verschieben + for ( USHORT i = 0, nCount = mpImplPolyPolygon->mnCount; i < nCount; i++ ) + mpImplPolyPolygon->mpPolyAry[ i ]->Scale( fScaleX, fScaleY ); +} + +// ----------------------------------------------------------------------- + +void PolyPolygon::Rotate( const Point& rCenter, USHORT nAngle10 ) +{ + DBG_CHKTHIS( PolyPolygon, NULL ); + nAngle10 %= 3600; + + if( nAngle10 ) + { + const double fAngle = F_PI1800 * nAngle10; + Rotate( rCenter, sin( fAngle ), cos( fAngle ) ); + } +} + +// ----------------------------------------------------------------------- + +void PolyPolygon::Rotate( const Point& rCenter, double fSin, double fCos ) +{ + DBG_CHKTHIS( PolyPolygon, NULL ); + + // Referenzcounter beruecksichtigen + if( mpImplPolyPolygon->mnRefCount > 1 ) + { + mpImplPolyPolygon->mnRefCount--; + mpImplPolyPolygon = new ImplPolyPolygon( *mpImplPolyPolygon ); + } + + // Punkte verschieben + for ( USHORT i = 0, nCount = mpImplPolyPolygon->mnCount; i < nCount; i++ ) + mpImplPolyPolygon->mpPolyAry[ i ]->Rotate( rCenter, fSin, fCos ); +} + +// ----------------------------------------------------------------------- + +void PolyPolygon::SlantX( long nYRef, double fSin, double fCos ) +{ + DBG_CHKTHIS( PolyPolygon, NULL ); + + // Referenzcounter beruecksichtigen + if( mpImplPolyPolygon->mnRefCount > 1 ) + { + mpImplPolyPolygon->mnRefCount--; + mpImplPolyPolygon = new ImplPolyPolygon( *mpImplPolyPolygon ); + } + + // Punkte verschieben + for ( USHORT i = 0, nCount = mpImplPolyPolygon->mnCount; i < nCount; i++ ) + mpImplPolyPolygon->mpPolyAry[ i ]->SlantX( nYRef, fSin, fCos ); +} + +// ----------------------------------------------------------------------- + +void PolyPolygon::SlantY( long nXRef, double fSin, double fCos ) +{ + DBG_CHKTHIS( PolyPolygon, NULL ); + + // Referenzcounter beruecksichtigen + if( mpImplPolyPolygon->mnRefCount > 1 ) + { + mpImplPolyPolygon->mnRefCount--; + mpImplPolyPolygon = new ImplPolyPolygon( *mpImplPolyPolygon ); + } + + // Punkte verschieben + for ( USHORT i = 0, nCount = mpImplPolyPolygon->mnCount; i < nCount; i++ ) + mpImplPolyPolygon->mpPolyAry[ i ]->SlantY( nXRef, fSin, fCos ); +} + +// ----------------------------------------------------------------------- + +void PolyPolygon::Distort( const Rectangle& rRefRect, const Polygon& rDistortedRect ) +{ + DBG_CHKTHIS( PolyPolygon, NULL ); + + // Referenzcounter beruecksichtigen + if( mpImplPolyPolygon->mnRefCount > 1 ) + { + mpImplPolyPolygon->mnRefCount--; + mpImplPolyPolygon = new ImplPolyPolygon( *mpImplPolyPolygon ); + } + + // Punkte verschieben + for ( USHORT i = 0, nCount = mpImplPolyPolygon->mnCount; i < nCount; i++ ) + mpImplPolyPolygon->mpPolyAry[ i ]->Distort( rRefRect, rDistortedRect ); +} + + +// ----------------------------------------------------------------------- + +void PolyPolygon::Clip( const Rectangle& rRect ) +{ + // Polygon-Clippen + USHORT nPolyCount = mpImplPolyPolygon->mnCount; + USHORT i; + + if ( !nPolyCount ) + return; + + // Referenzcounter beruecksichtigen + if ( mpImplPolyPolygon->mnRefCount > 1 ) + { + mpImplPolyPolygon->mnRefCount--; + mpImplPolyPolygon = new ImplPolyPolygon( *mpImplPolyPolygon ); + } + + // Erst jedes Polygon Clippen und dann die leeren entfernen + for ( i = 0; i < nPolyCount; i++ ) + mpImplPolyPolygon->mpPolyAry[i]->Clip( rRect ); + while ( nPolyCount ) + { + if ( GetObject( nPolyCount-1 ).GetSize() <= 2 ) + Remove( nPolyCount-1 ); + nPolyCount--; + } +} + +// ----------------------------------------------------------------------- + +Rectangle PolyPolygon::GetBoundRect() const +{ + DBG_CHKTHIS( PolyPolygon, NULL ); + + long nXMin, nXMax, nYMin, nYMax; + BOOL bFirst = TRUE; + USHORT nPolyCount = mpImplPolyPolygon->mnCount; + + for ( USHORT n = 0; n < nPolyCount; n++ ) + { + const Polygon* pPoly = mpImplPolyPolygon->mpPolyAry[n]; + const Point* pAry = pPoly->GetConstPointAry(); + USHORT nPointCount = pPoly->GetSize(); + + for ( USHORT i = 0; i < nPointCount; i++ ) + { + const Point* pPt = &pAry[ i ]; + + if ( bFirst ) + { + nXMin = nXMax = pPt->X(); + nYMin = nYMax = pPt->Y(); + bFirst = FALSE; + } + else + { + if ( pPt->X() < nXMin ) + nXMin = pPt->X(); + if ( pPt->X() > nXMax ) + nXMax = pPt->X(); + if ( pPt->Y() < nYMin ) + nYMin = pPt->Y(); + if ( pPt->Y() > nYMax ) + nYMax = pPt->Y(); + } + } + } + + if ( !bFirst ) + return Rectangle( nXMin, nYMin, nXMax, nYMax ); + else + return Rectangle(); +} + +// ----------------------------------------------------------------------- + +Polygon& PolyPolygon::operator[]( USHORT nPos ) +{ + DBG_CHKTHIS( PolyPolygon, NULL ); + DBG_ASSERT( nPos < Count(), "PolyPolygon::[](): nPos >= nSize" ); + + if ( mpImplPolyPolygon->mnRefCount > 1 ) + { + mpImplPolyPolygon->mnRefCount--; + mpImplPolyPolygon = new ImplPolyPolygon( *mpImplPolyPolygon ); + } + + return *(mpImplPolyPolygon->mpPolyAry[nPos]); +} + +// ----------------------------------------------------------------------- + +PolyPolygon& PolyPolygon::operator=( const PolyPolygon& rPolyPoly ) +{ + DBG_CHKTHIS( PolyPolygon, NULL ); + DBG_CHKOBJ( &rPolyPoly, PolyPolygon, NULL ); + DBG_ASSERT( rPolyPoly.mpImplPolyPolygon->mnRefCount < 0xFFFE, "PolyPolygon: RefCount overflow" ); + + rPolyPoly.mpImplPolyPolygon->mnRefCount++; + + if ( mpImplPolyPolygon->mnRefCount > 1 ) + mpImplPolyPolygon->mnRefCount--; + else + delete mpImplPolyPolygon; + + mpImplPolyPolygon = rPolyPoly.mpImplPolyPolygon; + return *this; +} + +// ----------------------------------------------------------------------- + +BOOL PolyPolygon::operator==( const PolyPolygon& rPolyPoly ) const +{ + DBG_CHKTHIS( PolyPolygon, NULL ); + DBG_CHKOBJ( &rPolyPoly, PolyPolygon, NULL ); + + if ( rPolyPoly.mpImplPolyPolygon == mpImplPolyPolygon ) + return TRUE; + else + return FALSE; +} + +// ----------------------------------------------------------------------- + +sal_Bool PolyPolygon::IsEqual( const PolyPolygon& rPolyPoly ) const +{ + sal_Bool bIsEqual = sal_True; + if ( Count() != rPolyPoly.Count() ) + bIsEqual = sal_False; + else + { + sal_uInt16 i; + for ( i = 0; i < Count(); i++ ) + { + if (!GetObject( i ).IsEqual( rPolyPoly.GetObject( i ) ) ) + { + sal_Bool bIsEqual = sal_False; + break; + } + } + } + return bIsEqual; +} + +// ----------------------------------------------------------------------- + +SvStream& operator>>( SvStream& rIStream, PolyPolygon& rPolyPoly ) +{ + DBG_CHKOBJ( &rPolyPoly, PolyPolygon, NULL ); + DBG_ASSERTWARNING( rIStream.GetVersion(), "PolyPolygon::>> - Solar-Version not set on rIStream" ); + + Polygon* pPoly; + USHORT nPolyCount; + + // Anzahl der Polygone einlesen + rIStream >> nPolyCount; + + // Daten anlegen + if( nPolyCount ) + { + // Referenzcounter beruecksichtigen + if ( rPolyPoly.mpImplPolyPolygon->mnRefCount > 1 ) + rPolyPoly.mpImplPolyPolygon->mnRefCount--; + else + delete rPolyPoly.mpImplPolyPolygon; + + rPolyPoly.mpImplPolyPolygon = new ImplPolyPolygon( nPolyCount ); + + for ( USHORT i = 0; i < nPolyCount; i++ ) + { + pPoly = new Polygon; + rIStream >> *pPoly; + rPolyPoly.mpImplPolyPolygon->mpPolyAry[i] = pPoly; + } + } + else + rPolyPoly = PolyPolygon(); + + return rIStream; +} + +// ----------------------------------------------------------------------- + +SvStream& operator<<( SvStream& rOStream, const PolyPolygon& rPolyPoly ) +{ + DBG_CHKOBJ( &rPolyPoly, PolyPolygon, NULL ); + DBG_ASSERTWARNING( rOStream.GetVersion(), "PolyPolygon::<< - Solar-Version not set on rOStream" ); + + // Anzahl der Polygone rausschreiben + USHORT nPolyCount = rPolyPoly.mpImplPolyPolygon->mnCount; + rOStream << nPolyCount; + + // Die einzelnen Polygone ausgeben + for ( USHORT i = 0; i < nPolyCount; i++ ) + rOStream << *(rPolyPoly.mpImplPolyPolygon->mpPolyAry[i]); + + return rOStream; +} + +// ----------------------------------------------------------------------- + +void PolyPolygon::Read( SvStream& rIStream ) +{ + VersionCompat aCompat( rIStream, STREAM_READ ); + + DBG_CHKTHIS( PolyPolygon, NULL ); + DBG_ASSERTWARNING( rIStream.GetVersion(), "PolyPolygon::>> - Solar-Version not set on rIStream" ); + + Polygon* pPoly; + USHORT nPolyCount; + + // Anzahl der Polygone einlesen + rIStream >> nPolyCount; + + // Daten anlegen + if( nPolyCount ) + { + // Referenzcounter beruecksichtigen + if ( mpImplPolyPolygon->mnRefCount > 1 ) + mpImplPolyPolygon->mnRefCount--; + else + delete mpImplPolyPolygon; + + mpImplPolyPolygon = new ImplPolyPolygon( nPolyCount ); + + for ( USHORT i = 0; i < nPolyCount; i++ ) + { + pPoly = new Polygon; + pPoly->ImplRead( rIStream ); + mpImplPolyPolygon->mpPolyAry[i] = pPoly; + } + } + else + *this = PolyPolygon(); +} + +// ----------------------------------------------------------------------- + +void PolyPolygon::Write( SvStream& rOStream ) const +{ + VersionCompat aCompat( rOStream, STREAM_WRITE, 1 ); + + DBG_CHKTHIS( PolyPolygon, NULL ); + DBG_ASSERTWARNING( rOStream.GetVersion(), "PolyPolygon::<< - Solar-Version not set on rOStream" ); + + // Anzahl der Polygone rausschreiben + USHORT nPolyCount = mpImplPolyPolygon->mnCount; + rOStream << nPolyCount; + + // Die einzelnen Polygone ausgeben + for ( USHORT i = 0; i < nPolyCount; i++ ) + mpImplPolyPolygon->mpPolyAry[i]->ImplWrite( rOStream );; +} diff --git a/tools/source/inet/inetmime.cxx b/tools/source/inet/inetmime.cxx index 27ad280495b1..794944a7aba4 100644 --- a/tools/source/inet/inetmime.cxx +++ b/tools/source/inet/inetmime.cxx @@ -2,9 +2,9 @@ * * $RCSfile: inetmime.cxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: sb $ $Date: 2002-03-19 15:15:42 $ + * last change: $Author: hr $ $Date: 2003-03-27 17:04:27 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -991,7 +991,7 @@ const sal_Char * INetMIME::scanQuotedBlock(const sal_Char * pBegin, const sal_Char * pEnd, sal_uInt32 nOpening, sal_uInt32 nClosing, - sal_uInt32 & rLength, + sal_Size & rLength, bool & rModify) { DBG_ASSERT(pBegin && pBegin <= pEnd, @@ -1062,7 +1062,7 @@ const sal_Unicode * INetMIME::scanQuotedBlock(const sal_Unicode * pBegin, const sal_Unicode * pEnd, sal_uInt32 nOpening, sal_uInt32 nClosing, - sal_uInt32 & rLength, + sal_Size & rLength, bool & rModify) { DBG_ASSERT(pBegin && pBegin <= pEnd, @@ -2592,7 +2592,7 @@ void INetMIME::writeHeaderFieldBody(INetMIMEOutputSink & rSink, // Calculate the length of in- and output: const sal_Unicode * pStart = pBodyPtr; - sal_uInt32 nLength = 0; + sal_Size nLength = 0; bool bModify = false; bool bEnd = false; while (pBodyPtr != pBodyEnd && !bEnd) @@ -2664,7 +2664,7 @@ void INetMIME::writeHeaderFieldBody(INetMIMEOutputSink & rSink, { // Calculate the length of in- and output: const sal_Unicode * pStart = pBodyPtr; - sal_uInt32 nLength = 0; + sal_Size nLength = 0; bool bBracketedBlock = false; bool bSymbol = *pStart != '.' && *pStart != '@'; bool bModify = false; diff --git a/tools/source/inet/makefile.mk b/tools/source/inet/makefile.mk index 74926210cd36..a7071ab54135 100644 --- a/tools/source/inet/makefile.mk +++ b/tools/source/inet/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.1.1.1 $ +# $Revision: 1.2 $ # -# last change: $Author: hr $ $Date: 2000-09-18 17:03:08 $ +# last change: $Author: hr $ $Date: 2003-03-27 17:04:28 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -73,11 +73,9 @@ SLOFILES=\ $(SLO)$/inetmsg.obj \ $(SLO)$/inetstrm.obj -.IF "$(UPDATER)" != "" OBJFILES=\ $(OBJ)$/inetmime.obj \ $(OBJ)$/inetmsg.obj \ $(OBJ)$/inetstrm.obj -.ENDIF .INCLUDE: target.mk diff --git a/tools/source/memtools/makefile.mk b/tools/source/memtools/makefile.mk index bc8e84bf15b1..737a5f35e470 100644 --- a/tools/source/memtools/makefile.mk +++ b/tools/source/memtools/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.1.1.1 $ +# $Revision: 1.2 $ # -# last change: $Author: hr $ $Date: 2000-09-18 17:03:08 $ +# last change: $Author: hr $ $Date: 2003-03-27 17:04:39 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -79,13 +79,11 @@ SLOFILES= $(SLO)$/contnr.obj \ $(SLO)$/mempool.obj \ $(SLO)$/multisel.obj -.IF "$(UPDATER)"!="" OBJFILES= $(OBJ)$/contnr.obj \ $(OBJ)$/table.obj \ $(OBJ)$/unqidx.obj \ $(OBJ)$/mempool.obj \ $(OBJ)$/multisel.obj -.ENDIF # --- Targets ------------------------------------------------------ diff --git a/tools/source/rc/makefile.mk b/tools/source/rc/makefile.mk index 3273847d66a4..dda72b516837 100644 --- a/tools/source/rc/makefile.mk +++ b/tools/source/rc/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.4 $ +# $Revision: 1.5 $ # -# last change: $Author: sb $ $Date: 2002-03-13 09:03:53 $ +# last change: $Author: hr $ $Date: 2003-03-27 17:04:40 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -67,7 +67,9 @@ TARGET=rc # --- Settings ----------------------------------------------------- +.INCLUDE : svpre.mk .INCLUDE : settings.mk +.INCLUDE : sv.mk # --- Files -------------------------------------------------------- @@ -75,11 +77,9 @@ SLOFILES= $(SLO)$/rc.obj \ $(SLO)$/resmgr.obj \ $(SLO)$/resary.obj -.IF "$(UPDATER)"!="" OBJFILES= $(OBJ)$/rc.obj \ $(OBJ)$/resmgr.obj \ $(OBJ)$/resary.obj -.ENDIF # --- Targets ------------------------------------------------------ diff --git a/tools/source/rc/resmgr.cxx b/tools/source/rc/resmgr.cxx index d450be5e828c..b1537c27a46b 100644 --- a/tools/source/rc/resmgr.cxx +++ b/tools/source/rc/resmgr.cxx @@ -2,9 +2,9 @@ * * $RCSfile: resmgr.cxx,v $ * - * $Revision: 1.21 $ + * $Revision: 1.22 $ * - * last change: $Author: dv $ $Date: 2002-11-28 11:38:49 $ + * last change: $Author: hr $ $Date: 2003-03-27 17:04:40 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -108,6 +108,9 @@ #include "simplerm.hxx" #endif +#include <functional> +#include <algorithm> + #pragma hdrstop #ifdef UNX @@ -142,45 +145,66 @@ struct ImpContent ULONG nOffset; }; -#if defined( OS2 ) && defined( ICC ) -static int _Optlink Compare( const void * pFirst, const void * pSecond ) -#elif S390 -extern "C" { int Compare( const void * pFirst, const void * pSecond ) -#else -static int __LOADONCALLAPI Compare( const void * pFirst, const void * pSecond ) -#endif +struct ImpContentLessCompare : public ::std::binary_function< ImpContent, ImpContent, bool> { - if( ((ImpContent *)pFirst)->nTypeAndId > ((ImpContent *)pSecond)->nTypeAndId ) - return( 1 ); - else if( ((ImpContent *)pFirst)->nTypeAndId < ((ImpContent *)pSecond)->nTypeAndId ) - return( -1 ); - else - return( 0 ); -} - -#ifdef S390 -} -#endif + inline bool operator() (const ImpContent& lhs, const ImpContent& rhs) const + { + return lhs.nTypeAndId < rhs.nTypeAndId; + } +}; -#if defined( OS2 ) && defined( ICC ) -static int _Optlink Search( const void * nTypeAndId, const void * pSecond ) -#elif S390 -extern "C" { int Search( const void * nTypeAndId, const void * pSecond ) -#else -static int __LOADONCALLAPI Search( const void * nTypeAndId, const void * pSecond ) -#endif +struct ImpContentMixLessCompare : public ::std::binary_function< ImpContent, ULONG, bool> { - if( (ULONG)nTypeAndId > (((ImpContent *)pSecond)->nTypeAndId) ) - return( 1 ); - else if( (ULONG)nTypeAndId < (((ImpContent *)pSecond)->nTypeAndId) ) - return( -1 ); - else - return( 0 ); -} + inline bool operator() (const ImpContent& lhs, const ULONG& rhs) const + { + return lhs.nTypeAndId < rhs; + } + inline bool operator() (const ULONG& lhs, const ImpContent& rhs) const + { + return lhs < rhs.nTypeAndId; + } +}; -#ifdef S390 -} -#endif + +//#if defined( OS2 ) && defined( ICC ) +//static int _Optlink Compare( const void * pFirst, const void * pSecond ) +//#elif S390 +//extern "C" { int Compare( const void * pFirst, const void * pSecond ) +//#else +//static int __LOADONCALLAPI Compare( const void * pFirst, const void * pSecond ) +//#endif +//{ +// if( ((ImpContent *)pFirst)->nTypeAndId > ((ImpContent *)pSecond)->nTypeAndId ) +// return( 1 ); +// else if( ((ImpContent *)pFirst)->nTypeAndId < ((ImpContent *)pSecond)->nTypeAndId ) +// return( -1 ); +// else +// return( 0 ); +//} +// +//#ifdef S390 +//} +//#endif + +//#if defined( OS2 ) && defined( ICC ) +//static int _Optlink Search( const void * nTypeAndId, const void * pSecond ) +//#elif S390 +//extern "C" { int Search( const void * nTypeAndId, const void * pSecond ) +//#else +//static int __LOADONCALLAPI Search( const void * nTypeAndId, const void * pSecond ) +//#endif +//{ +// if( (ULONG)nTypeAndId > (((ImpContent *)pSecond)->nTypeAndId) ) +// return( 1 ); +// else if( (ULONG)nTypeAndId < (((ImpContent *)pSecond)->nTypeAndId) ) +// return( -1 ); +// else +// return( 0 ); +//} +// +//#ifdef S390 +//} +//#endif // ======================================================================= @@ -191,15 +215,24 @@ static ResHookProc pImplResHookProc = 0; SvStream * InternalResMgr::GetBitmapStream( USHORT nId ) { // Anfang der Strings suchen - ImpContent * pFind = (ImpContent *) - bsearch( (void *)((ULONG(RT_SYS_BITMAP) << 16) | nId), pContent, nEntries, - sizeof( ImpContent ), Search ); - - if ( pFind ) + ImpContent * pFind = ::std::lower_bound(pContent, + pContent + nEntries, + ((ULONG(RT_SYS_BITMAP) << 16) | nId), + ImpContentMixLessCompare()); + if ( (pFind != (pContent + nEntries)) && (pFind->nTypeAndId == ((ULONG(RT_SYS_BITMAP) << 16) | nId)) ) { pStm->Seek( pFind->nOffset ); return pStm; } +// ImpContent * pFind = (ImpContent *) +// bsearch( (void *)((ULONG(RT_SYS_BITMAP) << 16) | nId), pContent, nEntries, +// sizeof( ImpContent ), Search ); + +// if ( pFind ) +// { +// pStm->Seek( pFind->nOffset ); +// return pStm; +// } return NULL; } @@ -221,7 +254,8 @@ void InternalResMgr::GetResMgrPath( InternalResMgr* pThis, INetURLObject aAppDir( *pAppFileName, INET_PROT_FILE ); aAppDir.CutName(); UniString aAppPath = aAppDir.PathToFileName(); - aAppDir.Append( String( RTL_CONSTASCII_USTRINGPARAM( "resource" ) ) ); + static const String sResource( RTL_CONSTASCII_USTRINGPARAM( "resource" ) ); + aAppDir.Append( sResource ); UniString aAppResPath = aAppDir.PathToFileName(); // Default resource path is bin\resource @@ -334,7 +368,7 @@ InternalResMgr::~InternalResMgr() aLine.Append( ByteString( aFileName, RTL_TEXTENCODING_UTF8 ) ); aStm.WriteLine( aLine ); - for( ULONG i = 0; i < pResUseDump->Count(); i++ ) + for( ULONG i = 0; i < pResUseDump->Count(); ++i ) { ULONG nKeyId = pResUseDump->GetObjectKey( i ); aLine.Assign( "Type/Id: " ); @@ -403,29 +437,31 @@ BOOL InternalResMgr::Create() if ( pLogFile ) { pResUseDump = new Table(); - for( ULONG i = 0; i < nEntries; i++ ) + for( ULONG i = 0; i < nEntries; ++i ) pResUseDump->Insert( pContent[i].nTypeAndId, NULL ); } #endif // swap the content to the right endian pContent[0].nTypeAndId = ResMgr::GetLong( &pContent[0].nTypeAndId ); pContent[0].nOffset = ResMgr::GetLong( &pContent[0].nOffset ); - for( ULONG i = 0; i < nEntries -1; i++ ) + ULONG nCount = nEntries - 1; + for( ULONG i = 0,j=1; i < nCount; ++i,++j ) { // swap the content to the right endian - pContent[i+1].nTypeAndId = ResMgr::GetLong( &pContent[i+1].nTypeAndId ); - pContent[i+1].nOffset = ResMgr::GetLong( &pContent[i+1].nOffset ); - if( pContent[i].nTypeAndId >= pContent[i +1].nTypeAndId ) + pContent[j].nTypeAndId = ResMgr::GetLong( &pContent[j].nTypeAndId ); + pContent[j].nOffset = ResMgr::GetLong( &pContent[j].nOffset ); + if( pContent[i].nTypeAndId >= pContent[j].nTypeAndId ) bSorted = FALSE; - if( (pContent[i].nTypeAndId & 0xFFFF0000) == (pContent[i +1].nTypeAndId & 0xFFFF0000) - && pContent[i].nOffset >= pContent[i +1].nOffset ) + if( (pContent[i].nTypeAndId & 0xFFFF0000) == (pContent[j].nTypeAndId & 0xFFFF0000) + && pContent[i].nOffset >= pContent[j].nOffset ) bEqual2Content = FALSE; } } DBG_ASSERT( bSorted, "content not sorted" ) DBG_ASSERT( bEqual2Content, "resource structure wrong" ) if( !bSorted ) - qsort( pContent, nEntries, sizeof( ImpContent ), Compare ); + ::std::sort(pContent,pContent+nEntries,ImpContentLessCompare()); + // qsort( pContent, nEntries, sizeof( ImpContent ), Compare ); bDone = TRUE; } @@ -494,10 +530,15 @@ void InternalResMgr::FreeInternalResMgr( InternalResMgr* pFreeInternalResMgr ) BOOL InternalResMgr::IsGlobalAvailable( RESOURCE_TYPE nRT, USHORT nId ) const { // Anfang der Strings suchen - ImpContent * pFind = (ImpContent *) - bsearch( (void *)((ULONG(nRT) << 16) | nId), pContent, nEntries, - sizeof( ImpContent ), Search ); - return pFind != NULL; + ULONG nValue = ((ULONG(nRT) << 16) | nId); + ImpContent * pFind = ::std::lower_bound(pContent, + pContent + nEntries, + nValue, + ImpContentMixLessCompare()); +// ImpContent * pFind = (ImpContent *) +// bsearch( (void *)((ULONG(nRT) << 16) | nId), pContent, nEntries, +// sizeof( ImpContent ), Search ); + return (pFind != (pContent + nEntries)) && (pFind->nTypeAndId == nValue); } // ----------------------------------------------------------------------- @@ -510,10 +551,16 @@ void* InternalResMgr::LoadGlobalRes( RESOURCE_TYPE nRT, USHORT nId, pResUseDump->Remove( (ULONG(nRT) << 16) | nId ); #endif // Anfang der Strings suchen - ImpContent * pFind = (ImpContent *) - bsearch( (void *)((ULONG(nRT) << 16) | nId), pContent, nEntries, - sizeof( ImpContent ), Search ); - if( nRT == RSC_STRING && bEqual2Content && pFind ) + ULONG nValue = ((ULONG(nRT) << 16) | nId); + ImpContent* pEnd = (pContent + nEntries); + ImpContent* pFind = ::std::lower_bound( pContent, + pEnd, + nValue, + ImpContentMixLessCompare()); +// ImpContent * pFind = (ImpContent *) +// bsearch( (void *)((ULONG(nRT) << 16) | nId), pContent, nEntries, +// sizeof( ImpContent ), Search ); + if( nRT == RSC_STRING && bEqual2Content && ((pFind != pEnd) && (pFind->nTypeAndId == nValue)) ) { // String Optimierung if( !pStringBlock ) @@ -522,9 +569,9 @@ void* InternalResMgr::LoadGlobalRes( RESOURCE_TYPE nRT, USHORT nId, ImpContent * pFirst = pFind; ImpContent * pLast = pFirst; while( pFirst > pContent && ((pFirst -1)->nTypeAndId >> 16) == RSC_STRING ) - pFirst--; - while( pLast < (pContent + nEntries) && (pLast->nTypeAndId >> 16) == RSC_STRING ) - pLast++; + --pFirst; + while( pLast < pEnd && (pLast->nTypeAndId >> 16) == RSC_STRING ) + ++pLast; nOffCorrection = pFirst->nOffset; UINT32 nSize; --pLast; @@ -624,7 +671,7 @@ static void RscError_Impl( const sal_Char* pMessage, ResMgr* pResMgr, aStr.Append( ByteString( GetTypeRes_Impl( ResId( (pResStack + nStackTop)->pResource->GetRT(), pNewResMgr ) ), RTL_TEXTENCODING_UTF8 ) ); aStr.Append( ", Id: " ); aStr.Append( ByteString::CreateFromInt32( (long)(pResStack + nStackTop)->pResource->GetId() ) ); - nStackTop--; + --nStackTop; } delete pNewResMgr; @@ -806,7 +853,7 @@ void ResMgr::TestStack( const Resource* pResObj ) { if ( DbgIsResource() ) { - for( short i = 1; i <= nTopRes; i++ ) + for( short i = 1; i <= nTopRes; ++i ) { if ( aStack[i].pResObj == pResObj ) { @@ -885,8 +932,7 @@ BOOL ResMgr::GetResource( const ResId& rId, const Resource* pResObj ) if ( pLastMgr != this ) Resource::SetResManager( this ); - nTopRes++; // Stackzeiger erhoehen - ImpRCStack* pTop = &aStack[nTopRes]; + ImpRCStack* pTop = &aStack[++nTopRes];// Stackzeiger erhoehen pTop->Init( pLastMgr, pResObj, nId | (rId.IsAutoRelease() ? 0 : RSC_DONTRELEASE) ); @@ -901,7 +947,7 @@ BOOL ResMgr::GetResource( const ResId& rId, const Resource* pResObj ) this, nRT, nId, aStack, nTopRes -1 ); #endif RscException_Impl(); - nTopRes--; + --nTopRes; return FALSE; } } @@ -924,7 +970,7 @@ BOOL ResMgr::GetResource( const ResId& rId, const Resource* pResObj ) this, nRT, nId, aStack, nTopRes -1 ); #endif RscException_Impl(); - nTopRes--; + --nTopRes; return FALSE; } } @@ -990,7 +1036,7 @@ void ResMgr::PopContext( const Resource* ) if ( pTop->pResMgr != this ) // wurde durch ResId gesetzt, automatisch zuruecksetzen Resource::SetResManager( pTop->pResMgr ); - nTopRes--; + --nTopRes; } } @@ -1073,17 +1119,19 @@ USHORT ResMgr::GetRemainSize() void* ResMgr::Increment( USHORT nSize ) { - BYTE* pClassRes = (BYTE*)aStack[nTopRes].pClassRes + nSize; + ImpRCStack& rStack = aStack[nTopRes]; + BYTE* pClassRes = (BYTE*)rStack.pClassRes + nSize; - aStack[nTopRes].pClassRes = pClassRes; + rStack.pClassRes = pClassRes; - RSHEADER_TYPE* pRes = aStack[nTopRes].pResource; + RSHEADER_TYPE* pRes = rStack.pResource; - if ( (pRes->GetGlobOff() == pRes->GetLocalOff()) && - (((char*)pRes + pRes->GetLocalOff()) == aStack[nTopRes].pClassRes) && - (aStack[nTopRes].Flags & RC_AUTORELEASE)) + USHORT nLocalOff = pRes->GetLocalOff(); + if ( (pRes->GetGlobOff() == nLocalOff) && + (((char*)pRes + nLocalOff) == rStack.pClassRes) && + (rStack.Flags & RC_AUTORELEASE)) { - PopContext( aStack[nTopRes].pResObj ); + PopContext( rStack.pResObj ); } return pClassRes; @@ -1273,7 +1321,7 @@ ResMgr* ResMgr::CreateResMgr( const sal_Char* pPrefixName, UniString aName; InternalResMgr* pInternalResMgr = NULL; int i; - for ( i = 0; i < 6; i++ ) + for ( i = 0; i < 6; ++i ) { pLang[i] = GetLang( nType, i ); @@ -1351,7 +1399,7 @@ ResMgr* ResMgr::SearchCreateResMgr( LANGUAGE_HINDI }; - for( size_t i = 0; i < sizeof( aLanguages )/sizeof( aLanguages[0] ); i++ ) + for( size_t i = 0; i < sizeof( aLanguages )/sizeof( aLanguages[0] ); ++i ) { nType = aLanguages[i]; aName = aBaseName; @@ -1417,7 +1465,7 @@ SimpleResMgr::SimpleResMgr( const sal_Char* pPrefixName, // Resourcefile suchen UniString aName; - for ( int i = 0; i < 6; i++ ) + for ( int i = 0; i < 6; ++i ) { pLang[i] = ResMgr::GetLang( nType, i ); diff --git a/tools/source/ref/makefile.mk b/tools/source/ref/makefile.mk index ad85f0accd62..dca712a0de34 100644 --- a/tools/source/ref/makefile.mk +++ b/tools/source/ref/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.1.1.1 $ +# $Revision: 1.2 $ # -# last change: $Author: hr $ $Date: 2000-09-18 17:03:09 $ +# last change: $Author: hr $ $Date: 2003-03-27 17:04:43 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -78,12 +78,10 @@ SLOFILES= $(SLO)$/ref.obj \ $(SLO)$/globname.obj \ $(SLO)$/errinf.obj -.IF "$(UPDATER)"!="" OBJFILES= $(OBJ)$/ref.obj \ $(OBJ)$/pstm.obj \ $(OBJ)$/globname.obj \ $(OBJ)$/errinf.obj -.ENDIF # --- Targets ------------------------------------------------------ diff --git a/tools/source/solar/makefile.mk b/tools/source/solar/makefile.mk index f9636dcd5378..f0b41d148021 100644 --- a/tools/source/solar/makefile.mk +++ b/tools/source/solar/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.3 $ +# $Revision: 1.4 $ # -# last change: $Author: hjs $ $Date: 2001-08-22 10:27:20 $ +# last change: $Author: hr $ $Date: 2003-03-27 17:04:44 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -66,6 +66,8 @@ PRJNAME=tools TARGET=mksvconf TARGETTYPE=CUI +LIBSALCPPRT=$(0) + # --- Settings ----------------------------------------------------- .INCLUDE : svpre.mk diff --git a/tools/source/stream/makefile.mk b/tools/source/stream/makefile.mk index 725a7e35f34d..c9d8cd9cbac4 100644 --- a/tools/source/stream/makefile.mk +++ b/tools/source/stream/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.3 $ +# $Revision: 1.4 $ # -# last change: $Author: th $ $Date: 2001-07-03 14:52:19 $ +# last change: $Author: hr $ $Date: 2003-03-27 17:04:46 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -78,13 +78,10 @@ SLOFILES= $(SLO)$/stream.obj \ $(SLO)$/cachestr.obj \ $(SLO)$/vcompat.obj -.IF "$(UPDATER)" != "" - OBJFILES+= $(OBJ)$/stream.obj \ $(OBJ)$/strmsys.obj \ $(OBJ)$/cachestr.obj \ $(OBJ)$/vcompat.obj -.ENDIF # --- Targets ------------------------------------------------------- diff --git a/tools/source/stream/strmunx.cxx b/tools/source/stream/strmunx.cxx index 1680c03348dd..60ba6ee4c2b4 100644 --- a/tools/source/stream/strmunx.cxx +++ b/tools/source/stream/strmunx.cxx @@ -2,9 +2,9 @@ * * $RCSfile: strmunx.cxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: hro $ $Date: 2001-07-27 08:10:24 $ + * last change: $Author: hr $ $Date: 2003-03-27 17:04:46 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -244,7 +244,7 @@ static ULONG GetSvError( int nErrno ) { 0, SVSTREAM_OK }, { EACCES, SVSTREAM_ACCESS_DENIED }, { EBADF, SVSTREAM_INVALID_HANDLE }, -#if defined( RS6000 ) || defined( ALPHA ) || defined( HP9000 ) || defined( NETBSD ) || defined( S390 ) || defined(FREEBSD) || defined(MACOSX) +#if defined( RS6000 ) || defined( ALPHA ) || defined( HP9000 ) || defined( NETBSD ) || defined(FREEBSD) || defined(MACOSX) { EDEADLK, SVSTREAM_LOCKING_VIOLATION }, #else { EDEADLOCK, SVSTREAM_LOCKING_VIOLATION }, diff --git a/tools/source/string/makefile.mk b/tools/source/string/makefile.mk index 5280ab5bd6e2..88eb4c58189a 100644 --- a/tools/source/string/makefile.mk +++ b/tools/source/string/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.2 $ +# $Revision: 1.3 $ # -# last change: $Author: th $ $Date: 2001-07-06 13:47:33 $ +# last change: $Author: hr $ $Date: 2003-03-27 17:04:49 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -78,13 +78,10 @@ SLOFILES= $(SLO)$/tstring.obj \ $(SLO)$/charset.obj \ $(SLO)$/tenccvt.obj - -.IF "$(UPDATER)"!="" OBJFILES= $(OBJ)$/tstring.obj \ $(OBJ)$/tustring.obj \ $(OBJ)$/charset.obj \ $(OBJ)$/tenccvt.obj -.ENDIF # --- Targets ------------------------------------------------------ diff --git a/tools/source/string/strascii.cxx b/tools/source/string/strascii.cxx index 276169cca84f..9b85c4ff16d0 100644 --- a/tools/source/string/strascii.cxx +++ b/tools/source/string/strascii.cxx @@ -2,9 +2,9 @@ * * $RCSfile: strascii.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: th $ $Date: 2001-07-25 10:46:27 $ + * last change: $Author: hr $ $Date: 2003-03-27 17:04:50 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -69,8 +69,8 @@ static BOOL ImplDbgCheckAsciiStr( const sal_Char* pAsciiStr, xub_StrLen nLen ) { if ( ((unsigned char)*pAsciiStr) > 127 ) return FALSE; - pAsciiStr++; - nLen--; + ++pAsciiStr, + --nLen; } return TRUE; @@ -89,9 +89,9 @@ static void ImplCopyAsciiStr( sal_Unicode* pDest, const sal_Char* pSrc, while ( nLen ) { *pDest = (unsigned char)*pSrc; - pDest++; - pSrc++; - nLen--; + ++pDest, + ++pSrc, + --nLen; } } @@ -103,8 +103,8 @@ static sal_Int32 ImplStringCompareAscii( const sal_Unicode* pStr1, const sal_Cha while ( ((nRet = ((sal_Int32)*pStr1)-((sal_Int32)((unsigned char)*pStr2))) == 0) && *pStr2 ) { - pStr1++; - pStr2++; + ++pStr1, + ++pStr2; } return nRet; @@ -120,9 +120,9 @@ static sal_Int32 ImplStringCompareAscii( const sal_Unicode* pStr1, const sal_Cha ((nRet = ((sal_Int32)*pStr1)-((sal_Int32)((unsigned char)*pStr2))) == 0) && *pStr2 ) { - pStr1++; - pStr2++; - nCount--; + ++pStr1, + ++pStr2, + --nCount; } return nRet; @@ -137,9 +137,9 @@ static sal_Int32 ImplStringCompareWithoutZeroAscii( const sal_Unicode* pStr1, co while ( nCount && ((nRet = ((sal_Int32)*pStr1)-((sal_Int32)((unsigned char)*pStr2))) == 0) ) { - pStr1++; - pStr2++; - nCount--; + ++pStr1, + ++pStr2, + --nCount; } return nRet; @@ -165,8 +165,8 @@ static sal_Int32 ImplStringICompareAscii( const sal_Unicode* pStr1, const sal_Ch if ( nRet != 0 ) break; - pStr1++; - pStr2++; + ++pStr1, + ++pStr2; } while ( c2 ); @@ -197,9 +197,9 @@ static sal_Int32 ImplStringICompareAscii( const sal_Unicode* pStr1, const sal_Ch if ( nRet != 0 ) break; - pStr1++; - pStr2++; - nCount--; + ++pStr1, + ++pStr2, + --nCount; } while ( c2 ); @@ -294,7 +294,7 @@ UniString& UniString::AssignAscii( const sal_Char* pAsciiStr, xub_StrLen nLen ) #ifdef DBG_UTIL if ( DbgIsAssert() ) { - for ( xub_StrLen i = 0; i < nLen; i++ ) + for ( xub_StrLen i = 0; i < nLen; ++i ) { if ( !pAsciiStr[i] ) { @@ -373,7 +373,7 @@ UniString& UniString::AppendAscii( const sal_Char* pAsciiStr, xub_StrLen nLen ) #ifdef DBG_UTIL if ( DbgIsAssert() ) { - for ( xub_StrLen i = 0; i < nLen; i++ ) + for ( xub_StrLen i = 0; i < nLen; ++i ) { if ( !pAsciiStr[i] ) { @@ -622,8 +622,8 @@ xub_StrLen UniString::SearchAscii( const sal_Char* pAsciiStr, xub_StrLen nIndex { if ( *pStr == cSearch ) return nIndex; - pStr++; - nIndex++; + ++pStr, + ++nIndex; } } else @@ -634,8 +634,8 @@ xub_StrLen UniString::SearchAscii( const sal_Char* pAsciiStr, xub_StrLen nIndex // Stimmt der String ueberein if ( ImplStringCompareWithoutZeroAscii( pStr, pAsciiStr, nStrLen ) == 0 ) return nIndex; - pStr++; - nIndex++; + ++pStr, + ++nIndex; } } diff --git a/tools/source/string/strcvt.cxx b/tools/source/string/strcvt.cxx index 4fd99aceca6e..32dfa83aedf7 100644 --- a/tools/source/string/strcvt.cxx +++ b/tools/source/string/strcvt.cxx @@ -2,9 +2,9 @@ * * $RCSfile: strcvt.cxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: kz $ $Date: 2001-03-20 10:31:27 $ + * last change: $Author: hr $ $Date: 2003-03-27 17:04:50 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -607,7 +607,12 @@ ByteString::ByteString( const rtl::OString& rStr ) { DBG_CTOR( ByteString, DbgCheckByteString ); - mpData = (ByteStringData*)rStr.pData; + OSL_ENSURE(rStr.pData->length < STRING_MAXLEN, + "Overflowing rtl::OString -> ByteString cut to zero length"); + mpData = rStr.pData->length < STRING_MAXLEN + ? reinterpret_cast< ByteStringData * >( + const_cast< rtl::OString & >(rStr).pData) + : &aImplEmptyStrData; ImplIncRefCount( mpData ); } @@ -625,8 +630,13 @@ ByteString& ByteString::Assign( const rtl::OString& rStr ) { DBG_CHKTHIS( ByteString, DbgCheckByteString ); - rtl_string_acquire( rStr.pData ); + OSL_ENSURE(rStr.pData->length < STRING_MAXLEN, + "Overflowing rtl::OString -> ByteString cut to zero length"); ImplDeleteData( mpData ); - mpData = (ByteStringData*)rStr.pData; + mpData = rStr.pData->length < STRING_MAXLEN + ? reinterpret_cast< ByteStringData * >( + const_cast< rtl::OString & >(rStr).pData) + : &aImplEmptyStrData; + ImplIncRefCount( mpData ); return *this; } diff --git a/tools/source/string/strimp.cxx b/tools/source/string/strimp.cxx index 69238d202578..9e9457064141 100644 --- a/tools/source/string/strimp.cxx +++ b/tools/source/string/strimp.cxx @@ -2,9 +2,9 @@ * * $RCSfile: strimp.cxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: th $ $Date: 2001-03-16 15:26:15 $ + * last change: $Author: hr $ $Date: 2003-03-27 17:04:52 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -77,8 +77,8 @@ static sal_Int32 ImplStringCompare( const STRCODE* pStr1, const STRCODE* pStr2 ) *pStr2 ) #endif { - pStr1++; - pStr2++; + ++pStr1, + ++pStr2; } return nRet; @@ -100,9 +100,9 @@ static sal_Int32 ImplStringCompare( const STRCODE* pStr1, const STRCODE* pStr2, *pStr2 ) #endif { - pStr1++; - pStr2++; - nCount--; + ++pStr1, + ++pStr2, + --nCount; } return nRet; @@ -122,9 +122,9 @@ static sal_Int32 ImplStringCompareWithoutZero( const STRCODE* pStr1, const STRCO ((nRet = ((sal_Int32)((unsigned STRCODE)*pStr1))-((sal_Int32)((unsigned STRCODE)*pStr2))) == 0) ) #endif { - pStr1++; - pStr2++; - nCount--; + ++pStr1, + ++pStr2, + --nCount; } return nRet; @@ -154,8 +154,8 @@ static sal_Int32 ImplStringICompare( const STRCODE* pStr1, const STRCODE* pStr2 if ( nRet != 0 ) break; - pStr1++; - pStr2++; + ++pStr1, + ++pStr2; } while ( c2 ); @@ -190,9 +190,9 @@ static sal_Int32 ImplStringICompare( const STRCODE* pStr1, const STRCODE* pStr2, if ( nRet != 0 ) break; - pStr1++; - pStr2++; - nCount--; + ++pStr1, + ++pStr2, + --nCount; } while ( c2 ); @@ -225,9 +225,9 @@ static sal_Int32 ImplStringICompareWithoutZero( const STRCODE* pStr1, const STRC nRet = ((sal_Int32)((unsigned STRCODE)c1))-((sal_Int32)((unsigned STRCODE)c2)); #endif - pStr1++; - pStr2++; - nCount--; + ++pStr1, + ++pStr2, + --nCount; } while ( nRet == 0 ); @@ -1048,8 +1048,8 @@ STRING& STRING::Fill( xub_StrLen nCount, STRCODE cFillChar ) do { *pStr = cFillChar; - pStr++; - nCount--; + ++pStr, + --nCount; } while ( nCount ); @@ -1080,8 +1080,8 @@ STRING& STRING::Expand( xub_StrLen nCount, STRCODE cExpandChar ) do { *pStr = cExpandChar; - pStr++; - nCount--; + ++pStr, + --nCount; } while ( nCount ); @@ -1103,7 +1103,7 @@ STRING& STRING::EraseLeadingChars( STRCODE c ) xub_StrLen nStart = 0; while ( mpData->maStr[nStart] == c ) - nStart++; + ++nStart; return Erase( 0, nStart ); } @@ -1132,7 +1132,7 @@ STRING& STRING::EraseLeadingAndTrailingChars( STRCODE c ) xub_StrLen nStart = 0; while ( mpData->maStr[nStart] == c ) - nStart++; + ++nStart; if ( nStart ) Erase( 0, nStart ); @@ -1156,8 +1156,8 @@ STRING& STRING::EraseAllChars( STRCODE c ) while ( i < mpData->mnLen ) { if ( mpData->maStr[i] == c ) - nCount++; - i++; + ++nCount; + ++i; } if ( nCount ) @@ -1175,12 +1175,12 @@ STRING& STRING::EraseAllChars( STRCODE c ) // Alten String kopieren und initialisieren nCount = 0; - for( xub_StrLen i = 0; i < mpData->mnLen; i++ ) + for( xub_StrLen i = 0; i < mpData->mnLen; ++i ) { if ( mpData->maStr[i] != c ) { pNewData->maStr[nCount] = mpData->maStr[i]; - nCount++; + ++nCount; } } @@ -1208,7 +1208,7 @@ STRING& STRING::Reverse() // Reverse STRCODE cTemp; xub_StrLen nCount = mpData->mnLen / 2; - for ( xub_StrLen i = 0; i < nCount; i++ ) + for ( xub_StrLen i = 0; i < nCount; ++i ) { cTemp = mpData->maStr[i]; mpData->maStr[i] = mpData->maStr[mpData->mnLen-i-1]; @@ -1237,8 +1237,8 @@ STRING& STRING::ToLowerAscii() *pStr += 32; } - pStr++; - nIndex++; + ++pStr, + ++nIndex; } return *this; @@ -1263,8 +1263,8 @@ STRING& STRING::ToUpperAscii() *pStr -= 32; } - pStr++; - nIndex++; + ++pStr, + ++nIndex; } return *this; @@ -1306,11 +1306,11 @@ STRING& STRING::ConvertLineEnd( LineEnd eLineEnd ) // \r\n oder \n\r, dann Zeichen ueberspringen if ( ((pStr[i+1] == _CR) || (pStr[i+1] == _LF)) && (pStr[i] != pStr[i+1]) ) - i++; + ++i; } else - nLen++; - i++; + ++nLen; + ++i; // Wenn String zu lang, dann konvertieren wir nicht if ( nLen >= STRING_MAXLEN ) @@ -1341,20 +1341,20 @@ STRING& STRING::ConvertLineEnd( LineEnd eLineEnd ) pNewData->maStr[j] = _CR; else pNewData->maStr[j] = _LF; - j++; + ++j; } if ( ((pStr[i+1] == _CR) || (pStr[i+1] == _LF)) && (pStr[i] != pStr[i+1]) ) - i++; + ++i; } else { pNewData->maStr[j] = mpData->maStr[i]; - j++; + ++j; } - i++; + ++i; } // Alte Daten loeschen und Neue zuweisen @@ -1607,9 +1607,9 @@ xub_StrLen STRING::Match( const STRING& rStr ) const // Stimmt das Zeichen nicht ueberein, dann abbrechen if ( *pStr1 != *pStr2 ) return i; - pStr1++; - pStr2++; - i++; + ++pStr1, + ++pStr2, + ++i; } return STRING_MATCH; @@ -1633,9 +1633,9 @@ xub_StrLen STRING::Match( const STRCODE* pCharStr ) const // Stimmt das Zeichen nicht ueberein, dann abbrechen if ( *pStr != *pCharStr ) return i; - pStr++; - pCharStr++; - i++; + ++pStr, + ++pCharStr, + ++i; } return STRING_MATCH; @@ -1654,8 +1654,8 @@ xub_StrLen STRING::Search( STRCODE c, xub_StrLen nIndex ) const { if ( *pStr == c ) return nIndex; - pStr++; - nIndex++; + ++pStr, + ++nIndex; } return STRING_NOTFOUND; @@ -1686,8 +1686,8 @@ xub_StrLen STRING::Search( const STRING& rStr, xub_StrLen nIndex ) const { if ( *pStr1 == cSearch ) return nIndex; - pStr1++; - nIndex++; + ++pStr1, + ++nIndex; } } else @@ -1700,8 +1700,8 @@ xub_StrLen STRING::Search( const STRING& rStr, xub_StrLen nIndex ) const // Stimmt der String ueberein if ( ImplStringCompareWithoutZero( pStr1, pStr2, nStrLen ) == 0 ) return nIndex; - pStr1++; - nIndex++; + ++pStr1, + ++nIndex; } } @@ -1732,8 +1732,8 @@ xub_StrLen STRING::Search( const STRCODE* pCharStr, xub_StrLen nIndex ) const { if ( *pStr == cSearch ) return nIndex; - pStr++; - nIndex++; + ++pStr, + ++nIndex; } } else @@ -1744,8 +1744,8 @@ xub_StrLen STRING::Search( const STRCODE* pCharStr, xub_StrLen nIndex ) const // Stimmt der String ueberein if ( ImplStringCompareWithoutZero( pStr, pCharStr, nStrLen ) == 0 ) return nIndex; - pStr++; - nIndex++; + ++pStr, + ++nIndex; } } @@ -1792,10 +1792,10 @@ xub_StrLen STRING::SearchChar( const STRCODE* pChars, xub_StrLen nIndex ) const { if ( *pCompStr == c ) return nIndex; - pCompStr++; + ++pCompStr; } - pStr++; - nIndex++; + ++pStr, + ++nIndex; } return STRING_NOTFOUND; @@ -1824,7 +1824,7 @@ xub_StrLen STRING::SearchCharBackward( const STRCODE* pChars, xub_StrLen nIndex { if ( *pCompStr == c ) return nIndex; - pCompStr++; + ++pCompStr; } } @@ -1848,8 +1848,8 @@ xub_StrLen STRING::SearchAndReplace( STRCODE c, STRCODE cRep, xub_StrLen nIndex mpData->maStr[nIndex] = cRep; return nIndex; } - pStr++; - nIndex++; + ++pStr, + ++nIndex; } return STRING_NOTFOUND; @@ -1902,8 +1902,8 @@ void STRING::SearchAndReplaceAll( STRCODE c, STRCODE cRep ) ImplCopyData( this ); mpData->maStr[nIndex] = cRep; } - pStr++; - nIndex++; + ++pStr, + ++nIndex; } } @@ -1959,9 +1959,9 @@ xub_StrLen STRING::GetTokenCount( STRCODE cTok ) const { // Stimmt das Tokenzeichen ueberein, dann erhoehe TokCount if ( *pStr == cTok ) - nTokCount++; - pStr++; - nIndex++; + ++nTokCount; + ++pStr, + ++nIndex; } return nTokCount; @@ -1988,7 +1988,7 @@ void STRING::SetToken( xub_StrLen nToken, STRCODE cTok, const STRING& rStr, // Stimmt das Tokenzeichen ueberein, dann erhoehe TokCount if ( *pStr == cTok ) { - nTok++; + ++nTok; if ( nTok == nToken ) nFirstChar = i+1; @@ -1999,8 +1999,8 @@ void STRING::SetToken( xub_StrLen nToken, STRCODE cTok, const STRING& rStr, } } - pStr++; - i++; + ++pStr, + ++i; } if ( nTok >= nToken ) @@ -2026,7 +2026,7 @@ STRING STRING::GetToken( xub_StrLen nToken, STRCODE cTok, xub_StrLen& rIndex ) c // Stimmt das Tokenzeichen ueberein, dann erhoehe TokCount if ( *pStr == cTok ) { - nTok++; + ++nTok; if ( nTok == nToken ) nFirstChar = i+1; @@ -2037,8 +2037,8 @@ STRING STRING::GetToken( xub_StrLen nToken, STRCODE cTok, xub_StrLen& rIndex ) c } } - pStr++; - i++; + ++pStr, + ++i; } if ( nTok >= nToken ) @@ -2102,11 +2102,11 @@ xub_StrLen STRING::GetQuotedTokenCount( const STRING& rQuotedPairs, STRCODE cTok // Stimmt das Tokenzeichen ueberein, dann erhoehe TokCount if ( c == cTok ) - nTokCount++; + ++nTokCount; } - pStr++; - nIndex++; + ++pStr, + ++nIndex; } return nTokCount; @@ -2160,7 +2160,7 @@ STRING STRING::GetQuotedToken( xub_StrLen nToken, const STRING& rQuotedPairs, // Stimmt das Tokenzeichen ueberein, dann erhoehe TokCount if ( c == cTok ) { - nTok++; + ++nTok; if ( nTok == nToken ) nFirstChar = i+1; @@ -2172,8 +2172,8 @@ STRING STRING::GetQuotedToken( xub_StrLen nToken, const STRING& rQuotedPairs, } } - pStr++; - i++; + ++pStr, + ++i; } if ( nTok >= nToken ) diff --git a/tools/source/string/strucvt.cxx b/tools/source/string/strucvt.cxx index af80df369a77..cc771af75311 100644 --- a/tools/source/string/strucvt.cxx +++ b/tools/source/string/strucvt.cxx @@ -2,9 +2,9 @@ * * $RCSfile: strucvt.cxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: kz $ $Date: 2001-03-20 10:31:27 $ + * last change: $Author: hr $ $Date: 2003-03-27 17:04:53 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -149,7 +149,12 @@ UniString::UniString( const rtl::OUString& rStr ) { DBG_CTOR( UniString, DbgCheckUniString ); - mpData = (UniStringData*)rStr.pData; + OSL_ENSURE(rStr.pData->length < STRING_MAXLEN, + "Overflowing rtl::OUString -> UniString cut to zero length"); + mpData = rStr.pData->length < STRING_MAXLEN + ? reinterpret_cast< UniStringData * >( + const_cast< rtl::OUString & >(rStr).pData) + : &aImplEmptyStrData; ImplIncRefCount( mpData ); } @@ -167,8 +172,13 @@ UniString& UniString::Assign( const rtl::OUString& rStr ) { DBG_CHKTHIS( UniString, DbgCheckUniString ); - rtl_uString_acquire( rStr.pData ); + OSL_ENSURE(rStr.pData->length < STRING_MAXLEN, + "Overflowing rtl::OUString -> UniString cut to zero length"); ImplDeleteData( mpData ); - mpData = (UniStringData*)rStr.pData; + mpData = rStr.pData->length < STRING_MAXLEN + ? reinterpret_cast< UniStringData * >( + const_cast< rtl::OUString & >(rStr).pData) + : &aImplEmptyStrData; + ImplIncRefCount( mpData ); return *this; } diff --git a/tools/source/string/tstring.cxx b/tools/source/string/tstring.cxx index 0f8a01a35447..290e70eeefc1 100644 --- a/tools/source/string/tstring.cxx +++ b/tools/source/string/tstring.cxx @@ -2,9 +2,9 @@ * * $RCSfile: tstring.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: th $ $Date: 2001-03-16 15:25:43 $ + * last change: $Author: hr $ $Date: 2003-03-27 17:04:53 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -104,7 +104,7 @@ xub_StrLen ImplStringLen( const sal_Char* pStr ) { const sal_Char* pTempStr = pStr; while( *pTempStr ) - pTempStr++; + ++pTempStr; return (xub_StrLen)(pTempStr-pStr); } @@ -114,7 +114,7 @@ xub_StrLen ImplStringLen( const sal_Unicode* pStr ) { const sal_Unicode* pTempStr = pStr; while( *pTempStr ) - pTempStr++; + ++pTempStr; return (xub_StrLen)(pTempStr-pStr); } @@ -205,8 +205,8 @@ BOOL ByteString::IsLowerAscii() const if ( (*pStr >= 65) && (*pStr <= 90) ) return FALSE; - pStr++; - nIndex++; + ++pStr, + ++nIndex; } return TRUE; @@ -226,8 +226,8 @@ BOOL ByteString::IsUpperAscii() const if ( (*pStr >= 97) && (*pStr <= 122) ) return FALSE; - pStr++; - nIndex++; + ++pStr, + ++nIndex; } return TRUE; @@ -248,8 +248,8 @@ BOOL ByteString::IsAlphaAscii() const ((*pStr >= 65) && (*pStr <= 90))) ) return FALSE; - pStr++; - nIndex++; + ++pStr, + ++nIndex; } return TRUE; @@ -269,8 +269,8 @@ BOOL ByteString::IsNumericAscii() const if ( !((*pStr >= 48) && (*pStr <= 57)) ) return FALSE; - pStr++; - nIndex++; + ++pStr, + ++nIndex; } return TRUE; @@ -292,8 +292,8 @@ BOOL ByteString::IsAlphaNumericAscii() const ((*pStr >= 48) && (*pStr <= 57))) ) return FALSE; - pStr++; - nIndex++; + ++pStr, + ++nIndex; } return TRUE; |