Files
core/OdfFile/Reader/Converter/docx_table_context.h
2023-03-01 23:21:57 +03:00

226 lines
6.6 KiB
C++

/*
* (c) Copyright Ascensio System SIA 2010-2023
*
* 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. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* 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: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#pragma once
#include <string>
#include <list>
#include <vector>
#include "ooxtablerowspanned.h"
namespace cpdoccore {
namespace oox {
class docx_conversion_context;
class docx_table_state
{
public:
docx_table_state(docx_conversion_context & Context, const std::wstring & StyleName);
std::wstring current_style() const { return table_style_; }
void start_column(unsigned int repeated, const std::wstring & defaultCellStyleName);
std::wstring get_default_cell_style_col(unsigned int column);
std::wstring get_default_cell_style_row();
void start_row(const std::wstring & StyleName, const std::wstring & defaultCellStyleName);
void end_row();
std::wstring current_row_style() const;
void start_cell();
void end_cell();
bool start_covered_cell(docx_conversion_context & Context);
void end_covered_cell();
int current_column() const;
void set_columns_spanned(unsigned int Val);
unsigned int current_columns_spaned() const;
void set_rows_spanned(unsigned int Column, unsigned int Val, unsigned int ColumnsSpanned, const std::wstring & Style);
unsigned int current_rows_spanned(unsigned int Column) const;
double get_current_cell_width();
void add_column_width(double width);
private:
docx_conversion_context & context_;
std::wstring table_style_;
std::vector<std::wstring> table_row_style_stack_;
std::wstring default_row_cell_style_name_;
int current_table_column_;
unsigned int columns_spanned_num_;
std::wstring columns_spanned_style_;
std::vector<table_row_spanned> rows_spanned_;
bool close_table_covered_cell_;
std::vector<unsigned int> columns_;
std::vector<double> columns_width_;
std::vector<std::wstring> columnsDefaultCellStyleName_;
};
class docx_table_context
{
public:
docx_table_context(docx_conversion_context & Context) : context_(Context)
{}
void start_table(const std::wstring & StyleName)
{
table_states_.push_back(docx_table_state(context_, StyleName));
}
void end_table()
{
if (table_states_.empty()) return;
table_states_.pop_back();
}
std::wstring current_style() const
{
if (table_states_.empty()) return L"";
return table_states_.back().current_style();
}
size_t in_table() const
{
return table_states_.size();
}
void start_column(unsigned int repeated, const std::wstring & defaultCellStyleName)
{
if (table_states_.empty()) return;
return table_states_.back().start_column(repeated, defaultCellStyleName);
}
void start_row(const std::wstring & StyleName, const std::wstring & defaultCellStyleName)
{
if (table_states_.empty()) return;
return table_states_.back().start_row(StyleName, defaultCellStyleName);
}
void end_row()
{
if (table_states_.empty()) return;
return table_states_.back().end_row();
}
std::wstring current_row_style() const
{
if (table_states_.empty()) return L"";
return table_states_.back().current_row_style();
}
void start_cell()
{
return table_states_.back().start_cell();
}
double get_current_cell_width()
{
if (table_states_.empty()) return 0;
return table_states_.back().get_current_cell_width();
}
void add_column_width(double width)
{
if (table_states_.empty()) return;
table_states_.back().add_column_width(width);
}
void end_cell()
{
if (table_states_.empty()) return;
return table_states_.back().end_cell();
}
bool start_covered_cell(docx_conversion_context & Context)
{
if (table_states_.empty()) return false;
return table_states_.back().start_covered_cell(Context);
}
void end_covered_cell()
{
if (table_states_.empty()) return;
return table_states_.back().end_covered_cell();
}
int current_column() const
{
if (table_states_.empty()) return 0;
return table_states_.back().current_column();
}
void set_columns_spanned(unsigned int Val)
{
if (table_states_.empty()) return;
return table_states_.back().set_columns_spanned(Val);
}
unsigned int current_columns_spaned() const
{
if (table_states_.empty()) return 0;
return table_states_.back().current_columns_spaned();
}
void set_rows_spanned(unsigned int Column, unsigned int Val, unsigned int ColumnsSpanned, const std::wstring & Style)
{
if (table_states_.empty()) return;
return table_states_.back().set_rows_spanned(Column, Val, ColumnsSpanned, Style);
}
unsigned int current_rows_spanned(unsigned int Column) const
{
if (table_states_.empty()) return 0;
return table_states_.back().current_rows_spanned(Column);
}
std::wstring get_default_cell_style_col(unsigned int column)
{
if (table_states_.empty()) return L"";
return table_states_.back().get_default_cell_style_col(column);
}
std::wstring get_default_cell_style_row()
{
if (table_states_.empty()) return L"";
return table_states_.back().get_default_cell_style_row();
}
private:
docx_conversion_context & context_;
std::vector<docx_table_state> table_states_;
};
}
}