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 */
26#include <vcl/graph.hxx>
27
29
31{
33 const basegfx::B2DRange& rPaintRange,
34 const basegfx::B2DRange& rDefineRange)
35 {
36 // reset and remember new target range for object geometry
37 maLastPaintRange = rPaintRange;
38 maLastDefineRange = rDefineRange;
39
40 if(isUsed())
41 {
42 maPrimitives.resize(1);
50 }
51 }
52
54 {
56 0.0,
57 rColor.GetRGBColor().getBColor(),
61 }
62
64 : maFillAttribute(
66 maFillGradientAttribute(
68 {
69 }
70
72 {
73 }
74
76 {
77 // only depends on fill, FillGradientAttribute alone defines no fill
78 return maFillAttribute && !maFillAttribute->isDefault();
79 }
80
82 {
83 if(hasSdrFillAttribute() && 0.0 != maFillAttribute->getTransparence())
84 {
85 return true;
86 }
87
89 {
90 return true;
91 }
92
94 {
96
97 return rGraphic.IsSupportedGraphic() && rGraphic.IsTransparent();
98 }
99
100 return false;
101 }
102
104 {
105 if(!maFillAttribute)
106 {
107 const_cast< SdrAllFillAttributesHelper* >(this)->maFillAttribute.emplace();
108 }
109
110 return *maFillAttribute;
111 }
112
114 {
116 {
117 const_cast< SdrAllFillAttributesHelper* >(this)->maFillGradientAttribute.emplace();
118 }
119
121 }
122
124 const basegfx::B2DRange& rPaintRange,
125 const basegfx::B2DRange& rDefineRange) const
126 {
127 if(!maPrimitives.empty() && (maLastPaintRange != rPaintRange || maLastDefineRange != rDefineRange))
128 {
129 const_cast< SdrAllFillAttributesHelper* >(this)->maPrimitives.clear();
130 }
131
132 if(maPrimitives.empty())
133 {
134 const_cast< SdrAllFillAttributesHelper* >(this)->createPrimitive2DSequence(rPaintRange, rDefineRange);
135 }
136
137 return maPrimitives;
138 }
139
141 {
142 basegfx::BColor aRetval(rFallback);
143
144 if(maFillAttribute && !maFillAttribute->isDefault())
145 {
146 const drawinglayer::attribute::FillGradientAttribute& rFillGradientAttribute = maFillAttribute->getGradient();
147 const drawinglayer::attribute::FillHatchAttribute& rFillHatchAttribute = maFillAttribute->getHatch();
148 const drawinglayer::attribute::SdrFillGraphicAttribute& rSdrFillGraphicAttribute = maFillAttribute->getFillGraphic();
149 const drawinglayer::attribute::FillGradientAttribute& rFillTransparenceGradientAttribute = getFillGradientAttribute();
150 double fTransparence(maFillAttribute->getTransparence());
151
152 if(!rFillTransparenceGradientAttribute.isDefault())
153 {
154 const double fTransA = rFillTransparenceGradientAttribute.getStartColor().luminance();
155 const double fTransB = rFillTransparenceGradientAttribute.getEndColor().luminance();
156
157 fTransparence = (fTransA + fTransB) * 0.5;
158 }
159
160 if(!rFillGradientAttribute.isDefault())
161 {
162 // gradient fill
163 const basegfx::BColor& rStart = rFillGradientAttribute.getStartColor();
164 const basegfx::BColor& rEnd = rFillGradientAttribute.getEndColor();
165
166 aRetval = basegfx::interpolate(rStart, rEnd, 0.5);
167 }
168 else if(!rFillHatchAttribute.isDefault())
169 {
170 // hatch fill
171 const basegfx::BColor& rColor = rFillHatchAttribute.getColor();
172
173 if(rFillHatchAttribute.isFillBackground())
174 {
175 const basegfx::BColor& rBackgroundColor = maFillAttribute->getColor();
176
177 // mix colors 50%/50%
178 aRetval = basegfx::interpolate(rColor, rBackgroundColor, 0.5);
179 }
180 else
181 {
182 // mix color with fallback color
183 aRetval = basegfx::interpolate(rColor, rFallback, 0.5);
184 }
185 }
186 else if(!rSdrFillGraphicAttribute.isDefault())
187 {
188 // graphic fill
189
190 // not used yet by purpose (see SwPageFrm::GetDrawBackgrdColor()),
191 // use fallback (already set)
192 }
193 else
194 {
195 // color fill
196 aRetval = maFillAttribute->getColor();
197 }
198
199 if(!basegfx::fTools::equalZero(fTransparence))
200 {
201 // blend into transparency
202 aRetval = basegfx::interpolate(aRetval, rFallback, fTransparence);
203 }
204 }
205
206 return aRetval.clamp();
207 }
208
210 {
211 if(!isUsed() || !hasSdrFillAttribute())
212 {
213 // not used or no fill
214 return false;
215 }
216
218
219 if(!rSdrFillAttribute.getHatch().isDefault())
220 {
221 // hatch is always top-left aligned, needs no full refreshes
222 return false;
223 }
224
225 if(!rSdrFillAttribute.getGradient().isDefault())
226 {
227 // gradients always scale with the object
228 return true;
229 }
230
231 if(!rSdrFillAttribute.getFillGraphic().isDefault())
232 {
233 // some graphic constellations may not need this, but since most do
234 // (stretch to fill, all but top-left aligned, ...) claim to do by default
235 return true;
236 }
237
238 // color fill
239 return false;
240 }
241
242} // end of namespace
243
244/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Color GetRGBColor() const
basegfx::BColor getBColor() const
bool IsSupportedGraphic() const
bool IsTransparent() const
double luminance() const
BColor & clamp()
const basegfx::BColor & getStartColor() const
const basegfx::BColor & getEndColor() 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