summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/l3experimental/l3draw-scopes.dtx
blob: 13592541066540580b27fc0f4fc6ca9011fcf901 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
% \iffalse meta-comment
%
%% File: l3draw-scopes.dtx
%
% Copyright (C) 2018-2020 The LaTeX3 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} package\\ Drawing scopes^^A
% }
%
% \author{^^A
%  The \LaTeX3 Project\thanks
%    {^^A
%      E-mail:
%        \href{mailto:latex-team@latex-project.org}
%          {latex-team@latex-project.org}^^A
%    }^^A
% }
%
% \date{Released 2020-05-18}
%
% \maketitle
%
% \begin{implementation}
%
% \section{\pkg{l3draw-scopes} implementation}
%
%    \begin{macrocode}
%<*initex|package>
%    \end{macrocode}
%
%    \begin{macrocode}
%<@@=draw>
%    \end{macrocode}
%
% \subsection{Drawing environment}
%
% \begin{variable}
%   {\g_@@_xmax_dim, \g_@@_xmin_dim, \g_@@_ymax_dim, \g_@@_ymin_dim}
%   Used to track the overall (official) size of the image created: may
%   not actually be the natural size of the content.
%    \begin{macrocode}
\dim_new:N \g_@@_xmax_dim
\dim_new:N \g_@@_xmin_dim
\dim_new:N \g_@@_ymax_dim
\dim_new:N \g_@@_ymin_dim
%    \end{macrocode}
% \end{variable}
%
% \begin{variable}{\l_draw_bb_update_bool}
%   Flag to indicate that a path (or similar) should update the bounding box
%   of the drawing.
%    \begin{macrocode}
\bool_new:N \l_draw_bb_update_bool
%    \end{macrocode}
% \end{variable}
%
% \begin{variable}{\l_@@_layer_main_box, \l_@@_layer_main_box}
%   Box for setting the drawing itself and the top-level layer.
%    \begin{macrocode}
\box_new:N \l_@@_main_box
\box_new:N \l_@@_layer_main_box
%    \end{macrocode}
% \end{variable}
%
% \begin{variable}{\g_@@_id_int}
%   The drawing number.
%    \begin{macrocode}
\int_new:N \g_@@_id_int
%    \end{macrocode}
% \end{variable}
%
% \begin{macro}{\@@_reset_bb:}
%   A simple auxiliary.
%    \begin{macrocode}
\cs_new_protected:Npn \@@_reset_bb:
  {
    \dim_gset:Nn \g_@@_xmax_dim { -\c_max_dim }
    \dim_gset:Nn \g_@@_xmin_dim {  \c_max_dim }
    \dim_gset:Nn \g_@@_ymax_dim { -\c_max_dim }
    \dim_gset:Nn \g_@@_ymin_dim {  \c_max_dim }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\draw_begin:, \draw_end:}
%   Drawings are created by setting them into a box, then adjusting the box
%   before inserting into the surroundings. Color is set here using the drawing
%   mechanism largely as it then sets up the internal data structures. It may be
%   that a coffin construct is better here in the longer term: that may become
%   clearer as the code is completed. As we need to avoid any insertion of
%   baseline skips, the outer box here has to be an |hbox|. To allow for
%   layers, there is some box nesting: notice that we 
%    \begin{macrocode}
\cs_new_protected:Npn \draw_begin:
  {
    \group_begin:
      \int_gincr:N \g_@@_id_int
      \hbox_set:Nw \l_@@_main_box
        \@@_backend_begin:
        \@@_reset_bb:
        \@@_path_reset_limits:
        \bool_set_true:N \l_draw_bb_update_bool
        \draw_transform_matrix_reset:
        \draw_transform_shift_reset:
        \@@_softpath_clear:
        \draw_linewidth:n { \l_draw_default_linewidth_dim }
        \draw_color:n { . }
        \draw_nonzero_rule:
        \draw_cap_butt:
        \draw_join_miter:
        \draw_miterlimit:n { 10 }
        \draw_dash_pattern:nn { } { 0cm }
        \hbox_set:Nw \l_@@_layer_main_box
  }
