00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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,
00065 const QDomElement& fullListStyle, int level )
00066 {
00067
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
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
00131
00132 writer.endElement();
00133 }
00134 writer.endElement();
00135 }