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>
26 #include <vcl/graph.hxx>
28 namespace drawinglayer::attribute
30 class ImpFillGraphicAttribute
35 basegfx::B2DRange maGraphicRange
;
39 // tiling definitions, offsets in X/Y in percent for each 2nd row.
40 // If both are set, Y is ignored (X has precedence)
44 ImpFillGraphicAttribute(
46 const basegfx::B2DRange
& rGraphicRange
,
50 : maGraphic(std::move(aGraphic
)),
51 maGraphicRange(rGraphicRange
),
56 // access once to ensure that the buffered bitmap exists, else
57 // the SolarMutex may be needed to create it. This may not be
58 // available when a renderer works with multi-threading.
59 // When changing this, please check if it is still possible to
60 // use a metafile as texture for a 3D object
61 maGraphic
.GetBitmapEx();
64 ImpFillGraphicAttribute()
72 const Graphic
& getGraphic() const { return maGraphic
; }
73 const basegfx::B2DRange
& getGraphicRange() const { return maGraphicRange
; }
74 bool getTiling() const { return mbTiling
; }
75 double getOffsetX() const { return mfOffsetX
; }
76 double getOffsetY() const { return mfOffsetY
; }
78 bool operator==(const ImpFillGraphicAttribute
& rCandidate
) const
80 return (getGraphic() == rCandidate
.getGraphic()
81 && getGraphicRange() == rCandidate
.getGraphicRange()
82 && getTiling() == rCandidate
.getTiling()
83 && getOffsetX() == rCandidate
.getOffsetX()
84 && getOffsetY() == rCandidate
.getOffsetY());
90 FillGraphicAttribute::ImplType
& theGlobalDefault()
92 static FillGraphicAttribute::ImplType SINGLETON
;
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());
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
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */