MsWrdText.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 Microsoft Word text document
36 *
37 */
38 #ifndef MS_WRD_MWAW_TEXT
39 # define MS_WRD_MWAW_TEXT
40
41 #include <map>
42 #include <string>
43 #include <vector>
44
45 #include "libmwaw_internal.hxx"
46
47 #include "MWAWEntry.hxx"
48
49 #include "MWAWDebug.hxx"
50
51 #include "MsWrdTextStyles.hxx"
52
53 namespace MsWrdTextInternal
54 {
55 struct State;
56 struct Table;
57 }
58
59 struct MsWrdEntry;
60 class MsWrdParser;
61 class MsWrdTextStyles;
62
64 class MsWrdText
65 {
66 friend class MsWrdParser;
67 friend class MsWrdTextStyles;
68 public:
70 struct PLC {
71 enum Type { TextPosition, HeaderFooter, Page, Section, ParagraphInfo, Paragraph, Font, Footnote, FootnoteDef, Field, Object };
72 PLC(Type type, int id=0)
73 : m_type(type)
74 , m_id(id)
75 , m_extra("")
76 {
77 }
79 friend std::ostream &operator<<(std::ostream &o, PLC const &plc);
81 struct ltstr {
82 bool operator()(PLC const &s1, PLC const &s2) const
83 {
84 if (s1.m_type != s2.m_type)
85 return int(s1.m_type) < int(s2.m_type);
86 if (s1.m_id != s2.m_id)
87 return s1.m_id < s2.m_id;
88 return false;
89 }
90 };
92 Type m_type;
94 int m_id;
96 std::string m_extra;
97 };
98 public:
100 explicit MsWrdText(MsWrdParser &parser);
102 virtual ~MsWrdText();
103
105 int version() const;
106
108 int numPages() const;
109
111 MWAWEntry getHeader() const;
112
114 MWAWEntry getFooter() const;
115 protected:
117 std::shared_ptr<MWAWParserState> &getParserState()
118 {
119 return m_parserState;
120 }
121
123 bool sendMainText();
124
126 bool sendText(MWAWEntry const &textEntry, bool mainZone, bool tableCell=false);
128 bool sendSection(int sectionId);
130 bool readHeaderTextLength();
131
133 bool createZones(long bot);
134
136 bool readTextStruct(MsWrdEntry &entry);
137
139 bool readPageBreak(MsWrdEntry &entry);
140
142 bool readParagraphInfo(MsWrdEntry &entry);
143
145 bool readFields(MsWrdEntry &entry, std::vector<long> const &fieldPos);
146
148 bool sendFieldComment(int id);
149
151 bool readFootnotesPos(MsWrdEntry &entry, std::vector<long> const &noteDef);
152
154 bool readFootnotesData(MsWrdEntry &entry);
155
157 bool sendFootnote(int id);
158
160 bool readFontNames(MsWrdEntry &entry);
161
163 void flushExtra();
164
166 bool sendTable(MsWrdTextInternal::Table const &table);
167
168 // interface with MsWrdTextStyles
169
171 long getMainTextLength() const;
173 std::multimap<long, MsWrdText::PLC> &getTextPLCMap();
175 std::multimap<long, MsWrdText::PLC> &getFilePLCMap();
176
177 //
178 // low level
179 //
180
182 void prepareData();
183
185 void prepareLines();
187 void convertFilePLCPos();
189 void prepareParagraphProperties();
191 void prepareFontProperties();
192
194 void prepareTableLimits();
196 bool updateTableBeginnningAt(long cPos, long &nextCPos);
197
199 bool readLongZone(MsWrdEntry &entry, int sz, std::vector<long> &list);
200
201 private:
202 MsWrdText(MsWrdText const &orig) = delete;
203 MsWrdText &operator=(MsWrdText const &orig) = delete;
204
205 protected:
206 //
207 // data
208 //
210 MWAWParserStatePtr m_parserState;
211
213 std::shared_ptr<MsWrdTextInternal::State> m_state;
214
216 std::shared_ptr<MsWrdTextStyles> m_stylesManager;
217
219 MsWrdParser *m_mainParser;
220 };
221 #endif
222 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
MsWrdText::PLC::m_extra
std::string m_extra
some extra data
Definition: MsWrdText.hxx:96
MsWrdText::m_stylesManager
std::shared_ptr< MsWrdTextStyles > m_stylesManager
the style manager
Definition: MsWrdText.hxx:216
MWAWParserStatePtr
std::shared_ptr< MWAWParserState > MWAWParserStatePtr
a smart pointer of MWAWParserState
Definition: libmwaw_internal.hxx:553
BeagleWksDRParserInternal::operator<<
std::ostream & operator<<(std::ostream &o, Shape const &shape)
Definition: BeagleWksDRParser.cxx:107
MWAWEntry.hxx
libmwaw_internal.hxx
MsWrdEntry
the entry of MsWrdParser
Definition: MsWrdParser.hxx:63
MsWrdText::PLC
Internal: the plc.
Definition: MsWrdText.hxx:70
MsWrdTextStyles.hxx
MsWrdTextInternal::Table
Internal and low level: a structure to store a table of a MsWrdText.
Definition: MsWrdText.cxx:292
MsWrdText::PLC::Type
Type
Definition: MsWrdText.hxx:71
MsWrdText::PLC::ltstr::operator()
bool operator()(PLC const &s1, PLC const &s2) const
Definition: MsWrdText.hxx:82
MsWrdText::PLC::m_id
int m_id
the identificator
Definition: MsWrdText.hxx:94
MsWrdText::m_parserState
MWAWParserStatePtr m_parserState
the parser state
Definition: MsWrdText.hxx:210
MsWrdParser
the main class to read a Microsoft Word file
Definition: MsWrdParser.hxx:96
MsWrdText::PLC::m_type
Type m_type
the plc type
Definition: MsWrdText.hxx:92
MWAWDebug.hxx
MsWrdTextInternal
Internal: the structures of a MsWrdText.
Definition: MsWrdText.cxx:69
MsWrdText
the main class to read the text part of Microsoft Word file
Definition: MsWrdText.hxx:64
MsWrdTextStyles
the main class to read/store the text font, paragraph, section stylesread
Definition: MsWrdTextStyles.hxx:66
MsWrdText::m_mainParser
MsWrdParser * m_mainParser
the main parser;
Definition: MsWrdText.hxx:219
MsWrdText::PLC::ltstr
a comparaison structure
Definition: MsWrdText.hxx:81
MWAWEntry
basic class to store an entry in a file This contained :
Definition: MWAWEntry.hxx:46
MsWrdText::getParserState
std::shared_ptr< MWAWParserState > & getParserState()
returns the parser state
Definition: MsWrdText.hxx:117
MsWrdText::m_state
std::shared_ptr< MsWrdTextInternal::State > m_state
the state
Definition: MsWrdText.hxx:213
MsWrdText::PLC::PLC
PLC(Type type, int id=0)
Definition: MsWrdText.hxx:72
MWAWDocumentInternal::getHeader
MWAWHeader * getHeader(MWAWInputStreamPtr &input, MWAWRSRCParserPtr const &rsrcParser, bool strict)
return the header corresponding to an input.
Definition: MWAWDocument.cxx:436