[Libreoffice-commits] core.git: 2 commits - writerfilter/source xmlsecurity/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Sun Aug 2 20:45:24 UTC 2020


 writerfilter/source/dmapper/DomainMapper.cxx                  |   84 
 writerfilter/source/dmapper/DomainMapper_Impl.cxx             | 2274 +++++-----
 writerfilter/source/dmapper/FormControlHelper.cxx             |  124 
 writerfilter/source/dmapper/NumberingManager.cxx              |  692 +--
 writerfilter/source/dmapper/PropertyMap.cxx                   |   54 
 writerfilter/source/dmapper/SdtHelper.cxx                     |   85 
 writerfilter/source/dmapper/SettingsTable.cxx                 |   52 
 writerfilter/source/dmapper/SmartTagHandler.cxx               |   61 
 writerfilter/source/dmapper/TDefTableHandler.cxx              |  140 
 writerfilter/source/dmapper/TableManager.cxx                  |   32 
 writerfilter/source/ooxml/OOXMLDocumentImpl.cxx               |  372 -
 writerfilter/source/ooxml/OOXMLFastContextHandler.cxx         |  298 -
 writerfilter/source/ooxml/OOXMLPropertySet.cxx                |   28 
 writerfilter/source/ooxml/OOXMLStreamImpl.cxx                 |   34 
 writerfilter/source/rtftok/rtfdocumentimpl.cxx                |  100 
 xmlsecurity/source/component/documentdigitalsignatures.cxx    |   38 
 xmlsecurity/source/dialogs/certificateviewer.cxx              |   70 
 xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx        |   66 
 xmlsecurity/source/dialogs/macrosecurity.cxx                  |  122 
 xmlsecurity/source/framework/buffernode.cxx                   |   90 
 xmlsecurity/source/framework/saxeventkeeperimpl.cxx           |  229 -
 xmlsecurity/source/framework/signatureengine.cxx              |   46 
 xmlsecurity/source/helper/ooxmlsecexporter.cxx                |   26 
 xmlsecurity/source/helper/xsecctl.cxx                         |   64 
 xmlsecurity/source/helper/xsecverify.cxx                      |  122 
 xmlsecurity/source/xmlsec/nss/digestcontext.cxx               |   28 
 xmlsecurity/source/xmlsec/nss/nssinitializer.cxx              |   24 
 xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx |   74 
 xmlsecurity/source/xmlsec/xmldocumentwrapper_xmlsecimpl.cxx   |   54 
 29 files changed, 2739 insertions(+), 2744 deletions(-)

New commits:
commit e2644b014005e1c79b0a7eaf1c3c4002464a1cf0
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Sun Aug 2 20:08:17 2020 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sun Aug 2 22:44:54 2020 +0200

    loplugin:flatten in writerfilter
    
    Change-Id: Ifaa63738c4e38dddd385821f568911927d834f1e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99966
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

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,56 +2569,56 @@ 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);
         }
-        catch( const uno::Exception & )
+        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)
         {
-            OSL_FAIL( "Exception in makeRedline" );
+            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) );
+        }
+    }
+    catch( const uno::Exception & )
+    {
+        OSL_FAIL( "Exception in makeRedline" );
     }
 }
 
@@ -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();
+
+    try
+    {
+        uno::Reference< uno::XInterface > xFieldInterface;
 
-            const auto& [sType, vArguments, vSwitches]{ splitFieldCommand(pContext->GetCommand()) };
-            (void)vSwitches;
-            OUString const sFirstParam(vArguments.empty() ? OUString() : vArguments.front());
+        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(

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list