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 <sal/config.h>
24 #include <drawinglayer/attribute/fillgraphicattribute.hxx>
25 #include <vcl/graph.hxx>
27 namespace drawinglayer
31 class ImpFillGraphicAttribute
36 basegfx::B2DRange maGraphicRange
;
40 // tiling definitions, offsets in X/Y in percent for each 2nd row.
41 // If both are set, Y is ignored (X has precedence)
45 ImpFillGraphicAttribute(
46 const Graphic
& rGraphic
,
47 const basegfx::B2DRange
& rGraphicRange
,
51 : maGraphic(rGraphic
),
52 maGraphicRange(rGraphicRange
),
57 // access once to ensure that the buffered bitmap exists, else
58 // the SolarMutex may be needed to create it. This may not be
59 // available when a renderer works with multi-threading.
60 // When changing this, please check if it is still possible to
61 // use a metafile as texture for a 3D object
62 maGraphic
.GetBitmapEx();
65 ImpFillGraphicAttribute()
66 : maGraphic(Graphic()),
67 maGraphicRange(basegfx::B2DRange()),
75 const Graphic
& getGraphic() const { return maGraphic
; }
76 const basegfx::B2DRange
& getGraphicRange() const { return maGraphicRange
; }
77 bool getTiling() const { return mbTiling
; }
78 double getOffsetX() const { return mfOffsetX
; }
79 double getOffsetY() const { return mfOffsetY
; }
81 bool operator==(const ImpFillGraphicAttribute
& rCandidate
) const
83 return (getGraphic() == rCandidate
.getGraphic()
84 && getGraphicRange() == rCandidate
.getGraphicRange()
85 && getTiling() == rCandidate
.getTiling()
86 && getOffsetX() == rCandidate
.getOffsetX()
87 && getOffsetY() == rCandidate
.getOffsetY());
93 struct theGlobalDefault
:
94 public rtl::Static
< FillGraphicAttribute::ImplType
, theGlobalDefault
> {};
97 FillGraphicAttribute::FillGraphicAttribute(
98 const Graphic
& rGraphic
,
99 const basegfx::B2DRange
& rGraphicRange
,
103 : mpFillGraphicAttribute(ImpFillGraphicAttribute(
104 rGraphic
, rGraphicRange
, bTiling
,
105 std::clamp(fOffsetX
, 0.0, 1.0),
106 std::clamp(fOffsetY
, 0.0, 1.0)))
110 FillGraphicAttribute::FillGraphicAttribute(const FillGraphicAttribute
&) = default;
112 FillGraphicAttribute::~FillGraphicAttribute() = default;
114 bool FillGraphicAttribute::isDefault() const
116 return mpFillGraphicAttribute
.same_object(theGlobalDefault::get());
119 FillGraphicAttribute
& FillGraphicAttribute::operator=(const FillGraphicAttribute
&) = default;
121 bool FillGraphicAttribute::operator==(const FillGraphicAttribute
& rCandidate
) const
123 // tdf#87509 default attr is always != non-default attr, even with same values
124 if(rCandidate
.isDefault() != isDefault())
127 return rCandidate
.mpFillGraphicAttribute
== mpFillGraphicAttribute
;
130 const Graphic
& FillGraphicAttribute::getGraphic() const
132 return mpFillGraphicAttribute
->getGraphic();
135 const basegfx::B2DRange
& FillGraphicAttribute::getGraphicRange() const
137 return mpFillGraphicAttribute
->getGraphicRange();
140 bool FillGraphicAttribute::getTiling() const
142 return mpFillGraphicAttribute
->getTiling();
145 double FillGraphicAttribute::getOffsetX() const
147 return mpFillGraphicAttribute
->getOffsetX();
150 double FillGraphicAttribute::getOffsetY() const
152 return mpFillGraphicAttribute
->getOffsetY();
155 } // end of namespace attribute
156 } // end of namespace drawinglayer
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */