bool KPrTextDocument::loadSpanTag( const QDomElement& tag, KoOasisContext& context, KoTextParag* parag, uint pos, QString& textData, KoTextCustomItem* & customItem ) { const QString localName( tag.localName() ); const bool isTextNS = tag.namespaceURI() == KoXmlNS::text; kdDebug( 32500 ) << "KPrTextDocument::loadSpanTag: " << localName << endl; if ( isTextNS ) { if ( localName == "a" ) { QString href( tag.attributeNS( KoXmlNS::xlink, "href", QString::null ) ); if ( href.startsWith( "#" ) ) { context.styleStack().save(); // We have a reference to a bookmark (### TODO) // As we do not support it now, treat it as a <span> without formatting parag->loadOasisSpan( tag, context, pos ); // recurse context.styleStack().restore(); } else { // The text is contained in a <span> inside the <a> element. In theory // we could have multiple spans there, but OO ensures that there is always only one, // splitting the hyperlink if necessary (at format changes). // Note that we ignore the formatting of the span. QDomElement spanElem = KoDom::namedItemNS( tag, KoXmlNS::text, "span" ); QString text; if ( spanElem.isNull() ) text = tag.text(); if ( spanElem.isNull() ) text = tag.text(); else { // The save/restore of the stack is done by the caller (KoTextParag::loadOasisSpan) // This allows to use the span's format for the variable. //kdDebug(32500) << "filling stack with " << spanElem.attributeNS( KoXmlNS::text, "style-name", QString::null ) << endl; context.fillStyleStack( spanElem, KoXmlNS::text, "style-name", "text" ); text = spanElem.text(); } textData = KoTextObject::customItemChar(); // hyperlink placeholder // unused tag.attributeNS( KoXmlNS::office, "name", QString::null ) KoVariableCollection& coll = context.variableCollection(); customItem = new KoLinkVariable( this, text, href, coll.formatCollection()->format( "STRING" ), &coll ); } return true; } } else // non "text:" tags { kdDebug()<<"Extension found tagName : "<< localName <<endl; } return false; }
void KoParagStyle::loadStyle( QDomElement & styleElem, KoOasisContext& context ) { // Load name m_name = styleElem.attributeNS( KoXmlNS::style, "name", QString::null ); m_displayName = styleElem.attributeNS( KoXmlNS::style, "display-name", QString::null ); if ( m_displayName.isEmpty() ) m_displayName = m_name; // OOo hack //m_bOutline = m_name.startsWith( "Heading" ); // real OASIS solution: m_bOutline = styleElem.hasAttributeNS( KoXmlNS::style, "default-outline-level" ); context.styleStack().save(); context.addStyles( &styleElem, "paragraph" ); // Load all parents - only because we don't support inheritance. KoParagLayout layout; KoParagLayout::loadOasisParagLayout( layout, context ); // loadOasisParagLayout doesn't load the counter. It's modelled differently for parags and for styles. int level = 0; bool listOK = false; const QString listStyleName = styleElem.attributeNS( KoXmlNS::style, "list-style-name", QString::null ); if ( m_bOutline ) { level = styleElem.attributeNS( KoXmlNS::style, "default-outline-level", QString::null ).toInt(); // 1-based listOK = context.pushOutlineListLevelStyle( level ); // allow overriding the outline numbering, see http://lists.oasis-open.org/archives/office/200310/msg00033.html if ( !listStyleName.isEmpty() ) context.pushListLevelStyle( listStyleName, level ); } else { // ######## BIG difference here. In the OOo/OASIS format, one list style has infos for 10 list levels... // ###### so we can't know a level at this point... // The only solution I can think of, to preserve document content when importing OO but // not necessarily the styles used when editing, is: // 1) when importing from OOo, convert each non-heading style with numbering // into 10 kotext styles (at least those used by the document) [TODO] // 2) for KWord's own loading/saving, to add a hack into the file format, say // style:default-level. // Note that default-level defaults to "1", i.e. works for non-nested OOo lists too. level = styleElem.attributeNS( KoXmlNS::style, "default-level", "1" ).toInt(); // 1-based listOK = !listStyleName.isEmpty(); if ( listOK ) listOK = context.pushListLevelStyle( listStyleName, level ); } if ( listOK ) { const QDomElement listStyle = context.listStyleStack().currentListStyle(); // The tag is either text:list-level-style-number or text:list-level-style-bullet const bool ordered = listStyle.localName() == "list-level-style-number"; Q_ASSERT( !layout.counter ); layout.counter = new KoParagCounter; layout.counter->loadOasis( context, -1, ordered, m_bOutline, level, true ); context.listStyleStack().pop(); } // This way, KoTextParag::setParagLayout also sets the style pointer, to this style layout.style = this; m_paragLayout = layout; m_format.load( context ); context.styleStack().restore(); }