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 class MWAWEntry;
55 class MWAWFont;
56 class MWAWParagraph;
57 class MWAWSection;
58 
59 namespace MRWParserInternal
60 {
61 struct State;
62 class SubDocument;
63 }
64 
65 class MRWGraph;
66 class MRWText;
67 
69 struct MRWEntry : public MWAWEntry {
71  MRWEntry() : MWAWEntry(), m_fileType(0), m_N(0), m_value(0) {
72  }
74  std::string name() const;
76  friend std::ostream &operator<< (std::ostream &o, MRWEntry const &ent) {
77  if (ent.m_N || ent.m_value || ent.m_extra.length()) {
78  o << "[";
79  if (ent.m_N) o << "N=" << ent.m_N << ",";
80  if (ent.m_value) o << "unkn=" << ent.m_value << ",";
81  if (ent.m_extra.length()) o << ent.m_extra;
82  o << "],";
83  }
84  return o;
85  }
89  int m_N;
91  int m_value;
92 };
93 
95 struct MRWStruct {
97  MRWStruct() : m_filePos(-1), m_pos(), m_type(-1), m_data() {
98  }
100  friend std::ostream &operator<<(std::ostream &o, MRWStruct const &dt);
102  int numValues() const {
103  return int(m_data.size());
104  }
106  bool isBasic() const {
107  return (m_type==1 || m_type==2) && m_data.size()<=1;
108  }
110  long value(int i) const;
112  long m_filePos;
116  int m_type;
118  std::vector<long> m_data;
119 };
120 
126 class MRWParser : public MWAWParser
127 {
128  friend class MRWGraph;
129  friend class MRWText;
131 
132 public:
134  MRWParser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header);
136  virtual ~MRWParser();
137 
139  bool checkHeader(MWAWHeader *header, bool strict=false);
140 
141  // the main parse function
142  void parse(WPXDocumentInterface *documentInterface);
143 
144 protected:
146  void init();
147 
149  void createDocument(WPXDocumentInterface *documentInterface);
150 
152  bool createZones();
154  bool readZone(int &actZone, bool onlyTest=false);
155 
157  Vec2f getPageLeftTop() const;
159  MWAWSection getSection(int zoneId) const;
160 
162  void newPage(int number);
163 
164  // interface with the text parser
165 
167  int getZoneId(uint32_t fileId, bool &endNote);
169  void sendText(int zoneId);
170 
171  // interface with the graph parser
173  float getPatternPercent(int id) const;
175  void sendToken(int zoneId, long tokenId, MWAWFont const &actFont);
176 
177  //
178  // low level
179  //
180 
182  bool isFilePos(long pos);
184  bool readEntryHeader(MRWEntry &entry);
186  bool decodeZone(std::vector<MRWStruct> &dataList, long numData=999999);
187 
189  bool readSeparator(MRWEntry const &entry);
191  bool readZoneDim(MRWEntry const &entry, int zoneId);
193  bool readZoneHeader(MRWEntry const &entry, int zoneId, bool onlyTest);
195  bool readZoneb(MRWEntry const &entry, int zoneId);
197  bool readZonec(MRWEntry const &entry, int zoneId);
199  bool readZone13(MRWEntry const &entry, int zoneId);
201  bool readDocInfo(MRWEntry const &entry, int zoneId);
203  bool readPrintInfo(MRWEntry const &entry);
205  bool readCPRT(MRWEntry const &entry);
206 
208  bool readNumbersString(int num, std::vector<long> &res);
209 
210 protected:
211  //
212  // data
213  //
215  shared_ptr<MRWParserInternal::State> m_state;
216 
219 
221  shared_ptr<MRWGraph> m_graphParser;
222 
224  shared_ptr<MRWText> m_textParser;
225 };
226 #endif
227 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
bool createZones()
finds the different objects zones
Definition: MRWParser.cxx:460
bool readNumbersString(int num, std::vector< long > &res)
try to read a number or a list of number entries
Definition: MRWParser.cxx:1359
a function used by MWAWDocument to store the version of document and the input
Definition: MWAWHeader.hxx:49
int getZoneId(uint32_t fileId, bool &endNote)
return a zoneid corresponding to a fileId (or -1) and set the endnote flag
Definition: MRWParser.cxx:301
the main class to read a Mariner Write file
Definition: MRWParser.hxx:126
void parse(WPXDocumentInterface *documentInterface)
virtual function used to parse the input
Definition: MRWParser.cxx:338
MRWParser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header)
constructor
Definition: MRWParser.cxx:228
shared_ptr< MWAWInputStream > MWAWInputStreamPtr
Definition: ACText.hxx:44
int numValues() const
returns the number of values
Definition: MRWParser.hxx:102
bool readZoneDim(MRWEntry const &entry, int zoneId)
try to read the zone dimension ( normal and with margin )
Definition: MRWParser.cxx:837
bool isBasic() const
returns true if this corresponds to a simple container
Definition: MRWParser.hxx:106
bool checkHeader(MWAWHeader *header, bool strict=false)
checks if the document header is correct (or not)
Definition: MRWParser.cxx:1482
std::vector< long > m_data
the data block
Definition: MRWParser.hxx:118
void createDocument(WPXDocumentInterface *documentInterface)
creates the listener which will be associated to the document
Definition: MRWParser.cxx:374
MWAWSection getSection(int zoneId) const
returns the section information corresponding to a zone
Definition: MRWParser.cxx:261
bool readZonec(MRWEntry const &entry, int zoneId)
try to read a unknown zone of 9 int
Definition: MRWParser.cxx:1107
bool readEntryHeader(MRWEntry &entry)
try to read an entry header
Definition: MRWParser.cxx:1334
bool readZoneHeader(MRWEntry const &entry, int zoneId, bool onlyTest)
try to read the zone header
Definition: MRWParser.cxx:634
the main class to read the graphic part of a Mariner Write file
Definition: MRWGraph.hxx:73
friend std::ostream & operator<<(std::ostream &o, MRWEntry const &ent)
operator&lt;&lt;
Definition: MRWParser.hxx:76
friend std::ostream & operator<<(std::ostream &o, MRWStruct const &dt)
operator&lt;&lt;
Definition: MRWParser.cxx:1575
bool readZone13(MRWEntry const &entry, int zoneId)
try to read a unknown zone of 23 int
Definition: MRWParser.cxx:1154
virtual ~MRWParser()
destructor
Definition: MRWParser.cxx:234
Class to store font.
Definition: MWAWFont.hxx:47
void newPage(int number)
adds a new page
Definition: MRWParser.cxx:271
bool readCPRT(MRWEntry const &entry)
try to read a xml printinfo zone
Definition: MRWParser.cxx:1249
long value(int i) const
returns the ith value (or 0 if it does not exists )
Definition: MRWParser.cxx:1565
bool readDocInfo(MRWEntry const &entry, int zoneId)
try to read the doc info zone
Definition: MRWParser.cxx:917
bool m_pageMarginsSpanSet
a flag to know if page margins span are set
Definition: MRWParser.hxx:218
MRWEntry()
constructor
Definition: MRWParser.hxx:71
int m_type
the data type
Definition: MRWParser.hxx:116
std::string name() const
returns the entry name;
Definition: MRWParser.cxx:1512
std::string m_extra
an extra string
Definition: MWAWEntry.hxx:172
bool readZone(int &actZone, bool onlyTest=false)
try to read a zone
Definition: MRWParser.cxx:472
a entry to store a zone structure
Definition: MRWParser.hxx:69
bool decodeZone(std::vector< MRWStruct > &dataList, long numData=999999)
try to decode a zone
Definition: MRWParser.cxx:1417
int m_N
the number of value
Definition: MRWParser.hxx:89
a class which stores section properties
Definition: MWAWSection.hxx:45
int m_fileType
the entry type
Definition: MRWParser.hxx:87
MWAWEntry m_pos
the file data position (for type=0 data )
Definition: MRWParser.hxx:114
int m_value
a unknown value
Definition: MRWParser.hxx:91
shared_ptr< MRWGraph > m_graphParser
the graph parser
Definition: MRWParser.hxx:221
void sendToken(int zoneId, long tokenId, MWAWFont const &actFont)
ask the graph parser to send a token
Definition: MRWParser.cxx:327
class to store the paragraph properties
Definition: MWAWParagraph.hxx:83
Vec2f getPageLeftTop() const
returns the page left top point ( in inches)
Definition: MRWParser.cxx:255
bool readSeparator(MRWEntry const &entry)
try to read the separator of differents part
Definition: MRWParser.cxx:605
shared_ptr< MRWParserInternal::State > m_state
the state
Definition: MRWParser.hxx:215
void sendText(int zoneId)
ask the text parser to send a zone
Definition: MRWParser.cxx:314
virtual class which defines the ancestor of all main zone parser
Definition: MWAWParser.hxx:98
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:66
float getPatternPercent(int id) const
return the pattern percent which corresponds to an id (or -1)
Definition: MRWParser.cxx:322
MRWStruct()
constructor
Definition: MRWParser.hxx:97
void init()
inits all internal variables
Definition: MRWParser.cxx:238
shared_ptr< MRWText > m_textParser
the text parser
Definition: MRWParser.hxx:224
Internal: a struct used to read some field.
Definition: MRWParser.hxx:95
bool isFilePos(long pos)
check if an entry is in file
Definition: MRWParser.cxx:284
bool readZoneb(MRWEntry const &entry, int zoneId)
try to read a unknown zone : one by separator?, borderdim?
Definition: MRWParser.cxx:1067
Internal: the subdocument of a MWParser.
Definition: MRWParser.cxx:181
shared_ptr< MWAWRSRCParser > MWAWRSRCParserPtr
Definition: MWAWParser.hxx:56
long m_filePos
the file position where the field description begin
Definition: MRWParser.hxx:112
bool readPrintInfo(MRWEntry const &entry)
try to read a printinfo zone
Definition: MRWParser.cxx:1275

Generated for libmwaw by doxygen 1.8.5