Debian Codegraph @

texmf-dist/tex/latex/hawkdraw/hawkdraw-nodes.code.tex

raw
1 % File: hawkdraw-nodes.code.tex
2 % Copyright 2026 Jasper Habicht (mail(at)jasperhabicht.de).
3 %
4 % This work may be distributed and/or modified under the
5 % conditions of the LaTeX Project Public License version 1.3c,
6 % available at http://www.latex-project.org/lppl/.
7 %
8 % This file is part of the `hawkdraw' package (The Work in LPPL)
9 % and all files in that bundle must be distributed together.
10 %
11 % This work has the LPPL maintenance status `maintained'.
12 %
13 % BOF
14
15 % v0.0.7 2026-05-25
16
17 \msg_new:nnn { hawkdraw } { node-unknown } {
18 Node ~ frame ~ `#1` ~ unknown.
19 }
20
21 \bool_new:N \l__hawkdraw_node_vbox_bool
22 \coffin_new:N \l_hawkdraw_node_coffin
23 \coffin_new:N \l_hawkdraw_node_frame_coffin
24
25 \clist_new:N \l_hawkdraw_node_anchor_clist
26 \dim_new:N \l_hawkdraw_node_width_dim
27 \clist_new:N \l_hawkdraw_node_padding_clist
28 \dim_new:N \l_hawkdraw_node_padding_left_dim
29 \dim_new:N \l_hawkdraw_node_padding_right_dim
30 \dim_new:N \l_hawkdraw_node_padding_top_dim
31 \dim_new:N \l_hawkdraw_node_padding_bottom_dim
32 \str_new:N \l_hawkdraw_node_text_color_str
33 \str_new:N \l_hawkdraw_node_frame_str
34
35 \cs_generate_variant:Nn \keys_set_known:nnN { nV }
36 \cs_generate_variant:Nn \draw_coffin_use:Nnnn { NeeV }
37 \cs_generate_variant:Nn \coffin_attach:NnnNnnnn { NnnNnnVV }
38
39 \keys_define:nn { hawkdraw / path / node } {
40 anchor .clist_set:N = \l_hawkdraw_node_anchor_clist ,
41 anchor .initial:n = { hc , vc } ,
42 width .code:n = {
43 \bool_set_true:N \l__hawkdraw_node_vbox_bool
44 \dim_set:Nn \l_hawkdraw_node_width_dim {#1}
45 } ,
46 padding .clist_set:N = \l_hawkdraw_node_padding_clist ,
47 padding .initial:n = { 5pt } ,
48 text ~ color .str_set:N = \l_hawkdraw_node_text_color_str ,
49 text ~ color .initial:n = { . } ,
50 frame .str_set:N = \l_hawkdraw_node_frame_str ,
51 frame .initial:n = { rectangle } ,
52 }
53
54 \cs_new_protected:cpn { __hawkdraw_process_path_ n :w } node #1#2 \s__hawkdraw_stop {
55 \cs_if_exist_use:cTF {
56 __hawkdraw_process_path_node_ \tl_head:n {#1} :w
57 } {
58 #1#2 \s__hawkdraw_stop
59 } {
60 \hawkdraw_put_node:nn { } {#1}
61 \tl_trim_spaces_apply:nN {#2} \__hawkdraw_continue_path:n
62 }
63 }
64
65 \cs_new_protected:cpn { __hawkdraw_process_path_node_ [ :w } [ #1 ] #2#3 \s__hawkdraw_stop {
66 \hawkdraw_put_node:nn {#1} {#2}
67 \tl_trim_spaces_apply:nN {#3} \__hawkdraw_continue_path:n
68 }
69
70 \cs_new_protected:Npn \hawkdraw_put_node:nn #1#2 {
71 \draw_scope_begin:
72 \fp_set_eq:NN \l_hawkdraw_point_at_fp \g_hawkdraw_path_last_point_fp
73 \clist_clear:N \l__hawkdraw_keys_unprocessed_clist
74 \fp_set:Nn \l_hawkdraw_point_at_path_part_fp { nan }
75 \keys_set_known:nnN { hawkdraw / path / point } {#1}
76 \l__hawkdraw_keys_unprocessed_clist
77 \fp_if_nan:nF { \l_hawkdraw_point_at_path_part_fp } {
78 \fp_set:Nn \l_hawkdraw_point_at_fp {
79 \cs_if_exist_use:cT {
80 __hawkdraw_point_part_ \l__hawkdraw_path_type_str :V
81 } {
82 \l_hawkdraw_point_at_path_part_fp
83 }
84 }
85 }
86 \keys_set_known:nVN { hawkdraw / path / node }
87 \l__hawkdraw_keys_unprocessed_clist
88 \l__hawkdraw_keys_unprocessed_clist
89 \tl_if_blank:nF \l_hawkdraw_point_name_tl {
90 \prop_gput:cVV { g__hawkdraw_points_ \int_use:N \g_hawkdraw_id_int _prop }
91 \l_hawkdraw_point_name_tl
92 \l_hawkdraw_point_at_fp
93 }
94 \bool_if:NTF \l__hawkdraw_node_vbox_bool {
95 \vcoffin_set:Nnn \l_hawkdraw_node_coffin {
96 \l_hawkdraw_node_width_dim
97 } {
98 \color_select:V \l_hawkdraw_node_text_color_str
99 \normalfont #2
100 }
101 } {
102 \hcoffin_set:Nn \l_hawkdraw_node_coffin {
103 \color_select:V \l_hawkdraw_node_text_color_str
104 \normalfont #2
105 }
106 }
107 \__hawkdraw_set_node_padding:
108 \__hawkdraw_set_node_frame:V \l__hawkdraw_keys_unprocessed_clist
109 \coffin_attach:NnnNnnnn
110 \l_hawkdraw_node_frame_coffin { hc } { vc }
111 \l_hawkdraw_node_coffin { hc } { vc }
112 { 0.5 \l_hawkdraw_node_padding_left_dim - 0.5 \l_hawkdraw_node_padding_right_dim }
113 { 0.5 \l_hawkdraw_node_padding_bottom_dim - 0.5 \l_hawkdraw_node_padding_top_dim }
114 \exp_args:Ne
115 \draw_coffin_use:NeeV \l_hawkdraw_node_frame_coffin {
116 \clist_item:Nn \l_hawkdraw_node_anchor_clist { 1 }
117 } {
118 \clist_item:Nn \l_hawkdraw_node_anchor_clist { 2 }
119 } \l_hawkdraw_point_at_fp
120 \draw_scope_end:
121 }
122
123 \cs_new_protected:Npn \__hawkdraw_set_node_padding: {
124 \int_case:nn { \clist_count:N \l_hawkdraw_node_padding_clist } {
125 { 1 } {
126 \dim_set:Nn \l_hawkdraw_node_padding_left_dim {
127 \clist_item:Nn \l_hawkdraw_node_padding_clist { 1 }
128 }
129 \dim_set:Nn \l_hawkdraw_node_padding_right_dim {
130 \clist_item:Nn \l_hawkdraw_node_padding_clist { 1 }
131 }
132 \dim_set:Nn \l_hawkdraw_node_padding_top_dim {
133 \clist_item:Nn \l_hawkdraw_node_padding_clist { 1 }
134 }
135 \dim_set:Nn \l_hawkdraw_node_padding_bottom_dim {
136 \clist_item:Nn \l_hawkdraw_node_padding_clist { 1 }
137 }
138 }
139 { 2 } {
140 \dim_set:Nn \l_hawkdraw_node_padding_left_dim {
141 \clist_item:Nn \l_hawkdraw_node_padding_clist { 2 }
142 }
143 \dim_set:Nn \l_hawkdraw_node_padding_right_dim {
144 \clist_item:Nn \l_hawkdraw_node_padding_clist { 2 }
145 }
146 \dim_set:Nn \l_hawkdraw_node_padding_top_dim {
147 \clist_item:Nn \l_hawkdraw_node_padding_clist { 1 }
148 }
149 \dim_set:Nn \l_hawkdraw_node_padding_bottom_dim {
150 \clist_item:Nn \l_hawkdraw_node_padding_clist { 1 }
151 }
152 }
153 { 3 } {
154 \dim_set:Nn \l_hawkdraw_node_padding_left_dim {
155 \clist_item:Nn \l_hawkdraw_node_padding_clist { 2 }
156 }
157 \dim_set:Nn \l_hawkdraw_node_padding_right_dim {
158 \clist_item:Nn \l_hawkdraw_node_padding_clist { 2 }
159 }
160 \dim_set:Nn \l_hawkdraw_node_padding_top_dim {
161 \clist_item:Nn \l_hawkdraw_node_padding_clist { 1 }
162 }
163 \dim_set:Nn \l_hawkdraw_node_padding_bottom_dim {
164 \clist_item:Nn \l_hawkdraw_node_padding_clist { 3 }
165 }
166 }
167 { 4 } {
168 \dim_set:Nn \l_hawkdraw_node_padding_left_dim {
169 \clist_item:Nn \l_hawkdraw_node_padding_clist { 4 }
170 }
171 \dim_set:Nn \l_hawkdraw_node_padding_right_dim {
172 \clist_item:Nn \l_hawkdraw_node_padding_clist { 2 }
173 }
174 \dim_set:Nn \l_hawkdraw_node_padding_top_dim {
175 \clist_item:Nn \l_hawkdraw_node_padding_clist { 1 }
176 }
177 \dim_set:Nn \l_hawkdraw_node_padding_bottom_dim {
178 \clist_item:Nn \l_hawkdraw_node_padding_clist { 3 }
179 }
180 }
181 }
182 }
183
184 \cs_new_protected:Npn \__hawkdraw_set_node_frame:n #1 {
185 \hcoffin_set:Nn \l_hawkdraw_node_frame_coffin {
186 \draw_suspend_begin:
187 \draw_begin:
188 \keys_set:nn { hawkdraw / path } {#1}
189 \hawkdraw_set_path_options:
190 \cs_if_exist_use:cTF { hawkdraw_node_frame_ \l_hawkdraw_node_frame_str :NVVVV } {
191 \l_hawkdraw_node_coffin
192 \l_hawkdraw_node_padding_left_dim
193 \l_hawkdraw_node_padding_right_dim
194 \l_hawkdraw_node_padding_top_dim
195 \l_hawkdraw_node_padding_bottom_dim
196 } {
197 \msg_warning:nnV { hawkdraw } { node-unknown } \l_hawkdraw_node_frame_str
198 }
199 \clist_remove_duplicates:N \l_hawkdraw_path_use_clist
200 \draw_path_use_clear:e { \clist_use:N \l_hawkdraw_path_use_clist }
201 \draw_end:
202 \draw_suspend_end:
203 }
204 }
205 \cs_generate_variant:Nn \__hawkdraw_set_node_frame:n { V }
206
207 \dim_new:N \hawkdraw_node_natural_width_dim
208 \dim_new:N \hawkdraw_node_natural_height_dim
209
210 \cs_new_protected:Npn \hawkdraw_node_create_frame:nn #1#2 {
211 \cs_new_protected:cpn { hawkdraw_node_frame_ #1 :Nnnnn } ##1##2##3##4##5 {
212 \dim_set:Nn \hawkdraw_node_natural_width_dim {
213 \coffin_wd:N ##1 + ##2 + ##3
214 }
215 \dim_set:Nn \hawkdraw_node_natural_height_dim {
216 \coffin_ht_plus_dp:N ##1 + ##4 + ##5
217 }
218 #2
219 }
220 \cs_generate_variant:cn { hawkdraw_node_frame_ #1 :Nnnnn } { NVVVV }
221 }
222
223 % ===
224
225 \hawkdraw_node_create_frame:nn { none } { }
226
227 \hawkdraw_node_create_frame:nn { rectangle } {
228 \draw_path_rectangle:nn {
229 (
230 -0.5 * \hawkdraw_node_natural_width_dim
231 ,
232 -0.5 * \hawkdraw_node_natural_width_dim
233 )
234 } {
235 (
236 \hawkdraw_node_natural_width_dim
237 ,
238 \hawkdraw_node_natural_height_dim
239 )
240 }
241 }
242
243 \hawkdraw_node_create_frame:nn { ellipse } {
244 \draw_path_ellipse:nnn { 0pt , 0pt } {
245 ( 0.5 * \hawkdraw_node_natural_width_dim , 0pt )
246 } {
247 ( 0pt , 0.5 * \hawkdraw_node_natural_height_dim )
248 }
249 }
250
251 \hawkdraw_node_create_frame:nn { circle } {
252 \draw_path_circle:nn { 0pt , 0pt } {
253 max(
254 0.5 * \hawkdraw_node_natural_width_dim
255 ,
256 0.5 * \hawkdraw_node_natural_height_dim
257 )
258 }
259 }
260
261 \hawkdraw_node_create_frame:nn { diamond } {
262 \draw_path_moveto:n {
263 ( 0pt , \hawkdraw_node_natural_height_dim )
264 }
265 \draw_path_lineto:n {
266 ( \hawkdraw_node_natural_width_dim , 0pt )
267 }
268 \draw_path_lineto:n {
269 ( 0pt , -1 * \hawkdraw_node_natural_height_dim )
270 }
271 \draw_path_lineto:n {
272 ( -1 * \hawkdraw_node_natural_width_dim , 0pt )
273 }
274 \draw_path_close:
275 }
276
277 % EOF