mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-07-11 05:24:10 +08:00
Co-authored-by: Alexander Trofimov <alexander.trofimov@onlyoffice.com> Co-committed-by: Alexander Trofimov <alexander.trofimov@onlyoffice.com>
202 lines
7.0 KiB
C++
202 lines
7.0 KiB
C++
/*
|
|
* Copyright (C) Ascensio System SIA, 2009-2026
|
|
*
|
|
* This program is a free software product. You can redistribute it and/or
|
|
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
|
* version 3 as published by the Free Software Foundation, together with the
|
|
* additional terms provided in the LICENSE file.
|
|
*
|
|
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
|
* details, see the GNU AGPL at: https://www.gnu.org/licenses/agpl-3.0.html
|
|
*
|
|
* You can contact Ascensio System SIA by email at info@onlyoffice.com
|
|
* or by postal mail at 20A-6 Ernesta Birznieka-Upisha Street, Riga,
|
|
* LV-1050, Latvia, European Union.
|
|
*
|
|
* The interactive user interfaces in modified versions of the Program
|
|
* are required to display Appropriate Legal Notices in accordance with
|
|
* Section 5 of the GNU AGPL version 3.
|
|
*
|
|
* No trademark rights are granted under this License.
|
|
*
|
|
* All non-code elements of the Product, including illustrations,
|
|
* icon sets, and technical writing content, are licensed under the
|
|
* Creative Commons Attribution-ShareAlike 4.0 International License:
|
|
* https://creativecommons.org/licenses/by-sa/4.0/legalcode
|
|
*
|
|
* This license applies only to such non-code elements and does not
|
|
* modify or replace the licensing terms applicable to the Program's
|
|
* source code, which remains licensed under the GNU Affero General
|
|
* Public License v3.
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
#include "xlsx_border.h"
|
|
#include <boost/functional.hpp>
|
|
#include <xml/simple_xml_writer.h>
|
|
#include "../Format/style_text_properties.h"
|
|
|
|
namespace cpdoccore {
|
|
namespace oox {
|
|
|
|
bool xlsx_border::operator == (const xlsx_border & rVal) const
|
|
{
|
|
const bool res =
|
|
diagonalUp.get_value_or(false) == rVal.diagonalUp.get_value_or(false) &&
|
|
diagonalDown.get_value_or(false) == rVal.diagonalDown.get_value_or(false) &&
|
|
outline.get_value_or(true) == rVal.outline.get_value_or(true) &&
|
|
|
|
left.get_value_or(xlsx_border_edge(L"none")) == rVal.left.get_value_or(xlsx_border_edge(L"none")) &&
|
|
right.get_value_or(xlsx_border_edge(L"none")) == rVal.right.get_value_or(xlsx_border_edge(L"none")) &&
|
|
top.get_value_or(xlsx_border_edge(L"none")) == rVal.top.get_value_or(xlsx_border_edge(L"none")) &&
|
|
bottom.get_value_or(xlsx_border_edge(L"none")) == rVal.bottom.get_value_or(xlsx_border_edge(L"none")) &&
|
|
diagonal.get_value_or(xlsx_border_edge(L"none")) == rVal.diagonal.get_value_or(xlsx_border_edge(L"none")) &&
|
|
vertical.get_value_or(xlsx_border_edge(L"none")) == rVal.vertical.get_value_or(xlsx_border_edge(L"none")) &&
|
|
horizontal.get_value_or(xlsx_border_edge(L"none")) == rVal.horizontal.get_value_or(xlsx_border_edge(L"none"));
|
|
|
|
return res;
|
|
}
|
|
|
|
bool xlsx_border::operator != (const xlsx_border & rVal) const
|
|
{
|
|
return !(this->operator ==(rVal));
|
|
}
|
|
|
|
bool xlsx_border_edge::operator == (const xlsx_border_edge & rVal) const
|
|
{
|
|
const bool res =
|
|
style.get_value_or(L"none") == rVal.style.get_value_or(L"none") &&
|
|
//abs(width.get_value_or(0)/100 - rVal.width.get_value_or(0)/100)<10 &&
|
|
color == rVal.color;
|
|
return res;
|
|
}
|
|
|
|
bool xlsx_border_edge::operator != (const xlsx_border_edge & rVal) const
|
|
{
|
|
return !(this->operator ==(rVal));
|
|
}
|
|
|
|
std::size_t hash_value(xlsx_border_edge const& val)
|
|
{
|
|
std::size_t seed = 0;
|
|
boost::hash_combine(seed, val.style.get_value_or(L""));
|
|
boost::hash_combine(seed, val.color.get_value_or(xlsx_color()));
|
|
return seed;
|
|
}
|
|
std::size_t hash_value(const _CP_OPT(xlsx_border_edge) & val)
|
|
{
|
|
std::size_t seed = 0;
|
|
if (val)
|
|
{
|
|
boost::hash_combine(seed, val->style.get_value_or(L""));
|
|
boost::hash_combine(seed, val->color.get_value_or(xlsx_color()));
|
|
}
|
|
return seed;
|
|
}
|
|
void xlsx_serialize(std::wostream & _Wostream, const _CP_OPT(xlsx_border_edge) & borderEdge, const std::wstring & name)
|
|
{
|
|
if (borderEdge)
|
|
{
|
|
CP_XML_WRITER(_Wostream)
|
|
{
|
|
CP_XML_NODE(name)
|
|
{
|
|
if (borderEdge->style)
|
|
CP_XML_ATTR(L"style", borderEdge->style.get());
|
|
|
|
if (borderEdge->color)
|
|
xlsx_serialize(CP_XML_STREAM(), borderEdge->color.get());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void xlsx_serialize(std::wostream & _Wostream, const xlsx_border & border)
|
|
{
|
|
CP_XML_WRITER(_Wostream)
|
|
{
|
|
CP_XML_NODE(L"border")
|
|
{
|
|
if (border.diagonalUp)
|
|
CP_XML_ATTR(L"diagonalUp", border.diagonalUp.get());
|
|
if (border.diagonalDown)
|
|
CP_XML_ATTR(L"diagonalDown", border.diagonalDown.get());
|
|
if (border.outline && border.outline.get() == false)
|
|
CP_XML_ATTR(L"outline", border.outline.get());
|
|
|
|
|
|
xlsx_serialize(CP_XML_STREAM(), border.left, L"left");
|
|
xlsx_serialize(CP_XML_STREAM(), border.right, L"right");
|
|
xlsx_serialize(CP_XML_STREAM(), border.top, L"top");
|
|
xlsx_serialize(CP_XML_STREAM(), border.bottom, L"bottom");
|
|
xlsx_serialize(CP_XML_STREAM(), border.diagonal, L"diagonal");
|
|
xlsx_serialize(CP_XML_STREAM(), border.vertical, L"vertical");
|
|
xlsx_serialize(CP_XML_STREAM(), border.horizontal, L"horizontal");
|
|
}
|
|
}
|
|
}
|
|
|
|
std::size_t hash_value(xlsx_border const& val)
|
|
{
|
|
std::size_t seed = 0;
|
|
boost::hash_combine(seed, val.diagonalUp.get_value_or(false));
|
|
boost::hash_combine(seed, val.diagonalDown.get_value_or(false));
|
|
boost::hash_combine(seed, val.outline.get_value_or(false));
|
|
|
|
boost::hash_combine(seed, val.left);
|
|
boost::hash_combine(seed, val.right);
|
|
boost::hash_combine(seed, val.top);
|
|
boost::hash_combine(seed, val.bottom);
|
|
boost::hash_combine(seed, val.diagonal);
|
|
boost::hash_combine(seed, val.vertical);
|
|
boost::hash_combine(seed, val.horizontal);
|
|
|
|
return seed;
|
|
}
|
|
|
|
bool is_default(const _CP_OPT(xlsx_border_edge) & borderEdge)
|
|
{
|
|
if (!borderEdge) return true;
|
|
if (is_default(borderEdge.get())) return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
bool is_default(xlsx_border_edge * borderEdge)
|
|
{
|
|
if (!borderEdge) return true;
|
|
if (!borderEdge->style) return true;
|
|
if (borderEdge->style.get() == L"none") return true;
|
|
|
|
return false;
|
|
}
|
|
bool is_default(xlsx_border_edge const& borderEdge)
|
|
{
|
|
if (!borderEdge.style) return true;
|
|
if (borderEdge.style.get() == L"none") return true;
|
|
|
|
return false;
|
|
}
|
|
bool is_default(xlsx_border const& border)
|
|
{
|
|
if (border.diagonalUp.get_value_or(false) == false &&
|
|
border.diagonalDown.get_value_or(false) == false &&
|
|
border.outline.get_value_or(true) == true &&
|
|
is_default(border.left) &&
|
|
is_default(border.right) &&
|
|
is_default(border.top) &&
|
|
is_default(border.bottom) &&
|
|
is_default(border.diagonal) &&
|
|
is_default(border.vertical) &&
|
|
is_default(border.horizontal)
|
|
)
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
|
|
}
|
|
}
|