1
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
blog/output/images/mobius-print/interleave.patch

100 lines
2.7 KiB
Diff

From b32e0a3e27142898e87e13464154d4f9d8c5e96e Mon Sep 17 00:00:00 2001
From: LEdoian <paperjam@pokemon.ledoian.cz>
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 <mj@ucw.cz>
+ * (c) 2024 LEdoian <paperjam@pokemon.ledoian.cz>
*/
#include <cassert>
@@ -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<page *> process(vector<page *> &pages) override;
+};
+
+vector<page *> interleave_cmd::process(vector<page *> &pages)
+{
+ vector<page *> 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<split; i++)
+ for (int j=0; j<n; j++)
+ out.push_back(in[j*split+i]);
+
+ return out;
+}
+
+static const arg_def interleave_args[] = {
+ { "n", AT_INT | AT_POSITIONAL | AT_MANDATORY, "Number of interleaving groups" },
+ { NULL, 0, NULL }
+};
+
/*** Command table ***/
template<typename T> 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_cmd>,
"Flip page horizontally and/or vertically" },
+ { "interleave", interleave_args, 0, &ctor<interleave_cmd>,
+ "Interleave pages from different parts of the document" },
{ "margins", margins_args, 0, &ctor<margins_cmd>,
"Define image box by dimensions of margins around it" },
{ "merge", no_args, 0, &ctor<merge_cmd>,
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