LibreOffice Module vcl (master)  1
GraphicObject.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #ifndef INCLUDED_VCL_GRAPHICOBJECT_HXX
21 #define INCLUDED_VCL_GRAPHICOBJECT_HXX
22 
23 #include <memory>
24 #include <vcl/graph.hxx>
25 #include <vcl/dllapi.h>
26 #include <o3tl/typed_flags_set.hxx>
27 
28 namespace com { namespace sun { namespace star { namespace graphic { class XGraphic; } } } }
29 
30 // Adjustment defines
32 {
33  NONE = 0x00,
34  DRAWMODE = 0x01,
35  COLORS = 0x02,
36  MIRROR = 0x04,
37  ROTATE = 0x08,
38  TRANSPARENCY = 0x10,
39  ALL = 0x1f,
40 };
41 namespace o3tl
42 {
43  template<> struct typed_flags<GraphicAdjustmentFlags> : is_typed_flags<GraphicAdjustmentFlags, 0x1f> {};
44 }
45 
46 enum class GraphicDrawMode
47 {
48  Standard = 0,
49  Greys = 1,
50  Mono = 2,
51  Watermark = 3
52 };
53 
54 class VirtualDevice;
55 struct GrfSimpleCacheObj;
56 struct ImplTileInfo;
57 
59 {
60 private:
61 
62  double mfGamma;
64  long mnLeftCrop;
65  long mnTopCrop;
68  sal_uInt16 mnRotate10;
70  short mnLumPercent;
71  short mnRPercent;
72  short mnGPercent;
73  short mnBPercent;
74  bool mbInvert;
77 
78 public:
79 
80  GraphicAttr();
81 
82  bool operator==( const GraphicAttr& rAttr ) const;
83  bool operator!=( const GraphicAttr& rAttr ) const { return !( *this == rAttr ); }
84 
85  void SetDrawMode( GraphicDrawMode eDrawMode ) { meDrawMode = eDrawMode; }
86  GraphicDrawMode GetDrawMode() const { return meDrawMode; }
87 
88  void SetMirrorFlags( BmpMirrorFlags nMirrFlags ) { mnMirrFlags = nMirrFlags; }
89  BmpMirrorFlags GetMirrorFlags() const { return mnMirrFlags; }
90 
91  void SetCrop( long nLeft_100TH_MM, long nTop_100TH_MM, long nRight_100TH_MM, long nBottom_100TH_MM )
92  {
93  mnLeftCrop = nLeft_100TH_MM; mnTopCrop = nTop_100TH_MM;
94  mnRightCrop = nRight_100TH_MM; mnBottomCrop = nBottom_100TH_MM;
95  }
96  long GetLeftCrop() const { return mnLeftCrop; }
97  long GetTopCrop() const { return mnTopCrop; }
98  long GetRightCrop() const { return mnRightCrop; }
99  long GetBottomCrop() const { return mnBottomCrop; }
100 
101  void SetRotation( sal_uInt16 nRotate10 ) { mnRotate10 = nRotate10; }
102  sal_uInt16 GetRotation() const { return mnRotate10; }
103 
104  void SetLuminance( short nLuminancePercent ) { mnLumPercent = nLuminancePercent; }
105  short GetLuminance() const { return mnLumPercent; }
106 
107  void SetContrast( short nContrastPercent ) { mnContPercent = nContrastPercent; }
108  short GetContrast() const { return mnContPercent; }
109 
110  void SetChannelR( short nChannelRPercent ) { mnRPercent = nChannelRPercent; }
111  short GetChannelR() const { return mnRPercent; }
112 
113  void SetChannelG( short nChannelGPercent ) { mnGPercent = nChannelGPercent; }
114  short GetChannelG() const { return mnGPercent; }
115 
116  void SetChannelB( short nChannelBPercent ) { mnBPercent = nChannelBPercent; }
117  short GetChannelB() const { return mnBPercent; }
118 
119  void SetGamma( double fGamma ) { mfGamma = fGamma; }
120  double GetGamma() const { return mfGamma; }
121 
122  void SetInvert( bool bInvert ) { mbInvert = bInvert; }
123  bool IsInvert() const { return mbInvert; }
124 
125  void SetTransparency( sal_uInt8 cTransparency ) { mcTransparency = cTransparency; }
126  sal_uInt8 GetTransparency() const { return mcTransparency; }
127 
128  bool IsSpecialDrawMode() const { return( meDrawMode != GraphicDrawMode::Standard ); }
129  bool IsMirrored() const { return mnMirrFlags != BmpMirrorFlags::NONE; }
130  bool IsCropped() const
131  {
132  return( mnLeftCrop != 0 || mnTopCrop != 0 ||
133  mnRightCrop != 0 || mnBottomCrop != 0 );
134  }
135  bool IsRotated() const { return( ( mnRotate10 % 3600 ) != 0 ); }
136  bool IsTransparent() const { return( mcTransparency > 0 ); }
137  bool IsAdjusted() const
138  {
139  return( mnLumPercent != 0 || mnContPercent != 0 || mnRPercent != 0 ||
140  mnGPercent != 0 || mnBPercent != 0 || mfGamma != 1.0 || mbInvert );
141  }
142 };
143 
145 {
146  friend class SdrGrafObj;
147 
148 private:
151  OUString maUserData;
152  std::unique_ptr<GrfSimpleCacheObj> mxSimpleCache;
153 
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;
162 
201  bool VCL_DLLPRIVATE ImplRenderTempTile(
202  VirtualDevice& rVDev,
203  int nNumTilesX,
204  int nNumTilesY,
205  const Size& rTileSizePixel,
206  const GraphicAttr* pAttr
207  );
208 
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
221  );
222 
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
230  );
231 
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
239  );
240 
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;
250 
251 public:
252  GraphicObject();
253  GraphicObject( const Graphic& rGraphic );
254  GraphicObject( const GraphicObject& rCacheObj );
255  ~GraphicObject();
256 
257  GraphicObject& operator=( const GraphicObject& rCacheObj );
258  bool operator==( const GraphicObject& rCacheObj ) const;
259  bool operator!=( const GraphicObject& rCacheObj ) const { return !( *this == rCacheObj ); }
260 
261  const Graphic& GetGraphic() const;
262  void SetGraphic( const Graphic& rGraphic, const GraphicObject* pCopyObj = nullptr);
263  void SetGraphic( const Graphic& rGraphic, const OUString& rLink );
264 
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
296 
297  void SetAttr( const GraphicAttr& rAttr );
298  const GraphicAttr& GetAttr() const { return maAttr; }
299 
300  bool HasUserData() const { return !maUserData.isEmpty(); }
301  void SetUserData();
302  void SetUserData( const OUString& rUserData );
303  const OUString& GetUserData() const { return maUserData; }
304 
305  OString GetUniqueID() const;
306 
307  GraphicType GetType() const;
308  Size GetPrefSize() const;
309  MapMode GetPrefMapMode() const;
310  bool IsTransparent() const;
311  bool IsAnimated() const;
312  bool IsEPS() const;
313 
314  bool Draw(
315  OutputDevice* pOut,
316  const Point& rPt,
317  const Size& rSz,
318  const GraphicAttr* pAttr = nullptr
319  );
320 
349  void DrawTiled(
350  OutputDevice* pOut,
351  const tools::Rectangle& rArea,
352  const Size& rSize,
353  const Size& rOffset,
354  int nTileCacheSize1D=128
355  );
356 
357  bool StartAnimation(
358  OutputDevice* pOut,
359  const Point& rPt,
360  const Size& rSz,
361  long nExtraData = 0,
362  OutputDevice* pFirstFrameOutDev = nullptr
363  );
364 
365  void StopAnimation( OutputDevice* pOut = nullptr, long nExtraData = 0 );
366 
367  static bool isGraphicObjectUniqueIdURL(OUString const & rURL);
368 
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;
379 };
380 
381 namespace vcl
382 {
383 namespace graphic
384 {
385 
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.
389 //
390 // Note: this implementation will cater for XNameContainer objects and deep inspect any containers
391 // if they exist
392 
393 VCL_DLLPUBLIC void SearchForGraphics(css::uno::Reference<css::uno::XInterface> const & rxInterface,
394  std::vector<css::uno::Reference<css::graphic::XGraphic>> & raGraphicList);
395 
396 }
397 } // end namespace vcl::graphic
398 
399 #endif // INCLUDED_VCL_GRAPHICOBJECT_HXX
400 
401 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsEPS() const
void SetTransparency(sal_uInt8 cTransparency)
void SetGamma(double fGamma)
bool IsInvert() const
const OUString & GetUserData() const
BmpMirrorFlags GetMirrorFlags() const
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
void SetInvert(bool bInvert)
long GetRightCrop() const
GraphicType
Definition: graph.hxx:36
bool IsMirrored() const
void SetMirrorFlags(BmpMirrorFlags nMirrFlags)
GraphicAttr maAttr
GraphicDrawMode GetDrawMode() const
long GetTopCrop() const
void SetDrawMode(GraphicDrawMode eDrawMode)
void SetGraphic(const Graphic &rGrf)
GraphicDrawMode
double GetGamma() const
bool IsTransparent() const
short GetChannelR() const
sal_uInt16 mnRotate10
short GetLuminance() const
bool operator==(const ItalicMatrix &a, const ItalicMatrix &b)
Definition: vclenum.hxx:203
long GetLeftCrop() const
bool IsAnimated() const
Graphic GetTransformedGraphic(SdrGrafObjTransformsAttrs nTransformFlags=SdrGrafObjTransformsAttrs::ALL) const
bool IsCropped() const
bool IsSpecialDrawMode() const
void SetContrast(short nContrastPercent)
const GraphicAttr & GetAttr() const
void SetCrop(long nLeft_100TH_MM, long nTop_100TH_MM, long nRight_100TH_MM, long nBottom_100TH_MM)
const Graphic & GetGraphic() const
bool IsRotated() const
short mnContPercent
GraphicDrawMode meDrawMode
void SetChannelG(short nChannelGPercent)
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:304
bool HasUserData() const
GraphicAdjustmentFlags
BmpMirrorFlags
Definition: bitmap.hxx:36
bool IsAdjusted() const
sal_uInt16 GetRotation() const
void SetChannelR(short nChannelRPercent)
OUString maUserData
void SetChannelB(short nChannelBPercent)
short mnLumPercent
short GetContrast() const
unsigned char sal_uInt8
sal_uInt8 mcTransparency
bool operator!=(const GraphicObject &rCacheObj) const
BmpMirrorFlags mnMirrFlags
void SetLuminance(short nLuminancePercent)
std::unique_ptr< GrfSimpleCacheObj > mxSimpleCache
bool operator!=(const GraphicAttr &rAttr) const
long GetBottomCrop() const
#define VCL_DLLPRIVATE
Definition: dllapi.h:31
void SearchForGraphics(uno::Reference< uno::XInterface > const &xInterface, std::vector< uno::Reference< css::graphic::XGraphic >> &raGraphicList)
SdrGrafObj & operator=(const SdrGrafObj &rObj)
short GetChannelG() const
short GetChannelB() const
void SetRotation(sal_uInt16 nRotate10)
sal_uInt8 GetTransparency() const
void StartAnimation()