LibreOffice Module svx (master) 1
sdrallfillattributeshelper.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 */
27#include <vcl/graph.hxx>
28
30
32{
34 const basegfx::B2DRange& rPaintRange,
35 const basegfx::B2DRange& rDefineRange)
36 {
37 // reset and remember new target range for object geometry
38 maLastPaintRange = rPaintRange;
39 maLastDefineRange = rDefineRange;
40
41 if(isUsed())
42 {
43 maPrimitives.resize(1);
51 }
52 }
53
55 {
57 0.0,
58 rColor.GetRGBColor().getBColor(),
62 }
63
65 : maFillAttribute(
67 maFillGradientAttribute(
69 {
70 }
71
73 {
74 }
75
77 {
78 // only depends on fill, FillGradientAttribute alone defines no fill
79 return maFillAttribute && !maFillAttribute->isDefault();
80 }
81
83 {
84 if(hasSdrFillAttribute() && 0.0 != maFillAttribute->getTransparence())
85 {
86 return true;
87 }
88
90 {
91 return true;
92 }
93
95 {
97
98 return rGraphic.IsSupportedGraphic() && rGraphic.IsTransparent();
99 }
100
101 return false;
102 }
103
105 {
106 if(!maFillAttribute)
107 {
108 const_cast< SdrAllFillAttributesHelper* >(this)->maFillAttribute.emplace();
109 }
110
111 return *maFillAttribute;
112 }
113
115 {
117 {
118 const_cast< SdrAllFillAttributesHelper* >(this)->maFillGradientAttribute.emplace();
119 }
120
122 }
123
125 const basegfx::B2DRange& rPaintRange,
126 const basegfx::B2DRange& rDefineRange) const
127 {
128 if(!maPrimitives.empty() && (maLastPaintRange != rPaintRange || maLastDefineRange != rDefineRange))
129 {
130 const_cast< SdrAllFillAttributesHelper* >(this)->maPrimitives.clear();
131 }
132
133 if(maPrimitives.empty())
134 {
135 const_cast< SdrAllFillAttributesHelper* >(this)->createPrimitive2DSequence(rPaintRange, rDefineRange);
136 }
137
138 return maPrimitives;
139 }
140
142 {
143 basegfx::BColor aRetval(rFallback);
144
145 if(maFillAttribute && !maFillAttribute->isDefault())
146 {
147 const drawinglayer::attribute::FillGradientAttribute& rFillGradientAttribute = maFillAttribute->getGradient();
148 const drawinglayer::attribute::FillHatchAttribute& rFillHatchAttribute = maFillAttribute->getHatch();
149 const drawinglayer::attribute::SdrFillGraphicAttribute& rSdrFillGraphicAttribute = maFillAttribute->getFillGraphic();
150 const drawinglayer::attribute::FillGradientAttribute& rFillTransparenceGradientAttribute = getFillGradientAttribute();
151 double fTransparence(maFillAttribute->getTransparence());
152
153 if(!rFillTransparenceGradientAttribute.isDefault())
154 {
155 const double fTransA(rFillTransparenceGradientAttribute.getColorStops().front().getStopColor().luminance());
156 const double fTransB(rFillTransparenceGradientAttribute.getColorStops().back().getStopColor().luminance());
157
158 fTransparence = (fTransA + fTransB) * 0.5;
159 }
160
161 if(!rFillGradientAttribute.isDefault())
162 {
163 // gradient fill
164 const basegfx::BColor aStart(rFillGradientAttribute.getColorStops().front().getStopColor());
165 const basegfx::BColor aEnd(rFillGradientAttribute.getColorStops().back().getStopColor());
166
167 aRetval = basegfx::interpolate(aStart, aEnd, 0.5);
168 }
169 else if(!rFillHatchAttribute.isDefault())
170 {
171 // hatch fill
172 const basegfx::BColor& rColor = rFillHatchAttribute.getColor();
173
174 if(rFillHatchAttribute.isFillBackground())
175 {
176 const basegfx::BColor& rBackgroundColor = maFillAttribute->getColor();
177
178 // mix colors 50%/50%
179 aRetval = basegfx::interpolate(rColor, rBackgroundColor, 0.5);
180 }
181 else
182 {
183 // mix color with fallback color
184 aRetval = basegfx::interpolate(rColor, rFallback, 0.5);
185 }
186 }
187 else if(!rSdrFillGraphicAttribute.isDefault())
188 {
189 // graphic fill
190
191 // not used yet by purpose (see SwPageFrm::GetDrawBackgrdColor()),
192 // use fallback (already set)
193 }
194 else
195 {
196 // color fill
197 aRetval = maFillAttribute->getColor();
198 }
199
200 if(!basegfx::fTools::equalZero(fTransparence))
201 {
202 // blend into transparency
203 aRetval = basegfx::interpolate(aRetval, rFallback, fTransparence);
204 }
205 }
206
207 return aRetval.clamp();
208 }
209
211 {
212 if(!isUsed() || !hasSdrFillAttribute())
213 {
214 // not used or no fill
215 return false;
216 }
217
219
220 if(!rSdrFillAttribute.getHatch().isDefault())
221 {
222 // hatch is always top-left aligned, needs no full refreshes
223 return false;
224 }
225
226 if(!rSdrFillAttribute.getGradient().isDefault())
227 {
228 // gradients always scale with the object
229 return true;
230 }
231
232 if(!rSdrFillAttribute.getFillGraphic().isDefault())
233 {
234 // some graphic constellations may not need this, but since most do
235 // (stretch to fill, all but top-left aligned, ...) claim to do by default
236 return true;
237 }
238
239 // color fill
240 return false;
241 }
242
243} // end of namespace
244
245/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Color GetRGBColor() const
basegfx::BColor getBColor() const
bool IsSupportedGraphic() const
bool IsTransparent() const
BColor & clamp()
const basegfx::BColorStops & getColorStops() const
const basegfx::BColor & getColor() const
const drawinglayer::attribute::FillGradientAttribute & getFillGradientAttribute() const
const drawinglayer::attribute::SdrFillAttribute & getFillAttribute() const
std::optional< drawinglayer::attribute::SdrFillAttribute > maFillAttribute
const drawinglayer::primitive2d::Primitive2DContainer & getPrimitive2DSequence(const basegfx::B2DRange &rPaintRange, const basegfx::B2DRange &rDefineRange) const
basegfx::BColor getAverageColor(const basegfx::BColor &rFallback) const
drawinglayer::primitive2d::Primitive2DContainer maPrimitives
void createPrimitive2DSequence(const basegfx::B2DRange &rPaintRange, const basegfx::B2DRange &rDefineRange)
std::optional< drawinglayer::attribute::FillGradientAttribute > maFillGradientAttribute
const FillHatchAttribute & getHatch() const
const FillGradientAttribute & getGradient() const
const SdrFillGraphicAttribute & getFillGraphic() const
bool equalZero(const T &rfVal)
B2DPolygon createPolygonFromRect(const B2DRectangle &rRect, double fRadiusX, double fRadiusY)
B2DTuple interpolate(const B2DTuple &rOld1, const B2DTuple &rOld2, double t)
attribute::FillGradientAttribute createNewTransparenceGradientAttribute(const SfxItemSet &rSet)
attribute::SdrFillAttribute createNewSdrFillAttribute(const SfxItemSet &rSet)
Primitive2DReference createPolyPolygonFillPrimitive(const basegfx::B2DPolyPolygon &rPolyPolygon, const attribute::SdrFillAttribute &rFill, const attribute::FillGradientAttribute &rFillGradient)
static SfxItemSet & rSet