[latex3-commits] [git/LaTeX3-latex3-latex3] main: Implement \draw_baseline:n (fixes #964) (8a5de0515)
Joseph Wright
joseph.wright at morningstar2.co.uk
Fri Jul 16 16:44:10 CEST 2021
Repository : https://github.com/latex3/latex3
On branch : main
Link : https://github.com/latex3/latex3/commit/8a5de0515265098d5e6bd1110d0970e8426e3662
>---------------------------------------------------------------
commit 8a5de0515265098d5e6bd1110d0970e8426e3662
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date: Fri Jul 16 15:44:10 2021 +0100
Implement \draw_baseline:n (fixes #964)
>---------------------------------------------------------------
8a5de0515265098d5e6bd1110d0970e8426e3662
l3experimental/CHANGELOG.md | 3 +
l3experimental/l3draw/l3draw-scopes.dtx | 96 ++++++++++++++++++++--
l3experimental/l3draw/l3draw.dtx | 37 +++++++++
l3experimental/l3draw/testfiles/m3draw004.lvt | 7 ++
l3experimental/l3draw/testfiles/m3draw004.ptex.tlg | 91 ++++++++++++++++++++
l3experimental/l3draw/testfiles/m3draw004.tlg | 70 ++++++++++++++++
.../l3draw/testfiles/m3draw004.uptex.tlg | 91 ++++++++++++++++++++
.../l3draw/testfiles/m3draw004.xetex.tlg | 73 ++++++++++++++++
8 files changed, 459 insertions(+), 9 deletions(-)
diff --git a/l3experimental/CHANGELOG.md b/l3experimental/CHANGELOG.md
index 5ad7f3d18..600a8ee9e 100644
--- a/l3experimental/CHANGELOG.md
+++ b/l3experimental/CHANGELOG.md
@@ -7,6 +7,9 @@ this project uses date-based 'snapshot' version identifiers.
## [Unreleased]
+### Added
+- `\draw_baseline:n`
+
## [2021-07-12]
### Added
diff --git a/l3experimental/l3draw/l3draw-scopes.dtx b/l3experimental/l3draw/l3draw-scopes.dtx
index 0e2bdd747..41ad6f280 100644
--- a/l3experimental/l3draw/l3draw-scopes.dtx
+++ b/l3experimental/l3draw/l3draw-scopes.dtx
@@ -150,6 +150,7 @@
}
\cs_new_protected:Npn \draw_end:
{
+ \@@_baseline_finalise:w
\exp_args:NNNV \hbox_set_end:
\clist_set:Nn \l_draw_layers_clist \l_draw_layers_clist
\@@_layers_insert:
@@ -162,15 +163,7 @@
\dim_gzero:N \g_@@_ymax_dim
\dim_gzero:N \g_@@_ymin_dim
}
- \hbox_set:Nn \l_@@_main_box
- {
- \skip_horizontal:n { -\g_@@_xmin_dim }
- \box_move_down:nn { \g_@@_ymin_dim }
- { \box_use_drop:N \l_@@_main_box }
- }
- \box_set_ht:Nn \l_@@_main_box
- { \g_@@_ymax_dim - \g_@@_ymin_dim }
- \box_set_dp:Nn \l_@@_main_box { 0pt }
+ \@@_finalise:
\box_set_wd:Nn \l_@@_main_box
{ \g_@@_xmax_dim - \g_@@_xmin_dim }
\mode_leave_vertical:
@@ -180,6 +173,91 @@
% \end{macrocode}
% \end{macro}
%
+% \begin{macro}{\@@_finalise:}
+% \begin{macro}{\@@_finalise_baseline:n}
+% Finalising the (vertical) size of the output depends on whether we have
+% an explicit baseline or not. To allow for that, we have two functions, and
+% the one that's used depends on whether the user has set a baseline. Notice
+% that in contrast to \pkg{pgf} we \emph{do} allow for a non-zero depth if
+% the explicit baseline is above the lowest edge of the initial bounding box.
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_finalise:
+ {
+ \hbox_set:Nn \l_@@_main_box
+ {
+ \skip_horizontal:n { -\g_@@_xmin_dim }
+ \box_move_down:nn
+ { \g_@@_ymin_dim }
+ { \box_use_drop:N \l_@@_main_box }
+ }
+ \box_set_dp:Nn \l_@@_main_box { 0pt }
+ \box_set_ht:Nn \l_@@_main_box
+ { \g_@@_ymax_dim - \g_@@_ymin_dim }
+ }
+\cs_new_protected:Npn \@@_finalise_baseline:n #1
+ {
+ \hbox_set:Nn \l_@@_main_box
+ {
+ \skip_horizontal:n { -\g_@@_xmin_dim }
+ \box_move_down:nn
+ {#1}
+ { \box_use_drop:N \l_@@_main_box }
+ }
+ \box_set_dp:Nn \l_@@_main_box
+ {
+ \dim_max:nn
+ { #1 - \g_@@_ymin_dim }
+ { 0pt }
+ }
+ \box_set_ht:Nn \l_@@_main_box
+ { \g_@@_ymax_dim + #1 }
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \subsection{Baseline position}
+%
+% \begin{variable}{\l_@@_baseline_bool, \l_@@_baseline_dim}
+% For tracking the explicit baseline and whether it is active.
+% \begin{macrocode}
+\bool_new:N \l_@@_baseline_bool
+\dim_new:N \l_@@_baseline_dim
+% \end{macrocode}
+% \end{variable}
+%
+% \begin{macro}{\draw_baseline:n}
+% A simple setting of the baseline along with the flag we need to know that
+% it is active.
+% \begin{macrocode}
+\cs_new_protected:Npn \draw_baseline:n #1
+ {
+ \bool_set_true:N \l_@@_baseline_bool
+ \dim_set:Nn \l_@@_baseline_dim { \fp_to_dim:n {#1} }
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\@@_baseline_finalise:w}
+% Rather than use a global data structure, we can arrange to put the baseline
+% value at the right group level with a small amount of shuffling. That happens
+% here.
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_baseline_finalise:w #1 \@@_finalise:
+ {
+ \bool_if:NTF \l_@@_baseline_bool
+ {
+ \use:x
+ {
+ \exp_not:n {#1}
+ \@@_finalise_baseline:n { \dim_use:N \l_@@_baseline_dim }
+ }
+ }
+ { #1 \@@_finalise: }
+ }
+% \end{macrocode}
+% \end{macro}
+%
% \subsection{Scopes}
%
% \begin{variable}{\l_@@_linewidth_dim}
diff --git a/l3experimental/l3draw/l3draw.dtx b/l3experimental/l3draw/l3draw.dtx
index 015e4781a..48b634a24 100644
--- a/l3experimental/l3draw/l3draw.dtx
+++ b/l3experimental/l3draw/l3draw.dtx
@@ -185,6 +185,43 @@
% axes at the driver level: this is then \enquote{transparent} to the
% \pkg{draw} level, and so should be used only when strictly required.)
%
+% The bounding box of the drawing is determined by tracking the size of the
+% \pkg{draw} commands between the start and end. The bounding box is (roughly)
+% the smallest box that contains all of the co-ordinates mentioned within the
+% drawing. This can include those automatically generated, for example the
+% supporting points needed to construct an arc.
+%
+% \begin{function}{\draw_baseline:n}
+% \begin{syntax}
+% \cs{draw_baseline:n} \Arg{length}
+% \end{syntax}
+% As standard, the baseline of the bounding box of a drawing is calculated
+% automatically at the bottom of the drawing. It is possible to adjust this
+% using the \cs{draw_baseline:n} function. If the drawing co-ordinates lead
+% to lower $y$-axis values than the \meta{length}, then the drawing will have
+% a depth as well as a height.
+% \begin{demo}
+% text
+% \draw_begin:
+% \draw_path_rectangle:nn { 0 , 0 } { 2ex , 1ex }
+% \draw_path_use:n { stroke }
+% \draw_end:
+% text
+% \draw_begin:
+% \draw_path_rectangle:nn { 0 , 1ex } { 2ex , 1ex }
+% \draw_baseline:n { 0pt }
+% \draw_path_use:n { stroke }
+% \draw_end:
+% text
+% \draw_begin:
+% \draw_path_rectangle:nn { 0 , -1ex } { 2ex , 1ex }
+% \draw_baseline:n { -0.5ex }
+% \draw_path_use:n { stroke }
+% \draw_end:
+% text
+% \end{demo}
+% \end{function}
+%
% \begin{function}{\draw_suspend_begin:, \draw_suspend_end:}
% \begin{syntax}
% \cs{draw_suspend_begin:}
diff --git a/l3experimental/l3draw/testfiles/m3draw004.lvt b/l3experimental/l3draw/testfiles/m3draw004.lvt
index bec03040b..928f68579 100644
--- a/l3experimental/l3draw/testfiles/m3draw004.lvt
+++ b/l3experimental/l3draw/testfiles/m3draw004.lvt
@@ -111,4 +111,11 @@
}
}
+\TEST { \draw_baseline:n }
+ {
+ \test:n { }
+ \test:n { \draw_baseline:n { 5cm } }
+ \test:n { \draw_baseline:n { -5cm } }
+ }
+
\END
diff --git a/l3experimental/l3draw/testfiles/m3draw004.ptex.tlg b/l3experimental/l3draw/testfiles/m3draw004.ptex.tlg
index 521f4b379..8c3629966 100644
--- a/l3experimental/l3draw/testfiles/m3draw004.ptex.tlg
+++ b/l3experimental/l3draw/testfiles/m3draw004.ptex.tlg
@@ -651,3 +651,94 @@ TEST 9: \color_stroke:n
<argument> \l_tmpa_box
l. ... }
============================================================
+============================================================
+TEST 10: \draw_baseline:n
+============================================================
+> \box...=
+\hbox(284.92755+0.0)x57.30551
+.\hbox(284.92755+0.0)x57.30551
+..\glue 0.2
+..\hbox(0.0+0.0)x0.0, shifted -0.2
+...\special{ps::[begin]}
+...\special{ps::@beginspecial}
+...\special{ps::0.3985 setlinewidth}
+...\special{color push gray 0}
+...\special{ps:SDict begin /color.sc {} def end}
+...\special{ps::0 setlinecap}
+...\special{ps::0 setlinejoin}
+...\special{ps::10 setmiterlimit}
+...\special{ps::[] 0 setdash}
+...\hbox(0.0+0.0)x0.0
+....\special{ps::0 0 moveto}
+....\special{ps::28.34647 283.46457 lineto}
+....\special{ps::56.69292 0 lineto}
+....\special{ps::gsave}
+....\special{ps::color.sc}
+....\special{ps::stroke}
+....\special{ps::grestore}
+....\special{ps::newpath}
+...\special{ps::@endspecial}
+...\special{ps::[end]}
+...\special{color pop}
+! OK.
+<argument> \l_tmpa_box
+l. ... }
+> \box...=
+\hbox(426.99133+142.46378)x57.30551
+.\hbox(426.99133+142.46378)x57.30551
+..\glue 0.2
+..\hbox(0.0+0.0)x0.0, shifted 142.26378
+...\special{ps::[begin]}
+...\special{ps::@beginspecial}
+...\special{ps::0.3985 setlinewidth}
+...\special{color push gray 0}
+...\special{ps:SDict begin /color.sc {} def end}
+...\special{ps::0 setlinecap}
+...\special{ps::0 setlinejoin}
+...\special{ps::10 setmiterlimit}
+...\special{ps::[] 0 setdash}
+...\hbox(0.0+0.0)x0.0
+....\special{ps::0 0 moveto}
+....\special{ps::28.34647 283.46457 lineto}
+....\special{ps::56.69292 0 lineto}
+....\special{ps::gsave}
+....\special{ps::color.sc}
+....\special{ps::stroke}
+....\special{ps::grestore}
+....\special{ps::newpath}
+...\special{ps::@endspecial}
+...\special{ps::[end]}
+...\special{color pop}
+! OK.
+<argument> \l_tmpa_box
+l. ... }
+> \box...=
+\hbox(142.46378+0.0)x57.30551
+.\hbox(142.46378+0.0)x57.30551
+..\glue 0.2
+..\hbox(0.0+0.0)x0.0, shifted -142.26378
+...\special{ps::[begin]}
+...\special{ps::@beginspecial}
+...\special{ps::0.3985 setlinewidth}
+...\special{color push gray 0}
+...\special{ps:SDict begin /color.sc {} def end}
+...\special{ps::0 setlinecap}
+...\special{ps::0 setlinejoin}
+...\special{ps::10 setmiterlimit}
+...\special{ps::[] 0 setdash}
+...\hbox(0.0+0.0)x0.0
+....\special{ps::0 0 moveto}
+....\special{ps::28.34647 283.46457 lineto}
+....\special{ps::56.69292 0 lineto}
+....\special{ps::gsave}
+....\special{ps::color.sc}
+....\special{ps::stroke}
+....\special{ps::grestore}
+....\special{ps::newpath}
+...\special{ps::@endspecial}
+...\special{ps::[end]}
+...\special{color pop}
+! OK.
+<argument> \l_tmpa_box
+l. ... }
+============================================================
diff --git a/l3experimental/l3draw/testfiles/m3draw004.tlg b/l3experimental/l3draw/testfiles/m3draw004.tlg
index 04c398ac9..b7c03aa0e 100644
--- a/l3experimental/l3draw/testfiles/m3draw004.tlg
+++ b/l3experimental/l3draw/testfiles/m3draw004.tlg
@@ -499,3 +499,73 @@ TEST 9: \color_stroke:n
<argument> \l_tmpa_box
l. ... }
============================================================
+============================================================
+TEST 10: \draw_baseline:n
+============================================================
+> \box...=
+\hbox(284.92755+0.0)x57.30551
+.\hbox(284.92755+0.0)x57.30551
+..\glue 0.2
+..\hbox(0.0+0.0)x0.0, shifted -0.2
+...\pdfsave
+...\pdfliteral{0.3985 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{28.34647 283.46457 l}
+....\pdfliteral{56.69292 0 l}
+....\pdfliteral{S}
+...\pdfrestore
+...\pdfcolorstack 0 pop
+! OK.
+<argument> \l_tmpa_box
+l. ... }
+> \box...=
+\hbox(426.99133+142.46378)x57.30551
+.\hbox(426.99133+142.46378)x57.30551
+..\glue 0.2
+..\hbox(0.0+0.0)x0.0, shifted 142.26378
+...\pdfsave
+...\pdfliteral{0.3985 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{28.34647 283.46457 l}
+....\pdfliteral{56.69292 0 l}
+....\pdfliteral{S}
+...\pdfrestore
+...\pdfcolorstack 0 pop
+! OK.
+<argument> \l_tmpa_box
+l. ... }
+> \box...=
+\hbox(142.46378+0.0)x57.30551
+.\hbox(142.46378+0.0)x57.30551
+..\glue 0.2
+..\hbox(0.0+0.0)x0.0, shifted -142.26378
+...\pdfsave
+...\pdfliteral{0.3985 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{28.34647 283.46457 l}
+....\pdfliteral{56.69292 0 l}
+....\pdfliteral{S}
+...\pdfrestore
+...\pdfcolorstack 0 pop
+! OK.
+<argument> \l_tmpa_box
+l. ... }
+============================================================
diff --git a/l3experimental/l3draw/testfiles/m3draw004.uptex.tlg b/l3experimental/l3draw/testfiles/m3draw004.uptex.tlg
index 521f4b379..8c3629966 100644
--- a/l3experimental/l3draw/testfiles/m3draw004.uptex.tlg
+++ b/l3experimental/l3draw/testfiles/m3draw004.uptex.tlg
@@ -651,3 +651,94 @@ TEST 9: \color_stroke:n
<argument> \l_tmpa_box
l. ... }
============================================================
+============================================================
+TEST 10: \draw_baseline:n
+============================================================
+> \box...=
+\hbox(284.92755+0.0)x57.30551
+.\hbox(284.92755+0.0)x57.30551
+..\glue 0.2
+..\hbox(0.0+0.0)x0.0, shifted -0.2
+...\special{ps::[begin]}
+...\special{ps::@beginspecial}
+...\special{ps::0.3985 setlinewidth}
+...\special{color push gray 0}
+...\special{ps:SDict begin /color.sc {} def end}
+...\special{ps::0 setlinecap}
+...\special{ps::0 setlinejoin}
+...\special{ps::10 setmiterlimit}
+...\special{ps::[] 0 setdash}
+...\hbox(0.0+0.0)x0.0
+....\special{ps::0 0 moveto}
+....\special{ps::28.34647 283.46457 lineto}
+....\special{ps::56.69292 0 lineto}
+....\special{ps::gsave}
+....\special{ps::color.sc}
+....\special{ps::stroke}
+....\special{ps::grestore}
+....\special{ps::newpath}
+...\special{ps::@endspecial}
+...\special{ps::[end]}
+...\special{color pop}
+! OK.
+<argument> \l_tmpa_box
+l. ... }
+> \box...=
+\hbox(426.99133+142.46378)x57.30551
+.\hbox(426.99133+142.46378)x57.30551
+..\glue 0.2
+..\hbox(0.0+0.0)x0.0, shifted 142.26378
+...\special{ps::[begin]}
+...\special{ps::@beginspecial}
+...\special{ps::0.3985 setlinewidth}
+...\special{color push gray 0}
+...\special{ps:SDict begin /color.sc {} def end}
+...\special{ps::0 setlinecap}
+...\special{ps::0 setlinejoin}
+...\special{ps::10 setmiterlimit}
+...\special{ps::[] 0 setdash}
+...\hbox(0.0+0.0)x0.0
+....\special{ps::0 0 moveto}
+....\special{ps::28.34647 283.46457 lineto}
+....\special{ps::56.69292 0 lineto}
+....\special{ps::gsave}
+....\special{ps::color.sc}
+....\special{ps::stroke}
+....\special{ps::grestore}
+....\special{ps::newpath}
+...\special{ps::@endspecial}
+...\special{ps::[end]}
+...\special{color pop}
+! OK.
+<argument> \l_tmpa_box
+l. ... }
+> \box...=
+\hbox(142.46378+0.0)x57.30551
+.\hbox(142.46378+0.0)x57.30551
+..\glue 0.2
+..\hbox(0.0+0.0)x0.0, shifted -142.26378
+...\special{ps::[begin]}
+...\special{ps::@beginspecial}
+...\special{ps::0.3985 setlinewidth}
+...\special{color push gray 0}
+...\special{ps:SDict begin /color.sc {} def end}
+...\special{ps::0 setlinecap}
+...\special{ps::0 setlinejoin}
+...\special{ps::10 setmiterlimit}
+...\special{ps::[] 0 setdash}
+...\hbox(0.0+0.0)x0.0
+....\special{ps::0 0 moveto}
+....\special{ps::28.34647 283.46457 lineto}
+....\special{ps::56.69292 0 lineto}
+....\special{ps::gsave}
+....\special{ps::color.sc}
+....\special{ps::stroke}
+....\special{ps::grestore}
+....\special{ps::newpath}
+...\special{ps::@endspecial}
+...\special{ps::[end]}
+...\special{color pop}
+! OK.
+<argument> \l_tmpa_box
+l. ... }
+============================================================
diff --git a/l3experimental/l3draw/testfiles/m3draw004.xetex.tlg b/l3experimental/l3draw/testfiles/m3draw004.xetex.tlg
index 1ae061672..5a747446f 100644
--- a/l3experimental/l3draw/testfiles/m3draw004.xetex.tlg
+++ b/l3experimental/l3draw/testfiles/m3draw004.xetex.tlg
@@ -518,3 +518,76 @@ TEST 9: \color_stroke:n
<argument> \l_tmpa_box
l. ... }
============================================================
+============================================================
+TEST 10: \draw_baseline:n
+============================================================
+> \box...=
+\hbox(284.92755+0.0)x57.30551
+.\hbox(284.92755+0.0)x57.30551
+..\glue 0.2
+..\hbox(0.0+0.0)x0.0, shifted -0.2
+...\special{x:gsave}
+...\special{pdf:literal 0.3985 w}
+...\special{pdfcolorstack 1 push (0 g 0 G)}
+...\special{pdf:literal 0 J}
+...\special{pdf:literal 0 j}
+...\special{pdf:literal 10 M}
+...\special{pdf:literal [] 0 d}
+...\hbox(0.0+0.0)x0.0
+....\special{pdf:literal 0 0 m}
+....\special{pdf:literal 28.34647 283.46457 l}
+....\special{pdf:literal 56.69292 0 l}
+....\special{pdf:literal S}
+...\special{x:grestore}
+...\special{pdfcolorstack \g__color_backend_stack_int current}
+...\special{pdfcolorstack 1 pop}
+! OK.
+<argument> \l_tmpa_box
+l. ... }
+> \box...=
+\hbox(426.99133+142.46378)x57.30551
+.\hbox(426.99133+142.46378)x57.30551
+..\glue 0.2
+..\hbox(0.0+0.0)x0.0, shifted 142.26378
+...\special{x:gsave}
+...\special{pdf:literal 0.3985 w}
+...\special{pdfcolorstack 1 push (0 g 0 G)}
+...\special{pdf:literal 0 J}
+...\special{pdf:literal 0 j}
+...\special{pdf:literal 10 M}
+...\special{pdf:literal [] 0 d}
+...\hbox(0.0+0.0)x0.0
+....\special{pdf:literal 0 0 m}
+....\special{pdf:literal 28.34647 283.46457 l}
+....\special{pdf:literal 56.69292 0 l}
+....\special{pdf:literal S}
+...\special{x:grestore}
+...\special{pdfcolorstack \g__color_backend_stack_int current}
+...\special{pdfcolorstack 1 pop}
+! OK.
+<argument> \l_tmpa_box
+l. ... }
+> \box...=
+\hbox(142.46378+0.0)x57.30551
+.\hbox(142.46378+0.0)x57.30551
+..\glue 0.2
+..\hbox(0.0+0.0)x0.0, shifted -142.26378
+...\special{x:gsave}
+...\special{pdf:literal 0.3985 w}
+...\special{pdfcolorstack 1 push (0 g 0 G)}
+...\special{pdf:literal 0 J}
+...\special{pdf:literal 0 j}
+...\special{pdf:literal 10 M}
+...\special{pdf:literal [] 0 d}
+...\hbox(0.0+0.0)x0.0
+....\special{pdf:literal 0 0 m}
+....\special{pdf:literal 28.34647 283.46457 l}
+....\special{pdf:literal 56.69292 0 l}
+....\special{pdf:literal S}
+...\special{x:grestore}
+...\special{pdfcolorstack \g__color_backend_stack_int current}
+...\special{pdfcolorstack 1 pop}
+! OK.
+<argument> \l_tmpa_box
+l. ... }
+============================================================
More information about the latex3-commits
mailing list.