/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */ /* libmwaw * Version: MPL 2.0 / LGPLv2+ * * The contents of this file are subject to the Mozilla Public License Version * 2.0 (the "License"); you may not use this file except in compliance with * the License or as specified alternatively below. You may obtain a copy of * the License at http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * Major Contributor(s): * Copyright (C) 2002 William Lachance (wrlach@gmail.com) * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net) * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch) * Copyright (C) 2006, 2007 Andrew Ziem * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr) * * * All Rights Reserved. * * 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 or later (the "LGPLv2+"), * in which case the provisions of the LGPLv2+ are applicable * instead of those above. */ #include #include #include #include #include #include #include "MWAWFont.hxx" #include "MWAWFontConverter.hxx" #include "MWAWGraphicStyle.hxx" #include "MWAWHeader.hxx" #include "MWAWParagraph.hxx" #include "MWAWPosition.hxx" #include "MWAWPrinter.hxx" #include "MWAWRSRCParser.hxx" #include "MWAWSection.hxx" #include "MWAWSpreadsheetListener.hxx" #include "MWAWSubDocument.hxx" #include "GreatWksDocument.hxx" #include "GreatWksGraph.hxx" #include "GreatWksText.hxx" #include "GreatWksSSParser.hxx" /** Internal: the structures of a GreatWksSSParser */ namespace GreatWksSSParserInternal { /**a style of a GreatWksSSParser */ class Style { public: /** constructor */ Style() : m_font(3,10) , m_backgroundColor(MWAWColor::white()) { } /** the font style */ MWAWFont m_font; /** the cell background color */ MWAWColor m_backgroundColor; }; /** a cell of a GreatWksSSParser */ class Cell final : public MWAWCell { public: /// constructor Cell() : m_content(), m_style(-1) { } Cell(Cell const &)=default; Cell &operator=(Cell &&)=default; Cell &operator=(Cell const &)=default; /// destructor ~Cell() final; //! returns true if the cell do contain any content bool isEmpty() const { return m_content.empty() && !hasBorders(); } //! the cell content MWAWCellContent m_content; /** the cell style */ int m_style; }; Cell::~Cell() { } /** the spreadsheet of a of a MsWksSSParser */ class Spreadsheet { public: //! constructor Spreadsheet() : m_widthDefault(75) , m_widthCols() , m_heightDefault(13) , m_heightRows() , m_cells() , m_name("Sheet0") { } //! returns the row size in point int getRowHeight(int row) const { if (row>=0&&row(m_heightRows.size())) return m_heightRows[size_t(row)]; return m_heightDefault; } //! returns the height of a row in point and updated repeated row double getRowHeight(int row, int &numRepeated) const { double res=getRowHeight(row); numRepeated=1; if (row<0 || row>=static_cast(m_heightRows.size())) numRepeated=1000; else { for (auto r=size_t(row+1); rres) break; ++numRepeated; } } return res; } //! convert the m_widthCols in a vector of of point size std::vector convertInPoint(std::vector const &list) const { auto numCols=size_t(getRightBottomPosition()[0]+1); std::vector res; res.resize(numCols); for (size_t i = 0; i < numCols; i++) { if (i>=list.size() || list[i] < 0) res[i] = float(m_widthDefault); else res[i] = float(list[i]); } return res; } /** the default column width */ int m_widthDefault; /** the column size in points */ std::vector m_widthCols; /** the default row height */ int m_heightDefault; /** the row height in points */ std::vector m_heightRows; /** the list of not empty cells */ std::vector m_cells; /** the spreadsheet name */ std::string m_name; protected: /** returns the last Right Bottom cell position */ MWAWVec2i getRightBottomPosition() const { int maxX = 0, maxY = 0; for (auto const &cell : m_cells) { MWAWVec2i const &p = cell.position(); if (p[0] > maxX) maxX = p[0]; if (p[1] > maxY) maxY = p[1]; } return MWAWVec2i(maxX, maxY); } }; //////////////////////////////////////// //! Internal: the state of a GreatWksSSParser struct State { //! constructor State() : m_spreadsheet() , m_styleList() , m_actPage(0) , m_numPages(0) , m_headerEntry() , m_footerEntry() , m_headerPrint(false) , m_footerPrint(false) , m_headerHeight(0) , m_footerHeight(0) { } //! returns the style corresponding to an id Style getStyle(int id) const { if (id<0 || id>=int(m_styleList.size())) { MWAW_DEBUG_MSG(("GreatWksSSParserInternal::State: can not find the style %d\n", id)); return Style(); } return m_styleList[size_t(id)]; } /** the spreadsheet */ Spreadsheet m_spreadsheet; /** the list of style */ std::vector