summaryrefslogtreecommitdiffstats
path: root/filters/kword/wordperfect/import/DocumentElement.cpp
blob: f10e5696962c1cc0d5fad46e2ecd3b5b3ad67387 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* DocumentElement: The items we are collecting to be put into the Writer
 * document: paragraph and spans of text, as well as section breaks.
 *
 * Copyright (C) 2002-2003 William Lachance (william.lachance@sympatico.ca)
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 * For further information visit http://libwpd.sourceforge.net
 *
 */

/* "This product is not manufactured, approved, or supported by 
 * Corel Corporation or Corel Corporation Limited."
 */

#include "DocumentElement.h"
#include "DocumentHandler.h"
#include "FilterInternal.h"
#include <string.h>

#define ASCII_SPACE 0x0020

void TagElement::print() const
{
	WRITER_DEBUG_MSG(("%s\n", msTagName.cstr()));
}

void TagOpenElement::write(DocumentHandler &xHandler) const
{
	xHandler.startElement(getTagName().cstr(), maAttrList);
}

void TagOpenElement::print() const
{ 
	TagElement::print(); 	
}

void TagOpenElement::addAttribute(const char *szAttributeName, const _SH_String &sAttributeValue)
{
        maAttrList.insert(szAttributeName, sAttributeValue);
}

void TagCloseElement::write(DocumentHandler &xHandler) const
{
	WRITER_DEBUG_MSG(("TagCloseElement: write (%s)\n", getTagName().cstr()));

	xHandler.endElement(getTagName().cstr());
}

void CharDataElement::write(DocumentHandler &xHandler) const
{
	WRITER_DEBUG_MSG(("TextElement: write\n"));
	xHandler.characters(msData);
}

TextElement::TextElement(const _SH_String & sTextBuf) :
#ifdef HAVE_LIBWPD_0100	
	msTextBuf(sTextBuf)
#else
	msTextBuf(sTextBuf, false)
#endif
{
}

// write: writes a text run, appropriately converting spaces to <text:s>
// elements
void TextElement::write(DocumentHandler &xHandler) const
{
	_SH_PropertyList xBlankAttrList;
        
	_SH_String sTemp;

	int iNumConsecutiveSpaces = 0;
        _SH_String::Iter i(msTextBuf);
	for (i.rewind(); i.next();) 
        {
		if (*(i()) == ASCII_SPACE)
			iNumConsecutiveSpaces++;
		else
			iNumConsecutiveSpaces = 0;

		if (iNumConsecutiveSpaces > 1) {
			if (sTemp.len() > 0) {
				xHandler.characters(sTemp);
				sTemp.clear();
			}
			xHandler.startElement("text:s", xBlankAttrList);
			xHandler.endElement("text:s");
		}
		else {
                        sTemp.append(i());
		}
	}
	xHandler.characters(sTemp);
}