/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ /* libwps * Version: MPL 2.0 / LGPLv2.1+ * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * Major Contributor(s): * Copyright (C) 2006, 2007 Andrew Ziem * Copyright (C) 2004 Marc Maurer (uwog@uwog.net) * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch) * * For minor contributions see the git repository. * * Alternatively, the contents of this file may be used under the terms * of the GNU Lesser General Public License Version 2.1 or later * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are * applicable instead of those above. */ #include #include #include #include #include #include #include #include "libwps_internal.h" #include "libwps_tools_win.h" #include "WPSCell.h" #include "WKSContentListener.h" #include "WPSEntry.h" #include "WPSFont.h" #include "WPSTable.h" #include "WKS4.h" #include "WKS4Spreadsheet.h" namespace WKS4SpreadsheetInternal { /////////////////////////////////////////////////////////////////// //! a class used to store a style of a cell in WKS4Spreadsheet struct Style final : public WPSCellFormat { //! construtor explicit Style(libwps_tools_win::Font::Type type) : WPSCellFormat() , m_fileFont() , m_fontType(type) , m_extra("") { for (int &unknFlag : m_unknFlags) unknFlag = 0; } Style(Style const &)=default; Style &operator=(Style const &)=default; //! destructor ~Style() final; //! operator<< friend std::ostream &operator<<(std::ostream &o, Style const &style); //! operator== bool operator==(Style const &st) const; //! operator!= bool operator!=(Style const &st) const { return !(*this==st); } /** the font */ WPSFont m_fileFont; //! font encoding type libwps_tools_win::Font::Type m_fontType; /** some flag */ int m_unknFlags[10]; /** extra data */ std::string m_extra; }; Style::~Style() { } //! operator<< std::ostream &operator<<(std::ostream &o, Style const &style) { o << "font=[" << style.m_fileFont << "],"; o << static_cast(style) << ","; bool hasUnkn = false; for (int unknFlag : style.m_unknFlags) { if (!unknFlag) continue; hasUnkn=true; break; } if (hasUnkn) { o << "unkn=[" << std::hex; for (int i = 0; i < 10; i++) { if (style.m_unknFlags[i]) o << "fS" << i << "=" << std::hex << style.m_unknFlags[i] << std::dec << ","; } o << std::dec << "]"; } if (style.m_extra.length()) o << ", extra=[" << style.m_extra << "]"; return o; } bool Style::operator==(Style const &st) const { if (m_fileFont!=st.m_fileFont) return false; if (m_format!=st.m_format || m_subFormat!=st.m_subFormat || m_digits!=st.m_digits || m_protected !=st.m_protected) return false; int diff = WPSCellFormat::compare(st); if (diff) return false; for (int i = 0; i < 10; i++) { if (m_unknFlags[i]!=st.m_unknFlags[i]) return false; } return m_extra==st.m_extra; } /////////////////////////////////////////////////////////////////// //! the style manager class StyleManager { public: StyleManager() : m_stylesList() {} //! add a new style and returns its id int add(Style const &st, bool dosFile) { if (dosFile) { for (size_t i=0; i < m_stylesList.size(); ++i) { if (m_stylesList[i]==st) return int(i); } } m_stylesList.push_back(st); return int(m_stylesList.size())-1; } //! returns the style with id bool get(int id, Style &style) const { if (id<0|| id >= int(m_stylesList.size())) { WPS_DEBUG_MSG(("WKS4ParserInternal::StyleManager::get can not find style %d\n", id)); return false; } style=m_stylesList[size_t(id)]; return true; } //! returns the number of style int size() const { return int(m_stylesList.size()); } //! print a style void print(int id, std::ostream &o) const { if (id < 0) return; if (id < int(m_stylesList.size())) o << ", style=" << m_stylesList[size_t(id)]; else { WPS_DEBUG_MSG(("WKS4ParserInternal::StyleManager::print: can not find a style\n")); o << ", ###style=" << id; } } protected: //! the styles std::vector