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 :
21 : #include <svx/sdr/overlay/overlaytools.hxx>
22 : #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
23 : #include <basegfx/matrix/b2dhommatrix.hxx>
24 : #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
25 : #include <basegfx/polygon/b2dpolygon.hxx>
26 : #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
27 : #include <basegfx/polygon/b2dpolygontools.hxx>
28 : #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
29 : #include <drawinglayer/geometry/viewinformation2d.hxx>
30 : #include <basegfx/matrix/b2dhommatrixtools.hxx>
31 :
32 : //////////////////////////////////////////////////////////////////////////////
33 :
34 : namespace drawinglayer
35 : {
36 : namespace primitive2d
37 : {
38 0 : OverlayBitmapExPrimitive::OverlayBitmapExPrimitive(
39 : const BitmapEx& rBitmapEx,
40 : const basegfx::B2DPoint& rBasePosition,
41 : sal_uInt16 nCenterX,
42 : sal_uInt16 nCenterY)
43 : : DiscreteMetricDependentPrimitive2D(),
44 : maBitmapEx(rBitmapEx),
45 : maBasePosition(rBasePosition),
46 : mnCenterX(nCenterX),
47 0 : mnCenterY(nCenterY)
48 0 : {}
49 :
50 0 : Primitive2DSequence OverlayBitmapExPrimitive::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
51 : {
52 0 : Primitive2DSequence aRetval;
53 0 : const Size aBitmapSize(getBitmapEx().GetSizePixel());
54 :
55 0 : if(aBitmapSize.Width() && aBitmapSize.Height() && basegfx::fTools::more(getDiscreteUnit(), 0.0))
56 : {
57 : // calculate back from internal bitmap's extreme coordinates (the edges)
58 : // to logical coordinates. Only use a unified scaling value (getDiscreteUnit(),
59 : // the prepared one which expresses how many logic units form a discrete unit)
60 : // for this step. This primitive is to be displayed always unscaled (in it's pixel size)
61 : // and unrotated, more like a marker
62 0 : const double fLeft(((0.0 - getCenterX()) * getDiscreteUnit()) + getBasePosition().getX());
63 0 : const double fTop(((0.0 - getCenterY()) * getDiscreteUnit()) + getBasePosition().getY());
64 0 : const double fRight(((aBitmapSize.getWidth() - getCenterX()) * getDiscreteUnit()) + getBasePosition().getX());
65 0 : const double fBottom(((aBitmapSize.getHeight() - getCenterY()) * getDiscreteUnit()) + getBasePosition().getY());
66 :
67 : // create a BitmapPrimitive2D using those positions
68 0 : basegfx::B2DHomMatrix aTransform;
69 :
70 0 : aTransform.set(0, 0, fRight - fLeft);
71 0 : aTransform.set(1, 1, fBottom - fTop);
72 0 : aTransform.set(0, 2, fLeft);
73 0 : aTransform.set(1, 2, fTop);
74 :
75 0 : const Primitive2DReference aPrimitive(new BitmapPrimitive2D(getBitmapEx(), aTransform));
76 0 : aRetval = Primitive2DSequence(&aPrimitive, 1);
77 : }
78 :
79 0 : return aRetval;
80 : }
81 :
82 0 : bool OverlayBitmapExPrimitive::operator==( const BasePrimitive2D& rPrimitive ) const
83 : {
84 0 : if(DiscreteMetricDependentPrimitive2D::operator==(rPrimitive))
85 : {
86 0 : const OverlayBitmapExPrimitive& rCompare = static_cast< const OverlayBitmapExPrimitive& >(rPrimitive);
87 :
88 0 : return (getBitmapEx() == rCompare.getBitmapEx()
89 0 : && getBasePosition() == rCompare.getBasePosition()
90 0 : && getCenterX() == rCompare.getCenterX()
91 0 : && getCenterY() == rCompare.getCenterY());
92 : }
93 :
94 0 : return false;
95 : }
96 :
97 0 : ImplPrimitrive2DIDBlock(OverlayBitmapExPrimitive, PRIMITIVE2D_ID_OVERLAYBITMAPEXPRIMITIVE)
98 :
99 : } // end of namespace primitive2d
100 : } // end of namespace drawinglayer
101 :
102 : //////////////////////////////////////////////////////////////////////////////
103 :
104 : namespace drawinglayer
105 : {
106 : namespace primitive2d
107 : {
108 0 : OverlayCrosshairPrimitive::OverlayCrosshairPrimitive(
109 : const basegfx::B2DPoint& rBasePosition,
110 : const basegfx::BColor& rRGBColorA,
111 : const basegfx::BColor& rRGBColorB,
112 : double fDiscreteDashLength)
113 : : ViewportDependentPrimitive2D(),
114 : maBasePosition(rBasePosition),
115 : maRGBColorA(rRGBColorA),
116 : maRGBColorB(rRGBColorB),
117 0 : mfDiscreteDashLength(fDiscreteDashLength)
118 0 : {}
119 :
120 0 : Primitive2DSequence OverlayCrosshairPrimitive::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
121 : {
122 : // use the prepared Viewport information accessible using getViewport()
123 0 : Primitive2DSequence aRetval;
124 :
125 0 : if(!getViewport().isEmpty())
126 : {
127 0 : aRetval.realloc(2);
128 0 : basegfx::B2DPolygon aPolygon;
129 :
130 0 : aPolygon.append(basegfx::B2DPoint(getViewport().getMinX(), getBasePosition().getY()));
131 0 : aPolygon.append(basegfx::B2DPoint(getViewport().getMaxX(), getBasePosition().getY()));
132 :
133 0 : aRetval[0] = Primitive2DReference(
134 : new PolygonMarkerPrimitive2D(
135 : aPolygon,
136 : getRGBColorA(),
137 : getRGBColorB(),
138 0 : getDiscreteDashLength()));
139 :
140 0 : aPolygon.clear();
141 0 : aPolygon.append(basegfx::B2DPoint(getBasePosition().getX(), getViewport().getMinY()));
142 0 : aPolygon.append(basegfx::B2DPoint(getBasePosition().getX(), getViewport().getMaxY()));
143 :
144 0 : aRetval[1] = Primitive2DReference(
145 : new PolygonMarkerPrimitive2D(
146 : aPolygon,
147 : getRGBColorA(),
148 : getRGBColorB(),
149 0 : getDiscreteDashLength()));
150 : }
151 :
152 0 : return aRetval;
153 : }
154 :
155 0 : bool OverlayCrosshairPrimitive::operator==( const BasePrimitive2D& rPrimitive ) const
156 : {
157 0 : if(ViewportDependentPrimitive2D::operator==(rPrimitive))
158 : {
159 0 : const OverlayCrosshairPrimitive& rCompare = static_cast< const OverlayCrosshairPrimitive& >(rPrimitive);
160 :
161 0 : return (getBasePosition() == rCompare.getBasePosition()
162 0 : && getRGBColorA() == rCompare.getRGBColorA()
163 0 : && getRGBColorB() == rCompare.getRGBColorB()
164 0 : && getDiscreteDashLength() == rCompare.getDiscreteDashLength());
165 : }
166 :
167 0 : return false;
168 : }
169 :
170 0 : ImplPrimitrive2DIDBlock(OverlayCrosshairPrimitive, PRIMITIVE2D_ID_OVERLAYCROSSHAIRPRIMITIVE)
171 :
172 : } // end of namespace primitive2d
173 : } // end of namespace drawinglayer
174 :
175 : //////////////////////////////////////////////////////////////////////////////
176 :
177 : namespace drawinglayer
178 : {
179 : namespace primitive2d
180 : {
181 0 : OverlayHatchRectanglePrimitive::OverlayHatchRectanglePrimitive(
182 : const basegfx::B2DRange& rObjectRange,
183 : double fDiscreteHatchDistance,
184 : double fHatchRotation,
185 : const basegfx::BColor& rHatchColor,
186 : double fDiscreteGrow,
187 : double fDiscreteShrink,
188 : double fRotation)
189 : : DiscreteMetricDependentPrimitive2D(),
190 : maObjectRange(rObjectRange),
191 : mfDiscreteHatchDistance(fDiscreteHatchDistance),
192 : mfHatchRotation(fHatchRotation),
193 : maHatchColor(rHatchColor),
194 : mfDiscreteGrow(fDiscreteGrow),
195 : mfDiscreteShrink(fDiscreteShrink),
196 0 : mfRotation(fRotation)
197 0 : {}
198 :
199 0 : Primitive2DSequence OverlayHatchRectanglePrimitive::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
200 : {
201 0 : Primitive2DSequence aRetval;
202 :
203 0 : if(basegfx::fTools::more(getDiscreteUnit(), 0.0))
204 : {
205 0 : basegfx::B2DRange aInnerRange(getObjectRange());
206 0 : basegfx::B2DRange aOuterRange(getObjectRange());
207 0 : basegfx::B2DPolyPolygon aHatchPolyPolygon;
208 :
209 0 : aOuterRange.grow(getDiscreteUnit() * getDiscreteGrow());
210 0 : aInnerRange.grow(getDiscreteUnit() * -getDiscreteShrink());
211 :
212 0 : aHatchPolyPolygon.append(basegfx::tools::createPolygonFromRect(aOuterRange));
213 :
214 0 : if(!aInnerRange.isEmpty())
215 : {
216 0 : aHatchPolyPolygon.append(basegfx::tools::createPolygonFromRect(aInnerRange));
217 : }
218 :
219 0 : if(!basegfx::fTools::equalZero(getRotation()))
220 : {
221 : const basegfx::B2DHomMatrix aTransform(basegfx::tools::createRotateAroundPoint(
222 0 : getObjectRange().getMinX(), getObjectRange().getMinY(), getRotation()));
223 :
224 0 : aHatchPolyPolygon.transform(aTransform);
225 : }
226 :
227 0 : const basegfx::BColor aEmptyColor(0.0, 0.0, 0.0);
228 : const drawinglayer::attribute::FillHatchAttribute aFillHatchAttribute(
229 : drawinglayer::attribute::HATCHSTYLE_SINGLE,
230 0 : getDiscreteHatchDistance() * getDiscreteUnit(),
231 0 : getHatchRotation() - getRotation(),
232 0 : getHatchColor(),
233 0 : false);
234 : const Primitive2DReference aPrimitive(
235 : new PolyPolygonHatchPrimitive2D(
236 : aHatchPolyPolygon,
237 : aEmptyColor,
238 0 : aFillHatchAttribute));
239 :
240 0 : aRetval = Primitive2DSequence(&aPrimitive, 1);
241 : }
242 :
243 0 : return aRetval;
244 : }
245 :
246 0 : bool OverlayHatchRectanglePrimitive::operator==( const BasePrimitive2D& rPrimitive ) const
247 : {
248 0 : if(DiscreteMetricDependentPrimitive2D::operator==(rPrimitive))
249 : {
250 0 : const OverlayHatchRectanglePrimitive& rCompare = static_cast< const OverlayHatchRectanglePrimitive& >(rPrimitive);
251 :
252 0 : return (getObjectRange() == rCompare.getObjectRange()
253 0 : && getDiscreteHatchDistance() == rCompare.getDiscreteHatchDistance()
254 0 : && getHatchRotation() == rCompare.getHatchRotation()
255 0 : && getHatchColor() == rCompare.getHatchColor()
256 0 : && getDiscreteGrow() == rCompare.getDiscreteGrow()
257 0 : && getDiscreteShrink() == rCompare.getDiscreteShrink()
258 0 : && getRotation() == rCompare.getRotation());
259 : }
260 :
261 0 : return false;
262 : }
263 :
264 0 : ImplPrimitrive2DIDBlock(OverlayHatchRectanglePrimitive, PRIMITIVE2D_ID_OVERLAYHATCHRECTANGLEPRIMITIVE)
265 :
266 : } // end of namespace primitive2d
267 : } // end of namespace drawinglayer
268 :
269 : //////////////////////////////////////////////////////////////////////////////
270 :
271 : namespace drawinglayer
272 : {
273 : namespace primitive2d
274 : {
275 0 : OverlayHelplineStripedPrimitive::OverlayHelplineStripedPrimitive(
276 : const basegfx::B2DPoint& rBasePosition,
277 : HelplineStyle eStyle,
278 : const basegfx::BColor& rRGBColorA,
279 : const basegfx::BColor& rRGBColorB,
280 : double fDiscreteDashLength)
281 : : ViewportDependentPrimitive2D(),
282 : maBasePosition(rBasePosition),
283 : meStyle(eStyle),
284 : maRGBColorA(rRGBColorA),
285 : maRGBColorB(rRGBColorB),
286 0 : mfDiscreteDashLength(fDiscreteDashLength)
287 0 : {}
288 :
289 0 : Primitive2DSequence OverlayHelplineStripedPrimitive::create2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
290 : {
291 : // use the prepared Viewport information accessible using getViewport()
292 0 : Primitive2DSequence aRetval;
293 :
294 0 : if(!getViewport().isEmpty())
295 : {
296 0 : switch(getStyle())
297 : {
298 : case HELPLINESTYLE_VERTICAL :
299 : {
300 0 : aRetval.realloc(1);
301 0 : basegfx::B2DPolygon aLine;
302 :
303 0 : aLine.append(basegfx::B2DPoint(getBasePosition().getX(), getViewport().getMinY()));
304 0 : aLine.append(basegfx::B2DPoint(getBasePosition().getX(), getViewport().getMaxY()));
305 :
306 0 : aRetval[0] = Primitive2DReference(
307 : new PolygonMarkerPrimitive2D(
308 : aLine,
309 : getRGBColorA(),
310 : getRGBColorB(),
311 0 : getDiscreteDashLength()));
312 0 : break;
313 : }
314 :
315 : case HELPLINESTYLE_HORIZONTAL :
316 : {
317 0 : aRetval.realloc(1);
318 0 : basegfx::B2DPolygon aLine;
319 :
320 0 : aLine.append(basegfx::B2DPoint(getViewport().getMinX(), getBasePosition().getY()));
321 0 : aLine.append(basegfx::B2DPoint(getViewport().getMaxX(), getBasePosition().getY()));
322 :
323 0 : aRetval[0] = Primitive2DReference(
324 : new PolygonMarkerPrimitive2D(
325 : aLine,
326 : getRGBColorA(),
327 : getRGBColorB(),
328 0 : getDiscreteDashLength()));
329 0 : break;
330 : }
331 :
332 : default: // case HELPLINESTYLE_POINT :
333 : {
334 0 : const double fDiscreteUnit((rViewInformation.getInverseObjectToViewTransformation() * basegfx::B2DVector(1.0, 0.0)).getLength());
335 0 : aRetval.realloc(2);
336 0 : basegfx::B2DPolygon aLineA, aLineB;
337 :
338 0 : aLineA.append(basegfx::B2DPoint(getBasePosition().getX(), getBasePosition().getY() - fDiscreteUnit));
339 0 : aLineA.append(basegfx::B2DPoint(getBasePosition().getX(), getBasePosition().getY() + fDiscreteUnit));
340 :
341 0 : aRetval[0] = Primitive2DReference(
342 : new PolygonMarkerPrimitive2D(
343 : aLineA,
344 : getRGBColorA(),
345 : getRGBColorB(),
346 0 : getDiscreteDashLength()));
347 :
348 0 : aLineB.append(basegfx::B2DPoint(getBasePosition().getX() - fDiscreteUnit, getBasePosition().getY()));
349 0 : aLineB.append(basegfx::B2DPoint(getBasePosition().getX() + fDiscreteUnit, getBasePosition().getY()));
350 :
351 0 : aRetval[1] = Primitive2DReference(
352 : new PolygonMarkerPrimitive2D(
353 : aLineB,
354 : getRGBColorA(),
355 : getRGBColorB(),
356 0 : getDiscreteDashLength()));
357 :
358 0 : break;
359 : }
360 : }
361 : }
362 :
363 0 : return aRetval;
364 : }
365 :
366 0 : bool OverlayHelplineStripedPrimitive::operator==( const BasePrimitive2D& rPrimitive ) const
367 : {
368 0 : if(ViewportDependentPrimitive2D::operator==(rPrimitive))
369 : {
370 0 : const OverlayHelplineStripedPrimitive& rCompare = static_cast< const OverlayHelplineStripedPrimitive& >(rPrimitive);
371 :
372 0 : return (getBasePosition() == rCompare.getBasePosition()
373 0 : && getStyle() == rCompare.getStyle()
374 0 : && getRGBColorA() == rCompare.getRGBColorA()
375 0 : && getRGBColorB() == rCompare.getRGBColorB()
376 0 : && getDiscreteDashLength() == rCompare.getDiscreteDashLength());
377 : }
378 :
379 0 : return false;
380 : }
381 :
382 0 : ImplPrimitrive2DIDBlock(OverlayHelplineStripedPrimitive, PRIMITIVE2D_ID_OVERLAYHELPLINESTRIPEDPRIMITIVE)
383 :
384 : } // end of namespace primitive2d
385 : } // end of namespace drawinglayer
386 :
387 : //////////////////////////////////////////////////////////////////////////////
388 :
389 : namespace drawinglayer
390 : {
391 : namespace primitive2d
392 : {
393 0 : OverlayRollingRectanglePrimitive::OverlayRollingRectanglePrimitive(
394 : const basegfx::B2DRange& aRollingRectangle,
395 : const basegfx::BColor& rRGBColorA,
396 : const basegfx::BColor& rRGBColorB,
397 : double fDiscreteDashLength)
398 : : ViewportDependentPrimitive2D(),
399 : maRollingRectangle(aRollingRectangle),
400 : maRGBColorA(rRGBColorA),
401 : maRGBColorB(rRGBColorB),
402 0 : mfDiscreteDashLength(fDiscreteDashLength)
403 0 : {}
404 :
405 0 : Primitive2DSequence OverlayRollingRectanglePrimitive::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
406 : {
407 : // use the prepared Viewport information accessible using getViewport()
408 0 : Primitive2DSequence aRetval;
409 :
410 0 : if(!getViewport().isEmpty())
411 : {
412 0 : basegfx::B2DPolygon aLine;
413 0 : aRetval.realloc(8);
414 :
415 : // Left lines
416 0 : aLine.append(basegfx::B2DPoint(getViewport().getMinX(), getRollingRectangle().getMinY()));
417 0 : aLine.append(basegfx::B2DPoint(getRollingRectangle().getMinX(), getRollingRectangle().getMinY()));
418 0 : aRetval[0] = Primitive2DReference(new PolygonMarkerPrimitive2D(aLine, getRGBColorA(), getRGBColorB(), getDiscreteDashLength()));
419 :
420 0 : aLine.clear();
421 0 : aLine.append(basegfx::B2DPoint(getViewport().getMinX(), getRollingRectangle().getMaxY()));
422 0 : aLine.append(basegfx::B2DPoint(getRollingRectangle().getMinX(), getRollingRectangle().getMaxY()));
423 0 : aRetval[1] = Primitive2DReference(new PolygonMarkerPrimitive2D(aLine, getRGBColorA(), getRGBColorB(), getDiscreteDashLength()));
424 :
425 : // Right lines
426 0 : aLine.clear();
427 0 : aLine.append(basegfx::B2DPoint(getRollingRectangle().getMaxX(), getRollingRectangle().getMinY()));
428 0 : aLine.append(basegfx::B2DPoint(getViewport().getMaxX(), getRollingRectangle().getMinY()));
429 0 : aRetval[2] = Primitive2DReference(new PolygonMarkerPrimitive2D(aLine, getRGBColorA(), getRGBColorB(), getDiscreteDashLength()));
430 :
431 0 : aLine.clear();
432 0 : aLine.append(basegfx::B2DPoint(getRollingRectangle().getMaxX(), getRollingRectangle().getMaxY()));
433 0 : aLine.append(basegfx::B2DPoint(getViewport().getMaxX(), getRollingRectangle().getMaxY()));
434 0 : aRetval[3] = Primitive2DReference(new PolygonMarkerPrimitive2D(aLine, getRGBColorA(), getRGBColorB(), getDiscreteDashLength()));
435 :
436 : // Top lines
437 0 : aLine.clear();
438 0 : aLine.append(basegfx::B2DPoint(getRollingRectangle().getMinX(), getViewport().getMinY()));
439 0 : aLine.append(basegfx::B2DPoint(getRollingRectangle().getMinX(), getRollingRectangle().getMinY()));
440 0 : aRetval[4] = Primitive2DReference(new PolygonMarkerPrimitive2D(aLine, getRGBColorA(), getRGBColorB(), getDiscreteDashLength()));
441 :
442 0 : aLine.clear();
443 0 : aLine.append(basegfx::B2DPoint(getRollingRectangle().getMaxX(), getViewport().getMinY()));
444 0 : aLine.append(basegfx::B2DPoint(getRollingRectangle().getMaxX(), getRollingRectangle().getMinY()));
445 0 : aRetval[5] = Primitive2DReference(new PolygonMarkerPrimitive2D(aLine, getRGBColorA(), getRGBColorB(), getDiscreteDashLength()));
446 :
447 : // Bottom lines
448 0 : aLine.clear();
449 0 : aLine.append(basegfx::B2DPoint(getRollingRectangle().getMinX(), getRollingRectangle().getMaxY()));
450 0 : aLine.append(basegfx::B2DPoint(getRollingRectangle().getMinX(), getViewport().getMaxY()));
451 0 : aRetval[6] = Primitive2DReference(new PolygonMarkerPrimitive2D(aLine, getRGBColorA(), getRGBColorB(), getDiscreteDashLength()));
452 :
453 0 : aLine.clear();
454 0 : aLine.append(basegfx::B2DPoint(getRollingRectangle().getMaxX(), getRollingRectangle().getMaxY()));
455 0 : aLine.append(basegfx::B2DPoint(getRollingRectangle().getMaxX(), getViewport().getMaxY()));
456 0 : aRetval[7] = Primitive2DReference(new PolygonMarkerPrimitive2D(aLine, getRGBColorA(), getRGBColorB(), getDiscreteDashLength()));
457 : }
458 :
459 0 : return aRetval;
460 : }
461 :
462 0 : bool OverlayRollingRectanglePrimitive::operator==( const BasePrimitive2D& rPrimitive ) const
463 : {
464 0 : if(ViewportDependentPrimitive2D::operator==(rPrimitive))
465 : {
466 0 : const OverlayRollingRectanglePrimitive& rCompare = static_cast< const OverlayRollingRectanglePrimitive& >(rPrimitive);
467 :
468 0 : return (getRollingRectangle() == rCompare.getRollingRectangle()
469 0 : && getRGBColorA() == rCompare.getRGBColorA()
470 0 : && getRGBColorB() == rCompare.getRGBColorB()
471 0 : && getDiscreteDashLength() == rCompare.getDiscreteDashLength());
472 : }
473 :
474 0 : return false;
475 : }
476 :
477 0 : ImplPrimitrive2DIDBlock(OverlayRollingRectanglePrimitive, PRIMITIVE2D_ID_OVERLAYROLLINGRECTANGLEPRIMITIVE)
478 :
479 : } // end of namespace primitive2d
480 : } // end of namespace drawinglayer
481 :
482 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|