[Libreoffice-commits] .: 4 commits - sw/source

Lubos Lunak llunak at kemper.freedesktop.org
Tue Apr 19 05:16:56 PDT 2011


 sw/source/core/doc/poolfmt.cxx      |    8 +++++++
 sw/source/filter/ww8/docxexport.cxx |   39 ++++++++++++++++++++++++++++++++++++
 sw/source/filter/ww8/docxexport.hxx |   16 ++++++++++++++
 sw/source/filter/ww8/wrtw8sty.cxx   |   36 +++++++++++++++++++++++----------
 4 files changed, 88 insertions(+), 11 deletions(-)

New commits:
commit 52ccb593ef31b68baca971a2f51c9bde2ceb5cc8
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Mon Apr 18 18:44:36 2011 +0200

    make left/right page style be followed by the other one
    
    so that the document is automatically set to alternating left/right pages

diff --git a/sw/source/core/doc/poolfmt.cxx b/sw/source/core/doc/poolfmt.cxx
index f2834e3..b6b13ec 100644
--- a/sw/source/core/doc/poolfmt.cxx
+++ b/sw/source/core/doc/poolfmt.cxx
@@ -1520,7 +1520,12 @@ SwPageDesc* SwDoc::GetPageDescFromPool( sal_uInt16 nId, bool bRegardLanguage )
             aSet.Put( aUL );
             bSetLeft = sal_False;
             if( pNewPgDsc )
+            {
                 pNewPgDsc->SetUseOn( nsUseOnPage::PD_LEFT );
+                // this relies on GetPageDescFromPool() not going into infinite recursion
+                // (by this point RES_POOLPAGE_LEFT will not reach this place again)
+                pNewPgDsc->SetFollow( GetPageDescFromPool( RES_POOLPAGE_RIGHT ));
+            }
         }
         break;
     case RES_POOLPAGE_RIGHT:				// Rechte Seite
@@ -1530,7 +1535,10 @@ SwPageDesc* SwDoc::GetPageDescFromPool( sal_uInt16 nId, bool bRegardLanguage )
             aSet.Put( aUL );
             bSetLeft = sal_False;
             if( pNewPgDsc )
+            {
                 pNewPgDsc->SetUseOn( nsUseOnPage::PD_RIGHT );
+                pNewPgDsc->SetFollow( GetPageDescFromPool( RES_POOLPAGE_LEFT ));
+            }
         }
         break;
 
