/src/libabw/src/lib/ABWContentCollector.h
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* |
3 | | * This file is part of the libabw project. |
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 | | |
10 | | #ifndef __ABWCONTENTCOLLECTOR_H__ |
11 | | #define __ABWCONTENTCOLLECTOR_H__ |
12 | | |
13 | | #include <memory> |
14 | | #include <vector> |
15 | | #include <stack> |
16 | | #include <set> |
17 | | |
18 | | #include <librevenge/librevenge.h> |
19 | | #include "ABWOutputElements.h" |
20 | | #include "ABWCollector.h" |
21 | | |
22 | | namespace libabw |
23 | | { |
24 | | |
25 | | enum ABWContext |
26 | | { |
27 | | ABW_SECTION, |
28 | | ABW_HEADER, |
29 | | ABW_FOOTER, |
30 | | ABW_FRAME_IMAGE, |
31 | | ABW_FRAME_TEXTBOX, |
32 | | ABW_FRAME_UNKNOWN |
33 | | }; |
34 | | |
35 | | struct ABWStyle |
36 | | { |
37 | 0 | ABWStyle() : basedon(), followedby(), properties() {} |
38 | 0 | ~ABWStyle() {} |
39 | | std::string basedon; |
40 | | std::string followedby; |
41 | | ABWPropertyMap properties; |
42 | | }; |
43 | | |
44 | | struct ABWContentTableState |
45 | | { |
46 | | ABWContentTableState(); |
47 | | ABWContentTableState(const ABWContentTableState &ts); |
48 | | ~ABWContentTableState(); |
49 | | |
50 | | ABWPropertyMap m_currentTableProperties; |
51 | | ABWPropertyMap m_currentCellProperties; |
52 | | |
53 | | int m_currentTableCol; |
54 | | int m_currentTableRow; |
55 | | int m_currentTableCellNumberInRow; |
56 | | int m_currentTableId; |
57 | | bool m_isTableRowOpened; |
58 | | bool m_isTableColumnOpened; |
59 | | bool m_isTableCellOpened; |
60 | | bool m_isCellWithoutParagraph; |
61 | | bool m_isRowWithoutCell; |
62 | | }; |
63 | | |
64 | | struct ABWContentParsingState |
65 | | { |
66 | | ABWContentParsingState(); |
67 | | ABWContentParsingState(const ABWContentParsingState &ps); |
68 | | ~ABWContentParsingState(); |
69 | | |
70 | | bool m_isDocumentStarted; |
71 | | bool m_isPageSpanOpened; |
72 | | bool m_isSectionOpened; |
73 | | bool m_isHeaderOpened; |
74 | | bool m_isFooterOpened; |
75 | | |
76 | | bool m_isPageFrame; |
77 | | |
78 | | bool m_isSpanOpened; |
79 | | bool m_isParagraphOpened; |
80 | | bool m_isListElementOpened; |
81 | | bool m_inParagraphOrListElement; |
82 | | |
83 | | ABWPropertyMap m_currentSectionStyle; |
84 | | ABWPropertyMap m_currentParagraphStyle; |
85 | | ABWPropertyMap m_currentCharacterStyle; |
86 | | |
87 | | double m_pageWidth; |
88 | | double m_pageHeight; |
89 | | double m_pageMarginTop; |
90 | | double m_pageMarginBottom; |
91 | | double m_pageMarginLeft; |
92 | | double m_pageMarginRight; |
93 | | int m_footerId; |
94 | | int m_footerLeftId; |
95 | | int m_footerFirstId; |
96 | | int m_footerLastId; |
97 | | int m_headerId; |
98 | | int m_headerLeftId; |
99 | | int m_headerFirstId; |
100 | | int m_headerLastId; |
101 | | int m_currentHeaderFooterId; |
102 | | librevenge::RVNGString m_currentHeaderFooterOccurrence; |
103 | | ABWContext m_parsingContext; |
104 | | |
105 | | bool m_deferredPageBreak; |
106 | | bool m_deferredColumnBreak; |
107 | | |
108 | | bool m_isNote; |
109 | | |
110 | | int m_currentListLevel; |
111 | | int m_currentListId; |
112 | | bool m_isFirstTextInListElement; |
113 | | |
114 | | std::stack<ABWContentTableState> m_tableStates; |
115 | | std::stack<std::pair<int, std::shared_ptr<ABWListElement>>> m_listLevels; |
116 | | }; |
117 | | |
118 | | class ABWContentCollector : public ABWCollector |
119 | | { |
120 | | public: |
121 | | ABWContentCollector(librevenge::RVNGTextInterface *iface, const std::map<int, int> &tableSizes, |
122 | | const std::map<std::string, ABWData> &data, |
123 | | const std::map<int, std::shared_ptr<ABWListElement>> &listElements); |
124 | | ~ABWContentCollector() override; |
125 | | |
126 | | // collector functions |
127 | | |
128 | | void collectTextStyle(const char *name, const char *basedon, const char *followedby, const char *props) override; |
129 | | void collectDocumentProperties(const char *props) override; |
130 | | void collectParagraphProperties(const char *level, const char *listid, const char *parentid, const char *style, const char *props) override; |
131 | | void collectSectionProperties(const char *footer, const char *footerLeft, const char *footerFirst, const char *footerLast, |
132 | | const char *header, const char *headerLeft, const char *headerFirst, const char *headerLast, |
133 | | const char *props) override; |
134 | | void collectCharacterProperties(const char *style, const char *props) override; |
135 | | void collectPageSize(const char *width, const char *height, const char *units, const char *pageScale) override; |
136 | | void closeParagraphOrListElement() override; |
137 | | void closeSpan() override; |
138 | | void openLink(const char *href) override; |
139 | | void closeLink() override; |
140 | | void openFoot(const char *id) override; |
141 | | void closeFoot() override; |
142 | | void openEndnote(const char *id) override; |
143 | | void closeEndnote() override; |
144 | | void openField(const char *type, const char *id) override; |
145 | | void closeField() override; |
146 | | void endSection() override; |
147 | | void startDocument() override; |
148 | | void endDocument() override; |
149 | | void insertLineBreak() override; |
150 | | void insertColumnBreak() override; |
151 | | void insertPageBreak() override; |
152 | | void insertText(const char *text) override; |
153 | | void insertImage(const char *dataid, const char *props) override; |
154 | 0 | void collectList(const char *, const char *, const char *, const char *, const char *, const char *) override {} |
155 | | |
156 | | void collectData(const char *name, const char *mimeType, const librevenge::RVNGBinaryData &data) override; |
157 | | void collectHeaderFooter(const char *id, const char *type) override; |
158 | | |
159 | | void openTable(const char *props) override; |
160 | | void closeTable() override; |
161 | | void openCell(const char *props) override; |
162 | | void closeCell() override; |
163 | | |
164 | | void openFrame(const char *props, const char *imageId, const char *title, const char *alt) override; |
165 | | void closeFrame(ABWOutputElements *(&elements), bool &pageFrame) override; |
166 | | void addFrameElements(ABWOutputElements &elements, bool pageFrame) override; |
167 | | |
168 | | void addMetadataEntry(const char *name, const char *value) override; |
169 | | |
170 | | private: |
171 | | ABWContentCollector(const ABWContentCollector &); |
172 | | ABWContentCollector &operator=(const ABWContentCollector &); |
173 | | |
174 | | void _setMetadata(); |
175 | | |
176 | | void _addBorderProperties(const std::map<std::string, std::string> &map, librevenge::RVNGPropertyList &propList, const std::string &defaultUndefBorderProp=""); |
177 | | |
178 | | void _openPageSpan(); |
179 | | void _closePageSpan(); |
180 | | |
181 | | void _openSection(); |
182 | | void _closeSection(); |
183 | | |
184 | | //! open a paragraph or a list element (depend on m_currentListLevel) |
185 | | void _openBlock(); |
186 | | //! close the current paragraph or list element |
187 | | void _closeBlock(); |
188 | | |
189 | | void _openParagraph(); |
190 | | void _closeParagraph(); |
191 | | |
192 | | void _openListElement(); |
193 | | void _closeListElement(); |
194 | | |
195 | | void _handleListChange(); |
196 | | void _changeList(); |
197 | | void _recurseListLevels(int oldLevel, int newLevel, int listId); |
198 | | void _writeOutDummyListLevels(int oldLevel, int newLevel); |
199 | | |
200 | | void _openSpan(); |
201 | | void _closeSpan(); |
202 | | |
203 | | void _openTable(); |
204 | | void _closeTable(); |
205 | | void _openTableRow(); |
206 | | void _closeTableRow(); |
207 | | void _openTableCell(); |
208 | | void _closeTableCell(); |
209 | | |
210 | | void _openHeader(); |
211 | | void _closeHeader(); |
212 | | void _openFooter(); |
213 | | void _closeFooter(); |
214 | | |
215 | | void _recurseTextProperties(const char *name, ABWPropertyMap &styleProps); |
216 | | std::string _findDocumentProperty(const char *name); |
217 | | std::string _findParagraphProperty(const char *name); |
218 | | std::string _findCharacterProperty(const char *name); |
219 | | std::string _findTableProperty(const char *name); |
220 | | std::string _findCellProperty(const char *name); |
221 | | std::string _findSectionProperty(const char *name); |
222 | | std::string _findMetadataEntry(const char *name); |
223 | | |
224 | | void _fillParagraphProperties(librevenge::RVNGPropertyList &propList, bool isListElement); |
225 | | bool _convertFieldDTFormat(std::string const &dtFormat, librevenge::RVNGPropertyListVector &propVect); |
226 | | |
227 | | int getCellPos(const char *startProp, const char *endProp, int defStart); |
228 | | |
229 | | std::shared_ptr<ABWContentParsingState> m_ps; |
230 | | librevenge::RVNGTextInterface *m_iface; |
231 | | std::stack<std::shared_ptr<ABWContentParsingState> > m_parsingStates; |
232 | | std::set<std::string> m_dontLoop; |
233 | | std::map<std::string, ABWStyle> m_textStyles; |
234 | | |
235 | | ABWPropertyMap m_documentStyle; |
236 | | ABWPropertyMap m_metadata; |
237 | | |
238 | | const std::map<std::string, ABWData> &m_data; |
239 | | const std::map<int, int> &m_tableSizes; |
240 | | int m_tableCounter; |
241 | | ABWOutputElements m_outputElements; |
242 | | ABWOutputElements m_pageOutputElements; |
243 | | const std::map<int, std::shared_ptr<ABWListElement>> &m_listElements; |
244 | | std::vector<std::shared_ptr<ABWListElement>> m_dummyListElements; |
245 | | }; |
246 | | |
247 | | } // namespace libabw |
248 | | |
249 | | #endif /* __ABWCOLLECTOR_H__ */ |
250 | | /* vim:set shiftwidth=2 softtabstop=2 expandtab: */ |