[latex3-commits] [git/LaTeX3-latex3-latex3] gh1191: Add "pdf-attr" key to l3graphics (8a267d2b1)

Joseph Wright joseph.wright at morningstar2.co.uk
Wed Apr 12 17:41:50 CEST 2023


Repository : https://github.com/latex3/latex3
On branch  : gh1191
Link       : https://github.com/latex3/latex3/commit/8a267d2b132218201ff14491eb7a5ecae7047ff2

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

commit 8a267d2b132218201ff14491eb7a5ecae7047ff2
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Wed Apr 12 16:41:50 2023 +0100

    Add "pdf-attr" key to l3graphics


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

8a267d2b132218201ff14491eb7a5ecae7047ff2
 l3backend/CHANGELOG.md                   |  3 ++
 l3backend/l3backend-graphics.dtx         | 55 +++++++++++++++++---------------
 l3experimental/CHANGELOG.md              |  3 ++
 l3experimental/l3graphics/l3graphics.dtx |  8 +++++
 4 files changed, 43 insertions(+), 26 deletions(-)

diff --git a/l3backend/CHANGELOG.md b/l3backend/CHANGELOG.md
index 82228400e..992b6ce5f 100644
--- a/l3backend/CHANGELOG.md
+++ b/l3backend/CHANGELOG.md
@@ -6,6 +6,9 @@ this project uses date-based 'snapshot' version identifiers.
 
 ## [Unreleased]
 
+### Changed
+- Pass additional attributes when loading PDF graphics
+
 ## [2023-03-30]
 
 ### Changed
