MarinerWrtParser.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 MARINER_WRT_PARSER
00038 #  define MARINER_WRT_PARSER
00039 
00040 #include <iostream>
00041 #include <string>
00042 #include <vector>
00043 
00044 #include <librevenge/librevenge.h>
00045 
00046 #include "MWAWDebug.hxx"
00047 #include "MWAWEntry.hxx"
00048 #include "MWAWInputStream.hxx"
00049 
00050 #include "MWAWParser.hxx"
00051 
00052 namespace MarinerWrtParserInternal
00053 {
00054 struct State;
00055 class SubDocument;
00056 }
00057 
00058 class MarinerWrtGraph;
00059 class MarinerWrtText;
00060 
00062 struct MarinerWrtEntry : public MWAWEntry {
00064   MarinerWrtEntry() : MWAWEntry(), m_fileType(0), m_N(0), m_value(0)
00065   {
00066   }
00068   std::string name() const;
00070   friend std::ostream &operator<< (std::ostream &o, MarinerWrtEntry const &ent)
00071   {
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 MarinerWrtStruct {
00092   MarinerWrtStruct() : m_filePos(-1), m_pos(), m_type(-1), m_data()
00093   {
00094   }
00096   friend std::ostream &operator<<(std::ostream &o, MarinerWrtStruct const &dt);
00098   int numValues() const
00099   {
00100     return int(m_data.size());
00101   }
00103   bool isBasic() const
00104   {
00105     return (m_type==1 || m_type==2) && m_data.size()<=1;
00106   }
00108   long value(int i) const;
00110   long m_filePos;
00112   MWAWEntry m_pos;
00114   int m_type;
00116   std::vector<long> m_data;
00117 };
00118 
00124 class MarinerWrtParser : public MWAWTextParser
00125 {
00126   friend class MarinerWrtGraph;
00127   friend class MarinerWrtText;
00128   friend class MarinerWrtParserInternal::SubDocument;
00129 
00130 public:
00132   MarinerWrtParser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header);
00134   virtual ~MarinerWrtParser();
00135 
00137   bool checkHeader(MWAWHeader *header, bool strict=false);
00138 
00139   // the main parse function
00140   void parse(librevenge::RVNGTextInterface *documentInterface);
00141 
00142 protected:
00144   void init();
00145 
00147   void createDocument(librevenge::RVNGTextInterface *documentInterface);
00148 
00150   bool createZones();
00152   bool readZone(int &actZone, bool onlyTest=false);
00153 
00155   MWAWVec2f getPageLeftTop() const;
00157   MWAWSection getSection(int zoneId) const;
00158 
00160   void newPage(int number);
00161 
00162   // interface with the text parser
00163 
00165   int getZoneId(uint32_t fileId, bool &endNote);
00167   void sendText(int zoneId);
00168 
00169   // interface with the graph parser
00171   float getPatternPercent(int id) const;
00173   void sendToken(int zoneId, long tokenId);
00174 
00175   //
00176   // low level
00177   //
00178 
00180   bool readEntryHeader(MarinerWrtEntry &entry);
00182   bool decodeZone(std::vector<MarinerWrtStruct> &dataList, long numData=999999);
00183 
00185   bool readSeparator(MarinerWrtEntry const &entry);
00187   bool readZoneDim(MarinerWrtEntry const &entry, int zoneId);
00189   bool readZoneHeader(MarinerWrtEntry const &entry, int zoneId, bool onlyTest);
00191   bool readZoneb(MarinerWrtEntry const &entry, int zoneId);
00193   bool readZonec(MarinerWrtEntry const &entry, int zoneId);
00195   bool readZone13(MarinerWrtEntry const &entry, int zoneId);
00197   bool readDocInfo(MarinerWrtEntry const &entry, int zoneId);
00199   bool readPrintInfo(MarinerWrtEntry const &entry);
00201   bool readCPRT(MarinerWrtEntry const &entry);
00202 
00204   bool readNumbersString(int num, std::vector<long> &res);
00205 
00206 protected:
00207   //
00208   // data
00209   //
00211   shared_ptr<MarinerWrtParserInternal::State> m_state;
00212 
00214   bool  m_pageMarginsSpanSet;
00215 
00217   shared_ptr<MarinerWrtGraph> m_graphParser;
00218 
00220   shared_ptr<MarinerWrtText> m_textParser;
00221 };
00222 #endif
00223 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: