2020-02-09 01:12:59 +08:00
|
|
|
// Copyright (c) 2014-2020 Thomas Fussell
|
2018-06-23 08:15:15 +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
|
|
|
|
// 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
|
|
|
|
|
2018-06-23 17:08:12 +08:00
|
|
|
#include <xlnt/worksheet/phonetic_pr.hpp>
|
2018-06-23 08:15:15 +08:00
|
|
|
#include <array>
|
|
|
|
namespace {
|
|
|
|
// Order of elements defined by phonetic_pr::Type enum
|
2018-07-14 16:07:48 +08:00
|
|
|
const std::array<std::string, 4> &Types()
|
2018-07-14 15:52:21 +08:00
|
|
|
{
|
|
|
|
static const std::array<std::string, 4> types{
|
2018-07-14 16:07:48 +08:00
|
|
|
std::string("fullwidthKatakana"),
|
|
|
|
std::string("halfwidthKatakana"),
|
|
|
|
std::string("Hiragana"),
|
|
|
|
std::string("noConversion")};
|
2018-07-14 15:52:21 +08:00
|
|
|
return types;
|
|
|
|
}
|
2018-06-23 08:15:15 +08:00
|
|
|
|
2018-06-26 16:32:59 +08:00
|
|
|
// Order of elements defined by phonetic_pr::alignment enum
|
2018-07-14 15:52:21 +08:00
|
|
|
const std::array<std::string, 4> &Alignments()
|
|
|
|
{
|
|
|
|
static const std::array<std::string, 4> alignments{
|
2018-07-14 16:07:48 +08:00
|
|
|
std::string("Center"),
|
|
|
|
std::string("Distributed"),
|
|
|
|
std::string("Left"),
|
|
|
|
std::string("NoControl")};
|
2018-07-14 15:52:21 +08:00
|
|
|
return alignments;
|
|
|
|
}
|
2018-06-23 08:15:15 +08:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace xlnt {
|
|
|
|
/// <summary>
|
|
|
|
/// out of line initialiser for static const member
|
|
|
|
/// </summary>
|
2018-07-14 16:07:48 +08:00
|
|
|
std::string phonetic_pr::Serialised_ID()
|
|
|
|
{
|
|
|
|
return "phoneticPr";
|
|
|
|
}
|
2018-06-23 08:15:15 +08:00
|
|
|
|
2018-06-26 16:32:59 +08:00
|
|
|
phonetic_pr::phonetic_pr(font_id_t font)
|
2018-06-23 08:15:15 +08:00
|
|
|
: font_id_(font)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void phonetic_pr::serialise(std::ostream &output_stream) const
|
|
|
|
{
|
2018-07-14 16:07:48 +08:00
|
|
|
output_stream << '<' << Serialised_ID() << R"( fontID=")" << std::to_string(font_id_) << '"';
|
2018-06-23 08:15:15 +08:00
|
|
|
if (has_type())
|
|
|
|
{
|
|
|
|
output_stream << R"( type=")" << type_as_string(type_.get()) << '"';
|
|
|
|
}
|
|
|
|
if (has_alignment())
|
|
|
|
{
|
|
|
|
output_stream << R"( alignment=")" << alignment_as_string(alignment_.get()) << '"';
|
|
|
|
}
|
|
|
|
output_stream << "/>";
|
|
|
|
}
|
|
|
|
|
2018-06-26 16:32:59 +08:00
|
|
|
phonetic_pr::font_id_t phonetic_pr::font_id() const
|
2018-06-23 08:15:15 +08:00
|
|
|
{
|
|
|
|
return font_id_;
|
|
|
|
}
|
|
|
|
|
2018-06-26 16:32:59 +08:00
|
|
|
void phonetic_pr::font_id(font_id_t font)
|
2018-06-23 08:15:15 +08:00
|
|
|
{
|
|
|
|
font_id_ = font;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool phonetic_pr::has_type() const
|
|
|
|
{
|
|
|
|
return type_.is_set();
|
|
|
|
}
|
|
|
|
|
2018-06-26 16:32:59 +08:00
|
|
|
phonetic_pr::phonetic_type phonetic_pr::type() const
|
2018-06-23 08:15:15 +08:00
|
|
|
{
|
|
|
|
return type_.get();
|
|
|
|
}
|
|
|
|
|
2018-06-26 16:32:59 +08:00
|
|
|
void phonetic_pr::type(phonetic_type type)
|
2018-06-23 08:15:15 +08:00
|
|
|
{
|
|
|
|
type_.set(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool phonetic_pr::has_alignment() const
|
|
|
|
{
|
|
|
|
return alignment_.is_set();
|
|
|
|
}
|
|
|
|
|
2018-06-26 16:32:59 +08:00
|
|
|
phonetic_pr::align phonetic_pr::alignment() const
|
2018-06-23 08:15:15 +08:00
|
|
|
{
|
|
|
|
return alignment_.get();
|
|
|
|
}
|
|
|
|
|
2018-06-26 16:32:59 +08:00
|
|
|
void phonetic_pr::alignment(align align)
|
2018-06-23 08:15:15 +08:00
|
|
|
{
|
|
|
|
alignment_.set(align);
|
|
|
|
}
|
|
|
|
|
|
|
|
// serialisation
|
2018-06-26 16:32:59 +08:00
|
|
|
const std::string &phonetic_pr::type_as_string(phonetic_pr::phonetic_type type)
|
2018-06-23 08:15:15 +08:00
|
|
|
{
|
2018-07-14 16:07:48 +08:00
|
|
|
return Types()[static_cast<std::size_t>(type)];
|
2018-06-23 08:15:15 +08:00
|
|
|
}
|
|
|
|
|
2018-06-26 16:32:59 +08:00
|
|
|
phonetic_pr::phonetic_type phonetic_pr::type_from_string(const std::string &str)
|
2018-06-23 08:15:15 +08:00
|
|
|
{
|
2018-07-14 15:52:21 +08:00
|
|
|
for (std::size_t i = 0; i < Types().size(); ++i)
|
2018-06-23 08:15:15 +08:00
|
|
|
{
|
2018-07-14 15:52:21 +08:00
|
|
|
if (str == Types()[i])
|
2018-06-23 08:15:15 +08:00
|
|
|
{
|
2018-06-26 16:32:59 +08:00
|
|
|
return static_cast<phonetic_type>(i);
|
2018-06-23 08:15:15 +08:00
|
|
|
}
|
|
|
|
}
|
2018-06-26 16:32:59 +08:00
|
|
|
return phonetic_type::no_conversion;
|
2018-06-23 08:15:15 +08:00
|
|
|
}
|
|
|
|
|
2018-06-26 16:32:59 +08:00
|
|
|
const std::string &phonetic_pr::alignment_as_string(align type)
|
2018-06-23 08:15:15 +08:00
|
|
|
{
|
2018-07-14 16:07:48 +08:00
|
|
|
return Alignments()[static_cast<std::size_t>(type)];
|
2018-06-23 08:15:15 +08:00
|
|
|
}
|
|
|
|
|
2018-06-26 16:32:59 +08:00
|
|
|
phonetic_pr::align phonetic_pr::alignment_from_string(const std::string &str)
|
2018-06-23 08:15:15 +08:00
|
|
|
{
|
2018-07-14 15:52:21 +08:00
|
|
|
for (std::size_t i = 0; i < Alignments().size(); ++i)
|
2018-06-23 08:15:15 +08:00
|
|
|
{
|
2018-07-14 15:52:21 +08:00
|
|
|
if (str == Alignments()[i])
|
2018-06-23 08:15:15 +08:00
|
|
|
{
|
2018-06-26 16:32:59 +08:00
|
|
|
return static_cast<align>(i);
|
2018-06-23 08:15:15 +08:00
|
|
|
}
|
|
|
|
}
|
2018-06-26 16:32:59 +08:00
|
|
|
return align::no_control;
|
2018-06-23 08:15:15 +08:00
|
|
|
}
|
|
|
|
|
2018-07-03 10:05:07 +08:00
|
|
|
bool phonetic_pr::operator==(const phonetic_pr &rhs) const
|
|
|
|
{
|
|
|
|
return font_id_ == rhs.font_id_
|
|
|
|
&& type_ == rhs.type_
|
|
|
|
&& alignment_ == rhs.alignment_;
|
|
|
|
}
|
|
|
|
|
2020-02-09 01:12:59 +08:00
|
|
|
} // namespace xlnt
|