Branch data Line data Source code
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 : : #include <drawinglayer/primitive2d/wallpaperprimitive2d.hxx>
21 : : #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
22 : : #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
23 : : #include <drawinglayer/primitive2d/fillbitmapprimitive2d.hxx>
24 : : #include <basegfx/polygon/b2dpolygontools.hxx>
25 : : #include <basegfx/polygon/b2dpolygon.hxx>
26 : : #include <drawinglayer/primitive2d/maskprimitive2d.hxx>
27 : :
28 : : //////////////////////////////////////////////////////////////////////////////
29 : :
30 : : namespace drawinglayer
31 : : {
32 : : namespace primitive2d
33 : : {
34 : 0 : Primitive2DSequence WallpaperBitmapPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
35 : : {
36 : 0 : Primitive2DSequence aRetval;
37 : :
38 [ # # ][ # # ]: 0 : if(!getLocalObjectRange().isEmpty() && !getBitmapEx().IsEmpty())
[ # # ][ # # ]
[ # # ]
39 : : {
40 : : // get bitmap PIXEL size
41 : 0 : const Size& rPixelSize = getBitmapEx().GetSizePixel();
42 : :
43 [ # # ][ # # ]: 0 : if(rPixelSize.Width() > 0 && rPixelSize.Height() > 0)
[ # # ]
44 : : {
45 [ # # ]: 0 : if(WALLPAPER_SCALE == getWallpaperStyle())
46 : : {
47 : : // shortcut for scale; use simple BitmapPrimitive2D
48 [ # # ]: 0 : basegfx::B2DHomMatrix aObjectTransform;
49 : :
50 [ # # ][ # # ]: 0 : aObjectTransform.set(0, 0, getLocalObjectRange().getWidth());
51 [ # # ][ # # ]: 0 : aObjectTransform.set(1, 1, getLocalObjectRange().getHeight());
52 [ # # ][ # # ]: 0 : aObjectTransform.set(0, 2, getLocalObjectRange().getMinX());
53 [ # # ][ # # ]: 0 : aObjectTransform.set(1, 2, getLocalObjectRange().getMinY());
54 : :
55 : : Primitive2DReference xReference(
56 : : new BitmapPrimitive2D(
57 : : getBitmapEx(),
58 [ # # ][ # # ]: 0 : aObjectTransform));
[ # # ]
59 : :
60 [ # # ][ # # ]: 0 : aRetval = Primitive2DSequence(&xReference, 1);
[ # # ][ # # ]
61 : : }
62 : : else
63 : : {
64 : : // transform to logic size
65 [ # # ]: 0 : basegfx::B2DHomMatrix aInverseViewTransformation(getViewTransformation());
66 [ # # ]: 0 : aInverseViewTransformation.invert();
67 : 0 : basegfx::B2DVector aLogicSize(rPixelSize.Width(), rPixelSize.Height());
68 [ # # ][ # # ]: 0 : aLogicSize = aInverseViewTransformation * aLogicSize;
69 : :
70 : : // apply laout
71 [ # # ]: 0 : basegfx::B2DPoint aTargetTopLeft(getLocalObjectRange().getMinimum());
72 : 0 : bool bUseTargetTopLeft(true);
73 : 0 : bool bNeedsClipping(false);
74 : :
75 [ # # # # : 0 : switch(getWallpaperStyle())
# # # # #
# # ]
76 : : {
77 : : default: //case WALLPAPER_TILE :, also WALLPAPER_NULL and WALLPAPER_APPLICATIONGRADIENT
78 : : {
79 : 0 : bUseTargetTopLeft = false;
80 : 0 : break;
81 : : }
82 : : case WALLPAPER_SCALE :
83 : : {
84 : : // handled by shortcut above
85 : 0 : break;
86 : : }
87 : : case WALLPAPER_TOPLEFT :
88 : : {
89 : : // nothing to do
90 : 0 : break;
91 : : }
92 : : case WALLPAPER_TOP :
93 : : {
94 [ # # ]: 0 : const basegfx::B2DPoint aCenter(getLocalObjectRange().getCenter());
95 : 0 : aTargetTopLeft.setX(aCenter.getX() - (aLogicSize.getX() * 0.5));
96 : 0 : break;
97 : : }
98 : : case WALLPAPER_TOPRIGHT :
99 : : {
100 [ # # ]: 0 : aTargetTopLeft.setX(getLocalObjectRange().getMaxX() - aLogicSize.getX());
101 : 0 : break;
102 : : }
103 : : case WALLPAPER_LEFT :
104 : : {
105 [ # # ]: 0 : const basegfx::B2DPoint aCenter(getLocalObjectRange().getCenter());
106 : 0 : aTargetTopLeft.setY(aCenter.getY() - (aLogicSize.getY() * 0.5));
107 : 0 : break;
108 : : }
109 : : case WALLPAPER_CENTER :
110 : : {
111 [ # # ]: 0 : const basegfx::B2DPoint aCenter(getLocalObjectRange().getCenter());
112 [ # # ]: 0 : aTargetTopLeft = aCenter - (aLogicSize * 0.5);
113 : 0 : break;
114 : : }
115 : : case WALLPAPER_RIGHT :
116 : : {
117 [ # # ]: 0 : const basegfx::B2DPoint aCenter(getLocalObjectRange().getCenter());
118 [ # # ]: 0 : aTargetTopLeft.setX(getLocalObjectRange().getMaxX() - aLogicSize.getX());
119 : 0 : aTargetTopLeft.setY(aCenter.getY() - (aLogicSize.getY() * 0.5));
120 : 0 : break;
121 : : }
122 : : case WALLPAPER_BOTTOMLEFT :
123 : : {
124 [ # # ]: 0 : aTargetTopLeft.setY(getLocalObjectRange().getMaxY() - aLogicSize.getY());
125 : 0 : break;
126 : : }
127 : : case WALLPAPER_BOTTOM :
128 : : {
129 [ # # ]: 0 : const basegfx::B2DPoint aCenter(getLocalObjectRange().getCenter());
130 : 0 : aTargetTopLeft.setX(aCenter.getX() - (aLogicSize.getX() * 0.5));
131 [ # # ]: 0 : aTargetTopLeft.setY(getLocalObjectRange().getMaxY() - aLogicSize.getY());
132 : 0 : break;
133 : : }
134 : : case WALLPAPER_BOTTOMRIGHT :
135 : : {
136 [ # # ][ # # ]: 0 : aTargetTopLeft = getLocalObjectRange().getMaximum() - aLogicSize;
137 : 0 : break;
138 : : }
139 : : }
140 : :
141 [ # # ]: 0 : if(bUseTargetTopLeft)
142 : : {
143 : : // fill target range
144 [ # # ]: 0 : const basegfx::B2DRange aTargetRange(aTargetTopLeft, aTargetTopLeft + aLogicSize);
145 : :
146 : : // create aligned, single BitmapPrimitive2D
147 [ # # ]: 0 : basegfx::B2DHomMatrix aObjectTransform;
148 : :
149 [ # # ][ # # ]: 0 : aObjectTransform.set(0, 0, aTargetRange.getWidth());
150 [ # # ][ # # ]: 0 : aObjectTransform.set(1, 1, aTargetRange.getHeight());
151 [ # # ][ # # ]: 0 : aObjectTransform.set(0, 2, aTargetRange.getMinX());
152 [ # # ][ # # ]: 0 : aObjectTransform.set(1, 2, aTargetRange.getMinY());
153 : :
154 : : Primitive2DReference xReference(
155 : : new BitmapPrimitive2D(
156 : : getBitmapEx(),
157 [ # # ][ # # ]: 0 : aObjectTransform));
[ # # ]
158 [ # # ][ # # ]: 0 : aRetval = Primitive2DSequence(&xReference, 1);
[ # # ]
159 : :
160 : : // clip when not completely inside object range
161 [ # # ][ # # ]: 0 : bNeedsClipping = !getLocalObjectRange().isInside(aTargetRange);
162 : : }
163 : : else
164 : : {
165 : : // WALLPAPER_TILE, WALLPAPER_NULL, WALLPAPER_APPLICATIONGRADIENT
166 : : // convert to relative positions
167 : : const basegfx::B2DVector aRelativeSize(
168 [ # # ]: 0 : aLogicSize.getX() / (getLocalObjectRange().getWidth() ? getLocalObjectRange().getWidth() : 1.0),
169 [ # # ][ # # ]: 0 : aLogicSize.getY() / (getLocalObjectRange().getHeight() ? getLocalObjectRange().getHeight() : 1.0));
[ # # ]
[ # # # # ]
170 : 0 : basegfx::B2DPoint aRelativeTopLeft(0.0, 0.0);
171 : :
172 [ # # ]: 0 : if(WALLPAPER_TILE != getWallpaperStyle())
173 : : {
174 : 0 : aRelativeTopLeft.setX(0.5 - aRelativeSize.getX());
175 : 0 : aRelativeTopLeft.setY(0.5 - aRelativeSize.getY());
176 : : }
177 : :
178 : : // prepare FillBitmapAttribute
179 : : const attribute::FillBitmapAttribute aFillBitmapAttribute(
180 : 0 : getBitmapEx(),
181 : : aRelativeTopLeft,
182 : : aRelativeSize,
183 [ # # ]: 0 : true);
184 : :
185 : : // create ObjectTransform
186 [ # # ]: 0 : basegfx::B2DHomMatrix aObjectTransform;
187 : :
188 [ # # ][ # # ]: 0 : aObjectTransform.set(0, 0, getLocalObjectRange().getWidth());
189 [ # # ][ # # ]: 0 : aObjectTransform.set(1, 1, getLocalObjectRange().getHeight());
190 [ # # ][ # # ]: 0 : aObjectTransform.set(0, 2, getLocalObjectRange().getMinX());
191 [ # # ][ # # ]: 0 : aObjectTransform.set(1, 2, getLocalObjectRange().getMinY());
192 : :
193 : : // create FillBitmapPrimitive
194 : : const drawinglayer::primitive2d::Primitive2DReference xFillBitmap(
195 : : new drawinglayer::primitive2d::FillBitmapPrimitive2D(
196 : : aObjectTransform,
197 [ # # ][ # # ]: 0 : aFillBitmapAttribute));
[ # # ]
198 [ # # ][ # # ]: 0 : aRetval = Primitive2DSequence(&xFillBitmap, 1);
[ # # ]
199 : :
200 : : // always embed tiled fill to clipping
201 [ # # ][ # # ]: 0 : bNeedsClipping = true;
202 : : }
203 : :
204 [ # # ]: 0 : if(bNeedsClipping)
205 : : {
206 : : // embed to clipping; this is necessary for tiled fills
207 : : const basegfx::B2DPolyPolygon aPolyPolygon(
208 [ # # ][ # # ]: 0 : basegfx::tools::createPolygonFromRect(getLocalObjectRange()));
[ # # ]
209 : : const drawinglayer::primitive2d::Primitive2DReference xClippedFill(
210 : : new drawinglayer::primitive2d::MaskPrimitive2D(
211 : : aPolyPolygon,
212 [ # # ][ # # ]: 0 : aRetval));
[ # # ]
213 [ # # ][ # # ]: 0 : aRetval = Primitive2DSequence(&xClippedFill, 1);
[ # # ][ # # ]
214 [ # # ]: 0 : }
215 : : }
216 : : }
217 : : }
218 : :
219 : 0 : return aRetval;
220 : : }
221 : :
222 : 0 : WallpaperBitmapPrimitive2D::WallpaperBitmapPrimitive2D(
223 : : const basegfx::B2DRange& rObjectRange,
224 : : const BitmapEx& rBitmapEx,
225 : : WallpaperStyle eWallpaperStyle)
226 : : : ViewTransformationDependentPrimitive2D(),
227 : : maObjectRange(rObjectRange),
228 : : maBitmapEx(rBitmapEx),
229 [ # # ]: 0 : meWallpaperStyle(eWallpaperStyle)
230 : : {
231 : 0 : }
232 : :
233 : 0 : bool WallpaperBitmapPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
234 : : {
235 [ # # ]: 0 : if(ViewTransformationDependentPrimitive2D::operator==(rPrimitive))
236 : : {
237 : 0 : const WallpaperBitmapPrimitive2D& rCompare = (WallpaperBitmapPrimitive2D&)rPrimitive;
238 : :
239 : 0 : return (getLocalObjectRange() == rCompare.getLocalObjectRange()
240 : 0 : && getBitmapEx() == rCompare.getBitmapEx()
241 [ # # ]: 0 : && getWallpaperStyle() == rCompare.getWallpaperStyle());
[ # # # # ]
242 : : }
243 : :
244 : 0 : return false;
245 : : }
246 : :
247 : 0 : basegfx::B2DRange WallpaperBitmapPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const
248 : : {
249 : 0 : return getLocalObjectRange();
250 : : }
251 : :
252 : : // provide unique ID
253 : 0 : ImplPrimitrive2DIDBlock(WallpaperBitmapPrimitive2D, PRIMITIVE2D_ID_WALLPAPERBITMAPPRIMITIVE2D)
254 : : } // end of namespace primitive2d
255 : : } // end of namespace drawinglayer
256 : :
257 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|