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:
shared_ptr< HMWJText > m_textParser
the text parser
Definition: HMWJParser.hxx:198
virtual ~HMWJParser()
destructor
Definition: HMWJParser.cxx:160
a class use to store the classic header find before file zone
Definition: HMWJParser.hxx:65
a function used by MWAWDocument to store the version of document and the input
Definition: MWAWHeader.hxx:49
int m_values[4]
4 unknown field : freeN?, totalN?, totalN1?, ?
Definition: HMWJParser.hxx:97
shared_ptr< MWAWInputStream > MWAWInputStreamPtr
Definition: ACText.hxx:44
bool createZones()
finds the different objects zones in a Hapanese File
Definition: HMWJParser.cxx:336
bool sendZone(long zId)
send a zone
Definition: HMWJParser.cxx:183
friend std::ostream & operator<<(std::ostream &o, HMWJZoneHeader const &h)
operator&lt;&lt;
Definition: HMWJParser.hxx:72
bool checkHeader(MWAWHeader *header, bool strict=false)
checks if the document header is correct (or not)
Definition: HMWJParser.cxx:1034
void init()
inits all internal variables
Definition: HMWJParser.cxx:164
long m_id
the zone id
Definition: HMWJParser.hxx:95
bool decodeZone(MWAWEntry const &entry, WPXBinaryData &data)
try to decode a zone
Definition: HMWJParser.cxx:1167
HMWJParser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header)
constructor
Definition: HMWJParser.cxx:154
void newPage(int number)
adds a new page
Definition: HMWJParser.cxx:207
int m_fieldSize
the field size
Definition: HMWJParser.hxx:93
bool readZone(MWAWEntry &entry)
try to read a generic zone
Definition: HMWJParser.cxx:507
the class to store a color
Definition: libmwaw_internal.hxx:161
bool readHeaderEnd()
try to read a unknown zone, just after the header (simillar to HMW Zoneb)
Definition: HMWJParser.cxx:883
shared_ptr< HMWJParserInternal::State > m_state
the state
Definition: HMWJParser.hxx:192
Class to store font.
Definition: MWAWFont.hxx:47
bool isFilePos(long pos)
check if an entry is in file
Definition: HMWJParser.cxx:220
bool m_isMain
true if this is the main header
Definition: HMWJParser.hxx:99
Internal: the subdocument of a MWParser.
Definition: HMWJParser.cxx:93
Vec2f getPageLeftTop() const
returns the page left top point ( in inches)
Definition: HMWJParser.cxx:198
bool sendText(long id, long cPos)
send a text zone
Definition: HMWJParser.cxx:178
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:419
long m_length
the zone size
Definition: HMWJParser.hxx:89
shared_ptr< HMWJGraph > m_graphParser
the graph parser
Definition: HMWJParser.hxx:195
bool readZoneA(MWAWEntry const &entry)
try to read the zone A ( a big zone containing 5 sub zone ? )
Definition: HMWJParser.cxx:702
HMWJZoneHeader(bool isMain)
constructor
Definition: HMWJParser.hxx:67
bool getColor(int colId, int patternId, MWAWColor &color) const
returns the color associated with a pattern
Definition: HMWJParser.cxx:190
the main class to read a HanMac Word-J file
Definition: HMWJParser.hxx:107
class to store the paragraph properties
Definition: MWAWParagraph.hxx:83
bool readClassicHeader(HMWJZoneHeader &header, long endPos=-1)
try to read a header of classic zone
Definition: HMWJParser.cxx:234
virtual class which defines the ancestor of all main zone parser
Definition: MWAWParser.hxx:98
int m_n
the number of item
Definition: HMWJParser.hxx:91
void createDocument(WPXDocumentInterface *documentInterface)
creates the listener which will be associated to the document
Definition: HMWJParser.cxx:293
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:258
the main class to read the graphic part of a HanMac Word-J file
Definition: HMWJGraph.hxx:83
the main class to read the text part of HanMac Word-J file
Definition: HMWJText.hxx:68
bool readZonesList()
try to read the zones list
Definition: HMWJParser.cxx:460
bool readZoneB(MWAWEntry const &entry)
try to read the zone B
Definition: HMWJParser.cxx:803
shared_ptr< MWAWRSRCParser > MWAWRSRCParserPtr
Definition: MWAWParser.hxx:56
bool readPrintInfo(MWAWEntry const &entry)
try to read a printinfo zone
Definition: HMWJParser.cxx:600

Generated for libmwaw by doxygen 1.8.5