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