Skip to content

Commit

Permalink
moving bdc code to backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Ulrike Fischer committed Jul 4, 2020
1 parent 748cd0a commit f71baa6
Show file tree
Hide file tree
Showing 2 changed files with 355 additions and 354 deletions.
355 changes: 355 additions & 0 deletions l3backend-pdf-extra.dtx
Expand Up @@ -568,6 +568,361 @@
% \end{macrocode}
% \end{macro}
% \end{macro}
% \subsubsection{Page resources /Properties + BDC operators}
% \begin{macro}
% {
% \@@_backend_bdc:nn,
% \@@_backend_bdc_obj:nn,
% \@@_backend_bdc_obj:n,
% \@@_backend_bmc:n,
% \@@_backend_emc:,
% \@@_backend_PageResources_gpush:n
% }
% \cs{@@_backend_bdc:nn}, \cs{@@_backend_bdc_obj:nn}, \cs{@@_backend_bdc_obj:n},
% \cs{@@_backend_bmc:n} and \cs{@@_backend_emc:}
% are the backend command that
% create the bdc/emc marker and store the properties.
% \cs{@@_backend_PageResources_gpush:n} outputs the /Properties and/or the other
% resources for the current page.
% \begin{macrocode}
% pdftex and luatex (and perhaps dvips ...) need to know if there are in a
% xform stream ...
%<*drivers>
\bool_new:N \l_@@_backend_xform_bool
%</drivers>
%<*dvips>
% dvips is easy: create an object, and reference it in the bdc
% ghostscript will then automatically replace it by a name
% and add the name to the /Properties dict
% special variant von accsupp
% https://chat.stackexchange.com/transcript/message/50831812#50831812
%
\cs_set_protected:Npn \@@_backend_bdc:nn #1 #2 % #1 eg. Span, #2: dict_content
{
\__pdf_backend_pdfmark:x{/#1~<<#2>>~/BDC}
}
\cs_set_protected:Npn \@@_backend_bdc_obj:nn #1 #2 % #1 eg. Span, #2: object name
{
\__pdf_backend_pdfmark:x{/#1~\@@_backend_object_ref:n{#2}~/BDC}
}
\cs_set_protected:Npn \@@_backend_bdc_obj:n #1 % #1 eg. Span,
{
\__pdf_backend_pdfmark:x{/#1~\@@_backend_object_last:~/BDC}
}
\cs_set_protected:Npn \@@_backend_emc:
{
\__pdf_backend_pdfmark:n{/EMC} %
}
\cs_set_protected:Npn \@@_backend_bmc:n #1
{
\__pdf_backend_pdfmark:n{/#1~/BMC} %
}
\cs_new_protected:Npn \@@_backend_PageResources_gpush:n #1 {}

%</dvips>
% xetex has to create the entries in the /Properties manually
% (like the other backends)
% use pdfbase special
% https://chat.stackexchange.com/transcript/message/50832016#50832016
% the property is added to xform resources automatically,
% no need to worry about it.
%<*dvipdfmx|xdvipdfmx>
\cs_set_protected:Npn \@@_backend_bdc_obj:nn #1 #2 % #1 eg. Span, #2: object name
{
\int_gincr:N \g_@@_backend_name_int
\__kernel_backend_literal:x
{
pdf:code~/#1/l3pdf\int_use:N\g_@@_backend_name_int\c_space_tl BDC
}
\__kernel_backend_literal:x
{
pdf:put~@resources~
<<
/Properties~
<<
/l3pdf\int_use:N\g_@@_backend_name_int\c_space_tl
\@@_backend_object_ref:n { #2 }
>>
>>
}
}
\cs_set_protected:Npn \@@_backend_bdc_obj:n #1 % #1 eg. Span
{
\int_gincr:N \g_@@_backend_name_int
\__kernel_backend_literal:x
{
pdf:code~/#1/l3pdf\int_use:N\g_@@_backend_name_int\c_space_tl BDC
}
\__kernel_backend_literal:x
{
pdf:put~@resources~
<<
/Properties~
<<
/l3pdf\int_use:N\g_@@_backend_name_int\c_space_tl
\@@_backend_object_last:
>>
>>
}
}
\cs_set_protected:Npn \@@_backend_bmc:n #1
{
\__kernel_backend_literal:n {pdf:code~/#1~BMC} %pdfbase
}

%this require management
\cs_set_protected:Npn \@@_backend_bdc_contobj:nn #1 #2
{
\pdf_object_now:nn { dict }{ #2 }
\@@_backend_bdc_obj:n { #1 }
}

\cs_set_protected:Npn \@@_backend_bdc_contstream:nn #1 #2
{
\__kernel_backend_literal:n {pdf:code~ /#1~<<#2>>~BDC }
}

\cs_set_protected:Npn \@@_backend_bdc:nn #1 #2
{
\bool_if:NTF \g_@@_Core_active_bool
{\cs_gset_eq:NN \@@_backend_bdc:nn \@@_backend_bdc_contobj:nn}
{\cs_gset_eq:NN \@@_backend_bdc:nn \@@_backend_bdc_contstream:nn}
\@@_backend_bdc:nn {#1}{#1}
}
\cs_set_protected:Npn \@@_backend_emc:
{
\__kernel_backend_literal:n {pdf:code~EMC} %pdfbase
}
% properties are handled automatically, but the other resources should be added
% at shipout
\cs_new_protected:Npn \@@_backend_PageResources_gpush:n #1
{
\clist_map_inline:Nn \c_@@_backend_PageResources_clist
{
\prop_if_empty:cF { \pdfdict_gname:n {Core/Page/Resources/##1} }
{
\__kernel_backend_literal:x
{
pdf:put~@resources~
<</##1~\@@_backend_object_ref:n {Page/Resources/##1}>>
}
}
}
}
%</dvipdfmx|xdvipdfmx>
% luatex + pdftex
%<*pdfmode>
\sys_if_engine_luatex:T
{
\cs_set_protected:Npn \@@_backend_bdc_obj:nn #1 #2 % #1 eg. Span, #2: object name
{
\int_gincr:N \g_@@_backend_name_int
\exp_args:Nx\__kernel_backend_literal_page:n
{ /#1 ~ /l3pdf\int_use:N\g_@@_backend_name_int\c_space_tl BDC }
\bool_if:NTF \l_@@_backend_xform_bool
{
\exp_args:Nnx\pdfdict_gput:nnn
{ Core/Xform/Resources/Properties }
{ l3pdf\int_use:N\g_@@_backend_name_int }
{ \@@_backend_object_ref:n { #2 } }
}
{
\exp_args:Nx \tex_latelua:D
{
l3kernel.pdf.Page_Resources_Properties_gput
(
tex.count["g_shipout_readonly_int"],
"l3pdf\int_use:N\g_@@_backend_name_int",
"\@@_backend_object_ref:n { #2 }"
)
}
}
}
\cs_set_protected:Npn \@@_backend_bdc_obj:n #1% #1 eg. Span
{
\int_gincr:N \g_@@_backend_name_int
\exp_args:Nx\__kernel_backend_literal_page:n
{ /#1 ~ /l3pdf\int_use:N\g_@@_backend_name_int\c_space_tl BDC }
\bool_if:NTF \l_@@_backend_xform_bool
{
\exp_args:Nnx\pdfdict_gput:nnn %no handler needed
{ Core/Xform/Resources/Properties }
{ l3pdf\int_use:N\g_@@_backend_name_int }
{ \@@_backend_object_last: }
}
{
\exp_args:Nx \tex_latelua:D
{
l3kernel.pdf.Page_Resources_Properties_gput
(
tex.count["g_shipout_readonly_int"],
"l3pdf\int_use:N\g_@@_backend_name_int",
"\@@_backend_object_last:"
)
}
}
}
\cs_set_protected:Npn \@@_backend_bmc:n #1
{
\__kernel_backend_literal_page:n { /#1~BMC }
}
\cs_set_protected:Npn \@@_backend_bdc_contobj:nn #1 #2
{
\pdf_object_now:nn { dict } { #2 }
\@@_backend_bdc_obj:n { #1 }
}
\cs_set_protected:Npn \@@_backend_bdc_contstream:nn #1 #2
{
\__kernel_backend_literal_page:n { /#1~<<#2>>~BDC }
}
\cs_set_protected:Npn \@@_backend_bdc:nn #1 #2
{
\bool_if:NTF \g_@@_Core_active_bool
{\cs_gset_eq:NN \@@_backend_bdc:nn \@@_backend_bdc_contobj:nn}
{\cs_gset_eq:NN \@@_backend_bdc:nn \@@_backend_bdc_contstream:nn}
\@@_backend_bdc:nn {#1}{#1}
}
\cs_set_protected:Npn \@@_backend_emc:
{
\__kernel_backend_literal_page:n { EMC }
}

\cs_new_protected:Npn \@@_backend_PageResources_gpush:n #1 {}
}

% pdflatex is the most complicated as it has to go through the aux ...
% the push command is extended to take other resources too
\sys_if_engine_pdftex:T
{
\cs_set_protected:Npn \@@_backend_bdc_obj:nn #1 #2 % #1 eg. Span, #2: object name
{
\int_gincr:N \g_@@_backend_name_int
\exp_args:Nx\__kernel_backend_literal_page:n
{ /#1 ~ /l3pdf\int_use:N\g_@@_backend_name_int\c_space_tl BDC }
% code to set the property ....
\int_gincr:N\g_@@_backend_resourceid_int
\bool_if:NTF \l_@@_backend_xform_bool
{
\exp_args:Nnxx\pdfdict_gput:nnn %no handler needed
{ Core/Xform/Resources/Properties }
{ l3pdf\int_use:N\g_@@_backend_resourceid_int }
{ \@@_backend_object_ref:n { #2 } }
}
{
\zref@labelbylist
{ l3pdf\int_use:N\g_@@_backend_resourceid_int }
{ l3pdf }
\tl_set:Nx \l_@@_tmpa_tl
{
\zref@extractdefault
{ l3pdf\int_use:N\g_@@_backend_resourceid_int }
{pdf@abspage}
{0}
}
\pdfdict_if_gexist:nF { Core/backend_Page\l_@@_tmpa_tl/Resources/Properties }
{
\pdfdict_gnew:n { Core/backend_Page\l_@@_tmpa_tl/Resources/Properties }
}
\exp_args:Nnxx\pdfdict_gput:nnn
{ Core/backend_Page\l_@@_tmpa_tl/Resources/Properties }
{ l3pdf\int_use:N\g_@@_backend_resourceid_int }
{ \@@_backend_object_ref:n{#2} }
}
}
\cs_set_protected:Npn \@@_backend_bdc_obj:n #1% #1 eg. Span
{
\int_gincr:N \g_@@_backend_name_int
\exp_args:Nx\__kernel_backend_literal_page:n
{ /#1 ~ /l3pdf\int_use:N\g_@@_backend_name_int\c_space_tl BDC }
% code to set the property ....
\int_gincr:N\g_@@_backend_resourceid_int
\bool_if:NTF \l_@@_backend_xform_bool
{
\exp_args:Nnxx\pdfdict_gput:nnn
{ Core/Xform/Resources/Properties }
{ l3pdf\int_use:N\g_@@_backend_resourceid_int }
{ \@@_backend_object_last: }
}
{
\zref@labelbylist
{ l3pdf\int_use:N\g_@@_backend_resourceid_int }
{ l3pdf }
\tl_set:Nx \l_@@_tmpa_tl
{
\zref@extractdefault
{ l3pdf\int_use:N\g_@@_backend_resourceid_int }
{pdf@abspage}
{0}
}
\pdfdict_if_gexist:nF { Core/backend_Page\l_@@_tmpa_tl/Resources/Properties }
{
\pdfdict_gnew:n { Core/backend_Page\l_@@_tmpa_tl/Resources/Properties }
}
\exp_args:Nnxx\pdfdict_gput:nnn
{ Core/backend_Page\l_@@_tmpa_tl/Resources/Properties }
{ l3pdf\int_use:N\g_@@_backend_resourceid_int }
{ \@@_backend_object_last: }
%\pdfdict_show:n { backend_Page\l_@@_tmpa_tl/Resources/Properties }
}
}
\cs_set_protected:Npn \@@_backend_bmc:n #1
{
\__kernel_backend_literal_page:n { /#1~BMC }
}
\cs_set_protected:Npn \@@_backend_bdc_contobj:nn #1 #2
{
\pdf_object_now:nn { dict } { #2 }
\@@_backend_bdc_obj:n { #1 }
}
\cs_set_protected:Npn \@@_backend_bdc_contstream:nn #1 #2
{
\__kernel_backend_literal_page:n { /#1~<<#2>>~BDC }
}
\cs_set_protected:Npn \@@_backend_bdc:nn #1 #2
{
\bool_if:NTF \g_@@_Core_active_bool
{\cs_gset_eq:NN \@@_backend_bdc:nn \@@_backend_bdc_contobj:nn}
{\cs_gset_eq:NN \@@_backend_bdc:nn \@@_backend_bdc_contstream:nn}
\@@_backend_bdc:nn {#1}{#1}
}
\cs_set_protected:Npn \@@_backend_emc:
{
\__kernel_backend_literal_page:n { EMC }
}

\cs_new:Npn \@@_backend_PageResources_gpush_aux:n #1 %#1 ExtGState etc
{
\prop_if_empty:cF
{ \pdfdict_gname:n {Core/Page/Resources/#1} }
{
\pdfdict_item:ne { #1 }{ \pdf_object_ref:n {Page/Resources/#1}}
}
}

\cs_new_protected:Npn \@@_backend_PageResources_gpush:n #1
{
\exp_args:NNx \tex_global:D \tex_pdfpageresources:D
{
\prop_if_exist:cT
{ \pdfdict_gname:n { Core/backend_Page#1/Resources/Properties } }
{
/Properties~
<<
\prop_map_function:cN
{ \pdfdict_gname:n { Core/backend_Page#1/Resources/Properties } }
\pdfdict_item:ne
>>
}
%% add ExtGState etc
\clist_map_function:NN
\c_@@_backend_PageResources_clist
\@@_backend_PageResources_gpush_aux:n
}
}
}
%</pdfmode>
% \end{macrocode}
% \end{macro}
% \subsection{\enquote{Catalog} \& subdirectories (pdfcatalog) }
% The backend command is already in the driver:
% \cs{@@_backend_catalog_gput:nn}
Expand Down

0 comments on commit f71baa6

Please sign in to comment.