[latex3-commits] [latex3/latex3] main: Add draw cmds for box/coffin positioning (fixes #1357) (a61f380ec)

github at latex-project.org github at latex-project.org
Thu Dec 7 08:02:46 CET 2023


Repository : https://github.com/latex3/latex3
On branch  : main
Link       : https://github.com/latex3/latex3/commit/a61f380ec712cc1f5e610d620634ca61f366c018

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

commit a61f380ec712cc1f5e610d620634ca61f366c018
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Thu Dec 7 06:34:32 2023 +0000

    Add draw cmds for box/coffin positioning (fixes #1357)


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

a61f380ec712cc1f5e610d620634ca61f366c018
 l3experimental/CHANGELOG.md                   |  4 ++
 l3experimental/l3draw/l3draw-boxes.dtx        | 40 ++++++++++--
 l3experimental/l3draw/l3draw.dtx              | 11 +++-
 l3experimental/l3draw/testfiles/m3draw006.lvt | 14 ++++-
 l3experimental/l3draw/testfiles/m3draw006.tlg | 89 ++++++++++++++++++++++++++-
 5 files changed, 147 insertions(+), 11 deletions(-)

diff --git a/l3experimental/CHANGELOG.md b/l3experimental/CHANGELOG.md
index c817dbc0d..84d0a4472 100644
--- a/l3experimental/CHANGELOG.md
+++ b/l3experimental/CHANGELOG.md
@@ -7,6 +7,10 @@ this project uses date-based 'snapshot' version identifiers.
 
 ## [Unreleased]
 
+### Added
+- `\draw_box_use:Nn` and `\draw_coffin_use:Nnnn` to allow
+  placement of boxed material at an offset (issue \#1357)
+
 ## [2023-11-01]
 
 ### Changed
diff --git a/l3experimental/l3draw/l3draw-boxes.dtx b/l3experimental/l3draw/l3draw-boxes.dtx
index 44989999a..bbc4ae94a 100644
--- a/l3experimental/l3draw/l3draw-boxes.dtx
+++ b/l3experimental/l3draw/l3draw-boxes.dtx
@@ -71,6 +71,8 @@
 % \end{variable}
 %
 % \begin{macro}{\draw_box_use:N}
+% \begin{macro}{\draw_box_use:Nn}
+% \begin{macro}{\@@_box_use:nNnnnnn}
 % \begin{macro}{\@@_box_use:Nnnnn}
 %   Before inserting a box, we need to make sure that the bounding box is being
 %   updated correctly. As drawings track transformations as a whole, rather
@@ -79,10 +81,22 @@
 %    \begin{macrocode}
 \cs_new_protected:Npn \draw_box_use:N #1
   {
-    \@@_box_use:Nnnnn #1
+    \@@_box_use:Nnnnnnn #1
       { 0pt } { -\box_dp:N #1 } { \box_wd:N #1 } { \box_ht:N #1 }
   }
-\cs_new_protected:Npn \@@_box_use:Nnnnn #1#2#3#4#5
+\cs_new_protected:Npn \draw_box_use:Nn #1#2
+  {
+    \@@_box_use:nNnnnn {#2} #1
+      { 0pt } { -\box_dp:N #1 } { \box_wd:N #1 } { \box_ht:N #1 }
+  }
+\cs_new_protected:Npn \@@_box_use:nNnnnn #1#2#3#4#5#6
+  {
+    \draw_scope_begin:
+      \draw_transform_shift:n {#1}
+      \@@_box_use:Nnnnnnn #2 {#3} {#4} {#5} {#6}
+    \draw_scope_end:
+  }
+\cs_new_protected:Npn \@@_box_use:Nnnnnnn #1#2#3#4#5
   {
     \bool_if:NT \l_draw_bb_update_bool
       {
@@ -126,18 +140,32 @@
 %    \end{macrocode}
 % \end{macro}
 % \end{macro}
+% \end{macro}
+% \end{macro}
 %
 % \begin{macro}{\draw_coffin_use:Nnn}
+% \begin{macro}{\draw_coffin_use:Nnnn}
+% \begin{macro}{\@@_coffin_use:nNnn}
 %   Slightly more than a shortcut: we have to allow for the fact that coffins
 %   have no apparent width before the reference point.
 %     \begin{macrocode}
 \cs_new_protected:Npn \draw_coffin_use:Nnn #1#2#3
+  {
+    \@@_coffin_use:nNnn { \@@_box_use:Nnnnnnn }
+      #1 {#2} {#3}
+  }
+\cs_new_protected:Npn \draw_coffin_use:Nnnn #1#2#3#4
+  {
+    \@@_coffin_use:nNnn { \@@_box_use:nNnnnn {#4} }
+      #1 {#2} {#3}
+  }
+\cs_new_protected:Npn \@@_coffin_use:nNnn #1#2#3#4
   {
     \group_begin:
       \hbox_set:Nn \l_@@_tmp_box
-        { \coffin_typeset:Nnnnn #1 {#2} {#3} { 0pt } { 0pt } }
-      \@@_box_use:Nnnnn \l_@@_tmp_box
-        { \box_wd:N \l_@@_tmp_box - \coffin_wd:N #1 }
+        { \coffin_typeset:Nnnnn #2 {#3} {#4} { 0pt } { 0pt } }
+      #1 \l_@@_tmp_box
+        { \box_wd:N \l_@@_tmp_box - \coffin_wd:N #2 }
         { -\box_dp:N \l_@@_tmp_box }
         { \box_wd:N \l_@@_tmp_box }
         { \box_ht:N \l_@@_tmp_box }
@@ -145,6 +173,8 @@
   }
 %    \end{macrocode}
 % \end{macro}
+% \end{macro}
+% \end{macro}
 %
 %    \begin{macrocode}
 %</package>
diff --git a/l3experimental/l3draw/l3draw.dtx b/l3experimental/l3draw/l3draw.dtx
index 9523fa433..f62ef53f5 100644
--- a/l3experimental/l3draw/l3draw.dtx
+++ b/l3experimental/l3draw/l3draw.dtx
@@ -961,9 +961,10 @@
 %
 % \subsection{Boxes and coffins}
 %
-% \begin{function}{\draw_box_use:N}
+% \begin{function}{\draw_box_use:N, \draw_box_use:Nn}
 %   \begin{syntax}
 %     \cs{draw_box_use:N} \meta{box}
+%     \cs{draw_box_use:Nn} \meta{box} \Arg{point}
 %   \end{syntax}
 %   Inserts the \meta{box} into a drawing, taking account of the current
 %   transformation matrix and shift, and adjusting the drawing bounding
@@ -990,11 +991,14 @@
 %       \draw_box_use:N \l_tmpa_box
 %     \draw_end:
 %   \end{demo}
+%   If the \meta{point} is given, the reference point of the box is placed there:
+%   otherwise it is positioned at the origin of the drawing.
 % \end{function}
 %
-% \begin{function}{\draw_coffin_use:Nnn}
+% \begin{function}{\draw_coffin_use:Nnn, \draw_coffin_use:Nnnn}
 %   \begin{syntax}
 %     \cs{draw_coffin_use:Nnn} \meta{coffin} \Arg{hpole} \Arg{vpole}
+%     \cs{draw_coffin_use:Nnnn} \meta{coffin} \Arg{hpole} \Arg{vpole} \Arg{point}
 %   \end{syntax}
 %   Inserts the \meta{coffin} into a drawing, taking account of the current
 %   transformation matrix and shift, and adjusting the drawing bounding
@@ -1012,6 +1016,9 @@
 %       \draw_coffin_use:Nnn \l_tmpa_coffin { hc } { vc }
 %     \draw_end:
 %   \end{demo}
+%   If the \meta{point} is given, the pole intersection of the coffine is
+%   placed there: otherwise it is positioned at the origin of the drawing.
+
 % \end{function}
 %
 % \subsection{Transformations}
diff --git a/l3experimental/l3draw/testfiles/m3draw006.lvt b/l3experimental/l3draw/testfiles/m3draw006.lvt
index 8986c1c85..e865efeca 100644
--- a/l3experimental/l3draw/testfiles/m3draw006.lvt
+++ b/l3experimental/l3draw/testfiles/m3draw006.lvt
@@ -32,7 +32,7 @@
 
 \START
 
-\TEST { \draw_box_use:N }
+\TEST { \draw_box_use:N(n) }
   {
     \test:n
       {
@@ -57,9 +57,14 @@
         \draw_transform_shift:n { 2cm , 2cm }
         \draw_box_use:N \l_tmpb_box
       }
+    \test:n
+      {
+        \hbox_set:Nn \l_tmpb_box { Hello }
+        \draw_box_use:Nn \l_tmpb_box { 2cm , 2cm }
+      }
   }
 
-\TEST { \draw_coffin_use:N }
+\TEST { \draw_coffin_use:Nnn(n) }
   {
     \test:n
       {
@@ -89,6 +94,11 @@
         \draw_transform_shift:n { 2cm , 2cm }
         \draw_coffin_use:Nnn \l_tmpb_coffin { l } { B }
       }
+    \test:n
+      {
+        \hcoffin_set:Nn \l_tmpb_coffin { Hello }
+        \draw_coffin_use:Nnnn \l_tmpb_coffin { l } { B } { 2cm , 2cm }
+      }
   }
 
 \END
diff --git a/l3experimental/l3draw/testfiles/m3draw006.tlg b/l3experimental/l3draw/testfiles/m3draw006.tlg
index fbd4b67e5..1982ff0b1 100644
--- a/l3experimental/l3draw/testfiles/m3draw006.tlg
+++ b/l3experimental/l3draw/testfiles/m3draw006.tlg
@@ -1,7 +1,7 @@
 This is a generated file for the LaTeX (2e + expl3) validation system.
 Don't change this file in any respect.
 ============================================================
-TEST 1: \draw_box_use:N 
+TEST 1: \draw_box_use:N (n)
 ============================================================
 > \box...=
 \hbox(142.66377+0.0)x284.92755
@@ -151,9 +151,48 @@ l. ...  }
 ! OK.
 <argument> \l_tmpa_box 
 l. ...  }
+> \box...=
+\hbox(142.66377+0.0)x284.92755
+.\hbox(142.66377+0.0)x284.92755
+..\glue 0.2
+..\hbox(0.0+0.0)x0.0, shifted -0.2
+...\pdfsave
+...\pdfliteral{0.39851 w}
+...\pdfcolorstack 0 push {0 g 0 G}
+...\pdfliteral{0 J}
+...\pdfliteral{0 j}
+...\pdfliteral{10 M}
+...\pdfliteral{[] 0 d}
+...\hbox(0.0+0.0)x0.0
+....\pdfliteral{0 0 m}
+....\pdfliteral{283.46457 0 l}
+....\pdfliteral{141.73228 0 m}
+....\pdfliteral{141.73228 141.73228 l}
+....\pdfliteral{S}
+....\pdfsave
+....\hbox(0.0+0.0)x0.0
+.....\kern 56.90552
+.....\hbox(6.94444+0.0)x0.0, shifted -56.90552
+......\pdfsave
+......\pdfsetmatrix{1 0 0 1}
+......\hbox(6.94444+0.0)x0.0, glue set - 22.50005fil
+.......\hbox(6.94444+0.0)x22.50005
+........\OT1/cmr/m/n/10 H
+........\OT1/cmr/m/n/10 e
+........\OT1/cmr/m/n/10 l
+........\OT1/cmr/m/n/10 l
+........\OT1/cmr/m/n/10 o
+.......\glue 0.0 plus 1.0fil minus 1.0fil
+......\pdfrestore
+....\pdfrestore
+...\pdfrestore
+...\pdfcolorstack 0 pop
+! OK.
+<argument> \l_tmpa_box 
+l. ...  }
 ============================================================
 ============================================================
-TEST 2: \draw_coffin_use:N 
+TEST 2: \draw_coffin_use:Nnn (n)
 ============================================================
 > \box...=
 \hbox(142.66377+0.0)x284.92755
@@ -375,4 +414,50 @@ l. ...  }
 ! OK.
 <argument> \l_tmpa_box 
 l. ...  }
+> \box...=
+\hbox(142.66377+0.0)x284.92755
+.\hbox(142.66377+0.0)x284.92755
+..\glue 0.2
+..\hbox(0.0+0.0)x0.0, shifted -0.2
+...\pdfsave
+...\pdfliteral{0.39851 w}
+...\pdfcolorstack 0 push {0 g 0 G}
+...\pdfliteral{0 J}
+...\pdfliteral{0 j}
+...\pdfliteral{10 M}
+...\pdfliteral{[] 0 d}
+...\hbox(0.0+0.0)x0.0
+....\pdfliteral{0 0 m}
+....\pdfliteral{283.46457 0 l}
+....\pdfliteral{141.73228 0 m}
+....\pdfliteral{141.73228 141.73228 l}
+....\pdfliteral{S}
+....\pdfsave
+....\hbox(0.0+0.0)x0.0
+.....\kern 56.90552
+.....\hbox(6.94444+0.0)x0.0, shifted -56.90552
+......\pdfsave
+......\pdfsetmatrix{1 0 0 1}
+......\hbox(6.94444+0.0)x0.0, glue set - 22.50005fil
+.......\hbox(6.94444+0.0)x22.50005
+........\hbox(6.94444+0.0)x22.50005
+.........\hbox(0.0+0.0)x0.0
+.........\kern 0.0
+.........\kern 0.0
+.........\hbox(6.94444+0.0)x22.50005
+..........\pdfcolorstack 0 push {0 g 0 G}
+..........\OT1/cmr/m/n/10 H
+..........\OT1/cmr/m/n/10 e
+..........\OT1/cmr/m/n/10 l
+..........\OT1/cmr/m/n/10 l
+..........\OT1/cmr/m/n/10 o
+..........\pdfcolorstack 0 pop
+.......\glue 0.0 plus 1.0fil minus 1.0fil
+......\pdfrestore
+....\pdfrestore
+...\pdfrestore
+...\pdfcolorstack 0 pop
+! OK.
+<argument> \l_tmpa_box 
+l. ...  }
 ============================================================





More information about the latex3-commits mailing list.