HMWJParser.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 HMWJ_PARSER
00038 #  define HMWJ_PARSER
00039 
00040 #include <iostream>
00041 #include <string>
00042 #include <vector>
00043 
00044 #include <libwpd/libwpd.h>
00045 
00046 #include "MWAWDebug.hxx"
00047 
00048 #include "MWAWParser.hxx"
00049 
00050 namespace HMWJParserInternal
00051 {
00052 struct State;
00053 class SubDocument;
00054 }
00055 
00056 class HMWJGraph;
00057 class HMWJText;
00058 
00060 struct HMWJZoneHeader {
00062   HMWJZoneHeader(bool isMain) : m_length(0), m_n(0), m_fieldSize(0), m_id(0), m_isMain(isMain) {
00063     for (int i=0; i < 4; i++) m_values[i] = 0;
00064   }
00065 
00067   friend std::ostream &operator<<(std::ostream &o, HMWJZoneHeader const &h) {
00068     if (h.m_n) o << "N=" << h.m_n << ",";
00069     if (h.m_id) o << "zId=" << std::hex << h.m_id << std::dec << ",";
00070     bool toPrint[4]= {true, true, true, true};
00071     if (h.m_isMain) {
00072       if (h.m_values[0]+h.m_n == h.m_values[1])
00073         toPrint[0]=toPrint[1]=false;
00074       else if (h.m_values[0]+h.m_n == h.m_values[2])
00075         toPrint[0]=toPrint[2]=false;
00076       else
00077         o << "###N,";
00078     }
00079     for (int i=0; i < 4; i++)
00080       if (toPrint[i] && h.m_values[i]) o << "h" << i << "=" << h.m_values[i] << ",";
00081     return o;
00082   }
00084   long m_length;
00086   int m_n;
00088   int m_fieldSize;
00090   long m_id;
00092   int m_values[4];
00094   bool m_isMain;
00095 };
00096 
00102 class HMWJParser : public MWAWParser
00103 {
00104   friend class HMWJGraph;
00105   friend class HMWJText;
00106   friend class HMWJParserInternal::SubDocument;
00107 
00108 public:
00110   HMWJParser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header);
00112   virtual ~HMWJParser();
00113 
00115   bool checkHeader(MWAWHeader *header, bool strict=false);
00116 
00117   // the main parse function
00118   void parse(WPXDocumentInterface *documentInterface);
00119 
00120 protected:
00122   void init();
00123 
00125   void createDocument(WPXDocumentInterface *documentInterface);
00126 
00128   bool createZones();
00129 
00131   Vec2f getPageLeftTop() const;
00132 
00134   void newPage(int number);
00135 
00136   // interface with the text parser
00137 
00139   bool sendText(long id, long cPos, bool asGraphic=false);
00141   bool canSendTextAsGraphic(long id, long cPos);
00142 
00143   // interface with the graph parser
00144 
00146   bool sendZone(long zId);
00148   bool getColor(int colId, int patternId, MWAWColor &color) const;
00149 
00150   //
00151   // low level
00152   //
00153 
00156   bool checkEntry(MWAWEntry &entry);
00157 
00159   bool readZonesList();
00161   bool readZone(MWAWEntry &entry);
00162 
00164   bool readClassicHeader(HMWJZoneHeader &header, long endPos=-1);
00166   bool decodeZone(MWAWEntry const &entry, WPXBinaryData &data);
00167 
00169   bool readPrintInfo(MWAWEntry const &entry);
00171   bool readHeaderEnd();
00172 #ifdef DEBUG
00173 
00174   bool readZoneWithHeader(MWAWEntry const &entry);
00175 #endif
00176 
00177   bool readZoneA(MWAWEntry const &entry);
00179   bool readZoneB(MWAWEntry const &entry);
00180 
00181 protected:
00182   //
00183   // data
00184   //
00186   shared_ptr<HMWJParserInternal::State> m_state;
00187 
00189   shared_ptr<HMWJGraph> m_graphParser;
00190 
00192   shared_ptr<HMWJText> m_textParser;
00193 };
00194 #endif
00195 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: