From b32e0a3e27142898e87e13464154d4f9d8c5e96e Mon Sep 17 00:00:00 2001 From: LEdoian Date: Sat, 2 Mar 2024 01:20:25 +0100 Subject: [PATCH] Implemented interleave --- SPDX-License-Identifier: GPL-2.0-or-later cmds.cc | 39 +++++++++++++++++++++++++++++++++++++++ paperjam.1.txt | 10 ++++++++++ 2 files changed, 49 insertions(+) diff --git a/cmds.cc b/cmds.cc index a2ac331..49590a5 100644 --- a/cmds.cc +++ b/cmds.cc @@ -2,6 +2,7 @@ * PaperJam -- Commands * * (c) 2018--2022 Martin Mares + * (c) 2024 LEdoian */ #include @@ -1490,6 +1491,42 @@ static const arg_def slice_args[] = { { NULL, 0, NULL } }; +/*** interleave ***/ + +class interleave_cmd : public cmd_exec { + int n; +public: + interleave_cmd(cmd *c) + { + n = c->arg("n")->as_int(0); + if (n <= 0) + err("The number of interleaving groups must be positive"); + } + vector process(vector &pages) override; +}; + +vector interleave_cmd::process(vector &pages) +{ + vector in, out; + + in = pages; + // The last page may be superfluous... + while (in.size() % n) + in.push_back(new empty_page(in[0]->width, in[0]->height)); + int split = (int) in.size() / n; + + for (int i=0; i cmd_exec *ctor(cmd *c) { return new T(c); } @@ -1515,6 +1552,8 @@ const cmd_def cmd_table[] = { "Fit image to a given paper" }, { "flip", flip_args, 0, &ctor, "Flip page horizontally and/or vertically" }, + { "interleave", interleave_args, 0, &ctor, + "Interleave pages from different parts of the document" }, { "margins", margins_args, 0, &ctor, "Define image box by dimensions of margins around it" }, { "merge", no_args, 0, &ctor, diff --git a/paperjam.1.txt b/paperjam.1.txt index 94f3432..9bebcd4 100644 --- a/paperjam.1.txt +++ b/paperjam.1.txt @@ -255,6 +255,16 @@ Flip pages horizontally or vertically. *v=*'switch':: Flip vertically. +interleave +~~~~~~~~~~ +Splits the document into n groups of same size and interleaves them (first page +from all groups, then second, ...). + +If the number of input pages is not divisible by n, blank pages are added. + +*n=*'number':: + Number of groups. + margins ~~~~~~~ Define a new image box by dimensions of margins around it. More technically, -- 2.43.0