Debian Codegraph @

texmf-dist/source/latex/gs1/GS1.dtx

raw
1 % \iffalse meta-comment
2 %
3 %% File: GS1.dtx Copyright (C) 2012-2017 Markus Kohm
4 %%
5 %% It may be distributed and/or modified under the conditions of the
6 %% LaTeX Project Public License (LPPL), either version 1.3c of this
7 %% license or (at your option) any later version. The latest version
8 %% of this license is in the file
9 %%
10 %% http://www.latex-project.org/lppl.txt
11 %%
12 %% This file is part of the "GS1 bundle" (The Work in LPPL)
13 %% and all files in that bundle must be distributed together.
14 %%
15 %% The released version of this bundle is available from CTAN.
16 %%
17 %% -------------------------------------------------------------------------
18 %
19 %<*driver|package|test>
20 \RequirePackage{expl3}[2017/05/29]
21 \GetIdInfo$Id: GS1.dtx 23 2021-06-17 07:00:36Z mjk $
22 {GS1 code handler and barcode generator}
23 %</driver|package|test>
24 %<*driver>
25 \documentclass{l3doc}
26 \begin{document}
27 \DocInput{\jobname.dtx}
28 \end{document}
29 %</driver>
30 %<*test>
31 \documentclass{article}
32 \usepackage{GS1}
33 \ExplSyntaxOn
34 \msg_new:nnn { GS1/test } { function }
35 {
36 Something~is~wrong~with~function~#1
37 \msg_line_context:~~of~\c_sys_jobname_str.tex.
38 }
39 \ExplSyntaxOff
40 \begin{document}
41 %</test>
42 % \fi
43 %
44 % \title{^^A
45 % The \pkg{GS1}\thanks
46 % {^^A
47 % GS1 is a registered trademark of GS1 AISBL. Nevertheless, GS1 AISBL
48 % neither has any rights on this package, nor is responsible for it in
49 % any kind. The package's name should indicate only, that the package
50 % implements some aspects of GS1 codes.^^A
51 % }
52 % package\\
53 % GS1 Code Handler and Barcode Generator\thanks
54 % {^^A
55 % This file describes v\ExplFileVersion,
56 % last revised \ExplFileDate.^^A
57 % }^^A
58 % }
59 %
60 % \author{^^A
61 % Markus Kohm\thanks
62 % {^^A
63 % E-mail: \href{mailto:[email protected]}{[email protected]}^^A
64 % }^^A
65 % }
66 %
67 % \date{Released \ExplFileDate}
68 %
69 % \maketitle
70 %
71 % \begin{documentation}
72 % \begin{abstract}
73 % There are several barcode packages out in the world, but they either need
74 % PStricks, or are restricted to EAN-13 barcodes. And most of all, they are
75 % all \LaTeXe. I've decided to write a package, that supports several GS1
76 % codes, and at almost the same time, I've decided to give L3 a chance. So
77 % I've started an experimental GS1 package using \pkg{expl3}. Using
78 % \pkg{expl3} was the main reason writing this package.
79 % \end{abstract}
80 %
81 % \tableofcontents
82 %
83 % \section*{Preface}
84 %
85 % Design and implementation of this package based on
86 % \begin{quote}\begin{description}
87 % \item[GS1:] ``Allgemeine GS1 Spezifikation'', Version~12.0, Januar~2012,
88 % Ausgabe~1.
89 % \end{description}\end{quote}
90 % This is the official GS1 specification for Germany, Austria and Switzerland.
91 %
92 % Currently only EAN-8 and EAN-13 codes and bar codes without extension have
93 % been implemented. Others may follow in future.
94 %
95 %
96 % \section{L3 Functions and Variables for GS1 Codes}
97 % \label{sec:doc:functions.and.variables}
98 %
99 % First of all: Please note, that the concept of private functions and
100 % variables is not well defined in \TeX. Several variables, that I'd have
101 % made private in C++, haven't been declared to be private in this
102 % implementation. Maybe I should change this.
103 %
104 % You should also know, that several test files may be created from the
105 % package source, and each of those may be used as an example for using the
106 % code. Nevertheless, \LaTeXe{} users will not need the following functions
107 % and should continue reading with \autoref{sec:doc:latex2e}.
108 %
109 % \begin{function}{\GS_set_code_digit_seq:Nn}
110 % \begin{syntax}
111 % "\GS_set_code_digit_seq:Nn" \meta{GS1 sequence variable} \Arg{token list}
112 % \end{syntax}
113 % Makes a GS1 sequence, that consist in digits only, from a \meta{token
114 % list}. To do so, only the tokens from 0 up to 9 of the \meta{token list}
115 % are set to the \meta{GS1 sequence variable}. All other tokens are
116 % ignored. So may, e.g., convert the string ``ISBN 978-3-86541-459-5'' into
117 % a GS1 sequence with the digits ``9783865414595'', where each digit is one
118 % item of the sequence.
119 % \end{function}
120 %
121 % \begin{function}{\GS_cut_EAN_control_digit:N}
122 % \begin{syntax}
123 % "\GS_cut_EAN_control_digit:N" \meta{GS1 sequence variable}
124 % \end{syntax}
125 % The \meta{GS1 sequence variable} should store either a EAN-8 or EAN-13
126 % code with or without control digit. If the code has seven or twelve
127 % digits, nothing happens. If the code has eight or 13 digits, the last one
128 % will be removed. All other cases result in an error message.
129 % \end{function}
130 %
131 % \begin{function}{\GS_set_EAN_control_digit:N}
132 % \begin{syntax}
133 % "\GS_set_EAN_control_digit:N" \meta{GS1 sequence variable}
134 % \end{syntax}
135 % The \meta{GS1 sequence variable} should store either a EAN-8 or EAN-13
136 % code with or without control digit. A new control digit will be
137 % calculated. If the code has seven or twelve digits the new control digit
138 % will be added. If the code has eight or 13 digits, the old control digit
139 % will be replaced by the new one. All other cases result in an error
140 % message.
141 % \end{function}
142 %
143 % \begin{function}{\int_set_to_EAN_control_digit:NN}
144 % \begin{syntax}
145 % "\int_set_to_EAN_control_digit:NN" \meta{integer variable} \meta{GS1 sequence variable}
146 % \end{syntax}
147 % Calculates the control digit of the \meta{GS1 sequence variable} using the
148 % EAN control digit algorithm and stores it into the \meta{integer
149 % variable}. Note, that the \meta{GS1 sequence variable} may be a sequence
150 % of digits of any length not only seven digits for EAN-8 or twelve digits
151 % for EAN-13.
152 % \end{function}
153 %
154 % \begin{function}{\GS_use_as_EAN_barcode:N}
155 % \begin{syntax}
156 % "\GS_use_as_EAN_barcode:N" \meta{GS1 sequence variable}
157 % \end{syntax}
158 % Prints an EAN-8 or EAN-13 bar code depending on
159 % \cs{l_GS_code_size_int}. Note, that the \meta{GS1 sequence variable} may
160 % have more than 8 resp. 13 items but not less! Use \cs{EANBarcode} if you
161 % need a more save function.
162 % \end{function}
163 %
164 %
165 % \section{\LaTeXe{} User Interface for GS1 Codes}
166 % \label{sec:doc:latex2e}
167 %
168 % This section describes the \LaTeXe-compatible user interface. Note, that
169 % the test files \file{EANControlDigit.tex}, \file{EANBarcode.tex},
170 % \file{GSSetup.tex}, and the resulting PDF files may be used as examples of
171 % the following commands.
172 %
173 % \begin{function}{\EANControlDigit}
174 % \begin{syntax}
175 % "\EANControlDigit"\Arg{string}
176 % \end{syntax}
177 % Only the digits of the \meta{string} will be used. All other tokens
178 % will be ignored. If the \meta{string} has 7 or 8 digits, the control
179 % digit of an EAN-8 code will be calculated and output. If the
180 % \meta{string} has 12 or 13 digits, the control digit of an EAN-13 code
181 % will be calculated and output. If the \meta{string} has 8 or 13 digits
182 % the last digit will be ignored. Any other number of digits will result in
183 % an error message.
184 % \end{function}
185 %
186 % \begin{function}{\EANBarcode}
187 % \begin{syntax}
188 % "\EANBarcode"\oarg{options}\Arg{string}
189 % \end{syntax}
190 % Creates the EAN bar code corresponding with \meta{string}. The optional
191 % argument \meta{options} may be used to use different settings from the
192 % defaults set by \cmd{\GSSetup}.
193 %
194 % Each digit of a EAN bar code is represented by seven modules. Each module
195 % is either black or white. A black module is a black, vertical line. A
196 % white module is just a gap. The seven modules start either with a black
197 % sequence of up to four modules, followed by a white sequence of up to four
198 % modules, followed by a black sequence of up to four modules, finished by a
199 % white sequence of up to four modules, or they start with a white sequence
200 % of up to four modules, followed by a black sequence of up to four modules,
201 % followed by a white sequence of up to four modules, finished by a black
202 % sequence of up to four modules.
203 % \end{function}
204 %
205 % \begin{function}{\GSSetup}
206 % \begin{syntax}
207 % "\GSSetup" \Arg{options}
208 % \end{syntax}
209 % \meta{options} is a list of \meta{key}=\meta{value} pairs. They are used
210 % to setup the default of several settings:
211 % \begin{description}
212 % \item[\texttt{ocrb=}\meta{boolean}]\hfill\\
213 % If \meta{boolean} is \texttt{true} the digits at the bottom of the bar
214 % code will be printed using OCR-b font ocrb/T1/m/n in 9pt. Predefined
215 % default is |ocrb=true|.
216 % \item[\texttt{module\_width=}\meta{dimension expression}]\hfill\\
217 % This is the width of one module. GS1 specifies a minimum module width
218 % of 0.264\,mm and a normal width of 0.33\,mm. You should not set a
219 % width below the minimum!
220 % \item[\texttt{module\_height=}\meta{dimension expression}]\hfill\\
221 % This is the height of a black module. GS1 specifies a normal bar code
222 % height of 21.31\,mm for EAN-8 and 25.01\,mm for EAN-13. Both values
223 % are inclusive the digits at the bottom of the bar code. Some marker
224 % modules are higher than the digit modules.
225 % \item[\texttt{code=}\meta{string}]\hfill\\
226 % The \meta{string} should either be \texttt{EAN-8} or \texttt{EAN-13}.
227 % The predefined default is |EAN-13|. More types will be
228 % supported in future.
229 % \item[\texttt{scale=}\meta{floating point}]\hfill\\
230 % This is the scale factor for the bar code. GS1 specifies scale classes
231 % from 0.8 up to 2.0 with steps of 0.05. Factors less than 0.8
232 % shouldn't be used. \emph{Currently \texttt{scale} won't be used!}
233 % \item[\texttt{scale\_to\_font=}\meta{boolean}]\hfill\\
234 % Ignore \texttt{module_width} and instead set the module width
235 % depending on the width of digit 0 of the current font. Note, that
236 % this will not scale the whole bar code but only the module width. To
237 % scale the whole bar code, you should use \texttt{scale}.
238 % \item[\texttt{add\_control=}\meta{boolean}]\hfill\\
239 % Add the control digit to the GS1 code. If there's already a control
240 % digit, replace it by the calculated one. The predefined default is
241 % |add_control=false|.
242 % \end{description}
243 % \end{function}
244 %
245 %
246 % \section{Internal Functions and Variables}
247 % \label{sec:doc:internal}
248 %
249 % You should not use or manipulate these! So, maybe it's better to stop
250 % reading now.
251 %
252 % \begin{function}{\__GS_set_key_code:nn}
253 % \begin{syntax}
254 % "\__GS_set_key_code:nn" \Arg{token list} \Arg{integer expression}
255 % \end{syntax}
256 % Sets \cs{l_GS_code_type_tl} to \meta{token list} and
257 % \cs{l_GS_code_size_int} to value of \Arg{integer expression}.
258 % \end{function}
259 %
260 % \begin{function}{\__GS_new_seq_c:cn}
261 % \begin{syntax}
262 % "\__GS_new_seq_c:cn" \Arg{sequence name} \Arg{token list}
263 % \end{syntax}
264 % Creates a sequence constant \cs{c__GS_\meta{sequence name}_seq}. The
265 % value of the constant will be build by the tokens of the \meta{token
266 % list}. These tokens should be either characters ``A'' or ``B'' for
267 % selection constants or digits 1--4 for module constants.
268 % \end{function}
269 %
270 % \begin{function}{\__GS_modules:Nn, \__GS_modules:cn, \__GS_modules:NnN}
271 % \begin{syntax}
272 % "\__GS_modules:Nn" \meta{sequence variable} \Arg{dimension expression}
273 % "\__GS_modules:cn" \Arg{sequence variable name} \Arg{dimension expression}
274 % "\__GS_modules:NnN" \meta{sequence variable} \Arg{dimension expression} \meta{boolean variable}
275 % \end{syntax}
276 % Draws the modules given by the \meta{sequence variable} with height
277 % \Arg{dimension expression}. The arguments are:
278 % \begin{arguments}
279 % \item \meta{sequence variable} or \meta{sequence variable name}, each item
280 % of the sequence stays for a number of modules with the same color.
281 % \cs{l__GS_black_bool} signals, whether the (first) modules are black or
282 % white and will be reversed after every item. Each module has the width
283 % \cs{l_GS_module_wd_dim}.
284 % \item \meta{dimension expression}, the height of the black modules. The
285 % modules will be raised by \cs{l_GS_module_ht_dim}.
286 % \item \meta{boolean variable}, \texttt{true} indicates, that the first
287 % module should be black. With \texttt{false}, the first module will be
288 % white.
289 % \end{arguments}
290 % \end{function}
291 %
292 % \begin{function}{\__GS_modules_start_black:Nn}
293 % \begin{syntax}
294 % "\__GS_modules_start_black:Nn" \meta{sequence variable} \Arg{dimension expression}
295 % \end{syntax}
296 % Same like \cs{__GS_modules:NnN} \meta{sequence variable} \Arg{dimension
297 % expression} \cs{c_true_bool}.
298 % \end{function}
299 %
300 % \begin{function}{\__GS_modules_start_white:Nn}
301 % \begin{syntax}
302 % "\__GS_modules_start_white:Nn" \meta{sequence variable} \Arg{dimension expression}
303 % \end{syntax}
304 % Same like \cs{__GS_modules:NnN} \meta{sequence variable} \Arg{dimension
305 % expression} \cs{c_false_bool}.
306 % \end{function}
307 %
308 % \end{documentation}
309 %
310 % \begin{implementation}
311 %
312 % \section{\pkg{GS1} implementation}
313 % \label{sec:implementation}
314 %
315 % \begin{macrocode}
316 %<@@=GS>
317 % \end{macrocode}
318 %
319 % The implementation has been done in two parts. The first part is the L3
320 % code with all the functions and variables. The second part is the
321 % \LaTeXe{} lookalike user interface.
322 %
323 % But before this, we just declare, what this is:
324 % \begin{macrocode}
325 %<*package>
326 \ProvidesExplPackage
327 {\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription}
328 % \end{macrocode}
329 % and what it requires:
330 % \begin{macrocode}
331 \RequirePackage{rule-D}
332 %</package>
333 % \end{macrocode}
334 %
335 % \subsection{Implementation of Functions and Variables}
336 % \label{sec:impl:functions.and.variables}
337 %
338 % \subsubsection{Constants}
339 % \label{sec:impl:constants}
340 %
341 % \begin{macro}{\__GS_new_seq_c:cn}
342 % While this is an internal function, that should allow only some tokens at
343 % the arguments, it is declared \texttt{nopar}.
344 % \begin{macrocode}
345 %<*package>
346 \cs_new_nopar:Npn \@@_new_seq_c:cn #1#2
347 {
348 \seq_new:c {c@@_ #1 _seq}
349 \seq_set_split:Nnn \l_tmpa_seq {} {#2}
350 \seq_gset_eq:cN {c@@_ #1 _seq} \l_tmpa_seq
351 }
352 %</package>
353 % \end{macrocode}
354 % \end{macro}
355 %
356 % \begin{variable}{\c__GS_AB0_seq, \c__GS_AB1_seq, \c__GS_AB2_seq,
357 % \c__GS_AB3_seq, \c__GS_AB4_seq, \c__GS_AB5_seq, \c__GS_AB6_seq,
358 % \c__GS_AB7_seq, \c__GS_AB8_seq, \c__GS_AB9_seq}
359 % These constants represent the generation rules of the left side of an EAN-13
360 % barcode. See figure~5.2.1.3.1-1 of the GS1 specification.
361 % \begin{macrocode}
362 %<*package>
363 \@@_new_seq_c:cn {AB0} {AAAAAA}
364 \@@_new_seq_c:cn {AB1} {AABABB}
365 \@@_new_seq_c:cn {AB2} {AABBAB}
366 \@@_new_seq_c:cn {AB3} {AABBBA}
367 \@@_new_seq_c:cn {AB4} {ABAABB}
368 \@@_new_seq_c:cn {AB5} {ABBAAB}
369 \@@_new_seq_c:cn {AB6} {ABBBAA}
370 \@@_new_seq_c:cn {AB7} {ABABAB}
371 \@@_new_seq_c:cn {AB8} {ABABBA}
372 \@@_new_seq_c:cn {AB9} {ABBABA}
373 %</package>
374 % \end{macrocode}
375 % \end{variable}
376 %
377 % \begin{variable}{\c__GS_A0_seq, \c__GS_A1_seq, \c__GS_A2_seq, \c__GS_A3_seq,
378 % \c__GS_A4_seq, \c__GS_A5_seq, \c__GS_A6_seq, \c__GS_A7_seq, \c__GS_A8_seq,
379 % \c__GS_A9_seq, \c__GS_B0_seq, \c__GS_B1_seq, \c__GS_B2_seq, \c__GS_B3_seq,
380 % \c__GS_B4_seq, \c__GS_B5_seq, \c__GS_B6_seq, \c__GS_B7_seq, \c__GS_B8_seq,
381 % \c__GS_B9_seq, \c__GS_margin_seq, \c__GS_separator_seq, \c__GS_special_seq,
382 % \c__GS_extra_margin_seq, \c__GS_extra_separator_seq}
383 % These constants represent the module sequences of digits and markers. See
384 % figure~5.2.1.2.1-1 and 5.2.1.2.2-1 of the GS1 specification. Note, that
385 % the module sequences of type C are same like type A but start with a black
386 % module instead of a white one.
387 % \begin{macrocode}
388 %<*package>
389 \@@_new_seq_c:cn {A0} {3211} % start white (C0 same but start with black)
390 \@@_new_seq_c:cn {A1} {2221}
391 \@@_new_seq_c:cn {A2} {2122}
392 \@@_new_seq_c:cn {A3} {1411}
393 \@@_new_seq_c:cn {A4} {1132}
394 \@@_new_seq_c:cn {A5} {1231}
395 \@@_new_seq_c:cn {A6} {1114}
396 \@@_new_seq_c:cn {A7} {1312}
397 \@@_new_seq_c:cn {A8} {1213}
398 \@@_new_seq_c:cn {A9} {3112}
399 \@@_new_seq_c:cn {B0} {1123} % start white
400 \@@_new_seq_c:cn {B1} {1222}
401 \@@_new_seq_c:cn {B2} {2212}
402 \@@_new_seq_c:cn {B3} {1141}
403 \@@_new_seq_c:cn {B4} {2311}
404 \@@_new_seq_c:cn {B5} {1321}
405 \@@_new_seq_c:cn {B6} {4111}
406 \@@_new_seq_c:cn {B7} {2131}
407 \@@_new_seq_c:cn {B8} {3121}
408 \@@_new_seq_c:cn {B9} {2113}
409 \@@_new_seq_c:cn {margin} {111} % start black
410 \@@_new_seq_c:cn {separator} {11111} % start white
411 \@@_new_seq_c:cn {special} {111111} % start white
412 \@@_new_seq_c:cn {extra_margin} {112} % start black
413 \@@_new_seq_c:cn {extra_separator} {11} % start white
414 %</package>
415 % \end{macrocode}
416 % \end{variable}
417 %
418 % There are some basic dimensions for the modules at the specification:
419 % \begin{variable}{\c__GS_module_min_width_dim, \c__GS_module_norm_width_dim}
420 % \begin{macrocode}
421 %<*package>
422 \dim_const:Nn \c_@@_module_min_width_dim {0.264mm}
423 \dim_const:Nn \c_@@_module_norm_width_dim {0.33mm}
424 %</package>
425 % \end{macrocode}
426 % \end{variable}
427 %
428 % \subsubsection{Settings and Variables}
429 % \label{seq:impl.settings}
430 %
431 % These settings will influence the work of several of the user functions.
432 % They are defined as keys of family \texttt{GS1}.
433 %
434 % \begin{variable}{ \l_GS_use_ocrb_bool, \l_GS_module_wd_dim,
435 % \l_GS_module_ht_dim, \l_GS_scale_fp, \l_GS_scale_to_font_bool,
436 % \l_GS_add_control_bool, \l_GS_code_type_tl, \l_GS_code_size_int }
437 % \begin{macro}{\__GS_set_key_code:nn}
438 % Needed to set both \cmd{\l_GS_code_type_tl} and \cmd{\l_GS_code_size_int}
439 % with one key. Together they are the type of code, to be handled.
440 % \begin{macrocode}
441 %<*package>
442 \cs_new_nopar:Npn \@@_set_key_code:nn #1#2
443 {
444 \tl_if_exist:NF \l_GS_code_type_tl { \tl_new:N \l_GS_code_type_tl }
445 \tl_set:Nn \l_GS_code_type_tl { #1 }
446 \int_if_exist:NF \l_GS_code_size_int { \int_new:N \l_GS_code_size_int }
447 \int_set:Nn \l_GS_code_size_int { #2 }
448 }
449 % \end{macrocode}
450 % \end{macro}
451 % \begin{macrocode}
452 \keys_define:nn { GS1 }
453 {
454 ocrb .bool_set:N = \l_GS_use_ocrb_bool,
455 ocrb .initial:n = true,
456 module_width .dim_set:N = \l_GS_module_wd_dim,
457 module_width .initial:V = \c_@@_module_norm_width_dim,
458 module_height .dim_set:N = \l_GS_module_ht_dim,
459 module_height .initial:V = \c_zero_dim,
460 code .choice:,
461 code / EAN-8 .code:n = { \@@_set_key_code:nn { EAN } { 8 } },
462 code / EAN8 .code:n = { \@@_set_key_code:nn { EAN } { 8 } },
463 code / EAN-13 .code:n = { \@@_set_key_code:nn { EAN } { 13 } },
464 code / EAN13 .code:n = { \@@_set_key_code:nn { EAN } { 13 } },
465 code .initial:n = EAN-13,
466 scale .fp_set:N = \l_GS_scale_fp,
467 scale .initial:n = 1.0,
468 scale_to_font .bool_set:N = \l_GS_scale_to_font_bool,
469 scale_to_font .initial:n = false,
470 add_control .bool_set:N = \l_GS_add_control_bool,
471 add_control .initial:n = false,
472 }
473 %</package>
474 % \end{macrocode}
475 % \end{variable}
476 %
477 % Note: Later I'll define a \LaTeXe{} command to change the defaults of those
478 % keys. Additionally local changes of those keys may be done using the
479 % optional argument of the \LaTeXe{} user commands. See
480 % \autoref{sec:impl:user.interface} for more information.
481 %
482 % \begin{variable}{\l__GS_code_seq}
483 % This will be used later for several local GS1 sequences. It is private
484 % and also shouldn't be used in global context.
485 % \begin{macrocode}
486 %<*package>
487 \seq_new:N \l_@@_code_seq
488 %</package>
489 % \end{macrocode}
490 % \end{variable}
491 %
492 % \subsubsection{Messages}
493 % \label{seq:impl.messages}
494 %
495 % We need a message for not supported lengths of EAN codes, because currently
496 % only EAN-8 and EAN-13 are supported, both with or without control
497 % digit. This message will be used as an error message.
498 % \begin{macrocode}
499 %<*package>
500 \msg_new:nnnn { GS1 } { EAN-code-size }
501 {
502 #1~isn't~a~valid~EAN~code~\msg_line_context:.
503 }
504 {
505 The~given~code~is~neither~a~EAN-8~with~or~without~control~digit,\\
506 nor~a~EAN-13~with~or~without~control~digit.\\\\
507 The~GS1~module~currently~only~supports~EAN-8~and~EAN~13.
508 }
509 %</package>
510 % \end{macrocode}
511 %
512 % Another message is only a warning message. It will be used whenever the used
513 % module width would be less than the minimum module width given by the GS1
514 % specification.
515 % \begin{macrocode}
516 %<*package>
517 \msg_new:nnn { GS1 } { module/minwidth }
518 {
519 Resulting~module~width~is~less~than~allowed~minimum~\msg_line_context:.\\\\
520 GS1~specification~declares~a~minimum~module~width~of~#2.\\
521 Currently~the~module~with~would~be~#1.\\
522 To~avoid~problems,~I'll~increase~module~width~to~#2.
523 }
524 %</package>
525 % \end{macrocode}
526 %
527 % \subsubsection{Functions}
528 % \label{seq:impl.functions}
529 %
530 % \begin{macro}{\GS_set_code_digit_seq:Nn}
531 % Convert a string into a code sequence ignoring all but digits.
532 % \begin{macrocode}
533 %<*package>
534 \cs_new_nopar:Npn \GS_set_code_digit_seq:Nn #1#2
535 {
536 \seq_set_eq:NN #1 \c_empty_seq
537 \tl_map_inline:nn
538 { #2 }
539 {
540 \tl_if_in:nnT
541 {0123456789}
542 {##1}
543 {
544 \seq_put_right:Nn #1 { ##1 }
545 }
546 }
547 }
548 %</package>
549 % \end{macrocode}
550 %
551 % \TestFiles{GS_set_code_digit.tex}\UnitTested
552 % \begin{macrocode}
553 %<*test&GS.set.code.digit.seq>
554 \ExplSyntaxOn
555 \seq_new:N \l_testa_seq
556 \seq_new:N \l_testb_seq
557
558 \GS_set_code_digit_seq:Nn \l_testa_seq {ISBN 978-3-86541-459-5}
559 Sequence~for~ISBN~978-3-86541-459-5~is:~
560 \seq_use:Nnnn \l_testa_seq { ,~ } { ,~} { ,~ }
561
562 \GS_set_code_digit_seq:Nn \l_testb_seq {9783865414595}
563 \seq_map_inline:Nn \l_testa_seq
564 {
565 \seq_pop_left:NN \l_testb_seq \l_tmpa_tl
566 \tl_set:Nn \l_tmpb_tl { #1 }
567 \tl_if_eq:NNF \l_tmpa_tl \l_tmpb_tl
568 {
569 \tl_show:N l_testa_seq
570 \tl_show:N l_testb_seq
571 \msg_fatal:nnn { GS1/test } { function } { \GS_set_code_digit_seq:Nn }
572 }
573 }
574
575 \GS_set_code_digit_seq:Nn \l_testa_seq {ISBN 978-3-86541-459-5}
576 \seq_set_split:Nnn \l_testb_seq {,} {9,7,8,3,8,6,5,4,1,4,5,9,5}
577 \seq_map_inline:Nn \l_testa_seq
578 {
579 \seq_pop_left:NN \l_testb_seq \l_tmpa_tl
580 \tl_set:Nn \l_tmpb_tl { #1 }
581 \tl_if_eq:NNF \l_tmpa_tl \l_tmpb_tl
582 {
583 \tl_show:N \l_testa_seq
584 \tl_show:N \l_testb_seq
585 \msg_fatal:nnn { GS1/test } { function } { \GS_set_code_digit_seq:Nn }
586 }
587 }
588
589 \ExplSyntaxOff
590 %</test&GS.set.code.digit.seq>
591 % \end{macrocode}
592 % \end{macro}
593 %
594 % \begin{macro}[updated = 2017-07-15]{\GS_cut_EAN_control_digit:N}
595 % \changes{v18}{2017/07/15}{replaced removed \cs{int_case:nnn} by
596 % \cs{int_case:nnF}}^^A
597 % EAN code sequences with control digit are either 8 or 13 digits. To
598 % remove the control digit we just have to remove the right most digit from
599 % a 8 or 13 digits sequence. 7 or 12 digit sequences are already without
600 % control digit. All other sequences are not supported.
601 % \begin{macrocode}
602 %<*package>
603 \cs_new_nopar:Npn \GS_cut_EAN_control_digit:N #1
604 {
605 \int_case:nnF
606 { \seq_count:N #1 }
607 {
608 { 7 } { }
609 { 8 } { \seq_pop_right:NN #1 \l_tempa_tl }
610 { 12 } { }
611 { 13 } { \seq_pop_right:NN #1 \l_tempa_tl }
612 }
613 {
614 \msg_error:nnn { GS1 } { EAN-code-size } { #1 }
615 }
616 }
617 %</package>
618 % \end{macrocode}
619 %
620 % \TestFiles{GS_cut_EAN_control_digit.tex}\UnitTested
621 % \begin{macrocode}
622 %<*test&GS.cut.EAN.control.digit>
623 \raggedright
624 \ExplSyntaxOn
625 \seq_new:N \l_testa_seq
626 \GS_set_code_digit_seq:Nn \l_testa_seq {ISBN 978-3-86541-459-5}
627 With~control:~\seq_use:Nnnn \l_testa_seq { ,~ } { ,~} { ,~ }\\
628 \GS_set_code_digit_seq:Nn \l_testb_seq {ISBN 978-3-86541-459}
629 \GS_cut_EAN_control_digit:N \l_testa_seq
630 \seq_map_inline:Nn \l_testa_seq
631 {
632 \seq_pop_left:NN \l_testb_seq \l_tmpa_tl
633 \tl_set:Nn \l_tmpb_tl { #1 }
634 \tl_if_eq:NNF \l_tmpa_tl \l_tmpb_tl
635 {
636 \tl_show:N \l_testa_seq
637 \tl_show:N \l_testb_seq
638 \msg_fatal:nnn { GS1/test } { function }
639 { \GS_cut_EAN_control_digit:N }
640 }
641 }
642 Without~control:~\seq_use:Nnnn \l_testa_seq { ,~ } { ,~} { ,~ }\\
643 \ExplSyntaxOff
644 %</test&GS.cut.EAN.control.digit>
645 % \end{macrocode}
646 % \end{macro}
647 %
648 % \begin{macro}{\int_set_to_EAN_control_digit:NN}
649 % Sets an integer to the control digit calculated with the EAN control digit
650 % algorithm for a given code sequence. Note, that the complete code
651 % sequence will be used to calculate the control digit. So, if you have a
652 % EAN-8 or EAN-13 code sequence, you should cut of the control digit first.
653 % \begin{macrocode}
654 %<*package>
655 \cs_new_nopar:Npn \int_set_to_EAN_control_digit:NN #1#2
656 {
657 \int_zero:N #1
658 \seq_set_eq:NN \l_tmpa_seq #2
659 \bool_until_do:nn
660 { \seq_if_empty_p:N \l_tmpa_seq }
661 {
662 \seq_pop_left:NN \l_tmpa_seq \l_tmpb_tl
663 \int_if_even:nTF
664 { \seq_count:N \l_tmpa_seq }
665 {
666 \int_add:Nn #1 { 3 * \l_tmpb_tl }
667 }
668 {
669 \int_add:Nn #1 { \l_tmpb_tl }
670 }
671 }
672 \int_set:Nn #1 { \int_mod:nn { 10 - \int_mod:nn { #1 } { 10 } } { 10 } }
673 }
674 %</package>
675 % \end{macrocode}
676 %
677 % \TestFiles{int_set_to_EAN_control_digit.tex}\UnitTested
678 % \begin{macrocode}
679 %<*test&int.set.to.EAN.control.digit>
680 \ExplSyntaxOn
681 \seq_new:N \l_testa_seq
682 \tl_new:N \l_control_tl
683 \GS_set_code_digit_seq:Nn \l_testa_seq {ISBN 978-3-86541-459-5}
684 \seq_pop_right:NN \l_testa_seq \l_control_tl
685 \int_new:N \l_control_int
686 \int_set_to_EAN_control_digit:NN \l_control_int \l_testa_seq
687 Control~digit~should~be~\tl_use:N \l_control_tl{} ~
688 \int_compare:nNnTF { \l_control_tl } { = } { \l_control_int }
689 {
690 ~and~is~\int_use:N \l_control_int .
691 }
692 {
693 ~but~it~\int_use:N \l_control_int .
694 \msg_error:nnn { GS1/test } { function }
695 { \int_set_to_EAN_control_digit:NN }
696 }
697 \ExplSyntaxOff
698 %</test&int.set.to.EAN.control.digit>
699 % \end{macrocode}
700 % \end{macro}
701 %
702 % \begin{macro}{\GS_set_EAN_control_digit:N}
703 % Add a new control digit to a EAN sequence
704 % \begin{macrocode}
705 %<*package>
706 \cs_new_nopar:Npn \GS_set_EAN_control_digit:N #1
707 {
708 \GS_cut_EAN_control_digit:N #1
709 \int_set_to_EAN_control_digit:NN \l_tmpa_int #1
710 \seq_put_right:NV #1 \l_tmpa_int
711 }
712 %</package>
713 % \end{macrocode}
714 %
715 % \TestFiles{GS_set_EAN_control_digit.tex}\UnitTested
716 % \begin{macrocode}
717 %<*test&GS.set.EAN.control.digit>
718 \ExplSyntaxOn
719 \seq_new:N \l_testa_seq
720 \GS_set_code_digit_seq:Nn \l_testa_seq {ISBN 978-3-86541-459-5}
721 \seq_new:N \l_testb_tl
722 \seq_pop_right:NN \l_testa_seq \l_testb_tl
723 \GS_set_EAN_control_digit:N \l_testa_seq
724 \tl_new:N \l_testa_tl
725 \seq_get_right:NN \l_testa_seq \l_testa_tl
726 Control~digit~should~be~ \tl_use:N \l_testb_tl {} ~
727 \int_compare:nNnTF { \l_testa_tl } { = } { \l_testb_tl }
728 {
729 ~and~is~\tl_use:N \l_testa_tl .
730 }
731 {
732 ~but~it~\tl_use:N \t_testa_tl .
733 \msg_error:nnn { GS1/test } { function } { \GS_set_EAN_control_digit:N }
734 }
735 \ExplSyntaxOff
736 %</test&GS.set.EAN.control.digit>
737 % \end{macrocode}
738 % \end{macro}
739 %
740 % \begin{macro}{\__GS_modules:Nn, \__GS_modules:NnN, \__GS_modules:cn,
741 % \__GS_modules_start_black:Nn, \__GS_modules_start_white:Nn}
742 % \begin{macrocode}
743 %<*package>
744 \cs_new_nopar:Npn \@@_modules:Nn #1#2
745 {
746 \seq_map_inline:Nn #1
747 {
748 \bool_if:NTF \l_@@_black_bool
749 {
750 \bool_set_false:N \l_@@_black_bool
751 \hbox_set:Nn \l_tmpa_box { 0 }
752 \rule:nnn
753 {
754 \dim_eval:n
755 {
756 \box_ht:N \l_tmpa_box + \l_GS_module_wd_dim / 2
757 - \dim_eval:n { #2 } + \l_GS_module_ht_dim
758 }
759 }
760 { \dim_eval:n { \l_GS_module_wd_dim * ##1 } }
761 { \dim_eval:n { #2 } }
762 }
763 {
764 \bool_set_true:N \l_@@_black_bool
765 \hbox_to_wd:nn { \l_GS_module_wd_dim * ##1 } { }
766 }
767 }
768 }
769
770 \cs_new_nopar:Npn \@@_modules:NnN #1#2#3
771 {
772 \bool_if_exist:NF \l_@@_black_bool { \bool_new:N \l_@@_black_bool }
773 \bool_set_eq:NN \l_@@_black_bool #3
774 \@@_modules:Nn #1 { #2 }
775 }
776
777 \cs_new_nopar:Npn \@@_modules_start_black:Nn #1#2
778 {
779 \@@_modules:NnN #1 { #2 } \c_true_bool
780 }
781
782 \cs_new_nopar:Npn \@@_modules_start_white:Nn #1#2
783 {
784 \@@_modules:NnN #1 { #2 } \c_false_bool
785 }
786
787 \cs_generate_variant:Nn \@@_modules:Nn { c }
788 %</package>
789 % \end{macrocode}
790 % \TestFiles{EANBarcode.tex}\UnitTested
791 % \end{macro}
792 %
793 % \begin{macro}{\GS_use_as_EAN_barcode:N}
794 % Puts the digits, rules, and gaps for an EAN barcode into the input
795 % stream.
796 % \begin{macrocode}
797 %<*package>
798 \cs_new_nopar:Npn \GS_use_as_EAN_barcode:N #1
799 {
800 \seq_set_eq:NN \l_@@_code_seq #1
801
802 \int_compare:nNnTF { \l_GS_code_size_int } { = } { 8 }
803 {
804 \hbox_to_wd:nn { \l_GS_module_wd_dim * 7 } { }
805 \seq_set_eq:Nc \l_GS_system_seq { c_@@_AB0_seq }
806 }
807 {
808 \hbox_to_wd:nn { \l_GS_module_wd_dim * 11 } { }
809 \seq_pop_left:NN \l_@@_code_seq \l_tmpa_tl
810 \seq_set_eq:Nc \l_GS_system_seq { c_@@_AB \l_tmpa_tl _seq }
811 \hbox_overlap_left:n { \l_tmpa_tl }
812 }
813
814 \@@_modules_start_black:Nn \c_@@_margin_seq
815 { \l_GS_module_ht_dim + \l_GS_module_wd_dim * 5 }
816
817 \int_step_inline:nnnn { 1 } { 1 }
818 { \int_div_truncate:nn { \l_GS_code_size_int } { 2 } }
819 {
820 \seq_pop_left:NN \l_@@_code_seq \l_tmpa_tl
821 \hbox_overlap_right:n { \l_tmpa_tl }
822 \seq_pop_left:NN \l_GS_system_seq \l_tmpb_tl
823 \@@_modules:cn { c_@@_ \l_tmpb_tl \l_tmpa_tl _seq }
824 { \l_GS_module_ht_dim }
825 }
826
827 \@@_modules_start_white:Nn \c_@@_separator_seq
828 { \l_GS_module_ht_dim + \l_GS_module_wd_dim * 5 }
829
830 \int_step_inline:nnnn { 1 } { 1 }
831 { \int_div_truncate:nn { \l_GS_code_size_int } { 2 } }
832 {
833 \seq_pop_left:NN \l_@@_code_seq \l_tmpa_tl
834 \hbox_overlap_right:n { \l_tmpa_tl }
835 \@@_modules:cn { c_@@_A \l_tmpa_tl _seq }
836 { \l_GS_module_ht_dim }
837 }
838
839 \@@_modules_start_black:Nn \c__GS_margin_seq
840 { \l_GS_module_ht_dim + \l_GS_module_wd_dim * 5 }
841
842 \hbox_to_wd:nn { \l_GS_module_wd_dim * 7 } { }
843 }
844 %</package>
845 % \end{macrocode}
846 % \TestFiles{EANBarcode.tex}\UnitTested
847 % \end{macro}
848 %
849 %
850 % \subsection{Implementation of the User Interface}
851 % \label{sec:impl:user.interface}
852 %
853 % For this, additional packages are needed:
854 % \begin{macrocode}
855 %<*package>
856 \RequirePackage{xparse}
857 % \end{macrocode}
858 %
859 % \begin{macro}{\EANControlDigit}
860 % \begin{macrocode}
861 \NewDocumentCommand \EANControlDigit
862 { m }
863 {
864 \group_begin:
865 \GS_set_code_digit_seq:Nn \l_@@_code_seq { #1 }
866 \GS_cut_EAN_control_digit:N \l_@@_code_seq
867 \int_set_to_EAN_control_digit:NN \l_tmpa_int \l_@@_code_seq
868 \int_to_arabic:n { \l_tmpa_int }
869 \group_end:
870 }
871 %</package>
872 % \end{macrocode}
873 % \TestFiles{EANControlDigit.tex}\UnitTested
874 %
875 % \begin{macrocode}
876 %<*test&EANControlDigit>
877 \begin{tabular}{ll}
878 \hline
879 Calculated & Known \\
880 \hline
881 501234567890-\EANControlDigit{501234567890} & 501234567890-0 \\
882 ISBN 978-3-86541-459-\EANControlDigit{ISBN 978-3-86541-459} & ISBN
883 978-3-86541-459-5 \\
884 EAN-8: 2012345\EANControlDigit{2012345} & EAN-8: 20123451 \\
885 \hline
886 \end{tabular}
887 %</test&EANControlDigit>
888 % \end{macrocode}
889 % \end{macro}
890 %
891 % \begin{macro}{\EANBarcode}
892 % \begin{macrocode}
893 %<*package>
894 \NewDocumentCommand \EANBarcode
895 { o m }
896 {
897 \group_begin:
898 \IfNoValueF{#1}{ \keys_set:nn { GS1 } { #1 } }
899 \dim_compare:nNnT { \l_GS_module_ht_dim } { = } { \c_zero_dim }
900 {
901 \int_compare:nNnTF { \l_GS_code_size_int } { = } { 8 }
902 { \dim_set:Nn \l_GS_module_ht_dim { 21.31 mm } }
903 { \dim_set:Nn \l_GS_module_ht_dim { 25.01 mm } }
904 }
905 \bool_if:nT \l_GS_use_ocrb_bool
906 {
907 % \end{macrocode}
908 % \textsc{ToDo:} Use \pkg{fontspec} if available.
909 % \begin{macrocode}
910 \usefont{OT1}{ocrb}{m}{n}\fontsize{9}{9}\selectfont
911 }
912
913 \GS_set_code_digit_seq:Nn \l_@@_code_seq { #2 }
914
915 \bool_if:NT \l_GS_add_control_bool
916 {
917 \GS_set_EAN_control_digit:N \l_@@_code_seq
918 }
919
920 \int_compare:nNnT
921 { \seq_count:N \l__GS_code_seq }
922 { > }
923 { \l_GS_code_size_int }
924 {
925 \msg_error:nnn { GS1 } { EAN-code-size } { #2 }
926 }
927 \int_while_do:nNnn
928 { \seq_count:N \l_@@_code_seq }
929 { < }
930 { \l_GS_code_size_int }
931 {
932 \seq_put_left:Nn \l_@@_code_seq { 0 }
933 }
934
935 \bool_if:NT \l_GS_scale_to_font_bool {
936 \hbox_set:Nn \l_tmpa_box { 0 }
937 \dim_set:Nn \l_GS_module_wd_dim { \box_wd:N \l_tmpa_box / 7 }
938 }
939
940 \dim_set:Nn \l_tmpa_dim
941 { \fp_to_decimal:N \l_GS_scale_fp \l_GS_module_wd_dim }
942
943 \dim_compare:nNnT
944 { \l_tmpa_dim }
945 { < }
946 { \c_@@_module_min_width_dim }
947 {
948 \msg_warning:nnxx { GS1 } { module/minwidth }
949 { \dim_use:N \l_GS_module_wd_dim }
950 { \dim_use:N \c_@@_module_min_width_dim }
951 \dim_set:Nn \l_GS_module_wd_dim
952 {
953 \c_@@_module_min_width_dim *
954 100 / \fp_to_int:n { 100 * \l_GS_scale_fp }
955 }
956 }
957
958 \hbox_set:Nn \l_tmpa_box { \GS_use_as_EAN_barcode:N \l_@@_code_seq }
959 \box_scale:Nnn \l_tmpa_box
960 { \fp_to_int:n { 100 * \l_GS_scale_fp } / 100 }
961 { \fp_to_int:n { 100 * \l_GS_scale_fp } / 100 }
962 \box_use:N \l_tmpa_box
963 \group_end:
964 }
965 %</package>
966 % \end{macrocode}
967 % \TestFiles{EANBarcode.tex}\UnitTested
968 %
969 % \begin{macrocode}
970 %<*test&EANBarcode|GSSetup>
971 \raggedright
972 \verb|\EANBarcode{ISBN 978-3-86541-459-5}|:
973 \EANBarcode{ISBN 978-3-86541-459-5}
974
975 \verb|\EANBarcode[add_control]{ISBN 978-3-86541-459-}|:
976 \EANBarcode[add_control]{ISBN 978-3-86541-459-}
977
978 \verb|\EANBarcode[ocrb=false]{ISBN 978-3-86541-459-5}|:
979 \EANBarcode[ocrb=false]{ISBN 978-3-86541-459-5}
980
981 \verb|\EANBarcode[code=EAN-8]{20123451}|:
982 \EANBarcode[code=EAN-8]{20123451}
983
984 \verb|\EANBarcode[code=EAN-8,ocrb=false,add_control]{2012345}|:
985 \EANBarcode[code=EAN-8,ocrb=false,add_control]{2012345}
986
987 %</test&EANBarcode|GSSetup>
988 % \end{macrocode}
989 % \end{macro}
990 %
991 % \begin{macro}{\GSSetup}
992 % \begin{macrocode}
993 %<*package>
994 \NewDocumentCommand \GSSetup
995 { m }
996 { \keys_set:nn { GS1 } { #1 } }
997 %</package>
998 % \end{macrocode}
999 %
1000 % \TestFiles{GSSetup.tex}\UnitTested
1001 % \begin{macrocode}
1002 %<*test&GSSetup>
1003 After \verb|\GSSetup{ocrb=false,add_control}|:
1004 \GSSetup{ocrb=false,add_control}
1005
1006 \verb|\EANBarcode[code=EAN-8]{2012345}|:
1007 \EANBarcode[code=EAN-8]{2012345}
1008
1009 \verb|\EANBarcode[code=EAN-8,ocrb,add_control=false]{20123451}|:
1010 \EANBarcode[code=EAN-8,ocrb,add_control=false]{20123451}
1011
1012 %</test&GSSetup>
1013 % \end{macrocode}
1014 % \end{macro}
1015 %
1016 % \iffalse
1017 %<*test>
1018 \end{document}
1019 %</test>
1020 % \fi
1021 % \end{implementation}
1022 %
1023 % \PrintIndex
1024 %
1025 \endinput
1026 %
1027 % end of file
1028
1029 % \endinput
1030 % Local Variables:
1031 % mode: doctex
1032 % TeX-master: t
1033 % End: