HanMacWrdKParser.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 HanMac Word-K document
00036  */
00037 #ifndef HAN_MAC_WRD_K_PARSER
00038 #  define HAN_MAC_WRD_K_PARSER
00039 
00040 #include <iostream>
00041 #include <string>
00042 #include <vector>
00043 
00044 #include <librevenge/librevenge.h>
00045 
00046 #include "MWAWDebug.hxx"
00047 #include "MWAWInputStream.hxx"
00048 
00049 #include "MWAWParser.hxx"
00050 
00051 namespace HanMacWrdKParserInternal
00052 {
00053 struct State;
00054 class SubDocument;
00055 }
00056 
00058 struct HanMacWrdKZone {
00060   HanMacWrdKZone(MWAWInputStreamPtr input, libmwaw::DebugFile &asciiFile);
00062   HanMacWrdKZone(shared_ptr<libmwaw::DebugFile> asciiFile);
00064   ~HanMacWrdKZone();
00065 
00067   long begin() const
00068   {
00069     return m_asciiFilePtr ? 0 : m_filePos;
00070   }
00072   long end() const
00073   {
00074     return m_asciiFilePtr ? (long) m_data.size() : m_endFilePos;
00075   }
00077   long length() const
00078   {
00079     if (m_asciiFilePtr) return (long) m_data.size();
00080     return m_endFilePos-m_filePos;
00081   }
00083   bool valid() const
00084   {
00085     return length() > 0;
00086   }
00087 
00088   // function to define the zone in the original file
00089 
00091   long fileBeginPos() const
00092   {
00093     return m_filePos;
00094   }
00096   long fileEndPos() const
00097   {
00098     return m_endFilePos;
00099   }
00101   void setFileBeginPos(long begPos)
00102   {
00103     m_filePos = m_endFilePos = begPos;
00104   }
00106   void setFileLength(long len)
00107   {
00108     m_endFilePos = m_filePos+len;
00109   }
00111   void setFilePositions(long begPos, long endPos)
00112   {
00113     m_filePos = begPos;
00114     m_endFilePos = endPos;
00115   }
00117   librevenge::RVNGBinaryData &getBinaryData()
00118   {
00119     return m_data;
00120   }
00122   std::string name() const
00123   {
00124     return name(m_type);
00125   }
00127   static std::string name(int type);
00128 
00130   friend std::ostream &operator<<(std::ostream &o, HanMacWrdKZone const &zone);
00131 
00133   libmwaw::DebugFile &ascii() const
00134   {
00135     return *m_asciiFile;
00136   }
00137 
00139   int m_type;
00140 
00142   long m_id;
00143 
00145   long m_subId;
00146 
00148   MWAWInputStreamPtr m_input;
00149 
00151   std::string m_extra;
00152 
00154   mutable bool m_parsed;
00155 
00156 protected:
00158   long m_filePos;
00159 
00161   long m_endFilePos;
00162 
00164   librevenge::RVNGBinaryData m_data;
00165 
00167   libmwaw::DebugFile *m_asciiFile;
00168 
00170   shared_ptr<libmwaw::DebugFile> m_asciiFilePtr;
00171 
00172 private:
00173   HanMacWrdKZone(HanMacWrdKZone const &orig);
00174   HanMacWrdKZone &operator=(HanMacWrdKZone const &orig);
00175 };
00176 
00177 class HanMacWrdKGraph;
00178 class HanMacWrdKText;
00179 
00185 class HanMacWrdKParser : public MWAWTextParser
00186 {
00187   friend class HanMacWrdKGraph;
00188   friend class HanMacWrdKText;
00189   friend class HanMacWrdKParserInternal::SubDocument;
00190 
00191 public:
00193   HanMacWrdKParser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header);
00195   virtual ~HanMacWrdKParser();
00196 
00198   bool checkHeader(MWAWHeader *header, bool strict=false);
00199 
00200   // the main parse function
00201   void parse(librevenge::RVNGTextInterface *documentInterface);
00202 
00203 protected:
00205   void init();
00206 
00208   void createDocument(librevenge::RVNGTextInterface *documentInterface);
00209 
00211   bool createZones();
00212 
00214   MWAWVec2f getPageLeftTop() const;
00215 
00217   void newPage(int number);
00218 
00219   // interface with the text parser
00220 
00222   bool sendText(long id, long subId, MWAWListenerPtr listener=MWAWListenerPtr());
00223 
00225   bool canSendTextAsGraphic(long id, long subId);
00226 
00227   // interface with the graph parser
00228 
00230   bool sendZone(long zId);
00232   bool getColor(int colId, int patternId, MWAWColor &color) const;
00233 
00234   //
00235   // low level
00236   //
00237 
00239   bool readZonesList();
00241   bool readZone(shared_ptr<HanMacWrdKZone> zone);
00243   shared_ptr<HanMacWrdKZone> decodeZone(shared_ptr<HanMacWrdKZone> zone);
00245   bool readFramesUnkn(shared_ptr<HanMacWrdKZone> zone);
00247   bool readPrintInfo(HanMacWrdKZone &zone);
00249   bool readZone6(shared_ptr<HanMacWrdKZone> zone);
00251   bool readZone8(shared_ptr<HanMacWrdKZone> zone);
00253   bool readZonea(shared_ptr<HanMacWrdKZone> zone);
00255   bool readZoneb(HanMacWrdKZone &zone);
00257   bool readZonec(shared_ptr<HanMacWrdKZone> zone);
00258 
00259 protected:
00260   //
00261   // data
00262   //
00264   shared_ptr<HanMacWrdKParserInternal::State> m_state;
00265 
00267   shared_ptr<HanMacWrdKGraph> m_graphParser;
00268 
00270   shared_ptr<HanMacWrdKText> m_textParser;
00271 };
00272 #endif
00273 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: