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 <vcl/dllapi.h>
25 #include <o3tl/typed_flags_set.hxx>
27 #include <vcl/GraphicAttributes.hxx>
29 namespace com::sun::star::graphic
{ class XGraphic
; }
32 enum class GraphicAdjustmentFlags
44 template<> struct typed_flags
<GraphicAdjustmentFlags
> : is_typed_flags
<GraphicAdjustmentFlags
, 0x1f> {};
48 struct GrfSimpleCacheObj
;
51 class VCL_DLLPUBLIC GraphicObject
53 friend class SdrGrafObj
;
59 std::unique_ptr
<GrfSimpleCacheObj
> mxSimpleCache
;
61 bool VCL_DLLPRIVATE
ImplGetCropParams(
62 OutputDevice
const * pOut
,
65 const GraphicAttr
* pAttr
,
66 tools::PolyPolygon
& rClipPolyPoly
,
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.
86 Virtual device to render everything into
89 Number of original tiles to generate in x direction
92 Number of original tiles to generate in y direction
95 Size in pixel of the original tile bitmap to render it in
98 Graphic attributes to be used for rendering
101 Graphic flags to be used for rendering
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
,
112 const Size
& rTileSizePixel
,
113 const GraphicAttr
* pAttr
116 /// internally called by ImplRenderTempTile()
117 bool VCL_DLLPRIVATE
ImplRenderTileRecursive(
118 VirtualDevice
& rVDev
,
123 int nRemainderTilesX
,
124 int nRemainderTilesY
,
125 const Size
& rTileSizePixel
,
126 const GraphicAttr
* pAttr
,
127 ImplTileInfo
& rTileInfo
130 bool VCL_DLLPRIVATE
ImplDrawTiled(
132 const tools::Rectangle
& rArea
,
133 const Size
& rSizePixel
,
135 const GraphicAttr
* pAttr
,
139 bool VCL_DLLPRIVATE
ImplDrawTiled(
144 const Size
& rTileSize
,
145 const GraphicAttr
* pAttr
148 void VCL_DLLPRIVATE
ImplTransformBitmap(
150 const GraphicAttr
& rAttr
,
151 const Size
& rCropLeftTop
,
152 const Size
& rCropRightBottom
,
153 const tools::Rectangle
& rCropRect
,
154 const Size
& rDstSize
,
160 GraphicObject( const Graphic
& rGraphic
);
161 GraphicObject( const GraphicObject
& rCacheObj
);
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.
180 Desired output size in logical coordinates. The mapmode to
181 interpret these logical coordinates in is given by the second
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.
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
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(); }
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;
224 const GraphicAttr
* pAttr
= nullptr
227 /** Draw the graphic repeatedly into the given output rectangle
230 OutputDevice where the rendering should take place
233 The output area that is filled with tiled instances of this graphic
236 The actual size of a single tile
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.
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.
257 const tools::Rectangle
& rArea
,
260 int nTileCacheSize1D
=128
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(
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
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: */