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/strokeattribute.hxx>
24 namespace drawinglayer::attribute
26 class ImpStrokeAttribute
30 std::vector
< double > maDotDashArray
; // array of double which defines the dot-dash pattern
31 double mfFullDotDashLen
; // sum of maDotDashArray (for convenience)
34 std::vector
< double >&& rDotDashArray
,
35 double fFullDotDashLen
)
36 : maDotDashArray(std::move(rDotDashArray
)),
37 mfFullDotDashLen(fFullDotDashLen
)
42 : mfFullDotDashLen(0.0)
47 const std::vector
< double >& getDotDashArray() const { return maDotDashArray
; }
48 double getFullDotDashLen() const
50 if(0.0 == mfFullDotDashLen
&& !maDotDashArray
.empty())
52 // calculate length on demand
53 const double fAccumulated(std::accumulate(maDotDashArray
.begin(), maDotDashArray
.end(), 0.0));
54 const_cast< ImpStrokeAttribute
* >(this)->mfFullDotDashLen
= fAccumulated
;
57 return mfFullDotDashLen
;
60 bool operator==(const ImpStrokeAttribute
& rCandidate
) const
62 return (getDotDashArray() == rCandidate
.getDotDashArray()
63 && getFullDotDashLen() == rCandidate
.getFullDotDashLen());
69 StrokeAttribute::ImplType
& theGlobalDefault()
71 static StrokeAttribute::ImplType SINGLETON
;
76 StrokeAttribute::StrokeAttribute(
77 std::vector
< double >&& rDotDashArray
,
78 double fFullDotDashLen
)
79 : mpStrokeAttribute(ImpStrokeAttribute(
80 std::move(rDotDashArray
), fFullDotDashLen
))
84 StrokeAttribute::StrokeAttribute()
85 : mpStrokeAttribute(theGlobalDefault())
89 StrokeAttribute::StrokeAttribute(const StrokeAttribute
&) = default;
91 StrokeAttribute::StrokeAttribute(StrokeAttribute
&&) = default;
93 StrokeAttribute::~StrokeAttribute() = default;
95 bool StrokeAttribute::isDefault() const
97 return mpStrokeAttribute
.same_object(theGlobalDefault());
100 StrokeAttribute
& StrokeAttribute::operator=(const StrokeAttribute
&) = default;
102 StrokeAttribute
& StrokeAttribute::operator=(StrokeAttribute
&&) = default;
104 bool StrokeAttribute::operator==(const StrokeAttribute
& rCandidate
) const
106 // tdf#87509 default attr is always != non-default attr, even with same values
107 if(rCandidate
.isDefault() != isDefault())
110 return rCandidate
.mpStrokeAttribute
== mpStrokeAttribute
;
113 const std::vector
< double >& StrokeAttribute::getDotDashArray() const
115 return mpStrokeAttribute
->getDotDashArray();
118 double StrokeAttribute::getFullDotDashLen() const
120 return mpStrokeAttribute
->getFullDotDashLen();
123 } // end of namespace
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */