[Libreoffice-commits] .: Branch 'libreoffice-3-6' - sw/inc sw/source
Ivan Timofeev
ivantimofeev at kemper.freedesktop.org
Thu Jun 21 01:20:55 PDT 2012
sw/inc/EnhancedPDFExportHelper.hxx | 9 +++
sw/source/core/text/EnhancedPDFExportHelper.cxx | 57 ++++++++++++------------
2 files changed, 37 insertions(+), 29 deletions(-)
New commits:
commit 9b6cab988b4dd7be88573aab99010aaac657f78f
Author: Ivan Timofeev <timofeev.i.s at 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
(cherry picked from commit db053e48d2ca17e1256eb12500f075488483603b)
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 ff70ebc..1427b76 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 ) )
{
More information about the Libreoffice-commits
mailing list