00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "ooimpressexport.h"
00021
00022 #include <qdom.h>
00023 #include <qfile.h>
00024 #include <qdatetime.h>
00025
00026 #include <kdebug.h>
00027 #include <kgenericfactory.h>
00028 #include <KoFilterChain.h>
00029 #include <KoGlobal.h>
00030 #include <KoUnit.h>
00031
00032 typedef KGenericFactory<OoImpressExport, KoFilter> OoImpressExportFactory;
00033 K_EXPORT_COMPONENT_FACTORY( libooimpressexport, OoImpressExportFactory( "kofficefilters" ) )
00034
00035
00036 OoImpressExport::OoImpressExport( KoFilter *, const char *, const QStringList & )
00037 : KoFilter()
00038 , m_currentPage( 0 )
00039 , m_objectIndex( 0 )
00040 , m_pageHeight( 0 )
00041 , m_activePage( 0 )
00042 , m_gridX( -1.0 )
00043 , m_gridY( -1.0 )
00044 , m_snapToGrid( false )
00045 , m_pictureIndex( 0 )
00046 , m_storeinp( 0L )
00047 , m_storeout( 0L )
00048 {
00049 }
00050
00051 OoImpressExport::~OoImpressExport()
00052 {
00053 delete m_storeout;
00054 delete m_storeinp;
00055 }
00056
00057 KoFilter::ConversionStatus OoImpressExport::convert( const QCString & from,
00058 const QCString & to )
00059 {
00060 kdDebug(30518) << "Entering Ooimpress Export filter: " << from << " - " << to << endl;
00061
00062 if ( ( to != "application/vnd.sun.xml.impress") || (from != "application/x-kpresenter" ) )
00063 {
00064 kdWarning(30518) << "Invalid mimetypes " << to << " " << from << endl;
00065 return KoFilter::NotImplemented;
00066 }
00067
00068
00069 KoFilter::ConversionStatus preStatus = openFile();
00070
00071 if ( preStatus != KoFilter::OK )
00072 return preStatus;
00073
00074 QDomImplementation impl;
00075 QDomDocument meta( impl.createDocumentType( "office:document-meta",
00076 "-//OpenOffice.org//DTD OfficeDocument 1.0//EN",
00077 "office.dtd" ) );
00078
00079 createDocumentMeta( meta );
00080
00081
00082 m_storeout = KoStore::createStore( m_chain->outputFile(), KoStore::Write, "", KoStore::Zip );
00083
00084 if ( !m_storeout )
00085 {
00086 kdWarning(30518) << "Couldn't open the requested file." << endl;
00087 return KoFilter::FileNotFound;
00088 }
00089
00090 if ( !m_storeout->open( "meta.xml" ) )
00091 {
00092 kdWarning(30518) << "Couldn't open the file 'meta.xml'." << endl;
00093 return KoFilter::CreationError;
00094 }
00095
00096 QCString metaString = meta.toCString();
00097
00098 m_storeout->write( metaString , metaString.length() );
00099 m_storeout->close();
00100
00101 QDomDocument content( impl.createDocumentType( "office:document-content",
00102 "-//OpenOffice.org//DTD OfficeDocument 1.0//EN",
00103 "office.dtd" ) );
00104
00105 createDocumentContent( content );
00106
00107
00108 m_styleFactory.addAutomaticStyles( content, m_styles );
00109
00110
00111 if ( !m_storeout->open( "content.xml" ) )
00112 {
00113 kdWarning(30518) << "Couldn't open the file 'content.xml'." << endl;
00114 return KoFilter::CreationError;
00115 }
00116
00117 QCString contentString = content.toCString();
00118
00119 m_storeout->write( contentString , contentString.length() );
00120 m_storeout->close();
00121
00122 QDomDocument settings( impl.createDocumentType( "office:document-content",
00123 "-//OpenOffice.org//DTD OfficeDocument 1.0//EN",
00124 "office.dtd" ) );
00125
00126 createDocumentSettings( settings );
00127
00128
00129 if ( !m_storeout->open( "settings.xml" ) )
00130 {
00131 kdWarning(30518) << "Couldn't open the file 'settings.xml'." << endl;
00132 return KoFilter::CreationError;
00133 }
00134
00135 QCString settingsString = settings.toCString();
00136
00137 m_storeout->write( settingsString , settingsString.length() );
00138 m_storeout->close();
00139
00140
00141 QDomDocument styles( impl.createDocumentType( "office:document-styles",
00142 "-//OpenOffice.org//DTD OfficeDocument 1.0//EN",
00143 "office.dtd" ) );
00144
00145 createDocumentStyles( styles );
00146
00147
00148 if ( !m_storeout->open( "styles.xml" ) )
00149 {
00150 kdWarning(30518) << "Couldn't open the file 'styles.xml'." << endl;
00151 return KoFilter::CreationError;
00152 }
00153
00154 QCString stylesString = styles.toCString();
00155
00156 m_storeout->write( stylesString , stylesString.length() );
00157 m_storeout->close();
00158
00159 QDomDocument manifest( impl.createDocumentType( "manifest:manifest",
00160 "-//OpenOffice.org//DTD Manifest 1.0//EN",
00161 "Manifest.dtd" ) );
00162
00163 createDocumentManifest( manifest );
00164
00165
00166 m_storeout->enterDirectory( "META-INF" );
00167 if ( !m_storeout->open( "manifest.xml" ) )
00168 {
00169 kdWarning(30518) << "Couldn't open the file 'META-INF/manifest.xml'." << endl;
00170 return KoFilter::CreationError;
00171 }
00172
00173 QCString manifestString = manifest.toCString();
00174
00175 m_storeout->write( manifestString , manifestString.length() );
00176 m_storeout->close();
00177
00178 return KoFilter::OK;
00179 }
00180
00181 KoFilter::ConversionStatus OoImpressExport::openFile()
00182 {
00183 m_storeinp = KoStore::createStore( m_chain->inputFile(), KoStore::Read );
00184
00185 if ( !m_storeinp )
00186 {
00187 kdWarning(30518) << "Couldn't open the requested file." << endl;
00188 return KoFilter::FileNotFound;
00189 }
00190
00191 if ( !m_storeinp->open( "maindoc.xml" ) )
00192 {
00193 kdWarning(30518) << "This file doesn't seem to be a valid KPresenter file" << endl;
00194 return KoFilter::WrongFormat;
00195 }
00196
00197 m_maindoc.setContent( m_storeinp->device() );
00198 m_storeinp->close();
00199
00200 if ( m_storeinp->open( "documentinfo.xml" ) )
00201 {
00202 m_documentinfo.setContent( m_storeinp->device() );
00203 m_storeinp->close();
00204 }
00205 else
00206 kdWarning(30518) << "Documentinfo do not exist!" << endl;
00207
00208 emit sigProgress( 10 );
00209
00210 return KoFilter::OK;
00211 }
00212
00213 void OoImpressExport::createDocumentMeta( QDomDocument & docmeta )
00214 {
00215 docmeta.appendChild( docmeta.createProcessingInstruction( "xml","version=\"1.0\" encoding=\"UTF-8\"" ) );
00216
00217 QDomElement content = docmeta.createElement( "office:document-meta" );
00218 content.setAttribute( "xmlns:office", "http://openoffice.org/2000/office" );
00219 content.setAttribute( "xmlns:xlink", "http://www.w3.org/1999/xlink" );
00220 content.setAttribute( "xmlns:dc", "http://purl.org/dc/elements/1.1/" );
00221 content.setAttribute( "xmlns:meta", "http://openoffice.org/2000/meta" );
00222 content.setAttribute( "office:version", "1.0" );
00223
00224 QDomNode meta = docmeta.createElement( "office:meta" );
00225
00226 QDomElement generator = docmeta.createElement( "meta:generator" );
00227 generator.appendChild( docmeta.createTextNode( "KPresenter 1.5" ) );
00228 meta.appendChild( generator );
00229
00230 QDomNode i = m_documentinfo.namedItem( "document-info" );
00231 if ( !i.isNull() )
00232 {
00233 QDomNode n = i.namedItem( "author" ).namedItem( "full-name" );
00234 if ( !n.isNull() )
00235 {
00236 QDomElement fullName = n.toElement();
00237 QDomElement creator = docmeta.createElement( "meta:initial-creator" );
00238 creator.appendChild( docmeta.createTextNode( fullName.text() ) );
00239 meta.appendChild( creator );
00240
00241 creator = docmeta.createElement( "meta:creator" );
00242 creator.appendChild( docmeta.createTextNode( fullName.text() ) );
00243 meta.appendChild( creator );
00244 }
00245 n = i.namedItem( "about" ).namedItem( "abstract" );
00246 if ( !n.isNull() )
00247 {
00248 QDomElement user = docmeta.createElement( "dc:description" );
00249 user.appendChild( n.firstChild() );
00250 meta.appendChild( user );
00251 }
00252 n = i.namedItem( "about" ).namedItem( "keyword" );
00253 if ( !n.isNull() )
00254 {
00255 QDomElement text = n.toElement();
00256 QDomElement key = docmeta.createElement( "meta:keywords" );
00257 QDomElement keyword = docmeta.createElement( "meta:keyword" );
00258 key.appendChild( keyword );
00259 keyword.appendChild( docmeta.createTextNode( text.text() ) );
00260 meta.appendChild( key );
00261 }
00262 n = i.namedItem( "about" ).namedItem( "subject" );
00263 if ( !n.isNull() )
00264 {
00265 QDomElement text = n.toElement();
00266 QDomElement subjet = docmeta.createElement( "dc:subject" );
00267 subjet.appendChild( docmeta.createTextNode( text.text() ) );
00268 meta.appendChild( subjet );
00269 }
00270 n = i.namedItem( "about" ).namedItem( "title" );
00271 if ( !n.isNull() )
00272 {
00273 QDomElement text = n.toElement();
00274 QDomElement title = docmeta.createElement( "dc:title" );
00275 title.appendChild( docmeta.createTextNode( text.text() ) );
00276 meta.appendChild( title );
00277 }
00278 }
00279
00280
00281
00282
00283
00284 content.appendChild( meta );
00285 docmeta.appendChild( content );
00286 }
00287
00288 void OoImpressExport::createDocumentStyles( QDomDocument & docstyles )
00289 {
00290 docstyles.appendChild( docstyles.createProcessingInstruction( "xml","version=\"1.0\" encoding=\"UTF-8\"" ) );
00291
00292 QDomElement content = docstyles.createElement( "office:document-content" );
00293 content.setAttribute( "xmlns:office", "http://openoffice.org/2000/office" );
00294 content.setAttribute( "xmlns:style", "http://openoffice.org/2000/style" );
00295 content.setAttribute( "xmlns:text", "http://openoffice.org/2000/text" );
00296 content.setAttribute( "xmlns:table", "http://openoffice.org/2000/table" );
00297 content.setAttribute( "xmlns:draw", "http://openoffice.org/2000/drawing" );
00298 content.setAttribute( "xmlns:fo", "http://www.w3.org/1999/XSL/Format" );
00299 content.setAttribute( "xmlns:xlink", "http://www.w3.org/1999/xlink" );
00300 content.setAttribute( "xmlns:number", "http://openoffice.org/2000/datastyle" );
00301 content.setAttribute( "xmlns:svg", "http://www.w3.org/2000/svg" );
00302 content.setAttribute( "xmlns:chart", "http://openoffice.org/2000/chart" );
00303 content.setAttribute( "xmlns:dr3d", "http://openoffice.org/2000/dr3d" );
00304 content.setAttribute( "xmlns:math", "http://www.w3.org/1998/Math/MathML" );
00305 content.setAttribute( "xmlns:form", "http://openoffice.org/2000/form" );
00306 content.setAttribute( "xmlns:script", "http://openoffice.org/2000/script" );
00307 content.setAttribute( "office:version", "1.0" );
00308
00309
00310 QDomElement styles = docstyles.createElement( "office:styles" );
00311 m_styleFactory.addOfficeStyles( docstyles, styles );
00312 content.appendChild( styles );
00313
00314 QDomElement automatic = docstyles.createElement( "office:automatic-styles" );
00315 m_styleFactory.addOfficeAutomatic( docstyles, automatic );
00316 content.appendChild( automatic );
00317
00318 QDomElement master = docstyles.createElement( "office:master-styles" );
00319 m_styleFactory.addOfficeMaster( docstyles, master );
00320 content.appendChild( master );
00321
00322 docstyles.appendChild( content );
00323 }
00324
00325 void OoImpressExport::createDocumentSettings( QDomDocument & docsetting )
00326 {
00327 docsetting.appendChild( docsetting.createProcessingInstruction( "xml","version=\"1.0\" encoding=\"UTF-8\"" ) );
00328
00329 QDomElement setting = docsetting.createElement( "office:document-settings" );
00330 setting.setAttribute( "xmlns:office", "http://openoffice.org/2000/office");
00331 setting.setAttribute( "xmlns:config", "http://openoffice.org/2001/config" );
00332 setting.setAttribute( "office:class", "presentation" );
00333 setting.setAttribute( "office:version", "1.0" );
00334
00335 QDomElement begin = docsetting.createElement( "office:settings" );
00336
00337 QDomElement configItem = docsetting.createElement("config:config-item-set" );
00338 configItem.setAttribute( "config:name", "view-settings" );
00339
00340 QDomElement mapIndexed = docsetting.createElement( "config:config-item-map-indexed" );
00341 mapIndexed.setAttribute("config:name", "Views" );
00342 configItem.appendChild( mapIndexed );
00343
00344
00345
00346 QDomElement mapItem = docsetting.createElement("config:config-item-map-entry" );
00347
00348 QDomElement attribute = docsetting.createElement("config:config-item" );
00349 attribute.setAttribute( "config:name", "SnapLinesDrawing" );
00350 attribute.setAttribute( "config:type", "string" );
00351 attribute.appendChild( docsetting.createTextNode( m_helpLine ) );
00352 mapItem.appendChild( attribute );
00353
00354
00355 attribute = docsetting.createElement("config:config-item" );
00356 attribute.setAttribute( "config:name", "IsSnapToGrid" );
00357 attribute.setAttribute( "config:type", "boolean" );
00358 attribute.appendChild( docsetting.createTextNode( m_snapToGrid ? "true" : "false" ) );
00359 mapItem.appendChild( attribute );
00360
00361 if ( m_gridX >=0 )
00362 {
00363 attribute = docsetting.createElement("config:config-item" );
00364 attribute.setAttribute( "config:name", "GridFineWidth" );
00365 attribute.setAttribute( "config:type", "int" );
00366 attribute.appendChild( docsetting.createTextNode( QString::number( ( int ) ( KoUnit::toMM( ( m_gridX ) )*100 ) ) ) );
00367 mapItem.appendChild( attribute );
00368 }
00369
00370 if ( m_gridY >=0 )
00371 {
00372 attribute = docsetting.createElement("config:config-item" );
00373 attribute.setAttribute( "config:name", "GridFineHeight" );
00374 attribute.setAttribute( "config:type", "int" );
00375 attribute.appendChild( docsetting.createTextNode( QString::number( ( int ) ( KoUnit::toMM( ( m_gridY ) )*100 ) ) ) );
00376 mapItem.appendChild( attribute );
00377 }
00378
00379 attribute = docsetting.createElement("config:config-item" );
00380 attribute.setAttribute( "config:name", "SelectedPage" );
00381 attribute.setAttribute( "config:type", "short" );
00382 attribute.appendChild( docsetting.createTextNode( QString::number( m_activePage ) ) );
00383 mapItem.appendChild( attribute );
00384
00385
00386 mapIndexed.appendChild( mapItem );
00387
00388 begin.appendChild( configItem );
00389
00390 setting.appendChild( begin );
00391
00392
00393 docsetting.appendChild( setting );
00394
00395 }
00396
00397 void OoImpressExport::createDocumentContent( QDomDocument & doccontent )
00398 {
00399 doccontent.appendChild( doccontent.createProcessingInstruction( "xml","version=\"1.0\" encoding=\"UTF-8\"" ) );
00400
00401 QDomElement content = doccontent.createElement( "office:document-content" );
00402 content.setAttribute( "xmlns:office", "http://openoffice.org/2000/office");
00403 content.setAttribute( "xmlns:style", "http://openoffice.org/2000/style" );
00404 content.setAttribute( "xmlns:text", "http://openoffice.org/2000/text" );
00405 content.setAttribute( "xmlns:table", "http://openoffice.org/2000/table" );
00406 content.setAttribute( "xmlns:draw", "http://openoffice.org/2000/drawing" );
00407 content.setAttribute( "xmlns:fo", "http://www.w3.org/1999/XSL/Format" );
00408 content.setAttribute( "xmlns:xlink", "http://www.w3.org/1999/xlink" );
00409 content.setAttribute( "xmlns:number", "http://openoffice.org/2000/datastyle" );
00410 content.setAttribute( "xmlns:svg", "http://www.w3.org/2000/svg" );
00411 content.setAttribute( "xmlns:chart", "http://openoffice.org/2000/chart" );
00412 content.setAttribute( "xmlns:dr3d", "http://openoffice.org/2000/dr3d" );
00413 content.setAttribute( "xmlns:math", "http://www.w3.org/1998/Math/MathML" );
00414 content.setAttribute( "xmlns:form", "http://openoffice.org/2000/form" );
00415 content.setAttribute( "xmlns:script", "http://openoffice.org/2000/script" );
00416 content.setAttribute( "xmlns:presentation", "http://openoffice.org/2000/presentation" );
00417 content.setAttribute( "office:class", "presentation" );
00418 content.setAttribute( "office:version", "1.0" );
00419
00420 QDomElement script = doccontent.createElement( "office:script" );
00421 content.appendChild( script );
00422
00423 m_styles = doccontent.createElement( "office:automatic-styles" );
00424 content.appendChild( m_styles );
00425
00426 QDomElement body = doccontent.createElement( "office:body" );
00427 exportBody( doccontent, body );
00428 content.appendChild( body );
00429
00430 doccontent.appendChild( content );
00431 }
00432
00433 void OoImpressExport::createDocumentManifest( QDomDocument & docmanifest )
00434 {
00435 docmanifest.appendChild( docmanifest.createProcessingInstruction( "xml","version=\"1.0\" encoding=\"UTF-8\"" ) );
00436
00437 QDomElement manifest = docmanifest.createElement( "manifest:manifest" );
00438 manifest.setAttribute( "xmlns:manifest", "http://openoffice.org/2001/manifest" );
00439
00440 QDomElement entry = docmanifest.createElement( "manifest:file-entry" );
00441 entry.setAttribute( "manifest:media-type", "application/vnd.sun.xml.impress" );
00442 entry.setAttribute( "manifest:full-path", "/" );
00443 manifest.appendChild( entry );
00444
00445 QMap<QString, QString>::Iterator it;
00446 for ( it = m_pictureLst.begin(); it != m_pictureLst.end(); ++it )
00447 {
00448 entry = docmanifest.createElement( "manifest:file-entry" );
00449 entry.setAttribute( "manifest:media-type", it.data() );
00450 entry.setAttribute( "manifest:full-path", it.key() );
00451 manifest.appendChild( entry );
00452 }
00453
00454 entry = docmanifest.createElement( "manifest:file-entry" );
00455 entry.setAttribute( "manifest:media-type", "text/xml" );
00456 entry.setAttribute( "manifest:full-path", "content.xml" );
00457 manifest.appendChild( entry );
00458
00459 entry = docmanifest.createElement( "manifest:file-entry" );
00460 entry.setAttribute( "manifest:media-type", "text/xml" );
00461 entry.setAttribute( "manifest:full-path", "styles.xml" );
00462 manifest.appendChild( entry );
00463
00464 entry = docmanifest.createElement( "manifest:file-entry" );
00465 entry.setAttribute( "manifest:media-type", "text/xml" );
00466 entry.setAttribute( "manifest:full-path", "meta.xml" );
00467 manifest.appendChild( entry );
00468
00469 entry = docmanifest.createElement( "manifest:file-entry" );
00470 entry.setAttribute( "manifest:media-type", "text/xml" );
00471 entry.setAttribute( "manifest:full-path", "settings.xml" );
00472 manifest.appendChild( entry );
00473
00474 docmanifest.appendChild( manifest );
00475 }
00476
00477 QString OoImpressExport::pictureKey( QDomElement &elem )
00478 {
00479
00480 int year=1970, month=1, day=1;
00481 int hour=0, minute=0, second=0, msec=0;
00482 if ( elem.tagName() == "KEY" )
00483 {
00484 if( elem.hasAttribute( "year" ) )
00485 year=elem.attribute( "year" ).toInt();
00486 if( elem.hasAttribute( "month" ) )
00487 month=elem.attribute( "month" ).toInt();
00488 if( elem.hasAttribute( "day" ) )
00489 day=elem.attribute( "day" ).toInt();
00490 if( elem.hasAttribute( "hour" ) )
00491 hour=elem.attribute( "hour" ).toInt();
00492 if( elem.hasAttribute( "minute" ) )
00493 minute=elem.attribute( "minute" ).toInt();
00494 if( elem.hasAttribute( "second" ) )
00495 second=elem.attribute( "second" ).toInt();
00496 if( elem.hasAttribute( "msec" ) )
00497 msec=elem.attribute( "msec" ).toInt();
00498 }
00499 QDateTime key;
00500 key.setDate( QDate( year, month, day ) );
00501 key.setTime( QTime( hour, minute, second, msec ) );
00502 return key.toString();
00503 }
00504
00505 void OoImpressExport::createPictureList( QDomNode &pictures )
00506 {
00507 pictures = pictures.firstChild();
00508 for( ; !pictures.isNull(); pictures = pictures.nextSibling() )
00509 {
00510 if ( pictures.isElement() )
00511 {
00512 QDomElement element = pictures.toElement();
00513 if ( element.tagName() == "KEY" )
00514 {
00515
00516 m_kpresenterPictureLst.insert( pictureKey( element ), element.attribute( "name" ) );
00517 }
00518 else
00519 kdDebug(30518)<<" Tag not recognize :"<<element.tagName()<<endl;
00520 }
00521 }
00522 }
00523
00524 void OoImpressExport::createAttribute( QDomNode &attributeValue )
00525 {
00526 QDomElement elem = attributeValue.toElement();
00527 if(elem.hasAttribute("activePage"))
00528 m_activePage=elem.attribute("activePage").toInt();
00529 if(elem.hasAttribute("gridx"))
00530 m_gridX = elem.attribute("gridx").toDouble();
00531 if(elem.hasAttribute("gridy"))
00532 m_gridY = elem.attribute("gridy").toDouble();
00533 if(elem.hasAttribute("snaptogrid"))
00534 m_snapToGrid = (bool)elem.attribute("snaptogrid").toInt();
00535 }
00536
00537 void OoImpressExport::createHelpLine( QDomNode &helpline )
00538 {
00539 helpline = helpline.firstChild();
00540 QDomElement helplines;
00541 for( ; !helpline.isNull(); helpline = helpline.nextSibling() )
00542 {
00543 if ( helpline.isElement() )
00544 {
00545 helplines = helpline.toElement();
00546 if ( helplines.tagName()=="Vertical" )
00547 {
00548 int tmpX = ( int ) ( KoUnit::toMM( helplines.attribute("value").toDouble() )*100 );
00549 m_helpLine+="V"+QString::number( tmpX );
00550 }
00551 else if ( helplines.tagName()=="Horizontal" )
00552 {
00553 int tmpY = ( int ) ( KoUnit::toMM( helplines.attribute("value").toDouble() )*100 );
00554 m_helpLine+="H"+QString::number( tmpY );
00555 }
00556 else if ( helplines.tagName()=="HelpPoint" )
00557 {
00558 QString str( "P%1,%2" );
00559 int tmpX = ( int ) ( KoUnit::toMM( helplines.attribute("posX").toDouble() )*100 );
00560 int tmpY = ( int ) ( KoUnit::toMM( helplines.attribute("posY").toDouble() )*100 );
00561 m_helpLine+=str.arg( QString::number( tmpX ) ).arg( QString::number( tmpY ) );
00562 }
00563 }
00564 }
00565
00566 }
00567
00568
00569 void OoImpressExport::exportBody( QDomDocument & doccontent, QDomElement & body )
00570 {
00571 QDomNode doc = m_maindoc.namedItem( "DOC" );
00572 QDomNode paper = doc.namedItem( "PAPER" );
00573 QDomNode background = doc.namedItem( "BACKGROUND" );
00574 QDomNode header = doc.namedItem( "HEADER" );
00575 QDomNode footer = doc.namedItem( "FOOTER" );
00576 QDomNode titles = doc.namedItem( "PAGETITLES" );
00577 QDomNode notes = doc.namedItem( "PAGENOTES" );
00578 QDomNode objects = doc.namedItem( "OBJECTS" );
00579 QDomNode pictures = doc.namedItem( "PICTURES" );
00580 QDomNode sounds = doc.namedItem( "SOUNDS" );
00581 QDomNode helpline = doc.namedItem( "HELPLINES" );
00582 QDomNode attributeValue = doc.namedItem( "ATTRIBUTES" );
00583 QDomNode infiniLoop = doc.namedItem( "INFINITLOOP" );
00584 QDomNode manualSwitch = doc.namedItem( "MANUALSWITCH" );
00585 QDomNode customSlideShow = doc.namedItem( "CUSTOMSLIDESHOWCONFIG" );
00586 QDomNode customSlideShowDefault = doc.namedItem( "DEFAULTCUSTOMSLIDESHOWNAME" );
00587
00588 QDomNode bgpage = background.firstChild();
00589
00590 createPictureList( pictures );
00591
00592 createHelpLine( helpline );
00593
00594 createAttribute( attributeValue );
00595
00596
00597 QDomElement p = paper.toElement();
00598 m_masterPageStyle = m_styleFactory.createPageMasterStyle( p );
00599 m_pageHeight = p.attribute( "ptHeight" ).toFloat();
00600
00601 m_currentPage = 1;
00602
00603
00604 QDomNode note = notes.firstChild();
00605 for ( QDomNode title = titles.firstChild(); !title.isNull() && !note.isNull();
00606 title = title.nextSibling(), note = note.nextSibling() )
00607 {
00608
00609
00610 QDomElement bg = bgpage.toElement();
00611 QString ps = m_styleFactory.createPageStyle( bg );
00612 bgpage = bgpage.nextSibling();
00613
00614 QDomElement t = title.toElement();
00615 QDomElement drawPage = doccontent.createElement( "draw:page" );
00616 drawPage.setAttribute( "draw:name", t.attribute( "title" ) );
00617 drawPage.setAttribute( "draw:style-name", ps );
00618 drawPage.setAttribute( "draw:id", m_currentPage );
00619 drawPage.setAttribute( "draw:master-page-name", m_masterPageStyle );
00620
00621 appendObjects( doccontent, objects, drawPage );
00622
00623 QDomElement noteElement = note.toElement();
00624 appendNote( doccontent, noteElement, drawPage );
00625 body.appendChild( drawPage );
00626 m_currentPage++;
00627 }
00628 int infiniLoopValue = -1;
00629 int manualSwitchValue = -1;
00630 if ( !infiniLoop.isNull() && infiniLoop.toElement().hasAttribute( "value" ))
00631 {
00632 bool ok;
00633 int val = infiniLoop.toElement().attribute( "value" ).toInt( &ok );
00634 if ( ok )
00635 infiniLoopValue = val;
00636 }
00637 if ( !manualSwitch.isNull() && manualSwitch.toElement().hasAttribute( "value" ))
00638 {
00639 bool ok;
00640 int val = manualSwitch.toElement().attribute( "value" ).toInt( &ok );
00641 if ( ok )
00642 manualSwitchValue = val;
00643 }
00644 if ( infiniLoopValue != -1 || manualSwitchValue != -1 || !customSlideShowDefault.isNull())
00645 {
00646 QDomElement settings = doccontent.createElement( "presentation:settings" );
00647 if ( infiniLoopValue !=-1 )
00648 settings.setAttribute( "presentation:force-manual", ( manualSwitchValue==1 ) ? "true" : "false" );
00649 if ( manualSwitchValue != -1 )
00650 settings.setAttribute( "presentation:endless", ( infiniLoopValue==1 ) ? "true": "false" );
00651 if ( !customSlideShowDefault.isNull() )
00652 settings.setAttribute( "presentation:show", customSlideShowDefault.toElement().attribute( "name" ) );
00653
00654 if ( !customSlideShow.isNull() )
00655 {
00656 for ( QDomNode customPage = customSlideShow.firstChild(); !customPage.isNull();
00657 customPage = customPage.nextSibling() )
00658 {
00659 QDomElement show = customPage.toElement();
00660 if ( !show.isNull() && show.tagName()=="CUSTOMSLIDESHOW" )
00661 {
00662 QDomElement showElement = doccontent.createElement( "presentation:show" );
00663 showElement.setAttribute( "presentation:name",show.attribute( "name" ) );
00664 showElement.setAttribute( "presentation:pages",show.attribute( "pages" ) );
00665 settings.appendChild( showElement );
00666 }
00667 }
00668 }
00669 body.appendChild( settings );
00670 }
00671 }
00672
00673
00674 void OoImpressExport::appendObjects(QDomDocument & doccontent, QDomNode &objects, QDomElement &drawPage)
00675 {
00676
00677
00678 for ( QDomNode object = objects.firstChild(); !object.isNull();
00679 object = object.nextSibling() )
00680 {
00681 QDomElement o = object.toElement();
00682
00683 QDomElement orig = o.namedItem( "ORIG" ).toElement();
00684 float y = orig.attribute( "y" ).toFloat();
00685
00686 if ( y < m_pageHeight * ( m_currentPage - 1 ) ||
00687 y >= m_pageHeight * m_currentPage )
00688 continue;
00689
00690 switch( o.attribute( "type" ).toInt() )
00691 {
00692 case 0:
00693 appendPicture( doccontent, o, drawPage );
00694 break;
00695 case 1:
00696 appendLine( doccontent, o, drawPage );
00697 break;
00698 case 2:
00699 appendRectangle( doccontent, o, drawPage );
00700 break;
00701 case 3:
00702 appendEllipse( doccontent, o, drawPage );
00703 break;
00704 case 4:
00705 appendTextbox( doccontent, o, drawPage );
00706 break;
00707 case 5:
00708 kdDebug(30518)<<" autoform not implemented\n";
00709 break;
00710 case 6:
00711 kdDebug(30518)<<" clipart not implemented\n";
00712 break;
00713 case 8:
00714 appendEllipse( doccontent, o, drawPage, true );
00715 break;
00716 case 9:
00717 kdDebug(30518)<<" part object not implemented \n";
00718 break;
00719 case 10:
00720 appendGroupObject( doccontent, o, drawPage );
00721 break;
00722 case 11:
00723 kdDebug(30518)<<" free hand not implemented\n";
00724 break;
00725 case 12:
00726 appendPolyline( doccontent, o, drawPage );
00727 break;
00728 case 13:
00729 case 14:
00730
00731
00732 break;
00733 case 15:
00734 case 16:
00735 appendPolyline( doccontent, o, drawPage, true );
00736 break;
00737 }
00738 ++m_objectIndex;
00739 }
00740
00741 }
00742
00743 void OoImpressExport::appendGroupObject( QDomDocument & doc, QDomElement & source, QDomElement & target )
00744 {
00745 QDomElement groupElement = doc.createElement( "draw:g" );
00746 QDomNode objects = source.namedItem( "OBJECTS" );
00747 appendObjects( doc, objects, groupElement);
00748 target.appendChild( groupElement );
00749 }
00750
00751 void OoImpressExport::appendNote( QDomDocument & doc, QDomElement & source, QDomElement & target )
00752 {
00753 QString noteText = source.attribute("note");
00754
00755 if ( noteText.isEmpty() )
00756 return;
00757 QDomElement noteElement = doc.createElement( "presentation:notes" );
00758 QDomElement noteTextBox = doc.createElement( "draw:text-box" );
00759
00760
00761
00762
00763 QStringList text = QStringList::split( "\n", noteText );
00764 for ( QStringList::Iterator it = text.begin(); it != text.end(); ++it ) {
00765 QDomElement tmp = doc.createElement( "text:p" );
00766 tmp.appendChild( doc.createTextNode( *it ) );
00767 noteTextBox.appendChild( tmp );
00768 }
00769 noteElement.appendChild( noteTextBox );
00770 target.appendChild( noteElement );
00771 }
00772
00773 void OoImpressExport::appendTextbox( QDomDocument & doc, QDomElement & source, QDomElement & target )
00774 {
00775 QDomElement textbox = doc.createElement( "draw:text-box" );
00776
00777 QDomNode textobject = source.namedItem( "TEXTOBJ" );
00778
00779
00780 QString gs = m_styleFactory.createGraphicStyle( source );
00781 textbox.setAttribute( "draw:style-name", gs );
00782
00783
00784 set2DGeometry( source, textbox );
00785
00786
00787 for ( QDomNode paragraph = textobject.firstChild(); !paragraph.isNull();
00788 paragraph = paragraph.nextSibling() )
00789 {
00790 QDomElement p = paragraph.toElement();
00791 appendParagraph( doc, p, textbox );
00792 }
00793
00794 target.appendChild( textbox );
00795 }
00796
00797 void OoImpressExport::appendParagraph( QDomDocument & doc, QDomElement & source, QDomElement & target )
00798 {
00799 QDomElement paragraph = doc.createElement( "text:p" );
00800
00801
00802 QString ps = m_styleFactory.createParagraphStyle( source );
00803 paragraph.setAttribute( "text:style-name", ps );
00804
00805
00806 for ( QDomNode text = source.firstChild(); !text.isNull();
00807 text = text.nextSibling() )
00808 {
00809 if ( text.nodeName() == "TEXT" )
00810 {
00811 QDomElement t = text.toElement();
00812 appendText( doc, t, paragraph );
00813 }
00814 }
00815
00816
00817 QDomNode counter = source.namedItem( "COUNTER" );
00818 if ( !counter.isNull() )
00819 {
00820 QDomElement c = counter.toElement();
00821 int type = c.attribute( "type" ).toInt();
00822
00823 int level = 1;
00824 if ( c.hasAttribute( "depth" ) )
00825 level = c.attribute( "depth" ).toInt() + 1;
00826
00827 QDomElement endOfList = target;
00828 for ( int l = 0; l < level; l++ )
00829 {
00830 QDomElement list;
00831 if ( type == 1 )
00832 {
00833 list = doc.createElement( "text:ordered-list" );
00834 list.setAttribute( "text:continue-numbering", "true" );
00835 }
00836 else
00837 list = doc.createElement( "text:unordered-list" );
00838
00839 if ( l == 0 )
00840 {
00841
00842 QString ls = m_styleFactory.createListStyle( c );
00843 list.setAttribute( "text:style-name", ls );
00844 }
00845
00846 QDomElement item = doc.createElement( "text:list-item" );
00847 list.appendChild( item );
00848 endOfList.appendChild( list );
00849 endOfList = item;
00850 }
00851
00852 endOfList.appendChild( paragraph );
00853 }
00854 else
00855 target.appendChild( paragraph );
00856 }
00857
00858 void OoImpressExport::appendText( QDomDocument & doc, QDomElement & source, QDomElement & target )
00859 {
00860 QDomElement textspan = doc.createElement( "text:span" );
00861
00862
00863 QString ts = m_styleFactory.createTextStyle( source );
00864 textspan.setAttribute( "text:style-name", ts );
00865
00866 textspan.appendChild( doc.createTextNode( source.text() ) );
00867 target.appendChild( textspan );
00868 }
00869
00870 void OoImpressExport::appendPicture( QDomDocument & doc, QDomElement & source, QDomElement & target )
00871 {
00872 QDomElement image = doc.createElement( "draw:image" );
00873
00874
00875 QString gs = m_styleFactory.createGraphicStyle( source );
00876 image.setAttribute( "draw:style-name", gs );
00877 QDomElement key = source.namedItem( "KEY" ).toElement();
00878
00879 QString pictureName = QString( "Picture/Picture%1" ).arg( m_pictureIndex );
00880
00881 image.setAttribute( "xlink:type", "simple" );
00882 image.setAttribute( "xlink:show", "embed" );
00883 image.setAttribute( "xlink:actuate", "onLoad");
00884
00885 if ( !key.isNull() )
00886 {
00887 QString str = pictureKey( key );
00888 QString returnstr = m_kpresenterPictureLst[str];
00889 const int pos=returnstr.findRev('.');
00890 if (pos!=-1)
00891 {
00892 const QString extension( returnstr.mid(pos+1) );
00893 pictureName +="."+extension;
00894 }
00895
00896 if ( m_storeinp->open( returnstr ) )
00897 {
00898 if ( m_storeout->open( pictureName ) )
00899 {
00900 QByteArray data(8*1024);
00901 uint total = 0;
00902 for ( int block = 0; ( block = m_storeinp->read(data.data(), data.size()) ) > 0;
00903 total += block )
00904 m_storeout->write(data.data(), data.size());
00905 m_storeout->close();
00906 m_storeinp->close();
00907 }
00908 }
00909 }
00910 image.setAttribute( "xlink:href", "#" + pictureName );
00911
00912
00913 set2DGeometry( source, image );
00914 target.appendChild( image );
00915
00916 m_pictureLst.insert( pictureName , "image/png" );
00917
00918 ++m_pictureIndex;
00919 }
00920
00921
00922 void OoImpressExport::appendLine( QDomDocument & doc, QDomElement & source, QDomElement & target )
00923 {
00924 QDomElement line = doc.createElement( "draw:line" );
00925
00926
00927 QString gs = m_styleFactory.createGraphicStyle( source );
00928 line.setAttribute( "draw:style-name", gs );
00929
00930
00931 setLineGeometry( source, line );
00932
00933 target.appendChild( line );
00934 }
00935
00936 void OoImpressExport::appendRectangle( QDomDocument & doc, QDomElement & source, QDomElement & target )
00937 {
00938 QDomElement rectangle = doc.createElement( "draw:rect" );
00939
00940
00941 QString gs = m_styleFactory.createGraphicStyle( source );
00942 rectangle.setAttribute( "draw:style-name", gs );
00943
00944
00945 set2DGeometry( source, rectangle );
00946
00947 target.appendChild( rectangle );
00948 }
00949
00950 void OoImpressExport::appendPolyline( QDomDocument & doc, QDomElement & source, QDomElement & target, bool _poly)
00951 {
00952 QDomElement polyline = doc.createElement( _poly ? "draw:polygon" : "draw:polyline" );
00953
00954
00955 QString gs = m_styleFactory.createGraphicStyle( source );
00956 polyline.setAttribute( "draw:style-name", gs );
00957
00958
00959 set2DGeometry( source, polyline, false, true );
00960
00961 target.appendChild( polyline );
00962 }
00963
00964 void OoImpressExport::appendEllipse( QDomDocument & doc, QDomElement & source, QDomElement & target, bool pieObject )
00965 {
00966 QDomElement size = source.namedItem( "SIZE" ).toElement();
00967
00968 double width = size.attribute( "width" ).toDouble();
00969 double height = size.attribute( "height" ).toDouble();
00970
00971 QDomElement ellipse = doc.createElement( (width == height) ? "draw:circle" : "draw:ellipse" );
00972
00973
00974 QString gs = m_styleFactory.createGraphicStyle( source );
00975 ellipse.setAttribute( "draw:style-name", gs );
00976
00977
00978 set2DGeometry( source, ellipse, pieObject );
00979
00980 target.appendChild( ellipse );
00981 }
00982
00983 void OoImpressExport::set2DGeometry( QDomElement & source, QDomElement & target, bool pieObject, bool multiPoint )
00984 {
00985 QDomElement orig = source.namedItem( "ORIG" ).toElement();
00986 QDomElement size = source.namedItem( "SIZE" ).toElement();
00987 QDomElement name = source.namedItem( "OBJECTNAME").toElement();
00988 float y = orig.attribute( "y" ).toFloat();
00989 y -= m_pageHeight * ( m_currentPage - 1 );
00990
00991 QDomElement angle = source.namedItem( "ANGLE").toElement();
00992 if ( !angle.isNull() )
00993 {
00994 QString returnAngle = rotateValue( angle.attribute( "value" ).toDouble() );
00995 if ( !returnAngle.isEmpty() )
00996 target.setAttribute("draw:transform",returnAngle );
00997 }
00998
00999 target.setAttribute( "draw:id", QString::number( m_objectIndex ) );
01000 target.setAttribute( "svg:x", StyleFactory::toCM( orig.attribute( "x" ) ) );
01001 target.setAttribute( "svg:y", QString( "%1cm" ).arg( KoUnit::toCM( y ) ) );
01002 target.setAttribute( "svg:width", StyleFactory::toCM( size.attribute( "width" ) ) );
01003 target.setAttribute( "svg:height", StyleFactory::toCM( size.attribute( "height" ) ) );
01004 QString nameStr = name.attribute("objectName");
01005 if( !nameStr.isEmpty() )
01006 target.setAttribute( "draw:name", nameStr );
01007 if ( pieObject )
01008 {
01009 QDomElement pie = source.namedItem( "PIETYPE").toElement();
01010 if( !pie.isNull() )
01011 {
01012 int typePie = pie.attribute("value").toInt();
01013 switch( typePie )
01014 {
01015 case 0:
01016 target.setAttribute( "draw:kind", "section");
01017 break;
01018 case 1:
01019 target.setAttribute( "draw:kind", "arc");
01020 break;
01021 case 2:
01022 target.setAttribute( "draw:kind", "cut");
01023 break;
01024 default:
01025 kdDebug(30518)<<" type unknown : "<<typePie<<endl;
01026 break;
01027 }
01028 }
01029 else
01030 target.setAttribute( "draw:kind", "section");
01031 QDomElement pieAngle = source.namedItem( "PIEANGLE").toElement();
01032 int startangle = 45;
01033 if( !pieAngle.isNull() )
01034 {
01035 startangle = (pieAngle.attribute("value").toInt())/16;
01036 target.setAttribute( "draw:start-angle", startangle);
01037 }
01038 else
01039 {
01040
01041 target.setAttribute( "draw:start-angle", 45 );
01042 }
01043 QDomElement pieLength = source.namedItem( "PIELENGTH").toElement();
01044 if( !pieLength.isNull() )
01045 {
01046 int value = pieLength.attribute("value").toInt();
01047 value = value /16;
01048 value = value + startangle;
01049 target.setAttribute( "draw:end-angle", value );
01050 }
01051 else
01052 {
01053
01054
01055 target.setAttribute( "draw:end-angle", (90+startangle) );
01056 }
01057 }
01058 if ( multiPoint )
01059 {
01060
01061 QDomElement point = source.namedItem( "POINTS" ).toElement();
01062 if ( !point.isNull() ) {
01063 QDomElement elemPoint = point.firstChild().toElement();
01064 QString listOfPoint;
01065 int maxX=0;
01066 int maxY=0;
01067 while ( !elemPoint.isNull() ) {
01068 if ( elemPoint.tagName() == "Point" ) {
01069 int tmpX = 0;
01070 int tmpY = 0;
01071 if( elemPoint.hasAttribute( "point_x" ) )
01072 tmpX = ( int ) ( KoUnit::toMM( elemPoint.attribute( "point_x" ).toDouble() )*100 );
01073 if( elemPoint.hasAttribute( "point_y" ) )
01074 tmpY = ( int ) ( KoUnit::toMM(elemPoint.attribute( "point_y" ).toDouble() )*100 );
01075 if ( !listOfPoint.isEmpty() )
01076 listOfPoint += QString( " %1,%2" ).arg( tmpX ).arg( tmpY );
01077 else
01078 listOfPoint = QString( "%1,%2" ).arg( tmpX ).arg( tmpY );
01079 maxX = QMAX( maxX, tmpX );
01080 maxY = QMAX( maxY, tmpY );
01081 }
01082 elemPoint = elemPoint.nextSibling().toElement();
01083 }
01084 target.setAttribute( "draw:points", listOfPoint );
01085 target.setAttribute( "svg:viewBox", QString( "0 0 %1 %2" ).arg( maxX ).arg( maxY ) );
01086 }
01087 }
01088 }
01089
01090 QString OoImpressExport::rotateValue( double val )
01091 {
01092 QString str;
01093 if ( val!=0.0 )
01094 {
01095 double value = -1 * ( ( double )val* M_PI )/180.0;
01096 str=QString( "rotate (%1)" ).arg( value );
01097 }
01098 return str;
01099 }
01100
01101
01102 void OoImpressExport::setLineGeometry( QDomElement & source, QDomElement & target )
01103 {
01104 QDomElement orig = source.namedItem( "ORIG" ).toElement();
01105 QDomElement size = source.namedItem( "SIZE" ).toElement();
01106 QDomElement linetype = source.namedItem( "LINETYPE" ).toElement();
01107 QDomElement name = source.namedItem( "OBJECTNAME").toElement();
01108 QDomElement angle = source.namedItem( "ANGLE").toElement();
01109 if ( !angle.isNull() )
01110 {
01111 QString returnAngle = rotateValue( angle.attribute( "value" ).toDouble() );
01112 if ( !returnAngle.isEmpty() )
01113 target.setAttribute("draw:transform",returnAngle );
01114 }
01115 float x1 = orig.attribute( "x" ).toFloat();
01116 float y1 = orig.attribute( "y" ).toFloat();
01117 float x2 = size.attribute( "width" ).toFloat();
01118 float y2 = size.attribute( "height" ).toFloat();
01119 int type = 0;
01120 if ( !linetype.isNull() )
01121 type = linetype.attribute( "value" ).toInt();
01122 y1 -= m_pageHeight * ( m_currentPage - 1 );
01123 x2 += x1;
01124 y2 += y1;
01125
01126 target.setAttribute( "draw:id", QString::number( m_objectIndex ) );
01127 QString xpos1 = StyleFactory::toCM( orig.attribute( "x" ) );
01128 QString xpos2 = QString( "%1cm" ).arg( KoUnit::toCM( x2 ) );
01129
01130 if ( type == 0 )
01131 {
01132 target.setAttribute( "svg:y1", QString( "%1cm" ).arg( KoUnit::toCM( y2/2.0 ) ) );
01133 target.setAttribute( "svg:y2", QString( "%1cm" ).arg( KoUnit::toCM( y2/2.0 ) ) );
01134 }
01135 else if ( type == 1 )
01136 {
01137 target.setAttribute( "svg:y1", QString( "%1cm" ).arg( KoUnit::toCM( y1 ) ) );
01138 target.setAttribute( "svg:y2", QString( "%1cm" ).arg( KoUnit::toCM( y2 ) ) );
01139 xpos1 = QString( "%1cm" ).arg( KoUnit::toCM( x1/2.0 ) );
01140 xpos2 = xpos1;
01141 }
01142 else if ( type == 3 )
01143 {
01144 target.setAttribute( "svg:y1", QString( "%1cm" ).arg( KoUnit::toCM( y2 ) ) );
01145 target.setAttribute( "svg:y2", QString( "%1cm" ).arg( KoUnit::toCM( y1 ) ) );
01146 }
01147 else
01148 {
01149 target.setAttribute( "svg:y1", QString( "%1cm" ).arg( KoUnit::toCM( y1 ) ) );
01150 target.setAttribute( "svg:y2", QString( "%1cm" ).arg( KoUnit::toCM( y2 ) ) );
01151 }
01152 target.setAttribute( "svg:x1", xpos1 );
01153 target.setAttribute( "svg:x2", xpos2 );
01154
01155 QString nameStr = name.attribute("objectName");
01156 if( !nameStr.isEmpty() )
01157 target.setAttribute( "draw:name", nameStr );
01158 }
01159
01160 #include "ooimpressexport.moc"