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

Vinaya Mandke vinaya.mandke at synerzip.com
Wed Feb 26 02:28:26 PST 2014


 sw/qa/extras/ooxmlexport/data/alphabeticalIndex_MultipleColumns.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport.cxx                             |   22 +++++++++
 sw/source/filter/ww8/docxattributeoutput.cxx                         |    6 ++
 sw/source/filter/ww8/docxattributeoutput.hxx                         |    1 
 sw/source/filter/ww8/docxexport.hxx                                  |    2 
 sw/source/filter/ww8/rtfexport.hxx                                   |    3 +
 sw/source/filter/ww8/wrtw8nds.cxx                                    |   10 +---
 sw/source/filter/ww8/wrtww8.hxx                                      |    5 ++
 sw/source/filter/ww8/ww8atr.cxx                                      |   24 ++++++++++
 writerfilter/source/dmapper/DomainMapper.cxx                         |    2 
 writerfilter/source/dmapper/DomainMapper_Impl.cxx                    |   14 +++++
 11 files changed, 80 insertions(+), 9 deletions(-)

New commits:
commit 263938c4a8789d881f8e736d317b6bcc09c3bce5
Author: Vinaya Mandke <vinaya.mandke at synerzip.com>
Date:   Thu Feb 13 20:02:53 2014 +0530

    fdo#73596 [DOCX] Multiple Columns in Index
    
    The number of columns in an Index is given by the "\c" switch.
    During export, added section breaks before and after the Index;
    this is to preserve the layout of the round tripped file in MS Office.
    
    Modified MSWordExportBase::NoPageBreakSection so that
    an incorrect "nextPage" section break is not exported.
    
    Conflicts:
    	sw/qa/extras/ooxmlexport/ooxmlexport.cxx
    Reviewed on:
    	https://gerrit.libreoffice.org/8047
    
    Change-Id: I364e19d6739c4c6a60e3c605044fc1fafd9147d3

diff --git a/sw/qa/extras/ooxmlexport/data/alphabeticalIndex_MultipleColumns.docx b/sw/qa/extras/ooxmlexport/data/alphabeticalIndex_MultipleColumns.docx
new file mode 100644
index 0000000..970166a
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/alphabeticalIndex_MultipleColumns.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index 73d3393..6826a4d 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -3661,6 +3661,28 @@ DECLARE_OOXMLEXPORT_TEST(testPageBreak,"fdo74566.docx")
     getRun(xParagraph4, 1, "Second Page First line after Page Break");
 }
 
+DECLARE_OOXMLEXPORT_TEST(testAlphabeticalIndex_MultipleColumns,"alphabeticalIndex_MultipleColumns.docx")
+{
+    // Bug :: fdo#73596
+    /*
+     * Index with multiple columns was not imported correctly and
+     * hence not exported correctly...
+     * The column count is given by the \c switch.
+     * If the column count is explicitly specified,
+     * MS Office adds section breaks before and after the Index.
+     */
+    xmlDocPtr pXmlDoc = parseExport("word/document.xml");
+        if (!pXmlDoc)
+            return;
+    xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc,"/w:document/w:body/w:p[3]/w:r[2]/w:instrText");
+    xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
+    OUString contents = OUString::createFromAscii((const char*)((pXmlNode->children[0]).content));
+    CPPUNIT_ASSERT( contents.match(" INDEX \\c \"4\"\\e \"") );
+    // check for section breaks after and before the Index Section
+    assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:pPr/w:sectPr/w:type","val","continuous");
+    assertXPath(pXmlDoc, "/w:document/w:body/w:p[9]/w:pPr/w:sectPr/w:type","val","continuous");
+}
+
 #endif
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 46258f9..77ee13e 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -271,6 +271,7 @@ void DocxAttributeOutput::StartParagraph( ww8::WW8TableNodeInfo::Pointer_t pText
     m_pSectionInfo.reset();
 
     m_bParagraphOpened = true;
+    m_bIsFirstParagraph = false;
 }
 
 void DocxAttributeOutput::EndParagraph( ww8::WW8TableNodeInfoInner::Pointer_t pTextNodeInfoInner )
@@ -3969,7 +3970,9 @@ void DocxAttributeOutput::SectionBreak( sal_uInt8 nC, const WW8_SepInfo* pSectio
         case msword::PageBreak:
             if ( pSectionInfo )
             {
-                if ( !m_bParagraphOpened )
+                // don't add section properties if this will be the first
+                // paragraph in the document
+                if ( !m_bParagraphOpened && !m_bIsFirstParagraph)
                 {
                     // Create a dummy paragraph if needed
                     m_pSerializer->startElementNS( XML_w, XML_p, FSEND );
@@ -6624,6 +6627,7 @@ DocxAttributeOutput::DocxAttributeOutput( DocxExport &rExport, FSHelperPtr pSeri
       m_nNextAnnotationMarkId( 0 ),
       m_pTableWrt( NULL ),
       m_bParagraphOpened( false ),
+      m_bIsFirstParagraph( true ),
       m_nColBreakStatus( COLBRK_NONE ),
       m_nTextFrameLevel( 0 ),
       m_closeHyperlinkInThisRun( false ),
diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx
index de98b3c..dd24e2f 100644
--- a/sw/source/filter/ww8/docxattributeoutput.hxx
+++ b/sw/source/filter/ww8/docxattributeoutput.hxx
@@ -745,6 +745,7 @@ private:
     SwWriteTable *m_pTableWrt;
 
     bool m_bParagraphOpened;
+    bool m_bIsFirstParagraph;
 
     // Remember that a column break has to be opened at the
     // beginning of the next paragraph
diff --git a/sw/source/filter/ww8/docxexport.hxx b/sw/source/filter/ww8/docxexport.hxx
index 6077966..4ce76e3 100644
--- a/sw/source/filter/ww8/docxexport.hxx
+++ b/sw/source/filter/ww8/docxexport.hxx
@@ -117,6 +117,8 @@ public:
 
     virtual bool FieldsQuoted() const { return true; }
 
+    virtual bool AddSectionBreaksForTOX() const { return true; }
+
     virtual bool ignoreAttributeForStyles( sal_uInt16 nWhich ) const;
 
     /// Guess the script (asian/western).
diff --git a/sw/source/filter/ww8/rtfexport.hxx b/sw/source/filter/ww8/rtfexport.hxx
index 21a4415..c23bff0 100644
--- a/sw/source/filter/ww8/rtfexport.hxx
+++ b/sw/source/filter/ww8/rtfexport.hxx
@@ -65,6 +65,9 @@ public:
     virtual bool SupportsOneColumnBreak() const { return false; }
 
     virtual bool FieldsQuoted() const { return true; }
+
+    virtual bool AddSectionBreaksForTOX() const { return false; }
+
     /// Guess the script (asian/western).
     virtual bool CollapseScriptsforWordOk( sal_uInt16 nScript, sal_uInt16 nWhich );
 
diff --git a/sw/source/filter/ww8/wrtw8nds.cxx b/sw/source/filter/ww8/wrtw8nds.cxx
index 29da65d..90d943e 100644
--- a/sw/source/filter/ww8/wrtw8nds.cxx
+++ b/sw/source/filter/ww8/wrtw8nds.cxx
@@ -1910,7 +1910,6 @@ void MSWordExportBase::OutputTextNode( const SwTxtNode& rNode )
             bLastCR = true;
     }
 
-    AttrOutput().StartParagraph( pTextNodeInfo );
 
     bool bFlyInTable = mpParentFrame && IsInTable();
 
@@ -1935,6 +1934,8 @@ void MSWordExportBase::OutputTextNode( const SwTxtNode& rNode )
         }
     }
 
+    AttrOutput().StartParagraph( pTextNodeInfo );
+
     const SwSection* pTOXSect = 0;
     if( bInWriteTOX )
     {
@@ -2606,15 +2607,10 @@ bool MSWordExportBase::NoPageBreakSection( const SfxItemSet* pSet )
     const SfxPoolItem* pI;
     if( pSet)
     {
-        bool bNoPageBreak = false;
+        bool bNoPageBreak = true;
         if ( SFX_ITEM_ON != pSet->GetItemState(RES_PAGEDESC, true, &pI)
             || 0 == ((SwFmtPageDesc*)pI)->GetPageDesc() )
         {
-            bNoPageBreak = true;
-        }
-
-        if (bNoPageBreak)
-        {
             if (SFX_ITEM_ON != pSet->GetItemState(RES_BREAK, true, &pI))
                 bNoPageBreak = true;
             else
diff --git a/sw/source/filter/ww8/wrtww8.hxx b/sw/source/filter/ww8/wrtww8.hxx
index fb63531..0718086 100644
--- a/sw/source/filter/ww8/wrtww8.hxx
+++ b/sw/source/filter/ww8/wrtww8.hxx
@@ -639,6 +639,9 @@ public:
     /// Determines if the import filter already quoted fields or not.
     virtual bool FieldsQuoted() const = 0;
 
+    /// Determines the Section Breaks are to be added for TOX Section
+    virtual bool AddSectionBreaksForTOX() const = 0;
+
     /// Used to filter out attributes that can be e.g. written to .doc but not to .docx
     virtual bool ignoreAttributeForStyles( sal_uInt16 /*nWhich*/ ) const { return false; }
 
@@ -965,6 +968,8 @@ public:
     virtual bool SupportsOneColumnBreak() const { return false; }
 
     virtual bool FieldsQuoted() const { return false; }
+
+    virtual bool AddSectionBreaksForTOX() const { return false; }
 private:
     /// Format-dependent part of the actual export.
     virtual void ExportDocument_Impl();
diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx
index 7178b96..db3270c 100644
--- a/sw/source/filter/ww8/ww8atr.cxx
+++ b/sw/source/filter/ww8/ww8atr.cxx
@@ -2058,9 +2058,26 @@ void AttributeOutputBase::StartTOX( const SwSection& rSect )
             switch (pTOX->GetType())
             {
             case TOX_INDEX:
+
+                // Add a continuous section break
+                if( GetExport().AddSectionBreaksForTOX() )
+                {
+                    sal_uLong nRstLnNum = 0;
+                    WW8_SepInfo rInfo( &GetExport( ).pDoc->GetPageDesc( 0 ), rSect.GetParent()->GetFmt() , nRstLnNum );
+                    GetExport( ).AttrOutput().SectionBreak( msword::PageBreak, &rInfo );
+                }
+
                 eCode = ww::eINDEX;
                 sStr = FieldString(eCode);
 
+                {
+                    const SwFmtCol& rCol = (const SwFmtCol&)( rSect.GetFmt()->GetFmtAttr( RES_COL ) );
+                    const SwColumns& rColumns = rCol.GetColumns();
+                    sal_Int32 nCol = rColumns.size();
+                    sStr += "\\c \"" + OUString::number( nCol ) + "\"";
+                }
+
+
                 if (pTOX->GetTOXForm().IsCommaSeparated())
                     sStr += "\\r ";
 
@@ -2351,6 +2368,13 @@ void AttributeOutputBase::EndTOX( const SwSection& rSect,bool bCareEnd )
     {
         ww::eField eCode = TOX_INDEX == pTOX->GetType() ? ww::eINDEX : ww::eTOC;
         GetExport( ).OutputField( 0, eCode, OUString(), WRITEFIELD_CLOSE );
+
+        if ( pTOX->GetType() == TOX_INDEX && GetExport().AddSectionBreaksForTOX() )
+        {
+            sal_uLong nRstLnNum = 0;
+            WW8_SepInfo rInfo( &GetExport( ).pDoc->GetPageDesc( 0 ), rSect.GetFmt() , nRstLnNum );
+            GetExport( ).AttrOutput().SectionBreak( msword::PageBreak, &rInfo );
+        }
     }
     GetExport( ).bInWriteTOX = false;
     if (bCareEnd)
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index cc4eec7..c4e3a9f 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -1936,7 +1936,7 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, PropertyMapPtr rContext, SprmType
 
             SectionColumnHandlerPtr pSectHdl( new SectionColumnHandler );
             pProperties->resolve(*pSectHdl);
-            if(pSectionContext)
+            if(pSectionContext && !m_pImpl->isInIndexContext())
             {
                 if( pSectHdl->IsEqualWidth() )
                 {
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index b66b7f3..0d98781 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -57,6 +57,7 @@
 #include <com/sun/star/awt/XControlModel.hpp>
 #include <com/sun/star/drawing/XControlShape.hpp>
 #include <com/sun/star/text/ControlCharacter.hpp>
+#include <com/sun/star/text/XTextColumns.hpp>
 #include <oox/mathml/import.hxx>
 
 #ifdef DEBUG_DOMAINMAPPER
@@ -2847,6 +2848,19 @@ void DomainMapper_Impl::handleIndex
 
     uno::Reference< text::XTextContent > xToInsert( xTOC, uno::UNO_QUERY );
     appendTextContent(xToInsert, uno::Sequence< beans::PropertyValue >() );
+
+    OUString sValue;
+    if( lcl_FindInCommand( pContext->GetCommand(), 'c', sValue ))
+    {
+        sValue = sValue.replaceAll("\"", "");
+        uno::Reference<text::XTextColumns> xTextColumns;
+        xTOC->getPropertyValue(rPropNameSupplier.GetName( PROP_TEXT_COLUMNS )) >>= xTextColumns;
+        if (xTextColumns.is())
+        {
+            xTextColumns->setColumnCount( sValue.toInt32() );
+            xTOC->setPropertyValue( rPropNameSupplier.GetName( PROP_TEXT_COLUMNS ), uno::makeAny( xTextColumns ) );
+        }
+    }
 }
 
 /*-------------------------------------------------------------------------


More information about the Libreoffice-commits mailing list