MRWParser.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 Mariner Write document
36  */
37 #ifndef MRW_PARSER
38 # define MRW_PARSER
39 
40 #include <iostream>
41 #include <string>
42 #include <vector>
43 
44 #include <libwpd/libwpd.h>
45 
46 class WPXBinaryData;
47 
48 #include "MWAWDebug.hxx"
49 #include "MWAWEntry.hxx"
50 #include "MWAWInputStream.hxx"
51 
52 #include "MWAWParser.hxx"
53 
54 namespace MRWParserInternal
55 {
56 struct State;
57 class SubDocument;
58 }
59 
60 class MRWGraph;
61 class MRWText;
62 
64 struct MRWEntry : public MWAWEntry {
66  MRWEntry() : MWAWEntry(), m_fileType(0), m_N(0), m_value(0) {
67  }
69  std::string name() const;
71  friend std::ostream &operator<< (std::ostream &o, MRWEntry const &ent) {
72  if (ent.m_N || ent.m_value || ent.m_extra.length()) {
73  o << "[";
74  if (ent.m_N) o << "N=" << ent.m_N << ",";
75  if (ent.m_value) o << "unkn=" << ent.m_value << ",";
76  if (ent.m_extra.length()) o << ent.m_extra;
77  o << "],";
78  }
79  return o;
80  }
84  int m_N;
86  int m_value;
87 };
88 
90 struct MRWStruct {
92  MRWStruct() : m_filePos(-1), m_pos(), m_type(-1), m_data() {
93  }
95  friend std::ostream &operator<<(std::ostream &o, MRWStruct const &dt);
97  int numValues() const {
98  return int(m_data.size());
99  }
101  bool isBasic() const {
102  return (m_type==1 || m_type==2) && m_data.size()<=1;
103  }
105  long value(int i) const;
107  long m_filePos;
111  int m_type;
113  std::vector<long> m_data;
114 };
115 
121 class MRWParser : public MWAWParser
122 {
123  friend class MRWGraph;
124  friend class MRWText;
126 
127 public:
129  MRWParser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header);
131  virtual ~MRWParser();
132 
134  bool checkHeader(MWAWHeader *header, bool strict=false);
135 
136  // the main parse function
137  void parse(WPXDocumentInterface *documentInterface);
138 
139 protected:
141  void init();
142 
144  void createDocument(WPXDocumentInterface *documentInterface);
145 
147  bool createZones();
149  bool readZone(int &actZone, bool onlyTest=false);
150 
152  Vec2f getPageLeftTop() const;
154  MWAWSection getSection(int zoneId) const;
155 
157  void newPage(int number);
158 
159  // interface with the text parser
160 
162  int getZoneId(uint32_t fileId, bool &endNote);
164  void sendText(int zoneId);
165 
166  // interface with the graph parser
168  float getPatternPercent(int id) const;
170  void sendToken(int zoneId, long tokenId);
171 
172  //
173  // low level
174  //
175 
177  bool readEntryHeader(MRWEntry &entry);
179  bool decodeZone(std::vector<MRWStruct> &dataList, long numData=999999);
180 
182  bool readSeparator(MRWEntry const &entry);
184  bool readZoneDim(MRWEntry const &entry, int zoneId);
186  bool readZoneHeader(MRWEntry const &entry, int zoneId, bool onlyTest);
188  bool readZoneb(MRWEntry const &entry, int zoneId);
190  bool readZonec(MRWEntry const &entry, int zoneId);
192  bool readZone13(MRWEntry const &entry, int zoneId);
194  bool readDocInfo(MRWEntry const &entry, int zoneId);
196  bool readPrintInfo(MRWEntry const &entry);
198  bool readCPRT(MRWEntry const &entry);
199 
201  bool readNumbersString(int num, std::vector<long> &res);
202 
203 protected:
204  //
205  // data
206  //
208  shared_ptr<MRWParserInternal::State> m_state;
209 
212 
214  shared_ptr<MRWGraph> m_graphParser;
215 
217  shared_ptr<MRWText> m_textParser;
218 };
219 #endif
220 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
bool createZones()
finds the different objects zones
Definition: MRWParser.cxx:444
bool readNumbersString(int num, std::vector< long > &res)
try to read a number or a list of number entries
Definition: MRWParser.cxx:1346
a function used by MWAWDocument to store the version of document and the input
Definition: MWAWHeader.hxx:47
int getZoneId(uint32_t fileId, bool &endNote)
return a zoneid corresponding to a fileId (or -1) and set the endnote flag
Definition: MRWParser.cxx:285
the main class to read a Mariner Write file
Definition: MRWParser.hxx:121
void parse(WPXDocumentInterface *documentInterface)
virtual function used to parse the input
Definition: MRWParser.cxx:322
MRWParser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header)
constructor
Definition: MRWParser.cxx:226
int numValues() const
returns the number of values
Definition: MRWParser.hxx:97
bool readZoneDim(MRWEntry const &entry, int zoneId)
try to read the zone dimension ( normal and with margin )
Definition: MRWParser.cxx:824
bool isBasic() const
returns true if this corresponds to a simple container
Definition: MRWParser.hxx:101
bool checkHeader(MWAWHeader *header, bool strict=false)
checks if the document header is correct (or not)
Definition: MRWParser.cxx:1469
std::vector< long > m_data
the data block
Definition: MRWParser.hxx:113
void createDocument(WPXDocumentInterface *documentInterface)
creates the listener which will be associated to the document
Definition: MRWParser.cxx:358
MWAWSection getSection(int zoneId) const
returns the section information corresponding to a zone
Definition: MRWParser.cxx:259
bool readZonec(MRWEntry const &entry, int zoneId)
try to read a unknown zone of 9 int
Definition: MRWParser.cxx:1094
bool readEntryHeader(MRWEntry &entry)
try to read an entry header
Definition: MRWParser.cxx:1321
bool readZoneHeader(MRWEntry const &entry, int zoneId, bool onlyTest)
try to read the zone header
Definition: MRWParser.cxx:618
the main class to read the graphic part of a Mariner Write file
Definition: MRWGraph.hxx:68
friend std::ostream & operator<<(std::ostream &o, MRWEntry const &ent)
operator&lt;&lt;
Definition: MRWParser.hxx:71
friend std::ostream & operator<<(std::ostream &o, MRWStruct const &dt)
operator&lt;&lt;
Definition: MRWParser.cxx:1562
bool readZone13(MRWEntry const &entry, int zoneId)
try to read a unknown zone of 23 int
Definition: MRWParser.cxx:1141
virtual ~MRWParser()
destructor
Definition: MRWParser.cxx:232
shared_ptr< MWAWRSRCParser > MWAWRSRCParserPtr
a smart pointer of MWAWRSRCParser
Definition: libmwaw_internal.hxx:354
void newPage(int number)
adds a new page
Definition: MRWParser.cxx:269
bool readCPRT(MRWEntry const &entry)
try to read a xml printinfo zone
Definition: MRWParser.cxx:1236
long value(int i) const
returns the ith value (or 0 if it does not exists )
Definition: MRWParser.cxx:1552
bool readDocInfo(MRWEntry const &entry, int zoneId)
try to read the doc info zone
Definition: MRWParser.cxx:904
bool m_pageMarginsSpanSet
a flag to know if page margins span are set
Definition: MRWParser.hxx:211
MRWEntry()
constructor
Definition: MRWParser.hxx:66
int m_type
the data type
Definition: MRWParser.hxx:111
std::string name() const
returns the entry name;
Definition: MRWParser.cxx:1499
std::string m_extra
an extra string
Definition: MWAWEntry.hxx:172
void sendToken(int zoneId, long tokenId)
ask the graph parser to send a token
Definition: MRWParser.cxx:311
bool readZone(int &actZone, bool onlyTest=false)
try to read a zone
Definition: MRWParser.cxx:456
a entry to store a zone structure
Definition: MRWParser.hxx:64
bool decodeZone(std::vector< MRWStruct > &dataList, long numData=999999)
try to decode a zone
Definition: MRWParser.cxx:1404
int m_N
the number of value
Definition: MRWParser.hxx:84
a class which stores section properties
Definition: MWAWSection.hxx:45
int m_fileType
the entry type
Definition: MRWParser.hxx:82
shared_ptr< MWAWInputStream > MWAWInputStreamPtr
a smart pointer of MWAWInputStream
Definition: libmwaw_internal.hxx:348
MWAWEntry m_pos
the file data position (for type=0 data )
Definition: MRWParser.hxx:109
int m_value
a unknown value
Definition: MRWParser.hxx:86
shared_ptr< MRWGraph > m_graphParser
the graph parser
Definition: MRWParser.hxx:214
Vec2f getPageLeftTop() const
returns the page left top point ( in inches)
Definition: MRWParser.cxx:253
bool readSeparator(MRWEntry const &entry)
try to read the separator of differents part
Definition: MRWParser.cxx:589
shared_ptr< MRWParserInternal::State > m_state
the state
Definition: MRWParser.hxx:208
void sendText(int zoneId)
ask the text parser to send a zone
Definition: MRWParser.cxx:298
virtual class which defines the ancestor of all main zone parser
Definition: MWAWParser.hxx:89
basic class to store an entry in a file This contained :
Definition: MWAWEntry.hxx:46
the main class to read the text part of Mariner Write file
Definition: MRWText.hxx:60
float getPatternPercent(int id) const
return the pattern percent which corresponds to an id (or -1)
Definition: MRWParser.cxx:306
MRWStruct()
constructor
Definition: MRWParser.hxx:92
void init()
inits all internal variables
Definition: MRWParser.cxx:236
shared_ptr< MRWText > m_textParser
the text parser
Definition: MRWParser.hxx:217
Internal: a struct used to read some field.
Definition: MRWParser.hxx:90
bool readZoneb(MRWEntry const &entry, int zoneId)
try to read a unknown zone : one by separator?, borderdim?
Definition: MRWParser.cxx:1054
Internal: the subdocument of a MWParser.
Definition: MRWParser.cxx:179
long m_filePos
the file position where the field description begin
Definition: MRWParser.hxx:107
bool readPrintInfo(MRWEntry const &entry)
try to read a printinfo zone
Definition: MRWParser.cxx:1262

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