Update ooo320-m1
[ooovba.git] / goodies / source / filter.vcl / icgm / cgm.cxx
blob8a6ca6d0cbca1136c59c9a54ac418f7ed08226c3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cgm.cxx,v $
10 * $Revision: 1.16 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_goodies.hxx"
33 #include <com/sun/star/task/XStatusIndicator.hpp>
34 #include <unotools/ucbstreamhelper.hxx>
36 #define CGM_BREAK_ACTION 0xffffffff
37 #include <osl/endian.h>
38 #include <vcl/virdev.hxx>
39 #include <vcl/graph.hxx>
40 #include <tools/stream.hxx>
41 #include <chart.hxx>
42 #include <main.hxx>
43 #include <elements.hxx>
44 #include <outact.hxx>
46 using namespace ::com::sun::star;
48 // ---------------------------------------------------------------
50 void CGM::ImplCGMInit()
52 mbIsFinished = mbPicture = mbMetaFile = mbPictureBody = sal_False;
54 mnActCount = 0;
55 mnOutdx = 28000;
56 mnOutdy = 21000;
58 mpBuf = NULL;
59 mpChart = NULL;
60 mpBitmapInUse = NULL;
62 pCopyOfE = new CGMElements( *this );
63 pElement = new CGMElements( *this );
66 // ---------------------------------------------------------------
68 #ifdef CGM_EXPORT_IMPRESS
70 CGM::CGM( sal_uInt32 nMode, uno::Reference< frame::XModel > & rModel ) :
71 mpGraphic ( NULL ),
72 mpCommentOut ( NULL ),
73 mbStatus ( sal_True ),
74 mpOutAct ( new CGMImpressOutAct( *this, rModel ) ),
75 mnMode ( nMode )
77 mnMode |= CGM_EXPORT_IMPRESS;
78 ImplCGMInit();
80 #endif
82 // ---------------------------------------------------------------
84 void CGM::ImplComment( sal_uInt32 Level, const char* Description )
86 if ( mpCommentOut )
88 if ( Level == CGM_DESCRIPTION )
90 *mpCommentOut << " " << Description << "\n";
92 else
94 sal_Int8 nFirst, nSecond, i, nCount = 0;
95 if ( mnActCount < 10000 )
96 nCount++;
97 if ( mnActCount < 1000 )
98 nCount++;
99 if ( mnActCount < 100 )
100 nCount++;
101 if ( mnActCount < 10 )
102 nCount++;
103 for ( i = 0; i <= nCount; i++ )
104 *mpCommentOut << " ";
105 mpCommentOut->WriteNumber( mnActCount );
107 switch( Level & 0xff )
109 case CGM_UNKNOWN_LEVEL :
110 *mpCommentOut << " L?";
111 break;
112 case CGM_UNKNOWN_COMMAND :
113 *mpCommentOut << " UNKNOWN COMMAND";
114 break;
115 case CGM_GDSF_ONLY :
116 *mpCommentOut << " LI";
117 break;
118 default:
119 *mpCommentOut << " L";
120 mpCommentOut->WriteNumber( Level & 0xff );
121 break;
123 *mpCommentOut << " C";
124 mpCommentOut->WriteNumber( mnElementClass );
125 *mpCommentOut << " ID-0x";
126 nFirst = ( mnElementID > 0x9F ) ? (sal_Int8)( mnElementID >> 4 ) + 'A' - 10: (sal_Int8)( mnElementID >> 4 ) + '0';
127 nSecond = ( ( mnElementID & 15 ) > 9 ) ? (sal_Int8)( mnElementID & 15 ) + 'A' - 10 : (sal_Int8)( mnElementID & 15 ) + '0';
128 *mpCommentOut << nFirst << nSecond;
129 *mpCommentOut << " Size";
130 nCount = 1;
131 if ( mnElementSize < 1000000 )
132 nCount++;
133 if ( mnElementSize < 100000 )
134 nCount++;
135 if ( mnElementSize < 10000 )
136 nCount++;
137 if ( mnElementSize < 1000 )
138 nCount++;
139 if ( mnElementSize < 100 )
140 nCount++;
141 if ( mnElementSize < 10 )
142 nCount++;
143 for ( i = 0; i < nCount; i++ )
144 *mpCommentOut << " ";
145 mpCommentOut->WriteNumber( mnElementSize );
146 *mpCommentOut << " " << Description << "\n";
151 // ---------------------------------------------------------------
153 CGM::~CGM()
156 #ifdef CGM_EXPORT_META
157 if ( mpGraphic )
159 mpGDIMetaFile->Stop();
160 mpGDIMetaFile->SetPrefMapMode( MapMode() );
161 mpGDIMetaFile->SetPrefSize( Size( static_cast< long >( mnOutdx ), static_cast< long >( mnOutdy ) ) );
162 delete mpVirDev;
163 *mpGraphic = Graphic( *mpGDIMetaFile );
165 #endif
166 sal_Int8* pBuf = (sal_Int8*)maDefRepList.First();
167 while( pBuf )
169 delete pBuf;
170 pBuf = (sal_Int8*)maDefRepList.Next();
172 maDefRepList.Clear();
173 delete mpBitmapInUse;
174 delete mpCommentOut;
175 delete mpChart;
176 delete mpOutAct;
177 delete pCopyOfE;
178 delete pElement;
179 delete [] mpBuf;
182 // ---------------------------------------------------------------
184 sal_uInt32 CGM::GetBackGroundColor()
186 return ( pElement ) ? pElement->aColorTable[ 0 ] : 0;
189 // ---------------------------------------------------------------
191 sal_uInt32 CGM::ImplGetUI16( sal_uInt32 /*nAlign*/ )
193 sal_uInt8* pSource = mpSource + mnParaSize;
194 mnParaSize += 2;
195 return ( pSource[ 0 ] << 8 ) + pSource[ 1 ];
198 // ---------------------------------------------------------------
200 sal_uInt8 CGM::ImplGetByte( sal_uInt32 nSource, sal_uInt32 nPrecision )
202 return (sal_uInt8)( nSource >> ( ( nPrecision - 1 ) << 3 ) );
205 // ---------------------------------------------------------------
207 long CGM::ImplGetI( sal_uInt32 nPrecision )
209 sal_uInt8* pSource = mpSource + mnParaSize;
210 mnParaSize += nPrecision;
211 switch( nPrecision )
213 case 1 :
215 return (char)*pSource;
218 case 2 :
220 return (sal_Int16)( ( pSource[ 0 ] << 8 ) | pSource[ 1 ] );
223 case 3 :
225 return ( ( pSource[ 0 ] << 24 ) | ( pSource[ 1 ] << 16 ) | pSource[ 2 ] << 8 ) >> 8;
227 case 4:
229 return (sal_Int32)( ( pSource[ 0 ] << 24 ) | ( pSource[ 1 ] << 16 ) | ( pSource[ 2 ] << 8 ) | ( pSource[ 3 ] ) );
231 default:
232 mbStatus = sal_False;
233 return 0;
237 // ---------------------------------------------------------------
239 sal_uInt32 CGM::ImplGetUI( sal_uInt32 nPrecision )
241 sal_uInt8* pSource = mpSource + mnParaSize;
242 mnParaSize += nPrecision;
243 switch( nPrecision )
245 case 1 :
246 return (sal_Int8)*pSource;
247 case 2 :
249 return (sal_uInt16)( ( pSource[ 0 ] << 8 ) | pSource[ 1 ] );
251 case 3 :
253 return ( pSource[ 0 ] << 16 ) | ( pSource[ 1 ] << 8 ) | pSource[ 2 ];
255 case 4:
257 return (sal_uInt32)( ( pSource[ 0 ] << 24 ) | ( pSource[ 1 ] << 16 ) | ( pSource[ 2 ] << 8 ) | ( pSource[ 3 ] ) );
259 default:
260 mbStatus = sal_False;
261 return 0;
265 // ---------------------------------------------------------------
267 void CGM::ImplGetSwitch4( sal_uInt8* pSource, sal_uInt8* pDest )
269 for ( int i = 0; i < 4; i++ )
271 pDest[ i ] = pSource[ i ^ 3 ]; // Little Endian <-> Big Endian switch
275 // ---------------------------------------------------------------
277 void CGM::ImplGetSwitch8( sal_uInt8* pSource, sal_uInt8* pDest )
279 for ( int i = 0; i < 8; i++ )
281 pDest[ i ] = pSource[ i ^ 7 ]; // Little Endian <-> Big Endian switch
285 // ---------------------------------------------------------------
287 double CGM::ImplGetFloat( RealPrecision eRealPrecision, sal_uInt32 nRealSize )
289 void* pPtr;
290 sal_uInt8 aBuf[8];
291 sal_Bool bCompatible;
292 double nRetValue;
293 double fDoubleBuf;
294 float fFloatBuf;
296 #ifdef OSL_BIGENDIAN
297 bCompatible = sal_True;
298 #else
299 bCompatible = sal_False;
300 #endif
301 if ( bCompatible )
302 pPtr = mpSource + mnParaSize;
303 else
305 if ( nRealSize == 4 )
306 ImplGetSwitch4( mpSource + mnParaSize, &aBuf[0] );
307 else
308 ImplGetSwitch8( mpSource + mnParaSize, &aBuf[0] );
309 pPtr = &aBuf;
311 if ( eRealPrecision == RP_FLOAT )
313 if ( nRealSize == 4 )
315 memcpy( (void*)&fFloatBuf, pPtr, 4 );
316 nRetValue = (double)fFloatBuf;
318 else
320 memcpy( (void*)&fDoubleBuf, pPtr, 8 );
321 nRetValue = fDoubleBuf;
324 else // ->RP_FIXED
326 long nVal;
327 int nSwitch = ( bCompatible ) ? 0 : 1 ;
328 if ( nRealSize == 4 )
330 sal_uInt16* pShort = (sal_uInt16*)pPtr;
331 nVal = pShort[ nSwitch ];
332 nVal <<= 16;
333 nVal |= pShort[ nSwitch ^ 1 ];
334 nRetValue = (double)nVal;
335 nRetValue /= 65536;
337 else
339 long* pLong = (long*)pPtr;
340 nRetValue = (double)abs( pLong[ nSwitch ] );
341 nRetValue *= 65536;
342 nVal = (sal_uInt32)( pLong[ nSwitch ^ 1 ] );
343 nVal >>= 16;
344 nRetValue += (double)nVal;
345 if ( pLong[ nSwitch ] < 0 )
347 nRetValue -= nRetValue;
349 nRetValue /= 65536;
352 mnParaSize += nRealSize;
353 return nRetValue;
356 // ---------------------------------------------------------------
358 sal_uInt32 CGM::ImplGetPointSize()
360 if ( pElement->eVDCType == VDC_INTEGER )
361 return pElement->nVDCIntegerPrecision << 1;
362 else
363 return pElement->nVDCRealSize << 1;
366 // ---------------------------------------------------------------
368 inline double CGM::ImplGetIX()
370 return ( ( ImplGetI( pElement->nVDCIntegerPrecision ) + mnVDCXadd ) * mnVDCXmul );
373 // ---------------------------------------------------------------
375 inline double CGM::ImplGetFX()
377 return ( ( ImplGetFloat( pElement->eVDCRealPrecision, pElement->nVDCRealSize ) + mnVDCXadd ) * mnVDCXmul );
380 // ---------------------------------------------------------------
382 inline double CGM::ImplGetIY()
384 return ( ( ImplGetI( pElement->nVDCIntegerPrecision ) + mnVDCYadd ) * mnVDCYmul );
387 // ---------------------------------------------------------------
389 inline double CGM::ImplGetFY()
391 return ( ( ImplGetFloat( pElement->eVDCRealPrecision, pElement->nVDCRealSize ) + mnVDCYadd ) * mnVDCYmul );
394 // ---------------------------------------------------------------
396 void CGM::ImplGetPoint( FloatPoint& rFloatPoint, sal_Bool bMap )
398 if ( pElement->eVDCType == VDC_INTEGER )
400 rFloatPoint.X = ImplGetIX();
401 rFloatPoint.Y = ImplGetIY();
403 else // ->floating points
405 rFloatPoint.X = ImplGetFX();
406 rFloatPoint.Y = ImplGetFY();
408 if ( bMap )
409 ImplMapPoint( rFloatPoint );
412 // ---------------------------------------------------------------
414 void CGM::ImplGetRectangle( FloatRect& rFloatRect, sal_Bool bMap )
416 if ( pElement->eVDCType == VDC_INTEGER )
418 rFloatRect.Left = ImplGetIX();
419 rFloatRect.Bottom = ImplGetIY();
420 rFloatRect.Right = ImplGetIX();
421 rFloatRect.Top = ImplGetIY();
423 else // ->floating points
425 rFloatRect.Left = ImplGetFX();
426 rFloatRect.Bottom = ImplGetFY();
427 rFloatRect.Right = ImplGetFX();
428 rFloatRect.Top = ImplGetFY();
430 if ( bMap )
432 ImplMapX( rFloatRect.Left );
433 ImplMapX( rFloatRect.Right );
434 ImplMapY( rFloatRect.Top );
435 ImplMapY( rFloatRect.Bottom );
436 rFloatRect.Justify();
440 // ---------------------------------------------------------------
442 void CGM::ImplGetRectangleNS( FloatRect& rFloatRect )
444 if ( pElement->eVDCType == VDC_INTEGER )
446 rFloatRect.Left = ImplGetI( pElement->nVDCIntegerPrecision );
447 rFloatRect.Bottom = ImplGetI( pElement->nVDCIntegerPrecision );
448 rFloatRect.Right = ImplGetI( pElement->nVDCIntegerPrecision );
449 rFloatRect.Top = ImplGetI( pElement->nVDCIntegerPrecision );
451 else // ->floating points
453 rFloatRect.Left = ImplGetFloat( pElement->eVDCRealPrecision, pElement->nVDCRealSize );
454 rFloatRect.Bottom = ImplGetFloat( pElement->eVDCRealPrecision, pElement->nVDCRealSize );
455 rFloatRect.Right = ImplGetFloat( pElement->eVDCRealPrecision, pElement->nVDCRealSize );
456 rFloatRect.Top = ImplGetFloat( pElement->eVDCRealPrecision, pElement->nVDCRealSize );
460 // ---------------------------------------------------------------
462 sal_uInt32 CGM::ImplGetBitmapColor( sal_Bool bDirect )
464 // the background color is always a direct color
466 sal_uInt32 nTmp;
467 if ( ( pElement->eColorSelectionMode == CSM_DIRECT ) || bDirect )
469 sal_uInt32 nColor = ImplGetByte( ImplGetUI( pElement->nColorPrecision ), 1 );
470 sal_uInt32 nDiff = pElement->nColorValueExtent[ 3 ] - pElement->nColorValueExtent[ 0 ] + 1;
472 if ( !nDiff )
473 nDiff++;
474 nColor = ( ( nColor - pElement->nColorValueExtent[ 0 ] ) << 8 ) / nDiff;
475 nTmp = nColor << 16 & 0xff0000;
477 nColor = ImplGetByte( ImplGetUI( pElement->nColorPrecision ), 1 );
478 nDiff = pElement->nColorValueExtent[ 4 ] - pElement->nColorValueExtent[ 1 ] + 1;
479 if ( !nDiff )
480 nDiff++;
481 nColor = ( ( nColor - pElement->nColorValueExtent[ 1 ] ) << 8 ) / nDiff;
482 nTmp |= nColor << 8 & 0xff00;
484 nColor = ImplGetByte( ImplGetUI( pElement->nColorPrecision ), 1 );
485 nDiff = pElement->nColorValueExtent[ 5 ] - pElement->nColorValueExtent[ 2 ] + 1;
486 if ( !nDiff )
487 nDiff++;
488 nColor = ( ( nColor - pElement->nColorValueExtent[ 2 ] ) << 8 ) / nDiff;
489 nTmp |= (sal_uInt8)nColor;
491 else
493 sal_uInt32 nIndex = ImplGetUI( pElement->nColorIndexPrecision );
494 nTmp = pElement->aColorTable[ (sal_uInt8)( nIndex ) ] ;
496 return nTmp;
499 // ---------------------------------------------------------------
501 // call this function each time after the mapmode settings has been changed
502 void CGM::ImplSetMapMode()
504 int nAngReverse = 1;
505 mnVDCdx = pElement->aVDCExtent.Right - pElement->aVDCExtent.Left;
507 mnVDCXadd = -pElement->aVDCExtent.Left;
508 mnVDCXmul = 1;
509 if ( mnVDCdx < 0 )
511 nAngReverse ^= 1;
512 mnVDCdx = -mnVDCdx;
513 mnVDCXmul = -1;
516 mnVDCdy = pElement->aVDCExtent.Bottom - pElement->aVDCExtent.Top;
517 mnVDCYadd = -pElement->aVDCExtent.Top;
518 mnVDCYmul = 1;
519 if ( mnVDCdy < 0 )
521 nAngReverse ^= 1;
522 mnVDCdy = -mnVDCdy;
523 mnVDCYmul = -1;
525 if ( nAngReverse )
526 mbAngReverse = sal_True;
527 else
528 mbAngReverse = sal_False;
530 double fQuo1 = mnVDCdx / mnVDCdy;
531 double fQuo2 = mnOutdx / mnOutdy;
532 if ( fQuo2 < fQuo1 )
534 mnXFraction = mnOutdx / mnVDCdx;
535 mnYFraction = mnOutdy * ( fQuo2 / fQuo1 ) / mnVDCdy;
537 else
539 mnXFraction = mnOutdx * ( fQuo1 / fQuo2 ) / mnVDCdx;
540 mnYFraction = mnOutdy / mnVDCdy;
544 // ---------------------------------------------------------------
546 void CGM::ImplMapDouble( double& nNumb )
548 if ( pElement->eDeviceViewPortMap == DVPM_FORCED )
550 // point is 1mm * ScalingFactor
551 switch ( pElement->eDeviceViewPortMode )
553 case DVPM_FRACTION :
555 nNumb *= ( mnXFraction + mnYFraction ) / 2;
557 break;
559 case DVPM_METRIC :
561 // nNumb *= ( 100 * pElement->nDeviceViewPortScale );
562 nNumb *= ( mnXFraction + mnYFraction ) / 2;
563 if ( pElement->nDeviceViewPortScale < 0 )
564 nNumb = -nNumb;
566 break;
568 case DVPM_DEVICE :
572 break;
574 default:
576 break;
579 else
586 // ---------------------------------------------------------------
588 void CGM::ImplMapX( double& nNumb )
590 if ( pElement->eDeviceViewPortMap == DVPM_FORCED )
592 // point is 1mm * ScalingFactor
593 switch ( pElement->eDeviceViewPortMode )
595 case DVPM_FRACTION :
597 nNumb *= mnXFraction;
599 break;
601 case DVPM_METRIC :
603 // nNumb *= ( 100 * pElement->nDeviceViewPortScale );
604 nNumb *= mnXFraction;
605 if ( pElement->nDeviceViewPortScale < 0 )
606 nNumb = -nNumb;
608 break;
610 case DVPM_DEVICE :
614 break;
616 default:
618 break;
621 else
629 // ---------------------------------------------------------------
631 void CGM::ImplMapY( double& nNumb )
633 if ( pElement->eDeviceViewPortMap == DVPM_FORCED )
635 // point is 1mm * ScalingFactor
636 switch ( pElement->eDeviceViewPortMode )
638 case DVPM_FRACTION :
640 nNumb *= mnYFraction;
642 break;
644 case DVPM_METRIC :
646 // nNumb *= ( 100 * pElement->nDeviceViewPortScale );
647 nNumb *= mnYFraction;
648 if ( pElement->nDeviceViewPortScale < 0 )
649 nNumb = -nNumb;
651 break;
653 case DVPM_DEVICE :
657 break;
659 default:
661 break;
664 else
672 // ---------------------------------------------------------------
674 // convert a point to the current VC mapmode (1/100TH mm)
675 void CGM::ImplMapPoint( FloatPoint& rFloatPoint )
677 if ( pElement->eDeviceViewPortMap == DVPM_FORCED )
679 // point is 1mm * ScalingFactor
680 switch ( pElement->eDeviceViewPortMode )
682 case DVPM_FRACTION :
684 rFloatPoint.X *= mnXFraction;
685 rFloatPoint.Y *= mnYFraction;
687 break;
689 case DVPM_METRIC :
691 rFloatPoint.X *= mnXFraction;
692 rFloatPoint.Y *= mnYFraction;
693 if ( pElement->nDeviceViewPortScale < 0 )
695 rFloatPoint.X = -rFloatPoint.X;
696 rFloatPoint.Y = -rFloatPoint.Y;
699 break;
701 case DVPM_DEVICE :
705 break;
707 default:
709 break;
712 else
719 // ---------------------------------------------------------------
721 void CGM::ImplDoClass()
723 #ifdef CGM_USER_BREAKPOINT
724 #ifdef WNT
725 if ( mnActCount == CGM_BREAK_ACTION )
726 _asm int 0x3;
727 #endif
728 #endif
729 switch ( mnElementClass )
731 case 0 : ImplDoClass0(); break;
732 case 1 : ImplDoClass1(); break;
733 case 2 : ImplDoClass2(); break;
734 case 3 : ImplDoClass3(); break;
735 case 4 :
737 ImplDoClass4();
738 mnAct4PostReset = 0;
740 break;
741 case 5 : ImplDoClass5(); break;
742 case 6 : ImplDoClass6(); break;
743 case 7 : ImplDoClass7(); break;
744 case 8 : ImplDoClass8(); break;
745 case 9 : ImplDoClass9(); break;
746 case 15 :ImplDoClass15(); break;
747 default : ComOut( CGM_UNKNOWN_COMMAND, "" ); break;
749 mnActCount++;
752 // ---------------------------------------------------------------
754 void CGM::ImplDefaultReplacement()
756 sal_uInt8* pBuf = (sal_uInt8*)maDefRepList.First();
757 if ( pBuf )
759 sal_uInt32 nElementSize = (sal_uInt32)(sal_uIntPtr)maDefRepSizeList.First();
760 sal_uInt32 nOldEscape = mnEscape;
761 sal_uInt32 nOldElementClass = mnElementClass;
762 sal_uInt32 nOldElementID = mnElementID;
763 sal_uInt32 nOldElementSize = mnElementSize;
764 sal_uInt8* pOldBuf = mpSource;
765 while( pBuf )
767 sal_uInt32 nCount = 0;
768 while ( mbStatus && ( nCount < nElementSize ) )
770 mpSource = pBuf + nCount;
771 mnParaSize = 0;
772 mnEscape = ImplGetUI16();
773 mnElementClass = mnEscape >> 12;
774 mnElementID = ( mnEscape & 0x0fe0 ) >> 5;
775 mnElementSize = mnEscape & 0x1f;
776 if ( mnElementSize == 31 )
778 mnElementSize = ImplGetUI16();
780 nCount += mnParaSize;
781 mnParaSize = 0;
782 mpSource = pBuf + nCount;
783 if ( mnElementSize & 1 )
784 nCount++;
785 nCount += mnElementSize;
786 if ( ( mnElementClass != 1 ) || ( mnElementID != 0xc ) ) // rekursion hier nicht moeglich!!
787 ImplDoClass();
789 nElementSize = (sal_uInt32)(sal_uIntPtr)maDefRepSizeList.Next();
790 pBuf = (sal_uInt8*)maDefRepList.Next();
792 mnEscape = nOldEscape;
793 mnElementClass = nOldElementClass;
794 mnElementID = nOldElementID;
795 mnParaSize = mnElementSize = nOldElementSize;
796 mpSource = pOldBuf;
800 // ---------------------------------------------------------------
802 sal_Bool CGM::Write( SvStream& rIStm )
804 if ( !mpBuf )
805 mpBuf = new sal_uInt8[ 0xffff ];
807 mnParaSize = 0;
808 mpSource = mpBuf;
809 rIStm.Read( mpSource, 2 );
810 mnEscape = ImplGetUI16();
811 mnElementClass = mnEscape >> 12;
812 mnElementID = ( mnEscape & 0x0fe0 ) >> 5;
813 mnElementSize = mnEscape & 0x1f;
815 if ( mnElementSize == 31 )
817 rIStm.Read( mpSource + mnParaSize, 2 );
818 mnElementSize = ImplGetUI16();
820 mnParaSize = 0;
821 if ( mnElementSize )
822 rIStm.Read( mpSource + mnParaSize, mnElementSize );
824 if ( mnElementSize & 1 )
825 rIStm.SeekRel( 1 );
826 ImplDoClass();
829 #ifdef CGM_USER_BREAKPOINT
830 #ifdef WNT
831 if ( !mbStatus || mnParaSize && ( mnElementSize != mnParaSize ) )
832 _asm int 0x3;
833 #endif
834 #endif
836 return mbStatus;
839 // ---------------------------------------------------------------
841 SvStream& operator>>( SvStream& rOStm, CGM& /*rCGM*/ )
844 return rOStm;
847 // ---------------------------------------------------------------
851 //================== GraphicImport - die exportierte Funktion ================
853 extern "C" sal_uInt32 __LOADONCALLAPI ImportCGM( String& rFileName, uno::Reference< frame::XModel > & rXModel, sal_uInt32 nMode, void* pProgressBar )
856 sal_uInt32 nStatus = 0; // retvalue == 0 -> ERROR
857 // == 0xffrrggbb -> background color in the lower 24 bits
858 sal_Bool bProgressBar = sal_False;
860 if( rXModel.is() )
862 CGM* pCGM= NULL;
866 pCGM = new CGM( nMode, rXModel );
867 if ( pCGM && pCGM->IsValid() )
869 if ( nMode & CGM_IMPORT_CGM )
871 SvStream* pIn = ::utl::UcbStreamHelper::CreateStream( rFileName, STREAM_READ );
872 if ( pIn )
874 pIn->SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN );
875 pIn->Seek( STREAM_SEEK_TO_END );
876 sal_uInt32 nInSize = pIn->Tell();
877 pIn->Seek( 0 );
879 #ifdef CGM_EXPORT_IMPRESS
880 uno::Reference< task::XStatusIndicator > aXStatInd;
881 sal_uInt32 nNext = 0;
882 sal_uInt32 nAdd = nInSize / 20;
883 if ( pProgressBar )
884 aXStatInd = *(uno::Reference< task::XStatusIndicator > *)pProgressBar;
885 bProgressBar = aXStatInd.is();
886 if ( bProgressBar )
887 aXStatInd->start( rtl::OUString::createFromAscii("CGM Import"), nInSize );
888 #endif
890 while ( pCGM->IsValid() && ( pIn->Tell() < nInSize ) && !pCGM->IsFinished() )
893 #ifdef CGM_EXPORT_IMPRESS
896 if ( bProgressBar )
898 sal_uInt32 nCurrentPos = pIn->Tell();
899 if ( nCurrentPos >= nNext )
901 aXStatInd->setValue( nCurrentPos );
902 nNext = nCurrentPos + nAdd;
905 #endif
907 if ( pCGM->Write( *pIn ) == sal_False )
908 break;
910 if ( pCGM->IsValid() )
912 nStatus = pCGM->GetBackGroundColor() | 0xff000000;
914 #ifdef CGM_EXPORT_IMPRESS
915 if ( bProgressBar )
916 aXStatInd->end();
917 #endif
918 delete pIn;
923 catch( ::com::sun::star::uno::Exception& )
925 nStatus = 0;
927 delete pCGM;
929 return nStatus;