MSWParser.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 for Microsoft Word ( version 3.0-5.1 )
00036  */
00037 #ifndef MSW_MWAW_PARSER
00038 #  define MSW_MWAW_PARSER
00039 
00040 #include <list>
00041 #include <map>
00042 #include <string>
00043 #include <vector>
00044 
00045 #include "MWAWDebug.hxx"
00046 #include "MWAWEntry.hxx"
00047 #include "MWAWInputStream.hxx"
00048 #include "MWAWPosition.hxx"
00049 
00050 #include "MWAWParser.hxx"
00051 
00052 namespace MSWParserInternal
00053 {
00054 struct Object;
00055 struct State;
00056 class SubDocument;
00057 }
00058 
00059 class MSWText;
00060 class MSWTextStyles;
00061 
00063 struct MSWEntry : public MWAWEntry {
00064   MSWEntry() : MWAWEntry(), m_pictType(-1) {
00065   }
00070   int pictType() const {
00071     return m_pictType;
00072   }
00074   void setPictType(int newId) {
00075     m_pictType = newId;
00076   }
00078   friend std::ostream &operator<<(std::ostream &o, MSWEntry const &entry);
00080   int m_pictType;
00081 };
00082 
00088 class MSWParser : public MWAWParser
00089 {
00090   friend class MSWText;
00091   friend class MSWTextStyles;
00092   friend class MSWParserInternal::SubDocument;
00093 
00094 public:
00096   MSWParser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header);
00098   virtual ~MSWParser();
00099 
00101   bool checkHeader(MWAWHeader *header, bool strict=false);
00102 
00104   void parse(WPXDocumentInterface *documentInterface);
00105 
00106 protected:
00108   void init();
00109 
00111   void createDocument(WPXDocumentInterface *documentInterface);
00112 
00114   bool createZones();
00115 
00117   bool readHeaderEndV3();
00118 
00120   bool readZoneList();
00121 
00123   bool readPrintInfo(MSWEntry &entry);
00124 
00126   bool readPrinter(MSWEntry &entry);
00127 
00129   bool readDocSum(MSWEntry &entry);
00130 
00132   bool readStringsZone(MSWEntry &entry, std::vector<std::string> &list);
00133 
00135   bool readObjects();
00136 
00138   bool readObjectList(MSWEntry &entry);
00139 
00141   bool readObjectFlags(MSWEntry &entry);
00142 
00144   bool readObject(MSWParserInternal::Object &obj);
00145 
00147   bool readDocumentInfo(MSWEntry &entry);
00148 
00150   bool readZone17(MSWEntry &entry);
00151 
00153   bool checkPicturePos(long pos, int type);
00154 
00156   bool readPicture(MSWEntry &entry);
00158   void sendPicture(long fPos, int cPos, MWAWPosition::AnchorTo anchor=MWAWPosition::Char);
00159 
00161   bool getColor(int id, MWAWColor &col) const;
00162 
00164   void newPage(int number);
00165 
00166   /*
00167    * interface with subdocument
00168    */
00170   void sendFootnote(int id);
00171 
00173   void sendFieldComment(int id);
00174 
00176   void send(int id, libmwaw::SubDocumentType type);
00178   void send(MWAWEntry const &entry);
00179 
00180   //
00181   // low level
00182   //
00183 
00185   MSWEntry readEntry(std::string type, int id=-1);
00186 
00187 protected:
00188   //
00189   // data
00190   //
00192   shared_ptr<MSWParserInternal::State> m_state;
00193 
00195   std::multimap<std::string, MSWEntry> m_entryMap;
00196 
00198   shared_ptr<MSWText> m_textParser;
00199 };
00200 #endif
00201 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: