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

Miklos Vajna vmiklos at collabora.co.uk
Fri Nov 15 08:02:09 PST 2013


 sw/qa/extras/ooxmlexport/data/para-auto-spacing.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport.cxx             |    6 ++
 sw/source/filter/ww8/docxattributeoutput.cxx         |   56 ++++++++++++++++---
 sw/source/filter/ww8/docxattributeoutput.hxx         |    4 +
 sw/source/filter/ww8/docxtablestyleexport.cxx        |   10 ++-
 writerfilter/source/dmapper/DomainMapper.cxx         |   33 ++++++++---
 writerfilter/source/dmapper/PropertyIds.cxx          |    2 
 writerfilter/source/dmapper/PropertyIds.hxx          |    2 
 writerfilter/source/dmapper/PropertyMap.hxx          |    1 
 9 files changed, 94 insertions(+), 20 deletions(-)

New commits:
commit 9db943c50519b2a36f3eb144fda7f08abe13bdb2
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Nov 15 16:55:31 2013 +0100

    DOCX export: fixes for para auto spacing roundtrip
    
    - m_bParaBeforeAutoSpacing / m_bParaBeforeAutoSpacing was never set to false
    - m_iParaBeforeSpacing / m_iParaAfterSpacing was uninitialized
    
    Change-Id: I5c8ebd8e4f4c151059916397bc45e0c0ebcf5040

diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 6bfc91d..70361fa 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -5656,6 +5656,7 @@ void DocxAttributeOutput::FormatULSpace( const SvxULSpaceItem& rULSpace )
             m_pParagraphSpacingAttrList->add( FSNS( XML_w, XML_before ),
                     OString::number( rULSpace.GetUpper() ) );
         }
+        m_bParaBeforeAutoSpacing = false;
         // check if after auto spacing was set during import and spacing we get from actual object is same
         // that we set in import. If yes just write afterAutoSpacing tag.
         if (m_bParaAfterAutoSpacing && m_iParaAfterSpacing == rULSpace.GetLower())
@@ -5668,6 +5669,7 @@ void DocxAttributeOutput::FormatULSpace( const SvxULSpaceItem& rULSpace )
             m_pParagraphSpacingAttrList->add( FSNS( XML_w, XML_after ),
                     OString::number( rULSpace.GetLower()) );
         }
+        m_bParaAfterAutoSpacing = false;
 
         if (rULSpace.GetContext())
             m_pSerializer->singleElementNS( XML_w, XML_contextualSpacing, FSEND );
@@ -6262,7 +6264,9 @@ DocxAttributeOutput::DocxAttributeOutput( DocxExport &rExport, FSHelperPtr pSeri
       m_bFrameBtLr(false),
       m_pTableStyleExport(new DocxTableStyleExport(rExport.pDoc, pSerializer)),
       m_bParaBeforeAutoSpacing(false),
-      m_bParaAfterAutoSpacing(false)
+      m_bParaAfterAutoSpacing(false),
+      m_iParaBeforeSpacing(0),
+      m_iParaAfterSpacing(0)
 {
 }
 
commit 68e538ea6d6b2308de7c9390116fa06cd8c02d18
Author: Nikhil Walvekar <nikhil.walvekar at synerzip.com>
Date:   Fri Nov 1 23:25:41 2013 +0530

    Resolved: Preservation of para before and after auto spacing.
    
    During import a flag and fixed value is stored in InteropGrabBag and
    during export we check for fixed value and value available in para spacing
    object. Write autospacing only if para spacing values are not modified during
    edit.
    
    Reviewed on:
    	https://gerrit.libreoffice.org/6575
    
    Change-Id: If34c5b61c3180b01e68dfe83862784c3d6f33981

diff --git a/sw/qa/extras/ooxmlexport/data/para-auto-spacing.docx b/sw/qa/extras/ooxmlexport/data/para-auto-spacing.docx
new file mode 100644
index 0000000..c7604bf
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/para-auto-spacing.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index 1bf422f..23fe7cd 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -1833,6 +1833,12 @@ DECLARE_OOXML_TEST(testFdo71646, "fdo71646.docx")
     CPPUNIT_ASSERT_EQUAL(text::WritingMode2::LR_TB, nLRDir);
 }
 
+DECLARE_OOXML_TEST(testParaAutoSpacing, "para-auto-spacing.docx")
+{
+    xmlDocPtr pXmlDoc = parseExport();
+    CPPUNIT_ASSERT(getXPath(pXmlDoc, "/w:document/w:body/w:p/w:pPr/w:spacing", "beforeAutospacing").match("1"));
+    CPPUNIT_ASSERT(getXPath(pXmlDoc, "/w:document/w:body/w:p/w:pPr/w:spacing", "afterAutospacing").match("1"));
+}
 #endif
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 9e41119..6bfc91d 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -5643,10 +5643,32 @@ void DocxAttributeOutput::FormatULSpace( const SvxULSpaceItem& rULSpace )
     {
         if ( !m_pParagraphSpacingAttrList )
             m_pParagraphSpacingAttrList = m_pSerializer->createAttrList();
-        m_pParagraphSpacingAttrList->add( FSNS( XML_w, XML_before ),
-                OString::number( rULSpace.GetUpper() ) );
-        m_pParagraphSpacingAttrList->add( FSNS( XML_w, XML_after ),
-                OString::number( rULSpace.GetLower() ) );
+        SAL_INFO("sw.ww8", "DocxAttributeOutput::FormatULSpace: setting spacing" << rULSpace.GetUpper() );
+        // check if before auto spacing was set during import and spacing we get from actual object is same
+        // that we set in import. If yes just write beforeAutoSpacing tag.
+        if (m_bParaBeforeAutoSpacing && m_iParaBeforeSpacing == rULSpace.GetUpper())
+        {
+            m_pParagraphSpacingAttrList->add( FSNS( XML_w, XML_beforeAutospacing ),
+                    "1" );
+        }
+        else
+        {
+            m_pParagraphSpacingAttrList->add( FSNS( XML_w, XML_before ),
+                    OString::number( rULSpace.GetUpper() ) );
+        }
+        // check if after auto spacing was set during import and spacing we get from actual object is same
+        // that we set in import. If yes just write afterAutoSpacing tag.
+        if (m_bParaAfterAutoSpacing && m_iParaAfterSpacing == rULSpace.GetLower())
+        {
+            m_pParagraphSpacingAttrList->add( FSNS( XML_w, XML_afterAutospacing ),
+                    "1" );
+        }
+        else
+        {
+            m_pParagraphSpacingAttrList->add( FSNS( XML_w, XML_after ),
+                    OString::number( rULSpace.GetLower()) );
+        }
+
         if (rULSpace.GetContext())
             m_pSerializer->singleElementNS( XML_w, XML_contextualSpacing, FSEND );
     }
@@ -6169,8 +6191,24 @@ void DocxAttributeOutput::ParaGrabBag(const SfxGrabBagItem& rItem)
     {
         if (i->first == "MirrorIndents")
             m_pSerializer->singleElementNS(XML_w, XML_mirrorIndents, FSEND);
+        else if (i->first == "ParaTopMarginBeforeAutoSpacing")
+        {
+            m_bParaBeforeAutoSpacing = true;
+            // get fixed value which was set during import
+            i->second >>= m_iParaBeforeSpacing;
+            m_iParaBeforeSpacing = MM100_TO_TWIP(m_iParaBeforeSpacing);
+            SAL_INFO("sw.ww8", "DocxAttributeOutput::ParaGrabBag: property =" << i->first << " : m_iParaBeforeSpacing= " << m_iParaBeforeSpacing);
+        }
+        else if (i->first == "ParaBottomMarginAfterAutoSpacing")
+        {
+            m_bParaAfterAutoSpacing = true;
+            // get fixed value which was set during import
+            i->second >>= m_iParaAfterSpacing;
+            m_iParaAfterSpacing = MM100_TO_TWIP(m_iParaAfterSpacing);
+            SAL_INFO("sw.ww8", "DocxAttributeOutput::ParaGrabBag: property =" << i->first << " : m_iParaBeforeSpacing= " << m_iParaAfterSpacing);
+        }
         else
-            SAL_INFO("sw.ww8", "DocxAttributeOutput::ParaGrabBag: unhandled grab bag property " << i->first);
+            SAL_INFO("sw.ww8", "DocxAttributeOutput::ParaGrabBag: unhandled grab bag property " << i->first );
     }
 }
 
