[latex3-commits] [l3svn] 07/08: Store full bbox data for images, and use this for dvipdfmx

noreply at latex-project.org noreply at latex-project.org
Sun Jun 4 11:46:47 CEST 2017


This is an automated email from the git hooks/post-receive script.

joseph pushed a commit to branch master
in repository l3svn.

commit 9f73ba55d91f03e9eb0e037f8d662b11b4d57efd
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Sun Jun 4 08:11:26 2017 +0200

    Store full bbox data for images, and use this for dvipdfmx
    
    In the dvipdfmx case, "pagebox" will go wrong unless there is also a
    full "bbox" argument. That means we need to store the information at
    least in that case. It therefore makes life easier if we simply cache
    the bbox in all cases, noting that where (llx,lly) = (0,0) we can
    avoid consuming two dimens. In some cases, for example pdfmode,
    xdvipdfmx, images always start (0,0) so that is a built-in assumption.
---
 l3kernel/l3drivers.dtx                 |   63 ++++++++++++++++++++-----------
 l3kernel/testfiles/m3expl001.xetex.tlg |    2 +-
 l3kernel/testfiles/m3expl003.xetex.tlg |    2 +-
 l3trial/l3image/l3image.dtx            |   64 +++++++++++++++++++++-----------
 4 files changed, 85 insertions(+), 46 deletions(-)

