Debian Codegraph @

texmf-dist/source/latex/l3experimental/l3draw/l3draw-boxes.dtx

raw
1 % \iffalse meta-comment
2 %
3 %% File: l3draw-boxes.dtx
4 %
5 % Copyright (C) 2018-2026 The LaTeX Project
6 %
7 % It may be distributed and/or modified under the conditions of the
8 % LaTeX Project Public License (LPPL), either version 1.3c of this
9 % license or (at your option) any later version. The latest version
10 % of this license is in the file
11 %
12 % http://www.latex-project.org/lppl.txt
13 %
14 % This file is part of the "l3experimental bundle" (The Work in LPPL)
15 % and all files in that bundle must be distributed together.
16 %
17 % -----------------------------------------------------------------------
18 %
19 % The development version of the bundle can be found at
20 %
21 % https://github.com/latex3/latex3
22 %
23 % for those people who are interested.
24 %
25 %<*driver>
26 \RequirePackage{expl3}
27 \documentclass[full]{l3doc}
28 \begin{document}
29 \DocInput{\jobname.dtx}
30 \end{document}
31 %</driver>
32 % \fi
33 %
34 % \title{^^A
35 % The \pkg{l3draw-boxes} package\\ Boxes in drawings^^A
36 % }
37 %
38 % \author{^^A
39 % The \LaTeX{} Project\thanks
40 % {^^A
41 % E-mail:
42 % \href{mailto:[email protected]}
43 % {[email protected]}^^A
44 % }^^A
45 % }
46 %
47 % \date{Released 2026-05-26}
48 %
49 % \maketitle
50 %
51 % \begin{implementation}
52 %
53 % \section{\pkg{l3draw-boxes} implementation}
54 %
55 % \begin{macrocode}
56 %<*package>
57 % \end{macrocode}
58 %
59 % \begin{macrocode}
60 %<@@=draw>
61 % \end{macrocode}
62 %
63 % Inserting boxes requires us to \enquote{interrupt} the drawing state,
64 % so is closely linked to scoping. At the same time, there are a few
65 % additional features required to make text work in a flexible way.
66 %
67 % \begin{variable}{\l_@@_tmp_box}
68 % \begin{macrocode}
69 \box_new:N \l_@@_tmp_box
70 % \end{macrocode}
71 % \end{variable}
72 %
73 % \begin{macro}{\draw_box_use:N}
74 % \begin{macro}{\draw_box_use:Nn}
75 % \begin{macro}{\@@_box_use:nNnnnnn}
76 % \begin{macro}{\@@_box_use:Nnnnn}
77 % Before inserting a box, we need to make sure that the bounding box is being
78 % updated correctly. As drawings track transformations as a whole, rather
79 % than as separate operations, we do the insertion using an almost-raw
80 % matrix. The process is split into two so that coffins are also supported.
81 % \begin{macrocode}
82 \cs_new_protected:Npn \draw_box_use:N #1
83 {
84 \@@_box_use:Nnnnnnn #1
85 { 0pt } { -\box_dp:N #1 } { \box_wd:N #1 } { \box_ht:N #1 }
86 }
87 \cs_new_protected:Npn \draw_box_use:Nn #1#2
88 {
89 \@@_box_use:nNnnnn {#2} #1
90 { 0pt } { -\box_dp:N #1 } { \box_wd:N #1 } { \box_ht:N #1 }
91 }
92 \cs_new_protected:Npn \@@_box_use:nNnnnn #1#2#3#4#5#6
93 {
94 \draw_scope_begin:
95 \draw_transform_shift:n {#1}
96 \@@_box_use:Nnnnnnn #2 {#3} {#4} {#5} {#6}
97 \draw_scope_end:
98 }
99 \cs_new_protected:Npn \@@_box_use:Nnnnnnn #1#2#3#4#5
100 {
101 \bool_if:NT \l_draw_bb_update_bool
102 {
103 \@@_point_process:nn
104 { \@@_path_update_limits:nn }
105 { \draw_point_transform:n { #2 , #3 } }
106 \@@_point_process:nn
107 { \@@_path_update_limits:nn }
108 { \draw_point_transform:n { #4 , #3 } }
109 \@@_point_process:nn
110 { \@@_path_update_limits:nn }
111 { \draw_point_transform:n { #4 , #5 } }
112 \@@_point_process:nn
113 { \@@_path_update_limits:nn }
114 { \draw_point_transform:n { #2 , #5 } }
115 }
116 \group_begin:
117 \hbox_set:Nn \l_@@_tmp_box
118 {
119 \use:e
120 {
121 \@@_backend_box_use:Nnnnn #1
122 { \fp_use:N \l_@@_matrix_a_fp }
123 { \fp_use:N \l_@@_matrix_b_fp }
124 { \fp_use:N \l_@@_matrix_c_fp }
125 { \fp_use:N \l_@@_matrix_d_fp }
126 }
127 }
128 \hbox_set:Nn \l_@@_tmp_box
129 {
130 \dim_horizontal:N \l_@@_xshift_dim
131 \box_move_up:nn { \l_@@_yshift_dim }
132 { \box_use_drop:N \l_@@_tmp_box }
133 }
134 \box_set_ht:Nn \l_@@_tmp_box { 0pt }
135 \box_set_dp:Nn \l_@@_tmp_box { 0pt }
136 \box_set_wd:Nn \l_@@_tmp_box { 0pt }
137 \box_use_drop:N \l_@@_tmp_box
138 \group_end:
139 }
140 % \end{macrocode}
141 % \end{macro}
142 % \end{macro}
143 % \end{macro}
144 % \end{macro}
145 %
146 % \begin{macro}{\draw_coffin_use:Nnn}
147 % \begin{macro}{\draw_coffin_use:Nnnn}
148 % \begin{macro}{\@@_coffin_use:nNnn}
149 % Slightly more than a shortcut: we have to allow for the fact that coffins
150 % have no apparent width before the reference point.
151 % \begin{macrocode}
152 \cs_new_protected:Npn \draw_coffin_use:Nnn #1#2#3
153 {
154 \@@_coffin_use:nNnn { \@@_box_use:Nnnnnnn }
155 #1 {#2} {#3}
156 }
157 \cs_new_protected:Npn \draw_coffin_use:Nnnn #1#2#3#4
158 {
159 \@@_coffin_use:nNnn { \@@_box_use:nNnnnn {#4} }
160 #1 {#2} {#3}
161 }
162 \cs_new_protected:Npn \@@_coffin_use:nNnn #1#2#3#4
163 {
164 \group_begin:
165 \hbox_set:Nn \l_@@_tmp_box
166 { \coffin_typeset:Nnnnn #2 {#3} {#4} { 0pt } { 0pt } }
167 #1 \l_@@_tmp_box
168 { \box_wd:N \l_@@_tmp_box - \coffin_wd:N #2 }
169 { -\box_dp:N \l_@@_tmp_box }
170 { \box_wd:N \l_@@_tmp_box }
171 { \box_ht:N \l_@@_tmp_box }
172 \group_end:
173 }
174 % \end{macrocode}
175 % \end{macro}
176 % \end{macro}
177 % \end{macro}
178 %
179 % \begin{macrocode}
180 %</package>
181 % \end{macrocode}
182 %
183 % \end{implementation}
184 %
185 % \PrintIndex