[latex3-commits] [git/latex3] master: Document image module interfaces (30d9fa7)

Joseph Wright joseph.wright at morningstar2.co.uk
Fri Dec 15 14:06:40 CET 2017


Repository : https://github.com/latex3/latex3
On branch  : master
Link       : https://github.com/latex3/latex3/commit/30d9fa71369f34b40dddda5118be44fcf6d8e2a1

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

commit 30d9fa71369f34b40dddda5118be44fcf6d8e2a1
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Fri Dec 15 13:06:40 2017 +0000

    Document image module interfaces
    
    Slightly odd as the module is in l3trial but impacts on the ccore
    l3drivers. Howerver, as none of the code can be used without loading
    l3image we should be fine :)
    
    One new interface is added, to provide a way for drivers to add to the
    bounding box cache.


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

30d9fa71369f34b40dddda5118be44fcf6d8e2a1
 l3kernel/l3drivers.dtx                   |  178 +++++++++++++----------------
 l3trial/l3image/l3image.dtx              |  184 ++++++++++++++++++++----------
 l3trial/l3image/testfiles/m3image000.tlg |   10 +-
 3 files changed, 207 insertions(+), 165 deletions(-)

diff --git a/l3kernel/l3drivers.dtx b/l3kernel/l3drivers.dtx
index 0a3dc70..4cf9f1d 100644
--- a/l3kernel/l3drivers.dtx
+++ b/l3kernel/l3drivers.dtx
@@ -850,7 +850,7 @@
 % \begin{macro}{\@@_image_getbb_eps:n}
 %   Simply use the generic function.
 %    \begin{macrocode}
-\cs_new_eq:NN \@@_image_getbb_eps:n \__image_read_bb:n
+\cs_new_eq:NN \@@_image_getbb_eps:n \image_read_bb:n
 %    \end{macrocode}
 % \end{macro}
 %
