22#include <kgenericfactory.h>
23#include <KoStoreDevice.h>
24#include <KoFilterChain.h>
29#include <tqsortedlist.h>
32typedef KGenericFactory<KprKword, KoFilter> KprKwordFactory;
33K_EXPORT_COMPONENT_FACTORY( libkprkword, KprKwordFactory(
"kofficefilters" ) )
35KprKword::KprKword(KoFilter *, const
char *, const TQStringList&) :
44KoFilter::ConversionStatus KprKword::convert(
const TQCString& from,
const TQCString& to )
46 if(to!=
"application/x-kword" || from!=
"application/x-kpresenter")
47 return KoFilter::NotImplemented;
49 KoStoreDevice* inpdev = m_chain->storageFile(
"root", KoStore::Read );
52 kdError(30502) <<
"Unable to open input stream" << endl;
53 return KoFilter::StorageCreationError;
56 inpdoc.setContent( inpdev );
59 outdoc.appendChild( outdoc.createProcessingInstruction(
"xml",
"version=\"1.0\" encoding=\"UTF-8\"" ) );
60 TQDomElement kwdoc = outdoc.createElement(
"DOC" );
61 kwdoc.setAttribute(
"editor",
"KprKword converter" );
62 kwdoc.setAttribute(
"mime",
"application/x-kword" );
63 kwdoc.setAttribute(
"syntaxVersion", 1 );
64 outdoc.appendChild( kwdoc );
66 TQDomElement paper = outdoc.createElement(
"PAPER" );
67 kwdoc.appendChild( paper );
68 paper.setAttribute(
"format", 1 );
69 paper.setAttribute(
"width", 595 );
70 paper.setAttribute(
"height", 841 );
71 TQDomElement borders = outdoc.createElement(
"PAPERBORDERS" );
72 paper.appendChild( borders );
73 borders.setAttribute(
"left", 28 );
74 borders.setAttribute(
"top", 42 );
75 borders.setAttribute(
"right", 28 );
76 borders.setAttribute(
"bottom", 42 );
78 TQDomElement framesets = outdoc.createElement(
"FRAMESETS" );
79 kwdoc.appendChild( framesets );
81 frameset = outdoc.createElement(
"FRAMESET" );
82 framesets.appendChild( frameset );
83 frameset.setAttribute(
"frameType", 1 );
84 frameset.setAttribute(
"frameInfo", 0 );
85 TQDomElement frame = outdoc.createElement(
"FRAME" );
86 frameset.appendChild( frame );
87 frame.setAttribute(
"left", 28 );
88 frame.setAttribute(
"top", 42 );
89 frame.setAttribute(
"right", 566 );
90 frame.setAttribute(
"bottom", 798 );
91 frame.setAttribute(
"autoCreateNewFrame", 1 );
92 frame.setAttribute(
"newFrameBehaviour", 0 );
94 titleStyleName = i18n(
"Slide Title");
102 TQDomElement styles = outdoc.createElement(
"STYLES" );
103 kwdoc.appendChild( styles );
105 TQDomElement style = outdoc.createElement(
"STYLE" );
106 styles.appendChild( style );
107 TQDomElement elem = outdoc.createElement(
"NAME" );
108 style.appendChild( elem );
109 elem.setAttribute(
"value", titleStyleName );
110 elem = outdoc.createElement(
"FOLLOWING" );
111 style.appendChild( elem );
112 elem.setAttribute(
"name",
"Standard" );
114 TQDomElement counter = outdoc.createElement(
"COUNTER" );
115 style.appendChild( counter );
116 counter.setAttribute(
"type", 1 );
117 counter.setAttribute(
"depth", 0 );
118 counter.setAttribute(
"start", 1 );
119 counter.setAttribute(
"numberingtype", 1 );
120 counter.setAttribute(
"righttext",
"." );
122 TQDomElement format = outdoc.createElement(
"FORMAT" );
123 style.appendChild( format );
124 TQDomElement font = outdoc.createElement(
"FONT" );
125 format.appendChild( font );
126 font.setAttribute(
"name", titleFont );
127 TQDomElement size = outdoc.createElement(
"SIZE" );
128 format.appendChild( size );
129 size.setAttribute(
"value", 24 );
130 TQDomElement bold = outdoc.createElement(
"WEIGHT" );
131 format.appendChild( bold );
132 bold.setAttribute(
"value", 75 );
135 style = outdoc.createElement(
"STYLE" );
136 styles.appendChild( style );
137 elem = outdoc.createElement(
"NAME" );
138 style.appendChild( elem );
139 elem.setAttribute(
"value",
"Standard" );
140 format = outdoc.createElement(
"FORMAT" );
141 style.appendChild( format );
145 KoStoreDevice* out = m_chain->storageFile(
"root", KoStore::Write );
147 kdError(30502) <<
"Unable to open output file!" << endl;
148 return KoFilter::StorageCreationError;
150 TQCString cstring = outdoc.toCString();
151 out->writeBlock( cstring.data(), cstring.length() );
160 bool operator < (
const KprObject & c )
const
164 bool operator == (
const KprObject & c )
const
170void KprKword::convert()
172 TQDomElement docElem = inpdoc.documentElement();
173 TQDomElement paper = docElem.namedItem(
"PAPER" ).toElement();
174 int ptPageHeight = paper.attribute(
"ptHeight" ).toInt();
176 TQDomElement objects = docElem.namedItem(
"OBJECTS" ).toElement();
177 if ( objects.isNull() )
180 TQSortedList< KprObject > objList;
181 objList.setAutoDelete(
true );
183 TQDomNodeList lst = objects.elementsByTagName(
"OBJECT" );
184 uint lstcount = lst.count();
185 for ( uint item = 0 ; item < lstcount ; ++item )
187 TQDomElement
object = lst.item( item ).toElement();
188 if (
object.attribute(
"type" ).toInt() == 4 )
190 TQDomElement orig =
object.namedItem(
"ORIG" ).toElement();
191 if ( !orig.isNull() )
193 KprObject * obj =
new KprObject;
194 obj->y = orig.attribute(
"y" ).toDouble();
196 objList.inSort( obj );
204 for ( TQPtrListIterator<KprObject> it(objList); it.current(); ++it )
206 TQDomElement elem = it.current()->elem;
208 int page = int( it.current()->y / ptPageHeight );
209 bool isTitle = ( page > curPage );
214 TQDomElement textObj = elem.namedItem(
"TEXTOBJ" ).toElement();
215 if (textObj.isNull())
218 TQDomNodeList lst = textObj.elementsByTagName(
"P" );
219 uint lstcount = lst.count();
220 for ( uint item = 0; item < lstcount ; ++item )
222 TQDomElement p = lst.item( item ).toElement();
225 TQDomElement parag = outdoc.createElement(
"PARAGRAPH" );
226 frameset.appendChild( parag );
228 TQDomElement outFormatsElem = outdoc.createElement(
"FORMATS" );
232 TQDomElement textElem = p.firstChild().toElement();
234 TQDomElement counter = p.namedItem(
"COUNTER" ).toElement();
235 TQDomElement indent=p.namedItem(
"INDENTS").toElement();
236 TQDomElement lineSpacing=p.namedItem(
"LINESPACING" ).toElement();
237 TQDomElement offset=p.namedItem(
"OFFSETS").toElement();
238 TQDomElement leftBorder = p.namedItem(
"LEFTBORDER" ).toElement();
239 TQDomElement rightBorder = p.namedItem(
"RIGHTBORDER" ).toElement();
240 TQDomElement topBorder = p.namedItem(
"TOPBORDER" ).toElement();
241 TQDomElement bottomBorder = p.namedItem(
"BOTTOMBORDER" ).toElement();
243 TQDomElement shadow=p.namedItem(
"SHADOW").toElement();
245 for ( ; !textElem.isNull() ; textElem = textElem.nextSibling().toElement() )
247 int oldLen = text.length();
248 text += textElem.text();
250 TQDomElement outFormatElem = outdoc.createElement(
"FORMAT" );
252 if ( textElem.attribute(
"italic" ).toInt() )
254 TQDomElement e = outdoc.createElement(
"ITALIC");
255 e.setAttribute(
"value", 1 );
256 outFormatElem.appendChild( e );
258 TQColor underlineColor;
259 if ( textElem.hasAttribute(
"underlinecolor" ))
261 underlineColor =TQColor(textElem.attribute(
"underlinecolor" ));
263 TQString underlineStyleLine;
264 if ( textElem.hasAttribute(
"underlinestyleline"))
266 underlineStyleLine = textElem.attribute(
"underlinestyleline");
268 if ( textElem.hasAttribute(
"underline" ))
270 TQDomElement e = outdoc.createElement(
"UNDERLINE");
271 TQString value = textElem.attribute(
"underline" );
272 if ( value ==
"double" )
274 e.setAttribute(
"value",
"double" );
276 else if ( value ==
"single" )
278 e.setAttribute(
"value",
"double" );
282 e.setAttribute(
"value", (
bool)value.toInt() ?
"1" :
"0" );
284 if ( underlineColor.isValid())
286 e.setAttribute(
"underlinecolor", underlineColor.name());
288 if ( !underlineStyleLine.isEmpty() )
289 e.setAttribute(
"styleline", underlineStyleLine);
290 outFormatElem.appendChild( e );
294 TQString strikeOutStyleLine;
295 if ( textElem.hasAttribute(
"strikeoutstyleline"))
297 strikeOutStyleLine = textElem.attribute(
"strikeoutstyleline");
299 TQString strikeOutValue;
300 if ( textElem.hasAttribute(
"strikeOut"))
302 strikeOutValue = textElem.attribute(
"strikeOut");
305 if( !strikeOutValue.isEmpty())
307 TQDomElement e = outdoc.createElement(
"STRIKEOUT");
308 e.setAttribute(
"value", strikeOutValue );
309 if ( !strikeOutStyleLine.isEmpty())
310 e.setAttribute(
"styleline", strikeOutStyleLine);
311 outFormatElem.appendChild( e );
319 if ( titleFont.isEmpty() && isTitle )
320 titleFont = textElem.attribute(
"family" );
323 if ( !textElem.attribute(
"color" ).isEmpty())
326 col.setNamedColor(textElem.attribute(
"color" ));
327 TQDomElement e = outdoc.createElement(
"COLOR");
328 e.setAttribute(
"red", col.red() );
329 e.setAttribute(
"green", col.green() );
330 e.setAttribute(
"blue", col.blue() );
331 outFormatElem.appendChild( e );
333 if ( !textElem.attribute(
"textbackcolor").isEmpty())
336 col.setNamedColor(textElem.attribute(
"textbackcolor" ));
337 TQDomElement e = outdoc.createElement(
"TEXTBACKGROUNDCOLOR");
338 e.setAttribute(
"red", col.red() );
339 e.setAttribute(
"green", col.green() );
340 e.setAttribute(
"blue", col.blue() );
341 outFormatElem.appendChild( e );
346 if( textElem.attribute(
"relativetextsize").toDouble())
348 relative = textElem.attribute(
"relativetextsize").toDouble();
352 if( textElem.attribute(
"VERTALIGN").toInt())
354 TQDomElement e = outdoc.createElement(
"VERTALIGN");
355 e.setAttribute(
"value", textElem.attribute(
"VERTALIGN").toInt() );
357 e.setAttribute(
"relativetextsize", relative );
358 outFormatElem.appendChild( e );
361 if( textElem.hasAttribute(
"shadowtext"))
363 TQDomElement e = outdoc.createElement(
"SHADOWTEXT");
364 e.setAttribute(
"value", textElem.attribute(
"shadowtext").toInt() );
365 outFormatElem.appendChild( e );
368 if( textElem.hasAttribute(
"offsetfrombaseline"))
370 TQDomElement e = outdoc.createElement(
"OFFSETFROMBASELINE");
371 e.setAttribute(
"value", textElem.attribute(
"offsetfrombaseline").toInt() );
372 outFormatElem.appendChild( e );
375 if( textElem.hasAttribute(
"wordbyword"))
377 TQDomElement e = outdoc.createElement(
"WORDBYWORD");
378 e.setAttribute(
"value", textElem.attribute(
"wordbyword").toInt() );
379 outFormatElem.appendChild( e );
382 if( textElem.hasAttribute(
"fontattribute"))
384 TQDomElement e = outdoc.createElement(
"FONTATTRIBUTE");
385 e.setAttribute(
"value", textElem.attribute(
"fontattribute") );
386 outFormatElem.appendChild( e );
388 if( textElem.hasAttribute(
"language"))
390 TQDomElement e = outdoc.createElement(
"LANGUAGE");
391 e.setAttribute(
"value", textElem.attribute(
"language") );
392 outFormatElem.appendChild( e );
394 if ( !outFormatElem.firstChild().isNull() )
396 outFormatElem.setAttribute(
"id", 1 );
397 outFormatElem.setAttribute(
"pos", oldLen );
398 outFormatElem.setAttribute(
"len", text.length() - oldLen );
399 outFormatsElem.appendChild( outFormatElem );
405 int len = text.length();
406 if ( len > 0 && text[ len - 1 ] ==
' ' )
407 text.truncate( len - 1 );
409 TQDomElement outTextElem = outdoc.createElement(
"TEXT" );
410 parag.appendChild( outTextElem );
411 outTextElem.appendChild( outdoc.createTextNode( text ) );
413 if ( !outFormatsElem.firstChild().isNull() )
414 parag.appendChild( outFormatsElem );
416 TQDomElement layoutElem = outdoc.createElement(
"LAYOUT" );
417 parag.appendChild( layoutElem );
418 TQDomElement nameElem = outdoc.createElement(
"NAME" );
419 layoutElem.appendChild( nameElem );
420 nameElem.setAttribute(
"value", isTitle ? titleStyleName : TQString(
"Standard") );
421 TQDomElement align=outdoc.createElement(
"FLOW");
422 if(p.hasAttribute(
"align"))
424 switch(p.attribute(
"align" ).toInt())
427 align.setAttribute(
"align",
"left");
430 align.setAttribute(
"align",
"right");
433 align.setAttribute(
"align",
"center");
436 align.setAttribute(
"align",
"justify");
440 if(!counter.isNull() )
441 layoutElem.appendChild( counter );
443 layoutElem.appendChild( indent );
444 if(!lineSpacing.isNull())
445 layoutElem.appendChild( lineSpacing );
447 layoutElem.appendChild( offset);
448 if(!leftBorder.isNull())
449 layoutElem.appendChild(leftBorder);
450 if(!rightBorder.isNull())
451 layoutElem.appendChild(rightBorder);
452 if(!topBorder.isNull())
453 layoutElem.appendChild(topBorder);
454 if(!bottomBorder.isNull())
455 layoutElem.appendChild(bottomBorder);
457 layoutElem.appendChild(align);
459 layoutElem.appendChild(shadow);
466#include <kprkword.moc>