LibreOffice Module drawinglayer (master) 1
wallpaperprimitive2d.cxx
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
28#include <vcl/graph.hxx>
30
31
33{
35 {
37
38 if(!getLocalObjectRange().isEmpty() && !getBitmapEx().IsEmpty())
39 {
40 // get bitmap PIXEL size
41 const Size& rPixelSize = getBitmapEx().GetSizePixel();
42
43 if(rPixelSize.Width() > 0 && rPixelSize.Height() > 0)
44 {
45 if(WallpaperStyle::Scale == getWallpaperStyle())
46 {
47 // shortcut for scale; use simple BitmapPrimitive2D
48 basegfx::B2DHomMatrix aObjectTransform;
49
50 aObjectTransform.set(0, 0, getLocalObjectRange().getWidth());
51 aObjectTransform.set(1, 1, getLocalObjectRange().getHeight());
52 aObjectTransform.set(0, 2, getLocalObjectRange().getMinX());
53 aObjectTransform.set(1, 2, getLocalObjectRange().getMinY());
54
55 Primitive2DReference xReference(
58 aObjectTransform));
59
60 aRetval = xReference;
61 }
62 else
63 {
64 // transform to logic size
65 basegfx::B2DHomMatrix aInverseViewTransformation(getViewTransformation());
66 aInverseViewTransformation.invert();
67 basegfx::B2DVector aLogicSize(rPixelSize.Width(), rPixelSize.Height());
68 aLogicSize = aInverseViewTransformation * aLogicSize;
69
70 // apply layout
71 basegfx::B2DPoint aTargetTopLeft(getLocalObjectRange().getMinimum());
72 bool bUseTargetTopLeft(true);
73 bool bNeedsClipping(false);
74
75 switch(getWallpaperStyle())
76 {
77 default: //case WallpaperStyle::Tile :, also WallpaperStyle::NONE and WallpaperStyle::ApplicationGradient
78 {
79 bUseTargetTopLeft = false;
80 break;
81 }
82 case WallpaperStyle::Scale :
83 {
84 // handled by shortcut above
85 break;
86 }
87 case WallpaperStyle::TopLeft :
88 {
89 // nothing to do
90 break;
91 }
92 case WallpaperStyle::Top :
93 {
94 const basegfx::B2DPoint aCenter(getLocalObjectRange().getCenter());
95 aTargetTopLeft.setX(aCenter.getX() - (aLogicSize.getX() * 0.5));
96 break;
97 }
98 case WallpaperStyle::TopRight :
99 {
100 aTargetTopLeft.setX(getLocalObjectRange().getMaxX() - aLogicSize.getX());
101 break;
102 }
103 case WallpaperStyle::Left :
104 {
105 const basegfx::B2DPoint aCenter(getLocalObjectRange().getCenter());
106 aTargetTopLeft.setY(aCenter.getY() - (aLogicSize.getY() * 0.5));
107 break;
108 }
109 case WallpaperStyle::Center :
110 {
111 const basegfx::B2DPoint aCenter(getLocalObjectRange().getCenter());
112 aTargetTopLeft = aCenter - (aLogicSize * 0.5);
113 break;
114 }
115 case WallpaperStyle::Right :
116 {
117 const basegfx::B2DPoint aCenter(getLocalObjectRange().getCenter());
118 aTargetTopLeft.setX(getLocalObjectRange().getMaxX() - aLogicSize.getX());
119 aTargetTopLeft.setY(aCenter.getY() - (aLogicSize.getY() * 0.5));
120 break;
121 }
122 case WallpaperStyle::BottomLeft :
123 {
124 aTargetTopLeft.setY(getLocalObjectRange().getMaxY() - aLogicSize.getY());
125 break;
126 }
127 case WallpaperStyle::Bottom :
128 {
129 const basegfx::B2DPoint aCenter(getLocalObjectRange().getCenter());
130 aTargetTopLeft.setX(aCenter.getX() - (aLogicSize.getX() * 0.5));
131 aTargetTopLeft.setY(getLocalObjectRange().getMaxY() - aLogicSize.getY());
132 break;
133 }
134 case WallpaperStyle::BottomRight :
135 {
136 aTargetTopLeft = getLocalObjectRange().getMaximum() - aLogicSize;
137 break;
138 }
139 }
140
141 if(bUseTargetTopLeft)
142 {
143 // fill target range
144 const basegfx::B2DRange aTargetRange(aTargetTopLeft, aTargetTopLeft + aLogicSize);
145
146 // create aligned, single BitmapPrimitive2D
147 basegfx::B2DHomMatrix aObjectTransform;
148
149 aObjectTransform.set(0, 0, aTargetRange.getWidth());
150 aObjectTransform.set(1, 1, aTargetRange.getHeight());
151 aObjectTransform.set(0, 2, aTargetRange.getMinX());
152 aObjectTransform.set(1, 2, aTargetRange.getMinY());
153
154 Primitive2DReference xReference(
156 getBitmapEx(),
157 aObjectTransform));
158 aRetval = xReference;
159
160 // clip when not completely inside object range
161 bNeedsClipping = !getLocalObjectRange().isInside(aTargetRange);
162 }
163 else
164 {
165 // WallpaperStyle::Tile, WallpaperStyle::NONE, WallpaperStyle::ApplicationGradient
166 // convert to relative positions
167 const basegfx::B2DVector aRelativeSize(
168 aLogicSize.getX() / (getLocalObjectRange().getWidth() ? getLocalObjectRange().getWidth() : 1.0),
169 aLogicSize.getY() / (getLocalObjectRange().getHeight() ? getLocalObjectRange().getHeight() : 1.0));
170 basegfx::B2DPoint aRelativeTopLeft(0.0, 0.0);
171
172 if(WallpaperStyle::Tile != getWallpaperStyle())
173 {
174 aRelativeTopLeft.setX(0.5 - aRelativeSize.getX());
175 aRelativeTopLeft.setY(0.5 - aRelativeSize.getY());
176 }
177
178 // prepare FillGraphicAttribute
179 const attribute::FillGraphicAttribute aFillGraphicAttribute(
181 basegfx::B2DRange(aRelativeTopLeft, aRelativeTopLeft+ aRelativeSize),
182 true);
183
184 // create ObjectTransform
185 const basegfx::B2DHomMatrix aObjectTransform(
188 getLocalObjectRange().getMinimum()));
189
190 // create FillBitmapPrimitive
193 aObjectTransform,
194 aFillGraphicAttribute));
195 aRetval = xFillBitmap;
196
197 // always embed tiled fill to clipping
198 bNeedsClipping = true;
199 }
200
201 if(bNeedsClipping)
202 {
203 // embed to clipping; this is necessary for tiled fills
204 basegfx::B2DPolyPolygon aPolyPolygon(
208 std::move(aPolyPolygon),
209 { aRetval }));
210 aRetval = xClippedFill;
211 }
212 }
213 }
214 }
215
216 if (aRetval.is())
217 rContainer.push_back(aRetval);
218 }
219
221 const basegfx::B2DRange& rObjectRange,
222 const BitmapEx& rBitmapEx,
223 WallpaperStyle eWallpaperStyle)
224 : maObjectRange(rObjectRange),
225 maBitmapEx(rBitmapEx),
226 meWallpaperStyle(eWallpaperStyle)
227 {
228 }
229
231 {
232 if(ViewTransformationDependentPrimitive2D::operator==(rPrimitive))
233 {
234 const WallpaperBitmapPrimitive2D& rCompare = static_cast<const WallpaperBitmapPrimitive2D&>(rPrimitive);
235
236 return (getLocalObjectRange() == rCompare.getLocalObjectRange()
237 && getBitmapEx() == rCompare.getBitmapEx()
238 && getWallpaperStyle() == rCompare.getWallpaperStyle());
239 }
240
241 return false;
242 }
243
245 {
246 return getLocalObjectRange();
247 }
248
249 // provide unique ID
251 {
253 }
254
255} // end of namespace
256
257/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const Size & GetSizePixel() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
void set(sal_uInt16 nRow, sal_uInt16 nColumn, double fValue)
B2DPoint getMaximum() const
TYPE getWidth() const
TYPE getMinX() const
TYPE getMinY() const
bool isInside(const Tuple2D< TYPE > &rTuple) const
TYPE getHeight() const
TYPE getX() const
void setY(TYPE fY)
TYPE getY() const
void setX(TYPE fX)
css::geometry::RealRectangle2D getRange(const css::uno::Sequence< css::beans::PropertyValue > &rViewParameters)
The getRange implementation for UNO API will use getRange from this implementation.
const basegfx::B2DHomMatrix & getViewTransformation() const
data read access
WallpaperBitmapPrimitive2D(const basegfx::B2DRange &rObjectRange, const BitmapEx &rBitmapEx, WallpaperStyle eWallpaperStyle)
constructor
const basegfx::B2DRange & getLocalObjectRange() const
data read access
virtual bool operator==(const BasePrimitive2D &rPrimitive) const override
compare operator
virtual void create2DDecomposition(Primitive2DContainer &rContainer, const geometry::ViewInformation2D &rViewInformation) const override
create local decomposition
virtual sal_uInt32 getPrimitive2DID() const override
provide unique ID
virtual basegfx::B2DRange getB2DRange(const geometry::ViewInformation2D &rViewInformation) const override
get B2Drange
#define PRIMITIVE2D_ID_WALLPAPERBITMAPPRIMITIVE2D
B2DHomMatrix createScaleTranslateB2DHomMatrix(double fScaleX, double fScaleY, double fTranslateX, double fTranslateY)
B2DPolygon createPolygonFromRect(const B2DRectangle &rRect, double fRadiusX, double fRadiusY)
WallpaperStyle