lib Library API Documentation

kooasiscontext.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2004 David Faure <faure@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017    Boston, MA 02111-1307, USA.
00018 */
00019 
00020 #include "kooasiscontext.h"
00021 #include <koOasisStyles.h>
00022 #include <koOasisStore.h>
00023 #include <koxmlns.h>
00024 #include <koxmlwriter.h>
00025 #include <kdebug.h>
00026 #include <kodom.h>
00027 
00028 KoOasisContext::KoOasisContext( KoDocument* doc, KoVariableCollection& varColl,
00029                                 KoOasisStyles& styles, KoStore* store )
00030     : m_doc( doc ), m_store( store ), m_varColl( varColl ), m_styles( styles ),
00031       m_cursorTextParagraph( 0 )
00032 {
00033     // Ideally this should be done by KoDocument and passed as argument here...
00034     KoOasisStore oasisStore( store );
00035     QString dummy;
00036     (void)oasisStore.loadAndParse( "tar:/META-INF/manifest.xml", m_manifestDoc, dummy );
00037 }
00038 
00039 void KoOasisContext::fillStyleStack( const QDomElement& object, const char* nsURI, const char* attrName )
00040 {
00041     // find all styles associated with an object and push them on the stack
00042     // OoImpressImport has more tests here, but I don't think they're relevant to OoWriterImport
00043     // ### TODO check the above comment, now that things are in kotext...
00044     if ( object.hasAttributeNS( nsURI, attrName ) ) {
00045         const QString styleName = object.attributeNS( nsURI, attrName, QString::null );
00046         const QDomElement* style = m_styles.styles()[styleName];
00047         if ( style )
00048             addStyles( style );
00049         else
00050             kdWarning(32500) << "fillStyleStack: no style named " << styleName << " found." << endl;
00051     }
00052 }
00053 
00054 void KoOasisContext::addStyles( const QDomElement* style )
00055 {
00056     Q_ASSERT( style );
00057     if ( !style ) return;
00058     // this recursive function is necessary as parent styles can have parents themselves
00059     if ( style->hasAttributeNS( KoXmlNS::style, "parent-style-name" ) ) {
00060         const QString parentStyleName = style->attributeNS( KoXmlNS::style, "parent-style-name", QString::null );
00061         QDomElement* parentStyle = m_styles.styles()[ parentStyleName ];
00062         if ( parentStyle )
00063             addStyles( parentStyle );
00064         else
00065             kdWarning(32500) << "Parent style not found: " << parentStyleName << endl;
00066     }
00067     else {
00068         QString family = style->attributeNS( KoXmlNS::style, "family", QString::null );
00069         if ( !family.isEmpty() ) {
00070             QDomElement* def = m_styles.defaultStyle( family );
00071             if ( def ) { // on top of all, the default style for this family
00072                 //kdDebug(32500) << "pushing default style " << style->attributeNS( KoXmlNS::style, "name", QString::null ) << endl;
00073                 m_styleStack.push( *def );
00074             }
00075         }
00076     }
00077 
00078     //kdDebug(32500) << "pushing style " << style->attributeNS( KoXmlNS::style, "name", QString::null ) << endl;
00079     m_styleStack.push( *style );
00080 }
00081 
00082 static QDomElement findListLevelStyle( const QDomElement& fullListStyle, int level )
00083 {
00084     for ( QDomNode n = fullListStyle.firstChild(); !n.isNull(); n = n.nextSibling() )
00085     {
00086        const QDomElement listLevelItem = n.toElement();
00087        if ( listLevelItem.attributeNS( KoXmlNS::text, "level", QString::null ).toInt() == level )
00088            return listLevelItem;
00089     }
00090     return QDomElement();
00091 }
00092 
00093 bool KoOasisContext::pushListLevelStyle( const QString& listStyleName, int level )
00094 {
00095     QDomElement* fullListStyle = m_styles.listStyles()[listStyleName];
00096     if ( !fullListStyle ) {
00097         kdWarning(32500) << "List style " << listStyleName << " not found!" << endl;
00098         return false;
00099     }
00100     else
00101         return pushListLevelStyle( listStyleName, *fullListStyle, level );
00102 }
00103 
00104 bool KoOasisContext::pushOutlineListLevelStyle( int level )
00105 {
00106     QDomElement outlineStyle = KoDom::namedItemNS( m_styles.officeStyle(), KoXmlNS::text, "outline-style" );
00107     Q_ASSERT( !outlineStyle.isNull() );
00108     return pushListLevelStyle( "<outline-style>", outlineStyle, level );
00109 }
00110 
00111 bool KoOasisContext::pushListLevelStyle( const QString& listStyleName, // for debug only
00112                                          const QDomElement& fullListStyle, int level )
00113 {
00114     // Find applicable list-level-style for level
00115     int i = level;
00116     QDomElement listLevelStyle;
00117     while ( i > 0 && listLevelStyle.isNull() ) {
00118         listLevelStyle = findListLevelStyle( fullListStyle, i );
00119         --i;
00120     }
00121     if ( listLevelStyle.isNull() ) {
00122         kdWarning(32500) << "List level style for level " << level << " in list style " << listStyleName << " not found!" << endl;
00123         return false;
00124     }
00125     //kdDebug(32500) << "Pushing list-level-style from list-style " << listStyleName << " level " << level << endl;
00126     m_listStyleStack.push( listLevelStyle );
00127     return true;
00128 }
00129 
00130 void KoOasisContext::setCursorPosition( KoTextParag* cursorTextParagraph,
00131                                         int cursorTextIndex )
00132 {
00133     m_cursorTextParagraph = cursorTextParagraph;
00134     m_cursorTextIndex = cursorTextIndex;
00135 }
00136 
00137 KoOasisContext::~KoOasisContext()
00138 {
00139 }
00140 
00142 
00143 KoSavingContext::KoSavingContext( KoGenStyles& mainStyles, KoVariableSettings* settings, bool hasColumns, SavingMode savingMode )
00144     : m_mainStyles( mainStyles ),
00145       m_savingMode( savingMode ),
00146       m_cursorTextParagraph( 0 ),
00147       m_variableSettings( settings ),
00148       m_hasColumns( hasColumns )
00149 {
00150 }
00151 
00152 
00153 KoSavingContext::~KoSavingContext()
00154 {
00155 }
00156 
00157 void KoSavingContext::setCursorPosition( KoTextParag* cursorTextParagraph,
00158                                          int cursorTextIndex )
00159 {
00160     m_cursorTextParagraph = cursorTextParagraph;
00161     m_cursorTextIndex = cursorTextIndex;
00162 }
00163 
00164 void KoSavingContext::addFontFace( const QString& fontName )
00165 {
00166     m_fontFaces[fontName] = true;
00167 }
00168 
00169 void KoSavingContext::writeFontFaces( KoXmlWriter& writer )
00170 {
00171     writer.startElement( "office:font-face-decls" );
00172     const QStringList fontFaces = m_fontFaces.keys();
00173     for ( QStringList::const_iterator ffit = fontFaces.begin(), ffend = fontFaces.end() ; ffit != ffend ; ++ffit ) {
00174         writer.startElement( "style:font-face" );
00175         writer.addAttribute( "style:name", *ffit );
00176         writer.addAttribute( "svg:font-family", *ffit );
00177         // TODO style:font-family-generic
00178         // TODO style:font-pitch
00179         writer.endElement(); // style:font-face
00180     }
00181     writer.endElement(); // office:font-face-decls
00182 }
KDE Logo
This file is part of the documentation for lib Library Version 1.4.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Feb 13 09:40:02 2006 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003