@@ -6222,7 +6260,9 @@ DocxAttributeOutput::DocxAttributeOutput( DocxExport &rExport, FSHelperPtr pSeri
       m_nextFontId( 1 ),
       m_bBtLr(false),
       m_bFrameBtLr(false),
-      m_pTableStyleExport(new DocxTableStyleExport(rExport.pDoc, pSerializer))
+      m_pTableStyleExport(new DocxTableStyleExport(rExport.pDoc, pSerializer)),
+      m_bParaBeforeAutoSpacing(false),
+      m_bParaAfterAutoSpacing(false)
 {
 }
 
diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx
index 1c8239b..14b22b2 100644
--- a/sw/source/filter/ww8/docxattributeoutput.hxx
+++ b/sw/source/filter/ww8/docxattributeoutput.hxx
@@ -779,6 +779,10 @@ private:
     PageMargins m_pageMargins;
 
     boost::shared_ptr<DocxTableStyleExport> m_pTableStyleExport;
+    // flag to check if auto spacing was set in original file
+    bool m_bParaBeforeAutoSpacing,m_bParaAfterAutoSpacing;
+    // store hardcoded value which was set during import.
+    sal_Int32 m_iParaBeforeSpacing,m_iParaAfterSpacing;
 
 public:
     DocxAttributeOutput( DocxExport &rExport, ::sax_fastparser::FSHelperPtr pSerializer, oox::drawingml::DrawingML* pDrawingML );
diff --git a/sw/source/filter/ww8/docxtablestyleexport.cxx b/sw/source/filter/ww8/docxtablestyleexport.cxx
index 3fc7246..af96d5f 100644
--- a/sw/source/filter/ww8/docxtablestyleexport.cxx
+++ b/sw/source/filter/ww8/docxtablestyleexport.cxx
@@ -277,12 +277,14 @@ void DocxTableStyleExport::Impl::tableStylePSpacing(uno::Sequence<beans::Propert
             pAttributeList->add(FSNS(XML_w, XML_lineRule), OUStringToOString(rSpacing[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
         else if (rSpacing[i].Name == "beforeLines")
             pAttributeList->add(FSNS(XML_w, XML_beforeLines), OUStringToOString(rSpacing[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
-        else if (rSpacing[i].Name == "beforeAutospacing")
-            pAttributeList->add(FSNS(XML_w, XML_beforeAutospacing), OUStringToOString(rSpacing[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
+        else if (rSpacing[i].Name == "ParaTopMarginBeforeAutoSpacing")
+            // Auto spacing will be available in grab bag only if it was set to true
+            pAttributeList->add(FSNS(XML_w, XML_beforeAutospacing), "1");
         else if (rSpacing[i].Name == "afterLines")
             pAttributeList->add(FSNS(XML_w, XML_afterLines), OUStringToOString(rSpacing[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
-        else if (rSpacing[i].Name == "afterAutospacing")
-            pAttributeList->add(FSNS(XML_w, XML_afterAutospacing), OUStringToOString(rSpacing[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
+        else if (rSpacing[i].Name == "ParaBottomMarginAfterAutoSpacing")
+            // Auto spacing will be available in grab bag only if it was set to true
+            pAttributeList->add(FSNS(XML_w, XML_afterAutospacing), "1");
     }
     sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList);
     m_pSerializer->singleElementNS(XML_w, XML_spacing, xAttributeList);
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index 8a3f589..ae81ad5 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -176,7 +176,7 @@ void DomainMapper::lcl_attribute(Id nName, Value & val)
     OUString sStringValue = val.getString();
 
     SectionPropertyMap * pSectionContext = m_pImpl->GetSectionContext();
-
+    PropertyMap::iterator oldPropValue;
     if( nName >= NS_rtf::LN_WIDENT && nName <= NS_rtf::LN_LCBSTTBFUSSR )
         m_pImpl->GetFIB().SetData( nName, nIntValue );
     else
@@ -1188,18 +1188,33 @@ void DomainMapper::lcl_attribute(Id nName, Value & val)
         break;
         // See SwWW8ImplReader::GetParagraphAutoSpace() on why these are 100 and 280
         case NS_ooxml::LN_CT_Spacing_beforeAutospacing:
-            m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "beforeAutospacing", OUString::number(nIntValue));
+        {
+            sal_Int32 default_spacing = 100;
             if (!m_pImpl->GetSettingsTable()->GetDoNotUseHTMLParagraphAutoSpacing())
-                m_pImpl->GetTopContext()->Insert( PROP_PARA_TOP_MARGIN, uno::makeAny( ConversionHelper::convertTwipToMM100(280) ) );
-            else
-                m_pImpl->GetTopContext()->Insert( PROP_PARA_TOP_MARGIN, uno::makeAny( ConversionHelper::convertTwipToMM100(100) ) );
+            {
+                default_spacing = 280;
+            }
+            m_pImpl->GetTopContext()->Insert( PROP_PARA_TOP_MARGIN, uno::makeAny( ConversionHelper::convertTwipToMM100(default_spacing) ) );
+            if  (nIntValue) // If auto spacing is set, then only store set value in InteropGrabBag
+            {
+                m_pImpl->GetTopContext()->Insert( PROP_PARA_TOP_MARGIN_BEFORE_AUTO_SPACING, uno::makeAny( ConversionHelper::convertTwipToMM100(default_spacing) ),true,true );
+            }
+        }
         break;
         case NS_ooxml::LN_CT_Spacing_afterAutospacing:
-            m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "afterAutospacing", OUString::number(nIntValue));
+        {
+            sal_Int32 default_spacing = 100;
+
             if (!m_pImpl->GetSettingsTable()->GetDoNotUseHTMLParagraphAutoSpacing())
-                m_pImpl->GetTopContext()->Insert( PROP_PARA_BOTTOM_MARGIN, uno::makeAny( ConversionHelper::convertTwipToMM100(280) ) );
-            else
-                m_pImpl->GetTopContext()->Insert( PROP_PARA_BOTTOM_MARGIN, uno::makeAny( ConversionHelper::convertTwipToMM100(100) ) );
+            {
+                default_spacing = 280;
+            }
+            m_pImpl->GetTopContext()->Insert( PROP_PARA_BOTTOM_MARGIN, uno::makeAny( ConversionHelper::convertTwipToMM100(default_spacing) ) );
+            if  (nIntValue) // If auto spacing is set, then only store set value in InteropGrabBag
+            {
+                m_pImpl->GetTopContext()->Insert( PROP_PARA_BOTTOM_MARGIN_AFTER_AUTO_SPACING, uno::makeAny( ConversionHelper::convertTwipToMM100(default_spacing) ),true,true );
+            }
+        }
         break;
         case NS_ooxml::LN_CT_SmartTagRun_uri:
         case NS_ooxml::LN_CT_SmartTagRun_element:
diff --git a/writerfilter/source/dmapper/PropertyIds.cxx b/writerfilter/source/dmapper/PropertyIds.cxx
index 9cdd249..b284855 100644
--- a/writerfilter/source/dmapper/PropertyIds.cxx
+++ b/writerfilter/source/dmapper/PropertyIds.cxx
@@ -125,6 +125,8 @@ const OUString& PropertyNameSupplier::GetName( PropertyIds eId ) const
             case PROP_PARA_FIRST_LINE_INDENT:    sName = "ParaFirstLineIndent"; break;
             case PROP_PARA_KEEP_TOGETHER:       sName = "ParaKeepTogether"; break;
             case PROP_PARA_TOP_MARGIN:       sName = "ParaTopMargin"; break;
+            case PROP_PARA_TOP_MARGIN_BEFORE_AUTO_SPACING:       sName = "ParaTopMarginBeforeAutoSpacing"; break;
+            case PROP_PARA_BOTTOM_MARGIN_AFTER_AUTO_SPACING:       sName = "ParaBottomMarginAfterAutoSpacing"; break;
             case PROP_PARA_CONTEXT_MARGIN:       sName = "ParaContextMargin"; break;
             case PROP_PARA_BOTTOM_MARGIN:       sName = "ParaBottomMargin"; break;
             case PROP_PARA_IS_HYPHENATION:     sName = "ParaIsHyphenation"; break;
diff --git a/writerfilter/source/dmapper/PropertyIds.hxx b/writerfilter/source/dmapper/PropertyIds.hxx
index d6c25ff..ee5045d 100644
--- a/writerfilter/source/dmapper/PropertyIds.hxx
+++ b/writerfilter/source/dmapper/PropertyIds.hxx
@@ -313,6 +313,8 @@ enum PropertyIds
         ,PROP_SURROUND_TEXT_WRAP_SMALL
         ,PROP_PARA_SHADOW_FORMAT
         ,PROP_FOOTNOTE_LINE_RELATIVE_WIDTH
+        ,PROP_PARA_TOP_MARGIN_BEFORE_AUTO_SPACING
+        ,PROP_PARA_BOTTOM_MARGIN_AFTER_AUTO_SPACING
     };
 struct PropertyNameSupplier_Impl;
 class PropertyNameSupplier
diff --git a/writerfilter/source/dmapper/PropertyMap.hxx b/writerfilter/source/dmapper/PropertyMap.hxx
index 5086dfa..456a4809 100644
--- a/writerfilter/source/dmapper/PropertyMap.hxx
+++ b/writerfilter/source/dmapper/PropertyMap.hxx
@@ -111,7 +111,6 @@ public:
     void Insert( PropertyIds eId, const ::com::sun::star::uno::Any& rAny, bool bOverwrite = true, bool bGrabBag = false );
     void Insert( PropertyIds eId, const PropValue& rValue, bool bOverwrite = true );
     void InsertProps(const boost::shared_ptr<PropertyMap> pMap);
-
     const ::com::sun::star::uno::Reference< ::com::sun::star::text::XFootnote>&  GetFootnote() const;
     void SetFootnote( ::com::sun::star::uno::Reference< ::com::sun::star::text::XFootnote> xF ) { m_xFootnote = xF; }
 


More information about the Libreoffice-commits mailing list