コード例 #1
0
ファイル: Daruma.php プロジェクト: nfephp-org/posprint
 /**
  * Implements barcodes 1D
  * ESC b n1 n2 n3 n4 s1...sn NULL
  *  n1 – tipo do código a ser impresso
  *      EAN13 1
  *      EAN8 2
  *      S2OF5 3
  *      I2OF5 4
  *      CODE128 5
  *      CODE39 6
  *      CODE93 7
  *      UPC_A 8
  *      CODABAR 9
  *      MSI 10
  *      CODE11 11
  *  n2 – largura da barra. De 2 a 5. Se 0, é usado 2.
  *  n3 – altura da barra. De 50 a 200. Se 0, é usado 50.
  *  n4 – se 1, imprime o código abaixo das barras
  *  s1...sn – string contendo o código.
  *      EAN-13: 12 dígitos de 0 a 9
  *      EAN–8: 7 dígitos de 0 a 9
  *      UPC–A: 11 dígitos de 0 a 9
  *      CODE 39 : Tamanho variável. 0-9, A-Z, '-', '.', '%', '/', '$', ' ', '+'
  *      O caracter '*' de start/stop é inserido automaticamente.
  *      Sem dígito de verificação MOD 43
  *      CODE 93: Tamanho variável. 0-9, A-Z, '-', '.', ' ', '$', '/', '+', '%'
  *      O caracter '*' de start/stop é inserido automaticamente.
  *      CODABAR: tamanho variável. 0 - 9, '$', '-', ':', '/', '.', '+'
  *      Existem 4 diferentes caracteres de start/stop: A, B, C, and D que são
  *      usados em pares e não podem aparecer em nenhum outro lugar do código.
  *      Sem dígito de verificação
  *      CODE 11: Tamanho variável. 0 a 9
  *      Checksum de dois caracteres.
  *      CODE 128: Tamanho variável. Todos os caracteres ASCII.
  *      Interleaved 2 of 5: tamanho sempre par. 0 a 9. Sem dígito de verificação
  *      Standard 2 of 5 (Industrial): 0 a 9. Sem dígito de verificação
  *      MSI/Plessey: tamanho variável. 0 - 9. 1 dígito de verificação
  *
  * @param int    $type        Default CODE128
  * @param int    $height
  * @param int    $lineWidth
  * @param string $txtPosition
  * @param string $txtFont
  * @param string $data
  */
 public function barcode($data = '123456', $type = 'CODE128', $height = 162, $lineWidth = 2, $txtPosition = 'none', $txtFont = '')
 {
     if (!($data = Barcodes\Barcode1DAnalysis::validate($data, $type))) {
         throw new \InvalidArgumentException('Data or barcode type is incorrect.');
     }
     if (!array_key_exists($type, $this->barcode1Dlist)) {
         throw new \InvalidArgumentException('This barcode type is not listed.');
     }
     $id = $this->barcode1Dlist[$type];
     $height = self::validateInteger($height, 50, 200, 50);
     $lineWidth = self::validateInteger($lineWidth, 2, 5, 2);
     $n4 = 0;
     if ($txtPosition != 'none') {
         $n4 = 1;
     }
     $this->buffer->write(self::ESC . 'b' . chr($id) . chr($lineWidth) . chr($height) . chr($n4) . $data);
 }
