nss: upgrade to release 3.73
[LibreOffice.git] / drawinglayer / source / primitive2d / fillhatchprimitive2d.cxx
blob9c4ef03bfba3af528380cfc6d789baf5f7c21e4d
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/PolyPolygonColorPrimitive2D.hxx>
23 #include <basegfx/polygon/b2dpolygontools.hxx>
24 #include <basegfx/polygon/b2dpolygon.hxx>
25 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
26 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
27 #include <drawinglayer/geometry/viewinformation2d.hxx>
30 using namespace com::sun::star;
33 namespace drawinglayer::primitive2d
35 void FillHatchPrimitive2D::create2DDecomposition(Primitive2DContainer& rContainer, const geometry::ViewInformation2D& /*rViewInformation*/) const
37 if(getFillHatch().isDefault())
38 return;
40 // create hatch
41 const basegfx::BColor aHatchColor(getFillHatch().getColor());
42 const double fAngle(getFillHatch().getAngle());
43 std::vector< basegfx::B2DHomMatrix > aMatrices;
44 double fDistance(getFillHatch().getDistance());
45 const bool bAdaptDistance(0 != getFillHatch().getMinimalDiscreteDistance());
47 // #i120230# evtl. adapt distance
48 if(bAdaptDistance)
50 const double fDiscreteDistance(getFillHatch().getDistance() / getDiscreteUnit());
52 if(fDiscreteDistance < static_cast<double>(getFillHatch().getMinimalDiscreteDistance()))
54 fDistance = static_cast<double>(getFillHatch().getMinimalDiscreteDistance()) * getDiscreteUnit();
58 // get hatch transformations
59 switch(getFillHatch().getStyle())
61 case attribute::HatchStyle::Triple:
63 // rotated 45 degrees
64 texture::GeoTexSvxHatch aHatch(
65 getDefinitionRange(),
66 getOutputRange(),
67 fDistance,
68 fAngle - F_PI4);
70 aHatch.appendTransformations(aMatrices);
72 [[fallthrough]];
74 case attribute::HatchStyle::Double:
76 // rotated 90 degrees
77 texture::GeoTexSvxHatch aHatch(
78 getDefinitionRange(),
79 getOutputRange(),
80 fDistance,
81 fAngle - F_PI2);
83 aHatch.appendTransformations(aMatrices);
85 [[fallthrough]];
87 case attribute::HatchStyle::Single:
89 // angle as given
90 texture::GeoTexSvxHatch aHatch(
91 getDefinitionRange(),
92 getOutputRange(),
93 fDistance,
94 fAngle);
96 aHatch.appendTransformations(aMatrices);
100 // prepare return value
101 const bool bFillBackground(getFillHatch().isFillBackground());
103 // evtl. create filled background
104 if(bFillBackground)
106 // create primitive for background
107 rContainer.push_back(
108 new PolyPolygonColorPrimitive2D(
109 basegfx::B2DPolyPolygon(
110 basegfx::utils::createPolygonFromRect(getOutputRange())), getBColor()));
113 // create primitives
114 const basegfx::B2DPoint aStart(0.0, 0.0);
115 const basegfx::B2DPoint aEnd(1.0, 0.0);
117 for(size_t a(0); a < aMatrices.size(); a++)
119 const basegfx::B2DHomMatrix& rMatrix = aMatrices[a];
120 basegfx::B2DPolygon aNewLine;
122 aNewLine.append(rMatrix * aStart);
123 aNewLine.append(rMatrix * aEnd);
125 // create hairline
126 rContainer.push_back(new PolygonHairlinePrimitive2D(aNewLine, aHatchColor));
130 FillHatchPrimitive2D::FillHatchPrimitive2D(
131 const basegfx::B2DRange& rOutputRange,
132 const basegfx::BColor& rBColor,
133 const attribute::FillHatchAttribute& rFillHatch)
134 : DiscreteMetricDependentPrimitive2D(),
135 maOutputRange(rOutputRange),
136 maDefinitionRange(rOutputRange),
137 maFillHatch(rFillHatch),
138 maBColor(rBColor)
142 FillHatchPrimitive2D::FillHatchPrimitive2D(
143 const basegfx::B2DRange& rOutputRange,
144 const basegfx::B2DRange& rDefinitionRange,
145 const basegfx::BColor& rBColor,
146 const attribute::FillHatchAttribute& rFillHatch)
147 : DiscreteMetricDependentPrimitive2D(),
148 maOutputRange(rOutputRange),
149 maDefinitionRange(rDefinitionRange),
150 maFillHatch(rFillHatch),
151 maBColor(rBColor)
155 bool FillHatchPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
157 if(DiscreteMetricDependentPrimitive2D::operator==(rPrimitive))
159 const FillHatchPrimitive2D& rCompare = static_cast<const FillHatchPrimitive2D&>(rPrimitive);
161 return (getOutputRange() == rCompare.getOutputRange()
162 && getDefinitionRange() == rCompare.getDefinitionRange()
163 && getFillHatch() == rCompare.getFillHatch()
164 && getBColor() == rCompare.getBColor());
167 return false;
170 basegfx::B2DRange FillHatchPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const
172 // return the geometrically visible area
173 return getOutputRange();
176 void FillHatchPrimitive2D::get2DDecomposition(Primitive2DDecompositionVisitor& rVisitor, const geometry::ViewInformation2D& rViewInformation) const
178 ::osl::MutexGuard aGuard( m_aMutex );
179 bool bAdaptDistance(0 != getFillHatch().getMinimalDiscreteDistance());
181 if(bAdaptDistance)
183 // behave view-dependent
184 DiscreteMetricDependentPrimitive2D::get2DDecomposition(rVisitor, rViewInformation);
186 else
188 // behave view-independent
189 BufferedDecompositionPrimitive2D::get2DDecomposition(rVisitor, rViewInformation);
193 // provide unique ID
194 ImplPrimitive2DIDBlock(FillHatchPrimitive2D, PRIMITIVE2D_ID_FILLHATCHPRIMITIVE2D)
196 } // end of namespace
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */