% \iffalse meta-comment
%
%% File: l3draw-boxes.dtx
%
% Copyright (C) 2018-2023 The LaTeX Project
%
% It may be distributed and/or modified under the conditions of the
% LaTeX Project Public License (LPPL), either version 1.3c of this
% license or (at your option) any later version.  The latest version
% of this license is in the file
%
%    http://www.latex-project.org/lppl.txt
%
% This file is part of the "l3experimental bundle" (The Work in LPPL)
% and all files in that bundle must be distributed together.
%
% -----------------------------------------------------------------------
%
% The development version of the bundle can be found at
%
%    https://github.com/latex3/latex3
%
% for those people who are interested.
%
%<*driver>
\RequirePackage{expl3}
\documentclass[full]{l3doc}
\begin{document}
  \DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
% \title{^^A
%   The \pkg{l3draw-boxes} package\\ Boxes in drawings^^A
% }
%
% \author{^^A
%  The \LaTeX{} Project\thanks
%    {^^A
%      E-mail:
%        \href{mailto:latex-team@latex-project.org}
%          {latex-team@latex-project.org}^^A
%    }^^A
% }
%
% \date{Released 2023-01-24}
%
% \maketitle
%
% \begin{implementation}
%
% \section{\pkg{l3draw-boxes} implementation}
%
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
%
%    \begin{macrocode}
%<@@=draw>
%    \end{macrocode}
%
% Inserting boxes requires us to \enquote{interrupt} the drawing state,
% so is closely linked to scoping. At the same time, there are a few
% additional features required to make text work in a flexible way.
%
% \begin{variable}{\l_@@_tmp_box}
%    \begin{macrocode}
\box_new:N \l_@@_tmp_box
%    \end{macrocode}
% \end{variable}
%
% \begin{macro}{\draw_box_use:N}
% \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
%   than as separate operations, we do the insertion using an almost-raw
%   matrix. The process is split into two so that coffins are also supported.
%    \begin{macrocode}
\cs_new_protected:Npn \draw_box_use:N #1
  {
    \@@_box_use:Nnnnn #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
  {
    \bool_if:NT \l_draw_bb_update_bool
      {
        \@@_point_process:nn
          { \@@_path_update_limits:nn }
          { \draw_point_transform:n { #2 , #3 } }
        \@@_point_process:nn
          { \@@_path_update_limits:nn }
          { \draw_point_transform:n { #4 , #3 } }
        \@@_point_process:nn
          { \@@_path_update_limits:nn }
          { \draw_point_transform:n { #4 , #5 } }
        \@@_point_process:nn
          { \@@_path_update_limits:nn }
          { \draw_point_transform:n { #2 , #5 } }
      }
    \group_begin:
      \hbox_set:Nn \l_@@_tmp_box
        {
          \use:x
            {
              \@@_backend_box_use:Nnnnn #1
                { \fp_use:N \l_@@_matrix_a_fp }
                { \fp_use:N \l_@@_matrix_b_fp }
                { \fp_use:N \l_@@_matrix_c_fp }
                { \fp_use:N \l_@@_matrix_d_fp }
            }
        }
      \hbox_set:Nn \l_@@_tmp_box
        {
          \__kernel_kern:n { \l_@@_xshift_dim }
          \box_move_up:nn { \l_@@_yshift_dim }
            { \box_use_drop:N \l_@@_tmp_box }
        }
      \box_set_ht:Nn \l_@@_tmp_box { 0pt }
      \box_set_dp:Nn \l_@@_tmp_box { 0pt }
      \box_set_wd:Nn \l_@@_tmp_box { 0pt }
      \box_use_drop:N \l_@@_tmp_box
    \group_end:
  }
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\draw_coffin_use:Nnn}
%   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
  {
    \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 }
        { -\box_dp:N \l_@@_tmp_box }
        { \box_wd:N \l_@@_tmp_box }
        { \box_ht:N \l_@@_tmp_box }
    \group_end:
  }
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
%</package>
%    \end{macrocode}
%
% \end{implementation}
%
% \PrintIndex