commit e8f4184b846329c2e30cb62dd72a599a6940d00a
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Mon Apr 18 17:46:54 2011 +0200

    avoid first-page header/footer extending to all pages (bnc#654230)

diff --git a/sw/source/filter/ww8/wrtw8sty.cxx b/sw/source/filter/ww8/wrtw8sty.cxx
index 53c192a..0ca0160 100644
--- a/sw/source/filter/ww8/wrtw8sty.cxx
+++ b/sw/source/filter/ww8/wrtw8sty.cxx
@@ -1708,22 +1708,26 @@ void MSWordExportBase::SectionProperties( const WW8_SepInfo& rSepInfo, WW8_PdAtt
 
     if ( nBreakCode != 0 )
     {
-        MSWordSections::SetHeaderFlag( nHeadFootFlags, *pPdFmt, WW8_HEADER_ODD );
-        MSWordSections::SetFooterFlag( nHeadFootFlags, *pPdFmt, WW8_FOOTER_ODD );
-
-        if ( !pPd->IsHeaderShared() || bLeftRightPgChain )
-            MSWordSections::SetHeaderFlag( nHeadFootFlags, *pPdLeftFmt, WW8_HEADER_EVEN );
-
-        if ( !pPd->IsFooterShared() || bLeftRightPgChain )
-            MSWordSections::SetFooterFlag( nHeadFootFlags, *pPdLeftFmt, WW8_FOOTER_EVEN );
-
         if ( titlePage )
         {
             // es gibt eine ErsteSeite:
             MSWordSections::SetHeaderFlag( nHeadFootFlags, *pPdFirstPgFmt, WW8_HEADER_FIRST );
             MSWordSections::SetFooterFlag( nHeadFootFlags, *pPdFirstPgFmt, WW8_FOOTER_FIRST );
         }
+        // write other headers/footers only if it's not the first page - I'm not quite sure
+        // this is technically correct, but it avoids first-page headers/footers
+        // extending to all pages (bnc#654230)
+        if( pPdFmt != pPdFirstPgFmt )
+        {
+            MSWordSections::SetHeaderFlag( nHeadFootFlags, *pPdFmt, WW8_HEADER_ODD );
+            MSWordSections::SetFooterFlag( nHeadFootFlags, *pPdFmt, WW8_FOOTER_ODD );
+
+            if ( !pPd->IsHeaderShared() || bLeftRightPgChain )
+                MSWordSections::SetHeaderFlag( nHeadFootFlags, *pPdLeftFmt, WW8_HEADER_EVEN );
 
+            if ( !pPd->IsFooterShared() || bLeftRightPgChain )
+                MSWordSections::SetFooterFlag( nHeadFootFlags, *pPdLeftFmt, WW8_FOOTER_EVEN );
+        }
         AttrOutput().SectionWW6HeaderFooterFlags( nHeadFootFlags );
     }
 
commit 27649d66a33f7f033fd9b926430a20a7326f2cb0
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Mon Apr 18 17:05:04 2011 +0200

    a more reliable way to detect w:titlePg (bnc#654230)

diff --git a/sw/source/filter/ww8/wrtw8sty.cxx b/sw/source/filter/ww8/wrtw8sty.cxx
index 3a518c4..53c192a 100644
--- a/sw/source/filter/ww8/wrtw8sty.cxx
+++ b/sw/source/filter/ww8/wrtw8sty.cxx
@@ -1594,6 +1594,7 @@ void MSWordExportBase::SectionProperties( const WW8_SepInfo& rSepInfo, WW8_PdAtt
         }
     }
 
+    bool titlePage = false;
     if ( bOutPgDscSet )
     {
         // es ist ein Follow gesetzt und dieser zeigt nicht auf sich
@@ -1620,10 +1621,19 @@ void MSWordExportBase::SectionProperties( const WW8_SepInfo& rSepInfo, WW8_PdAtt
                 pPdFmt = &rFollowFmt;
 
                 // has different headers/footers for the title page
-                AttrOutput().SectionTitlePage();
+                titlePage = true;
             }
         }
 
+        // The code above tries to detect if this is first page headers/footers,
+        // but it doesn't work even for quite trivial testcases. As I don't actually
+        // understand that code, I'll keep it. The simple and (at least for me) reliable way
+        // to detect for first page seems to be just RES_POOLPAGE_FIRST.
+        if( pPd->GetPoolFmtId() == RES_POOLPAGE_FIRST )
+            titlePage = true;
+        if( titlePage )
+            AttrOutput().SectionTitlePage();
+
         const SfxItemSet* pOldI = pISet;
 
         AttrOutput().SectionPageBorders( pPdFmt, pPdFirstPgFmt );
@@ -1707,7 +1717,7 @@ void MSWordExportBase::SectionProperties( const WW8_SepInfo& rSepInfo, WW8_PdAtt
         if ( !pPd->IsFooterShared() || bLeftRightPgChain )
             MSWordSections::SetFooterFlag( nHeadFootFlags, *pPdLeftFmt, WW8_FOOTER_EVEN );
 
-        if ( pPdFmt != pPdFirstPgFmt )
+        if ( titlePage )
         {
             // es gibt eine ErsteSeite:
             MSWordSections::SetHeaderFlag( nHeadFootFlags, *pPdFirstPgFmt, WW8_HEADER_FIRST );
commit 7864643c7155835c28740ed3c8de2eea34fb6742
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Mon Apr 18 14:27:59 2011 +0200

    implement w:evenAndOddHeaders (and settings.xml too)

diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx
index 1ee4051..074a128 100644
--- a/sw/source/filter/ww8/docxexport.cxx
+++ b/sw/source/filter/ww8/docxexport.cxx
@@ -215,6 +215,9 @@ void DocxExport::WriteHeadersFooters( sal_uInt8 nHeadFootFlags,
     if ( nHeadFootFlags & nsHdFtFlags::WW8_FOOTER_FIRST )
         WriteHeaderFooter( rFirstPageFmt, false, "first" );
 
+    if ( nHeadFootFlags & ( nsHdFtFlags::WW8_FOOTER_EVEN | nsHdFtFlags::WW8_HEADER_EVEN ))
+        settings.evenAndOddHeaders = true;
+
 #if OSL_DEBUG_LEVEL > 1
     fprintf( stderr, "DocxExport::WriteHeadersFooters() - nBreakCode introduced, but ignored\n" );
 #endif
@@ -339,6 +342,8 @@ void DocxExport::ExportDocument_Impl()
 
     WriteFonts();
 
+    WriteSettings();
+
     delete pStyles, pStyles = NULL;
     delete m_pSections, m_pSections = NULL;
 }
@@ -642,6 +647,28 @@ void DocxExport::WriteProperties( )
     m_pFilter->exportDocumentProperties( xDocProps );
 }
 
+void DocxExport::WriteSettings()
+{
+    if( !settings.hasData())
+        return;
+    m_pFilter->addRelation( m_pDocumentFS->getOutputStream(),
+            S( "http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings" ),
+            S( "settings.xml" ) );
+
+    ::sax_fastparser::FSHelperPtr pFS = m_pFilter->openFragmentStreamWithSerializer(
+            S( "word/settings.xml" ),
+            S( "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml" ) );
+
+    pFS->startElementNS( XML_w, XML_settings,
+            FSNS( XML_xmlns, XML_w ), "http://schemas.openxmlformats.org/wordprocessingml/2006/main",
+            FSEND );
+
+    if( settings.evenAndOddHeaders )
+        pFS->singleElementNS( XML_w, XML_evenAndOddHeaders, FSEND );
+
+    pFS->endElementNS( XML_w, XML_settings );
+}
+
 VMLExport& DocxExport::VMLExporter()
 {
     return *m_pVMLExport;
@@ -726,4 +753,16 @@ DocxExport::~DocxExport()
     delete m_pDrawingML, m_pDrawingML = NULL;
 }
 
+DocxSettingsData::DocxSettingsData()
+: evenAndOddHeaders( false )
+{
+}
+
+bool DocxSettingsData::hasData() const
+{
+    if( evenAndOddHeaders )
+        return true;
+    return false;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ww8/docxexport.hxx b/sw/source/filter/ww8/docxexport.hxx
index 4838d55..ee84dcd 100644
--- a/sw/source/filter/ww8/docxexport.hxx
+++ b/sw/source/filter/ww8/docxexport.hxx
@@ -58,6 +58,14 @@ namespace com { namespace sun { namespace star {
     namespace frame { class XModel; }
 } } }
 
+/// Data to be written in the document settings part of the document
+struct DocxSettingsData
+{
+    DocxSettingsData();
+    bool hasData() const; /// returns true if there are any non-default settings (i.e. something to write)
+    bool evenAndOddHeaders;
+};
+
 /// The class that does all the actual DOCX export-related work.
 class DocxExport : public MSWordExportBase
 {
@@ -85,6 +93,8 @@ class DocxExport : public MSWordExportBase
     /// Exporter of the VML shapes.
     oox::vml::VMLExport *m_pVMLExport;
 
+    DocxSettingsData settings;
+
 public:
 
     DocxExportFilter& GetFilter() { return *m_pFilter; };
@@ -192,6 +202,9 @@ private:
     /// Write docProps/core.xml
     void WriteProperties();
 
+    /// Write word/settings.xml
+    void WriteSettings();
+
     /// All xml namespaces to be used at the top of any text .xml file (main doc, headers, footers,...)
     sax_fastparser::XFastAttributeListRef MainXmlNamespaces( sax_fastparser::FSHelperPtr serializer );
 
@@ -210,6 +223,9 @@ public:
     /// Reference to the VMLExport instance for the main document.
     oox::vml::VMLExport& VMLExporter();
 
+    /// Data to be exported in the settings part of the document
+    DocxSettingsData& settingsData();
+
 private:
     /// No copying.
     DocxExport( const DocxExport& );


More information about the Libreoffice-commits mailing list