HMWKParser.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 HMWK_PARSER
00038 #  define HMWK_PARSER
00039 
00040 #include <iostream>
00041 #include <string>
00042 #include <vector>
00043 
00044 #include <libwpd/libwpd.h>
00045 
00046 #include "MWAWDebug.hxx"
00047 #include "MWAWInputStream.hxx"
00048 
00049 #include "MWAWParser.hxx"
00050 
00051 namespace HMWKParserInternal
00052 {
00053 struct State;
00054 class SubDocument;
00055 }
00056 
00058 struct HMWKZone {
00060   HMWKZone(MWAWInputStreamPtr input, libmwaw::DebugFile &asciiFile);
00062   HMWKZone(shared_ptr<libmwaw::DebugFile> asciiFile);
00064   ~HMWKZone();
00065 
00067   long begin() const {
00068     return m_asciiFilePtr ? 0 : m_filePos;
00069   }
00071   long end() const {
00072     return m_asciiFilePtr ? (long) m_data.size() : m_endFilePos;
00073   }
00075   long length() const {
00076     if (m_asciiFilePtr) return (long) m_data.size();
00077     return m_endFilePos-m_filePos;
00078   }
00080   bool valid() const {
00081     return length() > 0;
00082   }
00083 
00084   // function to define the zone in the original file
00085 
00087   long fileBeginPos() const {
00088     return m_filePos;
00089   }
00091   long fileEndPos() const {
00092     return m_endFilePos;
00093   }
00095   void setFileBeginPos(long begPos) {
00096     m_filePos = m_endFilePos = begPos;
00097   }
00099   void setFileLength(long len) {
00100     m_endFilePos = m_filePos+len;
00101   }
00103   void setFilePositions(long begPos, long endPos) {
00104     m_filePos = begPos;
00105     m_endFilePos = endPos;
00106   }
00108   WPXBinaryData &getBinaryData() {
00109     return m_data;
00110   }
00112   std::string name() const {
00113     return name(m_type);
00114   }
00116   static std::string name(int type);
00117 
00119   friend std::ostream &operator<<(std::ostream &o, HMWKZone const &zone);
00120 
00122   libmwaw::DebugFile &ascii() {
00123     return *m_asciiFile;
00124   }
00125 
00127   int m_type;
00128 
00130   long m_id;
00131 
00133   long m_subId;
00134 
00136   MWAWInputStreamPtr m_input;
00137 
00139   std::string m_extra;
00140 
00142   mutable bool m_parsed;
00143 
00144 protected:
00146   long m_filePos;
00147 
00149   long m_endFilePos;
00150 
00152   WPXBinaryData m_data;
00153 
00155   libmwaw::DebugFile *m_asciiFile;
00156 
00158   shared_ptr<libmwaw::DebugFile> m_asciiFilePtr;
00159 
00160 private:
00161   HMWKZone(HMWKZone const &orig);
00162   HMWKZone &operator=(HMWKZone const &orig);
00163 };
00164 
00165 class HMWKGraph;
00166 class HMWKText;
00167 
00173 class HMWKParser : public MWAWParser
00174 {
00175   friend class HMWKGraph;
00176   friend class HMWKText;
00177   friend class HMWKParserInternal::SubDocument;
00178 
00179 public:
00181   HMWKParser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header);
00183   virtual ~HMWKParser();
00184 
00186   bool checkHeader(MWAWHeader *header, bool strict=false);
00187 
00188   // the main parse function
00189   void parse(WPXDocumentInterface *documentInterface);
00190 
00191 protected:
00193   void init();
00194 
00196   void createDocument(WPXDocumentInterface *documentInterface);
00197 
00199   bool createZones();
00200 
00202   Vec2f getPageLeftTop() const;
00203 
00205   void newPage(int number);
00206 
00207   // interface with the text parser
00208 
00210   bool sendText(long id, long subId, bool asGraphic=false);
00211 
00213   bool canSendTextAsGraphic(long id, long subId);
00214 
00215   // interface with the graph parser
00216 
00218   bool sendZone(long zId);
00220   bool getColor(int colId, int patternId, MWAWColor &color) const;
00221 
00222   //
00223   // low level
00224   //
00225 
00227   bool readZonesList();
00229   bool readZone(shared_ptr<HMWKZone> zone);
00231   shared_ptr<HMWKZone> decodeZone(shared_ptr<HMWKZone> zone);
00233   bool readFramesUnkn(shared_ptr<HMWKZone> zone);
00235   bool readPrintInfo(HMWKZone &zone);
00237   bool readZone6(shared_ptr<HMWKZone> zone);
00239   bool readZone8(shared_ptr<HMWKZone> zone);
00241   bool readZonea(shared_ptr<HMWKZone> zone);
00243   bool readZoneb(HMWKZone &zone);
00245   bool readZonec(shared_ptr<HMWKZone> zone);
00246 
00247 protected:
00248   //
00249   // data
00250   //
00252   shared_ptr<HMWKParserInternal::State> m_state;
00253 
00255   shared_ptr<HMWKGraph> m_graphParser;
00256 
00258   shared_ptr<HMWKText> m_textParser;
00259 };
00260 #endif
00261 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: