| 1 |
%% |
| 2 |
%% This is file `qrcodetikz.sty', |
| 3 |
%% generated with the docstrip utility. |
| 4 |
%% |
| 5 |
%% The original source files were: |
| 6 |
%% |
| 7 |
%% qrcodetikz.dtx |
| 8 |
%% |
| 9 |
%% Copyright (C) 2025 Miguel V. S. Frasson ([email protected]) |
| 10 |
%% |
| 11 |
%% This file is part of the `qrcodetikz' package. |
| 12 |
%% |
| 13 |
%% This package may be distributed under the terms of the LaTeX |
| 14 |
%% Project Public License, as described in lppl.txt in the base |
| 15 |
%% LaTeX distribution, either version 1.3 or (at your option) |
| 16 |
%% any later version. |
| 17 |
%% |
| 18 |
%% This program is distributed in the hope that it will be useful, |
| 19 |
%% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 |
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 21 |
%% |
| 22 |
\NeedsTeXFormat{LaTeX2e}[2020-02-02] |
| 23 |
\ProvidesPackage{qrcodetikz}[2025-05-28 v1.0 Prettier qrcodes] |
| 24 |
\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{qrcode}} |
| 25 |
\ProcessOptions |
| 26 |
\RequirePackage{qrcode} |
| 27 |
\RequirePackage{tikz} |
| 28 |
\ExplSyntaxOn |
| 29 |
\int_new:N \l_qrtz_size_int |
| 30 |
\tl_new:N \l_qrtz_x |
| 31 |
\tl_new:N \l_qrtz_y |
| 32 |
\tl_new:N \l_qrtz_dir |
| 33 |
\tl_new:N \l_qrtz_component |
| 34 |
\tl_new:N \l_qrtz_path |
| 35 |
\tl_new:N \l_qrtz_border |
| 36 |
\tl_new:N \l_qrtz_inner |
| 37 |
\tl_new:N \l_qrtz_straight |
| 38 |
\tl_new:N \l_qrtz_outer |
| 39 |
\intarray_new:Nn \g_qrtz_labels_intarray {177 * 177} |
| 40 |
\seq_new:N \l_qrtz_border_seq |
| 41 |
\prop_new:N \g_qrtz_paths_prop |
| 42 |
\bool_new:N \g_qrtz_aux_fallback_written_bool |
| 43 |
\bool_gset_false:N \g_qrtz_aux_fallback_written_bool |
| 44 |
\bool_new:N \l_qrtz_continue_straight_bool |
| 45 |
\bool_new:N \l_qrtz_can_continue_bool |
| 46 |
\cs_new:Nn \qrtz_index:nn { |
| 47 |
( \l_qrtz_size_int - (#2) ) * \l_qrtz_size_int + (#1) |
| 48 |
} |
| 49 |
\cs_new:Nn \qrtz_pixel:nn { |
| 50 |
\intarray_item:Nn \g_qrtz_labels_intarray { \qrtz_index:nn {#1}{#2} } |
| 51 |
} |
| 52 |
\cs_new:Nn \qrtz_find:nnN { |
| 53 |
\int_set:Nn #3 { \qrtz_index:nn {#1}{#2} } |
| 54 |
\int_until_do:nNnn {\intarray_item:Nn \g_qrtz_labels_intarray #3} = #3 |
| 55 |
{ |
| 56 |
\int_set:Nn #3 {\intarray_item:Nn \g_qrtz_labels_intarray #3} |
| 57 |
} |
| 58 |
} |
| 59 |
\cs_new:Nn \qrtz_union:nnnn { |
| 60 |
\qrtz_find:nnN {#1}{#2} \l_tmpa_int |
| 61 |
\qrtz_find:nnN {#3}{#4} \l_tmpb_int |
| 62 |
\intarray_gset:Nnn \g_qrtz_labels_intarray \l_tmpb_int \l_tmpa_int |
| 63 |
} |
| 64 |
\cs_new:Nn \qrtz_compute_components:n { |
| 65 |
\int_zero:N \l_tmpa_int |
| 66 |
\tl_map_inline:nn {#1} |
| 67 |
{ |
| 68 |
\int_incr:N \l_tmpa_int |
| 69 |
\intarray_gset:Nnn |
| 70 |
\g_qrtz_labels_intarray { \l_tmpa_int } { ##1 * \l_tmpa_int } |
| 71 |
} |
| 72 |
\int_set:Nn \l_qrtz_size_int { \fp_to_int:n { sqrt( \l_tmpa_int ) } } |
| 73 |
\int_step_inline:nn { \l_qrtz_size_int } { % i=##1 |
| 74 |
\int_step_inline:nn { \l_qrtz_size_int } { % j = ####1 |
| 75 |
|
| 76 |
\bool_if:nT { |
| 77 |
\bool_lazy_all_p:n { |
| 78 |
{ \int_compare_p:nNn {##1} < \l_qrtz_size_int } |
| 79 |
{ \int_compare_p:nNn { \qrtz_pixel:nn {##1}{####1} } > 0 } |
| 80 |
{ \int_compare_p:nNn { \qrtz_pixel:nn {1 + ##1}{####1} } > 0 } |
| 81 |
} |
| 82 |
} |
| 83 |
{ \qrtz_union:nnnn {##1}{####1} {1 + ##1}{####1} } |
| 84 |
|
| 85 |
\bool_if:nT { |
| 86 |
\bool_lazy_all_p:n { |
| 87 |
{ \int_compare_p:nNn {####1} < \l_qrtz_size_int } |
| 88 |
{ \int_compare_p:nNn { \qrtz_pixel:nn {##1}{####1} } > 0 } |
| 89 |
{ \int_compare_p:nNn { \qrtz_pixel:nn {##1}{1 + ####1} } > 0 } |
| 90 |
} |
| 91 |
} |
| 92 |
{ \qrtz_union:nnnn {##1}{####1} {##1}{1 + ####1} } |
| 93 |
} |
| 94 |
} |
| 95 |
\int_step_inline:nn { \l_qrtz_size_int } { % i = ##1 |
| 96 |
\int_step_inline:nn { \l_qrtz_size_int } { % j = ####1 |
| 97 |
|
| 98 |
\int_set:Nn \l_tmpa_int { \qrtz_index:nn {##1} {####1} } |
| 99 |
|
| 100 |
\int_compare:nNnF |
| 101 |
{\intarray_item:Nn \g_qrtz_labels_intarray \l_tmpa_int} = 0 |
| 102 |
{ |
| 103 |
\qrtz_find:nnN {##1} {####1} \l_tmpb_int |
| 104 |
\intarray_gset:Nnn \g_qrtz_labels_intarray \l_tmpa_int \l_tmpb_int |
| 105 |
} |
| 106 |
} |
| 107 |
} |
| 108 |
} |
| 109 |
\cs_new:Nn \qrtz_build_border_list:n { |
| 110 |
\qrtz_compute_components:n { #1 } |
| 111 |
% |
| 112 |
\seq_clear:N \l_qrtz_border_seq |
| 113 |
% |
| 114 |
\int_step_inline:nn { \l_qrtz_size_int } |
| 115 |
{ |
| 116 |
% x = ##1 |
| 117 |
\int_step_inline:nn { \l_qrtz_size_int } |
| 118 |
{ |
| 119 |
% y = ####1 |
| 120 |
\tl_set:Ne \l_qrtz_component { \qrtz_pixel:nn {##1}{####1} } |
| 121 |
\int_compare:nNnT { \l_qrtz_component } > 0 |
| 122 |
{ |
| 123 |
\bool_lazy_or:nnT |
| 124 |
{ \int_compare_p:nNn { ##1 } = 1 } |
| 125 |
{ \int_compare_p:nNn { \qrtz_pixel:nn {##1 - 1}{####1} } = 0 } |
| 126 |
{ |
| 127 |
\seq_put_left:Ne \l_qrtz_border_seq |
| 128 |
{ ##1, \int_eval:n{ ####1 + 1 }, 3, \l_qrtz_component } |
| 129 |
} |
| 130 |
% |
| 131 |
\bool_lazy_or:nnT |
| 132 |
{ \int_compare_p:nNn { ##1 } = { \l_qrtz_size_int } } |
| 133 |
{ \int_compare_p:nNn { \qrtz_pixel:nn {##1 + 1}{####1} } = 0 } |
| 134 |
{ |
| 135 |
\seq_put_left:Ne \l_qrtz_border_seq |
| 136 |
{ \int_eval:n{ ##1 + 1 }, ####1, 1, \l_qrtz_component } |
| 137 |
} |
| 138 |
% |
| 139 |
\bool_lazy_or:nnT |
| 140 |
{ \int_compare_p:nNn { ####1 } = { \l_qrtz_size_int } } |
| 141 |
{ \int_compare_p:nNn { \qrtz_pixel:nn {##1}{####1+1} } = 0 } |
| 142 |
{ |
| 143 |
\seq_put_left:Ne \l_qrtz_border_seq |
| 144 |
{\int_eval:n{##1+1}, \int_eval:n{####1+1}, 2, \l_qrtz_component } |
| 145 |
} |
| 146 |
% |
| 147 |
\bool_lazy_or:nnT |
| 148 |
{ \int_compare_p:nNn { ####1 } = 1 } |
| 149 |
{ \int_compare_p:nNn { \qrtz_pixel:nn {##1}{####1-1} } = 0 } |
| 150 |
{ |
| 151 |
\seq_put_left:Ne \l_qrtz_border_seq |
| 152 |
{ ##1, ####1, 0, \l_qrtz_component } |
| 153 |
} |
| 154 |
} |
| 155 |
} |
| 156 |
} |
| 157 |
} |
| 158 |
\cs_new:Nn \qrtz_build_tikz_path:nN { |
| 159 |
\message{<Computing~ Tikz~ path~ ...} |
| 160 |
% build border list |
| 161 |
\qrtz_build_border_list:n { #1 } |
| 162 |
\tl_set:Nn \l_qrtz_path {} |
| 163 |
\bool_until_do:nn { \seq_if_empty_p:N \l_qrtz_border_seq } |
| 164 |
{ |
| 165 |
\bool_set_true:N \l_qrtz_can_continue_bool |
| 166 |
\bool_set_false:N \l_qrtz_continue_straight_bool |
| 167 |
\seq_get_left:NN \l_qrtz_border_seq \l_qrtz_border |
| 168 |
\tl_set:Ne \l_qrtz_x { \clist_item:Nn \l_qrtz_border 1 } |
| 169 |
\tl_set:Ne \l_qrtz_y { \clist_item:Nn \l_qrtz_border 2 } |
| 170 |
\tl_set:Ne \l_qrtz_dir { \clist_item:Nn \l_qrtz_border 3 } |
| 171 |
\tl_set:Ne \l_qrtz_component { \clist_item:Nn \l_qrtz_border 4 } |
| 172 |
\bool_while_do:Nn \l_qrtz_can_continue_bool |
| 173 |
{ |
| 174 |
\seq_remove_all:NV \l_qrtz_border_seq \l_qrtz_border |
| 175 |
|
| 176 |
\bool_if:NF \l_qrtz_continue_straight_bool |
| 177 |
{ % else |
| 178 |
\tl_put_right:Ne \l_qrtz_path { (\l_qrtz_x,\l_qrtz_y) -- } |
| 179 |
} |
| 180 |
|
| 181 |
\tl_set:Ne \l_qrtz_dir { \clist_item:Nn \l_qrtz_border 3 } |
| 182 |
|
| 183 |
\int_case:nn { \l_qrtz_dir } |
| 184 |
{ |
| 185 |
0 { \tl_set:Ne \l_qrtz_x { \int_eval:n { \l_qrtz_x + 1 } } } |
| 186 |
1 { \tl_set:Ne \l_qrtz_y { \int_eval:n { \l_qrtz_y + 1 } } } |
| 187 |
2 { \tl_set:Ne \l_qrtz_x { \int_eval:n { \l_qrtz_x - 1 } } } |
| 188 |
3 { \tl_set:Ne \l_qrtz_y { \int_eval:n { \l_qrtz_y - 1 } } } |
| 189 |
} |
| 190 |
\tl_set:Ne \l_qrtz_inner { % inner=left: dir+1 mod 4 |
| 191 |
\l_qrtz_x, \l_qrtz_y, |
| 192 |
\int_eval:n { \int_mod:nn { \l_qrtz_dir + 1 } { 4 } }, |
| 193 |
\l_qrtz_component |
| 194 |
} |
| 195 |
|
| 196 |
\tl_set:Ne \l_qrtz_straight { |
| 197 |
\l_qrtz_x, \l_qrtz_y, \l_qrtz_dir, \l_qrtz_component |
| 198 |
} |
| 199 |
|
| 200 |
\tl_set:Ne \l_qrtz_outer { % outer=right: dir-1 +4 mod 4 |
| 201 |
\l_qrtz_x, \l_qrtz_y, |
| 202 |
\int_eval:n { \int_mod:nn { \l_qrtz_dir + 3 } { 4 } }, |
| 203 |
\l_qrtz_component |
| 204 |
} |
| 205 |
\seq_if_in:NVTF \l_qrtz_border_seq \l_qrtz_inner |
| 206 |
{ |
| 207 |
\bool_set_false:N \l_qrtz_continue_straight_bool |
| 208 |
\tl_set_eq:NN \l_qrtz_border \l_qrtz_inner |
| 209 |
} |
| 210 |
{ % else |
| 211 |
\seq_if_in:NVTF \l_qrtz_border_seq \l_qrtz_straight |
| 212 |
{ |
| 213 |
\bool_set_true:N \l_qrtz_continue_straight_bool |
| 214 |
\tl_set_eq:NN \l_qrtz_border \l_qrtz_straight |
| 215 |
} |
| 216 |
{ % else |
| 217 |
\seq_if_in:NVTF \l_qrtz_border_seq \l_qrtz_outer |
| 218 |
{ |
| 219 |
\bool_set_false:N \l_qrtz_continue_straight_bool |
| 220 |
\tl_set_eq:NN \l_qrtz_border \l_qrtz_outer |
| 221 |
} |
| 222 |
{ % else (dead-end) |
| 223 |
\bool_set_false:N \l_qrtz_can_continue_bool |
| 224 |
\tl_put_right:Nn \l_qrtz_path { cycle } |
| 225 |
} % fi |
| 226 |
} % fi |
| 227 |
} % fi |
| 228 |
} % end-while |
| 229 |
} % end-while |
| 230 |
\tl_set_eq:NN #2 \l_qrtz_path |
| 231 |
\message{~done>.^^J}% |
| 232 |
} |
| 233 |
\cs_generate_variant:Nn \qrtz_build_tikz_path:nN { eN } |
| 234 |
|
| 235 |
\tl_set_eq:NN \QRTZBinaryToTikzPath \qrtz_build_tikz_path:eN |
| 236 |
\cs_new:Nn \qrtz_get_tikz_path_maybe_saved:nN { |
| 237 |
\prop_get:NeN \g_qrtz_paths_prop { #1 } { #2 } |
| 238 |
\use:c {ifqr@forget@mode} \tl_set_eq:NN #2 \q_no_value \fi |
| 239 |
\quark_if_no_value:NTF #2 |
| 240 |
{ |
| 241 |
\qrtz_build_tikz_path:nN { #1 }{ #2 } |
| 242 |
\qrtz_save_write_path_to_aux:ee { #1 }{ #2 } |
| 243 |
} |
| 244 |
{ |
| 245 |
\message{<Using~ saved~ Tikz~ path>^^J}% |
| 246 |
} |
| 247 |
} |
| 248 |
|
| 249 |
\cs_generate_variant:Nn \qrtz_get_tikz_path_maybe_saved:nN { eN } |
| 250 |
|
| 251 |
\tl_set_eq:NN \QRTZgetTikzPathMaybeSaved \qrtz_get_tikz_path_maybe_saved:eN |
| 252 |
\cs_new:Nn \qrtz_save_write_path_to_aux:nn { |
| 253 |
\bool_if:NF \g_qrtz_aux_fallback_written_bool |
| 254 |
{ |
| 255 |
\iow_shipout:cn { @auxout } { \providecommand{\QRTZsavePath}[2]{} } |
| 256 |
\bool_gset_true:N \g_qrtz_aux_fallback_written_bool |
| 257 |
} |
| 258 |
\message{<Writing~ Tikz~ path~ to~ aux~ file>^^J}% |
| 259 |
\iow_shipout:cn { @auxout } { \QRTZsavePath {#1}{#2} } |
| 260 |
\prop_get:NnN \g_qrtz_paths_prop { #1 } \l_tmpa_tl |
| 261 |
\quark_if_no_value:NT \l_tmpa_tl |
| 262 |
{ |
| 263 |
\message{<Saving~ Tikz~ path~ to~ memory~ for~ later~ use>^^J}% |
| 264 |
\prop_gput:Nnn \g_qrtz_paths_prop { #1 } { #2 } |
| 265 |
} |
| 266 |
} |
| 267 |
|
| 268 |
\cs_generate_variant:Nn \qrtz_save_write_path_to_aux:nn { ee } |
| 269 |
|
| 270 |
\tl_set_eq:NN \QRTZsavePath \qrtz_save_write_path_to_aux:nn |
| 271 |
\cs_new:Nn \qrtz_print_qr_matrix:n { |
| 272 |
\message{^^J~(} |
| 273 |
\use:c{qr@matrixtobinary}{#1} % stores into \qr@binarymatrix@result |
| 274 |
\QRTZprintBinaryString{ \use:c{qr@binarymatrix@result} } |
| 275 |
\message{~)~} |
| 276 |
} |
| 277 |
|
| 278 |
\tl_set_eq:NN \QRTZprintQRmatrix \qrtz_print_qr_matrix:n |
| 279 |
\ExplSyntaxOff |
| 280 |
\newcommand{\QRTZ@extraFillOpts}{} |
| 281 |
\newcommand{\qrcodeFillOptions}[1]{\gdef\QRTZ@extraFillOpts{#1}} |
| 282 |
|
| 283 |
\newcommand{\QRTZprintBinaryString}[1]{% |
| 284 |
\setlength{\qr@modulesize}{\qr@desiredheight}% |
| 285 |
\divide\qr@modulesize by \qr@size\relax |
| 286 |
\setlength{\qr@minipagewidth}{\qr@modulesize}% |
| 287 |
\multiply\qr@minipagewidth by \qr@size\relax |
| 288 |
\ifqr@tight |
| 289 |
\else |
| 290 |
\advance\qr@minipagewidth by 8\qr@modulesize |
| 291 |
\fi |
| 292 |
\QRTZgetTikzPathMaybeSaved{#1}{\QRTZtikzPath}% |
| 293 |
\pgfmathsetmacro\QRTZtikzScale{0.03514598*\qr@desiredheight/\qr@size}% |
| 294 |
\expandafter\def\expandafter\QRTZinternalFillOptions\expandafter{\expandafter |
| 295 |
[\QRTZ@extraFillOpts,scale=\QRTZtikzScale,even odd rule]}% |
| 296 |
\parbox{\qr@minipagewidth}{% |
| 297 |
\tikz |
| 298 |
\expandafter\fill\QRTZinternalFillOptions |
| 299 |
\ifqr@tight\else(-3,-3)(\qr@size+5,\qr@size+5)\fi |
| 300 |
\QRTZtikzPath ;% |
| 301 |
}% |
| 302 |
} |
| 303 |
\let\qr@printmatrixORIGINAL\qr@printmatrix |
| 304 |
\let\qr@printsavedbinarymatrixORIGINAL\qr@printsavedbinarymatrix |
| 305 |
|
| 306 |
\newcommand{\qrcodetikzOn}{% |
| 307 |
\let\qr@printmatrix\QRTZprintQRmatrix |
| 308 |
\let\qr@printsavedbinarymatrix\QRTZprintBinaryString |
| 309 |
} |
| 310 |
|
| 311 |
\newcommand{\qrcodetikzOff}{% |
| 312 |
\let\qr@printmatrix\qr@printmatrixORIGINAL |
| 313 |
\let\qr@printsavedbinarymatrix\qr@printsavedbinarymatrixORIGINAL |
| 314 |
} |
| 315 |
|
| 316 |
\qrcodetikzOn |
| 317 |
\def\qr@fivezeros{00000}% |
| 318 |
\endinput |
| 319 |
%% |
| 320 |
%% End of file `qrcodetikz.sty'. |