summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorEilidh McAdam <eilidh.mcadam@itomig.de>2015-09-08 19:01:19 +0100
committerJan-Marek Glogowski <glogow@fbihome.de>2016-01-22 14:22:12 +0000
commit3c1a343f6936f1dcefdf79a677f8c26ce29676e6 (patch)
tree1e8a21c764ec489381d6d9c63dacba12e029cbe9 /sw
parentdfbc2f37207f11a3bafb2c5ce0dea4fcc137e527 (diff)
tdf#89708 Adjust print page range for unprinted blank pages
Depending on whether automatically inserted blank pages are to be printed or not, the range of pages to print is expressed differently to the pages displayed in the preview in the Print dialog - i.e. the page range includes blank pages, whereas the preview doesn't (if blank pages are not to be printed). This patch adapts the range so that if blank pages are ignored upon printing, the range can be expressed across printable pages only, same as the Print dialog preview. An example is a merged document of several records into a single page letter or document - blanks are automatically put in between documents but usually aren't displayed/printed. Previously, printing page 2 would print the blank page between the 1st and 2nd merged document. After this change, printing page 2 will print the 2nd merged document instead. The "Pages" (print range) text box in the Print dialog defaults to the current page - this patch adjusts this when blanks are not to be printed so that it is expressed as the current page minus any blanks since the start of the document. Change-Id: Ic1d4d374a82c6f921bb41a97130838757c6b74b1 Reviewed-on: https://gerrit.libreoffice.org/18420 Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de> Tested-by: Jan-Marek Glogowski <glogow@fbihome.de>
Diffstat (limited to 'sw')
-rw-r--r--sw/source/core/doc/doc.cxx47
-rw-r--r--sw/source/uibase/uno/unotxdoc.cxx15
2 files changed, 61 insertions, 1 deletions
diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx
index 644588e39f30..0022f2fe35ae 100644
--- a/sw/source/core/doc/doc.cxx
+++ b/sw/source/core/doc/doc.cxx
@@ -724,9 +724,54 @@ void SwDoc::CalculatePagesForPrinting(
// get vector of pages to print according to PageRange and valid pages set from above
// (result may be an empty vector, for example if the range string is not correct)
- StringRangeEnumerator::getRangesFromString(
+ // If excluding empty pages, allow range to specify range of printable pages
+ if (bPrintEmptyPages || nContent == 0)
+ {
+ // Use range enumerator directly
+ StringRangeEnumerator::getRangesFromString(
aPageRange, rData.GetPagesToPrint(),
1, nDocPageCount, 0, &rData.GetValidPagesSet() );
+ }
+ else // not printing blanks and not printing all
+ {
+ // Use range enumerator to adjust for empty pages - numbers in range are
+ // essentially indexes into the valid page number set
+ StringRangeEnumerator aEnum( aPageRange, 1, nDocPageCount, 0);
+ rData.GetPagesToPrint().clear();
+ rData.GetPagesToPrint().reserve(static_cast<size_t>(aEnum.size()));
+
+ std::set<sal_Int32>::iterator valIt = rData.GetValidPagesSet().begin();
+ sal_Int32 lastRangeValue = 1;
+ for (StringRangeEnumerator::Iterator it = aEnum.begin(); it != aEnum.end(); ++it)
+ {
+ // Move valid page set iterator forward/back by diff between current
+ // and previous numbers expressed in range
+ if ((*it) - lastRangeValue > 0)
+ {
+ // Fast-forward
+ for (sal_Int32 i = 0;
+ i < (*it) - lastRangeValue && valIt != rData.GetValidPagesSet().end();
+ ++i, ++valIt)
+ ;
+ }
+ else if (lastRangeValue - (*it) > 0)
+ {
+ // Rewind
+ for (sal_Int32 i = 0;
+ i < lastRangeValue - (*it) && valIt != rData.GetValidPagesSet().begin();
+ ++i, --valIt)
+ ;
+ }
+
+ // Range encompasses more values than are listed as valid
+ if (valIt == rData.GetValidPagesSet().end())
+ break;
+
+ rData.GetPagesToPrint().push_back(*valIt);
+
+ lastRangeValue = *it;
+ }
+ }
}
void SwDoc::UpdatePagesForPrintingWithPostItData(
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index 2a7d9d29a6f6..4a386fc8678f 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -38,6 +38,8 @@
#include <viewsh.hxx>
#include <pvprtdat.hxx>
#include <printdata.hxx>
+#include <pagefrm.hxx>
+#include <rootfrm.hxx>
#include <svl/stritem.hxx>
#include <unotxdoc.hxx>
#include <svl/numuno.hxx>
@@ -200,6 +202,19 @@ static SwPrintUIOptions * lcl_GetPrintUIOptions(
if (pPreview)
nCurrentPage = pPreview->GetSelectedPage();
}
+
+ // If blanks are skipped, account for them in initial page range value
+ if (!rPrintData.IsPrintEmptyPages())
+ {
+ sal_uInt16 nMax = nCurrentPage;
+ SwPageFrame *pPage = dynamic_cast<SwPageFrame*>(pSh->GetLayout()->Lower());
+ for ( ; nMax-- > 0; )
+ {
+ if (pPage->Frame().Height() == 0)
+ nCurrentPage--;
+ pPage = static_cast<SwPageFrame*>(pPage->GetNext());
+ }
+ }
return new SwPrintUIOptions( nCurrentPage, bWebDoc, bSwSrcView, bHasSelection, bHasPostIts, rPrintData );
}