HanMacWrdJParser.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-J document
00036  */
00037 #ifndef HAN_MAC_WRD_J_PARSER
00038 #  define HAN_MAC_WRD_J_PARSER
00039 
00040 #include <iostream>
00041 #include <string>
00042 #include <vector>
00043 
00044 #include <librevenge/librevenge.h>
00045 
00046 #include "MWAWDebug.hxx"
00047 
00048 #include "MWAWParser.hxx"
00049 
00050 namespace HanMacWrdJParserInternal
00051 {
00052 struct State;
00053 class SubDocument;
00054 }
00055 
00056 class HanMacWrdJGraph;
00057 class HanMacWrdJText;
00058 
00060 struct HanMacWrdJZoneHeader {
00062   HanMacWrdJZoneHeader(bool isMain) : m_length(0), m_n(0), m_fieldSize(0), m_id(0), m_isMain(isMain)
00063   {
00064     for (int i=0; i < 4; i++) m_values[i] = 0;
00065   }
00066 
00068   friend std::ostream &operator<<(std::ostream &o, HanMacWrdJZoneHeader const &h)
00069   {
00070     if (h.m_n) o << "N=" << h.m_n << ",";
00071     if (h.m_id) o << "zId=" << std::hex << h.m_id << std::dec << ",";
00072     bool toPrint[4]= {true, true, true, true};
00073     if (h.m_isMain) {
00074       if (h.m_values[0]+h.m_n == h.m_values[1])
00075         toPrint[0]=toPrint[1]=false;
00076       else if (h.m_values[0]+h.m_n == h.m_values[2])
00077         toPrint[0]=toPrint[2]=false;
00078       else
00079         o << "###N,";
00080     }
00081     for (int i=0; i < 4; i++)
00082       if (toPrint[i] && h.m_values[i]) o << "h" << i << "=" << h.m_values[i] << ",";
00083     return o;
00084   }
00086   long m_length;
00088   int m_n;
00090   int m_fieldSize;
00092   long m_id;
00094   int m_values[4];
00096   bool m_isMain;
00097 };
00098 
00104 class HanMacWrdJParser : public MWAWTextParser
00105 {
00106   friend class HanMacWrdJGraph;
00107   friend class HanMacWrdJText;
00108   friend class HanMacWrdJParserInternal::SubDocument;
00109 
00110 public:
00112   HanMacWrdJParser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header);
00114   virtual ~HanMacWrdJParser();
00115 
00117   bool checkHeader(MWAWHeader *header, bool strict=false);
00118 
00119   // the main parse function
00120   void parse(librevenge::RVNGTextInterface *documentInterface);
00121 
00122 protected:
00124   void init();
00125 
00127   void createDocument(librevenge::RVNGTextInterface *documentInterface);
00128 
00130   bool createZones();
00131 
00133   MWAWVec2f getPageLeftTop() const;
00134 
00136   void newPage(int number);
00137 
00138   // interface with the text parser
00139 
00141   bool sendText(long id, long cPos, MWAWListenerPtr listener=MWAWListenerPtr());
00143   bool canSendTextAsGraphic(long id, long cPos);
00144 
00145   // interface with the graph parser
00146 
00148   bool sendZone(long zId);
00150   bool getColor(int colId, int patternId, MWAWColor &color) const;
00151 
00152   //
00153   // low level
00154   //
00155 
00158   bool checkEntry(MWAWEntry &entry);
00159 
00161   bool readZonesList();
00163   bool readZone(MWAWEntry &entry);
00164 
00166   bool readClassicHeader(HanMacWrdJZoneHeader &header, long endPos=-1);
00168   bool decodeZone(MWAWEntry const &entry, librevenge::RVNGBinaryData &data);
00169 
00171   bool readPrintInfo(MWAWEntry const &entry);
00173   bool readHeaderEnd();
00174 #ifdef DEBUG
00175 
00176   bool readZoneWithHeader(MWAWEntry const &entry);
00177 #endif
00178 
00179   bool readZoneA(MWAWEntry const &entry);
00181   bool readZoneB(MWAWEntry const &entry);
00182 
00183 protected:
00184   //
00185   // data
00186   //
00188   shared_ptr<HanMacWrdJParserInternal::State> m_state;
00189 
00191   shared_ptr<HanMacWrdJGraph> m_graphParser;
00192 
00194   shared_ptr<HanMacWrdJText> m_textParser;
00195 };
00196 #endif
00197 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: