MWProParser.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 #ifndef MW_PRO_PARSER
00036 #  define MW_PRO_PARSER
00037 
00038 #include <list>
00039 #include <string>
00040 #include <vector>
00041 
00042 #include "MWAWDebug.hxx"
00043 #include "MWAWEntry.hxx"
00044 #include "MWAWInputStream.hxx"
00045 
00046 #include "MWAWParser.hxx"
00047 
00048 class WPXBinaryData;
00049 
00050 namespace MWProParserInternal
00051 {
00052 struct State;
00053 struct TextZoneData;
00054 struct TextZone;
00055 struct Token;
00056 struct Zone;
00057 class SubDocument;
00058 }
00059 
00060 class MWProStructures;
00061 class MWProStructuresListenerState;
00062 
00068 class MWProParser : public MWAWParser
00069 {
00070   friend class MWProStructures;
00071   friend class MWProStructuresListenerState;
00072   friend class MWProParserInternal::SubDocument;
00073 
00074 public:
00076   MWProParser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header);
00078   virtual ~MWProParser();
00079 
00081   bool checkHeader(MWAWHeader *header, bool strict=false);
00082 
00083   // the main parse function
00084   void parse(WPXDocumentInterface *documentInterface);
00085 
00086 protected:
00088   void init();
00089 
00091   void createDocument(WPXDocumentInterface *documentInterface);
00092 
00094   bool createZones();
00095 
00097   bool getZoneData(WPXBinaryData &data, int blockId);
00098 
00100   bool getFreeZoneList(int blockId, std::vector<int> &blockLists);
00101 
00106   bool parseDataZone(int blockId, int type);
00107 
00109   bool parseTextZone(shared_ptr<MWProParserInternal::Zone> zone);
00110 
00112   bool readTextEntries(shared_ptr<MWProParserInternal::Zone> zone,
00113                        std::vector<MWAWEntry> &res, int textLength);
00115   bool readTextIds(shared_ptr<MWProParserInternal::Zone> zone,
00116                    std::vector<MWProParserInternal::TextZoneData> &res,
00117                    int textLength, int type);
00119   bool readTextTokens(shared_ptr<MWProParserInternal::Zone> zone,
00120                       std::vector<MWProParserInternal::Token> &res,
00121                       int textLength);
00122 
00125   std::vector<int> const &getBlocksCalledByToken() const;
00126 
00128   float pageHeight() const;
00130   int numColumns() const;
00131 
00133   void newPage(int number, bool softBreak=false);
00134 
00135   //
00136   // interface with MWProParserStructures
00137   //
00138 
00140   bool sendTextZone(int blockId, bool mainZone = false);
00141 
00143   int findNumHardBreaks(int blockId);
00144 
00146   bool sendPictureZone(int blockId, MWAWPosition const &pictPos,
00147                        WPXPropertyList extras = WPXPropertyList());
00148 
00150   bool sendTextBoxZone(int blockId, MWAWPosition const &pos,
00151                        WPXPropertyList extras = WPXPropertyList());
00152 
00154   bool sendEmptyFrameZone(MWAWPosition const &pos, WPXPropertyList extras);
00155 
00156   //
00157   // low level
00158   //
00159 
00161   bool readPrintInfo();
00162 
00164   bool readDocHeader();
00165 
00166 #ifdef DEBUG
00167 
00168   void saveOriginal(MWAWInputStreamPtr input);
00169 #endif
00170 
00172   bool sendPicture(shared_ptr<MWProParserInternal::Zone> zone, MWAWPosition pictPos, WPXPropertyList const &extras);
00173 
00175   bool sendText(shared_ptr<MWProParserInternal::TextZone> zone, bool mainZone = false);
00176 
00178   int findNumHardBreaks(shared_ptr<MWProParserInternal::TextZone> zone);
00179 
00181   void checkUnparsed();
00182 
00183 protected:
00184   //
00185   // data
00186   //
00188   shared_ptr<MWProParserInternal::State> m_state;
00189 
00191   shared_ptr<MWProStructures> m_structures;
00192 };
00193 #endif
00194 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: