Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <com/sun/star/task/XStatusIndicator.hpp>
21 : #include <unotools/ucbstreamhelper.hxx>
22 :
23 : #define CGM_BREAK_ACTION 0xffffffff
24 : #include <osl/endian.h>
25 : #include <vcl/virdev.hxx>
26 : #include <vcl/graph.hxx>
27 : #include <tools/stream.hxx>
28 : #include <chart.hxx>
29 : #include <main.hxx>
30 : #include <elements.hxx>
31 : #include <outact.hxx>
32 :
33 : using namespace ::com::sun::star;
34 :
35 : // ---------------------------------------------------------------
36 :
37 0 : void CGM::ImplCGMInit()
38 : {
39 0 : mbIsFinished = mbPicture = mbMetaFile = mbPictureBody = sal_False;
40 :
41 0 : mnActCount = 0;
42 0 : mnOutdx = 28000;
43 0 : mnOutdy = 21000;
44 :
45 0 : mpBuf = NULL;
46 0 : mpChart = NULL;
47 0 : mpBitmapInUse = NULL;
48 :
49 0 : pCopyOfE = new CGMElements( *this );
50 0 : pElement = new CGMElements( *this );
51 0 : }
52 :
53 : // ---------------------------------------------------------------
54 :
55 : #ifdef CGM_EXPORT_IMPRESS
56 :
57 0 : CGM::CGM( sal_uInt32 nMode, uno::Reference< frame::XModel > & rModel ) :
58 : mpGraphic ( NULL ),
59 : mbStatus ( sal_True ),
60 0 : mpOutAct ( new CGMImpressOutAct( *this, rModel ) ),
61 0 : mnMode ( nMode )
62 : {
63 0 : mnMode |= CGM_EXPORT_IMPRESS;
64 0 : ImplCGMInit();
65 0 : }
66 : #endif
67 :
68 : // ---------------------------------------------------------------
69 :
70 0 : CGM::~CGM()
71 : {
72 :
73 : #ifdef CGM_EXPORT_META
74 0 : if ( mpGraphic )
75 : {
76 0 : mpGDIMetaFile->Stop();
77 0 : mpGDIMetaFile->SetPrefMapMode( MapMode() );
78 0 : mpGDIMetaFile->SetPrefSize( Size( static_cast< long >( mnOutdx ), static_cast< long >( mnOutdy ) ) );
79 0 : delete mpVirDev;
80 0 : *mpGraphic = Graphic( *mpGDIMetaFile );
81 : }
82 : #endif
83 0 : for( size_t i = 0, n = maDefRepList.size(); i < n; ++i )
84 0 : delete maDefRepList[ i ];
85 0 : maDefRepList.clear();
86 0 : maDefRepSizeList.clear();
87 0 : delete mpBitmapInUse;
88 0 : delete mpChart;
89 0 : delete mpOutAct;
90 0 : delete pCopyOfE;
91 0 : delete pElement;
92 0 : delete [] mpBuf;
93 0 : };
94 :
95 : // ---------------------------------------------------------------
96 :
97 0 : sal_uInt32 CGM::GetBackGroundColor()
98 : {
99 0 : return ( pElement ) ? pElement->aColorTable[ 0 ] : 0;
100 : }
101 :
102 : // ---------------------------------------------------------------
103 :
104 0 : sal_uInt32 CGM::ImplGetUI16( sal_uInt32 /*nAlign*/ )
105 : {
106 0 : sal_uInt8* pSource = mpSource + mnParaSize;
107 0 : mnParaSize += 2;
108 0 : return ( pSource[ 0 ] << 8 ) + pSource[ 1 ];
109 : };
110 :
111 : // ---------------------------------------------------------------
112 :
113 0 : sal_uInt8 CGM::ImplGetByte( sal_uInt32 nSource, sal_uInt32 nPrecision )
114 : {
115 0 : return (sal_uInt8)( nSource >> ( ( nPrecision - 1 ) << 3 ) );
116 : };
117 :
118 : // ---------------------------------------------------------------
119 :
120 0 : long CGM::ImplGetI( sal_uInt32 nPrecision )
121 : {
122 0 : sal_uInt8* pSource = mpSource + mnParaSize;
123 0 : mnParaSize += nPrecision;
124 0 : switch( nPrecision )
125 : {
126 : case 1 :
127 : {
128 0 : return (char)*pSource;
129 : }
130 :
131 : case 2 :
132 : {
133 0 : return (sal_Int16)( ( pSource[ 0 ] << 8 ) | pSource[ 1 ] );
134 : }
135 :
136 : case 3 :
137 : {
138 0 : return ( ( pSource[ 0 ] << 24 ) | ( pSource[ 1 ] << 16 ) | pSource[ 2 ] << 8 ) >> 8;
139 : }
140 : case 4:
141 : {
142 0 : return (sal_Int32)( ( pSource[ 0 ] << 24 ) | ( pSource[ 1 ] << 16 ) | ( pSource[ 2 ] << 8 ) | ( pSource[ 3 ] ) );
143 : }
144 : default:
145 0 : mbStatus = sal_False;
146 0 : return 0;
147 : }
148 : }
149 :
150 : // ---------------------------------------------------------------
151 :
152 0 : sal_uInt32 CGM::ImplGetUI( sal_uInt32 nPrecision )
153 : {
154 0 : sal_uInt8* pSource = mpSource + mnParaSize;
155 0 : mnParaSize += nPrecision;
156 0 : switch( nPrecision )
157 : {
158 : case 1 :
159 0 : return (sal_Int8)*pSource;
160 : case 2 :
161 : {
162 0 : return (sal_uInt16)( ( pSource[ 0 ] << 8 ) | pSource[ 1 ] );
163 : }
164 : case 3 :
165 : {
166 0 : return ( pSource[ 0 ] << 16 ) | ( pSource[ 1 ] << 8 ) | pSource[ 2 ];
167 : }
168 : case 4:
169 : {
170 0 : return (sal_uInt32)( ( pSource[ 0 ] << 24 ) | ( pSource[ 1 ] << 16 ) | ( pSource[ 2 ] << 8 ) | ( pSource[ 3 ] ) );
171 : }
172 : default:
173 0 : mbStatus = sal_False;
174 0 : return 0;
175 : }
176 : }
177 :
178 : // ---------------------------------------------------------------
179 :
180 0 : void CGM::ImplGetSwitch4( sal_uInt8* pSource, sal_uInt8* pDest )
181 : {
182 0 : for ( int i = 0; i < 4; i++ )
183 : {
184 0 : pDest[ i ] = pSource[ i ^ 3 ]; // Little Endian <-> Big Endian switch
185 : }
186 0 : }
187 :
188 : // ---------------------------------------------------------------
189 :
190 0 : void CGM::ImplGetSwitch8( sal_uInt8* pSource, sal_uInt8* pDest )
191 : {
192 0 : for ( int i = 0; i < 8; i++ )
193 : {
194 0 : pDest[ i ] = pSource[ i ^ 7 ]; // Little Endian <-> Big Endian switch
195 : }
196 0 : }
197 :
198 : // ---------------------------------------------------------------
199 :
200 0 : double CGM::ImplGetFloat( RealPrecision eRealPrecision, sal_uInt32 nRealSize )
201 : {
202 : void* pPtr;
203 : sal_uInt8 aBuf[8];
204 : sal_Bool bCompatible;
205 : double nRetValue;
206 : double fDoubleBuf;
207 : float fFloatBuf;
208 :
209 : #ifdef OSL_BIGENDIAN
210 : bCompatible = sal_True;
211 : #else
212 0 : bCompatible = sal_False;
213 : #endif
214 0 : if ( bCompatible )
215 0 : pPtr = mpSource + mnParaSize;
216 : else
217 : {
218 0 : if ( nRealSize == 4 )
219 0 : ImplGetSwitch4( mpSource + mnParaSize, &aBuf[0] );
220 : else
221 0 : ImplGetSwitch8( mpSource + mnParaSize, &aBuf[0] );
222 0 : pPtr = &aBuf;
223 : }
224 0 : if ( eRealPrecision == RP_FLOAT )
225 : {
226 0 : if ( nRealSize == 4 )
227 : {
228 0 : memcpy( (void*)&fFloatBuf, pPtr, 4 );
229 0 : nRetValue = (double)fFloatBuf;
230 : }
231 : else
232 : {
233 0 : memcpy( (void*)&fDoubleBuf, pPtr, 8 );
234 0 : nRetValue = fDoubleBuf;
235 : }
236 : }
237 : else // ->RP_FIXED
238 : {
239 : long nVal;
240 0 : int nSwitch = ( bCompatible ) ? 0 : 1 ;
241 0 : if ( nRealSize == 4 )
242 : {
243 0 : sal_uInt16* pShort = (sal_uInt16*)pPtr;
244 0 : nVal = pShort[ nSwitch ];
245 0 : nVal <<= 16;
246 0 : nVal |= pShort[ nSwitch ^ 1 ];
247 0 : nRetValue = (double)nVal;
248 0 : nRetValue /= 65536;
249 : }
250 : else
251 : {
252 0 : sal_Int32* pLong = (sal_Int32*)pPtr;
253 0 : nRetValue = (double)abs( pLong[ nSwitch ] );
254 0 : nRetValue *= 65536;
255 0 : nVal = (sal_uInt32)( pLong[ nSwitch ^ 1 ] );
256 0 : nVal >>= 16;
257 0 : nRetValue += (double)nVal;
258 0 : if ( pLong[ nSwitch ] < 0 )
259 : {
260 0 : nRetValue = -nRetValue;
261 : }
262 0 : nRetValue /= 65536;
263 : }
264 : }
265 0 : mnParaSize += nRealSize;
266 0 : return nRetValue;
267 : }
268 :
269 : // ---------------------------------------------------------------
270 :
271 0 : sal_uInt32 CGM::ImplGetPointSize()
272 : {
273 0 : if ( pElement->eVDCType == VDC_INTEGER )
274 0 : return pElement->nVDCIntegerPrecision << 1;
275 : else
276 0 : return pElement->nVDCRealSize << 1;
277 : }
278 :
279 : // ---------------------------------------------------------------
280 :
281 0 : inline double CGM::ImplGetIX()
282 : {
283 0 : return ( ( ImplGetI( pElement->nVDCIntegerPrecision ) + mnVDCXadd ) * mnVDCXmul );
284 : }
285 :
286 : // ---------------------------------------------------------------
287 :
288 0 : inline double CGM::ImplGetFX()
289 : {
290 0 : return ( ( ImplGetFloat( pElement->eVDCRealPrecision, pElement->nVDCRealSize ) + mnVDCXadd ) * mnVDCXmul );
291 : }
292 :
293 : // ---------------------------------------------------------------
294 :
295 0 : inline double CGM::ImplGetIY()
296 : {
297 0 : return ( ( ImplGetI( pElement->nVDCIntegerPrecision ) + mnVDCYadd ) * mnVDCYmul );
298 : }
299 :
300 : // ---------------------------------------------------------------
301 :
302 0 : inline double CGM::ImplGetFY()
303 : {
304 0 : return ( ( ImplGetFloat( pElement->eVDCRealPrecision, pElement->nVDCRealSize ) + mnVDCYadd ) * mnVDCYmul );
305 : }
306 :
307 : // ---------------------------------------------------------------
308 :
309 0 : void CGM::ImplGetPoint( FloatPoint& rFloatPoint, sal_Bool bMap )
310 : {
311 0 : if ( pElement->eVDCType == VDC_INTEGER )
312 : {
313 0 : rFloatPoint.X = ImplGetIX();
314 0 : rFloatPoint.Y = ImplGetIY();
315 : }
316 : else // ->floating points
317 : {
318 0 : rFloatPoint.X = ImplGetFX();
319 0 : rFloatPoint.Y = ImplGetFY();
320 : }
321 0 : if ( bMap )
322 0 : ImplMapPoint( rFloatPoint );
323 0 : }
324 :
325 : // ---------------------------------------------------------------
326 :
327 0 : void CGM::ImplGetRectangle( FloatRect& rFloatRect, sal_Bool bMap )
328 : {
329 0 : if ( pElement->eVDCType == VDC_INTEGER )
330 : {
331 0 : rFloatRect.Left = ImplGetIX();
332 0 : rFloatRect.Bottom = ImplGetIY();
333 0 : rFloatRect.Right = ImplGetIX();
334 0 : rFloatRect.Top = ImplGetIY();
335 : }
336 : else // ->floating points
337 : {
338 0 : rFloatRect.Left = ImplGetFX();
339 0 : rFloatRect.Bottom = ImplGetFY();
340 0 : rFloatRect.Right = ImplGetFX();
341 0 : rFloatRect.Top = ImplGetFY();
342 : }
343 0 : if ( bMap )
344 : {
345 0 : ImplMapX( rFloatRect.Left );
346 0 : ImplMapX( rFloatRect.Right );
347 0 : ImplMapY( rFloatRect.Top );
348 0 : ImplMapY( rFloatRect.Bottom );
349 0 : rFloatRect.Justify();
350 : }
351 0 : }
352 :
353 : // ---------------------------------------------------------------
354 :
355 0 : void CGM::ImplGetRectangleNS( FloatRect& rFloatRect )
356 : {
357 0 : if ( pElement->eVDCType == VDC_INTEGER )
358 : {
359 0 : rFloatRect.Left = ImplGetI( pElement->nVDCIntegerPrecision );
360 0 : rFloatRect.Bottom = ImplGetI( pElement->nVDCIntegerPrecision );
361 0 : rFloatRect.Right = ImplGetI( pElement->nVDCIntegerPrecision );
362 0 : rFloatRect.Top = ImplGetI( pElement->nVDCIntegerPrecision );
363 : }
364 : else // ->floating points
365 : {
366 0 : rFloatRect.Left = ImplGetFloat( pElement->eVDCRealPrecision, pElement->nVDCRealSize );
367 0 : rFloatRect.Bottom = ImplGetFloat( pElement->eVDCRealPrecision, pElement->nVDCRealSize );
368 0 : rFloatRect.Right = ImplGetFloat( pElement->eVDCRealPrecision, pElement->nVDCRealSize );
369 0 : rFloatRect.Top = ImplGetFloat( pElement->eVDCRealPrecision, pElement->nVDCRealSize );
370 : }
371 0 : }
372 :
373 : // ---------------------------------------------------------------
374 :
375 0 : sal_uInt32 CGM::ImplGetBitmapColor( sal_Bool bDirect )
376 : {
377 : // the background color is always a direct color
378 :
379 : sal_uInt32 nTmp;
380 0 : if ( ( pElement->eColorSelectionMode == CSM_DIRECT ) || bDirect )
381 : {
382 0 : sal_uInt32 nColor = ImplGetByte( ImplGetUI( pElement->nColorPrecision ), 1 );
383 0 : sal_uInt32 nDiff = pElement->nColorValueExtent[ 3 ] - pElement->nColorValueExtent[ 0 ] + 1;
384 :
385 0 : if ( !nDiff )
386 0 : nDiff++;
387 0 : nColor = ( ( nColor - pElement->nColorValueExtent[ 0 ] ) << 8 ) / nDiff;
388 0 : nTmp = nColor << 16 & 0xff0000;
389 :
390 0 : nColor = ImplGetByte( ImplGetUI( pElement->nColorPrecision ), 1 );
391 0 : nDiff = pElement->nColorValueExtent[ 4 ] - pElement->nColorValueExtent[ 1 ] + 1;
392 0 : if ( !nDiff )
393 0 : nDiff++;
394 0 : nColor = ( ( nColor - pElement->nColorValueExtent[ 1 ] ) << 8 ) / nDiff;
395 0 : nTmp |= nColor << 8 & 0xff00;
396 :
397 0 : nColor = ImplGetByte( ImplGetUI( pElement->nColorPrecision ), 1 );
398 0 : nDiff = pElement->nColorValueExtent[ 5 ] - pElement->nColorValueExtent[ 2 ] + 1;
399 0 : if ( !nDiff )
400 0 : nDiff++;
401 0 : nColor = ( ( nColor - pElement->nColorValueExtent[ 2 ] ) << 8 ) / nDiff;
402 0 : nTmp |= (sal_uInt8)nColor;
403 : }
404 : else
405 : {
406 0 : sal_uInt32 nIndex = ImplGetUI( pElement->nColorIndexPrecision );
407 0 : nTmp = pElement->aColorTable[ (sal_uInt8)( nIndex ) ] ;
408 : }
409 0 : return nTmp;
410 : }
411 :
412 : // ---------------------------------------------------------------
413 :
414 : // call this function each time after the mapmode settings has been changed
415 0 : void CGM::ImplSetMapMode()
416 : {
417 0 : int nAngReverse = 1;
418 0 : mnVDCdx = pElement->aVDCExtent.Right - pElement->aVDCExtent.Left;
419 :
420 0 : mnVDCXadd = -pElement->aVDCExtent.Left;
421 0 : mnVDCXmul = 1;
422 0 : if ( mnVDCdx < 0 )
423 : {
424 0 : nAngReverse ^= 1;
425 0 : mnVDCdx = -mnVDCdx;
426 0 : mnVDCXmul = -1;
427 : }
428 :
429 0 : mnVDCdy = pElement->aVDCExtent.Bottom - pElement->aVDCExtent.Top;
430 0 : mnVDCYadd = -pElement->aVDCExtent.Top;
431 0 : mnVDCYmul = 1;
432 0 : if ( mnVDCdy < 0 )
433 : {
434 0 : nAngReverse ^= 1;
435 0 : mnVDCdy = -mnVDCdy;
436 0 : mnVDCYmul = -1;
437 : }
438 0 : if ( nAngReverse )
439 0 : mbAngReverse = sal_True;
440 : else
441 0 : mbAngReverse = sal_False;
442 :
443 0 : double fQuo1 = mnVDCdx / mnVDCdy;
444 0 : double fQuo2 = mnOutdx / mnOutdy;
445 0 : if ( fQuo2 < fQuo1 )
446 : {
447 0 : mnXFraction = mnOutdx / mnVDCdx;
448 0 : mnYFraction = mnOutdy * ( fQuo2 / fQuo1 ) / mnVDCdy;
449 : }
450 : else
451 : {
452 0 : mnXFraction = mnOutdx * ( fQuo1 / fQuo2 ) / mnVDCdx;
453 0 : mnYFraction = mnOutdy / mnVDCdy;
454 : }
455 0 : }
456 :
457 : // ---------------------------------------------------------------
458 :
459 0 : void CGM::ImplMapDouble( double& nNumb )
460 : {
461 0 : if ( pElement->eDeviceViewPortMap == DVPM_FORCED )
462 : {
463 : // point is 1mm * ScalingFactor
464 0 : switch ( pElement->eDeviceViewPortMode )
465 : {
466 : case DVPM_FRACTION :
467 : {
468 0 : nNumb *= ( mnXFraction + mnYFraction ) / 2;
469 : }
470 0 : break;
471 :
472 : case DVPM_METRIC :
473 : {
474 : // nNumb *= ( 100 * pElement->nDeviceViewPortScale );
475 0 : nNumb *= ( mnXFraction + mnYFraction ) / 2;
476 0 : if ( pElement->nDeviceViewPortScale < 0 )
477 0 : nNumb = -nNumb;
478 : }
479 0 : break;
480 :
481 : case DVPM_DEVICE :
482 : {
483 :
484 : }
485 0 : break;
486 :
487 : default:
488 :
489 0 : break;
490 : }
491 : }
492 : else
493 : {
494 :
495 :
496 : }
497 0 : }
498 :
499 : // ---------------------------------------------------------------
500 :
501 0 : void CGM::ImplMapX( double& nNumb )
502 : {
503 0 : if ( pElement->eDeviceViewPortMap == DVPM_FORCED )
504 : {
505 : // point is 1mm * ScalingFactor
506 0 : switch ( pElement->eDeviceViewPortMode )
507 : {
508 : case DVPM_FRACTION :
509 : {
510 0 : nNumb *= mnXFraction;
511 : }
512 0 : break;
513 :
514 : case DVPM_METRIC :
515 : {
516 : // nNumb *= ( 100 * pElement->nDeviceViewPortScale );
517 0 : nNumb *= mnXFraction;
518 0 : if ( pElement->nDeviceViewPortScale < 0 )
519 0 : nNumb = -nNumb;
520 : }
521 0 : break;
522 :
523 : case DVPM_DEVICE :
524 : {
525 :
526 : }
527 0 : break;
528 :
529 : default:
530 :
531 0 : break;
532 : }
533 : }
534 : else
535 : {
536 :
537 :
538 : }
539 0 : }
540 :
541 :
542 : // ---------------------------------------------------------------
543 :
544 0 : void CGM::ImplMapY( double& nNumb )
545 : {
546 0 : if ( pElement->eDeviceViewPortMap == DVPM_FORCED )
547 : {
548 : // point is 1mm * ScalingFactor
549 0 : switch ( pElement->eDeviceViewPortMode )
550 : {
551 : case DVPM_FRACTION :
552 : {
553 0 : nNumb *= mnYFraction;
554 : }
555 0 : break;
556 :
557 : case DVPM_METRIC :
558 : {
559 : // nNumb *= ( 100 * pElement->nDeviceViewPortScale );
560 0 : nNumb *= mnYFraction;
561 0 : if ( pElement->nDeviceViewPortScale < 0 )
562 0 : nNumb = -nNumb;
563 : }
564 0 : break;
565 :
566 : case DVPM_DEVICE :
567 : {
568 :
569 : }
570 0 : break;
571 :
572 : default:
573 :
574 0 : break;
575 : }
576 : }
577 : else
578 : {
579 :
580 :
581 : }
582 0 : }
583 :
584 :
585 : // ---------------------------------------------------------------
586 :
587 : // convert a point to the current VC mapmode (1/100TH mm)
588 0 : void CGM::ImplMapPoint( FloatPoint& rFloatPoint )
589 : {
590 0 : if ( pElement->eDeviceViewPortMap == DVPM_FORCED )
591 : {
592 : // point is 1mm * ScalingFactor
593 0 : switch ( pElement->eDeviceViewPortMode )
594 : {
595 : case DVPM_FRACTION :
596 : {
597 0 : rFloatPoint.X *= mnXFraction;
598 0 : rFloatPoint.Y *= mnYFraction;
599 : }
600 0 : break;
601 :
602 : case DVPM_METRIC :
603 : {
604 0 : rFloatPoint.X *= mnXFraction;
605 0 : rFloatPoint.Y *= mnYFraction;
606 0 : if ( pElement->nDeviceViewPortScale < 0 )
607 : {
608 0 : rFloatPoint.X = -rFloatPoint.X;
609 0 : rFloatPoint.Y = -rFloatPoint.Y;
610 : }
611 : }
612 0 : break;
613 :
614 : case DVPM_DEVICE :
615 : {
616 :
617 : }
618 0 : break;
619 :
620 : default:
621 :
622 0 : break;
623 : }
624 : }
625 : else
626 : {
627 :
628 :
629 : }
630 0 : }
631 :
632 : // ---------------------------------------------------------------
633 :
634 0 : void CGM::ImplDoClass()
635 : {
636 : #ifdef CGM_USER_BREAKPOINT
637 : #ifdef WNT
638 : if ( mnActCount == CGM_BREAK_ACTION )
639 : _asm int 0x3;
640 : #endif
641 : #endif
642 0 : switch ( mnElementClass )
643 : {
644 0 : case 0 : ImplDoClass0(); break;
645 0 : case 1 : ImplDoClass1(); break;
646 0 : case 2 : ImplDoClass2(); break;
647 0 : case 3 : ImplDoClass3(); break;
648 : case 4 :
649 : {
650 0 : ImplDoClass4();
651 0 : mnAct4PostReset = 0;
652 : }
653 0 : break;
654 0 : case 5 : ImplDoClass5(); break;
655 0 : case 6 : ImplDoClass6(); break;
656 0 : case 7 : ImplDoClass7(); break;
657 0 : case 8 : ImplDoClass8(); break;
658 0 : case 9 : ImplDoClass9(); break;
659 0 : case 15 :ImplDoClass15(); break;
660 0 : default: break;
661 : }
662 0 : mnActCount++;
663 0 : };
664 :
665 : // ---------------------------------------------------------------
666 :
667 0 : void CGM::ImplDefaultReplacement()
668 : {
669 0 : if ( !maDefRepList.empty() )
670 : {
671 0 : sal_uInt32 nOldEscape = mnEscape;
672 0 : sal_uInt32 nOldElementClass = mnElementClass;
673 0 : sal_uInt32 nOldElementID = mnElementID;
674 0 : sal_uInt32 nOldElementSize = mnElementSize;
675 0 : sal_uInt8* pOldBuf = mpSource;
676 :
677 0 : for ( size_t i = 0, n = maDefRepList.size(); i < n; ++i )
678 : {
679 0 : sal_uInt8* pBuf = maDefRepList[ i ];
680 0 : sal_uInt32 nElementSize = maDefRepSizeList[ i ];
681 0 : sal_uInt32 nCount = 0;
682 0 : while ( mbStatus && ( nCount < nElementSize ) )
683 : {
684 0 : mpSource = pBuf + nCount;
685 0 : mnParaSize = 0;
686 0 : mnEscape = ImplGetUI16();
687 0 : mnElementClass = mnEscape >> 12;
688 0 : mnElementID = ( mnEscape & 0x0fe0 ) >> 5;
689 0 : mnElementSize = mnEscape & 0x1f;
690 0 : if ( mnElementSize == 31 )
691 : {
692 0 : mnElementSize = ImplGetUI16();
693 : }
694 0 : nCount += mnParaSize;
695 0 : mnParaSize = 0;
696 0 : mpSource = pBuf + nCount;
697 0 : if ( mnElementSize & 1 )
698 0 : nCount++;
699 0 : nCount += mnElementSize;
700 0 : if ( ( mnElementClass != 1 ) || ( mnElementID != 0xc ) ) // rekursion hier nicht moeglich!!
701 0 : ImplDoClass();
702 : }
703 : }
704 0 : mnEscape = nOldEscape;
705 0 : mnElementClass = nOldElementClass;
706 0 : mnElementID = nOldElementID;
707 0 : mnParaSize = mnElementSize = nOldElementSize;
708 0 : mpSource = pOldBuf;
709 : }
710 0 : }
711 :
712 : // ---------------------------------------------------------------
713 :
714 0 : sal_Bool CGM::Write( SvStream& rIStm )
715 : {
716 0 : if ( !mpBuf )
717 0 : mpBuf = new sal_uInt8[ 0xffff ];
718 :
719 0 : mnParaSize = 0;
720 0 : mpSource = mpBuf;
721 0 : rIStm.Read( mpSource, 2 );
722 0 : mnEscape = ImplGetUI16();
723 0 : mnElementClass = mnEscape >> 12;
724 0 : mnElementID = ( mnEscape & 0x0fe0 ) >> 5;
725 0 : mnElementSize = mnEscape & 0x1f;
726 :
727 0 : if ( mnElementSize == 31 )
728 : {
729 0 : rIStm.Read( mpSource + mnParaSize, 2 );
730 0 : mnElementSize = ImplGetUI16();
731 : }
732 0 : mnParaSize = 0;
733 0 : if ( mnElementSize )
734 0 : rIStm.Read( mpSource + mnParaSize, mnElementSize );
735 :
736 0 : if ( mnElementSize & 1 )
737 0 : rIStm.SeekRel( 1 );
738 0 : ImplDoClass();
739 :
740 :
741 : #ifdef CGM_USER_BREAKPOINT
742 : #ifdef WNT
743 : if ( !mbStatus || mnParaSize && ( mnElementSize != mnParaSize ) )
744 : _asm int 0x3;
745 : #endif
746 : #endif
747 :
748 0 : return mbStatus;
749 : };
750 :
751 : // ---------------------------------------------------------------
752 :
753 0 : SvStream& operator>>( SvStream& rOStm, CGM& /*rCGM*/ )
754 : {
755 :
756 0 : return rOStm;
757 : };
758 :
759 : // ---------------------------------------------------------------
760 :
761 :
762 :
763 : //================== GraphicImport - die exportierte Funktion ================
764 :
765 : extern "C" SAL_DLLPUBLIC_EXPORT sal_uInt32 SAL_CALL
766 0 : ImportCGM( String& rFileName, uno::Reference< frame::XModel > & rXModel, sal_uInt32 nMode, void* pProgressBar )
767 : {
768 :
769 0 : sal_uInt32 nStatus = 0; // retvalue == 0 -> ERROR
770 : // == 0xffrrggbb -> background color in the lower 24 bits
771 0 : sal_Bool bProgressBar = sal_False;
772 :
773 0 : if( rXModel.is() )
774 : {
775 0 : CGM* pCGM= NULL;
776 :
777 : try
778 : {
779 0 : pCGM = new CGM( nMode, rXModel );
780 0 : if ( pCGM && pCGM->IsValid() )
781 : {
782 0 : if ( nMode & CGM_IMPORT_CGM )
783 : {
784 0 : SvStream* pIn = ::utl::UcbStreamHelper::CreateStream( rFileName, STREAM_READ );
785 0 : if ( pIn )
786 : {
787 0 : pIn->SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN );
788 0 : pIn->Seek( STREAM_SEEK_TO_END );
789 0 : sal_uInt32 nInSize = pIn->Tell();
790 0 : pIn->Seek( 0 );
791 :
792 : #ifdef CGM_EXPORT_IMPRESS
793 0 : uno::Reference< task::XStatusIndicator > aXStatInd;
794 0 : sal_uInt32 nNext = 0;
795 0 : sal_uInt32 nAdd = nInSize / 20;
796 0 : if ( pProgressBar )
797 0 : aXStatInd = *(uno::Reference< task::XStatusIndicator > *)pProgressBar;
798 0 : bProgressBar = aXStatInd.is();
799 0 : if ( bProgressBar )
800 0 : aXStatInd->start( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CGM Import" )), nInSize );
801 : #endif
802 :
803 0 : while ( pCGM->IsValid() && ( pIn->Tell() < nInSize ) && !pCGM->IsFinished() )
804 : {
805 :
806 : #ifdef CGM_EXPORT_IMPRESS
807 :
808 :
809 0 : if ( bProgressBar )
810 : {
811 0 : sal_uInt32 nCurrentPos = pIn->Tell();
812 0 : if ( nCurrentPos >= nNext )
813 : {
814 0 : aXStatInd->setValue( nCurrentPos );
815 0 : nNext = nCurrentPos + nAdd;
816 : }
817 : }
818 : #endif
819 :
820 0 : if ( pCGM->Write( *pIn ) == sal_False )
821 0 : break;
822 : }
823 0 : if ( pCGM->IsValid() )
824 : {
825 0 : nStatus = pCGM->GetBackGroundColor() | 0xff000000;
826 : }
827 : #ifdef CGM_EXPORT_IMPRESS
828 0 : if ( bProgressBar )
829 0 : aXStatInd->end();
830 : #endif
831 0 : delete pIn;
832 : }
833 : }
834 : }
835 : }
836 0 : catch( const ::com::sun::star::uno::Exception& )
837 : {
838 0 : nStatus = 0;
839 : }
840 0 : delete pCGM;
841 : }
842 0 : return nStatus;
843 : }
844 :
845 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|