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 #include "MWAWInputStream.hxx"
48 
49 #include "MWAWParser.hxx"
50 
51 class MWAWEntry;
52 class MWAWFont;
53 class MWAWParagraph;
54 
55 namespace HMWJParserInternal
56 {
57 struct State;
58 class SubDocument;
59 }
60 
61 class HMWJGraph;
62 class HMWJText;
63 
67  HMWJZoneHeader(bool isMain) : m_length(0), m_n(0), m_fieldSize(0), m_id(0), m_isMain(isMain) {
68  for (int i=0; i < 4; i++) m_values[i] = 0;
69  }
70 
72  friend std::ostream &operator<<(std::ostream &o, HMWJZoneHeader const &h) {
73  if (h.m_n) o << "N=" << h.m_n << ",";
74  if (h.m_id) o << "zId=" << std::hex << h.m_id << std::dec << ",";
75  bool toPrint[4]= {true, true, true, true};
76  if (h.m_isMain) {
77  if (h.m_values[0]+h.m_n == h.m_values[1])
78  toPrint[0]=toPrint[1]=false;
79  else if (h.m_values[0]+h.m_n == h.m_values[2])
80  toPrint[0]=toPrint[2]=false;
81  else
82  o << "###N,";
83  }
84  for (int i=0; i < 4; i++)
85  if (toPrint[i] && h.m_values[i]) o << "h" << i << "=" << h.m_values[i] << ",";
86  return o;
87  }
89  long m_length;
91  int m_n;
95  long m_id;
97  int m_values[4];
99  bool m_isMain;
100 };
101 
107 class HMWJParser : public MWAWParser
108 {
109  friend class HMWJGraph;
110  friend class HMWJText;
112 
113 public:
115  HMWJParser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header);
117  virtual ~HMWJParser();
118 
120  bool checkHeader(MWAWHeader *header, bool strict=false);
121 
122  // the main parse function
123  void parse(WPXDocumentInterface *documentInterface);
124 
125 protected:
127  void init();
128 
130  void createDocument(WPXDocumentInterface *documentInterface);
131 
133  bool createZones();
134 
136  Vec2f getPageLeftTop() const;
137 
139  void newPage(int number);
140 
141  // interface with the text parser
142 
144  bool sendText(long id, long cPos);
145 
146  // interface with the graph parser
147 
149  bool sendZone(long zId);
151  bool getColor(int colId, int patternId, MWAWColor &color) const;
152 
153  //
154  // low level
155  //
156 
159  bool checkEntry(MWAWEntry &entry);
160 
162  bool readZonesList();
164  bool readZone(MWAWEntry &entry);
165 
167  bool readClassicHeader(HMWJZoneHeader &header, long endPos=-1);
169  bool decodeZone(MWAWEntry const &entry, WPXBinaryData &data);
170 
172  bool readPrintInfo(MWAWEntry const &entry);
174  bool readHeaderEnd();
175 #ifdef DEBUG
176 
177  bool readZoneWithHeader(MWAWEntry const &entry);
178 #endif
179 
180  bool readZoneA(MWAWEntry const &entry);
182  bool readZoneB(MWAWEntry const &entry);
183 
185  bool isFilePos(long pos);
186 
187 protected:
188  //
189  // data
190  //
192  shared_ptr<HMWJParserInternal::State> m_state;
193 
195  shared_ptr<HMWJGraph> m_graphParser;
196 
198  shared_ptr<HMWJText> m_textParser;
199 };
200 #endif
201 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:

Generated on Wed May 22 2013 18:12:37 for libmwaw by doxygen 1.8.1.2