Debian Codegraph @

src/lib/RVNGTextTextGenerator.cpp

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* librevenge
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) 2002 William Lachance ([email protected])
11 * Copyright (C) 2002-2003 Marc Maurer ([email protected])
12 *
13 * For minor contributions see the git repository.
14 *
15 * Alternatively, the contents of this file may be used under the terms
16 * of the GNU Lesser General Public License Version 2.1 or later
17 * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
18 * applicable instead of those above.
19 */
20
21 #include <librevenge-generators/librevenge-generators.h>
22
23 #include <sstream>
24
25 // use the BELL code to represent a TAB for now
26 #define UCS_TAB 0x0009
27
28 namespace librevenge
29 {
30
31 namespace
32 {
33
34 const RVNGString getNoteMark(const RVNGPropertyList &propList, int &nextNote)
35 {
36 RVNGString mark;
37
38 if (propList["text:label"])
39 {
40 mark = propList["text:label"]->getStr();
41 }
42 else if (propList["librevenge:number"])
43 {
44 const RVNGProperty *const number = propList["librevenge:number"];
45 if (number->getInt() >= nextNote)
46 {
47 mark = number->getStr();
48 nextNote = number->getInt() + 1;
49 }
50 else
51 {
52 mark.sprintf("%d", nextNote);
53 ++nextNote;
54 }
55 }
56 else
57 {
58 mark.sprintf("%d", nextNote);
59 ++nextNote;
60 }
61
62 return mark;
63 }
64
65 }
66
67 struct RVNGTextTextGeneratorImpl
68 {
69 explicit RVNGTextTextGeneratorImpl(RVNGString &document, bool isInfo);
70
71 RVNGString &m_document;
72 std::ostringstream m_text;
73 std::ostringstream *m_stream;
74 std::ostringstream m_footnote;
75 std::ostringstream m_endnotes;
76 int m_nextFootnote;
77 int m_nextEndnote;
78 bool m_inFootnote;
79 bool m_isInfo;
80
81 // disable copying
82 RVNGTextTextGeneratorImpl(const RVNGTextTextGeneratorImpl &);
83 RVNGTextTextGeneratorImpl &operator=(const RVNGTextTextGeneratorImpl &);
84 };
85
86 RVNGTextTextGeneratorImpl::RVNGTextTextGeneratorImpl(RVNGString &document, const bool isInfo)
87 : m_document(document)
88 , m_text()
89 , m_stream(&m_text)
90 , m_footnote()
91 , m_endnotes()
92 , m_nextFootnote(1)
93 , m_nextEndnote(1)
94 , m_inFootnote(false)
95 , m_isInfo(isInfo)
96 {
97 }
98
99 RVNGTextTextGenerator::RVNGTextTextGenerator(RVNGString &document, const bool isInfo) :
100 m_impl(new RVNGTextTextGeneratorImpl(document, isInfo))
101 {
102 }
103
104 RVNGTextTextGenerator::~RVNGTextTextGenerator()
105 {
106 delete m_impl;
107 }
108
109 void RVNGTextTextGenerator::setDocumentMetaData(const RVNGPropertyList &propList)
110 {
111 if (!m_impl->m_isInfo)
112 return;
113 RVNGPropertyList::Iter propIter(propList);
114 for (propIter.rewind(); propIter.next();)
115 {
116 *m_impl->m_stream << propIter.key() << ' ' << propIter()->getStr().cstr() << '\n';
117 }
118 }
119
120 void RVNGTextTextGenerator::startDocument(const RVNGPropertyList &) {}
121 void RVNGTextTextGenerator::endDocument()
122 {
123 if (!m_impl->m_endnotes.str().empty())
124 {
125 *m_impl->m_stream << '\n';
126 *m_impl->m_stream << m_impl->m_endnotes.str();
127 }
128 m_impl->m_document=m_impl->m_stream->str().c_str();
129 }
130
131 void RVNGTextTextGenerator::definePageStyle(const RVNGPropertyList &) {}
132 void RVNGTextTextGenerator::defineEmbeddedFont(const RVNGPropertyList &) {}
133 void RVNGTextTextGenerator::openPageSpan(const RVNGPropertyList & /* propList */) {}
134 void RVNGTextTextGenerator::closePageSpan() {}
135 void RVNGTextTextGenerator::openHeader(const RVNGPropertyList & /* propList */) {}
136 void RVNGTextTextGenerator::closeHeader() {}
137 void RVNGTextTextGenerator::openFooter(const RVNGPropertyList & /* propList */) {}
138 void RVNGTextTextGenerator::closeFooter() {}
139
140 void RVNGTextTextGenerator::defineSectionStyle(const RVNGPropertyList &) {}
141 void RVNGTextTextGenerator::openSection(const RVNGPropertyList & /* propList */) {}
142 void RVNGTextTextGenerator::closeSection() {}
143
144 void RVNGTextTextGenerator::defineParagraphStyle(const RVNGPropertyList &) {}
145 void RVNGTextTextGenerator::openParagraph(const RVNGPropertyList & /* propList */) {}
146
147 void RVNGTextTextGenerator::closeParagraph()
148 {
149 if (m_impl->m_isInfo)
150 return;
151 *m_impl->m_stream << '\n';
152 if (!m_impl->m_inFootnote && !m_impl->m_footnote.str().empty())
153 {
154 *m_impl->m_stream << '\n';
155 *m_impl->m_stream << m_impl->m_footnote.str();
156 *m_impl->m_stream << '\n';
157 m_impl->m_footnote.str("");
158 }
159 }
160
161 void RVNGTextTextGenerator::defineCharacterStyle(const RVNGPropertyList &) {}
162 void RVNGTextTextGenerator::openSpan(const RVNGPropertyList & /* propList */) {}
163 void RVNGTextTextGenerator::closeSpan() {}
164
165 void RVNGTextTextGenerator::openLink(const RVNGPropertyList & /* propList */) {}
166 void RVNGTextTextGenerator::closeLink() {}
167
168 void RVNGTextTextGenerator::insertTab()
169 {
170 if (m_impl->m_isInfo)
171 return;
172 *m_impl->m_stream << static_cast<char>(UCS_TAB);
173 }
174
175 void RVNGTextTextGenerator::insertText(const RVNGString &text)
176 {
177 if (m_impl->m_isInfo)
178 return;
179 *m_impl->m_stream << text.cstr();
180 }
181
182 void RVNGTextTextGenerator::insertSpace()
183 {
184 if (m_impl->m_isInfo)
185 return;
186 *m_impl->m_stream << ' ';
187 }
188
189 void RVNGTextTextGenerator::insertLineBreak()
190 {
191 if (m_impl->m_isInfo)
192 return;
193 *m_impl->m_stream << '\n';
194 }
195
196 void RVNGTextTextGenerator::insertField(const RVNGPropertyList & /* propList */) {}
197
198 void RVNGTextTextGenerator::openOrderedListLevel(const RVNGPropertyList & /* propList */) {}
199 void RVNGTextTextGenerator::openUnorderedListLevel(const RVNGPropertyList & /* propList */) {}
200 void RVNGTextTextGenerator::closeOrderedListLevel() {}
201 void RVNGTextTextGenerator::closeUnorderedListLevel() {}
202 void RVNGTextTextGenerator::openListElement(const RVNGPropertyList & /* propList */) {}
203 void RVNGTextTextGenerator::closeListElement() {}
204
205 void RVNGTextTextGenerator::openFootnote(const RVNGPropertyList &propList)
206 {
207 const RVNGString mark = getNoteMark(propList, m_impl->m_nextFootnote);
208
209 *m_impl->m_stream << '[' << mark.cstr() << ']';
210 m_impl->m_stream = &m_impl->m_footnote;
211 *m_impl->m_stream << '[' << mark.cstr() << "] ";
212
213 m_impl->m_inFootnote = true;
214 }
215
216 void RVNGTextTextGenerator::closeFootnote()
217 {
218 // TODO: I am not sure if we allow nested footnotes
219 m_impl->m_stream = &m_impl->m_text;
220 m_impl->m_inFootnote = false;
221 }
222
223 void RVNGTextTextGenerator::openEndnote(const RVNGPropertyList &propList)
224 {
225 const RVNGString mark = getNoteMark(propList, m_impl->m_nextEndnote);
226
227 *m_impl->m_stream << '[' << mark.cstr() << ']';
228 m_impl->m_stream = &m_impl->m_endnotes;
229 *m_impl->m_stream << '[' << mark.cstr() << "] ";
230 }
231
232 void RVNGTextTextGenerator::closeEndnote()
233 {
234 m_impl->m_stream = &m_impl->m_text;
235 }
236
237 void RVNGTextTextGenerator::openComment(const RVNGPropertyList & /* propList */) {}
238 void RVNGTextTextGenerator::closeComment() {}
239 void RVNGTextTextGenerator::openTextBox(const RVNGPropertyList & /* propList */) {}
240 void RVNGTextTextGenerator::closeTextBox() {}
241
242 void RVNGTextTextGenerator::openTable(const RVNGPropertyList & /* propList */) {}
243 void RVNGTextTextGenerator::openTableRow(const RVNGPropertyList & /* propList */) {}
244 void RVNGTextTextGenerator::closeTableRow() {}
245 void RVNGTextTextGenerator::openTableCell(const RVNGPropertyList & /* propList */) {}
246 void RVNGTextTextGenerator::closeTableCell() {}
247 void RVNGTextTextGenerator::insertCoveredTableCell(const RVNGPropertyList & /* propList */) {}
248 void RVNGTextTextGenerator::closeTable() {}
249
250 void RVNGTextTextGenerator::openFrame(const RVNGPropertyList & /* propList */) {}
251 void RVNGTextTextGenerator::closeFrame() {}
252
253 void RVNGTextTextGenerator::openGroup(const librevenge::RVNGPropertyList & /* propList */) {}
254 void RVNGTextTextGenerator::closeGroup() {}
255
256 void RVNGTextTextGenerator::defineGraphicStyle(const librevenge::RVNGPropertyList & /* propList */) {}
257 void RVNGTextTextGenerator::drawRectangle(const librevenge::RVNGPropertyList & /* propList */) {}
258 void RVNGTextTextGenerator::drawEllipse(const librevenge::RVNGPropertyList & /* propList */) {}
259 void RVNGTextTextGenerator::drawPolygon(const librevenge::RVNGPropertyList & /* propList */) {}
260 void RVNGTextTextGenerator::drawPolyline(const librevenge::RVNGPropertyList & /* propList */) {}
261 void RVNGTextTextGenerator::drawPath(const librevenge::RVNGPropertyList & /* propList */) {}
262 void RVNGTextTextGenerator::drawConnector(const librevenge::RVNGPropertyList & /* propList */) {}
263
264 void RVNGTextTextGenerator::insertBinaryObject(const RVNGPropertyList & /* propList */) {}
265 void RVNGTextTextGenerator::insertEquation(const RVNGPropertyList & /* propList */) {}
266
267 }
268
269 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */