DocumentElement.cpp
1/* DocumentElement: The items we are collecting to be put into the Writer
2 * document: paragraph and spans of text, as well as section breaks.
3 *
4 * Copyright (C) 2002-2003 William Lachance (william.lachance@sympatico.ca)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 * For further information visit http://libwpd.sourceforge.net
22 *
23 */
24
25/* "This product is not manufactured, approved, or supported by
26 * Corel Corporation or Corel Corporation Limited."
27 */
28
29#include "DocumentElement.h"
30#include "DocumentHandler.h"
31#include "FilterInternal.h"
32#include <string.h>
33
34#define ASCII_SPACE 0x0020
35
36void TagElement::print() const
37{
38 WRITER_DEBUG_MSG(("%s\n", msTagName.cstr()));
39}
40
41void TagOpenElement::write(DocumentHandler &xHandler) const
42{
43 xHandler.startElement(getTagName().cstr(), maAttrList);
44}
45
46void TagOpenElement::print() const
47{
48 TagElement::print();
49}
50
51void TagOpenElement::addAttribute(const char *szAttributeName, const _SH_String &sAttributeValue)
52{
53 maAttrList.insert(szAttributeName, sAttributeValue);
54}
55
56void TagCloseElement::write(DocumentHandler &xHandler) const
57{
58 WRITER_DEBUG_MSG(("TagCloseElement: write (%s)\n", getTagName().cstr()));
59
60 xHandler.endElement(getTagName().cstr());
61}
62
63void CharDataElement::write(DocumentHandler &xHandler) const
64{
65 WRITER_DEBUG_MSG(("TextElement: write\n"));
66 xHandler.characters(msData);
67}
68
69TextElement::TextElement(const _SH_String & sTextBuf) :
70#ifdef HAVE_LIBWPD_0100
71 msTextBuf(sTextBuf)
72#else
73 msTextBuf(sTextBuf, false)
74#endif
75{
76}
77
78// write: writes a text run, appropriately converting spaces to <text:s>
79// elements
80void TextElement::write(DocumentHandler &xHandler) const
81{
82 _SH_PropertyList xBlankAttrList;
83
84 _SH_String sTemp;
85
86 int iNumConsecutiveSpaces = 0;
87 _SH_String::Iter i(msTextBuf);
88 for (i.rewind(); i.next();)
89 {
90 if (*(i()) == ASCII_SPACE)
91 iNumConsecutiveSpaces++;
92 else
93 iNumConsecutiveSpaces = 0;
94
95 if (iNumConsecutiveSpaces > 1) {
96 if (sTemp.len() > 0) {
97 xHandler.characters(sTemp);
98 sTemp.clear();
99 }
100 xHandler.startElement("text:s", xBlankAttrList);
101 xHandler.endElement("text:s");
102 }
103 else {
104 sTemp.append(i());
105 }
106 }
107 xHandler.characters(sTemp);
108}