Subversion Repositories Scribus

Compare Revisions

Ignore whitespace Rev 25038 → Rev 25039

/branches/Version15x/Scribus/scribus/plugins/barcodegenerator/barcode.ps
1,9 → 1,9
%!PS
 
% Barcode Writer in Pure PostScript - Version 2018-02-04
% Barcode Writer in Pure PostScript - Version 2021-09-28
% https://bwipp.terryburton.co.uk
%
% Copyright (c) 2004-2018 Terry Burton
% Copyright (c) 2004-2022 Terry Burton
%
% Permission is hereby granted, free of charge, to any
% person obtaining a copy of this software and associated
32,7 → 32,7
% --BEGIN TEMPLATE--
 
% --BEGIN RESOURCE preamble--
%%BeginResource: Category uk.co.terryburton.bwipp 0.0 2018020400 29629 32838
%%BeginResource: Category uk.co.terryburton.bwipp 0.0 2021092800 29733 32838
%%BeginData: 6 ASCII Lines
currentglobal
true setglobal
46,8 → 46,8
 
% --BEGIN RESOURCE raiseerror--
% --REQUIRES preamble--
%%BeginResource: uk.co.terryburton.bwipp raiseerror 0.0 2018020400 153516 39847
%%BeginData: 13 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp raiseerror 0.0 2021092800 39041 38872
%%BeginData: 15 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
begin
57,7 → 57,9
$error /command null put
$error /newerror true put
stop
} bind def
}
[/barcode] {null def} forall
bind def
/raiseerror dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
65,10 → 67,1829
%%EndResource
% --END RESOURCE raiseerror--
 
% --BEGIN RESOURCE parseinput--
% --REQUIRES preamble raiseerror--
%%BeginResource: uk.co.terryburton.bwipp parseinput 0.0 2021092800 58513 58076
%%BeginData: 129 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
4 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
begin
/parseinput {
 
6 dict begin
 
/fncvals exch def
/barcode exch def
 
/parse dup dup fncvals exch get def fncvals exch undef
/parsefnc dup dup fncvals exch get def fncvals exch undef
/parseonly dup dup fncvals exch known def fncvals exch undef
/eci dup dup fncvals exch known def fncvals exch undef
 
/msg barcode length array def
/j 0 def
barcode { % loop
(^) search exch
% Copy characters up to a "^"
dup length exch
msg exch j exch [ exch {} forall ] putinterval
j add /j exch def
{ % Found a "^" escape character
pop
1 { % common exit
 
parse not parsefnc not and { % "^" as is
msg j 94 put
/j j 1 add def
exit
} if
 
% Encode "^" to start with
msg j 94 put
/j j 1 add def
 
% parse
parse {
dup length 3 ge {
dup 0 3 getinterval true exch {
dup 48 lt exch 57 gt or { pop false } if
} forall
{ % "^NNN" to byte
dup 0 3 getinterval cvi dup 255 gt {
pop pop
/bwipp.invalidOrdinal (Ordinal must be 000 to 255) //raiseerror exec
} if
/j j 1 sub def % Replace "^" with ordinal
msg exch j exch put
/j j 1 add def
dup length 3 sub 3 exch getinterval
} if
} if
} if
 
parseonly
parsefnc not or
msg j 1 sub get 94 ne % Carat was substituted away
or {exit} if
 
% parsefnc
/j j 1 sub def
dup length 3 lt {
pop
/bwipp.truncatedFNC (Function character truncated) //raiseerror exec
} if
dup 0 get 94 eq { % "^^" -> "^"
msg j 94 put
/j j 1 add def
dup length 1 sub 1 exch getinterval
exit
} if
dup 0 3 getinterval (ECI) eq eci and { % "^ECInnnnnn" -> -1nnnnnn
dup length 9 lt {
pop
/bwipp.truncatedECI (ECI truncated) //raiseerror exec
} if
dup 3 6 getinterval
dup {
dup 48 lt exch 57 gt or {
pop pop
/bwipp.invalidECI (ECI must be 000000 to 999999) //raiseerror exec
} if
} forall
0 exch {48 sub sub 10 mul} forall 10 idiv 1000000 sub
msg exch j exch put
/j j 1 add def
dup length 9 sub 9 exch getinterval
exit
} if
dup length 4 lt { % "^FNCx" -> fncvals{FNCx}
pop
/bwipp.truncatedFNC (Function character truncated) //raiseerror exec
} if
dup 0 4 getinterval dup fncvals exch known not {
dup length 28 add string dup 28 4 -1 roll putinterval
dup 0 (Unknown function character: ) putinterval
exch pop
/bwipp.unknownFNC exch //raiseerror exec
} if
fncvals exch get
msg exch j exch put
/j j 1 add def
dup length 4 sub 4 exch getinterval
exit
 
} repeat
} { % No more "^" characters
exit
} ifelse
} loop
 
parseonly not {
msg 0 j getinterval
} {
j string
0 1 j 1 sub { 1 index exch dup msg exch get put } for
} ifelse
 
end
 
}
[/barcode] {null def} forall
bind def
/parseinput dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END RESOURCE parseinput--
 
% --BEGIN RESOURCE gs1lint--
% --REQUIRES preamble raiseerror--
%%BeginResource: uk.co.terryburton.bwipp gs1lint 0.0 2021092800 346062 386888
%%BeginData: 1674 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
2 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
begin
/gs1lint {
 
20 dict begin
 
/vals exch def
/ais exch def
 
/lintnumeric {
true exch {
dup 48 lt exch 57 gt or { pop false exit } if
} forall
not { pop /bwipp.GS1notNumeric (Not numeric) false exit } if
} bind def
 
/lintcset82 {
true exch {
1 string dup 0 4 -1 roll put
(!"%&'()*+,-./0123456789:;<=>?ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz)
exch search not { pop pop false exit } if
pop pop pop
} forall
not { pop /bwipp.GS1badCSET82character (Invalid CSET 82 character) false exit } if
} bind def
 
/lintcset39 {
true exch {
1 string dup 0 4 -1 roll put
(#-/0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ)
exch search not { pop pop false exit } if
pop pop pop
} forall
not { pop /bwipp.GS1badCSET39character (Invalid CSET 39 character) false exit } if
} bind def
 
/lintkey {
dup length 2 lt { pop pop /bwipp.GS1keyTooShort (Key is too short) false exit } if
dup 0 get dup 48 lt exch 57 gt or exch
1 get dup 48 lt exch 57 gt or or {
pop /bwipp.GS1badGCP (Non-numeric company prefix) false exit
} if
} bind def
 
/lintimporteridx {
(-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz)
exch search not {pop pop /bwipp.GS1badImporterIndex (Invalid importer index) false exit} if
pop pop pop
} bind def
 
/lintcsum {
mark exch
dup length 2 mod 0 eq {3} {1} ifelse
exch { 48 sub 1 index mul exch 4 exch sub } forall pop
0 counttomark 1 sub {add} repeat exch pop
10 mod 0 ne { pop /bwipp.GS1badChecksum (Bad checksum) false exit } if
} bind def
 
/cset82 <<
0 (!"%&'\(\)*+,-./0123456789:;<=>?ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz)
{ exch dup 1 add } forall pop
>> def
 
/cset32 <<
0 (23456789ABCDEFGHJKLMNPQRSTUVWXYZ)
{ exch dup 1 add } forall pop
>> def
 
/lintcsumalpha {
dup length 2 lt { pop pop /bwipp.GS1alphaTooShort (Alphanumeric string is too short to check) false exit} if
dup length 2 sub
2 copy
0 exch getinterval mark exch {
dup cset82 exch known { cset82 exch get } { -1 exit } ifelse
} forall
dup -1 eq { cleartomark pop pop pop /bwipp.GS1UnknownCSET82Character (Unknown CSET 82 character) false exit} if
counttomark array astore exch pop
3 1 roll
2 getinterval mark exch {
dup cset32 exch known { cset32 exch get } { -1 exit } ifelse
} forall
dup -1 eq { cleartomark pop pop /bwipp.GS1UnknownCSET32Character (Unknown CSET 32 character) false exit} if
counttomark array astore exch pop
dup 0 get 5 bitshift exch 1 get add exch
[ 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 ]
1 index length
dup 2 index length gt { pop pop pop pop pop /bwipp.GS1alphaTooLong (Alphanumeric string is too long to check) false exit} if
0 exch getinterval {exch} forall
0 exch { 3 -1 roll exch mul add } forall 1021 mod
ne { pop /bwipp.GS1badAlphaCheckCharacters (Bad alphanumeric check characters) false exit} if
} bind def
 
/iso3166 << [
/004 /008 /010 /012 /016 /020 /024 /028 /031 /032 /036 /040 /044 /048
/050 /051 /052 /056 /060 /064 /068 /070 /072 /074 /076 /084 /086 /090 /092 /096
/100 /104 /108 /112 /116 /120 /124 /132 /136 /140 /144 /148
/152 /156 /158 /162 /166 /170 /174 /175 /178 /180 /184 /188 /191 /192 /196
/203 /204 /208 /212 /214 /218 /222 /226 /231 /232 /233 /234 /238 /239 /242 /246 /248
/250 /254 /258 /260 /262 /266 /268 /270 /275 /276 /288 /292 /296
/300 /304 /308 /312 /316 /320 /324 /328 /332 /334 /336 /340 /344 /348
/352 /356 /360 /364 /368 /372 /376 /380 /384 /388 /392 /398
/400 /404 /408 /410 /414 /417 /418 /422 /426 /428 /430 /434 /438 /440 /442 /446
/450 /454 /458 /462 /466 /470 /474 /478 /480 /484 /492 /496 /498 /499
/500 /504 /508 /512 /516 /520 /524 /528 /531 /533 /534 /535 /540 /548
/554 /558 /562 /566 /570 /574 /578 /580 /581 /583 /584 /585 /586 /591 /598
/600 /604 /608 /612 /616 /620 /624 /626 /630 /634 /638 /642 /643 /646
/652 /654 /659 /660 /662 /663 /666 /670 /674 /678 /682 /686 /688 /690 /694
/702 /703 /704 /705 /706 /710 /716 /724 /728 /729 /732 /740 /744 /748
/752 /756 /760 /762 /764 /768 /772 /776 /780 /784 /788 /792 /795 /796 /798
/800 /804 /807 /818 /826 /831 /832 /833 /834 /840
/850 /854 /858 /860 /862 /876 /882 /887 /894
] {dup} forall >> def
 
/lintiso3166 {
iso3166 exch known not { pop /bwipp.GS1UnknownCountry (Unknown country code) false exit } if
} bind def
 
/lintiso3166999 {
dup /999 ne {
iso3166 exch known not { pop /bwipp.GS1UnknownCountryOr999 (Unknown country code or not 999) false exit } if
} {
pop
} ifelse
} bind def
 
/lintiso3166list {
dup length 3 mod 0 ne {
pop pop /bwipp.GS1BadCountryListLength (Not a group of three-digit country codes) false exit
} if
true
0 3 3 index length 1 sub {
2 index exch 3 getinterval
iso3166 exch known not { pop pop false exit } if
} for
not { pop /bwipp.GS1UnknownCountry (Unknown country code) false exit } if
pop
} bind def
 
/iso3166alpha2 << [
/AD /AE /AF /AG /AI /AL /AM /AO /AQ /AR /AS /AT /AU /AW /AX /AZ
/BA /BB /BD /BE /BF /BG /BH /BI /BJ /BL /BM /BN /BO /BQ /BR /BS /BT /BV /BW /BY /BZ
/CA /CC /CD /CF /CG /CH /CI /CK /CL /CM /CN /CO /CR /CU /CV /CW /CX /CY /CZ
/DE /DJ /DK /DM /DO /DZ
/EC /EE /EG /EH /ER /ES /ET
/FI /FJ /FK /FM /FO /FR
/GA /GB /GD /GE /GF /GG /GH /GI /GL /GM /GN /GP /GQ /GR /GS /GT /GU /GW /GY
/HK /HM /HN /HR /HT /HU
/ID /IE /IL /IM /IN /IO /IQ /IR /IS /IT /JE /JM /JO /JP
/KE /KG /KH /KI /KM /KN /KP /KR /KW /KY /KZ
/LA /LB /LC /LI /LK /LR /LS /LT /LU /LV /LY
/MA /MC /MD /ME /MF /MG /MH /MK /ML /MM /MN /MO /MP /MQ /MR /MS /MT /MU /MV /MW /MX /MY /MZ
/NA /NC /NE /NF /NG /NI /NL /NO /NP /NR /NU /NZ
/OM
/PA /PE /PF /PG /PH /PK /PL /PM /PN /PR /PS /PT /PW /PY
/QA
/RE /RO /RS /RU /RW
/SA /SB /SC /SD /SE /SG /SH /SI /SJ /SK /SL /SM /SN /SO /SR /SS /ST /SV /SX /SY /SZ
/TC /TD /TF /TG /TH /TJ /TK /TL /TM /TN /TO /TR /TT /TV /TW /TZ
/UA /UG /UM /US /UY /UZ
/VA /VC /VE /VG /VI /VN /VU
/WF /WS
/YE /YT
/ZA /ZM /ZW
] {dup} forall >> def
 
/lintiso3166alpha2 {
iso3166alpha2 exch known not { pop /bwipp.GS1UnknownCountryAlpha (Unknown country alpha code) false exit } if
} bind def
 
/iso4217 << [
/008 /012 /032 /036 /044 /048
/050 /051 /052 /060 /064 /068 /072 /084 /090 /096
/104 /108 /116 /124 /132 /136 /144
/152 /156 /170 /174 /188 /191 /192
/203 /208 /214 /222 /230 /232 /238 /242 /262 /270 /292
/320 /324 /328 /332 /340 /344 /348
/352 /356 /360 /364 /368 /376 /388 /392 /398
/400 /404 /408 /410 /414 /417 /418
/422 /426 /430 /434 /446
/454 /458 /462 /480 /484 /496 /498
/504 /512 /516 /524 /532 /533 /548
/554 /558 /566 /578 /586 /590 /598
/600 /604 /608 /634 /643 /646 /654 /682 /690 /694
/702 /704 /706 /710 /728 /748
/752 /756 /760 /764 /776 /780 /784 /788
/800 /807 /818 /826 /834 /840 /858 /860 /882 /886
/901 /927 /928 /929 /930 /931 /932 /933 /934 /936 /938
/940 /941 /943 /944 /946 /947 /948 /949
/950 /951 /952 /953 /955 /956 /957 /958 /959
/960 /961 /962 /963 /964 /965 /967 /968 /969
/970 /971 /972 /973 /975 /976 /977 /978 /979
/980 /981 /984 /985 /986 /990 /994 /997 /999
] {dup} forall >> def
 
/lintiso4217 {
iso4217 exch known not { pop /bwipp.GS1UnknownCurrency (Unknown currency code) false exit } if
} bind def
 
/lintiban {
dup length 4 le { pop pop /bwipp.GS1tooShort (IBAN too short) false exit } if
dup true exch {
1 string dup 0 4 -1 roll put
(0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ)
exch search not { pop pop false exit } if
pop pop pop
} forall
not { pop /bwipp.GS1badIBANcharacter (Invalid IBAN character) false exit } if
dup mark exch mark exch {} forall counttomark -4 roll counttomark array astore exch pop {
48 sub dup 9 gt {7 sub dup 10 idiv exch 10 mod} if
} forall counttomark array astore exch pop
0 exch {exch 10 mul add 97 mod} forall
1 ne { pop pop /bwipp.GS1badIBANchecksum (IBAN checksum incorrect) false exit } if
0 2 getinterval lintiso3166alpha2
} bind def
 
/lintzero {
(0) ne { pop /bwipp.GS1zeroRequired (Zero is required) false exit } if
} bind def
 
/lintnonzero {
false exch { 48 ne {pop true} if } forall
not { pop /bwipp.GS1zeroNotPermitted (Zero not permitted) false exit } if
} bind def
 
/lintnozeroprefix {
dup length 1 gt exch 0 get 48 eq and {
pop /bwipp.GS1badZeroPrefix (Zero prefix is not permitted) false exit
} if
} bind def
 
/lintyymmd0 {
dup 2 2 getinterval cvi dup 1 lt exch 12 gt or { pop /bwipp.GS1badMonth (Invalid month) false exit } if
dup 0 2 getinterval cvi dup 21 sub % Update 20YY periodically for century calculation
dup 51 ge {pop 1900 add} { -50 le {2100 add} {2000 add} ifelse} ifelse % YYYY
dup 400 mod 0 eq exch dup 4 mod 0 eq exch 100 mod 0 ne and or % Leap year?
[ 31 3 -1 roll {29} {28} ifelse 31 30 31 30 31 31 30 31 30 31 ]
1 index 2 2 getinterval cvi 1 sub get
exch 4 2 getinterval cvi lt { pop /bwipp.GS1badDay (Invalid day of month) false exit } if
} bind def
 
/lintyymmdd {
dup length 6 ne { pop /bwipp.GS1badDateLength (Invalid length for date) false exit } if
dup 4 2 getinterval cvi 1 lt { pop /bwipp.GS1badDay (Invalid day of month) false exit } if
lintyymmd0
} bind def
 
/lintyymmddhh {
dup length 8 ne { pop /bwipp.GS1badYYMMDDHHLength (Invalid length for date with hour) false exit } if
dup 6 2 getinterval cvi 23 gt { pop pop /bwipp.GS1badHour (Invalid hour of day) false exit } if
0 6 getinterval lintyymmdd
} bind def
 
/linthhmm {
dup 0 2 getinterval cvi 23 gt { pop pop /bwipp.GS1badHour (Invalid hour of day) false exit } if
2 2 getinterval cvi 59 gt { pop /bwipp.GS1badMinute (Invalid minute in the hour) false exit } if
} bind def
 
/lintmmoptss {
dup length dup 2 ne exch 4 ne and {
pop /bwipp.GS1badTimeLength (Invalid length for optional minutes and seconds) false exit
} if
dup 0 2 getinterval cvi 59 gt { pop pop /bwipp.GS1badMinute (Invalid minute in the hour) false exit } if
dup length 4 ge {
dup 2 2 getinterval cvi 59 gt { pop pop /bwipp.GS1badSecond (Invalid second in the minute) false exit } if
} if
pop
} bind def
 
/lintyesno {
dup (0) ne exch (1) ne and {
pop /bwipp.GS1badBoolean (Neither 0 nor 1 for yes or no) false exit
} if
} bind def
 
/lintwinding {
dup (0) ne exch dup (1) ne exch (9) ne and and {
pop /bwipp.GS1badWinding (Invalid winding direction) false exit
} if
} bind def
 
/lintpieceoftotal {
dup length 2 mod 0 ne { pop pop /bwipp.GS1badPieceTotalLength (Invalid piece/total length) false exit } if
dup dup length 2 idiv 0 exch getinterval cvi
dup 0 eq { pop pop pop /bwipp.GS1badPieceNumber (Invalid piece number) false exit } if
exch dup length 2 idiv dup getinterval cvi
dup 0 eq { pop pop pop /bwipp.GS1badPieceTotal (Invalid total number) false exit } if
gt { pop /bwipp.GS1pieceExceedsTotal (Piece number exceeds total) false exit } if
} bind def
 
/lintpcenc {
{
(%) search not {pop exit} if
pop pop dup length 2 lt { pop pop /bwipp.GS1badPercentEscape (Invalid % escape) false exit } if
dup 0 2 getinterval true exch {
1 string dup 0 4 -1 roll put
(0123456789ABCDEFabcdef)
exch search not { pop pop false exit } if
pop pop pop
} forall
not { pop pop /bwipp.GS1badPercentChars (Invalid characters for percent encoding) false exit } if
} loop
} bind def
 
/lintcouponcode {
dup true exch {
dup 48 lt exch 57 gt or { pop false exit } if
} forall
not { pop pop /bwipp.GS1couponNotNumeric (Coupon not numeric) false exit } if
 
% GCP VLI and value
dup length 1 lt {
pop pop /bwipp.GS1couponTooShortGCPVLI (Coupon too short: Missing GCP VLI) false exit
} if
dup 0 1 getinterval cvi dup 6 gt {
pop pop /bwipp.GS1couponBadGCPVLI (Coupon GCP length indicator must be 0-6) false exit
} if
6 add 1 add
2 copy exch length gt {
pop pop pop /bwipp.GS1couponTooShortGCP (Coupon too short: GCP truncated) false exit
} if
dup 2 index length exch sub getinterval
 
% Offer Code
dup length 6 lt {
pop pop /bwipp.GS1couponTooShortOfferCode (Coupon too short: Offer Code truncated) false exit
} if
dup length 6 sub 6 exch getinterval
 
% Save Value VLI and value
dup length 1 lt {
pop pop /bwipp.GS1couponTooShortSaveValueVLI (Coupon too short: Missing Save Value VLI) false exit
} if
dup 0 1 getinterval cvi dup dup 1 lt exch 5 gt or {
pop pop /bwipp.GS1couponBadSaveValueVLI (Coupon Save Value length indicator must be 1-5) false exit
} if
1 add
2 copy exch length gt {
pop pop pop /bwipp.GS1couponTooShortSaveValue (Coupon too short: Save Value truncated) false exit
} if
dup 2 index length exch sub getinterval
 
% 1st Purchase Requirement VLI and value
dup length 1 lt {
pop pop /bwipp.GS1couponTooShort1stPurchaseRequirementVLI (Coupon too short: Missing 1st Purchase Requirement VLI) false exit
} if
dup 0 1 getinterval cvi dup dup 1 lt exch 5 gt or {
pop pop /bwipp.GS1couponBad1stPurchaseRequirementVLI (Coupon 1st Purchase Requirement length indicator must be 1-5) false exit
} if
1 add
2 copy exch length gt {
pop pop pop /bwipp.GS1couponTooShort1stPurchaseRequirement (Coupon too short: 1st Purchase Requirement truncated) false exit
} if
dup 2 index length exch sub getinterval
 
% 1st Purchase Requirement Code
dup length 1 lt {
pop pop /bwipp.GS1couponTooShort1stPurchaseRequirementCode (Coupon too short: Missing 1st Purchase Requirement Code) false exit
} if
dup 0 1 getinterval cvi dup 4 gt exch 9 ne and {
pop pop /bwipp.GS1couponBad1stPurchaseRequirementCode (Coupon 1st Purchase Requirement Code must be 0-4 or 9) false exit
} if
dup length 1 sub 1 exch getinterval
 
% 1st Purchase Family Code
dup length 3 lt {
pop pop /bwipp.GS1couponTooShort1stPurchaseFamilyCode (Coupon too short: 1st Purchase Family Code truncated) false exit
} if
dup length 3 sub 3 exch getinterval
 
% Optional field 1
dup length 1 ge { dup 0 1 getinterval cvi 1 eq {
1 dup 2 index length exch sub getinterval
 
% Additional Purchase Rules Code
dup length 1 lt {
pop pop /bwipp.GS1couponTooShortAdditionalPurchaseRulesCode (Coupon too short: Missing Additional Purchase Rules Code) false exit
} if
dup 0 1 getinterval cvi 3 gt {
pop pop /bwipp.GS1couponBadAdditionalPurchaseRulesCode (Coupon Additional Purchase Rules Code must be 0-3) false exit
} if
dup length 1 sub 1 exch getinterval
 
% 2nd Purchase RequirementVLI and value
dup length 1 lt {
pop pop /bwipp.GS1couponTooShort2ndPurchaseRequirementVLI (Coupon too short: Missing 2nd Purchase Requirement VLI) false exit
} if
dup 0 1 getinterval cvi dup dup 1 lt exch 5 gt or {
pop pop /bwipp.GS1couponBad2ndPurchaseRequirementVLI (Coupon 2nd Purchase Requirement length indicator must be 1-5) false exit
} if
1 add
2 copy exch length gt {
pop pop pop /bwipp.GS1couponTooShort2ndPurchaseRequirement (Coupon too short: 2nd Purchase Requirement truncated) false exit
} if
dup 2 index length exch sub getinterval
 
% 2nd Purchase Requirement Code
dup length 1 lt {
pop pop /bwipp.GS1couponTooShort2ndPurchaseRequirementCode (Coupon too short: Missing 2nd Purchase Requirement Code) false exit
} if
dup 0 1 getinterval cvi dup 4 gt exch 9 ne and {
pop pop /bwipp.GS1couponBad2ndPurchaseRequirementCode (Coupon 2nd Purchase Requirement Code must be 0-4 or 9) false exit
} if
dup length 1 sub 1 exch getinterval
 
% 2nd Purchase Family Code
dup length 3 lt {
pop pop /bwipp.GS1couponTooShort2ndPurchaseFamilyCode (Coupon too short: 2nd Purchase Family Code truncated) false exit
} if
dup length 3 sub 3 exch getinterval
 
% 2nd Purchase GCP VLI and value
dup length 1 lt {
pop pop /bwipp.GS1couponTooShort2ndPurchaseGCPVLI (Coupon too short: Missing 2nd Purchase GCP VLI) false exit
} if
dup 0 1 getinterval cvi dup dup 6 gt exch 9 ne and {
pop pop /bwipp.GS1couponBad2ndPurchaseGCPVLI (Coupon 2nd Purchase GCP length indicator must be 0-6 or 9) false exit
} if
dup 9 ne {6 add} {pop 0} ifelse 1 add
2 copy exch length gt {
pop pop pop /bwipp.GS1couponTooShort2ndPurchaseGCP (Coupon too short: 2nd Purchase GCP truncated) false exit
} if
dup 2 index length exch sub getinterval
 
} if } if
 
% Optional field 2
dup length 1 ge { dup 0 1 getinterval cvi 2 eq {
1 dup 2 index length exch sub getinterval
 
% 3rd Purchase RequirementVLI and value
dup length 1 lt {
pop pop /bwipp.GS1couponTooShort3rdPurchaseRequirementVLI (Coupon too short: Missing 3rd Purchase Requirement VLI) false exit
} if
dup 0 1 getinterval cvi dup dup 1 lt exch 5 gt or {
pop pop /bwipp.GS1couponBad3rdPurchaseRequirementVLI (Coupon 3rd Purchase Requirement length indicator must be 1-5) false exit
} if
1 add
2 copy exch length gt {
pop pop pop /bwipp.GS1couponTooShort3rdPurchaseRequirement (Coupon too short: 3rd Purchase Requirement truncated) false exit
} if
dup 2 index length exch sub getinterval
 
% 3rd Purchase Requirement Code
dup length 1 lt {
pop pop /bwipp.GS1couponTooShort3rdPurchaseRequirementCode (Coupon too short: Missing 3rd Purchase Requirement Code) false exit
} if
dup 0 1 getinterval cvi dup 4 gt exch 9 ne and {
pop pop /bwipp.GS1couponBad3rdPurchaseRequirementCode (Coupon 3rd Purchase Requirement Code must be 0-4 or 9) false exit
} if
dup length 1 sub 1 exch getinterval
 
% 3rd Purchase Family Code
dup length 3 lt {
pop pop /bwipp.GS1couponTooShort3rdPurchaseFamilyCode (Coupon too short: 3rd Purchase Family Code truncated) false exit
} if
dup length 3 sub 3 exch getinterval
 
% 3rd Purchase GCP VLI and value
dup length 1 lt {
pop pop /bwipp.GS1couponTooShort3rdPurchaseGCPVLI (Coupon too short: Missing 3rd Purchase GCP VLI) false exit
} if
dup 0 1 getinterval cvi dup dup 6 gt exch 9 ne and {
pop pop /bwipp.GS1couponBad3rdPurchaseGCPVLI (Coupon 3rd Purchase GCP length indicator must be 0-6 or 9) false exit
} if
dup 9 ne {6 add} {pop 0} ifelse 1 add
2 copy exch length gt {
pop pop pop /bwipp.GS1couponTooShort3rdPurchaseGCP (Coupon too short: 3rd Purchase GCP truncated) false exit
} if
dup 2 index length exch sub getinterval
 
} if } if
 
% Optional field 3
/couponexpire -1 def
dup length 1 ge { dup 0 1 getinterval cvi 3 eq {
1 dup 2 index length exch sub getinterval
 
% Expiration date
dup length 6 lt {
pop pop /bwipp.GS1couponTooShortExpirationDate (Coupon too short: Expiration date) false exit
} if
dup 2 2 getinterval cvi dup 1 lt exch 12 gt or { pop pop /bwipp.GS1couponExpirationDateBadMonth (Invalid month in expiration date) false exit } if
dup 0 2 getinterval cvi dup 21 sub % Update 20YY periodically for century calculation
dup 51 ge {pop 1900 add} { -50 le {2100 add} {2000 add} ifelse} ifelse % YYYY
dup 400 mod 0 eq exch dup 4 mod 0 eq exch 100 mod 0 ne and or % Leap year?
[ 31 3 -1 roll {29} {28} ifelse 31 30 31 30 31 31 30 31 30 31 ]
1 index 2 2 getinterval cvi 1 sub get
1 index 4 2 getinterval cvi dup 3 1 roll lt
exch 1 lt or { pop pop /bwipp.GS1couponExpirationDateBadDay (Invalid day of month in expiration date) false exit } if
dup 0 6 getinterval cvi /couponexpire exch def
dup length 6 sub 6 exch getinterval
 
} if } if
 
% Optional field 4
dup length 1 ge { dup 0 1 getinterval cvi 4 eq {
1 dup 2 index length exch sub getinterval
 
% Start date
dup length 6 lt {
pop pop /bwipp.GS1couponTooShortStartDate (Coupon too short: Start date) false exit
} if
dup 2 2 getinterval cvi dup 1 lt exch 12 gt or { pop pop /bwipp.GS1couponStartDateBadMonth (Invalid month in start date) false exit } if
dup 0 2 getinterval cvi dup 21 sub % Update 20YY periodically for century calculation
dup 51 ge {pop 1900 add} { -50 le {2100 add} {2000 add} ifelse} ifelse % YYYY
dup 400 mod 0 eq exch dup 4 mod 0 eq exch 100 mod 0 ne and or % Leap year?
[ 31 3 -1 roll {29} {28} ifelse 31 30 31 30 31 31 30 31 30 31 ]
1 index 2 2 getinterval cvi 1 sub get
1 index 4 2 getinterval cvi dup 3 1 roll lt
exch 1 lt or { pop pop /bwipp.GS1couponStartDateBadDay (Invalid day of month in start date) false exit } if
dup 0 6 getinterval cvi /couponstart exch def
couponexpire -1 ne couponexpire couponstart lt and {
pop pop /bwipp.GS1couponExpireDateBeforeStartDate (Coupon expires before it starts) false exit
} if
dup length 6 sub 6 exch getinterval
 
} if } if
 
% Optional field 5
dup length 1 ge { dup 0 1 getinterval cvi 5 eq {
1 dup 2 index length exch sub getinterval
 
% Serial Number VLI and value
dup length 1 lt {
pop pop /bwipp.GS1couponTooShortSerialNumberVLI (Coupon too short: Missing Serial Number VLI) false exit
} if
dup 0 1 getinterval cvi 6 add 1 add
2 copy exch length gt {
pop pop pop /bwipp.GS1couponTooShortSerialNumber (Coupon too short: Serial Number truncated) false exit
} if
dup 2 index length exch sub getinterval
 
} if } if
 
% Optional field 6
dup length 1 ge { dup 0 1 getinterval cvi 6 eq {
1 dup 2 index length exch sub getinterval
 
% Retailer GCP/GLN VLI and value
dup length 1 lt {
pop pop /bwipp.GS1couponTooShortRetailerGCPGLNVLI (Coupon too short: Missing Retailer GCP/GLN VLI) false exit
} if
dup 0 1 getinterval cvi dup dup 1 lt exch 7 gt or {
pop pop /bwipp.GS1couponBadRetailerGCPGLNVLI (Coupon Retailer GCP/GLN length indicator must be 1-7) false exit
} if
6 add 1 add
2 copy exch length gt {
pop pop pop /bwipp.GS1couponTooShortRetailerGCPGLN (Coupon too short: Retailer GCP/GLN truncated) false exit
} if
dup 2 index length exch sub getinterval
 
} if } if
 
% Optional field 9
dup length 1 ge { dup 0 1 getinterval cvi 9 eq {
1 dup 2 index length exch sub getinterval
 
% Save Value Code
dup length 1 lt {
pop pop /bwipp.GS1couponTooShortSaveValueCode (Coupon too short: Missing Save Value Code) false exit
} if
dup 0 1 getinterval cvi dup 6 gt exch dup 3 eq exch 4 eq or or {
pop pop /bwipp.GS1couponBadSaveValueCode (Coupon Save Value Code must be 0,1,2,5 or 6) false exit
} if
dup length 1 sub 1 exch getinterval
 
% Save Value Applies to Item
dup length 1 lt {
pop pop /bwipp.GS1couponTooShortSaveValueAppliesToItem (Coupon too short: Missing Save Value Applies to Item) false exit
} if
dup 0 1 getinterval cvi 2 gt {
pop pop /bwipp.GS1couponBadSaveValueAppliesToItem (Coupon Save Value Applies to Item must be 0-2) false exit
} if
dup length 1 sub 1 exch getinterval
 
% Store Coupon Flag
dup length 1 lt {
pop pop /bwipp.GS1couponTooShortStoreCouponFlag (Coupon too short: Missing Store Coupon Flag) false exit
} if
dup length 1 sub 1 exch getinterval
 
% Don't Multiply Flag
dup length 1 lt {
pop pop /bwipp.GS1couponTooShortDontMultiplyFlag (Coupon too short: Missing Don't Multiply Flag) false exit
} if
dup 0 1 getinterval cvi 1 gt {
pop pop /bwipp.GS1couponBadDontMultiplyFlag (Don't Multiply Flag must be 0 or 1) false exit
} if
dup length 1 sub 1 exch getinterval
 
} if } if
 
dup length 0 ne {
pop pop /bwipp.GS1couponUnrecognisedOptionalField (Coupon fields must be 1,2,3,4,5,6 or 9, increasing order) false exit
} if
pop
} bind def
 
/lintcouponposoffer {
dup true exch {
dup 48 lt exch 57 gt or { pop false exit } if
} forall
not { pop pop /bwipp.GS1couponNotNumeric (Coupon not numeric) false exit } if
% Format Code
dup length 1 lt {
pop pop /bwipp.GS1couponTooShortFormatCode (Coupon too short: Missing Format Code) false exit
} if
dup 0 1 getinterval dup (0) ne exch (1) ne and {
pop pop /bwipp.GS1couponBadFormatCode (Coupon format must be 0 or 1) false exit
} if
dup length 1 sub 1 exch getinterval
% Funder ID VLI and Funder ID
dup length 1 lt {
pop pop /bwipp.GS1couponTooShortFunderVLI (Coupon too short: Missing Funder VLI) false exit
} if
dup 0 1 getinterval cvi dup 6 gt {
pop pop pop /bwipp.GS1couponBadFunderVLI (Coupon Funder length indicator must be 0-6) false exit
} if
6 add 1 add
2 copy exch length gt {
pop pop pop /bwipp.GS1couponTooShortFunder (Coupon too short: Truncated Funder ID) false exit
} if
dup 2 index length exch sub getinterval
% Offer Code
dup length 6 lt {
pop pop /bwipp.GS1couponTooShortOfferCode (Coupon too short: Truncated Offer Code) false exit
} if
dup length 6 sub 6 exch getinterval
% Serial Number VLI and Serial Number
dup length 1 lt {
pop pop /bwipp.GS1couponTooShortSnVLI (Coupon too short: Missing SN VLI) false exit
} if
dup 0 1 getinterval cvi
6 add 1 add
2 copy exch length gt {
pop pop pop /bwipp.GS1couponTooShortSn (Coupon too short: Truncated SN) false exit
} if
dup 2 index length exch sub getinterval
dup length 0 ne {
pop pop /bwipp.GS1couponTooLong (Coupon too long) false exit
} if
pop
} bind def
 
/gs1syntax <<
 
[
<< /cset /N /min 18 /max 18 /check [ /lintcsum /lintkey ] >>
]
(00) exch dup
pop
 
[
<< /cset /N /min 14 /max 14 /check [ /lintcsum /lintkey ] >>
]
(01) exch dup
(02) exch dup
pop
 
[
<< /cset /X /min 1 /max 20 /check [] >>
]
(10) exch dup
pop
 
[
<< /cset /N /min 6 /max 6 /check [ /lintyymmd0 ] >>
]
(11) exch dup
(12) exch dup
(13) exch dup
(15) exch dup
(16) exch dup
(17) exch dup
pop
 
[
<< /cset /N /min 2 /max 2 /check [] >>
]
(20) exch dup
pop
 
[
<< /cset /X /min 1 /max 20 /check [] >>
]
(21) exch dup
(22) exch dup
pop
 
[
<< /cset /X /min 1 /max 28 /check [] >>
]
(235) exch dup
pop
 
[
<< /cset /X /min 1 /max 30 /check [] >>
]
(240) exch dup
(241) exch dup
pop
 
[
<< /cset /N /min 1 /max 6 /check [] >>
]
(242) exch dup
pop
 
[
<< /cset /X /min 1 /max 20 /check [] >>
]
(243) exch dup
pop
 
[
<< /cset /X /min 1 /max 30 /check [] >>
]
(250) exch dup
(251) exch dup
pop
 
[
<< /cset /N /min 13 /max 13 /check [ /lintcsum /lintkey ] >>
<< /cset /X /min 0 /max 17 /check [] >>
]
(253) exch dup
pop
 
[
<< /cset /X /min 1 /max 20 /check [] >>
]
(254) exch dup
pop
 
[
<< /cset /N /min 13 /max 13 /check [ /lintcsum /lintkey ] >>
<< /cset /N /min 0 /max 12 /check [] >>
]
(255) exch dup
pop
 
[
<< /cset /N /min 1 /max 8 /check [] >>
]
(30) exch dup
pop
 
[
<< /cset /N /min 6 /max 6 /check [] >>
]
(3100) exch dup
(3101) exch dup
(3102) exch dup
(3103) exch dup
(3104) exch dup
(3105) exch dup
(3110) exch dup
(3111) exch dup
(3112) exch dup
(3113) exch dup
(3114) exch dup
(3115) exch dup
(3120) exch dup
(3121) exch dup
(3122) exch dup
(3123) exch dup
(3124) exch dup
(3125) exch dup
(3130) exch dup
(3131) exch dup
(3132) exch dup
(3133) exch dup
(3134) exch dup
(3135) exch dup
(3140) exch dup
(3141) exch dup
(3142) exch dup
(3143) exch dup
(3144) exch dup
(3145) exch dup
(3150) exch dup
(3151) exch dup
(3152) exch dup
(3153) exch dup
(3154) exch dup
(3155) exch dup
(3160) exch dup
(3161) exch dup
(3162) exch dup
(3163) exch dup
(3164) exch dup
(3165) exch dup
(3200) exch dup
(3201) exch dup
(3202) exch dup
(3203) exch dup
(3204) exch dup
(3205) exch dup
(3210) exch dup
(3211) exch dup
(3212) exch dup
(3213) exch dup
(3214) exch dup
(3215) exch dup
(3220) exch dup
(3221) exch dup
(3222) exch dup
(3223) exch dup
(3224) exch dup
(3225) exch dup
(3230) exch dup
(3231) exch dup
(3232) exch dup
(3233) exch dup
(3234) exch dup
(3235) exch dup
(3240) exch dup
(3241) exch dup
(3242) exch dup
(3243) exch dup
(3244) exch dup
(3245) exch dup
(3250) exch dup
(3251) exch dup
(3252) exch dup
(3253) exch dup
(3254) exch dup
(3255) exch dup
(3260) exch dup
(3261) exch dup
(3262) exch dup
(3263) exch dup
(3264) exch dup
(3265) exch dup
(3270) exch dup
(3271) exch dup
(3272) exch dup
(3273) exch dup
(3274) exch dup
(3275) exch dup
(3280) exch dup
(3281) exch dup
(3282) exch dup
(3283) exch dup
(3284) exch dup
(3285) exch dup
(3290) exch dup
(3291) exch dup
(3292) exch dup
(3293) exch dup
(3294) exch dup
(3295) exch dup
(3300) exch dup
(3301) exch dup
(3302) exch dup
(3303) exch dup
(3304) exch dup
(3305) exch dup
(3310) exch dup
(3311) exch dup
(3312) exch dup
(3313) exch dup
(3314) exch dup
(3315) exch dup
(3320) exch dup
(3321) exch dup
(3322) exch dup
(3323) exch dup
(3324) exch dup
(3325) exch dup
(3330) exch dup
(3331) exch dup
(3332) exch dup
(3333) exch dup
(3334) exch dup
(3335) exch dup
(3340) exch dup
(3341) exch dup
(3342) exch dup
(3343) exch dup
(3344) exch dup
(3345) exch dup
(3350) exch dup
(3351) exch dup
(3352) exch dup
(3353) exch dup
(3354) exch dup
(3355) exch dup
(3360) exch dup
(3361) exch dup
(3362) exch dup
(3363) exch dup
(3364) exch dup
(3365) exch dup
(3370) exch dup
(3371) exch dup
(3372) exch dup
(3373) exch dup
(3374) exch dup
(3375) exch dup
(3400) exch dup
(3401) exch dup
(3402) exch dup
(3403) exch dup
(3404) exch dup
(3405) exch dup
(3410) exch dup
(3411) exch dup
(3412) exch dup
(3413) exch dup
(3414) exch dup
(3415) exch dup
(3420) exch dup
(3421) exch dup
(3422) exch dup
(3423) exch dup
(3424) exch dup
(3425) exch dup
(3430) exch dup
(3431) exch dup
(3432) exch dup
(3433) exch dup
(3434) exch dup
(3435) exch dup
(3440) exch dup
(3441) exch dup
(3442) exch dup
(3443) exch dup
(3444) exch dup
(3445) exch dup
(3450) exch dup
(3451) exch dup
(3452) exch dup
(3453) exch dup
(3454) exch dup
(3455) exch dup
(3460) exch dup
(3461) exch dup
(3462) exch dup
(3463) exch dup
(3464) exch dup
(3465) exch dup
(3470) exch dup
(3471) exch dup
(3472) exch dup
(3473) exch dup
(3474) exch dup
(3475) exch dup
(3480) exch dup
(3481) exch dup
(3482) exch dup
(3483) exch dup
(3484) exch dup
(3485) exch dup
(3490) exch dup
(3491) exch dup
(3492) exch dup
(3493) exch dup
(3494) exch dup
(3495) exch dup
(3500) exch dup
(3501) exch dup
(3502) exch dup
(3503) exch dup
(3504) exch dup
(3505) exch dup
(3510) exch dup
(3511) exch dup
(3512) exch dup
(3513) exch dup
(3514) exch dup
(3515) exch dup
(3520) exch dup
(3521) exch dup
(3522) exch dup
(3523) exch dup
(3524) exch dup
(3525) exch dup
(3530) exch dup
(3531) exch dup
(3532) exch dup
(3533) exch dup
(3534) exch dup
(3535) exch dup
(3540) exch dup
(3541) exch dup
(3542) exch dup
(3543) exch dup
(3544) exch dup
(3545) exch dup
(3550) exch dup
(3551) exch dup
(3552) exch dup
(3553) exch dup
(3554) exch dup
(3555) exch dup
(3560) exch dup
(3561) exch dup
(3562) exch dup
(3563) exch dup
(3564) exch dup
(3565) exch dup
(3570) exch dup
(3571) exch dup
(3572) exch dup
(3573) exch dup
(3574) exch dup
(3575) exch dup
(3600) exch dup
(3601) exch dup
(3602) exch dup
(3603) exch dup
(3604) exch dup
(3605) exch dup
(3610) exch dup
(3611) exch dup
(3612) exch dup
(3613) exch dup
(3614) exch dup
(3615) exch dup
(3620) exch dup
(3621) exch dup
(3622) exch dup
(3623) exch dup
(3624) exch dup
(3625) exch dup
(3630) exch dup
(3631) exch dup
(3632) exch dup
(3633) exch dup
(3634) exch dup
(3635) exch dup
(3640) exch dup
(3641) exch dup
(3642) exch dup
(3643) exch dup
(3644) exch dup
(3645) exch dup
(3650) exch dup
(3651) exch dup
(3652) exch dup
(3653) exch dup
(3654) exch dup
(3655) exch dup
(3660) exch dup
(3661) exch dup
(3662) exch dup
(3663) exch dup
(3664) exch dup
(3665) exch dup
(3670) exch dup
(3671) exch dup
(3672) exch dup
(3673) exch dup
(3674) exch dup
(3675) exch dup
(3680) exch dup
(3681) exch dup
(3682) exch dup
(3683) exch dup
(3684) exch dup
(3685) exch dup
(3690) exch dup
(3691) exch dup
(3692) exch dup
(3693) exch dup
(3694) exch dup
(3695) exch dup
pop
 
[
<< /cset /N /min 1 /max 8 /check [] >>
]
(37) exch dup
pop
 
[
<< /cset /N /min 1 /max 15 /check [] >>
]
(3900) exch dup
(3901) exch dup
(3902) exch dup
(3903) exch dup
(3904) exch dup
(3905) exch dup
(3906) exch dup
(3907) exch dup
(3908) exch dup
(3909) exch dup
pop
 
[
<< /cset /N /min 3 /max 3 /check [ /lintiso4217 ] >>
<< /cset /N /min 1 /max 15 /check [] >>
]
(3910) exch dup
(3911) exch dup
(3912) exch dup
(3913) exch dup
(3914) exch dup
(3915) exch dup
(3916) exch dup
(3917) exch dup
(3918) exch dup
(3919) exch dup
pop
 
[
<< /cset /N /min 1 /max 15 /check [] >>
]
(3920) exch dup
(3921) exch dup
(3922) exch dup
(3923) exch dup
(3924) exch dup
(3925) exch dup
(3926) exch dup
(3927) exch dup
(3928) exch dup
(3929) exch dup
pop
 
[
<< /cset /N /min 3 /max 3 /check [ /lintiso4217 ] >>
<< /cset /N /min 1 /max 15 /check [] >>
]
(3930) exch dup
(3931) exch dup
(3932) exch dup
(3933) exch dup
(3934) exch dup
(3935) exch dup
(3936) exch dup
(3937) exch dup
(3938) exch dup
(3939) exch dup
pop
 
[
<< /cset /N /min 4 /max 4 /check [] >>
]
(3940) exch dup
(3941) exch dup
(3942) exch dup
(3943) exch dup
pop
 
[
<< /cset /N /min 6 /max 6 /check [] >>
]
(3950) exch dup
(3951) exch dup
(3952) exch dup
(3953) exch dup
(3954) exch dup
(3955) exch dup
pop
 
[
<< /cset /X /min 1 /max 30 /check [] >>
]
(400) exch dup
pop
 
[
<< /cset /X /min 1 /max 30 /check [ /lintkey ] >>
]
(401) exch dup
pop
 
[
<< /cset /N /min 17 /max 17 /check [ /lintcsum /lintkey ] >>
]
(402) exch dup
pop
 
[
<< /cset /X /min 1 /max 30 /check [] >>
]
(403) exch dup
pop
 
[
<< /cset /N /min 13 /max 13 /check [ /lintcsum /lintkey ] >>
]
(410) exch dup
(411) exch dup
(412) exch dup
(413) exch dup
(414) exch dup
(415) exch dup
(416) exch dup
(417) exch dup
pop
 
[
<< /cset /X /min 1 /max 20 /check [] >>
]
(420) exch dup
pop
 
[
<< /cset /N /min 3 /max 3 /check [ /lintiso3166 ] >>
<< /cset /X /min 1 /max 9 /check [] >>
]
(421) exch dup
pop
 
[
<< /cset /N /min 3 /max 3 /check [ /lintiso3166 ] >>
]
(422) exch dup
pop
 
[
<< /cset /N /min 3 /max 15 /check [ /lintiso3166list ] >>
]
(423) exch dup
pop
 
[
<< /cset /N /min 3 /max 3 /check [ /lintiso3166 ] >>
]
(424) exch dup
pop
 
[
<< /cset /N /min 3 /max 15 /check [ /lintiso3166list ] >>
]
(425) exch dup
pop
 
[
<< /cset /N /min 3 /max 3 /check [ /lintiso3166 ] >>
]
(426) exch dup
pop
 
[
<< /cset /X /min 1 /max 3 /check [] >>
]
(427) exch dup
pop
 
[
<< /cset /X /min 1 /max 35 /check [ /lintpcenc ] >>
]
(4300) exch dup
(4301) exch dup
pop
 
[
<< /cset /X /min 1 /max 70 /check [ /lintpcenc ] >>
]
(4302) exch dup
(4303) exch dup
(4304) exch dup
(4305) exch dup
(4306) exch dup
pop
 
[
<< /cset /X /min 2 /max 2 /check [ /lintiso3166alpha2 ] >>
]
(4307) exch dup
pop
 
[
<< /cset /X /min 1 /max 30 /check [] >>
]
(4308) exch dup
pop
 
[
<< /cset /X /min 1 /max 35 /check [ /lintpcenc ] >>
]
(4310) exch dup
(4311) exch dup
pop
 
[
<< /cset /X /min 1 /max 70 /check [ /lintpcenc ] >>
]
(4312) exch dup
(4313) exch dup
(4314) exch dup
(4315) exch dup
(4316) exch dup
pop
 
[
<< /cset /X /min 2 /max 2 /check [ /lintiso3166alpha2 ] >>
]
(4317) exch dup
pop
 
[
<< /cset /X /min 1 /max 20 /check [] >>
]
(4318) exch dup
pop
 
[
<< /cset /X /min 1 /max 30 /check [] >>
]
(4319) exch dup
pop
 
[
<< /cset /X /min 1 /max 35 /check [ /lintpcenc ] >>
]
(4320) exch dup
pop
 
[
<< /cset /N /min 1 /max 1 /check [ /lintyesno ] >>
]
(4321) exch dup
(4322) exch dup
(4323) exch dup
pop
 
[
<< /cset /N /min 6 /max 6 /check [ /lintyymmd0 ] >>
<< /cset /N /min 4 /max 4 /check [ /linthhmm ] >>
]
(4324) exch dup
(4325) exch dup
pop
 
[
<< /cset /N /min 6 /max 6 /check [ /lintyymmdd ] >>
]
(4326) exch dup
pop
 
[
<< /cset /N /min 13 /max 13 /check [] >>
]
(7001) exch dup
pop
 
[
<< /cset /X /min 1 /max 30 /check [] >>
]
(7002) exch dup
pop
 
[
<< /cset /N /min 6 /max 6 /check [ /lintyymmdd ] >>
<< /cset /N /min 4 /max 4 /check [ /linthhmm ] >>
]
(7003) exch dup
pop
 
[
<< /cset /N /min 1 /max 4 /check [] >>
]
(7004) exch dup
pop
 
[
<< /cset /X /min 1 /max 12 /check [] >>
]
(7005) exch dup
pop
 
[
<< /cset /N /min 6 /max 6 /check [ /lintyymmdd ] >>
]
(7006) exch dup
pop
 
[
<< /cset /N /min 6 /max 6 /check [ /lintyymmdd ] >>
<< /cset /N /min 0 /max 6 /check [ /lintyymmdd ] >>
]
(7007) exch dup
pop
 
[
<< /cset /X /min 1 /max 3 /check [] >>
]
(7008) exch dup
pop
 
[
<< /cset /X /min 1 /max 10 /check [] >>
]
(7009) exch dup
pop
 
[
<< /cset /X /min 1 /max 2 /check [] >>
]
(7010) exch dup
pop
 
[
<< /cset /X /min 1 /max 20 /check [] >>
]
(7020) exch dup
(7021) exch dup
(7022) exch dup
pop
 
[
<< /cset /X /min 1 /max 30 /check [ /lintkey ] >>
]
(7023) exch dup
pop
 
[
<< /cset /N /min 3 /max 3 /check [ /lintiso3166999 ] >>
<< /cset /X /min 1 /max 27 /check [] >>
]
(7030) exch dup
(7031) exch dup
(7032) exch dup
(7033) exch dup
(7034) exch dup
(7035) exch dup
(7036) exch dup
(7037) exch dup
(7038) exch dup
(7039) exch dup
pop
 
[
<< /cset /N /min 1 /max 1 /check [] >>
<< /cset /X /min 1 /max 1 /check [] >>
<< /cset /X /min 1 /max 1 /check [] >>
<< /cset /X /min 1 /max 1 /check [ /lintimporteridx ] >>
]
(7040) exch dup
pop
 
[
<< /cset /X /min 1 /max 20 /check [] >>
]
(710) exch dup
(711) exch dup
(712) exch dup
(713) exch dup
(714) exch dup
(715) exch dup
pop
 
[
<< /cset /X /min 2 /max 2 /check [] >>
<< /cset /X /min 1 /max 28 /check [] >>
]
(7230) exch dup
(7231) exch dup
(7232) exch dup
(7233) exch dup
(7234) exch dup
(7235) exch dup
(7236) exch dup
(7237) exch dup
(7238) exch dup
(7239) exch dup
pop
 
[
<< /cset /X /min 1 /max 20 /check [] >>
]
(7240) exch dup
pop
 
[
<< /cset /N /min 4 /max 4 /check [ /lintnonzero ] >>
<< /cset /N /min 5 /max 5 /check [ /lintnonzero ] >>
<< /cset /N /min 3 /max 3 /check [ /lintnonzero ] >>
<< /cset /N /min 1 /max 1 /check [ /lintwinding ] >>
<< /cset /N /min 1 /max 1 /check [] >>
]
(8001) exch dup
pop
 
[
<< /cset /X /min 1 /max 20 /check [] >>
]
(8002) exch dup
pop
 
[
<< /cset /N /min 1 /max 1 /check [ /lintzero ] >>
<< /cset /N /min 13 /max 13 /check [ /lintcsum /lintkey ] >>
<< /cset /X /min 0 /max 16 /check [] >>
]
(8003) exch dup
pop
 
[
<< /cset /X /min 1 /max 30 /check [ /lintkey ] >>
]
(8004) exch dup
pop
 
[
<< /cset /N /min 6 /max 6 /check [] >>
]
(8005) exch dup
pop
 
[
<< /cset /N /min 14 /max 14 /check [ /lintcsum ] >>
<< /cset /N /min 4 /max 4 /check [ /lintpieceoftotal ] >>
]
(8006) exch dup
pop
 
[
<< /cset /X /min 1 /max 34 /check [ /lintiban ] >>
]
(8007) exch dup
pop
 
[
<< /cset /N /min 8 /max 8 /check [ /lintyymmddhh ] >>
<< /cset /N /min 0 /max 4 /check [ /lintmmoptss ] >>
]
(8008) exch dup
pop
 
[
<< /cset /X /min 1 /max 50 /check [] >>
]
(8009) exch dup
pop
 
[
<< /cset /C /min 1 /max 30 /check [ /lintkey ] >>
]
(8010) exch dup
pop
 
[
<< /cset /N /min 1 /max 12 /check [ /lintnozeroprefix ] >>
]
(8011) exch dup
pop
 
[
<< /cset /X /min 1 /max 20 /check [] >>
]
(8012) exch dup
pop
 
[
<< /cset /X /min 1 /max 25 /check [ /lintcsumalpha /lintkey ] >>
]
(8013) exch dup
pop
 
[
<< /cset /N /min 18 /max 18 /check [ /lintcsum ] >>
]
(8017) exch dup
(8018) exch dup
pop
 
[
<< /cset /N /min 1 /max 10 /check [] >>
]
(8019) exch dup
pop
 
[
<< /cset /X /min 1 /max 25 /check [] >>
]
(8020) exch dup
pop
 
[
<< /cset /N /min 14 /max 14 /check [ /lintcsum ] >>
<< /cset /N /min 4 /max 4 /check [ /lintpieceoftotal ] >>
]
(8026) exch dup
pop
 
[
<< /cset /X /min 1 /max 70 /check [ /lintcouponcode ] >>
]
(8110) exch dup
pop
 
[
<< /cset /N /min 4 /max 4 /check [] >>
]
(8111) exch dup
pop
 
[
<< /cset /X /min 1 /max 70 /check [ /lintcouponposoffer ] >>
]
(8112) exch dup
pop
 
[
<< /cset /X /min 1 /max 70 /check [] >>
]
(8200) exch dup
pop
 
[
<< /cset /X /min 1 /max 30 /check [] >>
]
(90) exch dup
pop
 
[
<< /cset /X /min 1 /max 90 /check [] >>
]
(91) exch dup
(92) exch dup
(93) exch dup
(94) exch dup
(95) exch dup
(96) exch dup
(97) exch dup
(98) exch dup
(99) exch dup
pop
 
>> def
 
true
0 1 vals length 1 sub {
dup ais exch get /ai exch def
vals exch get /val exch def
gs1syntax ai known {
gs1syntax ai get { % For each element of the AI
/props exch def
props /max get val length 2 copy gt {exch} if pop
val exch 0 exch getinterval /eval exch def
/val val eval length dup val length exch sub getinterval def
eval length props /min get lt {
pop /bwipp.GS1valueTooShort (Too short) false exit
} if
<< /N /lintnumeric /X /lintcset82 /C /lintcset39 >> props /cset get get eval exch load exec
eval length 0 gt {
props /check get { eval exch load exec } forall
} if
} forall
dup not {exit} if
val length 0 ne {
pop /bwipp.GS1valueTooLong (Too long) false exit
} if
} {
pop /bwipp.GS1unknownAI (Unrecognised AI) false exit
} ifelse
} for
not {
dup length ai length add 5 add string
dup 0 (AI ) putinterval
dup 3 ai putinterval
dup 3 ai length add (: ) putinterval
dup 5 ai length add 4 -1 roll putinterval
//raiseerror exec
} if
true
 
end
 
}
[/barcode] {null def} forall
bind def
/gs1lint dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END RESOURCE gs1lint--
 
% --BEGIN RENDERER renlinear--
% --REQUIRES preamble raiseerror--
%%BeginResource: uk.co.terryburton.bwipp renlinear 0.0 2018020400 85663 81483
%%BeginData: 237 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp renlinear 0.0 2021092800 74624 73842
%%BeginData: 239 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
114,10 → 1935,10
/guardrightypos 0 def
/guardwidth 6 def
/guardheight 7 def
 
% Apply the renderer options and the user options
args {def} forall
opt {def} forall
opt {def} forall
 
/barcolor barcolor cvlit def
/textcolor textcolor cvlit def
146,7 → 1967,7
/guardrightypos guardrightypos cvr def
/guardwidth guardwidth cvr def
/guardheight guardheight cvr def
 
% Create bar elements and put them into the bars array
/bars sbs length 1 add 2 idiv array def
/x 0.00 def /maxh 0 def
165,7 → 1986,7
bars i 2 idiv -1 put % Dummy entry
} ifelse
} {
/d sbs i get spaceratio mul spaceratio sub 1 add def % d=digit*r-r+1
/d sbs i get spaceratio mul spaceratio sub 1 add def % d=digit*r-r+1
} ifelse
/x x d add def % x+=d
} for
196,16 → 2017,16
x borderleft add borderright add 0 rlineto
0 maxh borderbottom add bordertop add rlineto
x borderleft add borderright add neg 0 rlineto
0 maxh borderbottom add bordertop add neg rlineto
0 maxh borderbottom add bordertop add neg rlineto
closepath
backgroundcolor (unset) ne { gsave backgroundcolor setanycolor fill grestore } if
backgroundcolor (unset) ne { gsave backgroundcolor setanycolor fill grestore } if
showborder {
gsave
bordercolor (unset) ne { bordercolor setanycolor } if
borderwidth setlinewidth stroke
grestore
} if
} if
 
% Display the bars for elements in the bars array
gsave
0 setlinecap
218,7 → 2039,7
} ifelse
} forall
grestore
 
% Display the text for elements in the text array
textcolor (unset) ne { textcolor setanycolor } if
includetext {
277,7 → 2098,7
textyalign (center) eq { /textypos textyoffset maxh textascent sub 2 div add def } if
textxpos textypos moveto textgaps 0 tstr ashow
} ifelse
} if
} if
 
% Display the guard elements
guardwhitespace {
287,7 → 2108,7
guardleftpos neg guardwidth add guardleftypos guardwidth 2 div add moveto
guardwidth neg guardheight -2 div rlineto
guardwidth guardheight -2 div rlineto
stroke
stroke
} if
guardrightpos 0 ne {
newpath
294,15 → 2115,17
guardrightpos x add guardwidth sub guardrightypos guardheight 2 div add moveto
guardwidth guardheight -2 div rlineto
guardwidth neg guardheight -2 div rlineto
stroke
stroke
} if
} if
 
grestore
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/renlinear dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
312,8 → 2135,8
 
% --BEGIN RENDERER renmatrix--
% --REQUIRES preamble raiseerror--
%%BeginResource: uk.co.terryburton.bwipp renmatrix 0.0 2018020400 108321 107254
%%BeginData: 333 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp renmatrix 0.0 2021092800 90671 89573
%%BeginData: 306 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
330,6 → 2153,7
/barcolor (unset) def
/backgroundcolor (unset) def
/colormap (unset) def
/dotty false def
/inkspread 0 def
/inkspreadh 0 def
/inkspreadv 0 def
369,115 → 2193,56
inkspread 0 ne {/inkspreadh inkspread def} if
inkspread 0 ne {/inkspreadv inkspread def} if
 
/xyget { pixx mul add pixs exch get } bind def
/xyinvert { pixx mul add pixs exch 2 copy get 1 xor put } bind def
/mxyget { pixx mul add m exch get 2#001 and } bind def
/mxyset { pixx mul add m exch 3 -1 roll put } bind def
/msetborder { pixx mul add m exch 2 copy get 2#010 or put } bind def
/mborderoff { pixx mul add m exch 2 copy get 2#100 or put } bind def
/misborder { pixx mul add m exch get 2#110 and 2#010 eq } bind def
/mclear { pixx mul add m exch 2 copy get 2#001 and put } bind def
/mclear4 {
2 copy mclear
2 copy 1 add mclear
2 copy exch 1 add exch mclear
2 copy exch 1 add exch mclear
1 add exch 1 add exch mclear
/xyget { pixx mul add pixs exch get} bind def
/cget { pixx mul add cache exch get and} bind def
/cput { % Optimise by only storing "stem" corners
dup 4 mod 0 eq { % dir is up or left
3 1 roll pixx mul add cache exch 2 copy get 4 -1 roll or put
} {
pop pop pop
} ifelse
} bind def
 
/abcd {
4 string 0 [
5 -2 roll
pixx mul add dup
pixs exch 2 getinterval aload pop 3 -1 roll % A B
pixs exch pixx add 2 getinterval aload pop % C D
] {3 copy 48 add put pop 1 add} forall pop
} bind def
 
/right {dir 1 ne {x y dir cput [x y]} if /x x 1 add def /dir 1 def} bind def
/down {dir 2 ne {x y dir cput [x y]} if /y y 1 add def /dir 2 def} bind def
/left {dir 4 ne {x y dir cput [x y]} if /x x 1 sub def /dir 4 def} bind def
/up {dir 8 ne {x y dir cput [x y]} if /y y 1 sub def /dir 8 def} bind def
 
/trace {
% Walk the outline of a region emitting edge coordinates of the path
/y exch def /x exch def
% dir 0:right 1:down 2:left 3:up
% hug 0:right 1:left
/dir x 1 add y 1 add mxyget def /hug dir def
% dir 1:right 2:down 4:left 8:up
/dir x 1 add y 1 add xyget 1 eq {8} {4} ifelse def
/sx x def /sy y def /sdir dir def
mark [x y] {
x 1 add y
x 1 add y 1 add
x y 1 add
x y
8 dir 2 mul neg roll
/Dy exch def /Dx exch def /D Dx Dy xyget def
/Cy exch def /Cx exch def /C Cx Cy xyget def
/By exch def /Bx exch def /B Bx By xyget def
/Ay exch def /Ax exch def /A Ax Ay xyget def
A B eq {
A C eq {/L} {/R} ifelse
} {
A C eq B D eq and {
A 0 eq hug 0 eq xor {/R} {/F} ifelse
} {
/F
 
% A B
% C D
mark {
x y abcd
1 { % Common exit
dup dup (0001) eq exch dup (0011) eq exch (1011) eq or or {pop right exit} if
dup dup (0010) eq exch dup (1010) eq exch (1110) eq or or {pop down exit} if
dup dup (1000) eq exch dup (1100) eq exch (1101) eq or or {pop left exit} if
dup dup (0100) eq exch dup (0101) eq exch (0111) eq or or {pop up exit} if
dup (1001) eq {
dir 2 eq {pop left exit} {pop right exit} ifelse
} { % 0110
dir 1 eq {pop down exit} {pop up exit} ifelse
} ifelse
} ifelse
dup /F eq {
pop
dir 0 eq {/x x 1 add def} if
dir 1 eq {/y y 1 add def} if
dir 2 eq {/x x 1 sub def} if
dir 3 eq {/y y 1 sub def} if
hug 0 eq {
Ax Ay msetborder
} {
Bx By msetborder
} ifelse
} {
/L eq {
/dir dir 3 add 4 mod def
hug 1 eq {
Bx By msetborder
Dx Dy mborderoff
} if
} { % R
/dir dir 1 add 4 mod def
hug 0 eq {
Ax Ay msetborder
Cx Cy mborderoff
} if
} ifelse
[x y]
} ifelse
} repeat
x sx eq y sy eq and dir sdir eq and {exit} if
} loop
counttomark array astore exch pop
 
% Invert the interior of the path
/x x 1 add def /y y 1 add def
/t x y mxyget 1 xor def
mark x y {
counttomark 0 eq {exit} if
/y exch def /x exch def
x y mxyget t ne {
0 x 1 sub -1 0 {dup y misborder {exch pop exit} if pop} for
pixx 1 sub x 1 add 1 pixx 1 sub {dup y misborder {exch pop exit} if pop} for
1 exch { % From left to right border
/i exch def
i y misborder not {
t i y mxyset
i y xyinvert
} if
i y 1 sub mxyget t ne i y 1 sub misborder not and {i y 1 sub} if
i y 1 add mxyget t ne i y 1 add misborder not and {i y 1 add} if
} for
} if
} loop
pop
 
% Walk the path to clear the border information
dup 0 get aload pop /y1 exch def /x1 exch def
dup dup length 1 sub 1 exch getinterval {
aload pop /y2 exch def /x2 exch def
x2 x1 gt { x1 2 x2 1 sub {y1 mclear4} for } if
y2 y1 gt { y1 2 y2 1 sub {x1 exch mclear4} for } if
x2 x1 lt { x1 -2 x2 1 add {y1 mclear4} for } if
y2 y1 lt { y1 -2 y2 1 add {x1 exch mclear4} for } if
/x1 x2 def /y1 y2 def
} forall
 
% Discard duplicate final point
dup length 1 sub 0 exch getinterval
 
} bind def
 
% Set RGB or CMYK color depending on length of given hex string
510,18 → 2275,26
/pixx pixx 2 add def
/pixy pixy 2 add def
 
% Track inverted regions and working space
/m [ pixs length {0} repeat ] def
% Cache of visited corners for each direction
/cache [ pixs length {0} repeat ] def
 
% Construct paths by tracing and inverting each dark region
% Construct paths by tracing regions avoiding duplication by using the cache
/paths [
0 1 pixy 1 sub {
0 1 pixy 2 sub {
/j exch def
0 1 pixx 1 sub {
0 1 pixx 2 sub {
/i exch def
i j xyget 1 eq {
i 1 sub j 1 sub trace
/k i j abcd def
k (0001) eq k (1001) eq or { % Black region stem corners
8 i j cget 0 eq {
i j trace
} if
} if
k (1110) eq { % White region stem corner
4 i j cget 0 eq {
i j trace
} if
} if
} for
} for
] def
557,9 → 2330,30
 
} bind def
 
/drawlayerdots {
 
/pixsorig pixs def
/pixs exch def
 
newpath
0 1 pixs length 1 sub {
dup pixx mod /x exch def
pixx idiv /y exch def
x y xyget 1 eq {
x 0.5 add pixy y sub 0.5 sub moveto
x 0.5 add pixy y sub 0.5 sub 0.5 inkspread sub 0 360 arc
} if
} for
fill
 
/pixs pixsorig def
 
} bind def
 
gsave
 
% Draw the image
/inkspread inkspread 2 div def
/inkspreadh inkspreadh 2 div def
/inkspreadv inkspreadv 2 div def
currentpoint translate
576,7 → 2370,7
/key exch def
[
pixs { key eq {1} {0} ifelse } forall
] drawlayer
] dotty {drawlayerdots} {drawlayer} ifelse
} forall
 
% Display the text for elements in the text array
643,7 → 2437,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/renmatrix dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
653,8 → 2449,8
 
% --BEGIN RENDERER renmaximatrix--
% --REQUIRES preamble raiseerror--
%%BeginResource: uk.co.terryburton.bwipp renmaximatrix 0.0 2018020400 55677 52149
%%BeginData: 79 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp renmaximatrix 0.0 2021092800 50254 49916
%%BeginData: 81 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
730,7 → 2526,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/renmaximatrix dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
744,8 → 2542,8
% --EXAM: 90200
% --EXOP: includetext guardwhitespace
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp ean5 0.0 2018020400 65550 65357
%%BeginData: 135 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp ean5 0.0 2021092800 58142 57964
%%BeginData: 137 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
764,8 → 2562,8
/textsize 12 def
/textxoffset 0 def
/textyoffset (unset) def
/height 0.7 def
/height 0.7 def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
775,8 → 2573,8
} loop
currentdict end /options exch def
} if
options {def} forall
options {def} forall
 
/textfont textfont cvlit def
/textsize textsize cvr def
/height height cvr def
796,7 → 2594,7
/bwipp.ean5badCharacter (EAN-5 add-on must contain only digits) //raiseerror exec
} if
} forall
 
% Create an array containing the character mappings
/encs
[ (3211) (2221) (2122) (1411) (1132)
827,7 → 2625,7
 
/sbs 31 string def
/txt 5 array def
 
0 1 4 {
/i exch def
 
877,7 → 2675,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/ean5 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
891,8 → 2691,8
% --EXAM: 05
% --EXOP: includetext guardwhitespace
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp ean2 0.0 2018020400 63867 63619
%%BeginData: 120 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp ean2 0.0 2021092800 56699 56466
%%BeginData: 122 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
912,7 → 2712,7
/textxoffset 0 def
/textyoffset (unset) def
/height 0.7 def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
923,7 → 2723,7
currentdict end /options exch def
} if
options {def} forall
 
/textfont textfont cvlit def
/textsize textsize cvr def
/height height cvr def
943,7 → 2743,7
/bwipp.ean2badCharacter (EAN-2 add-on must contain only digits) //raiseerror exec
} if
} forall
 
% Create an array containing the character mappings
/encs
[ (3211) (2221) (2122) (1411) (1132)
959,7 → 2759,7
 
/sbs 13 string def
/txt 2 array def
 
0 1 1 {
/i exch def
 
976,7 → 2776,7
length /indx exch def % indx is the length of pre
pop pop % Discard seek and post
/enc encs indx get def % Get the indxth encoding
mirrormap i get 49 eq { % Reverse enc if 1 in this position in mirrormap
mirrormap i get 49 eq { % Reverse enc if 1 in this position in mirrormap
/enclen enc length def
/revenc enclen string def
0 1 enclen 1 sub {
1009,7 → 2809,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/ean2 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
1023,8 → 2825,8
% --EXAM: 2112345678900
% --EXOP: includetext guardwhitespace
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp ean13 0.0 2018020400 91601 94632
%%BeginData: 215 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp ean13 0.0 2021092800 77528 80639
%%BeginData: 217 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
1068,7 → 2870,7
/textxoffset textxoffset cvr def
/textyoffset textyoffset cvr def
/height height cvr def
/addongap addongap cvr def
/addongap addongap cvr def
addontextfont (unset) ne {/addontextfont addontextfont cvlit def} if
addontextsize (unset) ne {/addontextsize addontextsize cvr def} if
addontextxoffset (unset) ne {/addontextxoffset addontextxoffset cvr def} if
1137,7 → 2939,7
 
/sbs 59 string def
/txt 13 array def
 
% Put the start character
sbs 0 encs 10 get putinterval
 
1217,8 → 3019,8
/bbs [bbs aload pop addcode (bbs) get {.075 add} forall] def
/txt [txt aload pop addcode (txt) get aload pop] def
/guardrightypos height 72 mul 6 sub def
} if
} if
 
% Return the arguments
<<
/ren //renlinear
1236,7 → 3038,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/ean13 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
1250,8 → 3054,8
% --EXAM: 02345673
% --EXOP: includetext guardwhitespace
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp ean8 0.0 2018020400 88151 91083
%%BeginData: 196 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp ean8 0.0 2021092800 74726 77866
%%BeginData: 198 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
1278,7 → 3082,7
/addontextsize (unset) def
/addontextxoffset (unset) def
/addontextyoffset (unset) def
 
% Parse the input options, either a string or a dict
options type /stringtype eq {
1 dict begin
1289,7 → 3093,7
currentdict end /options exch def
} if
options {def} forall
 
/textfont textfont cvlit def
/textsize textsize cvr def
/textxoffset textxoffset cvr def
1345,7 → 3149,7
pad 0 barcode putinterval % Add barcode to the start of the pad
pad 7 checksum 48 add put % Put ascii for checksum at end of pad
/barcode pad def
 
% Create an array containing the character mappings
/encs
[ (3211) (2221) (2122) (1411) (1132)
1358,7 → 3162,7
 
/sbs 43 string def
/txt 8 array def
 
% Put the start character
sbs 0 encs 10 get putinterval
 
1424,7 → 3228,7
/bbs [bbs aload pop addcode (bbs) get {.075 add} forall] def
/txt [txt aload pop addcode (txt) get aload pop] def
/guardrightypos height 72 mul 6 sub def
} if
} if
 
% Return the arguments
<<
1444,7 → 3248,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/ean8 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
1458,8 → 3264,8
% --EXAM: 416000336108
% --EXOP: includetext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp upca 0.0 2018020400 97138 100087
%%BeginData: 248 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp upca 0.0 2021092800 82465 85414
%%BeginData: 250 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
1480,7 → 3286,7
/textsize 12 def
/textxoffset -7 def
/textyoffset -4 def
/height 1 def
/height 1 def
/addongap 12 def
/addontextfont (unset) def
/addontextsize (unset) def
1496,7 → 3302,7
} loop
currentdict end /options exch def
} if
options {def} forall
options {def} forall
 
/textfont textfont cvlit def
/textsize textsize cvr def
1576,7 → 3382,7
addon length 0 ne addon length 2 ne and addon length 5 ne and {
/bwipp.upcAbadAddOnLength (Add-on for UPC-A must be 2 or 5 digits) //raiseerror exec
} if
 
% Add checksum digit to barcode
/pad 12 string def % Create pad one bigger than barcode
/checksum 0 def
1685,7 → 3491,7
/bbs [bbs aload pop addcode (bbs) get {.075 add} forall] def
/txt [txt aload pop addcode (txt) get aload pop] def
/guardrightypos height 72 mul 6 sub def
} if
} if
 
% Return the arguments
<<
1704,7 → 3510,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/upca dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
1718,8 → 3526,8
% --EXAM: 00123457
% --EXOP: includetext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp upce 0.0 2018020400 102967 109183
%%BeginData: 287 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp upce 0.0 2021092800 87070 90062
%%BeginData: 289 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
1746,7 → 3554,7
/addontextsize (unset) def
/addontextxoffset (unset) def
/addontextyoffset (unset) def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
1757,7 → 3565,7
currentdict end /options exch def
} if
options {def} forall
 
/textfont textfont cvlit def
/textsize textsize cvr def
/textxoffset textxoffset cvr def
1935,7 → 3743,7
length /indx exch def % indx is the length of pre
pop pop % Discard seek and post
/enc encs indx get def % Get the indxth encoding
mirrormap i 1 sub get 49 eq { % Reverse enc if 1 in this position in mirrormap
mirrormap i 1 sub get 49 eq { % Reverse enc if 1 in this position in mirrormap
/enclen enc length def
/revenc enclen string def
0 1 enclen 1 sub {
2003,7 → 3811,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/upce dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
2014,11 → 3824,11
% --BEGIN ENCODER isbn--
% --REQUIRES preamble raiseerror renlinear ean5 ean2 ean13--
% --DESC: ISBN
% --EXAM: 978-1-56581-231-4 52250
% --EXAM: 978-1-56581-231-4 90000
% --EXOP: includetext guardwhitespace
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp isbn 0.0 2018020400 104089 106810
%%BeginData: 252 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp isbn 0.0 2021092800 89478 88857
%%BeginData: 254 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
2039,9 → 3849,9
/isbntextxoffset (unset) def
/isbntextyoffset (unset) def
/height 1 def
/addongap 12 def
/addongap 12 def
/legacy false def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
2052,7 → 3862,7
currentdict end /options exch def
} if
options {def} forall
 
/isbntextfont isbntextfont cvlit def
/isbntextsize isbntextsize cvr def
isbntextxoffset (unset) ne {/isbntextxoffset isbntextxoffset cvr def} if
2220,7 → 4030,7
 
% Convert ISBN digits to EAN-13
/barcode 12 string def
isbn length 9 eq {
isbn length 9 eq {
barcode 0 (978) putinterval
barcode 3 isbn putinterval
} {
2229,7 → 4039,7
 
% Append the addon
addon () ne {
12 addon length add 1 add string
12 addon length add 1 add string
dup 0 barcode putinterval
dup 12 ( ) putinterval
dup 13 addon putinterval
2238,7 → 4048,7
 
% Get the result of encoding with ean13
options (dontdraw) true put
options (addongap) addongap put
options (addongap) addongap put
/args barcode options //ean13 exec def
 
% Add the ISBN text
2266,8 → 4076,10
dontdraw not //renlinear if
 
end
} bind def
 
}
[/barcode] {null def} forall
bind def
/isbn dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
2281,8 → 4093,8
% --EXAM: 979-0-2605-3211-3
% --EXOP: includetext guardwhitespace
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp ismn 0.0 2018020400 99933 102747
%%BeginData: 231 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp ismn 0.0 2021092800 85922 85418
%%BeginData: 233 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
2303,7 → 4115,7
/ismntextxoffset (unset) def
/ismntextyoffset (unset) def
/height 1 def
/addongap 12 def
/addongap 12 def
/legacy false def
 
% Parse the input options
2316,7 → 4128,7
currentdict end /options exch def
} if
options {def} forall
 
/ismntextfont ismntextfont cvlit def
/ismntextsize ismntextsize cvr def
ismntextxoffset (unset) ne {/ismntextxoffset ismntextxoffset cvr def} if
2323,7 → 4135,7
ismntextyoffset (unset) ne {/ismntextyoffset ismntextyoffset cvr def} if
/height height cvr def
/addongap addongap cvr def
 
% Split off the addon
barcode ( ) search {
/barcode exch def
2468,11 → 4280,11
/ismntxt pad def
 
% Convert ISMN digits to EAN-13
/barcode ismn 0 12 getinterval def
/barcode ismn 0 12 getinterval def
 
% Append the addon
addon () ne {
12 addon length add 1 add string
12 addon length add 1 add string
dup 0 barcode putinterval
dup 12 ( ) putinterval
dup 13 addon putinterval
2481,7 → 4293,7
 
% Get the result of encoding with ean13
options (dontdraw) true put
options (addongap) addongap put
options (addongap) addongap put
/args barcode options //ean13 exec def
 
% Add the ISMN text
2509,8 → 4321,10
dontdraw not //renlinear if
 
end
} bind def
 
}
[/barcode] {null def} forall
bind def
/ismn dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
2524,8 → 4338,8
% --EXAM: 0311-175X 00 17
% --EXOP: includetext guardwhitespace
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp issn 0.0 2018020400 89245 88647
%%BeginData: 176 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp issn 0.0 2021092800 77354 76846
%%BeginData: 178 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
2546,7 → 4360,7
/issntextxoffset (unset) def
/issntextyoffset (unset) def
/height 1 def
/addongap 12 def
/addongap 12 def
 
% Parse the input options
options type /stringtype eq {
2558,7 → 4372,7
currentdict end /options exch def
} if
options {def} forall
 
/issntextfont issntextfont cvlit def
/issntextsize issntextsize cvr def
issntextxoffset (unset) ne {/issntextxoffset issntextxoffset cvr def} if
2652,7 → 4466,7
/issntxt pad def
 
% Convert ISSN digits to EAN-13
/barcode issn 0 7 getinterval def
/barcode issn 0 7 getinterval def
 
% Append the sequence variant
/barcode 12 string def
2662,7 → 4476,7
 
% Append the addon
addon () ne {
12 addon length add 1 add string
12 addon length add 1 add string
dup 0 barcode putinterval
dup 12 ( ) putinterval
dup 13 addon putinterval
2671,7 → 4485,7
 
% Get the result of encoding with ean13
options (dontdraw) true put
options (addongap) addongap put
options (addongap) addongap put
/args barcode options //ean13 exec def
 
% Add the ISSN text
2698,7 → 4512,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/issn dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
2706,17 → 4522,112
%%EndResource
% --END ENCODER issn--
 
% --BEGIN ENCODER mands--
% --REQUIRES preamble raiseerror renlinear ean2 ean5 ean8--
% --DESC: Marks & Spencer
% --EXAM: 0642118
% --EXOP: includetext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp mands 0.0 2021092800 66033 65940
%%BeginData: 82 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
dup /ean8 dup /uk.co.terryburton.bwipp findresource put
begin
/mands {
 
20 dict begin
 
/options exch def
/barcode exch def
 
/dontdraw false def
/includetext false def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
options {
token false eq {exit} if dup length string cvs (=) search
true eq {cvlit exch pop exch def} {cvlit true def} ifelse
} loop
currentdict end /options exch def
} if
options {def} forall
 
/barlen barcode length def
 
% Validate the input
barlen 7 ne barlen 8 ne and {
/bwipp.MandSbadLength (M&S barcode must be 7 or 8 characters) //raiseerror exec
} if
 
barlen 7 eq {
/barcode (00000000) 8 string copy dup 1 barcode putinterval def
} if
 
% Get the result of encoding with ean8
options (dontdraw) true put
/args barcode options //ean8 exec def
 
% Remove the centre guard
args (bbs) get dup
dup 2 get 10 exch put
dup 2 get 11 exch put
args (bhs) get dup
dup 2 get 10 exch put
dup 2 get 11 exch put
 
% Fix up the text for 7-digit inputs
/txt args (txt) get def
barlen 7 eq {
0 1 6 {
txt exch 2 copy
1 add get 0 get 3 1 roll get
0 get exch 0 exch putinterval
} for
txt 7 get 0 get 0 ( ) putinterval
} if
 
% Add the M and S guards
10 array dup 0 txt putinterval /txt exch def
txt 0 get dup length array copy txt exch 8 exch put
txt 0 get dup length array copy txt exch 9 exch put
txt 8 get 0 (M) put txt 8 get 1 -12 put
txt 9 get 0 (S) put txt 9 get 1 69 put
 
args (txt) txt put
args (opt) options put
args
 
dontdraw not //renlinear if
 
end
 
}
[/barcode] {null def} forall
bind def
/mands dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER mands--
 
% --BEGIN ENCODER code128--
% --REQUIRES preamble raiseerror renlinear--
% --REQUIRES preamble raiseerror parseinput renlinear--
% --DESC: Code 128
% --EXAM: Count01234567!
% --EXOP: includetext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp code128 0.0 2018020400 139931 142645
%%BeginData: 455 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp code128 0.0 2021092800 120207 119811
%%BeginData: 425 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/code128 {
2755,40 → 4666,32
/textyoffset textyoffset cvr def
/height height cvr def
 
% Parse ordinals of the form ^NNN to ASCII
parse {
/msg barcode length string def
/j 0 def
barcode
{ % loop
(^) search {
dup msg exch j exch putinterval
length j add 1 add /j exch def
pop
dup 0 3 getinterval cvi msg exch j 1 sub exch put
dup length 3 sub 3 exch getinterval
} {
dup msg exch j exch putinterval
length j add /j exch def
/barcode msg 0 j getinterval def
exit
} ifelse
} loop
} if
 
/barlen barcode length def
 
% Special function characters
/sta -1 def /stb -2 def /stc -3 def
/swa -4 def /swb -5 def /swc -6 def
/fn1 -7 def /fn2 -8 def /fn3 -9 def
/sta -1 def /stb -2 def /stc -3 def
/swa -4 def /swb -5 def /swc -6 def
/fn1 -7 def /fn2 -8 def /fn3 -9 def
/fn4 -10 def /sft -11 def /stp -12 def
/lka -13 def /lkc -14 def % CC-A/B and CC-C linkage
 
% Parse the input
/fncvals <<
/parse parse
/parsefnc parsefnc
(FNC1) fn1
(FNC1) fn1
(FNC2) fn2
(FNC3) fn3
% (FNC4) fn4 Not user accessible as encoded automatically
(LNKA) lka
(LNKC) lkc
>> def
/msg barcode fncvals //parseinput exec def
/msglen msg length def
 
% Character maps for each state
/charmaps [
% A B C A B C A B C
[ 32 32 (00) ] [ (!) (!) (01) ] [ (") (") (02) ] % 0-2
[ 32 32 (00) ] [ (!) (!) (01) ] [ (") (") (02) ] % 0-2
[ (#) (#) (03) ] [ ($) ($) (04) ] [ (%) (%) (05) ] % 3-5
[ (&) (&) (06) ] [ (') (') (07) ] [ 40 40 (08) ] % 6-8
[ 41 41 (09) ] [ (*) (*) (10) ] [ (+) (+) (11) ] % 9-11
2824,8 → 4727,8
[ swc swc (99) ] [ swb fn4 swb ] [ fn4 swa swa ] % 99-101
[ fn1 fn1 fn1 ] [ sta sta sta ] [ stb stb stb ] % 102-104
[ stc stc stc ] [ stp stp stp ] % 105-106
] def
] def
 
% Invert charmaps to give character to value maps for each state
/charvals [ 109 dict 109 dict 109 dict ] def
0 1 charmaps length 1 sub {
2834,7 → 4737,7
0 1 2 {
/j exch def
encs j get dup type /stringtype eq {0 get} if % convert string to ASCII if required
charvals j get exch i put
charvals j get exch i put
} for
} for
/seta charvals 0 get def
2849,10 → 4752,10
raw {/encoding (raw) def} if
 
encoding (raw) eq {
/cws barlen array def
/cws barcode length array def
/i 0 def /j 0 def
{ % loop
i barlen eq {exit} if
i barcode length eq {exit} if
/cw barcode i 1 add 3 getinterval cvi def
cws j cw put
/i i 4 add def
2862,41 → 4765,14
/text () def
} if
 
encoding (auto) eq {
encoding (auto) eq {
 
/fncvals <<
(FNC1) fn1
(FNC2) fn2
(FNC3) fn3
% (FNC4) fn4 Not user accessible as encoded automatically
(LNKA) lka
(LNKC) lkc
>> def
/text msglen string def
0 1 msglen 1 sub {
/i exch def
text i msg i get dup 0 lt { pop 32 } if put
} for
 
% Convert input into bytes accounting for FNC and LNK characters
/msg barlen array def
/text barlen string def
/i 0 def /j 0 def {
i barlen eq {exit} if
/char barcode i get def
text j char put
parsefnc char 94 eq and i barlen 4 sub lt and {
barcode i 1 add get 94 ne {
/char fncvals barcode i 1 add 4 getinterval get def
text j ( ) putinterval
/i i 4 add def
} {
/i i 1 add def
} ifelse
} if
msg j char put
/i i 1 add def
/j j 1 add def
} loop
/msg msg 0 j getinterval def
/msglen msg length def
/text text 0 j getinterval def
 
% Standard and extended ASCII runlength at position
/numSA [ msglen {0} repeat 0 ] def
/numEA [ msglen {0} repeat 0 ] def
2938,10 → 4814,12
p msglen ge {exit} if
msg p get
dup setc exch known not {pop exit} if
fn1 eq {
dup -1 le {
% FNC1 in odd position of run like two digits
s 2 mod 0 eq {/s s 1 add def} {exit} ifelse
} if
fn1 eq s 2 mod 0 eq and {/s s 1 add def} {exit} ifelse
} {
pop
} ifelse
/n n 1 add def
/s s 1 add def
/p p 1 add def
2992,7 → 4870,7
% Does a-only come before b-only after given position and vice versa
/abeforeb {dup nextanotb exch get exch nextbnota exch get lt} bind def
/bbeforea {dup nextbnota exch get exch nextanotb exch get lt} bind def
 
/cws barcode length 2 mul 3 add array def
 
% Select start character
3014,11 → 4892,11
/cset (setc) def
exit
} if
0 abeforeb {
0 abeforeb {
sta enca
/cset (seta) def
exit
} if
exit
} if
stb enca
/cset (setb) def
exit
3025,14 → 4903,14
} loop
 
% Main encoding loop
/i 0 def {
/i 0 def {
i msglen eq {exit} if
 
i numsscr /nums exch def /nchars exch def
 
% Determine switches and shifts
{ % common exit
cset (seta) eq cset (setb) eq or nums 4 ge and
cset (seta) eq cset (setb) eq or nums 4 ge and
msg i get fn1 ne and {
nums 2 mod 0 eq {
swc cset (seta) eq {enca} {encb} ifelse
3046,9 → 4924,9
exit
} ifelse
} if
cset (setb) eq msg i get anotb and {
cset (setb) eq msg i get anotb and {
i msglen 1 sub lt {
i 1 add bbeforea {
i 1 add bbeforea {
sft encb
msg i get enca
/i i 1 add def
3072,7 → 4950,7
/cset (setb) def
exit
} if
cset (setc) eq nums 2 lt and {
cset (setc) eq nums 2 lt and msg i get -1 gt and {
i abeforeb {
swa encc
/cset (seta) def
3082,7 → 4960,7
/cset (setb) def
exit
} if
 
% No switches or latches so encode
cset (seta) eq {
msg i get enca
3095,19 → 4973,19
exit
} if
cset (setc) eq {
msg i get fn1 eq {
fn1 encc
msg i get -1 le {
msg i get encc
/i i 1 add def
} {
msg i 2 getinterval encc
/i i 2 add def
/i i 2 add def
} ifelse
exit
} if
 
exit
} loop
 
} loop
/cws cws 0 j getinterval def
} if % auto encoding
3165,7 → 5043,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/code128 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
3174,16 → 5054,18
% --END ENCODER code128--
 
% --BEGIN ENCODER gs1-128--
% --REQUIRES preamble raiseerror renlinear code128--
% --REQUIRES preamble raiseerror parseinput gs1lint renlinear code128--
% --DESC: GS1-128
% --EXAM: (01)95012345678903(3103)000123
% --EXOP: includetext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp gs1-128 0.0 2018020400 80021 79624
%%BeginData: 158 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp gs1-128 0.0 2021092800 81345 84637
%%BeginData: 156 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /gs1lint dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
dup /code128 dup /uk.co.terryburton.bwipp findresource put
begin
3203,7 → 5085,9
/height 0.5 def
/linkagea false def
/linkagec false def
/parse false def
/dontlint false def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
3219,29 → 5103,18
/textsize textsize cvr def
/textxoffset textxoffset cvr def
/textyoffset textyoffset cvr def
/height height cvr def
/height height cvr def
 
/text barcode def
 
% Expand ordinals of the form ^NNN to ASCII
/expand {
/in exch def
/out in length string def
/j 0 def
in
{ % loop
(^) search {
dup out exch j exch putinterval
length j add 1 add /j exch def
pop
dup 0 3 getinterval cvi out exch j 1 sub exch put
dup length 3 sub 3 exch getinterval
} {
dup out exch j exch putinterval
length j add /j exch def
out 0 j getinterval exit
} ifelse
} loop
/fncvals <<
/parse parse
/parseonly true
/parsefnc false
>> def
fncvals //parseinput exec
} bind def
 
% Parse out AIs
3263,6 → 5136,8
} loop
pop
 
dontlint not { ais vals //gs1lint exec pop } if
 
% Pre-defined fixed length data field AIs
% any AI whose prefix is not included in this table must be
% terminated with "FNC1", even if it's fixed length
3281,7 → 5156,7
10 2 string cvrs dup aifixed 3 1 roll put
} forall
 
% Create the code128 data
% Create the code128 data
/fnc1 -1 def
/c128 [ fnc1 ] def
0 1 ais length 1 sub {
3321,6 → 5196,7
/barcode barcode 0 j getinterval def
 
% Get the result of encoding with code128
options (parse) undef
options (height) height put
options (dontdraw) true put
options (parsefnc) true put
3330,12 → 5206,14
args (textxalign) (center) put
args (opt) options put
args
 
dontdraw not //renlinear if
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/gs1-128 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
3344,13 → 5222,13
% --END ENCODER gs1-128--
 
% --BEGIN ENCODER ean14--
% --REQUIRES preamble raiseerror renlinear code128--
% --REQUIRES preamble raiseerror parseinput renlinear code128--
% --DESC: GS1-14
% --EXAM: (01) 0 46 01234 56789 3
% --EXOP: includetext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp ean14 0.0 2018020400 71196 70896
%%BeginData: 105 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp ean14 0.0 2021092800 63440 66700
%%BeginData: 107 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
3387,7 → 5265,7
/textsize textsize cvr def
/textxoffset textxoffset cvr def
/textyoffset textyoffset cvr def
/height height cvr def
/height height cvr def
 
% Strip spaces from the given data
/text barcode def
3395,7 → 5273,7
{dup 32 ne {3 copy put pop 1 add} {pop} ifelse} forall
0 exch getinterval /barcode exch def
/hasspace text length barcode length ne def
 
% Validate the input
barcode 0 4 getinterval (\(01\)) ne {
/bwipp.ean14badAI (GS1-14 must begin with (01) application identifier) //raiseerror exec
3414,7 → 5292,7
0 1 12 {
/i exch def
/checksum checksum barcode i 4 add get 48 sub i 2 mod 0 eq {3 mul} if add def
} for
} for
/checksum 10 checksum 10 mod sub 10 mod def
barcode length 18 eq {
barcode 17 get checksum 48 add ne {
3447,12 → 5325,14
args (textxalign) (center) put
args (opt) options put
args
 
dontdraw not //renlinear if
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/ean14 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
3461,13 → 5341,13
% --END ENCODER ean14--
 
% --BEGIN ENCODER sscc18--
% --REQUIRES preamble raiseerror renlinear code128--
% --REQUIRES preamble raiseerror parseinput renlinear code128--
% --DESC: SSCC-18
% --EXAM: (00) 0 0614141 123456789 0
% --EXOP: includetext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp sscc18 0.0 2018020400 71208 70903
%%BeginData: 105 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp sscc18 0.0 2021092800 63324 66579
%%BeginData: 107 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
3488,7 → 5368,7
/textxoffset 0 def
/textyoffset -7 def
/height 1 def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
3504,7 → 5384,7
/textsize textsize cvr def
/textxoffset textxoffset cvr def
/textyoffset textyoffset cvr def
/height height cvr def
/height height cvr def
 
% Strip spaces from the given data
/text barcode def
3531,7 → 5411,7
0 1 16 {
/i exch def
/checksum checksum barcode i 4 add get 48 sub i 2 mod 0 eq {3 mul} if add def
} for
} for
/checksum 10 checksum 10 mod sub 10 mod def
barcode length 22 eq {
barcode 21 get checksum 48 add ne {
3564,12 → 5444,14
args (textxalign) (center) put
args (opt) options put
args
 
dontdraw not //renlinear if
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/sscc18 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
3583,8 → 5465,8
% --EXAM: THIS IS CODE 39
% --EXOP: includetext includecheck includecheckintext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp code39 0.0 2018020400 71882 71562
%%BeginData: 141 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp code39 0.0 2021092800 62946 62513
%%BeginData: 143 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
3607,7 → 5489,7
/textsize 10 def
/textyoffset -7 def
/height 1 def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
3618,7 → 5500,7
currentdict end /options exch def
} if
options {def} forall
 
/textfont textfont cvlit def
/textsize textsize cvr def
/textyoffset textyoffset cvr def
3705,7 → 5587,7
txt barlen 1 add [() barlen 1 add 16 mul textyoffset textfont textsize] put
} ifelse
} ifelse
 
% Return the arguments
<<
/ren //renlinear
3722,7 → 5604,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/code39 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
3731,16 → 5615,17
% --END ENCODER code39--
 
% --BEGIN ENCODER code39ext--
% --REQUIRES preamble raiseerror renlinear code39--
% --REQUIRES preamble raiseerror parseinput renlinear code39--
% --DESC: Code 39 Extended
% --EXAM: Code39 Ext!
% --EXOP: includetext includecheck includecheckintext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp code39ext 0.0 2018020400 67995 71251
%%BeginData: 110 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp code39ext 0.0 2021092800 61643 64843
%%BeginData: 100 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
dup /code39 dup /uk.co.terryburton.bwipp findresource put
begin
3767,25 → 5652,14
options {def} forall
 
% Parse ordinals of the form ^NNN to ASCII
parse {
/msg barcode length string def
/j 0 def
barcode
{ % loop
(^) search {
dup msg exch j exch putinterval
length j add 1 add /j exch def
pop
dup 0 3 getinterval cvi msg exch j 1 sub exch put
dup length 3 sub 3 exch getinterval
} {
dup msg exch j exch putinterval
length j add /j exch def
/barcode msg 0 j getinterval def
exit
} ifelse
} loop
} if
/fncvals <<
/parse parse
/parseonly true
/parsefnc false
>> def
/barcode barcode fncvals //parseinput exec def
/barlen barcode length def
options (parse) undef
 
% Validate the input
barcode {
3794,8 → 5668,6
} if
} forall
 
/barlen barcode length def
 
% Extended alphabet to non-extended alphabet
/extencs
[ (%U) ($A) ($B) ($C) ($D) ($E) ($F) ($G) ($H) ($I) ($J) ($K) ($L) ($M) ($N) ($O)
3844,7 → 5716,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/code39ext dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
3858,8 → 5732,8
% --EXAM: 01234567
% --EXOP: includetext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp code32 0.0 2018020400 65276 68553
%%BeginData: 99 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp code32 0.0 2021092800 58521 58072
%%BeginData: 101 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
3926,7 → 5800,7
/text exch def
 
% convert number from base10 to base32
/val text cvi 32 barcode cvrs def
/val text cvi 32 6 string cvrs def
/barcode 6 string def
0 1 5 {barcode exch 48 put} for
barcode 6 val length sub val putinterval
3955,7 → 5829,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/code32 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
3969,8 → 5845,8
% --EXAM: 123456
% --EXOP: includetext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp pzn 0.0 2018020400 65523 68725
%%BeginData: 100 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp pzn 0.0 2021092800 58384 58092
%%BeginData: 102 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
3980,10 → 5856,10
/pzn {
 
20 dict begin
 
/options exch def % We are given an options string
/barcode exch def % We are given a barcode string
 
/dontdraw false def
/includetext false def % Enable/disable code32 text
/textfont /Courier def
3992,7 → 5868,7
/textxoffset 0 def
/height 1 def
/pzn8 false def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
4003,7 → 5879,7
currentdict end /options exch def
} if
options {def} forall
 
/textfont textfont cvlit def
/textsize textsize cvr def
/textyoffset textyoffset cvr def
4032,8 → 5908,8
0 1 msglen 3 sub {
/i exch def
barcode i get 48 sub i pzn8 {1} {2} ifelse add mul
checksum add /checksum exch def
} for
checksum add /checksum exch def
} for
/checksum checksum 11 mod def
checksum 10 eq {
/bwipp.pznBadInputSequence (Incorrect PZN input sequence provided) //raiseerror exec
4044,30 → 5920,32
} if
} if
msglen string
dup 0 45 put
dup 0 45 put
dup 1 barcode putinterval
dup msglen 1 sub checksum 48 add put
/msg exch def
 
% Get the result of encoding with code39
options (dontdraw) true put
/args msg options //code39 exec def
 
% format HRI
/text msglen 5 add string def
text 0 (PZN - ) putinterval
text 6 msg 1 msglen 1 sub getinterval putinterval
 
args (txt) [ [text textxoffset textyoffset textfont textsize] ] put
args (textxalign) (center) put
args (opt) options put
args
 
dontdraw not //renlinear if
 
end
} bind def
 
}
[/barcode] {null def} forall
bind def
/pzn dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
4076,16 → 5954,17
% --END ENCODER pzn--
 
% --BEGIN ENCODER code93--
% --REQUIRES preamble raiseerror renlinear--
% --REQUIRES preamble raiseerror parseinput renlinear--
% --DESC: Code 93
% --EXAM: THIS IS CODE 93
% --EXOP: includetext includecheck
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp code93 0.0 2018020400 69793 69577
%%BeginData: 148 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp code93 0.0 2021092800 62124 61789
%%BeginData: 134 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/code93 {
4102,8 → 5981,9
/textsize 10 def
/textyoffset -7 def
/height 1 def
/parsefnc false def
/parse false def
/parsefnc false def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
4114,12 → 5994,12
currentdict end /options exch def
} if
options {def} forall
 
/textfont textfont cvlit def
/textsize textsize cvr def
/textyoffset textyoffset cvr def
/height height cvr def
 
/encs
[ (131112) (111213) (111312) (111411) (121113)
(121212) (121311) (111114) (131211) (141111)
4136,35 → 6016,17
% Create a string of the available characters
/barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def
 
/barlen barcode length def
 
% Special function characters
/sft1 -1 def /sft2 -2 def /sft3 -3 def /sft4 -4 def
/fncvals <<
/parse parse
/parsefnc parsefnc
(SFT$) sft1
(SFT%) sft2
(SFT/) sft3
(SFT+) sft4
>> def
 
% Convert input into bytes accounting for shift characters
/msg barlen array def
/i 0 def /j 0 def {
i barlen eq {exit} if
/char barcode i get def
parsefnc char 94 eq and i barlen 4 sub lt and {
barcode i 1 add get 94 ne {
/char fncvals barcode i 1 add 4 getinterval get def
/i i 4 add def
} {
/i i 1 add def
} ifelse
} if
msg j char put
/i i 1 add def
/j j 1 add def
} loop
/msg msg 0 j getinterval def
/msg barcode fncvals //parseinput exec def
/msglen msg length def
 
includecheck {
4176,12 → 6038,12
 
% Put the start character
sbs 0 encs 47 get putinterval
 
/checksum1 0 def /checksum2 0 def
0 1 msglen 1 sub {
/i exch def
% Lookup the encoding for the each barcode character
msg i get dup 0 lt {
msg i get dup 0 lt {
42 exch sub /indx exch def
/char ( ) def
} {
4208,7 → 6070,7
sbs msglen 6 mul 18 add encs 48 get putinterval
} {
% Put the end character
sbs msglen 6 mul 6 add encs 48 get putinterval
sbs msglen 6 mul 6 add encs 48 get putinterval
} ifelse
 
% Return the arguments
4227,7 → 6089,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/code93 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
4236,16 → 6100,17
% --END ENCODER code93--
 
% --BEGIN ENCODER code93ext--
% --REQUIRES preamble raiseerror renlinear code93--
% --REQUIRES preamble raiseerror parseinput renlinear code93--
% --DESC: Code 93 Extended
% --EXAM: Code93 Ext!
% --EXOP: includetext includecheck
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp code93ext 0.0 2018020400 68340 71524
%%BeginData: 114 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp code93ext 0.0 2021092800 62105 65416
%%BeginData: 104 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
dup /code93 dup /uk.co.terryburton.bwipp findresource put
begin
4272,36 → 6137,23
options {def} forall
 
% Parse ordinals of the form ^NNN to ASCII
parse {
/msg barcode length string def
/j 0 def
barcode
{ % loop
(^) search {
dup msg exch j exch putinterval
length j add 1 add /j exch def
pop
dup 0 3 getinterval cvi msg exch j 1 sub exch put
dup length 3 sub 3 exch getinterval
} {
dup msg exch j exch putinterval
length j add /j exch def
/barcode msg 0 j getinterval def
exit
} ifelse
} loop
} if
 
/fncvals <<
/parse parse
/parseonly true
/parsefnc false
>> def
/barcode barcode fncvals //parseinput exec def
/barlen barcode length def
options (parse) undef
 
% Extended alphabet to non-extended alphabet
/extencs
[ (^SFT%U) (^SFT$A) (^SFT$B) (^SFT$C) (^SFT$D) (^SFT$E) (^SFT$F) (^SFT$G)
[ (^SFT%U) (^SFT$A) (^SFT$B) (^SFT$C) (^SFT$D) (^SFT$E) (^SFT$F) (^SFT$G)
(^SFT$H) (^SFT$I) (^SFT$J) (^SFT$K) (^SFT$L) (^SFT$M) (^SFT$N) (^SFT$O)
(^SFT$P) (^SFT$Q) (^SFT$R) (^SFT$S) (^SFT$T) (^SFT$U) (^SFT$V) (^SFT$W)
(^SFT$X) (^SFT$Y) (^SFT$Z) (^SFT%A) (^SFT%B) (^SFT%C) (^SFT%D) (^SFT%E)
( ) (^SFT/A) (^SFT/B) (^SFT/C) (^SFT/D) (^SFT/E) (^SFT/F) (^SFT/G)
(^SFT/H) (^SFT/I) (^SFT/J) (^SFT/K) (^SFT/L) (-) (.) (^SFT/O)
( ) (^SFT/A) (^SFT/B) (^SFT/C) ($) (%) (^SFT/F) (^SFT/G)
(^SFT/H) (^SFT/I) (^SFT/J) (+) (^SFT/L) (-) (.) (/)
(0) (1) (2) (3) (4) (5) (6) (7)
(8) (9) (^SFT/Z) (^SFT%F) (^SFT%G) (^SFT%H) (^SFT%I) (^SFT%J)
(^SFT%V) (A) (B) (C) (D) (E) (F) (G)
4353,7 → 6205,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/code93ext dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
4367,8 → 6221,8
% --EXAM: 2401234567
% --EXOP: height=0.5 includecheck includetext includecheckintext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp interleaved2of5 0.0 2018020400 69893 69673
%%BeginData: 150 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp interleaved2of5 0.0 2021092800 61533 61224
%%BeginData: 152 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
4389,7 → 6243,7
/textsize 10 def
/textyoffset -7 def
/height 1 def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
4400,7 → 6254,7
currentdict end /options exch def
} if
options {def} forall
 
/textfont textfont cvlit def
/textsize textsize cvr def
/textyoffset textyoffset cvr def
4412,7 → 6266,7
/bwipp.interleaved2of5badCharacter (Interleaved 2 of 5 must contain only digits) //raiseerror exec
} if
} forall
 
/barlen barcode length def % Length of the code
 
% Prefix 0 to barcode if length is even and including checkdigit
4515,7 → 6369,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/interleaved2of5 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
4529,8 → 6385,8
% --EXAM: 0 46 01234 56789 3
% --EXOP: includetext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp itf14 0.0 2018020400 68130 71302
%%BeginData: 109 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp itf14 0.0 2021092800 60903 60661
%%BeginData: 111 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
4556,7 → 6412,7
/borderwidth 4 def
/borderleft 15 def
/borderright 15 def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
4572,7 → 6428,7
/textsize textsize cvr def
/textxoffset textxoffset cvr def
/textyoffset textyoffset cvr def
/height height cvr def
/height height cvr def
/borderwidth borderwidth cvr def
/borderleft borderleft cvr def
/borderright borderright cvr def
4631,12 → 6487,14
args (textxalign) (center) put
args (opt) options put
args
 
dontdraw not //renlinear if
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/itf14 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
4650,8 → 6508,8
% --EXAM: 563102430313
% --EXOP: includetext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp identcode 0.0 2018020400 64233 67405
%%BeginData: 91 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp identcode 0.0 2021092800 57310 57220
%%BeginData: 93 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
4672,7 → 6530,7
/textxoffset 0 def
/textyoffset -7 def
/height 1 def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
4688,7 → 6546,7
/textsize textsize cvr def
/textxoffset textxoffset cvr def
/textyoffset textyoffset cvr def
/height height cvr def
/height height cvr def
 
% Validate the input
barcode length 11 ne barcode length 12 ne and {
4705,7 → 6563,7
0 1 10 {
/i exch def
/checksum checksum barcode i get 48 sub i 2 mod 0 eq {4 mul} {9 mul} ifelse add def
} for
} for
/checksum 10 checksum 10 mod sub 10 mod def
barcode length 12 eq {
barcode 11 get checksum 48 add ne {
4734,12 → 6592,14
args (textxalign) (center) put
args (opt) options put
args
 
dontdraw not //renlinear if
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/identcode dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
4753,8 → 6613,8
% --EXAM: 21348075016401
% --EXOP: includetext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp leitcode 0.0 2018020400 64225 67401
%%BeginData: 91 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp leitcode 0.0 2021092800 57302 57216
%%BeginData: 93 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
4775,7 → 6635,7
/textxoffset 0 def
/textyoffset -7 def
/height 1 def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
4791,7 → 6651,7
/textsize textsize cvr def
/textxoffset textxoffset cvr def
/textyoffset textyoffset cvr def
/height height cvr def
/height height cvr def
 
% Validate the input
barcode length 13 ne barcode length 14 ne and {
4808,7 → 6668,7
0 1 12 {
/i exch def
/checksum checksum barcode i get 48 sub i 2 mod 0 eq {4 mul} {9 mul} ifelse add def
} for
} for
/checksum 10 checksum 10 mod sub 10 mod def
barcode length 14 eq {
barcode 13 get checksum 48 add ne {
4837,12 → 6697,14
args (textxalign) (center) put
args (opt) options put
args
 
dontdraw not //renlinear if
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/leitcode dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
4856,8 → 6718,8
% --EXAM: (01)24012345678905
% --EXOP:
% --RNDR: renlinear renmatrix
%%BeginResource: uk.co.terryburton.bwipp databaromni 0.0 2018020400 132064 134102
%%BeginData: 420 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp databaromni 0.0 2021092800 105433 104213
%%BeginData: 425 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
4876,7 → 6738,7
/linkage false def
/format (omni) def
/barxmult 33 def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
4887,7 → 6749,7
currentdict end /options exch def
} if
options {def} forall
 
format (truncated) eq {/height 13 72 div def} if
/height height cvr def
/barxmult barxmult cvi def
4944,7 → 6806,7
} loop
exch pop exch pop
} bind def
 
/getRSSwidths {
/oe exch def
/el exch def
4955,7 → 6817,7
/mask 0 def
0 1 el 2 sub {
/bar exch def
/ew 1 def
/ew 1 def
/mask mask 1 bar bitshift or def {
/sval nm ew sub 1 sub el bar sub 2 sub ncr def
oe mask 0 eq and nm ew sub el 2 mul sub bar 2 mul add -2 ge and {
4975,20 → 6837,20
val 0 lt {exit} if
/ew ew 1 add def
/mask mask 1 bar bitshift not and def
} loop
} loop
/val val sval add def
/nm nm ew sub def
out bar ew put
out bar ew put
} for
out el 1 sub nm put
out
} bind def
/binval [
 
/binval [
linkage {1} {0} ifelse
barcode 4 13 getinterval {48 sub} forall
] def
 
0 1 12 {
/i exch def
binval i 1 add 2 copy get binval i get 4537077 mod 10 mul add put
5009,7 → 6871,7
/left left 3 -1 roll 10 13 j sub exp cvi mul add def
} ifelse
} for
 
/d1 left 1597 idiv def
/d2 left 1597 mod def
/d3 right 1597 idiv def
5077,7 → 6939,7
} if
/i i 8 add def
} loop
 
/d1wo d1 d1gs sub d1te idiv d1elo d1mwo 4 false getRSSwidths def
/d1we d1 d1gs sub d1te mod d1ele d1mwe 4 true getRSSwidths def
/d2wo d2 d2gs sub d2to mod d2elo d2mwo 4 true getRSSwidths def
5100,7 → 6962,7
d2w 7 i 2 mul sub d2wo i get put
d2w 6 i 2 mul sub d2we i get put
} for
 
/d3w 8 array def
0 1 3 {
/i exch def
5107,7 → 6969,7
d3w 7 i 2 mul sub d3wo i get put
d3w 6 i 2 mul sub d3we i get put
} for
 
/d4w 8 array def
0 1 3 {
/i exch def
5121,7 → 6983,7
d3w {} forall
d4w {} forall
] def
 
/checkweights [
1 3 9 27 2 6 18 54
58 72 24 8 29 36 12 4
5134,13 → 6996,13
3 1 9 1 1 2 7 4 1 1 2 5 6 1 1
2 3 8 1 1 1 5 7 1 1 1 3 9 1 1
] def
 
/checksum 0 def
0 1 31 {
/i exch def
/checksum checksum widths i get checkweights i get mul add def
/checksum checksum widths i get checkweights i get mul add def
} for
/checksum checksum 79 mod def
/checksum checksum 79 mod def
checksum 8 ge {/checksum checksum 1 add def} if
checksum 72 ge {/checksum checksum 1 add def} if
/checklt checkwidths checksum 9 idiv 5 mul 5 getinterval def
5155,10 → 7017,10
format (omni) eq format (truncated) eq or { % linear
 
/sbs [
1 d1w {} forall checklt {} forall d2w {} forall
1 d1w {} forall checklt {} forall d2w {} forall
d4w {} forall checkrt {} forall d3w {} forall 1 1
] def
 
<<
/ren //renlinear
/sbs sbs
5168,19 → 7030,19
/textxalign (center)
/opt options
>>
 
dontdraw not //renlinear if
 
} { % 2D - stacked or stackedomni
 
/top [ 1 1 d1w {} forall checklt {} forall d2w {} forall 1 1 0 ] def
/bot [ 1 1 d4w {} forall checkrt {} forall d3w {} forall 1 1 0 ] def
/bot [ 1 1 d4w {} forall checkrt {} forall d3w {} forall 1 1 0 ] def
0 2 24 {
/i exch def
top i get {0} repeat
top i 1 add get {1} repeat
} for
50 array astore /top exch def
50 array astore /top exch def
0 2 24 {
/i exch def
bot i get {1} repeat
5190,8 → 7052,9
 
% Stacked
format (stacked) eq {
/sep [ 50 {0} repeat ] def
4 1 45 {
/sep 50 array def
sep 0 0 put
1 1 49 {
/i exch def
top i get bot i get eq {
sep i 1 top i get sub put
5199,6 → 7062,8
sep i 1 sep i 1 sub get sub put
} ifelse
} for
sep 0 [ 0 0 0 0 ] putinterval
sep 46 [ 0 0 0 0 ] putinterval
/pixs [
5 {top aload pop} repeat
sep aload pop
5206,7 → 7071,7
] def
/pixy pixs length 50 idiv def
} if
 
% Stacked omnidirectional
format (stackedomni) eq {
/sep1 [ top {1 exch sub} forall ] def
5256,7 → 7121,7
] def
/pixy pixs length 50 idiv def
} if
 
% Return the arguments
<<
/ren //renmatrix
5267,14 → 7132,16
/width 50 72 div
/opt options
>>
 
dontdraw not //renmatrix if
 
} ifelse
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/databaromni dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
5288,8 → 7155,8
% --EXAM: (01)24012345678905
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp databarstacked 0.0 2018020400 67609 70868
%%BeginData: 73 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp databarstacked 0.0 2021092800 58192 61579
%%BeginData: 75 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
5354,12 → 7221,14
 
args (opt) options put
args
 
dontdraw not //renmatrix if
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/databarstacked dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
5373,8 → 7242,8
% --EXAM: (01)24012345678905
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp databarstackedomni 0.0 2018020400 67709 70948
%%BeginData: 73 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp databarstackedomni 0.0 2021092800 58236 61531
%%BeginData: 75 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
5439,12 → 7308,14
 
args (opt) options put
args
 
dontdraw not //renmatrix if
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/databarstackedomni dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
5458,8 → 7329,8
% --EXAM: (01)24012345678905
% --EXOP:
% --RNDR: renlinear renmatrix
%%BeginResource: uk.co.terryburton.bwipp databartruncated 0.0 2018020400 67635 70884
%%BeginData: 73 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp databartruncated 0.0 2021092800 58138 61491
%%BeginData: 75 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
5524,12 → 7395,14
 
args (opt) options put
args
 
dontdraw not //renlinear if
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/databartruncated dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
5543,8 → 7416,8
% --EXAM: (01)15012345678907
% --EXOP:
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp databarlimited 0.0 2018020400 93145 95946
%%BeginData: 276 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp databarlimited 0.0 2021092800 80912 80201
%%BeginData: 278 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
5571,7 → 7444,7
currentdict end /options exch def
} if
options {def} forall
 
/height height cvr def
 
% Validate the input
5599,7 → 7472,7
/checksum 10 checksum 10 mod sub 10 mod def
barcode length 18 eq {
barcode 17 get checksum 48 add ne {
/bwipp.databaromniBadCheckDigit (Incorrect GS1 DataBar Limited check digit provided) //raiseerror exec
/bwipp.databarlimitedBadCheckDigit (Incorrect GS1 DataBar Limited check digit provided) //raiseerror exec
} if
} if
18 string
5608,7 → 7481,7
/barcode exch def
 
% Strip the AI and optional check digit
/binval [
/binval [
barcode 4 13 getinterval {48 sub} forall
] def
linkage {
5617,7 → 7490,7
/i exch def
binval i binval i get linkval i get add put
} for
} if
} if
 
% Create the human readable text
/txt barcode length array def
5641,7 → 7514,7
} loop
exch pop exch pop
} bind def
 
/getRSSwidths {
/oe exch def
/el exch def
5652,7 → 7525,7
/mask 0 def
0 1 el 2 sub {
/bar exch def
/ew 1 def
/ew 1 def
/mask mask 1 bar bitshift or def {
/sval nm ew sub 1 sub el bar sub 2 sub ncr def
oe mask 0 eq and nm ew sub el 2 mul sub bar 2 mul add -2 ge and {
5672,15 → 7545,15
val 0 lt {exit} if
/ew ew 1 add def
/mask mask 1 bar bitshift not and def
} loop
} loop
/val val sval add def
/nm nm ew sub def
out bar ew put
out bar ew put
} for
out el 1 sub nm put
out
} bind def
 
0 1 11 {
/i exch def
binval i 1 add 2 copy get binval i get 2013571 mod 10 mul add put
5701,7 → 7574,7
/d1 d1 3 -1 roll 10 12 j sub exp cvi mul add def
} ifelse
} for
 
/tab267 [
183063 0 17 9 6 3 6538 28
820063 183064 13 13 5 4 875 728
5736,9 → 7609,9
/i i 8 add def
} loop
 
/d1wo d1 d1gs sub d1te idiv d1elo d1mwo 7 false getRSSwidths def
/d1wo d1 d1gs sub d1te idiv d1elo d1mwo 7 false getRSSwidths def
/d1we d1 d1gs sub d1te mod d1ele d1mwe 7 true getRSSwidths def
/d2wo d2 d2gs sub d2te idiv d2elo d2mwo 7 false getRSSwidths def
/d2wo d2 d2gs sub d2te idiv d2elo d2mwo 7 false getRSSwidths def
/d2we d2 d2gs sub d2te mod d2ele d2mwe 7 true getRSSwidths def
 
/d1w 14 array def
5759,7 → 7632,7
d1w {} forall
d2w {} forall
] def
 
/checkweights [
1 3 9 27 81 65 17 51 64 14 42 37 22 66
20 60 2 6 18 54 73 41 34 13 39 28 84 74
5780,7 → 7653,7
322 323
326 337
] def
 
/checksum 0 def
0 1 27 {
/i exch def
5797,11 → 7670,11
checkwidths i 2 mul swidths i get put
checkwidths i 2 mul 1 add bwidths i get put
} for
 
/sbs [
1 d1w {} forall checkwidths {} forall d2w {} forall 1 1
1 d1w {} forall checkwidths {} forall d2w {} forall 1 1 5
] def
 
% Return the arguments
<<
/ren //renlinear
5817,7 → 7690,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/databarlimited dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
5826,16 → 7701,18
% --END ENCODER databarlimited--
 
% --BEGIN ENCODER databarexpanded--
% --REQUIRES preamble raiseerror renlinear renmatrix--
% --REQUIRES preamble raiseerror parseinput gs1lint renlinear renmatrix--
% --DESC: GS1 DataBar Expanded
% --EXAM: (01)95012345678903(3103)000123
% --EXOP:
% --RNDR: renlinear renmatrix
%%BeginResource: uk.co.terryburton.bwipp databarexpanded 0.0 2018020400 245908 243901
%%BeginData: 880 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp databarexpanded 0.0 2021092800 242723 244991
%%BeginData: 886 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /gs1lint dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
begin
5846,13 → 7723,15
/options exch def % We are given an option string
/barcode exch def % We are given a barcode string
 
/parse false def
/dontlint false def
/dontdraw false def
/height 34 72 div def
/format (expanded) def
/segments -1 def
/linkage false def
/linkage false def
/barxmult 34 def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
5863,7 → 7742,7
currentdict end /options exch def
} if
options {def} forall
 
/height height cvr def
/segments segments cvi def
/barxmult barxmult cvi def
5870,27 → 7749,20
 
segments -1 eq {
/segments format (expandedstacked) eq {4} {22} ifelse def
} if
} {
segments 2 lt segments 22 gt or segments 2 mod 0 ne or {
/bwipp.gs1databarexpandedBadSegments (The number of segments must be even from 2 to 22) //raiseerror exec
} if
} ifelse
 
% Expand ordinals of the form ^NNN to ASCII
/expand {
/in exch def
/out in length string def
/j 0 def
in
{ % loop
(^) search {
dup out exch j exch putinterval
length j add 1 add /j exch def
pop
dup 0 3 getinterval cvi out exch j 1 sub exch put
dup length 3 sub 3 exch getinterval
} {
dup out exch j exch putinterval
length j add /j exch def
out 0 j getinterval exit
} ifelse
} loop
/fncvals <<
/parse parse
/parseonly true
/parsefnc false
>> def
fncvals //parseinput exec
} bind def
 
% Parse out AIs
5912,6 → 7784,8
} loop
pop
 
dontlint not { ais vals //gs1lint exec pop } if
 
% Method selection
{ % common exit
 
5923,7 → 7797,7
} if
} if
} if
 
% (01)9...(3202)...
ais length 2 eq {
ais 0 get (01) eq ais 1 get (3202) eq and {
5932,7 → 7806,7
} if
} if
} if
 
% (01)9...(3203)...
ais length 2 eq {
ais 0 get (01) eq ais 1 get (3203) eq and {
5941,7 → 7815,7
} if
} if
} if
 
% (01)9...(310x/320x)...[(11/13/15/17)...]
ais length dup 2 eq exch 3 eq or {
/ai310x false 3100 1 3109 {10 4 string cvrs ais 1 get eq or} for def
5955,7 → 7829,8
ais length 3 eq {
vals 0 get 0 1 getinterval (9) eq
vals 1 get cvi 99999 le and
vals 2 cvi 999999 le and {
vals 2 get 2 2 getinterval cvi dup 1 ge exch 12 le and and % Month 1-12
vals 2 get 4 2 getinterval cvi dup 0 ge exch 31 le and and { % Day 0-31
ai310x ais 2 get (11) eq and { (0111000) false exit } if
ai320x ais 2 get (11) eq and { (0111001) false exit } if
ai310x ais 2 get (13) eq and { (0111010) false exit } if
5974,7 → 7849,7
} ifelse
} if
} if
 
% (01)9...(392x)...
ais length 2 ge {
/ai392x false 3920 1 3923 {10 4 string cvrs ais 1 get eq or} for def
5982,7 → 7857,7
vals 0 get 0 1 getinterval (9) eq { (01100) true exit } if
} if
} if
 
% (01)9...(393x)...
ais length 2 ge {
/ai393x false 3930 1 3933 {10 4 string cvrs ais 1 get eq or} for def
5990,17 → 7865,17
vals 0 get 0 1 getinterval (9) eq { (01101) true exit } if
} if
} if
 
% (01)...
ais 0 get (01) eq { (1) true exit } if
 
% Freeform
(00) true exit
 
} loop
/gpfallow exch def
/method exch def
 
/conv12to40 {
(0000000000000000000000000000000000000000) 40 string copy
2 copy 0 10 getinterval exch 0 3 getinterval cvi 2 10 string cvrs dup length 10 exch sub exch putinterval
6009,23 → 7884,25
2 copy 30 10 getinterval exch 9 3 getinterval cvi 2 10 string cvrs dup length 10 exch sub exch putinterval
exch pop
} bind def
 
/conv13to44 {
(00000000000000000000000000000000000000000000) 44 string copy
2 copy 0 4 getinterval exch 0 1 getinterval cvi 2 4 string cvrs dup length 4 exch sub exch putinterval
dup 3 -1 roll 1 12 getinterval conv12to40 4 exch putinterval
} bind def
 
/tobin {
string dup length 1 sub 0 exch 1 exch {1 index exch 48 put} for
dup 3 -1 roll 2 2 index length string cvrs dup length 2 index length exch sub exch putinterval
dup 3 -1 roll 2 2 index length string cvrs dup length 2 index length exch sub exch putinterval
} bind def
 
/fnc1 -1 def /lnumeric -2 def /lalphanumeric -3 def /liso646 -4 def
 
method (00) eq {
/cdf [] def
/gpf [] def
} if
 
method (1) eq {
/cdf vals 0 get 0 13 getinterval conv13to44 def
/cdf [ cdf {48 sub} forall ] def
6033,7 → 7910,7
/ais ais 1 ais length 1 sub getinterval def
/vals vals 1 vals length 1 sub getinterval def
} if
 
method (0100) eq {
/cdf 55 string def
cdf 0 vals 0 get 1 12 getinterval conv12to40 putinterval
6043,7 → 7920,7
/ais [] def
/vals [] def
} if
 
method (0101) eq {
/cdf 55 string def
cdf 0 vals 0 get 1 12 getinterval conv12to40 putinterval
6058,7 → 7935,7
/ais [] def
/vals [] def
} if
 
method length 7 eq {
/cdf 76 string def
cdf 0 vals 0 get 1 12 getinterval conv12to40 putinterval
6079,17 → 7956,17
/ais [] def
/vals [] def
} if
 
method (01100) eq {
/cdf 42 string def
cdf 0 vals 0 get 1 12 getinterval conv12to40 putinterval
cdf 40 ais 1 get 3 1 getinterval cvi 2 tobin putinterval
/cdf [ cdf {48 sub} forall ] def
/gpf [ vals 1 get {} forall ] def
/gpf [ vals 1 get {} forall ais length 2 gt { fnc1 } if ] def
/ais ais 2 ais length 2 sub getinterval def
/vals vals 2 vals length 2 sub getinterval def
} if
 
method (01101) eq {
/cdf 52 string def
cdf 0 vals 0 get 1 12 getinterval conv12to40 putinterval
6096,11 → 7973,11
cdf 40 ais 1 get 3 1 getinterval cvi 2 tobin putinterval
cdf 42 vals 1 get 0 3 getinterval cvi 10 tobin putinterval
/cdf [ cdf {48 sub} forall ] def
/gpf [ vals 1 get dup length 3 sub 3 exch getinterval {} forall ] def
/gpf [ vals 1 get dup length 3 sub 3 exch getinterval {} forall ais length 2 gt { fnc1 } if ] def
/ais ais 2 ais length 2 sub getinterval def
/vals vals 2 vals length 2 sub getinterval def
} if
 
% Variable length symbol field
gpfallow {
/vlf 2 array def
6126,21 → 8003,19
10 2 string cvrs dup aifixed 3 1 roll put
} forall
 
/fnc1 -1 def /lnumeric -2 def /lalphanumeric -3 def /liso646 -4 def
/numeric <<
0 1 119 {
dup (00) 2 string copy dup 3 -1 roll 11 2 string cvrs
dup length 2 exch sub exch putinterval
dup 0 get 65 eq {dup 0 94 put} if
dup 1 get 65 eq {dup 1 94 put} if
dup length 2 exch sub exch putinterval
dup 0 get 65 eq {dup 0 94 put} if
dup 1 get 65 eq {dup 1 94 put} if
exch 8 add
(0000000) 7 string copy dup 3 -1 roll 2 7 string cvrs
(0000000) 7 string copy dup 3 -1 roll 2 7 string cvrs
dup length 7 exch sub exch putinterval
} for
lalphanumeric (0000)
>> def
 
/alphanumeric <<
48 1 57 {dup 43 sub 5 tobin} for
fnc1 (01111)
6150,7 → 8025,7
lnumeric (000)
liso646 (00100)
>> def
 
/iso646 <<
48 1 57 {dup 43 sub 5 tobin} for
fnc1 (01111)
6165,7 → 8040,7
lnumeric (000)
lalphanumeric (00100)
>> def
 
% Append the remaining AI data
0 1 ais length 1 sub {
/i exch def
6187,16 → 8062,16
% Calculate the number of bits remaining to the next valid symbol size
/rembits {
dup
12 div ceiling cvi 12 mul % Round up to multiple of 12
12 div ceiling cvi 12 mul % Round up to multiple of 12
48 2 copy lt {exch} if pop % At least 4 symbols
dup 12 idiv dup segments mod 1 eq { % At least 2 symbols on last row of stacked symbol
1 add 12 mul exch pop
} {
pop
} ifelse
} ifelse
exch sub
} bind def
 
/encode {
dup /raw ne {exch get} {pop} ifelse
[ exch {48 sub} forall ]
6204,7 → 8079,7
gpfenc exch j exch putinterval
/j exch j add def
} bind def
 
% Pre-compute alphanumeric and numeric runlengths and position of next ISO646-only characters
/numericruns [ gpf length {0} repeat 0 -1 ] def
/alphanumericruns [ gpf length {0} repeat 0 ] def
6213,7 → 8088,7
/i exch def
gpf i get
(00) 2 string copy
dup 0 gpf i get dup fnc1 eq {pop 94} if put
dup 0 gpf i get dup fnc1 eq {pop 94} if put
i gpf length 1 sub lt {dup 1 gpf i 1 add get dup fnc1 eq {pop 94} if put} if
numeric exch known {
numericruns i numericruns i 2 add get 2 add put
6231,7 → 8106,7
nextiso646only i nextiso646only i 1 add get 1 add put
} ifelse
} for
 
% Encode the general purpose field
/gpfenc 252 array def
/i 0 def /j 0 def /mode (numeric) def
6238,10 → 8113,10
{ % loop
i gpf length eq {exit} if
{ % not a loop but common exit point
 
mode (numeric) eq {
i gpf length 2 sub le {
2 string
2 string
dup 0 gpf i get dup fnc1 eq {pop 94} if put
dup 1 gpf i 1 add get dup fnc1 eq {pop 94} if put
dup numeric exch known {
6250,7 → 8125,7
exit
} if
pop
lalphanumeric numeric encode
lalphanumeric numeric encode
/mode (alphanumeric) def
exit
} {
6267,13 → 8142,13
/i i 1 add def
exit
} { % C1.FNC1
2 string dup 0 gpf i get put dup 1 94 put numeric encode
2 string dup 0 gpf i get put dup 1 94 put numeric encode
/i i 1 add def
exit
} ifelse
} ifelse
} if
 
mode (alphanumeric) eq {
gpf i get fnc1 eq {
fnc1 alphanumeric encode
6300,7 → 8175,7
/i i 1 add def
exit
} if
 
mode (iso646) eq {
gpf i get fnc1 eq {
fnc1 iso646 encode
6322,13 → 8197,13
/i i 1 add def
exit
} if
 
} loop
} loop
/gpf gpfenc 0 j getinterval def
 
% Complete the variable length field and create pad
1 12 add method length add vlf length add cdf length add gpf length add
1 12 add method length add vlf length add cdf length add gpf length add
dup rembits dup array /pad exch def
vlf length 0 ne {
add 12 idiv
6340,16 → 8215,16
pad length 0 gt {
0 5 pad length 1 sub { % Fill with 00100
/i exch def
pad i [ 0 0 1 0 0 ] 0 pad length i sub 5 2 copy gt {exch} if pop getinterval putinterval
} for
pad i [ 0 0 1 0 0 ] 0 pad length i sub 5 2 copy gt {exch} if pop getinterval putinterval
} for
mode (numeric) eq { % Prefix shift from numeric to ASCII
/pad [ 0 0 0 0 pad aload pop ] 0 pad length getinterval def
} if
} if
 
% Concatenate fields
/binval [
linkage {1} {0} ifelse
linkage {1} {0} ifelse
method {48 sub} forall
vlf aload pop
cdf aload pop
6357,7 → 8232,7
pad aload pop
] def
/datalen binval length 12 idiv def
 
/ncr { % n r
2 copy sub 2 copy lt {exch} if % n r maxd mind
1 1 5 3 roll % mind j=1 v=1 n maxd
6373,7 → 8248,7
} loop
exch pop exch pop
} bind def
 
/getRSSwidths {
/oe exch def
/el exch def
6384,7 → 8259,7
/mask 0 def
0 1 el 2 sub {
/bar exch def
/ew 1 def
/ew 1 def
/mask mask 1 bar bitshift or def {
/sval nm ew sub 1 sub el bar sub 2 sub ncr def
oe mask 0 eq and nm ew sub el 2 mul sub bar 2 mul add -2 ge and {
6404,10 → 8279,10
val 0 lt {exit} if
/ew ew 1 add def
/mask mask 1 bar bitshift not and def
} loop
} loop
/val val sval add def
/nm nm ew sub def
out bar ew put
out bar ew put
} for
out el 1 sub nm put
out
6422,7 → 8297,7
] def
 
/dxw datalen array def
 
0 1 datalen 1 sub {
 
/x exch def
6445,14 → 8320,14
/dwo d dgs sub dte idiv delo dmwo 4 true getRSSwidths def
/dwe d dgs sub dte mod dele dmwe 4 false getRSSwidths def
 
/dw 8 array def
x 2 mod 0 eq {
/dw 8 array def
x 2 mod 0 eq {
0 1 3 {
/j exch def
dw 7 j 2 mul sub dwo j get put
dw 6 j 2 mul sub dwe j get put
} for
} {
} {
0 1 3 {
/j exch def
dw j 2 mul dwo j get put
6463,7 → 8338,7
dxw x dw put
 
} for
 
/finderwidths [
1 8 4 1 1 1 1 4 8 1
3 6 4 1 1 1 1 4 6 3
6498,7 → 8373,7
77 96 32 81 27 9 3 1 % A1R
20 60 180 118 143 7 21 63 % A2L
205 209 140 117 39 13 145 189 % A2R
193 157 49 147 19 57 171 91 % B1L
193 157 49 147 19 57 171 91 % B1L
132 44 85 169 197 136 186 62 % B1R
185 133 188 142 4 12 36 108 % B2L
50 87 29 80 97 173 128 113 % B2R
6527,11 → 8402,11
/widths [
dxw {{} forall} forall
] def
 
/checksum 0 def
0 1 widths length 1 sub {
/i exch def
/checksum checksum widths i get checkweightseq i get mul add def
/checksum checksum widths i get checkweightseq i get mul add def
} for
/checksum checksum 211 mod datalen 3 sub 211 mul add def
 
6550,7 → 8425,7
/cwo checksum cgs sub cte idiv celo cmwo 4 true getRSSwidths def
/cwe checksum cgs sub cte mod cele cmwe 4 false getRSSwidths def
 
/cw 8 array def
/cw 8 array def
0 1 3 {
/i exch def
cw i 2 mul cwo i get put
6573,7 → 8448,7
0 1 segments 1 sub {
/pos exch r segments mul add def
pos datalen lt {
dxw pos get {} forall
dxw pos get {} forall
pos 2 mod 0 eq {fxw pos 2 idiv get {} forall} if
} if
} for
6596,6 → 8471,8
1 1
] def
 
options (parse) undef
 
<<
/ren //renlinear
/sbs sbs
6625,12 → 8502,10
 
% Derive the separator pattern
/sep [ row {1 exch sub} forall ] def
sep 0 [ 0 0 0 0 ] putinterval
sep row length 4 sub [ 0 0 0 0 ] putinterval
/finderpos [ % Finder pattern module positions
19 98 row length 13 sub {} for
68 98 row length 13 sub {} for
] def
] def
finderpos {
dup 14 add 1 exch {
/i exch def
6646,6 → 8521,8
sep exch i exch put
} for
} forall
sep 0 [ 0 0 0 0 ] putinterval
sep row length 4 sub [ 0 0 0 0 ] putinterval
 
% For even segment-pair symbols reverse alternate rows
segments 4 mod 0 eq r 2 mod 1 eq and {
6669,9 → 8546,9
% Extend last row and separator to fill width of symbol
/pixx rows 0 get length def
[ pixx {0} repeat ] dup 0 rows numrows 1 sub get putinterval
rows exch numrows 1 sub exch put
rows exch numrows 1 sub exch put
[ pixx {0} repeat ] dup 0 seps numrows 1 sub get putinterval
seps exch numrows 1 sub exch put
seps exch numrows 1 sub exch put
 
% Middle separator pattern
/sep [ pixx 2 idiv 1 add { 0 1 } repeat ] 0 pixx getinterval def
6693,6 → 8570,8
} for
] def
 
options (parse) undef
 
<<
/ren //renmatrix
/pixs pixs
6709,7 → 8588,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/databarexpanded dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
6718,13 → 8599,13
% --END ENCODER databarexpanded--
 
% --BEGIN ENCODER databarexpandedstacked--
% --REQUIRES preamble raiseerror renlinear renmatrix databarexpanded--
% --REQUIRES preamble raiseerror parseinput gs1lint renlinear renmatrix databarexpanded--
% --DESC: GS1 DataBar Expanded Stacked
% --EXAM: (01)95012345678903(3103)000123
% --EXOP: segments=4
% --RNDR: renlinear renmatrix
%%BeginResource: uk.co.terryburton.bwipp databarexpandedstacked 0.0 2018020400 62246 65648
%%BeginData: 43 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp databarexpandedstacked 0.0 2021092800 66639 63073
%%BeginData: 45 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
6759,12 → 8640,14
 
args (opt) options put
args
 
dontdraw not //renmatrix if
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/databarexpandedstacked dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
6773,16 → 8656,18
% --END ENCODER databarexpandedstacked--
 
% --BEGIN ENCODER gs1northamericancoupon--
% --REQUIRES preamble raiseerror renlinear renmatrix databarexpanded databarexpandedstacked--
% --REQUIRES preamble raiseerror parseinput gs1lint renlinear renmatrix databarexpanded databarexpandedstacked--
% --DESC: GS1 North American Coupon
% --EXAM: (8110)106141416543213500110000310123196000
% --EXOP: includetext segments=8
% --RNDR: renlinear renmatrix
%%BeginResource: uk.co.terryburton.bwipp gs1northamericancoupon 0.0 2018020400 88067 84250
%%BeginData: 133 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp gs1northamericancoupon 0.0 2021092800 82792 82511
%%BeginData: 131 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /gs1lint dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
dup /databarexpandedstacked dup /uk.co.terryburton.bwipp findresource put
begin
6800,6 → 8685,8
/coupontextsize 9 def
/coupontextxoffset (unset) def
/coupontextyoffset (unset) def
/parse false def
/dontlint false def
 
% Parse the input options
options type /stringtype eq {
6819,23 → 8706,12
 
% Expand ordinals of the form ^NNN to ASCII
/expand {
/in exch def
/out in length string def
/j 0 def
in
{ % loop
(^) search {
dup out exch j exch putinterval
length j add 1 add /j exch def
pop
dup 0 3 getinterval cvi out exch j 1 sub exch put
dup length 3 sub 3 exch getinterval
} {
dup out exch j exch putinterval
length j add /j exch def
out 0 j getinterval exit
} ifelse
} loop
/fncvals <<
/parse parse
/parseonly true
/parsefnc false
>> def
fncvals //parseinput exec
} bind def
 
% Parse out AIs
6865,6 → 8741,8
/bwipp.gs1northamericancouponBadAIStructure (A GS1 North American Coupon should consist of a single AI (8110)) //raiseerror exec
} if
 
dontlint not { ais vals //gs1lint exec pop } if
 
% Parse out the Company Prefix and Offer Code
/val vals 0 get def
/vli val 0 get 48 sub def
6879,6 → 8757,7
coupontext gcp length 1 add cod putinterval
 
% Get the result of encoding with databarexpandedstacked
options (parse) undef
options (dontdraw) true put
 
/args barcode options //databarexpandedstacked exec def
6909,7 → 8788,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/gs1northamericancoupon dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
6923,8 → 8804,8
% --EXAM: 117480
% --EXOP: showborder
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp pharmacode 0.0 2018020400 61634 61273
%%BeginData: 91 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp pharmacode 0.0 2021092800 54994 54752
%%BeginData: 93 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
6941,7 → 8822,7
/height 8 2.835 mul 72 div def
/nwidth 0.5 2.835 mul def
/wwidth 1.5 2.835 mul def
/swidth 1.0 2.835 mul def
/swidth 1.0 2.835 mul def
 
% Parse the input options
options type /stringtype eq {
6953,7 → 8834,7
currentdict end /options exch def
} if
options {def} forall
 
/height height cvr def
/nwidth nwidth cvr def
/wwidth wwidth cvr def
6979,7 → 8860,7
txt i [barcode i 1 getinterval 0 0 () 0] put
} for
 
% Convert the integer into the paramacode string
% Convert the integer into the paramacode string
/barcode barcode cvi 1 add 2 17 string cvrs def
/barcode barcode 1 barcode length 1 sub getinterval def
 
7012,7 → 8893,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/pharmacode dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
7026,8 → 8909,8
% --EXAM: 117480
% --EXOP: includetext showborder
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp pharmacode2 0.0 2018020400 62369 62035
%%BeginData: 96 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp pharmacode2 0.0 2021092800 55825 55610
%%BeginData: 98 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
7078,12 → 8961,10
} for
 
/encstr 16 string def
/bhs 16 array def
/bbs 16 array def
/sbs 32 array def
/bar 1 25.4 div height mul def % bar height (mm)
/spc 1 25.4 div 72 mul def % bar width & spacing (1mm)
 
% Convert number into a base3 representation
/i 15 def
/val barcode cvi def
7095,8 → 8976,10
/i i 1 sub def
} loop
/encstr encstr i 1 add 15 i sub getinterval def
 
% Generate the bar pattern
/bhs encstr length array def
/bbs encstr length array def
0 1 encstr length 1 sub {
/i exch def
encstr i get dup
7103,7 → 8986,7
bhs i bar [1 1 2] 5 -1 roll get mul put
bbs i [0 bar 0] 4 -1 roll get put
} for
 
% Return the arguments
<<
/ren //renlinear
7120,7 → 9003,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/pharmacode2 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
7134,8 → 9019,8
% --EXAM: 01234567
% --EXOP: includetext includecheck includecheckintext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp code2of5 0.0 2018020400 72227 71786
%%BeginData: 150 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp code2of5 0.0 2021092800 63389 62953
%%BeginData: 153 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
7199,12 → 9084,12
} if
 
% Create an array containing the character mappings
/versions <<
/versions <<
/industrial
[ (1111313111) (3111111131) (1131111131) (3131111111)
(1111311131) (3111311111) (1131311111) (1111113131)
(3111113111) (1131113111) (313111) (31113)
]
]
/iata
[ (1111313111) (3111111131) (1131111131) (3131111111)
(1111311131) (3111311111) (1131311111) (1111113131)
7230,13 → 9115,14
 
/cs encs 0 get length def
/cw 0 encs 0 get {48 sub add} forall def
/ss encs dup length 2 sub get length def
/sw 0 encs dup length 2 sub get {48 sub add} forall def
/ss encs 10 get length def
/sw 0 encs 10 get {48 sub add} forall def
/es encs 11 get length def
 
% Create a string of the available characters
/barchars (0123456789) def
 
/sbs barlen includecheck {1 add} if cs mul ss add ss add string def
/sbs barlen includecheck {1 add} if cs mul ss add es add string def
/txt barlen includecheck {1 add} if array def
 
% Put the start character
7282,7 → 9168,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/code2of5 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
7296,8 → 9184,8
% --EXAM: 01234567
% --EXOP: includetext includecheck includecheckintext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp industrial2of5 0.0 2018020400 57777 57523
%%BeginData: 55 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp industrial2of5 0.0 2021092800 51614 51610
%%BeginData: 57 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
7318,7 → 9206,7
/textxoffset 0 def
/textyoffset -7 def
/height 1 def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
7334,7 → 9222,7
/textsize textsize cvr def
/textxoffset textxoffset cvr def
/textyoffset textyoffset cvr def
/height height cvr def
/height height cvr def
 
% Get the result of encoding with code2of5 with version=industrial
options (dontdraw) true put
7346,10 → 9234,12
args
 
dontdraw not //renlinear if
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/industrial2of5 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
7363,8 → 9253,8
% --EXAM: 01234567
% --EXOP: includetext includecheck includecheckintext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp iata2of5 0.0 2018020400 57747 57499
%%BeginData: 55 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp iata2of5 0.0 2021092800 51712 51586
%%BeginData: 57 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
7385,7 → 9275,7
/textxoffset 0 def
/textyoffset -7 def
/height 1 def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
7401,7 → 9291,7
/textsize textsize cvr def
/textxoffset textxoffset cvr def
/textyoffset textyoffset cvr def
/height height cvr def
/height height cvr def
 
% Get the result of encoding with code2of5 with version=iata
options (dontdraw) true put
7413,10 → 9303,12
args
 
dontdraw not //renlinear if
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/iata2of5 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
7430,8 → 9322,8
% --EXAM: 01234567
% --EXOP: includetext includecheck includecheckintext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp matrix2of5 0.0 2018020400 57757 57507
%%BeginData: 55 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp matrix2of5 0.0 2021092800 51594 51594
%%BeginData: 57 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
7452,7 → 9344,7
/textxoffset 0 def
/textyoffset -7 def
/height 1 def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
7468,7 → 9360,7
/textsize textsize cvr def
/textxoffset textxoffset cvr def
/textyoffset textyoffset cvr def
/height height cvr def
/height height cvr def
 
% Get the result of encoding with code2of5 with version=matrix
options (dontdraw) true put
7480,10 → 9372,12
args
 
dontdraw not //renlinear if
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/matrix2of5 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
7497,8 → 9391,8
% --EXAM: 01234567
% --EXOP: includetext includecheck includecheckintext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp coop2of5 0.0 2018020400 57747 57499
%%BeginData: 55 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp coop2of5 0.0 2021092800 51584 51586
%%BeginData: 57 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
7519,7 → 9413,7
/textxoffset 0 def
/textyoffset -7 def
/height 1 def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
7535,7 → 9429,7
/textsize textsize cvr def
/textxoffset textxoffset cvr def
/textyoffset textyoffset cvr def
/height height cvr def
/height height cvr def
 
% Get the result of encoding with code2of5 with version=coop
options (dontdraw) true put
7547,10 → 9441,12
args
 
dontdraw not //renlinear if
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/coop2of5 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
7564,8 → 9460,8
% --EXAM: 01234567
% --EXOP: includetext includecheck includecheckintext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp datalogic2of5 0.0 2018020400 57772 57519
%%BeginData: 55 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp datalogic2of5 0.0 2021092800 51609 51606
%%BeginData: 57 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
7586,7 → 9482,7
/textxoffset 0 def
/textyoffset -7 def
/height 1 def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
7602,7 → 9498,7
/textsize textsize cvr def
/textxoffset textxoffset cvr def
/textyoffset textyoffset cvr def
/height height cvr def
/height height cvr def
 
% Get the result of encoding with code2of5 with version=datalogic
options (dontdraw) true put
7614,10 → 9510,12
args
 
dontdraw not //renlinear if
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/datalogic2of5 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
7631,8 → 9529,8
% --EXAM: 0123456789
% --EXOP: includetext includecheck includecheckintext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp code11 0.0 2018020400 75027 74603
%%BeginData: 158 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp code11 0.0 2021092800 64947 64514
%%BeginData: 160 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
7654,7 → 9552,7
/textsize 10 def
/textyoffset -7 def
/height 1 def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
7665,12 → 9563,12
currentdict end /options exch def
} if
options {def} forall
 
/textfont textfont cvlit def
/textsize textsize cvr def
/textyoffset textyoffset cvr def
/height height cvr def
 
% Create an array containing the character mappings
/encs
[ (111131) (311131) (131131) (331111) (113131)
7740,15 → 9638,15
/xpos exch enc exch get 48 sub xpos add def
} for
} for
 
% Put the checksum and end characters
includecheck {
barlen 10 ge {
sbs barlen 6 mul 6 add encs checksum1 get putinterval
sbs barlen 6 mul 6 add encs checksum1 get putinterval
sbs barlen 6 mul 12 add encs checksum2 get putinterval
includecheckintext {
txt barlen [barchars checksum1 1 getinterval xpos textyoffset textfont textsize] put
/enc encs checksum1 get def
/enc encs checksum1 get def
0 1 5 { % xpos+=width of the character
/xpos exch enc exch get 48 sub xpos add def
} for
7759,7 → 9657,7
} ifelse
sbs barlen 6 mul 18 add encs 11 get putinterval
} {
sbs barlen 6 mul 6 add encs checksum1 get putinterval
sbs barlen 6 mul 6 add encs checksum1 get putinterval
includecheckintext {
txt barlen [barchars checksum1 1 getinterval xpos textyoffset textfont textsize] put
} {
7787,7 → 9685,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/code11 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
7801,8 → 9701,8
% --EXAM: BC412
% --EXOP: semi includetext includecheckintext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp bc412 0.0 2018020400 68848 68602
%%BeginData: 148 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp bc412 0.0 2021092800 60520 60057
%%BeginData: 150 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
7826,7 → 9726,7
/textsize 10 def
/textyoffset -7 def
/height 1 def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
7837,12 → 9737,12
currentdict end /options exch def
} if
options {def} forall
 
/textfont textfont cvlit def
/textsize textsize cvr def
/textyoffset textyoffset cvr def
/height height cvr def
 
semi {
/includecheck true def
/includestartstop true def
7922,16 → 9822,16
txt barlen [() barlen 12 mul txtpos add textyoffset textfont textsize] put
} ifelse
/pos pos 8 add def
} if
} if
 
% Put the stop character
includestartstop {
includestartstop {
sbs pos encs 36 get putinterval
/pos pos 2 add def
} if
 
% Return the arguments
/sbs sbs 0 pos getinterval def
/sbs sbs 0 pos getinterval def
<<
/ren //renlinear
/sbs [sbs {48 sub} forall]
7947,7 → 9847,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/bc412 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
7961,8 → 9863,8
% --EXAM: A0123456789B
% --EXOP: includetext includecheck includecheckintext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp rationalizedCodabar 0.0 2018020400 75395 74887
%%BeginData: 156 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp rationalizedCodabar 0.0 2021092800 65315 64822
%%BeginData: 158 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
7985,7 → 9887,7
/textsize 10 def
/textyoffset -7 def
/height 1 def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
7996,12 → 9898,12
currentdict end /options exch def
} if
options {def} forall
 
/textfont textfont cvlit def
/textsize textsize cvr def
/textyoffset textyoffset cvr def
/height height cvr def
 
% Create an array containing the character mappings
/encs
[ (11111331) (11113311) (11131131) (33111111) (11311311)
8024,7 → 9926,7
16 1 19 {ssvals exch dup barchars exch 1 getinterval exch put} for
 
% Validate the input
barcode 0 1 getinterval ssvals exch known not
barcode 0 1 getinterval ssvals exch known not
barcode barcode length 1 sub 1 getinterval ssvals exch known not or {
altstartstop {
/bwipp.rationalizedCodabarBadAltStartStop (Codabar start and stop characters must be one of E N T or *) //raiseerror exec
8046,7 → 9948,7
checksum add /checksum exch def
} for
barcode barcode length 1 sub 1 getinterval charvals exch get
checksum add /checksum exch def
checksum add /checksum exch def
/checksum 16 checksum 16 mod sub 16 mod def
validatecheck {
barcode barlen 1 sub get barchars checksum get ne {
8115,7 → 10017,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/rationalizedCodabar dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
8129,8 → 10033,8
% --EXAM: 0123456709498765432101234567891
% --EXOP: barcolor=FF0000
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp onecode 0.0 2018020400 110197 113391
%%BeginData: 335 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp onecode 0.0 2021092800 99045 98718
%%BeginData: 337 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
8145,7 → 10049,7
 
/dontdraw false def
/height 0.15 def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
8156,11 → 10060,11
currentdict end /options exch def
} if
options {def} forall
 
/height height cvr def
 
/barlen barcode length def
 
% Create the human readable text
/txtdict <<
2 dup
8186,18 → 10090,18
/base exch def
/num exch def
num length 1 sub -1 1 {
/i exch def
/i exch def
num i 1 sub 2 copy get num i get base idiv add put
num i num i get base mod put
} for
{ %loop - extend input as necessary
num 0 get base lt {exit} if
/num [0 num {} forall] def
/num [0 num {} forall] def
num 0 num 0 get num 1 get base idiv add put
num 1 num 1 get base mod put
} loop
% Trim leading zeros
/num [/i true def num {dup 0 eq i and {pop} {/i false def} ifelse} forall] def
/num [/i true def num {dup 0 eq i and {pop} {/i false def} ifelse} forall] def
num length 0 eq {/num [0] def} if
num
} bind def
8206,7 → 10110,7
2 copy length exch length
2 copy sub abs /offset exch def
lt {exch} if
/a exch def /b exch def
/a exch def /b exch def
0 1 b length 1 sub {
dup a exch offset add 2 copy get b 5 -1 roll get add put
} for
8234,7 → 10138,7
bintmp j bintmp j get 256 idiv put
} for
bytes i bintmp bintmp length 1 sub get 256 mod put
bintmp bintmp length 1 sub 2 copy get 256 idiv put
bintmp bintmp length 1 sub 2 copy get 256 idiv put
} for
 
% Generation of 11-bit CRC on byte array
8242,7 → 10146,7
/dat bytes 0 get 5 bitshift def
6 {
fcs dat xor 1024 and 0 ne {
/fcs fcs 1 bitshift 3893 xor def
/fcs fcs 1 bitshift 3893 xor def
} {
/fcs fcs 1 bitshift def
} ifelse
8250,10 → 10154,10
/dat dat 1 bitshift def
} repeat
1 1 12 {
bytes exch get 3 bitshift /dat exch def
8 {
bytes exch get 3 bitshift /dat exch def
8 {
fcs dat xor 1024 and 0 ne {
/fcs fcs 1 bitshift 3893 xor def
/fcs fcs 1 bitshift 3893 xor def
} {
/fcs fcs 1 bitshift def
} ifelse
8275,7 → 10179,7
/j exch def
binval j 1 add 2 copy get binval j get b mod 10 mul add put
binval j binval j get b idiv put
} for
} for
codewords i binval binval length 1 sub get b mod put
binval binval length 1 sub 2 copy get b idiv put
} for
8288,100 → 10192,100
 
% Conversion from codewords to characters
/tab513 [
31 7936 47 7808 55 7552 59 7040 61 6016 62 3968 79 7744 87
7488 91 6976 93 5952 94 3904 103 7360 107 6848 109 5824 110 3776
115 6592 117 5568 118 3520 121 5056 122 3008 124 1984 143 7712 151
7456 155 6944 157 5920 158 3872 167 7328 171 6816 173 5792 174 3744
179 6560 181 5536 182 3488 185 5024 186 2976 188 1952 199 7264 203
6752 205 5728 206 3680 211 6496 213 5472 214 3424 217 4960 218 2912
220 1888 227 6368 229 5344 230 3296 233 4832 234 2784 236 1760 241
4576 242 2528 244 1504 248 992 271 7696 279 7440 283 6928 285 5904
286 3856 295 7312 299 6800 301 5776 302 3728 307 6544 309 5520 310
3472 313 5008 314 2960 316 1936 327 7248 331 6736 333 5712 334 3664
339 6480 341 5456 342 3408 345 4944 346 2896 348 1872 355 6352 357
5328 358 3280 361 4816 362 2768 364 1744 369 4560 370 2512 372 1488
376 976 391 7216 395 6704 397 5680 398 3632 403 6448 405 5424 406
3376 409 4912 410 2864 412 1840 419 6320 421 5296 422 3248 425 4784
426 2736 428 1712 433 4528 434 2480 436 1456 440 944 451 6256 453
5232 454 3184 457 4720 458 2672 460 1648 465 4464 466 2416 468 1392
472 880 481 4336 482 2288 484 1264 488 752 527 7688 535 7432 539
6920 541 5896 542 3848 551 7304 555 6792 557 5768 558 3720 563 6536
565 5512 566 3464 569 5000 570 2952 572 1928 583 7240 587 6728 589
5704 590 3656 595 6472 597 5448 598 3400 601 4936 602 2888 604 1864
611 6344 613 5320 614 3272 617 4808 618 2760 620 1736 625 4552 626
2504 628 1480 632 968 647 7208 651 6696 653 5672 654 3624 659 6440
661 5416 662 3368 665 4904 666 2856 668 1832 675 6312 677 5288 678
3240 681 4776 682 2728 684 1704 689 4520 690 2472 692 1448 696 936
707 6248 709 5224 710 3176 713 4712 714 2664 716 1640 721 4456 722
2408 724 1384 728 872 737 4328 738 2280 740 1256 775 7192 779 6680
781 5656 782 3608 787 6424 789 5400 790 3352 793 4888 794 2840 796
1816 803 6296 805 5272 806 3224 809 4760 810 2712 812 1688 817 4504
818 2456 820 1432 824 920 835 6232 837 5208 838 3160 841 4696 842
2648 844 1624 849 4440 850 2392 852 1368 865 4312 866 2264 868 1240
899 6200 901 5176 902 3128 905 4664 906 2616 908 1592 913 4408 914
2360 916 1336 929 4280 930 2232 932 1208 961 4216 962 2168 964 1144
1039 7684 1047 7428 1051 6916 1053 5892 1054 3844 1063 7300 1067 6788 1069
5764 1070 3716 1075 6532 1077 5508 1078 3460 1081 4996 1082 2948 1084 1924
1095 7236 1099 6724 1101 5700 1102 3652 1107 6468 1109 5444 1110 3396 1113
4932 1114 2884 1116 1860 1123 6340 1125 5316 1126 3268 1129 4804 1130 2756
1132 1732 1137 4548 1138 2500 1140 1476 1159 7204 1163 6692 1165 5668 1166
3620 1171 6436 1173 5412 1174 3364 1177 4900 1178 2852 1180 1828 1187 6308
1189 5284 1190 3236 1193 4772 1194 2724 1196 1700 1201 4516 1202 2468 1204
1444 1219 6244 1221 5220 1222 3172 1225 4708 1226 2660 1228 1636 1233 4452
1234 2404 1236 1380 1249 4324 1250 2276 1287 7188 1291 6676 1293 5652 1294
3604 1299 6420 1301 5396 1302 3348 1305 4884 1306 2836 1308 1812 1315 6292
1317 5268 1318 3220 1321 4756 1322 2708 1324 1684 1329 4500 1330 2452 1332
1428 1347 6228 1349 5204 1350 3156 1353 4692 1354 2644 1356 1620 1361 4436
1362 2388 1377 4308 1378 2260 1411 6196 1413 5172 1414 3124 1417 4660 1418
2612 1420 1588 1425 4404 1426 2356 1441 4276 1442 2228 1473 4212 1474 2164
1543 7180 1547 6668 1549 5644 1550 3596 1555 6412 1557 5388 1558 3340 1561
4876 1562 2828 1564 1804 1571 6284 1573 5260 1574 3212 1577 4748 1578 2700
1580 1676 1585 4492 1586 2444 1603 6220 1605 5196 1606 3148 1609 4684 1610
2636 1617 4428 1618 2380 1633 4300 1634 2252 1667 6188 1669 5164 1670 3116
1673 4652 1674 2604 1681 4396 1682 2348 1697 4268 1698 2220 1729 4204 1730
2156 1795 6172 1797 5148 1798 3100 1801 4636 1802 2588 1809 4380 1810 2332
1825 4252 1826 2204 1857 4188 1858 2140 1921 4156 1922 2108 2063 7682 2071
7426 2075 6914 2077 5890 2078 3842 2087 7298 2091 6786 2093 5762 2094 3714
2099 6530 2101 5506 2102 3458 2105 4994 2106 2946 2119 7234 2123 6722 2125
5698 2126 3650 2131 6466 2133 5442 2134 3394 2137 4930 2138 2882 2147 6338
2149 5314 2150 3266 2153 4802 2154 2754 2161 4546 2162 2498 2183 7202 2187
6690 2189 5666 2190 3618 2195 6434 2197 5410 2198 3362 2201 4898 2202 2850
2211 6306 2213 5282 2214 3234 2217 4770 2218 2722 2225 4514 2226 2466 2243
6242 2245 5218 2246 3170 2249 4706 2250 2658 2257 4450 2258 2402 2273 4322
2311 7186 2315 6674 2317 5650 2318 3602 2323 6418 2325 5394 2326 3346 2329
4882 2330 2834 2339 6290 2341 5266 2342 3218 2345 4754 2346 2706 2353 4498
2354 2450 2371 6226 2373 5202 2374 3154 2377 4690 2378 2642 2385 4434 2401
4306 2435 6194 2437 5170 2438 3122 2441 4658 2442 2610 2449 4402 2465 4274
2497 4210 2567 7178 2571 6666 2573 5642 2574 3594 2579 6410 2581 5386 2582
3338 2585 4874 2586 2826 2595 6282 2597 5258 2598 3210 2601 4746 2602 2698
2609 4490 2627 6218 2629 5194 2630 3146 2633 4682 2641 4426 2657 4298 2691
6186 2693 5162 2694 3114 2697 4650 2705 4394 2721 4266 2753 4202 2819 6170
2821 5146 2822 3098 2825 4634 2833 4378 2849 4250 2881 4186 2945 4154 3079
7174 3083 6662 3085 5638 3086 3590 3091 6406 3093 5382 3094 3334 3097 4870
3107 6278 3109 5254 3110 3206 3113 4742 3121 4486 3139 6214 3141 5190 3145
4678 3153 4422 3169 4294 3203 6182 3205 5158 3209 4646 3217 4390 3233 4262
3265 4198 3331 6166 3333 5142 3337 4630 3345 4374 3361 4246 3393 4182 3457
4150 3587 6158 3589 5134 3593 4622 3601 4366 3617 4238 3649 4174 3713 4142
3841 4126 4111 7681 4119 7425 4123 6913 4125 5889 4135 7297 4139 6785 4141
5761 4147 6529 4149 5505 4153 4993 4167 7233 4171 6721 4173 5697 4179 6465
4181 5441 4185 4929 4195 6337 4197 5313 4201 4801 4209 4545 4231 7201 4235
6689 4237 5665 4243 6433 4245 5409 4249 4897 4259 6305 4261 5281 4265 4769
4273 4513 4291 6241 4293 5217 4297 4705 4305 4449 4359 7185 4363 6673 4365
5649 4371 6417 4373 5393 4377 4881 4387 6289 4389 5265 4393 4753 4401 4497
4419 6225 4421 5201 4425 4689 4483 6193 4485 5169 4489 4657 4615 7177 4619
6665 4621 5641 4627 6409 4629 5385 4633 4873 4643 6281 4645 5257 4649 4745
4675 6217 4677 5193 4739 6185 4741 5161 4867 6169 4869 5145 5127 7173 5131
6661 5133 5637 5139 6405 5141 5381 5155 6277 5157 5253 5187 6213 5251 6181
5379 6165 5635 6157 6151 7171 6155 6659 6163 6403 6179 6275 6211 5189 4681
4433 4321 3142 2634 2386 2274 1612 1364 1252 856 744 496
31 7936 47 7808 55 7552 59 7040 61 6016 62 3968 79 7744 87
7488 91 6976 93 5952 94 3904 103 7360 107 6848 109 5824 110 3776
115 6592 117 5568 118 3520 121 5056 122 3008 124 1984 143 7712 151
7456 155 6944 157 5920 158 3872 167 7328 171 6816 173 5792 174 3744
179 6560 181 5536 182 3488 185 5024 186 2976 188 1952 199 7264 203
6752 205 5728 206 3680 211 6496 213 5472 214 3424 217 4960 218 2912
220 1888 227 6368 229 5344 230 3296 233 4832 234 2784 236 1760 241
4576 242 2528 244 1504 248 992 271 7696 279 7440 283 6928 285 5904
286 3856 295 7312 299 6800 301 5776 302 3728 307 6544 309 5520 310
3472 313 5008 314 2960 316 1936 327 7248 331 6736 333 5712 334 3664
339 6480 341 5456 342 3408 345 4944 346 2896 348 1872 355 6352 357
5328 358 3280 361 4816 362 2768 364 1744 369 4560 370 2512 372 1488
376 976 391 7216 395 6704 397 5680 398 3632 403 6448 405 5424 406
3376 409 4912 410 2864 412 1840 419 6320 421 5296 422 3248 425 4784
426 2736 428 1712 433 4528 434 2480 436 1456 440 944 451 6256 453
5232 454 3184 457 4720 458 2672 460 1648 465 4464 466 2416 468 1392
472 880 481 4336 482 2288 484 1264 488 752 527 7688 535 7432 539
6920 541 5896 542 3848 551 7304 555 6792 557 5768 558 3720 563 6536
565 5512 566 3464 569 5000 570 2952 572 1928 583 7240 587 6728 589
5704 590 3656 595 6472 597 5448 598 3400 601 4936 602 2888 604 1864
611 6344 613 5320 614 3272 617 4808 618 2760 620 1736 625 4552 626
2504 628 1480 632 968 647 7208 651 6696 653 5672 654 3624 659 6440
661 5416 662 3368 665 4904 666 2856 668 1832 675 6312 677 5288 678
3240 681 4776 682 2728 684 1704 689 4520 690 2472 692 1448 696 936
707 6248 709 5224 710 3176 713 4712 714 2664 716 1640 721 4456 722
2408 724 1384 728 872 737 4328 738 2280 740 1256 775 7192 779 6680
781 5656 782 3608 787 6424 789 5400 790 3352 793 4888 794 2840 796
1816 803 6296 805 5272 806 3224 809 4760 810 2712 812 1688 817 4504
818 2456 820 1432 824 920 835 6232 837 5208 838 3160 841 4696 842
2648 844 1624 849 4440 850 2392 852 1368 865 4312 866 2264 868 1240
899 6200 901 5176 902 3128 905 4664 906 2616 908 1592 913 4408 914
2360 916 1336 929 4280 930 2232 932 1208 961 4216 962 2168 964 1144
1039 7684 1047 7428 1051 6916 1053 5892 1054 3844 1063 7300 1067 6788 1069
5764 1070 3716 1075 6532 1077 5508 1078 3460 1081 4996 1082 2948 1084 1924
1095 7236 1099 6724 1101 5700 1102 3652 1107 6468 1109 5444 1110 3396 1113
4932 1114 2884 1116 1860 1123 6340 1125 5316 1126 3268 1129 4804 1130 2756
1132 1732 1137 4548 1138 2500 1140 1476 1159 7204 1163 6692 1165 5668 1166
3620 1171 6436 1173 5412 1174 3364 1177 4900 1178 2852 1180 1828 1187 6308
1189 5284 1190 3236 1193 4772 1194 2724 1196 1700 1201 4516 1202 2468 1204
1444 1219 6244 1221 5220 1222 3172 1225 4708 1226 2660 1228 1636 1233 4452
1234 2404 1236 1380 1249 4324 1250 2276 1287 7188 1291 6676 1293 5652 1294
3604 1299 6420 1301 5396 1302 3348 1305 4884 1306 2836 1308 1812 1315 6292
1317 5268 1318 3220 1321 4756 1322 2708 1324 1684 1329 4500 1330 2452 1332
1428 1347 6228 1349 5204 1350 3156 1353 4692 1354 2644 1356 1620 1361 4436
1362 2388 1377 4308 1378 2260 1411 6196 1413 5172 1414 3124 1417 4660 1418
2612 1420 1588 1425 4404 1426 2356 1441 4276 1442 2228 1473 4212 1474 2164
1543 7180 1547 6668 1549 5644 1550 3596 1555 6412 1557 5388 1558 3340 1561
4876 1562 2828 1564 1804 1571 6284 1573 5260 1574 3212 1577 4748 1578 2700
1580 1676 1585 4492 1586 2444 1603 6220 1605 5196 1606 3148 1609 4684 1610
2636 1617 4428 1618 2380 1633 4300 1634 2252 1667 6188 1669 5164 1670 3116
1673 4652 1674 2604 1681 4396 1682 2348 1697 4268 1698 2220 1729 4204 1730
2156 1795 6172 1797 5148 1798 3100 1801 4636 1802 2588 1809 4380 1810 2332
1825 4252 1826 2204 1857 4188 1858 2140 1921 4156 1922 2108 2063 7682 2071
7426 2075 6914 2077 5890 2078 3842 2087 7298 2091 6786 2093 5762 2094 3714
2099 6530 2101 5506 2102 3458 2105 4994 2106 2946 2119 7234 2123 6722 2125
5698 2126 3650 2131 6466 2133 5442 2134 3394 2137 4930 2138 2882 2147 6338
2149 5314 2150 3266 2153 4802 2154 2754 2161 4546 2162 2498 2183 7202 2187
6690 2189 5666 2190 3618 2195 6434 2197 5410 2198 3362 2201 4898 2202 2850
2211 6306 2213 5282 2214 3234 2217 4770 2218 2722 2225 4514 2226 2466 2243
6242 2245 5218 2246 3170 2249 4706 2250 2658 2257 4450 2258 2402 2273 4322
2311 7186 2315 6674 2317 5650 2318 3602 2323 6418 2325 5394 2326 3346 2329
4882 2330 2834 2339 6290 2341 5266 2342 3218 2345 4754 2346 2706 2353 4498
2354 2450 2371 6226 2373 5202 2374 3154 2377 4690 2378 2642 2385 4434 2401
4306 2435 6194 2437 5170 2438 3122 2441 4658 2442 2610 2449 4402 2465 4274
2497 4210 2567 7178 2571 6666 2573 5642 2574 3594 2579 6410 2581 5386 2582
3338 2585 4874 2586 2826 2595 6282 2597 5258 2598 3210 2601 4746 2602 2698
2609 4490 2627 6218 2629 5194 2630 3146 2633 4682 2641 4426 2657 4298 2691
6186 2693 5162 2694 3114 2697 4650 2705 4394 2721 4266 2753 4202 2819 6170
2821 5146 2822 3098 2825 4634 2833 4378 2849 4250 2881 4186 2945 4154 3079
7174 3083 6662 3085 5638 3086 3590 3091 6406 3093 5382 3094 3334 3097 4870
3107 6278 3109 5254 3110 3206 3113 4742 3121 4486 3139 6214 3141 5190 3145
4678 3153 4422 3169 4294 3203 6182 3205 5158 3209 4646 3217 4390 3233 4262
3265 4198 3331 6166 3333 5142 3337 4630 3345 4374 3361 4246 3393 4182 3457
4150 3587 6158 3589 5134 3593 4622 3601 4366 3617 4238 3649 4174 3713 4142
3841 4126 4111 7681 4119 7425 4123 6913 4125 5889 4135 7297 4139 6785 4141
5761 4147 6529 4149 5505 4153 4993 4167 7233 4171 6721 4173 5697 4179 6465
4181 5441 4185 4929 4195 6337 4197 5313 4201 4801 4209 4545 4231 7201 4235
6689 4237 5665 4243 6433 4245 5409 4249 4897 4259 6305 4261 5281 4265 4769
4273 4513 4291 6241 4293 5217 4297 4705 4305 4449 4359 7185 4363 6673 4365
5649 4371 6417 4373 5393 4377 4881 4387 6289 4389 5265 4393 4753 4401 4497
4419 6225 4421 5201 4425 4689 4483 6193 4485 5169 4489 4657 4615 7177 4619
6665 4621 5641 4627 6409 4629 5385 4633 4873 4643 6281 4645 5257 4649 4745
4675 6217 4677 5193 4739 6185 4741 5161 4867 6169 4869 5145 5127 7173 5131
6661 5133 5637 5139 6405 5141 5381 5155 6277 5157 5253 5187 6213 5251 6181
5379 6165 5635 6157 6151 7171 6155 6659 6163 6403 6179 6275 6211 5189 4681
4433 4321 3142 2634 2386 2274 1612 1364 1252 856 744 496
] def
 
/tab213 [
3 6144 5 5120 6 3072 9 4608 10 2560 12 1536 17 4352 18
2304 20 1280 24 768 33 4224 34 2176 36 1152 40 640 48 384
65 4160 66 2112 68 1088 72 576 80 320 96 192 129 4128 130
2080 132 1056 136 544 144 288 257 4112 258 2064 260 1040 264 528
513 4104 514 2056 516 1032 1025 4100 1026 2052 2049 4098 4097 2050 1028
3 6144 5 5120 6 3072 9 4608 10 2560 12 1536 17 4352 18
2304 20 1280 24 768 33 4224 34 2176 36 1152 40 640 48 384
65 4160 66 2112 68 1088 72 576 80 320 96 192 129 4128 130
2080 132 1056 136 544 144 288 257 4112 258 2064 260 1040 264 528
513 4104 514 2056 516 1032 1025 4100 1026 2052 2049 4098 4097 2050 1028
520 272 160
] def
 
8389,7 → 10293,7
0 1 9 {
/i exch def
codewords i get dup 1286 le {
tab513 exch get
tab513 exch get
} {
tab213 exch 1287 sub get
} ifelse
8420,7 → 10324,7
4 7 7 5 0 12 1 11 2 9 9 0 6 8 5 3 3 10 8 2
] def
 
/bbs 65 array def
/bbs 65 array def
/bhs 65 array def
0 1 64 {
/i exch def
8432,18 → 10336,18
} if
dec not asc and {
bbs i 3 height mul 8 div put
bhs i 5 height mul 8 div put
bhs i 5 height mul 8 div put
} if
dec asc not and {
bbs i 0 height mul 8 div put
bhs i 5 height mul 8 div put
bhs i 5 height mul 8 div put
} if
dec asc and {
bbs i 0 height mul 8 div put
bhs i 8 height mul 8 div put
bhs i 8 height mul 8 div put
} if
} for
 
% Return the arguments
<<
/ren //renlinear
8462,7 → 10366,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/onecode dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
8476,8 → 10382,8
% --EXAM: 01234
% --EXOP: includetext includecheckintext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp postnet 0.0 2018020400 69622 69308
%%BeginData: 140 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp postnet 0.0 2021092800 61190 60891
%%BeginData: 142 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
8498,7 → 10404,7
/textsize 10 def
/textyoffset -7 def
/height 0.125 def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
8509,12 → 10415,12
currentdict end /options exch def
} if
options {def} forall
 
/textfont textfont cvlit def
/textsize textsize cvr def
/textyoffset textyoffset cvr def
/height height cvr def
 
/barlen barcode length validatecheck {1 sub} if def
 
% Validate the input
8581,14 → 10487,14
/j exch def
heights j enc j 1 getinterval cvi height mul 5 div put
} for
bhs barlen 5 mul 1 add heights putinterval
bhs barlen 5 mul 1 add heights putinterval
 
includecheckintext {
txt barlen [barchars checksum 1 getinterval barlen 5 mul 1 add 3.312 mul textyoffset textfont textsize] put
} {
txt barlen [( ) barlen 5 mul 1 add 72 mul 25 div textyoffset textfont textsize] put
} ifelse
 
% Put end character
/enc encs 11 get def
/heights enc length array def
8596,7 → 10502,7
/j exch def
heights j enc j 1 getinterval cvi height mul 5 div put
} for
bhs barlen 5 mul 6 add heights putinterval
bhs barlen 5 mul 6 add heights putinterval
 
% Return the arguments
<<
8614,7 → 10520,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/postnet dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
8628,8 → 10536,8
% --EXAM: 01234567890
% --EXOP: includetext includecheckintext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp planet 0.0 2018020400 69418 69108
%%BeginData: 141 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp planet 0.0 2021092800 61050 60755
%%BeginData: 143 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
8650,7 → 10558,7
/textsize 10 def
/textyoffset -7 def
/height 0.125 def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
8661,7 → 10569,7
currentdict end /options exch def
} if
options {def} forall
 
/textfont textfont cvlit def
/textsize textsize cvr def
/textyoffset textyoffset cvr def
8734,14 → 10642,14
/j exch def
heights j enc j 1 getinterval cvi height mul 5 div put
} for
bhs barlen 5 mul 1 add heights putinterval
bhs barlen 5 mul 1 add heights putinterval
 
includecheckintext {
txt barlen [barchars checksum 1 getinterval barlen 5 mul 1 add 3.312 mul textyoffset textfont textsize] put
} {
txt barlen [( ) barlen 5 mul 1 add 72 mul 25 div textyoffset textfont textsize] put
} ifelse
 
% Put end character
/enc encs 11 get def
/heights enc length array def
8749,7 → 10657,7
/j exch def
heights j enc j 1 getinterval cvi height mul 5 div put
} for
bhs barlen 5 mul 6 add heights putinterval
bhs barlen 5 mul 6 add heights putinterval
 
% Return the arguments
<<
8767,7 → 10675,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/planet dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
8781,8 → 10691,8
% --EXAM: LE28HS9Z
% --EXOP: includetext barcolor=FF0000
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp royalmail 0.0 2018020400 70365 70114
%%BeginData: 145 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp royalmail 0.0 2021092800 61861 61521
%%BeginData: 147 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
8803,7 → 10713,7
/textsize 10 def
/textyoffset -7 def
/height 0.175 def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
8814,7 → 10724,7
currentdict end /options exch def
} if
options {def} forall
 
/textfont textfont cvlit def
/textsize textsize cvr def
/textyoffset textyoffset cvr def
8840,7 → 10750,7
/i exch def
/indx charvals barcode i 1 getinterval get def
/checksumrow checksumrow indx 6 idiv add def
/checksumcol checksumcol indx 6 mod add def
/checksumcol checksumcol indx 6 mod add def
} for
/checksum checksumrow 6 mod 6 mul checksumcol 6 mod add def
validatecheck {
8852,12 → 10762,12
 
% Create an array containing the character mappings
/encs
[ (3300) (2211) (2301) (2310) (3201) (3210)
(1122) (0033) (0123) (0132) (1023) (1032)
(1302) (0213) (0303) (0312) (1203) (1212)
(1320) (0231) (0321) (0330) (1221) (1230)
(3102) (2013) (2103) (2112) (3003) (3012)
(3120) (2031) (2121) (2130) (3021) (3030)
[ (3300) (2211) (2301) (2310) (3201) (3210)
(1122) (0033) (0123) (0132) (1023) (1032)
(1302) (0213) (0303) (0312) (1203) (1212)
(1320) (0231) (0321) (0330) (1221) (1230)
(3102) (2013) (2103) (2112) (3003) (3012)
(3120) (2031) (2121) (2130) (3021) (3030)
(2) (3)
] def
 
8866,7 → 10776,7
 
% Put start character
encstr 0 encs 36 get putinterval
 
0 1 barlen 1 sub {
/i exch def
/indx charvals barcode i 1 getinterval get def
8881,11 → 10791,11
} {
txt barlen [( ) barlen 4 mul 1 add 3.312 mul textyoffset textfont textsize] put
} ifelse
 
% Put end character
encstr barlen 4 mul 5 add encs 37 get putinterval
encstr barlen 4 mul 5 add encs 37 get putinterval
 
/bbs encstr length array def
/bbs encstr length array def
/bhs encstr length array def
0 1 encstr length 1 sub {
/i exch def
8907,7 → 10817,7
bhs i 8 height mul 8 div put
} if
} for
 
% Return the arguments
<<
/ren //renlinear
8924,7 → 10834,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/royalmail dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
8938,8 → 10850,8
% --EXAM: 5956439111ABA 9
% --EXOP: includetext custinfoenc=character
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp auspost 0.0 2018020400 82569 82192
%%BeginData: 202 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp auspost 0.0 2021092800 72673 72415
%%BeginData: 204 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
8959,7 → 10871,7
/textyoffset -7 def
/height 0.175 def
/custinfoenc (character) def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
8970,7 → 10882,7
currentdict end /options exch def
} if
options {def} forall
 
/textfont textfont cvlit def
/textsize textsize cvr def
/textyoffset textyoffset cvr def
8992,7 → 10904,7
 
% Create a string of the available characters
/barchars (ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz #) def
 
/barlen barcode length def
barcode 0 2 getinterval (11) eq {37} if
barcode 0 2 getinterval (45) eq {37} if
9006,20 → 10918,20
 
% Encode the FCC
0 1 1 {
/i exch def
/i exch def
encs barcode i 1 getinterval cvi 64 add get
encstr i 2 mul 2 add 3 2 roll putinterval
} for
 
% Encode the DPID
2 1 9 {
/i exch def
/i exch def
encs barcode i 1 getinterval cvi 64 add get
encstr i 2 mul 2 add 3 2 roll putinterval
txt i 2 sub [barcode i 1 getinterval i 2 sub 2 mul 6 add 3.312 mul textyoffset textfont textsize] put
} for
% Encode the customer information
 
% Encode the customer information
custinfoenc (numeric) eq {
0 1 barlen 11 sub {
/i exch def
9026,37 → 10938,37
encs barcode i 10 add 1 getinterval cvi 64 add get
encstr i 2 mul 22 add 3 2 roll putinterval
txt i 8 add [barcode i 10 add 1 getinterval i 2 mul 22 add 3.312 mul textyoffset textfont textsize] put
} for
} for
/ciflen barlen 10 sub 2 mul def
} {
0 1 barlen 11 sub {
/i exch def
/i exch def
barcode i 10 add 1 getinterval barchars exch search
pop
length /indx exch def
pop pop
/enc encs indx get def
pop
length /indx exch def
pop pop
/enc encs indx get def
encstr i 3 mul 22 add enc putinterval
txt i 8 add [barcode i 10 add 1 getinterval i 3 mul 22 add 3.312 mul textyoffset textfont textsize] put
} for
} for
/ciflen barlen 10 sub 3 mul def
} ifelse
 
% Add any filler characters
22 ciflen add 1 encstr length 14 sub {
22 ciflen add 1 encstr length 14 sub {
encstr exch encs 75 get putinterval
} for
 
% Create the 64x64 Reed-Solomon table
/rstable 64 64 mul array def
rstable 0 [ 64 {0} repeat ] putinterval
rstable 64 [ 0 1 63 {} for ] putinterval
/prev 1 def
64 {
64 {
/next prev 1 bitshift def
next 64 and 0 ne {
/next next 67 xor def
} if
} if
0 1 63 {
/j exch def
/nextcell {rstable 64 next mul j add} def
9067,7 → 10979,7
} for
/prev next def
} repeat
 
% Calculate the Reed-Solomon codes for triples
/rscodes encstr length 16 sub 3 idiv 4 add array def
rscodes 0 [ 4 {0} repeat ] putinterval
9076,9 → 10988,9
rscodes rscodes length i 2 sub 3 idiv sub 1 sub
encstr i 1 getinterval cvi 16 mul
encstr i 1 add 1 getinterval cvi 4 mul add
encstr i 2 add 1 getinterval cvi add
encstr i 2 add 1 getinterval cvi add
put
} for
} for
rscodes length 5 sub -1 0 {
/i exch def
0 1 4 {
9094,12 → 11006,12
/enc rscodes 3 i sub get 4 3 string cvrs def
checkcode i 3 mul 3 enc length sub add enc putinterval
} for
 
% Put checkcode and end characters
encstr encstr length 14 sub checkcode putinterval
encstr encstr length 2 sub encs 74 get putinterval
encstr encstr length 2 sub encs 74 get putinterval
 
/bbs encstr length array def
/bbs encstr length array def
/bhs encstr length array def
0 1 encstr length 1 sub {
/i exch def
9120,8 → 11032,8
bbs i 3 height mul 8 div put
bhs i 2 height mul 8 div put
} if
} for
} for
 
% Return the arguments
<<
/ren //renlinear
9138,7 → 11050,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/auspost dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
9152,8 → 11066,8
% --EXAM: 1231FZ13XHS
% --EXOP: includetext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp kix 0.0 2018020400 64411 64309
%%BeginData: 111 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp kix 0.0 2021092800 57107 57044
%%BeginData: 113 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
9172,7 → 11086,7
/textsize 10 def
/textyoffset -7 def
/height 0.175 def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
9183,20 → 11097,20
currentdict end /options exch def
} if
options {def} forall
 
/textfont textfont cvlit def
/textsize textsize cvr def
/textyoffset textyoffset cvr def
/height height cvr def
 
% Create an array containing the character mappings
/encs
[ (0033) (0123) (0132) (1023) (1032) (1122)
(0213) (0303) (0312) (1203) (1212) (1302)
(0213) (0303) (0312) (1203) (1212) (1302)
(0231) (0321) (0330) (1221) (1230) (1320)
(2013) (2103) (2112) (3003) (3012) (3102)
(2031) (2121) (2130) (3021) (3030) (3120)
(2211) (2301) (2310) (3201) (3210) (3300)
(2031) (2121) (2130) (3021) (3030) (3120)
(2211) (2301) (2310) (3201) (3210) (3300)
] def
 
% Create a string of the available characters
9214,7 → 11128,7
/barlen barcode length def
/encstr barlen 4 mul string def
/txt barlen array def
 
0 1 barlen 1 sub {
/i exch def
/indx charvals barcode i 1 getinterval get def
9222,7 → 11136,7
txt i [barcode i 1 getinterval i 4 mul 3.312 mul textyoffset textfont textsize] put
} for
 
/bbs encstr length array def
/bbs encstr length array def
/bhs encstr length array def
0 1 encstr length 1 sub {
/i exch def
9244,7 → 11158,7
bhs i 8 height mul 8 div put
} if
} for
 
% Return the arguments
<<
/ren //renlinear
9261,7 → 11175,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/kix dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
9275,8 → 11191,8
% --EXAM: 6540123789-A-K-Z
% --EXOP: includetext includecheckintext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp japanpost 0.0 2018020400 70942 70662
%%BeginData: 162 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp japanpost 0.0 2021092800 62022 61757
%%BeginData: 164 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
9296,7 → 11212,7
/textsize 10 def
/textyoffset -7 def
/height 0.175 def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
9307,17 → 11223,17
currentdict end /options exch def
} if
options {def} forall
 
/textfont textfont cvlit def
/textsize textsize cvr def
/textyoffset textyoffset cvr def
/height height cvr def
 
% Create an array containing the character mappings
% 0123456789- C1C2C3C4C5C6C7C8 ST EN
/encs
[ (300) (330) (312) (132) (321) (303) (123) (231) (213) (033) (030)
(120) (102) (210) (012) (201) (021) (003) (333)
(120) (102) (210) (012) (201) (021) (003) (333)
(31) (13)
] def
 
9324,7 → 11240,7
% Create a string of the available characters
/barchars (0123456789-ABCDEFGHIJKLMNOPQRSTUVWXYZ) def
/barlen barcode length def
 
/encstr 20 1 add 3 mul 4 add string def
/digits 20 array def
/txt barlen 1 add array def
9435,7 → 11351,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/japanpost dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
9449,8 → 11367,8
% --EXAM: 0123456789
% --EXOP: includetext includecheck includecheckintext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp msi 0.0 2018020400 74529 74247
%%BeginData: 139 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp msi 0.0 2021092800 67297 66798
%%BeginData: 141 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
9473,7 → 11391,7
/textsize 10 def
/textyoffset -7 def
/height 1 def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
9484,12 → 11402,12
currentdict end /options exch def
} if
options {def} forall
 
/textfont textfont cvlit def
/textsize textsize cvr def
/textyoffset textyoffset cvr def
/height height cvr def
 
% Create an array containing the character mappings
/encs
[ (12121212) (12121221) (12122112) (12122121) (12211212)
9505,7 → 11423,7
 
/mod10 {
/code exch def
0 0 code {48 sub exch 10 mul add exch} forall pop 2 mul
0 0 code {48 sub exch 10 mul add exch} forall pop 2 mul
0 {1 index 10 mod add exch 10 idiv dup 0 eq {pop exit} if exch} loop
0 0 code {48 sub add exch} forall exch pop add
10 mod 10 exch sub 10 mod
9515,7 → 11433,7
/mod11 {
/code exch def
code length 1 sub code {48 sub exch dup 1 sub exch 6 mod 2 add exch} forall pop
0 code length {3 1 roll mul add} repeat
0 code length {3 1 roll mul add} repeat
11 mod 11 exch sub 11 mod
dup 10 eq badmod11 and {
pop code length 2 add string dup 0 code putinterval dup code length (10) putinterval
9527,7 → 11445,7
/ncrmod11 {
/code exch def
code length 1 sub code {48 sub exch dup 1 sub exch 8 mod 2 add exch} forall pop
0 code length {3 1 roll mul add} repeat
0 code length {3 1 roll mul add} repeat
11 mod 11 exch sub 11 mod
dup 10 eq badmod11 and {
pop code length 2 add string dup 0 code putinterval dup code length (10) putinterval
9586,7 → 11504,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/msi dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
9600,8 → 11520,8
% --EXAM: 01234ABCD
% --EXOP: includetext includecheckintext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp plessey 0.0 2018020400 72431 72054
%%BeginData: 146 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp plessey 0.0 2021092800 63687 63197
%%BeginData: 148 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
9623,7 → 11543,7
/textsize 10 def
/textyoffset -7 def
/height 1 def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
9634,12 → 11554,12
currentdict end /options exch def
} if
options {def} forall
 
/textfont textfont cvlit def
/textsize textsize cvr def
/textyoffset textyoffset cvr def
/height height cvr def
 
% Create a string of the available characters
/barchars (0123456789ABCDEF) def
/charvals 16 dict def
9744,7 → 11664,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/plessey dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
9753,16 → 11675,17
% --END ENCODER plessey--
 
% --BEGIN ENCODER telepen--
% --REQUIRES preamble raiseerror renlinear--
% --REQUIRES preamble raiseerror parseinput renlinear--
% --DESC: Telepen
% --EXAM: ABCDEF
% --EXOP: includetext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp telepen 0.0 2018020400 73389 73189
%%BeginData: 173 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp telepen 0.0 2021092800 65612 65365
%%BeginData: 165 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/telepen {
9798,25 → 11721,14
/height height cvr def
 
% Parse ordinals of the form ^NNN to ASCII
parse {
/msg barcode length string def
/j 0 def
barcode
{ % loop
(^) search {
dup msg exch j exch putinterval
length j add 1 add /j exch def
pop
dup 0 3 getinterval cvi msg exch j 1 sub exch put
dup length 3 sub 3 exch getinterval
} {
dup msg exch j exch putinterval
length j add /j exch def
/barcode msg 0 j getinterval def
exit
} ifelse
} loop
} if
/fncvals <<
/parse parse
/parseonly true
/parsefnc false
>> def
/barcode barcode fncvals //parseinput exec def
/barlen barcode length def
options (parse) undef
 
% Create an array containing the character mappings
/encs
9868,7 → 11780,7
{ % loop
i barlen eq {exit} if
numeric { % numeric mode: 00-99 & 0X-9X
barcode i get 16 gt {
barcode i get 16 gt {
/np barcode i 2 getinterval def
np 1 1 getinterval (X) eq { % X in even position amongst digits
/indx np 0 1 getinterval cvi 17 add def
9929,7 → 11841,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/telepen dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
9938,13 → 11852,13
% --END ENCODER telepen--
 
% --BEGIN ENCODER telepennumeric--
% --REQUIRES preamble raiseerror renlinear telepen--
% --REQUIRES preamble raiseerror parseinput renlinear telepen--
% --DESC: Telepen Numeric
% --EXAM: 01234567
% --EXOP: includetext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp telepennumeric 0.0 2018020400 57757 57607
%%BeginData: 55 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp telepennumeric 0.0 2021092800 54465 57771
%%BeginData: 57 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
9965,7 → 11879,7
/textxoffset 0 def
/textyoffset -7 def
/height 1 def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
9981,7 → 11895,7
/textsize textsize cvr def
/textxoffset textxoffset cvr def
/textyoffset textyoffset cvr def
/height height cvr def
/height height cvr def
 
% Get the result of encoding with code2of5 with version=industrial
options (dontdraw) true put
9993,10 → 11907,12
args
 
dontdraw not //renlinear if
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/telepennumeric dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
10005,16 → 11921,17
% --END ENCODER telepennumeric--
 
% --BEGIN ENCODER posicode--
% --REQUIRES preamble raiseerror renlinear--
% --REQUIRES preamble raiseerror parseinput renlinear--
% --DESC: PosiCode
% --EXAM: ABC123
% --EXOP: version=b inkspread=-0.5 parsefnc includetext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp posicode 0.0 2018020400 121292 127720
%%BeginData: 423 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp posicode 0.0 2021092800 107308 106674
%%BeginData: 390 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/posicode {
10058,32 → 11975,9
/checkoffset checkoffset cvi def
/height height cvr def
 
% Parse ordinals of the form ^NNN to ASCII
parse {
/msg barcode length string def
/j 0 def
barcode
{ % loop
(^) search {
dup msg exch j exch putinterval
length j add 1 add /j exch def
pop
dup 0 3 getinterval cvi msg exch j 1 sub exch put
dup length 3 sub 3 exch getinterval
} {
dup msg exch j exch putinterval
length j add /j exch def
/barcode msg 0 j getinterval def
exit
} ifelse
} loop
} if
 
/barlen barcode length def
 
% Special function characters
/la0 -1 def /la1 -2 def /la2 -3 def
/sf0 -4 def /sf1 -5 def /sf2 -6 def
/la0 -1 def /la1 -2 def /la2 -3 def
/sf0 -4 def /sf1 -5 def /sf2 -6 def
/fn1 -7 def /fn2 -8 def /fn3 -9 def /fn4 -10 def
 
% Character maps for each state
10091,7 → 11985,7
/normal
[
% 0 1 2 0 1 2 0 1 2
[ (0) (^) (') ] [ (1) (;) 27 ] [ (2) (<) 28 ] % 0-2
[ (0) (^) (') ] [ (1) (;) 27 ] [ (2) (<) 28 ] % 0-2
[ (3) (=) 29 ] [ (4) (>) 30 ] [ (5) (?) 31 ] % 3-5
[ (6) (@) (!) ] [ (7) ([) (") ] [ (8) 92 (#) ] % 6-8
[ (9) (]) (&) ] [ (A) (a) 1 ] [ (B) (b) 2 ] % 9-11
10124,8 → 12018,8
[ (X) -98 -98 ] [ (Y) -98 -98 ] [ (Z) -98 -98 ] % 33-35
[ (-) -98 -98 ] [ (.) -98 -98 ] % 36-37
]
>>
version (a) eq version (b) eq or {/normal} {/limited} ifelse get
>>
version (a) eq version (b) eq or {/normal} {/limited} ifelse get
/charmaps exch def
 
% Invert charmaps to give character to value maps for each state
10138,7 → 12032,7
0 1 2 {
/j exch def
encs j get dup type /stringtype eq {0 get} if % convert string to ASCII if required
charvals j get exch i put
charvals j get exch i put
} for
} for
/set0 charvals 0 get def
10148,10 → 12042,10
raw {/encoding (raw) def} if
 
encoding (raw) eq {
/cws barlen array def
/cws barcode length array def
/i 0 def /j 0 def
{ % loop
i barlen eq {exit} if
i barcode length eq {exit} if
/cw barcode i 1 add 3 getinterval cvi def
cws j cw put
/i i 4 add def
10161,39 → 12055,26
/text () def
} if
 
encoding (auto) eq {
encoding (auto) eq {
 
% Parse the input
/fncvals <<
/parse parse
/parsefnc parsefnc
(FNC1) fn1
(FNC2) fn2
(FNC3) fn3
% (FNC4) fn4 Not user accessible as encoded automatically
>> def
 
% Convert input into bytes accounting for FNC characters
/msg barlen array def
/text barlen string def
/i 0 def /j 0 def {
i barlen eq {exit} if
/char barcode i get def
text j char put
parsefnc char 94 eq and i barlen 4 sub lt and {
barcode i 1 add get 94 ne {
/char fncvals barcode i 1 add 4 getinterval get def
text j ( ) putinterval
/i i 4 add def
} {
/i i 1 add def
} ifelse
} if
msg j char put
/i i 1 add def
/j j 1 add def
} loop
/msg msg 0 j getinterval def
/msg barcode fncvals //parseinput exec def
/msglen msg length def
/text text 0 j getinterval def
 
/text msglen string def
0 1 msglen 1 sub {
/i exch def
text i msg i get dup 0 lt { pop 32 } if put
} for
 
% Standard and extended ASCII runlength at position
/numSA [ msglen {0} repeat 0 ] def
/numEA [ msglen {0} repeat 0 ] def
10238,7 → 12119,7
/i 0 def /j 0 def /cset (set0) def
{
i msglen eq {exit} if
 
{ % common exit
 
% Read next two characters
10246,7 → 12127,7
/char2 i 1 add msglen lt {msg i 1 add get} {-99} ifelse def
 
% If current mode is sufficient then directly encode
cset load char1 known {
cset load char1 known {
char1 cset load enc
/i i 1 add def
exit
10258,7 → 12139,7
char1 set2 enc
/i i 1 add def
exit
} if
} if
 
% If char2 is also not in this set then latch else shift encode
cset load char2 known not {
10270,7 → 12151,7
/cset (set0) def
} ifelse
exit
} {
} {
cset (set0) eq {
sf1 cset load enc
char1 set1 enc
10277,7 → 12158,7
} {
sf0 cset load enc
char1 set0 enc
} ifelse
} ifelse
/i i 1 add def
exit
} ifelse
10284,7 → 12165,7
 
exit
} loop
 
} loop
/cws cws 0 j getinterval def
} if % auto encoding
10341,7 → 12222,7
/c2w [
[ 495 330 210 126 70 35 15 5 ]
[ 165 120 84 56 35 20 10 4 ]
[ 45 36 28 21 15 10 6 3 ]
[ 45 36 28 21 15 10 6 3 ]
[ 9 8 7 6 5 4 3 2 ]
[ 1 1 1 1 1 1 1 1 ]
] def
10354,7 → 12235,7
} if
/v v -1 bitshift def
/cw cw -1 bitshift def
} repeat
} repeat
} forall
/v v checkoffset add def
 
10362,7 → 12243,7
/v v 1023 and def
v 824 gt v 853 lt and {
/v v 292 add def
} if
} if
} {
/v v 1023 and 45 add def
} ifelse
10390,7 → 12271,7
} loop
20 0 1 4 {d exch get sub} for
d exch 5 exch put
version (b) eq version (limitedb) eq or {
version (b) eq version (limitedb) eq or {
/d [ d {1 add} forall ] def
} if
/cbs (111111111111) 12 string copy def
10401,8 → 12282,8
 
% Concatenate the space bar successions
/sbs cws length 6 mul 31 add string def
encs encs length 2 sub get dup
sbs exch 0 exch putinterval
encs encs length 2 sub get dup
sbs exch 0 exch putinterval
length /j exch def
0 1 cws length 1 sub {
/i exch def
10431,7 → 12312,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/posicode dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
10440,16 → 12323,17
% --END ENCODER posicode--
 
% --BEGIN ENCODER codablockf--
% --REQUIRES preamble raiseerror renmatrix--
% --REQUIRES preamble raiseerror parseinput renmatrix--
% --DESC: Codablock F
% --EXAM: CODABLOCK F 34567890123456789010040digit
% --EXOP: columns=8
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp codablockf 0.0 2018020400 150611 163733
%%BeginData: 520 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp codablockf 0.0 2021092800 128719 128096
%%BeginData: 488 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
begin
/codablockf {
10483,41 → 12367,39
/rowheight rowheight cvi def
/sepheight sepheight cvi def
 
columns 4 ge columns 62 le and
rows 2 ge rows 44 le and rows -1 eq or and {/c columns def} if
/c columns 4 ge columns 62 le and {columns} {8} ifelse def
/rows rows 2 ge rows 44 le and {rows} {-1} ifelse def
 
% Parse ordinals of the form ^NNN to ASCII
parse {
/msg barcode length string def
/j 0 def
barcode
{ % loop
(^) search {
dup msg exch j exch putinterval
length j add 1 add /j exch def
pop
dup 0 3 getinterval cvi msg exch j 1 sub exch put
dup length 3 sub 3 exch getinterval
} {
dup msg exch j exch putinterval
length j add /j exch def
/barcode msg 0 j getinterval def
exit
} ifelse
} loop
} if
 
/barlen barcode length def
 
% Convert input into bytes accounting for FNC characters
% Convert input into bytes accounting for FNC characters
/swa -1 def /swb -2 def /swc -3 def /sft -4 def
/fn1 -5 def /fn2 -6 def /fn3 -7 def /fn4 -8 def
/sta -9 def /stp -10 def
 
% Parse the input
/fncvals <<
/parse parse
/parsefnc parsefnc
(FNC1) fn1
% (FNC2) fn2 Not permitted for Codablock F
(FNC3) fn3
% (FNC4) fn4 Not user accessible as encoded automatically
>> def
/msg barcode fncvals //parseinput exec def
/msglen msg length def
 
% FNC4 codeword insertion for extended ASCII
/msgtmp [] def
msg {
/char exch def
/msgtmp [ msgtmp aload pop char 128 lt {char} {fn4 char 127 and} ifelse ] def
} forall
/msg msgtmp def
/msglen msg length def
 
% Character maps for each state
/charmaps [
% A B C A B C A B C
[ 32 32 (00) ] [ (!) (!) (01) ] [ (") (") (02) ] % 0-2
[ 32 32 (00) ] [ (!) (!) (01) ] [ (") (") (02) ] % 0-2
[ (#) (#) (03) ] [ ($) ($) (04) ] [ (%) (%) (05) ] % 3-5
[ (&) (&) (06) ] [ (') (') (07) ] [ 40 40 (08) ] % 6-8
[ 41 41 (09) ] [ (*) (*) (10) ] [ (+) (+) (11) ] % 9-11
10553,7 → 12435,7
[ swc swc (99) ] [ swb fn4 swb ] [ fn4 swa swa ] % 99-101
[ fn1 fn1 fn1 ] [ sta sta sta ] [ stp stp stp ] % 102-104
] def
 
% Invert charmaps to give character to value maps for each state
/charvals [ 105 dict 105 dict 105 dict ] def
0 1 charmaps length 1 sub {
10562,47 → 12444,13
0 1 2 {
/j exch def
encs j get dup type /stringtype eq {0 get} if % convert string to ASCII if required
charvals j get exch i put
charvals j get exch i put
} for
} for
/seta charvals 0 get def
/setb charvals 1 get def
/setc charvals 2 get def
/fncvals <<
(FNC1) fn1
% (FNC2) fn2 Not permitted for Codablock F
(FNC3) fn3
% (FNC4) fn4 Not user accessible as encoded automatically
>> def
/msg barlen array def
/i 0 def /j 0 def {
i barlen eq {exit} if
/char barcode i get def
parsefnc char 94 eq and i barlen 4 sub lt and {
barcode i 1 add get 94 ne {
/char fncvals barcode i 1 add 4 getinterval get def
/i i 4 add def
} {
/i i 1 add def
} ifelse
} if
msg j char put
/i i 1 add def
/j j 1 add def
} loop
/msg msg 0 j getinterval def
/msglen msg length def
 
% FNC4 codeword insertion for extended ASCII
/msgtmp [] def
msg {
/char exch def
/msgtmp [ msgtmp aload pop char 128 lt {char} {fn4 char 127 and} ifelse ] def
} forall
/msg msgtmp def
/msglen msg length def
 
% Determine digit runlength and characters from given position
/numsscr {
/n 0 def /s 0 def
10677,11 → 12525,11
} bind def
 
% Convert message to codewords
/cws c 5 add rows -1 ne {rows} {44} ifelse mul array def
/cws c 5 add 44 mul array def
 
/i 0 def /j 0 def /r 1 def
/lastrow false def {
 
lastrow {exit} if
 
% Add start character and code subset selector
10698,11 → 12546,11
/cset (setc) def
exit
} if
i abeforeb {
i abeforeb {
sft enca
/cset (seta) def
exit
} if
exit
} if
swb enca
/cset (setb) def
exit
10714,14 → 12562,15
/rem c 3 add j c 5 add mod sub def % Codewords to end of row
 
i msglen eq endofrow or {exit} if
 
i numsscr /nums exch def /nchars exch def
/remnums nums rem 2 mul gt {rem 2 mul} {nums} ifelse def
 
% Determine switches and shifts
{ % common exit
cset (seta) eq cset (setb) eq or nums 4 ge and
cset (seta) eq cset (setb) eq or remnums 4 ge and
msg i get fn1 ne and {
nums 2 mod 0 eq
remnums 2 mod 0 eq
rem 3 ge and {
swc cset (seta) eq {enca} {encb} ifelse
/cset (setc) def
10736,7 → 12585,7
} repeat
exit
} if
nums 2 mod 0 ne
remnums 2 mod 0 ne
rem 4 ge and {
msg i get cset (seta) eq {enca} {encb} ifelse
/i i 1 add def
10754,10 → 12603,10
exit
} if
} if
cset (setb) eq msg i get anotb and
rem 2 ge and {
cset (setb) eq msg i get anotb and
rem 2 ge and {
i msglen 1 sub lt {
i 1 add bbeforea {
i 1 add bbeforea {
sft encb
msg i get enca
/i i 1 add def
10786,7 → 12635,7
/i i 1 add def
exit
} if
cset (setc) eq nums 2 lt and
cset (setc) eq remnums 2 lt and
rem 2 ge and {
i abeforeb {
swa encc
10801,7 → 12650,7
/i i 1 add def
exit
} if
 
% No switches or latches so try to encode
cset (seta) eq seta msg i get known and
rem 1 ge and {
10815,7 → 12664,7
/i i 1 add def
exit
} if
cset (setc) eq nums 2 ge and
cset (setc) eq remnums 2 ge and
rem 1 ge and {
msg i get fn1 eq {
fn1 encc
10822,7 → 12671,7
/i i 1 add def
} {
msg i 2 getinterval encc
/i i 2 add def
/i i 2 add def
} ifelse
exit
} if
10836,7 → 12685,7
} loop
 
% Determine whether this is the final row
r rows eq rows -1 eq or r 1 gt and i msglen eq and rem 2 ge and {
r rows ge rows -1 eq or r 1 gt and i msglen eq and rem 2 ge and {
rem 2 sub padrow
/j j 3 add def % Skip symbol and row checksum character positions
stp enca
10858,7 → 12707,7
26 1 63 {} for
] def
/cmap [ 0 1 85 {} for ] def
 
% Add symbol check characters to last row
/chkmsg msglen array def
/j 0 def
10923,7 → 12772,7
/sbs [
cws i c 5 add mul c 5 add getinterval {
encs exch get {48 sub} forall
} forall
} forall
] def
mark
0 sbs {1 index 1 eq {{0}} {{1}} ifelse repeat} forall
10947,7 → 12796,7
rowheight {rowbits r 1 sub get aload pop} repeat
symwid sepheight mul {1} repeat
] def
 
% Return the arguments
<<
/ren //renmatrix
10963,7 → 12812,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/codablockf dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
10972,16 → 12823,17
% --END ENCODER codablockf--
 
% --BEGIN ENCODER code16k--
% --REQUIRES preamble raiseerror renmatrix--
% --REQUIRES preamble raiseerror parseinput renmatrix--
% --DESC: Code 16K
% --EXAM: Abcd-1234567890-wxyZ
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp code16k 0.0 2018020400 182748 198997
%%BeginData: 744 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp code16k 0.0 2021092800 153345 152816
%%BeginData: 711 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
begin
/code16k {
11021,33 → 12873,10
 
pos -1 ne {/rows 16 def} if
 
% Parse ordinals of the form ^NNN to ASCII
parse {
/msg barcode length string def
/j 0 def
barcode
{ % loop
(^) search {
dup msg exch j exch putinterval
length j add 1 add /j exch def
pop
dup 0 3 getinterval cvi msg exch j 1 sub exch put
dup length 3 sub 3 exch getinterval
} {
dup msg exch j exch putinterval
length j add /j exch def
/barcode msg 0 j getinterval def
exit
} ifelse
} loop
} if
 
/barlen barcode length def
 
% Convert input into bytes accounting for FNC characters
/swa -1 def /swb -2 def /swc -3 def
/sa1 -4 def /sb1 -5 def /sc1 -6 def
/sa2 -7 def /sb2 -8 def /sc2 -9 def
% Convert input into bytes accounting for FNC characters
/swa -1 def /swb -2 def /swc -3 def
/sa1 -4 def /sb1 -5 def /sc1 -6 def
/sa2 -7 def /sb2 -8 def /sc2 -9 def
/pad -10 def /sb3 -11 def /sc3 -12 def
/fn1 -13 def /fn2 -14 def /fn3 -15 def /fn4 -16 def
 
11054,7 → 12883,7
% Character maps for each state
/charmaps [
% A B C A B C A B C
[ 32 32 (00) ] [ (!) (!) (01) ] [ (") (") (02) ] % 0-2
[ 32 32 (00) ] [ (!) (!) (01) ] [ (") (") (02) ] % 0-2
[ (#) (#) (03) ] [ ($) ($) (04) ] [ (%) (%) (05) ] % 3-5
[ (&) (&) (06) ] [ (') (') (07) ] [ 40 40 (08) ] % 6-8
[ 41 41 (09) ] [ (*) (*) (10) ] [ (+) (+) (11) ] % 9-11
11090,8 → 12919,8
[ swc swc (99) ] [ swb fn4 swb ] [ fn4 swa swa ] % 99-101
[ fn1 fn1 fn1 ] [ pad pad pad ] [ sb2 sa2 sb1 ] % 102-104
[ sc2 sc2 sb2 ] [ sc3 sc3 sb3 ] % 105-106
] def
] def
 
% Invert charmaps to give character to value maps for each state
/charvals [ 109 dict 109 dict 109 dict ] def
0 1 charmaps length 1 sub {
11100,7 → 12929,7
0 1 2 {
/j exch def
encs j get dup type /stringtype eq {0 get} if % convert string to ASCII if required
charvals j get exch i put
charvals j get exch i put
} for
} for
/seta charvals 0 get def
11110,10 → 12939,10
raw {/encoding (raw) def} if
 
encoding (raw) eq {
/cws barlen array def
/cws barcode length array def
/i 0 def /j 0 def
{ % loop
i barlen eq {exit} if
i barcode length eq {exit} if
/cw barcode i 1 add 3 getinterval cvi def
cws j cw put
/i i 4 add def
11120,36 → 12949,23
/j j 1 add def
} loop
/cws cws 0 j getinterval def
/text () def
} if
 
encoding (auto) eq {
encoding (auto) eq {
 
% Parse the input
/fncvals <<
/parse parse
/parsefnc parsefnc
/eci true
(FNC1) fn1
(FNC2) fn2
(FNC3) fn3
% (FNC4) fn4 Not user accessible as encoded automatically
>> def
/msg barlen array def
/i 0 def /j 0 def {
i barlen eq {exit} if
/char barcode i get def
parsefnc char 94 eq and i barlen 4 sub lt and {
barcode i 1 add get 94 ne {
/char fncvals barcode i 1 add 4 getinterval get def
/i i 4 add def
} {
/i i 1 add def
} ifelse
} if
msg j char put
/i i 1 add def
/j j 1 add def
} loop
/msg msg 0 j getinterval def
/msg barcode fncvals //parseinput exec def
/msglen msg length def
 
% Standard and extended ASCII runlength at position
/numSA [ msglen {0} repeat 0 ] def
/numEA [ msglen {0} repeat 0 ] def
11183,7 → 12999,7
} for
/msg msgtmp def
/msglen msg length def
 
% Determine digit runlength and characters from given position
/numsscr {
/n 0 def /s 0 def
11245,9 → 13061,9
% Does a-only come before b-only after given position and vice versa
/abeforeb {dup nextanotb exch get exch nextbnota exch get lt} bind def
/bbeforea {dup nextbnota exch get exch nextanotb exch get lt} bind def
 
/cws barcode length 2 mul 3 add array def
 
% Select mode and encode first characters
/i 0 def /j 0 def
{ % common exit
11255,7 → 13071,7
pos -1 ne {
% encode one and two
cws 0 pos 10 idiv 1 sub put
cws 1 pos 10 mod 1 sub put
cws 1 pos 10 mod 1 sub put
/j 2 def
/cset (setb) def
/mode 7 def
11307,7 → 13123,7
/i 1 def
exit
} if
% b . 3+ odd nums => c sb2 encode
% b . 3+ odd nums => c sb2 encode
setb msg 0 get known
1 numsscr exch pop dup 3 ge exch 2 mod 1 eq and and {
msg 0 get encb
11343,9 → 13159,9
 
{ % Encode remainder
i msglen eq {exit} if
 
i numsscr /nums exch def /nchars exch def
 
% Determine switches and shifts
{ % common exit
cset (seta) eq {
11379,7 → 13195,7
} if
% 4 nums . a => sc2 encode
i msglen 4 sub lt {
nums 4 eq
nums 4 eq
seta msg i 4 add get known and {
sc2 enca
2 {
11388,7 → 13204,7
/i i 1 add def
} {
msg i 2 getinterval encc
/i i 2 add def
/i i 2 add def
} ifelse
} repeat
exit
11395,8 → 13211,8
} if
} if
% 6 nums . a => sc3 encode
i msglen 6 sub lt {
nums 6 eq
i msglen 6 sub lt {
nums 6 eq
seta msg i 6 add get known and {
sc3 enca
3 {
11435,7 → 13251,7
} if
% anotb . anotb . bnota before anotb => sa2 encode
i msglen 2 sub lt {
msg i get anotb
msg i get anotb
msg i 1 add get anotb and
i 2 add bbeforea and {
sa2 encb
11494,7 → 13310,7
% otherwise => encode
msg i get encb
/i i 1 add def
exit
exit
} if
cset (setc) eq {
% 2+ nums => encode
11556,7 → 13372,7
} if
% b . b . b . 2+ even nums => sb3 encode
i msglen 3 sub lt {
setb msg i get known
setb msg i get known
setb msg i 1 add get known and
setb msg i 2 add get known and
i 3 add numsscr exch pop dup 2 ge exch 2 mod 0 eq and and {
11565,7 → 13381,7
msg i 1 add get encb
msg i 2 add get encb
/i i 3 add def
exit
exit
} if
} if
% anotb before bnota => swa
11581,13 → 13397,13
} if
exit
} loop
 
} loop
/cws cws 0 j getinterval def
} if % auto encoding
 
% Basic metrics for the each symbol
% r dcws
% r dcws
/metrics [
[ 2 7 ]
[ 3 12 ]
11627,9 → 13443,9
/cws [ r 2 sub 7 mul mode add cws aload pop ] def
 
% Calculate the check characters
0 0 1 dcws {dup 2 add exch cws exch get mul add} for
0 0 1 dcws {dup 2 add exch cws exch get mul add} for
107 mod /c1 exch def
0 0 1 dcws {dup 1 add exch cws exch get mul add} for
0 0 1 dcws {dup 1 add exch cws exch get mul add} for
c1 dcws 2 add mul add 107 mod /c2 exch def
/cws [ cws aload pop c1 c2 ] def
 
11654,7 → 13470,7
] def
 
% Start/stop character encodings
/startencs [
/startencs [
(3211) (2221) (2122) (1411) (1132) (1231) (1114) (3112)
(3211) (2221) (2122) (1411) (1132) (1231) (1114) (3112)
] def
11671,7 → 13487,7
} {
/stopencs stopencseven def
} ifelse
 
% Derive the bits for each row
/rowbits r array def
0 1 r 1 sub {
11682,7 → 13498,7
1
cws i 5 mul 5 getinterval {
encs exch get {48 sub} forall
} forall
} forall
stopencs i get {48 sub} forall
1
] def
11703,7 → 13519,7
rowheight {rowbits r 1 sub get aload pop} repeat
81 sepheight mul {1} repeat
] def
 
% Return the arguments
<<
/ren //renmatrix
11719,7 → 13535,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/code16k dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
11728,16 → 13546,17
% --END ENCODER code16k--
 
% --BEGIN ENCODER code49--
% --REQUIRES preamble raiseerror renmatrix--
% --REQUIRES preamble raiseerror parseinput renmatrix--
% --DESC: Code 49
% --EXAM: MULTIPLE ROWS IN CODE 49
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp code49 0.0 2018020400 281149 300877
%%BeginData: 1076 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp code49 0.0 2021092800 255438 268416
%%BeginData: 1042 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
begin
/code49 {
11773,53 → 13592,16
/rowheight rowheight cvi def
/sepheight sepheight cvi def
 
% Parse ordinals of the form ^NNN to ASCII
parse {
/msg barcode length string def
/j 0 def
barcode
{ % loop
(^) search {
dup msg exch j exch putinterval
length j add 1 add /j exch def
pop
dup 0 3 getinterval cvi msg exch j 1 sub exch put
dup length 3 sub 3 exch getinterval
} {
dup msg exch j exch putinterval
length j add /j exch def
/barcode msg 0 j getinterval def
exit
} ifelse
} loop
} if
 
/barlen barcode length def
 
% Convert input into bytes accounting for FNC characters
% Parse the input
/s1 -1 def /s2 -2 def /fn1 -3 def /fn2 -4 def /fn3 -5 def /ns -6 def
/fncvals <<
/parse parse
/parsefnc parsefnc
(FNC1) fn1
(FNC2) fn2
(FNC3) fn3
>> def
/msg barlen array def
/i 0 def /j 0 def {
i barlen eq {exit} if
/char barcode i get def
parsefnc char 94 eq and i barlen 4 sub lt and {
barcode i 1 add get 94 ne {
/char fncvals barcode i 1 add 4 getinterval get def
/i i 4 add def
} {
/i i 1 add def
} ifelse
} if
msg j char put
/i i 1 add def
/j j 1 add def
} loop
/msg msg 0 j getinterval def
/msg barcode fncvals //parseinput exec def
/msglen msg length def
 
% Character encodings
11835,9 → 13617,9
/charvals 49 dict def
0 1 48 {
/i exch def
charmap i get
charmap i get
dup type /stringtype eq {0 get} if % convert string to ASCII if required
charvals exch i put
charvals exch i put
} for
 
% Shifted character encodings
11920,17 → 13702,17
/method (alpha) def /i -1 def /j -1 def
 
% Handle start for each mode
mode 0 eq mode 1 eq or {/method (alpha) def /i 0 def /j 0 def} if
mode 0 eq mode 1 eq or {/method (alpha) def /i 0 def /j 0 def} if
mode 2 eq {/method (numeric) def /i 0 def /j 0 def} if
mode 3 eq {
/posval [
/posval [
12 22
13 23 33
14 24 34 44
15 25 35 45 55
16 26 36 46 56 66
17 27 37 47 57 67 77
18 28 38 48 58 68 78 88
17 27 37 47 57 67 77
18 28 38 48 58 68 78 88
19 29 39 49 59 69 79 89 99
] def
cws 0 0 1 43 {dup posval exch get pos ne {pop} if} for 1 add put
11970,7 → 13752,7
/cws cws 0 j getinterval def
 
% Basic metrics for the each symbol
% r dcws
% r dcws
/metrics [
[ 2 9 ]
[ 3 16 ]
12004,7 → 13786,7
0 1 r 2 sub {
/i exch def
/cc cws j 7 getinterval def
ccs i 8 mul cc putinterval
ccs i 8 mul cc putinterval
ccs i 8 mul 7 add 0 cc {add} forall 49 mod put
/j j 7 add def
} for
12027,7 → 13809,7
/score 0 def
0 1 r 1 sub 8 mul 2 idiv 1 sub {
/i exch def
ccs i 2 mul get 49 mul ccs i 2 mul 1 add get add
ccs i 2 mul get 49 mul ccs i 2 mul 1 add get add
weights i 1 add get mul /score exch score add def
} for
score
12043,10 → 13825,10
/wr1 lastrow 0 get 49 mul lastrow 1 get add def
 
% wr2 check character
cr7 weighty 0 get mul weighty calccheck add
cr7 weighty 0 get mul weighty calccheck add
wr1 weighty r 4 mul 3 sub get mul add
2401 mod dup /wr2 exch def
dup 49 idiv exch 49 mod 2 array astore
dup 49 idiv exch 49 mod 2 array astore
lastrow 2 3 -1 roll putinterval
 
% wr3 check character
12054,7 → 13836,7
wr1 weightx r 4 mul 3 sub get mul add
wr2 weightx r 4 mul 2 sub get mul add
2401 mod
dup 49 idiv exch 49 mod 2 array astore
dup 49 idiv exch 49 mod 2 array astore
lastrow 4 3 -1 roll putinterval
 
% Place last row check character
12807,7 → 14589,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/code49 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
12821,8 → 14605,8
% --EXAM: 3493
% --EXOP: height=0.5 includetext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp channelcode 0.0 2018020400 140776 146430
%%BeginData: 248 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp channelcode 0.0 2021092800 125552 124333
%%BeginData: 250 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
13067,7 → 14851,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/channelcode dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
13081,8 → 14867,8
% --EXAM: 11099
% --EXOP: inkspread=-0.25 showborder borderleft=0 borderright=0
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp flattermarken 0.0 2018020400 60397 60097
%%BeginData: 93 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp flattermarken 0.0 2021092800 53805 53752
%%BeginData: 95 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
13172,7 → 14958,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/flattermarken dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
13186,8 → 14974,8
% --EXAM: 331132131313411122131311333213114131131221323
% --EXOP: height=0.5
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp raw 0.0 2018020400 55087 54976
%%BeginData: 52 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp raw 0.0 2021092800 49511 49415
%%BeginData: 54 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
13236,7 → 15024,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/raw dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
13250,8 → 15040,8
% --EXAM: FATDAFTDAD
% --EXOP:
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp daft 0.0 2018020400 58981 58843
%%BeginData: 76 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp daft 0.0 2021092800 52789 52642
%%BeginData: 78 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
13324,7 → 15114,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/daft dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
13338,8 → 15130,8
% --EXAM: fima
% --EXOP: backgroundcolor=DD000011
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp symbol 0.0 2018020400 58561 58498
%%BeginData: 72 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp symbol 0.0 2021092800 53469 53305
%%BeginData: 79 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
13386,15 → 15178,20
/bhs [.625 .625 .625 .625 .625 .625 .625] def
/bbs [0 0 0 0 0 0 0] def
} bind
/fime {
/sbs [2.25 6.75 2.25 15.75 2.25 6.75 2.25] def
/bhs [.625 .625 .625 .625 .625 .625 .625] def
/bbs [0 0 0 0 0 0 0] def
} bind
>> def
 
% Valiate input
% Valiate input
symbols barcode known not {
/bwipp.symbolUnknownSymbol (Unknown symbol name provided) //raiseerror exec
/bwipp.symbolUnknownSymbol (Unknown symbol name provided) //raiseerror exec
} if
 
symbols barcode get exec
 
% Return the arguments
<<
/ren //renlinear
13408,7 → 15205,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/symbol dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
13417,16 → 15216,17
% --END ENCODER symbol--
 
% --BEGIN ENCODER pdf417--
% --REQUIRES preamble raiseerror renmatrix--
% --REQUIRES preamble raiseerror parseinput renmatrix--
% --DESC: PDF417
% --EXAM: This is PDF417
% --EXOP: columns=2
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp pdf417 0.0 2018020400 218585 234575
%%BeginData: 873 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp pdf417 0.0 2021092800 196554 198626
%%BeginData: 900 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
begin
/pdf417 {
13446,6 → 15246,7
/ccc false def
/raw false def
/parse false def
/parsefnc false def
 
% Parse the input options
options type /stringtype eq {
13463,27 → 15264,6
/rows rows cvi def
/rowmult rowmult cvr def
 
% Parse ordinals of the form ^NNN to ASCII
parse {
/msg barcode length string def
/j 0 def
barcode
{ % loop
(^) search {
dup msg exch j exch putinterval
length j add 1 add /j exch def
pop
dup 0 3 getinterval cvi msg exch j 1 sub exch put
dup length 3 sub 3 exch getinterval
} {
dup msg exch j exch putinterval
length j add /j exch def
/barcode msg 0 j getinterval def
exit
} ifelse
} loop
} if
 
raw {/encoding (raw) def} if
 
% Convert input into array of codewords
13500,9 → 15280,6
/datcws datcws 0 j getinterval def
} if
 
/barcode [ barcode {} forall ] def
/barlen barcode length def
 
ccc {/encoding (ccc) def} if
 
/encb {
13540,26 → 15317,37
} if
out
} bind def
 
encoding (byte) eq encoding (ccc) eq or {
/barlen barcode length def
/datcws barlen 6 idiv 5 mul barlen 6 mod add 1 add array def
datcws 0 barlen 6 mod 0 eq {924} {901} ifelse put
datcws 1 barcode encb putinterval
datcws 1 [ barcode {} forall ] encb putinterval
encoding (ccc) eq {/datcws [920 datcws aload pop] def} if
} if
 
encoding (auto) eq {
 
% Parse the input
/fncvals <<
/parse parse
/parsefnc parsefnc
/eci true
% Predates FNC non-data codewords, but supports ECI
>> def
/msg barcode fncvals //parseinput exec def
/msglen msg length def
 
% Modes and text submodes
/T 0 def /N 1 def /B 2 def
/A 0 def /L 1 def /M 2 def /P 3 def
 
% Special function characters for mode switching
/tl -1 def /nl -2 def /bl -3 def /bl6 -4 def /bs -5 def
 
% Special function characters for text mode
/al -6 def /ll -7 def /ml -8 def /pl -9 def /as -10 def /ps -11 def
 
% Character maps for each state
/charmaps [
% A L M P
13594,23 → 15382,23
[ ml ml al (') ] % 28
[ ps ps ps al ] % 29
] def
 
% Invert charmaps to give character to value maps for each state
/charvals [ 30 dict 30 dict 30 dict 30 dict ] def
/alltext 104 dict def
0 1 charmaps length 1 sub {
/i exch def
/encs charmaps i get def
0 1 3 {
/j exch def
encs j get dup type /stringtype eq {0 get} if % convert string to ASCII if required
dup charvals j get exch i put
alltext exch -1 put
} for
/i exch def
/encs charmaps i get def
0 1 3 {
/j exch def
encs j get dup type /stringtype eq {0 get} if % convert string to ASCII if required
dup charvals j get exch i put
alltext exch -1 put
} for
} for
 
/e 10000 def % "Empty"
 
/latlen [ % Bit length of latch between submodes
% To: A L M P From
[ 0 1 1 2 ] % A
13618,7 → 15406,7
[ 1 1 0 1 ] % M
[ 1 2 2 0 ] % P
] def
 
/latseq [ % Latch sequences between submodes
% To: A L M P From
[ [] [ll] [ml] [ml pl] ] % A
13626,7 → 15414,7
[ [al] [ll] [] [pl] ] % M
[ [al] [al ll] [al ml] [] ] % P
] def
 
/shftlen [ % Bit length of shift to submode
% To: A L M P From
[ e e e 1 ] % A
13634,35 → 15422,46
[ e e e 1 ] % M
[ e e e e ] % P
] def
 
% Determine runlengths of digits
/numdigits [ barlen {0} repeat 0 ] def
/numtext [ barlen {0} repeat 0 ] def
/numbytes [ barlen {0} repeat 0 ] def
barlen 1 sub -1 0 {
/numdigits [ msglen {0} repeat 0 ] def
/numtext [ msglen {0} repeat 0 ] def
/numbytes [ msglen {0} repeat 0 ] def
/iseci [ msglen {0} repeat 0 ] def
msglen 1 sub -1 0 {
/i exch def
barcode i get dup 48 ge exch 57 le and {
msg i get dup 48 ge exch 57 le and {
numdigits i numdigits i 1 add get 1 add put
} if
alltext barcode i get known numdigits i get 13 lt and {
alltext msg i get known numdigits i get 13 lt and {
numtext i numtext i 1 add get 1 add put
} if
numtext i get 5 lt numdigits i get 13 lt and {
msg i get 0 ge numtext i get 5 lt and numdigits i get 13 lt and {
numbytes i numbytes i 1 add get 1 add put
} if
iseci i msg i get -1000000 le put
} for
/numdigits numdigits 0 barlen getinterval def
/numtext numtext 0 barlen getinterval def
/numbytes numbytes 0 barlen getinterval def
/numdigits numdigits 0 msglen getinterval def
/numtext numtext 0 msglen getinterval def
/numbytes numbytes 0 msglen getinterval def
 
/seq [] def /seqlen 0 def /state T def /p 0 def { % loop
p barlen eq {exit} if
p msglen eq {exit} if
iseci p get {
/eci msg p get def
/seq [
seq aload pop
[ eci ]
] def
/p p 1 add def
/seqlen seqlen eci -1810900 le {2} {eci -1000900 le {3} {2} ifelse} ifelse add def
} {
/n numdigits p get def
n 13 ge {
/seq [
seq aload pop
nl
[ barcode p n getinterval aload pop ]
[ msg p n getinterval aload pop ]
] def
/state N def
/p p n add def
13672,8 → 15471,10
t 5 ge {
/seq [
seq aload pop
state T ne {tl} if
[ barcode p t getinterval aload pop ]
state T ne {
tl
} if
[ msg p t getinterval aload pop ]
] def
/state T def
/p p t add def
13684,7 → 15485,7
/seq [
seq aload pop
bs
[ barcode p get ]
[ msg p get ]
] def
/p p b add def
/seqlen seqlen 2 add def
13692,18 → 15493,18
/seq [
seq aload pop
b 6 mod 0 ne {bl} {bl6} ifelse
[ barcode p b getinterval aload pop ]
[ msg p b getinterval aload pop ]
] def
/state B def
/p p b add def
/seqlen seqlen 1 add b add def
} ifelse } ifelse } ifelse
} ifelse } ifelse } ifelse } ifelse
} loop
 
/latchcws <<
tl 900 bl 901 bl6 924 nl 902 bs 913
>> def
 
% Submode encoding functions
/enca {charvals A get exch get} bind def
/encl {charvals L get exch get} bind def
13710,25 → 15511,24
/encm {charvals M get exch get} bind def
/encp {charvals P get exch get} bind def
/textencfuncs [ /enca /encl /encm /encp ] def
 
/addtotext {
text exch l exch put
/l l 1 add def
} bind def
 
/enct {
/in exch def
 
/curlen [ e e e e ] def
curlen submode 0 put
/curseq [ [] [] [] [] ] def
 
% Derive the optimal sequences ending in each submode
in {
 
/char exch def
 
% Check for optimisations in the current sequences by latching from x to y
{ % loop
/imp false def
13749,18 → 15549,18
} forall
imp not {exit} if % Repeat unless no improvement
} loop
 
% Determine optimal next sequences for each valid encoding
/nxtlen [ e e e e ] def
/nxtseq 4 array def
 
[ A L M P ] {
/x exch def
 
{ % loop for common exit
 
charvals x get char known not {exit} if
 
% Extend directly
/cost curlen x get 1 add def
cost nxtlen x get lt {
13767,7 → 15567,7
nxtlen x cost put
nxtseq x [ curseq x get aload pop char ] put
} if
 
% Optimise for direct shifts from y to x
[ A L M P ] {
/y exch def
13783,17 → 15583,17
} if
} if
} forall
 
exit
} loop
 
} forall
 
/curlen nxtlen def
/curseq nxtseq def
 
} forall
 
% Select the optimal sequence
/minseq e def
[ A L M P ] {
13803,24 → 15603,24
/txtseq curseq k get def
} if
} forall
 
% Encode the sequence
/text minseq array def
/k 0 def /l 0 def {
k txtseq length ge {exit} if
 
/char txtseq k get def
 
% Encode character
char textencfuncs submode get load exec addtotext
/k k 1 add def
 
% Encode shifted next character
char as eq char ps eq or {
txtseq k get char as eq {enca} {encp} ifelse addtotext
/k k 1 add def
} if
 
% Latches to new submode
char al eq {/submode A def} if
char ll eq {/submode L def} if
13827,7 → 15627,7
char ml eq {/submode M def} if
char pl eq {/submode P def} if
} loop
 
text length 2 mod 1 eq {
submode P eq {
/pad al encp def
13837,17 → 15637,17
} ifelse
/text [ text aload pop pad ] def
} if
 
/out text length 2 idiv array def
0 1 out length 1 sub {
/k exch def
out k text k 2 mul get 30 mul text k 2 mul 1 add get add put
} for
 
out
 
} bind def
 
/encn {
/in exch def
/out [] def
13881,14 → 15681,27
} for
out
} bind def
 
/ence {
0 get neg 1000000 sub
dup 000899 le { % ECI 000000 - 000899
927 exch 2 array astore
} { dup 810899 le { % ECI 000900 - 810899
926 exch dup 900 idiv 1 sub exch 900 mod 3 array astore
} { dup 811799 le { % ECI 810900 - 811799
925 exch 810900 sub 2 array astore
} {
/bwipp.pdf417badECI (PDF417 supports ECIs 000000 to 811799) //raiseerror exec
} ifelse } ifelse } ifelse
} bind def
 
/encfuncs [ /enct /encn /encb ] def
 
/addtocws {
dup datcws j 3 -1 roll putinterval
length j add /j exch def
} bind def
 
% Encode the sequence
/state T def /submode A def
/datcws seqlen array def
13895,8 → 15708,12
/i 0 def /j 0 def {
i seq length ge {exit} if
/chars seq i get def
chars type /arraytype eq { % Encode data according to mode
chars encfuncs state get load exec addtocws
chars type /arraytype eq {
chars 0 get -1000000 le { % ECI
chars ence addtocws
} { % Encode data according to mode
chars encfuncs state get load exec addtocws
} ifelse
} { % Encode the latch to new state or byte shift
[ latchcws chars get ] addtocws
chars tl eq {/state T def /submode A def} if
13928,7 → 15745,7
 
% To determine size of matrix, number of columns if given by user...
columns 0 eq {/columns m k add 3 div sqrt round cvi def} if
columns 1 ge columns 30 le and {/c columns def} if
/c columns 1 ge {columns} {1} ifelse def
 
% ... and rows is greater of those required and that given by user within limits
/r m k add 1 add columns div ceiling cvi def % Required
13935,6 → 15752,11
r rows lt rows 90 le and {/r rows def} if
r 3 lt {/r 3 def} if
 
% Symbol cannot exceed 90 rows
r 90 gt {
/bwipp.pdf417insufficientCapacity (Insufficient capacity in the symbol) //raiseerror exec
} if
 
% Opportunistically raise the error level if a better fit to the matrix is possible
/maxeclevel c r mul 1 sub m sub ln 2 ln div cvi 1 sub 8 2 copy gt {exch} if pop def
maxeclevel eclevel gt {
13967,12 → 15789,12
% Generate the coefficients
/coeffs [ 1 k {0} repeat ] def
1 1 k {
/i exch def
/i exch def
coeffs i coeffs i 1 sub get put
i 1 sub -1 1 {
/j exch def
coeffs j coeffs j 1 sub get coeffs j get rsalog i get rsprod add 929 mod put
} for
} for
coeffs 0 coeffs 0 get rsalog i get rsprod put
} for
/coeffs coeffs 0 coeffs length 1 sub getinterval def
13991,6 → 15813,8
% Trim the working space from the end of the codewords
/cws cws 0 cws length 1 sub getinterval def
 
options /debugcws known { /bwipp.debugcws cws //raiseerror exec } if
 
% Base 10 encoding of the bar space successions for the codewords in each cluster
/clusters [
[
14248,7 → 16072,7
} ifelse
/pixs rwid r mul array def
 
0 1 r 1 sub {
0 1 r 1 sub {
/i exch def
 
i 3 mod 0 eq {
14293,7 → 16117,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/pdf417 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
14302,13 → 16128,13
% --END ENCODER pdf417--
 
% --BEGIN ENCODER pdf417compact--
% --REQUIRES preamble raiseerror renmatrix pdf417--
% --REQUIRES preamble raiseerror parseinput renmatrix pdf417--
% --DESC: Compact PDF417
% --EXAM: This is compact PDF417
% --EXOP: columns=2
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp pdf417compact 0.0 2018020400 59551 59402
%%BeginData: 43 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp pdf417compact 0.0 2021092800 53355 56790
%%BeginData: 45 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
14343,12 → 16169,14
 
args (opt) options put
args
 
dontdraw not //renmatrix if
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/pdf417compact dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
14357,16 → 16185,17
% --END ENCODER pdf417compact--
 
% --BEGIN ENCODER micropdf417--
% --REQUIRES preamble raiseerror renmatrix--
% --REQUIRES preamble raiseerror parseinput renmatrix--
% --DESC: MicroPDF417
% --EXAM: MicroPDF417
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp micropdf417 0.0 2018020400 235011 247567
%%BeginData: 959 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp micropdf417 0.0 2021092800 207257 212591
%%BeginData: 982 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
begin
/micropdf417 {
14386,6 → 16215,7
/ccb false def
/raw false def
/parse false def
/parsefnc false def
 
% Parse the input options
options type /stringtype eq {
14408,27 → 16238,6
/rows rows cvi def
/rowmult rowmult cvr def
 
% Parse ordinals of the form ^NNN to ASCII
parse {
/msg barcode length string def
/j 0 def
barcode
{ % loop
(^) search {
dup msg exch j exch putinterval
length j add 1 add /j exch def
pop
dup 0 3 getinterval cvi msg exch j 1 sub exch put
dup length 3 sub 3 exch getinterval
} {
dup msg exch j exch putinterval
length j add /j exch def
/barcode msg 0 j getinterval def
exit
} ifelse
} loop
} if
 
raw {/encoding (raw) def} if
cca {/encoding (cca) def} if
 
14446,9 → 16255,6
/datcws datcws 0 j getinterval def
} if
 
/barcode [ barcode {} forall ] def
/barlen barcode length def
 
ccb {/encoding (ccb) def} if
 
/encb {
14488,24 → 16294,35
} bind def
 
encoding (byte) eq encoding (ccb) eq or {
/barlen barcode length def
/datcws barlen 6 idiv 5 mul barlen 6 mod add 1 add array def
datcws 0 barlen 6 mod 0 eq {924} {901} ifelse put
datcws 1 barcode encb putinterval
datcws 1 [ barcode {} forall ] encb putinterval
encoding (ccb) eq {/datcws [920 datcws aload pop] def} if
} if
 
encoding (auto) eq {
 
% Parse the input
/fncvals <<
/parse parse
/parsefnc parsefnc
/eci true
% Predates FNC non-data codewords, but supports ECI
>> def
/msg barcode fncvals //parseinput exec def
/msglen msg length def
 
% Modes and text submodes
/T 0 def /N 1 def /B 2 def
/A 0 def /L 1 def /M 2 def /P 3 def
 
% Special function characters for mode switching
/tl -1 def /nl -2 def /bl -3 def /bl6 -4 def /bs -5 def
 
% Special function characters for text mode
/al -6 def /ll -7 def /ml -8 def /pl -9 def /as -10 def /ps -11 def
 
% Character maps for each state
/charmaps [
% A L M P
14540,23 → 16357,23
[ ml ml al (') ] % 28
[ ps ps ps al ] % 29
] def
 
% Invert charmaps to give character to value maps for each state
/charvals [ 30 dict 30 dict 30 dict 30 dict ] def
/alltext 104 dict def
0 1 charmaps length 1 sub {
/i exch def
/encs charmaps i get def
0 1 3 {
/j exch def
encs j get dup type /stringtype eq {0 get} if % convert string to ASCII if required
dup charvals j get exch i put
alltext exch -1 put
} for
/i exch def
/encs charmaps i get def
0 1 3 {
/j exch def
encs j get dup type /stringtype eq {0 get} if % convert string to ASCII if required
dup charvals j get exch i put
alltext exch -1 put
} for
} for
 
/e 10000 def % "Empty"
 
/latlen [ % Bit length of latch between submodes
% To: A L M P From
[ 0 1 1 2 ] % A
14564,7 → 16381,7
[ 1 1 0 1 ] % M
[ 1 2 2 0 ] % P
] def
 
/latseq [ % Latch sequences between submodes
% To: A L M P From
[ [] [ll] [ml] [ml pl] ] % A
14572,7 → 16389,7
[ [al] [ll] [] [pl] ] % M
[ [al] [al ll] [al ml] [] ] % P
] def
 
/shftlen [ % Bit length of shift to submode
% To: A L M P From
[ e e e 1 ] % A
14580,35 → 16397,46
[ e e e 1 ] % M
[ e e e e ] % P
] def
 
% Determine runlengths of digits
/numdigits [ barlen {0} repeat 0 ] def
/numtext [ barlen {0} repeat 0 ] def
/numbytes [ barlen {0} repeat 0 ] def
barlen 1 sub -1 0 {
/numdigits [ msglen {0} repeat 0 ] def
/numtext [ msglen {0} repeat 0 ] def
/numbytes [ msglen {0} repeat 0 ] def
/iseci [ msglen {0} repeat ] def
msglen 1 sub -1 0 {
/i exch def
barcode i get dup 48 ge exch 57 le and {
msg i get dup 48 ge exch 57 le and {
numdigits i numdigits i 1 add get 1 add put
} if
alltext barcode i get known numdigits i get 13 lt and {
alltext msg i get known numdigits i get 13 lt and {
numtext i numtext i 1 add get 1 add put
} if
numtext i get 5 lt numdigits i get 13 lt and {
msg i get 0 ge numtext i get 5 lt and numdigits i get 13 lt and {
numbytes i numbytes i 1 add get 1 add put
} if
iseci i msg i get -1000000 le put
} for
/numdigits numdigits 0 barlen getinterval def
/numtext numtext 0 barlen getinterval def
/numbytes numbytes 0 barlen getinterval def
/numdigits numdigits 0 msglen getinterval def
/numtext numtext 0 msglen getinterval def
/numbytes numbytes 0 msglen getinterval def
 
/seq [] def /seqlen 0 def /state B def /p 0 def { % loop
p barlen eq {exit} if
p msglen eq {exit} if
iseci p get {
/eci msg p get def
/seq [
seq aload pop
[ eci ]
] def
/p p 1 add def
/seqlen seqlen eci -1810900 le {2} {eci -1000900 le {3} {2} ifelse} ifelse add def
} {
/n numdigits p get def
n 13 ge {
/seq [
seq aload pop
nl
[ barcode p n getinterval aload pop ]
[ msg p n getinterval aload pop ]
] def
/state N def
/p p n add def
14618,8 → 16446,10
t 5 ge {
/seq [
seq aload pop
state T ne {tl} if
[ barcode p t getinterval aload pop ]
state T ne {
tl
} if
[ msg p t getinterval aload pop ]
] def
/state T def
/p p t add def
14630,7 → 16460,7
/seq [
seq aload pop
bs
[ barcode p get ]
[ msg p get ]
] def
/p p b add def
/seqlen seqlen 2 add def
14638,18 → 16468,18
/seq [
seq aload pop
b 6 mod 0 ne {bl} {bl6} ifelse
[ barcode p b getinterval aload pop ]
[ msg p b getinterval aload pop ]
] def
/state B def
/p p b add def
/seqlen seqlen 1 add b add def
} ifelse } ifelse } ifelse
} ifelse } ifelse } ifelse } ifelse
} loop
 
/latchcws <<
tl 900 bl 901 bl6 924 nl 902 bs 913
>> def
 
% Submode encoding functions
/enca {charvals A get exch get} bind def
/encl {charvals L get exch get} bind def
14656,25 → 16486,25
/encm {charvals M get exch get} bind def
/encp {charvals P get exch get} bind def
/textencfuncs [ /enca /encl /encm /encp ] def
 
/addtotext {
text exch l exch put
/l l 1 add def
} bind def
 
/enct {
 
/in exch def
 
/curlen [ e e e e ] def
curlen submode 0 put
/curseq [ [] [] [] [] ] def
 
% Derive the optimal sequences ending in each submode
in {
 
/char exch def
 
% Check for optimisations in the current sequences by latching from x to y
{ % loop
/imp false def
14695,18 → 16525,18
} forall
imp not {exit} if % Repeat unless no improvement
} loop
 
% Determine optimal next sequences for each valid encoding
/nxtlen [ e e e e ] def
/nxtseq 4 array def
 
[ A L M P ] {
/x exch def
 
{ % loop for common exit
 
charvals x get char known not {exit} if
 
% Extend directly
/cost curlen x get 1 add def
cost nxtlen x get lt {
14713,7 → 16543,7
nxtlen x cost put
nxtseq x [ curseq x get aload pop char ] put
} if
 
% Optimise for direct shifts from y to x
[ A L M P ] {
/y exch def
14729,17 → 16559,17
} if
} if
} forall
 
exit
} loop
 
} forall
 
/curlen nxtlen def
/curseq nxtseq def
 
} forall
 
% Select the optimal sequence
/minseq e def
[ A L M P ] {
14749,24 → 16579,24
/txtseq curseq k get def
} if
} forall
 
% Encode the sequence
/text minseq array def
/k 0 def /l 0 def {
k txtseq length ge {exit} if
 
/char txtseq k get def
 
% Encode character
char textencfuncs submode get load exec addtotext
/k k 1 add def
 
% Encode shifted next character
char as eq char ps eq or {
txtseq k get char as eq {enca} {encp} ifelse addtotext
/k k 1 add def
} if
 
% Latches to new submode
char al eq {/submode A def} if
char ll eq {/submode L def} if
14773,7 → 16603,7
char ml eq {/submode M def} if
char pl eq {/submode P def} if
} loop
 
text length 2 mod 1 eq {
submode P eq {
/pad al encp def
14783,17 → 16613,17
} ifelse
/text [ text aload pop pad ] def
} if
 
/out text length 2 idiv array def
0 1 out length 1 sub {
/k exch def
out k text k 2 mul get 30 mul text k 2 mul 1 add get add put
} for
 
out
 
} bind def
 
/encn {
/in exch def
/out [] def
14827,22 → 16657,39
} for
out
} bind def
 
/ence {
0 get neg 1000000 sub
dup 000899 le { % ECI 000000 - 000899
927 exch 2 array astore
} { dup 810899 le { % ECI 000900 - 810899
926 exch dup 900 idiv 1 sub exch 900 mod 3 array astore
} { dup 811799 le { % ECI 810900 - 811799
925 exch 810900 sub 2 array astore
} {
/bwipp.pdf417badECI (PDF417 supports ECIs 000000 to 811799) //raiseerror exec
} ifelse } ifelse } ifelse
} bind def
 
/encfuncs [ /enct /encn /encb ] def
 
/addtocws {
dup datcws j 3 -1 roll putinterval
length j add /j exch def
} bind def
 
% Encode the sequence
/state T def /submode A def
% No need to set state as seq will always begin with a latch, unlike for pdf417
/datcws seqlen array def
/i 0 def /j 0 def {
i seq length ge {exit} if
/chars seq i get def
chars type /arraytype eq { % Encode data according to mode
chars encfuncs state get load exec addtocws
chars 0 get -1000000 le { % ECI
chars ence addtocws
} { % Encode data according to mode
chars encfuncs state get load exec addtocws
} ifelse
} { % Encode the latch to new state or byte shift
[ latchcws chars get ] addtocws
chars tl eq {/state T def /submode A def} if
14966,12 → 16813,12
% Generate the coefficients
/coeffs [ 1 k {0} repeat ] def
1 1 k {
/i exch def
/i exch def
coeffs i coeffs i 1 sub get put
i 1 sub -1 1 {
/j exch def
coeffs j coeffs j 1 sub get coeffs j get rsalog i get rsprod add 929 mod put
} for
} for
coeffs 0 coeffs 0 get rsalog i get rsprod put
} for
/coeffs coeffs 0 coeffs length 1 sub getinterval def
14990,6 → 16837,8
% Trim the working space from the end of the codewords
/cws cws 0 cws length 1 sub getinterval def
 
options /debugcws known { /bwipp.debugcws cws //raiseerror exec } if
 
% Base 10 encoding of the bar space successions for the codewords in each cluster
/clusters [
[
15319,7 → 17168,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/micropdf417 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
15328,16 → 17179,17
% --END ENCODER micropdf417--
 
% --BEGIN ENCODER datamatrix--
% --REQUIRES preamble raiseerror renmatrix--
% --REQUIRES preamble raiseerror parseinput renmatrix--
% --DESC: Data Matrix
% --EXAM: This is Data Matrix!
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp datamatrix 0.0 2018020400 246383 265388
%%BeginData: 876 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp datamatrix 0.0 2021092800 208367 234349
%%BeginData: 920 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
begin
/datamatrix {
15354,7 → 17206,12
/version (unset) def
/parse false def
/parsefnc false def
/dmre false def
/encoding (auto) def
/mailmark false def
/raw false def
/dmre false def % Alias for isodmre
/dindmre false def
/isodmre false def
 
% Parse the input options
options type /stringtype eq {
15376,121 → 17233,64
/columns columns cvi def
/rows rows cvi def
 
% Parse ordinals of the form ^NNN to ASCII
parse {
/msg barcode length string def
/j 0 def
barcode
{ % loop
(^) search {
dup msg exch j exch putinterval
length j add 1 add /j exch def
pop
dup 0 3 getinterval cvi msg exch j 1 sub exch put
dup length 3 sub 3 exch getinterval
} {
dup msg exch j exch putinterval
length j add /j exch def
/barcode msg 0 j getinterval def
exit
} ifelse
} loop
} if
/isodmre dmre def
 
% Macro 05/06 compression of [)>{RS}05/06{GS}...{RS}{EOT} structured data
/mac05comp false def
/mac06comp false def
barcode length 9 ge {
barcode 0 7 getinterval
dup ([\)>\03605\035) eq
exch ([\)>\03606\035) eq or
barcode barcode length 2 sub 2 getinterval (\036\004) eq and {
barcode 5 get 53 eq {/mac05comp} {/mac06comp} ifelse true def
/barcode barcode 7 barcode length 9 sub getinterval def
} if
} if
 
/barlen barcode length def
 
% Convert input into bytes accounting for FNC characters
/fnc1 -1 def /prog -2 def /m05 -3 def /m06 -4 def
/fncvals <<
(FNC1) fnc1
(PROG) prog
(MAC5) m05
(MAC6) m06
>> def
/msg barlen array def
/i 0 def /j 0 def {
i barlen eq {exit} if
/char barcode i get def
parsefnc char 94 eq and i barlen 4 sub lt and {
barcode i 1 add get 94 ne {
/char fncvals barcode i 1 add 4 getinterval get def
/i i 4 add def
} {
/i i 1 add def
} ifelse
} if
msg j char put
/i i 1 add def
/j j 1 add def
} loop
/msg msg 0 j getinterval def
 
% Prefix the Macro 05/06 compression indicator
mac05comp { /msg [ m05 msg aload pop ] def } if
mac06comp { /msg [ m06 msg aload pop ] def } if
 
/msglen msg length def
 
% Basic metrics for the each symbol
% rows cols regh regv rscw rsbl
% rows cols regh regv rscw rsbl
/metrics [
% Standard square symbols
[ 10 10 1 1 5 1 ]
[ 12 12 1 1 7 1 ]
[ 14 14 1 1 10 1 ]
[ 16 16 1 1 12 1 ]
[ 18 18 1 1 14 1 ]
[ 20 20 1 1 18 1 ]
[ 22 22 1 1 20 1 ]
[ 24 24 1 1 24 1 ]
[ 26 26 1 1 28 1 ]
[ 32 32 2 2 36 1 ]
[ 36 36 2 2 42 1 ]
[ 40 40 2 2 48 1 ]
[ 44 44 2 2 56 1 ]
[ 48 48 2 2 68 1 ]
[ 52 52 2 2 84 2 ]
[ 64 64 4 4 112 2 ]
[ 72 72 4 4 144 4 ]
[ 80 80 4 4 192 4 ]
[ 88 88 4 4 224 4 ]
[ 96 96 4 4 272 4 ]
[ 104 104 4 4 336 6 ]
[ 120 120 6 6 408 6 ]
[ 132 132 6 6 496 8 ]
[ 144 144 6 6 620 10 ]
[ 10 10 1 1 5 1 ]
[ 12 12 1 1 7 1 ]
[ 14 14 1 1 10 1 ]
[ 16 16 1 1 12 1 ]
[ 18 18 1 1 14 1 ]
[ 20 20 1 1 18 1 ]
[ 22 22 1 1 20 1 ]
[ 24 24 1 1 24 1 ]
[ 26 26 1 1 28 1 ]
[ 32 32 2 2 36 1 ]
[ 36 36 2 2 42 1 ]
[ 40 40 2 2 48 1 ]
[ 44 44 2 2 56 1 ]
[ 48 48 2 2 68 1 ]
[ 52 52 2 2 84 2 ]
[ 64 64 4 4 112 2 ]
[ 72 72 4 4 144 4 ]
[ 80 80 4 4 192 4 ]
[ 88 88 4 4 224 4 ]
[ 96 96 4 4 272 4 ]
[ 104 104 4 4 336 6 ]
[ 120 120 6 6 408 6 ]
[ 132 132 6 6 496 8 ]
[ 144 144 6 6 620 10 ]
% Optional rectangular symbols
[ 8 18 1 1 7 1 ]
[ 8 32 1 2 11 1 ]
dmre { [ 8 48 1 2 15 1 ] } if
dmre { [ 8 64 1 4 18 1 ] } if
[ 12 26 1 1 14 1 ]
[ 12 36 1 2 18 1 ]
dmre { [ 12 64 1 4 27 1 ] } if
[ 16 36 1 2 24 1 ]
[ 16 48 1 2 28 1 ]
dmre { [ 16 64 1 4 36 1 ] } if
dmre { [ 24 32 1 2 28 1 ] } if
dmre { [ 24 36 1 2 33 1 ] } if
dmre { [ 24 48 1 2 41 1 ] } if
dmre { [ 24 64 1 4 46 1 ] } if
dmre { [ 26 32 1 2 32 1 ] } if
dmre { [ 26 40 1 2 38 1 ] } if
dmre { [ 26 48 1 2 42 1 ] } if
dmre { [ 26 64 1 4 50 1 ] } if
[ 8 18 1 1 7 1 ]
[ 8 32 1 2 11 1 ]
dindmre isodmre or { [ 8 48 1 2 15 1 ] } if
dindmre isodmre or { [ 8 64 1 4 18 1 ] } if
isodmre { [ 8 80 1 4 22 1 ] } if
isodmre { [ 8 96 1 4 28 1 ] } if
isodmre { [ 8 120 1 6 32 1 ] } if
isodmre { [ 8 144 1 6 36 1 ] } if
[ 12 26 1 1 14 1 ]
[ 12 36 1 2 18 1 ]
dindmre isodmre or { [ 12 64 1 4 27 1 ] } if
isodmre { [ 12 88 1 4 36 1 ] } if
[ 16 36 1 2 24 1 ]
[ 16 48 1 2 28 1 ]
dindmre isodmre or { [ 16 64 1 4 36 1 ] } if
isodmre { [ 20 36 1 2 28 1 ] } if
isodmre { [ 20 44 1 2 34 1 ] } if
isodmre { [ 20 64 1 4 42 1 ] } if
isodmre { [ 22 48 1 2 38 1 ] } if
dindmre { [ 24 32 1 2 28 1 ] } if
dindmre { [ 24 36 1 2 33 1 ] } if
dindmre isodmre or { [ 24 48 1 2 41 1 ] } if
dindmre isodmre or { [ 24 64 1 4 46 1 ] } if
dindmre { [ 26 32 1 2 32 1 ] } if
dindmre isodmre or { [ 26 40 1 2 38 1 ] } if
dindmre isodmre or { [ 26 48 1 2 42 1 ] } if
dindmre isodmre or { [ 26 64 1 4 50 1 ] } if
] def
 
% Create array of codewords remaining to make a full symbol
15524,430 → 17324,521
} if
} for
 
% Special characters
/lC -5 def /lB -6 def /lX -7 def /lT -8 def /lE -9 def /unl -10 def
/sapp -11 def /usft -12 def /sft1 -13 def /sft2 -14 def /sft3 -15 def /eci -16 def /pad -17 def
/unlcw 254 def
raw {/encoding (raw) def} if
 
/Avals <<
0 1 128 {dup 1 add} for
pad 129
0 1 99 { % Double digits
dup 10 2 string cvrs (00) 2 string copy dup 2 3 index length sub 4 -1 roll putinterval
exch 130 add
} for
229 [ lC lB fnc1 sapp prog usft m05 m06 lX lT lE eci ] {exch 1 add dup} forall pop
>> def
/Avals <<
Avals {[exch]} forall
>> def
encoding (raw) eq {
/cws barcode length array def
/i 0 def /j 0 def
{ % loop
i barcode length eq {exit} if
/cw barcode i 1 add 3 getinterval cvi def
cws j cw put
/i i 4 add def
/j j 1 add def
} loop
/cws cws 0 j getinterval def
} if % encoding=raw
 
/CNvals <<
sft1 0
sft2 1
sft3 2
32 3
48 1 57 {dup 44 sub} for % 0-9
65 1 90 {dup 51 sub} for % A-Z
>> def
/C1vals << 0 1 31 {dup} for >> def
/C2vals <<
33 1 47 {dup 33 sub} for
58 1 64 {dup 43 sub} for
91 1 95 {dup 69 sub} for
fnc1 27
usft 30
>> def
/C3vals << 96 1 127 {dup 96 sub} for >> def
/Cvals <<
CNvals {[exch]} forall
C1vals {[exch CNvals sft1 get exch]} forall
C2vals {[exch CNvals sft2 get exch]} forall
C3vals {[exch CNvals sft3 get exch]} forall
>> def
encoding (auto) eq {
 
/TNvals <<
sft1 0
sft2 1
sft3 2
32 3
48 1 57 {dup 44 sub} for % 0-9
97 1 122 {dup 83 sub} for % a-z
>> def
/T1vals << 0 1 31 {dup} for >> def
/T2vals <<
33 1 47 {dup 33 sub} for
58 1 64 {dup 43 sub} for
91 1 95 {dup 69 sub} for
fnc1 27
usft 30
>> def
/T3vals <<
96 0
65 1 90 {dup 64 sub} for
123 1 127 {dup 96 sub} for
>> def
/Tvals <<
TNvals {[exch]} forall
T1vals {[exch TNvals sft1 get exch]} forall
T2vals {[exch TNvals sft2 get exch]} forall
T3vals {[exch TNvals sft3 get exch]} forall
>> def
% Special characters
/fnc1 -1 def /prog -2 def /m05 -3 def /m06 -4 def
/lC -5 def /lB -6 def /lX -7 def /lT -8 def /lE -9 def /unl -10 def
/sapp -11 def /usft -12 def /sft1 -13 def /sft2 -14 def /sft3 -15 def /eci -16 def /pad -17 def
/unlcw 254 def
 
% Extended ASCII mappings
128 1 255 {
/i exch def
Avals i [ Avals usft get aload pop Avals i 128 sub get aload pop ] put
Cvals i [ Cvals usft get aload pop Cvals i 128 sub get aload pop ] put
Tvals i [ Tvals usft get aload pop Tvals i 128 sub get aload pop ] put
} for
% Parse the input
/fncvals <<
/parse parse
/parsefnc parsefnc
/eci true
(FNC1) fnc1
(PROG) prog
% (MAC5) m05 Encoded automatically
% (MAC6) m06 Encoded automatically
>> def
/msg barcode fncvals //parseinput exec def
/msglen msg length def
 
/Xvals <<
13 0
42 1
62 2
32 3
48 1 57 {dup 44 sub} for
65 1 90 {dup 51 sub} for
>> def
/Xvals <<
Xvals {[exch]} forall
>> def
% Macro 05/06 compression of [)>{RS}05/06{GS}...{RS}{EOT} structured data
msglen 9 ge {
msg 0 7 getinterval aload pop
29 eq exch pop exch 48 eq and exch % [)>{RS}0*{GS}...
30 eq and exch 62 eq and exch 41 eq and exch 91 eq and {
msg msglen 2 sub 2 getinterval aload pop
4 eq exch 30 eq and { % ...{RS}{EOT}
msg 5 get 53 eq { % ...5...
/msg [ m05 msg 7 msg length 9 sub getinterval aload pop ] def
} {
msg 5 get 54 eq { % ...6...
/msg [ m06 msg 7 msg length 9 sub getinterval aload pop ] def
} if
} ifelse
} if
} if
} if
/msglen msg length def
 
/Evals <<
64 1 94 {dup 64 sub} for
unl 31
32 1 63 {dup} for
>> def
/Evals <<
Evals {[exch]} forall
>> def
/Avals <<
0 1 128 {dup 1 add} for
pad 129
0 1 99 { % Double digits
dup 10 2 string cvrs (00) 2 string copy dup 2 3 index length sub 4 -1 roll putinterval
exch 130 add
} for
229 [ lC lB fnc1 sapp prog usft m05 m06 lX lT lE eci ] {exch 1 add dup} forall pop
>> def
/Avals <<
Avals {[exch]} forall
>> def
 
/Bvals <<
0 1 255 {dup} for
>> def
/Bvals <<
Bvals {[exch]} forall
>> def
/CNvals <<
sft1 0
sft2 1
sft3 2
32 3
48 1 57 {dup 44 sub} for % 0-9
65 1 90 {dup 51 sub} for % A-Z
>> def
/C1vals << 0 1 31 {dup} for >> def
/C2vals <<
33 1 47 {dup 33 sub} for
58 1 64 {dup 43 sub} for
91 1 95 {dup 69 sub} for
fnc1 27
usft 30
>> def
/C3vals << 96 1 127 {dup 96 sub} for >> def
/Cvals <<
CNvals {[exch]} forall
C1vals {[exch CNvals sft1 get exch]} forall
C2vals {[exch CNvals sft2 get exch]} forall
C3vals {[exch CNvals sft3 get exch]} forall
>> def
 
/encvals [ Avals Cvals Tvals Xvals Evals Bvals ] def
/TNvals <<
sft1 0
sft2 1
sft3 2
32 3
48 1 57 {dup 44 sub} for % 0-9
97 1 122 {dup 83 sub} for % a-z
>> def
/T1vals << 0 1 31 {dup} for >> def
/T2vals <<
33 1 47 {dup 33 sub} for
58 1 64 {dup 43 sub} for
91 1 95 {dup 69 sub} for
fnc1 27
usft 30
>> def
/T3vals <<
96 0
65 1 90 {dup 64 sub} for
123 1 127 {dup 96 sub} for
>> def
/Tvals <<
TNvals {[exch]} forall
T1vals {[exch TNvals sft1 get exch]} forall
T2vals {[exch TNvals sft2 get exch]} forall
T3vals {[exch TNvals sft3 get exch]} forall
>> def
 
/numD [ msglen {0} repeat 0 ] def
/nextXterm [ msglen {0} repeat 9999 ] def
/nextNonX [ msglen {0} repeat 9999 ] def
msglen 1 sub -1 0 {
/i exch def
/barchar msg i get def
barchar 48 ge barchar 57 le and {
numD i numD i 1 add get 1 add put
} if
barchar 13 eq barchar 42 eq or barchar 62 eq or {
nextXterm i 0 put
} {
nextXterm i nextXterm i 1 add get 1 add put
} ifelse
Xvals barchar known not {
nextNonX i 0 put
} {
nextNonX i nextNonX i 1 add get 1 add put
} ifelse
} for
/nextXterm [nextXterm {dup 10000 gt {pop 10000} if} forall] def
/nextNonX [nextNonX {dup 10000 gt {pop 10000} if} forall] def
% Extended ASCII mappings
128 1 255 {
/i exch def
Avals i [ Avals usft get aload pop Avals i 128 sub get aload pop ] put
Cvals i [ Cvals usft get aload pop Cvals i 128 sub get aload pop ] put
Tvals i [ Tvals usft get aload pop Tvals i 128 sub get aload pop ] put
} for
 
/isD {char 48 ge char 57 le and} bind def
/isC {CNvals char known} bind def
/isT {TNvals char known} bind def
/isX {Xvals char known} bind def
/isE {Evals char known} bind def
/isEA {char 127 gt} bind def
/isFN {char 0 lt} bind def
/XtermFirst {dup nextXterm exch get exch nextNonX exch get lt} bind def
/Xvals <<
13 0
42 1
62 2
32 3
48 1 57 {dup 44 sub} for
65 1 90 {dup 51 sub} for
>> def
/Xvals <<
Xvals {[exch]} forall
>> def
 
/A 0 def /C 1 def /T 2 def /X 3 def /E 4 def /B 5 def
/Evals <<
64 1 94 {dup 64 sub} for
unl 31
32 1 63 {dup} for
>> def
/Evals <<
Evals {[exch]} forall
>> def
 
/lookup {
/ac 1 def /cc 2 def /tc 2 def /xc 2 def /ec 2 def /bc 2.25 def
mode A eq {/ac 0 def /cc 1 def /tc 1 def /xc 1 def /ec 1 def /bc 1.25 def} if
mode C eq {/cc 0 def} if
mode T eq {/tc 0 def} if
mode X eq {/xc 0 def} if
mode E eq {/ec 0 def} if
mode B eq {/bc 0 def} if
1 { % common exit
/k 0 def { % loop
i k add msglen eq {
[/ac /cc /tc /xc /ec /bc] {dup load ceiling def} forall
true [ cc tc xc ec bc] {ac exch le and} forall {A exit} if
true [ac cc tc xc ec ] {bc exch lt and} forall {B exit} if
true [ac cc tc xc bc] {ec exch lt and} forall {E exit} if
true [ac cc xc ec bc] {tc exch lt and} forall {T exit} if
true [ac cc tc ec bc] {xc exch lt and} forall {X exit} if
C exit
} if
/char msg i k add get def
/ac ac isD {1 2 div add} {isEA {ceiling 2 add} {ceiling 1 add} ifelse} ifelse def
/cc cc isC {2 3 div add} {isEA { 8 3 div add } { 4 3 div add } ifelse} ifelse def
/tc tc isT {2 3 div add} {isEA { 8 3 div add } { 4 3 div add } ifelse} ifelse def
/xc xc isX {2 3 div add} {isEA {13 3 div add } {10 3 div add } ifelse} ifelse def
/ec ec isE {3 4 div add} {isEA {17 4 div add } {13 4 div add } ifelse} ifelse def
/bc bc isFN {4 add} {1 add} ifelse def
k 4 ge {
true [ cc tc xc ec bc] {ac 1 add exch le and} forall {A exit} if
bc 1 add ac le {B exit} if
true [ cc tc xc ec ] {bc 1 add exch lt and} forall {B exit} if
true [ac cc tc xc bc] {ec 1 add exch lt and} forall {E exit} if
true [ac cc xc ec bc] {tc 1 add exch lt and} forall {T exit} if
true [ac cc tc ec bc] {xc 1 add exch lt and} forall {X exit} if
true [ac tc ec bc] {cc 1 add exch lt and} forall {
cc xc lt {C exit} if
cc xc eq {i k add 1 add XtermFirst {X exit} {C exit} ifelse} if
} if
} if
/k k 1 add def
} loop
} repeat
} bind def
/Bvals <<
0 1 255 {dup} for
>> def
/Bvals <<
Bvals {[exch]} forall
>> def
 
/addtocws {
dup cws exch j exch putinterval
/j exch length j add def
} bind def
/encvals [ Avals Cvals Tvals Xvals Evals Bvals ] def
 
/encA {
1 { % Common exit
numD i get 2 ge {
2 string dup 0 msg i get put dup 1 msg i 1 add get put Avals exch get addtocws
/i i 2 add def
exit
/numD [ msglen {0} repeat 0 ] def
/nextXterm [ msglen {0} repeat 9999 ] def
/nextNonX [ msglen {0} repeat 9999 ] def
/isECI [ msglen {false} repeat false ] def
msglen 1 sub -1 0 {
/i exch def
/barchar msg i get def
barchar 48 ge barchar 57 le and {
numD i numD i 1 add get 1 add put
} if
/newmode lookup def
newmode mode ne {
Avals [-1 lC lT lX lE lB] newmode get get addtocws
/mode newmode def
exit
} if
Avals msg i get get addtocws
/i i 1 add def
exit
} repeat
} bind def
 
/CTXvalstocws {
/in exch def
mark
0 3 in length 1 sub {
in exch 3 getinterval 0 exch {add 40 mul} forall 40 idiv 1 add
dup 256 idiv exch 256 mod
barchar 13 eq barchar 42 eq or barchar 62 eq or {
nextXterm i 0 put
} {
nextXterm i nextXterm i 1 add get 1 add put
} ifelse
Xvals barchar known not {
nextNonX i 0 put
} {
nextNonX i nextNonX i 1 add get 1 add put
} ifelse
isECI i barchar -1000000 le put
} for
counttomark array astore exch pop
} bind def
/nextXterm [nextXterm {dup 10000 gt {pop 10000} if} forall] def
/nextNonX [nextNonX {dup 10000 gt {pop 10000} if} forall] def
 
/encCTX {
/p 0 def
/ctxvals 2500 array def
/isD {char 48 ge char 57 le and} bind def
/isC {CNvals char known} bind def
/isT {TNvals char known} bind def
/isX {Xvals char known} bind def
/isE {Evals char known} bind def
/isEA {char 127 gt} bind def
/isFN {char 0 lt} bind def
/XtermFirst {dup nextXterm exch get exch nextNonX exch get lt} bind def
 
% Lookup the values for each character
{
i msglen eq {exit} if
encvals mode get msg i get known not {exit} if
p 3 mod 0 eq {
lookup mode ne {
ctxvals 0 p getinterval CTXvalstocws addtocws
[unlcw] addtocws
/mode A def
/A 0 def /C 1 def /T 2 def /X 3 def /E 4 def /B 5 def
 
/lookup {
/ac 1 def /cc 2 def /tc 2 def /xc 2 def /ec 2 def /bc 2.25 def
mode A eq {/ac 0 def /cc 1 def /tc 1 def /xc 1 def /ec 1 def /bc 1.25 def} if
mode C eq {/cc 0 def} if
mode T eq {/tc 0 def} if
mode X eq {/xc 0 def} if
mode E eq {/ec 0 def} if
mode B eq {/bc 0 def} if
1 { % common exit
isECI i get {A exit} if % ECI only in ASCII
mailmark i 45 lt and {C exit} if % Mailmark is C40 only for 45 characters
/k 0 def { % loop
i k add msglen eq {
[/ac /cc /tc /xc /ec /bc] {dup load ceiling def} forall
true [ cc tc xc ec bc] {ac exch le and} forall {A exit} if
true [ac cc tc xc ec ] {bc exch lt and} forall {B exit} if
true [ac cc tc xc bc] {ec exch lt and} forall {E exit} if
true [ac cc xc ec bc] {tc exch lt and} forall {T exit} if
true [ac cc tc ec bc] {xc exch lt and} forall {X exit} if
C exit
} if
/char msg i k add get def
/ac ac isD {1 2 div add} {isEA {ceiling 2 add} {ceiling 1 add} ifelse} ifelse def
/cc cc isC {2 3 div add} {isEA { 8 3 div add } { 4 3 div add } ifelse} ifelse def
/tc tc isT {2 3 div add} {isEA { 8 3 div add } { 4 3 div add } ifelse} ifelse def
/xc xc isX {2 3 div add} {isEA {13 3 div add } {10 3 div add } ifelse} ifelse def
/ec ec isE {3 4 div add} {isEA {17 4 div add } {13 4 div add } ifelse} ifelse def
/bc bc isFN {4 add} {1 add} ifelse def
k 4 ge {
true [ cc tc xc ec bc] {ac 1 add exch le and} forall {A exit} if
bc 1 add ac le {B exit} if
true [ cc tc xc ec ] {bc 1 add exch lt and} forall {B exit} if
true [ac cc tc xc bc] {ec 1 add exch lt and} forall {E exit} if
true [ac cc xc ec bc] {tc 1 add exch lt and} forall {T exit} if
true [ac cc tc ec bc] {xc 1 add exch lt and} forall {X exit} if
true [ac tc ec bc] {cc 1 add exch lt and} forall {
cc xc lt {C exit} if
cc xc eq {i k add 1 add XtermFirst {X exit} {C exit} ifelse} if
} if
} if
/k k 1 add def
} loop
} repeat
} bind def
 
/addtocws {
dup cws exch j exch putinterval
/j exch length j add def
} bind def
 
/ECItocws {
neg 1000000 sub
dup 000126 le { % ECI 000000 - 000126
1 add
1 array astore
} { dup 016382 le { % ECI 000127 - 016382
127 sub
dup 254 idiv 128 add exch
254 mod 1 add
2 array astore
} { % ECI 016383 - 999999
16383 sub
dup 64516 idiv 192 add exch
dup 254 idiv 254 mod 1 add exch
254 mod 1 add
3 array astore
} ifelse } ifelse
} bind def
 
/encA {
1 { % Common exit
isECI i get {
Avals eci get addtocws
msg i get ECItocws addtocws
/i i 1 add def
exit
} if
msglen i sub 3 le { % Check end of data conditions
/remcws numremcws j p 3 idiv 2 mul add get def
/remvals [
msg i msglen i sub getinterval {
dup encvals mode get exch known {
encvals mode get exch get aload pop
} { % Unencodable X12 characters
pop -1 -1 -1 -1
} ifelse
} forall
] def
remcws 2 eq remvals length 3 eq and {
% Encode and omit unlatch
[
ctxvals 0 p getinterval aload pop
remvals aload pop
] CTXvalstocws addtocws
/mode A def
/i msglen def
exit
} if
remcws 2 eq remvals length 2 eq and mode X ne and {
% Encode with sft1 as third value, omit unlatch
[
ctxvals 0 p getinterval aload pop
remvals aload pop
encvals mode get sft1 get aload pop
] CTXvalstocws addtocws
/mode A def
/i msglen def
exit
} if
remcws 2 eq remvals length 1 eq and {
% Unlatch to ASCII
numD i get 2 ge {
2 string dup 0 msg i get put dup 1 msg i 1 add get put Avals exch get addtocws
/i i 2 add def
exit
} if
/newmode lookup def
newmode mode ne {
Avals [-1 lC lT lX lE lB] newmode get get addtocws
/mode newmode def
exit
} if
Avals msg i get get addtocws
/i i 1 add def
exit
} repeat
} bind def
 
/CTXvalstocws {
/in exch def
mark
0 3 in length 1 sub {
in exch 3 getinterval 0 exch {add 40 mul} forall 40 idiv 1 add
dup 256 idiv exch 256 mod
} for
counttomark array astore exch pop
} bind def
 
/encCTX {
/p 0 def
/ctxvals 2500 array def
/done false def
 
% Lookup the values for each character
{
i msglen eq {exit} if
encvals mode get msg i get known not {exit} if
p 3 mod 0 eq {
/newmode lookup def
newmode mode ne {
ctxvals 0 p getinterval CTXvalstocws addtocws
[unlcw] addtocws
Avals msg i get get addtocws
/mode A def
/i msglen def
newmode A ne {
Avals [-1 lC lT lX lE lB] newmode get get addtocws
} if
/mode newmode def
/done true def
exit
} if
remcws 1 eq remvals length 1 eq and {
% Implied unlatch to ASCII
ctxvals 0 p getinterval CTXvalstocws addtocws
Avals msg i get get addtocws
/mode A def
/i msglen def
exit
msglen i sub 3 le { % Check end of data conditions
/remcws numremcws j p 3 idiv 2 mul add get def
/remvals [
msg i msglen i sub getinterval {
dup encvals mode get exch known {
encvals mode get exch get aload pop
} { % Unencodable X12 characters
pop -1 -1 -1 -1
} ifelse
} forall
] def
remcws 2 eq remvals length 3 eq and {
% Encode and omit unlatch
[
ctxvals 0 p getinterval aload pop
remvals aload pop
] CTXvalstocws addtocws
/mode A def
/i msglen def
/done true def
exit
} if
remcws 2 eq remvals length 2 eq and mode X ne and {
% Encode with sft1 as third value, omit unlatch
[
ctxvals 0 p getinterval aload pop
remvals aload pop
encvals mode get sft1 get aload pop
] CTXvalstocws addtocws
/mode A def
/i msglen def
/done true def
exit
} if
remcws 2 eq remvals length 1 eq and {
% Unlatch to ASCII
ctxvals 0 p getinterval CTXvalstocws addtocws
[unlcw] addtocws
Avals msg i get get addtocws
/mode A def
/i msglen def
/done true def
exit
} if
remcws 1 eq remvals length 1 eq and {
% Implied unlatch to ASCII
ctxvals 0 p getinterval CTXvalstocws addtocws
Avals msg i get get addtocws
/mode A def
/i msglen def
/done true def
exit
} if
} if
} if
} if
encvals mode get msg i get get
dup ctxvals exch p exch putinterval
/p exch length p add def
/i i 1 add def
} loop
encvals mode get msg i get get
dup ctxvals exch p exch putinterval
/p exch length p add def
/i i 1 add def
} loop
 
% Backtrack to a boundary and return to ASCII
mode A ne {
{
p 3 mod 0 eq {exit} if
/i i 1 sub def
/p p encvals mode get msg i get get length sub def
} loop
[
ctxvals 0 p getinterval aload pop
] CTXvalstocws addtocws
[unlcw] addtocws
/mode A def
% Encode something to avoid latching immediately back
i msglen ne {
numD i get 2 ge {
2 string dup 0 msg i get put dup 1 msg i 1 add get put Avals exch get addtocws
/i i 2 add def
} {
Avals msg i get get addtocws
/i i 1 add def
} ifelse
% Backtrack to a boundary and return to ASCII
done not {
{
p 3 mod 0 eq {exit} if
/i i 1 sub def
/p p encvals mode get msg i get get length sub def
} loop
[
ctxvals 0 p getinterval aload pop
] CTXvalstocws addtocws
[unlcw] addtocws
/mode A def
% Encode something to avoid latching immediately back
i msglen ne isECI i get not and {
numD i get 2 ge {
2 string dup 0 msg i get put dup 1 msg i 1 add get put Avals exch get addtocws
/i i 2 add def
} {
Avals msg i get get addtocws
/i i 1 add def
} ifelse
} if
} if
} if
 
} bind def
} bind def
 
/Evalstocws {
/in exch def
/inlen in length def
/outlen in length 4 div 3 mul ceiling cvi def
/in [ in aload pop 0 0 0 ] def
mark
0 4 inlen 1 sub {
in exch 4 getinterval 0 exch {or 6 bitshift} forall -6 bitshift
dup -16 bitshift 255 and exch
dup -8 bitshift 255 and exch
255 and
} for
counttomark array astore exch pop
0 outlen getinterval
} bind def
/Evalstocws {
/in exch def
/inlen in length def
/outlen in length 4 div 3 mul ceiling cvi def
/in [ in aload pop 0 0 0 ] def
mark
0 4 inlen 1 sub {
in exch 4 getinterval 0 exch {or 6 bitshift} forall -6 bitshift
dup -16 bitshift 255 and exch
dup -8 bitshift 255 and exch
255 and
} for
counttomark array astore exch pop
0 outlen getinterval
} bind def
 
/encE {
/p 0 def
/edifactvals 2100 array def
/encE {
/p 0 def
/edifactvals 2100 array def
 
% Lookup the values for each character
{
i msglen eq {exit} if
Evals msg i get known not {exit} if
p 4 mod 0 eq {
msglen i sub 2 le { % Check end of data condition
/remcws numremcws j p 4 idiv 3 mul add get def
/remvals [
msg i msglen i sub getinterval {
Avals exch get aload pop
} forall
] def
remcws 1 eq remcws 2 eq or remvals length remcws le and {
% Implied unlatch to ASCII
edifactvals 0 p getinterval Evalstocws addtocws
remvals addtocws
/mode A def
/i msglen def
exit
% Lookup the values for each character
{
i msglen eq {exit} if
Evals msg i get known not {exit} if
p 4 mod 0 eq {
msglen i sub 2 le { % Check end of data condition
/remcws numremcws j p 4 idiv 3 mul add get def
/remvals [
msg i msglen i sub getinterval {
Avals exch get aload pop
} forall
] def
remcws 1 eq remcws 2 eq or remvals length remcws le and {
% Implied unlatch to ASCII
edifactvals 0 p getinterval Evalstocws addtocws
remvals addtocws
/mode A def
/i msglen def
exit
} if
} if
lookup mode ne {exit} if
} if
lookup mode ne {exit} if
} if
Evals msg i get get
dup edifactvals exch p exch putinterval
/p exch length p add def
/i i 1 add def
} loop
 
% Unlatch and pad with zeros until boundary
mode A ne {
/remcws numremcws j p 4 idiv 3 mul add 1 sub get 1 sub def
p 4 mod 0 ne i msglen ne or remcws 3 ge or { % Unlatch unless less than 3 codewords remain
Evals unl get
Evals msg i get get
dup edifactvals exch p exch putinterval
/p exch length p add def
/i i 1 add def
} loop
 
% Unlatch and pad with zeros until boundary
mode A ne {
/remcws numremcws j p 4 idiv 3 mul add 1 sub get 1 sub def
p 4 mod 0 ne i msglen ne or remcws 3 ge or { % Unlatch unless less than 3 codewords remain
Evals unl get
dup edifactvals exch p exch putinterval
/p exch length p add def
} if
edifactvals 0 p getinterval Evalstocws addtocws
/mode A def
% Encode something to avoid latching immediately back
i msglen ne isECI i get not and {
numD i get 2 ge {
2 string dup 0 msg i get put dup 1 msg i 1 add get put Avals exch get addtocws
/i i 2 add def
} {
Avals msg i get get addtocws
/i i 1 add def
} ifelse
} if
} if
edifactvals 0 p getinterval Evalstocws addtocws
/mode A def
% Encode something to avoid latching immediately back
i msglen ne {
numD i get 2 ge {
2 string dup 0 msg i get put dup 1 msg i 1 add get put Avals exch get addtocws
/i i 2 add def
 
} bind def
 
/encB {
/p 0 def /bvals 1558 array def {
i msglen eq {exit} if
lookup mode ne {exit} if
bvals p msg i get put
/p p 1 add def
/i i 1 add def
} loop
/remcws numremcws j p add get 1 sub def
/bvals [
remcws 0 eq i msglen eq and { % Terminates symbol
0
} {
Avals msg i get get addtocws
/i i 1 add def
p 250 lt {p} {p 250 idiv 249 add p 250 mod} ifelse
} ifelse
} if
} if
bvals 0 p getinterval aload pop
] def
0 1 bvals length 1 sub { % Pseudo-randomise based on codeword position
/p exch def
j p add 1 add 149 mul 255 mod 1 add bvals p get add
dup 256 ge {256 sub} if
bvals exch p exch put
} for
bvals addtocws
/mode A def
} bind def
 
} bind def
 
/encB {
/p 0 def /bvals 1558 array def {
i msglen eq {exit} if
lookup mode ne {exit} if
bvals p msg i get put
/p p 1 add def
/i i 1 add def
% Derive the codewords
/cws 1558 array def
/mode A def /i 0 def /j 0 def {
i msglen ge {exit} if
[ /encA /encCTX /encCTX /encCTX /encE /encB ] mode get load exec
} loop
/remcws numremcws j p add get 1 sub def
/bvals [
remcws 0 eq i msglen eq and { % Terminates symbol
0
} {
p 250 lt {p} {p 250 idiv 249 add p 250 mod} ifelse
} ifelse
bvals 0 p getinterval aload pop
] def
0 1 bvals length 1 sub { % Pseudo-randomise based on codeword position
/p exch def
j p add 1 add 149 mul 255 mod 1 add bvals p get add
dup 256 ge {256 sub} if
bvals exch p exch put
} for
bvals addtocws
/mode A def
} bind def
/cws cws 0 j getinterval def
 
% Derive the codewords
/cws 1558 array def
/mode A def /i 0 def /j 0 def {
i msglen ge {exit} if
[ /encA /encCTX /encCTX /encCTX /encE /encB ] mode get load exec
} loop
/cws cws 0 j getinterval def
} if % encoding=auto
 
% Extend codewords to fill symbol with pseudo-randomised pad characters
/datlen cws length def
15962,6 → 17853,8
} for
} if
 
options /debugcws known { /bwipp.debugcws cws //raiseerror exec } if
 
% Lookup symbol metrics based on number of codewords and user specification
/i 0 def { % loop
/m metrics i get def
16189,7 → 18082,7
/cwpos cwpos 1 add def
} if
} for
} if
} if
} for
 
% Return the arguments
16207,7 → 18100,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/datamatrix dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
16216,13 → 18111,13
% --END ENCODER datamatrix--
 
% --BEGIN ENCODER datamatrixrectangular--
% --REQUIRES preamble raiseerror renmatrix datamatrix--
% --REQUIRES preamble raiseerror parseinput renmatrix datamatrix--
% --DESC: Data Matrix Rectangular
% --EXAM: 1234
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp datamatrixrectangular 0.0 2018020400 59607 59346
%%BeginData: 43 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp datamatrixrectangular 0.0 2021092800 53411 56710
%%BeginData: 45 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
16257,12 → 18152,14
 
args (opt) options put
args
 
dontdraw not //renmatrix if
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/datamatrixrectangular dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
16270,17 → 18167,177
%%EndResource
% --END ENCODER datamatrixrectangular--
 
% --BEGIN ENCODER datamatrixrectangularextension--
% --REQUIRES preamble raiseerror parseinput renmatrix datamatrix--
% --DESC: Data Matrix Rectangular Extension
% --EXAM: 1234
% --EXOP: version=8x96
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp datamatrixrectangularextension 0.0 2021092800 54318 57584
%%BeginData: 55 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
dup /datamatrix dup /uk.co.terryburton.bwipp findresource put
begin
/datamatrixrectangularextension {
 
20 dict begin
 
/options exch def
/barcode exch def
 
/dontdraw false def
 
/dmre false def
/dindmre false def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
options {
token false eq {exit} if dup length string cvs (=) search
true eq {cvlit exch pop exch def} {cvlit true def} ifelse
} loop
currentdict end /options exch def
} if
options {def} forall
 
% Get the result of encoding with datamatrix
options (dontdraw) true put
options (format) (rectangle) put
 
dindmre dmre or not { % Default is (ISO) DMRE
options (dmre) true put
} { % Otherwise enable formats as given
options (dmre) dmre put % ISO
options (dindmre) dindmre put % DIN
} ifelse
 
/args barcode options //datamatrix exec def
 
args (opt) options put
args
 
dontdraw not //renmatrix if
 
end
 
}
[/barcode] {null def} forall
bind def
/datamatrixrectangularextension dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER datamatrixrectangularextension--
 
% --BEGIN ENCODER mailmark--
% --REQUIRES preamble raiseerror parseinput renmatrix datamatrix--
% --DESC: Royal Mail Mailmark
% --EXAM: JGB 012100123412345678AB19XY1A 0 www.xyz.com
% --EXOP: type=29
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp mailmark 0.0 2021092800 56791 60248
%%BeginData: 80 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
dup /datamatrix dup /uk.co.terryburton.bwipp findresource put
begin
/mailmark {
 
20 dict begin % Confine variables to local scope
 
/options exch def % We are given an option string
/barcode exch def % We are given a barcode string
 
/type (unset) def % 7, 9 or 29
/parse false def
/dontdraw false def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
options {
token false eq {exit} if dup length string cvs (=) search
true eq {cvlit exch pop exch def} {cvlit true def} ifelse
} loop
currentdict end /options exch def
} if
options {def} forall
 
% Parse ordinals of the form ^NNN to ASCII
/fncvals <<
/parse parse
/parseonly true
/parsefnc false
>> def
/barcode barcode fncvals //parseinput exec def
/barlen barcode length def
options (parse) undef
 
% Map the given type to a format and version of Data Matrix
<<
(7) (24x24)
(9) (32x32)
(29) (16x48)
>> /type load get /version exch def
 
<<
(7) (square)
(9) (square)
(29) (rectangle)
>> /type load get /format exch def
 
% Validate the input
barcode length 45 lt {
/bwipp.mailmarkBadLength (Royal Mail Mailmark must contain at least 45 characters of Mailmark formatted data, including any required space padding) //raiseerror exec
} if
barcode 0 4 getinterval (JGB ) ne {
/bwipp.mailmarkBadIndicator (Royal Mail Mailmark must begin with JGB<space> identifier) //raiseerror exec
} if
 
% Get the result of encoding with datamatrix
options (dontdraw) true put
options (version) version put
options (format) format put
options (mailmark) true put
/args barcode options //datamatrix exec def
 
args (opt) options put
args
 
dontdraw not //renmatrix if
 
end
 
}
[/barcode] {null def} forall
bind def
/mailmark dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER mailmark--
 
% --BEGIN ENCODER qrcode--
% --REQUIRES preamble raiseerror renmatrix--
% --REQUIRES preamble raiseerror parseinput renmatrix--
% --DESC: QR Code
% --EXAM: http://goo.gl/0bis
% --EXOP: eclevel=M
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp qrcode 0.0 2018020400 311593 330201
%%BeginData: 1028 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp qrcode 0.0 2021092800 320203 358349
%%BeginData: 1306 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
begin
/qrcode {
16291,9 → 18348,9
/barcode exch def
 
/dontdraw false def
/format (full) def % full or micro or any
/version (unset) def % 1-40 or M1-M4
/eclevel (unset) def % L, M, Q or H
/format (unset) def % full or micro. rMQR symbols are specified using version
/version (unset) def % 1-40 or M1-M4 or R7x43, etc
/eclevel (unset) def % full: L, M, Q, H; micro: L, M, Q; rmqr: M, H
/parse false def
/parsefnc false def
/mask -1 def
16311,51 → 18368,30
 
/mask mask cvi def
 
% Parse ordinals of the form ^NNN to ASCII
parse {
/msg barcode length string def
/j 0 def
barcode
{ % loop
(^) search {
dup msg exch j exch putinterval
length j add 1 add /j exch def
pop
dup 0 3 getinterval cvi msg exch j 1 sub exch put
dup length 3 sub 3 exch getinterval
} {
dup msg exch j exch putinterval
length j add /j exch def
/barcode msg 0 j getinterval def
exit
} ifelse
} loop
} if
% If version is supplied and format is not given then set format to correspond
version (unset) ne {
format (unset) eq {
(full)
version 0 1 getinterval (M) eq { pop (micro) } if
version 0 1 getinterval (R) eq { pop (rmqr) } if
/format exch def
} if
} {
format (unset) eq { /format (full) def } if % Default to full
} ifelse
 
/barlen barcode length def
% Default error correction level
eclevel (unset) eq {/eclevel format (micro) ne {(M)} {(L)} ifelse def} if
 
% Convert input into bytes accounting for FNC characters
% Parse the input
/fn1 -1 def
/fncvals <<
/parse parse
/parsefnc parsefnc
/eci true
(FNC1) fn1
>> def
/msg barlen array def
/i 0 def /j 0 def {
i barlen eq {exit} if
/char barcode i get def
parsefnc char 94 eq and i barlen 4 sub lt and {
barcode i 1 add get 94 ne {
/char fncvals barcode i 1 add 4 getinterval get def
/i i 4 add def
} {
/i i 1 add def
} ifelse
} if
msg j char put
/i i 1 add def
/j j 1 add def
} loop
/msg msg 0 j getinterval def
/msg barcode fncvals //parseinput exec def
/msglen msg length def
 
% If FNC1 in first position then escape % as %%
16368,18 → 18404,30
} if
} if
 
% Default error correction level
eclevel (unset) eq {/eclevel format (full) eq {(M)} {(L)} ifelse def} if
% Enumerate vergrps
[
/v1to9 /v10to26 /v27to40
/vM1 /vM2 /vM3 /vM4
/vR7x43 /vR7x59 /vR7x77 /vR7x99 /vR7x139
/vR9x43 /vR9x59 /vR9x77 /vR9x99 /vR9x139
/vR11x27 /vR11x43 /vR11x59 /vR11x77 /vR11x99 /vR11x139
/vR13x27 /vR13x43 /vR13x59 /vR13x77 /vR13x99 /vR13x139
/vR15x43 /vR15x59 /vR15x77 /vR15x99 /vR15x139
/vR17x43 /vR17x59 /vR17x77 /vR17x99 /vR17x139
] 0 exch {1 index def 1 add} forall pop
 
% Convert from input into message bitstream
/N 0 def /A 1 def /B 2 def /K 3 def
%
% Modes: (N)umeric, (A)lphanumeric, (B)yte, (K)anji, (E)CI
%
/N 0 def /A 1 def /B 2 def /K 3 def /E 4 def
 
/Nexcl <<
[
16#30 1 16#39 {} for
] {-1} forall
>> def
 
/Aexcl <<
[
16#20 16#24 16#25 16#2A 16#2B 16#2D 16#2E 16#2F 16#3A
16387,7 → 18435,7
fn1
] {-1} forall
>> def
 
/Bexcl <<
[
16#00 1 16#1F {} for
16397,7 → 18445,7
16#A0 1 16#DF {} for
] {-1} forall
>> def
 
/Kexcl <<
[
16#81 1 16#9F {} for
16404,29 → 18452,76
16#E0 1 16#EB {} for
] {-1} forall
>> def
/mids [ % N A B K
[ (0001) (0010) (0100) (1000) ] % 1-9
[ (0001) (0010) (0100) (1000) ] % 10-26
[ (0001) (0010) (0100) (1000) ] % 27-40
[ () -1 -1 -1 ] % M1
[ (0) (1) -1 -1 ] % M2
[ (00) (01) (10) (11) ] % M3
[ (000) (001) (010) (011) ] % M4
 
/mids [
% N A B K E
[ (0001) (0010) (0100) (1000) (0111) ] % v1to9
[ (0001) (0010) (0100) (1000) (0111) ] % v10to26
[ (0001) (0010) (0100) (1000) (0111) ] % v27to40
[ () -1 -1 -1 -1 ] % vM1
[ (0) (1) -1 -1 -1 ] % vM2
[ (00) (01) (10) (11) -1 ] % vM3
[ (000) (001) (010) (011) -1 ] % vM4
32 {
[ (001) (010) (011) (100) -1 ] % rMQR
} repeat
] def
 
/cclens [ % N A B K
[ 10 9 8 8 ] % 1-9
[ 12 11 16 10 ] % 10-26
[ 14 13 16 12 ] % 27-40
[ 3 -1 -1 -1 ] % M1
[ 4 3 -1 -1 ] % M2
[ 5 4 4 3 ] % M3
[ 6 5 5 4 ] % M4
[ 10 9 8 8 ] % v1to9
[ 12 11 16 10 ] % v10to26
[ 14 13 16 12 ] % v27to40
[ 3 -1 -1 -1 ] % vM1
[ 4 3 -1 -1 ] % vM2
[ 5 4 4 3 ] % vM3
[ 6 5 5 4 ] % vM4
[ 4 3 3 2 ] % vR7x43
[ 5 5 4 3 ] % vR7x59
[ 6 5 5 4 ] % vR7x77
[ 7 6 5 5 ] % vR7x99
[ 7 6 6 5 ] % vR7x139
[ 5 5 4 3 ] % vR9x43
[ 6 5 5 4 ] % vR9x59
[ 7 6 5 5 ] % vR9x77
[ 7 6 6 5 ] % vR9x99
[ 8 7 6 6 ] % vR9x139
[ 4 4 3 2 ] % vR11x27
[ 6 5 5 4 ] % vR11x43
[ 7 6 5 5 ] % vR11x59
[ 7 6 6 5 ] % vR11x77
[ 8 7 6 6 ] % vR11x99
[ 8 7 7 6 ] % vR11x139
[ 5 5 4 3 ] % vR13x27
[ 6 6 5 5 ] % vR13x43
[ 7 6 6 5 ] % vR13x59
[ 8 7 6 6 ] % vR13x77
[ 8 7 7 6 ] % vR13x99
[ 8 8 7 7 ] % vR13x139
[ 7 6 6 5 ] % vR15x43
[ 7 7 6 5 ] % vR15x59
[ 8 7 7 6 ] % vR15x77
[ 8 7 7 6 ] % vR15x99
[ 9 8 7 7 ] % vR15x139
[ 7 6 6 5 ] % vR17x43
[ 8 7 6 6 ] % vR17x59
[ 8 7 7 6 ] % vR17x77
[ 8 8 7 6 ] % vR17x99
[ 9 8 8 7 ] % vR17x139
] def
/termlens [ 4 4 4 3 5 7 9 ] def
 
/termlens [
3 {
4 % Full
} repeat
3 % vM1
5 % vM2
7 % vM3
9 % vM4
32 {
3 % rMQR
} repeat
] def
 
% Encoding functions
/tobin {
string dup length 1 sub 0 exch 1 exch {1 index exch 48 put} for
16441,7 → 18536,7
/encA {
/in exch def
fnc1first { % FNC1 as %
/in [ in { dup -1 eq {pop 37} if } forall ] def
/in [ in { dup fn1 eq {pop 37} if } forall ] def
} if
/out in length 11 mul 2 idiv 1 add string def
/k 0 def /m 0 def {
16458,7 → 18553,7
} loop
out 0 m getinterval
} bind def
 
/encN {
/in exch def
/out in length 10 mul 3 idiv 1 add string def
16481,11 → 18576,11
} loop
out 0 m getinterval
} bind def
 
/encB {
/in exch def
fnc1first { % FNC1 as GS
/in [ in { dup -1 eq {pop 29} if } forall ] def
/in [ in { dup fn1 eq {pop 29} if } forall ] def
} if
/out in length 8 mul string def
0 1 in length 1 sub {
16495,7 → 18590,7
} for
out
} bind def
 
/encK {
/in exch def
/out in length 2 idiv 13 mul string def
16510,28 → 18605,46
} loop
out
} bind def
/encfuncs [ /encN /encA /encB /encK ] def
 
/encE {
0 get neg 1000000 sub
dup 000127 le { % ECI 000000 - 000127
8 tobin
} { dup 016383 le { % ECI 000128 - 016383
2#1000000000000000 add 16 tobin
} { % ECI 016384 - 999999
2#110000000000000000000000 add 24 tobin
} ifelse } ifelse
} bind def
 
/encfuncs [ /encN /encA /encB /encK /encE ] def
 
/addtobits {
dup bits j 3 -1 roll putinterval
length j add /j exch def
} bind def
 
/numNs [ msglen {0} repeat 0 ] def
/numAs [ msglen {0} repeat 0 ] def
/numBs [ msglen {0} repeat 0 ] def
/numKs [ msglen {0} repeat -1 ] def
/numKs [ msglen {0} repeat 0 ] def
/nextNs [ msglen {0} repeat 9999 ] def
/nextBs [ msglen {0} repeat 9999 ] def
/nextAs [ msglen {0} repeat 9999 ] def
/nextKs [ msglen {0} repeat 9999 ] def
/numAN 0 def % Inclusive alphanumeric count (for rMQR only)
/isECI msglen array def
msglen 1 sub -1 0 {
/i exch def
/barchar msg i get def
Kexcl barchar known {
nextKs i 0 put
numKs i numKs i 1 add get 1 add put
/sjis i 1 add msglen lt { barchar 256 mul msg i 1 add get add } {0} ifelse def % Zero if last char
sjis 16#8140 ge sjis 16#9FFC le and sjis 16#E040 ge sjis 16#EBBF le and or {
nextKs i 0 put
numKs i numKs i 2 add get 1 add put
} {
nextKs i nextKs i 1 add get 1 add put
} ifelse
} {
nextKs i nextKs i 1 add get 1 add put
} ifelse
16538,6 → 18651,7
Nexcl barchar known {
nextNs i 0 put
numNs i numNs i 1 add get 1 add put
/numAN numAN 1 add def
} {
nextNs i nextNs i 1 add get 1 add put
} ifelse
16550,12 → 18664,20
Aexcl barchar known {
nextAs i 0 put
numAs i numAs i 1 add get 1 add put
/numAN numAN 1 add def
} {
nextAs i nextAs i 1 add get 1 add put
} ifelse
isECI i barchar -1000000 le put
} for
/numKs [ numKs {1 add 2 idiv} forall ] def
0 1 msglen 1 sub { % Scan forward to set any "2nd byte 1st byte" Kanji matches to zero
/i exch def
numKs i get 0 gt {
numKs i 1 add 0 put
nextKs i 1 add nextKs i 1 add get 1 add put
} if
} for
 
/KbeforeB {numK exch ver get ge nextBs numK 2 mul i add get 0 eq and} bind def
/KbeforeA {numK exch ver get ge nextAs numK 2 mul i add get 0 eq and} bind def
/KbeforeN {numK exch ver get ge nextNs numK 2 mul i add get 0 eq and} bind def
16569,13 → 18691,45
/NbeforeA {numN exch ver get ge nextAs numN i add get 0 eq and} bind def
/NbeforeE {numN exch ver get ge numN i add msglen eq and} bind def
 
% Encode unterminated bitsream for each version group separately
/msgbits [-1 -1 -1 -1 -1 -1 -1] def
/v1to9 0 def /v10to26 1 def /v27to40 2 def /vM1 3 def /vM2 4 def /vM3 5 def /vM4 6 def
% Elements of the encoded message have differing lengths based on the
% resulting symbol size. The symbol sizes with different element lengths
% are batched into vergrps. To pick the smallest symbol that holds our
% content we encode the message according to each available vergrp, based
% on the format of symbol.
 
% Determine which groups we need to encode
version (unset) ne {
% A specific version of symbol is given so encode in just the corresponding vergrp
/verset <<
% Full
0 1 9 { 10 2 string cvrs v1to9 } for
10 1 26 { 10 2 string cvrs v10to26 } for
27 1 40 { 10 2 string cvrs v27to40 } for
 
% Micro
(M1) vM1 (M2) vM2 (M3) vM3 (M4) vM4
 
% rMQR
(R7x43) vR7x43 (R7x59) vR7x59 (R7x77) vR7x77 (R7x99) vR7x99 (R7x139) vR7x139
(R9x43) vR9x43 (R9x59) vR9x59 (R9x77) vR9x77 (R9x99) vR9x99 (R9x139) vR9x139
(R11x27) vR11x27 (R11x43) vR11x43 (R11x59) vR11x59 (R11x77) vR11x77 (R11x99) vR11x99 (R11x139) vR11x139
(R13x27) vR13x27 (R13x43) vR13x43 (R13x59) vR13x59 (R13x77) vR13x77 (R13x99) vR13x99 (R13x139) vR13x139
(R15x43) vR15x43 (R15x59) vR15x59 (R15x77) vR15x77 (R15x99) vR15x99 (R15x139) vR15x139
(R17x43) vR17x43 (R17x59) vR17x59 (R17x77) vR17x77 (R17x99) vR17x99 (R17x139) vR17x139
>> version get [ exch ] def
} {
% Just the format is specified so encode in each vergrp for the type of symbol
format (full) eq { /verset [v1to9 v10to26 v27to40] def } if
format (micro) eq { /verset [vM1 vM2 vM3 vM4] def } if
% rMQR symbols are accessed with an explicit version
} ifelse
 
% Encode unterminated bitstream for each compatible vergrp separately
/msgbits [ 39 {-1} repeat ] def
/e 10000 def
[v1to9 v10to26 v27to40 vM1 vM2 vM3 vM4] {
verset {
/ver exch def
 
% Derive optimal sequence
/mode -1 def /seq [] def /i 0 def {
i msglen ge {exit} if
16583,13 → 18737,25
/numB numBs i get def
/numA numAs i get def
/numN numNs i get def
/eci isECI i get def
ver vM1 eq numA 1 ge and {/seq -1 def exit} if
ver vM1 eq numB 1 ge and {/seq -1 def exit} if
ver vM1 eq numK 1 ge and {/seq -1 def exit} if
ver vM1 eq eci and {/seq -1 def exit} if
ver vM2 eq numB 1 ge and {/seq -1 def exit} if
ver vM2 eq numK 1 ge and {/seq -1 def exit} if
ver vM2 eq eci and {/seq -1 def exit} if
ver vM3 eq eci and {/seq -1 def exit} if
ver vM4 eq eci and {/seq -1 def exit} if
ver vR7x43 ge eci and {/seq -1 def exit} if
{ % common exit
mode -1 eq { % Set initial mode
eci {
E exit
} if
ver vR7x43 ge { % TODO rMQR is all numeric/alphanumeric/Kanji/binary only for now
numN msglen eq {N} { numAN msglen eq {A} { numK 2 mul msglen eq {K} {B} ifelse } ifelse } ifelse exit
} if
mode -1 eq { % Set initial mode (or mode after ECI)
[ 1 1 1 e e 1 1] KbeforeA {K exit} if
[ 1 1 1 e e 1 1] KbeforeN {K exit} if
[ 5 5 6 e e 2 3] KbeforeB {K exit} if
16596,6 → 18762,7
[ 1 1 1 e e 1 1] KbeforeE {K exit} if
numK 1 ge {B exit} if
[ 6 7 8 e e 3 4] AbeforeB {A exit} if
[ 1 1 1 e 1 1 1] AbeforeN {A exit} if
[ 1 1 1 e 1 1 1] AbeforeE {A exit} if
numA 1 ge {
ver vM2 ne {B} {A} ifelse exit
16660,6 → 18827,7
mode B eq {B msg i numB getinterval} if
mode A eq {A msg i numA getinterval} if
mode N eq {N msg i numN getinterval} if
mode E eq {E msg i 1 getinterval /mode -1 def} if
/dat exch def /sw exch def
/seq [ seq aload pop sw dat ] def
} ifelse
16671,18 → 18839,23
seq -1 eq {exit} if % Sequence not available
/bits 23648 string def
/j 0 def
fnc1first {(0101) addtobits} if
fnc1first {
ver vR7x43 lt { (0101) } { (101) } ifelse addtobits
} if
/abort false def
0 2 seq length 1 sub {
/i exch def
/mode seq i get def
mids ver get mode get addtobits
/cclen cclens ver get mode get def
/chars seq i 1 add get def
chars length 2 cclen exp cvi ge { % Too many characters for cc indicator
/abort true def exit
/charslen chars length mode K eq {2 idiv} if def
mode E ne {
/cclen cclens ver get mode get def
charslen 2 cclen exp cvi ge { % Too many characters for cc indicator
/abort true def exit
} if
charslen cclen tobin addtobits
} if
chars length mode K eq {2 idiv} if cclen tobin addtobits
chars encfuncs mode get load exec addtobits
} for
abort {exit} if
16694,80 → 18867,114
 
% Lookup the most appropriate symbol specification
/metrics [
% format vers vergrp size align modules error codewords error correction blocks
% L M Q H L1 L2 M1 M2 Q1 Q2 H1 H2
[ (micro) (M1) vM1 11 98 99 36 [ 2 99 99 99 ] [ 1 0 -1 -1 -1 -1 -1 -1 ] ]
[ (micro) (M2) vM2 13 98 99 80 [ 5 6 99 99 ] [ 1 0 1 0 -1 -1 -1 -1 ] ]
[ (micro) (M3) vM3 15 98 99 132 [ 6 8 99 99 ] [ 1 0 1 0 -1 -1 -1 -1 ] ]
[ (micro) (M4) vM4 17 98 99 192 [ 8 10 14 99 ] [ 1 0 1 0 1 0 -1 -1 ] ]
[ (full) (1) v1to9 21 98 99 208 [ 7 10 13 17 ] [ 1 0 1 0 1 0 1 0 ] ]
[ (full) (2) v1to9 25 18 99 359 [ 10 16 22 28 ] [ 1 0 1 0 1 0 1 0 ] ]
[ (full) (3) v1to9 29 22 99 567 [ 15 26 36 44 ] [ 1 0 1 0 2 0 2 0 ] ]
[ (full) (4) v1to9 33 26 99 807 [ 20 36 52 64 ] [ 1 0 2 0 2 0 4 0 ] ]
[ (full) (5) v1to9 37 30 99 1079 [ 26 48 72 88 ] [ 1 0 2 0 2 2 2 2 ] ]
[ (full) (6) v1to9 41 34 99 1383 [ 36 64 96 112 ] [ 2 0 4 0 4 0 4 0 ] ]
[ (full) (7) v1to9 45 22 38 1568 [ 40 72 108 130 ] [ 2 0 4 0 2 4 4 1 ] ]
[ (full) (8) v1to9 49 24 42 1936 [ 48 88 132 156 ] [ 2 0 2 2 4 2 4 2 ] ]
[ (full) (9) v1to9 53 26 46 2336 [ 60 110 160 192 ] [ 2 0 3 2 4 4 4 4 ] ]
[ (full) (10) v10to26 57 28 50 2768 [ 72 130 192 224 ] [ 2 2 4 1 6 2 6 2 ] ]
[ (full) (11) v10to26 61 30 54 3232 [ 80 150 224 264 ] [ 4 0 1 4 4 4 3 8 ] ]
[ (full) (12) v10to26 65 32 58 3728 [ 96 176 260 308 ] [ 2 2 6 2 4 6 7 4 ] ]
[ (full) (13) v10to26 69 34 62 4256 [ 104 198 288 352 ] [ 4 0 8 1 8 4 12 4 ] ]
[ (full) (14) v10to26 73 26 46 4651 [ 120 216 320 384 ] [ 3 1 4 5 11 5 11 5 ] ]
[ (full) (15) v10to26 77 26 48 5243 [ 132 240 360 432 ] [ 5 1 5 5 5 7 11 7 ] ]
[ (full) (16) v10to26 81 26 50 5867 [ 144 280 408 480 ] [ 5 1 7 3 15 2 3 13 ] ]
[ (full) (17) v10to26 85 30 54 6523 [ 168 308 448 532 ] [ 1 5 10 1 1 15 2 17 ] ]
[ (full) (18) v10to26 89 30 56 7211 [ 180 338 504 588 ] [ 5 1 9 4 17 1 2 19 ] ]
[ (full) (19) v10to26 93 30 58 7931 [ 196 364 546 650 ] [ 3 4 3 11 17 4 9 16 ] ]
[ (full) (20) v10to26 97 34 62 8683 [ 224 416 600 700 ] [ 3 5 3 13 15 5 15 10 ] ]
[ (full) (21) v10to26 101 28 50 9252 [ 224 442 644 750 ] [ 4 4 17 0 17 6 19 6 ] ]
[ (full) (22) v10to26 105 26 50 10068 [ 252 476 690 816 ] [ 2 7 17 0 7 16 34 0 ] ]
[ (full) (23) v10to26 109 30 54 10916 [ 270 504 750 900 ] [ 4 5 4 14 11 14 16 14 ] ]
[ (full) (24) v10to26 113 28 54 11796 [ 300 560 810 960 ] [ 6 4 6 14 11 16 30 2 ] ]
[ (full) (25) v10to26 117 32 58 12708 [ 312 588 870 1050 ] [ 8 4 8 13 7 22 22 13 ] ]
[ (full) (26) v10to26 121 30 58 13652 [ 336 644 952 1110 ] [ 10 2 19 4 28 6 33 4 ] ]
[ (full) (27) v27to40 125 34 62 14628 [ 360 700 1020 1200 ] [ 8 4 22 3 8 26 12 28 ] ]
[ (full) (28) v27to40 129 26 50 15371 [ 390 728 1050 1260 ] [ 3 10 3 23 4 31 11 31 ] ]
[ (full) (29) v27to40 133 30 54 16411 [ 420 784 1140 1350 ] [ 7 7 21 7 1 37 19 26 ] ]
[ (full) (30) v27to40 137 26 52 17483 [ 450 812 1200 1440 ] [ 5 10 19 10 15 25 23 25 ] ]
[ (full) (31) v27to40 141 30 56 18587 [ 480 868 1290 1530 ] [ 13 3 2 29 42 1 23 28 ] ]
[ (full) (32) v27to40 145 34 60 19723 [ 510 924 1350 1620 ] [ 17 0 10 23 10 35 19 35 ] ]
[ (full) (33) v27to40 149 30 58 20891 [ 540 980 1440 1710 ] [ 17 1 14 21 29 19 11 46 ] ]
[ (full) (34) v27to40 153 34 62 22091 [ 570 1036 1530 1800 ] [ 13 6 14 23 44 7 59 1 ] ]
[ (full) (35) v27to40 157 30 54 23008 [ 570 1064 1590 1890 ] [ 12 7 12 26 39 14 22 41 ] ]
[ (full) (36) v27to40 161 24 50 24272 [ 600 1120 1680 1980 ] [ 6 14 6 34 46 10 2 64 ] ]
[ (full) (37) v27to40 165 28 54 25568 [ 630 1204 1770 2100 ] [ 17 4 29 14 49 10 24 46 ] ]
[ (full) (38) v27to40 169 32 58 26896 [ 660 1260 1860 2220 ] [ 4 18 13 32 48 14 42 32 ] ]
[ (full) (39) v27to40 173 26 54 28256 [ 720 1316 1950 2310 ] [ 20 4 40 7 43 22 10 67 ] ]
[ (full) (40) v27to40 177 30 58 29648 [ 750 1372 2040 2430 ] [ 19 6 18 31 34 34 20 61 ] ]
% format vers vergrp rows cols align modules error codewords error correction blocks
% L M Q H L1 L2 M1 M2 Q1 Q2 H1 H2
[ (micro) (M1) vM1 11 11 98 99 36 [ 2 99 99 99 ] [ 1 0 -1 -1 -1 -1 -1 -1 ] ]
[ (micro) (M2) vM2 13 13 98 99 80 [ 5 6 99 99 ] [ 1 0 1 0 -1 -1 -1 -1 ] ]
[ (micro) (M3) vM3 15 15 98 99 132 [ 6 8 99 99 ] [ 1 0 1 0 -1 -1 -1 -1 ] ]
[ (micro) (M4) vM4 17 17 98 99 192 [ 8 10 14 99 ] [ 1 0 1 0 1 0 -1 -1 ] ]
[ (full) (1) v1to9 21 21 98 99 208 [ 7 10 13 17 ] [ 1 0 1 0 1 0 1 0 ] ]
[ (full) (2) v1to9 25 25 18 99 359 [ 10 16 22 28 ] [ 1 0 1 0 1 0 1 0 ] ]
[ (full) (3) v1to9 29 29 22 99 567 [ 15 26 36 44 ] [ 1 0 1 0 2 0 2 0 ] ]
[ (full) (4) v1to9 33 33 26 99 807 [ 20 36 52 64 ] [ 1 0 2 0 2 0 4 0 ] ]
[ (full) (5) v1to9 37 37 30 99 1079 [ 26 48 72 88 ] [ 1 0 2 0 2 2 2 2 ] ]
[ (full) (6) v1to9 41 41 34 99 1383 [ 36 64 96 112 ] [ 2 0 4 0 4 0 4 0 ] ]
[ (full) (7) v1to9 45 45 22 38 1568 [ 40 72 108 130 ] [ 2 0 4 0 2 4 4 1 ] ]
[ (full) (8) v1to9 49 49 24 42 1936 [ 48 88 132 156 ] [ 2 0 2 2 4 2 4 2 ] ]
[ (full) (9) v1to9 53 53 26 46 2336 [ 60 110 160 192 ] [ 2 0 3 2 4 4 4 4 ] ]
[ (full) (10) v10to26 57 57 28 50 2768 [ 72 130 192 224 ] [ 2 2 4 1 6 2 6 2 ] ]
[ (full) (11) v10to26 61 61 30 54 3232 [ 80 150 224 264 ] [ 4 0 1 4 4 4 3 8 ] ]
[ (full) (12) v10to26 65 65 32 58 3728 [ 96 176 260 308 ] [ 2 2 6 2 4 6 7 4 ] ]
[ (full) (13) v10to26 69 69 34 62 4256 [ 104 198 288 352 ] [ 4 0 8 1 8 4 12 4 ] ]
[ (full) (14) v10to26 73 73 26 46 4651 [ 120 216 320 384 ] [ 3 1 4 5 11 5 11 5 ] ]
[ (full) (15) v10to26 77 77 26 48 5243 [ 132 240 360 432 ] [ 5 1 5 5 5 7 11 7 ] ]
[ (full) (16) v10to26 81 81 26 50 5867 [ 144 280 408 480 ] [ 5 1 7 3 15 2 3 13 ] ]
[ (full) (17) v10to26 85 85 30 54 6523 [ 168 308 448 532 ] [ 1 5 10 1 1 15 2 17 ] ]
[ (full) (18) v10to26 89 89 30 56 7211 [ 180 338 504 588 ] [ 5 1 9 4 17 1 2 19 ] ]
[ (full) (19) v10to26 93 93 30 58 7931 [ 196 364 546 650 ] [ 3 4 3 11 17 4 9 16 ] ]
[ (full) (20) v10to26 97 97 34 62 8683 [ 224 416 600 700 ] [ 3 5 3 13 15 5 15 10 ] ]
[ (full) (21) v10to26 101 101 28 50 9252 [ 224 442 644 750 ] [ 4 4 17 0 17 6 19 6 ] ]
[ (full) (22) v10to26 105 105 26 50 10068 [ 252 476 690 816 ] [ 2 7 17 0 7 16 34 0 ] ]
[ (full) (23) v10to26 109 109 30 54 10916 [ 270 504 750 900 ] [ 4 5 4 14 11 14 16 14 ] ]
[ (full) (24) v10to26 113 113 28 54 11796 [ 300 560 810 960 ] [ 6 4 6 14 11 16 30 2 ] ]
[ (full) (25) v10to26 117 117 32 58 12708 [ 312 588 870 1050 ] [ 8 4 8 13 7 22 22 13 ] ]
[ (full) (26) v10to26 121 121 30 58 13652 [ 336 644 952 1110 ] [ 10 2 19 4 28 6 33 4 ] ]
[ (full) (27) v27to40 125 125 34 62 14628 [ 360 700 1020 1200 ] [ 8 4 22 3 8 26 12 28 ] ]
[ (full) (28) v27to40 129 129 26 50 15371 [ 390 728 1050 1260 ] [ 3 10 3 23 4 31 11 31 ] ]
[ (full) (29) v27to40 133 133 30 54 16411 [ 420 784 1140 1350 ] [ 7 7 21 7 1 37 19 26 ] ]
[ (full) (30) v27to40 137 137 26 52 17483 [ 450 812 1200 1440 ] [ 5 10 19 10 15 25 23 25 ] ]
[ (full) (31) v27to40 141 141 30 56 18587 [ 480 868 1290 1530 ] [ 13 3 2 29 42 1 23 28 ] ]
[ (full) (32) v27to40 145 145 34 60 19723 [ 510 924 1350 1620 ] [ 17 0 10 23 10 35 19 35 ] ]
[ (full) (33) v27to40 149 149 30 58 20891 [ 540 980 1440 1710 ] [ 17 1 14 21 29 19 11 46 ] ]
[ (full) (34) v27to40 153 153 34 62 22091 [ 570 1036 1530 1800 ] [ 13 6 14 23 44 7 59 1 ] ]
[ (full) (35) v27to40 157 157 30 54 23008 [ 570 1064 1590 1890 ] [ 12 7 12 26 39 14 22 41 ] ]
[ (full) (36) v27to40 161 161 24 50 24272 [ 600 1120 1680 1980 ] [ 6 14 6 34 46 10 2 64 ] ]
[ (full) (37) v27to40 165 165 28 54 25568 [ 630 1204 1770 2100 ] [ 17 4 29 14 49 10 24 46 ] ]
[ (full) (38) v27to40 169 169 32 58 26896 [ 660 1260 1860 2220 ] [ 4 18 13 32 48 14 42 32 ] ]
[ (full) (39) v27to40 173 173 26 54 28256 [ 720 1316 1950 2310 ] [ 20 4 40 7 43 22 10 67 ] ]
[ (full) (40) v27to40 177 177 30 58 29648 [ 750 1372 2040 2430 ] [ 19 6 18 31 34 34 20 61 ] ]
[ (rmqr) (R7x43) vR7x43 7 43 22 99 104 [ 99 7 99 10 ] [ -1 -1 1 0 -1 -1 1 0 ] ]
[ (rmqr) (R7x59) vR7x59 7 59 20 40 171 [ 99 9 99 14 ] [ -1 -1 1 0 -1 -1 1 0 ] ]
[ (rmqr) (R7x77) vR7x77 7 77 26 52 261 [ 99 12 99 22 ] [ -1 -1 1 0 -1 -1 1 0 ] ]
[ (rmqr) (R7x99) vR7x99 7 99 24 50 358 [ 99 16 99 30 ] [ -1 -1 1 0 -1 -1 1 0 ] ]
[ (rmqr) (R7x139) vR7x139 7 139 28 56 545 [ 99 24 99 44 ] [ -1 -1 1 0 -1 -1 2 0 ] ]
[ (rmqr) (R9x43) vR9x43 9 43 22 99 170 [ 99 9 99 14 ] [ -1 -1 1 0 -1 -1 1 0 ] ]
[ (rmqr) (R9x59) vR9x59 9 59 20 40 267 [ 99 12 99 22 ] [ -1 -1 1 0 -1 -1 1 0 ] ]
[ (rmqr) (R9x77) vR9x77 9 77 26 52 393 [ 99 18 99 32 ] [ -1 -1 1 0 -1 -1 1 1 ] ]
[ (rmqr) (R9x99) vR9x99 9 99 24 50 532 [ 99 24 99 44 ] [ -1 -1 1 0 -1 -1 2 0 ] ]
[ (rmqr) (R9x139) vR9x139 9 139 28 56 797 [ 99 36 99 66 ] [ -1 -1 1 1 -1 -1 3 0 ] ]
[ (rmqr) (R11x27) vR11x27 11 27 98 99 122 [ 99 8 99 10 ] [ -1 -1 1 0 -1 -1 1 0 ] ]
[ (rmqr) (R11x43) vR11x43 11 43 22 99 249 [ 99 12 99 20 ] [ -1 -1 1 0 -1 -1 1 0 ] ]
[ (rmqr) (R11x59) vR11x59 11 59 20 40 376 [ 99 16 99 32 ] [ -1 -1 1 0 -1 -1 1 1 ] ]
[ (rmqr) (R11x77) vR11x77 11 77 26 52 538 [ 99 24 99 44 ] [ -1 -1 1 0 -1 -1 1 1 ] ]
[ (rmqr) (R11x99) vR11x99 11 99 24 50 719 [ 99 32 99 60 ] [ -1 -1 1 1 -1 -1 1 1 ] ]
[ (rmqr) (R11x139) vR11x139 11 139 28 56 1062 [ 99 48 99 90 ] [ -1 -1 2 0 -1 -1 3 0 ] ]
[ (rmqr) (R13x27) vR13x27 13 27 98 99 172 [ 99 9 99 14 ] [ -1 -1 1 0 -1 -1 1 0 ] ]
[ (rmqr) (R13x43) vR13x43 13 43 22 99 329 [ 99 14 99 28 ] [ -1 -1 1 0 -1 -1 1 0 ] ]
[ (rmqr) (R13x59) vR13x59 13 59 20 40 486 [ 99 22 99 40 ] [ -1 -1 1 0 -1 -1 2 0 ] ]
[ (rmqr) (R13x77) vR13x77 13 77 26 52 684 [ 99 32 99 56 ] [ -1 -1 1 1 -1 -1 1 1 ] ]
[ (rmqr) (R13x99) vR13x99 13 99 24 50 907 [ 99 40 99 78 ] [ -1 -1 1 1 -1 -1 1 2 ] ]
[ (rmqr) (R13x139) vR13x139 13 139 28 56 1328 [ 99 60 99 112 ] [ -1 -1 2 1 -1 -1 2 2 ] ]
[ (rmqr) (R15x43) vR15x43 15 43 22 99 409 [ 99 18 99 36 ] [ -1 -1 1 0 -1 -1 1 1 ] ]
[ (rmqr) (R15x59) vR15x59 15 59 20 40 596 [ 99 26 99 48 ] [ -1 -1 1 0 -1 -1 2 0 ] ]
[ (rmqr) (R15x77) vR15x77 15 77 26 52 830 [ 99 36 99 72 ] [ -1 -1 1 1 -1 -1 2 1 ] ]
[ (rmqr) (R15x99) vR15x99 15 99 24 50 1095 [ 99 48 99 88 ] [ -1 -1 2 0 -1 -1 4 0 ] ]
[ (rmqr) (R15x139) vR15x139 15 139 28 56 1594 [ 99 72 99 130 ] [ -1 -1 2 1 -1 -1 1 4 ] ]
[ (rmqr) (R17x43) vR17x43 17 43 22 99 489 [ 99 22 99 40 ] [ -1 -1 1 0 -1 -1 1 1 ] ]
[ (rmqr) (R17x59) vR17x59 17 59 20 40 706 [ 99 32 99 60 ] [ -1 -1 2 0 -1 -1 2 0 ] ]
[ (rmqr) (R17x77) vR17x77 17 77 26 52 976 [ 99 44 99 84 ] [ -1 -1 2 0 -1 -1 1 2 ] ]
[ (rmqr) (R17x99) vR17x99 17 99 24 50 1283 [ 99 60 99 104 ] [ -1 -1 2 1 -1 -1 4 0 ] ]
[ (rmqr) (R17x139) vR17x139 17 139 28 56 1860 [ 99 80 99 156 ] [ -1 -1 4 0 -1 -1 2 4 ] ]
] def
/eclval (LMQH) eclevel search pop length exch pop exch pop def
0 1 43 {
0 1 metrics length 1 sub {
/i exch def
/m metrics i get def
/frmt m 0 get def % Format of the symbol
/vers m 1 get def % Version of symbol
/vergrp m 2 get def % Version group
/size m 3 get def % Length of side
/asp2 m 4 get def % Position of second alignment symbol
/asp3 m 5 get def % Position of third alignment symbol
/nmod m 6 get def % Number of modules
/verind i 44 sub def % Version indicator for rMQR format info
/rows m 3 get def % Length of side
/cols m 4 get def % Length of side
/asp2 m 5 get def % Position of second alignment symbol
/asp3 m 6 get def % Position of third alignment symbol
/nmod m 7 get def % Number of modules
/ncws nmod 8 idiv def % Total number of codewords
/rbit nmod 8 mod def % Number of remainder bits
/lc4b false def % Last data codeword is 4 bits long
size 11 eq size 15 eq or { % Adjustments for M1 and M3 symbols
vers (M1) eq vers (M3) eq or { % Adjustments for M1 and M3 symbols
/ncws ncws 1 add def
/rbit 0 def
/lc4b true def
} if
/ecws m 7 get eclval get def % Number of error correction codewords
/ecws m 8 get eclval get def % Number of error correction codewords
/dcws ncws ecws sub def % Number of data codewords
/dmod dcws 8 mul lc4b {4} {0} ifelse sub def % Number of data modules
/ecb1 m 8 get eclval 2 mul get def % First error correction blocks
/ecb2 m 8 get eclval 2 mul 1 add get def % Second error correction blocks
/ecb1 m 9 get eclval 2 mul get def % First error correction blocks
/ecb2 m 9 get eclval 2 mul 1 add get def % Second error correction blocks
/okay true def
format (any) ne format frmt ne and {/okay false def} if % The format must match that supplied
frmt (micro) eq fnc1first and {/okay false def} if
format frmt ne {/okay false def} if % The format must match that supplied
frmt (micro) eq fnc1first and {/okay false def} if % FNC1 mode is only available in full and rmqr
version (unset) ne version vers ne and {/okay false def} if % The version must match that supplied
ecb1 -1 eq ecb2 -1 eq or {/okay false def} if % Error correction level must be valid
/verbits msgbits vergrp get def
16804,12 → 19011,12
/padstrs [ (11101100) (00010001) ] def
/padnum 0 def
msgbits length 8 div ceiling 8 mul cvi 8 dmod lc4b {5} {1} ifelse sub {
pad exch padstrs padnum get putinterval
pad exch padstrs padnum get putinterval
/padnum padnum 1 add 2 mod def
} for
 
% Evaluate the padded message into codewords
/cws dcws array def
/cws dcws array def
0 1 cws length 1 sub {
/c exch def
/bpcw 8 def
16819,13 → 19026,15
0 1 bpcw 1 sub {
/i exch def
/cw cw 2 bpcw i sub 1 sub exp cvi cwb i get 48 sub mul add def
} for
} for
cws c cw put
} for
} for
 
% Short final data byte in M1 and M3 symbols has high-order value
lc4b {cws cws length 1 sub 2 copy get 4 bitshift put} if
 
options /debugcws known { /bwipp.debugcws cws //raiseerror exec } if
 
% Calculate the log and anti-log tables
/rsalog [ 1 255 { dup 2 mul dup 256 ge {285 xor} if } repeat ] def
/rslog 256 array def
16833,7 → 19042,7
 
% Function to calculate the product in the field
/rsprod {
2 copy 0 ne exch 0 ne and {
2 copy 0 ne exch 0 ne and {
rslog exch get exch rslog exch get add 255 mod rsalog exch get
} {
pop pop 0
16843,12 → 19052,12
% Generate the coefficients for the Reed-Solomon algorithm
/coeffs [ 1 ecpb {0} repeat ] def
0 1 ecpb 1 sub {
/i exch def
/i exch def
coeffs i 1 add coeffs i get put
i -1 1 {
/j exch def
coeffs j coeffs j 1 sub get coeffs j get rsalog i get rsprod xor put
} for
} for
coeffs 0 coeffs 0 get rsalog i get rsprod put
} for
/coeffs coeffs 0 coeffs length 1 sub getinterval def
16882,7 → 19091,7
dcwsb ecb1 i add cws ecb1 dcpb mul i dcpb 1 add mul add dcpb 1 add getinterval put
ecwsb ecb1 i add dcwsb ecb1 i add get rscodes put
} for
 
% Reassemble the codewords
/cws ncws array def
/cw 0 def
16904,7 → 19113,7
/cw cw 1 add def
} for
} for
 
% Extend codewords by one if there are remainder bits
rbit 0 gt {
/pad cws length 1 add array def
16912,10 → 19121,10
pad pad length 1 sub 0 put
/cws pad def
} if
 
% Fixups for the short final data byte in M1 and M3 symbols
lc4b {
cws dcws 1 sub 2 copy get -4 bitshift put
cws dcws 1 sub 2 copy get -4 bitshift put
dcws 1 sub 1 ncws 2 sub {
/i exch def
cws i cws i get 15 and 4 bitshift put
16924,10 → 19133,47
cws ncws 1 sub cws ncws 1 sub get 15 and 4 bitshift put
} if
 
options /debugecc known { /bwipp.debugecc cws //raiseerror exec } if
 
% Create the bitmap
/pixs [ size size mul {-1} repeat ] def
/qmv {size mul add} bind def
/pixs [ rows cols mul {-1} repeat ] def
/qmv {cols mul add} bind def
 
% Timing patterns
format (full) eq {
8 1 cols 9 sub {
/i exch def
pixs i 6 qmv i 1 add 2 mod put
pixs 6 i qmv i 1 add 2 mod put
} for
} if
format (micro) eq {
8 1 cols 1 sub {
/i exch def
pixs i 0 qmv i 1 add 2 mod put
pixs 0 i qmv i 1 add 2 mod put
} for
} if
format (rmqr) eq {
3 1 cols 4 sub { % Along top and bottom
/i exch def
pixs i 0 qmv i 1 add 2 mod put
pixs i rows 1 sub qmv i 1 add 2 mod put
} for
3 1 rows 4 sub { % Along left and right
/i exch def
pixs 0 i qmv i 1 add 2 mod put
pixs cols 1 sub i qmv i 1 add 2 mod put
} for
asp2 1 sub asp3 asp2 sub cols 13 sub { % Down interior
/i exch def
3 1 rows 4 sub {
/j exch def
pixs i j qmv j 1 add 2 mod put
} for
} for
} if
 
% Finder patterns
/fpat [
[ 1 1 1 1 1 1 1 0 ]
16939,27 → 19185,58
[ 1 1 1 1 1 1 1 0 ]
[ 0 0 0 0 0 0 0 0 ]
] def
0 1 fpat length 1 sub {
/fsubpat [
[ 1 1 1 1 1 9 9 9 ]
[ 1 0 0 0 1 9 9 9 ]
[ 1 0 1 0 1 9 9 9 ]
[ 1 0 0 0 1 9 9 9 ]
[ 1 1 1 1 1 9 9 9 ]
[ 9 9 9 9 9 9 9 9 ]
[ 9 9 9 9 9 9 9 9 ]
[ 9 9 9 9 9 9 9 9 ]
] def
/fcorpat [
[ 1 1 1 9 9 9 9 9 ]
[ 1 0 9 9 9 9 9 9 ]
[ 1 9 9 9 9 9 9 9 ]
[ 9 9 9 9 9 9 9 9 ]
[ 9 9 9 9 9 9 9 9 ]
[ 9 9 9 9 9 9 9 9 ]
[ 9 9 9 9 9 9 9 9 ]
[ 9 9 9 9 9 9 9 9 ]
] def
/fnullpat [
[ 9 9 9 9 9 9 9 9 ]
[ 9 9 9 9 9 9 9 9 ]
[ 9 9 9 9 9 9 9 9 ]
[ 9 9 9 9 9 9 9 9 ]
[ 9 9 9 9 9 9 9 9 ]
[ 9 9 9 9 9 9 9 9 ]
[ 9 9 9 9 9 9 9 9 ]
[ 9 9 9 9 9 9 9 9 ]
] def
/fpats <<
% TL TR BL BR
(full) [ fpat fpat fpat fnullpat ]
(micro) [ fpat fnullpat fnullpat fnullpat ]
(rmqr) [ fpat fcorpat fcorpat fsubpat ]
>> format get def
0 1 7 {
/y exch def
0 1 fpat 0 get length 1 sub {
0 1 7 {
/x exch def
/fpb fpat y get x get def
pixs x y qmv fpb put
format (full) eq {
pixs size x sub 1 sub y qmv fpb put
pixs x size y sub 1 sub qmv fpb put
} if
/fpb0 fpats 0 get y get x get def
/fpb1 fpats 1 get y get x get def
/fpb2 fpats 2 get y get x get def
/fpb3 fpats 3 get y get x get def
fpb0 9 ne y rows lt and {pixs x y qmv fpb0 put} if
fpb1 9 ne {pixs cols x sub 1 sub y qmv fpb1 put} if
fpb2 9 ne {pixs x rows y sub 1 sub qmv fpb2 put} if
fpb3 9 ne {pixs cols x sub 1 sub rows y sub 1 sub qmv fpb3 put} if
} for
} for
 
% Alignment patterns
/algnpat [
[ 1 1 1 1 1 ]
[ 1 0 0 0 1 ]
[ 1 0 1 0 1 ]
[ 1 0 0 0 1 ]
[ 1 1 1 1 1 ]
] def
/putalgnpat {
/py exch def
/px exch def
16967,70 → 19244,88
/pb exch def
0 1 4 {
/pa exch def
pixs px pa add py pb add qmv algnpat pb get pa get put
/algnb algnpat pb get pa get def
algnb 9 ne {
pixs px pa add py pb add qmv algnb put
} if
} for
} for
} bind def
asp2 2 sub asp3 asp2 sub size 13 sub {
/i exch def
i 4 putalgnpat
4 i putalgnpat
} for
asp2 2 sub asp3 asp2 sub size 9 sub {
/x exch def
asp2 2 sub asp3 asp2 sub size 9 sub {
/y exch def
x y putalgnpat
} for
} for
% Timing patterns
format (full) eq {
8 1 size 9 sub {
/algnpat [
[ 1 1 1 1 1 ]
[ 1 0 0 0 1 ]
[ 1 0 1 0 1 ]
[ 1 0 0 0 1 ]
[ 1 1 1 1 1 ]
] def
asp2 2 sub asp3 asp2 sub cols 13 sub {
/i exch def
pixs i 6 qmv i 1 add 2 mod put
pixs 6 i qmv i 1 add 2 mod put
i 4 putalgnpat
4 i putalgnpat
} for
} {
8 1 size 1 sub {
asp2 2 sub asp3 asp2 sub cols 9 sub {
/x exch def
asp2 2 sub asp3 asp2 sub rows 9 sub {
/y exch def
x y putalgnpat
} for
} for
} if
format (rmqr) eq {
/algnpat [
[ 1 1 1 9 9 ]
[ 1 0 1 9 9 ]
[ 1 1 1 9 9 ]
[ 9 9 9 9 9 ]
[ 9 9 9 9 9 ]
] def
asp2 2 sub asp3 asp2 sub cols 13 sub {
/i exch def
pixs i 0 qmv i 1 add 2 mod put
pixs 0 i qmv i 1 add 2 mod put
i 0 putalgnpat
i rows 3 sub putalgnpat
} for
} ifelse
} if
 
% Format information modules
format (full) eq {
/formatmap [
[ [ 0 8 ] [ 8 size 1 sub ] ] [ [ 1 8 ] [ 8 size 2 sub ] ] [ [ 2 8 ] [ 8 size 3 sub ] ]
[ [ 3 8 ] [ 8 size 4 sub ] ] [ [ 4 8 ] [ 8 size 5 sub ] ] [ [ 5 8 ] [ 8 size 6 sub ] ]
[ [ 7 8 ] [ 8 size 7 sub ] ] [ [ 8 8 ] [ size 8 sub 8 ] ] [ [ 8 7 ] [ size 7 sub 8 ] ]
[ [ 8 5 ] [ size 6 sub 8 ] ] [ [ 8 4 ] [ size 5 sub 8 ] ] [ [ 8 3 ] [ size 4 sub 8 ] ]
[ [ 8 2 ] [ size 3 sub 8 ] ] [ [ 8 1 ] [ size 2 sub 8 ] ] [ [ 8 0 ] [ size 1 sub 8 ] ]
] def
} {
/formatmap [
/formatmap <<
(full) [
[ [ 0 8 ] [ 8 cols 1 sub ] ] [ [ 1 8 ] [ 8 cols 2 sub ] ] [ [ 2 8 ] [ 8 cols 3 sub ] ]
[ [ 3 8 ] [ 8 cols 4 sub ] ] [ [ 4 8 ] [ 8 cols 5 sub ] ] [ [ 5 8 ] [ 8 cols 6 sub ] ]
[ [ 7 8 ] [ 8 cols 7 sub ] ] [ [ 8 8 ] [ cols 8 sub 8 ] ] [ [ 8 7 ] [ cols 7 sub 8 ] ]
[ [ 8 5 ] [ cols 6 sub 8 ] ] [ [ 8 4 ] [ cols 5 sub 8 ] ] [ [ 8 3 ] [ cols 4 sub 8 ] ]
[ [ 8 2 ] [ cols 3 sub 8 ] ] [ [ 8 1 ] [ cols 2 sub 8 ] ] [ [ 8 0 ] [ cols 1 sub 8 ] ]
]
(micro) [
[ [ 1 8 ] ] [ [ 2 8 ] ] [ [ 3 8 ] ] [ [ 4 8 ] ] [ [ 5 8 ] ]
[ [ 6 8 ] ] [ [ 7 8 ] ] [ [ 8 8 ] ] [ [ 8 7 ] ] [ [ 8 6 ] ]
[ [ 8 5 ] ] [ [ 8 4 ] ] [ [ 8 3 ] ] [ [ 8 2 ] ] [ [ 8 1 ] ]
] def
} ifelse
]
(rmqr) [
[ [ 11 3 ] [ cols 3 sub rows 6 sub ] ] [ [ 11 2 ] [ cols 4 sub rows 6 sub ] ] [ [ 11 1 ] [ cols 5 sub rows 6 sub ] ]
[ [ 10 5 ] [ cols 6 sub rows 2 sub ] ] [ [ 10 4 ] [ cols 6 sub rows 3 sub ] ] [ [ 10 3 ] [ cols 6 sub rows 4 sub ] ]
[ [ 10 2 ] [ cols 6 sub rows 5 sub ] ] [ [ 10 1 ] [ cols 6 sub rows 6 sub ] ] [ [ 9 5 ] [ cols 7 sub rows 2 sub ] ]
[ [ 9 4 ] [ cols 7 sub rows 3 sub ] ] [ [ 9 3 ] [ cols 7 sub rows 4 sub ] ] [ [ 9 2 ] [ cols 7 sub rows 5 sub ] ]
[ [ 9 1 ] [ cols 7 sub rows 6 sub ] ] [ [ 8 5 ] [ cols 8 sub rows 2 sub ] ] [ [ 8 4 ] [ cols 8 sub rows 3 sub ] ]
[ [ 8 3 ] [ cols 8 sub rows 4 sub ] ] [ [ 8 2 ] [ cols 8 sub rows 5 sub ] ] [ [ 8 1 ] [ cols 8 sub rows 6 sub ] ]
]
>> format get def
formatmap {
{ {} forall qmv pixs exch 0 put } forall
{ {} forall qmv pixs exch 1 put } forall
} forall
 
% Version information modules
size 45 ge {
format (full) eq cols 45 ge and {
/versionmap [
[ [ size 9 sub 5 ] [ 5 size 9 sub ] ] [ [ size 10 sub 5 ] [ 5 size 10 sub ] ]
[ [ size 11 sub 5 ] [ 5 size 11 sub ] ] [ [ size 9 sub 4 ] [ 4 size 9 sub ] ]
[ [ size 10 sub 4 ] [ 4 size 10 sub ] ] [ [ size 11 sub 4 ] [ 4 size 11 sub ] ]
[ [ size 9 sub 3 ] [ 3 size 9 sub ] ] [ [ size 10 sub 3 ] [ 3 size 10 sub ] ]
[ [ size 11 sub 3 ] [ 3 size 11 sub ] ] [ [ size 9 sub 2 ] [ 2 size 9 sub ] ]
[ [ size 10 sub 2 ] [ 2 size 10 sub ] ] [ [ size 11 sub 2 ] [ 2 size 11 sub ] ]
[ [ size 9 sub 1 ] [ 1 size 9 sub ] ] [ [ size 10 sub 1 ] [ 1 size 10 sub ] ]
[ [ size 11 sub 1 ] [ 1 size 11 sub ] ] [ [ size 9 sub 0 ] [ 0 size 9 sub ] ]
[ [ size 10 sub 0 ] [ 0 size 10 sub ] ] [ [ size 11 sub 0 ] [ 0 size 11 sub ] ]
[ [ cols 9 sub 5 ] [ 5 cols 9 sub ] ] [ [ cols 10 sub 5 ] [ 5 cols 10 sub ] ]
[ [ cols 11 sub 5 ] [ 5 cols 11 sub ] ] [ [ cols 9 sub 4 ] [ 4 cols 9 sub ] ]
[ [ cols 10 sub 4 ] [ 4 cols 10 sub ] ] [ [ cols 11 sub 4 ] [ 4 cols 11 sub ] ]
[ [ cols 9 sub 3 ] [ 3 cols 9 sub ] ] [ [ cols 10 sub 3 ] [ 3 cols 10 sub ] ]
[ [ cols 11 sub 3 ] [ 3 cols 11 sub ] ] [ [ cols 9 sub 2 ] [ 2 cols 9 sub ] ]
[ [ cols 10 sub 2 ] [ 2 cols 10 sub ] ] [ [ cols 11 sub 2 ] [ 2 cols 11 sub ] ]
[ [ cols 9 sub 1 ] [ 1 cols 9 sub ] ] [ [ cols 10 sub 1 ] [ 1 cols 10 sub ] ]
[ [ cols 11 sub 1 ] [ 1 cols 11 sub ] ] [ [ cols 9 sub 0 ] [ 0 cols 9 sub ] ]
[ [ cols 10 sub 0 ] [ 0 cols 10 sub ] ] [ [ cols 11 sub 0 ] [ 0 cols 11 sub ] ]
] def
} {
/versionmap [] def
17041,29 → 19336,31
 
% Reserve the solitary dark module in full symbols
format (full) eq {
pixs 8 size 8 sub qmv 0 put
pixs 8 rows 8 sub qmv 0 put
} if
 
% Calculate the mask patterns
format (full) eq {
/maskfuncs [
{add 2 mod} bind
{exch pop 2 mod} bind
{pop 3 mod} bind
{add 3 mod} bind
{2 idiv exch 3 idiv add 2 mod} bind
{mul dup 2 mod exch 3 mod add} bind
{mul dup 2 mod exch 3 mod add 2 mod} bind
{2 copy mul 3 mod 3 1 roll add 2 mod add 2 mod} bind
] def
} {
/maskfuncs [
{exch pop 2 mod} bind
{2 idiv exch 3 idiv add 2 mod} bind
{mul dup 2 mod exch 3 mod add 2 mod} bind
{2 copy mul 3 mod 3 1 roll add 2 mod add 2 mod} bind
] def
} ifelse
/maskfuncs <<
(full) [
{add 2 mod}
{exch pop 2 mod}
{pop 3 mod}
{add 3 mod}
{2 idiv exch 3 idiv add 2 mod}
{mul dup 2 mod exch 3 mod add}
{mul dup 2 mod exch 3 mod add 2 mod}
{2 copy mul 3 mod 3 1 roll add 2 mod add 2 mod}
]
(micro) [
{exch pop 2 mod}
{2 idiv exch 3 idiv add 2 mod}
{mul dup 2 mod exch 3 mod add 2 mod}
{2 copy mul 3 mod 3 1 roll add 2 mod add 2 mod}
]
(rmqr) [
{2 idiv exch 3 idiv add 2 mod}
]
>> format get def
mask -1 ne { % User specifies a mask
/maskfuncs [maskfuncs mask 1 sub get] def
/bestmaskval mask 1 sub def
17071,12 → 19368,12
/masks maskfuncs length array def
0 1 masks length 1 sub {
/m exch def
/mask size size mul array def
0 1 size 1 sub {
/mask rows cols mul array def
0 1 rows 1 sub {
/j exch def
0 1 size 1 sub {
0 1 cols 1 sub {
/i exch def
i j maskfuncs m get exec 0 eq
i j maskfuncs m get exec 0 eq
pixs i j qmv get -1 eq and {1} {0} ifelse
mask i j qmv 3 -1 roll put
} for
17083,10 → 19380,10
} for
masks m mask put
} for
 
% Walk the symbol placing the bitstream
/posx size 1 sub def
/posy size 1 sub def
/posx cols format (rmqr) ne {1} {2} ifelse sub def
/posy rows 1 sub def
/dir -1 def % -1 is upwards, 1 is downwards
/col 1 def % 0 is left bit, 1 is right bit
/num 0 def
17102,9 → 19399,9
/posx posx 1 sub def
} {
/col 1 def
/posx posx 1 add def
/posx posx 1 add def
/posy posy dir add def
posy 0 lt posy size ge or { % Turn around at top and bottom
posy 0 lt posy rows ge or { % Turn around at top and bottom
/dir dir -1 mul def
/posy posy dir add def
/posx posx 2 sub def
17138,22 → 19435,22
} for
scr1 scr3
} bind def
 
% Evaluation algorithm for full symbols
/evalfull {
/sym exch def
 
/n1 0 def /n2 0 def /n3 0 def
/rle size 1 add array def
/lastpairs size array def
/thispairs size array def
/sizeadd1 size 1 add def
0 1 size 1 sub {
/rle cols 1 add array def
/lastpairs cols array def
/thispairs cols array def
/colsadd1 cols 1 add def
0 1 cols 1 sub {
/i exch def
 
% Runlength encode (light, dark, light, ...) and evaluate each column
mark 0 0
i size dup dup mul 1 sub {
i cols dup dup mul 1 sub {
sym exch get exch 1 index eq {exch 1 add exch} {1 exch} ifelse
} for
pop
17162,11 → 19459,11
pop
 
% Runlength encode (light, dark, light, ...) and evaluate each row
/symrow sym i size mul size getinterval def
mark 0 0
symrow {
/symrow sym i cols mul cols getinterval def
mark 0 0
symrow {
exch 1 index eq {exch 1 add exch} {1 exch} ifelse
} forall
} forall
pop
rle 0 counttomark 2 sub getinterval astore
evalfulln1n3 n3 add /n3 exch def n1 add /n1 exch def
17181,28 → 19478,28
i 0 gt {
mark
lastpairs aload pop thispairs aload pop
n2 size { exch sizeadd1 index add 3 and 0 eq {3 add} if } repeat
n2 cols { exch colsadd1 index add 3 and 0 eq {3 add} if } repeat
/n2 exch def
cleartomark
} if
 
} for
% Score dark/light imbalance
 
% Score dark/light imbalance
/dark 0 sym {add} forall def
/n4 dark 100 mul size dup mul div 50 sub abs 5 div cvi 10 mul def
/n4 dark 100 mul cols dup mul div 50 sub abs 5 div cvi 10 mul def
 
n1 n2 add n3 add n4 add
} bind def
 
% Evaluation algorithm for micro symbols
/evalmicro {
/sym exch def
/dkrhs 0 def /dkbot 0 def
1 1 size 1 sub {
1 1 cols 1 sub {
/i exch def
/dkrhs dkrhs sym size 1 sub i qmv get add def
/dkbot dkbot sym i size 1 sub qmv get add def
/dkrhs dkrhs sym cols 1 sub i qmv get add def
/dkbot dkbot sym i cols 1 sub qmv get add def
} for
dkrhs dkbot le {
dkrhs 16 mul dkbot add neg
17210,23 → 19507,23
dkbot 16 mul dkrhs add neg
} ifelse
} bind def
 
% Evaluate the masked symbols to find the most suitable
/bestscore 999999999 def
0 1 masks length 1 sub {
/m exch def
/masksym size size mul array def
0 1 size size mul 1 sub {
/masksym rows cols mul array def
0 1 rows cols mul 1 sub {
/i exch def
masksym i pixs i get masks m get i get xor put
} for
masks length 1 ne {
masks length 1 ne { % Not rMQR nor user-specified mask
format (full) eq {
masksym evalfull /score exch def
} {
masksym evalmicro /score exch def
} ifelse
score bestscore lt {
score bestscore lt {
/bestsym masksym def
/bestmaskval m def
/bestscore score def
17239,20 → 19536,27
 
% Set the solitary dark module in full symbols
format (full) eq {
pixs 8 size 8 sub qmv 1 put
pixs 8 cols 8 sub qmv 1 put
} if
 
% Add the format information
format (full) eq {
/fmtvals [
16#5412 16#5125 16#5e7c 16#5b4b 16#45f9 16#40ce 16#4f97 16#4aa0
16#5412 16#5125 16#5e7c 16#5b4b 16#45f9 16#40ce 16#4f97 16#4aa0
16#77c4 16#72f3 16#7daa 16#789d 16#662f 16#6318 16#6c41 16#6976
16#1689 16#13be 16#1ce7 16#19d0 16#0762 16#0255 16#0d0c 16#083b
16#1689 16#13be 16#1ce7 16#19d0 16#0762 16#0255 16#0d0c 16#083b
16#355f 16#3068 16#3f31 16#3a06 16#24b4 16#2183 16#2eda 16#2bed
] def
/ecid (MLHQ) eclevel search pop length exch pop exch pop def
/fmtval fmtvals ecid 3 bitshift bestmaskval add get def
} {
0 1 formatmap length 1 sub {
/i exch def
formatmap i get {
pixs exch aload pop qmv fmtval 14 i sub neg bitshift 1 and put
} forall
} for
} if
format (micro) eq {
/fmtvals [
16#4445 16#4172 16#4e2b 16#4b1c 16#55ae 16#5099 16#5fc0 16#5af7
16#6793 16#62a4 16#6dfd 16#68ca 16#7678 16#734f 16#7c16 16#7921
17259,26 → 19563,54
16#06de 16#03e9 16#0cb0 16#0987 16#1735 16#1202 16#1d5b 16#186c
16#2508 16#203f 16#2f66 16#2a51 16#34e3 16#31d4 16#3e8d 16#3bba
] def
/symid [ [0] [1 2] [3 4] [5 6 7] ] size 11 sub 2 idiv get eclval get def
/symid [ [0] [1 2] [3 4] [5 6 7] ] cols 11 sub 2 idiv get eclval get def
/fmtval fmtvals symid 2 bitshift bestmaskval add get def
} ifelse
0 1 formatmap length 1 sub {
/i exch def
formatmap i get {
pixs exch {} forall qmv fmtval 14 i sub neg bitshift 1 and put
} forall
} for
0 1 formatmap length 1 sub {
/i exch def
pixs formatmap i get 0 get aload pop qmv fmtval 14 i sub neg bitshift 1 and put
} for
} if
format (rmqr) eq {
/fmtvals1 [
16#1fab2 16#1e597 16#1dbdd 16#1c4f8 16#1b86c 16#1a749 16#19903 16#18626
16#17f0e 16#1602b 16#15e61 16#14144 16#13dd0 16#122f5 16#11cbf 16#1039a
16#0f1ca 16#0eeef 16#0d0a5 16#0cf80 16#0b314 16#0ac31 16#0927b 16#08d5e
16#07476 16#06b53 16#05519 16#04a3c 16#036a8 16#0298d 16#017c7 16#008e2
16#3f367 16#3ec42 16#3d208 16#3cd2d 16#3b1b9 16#3ae9c 16#390d6 16#38ff3
16#376db 16#369fe 16#357b4 16#34891 16#33405 16#32b20 16#3156a 16#30a4f
16#2f81f 16#2e73a 16#2d970 16#2c655 16#2bac1 16#2a5e4 16#29bae 16#2848b
16#27da3 16#26286 16#25ccc 16#243e9 16#23f7d 16#22058 16#21e12 16#20137
] def
/fmtvals2 [
16#20a7b 16#2155e 16#22b14 16#23431 16#248a5 16#25780 16#269ca 16#276ef
16#28fc7 16#290e2 16#2aea8 16#2b18d 16#2cd19 16#2d23c 16#2ec76 16#2f353
16#30103 16#31e26 16#3206c 16#33f49 16#343dd 16#35cf8 16#362b2 16#37d97
16#384bf 16#39b9a 16#3a5d0 16#3baf5 16#3c661 16#3d944 16#3e70e 16#3f82b
16#003ae 16#01c8b 16#022c1 16#03de4 16#04170 16#05e55 16#0601f 16#07f3a
16#08612 16#09937 16#0a77d 16#0b858 16#0c4cc 16#0dbe9 16#0e5a3 16#0fa86
16#108d6 16#117f3 16#129b9 16#1369c 16#14a08 16#1552d 16#16b67 16#17442
16#18d6a 16#1924f 16#1ac05 16#1b320 16#1cfb4 16#1d091 16#1eedb 16#1f1fe
] def
/fmtvalu (MH) eclevel search pop length exch pop exch pop 5 bitshift verind add def
/fmtval1 fmtvals1 fmtvalu get def
/fmtval2 fmtvals2 fmtvalu get def
0 1 formatmap length 1 sub {
/i exch def
pixs formatmap i get 0 get aload pop qmv fmtval1 17 i sub neg bitshift 1 and put
pixs formatmap i get 1 get aload pop qmv fmtval2 17 i sub neg bitshift 1 and put
} for
} if
 
% Add the version information
size 45 ge {
format (full) eq cols 45 ge and {
/vervals [
16#07c94 16#085bc 16#09a99 16#0a4d3 16#0bbf6 16#0c762 16#0d847
16#0e60d 16#0f928 16#10b78 16#1145d 16#12a17 16#13532 16#149a6
16#15683 16#168c9 16#177ec 16#18ec4 16#191e1 16#1afab 16#1b08e
16#1cc1a 16#1d33f 16#1ed75 16#1f250 16#209d5 16#216fd 16#228ba
16#07c94 16#085bc 16#09a99 16#0a4d3 16#0bbf6 16#0c762 16#0d847
16#0e60d 16#0f928 16#10b78 16#1145d 16#12a17 16#13532 16#149a6
16#15683 16#168c9 16#177ec 16#18ec4 16#191e1 16#1afab 16#1b08e
16#1cc1a 16#1d33f 16#1ed75 16#1f250 16#209d5 16#216fd 16#228ba
16#2379f 16#24b0b 16#2542e 16#26a64 16#27541 16#28c69
] def
/verval vervals size 17 sub 4 idiv 7 sub get def
/verval vervals cols 17 sub 4 idiv 7 sub get def
0 1 versionmap length 1 sub {
/i exch def
versionmap i get {
17291,10 → 19623,10
<<
/ren //renmatrix
/pixs pixs
/pixx size
/pixy size
/height size 2 mul 72 div
/width size 2 mul 72 div
/pixx cols
/pixy rows
/height rows 2 mul 72 div
/width cols 2 mul 72 div
/opt options
>>
 
17302,7 → 19634,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/qrcode dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
17310,14 → 19644,153
%%EndResource
% --END ENCODER qrcode--
 
% --BEGIN ENCODER swissqrcode--
% --REQUIRES preamble raiseerror parseinput renmatrix qrcode--
% --DESC: Swiss QR Code
% --EXAM:
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp swissqrcode 0.0 2021092800 62083 65448
%%BeginData: 127 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
dup /qrcode dup /uk.co.terryburton.bwipp findresource put
begin
/swissqrcode {
 
20 dict begin % Confine variables to local scope
 
/options exch def % We are given an option string
/barcode exch def % We are given a barcode string
 
/dontdraw false def
 
/parse false def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
options {
token false eq {exit} if dup length string cvs (=) search
true eq {cvlit exch pop exch def} {cvlit true def} ifelse
} loop
currentdict end /options exch def
} if
options {def} forall
 
% Parse ordinals of the form ^NNN to ASCII
/fncvals <<
/parse parse
/parseonly true
/parsefnc false
>> def
/barcode barcode fncvals //parseinput exec def
/barlen barcode length def
options (parse) undef
 
% Validate the input length
barcode length 997 gt {
/bwipp.swissqrcodeBadLength (Swiss QR Code input must not exceed 997 digits) //raiseerror exec
} if
 
% Get the result of encoding with qrcode
options (dontdraw) true put
/args barcode options //qrcode exec def
 
args (opt) options put
args
 
% The 7mm-wide Swiss Cross is defined by the specification as being an
% overlaid image, i.e. not made out of "modules", so very likely a
% different pitch. It cannot therefore be represented by our standard image
% dictionary and would be a nightmare to gridfit. The application assumes a
% sufficient high-resolution print process that such issues do not matter.
%
% So for now we simply do as we're told and paint over the top of the
% barcode image that has been scaled to 46mm, user be damned!
%
dontdraw not {
 
gsave
currentpoint translate
72 25.4 div dup scale % pt to mm
 
% Clipping path with 7mm hole for the Swiss Cross
gsave
newpath
0 0 moveto
46 0 lineto
46 46 lineto
0 46 lineto
closepath
19.5 19.5 moveto
19.5 26.5 lineto
26.5 26.5 lineto
26.5 19.5 lineto
closepath
clip
 
% Scale the QR Code to fit within 46mm
gsave
0 0 moveto
46 args (pixx) get div 2 div dup scale
//renmatrix exec
grestore
 
grestore % Clipping
 
% Draw Swiss Cross
19.5 dup translate
7 83 div dup scale
 
newpath
6 6 moveto
6 77 lineto
77 77 lineto
77 6 lineto
closepath
49 18 moveto
49 34 lineto
65 34 lineto
65 49 lineto
49 49 lineto
49 65 lineto
34 65 lineto
34 49 lineto
18 49 lineto
18 34 lineto
34 34 lineto
34 18 lineto
closepath
0 0 0 setrgbcolor fill
 
grestore
 
} if
 
end
 
}
[/barcode] {null def} forall
bind def
/swissqrcode dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER swissqrcode--
 
% --BEGIN ENCODER microqrcode--
% --REQUIRES preamble raiseerror renmatrix qrcode--
% --REQUIRES preamble raiseerror parseinput renmatrix qrcode--
% --DESC: Micro QR Code
% --EXAM: 1234
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp microqrcode 0.0 2018020400 59555 59304
%%BeginData: 43 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp microqrcode 0.0 2021092800 56791 56668
%%BeginData: 45 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
17352,12 → 19825,14
 
args (opt) options put
args
 
dontdraw not //renmatrix if
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/microqrcode dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
17365,17 → 19840,75
%%EndResource
% --END ENCODER microqrcode--
 
% --BEGIN ENCODER rectangularmicroqrcode--
% --REQUIRES preamble raiseerror parseinput renmatrix qrcode--
% --DESC: Rectangular Micro QR Code
% --EXAM: 1234
% --EXOP: version=R17x139
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp rectangularmicroqrcode 0.0 2021092800 56834 56700
%%BeginData: 45 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
dup /qrcode dup /uk.co.terryburton.bwipp findresource put
begin
/rectangularmicroqrcode {
 
20 dict begin % Confine variables to local scope
 
/options exch def % We are given an option string
/barcode exch def % We are given a barcode string
 
/dontdraw false def
 
% Parse the input options
options type /stringtype eq {
1 dict begin
options {
token false eq {exit} if dup length string cvs (=) search
true eq {cvlit exch pop exch def} {cvlit true def} ifelse
} loop
currentdict end /options exch def
} if
options {def} forall
 
% Get the result of encoding with qrcode with format=micro
options (dontdraw) true put
options (format) (rmqr) put
 
/args barcode options //qrcode exec def
 
args (opt) options put
args
 
dontdraw not //renmatrix if
 
end
 
}
[/barcode] {null def} forall
bind def
/rectangularmicroqrcode dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER rectangularmicroqrcode--
 
% --BEGIN ENCODER maxicode--
% --REQUIRES preamble raiseerror renmaximatrix--
% --REQUIRES preamble raiseerror parseinput renmaximatrix--
% --DESC: MaxiCode
% --EXAM: [)>^03001^02996152382802^029840^029001^0291Z00004951^029UPSN^02906X610^029159^0291234567^0291/1^029^029Y^029634 ALPHA DR^029PITTSBURGH^029PA^029^004
% --EXOP: mode=2 parse
% --RNDR: renmaximatrix
%%BeginResource: uk.co.terryburton.bwipp maxicode 0.0 2018020400 138022 143801
%%BeginData: 564 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp maxicode 0.0 2021092800 126843 125788
%%BeginData: 596 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renmaximatrix dup /uk.co.terryburton.bwipp findresource put
begin
/maxicode {
17389,6 → 19922,7
/mode -1 def
/sam -1 def
/parse false def
/parsefnc false def
 
% Parse the input options
options type /stringtype eq {
17404,52 → 19938,51
/mode mode cvi def
/sam sam cvi def
 
% Parse ordinals of the form ^NNN to ASCII
parse {
/msg barcode length string def
/j 0 def
barcode
{ % loop
(^) search {
dup msg exch j exch putinterval
length j add 1 add /j exch def
pop
dup 0 3 getinterval cvi msg exch j 1 sub exch put
dup length 3 sub 3 exch getinterval
} {
dup msg exch j exch putinterval
length j add /j exch def
/barcode msg 0 j getinterval def
exit
} ifelse
} loop
} if
/msg barcode def
% Parse the input
/fncvals <<
/parse parse
/parsefnc parsefnc
/eci true
% ECIs only
>> def
/msg barcode fncvals //parseinput exec def
/msglen msg length def
 
% Special message handling for modes 2 and 3
mode 2 eq mode 3 eq or {
 
% Normalise messages that begin with a field identifier [)>RS01GSyy
msg 0 7 getinterval <5b293e1e30311d> eq {
/fid msg 0 9 getinterval def
/msg msg 9 msglen 9 sub getinterval def
% Convert to a string for extracting the structured data
/barcode msglen string def
0 1 msglen 1 sub {
/i exch def
msg i get 0 gt {
barcode i msg i get put
} if
} for
/barlen barcode length def
 
% Normalise messages that begin with a field identifier [)>{RS}01{GS}yy
barcode 0 7 getinterval <5b293e1e30311d> eq {
/fid barcode 0 9 getinterval def
/barcode barcode 9 barlen 9 sub getinterval def
} {
/fid () def
} ifelse
 
% Read the postcode, country code and service code fields separated by GS
msg <1d> search pop /pcode exch def
% Read the postcode, country code and service code fields seperated by GS
barcode <1d> search pop /pcode exch def
pop <1d> search pop /ccode exch def
pop <1d> search pop /scode exch def
pop /msg exch def
pop /barcode exch def
 
% Prepend the field identifier
msg length fid length add string dup
0 fid putinterval dup
fid length msg putinterval
/msg exch def
barcode length fid length add string dup
0 fid putinterval dup
fid length barcode putinterval
/barcode exch def
/barlen barcode length def
 
/msg [ barcode {} forall ] def
/msglen msg length def
 
} if
17458,10 → 19991,10
/eci -1 def /pad -2 def /ns -3 def
/la -4 def /lb -5 def
/sa -6 def /sb -7 def /sc -8 def /sd -9 def /se -10 def
/sa2 -11 def /sa3 -12 def
/sa2 -11 def /sa3 -12 def
/lkc -13 def /lkd -14 def /lke -15 def
/pd2 -16 def /pd3 -17 def
/pd2 -16 def /pd3 -17 def
 
% Character maps for each state
/charmaps [
% A B C D E
17474,7 → 20007,7
[ (F) (f) 198 230 6 ] % 6
[ (G) (g) 199 231 7 ] % 7
[ (H) (h) 200 232 8 ] % 8
[ (I) (i) 201 233 9 ] % 9
[ (I) (i) 201 233 9 ] % 9
[ (J) (j) 202 234 10 ] % 10
[ (K) (k) 203 235 11 ] % 11
[ (L) (l) 204 236 12 ] % 12
17529,8 → 20062,8
[ sd sd sd lkd sd ] % 61
[ se se se se lke ] % 62
[ lb la lb lb lb ] % 63
] def
] def
 
% Invert charmaps to give character to value maps for each state
/charvals [ 64 dict 64 dict 64 dict 64 dict 64 dict ] def
0 1 charmaps length 1 sub {
17539,7 → 20072,7
0 1 4 {
/j exch def
encs j get dup type /stringtype eq {0 get} if % convert string to ASCII if required
charvals j get exch i put
charvals j get exch i put
} for
} for
/seta charvals 0 get def
17560,15 → 20093,15
} for
/nseq nseq 0 msglen getinterval def
 
% Encode the message from ASCII to codewords
% Encode the message from ASCII to codewords
/prefixinset {
0 {
2 copy exch length ge {exit} if
2 copy exch length ge {exit} if
2 copy get 3 index exch known {1 add} {exit} ifelse
} loop
exch pop exch pop
} bind def
 
/enc {
exch get out exch j exch put
/j j 1 add def
17586,10 → 20119,39
exit
} if
{ % not a loop but common exit point
% Immediately encode an ECI
msg i get -1000000 le {
eci cset load enc
msg i get neg 1000000 sub
dup 000031 le { % ECI 000000 - 000031
63 and
1 array astore
} { dup 001023 le { % ECI 000032 - 001023
dup -6 bitshift 31 and 32 or exch
63 and
2 array astore
} { dup 032767 le { % ECI 001024 - 032767
dup -12 bitshift 47 and 48 or exch
dup -6 bitshift 63 and exch
63 and
3 array astore
} { % ECI 032768 - 999999
dup -18 bitshift 55 and 56 or exch
dup -12 bitshift 63 and exch
dup -6 bitshift 63 and exch
63 and
4 array astore
} ifelse } ifelse } ifelse
dup out exch j exch putinterval
length j add /j exch def
/i i 1 add def
exit
} if
 
% If 9 numerals available then use NS
nseq i get 9 ge {
msg i 9 getinterval cvi 4 { dup 63 and exch -6 bitshift } repeat cset load ns get
msg i 9 getinterval 0 exch {48 sub add 10 mul} forall 10 idiv
4 { dup 63 and exch -6 bitshift } repeat cset load ns get
0 2 10 {index} for 6 array astore 7 1 roll 6 {pop} repeat
out exch j exch putinterval
/i i 9 add def
17596,19 → 20158,19
/j j 6 add def
exit
} if
 
% Read next three characters
/char1 msg i get def
/char2 i 1 add msglen lt {msg i 1 add get} {-99} ifelse def
/char3 i 2 add msglen lt {msg i 2 add get} {-99} ifelse def
 
% If current mode is sufficient then directly encode
cset load char1 known {
cset load char1 known {
char1 cset load enc
/i i 1 add def
exit
} if
 
% For switching from A to B
cset (seta) eq setb char1 known and {
setb char2 known {
17621,7 → 20183,7
} ifelse
exit
} if
 
% For switching from B to A encode according to length of prefix
cset (setb) eq seta char1 known and {
/p seta msg i 4 msglen i sub 2 copy gt {exch} if pop getinterval prefixinset def
17634,7 → 20196,7
sa2 setb enc
char1 seta enc
char2 seta enc
/i i 2 add def
/i i 2 add def
} if
p 3 eq {
sa3 setb enc
17641,7 → 20203,7
char1 seta enc
char2 seta enc
char3 seta enc
/i i 3 add def
/i i 3 add def
} if
p 4 ge {
la setb enc
17649,24 → 20211,24
} if
exit
} if
 
% If character is in A or B then directly latch
seta char1 known {
la cset load enc
/cset (seta) def
exit
} if
} if
setb char1 known {
lb cset load enc
/cset (setb) def
exit
} if
} if
 
% Determine which one of sets C, D or E the character is in
setc char1 known {/setx (setc) def /sx sc def /lkx lkc def} if
setd char1 known {/setx (setd) def /sx sd def /lkx lkd def} if
sete char1 known {/setx (sete) def /sx se def /lkx lke def} if
 
% Encode according to the length of the prefix
/p setx load msg i 4 msglen i sub 2 copy gt {exch} if pop getinterval prefixinset def
p 1 eq {
17693,20 → 20255,20
p 4 ge {
sx cset load enc
lkx setx load enc
/cset setx def
/cset setx def
} if
 
exit
} loop % out
} loop
/encmsg out 0 j getinterval def
/padval cset load pad get def
/padval cset load pad get def
 
% Prefix the encoded message with the structured append insert
/sami [] def
sam -1 ne {
/sami 2 array def
sami 0 seta pad get put
sami 0 seta pad get put
sami 1 sam 10 idiv 1 sub 8 mul sam 10 mod 1 sub add put
} if
/encmsg [ sami aload pop encmsg aload pop ] def
17725,8 → 20287,8
pcb pcode cvi 2 30 string cvrs dup length 36 exch sub exch putinterval
} { % mode=3
% For alphanumeric postcode, trim or pad with spaces to 6 chars and encode to binary
/pccw [
( ) 6 string copy dup 0 pcode length 6 gt {pcode 0 6 getinterval} {pcode} ifelse putinterval
/pccw [
( ) 6 string copy dup 0 pcode length 6 gt {pcode 0 6 getinterval} {pcode} ifelse putinterval
{seta exch get} forall
] def
0 1 5 {
17753,7 → 20315,7
 
% Evaluate the structured carrier message as codewords
/pri [ 0 0 0 0 0 0 0 0 0 0 ] def
0 1 59 {
0 1 59 {
/i exch def
/ps i 6 idiv def
/ep 2 5 i 6 mod sub exp cvi scm i get 48 sub mul def
17846,11 → 20408,11
% Recompose the secondary parity codewords
/secchk [ 0 1 scodes 1 sub { dup secochk exch get exch secechk exch get } for ] def
 
% Concatenate the data into final codewords
% Concatinate the data into final codewords
/codewords [
pri aload pop
pri aload pop
pri 10 rscodes aload pop
sec aload pop
sec aload pop
secchk aload pop
] def
 
17864,49 → 20426,49
 
% Maps modules to pixels in the grid
/modmap [
469 529 286 316 347 346 673 672 703 702 647 676 283 282 313 312 370 610 618 379
378 409 408 439 705 704 559 589 588 619 458 518 640 701 675 674 285 284 315 314
310 340 531 289 288 319 349 348 456 486 517 516 471 470 369 368 399 398 429 428
549 548 579 578 609 608 649 648 679 678 709 708 639 638 669 668 699 698 279 278
309 308 339 338 381 380 411 410 441 440 561 560 591 590 621 620 547 546 577 576
607 606 367 366 397 396 427 426 291 290 321 320 351 350 651 650 681 680 711 710
1 0 31 30 61 60 3 2 33 32 63 62 5 4 35 34 65 64 7 6
37 36 67 66 9 8 39 38 69 68 11 10 41 40 71 70 13 12 43 42
73 72 15 14 45 44 75 74 17 16 47 46 77 76 19 18 49 48 79 78
21 20 51 50 81 80 23 22 53 52 83 82 25 24 55 54 85 84 27 26
57 56 87 86 117 116 147 146 177 176 115 114 145 144 175 174 113 112 143 142
173 172 111 110 141 140 171 170 109 108 139 138 169 168 107 106 137 136 167 166
105 104 135 134 165 164 103 102 133 132 163 162 101 100 131 130 161 160 99 98
129 128 159 158 97 96 127 126 157 156 95 94 125 124 155 154 93 92 123 122
153 152 91 90 121 120 151 150 181 180 211 210 241 240 183 182 213 212 243 242
185 184 215 214 245 244 187 186 217 216 247 246 189 188 219 218 249 248 191 190
221 220 251 250 193 192 223 222 253 252 195 194 225 224 255 254 197 196 227 226
257 256 199 198 229 228 259 258 201 200 231 230 261 260 203 202 233 232 263 262
205 204 235 234 265 264 207 206 237 236 267 266 297 296 327 326 357 356 295 294
325 324 355 354 293 292 323 322 353 352 277 276 307 306 337 336 275 274 305 304
335 334 273 272 303 302 333 332 271 270 301 300 331 330 361 360 391 390 421 420
363 362 393 392 423 422 365 364 395 394 425 424 383 382 413 412 443 442 385 384
415 414 445 444 387 386 417 416 447 446 477 476 507 506 537 536 475 474 505 504
535 534 473 472 503 502 533 532 455 454 485 484 515 514 453 452 483 482 513 512
451 450 481 480 511 510 541 540 571 570 601 600 543 542 573 572 603 602 545 544
575 574 605 604 563 562 593 592 623 622 565 564 595 594 625 624 567 566 597 596
627 626 657 656 687 686 717 716 655 654 685 684 715 714 653 652 683 682 713 712
637 636 667 666 697 696 635 634 665 664 695 694 633 632 663 662 693 692 631 630
661 660 691 690 721 720 751 750 781 780 723 722 753 752 783 782 725 724 755 754
785 784 727 726 757 756 787 786 729 728 759 758 789 788 731 730 761 760 791 790
733 732 763 762 793 792 735 734 765 764 795 794 737 736 767 766 797 796 739 738
769 768 799 798 741 740 771 770 801 800 743 742 773 772 803 802 745 744 775 774
805 804 747 746 777 776 807 806 837 836 867 866 897 896 835 834 865 864 895 894
833 832 863 862 893 892 831 830 861 860 891 890 829 828 859 858 889 888 827 826
857 856 887 886 825 824 855 854 885 884 823 822 853 852 883 882 821 820 851 850
881 880 819 818 849 848 879 878 817 816 847 846 877 876 815 814 845 844 875 874
813 812 843 842 873 872 811 810 841 840 871 870 901 900 931 930 961 960 903 902
933 932 963 962 905 904 935 934 965 964 907 906 937 936 967 966 909 908 939 938
969 968 911 910 941 940 971 970 913 912 943 942 973 972 915 914 945 944 975 974
917 916 947 946 977 976 919 918 949 948 979 978 921 920 951 950 981 980 923 922
953 952 983 982 925 924 955 954 985 984 927 926 957 956 987 986 58 89 88 118
149 148 178 209 208 238 269 268 298 329 328 358 389 388 418 449 448 478 509 508
538 569 568 598 629 628 658 689 688 718 749 748 778 809 808 838 869 868 898 929
469 529 286 316 347 346 673 672 703 702 647 676 283 282 313 312 370 610 618 379
378 409 408 439 705 704 559 589 588 619 458 518 640 701 675 674 285 284 315 314
310 340 531 289 288 319 349 348 456 486 517 516 471 470 369 368 399 398 429 428
549 548 579 578 609 608 649 648 679 678 709 708 639 638 669 668 699 698 279 278
309 308 339 338 381 380 411 410 441 440 561 560 591 590 621 620 547 546 577 576
607 606 367 366 397 396 427 426 291 290 321 320 351 350 651 650 681 680 711 710
1 0 31 30 61 60 3 2 33 32 63 62 5 4 35 34 65 64 7 6
37 36 67 66 9 8 39 38 69 68 11 10 41 40 71 70 13 12 43 42
73 72 15 14 45 44 75 74 17 16 47 46 77 76 19 18 49 48 79 78
21 20 51 50 81 80 23 22 53 52 83 82 25 24 55 54 85 84 27 26
57 56 87 86 117 116 147 146 177 176 115 114 145 144 175 174 113 112 143 142
173 172 111 110 141 140 171 170 109 108 139 138 169 168 107 106 137 136 167 166
105 104 135 134 165 164 103 102 133 132 163 162 101 100 131 130 161 160 99 98
129 128 159 158 97 96 127 126 157 156 95 94 125 124 155 154 93 92 123 122
153 152 91 90 121 120 151 150 181 180 211 210 241 240 183 182 213 212 243 242
185 184 215 214 245 244 187 186 217 216 247 246 189 188 219 218 249 248 191 190
221 220 251 250 193 192 223 222 253 252 195 194 225 224 255 254 197 196 227 226
257 256 199 198 229 228 259 258 201 200 231 230 261 260 203 202 233 232 263 262
205 204 235 234 265 264 207 206 237 236 267 266 297 296 327 326 357 356 295 294
325 324 355 354 293 292 323 322 353 352 277 276 307 306 337 336 275 274 305 304
335 334 273 272 303 302 333 332 271 270 301 300 331 330 361 360 391 390 421 420
363 362 393 392 423 422 365 364 395 394 425 424 383 382 413 412 443 442 385 384
415 414 445 444 387 386 417 416 447 446 477 476 507 506 537 536 475 474 505 504
535 534 473 472 503 502 533 532 455 454 485 484 515 514 453 452 483 482 513 512
451 450 481 480 511 510 541 540 571 570 601 600 543 542 573 572 603 602 545 544
575 574 605 604 563 562 593 592 623 622 565 564 595 594 625 624 567 566 597 596
627 626 657 656 687 686 717 716 655 654 685 684 715 714 653 652 683 682 713 712
637 636 667 666 697 696 635 634 665 664 695 694 633 632 663 662 693 692 631 630
661 660 691 690 721 720 751 750 781 780 723 722 753 752 783 782 725 724 755 754
785 784 727 726 757 756 787 786 729 728 759 758 789 788 731 730 761 760 791 790
733 732 763 762 793 792 735 734 765 764 795 794 737 736 767 766 797 796 739 738
769 768 799 798 741 740 771 770 801 800 743 742 773 772 803 802 745 744 775 774
805 804 747 746 777 776 807 806 837 836 867 866 897 896 835 834 865 864 895 894
833 832 863 862 893 892 831 830 861 860 891 890 829 828 859 858 889 888 827 826
857 856 887 886 825 824 855 854 885 884 823 822 853 852 883 882 821 820 851 850
881 880 819 818 849 848 879 878 817 816 847 846 877 876 815 814 845 844 875 874
813 812 843 842 873 872 811 810 841 840 871 870 901 900 931 930 961 960 903 902
933 932 963 962 905 904 935 934 965 964 907 906 937 936 967 966 909 908 939 938
969 968 911 910 941 940 971 970 913 912 943 942 973 972 915 914 945 944 975 974
917 916 947 946 977 976 919 918 949 948 979 978 921 920 951 950 981 980 923 922
953 952 983 982 925 924 955 954 985 984 927 926 957 956 987 986 58 89 88 118
149 148 178 209 208 238 269 268 298 329 328 358 389 388 418 449 448 478 509 508
538 569 568 598 629 628 658 689 688 718 749 748 778 809 808 838 869 868 898 929
928 958 989 988
] def
 
17933,7 → 20495,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/maxicode dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
17942,16 → 20506,17
% --END ENCODER maxicode--
 
% --BEGIN ENCODER azteccode--
% --REQUIRES preamble raiseerror renmatrix--
% --REQUIRES preamble raiseerror parseinput renmatrix--
% --DESC: Aztec Code
% --EXAM: This is Aztec Code
% --EXOP: format=full
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp azteccode 0.0 2018020400 203151 219167
%%BeginData: 679 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp azteccode 0.0 2021092800 183704 199457
%%BeginData: 780 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
begin
/azteccode {
17969,6 → 20534,7
/ecaddchars 3 def
/raw false def
/parse false def
/parsefnc false def
 
% Parse the input options
options type /stringtype eq {
17980,46 → 20546,50
currentdict end /options exch def
} if
options {def} forall
 
/layers layers cvi def
/eclevel eclevel cvr def
/ecaddchars ecaddchars cvi def
 
% Parse ordinals of the form ^NNN to ASCII
parse {
/msg barcode length string def
/j 0 def
barcode
{ % loop
(^) search {
dup msg exch j exch putinterval
length j add 1 add /j exch def
pop
dup 0 3 getinterval cvi msg exch j 1 sub exch put
dup length 3 sub 3 exch getinterval
} {
dup msg exch j exch putinterval
length j add /j exch def
/barcode msg 0 j getinterval def
exit
} ifelse
} loop
format (rune) eq {
barcode length 0 eq {
/bwipp.aztecRuneNotNumeric (Aztec runes must be numeric) //raiseerror exec
} if
barcode {
dup 48 lt exch 57 gt or {
/bwipp.aztecRuneNotNumeric (Aztec runes must be numeric) //raiseerror exec
} if
} forall
barcode cvi dup 0 lt exch 255 gt or {
/bwipp.aztecRuneInvalid (Aztec runes must be 0 to 255) //raiseerror exec
} if
} if
 
% Parse the input
/fn1 -1 def
/fncvals <<
/parse parse
/parsefnc parsefnc
/eci true
(FNC1) fn1
>> def
/msg barcode fncvals //parseinput exec def
/msglen msg length def
 
% Convert from input into message bitstream
/msgbits () def
format (rune) ne raw and {/msgbits barcode def} if
/msgbits () def
format (rune) ne raw and {/msgbits barcode def} if
format (rune) ne raw not and {
 
% State key: "U"pper, "L"ower, "M"ixed, "P"unctuation, "D"igit, "B"inary
/U 0 def /L 1 def /M 2 def /P 3 def /D 4 def /B 5 def
 
% Special function characters
/lu -1 def /ll -2 def /lm -3 def
/lp -4 def /ld -5 def /su -6 def
/sp -7 def /sb -8 def /fl -9 def
/p2 -10 def /p3 -11 def /p4 -12 def /p5 -13 def
/lu -2 def /ll -3 def /lm -4 def
/lp -5 def /ld -6 def /su -7 def
/sp -8 def /sb -9 def /fl -10 def
/p2 -11 def /p3 -12 def /p4 -13 def /p5 -14 def
 
% Character maps for each state
/charmaps [
% U L M P D
18055,8 → 20625,8
[ lm lm lu ({) -99 ] % 29
[ ld ld lp (}) -99 ] % 30
[ sb sb sb lu -99 ] % 31
] def
] def
 
% Invert charmaps to give character to value maps for each state
/charvals [ 32 dict 32 dict 32 dict 32 dict 16 dict ] def
0 1 charmaps length 1 sub {
18065,10 → 20635,10
0 1 4 {
/j exch def
encs j get dup type /stringtype eq {0 get} if % convert string to ASCII if required
charvals j get exch i put
charvals j get exch i put
} for
} for
 
% Punctuation compression
/pcomp <<
<0d0a> p2 % CR LF
18076,9 → 20646,9
(, ) p4
(: ) p5
>> def
 
/e 10000 def % "Empty"
 
/latlen [ % Bit length of latch between states
% To: U L M P D B From
[ 0 5 5 10 5 10 ] % U
18107,22 → 20677,34
[ e e e e e ] % P
[ 4 e e 4 e ] % D
] def
% U L M P D B
/charsize [ 5 5 5 5 4 8 ] def
 
/charsize {
dup 0 ge {
% U L M P D B
pop [ 5 5 5 5 4 8 ] exch get
} { % FNC or ECI in P
exch pop
dup fn1 eq { % FNC1: PS{Flg(0)} + 3
pop 8
} { % ECI: PS{Flg(n)} + 3 + 4n
neg 1000000 sub dup 0 eq {pop 1} if
ln 10 ln div cvi 1 add 4 mul 8 add
} ifelse
} ifelse
} bind def
 
% U L M P D B
/curlen [ 0 e e e e e ] def
/curseq [ [] [] [] [] [] [] ] def
 
/backto U def % U
/lastchar () def
 
% Derive the optimal sequences ending in each state
barcode {
msg {
 
/char exch def
 
% Check for optimisations in the current sequences by latching from x to y
{ % loop
/imp false def
18149,31 → 20731,35
imp not {exit} if % Repeat unless no improvement
} loop
 
% Determine optimal next sequences for each valid encoding
/nxtlen [ e e e e e e ] def
% Determine optimal next sequences for each valid encoding
/nxtlen [ e e e e e e ] def
/nxtseq 6 array def
 
[ U L M P D B ] {
/x exch def
 
{ % loop for common exit
 
% Skip states that cannot encode character
x B ne {charvals x get char known not {exit} if} if
char 0 ge {
x B ne {charvals x get char known not {exit} if} if
} {
x P ne {exit} if % Only P can encode FNC1 and ECI
} ifelse
 
% Extend directly
/cost curlen x get charsize x get add def
/cost curlen x get x char charsize add def
cost nxtlen x get lt {
nxtlen x cost put
nxtseq x [ curseq x get aload pop char ] put
} if
% Optimise for direct shifts from y to x
 
% Optimise for direct shifts from y to x
x B eq {exit} if % B is treated as a latch
[ U L M P D ] {
/y exch def
x y ne {
/cost curlen y get shftlen y get x get add charsize x get add def
/cost curlen y get shftlen y get x get add x char charsize add def
cost nxtlen y get lt {
nxtlen y cost put
nxtseq y [
18184,36 → 20770,88
} if
} if
} forall
 
exit
} loop
 
} forall
 
% Optimise using P compression
lastchar () ne {
lastchar () ne char 0 ge and {
/pchars 2 string dup 0 lastchar put dup 1 char put def
pcomp pchars known {
curlen P get nxtlen P get lt {
nxtlen P curlen P get put
nxtseq P [ curseq P get aload pop pop pcomp pchars get ] put
} if
[ U L M P D ] {
/i exch def
/inP true def % U and L can't encode CR, comma, dot or colon
i M eq { % M can encode CR
lastchar 13 eq { /inP false def } if
} {
i D eq { % D can encode comma and dot
lastchar 44 eq lastchar 46 eq or { /inP false def } if
} if
} ifelse
inP curlen i get nxtlen i get lt and {
/curseqi curseq i get def
/lastld false def
/lastsp false def
/lastidx -1 def
curseqi length 1 sub -1 0 { % Search backwards for lastchar
/idx exch def
/ch curseqi idx get def
lastidx -1 eq {
ch lastchar eq {
/lastidx idx def
idx 0 gt {
curseqi idx 1 sub get sp eq { /lastsp true def } if % Preceded by P/S
} if
} if
} { % Found lastchar, check latch
ch 0 lt ch ld ge and { % If have latch
i P eq {
ch ld eq { /lastld true def } if % Set flag if D/L for adjustment below
} {
ch lp ne { /inP lastsp def } if % If not P/L only in P if have P/S
} ifelse
exit
} if
} ifelse
} for
inP lastidx 0 ge and {
nxtlen i curlen i get put
lastidx curseqi length 1 sub lt { % If lastchar not at end of sequence
i P eq {
lastld { nxtlen i nxtlen i get 1 add put } if % Adjust count if D/L
% Move lastchar to end and replace
nxtseq i [ curseqi aload pop curseqi length lastidx sub -1 roll pop pcomp pchars get ] put
} {
% Replace lastchar in situ
nxtseq i [ curseqi aload pop ] put
nxtseq i get lastidx pcomp pchars get put
} ifelse
} {
nxtseq i [ curseqi aload pop pop pcomp pchars get ] put
} ifelse
} if
} if
} forall
} if
} if
} if
 
% Account for binary extension for 32 or more bytes
/numbytes 0 def
nxtseq B get {
sb eq {0} {numbytes 1 add} ifelse /numbytes exch def
} forall
numbytes 32 eq {nxtlen B nxtlen B get 11 add put} if
nxtseq B get null ne {
/numbytes 0 def
nxtseq B get {
sb eq {0} {numbytes 1 add} ifelse /numbytes exch def
} forall
numbytes 32 eq {nxtlen B nxtlen B get 11 add put} if
} if
 
/curlen nxtlen def
/curseq nxtseq def
/lastchar char def
/lastchar char 0 ge {char} {()} ifelse def
 
} forall
 
% Select the optimal sequence
/minseq e def
[ U L M P D B ] {
18223,44 → 20861,67
/seq curseq i get def
} if
} forall
 
% Encoding functions
/tobin {
string dup length 1 sub 0 exch 1 exch {1 index exch 48 put} for
dup 3 -1 roll 2 2 index length string cvrs dup length 2 index length exch sub exch putinterval
dup 3 -1 roll 2 2 index length string cvrs dup length 2 index length exch sub exch putinterval
} bind def
 
/encu {charvals U get exch get 5 tobin} bind def
/encl {charvals L get exch get 5 tobin} bind def
/encm {charvals M get exch get 5 tobin} bind def
/encp {charvals P get exch get 5 tobin} bind def
/encd {charvals D get exch get 4 tobin} bind def
 
/encp {
dup fn1 eq { % FNC1: Flg(0)
pop (00000000)
} {
dup -1000000 le { % ECI: Flg(n) + n-Digits
neg 1000000 sub dup dup 0 eq {pop 1} if
ln 10 ln div cvi
dup 1 add 4 mul 8 add string
dup 0 (00000) putinterval % Flg(n)
dup 2 index 1 add 3 tobin 5 exch putinterval % len
3 1 roll -1 0 { % ECI digits in "Digit" encoding
4 mul 8 add exch
dup 10 idiv 3 index 4 2 roll
10 mod 2 add 4 tobin putinterval
} for
pop
} {
charvals P get exch get 5 tobin
} ifelse } ifelse
} bind def
 
/encfuncs [ /encu /encl /encm /encp /encd ] def
 
/addtomsgbits {
/v exch def
msgbits j v putinterval
/j j v length add def
} bind def
 
% Encode the sequence
/state U def
/msgbits minseq string def
/i 0 def /j 0 def {
i seq length ge {exit} if
 
state B ne {
 
/char seq i get def
 
% Encode character
char encfuncs state get load exec addtomsgbits
/i i 1 add def
 
% Encode shifted next character
char su eq char sp eq or {
seq i get char su eq {encu} {encp} ifelse addtomsgbits
/i i 1 add def
} if
 
% Latches to new state
char lu eq {/state U def} if
char ll eq {/state L def} if
18268,16 → 20929,16
char lp eq {/state P def} if
char ld eq {/state D def} if
char sb eq {/state B def} if
 
} { % Binary
 
% Find number of bytes before latch or end
/numbytes 0 def {
i numbytes add seq length ge {exit} if
seq i numbytes add get 0 lt {exit} if
seq i numbytes add get 0 lt {exit} if
/numbytes numbytes 1 add def
} loop
 
% Encode length
numbytes 31 le {
numbytes 5 tobin addtomsgbits
18285,13 → 20946,13
0 5 tobin addtomsgbits
numbytes 31 sub 11 tobin addtomsgbits
} ifelse
 
% Encode bytes
numbytes {
seq i get 8 tobin addtomsgbits
seq i get 8 tobin addtomsgbits
/i i 1 add def
} repeat
 
% Return to previous state as indicated
i seq length lt {
/char seq i get def
18300,14 → 20961,14
char ll eq {/state L def} if
char lm eq {/state M def} if
} if
 
} ifelse
 
} loop
 
} if
 
% Lookup the most appropriate symbol specification
% Lookup the most appropriate symbol specification
/metrics [
[ (rune) 0 0 0 6 ] % Special metric for rune symbols
[ (compact) 1 1 17 6 ] [ (full) 1 1 21 6 ] [ (compact) 2 0 40 6 ]
18333,12 → 20994,12
/ncws m 3 get def % Total of codewords
/bpcw m 4 get def % Bits per codeword
/numecw ncws eclevel mul 100 div ecaddchars add ceiling cvi def
msgbits length 0 eq {/numecw 0 def} if % Error correction codewords
msgbits length 0 eq {/numecw 0 def} if % Error correction codewords
/numdcw ncws numecw sub def % Data codewords
/okay true def
format (unset) ne format frmt ne and {/okay false def} if
readerinit icap 1 ne and {/okay false def} if
layers -1 ne layers mlyr ne and {/okay false def} if
layers -1 ne layers mlyr ne and {/okay false def} if
msgbits length bpcw div ceiling cvi numdcw gt {/okay false def} if
okay {exit} if
/i i 1 add def
18358,8 → 21019,8
/cwf msgbits m bpcw add 1 sub 1 getinterval def % Last bit
cwb allzero {/cwf (1) def /m m 1 sub def} if % Flip last bit to avoid zeros
cwb allones {/cwf (0) def /m m 1 sub def} if % Flip last bit to avoid ones
% Concatenate the bits
12 string dup 0 cwb putinterval
% Concatenate the bits
12 string dup 0 cwb putinterval
dup bpcw 1 sub cwf putinterval
0 bpcw getinterval
/cwb exch def
18375,11 → 21036,13
/cw cw 2 bpcw i sub 1 sub exp cvi cwb i get 48 sub mul add def
} for
cws c cw put
/m m bpcw add def
/m m bpcw add def
/c c 1 add def
} loop
} loop
/cws cws 0 c getinterval def
 
options /debugcws known { /bwipp.debugcws cws //raiseerror exec } if
 
% Reed-Solomon algorithm
/rscodes {
 
18405,12 → 21068,12
% Generate the coefficients
/coeffs [ 1 rsnc {0} repeat ] def
1 1 rsnc {
/i exch def
/i exch def
coeffs i coeffs i 1 sub get put
i 1 sub -1 1 {
/j exch def
coeffs j coeffs j 1 sub get coeffs j get rsalog i get rsprod xor put
} for
} for
coeffs 0 coeffs 0 get rsalog i get rsprod put
} for
 
18418,11 → 21081,11
/nd rscws length def
/rscws [ rscws {} forall rsnc {0} repeat 0 ] def
0 1 nd 1 sub {
/k exch rscws exch get rscws nd get xor def
/k exch rscws exch get rscws nd get xor def
0 1 rsnc 1 sub {
/j exch def
/j exch def
rscws nd j add rscws nd j add 1 add get k coeffs rsnc j sub 1 sub get rsprod xor put
} for
} for
} for
 
% Return all but the last codeword
18440,11 → 21103,11
mode 2#0000000011110000 and -4 bitshift
mode 2#0000000000001111 and
] def
/mode mode 6 16 19 rscodes def
/mode mode 6 16 19 rscodes def
} if
format (compact) eq {
/mode layers 1 sub 6 bitshift cws length 1 sub add def
readerinit {/mode mode 2#00100000 or def} if
readerinit {/mode mode 2#00100000 or def} if
/mode [
mode 2#11110000 and -4 bitshift
mode 2#00001111 and
18464,16 → 21127,16
0 1 modebits length 1 sub {modebits exch (0) putinterval} for
0 1 mode length 1 sub {
/i exch def
modebits mode i get 2 4 string cvrs dup length 4 exch sub 4 i mul add exch putinterval
modebits mode i get 2 4 string cvrs dup length 4 exch sub 4 i mul add exch putinterval
} for
 
% Extend the data codewords with error correction codewords to create the bit string for the data
/rsparams [
[] [] [] [] [] []
[ 64 67 ] % 6-bit codewords
[] [] [] [] [] []
[ 64 67 ] % 6-bit codewords
[]
[ 256 301 ] % 8-bit codewords
[]
[]
[ 1024 1033 ] % 10-bit codewords
[]
[ 4096 4201 ] % 12-bit codewords
18480,16 → 21143,16
] def
/cws cws ncws cws length sub rsparams bpcw get {} forall rscodes def
format (full) eq {
/databits layers layers mul 16 mul layers 112 mul add string def
/databits layers layers mul 16 mul layers 112 mul add string def
} {
/databits layers layers mul 16 mul layers 88 mul add string def
/databits layers layers mul 16 mul layers 88 mul add string def
} ifelse
0 1 databits length 1 sub {databits exch (0) putinterval} for
0 1 ncws 1 sub {
0 1 ncws 1 sub {
/i exch def
databits cws i get 2 bpcw string cvrs
dup length bpcw exch sub bpcw i mul add databits length ncws bpcw mul sub add
exch putinterval
databits cws i get 2 bpcw string cvrs
dup length bpcw exch sub bpcw i mul add databits length ncws bpcw mul sub add
exch putinterval
} for
 
% Move to a point in the cartesian plane centered on the bullseye
18502,7 → 21165,7
/lwid fw llyr 4 mul add def
/ldir lbit 2 idiv lwid idiv def
ldir 0 eq { % Top
lwid 1 sub 2 idiv neg 1 add lbit 2 idiv lwid mod add
lwid 1 sub 2 idiv neg 1 add lbit 2 idiv lwid mod add
fw 1 sub 2 idiv llyr 2 mul add lbit 2 mod add
cmv
} if
18526,7 → 21189,7
% Create the pixel map
% For full symbols we disregard the reference grid at this stage
format (full) eq {/fw 12 def} {/fw 9 def} ifelse
/size fw layers 4 mul add 2 add def
/size fw layers 4 mul add 2 add def
/pixs [size size mul {-1} repeat] def
/mid size 1 sub 2 idiv size mul size 1 sub 2 idiv add def
 
18556,7 → 21219,7
npixs i size 2 idiv neg j add cmv [size 2 idiv j add i add 1 add 2 mod] putinterval
npixs i neg size 2 idiv neg j add cmv [size 2 idiv j add i add 1 add 2 mod] putinterval
} for
} for
} for
/j 0 def
0 1 npixs length 1 sub {
/i exch def
18591,7 → 21254,7
 
% Mode ring
format (full) eq {
/modemap [
/modemap [
[-5 7] [-4 7] [-3 7] [-2 7] [-1 7] [ 1 7] [ 2 7] [ 3 7] [ 4 7] [ 5 7]
[ 7 5] [ 7 4] [ 7 3] [ 7 2] [ 7 1] [ 7 -1] [ 7 -2] [ 7 -3] [ 7 -4] [ 7 -5]
[ 5 -7] [ 4 -7] [ 3 -7] [ 2 -7] [ 1 -7] [-1 -7] [-2 -7] [-3 -7] [-4 -7] [-5 -7]
18624,7 → 21287,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/azteccode dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
18633,13 → 21298,13
% --END ENCODER azteccode--
 
% --BEGIN ENCODER azteccodecompact--
% --REQUIRES preamble raiseerror renmatrix azteccode--
% --REQUIRES preamble raiseerror parseinput renmatrix azteccode--
% --DESC: Compact Aztec Code
% --EXAM: 1234
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp azteccodecompact 0.0 2018020400 59583 59327
%%BeginData: 43 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp azteccodecompact 0.0 2021092800 53387 56691
%%BeginData: 45 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
18674,12 → 21339,14
 
args (opt) options put
args
 
dontdraw not //renmatrix if
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/azteccodecompact dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
18688,13 → 21355,13
% --END ENCODER azteccodecompact--
 
% --BEGIN ENCODER aztecrune--
% --REQUIRES preamble raiseerror renmatrix azteccode--
% --REQUIRES preamble raiseerror parseinput renmatrix azteccode--
% --DESC: Aztec Runes
% --EXAM: 1
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp aztecrune 0.0 2018020400 59552 59303
%%BeginData: 43 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp aztecrune 0.0 2021092800 53356 56667
%%BeginData: 45 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
18729,12 → 21396,14
 
args (opt) options put
args
 
dontdraw not //renmatrix if
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/aztecrune dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
18743,16 → 21412,17
% --END ENCODER aztecrune--
 
% --BEGIN ENCODER codeone--
% --REQUIRES preamble raiseerror renmatrix--
% --REQUIRES preamble raiseerror parseinput renmatrix--
% --DESC: Code One
% --EXAM: Code One
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp codeone 0.0 2018020400 234465 250175
%%BeginData: 856 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp codeone 0.0 2021092800 196362 218850
%%BeginData: 883 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
begin
/codeone {
18778,29 → 21448,6
} if
options {def} forall
 
% Parse ordinals of the form ^NNN to ASCII
parse {
/msg barcode length string def
/j 0 def
barcode
{ % loop
(^) search {
dup msg exch j exch putinterval
length j add 1 add /j exch def
pop
dup 0 3 getinterval cvi msg exch j 1 sub exch put
dup length 3 sub 3 exch getinterval
} {
dup msg exch j exch putinterval
length j add /j exch def
/barcode msg 0 j getinterval def
exit
} ifelse
} loop
} if
 
/barlen barcode length def
 
/stype version 0 1 getinterval (S) eq def
 
stype {
18856,6 → 21503,8
a
} bind def
 
/barlen barcode length def
 
% Convert value plus one to binary
/v [ 1 ] def
0 1 barlen 1 sub {
18888,27 → 21537,50
% Convert input into bytes accounting for FNC characters
/fnc1 -1 def /fnc3 -2 def
/fncvals <<
/parse parse
/parsefnc parsefnc
/eci true
(FNC1) fnc1
(FNC3) fnc3
>> def
/msg barlen array def
/i 0 def /j 0 def {
i barlen eq {exit} if
/char barcode i get def
parsefnc char 94 eq and i barlen 4 sub lt and {
barcode i 1 add get 94 ne {
/char fncvals barcode i 1 add 4 getinterval get def
/i i 4 add def
/msg barcode fncvals //parseinput exec def
/msglen msg length def
 
% Special characters
/lC -5 def /lB -6 def /lX -7 def /lT -8 def /lD -9 def /unl -10 def
/fnc2 -11 def /fnc4 -12 def /sft1 -13 def /sft2 -14 def /sft3 -15 def /eci -16 def /pad -17 def /fnc1lD -18 def
/unlcw 255 def
 
% Code One stores ECIs in data
/eciesc 16#5c def % We choose \ as a typical default
/numecis 0 msg { -1000000 le {1 add} if } forall def
numecis 0 gt {
/msgtmp msg length 2 mul numecis 6 mul add 2 add array def
msgtmp 0 pad put
msgtmp 1 eciesc put
/j 2 def
0 1 msg length 1 sub {
msg exch get
dup -1000000 le {
neg 10 7 string cvrs 1 6 getinterval {} forall 6 array astore
msgtmp exch j 1 add exch putinterval
msgtmp j eciesc put
/j j 7 add def
} {
/i i 1 add def
dup eciesc ne {
msgtmp exch j exch put
/j j 1 add def
} {
pop
msgtmp j eciesc put
msgtmp j 1 add eciesc put
/j j 2 add def
} ifelse
} ifelse
} if
msg j char put
/i i 1 add def
/j j 1 add def
} loop
/msg msg 0 j getinterval def
/msglen msg length def
} for
/msg msgtmp 0 j getinterval def
/msglen msg length def
} if
 
% Basic metrics for the each symbol
% ver row col dcol dcws rscw rsbl ro ri rl
18925,7 → 21597,7
[ (T-32) 16 33 32 24 16 1 99 99 99 ]
[ (T-48) 16 49 48 38 22 1 99 99 99 ]
] def
 
% Select metrics of an appropriate symbol
/fullcws [] def
metrics {
18948,12 → 21620,7
numremcws i numremcws i 1 add get 1 add put
} if
} for
% Special characters
/lC -5 def /lB -6 def /lX -7 def /lT -8 def /lD -9 def /unl -10 def
/fnc2 -11 def /fnc4 -12 def /sft1 -13 def /sft2 -14 def /sft3 -15 def /eci -16 def /pad -17 def /fnc1lD -18 def
/unlcw 255 def
 
/Avals <<
0 1 128 {dup 1 add} for
pad 129
18969,7 → 21636,7
/Avals <<
Avals {[exch]} forall
>> def
 
/CNvals <<
sft1 0
sft2 1
18996,7 → 21663,7
C2vals {[exch CNvals sft2 get exch]} forall
C3vals {[exch CNvals sft3 get exch]} forall
>> def
 
/TNvals <<
sft1 0
sft2 1
19027,7 → 21694,7
T2vals {[exch TNvals sft2 get exch]} forall
T3vals {[exch TNvals sft3 get exch]} forall
>> def
 
% Extended ASCII mappings
128 1 255 {
/i exch def
19035,7 → 21702,7
Cvals i [ Cvals fnc4 get aload pop Cvals i 128 sub get aload pop ] put
Tvals i [ Tvals fnc4 get aload pop Tvals i 128 sub get aload pop ] put
} for
 
/Xvals <<
13 0
42 1
19047,7 → 21714,7
/Xvals <<
Xvals {[exch]} forall
>> def
 
/Bvals <<
0 1 255 {dup} for
>> def
19054,9 → 21721,9
/Bvals <<
Bvals {[exch]} forall
>> def
 
/encvals [ Avals Cvals Tvals Xvals -1 Bvals ] def
 
/numD [ msglen {0} repeat 0 ] def
/nextXterm [ msglen {0} repeat 9999 ] def
/nextNonX [ msglen {0} repeat 9999 ] def
19079,7 → 21746,7
} for
/nextXterm [nextXterm {dup 10000 gt {pop 10000} if} forall] def
/nextNonX [nextNonX {dup 10000 gt {pop 10000} if} forall] def
 
/isD {char 48 ge char 57 le and} bind def
/isC {CNvals char known} bind def
/isT {TNvals char known} bind def
19087,9 → 21754,9
/isEA {char 127 gt} bind def
/isFN {char 0 lt} bind def
/XtermFirst {dup nextXterm exch get exch nextNonX exch get lt} bind def
 
/A 0 def /C 1 def /T 2 def /X 3 def /D 4 def /B 5 def
 
/lookup {
/ac 1 def /cc 2 def /tc 2 def /xc 2 def /bc 3 def
mode A eq {/ac 0 def /cc 1 def /tc 1 def /xc 1 def /bc 2 def} if
19112,32 → 21779,32
/tc tc isT {2 3 div add} {isEA { 8 3 div add } { 4 3 div add } ifelse} ifelse def
/xc xc isX {2 3 div add} {isEA {13 3 div add } {10 3 div add } ifelse} ifelse def
/bc bc isFN {3 add} {1 add} ifelse def
k 3 ge {
k 3 ge { % Checking after at least 4 characters (cf. Data Matrix), not 3 as in spec Step Q
true [ac cc tc xc ] {bc 1 add exch ceiling le and} forall {B exit} if
true [ cc tc xc bc] {ac 1 add exch ceiling le and} forall {A exit} if
true [ac cc xc bc] {tc 1 add exch ceiling le and} forall {T exit} if
true [ac tc ] {cc 1 add exch ceiling le and} forall {
true [ac cc xc bc] {tc ceiling 1 add exch ceiling le and} forall {T exit} if
true [ac tc ] {cc ceiling 1 add exch ceiling le and} forall {
cc ceiling xc ceiling lt {C exit} if
cc xc eq {i k add 1 add XtermFirst {X exit} {C exit} ifelse} if
} if
true [ac cc tc bc] {xc 1 add exch lt and} forall {X exit} if
true [ac cc tc bc] {xc ceiling 1 add exch ceiling le and} forall {X exit} if
} if
/k k 1 add def
} loop
} repeat
} bind def
 
/addtocws {
dup cws exch j exch putinterval
/j exch length j add def
} bind def
 
/tobin {
string dup length 1 sub 0 exch 1 exch {1 index exch 48 put} for
dup 3 -1 roll 2 2 index length string cvrs dup length 2 index length exch sub exch putinterval
[ exch {48 sub} forall ]
} bind def
 
/encA {
1 { % Common exit
numD i get 21 ge {
19182,7 → 21849,7
exit
} repeat
} bind def
 
/CTXvalstocws {
/in exch def
mark
19192,32 → 21859,51
} for
counttomark array astore exch pop
} bind def
 
/encCTX {
/p 0 def
/ctxvals 2220 array def
 
% Lookup the values for each character
{
i msglen eq {exit} if
encvals mode get msg i get known not {exit} if
p 3 mod 0 eq {
numD i get 12 ge {
ctxvals 0 p getinterval CTXvalstocws addtocws
[unlcw] addtocws
/mode A def
exit
} if
numD i get dup 8 ge exch i add msglen eq and {
[unlcw] addtocws
/mode A def
exit
} if
lookup mode ne {
ctxvals 0 p getinterval CTXvalstocws addtocws
[unlcw] addtocws
/mode A def
exit
} if
mode X eq { % Steps E1c, E2
Xvals msg i get known not {
ctxvals 0 p getinterval CTXvalstocws addtocws
% Unlatch to ASCII unless one codeword left and single ASCII to encode
numremcws j get 1 ne msg i get 127 gt or {
[unlcw] addtocws
} if
/mode A def
exit
} if
i 1 add msglen lt {
Xvals msg i 1 add get known not {exit} if
i 2 add msglen lt {
Xvals msg i 2 add get known not {exit} if
} if
} if
} {
lookup mode ne {
ctxvals 0 p getinterval CTXvalstocws addtocws
[unlcw] addtocws
/mode A def
exit
} if
} ifelse
msglen i sub 3 le { % Check end of data conditions
/remcws numremcws j p 3 idiv 2 mul add get def
/remvals [
19274,7 → 21960,7
/p exch length p add def
/i i 1 add def
} loop
 
% Backtrack to a boundary and return to ASCII
mode A ne {
{
19298,11 → 21984,11
} ifelse
} if
} if
 
} bind def
 
/encD {
 
{ % loop
 
numD i get 3 lt {
19311,13 → 21997,19
/remcws numremcws j Dbits length 8 idiv add get def
 
% Final codeword with no data
numremcws j Dbits length 8 idiv add 1 sub get 1 sub 0 eq
i msglen eq and {exit} if
% Final digit into final codeword as ASCII
numremcws j Dbits length 8 idiv add 1 sub get 1 sub 0 eq Drem 0 eq and % No remaining codewords and no bits
remcws 1 eq Drem 0 ne and or % Or 1 remaining codeword and some bits
i msglen eq and {
Drem 4 eq Drem 6 eq or { /Dbits [ Dbits aload pop 1 1 1 1 ] def } if
Drem 2 eq Drem 6 eq or { /Dbits [ Dbits aload pop 0 1 ] def } if
exit
} if
 
% Final digit or double-digit into final codeword as ASCII
i msglen 1 sub eq numD i get 1 eq and
i msglen 2 sub eq numD i get 2 eq and or
remcws 1 eq and Drem 0 eq and {exit} if
 
% Latch to ASCII unless 4 or 6 bits remain in final codeword
i msglen 1 sub eq numD i get 1 eq and
remcws 1 eq and Drem 4 eq Drem 6 eq or and not {
19341,9 → 22033,9
} if
 
exit
 
} if
 
% Three digit value plus one to ten bits
/Dbits [
Dbits aload pop
19351,7 → 22043,7
1 add 10 tobin aload pop
] def
/i i 3 add def
 
} loop
 
mark
19362,7 → 22054,7
/mode A def
 
} bind def
 
/encB {
/p 0 def /bvals 1480 array def {
i msglen eq {exit} if
19392,7 → 22084,7
[ /encA /encCTX /encCTX /encCTX /encD /encB ] mode get load exec
} loop
/cws cws 0 j getinterval def
 
} ifelse
 
% Select metrics of an appropriate symbol
19404,7 → 22096,7
/cols m 2 get def % Columns in symbol
/dcol m 3 get def % Data columns in symbol
/dcws m 4 get def % Data codewords in symbol
/rscw m 5 get def % Error correction codewords
/rscw m 5 get def % Error correction codewords
/rsbl m 6 get def % Error correction blocks
/riso m 7 get def % Riser offset
/risi m 8 get def % Riser interval
19425,16 → 22117,18
/cws [ dcws cws length sub {0} repeat cws aload pop ] def
} ifelse
 
options /debugcws known { /bwipp.debugcws cws //raiseerror exec } if
 
% De-interleave the codewords into blocks
/cwbs rsbl array def % Array of data codeword blocks
/ecbs rsbl array def % Array of error correction blocks
0 1 rsbl 1 sub {
/i exch def
/cwb dcpb array def
/cwb dcpb array def
0 1 dcpb 1 sub {
/j exch def
cwb j cws j rsbl mul i add get put
} for
} for
cwbs i cwb put
} for
 
19446,7 → 22140,7
/rslog gf array def
1 1 gf-1 {dup rsalog exch get exch rslog 3 1 roll put} for
/rsprod {
2 copy 0 ne exch 0 ne and {
2 copy 0 ne exch 0 ne and {
rslog exch get exch rslog exch get add gf-1 mod rsalog exch get
} {
pop pop 0
19456,12 → 22150,12
% Generate the coefficients for the Reed-Solomon algorithm
/coeffs [ 1 ecpb {0} repeat ] def
0 1 ecpb 1 sub {
/i exch def
/i exch def
coeffs i 1 add coeffs i get put
i -1 1 {
/j exch def
coeffs j coeffs j 1 sub get coeffs j get rsalog i get rsprod xor put
} for
} for
coeffs 0 coeffs 0 get rsalog i get rsprod put
} for
/coeffs coeffs 0 coeffs length 1 sub getinterval def
19520,14 → 22214,14
 
% Centre pattern
/artifact [
{cols {0} repeat} bind
{cols {1} repeat} bind
{0 cols 2 sub {1} repeat 0} bind
{0 1 cols 4 sub {0} repeat 1 0} bind
{cols 1 sub 2 idiv {-1} repeat 1 cols 1 sub 2 idiv {-1} repeat} bind
{cols 1 sub 2 idiv {-1} repeat 0 cols 1 sub 2 idiv {-1} repeat} bind
{1 cols 2 sub {0} repeat 1} bind
{1 0 cols 4 sub {1} repeat 0 1} bind
{cols {0} repeat} bind
{cols {1} repeat} bind
{0 cols 2 sub {1} repeat 0} bind
{0 1 cols 4 sub {0} repeat 1 0} bind
{cols 1 sub 2 idiv {-1} repeat 1 cols 1 sub 2 idiv {-1} repeat} bind
{cols 1 sub 2 idiv {-1} repeat 0 cols 1 sub 2 idiv {-1} repeat} bind
{1 cols 2 sub {0} repeat 1} bind
{1 0 cols 4 sub {1} repeat 0 1} bind
] def
/cpat <<
/A (121343)
19541,7 → 22235,7
/S (56661278)
/T (5666666666127878)
>> vers 0 1 getinterval get def
pixs 0 rows cpat length sub 2 idiv mmv
pixs 0 rows cpat length sub 2 idiv mmv
[ cpat {artifact exch 49 sub get exec} forall ] putinterval
 
% Risers
19553,7 → 22247,7
pixs j i mmv
3 -1 roll putinterval
i risl 1 sub ne {
pixs cols j sub 2 sub rows i sub 1 sub mmv
pixs cols j sub 2 sub rows i sub 1 sub mmv
3 -1 roll putinterval
} {pop} ifelse
} for
19602,7 → 22296,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/codeone dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
19611,16 → 22307,17
% --END ENCODER codeone--
 
% --BEGIN ENCODER hanxin--
% --REQUIRES preamble raiseerror renmatrix--
% --REQUIRES preamble raiseerror parseinput renmatrix--
% --DESC: Han Xin Code
% --EXAM: This is Han Xin
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp hanxin 0.0 2018020400 360817 380345
%%BeginData: 886 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp hanxin 0.0 2021092800 305838 345620
%%BeginData: 852 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
begin
/hanxin {
19650,50 → 22347,13
 
/mask mask cvi def
 
% Parse ordinals of the form ^NNN to ASCII
parse {
/msg barcode length string def
/j 0 def
barcode
{ % loop
(^) search {
dup msg exch j exch putinterval
length j add 1 add /j exch def
pop
dup 0 3 getinterval cvi msg exch j 1 sub exch put
dup length 3 sub 3 exch getinterval
} {
dup msg exch j exch putinterval
length j add /j exch def
/barcode msg 0 j getinterval def
exit
} ifelse
} loop
} if
 
/barlen barcode length def
 
% Convert input into bytes accounting for FNC characters
% Parse the input
/fncvals <<
/parse parse
/parsefnc parsefnc
% No FNC characters defined
>> def
/msg barlen array def
/i 0 def /j 0 def {
i barlen eq {exit} if
/char barcode i get def
parsefnc char 94 eq and i barlen 4 sub lt and {
barcode i 1 add get 94 ne {
/char fncvals barcode i 1 add 4 getinterval get def
/i i 4 add def
} {
/i i 1 add def
} ifelse
} if
msg j char put
/i i 1 add def
/j j 1 add def
} loop
/msg msg 0 j getinterval def
/msg barcode fncvals //parseinput exec def
/msglen msg length def
 
% Default error correction level
20076,7 → 22736,7
bits length dmod gt {/okay false def} if % Bitstream must fit into data modules
okay {exit} if
} for
 
okay not {
/bwipp.hanxinNoValidSymbol (No valid symbol available) //raiseerror exec
} if
20192,7 → 22852,7
13 ncws 1 sub { dup ncws lt {cws exch get} {pop} ifelse } for
} for
] def
 
% Extend codewords by one if there are remainder bits
rbit 0 gt {
/pad cws length 1 add array def
20405,7 → 23065,7
} for
scr1 scr3
} bind def
 
% Evaluation algorithm
/evalfull {
/sym exch def
20443,7 → 23103,7
 
n1 n3 add
} bind def
 
% Evaluate the masked symbols to find the most suitable
/bestscore 999999999 def
0 1 masks length 1 sub {
20500,7 → 23160,9
 
end
 
} bind def
}
[/barcode] {null def} forall
bind def
/hanxin dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
20509,16 → 23171,17
% --END ENCODER hanxin--
 
% --BEGIN ENCODER dotcode--
% --REQUIRES preamble raiseerror renmatrix--
% --REQUIRES preamble raiseerror parseinput renmatrix--
% --DESC: DotCode
% --EXAM: This is DotCode
% --EXOP: fast inkspread=0.3
% --EXOP: inkspread=0.16
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp dotcode 0.0 2018020400 293476 312375
%%BeginData: 1041 ASCII Lines
%%BeginResource: uk.co.terryburton.bwipp dotcode 0.0 2021092800 231580 260718
%%BeginData: 1037 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
begin
/dotcode {
20559,29 → 23222,6
/ratio 3 2 div def
} if
 
% Parse ordinals of the form ^NNN to ASCII
parse {
/msg barcode length string def
/j 0 def
barcode
{ % loop
(^) search {
dup msg exch j exch putinterval
length j add 1 add /j exch def
pop
dup 0 3 getinterval cvi msg exch j 1 sub exch put
dup length 3 sub 3 exch getinterval
} {
dup msg exch j exch putinterval
length j add /j exch def
/barcode msg 0 j getinterval def
exit
} ifelse
} loop
} if
 
/barlen barcode length def
 
% Convert input into bytes accounting for FNC characters
/laa -1 def /lab -2 def /lac -3 def /bin -4 def
/sfa -5 def /sfb -6 def /sb2 -7 def /sb3 -8 def
20593,6 → 23233,36
/aim -29 def /m05 -30 def /m06 -31 def /m12 -32 def
/mac -33 def
 
% Parse the input
/fncvals <<
/parse parse
/parsefnc parsefnc
/eci true
(FNC1) fn1
% (FNC2) fn2 % Use ^ECInnnnnn for ECI; Structured append not supported
(FNC3) fn3
>> def
/msg barcode fncvals //parseinput exec def
/msglen msg length def
 
% Special FNC2 semantics: Expand ECI characters into ^FNC2nnnnnn
/numecis 0 msg { -1000000 le {1 add} if } forall def
/msgtmp msg length numecis 6 mul add array def
/j 0 def
0 1 msg length 1 sub {
msg exch get dup -1000000 le {
neg 10 7 string cvrs 1 6 getinterval {} forall 6 array astore
msgtmp exch j 1 add exch putinterval
msgtmp j fn2 put
/j j 7 add def
} {
msgtmp exch j exch put
/j j 1 add def
} ifelse
} for
/msg msgtmp def
/msglen msg length def
 
% Character maps for each state
/charmaps [
% A B C A B C A B C
20658,30 → 23328,6
102 [ sc2 sc3 sc4 sc5 sc6 sc7 tma tmb tmc tms ] {exch 1 add dup} forall pop
>> def
 
/fncvals <<
(FNC1) fn1
(FNC2) fn2
(FNC3) fn3
>> def
/msg barlen array def
/i 0 def /j 0 def {
i barlen eq {exit} if
/char barcode i get def