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 .
20 #ifndef INCLUDED_VCL_GRAPHICOBJECT_HXX
21 #define INCLUDED_VCL_GRAPHICOBJECT_HXX
24 #include <vcl/graph.hxx>
25 #include <vcl/dllapi.h>
26 #include <o3tl/typed_flags_set.hxx>
28 namespace com
{ namespace sun
{ namespace star
{ namespace graphic
{ class XGraphic
; } } } }
31 enum class GraphicAdjustmentFlags
43 template<> struct typed_flags
<GraphicAdjustmentFlags
> : is_typed_flags
<GraphicAdjustmentFlags
, 0x1f> {};
46 enum class GraphicDrawMode
55 struct GrfSimpleCacheObj
;
58 class VCL_DLLPUBLIC GraphicAttr
63 BmpMirrorFlags mnMirrFlags
;
68 sal_uInt16 mnRotate10
;
75 sal_uInt8 mcTransparency
;
76 GraphicDrawMode meDrawMode
;
82 bool operator==( const GraphicAttr
& rAttr
) const;
83 bool operator!=( const GraphicAttr
& rAttr
) const { return !( *this == rAttr
); }
85 void SetDrawMode( GraphicDrawMode eDrawMode
) { meDrawMode
= eDrawMode
; }
86 GraphicDrawMode
GetDrawMode() const { return meDrawMode
; }
88 void SetMirrorFlags( BmpMirrorFlags nMirrFlags
) { mnMirrFlags
= nMirrFlags
; }
89 BmpMirrorFlags
GetMirrorFlags() const { return mnMirrFlags
; }
91 void SetCrop( long nLeft_100TH_MM
, long nTop_100TH_MM
, long nRight_100TH_MM
, long nBottom_100TH_MM
)
93 mnLeftCrop
= nLeft_100TH_MM
; mnTopCrop
= nTop_100TH_MM
;
94 mnRightCrop
= nRight_100TH_MM
; mnBottomCrop
= nBottom_100TH_MM
;
96 long GetLeftCrop() const { return mnLeftCrop
; }
97 long GetTopCrop() const { return mnTopCrop
; }
98 long GetRightCrop() const { return mnRightCrop
; }
99 long GetBottomCrop() const { return mnBottomCrop
; }
101 void SetRotation( sal_uInt16 nRotate10
) { mnRotate10
= nRotate10
; }
102 sal_uInt16
GetRotation() const { return mnRotate10
; }
104 void SetLuminance( short nLuminancePercent
) { mnLumPercent
= nLuminancePercent
; }
105 short GetLuminance() const { return mnLumPercent
; }
107 void SetContrast( short nContrastPercent
) { mnContPercent
= nContrastPercent
; }
108 short GetContrast() const { return mnContPercent
; }
110 void SetChannelR( short nChannelRPercent
) { mnRPercent
= nChannelRPercent
; }
111 short GetChannelR() const { return mnRPercent
; }
113 void SetChannelG( short nChannelGPercent
) { mnGPercent
= nChannelGPercent
; }
114 short GetChannelG() const { return mnGPercent
; }
116 void SetChannelB( short nChannelBPercent
) { mnBPercent
= nChannelBPercent
; }
117 short GetChannelB() const { return mnBPercent
; }
119 void SetGamma( double fGamma
) { mfGamma
= fGamma
; }
120 double GetGamma() const { return mfGamma
; }
122 void SetInvert( bool bInvert
) { mbInvert
= bInvert
; }
123 bool IsInvert() const { return mbInvert
; }
125 void SetTransparency( sal_uInt8 cTransparency
) { mcTransparency
= cTransparency
; }
126 sal_uInt8
GetTransparency() const { return mcTransparency
; }
128 bool IsSpecialDrawMode() const { return( meDrawMode
!= GraphicDrawMode::Standard
); }
129 bool IsMirrored() const { return mnMirrFlags
!= BmpMirrorFlags::NONE
; }
130 bool IsCropped() const
132 return( mnLeftCrop
!= 0 || mnTopCrop
!= 0 ||
133 mnRightCrop
!= 0 || mnBottomCrop
!= 0 );
135 bool IsRotated() const { return( ( mnRotate10
% 3600 ) != 0 ); }
136 bool IsTransparent() const { return( mcTransparency
> 0 ); }
137 bool IsAdjusted() const
139 return( mnLumPercent
!= 0 || mnContPercent
!= 0 || mnRPercent
!= 0 ||
140 mnGPercent
!= 0 || mnBPercent
!= 0 || mfGamma
!= 1.0 || mbInvert
);
144 class VCL_DLLPUBLIC GraphicObject
146 friend class SdrGrafObj
;
152 std::unique_ptr
<GrfSimpleCacheObj
> mxSimpleCache
;
154 bool VCL_DLLPRIVATE
ImplGetCropParams(
155 OutputDevice
const * pOut
,
158 const GraphicAttr
* pAttr
,
159 tools::PolyPolygon
& rClipPolyPoly
,
160 bool& bRectClipRegion
163 /** Render a given number of tiles in an optimized way
165 This method recursively subdivides the tile rendering problem
166 in smaller parts, i.e. rendering output size x with few tiles
167 of size y, which in turn are generated from the original
168 bitmap in a recursive fashion. The subdivision size can be
169 controlled by the exponent argument, which specifies the
170 minimal number of smaller tiles used in one recursion
171 step. The resulting tile size is given as the integer number
172 of repetitions of the original bitmap along x and y. As the
173 exponent need not necessarily divide these numbers without
174 remainder, the repetition counts are effectively converted to
175 base-exponent numbers, where each place denotes the number of
176 times the corresponding tile size is rendered.
179 Virtual device to render everything into
182 Number of original tiles to generate in x direction
185 Number of original tiles to generate in y direction
187 @param rTileSizePixel
188 Size in pixel of the original tile bitmap to render it in
191 Graphic attributes to be used for rendering
194 Graphic flags to be used for rendering
197 Current output point for this recursion level (should start with (0,0))
199 @return true, if everything was successfully rendered.
201 bool VCL_DLLPRIVATE
ImplRenderTempTile(
202 VirtualDevice
& rVDev
,
205 const Size
& rTileSizePixel
,
206 const GraphicAttr
* pAttr
209 /// internally called by ImplRenderTempTile()
210 bool VCL_DLLPRIVATE
ImplRenderTileRecursive(
211 VirtualDevice
& rVDev
,
216 int nRemainderTilesX
,
217 int nRemainderTilesY
,
218 const Size
& rTileSizePixel
,
219 const GraphicAttr
* pAttr
,
220 ImplTileInfo
& rTileInfo
223 bool VCL_DLLPRIVATE
ImplDrawTiled(
225 const tools::Rectangle
& rArea
,
226 const Size
& rSizePixel
,
228 const GraphicAttr
* pAttr
,
232 bool VCL_DLLPRIVATE
ImplDrawTiled(
237 const Size
& rTileSize
,
238 const GraphicAttr
* pAttr
241 void VCL_DLLPRIVATE
ImplTransformBitmap(
243 const GraphicAttr
& rAttr
,
244 const Size
& rCropLeftTop
,
245 const Size
& rCropRightBottom
,
246 const tools::Rectangle
& rCropRect
,
247 const Size
& rDstSize
,
253 GraphicObject( const Graphic
& rGraphic
);
254 GraphicObject( const GraphicObject
& rCacheObj
);
257 GraphicObject
& operator=( const GraphicObject
& rCacheObj
);
258 bool operator==( const GraphicObject
& rCacheObj
) const;
259 bool operator!=( const GraphicObject
& rCacheObj
) const { return !( *this == rCacheObj
); }
261 const Graphic
& GetGraphic() const;
262 void SetGraphic( const Graphic
& rGraphic
, const GraphicObject
* pCopyObj
= nullptr);
263 void SetGraphic( const Graphic
& rGraphic
, const OUString
& rLink
);
265 /** Get graphic transformed according to given attributes
267 This method returns a Graphic transformed, cropped and scaled
268 to the given parameters, ready to be rendered to printer or
269 display. The returned graphic has the same visual appearance
270 as if it had been drawn via GraphicObject::Draw() to a
271 specific output device.
274 Desired output size in logical coordinates. The mapmode to
275 interpret these logical coordinates in is given by the second
279 Mapmode the output should be interpreted in. This is used to
280 interpret rDestSize, to set the appropriate PrefMapMode on the
281 returned Graphic, and to deal correctly with metafile graphics.
284 Graphic attributes used to transform the graphic. This
285 includes cropping, rotation, mirroring, and various color
286 adjustment parameters.
288 @return the readily transformed Graphic
290 Graphic
GetTransformedGraphic(
291 const Size
& rDestSize
,
292 const MapMode
& rDestMap
,
293 const GraphicAttr
& rAttr
295 Graphic
GetTransformedGraphic( const GraphicAttr
* pAttr
) const; // TODO: Change to Impl
297 void SetAttr( const GraphicAttr
& rAttr
);
298 const GraphicAttr
& GetAttr() const { return maAttr
; }
300 bool HasUserData() const { return !maUserData
.isEmpty(); }
302 void SetUserData( const OUString
& rUserData
);
303 const OUString
& GetUserData() const { return maUserData
; }
305 OString
GetUniqueID() const;
307 GraphicType
GetType() const;
308 Size
GetPrefSize() const;
309 MapMode
GetPrefMapMode() const;
310 bool IsTransparent() const;
311 bool IsAnimated() const;
318 const GraphicAttr
* pAttr
= nullptr
321 /** Draw the graphic repeatedly into the given output rectangle
324 OutputDevice where the rendering should take place
327 The output area that is filled with tiled instances of this graphic
330 The actual size of a single tile
333 Offset from the left, top position of rArea, where to start
334 the tiling. The upper left corner of the graphic tilings will
335 virtually start at this position. Concretely, only that many
336 tiles are drawn to completely fill the given output area.
339 Optional rendering flags
341 @param nTileCacheSize1D
342 Optional dimension of the generated cache tiles. The pOut sees
343 a number of tile draws, which have approximately
344 nTileCacheSize1D times nTileCacheSize1D bitmap sizes if the
345 tile bitmap is smaller. Otherwise, the tile is drawn as
346 is. This is useful if e.g. you want only a few, very large
347 bitmap drawings appear on the outdev.
351 const tools::Rectangle
& rArea
,
354 int nTileCacheSize1D
=128
362 OutputDevice
* pFirstFrameOutDev
= nullptr
365 void StopAnimation( OutputDevice
* pOut
= nullptr, long nExtraData
= 0 );
367 static bool isGraphicObjectUniqueIdURL(OUString
const & rURL
);
369 // create CropScaling information
370 // fWidth, fHeight: object size
371 // f*Crop: crop values relative to original bitmap size
372 basegfx::B2DVector
calculateCropScaling(
378 double fBottomCrop
) const;
386 // Will search an object ( e.g. a control ) for any 'ImageURL' or 'Graphic'
387 // properties and return graphics from the properties in a vector. ImageURL
388 // will be loaded from the URL.
390 // Note: this implementation will cater for XNameContainer objects and deep inspect any containers
393 VCL_DLLPUBLIC
void SearchForGraphics(css::uno::Reference
<css::uno::XInterface
> const & rxInterface
,
394 std::vector
<css::uno::Reference
<css::graphic::XGraphic
>> & raGraphicList
);
397 } // end namespace vcl::graphic
399 #endif // INCLUDED_VCL_GRAPHICOBJECT_HXX
401 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */