xref: /aoo42x/main/vcl/source/gdi/graph.cxx (revision 9f62ea84)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_vcl.hxx"
26 
27 #include <vcl/outdev.hxx>
28 #include <vcl/svapp.hxx>
29 #include <vcl/graph.hxx>
30 
31 #include <impgraph.hxx>
32 
33 #include <comphelper/processfactory.hxx>
34 
35 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
36 #include <com/sun/star/graphic/XGraphicProvider.hpp>
37 #include <com/sun/star/lang/XUnoTunnel.hpp>
38 #include <com/sun/star/lang/XTypeProvider.hpp>
39 #include <com/sun/star/graphic/XGraphic.hpp>
40 
41 // -----------------------
42 // - Compression defines -
43 // -----------------------
44 
45 #define COMPRESS_OWN                ('S'|('D'<<8UL))
46 #define COMPRESS_NONE               ( 0UL )
47 #define RLE_8                       ( 1UL )
48 #define RLE_4                       ( 2UL )
49 #define BITFIELDS                   ( 3UL )
50 #define ZCOMPRESS                   ( COMPRESS_OWN | 0x01000000UL ) /* == 'SD01' (binary) */
51 
52 using namespace ::com::sun::star;
53 
54 // -----------------------
55 // - Default-Drawmethode -
56 // -----------------------
57 
58 static void ImplDrawDefault( OutputDevice* pOutDev, const UniString* pText,
59                              Font* pFont, const Bitmap* pBitmap, const BitmapEx* pBitmapEx,
60                              const Point& rDestPt, const Size& rDestSize )
61 {
62     sal_uInt16      nPixel = (sal_uInt16) pOutDev->PixelToLogic( Size( 1, 1 ) ).Width();
63     sal_uInt16      nPixelWidth = nPixel;
64     Point       aPoint( rDestPt.X() + nPixelWidth, rDestPt.Y() + nPixelWidth );
65     Size        aSize( rDestSize.Width() - ( nPixelWidth << 1 ), rDestSize.Height() - ( nPixelWidth << 1 ) );
66     sal_Bool        bFilled = ( pBitmap != NULL || pBitmapEx != NULL || pFont != NULL );
67     Rectangle   aBorderRect( aPoint, aSize );
68 
69     pOutDev->Push();
70 
71     pOutDev->SetFillColor();
72 
73     // Auf dem Drucker ein schwarzes Rechteck und auf dem Bildschirm eins mit 3D-Effekt
74     if ( pOutDev->GetOutDevType() == OUTDEV_PRINTER )
75         pOutDev->SetLineColor( COL_BLACK );
76     else
77     {
78         aBorderRect.Left() += nPixel;
79         aBorderRect.Top() += nPixel;
80 
81         pOutDev->SetLineColor( COL_LIGHTGRAY );
82         pOutDev->DrawRect( aBorderRect );
83 
84         aBorderRect.Left() -= nPixel;
85         aBorderRect.Top() -= nPixel;
86         aBorderRect.Right() -= nPixel;
87         aBorderRect.Bottom() -= nPixel;
88         pOutDev->SetLineColor( COL_GRAY );
89     }
90 
91     pOutDev->DrawRect( aBorderRect );
92 
93     aPoint.X() += nPixelWidth + 2*nPixel;
94     aPoint.Y() += nPixelWidth + 2*nPixel;
95     aSize.Width() -= 2*nPixelWidth + 4*nPixel;
96     aSize.Height() -= 2*nPixelWidth + 4*nPixel;
97 
98     if( aSize.Width() > 0 && aSize.Height() > 0
99         && (  ( pBitmap && !!*pBitmap ) || ( pBitmapEx && !!*pBitmapEx ) ) )
100     {
101         Size aBitmapSize( pOutDev->PixelToLogic( pBitmap ? pBitmap->GetSizePixel() : pBitmapEx->GetSizePixel() ) );
102 
103         if( aSize.Height() > aBitmapSize.Height() && aSize.Width() > aBitmapSize.Width() )
104         {
105             if ( pBitmap )
106                 pOutDev->DrawBitmap( aPoint, *pBitmap );
107             else
108                 pOutDev->DrawBitmapEx( aPoint, *pBitmapEx );
109             aPoint.X() += aBitmapSize.Width() + 2*nPixel;
110             aSize.Width() -= aBitmapSize.Width() + 2*nPixel;
111         }
112     }
113 
114     if ( aSize.Width() > 0 && aSize.Height() > 0 && pFont && pText && pText->Len()
115          && !(!pOutDev->IsOutputEnabled() /*&& pOutDev->GetConnectMetaFile() */) )
116     {
117         MapMode aMapMode( MAP_POINT );
118         Size    aSz = pOutDev->LogicToLogic( Size( 0, 12 ), &aMapMode, NULL );
119         long    nThreshold = aSz.Height() / 2;
120         long    nStep = nThreshold / 3;
121 
122         if ( !nStep )
123             nStep = aSz.Height() - nThreshold;
124 
125         for(;; aSz.Height() -= nStep )
126         {
127             pFont->SetSize( aSz );
128             pOutDev->SetFont( *pFont );
129 
130             long nTextHeight = pOutDev->GetTextHeight();
131             long nTextWidth = pOutDev->GetTextWidth( *pText );
132             if ( nTextHeight )
133             {
134                 // Die N"aherung ber"ucksichtigt keine Ungenauigkeiten durch
135                 // Wortumbr"uche
136                 long nLines = aSize.Height() / nTextHeight;
137                 long nWidth = aSize.Width() * nLines; // N"aherung!!!
138 
139                 if ( nTextWidth <= nWidth || aSz.Height() <= nThreshold )
140                 {
141                     sal_uInt16 nStart = 0;
142                     sal_uInt16 nLen = 0;
143 
144                     while( nStart < pText->Len() && pText->GetChar( nStart ) == ' ' )
145                         nStart++;
146                     while( nStart+nLen < pText->Len() && pText->GetChar( nStart+nLen ) != ' ' )
147                         nLen++;
148                     while( nStart < pText->Len() && nLines-- )
149                     {
150                         sal_uInt16 nNext = nLen;
151                         do
152                         {
153                             while ( nStart+nNext < pText->Len() && pText->GetChar( nStart+nNext ) == ' ' )
154                                 nNext++;
155                             while ( nStart+nNext < pText->Len() && pText->GetChar( nStart+nNext ) != ' ' )
156                                 nNext++;
157                             nTextWidth = pOutDev->GetTextWidth( *pText, nStart, nNext );
158                             if ( nTextWidth > aSize.Width() )
159                                 break;
160                             nLen = nNext;
161                         }
162                         while ( nStart+nNext < pText->Len() );
163 
164                         sal_uInt16 n = nLen;
165                         nTextWidth = pOutDev->GetTextWidth( *pText, nStart, n );
166                         while( nTextWidth > aSize.Width() )
167                             nTextWidth = pOutDev->GetTextWidth( *pText, nStart, --n );
168                         pOutDev->DrawText( aPoint, *pText, nStart, n );
169 
170                         aPoint.Y() += nTextHeight;
171                         nStart      = sal::static_int_cast<sal_uInt16>(nStart + nLen);
172                         nLen        = nNext-nLen;
173                         while( nStart < pText->Len() && pText->GetChar( nStart ) == ' ' )
174                         {
175                             nStart++;
176                             nLen--;
177                         }
178                     }
179                     break;
180                 }
181             }
182             else
183                 break;
184         }
185     }
186 
187     // Falls die Default-Graphik keinen Inhalt hat,
188     // malen wir ein rotes Kreuz
189     if( !bFilled )
190     {
191         aBorderRect.Left()++;
192         aBorderRect.Top()++;
193         aBorderRect.Right()--;
194         aBorderRect.Bottom()--;
195 
196         pOutDev->SetLineColor( COL_LIGHTRED );
197         pOutDev->DrawLine( aBorderRect.TopLeft(), aBorderRect.BottomRight() );
198         pOutDev->DrawLine( aBorderRect.TopRight(), aBorderRect.BottomLeft() );
199     }
200 
201     pOutDev->Pop();
202 }
203 
204 // -----------
205 // - Graphic -
206 // -----------
207 
208 TYPEINIT1_AUTOFACTORY( Graphic, SvDataCopyStream );
209 
210 // ------------------------------------------------------------------------
211 
212 Graphic::Graphic()
213 {
214     mpImpGraphic = new ImpGraphic;
215 }
216 
217 // ------------------------------------------------------------------------
218 
219 Graphic::Graphic( const Graphic& rGraphic ) :
220 SvDataCopyStream()
221 {
222     if( rGraphic.IsAnimated() )
223         mpImpGraphic = new ImpGraphic( *rGraphic.mpImpGraphic );
224     else
225     {
226         mpImpGraphic = rGraphic.mpImpGraphic;
227         mpImpGraphic->mnRefCount++;
228     }
229 }
230 
231 // ------------------------------------------------------------------------
232 
233 Graphic::Graphic( const Bitmap& rBmp )
234 {
235     mpImpGraphic = new ImpGraphic( rBmp );
236 }
237 
238 // ------------------------------------------------------------------------
239 
240 Graphic::Graphic( const BitmapEx& rBmpEx )
241 {
242     mpImpGraphic = new ImpGraphic( rBmpEx );
243 }
244 
245 // ------------------------------------------------------------------------
246 
247 Graphic::Graphic( const Animation& rAnimation )
248 {
249     mpImpGraphic = new ImpGraphic( rAnimation );
250 }
251 
252 // ------------------------------------------------------------------------
253 
254 Graphic::Graphic( const GDIMetaFile& rMtf )
255 {
256     mpImpGraphic = new ImpGraphic( rMtf );
257 }
258 
259 // ------------------------------------------------------------------------
260 
261 Graphic::Graphic( const ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic >& rxGraphic )
262 {
263 	uno::Reference< lang::XUnoTunnel >		xTunnel( rxGraphic, uno::UNO_QUERY );
264 	uno::Reference< lang::XTypeProvider	>	xProv( rxGraphic, uno::UNO_QUERY );
265 	const ::Graphic* 						pGraphic = ( ( xTunnel.is() && xProv.is() ) ?
266 														 reinterpret_cast< ::Graphic* >( xTunnel->getSomething( xProv->getImplementationId() ) ) :
267 													 	 NULL );
268 
269 	if( pGraphic )
270 	{
271 		if( pGraphic->IsAnimated() )
272 			mpImpGraphic = new ImpGraphic( *pGraphic->mpImpGraphic );
273 		else
274 		{
275 			mpImpGraphic = pGraphic->mpImpGraphic;
276 			mpImpGraphic->mnRefCount++;
277 		}
278 	}
279 	else
280 		mpImpGraphic = new ImpGraphic;
281 }
282 
283 // ------------------------------------------------------------------------
284 
285 Graphic::~Graphic()
286 {
287     if( mpImpGraphic->mnRefCount == 1UL )
288         delete mpImpGraphic;
289     else
290         mpImpGraphic->mnRefCount--;
291 }
292 
293 // ------------------------------------------------------------------------
294 
295 void Graphic::ImplTestRefCount()
296 {
297     if( mpImpGraphic->mnRefCount > 1UL )
298     {
299         mpImpGraphic->mnRefCount--;
300         mpImpGraphic = new ImpGraphic( *mpImpGraphic );
301     }
302 }
303 
304 // ------------------------------------------------------------------------
305 
306 Graphic& Graphic::operator=( const Graphic& rGraphic )
307 {
308     if( &rGraphic != this )
309     {
310         if( rGraphic.IsAnimated() )
311         {
312             if( mpImpGraphic->mnRefCount == 1UL )
313                 delete mpImpGraphic;
314             else
315                 mpImpGraphic->mnRefCount--;
316 
317             mpImpGraphic = new ImpGraphic( *rGraphic.mpImpGraphic );
318         }
319         else
320         {
321             rGraphic.mpImpGraphic->mnRefCount++;
322 
323             if( mpImpGraphic->mnRefCount == 1UL )
324                 delete mpImpGraphic;
325             else
326                 mpImpGraphic->mnRefCount--;
327 
328             mpImpGraphic = rGraphic.mpImpGraphic;
329         }
330     }
331 
332     return *this;
333 }
334 
335 // ------------------------------------------------------------------------
336 
337 sal_Bool Graphic::operator==( const Graphic& rGraphic ) const
338 {
339     return( *mpImpGraphic == *rGraphic.mpImpGraphic );
340 }
341 
342 // ------------------------------------------------------------------------
343 
344 sal_Bool Graphic::operator!=( const Graphic& rGraphic ) const
345 {
346     return( *mpImpGraphic != *rGraphic.mpImpGraphic );
347 }
348 
349 // ------------------------------------------------------------------------
350 
351 sal_Bool Graphic::operator!() const
352 {
353     return( GRAPHIC_NONE == mpImpGraphic->ImplGetType() );
354 }
355 
356 // ------------------------------------------------------------------------
357 
358 void Graphic::Load( SvStream& rIStm )
359 {
360     rIStm >> *this;
361 }
362 
363 // ------------------------------------------------------------------------
364 
365 void Graphic::Save( SvStream& rOStm )
366 {
367     rOStm << *this;
368 }
369 
370 // ------------------------------------------------------------------------
371 
372 void Graphic::Assign( const SvDataCopyStream& rCopyStream )
373 {
374     *this = (const Graphic& ) rCopyStream;
375 }
376 
377 // ------------------------------------------------------------------------
378 
379 void Graphic::Clear()
380 {
381     ImplTestRefCount();
382     mpImpGraphic->ImplClear();
383 }
384 
385 // ------------------------------------------------------------------------
386 
387 GraphicType Graphic::GetType() const
388 {
389     return mpImpGraphic->ImplGetType();
390 }
391 
392 // ------------------------------------------------------------------------
393 
394 void Graphic::SetDefaultType()
395 {
396     ImplTestRefCount();
397     mpImpGraphic->ImplSetDefaultType();
398 }
399 
400 // ------------------------------------------------------------------------
401 
402 sal_Bool Graphic::IsSupportedGraphic() const
403 {
404     return mpImpGraphic->ImplIsSupportedGraphic();
405 }
406 
407 // ------------------------------------------------------------------------
408 
409 sal_Bool Graphic::IsTransparent() const
410 {
411     return mpImpGraphic->ImplIsTransparent();
412 }
413 
414 // ------------------------------------------------------------------------
415 
416 sal_Bool Graphic::IsAlpha() const
417 {
418     return mpImpGraphic->ImplIsAlpha();
419 }
420 
421 // ------------------------------------------------------------------------
422 
423 sal_Bool Graphic::IsAnimated() const
424 {
425     return mpImpGraphic->ImplIsAnimated();
426 }
427 
428 // ------------------------------------------------------------------------
429 
430 sal_Bool Graphic::IsEPS() const
431 {
432     return mpImpGraphic->ImplIsEPS();
433 }
434 
435 // ------------------------------------------------------------------------
436 
437 sal_Bool Graphic::IsRenderGraphic() const
438 {
439     return mpImpGraphic->ImplIsRenderGraphic();
440 }
441 
442 // ------------------------------------------------------------------------
443 
444 sal_Bool Graphic::HasRenderGraphic() const
445 {
446     return mpImpGraphic->ImplHasRenderGraphic();
447 }
448 
449 // ------------------------------------------------------------------------
450 
451 Bitmap Graphic::GetBitmap(const GraphicConversionParameters& rParameters) const
452 {
453     return mpImpGraphic->ImplGetBitmap(rParameters);
454 }
455 
456 // ------------------------------------------------------------------------
457 
458 BitmapEx Graphic::GetBitmapEx(const GraphicConversionParameters& rParameters) const
459 {
460     return mpImpGraphic->ImplGetBitmapEx(rParameters);
461 }
462 
463 // ------------------------------------------------------------------------
464 
465 Animation Graphic::GetAnimation() const
466 {
467     return mpImpGraphic->ImplGetAnimation();
468 }
469 
470 // ------------------------------------------------------------------------
471 
472 const GDIMetaFile& Graphic::GetGDIMetaFile() const
473 {
474     return mpImpGraphic->ImplGetGDIMetaFile();
475 }
476 
477 // ------------------------------------------------------------------------
478 
479 ::vcl::RenderGraphic Graphic::GetRenderGraphic() const
480 {
481     return mpImpGraphic->ImplGetRenderGraphic();
482 }
483 
484 // ------------------------------------------------------------------------
485 
486 uno::Reference< graphic::XGraphic > Graphic::GetXGraphic() const
487 {
488 	uno::Reference< graphic::XGraphic > xRet;
489 
490 	if( GetType() != GRAPHIC_NONE )
491 	{
492 		uno::Reference < lang::XMultiServiceFactory > xMSF( ::comphelper::getProcessServiceFactory() );
493 
494 		if( xMSF.is() )
495 		{
496 			uno::Reference< graphic::XGraphicProvider > xProv( xMSF->createInstance(
497 				::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.graphic.GraphicProvider" ) ) ),
498 				uno::UNO_QUERY );
499 
500 			if( xProv.is() )
501 			{
502 				uno::Sequence< beans::PropertyValue > 	aLoadProps( 1 );
503 				::rtl::OUString							aURL( RTL_CONSTASCII_USTRINGPARAM( "private:memorygraphic/" ) );
504 
505 				aLoadProps[ 0 ].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) );
506 				aLoadProps[ 0 ].Value <<= ( aURL += ::rtl::OUString::valueOf( reinterpret_cast< sal_Int64 >( this ) ) );
507 
508 				xRet = xProv->queryGraphic( aLoadProps );
509 			}
510 		}
511 	}
512 
513 	return xRet;
514 }
515 
516 // ------------------------------------------------------------------------
517 
518 Size Graphic::GetPrefSize() const
519 {
520     return mpImpGraphic->ImplGetPrefSize();
521 }
522 
523 // ------------------------------------------------------------------------
524 
525 void Graphic::SetPrefSize( const Size& rPrefSize )
526 {
527     ImplTestRefCount();
528     mpImpGraphic->ImplSetPrefSize( rPrefSize );
529 }
530 
531 // ------------------------------------------------------------------------
532 
533 MapMode Graphic::GetPrefMapMode() const
534 {
535     return mpImpGraphic->ImplGetPrefMapMode();
536 }
537 
538 // ------------------------------------------------------------------------
539 
540 void Graphic::SetPrefMapMode( const MapMode& rPrefMapMode )
541 {
542     ImplTestRefCount();
543     mpImpGraphic->ImplSetPrefMapMode( rPrefMapMode );
544 }
545 
546 // ------------------------------------------------------------------
547 
548 Size Graphic::GetSizePixel( const OutputDevice* pRefDevice ) const
549 {
550     Size aRet;
551 
552     if( GRAPHIC_BITMAP == mpImpGraphic->ImplGetType() )
553         aRet = mpImpGraphic->ImplGetBitmapEx(GraphicConversionParameters()).GetSizePixel();
554     else
555         aRet = ( pRefDevice ? pRefDevice : Application::GetDefaultDevice() )->LogicToPixel( GetPrefSize(), GetPrefMapMode() );
556 
557     return aRet;
558 }
559 
560 // ------------------------------------------------------------------
561 
562 sal_uLong Graphic::GetSizeBytes() const
563 {
564     return mpImpGraphic->ImplGetSizeBytes();
565 }
566 
567 // ------------------------------------------------------------------------
568 
569 void Graphic::Draw( OutputDevice* pOutDev, const Point& rDestPt ) const
570 {
571     mpImpGraphic->ImplDraw( pOutDev, rDestPt );
572 }
573 
574 // ------------------------------------------------------------------------
575 
576 void Graphic::Draw( OutputDevice* pOutDev,
577                     const Point& rDestPt, const Size& rDestSz ) const
578 {
579     if( GRAPHIC_DEFAULT == mpImpGraphic->ImplGetType() )
580         ImplDrawDefault( pOutDev, NULL, NULL, NULL, NULL, rDestPt, rDestSz );
581     else
582         mpImpGraphic->ImplDraw( pOutDev, rDestPt, rDestSz );
583 }
584 
585 // ------------------------------------------------------------------------
586 
587 void Graphic::Draw( OutputDevice* pOutDev, const String& rText,
588                     Font& rFont, const Bitmap& rBitmap,
589                     const Point& rDestPt, const Size& rDestSz )
590 {
591     ImplDrawDefault( pOutDev, &rText, &rFont, &rBitmap, NULL, rDestPt, rDestSz );
592 }
593 
594 // ------------------------------------------------------------------------
595 
596 void Graphic::DrawEx( OutputDevice* pOutDev, const String& rText,
597                     Font& rFont, const BitmapEx& rBitmap,
598                     const Point& rDestPt, const Size& rDestSz )
599 {
600     ImplDrawDefault( pOutDev, &rText, &rFont, NULL, &rBitmap, rDestPt, rDestSz );
601 }
602 
603 // ------------------------------------------------------------------------
604 
605 void Graphic::StartAnimation( OutputDevice* pOutDev, const Point& rDestPt, long nExtraData,
606                               OutputDevice* pFirstFrameOutDev )
607 {
608     ImplTestRefCount();
609     mpImpGraphic->ImplStartAnimation( pOutDev, rDestPt, nExtraData, pFirstFrameOutDev );
610 }
611 
612 // ------------------------------------------------------------------------
613 
614 void Graphic::StartAnimation( OutputDevice* pOutDev, const Point& rDestPt,
615                               const Size& rDestSz, long nExtraData,
616                               OutputDevice* pFirstFrameOutDev )
617 {
618     ImplTestRefCount();
619     mpImpGraphic->ImplStartAnimation( pOutDev, rDestPt, rDestSz, nExtraData, pFirstFrameOutDev );
620 }
621 
622 // ------------------------------------------------------------------------
623 
624 void Graphic::StopAnimation( OutputDevice* pOutDev, long nExtraData )
625 {
626     ImplTestRefCount();
627     mpImpGraphic->ImplStopAnimation( pOutDev, nExtraData );
628 }
629 
630 // ------------------------------------------------------------------------
631 
632 void Graphic::SetAnimationNotifyHdl( const Link& rLink )
633 {
634     mpImpGraphic->ImplSetAnimationNotifyHdl( rLink );
635 }
636 
637 // ------------------------------------------------------------------------
638 
639 Link Graphic::GetAnimationNotifyHdl() const
640 {
641     return mpImpGraphic->ImplGetAnimationNotifyHdl();
642 }
643 
644 // ------------------------------------------------------------------------
645 
646 sal_uLong Graphic::GetAnimationLoopCount() const
647 {
648     return mpImpGraphic->ImplGetAnimationLoopCount();
649 }
650 
651 // ------------------------------------------------------------------------
652 
653 void Graphic::ResetAnimationLoopCount()
654 {
655     mpImpGraphic->ImplResetAnimationLoopCount();
656 }
657 
658 // ------------------------------------------------------------------------
659 
660 List* Graphic::GetAnimationInfoList() const
661 {
662     return mpImpGraphic->ImplGetAnimationInfoList();
663 }
664 
665 // ------------------------------------------------------------------------
666 
667 GraphicReader* Graphic::GetContext()
668 {
669     return mpImpGraphic->ImplGetContext();
670 }
671 
672 // ------------------------------------------------------------------------
673 
674 void Graphic::SetContext( GraphicReader* pReader )
675 {
676     mpImpGraphic->ImplSetContext( pReader );
677 }
678 
679 // ------------------------------------------------------------------------
680 
681 sal_uInt16 Graphic::GetGraphicsCompressMode( SvStream& rIStm )
682 {
683     const sal_uLong     nPos = rIStm.Tell();
684     const sal_uInt16    nOldFormat = rIStm.GetNumberFormatInt();
685     sal_uInt32          nTmp32;
686     sal_uInt16          nTmp16;
687     sal_uInt16          nCompressMode = COMPRESSMODE_NONE;
688 
689     rIStm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
690 
691     rIStm >> nTmp32;
692 
693     // is it a swapped graphic with a bitmap?
694     rIStm.SeekRel( (nTmp32 == (sal_uInt32) GRAPHIC_BITMAP ) ? 40 : -4 );
695 
696     // try to read bitmap id
697     rIStm >> nTmp16;
698 
699     // check id of BitmapFileHeader
700     if( 0x4D42 == nTmp16 )
701     {
702         // seek to compress field of BitmapInfoHeader
703         rIStm.SeekRel( 28 );
704         rIStm >> nTmp32;
705 
706         // Compare with our own compressmode
707         if( ZCOMPRESS == nTmp32 )
708             nCompressMode = COMPRESSMODE_ZBITMAP;
709     }
710 
711     rIStm.SetNumberFormatInt( nOldFormat );
712     rIStm.Seek( nPos );
713 
714     return nCompressMode;
715 }
716 
717 // ------------------------------------------------------------------------
718 
719 void Graphic::SetDocFileName( const String& rName, sal_uLong nFilePos )
720 {
721     mpImpGraphic->ImplSetDocFileName( rName, nFilePos );
722 }
723 
724 // ------------------------------------------------------------------------
725 
726 const String& Graphic::GetDocFileName() const
727 {
728     return mpImpGraphic->ImplGetDocFileName();
729 }
730 
731 // ------------------------------------------------------------------------
732 
733 sal_uLong Graphic::GetDocFilePos() const
734 {
735     return mpImpGraphic->ImplGetDocFilePos();
736 }
737 
738 // ------------------------------------------------------------------------
739 
740 sal_Bool Graphic::ReadEmbedded( SvStream& rIStream, sal_Bool bSwap )
741 {
742     ImplTestRefCount();
743     return mpImpGraphic->ImplReadEmbedded( rIStream, bSwap );
744 }
745 
746 // ------------------------------------------------------------------------
747 
748 sal_Bool Graphic::WriteEmbedded( SvStream& rOStream )
749 {
750     ImplTestRefCount();
751     return mpImpGraphic->ImplWriteEmbedded( rOStream );
752 }
753 
754 // ------------------------------------------------------------------------
755 
756 sal_Bool Graphic::SwapOut()
757 {
758     ImplTestRefCount();
759     return mpImpGraphic->ImplSwapOut();
760 }
761 
762 // ------------------------------------------------------------------------
763 
764 sal_Bool Graphic::SwapOut( SvStream* pOStream )
765 {
766     ImplTestRefCount();
767     return mpImpGraphic->ImplSwapOut( pOStream );
768 }
769 
770 // ------------------------------------------------------------------------
771 
772 sal_Bool Graphic::SwapIn()
773 {
774     ImplTestRefCount();
775     return mpImpGraphic->ImplSwapIn();
776 }
777 
778 // ------------------------------------------------------------------------
779 
780 sal_Bool Graphic::SwapIn( SvStream* pStrm )
781 {
782     ImplTestRefCount();
783     return mpImpGraphic->ImplSwapIn( pStrm );
784 }
785 
786 // ------------------------------------------------------------------------
787 
788 sal_Bool Graphic::IsSwapOut() const
789 {
790     return mpImpGraphic->ImplIsSwapOut();
791 }
792 
793 // ------------------------------------------------------------------------
794 
795 void Graphic::SetLink( const GfxLink& rGfxLink )
796 {
797     ImplTestRefCount();
798     mpImpGraphic->ImplSetLink( rGfxLink );
799 }
800 
801 // ------------------------------------------------------------------------
802 
803 GfxLink Graphic::GetLink() const
804 {
805     return mpImpGraphic->ImplGetLink();
806 }
807 
808 // ------------------------------------------------------------------------
809 
810 sal_Bool Graphic::IsLink() const
811 {
812     return mpImpGraphic->ImplIsLink();
813 }
814 
815 // ------------------------------------------------------------------------
816 
817 sal_uLong Graphic::GetChecksum() const
818 {
819     return mpImpGraphic->ImplGetChecksum();
820 }
821 
822 // ------------------------------------------------------------------------
823 
824 sal_Bool Graphic::ExportNative( SvStream& rOStream ) const
825 {
826 	return mpImpGraphic->ImplExportNative( rOStream );
827 }
828 
829 // ------------------------------------------------------------------------
830 
831 SvStream& operator>>( SvStream& rIStream, Graphic& rGraphic )
832 {
833     rGraphic.ImplTestRefCount();
834     return rIStream >> *rGraphic.mpImpGraphic;
835 }
836 
837 // ------------------------------------------------------------------------
838 
839 SvStream& operator<<( SvStream& rOStream, const Graphic& rGraphic )
840 {
841     return rOStream << *rGraphic.mpImpGraphic;
842 }
843