2021-08-22 20:23:18 +08:00
|
|
|
// Copyright (c) 2014-2021 Thomas Fussell
|
2015-10-02 06:14:42 +08:00
|
|
|
// Copyright (c) 2010-2015 openpyxl
|
2014-06-06 04:19:31 +08:00
|
|
|
//
|
|
|
|
// 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,
|
2014-06-06 04:19:31 +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-04 20:29:10 +08:00
|
|
|
|
2014-06-06 04:19:31 +08:00
|
|
|
#pragma once
|
|
|
|
|
2015-10-14 01:56:07 +08:00
|
|
|
#include <string>
|
|
|
|
|
2015-11-20 11:54:54 +08:00
|
|
|
#include <xlnt/xlnt_config.hpp>
|
2015-10-14 01:56:07 +08:00
|
|
|
#include <xlnt/styles/color.hpp>
|
2016-08-16 12:23:49 +08:00
|
|
|
#include <xlnt/utils/optional.hpp>
|
2015-11-04 13:36:14 +08:00
|
|
|
|
2014-06-06 04:19:31 +08:00
|
|
|
namespace xlnt {
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-19 03:30:46 +08:00
|
|
|
class style;
|
2014-06-06 04:19:31 +08:00
|
|
|
|
2015-11-21 09:41:32 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Describes the font style of a particular cell.
|
|
|
|
/// </summary>
|
2016-11-01 08:48:43 +08:00
|
|
|
class XLNT_API font
|
2014-06-06 04:19:31 +08:00
|
|
|
{
|
2016-01-18 14:23:31 +08:00
|
|
|
public:
|
2016-11-20 14:01:32 +08:00
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// Text can be underlined in the enumerated ways
|
2016-11-20 14:01:32 +08:00
|
|
|
/// </summary>
|
2015-10-29 03:08:54 +08:00
|
|
|
enum class underline_style
|
2014-06-06 04:19:31 +08:00
|
|
|
{
|
|
|
|
none,
|
|
|
|
double_,
|
|
|
|
double_accounting,
|
|
|
|
single,
|
|
|
|
single_accounting
|
|
|
|
};
|
2016-11-20 14:01:32 +08:00
|
|
|
|
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// Constructs a default font. Calibri, size 12
|
2016-11-20 14:01:32 +08:00
|
|
|
/// </summary>
|
2016-06-11 01:40:50 +08:00
|
|
|
font();
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2016-11-20 14:01:32 +08:00
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// Sets the bold state of the font to bold and returns a reference to the font.
|
2016-11-20 14:01:32 +08:00
|
|
|
/// </summary>
|
2016-08-16 12:23:49 +08:00
|
|
|
font &bold(bool bold);
|
2016-01-18 14:23:31 +08:00
|
|
|
|
2016-11-20 14:01:32 +08:00
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// Returns the bold state of the font.
|
2016-11-20 14:01:32 +08:00
|
|
|
/// </summary>
|
2016-08-16 12:23:49 +08:00
|
|
|
bool bold() const;
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2016-11-20 14:01:32 +08:00
|
|
|
/// <summary>
|
2018-03-21 21:03:37 +08:00
|
|
|
/// Sets the vertical alignment of the font to subscript and returns a reference to the font.
|
|
|
|
/// </summary>
|
|
|
|
font &subscript(bool value);
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns true if this font has a vertical alignment of subscript.
|
|
|
|
/// </summary>
|
|
|
|
bool subscript() const;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Sets the vertical alignment of the font to superscript and returns a reference to the font.
|
2016-11-20 14:01:32 +08:00
|
|
|
/// </summary>
|
2018-03-21 21:03:37 +08:00
|
|
|
font &superscript(bool value);
|
2016-10-14 08:11:02 +08:00
|
|
|
|
2016-11-20 14:01:32 +08:00
|
|
|
/// <summary>
|
2018-03-21 21:03:37 +08:00
|
|
|
/// Returns true if this font has a vertical alignment of superscript.
|
2016-11-20 14:01:32 +08:00
|
|
|
/// </summary>
|
2016-12-04 20:29:10 +08:00
|
|
|
bool superscript() const;
|
2016-10-14 08:11:02 +08:00
|
|
|
|
2016-11-20 14:01:32 +08:00
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// Sets the bold state of the font to bold and returns a reference to the font.
|
2016-11-20 14:01:32 +08:00
|
|
|
/// </summary>
|
2016-08-16 12:23:49 +08:00
|
|
|
font &italic(bool italic);
|
2016-01-18 14:23:31 +08:00
|
|
|
|
2016-11-20 14:01:32 +08:00
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// Returns true if this font has italics applied.
|
2016-11-20 14:01:32 +08:00
|
|
|
/// </summary>
|
2016-08-16 12:23:49 +08:00
|
|
|
bool italic() const;
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2016-11-20 14:01:32 +08:00
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// Sets the bold state of the font to bold and returns a reference to the font.
|
2016-11-20 14:01:32 +08:00
|
|
|
/// </summary>
|
2016-08-16 12:23:49 +08:00
|
|
|
font &strikethrough(bool strikethrough);
|
2016-01-18 14:23:31 +08:00
|
|
|
|
2016-11-20 14:01:32 +08:00
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// Returns true if this font has a strikethrough applied.
|
2016-11-20 14:01:32 +08:00
|
|
|
/// </summary>
|
2016-08-16 12:23:49 +08:00
|
|
|
bool strikethrough() const;
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2017-02-07 05:54:09 +08:00
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// Sets the bold state of the font to bold and returns a reference to the font.
|
2017-02-07 05:54:09 +08:00
|
|
|
/// </summary>
|
2017-02-11 12:22:38 +08:00
|
|
|
font &outline(bool outline);
|
2017-02-07 05:54:09 +08:00
|
|
|
|
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// Returns true if this font has an outline applied.
|
2017-02-07 05:54:09 +08:00
|
|
|
/// </summary>
|
2017-02-11 12:22:38 +08:00
|
|
|
bool outline() const;
|
2017-02-07 05:54:09 +08:00
|
|
|
|
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// Sets the shadow state of the font to shadow and returns a reference to the font.
|
2017-02-07 05:54:09 +08:00
|
|
|
/// </summary>
|
2017-02-11 12:22:38 +08:00
|
|
|
font &shadow(bool shadow);
|
2017-02-07 05:54:09 +08:00
|
|
|
|
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// Returns true if this font has a shadow applied.
|
2017-02-07 05:54:09 +08:00
|
|
|
/// </summary>
|
2017-02-11 12:22:38 +08:00
|
|
|
bool shadow() const;
|
2017-02-07 05:54:09 +08:00
|
|
|
|
2016-11-20 14:01:32 +08:00
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// Sets the underline state of the font to new_underline and returns a reference to the font.
|
2016-11-20 14:01:32 +08:00
|
|
|
/// </summary>
|
2016-08-16 12:23:49 +08:00
|
|
|
font &underline(underline_style new_underline);
|
2016-01-18 14:23:31 +08:00
|
|
|
|
2016-11-20 14:01:32 +08:00
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// Returns true if this font has any type of underline applied.
|
2016-11-20 14:01:32 +08:00
|
|
|
/// </summary>
|
2016-08-16 12:23:49 +08:00
|
|
|
bool underlined() const;
|
2016-01-18 14:23:31 +08:00
|
|
|
|
2016-11-20 14:01:32 +08:00
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// Returns the particular style of underline this font has applied.
|
2016-11-20 14:01:32 +08:00
|
|
|
/// </summary>
|
2016-08-16 12:23:49 +08:00
|
|
|
underline_style underline() const;
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// Returns true if this font has a defined size.
|
2016-12-02 21:37:50 +08:00
|
|
|
/// </summary>
|
|
|
|
bool has_size() const;
|
|
|
|
|
2016-11-20 14:01:32 +08:00
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// Sets the size of the font to size and returns a reference to the font.
|
2016-11-20 14:01:32 +08:00
|
|
|
/// </summary>
|
2016-12-23 19:51:30 +08:00
|
|
|
font &size(double size);
|
2016-01-18 14:23:31 +08:00
|
|
|
|
2016-11-20 14:01:32 +08:00
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// Returns the size of the font.
|
2016-11-20 14:01:32 +08:00
|
|
|
/// </summary>
|
2016-12-23 19:51:30 +08:00
|
|
|
double size() const;
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// Returns true if this font has a particular face applied (e.g. "Comic Sans").
|
2016-12-02 21:37:50 +08:00
|
|
|
/// </summary>
|
|
|
|
bool has_name() const;
|
|
|
|
|
2016-11-20 14:01:32 +08:00
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// Sets the font face to name and returns a reference to the font.
|
2016-11-20 14:01:32 +08:00
|
|
|
/// </summary>
|
2016-08-16 12:23:49 +08:00
|
|
|
font &name(const std::string &name);
|
2016-01-18 14:23:31 +08:00
|
|
|
|
2016-11-20 14:01:32 +08:00
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// Returns the name of the font face.
|
2016-11-20 14:01:32 +08:00
|
|
|
/// </summary>
|
2019-12-27 01:03:12 +08:00
|
|
|
const std::string &name() const;
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// Returns true if this font has a color applied.
|
2016-12-02 21:37:50 +08:00
|
|
|
/// </summary>
|
|
|
|
bool has_color() const;
|
|
|
|
|
2016-11-20 14:01:32 +08:00
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// Sets the color of the font to c and returns a reference to the font.
|
2016-11-20 14:01:32 +08:00
|
|
|
/// </summary>
|
2016-08-16 12:23:49 +08:00
|
|
|
font &color(const color &c);
|
2016-01-18 14:23:31 +08:00
|
|
|
|
2016-11-20 14:01:32 +08:00
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// Returns the color that this font is using.
|
2016-11-20 14:01:32 +08:00
|
|
|
/// </summary>
|
2016-12-04 20:29:10 +08:00
|
|
|
xlnt::color color() const;
|
2016-12-02 21:37:50 +08:00
|
|
|
|
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// Returns true if this font has a family defined.
|
2016-12-02 21:37:50 +08:00
|
|
|
/// </summary>
|
|
|
|
bool has_family() const;
|
2016-01-18 14:23:31 +08:00
|
|
|
|
2016-11-20 14:01:32 +08:00
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// Sets the family index of the font to family and returns a reference to the font.
|
2016-11-20 14:01:32 +08:00
|
|
|
/// </summary>
|
2016-08-16 12:23:49 +08:00
|
|
|
font &family(std::size_t family);
|
2016-07-10 03:12:53 +08:00
|
|
|
|
2016-11-20 14:01:32 +08:00
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// Returns the family index for the font.
|
2016-11-20 14:01:32 +08:00
|
|
|
/// </summary>
|
2016-12-04 20:29:10 +08:00
|
|
|
std::size_t family() const;
|
2016-12-02 21:37:50 +08:00
|
|
|
|
2017-02-07 05:54:09 +08:00
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// Returns true if this font has a charset defined.
|
2017-02-07 05:54:09 +08:00
|
|
|
/// </summary>
|
|
|
|
bool has_charset() const;
|
|
|
|
|
2017-03-31 11:52:57 +08:00
|
|
|
// TODO: charset should be an enum, not a number
|
|
|
|
|
2017-02-07 05:54:09 +08:00
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// Sets the charset of the font to charset and returns a reference to the font.
|
2017-02-07 05:54:09 +08:00
|
|
|
/// </summary>
|
|
|
|
font &charset(std::size_t charset);
|
|
|
|
|
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// Returns the charset of the font.
|
2017-02-07 05:54:09 +08:00
|
|
|
/// </summary>
|
|
|
|
std::size_t charset() const;
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// Returns true if this font has a scheme.
|
2016-12-02 21:37:50 +08:00
|
|
|
/// </summary>
|
|
|
|
bool has_scheme() const;
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2016-11-20 14:01:32 +08:00
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// Sets the scheme of the font to scheme and returns a reference to the font.
|
2016-11-20 14:01:32 +08:00
|
|
|
/// </summary>
|
2016-08-16 12:23:49 +08:00
|
|
|
font &scheme(const std::string &scheme);
|
2016-07-10 03:12:53 +08:00
|
|
|
|
2016-11-20 14:01:32 +08:00
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// Returns the scheme of this font.
|
2016-11-20 14:01:32 +08:00
|
|
|
/// </summary>
|
2019-12-27 01:03:12 +08:00
|
|
|
const std::string &scheme() const;
|
2016-12-04 20:29:10 +08:00
|
|
|
|
2016-11-01 08:48:43 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Returns true if left is exactly equal to right.
|
|
|
|
/// </summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
bool operator==(const font &other) const;
|
2016-12-04 20:29:10 +08:00
|
|
|
|
2016-11-01 08:48:43 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Returns true if left is not exactly equal to right.
|
|
|
|
/// </summary>
|
2018-06-24 13:31:05 +08:00
|
|
|
bool operator!=(const font &other) const
|
|
|
|
{
|
|
|
|
return !operator==(other);
|
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2016-01-18 14:23:31 +08:00
|
|
|
private:
|
2015-10-19 03:30:46 +08:00
|
|
|
friend class style;
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2016-11-20 14:01:32 +08:00
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// The name of the font
|
2016-11-20 14:01:32 +08:00
|
|
|
/// </summary>
|
2016-12-02 21:37:50 +08:00
|
|
|
optional<std::string> name_;
|
2016-11-20 14:01:32 +08:00
|
|
|
|
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// size
|
2016-11-20 14:01:32 +08:00
|
|
|
/// </summary>
|
2016-12-23 19:51:30 +08:00
|
|
|
optional<double> size_;
|
2016-11-20 14:01:32 +08:00
|
|
|
|
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// bold
|
2016-11-20 14:01:32 +08:00
|
|
|
/// </summary>
|
2015-11-01 22:43:01 +08:00
|
|
|
bool bold_ = false;
|
2016-11-20 14:01:32 +08:00
|
|
|
|
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// italic
|
2016-11-20 14:01:32 +08:00
|
|
|
/// </summary>
|
2015-11-01 22:43:01 +08:00
|
|
|
bool italic_ = false;
|
2016-11-20 14:01:32 +08:00
|
|
|
|
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// superscript
|
2016-11-20 14:01:32 +08:00
|
|
|
/// </summary>
|
2015-11-01 22:43:01 +08:00
|
|
|
bool superscript_ = false;
|
2016-11-20 14:01:32 +08:00
|
|
|
|
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// subscript
|
2016-11-20 14:01:32 +08:00
|
|
|
/// </summary>
|
2015-11-01 22:43:01 +08:00
|
|
|
bool subscript_ = false;
|
2016-11-20 14:01:32 +08:00
|
|
|
|
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// strikethrough
|
2016-11-20 14:01:32 +08:00
|
|
|
/// </summary>
|
2015-11-01 22:43:01 +08:00
|
|
|
bool strikethrough_ = false;
|
2016-11-20 14:01:32 +08:00
|
|
|
|
2017-02-07 05:54:09 +08:00
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// outline
|
2017-02-07 05:54:09 +08:00
|
|
|
/// </summary>
|
2017-02-11 12:22:38 +08:00
|
|
|
bool outline_ = false;
|
2017-02-07 05:54:09 +08:00
|
|
|
|
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// shadow
|
2017-02-07 05:54:09 +08:00
|
|
|
/// </summary>
|
2017-02-11 12:22:38 +08:00
|
|
|
bool shadow_ = false;
|
2017-02-07 05:54:09 +08:00
|
|
|
|
2016-11-20 14:01:32 +08:00
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// underline style
|
2016-11-20 14:01:32 +08:00
|
|
|
/// </summary>
|
2016-12-04 20:29:10 +08:00
|
|
|
underline_style underline_ = underline_style::none;
|
2016-11-20 14:01:32 +08:00
|
|
|
|
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// color
|
2016-11-20 14:01:32 +08:00
|
|
|
/// </summary>
|
2016-12-04 20:29:10 +08:00
|
|
|
optional<xlnt::color> color_;
|
2016-11-20 14:01:32 +08:00
|
|
|
|
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// family
|
2016-11-20 14:01:32 +08:00
|
|
|
/// </summary>
|
2016-12-04 20:29:10 +08:00
|
|
|
optional<std::size_t> family_;
|
2016-11-20 14:01:32 +08:00
|
|
|
|
2017-02-07 05:54:09 +08:00
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// charset
|
2017-02-07 05:54:09 +08:00
|
|
|
/// </summary>
|
|
|
|
optional<std::size_t> charset_;
|
|
|
|
|
2016-11-20 14:01:32 +08:00
|
|
|
/// <summary>
|
2017-03-31 11:52:57 +08:00
|
|
|
/// scheme
|
2016-11-20 14:01:32 +08:00
|
|
|
/// </summary>
|
2016-12-04 20:29:10 +08:00
|
|
|
optional<std::string> scheme_;
|
2014-06-06 04:19:31 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace xlnt
|