Skip to content

Commit

Permalink
Implemented page ranges properly instead of treating them as lists of…
Browse files Browse the repository at this point in the history
… pages. This makes merging 10 faster.
  • Loading branch information
strichter committed Jan 8, 2017
1 parent b40dfd1 commit 62f853f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/z3c/rml/attr.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class IntegerSequence(Sequence):
def fromUnicode(self, ustr):
ustr = ustr.strip()
pieces = self.splitre.split(ustr)
numbers = set([])
numbers = []
for piece in pieces:
# Ignore empty pieces.
if not piece:
Expand All @@ -220,10 +220,10 @@ def fromUnicode(self, ustr):
if '-' in piece:
start, end = piece.split('-')
# Make range lower and upper bound inclusive.
numbers.update(range(int(start), int(end)+1))
numbers.append((int(start), int(end)+1))
continue
# The piece is just a number
numbers.add(int(piece))
numbers.append((int(piece), int(piece)+1))
return list(numbers)

class Choice(BaseChoice):
Expand Down
14 changes: 6 additions & 8 deletions src/z3c/rml/pdfinclude.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,19 @@ def split(self, availWidth, availheight):
pages = self.pages
if not pages:
pdf = PyPDF2.PdfFileReader(self.pdf_file, strict=STRICT)
num_pages = pdf.getNumPages()
pages = range(num_pages)
else:
num_pages = len(pages)
pages = [(1, pdf.getNumPages()+1)]

num_pages = sum(pr[1]-pr[0] for pr in pages)

start_page = self.canv.getPageNumber()
self.proc.operations.append(
(start_page, self.pdf_file, self.pages, num_pages))

result = []
(start_page, self.pdf_file, pages, num_pages))

# Insert blank pages instead of pdf for now, to correctly number the
# pages. We will replace these blank pages with included PDF in
# ConcatenationPostProcessor.
for i in pages:
result = []
for i in range(num_pages):
# Add empty spacer so platypus don't complain about too many empty
# pages
result.append(flowables.Spacer(0, 0))
Expand Down

0 comments on commit 62f853f

Please sign in to comment.