From b1ce47fe4d0e1f06d1b019c3c6eb5f1b0ecd5e14 Mon Sep 17 00:00:00 2001
From: Karl Berry <karl@freefriends.org>
Date: Sat, 15 Jul 2017 21:27:01 +0000
Subject: l3 (15jul17)

git-svn-id: svn://tug.org/texlive/trunk@44813 c570f23f-e606-0410-a88d-b1316a301751
---
 .../texmf-dist/tex/latex/l3kernel/l3xdvipdfmx.def  | 137 +++++++++++++--------
 1 file changed, 84 insertions(+), 53 deletions(-)

(limited to 'Master/texmf-dist/tex/latex/l3kernel/l3xdvipdfmx.def')

diff --git a/Master/texmf-dist/tex/latex/l3kernel/l3xdvipdfmx.def b/Master/texmf-dist/tex/latex/l3kernel/l3xdvipdfmx.def
index 4046489e12e..f66bc633b4c 100644
--- a/Master/texmf-dist/tex/latex/l3kernel/l3xdvipdfmx.def
+++ b/Master/texmf-dist/tex/latex/l3kernel/l3xdvipdfmx.def
@@ -22,6 +22,22 @@
 \ProvidesExplFile
   {l3xdvidpfmx.def}{2017/03/18}{}
   {L3 Experimental driver: xdvipdfmx}
