MsWrdParser.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 MS_WRD_MWAW_PARSER
00038 #  define MS_WRD_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 MsWrdParserInternal
00053 {
00054 struct Object;
00055 struct State;
00056 class SubDocument;
00057 }
00058 
00059 class MsWrdText;
00060 class MsWrdTextStyles;
00061 
00063 struct MsWrdEntry : public MWAWEntry {
00064   MsWrdEntry() : MWAWEntry(), m_pictType(-1)
00065   {
00066   }
00071   int pictType() const
00072   {
00073     return m_pictType;
00074   }
00076   void setPictType(int newId)
00077   {
00078     m_pictType = newId;
00079   }
00081   friend std::ostream &operator<<(std::ostream &o, MsWrdEntry const &entry);
00083   int m_pictType;
00084 };
00085 
00091 class MsWrdParser : public MWAWTextParser
00092 {
00093   friend class MsWrdText;
00094   friend class MsWrdTextStyles;
00095   friend class MsWrdParserInternal::SubDocument;
00096 
00097 public:
00099   MsWrdParser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header);
00101   virtual ~MsWrdParser();
00102 
00104   bool checkHeader(MWAWHeader *header, bool strict=false);
00105 
00107   void parse(librevenge::RVNGTextInterface *documentInterface);
00108 
00109 protected:
00111   void init();
00112 
00114   void createDocument(librevenge::RVNGTextInterface *documentInterface);
00115 
00117   bool createZones();
00118 
00120   bool readHeaderEndV3();
00121 
00123   bool readZoneList();
00124 
00126   bool readPrintInfo(MsWrdEntry &entry);
00127 
00129   bool readPrinter(MsWrdEntry &entry);
00130 
00132   bool readDocSum(MsWrdEntry &entry);
00133 
00135   bool readStringsZone(MsWrdEntry &entry, std::vector<std::string> &list);
00136 
00138   bool readObjects();
00139 
00141   bool readObjectList(MsWrdEntry &entry);
00142 
00144   bool readObjectFlags(MsWrdEntry &entry);
00145 
00147   bool readObject(MsWrdParserInternal::Object &obj);
00148 
00150   bool readDocumentInfo(MsWrdEntry &entry);
00151 
00153   bool readZone17(MsWrdEntry &entry);
00154 
00156   bool checkPicturePos(long pos, int type);
00157 
00159   bool readPicture(MsWrdEntry &entry);
00161   void sendPicture(long fPos, int cPos, MWAWPosition::AnchorTo anchor=MWAWPosition::Char);
00162 
00164   bool getColor(int id, MWAWColor &col) const;
00165 
00167   void newPage(int number);
00168 
00169   /*
00170    * interface with subdocument
00171    */
00173   void sendFootnote(int id);
00174 
00176   void sendFieldComment(int id);
00177 
00179   void send(int id, libmwaw::SubDocumentType type);
00181   void send(MWAWEntry const &entry);
00182 
00183   //
00184   // low level
00185   //
00186 
00188   MsWrdEntry readEntry(std::string type, int id=-1);
00189 
00190 protected:
00191   //
00192   // data
00193   //
00195   shared_ptr<MsWrdParserInternal::State> m_state;
00196 
00198   std::multimap<std::string, MsWrdEntry> m_entryMap;
00199 
00201   shared_ptr<MsWrdText> m_textParser;
00202 };
00203 #endif
00204 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: