[latex3-commits] [git/LaTeX3-latex3-pdfresources] backendtest: moved bdc code to dtx (050f3c6)

Ulrike Fischer fischer at troubleshooting-tex.de
Sun Jun 30 23:57:21 CEST 2019


Repository : https://github.com/latex3/pdfresources
On branch  : backendtest
Link       : https://github.com/latex3/pdfresources/commit/050f3c68f892e1ab35ce889ec96735bdea1abe3b

>---------------------------------------------------------------

commit 050f3c68f892e1ab35ce889ec96735bdea1abe3b
Author: Ulrike Fischer <fischer at troubleshooting-tex.de>
Date:   Sun Jun 30 23:57:21 2019 +0200

    moved bdc code to dtx


>---------------------------------------------------------------

050f3c68f892e1ab35ce889ec96735bdea1abe3b
 experiments/bdc-properties.tex | 184 +++--------------------------------------
 pdfresources.dtx               | 165 +++++++++++++++++++++++++++++++++++-
 2 files changed, 172 insertions(+), 177 deletions(-)

diff --git a/experiments/bdc-properties.tex b/experiments/bdc-properties.tex
index 91bd29a..2d44fa1 100644
--- a/experiments/bdc-properties.tex
+++ b/experiments/bdc-properties.tex
@@ -1,10 +1,8 @@
 % !Mode:: "TeX:DE:UTF-8:Main"
 \documentclass{article}
-\usepackage{l3pdf,pdfresources,ifluatex}
-
+\usepackage{l3pdf,pdfresources}
 
 \ExplSyntaxOn
