| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
% Copyright (C) 2019-2021 by Benjamin Berg <[email protected]> |
| 4 |
% |
| 5 |
% This work may be distributed and/or modified under the |
| 6 |
% conditions of the LaTeX Project Public License, either version 1.3c |
| 7 |
% of this license or (at your option) any later version. |
| 8 |
% The latest version of this license is in |
| 9 |
% http://www.latex-project.org/lppl.txt |
| 10 |
% |
| 11 |
% This work has the LPPL maintenance status `maintained'. |
| 12 |
% |
| 13 |
% The Current Maintainer of this work is Benjamin Berg. |
| 14 |
% |
| 15 |
% \fi |
| 16 |
% |
| 17 |
% \iffalse |
| 18 |
%<*driver> |
| 19 |
\ProvidesFile{sdapsbase.dtx} |
| 20 |
%</driver> |
| 21 |
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01] |
| 22 |
%<package>\ProvidesPackage{sdapsbase} |
| 23 |
%<*package> |
| 24 |
[2015/01/14 v0.1 Initial version of SDAPS base package] |
| 25 |
%</package> |
| 26 |
% |
| 27 |
%<*driver> |
| 28 |
\documentclass{ltxdoc} |
| 29 |
\usepackage{sdapsbase}[2015/01/14] |
| 30 |
%\EnableCrossrefs |
| 31 |
\CodelineIndex |
| 32 |
\RecordChanges |
| 33 |
\begin{document} |
| 34 |
\DocInput{sdapsbase.dtx} |
| 35 |
\end{document} |
| 36 |
%</driver> |
| 37 |
% \fi |
| 38 |
% |
| 39 |
% \CheckSum{0} |
| 40 |
% |
| 41 |
% \CharacterTable |
| 42 |
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z |
| 43 |
% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z |
| 44 |
% Digits \0\1\2\3\4\5\6\7\8\9 |
| 45 |
% Exclamation \! Double quote \" Hash (number) \# |
| 46 |
% Dollar \$ Percent \% Ampersand \& |
| 47 |
% Acute accent \' Left paren \( Right paren \) |
| 48 |
% Asterisk \* Plus \+ Comma \, |
| 49 |
% Minus \- Point \. Solidus \/ |
| 50 |
% Colon \: Semicolon \; Less than \< |
| 51 |
% Equals \= Greater than \> Question mark \? |
| 52 |
% Commercial at \@ Left bracket \[ Backslash \\ |
| 53 |
% Right bracket \] Circumflex \^ Underscore \_ |
| 54 |
% Grave accent \` Left brace \{ Vertical bar \| |
| 55 |
% Right brace \} Tilde \~} |
| 56 |
% |
| 57 |
% |
| 58 |
% \changes{v0.1}{2015/01/14}{Initial version} |
| 59 |
% |
| 60 |
% \GetFileInfo{sdapsbase.dtx} |
| 61 |
% |
| 62 |
% \DoNotIndex{\newcommand,\newenvironment} |
| 63 |
% |
| 64 |
% |
| 65 |
% \title{The \textsf{sdapsbase} package\thanks{This document |
| 66 |
% corresponds to \textsf{sdapsbase}~\fileversion, dated \filedate.}} |
| 67 |
% \author{Benjamin Berg \\ \texttt{[email protected]}} |
| 68 |
% |
| 69 |
% \maketitle |
| 70 |
% |
| 71 |
% \section{Documentation} |
| 72 |
% |
| 73 |
% Please refer to \url{https://sdaps.org/class-doc} for documentation. |
| 74 |
% |
| 75 |
% \StopEventually{\PrintChanges\PrintIndex} |
| 76 |
% |
| 77 |
% \section{Implementation} |
| 78 |
% |
| 79 |
% This package uses the \LaTeX3 language internally, so we need to enable it. |
| 80 |
% \begin{macrocode} |
| 81 |
% We need at least 2011-08-23 for \keys_set_known:nnN |
| 82 |
\RequirePackage{expl3}[2011/08/23] |
| 83 |
%\RequirePackage{xparse} |
| 84 |
\ExplSyntaxOn |
| 85 |
% \end{macrocode} |
| 86 |
% |
| 87 |
% And we need a number of other packages. |
| 88 |
% \begin{macrocode} |
| 89 |
\ExplSyntaxOff |
| 90 |
|
| 91 |
\input{sdapscode128} |
| 92 |
|
| 93 |
\RequirePackage{qrcode} |
| 94 |
|
| 95 |
\RequirePackage{tikz} |
| 96 |
\usetikzlibrary{calc} |
| 97 |
\usetikzlibrary{positioning} |
| 98 |
\usetikzlibrary{decorations.pathmorphing} |
| 99 |
\ExplSyntaxOn |
| 100 |
|
| 101 |
|
| 102 |
% Define aliases for code128 functions, and generate variants |
| 103 |
\cs_new_eq:NN \code_render:n \code |
| 104 |
\cs_generate_variant:Nn \code_render:n { x, V } |
| 105 |
|
| 106 |
% Also define an alias for the qrcode renderer |
| 107 |
\cs_new_protected_nopar:Nn \qrcode_render:nn { |
| 108 |
\qrcode[#1] {#2} |
| 109 |
} |
| 110 |
\cs_generate_variant:Nn \qrcode_render:nn { nx, nV } |
| 111 |
|
| 112 |
|
| 113 |
% Define a method to check for RTL languages, as the relevant commands |
| 114 |
% may not always be defined. |
| 115 |
\prg_new_conditional:Npnn \sdaps_if_rtl: { p, T, F, TF } |
| 116 |
{ |
| 117 |
\cs_if_exist:cTF { if@RTL } { |
| 118 |
\tl_use:c { if@RTL } |
| 119 |
\prg_return_true: |
| 120 |
\else |
| 121 |
\prg_return_false: |
| 122 |
\fi |
| 123 |
} { |
| 124 |
\prg_return_false: |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
% \end{macrocode} |
| 129 |
% |
| 130 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 131 |
% |
| 132 |
% \subsection{Context Handling} |
| 133 |
% |
| 134 |
% When creating complex questionnaires we need a mechnism to handle the current |
| 135 |
% context. By choice this mechanism works in global scope as items inside a |
| 136 |
% nested environment (e.g. multicol) need to have an effect on items outside |
| 137 |
% the environment. Because of this, we implement our own context, which works |
| 138 |
% similar to TeX groups containing local definitions. |
| 139 |
% |
| 140 |
% \begin{macrocode} |
| 141 |
|
| 142 |
\cs_generate_variant:Nn \tl_if_eq:nnTF { Vn } |
| 143 |
\cs_generate_variant:Nn \tl_if_eq:nnT { Vn } |
| 144 |
\cs_generate_variant:Nn \tl_if_eq:nnF { Vn } |
| 145 |
\cs_generate_variant:Nn \int_if_odd:nTF { V } |
| 146 |
\cs_generate_variant:Nn \int_if_odd:nF { V } |
| 147 |
\cs_generate_variant:Nn \int_if_odd:nT { V } |
| 148 |
\cs_generate_variant:Nn \tl_set:Nn { Nv } |
| 149 |
\cs_generate_variant:Nn \msg_error:nnn { nnV } |
| 150 |
\cs_generate_variant:Nn \exp_not:n { f } |
| 151 |
|
| 152 |
|
| 153 |
\tl_new:N \l__sdaps_tmpa_tl |
| 154 |
\tl_new:N \l__sdaps_tmpb_tl |
| 155 |
|
| 156 |
\dim_new:N \l__sdaps_tmpa_dim % |
| 157 |
\dim_new:N \l__sdaps_tmpb_dim % |
| 158 |
|
| 159 |
\prop_new:N \g__sdaps_current_context_prop |
| 160 |
\tl_new:N \g__sdaps_current_context_id_tl |
| 161 |
|
| 162 |
\tl_new:N \g__sdaps_current_context_tl |
| 163 |
|
| 164 |
\seq_new:N \g__sdaps_context_ids_seq |
| 165 |
\seq_new:N \g__sdaps_contexts_seq |
| 166 |
|
| 167 |
% Global metadata write enable variable managed by context |
| 168 |
\bool_new:N \g_sdaps_write_enable_bool |
| 169 |
\bool_gset_false:N \g_sdaps_write_enable_bool |
| 170 |
|
| 171 |
\cs_new_protected_nopar:Nn \_sdaps_context_to_tl:N |
| 172 |
{ |
| 173 |
\tl_set:Nx #1 {_write_enable=\bool_if:NTF\g_sdaps_write_enable_bool{\c_true_bool}{\c_false_bool}} |
| 174 |
\prop_map_inline:Nn \g__sdaps_current_context_prop { |
| 175 |
% Could we remove some of the braces in the TL? |
| 176 |
\tl_if_eq:nnTF { \undefined } { ##2 } { |
| 177 |
\tl_put_right:Nn #1 {,{##1}} |
| 178 |
} { |
| 179 |
\tl_put_right:Nn #1 {,{##1}={##2}} |
| 180 |
} |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
|
| 185 |
% Create new context using given identifier |
| 186 |
\cs_new_protected_nopar:Nn \sdaps_context_begin:n |
| 187 |
{ |
| 188 |
% We need to serialize the current context and save it away. |
| 189 |
|
| 190 |
\group_begin: |
| 191 |
% Serialize the current context |
| 192 |
\_sdaps_context_to_tl:N \l__sdaps_tmpa_tl |
| 193 |
\tl_gset:NV \g__sdaps_current_context_tl \l__sdaps_tmpa_tl |
| 194 |
% Stuff it away in our sequence |
| 195 |
\seq_gput_left:NV \g__sdaps_contexts_seq \g__sdaps_current_context_tl |
| 196 |
\seq_gput_left:NV \g__sdaps_context_ids_seq \g__sdaps_current_context_id_tl |
| 197 |
|
| 198 |
% Clear the hooks |
| 199 |
\sdaps_context_put:nn { _context_hook_end } {} |
| 200 |
\sdaps_context_put:nn { _context_hook_post_end } {} |
| 201 |
|
| 202 |
\tl_gset:Nn \g__sdaps_current_context_id_tl { #1 } |
| 203 |
\group_end: |
| 204 |
} |
| 205 |
|
| 206 |
\msg_new:nnn { sdapsbase } { context_end_none_left } { There ~ is ~ no ~ context ~ to ~ end ~ left! } |
| 207 |
\msg_new:nnn { sdapsbase } { context_end_broken } { The ~ current ~ context ~ with ~ id ~ #1 ~ may ~ not ~ be ~ ended ~ here. } |
| 208 |
|
| 209 |
\cs_new_protected_nopar:Nn \__sdaps_context_end: |
| 210 |
{ |
| 211 |
\seq_if_empty:NTF \g__sdaps_context_ids_seq { |
| 212 |
\msg_error:nn { sdapsbase } { context_end_none_left } |
| 213 |
} { |
| 214 |
|
| 215 |
\group_begin: |
| 216 |
\sdaps_context_get:nN { _context_hook_end } \l_tmpa_tl |
| 217 |
\tl_if_eq:VnF \l_tmpa_tl { \q_no_value } { \tl_use:N \l_tmpa_tl } |
| 218 |
|
| 219 |
% Grab post end hook |
| 220 |
\sdaps_context_get:nN { _context_hook_post_end } \l_tmpa_tl |
| 221 |
|
| 222 |
\_sdaps_context_clear: |
| 223 |
\seq_gpop_left:NN \g__sdaps_contexts_seq \g__sdaps_current_context_tl |
| 224 |
\seq_gpop_left:NN \g__sdaps_context_ids_seq \l__sdaps_tmpa_tl |
| 225 |
|
| 226 |
% Unpack context token list |
| 227 |
\sdaps_context_set:V \g__sdaps_current_context_tl |
| 228 |
|
| 229 |
\sdaps_context_get:nN { _write_enable } \l_tmpb_tl |
| 230 |
\bool_gset:Nn \g_sdaps_write_enable_bool { \l_tmpb_tl } |
| 231 |
\sdaps_context_remove:n { _write_enable } |
| 232 |
|
| 233 |
\tl_gclear:N \g__sdaps_current_context_tl |
| 234 |
\tl_gset:NV \g__sdaps_current_context_id_tl \l__sdaps_tmpa_tl |
| 235 |
|
| 236 |
\tl_if_eq:VnF \l_tmpa_tl { \q_no_value } { \tl_use:N \l_tmpa_tl } |
| 237 |
\group_end: |
| 238 |
} |
| 239 |
} |
| 240 |
|
| 241 |
\bool_new:N \l__sdaps_tmp_bool |
| 242 |
|
| 243 |
\cs_new_protected_nopar:Nn \__sdaps_test_context_id:n |
| 244 |
{ |
| 245 |
\tl_if_eq:VnTF \g__sdaps_current_context_id_tl { #1 } { |
| 246 |
\bool_set:Nn \l__sdaps_tmp_bool \c_true_bool |
| 247 |
} { |
| 248 |
\bool_set:Nn \l__sdaps_tmp_bool \c_false_bool |
| 249 |
} |
| 250 |
} |
| 251 |
|
| 252 |
% Exit first context with passed in identifier |
| 253 |
\cs_new_protected_nopar:Nn \sdaps_context_end:n |
| 254 |
{ |
| 255 |
\__sdaps_test_context_id:n { #1 } |
| 256 |
|
| 257 |
\bool_until_do:nn { \l__sdaps_tmp_bool } { |
| 258 |
\sdaps_context_end: |
| 259 |
|
| 260 |
\__sdaps_test_context_id:n { #1 } |
| 261 |
} |
| 262 |
\sdaps_context_end: |
| 263 |
} |
| 264 |
|
| 265 |
\cs_new_protected_nopar:Nn \__sdaps_context_end_local_scope: |
| 266 |
{ |
| 267 |
\__sdaps_test_context_id:n { sdaps_local_scope } |
| 268 |
|
| 269 |
\bool_until_do:nn { \l__sdaps_tmp_bool } { |
| 270 |
\__sdaps_context_end: |
| 271 |
|
| 272 |
\__sdaps_test_context_id:n { sdaps_local_scope } |
| 273 |
} |
| 274 |
\__sdaps_context_end: |
| 275 |
} |
| 276 |
|
| 277 |
% Exit current context |
| 278 |
\cs_new_protected_nopar:Nn \sdaps_context_end: |
| 279 |
{ |
| 280 |
% Ensure the current context is not a local group |
| 281 |
\tl_if_eq:VnTF \g__sdaps_current_context_id_tl { sdaps_local_scope } { |
| 282 |
\msg_error:nnV { sdapsbase } { context_end_broken } \g__sdaps_current_context_id_tl |
| 283 |
} {} |
| 284 |
|
| 285 |
\__sdaps_context_end: |
| 286 |
} |
| 287 |
|
| 288 |
% Create new context using an empty name |
| 289 |
\cs_new_protected_nopar:Nn \sdaps_context_begin: |
| 290 |
{ |
| 291 |
\sdaps_context_begin:n {} |
| 292 |
} |
| 293 |
|
| 294 |
\cs_new_protected_nopar:Nn \sdaps_context_begin_local: |
| 295 |
{ |
| 296 |
% Create a new context which will automatically be destroyed at the end of |
| 297 |
% the current TeX group. |
| 298 |
\sdaps_context_begin:n { sdaps_local_scope } |
| 299 |
\group_insert_after:N \__sdaps_context_end_local_scope: |
| 300 |
} |
| 301 |
|
| 302 |
\cs_new_protected_nopar:Nn \sdaps_context_put:n |
| 303 |
{ |
| 304 |
\sdaps_context_put:nn { #1 } { \undefined } |
| 305 |
} |
| 306 |
|
| 307 |
\cs_new_protected_nopar:Nn \sdaps_context_remove:n |
| 308 |
{ |
| 309 |
\prop_gremove:Nn \g__sdaps_current_context_prop { #1 } |
| 310 |
} |
| 311 |
|
| 312 |
\msg_new:nnn { sdapsbase } { context_key_broken } { Keys ~ may ~ not ~ contain ~ any ~ special ~ tokens! ~ However ~ the ~ key ~ #1 ~ does ~ contain ~ tokens ~ that ~ are ~ not ~ permissible! } |
| 313 |
% Directly set a certain key |
| 314 |
\cs_new_protected_nopar:Nn \sdaps_context_put:nn |
| 315 |
{ |
| 316 |
% TODO: How can I ensure that {} are not contained? |
| 317 |
% Though it would not be that bad actually. |
| 318 |
\tl_if_in:nnTF {#1} {,} { |
| 319 |
\msg_error:nnn { sdapsbase } { context_key_broken } {#1} |
| 320 |
} { |
| 321 |
} |
| 322 |
|
| 323 |
\tl_if_in:nnTF {#1} {=} { |
| 324 |
\msg_error:nnn { sdapsbase } { context_key_broken } {#1} |
| 325 |
} { |
| 326 |
} |
| 327 |
|
| 328 |
\prop_gput:Nnn \g__sdaps_current_context_prop { #1 } { #2 } |
| 329 |
} |
| 330 |
\cs_generate_variant:Nn \sdaps_context_put:nn { nV } |
| 331 |
|
| 332 |
% Set a set of keys using comma separated list of key/value pairs |
| 333 |
\cs_new_protected_nopar:Nn \sdaps_context_set:n |
| 334 |
{ |
| 335 |
\keyval_parse:NNn \sdaps_context_put:n \sdaps_context_put:nn { #1 } |
| 336 |
} |
| 337 |
\cs_generate_variant:Nn \sdaps_context_set:n {V} |
| 338 |
|
| 339 |
\cs_new_protected_nopar:Nn \sdaps_context_get:nN |
| 340 |
{ |
| 341 |
\prop_get:NnN \g__sdaps_current_context_prop { #1 } #2 |
| 342 |
} |
| 343 |
|
| 344 |
\cs_new_protected_nopar:Nn \sdaps_context_gget:nN |
| 345 |
{ |
| 346 |
\prop_get:NnN \g__sdaps_current_context_prop { #1 } \l_tmpa_tl |
| 347 |
\tl_gset_eq:NN #2 \l_tmpa_tl |
| 348 |
} |
| 349 |
|
| 350 |
\cs_new_protected_nopar:Nn \sdaps_context_append:nnn |
| 351 |
{ |
| 352 |
\sdaps_context_get:nN { #1 } \l__sdaps_tmpa_tl |
| 353 |
\tl_if_eq:VnTF \l__sdaps_tmpa_tl { \q_no_value } { |
| 354 |
\sdaps_context_put:nn { #1 } { #2 } |
| 355 |
} { |
| 356 |
\tl_put_right:Nn \l__sdaps_tmpa_tl { #3 } |
| 357 |
\tl_put_right:Nn \l__sdaps_tmpa_tl { #2 } |
| 358 |
\sdaps_context_put:nV { #1 } \l__sdaps_tmpa_tl |
| 359 |
} |
| 360 |
} |
| 361 |
\cs_generate_variant:Nn \sdaps_context_append:nnn { nVn } |
| 362 |
|
| 363 |
|
| 364 |
\cs_new_protected_nopar:Nn \sdaps_context_append:nn |
| 365 |
{ |
| 366 |
\sdaps_context_append:nnn { #1 } { #2 } { , } |
| 367 |
} |
| 368 |
|
| 369 |
\cs_new_protected_nopar:Nn \sdaps_context_hook_end:n |
| 370 |
{ |
| 371 |
\sdaps_context_append:nnn { _context_hook_end } { #1 } { } |
| 372 |
} |
| 373 |
|
| 374 |
\cs_new_protected_nopar:Nn \sdaps_context_hook_post_end:n |
| 375 |
{ |
| 376 |
\sdaps_context_append:nnn { _context_hook_post_end } { #1 } { } |
| 377 |
} |
| 378 |
|
| 379 |
\cs_new_protected_nopar:Nn \sdaps_context_enable_writing: |
| 380 |
{ |
| 381 |
\bool_gset_true:N \g_sdaps_write_enable_bool |
| 382 |
} |
| 383 |
|
| 384 |
\cs_new_protected_nopar:Nn \sdaps_context_disable_writing: |
| 385 |
{ |
| 386 |
\bool_gset_false:N \g_sdaps_write_enable_bool |
| 387 |
} |
| 388 |
|
| 389 |
\cs_new_protected_nopar:Nn \_sdaps_context_clear: |
| 390 |
{ |
| 391 |
\prop_gclear:N \g__sdaps_current_context_prop |
| 392 |
} |
| 393 |
|
| 394 |
\cs_new:Nn \sdaps_context_map_function:N |
| 395 |
{ |
| 396 |
\prop_map_function:NN \g__sdaps_current_context_prop #1 |
| 397 |
} |
| 398 |
|
| 399 |
\cs_new_protected_nopar:Nn \__sdaps_get:Nn |
| 400 |
{ |
| 401 |
\prop_get:NnN \g__sdaps_current_context_prop { #2 } #1 |
| 402 |
} |
| 403 |
|
| 404 |
\cs_new_protected_nopar:Nn \__sdaps_get_empty:Nn |
| 405 |
{ |
| 406 |
\prop_get:NnN \g__sdaps_current_context_prop { #2 } #1 |
| 407 |
\tl_if_eq:VnT #1 { \q_no_value } { |
| 408 |
\tl_set:Nn #1 {} |
| 409 |
} |
| 410 |
} |
| 411 |
|
| 412 |
\cs_new_protected_nopar:Nn \__sdaps_append_from_context:nN |
| 413 |
{ |
| 414 |
\prop_get:NnN \g__sdaps_current_context_prop { #1 } \l__sdaps_tmpb_tl |
| 415 |
\tl_if_eq:VnF \l__sdaps_tmpb_tl { \q_no_value } { |
| 416 |
\tl_put_right:Nn #2 {,} |
| 417 |
\tl_put_right:NV #2 {\l__sdaps_tmpb_tl} |
| 418 |
} |
| 419 |
} |
| 420 |
\cs_generate_variant:Nn \__sdaps_append_from_context:nN { VN } |
| 421 |
|
| 422 |
|
| 423 |
% \end{macrocode} |
| 424 |
% |
| 425 |
% \subsection{Defining Question and Headings} |
| 426 |
% |
| 427 |
% SDAPS needs to know about questions and headings/sections. Internally SDAPS |
| 428 |
% uses the context management system to number these correctly and assign the |
| 429 |
% variable names including the variable name concatenation automatically. |
| 430 |
% |
| 431 |
% Note that the infrastructure present here will not prevent you from nesting |
| 432 |
% questions, and SDAPS should actually handle this case just fine (ever wanted |
| 433 |
% to put a question inside a textbox?). |
| 434 |
% |
| 435 |
% It is important to keep these balanced. Please note that the SDAPS class does |
| 436 |
% not use TeX groups here, so you could for example start a context inside a |
| 437 |
% table and end it outside of it. |
| 438 |
% |
| 439 |
% \begin{macrocode} |
| 440 |
|
| 441 |
\seq_new:N \g__sdaps_object_id_seq |
| 442 |
\int_new:N \g__sdaps_object_id_int |
| 443 |
\int_gzero:N \g__sdaps_object_id_int |
| 444 |
|
| 445 |
\cs_new_protected_nopar:Nn \_sdaps_qobject_end_hook: |
| 446 |
{ |
| 447 |
% Take the current implicit variable |
| 448 |
\sdaps_context_get:nN { _implicit_var } \l__sdaps_tmpa_tl |
| 449 |
|
| 450 |
% Prepend explicit variable name; we assume that either _implicit_var or _var |
| 451 |
% have a proper value. |
| 452 |
\sdaps_context_get:nN { _var } \l__sdaps_tmpb_tl |
| 453 |
\tl_if_eq:VnF \l__sdaps_tmpb_tl { \q_no_value } { |
| 454 |
\tl_if_eq:VnTF \l__sdaps_tmpa_tl { \q_no_value } { |
| 455 |
\tl_clear:N \l__sdaps_tmpa_tl |
| 456 |
} { |
| 457 |
\tl_put_left:Nn \l__sdaps_tmpa_tl { _ } |
| 458 |
} |
| 459 |
\tl_put_left:NV \l__sdaps_tmpa_tl \l__sdaps_tmpb_tl |
| 460 |
} |
| 461 |
|
| 462 |
\sdaps_context_get:nN { id } \l__sdaps_tmpb_tl |
| 463 |
|
| 464 |
\tl_if_eq:VnTF \l__sdaps_tmpb_tl { \q_no_value } { |
| 465 |
\msg_warning:nn { sdapsbase } { no_qid } |
| 466 |
} { |
| 467 |
\sdaps_info_write_x:x{ |
| 468 |
Variable[\l__sdaps_tmpb_tl]=\l__sdaps_tmpa_tl |
| 469 |
} |
| 470 |
} |
| 471 |
} |
| 472 |
|
| 473 |
\cs_new_protected_nopar:Nn \_sdaps_qobject_post_hook: |
| 474 |
{ |
| 475 |
\seq_gpop_right:NN \g__sdaps_object_id_seq \l__sdaps_tmpa_tl |
| 476 |
\int_gset:NV \g__sdaps_object_id_int \l__sdaps_tmpa_tl |
| 477 |
} |
| 478 |
|
| 479 |
\cs_new_protected_nopar:Nn \sdaps_qobject_begin:nnn |
| 480 |
{ |
| 481 |
\int_gincr:N \g__sdaps_object_id_int |
| 482 |
\seq_gput_right:NV \g__sdaps_object_id_seq \g__sdaps_object_id_int |
| 483 |
\tl_set:Nx \l__sdaps_tmpa_tl { \int_use:N \g__sdaps_object_id_int } |
| 484 |
\int_gzero:N \g__sdaps_object_id_int |
| 485 |
|
| 486 |
\tl_set:Nx \l__sdaps_tmpb_tl { \seq_use:Nn \g__sdaps_object_id_seq {.} } |
| 487 |
|
| 488 |
\sdaps_context_begin:n {#1} |
| 489 |
\sdaps_context_put:nV {id} \l__sdaps_tmpb_tl |
| 490 |
\sdaps_info_write:x {QObject-#2=\tl_use:N\l__sdaps_tmpb_tl. ~ \exp_not:n{#3}} |
| 491 |
\sdaps_context_append:nVn { _implicit_var } \l__sdaps_tmpa_tl { _ } |
| 492 |
\sdaps_context_hook_end:n { \_sdaps_qobject_end_hook: } |
| 493 |
\sdaps_context_hook_post_end:n { \_sdaps_qobject_post_hook: } |
| 494 |
} |
| 495 |
\cs_generate_variant:Nn \sdaps_qobject_begin:nnn { nnV, nVV, nVn } |
| 496 |
|
| 497 |
|
| 498 |
\cs_new_protected_nopar:Nn \sdaps_qobject_end:n |
| 499 |
{ |
| 500 |
% End the context in question, everything else is done from the close hook |
| 501 |
\sdaps_context_end:n {#1} |
| 502 |
} |
| 503 |
|
| 504 |
\cs_new_protected_nopar:Nn \sdaps_qobject_begin:nn |
| 505 |
{ |
| 506 |
\sdaps_qobject_begin:nnn { unnamed_qobject } { #1 } { #2 } |
| 507 |
} |
| 508 |
|
| 509 |
\cs_new_protected_nopar:Nn \sdaps_qobject_begin_local:nn |
| 510 |
{ |
| 511 |
% Empty local context which automatically closes the qobject |
| 512 |
\sdaps_context_begin_local: |
| 513 |
\sdaps_qobject_begin:nnn { unnamed_local_qobject } { #1 } { #2 } |
| 514 |
} |
| 515 |
|
| 516 |
\cs_new_protected_nopar:Nn \sdaps_qobject_end: |
| 517 |
{ |
| 518 |
\sdaps_qobject_end:n { unnamed_qobject } |
| 519 |
} |
| 520 |
|
| 521 |
\cs_new_protected_nopar:Nn \sdaps_qobject_append_var:n |
| 522 |
{ |
| 523 |
% If the given variable name starts with _ then include the implicitly |
| 524 |
% generated variable name. |
| 525 |
\tl_if_head_eq_charcode:nNTF { #1 } _ { |
| 526 |
\sdaps_context_get:nN { _implicit_var } \l__sdaps_tmpa_tl |
| 527 |
\tl_if_eq:VnF \l__sdaps_tmpa_tl { \q_no_value } { |
| 528 |
\sdaps_context_append:nVn { _var } \l__sdaps_tmpa_tl { _ } |
| 529 |
} |
| 530 |
|
| 531 |
\sdaps_context_append:nnn { _var } { #1 } { } |
| 532 |
} { |
| 533 |
\sdaps_context_append:nnn { _var } { #1 } { _ } |
| 534 |
} |
| 535 |
|
| 536 |
% We have a proper variable name now, delete the implicit one |
| 537 |
\sdaps_context_remove:n { _implicit_var } |
| 538 |
} |
| 539 |
\cs_generate_variant:Nn \sdaps_qobject_append_var:n { V } |
| 540 |
|
| 541 |
\msg_new:nnn { sdapsbase } { no_qid } { Trying~to~output~metadata~but~no~question~ID~is~set~on~the~context.~Did~you~start~a~question?~Supressing~the~output! } |
| 542 |
|
| 543 |
\cs_new_protected_nopar:Nn \sdaps_answer:n |
| 544 |
{ |
| 545 |
\sdaps_context_get:nN { id } \l__sdaps_tmpa_tl |
| 546 |
|
| 547 |
\tl_if_eq:VnTF \l__sdaps_tmpa_tl { \q_no_value } { |
| 548 |
\msg_warning:nn { sdapsbase } { no_qid } |
| 549 |
} { |
| 550 |
\sdaps_info_write:x { |
| 551 |
Answer[\tl_use:N \l__sdaps_tmpa_tl]=\exp_not:n { #1 } |
| 552 |
} |
| 553 |
} |
| 554 |
} |
| 555 |
\cs_generate_variant:Nn \sdaps_answer:n { o } |
| 556 |
\cs_generate_variant:Nn \sdaps_answer:n { f } |
| 557 |
\cs_generate_variant:Nn \sdaps_answer:n { V } |
| 558 |
|
| 559 |
\cs_new_protected_nopar:Nn \sdaps_range:nnn |
| 560 |
{ |
| 561 |
\sdaps_context_get:nN { id } \l__sdaps_tmpa_tl |
| 562 |
|
| 563 |
\tl_if_eq:VnTF \l__sdaps_tmpa_tl { \q_no_value } { |
| 564 |
\msg_warning:nn { sdapsbase } { no_qid } |
| 565 |
} { |
| 566 |
\sdaps_info_write:x { |
| 567 |
Range-#1[\tl_use:N \l__sdaps_tmpa_tl]=\int_eval:n{#2},\exp_not:n { #3 } |
| 568 |
} |
| 569 |
} |
| 570 |
} |
| 571 |
\cs_generate_variant:Nn \sdaps_range:nnn { nno } |
| 572 |
\cs_generate_variant:Nn \sdaps_range:nnn { nnf } |
| 573 |
\cs_generate_variant:Nn \sdaps_range:nnn { nnV } |
| 574 |
|
| 575 |
\cs_generate_variant:Nn \tl_if_head_eq_charcode:nNT { VN } |
| 576 |
|
| 577 |
\cs_new_protected_nopar:Nn \_sdaps_generate_var:nN |
| 578 |
{ |
| 579 |
\tl_set:Nn \l__sdaps_tmpa_tl { #1 } |
| 580 |
|
| 581 |
% Generate a variable name if there is none (prepended with _ prefix) |
| 582 |
\tl_if_empty:VT \l__sdaps_tmpa_tl { |
| 583 |
\tl_set:Nx \l__sdaps_tmpa_tl { _ \int_eval:n { \g__sdaps_object_id_int + 1 } } |
| 584 |
} |
| 585 |
|
| 586 |
% Prepend any implicitly generated variable names if prefixed by _ |
| 587 |
\tl_if_head_eq_charcode:VNT \l__sdaps_tmpa_tl _ { |
| 588 |
\sdaps_context_get:nN { _implicit_var } \l__sdaps_tmpb_tl |
| 589 |
\tl_if_eq:VnTF \l__sdaps_tmpb_tl { \q_no_value } { |
| 590 |
\tl_remove_once:Nn \l__sdaps_tmpa_tl { _ } |
| 591 |
} { |
| 592 |
\tl_put_left:NV \l__sdaps_tmpa_tl \l__sdaps_tmpb_tl |
| 593 |
} |
| 594 |
} |
| 595 |
|
| 596 |
% Prepend explicit variable name |
| 597 |
\sdaps_context_get:nN { _var } \l__sdaps_tmpb_tl |
| 598 |
\tl_if_eq:VnF \l__sdaps_tmpb_tl { \q_no_value } { |
| 599 |
\tl_put_left:Nn \l__sdaps_tmpa_tl { _ } |
| 600 |
\tl_put_left:NV \l__sdaps_tmpa_tl \l__sdaps_tmpb_tl |
| 601 |
} |
| 602 |
|
| 603 |
\tl_set:NV #2 \l__sdaps_tmpa_tl |
| 604 |
} |
| 605 |
|
| 606 |
\cs_new_protected_nopar:Nn \_sdaps_box_inc_object_id: |
| 607 |
{ |
| 608 |
\bool_if:NT \g_sdaps_write_enable_bool { |
| 609 |
\int_gincr:N \g__sdaps_object_id_int |
| 610 |
} |
| 611 |
} |
| 612 |
|
| 613 |
% \end{macrocode} |
| 614 |
% |
| 615 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 616 |
% |
| 617 |
% \subsection{Data handling and override specification} |
| 618 |
% |
| 619 |
% Often it is useful to set certain flags for specific checkboxes. As the |
| 620 |
% checkbox may only be generated internally by SDAPS it is impossible to pass |
| 621 |
% a flag to it directly. Because of this \textsf{sdapsbase} has some mechanisms |
| 622 |
% to maintain a tree with options. |
| 623 |
% |
| 624 |
% \begin{verbatim} |
| 625 |
% \sdaps_overrides_init:n{*={ |
| 626 |
% *={}, |
| 627 |
% checkbox2={ellipse}, |
| 628 |
% checkbox3,1={width=6mm}, |
| 629 |
% }} |
| 630 |
% \end{verbatim} |
| 631 |
% |
| 632 |
% \begin{macrocode} |
| 633 |
|
| 634 |
\cs_generate_variant:Nn \keyval_parse:NNn { NNV } |
| 635 |
\cs_generate_variant:Nn \int_gset:Nn { NV } |
| 636 |
|
| 637 |
\seq_new:N \g__sdaps_checkbox_overlays_seq |
| 638 |
\seq_new:N \g__sdaps_textbox_overlays_seq |
| 639 |
|
| 640 |
|
| 641 |
\prop_new:N \g__sdaps_id_to_overrides_prop |
| 642 |
\prop_new:N \g__sdaps_overrides_prop |
| 643 |
\prop_new:N \g__sdaps_id_overrides_prop |
| 644 |
|
| 645 |
\cs_new_protected_nopar:Nn \__sdaps_questionnaire_overrides_set:nn |
| 646 |
{ |
| 647 |
\str_if_eq:eeTF { #1 } { * } { |
| 648 |
\__sdaps_parse_overrides:n{ #2 } |
| 649 |
} { |
| 650 |
\prop_put:Nnn \g__sdaps_id_to_overrides_prop { #1 } { #2 } |
| 651 |
} |
| 652 |
} |
| 653 |
|
| 654 |
\cs_new_protected_nopar:Nn \sdaps_overrides_init:n |
| 655 |
{ |
| 656 |
\keyval_parse:NNn \use_none:n \__sdaps_questionnaire_overrides_set:nn { #1 } |
| 657 |
} |
| 658 |
|
| 659 |
|
| 660 |
\cs_new_protected_nopar:Nn \__sdaps_overrides_set:nn |
| 661 |
{ |
| 662 |
\prop_gput:Nnn \g__sdaps_overrides_prop { #1 } { #2 } |
| 663 |
} |
| 664 |
|
| 665 |
\cs_new_protected_nopar:Nn \__sdaps_id_overrides_set:nn |
| 666 |
{ |
| 667 |
\prop_gput:Nnn \g__sdaps_id_overrides_prop { #1 } { #2 } |
| 668 |
} |
| 669 |
|
| 670 |
\cs_new_protected_nopar:Nn \__sdaps_parse_overrides:n |
| 671 |
{ |
| 672 |
\prop_gclear:N \g__sdaps_overrides_prop |
| 673 |
\keyval_parse:NNn \use_none:n \__sdaps_overrides_set:nn { #1 } |
| 674 |
} |
| 675 |
|
| 676 |
\tl_new:N \l__sdaps_set_qid_tl |
| 677 |
\cs_new_protected_nopar:Nn \sdaps_set_questionnaire_id:n |
| 678 |
{ |
| 679 |
\tl_gset:Nn \g__sdaps_questionnaire_id_tl { #1 } |
| 680 |
\prop_gclear:N \g__sdaps_id_overrides_prop |
| 681 |
\prop_get:NnNT \g__sdaps_id_to_overrides_prop { #1 } \l__sdaps_set_qid_tl { |
| 682 |
\keyval_parse:NNV \use_none:n \__sdaps_id_overrides_set:nn \l__sdaps_set_qid_tl |
| 683 |
} |
| 684 |
} |
| 685 |
\cs_generate_variant:Nn \sdaps_set_questionnaire_id:n { V } |
| 686 |
|
| 687 |
|
| 688 |
\cs_new_protected_nopar:Nn \__sdaps_append_override_options:Nnn |
| 689 |
{ |
| 690 |
% Global definition |
| 691 |
% First generic for all items |
| 692 |
\prop_get:NnNT \g__sdaps_overrides_prop { * } \l__sdaps_tmpa_tl { |
| 693 |
\tl_put_right:Nn #1 {,} |
| 694 |
\tl_put_right:NV #1 \l__sdaps_tmpa_tl |
| 695 |
} |
| 696 |
\tl_if_empty:nF { #2 } { |
| 697 |
% Items with same variable name |
| 698 |
\prop_get:NnNT \g__sdaps_overrides_prop { #2 } \l__sdaps_tmpa_tl { |
| 699 |
\tl_put_right:Nn #1 {,} |
| 700 |
\tl_put_right:NV #1 \l__sdaps_tmpa_tl |
| 701 |
} |
| 702 |
\tl_if_empty:nF { #3 } { |
| 703 |
% Items with same variable name and value |
| 704 |
\prop_get:NnNT \g__sdaps_overrides_prop { #2 } \l__sdaps_tmpa_tl { |
| 705 |
\tl_put_right:Nn #1 {,} |
| 706 |
\tl_put_right:NV #1 \l__sdaps_tmpa_tl |
| 707 |
} |
| 708 |
} |
| 709 |
} |
| 710 |
|
| 711 |
|
| 712 |
% Local (questionnaire ID specific) definition |
| 713 |
% First generic for all items |
| 714 |
\prop_get:NnNT \g__sdaps_id_overrides_prop { * } \l__sdaps_tmpa_tl { |
| 715 |
\tl_put_right:Nn #1 {,} |
| 716 |
\tl_put_right:NV #1 \l__sdaps_tmpa_tl |
| 717 |
} |
| 718 |
\tl_if_empty:nF { #2 } { |
| 719 |
% Items with same variable name |
| 720 |
\prop_get:NnNT \g__sdaps_id_overrides_prop { #2 } \l__sdaps_tmpa_tl { |
| 721 |
\tl_put_right:Nn #1 {,} |
| 722 |
\tl_put_right:NV #1 \l__sdaps_tmpa_tl |
| 723 |
} |
| 724 |
\tl_if_empty:nF { #3 } { |
| 725 |
% Items with same variable name and value |
| 726 |
\prop_get:NnNT \g__sdaps_id_overrides_prop { #2 } \l__sdaps_tmpa_tl { |
| 727 |
\tl_put_right:Nn #1 {,} |
| 728 |
\tl_put_right:NV #1 \l__sdaps_tmpa_tl |
| 729 |
} |
| 730 |
} |
| 731 |
} |
| 732 |
} |
| 733 |
\cs_generate_variant:Nn \__sdaps_append_override_options:Nnn { NVn } |
| 734 |
|
| 735 |
% \end{macrocode} |
| 736 |
% |
| 737 |
% |
| 738 |
% |
| 739 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 740 |
% |
| 741 |
% |
| 742 |
% First we define constants and global variables for later use. |
| 743 |
% \begin{macrocode} |
| 744 |
\dim_new:N \g_sdaps_linewidth_dim |
| 745 |
\g_sdaps_linewidth_dim=1bp |
| 746 |
\tl_new:N \g__sdaps_checkbox_last_info_tl |
| 747 |
|
| 748 |
\int_new:N \g__sdaps_textbox_num_int |
| 749 |
\int_set:Nn \g__sdaps_textbox_num_int 0 |
| 750 |
|
| 751 |
\tl_new:N \l_sdaps_var_tl |
| 752 |
\dim_new:N \l_sdaps_x_dim |
| 753 |
\dim_new:N \l_sdaps_y_dim |
| 754 |
\dim_new:N \l_sdaps_width_dim |
| 755 |
\dim_new:N \l_sdaps_height_dim |
| 756 |
|
| 757 |
% \end{macrocode} |
| 758 |
% |
| 759 |
% We need to be able to output data into the .sdaps file. On startup the |
| 760 |
% output is opened but writing is disabled. Note that the write enabled |
| 761 |
% variable is managed by the context. |
| 762 |
% |
| 763 |
% \begin{macrocode} |
| 764 |
|
| 765 |
\iow_new:N \g_sdaps_infofile_iow |
| 766 |
\iow_open:Nn \g_sdaps_infofile_iow { \c_sys_jobname_str . sdaps } |
| 767 |
\int_new:N \g__sdaps_infofile_line_int |
| 768 |
\int_gset:Nn \g__sdaps_infofile_line_int { 0 } |
| 769 |
|
| 770 |
\cs_new_protected_nopar:Nn \sdaps_info_write:n |
| 771 |
{ |
| 772 |
\bool_if:NT \g_sdaps_write_enable_bool { |
| 773 |
\int_gincr:N \g__sdaps_infofile_line_int |
| 774 |
\iow_shipout:Nx \g_sdaps_infofile_iow { [ \int_use:N \g__sdaps_infofile_line_int ] \exp_not:n { #1 } } |
| 775 |
} |
| 776 |
} |
| 777 |
\cs_generate_variant:Nn \sdaps_info_write:n { x } |
| 778 |
|
| 779 |
\cs_new_protected_nopar:Nn \sdaps_info_write_x:n |
| 780 |
{ |
| 781 |
\bool_if:NT \g_sdaps_write_enable_bool { |
| 782 |
\int_gincr:N \g__sdaps_infofile_line_int |
| 783 |
\iow_shipout_x:Nx \g_sdaps_infofile_iow { [ \int_use:N \g__sdaps_infofile_line_int ] \exp_not:n { #1 } } |
| 784 |
} |
| 785 |
} |
| 786 |
\cs_generate_variant:Nn \sdaps_info_write_x:n { x } |
| 787 |
|
| 788 |
|
| 789 |
% \end{macrocode} |
| 790 |
% |
| 791 |
% Set some options at the beginning of the document. |
| 792 |
% \begin{macrocode} |
| 793 |
%\AtBeginDocument{} |
| 794 |
% \end{macrocode} |
| 795 |
% |
| 796 |
% \subsection{Definition for keyword parameters} |
| 797 |
% |
| 798 |
% \begin{macrocode} |
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
\dim_new:N \l_sdaps_checkbox_linewidth_dim |
| 803 |
\dim_new:N \l_sdaps_checkbox_width_dim |
| 804 |
\dim_new:N \l_sdaps_checkbox_height_dim |
| 805 |
\tl_new:N \l_sdaps_checkbox_form_tl |
| 806 |
\tl_new:N \l_sdaps_checkbox_fill_tl |
| 807 |
\tl_new:N \l_sdaps_checkbox_draw_tl |
| 808 |
\tl_new:N \l_sdaps_checkbox_var_tl |
| 809 |
\tl_new:N \l_sdaps_checkbox_value_tl |
| 810 |
\bool_new:N \l_sdaps_checkbox_draw_check_bool |
| 811 |
|
| 812 |
\tl_set:Nn \l_sdaps_checkbox_form_tl { box } |
| 813 |
|
| 814 |
\tl_new:N \l_sdaps_parse_unknown_tl |
| 815 |
|
| 816 |
|
| 817 |
% Internal overlays |
| 818 |
\tl_new:N \l_sdaps_overlay_centered_text_tl |
| 819 |
\tl_new:N \l_sdaps_overlay_minipage_text_tl |
| 820 |
\tl_new:N \l_sdaps_overlay_minipage_pos_tl |
| 821 |
\dim_new:N \l_sdaps_overlay_minipage_pad_dim |
| 822 |
|
| 823 |
% Note that width/height is the *outside* width/height |
| 824 |
\keys_define:nn { sdaps / checkbox } |
| 825 |
{ |
| 826 |
linewidth .dim_set:N = \l_sdaps_checkbox_linewidth_dim, |
| 827 |
linewidth .initial:n = 1bp, |
| 828 |
width .dim_set:N = \l_sdaps_checkbox_width_dim, |
| 829 |
width .initial:n = 3.5mm, |
| 830 |
height .dim_set:N = \l_sdaps_checkbox_height_dim, |
| 831 |
height .initial:n = 3.5mm, |
| 832 |
form .choices:nn = { box, ellipse } { \tl_set:Nx \l_sdaps_checkbox_form_tl { \l_keys_choice_tl } }, |
| 833 |
value .tl_set:N = \l_sdaps_checkbox_value_tl, |
| 834 |
|
| 835 |
fill .tl_set:N = \l_sdaps_checkbox_fill_tl, |
| 836 |
fill .initial:n = { white }, |
| 837 |
|
| 838 |
draw .tl_set:N = \l_sdaps_checkbox_draw_tl, |
| 839 |
draw .initial:n = { . }, |
| 840 |
|
| 841 |
draw_check .bool_set:N = \l_sdaps_checkbox_draw_check_bool, |
| 842 |
draw_check .default:n = true, |
| 843 |
draw_check .initial:n = false, |
| 844 |
|
| 845 |
% Simple node overlay |
| 846 |
centered_text .tl_set:N = \l_sdaps_overlay_centered_text_tl, |
| 847 |
centered_text .initial:n = {}, |
| 848 |
|
| 849 |
% minipage overlay |
| 850 |
text .tl_set:N = \l_sdaps_overlay_minipage_text_tl, |
| 851 |
text .initial:n = {}, |
| 852 |
text_align .tl_set:N = \l_sdaps_overlay_minipage_pos_tl, |
| 853 |
text_align .initial:n = {c}, |
| 854 |
text_padding .dim_set:N = \l_sdaps_overlay_minipage_pad_dim, |
| 855 |
text_padding .initial:n = {2bp}, |
| 856 |
|
| 857 |
ellipse .meta:n = { form=ellipse }, |
| 858 |
box .meta:n = { form=box }, |
| 859 |
} |
| 860 |
% \end{macrocode} |
| 861 |
% |
| 862 |
% \subsection{Checkboxes} |
| 863 |
% |
| 864 |
% |
| 865 |
% \begin{macrocode} |
| 866 |
|
| 867 |
\cs_new_protected_nopar:Nn \__sdaps_checkbox_internal:nn |
| 868 |
{ |
| 869 |
\mbox{ |
| 870 |
\sdaps_if_rtl:T {\beginL} |
| 871 |
\pdfsavepos |
| 872 |
|
| 873 |
% Position of page and baseline offset |
| 874 |
\dim_set:Nn \l_sdaps_x_dim { \hoffset } |
| 875 |
\dim_set:Nn \l_sdaps_y_dim { \voffset + \l_sdaps_checkbox_height_dim - \dim_eval:n { 0.5\l_sdaps_checkbox_height_dim - 0.8ex } } |
| 876 |
|
| 877 |
% Size |
| 878 |
\dim_set:Nn \l_sdaps_width_dim { \l_sdaps_checkbox_width_dim } |
| 879 |
\dim_set:Nn \l_sdaps_height_dim { \l_sdaps_checkbox_height_dim } |
| 880 |
|
| 881 |
\bool_if:NT \g_sdaps_write_enable_bool { |
| 882 |
% pdflast[xy]pos is the PDF position of the baseline at the start of the box |
| 883 |
% excluding the page origin offset. |
| 884 |
\sdaps_context_get:nN {id} \l__sdaps_tmpa_tl |
| 885 |
\tl_if_eq:VnTF \l__sdaps_tmpa_tl { \q_no_value } { |
| 886 |
\msg_warning:nn { sdapsbase } { no_qid } |
| 887 |
} { |
| 888 |
\sdaps_info_write_x:x{ |
| 889 |
Box[\l__sdaps_tmpa_tl]=Checkbox, |
| 890 |
\exp_not:n{\int_use:N\g_sdaps_page_int}, |
| 891 |
\exp_not:n{\dim_eval:n} { \exp_not:f {\dim_use:N \l_sdaps_x_dim + \the\pdflastxpos sp} }, |
| 892 |
\exp_not:n{\dim_eval:n} { \exp_not:f {\dim_use:N \l_sdaps_y_dim + \the\pdflastypos sp} }, |
| 893 |
\dim_use:N \l_sdaps_width_dim, |
| 894 |
\dim_use:N \l_sdaps_height_dim, |
| 895 |
\tl_to_str:N\l_sdaps_checkbox_form_tl, |
| 896 |
\dim_use:N \l_sdaps_checkbox_linewidth_dim, |
| 897 |
#1,\tl_if_empty:nTF { #2 } { \int_use:N \g__sdaps_object_id_int } { #2 } |
| 898 |
} |
| 899 |
} |
| 900 |
} |
| 901 |
|
| 902 |
|
| 903 |
\tikz[baseline={0.5\l_sdaps_checkbox_height_dim-0.8ex}]{% |
| 904 |
\tl_if_eq:VnT \l_sdaps_checkbox_form_tl { box } { |
| 905 |
\draw[line~width=\l_sdaps_checkbox_linewidth_dim,fill=\l_sdaps_checkbox_fill_tl,draw=\l_sdaps_checkbox_draw_tl] (0.5\l_sdaps_checkbox_linewidth_dim, 0.5\l_sdaps_checkbox_linewidth_dim) rectangle +($(\l_sdaps_checkbox_width_dim, \l_sdaps_checkbox_height_dim)-(\l_sdaps_checkbox_linewidth_dim,\l_sdaps_checkbox_linewidth_dim)$);% |
| 906 |
} |
| 907 |
\tl_if_eq:VnT \l_sdaps_checkbox_form_tl { ellipse } { |
| 908 |
\draw[line~width=\l_sdaps_checkbox_linewidth_dim,fill=\l_sdaps_checkbox_fill_tl,draw=\l_sdaps_checkbox_draw_tl] (0.5\l_sdaps_checkbox_width_dim, 0.5\l_sdaps_checkbox_height_dim) circle [x~radius=0.5\l_sdaps_checkbox_width_dim-0.5\l_sdaps_checkbox_linewidth_dim, y~radius=0.5\l_sdaps_checkbox_height_dim-0.5\l_sdaps_checkbox_linewidth_dim];% |
| 909 |
} |
| 910 |
|
| 911 |
% For the overlay we actually position the nodes relative to the checkbox |
| 912 |
% and not absolute on the page. |
| 913 |
\dim_set:Nn \l_sdaps_x_dim { 0pt } |
| 914 |
\dim_set:Nn \l_sdaps_y_dim { \l_sdaps_checkbox_height_dim } |
| 915 |
|
| 916 |
% Use overlay so that nothing happens if a node is larger than the checkbox |
| 917 |
\begin{scope}[overlay] |
| 918 |
\seq_map_inline:Nn \g__sdaps_checkbox_overlays_seq {##1} |
| 919 |
\end{scope} |
| 920 |
} |
| 921 |
\sdaps_if_rtl:T {\endL} |
| 922 |
} |
| 923 |
} |
| 924 |
\cs_generate_variant:Nn \__sdaps_checkbox_internal:nn { Vn } |
| 925 |
|
| 926 |
\sdaps_context_set:n { checkboxtype=multichoice } |
| 927 |
\cs_new_protected_nopar:Nn \sdaps_checkbox_set_type:n |
| 928 |
{ |
| 929 |
\sdaps_context_set:n { checkboxtype={#1} } |
| 930 |
} |
| 931 |
\cs_generate_variant:Nn \sdaps_checkbox_set_type:n { V } |
| 932 |
|
| 933 |
\cs_new_protected_nopar:Nn \sdaps_checkbox:nn |
| 934 |
{ |
| 935 |
\group_begin:% |
| 936 |
|
| 937 |
\_sdaps_generate_var:nN { #1 } \l_sdaps_var_tl |
| 938 |
|
| 939 |
\sdaps_context_get:nN { checkboxtype } \l__sdaps_tmpa_tl |
| 940 |
\tl_if_eq:VnTF \l__sdaps_tmpa_tl { multichoice } { |
| 941 |
\tl_set:Nn \l_sdaps_parse_unknown_tl { box } |
| 942 |
} { |
| 943 |
\tl_set:Nn \l_sdaps_parse_unknown_tl { ellipse } |
| 944 |
} |
| 945 |
|
| 946 |
\__sdaps_append_from_context:nN { * } \l_sdaps_parse_unknown_tl |
| 947 |
\__sdaps_append_from_context:VN \l__sdaps_tmpa_tl \l_sdaps_parse_unknown_tl |
| 948 |
\__sdaps_append_override_options:NVn \l_sdaps_parse_unknown_tl \l_sdaps_var_tl { #2 } |
| 949 |
|
| 950 |
\keys_set_known:nVN { sdaps / checkbox } \l_sdaps_parse_unknown_tl \l_sdaps_parse_unknown_tl |
| 951 |
|
| 952 |
\_sdaps_box_inc_object_id: |
| 953 |
|
| 954 |
\__sdaps_checkbox_internal:Vn \l_sdaps_var_tl { #2 } |
| 955 |
\group_end:% |
| 956 |
\ignorespaces |
| 957 |
} |
| 958 |
\cs_generate_variant:Nn \sdaps_checkbox:nn { Vn, VV, nV } |
| 959 |
|
| 960 |
|
| 961 |
\cs_new_protected_nopar:Nn \sdaps_overlay_check: |
| 962 |
{ |
| 963 |
\bool_if:NT \l_sdaps_checkbox_draw_check_bool { |
| 964 |
\begin{scope}[decoration={random~steps,segment~length=4pt,amplitude=1pt}] |
| 965 |
\draw[line~width=\l_sdaps_checkbox_linewidth_dim, decorate] ($(0, 0) - (2pt,2pt)$) -- (0.5\l_sdaps_checkbox_width_dim, 0.5\l_sdaps_checkbox_height_dim) -- ($(\l_sdaps_checkbox_width_dim, \l_sdaps_checkbox_height_dim) + (2pt,2pt)$);% |
| 966 |
\draw[line~width=\l_sdaps_checkbox_linewidth_dim, decorate] ($(0, \l_sdaps_checkbox_height_dim) + (-2pt,2pt)$) -- (0.5\l_sdaps_checkbox_width_dim, 0.5\l_sdaps_checkbox_height_dim) -- ($(\l_sdaps_checkbox_width_dim, 0) + (2pt,-2pt)$);% |
| 967 |
\end{scope} |
| 968 |
} |
| 969 |
} |
| 970 |
\seq_put_left:Nn \g__sdaps_checkbox_overlays_seq \sdaps_overlay_check: |
| 971 |
|
| 972 |
|
| 973 |
\cs_new_protected_nopar:Nn \sdaps_overlay_centered: |
| 974 |
{ |
| 975 |
\tl_if_empty:NF \l_sdaps_overlay_centered_text_tl { |
| 976 |
\node[anchor=center,inner~sep=0pt,outer~sep=0pt] at ($(\l_sdaps_x_dim, \l_sdaps_y_dim) + 0.5*(\l_sdaps_width_dim, -\l_sdaps_height_dim)$) { |
| 977 |
\l_sdaps_overlay_centered_text_tl |
| 978 |
}; |
| 979 |
} |
| 980 |
} |
| 981 |
\seq_put_left:Nn \g__sdaps_checkbox_overlays_seq \sdaps_overlay_centered: |
| 982 |
\seq_put_left:Nn \g__sdaps_textbox_overlays_seq \sdaps_overlay_centered: |
| 983 |
|
| 984 |
|
| 985 |
\cs_new_protected_nopar:Nn \sdaps_overlay_minipage: |
| 986 |
{ |
| 987 |
\tl_if_empty:NF \l_sdaps_overlay_minipage_text_tl { |
| 988 |
\node[anchor=center,inner~sep=0pt,outer~sep=0pt] at ($(\l_sdaps_x_dim, \l_sdaps_y_dim) + 0.5*(\l_sdaps_width_dim, -\l_sdaps_height_dim)$) { |
| 989 |
\dim_set:Nn \l_sdaps_width_dim { \l_sdaps_width_dim - 2\l_sdaps_overlay_minipage_pad_dim } |
| 990 |
\dim_set:Nn \l_sdaps_height_dim { \l_sdaps_height_dim - 2\l_sdaps_overlay_minipage_pad_dim } |
| 991 |
|
| 992 |
\begin{minipage}[t][\l_sdaps_height_dim][\l_sdaps_overlay_minipage_pos_tl]{\l_sdaps_width_dim} |
| 993 |
% Hm, is this sane? |
| 994 |
\tex_let:D \textheight\l_sdaps_height_dim |
| 995 |
\l_sdaps_overlay_minipage_text_tl |
| 996 |
\end{minipage} |
| 997 |
}; |
| 998 |
} |
| 999 |
} |
| 1000 |
\seq_put_left:Nn \g__sdaps_checkbox_overlays_seq \sdaps_overlay_minipage: |
| 1001 |
\seq_put_left:Nn \g__sdaps_textbox_overlays_seq \sdaps_overlay_minipage: |
| 1002 |
|
| 1003 |
|
| 1004 |
% \end{macrocode} |
| 1005 |
% |
| 1006 |
|
| 1007 |
|
| 1008 |
% \subsection{Textboxes} |
| 1009 |
% |
| 1010 |
% |
| 1011 |
% \begin{macrocode} |
| 1012 |
|
| 1013 |
\sdaps_context_set:n { textboxtype=textbox } |
| 1014 |
\cs_new_protected_nopar:Nn \sdaps_textbox_set_type:n |
| 1015 |
{ |
| 1016 |
\sdaps_context_set:n { textboxtype={#1} } |
| 1017 |
} |
| 1018 |
\cs_generate_variant:Nn \sdaps_textbox_set_type:n { V } |
| 1019 |
|
| 1020 |
\dim_new:N \l_sdaps_textbox_linewidth_dim |
| 1021 |
\tl_new:N \l_sdaps_textbox_var_tl |
| 1022 |
\tl_new:N \l_sdaps_textbox_fill_tl |
| 1023 |
\tl_new:N \l_sdaps_textbox_draw_tl |
| 1024 |
\tl_new:N \l__sdaps_textbox_boxtype_tl |
| 1025 |
|
| 1026 |
|
| 1027 |
\keys_define:nn { sdaps / textbox } |
| 1028 |
{ |
| 1029 |
linewidth .dim_set:N = \l_sdaps_textbox_linewidth_dim, |
| 1030 |
linewidth .initial:n = 1bp, |
| 1031 |
|
| 1032 |
fill .tl_set:N = \l_sdaps_textbox_fill_tl, |
| 1033 |
fill .initial:n = { white }, |
| 1034 |
|
| 1035 |
draw .tl_set:N = \l_sdaps_textbox_draw_tl, |
| 1036 |
draw .initial:n = { . }, |
| 1037 |
|
| 1038 |
% Simple node overlay |
| 1039 |
centered_text .tl_set:N = \l_sdaps_overlay_centered_text_tl, |
| 1040 |
centered_text .initial:n = {}, |
| 1041 |
|
| 1042 |
% minipage overlay |
| 1043 |
text .tl_set:N = \l_sdaps_overlay_minipage_text_tl, |
| 1044 |
text .initial:n = {}, |
| 1045 |
text_align .tl_set:N = \l_sdaps_overlay_minipage_pos_tl, |
| 1046 |
text_align .initial:n = {c}, |
| 1047 |
text_padding .dim_set:N = \l_sdaps_overlay_minipage_pad_dim, |
| 1048 |
text_padding .initial:n = {2bp}, |
| 1049 |
} |
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
\dim_new:N \l__sdaps_textbox_dp_dim |
| 1055 |
\dim_new:N \l__sdaps_textbox_ht_dim |
| 1056 |
\dim_new:N \l__sdaps_textbox_wd_dim |
| 1057 |
\dim_new:N \l__sdaps_textbox_pad_dim |
| 1058 |
|
| 1059 |
|
| 1060 |
\msg_new:nnn { sdapsbase } { textbox_wrong_mode } { Impossible~to~layout~a~#1~textbox~in~#2~mode. } |
| 1061 |
|
| 1062 |
\cs_new_protected_nopar:Nn \__sdaps_textbox_prepare:n |
| 1063 |
{ |
| 1064 |
\tl_set:Nn \l_sdaps_parse_unknown_tl {} |
| 1065 |
|
| 1066 |
\_sdaps_generate_var:nN { #1 } \l_sdaps_var_tl |
| 1067 |
|
| 1068 |
\sdaps_context_get:nN { textboxtype } \l__sdaps_tmpa_tl |
| 1069 |
\tl_if_eq:VnTF \l__sdaps_tmpa_tl { codebox } { |
| 1070 |
\tl_set:Nn \l__sdaps_textbox_boxtype_tl { Codebox } |
| 1071 |
} { |
| 1072 |
\tl_set:Nn \l__sdaps_textbox_boxtype_tl { Textbox } |
| 1073 |
} |
| 1074 |
|
| 1075 |
\__sdaps_append_from_context:nN { * } \l_sdaps_parse_unknown_tl |
| 1076 |
\__sdaps_append_from_context:VN \l__sdaps_tmpa_tl \l_sdaps_parse_unknown_tl |
| 1077 |
\__sdaps_append_override_options:NVn \l_sdaps_parse_unknown_tl \l_sdaps_var_tl { } |
| 1078 |
|
| 1079 |
\keys_set_known:nVN { sdaps / textbox } \l_sdaps_parse_unknown_tl \l_sdaps_parse_unknown_tl |
| 1080 |
|
| 1081 |
\_sdaps_box_inc_object_id: |
| 1082 |
} |
| 1083 |
|
| 1084 |
\cs_new_protected_nopar:Nn \sdaps_textbox_vhstretch:nnn |
| 1085 |
{ |
| 1086 |
% \end{macrocode} |
| 1087 |
% |
| 1088 |
% At first we need to ensure that we are not in math mode. We also error out if |
| 1089 |
% switching into vertical mode (by inserting a paragraph break) fails. |
| 1090 |
% |
| 1091 |
% The scaling feature will likely fail in inner vertical mode, but it is still |
| 1092 |
% permissible. |
| 1093 |
% |
| 1094 |
% \begin{macrocode} |
| 1095 |
\if_mode_math: |
| 1096 |
\msg_error:nnnn { sdapsbase } { textbox_wrong_mode } { vhstretch } { math } |
| 1097 |
\else: |
| 1098 |
\tex_par:D |
| 1099 |
\if_mode_horizontal: |
| 1100 |
\msg_error:nnnn { sdapsbase } { textbox_wrong_mode } { vhstretch } { horizontal } |
| 1101 |
\else: |
| 1102 |
% Go into vertical mode by ending the current paragraph and insert |
| 1103 |
% \cs{widowpenalty} so that we don't get an unwelcome page break. It is |
| 1104 |
% assumed that any explanation for the textbox will be on top. |
| 1105 |
\tex_penalty:D \tex_widowpenalty:D |
| 1106 |
|
| 1107 |
\group_begin:% |
| 1108 |
|
| 1109 |
\__sdaps_textbox_prepare:n { #1 } |
| 1110 |
|
| 1111 |
% \end{macrocode} |
| 1112 |
% |
| 1113 |
% First we define the height and depth of the box that will be set. Setting the |
| 1114 |
% height works by inserting a rule into the first box and adding a negative |
| 1115 |
% skip afterwards. The depth is compensated by simply doing the same thing at |
| 1116 |
% the bottom. |
| 1117 |
% |
| 1118 |
% Note that we need to add nobreak/nointerlineskip everywhere so that we |
| 1119 |
% don't insert extra spacing and no page break will happen. |
| 1120 |
% |
| 1121 |
% The first box has a defined height and stores the current position for the |
| 1122 |
% frame code later on. Then two cleaders follow which simply implement the |
| 1123 |
% required stretching (cleaders are used to prevent page breaking, I do not |
| 1124 |
% know whether this is sane, but it seems to work just fine). After this the |
| 1125 |
% box containing the main drawing code is placed. We simply use a vbox with |
| 1126 |
% right aligned content. The last thing happening is a vskip plus hbox to set |
| 1127 |
% the correct depth. |
| 1128 |
% |
| 1129 |
% \begin{macrocode} |
| 1130 |
% TODO: Make this configurable |
| 1131 |
\dim_set:Nn \l__sdaps_textbox_dp_dim { 0.5ex } |
| 1132 |
\dim_set:Nn \l__sdaps_textbox_ht_dim { 1.7ex } |
| 1133 |
|
| 1134 |
\vbox:n { |
| 1135 |
\sdaps_if_rtl:T {\beginL} |
| 1136 |
\leftskip=0pt |
| 1137 |
\rightskip=0pt plus 1fill |
| 1138 |
\noindent |
| 1139 |
\tex_vrule:D height \l__sdaps_textbox_ht_dim depth 0pt width 0pt |
| 1140 |
\pgfsys@markposition{textboxtop\int_use:N\g__sdaps_textbox_num_int} |
| 1141 |
\sdaps_if_rtl:T {\endL} |
| 1142 |
} |
| 1143 |
|
| 1144 |
\tex_penalty:D 10000 |
| 1145 |
\nointerlineskip |
| 1146 |
|
| 1147 |
\tex_cleaders:D\tex_hbox:D{}\skip_vertical:n{#2 - \l__sdaps_textbox_ht_dim} |
| 1148 |
|
| 1149 |
\tex_penalty:D 10000 |
| 1150 |
\nointerlineskip |
| 1151 |
|
| 1152 |
\tex_cleaders:D\tex_hbox:D{}\skip_vertical:n{\stretch{#3}} |
| 1153 |
|
| 1154 |
\tex_penalty:D 10000 |
| 1155 |
\nointerlineskip |
| 1156 |
|
| 1157 |
\vbox:n { |
| 1158 |
\sdaps_if_rtl:T {\beginL} |
| 1159 |
\noindent |
| 1160 |
\leftskip=0pt plus 1fill |
| 1161 |
\rightskip=0pt |
| 1162 |
\begin{tikzpicture}[remember~picture,overlay,shift=(current~page.south~west)] |
| 1163 |
\pgfsys@getposition{pgfpageorigin}{\@sdaps@pageorigin} |
| 1164 |
\pgfsys@getposition{textboxtop\int_use:N\g__sdaps_textbox_num_int}{\@sdaps@textboxtoppos} |
| 1165 |
\pgfpointadd{\@sdaps@textboxtoppos}{ |
| 1166 |
\pgfpointadd{\@sdaps@pageorigin}{\pgfpoint{0}{\l__sdaps_textbox_ht_dim}} |
| 1167 |
} |
| 1168 |
\pgfgetlastxy{\l__sdaps_x}{\l__sdaps_y} |
| 1169 |
\dim_set:Nn \l_sdaps_x_dim {\l__sdaps_x} |
| 1170 |
\dim_set:Nn \l_sdaps_y_dim {\l__sdaps_y} |
| 1171 |
|
| 1172 |
\pgfsys@getposition{\pgfpictureid}{\@sdaps@textboxbottompos} |
| 1173 |
\pgfpointdiff{\@sdaps@textboxtoppos}{\@sdaps@textboxbottompos} |
| 1174 |
|
| 1175 |
% Is there a more elegant way to multiply the height with -1? |
| 1176 |
\pgfgetlastxy{\l__sdaps_width}{\l__sdaps_height} |
| 1177 |
% Add the minimum height (i.e. depth below the last baseline) to the |
| 1178 |
% overall height. |
| 1179 |
\pgfpoint{\l__sdaps_width}{-\l__sdaps_height + \l__sdaps_textbox_ht_dim} |
| 1180 |
\pgfgetlastxy{\l__sdaps_width}{\l__sdaps_height} |
| 1181 |
\dim_set:Nn \l_sdaps_width_dim {\l__sdaps_width} |
| 1182 |
\dim_set:Nn \l_sdaps_height_dim {\l__sdaps_height} |
| 1183 |
|
| 1184 |
% Draw the rectangle |
| 1185 |
\draw[line~width=\l_sdaps_textbox_linewidth_dim,fill=\l_sdaps_textbox_fill_tl,draw=\l_sdaps_textbox_draw_tl] ($(\l_sdaps_x_dim, \l_sdaps_y_dim) + 0.5 * (\l_sdaps_textbox_linewidth_dim, -\l_sdaps_textbox_linewidth_dim)$) rectangle +($(\l_sdaps_width_dim, -\l_sdaps_height_dim) - (\l_sdaps_textbox_linewidth_dim, -\l_sdaps_textbox_linewidth_dim)$); |
| 1186 |
|
| 1187 |
\begin{scope} |
| 1188 |
\seq_map_inline:Nn \g__sdaps_textbox_overlays_seq {##1} |
| 1189 |
\end{scope} |
| 1190 |
|
| 1191 |
\bool_if:NT \g_sdaps_write_enable_bool { |
| 1192 |
\sdaps_context_get:nN {id} \l__sdaps_tmpa_tl |
| 1193 |
\tl_if_eq:VnTF \l__sdaps_tmpa_tl { \q_no_value } { |
| 1194 |
\msg_warning:nn { sdapsbase } { no_qid } |
| 1195 |
} { |
| 1196 |
\sdaps_info_write_x:x { |
| 1197 |
Box[\l__sdaps_tmpa_tl]=\l__sdaps_textbox_boxtype_tl, |
| 1198 |
\exp_not:n{\int_use:N\g_sdaps_page_int}, |
| 1199 |
\dim_use:N \l_sdaps_x_dim, |
| 1200 |
\dim_use:N \l_sdaps_y_dim, |
| 1201 |
\dim_use:N \l_sdaps_width_dim, |
| 1202 |
\dim_use:N \l_sdaps_height_dim, |
| 1203 |
\dim_use:N \l_sdaps_textbox_linewidth_dim, |
| 1204 |
\tl_use:N \l_sdaps_var_tl, |
| 1205 |
} |
| 1206 |
} |
| 1207 |
} |
| 1208 |
\end{tikzpicture} |
| 1209 |
\sdaps_if_rtl:T {\endL} |
| 1210 |
} |
| 1211 |
|
| 1212 |
% We are done here, but we need the correct depth, so skip around a bit |
| 1213 |
\tex_penalty:D 10000 |
| 1214 |
\nointerlineskip |
| 1215 |
|
| 1216 |
\skip_vertical:n{ - \l__sdaps_textbox_dp_dim} |
| 1217 |
|
| 1218 |
\tex_penalty:D 10000 |
| 1219 |
\nointerlineskip |
| 1220 |
|
| 1221 |
\hbox:n { \vrule depth \l__sdaps_textbox_dp_dim height 0pt width 0pt } |
| 1222 |
|
| 1223 |
\int_gincr:N\g__sdaps_textbox_num_int |
| 1224 |
|
| 1225 |
\group_end: |
| 1226 |
\fi: |
| 1227 |
\fi: |
| 1228 |
} |
| 1229 |
\cs_generate_variant:Nn \sdaps_textbox_vhstretch:nnn { Vnn } |
| 1230 |
|
| 1231 |
\cs_new_protected_nopar:Nn \sdaps_textbox_vhstretch:nn |
| 1232 |
{ |
| 1233 |
\sdaps_textbox_vhstretch:nnn { #1 } { #2 } { 1 } |
| 1234 |
} |
| 1235 |
|
| 1236 |
|
| 1237 |
\cs_new_protected_nopar:Nn \sdaps_textbox_hstretch:nnnnn |
| 1238 |
{ |
| 1239 |
\group_begin: |
| 1240 |
\sdaps_if_rtl:T {\beginL} |
| 1241 |
|
| 1242 |
\__sdaps_textbox_prepare:n { #1 } |
| 1243 |
|
| 1244 |
\dim_set:Nn \l_tmpa_dim { #2 } |
| 1245 |
\dim_set:Nn \l_tmpb_dim { #3 } |
| 1246 |
|
| 1247 |
% Place a vrule to make space for the top/bottom padding |
| 1248 |
\tex_vrule:D depth \dim_use:N \l_tmpa_dim height \dim_use:N \l_tmpb_dim width 0pt \nobreak |
| 1249 |
\pgfsys@markposition{textboxstart\int_use:N\g__sdaps_textbox_num_int} \nobreak |
| 1250 |
|
| 1251 |
\skip_horizontal:n { #4 + \stretch{#5} } \nobreak |
| 1252 |
|
| 1253 |
% The textbox (rendered on the background) |
| 1254 |
\begin{tikzpicture}[remember~picture,overlay,shift=(current~page.south~west)] |
| 1255 |
\pgfsys@getposition{pgfpageorigin}{\@sdaps@pageorigin} |
| 1256 |
\pgfsys@getposition{textboxstart\int_use:N\g__sdaps_textbox_num_int}{\@sdaps@textboxpos} |
| 1257 |
% The position here is the position of the baseline. |
| 1258 |
% So move up by height (param 2) to get the correct vertical position. |
| 1259 |
\pgfpointadd{\@sdaps@textboxpos}{ |
| 1260 |
\pgfpointadd{\@sdaps@pageorigin}{\pgfpoint{0}{ \dim_use:N \l_tmpb_dim}} |
| 1261 |
} |
| 1262 |
\pgfgetlastxy{\l__sdaps_x}{\l__sdaps_y} |
| 1263 |
\dim_set:Nn \l_sdaps_x_dim {\l__sdaps_x} |
| 1264 |
\dim_set:Nn \l_sdaps_y_dim {\l__sdaps_y} |
| 1265 |
|
| 1266 |
\pgfsys@getposition{\pgfpictureid}{\@sdaps@textboxendpos} |
| 1267 |
% Calculate width and add the height to it |
| 1268 |
\pgfpointadd{ |
| 1269 |
\pgfpointdiff{\@sdaps@textboxpos}{\@sdaps@textboxendpos} |
| 1270 |
}{\pgfpoint{0pt}{\dim_use:N \l_tmpa_dim + \dim_use:N \l_tmpb_dim}} |
| 1271 |
\pgfgetlastxy{\l__sdaps_width}{\l__sdaps_height} |
| 1272 |
\dim_set:Nn \l_sdaps_width_dim {\l__sdaps_width} |
| 1273 |
\dim_set:Nn \l_sdaps_height_dim {\l__sdaps_height} |
| 1274 |
|
| 1275 |
% Draw the rectangle |
| 1276 |
\draw[line~width=\l_sdaps_textbox_linewidth_dim,fill=\l_sdaps_textbox_fill_tl,draw=\l_sdaps_textbox_draw_tl] ($(\l_sdaps_x_dim, \l_sdaps_y_dim) + 0.5 * (\l_sdaps_textbox_linewidth_dim, -\l_sdaps_textbox_linewidth_dim)$) rectangle +($(\l_sdaps_width_dim, -\l_sdaps_height_dim) - (\l_sdaps_textbox_linewidth_dim, -\l_sdaps_textbox_linewidth_dim)$); |
| 1277 |
|
| 1278 |
\begin{scope} |
| 1279 |
\seq_map_inline:Nn \g__sdaps_textbox_overlays_seq {##1} |
| 1280 |
\end{scope} |
| 1281 |
|
| 1282 |
\bool_if:NT \g_sdaps_write_enable_bool { |
| 1283 |
\sdaps_context_get:nN {id} \l__sdaps_tmpa_tl |
| 1284 |
\tl_if_eq:VnTF \l__sdaps_tmpa_tl { \q_no_value } { |
| 1285 |
\msg_warning:nn { sdapsbase } { no_qid } |
| 1286 |
} { |
| 1287 |
\sdaps_info_write_x:x { |
| 1288 |
Box[\l__sdaps_tmpa_tl]=\l__sdaps_textbox_boxtype_tl, |
| 1289 |
\exp_not:n{\int_use:N\g_sdaps_page_int}, |
| 1290 |
\dim_use:N \l_sdaps_x_dim, |
| 1291 |
\dim_use:N \l_sdaps_y_dim, |
| 1292 |
\dim_use:N \l_sdaps_width_dim, |
| 1293 |
\dim_use:N \l_sdaps_height_dim, |
| 1294 |
\dim_use:N \l_sdaps_textbox_linewidth_dim, |
| 1295 |
\tl_use:N \l_sdaps_var_tl, |
| 1296 |
} |
| 1297 |
} |
| 1298 |
} |
| 1299 |
\end{tikzpicture} |
| 1300 |
|
| 1301 |
\int_gincr:N\g__sdaps_textbox_num_int |
| 1302 |
|
| 1303 |
\sdaps_if_rtl:T {\endL} |
| 1304 |
\group_end: |
| 1305 |
} |
| 1306 |
|
| 1307 |
\cs_new_protected_nopar:Nn \__sdaps_textbox_prepare_coffin: |
| 1308 |
{ |
| 1309 |
\dim_set:Nn \l__sdaps_textbox_ht_dim { \coffin_ht:N \l__sdaps_textbox_coffin } |
| 1310 |
\dim_set:Nn \l__sdaps_textbox_dp_dim { \coffin_dp:N \l__sdaps_textbox_coffin } |
| 1311 |
\dim_set:Nn \l__sdaps_textbox_wd_dim { \coffin_wd:N \l__sdaps_textbox_coffin } |
| 1312 |
|
| 1313 |
\hcoffin_set:Nn \l_tmpa_coffin { |
| 1314 |
\tex_vrule:D depth 0pt height \dim_eval:n { \l__sdaps_textbox_ht_dim + \l__sdaps_textbox_pad_dim } width 0pt |
| 1315 |
|
| 1316 |
\pdfsavepos |
| 1317 |
|
| 1318 |
\dim_set:Nn \l_sdaps_width_dim {\l__sdaps_textbox_wd_dim + 2\l__sdaps_textbox_pad_dim} |
| 1319 |
\dim_set:Nn \l_sdaps_height_dim {\l__sdaps_textbox_ht_dim + \l__sdaps_textbox_dp_dim + 2\l__sdaps_textbox_pad_dim} |
| 1320 |
|
| 1321 |
% pdflast[xy]pos is the PDF position of the top left corner excluding the |
| 1322 |
% origin |
| 1323 |
\bool_if:NT \g_sdaps_write_enable_bool { |
| 1324 |
\sdaps_context_get:nN {id} \l__sdaps_tmpa_tl |
| 1325 |
\tl_if_eq:VnTF \l__sdaps_tmpa_tl { \q_no_value } { |
| 1326 |
\msg_warning:nn { sdapsbase } { no_qid } |
| 1327 |
} { |
| 1328 |
\sdaps_info_write_x:x { |
| 1329 |
Box[\l__sdaps_tmpa_tl]=\l__sdaps_textbox_boxtype_tl, |
| 1330 |
\exp_not:n{\int_use:N\g_sdaps_page_int}, |
| 1331 |
\exp_not:n{\dim_eval:n {\hoffset + \the\pdflastxpos sp}}, |
| 1332 |
\exp_not:n{\dim_eval:n} { \exp_not:n {\voffset + \the\pdflastypos sp} + \dim_use:N \l__sdaps_textbox_ht_dim + \dim_use:N \l__sdaps_textbox_pad_dim }, |
| 1333 |
\dim_use:N \l_sdaps_width_dim, |
| 1334 |
\dim_use:N \l_sdaps_height_dim, |
| 1335 |
\dim_use:N \l_sdaps_textbox_linewidth_dim, |
| 1336 |
\tl_use:N \l_sdaps_var_tl, |
| 1337 |
} |
| 1338 |
} |
| 1339 |
} |
| 1340 |
|
| 1341 |
\dim_set:Nn \l_sdaps_x_dim { 0pt } |
| 1342 |
\dim_set:Nn \l_sdaps_y_dim { \l__sdaps_textbox_ht_dim + \l__sdaps_textbox_pad_dim } |
| 1343 |
|
| 1344 |
% The textbox (rendered on the background) |
| 1345 |
\begin{tikzpicture}[overlay] |
| 1346 |
% Draw the rectangle |
| 1347 |
\draw[line~width=\l_sdaps_textbox_linewidth_dim,fill=\l_sdaps_textbox_fill_tl,draw=\l_sdaps_textbox_draw_tl] ($(\l_sdaps_x_dim, \l_sdaps_y_dim) + 0.5 * (\l_sdaps_textbox_linewidth_dim, -\l_sdaps_textbox_linewidth_dim)$) rectangle +($(\l_sdaps_width_dim, -\l_sdaps_height_dim) - (\l_sdaps_textbox_linewidth_dim, -\l_sdaps_textbox_linewidth_dim)$); |
| 1348 |
|
| 1349 |
\begin{scope} |
| 1350 |
\seq_map_inline:Nn \g__sdaps_textbox_overlays_seq {##1}% |
| 1351 |
\end{scope} |
| 1352 |
\end{tikzpicture} |
| 1353 |
\skip_horizontal:n { \l__sdaps_textbox_pad_dim } |
| 1354 |
} |
| 1355 |
|
| 1356 |
\hcoffin_set:Nn \l_tmpb_coffin { |
| 1357 |
\skip_horizontal:n { \l__sdaps_textbox_pad_dim } |
| 1358 |
\tex_vrule:D depth \l__sdaps_textbox_pad_dim height 0pt width 0pt |
| 1359 |
} |
| 1360 |
|
| 1361 |
\coffin_join:NnnNnnnn \l_tmpa_coffin { r } { H } \l__sdaps_textbox_coffin { l } { H } { 0pt } { 0pt } |
| 1362 |
\coffin_join:NnnNnnnn \l_tmpa_coffin { r } { b } \l_tmpb_coffin { l } { t } { 0pt } { 0pt } |
| 1363 |
|
| 1364 |
\coffin_set_eq:NN \l__sdaps_textbox_coffin \l_tmpa_coffin |
| 1365 |
|
| 1366 |
|
| 1367 |
\int_gincr:N\g__sdaps_textbox_num_int |
| 1368 |
} |
| 1369 |
|
| 1370 |
\coffin_new:N \l__sdaps_textbox_coffin |
| 1371 |
\cs_new_protected_nopar:Nn \sdaps_textbox_hbox:nnn |
| 1372 |
{ |
| 1373 |
\group_begin: |
| 1374 |
|
| 1375 |
\__sdaps_textbox_prepare:n { #1 } |
| 1376 |
|
| 1377 |
\hcoffin_set:Nn \l__sdaps_textbox_coffin { \tl_trim_spaces:n { #3 } } |
| 1378 |
|
| 1379 |
\dim_set:Nn \l__sdaps_textbox_pad_dim { #2 } |
| 1380 |
|
| 1381 |
\__sdaps_textbox_prepare_coffin: |
| 1382 |
|
| 1383 |
\coffin_typeset:Nnnnn \l__sdaps_textbox_coffin { l } { H } { 0pt } { 0pt } |
| 1384 |
|
| 1385 |
\group_end: |
| 1386 |
} |
| 1387 |
|
| 1388 |
\cs_new_protected:Nn \sdaps_textbox_vbox:nnnn |
| 1389 |
{ |
| 1390 |
\group_begin: |
| 1391 |
|
| 1392 |
\__sdaps_textbox_prepare:n { #1 } |
| 1393 |
|
| 1394 |
\dim_set:Nn \l__sdaps_textbox_pad_dim { #3 } |
| 1395 |
\dim_set:Nn \l__sdaps_textbox_wd_dim { #2 - 2\l__sdaps_textbox_pad_dim } |
| 1396 |
|
| 1397 |
\vcoffin_set:Nnn \l__sdaps_textbox_coffin { \l__sdaps_textbox_wd_dim } { \tl_trim_spaces:n { #4 }} |
| 1398 |
|
| 1399 |
\__sdaps_textbox_prepare_coffin: |
| 1400 |
|
| 1401 |
\coffin_typeset:Nnnnn \l__sdaps_textbox_coffin { l } { H } { 0pt } { 0pt } |
| 1402 |
|
| 1403 |
\group_end: |
| 1404 |
} |
| 1405 |
|
| 1406 |
% \end{macrocode} |
| 1407 |
% |
| 1408 |
% |
| 1409 |
% \subsection{Page Marking} |
| 1410 |
% |
| 1411 |
% SDAPS depends on certain markings on every page. The following function |
| 1412 |
% implement drawing these marks. |
| 1413 |
% |
| 1414 |
% \begin{macrocode} |
| 1415 |
|
| 1416 |
\int_new:N \g_sdaps_page_int |
| 1417 |
\int_set:Nn \g_sdaps_page_int { 0 } |
| 1418 |
|
| 1419 |
% Disabling recognition disables all drawings related to automatic recognition |
| 1420 |
\bool_new:N \g_sdaps_recognition_bool |
| 1421 |
\bool_new:N \g_sdaps_draft_bool |
| 1422 |
\bool_new:N \g_sdaps_twoside_bool |
| 1423 |
\bool_new:N \g_sdaps_print_questionnaire_id_bool |
| 1424 |
|
| 1425 |
\bool_set:Nn \g_sdaps_recognition_bool \c_true_bool |
| 1426 |
\bool_set:Nn \g_sdaps_draft_bool \c_true_bool |
| 1427 |
\bool_set:Nn \g_sdaps_twoside_bool \c_false_bool |
| 1428 |
\bool_set:Nn \g_sdaps_print_questionnaire_id_bool \c_false_bool |
| 1429 |
|
| 1430 |
|
| 1431 |
|
| 1432 |
\tl_new:N \g_sdaps_style_tl |
| 1433 |
\tl_new:N \g_sdaps_checkmode_tl |
| 1434 |
\dim_new:N \g_sdaps_edge_left_margin_dim |
| 1435 |
\dim_new:N \g_sdaps_edge_right_margin_dim |
| 1436 |
\dim_new:N \g_sdaps_edge_top_margin_dim |
| 1437 |
\dim_new:N \g_sdaps_edge_bottom_margin_dim |
| 1438 |
\dim_new:N \g_sdaps_edge_marker_linewidth_dim |
| 1439 |
\dim_new:N \g_sdaps_edge_marker_length_dim |
| 1440 |
|
| 1441 |
\dim_new:N \g_sdaps_classic_boxpad_dim |
| 1442 |
\dim_new:N \g_sdaps_classic_boxsize_dim |
| 1443 |
|
| 1444 |
|
| 1445 |
\tl_gset:Nn \g_sdaps_style_tl { code128 } |
| 1446 |
\tl_gset:Nn \g_sdaps_twoside_barcode_tl { both } |
| 1447 |
\tl_gset:Nn \g_sdaps_checkmode_tl { checkcorrect } |
| 1448 |
\dim_gset:Nn \g_sdaps_edge_left_margin_dim { 10mm } |
| 1449 |
\dim_gset:Nn \g_sdaps_edge_right_margin_dim { 10mm } |
| 1450 |
\dim_gset:Nn \g_sdaps_edge_top_margin_dim { 12mm } |
| 1451 |
\dim_gset:Nn \g_sdaps_edge_bottom_margin_dim { 12mm } |
| 1452 |
\dim_gset:Nn \g_sdaps_edge_marker_linewidth_dim { 1bp } |
| 1453 |
\dim_gset:Nn \g_sdaps_edge_marker_length_dim { 20mm } |
| 1454 |
|
| 1455 |
\dim_gset:Nn \g_sdaps_classic_boxpad_dim { 3mm } |
| 1456 |
\dim_gset:Nn \g_sdaps_classic_boxsize_dim { 3.5mm } |
| 1457 |
|
| 1458 |
|
| 1459 |
\tl_new:N \g__sdaps_questionnaire_id_tl |
| 1460 |
\tl_gset:Nn \g__sdaps_questionnaire_id_tl { } |
| 1461 |
|
| 1462 |
\tl_new:N \g_sdaps_questionnaire_id_label_tl |
| 1463 |
\tl_gset:Nn \g_sdaps_questionnaire_id_label_tl { } |
| 1464 |
|
| 1465 |
|
| 1466 |
\tl_new:N \g_sdaps_survey_id_tl |
| 1467 |
\tl_gset:Nn \g_sdaps_survey_id_tl { 32498923 } |
| 1468 |
|
| 1469 |
\tl_new:N \g_sdaps_global_id_tl |
| 1470 |
\tl_gset:Nn \g_sdaps_global_id_tl { } |
| 1471 |
|
| 1472 |
\tl_new:N \g_sdaps_global_id_label_tl |
| 1473 |
\tl_gset:Nn \g_sdaps_global_id_label_tl { } |
| 1474 |
|
| 1475 |
|
| 1476 |
|
| 1477 |
|
| 1478 |
% Settings for code128 barcodes (used in code128 style, who would have thought?) |
| 1479 |
\dim_new:N \c_sdaps_barcode_height_dim |
| 1480 |
\dim_gset:Nn \c_sdaps_barcode_height_dim {6.5mm} |
| 1481 |
% This is the same as the default |
| 1482 |
\dim_new:N \c_sdaps_barcode_bar_width_dim |
| 1483 |
\dim_gset:Nn \c_sdaps_barcode_bar_width_dim {0.33mm} |
| 1484 |
% Same as default. Barwidth is decreased for printing by this value. |
| 1485 |
\dim_new:N \c_sdaps_barcode_bcorr_dim |
| 1486 |
\dim_gset:Nn \c_sdaps_barcode_bcorr_dim {0.020mm} |
| 1487 |
|
| 1488 |
% The padding on the left/right of a barcode. This is the distance that the |
| 1489 |
% barcodes will be printed from the cornermarks |
| 1490 |
% Choosen to be the same as the barcode height. Note that the Code-128 |
| 1491 |
% standard requires a quiet zone of max(10*modulesize, ~6.4mm). |
| 1492 |
\dim_new:N \c_sdaps_barcode_hpad_dim |
| 1493 |
\dim_gset:Nn \c_sdaps_barcode_hpad_dim {6.5mm} |
| 1494 |
|
| 1495 |
% This needs to be smaller than 6.5mm because otherwise the content is too close. |
| 1496 |
% We set it so that it forms a golden ratio 6.5mm*(sqrt(5/4)-0.5). This means |
| 1497 |
% we have about 4.5mm padding to the content. |
| 1498 |
\dim_new:N \c_sdaps_barcode_vpad_dim |
| 1499 |
\dim_gset:Nn \c_sdaps_barcode_vpad_dim {4.02mm} |
| 1500 |
|
| 1501 |
|
| 1502 |
\cs_new_protected_nopar:Nn \sdaps_draw_codes: |
| 1503 |
{ |
| 1504 |
\group_begin: |
| 1505 |
\begin{scope}[line~width=\g_sdaps_edge_marker_linewidth_dim, shift={(current~page.south~west)}] |
| 1506 |
\str_if_eq:VnT \g_sdaps_style_tl { qr } { |
| 1507 |
\tl_if_empty:VF \g__sdaps_questionnaire_id_tl { |
| 1508 |
\begin{scope}[shift={($(\g_sdaps_edge_left_margin_dim, \g_sdaps_edge_bottom_margin_dim)$)}] |
| 1509 |
\node(barcode)[anchor=south~west,outer~sep=0,inner~sep=0]{ |
| 1510 |
\qrcode_render:nV {nolink,version=2,level=H,padding,height=10mm} \g__sdaps_questionnaire_id_tl |
| 1511 |
}; |
| 1512 |
\end{scope} |
| 1513 |
} |
| 1514 |
|
| 1515 |
% We unconditionally print this barcode, it is required for the recognition |
| 1516 |
% process. |
| 1517 |
\begin{scope}[shift={($(\paperwidth, 0) + (-\g_sdaps_edge_right_margin_dim, \g_sdaps_edge_bottom_margin_dim)$)}] |
| 1518 |
\pgfmathsetbasenumberlength{4} |
| 1519 |
\pgfmathdectobase{\paddedpage}{\int_use:N\g_sdaps_page_int}{10}% Yes, padding to 4 chars the hard way |
| 1520 |
\node(barcode)[anchor=south~east,outer~sep=0,inner~sep=0]{ |
| 1521 |
\qrcode_render:nx {nolink,version=2,level=H,padding,height=10mm} {\tl_use:N\g_sdaps_survey_id_tl\paddedpage} |
| 1522 |
}; |
| 1523 |
\end{scope} |
| 1524 |
|
| 1525 |
\tl_if_empty:VF \g_sdaps_global_id_tl { |
| 1526 |
\begin{scope}[shift={($(\paperwidth/2-\g_sdaps_edge_right_margin_dim/2+\g_sdaps_edge_left_margin_dim/2, \g_sdaps_edge_bottom_margin_dim)$)}] |
| 1527 |
\node(barcode)[anchor=south,outer~sep=0,inner~sep=0]{ |
| 1528 |
\qrcode_render:nV {nolink,version=2,level=H,padding,height=10mm} \g_sdaps_global_id_tl |
| 1529 |
}; |
| 1530 |
\end{scope} |
| 1531 |
} |
| 1532 |
} |
| 1533 |
|
| 1534 |
\str_if_eq:VnT \g_sdaps_style_tl { code128 } { |
| 1535 |
\tl_if_empty:VF \g__sdaps_questionnaire_id_tl { |
| 1536 |
% TODO: do not hardcode the font! |
| 1537 |
\ttfamily\footnotesize |
| 1538 |
|
| 1539 |
\begin{scope}[shift={($(\g_sdaps_edge_left_margin_dim, \g_sdaps_edge_bottom_margin_dim) + (\c_sdaps_barcode_hpad_dim, \c_sdaps_barcode_vpad_dim)$)}] |
| 1540 |
\node(barcode)[anchor=south~west,outer~sep=0,inner~sep=0]{ |
| 1541 |
\X = \c_sdaps_barcode_bar_width_dim |
| 1542 |
\bcorr = \c_sdaps_barcode_bcorr_dim |
| 1543 |
\barheight = \c_sdaps_barcode_height_dim |
| 1544 |
\code_render:V \g__sdaps_questionnaire_id_tl |
| 1545 |
}; |
| 1546 |
\node[below=1mm~of~barcode,distance=0,anchor=north,outer~sep=0,inner~sep=0]{ |
| 1547 |
\tl_if_empty:VTF \g_sdaps_questionnaire_id_label_tl { |
| 1548 |
\tl_use:N \g__sdaps_questionnaire_id_tl |
| 1549 |
} { |
| 1550 |
\tl_use:N \g_sdaps_questionnaire_id_label_tl |
| 1551 |
} |
| 1552 |
}; |
| 1553 |
\end{scope} |
| 1554 |
} |
| 1555 |
|
| 1556 |
% We unconditionally print this barcode, it is required for the recognition |
| 1557 |
% process. |
| 1558 |
\begin{scope}[shift={($(\paperwidth, 0) + (-\g_sdaps_edge_right_margin_dim, \g_sdaps_edge_bottom_margin_dim) + (-\c_sdaps_barcode_hpad_dim, \c_sdaps_barcode_vpad_dim)$)}] |
| 1559 |
\pgfmathsetbasenumberlength{4} |
| 1560 |
\pgfmathdectobase{\paddedpage}{\int_use:N\g_sdaps_page_int}{10}% Yes, padding to 4 chars the hard way |
| 1561 |
\node(barcode)[anchor=south~east,outer~sep=0,inner~sep=0]{ |
| 1562 |
\X = \c_sdaps_barcode_bar_width_dim |
| 1563 |
\bcorr = \c_sdaps_barcode_bcorr_dim |
| 1564 |
\barheight = \c_sdaps_barcode_height_dim |
| 1565 |
\code_render:x {\tl_use:N\g_sdaps_survey_id_tl \paddedpage} |
| 1566 |
}; |
| 1567 |
\node[below=1mm~of~barcode,distance=0,anchor=north,outer~sep=0,inner~sep=0]{ |
| 1568 |
% TODO: do not hardcode the font! |
| 1569 |
\ttfamily\footnotesize |
| 1570 |
|
| 1571 |
\tl_use:N\g_sdaps_survey_id_tl\,\paddedpage |
| 1572 |
}; |
| 1573 |
\end{scope} |
| 1574 |
|
| 1575 |
\tl_if_empty:VF \g_sdaps_global_id_tl { |
| 1576 |
\begin{scope}[shift={($(\paperwidth/2-\g_sdaps_edge_right_margin_dim/2+\g_sdaps_edge_left_margin_dim/2, 0) + (0, \g_sdaps_edge_bottom_margin_dim) + (0, \c_sdaps_barcode_vpad_dim)$)}] |
| 1577 |
\node(barcode)[anchor=south,outer~sep=0,inner~sep=0]{ |
| 1578 |
\X = \c_sdaps_barcode_bar_width_dim |
| 1579 |
\bcorr = \c_sdaps_barcode_bcorr_dim |
| 1580 |
\barheight = \c_sdaps_barcode_height_dim |
| 1581 |
\code_render:V \g_sdaps_global_id_tl |
| 1582 |
}; |
| 1583 |
\node[below=1mm~of~barcode,distance=0,anchor=north,outer~sep=0,inner~sep=0]{ |
| 1584 |
% TODO: do not hardcode the font! |
| 1585 |
\ttfamily\footnotesize |
| 1586 |
|
| 1587 |
\tl_if_empty:VTF \g_sdaps_global_id_label_tl { |
| 1588 |
\tl_use:N \g_sdaps_global_id_tl |
| 1589 |
} { |
| 1590 |
\tl_use:N \g_sdaps_global_id_label_tl |
| 1591 |
} |
| 1592 |
}; |
| 1593 |
\end{scope} |
| 1594 |
} |
| 1595 |
} |
| 1596 |
\end{scope}% |
| 1597 |
\group_end: |
| 1598 |
} |
| 1599 |
|
| 1600 |
\msg_new:nnn { sdapsbase } { classic_too_many_pages } { You~cannot~have~more~than~six~pages~with~the~classic~style. } |
| 1601 |
\msg_new:nnn { sdapsbase } { odd_page_count } { You~have~an~odd~number~of~pages,~this~does~not~work~in~duplex~mode! } |
| 1602 |
|
| 1603 |
% This needs to be called once for each page! |
| 1604 |
\cs_new_protected_nopar:Nn \sdaps_page_end: { |
| 1605 |
\bool_if:NTF \g_sdaps_recognition_bool { |
| 1606 |
\group_begin: |
| 1607 |
|
| 1608 |
\int_gincr:N\g_sdaps_page_int% |
| 1609 |
\sdaps_info_write:x{Pages=\int_use:N\g_sdaps_page_int} |
| 1610 |
|
| 1611 |
\normalfont% |
| 1612 |
|
| 1613 |
\begin{tikzpicture}[remember~picture,overlay]% |
| 1614 |
|
| 1615 |
%--------------------------------------------------------------------------- |
| 1616 |
% corner marks and corner boxes in classic mode |
| 1617 |
%--------------------------------------------------------------------------- |
| 1618 |
\begin{scope}[line~width=\g_sdaps_edge_marker_linewidth_dim, line~join=miter] |
| 1619 |
\begin{scope}[shift={($(current~page.north~west) + (\g_sdaps_edge_left_margin_dim, -\g_sdaps_edge_top_margin_dim)$)}] |
| 1620 |
\draw (0,-\g_sdaps_edge_marker_length_dim) -- (0, 0) -- (\g_sdaps_edge_marker_length_dim,0); |
| 1621 |
|
| 1622 |
\str_if_eq:VnT \g_sdaps_style_tl { classic } { |
| 1623 |
% TODO: Is the filled/non-filled mapping still correct? |
| 1624 |
\int_case:nnTF \g_sdaps_page_int { |
| 1625 |
{ 1 } { \draw } |
| 1626 |
{ 2 } { \fill } |
| 1627 |
{ 3 } { \fill } |
| 1628 |
{ 4 } { \fill } |
| 1629 |
{ 5 } { \fill } |
| 1630 |
{ 6 } { \draw } |
| 1631 |
} { |
| 1632 |
(\g_sdaps_classic_boxpad_dim, -\g_sdaps_classic_boxpad_dim) rectangle +(\g_sdaps_classic_boxsize_dim,-\g_sdaps_classic_boxsize_dim); |
| 1633 |
} { |
| 1634 |
% Error out (first time) |
| 1635 |
\msg_error:nn { sdapsbase } { classic_too_many_pages } |
| 1636 |
} |
| 1637 |
} |
| 1638 |
\end{scope} |
| 1639 |
\begin{scope}[shift={($(current~page.north~east) + (-\g_sdaps_edge_right_margin_dim, -\g_sdaps_edge_top_margin_dim)$)}] |
| 1640 |
\draw (0,-\g_sdaps_edge_marker_length_dim) -- (0,0) -- (-\g_sdaps_edge_marker_length_dim,0); |
| 1641 |
|
| 1642 |
\str_if_eq:VnT \g_sdaps_style_tl { classic } { |
| 1643 |
% TODO: Is the filled/non-filled mapping still correct? |
| 1644 |
\int_case:nnT \g_sdaps_page_int { |
| 1645 |
{ 1 } { \fill } |
| 1646 |
{ 2 } { \fill } |
| 1647 |
{ 3 } { \draw } |
| 1648 |
{ 4 } { \draw } |
| 1649 |
{ 5 } { \draw } |
| 1650 |
{ 6 } { \draw } |
| 1651 |
} { |
| 1652 |
(-\g_sdaps_classic_boxpad_dim, -\g_sdaps_classic_boxpad_dim) rectangle +(-\g_sdaps_classic_boxsize_dim,-\g_sdaps_classic_boxsize_dim); |
| 1653 |
} |
| 1654 |
} |
| 1655 |
\end{scope} |
| 1656 |
\begin{scope}[shift={($(current~page.south~west) + (\g_sdaps_edge_left_margin_dim, \g_sdaps_edge_bottom_margin_dim)$)}] |
| 1657 |
\draw (0,\g_sdaps_edge_marker_length_dim) -- (0, 0) -- (\g_sdaps_edge_marker_length_dim,0); |
| 1658 |
|
| 1659 |
\str_if_eq:VnT \g_sdaps_style_tl { classic } { |
| 1660 |
% TODO: Is the filled/non-filled mapping still correct? |
| 1661 |
\int_case:nnT \g_sdaps_page_int { |
| 1662 |
{ 1 } { \fill } |
| 1663 |
{ 2 } { \draw } |
| 1664 |
{ 3 } { \fill } |
| 1665 |
{ 4 } { \fill } |
| 1666 |
{ 5 } { \draw } |
| 1667 |
{ 6 } { \draw } |
| 1668 |
} { |
| 1669 |
(\g_sdaps_classic_boxpad_dim, \g_sdaps_classic_boxpad_dim) rectangle +(\g_sdaps_classic_boxsize_dim,\g_sdaps_classic_boxsize_dim); |
| 1670 |
} |
| 1671 |
} |
| 1672 |
\end{scope} |
| 1673 |
\begin{scope}[shift={($(current~page.south~east) + (-\g_sdaps_edge_right_margin_dim, \g_sdaps_edge_bottom_margin_dim)$)}] |
| 1674 |
\draw (0,\g_sdaps_edge_marker_length_dim) -- (0mm, 0mm) -- (-\g_sdaps_edge_marker_length_dim,0); |
| 1675 |
|
| 1676 |
\str_if_eq:VnT \g_sdaps_style_tl { classic } { |
| 1677 |
% TODO: Is the filled/non-filled mapping still correct? |
| 1678 |
\int_case:nnT \g_sdaps_page_int { |
| 1679 |
{ 1 } { \fill } |
| 1680 |
{ 2 } { \draw } |
| 1681 |
{ 3 } { \fill } |
| 1682 |
{ 4 } { \draw } |
| 1683 |
{ 5 } { \draw } |
| 1684 |
{ 6 } { \fill } |
| 1685 |
} { |
| 1686 |
(-\g_sdaps_classic_boxpad_dim, \g_sdaps_classic_boxpad_dim) rectangle +(-\g_sdaps_classic_boxsize_dim,\g_sdaps_classic_boxsize_dim); |
| 1687 |
} |
| 1688 |
} |
| 1689 |
\end{scope} |
| 1690 |
\end{scope} |
| 1691 |
|
| 1692 |
%--------------------------------------------------------------------------- |
| 1693 |
% barcodes/qr codes |
| 1694 |
%--------------------------------------------------------------------------- |
| 1695 |
\bool_if:NTF \g__sdaps_last_page_bool { |
| 1696 |
|
| 1697 |
\int_compare:nNnTF { \g_sdaps_page_int } = { 1 } { |
| 1698 |
% if we have a one page document, just always stamp the last |
| 1699 |
% page. This means that SDAPS can fall back to simplex mode |
| 1700 |
% automatically. |
| 1701 |
\sdaps_draw_codes: |
| 1702 |
} { |
| 1703 |
|
| 1704 |
\bool_if:NTF \g_sdaps_twoside_bool { |
| 1705 |
\int_if_odd:VT \g_sdaps_page_int { |
| 1706 |
% This should no happen; draw a barcode though to keep things |
| 1707 |
% somewhat sane. |
| 1708 |
\msg_warning:nn { sdapsbase } { odd_page_count } |
| 1709 |
\sdaps_draw_codes: |
| 1710 |
} { |
| 1711 |
% Even page (i.e. back) has a barcode except in "front" mode |
| 1712 |
\str_if_eq:VnF \g_sdaps_twoside_barcode_tl { front } { |
| 1713 |
\sdaps_draw_codes: |
| 1714 |
} |
| 1715 |
} |
| 1716 |
} { |
| 1717 |
\sdaps_draw_codes: |
| 1718 |
} |
| 1719 |
} |
| 1720 |
|
| 1721 |
% TODO: Check whether the page count is as expected? |
| 1722 |
} { |
| 1723 |
\bool_if:NTF \g_sdaps_twoside_bool { |
| 1724 |
\str_if_eq:VnTF \g_sdaps_twoside_barcode_tl { both } { |
| 1725 |
\sdaps_draw_codes: |
| 1726 |
} { |
| 1727 |
\str_if_eq:VnTF \g_sdaps_twoside_barcode_tl { front } { |
| 1728 |
\int_if_odd:VT \g_sdaps_page_int { |
| 1729 |
\sdaps_draw_codes: |
| 1730 |
} |
| 1731 |
} { % And back is the only thing left |
| 1732 |
\int_if_odd:VF \g_sdaps_page_int { |
| 1733 |
\sdaps_draw_codes: |
| 1734 |
} |
| 1735 |
} |
| 1736 |
} |
| 1737 |
} { |
| 1738 |
\sdaps_draw_codes: |
| 1739 |
} |
| 1740 |
} |
| 1741 |
|
| 1742 |
%--------------------------------------------------------------------------- |
| 1743 |
% watermark for non final mode |
| 1744 |
%--------------------------------------------------------------------------- |
| 1745 |
\bool_if:NT \g_sdaps_draft_bool { |
| 1746 |
\node [rotate=60,scale=10,text~opacity=0.2,color=red] |
| 1747 |
at (current~page.center) {\textsc{draft}}; |
| 1748 |
} |
| 1749 |
\end{tikzpicture} |
| 1750 |
|
| 1751 |
\group_end: |
| 1752 |
} { |
| 1753 |
\int_gincr:N\g_sdaps_page_int |
| 1754 |
} |
| 1755 |
} |
| 1756 |
|
| 1757 |
|
| 1758 |
% \end{macrocode} |
| 1759 |
% |
| 1760 |
% \subsection{Starting/Ending an SDAPS context} |
| 1761 |
% |
| 1762 |
% These need to be used to begin rendering into an SDAPS context and finishing |
| 1763 |
% everything off. |
| 1764 |
% |
| 1765 |
% Note that this base package does not automatically call |
| 1766 |
% \textbackslash sdaps\_page\_end: for |
| 1767 |
% you, so if you are using this class directly you will need to make sure that |
| 1768 |
% this handler is called after all form elements on a page. An easy of doing |
| 1769 |
% this is to call it from inside the page footer. |
| 1770 |
% |
| 1771 |
% |
| 1772 |
% %\begin{macrocode} |
| 1773 |
|
| 1774 |
\bool_new:N \g__sdaps_last_page_bool |
| 1775 |
|
| 1776 |
\cs_new_protected_nopar:Nn \sdaps_begin: { |
| 1777 |
\bool_gset:Nn \g__sdaps_last_page_bool \c_false_bool |
| 1778 |
|
| 1779 |
% TODO: We really want to make sure nobody modifies the values after \sdaps_begin: |
| 1780 |
\sdaps_info_write:x{SDAPSVersion=1.9.10} |
| 1781 |
\sdaps_info_write:x{Duplex=\bool_if:NTF \g_sdaps_twoside_bool {true} {false}} |
| 1782 |
\sdaps_info_write:x{PrintQuestionnaireId=\bool_if:NTF \g_sdaps_print_questionnaire_id_bool {1} {0}} |
| 1783 |
\sdaps_info_write:x{ |
| 1784 |
PageSize=\the\paperwidth, \the\paperheight |
| 1785 |
} |
| 1786 |
\sdaps_info_write:x{Style=\g_sdaps_style_tl} |
| 1787 |
\sdaps_info_write:x{CheckMode=\g_sdaps_checkmode_tl} |
| 1788 |
\sdaps_info_write:x{GlobalID=\g_sdaps_global_id_tl} |
| 1789 |
\sdaps_info_write:x{GlobalIDLabel=\g_sdaps_global_id_label_tl} |
| 1790 |
|
| 1791 |
\sdaps_info_write:x{ |
| 1792 |
CornerMarkMargin= |
| 1793 |
\dim_use:N\g_sdaps_edge_left_margin_dim, |
| 1794 |
\dim_use:N\g_sdaps_edge_right_margin_dim, |
| 1795 |
\dim_use:N\g_sdaps_edge_top_margin_dim, |
| 1796 |
\dim_use:N\g_sdaps_edge_bottom_margin_dim |
| 1797 |
} |
| 1798 |
|
| 1799 |
\int_gset:Nn \g_sdaps_page_int { 0 } |
| 1800 |
} |
| 1801 |
|
| 1802 |
\cs_new_protected_nopar:Nn \sdaps_end: { |
| 1803 |
% Note that using \sdaps_info_write_x:n may not work in some cases. |
| 1804 |
% For this reason we write the out the Pages counter after each page, |
| 1805 |
% which is fine to do. |
| 1806 |
% Note that this means that the below "hack" to make onesided documents |
| 1807 |
% work even in twoside (duplex) mode may not always work either. |
| 1808 |
|
| 1809 |
\bool_gset:Nn \g__sdaps_last_page_bool \c_true_bool |
| 1810 |
} |
| 1811 |
|
| 1812 |
|
| 1813 |
% |
| 1814 |
% \end{macrocode} |
| 1815 |
% |
| 1816 |
|
| 1817 |
% \Finale |
| 1818 |
\endinput |