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:
shared_ptr< HMWJText > m_textParser
the text parser
Definition: HMWJParser.hxx:192
virtual ~HMWJParser()
destructor
Definition: HMWJParser.cxx:158
a class use to store the classic header find before file zone
Definition: HMWJParser.hxx:60
a function used by MWAWDocument to store the version of document and the input
Definition: MWAWHeader.hxx:47
int m_values[4]
4 unknown field : freeN?, totalN?, totalN1?, ?
Definition: HMWJParser.hxx:92
bool createZones()
finds the different objects zones in a Hapanese File
Definition: HMWJParser.cxx:326
bool sendZone(long zId)
send a zone
Definition: HMWJParser.cxx:186
friend std::ostream & operator<<(std::ostream &o, HMWJZoneHeader const &h)
operator&lt;&lt;
Definition: HMWJParser.hxx:67
bool canSendTextAsGraphic(long id, long cPos)
check if we can send a textzone as graphic
Definition: HMWJParser.cxx:181
bool checkHeader(MWAWHeader *header, bool strict=false)
checks if the document header is correct (or not)
Definition: HMWJParser.cxx:1024
void init()
inits all internal variables
Definition: HMWJParser.cxx:162
long m_id
the zone id
Definition: HMWJParser.hxx:90
bool decodeZone(MWAWEntry const &entry, WPXBinaryData &data)
try to decode a zone
Definition: HMWJParser.cxx:1157
HMWJParser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header)
constructor
Definition: HMWJParser.cxx:152
void newPage(int number)
adds a new page
Definition: HMWJParser.cxx:210
int m_fieldSize
the field size
Definition: HMWJParser.hxx:88
bool readZone(MWAWEntry &entry)
try to read a generic zone
Definition: HMWJParser.cxx:498
the class to store a color
Definition: libmwaw_internal.hxx:166
bool readHeaderEnd()
try to read a unknown zone, just after the header (simillar to HMW Zoneb)
Definition: HMWJParser.cxx:873
shared_ptr< HMWJParserInternal::State > m_state
the state
Definition: HMWJParser.hxx:186
bool sendText(long id, long cPos, bool asGraphic=false)
send a text zone
Definition: HMWJParser.cxx:176
shared_ptr< MWAWRSRCParser > MWAWRSRCParserPtr
a smart pointer of MWAWRSRCParser
Definition: libmwaw_internal.hxx:354
bool m_isMain
true if this is the main header
Definition: HMWJParser.hxx:94
Internal: the subdocument of a MWParser.
Definition: HMWJParser.cxx:91
Vec2f getPageLeftTop() const
returns the page left top point ( in inches)
Definition: HMWJParser.cxx:201
bool checkEntry(MWAWEntry &entry)
look in entry.begin() to see if a entry exists at this position, if so fills entry.end(), entry.id(), ...
Definition: HMWJParser.cxx:411
long m_length
the zone size
Definition: HMWJParser.hxx:84
shared_ptr< HMWJGraph > m_graphParser
the graph parser
Definition: HMWJParser.hxx:189
bool readZoneA(MWAWEntry const &entry)
try to read the zone A ( a big zone containing 5 sub zone ? )
Definition: HMWJParser.cxx:693
shared_ptr< MWAWInputStream > MWAWInputStreamPtr
a smart pointer of MWAWInputStream
Definition: libmwaw_internal.hxx:348
HMWJZoneHeader(bool isMain)
constructor
Definition: HMWJParser.hxx:62
bool getColor(int colId, int patternId, MWAWColor &color) const
returns the color associated with a pattern
Definition: HMWJParser.cxx:193
the main class to read a HanMac Word-J file
Definition: HMWJParser.hxx:102
bool readClassicHeader(HMWJZoneHeader &header, long endPos=-1)
try to read a header of classic zone
Definition: HMWJParser.cxx:223
virtual class which defines the ancestor of all main zone parser
Definition: MWAWParser.hxx:89
int m_n
the number of item
Definition: HMWJParser.hxx:86
void createDocument(WPXDocumentInterface *documentInterface)
creates the listener which will be associated to the document
Definition: HMWJParser.cxx:283
basic class to store an entry in a file This contained :
Definition: MWAWEntry.hxx:46
void parse(WPXDocumentInterface *documentInterface)
virtual function used to parse the input
Definition: HMWJParser.cxx:247
the main class to read the graphic part of a HanMac Word-J file
Definition: HMWJGraph.hxx:78
the main class to read the text part of HanMac Word-J file
Definition: HMWJText.hxx:62
bool readZonesList()
try to read the zones list
Definition: HMWJParser.cxx:452
bool readZoneB(MWAWEntry const &entry)
try to read the zone B
Definition: HMWJParser.cxx:793
bool readPrintInfo(MWAWEntry const &entry)
try to read a printinfo zone
Definition: HMWJParser.cxx:591

Generated on Tue Mar 10 2015 17:32:08 for libmwaw by doxygen 1.8.5