LibreOffice Module drawinglayer (master) 1
strokeattribute.cxx
Go to the documentation of this file.
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
21#include <numeric>
22
23
25{
27 {
28 public:
29 // data definitions
30 std::vector< double > maDotDashArray; // array of double which defines the dot-dash pattern
31 double mfFullDotDashLen; // sum of maDotDashArray (for convenience)
32
34 std::vector< double >&& rDotDashArray,
35 double fFullDotDashLen)
36 : maDotDashArray(std::move(rDotDashArray)),
37 mfFullDotDashLen(fFullDotDashLen)
38 {
39 }
40
42 : mfFullDotDashLen(0.0)
43 {
44 }
45
46 // data read access
47 const std::vector< double >& getDotDashArray() const { return maDotDashArray; }
48 double getFullDotDashLen() const
49 {
50 if(0.0 == mfFullDotDashLen && !maDotDashArray.empty())
51 {
52 // calculate length on demand
53 const double fAccumulated(std::accumulate(maDotDashArray.begin(), maDotDashArray.end(), 0.0));
54 const_cast< ImpStrokeAttribute* >(this)->mfFullDotDashLen = fAccumulated;
55 }
56
57 return mfFullDotDashLen;
58 }
59
60 bool operator==(const ImpStrokeAttribute& rCandidate) const
61 {
62 return (getDotDashArray() == rCandidate.getDotDashArray()
63 && getFullDotDashLen() == rCandidate.getFullDotDashLen());
64 }
65 };
66
67 namespace
68 {
69 StrokeAttribute::ImplType& theGlobalDefault()
70 {
71 static StrokeAttribute::ImplType SINGLETON;
72 return SINGLETON;
73 }
74 }
75
77 std::vector< double >&& rDotDashArray,
78 double fFullDotDashLen)
79 : mpStrokeAttribute(ImpStrokeAttribute(
80 std::move(rDotDashArray), fFullDotDashLen))
81 {
82 }
83
85 : mpStrokeAttribute(theGlobalDefault())
86 {
87 }
88
90
92
94
96 {
97 return mpStrokeAttribute.same_object(theGlobalDefault());
98 }
99
101
103
104 bool StrokeAttribute::operator==(const StrokeAttribute& rCandidate) const
105 {
106 // tdf#87509 default attr is always != non-default attr, even with same values
107 if(rCandidate.isDefault() != isDefault())
108 return false;
109
110 return rCandidate.mpStrokeAttribute == mpStrokeAttribute;
111 }
112
113 const std::vector< double >& StrokeAttribute::getDotDashArray() const
114 {
115 return mpStrokeAttribute->getDotDashArray();
116 }
117
119 {
120 return mpStrokeAttribute->getFullDotDashLen();
121 }
122
123} // end of namespace
124
125/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const std::vector< double > & getDotDashArray() const
ImpStrokeAttribute(std::vector< double > &&rDotDashArray, double fFullDotDashLen)
bool operator==(const ImpStrokeAttribute &rCandidate) const
const ::std::vector< double > & getDotDashArray() const
o3tl::cow_wrapper< ImpStrokeAttribute > ImplType
bool operator==(const StrokeAttribute &rCandidate) const
StrokeAttribute & operator=(const StrokeAttribute &)
bool same_object(const cow_wrapper &rOther) const