MacWrtProParser.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 MAC_WRT_PRO_PARSER
00036 #  define MAC_WRT_PRO_PARSER
00037 
00038 #include <list>
00039 #include <string>
00040 #include <vector>
00041 
00042 #include "MWAWDebug.hxx"
00043 #include "MWAWEntry.hxx"
00044 #include "MWAWGraphicStyle.hxx"
00045 #include "MWAWInputStream.hxx"
00046 
00047 #include "MWAWParser.hxx"
00048 
00049 namespace MacWrtProParserInternal
00050 {
00051 struct State;
00052 struct TextZoneData;
00053 struct TextZone;
00054 struct Token;
00055 struct Zone;
00056 class SubDocument;
00057 }
00058 
00059 class MacWrtProStructures;
00060 class MacWrtProStructuresListenerState;
00061 
00067 class MacWrtProParser : public MWAWTextParser
00068 {
00069   friend class MacWrtProStructures;
00070   friend class MacWrtProStructuresListenerState;
00071   friend class MacWrtProParserInternal::SubDocument;
00072 
00073 public:
00075   MacWrtProParser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header);
00077   virtual ~MacWrtProParser();
00078 
00080   bool checkHeader(MWAWHeader *header, bool strict=false);
00081 
00082   // the main parse function
00083   void parse(librevenge::RVNGTextInterface *documentInterface);
00084 
00085 protected:
00087   void init();
00088 
00090   void createDocument(librevenge::RVNGTextInterface *documentInterface);
00091 
00093   bool createZones();
00094 
00096   bool getZoneData(librevenge::RVNGBinaryData &data, int blockId);
00097 
00099   bool getFreeZoneList(int blockId, std::vector<int> &blockLists);
00100 
00105   bool parseDataZone(int blockId, int type);
00106 
00108   bool parseTextZone(shared_ptr<MacWrtProParserInternal::Zone> zone);
00109 
00111   bool readTextEntries(shared_ptr<MacWrtProParserInternal::Zone> zone,
00112                        std::vector<MWAWEntry> &res, int textLength);
00114   bool readTextIds(shared_ptr<MacWrtProParserInternal::Zone> zone,
00115                    std::vector<MacWrtProParserInternal::TextZoneData> &res,
00116                    int textLength, int type);
00118   bool readTextTokens(shared_ptr<MacWrtProParserInternal::Zone> zone,
00119                       std::vector<MacWrtProParserInternal::Token> &res,
00120                       int textLength);
00121 
00124   std::vector<int> const &getBlocksCalledByToken() const;
00125 
00127   float pageHeight() const;
00129   int numColumns() const;
00130 
00132   void newPage(int number, bool softBreak=false);
00133 
00134   //
00135   // interface with MacWrtProParserStructures
00136   //
00137 
00139   bool sendTextZone(int blockId, bool mainZone = false);
00140 
00142   int findNumHardBreaks(int blockId);
00143 
00145   bool sendPictureZone(int blockId, MWAWPosition const &pictPos, MWAWGraphicStyle const &style=MWAWGraphicStyle::emptyStyle());
00146 
00148   bool sendTextBoxZone(int blockId, MWAWPosition const &pos, MWAWGraphicStyle const &style=MWAWGraphicStyle::emptyStyle());
00150   bool sendEmptyFrameZone(MWAWPosition const &pos, MWAWGraphicStyle const &style);
00151 
00152   //
00153   // low level
00154   //
00155 
00157   bool readPrintInfo();
00158 
00160   bool readDocHeader();
00161 
00162 #ifdef DEBUG
00163 
00164   void saveOriginal(MWAWInputStreamPtr input);
00165 #endif
00166 
00168   bool sendPicture(shared_ptr<MacWrtProParserInternal::Zone> zone, MWAWPosition pictPos, MWAWGraphicStyle const &style=MWAWGraphicStyle::emptyStyle());
00169 
00171   bool sendText(shared_ptr<MacWrtProParserInternal::TextZone> zone, bool mainZone = false);
00172 
00174   int findNumHardBreaks(shared_ptr<MacWrtProParserInternal::TextZone> zone);
00175 
00177   void checkUnparsed();
00178 
00179 protected:
00180   //
00181   // data
00182   //
00184   shared_ptr<MacWrtProParserInternal::State> m_state;
00185 
00187   shared_ptr<MacWrtProStructures> m_structures;
00188 };
00189 #endif
00190 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: