Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <tools/vcompat.hxx>
31 : : #include <tools/urlobj.hxx>
32 : : #include <tools/debug.hxx>
33 : : #include <tools/stream.hxx>
34 : : #include <tools/helpers.hxx>
35 : :
36 : : #include <ucbhelper/content.hxx>
37 : :
38 : : #include <unotools/ucbstreamhelper.hxx>
39 : : #include <unotools/tempfile.hxx>
40 : : #include <vcl/outdev.hxx>
41 : : #include <vcl/virdev.hxx>
42 : : #include <vcl/gfxlink.hxx>
43 : : #include <vcl/cvtgrf.hxx>
44 : : #include <vcl/graph.hxx>
45 : : #include <vcl/metaact.hxx>
46 : :
47 : : #include <impgraph.hxx>
48 : :
49 : : #include <com/sun/star/ucb/CommandAbortedException.hpp>
50 : :
51 : : // -----------
52 : : // - Defines -
53 : : // -----------
54 : :
55 : : #define GRAPHIC_MAXPARTLEN 256000L
56 : : #define GRAPHIC_MTFTOBMP_MAXEXT 2048
57 : : #define GRAPHIC_STREAMBUFSIZE 8192UL
58 : :
59 : : #define SYS_WINMETAFILE 0x00000003L
60 : : #define SYS_WNTMETAFILE 0x00000004L
61 : : #define SYS_OS2METAFILE 0x00000005L
62 : : #define SYS_MACMETAFILE 0x00000006L
63 : :
64 : : #define GRAPHIC_FORMAT_50 static_cast<sal_uInt32>(COMPAT_FORMAT( 'G', 'R', 'F', '5' ))
65 : : #define NATIVE_FORMAT_50 static_cast<sal_uInt32>(COMPAT_FORMAT( 'N', 'A', 'T', '5' ))
66 : :
67 : : // ---------------
68 : : // - ImpSwapFile -
69 : : // ---------------
70 : :
71 : 21 : struct ImpSwapFile
72 : : {
73 : : INetURLObject aSwapURL;
74 : : sal_uLong nRefCount;
75 : : };
76 : :
77 : : // -----------------
78 : : // - Graphicreader -
79 : : // -----------------
80 : :
81 : 0 : class ReaderData
82 : : {
83 : : public:
84 : : Size maPreviewSize;
85 : : };
86 : :
87 : 52 : GraphicReader::~GraphicReader()
88 : : {
89 : 52 : delete mpReaderData;
90 [ - + ]: 52 : }
91 : :
92 : : // ------------------------------------------------------------------------
93 : :
94 : 26 : void GraphicReader::DisablePreviewMode()
95 : : {
96 [ - + ]: 26 : if( mpReaderData )
97 : 0 : mpReaderData->maPreviewSize = Size( 0, 0 );
98 : 26 : }
99 : :
100 : : // ------------------------------------------------------------------------
101 : :
102 : 0 : void GraphicReader::SetPreviewSize( const Size& rSize )
103 : : {
104 [ # # ]: 0 : if( !mpReaderData )
105 : 0 : mpReaderData = new ReaderData;
106 : 0 : mpReaderData->maPreviewSize = rSize;
107 : 0 : }
108 : :
109 : : // ------------------------------------------------------------------------
110 : :
111 : 26 : Size GraphicReader::GetPreviewSize() const
112 : : {
113 : 26 : Size aSize( 0, 0 );
114 [ - + ]: 26 : if( mpReaderData )
115 : 0 : aSize = mpReaderData->maPreviewSize;
116 : 26 : return aSize;
117 : : }
118 : :
119 : : // --------------
120 : : // - ImpGraphic -
121 : : // --------------
122 : :
123 : 119357 : ImpGraphic::ImpGraphic() :
124 : : mpAnimation ( NULL ),
125 : : mpContext ( NULL ),
126 : : mpSwapFile ( NULL ),
127 : : mpGfxLink ( NULL ),
128 : : meType ( GRAPHIC_NONE ),
129 : : mnDocFilePos ( 0UL ),
130 : : mnSizeBytes ( 0UL ),
131 : : mnRefCount ( 1UL ),
132 : : mbSwapOut ( sal_False ),
133 [ + - ][ + - ]: 119357 : mbSwapUnderway ( sal_False )
[ + - ]
134 : : {
135 : 119357 : }
136 : :
137 : : // ------------------------------------------------------------------------
138 : :
139 : 84 : ImpGraphic::ImpGraphic( const ImpGraphic& rImpGraphic ) :
140 : : maMetaFile ( rImpGraphic.maMetaFile ),
141 : : maEx ( rImpGraphic.maEx ),
142 : : mpContext ( NULL ),
143 : : mpSwapFile ( rImpGraphic.mpSwapFile ),
144 : : meType ( rImpGraphic.meType ),
145 : : maDocFileURLStr ( rImpGraphic.maDocFileURLStr ),
146 : : mnDocFilePos ( rImpGraphic.mnDocFilePos ),
147 : : mnSizeBytes ( rImpGraphic.mnSizeBytes ),
148 : : mnRefCount ( 1UL ),
149 : : mbSwapOut ( rImpGraphic.mbSwapOut ),
150 [ + - ][ + - ]: 84 : mbSwapUnderway ( sal_False )
[ + - ]
151 : : {
152 [ - + ]: 84 : if( mpSwapFile )
153 : 0 : mpSwapFile->nRefCount++;
154 : :
155 [ - + ]: 84 : if( rImpGraphic.mpGfxLink )
156 [ # # ][ # # ]: 0 : mpGfxLink = new GfxLink( *rImpGraphic.mpGfxLink );
157 : : else
158 : 84 : mpGfxLink = NULL;
159 : :
160 [ + + ]: 84 : if( rImpGraphic.mpAnimation )
161 : : {
162 [ + - ][ + - ]: 18 : mpAnimation = new Animation( *rImpGraphic.mpAnimation );
163 [ + - ]: 18 : maEx = mpAnimation->GetBitmapEx();
164 : : }
165 : : else
166 : 66 : mpAnimation = NULL;
167 : 84 : }
168 : :
169 : : // ------------------------------------------------------------------------
170 : :
171 : 4052 : ImpGraphic::ImpGraphic( const Bitmap& rBitmap ) :
172 : : maEx ( rBitmap ),
173 : : mpAnimation ( NULL ),
174 : : mpContext ( NULL ),
175 : : mpSwapFile ( NULL ),
176 : : mpGfxLink ( NULL ),
177 : 4052 : meType ( !rBitmap ? GRAPHIC_NONE : GRAPHIC_BITMAP ),
178 : : mnDocFilePos ( 0UL ),
179 : : mnSizeBytes ( 0UL ),
180 : : mnRefCount ( 1UL ),
181 : : mbSwapOut ( sal_False ),
182 [ + - ]: 8104 : mbSwapUnderway ( sal_False )
[ + - + - ]
183 : : {
184 : 4052 : }
185 : :
186 : : // ------------------------------------------------------------------------
187 : :
188 : 199895 : ImpGraphic::ImpGraphic( const BitmapEx& rBitmapEx ) :
189 : : maEx ( rBitmapEx ),
190 : : mpAnimation ( NULL ),
191 : : mpContext ( NULL ),
192 : : mpSwapFile ( NULL ),
193 : : mpGfxLink ( NULL ),
194 : 199895 : meType ( !rBitmapEx ? GRAPHIC_NONE : GRAPHIC_BITMAP ),
195 : : mnDocFilePos ( 0UL ),
196 : : mnSizeBytes ( 0UL ),
197 : : mnRefCount ( 1UL ),
198 : : mbSwapOut ( sal_False ),
199 [ + - ]: 399790 : mbSwapUnderway ( sal_False )
[ + - + - ]
200 : : {
201 : 199895 : }
202 : :
203 : : // ------------------------------------------------------------------------
204 : :
205 : 18 : ImpGraphic::ImpGraphic( const Animation& rAnimation ) :
206 : 18 : maEx ( rAnimation.GetBitmapEx() ),
207 [ + - ]: 18 : mpAnimation ( new Animation( rAnimation ) ),
208 : : mpContext ( NULL ),
209 : : mpSwapFile ( NULL ),
210 : : mpGfxLink ( NULL ),
211 : : meType ( GRAPHIC_BITMAP ),
212 : : mnDocFilePos ( 0UL ),
213 : : mnSizeBytes ( 0UL ),
214 : : mnRefCount ( 1UL ),
215 : : mbSwapOut ( sal_False ),
216 [ + - ][ + - ]: 54 : mbSwapUnderway ( sal_False )
[ + - ][ + - ]
217 : : {
218 : 18 : }
219 : :
220 : : // ------------------------------------------------------------------------
221 : :
222 : 7165 : ImpGraphic::ImpGraphic( const GDIMetaFile& rMtf ) :
223 : : maMetaFile ( rMtf ),
224 : : mpAnimation ( NULL ),
225 : : mpContext ( NULL ),
226 : : mpSwapFile ( NULL ),
227 : : mpGfxLink ( NULL ),
228 : : meType ( GRAPHIC_GDIMETAFILE ),
229 : : mnDocFilePos ( 0UL ),
230 : : mnSizeBytes ( 0UL ),
231 : : mnRefCount ( 1UL ),
232 : : mbSwapOut ( sal_False ),
233 [ + - ][ + - ]: 7165 : mbSwapUnderway ( sal_False )
[ + - ]
234 : : {
235 : 7165 : }
236 : :
237 : : // ------------------------------------------------------------------------
238 : :
239 [ + - ][ + - ]: 330233 : ImpGraphic::~ImpGraphic()
[ + - ]
240 : : {
241 [ + - ]: 330233 : ImplClear();
242 : :
243 [ - + ]: 330233 : if( (sal_uLong) mpContext > 1UL )
244 [ # # ][ # # ]: 0 : delete mpContext;
245 [ - + ]: 653561 : }
246 : :
247 : : // ------------------------------------------------------------------------
248 : :
249 : 6911 : ImpGraphic& ImpGraphic::operator=( const ImpGraphic& rImpGraphic )
250 : : {
251 [ + - ]: 6911 : if( &rImpGraphic != this )
252 : : {
253 [ + + ]: 6911 : if( !mbSwapUnderway )
254 : 6905 : ImplClear();
255 : :
256 : 6911 : maMetaFile = rImpGraphic.maMetaFile;
257 : 6911 : meType = rImpGraphic.meType;
258 : 6911 : mnSizeBytes = rImpGraphic.mnSizeBytes;
259 : :
260 [ - + ]: 6911 : delete mpAnimation;
261 : :
262 [ - + ]: 6911 : if ( rImpGraphic.mpAnimation )
263 : : {
264 [ # # ]: 0 : mpAnimation = new Animation( *rImpGraphic.mpAnimation );
265 : 0 : maEx = mpAnimation->GetBitmapEx();
266 : : }
267 : : else
268 : : {
269 : 6911 : mpAnimation = NULL;
270 : 6911 : maEx = rImpGraphic.maEx;
271 : : }
272 : :
273 [ + + ]: 6911 : if( !mbSwapUnderway )
274 : : {
275 : 6905 : maDocFileURLStr = rImpGraphic.maDocFileURLStr;
276 : 6905 : mnDocFilePos = rImpGraphic.mnDocFilePos;
277 : 6905 : mbSwapOut = rImpGraphic.mbSwapOut;
278 : 6905 : mpSwapFile = rImpGraphic.mpSwapFile;
279 : :
280 [ - + ]: 6905 : if( mpSwapFile )
281 : 0 : mpSwapFile->nRefCount++;
282 : : }
283 : :
284 [ - + ]: 6911 : delete mpGfxLink;
285 : :
286 [ - + ]: 6911 : if( rImpGraphic.mpGfxLink )
287 [ # # ]: 0 : mpGfxLink = new GfxLink( *rImpGraphic.mpGfxLink );
288 : : else
289 : 6911 : mpGfxLink = NULL;
290 : : }
291 : :
292 : 6911 : return *this;
293 : : }
294 : :
295 : : // ------------------------------------------------------------------------
296 : :
297 : 37 : sal_Bool ImpGraphic::operator==( const ImpGraphic& rImpGraphic ) const
298 : : {
299 : 37 : sal_Bool bRet = sal_False;
300 : :
301 [ + + ]: 37 : if( this == &rImpGraphic )
302 : 2 : bRet = sal_True;
303 [ + - ][ + - ]: 35 : else if( !ImplIsSwapOut() && ( rImpGraphic.meType == meType ) )
[ + - ]
304 : : {
305 [ - - + - ]: 35 : switch( meType )
306 : : {
307 : : case( GRAPHIC_NONE ):
308 : 0 : bRet = sal_True;
309 : 0 : break;
310 : :
311 : : case( GRAPHIC_GDIMETAFILE ):
312 : : {
313 [ # # ]: 0 : if( rImpGraphic.maMetaFile == maMetaFile )
314 : 0 : bRet = sal_True;
315 : : }
316 : 0 : break;
317 : :
318 : : case( GRAPHIC_BITMAP ):
319 : : {
320 [ - + ]: 35 : if( mpAnimation )
321 : : {
322 [ # # ][ # # ]: 0 : if( rImpGraphic.mpAnimation && ( *rImpGraphic.mpAnimation == *mpAnimation ) )
[ # # ]
323 : 0 : bRet = sal_True;
324 : : }
325 [ + - ][ + - ]: 35 : else if( !rImpGraphic.mpAnimation && ( rImpGraphic.maEx == maEx ) )
[ + - ]
326 : 35 : bRet = sal_True;
327 : : }
328 : 35 : break;
329 : :
330 : : default:
331 : 35 : break;
332 : : }
333 : : }
334 : :
335 : 37 : return bRet;
336 : : }
337 : :
338 : : // ------------------------------------------------------------------------
339 : :
340 : 344349 : void ImpGraphic::ImplClearGraphics( sal_Bool bCreateSwapInfo )
341 : : {
342 [ + + ][ + - ]: 344349 : if( bCreateSwapInfo && !ImplIsSwapOut() )
[ + + ]
343 : : {
344 [ + - ]: 15 : maSwapInfo.maPrefMapMode = ImplGetPrefMapMode();
345 : 15 : maSwapInfo.maPrefSize = ImplGetPrefSize();
346 : : }
347 : :
348 : 344349 : maEx.Clear();
349 : 344349 : maMetaFile.Clear();
350 : :
351 [ + + ]: 344349 : if( mpAnimation )
352 : : {
353 : 36 : mpAnimation->Clear();
354 [ + - ]: 36 : delete mpAnimation;
355 : 36 : mpAnimation = NULL;
356 : : }
357 : :
358 [ + + ]: 344349 : if( mpGfxLink )
359 : : {
360 [ + - ]: 3459 : delete mpGfxLink;
361 : 3459 : mpGfxLink = NULL;
362 : : }
363 : 344349 : }
364 : :
365 : : // ------------------------------------------------------------------------
366 : :
367 : 344334 : void ImpGraphic::ImplClear()
368 : : {
369 [ - + ]: 344334 : if( mpSwapFile )
370 : : {
371 [ # # ]: 0 : if( mpSwapFile->nRefCount > 1 )
372 : 0 : mpSwapFile->nRefCount--;
373 : : else
374 : : {
375 : : try
376 : : {
377 : : ::ucbhelper::Content aCnt( mpSwapFile->aSwapURL.GetMainURL( INetURLObject::NO_DECODE ),
378 [ # # ][ # # ]: 0 : ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >() );
379 : :
380 : : aCnt.executeCommand( ::rtl::OUString("delete"),
381 [ # # ][ # # ]: 0 : ::com::sun::star::uno::makeAny( sal_Bool( sal_True ) ) );
[ # # # #
# ][ # # ]
382 : : }
383 : 0 : catch( const ::com::sun::star::ucb::ContentCreationException& )
384 : : {
385 : : }
386 : 0 : catch( const ::com::sun::star::uno::RuntimeException& )
387 : : {
388 : : }
389 : 0 : catch( const ::com::sun::star::ucb::CommandAbortedException& )
390 : : {
391 : : }
392 : 0 : catch( const ::com::sun::star::uno::Exception& )
393 : : {
394 : : }
395 : :
396 [ # # ]: 0 : delete mpSwapFile;
397 : : }
398 : :
399 : 0 : mpSwapFile = NULL;
400 : : }
401 : :
402 : 344334 : mbSwapOut = sal_False;
403 : 344334 : mnDocFilePos = 0UL;
404 : 344334 : maDocFileURLStr.Erase();
405 : :
406 : : // cleanup
407 : 344334 : ImplClearGraphics( sal_False );
408 : 344334 : meType = GRAPHIC_NONE;
409 : 344334 : mnSizeBytes = 0;
410 : 344334 : }
411 : :
412 : : // ------------------------------------------------------------------------
413 : :
414 : 423776 : GraphicType ImpGraphic::ImplGetType() const
415 : : {
416 : 423776 : return meType;
417 : : }
418 : :
419 : : // ------------------------------------------------------------------------
420 : :
421 : 132 : void ImpGraphic::ImplSetDefaultType()
422 : : {
423 : 132 : ImplClear();
424 : 132 : meType = GRAPHIC_DEFAULT;
425 : 132 : }
426 : :
427 : : // ------------------------------------------------------------------------
428 : :
429 : 157015 : sal_Bool ImpGraphic::ImplIsSupportedGraphic() const
430 : : {
431 : 157015 : return( meType != GRAPHIC_NONE );
432 : : }
433 : :
434 : : // ------------------------------------------------------------------------
435 : :
436 : 35206 : sal_Bool ImpGraphic::ImplIsTransparent() const
437 : : {
438 : : sal_Bool bRet;
439 : :
440 [ + + ]: 35206 : if( meType == GRAPHIC_BITMAP )
441 [ - + ]: 21392 : bRet = ( mpAnimation ? mpAnimation->IsTransparent() : maEx.IsTransparent() );
442 : : else
443 : 13814 : bRet = sal_True;
444 : :
445 : 35206 : return bRet;
446 : : }
447 : :
448 : : // ------------------------------------------------------------------------
449 : :
450 : 35204 : sal_Bool ImpGraphic::ImplIsAlpha() const
451 : : {
452 : : sal_Bool bRet;
453 : :
454 [ + + ]: 35204 : if( meType == GRAPHIC_BITMAP )
455 [ + - ][ + + ]: 21390 : bRet = ( NULL == mpAnimation ) && maEx.IsAlpha();
456 : : else
457 : 13814 : bRet = sal_False;
458 : :
459 : 35204 : return bRet;
460 : : }
461 : :
462 : : // ------------------------------------------------------------------------
463 : :
464 : 282243 : sal_Bool ImpGraphic::ImplIsAnimated() const
465 : : {
466 : 282243 : return( mpAnimation != NULL );
467 : : }
468 : :
469 : : // ------------------------------------------------------------------------
470 : :
471 : 35204 : sal_Bool ImpGraphic::ImplIsEPS() const
472 : : {
473 : : return( ( meType == GRAPHIC_GDIMETAFILE ) &&
474 : 191 : ( maMetaFile.GetActionSize() > 0 ) &&
475 [ + + + - ]: 35395 : ( maMetaFile.GetAction( 0 )->GetType() == META_EPS_ACTION ) );
[ - + ]
476 : : }
477 : :
478 : : // ------------------------------------------------------------------------
479 : :
480 : 35269 : sal_Bool ImpGraphic::ImplIsRenderGraphic() const
481 : : {
482 : : return( ( GRAPHIC_GDIMETAFILE == meType ) &&
483 : 256 : ( 1 == maMetaFile.GetActionSize() ) &&
484 [ + + - + ]: 35525 : ( META_RENDERGRAPHIC_ACTION == maMetaFile.GetAction( 0 )->GetType() ) );
[ # # ]
485 : : }
486 : :
487 : : // ------------------------------------------------------------------------
488 : :
489 : 35204 : sal_Bool ImpGraphic::ImplHasRenderGraphic() const
490 : : {
491 : 35204 : sal_Bool bRet = sal_False;
492 : :
493 [ + + ]: 35204 : if( GRAPHIC_GDIMETAFILE == meType )
494 : : {
495 : 191 : GDIMetaFile& rMtf = const_cast< ImpGraphic* >( this )->maMetaFile;
496 : :
497 [ + + ][ + - ]: 191510 : for( MetaAction* pAct = rMtf.FirstAction(); pAct && !bRet; pAct = rMtf.NextAction() )
[ + + ]
498 : : {
499 [ - + ]: 191319 : if( META_RENDERGRAPHIC_ACTION == pAct->GetType() )
500 : : {
501 : 0 : bRet = sal_True;
502 : : }
503 : : }
504 : :
505 : 191 : rMtf.WindStart();
506 : : }
507 : :
508 : 35204 : return( bRet );
509 : : }
510 : :
511 : : // ------------------------------------------------------------------------
512 : :
513 : 941 : Bitmap ImpGraphic::ImplGetBitmap(const GraphicConversionParameters& rParameters) const
514 : : {
515 : 941 : Bitmap aRetBmp;
516 : :
517 [ + - ]: 941 : if( meType == GRAPHIC_BITMAP )
518 : : {
519 [ - + ]: 941 : const BitmapEx& rRetBmpEx = ( mpAnimation ? mpAnimation->GetBitmapEx() : maEx );
520 : 941 : const Color aReplaceColor( COL_WHITE );
521 : :
522 [ + - ][ + - ]: 941 : aRetBmp = rRetBmpEx.GetBitmap( &aReplaceColor );
[ + - ]
523 : :
524 [ + - ][ - + ]: 941 : if(rParameters.getSizePixel().Width() || rParameters.getSizePixel().Height())
[ + - ][ + - ]
[ - + ]
525 [ # # ]: 941 : aRetBmp.Scale(rParameters.getSizePixel());
526 : : }
527 [ # # ][ # # ]: 0 : else if( ( meType != GRAPHIC_DEFAULT ) && ImplIsSupportedGraphic() )
[ # # ]
528 : : {
529 : : // use corner points of graphic to determine the pixel
530 : : // extent of the graphic (rounding errors are possible else)
531 [ # # ]: 0 : VirtualDevice aVDev;
532 : 0 : const Point aNullPt;
533 [ # # ]: 0 : const Point aTLPix( aVDev.LogicToPixel( aNullPt, maMetaFile.GetPrefMapMode() ) );
534 [ # # ]: 0 : const Point aBRPix( aVDev.LogicToPixel( Point( maMetaFile.GetPrefSize().Width() - 1, maMetaFile.GetPrefSize().Height() - 1 ), maMetaFile.GetPrefMapMode() ) );
535 [ # # ]: 0 : Size aDrawSize( aVDev.LogicToPixel( maMetaFile.GetPrefSize(), maMetaFile.GetPrefMapMode() ) );
536 : 0 : Size aSizePix( labs( aBRPix.X() - aTLPix.X() ) + 1, labs( aBRPix.Y() - aTLPix.Y() ) + 1 );
537 : :
538 [ # # ][ # # ]: 0 : if(rParameters.getSizePixel().Width() && rParameters.getSizePixel().Height())
[ # # ][ # # ]
[ # # ]
539 : : {
540 : 0 : aDrawSize.Width() = FRound((double)rParameters.getSizePixel().Width() *
541 : 0 : (double)aDrawSize.Width() / (double)aSizePix.Width());
542 : 0 : aDrawSize.Height() = FRound((double)rParameters.getSizePixel().Height() *
543 : 0 : (double)aDrawSize.Height() / (double)aSizePix.Height());
544 : :
545 : 0 : aSizePix = rParameters.getSizePixel();
546 : : }
547 : :
548 [ # # ][ # # ]: 0 : if( aSizePix.Width() && aSizePix.Height() && !rParameters.getUnlimitedSize()
[ # # # #
# # ][ # # ]
549 : 0 : && (aSizePix.Width() > GRAPHIC_MTFTOBMP_MAXEXT || aSizePix.Height() > GRAPHIC_MTFTOBMP_MAXEXT))
550 : : {
551 : 0 : const Size aOldSizePix( aSizePix );
552 : 0 : double fWH = (double) aSizePix.Width() / aSizePix.Height();
553 : :
554 [ # # ]: 0 : if( fWH <= 1.0 )
555 : 0 : aSizePix.Width() = FRound( GRAPHIC_MTFTOBMP_MAXEXT * fWH ), aSizePix.Height() = GRAPHIC_MTFTOBMP_MAXEXT;
556 : : else
557 : 0 : aSizePix.Width() = GRAPHIC_MTFTOBMP_MAXEXT, aSizePix.Height() = FRound( GRAPHIC_MTFTOBMP_MAXEXT / fWH );
558 : :
559 : 0 : aDrawSize.Width() = FRound( ( (double) aDrawSize.Width() * aSizePix.Width() ) / aOldSizePix.Width() );
560 : 0 : aDrawSize.Height() = FRound( ( (double) aDrawSize.Height() * aSizePix.Height() ) / aOldSizePix.Height() );
561 : : }
562 : :
563 [ # # ][ # # ]: 0 : if( aVDev.SetOutputSizePixel( aSizePix ) )
564 : : {
565 [ # # ]: 0 : if(rParameters.getAntiAliase())
566 : : {
567 [ # # ]: 0 : aVDev.SetAntialiasing(aVDev.GetAntialiasing() | ANTIALIASING_ENABLE_B2DDRAW);
568 : : }
569 : :
570 [ # # ]: 0 : if(rParameters.getSnapHorVerLines())
571 : : {
572 [ # # ]: 0 : aVDev.SetAntialiasing(aVDev.GetAntialiasing() | ANTIALIASING_PIXELSNAPHAIRLINE);
573 : : }
574 : :
575 [ # # ]: 0 : ImplDraw( &aVDev, aNullPt, aDrawSize );
576 [ # # ][ # # ]: 0 : aRetBmp = aVDev.GetBitmap( aNullPt, aVDev.GetOutputSizePixel() );
[ # # ]
577 [ # # ]: 0 : }
578 : : }
579 : :
580 [ + - ]: 941 : if( !!aRetBmp )
581 : : {
582 [ + - ][ + - ]: 941 : aRetBmp.SetPrefMapMode( ImplGetPrefMapMode() );
[ + - ]
583 [ + - ]: 941 : aRetBmp.SetPrefSize( ImplGetPrefSize() );
584 : : }
585 : :
586 : 941 : return aRetBmp;
587 : : }
588 : :
589 : : // ------------------------------------------------------------------------
590 : :
591 : 248721 : BitmapEx ImpGraphic::ImplGetBitmapEx(const GraphicConversionParameters& rParameters) const
592 : : {
593 : 248721 : BitmapEx aRetBmpEx;
594 : :
595 [ + + ]: 248721 : if( meType == GRAPHIC_BITMAP )
596 : : {
597 [ - + ][ + - ]: 148096 : aRetBmpEx = ( mpAnimation ? mpAnimation->GetBitmapEx() : maEx );
598 : :
599 [ + - ][ - + ]: 148096 : if(rParameters.getSizePixel().Width() || rParameters.getSizePixel().Height())
[ + - ][ + - ]
[ - + ]
600 [ # # ]: 0 : aRetBmpEx.Scale(rParameters.getSizePixel());
601 : : }
602 [ + - ][ - + ]: 100625 : else if( ( meType != GRAPHIC_DEFAULT ) && ImplIsSupportedGraphic() )
[ - + ]
603 : : {
604 [ # # ][ # # ]: 0 : const ImpGraphic aMonoMask( maMetaFile.GetMonochromeMtf( COL_BLACK ) );
[ # # ]
605 [ # # ][ # # ]: 0 : aRetBmpEx = BitmapEx(ImplGetBitmap(rParameters), aMonoMask.ImplGetBitmap(rParameters));
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
606 : : }
607 : :
608 : 248721 : return aRetBmpEx;
609 : : }
610 : :
611 : : // ------------------------------------------------------------------------
612 : :
613 : 0 : Animation ImpGraphic::ImplGetAnimation() const
614 : : {
615 : 0 : Animation aAnimation;
616 : :
617 [ # # ]: 0 : if( mpAnimation )
618 [ # # ]: 0 : aAnimation = *mpAnimation;
619 : :
620 : 0 : return aAnimation;
621 : : }
622 : :
623 : : // ------------------------------------------------------------------------
624 : :
625 : 0 : ::vcl::RenderGraphic ImpGraphic::ImplGetRenderGraphic() const
626 : : {
627 : 0 : ::vcl::RenderGraphic aRet;
628 : :
629 [ # # ][ # # ]: 0 : if( ImplIsRenderGraphic() )
630 [ # # ][ # # ]: 0 : aRet = static_cast< MetaRenderGraphicAction* >( maMetaFile.GetAction( 0 ) )->GetRenderGraphic();
631 : :
632 : 0 : return( aRet );
633 : : }
634 : :
635 : : // ------------------------------------------------------------------------
636 : :
637 : 561 : const GDIMetaFile& ImpGraphic::ImplGetGDIMetaFile() const
638 : : {
639 : 561 : return maMetaFile;
640 : : }
641 : :
642 : : // ------------------------------------------------------------------------
643 : :
644 : 40587 : Size ImpGraphic::ImplGetPrefSize() const
645 : : {
646 : 40587 : Size aSize;
647 : :
648 [ - + ]: 40587 : if( ImplIsSwapOut() )
649 : 0 : aSize = maSwapInfo.maPrefSize;
650 : : else
651 : : {
652 [ + + + ]: 40587 : switch( meType )
653 : : {
654 : : case( GRAPHIC_NONE ):
655 : : case( GRAPHIC_DEFAULT ):
656 : 14248 : break;
657 : :
658 : : case( GRAPHIC_BITMAP ):
659 : : {
660 : 25536 : aSize = maEx.GetPrefSize();
661 : :
662 [ - + ][ + + ]: 25536 : if( !aSize.Width() || !aSize.Height() )
[ + + ]
663 : 2227 : aSize = maEx.GetSizePixel();
664 : : }
665 : 25536 : break;
666 : :
667 : : default:
668 : : {
669 [ + - ]: 803 : if( ImplIsSupportedGraphic() )
670 : 803 : aSize = maMetaFile.GetPrefSize();
671 : : }
672 : 803 : break;
673 : : }
674 : : }
675 : :
676 : 40587 : return aSize;
677 : : }
678 : :
679 : : // ------------------------------------------------------------------------
680 : :
681 : 3231 : void ImpGraphic::ImplSetPrefSize( const Size& rPrefSize )
682 : : {
683 [ + + + ]: 3231 : switch( meType )
684 : : {
685 : : case( GRAPHIC_NONE ):
686 : : case( GRAPHIC_DEFAULT ):
687 : 66 : break;
688 : :
689 : : case( GRAPHIC_BITMAP ):
690 : : // #108077# Push through pref size to animation object,
691 : : // will be lost on copy otherwise
692 [ - + ]: 3066 : if( ImplIsAnimated() )
693 : 0 : const_cast< BitmapEx& >(mpAnimation->GetBitmapEx()).SetPrefSize( rPrefSize );
694 : :
695 : 3066 : maEx.SetPrefSize( rPrefSize );
696 : 3066 : break;
697 : :
698 : : default:
699 : : {
700 [ + - ]: 99 : if( ImplIsSupportedGraphic() )
701 : 99 : maMetaFile.SetPrefSize( rPrefSize );
702 : : }
703 : 99 : break;
704 : : }
705 : 3231 : }
706 : :
707 : : // ------------------------------------------------------------------------
708 : :
709 : 40440 : MapMode ImpGraphic::ImplGetPrefMapMode() const
710 : : {
711 [ + - ]: 40440 : MapMode aMapMode;
712 : :
713 [ - + ]: 40440 : if( ImplIsSwapOut() )
714 [ # # ]: 0 : aMapMode = maSwapInfo.maPrefMapMode;
715 : : else
716 : : {
717 [ + + + ]: 40440 : switch( meType )
718 : : {
719 : : case( GRAPHIC_NONE ):
720 : : case( GRAPHIC_DEFAULT ):
721 : 14248 : break;
722 : :
723 : : case( GRAPHIC_BITMAP ):
724 : : {
725 : 25563 : const Size aSize( maEx.GetPrefSize() );
726 : :
727 [ + - ][ + + ]: 25563 : if ( aSize.Width() && aSize.Height() )
[ + + ]
728 [ + - ]: 23345 : aMapMode = maEx.GetPrefMapMode();
729 : : }
730 : 25563 : break;
731 : :
732 : : default:
733 : : {
734 [ + - ]: 629 : if( ImplIsSupportedGraphic() )
735 [ + - ]: 629 : return maMetaFile.GetPrefMapMode();
736 : : }
737 : 0 : break;
738 : : }
739 : : }
740 : :
741 [ + - ][ + - ]: 40440 : return aMapMode;
742 : : }
743 : :
744 : : // ------------------------------------------------------------------------
745 : :
746 : 3231 : void ImpGraphic::ImplSetPrefMapMode( const MapMode& rPrefMapMode )
747 : : {
748 [ + + + ]: 3231 : switch( meType )
749 : : {
750 : : case( GRAPHIC_NONE ):
751 : : case( GRAPHIC_DEFAULT ):
752 : 66 : break;
753 : :
754 : : case( GRAPHIC_BITMAP ):
755 : : // #108077# Push through pref mapmode to animation object,
756 : : // will be lost on copy otherwise
757 [ - + ]: 3066 : if( ImplIsAnimated() )
758 : 0 : const_cast< BitmapEx& >(mpAnimation->GetBitmapEx()).SetPrefMapMode( rPrefMapMode );
759 : :
760 : 3066 : maEx.SetPrefMapMode( rPrefMapMode );
761 : 3066 : break;
762 : :
763 : : default:
764 : : {
765 [ + - ]: 99 : if( ImplIsSupportedGraphic() )
766 : 99 : maMetaFile.SetPrefMapMode( rPrefMapMode );
767 : : }
768 : 99 : break;
769 : : }
770 : 3231 : }
771 : :
772 : : // ------------------------------------------------------------------------
773 : :
774 : 35204 : sal_uLong ImpGraphic::ImplGetSizeBytes() const
775 : : {
776 [ + + ]: 35204 : if( 0 == mnSizeBytes )
777 : : {
778 [ + + ]: 33641 : if( meType == GRAPHIC_BITMAP )
779 : : {
780 [ - + ]: 19909 : mnSizeBytes = mpAnimation ? mpAnimation->GetSizeBytes() : maEx.GetSizeBytes();
781 : : }
782 [ + + ]: 13732 : else if( meType == GRAPHIC_GDIMETAFILE )
783 : : {
784 : 109 : mnSizeBytes = maMetaFile.GetSizeBytes();
785 : : }
786 : : }
787 : :
788 : 35204 : return( mnSizeBytes );
789 : : }
790 : :
791 : : // ------------------------------------------------------------------------
792 : :
793 : 0 : void ImpGraphic::ImplDraw( OutputDevice* pOutDev, const Point& rDestPt ) const
794 : : {
795 [ # # ][ # # ]: 0 : if( ImplIsSupportedGraphic() && !ImplIsSwapOut() )
[ # # ]
796 : : {
797 [ # # # ]: 0 : switch( meType )
798 : : {
799 : : case( GRAPHIC_DEFAULT ):
800 : 0 : break;
801 : :
802 : : case( GRAPHIC_BITMAP ):
803 : : {
804 [ # # ]: 0 : if ( mpAnimation )
805 : 0 : mpAnimation->Draw( pOutDev, rDestPt );
806 : : else
807 : 0 : maEx.Draw( pOutDev, rDestPt );
808 : : }
809 : 0 : break;
810 : :
811 : : default:
812 : 0 : ImplDraw( pOutDev, rDestPt, maMetaFile.GetPrefSize() );
813 : 0 : break;
814 : : }
815 : : }
816 : 0 : }
817 : :
818 : : // ------------------------------------------------------------------------
819 : :
820 : 315 : void ImpGraphic::ImplDraw( OutputDevice* pOutDev,
821 : : const Point& rDestPt, const Size& rDestSize ) const
822 : : {
823 [ + - ][ + - ]: 315 : if( ImplIsSupportedGraphic() && !ImplIsSwapOut() )
[ + - ]
824 : : {
825 [ - + + ]: 315 : switch( meType )
826 : : {
827 : : case( GRAPHIC_DEFAULT ):
828 : 0 : break;
829 : :
830 : : case( GRAPHIC_BITMAP ):
831 : : {
832 [ - + ]: 25 : if( mpAnimation )
833 : 0 : mpAnimation->Draw( pOutDev, rDestPt, rDestSize );
834 : : else
835 : 25 : maEx.Draw( pOutDev, rDestPt, rDestSize );
836 : : }
837 : 25 : break;
838 : :
839 : : default:
840 : : {
841 : 290 : ( (ImpGraphic*) this )->maMetaFile.WindStart();
842 : 290 : ( (ImpGraphic*) this )->maMetaFile.Play( pOutDev, rDestPt, rDestSize );
843 : 290 : ( (ImpGraphic*) this )->maMetaFile.WindStart();
844 : : }
845 : 315 : break;
846 : : }
847 : : }
848 : 315 : }
849 : :
850 : : // ------------------------------------------------------------------------
851 : :
852 : 0 : void ImpGraphic::ImplStartAnimation( OutputDevice* pOutDev, const Point& rDestPt,
853 : : const Size& rDestSize, long nExtraData,
854 : : OutputDevice* pFirstFrameOutDev )
855 : : {
856 [ # # ][ # # ]: 0 : if( ImplIsSupportedGraphic() && !ImplIsSwapOut() && mpAnimation )
[ # # ][ # # ]
857 : 0 : mpAnimation->Start( pOutDev, rDestPt, rDestSize, nExtraData, pFirstFrameOutDev );
858 : 0 : }
859 : :
860 : : // ------------------------------------------------------------------------
861 : :
862 : 0 : void ImpGraphic::ImplStopAnimation( OutputDevice* pOutDev, long nExtraData )
863 : : {
864 [ # # ][ # # ]: 0 : if( ImplIsSupportedGraphic() && !ImplIsSwapOut() && mpAnimation )
[ # # ][ # # ]
865 : 0 : mpAnimation->Stop( pOutDev, nExtraData );
866 : 0 : }
867 : :
868 : : // ------------------------------------------------------------------------
869 : :
870 : 3198 : void ImpGraphic::ImplSetAnimationNotifyHdl( const Link& rLink )
871 : : {
872 [ - + ]: 3198 : if( mpAnimation )
873 : 0 : mpAnimation->SetNotifyHdl( rLink );
874 : 3198 : }
875 : :
876 : : // ------------------------------------------------------------------------
877 : :
878 : 3621 : Link ImpGraphic::ImplGetAnimationNotifyHdl() const
879 : : {
880 : 3621 : Link aLink;
881 : :
882 [ - + ]: 3621 : if( mpAnimation )
883 : 0 : aLink = mpAnimation->GetNotifyHdl();
884 : :
885 : 3621 : return aLink;
886 : : }
887 : :
888 : : // ------------------------------------------------------------------------
889 : :
890 : 0 : sal_uLong ImpGraphic::ImplGetAnimationLoopCount() const
891 : : {
892 [ # # ]: 0 : return( mpAnimation ? mpAnimation->GetLoopCount() : 0UL );
893 : : }
894 : :
895 : : // ------------------------------------------------------------------------
896 : :
897 : 13578 : GraphicReader* ImpGraphic::ImplGetContext()
898 : : {
899 : 13578 : return mpContext;
900 : : }
901 : :
902 : : // ------------------------------------------------------------------------
903 : :
904 : 78 : void ImpGraphic::ImplSetContext( GraphicReader* pReader )
905 : : {
906 : 78 : mpContext = pReader;
907 : 78 : }
908 : :
909 : : // ------------------------------------------------------------------------
910 : :
911 : 3198 : void ImpGraphic::ImplSetDocFileName( const String& rName, sal_uLong nFilePos )
912 : : {
913 [ + - ][ + - ]: 3198 : const INetURLObject aURL( rName );
914 : :
915 : : DBG_ASSERT( !rName.Len() || ( aURL.GetProtocol() != INET_PROT_NOT_VALID ), "Graphic::SetDocFileName(...): invalid URL" );
916 : :
917 [ + - ][ + - ]: 3198 : maDocFileURLStr = aURL.GetMainURL( INetURLObject::NO_DECODE );
918 [ + - ]: 3198 : mnDocFilePos = nFilePos;
919 : 3198 : }
920 : :
921 : : // ------------------------------------------------------------------------
922 : :
923 : 3621 : const String& ImpGraphic::ImplGetDocFileName() const
924 : : {
925 : 3621 : return maDocFileURLStr;
926 : : }
927 : :
928 : : // ------------------------------------------------------------------------
929 : :
930 : 3621 : sal_uLong ImpGraphic::ImplGetDocFilePos() const
931 : : {
932 : 3621 : return mnDocFilePos;
933 : : }
934 : :
935 : : // ------------------------------------------------------------------------
936 : :
937 : 6 : sal_Bool ImpGraphic::ImplReadEmbedded( SvStream& rIStm, sal_Bool bSwap )
938 : : {
939 [ + - ]: 6 : MapMode aMapMode;
940 : 6 : Size aSize;
941 : 6 : const sal_uLong nStartPos = rIStm.Tell();
942 : : sal_uInt32 nId;
943 : : sal_uLong nHeaderLen;
944 : : //#fdo39428 SvStream no longer supports operator>>(long&)
945 : : sal_Int32 nType;
946 : : sal_Int32 nLen;
947 : 6 : const sal_uInt16 nOldFormat = rIStm.GetNumberFormatInt();
948 : 6 : sal_Bool bRet = sal_False;
949 : :
950 [ - + ]: 6 : if( !mbSwapUnderway )
951 : : {
952 [ # # ]: 0 : const String aTempURLStr( maDocFileURLStr );
953 : 0 : const sal_uLong nTempPos = mnDocFilePos;
954 : :
955 [ # # ]: 0 : ImplClear();
956 : :
957 [ # # ]: 0 : maDocFileURLStr = aTempURLStr;
958 [ # # ]: 0 : mnDocFilePos = nTempPos;
959 : : }
960 : :
961 [ + - ]: 6 : rIStm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
962 [ + - ]: 6 : rIStm >> nId;
963 : :
964 : : // check version
965 [ + - ]: 6 : if( GRAPHIC_FORMAT_50 == nId )
966 : : {
967 : : // read new style header
968 [ + - ][ + - ]: 6 : VersionCompat* pCompat = new VersionCompat( rIStm, STREAM_READ );
969 : :
970 [ + - ]: 6 : rIStm >> nType;
971 [ + - ]: 6 : rIStm >> nLen;
972 [ + - ]: 6 : rIStm >> aSize;
973 [ + - ]: 6 : rIStm >> aMapMode;
974 : :
975 [ + - ][ + - ]: 6 : delete pCompat;
976 : : }
977 : : else
978 : : {
979 : : // read old style header
980 : : //#fdo39428 SvStream no longer supports operator>>(long&)
981 : : sal_Int32 nWidth, nHeight;
982 : : sal_Int32 nMapMode, nScaleNumX, nScaleDenomX;
983 : : sal_Int32 nScaleNumY, nScaleDenomY, nOffsX, nOffsY;
984 : :
985 [ # # ]: 0 : rIStm.SeekRel( -4L );
986 : :
987 [ # # ][ # # ]: 0 : rIStm >> nType >> nLen >> nWidth >> nHeight;
[ # # ][ # # ]
988 [ # # ][ # # ]: 0 : rIStm >> nMapMode >> nScaleNumX >> nScaleDenomX >> nScaleNumY;
[ # # ][ # # ]
989 [ # # ][ # # ]: 0 : rIStm >> nScaleDenomY >> nOffsX >> nOffsY;
[ # # ]
990 : :
991 : : // swapped
992 [ # # ]: 0 : if( nType > 100L )
993 : : {
994 : 0 : nType = OSL_SWAPDWORD( nType );
995 : 0 : nLen = OSL_SWAPDWORD( nLen );
996 : 0 : nWidth = OSL_SWAPDWORD( nWidth );
997 : 0 : nHeight = OSL_SWAPDWORD( nHeight );
998 : 0 : nMapMode = OSL_SWAPDWORD( nMapMode );
999 : 0 : nScaleNumX = OSL_SWAPDWORD( nScaleNumX );
1000 : 0 : nScaleDenomX = OSL_SWAPDWORD( nScaleDenomX );
1001 : 0 : nScaleNumY = OSL_SWAPDWORD( nScaleNumY );
1002 : 0 : nScaleDenomY = OSL_SWAPDWORD( nScaleDenomY );
1003 : 0 : nOffsX = OSL_SWAPDWORD( nOffsX );
1004 : 0 : nOffsY = OSL_SWAPDWORD( nOffsY );
1005 : : }
1006 : :
1007 : 0 : aSize = Size( nWidth, nHeight );
1008 : : aMapMode = MapMode( (MapUnit) nMapMode, Point( nOffsX, nOffsY ),
1009 : : Fraction( nScaleNumX, nScaleDenomX ),
1010 [ # # ][ # # ]: 0 : Fraction( nScaleNumY, nScaleDenomY ) );
[ # # ][ # # ]
[ # # ]
1011 : : }
1012 : :
1013 : 6 : nHeaderLen = rIStm.Tell() - nStartPos;
1014 : 6 : meType = (GraphicType) nType;
1015 : :
1016 [ + - ]: 6 : if( meType )
1017 : : {
1018 [ + - ]: 6 : if( meType == GRAPHIC_BITMAP )
1019 : : {
1020 : 6 : maEx.aBitmapSize = aSize;
1021 : :
1022 [ + - ][ + - ]: 6 : if( aMapMode != MapMode() )
[ + - ][ - + ]
1023 : : {
1024 [ # # ]: 0 : maEx.SetPrefMapMode( aMapMode );
1025 : 0 : maEx.SetPrefSize( aSize );
1026 : : }
1027 : : }
1028 : : else
1029 : : {
1030 [ # # ]: 0 : maMetaFile.SetPrefMapMode( aMapMode );
1031 : 0 : maMetaFile.SetPrefSize( aSize );
1032 : : }
1033 : :
1034 [ - + ]: 6 : if( bSwap )
1035 : : {
1036 [ # # ]: 0 : if( maDocFileURLStr.Len() )
1037 : : {
1038 [ # # ]: 0 : rIStm.Seek( nStartPos + nHeaderLen + nLen );
1039 : 0 : bRet = mbSwapOut = sal_True;
1040 : : }
1041 : : else
1042 : : {
1043 [ # # ]: 0 : ::utl::TempFile aTempFile;
1044 [ # # ][ # # ]: 0 : const INetURLObject aTmpURL( aTempFile.GetURL() );
[ # # ][ # # ]
1045 : :
1046 [ # # ][ # # ]: 0 : if( !aTmpURL.GetMainURL( INetURLObject::NO_DECODE ).isEmpty() )
1047 : : {
1048 : 0 : SvStream* pOStm = NULL;
1049 : : try
1050 : : {
1051 [ # # ][ # # ]: 0 : pOStm = ::utl::UcbStreamHelper::CreateStream( aTmpURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READWRITE | STREAM_SHARE_DENYWRITE );
[ # # ][ # # ]
[ # # ]
1052 : : }
1053 [ # # ]: 0 : catch( const ::com::sun::star::uno::Exception& )
1054 : : {
1055 : : }
1056 : :
1057 [ # # ]: 0 : if( pOStm )
1058 : : {
1059 : 0 : sal_uLong nFullLen = nHeaderLen + nLen;
1060 : 0 : sal_uLong nPartLen = Min( nFullLen, (sal_uLong) GRAPHIC_MAXPARTLEN );
1061 : 0 : sal_uInt8* pBuffer = (sal_uInt8*) rtl_allocateMemory( nPartLen );
1062 : :
1063 [ # # ]: 0 : pOStm->SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
1064 : :
1065 [ # # ]: 0 : if( pBuffer )
1066 : : {
1067 [ # # ]: 0 : rIStm.Seek( nStartPos );
1068 : :
1069 [ # # ]: 0 : while( nFullLen )
1070 : : {
1071 [ # # ]: 0 : rIStm.Read( (char*) pBuffer, nPartLen );
1072 [ # # ]: 0 : pOStm->Write( (char*) pBuffer, nPartLen );
1073 : :
1074 : 0 : nFullLen -= nPartLen;
1075 : :
1076 [ # # ]: 0 : if( nFullLen < GRAPHIC_MAXPARTLEN )
1077 : 0 : nPartLen = nFullLen;
1078 : : }
1079 : :
1080 : 0 : rtl_freeMemory( pBuffer );
1081 : 0 : sal_uLong nReadErr = rIStm.GetError(), nWriteErr = pOStm->GetError();
1082 [ # # ][ # # ]: 0 : delete pOStm, pOStm = NULL;
1083 : :
1084 [ # # ][ # # ]: 0 : if( !nReadErr && !nWriteErr )
1085 : : {
1086 : 0 : bRet = mbSwapOut = sal_True;
1087 [ # # ][ # # ]: 0 : mpSwapFile = new ImpSwapFile;
1088 : 0 : mpSwapFile->nRefCount = 1;
1089 [ # # ]: 0 : mpSwapFile->aSwapURL = aTmpURL;
1090 : : }
1091 : : else
1092 : : {
1093 : : try
1094 : : {
1095 : : ::ucbhelper::Content aCnt( aTmpURL.GetMainURL( INetURLObject::NO_DECODE ),
1096 [ # # ][ # # ]: 0 : ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >() );
1097 : :
1098 : : aCnt.executeCommand( ::rtl::OUString("delete"),
1099 [ # # ][ # # ]: 0 : ::com::sun::star::uno::makeAny( sal_Bool( sal_True ) ) );
[ # # # #
# ][ # # ]
1100 : : }
1101 [ # # ]: 0 : catch( const ::com::sun::star::ucb::ContentCreationException& )
1102 : : {
1103 : : }
1104 [ # # ]: 0 : catch( const ::com::sun::star::uno::RuntimeException& )
1105 : : {
1106 : : }
1107 [ # # ]: 0 : catch( const ::com::sun::star::ucb::CommandAbortedException& )
1108 : : {
1109 : : }
1110 [ # # ]: 0 : catch( const ::com::sun::star::uno::Exception& )
1111 : : {
1112 : : }
1113 : : }
1114 : : }
1115 : :
1116 [ # # ][ # # ]: 0 : delete pOStm;
1117 : : }
1118 [ # # ][ # # ]: 0 : }
1119 : : }
1120 : : }
1121 [ - + ][ # # ]: 6 : else if( meType == GRAPHIC_BITMAP || meType == GRAPHIC_GDIMETAFILE )
1122 : : {
1123 [ + - ]: 6 : rIStm >> *this;
1124 : 6 : bRet = ( rIStm.GetError() == 0UL );
1125 : : }
1126 [ # # ][ # # ]: 0 : else if( meType >= SYS_WINMETAFILE && meType <= SYS_MACMETAFILE )
1127 : : {
1128 [ # # ]: 0 : Graphic aSysGraphic;
1129 : : sal_uLong nCvtType;
1130 : :
1131 [ # # # # ]: 0 : switch( sal::static_int_cast<sal_uLong>(meType) )
1132 : : {
1133 : : case( SYS_WINMETAFILE ):
1134 : 0 : case( SYS_WNTMETAFILE ): nCvtType = CVT_WMF; break;
1135 : 0 : case( SYS_OS2METAFILE ): nCvtType = CVT_MET; break;
1136 : 0 : case( SYS_MACMETAFILE ): nCvtType = CVT_PCT; break;
1137 : :
1138 : : default:
1139 : 0 : nCvtType = CVT_UNKNOWN;
1140 : 0 : break;
1141 : : }
1142 : :
1143 [ # # ][ # # ]: 0 : if( nType && GraphicConverter::Import( rIStm, aSysGraphic, nCvtType ) == ERRCODE_NONE )
[ # # ][ # # ]
1144 : : {
1145 [ # # ][ # # ]: 0 : *this = ImpGraphic( aSysGraphic.GetGDIMetaFile() );
[ # # ][ # # ]
1146 : 0 : bRet = ( rIStm.GetError() == 0UL );
1147 : : }
1148 : : else
1149 [ # # ]: 0 : meType = GRAPHIC_DEFAULT;
1150 : : }
1151 : :
1152 [ + - ]: 6 : if( bRet )
1153 : : {
1154 [ + - ]: 6 : ImplSetPrefMapMode( aMapMode );
1155 : 6 : ImplSetPrefSize( aSize );
1156 : : }
1157 : : }
1158 : : else
1159 : 0 : bRet = sal_True;
1160 : :
1161 [ + - ]: 6 : rIStm.SetNumberFormatInt( nOldFormat );
1162 : :
1163 [ + - ]: 6 : return bRet;
1164 : : }
1165 : :
1166 : : // ------------------------------------------------------------------------
1167 : :
1168 : 15 : sal_Bool ImpGraphic::ImplWriteEmbedded( SvStream& rOStm )
1169 : : {
1170 : 15 : sal_Bool bRet = sal_False;
1171 : :
1172 [ + - ][ + - ]: 15 : if( ( meType != GRAPHIC_NONE ) && ( meType != GRAPHIC_DEFAULT ) && !ImplIsSwapOut() )
[ + - ][ + - ]
1173 : : {
1174 [ + - ]: 15 : const MapMode aMapMode( ImplGetPrefMapMode() );
1175 [ + - ]: 15 : const Size aSize( ImplGetPrefSize() );
1176 : 15 : const sal_uInt16 nOldFormat = rOStm.GetNumberFormatInt();
1177 : : sal_uLong nDataFieldPos;
1178 : :
1179 [ + - ]: 15 : rOStm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
1180 : :
1181 : : // write correct version ( old style/new style header )
1182 [ + - ]: 15 : if( rOStm.GetVersion() >= SOFFICE_FILEFORMAT_50 )
1183 : : {
1184 : : // write ID for new format (5.0)
1185 [ + - ]: 15 : rOStm << GRAPHIC_FORMAT_50;
1186 : :
1187 : : // write new style header
1188 [ + - ][ + - ]: 15 : VersionCompat* pCompat = new VersionCompat( rOStm, STREAM_WRITE, 1 );
1189 : :
1190 : : //#fdo39428 SvStream no longer supports operator<<(long)
1191 [ + - ]: 15 : rOStm << sal::static_int_cast<sal_Int32>(meType);
1192 : :
1193 : : // data size is updated later
1194 : 15 : nDataFieldPos = rOStm.Tell();
1195 [ + - ]: 15 : rOStm << (sal_Int32) 0;
1196 : :
1197 [ + - ]: 15 : rOStm << aSize;
1198 [ + - ]: 15 : rOStm << aMapMode;
1199 : :
1200 [ + - ][ + - ]: 15 : delete pCompat;
1201 : : }
1202 : : else
1203 : : {
1204 : : // write old style (<=4.0) header
1205 [ # # ]: 0 : rOStm << (sal_Int32) meType;
1206 : :
1207 : : // data size is updated later
1208 : 0 : nDataFieldPos = rOStm.Tell();
1209 [ # # ]: 0 : rOStm << (sal_Int32) 0;
1210 : : //#fdo39428 SvStream no longer supports operator<<(long)
1211 [ # # ]: 0 : rOStm << sal::static_int_cast<sal_Int32>(aSize.Width());
1212 [ # # ]: 0 : rOStm << sal::static_int_cast<sal_Int32>(aSize.Height());
1213 [ # # ]: 0 : rOStm << sal::static_int_cast<sal_Int32>(aMapMode.GetMapUnit());
1214 [ # # ]: 0 : rOStm << sal::static_int_cast<sal_Int32>(aMapMode.GetScaleX().GetNumerator());
1215 [ # # ]: 0 : rOStm << sal::static_int_cast<sal_Int32>(aMapMode.GetScaleX().GetDenominator());
1216 [ # # ]: 0 : rOStm << sal::static_int_cast<sal_Int32>(aMapMode.GetScaleY().GetNumerator());
1217 [ # # ]: 0 : rOStm << sal::static_int_cast<sal_Int32>(aMapMode.GetScaleY().GetDenominator());
1218 [ # # ]: 0 : rOStm << sal::static_int_cast<sal_Int32>(aMapMode.GetOrigin().X());
1219 [ # # ]: 0 : rOStm << sal::static_int_cast<sal_Int32>(aMapMode.GetOrigin().Y());
1220 : : }
1221 : :
1222 : : // write data block
1223 [ + - ]: 15 : if( !rOStm.GetError() )
1224 : : {
1225 : 15 : const sal_uLong nDataStart = rOStm.Tell();
1226 : :
1227 [ + - ]: 15 : if( ImplIsSupportedGraphic() )
1228 [ + - ]: 15 : rOStm << *this;
1229 : :
1230 [ + - ]: 15 : if( !rOStm.GetError() )
1231 : : {
1232 : 15 : const sal_uLong nStmPos2 = rOStm.Tell();
1233 [ + - ]: 15 : rOStm.Seek( nDataFieldPos );
1234 : : //fdo39428 SvStream no longer supports operator<<(long)
1235 [ + - ]: 15 : rOStm << sal::static_int_cast<sal_Int32>(nStmPos2 - nDataStart);
1236 [ + - ]: 15 : rOStm.Seek( nStmPos2 );
1237 : 15 : bRet = sal_True;
1238 : : }
1239 : : }
1240 : :
1241 [ + - ][ + - ]: 15 : rOStm.SetNumberFormatInt( nOldFormat );
1242 : : }
1243 : :
1244 : 15 : return bRet;
1245 : : }
1246 : :
1247 : : // ------------------------------------------------------------------------
1248 : :
1249 : 15 : sal_Bool ImpGraphic::ImplSwapOut()
1250 : : {
1251 : 15 : sal_Bool bRet = sal_False;
1252 : :
1253 [ + - ]: 15 : if( !ImplIsSwapOut() )
1254 : : {
1255 [ + - ]: 15 : if( !maDocFileURLStr.Len() )
1256 : : {
1257 [ + - ]: 15 : ::utl::TempFile aTempFile;
1258 [ + - ][ + - ]: 15 : const INetURLObject aTmpURL( aTempFile.GetURL() );
[ + - ][ + - ]
1259 : :
1260 [ + - ][ + - ]: 15 : if( !aTmpURL.GetMainURL( INetURLObject::NO_DECODE ).isEmpty() )
1261 : : {
1262 : 15 : SvStream* pOStm = NULL;
1263 : : try
1264 : : {
1265 [ + - ][ + - ]: 15 : pOStm = ::utl::UcbStreamHelper::CreateStream( aTmpURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READWRITE | STREAM_SHARE_DENYWRITE );
[ + - ][ + - ]
[ # # ]
1266 : : }
1267 [ # # ]: 0 : catch( const ::com::sun::star::uno::Exception& )
1268 : : {
1269 : : }
1270 [ + - ]: 15 : if( pOStm )
1271 : : {
1272 : 15 : pOStm->SetVersion( SOFFICE_FILEFORMAT_50 );
1273 : 15 : pOStm->SetCompressMode( COMPRESSMODE_NATIVE );
1274 : :
1275 [ + - ][ + - ]: 15 : if( ( bRet = ImplSwapOut( pOStm ) ) == sal_True )
1276 : : {
1277 [ + - ][ + - ]: 15 : mpSwapFile = new ImpSwapFile;
1278 : 15 : mpSwapFile->nRefCount = 1;
1279 [ + - ]: 15 : mpSwapFile->aSwapURL = aTmpURL;
1280 : : }
1281 : : else
1282 : : {
1283 [ # # ][ # # ]: 0 : delete pOStm, pOStm = NULL;
1284 : :
1285 : : try
1286 : : {
1287 : : ::ucbhelper::Content aCnt( aTmpURL.GetMainURL( INetURLObject::NO_DECODE ),
1288 [ # # ][ # # ]: 0 : ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >() );
1289 : :
1290 : : aCnt.executeCommand( ::rtl::OUString("delete"),
1291 [ # # ][ # # ]: 0 : ::com::sun::star::uno::makeAny( sal_Bool( sal_True ) ) );
[ # # # #
# ][ # # ]
1292 : : }
1293 [ # # ]: 0 : catch( const ::com::sun::star::ucb::ContentCreationException& )
1294 : : {
1295 : : }
1296 [ # # ]: 0 : catch( const ::com::sun::star::uno::RuntimeException& )
1297 : : {
1298 : : }
1299 [ # # ]: 0 : catch( const ::com::sun::star::ucb::CommandAbortedException& )
1300 : : {
1301 : : }
1302 [ # # ]: 0 : catch( const ::com::sun::star::uno::Exception& )
1303 : : {
1304 : : }
1305 : : }
1306 : :
1307 [ + - ][ + - ]: 15 : delete pOStm;
1308 : : }
1309 [ + - ][ + - ]: 15 : }
1310 : : }
1311 : : else
1312 : : {
1313 : 0 : ImplClearGraphics( sal_True );
1314 : 0 : bRet = mbSwapOut = sal_True;
1315 : : }
1316 : : }
1317 : :
1318 : 15 : return bRet;
1319 : : }
1320 : :
1321 : : // ------------------------------------------------------------------------
1322 : :
1323 : 15 : sal_Bool ImpGraphic::ImplSwapOut( SvStream* pOStm )
1324 : : {
1325 : 15 : sal_Bool bRet = sal_False;
1326 : :
1327 [ + - ]: 15 : if( pOStm )
1328 : : {
1329 : 15 : pOStm->SetBufferSize( GRAPHIC_STREAMBUFSIZE );
1330 : :
1331 [ + - ][ + - ]: 15 : if( !pOStm->GetError() && ImplWriteEmbedded( *pOStm ) )
[ + - ]
1332 : : {
1333 : 15 : pOStm->Flush();
1334 : :
1335 [ + - ]: 15 : if( !pOStm->GetError() )
1336 : : {
1337 : 15 : ImplClearGraphics( sal_True );
1338 : 15 : bRet = mbSwapOut = sal_True;
1339 : : }
1340 : : }
1341 : : }
1342 : : else
1343 : : {
1344 : 0 : ImplClearGraphics( sal_True );
1345 : 0 : bRet = mbSwapOut = sal_True;
1346 : : }
1347 : :
1348 : 15 : return bRet;
1349 : : }
1350 : :
1351 : : // ------------------------------------------------------------------------
1352 : :
1353 : 8 : sal_Bool ImpGraphic::ImplSwapIn()
1354 : : {
1355 : 8 : sal_Bool bRet = sal_False;
1356 : :
1357 [ + + ]: 8 : if( ImplIsSwapOut() )
1358 : : {
1359 [ + - ]: 6 : String aSwapURL;
1360 : :
1361 [ + - ]: 6 : if( mpSwapFile )
1362 [ + - ][ + - ]: 6 : aSwapURL = mpSwapFile->aSwapURL.GetMainURL( INetURLObject::NO_DECODE );
[ # # ]
1363 : : else
1364 [ # # ]: 0 : aSwapURL = maDocFileURLStr;
1365 : :
1366 [ + - ]: 6 : if( aSwapURL.Len() )
1367 : : {
1368 : 6 : SvStream* pIStm = NULL;
1369 : : try
1370 : : {
1371 [ + - ]: 6 : pIStm = ::utl::UcbStreamHelper::CreateStream( aSwapURL, STREAM_READWRITE | STREAM_SHARE_DENYWRITE );
1372 : : }
1373 [ # # ]: 0 : catch( const ::com::sun::star::uno::Exception& )
1374 : : {
1375 : : }
1376 : :
1377 [ + - ]: 6 : if( pIStm )
1378 : : {
1379 : 6 : pIStm->SetVersion( SOFFICE_FILEFORMAT_50 );
1380 : 6 : pIStm->SetCompressMode( COMPRESSMODE_NATIVE );
1381 : :
1382 [ - + ]: 6 : if( !mpSwapFile )
1383 [ # # ]: 0 : pIStm->Seek( mnDocFilePos );
1384 : :
1385 [ + - ]: 6 : bRet = ImplSwapIn( pIStm );
1386 [ + - ][ + - ]: 6 : delete pIStm;
1387 : :
1388 [ + - ]: 6 : if( mpSwapFile )
1389 : : {
1390 [ - + ]: 6 : if( mpSwapFile->nRefCount > 1 )
1391 : 0 : mpSwapFile->nRefCount--;
1392 : : else
1393 : : {
1394 : : try
1395 : : {
1396 : : ::ucbhelper::Content aCnt( aSwapURL,
1397 [ + - ][ + - ]: 6 : ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >() );
1398 : :
1399 : : aCnt.executeCommand( ::rtl::OUString("delete"),
1400 [ + - ][ + - ]: 6 : ::com::sun::star::uno::makeAny( sal_Bool( sal_True ) ) );
[ # # # #
# ][ + - ]
1401 : : }
1402 [ # # ]: 0 : catch( const ::com::sun::star::ucb::ContentCreationException& )
1403 : : {
1404 : : }
1405 [ # # ]: 0 : catch( const ::com::sun::star::uno::RuntimeException& )
1406 : : {
1407 : : }
1408 [ # # ]: 0 : catch( const ::com::sun::star::ucb::CommandAbortedException& )
1409 : : {
1410 : : }
1411 [ # # ]: 0 : catch( const ::com::sun::star::uno::Exception& )
1412 : : {
1413 : : }
1414 : :
1415 [ + - ][ + - ]: 6 : delete mpSwapFile;
1416 : : }
1417 : :
1418 : 6 : mpSwapFile = NULL;
1419 : : }
1420 : : }
1421 [ + - ]: 6 : }
1422 : : }
1423 : :
1424 : 8 : return bRet;
1425 : : }
1426 : :
1427 : : // ------------------------------------------------------------------------
1428 : :
1429 : 6 : sal_Bool ImpGraphic::ImplSwapIn( SvStream* pIStm )
1430 : : {
1431 : 6 : sal_Bool bRet = sal_False;
1432 : :
1433 [ + - ]: 6 : if( pIStm )
1434 : : {
1435 : 6 : pIStm->SetBufferSize( GRAPHIC_STREAMBUFSIZE );
1436 : :
1437 [ + - ]: 6 : if( !pIStm->GetError() )
1438 : : {
1439 : 6 : mbSwapUnderway = sal_True;
1440 : 6 : bRet = ImplReadEmbedded( *pIStm );
1441 : 6 : mbSwapUnderway = sal_False;
1442 : :
1443 [ - + ]: 6 : if( !bRet )
1444 : 0 : ImplClear();
1445 : : else
1446 : 6 : mbSwapOut = sal_False;
1447 : : }
1448 : : }
1449 : :
1450 : 6 : return bRet;
1451 : : }
1452 : :
1453 : : // ------------------------------------------------------------------------
1454 : :
1455 : 221433 : sal_Bool ImpGraphic::ImplIsSwapOut() const
1456 : : {
1457 : 221433 : return mbSwapOut;
1458 : : }
1459 : :
1460 : : // ------------------------------------------------------------------------
1461 : :
1462 : 3459 : void ImpGraphic::ImplSetLink( const GfxLink& rGfxLink )
1463 : : {
1464 [ - + ]: 3459 : delete mpGfxLink;
1465 [ + - ]: 3459 : mpGfxLink = new GfxLink( rGfxLink );
1466 : :
1467 [ + + ]: 3459 : if( mpGfxLink->IsNative() )
1468 : 3437 : mpGfxLink->SwapOut();
1469 : 3459 : }
1470 : :
1471 : : // ------------------------------------------------------------------------
1472 : :
1473 : 274 : GfxLink ImpGraphic::ImplGetLink()
1474 : : {
1475 [ + - ]: 274 : return( mpGfxLink ? *mpGfxLink : GfxLink() );
1476 : : }
1477 : :
1478 : : // ------------------------------------------------------------------------
1479 : :
1480 : 43923 : sal_Bool ImpGraphic::ImplIsLink() const
1481 : : {
1482 [ + + ]: 43923 : return ( mpGfxLink != NULL ) ? sal_True : sal_False;
1483 : : }
1484 : :
1485 : : // ------------------------------------------------------------------------
1486 : :
1487 : 36296 : sal_uLong ImpGraphic::ImplGetChecksum() const
1488 : : {
1489 : 36296 : sal_uLong nRet = 0;
1490 : :
1491 [ + - ][ + - ]: 36296 : if( ImplIsSupportedGraphic() && !ImplIsSwapOut() )
[ + - ]
1492 : : {
1493 [ - + + ]: 36296 : switch( meType )
1494 : : {
1495 : : case( GRAPHIC_DEFAULT ):
1496 : 0 : break;
1497 : :
1498 : : case( GRAPHIC_BITMAP ):
1499 : : {
1500 [ - + ]: 36084 : if( mpAnimation )
1501 : 0 : nRet = mpAnimation->GetChecksum();
1502 : : else
1503 : 36084 : nRet = maEx.GetChecksum();
1504 : : }
1505 : 36084 : break;
1506 : :
1507 : : default:
1508 : 212 : nRet = maMetaFile.GetChecksum();
1509 : 36296 : break;
1510 : : }
1511 : : }
1512 : :
1513 : 36296 : return nRet;
1514 : : }
1515 : :
1516 : : // ------------------------------------------------------------------------
1517 : :
1518 : 435 : sal_Bool ImpGraphic::ImplExportNative( SvStream& rOStm ) const
1519 : : {
1520 : 435 : sal_Bool bResult = sal_False;
1521 : :
1522 [ + - ]: 435 : if( !rOStm.GetError() )
1523 : : {
1524 [ + - ]: 435 : if( !ImplIsSwapOut() )
1525 : : {
1526 [ + + ][ + - ]: 435 : if( mpGfxLink && mpGfxLink->IsNative() )
[ + + ]
1527 : 9 : bResult = mpGfxLink->ExportNative( rOStm );
1528 : : else
1529 : : {
1530 : 426 : rOStm << *this;
1531 : 426 : bResult = ( rOStm.GetError() == ERRCODE_NONE );
1532 : : }
1533 : : }
1534 : : else
1535 : 0 : rOStm.SetError( SVSTREAM_GENERALERROR );
1536 : : }
1537 : :
1538 : 435 : return bResult;
1539 : : }
1540 : :
1541 : : // ------------------------------------------------------------------------
1542 : :
1543 : 6939 : SvStream& operator>>( SvStream& rIStm, ImpGraphic& rImpGraphic )
1544 : : {
1545 [ + - ]: 6939 : if( !rIStm.GetError() )
1546 : : {
1547 : 6939 : const sal_uLong nStmPos1 = rIStm.Tell();
1548 : : sal_uInt32 nTmp;
1549 : :
1550 [ + + ]: 6939 : if ( !rImpGraphic.mbSwapUnderway )
1551 [ + - ]: 6933 : rImpGraphic.ImplClear();
1552 : :
1553 : : // read Id
1554 [ + - ]: 6939 : rIStm >> nTmp;
1555 : :
1556 : : // if there is no more data, avoid further expensive
1557 : : // reading which will create VDevs and other stuff, just to
1558 : : // read nothing. CAUTION: Eof is only true AFTER reading another
1559 : : // byte, a speciality of SvMemoryStream (!)
1560 [ + - ][ + + ]: 6939 : if(!rIStm.GetError() && !rIStm.IsEof())
[ + + ]
1561 : : {
1562 [ + + ]: 6911 : if( NATIVE_FORMAT_50 == nTmp )
1563 : : {
1564 [ + - ]: 6 : Graphic aGraphic;
1565 [ + - ]: 6 : GfxLink aLink;
1566 : : VersionCompat* pCompat;
1567 : :
1568 : : // read compat info
1569 [ + - ][ + - ]: 6 : pCompat = new VersionCompat( rIStm, STREAM_READ );
1570 [ + - ][ + - ]: 6 : delete pCompat;
1571 : :
1572 [ + - ]: 6 : rIStm >> aLink;
1573 : :
1574 : : // set dummy link to avoid creation of additional link after filtering;
1575 : : // we set a default link to avoid unnecessary swapping of native data
1576 [ + - ][ + - ]: 6 : aGraphic.SetLink( GfxLink() );
[ + - ]
1577 : :
1578 [ + - ][ + - ]: 6 : if( !rIStm.GetError() && aLink.LoadNative( aGraphic ) )
[ + - ][ + - ]
1579 : : {
1580 : : // set link only, if no other link was set
1581 : 6 : const sal_Bool bSetLink = ( rImpGraphic.mpGfxLink == NULL );
1582 : :
1583 : : // assign graphic
1584 [ + - ]: 6 : rImpGraphic = *aGraphic.ImplGetImpGraphic();
1585 : :
1586 [ + - ][ + - ]: 6 : if( aLink.IsPrefMapModeValid() )
1587 [ + - ][ + - ]: 6 : rImpGraphic.ImplSetPrefMapMode( aLink.GetPrefMapMode() );
1588 : :
1589 [ + - ][ + - ]: 6 : if( aLink.IsPrefSizeValid() )
1590 [ + - ]: 6 : rImpGraphic.ImplSetPrefSize( aLink.GetPrefSize() );
1591 : :
1592 [ + - ]: 6 : if( bSetLink )
1593 [ + - ]: 6 : rImpGraphic.ImplSetLink( aLink );
1594 : : }
1595 : : else
1596 : : {
1597 [ # # ]: 0 : rIStm.Seek( nStmPos1 );
1598 [ # # ]: 0 : rIStm.SetError( ERRCODE_IO_WRONGFORMAT );
1599 [ + - ][ + - ]: 6 : }
1600 : : }
1601 : : else
1602 : : {
1603 [ + - ]: 6905 : BitmapEx aBmpEx;
1604 : 6905 : const sal_uInt16 nOldFormat = rIStm.GetNumberFormatInt();
1605 : :
1606 [ + - ]: 6905 : rIStm.SeekRel( -4 );
1607 [ + - ]: 6905 : rIStm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
1608 [ + - ]: 6905 : rIStm >> aBmpEx;
1609 : :
1610 [ - + ]: 6905 : if( !rIStm.GetError() )
1611 : : {
1612 : 0 : sal_uInt32 nMagic1(0), nMagic2(0);
1613 : 0 : sal_uLong nActPos = rIStm.Tell();
1614 : :
1615 [ # # ][ # # ]: 0 : rIStm >> nMagic1 >> nMagic2;
1616 [ # # ]: 0 : rIStm.Seek( nActPos );
1617 : :
1618 [ # # ][ # # ]: 0 : rImpGraphic = ImpGraphic( aBmpEx );
[ # # ]
1619 : :
1620 [ # # ][ # # ]: 0 : if( !rIStm.GetError() && ( 0x5344414e == nMagic1 ) && ( 0x494d4931 == nMagic2 ) )
[ # # ][ # # ]
1621 : : {
1622 [ # # ][ # # ]: 0 : delete rImpGraphic.mpAnimation;
1623 [ # # ][ # # ]: 0 : rImpGraphic.mpAnimation = new Animation;
1624 [ # # ]: 0 : rIStm >> *rImpGraphic.mpAnimation;
1625 : :
1626 : : // #108077# manually set loaded BmpEx to Animation
1627 : : // (which skips loading its BmpEx if already done)
1628 [ # # ]: 0 : rImpGraphic.mpAnimation->SetBitmapEx(aBmpEx);
1629 : : }
1630 : : else
1631 [ # # ]: 0 : rIStm.ResetError();
1632 : : }
1633 : : else
1634 : : {
1635 [ + - ]: 6905 : GDIMetaFile aMtf;
1636 : :
1637 [ + - ]: 6905 : rIStm.Seek( nStmPos1 );
1638 [ + - ]: 6905 : rIStm.ResetError();
1639 [ + - ]: 6905 : rIStm >> aMtf;
1640 : :
1641 [ + - ]: 6905 : if( !rIStm.GetError() )
1642 [ + - ][ + - ]: 6905 : rImpGraphic = aMtf;
[ + - ]
1643 : : else
1644 [ # # ][ + - ]: 6905 : rIStm.Seek( nStmPos1 );
1645 : : }
1646 : :
1647 [ + - ][ + - ]: 6939 : rIStm.SetNumberFormatInt( nOldFormat );
1648 : : }
1649 : : }
1650 : : }
1651 : :
1652 : 6939 : return rIStm;
1653 : : }
1654 : :
1655 : : // ------------------------------------------------------------------------
1656 : :
1657 : 1648 : SvStream& operator<<( SvStream& rOStm, const ImpGraphic& rImpGraphic )
1658 : : {
1659 [ + - ]: 1648 : if( !rOStm.GetError() )
1660 : : {
1661 [ + - ]: 1648 : if( !rImpGraphic.ImplIsSwapOut() )
1662 : : {
1663 [ + + + + ]: 2116 : if( ( rOStm.GetVersion() >= SOFFICE_FILEFORMAT_50 ) &&
[ + - + - ]
[ + + ]
1664 : 453 : ( rOStm.GetCompressMode() & COMPRESSMODE_NATIVE ) &&
1665 : 15 : rImpGraphic.mpGfxLink && rImpGraphic.mpGfxLink->IsNative() )
1666 : : {
1667 : : VersionCompat* pCompat;
1668 : :
1669 : : // native format
1670 : 15 : rOStm << NATIVE_FORMAT_50;
1671 : :
1672 : : // write compat info
1673 [ + - ]: 15 : pCompat = new VersionCompat( rOStm, STREAM_WRITE, 1 );
1674 [ + - ]: 15 : delete pCompat;
1675 : :
1676 [ + - ]: 15 : rImpGraphic.mpGfxLink->SetPrefMapMode( rImpGraphic.ImplGetPrefMapMode() );
1677 [ + - ]: 15 : rImpGraphic.mpGfxLink->SetPrefSize( rImpGraphic.ImplGetPrefSize() );
1678 : 15 : rOStm << *rImpGraphic.mpGfxLink;
1679 : : }
1680 : : else
1681 : : {
1682 : : // own format
1683 : 1633 : const sal_uInt16 nOldFormat = rOStm.GetNumberFormatInt();
1684 : 1633 : rOStm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
1685 : :
1686 [ + - + ]: 1633 : switch( rImpGraphic.ImplGetType() )
1687 : : {
1688 : : case( GRAPHIC_NONE ):
1689 : : case( GRAPHIC_DEFAULT ):
1690 : 1207 : break;
1691 : :
1692 : : case GRAPHIC_BITMAP:
1693 : : {
1694 [ # # ]: 0 : if ( rImpGraphic.ImplIsAnimated() )
1695 : 0 : rOStm << *rImpGraphic.mpAnimation;
1696 : : else
1697 : 0 : rOStm << rImpGraphic.maEx;
1698 : : }
1699 : 0 : break;
1700 : :
1701 : : default:
1702 : : {
1703 [ + - ]: 426 : if( rImpGraphic.ImplIsSupportedGraphic() )
1704 : 426 : rOStm << rImpGraphic.maMetaFile;
1705 : : }
1706 : 426 : break;
1707 : : }
1708 : :
1709 : 1633 : rOStm.SetNumberFormatInt( nOldFormat );
1710 : : }
1711 : : }
1712 : : else
1713 : 0 : rOStm.SetError( SVSTREAM_GENERALERROR );
1714 : : }
1715 : :
1716 : 1648 : return rOStm;
1717 : : }
1718 : :
1719 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|