MRWParser.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 convert Mariner Write document
00036  */
00037 #ifndef MRW_PARSER
00038 #  define MRW_PARSER
00039 
00040 #include <iostream>
00041 #include <string>
00042 #include <vector>
00043 
00044 #include <libwpd/libwpd.h>
00045 
00046 class WPXBinaryData;
00047 
00048 #include "MWAWDebug.hxx"
00049 #include "MWAWEntry.hxx"
00050 #include "MWAWInputStream.hxx"
00051 
00052 #include "MWAWParser.hxx"
00053 
00054 namespace MRWParserInternal
00055 {
00056 struct State;
00057 class SubDocument;
00058 }
00059 
00060 class MRWGraph;
00061 class MRWText;
00062 
00064 struct MRWEntry : public MWAWEntry {
00066   MRWEntry() : MWAWEntry(), m_fileType(0), m_N(0), m_value(0) {
00067   }
00069   std::string name() const;
00071   friend std::ostream &operator<< (std::ostream &o, MRWEntry const &ent) {
00072     if (ent.m_N || ent.m_value || ent.m_extra.length()) {
00073       o << "[";
00074       if (ent.m_N) o << "N=" << ent.m_N << ",";
00075       if (ent.m_value) o << "unkn=" << ent.m_value << ",";
00076       if (ent.m_extra.length()) o << ent.m_extra;
00077       o << "],";
00078     }
00079     return o;
00080   }
00082   int m_fileType;
00084   int m_N;
00086   int m_value;
00087 };
00088 
00090 struct MRWStruct {
00092   MRWStruct() : m_filePos(-1), m_pos(), m_type(-1), m_data() {
00093   }
00095   friend std::ostream &operator<<(std::ostream &o, MRWStruct const &dt);
00097   int numValues() const {
00098     return int(m_data.size());
00099   }
00101   bool isBasic() const {
00102     return (m_type==1 || m_type==2) && m_data.size()<=1;
00103   }
00105   long value(int i) const;
00107   long m_filePos;
00109   MWAWEntry m_pos;
00111   int m_type;
00113   std::vector<long> m_data;
00114 };
00115 
00121 class MRWParser : public MWAWParser
00122 {
00123   friend class MRWGraph;
00124   friend class MRWText;
00125   friend class MRWParserInternal::SubDocument;
00126 
00127 public:
00129   MRWParser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header);
00131   virtual ~MRWParser();
00132 
00134   bool checkHeader(MWAWHeader *header, bool strict=false);
00135 
00136   // the main parse function
00137   void parse(WPXDocumentInterface *documentInterface);
00138 
00139 protected:
00141   void init();
00142 
00144   void createDocument(WPXDocumentInterface *documentInterface);
00145 
00147   bool createZones();
00149   bool readZone(int &actZone, bool onlyTest=false);
00150 
00152   Vec2f getPageLeftTop() const;
00154   MWAWSection getSection(int zoneId) const;
00155 
00157   void newPage(int number);
00158 
00159   // interface with the text parser
00160 
00162   int getZoneId(uint32_t fileId, bool &endNote);
00164   void sendText(int zoneId);
00165 
00166   // interface with the graph parser
00168   float getPatternPercent(int id) const;
00170   void sendToken(int zoneId, long tokenId);
00171 
00172   //
00173   // low level
00174   //
00175 
00177   bool readEntryHeader(MRWEntry &entry);
00179   bool decodeZone(std::vector<MRWStruct> &dataList, long numData=999999);
00180 
00182   bool readSeparator(MRWEntry const &entry);
00184   bool readZoneDim(MRWEntry const &entry, int zoneId);
00186   bool readZoneHeader(MRWEntry const &entry, int zoneId, bool onlyTest);
00188   bool readZoneb(MRWEntry const &entry, int zoneId);
00190   bool readZonec(MRWEntry const &entry, int zoneId);
00192   bool readZone13(MRWEntry const &entry, int zoneId);
00194   bool readDocInfo(MRWEntry const &entry, int zoneId);
00196   bool readPrintInfo(MRWEntry const &entry);
00198   bool readCPRT(MRWEntry const &entry);
00199 
00201   bool readNumbersString(int num, std::vector<long> &res);
00202 
00203 protected:
00204   //
00205   // data
00206   //
00208   shared_ptr<MRWParserInternal::State> m_state;
00209 
00211   bool  m_pageMarginsSpanSet;
00212 
00214   shared_ptr<MRWGraph> m_graphParser;
00215 
00217   shared_ptr<MRWText> m_textParser;
00218 };
00219 #endif
00220 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: