1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
|
%%
%% This is file `GS1.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% GS1.dtx (with options: `package')
%%
%% EXPERIMENTAL CODE
%%
%% This Work depends on the correct version of expl3 release. If
%% you'll update expl3 you may need a update of this this Work too.
%%
%% Do not distribute this file without also distributing the
%% source files specified above.
%%
%% Do not distribute modified version of this file.
%%
%% File: GS1.dtx Copyright (C) 2012 Markus Kohm
%%
%% It may be distributed and/or modified under the conditions of the
%% LaTeX Project Public License (LPPL), either version 1.3c of this
%% license or (at your option) any later version. The latest version
%% of this license is in the file
%%
%% http://www.latex-project.org/lppl.txt
%%
%% This file is part of the "GS1 bundle" (The Work in LPPL)
%% and all files in that bundle must be distributed together.
%%
%% The released version of this bundle is available from CTAN.
%%
%% -------------------------------------------------------------------------
\RequirePackage{l3names}
\GetIdInfo$Id: GS1.dtx 9 2012-08-01 09:31:32Z mjk $
{GS1 code handler and barcode generator}
\ProvidesExplPackage
{\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription}
\RequirePackage{expl3}[2012/07/16]
\RequirePackage{rule-D}
\cs_new_nopar:Npn \__GS_new_seq_c:cn #1#2
{
\seq_new:c {c__GS_ #1 _seq}
\seq_set_split:Nnn \l_tmpa_seq {} {#2}
\seq_gset_eq:cN {c__GS_ #1 _seq} \l_tmpa_seq
}
\__GS_new_seq_c:cn {AB0} {AAAAAA}
\__GS_new_seq_c:cn {AB1} {AABABB}
\__GS_new_seq_c:cn {AB2} {AABBAB}
\__GS_new_seq_c:cn {AB3} {AABBBA}
\__GS_new_seq_c:cn {AB4} {ABAABB}
\__GS_new_seq_c:cn {AB5} {ABBAAB}
\__GS_new_seq_c:cn {AB6} {ABBBAA}
\__GS_new_seq_c:cn {AB7} {ABABAB}
\__GS_new_seq_c:cn {AB8} {ABABBA}
\__GS_new_seq_c:cn {AB9} {ABBABA}
\__GS_new_seq_c:cn {A0} {3211} % start white (C0 same but start with black)
\__GS_new_seq_c:cn {A1} {2221}
\__GS_new_seq_c:cn {A2} {2122}
\__GS_new_seq_c:cn {A3} {1411}
\__GS_new_seq_c:cn {A4} {1132}
\__GS_new_seq_c:cn {A5} {1231}
\__GS_new_seq_c:cn {A6} {1114}
\__GS_new_seq_c:cn {A7} {1312}
\__GS_new_seq_c:cn {A8} {1213}
\__GS_new_seq_c:cn {A9} {3112}
\__GS_new_seq_c:cn {B0} {1123} % start white
\__GS_new_seq_c:cn {B1} {1222}
\__GS_new_seq_c:cn {B2} {2212}
\__GS_new_seq_c:cn {B3} {1141}
\__GS_new_seq_c:cn {B4} {2311}
\__GS_new_seq_c:cn {B5} {1321}
\__GS_new_seq_c:cn {B6} {4111}
\__GS_new_seq_c:cn {B7} {2131}
\__GS_new_seq_c:cn {B8} {3121}
\__GS_new_seq_c:cn {B9} {2113}
\__GS_new_seq_c:cn {margin} {111} % start black
\__GS_new_seq_c:cn {separator} {11111} % start white
\__GS_new_seq_c:cn {special} {111111} % start white
\__GS_new_seq_c:cn {extra_margin} {112} % start black
\__GS_new_seq_c:cn {extra_separator} {11} % start white
\dim_const:Nn \c__GS_module_min_width_dim {0.264mm}
\dim_const:Nn \c__GS_module_norm_width_dim {0.33mm}
\cs_new_nopar:Npn \__GS_set_key_code:nn #1#2
{
\tl_if_exist:NF \l_GS_code_type_tl { \tl_new:N \l_GS_code_type_tl }
\tl_set:Nn \l_GS_code_type_tl { #1 }
\int_if_exist:NF \l_GS_code_size_int { \int_new:N \l_GS_code_size_int }
\int_set:Nn \l_GS_code_size_int { #2 }
}
\keys_define:nn { GS1 }
{
ocrb .bool_set:N = \l_GS_use_ocrb_bool,
ocrb .initial:n = true,
module_width .dim_set:N = \l_GS_module_wd_dim,
module_width .initial:V = \c__GS_module_norm_width_dim,
module_height .dim_set:N = \l_GS_module_ht_dim,
module_height .initial:V = \c_zero_dim,
code .choice:,
code / EAN-8 .code:n = { \__GS_set_key_code:nn { EAN } { 8 } },
code / EAN8 .code:n = { \__GS_set_key_code:nn { EAN } { 8 } },
code / EAN-13 .code:n = { \__GS_set_key_code:nn { EAN } { 13 } },
code / EAN13 .code:n = { \__GS_set_key_code:nn { EAN } { 13 } },
code .initial:n = EAN-13,
scale .fp_set:N = \l_GS_scale_fp,
scale .initial:n = 1.0,
scale_to_font .bool_set:N = \l_GS_scale_to_font_bool,
scale_to_font .initial:n = false,
add_control .bool_set:N = \l_GS_add_control_bool,
add_control .initial:n = false,
}
\seq_new:N \l__GS_code_seq
\msg_new:nnnn { GS1 } { EAN-code-size }
{
#1~isn't~a~valid~EAN~code~\msg_line_context:.
}
{
The~given~code~is~neither~a~EAN-8~with~or~without~control~digit,\\
nor~a~EAN-13~with~or~without~control~digit.\\\\
The~GS1~module~currently~only~supports~EAN-8~and~EAN~13.
}
\cs_new_nopar:Npn \GS_set_code_digit_seq:Nn #1#2
{
\seq_set_eq:NN #1 \c_empty_seq
\tl_map_inline:nn
{ #2 }
{
\tl_if_in:nnT
{0123456789}
{##1}
{
\seq_put_right:Nn #1 { ##1 }
}
}
}
\cs_new_nopar:Npn \GS_cut_EAN_control_digit:N #1
{
\int_case:nnn
{ \seq_count:N #1 }
{
{ 7 } { }
{ 8 } { \seq_pop_right:NN #1 \l_tempa_tl }
{ 12 } { }
{ 13 } { \seq_pop_right:NN #1 \l_tempa_tl }
}
{
\msg_error:nnn { GS1 } { EAN-code-size } { #1 }
}
}
\cs_new_nopar:Npn \int_set_to_EAN_control_digit:NN #1#2
{
\int_zero:N #1
\seq_set_eq:NN \l_tmpa_seq #2
\bool_until_do:nn
{ \seq_if_empty_p:N \l_tmpa_seq }
{
\seq_pop_left:NN \l_tmpa_seq \l_tmpb_tl
\int_if_even:nTF
{ \seq_count:N \l_tmpa_seq }
{
\int_add:Nn #1 { 3 * \l_tmpb_tl }
}
{
\int_add:Nn #1 { \l_tmpb_tl }
}
}
\int_set:Nn #1 { \int_mod:nn { 10 - \int_mod:nn { #1 } { 10 } } { 10 } }
}
\cs_new_nopar:Npn \GS_set_EAN_control_digit:N #1
{
\GS_cut_EAN_control_digit:N #1
\int_set_to_EAN_control_digit:NN \l_tmpa_int #1
\seq_put_right:NV #1 \l_tmpa_int
}
\cs_new_nopar:Npn \__GS_modules:Nn #1#2
{
\seq_map_inline:Nn #1
{
\bool_if:NTF \l__GS_black_bool
{
\bool_set_false:N \l__GS_black_bool
\hbox_set:Nn \l_tmpa_box { 0 }
\rule:nnn
{
\dim_eval:n
{
\box_ht:N \l_tmpa_box + \l_GS_module_wd_dim / 2
- \dim_eval:n { #2 } + \l_GS_module_ht_dim
}
}
{ \dim_eval:n { \l_GS_module_wd_dim * ##1 } }
{ \dim_eval:n { #2 } }
}
{
\bool_set_true:N \l__GS_black_bool
\hbox_to_wd:nn { \l_GS_module_wd_dim * ##1 } { }
}
}
}
\cs_new_nopar:Npn \__GS_modules:NnN #1#2#3
{
\bool_if_exist:NF \l__GS_black_bool { \bool_new:N \l__GS_black_bool }
\bool_set_eq:NN \l__GS_black_bool #3
\__GS_modules:Nn #1 { #2 }
}
\cs_new_nopar:Npn \__GS_modules_start_black:Nn #1#2
{
\__GS_modules:NnN #1 { #2 } \c_true_bool
}
\cs_new_nopar:Npn \__GS_modules_start_white:Nn #1#2
{
\__GS_modules:NnN #1 { #2 } \c_false_bool
}
\cs_generate_variant:Nn \__GS_modules:Nn { c }
\cs_new_nopar:Npn \GS_use_as_EAN_barcode:N #1
{
\seq_set_eq:NN \l__GS_code_seq #1
\leavevmode
\int_compare:nNnTF { \l_GS_code_size_int } { = } { 8 }
{
\hbox_to_wd:nn { \l_GS_module_wd_dim * 7 } { }
\seq_set_eq:Nc \l_GS_system_seq { c__GS_AB0_seq }
}
{
\hbox_to_wd:nn { \l_GS_module_wd_dim * 11 } { }
\seq_pop_left:NN \l__GS_code_seq \l_tmpa_tl
\seq_set_eq:Nc \l_GS_system_seq { c__GS_AB \l_tmpa_tl _seq }
\hbox_overlap_left:n { \l_tmpa_tl }
}
\__GS_modules_start_black:Nn \c__GS_margin_seq
{ \l_GS_module_ht_dim + \l_GS_module_wd_dim * 5 }
\int_step_inline:nnnn { 1 } { 1 }
{ \int_div_truncate:nn { \l_GS_code_size_int } { 2 } }
{
\seq_pop_left:NN \l__GS_code_seq \l_tmpa_tl
\hbox_overlap_right:n { \l_tmpa_tl }
\seq_pop_left:NN \l_GS_system_seq \l_tmpb_tl
\__GS_modules:cn { c__GS_ \l_tmpb_tl \l_tmpa_tl _seq }
{ \l_GS_module_ht_dim }
}
\__GS_modules_start_white:Nn \c__GS_separator_seq
{ \l_GS_module_ht_dim + \l_GS_module_wd_dim * 5 }
\int_step_inline:nnnn { 1 } { 1 }
{ \int_div_truncate:nn { \l_GS_code_size_int } { 2 } }
{
\seq_pop_left:NN \l__GS_code_seq \l_tmpa_tl
\hbox_overlap_right:n { \l_tmpa_tl }
\__GS_modules:cn { c__GS_A \l_tmpa_tl _seq }
{ \l_GS_module_ht_dim }
}
\__GS_modules_start_black:Nn \c__GS_margin_seq
{ \l_GS_module_ht_dim + \l_GS_module_wd_dim * 5 }
\hbox_to_wd:nn { \l_GS_module_wd_dim * 7 } { }
}
\RequirePackage{xparse}
\NewDocumentCommand \EANControlDigit
{ m }
{
\group_begin:
\GS_set_code_digit_seq:Nn \l__GS_code_seq { #1 }
\GS_cut_EAN_control_digit:N \l__GS_code_seq
\int_set_to_EAN_control_digit:NN \l_tmpa_int \l__GS_code_seq
\int_to_arabic:n { \l_tmpa_int }
\group_end:
}
\NewDocumentCommand \EANBarcode
{ o m }
{
\group_begin:
\IfNoValueF{#1}{ \keys_set:nn { GS1 } { #1 } }
\dim_compare:nNnT { \l_GS_module_ht_dim } { = } { \c_zero_dim }
{
\int_compare:nNnTF { \l_GS_code_size_int } { = } { 8 }
{ \dim_set:Nn \l_GS_module_ht_dim { 21.31 mm } }
{ \dim_set:Nn \l_GS_module_ht_dim { 25.01 mm } }
}
\bool_if:nT \l_GS_use_ocrb_bool
{
\usefont{OT1}{ocrb}{m}{n}\fontsize{9}{9}\selectfont
}
\GS_set_code_digit_seq:Nn \l__GS_code_seq { #2 }
\bool_if:NT \l_GS_add_control_bool
{
\GS_set_EAN_control_digit:N \l__GS_code_seq
}
\int_compare:nNnT
{ \seq_count:N \l__GS_code_seq }
{ > }
{ \l_GS_code_size_int }
{
\msg_error:nnn { GS1 } { EAN-code-size } { #2 }
}
\int_while_do:nNnn
{ \seq_count:N \l__GS_code_seq }
{ < }
{ \l_GS_code_size_int }
{
\seq_put_left:Nn \l__GS_code_seq { 0 }
}
\GS_use_as_EAN_barcode:N \l__GS_code_seq
\group_end:
}
\NewDocumentCommand \GSSetup
{ m }
{ \keys_set:nn { GS1 } { #1 } }
%%
%%
%% End of file `GS1.sty'.
|