[latex3-commits] [git/LaTeX3-latex3-pdfresources] backendtest: working on pageattr (33c06c0)
Ulrike Fischer
fischer at troubleshooting-tex.de
Fri Jun 21 00:02:27 CEST 2019
Repository : https://github.com/latex3/pdfresources
On branch : backendtest
Link : https://github.com/latex3/pdfresources/commit/33c06c0ee5e98048ad12d0b1d45d176025913ddd
>---------------------------------------------------------------
commit 33c06c0ee5e98048ad12d0b1d45d176025913ddd
Author: Ulrike Fischer <fischer at troubleshooting-tex.de>
Date: Fri Jun 21 00:02:27 2019 +0200
working on pageattr
>---------------------------------------------------------------
33c06c0ee5e98048ad12d0b1d45d176025913ddd
build.lua | 2 +-
experiments/dvipdfmx-properties.tex | 10 ++
experiments/dvips-properties.tex | 18 +++
experiments/lualatex-properties-lua.tex | 66 ++++++++++
experiments/lualatex-properties.tex | 32 +++++
experiments/pdfmode-properties.tex | 37 ++++++
pdfresources.dtx | 212 +++++++++++++++++++++++++-------
7 files changed, 333 insertions(+), 44 deletions(-)
diff --git a/build.lua b/build.lua
index 37d843c..1fde1c0 100644
--- a/build.lua
+++ b/build.lua
@@ -6,7 +6,7 @@
bundle = ""
module = "pdfresources"
-installfiles = {"*.sty","*.cls","*.def"}
+installfiles = {"*.sty","*.cls","*.def","*.lua"}
sourcefiles = {"*.dtx","*.ins","hluatex-experimental.def","tmpl3shipout.sty"}
checkruns = 3
diff --git a/experiments/dvipdfmx-properties.tex b/experiments/dvipdfmx-properties.tex
index deef3fb..16bb244 100644
--- a/experiments/dvipdfmx-properties.tex
+++ b/experiments/dvipdfmx-properties.tex
@@ -3,8 +3,13 @@
\ExplSyntaxOn
\pdf_uncompress:
\ExplSyntaxOff
+%works fine, resources only on page 2
\begin{document}
+abc
+\vspace{44\baselineskip}
+
+x\\x\\x\\
\special{pdf:code /Span /Test1 BDC}
\special{pdf:put @resources <<
/Properties <</Test1 <</Type /Artifact>>>>>>}
@@ -17,5 +22,10 @@ blblblb
blblblb
\special{pdf:code EMC}
+\mbox{\special{pdf:code /Span /Test3 BDC}
+ \special{pdf:put @resources <<
+ /Properties <</Test3 <</Type /Artifact>>>>>>}
+blblblb
+\special{pdf:code EMC}}
\end{document}
\ No newline at end of file
diff --git a/experiments/dvips-properties.tex b/experiments/dvips-properties.tex
new file mode 100644
index 0000000..bea36dd
--- /dev/null
+++ b/experiments/dvips-properties.tex
@@ -0,0 +1,18 @@
+\documentclass{article}
+\usepackage{l3pdf,pdfresources}
+\ExplSyntaxOn
+\pdf_uncompress:
+\ExplSyntaxOff
+%looks okay,
+\begin{document}
+abc
+
+\vspace{44\baselineskip}
+
+x\\x\\x\\
+\special{ps:[/Span <</Type /Artifact>> /BDC pdfmark}
+some text
+\special{ps:[/EMC pdfmark}
+
+
+\end{document}
\ No newline at end of file
diff --git a/experiments/lualatex-properties-lua.tex b/experiments/lualatex-properties-lua.tex
new file mode 100644
index 0000000..d1621fa
--- /dev/null
+++ b/experiments/lualatex-properties-lua.tex
@@ -0,0 +1,66 @@
+\documentclass[10pt]{article}
+\usepackage{l3pdf,pdfresources,luacode}
+\begin{luacode}
+pdfdata= pdfdata or {}
+pdfdata.resources = pdfdata.resources or {}
+pdfdata.resources.properties = pdfdata.resources.properties or {}
+
+function pdfdata.resources.properties.store (id,obj)
+ pdfdata.resources.properties[tex.count["c at page"]] = pdfdata.resources.properties[tex.count["c at page"]] or {}
+ pdfdata.resources.properties[tex.count["c at page"]]["LTX"..id]= obj
+end
+
+function pdfdata.resources.properties.output(page)
+ local t = pdfdata.resources.properties[page]
+ if t and not( next(t) == nil) then
+ local dict="/Properties <<"
+ for name, obj in pairs(t) do
+ dict=dict.." /"..name.." "..obj
+ end
+ dict=dict..">>"
+ return dict
+ end
+end
+\end{luacode}
+\ExplSyntaxOn
+\pdf_uncompress:
+\int_new:N\g__pdf_BDCobj_int
+\cs_set_protected:Npn \__pdf_backend_bdc:nn #1 #2
+ {
+ \int_gincr:N\g__pdf_BDCobj_int
+ \__pdf_backend_object_now:nn {dict}{#1}%
+ \exp_args:Nx \latelua{
+ pdfdata.resources.properties.store ("\int_use:N\g__pdf_BDCobj_int", "\__pdf_backend_object_last:")
+ pdfdata.resources.properties.output(tex.count["c at page"])
+ pdf.setpageresources (pdfdata.resources.properties.output(tex.count["c at page"]))
+% texio.write_nl(table.serialize(pdfdata.resources.properties))
+ }
+ }
+\ExplSyntaxOff
+%This is works ...
+%to do: check if more than one by page can be handled
+\begin{document}
+abc
+
+\vspace{44\baselineskip}
+
+x\\x\\x\\
+\ExplSyntaxOn
+%\__pdf_backend_bdc:nn {span}{/Type/Artifact}
+
+%\__pdf_backend_object_new:nn {BDC1}{dict}
+%\__pdf_backend_object_write:nn{BDC1}{/Type/Artifact}
+%\latelua{pdf.setpageresources("/Properties <</BDC1~\__pdf_backend_object_ref:n {BDC1}>>")}
+\__pdf_backend_bdc:nn {Span}{/Type/Artifact}
+abc
+\__pdf_backend_emc:
+\__pdf_backend_bdc:nn {Span}{/Type/X /MCID~1}
+abc
+\__pdf_backend_emc:
+
+\mbox{\__pdf_backend_bdc:nn {Span}{/Type/X /MCID~2}
+abc
+\__pdf_backend_emc:}
+
+\ExplSyntaxOff
+\end{document}
\ No newline at end of file
diff --git a/experiments/lualatex-properties.tex b/experiments/lualatex-properties.tex
new file mode 100644
index 0000000..74b5365
--- /dev/null
+++ b/experiments/lualatex-properties.tex
@@ -0,0 +1,32 @@
+\documentclass{article}
+\usepackage{l3pdf,pdfresources}
+\ExplSyntaxOn
+\pdf_uncompress:
+\ExplSyntaxOff
+%This is works ...
+%to do: check if more than one by page can be handled
+\begin{document}
+abc
+
+\vspace{44\baselineskip}
+
+x\\x\\x\\
+\ExplSyntaxOn
+\__pdf_backend_object_new:nn {BDC1}{dict}
+\__pdf_backend_object_write:nn{BDC1}{/Type/Artifact}
+\latelua{pdf.setpageresources("/Properties <</BDC1~\__pdf_backend_object_ref:n {BDC1}>>")}
+\__pdf_backend_bdc:nn {Span}{/BDC1}
+abc
+\__pdf_backend_emc:
+\ExplSyntaxOff
+
+\begin{figure}[p]
+\__pdf_backend_object_new:nn {BDC2}{dict}
+\__pdf_backend_object_write:nn{BDC2}{/Type/Artifact}
+%\exp_args:Nx\__pdf_backend_pageresources:n {/Properties~<</BDC2~\__pdf_backend_object_ref:n {BDC2}>>}
+\latelua{pdf.setpageresources("/Properties <</BDC2~\__pdf_backend_object_ref:n {BDC2}>>")}
+\__pdf_backend_bdc:nn {Span}{/BDC2}
+abc
+\__pdf_backend_emc:
+\end{figure}
+\end{document}
\ No newline at end of file
diff --git a/experiments/pdfmode-properties.tex b/experiments/pdfmode-properties.tex
new file mode 100644
index 0000000..1e84efe
--- /dev/null
+++ b/experiments/pdfmode-properties.tex
@@ -0,0 +1,37 @@
+\documentclass{article}
+\usepackage{l3pdf,pdfresources}
+\ExplSyntaxOn
+\pdf_uncompress:
+\ExplSyntaxOff
+\usepackage{zref-user,zref-abspage}
+%pdflatex needs two pass?
+\begin{document}
+abc
+
+\vspace{44\baselineskip}
+
+x\\x\\x\\
+\ExplSyntaxOn\makeatletter
+\__pdf_backend_object_new:nn {BDC1}{dict}
+\__pdf_backend_object_write:nn{BDC1}{/Type/Artifact}
+\AtBeginShipout{%
+\int_compare:nNnT{\zref at extractdefault {BDC1} {abspage} {0}}={\g__pdf_abspage_int}
+{\exp_args:Nx\__pdf_backend_pageresources:n {/Properties~<</BDC1~\__pdf_backend_object_ref:n {BDC1}>>}}}
+%\latelua{pdf.setpageresources("/Properties <</BDC1~\__pdf_backend_object_ref:n {BDC1}>>")}
+\__pdf_backend_bdc:nn {Span}{/BDC1}\zref at label{BDC1}
+abc
+\__pdf_backend_emc:
+
+\begin{figure}[p]
+\__pdf_backend_object_new:nn {BDC2}{dict}
+\__pdf_backend_object_write:nn{BDC2}{/Type/Artifact}
+\AtBeginShipout{%
+\int_compare:nNnT{\zref at extractdefault {BDC2} {abspage} {0}}={\g__pdf_abspage_int}
+{\exp_args:Nx\__pdf_backend_pageresources:n {/Properties~<</BDC2~\__pdf_backend_object_ref:n {BDC2}>>}}}
+\__pdf_backend_bdc:nn {Span}{/BDC2}\zlabel{BDC2}
+abc
+\__pdf_backend_emc:
+\end{figure}
+\ExplSyntaxOff
+
+\end{document}
\ No newline at end of file
diff --git a/pdfresources.dtx b/pdfresources.dtx
index 53fb6ce..c7c433a 100644
--- a/pdfresources.dtx
+++ b/pdfresources.dtx
@@ -92,6 +92,15 @@
%^^A still needed:
%^^A \pdf at strcmp??
%^^A \pdf at escapestring?? \pdfescapestring
+% \subsection{luacode}
+% \begin{macrocode}
+%<*package>
+\sys_if_engine_luatex:T
+{
+ \directlua{require("pdfresources.lua")}
+}
+%</package>
+% \end{macrocode}
% \subsection{end of run}
% \begin{NOTE}{UF}
% the \enquote{end-of-run} command is temporary until shipout/atendshipout code
@@ -227,34 +236,88 @@
% \subsubsection{backend / pdfpageattr}
% \begin{NOTE}{UF}
% path: page
-% pdfpageattr is a single token register which is output at the shipout for every page.
-% Implementation for dvips, dvipdfmx missing. dvips syntax:
-% \verb+ \special{ps: [{ThisPage}<</Rotate 90>> /PUT pdfmark}+
-% dvipdfmx syntax: \verb+\special{pdf: put @thispage << /ABC /XYZ >>}+
-%
+% The engines differ a lot here: pdflatex and lualatex uses a register while with
+% dvips a one-shot-special ist used. So for pdflatex and lualatex code to clear the register
+% is needed. Specials are used at shipout, registers 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 ...%
% \end{NOTE}
% \begin{macrocode}
%<*package>
%% backend commands
-\bool_if:nT {\sys_if_engine_pdftex_p: && \sys_if_output_pdf_p: || \sys_if_engine_luatex_p: }
+\bool_if:nT {\sys_if_engine_pdftex_p: && \sys_if_output_pdf_p: }
{
- %definition works also for luatex
- \cs_new_protected:Npx \@@_backend_pageattr:n #1
- {
- \exp_not:N \tex_global:D
- \cs_if_exist:NTF \tex_pdfpageattr:D
- { \tex_pdfpageattr:D }
- { \tex_pdfvariable:D pageattr }
- {#1}
- }
+ \cs_new_protected:Npn \@@_backend_pageattr:n #1
+ {
+ \tex_global:D \tex_pdfpageattr:D {#1}
+ }
+ %clear the register, should be used in shipout before
+ %filling with the new values. Noops in dvips/dvipdfmx
+ \cs_new_protected:Npn \@@_backend_pageattr_clear:
+ {
+ \tex_global:D \tex_pdfpageattr:D {}
+ }
+ % the command used in the document.
+ % special with dvips/dvipdfmx
+ % \latelua with lualatex
+ % write to aux with pdflatex
+ \cs_new_protected:Npn \@@_backend_pageattr_doc:nn #1 #2
+ {
+ \@@_backend_pageattr_aux:nn {#1}{#2}
+ }
+ \cs_new_protected:Npn \@@_backend_pageattr_aux:nn #1 #2
+ {
+ \iow_shipout_x:Nx \@auxout
+ {
+ \token_to_str:N\csname
+ __pdf_backend_pageattr_gput:nnn
+ \token_to_str:N\endcsname
+ {\exp_not:N\int_use:N \g__pdf_abspage_int}
+ { #1 }
+ { #2 }
+ }
+ }
}
+\sys_if_engine_luatex:T
+{
+ %needed ??????????????
+ \cs_new_protected:Npn \@@_backend_pageattr:n #1
+ {
+ \latelua{pdf.setpageattributes("#1")}
+ }
+ %clear the register, should be used in shipout before
+ %filling with the new values. Noops in dvips/dvipdfmx
+ \cs_new_protected:Npn \@@_backend_pageattr_clear:
+ {
+ \latelua{pdf.setpageattributes("")}
+ }
+ %the command used in the document.
+ % special with dvips/dvipdfmx
+ % \latelua with lualatex
+ % write to aux with pdflatex
+ \cs_new_protected:Npn \@@_backend_pageattr_doc:nn #1 #2
+ {
+ \latelua{l3kernel._@@.pageattr_doc (tex.count["g_@@_abspage_int"],"#1","#2")}
+ }
+}
\sys_if_engine_xetex:T
{
\cs_new_protected:Npx \@@_backend_pageattr:n #1
{
\tex_special:D{pdf:~put~@thispage~<<#1>>}
}
+ \cs_new_protected:Npn \@@_backend_pageattr_clear: {}
+ % the command used in the document.
+ % special with dvips/dvipdfmx
+ % \latelua with lualatex
+ % write to aux with pdflatex
+ \cs_new_protected:Npn \@@_backend_pageattr_doc:nn #1 #2
+ {
+ \@@_backend_pageattr:n {/#1~#2}
+ }
}
\bool_if:nT {\sys_if_engine_pdftex_p: && !\sys_if_output_pdf_p: }
@@ -263,6 +326,15 @@
{
\tex_special:D{ps:~[{ThisPage}<<#1>>~/PUT~pdfmark}
}
+ \cs_new_protected:Npn \@@_backend_pageattr_clear: {}
+ % the command used in the document.
+ % special with dvips/dvipdfmx
+ % \latelua with lualatex
+ % write to aux with pdflatex
+ \cs_new_protected:Npn \@@_backend_pageattr_doc:nn #1 #2
+ {
+ \@@_backend_pageattr:n {/#1~#2}
+ }
}
%</package>
% \end{macrocode}
@@ -394,6 +466,7 @@
\cs_new_protected:Npn \@@_shipout_code:
{
\int_gincr:N \g_@@_abspage_int
+ \int_show:N \g_@@_abspage_int
\@@_everypage_shipout_code:V \g_@@_abspage_int
\int_compare:nNnT { \g_@@_abspage_int }={\zref at extractdefault{LastPage}{abspage}{0}}
{
@@ -512,28 +585,29 @@
% \begin{syntax}
% \cs{pdf_pageattr_gput:nn} \Arg{name} \Arg{value}
% \end{syntax}
-% Adds |/|\meta{name} \meta{value} at shipout to the page dictionaries of the
-% current page and the following pages. The name-value pair is stored immediatly,
-% so the asynchronous page breaking must be taken into account when adding content.
-% It is always stored globally.
+% Adds |/|\meta{name} \meta{value} to the page dictionary of the
+% current page and the following pages. The values are assigned directly,
+% so one should take into account the asynchronous page breaking and use the
+% command only in sensible places like after a \cs{clearpage} and not inside
+% floats. It is always stored globally.
% \meta{name} should be a valid pdf name without the leading slash,
% \meta{value} should be a valid pdf value. Any escaping or (re)encoding must be
% done explictly. If a \meta{name} is used twice, only the last \meta{value}
-% set will be used.
+% set will be used. Names set with \cs{pdf_thispageattr_gput:nn} will overwrite
+% names set with \cs{pdf_pageattr_gput:nn} if there is a clash.
% \end{function}
-% \begin{function}[added = 2019-06-11]
-% {\pdf_pageattr_gput:nnn}
+% \begin{function}[added = 2019-06-04]
+% {
+% \pdf_pageattr_gremove:n
+% }
% \begin{syntax}
-% \cs{pdf_pageattr_gput:nnn} \Arg{num} \Arg{name} \Arg{value}
+% \pdf_pageattr_gremove:n \Arg{name}
% \end{syntax}
-% Adds |/|\meta{name} \meta{value} at shipout to the page dictionaries of the
-% page with the absolute page number \meta{num}.
-% It is always stored globally. If \Arg{name} has already a value set with
-% \cs{pdf_pageattr_gput:nn} it will overwrite it for this page.
-% \meta{name} should be a valid pdf name without the leading slash,
-% \meta{value} should be a valid pdf value. Any escaping or (re)encoding must be
-% done explictly. If a \meta{name} is used twice, only the last \meta{value}
-% set will be used.
+% Removes |/|\meta{name} and its associated \meta{value} added by \cs{pdf_pageattr_gput:nn}
+% from the page dictionaries of the current and the following pages.
+% If \meta{name} is not found no change occurs,
+% \emph{i.e}~there is no need to test for the existence of a name before
+% trying to remove it. It doesn't affect values set with \cs{pdf_thispageattr_gput:nn}.
% \end{function}
% \begin{function}[added = 2019-06-04]
% {\pdf_pageattr_get:nN}
@@ -547,19 +621,36 @@
% to the special marker \cs{q_no_value}. The \meta{token list
% variable} is set within the current \TeX{} group.
% \end{function}
-% \begin{function}[added = 2019-06-04]
-% {
-% \pdf_pageattr_gremove:n
-% }
+% \begin{function}[added = 2019-06-19]
+% {\pdf_thispageattr_gput:nn}
% \begin{syntax}
-% \pdf_pageattr_gremove:n \Arg{name}
+% \cs{pdf_thispageattr_gput:nn} \Arg{name} \Arg{value}
% \end{syntax}
-% Removes |/|\meta{name} and its associated \meta{value} from the page dictionaries
-% of the current and the following pages (if the name-value pair has been added by
-% \cs{pdf_pageattr_gput:nn}). If \meta{name} is not found no change occurs,
-% \emph{i.e}~there is no need to test for the existence of a name before
-% trying to remove it.
+% Adds |/|\meta{name} \meta{value} at shipout to the page dictionary of the
+% current page.
+% It is always stored globally. If \Arg{name} has already a value set with
+% \cs{pdf_pageattr_gput:nn} it will overwrite it for this page.
+% \meta{name} should be a valid pdf name without the leading slash,
+% \meta{value} should be a valid pdf value. Any escaping or (re)encoding must be
+% done explictly. If a \meta{name} is used twice, only the last \meta{value}
+% set will be used. With the engine pdflatex at least a second compilation is needed.
% \end{function}
+% \begin{function}[added = 2019-06-11]
+% {\pdf_pageattr_gput:nnn}
+% \begin{syntax}
+% \cs{pdf_pageattr_gput:nnn} \Arg{num} \Arg{name} \Arg{value}
+% \end{syntax}
+% Adds |/|\meta{name} \meta{value} at shipout to the page dictionaries of the
+% page with the absolute page number \meta{num}.
+% It is always stored globally. If \Arg{name} has already a value set with
+% \cs{pdf_pageattr_gput:nn} it will overwrite it for this page.
+% \meta{name} should be a valid pdf name without the leading slash,
+% \meta{value} should be a valid pdf value. Any escaping or (re)encoding must be
+% done explictly. If a \meta{name} is used twice, only the last \meta{value}
+% set will be used.
+% \end{function}
+
+
% \begin{macrocode}
%<*package>
\@@_tree_new:n {Page}
@@ -573,8 +664,8 @@
\@@_tree_gput:nnn {Page}{#1}{#2}
}
-% setter by page:
-\cs_new_protected:Npn \pdf_pageattr_gput:nnn #1 #2 #3
+% setter by page number:
+\cs_new_protected:Npn \@@_pageattr_gput:nnn #1 #2 #3
{
\@@_tree_new:n {Page#1}
\@@_tree_gput:nnn {Page#1}{#2}{#3}
@@ -594,6 +685,11 @@
\@@_tree_gremove:nn { Page } { #1 }
}
+\cs_new_protected:Npn \pdf_thispageattr_gput:nn #1
+ {
+
+ }
+
% push to the register
\cs_new_protected:Npn \@@_pageattr_gpush:n #1 %#1 = page number
{
@@ -1785,4 +1881,34 @@
%</package>
% \end{macrocode}
+% \subsection{lua code for lualatex}
+% \begin{macrocode}
+%<*lua>
+l3kernel= l3kernel or {}
+l3kernel._@@ = l3kernel._@@ or {}
+l3kernel._@@.Page = l3kernel._@@.Page or {}
+local _@@ = l3kernel._@@
+local pdf = pdf
+
+local function _@@_addpageattributes (page,name,value)
+ _@@.Page[page] = _@@.Page[page] or {}
+ _@@.Page[page][name]=value
+end
+
+local function _@@_pushpageattributes (page)
+ local token=""
+ if _@@.Page[page] then
+ for name,value in pairs(_@@.Page[page]) do
+ token = token .. "/"..name.." "..value
+ end
+ end
+ return token
+end
+
+function l3kernel._@@.pageattr_doc (page,name,value) -- tex.count["g__pdf_abspage_int"]
+ _@@_addpageattributes (page,name,value)
+ pdf.setpageattributes(_@@_pushpageattributes (page))
+end
+%</lua>
+% \end{macrocode}
% \PrintIndex
More information about the latex3-commits
mailing list