HMWJParser.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
2 
3 /* libmwaw
4 * Version: MPL 2.0 / LGPLv2+
5 *
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 2.0 (the "License"); you may not use this file except in compliance with
8 * the License or as specified alternatively below. You may obtain a copy of
9 * the License at http://www.mozilla.org/MPL/
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * Major Contributor(s):
17 * Copyright (C) 2002 William Lachance (wrlach@gmail.com)
18 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
19 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
20 * Copyright (C) 2006, 2007 Andrew Ziem
21 * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
22 *
23 *
24 * All Rights Reserved.
25 *
26 * For minor contributions see the git repository.
27 *
28 * Alternatively, the contents of this file may be used under the terms of
29 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
30 * in which case the provisions of the LGPLv2+ are applicable
31 * instead of those above.
32 */
33 
34 /*
35  * Parser to convert HanMac Word-J document
36  */
37 #ifndef HMWJ_PARSER
38 # define HMWJ_PARSER
39 
40 #include <iostream>
41 #include <string>
42 #include <vector>
43 
44 #include <libwpd/libwpd.h>
45 
46 #include "MWAWDebug.hxx"
47 
48 #include "MWAWParser.hxx"
49 
50 namespace HMWJParserInternal
51 {
52 struct State;
53 class SubDocument;
54 }
55 
56 class HMWJGraph;
57 class HMWJText;
58 
62  HMWJZoneHeader(bool isMain) : m_length(0), m_n(0), m_fieldSize(0), m_id(0), m_isMain(isMain) {
63  for (int i=0; i < 4; i++) m_values[i] = 0;
64  }
65 
67  friend std::ostream &operator<<(std::ostream &o, HMWJZoneHeader const &h) {
68  if (h.m_n) o << "N=" << h.m_n << ",";
69  if (h.m_id) o << "zId=" << std::hex << h.m_id << std::dec << ",";
70  bool toPrint[4]= {true, true, true, true};
71  if (h.m_isMain) {
72  if (h.m_values[0]+h.m_n == h.m_values[1])
73  toPrint[0]=toPrint[1]=false;
74  else if (h.m_values[0]+h.m_n == h.m_values[2])
75  toPrint[0]=toPrint[2]=false;
76  else
77  o << "###N,";
78  }
79  for (int i=0; i < 4; i++)
80  if (toPrint[i] && h.m_values[i]) o << "h" << i << "=" << h.m_values[i] << ",";
81  return o;
82  }
84  long m_length;
86  int m_n;
90  long m_id;
92  int m_values[4];
94  bool m_isMain;
95 };
96 
102 class HMWJParser : public MWAWParser
103 {
104  friend class HMWJGraph;
105  friend class HMWJText;
107 
108 public:
110  HMWJParser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header);
112  virtual ~HMWJParser();
113 
115  bool checkHeader(MWAWHeader *header, bool strict=false);
116 
117  // the main parse function
118  void parse(WPXDocumentInterface *documentInterface);
119 
120 protected:
122  void init();
123 
125  void createDocument(WPXDocumentInterface *documentInterface);
126 
128  bool createZones();
129 
131  Vec2f getPageLeftTop() const;
132 
134  void newPage(int number);
135 
136  // interface with the text parser
137 
139  bool sendText(long id, long cPos, bool asGraphic=false);
141  bool canSendTextAsGraphic(long id, long cPos);
142 
143  // interface with the graph parser
144 
146  bool sendZone(long zId);
148  bool getColor(int colId, int patternId, MWAWColor &color) const;
149 
150  //
151  // low level
152  //
153 
156  bool checkEntry(MWAWEntry &entry);
157 
159  bool readZonesList();
161  bool readZone(MWAWEntry &entry);
162 
164  bool readClassicHeader(HMWJZoneHeader &header, long endPos=-1);
166  bool decodeZone(MWAWEntry const &entry, WPXBinaryData &data);
167 
169  bool readPrintInfo(MWAWEntry const &entry);
171  bool readHeaderEnd();
172 #ifdef DEBUG
173 
174  bool readZoneWithHeader(MWAWEntry const &entry);
175 #endif
176 
177  bool readZoneA(MWAWEntry const &entry);
179  bool readZoneB(MWAWEntry const &entry);
180 
181 protected:
182  //
183  // data
184  //
186  shared_ptr<HMWJParserInternal::State> m_state;
187 
189  shared_ptr<HMWJGraph> m_graphParser;
190 
192  shared_ptr<HMWJText> m_textParser;
193 };
194 #endif
195 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:

Generated on Sat Apr 26 2014 04:35:17 for libmwaw by doxygen 1.8.3.1