Skip to content

Commit fa2fd17

Browse files
gitlostterryburton
authored andcommitted
telepennumeric: implement DLE switch to trailing ASCII
1 parent 6c72930 commit fa2fd17

3 files changed

Lines changed: 43 additions & 3 deletions

File tree

src/telepen.ps.src

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,31 @@ begin
136136
/barlen barcode length def
137137
options (parse) undef
138138

139+
%
140+
% Check numeric for DLE (ASCII 16) indicating switch to trailing ASCII
141+
%
142+
/trailasclen 0 def
143+
numeric {
144+
barcode <10> search {
145+
/barcode exch def
146+
/trailasc barlen barcode length sub string def
147+
trailasc exch 0 exch putinterval % DLE
148+
trailasc exch 1 exch putinterval
149+
/barlen barcode length def
150+
barlen 0 eq {
151+
/bwipp.telepenNumericDLEFirstCharacter (DLE cannot be first character in Telepen Numeric) //raiseerror exec
152+
} if
153+
/trailasclen trailasc length def
154+
} { pop } ifelse
155+
} if
156+
139157
%
140158
% Apply AST spec overrides and resolve physical specification
141159
%
142160
/telepen ast /apply_ast //render exec not { //raiseerror exec } if
143161
/resolve_strictspec //render exec
144162

145-
/sbs barlen 16 mul 48 add string def
163+
/sbs barlen trailasclen add 16 mul 48 add string def
146164

147165
%
148166
% Put the start character ASCII 95
@@ -196,6 +214,17 @@ begin
196214
/l l enc length add def
197215
} loop
198216

217+
0 1 trailasclen 1 sub {
218+
trailasc exch get /indx exch def
219+
indx 127 gt {
220+
/bwipp.telepenInvalidAlphaCharacter (Telepen Alpha characters must have ordinal values 0 to 127) //raiseerror exec
221+
} if
222+
/checksum checksum indx add def
223+
/enc //telepen.encs indx get def
224+
sbs l enc putinterval
225+
/l l enc length add def
226+
} for
227+
199228
%
200229
% Put the checksum character
201230
%
@@ -217,12 +246,17 @@ begin
217246
/sbs sbs 0 l getinterval def
218247

219248
% Build display text: replace non-printable chars with spaces
220-
/text barcode length string def
249+
/text barcode length trailasclen add string def
221250
0 1 barcode length 1 sub {
222251
/i exch def
223252
/c barcode i get def
224253
text i c 32 ge c 126 le and { c } { 32 } ifelse put
225254
} for
255+
1 1 trailasclen 1 sub { % Skip initial DLE
256+
/i exch def
257+
/c trailasc i get def
258+
text i 1 sub barcode length add c 32 ge c 126 le and { c } { 32 } ifelse put
259+
} for
226260

227261
/sbs [sbs {48 sub} forall] def
228262

tests/ps_tests/telepen.ps.test

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@
1919
{ (123) (numeric dontdraw) telepen } /bwipp.telepenNumericNotDigitPair isError
2020
{ (X123) (numeric dontdraw) telepen } /bwipp.telepenInvalidNumericCharacter isError
2121
{ (ABC\200) (dontdraw) telepen } /bwipp.telepenInvalidAlphaCharacter isError
22-
{ (123^016) (numeric parse dontdraw) telepen } /bwipp.telepenInvalidNumericCharacter isError
22+
{ (123^016) (numeric parse dontdraw) telepen } /bwipp.telepenNumericNotDigitPair isError % DLE now indicates trailing ASCII
23+
{ (123^015) (numeric parse dontdraw) telepen } /bwipp.telepenInvalidNumericCharacter isError
2324
{ (123^200) (numeric parse dontdraw) telepen } /bwipp.telepenInvalidNumericCharacter isError
25+
{ (^016A) (numeric parse dontdraw) telepen } /bwipp.telepenNumericDLEFirstCharacter isError
2426
{ (12^0153) (numeric parse dontdraw) telepen } /bwipp.telepenNumericNotDigitPair isError
2527
{ (12^1273) (numeric parse dontdraw) telepen } /bwipp.telepenNumericNotDigitPair isError
2628
{ (12^20034) (numeric parse dontdraw) telepen } /bwipp.telepenInvalidNumericControlCharacter isError
29+
{ (12^016^200) (numeric parse dontdraw) telepen } /bwipp.telepenInvalidAlphaCharacter isError
2730

2831
{ 501 string (dontdraw) telepen } /bwipp.telepeninputTooLong isError
2932

tests/ps_tests/telepennumeric.ps.test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
{ (01234567) (dontdraw) telepennumeric /sbs get
1212
} [ 1 1 1 1 1 1 1 1 1 1 3 3 3 1 1 1 1 1 1 1 3 1 1 1 3 3 1 3 1 3 1 1 3 1 3 3 3 3 1 3 1 1 1 1 1 3 1 1 1 1 3 3 1 1 3 1 3 1 3 3 1 1 1 1 1 1 1 1 1 1 ] debugIsEqual
1313

14+
{ (12^0163) (parse dontdraw) telepennumeric /sbs get % DLE indicating trailing ASCII
15+
} [ 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 3 1 1 1 3 1 3 1 3 1 1 1 3 1 1 1 1 1 1 1 3 1 1 1 1 1 3 1 1 1 3 3 1 1 3 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 ] debugIsEqual
16+
1417
{ (12^01534) (parse dontdraw) telepennumeric /sbs get % May be odd length if contains control chars
1518
} [ 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 3 1 1 1 3 1 1 1 1 1 1 1 1 1 3 1 3 1 1 1 1 3 1 1 1 1 1 3 1 1 3 1 1 1 1 1 3 1 3 1 3 3 1 1 1 1 1 1 1 1 1 1 ] debugIsEqual
1619

0 commit comments

Comments
 (0)