merge the formfield patch from ooo-build
[ooovba.git] / writerperfect / source / filter / DocumentElement.cxx
bloba869b5918a6c12f50046035a4c42a06b8c979b8b
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.
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * For further information visit http://libwpd.sourceforge.net
24 /* "This product is not manufactured, approved, or supported by
25 * Corel Corporation or Corel Corporation Limited."
28 #include "DocumentElement.hxx"
29 #include "FilterInternal.hxx"
30 #include <string.h>
32 #define ASCII_SPACE 0x0020
34 void TagElement::print() const
36 WRITER_DEBUG_MSG(("%s\n", msTagName.cstr()));
39 void TagOpenElement::write(DocumentHandler *pHandler) const
41 pHandler->startElement(getTagName().cstr(), maAttrList);
44 void TagOpenElement::print() const
46 TagElement::print();
49 void TagOpenElement::addAttribute(const char *szAttributeName, const WPXString &sAttributeValue)
51 maAttrList.insert(szAttributeName, sAttributeValue);
54 void TagCloseElement::write(DocumentHandler *pHandler) const
56 WRITER_DEBUG_MSG(("TagCloseElement: write (%s)\n", getTagName().cstr()));
58 pHandler->endElement(getTagName().cstr());
61 void CharDataElement::write(DocumentHandler *pHandler) const
63 WRITER_DEBUG_MSG(("TextElement: write\n"));
64 pHandler->characters(msData);
67 TextElement::TextElement(const WPXString & sTextBuf) :
68 msTextBuf(sTextBuf, false)
72 // write: writes a text run, appropriately converting spaces to <text:s>
73 // elements
74 void TextElement::write(DocumentHandler *pHandler) const
76 WPXPropertyList xBlankAttrList;
78 WPXString sTemp;
80 int iNumConsecutiveSpaces = 0;
81 WPXString::Iter i(msTextBuf);
82 for (i.rewind(); i.next();)
84 if (*(i()) == ASCII_SPACE)
85 iNumConsecutiveSpaces++;
86 else
87 iNumConsecutiveSpaces = 0;
89 if (iNumConsecutiveSpaces > 1) {
90 if (sTemp.len() > 0) {
91 pHandler->characters(sTemp);
92 sTemp.clear();
94 pHandler->startElement("text:s", xBlankAttrList);
95 pHandler->endElement("text:s");
97 else {
98 sTemp.append(i());
101 pHandler->characters(sTemp);