LibreOffice Module drawinglayer (master) 1
fillhatchprimitive2d.cxx
Go to the documentation of this file.
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
21#include <texture/texture.hxx>
28#include <utility>
29
30
31using namespace com::sun::star;
32
33
35{
37 {
38 if(getFillHatch().isDefault())
39 return;
40
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());
47
48 // #i120230# evtl. adapt distance
49 if(bAdaptDistance)
50 {
51 const double fDiscreteDistance(getFillHatch().getDistance() / getDiscreteUnit());
52
53 if(fDiscreteDistance < static_cast<double>(getFillHatch().getMinimalDiscreteDistance()))
54 {
55 fDistance = static_cast<double>(getFillHatch().getMinimalDiscreteDistance()) * getDiscreteUnit();
56 }
57 }
58
59 // get hatch transformations
60 switch(getFillHatch().getStyle())
61 {
63 {
64 // rotated 45 degrees
68 fDistance,
69 fAngle - M_PI_4);
70
71 aHatch.appendTransformations(aMatrices);
72
73 [[fallthrough]];
74 }
76 {
77 // rotated 90 degrees
81 fDistance,
82 fAngle - M_PI_2);
83
84 aHatch.appendTransformations(aMatrices);
85
86 [[fallthrough]];
87 }
89 {
90 // angle as given
94 fDistance,
95 fAngle);
96
97 aHatch.appendTransformations(aMatrices);
98 }
99 }
100
101 // prepare return value
102 const bool bFillBackground(getFillHatch().isFillBackground());
103
104 // evtl. create filled background
105 if(bFillBackground)
106 {
107 // create primitive for background
108 rContainer.push_back(
112 }
113
114 // create primitives
115 const basegfx::B2DPoint aStart(0.0, 0.0);
116 const basegfx::B2DPoint aEnd(1.0, 0.0);
117
118 for (const auto &a : aMatrices)
119 {
120 const basegfx::B2DHomMatrix& rMatrix = a;
121 basegfx::B2DPolygon aNewLine;
122
123 aNewLine.append(rMatrix * aStart);
124 aNewLine.append(rMatrix * aEnd);
125
126 // create hairline
127 rContainer.push_back(new PolygonHairlinePrimitive2D(std::move(aNewLine), aHatchColor));
128 }
129 }
130
132 const basegfx::B2DRange& rOutputRange,
133 const basegfx::BColor& rBColor,
135 : maOutputRange(rOutputRange),
136 maDefinitionRange(rOutputRange),
137 maFillHatch(std::move(aFillHatch)),
138 maBColor(rBColor)
139 {
140 }
141
143 const basegfx::B2DRange& rOutputRange,
144 const basegfx::B2DRange& rDefinitionRange,
145 const basegfx::BColor& rBColor,
147 : maOutputRange(rOutputRange),
148 maDefinitionRange(rDefinitionRange),
149 maFillHatch(std::move(aFillHatch)),
150 maBColor(rBColor)
151 {
152 }
153
155 {
156 if(DiscreteMetricDependentPrimitive2D::operator==(rPrimitive))
157 {
158 const FillHatchPrimitive2D& rCompare = static_cast<const FillHatchPrimitive2D&>(rPrimitive);
159
160 return (getOutputRange() == rCompare.getOutputRange()
161 && getDefinitionRange() == rCompare.getDefinitionRange()
162 && getFillHatch() == rCompare.getFillHatch()
163 && getBColor() == rCompare.getBColor());
164 }
165
166 return false;
167 }
168
170 {
171 // return the geometrically visible area
172 return getOutputRange();
173 }
174
176 {
177 bool bAdaptDistance(0 != getFillHatch().getMinimalDiscreteDistance());
178
179 if(bAdaptDistance)
180 {
181 // behave view-dependent
183 }
184 else
185 {
186 // behave view-independent
188 }
189 }
190
191 // provide unique ID
193 {
195 }
196
197} // end of namespace
198
199/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void append(const basegfx::B2DPoint &rPoint, sal_uInt32 nCount)
virtual void get2DDecomposition(Primitive2DDecompositionVisitor &rVisitor, const geometry::ViewInformation2D &rViewInformation) const override
The getDecomposition default implementation will on demand use create2DDecomposition() if maBuffered2...
virtual void get2DDecomposition(Primitive2DDecompositionVisitor &rVisitor, const geometry::ViewInformation2D &rViewInformation) const override
Override standard getDecomposition to be view-dependent here.
virtual basegfx::B2DRange getB2DRange(const geometry::ViewInformation2D &rViewInformation) const override
get range
virtual void create2DDecomposition(Primitive2DContainer &rContainer, const geometry::ViewInformation2D &rViewInformation) const override
local decomposition.
const basegfx::B2DRange & getOutputRange() const
data read access
FillHatchPrimitive2D(const basegfx::B2DRange &rOutputRange, const basegfx::BColor &rBColor, attribute::FillHatchAttribute aFillHatch)
constructors. The one without definition range will use output range as definition range
virtual bool operator==(const BasePrimitive2D &rPrimitive) const override
compare operator
const attribute::FillHatchAttribute & getFillHatch() const
const basegfx::B2DRange & getDefinitionRange() const
virtual sal_uInt32 getPrimitive2DID() const override
provide unique ID
virtual void get2DDecomposition(Primitive2DDecompositionVisitor &rVisitor, const geometry::ViewInformation2D &rViewInformation) const override
Override standard getDecomposition to be view-dependent here.
void appendTransformations(::std::vector< basegfx::B2DHomMatrix > &rMatrices)
Definition: texture.cxx:879
#define PRIMITIVE2D_ID_FILLHATCHPRIMITIVE2D
uno_Any a
B2DPolygon createPolygonFromRect(const B2DRectangle &rRect, double fRadiusX, double fRadiusY)