Commits

Anonymous committed 4498249

swbookmarkfixes01: priliminary fix in rtf export

  • Participants
  • Parent commits 696a06e

Comments (0)

Files changed (1)

File sw/source/filter/ww8/rtfexport.cxx

     Strm() << '}';
 }
 
+namespace
+{
+    struct lcl_PageDescIndexer
+    {
+        ::std::map<const SwPageDesc*, sal_Int32> m_vIndexByPageDesc;
+        void operator()(SwPageDesc* pPageDesc)
+        {
+            m_vIndexByPageDesc[pPageDesc] = m_vIndexByPageDesc.size();
+        };
+        sal_Int32 GetIndexByPageDesc(const SwPageDesc* pPageDesc) const { return m_vIndexByPageDesc.find(pPageDesc)->second; };
+    };
+
+    struct lcl_PageDescWriter
+    {
+        lcl_PageDescWriter(RtfExport* const pExport, ::sw::pagedesc::IDocumentPageDescAccess* pPageDescAccess)
+            : m_pExport(pExport)
+            , m_aPageDescIndexer(pPageDescAccess->ForEach(lcl_PageDescIndexer()))
+        {};
+        RtfExport* const m_pExport;
+        lcl_PageDescIndexer m_aPageDescIndexer;
+        void operator()(SwPageDesc* pPageDesc)
+        {
+            m_pExport->Strm() << RtfExport::sNewLine << '{' << OOO_STRING_SVTOOLS_RTF_PGDSC;
+            m_pExport->OutULong( m_aPageDescIndexer.GetIndexByPageDesc(pPageDesc) ) << OOO_STRING_SVTOOLS_RTF_PGDSCUSE;
+            m_pExport->OutULong( pPageDesc->ReadUseOn() );
+            m_pExport->OutPageDescription( *pPageDesc, FALSE, FALSE );
+            m_pExport->Strm() << OOO_STRING_SVTOOLS_RTF_PGDSCNXT;
+            m_pExport->OutULong( m_aPageDescIndexer.GetIndexByPageDesc(pPageDesc->GetFollow()) ) << ' ';
+            m_pExport->Strm() << m_pExport->OutString( pPageDesc->GetName(), m_pExport->eDefaultEncoding) << ";}";
+        };
+    };
+}
+
 void RtfExport::WritePageDescTable()
 {
     OSL_TRACE("%s", OSL_THIS_FUNC);
-
+    ::sw::pagedesc::IDocumentPageDescAccess* pPageDescAccess = pDoc->getIDocumentPageDescAccess();
+    if(!pPageDescAccess->GetPageDescCnt())
+        return;
     // Write page descriptions (page styles)
-    USHORT nSize = pDoc->GetPageDescCnt();
-    if( !nSize )
-        return;
-
     Strm() << sNewLine;        // a separator
     bOutPageDescs = TRUE;
     Strm() << '{' << OOO_STRING_SVTOOLS_RTF_IGNORE << OOO_STRING_SVTOOLS_RTF_PGDSCTBL;
-    for( USHORT n = 0; n < nSize; ++n )
-    {
-        const SwPageDesc& rPageDesc =
-            const_cast<const SwDoc*>(pDoc)->GetPageDesc( n );
-
-        Strm() << sNewLine << '{' << OOO_STRING_SVTOOLS_RTF_PGDSC;
-        OutULong( n ) << OOO_STRING_SVTOOLS_RTF_PGDSCUSE;
-        OutULong( rPageDesc.ReadUseOn() );
-
-        OutPageDescription( rPageDesc, FALSE, FALSE );
-
-        // search for the next page description
-        USHORT i = nSize;
-        while( i  )
-            if( rPageDesc.GetFollow() ==
-                    &const_cast<const SwDoc *>(pDoc)->GetPageDesc( --i ) )
-                break;
-        Strm() << OOO_STRING_SVTOOLS_RTF_PGDSCNXT;
-        OutULong( i ) << ' ';
-        Strm() << OutString( rPageDesc.GetName(), eDefaultEncoding) << ";}";
-    }
+    pPageDescAccess->ForEach(lcl_PageDescWriter(this, pPageDescAccess));
     Strm() << '}' << sNewLine;
     bOutPageDescs = FALSE;
 }
     Strm() << OOO_STRING_SVTOOLS_RTF_FORMSHADE;
 
     // size and empty margins of the page
-    if( pDoc->GetPageDescCnt() )
+    if( pDoc->getIDocumentPageDescAccess()->GetPageDescCnt() )
     {
+        lcl_PageDescIndexer aPageDescIndexer(pDoc->getIDocumentPageDescAccess()->ForEach(lcl_PageDescIndexer()));
         //JP 06.04.99: Bug 64361 - Seeking the first SwFmtPageDesc. If
         //				no set, the default is valid
         const SwFmtPageDesc* pSttPgDsc = 0;
                 pSttPgDsc = (SwFmtPageDesc*)&pSet->Get( RES_PAGEDESC );
                 if( !pSttPgDsc->GetPageDesc() )
                     pSttPgDsc = 0;
-                else if( pDoc->FindPageDescByName( pSttPgDsc->
-                                    GetPageDesc()->GetName(), &nPosInDoc ))
+                else
                 {
+                    nPosInDoc = aPageDescIndexer.GetIndexByPageDesc(pSttPgDsc->GetPageDesc());
                     Strm() << '{' << OOO_STRING_SVTOOLS_RTF_IGNORE << OOO_STRING_SVTOOLS_RTF_PGDSCNO;
                     OutULong( nPosInDoc ) << '}';
                 }
             }
         }
         const SwPageDesc& rPageDesc = pSttPgDsc ? *pSttPgDsc->GetPageDesc()
-            : const_cast<const SwDoc *>(pDoc)->GetPageDesc( 0 );
+            : *(const_cast<const SwDoc *>(pDoc)->getIDocumentPageDescAccess()->GetDefaultPageDesc());
         const SwFrmFmt &rFmtPage = rPageDesc.GetMaster();
 
         {