1919use Picqer \Barcode \BarcodeBar ;
2020use Picqer \Barcode \Exceptions \InvalidFormatException ;
2121
22- define ('TELEPEN_START_CHAR ' , '_ ' );
23- define ('TELEPEN_STOP_CHAR ' , 'z ' );
24- define ('TELEPEN_ALPHA ' , 'alpha ' );
25- define ('TELEPEN_NUMERIC ' , 'numeric ' );
26-
2722class TypeTelepen implements TypeInterface
2823{
24+ private const TELEPEN_START_CHAR = '_ ' ;
25+ private const TELEPEN_STOP_CHAR = 'z ' ;
26+ private const TELEPEN_ALPHA = 'alpha ' ;
27+ private const TELEPEN_NUMERIC = 'numeric ' ;
28+
2929 private $ telepen_lookup_table ;
3030 private $ mode ;
3131
3232 public function __construct ($ m = 'alpha ' )
3333 {
34- $ this ->mode = TELEPEN_ALPHA ;
34+ $ this ->mode = self :: TELEPEN_ALPHA ;
3535 if (strtolower ($ m ) == 'numeric ' ) {
36- $ this ->mode = TELEPEN_NUMERIC ;
36+ $ this ->mode = self :: TELEPEN_NUMERIC ;
3737 }
3838 $ this ->createTelepenConversionTable ();
3939 }
@@ -60,7 +60,7 @@ public function getBarcodeData(string $code): Barcode
6060 protected function encode ($ code ) : string
6161 {
6262 $ result = null ;
63- if ($ this ->mode == TELEPEN_ALPHA ) {
63+ if ($ this ->mode == self :: TELEPEN_ALPHA ) {
6464 $ result = $ this ->encodeAlpha ($ code );
6565 } else {
6666 $ result = $ this ->encodeNumeric ($ code );
@@ -71,8 +71,10 @@ protected function encode($code) : string
7171
7272 protected function encodeAlpha ($ code ) : string
7373 {
74-
75- if (!preg_match ('/[ -~]+/ ' , $ code )) { // everything from ASCII32-ASCII127
74+ // We aren't interested in the non-printable parts of the ASCII set
75+ if (
76+ !preg_match ('/[ -~]+/ ' , $ code )
77+ ) { // everything from ASCII32-ASCII127
7678 throw new InvalidFormatException ("Invalid characters in data " );
7779 }
7880
@@ -84,7 +86,7 @@ protected function encodeAlpha($code) : string
8486 */
8587
8688 // begin with start char
87- $ dest = $ this ->telepen_lookup_table [ord (TELEPEN_START_CHAR )];
89+ $ dest = $ this ->telepen_lookup_table [ord (self :: TELEPEN_START_CHAR )];
8890
8991 for ($ i = 0 ; $ i < strlen ($ code ); $ i ++) {
9092 //$ascii_code = ord(substr($code, $i, 1));
@@ -100,7 +102,7 @@ protected function encodeAlpha($code) : string
100102 }
101103
102104 $ dest .= $ this ->telepen_lookup_table [ord ($ check_digit )];
103- $ dest .= $ this ->telepen_lookup_table [ord (TELEPEN_STOP_CHAR )]; // Stop
105+ $ dest .= $ this ->telepen_lookup_table [ord (self :: TELEPEN_STOP_CHAR )]; // Stop
104106
105107 return $ dest ;
106108 }
@@ -120,7 +122,7 @@ private function encodeNumeric(string $code) : string
120122 }
121123
122124 $ count = 0 ;
123- $ dest = $ this ->telepen_lookup_table [ord (TELEPEN_START_CHAR )]; // begin with the start character _
125+ $ dest = $ this ->telepen_lookup_table [ord (self :: TELEPEN_START_CHAR )]; // begin with the start character _
124126
125127 for ($ i = 0 ; $ i < strlen ($ code ); $ i += 2 ) {
126128 $ c1 = $ code [$ i ];
@@ -145,42 +147,54 @@ private function encodeNumeric(string $code) : string
145147 }
146148
147149 $ dest .= $ this ->telepen_lookup_table [$ check_digit ];
148- $ dest .= $ this ->telepen_lookup_table [ord (TELEPEN_STOP_CHAR )]; // Stop
150+ $ dest .= $ this ->telepen_lookup_table [ord (self :: TELEPEN_STOP_CHAR )]; // Stop
149151
150152 return $ dest ;
151153 }
152154
155+ /**
156+ * The table provides a representation of barcode patterns
157+ * for each character in the ASCII set. from ASCII0-127
158+ * Each barcode starts with "_" - ASCII95 0x5F,
159+ * and ends with "z" - ASCII122 0xFA.
160+ * More information about Telepen symbology is available from
161+ * https://v4l237.n3cdn1.secureserver.net/wp-content/uploads/2022/05/Barcode-Symbology-information-and-History.pdf
162+ */
153163 private function createTelepenConversionTable ()
154164 {
155165 $ this ->telepen_lookup_table = [
156- "1111111111111111 " , "1131313111 " , "33313111 " , "1111313131 " ,
157- "3111313111 " , "11333131 " , "13133131 " , "111111313111 " , "31333111 " ,
158- "1131113131 " , "33113131 " , "1111333111 " , "3111113131 " , "1113133111 " ,
159- "1311133111 " , "111111113131 " , "3131113111 " , "11313331 " , "333331 " ,
160- "111131113111 " , "31113331 " , "1133113111 " , "1313113111 " , "1111113331 " ,
161- "31131331 " , "113111113111 " , "3311113111 " , "1111131331 " , "311111113111 " ,
162- "1113111331 " , "1311111331 " , "11111111113111 " , "31313311 " , "1131311131 " ,
163- "33311131 " , "1111313311 " , "3111311131 " , "11333311 " , "13133311 " ,
164- "111111311131 " , "31331131 " , "1131113311 " , "33113311 " , "1111331131 " ,
165- "3111113311 " , "1113131131 " , "1311131131 " , "111111113311 " , "3131111131 " ,
166- "1131131311 " , "33131311 " , "111131111131 " , "3111131311 " , "1133111131 " ,
167- "1313111131 " , "111111131311 " , "3113111311 " , "113111111131 " ,
168- "3311111131 " , "111113111311 " , "311111111131 " , "111311111311 " ,
169- "131111111311 " , "11111111111131 " , "3131311111 " , "11313133 " , "333133 " ,
170- "111131311111 " , "31113133 " , "1133311111 " , "1313311111 " , "1111113133 " ,
171- "313333 " , "113111311111 " , "3311311111 " , "11113333 " , "311111311111 " ,
172- "11131333 " , "13111333 " , "11111111311111 " , "31311133 " , "1131331111 " ,
173- "33331111 " , "1111311133 " , "3111331111 " , "11331133 " , "13131133 " ,
174- "111111331111 " , "3113131111 " , "1131111133 " , "33111133 " , "111113131111 " ,
175- "3111111133 " , "111311131111 " , "131111131111 " , "111111111133 " ,
176- "31311313 " , "113131111111 " , "3331111111 " , "1111311313 " , "311131111111 " ,
177- "11331313 " , "13131313 " , "11111131111111 " , "3133111111 " , "1131111313 " ,
178- "33111313 " , "111133111111 " , "3111111313 " , "111313111111 " ,
179- "131113111111 " , "111111111313 " , "313111111111 " , "1131131113 " ,
180- "33131113 " , "11113111111111 " , "3111131113 " , "113311111111 " ,
181- "131311111111 " , "111111131113 " , "3113111113 " , "11311111111111 " ,
182- "331111111111 " , "111113111113 " , "31111111111111 " , "111311111113 " ,
183- "131111111113 "
166+ "1111111111111111 " , "1131313111 " , "33313111 " , "1111313131 " ,
167+ "3111313111 " , "11333131 " , "13133131 " , "111111313111 " ,
168+ "31333111 " , "1131113131 " , "33113131 " , "1111333111 " ,
169+ "3111113131 " , "1113133111 " , "1311133111 " , "111111113131 " ,
170+ "3131113111 " , "11313331 " , "333331 " , "111131113111 " ,
171+ "31113331 " , "1133113111 " , "1313113111 " , "1111113331 " ,
172+ "31131331 " , "113111113111 " , "3311113111 " , "1111131331 " ,
173+ "311111113111 " , "1113111331 " , "1311111331 " , "11111111113111 " ,
174+ "31313311 " , "1131311131 " , "33311131 " , "1111313311 " ,
175+ "3111311131 " , "11333311 " , "13133311 " , "111111311131 " ,
176+ "31331131 " , "1131113311 " , "33113311 " , "1111331131 " ,
177+ "3111113311 " , "1113131131 " , "1311131131 " , "111111113311 " ,
178+ "3131111131 " , "1131131311 " , "33131311 " , "111131111131 " ,
179+ "3111131311 " , "1133111131 " , "1313111131 " , "111111131311 " ,
180+ "3113111311 " , "113111111131 " , "3311111131 " , "111113111311 " ,
181+ "311111111131 " , "111311111311 " , "131111111311 " , "11111111111131 " ,
182+ "3131311111 " , "11313133 " , "333133 " , "111131311111 " ,
183+ "31113133 " , "1133311111 " , "1313311111 " , "1111113133 " ,
184+ "313333 " , "113111311111 " , "3311311111 " , "11113333 " ,
185+ "311111311111 " , "11131333 " , "13111333 " , "11111111311111 " ,
186+ "31311133 " , "1131331111 " , "33331111 " , "1111311133 " ,
187+ "3111331111 " , "11331133 " , "13131133 " , "111111331111 " ,
188+ "3113131111 " , "1131111133 " , "33111133 " , "111113131111 " ,
189+ "3111111133 " , "111311131111 " , "131111131111 " , "111111111133 " ,
190+ "31311313 " , "113131111111 " , "3331111111 " , "1111311313 " ,
191+ "311131111111 " , "11331313 " , "13131313 " , "11111131111111 " ,
192+ "3133111111 " , "1131111313 " , "33111313 " , "111133111111 " ,
193+ "3111111313 " , "111313111111 " , "131113111111 " , "111111111313 " ,
194+ "313111111111 " , "1131131113 " , "33131113 " , "11113111111111 " ,
195+ "3111131113 " , "113311111111 " , "131311111111 " , "111111131113 " ,
196+ "3113111113 " , "11311111111111 " , "331111111111 " , "111113111113 " ,
197+ "31111111111111 " , "111311111113 " , "131111111113 "
184198 ];
185199 }
186200}
0 commit comments