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 <string_view>
24 #include <vcl/graph.hxx>
25 #include <vcl/dllapi.h>
26 #include <o3tl/typed_flags_set.hxx>
28 #include <vcl/GraphicAttributes.hxx>
30 namespace com::sun::star::graphic
{ class XGraphic
; }
33 enum class GraphicAdjustmentFlags
45 template<> struct typed_flags
<GraphicAdjustmentFlags
> : is_typed_flags
<GraphicAdjustmentFlags
, 0x1f> {};
49 struct GrfSimpleCacheObj
;
52 class VCL_DLLPUBLIC GraphicObject
54 friend class SdrGrafObj
;
60 std::unique_ptr
<GrfSimpleCacheObj
> mxSimpleCache
;
62 bool VCL_DLLPRIVATE
ImplGetCropParams(
63 const OutputDevice
& rOut
,
66 const GraphicAttr
* pAttr
,
67 tools::PolyPolygon
& rClipPolyPoly
,
71 /** Render a given number of tiles in an optimized way
73 This method recursively subdivides the tile rendering problem
74 in smaller parts, i.e. rendering output size x with few tiles
75 of size y, which in turn are generated from the original
76 bitmap in a recursive fashion. The subdivision size can be
77 controlled by the exponent argument, which specifies the
78 minimal number of smaller tiles used in one recursion
79 step. The resulting tile size is given as the integer number
80 of repetitions of the original bitmap along x and y. As the
81 exponent need not necessarily divide these numbers without
82 remainder, the repetition counts are effectively converted to
83 base-exponent numbers, where each place denotes the number of
84 times the corresponding tile size is rendered.
87 Virtual device to render everything into
90 Number of original tiles to generate in x direction
93 Number of original tiles to generate in y direction
96 Size in pixel of the original tile bitmap to render it in
99 Graphic attributes to be used for rendering
102 Graphic flags to be used for rendering
105 Current output point for this recursion level (should start with (0,0))
107 @return true, if everything was successfully rendered.
109 bool VCL_DLLPRIVATE
ImplRenderTempTile(
110 VirtualDevice
& rVDev
,
113 const Size
& rTileSizePixel
,
114 const GraphicAttr
* pAttr
117 /// internally called by ImplRenderTempTile()
118 bool VCL_DLLPRIVATE
ImplRenderTileRecursive(
119 VirtualDevice
& rVDev
,
124 int nRemainderTilesX
,
125 int nRemainderTilesY
,
126 const Size
& rTileSizePixel
,
127 const GraphicAttr
* pAttr
,
128 ImplTileInfo
& rTileInfo
131 bool VCL_DLLPRIVATE
ImplDrawTiled(
133 const tools::Rectangle
& rArea
,
134 const Size
& rSizePixel
,
136 const GraphicAttr
* pAttr
,
140 bool VCL_DLLPRIVATE
ImplDrawTiled(
145 const Size
& rTileSize
,
146 const GraphicAttr
* pAttr
149 void VCL_DLLPRIVATE
ImplTransformBitmap(
151 const GraphicAttr
& rAttr
,
152 const Size
& rCropLeftTop
,
153 const Size
& rCropRightBottom
,
154 const tools::Rectangle
& rCropRect
,
155 const Size
& rDstSize
,
161 GraphicObject( Graphic aGraphic
);
162 GraphicObject( const GraphicObject
& rCacheObj
);
165 GraphicObject
& operator=( const GraphicObject
& rCacheObj
);
166 bool operator==( const GraphicObject
& rCacheObj
) const;
167 bool operator!=( const GraphicObject
& rCacheObj
) const { return !( *this == rCacheObj
); }
169 const Graphic
& GetGraphic() const;
170 void SetGraphic( const Graphic
& rGraphic
);
172 /** Get graphic transformed according to given attributes
174 This method returns a Graphic transformed, cropped and scaled
175 to the given parameters, ready to be rendered to printer or
176 display. The returned graphic has the same visual appearance
177 as if it had been drawn via GraphicObject::Draw() to a
178 specific output device.
181 Desired output size in logical coordinates. The mapmode to
182 interpret these logical coordinates in is given by the second
186 Mapmode the output should be interpreted in. This is used to
187 interpret rDestSize, to set the appropriate PrefMapMode on the
188 returned Graphic, and to deal correctly with metafile graphics.
191 Graphic attributes used to transform the graphic. This
192 includes cropping, rotation, mirroring, and various color
193 adjustment parameters.
195 @return the readily transformed Graphic
197 Graphic
GetTransformedGraphic(
198 const Size
& rDestSize
,
199 const MapMode
& rDestMap
,
200 const GraphicAttr
& rAttr
202 Graphic
GetTransformedGraphic( const GraphicAttr
* pAttr
) const; // TODO: Change to Impl
204 void SetAttr( const GraphicAttr
& rAttr
);
205 const GraphicAttr
& GetAttr() const { return maAttr
; }
207 bool HasUserData() const { return !maUserData
.isEmpty(); }
209 void SetUserData( const OUString
& rUserData
);
210 const OUString
& GetUserData() const { return maUserData
; }
212 OString
GetUniqueID() const;
214 GraphicType
GetType() const;
215 Size
GetPrefSize() const;
216 MapMode
GetPrefMapMode() const;
217 bool IsTransparent() const;
218 bool IsAnimated() const;
221 bool Draw(OutputDevice
& rOut
,
224 const GraphicAttr
* pAttr
= nullptr) const;
226 /** Draw the graphic repeatedly into the given output rectangle
229 OutputDevice where the rendering should take place
232 The output area that is filled with tiled instances of this graphic
235 The actual size of a single tile
238 Offset from the left, top position of rArea, where to start
239 the tiling. The upper left corner of the graphic tilings will
240 virtually start at this position. Concretely, only that many
241 tiles are drawn to completely fill the given output area.
244 Optional rendering flags
246 @param nTileCacheSize1D
247 Optional dimension of the generated cache tiles. The pOut sees
248 a number of tile draws, which have approximately
249 nTileCacheSize1D times nTileCacheSize1D bitmap sizes if the
250 tile bitmap is smaller. Otherwise, the tile is drawn as
251 is. This is useful if e.g. you want only a few, very large
252 bitmap drawings appear on the outdev.
256 const tools::Rectangle
& rArea
,
259 int nTileCacheSize1D
=128
266 tools::Long nExtraData
= 0,
267 OutputDevice
* pFirstFrameOutDev
= nullptr
270 void StopAnimation( const OutputDevice
* pOut
= nullptr, tools::Long nExtraData
= 0 );
272 static bool isGraphicObjectUniqueIdURL(std::u16string_view rURL
);
274 // create CropScaling information
275 // fWidth, fHeight: object size
276 // f*Crop: crop values relative to original bitmap size
277 basegfx::B2DVector
calculateCropScaling(
283 double fBottomCrop
) const;
286 namespace vcl::graphic
289 // Will search an object ( e.g. a control ) for any 'ImageURL' or 'Graphic'
290 // properties and return graphics from the properties in a vector. ImageURL
291 // will be loaded from the URL.
293 // Note: this implementation will cater for XNameContainer objects and deep inspect any containers
296 VCL_DLLPUBLIC
void SearchForGraphics(css::uno::Reference
<css::uno::XInterface
> const & rxInterface
,
297 std::vector
<css::uno::Reference
<css::graphic::XGraphic
>> & raGraphicList
);
300 } // end namespace vcl::graphic
302 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */