diff options
author | Ivan Timofeev <timofeev.i.s@gmail.com> | 2012-06-20 22:15:46 +0400 |
---|---|---|
committer | Ivan Timofeev <timofeev.i.s@gmail.com> | 2012-06-21 11:18:05 +0400 |
commit | db053e48d2ca17e1256eb12500f075488483603b (patch) | |
tree | 1aad46a74a20c6db4e4b00a3bb3975d87ad778fb /sw | |
parent | 5f690158d1468d9eaec8cdc648b795487b0dcd89 (diff) |
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
Diffstat (limited to 'sw')
-rw-r--r-- | sw/inc/EnhancedPDFExportHelper.hxx | 9 | ||||
-rw-r--r-- | sw/source/core/text/EnhancedPDFExportHelper.cxx | 57 |
2 files changed, 37 insertions, 29 deletions
diff --git a/sw/inc/EnhancedPDFExportHelper.hxx b/sw/inc/EnhancedPDFExportHelper.hxx index 2020d139ce88..a5a5210b373c 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 5cbc4310144f..6a4210d7d9a6 100644 --- a/sw/source/core/text/EnhancedPDFExportHelper.cxx +++ b/sw/source/core/text/EnhancedPDFExportHelper.cxx @@ -1523,12 +1523,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() ); } } @@ -2150,7 +2155,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; @@ -2158,6 +2163,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; @@ -2165,18 +2174,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; } } } @@ -2185,9 +2188,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 ) ) { @@ -2218,13 +2221,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; @@ -2232,15 +2239,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; } } } @@ -2249,9 +2250,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 ) ) { |