1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <drawinglayer/texture/texture.hxx>
22 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
23 #include <basegfx/polygon/b2dpolygontools.hxx>
24 #include <basegfx/polygon/b2dpolygon.hxx>
25 #include <basegfx/utils/canvastools.hxx>
26 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
27 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
28 #include <drawinglayer/geometry/viewinformation2d.hxx>
31 using namespace com::sun::star
;
34 namespace drawinglayer
38 void FillHatchPrimitive2D::create2DDecomposition(Primitive2DContainer
& rContainer
, const geometry::ViewInformation2D
& /*rViewInformation*/) const
40 if(!getFillHatch().isDefault())
43 const basegfx::BColor
aHatchColor(getFillHatch().getColor());
44 const double fAngle(getFillHatch().getAngle());
45 std::vector
< basegfx::B2DHomMatrix
> aMatrices
;
46 double fDistance(getFillHatch().getDistance());
47 const bool bAdaptDistance(0 != getFillHatch().getMinimalDiscreteDistance());
49 // #i120230# evtl. adapt distance
52 const double fDiscreteDistance(getFillHatch().getDistance() / getDiscreteUnit());
54 if(fDiscreteDistance
< static_cast<double>(getFillHatch().getMinimalDiscreteDistance()))
56 fDistance
= static_cast<double>(getFillHatch().getMinimalDiscreteDistance()) * getDiscreteUnit();
60 // get hatch transformations
61 switch(getFillHatch().getStyle())
63 case attribute::HatchStyle::Triple
:
66 texture::GeoTexSvxHatch
aHatch(
72 aHatch
.appendTransformations(aMatrices
);
76 case attribute::HatchStyle::Double
:
79 texture::GeoTexSvxHatch
aHatch(
85 aHatch
.appendTransformations(aMatrices
);
89 case attribute::HatchStyle::Single
:
92 texture::GeoTexSvxHatch
aHatch(
98 aHatch
.appendTransformations(aMatrices
);
102 // prepare return value
103 const bool bFillBackground(getFillHatch().isFillBackground());
105 // evtl. create filled background
108 // create primitive for background
109 rContainer
.push_back(
110 new PolyPolygonColorPrimitive2D(
111 basegfx::B2DPolyPolygon(
112 basegfx::utils::createPolygonFromRect(getOutputRange())), getBColor()));
116 const basegfx::B2DPoint
aStart(0.0, 0.0);
117 const basegfx::B2DPoint
aEnd(1.0, 0.0);
119 for(size_t a(0); a
< aMatrices
.size(); a
++)
121 const basegfx::B2DHomMatrix
& rMatrix
= aMatrices
[a
];
122 basegfx::B2DPolygon aNewLine
;
124 aNewLine
.append(rMatrix
* aStart
);
125 aNewLine
.append(rMatrix
* aEnd
);
128 rContainer
.push_back(new PolygonHairlinePrimitive2D(aNewLine
, aHatchColor
));
133 FillHatchPrimitive2D::FillHatchPrimitive2D(
134 const basegfx::B2DRange
& rOutputRange
,
135 const basegfx::BColor
& rBColor
,
136 const attribute::FillHatchAttribute
& rFillHatch
)
137 : DiscreteMetricDependentPrimitive2D(),
138 maOutputRange(rOutputRange
),
139 maDefinitionRange(rOutputRange
),
140 maFillHatch(rFillHatch
),
145 FillHatchPrimitive2D::FillHatchPrimitive2D(
146 const basegfx::B2DRange
& rOutputRange
,
147 const basegfx::B2DRange
& rDefinitionRange
,
148 const basegfx::BColor
& rBColor
,
149 const attribute::FillHatchAttribute
& rFillHatch
)
150 : DiscreteMetricDependentPrimitive2D(),
151 maOutputRange(rOutputRange
),
152 maDefinitionRange(rDefinitionRange
),
153 maFillHatch(rFillHatch
),
158 bool FillHatchPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
160 if(DiscreteMetricDependentPrimitive2D::operator==(rPrimitive
))
162 const FillHatchPrimitive2D
& rCompare
= static_cast<const FillHatchPrimitive2D
&>(rPrimitive
);
164 return (getOutputRange() == rCompare
.getOutputRange()
165 && getDefinitionRange() == rCompare
.getDefinitionRange()
166 && getFillHatch() == rCompare
.getFillHatch()
167 && getBColor() == rCompare
.getBColor());
173 basegfx::B2DRange
FillHatchPrimitive2D::getB2DRange(const geometry::ViewInformation2D
& /*rViewInformation*/) const
175 // return the geometrically visible area
176 return getOutputRange();
179 void FillHatchPrimitive2D::get2DDecomposition(Primitive2DDecompositionVisitor
& rVisitor
, const geometry::ViewInformation2D
& rViewInformation
) const
181 ::osl::MutexGuard
aGuard( m_aMutex
);
182 bool bAdaptDistance(0 != getFillHatch().getMinimalDiscreteDistance());
186 // behave view-dependent
187 DiscreteMetricDependentPrimitive2D::get2DDecomposition(rVisitor
, rViewInformation
);
191 // behave view-independent
192 BufferedDecompositionPrimitive2D::get2DDecomposition(rVisitor
, rViewInformation
);
197 ImplPrimitive2DIDBlock(FillHatchPrimitive2D
, PRIMITIVE2D_ID_FILLHATCHPRIMITIVE2D
)
199 } // end of namespace primitive2d
200 } // end of namespace drawinglayer
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */