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 <drawinglayer/attribute/linestartendattribute.hxx>
21 #include <basegfx/polygon/b2dpolygon.hxx>
22 #include <basegfx/polygon/b2dpolypolygon.hxx>
23 #include <rtl/instance.hxx>
26 namespace drawinglayer::attribute
28 class ImpLineStartEndAttribute
32 double mfWidth
; // absolute line StartEndGeometry base width
33 basegfx::B2DPolyPolygon maPolyPolygon
; // the StartEndGeometry PolyPolygon
35 bool mbCentered
: 1; // use centered to lineStart/End point?
37 ImpLineStartEndAttribute(
39 const basegfx::B2DPolyPolygon
& rPolyPolygon
,
42 maPolyPolygon(rPolyPolygon
),
47 ImpLineStartEndAttribute()
49 maPolyPolygon(basegfx::B2DPolyPolygon()),
55 double getWidth() const { return mfWidth
; }
56 const basegfx::B2DPolyPolygon
& getB2DPolyPolygon() const { return maPolyPolygon
; }
57 bool isCentered() const { return mbCentered
; }
59 bool operator==(const ImpLineStartEndAttribute
& rCandidate
) const
61 return (basegfx::fTools::equal(getWidth(), rCandidate
.getWidth())
62 && getB2DPolyPolygon() == rCandidate
.getB2DPolyPolygon()
63 && isCentered() == rCandidate
.isCentered());
69 struct theGlobalDefault
:
70 public rtl::Static
< LineStartEndAttribute::ImplType
, theGlobalDefault
> {};
73 LineStartEndAttribute::LineStartEndAttribute(
75 const basegfx::B2DPolyPolygon
& rPolyPolygon
,
77 : mpLineStartEndAttribute(ImpLineStartEndAttribute(
78 fWidth
, rPolyPolygon
, bCentered
))
82 LineStartEndAttribute::LineStartEndAttribute()
83 : mpLineStartEndAttribute(theGlobalDefault::get())
87 LineStartEndAttribute::LineStartEndAttribute(const LineStartEndAttribute
&) = default;
89 LineStartEndAttribute::~LineStartEndAttribute() = default;
91 bool LineStartEndAttribute::isDefault() const
93 return mpLineStartEndAttribute
.same_object(theGlobalDefault::get());
96 LineStartEndAttribute
& LineStartEndAttribute::operator=(const LineStartEndAttribute
&) = default;
98 bool LineStartEndAttribute::operator==(const LineStartEndAttribute
& rCandidate
) const
100 // tdf#87509 default attr is always != non-default attr, even with same values
101 if(rCandidate
.isDefault() != isDefault())
104 return rCandidate
.mpLineStartEndAttribute
== mpLineStartEndAttribute
;
107 double LineStartEndAttribute::getWidth() const
109 return mpLineStartEndAttribute
->getWidth();
112 const basegfx::B2DPolyPolygon
& LineStartEndAttribute::getB2DPolyPolygon() const
114 return mpLineStartEndAttribute
->getB2DPolyPolygon();
117 bool LineStartEndAttribute::isCentered() const
119 return mpLineStartEndAttribute
->isCentered();
122 bool LineStartEndAttribute::isActive() const
124 return (0.0 != getWidth()
125 && 0 != getB2DPolyPolygon().count()
126 && 0 != getB2DPolyPolygon().getB2DPolygon(0).count());
129 } // end of namespace
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */