summaryrefslogtreecommitdiffstats
path: root/filters/olefilters/powerpoint97/pptxml.cpp
blob: 42be4de5c5a76d101b3b0dc99d076623f6f83258 (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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
/*
    Copyright (C) 2000, S.R.Haque <shaheedhaque@hotmail.com>.
    This file is part of the KDE project

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library 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; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.

DESCRIPTION
*/

#include <pptdoc.h>
#include <pptxml.h>
#include <tqobject.h>
#include <KoGlobal.h>

const int PptXml::s_area = 30512;

PptXml::PptXml(
    const myFile &mainStream,
    const myFile &currentUser,
    const myFile &pictures):
        PptDoc(
            mainStream,
            currentUser,
            pictures)
{
    m_isConverted = false;
    m_success = false;
    m_half = false;
    m_y = 0;
}

PptXml::~PptXml()
{
}

bool PptXml::convert()
{
    if (!m_isConverted)
    {
       // m_y = 30;
        m_success = parse();
        m_isConverted = true;
    }
    return m_success;
}

void PptXml::encode(TQString &text)
{
  // When encoding the stored form of text to its run-time form,
  // be sure to do the conversion for "&amp;" to "&" first to avoid
  // accidentally converting user text into one of the other escape
  // sequences.

  text.replace('&', "&amp;");
  text.replace('<', "&lt;");
  text.replace('>', "&gt;"); // Needed to avoid ]]>

  // Strictly, there is no need to encode " or ', but we do so to allow
  // them to co-exist!

  text.replace('"', "&quot;");
  text.replace('\'', "&apos;");
}

const TQString PptXml::getXml() const
{
    TQString body = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE DOC>\n"
        "<DOC mime=\"application/x-kpresenter\" email=\"reggie@kde.org\" syntaxVersion=\"2\" author=\"Reginald Stadlbauer\" editor=\"Powerpoint import filter\">\n"
        " <PAPER ptWidth=\"680\" unit=\"0\" format=\"5\" orientation=\"0\" ptHeight=\"510\">\n"
        "  <PAPERBORDERS ptRight=\"0\" ptBottom=\"0\" ptLeft=\"0\" ptTop=\"0\"/>\n"
        " </PAPER>\n"
        " <BACKGROUND rastX=\"10\" rastY=\"10\" color=\"#ffffff\">\n";
    body += m_pages;
    body += " </BACKGROUND>\n"
        " <HEADER show=\"0\">\n"
        "  <ORIG x=\"0\" y=\"0\"/>\n"
        "  <SIZE width=\"680\" height=\"20\"/>\n"
        "  <PEN width=\"1\" style=\"0\" color=\"#000000\"/>\n"
        "  <TEXTOBJ>\n"
        "   <P/>\n"
        "  </TEXTOBJ>\n"
        " </HEADER>\n"
        " <FOOTER show=\"0\">\n"
        "  <ORIG x=\"0\" y=\"430\"/>\n"
        "  <SIZE width=\"680\" height=\"20\"/>\n"
        "  <PEN width=\"1\" style=\"0\" color=\"#000000\"/>\n"
        "  <TEXTOBJ>\n"
        "   <P/>\n"
        "  </TEXTOBJ>\n"
        " </FOOTER>\n"
        " <PAGETITLES>\n";
    body += m_titles;
    body += " </PAGETITLES>\n"
        " <PAGENOTES>\n";
    body += m_notes;
    body += " </PAGENOTES>\n"
        " <OBJECTS>\n";
    body += m_text;
    body += " </OBJECTS>\n"
        " <INFINITLOOP value=\"0\"/>\n"
        " <MANUALSWITCH value=\"1\"/>\n"
        " <PRESSPEED value=\"1\"/>\n"
        " <PRESSLIDES value=\"0\"/>\n"
        " <SELSLIDES>\n"
        " <SLIDE nr=\"0\" show=\"1\"/>\n"
        " </SELSLIDES>\n"
        " <PIXMAPS>\n"
        " </PIXMAPS>\n"
        " <CLIPARTS>\n"
        " </CLIPARTS>\n";
    body += m_embedded;
    body += "</DOC>\n";
    //kdDebug(s_area) << body << endl;
    return body;
}

void PptXml::gotDrawing(
    unsigned id,
    TQString type,
    unsigned length,
    const char *data)
{
    TQString ourKey;
    TQString uid;
    TQString mimeType;
    TQString filterArgs;

    // Send the picture to the outside world and get back the UID.

    ourKey = "vectorGraphic" + TQString::number(id) + "." + type;
    if (type == "msod")
    {
        filterArgs = "shape-id=";
        filterArgs += TQString::number(id);
        filterArgs += ";delay-stream=";
        filterArgs += TQString::number(0);
    }
    emit signalSavePart(
            ourKey,
            uid,
            mimeType,
            type,
            length,
            data);

    // Add an entry to the list of embedded objects too. TBD: fix
    // RECT and FRAME settings.
if (mimeType != "application/x-kontour")
{
    m_embedded += "  <EMBEDDED>\n"
                "<OBJECT url=\"" +
                uid +
                "\" mime=\"" +
                mimeType +
                "\">\n<RECT x=\"30\" y=\"190\" w=\"120\" h=\"80\"/>\n"
                "</OBJECT>\n"
                "<SETTINGS>\n"
                "<EFFECTS effect=\"0\" effect2=\"0\"/>\n"
                "<PEN red=\"0\" green=\"0\" blue=\"0\" width=\"1\" style=\"0\"/>\n"
                "<BRUSH red=\"0\" green=\"0\" blue=\"0\" style=\"0\"/>\n"
                "<PRESNUM value=\"0\"/>\n"
                "<ANGLE value=\"0\"/>\n"
                "<FILLTYPE value=\"0\"/>\n"
                "<GRADIENT red1=\"255\" green1=\"0\" blue1=\"0\" red2=\"0\" green2=\"255\" blue2=\"0\" type=\"1\" unbalanced=\"0\" xfactor=\"100\" yfactor=\"100\"/>\n"
                "<DISAPPEAR effect=\"0\" doit=\"0\" num=\"1\"/>\n"
                "</SETTINGS>\n"
                "  </EMBEDDED>\n";
}
}

void PptXml::gotSlide(PptSlide &slide)
{
	static const unsigned pageHeight = 510;
	TQ_UINT16 numbOfPholders = 0;
    	m_pages += "  <PAGE/>\n";
	numbOfPholders = slide.getNumberOfPholders();
	for(TQ_UINT16 i = 0; i < numbOfPholders; i++)
	{
		slide.gotoPlaceholder(i);
		setPlaceholder(slide);
	}
	m_y += pageHeight;
}

void PptXml::setPlaceholder(PptSlide &slide)
{
 	TQString xml_friendly;
 	unsigned i = 0;
	bool 		bulletedList = false; 	//is this a bulleted list?
	TQ_UINT16 	type;				//type of text
	TQString 	x;				//x of placeholder
	TQString 	align;				//align of text
	TQString 	height ;			//height of placeholder
	TQString 	width ;			//width of placeholder
	TQString 	pointSize;			//font size

 	xml_friendly = *slide.getPlaceholderText().at(i);
  	encode(xml_friendly);

	type = slide.getPlaceholderType();
	TQ_UINT16 y = 0;

	switch (type)
	{
	case TITLE_TEXT:
		y = 30;
		height = TQString::number(55);
		x = TQString::number(30);
		width = TQString::number(610);
		align = TQString::number(ALIGN_CENTER);
		pointSize = TQString::number(44);
		bulletedList = false;
		m_titles += "  <Title title=\"" + xml_friendly + "\" />\n";
		break;
	case CENTER_TITLE_TEXT:
		y = 130;
		x = TQString::number(45);
		height = TQString::number(55);
		width = TQString::number(610);
		align = TQString::number(ALIGN_CENTER);
		pointSize = TQString::number(44);
		bulletedList = false;
		m_titles += "  <Title title=\"" + xml_friendly + "\" />\n";
		break;
	case CENTER_BODY_TEXT:
		y = 200;
		x = TQString::number(35);
		height = TQString::number(37);
		width = TQString::number(610);
		align = TQString::number(ALIGN_CENTER);
		pointSize = TQString::number(32);
		bulletedList = false;
		break;
	case NOTES_TEXT:
		m_notes += "  <Note note=\"\" />\n";
		break;
	case BODY_TEXT:
		y = 130;
		x = TQString::number(35);
		height = TQString::number(268);
		width = TQString::number(610);
		align = TQString::number(ALIGN_LEFT);
		pointSize = TQString::number(28);
		bulletedList = true;
		break;
	case OTHER_TEXT:
	case HALF_BODY_TEXT:
	case QUARTER_BODY_TEXT:
		y = 130;
		if(m_half)
		{
			x = TQString::number(335);
			width = TQString::number(300);
			m_half = false;
		}
		else
		{
			x = TQString::number(30);
			width = TQString::number(300);
			m_half = true;
		}
		height = TQString::number(268);
		align = TQString::number(ALIGN_LEFT);
		pointSize = TQString::number(28);
		bulletedList = true;
		break;
	default:
		return;
		break;
	}

    	m_text += "<OBJECT type=\"4\">\n"
            	" <ORIG x=\""+x+"\" y=\""+TQString::number(y + m_y)+"\"/>\n"
            	" <SIZE width=\""+width+"\" height=\""+ height +"\"/>\n"
            	" <PEN width=\"1\" style=\"0\" color=\"#000000\"/>\n"
            	" <TEXTOBJ>\n"
            	"  <P align=\""+align+"\">\n";
	if(bulletedList)
 		m_text += "   <COUNTER numberingtype=\"0\" type=\"10\" depth=\"0\" />\n";
	m_text += "   <TEXT family=\"utopia\" pointSize=\""+pointSize+"\" color=\"#000000\">";

    	for (i = 0; i < slide.getPlaceholderText().count(); i++)
    	{
        	xml_friendly = *slide.getPlaceholderText().at(i);
        	encode(xml_friendly);
        	m_text += xml_friendly;
        	if (i < slide.getPlaceholderText().count() - 1)
		{
        		m_text += "</TEXT>\n"
          			"  </P>\n"
            			"  <P align=\"1\">\n";
			if(bulletedList)
            			m_text += "   <COUNTER numberingtype=\"0\" type=\"10\" depth=\"0\" />\n";
           		m_text += "   <TEXT family=\"utopia\" pointSize=\""+pointSize+"\" color=\"#000000\">";
		}
 	}
    	m_text += "</TEXT>\n"
     		"  </P>\n"
            	" </TEXTOBJ>\n"
            	"</OBJECT>";

}

#include "pptxml.moc"