| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
%% File: l3draw-paths.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-paths} package\\ Drawing paths^^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-paths} implementation} |
| 54 |
% |
| 55 |
% \begin{macrocode} |
| 56 |
%<*package> |
| 57 |
% \end{macrocode} |
| 58 |
% |
| 59 |
% \begin{macrocode} |
| 60 |
%<@@=draw> |
| 61 |
% \end{macrocode} |
| 62 |
% |
| 63 |
% This sub-module covers more-or-less the same ideas as |
| 64 |
% \texttt{pgfcorepathconstruct.code.tex}, though using the expandable FPU |
| 65 |
% means that the implementation often varies. At present, equivalents of the |
| 66 |
% following are currently absent: |
| 67 |
% \begin{itemize} |
| 68 |
% \item \cs{pgfpatharcto}, \cs{pgfpatharctoprecomputed}: These are |
| 69 |
% extremely specialized and are very complex in implementation. If the |
| 70 |
% functionality is required, it is likely that it will be set up from |
| 71 |
% scratch here. |
| 72 |
% \item \cs{pgfpathparabola}: Seems to be unused other than defining |
| 73 |
% a Ti\emph{k}Z interface, which itself is then not used further. |
| 74 |
% \item \cs{pgfpathsine}, \cs{pgfpathcosine}: Need to see exactly how |
| 75 |
% these need to work, in particular whether a wider input range is |
| 76 |
% needed and what approximation to make. |
| 77 |
% \item \cs{pgfpathcurvebetweentime}, \cs{pgfpathcurvebetweentimecontinue}: |
| 78 |
% These don't seem to be used at all. |
| 79 |
% \end{itemize} |
| 80 |
% |
| 81 |
% \begin{variable} |
| 82 |
% {\l_@@_path_tmp_tl, \l_@@_path_tmpa_fp, \l_@@_path_tmpb_fp} |
| 83 |
% Scratch space. |
| 84 |
% \begin{macrocode} |
| 85 |
\tl_new:N \l_@@_path_tmp_tl |
| 86 |
\fp_new:N \l_@@_path_tmpa_fp |
| 87 |
\fp_new:N \l_@@_path_tmpb_fp |
| 88 |
% \end{macrocode} |
| 89 |
% \end{variable} |
| 90 |
% |
| 91 |
% \subsection{Tracking paths} |
| 92 |
% |
| 93 |
% \begin{variable}{\g_@@_path_lastx_dim, \g_@@_path_lasty_dim} |
| 94 |
% The last point visited on a path. |
| 95 |
% \begin{macrocode} |
| 96 |
\dim_new:N \g_@@_path_lastx_dim |
| 97 |
\dim_new:N \g_@@_path_lasty_dim |
| 98 |
% \end{macrocode} |
| 99 |
% \end{variable} |
| 100 |
% |
| 101 |
% \begin{variable} |
| 102 |
% { |
| 103 |
% \g_@@_path_xmax_dim, |
| 104 |
% \g_@@_path_xmin_dim, |
| 105 |
% \g_@@_path_ymax_dim, |
| 106 |
% \g_@@_path_ymin_dim |
| 107 |
% } |
| 108 |
% The limiting size of a path. |
| 109 |
% \begin{macrocode} |
| 110 |
\dim_new:N \g_@@_path_xmax_dim |
| 111 |
\dim_new:N \g_@@_path_xmin_dim |
| 112 |
\dim_new:N \g_@@_path_ymax_dim |
| 113 |
\dim_new:N \g_@@_path_ymin_dim |
| 114 |
% \end{macrocode} |
| 115 |
% \end{variable} |
| 116 |
% |
| 117 |
% \begin{macro}{\@@_path_update_limits:nn} |
| 118 |
% \begin{macro}{\@@_path_reset_limits:} |
| 119 |
% Track the limits of a path and (perhaps) of the picture as a whole. |
| 120 |
% (At present the latter is always true: that will change as more complex |
| 121 |
% functionality is added.) |
| 122 |
% \begin{macrocode} |
| 123 |
\cs_new_protected:Npn \@@_path_update_limits:nn #1#2 |
| 124 |
{ |
| 125 |
\dim_gset:Nn \g_@@_path_xmax_dim |
| 126 |
{ \dim_max:nn \g_@@_path_xmax_dim {#1} } |
| 127 |
\dim_gset:Nn \g_@@_path_xmin_dim |
| 128 |
{ \dim_min:nn \g_@@_path_xmin_dim {#1} } |
| 129 |
\dim_gset:Nn \g_@@_path_ymax_dim |
| 130 |
{ \dim_max:nn \g_@@_path_ymax_dim {#2} } |
| 131 |
\dim_gset:Nn \g_@@_path_ymin_dim |
| 132 |
{ \dim_min:nn \g_@@_path_ymin_dim {#2} } |
| 133 |
\bool_if:NT \l_draw_bb_update_bool |
| 134 |
{ |
| 135 |
\dim_gset:Nn \g_draw_bb_xmax_dim |
| 136 |
{ \dim_max:nn \g_draw_bb_xmax_dim {#1} } |
| 137 |
\dim_gset:Nn \g_draw_bb_xmin_dim |
| 138 |
{ \dim_min:nn \g_draw_bb_xmin_dim {#1} } |
| 139 |
\dim_gset:Nn \g_draw_bb_ymax_dim |
| 140 |
{ \dim_max:nn \g_draw_bb_ymax_dim {#2} } |
| 141 |
\dim_gset:Nn \g_draw_bb_ymin_dim |
| 142 |
{ \dim_min:nn \g_draw_bb_ymin_dim {#2} } |
| 143 |
} |
| 144 |
} |
| 145 |
\cs_new_protected:Npn \@@_path_reset_limits: |
| 146 |
{ |
| 147 |
\dim_gset:Nn \g_@@_path_xmax_dim { -\c_max_dim } |
| 148 |
\dim_gset:Nn \g_@@_path_xmin_dim { \c_max_dim } |
| 149 |
\dim_gset:Nn \g_@@_path_ymax_dim { -\c_max_dim } |
| 150 |
\dim_gset:Nn \g_@@_path_ymin_dim { \c_max_dim } |
| 151 |
} |
| 152 |
% \end{macrocode} |
| 153 |
% \end{macro} |
| 154 |
% \end{macro} |
| 155 |
% |
| 156 |
% \begin{macro}{\@@_path_update_last:nn} |
| 157 |
% A simple auxiliary to avoid repetition. |
| 158 |
% \begin{macrocode} |
| 159 |
\cs_new_protected:Npn \@@_path_update_last:nn #1#2 |
| 160 |
{ |
| 161 |
\dim_gset:Nn \g_@@_path_lastx_dim {#1} |
| 162 |
\dim_gset:Nn \g_@@_path_lasty_dim {#2} |
| 163 |
} |
| 164 |
% \end{macrocode} |
| 165 |
% \end{macro} |
| 166 |
% |
| 167 |
% \subsection{Corner arcs} |
| 168 |
% |
| 169 |
% At the level of path \emph{construction}, rounded corners are handled |
| 170 |
% by inserting a marker into the path: that is then picked up once the |
| 171 |
% full path is constructed. Thus we need to set up the appropriate |
| 172 |
% data structures here, such that this can be applied every time it is |
| 173 |
% relevant. |
| 174 |
% |
| 175 |
% \begin{variable}{\l_@@_corner_xarc_dim, \l_@@_corner_yarc_dim} |
| 176 |
% The two arcs in use. |
| 177 |
% \begin{macrocode} |
| 178 |
\dim_new:N \l_@@_corner_xarc_dim |
| 179 |
\dim_new:N \l_@@_corner_yarc_dim |
| 180 |
% \end{macrocode} |
| 181 |
% \end{variable} |
| 182 |
% |
| 183 |
% \begin{variable}{\l_@@_corner_arc_bool} |
| 184 |
% A flag to speed up the repeated checks. |
| 185 |
% \begin{macrocode} |
| 186 |
\bool_new:N \l_@@_corner_arc_bool |
| 187 |
% \end{macrocode} |
| 188 |
% \end{variable} |
| 189 |
% |
| 190 |
% \begin{macro}{\draw_path_corner_arc:nn} |
| 191 |
% Calculate the arcs, check they are non-zero. |
| 192 |
% \begin{macrocode} |
| 193 |
\cs_new_protected:Npn \draw_path_corner_arc:nn #1#2 |
| 194 |
{ |
| 195 |
\dim_set:Nn \l_@@_corner_xarc_dim { \fp_to_dim:n {#1} } |
| 196 |
\dim_set:Nn \l_@@_corner_yarc_dim { \fp_to_dim:n {#2} } |
| 197 |
\bool_lazy_and:nnTF |
| 198 |
{ \dim_compare_p:nNn \l_@@_corner_xarc_dim = { 0pt } } |
| 199 |
{ \dim_compare_p:nNn \l_@@_corner_yarc_dim = { 0pt } } |
| 200 |
{ \bool_set_false:N \l_@@_corner_arc_bool } |
| 201 |
{ \bool_set_true:N \l_@@_corner_arc_bool } |
| 202 |
} |
| 203 |
% \end{macrocode} |
| 204 |
% \end{macro} |
| 205 |
% |
| 206 |
% \begin{macro}{\@@_path_mark_corner:} |
| 207 |
% Mark up corners for arc post-processing. |
| 208 |
% \begin{macrocode} |
| 209 |
\cs_new_protected:Npn \@@_path_mark_corner: |
| 210 |
{ |
| 211 |
\bool_if:NT \l_@@_corner_arc_bool |
| 212 |
{ |
| 213 |
\@@_softpath_roundpoint:VV |
| 214 |
\l_@@_corner_xarc_dim |
| 215 |
\l_@@_corner_yarc_dim |
| 216 |
} |
| 217 |
} |
| 218 |
% \end{macrocode} |
| 219 |
% \end{macro} |
| 220 |
% |
| 221 |
% \subsection{Basic path constructions} |
| 222 |
% |
| 223 |
% \begin{macro}{\draw_path_moveto:n, \draw_path_lineto:n} |
| 224 |
% \begin{macro}{\@@_path_moveto:nn, \@@_path_lineto:nn} |
| 225 |
% \begin{macro}{\draw_path_curveto:nnn} |
| 226 |
% \begin{macro}{\@@_path_curveto:nnnnnn} |
| 227 |
% At present, stick to purely linear transformation support and skip the |
| 228 |
% soft path business: that will likely need to be revisited later. |
| 229 |
% \begin{macrocode} |
| 230 |
\cs_new_protected:Npn \draw_path_moveto:n #1 |
| 231 |
{ |
| 232 |
\@@_point_process:nn |
| 233 |
{ \@@_path_moveto:nn } |
| 234 |
{ \draw_point_transform:n {#1} } |
| 235 |
} |
| 236 |
\cs_new_protected:Npn \@@_path_moveto:nn #1#2 |
| 237 |
{ |
| 238 |
\@@_path_update_limits:nn {#1} {#2} |
| 239 |
\@@_softpath_moveto:nn {#1} {#2} |
| 240 |
\@@_path_update_last:nn {#1} {#2} |
| 241 |
} |
| 242 |
\cs_new_protected:Npn \draw_path_lineto:n #1 |
| 243 |
{ |
| 244 |
\@@_point_process:nn |
| 245 |
{ \@@_path_lineto:nn } |
| 246 |
{ \draw_point_transform:n {#1} } |
| 247 |
} |
| 248 |
\cs_new_protected:Npn \@@_path_lineto:nn #1#2 |
| 249 |
{ |
| 250 |
\@@_path_mark_corner: |
| 251 |
\@@_path_update_limits:nn {#1} {#2} |
| 252 |
\@@_softpath_lineto:nn {#1} {#2} |
| 253 |
\@@_path_update_last:nn {#1} {#2} |
| 254 |
} |
| 255 |
\cs_new_protected:Npn \draw_path_curveto:nnn #1#2#3 |
| 256 |
{ |
| 257 |
\@@_point_process:nnnn |
| 258 |
{ |
| 259 |
\@@_path_mark_corner: |
| 260 |
\@@_path_curveto:nnnnnn |
| 261 |
} |
| 262 |
{ \draw_point_transform:n {#1} } |
| 263 |
{ \draw_point_transform:n {#2} } |
| 264 |
{ \draw_point_transform:n {#3} } |
| 265 |
} |
| 266 |
\cs_new_protected:Npn \@@_path_curveto:nnnnnn #1#2#3#4#5#6 |
| 267 |
{ |
| 268 |
\@@_path_update_limits:nn {#1} {#2} |
| 269 |
\@@_path_update_limits:nn {#3} {#4} |
| 270 |
\@@_path_update_limits:nn {#5} {#6} |
| 271 |
\@@_softpath_curveto:nnnnnn {#1} {#2} {#3} {#4} {#5} {#6} |
| 272 |
\@@_path_update_last:nn {#5} {#6} |
| 273 |
} |
| 274 |
% \end{macrocode} |
| 275 |
% \end{macro} |
| 276 |
% \end{macro} |
| 277 |
% \end{macro} |
| 278 |
% \end{macro} |
| 279 |
% |
| 280 |
% \begin{macro}{\draw_path_close:} |
| 281 |
% A simple wrapper. |
| 282 |
% \begin{macrocode} |
| 283 |
\cs_new_protected:Npn \draw_path_close: |
| 284 |
{ |
| 285 |
\@@_path_mark_corner: |
| 286 |
\@@_softpath_closepath: |
| 287 |
} |
| 288 |
% \end{macrocode} |
| 289 |
% \end{macro} |
| 290 |
% |
| 291 |
% \subsection{Accessing path information} |
| 292 |
% |
| 293 |
% \begin{macro}[EXP]{\draw_path_lastx:, \draw_path_lasty:} |
| 294 |
% Wrappers so the underlying data are read-only for users. |
| 295 |
% \begin{macrocode} |
| 296 |
\cs_new:Npn \draw_path_lastx: { \dim_use:N \g_@@_path_lastx_dim } |
| 297 |
\cs_new:Npn \draw_path_lasty: { \dim_use:N \g_@@_path_lasty_dim } |
| 298 |
% \end{macrocode} |
| 299 |
% \end{macro} |
| 300 |
% |
| 301 |
% \subsection{Canvas path constructions} |
| 302 |
% |
| 303 |
% \begin{macro}{\draw_path_canvas_moveto:n, \draw_path_canvas_lineto:n} |
| 304 |
% \begin{macro}{\draw_path_canvas_curveto:nnn} |
| 305 |
% Operations with no application of the transformation matrix. |
| 306 |
% \begin{macrocode} |
| 307 |
\cs_new_protected:Npn \draw_path_canvas_moveto:n #1 |
| 308 |
{ \@@_point_process:nn { \@@_path_moveto:nn } { \draw_point:n {#1} } } |
| 309 |
\cs_new_protected:Npn \draw_path_canvas_lineto:n #1 |
| 310 |
{ \@@_point_process:nn { \@@_path_lineto:nn } { \draw_point:n {#1} } } |
| 311 |
\cs_new_protected:Npn \draw_path_canvas_curveto:nnn #1#2#3 |
| 312 |
{ |
| 313 |
\@@_point_process:nnnn |
| 314 |
{ |
| 315 |
\@@_path_mark_corner: |
| 316 |
\@@_path_curveto:nnnnnn |
| 317 |
} |
| 318 |
{ \draw_point:n {#1} } |
| 319 |
{ \draw_point:n {#2} } |
| 320 |
{ \draw_point:n {#3} } |
| 321 |
} |
| 322 |
% \end{macrocode} |
| 323 |
% \end{macro} |
| 324 |
% \end{macro} |
| 325 |
% |
| 326 |
% \subsection{Computed curves} |
| 327 |
% |
| 328 |
% More complex operations need some calculations. To assist with those, various |
| 329 |
% constants are pre-defined. |
| 330 |
% |
| 331 |
% \begin{macro}{\draw_path_curveto:nn} |
| 332 |
% \begin{macro}{\@@_path_curveto:nnnn} |
| 333 |
% \begin{variable}{\c_@@_path_curveto_a_fp, \c_@@_path_curveto_b_fp} |
| 334 |
% A quadratic curve with one control point $(x_{\mathrm{c}}, |
| 335 |
% y_{\mathrm{c}})$. The two required control points are then |
| 336 |
% \[ |
| 337 |
% x_{1} = \frac{1}{3}x_{\mathrm{s}} + \frac{2}{3}x_{\mathrm{c}} |
| 338 |
% \quad |
| 339 |
% y_{1} = \frac{1}{3}y_{\mathrm{s}} + \frac{2}{3}y_{\mathrm{c}} |
| 340 |
% \] |
| 341 |
% and |
| 342 |
% \[ |
| 343 |
% x_{2} = \frac{1}{3}x_{\mathrm{e}} + \frac{2}{3}x_{\mathrm{c}} |
| 344 |
% \quad |
| 345 |
% x_{2} = \frac{1}{3}y_{\mathrm{e}} + \frac{2}{3}y_{\mathrm{c}} |
| 346 |
% \] |
| 347 |
% using the start (last) point $(x_{\mathrm{s}}, y_{\mathrm{s}})$ |
| 348 |
% and the end point $(x_{\mathrm{s}}, y_{\mathrm{s}})$. |
| 349 |
% \begin{macrocode} |
| 350 |
\cs_new_protected:Npn \draw_path_curveto:nn #1#2 |
| 351 |
{ |
| 352 |
\@@_point_process:nnn |
| 353 |
{ \@@_path_curveto:nnnn } |
| 354 |
{ \draw_point_transform:n {#1} } |
| 355 |
{ \draw_point_transform:n {#2} } |
| 356 |
} |
| 357 |
\cs_new_protected:Npn \@@_path_curveto:nnnn #1#2#3#4 |
| 358 |
{ |
| 359 |
\fp_set:Nn \l_@@_path_tmpa_fp { \c_@@_path_curveto_b_fp * #1 } |
| 360 |
\fp_set:Nn \l_@@_path_tmpb_fp { \c_@@_path_curveto_b_fp * #2 } |
| 361 |
\use:e |
| 362 |
{ |
| 363 |
\@@_path_mark_corner: |
| 364 |
\@@_path_curveto:nnnnnn |
| 365 |
{ |
| 366 |
\fp_to_dim:n |
| 367 |
{ |
| 368 |
\c_@@_path_curveto_a_fp * \g_@@_path_lastx_dim |
| 369 |
+ \l_@@_path_tmpa_fp |
| 370 |
} |
| 371 |
} |
| 372 |
{ |
| 373 |
\fp_to_dim:n |
| 374 |
{ |
| 375 |
\c_@@_path_curveto_a_fp * \g_@@_path_lasty_dim |
| 376 |
+ \l_@@_path_tmpb_fp |
| 377 |
} |
| 378 |
} |
| 379 |
{ |
| 380 |
\fp_to_dim:n |
| 381 |
{ \c_@@_path_curveto_a_fp * #3 + \l_@@_path_tmpa_fp } |
| 382 |
} |
| 383 |
{ |
| 384 |
\fp_to_dim:n |
| 385 |
{ \c_@@_path_curveto_a_fp * #4 + \l_@@_path_tmpb_fp } |
| 386 |
} |
| 387 |
{#3} |
| 388 |
{#4} |
| 389 |
} |
| 390 |
} |
| 391 |
\fp_const:Nn \c_@@_path_curveto_a_fp { 1 / 3 } |
| 392 |
\fp_const:Nn \c_@@_path_curveto_b_fp { 2 / 3 } |
| 393 |
% \end{macrocode} |
| 394 |
% \end{variable} |
| 395 |
% \end{macro} |
| 396 |
% \end{macro} |
| 397 |
% |
| 398 |
% \begin{macro}{\draw_path_arc:nnn} |
| 399 |
% \begin{macro}{\draw_path_arc:nnnn} |
| 400 |
% \begin{macro}{\@@_path_arc:nnnn} |
| 401 |
% \begin{macro}{\@@_path_arc:nnNnn} |
| 402 |
% \begin{macro} |
| 403 |
% { |
| 404 |
% \@@_path_arc_auxi:nnnnNnn, |
| 405 |
% \@@_path_arc_auxi:enenNnn, |
| 406 |
% \@@_path_arc_auxi:eennNnn |
| 407 |
% } |
| 408 |
% \begin{macro}{\@@_path_arc_auxii:nnnNnnnn} |
| 409 |
% \begin{macro}{\@@_path_arc_auxiii:nn} |
| 410 |
% \begin{macro}{\@@_path_arc_auxiv:nnnn} |
| 411 |
% \begin{macro}{\@@_path_arc_auxv:nn, \@@_path_arc_auxvi:nn} |
| 412 |
% \begin{macro}{\@@_path_arc_add:nnnn} |
| 413 |
% \begin{variable}{\l_@@_path_arc_delta_fp, \l_@@_path_arc_start_fp} |
| 414 |
% \begin{variable}{\c_@@_path_arc_90_fp,\c_@@_path_arc_60_fp} |
| 415 |
% Drawing an arc means dividing the total curve required into sections: |
| 416 |
% using Bézier curves we can cover at most $90^{\circ}$ at once. To allow |
| 417 |
% for later manipulations, we aim to have roughly equal last segments to |
| 418 |
% the line, with the split set at a final part of $115^{\circ}$. |
| 419 |
% \begin{macrocode} |
| 420 |
\cs_new_protected:Npn \draw_path_arc:nnn #1#2#3 |
| 421 |
{ \draw_path_arc:nnnn {#1} {#1} {#2} {#3} } |
| 422 |
\cs_new_protected:Npn \draw_path_arc:nnnn #1#2#3#4 |
| 423 |
{ |
| 424 |
\use:e |
| 425 |
{ |
| 426 |
\@@_path_arc:nnnn |
| 427 |
{ \fp_eval:n {#3} } |
| 428 |
{ \fp_eval:n {#4} } |
| 429 |
{ \fp_to_dim:n {#1} } |
| 430 |
{ \fp_to_dim:n {#2} } |
| 431 |
} |
| 432 |
} |
| 433 |
\cs_new_protected:Npn \@@_path_arc:nnnn #1#2#3#4 |
| 434 |
{ |
| 435 |
\fp_compare:nNnTF {#1} > {#2} |
| 436 |
{ \@@_path_arc:nnNnn {#1} {#2} - {#3} {#4} } |
| 437 |
{ \@@_path_arc:nnNnn {#1} {#2} + {#3} {#4} } |
| 438 |
} |
| 439 |
\cs_new_protected:Npn \@@_path_arc:nnNnn #1#2#3#4#5 |
| 440 |
{ |
| 441 |
\fp_set:Nn \l_@@_path_arc_start_fp {#1} |
| 442 |
\fp_set:Nn \l_@@_path_arc_delta_fp { abs( #1 - #2 ) } |
| 443 |
\fp_while_do:nNnn { \l_@@_path_arc_delta_fp } > { 90 } |
| 444 |
{ |
| 445 |
\fp_compare:nNnTF \l_@@_path_arc_delta_fp > { 115 } |
| 446 |
{ |
| 447 |
\@@_path_arc_auxi:eennNnn |
| 448 |
{ \fp_to_decimal:N \l_@@_path_arc_start_fp } |
| 449 |
{ \fp_eval:n { \l_@@_path_arc_start_fp #3 90 } } |
| 450 |
{ 90 } {#2} |
| 451 |
#3 {#4} {#5} |
| 452 |
} |
| 453 |
{ |
| 454 |
\@@_path_arc_auxi:eennNnn |
| 455 |
{ \fp_to_decimal:N \l_@@_path_arc_start_fp } |
| 456 |
{ \fp_eval:n { \l_@@_path_arc_start_fp #3 60 } } |
| 457 |
{ 60 } {#2} |
| 458 |
#3 {#4} {#5} |
| 459 |
} |
| 460 |
} |
| 461 |
\@@_path_mark_corner: |
| 462 |
\@@_path_arc_auxi:enenNnn |
| 463 |
{ \fp_to_decimal:N \l_@@_path_arc_start_fp } |
| 464 |
{#2} |
| 465 |
{ \fp_eval:n { abs( \l_@@_path_arc_start_fp - #2 ) } } |
| 466 |
{#2} |
| 467 |
#3 {#4} {#5} |
| 468 |
} |
| 469 |
% \end{macrocode} |
| 470 |
% The auxiliary is responsible for calculating the required points. |
| 471 |
% The \enquote{magic} number required to determine the length of the |
| 472 |
% control vectors is well-established for a right-angle: |
| 473 |
% $\frac{4}{3}(\sqrt{2} - 1) = 0.552\,284\,75$. For other cases, we follow |
| 474 |
% the calculation used by \pkg{pgf} but with the second common case of |
| 475 |
% $60^{\circ}$ pre-calculated for speed. |
| 476 |
% \begin{macrocode} |
| 477 |
\cs_new_protected:Npn \@@_path_arc_auxi:nnnnNnn #1#2#3#4#5#6#7 |
| 478 |
{ |
| 479 |
\use:e |
| 480 |
{ |
| 481 |
\@@_path_arc_auxii:nnnNnnnn |
| 482 |
{#1} {#2} {#4} #5 {#6} {#7} |
| 483 |
{ |
| 484 |
\fp_to_dim:n |
| 485 |
{ |
| 486 |
\cs_if_exist_use:cF |
| 487 |
{ c_@@_path_arc_ #3 _fp } |
| 488 |
{ 4/3 * tand( 0.25 * #3 ) } |
| 489 |
* #6 |
| 490 |
} |
| 491 |
} |
| 492 |
{ |
| 493 |
\fp_to_dim:n |
| 494 |
{ |
| 495 |
\cs_if_exist_use:cF |
| 496 |
{ c_@@_path_arc_ #3 _fp } |
| 497 |
{ 4/3 * tand( 0.25 * #3 ) } |
| 498 |
* #7 |
| 499 |
} |
| 500 |
} |
| 501 |
} |
| 502 |
} |
| 503 |
\cs_generate_variant:Nn \@@_path_arc_auxi:nnnnNnn { ene , ee } |
| 504 |
% \end{macrocode} |
| 505 |
% We can now calculate the required points. As everything here is |
| 506 |
% non-expandable, that is best done by using \texttt{e}-type expansion |
| 507 |
% to build up the tokens. The three points are calculated out-of-order, |
| 508 |
% since finding the second control point needs the position of the end |
| 509 |
% point. Once the points are found, fire-off the fundamental path |
| 510 |
% operation and update the record of where we are up to. The final |
| 511 |
% point has to be |
| 512 |
% \begin{macrocode} |
| 513 |
\cs_new_protected:Npn \@@_path_arc_auxii:nnnNnnnn #1#2#3#4#5#6#7#8 |
| 514 |
{ |
| 515 |
\tl_clear:N \l_@@_path_tmp_tl |
| 516 |
\@@_point_process:nn |
| 517 |
{ \@@_path_arc_auxiii:nn } |
| 518 |
{ |
| 519 |
\@@_point_transform_noshift:n |
| 520 |
{ \draw_point_polar:nnn {#7} {#8} { #1 #4 90 } } |
| 521 |
} |
| 522 |
\@@_point_process:nnn |
| 523 |
{ \@@_path_arc_auxiv:nnnn } |
| 524 |
{ |
| 525 |
\draw_point_transform:n |
| 526 |
{ \draw_point_polar:nnn {#5} {#6} {#1} } |
| 527 |
} |
| 528 |
{ |
| 529 |
\draw_point_transform:n |
| 530 |
{ \draw_point_polar:nnn {#5} {#6} {#2} } |
| 531 |
} |
| 532 |
\@@_point_process:nn |
| 533 |
{ \@@_path_arc_auxv:nn } |
| 534 |
{ |
| 535 |
\@@_point_transform_noshift:n |
| 536 |
{ \draw_point_polar:nnn {#7} {#8} { #2 #4 -90 } } |
| 537 |
} |
| 538 |
\exp_after:wN \@@_path_curveto:nnnnnn \l_@@_path_tmp_tl |
| 539 |
\fp_set:Nn \l_@@_path_arc_delta_fp { abs ( #2 - #3 ) } |
| 540 |
\fp_set:Nn \l_@@_path_arc_start_fp {#2} |
| 541 |
} |
| 542 |
% \end{macrocode} |
| 543 |
% The first control point. |
| 544 |
% \begin{macrocode} |
| 545 |
\cs_new_protected:Npn \@@_path_arc_auxiii:nn #1#2 |
| 546 |
{ |
| 547 |
\@@_path_arc_aux_add:nn |
| 548 |
{ \g_@@_path_lastx_dim + #1 } |
| 549 |
{ \g_@@_path_lasty_dim + #2 } |
| 550 |
} |
| 551 |
% \end{macrocode} |
| 552 |
% The end point: simple arithmetic. |
| 553 |
% \begin{macrocode} |
| 554 |
\cs_new_protected:Npn \@@_path_arc_auxiv:nnnn #1#2#3#4 |
| 555 |
{ |
| 556 |
\@@_path_arc_aux_add:nn |
| 557 |
{ \g_@@_path_lastx_dim - #1 + #3 } |
| 558 |
{ \g_@@_path_lasty_dim - #2 + #4 } |
| 559 |
} |
| 560 |
% \end{macrocode} |
| 561 |
% The second control point: extract the last point, do some |
| 562 |
% rearrangement and record. |
| 563 |
% \begin{macrocode} |
| 564 |
\cs_new_protected:Npn \@@_path_arc_auxv:nn #1#2 |
| 565 |
{ |
| 566 |
\exp_after:wN \@@_path_arc_auxvi:nn |
| 567 |
\l_@@_path_tmp_tl {#1} {#2} |
| 568 |
} |
| 569 |
\cs_new_protected:Npn \@@_path_arc_auxvi:nn #1#2#3#4#5#6 |
| 570 |
{ |
| 571 |
\tl_set:Nn \l_@@_path_tmp_tl { {#1} {#2} } |
| 572 |
\@@_path_arc_aux_add:nn |
| 573 |
{ #5 + #3 } |
| 574 |
{ #6 + #4 } |
| 575 |
\tl_put_right:Nn \l_@@_path_tmp_tl { {#3} {#4} } |
| 576 |
} |
| 577 |
\cs_new_protected:Npn \@@_path_arc_aux_add:nn #1#2 |
| 578 |
{ |
| 579 |
\tl_put_right:Ne \l_@@_path_tmp_tl |
| 580 |
{ { \fp_to_dim:n {#1} } { \fp_to_dim:n {#2} } } |
| 581 |
} |
| 582 |
\fp_new:N \l_@@_path_arc_delta_fp |
| 583 |
\fp_new:N \l_@@_path_arc_start_fp |
| 584 |
\fp_const:cn { c_@@_path_arc_90_fp } { 4/3 * (sqrt(2) - 1) } |
| 585 |
\fp_const:cn { c_@@_path_arc_60_fp } { 4/3 * tand(15) } |
| 586 |
% \end{macrocode} |
| 587 |
% \end{variable} |
| 588 |
% \end{variable} |
| 589 |
% \end{macro} |
| 590 |
% \end{macro} |
| 591 |
% \end{macro} |
| 592 |
% \end{macro} |
| 593 |
% \end{macro} |
| 594 |
% \end{macro} |
| 595 |
% \end{macro} |
| 596 |
% \end{macro} |
| 597 |
% \end{macro} |
| 598 |
% \end{macro} |
| 599 |
% |
| 600 |
% \begin{macro}{\draw_path_arc_axes:nnnn} |
| 601 |
% A simple wrapper. |
| 602 |
% \begin{macrocode} |
| 603 |
\cs_new_protected:Npn \draw_path_arc_axes:nnnn #1#2#3#4 |
| 604 |
{ |
| 605 |
\group_begin: |
| 606 |
\draw_transform_triangle:nnn { 0cm , 0cm } {#1} {#2} |
| 607 |
\draw_path_arc:nnn { 1pt } {#3} {#4} |
| 608 |
\group_end: |
| 609 |
} |
| 610 |
% \end{macrocode} |
| 611 |
% \end{macro} |
| 612 |
% |
| 613 |
% \begin{macro}{\draw_path_ellipse:nnn} |
| 614 |
% \begin{macro}{\@@_path_ellipse:nnnnnn} |
| 615 |
% \begin{macro}[EXP] |
| 616 |
% { |
| 617 |
% \@@_path_ellipse_arci:nnnnnn , |
| 618 |
% \@@_path_ellipse_arcii:nnnnnn , |
| 619 |
% \@@_path_ellipse_arciii:nnnnnn , |
| 620 |
% \@@_path_ellipse_arciv:nnnnnn |
| 621 |
% } |
| 622 |
% \begin{variable}{\c_@@_path_ellipse_fp} |
| 623 |
% Drawing an ellipse is an optimized version of drawing an arc, in particular |
| 624 |
% reusing the same constant. We need to deal with the ellipse in four parts |
| 625 |
% and also deal with moving to the right place, closing it and ending up |
| 626 |
% back at the center. That is handled on a per-arc basis, each in a |
| 627 |
% separate auxiliary for readability. |
| 628 |
% \begin{macrocode} |
| 629 |
\cs_new_protected:Npn \draw_path_ellipse:nnn #1#2#3 |
| 630 |
{ |
| 631 |
\@@_point_process:nnnn |
| 632 |
{ \@@_path_ellipse:nnnnnn } |
| 633 |
{ \draw_point_transform:n {#1} } |
| 634 |
{ \@@_point_transform_noshift:n {#2} } |
| 635 |
{ \@@_point_transform_noshift:n {#3} } |
| 636 |
} |
| 637 |
\cs_new_protected:Npn \@@_path_ellipse:nnnnnn #1#2#3#4#5#6 |
| 638 |
{ |
| 639 |
\use:e |
| 640 |
{ |
| 641 |
\@@_path_moveto:nn |
| 642 |
{ \fp_to_dim:n { #1 + #3 } } { \fp_to_dim:n { #2 + #4 } } |
| 643 |
\@@_path_ellipse_arci:nnnnnn {#1} {#2} {#3} {#4} {#5} {#6} |
| 644 |
\@@_path_ellipse_arcii:nnnnnn {#1} {#2} {#3} {#4} {#5} {#6} |
| 645 |
\@@_path_ellipse_arciii:nnnnnn {#1} {#2} {#3} {#4} {#5} {#6} |
| 646 |
\@@_path_ellipse_arciv:nnnnnn {#1} {#2} {#3} {#4} {#5} {#6} |
| 647 |
} |
| 648 |
\@@_softpath_closepath: |
| 649 |
\@@_path_moveto:nn {#1} {#2} |
| 650 |
} |
| 651 |
\cs_new:Npn \@@_path_ellipse_arci:nnnnnn #1#2#3#4#5#6 |
| 652 |
{ |
| 653 |
\@@_path_curveto:nnnnnn |
| 654 |
{ \fp_to_dim:n { #1 + #3 + #5 * \c_@@_path_ellipse_fp } } |
| 655 |
{ \fp_to_dim:n { #2 + #4 + #6 * \c_@@_path_ellipse_fp } } |
| 656 |
{ \fp_to_dim:n { #1 + #3 * \c_@@_path_ellipse_fp + #5 } } |
| 657 |
{ \fp_to_dim:n { #2 + #4 * \c_@@_path_ellipse_fp + #6 } } |
| 658 |
{ \fp_to_dim:n { #1 + #5 } } |
| 659 |
{ \fp_to_dim:n { #2 + #6 } } |
| 660 |
} |
| 661 |
\cs_new:Npn \@@_path_ellipse_arcii:nnnnnn #1#2#3#4#5#6 |
| 662 |
{ |
| 663 |
\@@_path_curveto:nnnnnn |
| 664 |
{ \fp_to_dim:n { #1 - #3 * \c_@@_path_ellipse_fp + #5 } } |
| 665 |
{ \fp_to_dim:n { #2 - #4 * \c_@@_path_ellipse_fp + #6 } } |
| 666 |
{ \fp_to_dim:n { #1 - #3 + #5 * \c_@@_path_ellipse_fp } } |
| 667 |
{ \fp_to_dim:n { #2 - #4 + #6 * \c_@@_path_ellipse_fp } } |
| 668 |
{ \fp_to_dim:n { #1 - #3 } } |
| 669 |
{ \fp_to_dim:n { #2 - #4 } } |
| 670 |
} |
| 671 |
\cs_new:Npn \@@_path_ellipse_arciii:nnnnnn #1#2#3#4#5#6 |
| 672 |
{ |
| 673 |
\@@_path_curveto:nnnnnn |
| 674 |
{ \fp_to_dim:n { #1 - #3 - #5 * \c_@@_path_ellipse_fp } } |
| 675 |
{ \fp_to_dim:n { #2 - #4 - #6 * \c_@@_path_ellipse_fp } } |
| 676 |
{ \fp_to_dim:n { #1 - #3 * \c_@@_path_ellipse_fp - #5 } } |
| 677 |
{ \fp_to_dim:n { #2 - #4 * \c_@@_path_ellipse_fp - #6 } } |
| 678 |
{ \fp_to_dim:n { #1 - #5 } } |
| 679 |
{ \fp_to_dim:n { #2 - #6 } } |
| 680 |
} |
| 681 |
\cs_new:Npn \@@_path_ellipse_arciv:nnnnnn #1#2#3#4#5#6 |
| 682 |
{ |
| 683 |
\@@_path_curveto:nnnnnn |
| 684 |
{ \fp_to_dim:n { #1 + #3 * \c_@@_path_ellipse_fp - #5 } } |
| 685 |
{ \fp_to_dim:n { #2 + #4 * \c_@@_path_ellipse_fp - #6 } } |
| 686 |
{ \fp_to_dim:n { #1 + #3 - #5 * \c_@@_path_ellipse_fp } } |
| 687 |
{ \fp_to_dim:n { #2 + #4 - #6 * \c_@@_path_ellipse_fp } } |
| 688 |
{ \fp_to_dim:n { #1 + #3 } } |
| 689 |
{ \fp_to_dim:n { #2 + #4 } } |
| 690 |
} |
| 691 |
\fp_const:Nn \c_@@_path_ellipse_fp { \fp_use:c { c_@@_path_arc_90_fp } } |
| 692 |
% \end{macrocode} |
| 693 |
% \end{variable} |
| 694 |
% \end{macro} |
| 695 |
% \end{macro} |
| 696 |
% \end{macro} |
| 697 |
% |
| 698 |
% \begin{macro}{\draw_path_circle:nn} |
| 699 |
% A shortcut. |
| 700 |
% \begin{macrocode} |
| 701 |
\cs_new_protected:Npn \draw_path_circle:nn #1#2 |
| 702 |
{ \draw_path_ellipse:nnn {#1} { #2 , 0pt } { 0pt , #2 } } |
| 703 |
% \end{macrocode} |
| 704 |
% \end{macro} |
| 705 |
% |
| 706 |
% \subsection{Rectangles} |
| 707 |
% |
| 708 |
% \begin{macro}{\draw_path_rectangle:nn} |
| 709 |
% \begin{macro}{\@@_path_rectangle:nnnn, \@@_path_rectangle_rounded:nnnn} |
| 710 |
% Building a rectangle can be a single operation, or for rounded versions will |
| 711 |
% involve step-by-step construction. |
| 712 |
% \begin{macrocode} |
| 713 |
\cs_new_protected:Npn \draw_path_rectangle:nn #1#2 |
| 714 |
{ |
| 715 |
\bool_lazy_or:nnTF |
| 716 |
{ \l_@@_corner_arc_bool } |
| 717 |
{ \l_@@_matrix_active_bool } |
| 718 |
{ |
| 719 |
\@@_point_process:nnn \@@_path_rectangle_rounded:nnnn |
| 720 |
{ \draw_point:n {#1} } |
| 721 |
{ \draw_point:n {#2} } |
| 722 |
} |
| 723 |
{ |
| 724 |
\@@_point_process:nnn \@@_path_rectangle:nnnn |
| 725 |
{ \draw_point:n { (#1) + ( \l_@@_xshift_dim , \l_@@_yshift_dim ) } } |
| 726 |
{ \draw_point:n {#2} } |
| 727 |
} |
| 728 |
} |
| 729 |
\cs_new_protected:Npn \@@_path_rectangle:nnnn #1#2#3#4 |
| 730 |
{ |
| 731 |
\@@_path_update_limits:nn {#1} {#2} |
| 732 |
\@@_path_update_limits:nn { #1 + #3 } { #2 + #4 } |
| 733 |
\@@_softpath_rectangle:nnnn {#1} {#2} {#3} {#4} |
| 734 |
\@@_path_update_last:nn {#1} {#2} |
| 735 |
} |
| 736 |
\cs_new_protected:Npn \@@_path_rectangle_rounded:nnnn #1#2#3#4 |
| 737 |
{ |
| 738 |
\draw_path_moveto:n { #1 + #3 , #2 + #4 } |
| 739 |
\draw_path_lineto:n { #1 , #2 + #4 } |
| 740 |
\draw_path_lineto:n { #1 , #2 } |
| 741 |
\draw_path_lineto:n { #1 + #3 , #2 } |
| 742 |
\draw_path_close: |
| 743 |
\draw_path_moveto:n { #1 , #2 } |
| 744 |
} |
| 745 |
% \end{macrocode} |
| 746 |
% \end{macro} |
| 747 |
% \end{macro} |
| 748 |
% |
| 749 |
% \begin{macro}{\draw_path_rectangle_corners:nn} |
| 750 |
% \begin{macro}{\@@_path_rectangle_corners:nnnn} |
| 751 |
% Another shortcut wrapper. |
| 752 |
% \begin{macrocode} |
| 753 |
\cs_new_protected:Npn \draw_path_rectangle_corners:nn #1#2 |
| 754 |
{ |
| 755 |
\@@_point_process:nnn |
| 756 |
{ \@@_path_rectangle_corners:nnnnn {#1} } |
| 757 |
{ \draw_point:n {#1} } |
| 758 |
{ \draw_point:n {#2} } |
| 759 |
} |
| 760 |
\cs_new_protected:Npn \@@_path_rectangle_corners:nnnnn #1#2#3#4#5 |
| 761 |
{ \draw_path_rectangle:nn {#1} { #4 - #2 , #5 - #3 } } |
| 762 |
% \end{macrocode} |
| 763 |
% \end{macro} |
| 764 |
% \end{macro} |
| 765 |
% |
| 766 |
% \subsection{Grids} |
| 767 |
% |
| 768 |
% \begin{macro}{\draw_path_grid:nnnn} |
| 769 |
% \begin{macro} |
| 770 |
% { |
| 771 |
% \@@_path_grid_auxi:nnnnnn, \@@_path_grid_auxi:eennnn, |
| 772 |
% \@@_path_grid_auxii:nnnnnn, |
| 773 |
% \@@_path_grid_auxiii:nnnnnn, \@@_path_grid_auxiiii:eennnn |
| 774 |
% } |
| 775 |
% \begin{macro} |
| 776 |
% {\@@_path_grid_auxiv:nnnnnnnn, \@@_path_grid_auxiv:eennnnnn} |
| 777 |
% The main complexity here is lining up the grid correctly. |
| 778 |
% To keep it simple, we tidy up the argument ordering first. |
| 779 |
% \begin{macrocode} |
| 780 |
\cs_new_protected:Npn \draw_path_grid:nnnn #1#2#3#4 |
| 781 |
{ |
| 782 |
\@@_point_process:nnn |
| 783 |
{ |
| 784 |
\@@_path_grid_auxi:eennnn |
| 785 |
{ \dim_abs:n {#1} } |
| 786 |
{ \dim_abs:n {#2} } |
| 787 |
} |
| 788 |
{ \draw_point:n {#3} } |
| 789 |
{ \draw_point:n {#4} } |
| 790 |
} |
| 791 |
\cs_new_protected:Npn \@@_path_grid_auxi:nnnnnn #1#2#3#4#5#6 |
| 792 |
{ |
| 793 |
\dim_compare:nNnTF {#3} > {#5} |
| 794 |
{ \@@_path_grid_auxii:nnnnnn {#1} {#2} {#5} {#4} {#3} {#6} } |
| 795 |
{ \@@_path_grid_auxii:nnnnnn {#1} {#2} {#3} {#4} {#5} {#6} } |
| 796 |
} |
| 797 |
\cs_generate_variant:Nn \@@_path_grid_auxi:nnnnnn { ee } |
| 798 |
\cs_new_protected:Npn \@@_path_grid_auxii:nnnnnn #1#2#3#4#5#6 |
| 799 |
{ |
| 800 |
\dim_compare:nNnTF {#4} > {#6} |
| 801 |
{ \@@_path_grid_auxiii:nnnnnn {#1} {#2} {#3} {#6} {#5} {#4} } |
| 802 |
{ \@@_path_grid_auxiii:nnnnnn {#1} {#2} {#3} {#4} {#5} {#6} } |
| 803 |
} |
| 804 |
\cs_new_protected:Npn \@@_path_grid_auxiii:nnnnnn #1#2#3#4#5#6 |
| 805 |
{ |
| 806 |
\@@_path_grid_auxiv:eennnnnn |
| 807 |
{ \fp_to_dim:n { #1 * ceil(#3/(#1)) } } |
| 808 |
{ \fp_to_dim:n { #2 * ceil(#4/(#2)) } } |
| 809 |
{#1} {#2} {#3} {#4} {#5} {#6} |
| 810 |
} |
| 811 |
\cs_new_protected:Npn \@@_path_grid_auxiv:nnnnnnnn #1#2#3#4#5#6#7#8 |
| 812 |
{ |
| 813 |
\dim_step_inline:nnnn |
| 814 |
{#1} |
| 815 |
{#3} |
| 816 |
{#7} |
| 817 |
{ |
| 818 |
\draw_path_moveto:n { ##1 , #6 } |
| 819 |
\draw_path_lineto:n { ##1 , #8 } |
| 820 |
} |
| 821 |
\dim_step_inline:nnnn |
| 822 |
{#2} |
| 823 |
{#4} |
| 824 |
{#8} |
| 825 |
{ |
| 826 |
\draw_path_moveto:n { #5 , ##1 } |
| 827 |
\draw_path_lineto:n { #7 , ##1 } |
| 828 |
} |
| 829 |
} |
| 830 |
\cs_generate_variant:Nn \@@_path_grid_auxiv:nnnnnnnn { ee } |
| 831 |
% \end{macrocode} |
| 832 |
% \end{macro} |
| 833 |
% \end{macro} |
| 834 |
% \end{macro} |
| 835 |
% |
| 836 |
% \subsection{Using paths} |
| 837 |
% |
| 838 |
% \begin{variable} |
| 839 |
% { |
| 840 |
% \l_@@_path_use_clip_bool , |
| 841 |
% \l_@@_path_use_fill_bool , |
| 842 |
% \l_@@_path_use_stroke_bool |
| 843 |
% } |
| 844 |
% Actions to pass to the driver. |
| 845 |
% \begin{macrocode} |
| 846 |
\bool_new:N \l_@@_path_use_clip_bool |
| 847 |
\bool_new:N \l_@@_path_use_fill_bool |
| 848 |
\bool_new:N \l_@@_path_use_stroke_bool |
| 849 |
% \end{macrocode} |
| 850 |
% \end{variable} |
| 851 |
% |
| 852 |
% \begin{variable}{\l_@@_path_use_clear_bool} |
| 853 |
% Actions handled at the macro layer. |
| 854 |
% \begin{macrocode} |
| 855 |
\bool_new:N \l_@@_path_use_clear_bool |
| 856 |
% \end{macrocode} |
| 857 |
% \end{variable} |
| 858 |
% |
| 859 |
% \begin{macro}{\draw_path_use:n, \draw_path_use_clear:n} |
| 860 |
% \begin{macro}{\draw_path_replace_bb:} |
| 861 |
% \begin{macro}{\@@_path_replace_bb:NnN} |
| 862 |
% \begin{macro}{\@@_path_use:n} |
| 863 |
% \begin{macro}{\@@_path_use_action_draw:, \@@_path_use_action_fillstroke:} |
| 864 |
% \begin{macro}{\@@_path_use_stroke_bb:} |
| 865 |
% \begin{macro}{\@@_path_use_bb:NnN} |
| 866 |
% There are a range of actions which can apply to a path: they are handled |
| 867 |
% in a single function which can carry out several of them. The first step |
| 868 |
% is to deal with the special case of clearing the path. |
| 869 |
% \begin{macrocode} |
| 870 |
\cs_new_protected:Npn \draw_path_use:n #1 |
| 871 |
{ |
| 872 |
\tl_if_blank:nF {#1} |
| 873 |
{ \@@_path_use:n {#1} } |
| 874 |
} |
| 875 |
\cs_new_protected:Npn \draw_path_use_clear:n #1 |
| 876 |
{ |
| 877 |
\bool_lazy_or:nnTF |
| 878 |
{ \tl_if_blank_p:n {#1} } |
| 879 |
{ \str_if_eq_p:nn {#1} { clear } } |
| 880 |
{ |
| 881 |
\@@_softpath_clear: |
| 882 |
\@@_path_reset_limits: |
| 883 |
} |
| 884 |
{ \@@_path_use:n { #1 , clear } } |
| 885 |
} |
| 886 |
\cs_new_protected:Npn \draw_path_replace_bb: |
| 887 |
{ |
| 888 |
\@@_path_replace_bb:NnN x { max } + |
| 889 |
\@@_path_replace_bb:NnN y { max } + |
| 890 |
\@@_path_replace_bb:NnN x { min } - |
| 891 |
\@@_path_replace_bb:NnN y { min } - |
| 892 |
\@@_softpath_clear: |
| 893 |
\@@_path_reset_limits: |
| 894 |
} |
| 895 |
\cs_new_protected:Npn \@@_path_replace_bb:NnN #1#2#3 |
| 896 |
{ |
| 897 |
\dim_gset:cn { g_draw_bb_ #1#2 _dim } |
| 898 |
{ |
| 899 |
\dim_use:c { g_@@_path_ #1#2 _dim } |
| 900 |
#3 0.5 \g_@@_linewidth_dim |
| 901 |
} |
| 902 |
} |
| 903 |
% \end{macrocode} |
| 904 |
% Map over the actions and set up the data: mainly just booleans, |
| 905 |
% but with the possibility to cover more complex cases. The business end |
| 906 |
% of the function is a series of checks on the various flags, then |
| 907 |
% taking the appropriate action(s). |
| 908 |
% \begin{macrocode} |
| 909 |
\cs_new_protected:Npn \@@_path_use:n #1 |
| 910 |
{ |
| 911 |
\bool_set_false:N \l_@@_path_use_clip_bool |
| 912 |
\bool_set_false:N \l_@@_path_use_fill_bool |
| 913 |
\bool_set_false:N \l_@@_path_use_stroke_bool |
| 914 |
\clist_map_inline:nn {#1} |
| 915 |
{ |
| 916 |
\cs_if_exist:cTF { l_@@_path_use_ ##1 _ bool } |
| 917 |
{ \bool_set_true:c { l_@@_path_use_ ##1 _ bool } } |
| 918 |
{ |
| 919 |
\cs_if_exist_use:cF { @@_path_use_action_ ##1 : } |
| 920 |
{ \msg_error:nnn { draw } { invalid-path-action } {##1} } |
| 921 |
} |
| 922 |
} |
| 923 |
\@@_softpath_round_corners: |
| 924 |
\bool_lazy_and:nnT |
| 925 |
{ \l_draw_bb_update_bool } |
| 926 |
{ \l_@@_path_use_stroke_bool } |
| 927 |
{ \@@_path_use_stroke_bb: } |
| 928 |
\@@_softpath_use: |
| 929 |
\bool_if:NT \l_@@_path_use_clip_bool |
| 930 |
{ |
| 931 |
\@@_backend_clip: |
| 932 |
\bool_set_false:N \l_draw_bb_update_bool |
| 933 |
\bool_lazy_or:nnF |
| 934 |
{ \l_@@_path_use_fill_bool } |
| 935 |
{ \l_@@_path_use_stroke_bool } |
| 936 |
{ \@@_backend_discardpath: } |
| 937 |
} |
| 938 |
\bool_lazy_or:nnT |
| 939 |
{ \l_@@_path_use_fill_bool } |
| 940 |
{ \l_@@_path_use_stroke_bool } |
| 941 |
{ |
| 942 |
\use:c |
| 943 |
{ |
| 944 |
@@_backend_ |
| 945 |
\bool_if:NT \l_@@_path_use_fill_bool { fill } |
| 946 |
\bool_if:NT \l_@@_path_use_stroke_bool { stroke } |
| 947 |
: |
| 948 |
} |
| 949 |
} |
| 950 |
\bool_if:NT \l_@@_path_use_clear_bool |
| 951 |
{ |
| 952 |
\@@_softpath_clear: |
| 953 |
\@@_path_reset_limits: |
| 954 |
} |
| 955 |
} |
| 956 |
\cs_new_protected:Npn \@@_path_use_action_draw: |
| 957 |
{ |
| 958 |
\bool_set_true:N \l_@@_path_use_stroke_bool |
| 959 |
} |
| 960 |
\cs_new_protected:Npn \@@_path_use_action_fillstroke: |
| 961 |
{ |
| 962 |
\bool_set_true:N \l_@@_path_use_fill_bool |
| 963 |
\bool_set_true:N \l_@@_path_use_stroke_bool |
| 964 |
} |
| 965 |
% \end{macrocode} |
| 966 |
% Where the path is relevant to size and is stroked, we need to allow for |
| 967 |
% the part which overlaps the edge of the bounding box. |
| 968 |
% \begin{macrocode} |
| 969 |
\cs_new_protected:Npn \@@_path_use_stroke_bb: |
| 970 |
{ |
| 971 |
\@@_path_use_bb:NnN x { max } + |
| 972 |
\@@_path_use_bb:NnN y { max } + |
| 973 |
\@@_path_use_bb:NnN x { min } - |
| 974 |
\@@_path_use_bb:NnN y { min } - |
| 975 |
} |
| 976 |
\cs_new_protected:Npn \@@_path_use_bb:NnN #1#2#3 |
| 977 |
{ |
| 978 |
\dim_compare:nNnF { \dim_use:c { g_draw_bb_ #1#2 _dim } } = { #3 -\c_max_dim } |
| 979 |
{ |
| 980 |
\dim_gset:cn { g_draw_bb_ #1#2 _dim } |
| 981 |
{ |
| 982 |
\use:c { dim_ #2 :nn } |
| 983 |
{ \dim_use:c { g_draw_bb_ #1#2 _dim } } |
| 984 |
{ |
| 985 |
\dim_use:c { g_@@_path_ #1#2 _dim } |
| 986 |
#3 0.5 \g_@@_linewidth_dim |
| 987 |
} |
| 988 |
} |
| 989 |
} |
| 990 |
} |
| 991 |
% \end{macrocode} |
| 992 |
% \end{macro} |
| 993 |
% \end{macro} |
| 994 |
% \end{macro} |
| 995 |
% \end{macro} |
| 996 |
% \end{macro} |
| 997 |
% \end{macro} |
| 998 |
% \end{macro} |
| 999 |
% |
| 1000 |
% \subsection{Scoping paths} |
| 1001 |
% |
| 1002 |
% \begin{variable} |
| 1003 |
% { |
| 1004 |
% \l_@@_path_lastx_dim, \l_@@_path_lasty_dim, |
| 1005 |
% \l_@@_path_xmax_dim, \l_@@_path_xmin_dim, |
| 1006 |
% \l_@@_path_ymax_dim, \l_@@_path_ymin_dim |
| 1007 |
% } |
| 1008 |
% \begin{variable}{\l_@@_softpath_corners_bool} |
| 1009 |
% Local storage for global data. There is already a |
| 1010 |
% \cs{l_@@_softpath_main_tl} for path manipulation, so we can reuse that |
| 1011 |
% (it is always grouped when the path is being reconstructed). |
| 1012 |
% \begin{macrocode} |
| 1013 |
\dim_new:N \l_@@_path_lastx_dim |
| 1014 |
\dim_new:N \l_@@_path_lasty_dim |
| 1015 |
\dim_new:N \l_@@_path_xmax_dim |
| 1016 |
\dim_new:N \l_@@_path_xmin_dim |
| 1017 |
\dim_new:N \l_@@_path_ymax_dim |
| 1018 |
\dim_new:N \l_@@_path_ymin_dim |
| 1019 |
\dim_new:N \l_@@_softpath_lastx_dim |
| 1020 |
\dim_new:N \l_@@_softpath_lasty_dim |
| 1021 |
\bool_new:N \l_@@_softpath_corners_bool |
| 1022 |
% \end{macrocode} |
| 1023 |
% \end{variable} |
| 1024 |
% \end{variable} |
| 1025 |
% |
| 1026 |
% \begin{macro}{\draw_path_scope_begin:, \draw_path_scope_end:} |
| 1027 |
% Scoping a path is a bit more involved, largely as there are a number |
| 1028 |
% of variables to keep hold of. |
| 1029 |
% \begin{macrocode} |
| 1030 |
\cs_new_protected:Npn \draw_path_scope_begin: |
| 1031 |
{ |
| 1032 |
\group_begin: |
| 1033 |
\dim_set_eq:NN \l_@@_path_lastx_dim \g_@@_path_lastx_dim |
| 1034 |
\dim_set_eq:NN \l_@@_path_lasty_dim \g_@@_path_lasty_dim |
| 1035 |
\dim_set_eq:NN \l_@@_path_xmax_dim \g_@@_path_xmax_dim |
| 1036 |
\dim_set_eq:NN \l_@@_path_xmin_dim \g_@@_path_xmin_dim |
| 1037 |
\dim_set_eq:NN \l_@@_path_ymax_dim \g_@@_path_ymax_dim |
| 1038 |
\dim_set_eq:NN \l_@@_path_ymin_dim \g_@@_path_ymin_dim |
| 1039 |
\dim_set_eq:NN \l_@@_softpath_lastx_dim \g_@@_softpath_lastx_dim |
| 1040 |
\dim_set_eq:NN \l_@@_softpath_lasty_dim \g_@@_softpath_lasty_dim |
| 1041 |
\@@_path_reset_limits: |
| 1042 |
\@@_softpath_save: |
| 1043 |
} |
| 1044 |
\cs_new_protected:Npn \draw_path_scope_end: |
| 1045 |
{ |
| 1046 |
\@@_softpath_restore: |
| 1047 |
\dim_gset_eq:NN \g_@@_softpath_lastx_dim \l_@@_softpath_lastx_dim |
| 1048 |
\dim_gset_eq:NN \g_@@_softpath_lasty_dim \l_@@_softpath_lasty_dim |
| 1049 |
\dim_gset_eq:NN \g_@@_path_xmax_dim \l_@@_path_xmax_dim |
| 1050 |
\dim_gset_eq:NN \g_@@_path_xmin_dim \l_@@_path_xmin_dim |
| 1051 |
\dim_gset_eq:NN \g_@@_path_ymax_dim \l_@@_path_ymax_dim |
| 1052 |
\dim_gset_eq:NN \g_@@_path_ymin_dim \l_@@_path_ymin_dim |
| 1053 |
\dim_gset_eq:NN \g_@@_path_lastx_dim \l_@@_path_lastx_dim |
| 1054 |
\dim_gset_eq:NN \g_@@_path_lasty_dim \l_@@_path_lasty_dim |
| 1055 |
\group_end: |
| 1056 |
} |
| 1057 |
% \end{macrocode} |
| 1058 |
% \end{macro} |
| 1059 |
% |
| 1060 |
% \subsection{Messages} |
| 1061 |
% |
| 1062 |
% \begin{macrocode} |
| 1063 |
\msg_new:nnnn { draw } { invalid-path-action } |
| 1064 |
{ Invalid~action~'#1'~for~path. } |
| 1065 |
{ Paths~can~be~used~with~actions~'draw',~'clip',~'fill'~or~'stroke'. } |
| 1066 |
% \end{macrocode} |
| 1067 |
% |
| 1068 |
% \begin{macrocode} |
| 1069 |
%</package> |
| 1070 |
% \end{macrocode} |
| 1071 |
% |
| 1072 |
% \end{implementation} |
| 1073 |
% |
| 1074 |
% \PrintIndex |