diff --git a/l3backend/l3backend-graphics.dtx b/l3backend/l3backend-graphics.dtx
index 97c97536f..228ca0db8 100644
--- a/l3backend/l3backend-graphics.dtx
+++ b/l3backend/l3backend-graphics.dtx
@@ -184,7 +184,8 @@
 \cs_new_protected:Npn \@@_backend_getbb_jpg:n #1
   {
     \int_zero:N \l_@@_page_int
-    \tl_clear:N \l_@@_pagebox_tl
+    \tl_clear:N m\l_@@_pagebox_tl
+    \str_clear:N \l_@@_pdf_str
     \tl_set:Nx \l_@@_attr_tl
       {
         \tl_if_empty:NF \l_@@_decodearray_str
@@ -205,6 +206,8 @@
         : \l_@@_pagebox_tl
         \int_compare:nNnT \l_@@_page_int > 1
           { :P \int_use:N \l_@@_page_int }
+        \str_if_empty:NF \l_@@_pdf_str
+          { :X \l_@@_pdf_str }
       }
     \@@_backend_getbb_auxi:n {#1}
   }
@@ -231,9 +234,12 @@
 \cs_new_protected:Npn \@@_backend_getbb_auxiii:n #1
   {
     \tex_immediate:D \tex_pdfximage:D
-      \bool_lazy_or:nnT
-        { \l_@@_interpolate_bool }
-        { ! \tl_if_empty_p:N \l_@@_decodearray_str }
+      \bool_lazy_any:nT
+        {
+          { \l_@@_interpolate_bool }
+          { ! \tl_if_empty_p:N \l_@@_decodearray_str }
+          { ! \str_if_empty_p:N \l_@@_pdf_str }
+        }
         {
           attr ~
             {
@@ -241,6 +247,7 @@
                 { /Decode~[ \l_@@_decodearray_str ] }
               \bool_if:NT \l_@@_interpolate_bool
                 { /Interpolate~true }
+              \l_@@_pdf_str
             }
         }
       \int_compare:nNnT \l_@@_page_int > 0
@@ -398,6 +405,7 @@
   {
     \int_zero:N \l_@@_page_int
     \tl_clear:N \l_@@_pagebox_tl
+    \str_clear:N \l_@@_pdf_str
     \@@_extract_bb:n {#1}
   }
 \cs_new_eq:NN \@@_backend_getbb_jpeg:n \@@_backend_getbb_jpg:n
@@ -430,10 +438,9 @@
 %  \begin{macro}{\@@_backend_include_auxi:nn}
 %  \begin{macro}{\@@_backend_include_auxii:nnn, \@@_backend_include_auxii:xnn}
 %  \begin{macro}{\@@_backend_include_auxiii:nnn}
-%   The special syntax depends on the file type. There is a difference in
-%   how PDF graphics are best handled between |dvipdfmx| and \XeTeX{}: for
-%   the latter it is better to use the primitive route. The relevant code for
-%   that is included later in this file.
+%   The special syntax depends on the file type. As detailed later, we use the
+%   primitive in \XeTeX{} to read the PDF bounding box but not to include the
+%   graphic.
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_backend_include_eps:n #1
   {
@@ -452,10 +459,8 @@
 \cs_new_eq:NN \@@_backend_include_jpeg:n \@@_backend_include_jpg:n
 \cs_new_eq:NN \@@_backend_include_png:n \@@_backend_include_jpg:n
 \cs_new_eq:NN \@@_backend_include_bmp:n \@@_backend_include_jpg:n
-%<*dvipdfmx>
 \cs_new_protected:Npn \@@_backend_include_pdf:n #1
   { \@@_backend_include_auxi:nn {#1} { epdf } }
-%</dvipdfmx>
 %    \end{macrocode}
 %   Graphic inclusion is set up to use the fact that each image is stored in
 %   the PDF as an XObject. This means that we can include repeated images
@@ -474,6 +479,8 @@
           { :D \l_@@_decodearray_str }
         \bool_if:NT \l_@@_interpolate_bool
            { :I }
+         \str_if_empty:NF \l_@@_pdf_str
+           { :X \l_@@_pdf_str }
       }
       {#1} {#2}
   }
@@ -513,15 +520,19 @@
               \dim_to_decimal_in_bp:n \l_@@_ury_dim \c_space_tl
           }
         (#1)
-        \bool_lazy_or:nnT
-          { \l_@@_interpolate_bool }
-          { ! \tl_if_empty_p:N \l_@@_decodearray_str }
+        \bool_lazy_any:nT
+          {
+            { \l_@@_interpolate_bool }
+            { ! \tl_if_empty_p:N \l_@@_decodearray_str }
+            { ! \str_if_empty_p:N \l_@@_pdf_str }
+          }
           {
             <<
               \tl_if_empty:NF \l_@@_decodearray_str
                 { /Decode~[ \l_@@_decodearray_str ] }
               \bool_if:NT \l_@@_interpolate_bool
                 { /Interpolate~true> }
+              \l_@@_pdf_str
             >>
           }
       }
@@ -575,6 +586,7 @@
   {
     \int_zero:N \l_@@_page_int
     \tl_clear:N \l_@@_pagebox_tl
+    \str_clear:N \l_@@_pdf_str
     \@@_backend_getbb_auxi:nN {#1} \tex_XeTeXpicfile:D
   }
 \cs_new_eq:NN \@@_backend_getbb_jpeg:n \@@_backend_getbb_jpg:n
@@ -638,19 +650,10 @@
 % \end{macro}
 %
 % \begin{macro}{\@@_backend_include_pdf:n}
-%   For PDF graphics, properly supporting the |pagebox| concept in \XeTeX{}
-%   is best done using the |\tex_XeTeXpdffile:D| primitive. The syntax here
-%   is the same as for the graphic measurement part, although we know at this
-%   stage that there must be some valid setting for \cs{l_@@_pagebox_tl}.
-%    \begin{macrocode}
-\cs_new_protected:Npn \@@_backend_include_pdf:n #1
-  {
-    \tex_XeTeXpdffile:D #1 ~
-      \int_compare:nNnT \l_@@_page_int > 0
-        { page ~ \int_use:N \l_@@_page_int \c_space_tl }
-        \exp_after:wN \@@_backend_getbb_pagebox:w \l_@@_pagebox_tl
-  }
-%    \end{macrocode}
+%   Earlier versions of the backend code used the \XeTeX{} primitive to
+%   implement this separately from the \texttt{dvipdfmx} approach. However,
+%   that does not allow for the addition of arbitrary PDF attributes, so
+%   we stick to the method which does.
 % \end{macro}
 %
 % \begin{macro}{\@@_backend_get_pagecount:n}
diff --git a/l3experimental/CHANGELOG.md b/l3experimental/CHANGELOG.md
index a3be92ce0..cfbdccde3 100644
--- a/l3experimental/CHANGELOG.md
+++ b/l3experimental/CHANGELOG.md
@@ -7,6 +7,9 @@ this project uses date-based 'snapshot' version identifiers.
 
 ## [Unreleased]
 
+### Added
+- Key `pdf-attr` to `l3graphics` for additional attribute setting
+
 ## [2023-03-30]
 
 ### Fixed
diff --git a/l3experimental/l3graphics/l3graphics.dtx b/l3experimental/l3graphics/l3graphics.dtx
index 346c1ef92..11e5e46d7 100644
--- a/l3experimental/l3graphics/l3graphics.dtx
+++ b/l3experimental/l3graphics/l3graphics.dtx
@@ -78,6 +78,11 @@
 %   which may contain multiple pages.
 % \end{variable}
 %
+% \begin{variable}{pdf-attr}
+%   Additional PDF-focussed attributes: available to allow control of
+%   extended |.pdf| structures beyond those needed for graphic inclusion.
+% \end{variable}
+%
 % \begin{variable}{pagebox}
 %   The nature of the page box setting used to determine the bounding box of
 %   material: used for |.pdf| files which feature multiple page box
@@ -206,6 +211,7 @@
 %     \l_@@_interpolate_bool ,
 %     \l_@@_page_int         ,
 %     \l_@@_pagebox_tl       ,
+%     \l_@@_pdf_str          ,
 %     \l_@@_type_str
 %   }
 %   Keys which control features of graphics. The standard value of |pagebox|
@@ -235,6 +241,8 @@
       crop ,
     page .int_set:N =
       \l_@@_page_int ,
+    pdf-attr .str_set:N =
+      \l_@@_pdf_str ,
     type . str_set:N =
       \l_@@_type_str
   }





More information about the latex3-commits mailing list.