/src/libreoffice/drawinglayer/source/attribute/strokeattribute.cxx
Line | Count | Source |
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/strokeattribute.hxx> |
21 | | #include <numeric> |
22 | | |
23 | | |
24 | | namespace drawinglayer::attribute |
25 | | { |
26 | | class ImpStrokeAttribute |
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 | | |
33 | | ImpStrokeAttribute( |
34 | | std::vector< double >&& rDotDashArray, |
35 | | double fFullDotDashLen) |
36 | 10.7k | : maDotDashArray(std::move(rDotDashArray)), |
37 | 10.7k | mfFullDotDashLen(fFullDotDashLen) |
38 | 10.7k | { |
39 | 10.7k | } |
40 | | |
41 | | ImpStrokeAttribute() |
42 | 5 | : mfFullDotDashLen(0.0) |
43 | 5 | { |
44 | 5 | } |
45 | | |
46 | | // data read access |
47 | 22.8k | const std::vector< double >& getDotDashArray() const { return maDotDashArray; } |
48 | | double getFullDotDashLen() const |
49 | 22.8k | { |
50 | 22.8k | if(0.0 == mfFullDotDashLen && !maDotDashArray.empty()) |
51 | 0 | { |
52 | | // calculate length on demand |
53 | 0 | const double fAccumulated(std::accumulate(maDotDashArray.begin(), maDotDashArray.end(), 0.0)); |
54 | 0 | const_cast< ImpStrokeAttribute* >(this)->mfFullDotDashLen = fAccumulated; |
55 | 0 | } |
56 | | |
57 | 22.8k | return mfFullDotDashLen; |
58 | 22.8k | } |
59 | | |
60 | | bool operator==(const ImpStrokeAttribute& rCandidate) const |
61 | 6.10k | { |
62 | 6.10k | return (getDotDashArray() == rCandidate.getDotDashArray() |
63 | 6.10k | && getFullDotDashLen() == rCandidate.getFullDotDashLen()); |
64 | 6.10k | } |
65 | | }; |
66 | | |
67 | | namespace |
68 | | { |
69 | | StrokeAttribute::ImplType& theGlobalDefault() |
70 | 22.7k | { |
71 | 22.7k | static StrokeAttribute::ImplType SINGLETON; |
72 | 22.7k | return SINGLETON; |
73 | 22.7k | } |
74 | | } |
75 | | |
76 | | StrokeAttribute::StrokeAttribute( |
77 | | std::vector< double >&& rDotDashArray, |
78 | | double fFullDotDashLen) |
79 | 10.7k | : mpStrokeAttribute(ImpStrokeAttribute( |
80 | 10.7k | std::move(rDotDashArray), fFullDotDashLen)) |
81 | 10.7k | { |
82 | 10.7k | } |
83 | | |
84 | | StrokeAttribute::StrokeAttribute() |
85 | 13 | : mpStrokeAttribute(theGlobalDefault()) |
86 | 13 | { |
87 | 13 | } |
88 | | |
89 | 10.4k | StrokeAttribute::StrokeAttribute(const StrokeAttribute&) = default; |
90 | | |
91 | 31.9k | StrokeAttribute::StrokeAttribute(StrokeAttribute&&) = default; |
92 | | |
93 | 53.1k | StrokeAttribute::~StrokeAttribute() = default; |
94 | | |
95 | | bool StrokeAttribute::isDefault() const |
96 | 22.7k | { |
97 | 22.7k | return mpStrokeAttribute.same_object(theGlobalDefault()); |
98 | 22.7k | } |
99 | | |
100 | 0 | StrokeAttribute& StrokeAttribute::operator=(const StrokeAttribute&) = default; |
101 | | |
102 | 0 | StrokeAttribute& StrokeAttribute::operator=(StrokeAttribute&&) = default; |
103 | | |
104 | | bool StrokeAttribute::operator==(const StrokeAttribute& rCandidate) const |
105 | 6.10k | { |
106 | | // tdf#87509 default attr is always != non-default attr, even with same values |
107 | 6.10k | if(rCandidate.isDefault() != isDefault()) |
108 | 0 | return false; |
109 | | |
110 | 6.10k | return rCandidate.mpStrokeAttribute == mpStrokeAttribute; |
111 | 6.10k | } |
112 | | |
113 | | const std::vector< double >& StrokeAttribute::getDotDashArray() const |
114 | 10.6k | { |
115 | 10.6k | return mpStrokeAttribute->getDotDashArray(); |
116 | 10.6k | } |
117 | | |
118 | | double StrokeAttribute::getFullDotDashLen() const |
119 | 10.6k | { |
120 | 10.6k | return mpStrokeAttribute->getFullDotDashLen(); |
121 | 10.6k | } |
122 | | |
123 | | } // end of namespace |
124 | | |
125 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |