2021-08-22 20:23:18 +08:00
|
|
|
// Copyright (c) 2014-2021 Thomas Fussell
|
2015-12-25 04:51:11 +08:00
|
|
|
// Copyright (c) 2010-2015 openpyxl
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
2021-08-22 20:23:18 +08:00
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
2015-12-25 04:51:11 +08:00
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
// THE SOFTWARE
|
|
|
|
//
|
|
|
|
// @license: http://www.opensource.org/licenses/mit-license.php
|
|
|
|
// @author: see AUTHORS file
|
2016-08-02 06:33:43 +08:00
|
|
|
|
2015-11-21 09:41:32 +08:00
|
|
|
#include <xlnt/styles/border.hpp>
|
2016-12-24 23:04:57 +08:00
|
|
|
#include <xlnt/utils/exceptions.hpp>
|
|
|
|
#include <detail/default_case.hpp>
|
2015-11-21 09:41:32 +08:00
|
|
|
|
|
|
|
namespace xlnt {
|
|
|
|
|
2016-08-16 12:23:49 +08:00
|
|
|
optional<xlnt::color> border::border_property::color() const
|
2015-11-21 09:41:32 +08:00
|
|
|
{
|
2016-12-24 23:04:57 +08:00
|
|
|
return color_;
|
2015-12-25 04:51:11 +08:00
|
|
|
}
|
|
|
|
|
2016-08-16 12:23:49 +08:00
|
|
|
border::border_property &border::border_property::color(const xlnt::color &c)
|
2015-12-25 04:51:11 +08:00
|
|
|
{
|
2016-12-24 23:04:57 +08:00
|
|
|
color_ = c;
|
|
|
|
return *this;
|
2015-12-25 04:51:11 +08:00
|
|
|
}
|
|
|
|
|
2016-08-16 12:23:49 +08:00
|
|
|
optional<border_style> border::border_property::style() const
|
2015-12-25 04:51:11 +08:00
|
|
|
{
|
2016-12-24 23:04:57 +08:00
|
|
|
return style_;
|
2015-12-25 04:51:11 +08:00
|
|
|
}
|
|
|
|
|
2016-08-16 12:23:49 +08:00
|
|
|
border::border_property &border::border_property::style(border_style s)
|
2015-12-25 04:51:11 +08:00
|
|
|
{
|
2016-12-24 23:04:57 +08:00
|
|
|
style_ = s;
|
|
|
|
return *this;
|
2015-12-25 04:51:11 +08:00
|
|
|
}
|
|
|
|
|
2017-03-23 09:44:59 +08:00
|
|
|
bool border::border_property::operator==(const border::border_property &right) const
|
2016-11-01 08:48:43 +08:00
|
|
|
{
|
2017-03-23 09:44:59 +08:00
|
|
|
auto &left = *this;
|
|
|
|
|
2016-11-01 08:48:43 +08:00
|
|
|
if (left.style().is_set() != right.style().is_set())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2016-12-24 23:04:57 +08:00
|
|
|
|
2016-11-01 08:48:43 +08:00
|
|
|
if (left.style().is_set())
|
|
|
|
{
|
|
|
|
if (left.style().get() != right.style().get())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2016-12-24 23:04:57 +08:00
|
|
|
|
2016-11-01 08:48:43 +08:00
|
|
|
if (left.color().is_set() != right.color().is_set())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2016-12-24 23:04:57 +08:00
|
|
|
|
2016-11-01 08:48:43 +08:00
|
|
|
if (left.color().is_set())
|
|
|
|
{
|
|
|
|
if (left.color().get() != right.color().get())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2016-12-24 23:04:57 +08:00
|
|
|
|
2016-11-01 08:48:43 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-23 09:44:59 +08:00
|
|
|
bool border::border_property::operator!=(const border::border_property &right) const
|
|
|
|
{
|
|
|
|
return !(*this == right);
|
|
|
|
}
|
|
|
|
|
2016-08-02 06:33:43 +08:00
|
|
|
border::border()
|
2015-12-25 04:51:11 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-08-16 12:23:49 +08:00
|
|
|
const std::vector<xlnt::border_side> &border::all_sides()
|
2015-12-25 04:51:11 +08:00
|
|
|
{
|
2020-11-20 20:24:47 +08:00
|
|
|
static auto sides = std::vector<xlnt::border_side>{xlnt::border_side::start, xlnt::border_side::end,
|
2016-12-24 23:04:57 +08:00
|
|
|
xlnt::border_side::top, xlnt::border_side::bottom, xlnt::border_side::diagonal, xlnt::border_side::vertical,
|
|
|
|
xlnt::border_side::horizontal};
|
|
|
|
|
2020-11-20 20:24:47 +08:00
|
|
|
return sides;
|
2015-12-25 04:51:11 +08:00
|
|
|
}
|
|
|
|
|
2016-08-16 12:23:49 +08:00
|
|
|
optional<border::border_property> border::side(border_side s) const
|
2015-12-25 04:51:11 +08:00
|
|
|
{
|
2016-12-24 23:04:57 +08:00
|
|
|
switch (s)
|
|
|
|
{
|
|
|
|
case border_side::bottom:
|
|
|
|
return bottom_;
|
|
|
|
case border_side::top:
|
|
|
|
return top_;
|
|
|
|
case border_side::start:
|
|
|
|
return start_;
|
|
|
|
case border_side::end:
|
|
|
|
return end_;
|
|
|
|
case border_side::vertical:
|
|
|
|
return vertical_;
|
|
|
|
case border_side::horizontal:
|
|
|
|
return horizontal_;
|
|
|
|
case border_side::diagonal:
|
|
|
|
return diagonal_;
|
|
|
|
}
|
2016-12-11 02:39:51 +08:00
|
|
|
|
|
|
|
default_case(start_);
|
2015-12-25 04:51:11 +08:00
|
|
|
}
|
|
|
|
|
2016-08-16 12:23:49 +08:00
|
|
|
border &border::side(border_side s, const border_property &prop)
|
2015-12-25 04:51:11 +08:00
|
|
|
{
|
2016-12-24 23:04:57 +08:00
|
|
|
switch (s)
|
|
|
|
{
|
|
|
|
case border_side::bottom:
|
|
|
|
bottom_ = prop;
|
|
|
|
break;
|
|
|
|
case border_side::top:
|
|
|
|
top_ = prop;
|
|
|
|
break;
|
|
|
|
case border_side::start:
|
|
|
|
start_ = prop;
|
|
|
|
break;
|
|
|
|
case border_side::end:
|
|
|
|
end_ = prop;
|
|
|
|
break;
|
|
|
|
case border_side::vertical:
|
|
|
|
vertical_ = prop;
|
|
|
|
break;
|
|
|
|
case border_side::horizontal:
|
|
|
|
horizontal_ = prop;
|
|
|
|
break;
|
|
|
|
case border_side::diagonal:
|
|
|
|
diagonal_ = prop;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
border &border::diagonal(diagonal_direction direction)
|
|
|
|
{
|
2016-12-24 23:04:57 +08:00
|
|
|
diagonal_direction_ = direction;
|
|
|
|
return *this;
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
optional<diagonal_direction> border::diagonal() const
|
|
|
|
{
|
2016-12-24 23:04:57 +08:00
|
|
|
return diagonal_direction_;
|
2015-12-25 04:51:11 +08:00
|
|
|
}
|
|
|
|
|
2017-03-23 09:44:59 +08:00
|
|
|
bool border::operator==(const border &right) const
|
2015-12-25 04:51:11 +08:00
|
|
|
{
|
2017-03-23 09:44:59 +08:00
|
|
|
auto &left = *this;
|
|
|
|
|
2016-11-01 08:48:43 +08:00
|
|
|
for (auto side : border::all_sides())
|
|
|
|
{
|
|
|
|
if (left.side(side).is_set() != right.side(side).is_set())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2016-12-24 23:04:57 +08:00
|
|
|
|
2016-11-01 08:48:43 +08:00
|
|
|
if (left.side(side).is_set())
|
|
|
|
{
|
|
|
|
if (left.side(side).get() != right.side(side).get())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-12-24 23:04:57 +08:00
|
|
|
|
2016-11-01 08:48:43 +08:00
|
|
|
return true;
|
2015-11-21 09:41:32 +08:00
|
|
|
}
|
|
|
|
|
2017-03-23 09:44:59 +08:00
|
|
|
bool border::operator!=(const border &right) const
|
|
|
|
{
|
|
|
|
return !(*this == right);
|
|
|
|
}
|
|
|
|
|
2015-11-21 09:41:32 +08:00
|
|
|
} // namespace xlnt
|