예제 #1
0
 public function eat8()
 {
     $la = weixin_qrcode_QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion());
     $ln = weixin_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 = weixin_qrcode_QRinput::estimateBitsMode8($p) + weixin_qrcode_QRinput::estimateBitsModeNum($q - $p) + 4 + $ln - weixin_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 = weixin_qrcode_QRinput::estimateBitsMode8($p) + weixin_qrcode_QRinput::estimateBitsModeAn($q - $p) + 4 + $la - weixin_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;
 }
예제 #2
0
 public function estimateBitStreamSizeOfEntry($version)
 {
     $bits = 0;
     if ($version == 0) {
         $version = 1;
     }
     switch ($this->mode) {
         case QR_MODE_NUM:
             $bits = weixin_qrcode_QRinput::estimateBitsModeNum($this->size);
             break;
         case QR_MODE_AN:
             $bits = weixin_qrcode_QRinput::estimateBitsModeAn($this->size);
             break;
         case QR_MODE_8:
             $bits = weixin_qrcode_QRinput::estimateBitsMode8($this->size);
             break;
         case QR_MODE_KANJI:
             $bits = weixin_qrcode_QRinput::estimateBitsModeKanji($this->size);
             break;
         case QR_MODE_STRUCTURE:
             return STRUCTURE_HEADER_BITS;
         default:
             return 0;
     }
     $l = weixin_qrcode_QRspec::lengthIndicator($this->mode, $version);
     $m = 1 << $l;
     $num = (int) (($this->size + $m - 1) / $m);
     $bits += $num * (4 + $l);
     return $bits;
 }