\cs_new_protected:Npn \draw_end:
  {
          \exp_args:NNNV \hbox_set_end:
          \clist_set:Nn \l_draw_layers_clist \l_draw_layers_clist
          \@@_layers_insert:
        \@@_backend_end:
      \hbox_set_end:
      \dim_compare:nNnT \g_@@_xmin_dim = \c_max_dim
        {
          \dim_gzero:N \g_@@_xmax_dim
          \dim_gzero:N \g_@@_xmin_dim
          \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 }
      \box_set_wd:Nn \l_@@_main_box
        { \g_@@_xmax_dim - \g_@@_xmin_dim }
      \mode_leave_vertical:
      \box_use_drop:N \l_@@_main_box
    \group_end:
  }
%    \end{macrocode}
% \end{macro}
%
% \subsection{Scopes}
%
% \begin{variable}{\l_@@_linewidth_dim}
% \begin{variable}{\l_@@_fill_color_tl, \l_@@_stroke_color_tl}
%   Storage for local variables.
%    \begin{macrocode}
\dim_new:N \l_@@_linewidth_dim
\tl_new:N \l_@@_fill_color_tl
\tl_new:N \l_@@_stroke_color_tl
%    \end{macrocode}
% \end{variable}
% \end{variable}
%
% \begin{macro}{\draw_scope_begin:, \draw_scope_begin:}
%   As well as the graphics (and \TeX{}) scope, also deal with global
%   data structures.
%    \begin{macrocode}
\cs_new_protected:Npn \draw_scope_begin:
  {
    \@@_backend_scope_begin:
    \group_begin:
      \dim_set_eq:NN \l_@@_linewidth_dim \g_@@_linewidth_dim
      \draw_path_scope_begin:
  }
\cs_new_protected:Npn \draw_scope_end:
  {
      \draw_path_scope_end:
      \dim_gset_eq:NN \g_@@_linewidth_dim \l_@@_linewidth_dim
    \group_end:
    \@@_backend_scope_end:
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{variable}
%   {\l_@@_xmax_dim, \l_@@_xmin_dim, \l_@@_ymax_dim, \l_@@_ymin_dim}
%   Storage for the bounding box.
%    \begin{macrocode}
\dim_new:N \l_@@_xmax_dim
\dim_new:N \l_@@_xmin_dim
\dim_new:N \l_@@_ymax_dim
\dim_new:N \l_@@_ymin_dim
%    \end{macrocode}
% \end{variable}
%
% \begin{macro}{\@@_scope_bb_begin:, \@@_scope_bb_end:}
%   The bounding box is simple: a straight group-based save and restore
%   approach.
%    \begin{macrocode}
\cs_new_protected:Npn \@@_scope_bb_begin:
  {
    \group_begin:
      \dim_set_eq:NN \l_@@_xmax_dim \g_@@_xmax_dim
      \dim_set_eq:NN \l_@@_xmin_dim \g_@@_xmin_dim
      \dim_set_eq:NN \l_@@_ymax_dim \g_@@_ymax_dim
      \dim_set_eq:NN \l_@@_ymin_dim \g_@@_ymin_dim
      \@@_reset_bb:
  }
\cs_new_protected:Npn \@@_scope_bb_end:
  {
      \dim_gset_eq:NN \g_@@_xmax_dim \l_@@_xmax_dim
      \dim_gset_eq:NN \g_@@_xmin_dim \l_@@_xmin_dim
      \dim_gset_eq:NN \g_@@_ymax_dim \l_@@_ymax_dim
      \dim_gset_eq:NN \g_@@_ymin_dim \l_@@_ymin_dim
    \group_end:
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\draw_suspend_begin:, \draw_suspend_end:}
%   Suspend all parts of a drawing.
%    \begin{macrocode}
\cs_new_protected:Npn \draw_suspend_begin:
  {
    \@@_scope_bb_begin:
    \draw_path_scope_begin:
    \draw_transform_matrix_reset:
    \draw_transform_shift_reset:
    \@@_layers_save:
  }
\cs_new_protected:Npn \draw_suspend_end:
  {
    \@@_layers_restore:
    \draw_path_scope_end:
    \@@_scope_bb_end:
  }
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
%</initex|package>
%    \end{macrocode}
%
% \end{implementation}
%
% \PrintIndex