Debian Codegraph @

src/lib/WPSTextParser.h

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* libwps
3 * Version: MPL 2.0 / LGPLv2.1+
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * Major Contributor(s):
10 * Copyright (C) 2009, 2011 Alonso Laurent ([email protected])
11 * Copyright (C) 2006, 2007 Andrew Ziem
12 * Copyright (C) 2004-2006 Fridrich Strba ([email protected])
13 * Copyright (C) 2004 Marc Maurer ([email protected])
14 * Copyright (C) 2003-2005 William Lachance ([email protected])
15 *
16 * For minor contributions see the git repository.
17 *
18 * Alternatively, the contents of this file may be used under the terms
19 * of the GNU Lesser General Public License Version 2.1 or later
20 * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
21 * applicable instead of those above.
22 *
23 * For further information visit http://libwps.sourceforge.net
24 */
25
26 #ifndef WPS_TEXT_PARSER_H
27 #define WPS_TEXT_PARSER_H
28
29 #include <vector>
30
31 #include "libwps_internal.h"
32
33 #include "WPSDebug.h"
34 #include "WPSEntry.h"
35
36 class WPSParser;
37
38 /** class used to defined the ancestor of parser which manages the text data */
39 class WPSTextParser
40 {
41 public:
42 //! virtual destructor
43 virtual ~WPSTextParser();
44
45 //! returns the file version
46 int version() const;
47
48 //! returns the actual input
49 RVNGInputStreamPtr &getInput()
50 {
51 return m_input;
52 }
53
54 protected:
55 //! constructor
56 WPSTextParser(WPSParser &parser, RVNGInputStreamPtr &input);
57
58 //! returns the map type->entry
59 std::multimap<std::string, WPSEntry> &getNameEntryMap();
60
61 //! returns the map type->entry
62 std::multimap<std::string, WPSEntry> const &getNameEntryMap() const;
63
64 protected:
65 //! structure which retrieves data information which correspond to a text position
66 struct DataFOD
67 {
68 /** different type which can be associated to a text position
69 *
70 * ATTR_TEXT: all text attributes (font, size, ...)
71 * ATTR_PARAG: all paragraph attributes (margin, tabs, ...)
72 * ATTR_PLC: other attribute (note, fields ... )
73 */
74 enum Type { ATTR_TEXT, ATTR_PARAG, ATTR_PLC, ATTR_UNKN };
75
76 //! the constructor
77 DataFOD()
78 : m_type(ATTR_UNKN)
79 , m_pos(-1)
80 , m_defPos(0)
81 , m_id(-1) {}
82
83 //! the type of the attribute
84 Type m_type;
85 //! the offset position of the text modified by this attribute
86 long m_pos;
87 //! the offset position of the definition of the attribute in the file
88 long m_defPos;
89 //! an identificator (which must be unique by category)
90 int m_id;
91 };
92
93 /** function which takes two sorted list of attribute (by text position).
94 \return a list of attribute */
95 std::vector<DataFOD> mergeSortedFODLists
96 (std::vector<DataFOD> const &lst1, std::vector<DataFOD> const &lst2) const;
97
98 /** callback when a new attribute is found in an FDPP/FDPC entry
99 *
100 * \param endPos define the end of the data's zone
101 * \param mess can be used to add a message in debugFile
102 * \return true and filled id if this attribute can be parsed */
103 typedef bool (WPSTextParser::* FDPParser)(long endPos,
104 int &id, std::string &mess);
105
106 /** parses a FDPP or a FDPC entry (which contains a list of ATTR_TEXT/ATTR_PARAG
107 * with their definition ) and adds found data in listFODs */
108 bool readFDP(WPSEntry const &entry,
109 std::vector<DataFOD> &fods, FDPParser parser);
110
111 protected:
112 //! a DebugFile used to write what we recognize when we parse the document
113 libwps::DebugFile &ascii()
114 {
115 return m_asciiFile;
116 }
117
118 private:
119 //! private copy constructor: forbidden
120 WPSTextParser(WPSTextParser const &parser) = delete;
121 //! private copy operator: forbidden
122 WPSTextParser &operator=(WPSTextParser const &parser) = delete;
123
124 protected:
125 //! the file version
126 mutable int m_version;
127 //! the main input
128 RVNGInputStreamPtr m_input;
129 //! pointer to the main zone parser;
130 WPSParser &m_mainParser;
131 //! an entry which corresponds to the complete text zone
132 WPSEntry m_textPositions;
133 //! the list of a FOD
134 std::vector<DataFOD> m_FODList;
135 //! the ascii file
136 libwps::DebugFile &m_asciiFile;
137 };
138
139
140 #endif /* WPSTEXTPARSER_H */
141 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */