kooasiscontext.cc
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 : m_doc( doc ), m_store( store ), m_varColl( varColl ), m_styles( styles ),
00031 m_cursorTextParagraph( 0 )
00032 {
00033
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
00042
00043
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
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 ) {
00072
00073 m_styleStack.push( *def );
00074 }
00075 }
00076 }
00077
00078
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,
00112 const QDomElement& fullListStyle, int level )
00113 {
00114
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
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
00178
00179 writer.endElement();
00180 }
00181 writer.endElement();
00182 }
This file is part of the documentation for lib Library Version 1.4.2.