@@ -1470,13 +1470,13 @@
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_image_getbb_jpg:n #1
   {
-    \int_zero:N \l__image_page_int
-    \tl_clear:N \l__image_pagebox_tl
+    \int_zero:N \l_image_page_int
+    \tl_clear:N \l_image_pagebox_tl
     \tl_set:Nx \l_@@_image_attr_tl
       {
-        \tl_if_empty:NF \l__image_decode_tl
-          { :D \l__image_decode_tl }
-        \bool_if:NT \l__image_interpolate_bool
+        \tl_if_empty:NF \l_image_decode_tl
+          { :D \l_image_decodearray_tl }
+        \bool_if:NT \l_image_interpolate_bool
           { :I }
       }
     \tl_clear:N \l_@@_image_attr_tl
@@ -1485,27 +1485,19 @@
 \cs_new_eq:NN \@@_image_getbb_png:n \@@_image_getbb_jpg:n
 \cs_new_protected:Npn \@@_image_getbb_pdf:n #1
   {
-    \tl_clear:N \l__image_decode_tl
-    \bool_set_false:N \l__image_interpolate_bool
+    \tl_clear:N \l_image_decode_tl
+    \bool_set_false:N \l_image_interpolate_bool
     \tl_set:Nx \l_@@_image_attr_tl
       {
-        : \l__image_pagebox_tl
-        \int_compare:nNnT \l__image_page_int > 1
-          { :P \int_use:N \l__image_page_int }
+        : \l_image_pagebox_tl
+        \int_compare:nNnT \l_image_page_int > 1
+          { :P \int_use:N \l_image_page_int }
       }
     \@@_image_getbb_auxi:n {#1}
   }
 \cs_new_protected:Npn \@@_image_getbb_auxi:n #1
   {
-    \dim_zero:N \l__image_llx_dim
-    \dim_zero:N \l__image_lly_dim
-    \dim_if_exist:cTF { c__image_ #1 \l_@@_image_attr_tl _urx_dim }
-      {
-        \dim_set_eq:Nc \l__image_urx_dim
-          { c__image_ #1 \l_@@_image_attr_tl _urx_dim }
-        \dim_set_eq:Nc \l__image_ury_dim
-          { c__image_ #1 \l_@@_image_attr_tl _ury_dim }
-      }
+    \image_bb_restore:xF { #1 \l_@@_image_attr_tl }
       { \@@_image_getbb_auxii:n {#1} }
   }
 %    \begin{macrocode}
@@ -1518,32 +1510,29 @@
   {
     \tex_immediate:D \pdftex_pdfximage:D
       \bool_lazy_or:nnT
-        { \l__image_interpolate_bool }
-        { ! \tl_if_empty_p:N \l__image_decode_tl }
+        { \l_image_interpolate_bool }
+        { ! \tl_if_empty_p:N \l_image_decodearray_tl }
         {
           attr ~
             {
-              \tl_if_empty:NF \l__image_decode_tl
-                { /Decode~[ \l__image_decode_tl ] }
-              \bool_if:NT \l__image_interpolate_bool
+              \tl_if_empty:NF \l_image_decode_tl
+                { /Decode~[ \l_image_decodearray_tl ] }
+              \bool_if:NT \l_image_interpolate_bool
                 { /Interpolate~true }
             }
         }
-      \int_compare:nNnT \l__image_page_int > 0
-        { page ~ \int_use:N \l__image_page_int }
-      \tl_if_empty:NF \l__image_pagebox_tl
-        { \l__image_pagebox_tl }
+      \int_compare:nNnT \l_image_page_int > 0
+        { page ~ \int_use:N \l_image_page_int }
+      \tl_if_empty:NF \l_image_pagebox_tl
+        { \l_image_pagebox_tl }
       {#1}
-    \hbox_set:Nn \l__image_tmp_box
+    \hbox_set:Nn \l_@@_tmp_box
       { \pdftex_pdfrefximage:D \pdftex_pdflastximage:D }
-    \dim_set:Nn \l__image_urx_dim { \box_wd:N \l__image_tmp_box }
-    \dim_set:Nn \l__image_ury_dim { \box_ht:N \l__image_tmp_box }
-    \int_const:cn { c__image_ #1 \l_@@_image_attr_tl _int }
+    \dim_set:Nn \l_image_urx_dim { \box_wd:N \l_@@_tmp_box }
+    \dim_set:Nn \l_image_ury_dim { \box_ht:N \l_@@_tmp_box }
+    \int_const:cn { c_@@_image_ #1 \l_@@_image_attr_tl _int }
       { \tex_the:D \pdftex_pdflastximage:D }
-    \dim_const:cn { c__image_ #1 \l_@@_image_attr_tl _urx_dim }
-      { \l__image_urx_dim }
-    \dim_const:cn { c__image_ #1 \l_@@_image_attr_tl _ury_dim }
-      { \l__image_ury_dim }
+    \image_bb_save:x { #1 \l_@@_image_attr_tl }
   }
 %    \end{macrocode}
 % \end{macro}
@@ -1558,7 +1547,7 @@
 \cs_new_protected:Npn \@@_image_include_jpg:n #1
   {
     \pdftex_pdfrefximage:D
-      \int_use:c { c__image_ #1 \l_@@_image_attr_tl _int }
+      \int_use:c { c_@@_image_ #1 \l_@@_image_attr_tl _int }
   }
 \cs_new_eq:NN \@@_image_include_pdf:n \@@_image_include_jpg:n
 \cs_new_eq:NN \@@_image_include_png:n \@@_image_include_jpg:n
@@ -1682,20 +1671,20 @@
 %   Simply use the generic functions: only for \texttt{dvipdfmx} in the
 %   extraction cases.
 %    \begin{macrocode}
-\cs_new_eq:NN \@@_image_getbb_eps:n \__image_read_bb:n
+\cs_new_eq:NN \@@_image_getbb_eps:n \image_read_bb:n
 %<*dvipdfmx>
 \cs_new_protected:Npn \@@_image_getbb_jpg:n #1
   {
-    \int_zero:N \l__image_page_int
-    \tl_clear:N \l__image_pagebox_tl
-    \__image_extract_bb:n {#1}
+    \int_zero:N \l_image_page_int
+    \tl_clear:N \l_image_pagebox_tl
+    \image_extract_bb:n {#1}
   }
 \cs_new_eq:NN \@@_image_getbb_png:n \@@_image_getbb_jpg:n
 \cs_new_protected:Npn \@@_image_getbb_pdf:n #1
   {
-    \tl_clear:N \l__image_decode_tl
-    \bool_set_false:N \l__image_interpolate_bool
-    \__image_extract_bb:n {#1}
+    \tl_clear:N \l_image_decode_tl
+    \bool_set_false:N \l_image_interpolate_bool
+    \image_extract_bb:n {#1}
   }
 %</dvipdfmx>
 %    \end{macrocode}
@@ -1742,23 +1731,23 @@
   {
     \@@_image_include_auxii:xnn
       {
-        \tl_if_empty:NF \l__image_pagebox_tl
-          { : \l__image_pagebox_tl }
-        \int_compare:nNnT \l__image_page_int > 1
-          { :P \int_use:N \l__image_page_int }
-        \tl_if_empty:NF \l__image_decode_tl
-          { :D \l__image_decode_tl }
-        \bool_if:NT \l__image_interpolate_bool
+        \tl_if_empty:NF \l_image_pagebox_tl
+          { : \l_image_pagebox_tl }
+        \int_compare:nNnT \l_image_page_int > 1
+          { :P \int_use:N \l_image_page_int }
+        \tl_if_empty:NF \l_image_decode_tl
+          { :D \l_image_decodearray_tl }
+        \bool_if:NT \l_image_interpolate_bool
            { :I }
       }
       {#1} {#2}
   }
 \cs_new_protected:Npn \@@_image_include_auxii:nnn #1#2#3
   {
-    \int_if_exist:cTF { c__image_ #2#1 _int }
+    \int_if_exist:cTF { c_@@_image_ #2#1 _int }
       {
         \tex_special:D
-          { pdf:usexobj~@image \int_use:c { c__image_ #2#1 _int } }
+          { pdf:usexobj~@image \int_use:c { c_@@_image_ #2#1 _int } }
       }
       { \@@_image_include_auxiii:nn {#2} {#1} {#3} }
   }
@@ -1772,31 +1761,31 @@
 \cs_new_protected:Npn \@@_image_include_auxiii:nnn #1#2#3
   {
     \int_gincr:N \g_@@_image_int
-    \int_const:cn { c__image_ #1#2 _int } { \g_@@_image_int }
+    \int_const:cn { c_@@_image_ #1#2 _int } { \g_@@_image_int }
     \tex_special:D
       {
         pdf:#3~
-        @image \int_use:c { c__image_ #1#2 _int }
-        \int_compare:nNnT \l__image_page_int > 1
-          { page ~ \int_use:N \l__image_page_int \c_space_tl }
-        \tl_if_empty:NF \l__image_pagebox_tl
+        @image \int_use:c { c_@@_image_ #1#2 _int }
+        \int_compare:nNnT \l_image_page_int > 1
+          { page ~ \int_use:N \l_image_page_int \c_space_tl }
+        \tl_if_empty:NF \l_image_pagebox_tl
           {
-            pagebox ~ \l__image_pagebox_tl \c_space_tl
+            pagebox ~ \l_image_pagebox_tl \c_space_tl
             bbox ~
-              \dim_to_decimal_in_bp:n \l__image_llx_dim \c_space_tl
-              \dim_to_decimal_in_bp:n \l__image_lly_dim \c_space_tl
-              \dim_to_decimal_in_bp:n \l__image_urx_dim \c_space_tl
-              \dim_to_decimal_in_bp:n \l__image_ury_dim \c_space_tl
+              \dim_to_decimal_in_bp:n \l_image_llx_dim \c_space_tl
+              \dim_to_decimal_in_bp:n \l_image_lly_dim \c_space_tl
+              \dim_to_decimal_in_bp:n \l_image_urx_dim \c_space_tl
+              \dim_to_decimal_in_bp:n \l_image_ury_dim \c_space_tl
           }
         (#1)
         \bool_lazy_or:nnT
-          { \l__image_interpolate_bool }
-          { ! \tl_if_empty_p:N \l__image_decode_tl }
+          { \l_image_interpolate_bool }
+          { ! \tl_if_empty_p:N \l_image_decodearray_tl }
           {
             <<
-              \tl_if_empty:NF \l__image_decode_tl
-                { /Decode~[ \l__image_decode_tl ] }
-              \bool_if:NT \l__image_interpolate_bool
+              \tl_if_empty:NF \l_image_decode_tl
+                { /Decode~[ \l_image_decodearray_tl ] }
+              \bool_if:NT \l_image_interpolate_bool
                 { /Interpolate~true> }
             >>
           }
@@ -1836,21 +1825,21 @@
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_image_getbb_jpg:n #1
   {
-    \int_zero:N \l__image_page_int
-    \tl_clear:N \l__image_pagebox_tl
+    \int_zero:N \l_image_page_int
+    \tl_clear:N \l_image_pagebox_tl
     \@@_image_getbb_auxi:nN {#1} \xetex_picfile:D
   }
 \cs_new_eq:NN \@@_image_getbb_png:n \@@_image_getbb_jpg:n
 \cs_new_protected:Npn \@@_image_getbb_pdf:n #1
   {
-    \tl_clear:N \l__image_decode_tl
-    \bool_set_false:N \l__image_interpolate_bool
+    \tl_clear:N \l_image_decode_tl
+    \bool_set_false:N \l_image_interpolate_bool
     \@@_image_getbb_auxi:nN {#1} \xetex_pdffile:D
   }
 \cs_new_protected:Npn \@@_image_getbb_auxi:nN #1#2
   {
-    \int_compare:nNnTF \l__image_page_int > 1
-      { \@@_image_getbb_auxii:VnN \l__image_page_int {#1} #2  }
+    \int_compare:nNnTF \l_image_page_int > 1
+      { \@@_image_getbb_auxii:VnN \l_image_page_int {#1} #2  }
       { \@@_image_getbb_auxiii:nNnn {#1} #2 }
   }
 \cs_new_protected:Npn \@@_image_getbb_auxii:nnN #1#2#3
@@ -1858,8 +1847,8 @@
 \cs_generate_variant:Nn \@@_image_getbb_auxii:nnN { V }
 \cs_new_protected:Npn \@@_image_getbb_auxiii:nNnn #1#2#3#4
   {
-    \tl_if_empty:NTF \l__image_pagebox_tl
-      { \@@_image_getbb_auxiv:VnNnn \l__image_pagebox_tl }
+    \tl_if_empty:NTF \l_image_pagebox_tl
+      { \@@_image_getbb_auxiv:VnNnn \l_image_pagebox_tl }
       { \@@_image_getbb_auxv:nNnn }
       {#1} #2 {#3} {#4}
   }
@@ -1874,24 +1863,15 @@
 \cs_generate_variant:Nn \@@_image_getbb_auxiv:nnNnn { V }
 \cs_new_protected:Npn \@@_image_getbb_auxv:nNnn #1#2#3#4
   {
-    \dim_zero:N \l__image_llx_dim
-    \dim_zero:N \l__image_lly_dim
-    \dim_if_exist:cTF { c__image_ #1#3 _urx_dim }
-      {
-        \dim_set_eq:Nc \l__image_urx_dim { c__image_ #1#3 _urx_dim }
-        \dim_set_eq:Nc \l__image_ury_dim { c__image_ #1#3 _ury_dim }
-      }
+    \image_bb_restore:nF {#1#3}
       { \@@_image_getbb_auxvi:nNnn {#1} #2 {#3} {#4} }
   }
 \cs_new_protected:Npn \@@_image_getbb_auxvi:nNnn #1#2#3#4
   {
-    \hbox_set:Nn \l__image_tmp_box { #2 #1 ~ #4 }
-    \dim_set:Nn \l__image_utx_dim { \box_wd:N \l__image_tmp_box }
-    \dim_set:Nn \l__image_ury_dim { \box_ht:N \l__image_tmp_box }
-    \dim_const:cn { c__image_ #1#3 _urx_dim }
-      { \l__image_urx_dim }
-    \dim_const:cn { c__image_ #1#3 _ury_dim }
-      { \l__image_ury_dim }
+    \hbox_set:Nn \l_@@_tmp_box { #2 #1 ~ #4 }
+    \dim_set:Nn \l_image_utx_dim { \box_wd:N \l_@@_tmp_box }
+    \dim_set:Nn \l_image_ury_dim { \box_ht:N \l_@@_tmp_box }
+    \image_bb_save:n {#1#3}
   }
 \cs_new:Npn \@@_image_getbb_pagebox:w #1 box {#1}
 %    \end{macrocode}
@@ -1907,14 +1887,14 @@
 %   For PDF images, properly supporting the |pagebox| concept in \XeTeX{}
 %   is best done using the |\xetex_pdffile:D| primitive. The syntax here
 %   is the same as for the image measurement part, although we know at this
-%   stage that there must be some valid setting for \cs{l__image_pagebox_tl}.
+%   stage that there must be some valid setting for \cs{l_image_pagebox_tl}.
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_image_include_pdf:n #1
   {
     \xetex_pdffile:D "#1" ~
-      \int_compare:nNnT \l__image_page_int > 0
-        { page~ \int_use:N \l__image_page_int }
-      \@@_image_getbb_auxiv:VnNnn \l__image_pagebox_tl
+      \int_compare:nNnT \l_image_page_int > 0
+        { page~ \int_use:N \l_image_page_int }
+      \@@_image_getbb_auxiv:VnNnn \l_image_pagebox_tl
   }
 %    \end{macrocode}
 % \end{macro}
@@ -2437,8 +2417,8 @@
 % \begin{macro}{\@@_image_getbb_png:n, \@@_image_getbb_jpg:n}
 %   These can be included by extracting the bounding box data.
 %    \begin{macrocode}
-\cs_new_eq:NN \@@_image_getbb_png:n \__image_extract_bb:n
-\cs_new_eq:NN \@@_image_getbb_jpg:n \__image_extract_bb:n
+\cs_new_eq:NN \@@_image_getbb_png:n \image_extract_bb:n
+\cs_new_eq:NN \@@_image_getbb_jpg:n \image_extract_bb:n
 %    \end{macrocode}
 % \end{macro}
 %
@@ -2456,8 +2436,8 @@
      \tex_special:D
        {
          dvisvgm:img~
-         \dim_to_decimal:n { \l__image_ury_dim } ~
-         \dim_to_decimal:n { \l__image_ury_dim } ~
+         \dim_to_decimal:n { \l_image_ury_dim } ~
+         \dim_to_decimal:n { \l_image_ury_dim } ~
          \@@_image_include_bitmap_quote:w #1 " " \q_stop
        }
   }
diff --git a/l3trial/l3image/l3image.dtx b/l3trial/l3image/l3image.dtx
index f8ab608..0ba7f09 100644
--- a/l3trial/l3image/l3image.dtx
+++ b/l3trial/l3image/l3image.dtx
@@ -69,49 +69,80 @@
 %   |mediabox| and |trimbox|.
 % \end{variable}
 %
-% \subsection{Internal functions}
+% \subsection{Driver functions}
 %
 % Inclusion of image files requires a range of low-level data be passed to
-% the driver layer. Individual drivers also require some common routines
-% which in themselves contain no driver-specific code. This functionality
-% is made available here.
+% the driver layer. These functions are primarily aimed at supporting this
+% work.
 %
-% \begin{variable}{\l__image_decode_tl}
+% \begin{variable}{\l_image_decode_tl}
 %   Array to decode color in bitmap image: when non-empty, this should
 %   be in the form of one, two or three pairs of real numbers in the range
 %   $[0,1]$, separated by spaces.
 % \end{variable}
 %
-% \begin{variable}{\l__image_interpolate_bool}
+% \begin{variable}{\l_image_interpolate_bool}
 %   Indicates whether interpolation should be applied to bitmap image files.
 % \end{variable}
 %
-% \begin{variable}{\l__image_page_int}
+% \begin{variable}{\l_image_page_int}
 %   The page to extract from a multi-page image file: used for |.pdf| files
 %   which may contain multiple pages.
 % \end{variable}
 %
-% \begin{variable}{\l__image_pagebox_tl}
+% \begin{variable}{\l_image_pagebox_tl}
 %   The nature of the page box setting used to determine the bounding box of
 %   material: used for |.pdf| files which feature multiple page box
 %   specifications.
 % \end{variable}
 %
 % \begin{variable}
-%   {\l__image_llx_dim, \l__image_lly_dim, \l__image_urx_dim, \l__image_ury_dim}
+%   {\l_image_llx_dim, \l_image_lly_dim, \l_image_urx_dim, \l_image_ury_dim}
 %   Dimensions which return the points $(\meta{llx},\meta{lly})$ and
 %   $(\meta{urx},\meta{ury})$ for the image. For many images only the resulting
 %   height and width are significant, but this is driver-dependent.
 % \end{variable}
 %
-% \begin{function}{\__image_extract_bb:n}
+% \begin{function}
+%   {
+%     \image_bb_save:n, \image_bb_save:x,
+%     \image_bb_restore:nF, \image_bb_restore:xF
+%   }
+%   \begin{syntax}
+%     \cs{image_bb_save:n} \meta{image}
+%     \cs{image_bb_restore:nF} \meta{image} \meta{false code}
+%   \end{syntax}
+%   This pair of functions are used to cache the bounding box of an \meta{image}
+%   so that extraction/reading is only required once. The \texttt{save}
+%   function stores the values from \cs{l_image_llx_dim},
+%   \cs{l_image_lly_dim}, \cs{l_image_urx_dim} and
+%   \cs{l_image_ury_dim} as constants. The \texttt{restore} function will then
+%   look up values for the bounding box of an \meta{image} and set the four
+%   dimensions appropriately. For any one \meta{image} the bounding box will
+%   be constant, so the \texttt{save} function should only be called once. Thus
+%   a typical use case is
+%   \begin{verbatim}
+%   \image_bb_restore:nF { <name> }
+%     {
+%       % Code to read the bb
+%       \image_bb_save:n { <name> }
+%     }
+%   \end{verbatim}
+%   \emph{i.e.}~every use of a bounding box will attempt to restore saved data,
+%   and saving will only take place where that is not possible.
+%   
+%   Note that the \meat{image} may not be a simple file name: a multi-page PDF,
+%   for example, will need to have the bounding box cached for each page used.
+% \end{function}
+%
+% \begin{function}{\image_extract_bb:n}
 %   \begin{syntax}
-%     \cs{__image_extract_bb:n} \meta{file}
+%     \cs{image_extract_bb:n} \meta{file}
 %   \end{syntax}
 %   Extracts bounding box data for the image \meta{file} using the |extractbb|
 %   utility, and stores the bounding box of the image file in
-%   \cs{l__image_llx_dim}, \cs{l__image_lly_dim}, \cs{l__image_urx_dim} and
-%   \cs{l__image_ury_dim}.
+%   \cs{l_image_llx_dim}, \cs{l_image_lly_dim}, \cs{l_image_urx_dim} and
+%   \cs{l_image_ury_dim}.
 %
 %   The \meta{file} name should be fully-qualified and sanitized: no search
 %   or other manipulation is carried out at this level. No check is made on
@@ -119,7 +150,7 @@
 %   using this function has made such a check. File types such as |.pdf| and
 %   |.jpg| are appropriate for parsing using this function.
 %
-%   When \cs{l__image_page_int} is positive the appropriate page will be
+%   When \cs{l_image_page_int} is positive the appropriate page will be
 %   queried from the image file.
 %
 %   Note that this function requires pipe shell calls to be enabled: this is
@@ -127,9 +158,9 @@
 %   when running the \TeX{} job.
 % \end{function}
 %
-% \begin{function}{\__image_read_bb:n}
+% \begin{function}{\image_read_bb:n}
 %   \begin{syntax}
-%     \cs{__image_read_bb:n} \meta{file}
+%     \cs{image_read_bb:n} \meta{file}
 %   \end{syntax}
 %   Parses the image \meta{file} to find a PostScript-style bounding box
 %   line of the form
@@ -138,8 +169,8 @@
 %   \end{verbatim}
 %   where \meta{llx}, \meta{lly}, \meta{urx} and \meta{ury} are the corners
 %   of the bounding box expressed in PostScript (\enquote{big}) points. The
-%   values are stored in \cs{l__image_llx_dim}, \cs{l__image_lly_dim},
-%   \cs{l__image_urx_dim} and \cs{l__image_ury_dim}.
+%   values are stored in \cs{l_image_llx_dim}, \cs{l_image_lly_dim},
+%   \cs{l_image_urx_dim} and \cs{l_image_ury_dim}.
 %
 %   The \meta{file} name should be fully-qualified and sanitized: no search
 %   or other manipulation is carried out at this level. No check is made on
@@ -181,24 +212,24 @@
 %
 % \begin{macro}
 %   {
-%     \l__image_decode_tl       ,
-%     \l__image_interpolate_bool,
-%     \l__image_page_int        ,
-%     \l__image_pagebox_tl
+%     \l_image_decodearray_tl  ,
+%     \l_image_interpolate_bool,
+%     \l_image_page_int        ,
+%     \l_image_pagebox_tl
 %   }
 %   Keys which control features of images. The standard value of |[pagebox|
 %   set up here should match the default for the drivers themselves: in
 %   the absence of any other setting the |cropbox| should be used.
 %    \begin{macrocode}
-\tl_new:N \l__image_pagebox_tl
+\tl_new:N \l_image_pagebox_tl
 \keys_define:nn { image }
   {
-    decode      .tl_set:N   = \l__image_decode_tl        ,
-    interpolate .bool_set:N = \l__image_interpolate_bool ,
-    page        .int_set:N  = \l__image_page_int         ,
+    decode      .tl_set:N   = \l_image_decodearray_tl        ,
+    interpolate .bool_set:N = \l_image_interpolate_bool ,
+    page        .int_set:N  = \l_image_page_int         ,
     pagebox     .choices:nn =
       { artbox , bleedbox , cropbox , mediabox , trimbox }
-      { \tl_set:Nn \l__image_pagebox_tl {#1} },
+      { \tl_set:Nn \l_image_pagebox_tl {#1} },
     pagebox     .initial:n  = cropbox
   }
 %    \end{macrocode}
@@ -208,19 +239,60 @@
 %
 % \begin{variable}
 %   {
-%     \l__image_llx_dim , \l__image_lly_dim,
-%     \l__image_urx_dim , \l__image_ury_dim
+%     \l_image_llx_dim , \l_image_lly_dim,
+%     \l_image_urx_dim , \l_image_ury_dim
 %   } 
 %   Storage for the return of bounding box.
 %    \begin{macrocode}
-\dim_new:N \l__image_llx_dim
-\dim_new:N \l__image_lly_dim
-\dim_new:N \l__image_urx_dim
-\dim_new:N \l__image_ury_dim
+\dim_new:N \l_image_llx_dim
+\dim_new:N \l_image_lly_dim
+\dim_new:N \l_image_urx_dim
+\dim_new:N \l_image_ury_dim
 %    \end{macrocode}
 % \end{variable}
 %
-% \begin{macro}{\__image_extract_bb:n, \__image_read_bb:n}
+% \begin{macro}{\image_bb_save:n, \image_bb_save:x}
+% \begin{macro}{\image_bb_restore:nF, \image_bb_restore:xF}
+%   Caching image bounding boxes is sensible, and these functions are needed both
+%   here and for drive-specific work. So they are made available as documented
+%   functions. To save on registers, the \enquote{origin} is only saved if it is
+%   not at zero.
+%     \begin{macrocode}
+\cs_new_protected:Npn \image_bb_save:n #1
+  {
+    \dim_if_exist:cTF { c_@@_ #1 _urx_dim }
+      { \__msg_kernel_error:nnn { image } { bb-already-cached } {#1} }
+      {
+        \dim_compare:nNnF \l_image_llx_dim = { 0pt }
+          { \dim_const:cn { c_@@_ #1 _llx_dim } { \l_image_llx_dim } }
+        \dim_if_zero:nNnF \l_image_lly_dim = { 0pt }
+          { \dim_const:cn { c_@@_ #1 _lly_dim } { \l_image_lly_dim } }
+        \dim_const:cn { c_@@_ #1 _urx_dim } { \l_image_urx_dim }
+        \dim_const:cn { c_@@_ #1 _ury_dim } { \l_image_ury_dim }
+      }
+  }
+\cs_generate_variant:Nn \image_bb_save:n { x }
+\cs_new_protected:Npn \image_bb_restore:nF #1#2
+  {
+    \dim_if_exist:cTF { c_@@_ #1 _urx_dim }
+      {
+        \dim_set_eq:Nc \l_image_urx_dim { c_@@_ #1 _urx_dim }
+        \dim_set_eq:Nc \l_image_ury_dim { c_@@_ #1 _ury_dim }
+        \dim_if_exist:cTF { c_@@_ #1 _llx_dim }
+          { \dim_set_eq:Nc \l_image_llx_dim { c_@@_ #1 _llx_dim } }
+          { \dim_zero:N \l_image_urx_dim }
+        \dim_if_exist:cTF { c_@@_ #1 _lly_dim }
+          { \dim_set_eq:Nc \l_image_lly_dim { c_@@_ #1 _lly_dim } }
+          { \dim_zero:N \l_image_lly_dim }
+      }
+      {#2}
+  }
+\cs_generate_variant:Nn \image_bb_restore:nF { x }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\image_extract_bb:n, \image_read_bb:n}
 % \begin{macro}{\@@_extract_bb_auix:nn, \@@_extract_bb_auix:Vn}
 % \begin{macro}{\@@_extract_bb_auxii:nnn}
 % \begin{macro}{\@@_extract_bb_auxiii:nnnn, \@@_extract_bb_auxiii:Vnnn}
@@ -240,10 +312,10 @@
 %  box has to be calculated by |extractbb|, with just the initial phase
 %  different.
 %    \begin{macrocode}
-\cs_new_protected:Npn \__image_extract_bb:n #1
+\cs_new_protected:Npn \image_extract_bb:n #1
   {
-    \int_compare:nNnTF \l__image_page_int > 0
-      { \@@_extract_bb_auxi:Vn \l__image_page_int {#1} }
+    \int_compare:nNnTF \l_image_page_int > 0
+      { \@@_extract_bb_auxi:Vn \l_image_page_int {#1} }
       { \@@_extract_bb_auxii:nnn {#1} { } { } }
   }
 \cs_new_protected:Npn \@@_extract_bb_auxi:nn #1#2
@@ -251,9 +323,9 @@
 \cs_generate_variant:Nn \@@_extract_bb_auxi:nn { Vn }
 \cs_new_protected:Npn \@@_extract_bb_auxii:nnn #1#2#3
   {
-   \tl_if_empty:NTF \l__image_pagebox_tl
+   \tl_if_empty:NTF \l_image_pagebox_tl
       { \@@_extract_bb_auxiv:nnn }
-      { \@@_extract_bb_auxiii:Vnnn \l__image_pagebox_tl }
+      { \@@_extract_bb_auxiii:Vnnn \l_image_pagebox_tl }
       {#1} {#2} {#3}
   }
 \cs_new_protected:Npn \@@_extract_bb_auxiii:nnnn #1#2#3#4
@@ -265,7 +337,7 @@
       { \tex_openin:D \l_@@_tmp_ior = "|extractbb~#3-O~#1" }
       { pipe-failed }
   }
-\cs_new_protected:Npn \__image_read_bb:n #1
+\cs_new_protected:Npn \image_read_bb:n #1
   {
     \@@_read_bb_auxi:nnn {#1} { }
       { \ior_open:Nn \l_@@_tmp_ior {#1} }
@@ -284,17 +356,7 @@
 %   \begin{macrocode}
 \cs_new_protected:Npn \@@_read_bb_auxi:nnnn #1#2#3#4
   {
-    \dim_if_exist:cTF { c_@@_ #1#2 _urx_dim }
-      {
-        \dim_set_eq:Nc \l__image_urx_dim { c_@@_ #1#2 _urx_dim }
-        \dim_set_eq:Nc \l__image_ury_dim { c_@@_ #1#2 _ury_dim }
-        \dim_if_exist:cTF { c_@@_ #1#2 _llx_dim }
-          { \dim_set_eq:Nc \l__image_llx_dim { c_@@_ #1#2 _llx_dim } }
-          { \dim_zero:N \l__image_urx_dim }
-        \dim_if_exist:cTF { c_@@_ #1#2 _lly_dim }
-          { \dim_set_eq:Nc \l__image_lly_dim { c_@@_ #1#2 _lly_dim } }
-          { \dim_zero:N \l__image_lly_dim }
-      }
+    \image_bb_restore:nF {#1#2}
       { \@@_read_bb_auxii:nnn {#3} {#4} {#1} {#2} }
   }
 \cs_new_protected:Npx \@@_read_bb_auxii:nnnn #1#2#3#4
@@ -312,12 +374,12 @@
     \exp_not:n
       {
         \ior_close:N \exp_not:N \l_@@_tmp_ior
-        \dim_compare:nNnF \l__image_llx_dim = { 0pt }
-          { \dim_const:cn { c_@@_ #3#4 _llx_dim } { \l__image_llx_dim } }
-        \dim_if_zero:nNnF \l__image_lly_dim = { 0pt }
-          { \dim_const:cn { c_@@_ #3#4 _lly_dim } { \l__image_lly_dim } }
-        \dim_const:cn { c_@@_ #3#4 _urx_dim } { \l__image_urx_dim }
-        \dim_const:cn { c_@@_ #3#4 _ury_dim } { \l__image_ury_dim }
+        \dim_compare:nNnF \l_image_llx_dim = { 0pt }
+          { \dim_const:cn { c_@@_ #3#4 _llx_dim } { \l_image_llx_dim } }
+        \dim_if_zero:nNnF \l_image_lly_dim = { 0pt }
+          { \dim_const:cn { c_@@_ #3#4 _lly_dim } { \l_image_lly_dim } }
+        \dim_const:cn { c_@@_ #3#4 _urx_dim } { \l_image_urx_dim }
+        \dim_const:cn { c_@@_ #3#4 _ury_dim } { \l_image_ury_dim }
       }
   }
 \use:x
@@ -358,10 +420,10 @@
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_read_bb_auxv:w #1~#2~#3~#4~#5 \q_stop
   {
-    \dim_set:Nn \l__image_llx_dim { #1 bp }
-    \dim_set:Nn \l__image_lly_dim { #2 bp }
-    \dim_set:Nn \l__image_urx_dim { #3 bp }
-    \dim_set:Nn \l__image_ury_dim { #4 bp }
+    \dim_set:Nn \l_image_llx_dim { #1 bp }
+    \dim_set:Nn \l_image_lly_dim { #2 bp }
+    \dim_set:Nn \l_image_urx_dim { #3 bp }
+    \dim_set:Nn \l_image_ury_dim { #4 bp }
     \ior_map_break:
   }
 %    \end{macrocode}
diff --git a/l3trial/l3image/testfiles/m3image000.tlg b/l3trial/l3image/testfiles/m3image000.tlg
index 0b6d366..6d68e38 100644
--- a/l3trial/l3image/testfiles/m3image000.tlg
+++ b/l3trial/l3image/testfiles/m3image000.tlg
@@ -2,9 +2,9 @@ This is a generated file for the LaTeX (2e + expl3) validation system.
 Don't change this file in any respect.
 Author: Bruno Le Floch
 (l3image.sty
-\l__image_page_int=\count...
-\l__image_llx_dim=\dimen...
-\l__image_lly_dim=\dimen...
-\l__image_urx_dim=\dimen...
-\l__image_ury_dim=\dimen...
+\l_image_page_int=\count...
+\l_image_llx_dim=\dimen...
+\l_image_lly_dim=\dimen...
+\l_image_urx_dim=\dimen...
+\l_image_ury_dim=\dimen...
 )





More information about the latex3-commits mailing list