lok: calc - send other views our selection in their co-ordinates.
[LibreOffice.git] / include / vcl / GraphicObject.hxx
blobbd5bcd71f1c3810ccbbe9c8d6317fbd178a606dc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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
23 #include <memory>
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; } } } }
30 // Adjustment defines
31 enum class GraphicAdjustmentFlags
33 NONE = 0x00,
34 DRAWMODE = 0x01,
35 COLORS = 0x02,
36 MIRROR = 0x04,
37 ROTATE = 0x08,
38 TRANSPARENCY = 0x10,
39 ALL = 0x1f,
41 namespace o3tl
43 template<> struct typed_flags<GraphicAdjustmentFlags> : is_typed_flags<GraphicAdjustmentFlags, 0x1f> {};
46 enum class GraphicDrawMode
48 Standard = 0,
49 Greys = 1,
50 Mono = 2,
51 Watermark = 3
54 class VirtualDevice;
55 struct GrfSimpleCacheObj;
56 struct ImplTileInfo;
58 class VCL_DLLPUBLIC GraphicAttr
60 private:
62 double mfGamma;
63 BmpMirrorFlags mnMirrFlags;
64 long mnLeftCrop;
65 long mnTopCrop;
66 long mnRightCrop;
67 long mnBottomCrop;
68 sal_uInt16 mnRotate10;
69 short mnContPercent;
70 short mnLumPercent;
71 short mnRPercent;
72 short mnGPercent;
73 short mnBPercent;
74 bool mbInvert;
75 sal_uInt8 mcTransparency;
76 GraphicDrawMode meDrawMode;
78 public:
80 GraphicAttr();
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;
148 private:
149 Graphic maGraphic;
150 GraphicAttr maAttr;
151 OUString maUserData;
152 std::unique_ptr<GrfSimpleCacheObj> mxSimpleCache;
154 bool VCL_DLLPRIVATE ImplGetCropParams(
155 OutputDevice const * pOut,
156 Point& rPt,
157 Size& rSz,
158 const GraphicAttr* pAttr,
159 tools::PolyPolygon& rClipPolyPoly,
160 bool& bRectClipRegion
161 ) const;
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.
178 @param rVDev
179 Virtual device to render everything into
181 @param nNumTilesX
182 Number of original tiles to generate in x direction
184 @param nNumTilesY
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
190 @param pAttr
191 Graphic attributes to be used for rendering
193 @param nFlags
194 Graphic flags to be used for rendering
196 @param rCurrPos
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,
203 int nNumTilesX,
204 int nNumTilesY,
205 const Size& rTileSizePixel,
206 const GraphicAttr* pAttr
209 /// internally called by ImplRenderTempTile()
210 bool VCL_DLLPRIVATE ImplRenderTileRecursive(
211 VirtualDevice& rVDev,
212 int nExponent,
213 int nMSBFactor,
214 int nNumOrigTilesX,
215 int nNumOrigTilesY,
216 int nRemainderTilesX,
217 int nRemainderTilesY,
218 const Size& rTileSizePixel,
219 const GraphicAttr* pAttr,
220 ImplTileInfo& rTileInfo
223 bool VCL_DLLPRIVATE ImplDrawTiled(
224 OutputDevice* pOut,
225 const tools::Rectangle& rArea,
226 const Size& rSizePixel,
227 const Size& rOffset,
228 const GraphicAttr* pAttr,
229 int nTileCacheSize1D
232 bool VCL_DLLPRIVATE ImplDrawTiled(
233 OutputDevice& rOut,
234 const Point& rPos,
235 int nNumTilesX,
236 int nNumTilesY,
237 const Size& rTileSize,
238 const GraphicAttr* pAttr
241 void VCL_DLLPRIVATE ImplTransformBitmap(
242 BitmapEx& rBmpEx,
243 const GraphicAttr& rAttr,
244 const Size& rCropLeftTop,
245 const Size& rCropRightBottom,
246 const tools::Rectangle& rCropRect,
247 const Size& rDstSize,
248 bool bEnlarge
249 ) const;
251 public:
252 GraphicObject();
253 GraphicObject( const Graphic& rGraphic );
254 GraphicObject( const GraphicObject& rCacheObj );
255 ~GraphicObject();
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.
273 @param rDestSize
274 Desired output size in logical coordinates. The mapmode to
275 interpret these logical coordinates in is given by the second
276 parameter, rDestMap.
278 @param rDestMap
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.
283 @param rAttr
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
294 ) const;
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(); }
301 void SetUserData();
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;
312 bool IsEPS() const;
314 bool Draw(
315 OutputDevice* pOut,
316 const Point& rPt,
317 const Size& rSz,
318 const GraphicAttr* pAttr = nullptr
321 /** Draw the graphic repeatedly into the given output rectangle
323 @param pOut
324 OutputDevice where the rendering should take place
326 @param rArea
327 The output area that is filled with tiled instances of this graphic
329 @param rSize
330 The actual size of a single tile
332 @param rOffset
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.
338 @param nFlags
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.
349 void DrawTiled(
350 OutputDevice* pOut,
351 const tools::Rectangle& rArea,
352 const Size& rSize,
353 const Size& rOffset,
354 int nTileCacheSize1D=128
357 bool StartAnimation(
358 OutputDevice* pOut,
359 const Point& rPt,
360 const Size& rSz,
361 long nExtraData = 0,
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(
373 double fWidth,
374 double fHeight,
375 double fLeftCrop,
376 double fTopCrop,
377 double fRightCrop,
378 double fBottomCrop) const;
381 namespace vcl
383 namespace graphic
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
391 // if they exist
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: */