calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / drawinglayer / source / primitive2d / fillhatchprimitive2d.cxx
blob1e86c907c406139ca8be9ac84a0702d6d74956c5
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/fillhatchprimitive2d.hxx>
21 #include <texture/texture.hxx>
22 #include <drawinglayer/primitive2d/PolygonHairlinePrimitive2D.hxx>
23 #include <drawinglayer/primitive2d/PolyPolygonColorPrimitive2D.hxx>
24 #include <basegfx/polygon/b2dpolygontools.hxx>
25 #include <basegfx/polygon/b2dpolygon.hxx>
26 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
27 #include <drawinglayer/geometry/viewinformation2d.hxx>
28 #include <utility>
31 using namespace com::sun::star;
34 namespace drawinglayer::primitive2d
36 void FillHatchPrimitive2D::create2DDecomposition(Primitive2DContainer& rContainer, const geometry::ViewInformation2D& /*rViewInformation*/) const
38 if(getFillHatch().isDefault())
39 return;
41 // create hatch
42 const basegfx::BColor aHatchColor(getFillHatch().getColor());
43 const double fAngle(getFillHatch().getAngle());
44 std::vector< basegfx::B2DHomMatrix > aMatrices;
45 double fDistance(getFillHatch().getDistance());
46 const bool bAdaptDistance(0 != getFillHatch().getMinimalDiscreteDistance());
48 // #i120230# evtl. adapt distance
49 if(bAdaptDistance)
51 const double fDiscreteDistance(getFillHatch().getDistance() / getDiscreteUnit());
53 if(fDiscreteDistance < static_cast<double>(getFillHatch().getMinimalDiscreteDistance()))
55 fDistance = static_cast<double>(getFillHatch().getMinimalDiscreteDistance()) * getDiscreteUnit();
59 // get hatch transformations
60 switch(getFillHatch().getStyle())
62 case attribute::HatchStyle::Triple:
64 // rotated 45 degrees
65 texture::GeoTexSvxHatch aHatch(
66 getDefinitionRange(),
67 getOutputRange(),
68 fDistance,
69 fAngle - M_PI_4);
71 aHatch.appendTransformations(aMatrices);
73 [[fallthrough]];
75 case attribute::HatchStyle::Double:
77 // rotated 90 degrees
78 texture::GeoTexSvxHatch aHatch(
79 getDefinitionRange(),
80 getOutputRange(),
81 fDistance,
82 fAngle - M_PI_2);
84 aHatch.appendTransformations(aMatrices);
86 [[fallthrough]];
88 case attribute::HatchStyle::Single:
90 // angle as given
91 texture::GeoTexSvxHatch aHatch(
92 getDefinitionRange(),
93 getOutputRange(),
94 fDistance,
95 fAngle);
97 aHatch.appendTransformations(aMatrices);
101 // prepare return value
102 const bool bFillBackground(getFillHatch().isFillBackground());
104 // evtl. create filled background
105 if(bFillBackground)
107 // create primitive for background
108 rContainer.push_back(
109 new PolyPolygonColorPrimitive2D(
110 basegfx::B2DPolyPolygon(
111 basegfx::utils::createPolygonFromRect(getOutputRange())), getBColor()));
114 // create primitives
115 const basegfx::B2DPoint aStart(0.0, 0.0);
116 const basegfx::B2DPoint aEnd(1.0, 0.0);
118 for (const auto &a : aMatrices)
120 const basegfx::B2DHomMatrix& rMatrix = a;
121 basegfx::B2DPolygon aNewLine;
123 aNewLine.append(rMatrix * aStart);
124 aNewLine.append(rMatrix * aEnd);
126 // create hairline
127 rContainer.push_back(new PolygonHairlinePrimitive2D(std::move(aNewLine), aHatchColor));
131 FillHatchPrimitive2D::FillHatchPrimitive2D(
132 const basegfx::B2DRange& rOutputRange,
133 const basegfx::BColor& rBColor,
134 attribute::FillHatchAttribute aFillHatch)
135 : maOutputRange(rOutputRange),
136 maDefinitionRange(rOutputRange),
137 maFillHatch(std::move(aFillHatch)),
138 maBColor(rBColor)
142 FillHatchPrimitive2D::FillHatchPrimitive2D(
143 const basegfx::B2DRange& rOutputRange,
144 const basegfx::B2DRange& rDefinitionRange,
145 const basegfx::BColor& rBColor,
146 attribute::FillHatchAttribute aFillHatch)
147 : maOutputRange(rOutputRange),
148 maDefinitionRange(rDefinitionRange),
149 maFillHatch(std::move(aFillHatch)),
150 maBColor(rBColor)
154 bool FillHatchPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
156 if(DiscreteMetricDependentPrimitive2D::operator==(rPrimitive))
158 const FillHatchPrimitive2D& rCompare = static_cast<const FillHatchPrimitive2D&>(rPrimitive);
160 return (getOutputRange() == rCompare.getOutputRange()
161 && getDefinitionRange() == rCompare.getDefinitionRange()
162 && getFillHatch() == rCompare.getFillHatch()
163 && getBColor() == rCompare.getBColor());
166 return false;
169 basegfx::B2DRange FillHatchPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const
171 // return the geometrically visible area
172 return getOutputRange();
175 void FillHatchPrimitive2D::get2DDecomposition(Primitive2DDecompositionVisitor& rVisitor, const geometry::ViewInformation2D& rViewInformation) const
177 bool bAdaptDistance(0 != getFillHatch().getMinimalDiscreteDistance());
179 if(bAdaptDistance)
181 // behave view-dependent
182 DiscreteMetricDependentPrimitive2D::get2DDecomposition(rVisitor, rViewInformation);
184 else
186 // behave view-independent
187 BufferedDecompositionPrimitive2D::get2DDecomposition(rVisitor, rViewInformation);
191 // provide unique ID
192 sal_uInt32 FillHatchPrimitive2D::getPrimitive2DID() const
194 return PRIMITIVE2D_ID_FILLHATCHPRIMITIVE2D;
197 } // end of namespace
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */