CWParser.hxx
Go to the documentation of this file.
00001 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
00002 
00003 /* libmwaw
00004 * Version: MPL 2.0 / LGPLv2+
00005 *
00006 * The contents of this file are subject to the Mozilla Public License Version
00007 * 2.0 (the "License"); you may not use this file except in compliance with
00008 * the License or as specified alternatively below. You may obtain a copy of
00009 * the License at http://www.mozilla.org/MPL/
00010 *
00011 * Software distributed under the License is distributed on an "AS IS" basis,
00012 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013 * for the specific language governing rights and limitations under the
00014 * License.
00015 *
00016 * Major Contributor(s):
00017 * Copyright (C) 2002 William Lachance (wrlach@gmail.com)
00018 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
00019 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
00020 * Copyright (C) 2006, 2007 Andrew Ziem
00021 * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
00022 *
00023 *
00024 * All Rights Reserved.
00025 *
00026 * For minor contributions see the git repository.
00027 *
00028 * Alternatively, the contents of this file may be used under the terms of
00029 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
00030 * in which case the provisions of the LGPLv2+ are applicable
00031 * instead of those above.
00032 */
00033 
00034 /*
00035  * Parser to Claris Works text document
00036  *
00037  */
00038 #ifndef CW_MWAW_PARSER
00039 #  define CW_MWAW_PARSER
00040 
00041 #include <set>
00042 #include <string>
00043 #include <vector>
00044 
00045 #include <libwpd/libwpd.h>
00046 
00047 #include "MWAWEntry.hxx"
00048 #include "MWAWPosition.hxx"
00049 
00050 #include "MWAWParser.hxx"
00051 
00052 #include "CWStruct.hxx"
00053 
00054 namespace CWParserInternal
00055 {
00056 struct State;
00057 class SubDocument;
00058 }
00059 
00060 class CWDatabase;
00061 class CWGraph;
00062 class CWPresentation;
00063 class CWSpreadsheet;
00064 class CWStyleManager;
00065 class CWTable;
00066 class CWText;
00067 
00073 class CWParser : public MWAWParser
00074 {
00075   friend class CWParserInternal::SubDocument;
00076   friend class CWDatabase;
00077   friend class CWGraph;
00078   friend class CWPresentation;
00079   friend class CWSpreadsheet;
00080   friend class CWStyleManager;
00081   friend class CWTable;
00082   friend class CWText;
00083 
00084 public:
00086   CWParser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header);
00088   virtual ~CWParser();
00089 
00091   bool checkHeader(MWAWHeader *header, bool strict=false);
00092 
00093   // the main parse function
00094   void parse(WPXDocumentInterface *documentInterface);
00095 
00096 protected:
00098   void init();
00099 
00101   void createDocument(WPXDocumentInterface *documentInterface);
00102 
00104   bool createZones();
00105 
00107   shared_ptr<CWStruct::DSET> getZone(int zId) const;
00108 
00110   bool exploreZonesGraph();
00112   bool exploreZonesGraphRec(int zId, std::set<int> &notDoneList);
00113 
00115   void typeMainZones();
00116 
00118   int typeMainZonesRec(int zId, CWStruct::DSET::Type type, int maxHeight);
00119 
00121   bool readZone();
00122 
00124   bool readPrintInfo();
00125 
00127   bool readStructZone(char const *zoneName, bool hasEntete);
00128 
00131   bool readStructIntZone(char const *zoneName, bool hasEntete, int fSz, std::vector<int> &res);
00132 
00134   Vec2i getDocumentPages() const;
00136   double getTextHeight() const;
00138   Vec2f getPageLeftTop() const;
00140   void newPage(int number);
00141 
00142   //
00143   // interface with the text parser
00144   //
00145 
00147   bool canSendZoneAsGraphic(int number) const;
00149   bool sendZone(int zoneId, bool asGraphic, MWAWPosition pos=MWAWPosition());
00151   void forceParsed(int zoneId);
00152 
00154   void sendFootnote(int zoneId);
00155 
00157   MWAWSection getMainSection() const;
00158 
00159   //
00160   // interface with the graph parser
00161   //
00162 
00164   void getHeaderFooterId(int &headerId, int &footerId) const;
00165 
00166   //
00167   // low level
00168   //
00169 
00171   bool readDocHeader();
00172 
00174   bool readDocInfo();
00175 
00177   bool readEndTable();
00178 
00182   shared_ptr<CWStruct::DSET> readDSET(bool &complete);
00183 
00184   // THE NAMED ENTRY
00185 
00186   /* read the document summary */
00187   bool readDSUM(MWAWEntry const &entry, bool inHeader);
00188 
00189   /* read the temporary file name ? */
00190   bool readTNAM(MWAWEntry const &entry);
00191 
00192   /* SNAP (in v6) : size[4]/size[2] picture... */
00193   bool readSNAP(MWAWEntry const &entry);
00194 
00195   /* sequence of plist of printer : in v6
00196    */
00197   bool readCPRT(MWAWEntry const &entry);
00198 
00200   void checkOrdering(std::vector<int16_t> &vec16, std::vector<int32_t> &vec32) const;
00201 
00202 protected:
00203 
00204 
00205   //
00206   // data
00207   //
00209   shared_ptr<CWParserInternal::State> m_state;
00210 
00212   bool m_pageSpanSet;
00213 
00215   shared_ptr<CWDatabase> m_databaseParser;
00216 
00218   shared_ptr<CWGraph> m_graphParser;
00219 
00221   shared_ptr<CWPresentation> m_presentationParser;
00222 
00224   shared_ptr<CWSpreadsheet> m_spreadsheetParser;
00225 
00227   shared_ptr<CWStyleManager> m_styleManager;
00228 
00230   shared_ptr<CWTable> m_tableParser;
00231 
00233   shared_ptr<CWText> m_textParser;
00234 };
00235 #endif
00236 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: