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  */
19 
20 #include <drawinglayer/attribute/lineattribute.hxx>
21 #include <basegfx/color/bcolor.hxx>
22 #include <rtl/instance.hxx>
23 
24 
25 namespace drawinglayer
26 {
27     namespace attribute
28     {
29         class ImpLineAttribute
30         {
31         public:
32             // data definitions
33             basegfx::BColor                         maColor;                // color
34             double                                  mfWidth;                // absolute line width
35             basegfx::B2DLineJoin                    meLineJoin;             // type of LineJoin
36             css::drawing::LineCap                   meLineCap;              // BUTT, ROUND, or SQUARE
37             double                                  mfMiterMinimumAngle;     // as needed for createAreaGeometry
38 
ImpLineAttribute(const basegfx::BColor & rColor,double fWidth,basegfx::B2DLineJoin aB2DLineJoin,css::drawing::LineCap aLineCap,double fMiterMinimumAngle)39             ImpLineAttribute(
40                 const basegfx::BColor& rColor,
41                 double fWidth,
42                 basegfx::B2DLineJoin aB2DLineJoin,
43                 css::drawing::LineCap aLineCap,
44                 double fMiterMinimumAngle)
45             :   maColor(rColor),
46                 mfWidth(fWidth),
47                 meLineJoin(aB2DLineJoin),
48                 meLineCap(aLineCap),
49                 mfMiterMinimumAngle(fMiterMinimumAngle)
50             {
51             }
52 
ImpLineAttribute()53             ImpLineAttribute()
54             :   maColor(basegfx::BColor()),
55                 mfWidth(0.0),
56                 meLineJoin(basegfx::B2DLineJoin::Round),
57                 meLineCap(css::drawing::LineCap_BUTT),
58                 mfMiterMinimumAngle(basegfx::deg2rad(15.0))
59             {
60             }
61 
62             // data read access
getColor() const63             const basegfx::BColor& getColor() const { return maColor; }
getWidth() const64             double getWidth() const { return mfWidth; }
getLineJoin() const65             basegfx::B2DLineJoin getLineJoin() const { return meLineJoin; }
getLineCap() const66             css::drawing::LineCap getLineCap() const { return meLineCap; }
getMiterMinimumAngle() const67             double getMiterMinimumAngle() const { return mfMiterMinimumAngle; }
68 
operator ==(const ImpLineAttribute & rCandidate) const69             bool operator==(const ImpLineAttribute& rCandidate) const
70             {
71                 return (getColor() == rCandidate.getColor()
72                     && getWidth() == rCandidate.getWidth()
73                     && getLineJoin() == rCandidate.getLineJoin()
74                     && getLineCap() == rCandidate.getLineCap()
75                     && getMiterMinimumAngle() == rCandidate.getMiterMinimumAngle());
76             }
77         };
78 
79         namespace
80         {
81             struct theGlobalDefault :
82                 public rtl::Static< LineAttribute::ImplType, theGlobalDefault > {};
83         }
84 
LineAttribute(const basegfx::BColor & rColor,double fWidth,basegfx::B2DLineJoin aB2DLineJoin,css::drawing::LineCap aLineCap,double fMiterMinimumAngle)85         LineAttribute::LineAttribute(
86             const basegfx::BColor& rColor,
87             double fWidth,
88             basegfx::B2DLineJoin aB2DLineJoin,
89             css::drawing::LineCap aLineCap,
90             double fMiterMinimumAngle)
91         :   mpLineAttribute(
92                 ImpLineAttribute(
93                     rColor,
94                     fWidth,
95                     aB2DLineJoin,
96                     aLineCap,
97                     fMiterMinimumAngle))
98         {
99         }
100 
LineAttribute()101         LineAttribute::LineAttribute()
102         :   mpLineAttribute(theGlobalDefault::get())
103         {
104         }
105 
106         LineAttribute::LineAttribute(const LineAttribute&) = default;
107 
108         LineAttribute::~LineAttribute() = default;
109 
isDefault() const110         bool LineAttribute::isDefault() const
111         {
112             return mpLineAttribute.same_object(theGlobalDefault::get());
113         }
114 
115         LineAttribute& LineAttribute::operator=(const LineAttribute&) = default;
116 
operator ==(const LineAttribute & rCandidate) const117         bool LineAttribute::operator==(const LineAttribute& rCandidate) const
118         {
119             // tdf#87509 default attr is always != non-default attr, even with same values
120             if(rCandidate.isDefault() != isDefault())
121                 return false;
122 
123             return rCandidate.mpLineAttribute == mpLineAttribute;
124         }
125 
getColor() const126         const basegfx::BColor& LineAttribute::getColor() const
127         {
128             return mpLineAttribute->getColor();
129         }
130 
getWidth() const131         double LineAttribute::getWidth() const
132         {
133             return mpLineAttribute->getWidth();
134         }
135 
getLineJoin() const136         basegfx::B2DLineJoin LineAttribute::getLineJoin() const
137         {
138             return mpLineAttribute->getLineJoin();
139         }
140 
getLineCap() const141         css::drawing::LineCap LineAttribute::getLineCap() const
142         {
143             return mpLineAttribute->getLineCap();
144         }
145 
getMiterMinimumAngle() const146         double LineAttribute::getMiterMinimumAngle() const
147         {
148             return mpLineAttribute->getMiterMinimumAngle();
149         }
150 
151     } // end of namespace attribute
152 } // end of namespace drawinglayer
153 
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
155