+\AtBeginDocument
+  {
+    \@ifpackageloaded { color }
+      {
+        \cs_new_protected:Npn \__driver_color_pickup:
+          { \tl_set_eq:NN \l__color_current_tl \current@color }
+      }
+      { \cs_new_protected:Npn \__driver_color_pickup: { } }
+  }
+\cs_new_protected:Npn \__driver_color_ensure_current:
+  {
+    \__driver_color_pickup:
+    \tex_special:D { color~push~\l__color_current_tl }
+  }
+\cs_new_protected:Npn \__driver_color_reset:
+  { \tex_special:D { color~pop } }
 \cs_new_protected:Npn \__driver_literal:n #1
   { \tex_special:D { pdf:literal~ #1 } }
 \cs_new_protected:Npn \__driver_scope_begin:
@@ -68,21 +84,6 @@
     \hbox_overlap_right:n { \box_use:N #1 }
     \__driver_scope_end:
   }
-\tl_new:N \l__driver_color_current_tl
-\tl_set:Nn \l__driver_color_current_tl { [ 0 ] }
-\AtBeginDocument
-  {
-    \@ifpackageloaded { color }
-      { \tl_set:Nn \l__driver_color_current_tl { \current@color } }
-      { }
-  }
-\cs_new_protected:Npn \__driver_color_ensure_current:
-  {
-    \tex_special:D { pdf:bcolor~\l__driver_color_current_tl }
-    \group_insert_after:N \__driver_color_reset:
-  }
-\cs_new_protected:Npn \__driver_color_reset:
-  { \tex_special:D { pdf:ecolor } }
 \cs_new_eq:NN \__driver_image_getbb_eps:n \__image_read_bb:n
 \int_new:N \g__driver_image_int
 \cs_new_protected:Npn \__driver_image_include_eps:n #1
@@ -91,15 +92,17 @@
   }
 \cs_new_protected:Npn \__driver_image_include_jpg:n #1
   { \__driver_image_include_auxi:nn {#1} { image } }
-\cs_new_eq:NN \__driver_image_include_png:n \__driver_image_include_png:n
-\cs_new_protected:Npn \__driver_image_include_pdf:n #1
-  { \__driver_image_include_auxi:nn {#1} { epdf } }
+\cs_new_eq:NN \__driver_image_include_png:n \__driver_image_include_jpg:n
 \cs_new_protected:Npn \__driver_image_include_auxi:nn #1#2
   {
     \__driver_image_include_auxii:xnn
       {
-        \int_compare:nNnT \l__image_page_int > 0
+        \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
            { :I }
       }
@@ -123,69 +126,97 @@
       {
         pdf:#3~
         @image \int_use:c { c__image_ #1#2 _int }
-        \int_compare:nNnT \l__image_page_int > 0
+        \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
+            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
+          }
         (#1)
-        \bool_if:NT \l__image_interpolate_bool
-          { <</Interpolate~true>> }
-      }
-  }
-\AtBeginDocument
-  {
-    \@ifpackageloaded { color }
-      {
-        \cs_set_protected:Npn \__driver_tmp:w #1 [ #2 ] #3 \q_stop
+        \bool_lazy_or:nnT
+          { \l__image_interpolate_bool }
+          { ! \tl_if_empty_p:N \l__imge_decode_tl }
           {
-            \tl_if_empty:nT {#2}
-              {
-                \cs_set_protected:Npn \__driver_color_ensure_current:
-                  {
-                    \tex_special:D { color~push~\l__driver_color_current_tl }
-                    \group_insert_after:N \__driver_color_reset:
-                  }
-                \cs_set_protected:Npn \__driver_color_reset:
-                  { \tex_special:D { color~pop } }
-              }
+            <<
+              \tl_if_empty:NF \l__imge_decode_tl
+                { /Decode~[ \l__imge_decode_tl ] }
+              \bool_if:NT \l__image_interpolate_bool
+                { /Interpolate~true> }
+            >>
           }
-        \exp_after:wN \__driver_tmp:w \current@color [ ] \q_stop
       }
-      { }
   }
 \cs_new_protected:Npn \__driver_image_getbb_jpg:n #1
   {
     \int_zero:N \l__image_page_int
+    \tl_clear:N \l__image_pagebox_tl
     \__driver_image_getbb_auxi:nN {#1} \xetex_picfile:D
   }
 \cs_new_eq:NN \__driver_image_getbb_png:n \__driver_image_getbb_jpg:n
 \cs_new_protected:Npn \__driver_image_getbb_pdf:n #1
-  { \__driver_image_getbb_auxi:nN {#1} \xetex_pdffile:D }
+  {
+    \tl_clear:N \l__image_decode_tl
+    \bool_set_false:N \l__image_interpolate_bool
+    \__driver_image_getbb_auxi:nN {#1} \xetex_pdffile:D
+  }
 \cs_new_protected:Npn \__driver_image_getbb_auxi:nN #1#2
   {
-    \int_compare:nNnTF \l__image_page_int > 0
+    \int_compare:nNnTF \l__image_page_int > 1
       { \__driver_image_getbb_auxii:VnN \l__image_page_int {#1} #2  }
       { \__driver_image_getbb_auxiii:nNnn {#1} #2 }
   }
 \cs_new_protected:Npn \__driver_image_getbb_auxii:nnN #1#2#3
-  { \__driver_image_getbb_auxiii:nNnn {#2} #3 { :P #1 } { page #1 } }
+  { \__driver_image_getbb_aux:nNnn {#2} #3 { :P #1 } { page #1 } }
 \cs_generate_variant:Nn \__driver_image_getbb_auxii:nnN { V }
 \cs_new_protected:Npn \__driver_image_getbb_auxiii:nNnn #1#2#3#4
   {
-    \dim_if_exist:cTF { c__image_ #1#3 _ht_dim }
+    \tl_if_empty:NTF \l__image_pagebox_tl
+      { \__driver_image_getbb_auxiv:VnNnn \l__image_pagebox_tl }
+      { \__driver_image_getbb_auxv:nNnn }
+      {#1} #2 {#3} {#4}
+  }
+\cs_new_protected:Npn \__driver_image_getbb_auxiv:nnNnn #1#2#3#4#5
+  {
+    \use:x
       {
-        \dim_set_eq:Nc \l__image_ht_dim { c__image_ #1#3 _ht_dim }
-        \dim_set_eq:Nc \l__image_wd_dim { c__image_ #1#3 _wd_dim }
+        \__driver_image_getbb_auxv:nNnn {#2} #3 { : #1 #4 }
+          { #5 ~ \__driver_image_getbb_pagebox:w #1 }
+      }
+  }
+\cs_generate_variant:Nn \__driver_image_getbb_auxiv:nnNnn { V }
+\cs_new_protected:Npn \__driver_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 }
       }
       { \__driver_image_getbb_auxvi:nNnn {#1} #2 {#3} {#4} }
   }
 \cs_new_protected:Npn \__driver_image_getbb_auxvi:nNnn #1#2#3#4
   {
     \hbox_set:Nn \l__image_tmp_box { #2 #1 ~ #4 }
-    \dim_set:Nn \l__image_ht_dim { \box_ht:N \l__image_tmp_box }
-    \dim_set:Nn \l__image_wd_dim { \box_wd:N \l__image_tmp_box }
-    \dim_const:cn { c__image_ #1#3 _ht_dim }
-      { \l__image_ht_dim }
-    \dim_const:cn { c__image_ #1#3 _wd_dim }
-      { \l__image_wd_dim }
+    \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 }
+  }
+\cs_new:Npn \__driver_image_getbb_pagebox:w #1 box {#1}
+\cs_new_protected:Npn \__driver_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 }
+      \__driver_image_getbb_auxiv:VnNnn \l__image_pagebox_tl
   }
 \cs_new_eq:NN \__driver_draw_literal:n \__driver_literal:n
 \cs_generate_variant:Nn \__driver_draw_literal:n { x }
-- 
cgit v1.2.3

