[Libreoffice-commits] core.git: 3 commits - officecfg/registry sw/qa sw/source writerfilter/source

Michael Stahl (via logerrit) logerrit at kemper.freedesktop.org
Wed Oct 23 11:10:54 UTC 2019


 officecfg/registry/schema/org/openoffice/Office/Common.xcs |    6 +++
 sw/qa/extras/ooxmlexport/ooxmlexport12.cxx                 |    2 -
 sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx              |    2 -
 sw/source/filter/ww8/docxattributeoutput.cxx               |   21 +++++++++++--
 sw/source/filter/ww8/docxattributeoutput.hxx               |    7 +++-
 sw/source/filter/ww8/rtfattributeoutput.cxx                |   21 ++++++++-----
 writerfilter/source/dmapper/DomainMapper.cxx               |    8 +++-
 writerfilter/source/dmapper/DomainMapper_Impl.cxx          |    3 +
 writerfilter/source/dmapper/DomainMapper_Impl.hxx          |    3 +
 9 files changed, 56 insertions(+), 17 deletions(-)

New commits:
commit ddd08c8996d444d7c0fe49d083c4f70f0a278d14
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Wed Oct 2 18:49:47 2019 +0200
Commit:     Michael Stahl <michael.stahl at cib.de>
CommitDate: Wed Oct 23 13:09:44 2019 +0200

    writerfilter: add config to import all fields as generic, incl. commands
    
    Change-Id: I02d178de3672200b69e60ba5841c993fa0d797f9
    Reviewed-on: https://gerrit.libreoffice.org/80076
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.stahl at cib.de>

diff --git a/officecfg/registry/schema/org/openoffice/Office/Common.xcs b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
index 5eeb6c570331..8f33efdb29cb 100644
--- a/officecfg/registry/schema/org/openoffice/Office/Common.xcs
+++ b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
@@ -3870,6 +3870,12 @@
             </info>
             <value>true</value>
           </prop>
+          <prop oor:name="ForceImportWWFieldsAsGenericFields" oor:type="xs:boolean" oor:nillable="false">
+            <info>
+              <desc>Experimental: force all fields in RTF/DOCX to be imported as dumb generic enhanced fields.</desc>
+            </info>
+            <value>false</value>
+          </prop>
           <prop oor:name="CreateMSOLockFiles" oor:type="xs:boolean" oor:nillable="false">
             <info>
               <desc>Specifies if LO should create MSO lock files next to the LO lock files
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index cb46699fad95..5ad13d6145e5 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -3111,8 +3111,10 @@ void DomainMapper::lcl_text(const sal_uInt8 * data_, size_t len)
             m_pImpl->SetCustomFtnMark( false );
             //otherwise ignore sText
         }
-        else if( m_pImpl->IsOpenFieldCommand() )
+        else if (m_pImpl->IsOpenFieldCommand() && !m_pImpl->IsForceGenericFields())
+        {
             m_pImpl->AppendFieldCommand(sText);
+        }
         else if( m_pImpl->IsOpenField() && m_pImpl->IsFieldResultAsString())
              /*depending on the success of the field insert operation this result will be
               set at the field or directly inserted into the text*/
@@ -3380,8 +3382,10 @@ void DomainMapper::lcl_utext(const sal_uInt8 * data_, size_t len)
                 pContext->GetFootnote()->setLabel( sText );
                 //otherwise ignore sText
             }
