File: OXML_Element_Text.cpp

package info (click to toggle)
abiword 3.0.8%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 64,532 kB
  • sloc: cpp: 477,427; ansic: 16,754; makefile: 5,785; xml: 4,014; yacc: 1,818; lex: 1,104; perl: 812; python: 413; php: 183; sh: 169
file content (128 lines) | stat: -rw-r--r-- 3,112 bytes parent folder | download
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */

/* AbiSource
 * 
 * Copyright (C) 2007 Philippe Milot <PhilMilot@gmail.com>
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU 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 General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  
 * 02110-1301 USA.
 */

// Class definition include
#include <OXML_Element_Text.h>

// AbiWord includes
#include <ut_types.h>
#include <ut_string.h>
#include <pd_Document.h>

OXML_Element_Text::OXML_Element_Text() : 
	OXML_Element("", T_TAG, SPAN), 
	m_pString(NULL), 
	m_range(UNKNOWN_RANGE)
{
}

OXML_Element_Text::~OXML_Element_Text()
{
	DELETEP(m_pString);
}

OXML_Element_Text::OXML_Element_Text(const gchar * text, int length) :
	OXML_Element("", T_TAG, SPAN)
	, m_pString(nullptr)
	, m_range(UNKNOWN_RANGE)
{
	setText(text, length);
}

void OXML_Element_Text::setText(const gchar * text, int /*length*/)
{
	DELETEP(m_pString);
	try {
		std::string str(text);
		m_pString = new UT_UCS4String(str);
	} catch(...) {
		m_pString = NULL;
	}
}

const UT_UCS4Char * OXML_Element_Text::getText_UCS4String()
{
	UT_return_val_if_fail(m_pString != NULL, NULL);
	return m_pString->ucs4_str();
}

const char * OXML_Element_Text::getText()
{
	UT_return_val_if_fail(m_pString != NULL, NULL);
	if(getType() == LIST)
	{
		const char* pStr = m_pString->utf8_str();
		if(pStr && (strlen(pStr) > 0) && (pStr[0] == '\t'))
			return pStr+1; //get rid of the initial tab
	}
	return m_pString->utf8_str();
}

UT_Error OXML_Element_Text::serialize(IE_Exp_OpenXML* exporter)
{
	UT_Error err = UT_OK;
	bool bList = false;
	const gchar* szValue = NULL;
	err = getAttribute("style", szValue);
	if(err == UT_OK && szValue)
	{
		if(!strcmp(szValue, "List Paragraph"))
		{
			bList = true;
		}
	}
	err = getAttribute("type", szValue);
	if(err == UT_OK && szValue)
	{
		if(!strcmp(szValue, "list_label"))
		{
			bList = true;
		}
	}
	err = getProperty("list-style", szValue);
	if(err == UT_OK && szValue)
	{
		bList = true;
	}

	err = exporter->startText(TARGET);
	if(err != UT_OK)
		return err;

	const UT_UCS4Char * text = getText_UCS4String();
	if(text)
		err = exporter->writeText(TARGET, text, bList);

	if(err != UT_OK)
		return err;
	
	return exporter->finishText(TARGET);
}

UT_Error OXML_Element_Text::addToPT(PD_Document * pDocument)
{
	UT_return_val_if_fail(pDocument != NULL && m_pString != NULL, UT_ERROR);

	//a text tag does not have children, so no need to call addChildrenToPT()
	return pDocument->appendSpan(m_pString->ucs4_str(), m_pString->length()) ? UT_OK : UT_ERROR; 
}