[latex3-commits] [git/LaTeX3-latex3-pdfresources] splitting: moving page backend (26a2e24)
Ulrike Fischer
fischer at troubleshooting-tex.de
Mon Jun 22 23:33:02 CEST 2020
Repository : https://github.com/latex3/pdfresources
On branch : splitting
Link : https://github.com/latex3/pdfresources/commit/26a2e24cd3f4be3c713a6c1bb43bf62b0c93dd62
>---------------------------------------------------------------
commit 26a2e24cd3f4be3c713a6c1bb43bf62b0c93dd62
Author: Ulrike Fischer <fischer at troubleshooting-tex.de>
Date: Mon Jun 22 23:33:02 2020 +0200
moving page backend
>---------------------------------------------------------------
26a2e24cd3f4be3c713a6c1bb43bf62b0c93dd62
l3backend-pdf-extra.dtx | 265 ++++++++++++++++++++++++++++++++++++++++++++++++
pdfresources.dtx | 261 +----------------------------------------------
2 files changed, 266 insertions(+), 260 deletions(-)
diff --git a/l3backend-pdf-extra.dtx b/l3backend-pdf-extra.dtx
index 9ec8871..d9d5aa8 100644
--- a/l3backend-pdf-extra.dtx
+++ b/l3backend-pdf-extra.dtx
@@ -162,6 +162,271 @@
%</dvipdfmx|xdvipdfmx>
% \end{macrocode}
% \end{macro}
+%
+% \subsubsection{\enquote{Page} and \enquote{ThisPage} /backend}
+% \begin{NOTE}{UF}
+% path: Page
+% !!!!!!!!!!!!!!!!!!!!!!
+% This part of the code depends on zref as it sets labels.
+% It also depends on code in coredict as the code uses the Core-dictionaries
+% !!!!!!!!!!!!!!!!!!!!!!
+%
+% The engines differ a lot here: pdflatex and lualatex uses a register while with
+% dvips/dvipdfmx a one-shot-special is used. So for pdflatex and lualatex code
+% to assemble the content of the register is needed. Specials are used at shipout,
+% the registers is set directly. With lualatex one can use
+% \cs{latelua} to delay the setting, with pdflatex one has to use a shipout hook.
+% To get the code on the correct page one has to use the aux with pdflatex.
+% In sum this means that quite a lot backend commands are needed to handle
+% this differences. Simply variants of \cs{pdfpageattr} are not enough ...%
+% dvips syntax: \special{ps: [{ThisPage}<</Rotate 90>> /PUT pdfmark}%
+% There seem to be an in-built management code: multiple uses don't lead to
+% multiple entries (/Rotate is special: there is always a /Rotate 0 in the dict,
+% but seems not to do harm).
+% dvipdfmx syntax: \special{pdf: put @thispage << /Rotate 90 >>},
+% like dvips the backend has an in-built management code.
+% Both change only the current page, so to get the pdftex behavior (which sets
+% also the following pages) one need to repeat it on every shipout.
+% \end{NOTE}
+% \begin{macro}
+% {
+% \@@_backend_Page_primitive:n,
+% \@@_backend_Page_gput:nn,
+% \@@_backend_Page_gremove:n,
+% \@@_backend_ThisPage_gput:nn,
+% \@@_backend_ThisPage_gpush:n
+% }
+% \cs{@@_backend_Page_primitive:n} is the primitive command to add
+% something to the /Page dictionary.
+% It works differently for the backends: pdftex and luatex overwrite existing
+% content, dvips and dvipdfmx are additive. luatex sets it in lua.
+% The higher level code has to take this into account.
+% \cs{@@_backend_Page_gput:nn} stores default values.
+% \cs{@@_backend_Page_gremove:n} allows to remove a value.
+% \cs{@@_backend_ThisPage_gput:nn} adds a value to the current page.
+% \cs{@@_backend_ThisPage_gpush:n} merges the default and the current page values
+% and add them to the dictionary of the current page in
+% \cs{g_@@_backend_thispage_shipout_tl}.
+% \begin{macrocode}
+% backend commands
+%<*pdfmode>
+\sys_if_engine_pdftex:T
+ {
+ %the primitive
+ \cs_new_protected:Npn \@@_backend_Page_primitive:n #1
+ {
+ \tex_global:D \tex_pdfpageattr:D { #1 }
+ }
+ % the command to store default values.
+ % Uses a prop with pdflatex + dvi,
+ % sets a lua table with lualatex
+ \cs_new_protected:Npn \@@_backend_Page_gput:nn #1 #2 %key,value
+ {
+ \pdfdict_gput:nnn {Core/Page}{ #1 }{ #2 }
+ }
+ % the command to remove a default value.
+ % Uses a prop with pdflatex + dvi,
+ % changes a lua table with lualatex
+ \cs_new_protected:Npn \@@_backend_Page_gremove:n #1
+ {
+ \pdfdict_gremove:nn {Core/Page}{ #1 }
+ }
+ % the command used in the document.
+ % direct call of the primitive special with dvips/dvipdfmx
+ % \latelua: fill a page related table with lualatex, merge it with the page
+ % table and push it directly
+ % write to aux and store in prop with pdflatex
+ \cs_new_protected:Npn \@@_backend_ThisPage_gput:nn #1 #2
+ {
+ %we need to know the page the resource should be added too.
+ \int_gincr:N\g_@@_backend_resourceid_int
+ \zref at labelbylist {l3pdf\int_use:N\g_@@_backend_resourceid_int} {l3pdf}
+ \tl_set:Nx \l_@@_tmpa_tl
+ {
+ \zref at extractdefault
+ {l3pdf\int_use:N\g_@@_backend_resourceid_int}
+ {pdf at abspage}
+ {0}
+ }
+ \pdfdict_if_gexist:nF {Core/backend_Page\l_@@_tmpa_tl}
+ {
+ \pdfdict_gnew:n {Core/backend_Page\l_@@_tmpa_tl}
+ }
+ %\__pdfcoredict_handler_gput:nnn {backend_Page\l_@@_tmpa_tl}{ #1 }{ #2 }
+ %backend_Page has no handler.
+ \pdfdict_gput:nnn {Core/backend_Page\l_@@_tmpa_tl}{ #1 }{ #2 }
+ }
+ %the code to push the values, used in shipout
+ %merges the two props and then fills the register in pdflatex
+ %merges the two tables and then fills (in lua) in luatex
+ %issues the values stored in the global prop with dvi
+ \cs_new_protected:Npn \@@_backend_ThisPage_gpush:n #1
+ {
+ \prop_gset_eq:Nc \g_@@_tmpa_prop { \pdfdict_gname:n { Core/Page } }
+ \prop_if_exist:cT { \pdfdict_gname:n { Core/backend_Page#1 } }
+ {
+ \prop_map_inline:cn { \pdfdict_gname:n { Core/backend_Page#1 } }
+ {
+ \prop_gput:Nnn \g_@@_tmpa_prop { ##1 }{ ##2 }
+ }
+ }
+ \exp_args:Nx \@@_backend_Page_primitive:n
+ {
+ \prop_map_function:NN \g_@@_tmpa_prop \pdfdict_item:ne
+ }
+ }
+ }
+
+\sys_if_engine_luatex:T
+ {% do we need to use some escaping for the values?????
+ \cs_new:Npn \@@_backend_luastring:n #1
+ {
+ "\tex_luaescapestring:D { \tex_unexpanded:D { #1 } }"
+ }
+ %not used, only there for consistency
+ \cs_new_protected:Npn \@@_backend_Page_primitive:n #1
+ {
+ \tex_latelua:D
+ {
+ pdf.setpageattributes(\@@_backend_luastring:n { #1 })
+ }
+ }
+ % the command to store default values.
+ % Uses a prop with pdflatex + dvi,
+ % sets a lua table with lualatex
+ \cs_new_protected:Npn \@@_backend_Page_gput:nn #1 #2
+ {
+ \tex_directlua:D
+ {
+ l3kernel.@@.backend_Page_gput
+ (
+ \@@_backend_luastring:n { #1 },
+ \@@_backend_luastring:n { #2 }
+ )
+ }
+ }
+ % the command to remove a default value.
+ % Uses a prop with pdflatex + dvi,
+ % changes a lua table with lualatex
+ \cs_new_protected:Npn \@@_backend_Page_gremove:n #1
+ {
+ \tex_directlua:D
+ {
+ l3kernel.@@.backend_Page_gremove (\@@_backend_luastring:n { #1 })
+ }
+ }
+ % the command used in the document.
+ % direct call of the primitive special with dvips/dvipdfmx
+ % \latelua: fill a page related table with lualatex, merge it with the page
+ % table and push it directly
+ % write to aux and store in prop with pdflatex
+ \cs_new_protected:Npn \@@_backend_ThisPage_gput:nn #1 #2
+ {
+ \tex_latelua:D
+ {
+ l3kernel.@@.backend_ThisPage_gput
+ (
+ tex.count["g_shipout_readonly_int"],
+ \@@_backend_luastring:n { #1 },
+ \@@_backend_luastring:n { #2 }
+ )
+ l3kernel.@@.backend_ThisPage_gpush (tex.count["g_shipout_readonly_int"])
+ }
+ }
+ %the code to push the values, used in shipout
+ %merges the two props and then fills the register in pdflatex
+ %merges the two tables (the one is probably still empty) and then fills (in lua) in luatex
+ %issues the values stored in the global prop with dvi
+ \cs_new_protected:Npn \@@_backend_ThisPage_gpush:n #1
+ {
+ \tex_latelua:D
+ {
+ l3kernel.@@.backend_ThisPage_gpush (tex.count["g_shipout_readonly_int"])
+ }
+ }
+ }
+%</pdfmode>
+%<*dvipdfmx|xdvipdfmx>
+ %the primitive
+\cs_new_protected:Npn \@@_backend_Page_primitive:n #1
+ {
+ \tex_special:D{pdf:~put~@thispage~<<#1>>}
+ }
+ % the command to store default values.
+ % Uses a prop with pdflatex + dvi,
+ % sets a lua table with lualatex
+\cs_new_protected:Npn \@@_backend_Page_gput:nn #1 #2
+ {
+ \pdfdict_gput:nnn {Core/Page}{ #1 }{ #2 }
+ }
+ % the command to remove a default value.
+ % Uses a prop with pdflatex + dvi,
+ % changes a lua table with lualatex
+\cs_new_protected:Npn \@@_backend_Page_gremove:n #1
+ {
+ \pdfdict_gremove:nn {Core/Page}{ #1 }
+ }
+ % the command used in the document.
+ % direct call of the primitive special with dvips/dvipdfmx
+ % \latelua: fill a page related table with lualatex, merge it with the page
+ % table and push it directly
+ % write to aux and store in prop with pdflatex
+\cs_new_protected:Npn \@@_backend_ThisPage_gput:nn #1 #2
+ {
+ \@@_backend_Page_primitive:n { /#1~#2 }
+ }
+ %the code to push the values, used in shipout
+ %merges the two props and then fills the register in pdflatex
+ %merges the two tables (the one is probably still empty)
+ % and then fills (in lua) in luatex
+ %issues the values stored in the global prop with dvi
+\cs_new_protected:Npn \@@_backend_ThisPage_gpush:n #1
+ {
+ \exp_args:Nx \@@_backend_Page_primitive:n
+ { \pdfdict_gmap:n {Core/Page} }
+ }
+%</dvipdfmx|xdvipdfmx>
+%<*dvips>
+\cs_new_protected:Npn \@@_backend_Page_primitive:n #1
+ {
+ \tex_special:D{ps:~[{ThisPage}<<#1>>~/PUT~pdfmark} %]
+ }
+ % the command to store default values.
+ % Uses a prop with pdflatex + dvi,
+ % sets a lua table with lualatex
+\cs_new_protected:Npn \@@_backend_Page_gput:nn #1 #2
+ {
+ \pdfdict_gput:nnn {Core/Page}{ #1 }{ #2 }
+ }
+ % the command to remove a default value.
+ % Uses a prop with pdflatex + dvi,
+ % changes a lua table with lualatex
+\cs_new_protected:Npn \@@_backend_Page_gremove:n #1
+ {
+ \pdfdict_gremove:nn {Core/Page}{ #1 }
+ }
+ % the command used in the document.
+ % direct call of the primitive special with dvips/dvipdfmx
+ % \latelua: fill a page related table with lualatex, merge it with the page
+ % table and push it directly
+ % write to aux and store in prop with pdflatex
+\cs_new_protected:Npn \@@_backend_ThisPage_gput:nn #1 #2
+ {
+ \@@_backend_Page_primitive:n { /#1~#2 }
+ }
+ %the code to push the values, used in shipout
+ %merges the two props and then fills the register in pdflatex
+ %merges the two tables (the one is probably still empty)
+ %and then fills (in lua) in luatex
+ %issues the values stored in the global prop with dvi
+\cs_new_protected:Npn \@@_backend_ThisPage_gpush:n #1
+ {
+ \exp_args:Nx \@@_backend_Page_primitive:n
+ { \pdfdict_gmap:n {Core/Page} }
+ }
+%</dvips>
+% \end{macrocode}
+% \end{macro}
% \end{implementation}
%
% \PrintIndex
diff --git a/pdfresources.dtx b/pdfresources.dtx
index 98a4946..5335dfe 100644
--- a/pdfresources.dtx
+++ b/pdfresources.dtx
@@ -184,7 +184,6 @@
% dvipdfmx syntax: \verb+\special{pdf:put @pages <</ABC /WEZ /EFG /XYZ /Rotate 0>>}+
% both remove duplicate entries automatically, so there is no need to be careful.
% \end{NOTE}
-
%
% \subsubsection{\enquote{Pages} / management}
% \begin{NOTE}{UF}
@@ -197,265 +196,7 @@
%
% \subsection{\enquote{Page} and \enquote{ThisPage} (pdfpageattr)}
% \subsubsection{\enquote{Page} and \enquote{ThisPage} /backend}
-% \begin{NOTE}{UF}
-% path: Page
-% The engines differ a lot here: pdflatex and lualatex uses a register while with
-% dvips/dvipdfmx a one-shot-special is used. So for pdflatex and lualatex code
-% to assemble the content of the register is needed. Specials are used at shipout,
-% the registers is set directly. With lualatex one can use
-% \cs{latelua} to delay the setting, with pdflatex one has to use a shipout hook.
-% To get the code on the correct page one has to use the aux with pdflatex.
-% In sum this means that quite a lot backend commands are needed to handle
-% this differences. Simply variants of \cs{pdfpageattr} are not enough ...%
-% dvips syntax: \special{ps: [{ThisPage}<</Rotate 90>> /PUT pdfmark}%
-% There seem to be an in-built management code: multiple uses don't lead to
-% multiple entries (/Rotate is special: there is always a /Rotate 0 in the dict,
-% but seems not to do harm).
-% dvipdfmx syntax: \special{pdf: put @thispage << /Rotate 90 >>},
-% like dvips the backend has an in-built management code.
-% Both change only the current page, so to get the pdftex behavior (which sets
-% also the following pages) one need to repeat it on every shipout.
-% \end{NOTE}
-% \begin{macro}
-% {
-% \@@_backend_Page_primitive:n,
-% \@@_backend_Page_gput:nn,
-% \@@_backend_Page_gremove:n,
-% \@@_backend_ThisPage_gput:nn,
-% \@@_backend_ThisPage_gpush:n
-% }
-% \cs{@@_backend_Page_primitive:n} is the primitive command to add
-% something to the /Page dictionary.
-% It works differently for the backends: pdftex and luatex overwrite existing
-% content, dvips and dvipdfmx are additive. luatex sets it in lua.
-% The higher level code has to take this into account.
-% \cs{@@_backend_Page_gput:nn} stores default values.
-% \cs{@@_backend_Page_gremove:n} allows to remove a value.
-% \cs{@@_backend_ThisPage_gput:nn} adds a value to the current page.
-% \cs{@@_backend_ThisPage_gpush:n} merges the default and the current page values
-% and add them to the dictionary of the current page in
-% \cs{g_@@_backend_thispage_shipout_tl}.
-% \begin{macrocode}
-% backend commands
-%<*pdfmode>
-\sys_if_engine_pdftex:T
- {
- %the primitive
- \cs_new_protected:Npn \@@_backend_Page_primitive:n #1
- {
- \tex_global:D \tex_pdfpageattr:D { #1 }
- }
- % the command to store default values.
- % Uses a prop with pdflatex + dvi,
- % sets a lua table with lualatex
- \cs_new_protected:Npn \@@_backend_Page_gput:nn #1 #2 %key,value
- {
- \pdfdict_gput:nnn {Core/Page}{ #1 }{ #2 }
- }
- % the command to remove a default value.
- % Uses a prop with pdflatex + dvi,
- % changes a lua table with lualatex
- \cs_new_protected:Npn \@@_backend_Page_gremove:n #1
- {
- \pdfdict_gremove:nn {Core/Page}{ #1 }
- }
- % the command used in the document.
- % direct call of the primitive special with dvips/dvipdfmx
- % \latelua: fill a page related table with lualatex, merge it with the page
- % table and push it directly
- % write to aux and store in prop with pdflatex
- \cs_new_protected:Npn \@@_backend_ThisPage_gput:nn #1 #2
- {
- %we need to know the page the resource should be added too.
- \int_gincr:N\g_@@_backend_resourceid_int
- \zref at labelbylist {l3pdf\int_use:N\g_@@_backend_resourceid_int} {l3pdf}
- \tl_set:Nx \l_@@_tmpa_tl
- {
- \zref at extractdefault
- {l3pdf\int_use:N\g_@@_backend_resourceid_int}
- {pdf at abspage}
- {0}
- }
- \pdfdict_if_gexist:nF {Core/backend_Page\l_@@_tmpa_tl}
- {
- \pdfdict_gnew:n {Core/backend_Page\l_@@_tmpa_tl}
- }
- %\__pdfcoredict_handler_gput:nnn {backend_Page\l_@@_tmpa_tl}{ #1 }{ #2 }
- %backend_Page has no handler.
- \pdfdict_gput:nnn {Core/backend_Page\l_@@_tmpa_tl}{ #1 }{ #2 }
- }
- %the code to push the values, used in shipout
- %merges the two props and then fills the register in pdflatex
- %merges the two tables and then fills (in lua) in luatex
- %issues the values stored in the global prop with dvi
- \cs_new_protected:Npn \@@_backend_ThisPage_gpush:n #1
- {
- \prop_gset_eq:Nc \g_@@_tmpa_prop { \pdfdict_gname:n { Core/Page } }
- \prop_if_exist:cT { \pdfdict_gname:n { Core/backend_Page#1 } }
- {
- \prop_map_inline:cn { \pdfdict_gname:n { Core/backend_Page#1 } }
- {
- \prop_gput:Nnn \g_@@_tmpa_prop { ##1 }{ ##2 }
- }
- }
- \exp_args:Nx \@@_backend_Page_primitive:n
- {
- \prop_map_function:NN \g_@@_tmpa_prop \pdfdict_item:ne
- }
- }
- }
-
-\sys_if_engine_luatex:T
- {% do we need to use some escaping for the values?????
- \cs_new:Npn \@@_backend_luastring:n #1
- {
- "\tex_luaescapestring:D { \tex_unexpanded:D { #1 } }"
- }
- %not used, only there for consistency
- \cs_new_protected:Npn \@@_backend_Page_primitive:n #1
- {
- \tex_latelua:D
- {
- pdf.setpageattributes(\@@_backend_luastring:n { #1 })
- }
- }
- % the command to store default values.
- % Uses a prop with pdflatex + dvi,
- % sets a lua table with lualatex
- \cs_new_protected:Npn \@@_backend_Page_gput:nn #1 #2
- {
- \tex_directlua:D
- {
- l3kernel.@@.backend_Page_gput
- (
- \@@_backend_luastring:n { #1 },
- \@@_backend_luastring:n { #2 }
- )
- }
- }
- % the command to remove a default value.
- % Uses a prop with pdflatex + dvi,
- % changes a lua table with lualatex
- \cs_new_protected:Npn \@@_backend_Page_gremove:n #1
- {
- \tex_directlua:D
- {
- l3kernel.@@.backend_Page_gremove (\@@_backend_luastring:n { #1 })
- }
- }
- % the command used in the document.
- % direct call of the primitive special with dvips/dvipdfmx
- % \latelua: fill a page related table with lualatex, merge it with the page
- % table and push it directly
- % write to aux and store in prop with pdflatex
- \cs_new_protected:Npn \@@_backend_ThisPage_gput:nn #1 #2
- {
- \tex_latelua:D
- {
- l3kernel.@@.backend_ThisPage_gput
- (
- tex.count["g_shipout_readonly_int"],
- \@@_backend_luastring:n { #1 },
- \@@_backend_luastring:n { #2 }
- )
- l3kernel.@@.backend_ThisPage_gpush (tex.count["g_shipout_readonly_int"])
- }
- }
- %the code to push the values, used in shipout
- %merges the two props and then fills the register in pdflatex
- %merges the two tables (the one is probably still empty) and then fills (in lua) in luatex
- %issues the values stored in the global prop with dvi
- \cs_new_protected:Npn \@@_backend_ThisPage_gpush:n #1
- {
- \tex_latelua:D
- {
- l3kernel.@@.backend_ThisPage_gpush (tex.count["g_shipout_readonly_int"])
- }
- }
- }
-%</pdfmode>
-%<*dvipdfmx|xdvipdfmx>
- %the primitive
-\cs_new_protected:Npn \@@_backend_Page_primitive:n #1
- {
- \tex_special:D{pdf:~put~@thispage~<<#1>>}
- }
- % the command to store default values.
- % Uses a prop with pdflatex + dvi,
- % sets a lua table with lualatex
-\cs_new_protected:Npn \@@_backend_Page_gput:nn #1 #2
- {
- \pdfdict_gput:nnn {Core/Page}{ #1 }{ #2 }
- }
- % the command to remove a default value.
- % Uses a prop with pdflatex + dvi,
- % changes a lua table with lualatex
-\cs_new_protected:Npn \@@_backend_Page_gremove:n #1
- {
- \pdfdict_gremove:nn {Core/Page}{ #1 }
- }
- % the command used in the document.
- % direct call of the primitive special with dvips/dvipdfmx
- % \latelua: fill a page related table with lualatex, merge it with the page
- % table and push it directly
- % write to aux and store in prop with pdflatex
-\cs_new_protected:Npn \@@_backend_ThisPage_gput:nn #1 #2
- {
- \@@_backend_Page_primitive:n { /#1~#2 }
- }
- %the code to push the values, used in shipout
- %merges the two props and then fills the register in pdflatex
- %merges the two tables (the one is probably still empty)
- % and then fills (in lua) in luatex
- %issues the values stored in the global prop with dvi
-\cs_new_protected:Npn \@@_backend_ThisPage_gpush:n #1
- {
- \exp_args:Nx \@@_backend_Page_primitive:n
- { \pdfdict_gmap:n {Core/Page} }
- }
-%</dvipdfmx|xdvipdfmx>
-%<*dvips>
-\cs_new_protected:Npn \@@_backend_Page_primitive:n #1
- {
- \tex_special:D{ps:~[{ThisPage}<<#1>>~/PUT~pdfmark} %]
- }
- % the command to store default values.
- % Uses a prop with pdflatex + dvi,
- % sets a lua table with lualatex
-\cs_new_protected:Npn \@@_backend_Page_gput:nn #1 #2
- {
- \pdfdict_gput:nnn {Core/Page}{ #1 }{ #2 }
- }
- % the command to remove a default value.
- % Uses a prop with pdflatex + dvi,
- % changes a lua table with lualatex
-\cs_new_protected:Npn \@@_backend_Page_gremove:n #1
- {
- \pdfdict_gremove:nn {Core/Page}{ #1 }
- }
- % the command used in the document.
- % direct call of the primitive special with dvips/dvipdfmx
- % \latelua: fill a page related table with lualatex, merge it with the page
- % table and push it directly
- % write to aux and store in prop with pdflatex
-\cs_new_protected:Npn \@@_backend_ThisPage_gput:nn #1 #2
- {
- \@@_backend_Page_primitive:n { /#1~#2 }
- }
- %the code to push the values, used in shipout
- %merges the two props and then fills the register in pdflatex
- %merges the two tables (the one is probably still empty)
- %and then fills (in lua) in luatex
- %issues the values stored in the global prop with dvi
-\cs_new_protected:Npn \@@_backend_ThisPage_gpush:n #1
- {
- \exp_args:Nx \@@_backend_Page_primitive:n
- { \pdfdict_gmap:n {Core/Page} }
- }
-%</dvips>
-% \end{macrocode}
-% \end{macro}
-%
+% moved to l3backend-pdf-extra
% \subsubsection{\enquote{Page} and \enquote{ThisPage} / management}
% \begin{NOTE}{UF}
% Open is the question if one need a command to set attribute on a page by page number.
More information about the latex3-commits
mailing list.