-            else if( m_pImpl->IsOpenFieldCommand() )
+            else if (m_pImpl->IsOpenFieldCommand() && !m_pImpl->IsForceGenericFields())
+            {
                 m_pImpl->AppendFieldCommand(sText);
+            }
             else if( m_pImpl->IsOpenField() && m_pImpl->IsFieldResultAsString())
                 /*depending on the success of the field insert operation this result will be
                   set at the field or directly inserted into the text*/
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index f23775bc8731..9df643e07f4f 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -193,6 +193,7 @@ DomainMapper_Impl::DomainMapper_Impl(
         m_xTextDocument( xModel, uno::UNO_QUERY ),
         m_xTextFactory( xModel, uno::UNO_QUERY ),
         m_xComponentContext( xContext ),
+        m_bForceGenericFields(!utl::ConfigManager::IsFuzzing() && officecfg::Office::Common::Filter::Microsoft::Import::ForceImportWWFieldsAsGenericFields::get(m_xComponentContext)),
         m_bSetUserFieldContent( false ),
         m_bSetCitation( false ),
         m_bSetDateValue( false ),
@@ -4354,7 +4355,7 @@ void DomainMapper_Impl::CloseFieldCommand()
 
             FieldConversionMap_t::const_iterator const aIt =
                 aFieldConversionMap.find(std::get<0>(field));
-            if(aIt != aFieldConversionMap.end())
+            if (aIt != aFieldConversionMap.end() && !m_bForceGenericFields)
             {
                 pContext->SetFieldId(aIt->second.eFieldId);
 
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index 6f5aaedd1fed..813d45bab770 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -418,6 +418,7 @@ private:
     std::stack<AnchoredContext>                                                     m_aAnchoredStack;
     std::stack<HeaderFooterContext>                                                 m_aHeaderFooterStack;
     std::stack<FieldContextPtr>                                                     m_aFieldStack;
+    bool m_bForceGenericFields;
     bool                                                                            m_bSetUserFieldContent;
     bool                                                                            m_bSetCitation;
     bool                                                                            m_bSetDateValue;
@@ -1000,6 +1001,8 @@ public:
 
     bool IsDiscardHeaderFooter() const;
 
+    bool IsForceGenericFields() const { return m_bForceGenericFields; }
+
     void SetParaAutoBefore(bool bParaAutoBefore) { m_bParaAutoBefore = bParaAutoBefore; }
 
     /// Forget about the previous paragraph, as it's not inside the same
commit 94e0b8407b02d76b27324b8b08012eb024aca9e9
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Mon Oct 21 18:33:51 2019 +0200
Commit:     Michael Stahl <michael.stahl at cib.de>
CommitDate: Wed Oct 23 13:09:20 2019 +0200

    sw: DOCX export of nested fieldmarks
    
    The DocxAttributeOutput was more or less ignoring FieldFlags::CmdEnd;
    split CmdField_Impl() into 2 functions to write the command text with
    the Start like WW8/RTF and the separator with the CmdEnd.
    
    Change-Id: I7cfa52e2d786a8c9b427057eadc9ccc271d2f90f
    Reviewed-on: https://gerrit.libreoffice.org/81263
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.stahl at cib.de>

diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx
index b60c6cd571e6..c48efcb95cc0 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx
@@ -678,7 +678,7 @@ DECLARE_OOXMLEXPORT_TEST(testTdf79435_legacyInputFields, "tdf79435_legacyInputFi
 {
     //using .doc input file to verify cross-format compatibility.
     uno::Reference<text::XFormField> xFormField
-        = getProperty<uno::Reference<text::XFormField>>(getRun(getParagraph(5), 2), "Bookmark");
+        = getProperty<uno::Reference<text::XFormField>>(getRun(getParagraph(5), 3), "Bookmark");
     uno::Reference<container::XNameContainer> xParameters(xFormField->getParameters());
 
     OUString sTmp;
diff --git a/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx
index 3996c634ab8f..15390ccd574c 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx
@@ -537,7 +537,7 @@ DECLARE_OOXMLEXPORT_TEST(testSdtDateDuplicate, "sdt-date-duplicate.docx")
 DECLARE_OOXMLEXPORT_TEST(testFdo81492, "fdo81492.docx")
 {
     if (xmlDocPtr pXmlDoc = parseExport())
-        assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[1]/w:r[7]/w:instrText", "ADDIN EN.CITE.DATA");
+        assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[1]/w:r[6]/w:instrText", "ADDIN EN.CITE.DATA");
 }
 
 DECLARE_OOXMLEXPORT_TEST(testEditTime, "fdo81341.docx")
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 3eb6cf085b7c..9e5c5aad1784 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -1394,7 +1394,18 @@ void DocxAttributeOutput::EndRun(const SwTextNode* pNode, sal_Int32 nPos, bool /
                 ++m_nFieldsInHyperlink;
 
             // Remove the field if no end needs to be written
-            if ( !pIt->bClose ) {
+            if (!pIt->bSep)
+            {
+                pIt = m_Fields.erase( pIt );
+                continue;
+            }
+        }
+        if (pIt->bSep && !pIt->pField)
+        {
+            CmdEndField_Impl(pNode, nPos, true);
+            // Remove the field if no end needs to be written
+            if (!pIt->bClose)
+            {
                 pIt = m_Fields.erase( pIt );
                 continue;
             }
@@ -2073,9 +2084,12 @@ void DocxAttributeOutput::CmdField_Impl( const SwTextNode* pNode, sal_Int32 nPos
             m_pSerializer->endElementNS( XML_w, XML_r );
         }
     }
+}
 
+void DocxAttributeOutput::CmdEndField_Impl(SwTextNode const*const pNode,
+        sal_Int32 const nPos, bool const bWriteRun)
+{
     // Write the Field separator
-    {
         if ( bWriteRun )
         {
             m_pSerializer->startElementNS(XML_w, XML_r);
@@ -2089,7 +2103,6 @@ void DocxAttributeOutput::CmdField_Impl( const SwTextNode* pNode, sal_Int32 nPos
         {
             m_pSerializer->endElementNS( XML_w, XML_r );
         }
-    }
 }
 
 /// Writes properties for run that is used to separate field implementation.
@@ -2190,6 +2203,7 @@ void DocxAttributeOutput::EndField_Impl( const SwTextNode* pNode, sal_Int32 nPos
     if ( rInfos.pField )
     {
         CmdField_Impl( pNode, nPos, rInfos, true );
+        CmdEndField_Impl( pNode, nPos, true );
     }
 
     // Write the bookmark start if any
@@ -7356,6 +7370,7 @@ void DocxAttributeOutput::WriteField_Impl( const SwField* pField, ww::eField eTy
     infos.sCmd = rFieldCmd;
     infos.eType = eType;
     infos.bClose = bool(FieldFlags::Close & nMode);
+    infos.bSep = bool(FieldFlags::CmdEnd & nMode);
     infos.bOpen = bool(FieldFlags::Start & nMode);
     m_Fields.push_back( infos );
 
diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx
index df8e10724987..d0f92c1f6fc6 100644
--- a/sw/source/filter/ww8/docxattributeoutput.hxx
+++ b/sw/source/filter/ww8/docxattributeoutput.hxx
@@ -58,9 +58,13 @@ struct FieldInfos
     const ::sw::mark::IFieldmark* pFieldmark;
     ww::eField  eType;
     bool        bOpen;
+    bool        bSep;
     bool        bClose;
     OUString    sCmd;
-    FieldInfos() : pFieldmark(nullptr), eType(ww::eUNKNOWN), bOpen(false), bClose(false){}
+    FieldInfos()
+        : pFieldmark(nullptr), eType(ww::eUNKNOWN)
+        , bOpen(false), bSep(false), bClose(false)
+    {}
 };
 
 enum DocxColBreakStatus
@@ -717,6 +721,7 @@ private:
     void StartField_Impl( const SwTextNode* pNode, sal_Int32 nPos, FieldInfos const & rInfos, bool bWriteRun = false );
     void DoWriteCmd( const OUString& rCmd );
     void CmdField_Impl( const SwTextNode* pNode, sal_Int32 nPos, FieldInfos const & rInfos, bool bWriteRun );
+    void CmdEndField_Impl( const SwTextNode* pNode, sal_Int32 nPos, bool bWriteRun );
     void EndField_Impl( const SwTextNode* pNode, sal_Int32 nPos, FieldInfos& rInfos );
     void DoWriteFieldRunProperties( const SwTextNode* pNode, sal_Int32 nPos, bool bWriteCombChars = false );
 
commit 4f174e66431628fa1343ec44d63cc3f02cc0bb0b
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Fri Oct 18 18:23:18 2019 +0200
Commit:     Michael Stahl <michael.stahl at cib.de>
CommitDate: Wed Oct 23 13:09:03 2019 +0200

    sw: RTF export: export fieldmarks
    
    There was some special code that was used only to export ruby
    attributes; generalise it a little.
    
    Change-Id: Iac5316b97e095fb3811404cad0568b9ab63a96f0
    Reviewed-on: https://gerrit.libreoffice.org/81085
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.stahl at cib.de>

diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx b/sw/source/filter/ww8/rtfattributeoutput.cxx
index 1fdbcd307541..078f9dc94dd6 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.cxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.cxx
@@ -532,7 +532,8 @@ void RtfAttributeOutput::StartRuby(const SwTextNode& rNode, sal_Int32 nPos,
 
 void RtfAttributeOutput::EndRuby(const SwTextNode& rNode, sal_Int32 nPos)
 {
-    m_rExport.OutputField(nullptr, ww::eEQ, ")", FieldFlags::End | FieldFlags::Close);
+    m_rExport.OutputField(nullptr, ww::eEQ, ")",
+                          FieldFlags::CmdEnd | FieldFlags::End | FieldFlags::Close);
     EndRun(&rNode, nPos);
 }
 
@@ -1585,7 +1586,7 @@ void RtfAttributeOutput::NumberingLevel(sal_uInt8 nLevel, sal_uInt16 nStart,
         m_rExport.Strm().WriteChar('}');
 }
 
-void RtfAttributeOutput::WriteField_Impl(const SwField* pField, ww::eField eType,
+void RtfAttributeOutput::WriteField_Impl(const SwField* const pField, ww::eField,
                                          const OUString& rFieldCmd, FieldFlags nMode)
 {
     // If there are no field instructions, don't export it as a field.
@@ -1607,21 +1608,25 @@ void RtfAttributeOutput::WriteField_Impl(const SwField* pField, ww::eField eType
         if (bHasInstructions)
             m_aRunText->append("}}");
     }
-    else if (eType == ww::eEQ)
+    else
     {
-        if (FieldFlags::Start & nMode)
+        if (nMode & FieldFlags::CmdStart)
         {
             m_aRunText->append("{" OOO_STRING_SVTOOLS_RTF_FIELD);
             m_aRunText->append("{" OOO_STRING_SVTOOLS_RTF_IGNORE OOO_STRING_SVTOOLS_RTF_FLDINST
-                               " ");
+                               // paragraph break closes group so open another one "inside" to
+                               " {"); // prevent leaving the field instruction
         }
         if (bHasInstructions)
             m_aRunText->append(
                 msfilter::rtfutil::OutString(rFieldCmd, m_rExport.GetCurrentEncoding()));
-        if (FieldFlags::End & nMode)
+        if (nMode & FieldFlags::CmdEnd)
         {
-            m_aRunText->append("}{" OOO_STRING_SVTOOLS_RTF_FLDRSLT " ");
-            m_aRunText->append("}}");
+            m_aRunText->append("}}{" OOO_STRING_SVTOOLS_RTF_FLDRSLT " {");
+        }
+        if (nMode & FieldFlags::Close)
+        {
+            m_aRunText->append("}}}");
         }
     }
 }


More information about the Libreoffice-commits mailing list