2015-12-25 06:10:02 +08:00
|
|
|
// Copyright (c) 2014-2016 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
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
|
|
|
|
// 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
|
|
|
|
|
|
|
|
#include <xlnt/styles/font.hpp>
|
|
|
|
|
|
|
|
namespace xlnt {
|
|
|
|
|
2016-06-11 01:40:50 +08:00
|
|
|
|
|
|
|
font::font()
|
|
|
|
: name_("Calibri"),
|
|
|
|
size_(12),
|
|
|
|
bold_(false),
|
|
|
|
italic_(false),
|
|
|
|
superscript_(false),
|
|
|
|
subscript_(false),
|
2016-09-06 10:17:36 +08:00
|
|
|
strikethrough_(false),
|
|
|
|
underline_(underline_style::none)
|
2016-06-11 01:40:50 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-08-16 12:23:49 +08:00
|
|
|
font &font::bold(bool bold)
|
2015-12-25 04:51:11 +08:00
|
|
|
{
|
|
|
|
bold_ = bold;
|
2016-08-18 19:34:18 +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_;
|
|
|
|
}
|
|
|
|
|
2016-08-16 12:23:49 +08:00
|
|
|
font &font::italic(bool italic)
|
2015-12-25 04:51:11 +08:00
|
|
|
{
|
|
|
|
italic_ = italic;
|
2016-08-18 19:34:18 +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-08-18 19:34:18 +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_;
|
|
|
|
}
|
|
|
|
|
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-08-18 19:34:18 +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-08-16 12:23:49 +08:00
|
|
|
font &font::size(std::size_t size)
|
2015-12-25 04:51:11 +08:00
|
|
|
{
|
|
|
|
size_ = size;
|
2016-08-18 19:34:18 +08:00
|
|
|
return *this;
|
2015-12-25 04:51:11 +08:00
|
|
|
}
|
|
|
|
|
2016-08-16 12:23:49 +08:00
|
|
|
std::size_t font::size() const
|
2015-12-25 04:51:11 +08:00
|
|
|
{
|
|
|
|
return size_;
|
|
|
|
}
|
|
|
|
|
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-08-18 19:34:18 +08:00
|
|
|
return *this;
|
2015-12-25 04:51:11 +08:00
|
|
|
}
|
2016-08-16 12:23:49 +08:00
|
|
|
std::string font::name() const
|
2015-12-25 04:51:11 +08:00
|
|
|
{
|
|
|
|
return name_;
|
|
|
|
}
|
|
|
|
|
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-08-18 19:34:18 +08:00
|
|
|
return *this;
|
2015-12-25 04:51:11 +08:00
|
|
|
}
|
|
|
|
|
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-08-18 19:34:18 +08:00
|
|
|
return *this;
|
2015-12-25 04:51:11 +08:00
|
|
|
}
|
|
|
|
|
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-08-18 19:34:18 +08:00
|
|
|
return *this;
|
2015-12-25 04:51:11 +08:00
|
|
|
}
|
|
|
|
|
2016-08-16 12:23:49 +08:00
|
|
|
optional<color> font::color() const
|
2015-12-25 04:51:11 +08:00
|
|
|
{
|
|
|
|
return color_;
|
|
|
|
}
|
|
|
|
|
2016-08-16 12:23:49 +08:00
|
|
|
optional<std::size_t> font::family() const
|
2015-12-25 04:51:11 +08:00
|
|
|
{
|
|
|
|
return family_;
|
|
|
|
}
|
|
|
|
|
2016-08-16 12:23:49 +08:00
|
|
|
optional<std::string> font::scheme() const
|
2016-07-10 03:12:53 +08:00
|
|
|
{
|
|
|
|
return scheme_;
|
|
|
|
}
|
|
|
|
|
2015-12-25 04:51:11 +08:00
|
|
|
std::string font::to_hash_string() const
|
|
|
|
{
|
|
|
|
std::string hash_string = "font";
|
|
|
|
|
|
|
|
hash_string.append(std::to_string(bold_));
|
|
|
|
hash_string.append(std::to_string(italic_));
|
|
|
|
hash_string.append(std::to_string(superscript_));
|
|
|
|
hash_string.append(std::to_string(subscript_));
|
|
|
|
hash_string.append(std::to_string(strikethrough_));
|
|
|
|
hash_string.append(name_);
|
|
|
|
hash_string.append(std::to_string(size_));
|
|
|
|
hash_string.append(std::to_string(static_cast<std::size_t>(underline_)));
|
2016-08-16 12:23:49 +08:00
|
|
|
hash_string.append(family_ ? std::to_string(*family_) : "");
|
|
|
|
hash_string.append(scheme_ ? *scheme_ : "");
|
2015-12-25 04:51:11 +08:00
|
|
|
|
|
|
|
return hash_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace xlnt
|