MarinerWrtParser.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 MARINER_WRT_PARSER
38 # define MARINER_WRT_PARSER
39
40 #include <iostream>
41 #include <string>
42 #include <vector>
43
44 #include <librevenge/librevenge.h>
45
46 #include "MWAWDebug.hxx"
47 #include "MWAWEntry.hxx"
48 #include "MWAWInputStream.hxx"
49
50 #include "MWAWParser.hxx"
51
52 namespace MarinerWrtParserInternal
53 {
54 struct State;
55 class SubDocument;
56 }
57
58 class MarinerWrtGraph;
59 class MarinerWrtText;
60
62 struct MarinerWrtEntry : public MWAWEntry {
64 MarinerWrtEntry() : MWAWEntry(), m_fileType(0), m_N(0), m_value(0)
65 {
66 }
68 virtual ~MarinerWrtEntry();
70 std::string name() const;
72 friend std::ostream &operator<< (std::ostream &o, MarinerWrtEntry const &ent)
73 {
74 if (ent.m_N || ent.m_value || ent.m_extra.length()) {
75 o << "[";
76 if (ent.m_N) o << "N=" << ent.m_N << ",";
77 if (ent.m_value) o << "unkn=" << ent.m_value << ",";
78 if (ent.m_extra.length()) o << ent.m_extra;
79 o << "],";
80 }
81 return o;
82 }
84 int m_fileType;
86 int m_N;
88 int m_value;
89 };
90
92 struct MarinerWrtStruct {
94 MarinerWrtStruct() : m_filePos(-1), m_pos(), m_type(-1), m_data()
95 {
96 }
98 friend std::ostream &operator<<(std::ostream &o, MarinerWrtStruct const &dt);
100 int numValues() const
101 {
102 return int(m_data.size());
103 }
105 bool isBasic() const
106 {
107 return (m_type==1 || m_type==2) && m_data.size()<=1;
108 }
110 long value(int i) const;
112 long m_filePos;
114 MWAWEntry m_pos;
116 int m_type;
118 std::vector<long> m_data;
119 };
120
126 class MarinerWrtParser : public MWAWTextParser
127 {
128 friend class MarinerWrtGraph;
129 friend class MarinerWrtText;
130 friend class MarinerWrtParserInternal::SubDocument;
131
132 public:
134 MarinerWrtParser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header);
136 virtual ~MarinerWrtParser();
137
139 bool checkHeader(MWAWHeader *header, bool strict=false);
140
141 // the main parse function
142 void parse(librevenge::RVNGTextInterface *documentInterface);
143
144 protected:
146 void init();
147
149 void createDocument(librevenge::RVNGTextInterface *documentInterface);
150
152 bool createZones();
154 bool readZone(int &actZone, bool onlyTest=false);
155
157 MWAWVec2f 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);
176
177 //
178 // low level
179 //
180
182 bool readEntryHeader(MarinerWrtEntry &entry);
184 bool decodeZone(std::vector<MarinerWrtStruct> &dataList, long numData=999999);
185
187 bool readSeparator(MarinerWrtEntry const &entry);
189 bool readZoneDim(MarinerWrtEntry const &entry, int zoneId);
191 bool readZoneHeader(MarinerWrtEntry const &entry, int zoneId, bool onlyTest);
193 bool readZoneb(MarinerWrtEntry const &entry, int zoneId);
195 bool readZonec(MarinerWrtEntry const &entry, int zoneId);
197 bool readZone13(MarinerWrtEntry const &entry, int zoneId);
199 bool readDocInfo(MarinerWrtEntry const &entry, int zoneId);
201 bool readPrintInfo(MarinerWrtEntry const &entry);
203 bool readCPRT(MarinerWrtEntry const &entry);
204
206 bool readNumbersString(int num, std::vector<long> &res);
207
208 protected:
209 //
210 // data
211 //
213 shared_ptr<MarinerWrtParserInternal::State> m_state;
214
216 bool m_pageMarginsSpanSet;
217
219 shared_ptr<MarinerWrtGraph> m_graphParser;
220
222 shared_ptr<MarinerWrtText> m_textParser;
223 };
224 #endif
225 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
MWAWHeader
a function used by MWAWDocument to store the version of document
Definition: MWAWHeader.hxx:56
MarinerWrtParser::m_textParser
shared_ptr< MarinerWrtText > m_textParser
the text parser
Definition: MarinerWrtParser.hxx:222
MWAWParser.hxx
MWAWEntry.hxx
MarinerWrtParser
the main class to read a Mariner Write file
Definition: MarinerWrtParser.hxx:126
MarinerWrtParser::m_state
shared_ptr< MarinerWrtParserInternal::State > m_state
the state
Definition: MarinerWrtParser.hxx:213
MarinerWrtText
the main class to read the text part of Mariner Write file
Definition: MarinerWrtText.hxx:60
MarinerWrtEntry
a entry to store a zone structure
Definition: MarinerWrtParser.hxx:62
MarinerWrtParser::m_pageMarginsSpanSet
bool m_pageMarginsSpanSet
a flag to know if page margins span are set
Definition: MarinerWrtParser.hxx:216
MarinerWrtGraph
the main class to read the graphic part of a Mariner Write file
Definition: MarinerWrtGraph.hxx:68
MarinerWrtParserInternal::SubDocument::parse
void parse(MWAWListenerPtr &listener, libmwaw::SubDocumentType type)
the parser function
Definition: MarinerWrtParser.cxx:217
HanMacWrdKTextInternal::getSection
Section getSection(const State &state, const long id)
Definition: HanMacWrdKText.cxx:249
MarinerWrtStruct
Internal: a struct used to read some field.
Definition: MarinerWrtParser.hxx:92
MWAWRSRCParserPtr
shared_ptr< MWAWRSRCParser > MWAWRSRCParserPtr
a smart pointer of MWAWRSRCParser
Definition: libmwaw_internal.hxx:527
MarinerWrtEntry::m_fileType
int m_fileType
the entry type
Definition: MarinerWrtParser.hxx:84
MarinerWrtStruct::m_type
int m_type
the data type
Definition: MarinerWrtParser.hxx:116
MarinerWrtParser::m_graphParser
shared_ptr< MarinerWrtGraph > m_graphParser
the graph parser
Definition: MarinerWrtParser.hxx:219
MWAWEntry::m_extra
std::string m_extra
an extra string
Definition: MWAWEntry.hxx:191
MWAWTextParser
virtual class which defines the ancestor of all text zone parser
Definition: MWAWParser.hxx:295
MarinerWrtStruct::numValues
int numValues() const
returns the number of values
Definition: MarinerWrtParser.hxx:100
MarinerWrtEntry::m_N
int m_N
the number of value
Definition: MarinerWrtParser.hxx:86
MarinerWrtStruct::m_pos
MWAWEntry m_pos
the file data position (for type=0 data )
Definition: MarinerWrtParser.hxx:114
MarinerWrtStruct::m_filePos
long m_filePos
the file position where the field description begin
Definition: MarinerWrtParser.hxx:112
MWAWSection
a class which stores section properties
Definition: MWAWSection.hxx:45
MWAWInputStreamPtr
shared_ptr< MWAWInputStream > MWAWInputStreamPtr
a smart pointer of MWAWInputStream
Definition: libmwaw_internal.hxx:517
MarinerWrtEntry::m_value
int m_value
a unknown value
Definition: MarinerWrtParser.hxx:88
MWAWInputStream.hxx
MWAWDebug.hxx
MarinerWrtStruct::MarinerWrtStruct
MarinerWrtStruct()
constructor
Definition: MarinerWrtParser.hxx:94
MarinerWrtStruct::m_data
std::vector< long > m_data
the data block
Definition: MarinerWrtParser.hxx:118
MarinerWrtParserInternal::operator<<
std::ostream & operator<<(std::ostream &o, Zone const &zone)
Definition: MarinerWrtParser.cxx:105
MarinerWrtStruct::isBasic
bool isBasic() const
returns true if this corresponds to a simple container
Definition: MarinerWrtParser.hxx:105
MarinerWrtEntry::MarinerWrtEntry
MarinerWrtEntry()
constructor
Definition: MarinerWrtParser.hxx:64
MWAWEntry
basic class to store an entry in a file This contained :
Definition: MWAWEntry.hxx:46
MarinerWrtParserInternal::SubDocument
Internal: the subdocument of a MarinerWrtParser.
Definition: MarinerWrtParser.cxx:184
MWAWVec2< float >
MarinerWrtParserInternal
Internal: the structures of a MarinerWrtParser.
Definition: MarinerWrtParser.cxx:65