-
 %correct g to c, is already in master ...
 \sys_if_engine_xetex:T
 {
@@ -14,184 +12,24 @@
 
 \pdf_uncompress:
 \ExplSyntaxOff
-\ifluatex
-\usepackage{luacode}
-% the following should latter get in the l3kernel table and be named
-% more sensibly. This here is only for testing
-%\begin{luacode}
-%l3kernel= l3kernel or {}
-%l3kernel.__pdf      = l3kernel.__pdf or {}
-%l3kernel.__pdf.Page = l3kernel.__pdf.Page or {}
-%l3kernel.__pdf.Page.Resources = l3kernel.__pdf.Resources or {}
-%l3kernel.__pdf.Page.Resources.Properties = l3kernel.__pdf.Page.Resources.Properties or {}
-%l3kernel.pdf= l3kernel.pdf or {} -- for "public" functions
-%
-%local Properties= l3kernel.__pdf.Page.Resources.Properties
-%
-%local function __pdf_backend_PageN_Resources_gpush (page)
-% local token=""
-% if Properties[page] then
-%  for name,value in pairs(Properties[page]) do
-%   token = token .. "/"..name.." "..value
-%  end
-%  token = "/Properties <<"..token..">>"
-% end
-% -- add ExtGstate etc here ....
-% return token
-%end
-%
-%-- the function is public, as I probably need it in tagpdf too ...
-%function l3kernel.pdf.Page_Resources_Properties_gput (page,name,value) -- tex.count["g__pdf_abspage_int"]
-% Properties[page] = Properties[page] or {}
-% Properties[page][name]=value
-% pdf.setpageresources(__pdf_backend_PageN_Resources_gpush (page))
-%end
-%
-%\end{luacode}
-\fi
-
-\ExplSyntaxOn
-%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
-
-\bool_if:nT {\sys_if_engine_pdftex_p: && !\sys_if_output_pdf_p: }
- {
-  \cs_set_protected:Npn \__pdf_backend_bdc:nn #1 #2 % #1 eg. Span, #2: object name
-   {
-     \special{ps:~mark~/#1~\__pdf_backend_object_ref:n{#2}~BDC~pdfmark}
-   }
-  \cs_set_protected:Npn \__pdf_backend_emc:
-   {
-    \special{ps:~mark~/EMC~pdfmark} %
-   }
-  \cs_new_protected:Npn \__pdf_backend_PageN_Resources_gpush:n #1 {}
- }
-
-\int_new:N  \g__pdf_backend_name_int
-%xetex has so create the entries in the /Properties manually (like the other backends)
-% use pdfbase special https://chat.stackexchange.com/transcript/message/50832016#50832016
-\sys_if_engine_xetex:T
-{
- \cs_set_protected:Npn \__pdf_backend_bdc:nn #1 #2 % #1 eg. Span, #2: object name
-   {
-     \int_gincr:N \g__pdf_backend_name_int
-     \special{pdf:code~/#1/l3pdf\int_use:N\g__pdf_backend_name_int\c_space_tl BDC}
-     %\special{pdf:content~/#1/l3pdf\int_use:N\g__pdf_backend_name_int\c_space_tl BDC}
-     \special{
-        pdf:put~@resources~
-        <<
-         /Properties~
-          <<
-           /l3pdf\int_use:N\g__pdf_backend_name_int\c_space_tl
-           \__pdf_backend_object_ref:n{#2}
-          >>
-         >>
-       }
-    }
-  \cs_set_protected:Npn \__pdf_backend_emc:
-   {
-    \special{pdf:code~EMC}  %pdfbase
-    %\special{pdf:content~EMC}% accsupp
-   }
-  \cs_new_protected:Npn \__pdf_backend_PageN_Resources_gpush:n #1 {}
-}
 
-% luatex
-\sys_if_engine_luatex:T
-{
- \cs_set_protected:Npn \__pdf_backend_bdc:nn #1 #2 % #1 eg. Span, #2: object name
-   {
-     \int_gincr:N \g__pdf_backend_name_int
-     \exp_args:Nx\__kernel_backend_literal_page:n
-       {/#1 ~ /l3pdf\int_use:N\g__pdf_backend_name_int\c_space_tl BDC}
-     \exp_args:Nx\tex_latelua:D
-      {
-       l3kernel.pdf.Page_Resources_Properties_gput
-        ( tex.count["g__pdf_abspage_int"],
-          "l3pdf\int_use:N\g__pdf_backend_name_int",
-          "\__pdf_backend_object_ref:n{#2}"
-        )
-      }
-   }
-  \cs_set_protected:Npn \__pdf_backend_emc:
-   {
-    \__kernel_backend_literal_page:n { EMC }
-   }
-  \cs_new_protected:Npn \__pdf_backend_PageN_Resources_gpush:n #1 {}
-}
-\makeatletter
-
-% pdflatex is the most complicated as it has to go through the aux ...
-\bool_if:nT {\sys_if_engine_pdftex_p: && \sys_if_output_pdf_p: }
-{
- \cs_set_protected:Npn \__pdf_backend_bdc:nn #1 #2 % #1 eg. Span, #2: object name
-   {
-     \int_gincr:N \g__pdf_backend_name_int
-     \exp_args:Nx\__kernel_backend_literal_page:n
-       {/#1 ~ /l3pdf\int_use:N\g__pdf_backend_name_int\c_space_tl BDC}
-    % code to set the property ....
-    \int_gincr:N\g__pdf_resourceid_int
-    \zref at labelbylist {l3pdf\int_use:N\g__pdf_resourceid_int} {l3pdf}
-    \tl_set:Nx \l__pdf_tmpa_tl
-     {
-      \zref at extractdefault{l3pdf\int_use:N\g__pdf_resourceid_int}
-                          {pdf at abspage}
-                          {0}
-     }
-    \__pdf_tree_new:n    {backend_Page\l__pdf_tmpa_tl/Resources/Properties}
-    \exp_args:Nnx\__pdf_tree_gput:nnn
-     {backend_Page\l__pdf_tmpa_tl/Resources/Properties}
-     {l3pdf\int_use:N\g__pdf_resourceid_int}
-     {\__pdf_backend_object_ref:n{#2}}
-   }
- \cs_set_protected:Npn \__pdf_backend_emc:
-   {
-    \__kernel_backend_literal_page:n { EMC }
-   }
-
- \cs_new_protected:Npn \__pdf_backend_PageN_Resources_gpush:n #1
-  {
-   \exp_args:NNx \tex_global:D \tex_pdfpageresources:D
-   {
-    \prop_if_exist:cT  { \__pdf_tree_prop_name:n  { backend_Page#1/Resources/Properties } }
-     {
-      /Properties~<<
-       \prop_map_function:cN
-        { \__pdf_tree_prop_name:n  { backend_Page#1/Resources/Properties } } \__pdf_dict_item:nn
-       >>
-     }
-    %% add ExtGState etc
-   }
-  }
-}
-
-% for testing here
-  \cs_set_protected:Npn \__pdf_everypage_shipout_code:n #1
-  {
-   \__pdf_backend_PageN_gpush:n { #1 }
-   \__pdf_backend_PageN_Resources_gpush:n { #1 }
-  }
-\ExplSyntaxOff
 \begin{document}
 \ExplSyntaxOn
-\__pdf_backend_object_new:nn   {objA}{dict}
-\__pdf_backend_object_write:nn {objA}{/Type/Artifact}
+\pdf_object_new:nn   {objA}{dict}
+\pdf_object_write:nn {objA}{/Type/Artifact}
 
-\__pdf_backend_object_new:nn   {objB}{dict}
-\__pdf_backend_object_write:nn {objB}{/ActualText(abc)}
+\pdf_object_new:nn   {objB}{dict}
+\pdf_object_write:nn {objB}{/ActualText(abc)}
 
 \vspace*{44\baselineskip}
-\__pdf_backend_bdc:nn {Span}{objA}xxx
-\__pdf_backend_emc:
+\pdf_bdc:nn {Span}{objA}xxx
+\pdf_emc:
 \\
-\__pdf_backend_bdc:nn {Span}{objA}xxx
-\__pdf_backend_emc:
+\pdf_bdc:nn {Span}{objA}xxx
+\pdf_emc:
 \\
-\__pdf_backend_bdc:nn {Span}{objB}xxx
-\__pdf_backend_emc:
+\pdf_bdc:nn {Span}{objB}xxx
+\pdf_emc:
 
 \ExplSyntaxOff
 \end{document} 
\ No newline at end of file
diff --git a/pdfresources.dtx b/pdfresources.dtx
index 4ddc3fc..6312a85 100644
--- a/pdfresources.dtx
+++ b/pdfresources.dtx
@@ -107,8 +107,8 @@
 %    \begin{macrocode}
 %<*package>
 \int_new:N \g_@@_abspage_int
-\int_new:N \g_@@_resourceid_int
-
+\int_new:N \g_@@_backend_resourceid_int
+\int_new:N \g_@@_backend_name_int
 \zref at newlist  {l3pdf}
 \zref at newprop* {pdf at abspage} [0] {\int_use:N\g_@@_abspage_int}
 \zref at addprop  {l3pdf} {pdf at abspage}
@@ -161,6 +161,7 @@
 \cs_new_protected:Npn \@@_everypage_shipout_code:n #1
  {
   \@@_backend_PageN_gpush:n { #1 }
+  \@@_backend_PageN_Resources_gpush:n { #1 }
  }
 \cs_generate_variant:Nn \@@_everypage_shipout_code:n {V}
 \cs_new_protected:Npn \@@_lastpage_shipout_code:
@@ -428,10 +429,10 @@
   \cs_new_protected:Npn \@@_backend_PageN_gput:nn #1 #2
    {
     \int_gincr:N\g_@@_resourceid_int
-    \zref at labelbylist {l3pdf\int_use:N\g_@@_resourceid_int} {l3pdf}
+    \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_@@_resourceid_int}
+      \zref at extractdefault{l3pdf\int_use:N\g_@@_backend_resourceid_int}
                           {pdf at abspage}
                           {0}
      }
@@ -766,6 +767,162 @@
   }
 %</package>
 %    \end{macrocode}
+% \subsection{page resources / Properties and bdc-mark}
+% \begin{NOTE}{UF}
+% we still need a switch for the case that the resource should be added to
+% xform resource instead of a page resources, see pdfbase.sty
+% \end{NOTE}
+% Entries to the /Properties dictionary in the page resources can
+% be added with dvips only through side-effect: if a bdc-mark is created dvips/ghostscript
+% will automatically create the necessary objects and names.
+% To get a sensible abstraction the code does the same for the other backends: There are
+% no public commands to add values to the /Properties dictionary directly, only
+% commands to set BDC-marks.
+% \begin{function}[added = 2019-06-29]
+%   {
+%    \pdf_bdc:nn
+%   }
+%   \begin{syntax}
+%     \pdf_bdc:nn \Arg{tag} \Arg{object name}
+%   \end{syntax}
+%    This command adds a BDC marked content operator to the current page stream.
+%   \meta{tag} is the tag of this operator (without the leading slash),
+%   \meta{object name}  is a the name of an dictionary object reserved with
+%   \cs{pdf_object_new:nn} and filled with \cs{\pdf_object_write:n} with
+%   the properties of the BDC.
+%   \begin{function}[added = 2019-06-30]
+%   {
+%    \pdf_emc:
+%   }
+%   \begin{syntax}
+%     \pdf_emc:
+%   \end{syntax}
+%    This command closes the  BDC marked content operator opened with \cs{pdf_bdc:nn}.
+%    It should be one the same page as the bdc-command.
+%
+%   \begin{verbatim}
+%   \pdf_object_new:nn   {objA}{dict}
+%   \pdf_object_write:nn {objA}{/Type/Artifact}
+%   \pdf_bdc:nn {Span}{objA}
+%   text
+%   \pdf_emc:
+%   \end{verbatim}
+% \end{function}
+% \subsubsection{bcd/Properties, backend code}
+%    \begin{macrocode}
+%<*package>
+% 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
+\bool_if:nT {\sys_if_engine_pdftex_p: && !\sys_if_output_pdf_p: }
+ {
+  \cs_set_protected:Npn \@@_backend_bdc:nn #1 #2 % #1 eg. Span, #2: object name
+   {
+     \special{ps:~mark~/#1~\@@_backend_object_ref:n{#2}~BDC~pdfmark}
+   }
+  \cs_set_protected:Npn \@@_backend_emc:
+   {
+    \special{ps:~mark~/EMC~pdfmark} %
+   }
+  \cs_new_protected:Npn \@@_backend_PageN_Resources_gpush:n #1 {}
+ }
+% xetex has so create the entries in the /Properties manually (like the other backends)
+% use pdfbase special https://chat.stackexchange.com/transcript/message/50832016#50832016
+\sys_if_engine_xetex:T
+{
+ \cs_set_protected:Npn \@@_backend_bdc:nn #1 #2 % #1 eg. Span, #2: object name
+   {
+     \int_gincr:N \g_@@_backend_name_int
+     \special{pdf:code~/#1/l3pdf\int_use:N\g_@@_backend_name_int\c_space_tl BDC}
+     \special{
+        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_emc:
+   {
+    \special{pdf:code~EMC}  %pdfbase
+   }
+  \cs_new_protected:Npn \@@_backend_PageN_Resources_gpush:n #1 {}
+}
+% luatex
+\sys_if_engine_luatex:T
+{
+ \cs_set_protected:Npn \@@_backend_bdc: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}
+     \exp_args:Nx\tex_latelua:D
+      {
+       l3kernel.pdf.Page_Resources_Properties_gput
+        ( tex.count["g_@@_abspage_int"],
+          "l3pdf\int_use:N\g_@@_backend_name_int",
+          "\@@_backend_object_ref:n{#2}"
+        )
+      }
+   }
+  \cs_set_protected:Npn \@@_backend_emc:
+   {
+    \__kernel_backend_literal_page:n { EMC }
+   }
+  \cs_new_protected:Npn \@@_backend_PageN_Resources_gpush:n #1 {}
+}
+
+% pdflatex is the most complicated as it has to go through the aux ...
+% !!! the push command will have to be extended to take other resources too
+\bool_if:nT {\sys_if_engine_pdftex_p: && \sys_if_output_pdf_p: }
+{
+ \cs_set_protected:Npn \@@_backend_bdc: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
+    \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}
+     }
+    \@@_tree_new:n    {backend_Page\l_@@_tmpa_tl/Resources/Properties}
+    \exp_args:Nnx\@@_tree_gput:nnn
+     {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_emc:
+   {
+    \__kernel_backend_literal_page:n { EMC }
+   }
+
+ \cs_new_protected:Npn \@@_backend_PageN_Resources_gpush:n #1
+  {
+   \exp_args:NNx \tex_global:D \tex_pdfpageresources:D
+   {
+    \prop_if_exist:cT  { \@@_tree_prop_name:n  { backend_Page#1/Resources/Properties } }
+     {
+      /Properties~<<
+       \prop_map_function:cN
+        { \@@_tree_prop_name:n  { backend_Page#1/Resources/Properties } } \@@_dict_item:nn
+       >>
+     }
+    %% add ExtGState etc
+   }
+  }
+}
+%</package>
+%    \end{macrocode}
 % ===================================
 %\subsubsection{pdfxform}
 % \begin{NOTE}{UF}





More information about the latex3-commits mailing list