[latex3-commits] [l3svn] branch master updated: Add \box_autosize_... functions
noreply at latex-project.org
noreply at latex-project.org
Tue Apr 4 08:06:21 CEST 2017
This is an automated email from the git hooks/post-receive script.
joseph pushed a commit to branch master
in repository l3svn.
The following commit(s) were added to refs/heads/master by this push:
new 8ed30bf Add \box_autosize_... functions
8ed30bf is described below
commit 8ed30bf76cff334dfb6562709215a498da565434
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date: Tue Apr 4 07:06:03 2017 +0100
Add \box_autosize_... functions
---
l3kernel/l3candidates.dtx | 112 +++++++++++++++++++++++++++----
l3kernel/testfiles/m3box004.lvt | 15 +++++
l3kernel/testfiles/m3box004.tlg | 44 +++++++++++-
l3kernel/testfiles/m3expl001.luatex.tlg | 6 ++
l3kernel/testfiles/m3expl001.ptex.tlg | 6 ++
l3kernel/testfiles/m3expl001.tlg | 6 ++
l3kernel/testfiles/m3expl001.uptex.tlg | 6 ++
l3kernel/testfiles/m3expl001.xetex.tlg | 6 ++
l3kernel/testfiles/m3expl003.luatex.tlg | 6 ++
l3kernel/testfiles/m3expl003.ptex.tlg | 6 ++
l3kernel/testfiles/m3expl003.tlg | 6 ++
l3kernel/testfiles/m3expl003.uptex.tlg | 6 ++
l3kernel/testfiles/m3expl003.xetex.tlg | 6 ++
13 files changed, 215 insertions(+), 16 deletions(-)
diff --git a/l3kernel/l3candidates.dtx b/l3kernel/l3candidates.dtx
index a96bc8c..ca67763 100644
--- a/l3kernel/l3candidates.dtx
+++ b/l3kernel/l3candidates.dtx
@@ -92,6 +92,49 @@
% On the other hand, rotation and resizing of boxed material can best be
% handled by modifying boxes. These transformations are described here.
%
+% \begin{function}[added = 2017-04-04]
+% {\box_autosize_to_wd_and_ht:Nnn, \box_autosize_to_wd_and_ht:Nnn}
+% \begin{syntax}
+% \cs{box_autosize_to_wd_and_ht:Nnn} \meta{box} \Arg{x-size} \Arg{y-size}
+% \end{syntax}
+% Resize the \meta{box} to fit within the given \meta{x-size} (horizontally)
+% and \meta{y-size} (vertically): both of the sizes are dimension
+% expressions).
+% The \meta{y-size} is the height only: it does not include any depth.
+% The updated \meta{box} will be an hbox, irrespective of the nature
+% of the \meta{box} before the resizing is applied. The final size of the
+% box will be the smaller of \Arg{x-size} and \Arg{y-size}, \emph{i.e.}~the
+% result will fit within the dimensions specified.
+% Negative sizes will
+% cause the material in the \meta{box} to be reversed in direction, but the
+% reference point of the \meta{box} will be unchanged.
+% Thus negative $y$-sizes will result in a box a depth dependent on the
+% height of the original box a height dependent on the depth.
+% The resizing applies within the current \TeX{} group level.
+% \end{function}
+%
+% \begin{function}[added = 2017-04-04]
+% {\box_autosize_to_wd_and_ht_plus_dp:Nnn, \box_autosize_to_wd_and_ht_plus_dp:Nnn}
+% \begin{syntax}
+% \cs{box_autosize_to_wd_and_ht_plus_dp:Nnn} \meta{box} \Arg{x-size} \Arg{y-size}
+% \end{syntax}
+% Resize the \meta{box} to fit within the given \meta{x-size} (horizontally)
+% and \meta{y-size} (vertically): both of the sizes are dimension
+% expressions).
+% The \meta{y-size} is the vertical size (height plus depth) of
+% the box.
+% The updated \meta{box} will be an hbox, irrespective of the nature
+% of the \meta{box} before the resizing is applied. The final size of the
+% box will be the smaller of \Arg{x-size} and \Arg{y-size}, \emph{i.e.}~the
+% result will fit within the dimensions specified.
+% Negative sizes will
+% cause the material in the \meta{box} to be reversed in direction, but the
+% reference point of the \meta{box} will be unchanged.
+% Thus negative $y$-sizes will result in a box a depth dependent on the
+% height of the original box a height dependent on the depth.
+% The resizing applies within the current \TeX{} group level.
+% \end{function}
+%
% \begin{function}{\box_resize:Nnn, \box_resize:cnn}
% \begin{syntax}
% \cs{box_resize:Nnn} \meta{box} \Arg{x-size} \Arg{y-size}
@@ -1369,13 +1412,13 @@
% \end{macro}
%
% \begin{macro}{\box_scale:Nnn, \box_scale:cnn}
+% \begin{macro}[aux]{\@@_scale_aux:N}
% When scaling a box, setting the scaling itself is easy enough. The
% new dimensions are also relatively easy to find, allowing only for
% the need to keep them positive in all cases. Once that is done then
% after a check for the trivial scaling a hand-off can be made to the
-% common code. The dimension scaling operations are carried out using
-% the \TeX{} mechanism as it avoids needing to use too many \texttt{fp}
-% operations.
+% common code. The code here is split into two as this allows sharing
+% with the auto-resizing functions.
% \begin{macrocode}
\cs_new_protected:Npn \box_scale:Nnn #1#2#3
{
@@ -1384,23 +1427,64 @@
\group_begin:
\fp_set:Nn \l_@@_scale_x_fp {#2}
\fp_set:Nn \l_@@_scale_y_fp {#3}
- \dim_set:Nn \l_@@_top_dim { \box_ht:N #1 }
- \dim_set:Nn \l_@@_bottom_dim { -\box_dp:N #1 }
- \dim_set:Nn \l_@@_right_dim { \box_wd:N #1 }
- \dim_zero:N \l_@@_left_dim
- \dim_set:Nn \l_@@_top_new_dim
- { \fp_abs:n { \l_@@_scale_y_fp } \l_@@_top_dim }
- \dim_set:Nn \l_@@_bottom_new_dim
- { \fp_abs:n { \l_@@_scale_y_fp } \l_@@_bottom_dim }
- \dim_set:Nn \l_@@_right_new_dim
- { \fp_abs:n { \l_@@_scale_x_fp } \l_@@_right_dim }
- \@@_resize_common:N #1
+ \@@_scale_aux:N #1
\group_end:
}
}
\cs_generate_variant:Nn \box_scale:Nnn { c }
+\cs_new_protected:Npn \@@_scale_aux:N #1
+ {
+ \dim_set:Nn \l_@@_top_dim { \box_ht:N #1 }
+ \dim_set:Nn \l_@@_bottom_dim { -\box_dp:N #1 }
+ \dim_set:Nn \l_@@_right_dim { \box_wd:N #1 }
+ \dim_zero:N \l_@@_left_dim
+ \dim_set:Nn \l_@@_top_new_dim
+ { \fp_abs:n { \l_@@_scale_y_fp } \l_@@_top_dim }
+ \dim_set:Nn \l_@@_bottom_new_dim
+ { \fp_abs:n { \l_@@_scale_y_fp } \l_@@_bottom_dim }
+ \dim_set:Nn \l_@@_right_new_dim
+ { \fp_abs:n { \l_@@_scale_x_fp } \l_@@_right_dim }
+ \@@_resize_common:N #1
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}
+% {
+% \box_autosize_to_wd_and_ht:Nnn ,
+% \box_autosize_to_wd_and_ht:cnn ,
+% \box_autosize_to_wd_and_ht_plus_dp:cnn ,
+% \box_autosize_to_wd_and_ht_plus_dp:Nnn
+% }
+% \begin{macro}[aux]{\@@_autosize:Nnnn}
+% Although autosizing a box uses dimensions, it has more in common in
+% implementation with scaling. As such, most of the real work here is
+% done elsewhere.
+% \begin{macrocode}
+\cs_new_protected:Npn \box_autosize_to_wd_and_ht:Nnn #1#2#3
+ { \@@_autosize:Nnnn #1 {#2} {#3} { \box_ht:N #1 } }
+\cs_generate_variant:Nn \box_autosize_to_wd_and_ht:Nnn { c }
+\cs_new_protected:Npn \box_autosize_to_wd_and_ht_plus_dp:Nnn #1#2#3
+ { \@@_autosize:Nnnn #1 {#2} {#3} { \box_ht:N #1 + \box_dp:N #1 } }
+\cs_generate_variant:Nn \box_autosize_to_wd_and_ht_plus_dp:Nnn { c }
+\cs_new_protected:Npn \@@_autosize:Nnnn #1#2#3#4
+ {
+ \hbox_set:Nn #1
+ {
+ \group_begin:
+ \fp_set:Nn \l_@@_scale_x_fp { (#2) / \box_wd:N #1 }
+ \fp_set:Nn \l_@@_scale_y_fp { (#3) / (#4) }
+ \fp_compare:nNnTF \l_@@_scale_x_fp > \l_@@_scale_y_fp
+ { \fp_set_eq:NN \l_@@_scale_x_fp \l_@@_scale_y_fp }
+ { \fp_set_eq:NN \l_@@_scale_y_fp \l_@@_scale_x_fp }
+ \@@_scale_aux:N #1
+ \group_end:
+ }
+ }
% \end{macrocode}
% \end{macro}
+% \end{macro}
%
% \begin{macro}[aux]{\@@_resize_common:N}
% The main resize function places in input into a box which will start
diff --git a/l3kernel/testfiles/m3box004.lvt b/l3kernel/testfiles/m3box004.lvt
index 8d2fd4e..fa7572f 100644
--- a/l3kernel/testfiles/m3box004.lvt
+++ b/l3kernel/testfiles/m3box004.lvt
@@ -199,6 +199,21 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\TEST { Resize~boxes~automatically }
+ {
+ \hbox_set:Nn \l_tmpa_box { ggg }
+ \group_begin:
+ \box_autosize_to_wd_and_ht:Nnn \l_tmpa_box { 1cm } { 1cm }
+ \box_show:N \l_tmpa_box
+ \group_end:
+ \group_begin:
+ \box_autosize_to_wd_and_ht_plus_dp:Nnn \l_tmpa_box { 1cm } { 1cm }
+ \box_show:N \l_tmpa_box
+ \group_end:
+ }
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\TEST { Trim~boxes }
{
\hbox_set:Nn \l_tmpa_box { \rule [ -10pt ] { 10pt } { 20pt } }
diff --git a/l3kernel/testfiles/m3box004.tlg b/l3kernel/testfiles/m3box004.tlg
index 19db7b4..e858bf4 100644
--- a/l3kernel/testfiles/m3box004.tlg
+++ b/l3kernel/testfiles/m3box004.tlg
@@ -724,7 +724,47 @@ l. ...}
l. ...}
============================================================
============================================================
-TEST 5: Trim boxes
+TEST 5: Resize boxes automatically
+============================================================
+> \box57=
+\hbox(8.16696+3.68831)x28.45284
+.\hbox(8.16696+3.68831)x28.45284
+..\kern 0.0
+..\hbox(8.16696+3.68831)x28.45284
+...\pdfsave
+...\pdfsetmatrix{1.89684 0 0 1.89684}
+...\hbox(4.30554+1.94444)x0.0, glue set - 15.00005fil
+....\hbox(4.30554+1.94444)x15.00005
+.....\OT1/cmr/m/n/10 g
+.....\OT1/cmr/m/n/10 g
+.....\OT1/cmr/m/n/10 g
+....\glue 0.0 plus 1.0fil minus 1.0fil
+...\pdfrestore
+..\glue 0.0 plus 1.0fil minus 1.0fil
+! OK.
+<argument> \l_tmpa_box
+l. ... }
+> \box57=
+\hbox(8.16696+3.68831)x28.45284
+.\hbox(8.16696+3.68831)x28.45284
+..\kern 0.0
+..\hbox(8.16696+3.68831)x28.45284
+...\pdfsave
+...\pdfsetmatrix{1.89684 0 0 1.89684}
+...\hbox(4.30554+1.94444)x0.0, glue set - 15.00005fil
+....\hbox(4.30554+1.94444)x15.00005
+.....\OT1/cmr/m/n/10 g
+.....\OT1/cmr/m/n/10 g
+.....\OT1/cmr/m/n/10 g
+....\glue 0.0 plus 1.0fil minus 1.0fil
+...\pdfrestore
+..\glue 0.0 plus 1.0fil minus 1.0fil
+! OK.
+<argument> \l_tmpa_box
+l. ... }
+============================================================
+============================================================
+TEST 6: Trim boxes
============================================================
> \box57=
\hbox(10.0+10.0)x10.0
@@ -836,7 +876,7 @@ l. ... }
l. ... }
============================================================
============================================================
-TEST 6: Viewport boxes
+TEST 7: Viewport boxes
============================================================
> \box57=
\hbox(10.0+10.0)x10.0
diff --git a/l3kernel/testfiles/m3expl001.luatex.tlg b/l3kernel/testfiles/m3expl001.luatex.tlg
index 6545062..582c1e4 100644
--- a/l3kernel/testfiles/m3expl001.luatex.tlg
+++ b/l3kernel/testfiles/m3expl001.luatex.tlg
@@ -4722,6 +4722,12 @@ Defining \box_resize_to_wd_and_ht:Nnn on line ...
Defining \box_resize_to_wd_and_ht:cnn on line ...
Defining \box_scale:Nnn on line ...
Defining \box_scale:cnn on line ...
+Defining \__box_scale_aux:N on line ...
+Defining \box_autosize_to_wd_and_ht:Nnn on line ...
+Defining \box_autosize_to_wd_and_ht:cnn on line ...
+Defining \box_autosize_to_wd_and_ht_plus_dp:Nnn on line ...
+Defining \box_autosize_to_wd_and_ht_plus_dp:cnn on line ...
+Defining \__box_autosize:Nnnn on line ...
Defining \__box_resize_common:N on line ...
Defining \box_clip:N on line ...
Defining \box_clip:c on line ...
diff --git a/l3kernel/testfiles/m3expl001.ptex.tlg b/l3kernel/testfiles/m3expl001.ptex.tlg
index 2396c39..aadb927 100644
--- a/l3kernel/testfiles/m3expl001.ptex.tlg
+++ b/l3kernel/testfiles/m3expl001.ptex.tlg
@@ -4690,6 +4690,12 @@ Defining \box_resize_to_wd_and_ht:Nnn on line ...
Defining \box_resize_to_wd_and_ht:cnn on line ...
Defining \box_scale:Nnn on line ...
Defining \box_scale:cnn on line ...
+Defining \__box_scale_aux:N on line ...
+Defining \box_autosize_to_wd_and_ht:Nnn on line ...
+Defining \box_autosize_to_wd_and_ht:cnn on line ...
+Defining \box_autosize_to_wd_and_ht_plus_dp:Nnn on line ...
+Defining \box_autosize_to_wd_and_ht_plus_dp:cnn on line ...
+Defining \__box_autosize:Nnnn on line ...
Defining \__box_resize_common:N on line ...
Defining \box_clip:N on line ...
Defining \box_clip:c on line ...
diff --git a/l3kernel/testfiles/m3expl001.tlg b/l3kernel/testfiles/m3expl001.tlg
index b33d1bb..d3dc1a5 100644
--- a/l3kernel/testfiles/m3expl001.tlg
+++ b/l3kernel/testfiles/m3expl001.tlg
@@ -4710,6 +4710,12 @@ Defining \box_resize_to_wd_and_ht:Nnn on line ...
Defining \box_resize_to_wd_and_ht:cnn on line ...
Defining \box_scale:Nnn on line ...
Defining \box_scale:cnn on line ...
+Defining \__box_scale_aux:N on line ...
+Defining \box_autosize_to_wd_and_ht:Nnn on line ...
+Defining \box_autosize_to_wd_and_ht:cnn on line ...
+Defining \box_autosize_to_wd_and_ht_plus_dp:Nnn on line ...
+Defining \box_autosize_to_wd_and_ht_plus_dp:cnn on line ...
+Defining \__box_autosize:Nnnn on line ...
Defining \__box_resize_common:N on line ...
Defining \box_clip:N on line ...
Defining \box_clip:c on line ...
diff --git a/l3kernel/testfiles/m3expl001.uptex.tlg b/l3kernel/testfiles/m3expl001.uptex.tlg
index a7ee4a6..86c8a4c 100644
--- a/l3kernel/testfiles/m3expl001.uptex.tlg
+++ b/l3kernel/testfiles/m3expl001.uptex.tlg
@@ -4690,6 +4690,12 @@ Defining \box_resize_to_wd_and_ht:Nnn on line ...
Defining \box_resize_to_wd_and_ht:cnn on line ...
Defining \box_scale:Nnn on line ...
Defining \box_scale:cnn on line ...
+Defining \__box_scale_aux:N on line ...
+Defining \box_autosize_to_wd_and_ht:Nnn on line ...
+Defining \box_autosize_to_wd_and_ht:cnn on line ...
+Defining \box_autosize_to_wd_and_ht_plus_dp:Nnn on line ...
+Defining \box_autosize_to_wd_and_ht_plus_dp:cnn on line ...
+Defining \__box_autosize:Nnnn on line ...
Defining \__box_resize_common:N on line ...
Defining \box_clip:N on line ...
Defining \box_clip:c on line ...
diff --git a/l3kernel/testfiles/m3expl001.xetex.tlg b/l3kernel/testfiles/m3expl001.xetex.tlg
index 28c86af..b329611 100644
--- a/l3kernel/testfiles/m3expl001.xetex.tlg
+++ b/l3kernel/testfiles/m3expl001.xetex.tlg
@@ -4700,6 +4700,12 @@ Defining \box_resize_to_wd_and_ht:Nnn on line ...
Defining \box_resize_to_wd_and_ht:cnn on line ...
Defining \box_scale:Nnn on line ...
Defining \box_scale:cnn on line ...
+Defining \__box_scale_aux:N on line ...
+Defining \box_autosize_to_wd_and_ht:Nnn on line ...
+Defining \box_autosize_to_wd_and_ht:cnn on line ...
+Defining \box_autosize_to_wd_and_ht_plus_dp:Nnn on line ...
+Defining \box_autosize_to_wd_and_ht_plus_dp:cnn on line ...
+Defining \__box_autosize:Nnnn on line ...
Defining \__box_resize_common:N on line ...
Defining \box_clip:N on line ...
Defining \box_clip:c on line ...
diff --git a/l3kernel/testfiles/m3expl003.luatex.tlg b/l3kernel/testfiles/m3expl003.luatex.tlg
index 4b758bc..6eb2e34 100644
--- a/l3kernel/testfiles/m3expl003.luatex.tlg
+++ b/l3kernel/testfiles/m3expl003.luatex.tlg
@@ -4723,6 +4723,12 @@ Defining \box_resize_to_wd_and_ht:Nnn on line ...
Defining \box_resize_to_wd_and_ht:cnn on line ...
Defining \box_scale:Nnn on line ...
Defining \box_scale:cnn on line ...
+Defining \__box_scale_aux:N on line ...
+Defining \box_autosize_to_wd_and_ht:Nnn on line ...
+Defining \box_autosize_to_wd_and_ht:cnn on line ...
+Defining \box_autosize_to_wd_and_ht_plus_dp:Nnn on line ...
+Defining \box_autosize_to_wd_and_ht_plus_dp:cnn on line ...
+Defining \__box_autosize:Nnnn on line ...
Defining \__box_resize_common:N on line ...
Defining \box_clip:N on line ...
Defining \box_clip:c on line ...
diff --git a/l3kernel/testfiles/m3expl003.ptex.tlg b/l3kernel/testfiles/m3expl003.ptex.tlg
index 81e9bbe..341ef7a 100644
--- a/l3kernel/testfiles/m3expl003.ptex.tlg
+++ b/l3kernel/testfiles/m3expl003.ptex.tlg
@@ -4691,6 +4691,12 @@ Defining \box_resize_to_wd_and_ht:Nnn on line ...
Defining \box_resize_to_wd_and_ht:cnn on line ...
Defining \box_scale:Nnn on line ...
Defining \box_scale:cnn on line ...
+Defining \__box_scale_aux:N on line ...
+Defining \box_autosize_to_wd_and_ht:Nnn on line ...
+Defining \box_autosize_to_wd_and_ht:cnn on line ...
+Defining \box_autosize_to_wd_and_ht_plus_dp:Nnn on line ...
+Defining \box_autosize_to_wd_and_ht_plus_dp:cnn on line ...
+Defining \__box_autosize:Nnnn on line ...
Defining \__box_resize_common:N on line ...
Defining \box_clip:N on line ...
Defining \box_clip:c on line ...
diff --git a/l3kernel/testfiles/m3expl003.tlg b/l3kernel/testfiles/m3expl003.tlg
index 731845b..aa01fc8 100644
--- a/l3kernel/testfiles/m3expl003.tlg
+++ b/l3kernel/testfiles/m3expl003.tlg
@@ -4711,6 +4711,12 @@ Defining \box_resize_to_wd_and_ht:Nnn on line ...
Defining \box_resize_to_wd_and_ht:cnn on line ...
Defining \box_scale:Nnn on line ...
Defining \box_scale:cnn on line ...
+Defining \__box_scale_aux:N on line ...
+Defining \box_autosize_to_wd_and_ht:Nnn on line ...
+Defining \box_autosize_to_wd_and_ht:cnn on line ...
+Defining \box_autosize_to_wd_and_ht_plus_dp:Nnn on line ...
+Defining \box_autosize_to_wd_and_ht_plus_dp:cnn on line ...
+Defining \__box_autosize:Nnnn on line ...
Defining \__box_resize_common:N on line ...
Defining \box_clip:N on line ...
Defining \box_clip:c on line ...
diff --git a/l3kernel/testfiles/m3expl003.uptex.tlg b/l3kernel/testfiles/m3expl003.uptex.tlg
index f7794e1..1ea195f 100644
--- a/l3kernel/testfiles/m3expl003.uptex.tlg
+++ b/l3kernel/testfiles/m3expl003.uptex.tlg
@@ -4691,6 +4691,12 @@ Defining \box_resize_to_wd_and_ht:Nnn on line ...
Defining \box_resize_to_wd_and_ht:cnn on line ...
Defining \box_scale:Nnn on line ...
Defining \box_scale:cnn on line ...
+Defining \__box_scale_aux:N on line ...
+Defining \box_autosize_to_wd_and_ht:Nnn on line ...
+Defining \box_autosize_to_wd_and_ht:cnn on line ...
+Defining \box_autosize_to_wd_and_ht_plus_dp:Nnn on line ...
+Defining \box_autosize_to_wd_and_ht_plus_dp:cnn on line ...
+Defining \__box_autosize:Nnnn on line ...
Defining \__box_resize_common:N on line ...
Defining \box_clip:N on line ...
Defining \box_clip:c on line ...
diff --git a/l3kernel/testfiles/m3expl003.xetex.tlg b/l3kernel/testfiles/m3expl003.xetex.tlg
index 81650df..5d11ab1 100644
--- a/l3kernel/testfiles/m3expl003.xetex.tlg
+++ b/l3kernel/testfiles/m3expl003.xetex.tlg
@@ -4701,6 +4701,12 @@ Defining \box_resize_to_wd_and_ht:Nnn on line ...
Defining \box_resize_to_wd_and_ht:cnn on line ...
Defining \box_scale:Nnn on line ...
Defining \box_scale:cnn on line ...
+Defining \__box_scale_aux:N on line ...
+Defining \box_autosize_to_wd_and_ht:Nnn on line ...
+Defining \box_autosize_to_wd_and_ht:cnn on line ...
+Defining \box_autosize_to_wd_and_ht_plus_dp:Nnn on line ...
+Defining \box_autosize_to_wd_and_ht_plus_dp:cnn on line ...
+Defining \__box_autosize:Nnnn on line ...
Defining \__box_resize_common:N on line ...
Defining \box_clip:N on line ...
Defining \box_clip:c on line ...
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the latex3-commits
mailing list