sw/inc/EnhancedPDFExportHelper.hxx              |    9 +++
 sw/source/core/text/EnhancedPDFExportHelper.cxx |   57 ++++++++++++------------
 2 files changed, 37 insertions(+), 29 deletions(-)

New commits:
commit a1fd984c7cd4d97c8b039c75e8340e431554ed26
Author: Ivan Timofeev <timofeev....@gmail.com>
Date:   Wed Jun 20 22:15:46 2012 +0400

    fdo#34093: fix error in calculation of page number of SwRect
    
    StringRangeEnumerator (i.e. user's input) contains page numbers in a 
different
    page range (it excludes empty pages). So:
    - first map page numbers to a common range, then compare
    - user's input can't contain empty pages, remove this check
    
    Change-Id: I4fce5215272fc90f39c9e05d3f3604734a8aebe3

diff --git a/sw/inc/EnhancedPDFExportHelper.hxx 
b/sw/inc/EnhancedPDFExportHelper.hxx
index 2020d13..a5a5210 100644
--- a/sw/inc/EnhancedPDFExportHelper.hxx
+++ b/sw/inc/EnhancedPDFExportHelper.hxx
@@ -216,7 +216,14 @@ class SwEnhancedPDFExportHelper
     OutputDevice& mrOut;
 
     StringRangeEnumerator* mpRangeEnum;
-    std::vector<bool> maIsPageEmpty;
+    /** The problem is that numbers in StringRangeEnumerator aren't accordant
+     * to real page numbers if mbSkipEmptyPages is true, because in this case
+     * empty pages are excluded from a page range and numbers in
+     * StringRangeEnumerator are shifted.
+     *
+     * maPageNumberMap[real_page_number] is either a corresponding page number
+     * in a page range without empty pages, or -1 if this page is empty. */
+    std::vector< sal_Int32 > maPageNumberMap;
 
     bool mbSkipEmptyPages;
     bool mbEditEngineOnly;
diff --git a/sw/source/core/text/EnhancedPDFExportHelper.cxx 
b/sw/source/core/text/EnhancedPDFExportHelper.cxx
index 7ed062d..ea19d26 100644
--- a/sw/source/core/text/EnhancedPDFExportHelper.cxx
+++ b/sw/source/core/text/EnhancedPDFExportHelper.cxx
@@ -1521,12 +1521,17 @@ SwEnhancedPDFExportHelper::SwEnhancedPDFExportHelper( 
SwEditShell& rSh,
 
     if ( mbSkipEmptyPages )
     {
-        maIsPageEmpty.resize( mrSh.GetPageCount() );
+        maPageNumberMap.resize( mrSh.GetPageCount() );
         const SwPageFrm* pCurrPage =
             static_cast<const SwPageFrm*>( mrSh.GetLayout()->Lower() );
-        for ( size_t i = 0, n = maIsPageEmpty.size(); i < n && pCurrPage; ++i )
+        sal_Int32 nPageNumber = 0;
+        for ( size_t i = 0, n = maPageNumberMap.size(); i < n && pCurrPage; 
++i )
         {
-            maIsPageEmpty[i] = pCurrPage->IsEmptyPage();
+            if ( pCurrPage->IsEmptyPage() )
+                maPageNumberMap[i] = -1;
+            else
+                maPageNumberMap[i] = nPageNumber++;
+
             pCurrPage = static_cast<const SwPageFrm*>( pCurrPage->GetNext() );
         }
     }
@@ -2148,7 +2153,7 @@ void SwEnhancedPDFExportHelper::EnhancedPDFExport()
 sal_Int32 SwEnhancedPDFExportHelper::CalcOutputPageNum( const SwRect& rRect ) 
const
 {
     // Document page number.
-    const sal_Int32 nPageNumOfRect = mrSh.GetPageNumAndSetOffsetForPDF( mrOut, 
rRect );
+    sal_Int32 nPageNumOfRect = mrSh.GetPageNumAndSetOffsetForPDF( mrOut, rRect 
);
     if ( nPageNumOfRect < 0 )
         return -1;
 
@@ -2156,6 +2161,10 @@ sal_Int32 SwEnhancedPDFExportHelper::CalcOutputPageNum( 
const SwRect& rRect ) co
     sal_Int32 nRet = -1;
     if ( mpRangeEnum )
     {
+        if ( mbSkipEmptyPages )
+            // Map the page number to the range without empty pages.
+            nPageNumOfRect = maPageNumberMap[ nPageNumOfRect ];
+
         if ( mpRangeEnum->hasValue( nPageNumOfRect ) )
         {
             sal_Int32 nOutputPageNum = 0;
@@ -2163,18 +2172,12 @@ sal_Int32 SwEnhancedPDFExportHelper::CalcOutputPageNum( 
const SwRect& rRect ) co
             StringRangeEnumerator::Iterator aEnd  = mpRangeEnum->end();
             for ( ; aIter != aEnd; ++aIter )
             {
-                bool bSkipThisPage = mbSkipEmptyPages &&
-                    static_cast<size_t>( *aIter ) < maIsPageEmpty.size() &&
-                    maIsPageEmpty[*aIter];
-                if ( !bSkipThisPage )
+                if ( *aIter == nPageNumOfRect )
                 {
-                    if ( *aIter == nPageNumOfRect )
-                    {
-                        nRet = nOutputPageNum;
-                        break;
-                    }
-                    ++nOutputPageNum;
+                    nRet = nOutputPageNum;
+                    break;
                 }
+                ++nOutputPageNum;
             }
         }
     }
@@ -2183,9 +2186,9 @@ sal_Int32 SwEnhancedPDFExportHelper::CalcOutputPageNum( 
const SwRect& rRect ) co
         if ( mbSkipEmptyPages )
         {
             sal_Int32 nOutputPageNum = 0;
-            for ( size_t i = 0; i < maIsPageEmpty.size(); ++i )
+            for ( size_t i = 0; i < maPageNumberMap.size(); ++i )
             {
-                if ( !maIsPageEmpty[i] )
+                if ( maPageNumberMap[i] >= 0 ) // is not empty?
                 {
                     if ( i == static_cast<size_t>( nPageNumOfRect ) )
                     {
@@ -2216,13 +2219,17 @@ void SwEnhancedPDFExportHelper::CalcOutputPageNums( 
const SwRect& rRect,
     rPageNums.clear();
 
     // Document page number.
-    const sal_Int32 nPageNumOfRect = mrSh.GetPageNumAndSetOffsetForPDF( mrOut, 
rRect );
+    sal_Int32 nPageNumOfRect = mrSh.GetPageNumAndSetOffsetForPDF( mrOut, rRect 
);
     if ( nPageNumOfRect < 0 )
         return;
 
     // What will be the page numbers of page nPageNumOfRect in the output pdf?
     if ( mpRangeEnum )
     {
+        if ( mbSkipEmptyPages )
+            // Map the page number to the range without empty pages.
+            nPageNumOfRect = maPageNumberMap[ nPageNumOfRect ];
+
         if ( mpRangeEnum->hasValue( nPageNumOfRect ) )
         {
             sal_Int32 nOutputPageNum = 0;
@@ -2230,15 +2237,9 @@ void SwEnhancedPDFExportHelper::CalcOutputPageNums( 
const SwRect& rRect,
             StringRangeEnumerator::Iterator aEnd  = mpRangeEnum->end();
             for ( ; aIter != aEnd; ++aIter )
             {
-                bool bSkipThisPage = mbSkipEmptyPages &&
-                    static_cast<size_t>( *aIter ) < maIsPageEmpty.size() &&
-                    maIsPageEmpty[*aIter];
-                if ( !bSkipThisPage )
-                {
-                    if ( *aIter == nPageNumOfRect )
-                        rPageNums.push_back( nOutputPageNum );
-                    ++nOutputPageNum;
-                }
+                if ( *aIter == nPageNumOfRect )
+                    rPageNums.push_back( nOutputPageNum );
+                ++nOutputPageNum;
             }
         }
     }
@@ -2247,9 +2248,9 @@ void SwEnhancedPDFExportHelper::CalcOutputPageNums( const 
SwRect& rRect,
         if ( mbSkipEmptyPages )
         {
             sal_Int32 nOutputPageNum = 0;
-            for ( size_t i = 0; i < maIsPageEmpty.size(); ++i )
+            for ( size_t i = 0; i < maPageNumberMap.size(); ++i )
             {
-                if ( !maIsPageEmpty[i] )
+                if ( maPageNumberMap[i] >= 0 ) // is not empty?
                 {
                     if ( i == static_cast<size_t>( nPageNumOfRect ) )
                     {
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to