Split selected pages as a booklet (unimposition)
(self, _action, _option, _unknown)
| 556 | self.paste_as_layer([data[second_id]], destination, 'OVERLAY', (1, 0.5)) |
| 557 | |
| 558 | def split_booklet(self, _action, _option, _unknown): |
| 559 | """ Split selected pages as a booklet (unimposition) """ |
| 560 | |
| 561 | # The user requested that we unimpose some pages. |
| 562 | # The imposition process took linear pages and reordered 4 of them per sheet for printing, so that the sheet may be folded into a book/booklet. |
| 563 | # Here we're doing the opposite process, turning a booklet into a linear document... like so: |
| 564 | # |
| 565 | # .---. .---. |
| 566 | # | 1 | | 1 | |
| 567 | # '---' '---' |
| 568 | # .---. .---. |
| 569 | # | 2 | .-------. | 2 | |
| 570 | # '---' IMPOSITION | 4 | 1 | UNIMPOSITION '---' |
| 571 | # .---. ---------> '-------' -----------> .---. |
| 572 | # | 3 | .-------. | 3 | |
| 573 | # '---' | 2 | 3 | '---' |
| 574 | # .---. '-------' .---. |
| 575 | # | 4 | | 4 | |
| 576 | # '---' '---' |
| 577 | # |
| 578 | # Usually, the entire document will be unimposed. But maybe the user has reasons to unimpose only parts of the document, and anyway this function intends |
| 579 | # to operate on selection, so any contiguous selection of pages will be supported. |
| 580 | |
| 581 | # selection is a list of 1-tuples, not in order |
| 582 | selection = self.iconview.get_selected_items() |
| 583 | selected_page_numbers = sorted_selection_indices(selection) |
| 584 | |
| 585 | if not is_selection_contiguous(selected_page_numbers): |
| 586 | msg = _('The page selection is not contiguous. Cannot unimpose.') |
| 587 | self.error_message_dialog(msg) |
| 588 | return |
| 589 | |
| 590 | model = self.iconview.get_model() |
| 591 | ref_list = [Gtk.TreeRowReference.new(model, path) |
| 592 | for path in selection] |
| 593 | pages = [model.get_value(model.get_iter(ref.get_path()), 0) |
| 594 | for ref in ref_list] |
| 595 | |
| 596 | # Need uniform page size. |
| 597 | if not is_same_page_size(pages): |
| 598 | msg = _('All pages must have the same size.') |
| 599 | self.error_message_dialog(msg) |
| 600 | return |
| 601 | |
| 602 | # Simulate split window |
| 603 | horizontal = [[1, 100]] |
| 604 | vertical = [[1, 50], [2, 50]] |
| 605 | |
| 606 | leftcrops, topcrops = splitter._crops(vertical), splitter._crops(horizontal) |
| 607 | |
| 608 | self.set_unsaved(True) |
| 609 | self.undomanager.commit("split booklet") |
| 610 | with self.render_lock(): |
| 611 | # Determine the pages for unimposition... so for example if we have have pages 1 2 3 containing 1 3-2 4 content |
| 612 | # we only want to unimpose those selected middle pages with offset=1 and halves=2 for the number of halves |
| 613 | # produced from the selection, so we end up with 1 2 3 4 at the end of the process |
| 614 | offset = selected_page_numbers[0] |
| 615 | halves = len(selected_page_numbers) * 2 |
nothing calls this directly
no test coverage detected