/* * 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_fill.h" #include "xlsx_fills.h" #include "../Format/style_text_properties.h" #include "../Format/style_table_properties.h" #include "../Format/style_paragraph_properties.h" #include #include #include namespace cpdoccore { namespace oox { class xlsx_fills::Impl { public: typedef boost::unordered_set > xlsx_fill_array; xlsx_fill_array fills_; }; xlsx_fills::xlsx_fills(): impl_( new xlsx_fills::Impl() ) { //defaults fill { xlsx_patternFill patternFill; patternFill.patternType = L"none"; xlsx_fill fill; fill.patternFill = patternFill; fill.index = 0; fill.bDefault = true; impl_->fills_.insert(fill); } { xlsx_patternFill patternFill; patternFill.patternType = L"gray125"; xlsx_fill fill; fill.patternFill = patternFill; fill.index = 1; fill.bDefault = false; impl_->fills_.insert(fill); } } xlsx_fills::~xlsx_fills() { } size_t xlsx_fills::size() const { return impl_->fills_.size(); } size_t xlsx_fills::fillId( const odf_reader::text_format_properties_ptr &textProp, const odf_reader::paragraph_format_properties *parProp, const odf_reader::style_table_cell_properties_attlist *cellProp, bool default_set) { bool is_default; return fillId(textProp, parProp, cellProp,default_set, is_default); } size_t xlsx_fills::fillId( const odf_reader::text_format_properties_ptr &textProp, const odf_reader::paragraph_format_properties *parProp, const odf_reader::style_table_cell_properties_attlist *cellProp, bool default_set, bool & is_default) { is_default = true; xlsx_fill fill(NULL, cellProp); if (fill.bEnabled) { fill.bDefault = default_set; Impl::xlsx_fill_array::const_iterator i = impl_->fills_.find(fill); if (i != impl_->fills_.end()) { const std::size_t dbgId = i->index; if (default_set && i->bDefault != default_set) { fill.index = i->index; impl_->fills_.insert(i,fill); is_default = default_set; return fill.index; } is_default = i->bDefault; return dbgId; } else { fill.index = impl_->fills_.size(); impl_->fills_.insert(fill); is_default = default_set; return fill.index; } } return 0; } namespace { struct compare_xlsx_fills { bool operator() (xlsx_fill const & x1, xlsx_fill const & x2) { return x1.index < x2.index; } }; } void xlsx_fills::serialize(std::wostream & _Wostream) const { std::vector inst_array; for (boost::unordered_set>::iterator it = impl_->fills_.begin(); it != impl_->fills_.end(); ++it) { inst_array.push_back(*it); } std::sort(inst_array.begin(), inst_array.end(), compare_xlsx_fills()); CP_XML_WRITER(_Wostream) { CP_XML_NODE(L"fills") { CP_XML_ATTR(L"count", inst_array.size()); for (size_t i = 0; i < inst_array.size(); i++) { xlsx_serialize(CP_XML_STREAM(), inst_array[i]); } } } } } }