F:/KPlato/koffice/libs/kotext/KoOasisContext.cpp

Aller à la documentation de ce fichier.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2004-2006 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., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, 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     : KoOasisLoadingContext( doc, styles, store ),
00031       m_varColl( varColl ),
00032       m_cursorTextParagraph( 0 )
00033 {
00034 }
00035 
00036 static QDomElement findListLevelStyle( const QDomElement& fullListStyle, int level )
00037 {
00038     for ( QDomNode n = fullListStyle.firstChild(); !n.isNull(); n = n.nextSibling() )
00039     {
00040        const QDomElement listLevelItem = n.toElement();
00041        if ( listLevelItem.attributeNS( KoXmlNS::text, "level", QString::null ).toInt() == level )
00042            return listLevelItem;
00043     }
00044     return QDomElement();
00045 }
00046 
00047 bool KoOasisContext::pushListLevelStyle( const QString& listStyleName, int level )
00048 {
00049     QDomElement* fullListStyle = oasisStyles().listStyles()[listStyleName];
00050     if ( !fullListStyle ) {
00051         kWarning(32500) << "List style " << listStyleName << " not found!" << endl;
00052         return false;
00053     }
00054     else
00055         return pushListLevelStyle( listStyleName, *fullListStyle, level );
00056 }
00057 
00058 bool KoOasisContext::pushOutlineListLevelStyle( int level )
00059 {
00060     QDomElement outlineStyle = KoDom::namedItemNS( oasisStyles().officeStyle(), KoXmlNS::text, "outline-style" );
00061     return pushListLevelStyle( "<outline-style>", outlineStyle, level );
00062 }
00063 
00064 bool KoOasisContext::pushListLevelStyle( const QString& listStyleName, // for debug only
00065                                          const QDomElement& fullListStyle, int level )
00066 {
00067     // Find applicable list-level-style for level
00068     int i = level;
00069     QDomElement listLevelStyle;
00070     while ( i > 0 && listLevelStyle.isNull() ) {
00071         listLevelStyle = findListLevelStyle( fullListStyle, i );
00072         --i;
00073     }
00074     if ( listLevelStyle.isNull() ) {
00075         kWarning(32500) << "List level style for level " << level << " in list style " << listStyleName << " not found!" << endl;
00076         return false;
00077     }
00078     //kDebug(32500) << "Pushing list-level-style from list-style " << listStyleName << " level " << level << endl;
00079     m_listStyleStack.push( listLevelStyle );
00080     return true;
00081 }
00082 
00083 void KoOasisContext::setCursorPosition( KoTextParag* cursorTextParagraph,
00084                                         int cursorTextIndex )
00085 {
00086     m_cursorTextParagraph = cursorTextParagraph;
00087     m_cursorTextIndex = cursorTextIndex;
00088 }
00089 
00090 KoOasisContext::~KoOasisContext()
00091 {
00092 }
00093 
00095 
00096 KoSavingContext::KoSavingContext( KoGenStyles& mainStyles, KoVariableSettings* settings, bool hasColumns, SavingMode savingMode )
00097     : m_mainStyles( mainStyles ),
00098       m_savingMode( savingMode ),
00099       m_cursorTextParagraph( 0 ),
00100       m_variableSettings( settings ),
00101       m_hasColumns( hasColumns )
00102 {
00103 }
00104 
00105 
00106 KoSavingContext::~KoSavingContext()
00107 {
00108 }
00109 
00110 void KoSavingContext::setCursorPosition( KoTextParag* cursorTextParagraph,
00111                                          int cursorTextIndex )
00112 {
00113     m_cursorTextParagraph = cursorTextParagraph;
00114     m_cursorTextIndex = cursorTextIndex;
00115 }
00116 
00117 void KoSavingContext::addFontFace( const QString& fontName )
00118 {
00119     m_fontFaces[fontName] = true;
00120 }
00121 
00122 void KoSavingContext::writeFontFaces( KoXmlWriter& writer )
00123 {
00124     writer.startElement( "office:font-face-decls" );
00125     const QStringList fontFaces = m_fontFaces.keys();
00126     for ( QStringList::const_iterator ffit = fontFaces.begin(), ffend = fontFaces.end() ; ffit != ffend ; ++ffit ) {
00127         writer.startElement( "style:font-face" );
00128         writer.addAttribute( "style:name", *ffit );
00129         writer.addAttribute( "svg:font-family", *ffit );
00130         // TODO style:font-family-generic
00131         // TODO style:font-pitch
00132         writer.endElement(); // style:font-face
00133     }
00134     writer.endElement(); // office:font-face-decls
00135 }

Généré le Wed Nov 22 23:41:08 2006 pour KPlato par  doxygen 1.5.1-p1