/src/libreoffice/drawinglayer/source/attribute/linestartendattribute.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/linestartendattribute.hxx> |
21 | | #include <basegfx/polygon/b2dpolygon.hxx> |
22 | | #include <basegfx/polygon/b2dpolypolygon.hxx> |
23 | | #include <utility> |
24 | | |
25 | | |
26 | | namespace drawinglayer::attribute |
27 | | { |
28 | | class ImpLineStartEndAttribute |
29 | | { |
30 | | public: |
31 | | // data definitions |
32 | | double mfWidth; // absolute line StartEndGeometry base width |
33 | | basegfx::B2DPolyPolygon maPolyPolygon; // the StartEndGeometry PolyPolygon |
34 | | |
35 | | bool mbCentered : 1; // use centered to lineStart/End point? |
36 | | |
37 | | ImpLineStartEndAttribute( |
38 | | double fWidth, |
39 | | basegfx::B2DPolyPolygon aPolyPolygon, |
40 | | bool bCentered) |
41 | 0 | : mfWidth(fWidth), |
42 | 0 | maPolyPolygon(std::move(aPolyPolygon)), |
43 | 0 | mbCentered(bCentered) |
44 | 0 | { |
45 | 0 | } |
46 | | |
47 | | ImpLineStartEndAttribute() |
48 | 0 | : mfWidth(0.0), |
49 | 0 | mbCentered(false) |
50 | 0 | { |
51 | 0 | } |
52 | | |
53 | | // data read access |
54 | 0 | double getWidth() const { return mfWidth; } |
55 | 0 | const basegfx::B2DPolyPolygon& getB2DPolyPolygon() const { return maPolyPolygon; } |
56 | 0 | bool isCentered() const { return mbCentered; } |
57 | | |
58 | | bool operator==(const ImpLineStartEndAttribute& rCandidate) const |
59 | 0 | { |
60 | 0 | return (basegfx::fTools::equal(getWidth(), rCandidate.getWidth()) |
61 | 0 | && getB2DPolyPolygon() == rCandidate.getB2DPolyPolygon() |
62 | 0 | && isCentered() == rCandidate.isCentered()); |
63 | 0 | } |
64 | | }; |
65 | | |
66 | | namespace |
67 | | { |
68 | | LineStartEndAttribute::ImplType& theGlobalDefault() |
69 | 0 | { |
70 | 0 | static LineStartEndAttribute::ImplType SINGLETON; |
71 | 0 | return SINGLETON; |
72 | 0 | } |
73 | | } |
74 | | |
75 | | LineStartEndAttribute::LineStartEndAttribute( |
76 | | double fWidth, |
77 | | const basegfx::B2DPolyPolygon& rPolyPolygon, |
78 | | bool bCentered) |
79 | 0 | : mpLineStartEndAttribute(ImpLineStartEndAttribute( |
80 | 0 | fWidth, rPolyPolygon, bCentered)) |
81 | 0 | { |
82 | 0 | } |
83 | | |
84 | | LineStartEndAttribute::LineStartEndAttribute() |
85 | 0 | : mpLineStartEndAttribute(theGlobalDefault()) |
86 | 0 | { |
87 | 0 | } |
88 | | |
89 | 0 | LineStartEndAttribute::LineStartEndAttribute(const LineStartEndAttribute&) = default; |
90 | | |
91 | 0 | LineStartEndAttribute::~LineStartEndAttribute() = default; |
92 | | |
93 | | bool LineStartEndAttribute::isDefault() const |
94 | 0 | { |
95 | 0 | return mpLineStartEndAttribute.same_object(theGlobalDefault()); |
96 | 0 | } |
97 | | |
98 | 0 | LineStartEndAttribute& LineStartEndAttribute::operator=(const LineStartEndAttribute&) = default; |
99 | | |
100 | | bool LineStartEndAttribute::operator==(const LineStartEndAttribute& rCandidate) const |
101 | 0 | { |
102 | | // tdf#87509 default attr is always != non-default attr, even with same values |
103 | 0 | if(rCandidate.isDefault() != isDefault()) |
104 | 0 | return false; |
105 | | |
106 | 0 | return rCandidate.mpLineStartEndAttribute == mpLineStartEndAttribute; |
107 | 0 | } |
108 | | |
109 | | double LineStartEndAttribute::getWidth() const |
110 | 0 | { |
111 | 0 | return mpLineStartEndAttribute->getWidth(); |
112 | 0 | } |
113 | | |
114 | | const basegfx::B2DPolyPolygon& LineStartEndAttribute::getB2DPolyPolygon() const |
115 | 0 | { |
116 | 0 | return mpLineStartEndAttribute->getB2DPolyPolygon(); |
117 | 0 | } |
118 | | |
119 | | bool LineStartEndAttribute::isCentered() const |
120 | 0 | { |
121 | 0 | return mpLineStartEndAttribute->isCentered(); |
122 | 0 | } |
123 | | |
124 | | bool LineStartEndAttribute::isActive() const |
125 | 0 | { |
126 | 0 | return (0.0 != getWidth() |
127 | 0 | && 0 != getB2DPolyPolygon().count() |
128 | 0 | && 0 != getB2DPolyPolygon().getB2DPolygon(0).count()); |
129 | 0 | } |
130 | | |
131 | | } // end of namespace |
132 | | |
133 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |