示例#1
0
 public function testMakeVersionInfoBits()
 {
     // From Appendix D in JISX0510:2004 (p 68)
     $bits = new BitArray();
     $this->methods['makeVersionInfoBits']->invoke(null, Version::getVersionForNumber(7), $bits);
     $this->assertEquals(' ...XXXXX ..X..X.X ..', $bits->__toString());
 }
示例#2
0
 /**
  * @dataProvider decodeInformationProvider
  * @param        integer $expectedVersion
  * @param        integer $mask
  */
 public function testDecodeVersionInformation($expectedVersion, $mask)
 {
     $version = Version::decodeVersionInformation($mask);
     $this->assertNotNull($version);
     $this->assertEquals($expectedVersion, $version->getVersionNumber());
 }
示例#3
0
 /**
  * Chooses the best version for the input.
  *
  * @param  integer              $numInputBits
  * @param  ErrorCorrectionLevel $ecLevel
  * @return Version
  * @throws Exception\WriterException
  */
 protected static function chooseVersion($numInputBits, ErrorCorrectionLevel $ecLevel)
 {
     for ($versionNum = 1; $versionNum <= 40; $versionNum++) {
         $version = Version::getVersionForNumber($versionNum);
         $numBytes = $version->getTotalCodewords();
         $ecBlocks = $version->getEcBlocksForLevel($ecLevel);
         $numEcBytes = $ecBlocks->getTotalEcCodewords();
         $numDataBytes = $numBytes - $numEcBytes;
         $totalInputBytes = intval(($numInputBits + 8) / 8);
         if ($numDataBytes >= $totalInputBytes) {
             return $version;
         }
     }
     throw new Exception\WriterException('Data too big');
 }
示例#4
0
 /**
  * Embeds position adjustment patterns if required.
  *
  * @param  Version    $version
  * @param  ByteMatrix $matrix
  * @return void
  */
 protected static function maybeEmbedPositionAdjustmentPatterns(Version $version, ByteMatrix $matrix)
 {
     if ($version->getVersionNumber() < 2) {
         return;
     }
     $index = $version->getVersionNumber() - 1;
     $coordinates = self::$positionAdjustmentPatternCoordinateTable[$index];
     $numCoordinates = count($coordinates);
     for ($i = 0; $i < $numCoordinates; $i++) {
         for ($j = 0; $j < $numCoordinates; $j++) {
             $y = $coordinates[$i];
             $x = $coordinates[$j];
             if ($x === null || $y === null) {
                 continue;
             }
             if ($matrix->get($x, $y) === -1) {
                 self::embedPositionAdjustmentPattern($x - 2, $y - 2, $matrix);
             }
         }
     }
 }