1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
23 #include <vcl/graph.hxx>
24 #include <svtools/svtdllapi.h>
26 #define GRFMGR_DRAW_NOTCACHED 0x00000000UL
27 #define GRFMGR_DRAW_CACHED 0x00000001UL
28 #define GRFMGR_DRAW_SMOOTHSCALE 0x00000002UL
29 #define GRFMGR_DRAW_USE_DRAWMODE_SETTINGS 0x00000004UL
30 #define GRFMGR_DRAW_SUBSTITUTE 0x00000008UL
31 #define GRFMGR_DRAW_NO_SUBSTITUTE 0x00000010UL
32 #define GRFMGR_DRAW_STANDARD (GRFMGR_DRAW_CACHED|GRFMGR_DRAW_SMOOTHSCALE)
36 #define GRFMGR_AUTOSWAPSTREAM_LINK ((SvStream*)0x00000000UL)
37 #define GRFMGR_AUTOSWAPSTREAM_LOADED ((SvStream*)0xfffffffdUL)
38 #define GRFMGR_AUTOSWAPSTREAM_TEMP ((SvStream*)0xfffffffeUL)
39 #define GRFMGR_AUTOSWAPSTREAM_NONE ((SvStream*)0xffffffffUL)
43 #define ADJUSTMENT_NONE 0x00000000UL
44 #define ADJUSTMENT_DRAWMODE 0x00000001UL
45 #define ADJUSTMENT_COLORS 0x00000002UL
46 #define ADJUSTMENT_MIRROR 0x00000004UL
47 #define ADJUSTMENT_ROTATE 0x00000008UL
48 #define ADJUSTMENT_TRANSPARENCY 0x00000010UL
49 #define ADJUSTMENT_ALL 0xFFFFFFFFUL
53 GRAPHICDRAWMODE_STANDARD
= 0,
54 GRAPHICDRAWMODE_GREYS
= 1,
55 GRAPHICDRAWMODE_MONO
= 2,
56 GRAPHICDRAWMODE_WATERMARK
= 3
61 class BitmapWriteAccess
;
64 struct GrfSimpleCacheObj
;
67 class SVT_DLLPUBLIC GraphicAttr
72 sal_uInt32 mnMirrFlags
;
77 sal_uInt16 mnRotate10
;
84 sal_uInt8 mcTransparency
;
85 GraphicDrawMode meDrawMode
;
92 sal_Bool
operator==( const GraphicAttr
& rAttr
) const;
93 sal_Bool
operator!=( const GraphicAttr
& rAttr
) const { return !( *this == rAttr
); }
95 void SetDrawMode( GraphicDrawMode eDrawMode
) { meDrawMode
= eDrawMode
; }
96 GraphicDrawMode
GetDrawMode() const { return meDrawMode
; }
98 void SetMirrorFlags( sal_uLong nMirrFlags
) { mnMirrFlags
= nMirrFlags
; }
99 sal_uLong
GetMirrorFlags() const { return mnMirrFlags
; }
101 void SetCrop( long nLeft_100TH_MM
, long nTop_100TH_MM
, long nRight_100TH_MM
, long nBottom_100TH_MM
)
103 mnLeftCrop
= nLeft_100TH_MM
; mnTopCrop
= nTop_100TH_MM
;
104 mnRightCrop
= nRight_100TH_MM
; mnBottomCrop
= nBottom_100TH_MM
;
106 long GetLeftCrop() const { return mnLeftCrop
; }
107 long GetTopCrop() const { return mnTopCrop
; }
108 long GetRightCrop() const { return mnRightCrop
; }
109 long GetBottomCrop() const { return mnBottomCrop
; }
111 void SetRotation( sal_uInt16 nRotate10
) { mnRotate10
= nRotate10
; }
112 sal_uInt16
GetRotation() const { return mnRotate10
; }
114 void SetLuminance( short nLuminancePercent
) { mnLumPercent
= nLuminancePercent
; }
115 short GetLuminance() const { return mnLumPercent
; }
117 void SetContrast( short nContrastPercent
) { mnContPercent
= nContrastPercent
; }
118 short GetContrast() const { return mnContPercent
; }
120 void SetChannelR( short nChannelRPercent
) { mnRPercent
= nChannelRPercent
; }
121 short GetChannelR() const { return mnRPercent
; }
123 void SetChannelG( short nChannelGPercent
) { mnGPercent
= nChannelGPercent
; }
124 short GetChannelG() const { return mnGPercent
; }
126 void SetChannelB( short nChannelBPercent
) { mnBPercent
= nChannelBPercent
; }
127 short GetChannelB() const { return mnBPercent
; }
129 void SetGamma( double fGamma
) { mfGamma
= fGamma
; }
130 double GetGamma() const { return mfGamma
; }
132 void SetInvert( sal_Bool bInvert
) { mbInvert
= bInvert
; }
133 sal_Bool
IsInvert() const { return mbInvert
; }
135 void SetTransparency( sal_uInt8 cTransparency
) { mcTransparency
= cTransparency
; }
136 sal_uInt8
GetTransparency() const { return mcTransparency
; }
138 sal_Bool
IsSpecialDrawMode() const { return( meDrawMode
!= GRAPHICDRAWMODE_STANDARD
); }
139 sal_Bool
IsMirrored() const { return( mnMirrFlags
!= 0UL ); }
140 sal_Bool
IsCropped() const
142 return( mnLeftCrop
!= 0 || mnTopCrop
!= 0 ||
143 mnRightCrop
!= 0 || mnBottomCrop
!= 0 );
145 sal_Bool
IsRotated() const { return( ( mnRotate10
% 3600 ) != 0 ); }
146 sal_Bool
IsTransparent() const { return( mcTransparency
> 0 ); }
147 sal_Bool
IsAdjusted() const
149 return( mnLumPercent
!= 0 || mnContPercent
!= 0 || mnRPercent
!= 0 ||
150 mnGPercent
!= 0 || mnBPercent
!= 0 || mfGamma
!= 1.0 || mbInvert
);
153 friend SvStream
& operator<<( SvStream
& rOStm
, const GraphicAttr
& rAttr
);
154 friend SvStream
& operator>>( SvStream
& rIStm
, GraphicAttr
& rAttr
);
157 class SVT_DLLPUBLIC GraphicObject
: public SvDataCopyStream
159 friend class GraphicManager
;
163 static GraphicManager
* mpGlobalMgr
;
168 MapMode maPrefMapMode
;
169 sal_uLong mnSizeBytes
;
171 GraphicManager
* mpMgr
;
173 Link
* mpSwapStreamHdl
;
175 Timer
* mpSwapOutTimer
;
176 GrfSimpleCacheObj
* mpSimpleCache
;
177 sal_uLong mnAnimationLoopCount
;
178 sal_Bool mbAutoSwapped
: 1;
179 sal_Bool mbTransparent
: 1;
180 sal_Bool mbAnimated
: 1;
182 sal_Bool mbIsInSwapIn
: 1;
183 sal_Bool mbIsInSwapOut
: 1;
184 sal_Bool mbAlpha
: 1;
186 void SVT_DLLPRIVATE
ImplConstruct();
187 void SVT_DLLPRIVATE
ImplAssignGraphicData();
188 void SVT_DLLPRIVATE
ImplSetGraphicManager(
189 const GraphicManager
* pMgr
,
190 const OString
* pID
= NULL
,
191 const GraphicObject
* pCopyObj
= NULL
193 void SVT_DLLPRIVATE
ImplAutoSwapIn();
194 sal_Bool SVT_DLLPRIVATE
ImplIsAutoSwapped() const { return mbAutoSwapped
; }
195 sal_Bool SVT_DLLPRIVATE
ImplGetCropParams(
199 const GraphicAttr
* pAttr
,
200 PolyPolygon
& rClipPolyPoly
,
201 sal_Bool
& bRectClipRegion
204 /** Render a given number of tiles in an optimized way
206 This method recursively subdivides the tile rendering problem
207 in smaller parts, i.e. rendering output size x with few tiles
208 of size y, which in turn are generated from the original
209 bitmap in a recursive fashion. The subdivision size can be
210 controlled by the exponent argument, which specifies the
211 minimal number of smaller tiles used in one recursion
212 step. The resulting tile size is given as the integer number
213 of repetitions of the original bitmap along x and y. As the
214 exponent need not necessarily divide these numbers without
215 remainder, the repetition counts are effectively converted to
216 base-exponent numbers, where each place denotes the number of
217 times the corresponding tile size is rendered.
220 Virtual device to render everything into
223 Number of repetitions per subdivision step, _must_ be greater than 1
226 Number of original tiles to generate in x direction
229 Number of original tiles to generate in y direction
231 @param rTileSizePixel
232 Size in pixel of the original tile bitmap to render it in
235 Graphic attributes to be used for rendering
238 Graphic flags to be used for rendering
241 Current output point for this recursion level (should start with (0,0))
243 @return true, if everything was successfully rendered.
245 bool SVT_DLLPRIVATE
ImplRenderTempTile(
246 VirtualDevice
& rVDev
,
250 const Size
& rTileSizePixel
,
251 const GraphicAttr
* pAttr
,
255 /// internally called by ImplRenderTempTile()
256 bool SVT_DLLPRIVATE
ImplRenderTileRecursive(
257 VirtualDevice
& rVDev
,
262 int nRemainderTilesX
,
263 int nRemainderTilesY
,
264 const Size
& rTileSizePixel
,
265 const GraphicAttr
* pAttr
,
267 ImplTileInfo
& rTileInfo
270 bool SVT_DLLPRIVATE
ImplDrawTiled(
272 const Rectangle
& rArea
,
273 const Size
& rSizePixel
,
275 const GraphicAttr
* pAttr
,
280 bool SVT_DLLPRIVATE
ImplDrawTiled(
285 const Size
& rTileSize
,
286 const GraphicAttr
* pAttr
,
290 void SVT_DLLPRIVATE
ImplTransformBitmap(
292 const GraphicAttr
& rAttr
,
293 const Size
& rCropLeftTop
,
294 const Size
& rCropRightBottom
,
295 const Rectangle
& rCropRect
,
296 const Size
& rDstSize
,
300 DECL_LINK( ImplAutoSwapOutHdl
, void* );
304 virtual void GraphicManagerDestroyed();
305 virtual SvStream
* GetSwapStream() const;
307 virtual void Load( SvStream
& );
308 virtual void Save( SvStream
& );
309 virtual void Assign( const SvDataCopyStream
& );
315 GraphicObject( const GraphicManager
* pMgr
= NULL
);
316 GraphicObject( const Graphic
& rGraphic
, const GraphicManager
* pMgr
= NULL
);
317 GraphicObject( const GraphicObject
& rCacheObj
, const GraphicManager
* pMgr
= NULL
);
318 explicit GraphicObject( const OString
& rUniqueID
, const GraphicManager
* pMgr
= NULL
);
321 GraphicObject
& operator=( const GraphicObject
& rCacheObj
);
322 sal_Bool
operator==( const GraphicObject
& rCacheObj
) const;
323 sal_Bool
operator!=( const GraphicObject
& rCacheObj
) const { return !( *this == rCacheObj
); }
325 sal_Bool
HasSwapStreamHdl() const { return( mpSwapStreamHdl
!= NULL
&& mpSwapStreamHdl
->IsSet() ); }
326 void SetSwapStreamHdl();
327 void SetSwapStreamHdl( const Link
& rHdl
, const sal_uLong nSwapOutTimeout
= 0UL );
328 sal_uLong
GetSwapOutTimeout() const { return( mpSwapOutTimer
? mpSwapOutTimer
->GetTimeout() : 0 ); }
330 void FireSwapInRequest();
331 void FireSwapOutRequest();
333 GraphicManager
& GetGraphicManager() const { return *mpMgr
; }
339 const GraphicAttr
* pAttr
= NULL
,
340 sal_uLong nFlags
= GRFMGR_DRAW_STANDARD
342 void ReleaseFromCache();
344 const Graphic
& GetGraphic() const;
345 void SetGraphic( const Graphic
& rGraphic
, const GraphicObject
* pCopyObj
= 0);
346 void SetGraphic( const Graphic
& rGraphic
, const String
& rLink
);
348 /** Get graphic transformed according to given attributes
350 This method returns a Graphic transformed, cropped and scaled
351 to the given parameters, ready to be rendered to printer or
352 display. The returned graphic has the same visual appearance
353 as if it had been drawn via GraphicObject::Draw() to a
354 specific output device.
357 Desired output size in logical coordinates. The mapmode to
358 interpret these logical coordinates in is given by the second
362 Mapmode the output should be interpreted in. This is used to
363 interpret rDestSize, to set the appropriate PrefMapMode on the
364 returned Graphic, and to deal correctly with metafile graphics.
367 Graphic attributes used to transform the graphic. This
368 includes cropping, rotation, mirroring, and various color
369 adjustment parameters.
371 @return the readily transformed Graphic
373 Graphic
GetTransformedGraphic(
374 const Size
& rDestSize
,
375 const MapMode
& rDestMap
,
376 const GraphicAttr
& rAttr
378 Graphic
GetTransformedGraphic( const GraphicAttr
* pAttr
= NULL
) const; // TODO: Change to Impl
380 void SetAttr( const GraphicAttr
& rAttr
);
381 const GraphicAttr
& GetAttr() const { return maAttr
; }
383 sal_Bool
HasLink() const { return( mpLink
!= NULL
&& mpLink
->Len() > 0 ); }
385 void SetLink( const String
& rLink
);
386 String
GetLink() const;
388 sal_Bool
HasUserData() const { return( mpUserData
!= NULL
&& mpUserData
->Len() > 0 ); }
390 void SetUserData( const String
& rUserData
);
391 String
GetUserData() const;
393 OString
GetUniqueID() const;
395 GraphicType
GetType() const { return meType
; }
396 const Size
& GetPrefSize() const { return maPrefSize
; }
397 const MapMode
& GetPrefMapMode() const { return maPrefMapMode
; }
398 sal_uLong
GetSizeBytes() const { return mnSizeBytes
; }
399 sal_Bool
IsTransparent() const { return mbTransparent
; }
400 sal_Bool
IsAlpha() const { return mbAlpha
; }
401 sal_Bool
IsAnimated() const { return mbAnimated
; }
402 sal_Bool
IsEPS() const { return mbEPS
; }
404 Link
GetAnimationNotifyHdl() const { return maGraphic
.GetAnimationNotifyHdl(); }
407 sal_Bool
SwapOut( SvStream
* pOStm
);
410 sal_Bool
IsInSwapIn() const { return mbIsInSwapIn
; }
411 sal_Bool
IsInSwapOut() const { return mbIsInSwapOut
; }
412 sal_Bool
IsInSwap() const { return( mbIsInSwapOut
|| mbIsInSwapOut
); }
413 sal_Bool
IsSwappedOut() const { return( mbAutoSwapped
|| maGraphic
.IsSwapOut() ); }
420 const GraphicAttr
* pAttr
= NULL
,
421 sal_uLong nFlags
= GRFMGR_DRAW_STANDARD
424 sal_Bool
DrawWithPDFHandling(
425 OutputDevice
& rOutDev
,
428 const GraphicAttr
* pGrfAttr
= NULL
,
429 const sal_uLong nFlags
= GRFMGR_DRAW_STANDARD
432 /** Draw the graphic repeatedly into the given output rectangle
435 OutputDevice where the rendering should take place
438 The output area that is filled with tiled instances of this graphic
441 The actual size of a single tile
444 Offset from the left, top position of rArea, where to start
445 the tiling. The upper left corner of the graphic tilings will
446 virtually start at this position. Concretely, only that many
447 tiles are drawn to completely fill the given output area.
453 Optional rendering flags
455 @param nTileCacheSize1D
456 Optional dimension of the generated cache tiles. The pOut sees
457 a number of tile draws, which have approximately
458 nTileCacheSize1D times nTileCacheSize1D bitmap sizes if the
459 tile bitmap is smaller. Otherwise, the tile is drawn as
460 is. This is useful if e.g. you want only a few, very large
461 bitmap drawings appear on the outdev.
463 @return sal_True, if drawing completed successfully
467 const Rectangle
& rArea
,
470 const GraphicAttr
* pAttr
= NULL
,
471 sal_uLong nFlags
= GRFMGR_DRAW_STANDARD
,
472 int nTileCacheSize1D
=128
475 sal_Bool
StartAnimation(
479 long nExtraData
= 0L,
480 const GraphicAttr
* pAttr
= NULL
,
481 sal_uLong nFlags
= GRFMGR_DRAW_STANDARD
,
482 OutputDevice
* pFirstFrameOutDev
= NULL
485 void StopAnimation( OutputDevice
* pOut
= NULL
, long nExtraData
= 0L );
487 friend SvStream
& operator<<( SvStream
& rOStm
, const GraphicObject
& rGraphicObj
);
488 friend SvStream
& operator>>( SvStream
& rIStm
, GraphicObject
& rGraphicObj
);
490 static GraphicObject
CreateGraphicObjectFromURL( const OUString
&rURL
);
491 // will inspect an object ( e.g. a control ) for any 'ImageURL'
492 // properties and return these in a vector. Note: this implementation
493 // will cater for XNameContainer objects and deepinspect any containees
495 static void InspectForGraphicObjectImageURL( const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& rxIf
, std::vector
< OUString
>& rvEmbedImgUrls
);
498 typedef ::std::vector
< GraphicObject
* > GraphicObjectList_impl
;
500 class SVT_DLLPUBLIC GraphicManager
502 friend class GraphicObject
;
503 friend class GraphicDisplayCacheEntry
;
507 GraphicObjectList_impl maObjList
;
508 GraphicCache
* mpCache
;
510 GraphicManager( const GraphicManager
& ) {}
511 GraphicManager
& operator=( const GraphicManager
& ) { return *this; }
513 sal_Bool SVT_DLLPRIVATE
ImplDraw(
518 const GraphicAttr
& rAttr
,
519 const sal_uLong nFlags
,
523 sal_Bool SVT_DLLPRIVATE
ImplCreateOutput(
527 const BitmapEx
& rBmpEx
,
528 const GraphicAttr
& rAttr
,
529 const sal_uLong nFlags
,
530 BitmapEx
* pBmpEx
= NULL
532 sal_Bool SVT_DLLPRIVATE
ImplCreateOutput(
536 const GDIMetaFile
& rMtf
,
537 const GraphicAttr
& rAttr
,
538 const sal_uLong nFlags
,
539 GDIMetaFile
& rOutMtf
,
543 static void SVT_DLLPRIVATE
ImplAdjust(
545 const GraphicAttr
& rAttr
,
546 sal_uLong nAdjustmentFlags
548 static void SVT_DLLPRIVATE
ImplAdjust(
550 const GraphicAttr
& rAttr
,
551 sal_uLong nAdjustmentFlags
553 static void SVT_DLLPRIVATE
ImplAdjust(
554 Animation
& rAnimation
,
555 const GraphicAttr
& rAttr
,
556 sal_uLong nAdjustmentFlags
559 static void SVT_DLLPRIVATE
ImplDraw(
563 const GDIMetaFile
& rMtf
,
564 const GraphicAttr
& rAttr
567 // Only used by GraphicObject's Ctor's and Dtor's
568 void SVT_DLLPRIVATE
ImplRegisterObj(
569 const GraphicObject
& rObj
,
570 Graphic
& rSubstitute
,
571 const OString
* pID
= NULL
,
572 const GraphicObject
* pCopyObj
= NULL
574 void SVT_DLLPRIVATE
ImplUnregisterObj( const GraphicObject
& rObj
);
575 inline sal_Bool SVT_DLLPRIVATE
ImplHasObjects() const { return !maObjList
.empty(); }
577 // Only used in swap case by GraphicObject
578 void SVT_DLLPRIVATE
ImplGraphicObjectWasSwappedOut( const GraphicObject
& rObj
);
579 sal_Bool SVT_DLLPRIVATE
ImplFillSwappedGraphicObject(
580 const GraphicObject
& rObj
,
583 void SVT_DLLPRIVATE
ImplGraphicObjectWasSwappedIn( const GraphicObject
& rObj
);
585 OString SVT_DLLPRIVATE
ImplGetUniqueID( const GraphicObject
& rObj
) const;
589 GraphicManager( sal_uLong nCacheSize
= 10000000UL, sal_uLong nMaxObjCacheSize
= 2400000UL );
592 void SetMaxCacheSize( sal_uLong nNewCacheSize
);
594 void SetMaxObjCacheSize(
595 sal_uLong nNewMaxObjSize
,
596 sal_Bool bDestroyGreaterCached
= sal_False
599 void SetCacheTimeout( sal_uLong nTimeoutSeconds
);
601 void ReleaseFromCache( const GraphicObject
& rObj
);
607 const GraphicObject
& rObj
,
608 const GraphicAttr
& rAttr
616 const GraphicAttr
& rAttr
,
617 const sal_uLong nFlags
,
622 #endif // _GRFMGR_HXX
624 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */