diff options
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper.cxx | 84 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.cxx | 2274 | ||||
-rw-r--r-- | writerfilter/source/dmapper/FormControlHelper.cxx | 124 | ||||
-rw-r--r-- | writerfilter/source/dmapper/NumberingManager.cxx | 692 | ||||
-rw-r--r-- | writerfilter/source/dmapper/PropertyMap.cxx | 54 | ||||
-rw-r--r-- | writerfilter/source/dmapper/SdtHelper.cxx | 85 | ||||
-rw-r--r-- | writerfilter/source/dmapper/SettingsTable.cxx | 52 | ||||
-rw-r--r-- | writerfilter/source/dmapper/SmartTagHandler.cxx | 61 | ||||
-rw-r--r-- | writerfilter/source/dmapper/TDefTableHandler.cxx | 140 | ||||
-rw-r--r-- | writerfilter/source/dmapper/TableManager.cxx | 32 | ||||
-rw-r--r-- | writerfilter/source/ooxml/OOXMLDocumentImpl.cxx | 372 | ||||
-rw-r--r-- | writerfilter/source/ooxml/OOXMLFastContextHandler.cxx | 298 | ||||
-rw-r--r-- | writerfilter/source/ooxml/OOXMLPropertySet.cxx | 28 | ||||
-rw-r--r-- | writerfilter/source/ooxml/OOXMLStreamImpl.cxx | 34 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.cxx | 100 |
15 files changed, 2213 insertions, 2217 deletions
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx index adb2f8359662..cf515ae72669 100644 --- a/writerfilter/source/dmapper/DomainMapper.cxx +++ b/writerfilter/source/dmapper/DomainMapper.cxx @@ -2979,37 +2979,37 @@ void DomainMapper::lcl_startSectionGroup() void DomainMapper::lcl_endSectionGroup() { - if (!m_pImpl->isInIndexContext() && !m_pImpl->isInBibliographyContext()) + if (m_pImpl->isInIndexContext() || m_pImpl->isInBibliographyContext()) + return; + + m_pImpl->CheckUnregisteredFrameConversion(); + m_pImpl->ExecuteFrameConversion(); + // When pasting, it's fine to not have any paragraph inside the document at all. + if (m_pImpl->GetIsFirstParagraphInSection() && m_pImpl->IsNewDoc()) { - m_pImpl->CheckUnregisteredFrameConversion(); - m_pImpl->ExecuteFrameConversion(); - // When pasting, it's fine to not have any paragraph inside the document at all. - if (m_pImpl->GetIsFirstParagraphInSection() && m_pImpl->IsNewDoc()) - { - // This section has no paragraph at all (e.g. they are all actually in a frame). - // If this section has a page break, there would be nothing to apply to the page - // style, so force a dummy paragraph. - lcl_startParagraphGroup(); - lcl_startCharacterGroup(); - sal_uInt8 const sBreak[] = { 0xd }; - lcl_text(sBreak, 1); - lcl_endCharacterGroup(); - lcl_endParagraphGroup(); - } - PropertyMapPtr pContext = m_pImpl->GetTopContextOfType(CONTEXT_SECTION); - SectionPropertyMap* pSectionContext = dynamic_cast< SectionPropertyMap* >( pContext.get() ); - OSL_ENSURE(pSectionContext, "SectionContext unavailable!"); - if(pSectionContext) - { - pSectionContext->CloseSectionGroup( *m_pImpl ); - // Remove the dummy paragraph if added for - // handling the section properties if section starts with a table - if (m_pImpl->GetIsDummyParaAddedForTableInSection()) - m_pImpl->RemoveDummyParaForTableInSection(); - } - m_pImpl->SetIsTextFrameInserted( false ); - m_pImpl->PopProperties(CONTEXT_SECTION); + // This section has no paragraph at all (e.g. they are all actually in a frame). + // If this section has a page break, there would be nothing to apply to the page + // style, so force a dummy paragraph. + lcl_startParagraphGroup(); + lcl_startCharacterGroup(); + sal_uInt8 const sBreak[] = { 0xd }; + lcl_text(sBreak, 1); + lcl_endCharacterGroup(); + lcl_endParagraphGroup(); } + PropertyMapPtr pContext = m_pImpl->GetTopContextOfType(CONTEXT_SECTION); + SectionPropertyMap* pSectionContext = dynamic_cast< SectionPropertyMap* >( pContext.get() ); + OSL_ENSURE(pSectionContext, "SectionContext unavailable!"); + if(pSectionContext) + { + pSectionContext->CloseSectionGroup( *m_pImpl ); + // Remove the dummy paragraph if added for + // handling the section properties if section starts with a table + if (m_pImpl->GetIsDummyParaAddedForTableInSection()) + m_pImpl->RemoveDummyParaForTableInSection(); + } + m_pImpl->SetIsTextFrameInserted( false ); + m_pImpl->PopProperties(CONTEXT_SECTION); } void DomainMapper::lcl_startParagraphGroup() @@ -3104,20 +3104,20 @@ void DomainMapper::lcl_startShape(uno::Reference<drawing::XShape> const& xShape) void DomainMapper::lcl_endShape( ) { - if (m_pImpl->GetTopContext()) - { - // End the current table, if there are any. Otherwise the unavoidable - // empty paragraph at the end of the shape text will cause problems: if - // the shape text ends with a table, the extra paragraph will be - // handled as an additional row of the ending table. - if (m_pImpl->hasTableManager()) - m_pImpl->getTableManager().endTable(); + if (!m_pImpl->GetTopContext()) + return; - lcl_endParagraphGroup(); - m_pImpl->PopShapeContext( ); - // A shape is always inside a paragraph (anchored or inline). - m_pImpl->SetIsOutsideAParagraph(false); - } + // End the current table, if there are any. Otherwise the unavoidable + // empty paragraph at the end of the shape text will cause problems: if + // the shape text ends with a table, the extra paragraph will be + // handled as an additional row of the ending table. + if (m_pImpl->hasTableManager()) + m_pImpl->getTableManager().endTable(); + + lcl_endParagraphGroup(); + m_pImpl->PopShapeContext( ); + // A shape is always inside a paragraph (anchored or inline). + m_pImpl->SetIsOutsideAParagraph(false); } void DomainMapper::PushStyleSheetProperties( const PropertyMapPtr& pStyleProperties, bool bAffectTableMngr ) diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index d3eaa4cb093d..6410df8fdfe5 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -131,23 +131,23 @@ static void lcl_linenumberingHeaderFooter( const uno::Reference<container::XName // Populate Dropdown Field properties from FFData structure static void lcl_handleDropdownField( const uno::Reference< beans::XPropertySet >& rxFieldProps, const FFDataHandler::Pointer_t& pFFDataHandler ) { - if ( rxFieldProps.is() ) - { - if ( !pFFDataHandler->getName().isEmpty() ) - rxFieldProps->setPropertyValue( "Name", uno::makeAny( pFFDataHandler->getName() ) ); + if ( !rxFieldProps.is() ) + return; - const FFDataHandler::DropDownEntries_t& rEntries = pFFDataHandler->getDropDownEntries(); - uno::Sequence< OUString > sItems( rEntries.size() ); - ::std::copy( rEntries.begin(), rEntries.end(), sItems.begin()); - if ( sItems.hasElements() ) - rxFieldProps->setPropertyValue( "Items", uno::makeAny( sItems ) ); + if ( !pFFDataHandler->getName().isEmpty() ) + rxFieldProps->setPropertyValue( "Name", uno::makeAny( pFFDataHandler->getName() ) ); - sal_Int32 nResult = pFFDataHandler->getDropDownResult().toInt32(); - if ( nResult ) - rxFieldProps->setPropertyValue( "SelectedItem", uno::makeAny( sItems[ nResult ] ) ); - if ( !pFFDataHandler->getHelpText().isEmpty() ) - rxFieldProps->setPropertyValue( "Help", uno::makeAny( pFFDataHandler->getHelpText() ) ); - } + const FFDataHandler::DropDownEntries_t& rEntries = pFFDataHandler->getDropDownEntries(); + uno::Sequence< OUString > sItems( rEntries.size() ); + ::std::copy( rEntries.begin(), rEntries.end(), sItems.begin()); + if ( sItems.hasElements() ) + rxFieldProps->setPropertyValue( "Items", uno::makeAny( sItems ) ); + + sal_Int32 nResult = pFFDataHandler->getDropDownResult().toInt32(); + if ( nResult ) + rxFieldProps->setPropertyValue( "SelectedItem", uno::makeAny( sItems[ nResult ] ) ); + if ( !pFFDataHandler->getHelpText().isEmpty() ) + rxFieldProps->setPropertyValue( "Help", uno::makeAny( pFFDataHandler->getHelpText() ) ); } static void lcl_handleTextField( const uno::Reference< beans::XPropertySet >& rxFieldProps, const FFDataHandler::Pointer_t& pFFDataHandler ) @@ -2071,101 +2071,101 @@ void DomainMapper_Impl::appendTextPortion( const OUString& rString, const Proper if( pPropertyMap == m_pTopContext && !deferredCharacterProperties.empty() && (GetTopContextType() == CONTEXT_CHARACTER) ) processDeferredCharacterProperties(); uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend; - if (xTextAppend.is() && hasTableManager() && !getTableManager().isIgnore()) - { - try - { - // If we are in comments, then disable CharGrabBag, comment text doesn't support that. - uno::Sequence< beans::PropertyValue > aValues = pPropertyMap->GetPropertyValues(/*bCharGrabBag=*/!m_bIsInComments); + if (!(xTextAppend.is() && hasTableManager() && !getTableManager().isIgnore())) + return; - if (m_bStartTOC || m_bStartIndex || m_bStartBibliography) - for( auto& rValue : aValues ) - { - if (rValue.Name == "CharHidden") - rValue.Value <<= false; - } + try + { + // If we are in comments, then disable CharGrabBag, comment text doesn't support that. + uno::Sequence< beans::PropertyValue > aValues = pPropertyMap->GetPropertyValues(/*bCharGrabBag=*/!m_bIsInComments); - uno::Reference< text::XTextRange > xTextRange; - if (m_aTextAppendStack.top().xInsertPosition.is()) + if (m_bStartTOC || m_bStartIndex || m_bStartBibliography) + for( auto& rValue : aValues ) { - xTextRange = xTextAppend->insertTextPortion(rString, aValues, m_aTextAppendStack.top().xInsertPosition); - m_aTextAppendStack.top().xCursor->gotoRange(xTextRange->getEnd(), true); + if (rValue.Name == "CharHidden") + rValue.Value <<= false; } - else + + uno::Reference< text::XTextRange > xTextRange; + if (m_aTextAppendStack.top().xInsertPosition.is()) + { + xTextRange = xTextAppend->insertTextPortion(rString, aValues, m_aTextAppendStack.top().xInsertPosition); + m_aTextAppendStack.top().xCursor->gotoRange(xTextRange->getEnd(), true); + } + else + { + if (m_bStartTOC || m_bStartIndex || m_bStartBibliography || m_nStartGenericField != 0) { - if (m_bStartTOC || m_bStartIndex || m_bStartBibliography || m_nStartGenericField != 0) + if (IsInHeaderFooter() && !m_bStartTOCHeaderFooter) { - if (IsInHeaderFooter() && !m_bStartTOCHeaderFooter) - { - xTextRange = xTextAppend->appendTextPortion(rString, aValues); - } - else - { - m_bStartedTOC = true; - uno::Reference< text::XTextCursor > xTOCTextCursor = xTextAppend->getEnd()->getText( )->createTextCursor( ); - assert(xTOCTextCursor.is()); - xTOCTextCursor->gotoEnd(false); - if (m_nStartGenericField != 0) - { - xTOCTextCursor->goLeft(1, false); - } - xTextRange = xTextAppend->insertTextPortion(rString, aValues, xTOCTextCursor); - SAL_WARN_IF(!xTextRange.is(), "writerfilter.dmapper", "insertTextPortion failed"); - if (!xTextRange.is()) - throw uno::Exception("insertTextPortion failed", nullptr); - m_bTextInserted = true; - xTOCTextCursor->gotoRange(xTextRange->getEnd(), true); - if (m_nStartGenericField == 0) - { - m_aTextAppendStack.push(TextAppendContext(xTextAppend, xTOCTextCursor)); - } - } + xTextRange = xTextAppend->appendTextPortion(rString, aValues); } else { -#if !defined(MACOSX) // TODO: check layout differences and support all platforms, if needed - sal_Int32 nPos = 0; - OUString sFontName; - OUString sDoubleSpace(" "); - PropertyMapPtr pContext = GetTopContextOfType(CONTEXT_CHARACTER); - // tdf#123703 workaround for longer space sequences of the old or compatible RTF documents - if (GetSettingsTable()->GetLongerSpaceSequence() && !IsOpenFieldCommand() && (nPos = rString.indexOf(sDoubleSpace)) != -1 && - // monospaced fonts have no longer space sequences, regardless of \fprq2 (not monospaced) font setting - // fix for the base monospaced font Courier - (!pContext || !pContext->isSet(PROP_CHAR_FONT_NAME) || - ((pContext->getProperty(PROP_CHAR_FONT_NAME)->second >>= sFontName) && sFontName.indexOf("Courier") == -1))) + m_bStartedTOC = true; + uno::Reference< text::XTextCursor > xTOCTextCursor = xTextAppend->getEnd()->getText( )->createTextCursor( ); + assert(xTOCTextCursor.is()); + xTOCTextCursor->gotoEnd(false); + if (m_nStartGenericField != 0) { - // an RTF space character is longer by an extra six-em-space in an old-style RTF space sequence, - // insert them to keep RTF document layout formatted by consecutive spaces - const sal_Unicode aExtraSpace[5] = { 0x2006, 0x20, 0x2006, 0x20, 0 }; - const sal_Unicode aExtraSpace2[4] = { 0x20, 0x2006, 0x20, 0 }; - xTextRange = xTextAppend->appendTextPortion(rString.replaceAll(sDoubleSpace, aExtraSpace, nPos) - .replaceAll(sDoubleSpace, aExtraSpace2, nPos), aValues); + xTOCTextCursor->goLeft(1, false); + } + xTextRange = xTextAppend->insertTextPortion(rString, aValues, xTOCTextCursor); + SAL_WARN_IF(!xTextRange.is(), "writerfilter.dmapper", "insertTextPortion failed"); + if (!xTextRange.is()) + throw uno::Exception("insertTextPortion failed", nullptr); + m_bTextInserted = true; + xTOCTextCursor->gotoRange(xTextRange->getEnd(), true); + if (m_nStartGenericField == 0) + { + m_aTextAppendStack.push(TextAppendContext(xTextAppend, xTOCTextCursor)); } - else -#endif - xTextRange = xTextAppend->appendTextPortion(rString, aValues); } } - - // reset moveFrom data of non-terminating runs of the paragraph - if ( m_pParaMarkerRedlineMoveFrom ) + else { - m_pParaMarkerRedlineMoveFrom.clear(); +#if !defined(MACOSX) // TODO: check layout differences and support all platforms, if needed + sal_Int32 nPos = 0; + OUString sFontName; + OUString sDoubleSpace(" "); + PropertyMapPtr pContext = GetTopContextOfType(CONTEXT_CHARACTER); + // tdf#123703 workaround for longer space sequences of the old or compatible RTF documents + if (GetSettingsTable()->GetLongerSpaceSequence() && !IsOpenFieldCommand() && (nPos = rString.indexOf(sDoubleSpace)) != -1 && + // monospaced fonts have no longer space sequences, regardless of \fprq2 (not monospaced) font setting + // fix for the base monospaced font Courier + (!pContext || !pContext->isSet(PROP_CHAR_FONT_NAME) || + ((pContext->getProperty(PROP_CHAR_FONT_NAME)->second >>= sFontName) && sFontName.indexOf("Courier") == -1))) + { + // an RTF space character is longer by an extra six-em-space in an old-style RTF space sequence, + // insert them to keep RTF document layout formatted by consecutive spaces + const sal_Unicode aExtraSpace[5] = { 0x2006, 0x20, 0x2006, 0x20, 0 }; + const sal_Unicode aExtraSpace2[4] = { 0x20, 0x2006, 0x20, 0 }; + xTextRange = xTextAppend->appendTextPortion(rString.replaceAll(sDoubleSpace, aExtraSpace, nPos) + .replaceAll(sDoubleSpace, aExtraSpace2, nPos), aValues); + } + else +#endif + xTextRange = xTextAppend->appendTextPortion(rString, aValues); } - CheckRedline( xTextRange ); - m_bParaChanged = true; - - //getTableManager( ).handle(xTextRange); - } - catch(const lang::IllegalArgumentException&) - { - OSL_FAIL( "IllegalArgumentException in DomainMapper_Impl::appendTextPortion" ); } - catch(const uno::Exception&) + + // reset moveFrom data of non-terminating runs of the paragraph + if ( m_pParaMarkerRedlineMoveFrom ) { - OSL_FAIL( "Exception in DomainMapper_Impl::appendTextPortion" ); + m_pParaMarkerRedlineMoveFrom.clear(); } + CheckRedline( xTextRange ); + m_bParaChanged = true; + + //getTableManager( ).handle(xTextRange); + } + catch(const lang::IllegalArgumentException&) + { + OSL_FAIL( "IllegalArgumentException in DomainMapper_Impl::appendTextPortion" ); + } + catch(const uno::Exception&) + { + OSL_FAIL( "Exception in DomainMapper_Impl::appendTextPortion" ); } } @@ -2179,21 +2179,21 @@ void DomainMapper_Impl::appendTextContent( return; uno::Reference< text::XTextAppendAndConvert > xTextAppendAndConvert( m_aTextAppendStack.top().xTextAppend, uno::UNO_QUERY ); OSL_ENSURE( xTextAppendAndConvert.is(), "trying to append a text content without XTextAppendAndConvert" ); - if (xTextAppendAndConvert.is() && hasTableManager() && !getTableManager().isIgnore()) + if (!(xTextAppendAndConvert.is() && hasTableManager() && !getTableManager().isIgnore())) + return; + + try + { + if (m_aTextAppendStack.top().xInsertPosition.is()) + xTextAppendAndConvert->insertTextContentWithProperties( xContent, xPropertyValues, m_aTextAppendStack.top().xInsertPosition ); + else + xTextAppendAndConvert->appendTextContent( xContent, xPropertyValues ); + } + catch(const lang::IllegalArgumentException&) + { + } + catch(const uno::Exception&) { - try - { - if (m_aTextAppendStack.top().xInsertPosition.is()) - xTextAppendAndConvert->insertTextContentWithProperties( xContent, xPropertyValues, m_aTextAppendStack.top().xInsertPosition ); - else - xTextAppendAndConvert->appendTextContent( xContent, xPropertyValues ); - } - catch(const lang::IllegalArgumentException&) - { - } - catch(const uno::Exception&) - { - } } } @@ -2282,53 +2282,53 @@ void DomainMapper_Impl::appendStarMath( const Value& val ) { uno::Reference< embed::XEmbeddedObject > formula; val.getAny() >>= formula; - if( formula.is() ) + if( !formula.is() ) + return; + + try { - try - { - uno::Reference< text::XTextContent > xStarMath( m_xTextFactory->createInstance("com.sun.star.text.TextEmbeddedObject"), uno::UNO_QUERY_THROW ); - uno::Reference< beans::XPropertySet > xStarMathProperties(xStarMath, uno::UNO_QUERY_THROW); - - xStarMathProperties->setPropertyValue(getPropertyName( PROP_EMBEDDED_OBJECT ), - val.getAny()); - // tdf#66405: set zero margins for embedded object - xStarMathProperties->setPropertyValue(getPropertyName( PROP_LEFT_MARGIN ), - uno::makeAny(sal_Int32(0))); - xStarMathProperties->setPropertyValue(getPropertyName( PROP_RIGHT_MARGIN ), - uno::makeAny(sal_Int32(0))); - xStarMathProperties->setPropertyValue(getPropertyName( PROP_TOP_MARGIN ), - uno::makeAny(sal_Int32(0))); - xStarMathProperties->setPropertyValue(getPropertyName( PROP_BOTTOM_MARGIN ), - uno::makeAny(sal_Int32(0))); - - uno::Reference< uno::XInterface > xInterface( formula->getComponent(), uno::UNO_QUERY ); - // set zero margins for object's component - uno::Reference< beans::XPropertySet > xComponentProperties( xInterface, uno::UNO_QUERY_THROW ); - xComponentProperties->setPropertyValue(getPropertyName( PROP_LEFT_MARGIN ), - uno::makeAny(sal_Int32(0))); - xComponentProperties->setPropertyValue(getPropertyName( PROP_RIGHT_MARGIN ), - uno::makeAny(sal_Int32(0))); - xComponentProperties->setPropertyValue(getPropertyName( PROP_TOP_MARGIN ), - uno::makeAny(sal_Int32(0))); - xComponentProperties->setPropertyValue(getPropertyName( PROP_BOTTOM_MARGIN ), - uno::makeAny(sal_Int32(0))); - Size size( 1000, 1000 ); - if( oox::FormulaImportBase* formulaimport = dynamic_cast< oox::FormulaImportBase* >( xInterface.get())) - size = formulaimport->getFormulaSize(); - xStarMathProperties->setPropertyValue(getPropertyName( PROP_WIDTH ), - uno::makeAny( sal_Int32(size.Width()))); - xStarMathProperties->setPropertyValue(getPropertyName( PROP_HEIGHT ), - uno::makeAny( sal_Int32(size.Height()))); - xStarMathProperties->setPropertyValue(getPropertyName(PROP_ANCHOR_TYPE), - uno::makeAny(text::TextContentAnchorType_AS_CHARACTER)); - // mimic the treatment of graphics here... it seems anchoring as character - // gives a better ( visually ) result - appendTextContent(xStarMath, uno::Sequence<beans::PropertyValue>()); - } - catch( const uno::Exception& ) - { - OSL_FAIL( "Exception in creation of StarMath object" ); - } + uno::Reference< text::XTextContent > xStarMath( m_xTextFactory->createInstance("com.sun.star.text.TextEmbeddedObject"), uno::UNO_QUERY_THROW ); + uno::Reference< beans::XPropertySet > xStarMathProperties(xStarMath, uno::UNO_QUERY_THROW); + + xStarMathProperties->setPropertyValue(getPropertyName( PROP_EMBEDDED_OBJECT ), + val.getAny()); + // tdf#66405: set zero margins for embedded object + xStarMathProperties->setPropertyValue(getPropertyName( PROP_LEFT_MARGIN ), + uno::makeAny(sal_Int32(0))); + xStarMathProperties->setPropertyValue(getPropertyName( PROP_RIGHT_MARGIN ), + uno::makeAny(sal_Int32(0))); + xStarMathProperties->setPropertyValue(getPropertyName( PROP_TOP_MARGIN ), + uno::makeAny(sal_Int32(0))); + xStarMathProperties->setPropertyValue(getPropertyName( PROP_BOTTOM_MARGIN ), + uno::makeAny(sal_Int32(0))); + + uno::Reference< uno::XInterface > xInterface( formula->getComponent(), uno::UNO_QUERY ); + // set zero margins for object's component + uno::Reference< beans::XPropertySet > xComponentProperties( xInterface, uno::UNO_QUERY_THROW ); + xComponentProperties->setPropertyValue(getPropertyName( PROP_LEFT_MARGIN ), + uno::makeAny(sal_Int32(0))); + xComponentProperties->setPropertyValue(getPropertyName( PROP_RIGHT_MARGIN ), + uno::makeAny(sal_Int32(0))); + xComponentProperties->setPropertyValue(getPropertyName( PROP_TOP_MARGIN ), + uno::makeAny(sal_Int32(0))); + xComponentProperties->setPropertyValue(getPropertyName( PROP_BOTTOM_MARGIN ), + uno::makeAny(sal_Int32(0))); + Size size( 1000, 1000 ); + if( oox::FormulaImportBase* formulaimport = dynamic_cast< oox::FormulaImportBase* >( xInterface.get())) + size = formulaimport->getFormulaSize(); + xStarMathProperties->setPropertyValue(getPropertyName( PROP_WIDTH ), + uno::makeAny( sal_Int32(size.Width()))); + xStarMathProperties->setPropertyValue(getPropertyName( PROP_HEIGHT ), + uno::makeAny( sal_Int32(size.Height()))); + xStarMathProperties->setPropertyValue(getPropertyName(PROP_ANCHOR_TYPE), + uno::makeAny(text::TextContentAnchorType_AS_CHARACTER)); + // mimic the treatment of graphics here... it seems anchoring as character + // gives a better ( visually ) result + appendTextContent(xStarMath, uno::Sequence<beans::PropertyValue>()); + } + catch( const uno::Exception& ) + { + OSL_FAIL( "Exception in creation of StarMath object" ); } } @@ -2426,55 +2426,55 @@ void DomainMapper_Impl::PushPageHeaderFooter(bool bHeader, SectionPropertyMap::P PropertyMapPtr pContext = DomainMapper_Impl::GetTopContextOfType(CONTEXT_SECTION); //ask for the header/footer name of the given type SectionPropertyMap* pSectionContext = dynamic_cast< SectionPropertyMap* >( pContext.get() ); - if(pSectionContext) - { - // clear the "Link To Previous" flag so that the header/footer - // content is not copied from the previous section - pSectionContext->ClearHeaderFooterLinkToPrevious(bHeader, eType); + if(!pSectionContext) + return; - if (!m_bIsNewDoc) - { - return; // TODO sw cannot Undo insert header/footer without crashing - } + // clear the "Link To Previous" flag so that the header/footer + // content is not copied from the previous section + pSectionContext->ClearHeaderFooterLinkToPrevious(bHeader, eType); - uno::Reference< beans::XPropertySet > xPageStyle = - pSectionContext->GetPageStyle( - *this, - eType == SectionPropertyMap::PAGE_FIRST ); - if (!xPageStyle.is()) - return; - try - { - bool bLeft = eType == SectionPropertyMap::PAGE_LEFT; - bool bFirst = eType == SectionPropertyMap::PAGE_FIRST; - if ((!bLeft && !GetSettingsTable()->GetEvenAndOddHeaders()) || (GetSettingsTable()->GetEvenAndOddHeaders())) - { - //switch on header/footer use - xPageStyle->setPropertyValue( - getPropertyName(ePropIsOn), - uno::makeAny(true)); - - // If the 'Different Even & Odd Pages' flag is turned on - do not ignore it - // Even if the 'Even' header/footer is blank - the flag should be imported (so it would look in LO like in Word) - if (!bFirst && GetSettingsTable()->GetEvenAndOddHeaders()) - xPageStyle->setPropertyValue(getPropertyName(ePropShared), uno::makeAny(false)); - - //set the interface - uno::Reference< text::XText > xText; - xPageStyle->getPropertyValue(getPropertyName(bLeft? ePropTextLeft: ePropText)) >>= xText; - - m_aTextAppendStack.push(TextAppendContext(uno::Reference< text::XTextAppend >(xText, uno::UNO_QUERY_THROW), - m_bIsNewDoc - ? uno::Reference<text::XTextCursor>() - : xText->createTextCursorByRange(xText->getStart()))); - m_bDiscardHeaderFooter = false; // set only on success! - } - } - catch( const uno::Exception& ) + if (!m_bIsNewDoc) + { + return; // TODO sw cannot Undo insert header/footer without crashing + } + + uno::Reference< beans::XPropertySet > xPageStyle = + pSectionContext->GetPageStyle( + *this, + eType == SectionPropertyMap::PAGE_FIRST ); + if (!xPageStyle.is()) + return; + try + { + bool bLeft = eType == SectionPropertyMap::PAGE_LEFT; + bool bFirst = eType == SectionPropertyMap::PAGE_FIRST; + if ((!bLeft && !GetSettingsTable()->GetEvenAndOddHeaders()) || (GetSettingsTable()->GetEvenAndOddHeaders())) { - DBG_UNHANDLED_EXCEPTION("writerfilter.dmapper"); + //switch on header/footer use + xPageStyle->setPropertyValue( + getPropertyName(ePropIsOn), + uno::makeAny(true)); + + // If the 'Different Even & Odd Pages' flag is turned on - do not ignore it + // Even if the 'Even' header/footer is blank - the flag should be imported (so it would look in LO like in Word) + if (!bFirst && GetSettingsTable()->GetEvenAndOddHeaders()) + xPageStyle->setPropertyValue(getPropertyName(ePropShared), uno::makeAny(false)); + + //set the interface + uno::Reference< text::XText > xText; + xPageStyle->getPropertyValue(getPropertyName(bLeft? ePropTextLeft: ePropText)) >>= xText; + + m_aTextAppendStack.push(TextAppendContext(uno::Reference< text::XTextAppend >(xText, uno::UNO_QUERY_THROW), + m_bIsNewDoc + ? uno::Reference<text::XTextCursor>() + : xText->createTextCursorByRange(xText->getStart()))); + m_bDiscardHeaderFooter = false; // set only on success! } } + catch( const uno::Exception& ) + { + DBG_UNHANDLED_EXCEPTION("writerfilter.dmapper"); + } } void DomainMapper_Impl::PushPageHeader(SectionPropertyMap::PageType eType) @@ -2569,57 +2569,57 @@ void DomainMapper_Impl::PushFootOrEndnote( bool bIsFootnote ) void DomainMapper_Impl::CreateRedline(uno::Reference<text::XTextRange> const& xRange, const RedlineParamsPtr& pRedline) { - if ( pRedline ) + if ( !pRedline ) + return; + + try { - try + OUString sType; + switch ( pRedline->m_nToken & 0xffff ) { - OUString sType; - switch ( pRedline->m_nToken & 0xffff ) - { - case XML_mod: - sType = getPropertyName( PROP_FORMAT ); - break; - case XML_moveTo: - case XML_ins: - sType = getPropertyName( PROP_INSERT ); - break; - case XML_moveFrom: - m_pParaMarkerRedlineMoveFrom = pRedline.get(); - [[fallthrough]]; - case XML_del: - sType = getPropertyName( PROP_DELETE ); - break; - case XML_ParagraphFormat: - sType = getPropertyName( PROP_PARAGRAPH_FORMAT ); - break; - default: - throw lang::IllegalArgumentException("illegal redline token type", nullptr, 0); - } - beans::PropertyValues aRedlineProperties( 3 ); - beans::PropertyValue * pRedlineProperties = aRedlineProperties.getArray( ); - pRedlineProperties[0].Name = getPropertyName( PROP_REDLINE_AUTHOR ); - pRedlineProperties[0].Value <<= pRedline->m_sAuthor; - pRedlineProperties[1].Name = getPropertyName( PROP_REDLINE_DATE_TIME ); - pRedlineProperties[1].Value <<= ConversionHelper::ConvertDateStringToDateTime( pRedline->m_sDate ); - pRedlineProperties[2].Name = getPropertyName( PROP_REDLINE_REVERT_PROPERTIES ); - pRedlineProperties[2].Value <<= pRedline->m_aRevertProperties; - if (!m_bIsActualParagraphFramed) - { - uno::Reference < text::XRedline > xRedline( xRange, uno::UNO_QUERY_THROW ); - xRedline->makeRedline( sType, aRedlineProperties ); - } - else - { - aFramedRedlines.push_back( uno::makeAny(xRange) ); - aFramedRedlines.push_back( uno::makeAny(sType) ); - aFramedRedlines.push_back( uno::makeAny(aRedlineProperties) ); - } + case XML_mod: + sType = getPropertyName( PROP_FORMAT ); + break; + case XML_moveTo: + case XML_ins: + sType = getPropertyName( PROP_INSERT ); + break; + case XML_moveFrom: + m_pParaMarkerRedlineMoveFrom = pRedline.get(); + [[fallthrough]]; + case XML_del: + sType = getPropertyName( PROP_DELETE ); + break; + case XML_ParagraphFormat: + sType = getPropertyName( PROP_PARAGRAPH_FORMAT ); + break; + default: + throw lang::IllegalArgumentException("illegal redline token type", nullptr, 0); + } + beans::PropertyValues aRedlineProperties( 3 ); + beans::PropertyValue * pRedlineProperties = aRedlineProperties.getArray( ); + pRedlineProperties[0].Name = getPropertyName( PROP_REDLINE_AUTHOR ); + pRedlineProperties[0].Value <<= pRedline->m_sAuthor; + pRedlineProperties[1].Name = getPropertyName( PROP_REDLINE_DATE_TIME ); + pRedlineProperties[1].Value <<= ConversionHelper::ConvertDateStringToDateTime( pRedline->m_sDate ); + pRedlineProperties[2].Name = getPropertyName( PROP_REDLINE_REVERT_PROPERTIES ); + pRedlineProperties[2].Value <<= pRedline->m_aRevertProperties; + if (!m_bIsActualParagraphFramed) + { + uno::Reference < text::XRedline > xRedline( xRange, uno::UNO_QUERY_THROW ); + xRedline->makeRedline( sType, aRedlineProperties ); } - catch( const uno::Exception & ) + else { - OSL_FAIL( "Exception in makeRedline" ); + aFramedRedlines.push_back( uno::makeAny(xRange) ); + aFramedRedlines.push_back( uno::makeAny(sType) ); + aFramedRedlines.push_back( uno::makeAny(aRedlineProperties) ); } } + catch( const uno::Exception & ) + { + OSL_FAIL( "Exception in makeRedline" ); + } } void DomainMapper_Impl::CheckParaMarkerRedline( uno::Reference< text::XTextRange > const& xRange ) @@ -3075,70 +3075,70 @@ void DomainMapper_Impl::PopShapeContext() getTableManager().endLevel(); popTableManager(); } - if ( !m_aAnchoredStack.empty() ) - { - // For OLE object replacement shape, the text append context was already removed - // or the OLE object couldn't be inserted. - if ( !m_aAnchoredStack.top().bToRemove ) - { - RemoveLastParagraph(); - if (!m_aTextAppendStack.empty()) - m_aTextAppendStack.pop(); - } + if ( m_aAnchoredStack.empty() ) + return; - uno::Reference< text::XTextContent > xObj = m_aAnchoredStack.top( ).xTextContent; - try - { - appendTextContent( xObj, uno::Sequence< beans::PropertyValue >() ); - } - catch ( const uno::RuntimeException& ) - { - // this is normal: the shape is already attached - } + // For OLE object replacement shape, the text append context was already removed + // or the OLE object couldn't be inserted. + if ( !m_aAnchoredStack.top().bToRemove ) + { + RemoveLastParagraph(); + if (!m_aTextAppendStack.empty()) + m_aTextAppendStack.pop(); + } - const uno::Reference<drawing::XShape> xShape( xObj, uno::UNO_QUERY_THROW ); - // Remove the shape if required (most likely replacement shape for OLE object) - // or anchored to a discarded header or footer - if ( m_aAnchoredStack.top().bToRemove || m_bDiscardHeaderFooter ) - { - try - { - uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(m_xTextDocument, uno::UNO_QUERY_THROW); - uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage(); - if ( xDrawPage.is() ) - xDrawPage->remove( xShape ); - } - catch( const uno::Exception& ) - { - } - } + uno::Reference< text::XTextContent > xObj = m_aAnchoredStack.top( ).xTextContent; + try + { + appendTextContent( xObj, uno::Sequence< beans::PropertyValue >() ); + } + catch ( const uno::RuntimeException& ) + { + // this is normal: the shape is already attached + } - // Relative width calculations deferred until section's margins are defined. - // Being cautious: only deferring undefined/minimum-width shapes in order to avoid causing potential regressions - css::awt::Size aShapeSize; + const uno::Reference<drawing::XShape> xShape( xObj, uno::UNO_QUERY_THROW ); + // Remove the shape if required (most likely replacement shape for OLE object) + // or anchored to a discarded header or footer + if ( m_aAnchoredStack.top().bToRemove || m_bDiscardHeaderFooter ) + { try { - aShapeSize = xShape->getSize(); + uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(m_xTextDocument, uno::UNO_QUERY_THROW); + uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage(); + if ( xDrawPage.is() ) + xDrawPage->remove( xShape ); } - catch (const css::uno::RuntimeException& e) + catch( const uno::Exception& ) { - // May happen e.g. when text frame has no frame format - // See sw/qa/extras/ooxmlimport/data/n779627.docx - SAL_WARN("writerfilter.dmapper", "getSize failed. " << e.Message); } - if( aShapeSize.Width <= 2 ) + } + + // Relative width calculations deferred until section's margins are defined. + // Being cautious: only deferring undefined/minimum-width shapes in order to avoid causing potential regressions + css::awt::Size aShapeSize; + try + { + aShapeSize = xShape->getSize(); + } + catch (const css::uno::RuntimeException& e) + { + // May happen e.g. when text frame has no frame format + // See sw/qa/extras/ooxmlimport/data/n779627.docx + SAL_WARN("writerfilter.dmapper", "getSize failed. " << e.Message); + } + if( aShapeSize.Width <= 2 ) + { + const uno::Reference<beans::XPropertySet> xShapePropertySet( xShape, uno::UNO_QUERY ); + SectionPropertyMap* pSectionContext = GetSectionContext(); + if ( pSectionContext && (!hasTableManager() || !getTableManager().isInTable()) && + xShapePropertySet->getPropertySetInfo()->hasPropertyByName(getPropertyName(PROP_RELATIVE_WIDTH)) ) { - const uno::Reference<beans::XPropertySet> xShapePropertySet( xShape, uno::UNO_QUERY ); - SectionPropertyMap* pSectionContext = GetSectionContext(); - if ( pSectionContext && (!hasTableManager() || !getTableManager().isInTable()) && - xShapePropertySet->getPropertySetInfo()->hasPropertyByName(getPropertyName(PROP_RELATIVE_WIDTH)) ) - { - pSectionContext->addRelativeWidthShape(xShape); - } + pSectionContext->addRelativeWidthShape(xShape); } - - m_aAnchoredStack.pop(); } + + m_aAnchoredStack.pop(); } bool DomainMapper_Impl::IsSdtEndBefore() @@ -4990,810 +4990,810 @@ void DomainMapper_Impl::CloseFieldCommand() if(!m_aFieldStack.empty()) pContext = m_aFieldStack.back(); OSL_ENSURE( pContext, "no field context available"); - if( pContext ) - { - m_bSetUserFieldContent = false; - m_bSetCitation = false; - m_bSetDateValue = false; - const FieldConversionMap_t& aFieldConversionMap = lcl_GetFieldConversion(); + if( !pContext ) + return; - try - { - uno::Reference< uno::XInterface > xFieldInterface; + m_bSetUserFieldContent = false; + m_bSetCitation = false; + m_bSetDateValue = false; + const FieldConversionMap_t& aFieldConversionMap = lcl_GetFieldConversion(); - const auto& [sType, vArguments, vSwitches]{ splitFieldCommand(pContext->GetCommand()) }; - (void)vSwitches; - OUString const sFirstParam(vArguments.empty() ? OUString() : vArguments.front()); + try + { + uno::Reference< uno::XInterface > xFieldInterface; + + const auto& [sType, vArguments, vSwitches]{ splitFieldCommand(pContext->GetCommand()) }; + (void)vSwitches; + OUString const sFirstParam(vArguments.empty() ? OUString() : vArguments.front()); - // apply font size to the form control - if (!m_aTextAppendStack.empty() && m_pLastCharacterContext && ( m_pLastCharacterContext->isSet(PROP_CHAR_HEIGHT) || m_pLastCharacterContext->isSet(PROP_CHAR_FONT_NAME ))) + // apply font size to the form control + if (!m_aTextAppendStack.empty() && m_pLastCharacterContext && ( m_pLastCharacterContext->isSet(PROP_CHAR_HEIGHT) || m_pLastCharacterContext->isSet(PROP_CHAR_FONT_NAME ))) + { + uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend; + if (xTextAppend.is()) { - uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend; - if (xTextAppend.is()) + uno::Reference< text::XTextCursor > xCrsr = xTextAppend->getText()->createTextCursor(); + if (xCrsr.is()) { - uno::Reference< text::XTextCursor > xCrsr = xTextAppend->getText()->createTextCursor(); - if (xCrsr.is()) + xCrsr->gotoEnd(false); + uno::Reference< beans::XPropertySet > xProp( xCrsr, uno::UNO_QUERY ); + if (m_pLastCharacterContext->isSet(PROP_CHAR_HEIGHT)) { - xCrsr->gotoEnd(false); - uno::Reference< beans::XPropertySet > xProp( xCrsr, uno::UNO_QUERY ); - if (m_pLastCharacterContext->isSet(PROP_CHAR_HEIGHT)) - { - xProp->setPropertyValue(getPropertyName(PROP_CHAR_HEIGHT), m_pLastCharacterContext->getProperty(PROP_CHAR_HEIGHT)->second); - if (m_pLastCharacterContext->isSet(PROP_CHAR_HEIGHT_COMPLEX)) - xProp->setPropertyValue(getPropertyName(PROP_CHAR_HEIGHT_COMPLEX), m_pLastCharacterContext->getProperty(PROP_CHAR_HEIGHT_COMPLEX)->second); - } - if (m_pLastCharacterContext->isSet(PROP_CHAR_FONT_NAME)) - xProp->setPropertyValue(getPropertyName(PROP_CHAR_FONT_NAME), m_pLastCharacterContext->getProperty(PROP_CHAR_FONT_NAME)->second); + xProp->setPropertyValue(getPropertyName(PROP_CHAR_HEIGHT), m_pLastCharacterContext->getProperty(PROP_CHAR_HEIGHT)->second); + if (m_pLastCharacterContext->isSet(PROP_CHAR_HEIGHT_COMPLEX)) + xProp->setPropertyValue(getPropertyName(PROP_CHAR_HEIGHT_COMPLEX), m_pLastCharacterContext->getProperty(PROP_CHAR_HEIGHT_COMPLEX)->second); } + if (m_pLastCharacterContext->isSet(PROP_CHAR_FONT_NAME)) + xProp->setPropertyValue(getPropertyName(PROP_CHAR_FONT_NAME), m_pLastCharacterContext->getProperty(PROP_CHAR_FONT_NAME)->second); } } + } - FieldConversionMap_t::const_iterator const aIt = aFieldConversionMap.find(sType); - if (aIt != aFieldConversionMap.end() - && (!m_bForceGenericFields - // these need to convert ffData to properties... - || (aIt->second.eFieldId == FIELD_FORMCHECKBOX) - || (aIt->second.eFieldId == FIELD_FORMDROPDOWN) - || (aIt->second.eFieldId == FIELD_FORMTEXT))) + FieldConversionMap_t::const_iterator const aIt = aFieldConversionMap.find(sType); + if (aIt != aFieldConversionMap.end() + && (!m_bForceGenericFields + // these need to convert ffData to properties... + || (aIt->second.eFieldId == FIELD_FORMCHECKBOX) + || (aIt->second.eFieldId == FIELD_FORMDROPDOWN) + || (aIt->second.eFieldId == FIELD_FORMTEXT))) + { + pContext->SetFieldId(aIt->second.eFieldId); + bool bCreateEnhancedField = false; + uno::Reference< beans::XPropertySet > xFieldProperties; + bool bCreateField = true; + switch (aIt->second.eFieldId) { - pContext->SetFieldId(aIt->second.eFieldId); - bool bCreateEnhancedField = false; - uno::Reference< beans::XPropertySet > xFieldProperties; - bool bCreateField = true; - switch (aIt->second.eFieldId) + case FIELD_HYPERLINK: + case FIELD_DOCPROPERTY: + case FIELD_TOC: + case FIELD_INDEX: + case FIELD_XE: + case FIELD_BIBLIOGRAPHY: + case FIELD_CITATION: + case FIELD_TC: + case FIELD_EQ: + case FIELD_INCLUDEPICTURE: + case FIELD_SYMBOL: + case FIELD_GOTOBUTTON: + bCreateField = false; + break; + case FIELD_FORMCHECKBOX : + case FIELD_FORMTEXT : + case FIELD_FORMDROPDOWN : + { + // If we use 'enhanced' fields then FIELD_FORMCHECKBOX, + // FIELD_FORMTEXT & FIELD_FORMDROPDOWN are treated specially + if ( m_bUsingEnhancedFields ) { - case FIELD_HYPERLINK: - case FIELD_DOCPROPERTY: - case FIELD_TOC: - case FIELD_INDEX: - case FIELD_XE: - case FIELD_BIBLIOGRAPHY: - case FIELD_CITATION: - case FIELD_TC: - case FIELD_EQ: - case FIELD_INCLUDEPICTURE: - case FIELD_SYMBOL: - case FIELD_GOTOBUTTON: - bCreateField = false; - break; - case FIELD_FORMCHECKBOX : - case FIELD_FORMTEXT : - case FIELD_FORMDROPDOWN : + bCreateField = false; + bCreateEnhancedField = true; + } + // for non enhanced fields checkboxes are displayed + // as an awt control not a field + else if ( aIt->second.eFieldId == FIELD_FORMCHECKBOX ) + bCreateField = false; + break; + } + default: + { + FieldContextPtr pOuter = GetParentFieldContext(m_aFieldStack); + if (pOuter) { - // If we use 'enhanced' fields then FIELD_FORMCHECKBOX, - // FIELD_FORMTEXT & FIELD_FORMDROPDOWN are treated specially - if ( m_bUsingEnhancedFields ) + if (!IsFieldNestingAllowed(pOuter, m_aFieldStack.back())) { + // Parent field can't host this child field: don't create a child field + // in this case. bCreateField = false; - bCreateEnhancedField = true; } - // for non enhanced fields checkboxes are displayed - // as an awt control not a field - else if ( aIt->second.eFieldId == FIELD_FORMCHECKBOX ) - bCreateField = false; - break; } - default: + break; + } + } + if (m_bStartTOC && (aIt->second.eFieldId == FIELD_PAGEREF) ) + { + bCreateField = false; + } + + if( bCreateField || bCreateEnhancedField ) + { + //add the service prefix + OUString sServiceName("com.sun.star.text."); + if ( bCreateEnhancedField ) { - FieldContextPtr pOuter = GetParentFieldContext(m_aFieldStack); - if (pOuter) - { - if (!IsFieldNestingAllowed(pOuter, m_aFieldStack.back())) - { - // Parent field can't host this child field: don't create a child field - // in this case. - bCreateField = false; - } - } - break; + const FieldConversionMap_t& aEnhancedFieldConversionMap = lcl_GetEnhancedFieldConversion(); + FieldConversionMap_t::const_iterator aEnhancedIt = + aEnhancedFieldConversionMap.find(sType); + if ( aEnhancedIt != aEnhancedFieldConversionMap.end()) + sServiceName += OUString::createFromAscii(aEnhancedIt->second.cFieldServiceName ); } - } - if (m_bStartTOC && (aIt->second.eFieldId == FIELD_PAGEREF) ) + else { - bCreateField = false; + sServiceName += "TextField." + OUString::createFromAscii(aIt->second.cFieldServiceName ); } - if( bCreateField || bCreateEnhancedField ) - { - //add the service prefix - OUString sServiceName("com.sun.star.text."); - if ( bCreateEnhancedField ) - { - const FieldConversionMap_t& aEnhancedFieldConversionMap = lcl_GetEnhancedFieldConversion(); - FieldConversionMap_t::const_iterator aEnhancedIt = - aEnhancedFieldConversionMap.find(sType); - if ( aEnhancedIt != aEnhancedFieldConversionMap.end()) - sServiceName += OUString::createFromAscii(aEnhancedIt->second.cFieldServiceName ); - } - else - { - sServiceName += "TextField." + OUString::createFromAscii(aIt->second.cFieldServiceName ); - } - #ifdef DBG_UTIL - TagLogger::getInstance().startElement("fieldService"); - TagLogger::getInstance().chars(sServiceName); - TagLogger::getInstance().endElement(); + TagLogger::getInstance().startElement("fieldService"); + TagLogger::getInstance().chars(sServiceName); + TagLogger::getInstance().endElement(); #endif - if (m_xTextFactory.is()) - { - xFieldInterface = m_xTextFactory->createInstance(sServiceName); - xFieldProperties.set( xFieldInterface, uno::UNO_QUERY_THROW); - } + if (m_xTextFactory.is()) + { + xFieldInterface = m_xTextFactory->createInstance(sServiceName); + xFieldProperties.set( xFieldInterface, uno::UNO_QUERY_THROW); } - switch( aIt->second.eFieldId ) + } + switch( aIt->second.eFieldId ) + { + case FIELD_ADDRESSBLOCK: break; + case FIELD_ADVANCE : break; + case FIELD_ASK : + handleFieldAsk(pContext, xFieldInterface, xFieldProperties); + break; + case FIELD_AUTONUM : + case FIELD_AUTONUMLGL : + case FIELD_AUTONUMOUT : + handleAutoNum(pContext, xFieldInterface, xFieldProperties); + break; + case FIELD_AUTHOR : + case FIELD_USERNAME : + case FIELD_USERINITIALS : + handleAuthor(sFirstParam, + xFieldProperties, + aIt->second.eFieldId); + break; + case FIELD_DATE: + if (xFieldProperties.is()) { - case FIELD_ADDRESSBLOCK: break; - case FIELD_ADVANCE : break; - case FIELD_ASK : - handleFieldAsk(pContext, xFieldInterface, xFieldProperties); - break; - case FIELD_AUTONUM : - case FIELD_AUTONUMLGL : - case FIELD_AUTONUMOUT : - handleAutoNum(pContext, xFieldInterface, xFieldProperties); - break; - case FIELD_AUTHOR : - case FIELD_USERNAME : - case FIELD_USERINITIALS : - handleAuthor(sFirstParam, - xFieldProperties, - aIt->second.eFieldId); - break; - case FIELD_DATE: - if (xFieldProperties.is()) + // Get field fixed property from the context handler + if (pContext->IsFieldLocked()) { - // Get field fixed property from the context handler - if (pContext->IsFieldLocked()) - { - xFieldProperties->setPropertyValue( - getPropertyName(PROP_IS_FIXED), - uno::makeAny( true )); - m_bSetDateValue = true; - } - else - xFieldProperties->setPropertyValue( - getPropertyName(PROP_IS_FIXED), - uno::makeAny( false )); - xFieldProperties->setPropertyValue( - getPropertyName(PROP_IS_DATE), + getPropertyName(PROP_IS_FIXED), uno::makeAny( true )); - SetNumberFormat( pContext->GetCommand(), xFieldProperties ); + m_bSetDateValue = true; } - break; - case FIELD_COMMENTS : - { - // OUString sParam = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" COMMENTS") ); - // A parameter with COMMENTS shouldn't set fixed - // ( or at least the binary filter doesn't ) - // If we set fixed then we won't export a field cmd. - // Additionally the para in COMMENTS is more like an - // instruction to set the document property comments - // with the param ( e.g. each COMMENT with a param will - // overwrite the Comments document property - // #TODO implement the above too - xFieldProperties->setPropertyValue( - getPropertyName( PROP_IS_FIXED ), uno::makeAny( false )); - //PROP_CURRENT_PRESENTATION is set later anyway - } - break; - case FIELD_CREATEDATE : - { + else xFieldProperties->setPropertyValue( - getPropertyName( PROP_IS_DATE ), uno::makeAny( true )); - SetNumberFormat( pContext->GetCommand(), xFieldProperties ); - } - break; - case FIELD_DOCPROPERTY : - handleDocProperty(pContext, sFirstParam, - xFieldInterface); - break; - case FIELD_DOCVARIABLE : + getPropertyName(PROP_IS_FIXED), + uno::makeAny( false )); + + xFieldProperties->setPropertyValue( + getPropertyName(PROP_IS_DATE), + uno::makeAny( true )); + SetNumberFormat( pContext->GetCommand(), xFieldProperties ); + } + break; + case FIELD_COMMENTS : + { + // OUString sParam = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" COMMENTS") ); + // A parameter with COMMENTS shouldn't set fixed + // ( or at least the binary filter doesn't ) + // If we set fixed then we won't export a field cmd. + // Additionally the para in COMMENTS is more like an + // instruction to set the document property comments + // with the param ( e.g. each COMMENT with a param will + // overwrite the Comments document property + // #TODO implement the above too + xFieldProperties->setPropertyValue( + getPropertyName( PROP_IS_FIXED ), uno::makeAny( false )); + //PROP_CURRENT_PRESENTATION is set later anyway + } + break; + case FIELD_CREATEDATE : + { + xFieldProperties->setPropertyValue( + getPropertyName( PROP_IS_DATE ), uno::makeAny( true )); + SetNumberFormat( pContext->GetCommand(), xFieldProperties ); + } + break; + case FIELD_DOCPROPERTY : + handleDocProperty(pContext, sFirstParam, + xFieldInterface); + break; + case FIELD_DOCVARIABLE : + { + //create a user field and type + uno::Reference< beans::XPropertySet > xMaster = + FindOrCreateFieldMaster("com.sun.star.text.FieldMaster.User", sFirstParam); + uno::Reference< text::XDependentTextField > xDependentField( xFieldInterface, uno::UNO_QUERY_THROW ); + xDependentField->attachTextFieldMaster( xMaster ); + m_bSetUserFieldContent = true; + } + break; + case FIELD_EDITTIME : + //it's a numbering type, no number format! SetNumberFormat( pContext->GetCommand(), xFieldProperties ); + break; + case FIELD_EQ: + { + OUString aCommand = pContext->GetCommand().trim(); + + msfilter::util::EquationResult aResult(msfilter::util::ParseCombinedChars(aCommand)); + if (!aResult.sType.isEmpty() && m_xTextFactory.is()) { - //create a user field and type - uno::Reference< beans::XPropertySet > xMaster = - FindOrCreateFieldMaster("com.sun.star.text.FieldMaster.User", sFirstParam); - uno::Reference< text::XDependentTextField > xDependentField( xFieldInterface, uno::UNO_QUERY_THROW ); - xDependentField->attachTextFieldMaster( xMaster ); - m_bSetUserFieldContent = true; + xFieldInterface = m_xTextFactory->createInstance("com.sun.star.text.TextField." + aResult.sType); + xFieldProperties = + uno::Reference< beans::XPropertySet >( xFieldInterface, + uno::UNO_QUERY_THROW); + xFieldProperties->setPropertyValue(getPropertyName(PROP_CONTENT), uno::makeAny(aResult.sResult)); } - break; - case FIELD_EDITTIME : - //it's a numbering type, no number format! SetNumberFormat( pContext->GetCommand(), xFieldProperties ); - break; - case FIELD_EQ: + else { - OUString aCommand = pContext->GetCommand().trim(); - - msfilter::util::EquationResult aResult(msfilter::util::ParseCombinedChars(aCommand)); - if (!aResult.sType.isEmpty() && m_xTextFactory.is()) - { - xFieldInterface = m_xTextFactory->createInstance("com.sun.star.text.TextField." + aResult.sType); - xFieldProperties = - uno::Reference< beans::XPropertySet >( xFieldInterface, - uno::UNO_QUERY_THROW); - xFieldProperties->setPropertyValue(getPropertyName(PROP_CONTENT), uno::makeAny(aResult.sResult)); - } - else + //merge Read_SubF_Ruby into filter/.../util.cxx and reuse that ? + sal_Int32 nSpaceIndex = aCommand.indexOf(' '); + if(nSpaceIndex > 0) + aCommand = aCommand.copy(nSpaceIndex).trim(); + if (aCommand.startsWith("\\s")) { - //merge Read_SubF_Ruby into filter/.../util.cxx and reuse that ? - sal_Int32 nSpaceIndex = aCommand.indexOf(' '); - if(nSpaceIndex > 0) - aCommand = aCommand.copy(nSpaceIndex).trim(); - if (aCommand.startsWith("\\s")) + aCommand = aCommand.copy(2); + if (aCommand.startsWith("\\do")) { - aCommand = aCommand.copy(2); - if (aCommand.startsWith("\\do")) + aCommand = aCommand.copy(3); + sal_Int32 nStartIndex = aCommand.indexOf('('); + sal_Int32 nEndIndex = aCommand.indexOf(')'); + if (nStartIndex > 0 && nEndIndex > 0) { - aCommand = aCommand.copy(3); - sal_Int32 nStartIndex = aCommand.indexOf('('); - sal_Int32 nEndIndex = aCommand.indexOf(')'); - if (nStartIndex > 0 && nEndIndex > 0) - { - // nDown is the requested "lower by" value in points. - sal_Int32 nDown = aCommand.copy(0, nStartIndex).toInt32(); - OUString aContent = aCommand.copy(nStartIndex + 1, nEndIndex - nStartIndex - 1); - PropertyMapPtr pCharContext = GetTopContext(); - // dHeight is the font size of the current style. - double dHeight = 0; - if ((GetPropertyFromParaStyleSheet(PROP_CHAR_HEIGHT) >>= dHeight) && dHeight != 0) - // Character escapement should be given in negative percents for subscripts. - pCharContext->Insert(PROP_CHAR_ESCAPEMENT, uno::makeAny( sal_Int16(- 100 * nDown / dHeight) ) ); - appendTextPortion(aContent, pCharContext); - } + // nDown is the requested "lower by" value in points. + sal_Int32 nDown = aCommand.copy(0, nStartIndex).toInt32(); + OUString aContent = aCommand.copy(nStartIndex + 1, nEndIndex - nStartIndex - 1); + PropertyMapPtr pCharContext = GetTopContext(); + // dHeight is the font size of the current style. + double dHeight = 0; + if ((GetPropertyFromParaStyleSheet(PROP_CHAR_HEIGHT) >>= dHeight) && dHeight != 0) + // Character escapement should be given in negative percents for subscripts. + pCharContext->Insert(PROP_CHAR_ESCAPEMENT, uno::makeAny( sal_Int16(- 100 * nDown / dHeight) ) ); + appendTextPortion(aContent, pCharContext); } } - else if (aCommand.startsWith("\\* jc")) - { - handleRubyEQField(pContext); - } + } + else if (aCommand.startsWith("\\* jc")) + { + handleRubyEQField(pContext); } } - break; - case FIELD_FILLIN : - if (xFieldProperties.is()) - xFieldProperties->setPropertyValue( - getPropertyName(PROP_HINT), uno::makeAny( pContext->GetCommand().getToken(1, '\"'))); - break; - case FIELD_FILENAME: + } + break; + case FIELD_FILLIN : + if (xFieldProperties.is()) + xFieldProperties->setPropertyValue( + getPropertyName(PROP_HINT), uno::makeAny( pContext->GetCommand().getToken(1, '\"'))); + break; + case FIELD_FILENAME: + { + sal_Int32 nNumberingTypeIndex = pContext->GetCommand().indexOf("\\p"); + if (xFieldProperties.is()) + xFieldProperties->setPropertyValue( + getPropertyName(PROP_FILE_FORMAT), + uno::makeAny( nNumberingTypeIndex > 0 ? text::FilenameDisplayFormat::FULL : text::FilenameDisplayFormat::NAME_AND_EXT )); + } + break; + case FIELD_FILESIZE : break; + case FIELD_FORMULA : + handleFieldFormula(pContext, xFieldProperties); + break; + case FIELD_FORMCHECKBOX : + case FIELD_FORMDROPDOWN : + case FIELD_FORMTEXT : { - sal_Int32 nNumberingTypeIndex = pContext->GetCommand().indexOf("\\p"); - if (xFieldProperties.is()) - xFieldProperties->setPropertyValue( - getPropertyName(PROP_FILE_FORMAT), - uno::makeAny( nNumberingTypeIndex > 0 ? text::FilenameDisplayFormat::FULL : text::FilenameDisplayFormat::NAME_AND_EXT )); - } - break; - case FIELD_FILESIZE : break; - case FIELD_FORMULA : - handleFieldFormula(pContext, xFieldProperties); - break; - case FIELD_FORMCHECKBOX : - case FIELD_FORMDROPDOWN : - case FIELD_FORMTEXT : + uno::Reference< text::XTextField > xTextField( xFieldInterface, uno::UNO_QUERY ); + if ( !xTextField.is() ) { - uno::Reference< text::XTextField > xTextField( xFieldInterface, uno::UNO_QUERY ); - if ( !xTextField.is() ) + FFDataHandler::Pointer_t + pFFDataHandler(pContext->getFFDataHandler()); + FormControlHelper::Pointer_t + pFormControlHelper(new FormControlHelper + (m_bUsingEnhancedFields ? aIt->second.eFieldId : FIELD_FORMCHECKBOX, + + m_xTextDocument, pFFDataHandler)); + pContext->setFormControlHelper(pFormControlHelper); + uno::Reference< text::XFormField > xFormField( xFieldInterface, uno::UNO_QUERY ); + uno::Reference< container::XNamed > xNamed( xFormField, uno::UNO_QUERY ); + if ( xNamed.is() ) { - FFDataHandler::Pointer_t - pFFDataHandler(pContext->getFFDataHandler()); - FormControlHelper::Pointer_t - pFormControlHelper(new FormControlHelper - (m_bUsingEnhancedFields ? aIt->second.eFieldId : FIELD_FORMCHECKBOX, - - m_xTextDocument, pFFDataHandler)); - pContext->setFormControlHelper(pFormControlHelper); - uno::Reference< text::XFormField > xFormField( xFieldInterface, uno::UNO_QUERY ); - uno::Reference< container::XNamed > xNamed( xFormField, uno::UNO_QUERY ); - if ( xNamed.is() ) - { - if ( pFFDataHandler && !pFFDataHandler->getName().isEmpty() ) - xNamed->setName( pFFDataHandler->getName() ); - pContext->SetFormField( xFormField ); - } - InsertFieldmark(m_aTextAppendStack, - xFormField, pContext->GetStartRange(), - pContext->GetFieldId()); + if ( pFFDataHandler && !pFFDataHandler->getName().isEmpty() ) + xNamed->setName( pFFDataHandler->getName() ); + pContext->SetFormField( xFormField ); } + InsertFieldmark(m_aTextAppendStack, + xFormField, pContext->GetStartRange(), + pContext->GetFieldId()); + } + else + { + if ( aIt->second.eFieldId == FIELD_FORMDROPDOWN ) + lcl_handleDropdownField( xFieldProperties, pContext->getFFDataHandler() ); else - { - if ( aIt->second.eFieldId == FIELD_FORMDROPDOWN ) - lcl_handleDropdownField( xFieldProperties, pContext->getFFDataHandler() ); - else - lcl_handleTextField( xFieldProperties, pContext->getFFDataHandler() ); - } + lcl_handleTextField( xFieldProperties, pContext->getFFDataHandler() ); } - break; - case FIELD_GOTOBUTTON : break; - case FIELD_HYPERLINK: - { - ::std::vector<OUString> aParts = pContext->GetCommandParts(); + } + break; + case FIELD_GOTOBUTTON : break; + case FIELD_HYPERLINK: + { + ::std::vector<OUString> aParts = pContext->GetCommandParts(); - // Syntax is either: - // HYPERLINK "" \l "link" - // or - // HYPERLINK \l "link" - // Make sure "HYPERLINK" doesn't end up as part of link in the second case. - if (!aParts.empty() && aParts[0] == "HYPERLINK") - aParts.erase(aParts.begin()); + // Syntax is either: + // HYPERLINK "" \l "link" + // or + // HYPERLINK \l "link" + // Make sure "HYPERLINK" doesn't end up as part of link in the second case. + if (!aParts.empty() && aParts[0] == "HYPERLINK") + aParts.erase(aParts.begin()); - ::std::vector<OUString>::const_iterator aItEnd = aParts.end(); - ::std::vector<OUString>::const_iterator aPartIt = aParts.begin(); + ::std::vector<OUString>::const_iterator aItEnd = aParts.end(); + ::std::vector<OUString>::const_iterator aPartIt = aParts.begin(); - OUString sURL; - OUString sTarget; + OUString sURL; + OUString sTarget; - while (aPartIt != aItEnd) + while (aPartIt != aItEnd) + { + if ( *aPartIt == "\\l" ) { - if ( *aPartIt == "\\l" ) - { - ++aPartIt; - - if (aPartIt == aItEnd) - break; + ++aPartIt; - sURL += "#" + *aPartIt; - } - else if (*aPartIt == "\\m" || *aPartIt == "\\n" || *aPartIt == "\\h") - { - } - else if ( *aPartIt == "\\o" || *aPartIt == "\\t" ) - { - ++aPartIt; + if (aPartIt == aItEnd) + break; - if (aPartIt == aItEnd) - break; + sURL += "#" + *aPartIt; + } + else if (*aPartIt == "\\m" || *aPartIt == "\\n" || *aPartIt == "\\h") + { + } + else if ( *aPartIt == "\\o" || *aPartIt == "\\t" ) + { + ++aPartIt; - sTarget = *aPartIt; - } - else - { - sURL = *aPartIt; - } + if (aPartIt == aItEnd) + break; - ++aPartIt; + sTarget = *aPartIt; } - - if (!sURL.isEmpty()) + else { - if (sURL.startsWith("file:///")) - { - // file:///absolute\\path\\to\\file => invalid file URI (Writer cannot open) - // convert all double backslashes to slashes: - sURL = sURL.replaceAll("\\\\", "/"); - - // file:///absolute\path\to\file => invalid file URI (Writer cannot open) - // convert all backslashes to slashes: - sURL = sURL.replace('\\', '/'); - } - // Try to make absolute any relative URLs, except - // for relative same-document URLs that only contain - // a fragment part: - else if (!sURL.startsWith("#")) { - try { - sURL = rtl::Uri::convertRelToAbs( - m_aBaseUrl, sURL); - } catch (rtl::MalformedUriException & e) { - SAL_WARN( - "writerfilter.dmapper", - "MalformedUriException " - << e.getMessage()); - } - } - pContext->SetHyperlinkURL(sURL); + sURL = *aPartIt; } - if (!sTarget.isEmpty()) - pContext->SetHyperlinkTarget(sTarget); + ++aPartIt; } - break; - case FIELD_IF : break; - case FIELD_INFO : break; - case FIELD_INCLUDEPICTURE: break; - case FIELD_KEYWORDS : + + if (!sURL.isEmpty()) { - if (!sFirstParam.isEmpty()) + if (sURL.startsWith("file:///")) { - xFieldProperties->setPropertyValue( - getPropertyName( PROP_IS_FIXED ), uno::makeAny( true )); - //PROP_CURRENT_PRESENTATION is set later anyway + // file:///absolute\\path\\to\\file => invalid file URI (Writer cannot open) + // convert all double backslashes to slashes: + sURL = sURL.replaceAll("\\\\", "/"); + + // file:///absolute\path\to\file => invalid file URI (Writer cannot open) + // convert all backslashes to slashes: + sURL = sURL.replace('\\', '/'); } - } - break; - case FIELD_LASTSAVEDBY : break; - case FIELD_MACROBUTTON: - { - //extract macro name - sal_Int32 nIndex = sizeof(" MACROBUTTON "); - OUString sMacro = pContext->GetCommand().getToken( 0, ' ', nIndex); - if (xFieldProperties.is()) - xFieldProperties->setPropertyValue( - getPropertyName(PROP_MACRO_NAME), uno::makeAny( sMacro )); - - //extract quick help text - if(xFieldProperties.is() && pContext->GetCommand().getLength() > nIndex + 1) - { - xFieldProperties->setPropertyValue( - getPropertyName(PROP_HINT), - uno::makeAny( pContext->GetCommand().copy( nIndex ))); + // Try to make absolute any relative URLs, except + // for relative same-document URLs that only contain + // a fragment part: + else if (!sURL.startsWith("#")) { + try { + sURL = rtl::Uri::convertRelToAbs( + m_aBaseUrl, sURL); + } catch (rtl::MalformedUriException & e) { + SAL_WARN( + "writerfilter.dmapper", + "MalformedUriException " + << e.getMessage()); + } } + pContext->SetHyperlinkURL(sURL); } - break; - case FIELD_MERGEFIELD : - { - //todo: create a database field and fieldmaster pointing to a column, only - //create a user field and type - uno::Reference< beans::XPropertySet > xMaster = - FindOrCreateFieldMaster("com.sun.star.text.FieldMaster.Database", sFirstParam); - - // xFieldProperties->setPropertyValue( - // "FieldCode", - // uno::makeAny( pContext->GetCommand().copy( nIndex + 1 ))); - uno::Reference< text::XDependentTextField > xDependentField( xFieldInterface, uno::UNO_QUERY_THROW ); - xDependentField->attachTextFieldMaster( xMaster ); - } - break; - case FIELD_MERGEREC : break; - case FIELD_MERGESEQ : break; - case FIELD_NEXT : break; - case FIELD_NEXTIF : break; - case FIELD_PAGE : - if (xFieldProperties.is()) - { - xFieldProperties->setPropertyValue( - getPropertyName(PROP_NUMBERING_TYPE), - uno::makeAny( lcl_ParseNumberingType(pContext->GetCommand()) )); - xFieldProperties->setPropertyValue( - getPropertyName(PROP_SUB_TYPE), - uno::makeAny( text::PageNumberType_CURRENT )); - } - break; - case FIELD_PAGEREF: - case FIELD_REF: - if (xFieldProperties.is() && !m_bStartTOC) + if (!sTarget.isEmpty()) + pContext->SetHyperlinkTarget(sTarget); + } + break; + case FIELD_IF : break; + case FIELD_INFO : break; + case FIELD_INCLUDEPICTURE: break; + case FIELD_KEYWORDS : + { + if (!sFirstParam.isEmpty()) { - bool bPageRef = aIt->second.eFieldId == FIELD_PAGEREF; - - // Do we need a GetReference (default) or a GetExpression field? - uno::Reference< text::XTextFieldsSupplier > xFieldsSupplier( GetTextDocument(), uno::UNO_QUERY ); - uno::Reference< container::XNameAccess > xFieldMasterAccess = xFieldsSupplier->getTextFieldMasters(); - - if (!xFieldMasterAccess->hasByName( - "com.sun.star.text.FieldMaster.SetExpression." - + sFirstParam)) - { xFieldProperties->setPropertyValue( - getPropertyName(PROP_REFERENCE_FIELD_SOURCE), - uno::makeAny( sal_Int16(text::ReferenceFieldSource::BOOKMARK)) ); + getPropertyName( PROP_IS_FIXED ), uno::makeAny( true )); + //PROP_CURRENT_PRESENTATION is set later anyway + } + } + break; + case FIELD_LASTSAVEDBY : break; + case FIELD_MACROBUTTON: + { + //extract macro name + sal_Int32 nIndex = sizeof(" MACROBUTTON "); + OUString sMacro = pContext->GetCommand().getToken( 0, ' ', nIndex); + if (xFieldProperties.is()) xFieldProperties->setPropertyValue( - getPropertyName(PROP_SOURCE_NAME), - uno::makeAny(sFirstParam) ); - sal_Int16 nFieldPart = (bPageRef ? text::ReferenceFieldPart::PAGE : text::ReferenceFieldPart::TEXT); - OUString sValue; - if( lcl_FindInCommand( pContext->GetCommand(), 'p', sValue )) - { - //above-below - nFieldPart = text::ReferenceFieldPart::UP_DOWN; - } - else if( lcl_FindInCommand( pContext->GetCommand(), 'r', sValue )) - { - //number - nFieldPart = text::ReferenceFieldPart::NUMBER; - } - else if( lcl_FindInCommand( pContext->GetCommand(), 'n', sValue )) - { - //number-no-context - nFieldPart = text::ReferenceFieldPart::NUMBER_NO_CONTEXT; - } - else if( lcl_FindInCommand( pContext->GetCommand(), 'w', sValue )) - { - //number-full-context - nFieldPart = text::ReferenceFieldPart::NUMBER_FULL_CONTEXT; - } + getPropertyName(PROP_MACRO_NAME), uno::makeAny( sMacro )); + + //extract quick help text + if(xFieldProperties.is() && pContext->GetCommand().getLength() > nIndex + 1) + { xFieldProperties->setPropertyValue( - getPropertyName( PROP_REFERENCE_FIELD_PART ), uno::makeAny( nFieldPart )); - } - else if( m_xTextFactory.is() ) - { - xFieldInterface = m_xTextFactory->createInstance("com.sun.star.text.TextField.GetExpression"); - xFieldProperties.set(xFieldInterface, uno::UNO_QUERY); - xFieldProperties->setPropertyValue( - getPropertyName(PROP_CONTENT), - uno::makeAny(sFirstParam)); - xFieldProperties->setPropertyValue(getPropertyName(PROP_SUB_TYPE), uno::makeAny(text::SetVariableType::STRING)); - } + getPropertyName(PROP_HINT), + uno::makeAny( pContext->GetCommand().copy( nIndex ))); } - break; - case FIELD_REVNUM : break; - case FIELD_SAVEDATE : - SetNumberFormat( pContext->GetCommand(), xFieldProperties ); - break; - case FIELD_SECTION : break; - case FIELD_SECTIONPAGES : break; - case FIELD_SEQ : + } + break; + case FIELD_MERGEFIELD : + { + //todo: create a database field and fieldmaster pointing to a column, only + //create a user field and type + uno::Reference< beans::XPropertySet > xMaster = + FindOrCreateFieldMaster("com.sun.star.text.FieldMaster.Database", sFirstParam); + +// xFieldProperties->setPropertyValue( +// "FieldCode", +// uno::makeAny( pContext->GetCommand().copy( nIndex + 1 ))); + uno::Reference< text::XDependentTextField > xDependentField( xFieldInterface, uno::UNO_QUERY_THROW ); + xDependentField->attachTextFieldMaster( xMaster ); + } + break; + case FIELD_MERGEREC : break; + case FIELD_MERGESEQ : break; + case FIELD_NEXT : break; + case FIELD_NEXTIF : break; + case FIELD_PAGE : + if (xFieldProperties.is()) { - // command looks like: " SEQ Table \* ARABIC " - OUString sCmd(pContext->GetCommand()); - // find the sequence name, e.g. "SEQ" - OUString sSeqName = msfilter::util::findQuotedText(sCmd, "SEQ ", '\\'); - sSeqName = sSeqName.trim(); - - // create a sequence field master using the sequence name - uno::Reference< beans::XPropertySet > xMaster = FindOrCreateFieldMaster( - "com.sun.star.text.FieldMaster.SetExpression", - sSeqName); - - xMaster->setPropertyValue( - getPropertyName(PROP_SUB_TYPE), - uno::makeAny(text::SetVariableType::SEQUENCE)); - - // apply the numbering type xFieldProperties->setPropertyValue( - getPropertyName(PROP_NUMBERING_TYPE), - uno::makeAny( lcl_ParseNumberingType(pContext->GetCommand()) )); + getPropertyName(PROP_NUMBERING_TYPE), + uno::makeAny( lcl_ParseNumberingType(pContext->GetCommand()) )); + xFieldProperties->setPropertyValue( + getPropertyName(PROP_SUB_TYPE), + uno::makeAny( text::PageNumberType_CURRENT )); + } - // attach the master to the field - uno::Reference< text::XDependentTextField > xDependentField( xFieldInterface, uno::UNO_QUERY_THROW ); - xDependentField->attachTextFieldMaster( xMaster ); + break; + case FIELD_PAGEREF: + case FIELD_REF: + if (xFieldProperties.is() && !m_bStartTOC) + { + bool bPageRef = aIt->second.eFieldId == FIELD_PAGEREF; - OUString sFormula = sSeqName + "+1"; - OUString sValue; - if( lcl_FindInCommand( pContext->GetCommand(), 'c', sValue )) - { - sFormula = sSeqName; - } - else if( lcl_FindInCommand( pContext->GetCommand(), 'r', sValue )) - { - sFormula = sValue; - } - // TODO \s isn't handled, but the spec isn't easy to understand without - // an example for this one. - xFieldProperties->setPropertyValue( - getPropertyName(PROP_CONTENT), - uno::makeAny(sFormula)); + // Do we need a GetReference (default) or a GetExpression field? + uno::Reference< text::XTextFieldsSupplier > xFieldsSupplier( GetTextDocument(), uno::UNO_QUERY ); + uno::Reference< container::XNameAccess > xFieldMasterAccess = xFieldsSupplier->getTextFieldMasters(); - // Take care of the numeric formatting definition, default is Arabic - sal_Int16 nNumberingType = lcl_ParseNumberingType(pContext->GetCommand()); - if (nNumberingType == style::NumberingType::PAGE_DESCRIPTOR) - nNumberingType = style::NumberingType::ARABIC; + if (!xFieldMasterAccess->hasByName( + "com.sun.star.text.FieldMaster.SetExpression." + + sFirstParam)) + { + xFieldProperties->setPropertyValue( + getPropertyName(PROP_REFERENCE_FIELD_SOURCE), + uno::makeAny( sal_Int16(text::ReferenceFieldSource::BOOKMARK)) ); + xFieldProperties->setPropertyValue( + getPropertyName(PROP_SOURCE_NAME), + uno::makeAny(sFirstParam) ); + sal_Int16 nFieldPart = (bPageRef ? text::ReferenceFieldPart::PAGE : text::ReferenceFieldPart::TEXT); + OUString sValue; + if( lcl_FindInCommand( pContext->GetCommand(), 'p', sValue )) + { + //above-below + nFieldPart = text::ReferenceFieldPart::UP_DOWN; + } + else if( lcl_FindInCommand( pContext->GetCommand(), 'r', sValue )) + { + //number + nFieldPart = text::ReferenceFieldPart::NUMBER; + } + else if( lcl_FindInCommand( pContext->GetCommand(), 'n', sValue )) + { + //number-no-context + nFieldPart = text::ReferenceFieldPart::NUMBER_NO_CONTEXT; + } + else if( lcl_FindInCommand( pContext->GetCommand(), 'w', sValue )) + { + //number-full-context + nFieldPart = text::ReferenceFieldPart::NUMBER_FULL_CONTEXT; + } + xFieldProperties->setPropertyValue( + getPropertyName( PROP_REFERENCE_FIELD_PART ), uno::makeAny( nFieldPart )); + } + else if( m_xTextFactory.is() ) + { + xFieldInterface = m_xTextFactory->createInstance("com.sun.star.text.TextField.GetExpression"); + xFieldProperties.set(xFieldInterface, uno::UNO_QUERY); xFieldProperties->setPropertyValue( - getPropertyName(PROP_NUMBERING_TYPE), - uno::makeAny(nNumberingType)); + getPropertyName(PROP_CONTENT), + uno::makeAny(sFirstParam)); + xFieldProperties->setPropertyValue(getPropertyName(PROP_SUB_TYPE), uno::makeAny(text::SetVariableType::STRING)); } - break; - case FIELD_SET : - handleFieldSet(pContext, xFieldInterface, xFieldProperties); - break; - case FIELD_SKIPIF : break; - case FIELD_STYLEREF : break; - case FIELD_SUBJECT : + } + break; + case FIELD_REVNUM : break; + case FIELD_SAVEDATE : + SetNumberFormat( pContext->GetCommand(), xFieldProperties ); + break; + case FIELD_SECTION : break; + case FIELD_SECTIONPAGES : break; + case FIELD_SEQ : + { + // command looks like: " SEQ Table \* ARABIC " + OUString sCmd(pContext->GetCommand()); + // find the sequence name, e.g. "SEQ" + OUString sSeqName = msfilter::util::findQuotedText(sCmd, "SEQ ", '\\'); + sSeqName = sSeqName.trim(); + + // create a sequence field master using the sequence name + uno::Reference< beans::XPropertySet > xMaster = FindOrCreateFieldMaster( + "com.sun.star.text.FieldMaster.SetExpression", + sSeqName); + + xMaster->setPropertyValue( + getPropertyName(PROP_SUB_TYPE), + uno::makeAny(text::SetVariableType::SEQUENCE)); + + // apply the numbering type + xFieldProperties->setPropertyValue( + getPropertyName(PROP_NUMBERING_TYPE), + uno::makeAny( lcl_ParseNumberingType(pContext->GetCommand()) )); + + // attach the master to the field + uno::Reference< text::XDependentTextField > xDependentField( xFieldInterface, uno::UNO_QUERY_THROW ); + xDependentField->attachTextFieldMaster( xMaster ); + + OUString sFormula = sSeqName + "+1"; + OUString sValue; + if( lcl_FindInCommand( pContext->GetCommand(), 'c', sValue )) { - if (!sFirstParam.isEmpty()) - { - xFieldProperties->setPropertyValue( - getPropertyName( PROP_IS_FIXED ), uno::makeAny( true )); - //PROP_CURRENT_PRESENTATION is set later anyway - } + sFormula = sSeqName; } - break; - case FIELD_SYMBOL: + else if( lcl_FindInCommand( pContext->GetCommand(), 'r', sValue )) { - uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend; - OUString sSymbol( sal_Unicode( sFirstParam.startsWithIgnoreAsciiCase("0x") ? sFirstParam.copy(2).toUInt32(16) : sFirstParam.toUInt32() ) ); - OUString sFont; - bool bHasFont = lcl_FindInCommand( pContext->GetCommand(), 'f', sFont); - if ( bHasFont ) - { - sFont = sFont.trim(); - if (sFont.startsWith("\"")) - sFont = sFont.copy(1); - if (sFont.endsWith("\"")) - sFont = sFont.copy(0,sFont.getLength()-1); - } + sFormula = sValue; + } + // TODO \s isn't handled, but the spec isn't easy to understand without + // an example for this one. + xFieldProperties->setPropertyValue( + getPropertyName(PROP_CONTENT), + uno::makeAny(sFormula)); + + // Take care of the numeric formatting definition, default is Arabic + sal_Int16 nNumberingType = lcl_ParseNumberingType(pContext->GetCommand()); + if (nNumberingType == style::NumberingType::PAGE_DESCRIPTOR) + nNumberingType = style::NumberingType::ARABIC; + xFieldProperties->setPropertyValue( + getPropertyName(PROP_NUMBERING_TYPE), + uno::makeAny(nNumberingType)); + } + break; + case FIELD_SET : + handleFieldSet(pContext, xFieldInterface, xFieldProperties); + break; + case FIELD_SKIPIF : break; + case FIELD_STYLEREF : break; + case FIELD_SUBJECT : + { + if (!sFirstParam.isEmpty()) + { + xFieldProperties->setPropertyValue( + getPropertyName( PROP_IS_FIXED ), uno::makeAny( true )); + //PROP_CURRENT_PRESENTATION is set later anyway + } + } + break; + case FIELD_SYMBOL: + { + uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend; + OUString sSymbol( sal_Unicode( sFirstParam.startsWithIgnoreAsciiCase("0x") ? sFirstParam.copy(2).toUInt32(16) : sFirstParam.toUInt32() ) ); + OUString sFont; + bool bHasFont = lcl_FindInCommand( pContext->GetCommand(), 'f', sFont); + if ( bHasFont ) + { + sFont = sFont.trim(); + if (sFont.startsWith("\"")) + sFont = sFont.copy(1); + if (sFont.endsWith("\"")) + sFont = sFont.copy(0,sFont.getLength()-1); + } - if (xTextAppend.is()) + if (xTextAppend.is()) + { + uno::Reference< text::XText > xText = xTextAppend->getText(); + uno::Reference< text::XTextCursor > xCrsr = xText->createTextCursor(); + if (xCrsr.is()) { - uno::Reference< text::XText > xText = xTextAppend->getText(); - uno::Reference< text::XTextCursor > xCrsr = xText->createTextCursor(); - if (xCrsr.is()) + xCrsr->gotoEnd(false); + xText->insertString(xCrsr, sSymbol, true); + uno::Reference< beans::XPropertySet > xProp( xCrsr, uno::UNO_QUERY ); + xProp->setPropertyValue(getPropertyName(PROP_CHAR_FONT_CHAR_SET), uno::makeAny(awt::CharSet::SYMBOL)); + if(bHasFont) { - xCrsr->gotoEnd(false); - xText->insertString(xCrsr, sSymbol, true); - uno::Reference< beans::XPropertySet > xProp( xCrsr, uno::UNO_QUERY ); - xProp->setPropertyValue(getPropertyName(PROP_CHAR_FONT_CHAR_SET), uno::makeAny(awt::CharSet::SYMBOL)); - if(bHasFont) - { - uno::Any aVal = uno::makeAny( sFont ); - xProp->setPropertyValue(getPropertyName(PROP_CHAR_FONT_NAME), aVal); - xProp->setPropertyValue(getPropertyName(PROP_CHAR_FONT_NAME_ASIAN), aVal); - xProp->setPropertyValue(getPropertyName(PROP_CHAR_FONT_NAME_COMPLEX), aVal); + uno::Any aVal = uno::makeAny( sFont ); + xProp->setPropertyValue(getPropertyName(PROP_CHAR_FONT_NAME), aVal); + xProp->setPropertyValue(getPropertyName(PROP_CHAR_FONT_NAME_ASIAN), aVal); + xProp->setPropertyValue(getPropertyName(PROP_CHAR_FONT_NAME_COMPLEX), aVal); - } } } } - break; - case FIELD_TEMPLATE: break; - case FIELD_TIME : + } + break; + case FIELD_TEMPLATE: break; + case FIELD_TIME : + { + if (pContext->IsFieldLocked()) { - if (pContext->IsFieldLocked()) - { - xFieldProperties->setPropertyValue( - getPropertyName(PROP_IS_FIXED), - uno::makeAny( true )); - m_bSetDateValue = true; - } - SetNumberFormat( pContext->GetCommand(), xFieldProperties ); + xFieldProperties->setPropertyValue( + getPropertyName(PROP_IS_FIXED), + uno::makeAny( true )); + m_bSetDateValue = true; } - break; - case FIELD_TITLE : + SetNumberFormat( pContext->GetCommand(), xFieldProperties ); + } + break; + case FIELD_TITLE : + { + if (!sFirstParam.isEmpty()) { - if (!sFirstParam.isEmpty()) - { - xFieldProperties->setPropertyValue( - getPropertyName( PROP_IS_FIXED ), uno::makeAny( true )); - //PROP_CURRENT_PRESENTATION is set later anyway - } + xFieldProperties->setPropertyValue( + getPropertyName( PROP_IS_FIXED ), uno::makeAny( true )); + //PROP_CURRENT_PRESENTATION is set later anyway } + } + break; + case FIELD_USERADDRESS : //todo: user address collects street, city ... + break; + case FIELD_INDEX: + handleIndex(pContext, + OUString::createFromAscii(aIt->second.cFieldServiceName)); break; - case FIELD_USERADDRESS : //todo: user address collects street, city ... + case FIELD_BIBLIOGRAPHY: + handleBibliography(pContext, + OUString::createFromAscii(aIt->second.cFieldServiceName)); break; - case FIELD_INDEX: - handleIndex(pContext, - OUString::createFromAscii(aIt->second.cFieldServiceName)); - break; - case FIELD_BIBLIOGRAPHY: - handleBibliography(pContext, - OUString::createFromAscii(aIt->second.cFieldServiceName)); + case FIELD_TOC: + handleToc(pContext, + OUString::createFromAscii(aIt->second.cFieldServiceName)); + break; + case FIELD_XE: + { + if( !m_xTextFactory.is() ) break; - case FIELD_TOC: - handleToc(pContext, - OUString::createFromAscii(aIt->second.cFieldServiceName)); - break; - case FIELD_XE: - { - if( !m_xTextFactory.is() ) - break; - uno::Reference< beans::XPropertySet > xTC( - m_xTextFactory->createInstance( - OUString::createFromAscii(aIt->second.cFieldServiceName)), - uno::UNO_QUERY_THROW); - if (!sFirstParam.isEmpty()) - { - xTC->setPropertyValue("PrimaryKey", - uno::makeAny(sFirstParam)); - } - uno::Reference< text::XTextContent > xToInsert( xTC, uno::UNO_QUERY ); - uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend; - if (xTextAppend.is()) - { - uno::Reference< text::XText > xText = xTextAppend->getText(); - uno::Reference< text::XTextCursor > xCrsr = xText->createTextCursor(); - if (xCrsr.is()) - { - xCrsr->gotoEnd(false); - xText->insertTextContent(uno::Reference< text::XTextRange >( xCrsr, uno::UNO_QUERY_THROW ), xToInsert, false); - } - } - } - break; - case FIELD_CITATION: + uno::Reference< beans::XPropertySet > xTC( + m_xTextFactory->createInstance( + OUString::createFromAscii(aIt->second.cFieldServiceName)), + uno::UNO_QUERY_THROW); + if (!sFirstParam.isEmpty()) { - if( !m_xTextFactory.is() ) - break; - - xFieldInterface = m_xTextFactory->createInstance( - OUString::createFromAscii(aIt->second.cFieldServiceName)); - uno::Reference< beans::XPropertySet > xTC(xFieldInterface, - uno::UNO_QUERY_THROW); - OUString sCmd(pContext->GetCommand());//sCmd is the entire instrText including the index e.g. CITATION Kra06 \l 1033 - if( !sCmd.isEmpty()){ - uno::Sequence<beans::PropertyValue> aValues( comphelper::InitPropertySequence({ - { "Identifier", uno::Any(sCmd) } - })); - xTC->setPropertyValue("Fields", uno::makeAny(aValues)); - } - uno::Reference< text::XTextContent > xToInsert( xTC, uno::UNO_QUERY ); - - uno::Sequence<beans::PropertyValue> aValues - = m_aFieldStack.back()->getProperties()->GetPropertyValues(); - appendTextContent(xToInsert, aValues); - m_bSetCitation = true; + xTC->setPropertyValue("PrimaryKey", + uno::makeAny(sFirstParam)); } - break; - - case FIELD_TC : + uno::Reference< text::XTextContent > xToInsert( xTC, uno::UNO_QUERY ); + uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend; + if (xTextAppend.is()) { - if( !m_xTextFactory.is() ) - break; - - uno::Reference< beans::XPropertySet > xTC( - m_xTextFactory->createInstance( - OUString::createFromAscii(aIt->second.cFieldServiceName)), - uno::UNO_QUERY_THROW); - if (!sFirstParam.isEmpty()) - { - xTC->setPropertyValue(getPropertyName(PROP_ALTERNATIVE_TEXT), - uno::makeAny(sFirstParam)); - } - OUString sValue; - // \f TC entry in doc with multiple tables - // if( lcl_FindInCommand( pContext->GetCommand(), 'f', sValue )) - // { - // todo: unsupported - // } - if( lcl_FindInCommand( pContext->GetCommand(), 'l', sValue )) - // \l Outline Level + uno::Reference< text::XText > xText = xTextAppend->getText(); + uno::Reference< text::XTextCursor > xCrsr = xText->createTextCursor(); + if (xCrsr.is()) { - sal_Int32 nLevel = sValue.toInt32(); - if( !sValue.isEmpty() && nLevel >= 0 && nLevel <= 10 ) - xTC->setPropertyValue(getPropertyName(PROP_LEVEL), uno::makeAny( static_cast<sal_Int16>(nLevel) )); + xCrsr->gotoEnd(false); + xText->insertTextContent(uno::Reference< text::XTextRange >( xCrsr, uno::UNO_QUERY_THROW ), xToInsert, false); } - // if( lcl_FindInCommand( pContext->GetCommand(), 'n', sValue )) - // \n Suppress page numbers - // { - //todo: unsupported feature - // } - pContext->SetTC( xTC ); } + } break; - case FIELD_NUMCHARS: - case FIELD_NUMWORDS: - case FIELD_NUMPAGES: - if (xFieldProperties.is()) - xFieldProperties->setPropertyValue( - getPropertyName(PROP_NUMBERING_TYPE), - uno::makeAny( lcl_ParseNumberingType(pContext->GetCommand()) )); - break; + case FIELD_CITATION: + { + if( !m_xTextFactory.is() ) + break; + + xFieldInterface = m_xTextFactory->createInstance( + OUString::createFromAscii(aIt->second.cFieldServiceName)); + uno::Reference< beans::XPropertySet > xTC(xFieldInterface, + uno::UNO_QUERY_THROW); + OUString sCmd(pContext->GetCommand());//sCmd is the entire instrText including the index e.g. CITATION Kra06 \l 1033 + if( !sCmd.isEmpty()){ + uno::Sequence<beans::PropertyValue> aValues( comphelper::InitPropertySequence({ + { "Identifier", uno::Any(sCmd) } + })); + xTC->setPropertyValue("Fields", uno::makeAny(aValues)); + } + uno::Reference< text::XTextContent > xToInsert( xTC, uno::UNO_QUERY ); + + uno::Sequence<beans::PropertyValue> aValues + = m_aFieldStack.back()->getProperties()->GetPropertyValues(); + appendTextContent(xToInsert, aValues); + m_bSetCitation = true; } - } - else - { - /* Unsupported fields will be handled here for docx file. - * To handle unsupported fields used fieldmark API. - */ - OUString aCode( pContext->GetCommand().trim() ); - // Don't waste resources on wrapping shapes inside a fieldmark. - if (sType != "SHAPE" && m_xTextFactory.is() && !m_aTextAppendStack.empty()) + break; + + case FIELD_TC : { - xFieldInterface = m_xTextFactory->createInstance("com.sun.star.text.Fieldmark"); - - uno::Reference<text::XFormField> const xFormField(xFieldInterface, uno::UNO_QUERY); - InsertFieldmark(m_aTextAppendStack, xFormField, pContext->GetStartRange(), - pContext->GetFieldId()); - xFormField->setFieldType(ODF_UNHANDLED); - ++m_nStartGenericField; - pContext->SetFormField( xFormField ); - uno::Reference<container::XNameContainer> const xNameCont(xFormField->getParameters()); - // note: setting the code to empty string is *required* in - // m_bForceGenericFields mode, or the export will write - // the ODF_UNHANDLED string! - assert(!m_bForceGenericFields || aCode.isEmpty()); - xNameCont->insertByName(ODF_CODE_PARAM, uno::makeAny(aCode)); - ww::eField const id(GetWW8FieldId(sType)); - if (id != ww::eNONE) - { // tdf#129247 tdf#134264 set WW8 id for WW8 export - xNameCont->insertByName(ODF_ID_PARAM, uno::makeAny(OUString::number(id))); + if( !m_xTextFactory.is() ) + break; + + uno::Reference< beans::XPropertySet > xTC( + m_xTextFactory->createInstance( + OUString::createFromAscii(aIt->second.cFieldServiceName)), + uno::UNO_QUERY_THROW); + if (!sFirstParam.isEmpty()) + { + xTC->setPropertyValue(getPropertyName(PROP_ALTERNATIVE_TEXT), + uno::makeAny(sFirstParam)); } + OUString sValue; + // \f TC entry in doc with multiple tables +// if( lcl_FindInCommand( pContext->GetCommand(), 'f', sValue )) +// { + // todo: unsupported +// } + if( lcl_FindInCommand( pContext->GetCommand(), 'l', sValue )) + // \l Outline Level + { + sal_Int32 nLevel = sValue.toInt32(); + if( !sValue.isEmpty() && nLevel >= 0 && nLevel <= 10 ) + xTC->setPropertyValue(getPropertyName(PROP_LEVEL), uno::makeAny( static_cast<sal_Int16>(nLevel) )); + } +// if( lcl_FindInCommand( pContext->GetCommand(), 'n', sValue )) +// \n Suppress page numbers +// { + //todo: unsupported feature +// } + pContext->SetTC( xTC ); } - else - m_bParaHadField = false; + break; + case FIELD_NUMCHARS: + case FIELD_NUMWORDS: + case FIELD_NUMPAGES: + if (xFieldProperties.is()) + xFieldProperties->setPropertyValue( + getPropertyName(PROP_NUMBERING_TYPE), + uno::makeAny( lcl_ParseNumberingType(pContext->GetCommand()) )); + break; } - //set the text field if there is any - pContext->SetTextField( uno::Reference< text::XTextField >( xFieldInterface, uno::UNO_QUERY ) ); } - catch( const uno::Exception& ) + else { - TOOLS_WARN_EXCEPTION( "writerfilter.dmapper", "Exception in CloseFieldCommand()" ); + /* Unsupported fields will be handled here for docx file. + * To handle unsupported fields used fieldmark API. + */ + OUString aCode( pContext->GetCommand().trim() ); + // Don't waste resources on wrapping shapes inside a fieldmark. + if (sType != "SHAPE" && m_xTextFactory.is() && !m_aTextAppendStack.empty()) + { + xFieldInterface = m_xTextFactory->createInstance("com.sun.star.text.Fieldmark"); + + uno::Reference<text::XFormField> const xFormField(xFieldInterface, uno::UNO_QUERY); + InsertFieldmark(m_aTextAppendStack, xFormField, pContext->GetStartRange(), + pContext->GetFieldId()); + xFormField->setFieldType(ODF_UNHANDLED); + ++m_nStartGenericField; + pContext->SetFormField( xFormField ); + uno::Reference<container::XNameContainer> const xNameCont(xFormField->getParameters()); + // note: setting the code to empty string is *required* in + // m_bForceGenericFields mode, or the export will write + // the ODF_UNHANDLED string! + assert(!m_bForceGenericFields || aCode.isEmpty()); + xNameCont->insertByName(ODF_CODE_PARAM, uno::makeAny(aCode)); + ww::eField const id(GetWW8FieldId(sType)); + if (id != ww::eNONE) + { // tdf#129247 tdf#134264 set WW8 id for WW8 export + xNameCont->insertByName(ODF_ID_PARAM, uno::makeAny(OUString::number(id))); + } + } + else + m_bParaHadField = false; } - pContext->SetCommandCompleted(); + //set the text field if there is any + pContext->SetTextField( uno::Reference< text::XTextField >( xFieldInterface, uno::UNO_QUERY ) ); + } + catch( const uno::Exception& ) + { + TOOLS_WARN_EXCEPTION( "writerfilter.dmapper", "Exception in CloseFieldCommand()" ); } + pContext->SetCommandCompleted(); } /*------------------------------------------------------------------------- //the _current_ fields require a string type result while TOCs accept richt results @@ -5831,21 +5831,21 @@ void DomainMapper_Impl::AppendFieldResult(OUString const& rString) assert(!m_aFieldStack.empty()); FieldContextPtr pContext = m_aFieldStack.back(); SAL_WARN_IF(!pContext, "writerfilter.dmapper", "no field context"); - if (pContext) + if (!pContext) + return; + + FieldContextPtr pOuter = GetParentFieldContext(m_aFieldStack); + if (pOuter) { - FieldContextPtr pOuter = GetParentFieldContext(m_aFieldStack); - if (pOuter) + if (!IsFieldNestingAllowed(pOuter, pContext)) { - if (!IsFieldNestingAllowed(pOuter, pContext)) - { - // Child can't host the field result, forward to parent. - pOuter->AppendResult(rString); - return; - } + // Child can't host the field result, forward to parent. + pOuter->AppendResult(rString); + return; } - - pContext->AppendResult(rString); } + + pContext->AppendResult(rString); } // Calculates css::DateTime based on ddddd.sssss since 1900-1-0 @@ -5896,121 +5896,121 @@ void DomainMapper_Impl::SetFieldResult(OUString const& rResult) } } - if( pContext ) + if( !pContext ) + return; + + uno::Reference<text::XTextField> xTextField = pContext->GetTextField(); + try { - uno::Reference<text::XTextField> xTextField = pContext->GetTextField(); - try + OSL_ENSURE( xTextField.is() + //||m_xTOC.is() ||m_xTC.is() + //||m_sHyperlinkURL.getLength() + , "DomainMapper_Impl::SetFieldResult: field not created" ); + if(xTextField.is()) { - OSL_ENSURE( xTextField.is() - //||m_xTOC.is() ||m_xTC.is() - //||m_sHyperlinkURL.getLength() - , "DomainMapper_Impl::SetFieldResult: field not created" ); - if(xTextField.is()) + try { - try + if( m_bSetUserFieldContent ) + { + // user field content has to be set at the field master + uno::Reference< text::XDependentTextField > xDependentField( xTextField, uno::UNO_QUERY_THROW ); + xDependentField->getTextFieldMaster()->setPropertyValue( + getPropertyName(PROP_CONTENT), + uno::makeAny( rResult )); + } + else if ( m_bSetCitation ) { - if( m_bSetUserFieldContent ) - { - // user field content has to be set at the field master - uno::Reference< text::XDependentTextField > xDependentField( xTextField, uno::UNO_QUERY_THROW ); - xDependentField->getTextFieldMaster()->setPropertyValue( - getPropertyName(PROP_CONTENT), - uno::makeAny( rResult )); - } - else if ( m_bSetCitation ) - { - uno::Reference< beans::XPropertySet > xFieldProperties( xTextField, uno::UNO_QUERY_THROW); - // In case of SetExpression, the field result contains the content of the variable. - uno::Reference<lang::XServiceInfo> xServiceInfo(xTextField, uno::UNO_QUERY); + uno::Reference< beans::XPropertySet > xFieldProperties( xTextField, uno::UNO_QUERY_THROW); + // In case of SetExpression, the field result contains the content of the variable. + uno::Reference<lang::XServiceInfo> xServiceInfo(xTextField, uno::UNO_QUERY); - bool bIsSetbiblio = xServiceInfo->supportsService("com.sun.star.text.TextField.Bibliography"); - if( bIsSetbiblio ) + bool bIsSetbiblio = xServiceInfo->supportsService("com.sun.star.text.TextField.Bibliography"); + if( bIsSetbiblio ) + { + uno::Any aProperty = xFieldProperties->getPropertyValue("Fields"); + uno::Sequence<beans::PropertyValue> aValues ; + aProperty >>= aValues; + beans::PropertyValue propertyVal; + sal_Int32 nTitleFoundIndex = -1; + for (sal_Int32 i = 0; i < aValues.getLength(); ++i) { - uno::Any aProperty = xFieldProperties->getPropertyValue("Fields"); - uno::Sequence<beans::PropertyValue> aValues ; - aProperty >>= aValues; - beans::PropertyValue propertyVal; - sal_Int32 nTitleFoundIndex = -1; - for (sal_Int32 i = 0; i < aValues.getLength(); ++i) + propertyVal = aValues[i]; + if (propertyVal.Name == "Title") { - propertyVal = aValues[i]; - if (propertyVal.Name == "Title") - { - nTitleFoundIndex = i; - break; - } - } - if (nTitleFoundIndex != -1) - { - OUString titleStr; - uno::Any aValue(propertyVal.Value); - aValue >>= titleStr; - titleStr += rResult; - propertyVal.Value <<= titleStr; - aValues[nTitleFoundIndex] = propertyVal; - } - else - { - aValues.realloc(aValues.getLength() + 1); - propertyVal.Name = "Title"; - propertyVal.Value <<= rResult; - aValues[aValues.getLength() - 1] = propertyVal; + nTitleFoundIndex = i; + break; } - xFieldProperties->setPropertyValue("Fields", - uno::makeAny(aValues)); } + if (nTitleFoundIndex != -1) + { + OUString titleStr; + uno::Any aValue(propertyVal.Value); + aValue >>= titleStr; + titleStr += rResult; + propertyVal.Value <<= titleStr; + aValues[nTitleFoundIndex] = propertyVal; + } + else + { + aValues.realloc(aValues.getLength() + 1); + propertyVal.Name = "Title"; + propertyVal.Value <<= rResult; + aValues[aValues.getLength() - 1] = propertyVal; + } + xFieldProperties->setPropertyValue("Fields", + uno::makeAny(aValues)); } - else if ( m_bSetDateValue ) - { - uno::Reference< util::XNumberFormatsSupplier > xNumberSupplier( m_xTextDocument, uno::UNO_QUERY_THROW ); + } + else if ( m_bSetDateValue ) + { + uno::Reference< util::XNumberFormatsSupplier > xNumberSupplier( m_xTextDocument, uno::UNO_QUERY_THROW ); - uno::Reference<util::XNumberFormatter> xFormatter(util::NumberFormatter::create(m_xComponentContext), uno::UNO_QUERY_THROW); - xFormatter->attachNumberFormatsSupplier( xNumberSupplier ); - sal_Int32 nKey = 0; + uno::Reference<util::XNumberFormatter> xFormatter(util::NumberFormatter::create(m_xComponentContext), uno::UNO_QUERY_THROW); + xFormatter->attachNumberFormatsSupplier( xNumberSupplier ); + sal_Int32 nKey = 0; - uno::Reference< beans::XPropertySet > xFieldProperties( xTextField, uno::UNO_QUERY_THROW); + uno::Reference< beans::XPropertySet > xFieldProperties( xTextField, uno::UNO_QUERY_THROW); - xFieldProperties->getPropertyValue( "NumberFormat" ) >>= nKey; - xFieldProperties->setPropertyValue( - "DateTimeValue", - uno::makeAny( lcl_dateTimeFromSerial( xFormatter->convertStringToNumber( nKey, rResult ) ) ) ); - } - else - { - uno::Reference< beans::XPropertySet > xFieldProperties( xTextField, uno::UNO_QUERY_THROW); - // In case of SetExpression, and Input fields the field result contains the content of the variable. - uno::Reference<lang::XServiceInfo> xServiceInfo(xTextField, uno::UNO_QUERY); - // there are fields with a content property, which aren't working correctly with - // a generalized try catch of the content, property, so just restrict content - // handling to these explicit services. - const bool bHasContent = xServiceInfo->supportsService("com.sun.star.text.TextField.SetExpression") || - xServiceInfo->supportsService("com.sun.star.text.TextField.Input"); - // If we already have content set, then use the current presentation - OUString sValue; - if (bHasContent) - { - // this will throw for field types without Content - uno::Any aValue(xFieldProperties->getPropertyValue( - getPropertyName(PROP_CONTENT))); - aValue >>= sValue; - } - xFieldProperties->setPropertyValue( - getPropertyName(bHasContent && sValue.isEmpty()? PROP_CONTENT : PROP_CURRENT_PRESENTATION), - uno::makeAny( rResult )); - } + xFieldProperties->getPropertyValue( "NumberFormat" ) >>= nKey; + xFieldProperties->setPropertyValue( + "DateTimeValue", + uno::makeAny( lcl_dateTimeFromSerial( xFormatter->convertStringToNumber( nKey, rResult ) ) ) ); } - catch( const beans::UnknownPropertyException& ) + else { - //some fields don't have a CurrentPresentation (DateTime) + uno::Reference< beans::XPropertySet > xFieldProperties( xTextField, uno::UNO_QUERY_THROW); + // In case of SetExpression, and Input fields the field result contains the content of the variable. + uno::Reference<lang::XServiceInfo> xServiceInfo(xTextField, uno::UNO_QUERY); + // there are fields with a content property, which aren't working correctly with + // a generalized try catch of the content, property, so just restrict content + // handling to these explicit services. + const bool bHasContent = xServiceInfo->supportsService("com.sun.star.text.TextField.SetExpression") || + xServiceInfo->supportsService("com.sun.star.text.TextField.Input"); + // If we already have content set, then use the current presentation + OUString sValue; + if (bHasContent) + { + // this will throw for field types without Content + uno::Any aValue(xFieldProperties->getPropertyValue( + getPropertyName(PROP_CONTENT))); + aValue >>= sValue; + } + xFieldProperties->setPropertyValue( + getPropertyName(bHasContent && sValue.isEmpty()? PROP_CONTENT : PROP_CURRENT_PRESENTATION), + uno::makeAny( rResult )); } } - } - catch (const uno::Exception&) - { - TOOLS_WARN_EXCEPTION("writerfilter.dmapper", "DomainMapper_Impl::SetFieldResult"); + catch( const beans::UnknownPropertyException& ) + { + //some fields don't have a CurrentPresentation (DateTime) + } } } + catch (const uno::Exception&) + { + TOOLS_WARN_EXCEPTION("writerfilter.dmapper", "DomainMapper_Impl::SetFieldResult"); + } } void DomainMapper_Impl::SetFieldFFData(const FFDataHandler::Pointer_t& pFFDataHandler) @@ -6861,63 +6861,63 @@ void DomainMapper_Impl::RemoveTopRedline( ) void DomainMapper_Impl::ApplySettingsTable() { - if (m_pSettingsTable && m_xTextFactory.is()) + if (!(m_pSettingsTable && m_xTextFactory.is())) + return; + + try { - try + uno::Reference< beans::XPropertySet > xTextDefaults(m_xTextFactory->createInstance("com.sun.star.text.Defaults"), uno::UNO_QUERY_THROW ); + sal_Int32 nDefTab = m_pSettingsTable->GetDefaultTabStop(); + xTextDefaults->setPropertyValue( getPropertyName( PROP_TAB_STOP_DISTANCE ), uno::makeAny(nDefTab) ); + if (m_pSettingsTable->GetLinkStyles()) { - uno::Reference< beans::XPropertySet > xTextDefaults(m_xTextFactory->createInstance("com.sun.star.text.Defaults"), uno::UNO_QUERY_THROW ); - sal_Int32 nDefTab = m_pSettingsTable->GetDefaultTabStop(); - xTextDefaults->setPropertyValue( getPropertyName( PROP_TAB_STOP_DISTANCE ), uno::makeAny(nDefTab) ); - if (m_pSettingsTable->GetLinkStyles()) - { - // If linked styles are enabled, set paragraph defaults from Word's default template - xTextDefaults->setPropertyValue(getPropertyName(PROP_PARA_BOTTOM_MARGIN), uno::makeAny(ConversionHelper::convertTwipToMM100(200))); - style::LineSpacing aSpacing; - aSpacing.Mode = style::LineSpacingMode::PROP; - aSpacing.Height = sal_Int16(115); - xTextDefaults->setPropertyValue(getPropertyName(PROP_PARA_LINE_SPACING), uno::makeAny(aSpacing)); - } - - if (m_pSettingsTable->GetZoomFactor() || m_pSettingsTable->GetView()) - { - std::vector<beans::PropertyValue> aViewProps; - if (m_pSettingsTable->GetZoomFactor()) - { - aViewProps.emplace_back("ZoomFactor", -1, uno::makeAny(m_pSettingsTable->GetZoomFactor()), beans::PropertyState_DIRECT_VALUE); - aViewProps.emplace_back("VisibleBottom", -1, uno::makeAny(sal_Int32(0)), beans::PropertyState_DIRECT_VALUE); - aViewProps.emplace_back("ZoomType", -1, - uno::makeAny(m_pSettingsTable->GetZoomType()), - beans::PropertyState_DIRECT_VALUE); - } - uno::Reference<container::XIndexContainer> xBox = document::IndexedPropertyValues::create(m_xComponentContext); - xBox->insertByIndex(sal_Int32(0), uno::makeAny(comphelper::containerToSequence(aViewProps))); - uno::Reference<document::XViewDataSupplier> xViewDataSupplier(m_xTextDocument, uno::UNO_QUERY); - xViewDataSupplier->setViewData(xBox); - } + // If linked styles are enabled, set paragraph defaults from Word's default template + xTextDefaults->setPropertyValue(getPropertyName(PROP_PARA_BOTTOM_MARGIN), uno::makeAny(ConversionHelper::convertTwipToMM100(200))); + style::LineSpacing aSpacing; + aSpacing.Mode = style::LineSpacingMode::PROP; + aSpacing.Height = sal_Int16(115); + xTextDefaults->setPropertyValue(getPropertyName(PROP_PARA_LINE_SPACING), uno::makeAny(aSpacing)); + } - uno::Reference< beans::XPropertySet > xSettings(m_xTextFactory->createInstance("com.sun.star.document.Settings"), uno::UNO_QUERY); - - if (m_pSettingsTable->GetDoNotExpandShiftReturn()) - xSettings->setPropertyValue( "DoNotJustifyLinesWithManualBreak", uno::makeAny(true) ); - if (m_pSettingsTable->GetUsePrinterMetrics()) - xSettings->setPropertyValue("PrinterIndependentLayout", uno::makeAny(document::PrinterIndependentLayout::DISABLED)); - if( m_pSettingsTable->GetEmbedTrueTypeFonts()) - xSettings->setPropertyValue( getPropertyName( PROP_EMBED_FONTS ), uno::makeAny(true) ); - if( m_pSettingsTable->GetEmbedSystemFonts()) - xSettings->setPropertyValue( getPropertyName( PROP_EMBED_SYSTEM_FONTS ), uno::makeAny(true) ); - xSettings->setPropertyValue("AddParaTableSpacing", uno::makeAny(m_pSettingsTable->GetDoNotUseHTMLParagraphAutoSpacing())); - if (m_pSettingsTable->GetNoLeading()) + if (m_pSettingsTable->GetZoomFactor() || m_pSettingsTable->GetView()) + { + std::vector<beans::PropertyValue> aViewProps; + if (m_pSettingsTable->GetZoomFactor()) { - xSettings->setPropertyValue("AddExternalLeading", uno::makeAny(!m_pSettingsTable->GetNoLeading())); + aViewProps.emplace_back("ZoomFactor", -1, uno::makeAny(m_pSettingsTable->GetZoomFactor()), beans::PropertyState_DIRECT_VALUE); + aViewProps.emplace_back("VisibleBottom", -1, uno::makeAny(sal_Int32(0)), beans::PropertyState_DIRECT_VALUE); + aViewProps.emplace_back("ZoomType", -1, + uno::makeAny(m_pSettingsTable->GetZoomType()), + beans::PropertyState_DIRECT_VALUE); } - if( m_pSettingsTable->GetProtectForm() ) - xSettings->setPropertyValue("ProtectForm", uno::makeAny( true )); - if( m_pSettingsTable->GetReadOnly() ) - xSettings->setPropertyValue("LoadReadonly", uno::makeAny( true )); + uno::Reference<container::XIndexContainer> xBox = document::IndexedPropertyValues::create(m_xComponentContext); + xBox->insertByIndex(sal_Int32(0), uno::makeAny(comphelper::containerToSequence(aViewProps))); + uno::Reference<document::XViewDataSupplier> xViewDataSupplier(m_xTextDocument, uno::UNO_QUERY); + xViewDataSupplier->setViewData(xBox); } - catch(const uno::Exception&) + + uno::Reference< beans::XPropertySet > xSettings(m_xTextFactory->createInstance("com.sun.star.document.Settings"), uno::UNO_QUERY); + + if (m_pSettingsTable->GetDoNotExpandShiftReturn()) + xSettings->setPropertyValue( "DoNotJustifyLinesWithManualBreak", uno::makeAny(true) ); + if (m_pSettingsTable->GetUsePrinterMetrics()) + xSettings->setPropertyValue("PrinterIndependentLayout", uno::makeAny(document::PrinterIndependentLayout::DISABLED)); + if( m_pSettingsTable->GetEmbedTrueTypeFonts()) + xSettings->setPropertyValue( getPropertyName( PROP_EMBED_FONTS ), uno::makeAny(true) ); + if( m_pSettingsTable->GetEmbedSystemFonts()) + xSettings->setPropertyValue( getPropertyName( PROP_EMBED_SYSTEM_FONTS ), uno::makeAny(true) ); + xSettings->setPropertyValue("AddParaTableSpacing", uno::makeAny(m_pSettingsTable->GetDoNotUseHTMLParagraphAutoSpacing())); + if (m_pSettingsTable->GetNoLeading()) { + xSettings->setPropertyValue("AddExternalLeading", uno::makeAny(!m_pSettingsTable->GetNoLeading())); } + if( m_pSettingsTable->GetProtectForm() ) + xSettings->setPropertyValue("ProtectForm", uno::makeAny( true )); + if( m_pSettingsTable->GetReadOnly() ) + xSettings->setPropertyValue("LoadReadonly", uno::makeAny( true )); + } + catch(const uno::Exception&) + { } } diff --git a/writerfilter/source/dmapper/FormControlHelper.cxx b/writerfilter/source/dmapper/FormControlHelper.cxx index 9c89bc0ad98a..180cbec10e85 100644 --- a/writerfilter/source/dmapper/FormControlHelper.cxx +++ b/writerfilter/source/dmapper/FormControlHelper.cxx @@ -217,80 +217,80 @@ void FormControlHelper::processField(uno::Reference<text::XFormField> const& xFo uno::Reference<container::XNameContainer> xNameCont = xFormField->getParameters(); uno::Reference<container::XNamed> xNamed( xFormField, uno::UNO_QUERY ); - if ( m_pFFData && xNamed.is() && xNameCont.is() ) - { - OUString sTmp = m_pFFData->getEntryMacro(); - if ( !sTmp.isEmpty() ) - xNameCont->insertByName( "EntryMacro", uno::makeAny(sTmp) ); - sTmp = m_pFFData->getExitMacro(); - if ( !sTmp.isEmpty() ) - xNameCont->insertByName( "ExitMacro", uno::makeAny(sTmp) ); + if ( !(m_pFFData && xNamed.is() && xNameCont.is()) ) + return; - sTmp = m_pFFData->getHelpText(); - if ( !sTmp.isEmpty() ) - xNameCont->insertByName( "Help", uno::makeAny(sTmp) ); + OUString sTmp = m_pFFData->getEntryMacro(); + if ( !sTmp.isEmpty() ) + xNameCont->insertByName( "EntryMacro", uno::makeAny(sTmp) ); + sTmp = m_pFFData->getExitMacro(); + if ( !sTmp.isEmpty() ) + xNameCont->insertByName( "ExitMacro", uno::makeAny(sTmp) ); - sTmp = m_pFFData->getStatusText(); - if ( !sTmp.isEmpty() ) - xNameCont->insertByName( "Hint", uno::makeAny(sTmp) ); + sTmp = m_pFFData->getHelpText(); + if ( !sTmp.isEmpty() ) + xNameCont->insertByName( "Help", uno::makeAny(sTmp) ); - if (m_pImpl->m_eFieldId == FIELD_FORMTEXT ) - { - sTmp = m_pFFData->getName(); - try - { - if ( !sTmp.isEmpty() ) - xNamed->setName( sTmp ); - } - catch ( uno::Exception& ) - { - TOOLS_INFO_EXCEPTION("writerfilter", "Set Formfield name failed"); - } + sTmp = m_pFFData->getStatusText(); + if ( !sTmp.isEmpty() ) + xNameCont->insertByName( "Hint", uno::makeAny(sTmp) ); - sTmp = m_pFFData->getTextType(); + if (m_pImpl->m_eFieldId == FIELD_FORMTEXT ) + { + sTmp = m_pFFData->getName(); + try + { if ( !sTmp.isEmpty() ) - xNameCont->insertByName( "Type", uno::makeAny(sTmp) ); - - const sal_uInt16 nMaxLength = m_pFFData->getTextMaxLength(); - if ( nMaxLength ) - { - xNameCont->insertByName( "MaxLength", uno::makeAny(nMaxLength) ); - } + xNamed->setName( sTmp ); + } + catch ( uno::Exception& ) + { + TOOLS_INFO_EXCEPTION("writerfilter", "Set Formfield name failed"); + } - sTmp = m_pFFData->getTextDefault(); - if ( !sTmp.isEmpty() ) - xNameCont->insertByName( "Content", uno::makeAny(sTmp) ); + sTmp = m_pFFData->getTextType(); + if ( !sTmp.isEmpty() ) + xNameCont->insertByName( "Type", uno::makeAny(sTmp) ); - sTmp = m_pFFData->getTextFormat(); - if ( !sTmp.isEmpty() ) - xNameCont->insertByName( "Format", uno::makeAny(sTmp) ); - } - else if (m_pImpl->m_eFieldId == FIELD_FORMCHECKBOX ) + const sal_uInt16 nMaxLength = m_pFFData->getTextMaxLength(); + if ( nMaxLength ) { - uno::Reference<beans::XPropertySet> xPropSet(xFormField, uno::UNO_QUERY); - uno::Any aAny; - aAny <<= m_pFFData->getCheckboxChecked(); - if ( xPropSet.is() ) - xPropSet->setPropertyValue("Checked", aAny); + xNameCont->insertByName( "MaxLength", uno::makeAny(nMaxLength) ); } - else if (m_pImpl->m_eFieldId == FIELD_FORMDROPDOWN ) + + sTmp = m_pFFData->getTextDefault(); + if ( !sTmp.isEmpty() ) + xNameCont->insertByName( "Content", uno::makeAny(sTmp) ); + + sTmp = m_pFFData->getTextFormat(); + if ( !sTmp.isEmpty() ) + xNameCont->insertByName( "Format", uno::makeAny(sTmp) ); + } + else if (m_pImpl->m_eFieldId == FIELD_FORMCHECKBOX ) + { + uno::Reference<beans::XPropertySet> xPropSet(xFormField, uno::UNO_QUERY); + uno::Any aAny; + aAny <<= m_pFFData->getCheckboxChecked(); + if ( xPropSet.is() ) + xPropSet->setPropertyValue("Checked", aAny); + } + else if (m_pImpl->m_eFieldId == FIELD_FORMDROPDOWN ) + { + const FFDataHandler::DropDownEntries_t& rEntries = m_pFFData->getDropDownEntries(); + if (!rEntries.empty()) { - const FFDataHandler::DropDownEntries_t& rEntries = m_pFFData->getDropDownEntries(); - if (!rEntries.empty()) + if ( xNameCont->hasByName(ODF_FORMDROPDOWN_LISTENTRY) ) + xNameCont->replaceByName(ODF_FORMDROPDOWN_LISTENTRY, uno::makeAny(comphelper::containerToSequence(rEntries))); + else + xNameCont->insertByName(ODF_FORMDROPDOWN_LISTENTRY, uno::makeAny(comphelper::containerToSequence(rEntries))); + + sal_Int32 nResult = m_pFFData->getDropDownResult().toInt32(); + if ( nResult ) { - if ( xNameCont->hasByName(ODF_FORMDROPDOWN_LISTENTRY) ) - xNameCont->replaceByName(ODF_FORMDROPDOWN_LISTENTRY, uno::makeAny(comphelper::containerToSequence(rEntries))); + if ( xNameCont->hasByName(ODF_FORMDROPDOWN_RESULT) ) + xNameCont->replaceByName(ODF_FORMDROPDOWN_RESULT, uno::makeAny( nResult ) ); else - xNameCont->insertByName(ODF_FORMDROPDOWN_LISTENTRY, uno::makeAny(comphelper::containerToSequence(rEntries))); - - sal_Int32 nResult = m_pFFData->getDropDownResult().toInt32(); - if ( nResult ) - { - if ( xNameCont->hasByName(ODF_FORMDROPDOWN_RESULT) ) - xNameCont->replaceByName(ODF_FORMDROPDOWN_RESULT, uno::makeAny( nResult ) ); - else - xNameCont->insertByName(ODF_FORMDROPDOWN_RESULT, uno::makeAny( nResult ) ); - } + xNameCont->insertByName(ODF_FORMDROPDOWN_RESULT, uno::makeAny( nResult ) ); } } } diff --git a/writerfilter/source/dmapper/NumberingManager.cxx b/writerfilter/source/dmapper/NumberingManager.cxx index c30a9a120bee..4495520bbe70 100644 --- a/writerfilter/source/dmapper/NumberingManager.cxx +++ b/writerfilter/source/dmapper/NumberingManager.cxx @@ -490,126 +490,126 @@ void ListDef::CreateNumberingRules( DomainMapper& rDMapper, uno::Reference< container::XNameContainer > xStyles = lcl_getUnoNumberingStyles( xFactory ); // Do the whole thing - if( !m_xNumRules.is() && xFactory.is() && xStyles.is( ) ) + if( !(!m_xNumRules.is() && xFactory.is() && xStyles.is( )) ) + return; + + try { - try - { - // Create the numbering style - uno::Reference< beans::XPropertySet > xStyle ( - xFactory->createInstance("com.sun.star.style.NumberingStyle"), - uno::UNO_QUERY_THROW ); + // Create the numbering style + uno::Reference< beans::XPropertySet > xStyle ( + xFactory->createInstance("com.sun.star.style.NumberingStyle"), + uno::UNO_QUERY_THROW ); - OUString sStyleName = GetStyleName(GetId(), xStyles); + OUString sStyleName = GetStyleName(GetId(), xStyles); - xStyles->insertByName( sStyleName, makeAny( xStyle ) ); + xStyles->insertByName( sStyleName, makeAny( xStyle ) ); - uno::Any oStyle = xStyles->getByName( sStyleName ); - xStyle.set( oStyle, uno::UNO_QUERY_THROW ); + uno::Any oStyle = xStyles->getByName( sStyleName ); + xStyle.set( oStyle, uno::UNO_QUERY_THROW ); - // Get the default OOo Numbering style rules - uno::Any aRules = xStyle->getPropertyValue( getPropertyName( PROP_NUMBERING_RULES ) ); - aRules >>= m_xNumRules; + // Get the default OOo Numbering style rules + uno::Any aRules = xStyle->getPropertyValue( getPropertyName( PROP_NUMBERING_RULES ) ); + aRules >>= m_xNumRules; - uno::Sequence<uno::Sequence<beans::PropertyValue>> aProps = GetMergedPropertyValues(); + uno::Sequence<uno::Sequence<beans::PropertyValue>> aProps = GetMergedPropertyValues(); - sal_Int32 nAbstLevels = m_pAbstractDef ? m_pAbstractDef->Size() : 0; - sal_Int32 nLevel = 0; - while ( nLevel < nAbstLevels ) - { - ListLevel::Pointer pAbsLevel = m_pAbstractDef->GetLevel( nLevel ); - ListLevel::Pointer pLevel = GetLevel( nLevel ); + sal_Int32 nAbstLevels = m_pAbstractDef ? m_pAbstractDef->Size() : 0; + sal_Int32 nLevel = 0; + while ( nLevel < nAbstLevels ) + { + ListLevel::Pointer pAbsLevel = m_pAbstractDef->GetLevel( nLevel ); + ListLevel::Pointer pLevel = GetLevel( nLevel ); - // Get the merged level properties - auto aLvlProps = comphelper::sequenceToContainer< std::vector<beans::PropertyValue> >(aProps[nLevel]); + // Get the merged level properties + auto aLvlProps = comphelper::sequenceToContainer< std::vector<beans::PropertyValue> >(aProps[nLevel]); - // Get the char style - uno::Sequence< beans::PropertyValue > aAbsCharStyleProps = pAbsLevel->GetCharStyleProperties( ); - if ( pLevel ) - { - uno::Sequence< beans::PropertyValue >& rAbsCharStyleProps = aAbsCharStyleProps; - uno::Sequence< beans::PropertyValue > aCharStyleProps = - pLevel->GetCharStyleProperties( ); - uno::Sequence< beans::PropertyValue >& rCharStyleProps = aCharStyleProps; - lcl_mergeProperties( rAbsCharStyleProps, rCharStyleProps ); - } - - if( aAbsCharStyleProps.hasElements() ) - { - // Change the sequence into a vector - auto aStyleProps = comphelper::sequenceToContainer<PropertyValueVector_t>(aAbsCharStyleProps); + // Get the char style + uno::Sequence< beans::PropertyValue > aAbsCharStyleProps = pAbsLevel->GetCharStyleProperties( ); + if ( pLevel ) + { + uno::Sequence< beans::PropertyValue >& rAbsCharStyleProps = aAbsCharStyleProps; + uno::Sequence< beans::PropertyValue > aCharStyleProps = + pLevel->GetCharStyleProperties( ); + uno::Sequence< beans::PropertyValue >& rCharStyleProps = aCharStyleProps; + lcl_mergeProperties( rAbsCharStyleProps, rCharStyleProps ); + } - //create (or find) a character style containing the character - // attributes of the symbol and apply it to the numbering level - OUString sStyle = rDMapper.getOrCreateCharStyle( aStyleProps, /*bAlwaysCreate=*/true ); - aLvlProps.push_back(comphelper::makePropertyValue(getPropertyName(PROP_CHAR_STYLE_NAME), sStyle)); - } + if( aAbsCharStyleProps.hasElements() ) + { + // Change the sequence into a vector + auto aStyleProps = comphelper::sequenceToContainer<PropertyValueVector_t>(aAbsCharStyleProps); - // Get the prefix / suffix / Parent numbering - // and add them to the level properties - OUString sText = pAbsLevel->GetBulletChar( ); - // Inherit <w:lvlText> from the abstract level in case the override would be empty. - if (pLevel && !pLevel->GetBulletChar().isEmpty()) - sText = pLevel->GetBulletChar( ); + //create (or find) a character style containing the character + // attributes of the symbol and apply it to the numbering level + OUString sStyle = rDMapper.getOrCreateCharStyle( aStyleProps, /*bAlwaysCreate=*/true ); + aLvlProps.push_back(comphelper::makePropertyValue(getPropertyName(PROP_CHAR_STYLE_NAME), sStyle)); + } - aLvlProps.push_back(comphelper::makePropertyValue(getPropertyName(PROP_PREFIX), OUString(""))); - aLvlProps.push_back(comphelper::makePropertyValue(getPropertyName(PROP_SUFFIX), OUString(""))); - aLvlProps.push_back(comphelper::makePropertyValue(getPropertyName(PROP_LIST_FORMAT), sText)); + // Get the prefix / suffix / Parent numbering + // and add them to the level properties + OUString sText = pAbsLevel->GetBulletChar( ); + // Inherit <w:lvlText> from the abstract level in case the override would be empty. + if (pLevel && !pLevel->GetBulletChar().isEmpty()) + sText = pLevel->GetBulletChar( ); - // Total count of replacement holders is determining amount of required parent numbering to include - // TODO: not sure how "%" symbol is escaped. This is not supported yet - sal_Int16 nParentNum = comphelper::string::getTokenCount(sText, '%'); - aLvlProps.push_back(comphelper::makePropertyValue(getPropertyName(PROP_PARENT_NUMBERING), nParentNum)); + aLvlProps.push_back(comphelper::makePropertyValue(getPropertyName(PROP_PREFIX), OUString(""))); + aLvlProps.push_back(comphelper::makePropertyValue(getPropertyName(PROP_SUFFIX), OUString(""))); + aLvlProps.push_back(comphelper::makePropertyValue(getPropertyName(PROP_LIST_FORMAT), sText)); - aLvlProps.push_back(comphelper::makePropertyValue(getPropertyName(PROP_POSITION_AND_SPACE_MODE), sal_Int16(text::PositionAndSpaceMode::LABEL_ALIGNMENT))); + // Total count of replacement holders is determining amount of required parent numbering to include + // TODO: not sure how "%" symbol is escaped. This is not supported yet + sal_Int16 nParentNum = comphelper::string::getTokenCount(sText, '%'); + aLvlProps.push_back(comphelper::makePropertyValue(getPropertyName(PROP_PARENT_NUMBERING), nParentNum)); - // Replace the numbering rules for the level - m_xNumRules->replaceByIndex(nLevel, uno::makeAny(comphelper::containerToSequence(aLvlProps))); + aLvlProps.push_back(comphelper::makePropertyValue(getPropertyName(PROP_POSITION_AND_SPACE_MODE), sal_Int16(text::PositionAndSpaceMode::LABEL_ALIGNMENT))); - // Handle the outline level here - if ( pAbsLevel->isOutlineNumbering()) - { - uno::Reference< text::XChapterNumberingSupplier > xOutlines ( - xFactory, uno::UNO_QUERY_THROW ); - uno::Reference< container::XIndexReplace > xOutlineRules = - xOutlines->getChapterNumberingRules( ); + // Replace the numbering rules for the level + m_xNumRules->replaceByIndex(nLevel, uno::makeAny(comphelper::containerToSequence(aLvlProps))); - StyleSheetEntryPtr pParaStyle = pAbsLevel->GetParaStyle( ); - aLvlProps.push_back(comphelper::makePropertyValue(getPropertyName(PROP_HEADING_STYLE_NAME), pParaStyle->sConvertedStyleName)); + // Handle the outline level here + if ( pAbsLevel->isOutlineNumbering()) + { + uno::Reference< text::XChapterNumberingSupplier > xOutlines ( + xFactory, uno::UNO_QUERY_THROW ); + uno::Reference< container::XIndexReplace > xOutlineRules = + xOutlines->getChapterNumberingRules( ); - xOutlineRules->replaceByIndex(nLevel, uno::makeAny(comphelper::containerToSequence(aLvlProps))); - } + StyleSheetEntryPtr pParaStyle = pAbsLevel->GetParaStyle( ); + aLvlProps.push_back(comphelper::makePropertyValue(getPropertyName(PROP_HEADING_STYLE_NAME), pParaStyle->sConvertedStyleName)); - // first level without default outline paragraph style - const tools::SvRef< StyleSheetEntry >& aParaStyle = pAbsLevel->GetParaStyle(); - if ( WW_OUTLINE_MAX + 1 == m_nDefaultParentLevels && ( !aParaStyle || - aParaStyle->sConvertedStyleName.getLength() != RTL_CONSTASCII_LENGTH( "Heading 1" ) || - !aParaStyle->sConvertedStyleName.startsWith("Heading ") || - aParaStyle->sConvertedStyleName[ RTL_CONSTASCII_LENGTH( "Heading " ) ] - u'1' != nLevel ) ) - { - m_nDefaultParentLevels = nLevel; - } + xOutlineRules->replaceByIndex(nLevel, uno::makeAny(comphelper::containerToSequence(aLvlProps))); + } - nLevel++; + // first level without default outline paragraph style + const tools::SvRef< StyleSheetEntry >& aParaStyle = pAbsLevel->GetParaStyle(); + if ( WW_OUTLINE_MAX + 1 == m_nDefaultParentLevels && ( !aParaStyle || + aParaStyle->sConvertedStyleName.getLength() != RTL_CONSTASCII_LENGTH( "Heading 1" ) || + !aParaStyle->sConvertedStyleName.startsWith("Heading ") || + aParaStyle->sConvertedStyleName[ RTL_CONSTASCII_LENGTH( "Heading " ) ] - u'1' != nLevel ) ) + { + m_nDefaultParentLevels = nLevel; } - // Create the numbering style for these rules - OUString sNumRulesName = getPropertyName( PROP_NUMBERING_RULES ); - xStyle->setPropertyValue( sNumRulesName, uno::makeAny( m_xNumRules ) ); - } - catch( const lang::IllegalArgumentException& ) - { - TOOLS_WARN_EXCEPTION( "writerfilter", "" ); - assert( !"Incorrect argument to UNO call" ); - } - catch( const uno::RuntimeException& ) - { - TOOLS_WARN_EXCEPTION( "writerfilter", "" ); - assert( !"Incorrect argument to UNO call" ); - } - catch( const uno::Exception& ) - { - TOOLS_WARN_EXCEPTION( "writerfilter", "" ); + nLevel++; } + + // Create the numbering style for these rules + OUString sNumRulesName = getPropertyName( PROP_NUMBERING_RULES ); + xStyle->setPropertyValue( sNumRulesName, uno::makeAny( m_xNumRules ) ); + } + catch( const lang::IllegalArgumentException& ) + { + TOOLS_WARN_EXCEPTION( "writerfilter", "" ); + assert( !"Incorrect argument to UNO call" ); + } + catch( const uno::RuntimeException& ) + { + TOOLS_WARN_EXCEPTION( "writerfilter", "" ); + assert( !"Incorrect argument to UNO call" ); + } + catch( const uno::Exception& ) + { + TOOLS_WARN_EXCEPTION( "writerfilter", "" ); } } @@ -770,308 +770,308 @@ void ListsManager::lcl_sprm( Sprm& rSprm ) { //fill the attributes of the style sheet sal_uInt32 nSprmId = rSprm.getId(); - if( m_pCurrentDefinition || + if( !(m_pCurrentDefinition || nSprmId == NS_ooxml::LN_CT_Numbering_abstractNum || nSprmId == NS_ooxml::LN_CT_Numbering_num || (nSprmId == NS_ooxml::LN_CT_NumPicBullet_pict && m_pCurrentNumPicBullet) || - nSprmId == NS_ooxml::LN_CT_Numbering_numPicBullet) + nSprmId == NS_ooxml::LN_CT_Numbering_numPicBullet)) + return; + + static bool bIsStartVisited = false; + sal_Int32 nIntValue = rSprm.getValue()->getInt(); + switch( nSprmId ) { - static bool bIsStartVisited = false; - sal_Int32 nIntValue = rSprm.getValue()->getInt(); - switch( nSprmId ) + case NS_ooxml::LN_CT_Numbering_abstractNum: { - case NS_ooxml::LN_CT_Numbering_abstractNum: + writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps(); + if(pProperties) { - writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps(); - if(pProperties) - { - //create a new Abstract list entry - OSL_ENSURE( !m_pCurrentDefinition, "current entry has to be NULL here"); - m_pCurrentDefinition = new AbstractListDef; - pProperties->resolve( *this ); - //append it to the table - m_aAbstractLists.push_back( m_pCurrentDefinition ); - m_pCurrentDefinition = AbstractListDef::Pointer(); - } + //create a new Abstract list entry + OSL_ENSURE( !m_pCurrentDefinition, "current entry has to be NULL here"); + m_pCurrentDefinition = new AbstractListDef; + pProperties->resolve( *this ); + //append it to the table + m_aAbstractLists.push_back( m_pCurrentDefinition ); + m_pCurrentDefinition = AbstractListDef::Pointer(); } - break; - case NS_ooxml::LN_CT_Numbering_num: + } + break; + case NS_ooxml::LN_CT_Numbering_num: + { + writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps(); + if(pProperties) { - writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps(); - if(pProperties) - { - // Create a new list entry - OSL_ENSURE( !m_pCurrentDefinition, "current entry has to be NULL here"); - ListDef::Pointer listDef( new ListDef ); - m_pCurrentDefinition = listDef.get(); - pProperties->resolve( *this ); - //append it to the table - m_aLists.push_back( listDef ); - - m_pCurrentDefinition = AbstractListDef::Pointer(); - } + // Create a new list entry + OSL_ENSURE( !m_pCurrentDefinition, "current entry has to be NULL here"); + ListDef::Pointer listDef( new ListDef ); + m_pCurrentDefinition = listDef.get(); + pProperties->resolve( *this ); + //append it to the table + m_aLists.push_back( listDef ); + + m_pCurrentDefinition = AbstractListDef::Pointer(); } - break; - case NS_ooxml::LN_CT_Numbering_numPicBullet: + } + break; + case NS_ooxml::LN_CT_Numbering_numPicBullet: + { + writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps(); + if (pProperties) { - writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps(); - if (pProperties) - { - NumPicBullet::Pointer numPicBullet(new NumPicBullet()); - m_pCurrentNumPicBullet = numPicBullet; - pProperties->resolve(*this); - m_aNumPicBullets.push_back(numPicBullet); - m_pCurrentNumPicBullet = NumPicBullet::Pointer(); - } + NumPicBullet::Pointer numPicBullet(new NumPicBullet()); + m_pCurrentNumPicBullet = numPicBullet; + pProperties->resolve(*this); + m_aNumPicBullets.push_back(numPicBullet); + m_pCurrentNumPicBullet = NumPicBullet::Pointer(); } - break; - case NS_ooxml::LN_CT_NumPicBullet_pict: - { - uno::Reference<drawing::XShape> xShape = m_rDMapper.PopPendingShape(); + } + break; + case NS_ooxml::LN_CT_NumPicBullet_pict: + { + uno::Reference<drawing::XShape> xShape = m_rDMapper.PopPendingShape(); - m_pCurrentNumPicBullet->SetShape(xShape); - } - break; - case NS_ooxml::LN_CT_Lvl_lvlPicBulletId: - if (ListLevel::Pointer pCurrentLevel = m_pCurrentDefinition->GetCurrentLevel()) + m_pCurrentNumPicBullet->SetShape(xShape); + } + break; + case NS_ooxml::LN_CT_Lvl_lvlPicBulletId: + if (ListLevel::Pointer pCurrentLevel = m_pCurrentDefinition->GetCurrentLevel()) + { + uno::Reference<drawing::XShape> xShape; + for (const auto& rNumPicBullet : m_aNumPicBullets) { - uno::Reference<drawing::XShape> xShape; - for (const auto& rNumPicBullet : m_aNumPicBullets) + if (rNumPicBullet->GetId() == nIntValue) { - if (rNumPicBullet->GetId() == nIntValue) - { - xShape = rNumPicBullet->GetShape(); - break; - } + xShape = rNumPicBullet->GetShape(); + break; } - if (xShape.is()) + } + if (xShape.is()) + { + uno::Reference<beans::XPropertySet> xPropertySet(xShape, uno::UNO_QUERY); + try { - uno::Reference<beans::XPropertySet> xPropertySet(xShape, uno::UNO_QUERY); - try + uno::Any aAny = xPropertySet->getPropertyValue("Graphic"); + if (aAny.has<uno::Reference<graphic::XGraphic>>() && pCurrentLevel) { - uno::Any aAny = xPropertySet->getPropertyValue("Graphic"); - if (aAny.has<uno::Reference<graphic::XGraphic>>() && pCurrentLevel) + auto xGraphic = aAny.get<uno::Reference<graphic::XGraphic>>(); + if (xGraphic.is()) { - auto xGraphic = aAny.get<uno::Reference<graphic::XGraphic>>(); - if (xGraphic.is()) - { - uno::Reference<awt::XBitmap> xBitmap(xGraphic, uno::UNO_QUERY); - pCurrentLevel->SetGraphicBitmap(xBitmap); - } + uno::Reference<awt::XBitmap> xBitmap(xGraphic, uno::UNO_QUERY); + pCurrentLevel->SetGraphicBitmap(xBitmap); } } - catch (const beans::UnknownPropertyException&) - {} - - // Respect only the aspect ratio of the picture, not its size. - awt::Size aPrefSize = xShape->getSize(); - // See SwDefBulletConfig::InitFont(), default height is 14. - const int nFontHeight = 14; - // Point -> mm100. - const int nHeight = nFontHeight * 35; - if ( aPrefSize.Height * aPrefSize.Width != 0 ) - { - int nWidth = (nHeight * aPrefSize.Width) / aPrefSize.Height; + } + catch (const beans::UnknownPropertyException&) + {} + + // Respect only the aspect ratio of the picture, not its size. + awt::Size aPrefSize = xShape->getSize(); + // See SwDefBulletConfig::InitFont(), default height is 14. + const int nFontHeight = 14; + // Point -> mm100. + const int nHeight = nFontHeight * 35; + if ( aPrefSize.Height * aPrefSize.Width != 0 ) + { + int nWidth = (nHeight * aPrefSize.Width) / aPrefSize.Height; - awt::Size aSize( convertMm100ToTwip(nWidth), convertMm100ToTwip(nHeight) ); - pCurrentLevel->SetGraphicSize( aSize ); - } - else - { - awt::Size aSize( convertMm100ToTwip(aPrefSize.Width), convertMm100ToTwip(aPrefSize.Height) ); - pCurrentLevel->SetGraphicSize( aSize ); - } + awt::Size aSize( convertMm100ToTwip(nWidth), convertMm100ToTwip(nHeight) ); + pCurrentLevel->SetGraphicSize( aSize ); } - } - break; - case NS_ooxml::LN_CT_Num_abstractNumId: - { - sal_Int32 nAbstractNumId = rSprm.getValue()->getInt(); - ListDef* pListDef = dynamic_cast< ListDef* >( m_pCurrentDefinition.get( ) ); - if ( pListDef != nullptr ) + else { - // The current def should be a ListDef - pListDef->SetAbstractDefinition( - GetAbstractList( nAbstractNumId ) ); + awt::Size aSize( convertMm100ToTwip(aPrefSize.Width), convertMm100ToTwip(aPrefSize.Height) ); + pCurrentLevel->SetGraphicSize( aSize ); } } - break; - case NS_ooxml::LN_CT_AbstractNum_multiLevelType: - break; - case NS_ooxml::LN_CT_AbstractNum_tmpl: - AbstractListDef::SetValue( nSprmId ); - break; - case NS_ooxml::LN_CT_AbstractNum_lvl: + } + break; + case NS_ooxml::LN_CT_Num_abstractNumId: + { + sal_Int32 nAbstractNumId = rSprm.getValue()->getInt(); + ListDef* pListDef = dynamic_cast< ListDef* >( m_pCurrentDefinition.get( ) ); + if ( pListDef != nullptr ) { - writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps(); - if(pProperties) - pProperties->resolve(*this); + // The current def should be a ListDef + pListDef->SetAbstractDefinition( + GetAbstractList( nAbstractNumId ) ); } - break; - case NS_ooxml::LN_CT_Lvl_start: - if (ListLevel::Pointer pCurrentLevel = m_pCurrentDefinition->GetCurrentLevel()) - pCurrentLevel->SetValue( nSprmId, nIntValue ); - bIsStartVisited = true; - break; - case NS_ooxml::LN_CT_Lvl_numFmt: + } + break; + case NS_ooxml::LN_CT_AbstractNum_multiLevelType: + break; + case NS_ooxml::LN_CT_AbstractNum_tmpl: + AbstractListDef::SetValue( nSprmId ); + break; + case NS_ooxml::LN_CT_AbstractNum_lvl: + { + writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps(); + if(pProperties) + pProperties->resolve(*this); + } + break; + case NS_ooxml::LN_CT_Lvl_start: + if (ListLevel::Pointer pCurrentLevel = m_pCurrentDefinition->GetCurrentLevel()) + pCurrentLevel->SetValue( nSprmId, nIntValue ); + bIsStartVisited = true; + break; + case NS_ooxml::LN_CT_Lvl_numFmt: + { + writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps(); + if (pProperties) { - writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps(); - if (pProperties) - { - pProperties->resolve(*this); - } - if (ListLevel::Pointer pCurrentLevel = m_pCurrentDefinition->GetCurrentLevel()) - { - if( !bIsStartVisited ) - { - pCurrentLevel->SetValue( NS_ooxml::LN_CT_Lvl_start, 0 ); - bIsStartVisited = true; - } - } + pProperties->resolve(*this); } - break; - case NS_ooxml::LN_CT_Lvl_isLgl: - case NS_ooxml::LN_CT_Lvl_legacy: - if (ListLevel::Pointer pCurrentLevel = m_pCurrentDefinition->GetCurrentLevel()) - { - pCurrentLevel->SetValue(nSprmId, nIntValue); - } - break; - case NS_ooxml::LN_CT_Lvl_suff: + if (ListLevel::Pointer pCurrentLevel = m_pCurrentDefinition->GetCurrentLevel()) { - if (ListLevel::Pointer pCurrentLevel = m_pCurrentDefinition->GetCurrentLevel()) + if( !bIsStartVisited ) { - SvxNumberFormat::LabelFollowedBy value = SvxNumberFormat::LISTTAB; - if( rSprm.getValue()->getString() == "tab" ) - value = SvxNumberFormat::LISTTAB; - else if( rSprm.getValue()->getString() == "space" ) - value = SvxNumberFormat::SPACE; - else if( rSprm.getValue()->getString() == "nothing" ) - value = SvxNumberFormat::NOTHING; - else - SAL_WARN( "writerfilter", "Unknown ST_LevelSuffix value " - << rSprm.getValue()->getString()); - pCurrentLevel->SetValue( nSprmId, value ); + pCurrentLevel->SetValue( NS_ooxml::LN_CT_Lvl_start, 0 ); + bIsStartVisited = true; } } - break; - case NS_ooxml::LN_CT_Lvl_lvlText: - case NS_ooxml::LN_CT_Lvl_rPr : //contains LN_EG_RPrBase_rFonts - { - writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps(); - if(pProperties) - pProperties->resolve(*this); - } - break; - case NS_ooxml::LN_CT_NumLvl_lvl: - { - // overwrite level - writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps(); - if(pProperties) - pProperties->resolve(*this); - } - break; - case NS_ooxml::LN_CT_Lvl_lvlJc: + } + break; + case NS_ooxml::LN_CT_Lvl_isLgl: + case NS_ooxml::LN_CT_Lvl_legacy: + if (ListLevel::Pointer pCurrentLevel = m_pCurrentDefinition->GetCurrentLevel()) { - sal_Int16 nValue = text::HoriOrientation::NONE; - switch (nIntValue) - { - case NS_ooxml::LN_Value_ST_Jc_left: - case NS_ooxml::LN_Value_ST_Jc_start: - nValue = text::HoriOrientation::LEFT; - break; - case NS_ooxml::LN_Value_ST_Jc_center: - nValue = text::HoriOrientation::CENTER; - break; - case NS_ooxml::LN_Value_ST_Jc_right: - case NS_ooxml::LN_Value_ST_Jc_end: - nValue = text::HoriOrientation::RIGHT; - break; - } - - if (nValue != text::HoriOrientation::NONE) - { - if (ListLevel::Pointer pLevel = m_pCurrentDefinition->GetCurrentLevel()) - { - pLevel->Insert( - PROP_ADJUST, uno::makeAny( nValue ) ); - } - } + pCurrentLevel->SetValue(nSprmId, nIntValue); } break; - case NS_ooxml::LN_CT_Lvl_pPr: - case NS_ooxml::LN_CT_PPrBase_ind: + case NS_ooxml::LN_CT_Lvl_suff: + { + if (ListLevel::Pointer pCurrentLevel = m_pCurrentDefinition->GetCurrentLevel()) { - //todo: how to handle paragraph properties within numbering levels (except LeftIndent and FirstLineIndent)? - writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps(); - if(pProperties) - pProperties->resolve(*this); + SvxNumberFormat::LabelFollowedBy value = SvxNumberFormat::LISTTAB; + if( rSprm.getValue()->getString() == "tab" ) + value = SvxNumberFormat::LISTTAB; + else if( rSprm.getValue()->getString() == "space" ) + value = SvxNumberFormat::SPACE; + else if( rSprm.getValue()->getString() == "nothing" ) + value = SvxNumberFormat::NOTHING; + else + SAL_WARN( "writerfilter", "Unknown ST_LevelSuffix value " + << rSprm.getValue()->getString()); + pCurrentLevel->SetValue( nSprmId, value ); } - break; - case NS_ooxml::LN_CT_PPrBase_tabs: - case NS_ooxml::LN_CT_Tabs_tab: + } + break; + case NS_ooxml::LN_CT_Lvl_lvlText: + case NS_ooxml::LN_CT_Lvl_rPr : //contains LN_EG_RPrBase_rFonts + { + writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps(); + if(pProperties) + pProperties->resolve(*this); + } + break; + case NS_ooxml::LN_CT_NumLvl_lvl: + { + // overwrite level + writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps(); + if(pProperties) + pProperties->resolve(*this); + } + break; + case NS_ooxml::LN_CT_Lvl_lvlJc: + { + sal_Int16 nValue = text::HoriOrientation::NONE; + switch (nIntValue) { - writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps(); - if(pProperties) - pProperties->resolve(*this); + case NS_ooxml::LN_Value_ST_Jc_left: + case NS_ooxml::LN_Value_ST_Jc_start: + nValue = text::HoriOrientation::LEFT; + break; + case NS_ooxml::LN_Value_ST_Jc_center: + nValue = text::HoriOrientation::CENTER; + break; + case NS_ooxml::LN_Value_ST_Jc_right: + case NS_ooxml::LN_Value_ST_Jc_end: + nValue = text::HoriOrientation::RIGHT; + break; } - break; - case NS_ooxml::LN_CT_Lvl_pStyle: + + if (nValue != text::HoriOrientation::NONE) { - OUString sStyleName = rSprm.getValue( )->getString( ); if (ListLevel::Pointer pLevel = m_pCurrentDefinition->GetCurrentLevel()) { - StyleSheetTablePtr pStylesTable = m_rDMapper.GetStyleSheetTable( ); - const StyleSheetEntryPtr pStyle = pStylesTable->FindStyleSheetByISTD( sStyleName ); - pLevel->SetParaStyle( pStyle ); + pLevel->Insert( + PROP_ADJUST, uno::makeAny( nValue ) ); } } - break; - case NS_ooxml::LN_CT_Num_lvlOverride: + } + break; + case NS_ooxml::LN_CT_Lvl_pPr: + case NS_ooxml::LN_CT_PPrBase_ind: + { + //todo: how to handle paragraph properties within numbering levels (except LeftIndent and FirstLineIndent)? + writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps(); + if(pProperties) + pProperties->resolve(*this); + } + break; + case NS_ooxml::LN_CT_PPrBase_tabs: + case NS_ooxml::LN_CT_Tabs_tab: + { + writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps(); + if(pProperties) + pProperties->resolve(*this); + } + break; + case NS_ooxml::LN_CT_Lvl_pStyle: + { + OUString sStyleName = rSprm.getValue( )->getString( ); + if (ListLevel::Pointer pLevel = m_pCurrentDefinition->GetCurrentLevel()) { - writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps(); - if (pProperties) - pProperties->resolve(*this); + StyleSheetTablePtr pStylesTable = m_rDMapper.GetStyleSheetTable( ); + const StyleSheetEntryPtr pStyle = pStylesTable->FindStyleSheetByISTD( sStyleName ); + pLevel->SetParaStyle( pStyle ); } - break; - case NS_ooxml::LN_CT_NumLvl_startOverride: + } + break; + case NS_ooxml::LN_CT_Num_lvlOverride: + { + writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps(); + if (pProperties) + pProperties->resolve(*this); + } + break; + case NS_ooxml::LN_CT_NumLvl_startOverride: + { + if(m_pCurrentDefinition) { - if(m_pCurrentDefinition) + if (ListLevel::Pointer pCurrentLevel = m_pCurrentDefinition->GetCurrentLevel()) { - if (ListLevel::Pointer pCurrentLevel = m_pCurrentDefinition->GetCurrentLevel()) - { - pCurrentLevel->SetValue(NS_ooxml::LN_CT_NumLvl_startOverride, nIntValue); - } + pCurrentLevel->SetValue(NS_ooxml::LN_CT_NumLvl_startOverride, nIntValue); } } - break; - case NS_ooxml::LN_CT_AbstractNum_numStyleLink: - { - OUString sStyleName = rSprm.getValue( )->getString( ); - m_pCurrentDefinition->SetNumStyleLink(sStyleName); - } - break; - case NS_ooxml::LN_CT_AbstractNum_styleLink: + } + break; + case NS_ooxml::LN_CT_AbstractNum_numStyleLink: + { + OUString sStyleName = rSprm.getValue( )->getString( ); + m_pCurrentDefinition->SetNumStyleLink(sStyleName); + } + break; + case NS_ooxml::LN_CT_AbstractNum_styleLink: + { + OUString sStyleName = rSprm.getValue()->getString(); + m_pCurrentDefinition->SetStyleLink(sStyleName); + } + break; + case NS_ooxml::LN_EG_RPrBase_rFonts: //contains font properties + case NS_ooxml::LN_EG_RPrBase_color: + case NS_ooxml::LN_EG_RPrBase_u: + case NS_ooxml::LN_EG_RPrBase_sz: + case NS_ooxml::LN_EG_RPrBase_lang: + case NS_ooxml::LN_EG_RPrBase_eastAsianLayout: + //no break! + default: + if (ListLevel::Pointer pCurrentLevel = m_pCurrentDefinition->GetCurrentLevel()) { - OUString sStyleName = rSprm.getValue()->getString(); - m_pCurrentDefinition->SetStyleLink(sStyleName); + m_rDMapper.PushListProperties(pCurrentLevel.get()); + m_rDMapper.sprm( rSprm ); + m_rDMapper.PopListProperties(); } - break; - case NS_ooxml::LN_EG_RPrBase_rFonts: //contains font properties - case NS_ooxml::LN_EG_RPrBase_color: - case NS_ooxml::LN_EG_RPrBase_u: - case NS_ooxml::LN_EG_RPrBase_sz: - case NS_ooxml::LN_EG_RPrBase_lang: - case NS_ooxml::LN_EG_RPrBase_eastAsianLayout: - //no break! - default: - if (ListLevel::Pointer pCurrentLevel = m_pCurrentDefinition->GetCurrentLevel()) - { - m_rDMapper.PushListProperties(pCurrentLevel.get()); - m_rDMapper.sprm( rSprm ); - m_rDMapper.PopListProperties(); - } - } } } diff --git a/writerfilter/source/dmapper/PropertyMap.cxx b/writerfilter/source/dmapper/PropertyMap.cxx index 5f8d9a906ba3..c1980623b072 100644 --- a/writerfilter/source/dmapper/PropertyMap.cxx +++ b/writerfilter/source/dmapper/PropertyMap.cxx @@ -331,23 +331,23 @@ void PropertyMap::dumpXml() const void PropertyMap::InsertProps( const PropertyMapPtr& rMap, const bool bOverwrite ) { - if ( rMap ) + if ( !rMap ) + return; + + for ( const auto& rPropPair : rMap->m_vMap ) { - for ( const auto& rPropPair : rMap->m_vMap ) + if ( bOverwrite || !m_vMap.count(rPropPair.first) ) { - if ( bOverwrite || !m_vMap.count(rPropPair.first) ) - { - if ( !bOverwrite && !rPropPair.second.getIsDocDefault() ) - m_vMap.insert(std::make_pair(rPropPair.first, PropValue(rPropPair.second.getValue(), rPropPair.second.getGrabBagType(), true))); - else - m_vMap[rPropPair.first] = rPropPair.second; - } + if ( !bOverwrite && !rPropPair.second.getIsDocDefault() ) + m_vMap.insert(std::make_pair(rPropPair.first, PropValue(rPropPair.second.getValue(), rPropPair.second.getGrabBagType(), true))); + else + m_vMap[rPropPair.first] = rPropPair.second; } + } - insertTableProperties( rMap.get(), bOverwrite ); + insertTableProperties( rMap.get(), bOverwrite ); - Invalidate(); - } + Invalidate(); } void PropertyMap::insertTableProperties( const PropertyMap*, const bool ) @@ -892,22 +892,22 @@ void SectionPropertyMap::CopyHeaderFooter( const uno::Reference< beans::XPropert xPrevStyle->getPropertyValue( sFooterIsShared ) >>= bFooterIsShared; } - if ( bHasPrevFooter ) + if ( !bHasPrevFooter ) + return; + + uno::Reference< beans::XMultiPropertySet > xMultiSet( xStyle, uno::UNO_QUERY_THROW ); + uno::Sequence<OUString> aProperties { sFooterIsOn, sFooterIsShared }; + uno::Sequence<uno::Any> aValues { uno::makeAny( true ), uno::makeAny( bFooterIsShared ) }; + xMultiSet->setPropertyValues( aProperties, aValues ); + if ( !bOmitRightFooter ) { - uno::Reference< beans::XMultiPropertySet > xMultiSet( xStyle, uno::UNO_QUERY_THROW ); - uno::Sequence<OUString> aProperties { sFooterIsOn, sFooterIsShared }; - uno::Sequence<uno::Any> aValues { uno::makeAny( true ), uno::makeAny( bFooterIsShared ) }; - xMultiSet->setPropertyValues( aProperties, aValues ); - if ( !bOmitRightFooter ) - { - CopyHeaderFooterTextProperty( xPrevStyle, xStyle, - PROP_FOOTER_TEXT ); - } - if ( !bFooterIsShared && !bOmitLeftFooter ) - { - CopyHeaderFooterTextProperty( xPrevStyle, xStyle, - PROP_FOOTER_TEXT_LEFT ); - } + CopyHeaderFooterTextProperty( xPrevStyle, xStyle, + PROP_FOOTER_TEXT ); + } + if ( !bFooterIsShared && !bOmitLeftFooter ) + { + CopyHeaderFooterTextProperty( xPrevStyle, xStyle, + PROP_FOOTER_TEXT_LEFT ); } } diff --git a/writerfilter/source/dmapper/SdtHelper.cxx b/writerfilter/source/dmapper/SdtHelper.cxx index 8a224243aa07..dff106acee13 100644 --- a/writerfilter/source/dmapper/SdtHelper.cxx +++ b/writerfilter/source/dmapper/SdtHelper.cxx @@ -145,51 +145,50 @@ void SdtHelper::createDateContentControl() xCrsr = xTextAppend->createTextCursorByRange(xTextAppend); } } - if (xCrsr.is()) + if (!xCrsr.is()) + return; + + try { - try - { - xCrsr->gotoRange(m_xDateFieldStartRange, false); - bool bIsInTable - = (m_rDM_Impl.hasTableManager() && m_rDM_Impl.getTableManager().isInTable()) - || (m_rDM_Impl.m_nTableDepth > 0); - if (bIsInTable) - xCrsr->goRight(1, false); - xCrsr->gotoEnd(true); - } - catch (uno::Exception&) - { - OSL_ENSURE(false, "Cannot get the right text range for date field"); - return; - } + xCrsr->gotoRange(m_xDateFieldStartRange, false); + bool bIsInTable = (m_rDM_Impl.hasTableManager() && m_rDM_Impl.getTableManager().isInTable()) + || (m_rDM_Impl.m_nTableDepth > 0); + if (bIsInTable) + xCrsr->goRight(1, false); + xCrsr->gotoEnd(true); + } + catch (uno::Exception&) + { + OSL_ENSURE(false, "Cannot get the right text range for date field"); + return; + } - uno::Reference<uno::XInterface> xFieldInterface - = m_rDM_Impl.GetTextFactory()->createInstance("com.sun.star.text.Fieldmark"); - uno::Reference<text::XFormField> xFormField(xFieldInterface, uno::UNO_QUERY); - uno::Reference<text::XTextContent> xToInsert(xFormField, uno::UNO_QUERY); - if (xFormField.is() && xToInsert.is()) - { - xToInsert->attach(uno::Reference<text::XTextRange>(xCrsr, uno::UNO_QUERY_THROW)); - xFormField->setFieldType(ODF_FORMDATE); - uno::Reference<container::XNameContainer> xNameCont = xFormField->getParameters(); - if (xNameCont.is()) - { - OUString sDateFormat = m_sDateFormat.makeStringAndClear(); - // Replace quotation mark used for marking static strings in date format - sDateFormat = sDateFormat.replaceAll("'", "\""); - xNameCont->insertByName(ODF_FORMDATE_DATEFORMAT, uno::makeAny(sDateFormat)); - xNameCont->insertByName(ODF_FORMDATE_DATEFORMAT_LANGUAGE, - uno::makeAny(m_sLocale.makeStringAndClear())); - } - OUString sFullDate = m_sDate.makeStringAndClear(); - if (!sFullDate.isEmpty()) - { - sal_Int32 nTimeSep = sFullDate.indexOf("T"); - if (nTimeSep != -1) - sFullDate = sFullDate.copy(0, nTimeSep); - xNameCont->insertByName(ODF_FORMDATE_CURRENTDATE, uno::makeAny(sFullDate)); - } - } + uno::Reference<uno::XInterface> xFieldInterface + = m_rDM_Impl.GetTextFactory()->createInstance("com.sun.star.text.Fieldmark"); + uno::Reference<text::XFormField> xFormField(xFieldInterface, uno::UNO_QUERY); + uno::Reference<text::XTextContent> xToInsert(xFormField, uno::UNO_QUERY); + if (!(xFormField.is() && xToInsert.is())) + return; + + xToInsert->attach(uno::Reference<text::XTextRange>(xCrsr, uno::UNO_QUERY_THROW)); + xFormField->setFieldType(ODF_FORMDATE); + uno::Reference<container::XNameContainer> xNameCont = xFormField->getParameters(); + if (xNameCont.is()) + { + OUString sDateFormat = m_sDateFormat.makeStringAndClear(); + // Replace quotation mark used for marking static strings in date format + sDateFormat = sDateFormat.replaceAll("'", "\""); + xNameCont->insertByName(ODF_FORMDATE_DATEFORMAT, uno::makeAny(sDateFormat)); + xNameCont->insertByName(ODF_FORMDATE_DATEFORMAT_LANGUAGE, + uno::makeAny(m_sLocale.makeStringAndClear())); + } + OUString sFullDate = m_sDate.makeStringAndClear(); + if (!sFullDate.isEmpty()) + { + sal_Int32 nTimeSep = sFullDate.indexOf("T"); + if (nTimeSep != -1) + sFullDate = sFullDate.copy(0, nTimeSep); + xNameCont->insertByName(ODF_FORMDATE_CURRENTDATE, uno::makeAny(sFullDate)); } } diff --git a/writerfilter/source/dmapper/SettingsTable.cxx b/writerfilter/source/dmapper/SettingsTable.cxx index e7af3f19e911..5ac2400cd493 100644 --- a/writerfilter/source/dmapper/SettingsTable.cxx +++ b/writerfilter/source/dmapper/SettingsTable.cxx @@ -763,33 +763,33 @@ void SettingsTable::ApplyProperties(uno::Reference<text::XTextDocument> const& x // Auto hyphenation: turns on hyphenation by default, <w:suppressAutoHyphens/> may still disable it at a paragraph level. // Situation is similar for RTF_WIDOWCTRL, which turns on widow / orphan control by default. - if (m_pImpl->m_bAutoHyphenation || m_pImpl->m_bNoHyphenateCaps || m_pImpl->m_bWidowControl) + if (!(m_pImpl->m_bAutoHyphenation || m_pImpl->m_bNoHyphenateCaps || m_pImpl->m_bWidowControl)) + return; + + uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(xDoc, uno::UNO_QUERY); + if (!xStyleFamiliesSupplier.is()) + return; + + uno::Reference<container::XNameAccess> xStyleFamilies = xStyleFamiliesSupplier->getStyleFamilies(); + uno::Reference<container::XNameContainer> xParagraphStyles = xStyleFamilies->getByName("ParagraphStyles").get< uno::Reference<container::XNameContainer> >(); + uno::Reference<style::XStyle> xDefault = xParagraphStyles->getByName("Standard").get< uno::Reference<style::XStyle> >(); + uno::Reference<beans::XPropertyState> xPropertyState(xDefault, uno::UNO_QUERY); + if (m_pImpl->m_bAutoHyphenation && lcl_isDefault(xPropertyState, "ParaIsHyphenation")) { - uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(xDoc, uno::UNO_QUERY); - if (!xStyleFamiliesSupplier.is()) - return; - - uno::Reference<container::XNameAccess> xStyleFamilies = xStyleFamiliesSupplier->getStyleFamilies(); - uno::Reference<container::XNameContainer> xParagraphStyles = xStyleFamilies->getByName("ParagraphStyles").get< uno::Reference<container::XNameContainer> >(); - uno::Reference<style::XStyle> xDefault = xParagraphStyles->getByName("Standard").get< uno::Reference<style::XStyle> >(); - uno::Reference<beans::XPropertyState> xPropertyState(xDefault, uno::UNO_QUERY); - if (m_pImpl->m_bAutoHyphenation && lcl_isDefault(xPropertyState, "ParaIsHyphenation")) - { - uno::Reference<beans::XPropertySet> xPropertySet(xDefault, uno::UNO_QUERY); - xPropertySet->setPropertyValue("ParaIsHyphenation", uno::makeAny(true)); - } - if (m_pImpl->m_bNoHyphenateCaps) - { - uno::Reference<beans::XPropertySet> xPropertySet(xDefault, uno::UNO_QUERY); - xPropertySet->setPropertyValue("ParaHyphenationNoCaps", uno::makeAny(true)); - } - if (m_pImpl->m_bWidowControl && lcl_isDefault(xPropertyState, "ParaWidows") && lcl_isDefault(xPropertyState, "ParaOrphans")) - { - uno::Reference<beans::XPropertySet> xPropertySet(xDefault, uno::UNO_QUERY); - uno::Any aAny = uno::makeAny(static_cast<sal_Int8>(2)); - xPropertySet->setPropertyValue("ParaWidows", aAny); - xPropertySet->setPropertyValue("ParaOrphans", aAny); - } + uno::Reference<beans::XPropertySet> xPropertySet(xDefault, uno::UNO_QUERY); + xPropertySet->setPropertyValue("ParaIsHyphenation", uno::makeAny(true)); + } + if (m_pImpl->m_bNoHyphenateCaps) + { + uno::Reference<beans::XPropertySet> xPropertySet(xDefault, uno::UNO_QUERY); + xPropertySet->setPropertyValue("ParaHyphenationNoCaps", uno::makeAny(true)); + } + if (m_pImpl->m_bWidowControl && lcl_isDefault(xPropertyState, "ParaWidows") && lcl_isDefault(xPropertyState, "ParaOrphans")) + { + uno::Reference<beans::XPropertySet> xPropertySet(xDefault, uno::UNO_QUERY); + uno::Any aAny = uno::makeAny(static_cast<sal_Int8>(2)); + xPropertySet->setPropertyValue("ParaWidows", aAny); + xPropertySet->setPropertyValue("ParaOrphans", aAny); } } diff --git a/writerfilter/source/dmapper/SmartTagHandler.cxx b/writerfilter/source/dmapper/SmartTagHandler.cxx index 2ea94a9635ba..b68c67830201 100644 --- a/writerfilter/source/dmapper/SmartTagHandler.cxx +++ b/writerfilter/source/dmapper/SmartTagHandler.cxx @@ -86,41 +86,40 @@ void SmartTagHandler::setElement(const OUString& rElement) { m_aElement = rEleme void SmartTagHandler::handle(const uno::Reference<text::XTextRange>& xParagraph) { - if (!m_aURI.isEmpty() && !m_aElement.isEmpty() && !m_aAttributes.empty()) - { - uno::Reference<rdf::XResource> xSubject(xParagraph, uno::UNO_QUERY); + if (!(!m_aURI.isEmpty() && !m_aElement.isEmpty() && !m_aAttributes.empty())) + return; + + uno::Reference<rdf::XResource> xSubject(xParagraph, uno::UNO_QUERY); - for (const std::pair<OUString, OUString>& rAttribute : m_aAttributes) + for (const std::pair<OUString, OUString>& rAttribute : m_aAttributes) + { + OUString aTypeNS = rAttribute.first; + OUString aMetadataFilePath = lcl_getTypePath(aTypeNS); + if (aMetadataFilePath.isEmpty()) + continue; + + uno::Reference<rdf::XURI> xType = rdf::URI::create(m_xComponentContext, aTypeNS); + uno::Sequence<uno::Reference<rdf::XURI>> aGraphNames + = m_xDocumentMetadataAccess->getMetadataGraphsWithType(xType); + uno::Reference<rdf::XURI> xGraphName; + if (aGraphNames.hasElements()) + xGraphName = aGraphNames[0]; + else { - OUString aTypeNS = rAttribute.first; - OUString aMetadataFilePath = lcl_getTypePath(aTypeNS); - if (aMetadataFilePath.isEmpty()) - continue; - - uno::Reference<rdf::XURI> xType = rdf::URI::create(m_xComponentContext, aTypeNS); - uno::Sequence<uno::Reference<rdf::XURI>> aGraphNames - = m_xDocumentMetadataAccess->getMetadataGraphsWithType(xType); - uno::Reference<rdf::XURI> xGraphName; - if (aGraphNames.hasElements()) - xGraphName = aGraphNames[0]; - else - { - uno::Sequence<uno::Reference<rdf::XURI>> xTypes = { xType }; - xGraphName = m_xDocumentMetadataAccess->addMetadataFile(aMetadataFilePath, xTypes); - } - uno::Reference<rdf::XNamedGraph> xGraph - = m_xDocumentMetadataAccess->getRDFRepository()->getGraph(xGraphName); - uno::Reference<rdf::XURI> xKey - = rdf::URI::create(m_xComponentContext, rAttribute.first); - uno::Reference<rdf::XLiteral> xValue - = rdf::Literal::create(m_xComponentContext, rAttribute.second); - xGraph->addStatement(xSubject, xKey, xValue); + uno::Sequence<uno::Reference<rdf::XURI>> xTypes = { xType }; + xGraphName = m_xDocumentMetadataAccess->addMetadataFile(aMetadataFilePath, xTypes); } - - m_aURI.clear(); - m_aElement.clear(); - m_aAttributes.clear(); + uno::Reference<rdf::XNamedGraph> xGraph + = m_xDocumentMetadataAccess->getRDFRepository()->getGraph(xGraphName); + uno::Reference<rdf::XURI> xKey = rdf::URI::create(m_xComponentContext, rAttribute.first); + uno::Reference<rdf::XLiteral> xValue + = rdf::Literal::create(m_xComponentContext, rAttribute.second); + xGraph->addStatement(xSubject, xKey, xValue); } + + m_aURI.clear(); + m_aElement.clear(); + m_aAttributes.clear(); } } // namespace writerfilter::dmapper diff --git a/writerfilter/source/dmapper/TDefTableHandler.cxx b/writerfilter/source/dmapper/TDefTableHandler.cxx index acd29d5ac274..deac21075535 100644 --- a/writerfilter/source/dmapper/TDefTableHandler.cxx +++ b/writerfilter/source/dmapper/TDefTableHandler.cxx @@ -310,80 +310,80 @@ void TDefTableHandler::lcl_attribute(Id rName, Value & rVal) void TDefTableHandler::localResolve(Id rName, const writerfilter::Reference<Properties>::Pointer_t& pProperties) { - if( pProperties ) + if( !pProperties ) + return; + + m_nLineWidth = m_nLineType = m_nLineColor = 0; + std::vector<beans::PropertyValue> aSavedGrabBag; + if (!m_aInteropGrabBagName.isEmpty()) { - m_nLineWidth = m_nLineType = m_nLineColor = 0; - std::vector<beans::PropertyValue> aSavedGrabBag; - if (!m_aInteropGrabBagName.isEmpty()) - { - aSavedGrabBag = m_aInteropGrabBag; - m_aInteropGrabBag.clear(); - } - pProperties->resolve( *this ); - table::BorderLine2 aBorderLine; - ConversionHelper::MakeBorderLine(m_nLineWidth, m_nLineType, m_nLineColor, aBorderLine, /*bIsOOXML=*/true); - const bool rtl = false; // TODO - switch( rName ) - { - case NS_ooxml::LN_CT_TcBorders_top: - m_aTopBorderLines.push_back(aBorderLine); - if (!m_aInteropGrabBagName.isEmpty()) - aSavedGrabBag.push_back(getInteropGrabBag("top")); - break; - case NS_ooxml::LN_CT_TcBorders_start: - if( rtl ) - m_aRightBorderLines.push_back(aBorderLine); - else - m_aLeftBorderLines.push_back(aBorderLine); - if (!m_aInteropGrabBagName.isEmpty()) - aSavedGrabBag.push_back(getInteropGrabBag("start")); - break; - case NS_ooxml::LN_CT_TcBorders_left: + aSavedGrabBag = m_aInteropGrabBag; + m_aInteropGrabBag.clear(); + } + pProperties->resolve( *this ); + table::BorderLine2 aBorderLine; + ConversionHelper::MakeBorderLine(m_nLineWidth, m_nLineType, m_nLineColor, aBorderLine, /*bIsOOXML=*/true); + const bool rtl = false; // TODO + switch( rName ) + { + case NS_ooxml::LN_CT_TcBorders_top: + m_aTopBorderLines.push_back(aBorderLine); + if (!m_aInteropGrabBagName.isEmpty()) + aSavedGrabBag.push_back(getInteropGrabBag("top")); + break; + case NS_ooxml::LN_CT_TcBorders_start: + if( rtl ) + m_aRightBorderLines.push_back(aBorderLine); + else m_aLeftBorderLines.push_back(aBorderLine); - if (!m_aInteropGrabBagName.isEmpty()) - aSavedGrabBag.push_back(getInteropGrabBag("left")); - break; - case NS_ooxml::LN_CT_TcBorders_bottom: - m_aBottomBorderLines.push_back(aBorderLine); - if (!m_aInteropGrabBagName.isEmpty()) - aSavedGrabBag.push_back(getInteropGrabBag("bottom")); - break; - case NS_ooxml::LN_CT_TcBorders_end: - if( rtl ) - m_aLeftBorderLines.push_back(aBorderLine); - else - m_aRightBorderLines.push_back(aBorderLine); - if (!m_aInteropGrabBagName.isEmpty()) - aSavedGrabBag.push_back(getInteropGrabBag("end")); - break; - case NS_ooxml::LN_CT_TcBorders_right: + if (!m_aInteropGrabBagName.isEmpty()) + aSavedGrabBag.push_back(getInteropGrabBag("start")); + break; + case NS_ooxml::LN_CT_TcBorders_left: + m_aLeftBorderLines.push_back(aBorderLine); + if (!m_aInteropGrabBagName.isEmpty()) + aSavedGrabBag.push_back(getInteropGrabBag("left")); + break; + case NS_ooxml::LN_CT_TcBorders_bottom: + m_aBottomBorderLines.push_back(aBorderLine); + if (!m_aInteropGrabBagName.isEmpty()) + aSavedGrabBag.push_back(getInteropGrabBag("bottom")); + break; + case NS_ooxml::LN_CT_TcBorders_end: + if( rtl ) + m_aLeftBorderLines.push_back(aBorderLine); + else m_aRightBorderLines.push_back(aBorderLine); - if (!m_aInteropGrabBagName.isEmpty()) - aSavedGrabBag.push_back(getInteropGrabBag("right")); - break; - case NS_ooxml::LN_CT_TcBorders_insideH: - m_aInsideHBorderLines.push_back(aBorderLine); - if (!m_aInteropGrabBagName.isEmpty()) - aSavedGrabBag.push_back(getInteropGrabBag("insideH")); - break; - case NS_ooxml::LN_CT_TcBorders_insideV: - m_aInsideVBorderLines.push_back(aBorderLine); - if (!m_aInteropGrabBagName.isEmpty()) - aSavedGrabBag.push_back(getInteropGrabBag("insideV")); - break; - case NS_ooxml::LN_CT_TcBorders_tl2br: - if (!m_aInteropGrabBagName.isEmpty()) - aSavedGrabBag.push_back(getInteropGrabBag("tl2br")); - break; - case NS_ooxml::LN_CT_TcBorders_tr2bl: - if (!m_aInteropGrabBagName.isEmpty()) - aSavedGrabBag.push_back(getInteropGrabBag("tr2bl")); - break; - default:; - } - if (!m_aInteropGrabBagName.isEmpty()) - m_aInteropGrabBag = aSavedGrabBag; + if (!m_aInteropGrabBagName.isEmpty()) + aSavedGrabBag.push_back(getInteropGrabBag("end")); + break; + case NS_ooxml::LN_CT_TcBorders_right: + m_aRightBorderLines.push_back(aBorderLine); + if (!m_aInteropGrabBagName.isEmpty()) + aSavedGrabBag.push_back(getInteropGrabBag("right")); + break; + case NS_ooxml::LN_CT_TcBorders_insideH: + m_aInsideHBorderLines.push_back(aBorderLine); + if (!m_aInteropGrabBagName.isEmpty()) + aSavedGrabBag.push_back(getInteropGrabBag("insideH")); + break; + case NS_ooxml::LN_CT_TcBorders_insideV: + m_aInsideVBorderLines.push_back(aBorderLine); + if (!m_aInteropGrabBagName.isEmpty()) + aSavedGrabBag.push_back(getInteropGrabBag("insideV")); + break; + case NS_ooxml::LN_CT_TcBorders_tl2br: + if (!m_aInteropGrabBagName.isEmpty()) + aSavedGrabBag.push_back(getInteropGrabBag("tl2br")); + break; + case NS_ooxml::LN_CT_TcBorders_tr2bl: + if (!m_aInteropGrabBagName.isEmpty()) + aSavedGrabBag.push_back(getInteropGrabBag("tr2bl")); + break; + default:; } + if (!m_aInteropGrabBagName.isEmpty()) + m_aInteropGrabBag = aSavedGrabBag; } diff --git a/writerfilter/source/dmapper/TableManager.cxx b/writerfilter/source/dmapper/TableManager.cxx index 61a9965227eb..ea71e887adb3 100644 --- a/writerfilter/source/dmapper/TableManager.cxx +++ b/writerfilter/source/dmapper/TableManager.cxx @@ -328,27 +328,27 @@ void TableManager::endParagraphGroup() mnTableDepth = mnTableDepthNew; - if (mnTableDepth > 0) + if (mnTableDepth <= 0) + return; + + if (isRowEnd()) { - if (isRowEnd()) - { - endOfRowAction(); - mTableDataStack.top()->endRow(getRowProps()); - mState.resetRowProps(); - } + endOfRowAction(); + mTableDataStack.top()->endRow(getRowProps()); + mState.resetRowProps(); + } - else if (isInCell()) - { - ensureOpenCell(getCellProps()); + else if (isInCell()) + { + ensureOpenCell(getCellProps()); - if (mState.isCellEnd()) - { - endOfCellAction(); - closeCell(getHandle()); - } + if (mState.isCellEnd()) + { + endOfCellAction(); + closeCell(getHandle()); } - mState.resetCellProps(); } + mState.resetCellProps(); } void TableManager::startParagraphGroup() diff --git a/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx index 285028cc9053..db4990cc6497 100644 --- a/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx +++ b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx @@ -184,38 +184,38 @@ void OOXMLDocumentImpl::importSubStreamRelations(const OOXMLStream::Pointer_t& p uno::Reference<io::XInputStream> xcpInputStream = cStream->getDocumentStream(); - if (xcpInputStream.is()) + if (!xcpInputStream.is()) + return; + + // importing itemprops files for item.xml from customXml. + if (OOXMLStream::CUSTOMXMLPROPS == nType) { - // importing itemprops files for item.xml from customXml. - if (OOXMLStream::CUSTOMXMLPROPS == nType) + try { - try - { - uno::Reference<uno::XComponentContext> xcpContext(pStream->getContext()); - uno::Reference<xml::dom::XDocumentBuilder> xDomBuilder(xml::dom::DocumentBuilder::create(xcpContext)); - xRelation = xDomBuilder->parse(xcpInputStream); - } - catch (uno::Exception const&) - { - TOOLS_WARN_EXCEPTION("writerfilter.ooxml", "importSubStream: exception while " - "parsing stream " << nType); - mxCustomXmlProsDom = xRelation; - } - - if(xRelation.is()) - { - mxCustomXmlProsDom = xRelation; - } + uno::Reference<uno::XComponentContext> xcpContext(pStream->getContext()); + uno::Reference<xml::dom::XDocumentBuilder> xDomBuilder(xml::dom::DocumentBuilder::create(xcpContext)); + xRelation = xDomBuilder->parse(xcpInputStream); } - else if(OOXMLStream::EMBEDDINGS == nType) + catch (uno::Exception const&) { - mxEmbeddings = xcpInputStream; + TOOLS_WARN_EXCEPTION("writerfilter.ooxml", "importSubStream: exception while " + "parsing stream " << nType); + mxCustomXmlProsDom = xRelation; } - else if(OOXMLStream::CHARTS == nType) + + if(xRelation.is()) { - importSubStreamRelations(cStream, OOXMLStream::EMBEDDINGS); + mxCustomXmlProsDom = xRelation; } } + else if(OOXMLStream::EMBEDDINGS == nType) + { + mxEmbeddings = xcpInputStream; + } + else if(OOXMLStream::CHARTS == nType) + { + importSubStreamRelations(cStream, OOXMLStream::EMBEDDINGS); + } } @@ -454,67 +454,67 @@ void OOXMLDocumentImpl::resolve(Stream & rStream) } } - if (xParser.is()) - { - uno::Reference<uno::XComponentContext> xContext(mpStream->getContext()); + if (!xParser.is()) + return; - OOXMLFastDocumentHandler * pDocHandler = - new OOXMLFastDocumentHandler(xContext, &rStream, this, mnXNoteId); - pDocHandler->setIsSubstream( mbIsSubstream ); - uno::Reference < xml::sax::XFastDocumentHandler > xDocumentHandler(pDocHandler); - uno::Reference < xml::sax::XFastTokenHandler > xTokenHandler(mpStream->getFastTokenHandler()); + uno::Reference<uno::XComponentContext> xContext(mpStream->getContext()); - resolveFastSubStream(rStream, OOXMLStream::SETTINGS); - mxThemeDom = importSubStream(OOXMLStream::THEME); - resolveFastSubStream(rStream, OOXMLStream::THEME); - mxGlossaryDocDom = importSubStream(OOXMLStream::GLOSSARY); - if (mxGlossaryDocDom.is()) - resolveGlossaryStream(rStream); + OOXMLFastDocumentHandler * pDocHandler = + new OOXMLFastDocumentHandler(xContext, &rStream, this, mnXNoteId); + pDocHandler->setIsSubstream( mbIsSubstream ); + uno::Reference < xml::sax::XFastDocumentHandler > xDocumentHandler(pDocHandler); + uno::Reference < xml::sax::XFastTokenHandler > xTokenHandler(mpStream->getFastTokenHandler()); - resolveEmbeddingsStream(mpStream); + resolveFastSubStream(rStream, OOXMLStream::SETTINGS); + mxThemeDom = importSubStream(OOXMLStream::THEME); + resolveFastSubStream(rStream, OOXMLStream::THEME); + mxGlossaryDocDom = importSubStream(OOXMLStream::GLOSSARY); + if (mxGlossaryDocDom.is()) + resolveGlossaryStream(rStream); - // Custom xml's are handled as part of grab bag. - resolveCustomXmlStream(rStream); + resolveEmbeddingsStream(mpStream); - resolveFastSubStream(rStream, OOXMLStream::FONTTABLE); - resolveFastSubStream(rStream, OOXMLStream::STYLES); - resolveFastSubStream(rStream, OOXMLStream::NUMBERING); + // Custom xml's are handled as part of grab bag. + resolveCustomXmlStream(rStream); - xParser->setFastDocumentHandler( xDocumentHandler ); - xParser->setTokenHandler( xTokenHandler ); + resolveFastSubStream(rStream, OOXMLStream::FONTTABLE); + resolveFastSubStream(rStream, OOXMLStream::STYLES); + resolveFastSubStream(rStream, OOXMLStream::NUMBERING); - xml::sax::InputSource aParserInput; - aParserInput.sSystemId = mpStream->getTarget(); - aParserInput.aInputStream = mpStream->getDocumentStream(); - try - { - xParser->parseStream(aParserInput); - } - catch (xml::sax::SAXException const& rErr) - { - // don't silently swallow these - handlers may not have been executed, - // and the domain mapper is likely in an inconsistent state - // In case user chooses to try to continue loading, don't ask again for this file - SfxObjectShell* rShell = SfxObjectShell::GetShellFromComponent(mxModel); - if (!rShell || !rShell->IsContinueImportOnFilterExceptions("SAXException: " + rErr.Message)) - throw; - } - catch (uno::RuntimeException const&) - { + xParser->setFastDocumentHandler( xDocumentHandler ); + xParser->setTokenHandler( xTokenHandler ); + + xml::sax::InputSource aParserInput; + aParserInput.sSystemId = mpStream->getTarget(); + aParserInput.aInputStream = mpStream->getDocumentStream(); + try + { + xParser->parseStream(aParserInput); + } + catch (xml::sax::SAXException const& rErr) + { + // don't silently swallow these - handlers may not have been executed, + // and the domain mapper is likely in an inconsistent state + // In case user chooses to try to continue loading, don't ask again for this file + SfxObjectShell* rShell = SfxObjectShell::GetShellFromComponent(mxModel); + if (!rShell || !rShell->IsContinueImportOnFilterExceptions("SAXException: " + rErr.Message)) throw; - } - // note: cannot throw anything other than SAXException out of here? - catch (uno::Exception const&) - { - css::uno::Any anyEx = cppu::getCaughtException(); - SAL_WARN("writerfilter.ooxml", "OOXMLDocumentImpl::resolve(): " << exceptionToString(anyEx)); - throw lang::WrappedTargetRuntimeException("", nullptr, anyEx); - } - catch (...) - { - SAL_WARN("writerfilter.ooxml", - "OOXMLDocumentImpl::resolve(): non-UNO exception"); - } + } + catch (uno::RuntimeException const&) + { + throw; + } + // note: cannot throw anything other than SAXException out of here? + catch (uno::Exception const&) + { + css::uno::Any anyEx = cppu::getCaughtException(); + SAL_WARN("writerfilter.ooxml", "OOXMLDocumentImpl::resolve(): " << exceptionToString(anyEx)); + throw lang::WrappedTargetRuntimeException("", nullptr, anyEx); + } + catch (...) + { + SAL_WARN("writerfilter.ooxml", + "OOXMLDocumentImpl::resolve(): non-UNO exception"); } } @@ -537,50 +537,50 @@ void OOXMLDocumentImpl::resolveCustomXmlStream(Stream & rStream) // Resolving all item[n].xml files from CustomXml folder. uno::Reference<embed::XRelationshipAccess> xRelationshipAccess; xRelationshipAccess.set(dynamic_cast<OOXMLStreamImpl&>(*mpStream).accessDocumentStream(), uno::UNO_QUERY); - if (xRelationshipAccess.is()) + if (!xRelationshipAccess.is()) + return; + + static const char sCustomType[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXml"; + static const char sCustomTypeStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/customXml"; + bool bFound = false; + const uno::Sequence<uno::Sequence< beans::StringPair>> aSeqs = xRelationshipAccess->getAllRelationships(); + std::vector<uno::Reference<xml::dom::XDocument>> aCustomXmlDomList; + std::vector<uno::Reference<xml::dom::XDocument>> aCustomXmlDomPropsList; + for (const uno::Sequence<beans::StringPair>& aSeq : aSeqs) { - static const char sCustomType[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXml"; - static const char sCustomTypeStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/customXml"; - bool bFound = false; - const uno::Sequence<uno::Sequence< beans::StringPair>> aSeqs = xRelationshipAccess->getAllRelationships(); - std::vector<uno::Reference<xml::dom::XDocument>> aCustomXmlDomList; - std::vector<uno::Reference<xml::dom::XDocument>> aCustomXmlDomPropsList; - for (const uno::Sequence<beans::StringPair>& aSeq : aSeqs) + for (const beans::StringPair& aPair : aSeq) { - for (const beans::StringPair& aPair : aSeq) + // Need to resolve only customxml files from document relationships. + // Skipping other files. + if (aPair.Second == sCustomType || + aPair.Second == sCustomTypeStrict) + bFound = true; + else if (aPair.First == "Target" && bFound) { - // Need to resolve only customxml files from document relationships. - // Skipping other files. - if (aPair.Second == sCustomType || - aPair.Second == sCustomTypeStrict) - bFound = true; - else if (aPair.First == "Target" && bFound) - { - // Adding value to extern variable customTarget. It will be used in ooxmlstreamimpl - // to ensure customxml target is visited in lcl_getTarget. - customTarget = aPair.Second; - } + // Adding value to extern variable customTarget. It will be used in ooxmlstreamimpl + // to ensure customxml target is visited in lcl_getTarget. + customTarget = aPair.Second; } + } - if (bFound) + if (bFound) + { + uno::Reference<xml::dom::XDocument> customXmlTemp = importSubStream(OOXMLStream::CUSTOMXML); + // This will add all item[n].xml with its relationship file i.e itemprops.xml to + // grabbag list. + if (mxCustomXmlProsDom.is() && customXmlTemp.is()) { - uno::Reference<xml::dom::XDocument> customXmlTemp = importSubStream(OOXMLStream::CUSTOMXML); - // This will add all item[n].xml with its relationship file i.e itemprops.xml to - // grabbag list. - if (mxCustomXmlProsDom.is() && customXmlTemp.is()) - { - aCustomXmlDomList.push_back(customXmlTemp); - aCustomXmlDomPropsList.push_back(mxCustomXmlProsDom); - resolveFastSubStream(rStream, OOXMLStream::CUSTOMXML); - } - - bFound = false; + aCustomXmlDomList.push_back(customXmlTemp); + aCustomXmlDomPropsList.push_back(mxCustomXmlProsDom); + resolveFastSubStream(rStream, OOXMLStream::CUSTOMXML); } - } - mxCustomXmlDomList = comphelper::containerToSequence(aCustomXmlDomList); - mxCustomXmlDomPropsList = comphelper::containerToSequence(aCustomXmlDomPropsList); + bFound = false; + } } + + mxCustomXmlDomList = comphelper::containerToSequence(aCustomXmlDomList); + mxCustomXmlDomPropsList = comphelper::containerToSequence(aCustomXmlDomPropsList); } void OOXMLDocumentImpl::resolveGlossaryStream(Stream & /*rStream*/) @@ -607,90 +607,90 @@ void OOXMLDocumentImpl::resolveGlossaryStream(Stream & /*rStream*/) } uno::Reference<embed::XRelationshipAccess> xRelationshipAccess; xRelationshipAccess.set(dynamic_cast<OOXMLStreamImpl&>(*pStream).accessDocumentStream(), uno::UNO_QUERY); - if (xRelationshipAccess.is()) - { - - const uno::Sequence< uno::Sequence< beans::StringPair > >aSeqs = xRelationshipAccess->getAllRelationships(); - std::vector< uno::Sequence<uno::Any> > aGlossaryDomList; - for (const uno::Sequence< beans::StringPair >& aSeq : aSeqs) - { - OOXMLStream::Pointer_t gStream; - //Follows following aSeq[0] is Id, aSeq[1] is Type, aSeq[2] is Target - if (aSeq.getLength() < 3) - { - SAL_WARN("writerfilter.ooxml", "too short sequence"); - continue; - } + if (!xRelationshipAccess.is()) + return; - OUString gId(aSeq[0].Second); - OUString gType(aSeq[1].Second); - OUString gTarget(aSeq[2].Second); - OUString contentType; - OOXMLStream::StreamType_t nType(OOXMLStream::UNKNOWN); - bool bFound = true; - if(gType == sSettingsType || - gType == sSettingsTypeStrict) - { - nType = OOXMLStream::SETTINGS; - contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml"; - } - else if(gType == sStylesType || - gType == sStylesTypeStrict) - { - nType = OOXMLStream::STYLES; - contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"; - } - else if(gType == sWebSettings || - gType == sWebSettingsStrict) - { - nType = OOXMLStream::WEBSETTINGS; - contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml"; - } - else if(gType == sFonttableType || - gType == sFonttableTypeStrict) + const uno::Sequence< uno::Sequence< beans::StringPair > >aSeqs = xRelationshipAccess->getAllRelationships(); + std::vector< uno::Sequence<uno::Any> > aGlossaryDomList; + for (const uno::Sequence< beans::StringPair >& aSeq : aSeqs) + { + OOXMLStream::Pointer_t gStream; + //Follows following aSeq[0] is Id, aSeq[1] is Type, aSeq[2] is Target + if (aSeq.getLength() < 3) + { + SAL_WARN("writerfilter.ooxml", "too short sequence"); + continue; + } + + OUString gId(aSeq[0].Second); + OUString gType(aSeq[1].Second); + OUString gTarget(aSeq[2].Second); + OUString contentType; + + OOXMLStream::StreamType_t nType(OOXMLStream::UNKNOWN); + bool bFound = true; + if(gType == sSettingsType || + gType == sSettingsTypeStrict) + { + nType = OOXMLStream::SETTINGS; + contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml"; + } + else if(gType == sStylesType || + gType == sStylesTypeStrict) + { + nType = OOXMLStream::STYLES; + contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"; + } + else if(gType == sWebSettings || + gType == sWebSettingsStrict) + { + nType = OOXMLStream::WEBSETTINGS; + contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml"; + } + else if(gType == sFonttableType || + gType == sFonttableTypeStrict) + { + nType = OOXMLStream::FONTTABLE; + contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml"; + } + else + { + bFound = false; + //"Unhandled content-type while grab bagging Glossary Folder"); + } + + if (bFound) + { + uno::Reference<xml::dom::XDocument> xDom; + try { - nType = OOXMLStream::FONTTABLE; - contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml"; + gStream = OOXMLDocumentFactory::createStream(pStream, nType); + uno::Reference<io::XInputStream> xInputStream = gStream->getDocumentStream(); + uno::Reference<uno::XComponentContext> xContext(pStream->getContext()); + uno::Reference<xml::dom::XDocumentBuilder> xDomBuilder(xml::dom::DocumentBuilder::create(xContext)); + xDom = xDomBuilder->parse(xInputStream); } - else + catch (uno::Exception const&) { - bFound = false; - //"Unhandled content-type while grab bagging Glossary Folder"); + TOOLS_INFO_EXCEPTION("writerfilter.ooxml", "importSubStream: exception while " + "parsing stream of Type" << nType); + return; } - if (bFound) + if (xDom.is()) { - uno::Reference<xml::dom::XDocument> xDom; - try - { - gStream = OOXMLDocumentFactory::createStream(pStream, nType); - uno::Reference<io::XInputStream> xInputStream = gStream->getDocumentStream(); - uno::Reference<uno::XComponentContext> xContext(pStream->getContext()); - uno::Reference<xml::dom::XDocumentBuilder> xDomBuilder(xml::dom::DocumentBuilder::create(xContext)); - xDom = xDomBuilder->parse(xInputStream); - } - catch (uno::Exception const&) - { - TOOLS_INFO_EXCEPTION("writerfilter.ooxml", "importSubStream: exception while " - "parsing stream of Type" << nType); - return; - } - - if (xDom.is()) - { - uno::Sequence< uno::Any > glossaryTuple (5); - glossaryTuple[0] <<= xDom; - glossaryTuple[1] <<= gId; - glossaryTuple[2] <<= gType; - glossaryTuple[3] <<= gTarget; - glossaryTuple[4] <<= contentType; - aGlossaryDomList.push_back(glossaryTuple); - } + uno::Sequence< uno::Any > glossaryTuple (5); + glossaryTuple[0] <<= xDom; + glossaryTuple[1] <<= gId; + glossaryTuple[2] <<= gType; + glossaryTuple[3] <<= gTarget; + glossaryTuple[4] <<= contentType; + aGlossaryDomList.push_back(glossaryTuple); } - } - mxGlossaryDomList = comphelper::containerToSequence(aGlossaryDomList); + } } + mxGlossaryDomList = comphelper::containerToSequence(aGlossaryDomList); } void OOXMLDocumentImpl::resolveEmbeddingsStream(const OOXMLStream::Pointer_t& pStream) diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx index 4cdcecb49b12..d4ba7779b0b0 100644 --- a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx +++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx @@ -333,20 +333,20 @@ Token_t OOXMLFastContextHandler::getToken() const void OOXMLFastContextHandler::sendTableDepth() const { - if (mnTableDepth > 0) - { - OOXMLPropertySet::Pointer_t pProps(new OOXMLPropertySet); - { - OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(mnTableDepth); - pProps->add(NS_ooxml::LN_tblDepth, pVal, OOXMLProperty::SPRM); - } - { - OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(1); - pProps->add(NS_ooxml::LN_inTbl, pVal, OOXMLProperty::SPRM); - } + if (mnTableDepth <= 0) + return; - mpStream->props(pProps.get()); + OOXMLPropertySet::Pointer_t pProps(new OOXMLPropertySet); + { + OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(mnTableDepth); + pProps->add(NS_ooxml::LN_tblDepth, pVal, OOXMLProperty::SPRM); } + { + OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(1); + pProps->add(NS_ooxml::LN_inTbl, pVal, OOXMLProperty::SPRM); + } + + mpStream->props(pProps.get()); } void OOXMLFastContextHandler::setHandle() @@ -357,25 +357,25 @@ void OOXMLFastContextHandler::setHandle() void OOXMLFastContextHandler::startCharacterGroup() { - if (isForwardEvents()) - { - if (mpParserState->isInCharacterGroup()) - endCharacterGroup(); + if (!isForwardEvents()) + return; - if (! mpParserState->isInParagraphGroup()) - startParagraphGroup(); + if (mpParserState->isInCharacterGroup()) + endCharacterGroup(); - if (! mpParserState->isInCharacterGroup()) - { - mpStream->startCharacterGroup(); - mpParserState->setInCharacterGroup(true); - mpParserState->resolveCharacterProperties(*mpStream); - } + if (! mpParserState->isInParagraphGroup()) + startParagraphGroup(); - // tdf#108714 : if we have a postponed break information, - // then apply it now, before any other paragraph content. - mpParserState->resolvePostponedBreak(*mpStream); + if (! mpParserState->isInCharacterGroup()) + { + mpStream->startCharacterGroup(); + mpParserState->setInCharacterGroup(true); + mpParserState->resolveCharacterProperties(*mpStream); } + + // tdf#108714 : if we have a postponed break information, + // then apply it now, before any other paragraph content. + mpParserState->resolvePostponedBreak(*mpStream); } void OOXMLFastContextHandler::endCharacterGroup() @@ -393,19 +393,19 @@ void OOXMLFastContextHandler::popBiDiEmbedLevel() {} void OOXMLFastContextHandler::startParagraphGroup() { - if (isForwardEvents()) - { - if (mpParserState->isInParagraphGroup()) - endParagraphGroup(); + if (!isForwardEvents()) + return; - if (! mpParserState->isInSectionGroup()) - startSectionGroup(); + if (mpParserState->isInParagraphGroup()) + endParagraphGroup(); - if (! mpParserState->isInParagraphGroup()) - { - mpStream->startParagraphGroup(); - mpParserState->setInParagraphGroup(true); - } + if (! mpParserState->isInSectionGroup()) + startSectionGroup(); + + if (! mpParserState->isInParagraphGroup()) + { + mpStream->startParagraphGroup(); + mpParserState->setInParagraphGroup(true); } } @@ -650,21 +650,21 @@ OUString TrimXMLWhitespace(const OUString & sText) void OOXMLFastContextHandler::text(const OUString & sText) { - if (isForwardEvents()) + if (!isForwardEvents()) + return; + + // tdf#108806: CRLFs in XML were converted to \n before this point. + // These must be converted to spaces before further processing. + OUString sNormalizedText = sText.replaceAll("\n", " "); + // tdf#108995: by default, leading and trailing white space is ignored; + // tabs are converted to spaces + if (!IsPreserveSpace()) { - // tdf#108806: CRLFs in XML were converted to \n before this point. - // These must be converted to spaces before further processing. - OUString sNormalizedText = sText.replaceAll("\n", " "); - // tdf#108995: by default, leading and trailing white space is ignored; - // tabs are converted to spaces - if (!IsPreserveSpace()) - { - sNormalizedText = TrimXMLWhitespace(sNormalizedText).replaceAll("\t", " "); - } - mpStream->utext(reinterpret_cast < const sal_uInt8 * > - (sNormalizedText.getStr()), - sNormalizedText.getLength()); + sNormalizedText = TrimXMLWhitespace(sNormalizedText).replaceAll("\t", " "); } + mpStream->utext(reinterpret_cast < const sal_uInt8 * > + (sNormalizedText.getStr()), + sNormalizedText.getLength()); } void OOXMLFastContextHandler::positionOffset(const OUString& rText) @@ -886,23 +886,23 @@ void OOXMLFastContextHandler::sendPropertyToParent() void OOXMLFastContextHandler::sendPropertiesToParent() { - if (mpParent != nullptr) - { - OOXMLPropertySet::Pointer_t pParentProps(mpParent->getPropertySet()); + if (mpParent == nullptr) + return; - if (pParentProps) - { - OOXMLPropertySet::Pointer_t pProps(getPropertySet()); + OOXMLPropertySet::Pointer_t pParentProps(mpParent->getPropertySet()); - if (pProps) - { - OOXMLValue::Pointer_t pValue - (new OOXMLPropertySetValue(getPropertySet())); + if (!pParentProps) + return; - pParentProps->add(getId(), pValue, OOXMLProperty::SPRM); + OOXMLPropertySet::Pointer_t pProps(getPropertySet()); + + if (pProps) + { + OOXMLValue::Pointer_t pValue + (new OOXMLPropertySetValue(getPropertySet())); + + pParentProps->add(getId(), pValue, OOXMLProperty::SPRM); - } - } } } @@ -1393,28 +1393,28 @@ void OOXMLFastContextHandlerTextTableCell::startCell() void OOXMLFastContextHandlerTextTableCell::endCell() { - if (isForwardEvents()) - { - OOXMLPropertySet::Pointer_t pProps(new OOXMLPropertySet); - { - OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(mnTableDepth); - pProps->add(NS_ooxml::LN_tblDepth, pVal, OOXMLProperty::SPRM); - } - { - OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(1); - pProps->add(NS_ooxml::LN_inTbl, pVal, OOXMLProperty::SPRM); - } - { - OOXMLValue::Pointer_t pVal = OOXMLBooleanValue::Create(mnTableDepth > 0); - pProps->add(NS_ooxml::LN_tblCell, pVal, OOXMLProperty::SPRM); - } - { - OOXMLValue::Pointer_t pVal = OOXMLBooleanValue::Create(mnTableDepth > 0); - pProps->add(NS_ooxml::LN_tcEnd, pVal, OOXMLProperty::SPRM); - } + if (!isForwardEvents()) + return; - mpStream->props(pProps.get()); + OOXMLPropertySet::Pointer_t pProps(new OOXMLPropertySet); + { + OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(mnTableDepth); + pProps->add(NS_ooxml::LN_tblDepth, pVal, OOXMLProperty::SPRM); + } + { + OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(1); + pProps->add(NS_ooxml::LN_inTbl, pVal, OOXMLProperty::SPRM); + } + { + OOXMLValue::Pointer_t pVal = OOXMLBooleanValue::Create(mnTableDepth > 0); + pProps->add(NS_ooxml::LN_tblCell, pVal, OOXMLProperty::SPRM); } + { + OOXMLValue::Pointer_t pVal = OOXMLBooleanValue::Create(mnTableDepth > 0); + pProps->add(NS_ooxml::LN_tcEnd, pVal, OOXMLProperty::SPRM); + } + + mpStream->props(pProps.get()); } /* @@ -1678,59 +1678,57 @@ void OOXMLFastContextHandlerShape::setToken(Token_t nToken) void OOXMLFastContextHandlerShape::sendShape( Token_t Element ) { - if ( mrShapeContext.is() && !m_bShapeSent ) - { - awt::Point aPosition = mpStream->getPositionOffset(); - mrShapeContext->setPosition(aPosition); - uno::Reference<drawing::XShape> xShape(mrShapeContext->getShape()); - m_bShapeSent = true; - if (xShape.is()) - { - OOXMLValue::Pointer_t - pValue(new OOXMLShapeValue(xShape)); - newProperty(NS_ooxml::LN_shape, pValue); + if ( !(mrShapeContext.is() && !m_bShapeSent) ) + return; - bool bIsPicture = Element == ( NMSP_dmlPicture | XML_pic ); + awt::Point aPosition = mpStream->getPositionOffset(); + mrShapeContext->setPosition(aPosition); + uno::Reference<drawing::XShape> xShape(mrShapeContext->getShape()); + m_bShapeSent = true; + if (!xShape.is()) + return; - //tdf#87569: Fix table layout with correcting anchoring - //If anchored object is in table, Word calculates its position from cell border - //instead of page (what is set in the sample document) - uno::Reference<beans::XPropertySet> xShapePropSet(xShape, uno::UNO_QUERY); - if (mnTableDepth > 0 && xShapePropSet.is() && mbIsVMLfound) //if we had a table - { - xShapePropSet->setPropertyValue(dmapper::getPropertyName(dmapper::PROP_FOLLOW_TEXT_FLOW), - uno::makeAny(mbAllowInCell)); - } - // Notify the dmapper that the shape is ready to use - if ( !bIsPicture ) - { - mpStream->startShape( xShape ); - m_bShapeStarted = true; - } - } + OOXMLValue::Pointer_t + pValue(new OOXMLShapeValue(xShape)); + newProperty(NS_ooxml::LN_shape, pValue); + + bool bIsPicture = Element == ( NMSP_dmlPicture | XML_pic ); + + //tdf#87569: Fix table layout with correcting anchoring + //If anchored object is in table, Word calculates its position from cell border + //instead of page (what is set in the sample document) + uno::Reference<beans::XPropertySet> xShapePropSet(xShape, uno::UNO_QUERY); + if (mnTableDepth > 0 && xShapePropSet.is() && mbIsVMLfound) //if we had a table + { + xShapePropSet->setPropertyValue(dmapper::getPropertyName(dmapper::PROP_FOLLOW_TEXT_FLOW), + uno::makeAny(mbAllowInCell)); + } + // Notify the dmapper that the shape is ready to use + if ( !bIsPicture ) + { + mpStream->startShape( xShape ); + m_bShapeStarted = true; } } void OOXMLFastContextHandlerShape::lcl_endFastElement (Token_t Element) { - if (isForwardEvents()) - { - - if (mrShapeContext.is()) - { - mrShapeContext->endFastElement(Element); - sendShape( Element ); - } + if (!isForwardEvents()) + return; - OOXMLFastContextHandlerProperties::lcl_endFastElement(Element); + if (mrShapeContext.is()) + { + mrShapeContext->endFastElement(Element); + sendShape( Element ); + } - // Ending the shape should be the last thing to do - bool bIsPicture = Element == ( NMSP_dmlPicture | XML_pic ); - if ( !bIsPicture && m_bShapeStarted) - mpStream->endShape( ); + OOXMLFastContextHandlerProperties::lcl_endFastElement(Element); - } + // Ending the shape should be the last thing to do + bool bIsPicture = Element == ( NMSP_dmlPicture | XML_pic ); + if ( !bIsPicture && m_bShapeStarted) + mpStream->endShape( ); } void SAL_CALL OOXMLFastContextHandlerShape::endUnknownElement @@ -2159,34 +2157,34 @@ void OOXMLFastContextHandlerMath::process() // to RTLD_GLOBAL, so most probably a gcc bug. oox::FormulaImportBase& import = dynamic_cast<oox::FormulaImportBase&>(dynamic_cast<SfxBaseModel&>(*component)); import.readFormulaOoxml(buffer); - if (isForwardEvents()) + if (!isForwardEvents()) + return; + + OOXMLPropertySet::Pointer_t pProps(new OOXMLPropertySet); + OOXMLValue::Pointer_t pVal( new OOXMLStarMathValue( ref )); + if (mbIsMathPara) { - OOXMLPropertySet::Pointer_t pProps(new OOXMLPropertySet); - OOXMLValue::Pointer_t pVal( new OOXMLStarMathValue( ref )); - if (mbIsMathPara) + switch (mnMathJcVal) { - switch (mnMathJcVal) - { - case eMathParaJc::CENTER: - pProps->add(NS_ooxml::LN_Value_math_ST_Jc_centerGroup, pVal, - OOXMLProperty::ATTRIBUTE); - break; - case eMathParaJc::LEFT: - pProps->add(NS_ooxml::LN_Value_math_ST_Jc_left, pVal, - OOXMLProperty::ATTRIBUTE); - break; - case eMathParaJc::RIGHT: - pProps->add(NS_ooxml::LN_Value_math_ST_Jc_right, pVal, - OOXMLProperty::ATTRIBUTE); - break; - default: - break; - } + case eMathParaJc::CENTER: + pProps->add(NS_ooxml::LN_Value_math_ST_Jc_centerGroup, pVal, + OOXMLProperty::ATTRIBUTE); + break; + case eMathParaJc::LEFT: + pProps->add(NS_ooxml::LN_Value_math_ST_Jc_left, pVal, + OOXMLProperty::ATTRIBUTE); + break; + case eMathParaJc::RIGHT: + pProps->add(NS_ooxml::LN_Value_math_ST_Jc_right, pVal, + OOXMLProperty::ATTRIBUTE); + break; + default: + break; } - else - pProps->add(NS_ooxml::LN_starmath, pVal, OOXMLProperty::ATTRIBUTE); - mpStream->props( pProps.get() ); } + else + pProps->add(NS_ooxml::LN_starmath, pVal, OOXMLProperty::ATTRIBUTE); + mpStream->props( pProps.get() ); } } diff --git a/writerfilter/source/ooxml/OOXMLPropertySet.cxx b/writerfilter/source/ooxml/OOXMLPropertySet.cxx index f413ced61d41..1d1724c9c451 100644 --- a/writerfilter/source/ooxml/OOXMLPropertySet.cxx +++ b/writerfilter/source/ooxml/OOXMLPropertySet.cxx @@ -575,23 +575,23 @@ string OOXMLHexValue::toString() const OOXMLHexColorValue::OOXMLHexColorValue(const char * pValue) : OOXMLHexValue(sal_uInt32(COL_AUTO)) { - if (strcmp(pValue, "auto")) - { - mnValue = rtl_str_toUInt32(pValue, 16); + if (!strcmp(pValue, "auto")) + return; + + mnValue = rtl_str_toUInt32(pValue, 16); - // Convert hash-encoded values (like #FF0080) - const sal_Int32 nLen = strlen(pValue); - if ( !mnValue && nLen > 1 && pValue[0] == '#' ) + // Convert hash-encoded values (like #FF0080) + const sal_Int32 nLen = strlen(pValue); + if ( !mnValue && nLen > 1 && pValue[0] == '#' ) + { + sal_Int32 nColor(COL_AUTO); + // Word appears to require strict 6 digit length, else it ignores it + if ( nLen == 7 ) { - sal_Int32 nColor(COL_AUTO); - // Word appears to require strict 6 digit length, else it ignores it - if ( nLen == 7 ) - { - const OUString sHashColor(pValue, nLen, RTL_TEXTENCODING_ASCII_US); - sax::Converter::convertColor( nColor, sHashColor ); - } - mnValue = nColor; + const OUString sHashColor(pValue, nLen, RTL_TEXTENCODING_ASCII_US); + sax::Converter::convertColor( nColor, sHashColor ); } + mnValue = nColor; } } diff --git a/writerfilter/source/ooxml/OOXMLStreamImpl.cxx b/writerfilter/source/ooxml/OOXMLStreamImpl.cxx index 73e527a5543e..7d48f1c08fce 100644 --- a/writerfilter/source/ooxml/OOXMLStreamImpl.cxx +++ b/writerfilter/source/ooxml/OOXMLStreamImpl.cxx @@ -348,25 +348,25 @@ void OOXMLStreamImpl::init() bool bFound = lcl_getTarget(mxRelationshipAccess, mnStreamType, msId, msTarget); - if (bFound) - { - sal_Int32 nLastIndex = msTarget.lastIndexOf('/'); - if (nLastIndex >= 0) - msPath = msTarget.copy(0, nLastIndex + 1); + if (!bFound) + return; - uno::Reference<embed::XHierarchicalStorageAccess> - xHierarchicalStorageAccess(mxStorage, uno::UNO_QUERY); + sal_Int32 nLastIndex = msTarget.lastIndexOf('/'); + if (nLastIndex >= 0) + msPath = msTarget.copy(0, nLastIndex + 1); - if (xHierarchicalStorageAccess.is()) - { - uno::Any aAny(xHierarchicalStorageAccess-> - openStreamElementByHierarchicalName - (msTarget, embed::ElementModes::SEEKABLEREAD)); - aAny >>= mxDocumentStream; - // Non-cached ID lookup works by accessing mxDocumentStream as an embed::XRelationshipAccess. - // So when it changes, we should empty the cache. - maIdCache.clear(); - } + uno::Reference<embed::XHierarchicalStorageAccess> + xHierarchicalStorageAccess(mxStorage, uno::UNO_QUERY); + + if (xHierarchicalStorageAccess.is()) + { + uno::Any aAny(xHierarchicalStorageAccess-> + openStreamElementByHierarchicalName + (msTarget, embed::ElementModes::SEEKABLEREAD)); + aAny >>= mxDocumentStream; + // Non-cached ID lookup works by accessing mxDocumentStream as an embed::XRelationshipAccess. + // So when it changes, we should empty the cache. + maIdCache.clear(); } } diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index 9fcbcf2a2f09..1f4ebda582d7 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -381,25 +381,25 @@ void RTFDocumentImpl::outputSettingsTable() void RTFDocumentImpl::checkFirstRun() { - if (m_bFirstRun) - { - outputSettingsTable(); - // start initial paragraph - m_bFirstRun = false; - assert(!m_bNeedSect || m_bFirstRunException); - setNeedSect(true); // first call that succeeds + if (!m_bFirstRun) + return; - // set the requested default font, if there are none - RTFValue::Pointer_t pFont - = getNestedAttribute(m_aDefaultState.getCharacterSprms(), - NS_ooxml::LN_EG_RPrBase_rFonts, NS_ooxml::LN_CT_Fonts_ascii); - RTFValue::Pointer_t pCurrentFont - = getNestedAttribute(m_aStates.top().getCharacterSprms(), - NS_ooxml::LN_EG_RPrBase_rFonts, NS_ooxml::LN_CT_Fonts_ascii); - if (pFont && !pCurrentFont) - putNestedAttribute(m_aStates.top().getCharacterSprms(), NS_ooxml::LN_EG_RPrBase_rFonts, - NS_ooxml::LN_CT_Fonts_ascii, pFont); - } + outputSettingsTable(); + // start initial paragraph + m_bFirstRun = false; + assert(!m_bNeedSect || m_bFirstRunException); + setNeedSect(true); // first call that succeeds + + // set the requested default font, if there are none + RTFValue::Pointer_t pFont + = getNestedAttribute(m_aDefaultState.getCharacterSprms(), NS_ooxml::LN_EG_RPrBase_rFonts, + NS_ooxml::LN_CT_Fonts_ascii); + RTFValue::Pointer_t pCurrentFont + = getNestedAttribute(m_aStates.top().getCharacterSprms(), NS_ooxml::LN_EG_RPrBase_rFonts, + NS_ooxml::LN_CT_Fonts_ascii); + if (pFont && !pCurrentFont) + putNestedAttribute(m_aStates.top().getCharacterSprms(), NS_ooxml::LN_EG_RPrBase_rFonts, + NS_ooxml::LN_CT_Fonts_ascii, pFont); } void RTFDocumentImpl::setNeedPar(bool bNeedPar) { m_bNeedPar = bNeedPar; } @@ -540,46 +540,46 @@ RTFDocumentImpl::getProperties(const RTFSprms& rAttributes, RTFSprms const& rSpr void RTFDocumentImpl::checkNeedPap() { - if (m_bNeedPap) - { - m_bNeedPap = false; // reset early, so we can avoid recursion when calling ourselves + if (!m_bNeedPap) + return; - if (m_aStates.empty()) - return; + m_bNeedPap = false; // reset early, so we can avoid recursion when calling ourselves - if (!m_aStates.top().getCurrentBuffer()) - { - writerfilter::Reference<Properties>::Pointer_t const pParagraphProperties(getProperties( - m_aStates.top().getParagraphAttributes(), m_aStates.top().getParagraphSprms(), - NS_ooxml::LN_Value_ST_StyleType_paragraph)); + if (m_aStates.empty()) + return; - // Writer will ignore a page break before a text frame, so guard it with empty paragraphs - bool hasBreakBeforeFrame = m_aStates.top().getFrame().hasProperties() - && m_aStates.top().getParagraphSprms().find( - NS_ooxml::LN_CT_PPrBase_pageBreakBefore); - if (hasBreakBeforeFrame) - { - dispatchSymbol(RTF_PAR); - m_bNeedPap = false; - } - Mapper().props(pParagraphProperties); - if (hasBreakBeforeFrame) - dispatchSymbol(RTF_PAR); + if (!m_aStates.top().getCurrentBuffer()) + { + writerfilter::Reference<Properties>::Pointer_t const pParagraphProperties(getProperties( + m_aStates.top().getParagraphAttributes(), m_aStates.top().getParagraphSprms(), + NS_ooxml::LN_Value_ST_StyleType_paragraph)); - if (m_aStates.top().getFrame().hasProperties()) - { - writerfilter::Reference<Properties>::Pointer_t const pFrameProperties( - new RTFReferenceProperties(RTFSprms(), m_aStates.top().getFrame().getSprms())); - Mapper().props(pFrameProperties); - } + // Writer will ignore a page break before a text frame, so guard it with empty paragraphs + bool hasBreakBeforeFrame + = m_aStates.top().getFrame().hasProperties() + && m_aStates.top().getParagraphSprms().find(NS_ooxml::LN_CT_PPrBase_pageBreakBefore); + if (hasBreakBeforeFrame) + { + dispatchSymbol(RTF_PAR); + m_bNeedPap = false; } - else + Mapper().props(pParagraphProperties); + if (hasBreakBeforeFrame) + dispatchSymbol(RTF_PAR); + + if (m_aStates.top().getFrame().hasProperties()) { - auto pValue = new RTFValue(m_aStates.top().getParagraphAttributes(), - m_aStates.top().getParagraphSprms()); - bufferProperties(*m_aStates.top().getCurrentBuffer(), pValue, nullptr); + writerfilter::Reference<Properties>::Pointer_t const pFrameProperties( + new RTFReferenceProperties(RTFSprms(), m_aStates.top().getFrame().getSprms())); + Mapper().props(pFrameProperties); } } + else + { + auto pValue = new RTFValue(m_aStates.top().getParagraphAttributes(), + m_aStates.top().getParagraphSprms()); + bufferProperties(*m_aStates.top().getCurrentBuffer(), pValue, nullptr); + } } void RTFDocumentImpl::runProps() |