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 #include "MWAWPageSpan.hxx"
49 
50 #include "MWAWParser.hxx"
51 
52 class MWAWEntry;
53 class MWAWFont;
54 class MWAWParagraph;
55 
56 namespace HMWJParserInternal
57 {
58 struct State;
59 class SubDocument;
60 }
61 
62 class HMWJGraph;
63 class HMWJText;
64 
68  HMWJZoneHeader(bool isMain) : m_length(0), m_n(0), m_fieldSize(0), m_id(0), m_isMain(isMain) {
69  for (int i=0; i < 4; i++) m_values[i] = 0;
70  }
71 
73  friend std::ostream &operator<<(std::ostream &o, HMWJZoneHeader const &h) {
74  if (h.m_n) o << "N=" << h.m_n << ",";
75  if (h.m_id) o << "zId=" << std::hex << h.m_id << std::dec << ",";
76  bool toPrint[4]= {true, true, true, true};
77  if (h.m_isMain) {
78  if (h.m_values[0]+h.m_n == h.m_values[1])
79  toPrint[0]=toPrint[1]=false;
80  else if (h.m_values[0]+h.m_n == h.m_values[2])
81  toPrint[0]=toPrint[2]=false;
82  else
83  o << "###N,";
84  }
85  for (int i=0; i < 4; i++)
86  if (toPrint[i] && h.m_values[i]) o << "h" << i << "=" << h.m_values[i] << ",";
87  return o;
88  }
90  long m_length;
92  int m_n;
96  long m_id;
98  int m_values[4];
100  bool m_isMain;
101 };
102 
108 class HMWJParser : public MWAWParser
109 {
110  friend class HMWJGraph;
111  friend class HMWJText;
113 
114 public:
116  HMWJParser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header);
118  virtual ~HMWJParser();
119 
121  bool checkHeader(MWAWHeader *header, bool strict=false);
122 
123  // the main parse function
124  void parse(WPXDocumentInterface *documentInterface);
125 
126 protected:
128  void init();
129 
131  void createDocument(WPXDocumentInterface *documentInterface);
132 
134  bool createZones();
135 
137  float pageHeight() const;
139  float pageWidth() const;
141  Vec2f getPageLeftTop() const;
142 
144  void newPage(int number);
145 
146  // interface with the text parser
147 
149  bool sendText(long id, long cPos);
150 
151  // interface with the graph parser
152 
154  bool sendZone(long zId);
156  bool getColor(int colId, int patternId, MWAWColor &color) const;
157 
158  //
159  // low level
160  //
161 
164  bool checkEntry(MWAWEntry &entry);
165 
167  bool readZonesList();
169  bool readZone(MWAWEntry &entry);
170 
172  bool readClassicHeader(HMWJZoneHeader &header, long endPos=-1);
174  bool decodeZone(MWAWEntry const &entry, WPXBinaryData &data);
175 
177  bool readPrintInfo(MWAWEntry const &entry);
179  bool readHeaderEnd();
180 
182  bool readZoneWithHeader(MWAWEntry const &entry);
184  bool readZoneA(MWAWEntry const &entry);
186  bool readZoneB(MWAWEntry const &entry);
187 
189  bool isFilePos(long pos);
190 
191 protected:
192  //
193  // data
194  //
196  shared_ptr<HMWJParserInternal::State> m_state;
197 
200 
202  shared_ptr<HMWJGraph> m_graphParser;
203 
205  shared_ptr<HMWJText> m_textParser;
206 };
207 #endif
208 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:

Generated on Sat May 4 2013 20:11:06 for libmwaw by doxygen 1.8.3.1