xref: /aoo41x/main/tools/source/generic/gen.cxx (revision 89b56da7)
1*89b56da7SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*89b56da7SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*89b56da7SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*89b56da7SAndrew Rist  * distributed with this work for additional information
6*89b56da7SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*89b56da7SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*89b56da7SAndrew Rist  * "License"); you may not use this file except in compliance
9*89b56da7SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*89b56da7SAndrew Rist  *
11*89b56da7SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*89b56da7SAndrew Rist  *
13*89b56da7SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*89b56da7SAndrew Rist  * software distributed under the License is distributed on an
15*89b56da7SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*89b56da7SAndrew Rist  * KIND, either express or implied.  See the License for the
17*89b56da7SAndrew Rist  * specific language governing permissions and limitations
18*89b56da7SAndrew Rist  * under the License.
19*89b56da7SAndrew Rist  *
20*89b56da7SAndrew Rist  *************************************************************/
21*89b56da7SAndrew Rist 
22*89b56da7SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_tools.hxx"
26cdf0e10cSrcweir #include <tools/debug.hxx>
27cdf0e10cSrcweir #include <tools/gen.hxx>
28cdf0e10cSrcweir #include <tools/stream.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir // =======================================================================
31cdf0e10cSrcweir 
operator >>(SvStream & rIStream,Pair & rPair)32cdf0e10cSrcweir SvStream& operator>>( SvStream& rIStream, Pair& rPair )
33cdf0e10cSrcweir {
34cdf0e10cSrcweir 	DBG_ASSERTWARNING( rIStream.GetVersion(), "Pair::>> - Solar-Version not set on rIStream" );
35cdf0e10cSrcweir 
36cdf0e10cSrcweir 	if ( rIStream.GetCompressMode() == COMPRESSMODE_FULL )
37cdf0e10cSrcweir 	{
38cdf0e10cSrcweir 		unsigned char	cId;
39cdf0e10cSrcweir 		unsigned char	cAry[8];
40cdf0e10cSrcweir 		int 			i;
41cdf0e10cSrcweir 		int 			i1;
42cdf0e10cSrcweir 		int 			i2;
43cdf0e10cSrcweir 		sal_uInt32			nNum;
44cdf0e10cSrcweir 
45cdf0e10cSrcweir 		rIStream >> cId;
46cdf0e10cSrcweir 		i1 = (cId & 0x70) >> 4;
47cdf0e10cSrcweir 		i2 = cId & 0x07;
48cdf0e10cSrcweir 		rIStream.Read( cAry, i1+i2 );
49cdf0e10cSrcweir 
50cdf0e10cSrcweir 		nNum = 0;
51cdf0e10cSrcweir 		i = i1;
52cdf0e10cSrcweir 		while ( i )
53cdf0e10cSrcweir 		{
54cdf0e10cSrcweir 			i--;
55cdf0e10cSrcweir 			nNum <<= 8;
56cdf0e10cSrcweir 			nNum |= cAry[i];
57cdf0e10cSrcweir 		}
58cdf0e10cSrcweir 		if ( cId & 0x80 )
59cdf0e10cSrcweir 			nNum ^= 0xFFFFFFFF;
60cdf0e10cSrcweir 		rPair.nA = (sal_Int32)nNum;
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 		nNum = 0;
63cdf0e10cSrcweir 		i = i1+i2;
64cdf0e10cSrcweir 		while ( i > i1 )
65cdf0e10cSrcweir 		{
66cdf0e10cSrcweir 			i--;
67cdf0e10cSrcweir 			nNum <<= 8;
68cdf0e10cSrcweir 			nNum |= cAry[i];
69cdf0e10cSrcweir 		}
70cdf0e10cSrcweir 		if ( cId & 0x08 )
71cdf0e10cSrcweir 			nNum ^= 0xFFFFFFFF;
72cdf0e10cSrcweir 		rPair.nB = (sal_Int32)nNum;
73cdf0e10cSrcweir 	}
74cdf0e10cSrcweir 	else
75cdf0e10cSrcweir 	{
76cdf0e10cSrcweir 		rIStream >> rPair.nA >> rPair.nB;
77cdf0e10cSrcweir 	}
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 	return rIStream;
80cdf0e10cSrcweir }
81cdf0e10cSrcweir 
82cdf0e10cSrcweir // -----------------------------------------------------------------------
83cdf0e10cSrcweir 
operator <<(SvStream & rOStream,const Pair & rPair)84cdf0e10cSrcweir SvStream& operator<<( SvStream& rOStream, const Pair& rPair )
85cdf0e10cSrcweir {
86cdf0e10cSrcweir 	DBG_ASSERTWARNING( rOStream.GetVersion(), "Pair::<< - Solar-Version not set on rOStream" );
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 	if ( rOStream.GetCompressMode() == COMPRESSMODE_FULL )
89cdf0e10cSrcweir 	{
90cdf0e10cSrcweir 		unsigned char	cAry[9];
91cdf0e10cSrcweir 		int 			i = 1;
92cdf0e10cSrcweir 		sal_uInt32			nNum;
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 		cAry[0] = 0;
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 		nNum = (sal_uInt32)(sal_Int32)rPair.nA;
97cdf0e10cSrcweir 		if ( rPair.nA < 0 )
98cdf0e10cSrcweir 		{
99cdf0e10cSrcweir 			cAry[0] |= 0x80;
100cdf0e10cSrcweir 			nNum ^= 0xFFFFFFFF;
101cdf0e10cSrcweir 		}
102cdf0e10cSrcweir 		if ( nNum )
103cdf0e10cSrcweir 		{
104cdf0e10cSrcweir 			cAry[i] = (unsigned char)(nNum & 0xFF);
105cdf0e10cSrcweir 			nNum >>= 8;
106cdf0e10cSrcweir 			i++;
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 			if ( nNum )
109cdf0e10cSrcweir 			{
110cdf0e10cSrcweir 				cAry[i] = (unsigned char)(nNum & 0xFF);
111cdf0e10cSrcweir 				nNum >>= 8;
112cdf0e10cSrcweir 				i++;
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 				if ( nNum )
115cdf0e10cSrcweir 				{
116cdf0e10cSrcweir 					cAry[i] = (unsigned char)(nNum & 0xFF);
117cdf0e10cSrcweir 					nNum >>= 8;
118cdf0e10cSrcweir 					i++;
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 					if ( nNum )
121cdf0e10cSrcweir 					{
122cdf0e10cSrcweir 						cAry[i] = (unsigned char)(nNum & 0xFF);
123cdf0e10cSrcweir 						nNum >>= 8;
124cdf0e10cSrcweir 						i++;
125cdf0e10cSrcweir 						cAry[0] |= 0x40;
126cdf0e10cSrcweir 					}
127cdf0e10cSrcweir 					else
128cdf0e10cSrcweir 						cAry[0] |= 0x30;
129cdf0e10cSrcweir 				}
130cdf0e10cSrcweir 				else
131cdf0e10cSrcweir 					cAry[0] |= 0x20;
132cdf0e10cSrcweir 			}
133cdf0e10cSrcweir 			else
134cdf0e10cSrcweir 				cAry[0] |= 0x10;
135cdf0e10cSrcweir 		}
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 		nNum = (sal_uInt32)(sal_Int32)rPair.nB;
138cdf0e10cSrcweir 		if ( rPair.nB < 0 )
139cdf0e10cSrcweir 		{
140cdf0e10cSrcweir 			cAry[0] |= 0x08;
141cdf0e10cSrcweir 			nNum ^= 0xFFFFFFFF;
142cdf0e10cSrcweir 		}
143cdf0e10cSrcweir 		if ( nNum )
144cdf0e10cSrcweir 		{
145cdf0e10cSrcweir 			cAry[i] = (unsigned char)(nNum & 0xFF);
146cdf0e10cSrcweir 			nNum >>= 8;
147cdf0e10cSrcweir 			i++;
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 			if ( nNum )
150cdf0e10cSrcweir 			{
151cdf0e10cSrcweir 				cAry[i] = (unsigned char)(nNum & 0xFF);
152cdf0e10cSrcweir 				nNum >>= 8;
153cdf0e10cSrcweir 				i++;
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 				if ( nNum )
156cdf0e10cSrcweir 				{
157cdf0e10cSrcweir 					cAry[i] = (unsigned char)(nNum & 0xFF);
158cdf0e10cSrcweir 					nNum >>= 8;
159cdf0e10cSrcweir 					i++;
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 					if ( nNum )
162cdf0e10cSrcweir 					{
163cdf0e10cSrcweir 						cAry[i] = (unsigned char)(nNum & 0xFF);
164cdf0e10cSrcweir 						nNum >>= 8;
165cdf0e10cSrcweir 						i++;
166cdf0e10cSrcweir 						cAry[0] |= 0x04;
167cdf0e10cSrcweir 					}
168cdf0e10cSrcweir 					else
169cdf0e10cSrcweir 						cAry[0] |= 0x03;
170cdf0e10cSrcweir 				}
171cdf0e10cSrcweir 				else
172cdf0e10cSrcweir 					cAry[0] |= 0x02;
173cdf0e10cSrcweir 			}
174cdf0e10cSrcweir 			else
175cdf0e10cSrcweir 				cAry[0] |= 0x01;
176cdf0e10cSrcweir 		}
177cdf0e10cSrcweir 
178cdf0e10cSrcweir 		rOStream.Write( cAry, i );
179cdf0e10cSrcweir 	}
180cdf0e10cSrcweir 	else
181cdf0e10cSrcweir 	{
182cdf0e10cSrcweir 		rOStream << rPair.nA << rPair.nB;
183cdf0e10cSrcweir 	}
184cdf0e10cSrcweir 
185cdf0e10cSrcweir 	return rOStream;
186cdf0e10cSrcweir }
187cdf0e10cSrcweir 
188cdf0e10cSrcweir /*************************************************************************
189cdf0e10cSrcweir |*
190cdf0e10cSrcweir |*    Rectangle::SetSize()
191cdf0e10cSrcweir |*
192cdf0e10cSrcweir |*    Beschreibung      GEN.SDW
193cdf0e10cSrcweir |*    Ersterstellung    DV 29.10.91
194cdf0e10cSrcweir |*    Letzte Aenderung  MM 21.04.94
195cdf0e10cSrcweir |*
196cdf0e10cSrcweir *************************************************************************/
197cdf0e10cSrcweir 
SetSize(const Size & rSize)198cdf0e10cSrcweir void Rectangle::SetSize( const Size& rSize )
199cdf0e10cSrcweir {
200cdf0e10cSrcweir     if ( rSize.Width() < 0 )
201cdf0e10cSrcweir         nRight  = nLeft + rSize.Width() +1;
202cdf0e10cSrcweir     else if ( rSize.Width() > 0 )
203cdf0e10cSrcweir         nRight  = nLeft + rSize.Width() -1;
204cdf0e10cSrcweir     else
205cdf0e10cSrcweir         nRight = RECT_EMPTY;
206cdf0e10cSrcweir 
207cdf0e10cSrcweir     if ( rSize.Height() < 0 )
208cdf0e10cSrcweir         nBottom  = nTop + rSize.Height() +1;
209cdf0e10cSrcweir     else if ( rSize.Height() > 0 )
210cdf0e10cSrcweir         nBottom  = nTop + rSize.Height() -1;
211cdf0e10cSrcweir     else
212cdf0e10cSrcweir         nBottom = RECT_EMPTY;
213cdf0e10cSrcweir }
214cdf0e10cSrcweir 
215cdf0e10cSrcweir /*************************************************************************
216cdf0e10cSrcweir |*
217cdf0e10cSrcweir |*    Rectangle::Union()
218cdf0e10cSrcweir |*
219cdf0e10cSrcweir |*    Beschreibung      GEN.SDW
220cdf0e10cSrcweir |*    Ersterstellung    TH 20.10.92
221cdf0e10cSrcweir |*    Letzte Aenderung  MM 21.04.94
222cdf0e10cSrcweir |*
223cdf0e10cSrcweir *************************************************************************/
224cdf0e10cSrcweir 
Union(const Rectangle & rRect)225cdf0e10cSrcweir Rectangle& Rectangle::Union( const Rectangle& rRect )
226cdf0e10cSrcweir {
227cdf0e10cSrcweir     if ( rRect.IsEmpty() )
228cdf0e10cSrcweir         return *this;
229cdf0e10cSrcweir 
230cdf0e10cSrcweir     if ( IsEmpty() )
231cdf0e10cSrcweir         *this = rRect;
232cdf0e10cSrcweir     else
233cdf0e10cSrcweir     {
234cdf0e10cSrcweir         nLeft  =  Min( Min( nLeft, rRect.nLeft ), Min( nRight, rRect.nRight )   );
235cdf0e10cSrcweir         nRight  = Max( Max( nLeft, rRect.nLeft ), Max( nRight, rRect.nRight )   );
236cdf0e10cSrcweir         nTop    = Min( Min( nTop, rRect.nTop ),   Min( nBottom, rRect.nBottom ) );
237cdf0e10cSrcweir         nBottom = Max( Max( nTop, rRect.nTop ),   Max( nBottom, rRect.nBottom ) );
238cdf0e10cSrcweir     }
239cdf0e10cSrcweir 
240cdf0e10cSrcweir     return *this;
241cdf0e10cSrcweir }
242cdf0e10cSrcweir 
243cdf0e10cSrcweir /*************************************************************************
244cdf0e10cSrcweir |*
245cdf0e10cSrcweir |*    Rectangle::Intersection()
246cdf0e10cSrcweir |*
247cdf0e10cSrcweir |*    Beschreibung      GEN.SDW
248cdf0e10cSrcweir |*    Ersterstellung    TH 20.10.92
249cdf0e10cSrcweir |*    Letzte Aenderung  MM 21.04.94
250cdf0e10cSrcweir |*
251cdf0e10cSrcweir *************************************************************************/
252cdf0e10cSrcweir 
Intersection(const Rectangle & rRect)253cdf0e10cSrcweir Rectangle& Rectangle::Intersection( const Rectangle& rRect )
254cdf0e10cSrcweir {
255cdf0e10cSrcweir     if ( IsEmpty() )
256cdf0e10cSrcweir         return *this;
257cdf0e10cSrcweir     if ( rRect.IsEmpty() )
258cdf0e10cSrcweir     {
259cdf0e10cSrcweir         *this = Rectangle();
260cdf0e10cSrcweir         return *this;
261cdf0e10cSrcweir     }
262cdf0e10cSrcweir 
263cdf0e10cSrcweir     // nicht mit umgedrehten Rechtecken arbeiten
264cdf0e10cSrcweir     Rectangle aTmpRect( rRect );
265cdf0e10cSrcweir     Justify();
266cdf0e10cSrcweir     aTmpRect.Justify();
267cdf0e10cSrcweir 
268cdf0e10cSrcweir     // Schnitt bilden
269cdf0e10cSrcweir     nLeft  = Max( nLeft, aTmpRect.nLeft );
270cdf0e10cSrcweir     nRight = Min( nRight, aTmpRect.nRight );
271cdf0e10cSrcweir     nTop   = Max( nTop, aTmpRect.nTop );
272cdf0e10cSrcweir     nBottom= Min( nBottom, aTmpRect.nBottom );
273cdf0e10cSrcweir 
274cdf0e10cSrcweir     // Feststellen ob Schnitt leer
275cdf0e10cSrcweir     if ( nRight < nLeft || nBottom < nTop )
276cdf0e10cSrcweir         *this = Rectangle();
277cdf0e10cSrcweir 
278cdf0e10cSrcweir     return *this;
279cdf0e10cSrcweir }
280cdf0e10cSrcweir 
281cdf0e10cSrcweir /*************************************************************************
282cdf0e10cSrcweir |*
283cdf0e10cSrcweir |*    Rectangle::Justify()
284cdf0e10cSrcweir |*
285cdf0e10cSrcweir |*    Beschreibung      GEN.SDW
286cdf0e10cSrcweir |*    Ersterstellung    DV 07.03.91
287cdf0e10cSrcweir |*    Letzte Aenderung  DV 07.03.91
288cdf0e10cSrcweir |*
289cdf0e10cSrcweir *************************************************************************/
290cdf0e10cSrcweir 
Justify()291cdf0e10cSrcweir void Rectangle::Justify()
292cdf0e10cSrcweir {
293cdf0e10cSrcweir     long nHelp;
294cdf0e10cSrcweir 
295cdf0e10cSrcweir     // Abfrage, ob Right kleiner Left
296cdf0e10cSrcweir     if ( (nRight < nLeft) && (nRight != RECT_EMPTY) )
297cdf0e10cSrcweir     {
298cdf0e10cSrcweir         nHelp = nLeft;
299cdf0e10cSrcweir         nLeft = nRight;
300cdf0e10cSrcweir         nRight = nHelp;
301cdf0e10cSrcweir     }
302cdf0e10cSrcweir 
303cdf0e10cSrcweir     // Abfrage, ob Bottom kleiner Top
304cdf0e10cSrcweir     if ( (nBottom < nTop) && (nBottom != RECT_EMPTY) )
305cdf0e10cSrcweir     {
306cdf0e10cSrcweir         nHelp = nBottom;
307cdf0e10cSrcweir         nBottom = nTop;
308cdf0e10cSrcweir         nTop = nHelp;
309cdf0e10cSrcweir     }
310cdf0e10cSrcweir }
311cdf0e10cSrcweir 
312cdf0e10cSrcweir /*************************************************************************
313cdf0e10cSrcweir |*
314cdf0e10cSrcweir |*    Rectangle::IsInside()
315cdf0e10cSrcweir |*
316cdf0e10cSrcweir |*    Beschreibung      GEN.SDW
317cdf0e10cSrcweir |*    Ersterstellung    TH 19.03.90
318cdf0e10cSrcweir |*    Letzte Aenderung  MM 21.04.94
319cdf0e10cSrcweir |*
320cdf0e10cSrcweir *************************************************************************/
321cdf0e10cSrcweir 
IsInside(const Point & rPoint) const322cdf0e10cSrcweir sal_Bool Rectangle::IsInside( const Point& rPoint ) const
323cdf0e10cSrcweir {
324cdf0e10cSrcweir     if ( IsEmpty() )
325cdf0e10cSrcweir         return sal_False;
326cdf0e10cSrcweir 
327cdf0e10cSrcweir     sal_Bool bRet = sal_True;
328cdf0e10cSrcweir     if ( nLeft <= nRight )
329cdf0e10cSrcweir     {
330cdf0e10cSrcweir         if ( (rPoint.X() < nLeft) || (rPoint.X() > nRight) )
331cdf0e10cSrcweir             bRet = sal_False;
332cdf0e10cSrcweir     }
333cdf0e10cSrcweir     else
334cdf0e10cSrcweir     {
335cdf0e10cSrcweir         if ( (rPoint.X() > nLeft) || (rPoint.X() < nRight) )
336cdf0e10cSrcweir             bRet = sal_False;
337cdf0e10cSrcweir     }
338cdf0e10cSrcweir     if ( nTop <= nBottom )
339cdf0e10cSrcweir     {
340cdf0e10cSrcweir         if ( (rPoint.Y() < nTop) || (rPoint.Y() > nBottom) )
341cdf0e10cSrcweir             bRet = sal_False;
342cdf0e10cSrcweir     }
343cdf0e10cSrcweir     else
344cdf0e10cSrcweir     {
345cdf0e10cSrcweir         if ( (rPoint.Y() > nTop) || (rPoint.Y() < nBottom) )
346cdf0e10cSrcweir             bRet = sal_False;
347cdf0e10cSrcweir     }
348cdf0e10cSrcweir     return bRet;
349cdf0e10cSrcweir }
350cdf0e10cSrcweir 
351cdf0e10cSrcweir /*************************************************************************
352cdf0e10cSrcweir |*
353cdf0e10cSrcweir |*    Rectangle::IsInside()
354cdf0e10cSrcweir |*
355cdf0e10cSrcweir |*    Beschreibung      GEN.SDW
356cdf0e10cSrcweir |*    Ersterstellung    TH 19.03.90
357cdf0e10cSrcweir |*    Letzte Aenderung  MM 21.04.94
358cdf0e10cSrcweir |*
359cdf0e10cSrcweir *************************************************************************/
360cdf0e10cSrcweir 
IsInside(const Rectangle & rRect) const361cdf0e10cSrcweir sal_Bool Rectangle::IsInside( const Rectangle& rRect ) const
362cdf0e10cSrcweir {
363cdf0e10cSrcweir     if ( IsInside( rRect.TopLeft() ) && IsInside( rRect.BottomRight() ) )
364cdf0e10cSrcweir         return sal_True;
365cdf0e10cSrcweir     else
366cdf0e10cSrcweir         return sal_False;
367cdf0e10cSrcweir }
368cdf0e10cSrcweir 
369cdf0e10cSrcweir /*************************************************************************
370cdf0e10cSrcweir |*
371cdf0e10cSrcweir |*    Rectangle::IsOver()
372cdf0e10cSrcweir |*
373cdf0e10cSrcweir |*    Beschreibung      GEN.SDW
374cdf0e10cSrcweir |*    Ersterstellung    TH 19.03.90
375cdf0e10cSrcweir |*    Letzte Aenderung  MM 21.04.94
376cdf0e10cSrcweir |*
377cdf0e10cSrcweir *************************************************************************/
378cdf0e10cSrcweir 
IsOver(const Rectangle & rRect) const379cdf0e10cSrcweir sal_Bool Rectangle::IsOver( const Rectangle& rRect ) const
380cdf0e10cSrcweir {
381cdf0e10cSrcweir     // Wenn sie sich nicht schneiden, ueberlappen sie auch nicht
382cdf0e10cSrcweir     return !GetIntersection( rRect ).IsEmpty();
383cdf0e10cSrcweir }
384cdf0e10cSrcweir 
385cdf0e10cSrcweir // =======================================================================
386cdf0e10cSrcweir 
operator >>(SvStream & rIStream,Rectangle & rRect)387cdf0e10cSrcweir SvStream& operator>>( SvStream& rIStream, Rectangle& rRect )
388cdf0e10cSrcweir {
389cdf0e10cSrcweir 	DBG_ASSERTWARNING( rIStream.GetVersion(), "Rectangle::>> - Solar-Version not set on rIStream" );
390cdf0e10cSrcweir 
391cdf0e10cSrcweir 	if ( rIStream.GetCompressMode() == COMPRESSMODE_FULL )
392cdf0e10cSrcweir 	{
393cdf0e10cSrcweir 		unsigned char	cIdAry[2];
394cdf0e10cSrcweir 		unsigned char	cAry[16];
395cdf0e10cSrcweir 		int 			i;
396cdf0e10cSrcweir 		int 			iLast;
397cdf0e10cSrcweir 		int 			i1;
398cdf0e10cSrcweir 		int 			i2;
399cdf0e10cSrcweir 		int 			i3;
400cdf0e10cSrcweir 		int 			i4;
401cdf0e10cSrcweir 		sal_uInt32			nNum;
402cdf0e10cSrcweir 
403cdf0e10cSrcweir 		rIStream.Read( cIdAry, 2 );
404cdf0e10cSrcweir 		i1 = (cIdAry[0] & 0x70) >> 4;
405cdf0e10cSrcweir 		i2 = cIdAry[0] & 0x07;
406cdf0e10cSrcweir 		i3 = (cIdAry[1] & 0x70) >> 4;
407cdf0e10cSrcweir 		i4 = cIdAry[1] & 0x07;
408cdf0e10cSrcweir 		rIStream.Read( cAry, i1+i2+i3+i4 );
409cdf0e10cSrcweir 
410cdf0e10cSrcweir 		nNum = 0;
411cdf0e10cSrcweir 		i = i1;
412cdf0e10cSrcweir 		iLast = i;
413cdf0e10cSrcweir 		while ( i )
414cdf0e10cSrcweir 		{
415cdf0e10cSrcweir 			i--;
416cdf0e10cSrcweir 			nNum <<= 8;
417cdf0e10cSrcweir 			nNum |= cAry[i];
418cdf0e10cSrcweir 		}
419cdf0e10cSrcweir 		iLast = i1;
420cdf0e10cSrcweir 		if ( cIdAry[0] & 0x80 )
421cdf0e10cSrcweir 			nNum ^= 0xFFFFFFFF;
422cdf0e10cSrcweir 		rRect.nLeft = (sal_Int32)nNum;
423cdf0e10cSrcweir 
424cdf0e10cSrcweir 		nNum = 0;
425cdf0e10cSrcweir 		i = iLast+i2;
426cdf0e10cSrcweir 		while ( i > iLast )
427cdf0e10cSrcweir 		{
428cdf0e10cSrcweir 			i--;
429cdf0e10cSrcweir 			nNum <<= 8;
430cdf0e10cSrcweir 			nNum |= cAry[i];
431cdf0e10cSrcweir 		}
432cdf0e10cSrcweir 		iLast += i2;
433cdf0e10cSrcweir 		if ( cIdAry[0] & 0x08 )
434cdf0e10cSrcweir 			nNum ^= 0xFFFFFFFF;
435cdf0e10cSrcweir 		rRect.nTop = (sal_Int32)nNum;
436cdf0e10cSrcweir 
437cdf0e10cSrcweir 		nNum = 0;
438cdf0e10cSrcweir 		i = iLast+i3;
439cdf0e10cSrcweir 		while ( i > iLast )
440cdf0e10cSrcweir 		{
441cdf0e10cSrcweir 			i--;
442cdf0e10cSrcweir 			nNum <<= 8;
443cdf0e10cSrcweir 			nNum |= cAry[i];
444cdf0e10cSrcweir 		}
445cdf0e10cSrcweir 		iLast += i3;
446cdf0e10cSrcweir 		if ( cIdAry[1] & 0x80 )
447cdf0e10cSrcweir 			nNum ^= 0xFFFFFFFF;
448cdf0e10cSrcweir 		rRect.nRight = (sal_Int32)nNum;
449cdf0e10cSrcweir 
450cdf0e10cSrcweir 		nNum = 0;
451cdf0e10cSrcweir 		i = iLast+i4;
452cdf0e10cSrcweir 		while ( i > iLast )
453cdf0e10cSrcweir 		{
454cdf0e10cSrcweir 			i--;
455cdf0e10cSrcweir 			nNum <<= 8;
456cdf0e10cSrcweir 			nNum |= cAry[i];
457cdf0e10cSrcweir 		}
458cdf0e10cSrcweir 		if ( cIdAry[1] & 0x08 )
459cdf0e10cSrcweir 			nNum ^= 0xFFFFFFFF;
460cdf0e10cSrcweir 		rRect.nBottom = (sal_Int32)nNum;
461cdf0e10cSrcweir 	}
462cdf0e10cSrcweir 	else
463cdf0e10cSrcweir 	{
464cdf0e10cSrcweir 		rIStream >> rRect.nLeft >> rRect.nTop >> rRect.nRight >> rRect.nBottom;
465cdf0e10cSrcweir 	}
466cdf0e10cSrcweir 
467cdf0e10cSrcweir 	return rIStream;
468cdf0e10cSrcweir }
469cdf0e10cSrcweir 
470cdf0e10cSrcweir // -----------------------------------------------------------------------
471cdf0e10cSrcweir 
operator <<(SvStream & rOStream,const Rectangle & rRect)472cdf0e10cSrcweir SvStream& operator<<( SvStream& rOStream, const Rectangle& rRect )
473cdf0e10cSrcweir {
474cdf0e10cSrcweir 	DBG_ASSERTWARNING( rOStream.GetVersion(), "Rectangle::<< - Solar-Version not set on rOStream" );
475cdf0e10cSrcweir 
476cdf0e10cSrcweir 	if ( rOStream.GetCompressMode() == COMPRESSMODE_FULL )
477cdf0e10cSrcweir 	{
478cdf0e10cSrcweir 		unsigned char	cAry[18];
479cdf0e10cSrcweir 		int 			i = 2;
480cdf0e10cSrcweir 		sal_uInt32			nNum;
481cdf0e10cSrcweir 
482cdf0e10cSrcweir 		cAry[0] = 0;
483cdf0e10cSrcweir 		cAry[1] = 0;
484cdf0e10cSrcweir 
485cdf0e10cSrcweir 		nNum = (sal_uInt32)(sal_Int32)rRect.nLeft;
486cdf0e10cSrcweir 		if ( rRect.nLeft < 0 )
487cdf0e10cSrcweir 		{
488cdf0e10cSrcweir 			cAry[0] |= 0x80;
489cdf0e10cSrcweir 			nNum ^= 0xFFFFFFFF;
490cdf0e10cSrcweir 		}
491cdf0e10cSrcweir 		if ( nNum )
492cdf0e10cSrcweir 		{
493cdf0e10cSrcweir 			cAry[i] = (unsigned char)(nNum & 0xFF);
494cdf0e10cSrcweir 			nNum >>= 8;
495cdf0e10cSrcweir 			i++;
496cdf0e10cSrcweir 
497cdf0e10cSrcweir 			if ( nNum )
498cdf0e10cSrcweir 			{
499cdf0e10cSrcweir 				cAry[i] = (unsigned char)(nNum & 0xFF);
500cdf0e10cSrcweir 				nNum >>= 8;
501cdf0e10cSrcweir 				i++;
502cdf0e10cSrcweir 
503cdf0e10cSrcweir 				if ( nNum )
504cdf0e10cSrcweir 				{
505cdf0e10cSrcweir 					cAry[i] = (unsigned char)(nNum & 0xFF);
506cdf0e10cSrcweir 					nNum >>= 8;
507cdf0e10cSrcweir 					i++;
508cdf0e10cSrcweir 
509cdf0e10cSrcweir 					if ( nNum )
510cdf0e10cSrcweir 					{
511cdf0e10cSrcweir 						cAry[i] = (unsigned char)(nNum & 0xFF);
512cdf0e10cSrcweir 						nNum >>= 8;
513cdf0e10cSrcweir 						i++;
514cdf0e10cSrcweir 						cAry[0] |= 0x40;
515cdf0e10cSrcweir 					}
516cdf0e10cSrcweir 					else
517cdf0e10cSrcweir 						cAry[0] |= 0x30;
518cdf0e10cSrcweir 				}
519cdf0e10cSrcweir 				else
520cdf0e10cSrcweir 					cAry[0] |= 0x20;
521cdf0e10cSrcweir 			}
522cdf0e10cSrcweir 			else
523cdf0e10cSrcweir 				cAry[0] |= 0x10;
524cdf0e10cSrcweir 		}
525cdf0e10cSrcweir 
526cdf0e10cSrcweir 		nNum = (sal_uInt32)(sal_Int32)rRect.nTop;
527cdf0e10cSrcweir 		if ( rRect.nTop < 0 )
528cdf0e10cSrcweir 		{
529cdf0e10cSrcweir 			cAry[0] |= 0x08;
530cdf0e10cSrcweir 			nNum ^= 0xFFFFFFFF;
531cdf0e10cSrcweir 		}
532cdf0e10cSrcweir 		if ( nNum )
533cdf0e10cSrcweir 		{
534cdf0e10cSrcweir 			cAry[i] = (unsigned char)(nNum & 0xFF);
535cdf0e10cSrcweir 			nNum >>= 8;
536cdf0e10cSrcweir 			i++;
537cdf0e10cSrcweir 
538cdf0e10cSrcweir 			if ( nNum )
539cdf0e10cSrcweir 			{
540cdf0e10cSrcweir 				cAry[i] = (unsigned char)(nNum & 0xFF);
541cdf0e10cSrcweir 				nNum >>= 8;
542cdf0e10cSrcweir 				i++;
543cdf0e10cSrcweir 
544cdf0e10cSrcweir 				if ( nNum )
545cdf0e10cSrcweir 				{
546cdf0e10cSrcweir 					cAry[i] = (unsigned char)(nNum & 0xFF);
547cdf0e10cSrcweir 					nNum >>= 8;
548cdf0e10cSrcweir 					i++;
549cdf0e10cSrcweir 
550cdf0e10cSrcweir 					if ( nNum )
551cdf0e10cSrcweir 					{
552cdf0e10cSrcweir 						cAry[i] = (unsigned char)(nNum & 0xFF);
553cdf0e10cSrcweir 						nNum >>= 8;
554cdf0e10cSrcweir 						i++;
555cdf0e10cSrcweir 						cAry[0] |= 0x04;
556cdf0e10cSrcweir 					}
557cdf0e10cSrcweir 					else
558cdf0e10cSrcweir 						cAry[0] |= 0x03;
559cdf0e10cSrcweir 				}
560cdf0e10cSrcweir 				else
561cdf0e10cSrcweir 					cAry[0] |= 0x02;
562cdf0e10cSrcweir 			}
563cdf0e10cSrcweir 			else
564cdf0e10cSrcweir 				cAry[0] |= 0x01;
565cdf0e10cSrcweir 		}
566cdf0e10cSrcweir 
567cdf0e10cSrcweir 		nNum = (sal_uInt32)(sal_Int32)rRect.nRight;
568cdf0e10cSrcweir 		if ( rRect.nRight < 0 )
569cdf0e10cSrcweir 		{
570cdf0e10cSrcweir 			cAry[1] |= 0x80;
571cdf0e10cSrcweir 			nNum ^= 0xFFFFFFFF;
572cdf0e10cSrcweir 		}
573cdf0e10cSrcweir 		if ( nNum )
574cdf0e10cSrcweir 		{
575cdf0e10cSrcweir 			cAry[i] = (unsigned char)(nNum & 0xFF);
576cdf0e10cSrcweir 			nNum >>= 8;
577cdf0e10cSrcweir 			i++;
578cdf0e10cSrcweir 
579cdf0e10cSrcweir 			if ( nNum )
580cdf0e10cSrcweir 			{
581cdf0e10cSrcweir 				cAry[i] = (unsigned char)(nNum & 0xFF);
582cdf0e10cSrcweir 				nNum >>= 8;
583cdf0e10cSrcweir 				i++;
584cdf0e10cSrcweir 
585cdf0e10cSrcweir 				if ( nNum )
586cdf0e10cSrcweir 				{
587cdf0e10cSrcweir 					cAry[i] = (unsigned char)(nNum & 0xFF);
588cdf0e10cSrcweir 					nNum >>= 8;
589cdf0e10cSrcweir 					i++;
590cdf0e10cSrcweir 
591cdf0e10cSrcweir 					if ( nNum )
592cdf0e10cSrcweir 					{
593cdf0e10cSrcweir 						cAry[i] = (unsigned char)(nNum & 0xFF);
594cdf0e10cSrcweir 						nNum >>= 8;
595cdf0e10cSrcweir 						i++;
596cdf0e10cSrcweir 						cAry[1] |= 0x40;
597cdf0e10cSrcweir 					}
598cdf0e10cSrcweir 					else
599cdf0e10cSrcweir 						cAry[1] |= 0x30;
600cdf0e10cSrcweir 				}
601cdf0e10cSrcweir 				else
602cdf0e10cSrcweir 					cAry[1] |= 0x20;
603cdf0e10cSrcweir 			}
604cdf0e10cSrcweir 			else
605cdf0e10cSrcweir 				cAry[1] |= 0x10;
606cdf0e10cSrcweir 		}
607cdf0e10cSrcweir 
608cdf0e10cSrcweir 		nNum = (sal_uInt32)(sal_Int32)rRect.nBottom;
609cdf0e10cSrcweir 		if ( rRect.nBottom < 0 )
610cdf0e10cSrcweir 		{
611cdf0e10cSrcweir 			cAry[1] |= 0x08;
612cdf0e10cSrcweir 			nNum ^= 0xFFFFFFFF;
613cdf0e10cSrcweir 		}
614cdf0e10cSrcweir 		if ( nNum )
615cdf0e10cSrcweir 		{
616cdf0e10cSrcweir 			cAry[i] = (unsigned char)(nNum & 0xFF);
617cdf0e10cSrcweir 			nNum >>= 8;
618cdf0e10cSrcweir 			i++;
619cdf0e10cSrcweir 
620cdf0e10cSrcweir 			if ( nNum )
621cdf0e10cSrcweir 			{
622cdf0e10cSrcweir 				cAry[i] = (unsigned char)(nNum & 0xFF);
623cdf0e10cSrcweir 				nNum >>= 8;
624cdf0e10cSrcweir 				i++;
625cdf0e10cSrcweir 
626cdf0e10cSrcweir 				if ( nNum )
627cdf0e10cSrcweir 				{
628cdf0e10cSrcweir 					cAry[i] = (unsigned char)(nNum & 0xFF);
629cdf0e10cSrcweir 					nNum >>= 8;
630cdf0e10cSrcweir 					i++;
631cdf0e10cSrcweir 
632cdf0e10cSrcweir 					if ( nNum )
633cdf0e10cSrcweir 					{
634cdf0e10cSrcweir 						cAry[i] = (unsigned char)(nNum & 0xFF);
635cdf0e10cSrcweir 						nNum >>= 8;
636cdf0e10cSrcweir 						i++;
637cdf0e10cSrcweir 						cAry[1] |= 0x04;
638cdf0e10cSrcweir 					}
639cdf0e10cSrcweir 					else
640cdf0e10cSrcweir 						cAry[1] |= 0x03;
641cdf0e10cSrcweir 				}
642cdf0e10cSrcweir 				else
643cdf0e10cSrcweir 					cAry[1] |= 0x02;
644cdf0e10cSrcweir 			}
645cdf0e10cSrcweir 			else
646cdf0e10cSrcweir 				cAry[1] |= 0x01;
647cdf0e10cSrcweir 		}
648cdf0e10cSrcweir 
649cdf0e10cSrcweir 		rOStream.Write( cAry, i );
650cdf0e10cSrcweir 	}
651cdf0e10cSrcweir 	else
652cdf0e10cSrcweir 	{
653cdf0e10cSrcweir 		rOStream << rRect.nLeft << rRect.nTop << rRect.nRight << rRect.nBottom;
654cdf0e10cSrcweir 	}
655cdf0e10cSrcweir 
656cdf0e10cSrcweir 	return rOStream;
657cdf0e10cSrcweir }
658