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