Teach symstore more duplicated DLLs
[LibreOffice.git] / drawinglayer / source / primitive2d / helplineprimitive2d.cxx
blobeb31fade9fb6d2f9ce8d7a17629ff16988bb7c25
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <drawinglayer/primitive2d/helplineprimitive2d.hxx>
21 #include <basegfx/polygon/b2dpolygon.hxx>
22 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
23 #include <basegfx/polygon/b2dpolygonclipper.hxx>
24 #include <basegfx/utils/canvastools.hxx>
25 #include <drawinglayer/geometry/viewinformation2d.hxx>
26 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
29 using namespace com::sun::star;
32 namespace drawinglayer
34 namespace primitive2d
36 void HelplinePrimitive2D::create2DDecomposition(Primitive2DContainer& rContainer, const geometry::ViewInformation2D& rViewInformation) const
38 if(!rViewInformation.getViewport().isEmpty() && !getDirection().equalZero())
40 // position to view coordinates, DashLen and DashLen in logic
41 const basegfx::B2DPoint aViewPosition(rViewInformation.getObjectToViewTransformation() * getPosition());
43 switch(getStyle())
45 default : // HelplineStyle2D::Point
47 const double fViewFixValue(15.0);
48 basegfx::B2DVector aNormalizedDirection(getDirection());
49 aNormalizedDirection.normalize();
50 aNormalizedDirection *= fViewFixValue;
51 const basegfx::B2DPoint aStartA(aViewPosition - aNormalizedDirection);
52 const basegfx::B2DPoint aEndA(aViewPosition + aNormalizedDirection);
53 basegfx::B2DPolygon aLineA;
54 aLineA.append(aStartA);
55 aLineA.append(aEndA);
56 aLineA.transform(rViewInformation.getInverseObjectToViewTransformation());
57 PolygonMarkerPrimitive2D* pNewA = new PolygonMarkerPrimitive2D(aLineA, getRGBColA(), getRGBColB(), getDiscreteDashLength());
58 rContainer.push_back(pNewA);
60 const basegfx::B2DVector aPerpendicularNormalizedDirection(basegfx::getPerpendicular(aNormalizedDirection));
61 const basegfx::B2DPoint aStartB(aViewPosition - aPerpendicularNormalizedDirection);
62 const basegfx::B2DPoint aEndB(aViewPosition + aPerpendicularNormalizedDirection);
63 basegfx::B2DPolygon aLineB;
64 aLineB.append(aStartB);
65 aLineB.append(aEndB);
66 aLineB.transform(rViewInformation.getInverseObjectToViewTransformation());
67 PolygonMarkerPrimitive2D* pNewB = new PolygonMarkerPrimitive2D(aLineB, getRGBColA(), getRGBColB(), getDiscreteDashLength());
68 rContainer.push_back(pNewB);
70 break;
72 case HelplineStyle2D::Line :
74 basegfx::B2DPolygon aLine;
76 if(basegfx::areParallel(getDirection(), basegfx::B2DVector(1.0, 0.0)))
78 // parallel to X-Axis, get cuts with Y-Axes
79 const double fCutA((rViewInformation.getDiscreteViewport().getMinX() - aViewPosition.getX()) / getDirection().getX());
80 const double fCutB((rViewInformation.getDiscreteViewport().getMaxX() - aViewPosition.getX()) / getDirection().getX());
81 const basegfx::B2DPoint aPosA(aViewPosition + (fCutA * getDirection()));
82 const basegfx::B2DPoint aPosB(aViewPosition + (fCutB * getDirection()));
83 const bool bBothLeft(aPosA.getX() < rViewInformation.getDiscreteViewport().getMinX() && aPosB.getX() < rViewInformation.getDiscreteViewport().getMinX());
84 const bool bBothRight(aPosA.getX() > rViewInformation.getDiscreteViewport().getMaxX() && aPosB.getX() < rViewInformation.getDiscreteViewport().getMaxX());
86 if(!bBothLeft && !bBothRight)
88 aLine.append(aPosA);
89 aLine.append(aPosB);
92 else
94 // get cuts with X-Axes
95 const double fCutA((rViewInformation.getDiscreteViewport().getMinY() - aViewPosition.getY()) / getDirection().getY());
96 const double fCutB((rViewInformation.getDiscreteViewport().getMaxY() - aViewPosition.getY()) / getDirection().getY());
97 const basegfx::B2DPoint aPosA(aViewPosition + (fCutA * getDirection()));
98 const basegfx::B2DPoint aPosB(aViewPosition + (fCutB * getDirection()));
99 const bool bBothAbove(aPosA.getY() < rViewInformation.getDiscreteViewport().getMinY() && aPosB.getY() < rViewInformation.getDiscreteViewport().getMinY());
100 const bool bBothBelow(aPosA.getY() > rViewInformation.getDiscreteViewport().getMaxY() && aPosB.getY() < rViewInformation.getDiscreteViewport().getMaxY());
102 if(!bBothAbove && !bBothBelow)
104 aLine.append(aPosA);
105 aLine.append(aPosB);
109 if(aLine.count())
111 // clip against visible area
112 const basegfx::B2DPolyPolygon aResult(basegfx::utils::clipPolygonOnRange(aLine, rViewInformation.getDiscreteViewport(), true, true));
114 for(sal_uInt32 a(0); a < aResult.count(); a++)
116 basegfx::B2DPolygon aPart(aResult.getB2DPolygon(a));
117 aPart.transform(rViewInformation.getInverseObjectToViewTransformation());
118 PolygonMarkerPrimitive2D* pNew = new PolygonMarkerPrimitive2D(aPart, getRGBColA(), getRGBColB(), getDiscreteDashLength());
119 rContainer.push_back(pNew);
123 break;
129 HelplinePrimitive2D::HelplinePrimitive2D(
130 const basegfx::B2DPoint& rPosition,
131 const basegfx::B2DVector& rDirection,
132 HelplineStyle2D eStyle,
133 const basegfx::BColor& rRGBColA,
134 const basegfx::BColor& rRGBColB,
135 double fDiscreteDashLength)
136 : BufferedDecompositionPrimitive2D(),
137 maPosition(rPosition),
138 maDirection(rDirection),
139 meStyle(eStyle),
140 maRGBColA(rRGBColA),
141 maRGBColB(rRGBColB),
142 mfDiscreteDashLength(fDiscreteDashLength),
143 maLastObjectToViewTransformation(),
144 maLastViewport()
148 bool HelplinePrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
150 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
152 const HelplinePrimitive2D& rCompare = static_cast<const HelplinePrimitive2D&>(rPrimitive);
154 return (getPosition() == rCompare.getPosition()
155 && getDirection() == rCompare.getDirection()
156 && getStyle() == rCompare.getStyle()
157 && getRGBColA() == rCompare.getRGBColA()
158 && getRGBColB() == rCompare.getRGBColB()
159 && getDiscreteDashLength() == rCompare.getDiscreteDashLength());
162 return false;
165 void HelplinePrimitive2D::get2DDecomposition(Primitive2DDecompositionVisitor& rVisitor, const geometry::ViewInformation2D& rViewInformation) const
167 ::osl::MutexGuard aGuard( m_aMutex );
169 if(!getBuffered2DDecomposition().empty())
171 if(maLastViewport != rViewInformation.getViewport() || maLastObjectToViewTransformation != rViewInformation.getObjectToViewTransformation())
173 // conditions of last local decomposition have changed, delete
174 const_cast< HelplinePrimitive2D* >(this)->setBuffered2DDecomposition(Primitive2DContainer());
178 if(getBuffered2DDecomposition().empty())
180 // remember ViewRange and ViewTransformation
181 const_cast< HelplinePrimitive2D* >(this)->maLastObjectToViewTransformation = rViewInformation.getObjectToViewTransformation();
182 const_cast< HelplinePrimitive2D* >(this)->maLastViewport = rViewInformation.getViewport();
185 // use parent implementation
186 BufferedDecompositionPrimitive2D::get2DDecomposition(rVisitor, rViewInformation);
189 // provide unique ID
190 ImplPrimitive2DIDBlock(HelplinePrimitive2D, PRIMITIVE2D_ID_HELPLINEPRIMITIVE2D)
192 } // end of namespace primitive2d
193 } // end of namespace drawinglayer
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */