vcl: 'horizontically'
[LibreOffice.git] / include / vcl / GraphicObject.hxx
blobd10b46b92c4cc8f8395222657436d941e7e122e2
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 #pragma once
22 #include <memory>
23 #include <vcl/graph.hxx>
24 #include <vcl/dllapi.h>
25 #include <o3tl/typed_flags_set.hxx>
27 #include <vcl/GraphicAttributes.hxx>
29 namespace com::sun::star::graphic { class XGraphic; }
31 // Adjustment defines
32 enum class GraphicAdjustmentFlags
34 NONE = 0x00,
35 DRAWMODE = 0x01,
36 COLORS = 0x02,
37 MIRROR = 0x04,
38 ROTATE = 0x08,
39 TRANSPARENCY = 0x10,
40 ALL = 0x1f,
42 namespace o3tl
44 template<> struct typed_flags<GraphicAdjustmentFlags> : is_typed_flags<GraphicAdjustmentFlags, 0x1f> {};
47 class VirtualDevice;
48 struct GrfSimpleCacheObj;
49 struct ImplTileInfo;
51 class VCL_DLLPUBLIC GraphicObject
53 friend class SdrGrafObj;
55 private:
56 Graphic maGraphic;
57 GraphicAttr maAttr;
58 OUString maUserData;
59 std::unique_ptr<GrfSimpleCacheObj> mxSimpleCache;
61 bool VCL_DLLPRIVATE ImplGetCropParams(
62 OutputDevice const * pOut,
63 Point& rPt,
64 Size& rSz,
65 const GraphicAttr* pAttr,
66 tools::PolyPolygon& rClipPolyPoly,
67 bool& bRectClipRegion
68 ) const;
70 /** Render a given number of tiles in an optimized way
72 This method recursively subdivides the tile rendering problem
73 in smaller parts, i.e. rendering output size x with few tiles
74 of size y, which in turn are generated from the original
75 bitmap in a recursive fashion. The subdivision size can be
76 controlled by the exponent argument, which specifies the
77 minimal number of smaller tiles used in one recursion
78 step. The resulting tile size is given as the integer number
79 of repetitions of the original bitmap along x and y. As the
80 exponent need not necessarily divide these numbers without
81 remainder, the repetition counts are effectively converted to
82 base-exponent numbers, where each place denotes the number of
83 times the corresponding tile size is rendered.
85 @param rVDev
86 Virtual device to render everything into
88 @param nNumTilesX
89 Number of original tiles to generate in x direction
91 @param nNumTilesY
92 Number of original tiles to generate in y direction
94 @param rTileSizePixel
95 Size in pixel of the original tile bitmap to render it in
97 @param pAttr
98 Graphic attributes to be used for rendering
100 @param nFlags
101 Graphic flags to be used for rendering
103 @param rCurrPos
104 Current output point for this recursion level (should start with (0,0))
106 @return true, if everything was successfully rendered.
108 bool VCL_DLLPRIVATE ImplRenderTempTile(
109 VirtualDevice& rVDev,
110 int nNumTilesX,
111 int nNumTilesY,
112 const Size& rTileSizePixel,
113 const GraphicAttr* pAttr
116 /// internally called by ImplRenderTempTile()
117 bool VCL_DLLPRIVATE ImplRenderTileRecursive(
118 VirtualDevice& rVDev,
119 int nExponent,
120 int nMSBFactor,
121 int nNumOrigTilesX,
122 int nNumOrigTilesY,
123 int nRemainderTilesX,
124 int nRemainderTilesY,
125 const Size& rTileSizePixel,
126 const GraphicAttr* pAttr,
127 ImplTileInfo& rTileInfo
130 bool VCL_DLLPRIVATE ImplDrawTiled(
131 OutputDevice* pOut,
132 const tools::Rectangle& rArea,
133 const Size& rSizePixel,
134 const Size& rOffset,
135 const GraphicAttr* pAttr,
136 int nTileCacheSize1D
139 bool VCL_DLLPRIVATE ImplDrawTiled(
140 OutputDevice& rOut,
141 const Point& rPos,
142 int nNumTilesX,
143 int nNumTilesY,
144 const Size& rTileSize,
145 const GraphicAttr* pAttr
148 void VCL_DLLPRIVATE ImplTransformBitmap(
149 BitmapEx& rBmpEx,
150 const GraphicAttr& rAttr,
151 const Size& rCropLeftTop,
152 const Size& rCropRightBottom,
153 const tools::Rectangle& rCropRect,
154 const Size& rDstSize,
155 bool bEnlarge
156 ) const;
158 public:
159 GraphicObject();
160 GraphicObject( const Graphic& rGraphic );
161 GraphicObject( const GraphicObject& rCacheObj );
162 ~GraphicObject();
164 GraphicObject& operator=( const GraphicObject& rCacheObj );
165 bool operator==( const GraphicObject& rCacheObj ) const;
166 bool operator!=( const GraphicObject& rCacheObj ) const { return !( *this == rCacheObj ); }
168 const Graphic& GetGraphic() const;
169 void SetGraphic( const Graphic& rGraphic);
171 /** Get graphic transformed according to given attributes
173 This method returns a Graphic transformed, cropped and scaled
174 to the given parameters, ready to be rendered to printer or
175 display. The returned graphic has the same visual appearance
176 as if it had been drawn via GraphicObject::Draw() to a
177 specific output device.
179 @param rDestSize
180 Desired output size in logical coordinates. The mapmode to
181 interpret these logical coordinates in is given by the second
182 parameter, rDestMap.
184 @param rDestMap
185 Mapmode the output should be interpreted in. This is used to
186 interpret rDestSize, to set the appropriate PrefMapMode on the
187 returned Graphic, and to deal correctly with metafile graphics.
189 @param rAttr
190 Graphic attributes used to transform the graphic. This
191 includes cropping, rotation, mirroring, and various color
192 adjustment parameters.
194 @return the readily transformed Graphic
196 Graphic GetTransformedGraphic(
197 const Size& rDestSize,
198 const MapMode& rDestMap,
199 const GraphicAttr& rAttr
200 ) const;
201 Graphic GetTransformedGraphic( const GraphicAttr* pAttr ) const; // TODO: Change to Impl
203 void SetAttr( const GraphicAttr& rAttr );
204 const GraphicAttr& GetAttr() const { return maAttr; }
206 bool HasUserData() const { return !maUserData.isEmpty(); }
207 void SetUserData();
208 void SetUserData( const OUString& rUserData );
209 const OUString& GetUserData() const { return maUserData; }
211 OString GetUniqueID() const;
213 GraphicType GetType() const;
214 Size GetPrefSize() const;
215 MapMode GetPrefMapMode() const;
216 bool IsTransparent() const;
217 bool IsAnimated() const;
218 bool IsEPS() const;
220 bool Draw(
221 OutputDevice* pOut,
222 const Point& rPt,
223 const Size& rSz,
224 const GraphicAttr* pAttr = nullptr
227 /** Draw the graphic repeatedly into the given output rectangle
229 @param pOut
230 OutputDevice where the rendering should take place
232 @param rArea
233 The output area that is filled with tiled instances of this graphic
235 @param rSize
236 The actual size of a single tile
238 @param rOffset
239 Offset from the left, top position of rArea, where to start
240 the tiling. The upper left corner of the graphic tilings will
241 virtually start at this position. Concretely, only that many
242 tiles are drawn to completely fill the given output area.
244 @param nFlags
245 Optional rendering flags
247 @param nTileCacheSize1D
248 Optional dimension of the generated cache tiles. The pOut sees
249 a number of tile draws, which have approximately
250 nTileCacheSize1D times nTileCacheSize1D bitmap sizes if the
251 tile bitmap is smaller. Otherwise, the tile is drawn as
252 is. This is useful if e.g. you want only a few, very large
253 bitmap drawings appear on the outdev.
255 void DrawTiled(
256 OutputDevice* pOut,
257 const tools::Rectangle& rArea,
258 const Size& rSize,
259 const Size& rOffset,
260 int nTileCacheSize1D=128
263 bool StartAnimation(
264 OutputDevice* pOut,
265 const Point& rPt,
266 const Size& rSz,
267 tools::Long nExtraData = 0,
268 OutputDevice* pFirstFrameOutDev = nullptr
271 void StopAnimation( const OutputDevice* pOut = nullptr, tools::Long nExtraData = 0 );
273 static bool isGraphicObjectUniqueIdURL(OUString const & rURL);
275 // create CropScaling information
276 // fWidth, fHeight: object size
277 // f*Crop: crop values relative to original bitmap size
278 basegfx::B2DVector calculateCropScaling(
279 double fWidth,
280 double fHeight,
281 double fLeftCrop,
282 double fTopCrop,
283 double fRightCrop,
284 double fBottomCrop) const;
287 namespace vcl::graphic
290 // Will search an object ( e.g. a control ) for any 'ImageURL' or 'Graphic'
291 // properties and return graphics from the properties in a vector. ImageURL
292 // will be loaded from the URL.
294 // Note: this implementation will cater for XNameContainer objects and deep inspect any containers
295 // if they exist
297 VCL_DLLPUBLIC void SearchForGraphics(css::uno::Reference<css::uno::XInterface> const & rxInterface,
298 std::vector<css::uno::Reference<css::graphic::XGraphic>> & raGraphicList);
301 } // end namespace vcl::graphic
303 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */