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-12-23 19:51:30 +08:00
|
|
|
#include <cmath>
|
|
|
|
|
2015-12-25 04:51:11 +08:00
|
|
|
#include <xlnt/styles/font.hpp>
|
|
|
|
|
2018-06-26 16:32:59 +08:00
|
|
|
namespace {
|
2018-07-14 15:52:21 +08:00
|
|
|
const std::string &Default_Name()
|
|
|
|
{
|
|
|
|
static const std::string Default("Calibri");
|
|
|
|
return Default;
|
|
|
|
}
|
2018-06-26 16:32:59 +08:00
|
|
|
constexpr double Default_Size = 12.0;
|
|
|
|
} // namespace
|
|
|
|
|
2015-12-25 04:51:11 +08:00
|
|
|
namespace xlnt {
|
|
|
|
|
2016-06-11 01:40:50 +08:00
|
|
|
font::font()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-08-16 12:23:49 +08:00
|
|
|
font &font::bold(bool bold)
|
2015-12-25 04:51:11 +08:00
|
|
|
{
|
|
|
|
bold_ = bold;
|
2016-12-24 23:04:57 +08:00
|
|
|
return *this;
|
2015-12-25 04:51:11 +08:00
|
|
|
}
|
|
|
|
|
2016-08-16 12:23:49 +08:00
|
|
|
bool font::bold() const
|
2015-12-25 04:51:11 +08:00
|
|
|
{
|
|
|
|
return bold_;
|
|
|
|
}
|
|
|
|
|
2018-03-21 21:03:37 +08:00
|
|
|
font &font::superscript(bool value)
|
2016-10-14 08:11:02 +08:00
|
|
|
{
|
2018-03-21 21:03:37 +08:00
|
|
|
superscript_ = value;
|
2016-12-24 23:04:57 +08:00
|
|
|
return *this;
|
2016-10-14 08:11:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool font::superscript() const
|
|
|
|
{
|
2016-12-24 23:04:57 +08:00
|
|
|
return superscript_;
|
2016-10-14 08:11:02 +08:00
|
|
|
}
|
|
|
|
|
2018-03-21 21:03:37 +08:00
|
|
|
font &font::subscript(bool value)
|
|
|
|
{
|
|
|
|
subscript_ = value;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool font::subscript() const
|
|
|
|
{
|
|
|
|
return subscript_;
|
|
|
|
}
|
|
|
|
|
2016-08-16 12:23:49 +08:00
|
|
|
font &font::italic(bool italic)
|
2015-12-25 04:51:11 +08:00
|
|
|
{
|
|
|
|
italic_ = italic;
|
2016-12-24 23:04:57 +08:00
|
|
|
return *this;
|
2015-12-25 04:51:11 +08:00
|
|
|
}
|
|
|
|
|
2016-08-16 12:23:49 +08:00
|
|
|
bool font::italic() const
|
2015-12-25 04:51:11 +08:00
|
|
|
{
|
|
|
|
return italic_;
|
|
|
|
}
|
|
|
|
|
2016-08-16 12:23:49 +08:00
|
|
|
font &font::strikethrough(bool strikethrough)
|
2015-12-25 04:51:11 +08:00
|
|
|
{
|
|
|
|
strikethrough_ = strikethrough;
|
2016-12-24 23:04:57 +08:00
|
|
|
return *this;
|
2015-12-25 04:51:11 +08:00
|
|
|
}
|
|
|
|
|
2016-08-16 12:23:49 +08:00
|
|
|
bool font::strikethrough() const
|
2015-12-25 04:51:11 +08:00
|
|
|
{
|
|
|
|
return strikethrough_;
|
|
|
|
}
|
|
|
|
|
2017-02-11 12:22:38 +08:00
|
|
|
font &font::outline(bool outline)
|
2017-02-07 05:54:09 +08:00
|
|
|
{
|
2017-02-11 12:22:38 +08:00
|
|
|
outline_ = outline;
|
2017-02-07 05:54:09 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2017-02-11 12:22:38 +08:00
|
|
|
bool font::outline() const
|
2017-02-07 05:54:09 +08:00
|
|
|
{
|
2017-02-11 12:22:38 +08:00
|
|
|
return outline_;
|
2017-02-07 05:54:09 +08:00
|
|
|
}
|
|
|
|
|
2017-02-11 12:22:38 +08:00
|
|
|
font &font::shadow(bool shadow)
|
2017-02-07 05:54:09 +08:00
|
|
|
{
|
2017-02-11 12:22:38 +08:00
|
|
|
shadow_ = shadow;
|
2017-02-07 05:54:09 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2017-02-11 12:22:38 +08:00
|
|
|
bool font::shadow() const
|
2017-02-07 05:54:09 +08:00
|
|
|
{
|
2017-02-11 12:22:38 +08:00
|
|
|
return shadow_;
|
2017-02-07 05:54:09 +08:00
|
|
|
}
|
|
|
|
|
2016-08-16 12:23:49 +08:00
|
|
|
font &font::underline(underline_style new_underline)
|
2015-12-25 04:51:11 +08:00
|
|
|
{
|
|
|
|
underline_ = new_underline;
|
2016-12-24 23:04:57 +08:00
|
|
|
return *this;
|
2015-12-25 04:51:11 +08:00
|
|
|
}
|
|
|
|
|
2016-08-16 12:23:49 +08:00
|
|
|
bool font::underlined() const
|
2015-12-25 04:51:11 +08:00
|
|
|
{
|
|
|
|
return underline_ != underline_style::none;
|
|
|
|
}
|
|
|
|
|
2016-08-16 12:23:49 +08:00
|
|
|
font::underline_style font::underline() const
|
2015-12-25 04:51:11 +08:00
|
|
|
{
|
|
|
|
return underline_;
|
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
bool font::has_size() const
|
|
|
|
{
|
|
|
|
return size_.is_set();
|
|
|
|
}
|
|
|
|
|
2016-12-23 19:51:30 +08:00
|
|
|
font &font::size(double size)
|
2015-12-25 04:51:11 +08:00
|
|
|
{
|
|
|
|
size_ = size;
|
2016-12-24 23:04:57 +08:00
|
|
|
return *this;
|
2015-12-25 04:51:11 +08:00
|
|
|
}
|
|
|
|
|
2016-12-23 19:51:30 +08:00
|
|
|
double font::size() const
|
2015-12-25 04:51:11 +08:00
|
|
|
{
|
2018-06-26 16:32:59 +08:00
|
|
|
if (size_.is_set())
|
|
|
|
{
|
|
|
|
return size_.get();
|
|
|
|
}
|
|
|
|
return Default_Size;
|
2016-12-02 21:37:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool font::has_name() const
|
|
|
|
{
|
|
|
|
return name_.is_set();
|
2015-12-25 04:51:11 +08:00
|
|
|
}
|
|
|
|
|
2016-08-16 12:23:49 +08:00
|
|
|
font &font::name(const std::string &name)
|
2015-12-25 04:51:11 +08:00
|
|
|
{
|
|
|
|
name_ = name;
|
2016-12-24 23:04:57 +08:00
|
|
|
return *this;
|
2015-12-25 04:51:11 +08:00
|
|
|
}
|
2016-12-02 21:37:50 +08:00
|
|
|
|
2018-07-14 15:52:21 +08:00
|
|
|
const std::string &font::name() const
|
2015-12-25 04:51:11 +08:00
|
|
|
{
|
2018-06-24 13:31:05 +08:00
|
|
|
if (name_.is_set())
|
|
|
|
{
|
|
|
|
return name_.get();
|
|
|
|
}
|
2018-07-14 15:52:21 +08:00
|
|
|
return Default_Name();
|
2016-12-02 21:37:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool font::has_color() const
|
|
|
|
{
|
|
|
|
return color_.is_set();
|
2015-12-25 04:51:11 +08:00
|
|
|
}
|
|
|
|
|
2016-08-16 12:23:49 +08:00
|
|
|
font &font::color(const xlnt::color &c)
|
2015-12-25 04:51:11 +08:00
|
|
|
{
|
|
|
|
color_ = c;
|
2016-12-24 23:04:57 +08:00
|
|
|
return *this;
|
2015-12-25 04:51:11 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
bool font::has_family() const
|
|
|
|
{
|
|
|
|
return family_.is_set();
|
|
|
|
}
|
|
|
|
|
2016-08-16 12:23:49 +08:00
|
|
|
font &font::family(std::size_t family)
|
2015-12-25 04:51:11 +08:00
|
|
|
{
|
|
|
|
family_ = family;
|
2016-12-24 23:04:57 +08:00
|
|
|
return *this;
|
2015-12-25 04:51:11 +08:00
|
|
|
}
|
|
|
|
|
2017-02-07 05:54:09 +08:00
|
|
|
bool font::has_charset() const
|
|
|
|
{
|
|
|
|
return charset_.is_set();
|
|
|
|
}
|
|
|
|
|
|
|
|
font &font::charset(std::size_t charset)
|
|
|
|
{
|
|
|
|
charset_ = charset;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2018-03-21 21:03:37 +08:00
|
|
|
std::size_t font::charset() const
|
|
|
|
{
|
|
|
|
return charset_.get();
|
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
bool font::has_scheme() const
|
|
|
|
{
|
|
|
|
return scheme_.is_set();
|
|
|
|
}
|
|
|
|
|
2016-08-16 12:23:49 +08:00
|
|
|
font &font::scheme(const std::string &scheme)
|
2015-12-25 04:51:11 +08:00
|
|
|
{
|
|
|
|
scheme_ = scheme;
|
2016-12-24 23:04:57 +08:00
|
|
|
return *this;
|
2015-12-25 04:51:11 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
color font::color() const
|
2015-12-25 04:51:11 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
return color_.get();
|
2015-12-25 04:51:11 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
std::size_t font::family() const
|
2015-12-25 04:51:11 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
return family_.get();
|
2015-12-25 04:51:11 +08:00
|
|
|
}
|
|
|
|
|
2018-07-14 15:52:21 +08:00
|
|
|
const std::string &font::scheme() const
|
2016-07-10 03:12:53 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
return scheme_.get();
|
2016-07-10 03:12:53 +08:00
|
|
|
}
|
|
|
|
|
2017-03-31 11:52:57 +08:00
|
|
|
bool font::operator==(const font &other) const
|
2016-11-01 08:48:43 +08:00
|
|
|
{
|
2018-03-21 21:03:37 +08:00
|
|
|
// name
|
|
|
|
if (has_name() != other.has_name()) return false;
|
|
|
|
if (has_name() && name() != other.name()) return false;
|
|
|
|
// size
|
|
|
|
if (has_size() != other.has_size()) return false;
|
|
|
|
if (has_size() && std::fabs(size() - other.size()) != 0.0) return false;
|
|
|
|
// family
|
|
|
|
if (has_family() != other.has_family()) return false;
|
|
|
|
if (has_family() && family() != other.family()) return false;
|
|
|
|
// scheme
|
|
|
|
if (has_scheme() != other.has_scheme()) return false;
|
|
|
|
if (has_scheme() && scheme() != other.scheme()) return false;
|
|
|
|
// color
|
|
|
|
if (has_color() != other.has_color()) return false;
|
|
|
|
if (has_color() && color() != other.color()) return false;
|
|
|
|
// charset
|
2018-06-26 16:32:59 +08:00
|
|
|
if (has_charset() != other.has_charset()) return false;
|
|
|
|
if (has_charset() && charset() != other.charset()) return false;
|
2018-03-21 21:03:37 +08:00
|
|
|
// modifiers
|
|
|
|
if (bold() != other.bold()) return false;
|
|
|
|
if (italic() != other.italic()) return false;
|
|
|
|
if (strikethrough() != other.strikethrough()) return false;
|
|
|
|
if (superscript() != other.superscript()) return false;
|
|
|
|
if (subscript() != other.subscript()) return false;
|
|
|
|
if (underline() != other.underline()) return false;
|
|
|
|
if (shadow() != other.shadow()) return false;
|
2016-12-24 23:04:57 +08:00
|
|
|
|
2016-11-01 08:48:43 +08:00
|
|
|
return true;
|
2015-12-25 04:51:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace xlnt
|