You are here

function BARCODE::_codaEncode in Barcode 6

1 call to BARCODE::_codaEncode()
BARCODE::_codaBarcode in ./barcode.inc.php

File

./barcode.inc.php, line 736

Class

BARCODE

Code

function _codaEncode($barnumber) {
  $encTable = array(
    "0000011",
    "0000110",
    "0001001",
    "1100000",
    "0010010",
    "1000010",
    "0100001",
    "0100100",
    "0110000",
    "1001000",
  );
  $chrTable = array(
    "-" => "0001100",
    "\$" => "0011000",
    ":" => "1000101",
    "/" => "1010001",
    "." => "1010100",
    "+" => "0011111",
    "A" => "0011010",
    "B" => "0001011",
    "C" => "0101001",
    "D" => "0001110",
  );
  $mfcStr = "";
  $widebar = str_pad("", $this->_n2w, "1", STR_PAD_LEFT);
  $widespc = str_pad("", $this->_n2w, "0", STR_PAD_LEFT);
  for ($i = 0; $i < strlen($barnumber); $i++) {
    if (preg_match("/[0-9]+/", $barnumber[$i])) {
      $tmp = $encTable[(int) $barnumber[$i]];
    }
    else {
      $tmp = $chrTable[strtoupper(trim($barnumber[$i]))];
    }
    $bar = true;
    for ($j = 0; $j < strlen($tmp); $j++) {
      if ($tmp[$j] == '0' && $bar) {
        $mfcStr .= '1';
      }
      else {
        if ($tmp[$j] == '0' && !$bar) {
          $mfcStr .= '0';
        }
        else {
          if ($tmp[$j] == '1' && $bar) {
            $mfcStr .= $widebar;
          }
          else {
            if ($tmp[$j] == '1' && !$bar) {
              $mfcStr .= $widespc;
            }
          }
        }
      }
      $bar = !$bar;
    }
    $mfcStr .= '0';
  }
  return $mfcStr;
}