Exemple #1
0
 public function __construct(wechat_qrcode_QRinput $input)
 {
     $spec = array(0, 0, 0, 0, 0);
     $this->datacode = $input->getByteStream();
     if (is_null($this->datacode)) {
         throw new Exception('null imput string');
     }
     wechat_qrcode_QRspec::getEccSpec($input->getVersion(), $input->getErrorCorrectionLevel(), $spec);
     $this->version = $input->getVersion();
     $this->b1 = wechat_qrcode_QRspec::rsBlockNum1($spec);
     $this->dataLength = wechat_qrcode_QRspec::rsDataLength($spec);
     $this->eccLength = wechat_qrcode_QRspec::rsEccLength($spec);
     $this->ecccode = array_fill(0, $this->eccLength, 0);
     $this->blocks = wechat_qrcode_QRspec::rsBlockNum($spec);
     $ret = $this->init($spec);
     if ($ret < 0) {
         throw new Exception('block alloc error');
         return null;
     }
     $this->count = 0;
 }
Exemple #2
0
 public function encodeString8bit($string, $version, $level)
 {
     if (string == NULL) {
         throw new Exception('empty string!');
         return NULL;
     }
     $input = new wechat_qrcode_QRinput($version, $level);
     if ($input == NULL) {
         return NULL;
     }
     $ret = $input->append($input, QR_MODE_8, strlen($string), str_split($string));
     if ($ret < 0) {
         unset($input);
         return NULL;
     }
     return $this->encodeInput($input);
 }
Exemple #3
0
 public function eat8()
 {
     $la = wechat_qrcode_QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion());
     $ln = wechat_qrcode_QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion());
     $p = 1;
     $dataStrLen = strlen($this->dataStr);
     while ($p < $dataStrLen) {
         $mode = $this->identifyMode($p);
         if ($mode == QR_MODE_KANJI) {
             break;
         }
         if ($mode == QR_MODE_NUM) {
             $q = $p;
             while (self::isdigitat($this->dataStr, $q)) {
                 $q++;
             }
             $dif = wechat_qrcode_QRinput::estimateBitsMode8($p) + wechat_qrcode_QRinput::estimateBitsModeNum($q - $p) + 4 + $ln - wechat_qrcode_QRinput::estimateBitsMode8($q);
             // - 4 - l8
             if ($dif < 0) {
                 break;
             } else {
                 $p = $q;
             }
         } else {
             if ($mode == QR_MODE_AN) {
                 $q = $p;
                 while (self::isalnumat($this->dataStr, $q)) {
                     $q++;
                 }
                 $dif = wechat_qrcode_QRinput::estimateBitsMode8($p) + wechat_qrcode_QRinput::estimateBitsModeAn($q - $p) + 4 + $la - wechat_qrcode_QRinput::estimateBitsMode8($q);
                 // - 4 - l8
                 if ($dif < 0) {
                     break;
                 } else {
                     $p = $q;
                 }
             } else {
                 $p++;
             }
         }
     }
     $run = $p;
     $ret = $this->input->append(QR_MODE_8, $run, str_split($this->dataStr));
     if ($ret < 0) {
         return -1;
     }
     return $run;
 }
Exemple #4
0
 public function estimateBitStreamSizeOfEntry($version)
 {
     $bits = 0;
     if ($version == 0) {
         $version = 1;
     }
     switch ($this->mode) {
         case QR_MODE_NUM:
             $bits = wechat_qrcode_QRinput::estimateBitsModeNum($this->size);
             break;
         case QR_MODE_AN:
             $bits = wechat_qrcode_QRinput::estimateBitsModeAn($this->size);
             break;
         case QR_MODE_8:
             $bits = wechat_qrcode_QRinput::estimateBitsMode8($this->size);
             break;
         case QR_MODE_KANJI:
             $bits = wechat_qrcode_QRinput::estimateBitsModeKanji($this->size);
             break;
         case QR_MODE_STRUCTURE:
             return STRUCTURE_HEADER_BITS;
         default:
             return 0;
     }
     $l = wechat_qrcode_QRspec::lengthIndicator($this->mode, $version);
     $m = 1 << $l;
     $num = (int) (($this->size + $m - 1) / $m);
     $bits += $num * (4 + $l);
     return $bits;
 }