コード例 #2
0
ファイル: Bematech.php プロジェクト: nfephp-org/posprint
 /**
  * Implements barcodes 1D
  *
  * @param int    $type        Default CODE128
  * @param int    $height
  * @param int    $lineWidth
  * @param string $txtPosition
  * @param string $txtFont
  * @param string $data
  */
 public function barcode($data = '123456', $type = 'CODE128', $height = 162, $lineWidth = 2, $txtPosition = 'none', $txtFont = '')
 {
     if ($this->printerMode == 'ESCPOS') {
         parent::barcode($data, $type, $height, $lineWidth, $txtPosition, $txtFont);
         return;
     }
     if (!($data = Barcodes\Barcode1DAnalysis::validate($data, $type))) {
         throw new \InvalidArgumentException('Data or barcode type is incorrect.');
     }
     if (!array_key_exists($type, $this->barcode1Dlist)) {
         throw new \InvalidArgumentException('This barcode type is not listed.');
     }
     $n = strlen($data);
     $id = $this->barcode1Dlist[$type];
     $height = self::validateInteger($height, 50, 200, 50);
     $lineWidth = self::validateInteger($lineWidth, 2, 5, 2);
     $n4 = 0;
     if ($txtPosition != 'none') {
         $n4 = 1;
     }
     switch ($type) {
         case 'UPC_A':
             $this->buffer->write(self::GS . 'kA' . self::VT . $data);
             break;
         case 'UPC_E':
             $this->buffer->write(self::GS . 'kB' . self::ACK . $data);
             break;
         case 'EAN13':
             $this->buffer->write(self::GS . 'kC' . self::FF . $data);
             break;
         case 'EAN8':
             $this->buffer->write(self::GS . 'kD' . self::BEL . $data);
             break;
         case 'CODE39':
             $this->buffer->write(self::GS . 'kE' . char($n) . $data);
             break;
         case 'I25':
             $this->buffer->write(self::GS . 'kF' . char($n) . $data);
             break;
         case 'CODABAR':
             $this->buffer->write(self::GS . 'kG' . char($n) . $data);
             break;
         case 'CODE93':
             $this->buffer->write(self::GS . 'kH' . char($n) . $data);
             break;
         case 'CODE128':
             $this->buffer->write(self::GS . 'kI' . char($n) . $data);
             break;
         case 'ISBN':
             $this->buffer->write(self::GS . 'k' . self::NAK . $data . self::NUL);
             break;
         case 'MSI':
             $this->buffer->write(self::GS . 'k' . self::SYN . $data . self::NUL);
             break;
     }
 }
コード例 #3
0
 /**
  * Implements barcodes 1D
  * GS k m n d1...dn
  * Prints bar code. n specifies the data length.
  *   m    bar code system             number of d (=k)
  *  "A"     UPC-A                       11 or 12
  *  "B"     UPC-E                       6, 7, 8, 11 or 12
  *  "C"     JAN13 / EAN13               12 or 13
  *  "D"     JAN8 / EAN8                 7 or 8
  *  "E"     CODE39                      1 or more
  *  "F"     ITF                         even
  *  "G"     CODABAR (NW-7)              2 or more
  *  "H"     CODE93                      1–255
  *  "I"     CODE128                     2–255
  *  "J"     GS1-128                     2–255
  *  "K"     GS1 DataBar Omnidirectional 13
  *  "L"     GS1 DataBar Truncated       13
  *  "M"     GS1 DataBar Limited         13
  *  "N"     GS1 DataBar Expanded        2–255.
  *
  *  GS h n Sets bar code height to n dots.
  *  GS w n Sets bar width of bar code. n = 2–6 (thin–thick)
  *  GS H n Selects print position of HRI characters.
  *           n = 0, "0": Not printed
  *           n = 1, "1": Above the bar code
  *           n = 2, "2": Below the bar code
  *           n = 3, "3": Both above and below the bar code
  *  GS f n Selects font for the HRI characters.
  *           n = 0, "0": Font A,
  *           n = 1, "1": Font B
  *
  * @param string $data
  * @param int    $type        Default CODE128
  * @param int    $height
  * @param int    $lineWidth
  * @param string $txtPosition
  * @param string $txtFont
  */
 public function barcode($data = '123456', $type = 'CODE128', $height = 162, $lineWidth = 2, $txtPosition = 'none', $txtFont = '')
 {
     switch ($txtPosition) {
         case 'Above':
             $tPos = 1;
             break;
         case 'Below':
             $tPos = 2;
             break;
         case 'Both':
             $tPos = 3;
             break;
         default:
             //none
             $tPos = 0;
     }
     $font = 0;
     if ($txtFont === 'B') {
         $font = 1;
     }
     if (!($data = Barcodes\Barcode1DAnalysis::validate($data, $type))) {
         throw new \InvalidArgumentException('Data or barcode type is incorrect.');
     }
     if (!array_key_exists($type, $this->barcode1Dlist)) {
         throw new \InvalidArgumentException('This barcode type is not listed.');
     }
     $id = $this->barcode1Dlist[$type];
     if (is_null($id)) {
         return;
     }
     $height = self::validateInteger($height, 1, 255, 4);
     $lineWidth = self::validateInteger($lineWidth, 1, 6, 2);
     $nlen = strlen($data);
     //set barcode height
     $this->buffer->write(self::GS . 'h' . chr($height));
     //set barcode bar width
     $this->buffer->write(self::GS . 'w' . chr($lineWidth));
     //Selects print position of HRI characters.
     $this->buffer->write(self::GS . 'H' . chr($tPos));
     //Selects font for the HRI characters.
     $this->buffer->write(self::GS . 'f' . chr($font));
     //Print barcode
     $this->buffer->write(self::GS . 'k' . chr($id) . chr($nlen) . $data);
 }