예제 #1
0
 /**
  * @dataProvider versionProvider
  * @param        integer $versionNumber
  * @param        integer $dimension
  */
 public function testVersionForNumber($versionNumber, $dimension)
 {
     $version = Version::getVersionForNumber($versionNumber);
     $this->assertNotNull($version);
     $this->assertEquals($versionNumber, $version->getVersionNumber());
     $this->assertNotNull($version->getAlignmentPatternCenters());
     if ($versionNumber > 1) {
         $this->assertTrue(count($version->getAlignmentPatternCenters()) > 0);
     }
     $this->assertEquals($dimension, $version->getDimensionForVersion());
     $this->assertNotNull($version->getEcBlocksForLevel(new ErrorCorrectionLevel(ErrorCorrectionLevel::H)));
     $this->assertNotNull($version->getEcBlocksForLevel(new ErrorCorrectionLevel(ErrorCorrectionLevel::L)));
     $this->assertNotNull($version->getEcBlocksForLevel(new ErrorCorrectionLevel(ErrorCorrectionLevel::M)));
     $this->assertNotNull($version->getEcBlocksForLevel(new ErrorCorrectionLevel(ErrorCorrectionLevel::Q)));
     $this->assertNotNull($version->buildFunctionPattern());
 }
예제 #2
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());
 }
예제 #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');
 }