xref: /AOO41X/main/writerperfect/source/filter/DocumentElement.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19   *
20  * For further information visit http://libwpd.sourceforge.net
21  *
22  */
23 
24 /* "This product is not manufactured, approved, or supported by
25  * Corel Corporation or Corel Corporation Limited."
26  */
27 
28 #include "DocumentElement.hxx"
29 #include "FilterInternal.hxx"
30 #include <string.h>
31 
32 #define ASCII_SPACE 0x0020
33 
print() const34 void TagElement::print() const
35 {
36     WRITER_DEBUG_MSG(("%s\n", msTagName.cstr()));
37 }
38 
write(DocumentHandler * pHandler) const39 void TagOpenElement::write(DocumentHandler *pHandler) const
40 {
41     pHandler->startElement(getTagName().cstr(), maAttrList);
42 }
43 
print() const44 void TagOpenElement::print() const
45 {
46     TagElement::print();
47 }
48 
addAttribute(const char * szAttributeName,const WPXString & sAttributeValue)49 void TagOpenElement::addAttribute(const char *szAttributeName, const WPXString &sAttributeValue)
50 {
51         maAttrList.insert(szAttributeName, sAttributeValue);
52 }
53 
write(DocumentHandler * pHandler) const54 void TagCloseElement::write(DocumentHandler *pHandler) const
55 {
56     WRITER_DEBUG_MSG(("TagCloseElement: write (%s)\n", getTagName().cstr()));
57 
58     pHandler->endElement(getTagName().cstr());
59 }
60 
write(DocumentHandler * pHandler) const61 void CharDataElement::write(DocumentHandler *pHandler) const
62 {
63     WRITER_DEBUG_MSG(("TextElement: write\n"));
64     pHandler->characters(msData);
65 }
66 
TextElement(const WPXString & sTextBuf)67 TextElement::TextElement(const WPXString & sTextBuf) :
68     msTextBuf(sTextBuf, false)
69 {
70 }
71 
72 // write: writes a text run, appropriately converting spaces to <text:s>
73 // elements
write(DocumentHandler * pHandler) const74 void TextElement::write(DocumentHandler *pHandler) const
75 {
76     WPXPropertyList xBlankAttrList;
77 
78     WPXString sTemp;
79 
80     int iNumConsecutiveSpaces = 0;
81         WPXString::Iter i(msTextBuf);
82     for (i.rewind(); i.next();)
83         {
84         if (*(i()) == ASCII_SPACE)
85             iNumConsecutiveSpaces++;
86         else
87             iNumConsecutiveSpaces = 0;
88 
89         if (iNumConsecutiveSpaces > 1) {
90             if (sTemp.len() > 0) {
91                 pHandler->characters(sTemp);
92                 sTemp.clear();
93             }
94             pHandler->startElement("text:s", xBlankAttrList);
95             pHandler->endElement("text:s");
96         }
97         else {
98                         sTemp.append(i());
99         }
100     }
101     pHandler->characters(sTemp);
102 }
103