diff --git a/l3kernel/l3drivers.dtx b/l3kernel/l3drivers.dtx
index a3e5efd..c823884 100644
--- a/l3kernel/l3drivers.dtx
+++ b/l3kernel/l3drivers.dtx
@@ -741,18 +741,22 @@
   }
 \cs_new_protected:Npn \@@_image_getbb_auxi:n #1
   {
-    \dim_if_exist:cTF { c__image_ #1 \l_@@_image_attr_tl _ht_dim }
+    \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_ht_dim
-          { c__image_ #1 \l_@@_image_attr_tl _ht_dim }
-        \dim_set_eq:Nc \l__image_wd_dim
-          { c__image_ #1 \l_@@_image_attr_tl _wd_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_getbb_auxii:n {#1} }
   }
 %    \begin{macrocode}
 %   Measuring the image is done by boxing up: for PDF images we could
 %   use |\pdftex_pdfximagebbox:D|, but if doesn't work for other types.
+%   As the box will always start at $(0,0)$ there is no need to worry about
+%   the lower-left position.
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_image_getbb_auxii:n #1
   {
@@ -766,14 +770,14 @@
       {#1}
     \hbox_set:Nn \l__image_tmp_box
       { \pdftex_pdfrefximage:D \pdftex_pdflastximage:D }
-    \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_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 }
       { \tex_the:D \pdftex_pdflastximage:D }
-    \dim_const:cn { c__image_ #1 \l_@@_image_attr_tl _ht_dim }
-      { \l__image_ht_dim }
-    \dim_const:cn { c__image_ #1 \l_@@_image_attr_tl _wd_dim }
-      { \l__image_wd_dim }
+    \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 }
   }
 %    \end{macrocode}
 % \end{macro}
@@ -1023,6 +1027,12 @@
       { \@@_image_include_auxiii:nn {#2} {#1} {#3} }
   }
 \cs_generate_variant:Nn \@@_image_include_auxii:nnn { x }
+%    \end{macrocode}
+%  Inclusion using the specials is relatively straight-forward, but there
+%  is one wrinkle. To get the |pagebox| correct for PDF images in all cases,
+%  it is necessary to provide both that information and the |bbox| argument:
+%  odd things happen otherwise!
+%    \begin{macrocode}
 \cs_new_protected:Npn \@@_image_include_auxiii:nnn #1#2#3
   {
     \int_gincr:N \g_@@_image_int
@@ -1034,7 +1044,14 @@
         \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
+          }
         (#1)
         \bool_if:NT \l__image_interpolate_bool
           { <</Interpolate~true>> }
@@ -1142,22 +1159,24 @@
 \cs_generate_variant:Nn \@@_image_getbb_auxiv:nnNnn { V }
 \cs_new_protected:Npn \@@_image_getbb_auxv:nNnn #1#2#3#4
   {
-    \dim_if_exist:cTF { c__image_ #1#3 _ht_dim }
+    \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_ht_dim { c__image_ #1#3 _ht_dim }
-        \dim_set_eq:Nc \l__image_wd_dim { c__image_ #1#3 _wd_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_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_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 \@@_image_getbb_pagebox:w #1 box {#1}
 %    \end{macrocode}
@@ -1169,7 +1188,7 @@
 % \end{macro}
 % \end{macro}
 %
-% \begin{macro}{\@@_image_include_pdf:n}
+% \begin{macro}[int]{\@@_image_include_pdf:n}
 %   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
diff --git a/l3kernel/testfiles/m3expl001.xetex.tlg b/l3kernel/testfiles/m3expl001.xetex.tlg
index 54ea8e7..f4d6555 100644
--- a/l3kernel/testfiles/m3expl001.xetex.tlg
+++ b/l3kernel/testfiles/m3expl001.xetex.tlg
@@ -5632,7 +5632,6 @@ Defining \g__driver_image_int on line ...
 Defining \__driver_image_include_eps:n on line ...
 Defining \__driver_image_include_jpg:n on line ...
 Defining \__driver_image_include_png:n on line ...
-Defining \__driver_image_include_pdf:n on line ...
 Defining \__driver_image_include_auxi:nn on line ...
 Defining \__driver_image_include_auxii:nnn on line ...
 Defining \__driver_image_include_auxii:xnn on line ...
@@ -5649,6 +5648,7 @@ Defining \__driver_image_getbb_auxiv:VnNnn on line ...
 Defining \__driver_image_getbb_auxv:nNnn on line ...
 Defining \__driver_image_getbb_auxvi:nNnn on line ...
 Defining \__driver_image_getbb_pagebox:w on line ...
+Defining \__driver_image_include_pdf:n on line ...
 Defining \__driver_draw_literal:n on line ...
 Defining \__driver_draw_literal:x on line ...
 Defining \__driver_draw_begin: on line ...
diff --git a/l3kernel/testfiles/m3expl003.xetex.tlg b/l3kernel/testfiles/m3expl003.xetex.tlg
index 20e55f1..d6befd0 100644
--- a/l3kernel/testfiles/m3expl003.xetex.tlg
+++ b/l3kernel/testfiles/m3expl003.xetex.tlg
@@ -5633,7 +5633,6 @@ Defining \g__driver_image_int on line ...
 Defining \__driver_image_include_eps:n on line ...
 Defining \__driver_image_include_jpg:n on line ...
 Defining \__driver_image_include_png:n on line ...
-Defining \__driver_image_include_pdf:n on line ...
 Defining \__driver_image_include_auxi:nn on line ...
 Defining \__driver_image_include_auxii:nnn on line ...
 Defining \__driver_image_include_auxii:xnn on line ...
@@ -5650,6 +5649,7 @@ Defining \__driver_image_getbb_auxiv:VnNnn on line ...
 Defining \__driver_image_getbb_auxv:nNnn on line ...
 Defining \__driver_image_getbb_auxvi:nNnn on line ...
 Defining \__driver_image_getbb_pagebox:w on line ...
+Defining \__driver_image_include_pdf:n on line ...
 Defining \__driver_draw_literal:n on line ...
 Defining \__driver_draw_literal:x on line ...
 Defining \__driver_draw_begin: on line ...
diff --git a/l3trial/l3image/l3image.dtx b/l3trial/l3image/l3image.dtx
index 899a5d7..c5ddd10 100644
--- a/l3trial/l3image/l3image.dtx
+++ b/l3trial/l3image/l3image.dtx
@@ -91,12 +91,11 @@
 %   specifications.
 % \end{variable}
 %
-% \begin{variable}{\l__image_ht_dim, \l__image_wd_dim}
-%   Dimensions holding the height and width of the image file.
-%   These values may be extracted/read from the image files themselves
-%   (see \cs{__image_extract_bb:n} and \cs{__image_read_bb:n}).  Note that
-%   image files have no depth: they are always included such that the reference
-%   point is at $(0,0)$.
+% \begin{variable}
+%   {\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}
@@ -104,8 +103,9 @@
 %     \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 size of the image file in \cs{l__image_ht_dim} and
-%   \cs{l__image_wd_dim}.
+%   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}.
 %
 %   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
@@ -136,8 +136,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 used to set the variables \cs{l__image_ht_dim} and
-%   \cs{l__image_wd_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
@@ -198,11 +198,17 @@
 %
 % \subsection{Obtaining bounding box data}
 %
-% \begin{variable}[int]{\l__image_ht_dim , \l__image_wd_dim}
-%   Storage for the return of results.
+% \begin{variable}[int]
+%   {
+%     \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_ht_dim
-\dim_new:N \l__image_wd_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}
 %
@@ -264,14 +270,22 @@
 %  As bounding boxes here start away from the lower-left origin, we need to
 %  store all four values (contrast with for example the \texttt{pdfmode}
 %  driver). Here |#2| is a potential page identifier: used to allow caching of
-%  individual pages in a multi-page document.
+%  individual pages in a multi-page document. Caching is applied to the
+%  upper-right position in all cases, but as the lower-left will often be
+%  $(0,0)$ it is only cached if required.
 %   \begin{macrocode}
 \cs_new_protected:Npx \@@_read_bb_auxi:nnnn #1#2#3#4
   {
-    \dim_if_exist:cTF { c_@@_ #1#2 _ht_dim }
+    \dim_if_exist:cTF { c_@@_ #1#2 _urx_dim }
       {
-        \dim_set_eq:Nc \l__image_ht_dim { c_@@_ #1#2 _ht_dim }
-        \dim_set_eq:Nc \l__image_wd_dim { c_@@_ #1#2 _wd_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 }
       }
       { \@@_read_bb_auxii:nnn {#3} {#4} {#1} {#2} }
   }
@@ -288,8 +302,12 @@
           }
       }
     \ior_close:N \exp_not:N \l_@@_tmp_ior
-    \dim_const:cn { c_@@_ #3#4 _ht_dim } { \l__image_ht_dim }
-    \dim_const:cn { c_@@_ #3#4 _wd_dim } { \l__image_wd_dim }
+    \dim_if_zero:NF \l__image_llx_dim
+      { \dim_const:cn { c_@@_ #3#4 _llx_dim } { \l__image_llx_dim } }
+    \dim_if_zero:NF \l__image_lly_dim
+      { \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
   {
@@ -329,8 +347,10 @@
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_read_bb_auxv:w #1~#2~#3~#4~#5 \q_stop
   {
-    \dim_set:Nn \l__image_ht_dim { #4 bp - #2 bp }
-    \dim_set:Nn \l__image_wd_dim { #3 bp - #1 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}

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the latex3-commits mailing list