Ejemplo n.º 1
0
 /**
  * @param Input $input
  */
 public function __construct(Input $input)
 {
     $spec = array(0, 0, 0, 0, 0);
     $this->dataCode = $input->getByteStream();
     if (is_null($this->dataCode)) {
         throw new InvalidConfigException('null input string');
     }
     Specifications::getEccSpec($input->getVersion(), $input->getErrorCorrectionLevel(), $spec);
     $this->version = $input->getVersion();
     $this->b1 = Specifications::rsBlockNum1($spec);
     $this->dataLength = Specifications::rsDataLength($spec);
     $this->eccLength = Specifications::rsEccLength($spec);
     $this->eccCode = array_fill(0, $this->eccLength, 0);
     $this->blocks = Specifications::rsBlockNum($spec);
     $ret = $this->init($spec);
     if ($ret < 0) {
         throw new \Exception('block alloc error');
     }
     $this->count = 0;
 }
Ejemplo n.º 2
0
 /**
  * @return int
  */
 public function eat8()
 {
     $la = Specifications::lengthIndicator(Enum::QR_MODE_AN, $this->input->getVersion());
     $ln = Specifications::lengthIndicator(Enum::QR_MODE_NUM, $this->input->getVersion());
     $p = 1;
     $dataStrLen = strlen($this->dataStr);
     while ($p < $dataStrLen) {
         $mode = $this->identifyMode($p);
         if ($mode == Enum::QR_MODE_KANJI) {
             break;
         }
         if ($mode == Enum::QR_MODE_NUM) {
             $q = $p;
             while (static::isDigitAt($this->dataStr, $q)) {
                 $q++;
             }
             $dif = Input::estimateBitsMode8($p) + Input::estimateBitsModeNum($q - $p) + 4 + $ln - Input::estimateBitsMode8($q);
             // - 4 - l8
             if ($dif < 0) {
                 break;
             } else {
                 $p = $q;
             }
         } else {
             if ($mode == Enum::QR_MODE_AN) {
                 $q = $p;
                 while (static::isAlNumAt($this->dataStr, $q)) {
                     $q++;
                 }
                 $dif = Input::estimateBitsMode8($p) + Input::estimateBitsModeAn($q - $p) + 4 + $la - Input::estimateBitsMode8($q);
                 // - 4 - l8
                 if ($dif < 0) {
                     break;
                 } else {
                     $p = $q;
                 }
             } else {
                 $p++;
             }
         }
     }
     $run = $p;
     $ret = $this->input->append(Enum::QR_MODE_8, $run, str_split($this->dataStr));
     if ($ret < 0) {
         return -1;
     }
     return $run;
 }
Ejemplo n.º 3
0
 /**
  * @param $version
  *
  * @return float|int|mixed
  */
 public function estimateBitStreamSizeOfEntry($version)
 {
     if ($version == 0) {
         $version = 1;
     }
     switch ($this->mode) {
         case Enum::QR_MODE_NUM:
             $bits = Input::estimateBitsModeNum($this->size);
             break;
         case Enum::QR_MODE_AN:
             $bits = Input::estimateBitsModeAn($this->size);
             break;
         case Enum::QR_MODE_8:
             $bits = Input::estimateBitsMode8($this->size);
             break;
         case Enum::QR_MODE_KANJI:
             $bits = Input::estimateBitsModeKanji($this->size);
             break;
         case Enum::QR_MODE_STRUCTURE:
             return Enum::STRUCTURE_HEADER_BITS;
         default:
             return 0;
     }
     $l = Specifications::lengthIndicator($this->mode, $version);
     $m = 1 << $l;
     $num = (int) (($this->size + $m - 1) / $m);
     $bits += $num * (4 + $l);
     return $bits;
 }
Ejemplo n.º 4
0
 /**
  * @param $string
  * @param $version
  * @param $level
  *
  * @return $this|null
  * @throws \yii\base\InvalidParamException
  */
 public function encodeString8bit($string, $version, $level)
 {
     if ($string == null) {
         throw new InvalidParamException('empty string!');
     }
     $input = new Input($version, $level);
     if ($input == null) {
         return null;
     }
     $ret = $input->append($input, Enum::QR_MODE_8, strlen($string), str_split($string));
     if ($ret < 0) {
         unset($input);
         return null;
     }
     return $this->encodeInput($input);
 }