Skip to content
This repository has been archived by the owner on Mar 6, 2023. It is now read-only.

Commit

Permalink
different page reshuffle callback. WARNING: DROPPED the "page_objnum_…
Browse files Browse the repository at this point in the history
…provider" callback, replaced with "page_order_index" -- trunk. (HH)

git-svn-id: https://serveur-svn.lri.fr/svn/modhel/luatex/trunk@7211 0b2b3880-5936-4365-a048-eb17d2e5a6bf
  • Loading branch information
luigiScarso committed Oct 23, 2019
1 parent c71be92 commit a16953d
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 40 deletions.
27 changes: 13 additions & 14 deletions manual/luatex-callbacks.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1038,36 +1038,35 @@ \subsection{\cbk {finish_pdfpage}}
This callback is called after the \PDF\ page stream has been assembled and before
the page object gets finalized.

\subsection{\cbk {page_objnum_provider}}
\subsection{\cbk {page_order_index}}

\topicindex{callbacks+\PDF\ file}

This is one that experts can use to juggle the page tree, a data structure
that determines the order in a \PDF\ file:

\startfunctioncall
function(objnum)
return objnum
function(pagenumber)
return pagenumber
end
\stopfunctioncall

We can for instance swap the first and last page:
Say that we have 12 pages, then we can do this:

\starttyping
local n = 0
callback.register("page_objnum_provider",function(objnum)
n = n + 1
if n == 1 then
return pdf.getpageref(tex.count[0])
elseif n == tex.count[0] then
return pdf.getpageref(1)
else
return objnum
callback.register("page_order_index",function(page)
if page == 1 then return 12
elseif page == 2 then return 11
elseif page == 11 then return 2
elseif page == 12 then return 1
else return page
end
end)
\stoptyping

When you mess things up \unknown\ don't complain.
This will swap the first two and last two pages. You need to know the number of
pages which is a side effect of the implementation. When you mess things up
\unknown\ don't complain.

\subsection{\cbk {process_pdf_image_content}}

Expand Down
Binary file modified manual/luatex.pdf
Binary file not shown.
4 changes: 4 additions & 0 deletions source/texk/web2c/luatexdir/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2019-10-22 Luigi Scarso <luigi.scarso@gmail.com>
* *** DROPPED "page_objnum_provider" callback , replaced with "page_order_index" ***


2019-10-18 Luigi Scarso <luigi.scarso@gmail.com>
* following https://tug.org/pipermail/tlbuild/2019q3/004553.html
we have now define(__sparc)
Expand Down
6 changes: 4 additions & 2 deletions source/texk/web2c/luatexdir/NEWS
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@

==============================================================
LuaTeX 1.11.1 2019-10-18
LuaTeX 1.11.1 2019-10-22
==============================================================

First release of luahbtex / luajithbtex,
luatex / luajittex with harfbuzz.
Small bug fixes, code clean up and a couple of new primitives
to match eTeX. See ChangeLog and the manual.
to match eTeX.
*** DROPPED the "page_objnum_provider" callback, replaced with "page_order_index". ***
See ChangeLog and the manual.



Expand Down
2 changes: 1 addition & 1 deletion source/texk/web2c/luatexdir/lua/lcallbacklib.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static const char *const callbacknames[] = {
"finish_synctex",
"wrapup_run",
"new_graf",
"page_objnum_provider",
"page_order_index",
"make_extensible",
"process_pdf_image_content",
NULL
Expand Down
2 changes: 1 addition & 1 deletion source/texk/web2c/luatexdir/luatex_svnversion.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define luatex_svn_revision 7207
#define luatex_svn_revision 7208
2 changes: 1 addition & 1 deletion source/texk/web2c/luatexdir/luatexcallbackids.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ typedef enum {
finish_synctex_callback,
wrapup_run_callback,
new_graf_callback,
page_objnum_provider_callback,
page_order_index_callback,
make_extensible_callback,
process_pdf_image_content_callback,
total_callbacks,
Expand Down
7 changes: 6 additions & 1 deletion source/texk/web2c/luatexdir/pdf/pdfgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -1777,7 +1777,12 @@ void pdf_end_page(PDF pdf)
if (callback_id > 0)
run_callback(callback_id, "b->",(global_shipping_mode == SHIPPING_PAGE));
if (global_shipping_mode == SHIPPING_PAGE) {
pdf->last_pages = pdf_do_page_divert(pdf, pdf->last_page, 0);
int location = 0;
int callback_id = callback_defined(page_order_index_callback);
if (callback_id) {
run_callback(callback_id, "d->d", total_pages, &location);
}
pdf->last_pages = pdf_do_page_divert(pdf, pdf->last_page, location);
/*tex Write out the |/Page| object. */
pdf_begin_obj(pdf, pdf->last_page, OBJSTM_ALWAYS);
pdf_begin_dict(pdf);
Expand Down
27 changes: 7 additions & 20 deletions source/texk/web2c/luatexdir/pdf/pdfpagetree.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void pdf_do_page_undivert(int divnum, int curdivnum)

/*tex Write a |/Pages| object. */

static void write_pages(PDF pdf, pages_entry * p, int parent, int callback_id)
static void write_pages(PDF pdf, pages_entry * p, int parent)
{
int i;
int pages_attributes ;
Expand All @@ -185,19 +185,7 @@ static void write_pages(PDF pdf, pages_entry * p, int parent, int callback_id)
pdf_add_name(pdf, "Kids");
pdf_begin_array(pdf);
for (i = 0; i < p->number_of_kids; i++) {
if (callback_id) {
/* new */
int objnum = (int) p->kids[i];
if (obj_type(pdf, objnum) == obj_type_page) {
run_callback(callback_id, "d->d", objnum, &objnum);
check_obj_exists(pdf, objnum);
pdf_add_ref(pdf, (int) objnum);
} else {
pdf_add_ref(pdf, (int) p->kids[i]);
}
} else {
pdf_add_ref(pdf, (int) p->kids[i]);
}
pdf_add_ref(pdf, (int) p->kids[i]);
}
pdf_end_array(pdf);
pdf_end_dict(pdf);
Expand All @@ -211,12 +199,12 @@ static void write_pages(PDF pdf, pages_entry * p, int parent, int callback_id)
*/

static int output_pages_list(PDF pdf, pages_entry * pe, int callback_id)
static int output_pages_list(PDF pdf, pages_entry * pe)
{
pages_entry *p, *q, *r;
if (pe->next == NULL) {
/*tex Everything fits into one |pages_entry|. */
write_pages(pdf, pe, 0, callback_id);
write_pages(pdf, pe, 0);
return pe->objnum;
}
/*tex One level higher needed. */
Expand All @@ -228,19 +216,18 @@ static int output_pages_list(PDF pdf, pages_entry * pe, int callback_id)
}
q->kids[q->number_of_kids++] = p->objnum;
q->number_of_pages += p->number_of_pages;
write_pages(pdf, p, q->objnum, callback_id);
write_pages(pdf, p, q->objnum);
}
/*tex Recurse through next higher level. */
return output_pages_list(pdf, r, callback_id);
return output_pages_list(pdf, r);
}

int output_pages_tree(PDF pdf)
{
int callback_id = callback_defined(page_objnum_provider_callback);
divert_list_entry *d;
/*tex Concatenate all diversions into diversion 0. */
pdf_do_page_undivert(0, 0);
/*tex Get diversion 0. */
d = get_divert_list(0);
return output_pages_list(pdf, d->first, callback_id);
return output_pages_list(pdf, d->first);
}

0 comments on commit a16953d

Please sign in to comment.