filters

slide.cpp
1/* libppt - library to read PowerPoint presentation
2 Copyright (C) 2005 Yolla Indria <yolla.indria@gmail.com>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA
18*/
19
20#include "slide.h"
21#include "presentation.h"
22#include "ustring.h"
23#include "objects.h"
24
25#include <vector>
26#include <iostream>
27
28
29using namespace Libppt;
30
31class Slide::Private
32{
33public:
34 Presentation* presentation;
35 UString title;
36 GroupObject* rootObject;
37
38 double pageWidth;
39 double pageHeight;
40};
41
42Slide::Slide( Presentation* pr )
43{
44 d = new Private;
45 d->presentation = pr;
46 d->rootObject = new GroupObject;
47 d->pageWidth = 0.0;
48 d->pageHeight = 0.0;
49}
50
51Slide::~Slide()
52{
53 delete d->rootObject;
54 delete d;
55}
56
57void Slide::clear()
58{
59 d->title = UString::null;
60 setRootObject( 0 );
61 d->rootObject = new GroupObject;
62}
63
64UString Slide::title() const
65{
66 return d->title;
67}
68
69void Slide::setTitle( const UString& t )
70{
71 UChar* s = new UChar[t.length()];
72 int len = 0;
73
74 // filter crazy characters
75 for( int i=0; i<t.length(); i++ )
76 if( t[i] != UChar(11) )
77 s[len++] = t[i];
78
79 d->title = UString( s, len );
80 delete [] s;
81}
82
83GroupObject *Slide::rootObject()
84{
85 return d->rootObject;
86}
87
88void Slide::setRootObject( GroupObject* root )
89{
90 delete d->rootObject;
91 d->rootObject = root;
92}
93
94TextObject* recursiveSearch( GroupObject* group, unsigned placeId )
95{
96 if( group )
97 for( unsigned i=0; i<group->objectCount(); i++ )
98 {
99 Object* object = group->object(i);
100 if( object->isText() )
101 {
102 TextObject* textObject = static_cast<TextObject*>(object);
103 if( textObject)
104 if( textObject->id() == (int)placeId )
105 return textObject;
106 }
107 if( object->isGroup() )
108 return recursiveSearch( static_cast<GroupObject*>(object), placeId );
109 }
110
111 return 0;
112}
113
114
115TextObject* Slide::textObject( unsigned placeId )
116{
117 return recursiveSearch( d->rootObject, placeId );
118}
119
120double Slide::pageWidth() const
121{
122 return d->pageWidth;
123}
124
125void Slide::setPageWidth( double pageWidth )
126{
127 d->pageWidth = pageWidth;
128}
129
130double Slide::pageHeight() const
131{
132 return d->pageHeight;
133}
134
135void Slide::setPageHeight( double pageHeight )
136{
137 d->pageHeight = pageHeight;
138}
static UString null
Static instance of a null string.