[latex3-commits] [git/LaTeX3-latex3-latex3] master: Extend PDF object creation to streams (4fb3ed2)

Joseph Wright joseph.wright at morningstar2.co.uk
Wed Sep 5 11:23:24 CEST 2018


Repository : https://github.com/latex3/latex3
On branch  : master
Link       : https://github.com/latex3/latex3/commit/4fb3ed236eb766e34777c6b306459550c7d13c5a

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

commit 4fb3ed236eb766e34777c6b306459550c7d13c5a
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Wed Sep 5 10:23:24 2018 +0100

    Extend PDF object creation to streams


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

4fb3ed236eb766e34777c6b306459550c7d13c5a
 l3kernel/l3drivers.dtx                  |  151 ++++++++++++++++++++++++-------
 l3kernel/testfiles/m3expl001.luatex.tlg |    2 +
 l3kernel/testfiles/m3expl001.ptex.tlg   |    6 ++
 l3kernel/testfiles/m3expl001.tlg        |    2 +
 l3kernel/testfiles/m3expl001.uptex.tlg  |    6 ++
 l3kernel/testfiles/m3expl001.xetex.tlg  |    6 ++
 l3kernel/testfiles/m3expl003.luatex.tlg |    2 +
 l3kernel/testfiles/m3expl003.ptex.tlg   |    6 ++
 l3kernel/testfiles/m3expl003.tlg        |    2 +
 l3kernel/testfiles/m3expl003.uptex.tlg  |    6 ++
 l3kernel/testfiles/m3expl003.xetex.tlg  |    6 ++
 11 files changed, 162 insertions(+), 33 deletions(-)

diff --git a/l3kernel/l3drivers.dtx b/l3kernel/l3drivers.dtx
index 29dd26a..f1c2a28 100644
--- a/l3kernel/l3drivers.dtx
+++ b/l3kernel/l3drivers.dtx
@@ -478,8 +478,7 @@
 %     \cs{driver_pdf_object_new:n} \Arg{name} \Arg{type}
 %   \end{syntax}
 %   Declares \meta{name} as a PDF object. The \type{type} should be one of
-%   |array| or |dict|. (Note that streams are objects but are handled
-%   separately.)
+%   |array| or |dict|, |fstream| or |stream|.
 % \end{function}
 %
 % \begin{function}[EXP]{\driver_pdf_object_ref:n}
@@ -501,6 +500,10 @@
 %     \item[\texttt{array}] A space-separated list of values
 %     \item[\texttt{dict}] Key--value pairs in the form
 %       \texttt{/\meta{key} \meta{value}}
+%     \item[\texttt{fstream}] Two brace groups: \meta{content} and
+%       \meta{additional attributes}
+%     \item[\texttt{stream}] Two brace groups: \meta{content} and
+%       \meta{additional attributes}
 %   \end{itemize}
 % \end{function}
 %
@@ -1421,38 +1424,72 @@
 % \end{macro}
 %
 % \begin{macro}{\driver_pdf_object_write:nn}
+% \begin{macro}
+%   {
+%     \@@_pdf_object_write_array:nn ,
+%     \@@_pdf_object_write_dict:nn  ,
+%     \@@_pdf_object_write_stream:nn
+%   }
+% \begin{macro}{\@@_pdf_object_write_stream:nnn}
 %   This is where we choose the actual type: some work to get things
 %   right.
 %    \begin{macrocode}
 \cs_new_protected:Npn \driver_pdf_object_write:nn #1#2
   {
-    \@@_literal:x
+    \@@_literal_postscript:x
       {
-        ps:mark ~ /_objdef ~ \driver_pdf_object_ref:n {#1} ~
-        /type / \prop_item:Nn \g_@@_pdf_object_prop {#1}
+        mark ~ /_objdef ~ \driver_pdf_object_ref:n {#1} ~
+        /type
+        \str_case_e:nn
+          { \prop_item:Nn \g_@@_pdf_object_prop {#1} }
+          {
+            { array }   { /array }
+            { dict }    { /dict }
+            { fstream } { /stream }
+            { stream }  { /stream }
+          }
         /OBJ ~ pdfmark
       }
-    \@@_literal:x
+    \use:c
+      { @@_pdf_object_write_ \prop_item:Nn \g_@@_pdf_object_prop {#1} :nn }
+      {#1} {#2}
+  }
+\cs_new_protected:Npn \@@_pdf_object_write_array:nn #1#2
+  {
+    \@@_literal_postscript:x
       {
-        ps:mark ~ \driver_pdf_object_ref:n {#1} ~
-          \str_case_e:nn
-            { \prop_item:Nn \g_@@_pdf_object_prop {#1} }
-            {
-              { array }
-                {
-                  [ ~ \exp_not:n {#2} ~ ]
-                  /PUTINTERVAL ~ pdfmark
-                }
-              { dict }
-                {
-                  << ~ \exp_not:n {#2} ~ >>
-                  /PUT ~ pdfmark
-                }
-            }
+        mark ~ \driver_pdf_object_ref:n {#1} ~
+          [ ~ \exp_not:n {#2} ~ ] ~ /PUTINTERVAL ~ pdfmark
+      }
+  }
+\cs_new_protected:Npn \@@_pdf_object_write_dict:nn #1#2
+  {
+    \@@_literal_postscript:x
+      {
+        mark ~ \driver_pdf_object_ref:n {#1} ~
+          << ~ \exp_not:n {#2} ~ >> ~ /PUT ~ pdfmark
+      }
+  }
+\cs_new_protected:Npn \@@_pdf_object_write_stream:nn #1#2
+  {
+    \exp_args:Nx
+      \@@_pdf_object_write_stream:nnn
+        { \driver_pdf_object_ref:n {#1} }
+        #2
+  }
+\cs_new_protected:Npn \@@_pdf_object_write_stream:nnn #1#2#3
+  {
+    \@@_literal_postscript:n
+      {
+        [nobreak] ~
+        mark ~ #1 ~ ( #3 ) ~ /PUT ~ pdfmark ~
+        mark ~ #1 ~ << #2 >> ~ /PUT ~ pdfmark
       }
   }
 %    \end{macrocode}
 % \end{macro}
+% \end{macro}
+% \end{macro}
 %
 % \begin{macro}{\driver_pdf_compresslevel:n}
 % \begin{macro}{\driver_pdf_objects_enable:, \driver_pdf_objects_disable:}
@@ -1756,9 +1793,9 @@
     {
       \cs_new_protected:Npx \driver_pdf_object_new:nn ##1##2
         {
-          #1 reserveobjnum
+          #1 reserveobjnum ~
           \int_const:cn
-            { g_@@_pdf_object_ \exp_not:N \tl_to_str:n {#1} _int }
+            { g_@@_pdf_object_ \exp_not:N \tl_to_str:n {##1} _int }
             {#2}
           \prop_gput:Nnn \exp_not:N \g_@@_pdf_object_prop {##1} {##2}
         }
@@ -1778,6 +1815,7 @@
 % \end{macro}
 %
 % \begin{macro}{\driver_pdf_object_write:nn}
+% \begin{macro}[EXP]{\@@_exp_not_i:nn, \@@_exp_not_ii:nn}
 %   Writing the data needs a little information about the structure of the
 %   object.
 %    \begin{macrocode}
@@ -1788,12 +1826,22 @@
         {
           \tex_immediate:D #1 useobjnum ~
           \int_use:c
-            { g_@@_pdf_object_ \tl_to_str:n {#1} _int }
+            { g_@@_pdf_object_ \tl_to_str:n {##1} _int }
             \str_case_e:nn
               { \prop_item:Nn \g_@@_pdf_object_prop {##1} }
               {
-                { array } { { [ ~ ##2 ~ ] } }
-                { dict }  { { << ~ ##2 ~ >> } }
+                { array } { { [ ~ \exp_not:n {##2} ~ ] } }
+                { dict }  { { << ~ \exp_not:n {##2} ~ >> } }
+                { fstream }
+                  {
+                    stream ~ attr ~ { \@@_exp_not_i:nn ##2 } ~
+                      file ~ { \@@_exp_not_ii:nn ##2 }
+                  }
+                { stream }
+                  {
+                    stream ~ attr ~ { \@@_exp_not_i:nn ##2 } ~ 
+                      { \@@_exp_not_ii:nn ##2 }
+                  }
               }
         }
     }
@@ -1801,8 +1849,11 @@
     { \@@_tmp:w { \tex_pdfextension:D obj ~ } }
     { \@@_tmp:w { \tex_pdfobj:D } }
 \group_end:
+\cs_new:Npn \@@_exp_not_i:nn #1#2 { \exp_not:n {#1} }
+\cs_new:Npn \@@_exp_not_ii:nn #1#2 { \exp_not:n {#2} }
 %    \end{macrocode}
 % \end{macro}
+% \end{macro}
 %
 % \subsubsection{PDF Structure}
 %
@@ -2109,23 +2160,57 @@
 % \end{macro}
 %
 % \begin{macro}{\driver_pdf_object_write:nn}
-%   This is where we choose the actual type
+% \begin{macro}{\@@_pdf_object_write:nnn}
+% \begin{macro}
+%   {
+%     \@@_pdf_object_write_array:nn   ,
+%     \@@_pdf_object_write_dict:nn    ,
+%     \@@_pdf_object_write_fstream:nn ,
+%     \@@_pdf_object_write_stream:nn
+%   }
+% \begin{macro}{\@@_pdf_object_write_stream:nnnn}
+%   This is where we choose the actual type.
 %    \begin{macrocode}
 \cs_new_protected:Npn \driver_pdf_object_write:nn #1#2
   {
+    \exp_args:Nx \@@_pdf_object_write:nnn
+      { \prop_item:Nn \g_@@_pdf_object_prop {#1} } {#1} {#2}
+  }
+\cs_new_protected:Npn \@@_pdf_object_write:nnn #1#2#3
+  { \use:c { @@_pdf_object_write_ #1 :nn } {#2} {#3} }
+\cs_new_protected:Npn \@@_pdf_object_write_array:nn #1#2
+  {
     \@@_literal:x
       {
         pdf:obj ~ \driver_pdf_object_ref:n {#1} ~
-        \str_case_e:nn
-          { \prop_item:Nn \g_@@_pdf_object_prop {#1} }
-          {
-            { array } { { [ ~ \exp_not:n {#2} ~ ] } }
-            { dict }  { { << ~ \exp_not:n {#2} ~ >> } }
-          }
+          [ ~ \exp_not:n {#2} ~ ]
+      }
+  }
+\cs_new_protected:Npn \@@_pdf_object_write_dict:nn #1#2
+  {
+    \@@_literal:x
+      {
+        pdf:obj ~ \driver_pdf_object_ref:n {#1} ~
+          << ~ \exp_not:n {#2} ~ >>
+      }
+  }
+\cs_new_protected:Npn \@@_pdf_object_write_fstream:nn #1#2
+  { \@@_pdf_object_write_stream:nnnn { f } {#1} #2 }
+\cs_new_protected:Npn \@@_pdf_object_write_stream:nn #1#2
+  { \@@_pdf_object_write_stream:nnnn { } {#1} #2 }
+\cs_new_protected:Npn \@@_pdf_object_write_stream:nnnn #1#2#3#4
+  {
+    \@@_literal:x
+      {
+        pdf: #1 stream ~ \driver_pdf_object_ref:n {#2} ~
+          ( \exp_not:n {#4} ) ~ << \exp_not:n {#3} >>
+        
       }
   }
 %    \end{macrocode}
 % \end{macro}
+% \end{macro}
+% \end{macro}
 %
 % \subsubsection{PDF Structure}
 %
diff --git a/l3kernel/testfiles/m3expl001.luatex.tlg b/l3kernel/testfiles/m3expl001.luatex.tlg
index 72838c2..d8c1d1f 100644
--- a/l3kernel/testfiles/m3expl001.luatex.tlg
+++ b/l3kernel/testfiles/m3expl001.luatex.tlg
@@ -6148,6 +6148,8 @@ Defining \g__driver_pdf_object_prop on line ...
 Defining \driver_pdf_object_new:nn on line ...
 Defining \driver_pdf_object_ref:n on line ...
 Defining \driver_pdf_object_write:nn on line ...
+Defining \__driver_exp_not_i:nn on line ...
+Defining \__driver_exp_not_ii:nn on line ...
 Defining \driver_pdf_compresslevel:n on line ...
 Defining \driver_pdf_objects_enable: on line ...
 Defining \driver_pdf_objects_disable: on line ...
diff --git a/l3kernel/testfiles/m3expl001.ptex.tlg b/l3kernel/testfiles/m3expl001.ptex.tlg
index 47b96fc..14bf510 100644
--- a/l3kernel/testfiles/m3expl001.ptex.tlg
+++ b/l3kernel/testfiles/m3expl001.ptex.tlg
@@ -6183,6 +6183,12 @@ Defining \g__driver_pdf_object_prop on line ...
 Defining \driver_pdf_object_new:nn on line ...
 Defining \driver_pdf_object_ref:n on line ...
 Defining \driver_pdf_object_write:nn on line ...
+Defining \__driver_pdf_object_write:nnn on line ...
+Defining \__driver_pdf_object_write_array:nn on line ...
+Defining \__driver_pdf_object_write_dict:nn on line ...
+Defining \__driver_pdf_object_write_fstream:nn on line ...
+Defining \__driver_pdf_object_write_stream:nn on line ...
+Defining \__driver_pdf_object_write_stream:nnnn on line ...
 Defining \driver_pdf_compresslevel:n on line ...
 Defining \driver_pdf_objects_enable: on line ...
 Defining \driver_pdf_objects_disable: on line ...
diff --git a/l3kernel/testfiles/m3expl001.tlg b/l3kernel/testfiles/m3expl001.tlg
index 17c92e8..334e562 100644
--- a/l3kernel/testfiles/m3expl001.tlg
+++ b/l3kernel/testfiles/m3expl001.tlg
@@ -6386,6 +6386,8 @@ Defining \g__driver_pdf_object_prop on line ...
 Defining \driver_pdf_object_new:nn on line ...
 Defining \driver_pdf_object_ref:n on line ...
 Defining \driver_pdf_object_write:nn on line ...
+Defining \__driver_exp_not_i:nn on line ...
+Defining \__driver_exp_not_ii:nn on line ...
 Defining \driver_pdf_compresslevel:n on line ...
 Defining \driver_pdf_objects_enable: on line ...
 Defining \driver_pdf_objects_disable: on line ...
diff --git a/l3kernel/testfiles/m3expl001.uptex.tlg b/l3kernel/testfiles/m3expl001.uptex.tlg
index a39973a..29ff463 100644
--- a/l3kernel/testfiles/m3expl001.uptex.tlg
+++ b/l3kernel/testfiles/m3expl001.uptex.tlg
@@ -6381,6 +6381,12 @@ Defining \g__driver_pdf_object_prop on line ...
 Defining \driver_pdf_object_new:nn on line ...
 Defining \driver_pdf_object_ref:n on line ...
 Defining \driver_pdf_object_write:nn on line ...
+Defining \__driver_pdf_object_write:nnn on line ...
+Defining \__driver_pdf_object_write_array:nn on line ...
+Defining \__driver_pdf_object_write_dict:nn on line ...
+Defining \__driver_pdf_object_write_fstream:nn on line ...
+Defining \__driver_pdf_object_write_stream:nn on line ...
+Defining \__driver_pdf_object_write_stream:nnnn on line ...
 Defining \driver_pdf_compresslevel:n on line ...
 Defining \driver_pdf_objects_enable: on line ...
 Defining \driver_pdf_objects_disable: on line ...
diff --git a/l3kernel/testfiles/m3expl001.xetex.tlg b/l3kernel/testfiles/m3expl001.xetex.tlg
index 44ad144..55b3714 100644
--- a/l3kernel/testfiles/m3expl001.xetex.tlg
+++ b/l3kernel/testfiles/m3expl001.xetex.tlg
@@ -6146,6 +6146,12 @@ Defining \g__driver_pdf_object_prop on line ...
 Defining \driver_pdf_object_new:nn on line ...
 Defining \driver_pdf_object_ref:n on line ...
 Defining \driver_pdf_object_write:nn on line ...
+Defining \__driver_pdf_object_write:nnn on line ...
+Defining \__driver_pdf_object_write_array:nn on line ...
+Defining \__driver_pdf_object_write_dict:nn on line ...
+Defining \__driver_pdf_object_write_fstream:nn on line ...
+Defining \__driver_pdf_object_write_stream:nn on line ...
+Defining \__driver_pdf_object_write_stream:nnnn on line ...
 Defining \driver_pdf_compresslevel:n on line ...
 Defining \driver_pdf_objects_enable: on line ...
 Defining \driver_pdf_objects_disable: on line ...
diff --git a/l3kernel/testfiles/m3expl003.luatex.tlg b/l3kernel/testfiles/m3expl003.luatex.tlg
index 72838c2..d8c1d1f 100644
--- a/l3kernel/testfiles/m3expl003.luatex.tlg
+++ b/l3kernel/testfiles/m3expl003.luatex.tlg
@@ -6148,6 +6148,8 @@ Defining \g__driver_pdf_object_prop on line ...
 Defining \driver_pdf_object_new:nn on line ...
 Defining \driver_pdf_object_ref:n on line ...
 Defining \driver_pdf_object_write:nn on line ...
+Defining \__driver_exp_not_i:nn on line ...
+Defining \__driver_exp_not_ii:nn on line ...
 Defining \driver_pdf_compresslevel:n on line ...
 Defining \driver_pdf_objects_enable: on line ...
 Defining \driver_pdf_objects_disable: on line ...
diff --git a/l3kernel/testfiles/m3expl003.ptex.tlg b/l3kernel/testfiles/m3expl003.ptex.tlg
index 47b96fc..14bf510 100644
--- a/l3kernel/testfiles/m3expl003.ptex.tlg
+++ b/l3kernel/testfiles/m3expl003.ptex.tlg
@@ -6183,6 +6183,12 @@ Defining \g__driver_pdf_object_prop on line ...
 Defining \driver_pdf_object_new:nn on line ...
 Defining \driver_pdf_object_ref:n on line ...
 Defining \driver_pdf_object_write:nn on line ...
+Defining \__driver_pdf_object_write:nnn on line ...
+Defining \__driver_pdf_object_write_array:nn on line ...
+Defining \__driver_pdf_object_write_dict:nn on line ...
+Defining \__driver_pdf_object_write_fstream:nn on line ...
+Defining \__driver_pdf_object_write_stream:nn on line ...
+Defining \__driver_pdf_object_write_stream:nnnn on line ...
 Defining \driver_pdf_compresslevel:n on line ...
 Defining \driver_pdf_objects_enable: on line ...
 Defining \driver_pdf_objects_disable: on line ...
diff --git a/l3kernel/testfiles/m3expl003.tlg b/l3kernel/testfiles/m3expl003.tlg
index 17c92e8..334e562 100644
--- a/l3kernel/testfiles/m3expl003.tlg
+++ b/l3kernel/testfiles/m3expl003.tlg
@@ -6386,6 +6386,8 @@ Defining \g__driver_pdf_object_prop on line ...
 Defining \driver_pdf_object_new:nn on line ...
 Defining \driver_pdf_object_ref:n on line ...
 Defining \driver_pdf_object_write:nn on line ...
+Defining \__driver_exp_not_i:nn on line ...
+Defining \__driver_exp_not_ii:nn on line ...
 Defining \driver_pdf_compresslevel:n on line ...
 Defining \driver_pdf_objects_enable: on line ...
 Defining \driver_pdf_objects_disable: on line ...
diff --git a/l3kernel/testfiles/m3expl003.uptex.tlg b/l3kernel/testfiles/m3expl003.uptex.tlg
index a39973a..29ff463 100644
--- a/l3kernel/testfiles/m3expl003.uptex.tlg
+++ b/l3kernel/testfiles/m3expl003.uptex.tlg
@@ -6381,6 +6381,12 @@ Defining \g__driver_pdf_object_prop on line ...
 Defining \driver_pdf_object_new:nn on line ...
 Defining \driver_pdf_object_ref:n on line ...
 Defining \driver_pdf_object_write:nn on line ...
+Defining \__driver_pdf_object_write:nnn on line ...
+Defining \__driver_pdf_object_write_array:nn on line ...
+Defining \__driver_pdf_object_write_dict:nn on line ...
+Defining \__driver_pdf_object_write_fstream:nn on line ...
+Defining \__driver_pdf_object_write_stream:nn on line ...
+Defining \__driver_pdf_object_write_stream:nnnn on line ...
 Defining \driver_pdf_compresslevel:n on line ...
 Defining \driver_pdf_objects_enable: on line ...
 Defining \driver_pdf_objects_disable: on line ...
diff --git a/l3kernel/testfiles/m3expl003.xetex.tlg b/l3kernel/testfiles/m3expl003.xetex.tlg
index 44ad144..55b3714 100644
--- a/l3kernel/testfiles/m3expl003.xetex.tlg
+++ b/l3kernel/testfiles/m3expl003.xetex.tlg
@@ -6146,6 +6146,12 @@ Defining \g__driver_pdf_object_prop on line ...
 Defining \driver_pdf_object_new:nn on line ...
 Defining \driver_pdf_object_ref:n on line ...
 Defining \driver_pdf_object_write:nn on line ...
+Defining \__driver_pdf_object_write:nnn on line ...
+Defining \__driver_pdf_object_write_array:nn on line ...
+Defining \__driver_pdf_object_write_dict:nn on line ...
+Defining \__driver_pdf_object_write_fstream:nn on line ...
+Defining \__driver_pdf_object_write_stream:nn on line ...
+Defining \__driver_pdf_object_write_stream:nnnn on line ...
 Defining \driver_pdf_compresslevel:n on line ...
 Defining \driver_pdf_objects_enable: on line ...
 Defining \driver_pdf_objects_disable: on line ...





More information about the latex3-commits mailing list