@@ -27,21 +27,21 @@ discard block |
||
| 27 | 27 | class QRvect { |
| 28 | 28 | |
| 29 | 29 | //---------------------------------------------------------------------- |
| 30 | - public static function eps($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE, $back_color = 0xFFFFFF, $fore_color = 0x000000, $cmyk = false) |
|
| 30 | + public static function eps($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4, $saveandprint = FALSE, $back_color = 0xFFFFFF, $fore_color = 0x000000, $cmyk = false) |
|
| 31 | 31 | { |
| 32 | 32 | $vect = self::vectEPS($frame, $pixelPerPoint, $outerFrame, $back_color, $fore_color, $cmyk); |
| 33 | 33 | |
| 34 | - if ($filename === false) { |
|
| 34 | + if ($filename===false) { |
|
| 35 | 35 | header("Content-Type: application/postscript"); |
| 36 | 36 | header('Content-Disposition: filename="qrcode.eps"'); |
| 37 | 37 | echo $vect; |
| 38 | 38 | } else { |
| 39 | - if($saveandprint===TRUE){ |
|
| 39 | + if ($saveandprint===TRUE) { |
|
| 40 | 40 | QRtools::save($vect, $filename); |
| 41 | 41 | header("Content-Type: application/postscript"); |
| 42 | 42 | header('Content-Disposition: filename="qrcode.eps"'); |
| 43 | 43 | echo $vect; |
| 44 | - }else{ |
|
| 44 | + } else { |
|
| 45 | 45 | QRtools::save($vect, $filename); |
| 46 | 46 | } |
| 47 | 47 | } |
@@ -54,8 +54,8 @@ discard block |
||
| 54 | 54 | $h = count($frame); |
| 55 | 55 | $w = strlen($frame[0]); |
| 56 | 56 | |
| 57 | - $imgW = $w + 2*$outerFrame; |
|
| 58 | - $imgH = $h + 2*$outerFrame; |
|
| 57 | + $imgW = $w + 2 * $outerFrame; |
|
| 58 | + $imgH = $h + 2 * $outerFrame; |
|
| 59 | 59 | |
| 60 | 60 | if ($cmyk) |
| 61 | 61 | { |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | |
| 113 | 113 | // set the symbol color |
| 114 | 114 | $output .= $back_color_string; |
| 115 | - $output .= '-'.$outerFrame.' -'.$outerFrame.' '.($w + 2*$outerFrame).' '.($h + 2*$outerFrame).' F'."\n"; |
|
| 115 | + $output .= '-'.$outerFrame.' -'.$outerFrame.' '.($w + 2 * $outerFrame).' '.($h + 2 * $outerFrame).' F'."\n"; |
|
| 116 | 116 | |
| 117 | 117 | |
| 118 | 118 | // set the symbol color |
@@ -120,9 +120,9 @@ discard block |
||
| 120 | 120 | |
| 121 | 121 | // Convert the matrix into pixels |
| 122 | 122 | |
| 123 | - for($i=0; $i<$h; $i++) { |
|
| 124 | - for($j=0; $j<$w; $j++) { |
|
| 125 | - if( $frame[$i][$j] == '1') { |
|
| 123 | + for ($i = 0; $i<$h; $i++) { |
|
| 124 | + for ($j = 0; $j<$w; $j++) { |
|
| 125 | + if ($frame[$i][$j]=='1') { |
|
| 126 | 126 | $y = $h - 1 - $i; |
| 127 | 127 | $x = $j; |
| 128 | 128 | $output .= $x.' '.$y.' 1 1 F'."\n"; |
@@ -131,27 +131,27 @@ discard block |
||
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | |
| 134 | - $output .='%%EOF'; |
|
| 134 | + $output .= '%%EOF'; |
|
| 135 | 135 | |
| 136 | 136 | return $output; |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | //---------------------------------------------------------------------- |
| 140 | - public static function svg($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE, $back_color, $fore_color) |
|
| 140 | + public static function svg($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4, $saveandprint = FALSE, $back_color, $fore_color) |
|
| 141 | 141 | { |
| 142 | 142 | $vect = self::vectSVG($frame, $pixelPerPoint, $outerFrame, $back_color, $fore_color); |
| 143 | 143 | |
| 144 | - if ($filename === false) { |
|
| 144 | + if ($filename===false) { |
|
| 145 | 145 | header("Content-Type: image/svg+xml"); |
| 146 | 146 | //header('Content-Disposition: attachment, filename="qrcode.svg"'); |
| 147 | 147 | echo $vect; |
| 148 | 148 | } else { |
| 149 | - if($saveandprint===TRUE){ |
|
| 149 | + if ($saveandprint===TRUE) { |
|
| 150 | 150 | QRtools::save($vect, $filename); |
| 151 | 151 | header("Content-Type: image/svg+xml"); |
| 152 | 152 | //header('Content-Disposition: filename="'.$filename.'"'); |
| 153 | 153 | echo $vect; |
| 154 | - }else{ |
|
| 154 | + } else { |
|
| 155 | 155 | QRtools::save($vect, $filename); |
| 156 | 156 | } |
| 157 | 157 | } |
@@ -164,8 +164,8 @@ discard block |
||
| 164 | 164 | $h = count($frame); |
| 165 | 165 | $w = strlen($frame[0]); |
| 166 | 166 | |
| 167 | - $imgW = $w + 2*$outerFrame; |
|
| 168 | - $imgH = $h + 2*$outerFrame; |
|
| 167 | + $imgW = $w + 2 * $outerFrame; |
|
| 168 | + $imgH = $h + 2 * $outerFrame; |
|
| 169 | 169 | |
| 170 | 170 | |
| 171 | 171 | $output = |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | '<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" xmlns:xlink="http://www.w3.org/1999/xlink" width="'.$imgW * $pixelPerPoint.'" height="'.$imgH * $pixelPerPoint.'" viewBox="0 0 '.$imgW * $pixelPerPoint.' '.$imgH * $pixelPerPoint.'">'."\n". |
| 181 | 181 | '<desc></desc>'."\n"; |
| 182 | 182 | |
| 183 | - if(!empty($back_color)) { |
|
| 183 | + if (!empty($back_color)) { |
|
| 184 | 184 | $backgroundcolor = str_pad(dechex($back_color), 6, "0", STR_PAD_LEFT); |
| 185 | 185 | $output .= '<rect width="'.$imgW * $pixelPerPoint.'" height="'.$imgH * $pixelPerPoint.'" fill="#'.$backgroundcolor.'" cx="0" cy="0" />'."\n"; |
| 186 | 186 | } |
@@ -194,9 +194,9 @@ discard block |
||
| 194 | 194 | |
| 195 | 195 | // Convert the matrix into pixels |
| 196 | 196 | |
| 197 | - for($i=0; $i<$h; $i++) { |
|
| 198 | - for($j=0; $j<$w; $j++) { |
|
| 199 | - if( $frame[$i][$j] == '1') { |
|
| 197 | + for ($i = 0; $i<$h; $i++) { |
|
| 198 | + for ($j = 0; $j<$w; $j++) { |
|
| 199 | + if ($frame[$i][$j]=='1') { |
|
| 200 | 200 | $y = ($i + $outerFrame) * $pixelPerPoint; |
| 201 | 201 | $x = ($j + $outerFrame) * $pixelPerPoint; |
| 202 | 202 | $output .= '<use x="'.$x.'" y="'.$y.'" xlink:href="#p" />'."\n"; |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | header("Content-Type: application/postscript"); |
| 42 | 42 | header('Content-Disposition: filename="qrcode.eps"'); |
| 43 | 43 | echo $vect; |
| 44 | - }else{ |
|
| 44 | + } else{ |
|
| 45 | 45 | QRtools::save($vect, $filename); |
| 46 | 46 | } |
| 47 | 47 | } |
@@ -72,8 +72,7 @@ discard block |
||
| 72 | 72 | $y = round((($back_color & 0x0000FF00) >> 8) / 255, 5); |
| 73 | 73 | $k = round(($back_color & 0x000000FF) / 255, 5); |
| 74 | 74 | $back_color_string = $c.' '.$m.' '.$y.' '.$k.' setcmykcolor'."\n"; |
| 75 | - } |
|
| 76 | - else |
|
| 75 | + } else |
|
| 77 | 76 | { |
| 78 | 77 | // convert a hexadecimal color code into decimal eps format (green = 0 1 0, blue = 0 0 1, ...) |
| 79 | 78 | $r = round((($fore_color & 0xFF0000) >> 16) / 255, 5); |
@@ -151,7 +150,7 @@ discard block |
||
| 151 | 150 | header("Content-Type: image/svg+xml"); |
| 152 | 151 | //header('Content-Disposition: filename="'.$filename.'"'); |
| 153 | 152 | echo $vect; |
| 154 | - }else{ |
|
| 153 | + } else{ |
|
| 155 | 154 | QRtools::save($vect, $filename); |
| 156 | 155 | } |
| 157 | 156 | } |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | //processing form input |
| 43 | 43 | //remember to sanitize user input in real-life solution !!! |
| 44 | 44 | $errorCorrectionLevel = 'L'; |
| 45 | - if (isset($_REQUEST['level']) && in_array($_REQUEST['level'], array('L','M','Q','H')))
|
|
| 45 | + if (isset($_REQUEST['level']) && in_array($_REQUEST['level'], array('L', 'M', 'Q', 'H')))
|
|
| 46 | 46 | $errorCorrectionLevel = $_REQUEST['level']; |
| 47 | 47 | |
| 48 | 48 | $matrixPointSize = 4; |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | if (isset($_REQUEST['data'])) {
|
| 54 | 54 | |
| 55 | 55 | //it's very important! |
| 56 | - if (trim($_REQUEST['data']) == '') |
|
| 56 | + if (trim($_REQUEST['data'])=='') |
|
| 57 | 57 | die('data cannot be empty! <a href="?">back</a>');
|
| 58 | 58 | |
| 59 | 59 | // user data |
@@ -73,17 +73,17 @@ discard block |
||
| 73 | 73 | |
| 74 | 74 | //config form |
| 75 | 75 | echo '<form action="index.php" method="post"> |
| 76 | - Data: <input name="data" value="'.(isset($_REQUEST['data'])?htmlspecialchars($_REQUEST['data']):'PHP QR Code :)').'" /> |
|
| 76 | + Data: <input name="data" value="'.(isset($_REQUEST['data']) ?htmlspecialchars($_REQUEST['data']) : 'PHP QR Code :)').'" /> |
|
| 77 | 77 | ECC: <select name="level"> |
| 78 | - <option value="L"'.(($errorCorrectionLevel=='L')?' selected':'').'>L - smallest</option> |
|
| 79 | - <option value="M"'.(($errorCorrectionLevel=='M')?' selected':'').'>M</option> |
|
| 80 | - <option value="Q"'.(($errorCorrectionLevel=='Q')?' selected':'').'>Q</option> |
|
| 81 | - <option value="H"'.(($errorCorrectionLevel=='H')?' selected':'').'>H - best</option> |
|
| 78 | + <option value="L"'.(($errorCorrectionLevel=='L') ? ' selected' : '').'>L - smallest</option> |
|
| 79 | + <option value="M"'.(($errorCorrectionLevel=='M') ? ' selected' : '').'>M</option> |
|
| 80 | + <option value="Q"'.(($errorCorrectionLevel=='Q') ? ' selected' : '').'>Q</option> |
|
| 81 | + <option value="H"'.(($errorCorrectionLevel=='H') ? ' selected' : '').'>H - best</option> |
|
| 82 | 82 | </select> |
| 83 | 83 | Size: <select name="size">'; |
| 84 | 84 | |
| 85 | - for($i=1;$i<=10;$i++) |
|
| 86 | - echo '<option value="'.$i.'"'.(($matrixPointSize==$i)?' selected':'').'>'.$i.'</option>'; |
|
| 85 | + for ($i = 1; $i<=10; $i++) |
|
| 86 | + echo '<option value="'.$i.'"'.(($matrixPointSize==$i) ? ' selected' : '').'>'.$i.'</option>'; |
|
| 87 | 87 | |
| 88 | 88 | echo '</select> |
| 89 | 89 | <input type="submit" value="GENERATE"></form><hr/>'; |
@@ -33,8 +33,9 @@ discard block |
||
| 33 | 33 | include "qrlib.php"; |
| 34 | 34 | |
| 35 | 35 | //ofcourse we need rights to create temp dir |
| 36 | - if (!file_exists($PNG_TEMP_DIR)) |
|
| 37 | - mkdir($PNG_TEMP_DIR); |
|
| 36 | + if (!file_exists($PNG_TEMP_DIR)) {
|
|
| 37 | + mkdir($PNG_TEMP_DIR); |
|
| 38 | + } |
|
| 38 | 39 | |
| 39 | 40 | |
| 40 | 41 | $filename = $PNG_TEMP_DIR.'test.png'; |
@@ -42,19 +43,22 @@ discard block |
||
| 42 | 43 | //processing form input |
| 43 | 44 | //remember to sanitize user input in real-life solution !!! |
| 44 | 45 | $errorCorrectionLevel = 'L'; |
| 45 | - if (isset($_REQUEST['level']) && in_array($_REQUEST['level'], array('L','M','Q','H')))
|
|
| 46 | - $errorCorrectionLevel = $_REQUEST['level']; |
|
| 46 | + if (isset($_REQUEST['level']) && in_array($_REQUEST['level'], array('L','M','Q','H'))) {
|
|
| 47 | + $errorCorrectionLevel = $_REQUEST['level']; |
|
| 48 | + } |
|
| 47 | 49 | |
| 48 | 50 | $matrixPointSize = 4; |
| 49 | - if (isset($_REQUEST['size'])) |
|
| 50 | - $matrixPointSize = min(max((int)$_REQUEST['size'], 1), 10); |
|
| 51 | + if (isset($_REQUEST['size'])) {
|
|
| 52 | + $matrixPointSize = min(max((int)$_REQUEST['size'], 1), 10); |
|
| 53 | + } |
|
| 51 | 54 | |
| 52 | 55 | |
| 53 | 56 | if (isset($_REQUEST['data'])) {
|
| 54 | 57 | |
| 55 | 58 | //it's very important! |
| 56 | - if (trim($_REQUEST['data']) == '') |
|
| 57 | - die('data cannot be empty! <a href="?">back</a>');
|
|
| 59 | + if (trim($_REQUEST['data']) == '') {
|
|
| 60 | + die('data cannot be empty! <a href="?">back</a>');
|
|
| 61 | + } |
|
| 58 | 62 | |
| 59 | 63 | // user data |
| 60 | 64 | $filename = $PNG_TEMP_DIR.'test'.md5($_REQUEST['data'].'|'.$errorCorrectionLevel.'|'.$matrixPointSize).'.png'; |
@@ -82,8 +86,9 @@ discard block |
||
| 82 | 86 | </select> |
| 83 | 87 | Size: <select name="size">'; |
| 84 | 88 | |
| 85 | - for($i=1;$i<=10;$i++) |
|
| 86 | - echo '<option value="'.$i.'"'.(($matrixPointSize==$i)?' selected':'').'>'.$i.'</option>'; |
|
| 89 | + for($i=1;$i<=10;$i++) {
|
|
| 90 | + echo '<option value="'.$i.'"'.(($matrixPointSize==$i)?' selected':'').'>'.$i.'</option>'; |
|
| 91 | + } |
|
| 87 | 92 | |
| 88 | 93 | echo '</select> |
| 89 | 94 | <input type="submit" value="GENERATE"></form><hr/>'; |
@@ -26,29 +26,29 @@ |
||
| 26 | 26 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 27 | 27 | */ |
| 28 | 28 | |
| 29 | - // Encoding modes |
|
| 29 | + // Encoding modes |
|
| 30 | 30 | |
| 31 | - define('QR_MODE_NUL', -1);
|
|
| 32 | - define('QR_MODE_NUM', 0);
|
|
| 33 | - define('QR_MODE_AN', 1);
|
|
| 34 | - define('QR_MODE_8', 2);
|
|
| 35 | - define('QR_MODE_KANJI', 3);
|
|
| 36 | - define('QR_MODE_STRUCTURE', 4);
|
|
| 31 | + define('QR_MODE_NUL', -1);
|
|
| 32 | + define('QR_MODE_NUM', 0);
|
|
| 33 | + define('QR_MODE_AN', 1);
|
|
| 34 | + define('QR_MODE_8', 2);
|
|
| 35 | + define('QR_MODE_KANJI', 3);
|
|
| 36 | + define('QR_MODE_STRUCTURE', 4);
|
|
| 37 | 37 | |
| 38 | - // Levels of error correction. |
|
| 38 | + // Levels of error correction. |
|
| 39 | 39 | |
| 40 | - define('QR_ECLEVEL_L', 0);
|
|
| 41 | - define('QR_ECLEVEL_M', 1);
|
|
| 42 | - define('QR_ECLEVEL_Q', 2);
|
|
| 43 | - define('QR_ECLEVEL_H', 3);
|
|
| 40 | + define('QR_ECLEVEL_L', 0);
|
|
| 41 | + define('QR_ECLEVEL_M', 1);
|
|
| 42 | + define('QR_ECLEVEL_Q', 2);
|
|
| 43 | + define('QR_ECLEVEL_H', 3);
|
|
| 44 | 44 | |
| 45 | - // Supported output formats |
|
| 45 | + // Supported output formats |
|
| 46 | 46 | |
| 47 | - define('QR_FORMAT_TEXT', 0);
|
|
| 48 | - define('QR_FORMAT_PNG', 1);
|
|
| 47 | + define('QR_FORMAT_TEXT', 0);
|
|
| 48 | + define('QR_FORMAT_PNG', 1);
|
|
| 49 | 49 | |
| 50 | - class qrstr {
|
|
| 51 | - public static function set(&$srctab, $x, $y, $repl, $replLen = false) {
|
|
| 52 | - $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl)); |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | 50 | \ No newline at end of file |
| 51 | + class qrstr {
|
|
| 52 | + public static function set(&$srctab, $x, $y, $repl, $replLen = false) {
|
|
| 53 | + $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl)); |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | 56 | \ No newline at end of file |
@@ -45,10 +45,10 @@ |
||
| 45 | 45 | // Supported output formats |
| 46 | 46 | |
| 47 | 47 | define('QR_FORMAT_TEXT', 0);
|
| 48 | - define('QR_FORMAT_PNG', 1);
|
|
| 48 | + define('QR_FORMAT_PNG', 1);
|
|
| 49 | 49 | |
| 50 | 50 | class qrstr {
|
| 51 | 51 | public static function set(&$srctab, $x, $y, $repl, $replLen = false) {
|
| 52 | - $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl)); |
|
| 52 | + $srctab[$y] = substr_replace($srctab[$y], ($replLen!==false) ?substr($repl, 0, $replLen) : $repl, $x, ($replLen!==false) ? $replLen : strlen($repl)); |
|
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | \ No newline at end of file |
@@ -75,32 +75,32 @@ discard block |
||
| 75 | 75 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 76 | 76 | */ |
| 77 | 77 | |
| 78 | - // Encoding modes |
|
| 78 | + // Encoding modes |
|
| 79 | 79 | |
| 80 | - define('QR_MODE_NUL', -1);
|
|
| 81 | - define('QR_MODE_NUM', 0);
|
|
| 82 | - define('QR_MODE_AN', 1);
|
|
| 83 | - define('QR_MODE_8', 2);
|
|
| 84 | - define('QR_MODE_KANJI', 3);
|
|
| 85 | - define('QR_MODE_STRUCTURE', 4);
|
|
| 86 | - |
|
| 87 | - // Levels of error correction. |
|
| 88 | - |
|
| 89 | - define('QR_ECLEVEL_L', 0);
|
|
| 90 | - define('QR_ECLEVEL_M', 1);
|
|
| 91 | - define('QR_ECLEVEL_Q', 2);
|
|
| 92 | - define('QR_ECLEVEL_H', 3);
|
|
| 80 | + define('QR_MODE_NUL', -1);
|
|
| 81 | + define('QR_MODE_NUM', 0);
|
|
| 82 | + define('QR_MODE_AN', 1);
|
|
| 83 | + define('QR_MODE_8', 2);
|
|
| 84 | + define('QR_MODE_KANJI', 3);
|
|
| 85 | + define('QR_MODE_STRUCTURE', 4);
|
|
| 86 | + |
|
| 87 | + // Levels of error correction. |
|
| 88 | + |
|
| 89 | + define('QR_ECLEVEL_L', 0);
|
|
| 90 | + define('QR_ECLEVEL_M', 1);
|
|
| 91 | + define('QR_ECLEVEL_Q', 2);
|
|
| 92 | + define('QR_ECLEVEL_H', 3);
|
|
| 93 | 93 | |
| 94 | - // Supported output formats |
|
| 94 | + // Supported output formats |
|
| 95 | 95 | |
| 96 | - define('QR_FORMAT_TEXT', 0);
|
|
| 97 | - define('QR_FORMAT_PNG', 1);
|
|
| 96 | + define('QR_FORMAT_TEXT', 0);
|
|
| 97 | + define('QR_FORMAT_PNG', 1);
|
|
| 98 | 98 | |
| 99 | - class qrstr {
|
|
| 100 | - public static function set(&$srctab, $x, $y, $repl, $replLen = false) {
|
|
| 101 | - $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl)); |
|
| 102 | - } |
|
| 103 | - } |
|
| 99 | + class qrstr {
|
|
| 100 | + public static function set(&$srctab, $x, $y, $repl, $replLen = false) {
|
|
| 101 | + $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl)); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | 105 | |
| 106 | 106 | |
@@ -212,9 +212,9 @@ discard block |
||
| 212 | 212 | //---------------------------------------------------------------------- |
| 213 | 213 | public static function buildCache() |
| 214 | 214 | { |
| 215 | - QRtools::markTime('before_build_cache'); |
|
| 215 | + QRtools::markTime('before_build_cache'); |
|
| 216 | 216 | |
| 217 | - $mask = new QRmask(); |
|
| 217 | + $mask = new QRmask(); |
|
| 218 | 218 | for ($a=1; $a <= QRSPEC_VERSION_MAX; $a++) { |
| 219 | 219 | $frame = QRspec::newFrame($a); |
| 220 | 220 | if (QR_IMAGE) { |
@@ -222,13 +222,13 @@ discard block |
||
| 222 | 222 | QRimage::png(self::binarize($frame), $fileName, 1, 0); |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | - $width = count($frame); |
|
| 226 | - $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); |
|
| 227 | - for ($maskNo=0; $maskNo<8; $maskNo++) |
|
| 228 | - $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true); |
|
| 225 | + $width = count($frame); |
|
| 226 | + $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); |
|
| 227 | + for ($maskNo=0; $maskNo<8; $maskNo++) |
|
| 228 | + $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | - QRtools::markTime('after_build_cache'); |
|
| 231 | + QRtools::markTime('after_build_cache'); |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | //---------------------------------------------------------------------- |
@@ -661,10 +661,10 @@ discard block |
||
| 661 | 661 | |
| 662 | 662 | // Version information pattern ----------------------------------------- |
| 663 | 663 | |
| 664 | - // Version information pattern (BCH coded). |
|
| 664 | + // Version information pattern (BCH coded). |
|
| 665 | 665 | // See Table 1 in Appendix D (pp.68) of JIS X0510:2004. |
| 666 | 666 | |
| 667 | - // size: [QRSPEC_VERSION_MAX - 6] |
|
| 667 | + // size: [QRSPEC_VERSION_MAX - 6] |
|
| 668 | 668 | |
| 669 | 669 | public static $versionPattern = array( |
| 670 | 670 | 0x07c94, 0x085bc, 0x09a99, 0x0a4d3, 0x0bbf6, 0x0c762, 0x0d847, 0x0e60d, |
@@ -1461,7 +1461,7 @@ discard block |
||
| 1461 | 1461 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 1462 | 1462 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 1463 | 1463 | 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, |
| 1464 | - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, |
|
| 1464 | + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, |
|
| 1465 | 1465 | -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, |
| 1466 | 1466 | 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, |
| 1467 | 1467 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
@@ -2523,17 +2523,17 @@ discard block |
||
| 2523 | 2523 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 2524 | 2524 | */ |
| 2525 | 2525 | |
| 2526 | - define('N1', 3);
|
|
| 2527 | - define('N2', 3);
|
|
| 2528 | - define('N3', 40);
|
|
| 2529 | - define('N4', 10);
|
|
| 2526 | + define('N1', 3);
|
|
| 2527 | + define('N2', 3);
|
|
| 2528 | + define('N3', 40);
|
|
| 2529 | + define('N4', 10);
|
|
| 2530 | 2530 | |
| 2531 | - class QRmask {
|
|
| 2531 | + class QRmask {
|
|
| 2532 | 2532 | |
| 2533 | - public $runLength = array(); |
|
| 2533 | + public $runLength = array(); |
|
| 2534 | 2534 | |
| 2535 | - //---------------------------------------------------------------------- |
|
| 2536 | - public function __construct() |
|
| 2535 | + //---------------------------------------------------------------------- |
|
| 2536 | + public function __construct() |
|
| 2537 | 2537 | {
|
| 2538 | 2538 | $this->runLength = array_fill(0, QRSPEC_WIDTH_MAX + 1, 0); |
| 2539 | 2539 | } |
@@ -94,11 +94,11 @@ discard block |
||
| 94 | 94 | // Supported output formats |
| 95 | 95 | |
| 96 | 96 | define('QR_FORMAT_TEXT', 0);
|
| 97 | - define('QR_FORMAT_PNG', 1);
|
|
| 97 | + define('QR_FORMAT_PNG', 1);
|
|
| 98 | 98 | |
| 99 | 99 | class qrstr {
|
| 100 | 100 | public static function set(&$srctab, $x, $y, $repl, $replLen = false) {
|
| 101 | - $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl)); |
|
| 101 | + $srctab[$y] = substr_replace($srctab[$y], ($replLen!==false) ?substr($repl, 0, $replLen) : $repl, $x, ($replLen!==false) ? $replLen : strlen($repl)); |
|
| 102 | 102 | } |
| 103 | 103 | } |
| 104 | 104 | |
@@ -115,15 +115,15 @@ discard block |
||
| 115 | 115 | * Config file, tuned-up for merged verion |
| 116 | 116 | */ |
| 117 | 117 | |
| 118 | - define('QR_CACHEABLE', false); // use cache - more disk reads but less CPU power, masks and format templates are stored there
|
|
| 119 | - define('QR_CACHE_DIR', false); // used when QR_CACHEABLE === true
|
|
| 120 | - define('QR_LOG_DIR', false); // default error logs dir
|
|
| 118 | + define('QR_CACHEABLE', false); // use cache - more disk reads but less CPU power, masks and format templates are stored there
|
|
| 119 | + define('QR_CACHE_DIR', false); // used when QR_CACHEABLE === true
|
|
| 120 | + define('QR_LOG_DIR', false); // default error logs dir
|
|
| 121 | 121 | |
| 122 | - define('QR_FIND_BEST_MASK', true); // if true, estimates best mask (spec. default, but extremally slow; set to false to significant performance boost but (propably) worst quality code
|
|
| 123 | - define('QR_FIND_FROM_RANDOM', 2); // if false, checks all masks available, otherwise value tells count of masks need to be checked, mask id are got randomly
|
|
| 124 | - define('QR_DEFAULT_MASK', 2); // when QR_FIND_BEST_MASK === false
|
|
| 122 | + define('QR_FIND_BEST_MASK', true); // if true, estimates best mask (spec. default, but extremally slow; set to false to significant performance boost but (propably) worst quality code
|
|
| 123 | + define('QR_FIND_FROM_RANDOM', 2); // if false, checks all masks available, otherwise value tells count of masks need to be checked, mask id are got randomly
|
|
| 124 | + define('QR_DEFAULT_MASK', 2); // when QR_FIND_BEST_MASK === false
|
|
| 125 | 125 | |
| 126 | - define('QR_PNG_MAXIMUM_SIZE', 1024); // maximum allowed png image width (in pixels), tune to make sure GD and PHP can handle such big images
|
|
| 126 | + define('QR_PNG_MAXIMUM_SIZE', 1024); // maximum allowed png image width (in pixels), tune to make sure GD and PHP can handle such big images
|
|
| 127 | 127 | |
| 128 | 128 | |
| 129 | 129 | |
@@ -164,8 +164,8 @@ discard block |
||
| 164 | 164 | $len = count($frame); |
| 165 | 165 | foreach ($frame as &$frameLine) { |
| 166 | 166 | |
| 167 | - for($i=0; $i<$len; $i++) { |
|
| 168 | - $frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0'; |
|
| 167 | + for ($i = 0; $i<$len; $i++) { |
|
| 168 | + $frameLine[$i] = (ord($frameLine[$i]) & 1) ? '1' : '0'; |
|
| 169 | 169 | } |
| 170 | 170 | } |
| 171 | 171 | |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | |
| 183 | 183 | $eccLevel = 'L'; |
| 184 | 184 | |
| 185 | - if (count($mode) > 1) { |
|
| 185 | + if (count($mode)>1) { |
|
| 186 | 186 | $eccLevel = $mode[1]; |
| 187 | 187 | } |
| 188 | 188 | |
@@ -195,8 +195,8 @@ discard block |
||
| 195 | 195 | |
| 196 | 196 | foreach ($qrTab as $line) { |
| 197 | 197 | $arrAdd = array(); |
| 198 | - foreach(str_split($line) as $char) |
|
| 199 | - $arrAdd[] = ($char=='1')?1:0; |
|
| 198 | + foreach (str_split($line) as $char) |
|
| 199 | + $arrAdd[] = ($char=='1') ? 1 : 0; |
|
| 200 | 200 | $barcode_array['bcode'][] = $arrAdd; |
| 201 | 201 | } |
| 202 | 202 | |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | QRtools::markTime('before_build_cache'); |
| 216 | 216 | |
| 217 | 217 | $mask = new QRmask(); |
| 218 | - for ($a=1; $a <= QRSPEC_VERSION_MAX; $a++) { |
|
| 218 | + for ($a = 1; $a<=QRSPEC_VERSION_MAX; $a++) { |
|
| 219 | 219 | $frame = QRspec::newFrame($a); |
| 220 | 220 | if (QR_IMAGE) { |
| 221 | 221 | $fileName = QR_CACHE_DIR.'frame_'.$a.'.png'; |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | |
| 225 | 225 | $width = count($frame); |
| 226 | 226 | $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); |
| 227 | - for ($maskNo=0; $maskNo<8; $maskNo++) |
|
| 227 | + for ($maskNo = 0; $maskNo<8; $maskNo++) |
|
| 228 | 228 | $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true); |
| 229 | 229 | } |
| 230 | 230 | |
@@ -234,9 +234,9 @@ discard block |
||
| 234 | 234 | //---------------------------------------------------------------------- |
| 235 | 235 | public static function log($outfile, $err) |
| 236 | 236 | { |
| 237 | - if (QR_LOG_DIR !== false) { |
|
| 238 | - if ($err != '') { |
|
| 239 | - if ($outfile !== false) { |
|
| 237 | + if (QR_LOG_DIR!==false) { |
|
| 238 | + if ($err!='') { |
|
| 239 | + if ($outfile!==false) { |
|
| 240 | 240 | file_put_contents(QR_LOG_DIR.basename($outfile).'-errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND); |
| 241 | 241 | } else { |
| 242 | 242 | file_put_contents(QR_LOG_DIR.'errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND); |
@@ -249,8 +249,8 @@ discard block |
||
| 249 | 249 | public static function dumpMask($frame) |
| 250 | 250 | { |
| 251 | 251 | $width = count($frame); |
| 252 | - for($y=0;$y<$width;$y++) { |
|
| 253 | - for($x=0;$x<$width;$x++) { |
|
| 252 | + for ($y = 0; $y<$width; $y++) { |
|
| 253 | + for ($x = 0; $x<$width; $x++) { |
|
| 254 | 254 | echo ord($frame[$y][$x]).','; |
| 255 | 255 | } |
| 256 | 256 | } |
@@ -281,9 +281,9 @@ discard block |
||
| 281 | 281 | <thead><tr style="border-bottom:1px solid silver"><td colspan="2" style="text-align:center">BENCHMARK</td></tr></thead> |
| 282 | 282 | <tbody>'; |
| 283 | 283 | |
| 284 | - foreach($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) { |
|
| 285 | - if ($p > 0) { |
|
| 286 | - echo '<tr><th style="text-align:right">till '.$markerId.': </th><td>'.number_format($thisTime-$lastTime, 6).'s</td></tr>'; |
|
| 284 | + foreach ($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) { |
|
| 285 | + if ($p>0) { |
|
| 286 | + echo '<tr><th style="text-align:right">till '.$markerId.': </th><td>'.number_format($thisTime - $lastTime, 6).'s</td></tr>'; |
|
| 287 | 287 | } else { |
| 288 | 288 | $startTime = $thisTime; |
| 289 | 289 | } |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | echo '</tbody><tfoot> |
| 296 | - <tr style="border-top:2px solid black"><th style="text-align:right">TOTAL: </th><td>'.number_format($lastTime-$startTime, 6).'s</td></tr> |
|
| 296 | + <tr style="border-top:2px solid black"><th style="text-align:right">TOTAL: </th><td>'.number_format($lastTime - $startTime, 6).'s</td></tr> |
|
| 297 | 297 | </tfoot> |
| 298 | 298 | </table>'; |
| 299 | 299 | } |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | fclose($handle); |
| 307 | 307 | return true; |
| 308 | 308 | } catch (Exception $e) { |
| 309 | - echo 'Exception reçue : ', $e->getMessage(), "\n"; |
|
| 309 | + echo 'Exception reçue : ', $e->getMessage(), "\n"; |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | } |
@@ -358,57 +358,57 @@ discard block |
||
| 358 | 358 | */ |
| 359 | 359 | |
| 360 | 360 | define('QRSPEC_VERSION_MAX', 40);
|
| 361 | - define('QRSPEC_WIDTH_MAX', 177);
|
|
| 361 | + define('QRSPEC_WIDTH_MAX', 177);
|
|
| 362 | 362 | |
| 363 | - define('QRCAP_WIDTH', 0);
|
|
| 364 | - define('QRCAP_WORDS', 1);
|
|
| 365 | - define('QRCAP_REMINDER', 2);
|
|
| 366 | - define('QRCAP_EC', 3);
|
|
| 363 | + define('QRCAP_WIDTH', 0);
|
|
| 364 | + define('QRCAP_WORDS', 1);
|
|
| 365 | + define('QRCAP_REMINDER', 2);
|
|
| 366 | + define('QRCAP_EC', 3);
|
|
| 367 | 367 | |
| 368 | 368 | class QRspec {
|
| 369 | 369 | |
| 370 | 370 | public static $capacity = array( |
| 371 | - array( 0, 0, 0, array( 0, 0, 0, 0)), |
|
| 372 | - array( 21, 26, 0, array( 7, 10, 13, 17)), // 1 |
|
| 373 | - array( 25, 44, 7, array( 10, 16, 22, 28)), |
|
| 374 | - array( 29, 70, 7, array( 15, 26, 36, 44)), |
|
| 375 | - array( 33, 100, 7, array( 20, 36, 52, 64)), |
|
| 376 | - array( 37, 134, 7, array( 26, 48, 72, 88)), // 5 |
|
| 377 | - array( 41, 172, 7, array( 36, 64, 96, 112)), |
|
| 378 | - array( 45, 196, 0, array( 40, 72, 108, 130)), |
|
| 379 | - array( 49, 242, 0, array( 48, 88, 132, 156)), |
|
| 380 | - array( 53, 292, 0, array( 60, 110, 160, 192)), |
|
| 381 | - array( 57, 346, 0, array( 72, 130, 192, 224)), //10 |
|
| 382 | - array( 61, 404, 0, array( 80, 150, 224, 264)), |
|
| 383 | - array( 65, 466, 0, array( 96, 176, 260, 308)), |
|
| 384 | - array( 69, 532, 0, array( 104, 198, 288, 352)), |
|
| 385 | - array( 73, 581, 3, array( 120, 216, 320, 384)), |
|
| 386 | - array( 77, 655, 3, array( 132, 240, 360, 432)), //15 |
|
| 387 | - array( 81, 733, 3, array( 144, 280, 408, 480)), |
|
| 388 | - array( 85, 815, 3, array( 168, 308, 448, 532)), |
|
| 389 | - array( 89, 901, 3, array( 180, 338, 504, 588)), |
|
| 390 | - array( 93, 991, 3, array( 196, 364, 546, 650)), |
|
| 391 | - array( 97, 1085, 3, array( 224, 416, 600, 700)), //20 |
|
| 392 | - array(101, 1156, 4, array( 224, 442, 644, 750)), |
|
| 393 | - array(105, 1258, 4, array( 252, 476, 690, 816)), |
|
| 394 | - array(109, 1364, 4, array( 270, 504, 750, 900)), |
|
| 395 | - array(113, 1474, 4, array( 300, 560, 810, 960)), |
|
| 396 | - array(117, 1588, 4, array( 312, 588, 870, 1050)), //25 |
|
| 397 | - array(121, 1706, 4, array( 336, 644, 952, 1110)), |
|
| 398 | - array(125, 1828, 4, array( 360, 700, 1020, 1200)), |
|
| 399 | - array(129, 1921, 3, array( 390, 728, 1050, 1260)), |
|
| 400 | - array(133, 2051, 3, array( 420, 784, 1140, 1350)), |
|
| 401 | - array(137, 2185, 3, array( 450, 812, 1200, 1440)), //30 |
|
| 402 | - array(141, 2323, 3, array( 480, 868, 1290, 1530)), |
|
| 403 | - array(145, 2465, 3, array( 510, 924, 1350, 1620)), |
|
| 404 | - array(149, 2611, 3, array( 540, 980, 1440, 1710)), |
|
| 405 | - array(153, 2761, 3, array( 570, 1036, 1530, 1800)), |
|
| 406 | - array(157, 2876, 0, array( 570, 1064, 1590, 1890)), //35 |
|
| 407 | - array(161, 3034, 0, array( 600, 1120, 1680, 1980)), |
|
| 408 | - array(165, 3196, 0, array( 630, 1204, 1770, 2100)), |
|
| 409 | - array(169, 3362, 0, array( 660, 1260, 1860, 2220)), |
|
| 410 | - array(173, 3532, 0, array( 720, 1316, 1950, 2310)), |
|
| 411 | - array(177, 3706, 0, array( 750, 1372, 2040, 2430)) //40 |
|
| 371 | + array(0, 0, 0, array(0, 0, 0, 0)), |
|
| 372 | + array(21, 26, 0, array(7, 10, 13, 17)), // 1 |
|
| 373 | + array(25, 44, 7, array(10, 16, 22, 28)), |
|
| 374 | + array(29, 70, 7, array(15, 26, 36, 44)), |
|
| 375 | + array(33, 100, 7, array(20, 36, 52, 64)), |
|
| 376 | + array(37, 134, 7, array(26, 48, 72, 88)), // 5 |
|
| 377 | + array(41, 172, 7, array(36, 64, 96, 112)), |
|
| 378 | + array(45, 196, 0, array(40, 72, 108, 130)), |
|
| 379 | + array(49, 242, 0, array(48, 88, 132, 156)), |
|
| 380 | + array(53, 292, 0, array(60, 110, 160, 192)), |
|
| 381 | + array(57, 346, 0, array(72, 130, 192, 224)), //10 |
|
| 382 | + array(61, 404, 0, array(80, 150, 224, 264)), |
|
| 383 | + array(65, 466, 0, array(96, 176, 260, 308)), |
|
| 384 | + array(69, 532, 0, array(104, 198, 288, 352)), |
|
| 385 | + array(73, 581, 3, array(120, 216, 320, 384)), |
|
| 386 | + array(77, 655, 3, array(132, 240, 360, 432)), //15 |
|
| 387 | + array(81, 733, 3, array(144, 280, 408, 480)), |
|
| 388 | + array(85, 815, 3, array(168, 308, 448, 532)), |
|
| 389 | + array(89, 901, 3, array(180, 338, 504, 588)), |
|
| 390 | + array(93, 991, 3, array(196, 364, 546, 650)), |
|
| 391 | + array(97, 1085, 3, array(224, 416, 600, 700)), //20 |
|
| 392 | + array(101, 1156, 4, array(224, 442, 644, 750)), |
|
| 393 | + array(105, 1258, 4, array(252, 476, 690, 816)), |
|
| 394 | + array(109, 1364, 4, array(270, 504, 750, 900)), |
|
| 395 | + array(113, 1474, 4, array(300, 560, 810, 960)), |
|
| 396 | + array(117, 1588, 4, array(312, 588, 870, 1050)), //25 |
|
| 397 | + array(121, 1706, 4, array(336, 644, 952, 1110)), |
|
| 398 | + array(125, 1828, 4, array(360, 700, 1020, 1200)), |
|
| 399 | + array(129, 1921, 3, array(390, 728, 1050, 1260)), |
|
| 400 | + array(133, 2051, 3, array(420, 784, 1140, 1350)), |
|
| 401 | + array(137, 2185, 3, array(450, 812, 1200, 1440)), //30 |
|
| 402 | + array(141, 2323, 3, array(480, 868, 1290, 1530)), |
|
| 403 | + array(145, 2465, 3, array(510, 924, 1350, 1620)), |
|
| 404 | + array(149, 2611, 3, array(540, 980, 1440, 1710)), |
|
| 405 | + array(153, 2761, 3, array(570, 1036, 1530, 1800)), |
|
| 406 | + array(157, 2876, 0, array(570, 1064, 1590, 1890)), //35 |
|
| 407 | + array(161, 3034, 0, array(600, 1120, 1680, 1980)), |
|
| 408 | + array(165, 3196, 0, array(630, 1204, 1770, 2100)), |
|
| 409 | + array(169, 3362, 0, array(660, 1260, 1860, 2220)), |
|
| 410 | + array(173, 3532, 0, array(720, 1316, 1950, 2310)), |
|
| 411 | + array(177, 3706, 0, array(750, 1372, 2040, 2430)) //40 |
|
| 412 | 412 | ); |
| 413 | 413 | |
| 414 | 414 | //---------------------------------------------------------------------- |
@@ -439,9 +439,9 @@ discard block |
||
| 439 | 439 | public static function getMinimumVersion($size, $level) |
| 440 | 440 | {
|
| 441 | 441 | |
| 442 | - for($i=1; $i<= QRSPEC_VERSION_MAX; $i++) {
|
|
| 443 | - $words = self::$capacity[$i][QRCAP_WORDS] - self::$capacity[$i][QRCAP_EC][$level]; |
|
| 444 | - if($words >= $size) |
|
| 442 | + for ($i = 1; $i<=QRSPEC_VERSION_MAX; $i++) {
|
|
| 443 | + $words = self::$capacity[$i][QRCAP_WORDS] - self::$capacity[$i][QRCAP_EC][$level]; |
|
| 444 | + if ($words>=$size) |
|
| 445 | 445 | return $i; |
| 446 | 446 | } |
| 447 | 447 | |
@@ -452,20 +452,20 @@ discard block |
||
| 452 | 452 | |
| 453 | 453 | public static $lengthTableBits = array( |
| 454 | 454 | array(10, 12, 14), |
| 455 | - array( 9, 11, 13), |
|
| 456 | - array( 8, 16, 16), |
|
| 457 | - array( 8, 10, 12) |
|
| 455 | + array(9, 11, 13), |
|
| 456 | + array(8, 16, 16), |
|
| 457 | + array(8, 10, 12) |
|
| 458 | 458 | ); |
| 459 | 459 | |
| 460 | 460 | //---------------------------------------------------------------------- |
| 461 | 461 | public static function lengthIndicator($mode, $version) |
| 462 | 462 | {
|
| 463 | - if ($mode == QR_MODE_STRUCTURE) |
|
| 463 | + if ($mode==QR_MODE_STRUCTURE) |
|
| 464 | 464 | return 0; |
| 465 | 465 | |
| 466 | - if ($version <= 9) {
|
|
| 466 | + if ($version<=9) {
|
|
| 467 | 467 | $l = 0; |
| 468 | - } else if ($version <= 26) {
|
|
| 468 | + } else if ($version<=26) {
|
|
| 469 | 469 | $l = 1; |
| 470 | 470 | } else {
|
| 471 | 471 | $l = 2; |
@@ -477,12 +477,12 @@ discard block |
||
| 477 | 477 | //---------------------------------------------------------------------- |
| 478 | 478 | public static function maximumWords($mode, $version) |
| 479 | 479 | {
|
| 480 | - if($mode == QR_MODE_STRUCTURE) |
|
| 480 | + if ($mode==QR_MODE_STRUCTURE) |
|
| 481 | 481 | return 3; |
| 482 | 482 | |
| 483 | - if($version <= 9) {
|
|
| 483 | + if ($version<=9) {
|
|
| 484 | 484 | $l = 0; |
| 485 | - } else if($version <= 26) {
|
|
| 485 | + } else if ($version<=26) {
|
|
| 486 | 486 | $l = 1; |
| 487 | 487 | } else {
|
| 488 | 488 | $l = 2; |
@@ -491,7 +491,7 @@ discard block |
||
| 491 | 491 | $bits = self::$lengthTableBits[$mode][$l]; |
| 492 | 492 | $words = (1 << $bits) - 1; |
| 493 | 493 | |
| 494 | - if($mode == QR_MODE_KANJI) {
|
|
| 494 | + if ($mode==QR_MODE_KANJI) {
|
|
| 495 | 495 | $words *= 2; // the number of bytes is required |
| 496 | 496 | } |
| 497 | 497 | |
@@ -503,47 +503,47 @@ discard block |
||
| 503 | 503 | // See Table 12-16 (pp.30-36), JIS X0510:2004. |
| 504 | 504 | |
| 505 | 505 | public static $eccTable = array( |
| 506 | - array(array( 0, 0), array( 0, 0), array( 0, 0), array( 0, 0)), |
|
| 507 | - array(array( 1, 0), array( 1, 0), array( 1, 0), array( 1, 0)), // 1 |
|
| 508 | - array(array( 1, 0), array( 1, 0), array( 1, 0), array( 1, 0)), |
|
| 509 | - array(array( 1, 0), array( 1, 0), array( 2, 0), array( 2, 0)), |
|
| 510 | - array(array( 1, 0), array( 2, 0), array( 2, 0), array( 4, 0)), |
|
| 511 | - array(array( 1, 0), array( 2, 0), array( 2, 2), array( 2, 2)), // 5 |
|
| 512 | - array(array( 2, 0), array( 4, 0), array( 4, 0), array( 4, 0)), |
|
| 513 | - array(array( 2, 0), array( 4, 0), array( 2, 4), array( 4, 1)), |
|
| 514 | - array(array( 2, 0), array( 2, 2), array( 4, 2), array( 4, 2)), |
|
| 515 | - array(array( 2, 0), array( 3, 2), array( 4, 4), array( 4, 4)), |
|
| 516 | - array(array( 2, 2), array( 4, 1), array( 6, 2), array( 6, 2)), //10 |
|
| 517 | - array(array( 4, 0), array( 1, 4), array( 4, 4), array( 3, 8)), |
|
| 518 | - array(array( 2, 2), array( 6, 2), array( 4, 6), array( 7, 4)), |
|
| 519 | - array(array( 4, 0), array( 8, 1), array( 8, 4), array(12, 4)), |
|
| 520 | - array(array( 3, 1), array( 4, 5), array(11, 5), array(11, 5)), |
|
| 521 | - array(array( 5, 1), array( 5, 5), array( 5, 7), array(11, 7)), //15 |
|
| 522 | - array(array( 5, 1), array( 7, 3), array(15, 2), array( 3, 13)), |
|
| 523 | - array(array( 1, 5), array(10, 1), array( 1, 15), array( 2, 17)), |
|
| 524 | - array(array( 5, 1), array( 9, 4), array(17, 1), array( 2, 19)), |
|
| 525 | - array(array( 3, 4), array( 3, 11), array(17, 4), array( 9, 16)), |
|
| 526 | - array(array( 3, 5), array( 3, 13), array(15, 5), array(15, 10)), //20 |
|
| 527 | - array(array( 4, 4), array(17, 0), array(17, 6), array(19, 6)), |
|
| 528 | - array(array( 2, 7), array(17, 0), array( 7, 16), array(34, 0)), |
|
| 529 | - array(array( 4, 5), array( 4, 14), array(11, 14), array(16, 14)), |
|
| 530 | - array(array( 6, 4), array( 6, 14), array(11, 16), array(30, 2)), |
|
| 531 | - array(array( 8, 4), array( 8, 13), array( 7, 22), array(22, 13)), //25 |
|
| 532 | - array(array(10, 2), array(19, 4), array(28, 6), array(33, 4)), |
|
| 533 | - array(array( 8, 4), array(22, 3), array( 8, 26), array(12, 28)), |
|
| 534 | - array(array( 3, 10), array( 3, 23), array( 4, 31), array(11, 31)), |
|
| 535 | - array(array( 7, 7), array(21, 7), array( 1, 37), array(19, 26)), |
|
| 536 | - array(array( 5, 10), array(19, 10), array(15, 25), array(23, 25)), //30 |
|
| 537 | - array(array(13, 3), array( 2, 29), array(42, 1), array(23, 28)), |
|
| 538 | - array(array(17, 0), array(10, 23), array(10, 35), array(19, 35)), |
|
| 539 | - array(array(17, 1), array(14, 21), array(29, 19), array(11, 46)), |
|
| 540 | - array(array(13, 6), array(14, 23), array(44, 7), array(59, 1)), |
|
| 541 | - array(array(12, 7), array(12, 26), array(39, 14), array(22, 41)), //35 |
|
| 542 | - array(array( 6, 14), array( 6, 34), array(46, 10), array( 2, 64)), |
|
| 543 | - array(array(17, 4), array(29, 14), array(49, 10), array(24, 46)), |
|
| 544 | - array(array( 4, 18), array(13, 32), array(48, 14), array(42, 32)), |
|
| 545 | - array(array(20, 4), array(40, 7), array(43, 22), array(10, 67)), |
|
| 546 | - array(array(19, 6), array(18, 31), array(34, 34), array(20, 61)),//40 |
|
| 506 | + array(array(0, 0), array(0, 0), array(0, 0), array(0, 0)), |
|
| 507 | + array(array(1, 0), array(1, 0), array(1, 0), array(1, 0)), // 1 |
|
| 508 | + array(array(1, 0), array(1, 0), array(1, 0), array(1, 0)), |
|
| 509 | + array(array(1, 0), array(1, 0), array(2, 0), array(2, 0)), |
|
| 510 | + array(array(1, 0), array(2, 0), array(2, 0), array(4, 0)), |
|
| 511 | + array(array(1, 0), array(2, 0), array(2, 2), array(2, 2)), // 5 |
|
| 512 | + array(array(2, 0), array(4, 0), array(4, 0), array(4, 0)), |
|
| 513 | + array(array(2, 0), array(4, 0), array(2, 4), array(4, 1)), |
|
| 514 | + array(array(2, 0), array(2, 2), array(4, 2), array(4, 2)), |
|
| 515 | + array(array(2, 0), array(3, 2), array(4, 4), array(4, 4)), |
|
| 516 | + array(array(2, 2), array(4, 1), array(6, 2), array(6, 2)), //10 |
|
| 517 | + array(array(4, 0), array(1, 4), array(4, 4), array(3, 8)), |
|
| 518 | + array(array(2, 2), array(6, 2), array(4, 6), array(7, 4)), |
|
| 519 | + array(array(4, 0), array(8, 1), array(8, 4), array(12, 4)), |
|
| 520 | + array(array(3, 1), array(4, 5), array(11, 5), array(11, 5)), |
|
| 521 | + array(array(5, 1), array(5, 5), array(5, 7), array(11, 7)), //15 |
|
| 522 | + array(array(5, 1), array(7, 3), array(15, 2), array(3, 13)), |
|
| 523 | + array(array(1, 5), array(10, 1), array(1, 15), array(2, 17)), |
|
| 524 | + array(array(5, 1), array(9, 4), array(17, 1), array(2, 19)), |
|
| 525 | + array(array(3, 4), array(3, 11), array(17, 4), array(9, 16)), |
|
| 526 | + array(array(3, 5), array(3, 13), array(15, 5), array(15, 10)), //20 |
|
| 527 | + array(array(4, 4), array(17, 0), array(17, 6), array(19, 6)), |
|
| 528 | + array(array(2, 7), array(17, 0), array(7, 16), array(34, 0)), |
|
| 529 | + array(array(4, 5), array(4, 14), array(11, 14), array(16, 14)), |
|
| 530 | + array(array(6, 4), array(6, 14), array(11, 16), array(30, 2)), |
|
| 531 | + array(array(8, 4), array(8, 13), array(7, 22), array(22, 13)), //25 |
|
| 532 | + array(array(10, 2), array(19, 4), array(28, 6), array(33, 4)), |
|
| 533 | + array(array(8, 4), array(22, 3), array(8, 26), array(12, 28)), |
|
| 534 | + array(array(3, 10), array(3, 23), array(4, 31), array(11, 31)), |
|
| 535 | + array(array(7, 7), array(21, 7), array(1, 37), array(19, 26)), |
|
| 536 | + array(array(5, 10), array(19, 10), array(15, 25), array(23, 25)), //30 |
|
| 537 | + array(array(13, 3), array(2, 29), array(42, 1), array(23, 28)), |
|
| 538 | + array(array(17, 0), array(10, 23), array(10, 35), array(19, 35)), |
|
| 539 | + array(array(17, 1), array(14, 21), array(29, 19), array(11, 46)), |
|
| 540 | + array(array(13, 6), array(14, 23), array(44, 7), array(59, 1)), |
|
| 541 | + array(array(12, 7), array(12, 26), array(39, 14), array(22, 41)), //35 |
|
| 542 | + array(array(6, 14), array(6, 34), array(46, 10), array(2, 64)), |
|
| 543 | + array(array(17, 4), array(29, 14), array(49, 10), array(24, 46)), |
|
| 544 | + array(array(4, 18), array(13, 32), array(48, 14), array(42, 32)), |
|
| 545 | + array(array(20, 4), array(40, 7), array(43, 22), array(10, 67)), |
|
| 546 | + array(array(19, 6), array(18, 31), array(34, 34), array(20, 61)), //40 |
|
| 547 | 547 | ); |
| 548 | 548 | |
| 549 | 549 | //---------------------------------------------------------------------- |
@@ -551,8 +551,8 @@ discard block |
||
| 551 | 551 | |
| 552 | 552 | public static function getEccSpec($version, $level, array &$spec) |
| 553 | 553 | {
|
| 554 | - if (count($spec) < 5) {
|
|
| 555 | - $spec = array(0,0,0,0,0); |
|
| 554 | + if (count($spec)<5) {
|
|
| 555 | + $spec = array(0, 0, 0, 0, 0); |
|
| 556 | 556 | } |
| 557 | 557 | |
| 558 | 558 | $b1 = self::$eccTable[$version][$level][0]; |
@@ -560,7 +560,7 @@ discard block |
||
| 560 | 560 | $data = self::getDataLength($version, $level); |
| 561 | 561 | $ecc = self::getECCLength($version, $level); |
| 562 | 562 | |
| 563 | - if($b2 == 0) {
|
|
| 563 | + if ($b2==0) {
|
|
| 564 | 564 | $spec[0] = $b1; |
| 565 | 565 | $spec[1] = (int)($data / $b1); |
| 566 | 566 | $spec[2] = (int)($ecc / $b1); |
@@ -569,7 +569,7 @@ discard block |
||
| 569 | 569 | } else {
|
| 570 | 570 | $spec[0] = $b1; |
| 571 | 571 | $spec[1] = (int)($data / ($b1 + $b2)); |
| 572 | - $spec[2] = (int)($ecc / ($b1 + $b2)); |
|
| 572 | + $spec[2] = (int)($ecc / ($b1 + $b2)); |
|
| 573 | 573 | $spec[3] = $b2; |
| 574 | 574 | $spec[4] = $spec[1] + 1; |
| 575 | 575 | } |
@@ -585,9 +585,9 @@ discard block |
||
| 585 | 585 | // See Table 1 in Appendix E (pp.71) of JIS X0510:2004. |
| 586 | 586 | |
| 587 | 587 | public static $alignmentPattern = array( |
| 588 | - array( 0, 0), |
|
| 589 | - array( 0, 0), array(18, 0), array(22, 0), array(26, 0), array(30, 0), // 1- 5 |
|
| 590 | - array(34, 0), array(22, 38), array(24, 42), array(26, 46), array(28, 50), // 6-10 |
|
| 588 | + array(0, 0), |
|
| 589 | + array(0, 0), array(18, 0), array(22, 0), array(26, 0), array(30, 0), // 1- 5 |
|
| 590 | + array(34, 0), array(22, 38), array(24, 42), array(26, 46), array(28, 50), // 6-10 |
|
| 591 | 591 | array(30, 54), array(32, 58), array(34, 62), array(26, 46), array(26, 48), //11-15 |
| 592 | 592 | array(26, 50), array(30, 54), array(30, 56), array(30, 58), array(34, 62), //16-20 |
| 593 | 593 | array(28, 50), array(26, 50), array(30, 54), array(28, 54), array(32, 58), //21-25 |
@@ -613,28 +613,28 @@ discard block |
||
| 613 | 613 | "\xa1\xa1\xa1\xa1\xa1" |
| 614 | 614 | ); |
| 615 | 615 | |
| 616 | - $yStart = $oy-2; |
|
| 617 | - $xStart = $ox-2; |
|
| 616 | + $yStart = $oy - 2; |
|
| 617 | + $xStart = $ox - 2; |
|
| 618 | 618 | |
| 619 | - for($y=0; $y<5; $y++) {
|
|
| 620 | - QRstr::set($frame, $xStart, $yStart+$y, $finder[$y]); |
|
| 619 | + for ($y = 0; $y<5; $y++) {
|
|
| 620 | + QRstr::set($frame, $xStart, $yStart + $y, $finder[$y]); |
|
| 621 | 621 | } |
| 622 | 622 | } |
| 623 | 623 | |
| 624 | 624 | //---------------------------------------------------------------------- |
| 625 | 625 | public static function putAlignmentPattern($version, &$frame, $width) |
| 626 | 626 | {
|
| 627 | - if($version < 2) |
|
| 627 | + if ($version<2) |
|
| 628 | 628 | return; |
| 629 | 629 | |
| 630 | 630 | $d = self::$alignmentPattern[$version][1] - self::$alignmentPattern[$version][0]; |
| 631 | - if($d < 0) {
|
|
| 631 | + if ($d<0) {
|
|
| 632 | 632 | $w = 2; |
| 633 | 633 | } else {
|
| 634 | 634 | $w = (int)(($width - self::$alignmentPattern[$version][0]) / $d + 2); |
| 635 | 635 | } |
| 636 | 636 | |
| 637 | - if($w * $w - 3 == 1) {
|
|
| 637 | + if ($w * $w - 3==1) {
|
|
| 638 | 638 | $x = self::$alignmentPattern[$version][0]; |
| 639 | 639 | $y = self::$alignmentPattern[$version][0]; |
| 640 | 640 | self::putAlignmentMarker($frame, $x, $y); |
@@ -642,16 +642,16 @@ discard block |
||
| 642 | 642 | } |
| 643 | 643 | |
| 644 | 644 | $cx = self::$alignmentPattern[$version][0]; |
| 645 | - for($x=1; $x<$w - 1; $x++) {
|
|
| 645 | + for ($x = 1; $x<$w - 1; $x++) {
|
|
| 646 | 646 | self::putAlignmentMarker($frame, 6, $cx); |
| 647 | - self::putAlignmentMarker($frame, $cx, 6); |
|
| 647 | + self::putAlignmentMarker($frame, $cx, 6); |
|
| 648 | 648 | $cx += $d; |
| 649 | 649 | } |
| 650 | 650 | |
| 651 | 651 | $cy = self::$alignmentPattern[$version][0]; |
| 652 | - for($y=0; $y<$w-1; $y++) {
|
|
| 652 | + for ($y = 0; $y<$w - 1; $y++) {
|
|
| 653 | 653 | $cx = self::$alignmentPattern[$version][0]; |
| 654 | - for($x=0; $x<$w-1; $x++) {
|
|
| 654 | + for ($x = 0; $x<$w - 1; $x++) {
|
|
| 655 | 655 | self::putAlignmentMarker($frame, $cx, $cy); |
| 656 | 656 | $cx += $d; |
| 657 | 657 | } |
@@ -677,10 +677,10 @@ discard block |
||
| 677 | 677 | //---------------------------------------------------------------------- |
| 678 | 678 | public static function getVersionPattern($version) |
| 679 | 679 | {
|
| 680 | - if($version < 7 || $version > QRSPEC_VERSION_MAX) |
|
| 680 | + if ($version<7 || $version>QRSPEC_VERSION_MAX) |
|
| 681 | 681 | return 0; |
| 682 | 682 | |
| 683 | - return self::$versionPattern[$version -7]; |
|
| 683 | + return self::$versionPattern[$version - 7]; |
|
| 684 | 684 | } |
| 685 | 685 | |
| 686 | 686 | // Format information -------------------------------------------------- |
@@ -695,10 +695,10 @@ discard block |
||
| 695 | 695 | |
| 696 | 696 | public static function getFormatInfo($mask, $level) |
| 697 | 697 | {
|
| 698 | - if($mask < 0 || $mask > 7) |
|
| 698 | + if ($mask<0 || $mask>7) |
|
| 699 | 699 | return 0; |
| 700 | 700 | |
| 701 | - if($level < 0 || $level > 3) |
|
| 701 | + if ($level<0 || $level>3) |
|
| 702 | 702 | return 0; |
| 703 | 703 | |
| 704 | 704 | return self::$formatInfo[$level][$mask]; |
@@ -727,8 +727,8 @@ discard block |
||
| 727 | 727 | "\xc1\xc1\xc1\xc1\xc1\xc1\xc1" |
| 728 | 728 | ); |
| 729 | 729 | |
| 730 | - for($y=0; $y<7; $y++) {
|
|
| 731 | - QRstr::set($frame, $ox, $oy+$y, $finder[$y]); |
|
| 730 | + for ($y = 0; $y<7; $y++) {
|
|
| 731 | + QRstr::set($frame, $ox, $oy + $y, $finder[$y]); |
|
| 732 | 732 | } |
| 733 | 733 | } |
| 734 | 734 | |
@@ -736,7 +736,7 @@ discard block |
||
| 736 | 736 | public static function createFrame($version) |
| 737 | 737 | {
|
| 738 | 738 | $width = self::$capacity[$version][QRCAP_WIDTH]; |
| 739 | - $frameLine = str_repeat ("\0", $width);
|
|
| 739 | + $frameLine = str_repeat("\0", $width);
|
|
| 740 | 740 | $frame = array_fill(0, $width, $frameLine); |
| 741 | 741 | |
| 742 | 742 | // Finder pattern |
@@ -747,7 +747,7 @@ discard block |
||
| 747 | 747 | // Separator |
| 748 | 748 | $yOffset = $width - 7; |
| 749 | 749 | |
| 750 | - for($y=0; $y<7; $y++) {
|
|
| 750 | + for ($y = 0; $y<7; $y++) {
|
|
| 751 | 751 | $frame[$y][7] = "\xc0"; |
| 752 | 752 | $frame[$y][$width - 8] = "\xc0"; |
| 753 | 753 | $frame[$yOffset][7] = "\xc0"; |
@@ -757,7 +757,7 @@ discard block |
||
| 757 | 757 | $setPattern = str_repeat("\xc0", 8);
|
| 758 | 758 | |
| 759 | 759 | QRstr::set($frame, 0, 7, $setPattern); |
| 760 | - QRstr::set($frame, $width-8, 7, $setPattern); |
|
| 760 | + QRstr::set($frame, $width - 8, 7, $setPattern); |
|
| 761 | 761 | QRstr::set($frame, 0, $width - 8, $setPattern); |
| 762 | 762 | |
| 763 | 763 | // Format info |
@@ -767,38 +767,38 @@ discard block |
||
| 767 | 767 | |
| 768 | 768 | $yOffset = $width - 8; |
| 769 | 769 | |
| 770 | - for($y=0; $y<8; $y++,$yOffset++) {
|
|
| 770 | + for ($y = 0; $y<8; $y++, $yOffset++) {
|
|
| 771 | 771 | $frame[$y][8] = "\x84"; |
| 772 | 772 | $frame[$yOffset][8] = "\x84"; |
| 773 | 773 | } |
| 774 | 774 | |
| 775 | 775 | // Timing pattern |
| 776 | 776 | |
| 777 | - for($i=1; $i<$width-15; $i++) {
|
|
| 778 | - $frame[6][7+$i] = chr(0x90 | ($i & 1)); |
|
| 779 | - $frame[7+$i][6] = chr(0x90 | ($i & 1)); |
|
| 777 | + for ($i = 1; $i<$width - 15; $i++) {
|
|
| 778 | + $frame[6][7 + $i] = chr(0x90 | ($i & 1)); |
|
| 779 | + $frame[7 + $i][6] = chr(0x90 | ($i & 1)); |
|
| 780 | 780 | } |
| 781 | 781 | |
| 782 | 782 | // Alignment pattern |
| 783 | 783 | self::putAlignmentPattern($version, $frame, $width); |
| 784 | 784 | |
| 785 | 785 | // Version information |
| 786 | - if($version >= 7) {
|
|
| 786 | + if ($version>=7) {
|
|
| 787 | 787 | $vinf = self::getVersionPattern($version); |
| 788 | 788 | |
| 789 | 789 | $v = $vinf; |
| 790 | 790 | |
| 791 | - for($x=0; $x<6; $x++) {
|
|
| 792 | - for($y=0; $y<3; $y++) {
|
|
| 793 | - $frame[($width - 11)+$y][$x] = chr(0x88 | ($v & 1)); |
|
| 791 | + for ($x = 0; $x<6; $x++) {
|
|
| 792 | + for ($y = 0; $y<3; $y++) {
|
|
| 793 | + $frame[($width - 11) + $y][$x] = chr(0x88 | ($v & 1)); |
|
| 794 | 794 | $v = $v >> 1; |
| 795 | 795 | } |
| 796 | 796 | } |
| 797 | 797 | |
| 798 | 798 | $v = $vinf; |
| 799 | - for($y=0; $y<6; $y++) {
|
|
| 800 | - for($x=0; $x<3; $x++) {
|
|
| 801 | - $frame[$y][$x+($width - 11)] = chr(0x88 | ($v & 1)); |
|
| 799 | + for ($y = 0; $y<6; $y++) {
|
|
| 800 | + for ($x = 0; $x<3; $x++) {
|
|
| 801 | + $frame[$y][$x + ($width - 11)] = chr(0x88 | ($v & 1)); |
|
| 802 | 802 | $v = $v >> 1; |
| 803 | 803 | } |
| 804 | 804 | } |
@@ -832,16 +832,16 @@ discard block |
||
| 832 | 832 | } else {
|
| 833 | 833 | |
| 834 | 834 | foreach ($frame as &$frameLine) {
|
| 835 | - $frameLine = join('<span class="m"> </span>', explode("\xc0", $frameLine));
|
|
| 835 | + $frameLine = join('<span class="m"> </span>', explode("\xc0", $frameLine));
|
|
| 836 | 836 | $frameLine = join('<span class="m">▒</span>', explode("\xc1", $frameLine));
|
| 837 | - $frameLine = join('<span class="p"> </span>', explode("\xa0", $frameLine));
|
|
| 837 | + $frameLine = join('<span class="p"> </span>', explode("\xa0", $frameLine));
|
|
| 838 | 838 | $frameLine = join('<span class="p">▒</span>', explode("\xa1", $frameLine));
|
| 839 | 839 | $frameLine = join('<span class="s">◇</span>', explode("\x84", $frameLine)); //format 0
|
| 840 | 840 | $frameLine = join('<span class="s">◆</span>', explode("\x85", $frameLine)); //format 1
|
| 841 | 841 | $frameLine = join('<span class="x">☢</span>', explode("\x81", $frameLine)); //special bit
|
| 842 | - $frameLine = join('<span class="c"> </span>', explode("\x90", $frameLine)); //clock 0
|
|
| 842 | + $frameLine = join('<span class="c"> </span>', explode("\x90", $frameLine)); //clock 0
|
|
| 843 | 843 | $frameLine = join('<span class="c">◷</span>', explode("\x91", $frameLine)); //clock 1
|
| 844 | - $frameLine = join('<span class="f"> </span>', explode("\x88", $frameLine)); //version
|
|
| 844 | + $frameLine = join('<span class="f"> </span>', explode("\x88", $frameLine)); //version
|
|
| 845 | 845 | $frameLine = join('<span class="f">▒</span>', explode("\x89", $frameLine)); //version
|
| 846 | 846 | $frameLine = join('♦', explode("\x01", $frameLine));
|
| 847 | 847 | $frameLine = join('⋅', explode("\0", $frameLine));
|
@@ -879,10 +879,10 @@ discard block |
||
| 879 | 879 | //---------------------------------------------------------------------- |
| 880 | 880 | public static function newFrame($version) |
| 881 | 881 | {
|
| 882 | - if($version < 1 || $version > QRSPEC_VERSION_MAX) |
|
| 882 | + if ($version<1 || $version>QRSPEC_VERSION_MAX) |
|
| 883 | 883 | return null; |
| 884 | 884 | |
| 885 | - if(!isset(self::$frames[$version])) {
|
|
| 885 | + if (!isset(self::$frames[$version])) {
|
|
| 886 | 886 | |
| 887 | 887 | $fileName = QR_CACHE_DIR.'frame_'.$version.'.dat'; |
| 888 | 888 | |
@@ -898,22 +898,22 @@ discard block |
||
| 898 | 898 | } |
| 899 | 899 | } |
| 900 | 900 | |
| 901 | - if(is_null(self::$frames[$version])) |
|
| 901 | + if (is_null(self::$frames[$version])) |
|
| 902 | 902 | return null; |
| 903 | 903 | |
| 904 | 904 | return self::$frames[$version]; |
| 905 | 905 | } |
| 906 | 906 | |
| 907 | 907 | //---------------------------------------------------------------------- |
| 908 | - public static function rsBlockNum($spec) { return $spec[0] + $spec[3]; }
|
|
| 909 | - public static function rsBlockNum1($spec) { return $spec[0]; }
|
|
| 910 | - public static function rsDataCodes1($spec) { return $spec[1]; }
|
|
| 911 | - public static function rsEccCodes1($spec) { return $spec[2]; }
|
|
| 912 | - public static function rsBlockNum2($spec) { return $spec[3]; }
|
|
| 913 | - public static function rsDataCodes2($spec) { return $spec[4]; }
|
|
| 914 | - public static function rsEccCodes2($spec) { return $spec[2]; }
|
|
| 915 | - public static function rsDataLength($spec) { return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]); }
|
|
| 916 | - public static function rsEccLength($spec) { return ($spec[0] + $spec[3]) * $spec[2]; }
|
|
| 908 | + public static function rsBlockNum($spec) { return $spec[0] + $spec[3]; }
|
|
| 909 | + public static function rsBlockNum1($spec) { return $spec[0]; }
|
|
| 910 | + public static function rsDataCodes1($spec) { return $spec[1]; }
|
|
| 911 | + public static function rsEccCodes1($spec) { return $spec[2]; }
|
|
| 912 | + public static function rsBlockNum2($spec) { return $spec[3]; }
|
|
| 913 | + public static function rsDataCodes2($spec) { return $spec[4]; }
|
|
| 914 | + public static function rsEccCodes2($spec) { return $spec[2]; }
|
|
| 915 | + public static function rsDataLength($spec) { return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]); }
|
|
| 916 | + public static function rsEccLength($spec) { return ($spec[0] + $spec[3]) * $spec[2]; }
|
|
| 917 | 917 | |
| 918 | 918 | } |
| 919 | 919 | |
@@ -952,19 +952,19 @@ discard block |
||
| 952 | 952 | class QRimage { |
| 953 | 953 | |
| 954 | 954 | //---------------------------------------------------------------------- |
| 955 | - public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE, $back_color, $fore_color) |
|
| 955 | + public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4, $saveandprint = FALSE, $back_color, $fore_color) |
|
| 956 | 956 | { |
| 957 | 957 | $image = self::image($frame, $pixelPerPoint, $outerFrame, $back_color, $fore_color); |
| 958 | 958 | |
| 959 | - if ($filename === false) { |
|
| 959 | + if ($filename===false) { |
|
| 960 | 960 | Header("Content-type: image/png"); |
| 961 | 961 | ImagePng($image); |
| 962 | 962 | } else { |
| 963 | - if($saveandprint===TRUE){ |
|
| 963 | + if ($saveandprint===TRUE) { |
|
| 964 | 964 | ImagePng($image, $filename); |
| 965 | 965 | header("Content-type: image/png"); |
| 966 | 966 | ImagePng($image); |
| 967 | - }else{ |
|
| 967 | + } else { |
|
| 968 | 968 | ImagePng($image, $filename); |
| 969 | 969 | } |
| 970 | 970 | } |
@@ -977,7 +977,7 @@ discard block |
||
| 977 | 977 | { |
| 978 | 978 | $image = self::image($frame, $pixelPerPoint, $outerFrame); |
| 979 | 979 | |
| 980 | - if ($filename === false) { |
|
| 980 | + if ($filename===false) { |
|
| 981 | 981 | Header("Content-type: image/jpeg"); |
| 982 | 982 | ImageJpeg($image, null, $q); |
| 983 | 983 | } else { |
@@ -993,10 +993,10 @@ discard block |
||
| 993 | 993 | $h = count($frame); |
| 994 | 994 | $w = strlen($frame[0]); |
| 995 | 995 | |
| 996 | - $imgW = $w + 2*$outerFrame; |
|
| 997 | - $imgH = $h + 2*$outerFrame; |
|
| 996 | + $imgW = $w + 2 * $outerFrame; |
|
| 997 | + $imgH = $h + 2 * $outerFrame; |
|
| 998 | 998 | |
| 999 | - $base_image =ImageCreate($imgW, $imgH); |
|
| 999 | + $base_image = ImageCreate($imgW, $imgH); |
|
| 1000 | 1000 | |
| 1001 | 1001 | // convert a hexadecimal color code into decimal eps format (green = 0 1 0, blue = 0 0 1, ...) |
| 1002 | 1002 | $r1 = round((($fore_color & 0xFF0000) >> 16), 5); |
@@ -1010,20 +1010,20 @@ discard block |
||
| 1010 | 1010 | |
| 1011 | 1011 | |
| 1012 | 1012 | |
| 1013 | - $col[0] = ImageColorAllocate($base_image,$r2,$b2,$g2); |
|
| 1014 | - $col[1] = ImageColorAllocate($base_image,$r1,$b1,$g1); |
|
| 1013 | + $col[0] = ImageColorAllocate($base_image, $r2, $b2, $g2); |
|
| 1014 | + $col[1] = ImageColorAllocate($base_image, $r1, $b1, $g1); |
|
| 1015 | 1015 | |
| 1016 | 1016 | imagefill($base_image, 0, 0, $col[0]); |
| 1017 | 1017 | |
| 1018 | - for($y=0; $y<$h; $y++) { |
|
| 1019 | - for($x=0; $x<$w; $x++) { |
|
| 1020 | - if ($frame[$y][$x] == '1') { |
|
| 1021 | - ImageSetPixel($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]); |
|
| 1018 | + for ($y = 0; $y<$h; $y++) { |
|
| 1019 | + for ($x = 0; $x<$w; $x++) { |
|
| 1020 | + if ($frame[$y][$x]=='1') { |
|
| 1021 | + ImageSetPixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]); |
|
| 1022 | 1022 | } |
| 1023 | 1023 | } |
| 1024 | 1024 | } |
| 1025 | 1025 | |
| 1026 | - $target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint); |
|
| 1026 | + $target_image = ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint); |
|
| 1027 | 1027 | ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH); |
| 1028 | 1028 | ImageDestroy($base_image); |
| 1029 | 1029 | |
@@ -1064,7 +1064,7 @@ discard block |
||
| 1064 | 1064 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 1065 | 1065 | */ |
| 1066 | 1066 | |
| 1067 | - define('STRUCTURE_HEADER_BITS', 20);
|
|
| 1067 | + define('STRUCTURE_HEADER_BITS', 20);
|
|
| 1068 | 1068 | define('MAX_STRUCTURED_SYMBOLS', 16);
|
| 1069 | 1069 | |
| 1070 | 1070 | class QRinputItem {
|
@@ -1078,12 +1078,12 @@ discard block |
||
| 1078 | 1078 | {
|
| 1079 | 1079 | $setData = array_slice($data, 0, $size); |
| 1080 | 1080 | |
| 1081 | - if (count($setData) < $size) {
|
|
| 1082 | - $setData = array_merge($setData, array_fill(0,$size-count($setData),0)); |
|
| 1081 | + if (count($setData)<$size) {
|
|
| 1082 | + $setData = array_merge($setData, array_fill(0, $size - count($setData), 0)); |
|
| 1083 | 1083 | } |
| 1084 | 1084 | |
| 1085 | - if(!QRinput::check($mode, $size, $setData)) {
|
|
| 1086 | - throw new Exception('Error m:'.$mode.',s:'.$size.',d:'.join(',',$setData));
|
|
| 1085 | + if (!QRinput::check($mode, $size, $setData)) {
|
|
| 1086 | + throw new Exception('Error m:'.$mode.',s:'.$size.',d:'.join(',', $setData));
|
|
| 1087 | 1087 | return null; |
| 1088 | 1088 | } |
| 1089 | 1089 | |
@@ -1105,19 +1105,19 @@ discard block |
||
| 1105 | 1105 | $bs->appendNum(4, $val); |
| 1106 | 1106 | $bs->appendNum(QRspec::lengthIndicator(QR_MODE_NUM, $version), $this->size); |
| 1107 | 1107 | |
| 1108 | - for($i=0; $i<$words; $i++) {
|
|
| 1109 | - $val = (ord($this->data[$i*3 ]) - ord('0')) * 100;
|
|
| 1110 | - $val += (ord($this->data[$i*3+1]) - ord('0')) * 10;
|
|
| 1111 | - $val += (ord($this->data[$i*3+2]) - ord('0'));
|
|
| 1108 | + for ($i = 0; $i<$words; $i++) {
|
|
| 1109 | + $val = (ord($this->data[$i * 3]) - ord('0')) * 100;
|
|
| 1110 | + $val += (ord($this->data[$i * 3 + 1]) - ord('0')) * 10;
|
|
| 1111 | + $val += (ord($this->data[$i * 3 + 2]) - ord('0'));
|
|
| 1112 | 1112 | $bs->appendNum(10, $val); |
| 1113 | 1113 | } |
| 1114 | 1114 | |
| 1115 | - if($this->size - $words * 3 == 1) {
|
|
| 1116 | - $val = ord($this->data[$words*3]) - ord('0');
|
|
| 1115 | + if ($this->size - $words * 3==1) {
|
|
| 1116 | + $val = ord($this->data[$words * 3]) - ord('0');
|
|
| 1117 | 1117 | $bs->appendNum(4, $val); |
| 1118 | - } else if($this->size - $words * 3 == 2) {
|
|
| 1119 | - $val = (ord($this->data[$words*3 ]) - ord('0')) * 10;
|
|
| 1120 | - $val += (ord($this->data[$words*3+1]) - ord('0'));
|
|
| 1118 | + } else if ($this->size - $words * 3==2) {
|
|
| 1119 | + $val = (ord($this->data[$words * 3]) - ord('0')) * 10;
|
|
| 1120 | + $val += (ord($this->data[$words * 3 + 1]) - ord('0'));
|
|
| 1121 | 1121 | $bs->appendNum(7, $val); |
| 1122 | 1122 | } |
| 1123 | 1123 | |
@@ -1139,14 +1139,14 @@ discard block |
||
| 1139 | 1139 | $bs->appendNum(4, 0x02); |
| 1140 | 1140 | $bs->appendNum(QRspec::lengthIndicator(QR_MODE_AN, $version), $this->size); |
| 1141 | 1141 | |
| 1142 | - for($i=0; $i<$words; $i++) {
|
|
| 1143 | - $val = (int)QRinput::lookAnTable(ord($this->data[$i*2 ])) * 45; |
|
| 1144 | - $val += (int)QRinput::lookAnTable(ord($this->data[$i*2+1])); |
|
| 1142 | + for ($i = 0; $i<$words; $i++) {
|
|
| 1143 | + $val = (int)QRinput::lookAnTable(ord($this->data[$i * 2])) * 45; |
|
| 1144 | + $val += (int)QRinput::lookAnTable(ord($this->data[$i * 2 + 1])); |
|
| 1145 | 1145 | |
| 1146 | 1146 | $bs->appendNum(11, $val); |
| 1147 | 1147 | } |
| 1148 | 1148 | |
| 1149 | - if($this->size & 1) {
|
|
| 1149 | + if ($this->size & 1) {
|
|
| 1150 | 1150 | $val = QRinput::lookAnTable(ord($this->data[$words * 2])); |
| 1151 | 1151 | $bs->appendNum(6, $val); |
| 1152 | 1152 | } |
@@ -1168,7 +1168,7 @@ discard block |
||
| 1168 | 1168 | $bs->appendNum(4, 0x4); |
| 1169 | 1169 | $bs->appendNum(QRspec::lengthIndicator(QR_MODE_8, $version), $this->size); |
| 1170 | 1170 | |
| 1171 | - for($i=0; $i<$this->size; $i++) {
|
|
| 1171 | + for ($i = 0; $i<$this->size; $i++) {
|
|
| 1172 | 1172 | $bs->appendNum(8, ord($this->data[$i])); |
| 1173 | 1173 | } |
| 1174 | 1174 | |
@@ -1190,9 +1190,9 @@ discard block |
||
| 1190 | 1190 | $bs->appendNum(4, 0x8); |
| 1191 | 1191 | $bs->appendNum(QRspec::lengthIndicator(QR_MODE_KANJI, $version), (int)($this->size / 2)); |
| 1192 | 1192 | |
| 1193 | - for($i=0; $i<$this->size; $i+=2) {
|
|
| 1194 | - $val = (ord($this->data[$i]) << 8) | ord($this->data[$i+1]); |
|
| 1195 | - if($val <= 0x9ffc) {
|
|
| 1193 | + for ($i = 0; $i<$this->size; $i += 2) {
|
|
| 1194 | + $val = (ord($this->data[$i]) << 8) | ord($this->data[$i + 1]); |
|
| 1195 | + if ($val<=0x9ffc) {
|
|
| 1196 | 1196 | $val -= 0x8140; |
| 1197 | 1197 | } else {
|
| 1198 | 1198 | $val -= 0xc140; |
@@ -1216,7 +1216,7 @@ discard block |
||
| 1216 | 1216 | public function encodeModeStructure() |
| 1217 | 1217 | {
|
| 1218 | 1218 | try {
|
| 1219 | - $bs = new QRbitstream(); |
|
| 1219 | + $bs = new QRbitstream(); |
|
| 1220 | 1220 | |
| 1221 | 1221 | $bs->appendNum(4, 0x03); |
| 1222 | 1222 | $bs->appendNum(4, ord($this->data[1]) - 1); |
@@ -1236,14 +1236,14 @@ discard block |
||
| 1236 | 1236 | {
|
| 1237 | 1237 | $bits = 0; |
| 1238 | 1238 | |
| 1239 | - if($version == 0) |
|
| 1239 | + if ($version==0) |
|
| 1240 | 1240 | $version = 1; |
| 1241 | 1241 | |
| 1242 | - switch($this->mode) {
|
|
| 1243 | - case QR_MODE_NUM: $bits = QRinput::estimateBitsModeNum($this->size); break; |
|
| 1244 | - case QR_MODE_AN: $bits = QRinput::estimateBitsModeAn($this->size); break; |
|
| 1245 | - case QR_MODE_8: $bits = QRinput::estimateBitsMode8($this->size); break; |
|
| 1246 | - case QR_MODE_KANJI: $bits = QRinput::estimateBitsModeKanji($this->size);break; |
|
| 1242 | + switch ($this->mode) {
|
|
| 1243 | + case QR_MODE_NUM: $bits = QRinput::estimateBitsModeNum($this->size); break; |
|
| 1244 | + case QR_MODE_AN: $bits = QRinput::estimateBitsModeAn($this->size); break; |
|
| 1245 | + case QR_MODE_8: $bits = QRinput::estimateBitsMode8($this->size); break; |
|
| 1246 | + case QR_MODE_KANJI: $bits = QRinput::estimateBitsModeKanji($this->size); break; |
|
| 1247 | 1247 | case QR_MODE_STRUCTURE: return STRUCTURE_HEADER_BITS; |
| 1248 | 1248 | default: |
| 1249 | 1249 | return 0; |
@@ -1266,7 +1266,7 @@ discard block |
||
| 1266 | 1266 | unset($this->bstream); |
| 1267 | 1267 | $words = QRspec::maximumWords($this->mode, $version); |
| 1268 | 1268 | |
| 1269 | - if($this->size > $words) {
|
|
| 1269 | + if ($this->size>$words) {
|
|
| 1270 | 1270 | |
| 1271 | 1271 | $st1 = new QRinputItem($this->mode, $words, $this->data); |
| 1272 | 1272 | $st2 = new QRinputItem($this->mode, $this->size - $words, array_slice($this->data, $words)); |
@@ -1285,18 +1285,18 @@ discard block |
||
| 1285 | 1285 | |
| 1286 | 1286 | $ret = 0; |
| 1287 | 1287 | |
| 1288 | - switch($this->mode) {
|
|
| 1289 | - case QR_MODE_NUM: $ret = $this->encodeModeNum($version); break; |
|
| 1290 | - case QR_MODE_AN: $ret = $this->encodeModeAn($version); break; |
|
| 1291 | - case QR_MODE_8: $ret = $this->encodeMode8($version); break; |
|
| 1292 | - case QR_MODE_KANJI: $ret = $this->encodeModeKanji($version);break; |
|
| 1293 | - case QR_MODE_STRUCTURE: $ret = $this->encodeModeStructure(); break; |
|
| 1288 | + switch ($this->mode) {
|
|
| 1289 | + case QR_MODE_NUM: $ret = $this->encodeModeNum($version); break; |
|
| 1290 | + case QR_MODE_AN: $ret = $this->encodeModeAn($version); break; |
|
| 1291 | + case QR_MODE_8: $ret = $this->encodeMode8($version); break; |
|
| 1292 | + case QR_MODE_KANJI: $ret = $this->encodeModeKanji($version); break; |
|
| 1293 | + case QR_MODE_STRUCTURE: $ret = $this->encodeModeStructure(); break; |
|
| 1294 | 1294 | |
| 1295 | 1295 | default: |
| 1296 | 1296 | break; |
| 1297 | 1297 | } |
| 1298 | 1298 | |
| 1299 | - if($ret < 0) |
|
| 1299 | + if ($ret<0) |
|
| 1300 | 1300 | return -1; |
| 1301 | 1301 | } |
| 1302 | 1302 | |
@@ -1320,7 +1320,7 @@ discard block |
||
| 1320 | 1320 | //---------------------------------------------------------------------- |
| 1321 | 1321 | public function __construct($version = 0, $level = QR_ECLEVEL_L) |
| 1322 | 1322 | {
|
| 1323 | - if ($version < 0 || $version > QRSPEC_VERSION_MAX || $level > QR_ECLEVEL_H) {
|
|
| 1323 | + if ($version<0 || $version>QRSPEC_VERSION_MAX || $level>QR_ECLEVEL_H) {
|
|
| 1324 | 1324 | throw new Exception('Invalid version no');
|
| 1325 | 1325 | return NULL; |
| 1326 | 1326 | } |
@@ -1338,7 +1338,7 @@ discard block |
||
| 1338 | 1338 | //---------------------------------------------------------------------- |
| 1339 | 1339 | public function setVersion($version) |
| 1340 | 1340 | {
|
| 1341 | - if($version < 0 || $version > QRSPEC_VERSION_MAX) {
|
|
| 1341 | + if ($version<0 || $version>QRSPEC_VERSION_MAX) {
|
|
| 1342 | 1342 | throw new Exception('Invalid version no');
|
| 1343 | 1343 | return -1; |
| 1344 | 1344 | } |
@@ -1357,7 +1357,7 @@ discard block |
||
| 1357 | 1357 | //---------------------------------------------------------------------- |
| 1358 | 1358 | public function setErrorCorrectionLevel($level) |
| 1359 | 1359 | {
|
| 1360 | - if($level > QR_ECLEVEL_H) {
|
|
| 1360 | + if ($level>QR_ECLEVEL_H) {
|
|
| 1361 | 1361 | throw new Exception('Invalid ECLEVEL');
|
| 1362 | 1362 | return -1; |
| 1363 | 1363 | } |
@@ -1389,11 +1389,11 @@ discard block |
||
| 1389 | 1389 | |
| 1390 | 1390 | public function insertStructuredAppendHeader($size, $index, $parity) |
| 1391 | 1391 | {
|
| 1392 | - if( $size > MAX_STRUCTURED_SYMBOLS ) {
|
|
| 1392 | + if ($size>MAX_STRUCTURED_SYMBOLS) {
|
|
| 1393 | 1393 | throw new Exception('insertStructuredAppendHeader wrong size');
|
| 1394 | 1394 | } |
| 1395 | 1395 | |
| 1396 | - if( $index <= 0 || $index > MAX_STRUCTURED_SYMBOLS ) {
|
|
| 1396 | + if ($index<=0 || $index>MAX_STRUCTURED_SYMBOLS) {
|
|
| 1397 | 1397 | throw new Exception('insertStructuredAppendHeader wrong index');
|
| 1398 | 1398 | } |
| 1399 | 1399 | |
@@ -1413,9 +1413,9 @@ discard block |
||
| 1413 | 1413 | {
|
| 1414 | 1414 | $parity = 0; |
| 1415 | 1415 | |
| 1416 | - foreach($this->items as $item) {
|
|
| 1417 | - if($item->mode != QR_MODE_STRUCTURE) {
|
|
| 1418 | - for($i=$item->size-1; $i>=0; $i--) {
|
|
| 1416 | + foreach ($this->items as $item) {
|
|
| 1417 | + if ($item->mode!=QR_MODE_STRUCTURE) {
|
|
| 1418 | + for ($i = $item->size - 1; $i>=0; $i--) {
|
|
| 1419 | 1419 | $parity ^= $item->data[$i]; |
| 1420 | 1420 | } |
| 1421 | 1421 | } |
@@ -1427,8 +1427,8 @@ discard block |
||
| 1427 | 1427 | //---------------------------------------------------------------------- |
| 1428 | 1428 | public static function checkModeNum($size, $data) |
| 1429 | 1429 | {
|
| 1430 | - for($i=0; $i<$size; $i++) {
|
|
| 1431 | - if((ord($data[$i]) < ord('0')) || (ord($data[$i]) > ord('9'))){
|
|
| 1430 | + for ($i = 0; $i<$size; $i++) {
|
|
| 1431 | + if ((ord($data[$i])<ord('0')) || (ord($data[$i])>ord('9'))) {
|
|
| 1432 | 1432 | return false; |
| 1433 | 1433 | } |
| 1434 | 1434 | } |
@@ -1442,7 +1442,7 @@ discard block |
||
| 1442 | 1442 | $w = (int)$size / 3; |
| 1443 | 1443 | $bits = $w * 10; |
| 1444 | 1444 | |
| 1445 | - switch($size - $w * 3) {
|
|
| 1445 | + switch ($size - $w * 3) {
|
|
| 1446 | 1446 | case 1: |
| 1447 | 1447 | $bits += 4; |
| 1448 | 1448 | break; |
@@ -1461,7 +1461,7 @@ discard block |
||
| 1461 | 1461 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 1462 | 1462 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 1463 | 1463 | 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, |
| 1464 | - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, |
|
| 1464 | + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, |
|
| 1465 | 1465 | -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, |
| 1466 | 1466 | 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, |
| 1467 | 1467 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
@@ -1471,14 +1471,14 @@ discard block |
||
| 1471 | 1471 | //---------------------------------------------------------------------- |
| 1472 | 1472 | public static function lookAnTable($c) |
| 1473 | 1473 | {
|
| 1474 | - return (($c > 127)?-1:self::$anTable[$c]); |
|
| 1474 | + return (($c>127) ?-1 : self::$anTable[$c]); |
|
| 1475 | 1475 | } |
| 1476 | 1476 | |
| 1477 | 1477 | //---------------------------------------------------------------------- |
| 1478 | 1478 | public static function checkModeAn($size, $data) |
| 1479 | 1479 | {
|
| 1480 | - for($i=0; $i<$size; $i++) {
|
|
| 1481 | - if (self::lookAnTable(ord($data[$i])) == -1) {
|
|
| 1480 | + for ($i = 0; $i<$size; $i++) {
|
|
| 1481 | + if (self::lookAnTable(ord($data[$i]))==-1) {
|
|
| 1482 | 1482 | return false; |
| 1483 | 1483 | } |
| 1484 | 1484 | } |
@@ -1492,7 +1492,7 @@ discard block |
||
| 1492 | 1492 | $w = (int)($size / 2); |
| 1493 | 1493 | $bits = $w * 11; |
| 1494 | 1494 | |
| 1495 | - if($size & 1) {
|
|
| 1495 | + if ($size & 1) {
|
|
| 1496 | 1496 | $bits += 6; |
| 1497 | 1497 | } |
| 1498 | 1498 | |
@@ -1514,14 +1514,14 @@ discard block |
||
| 1514 | 1514 | //---------------------------------------------------------------------- |
| 1515 | 1515 | public static function checkModeKanji($size, $data) |
| 1516 | 1516 | {
|
| 1517 | - if($size & 1) |
|
| 1517 | + if ($size & 1) |
|
| 1518 | 1518 | return false; |
| 1519 | 1519 | |
| 1520 | - for($i=0; $i<$size; $i+=2) {
|
|
| 1521 | - $val = (ord($data[$i]) << 8) | ord($data[$i+1]); |
|
| 1522 | - if( $val < 0x8140 |
|
| 1523 | - || ($val > 0x9ffc && $val < 0xe040) |
|
| 1524 | - || $val > 0xebbf) {
|
|
| 1520 | + for ($i = 0; $i<$size; $i += 2) {
|
|
| 1521 | + $val = (ord($data[$i]) << 8) | ord($data[$i + 1]); |
|
| 1522 | + if ($val<0x8140 |
|
| 1523 | + || ($val>0x9ffc && $val<0xe040) |
|
| 1524 | + || $val>0xebbf) {
|
|
| 1525 | 1525 | return false; |
| 1526 | 1526 | } |
| 1527 | 1527 | } |
@@ -1535,12 +1535,12 @@ discard block |
||
| 1535 | 1535 | |
| 1536 | 1536 | public static function check($mode, $size, $data) |
| 1537 | 1537 | {
|
| 1538 | - if($size <= 0) |
|
| 1538 | + if ($size<=0) |
|
| 1539 | 1539 | return false; |
| 1540 | 1540 | |
| 1541 | - switch($mode) {
|
|
| 1542 | - case QR_MODE_NUM: return self::checkModeNum($size, $data); break; |
|
| 1543 | - case QR_MODE_AN: return self::checkModeAn($size, $data); break; |
|
| 1541 | + switch ($mode) {
|
|
| 1542 | + case QR_MODE_NUM: return self::checkModeNum($size, $data); break; |
|
| 1543 | + case QR_MODE_AN: return self::checkModeAn($size, $data); break; |
|
| 1544 | 1544 | case QR_MODE_KANJI: return self::checkModeKanji($size, $data); break; |
| 1545 | 1545 | case QR_MODE_8: return true; break; |
| 1546 | 1546 | case QR_MODE_STRUCTURE: return true; break; |
@@ -1558,7 +1558,7 @@ discard block |
||
| 1558 | 1558 | {
|
| 1559 | 1559 | $bits = 0; |
| 1560 | 1560 | |
| 1561 | - foreach($this->items as $item) {
|
|
| 1561 | + foreach ($this->items as $item) {
|
|
| 1562 | 1562 | $bits += $item->estimateBitStreamSizeOfEntry($version); |
| 1563 | 1563 | } |
| 1564 | 1564 | |
@@ -1574,10 +1574,10 @@ discard block |
||
| 1574 | 1574 | $prev = $version; |
| 1575 | 1575 | $bits = $this->estimateBitStreamSize($prev); |
| 1576 | 1576 | $version = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); |
| 1577 | - if ($version < 0) {
|
|
| 1577 | + if ($version<0) {
|
|
| 1578 | 1578 | return -1; |
| 1579 | 1579 | } |
| 1580 | - } while ($version > $prev); |
|
| 1580 | + } while ($version>$prev); |
|
| 1581 | 1581 | |
| 1582 | 1582 | return $version; |
| 1583 | 1583 | } |
@@ -1586,14 +1586,14 @@ discard block |
||
| 1586 | 1586 | public static function lengthOfCode($mode, $version, $bits) |
| 1587 | 1587 | {
|
| 1588 | 1588 | $payload = $bits - 4 - QRspec::lengthIndicator($mode, $version); |
| 1589 | - switch($mode) {
|
|
| 1589 | + switch ($mode) {
|
|
| 1590 | 1590 | case QR_MODE_NUM: |
| 1591 | 1591 | $chunks = (int)($payload / 10); |
| 1592 | 1592 | $remain = $payload - $chunks * 10; |
| 1593 | 1593 | $size = $chunks * 3; |
| 1594 | - if($remain >= 7) {
|
|
| 1594 | + if ($remain>=7) {
|
|
| 1595 | 1595 | $size += 2; |
| 1596 | - } else if($remain >= 4) {
|
|
| 1596 | + } else if ($remain>=4) {
|
|
| 1597 | 1597 | $size += 1; |
| 1598 | 1598 | } |
| 1599 | 1599 | break; |
@@ -1601,7 +1601,7 @@ discard block |
||
| 1601 | 1601 | $chunks = (int)($payload / 11); |
| 1602 | 1602 | $remain = $payload - $chunks * 11; |
| 1603 | 1603 | $size = $chunks * 2; |
| 1604 | - if($remain >= 6) |
|
| 1604 | + if ($remain>=6) |
|
| 1605 | 1605 | $size++; |
| 1606 | 1606 | break; |
| 1607 | 1607 | case QR_MODE_8: |
@@ -1619,8 +1619,8 @@ discard block |
||
| 1619 | 1619 | } |
| 1620 | 1620 | |
| 1621 | 1621 | $maxsize = QRspec::maximumWords($mode, $version); |
| 1622 | - if($size < 0) $size = 0; |
|
| 1623 | - if($size > $maxsize) $size = $maxsize; |
|
| 1622 | + if ($size<0) $size = 0; |
|
| 1623 | + if ($size>$maxsize) $size = $maxsize; |
|
| 1624 | 1624 | |
| 1625 | 1625 | return $size; |
| 1626 | 1626 | } |
@@ -1630,10 +1630,10 @@ discard block |
||
| 1630 | 1630 | {
|
| 1631 | 1631 | $total = 0; |
| 1632 | 1632 | |
| 1633 | - foreach($this->items as $item) {
|
|
| 1633 | + foreach ($this->items as $item) {
|
|
| 1634 | 1634 | $bits = $item->encodeBitStream($this->version); |
| 1635 | 1635 | |
| 1636 | - if($bits < 0) |
|
| 1636 | + if ($bits<0) |
|
| 1637 | 1637 | return -1; |
| 1638 | 1638 | |
| 1639 | 1639 | $total += $bits; |
@@ -1646,21 +1646,21 @@ discard block |
||
| 1646 | 1646 | public function convertData() |
| 1647 | 1647 | {
|
| 1648 | 1648 | $ver = $this->estimateVersion(); |
| 1649 | - if($ver > $this->getVersion()) {
|
|
| 1649 | + if ($ver>$this->getVersion()) {
|
|
| 1650 | 1650 | $this->setVersion($ver); |
| 1651 | 1651 | } |
| 1652 | 1652 | |
| 1653 | - for(;;) {
|
|
| 1653 | + for (;;) {
|
|
| 1654 | 1654 | $bits = $this->createBitStream(); |
| 1655 | 1655 | |
| 1656 | - if($bits < 0) |
|
| 1656 | + if ($bits<0) |
|
| 1657 | 1657 | return -1; |
| 1658 | 1658 | |
| 1659 | 1659 | $ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); |
| 1660 | - if($ver < 0) {
|
|
| 1660 | + if ($ver<0) {
|
|
| 1661 | 1661 | throw new Exception('WRONG VERSION');
|
| 1662 | 1662 | return -1; |
| 1663 | - } else if($ver > $this->getVersion()) {
|
|
| 1663 | + } else if ($ver>$this->getVersion()) {
|
|
| 1664 | 1664 | $this->setVersion($ver); |
| 1665 | 1665 | } else {
|
| 1666 | 1666 | break; |
@@ -1677,11 +1677,11 @@ discard block |
||
| 1677 | 1677 | $maxwords = QRspec::getDataLength($this->version, $this->level); |
| 1678 | 1678 | $maxbits = $maxwords * 8; |
| 1679 | 1679 | |
| 1680 | - if ($maxbits == $bits) {
|
|
| 1680 | + if ($maxbits==$bits) {
|
|
| 1681 | 1681 | return 0; |
| 1682 | 1682 | } |
| 1683 | 1683 | |
| 1684 | - if ($maxbits - $bits < 5) {
|
|
| 1684 | + if ($maxbits - $bits<5) {
|
|
| 1685 | 1685 | return $bstream->appendNum($maxbits - $bits, 0); |
| 1686 | 1686 | } |
| 1687 | 1687 | |
@@ -1691,21 +1691,21 @@ discard block |
||
| 1691 | 1691 | $padding = new QRbitstream(); |
| 1692 | 1692 | $ret = $padding->appendNum($words * 8 - $bits + 4, 0); |
| 1693 | 1693 | |
| 1694 | - if($ret < 0) |
|
| 1694 | + if ($ret<0) |
|
| 1695 | 1695 | return $ret; |
| 1696 | 1696 | |
| 1697 | 1697 | $padlen = $maxwords - $words; |
| 1698 | 1698 | |
| 1699 | - if($padlen > 0) {
|
|
| 1699 | + if ($padlen>0) {
|
|
| 1700 | 1700 | |
| 1701 | 1701 | $padbuf = array(); |
| 1702 | - for($i=0; $i<$padlen; $i++) {
|
|
| 1703 | - $padbuf[$i] = ($i&1)?0x11:0xec; |
|
| 1702 | + for ($i = 0; $i<$padlen; $i++) {
|
|
| 1703 | + $padbuf[$i] = ($i & 1) ? 0x11 : 0xec; |
|
| 1704 | 1704 | } |
| 1705 | 1705 | |
| 1706 | 1706 | $ret = $padding->appendBytes($padlen, $padbuf); |
| 1707 | 1707 | |
| 1708 | - if($ret < 0) |
|
| 1708 | + if ($ret<0) |
|
| 1709 | 1709 | return $ret; |
| 1710 | 1710 | |
| 1711 | 1711 | } |
@@ -1718,15 +1718,15 @@ discard block |
||
| 1718 | 1718 | //---------------------------------------------------------------------- |
| 1719 | 1719 | public function mergeBitStream() |
| 1720 | 1720 | {
|
| 1721 | - if($this->convertData() < 0) {
|
|
| 1721 | + if ($this->convertData()<0) {
|
|
| 1722 | 1722 | return null; |
| 1723 | 1723 | } |
| 1724 | 1724 | |
| 1725 | 1725 | $bstream = new QRbitstream(); |
| 1726 | 1726 | |
| 1727 | - foreach($this->items as $item) {
|
|
| 1727 | + foreach ($this->items as $item) {
|
|
| 1728 | 1728 | $ret = $bstream->append($item->bstream); |
| 1729 | - if($ret < 0) {
|
|
| 1729 | + if ($ret<0) {
|
|
| 1730 | 1730 | return null; |
| 1731 | 1731 | } |
| 1732 | 1732 | } |
@@ -1740,12 +1740,12 @@ discard block |
||
| 1740 | 1740 | |
| 1741 | 1741 | $bstream = $this->mergeBitStream(); |
| 1742 | 1742 | |
| 1743 | - if($bstream == null) {
|
|
| 1743 | + if ($bstream==null) {
|
|
| 1744 | 1744 | return null; |
| 1745 | 1745 | } |
| 1746 | 1746 | |
| 1747 | 1747 | $ret = $this->appendPaddingBit($bstream); |
| 1748 | - if($ret < 0) {
|
|
| 1748 | + if ($ret<0) {
|
|
| 1749 | 1749 | return null; |
| 1750 | 1750 | } |
| 1751 | 1751 | |
@@ -1756,7 +1756,7 @@ discard block |
||
| 1756 | 1756 | public function getByteStream() |
| 1757 | 1757 | {
|
| 1758 | 1758 | $bstream = $this->getBitStream(); |
| 1759 | - if($bstream == null) {
|
|
| 1759 | + if ($bstream==null) {
|
|
| 1760 | 1760 | return null; |
| 1761 | 1761 | } |
| 1762 | 1762 | |
@@ -1824,8 +1824,8 @@ discard block |
||
| 1824 | 1824 | $bstream->allocate($bits); |
| 1825 | 1825 | |
| 1826 | 1826 | $mask = 1 << ($bits - 1); |
| 1827 | - for($i=0; $i<$bits; $i++) {
|
|
| 1828 | - if($num & $mask) {
|
|
| 1827 | + for ($i = 0; $i<$bits; $i++) {
|
|
| 1828 | + if ($num & $mask) {
|
|
| 1829 | 1829 | $bstream->data[$i] = 1; |
| 1830 | 1830 | } else {
|
| 1831 | 1831 | $bstream->data[$i] = 0; |
@@ -1841,12 +1841,12 @@ discard block |
||
| 1841 | 1841 | {
|
| 1842 | 1842 | $bstream = new QRbitstream(); |
| 1843 | 1843 | $bstream->allocate($size * 8); |
| 1844 | - $p=0; |
|
| 1844 | + $p = 0; |
|
| 1845 | 1845 | |
| 1846 | - for($i=0; $i<$size; $i++) {
|
|
| 1846 | + for ($i = 0; $i<$size; $i++) {
|
|
| 1847 | 1847 | $mask = 0x80; |
| 1848 | - for($j=0; $j<8; $j++) {
|
|
| 1849 | - if($data[$i] & $mask) {
|
|
| 1848 | + for ($j = 0; $j<8; $j++) {
|
|
| 1849 | + if ($data[$i] & $mask) {
|
|
| 1850 | 1850 | $bstream->data[$p] = 1; |
| 1851 | 1851 | } else {
|
| 1852 | 1852 | $bstream->data[$p] = 0; |
@@ -1866,11 +1866,11 @@ discard block |
||
| 1866 | 1866 | return -1; |
| 1867 | 1867 | } |
| 1868 | 1868 | |
| 1869 | - if($arg->size() == 0) {
|
|
| 1869 | + if ($arg->size()==0) {
|
|
| 1870 | 1870 | return 0; |
| 1871 | 1871 | } |
| 1872 | 1872 | |
| 1873 | - if($this->size() == 0) {
|
|
| 1873 | + if ($this->size()==0) {
|
|
| 1874 | 1874 | $this->data = $arg->data; |
| 1875 | 1875 | return 0; |
| 1876 | 1876 | } |
@@ -1883,12 +1883,12 @@ discard block |
||
| 1883 | 1883 | //---------------------------------------------------------------------- |
| 1884 | 1884 | public function appendNum($bits, $num) |
| 1885 | 1885 | {
|
| 1886 | - if ($bits == 0) |
|
| 1886 | + if ($bits==0) |
|
| 1887 | 1887 | return 0; |
| 1888 | 1888 | |
| 1889 | 1889 | $b = QRbitstream::newFromNum($bits, $num); |
| 1890 | 1890 | |
| 1891 | - if(is_null($b)) |
|
| 1891 | + if (is_null($b)) |
|
| 1892 | 1892 | return -1; |
| 1893 | 1893 | |
| 1894 | 1894 | $ret = $this->append($b); |
@@ -1900,12 +1900,12 @@ discard block |
||
| 1900 | 1900 | //---------------------------------------------------------------------- |
| 1901 | 1901 | public function appendBytes($size, $data) |
| 1902 | 1902 | {
|
| 1903 | - if ($size == 0) |
|
| 1903 | + if ($size==0) |
|
| 1904 | 1904 | return 0; |
| 1905 | 1905 | |
| 1906 | 1906 | $b = QRbitstream::newFromBytes($size, $data); |
| 1907 | 1907 | |
| 1908 | - if(is_null($b)) |
|
| 1908 | + if (is_null($b)) |
|
| 1909 | 1909 | return -1; |
| 1910 | 1910 | |
| 1911 | 1911 | $ret = $this->append($b); |
@@ -1920,7 +1920,7 @@ discard block |
||
| 1920 | 1920 | |
| 1921 | 1921 | $size = $this->size(); |
| 1922 | 1922 | |
| 1923 | - if($size == 0) {
|
|
| 1923 | + if ($size==0) {
|
|
| 1924 | 1924 | return array(); |
| 1925 | 1925 | } |
| 1926 | 1926 | |
@@ -1929,9 +1929,9 @@ discard block |
||
| 1929 | 1929 | |
| 1930 | 1930 | $p = 0; |
| 1931 | 1931 | |
| 1932 | - for($i=0; $i<$bytes; $i++) {
|
|
| 1932 | + for ($i = 0; $i<$bytes; $i++) {
|
|
| 1933 | 1933 | $v = 0; |
| 1934 | - for($j=0; $j<8; $j++) {
|
|
| 1934 | + for ($j = 0; $j<8; $j++) {
|
|
| 1935 | 1935 | $v = $v << 1; |
| 1936 | 1936 | $v |= $this->data[$p]; |
| 1937 | 1937 | $p++; |
@@ -1939,9 +1939,9 @@ discard block |
||
| 1939 | 1939 | $data[$i] = $v; |
| 1940 | 1940 | } |
| 1941 | 1941 | |
| 1942 | - if($size & 7) {
|
|
| 1942 | + if ($size & 7) {
|
|
| 1943 | 1943 | $v = 0; |
| 1944 | - for($j=0; $j<($size & 7); $j++) {
|
|
| 1944 | + for ($j = 0; $j<($size & 7); $j++) {
|
|
| 1945 | 1945 | $v = $v << 1; |
| 1946 | 1946 | $v |= $this->data[$p]; |
| 1947 | 1947 | $p++; |
@@ -2010,40 +2010,40 @@ discard block |
||
| 2010 | 2010 | //---------------------------------------------------------------------- |
| 2011 | 2011 | public static function isdigitat($str, $pos) |
| 2012 | 2012 | {
|
| 2013 | - if ($pos >= strlen($str)) |
|
| 2013 | + if ($pos>=strlen($str)) |
|
| 2014 | 2014 | return false; |
| 2015 | 2015 | |
| 2016 | - return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9')));
|
|
| 2016 | + return ((ord($str[$pos])>=ord('0')) && (ord($str[$pos])<=ord('9')));
|
|
| 2017 | 2017 | } |
| 2018 | 2018 | |
| 2019 | 2019 | //---------------------------------------------------------------------- |
| 2020 | 2020 | public static function isalnumat($str, $pos) |
| 2021 | 2021 | {
|
| 2022 | - if ($pos >= strlen($str)) |
|
| 2022 | + if ($pos>=strlen($str)) |
|
| 2023 | 2023 | return false; |
| 2024 | 2024 | |
| 2025 | - return (QRinput::lookAnTable(ord($str[$pos])) >= 0); |
|
| 2025 | + return (QRinput::lookAnTable(ord($str[$pos]))>=0); |
|
| 2026 | 2026 | } |
| 2027 | 2027 | |
| 2028 | 2028 | //---------------------------------------------------------------------- |
| 2029 | 2029 | public function identifyMode($pos) |
| 2030 | 2030 | {
|
| 2031 | - if ($pos >= strlen($this->dataStr)) |
|
| 2031 | + if ($pos>=strlen($this->dataStr)) |
|
| 2032 | 2032 | return QR_MODE_NUL; |
| 2033 | 2033 | |
| 2034 | 2034 | $c = $this->dataStr[$pos]; |
| 2035 | 2035 | |
| 2036 | - if(self::isdigitat($this->dataStr, $pos)) {
|
|
| 2036 | + if (self::isdigitat($this->dataStr, $pos)) {
|
|
| 2037 | 2037 | return QR_MODE_NUM; |
| 2038 | - } else if(self::isalnumat($this->dataStr, $pos)) {
|
|
| 2038 | + } else if (self::isalnumat($this->dataStr, $pos)) {
|
|
| 2039 | 2039 | return QR_MODE_AN; |
| 2040 | - } else if($this->modeHint == QR_MODE_KANJI) {
|
|
| 2040 | + } else if ($this->modeHint==QR_MODE_KANJI) {
|
|
| 2041 | 2041 | |
| 2042 | - if ($pos+1 < strlen($this->dataStr)) |
|
| 2042 | + if ($pos + 1<strlen($this->dataStr)) |
|
| 2043 | 2043 | {
|
| 2044 | - $d = $this->dataStr[$pos+1]; |
|
| 2044 | + $d = $this->dataStr[$pos + 1]; |
|
| 2045 | 2045 | $word = (ord($c) << 8) | ord($d); |
| 2046 | - if(($word >= 0x8140 && $word <= 0x9ffc) || ($word >= 0xe040 && $word <= 0xebbf)) {
|
|
| 2046 | + if (($word>=0x8140 && $word<=0x9ffc) || ($word>=0xe040 && $word<=0xebbf)) {
|
|
| 2047 | 2047 | return QR_MODE_KANJI; |
| 2048 | 2048 | } |
| 2049 | 2049 | } |
@@ -2058,32 +2058,32 @@ discard block |
||
| 2058 | 2058 | $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion()); |
| 2059 | 2059 | |
| 2060 | 2060 | $p = 0; |
| 2061 | - while(self::isdigitat($this->dataStr, $p)) {
|
|
| 2061 | + while (self::isdigitat($this->dataStr, $p)) {
|
|
| 2062 | 2062 | $p++; |
| 2063 | 2063 | } |
| 2064 | 2064 | |
| 2065 | 2065 | $run = $p; |
| 2066 | 2066 | $mode = $this->identifyMode($p); |
| 2067 | 2067 | |
| 2068 | - if($mode == QR_MODE_8) {
|
|
| 2068 | + if ($mode==QR_MODE_8) {
|
|
| 2069 | 2069 | $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln |
| 2070 | 2070 | + QRinput::estimateBitsMode8(1) // + 4 + l8 |
| 2071 | 2071 | - QRinput::estimateBitsMode8($run + 1); // - 4 - l8 |
| 2072 | - if($dif > 0) {
|
|
| 2072 | + if ($dif>0) {
|
|
| 2073 | 2073 | return $this->eat8(); |
| 2074 | 2074 | } |
| 2075 | 2075 | } |
| 2076 | - if($mode == QR_MODE_AN) {
|
|
| 2076 | + if ($mode==QR_MODE_AN) {
|
|
| 2077 | 2077 | $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln |
| 2078 | 2078 | + QRinput::estimateBitsModeAn(1) // + 4 + la |
| 2079 | - - QRinput::estimateBitsModeAn($run + 1);// - 4 - la |
|
| 2080 | - if($dif > 0) {
|
|
| 2079 | + - QRinput::estimateBitsModeAn($run + 1); // - 4 - la |
|
| 2080 | + if ($dif>0) {
|
|
| 2081 | 2081 | return $this->eatAn(); |
| 2082 | 2082 | } |
| 2083 | 2083 | } |
| 2084 | 2084 | |
| 2085 | 2085 | $ret = $this->input->append(QR_MODE_NUM, $run, str_split($this->dataStr)); |
| 2086 | - if($ret < 0) |
|
| 2086 | + if ($ret<0) |
|
| 2087 | 2087 | return -1; |
| 2088 | 2088 | |
| 2089 | 2089 | return $run; |
@@ -2092,15 +2092,15 @@ discard block |
||
| 2092 | 2092 | //---------------------------------------------------------------------- |
| 2093 | 2093 | public function eatAn() |
| 2094 | 2094 | {
|
| 2095 | - $la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion()); |
|
| 2095 | + $la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion()); |
|
| 2096 | 2096 | $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion()); |
| 2097 | 2097 | |
| 2098 | 2098 | $p = 0; |
| 2099 | 2099 | |
| 2100 | - while(self::isalnumat($this->dataStr, $p)) {
|
|
| 2101 | - if(self::isdigitat($this->dataStr, $p)) {
|
|
| 2100 | + while (self::isalnumat($this->dataStr, $p)) {
|
|
| 2101 | + if (self::isdigitat($this->dataStr, $p)) {
|
|
| 2102 | 2102 | $q = $p; |
| 2103 | - while(self::isdigitat($this->dataStr, $q)) {
|
|
| 2103 | + while (self::isdigitat($this->dataStr, $q)) {
|
|
| 2104 | 2104 | $q++; |
| 2105 | 2105 | } |
| 2106 | 2106 | |
@@ -2108,7 +2108,7 @@ discard block |
||
| 2108 | 2108 | + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln |
| 2109 | 2109 | - QRinput::estimateBitsModeAn($q); // - 4 - la |
| 2110 | 2110 | |
| 2111 | - if($dif < 0) {
|
|
| 2111 | + if ($dif<0) {
|
|
| 2112 | 2112 | break; |
| 2113 | 2113 | } else {
|
| 2114 | 2114 | $p = $q; |
@@ -2120,17 +2120,17 @@ discard block |
||
| 2120 | 2120 | |
| 2121 | 2121 | $run = $p; |
| 2122 | 2122 | |
| 2123 | - if(!self::isalnumat($this->dataStr, $p)) {
|
|
| 2123 | + if (!self::isalnumat($this->dataStr, $p)) {
|
|
| 2124 | 2124 | $dif = QRinput::estimateBitsModeAn($run) + 4 + $la |
| 2125 | 2125 | + QRinput::estimateBitsMode8(1) // + 4 + l8 |
| 2126 | 2126 | - QRinput::estimateBitsMode8($run + 1); // - 4 - l8 |
| 2127 | - if($dif > 0) {
|
|
| 2127 | + if ($dif>0) {
|
|
| 2128 | 2128 | return $this->eat8(); |
| 2129 | 2129 | } |
| 2130 | 2130 | } |
| 2131 | 2131 | |
| 2132 | 2132 | $ret = $this->input->append(QR_MODE_AN, $run, str_split($this->dataStr)); |
| 2133 | - if($ret < 0) |
|
| 2133 | + if ($ret<0) |
|
| 2134 | 2134 | return -1; |
| 2135 | 2135 | |
| 2136 | 2136 | return $run; |
@@ -2141,12 +2141,12 @@ discard block |
||
| 2141 | 2141 | {
|
| 2142 | 2142 | $p = 0; |
| 2143 | 2143 | |
| 2144 | - while($this->identifyMode($p) == QR_MODE_KANJI) {
|
|
| 2144 | + while ($this->identifyMode($p)==QR_MODE_KANJI) {
|
|
| 2145 | 2145 | $p += 2; |
| 2146 | 2146 | } |
| 2147 | 2147 | |
| 2148 | 2148 | $ret = $this->input->append(QR_MODE_KANJI, $p, str_split($this->dataStr)); |
| 2149 | - if($ret < 0) |
|
| 2149 | + if ($ret<0) |
|
| 2150 | 2150 | return -1; |
| 2151 | 2151 | |
| 2152 | 2152 | return $ret; |
@@ -2161,34 +2161,34 @@ discard block |
||
| 2161 | 2161 | $p = 1; |
| 2162 | 2162 | $dataStrLen = strlen($this->dataStr); |
| 2163 | 2163 | |
| 2164 | - while($p < $dataStrLen) {
|
|
| 2164 | + while ($p<$dataStrLen) {
|
|
| 2165 | 2165 | |
| 2166 | 2166 | $mode = $this->identifyMode($p); |
| 2167 | - if($mode == QR_MODE_KANJI) {
|
|
| 2167 | + if ($mode==QR_MODE_KANJI) {
|
|
| 2168 | 2168 | break; |
| 2169 | 2169 | } |
| 2170 | - if($mode == QR_MODE_NUM) {
|
|
| 2170 | + if ($mode==QR_MODE_NUM) {
|
|
| 2171 | 2171 | $q = $p; |
| 2172 | - while(self::isdigitat($this->dataStr, $q)) {
|
|
| 2172 | + while (self::isdigitat($this->dataStr, $q)) {
|
|
| 2173 | 2173 | $q++; |
| 2174 | 2174 | } |
| 2175 | 2175 | $dif = QRinput::estimateBitsMode8($p) // + 4 + l8 |
| 2176 | 2176 | + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln |
| 2177 | 2177 | - QRinput::estimateBitsMode8($q); // - 4 - l8 |
| 2178 | - if($dif < 0) {
|
|
| 2178 | + if ($dif<0) {
|
|
| 2179 | 2179 | break; |
| 2180 | 2180 | } else {
|
| 2181 | 2181 | $p = $q; |
| 2182 | 2182 | } |
| 2183 | - } else if($mode == QR_MODE_AN) {
|
|
| 2183 | + } else if ($mode==QR_MODE_AN) {
|
|
| 2184 | 2184 | $q = $p; |
| 2185 | - while(self::isalnumat($this->dataStr, $q)) {
|
|
| 2185 | + while (self::isalnumat($this->dataStr, $q)) {
|
|
| 2186 | 2186 | $q++; |
| 2187 | 2187 | } |
| 2188 | 2188 | $dif = QRinput::estimateBitsMode8($p) // + 4 + l8 |
| 2189 | 2189 | + QRinput::estimateBitsModeAn($q - $p) + 4 + $la |
| 2190 | 2190 | - QRinput::estimateBitsMode8($q); // - 4 - l8 |
| 2191 | - if($dif < 0) {
|
|
| 2191 | + if ($dif<0) {
|
|
| 2192 | 2192 | break; |
| 2193 | 2193 | } else {
|
| 2194 | 2194 | $p = $q; |
@@ -2201,7 +2201,7 @@ discard block |
||
| 2201 | 2201 | $run = $p; |
| 2202 | 2202 | $ret = $this->input->append(QR_MODE_8, $run, str_split($this->dataStr)); |
| 2203 | 2203 | |
| 2204 | - if($ret < 0) |
|
| 2204 | + if ($ret<0) |
|
| 2205 | 2205 | return -1; |
| 2206 | 2206 | |
| 2207 | 2207 | return $run; |
@@ -2210,9 +2210,9 @@ discard block |
||
| 2210 | 2210 | //---------------------------------------------------------------------- |
| 2211 | 2211 | public function splitString() |
| 2212 | 2212 | {
|
| 2213 | - while (strlen($this->dataStr) > 0) |
|
| 2213 | + while (strlen($this->dataStr)>0) |
|
| 2214 | 2214 | {
|
| 2215 | - if($this->dataStr == '') |
|
| 2215 | + if ($this->dataStr=='') |
|
| 2216 | 2216 | return 0; |
| 2217 | 2217 | |
| 2218 | 2218 | $mode = $this->identifyMode(0); |
@@ -2221,7 +2221,7 @@ discard block |
||
| 2221 | 2221 | case QR_MODE_NUM: $length = $this->eatNum(); break; |
| 2222 | 2222 | case QR_MODE_AN: $length = $this->eatAn(); break; |
| 2223 | 2223 | case QR_MODE_KANJI: |
| 2224 | - if ($mode == QR_MODE_KANJI) |
|
| 2224 | + if ($mode==QR_MODE_KANJI) |
|
| 2225 | 2225 | $length = $this->eatKanji(); |
| 2226 | 2226 | else $length = $this->eat8(); |
| 2227 | 2227 | break; |
@@ -2229,8 +2229,8 @@ discard block |
||
| 2229 | 2229 | |
| 2230 | 2230 | } |
| 2231 | 2231 | |
| 2232 | - if($length == 0) return 0; |
|
| 2233 | - if($length < 0) return -1; |
|
| 2232 | + if ($length==0) return 0; |
|
| 2233 | + if ($length<0) return -1; |
|
| 2234 | 2234 | |
| 2235 | 2235 | $this->dataStr = substr($this->dataStr, $length); |
| 2236 | 2236 | } |
@@ -2244,10 +2244,10 @@ discard block |
||
| 2244 | 2244 | |
| 2245 | 2245 | while ($p<$stringLen) {
|
| 2246 | 2246 | $mode = self::identifyMode(substr($this->dataStr, $p), $this->modeHint); |
| 2247 | - if($mode == QR_MODE_KANJI) {
|
|
| 2247 | + if ($mode==QR_MODE_KANJI) {
|
|
| 2248 | 2248 | $p += 2; |
| 2249 | 2249 | } else {
|
| 2250 | - if (ord($this->dataStr[$p]) >= ord('a') && ord($this->dataStr[$p]) <= ord('z')) {
|
|
| 2250 | + if (ord($this->dataStr[$p])>=ord('a') && ord($this->dataStr[$p])<=ord('z')) {
|
|
| 2251 | 2251 | $this->dataStr[$p] = chr(ord($this->dataStr[$p]) - 32); |
| 2252 | 2252 | } |
| 2253 | 2253 | $p++; |
@@ -2260,13 +2260,13 @@ discard block |
||
| 2260 | 2260 | //---------------------------------------------------------------------- |
| 2261 | 2261 | public static function splitStringToQRinput($string, QRinput $input, $modeHint, $casesensitive = true) |
| 2262 | 2262 | {
|
| 2263 | - if(is_null($string) || $string == '\0' || $string == '') {
|
|
| 2263 | + if (is_null($string) || $string=='\0' || $string=='') {
|
|
| 2264 | 2264 | throw new Exception('empty string!!!');
|
| 2265 | 2265 | } |
| 2266 | 2266 | |
| 2267 | 2267 | $split = new QRsplit($string, $input, $modeHint); |
| 2268 | 2268 | |
| 2269 | - if(!$casesensitive) |
|
| 2269 | + if (!$casesensitive) |
|
| 2270 | 2270 | $split->toUpper(); |
| 2271 | 2271 | |
| 2272 | 2272 | return $split->splitString(); |
@@ -2311,22 +2311,22 @@ discard block |
||
| 2311 | 2311 | |
| 2312 | 2312 | class QRrsItem {
|
| 2313 | 2313 | |
| 2314 | - public $mm; // Bits per symbol |
|
| 2315 | - public $nn; // Symbols per block (= (1<<mm)-1) |
|
| 2316 | - public $alpha_to = array(); // log lookup table |
|
| 2317 | - public $index_of = array(); // Antilog lookup table |
|
| 2318 | - public $genpoly = array(); // Generator polynomial |
|
| 2319 | - public $nroots; // Number of generator roots = number of parity symbols |
|
| 2320 | - public $fcr; // First consecutive root, index form |
|
| 2321 | - public $prim; // Primitive element, index form |
|
| 2322 | - public $iprim; // prim-th root of 1, index form |
|
| 2323 | - public $pad; // Padding bytes in shortened block |
|
| 2314 | + public $mm; // Bits per symbol |
|
| 2315 | + public $nn; // Symbols per block (= (1<<mm)-1) |
|
| 2316 | + public $alpha_to = array(); // log lookup table |
|
| 2317 | + public $index_of = array(); // Antilog lookup table |
|
| 2318 | + public $genpoly = array(); // Generator polynomial |
|
| 2319 | + public $nroots; // Number of generator roots = number of parity symbols |
|
| 2320 | + public $fcr; // First consecutive root, index form |
|
| 2321 | + public $prim; // Primitive element, index form |
|
| 2322 | + public $iprim; // prim-th root of 1, index form |
|
| 2323 | + public $pad; // Padding bytes in shortened block |
|
| 2324 | 2324 | public $gfpoly; |
| 2325 | 2325 | |
| 2326 | 2326 | //---------------------------------------------------------------------- |
| 2327 | 2327 | public function modnn($x) |
| 2328 | 2328 | {
|
| 2329 | - while ($x >= $this->nn) {
|
|
| 2329 | + while ($x>=$this->nn) {
|
|
| 2330 | 2330 | $x -= $this->nn; |
| 2331 | 2331 | $x = ($x >> $this->mm) + ($x & $this->nn); |
| 2332 | 2332 | } |
@@ -2344,47 +2344,47 @@ discard block |
||
| 2344 | 2344 | $rs = null; |
| 2345 | 2345 | |
| 2346 | 2346 | // Check parameter ranges |
| 2347 | - if($symsize < 0 || $symsize > 8) return $rs; |
|
| 2348 | - if($fcr < 0 || $fcr >= (1<<$symsize)) return $rs; |
|
| 2349 | - if($prim <= 0 || $prim >= (1<<$symsize)) return $rs; |
|
| 2350 | - if($nroots < 0 || $nroots >= (1<<$symsize)) return $rs; // Can't have more roots than symbol values! |
|
| 2351 | - if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) return $rs; // Too much padding |
|
| 2347 | + if ($symsize<0 || $symsize>8) return $rs; |
|
| 2348 | + if ($fcr<0 || $fcr>=(1 << $symsize)) return $rs; |
|
| 2349 | + if ($prim<=0 || $prim>=(1 << $symsize)) return $rs; |
|
| 2350 | + if ($nroots<0 || $nroots>=(1 << $symsize)) return $rs; // Can't have more roots than symbol values! |
|
| 2351 | + if ($pad<0 || $pad>=((1 << $symsize) - 1 - $nroots)) return $rs; // Too much padding |
|
| 2352 | 2352 | |
| 2353 | 2353 | $rs = new QRrsItem(); |
| 2354 | 2354 | $rs->mm = $symsize; |
| 2355 | - $rs->nn = (1<<$symsize)-1; |
|
| 2355 | + $rs->nn = (1 << $symsize) - 1; |
|
| 2356 | 2356 | $rs->pad = $pad; |
| 2357 | 2357 | |
| 2358 | - $rs->alpha_to = array_fill(0, $rs->nn+1, 0); |
|
| 2359 | - $rs->index_of = array_fill(0, $rs->nn+1, 0); |
|
| 2358 | + $rs->alpha_to = array_fill(0, $rs->nn + 1, 0); |
|
| 2359 | + $rs->index_of = array_fill(0, $rs->nn + 1, 0); |
|
| 2360 | 2360 | |
| 2361 | 2361 | // PHP style macro replacement ;) |
| 2362 | - $NN =& $rs->nn; |
|
| 2363 | - $A0 =& $NN; |
|
| 2362 | + $NN = & $rs->nn; |
|
| 2363 | + $A0 = & $NN; |
|
| 2364 | 2364 | |
| 2365 | 2365 | // Generate Galois field lookup tables |
| 2366 | 2366 | $rs->index_of[0] = $A0; // log(zero) = -inf |
| 2367 | 2367 | $rs->alpha_to[$A0] = 0; // alpha**-inf = 0 |
| 2368 | 2368 | $sr = 1; |
| 2369 | 2369 | |
| 2370 | - for($i=0; $i<$rs->nn; $i++) {
|
|
| 2370 | + for ($i = 0; $i<$rs->nn; $i++) {
|
|
| 2371 | 2371 | $rs->index_of[$sr] = $i; |
| 2372 | 2372 | $rs->alpha_to[$i] = $sr; |
| 2373 | 2373 | $sr <<= 1; |
| 2374 | - if($sr & (1<<$symsize)) {
|
|
| 2374 | + if ($sr & (1 << $symsize)) {
|
|
| 2375 | 2375 | $sr ^= $gfpoly; |
| 2376 | 2376 | } |
| 2377 | 2377 | $sr &= $rs->nn; |
| 2378 | 2378 | } |
| 2379 | 2379 | |
| 2380 | - if($sr != 1){
|
|
| 2380 | + if ($sr!=1) {
|
|
| 2381 | 2381 | // field generator polynomial is not primitive! |
| 2382 | 2382 | $rs = NULL; |
| 2383 | 2383 | return $rs; |
| 2384 | 2384 | } |
| 2385 | 2385 | |
| 2386 | 2386 | /* Form RS code generator polynomial from its roots */ |
| 2387 | - $rs->genpoly = array_fill(0, $nroots+1, 0); |
|
| 2387 | + $rs->genpoly = array_fill(0, $nroots + 1, 0); |
|
| 2388 | 2388 | |
| 2389 | 2389 | $rs->fcr = $fcr; |
| 2390 | 2390 | $rs->prim = $prim; |
@@ -2392,21 +2392,21 @@ discard block |
||
| 2392 | 2392 | $rs->gfpoly = $gfpoly; |
| 2393 | 2393 | |
| 2394 | 2394 | /* Find prim-th root of 1, used in decoding */ |
| 2395 | - for($iprim=1;($iprim % $prim) != 0;$iprim += $rs->nn) |
|
| 2395 | + for ($iprim = 1; ($iprim % $prim)!=0; $iprim += $rs->nn) |
|
| 2396 | 2396 | ; // intentional empty-body loop! |
| 2397 | 2397 | |
| 2398 | 2398 | $rs->iprim = (int)($iprim / $prim); |
| 2399 | 2399 | $rs->genpoly[0] = 1; |
| 2400 | 2400 | |
| 2401 | - for ($i = 0,$root=$fcr*$prim; $i < $nroots; $i++, $root += $prim) {
|
|
| 2402 | - $rs->genpoly[$i+1] = 1; |
|
| 2401 | + for ($i = 0, $root = $fcr * $prim; $i<$nroots; $i++, $root += $prim) {
|
|
| 2402 | + $rs->genpoly[$i + 1] = 1; |
|
| 2403 | 2403 | |
| 2404 | 2404 | // Multiply rs->genpoly[] by @**(root + x) |
| 2405 | - for ($j = $i; $j > 0; $j--) {
|
|
| 2406 | - if ($rs->genpoly[$j] != 0) {
|
|
| 2407 | - $rs->genpoly[$j] = $rs->genpoly[$j-1] ^ $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[$j]] + $root)]; |
|
| 2405 | + for ($j = $i; $j>0; $j--) {
|
|
| 2406 | + if ($rs->genpoly[$j]!=0) {
|
|
| 2407 | + $rs->genpoly[$j] = $rs->genpoly[$j - 1] ^ $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[$j]] + $root)]; |
|
| 2408 | 2408 | } else {
|
| 2409 | - $rs->genpoly[$j] = $rs->genpoly[$j-1]; |
|
| 2409 | + $rs->genpoly[$j] = $rs->genpoly[$j - 1]; |
|
| 2410 | 2410 | } |
| 2411 | 2411 | } |
| 2412 | 2412 | // rs->genpoly[0] can never be zero |
@@ -2414,7 +2414,7 @@ discard block |
||
| 2414 | 2414 | } |
| 2415 | 2415 | |
| 2416 | 2416 | // convert rs->genpoly[] to index form for quicker encoding |
| 2417 | - for ($i = 0; $i <= $nroots; $i++) |
|
| 2417 | + for ($i = 0; $i<=$nroots; $i++) |
|
| 2418 | 2418 | $rs->genpoly[$i] = $rs->index_of[$rs->genpoly[$i]]; |
| 2419 | 2419 | |
| 2420 | 2420 | return $rs; |
@@ -2423,38 +2423,38 @@ discard block |
||
| 2423 | 2423 | //---------------------------------------------------------------------- |
| 2424 | 2424 | public function encode_rs_char($data, &$parity) |
| 2425 | 2425 | {
|
| 2426 | - $MM =& $this->mm; |
|
| 2427 | - $NN =& $this->nn; |
|
| 2428 | - $ALPHA_TO =& $this->alpha_to; |
|
| 2429 | - $INDEX_OF =& $this->index_of; |
|
| 2430 | - $GENPOLY =& $this->genpoly; |
|
| 2431 | - $NROOTS =& $this->nroots; |
|
| 2432 | - $FCR =& $this->fcr; |
|
| 2433 | - $PRIM =& $this->prim; |
|
| 2434 | - $IPRIM =& $this->iprim; |
|
| 2435 | - $PAD =& $this->pad; |
|
| 2436 | - $A0 =& $NN; |
|
| 2426 | + $MM = & $this->mm; |
|
| 2427 | + $NN = & $this->nn; |
|
| 2428 | + $ALPHA_TO = & $this->alpha_to; |
|
| 2429 | + $INDEX_OF = & $this->index_of; |
|
| 2430 | + $GENPOLY = & $this->genpoly; |
|
| 2431 | + $NROOTS = & $this->nroots; |
|
| 2432 | + $FCR = & $this->fcr; |
|
| 2433 | + $PRIM = & $this->prim; |
|
| 2434 | + $IPRIM = & $this->iprim; |
|
| 2435 | + $PAD = & $this->pad; |
|
| 2436 | + $A0 = & $NN; |
|
| 2437 | 2437 | |
| 2438 | 2438 | $parity = array_fill(0, $NROOTS, 0); |
| 2439 | 2439 | |
| 2440 | - for($i=0; $i< ($NN-$NROOTS-$PAD); $i++) {
|
|
| 2440 | + for ($i = 0; $i<($NN - $NROOTS - $PAD); $i++) {
|
|
| 2441 | 2441 | |
| 2442 | 2442 | $feedback = $INDEX_OF[$data[$i] ^ $parity[0]]; |
| 2443 | - if($feedback != $A0) {
|
|
| 2443 | + if ($feedback!=$A0) {
|
|
| 2444 | 2444 | // feedback term is non-zero |
| 2445 | 2445 | |
| 2446 | 2446 | // This line is unnecessary when GENPOLY[NROOTS] is unity, as it must |
| 2447 | 2447 | // always be for the polynomials constructed by init_rs() |
| 2448 | 2448 | $feedback = $this->modnn($NN - $GENPOLY[$NROOTS] + $feedback); |
| 2449 | 2449 | |
| 2450 | - for($j=1;$j<$NROOTS;$j++) {
|
|
| 2451 | - $parity[$j] ^= $ALPHA_TO[$this->modnn($feedback + $GENPOLY[$NROOTS-$j])]; |
|
| 2450 | + for ($j = 1; $j<$NROOTS; $j++) {
|
|
| 2451 | + $parity[$j] ^= $ALPHA_TO[$this->modnn($feedback + $GENPOLY[$NROOTS - $j])]; |
|
| 2452 | 2452 | } |
| 2453 | 2453 | } |
| 2454 | 2454 | |
| 2455 | 2455 | // Shift |
| 2456 | 2456 | array_shift($parity); |
| 2457 | - if($feedback != $A0) {
|
|
| 2457 | + if ($feedback!=$A0) {
|
|
| 2458 | 2458 | array_push($parity, $ALPHA_TO[$this->modnn($feedback + $GENPOLY[0])]); |
| 2459 | 2459 | } else {
|
| 2460 | 2460 | array_push($parity, 0); |
@@ -2472,13 +2472,13 @@ discard block |
||
| 2472 | 2472 | //---------------------------------------------------------------------- |
| 2473 | 2473 | public static function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) |
| 2474 | 2474 | {
|
| 2475 | - foreach(self::$items as $rs) {
|
|
| 2476 | - if($rs->pad != $pad) continue; |
|
| 2477 | - if($rs->nroots != $nroots) continue; |
|
| 2478 | - if($rs->mm != $symsize) continue; |
|
| 2479 | - if($rs->gfpoly != $gfpoly) continue; |
|
| 2480 | - if($rs->fcr != $fcr) continue; |
|
| 2481 | - if($rs->prim != $prim) continue; |
|
| 2475 | + foreach (self::$items as $rs) {
|
|
| 2476 | + if ($rs->pad!=$pad) continue; |
|
| 2477 | + if ($rs->nroots!=$nroots) continue; |
|
| 2478 | + if ($rs->mm!=$symsize) continue; |
|
| 2479 | + if ($rs->gfpoly!=$gfpoly) continue; |
|
| 2480 | + if ($rs->fcr!=$fcr) continue; |
|
| 2481 | + if ($rs->prim!=$prim) continue; |
|
| 2482 | 2482 | |
| 2483 | 2483 | return $rs; |
| 2484 | 2484 | } |
@@ -2542,10 +2542,10 @@ discard block |
||
| 2542 | 2542 | public function writeFormatInformation($width, &$frame, $mask, $level) |
| 2543 | 2543 | {
|
| 2544 | 2544 | $blacks = 0; |
| 2545 | - $format = QRspec::getFormatInfo($mask, $level); |
|
| 2545 | + $format = QRspec::getFormatInfo($mask, $level); |
|
| 2546 | 2546 | |
| 2547 | - for($i=0; $i<8; $i++) {
|
|
| 2548 | - if($format & 1) {
|
|
| 2547 | + for ($i = 0; $i<8; $i++) {
|
|
| 2548 | + if ($format & 1) {
|
|
| 2549 | 2549 | $blacks += 2; |
| 2550 | 2550 | $v = 0x85; |
| 2551 | 2551 | } else {
|
@@ -2553,7 +2553,7 @@ discard block |
||
| 2553 | 2553 | } |
| 2554 | 2554 | |
| 2555 | 2555 | $frame[8][$width - 1 - $i] = chr($v); |
| 2556 | - if($i < 6) {
|
|
| 2556 | + if ($i<6) {
|
|
| 2557 | 2557 | $frame[$i][8] = chr($v); |
| 2558 | 2558 | } else {
|
| 2559 | 2559 | $frame[$i + 1][8] = chr($v); |
@@ -2561,8 +2561,8 @@ discard block |
||
| 2561 | 2561 | $format = $format >> 1; |
| 2562 | 2562 | } |
| 2563 | 2563 | |
| 2564 | - for($i=0; $i<7; $i++) {
|
|
| 2565 | - if($format & 1) {
|
|
| 2564 | + for ($i = 0; $i<7; $i++) {
|
|
| 2565 | + if ($format & 1) {
|
|
| 2566 | 2566 | $blacks += 2; |
| 2567 | 2567 | $v = 0x85; |
| 2568 | 2568 | } else {
|
@@ -2570,7 +2570,7 @@ discard block |
||
| 2570 | 2570 | } |
| 2571 | 2571 | |
| 2572 | 2572 | $frame[$width - 7 + $i][8] = chr($v); |
| 2573 | - if($i == 0) {
|
|
| 2573 | + if ($i==0) {
|
|
| 2574 | 2574 | $frame[8][7] = chr($v); |
| 2575 | 2575 | } else {
|
| 2576 | 2576 | $frame[8][6 - $i] = chr($v); |
@@ -2583,27 +2583,27 @@ discard block |
||
| 2583 | 2583 | } |
| 2584 | 2584 | |
| 2585 | 2585 | //---------------------------------------------------------------------- |
| 2586 | - public function mask0($x, $y) { return ($x+$y)&1; }
|
|
| 2587 | - public function mask1($x, $y) { return ($y&1); }
|
|
| 2588 | - public function mask2($x, $y) { return ($x%3); }
|
|
| 2589 | - public function mask3($x, $y) { return ($x+$y)%3; }
|
|
| 2590 | - public function mask4($x, $y) { return (((int)($y/2))+((int)($x/3)))&1; }
|
|
| 2591 | - public function mask5($x, $y) { return (($x*$y)&1)+($x*$y)%3; }
|
|
| 2592 | - public function mask6($x, $y) { return ((($x*$y)&1)+($x*$y)%3)&1; }
|
|
| 2593 | - public function mask7($x, $y) { return ((($x*$y)%3)+(($x+$y)&1))&1; }
|
|
| 2586 | + public function mask0($x, $y) { return ($x + $y) & 1; }
|
|
| 2587 | + public function mask1($x, $y) { return ($y & 1); }
|
|
| 2588 | + public function mask2($x, $y) { return ($x % 3); }
|
|
| 2589 | + public function mask3($x, $y) { return ($x + $y) % 3; }
|
|
| 2590 | + public function mask4($x, $y) { return (((int)($y / 2)) + ((int)($x / 3))) & 1; }
|
|
| 2591 | + public function mask5($x, $y) { return (($x * $y) & 1) + ($x * $y) % 3; }
|
|
| 2592 | + public function mask6($x, $y) { return ((($x * $y) & 1) + ($x * $y) % 3) & 1; }
|
|
| 2593 | + public function mask7($x, $y) { return ((($x * $y) % 3) + (($x + $y) & 1)) & 1; }
|
|
| 2594 | 2594 | |
| 2595 | 2595 | //---------------------------------------------------------------------- |
| 2596 | 2596 | private function generateMaskNo($maskNo, $width, $frame) |
| 2597 | 2597 | {
|
| 2598 | 2598 | $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); |
| 2599 | 2599 | |
| 2600 | - for($y=0; $y<$width; $y++) {
|
|
| 2601 | - for($x=0; $x<$width; $x++) {
|
|
| 2602 | - if(ord($frame[$y][$x]) & 0x80) {
|
|
| 2600 | + for ($y = 0; $y<$width; $y++) {
|
|
| 2601 | + for ($x = 0; $x<$width; $x++) {
|
|
| 2602 | + if (ord($frame[$y][$x]) & 0x80) {
|
|
| 2603 | 2603 | $bitMask[$y][$x] = 0; |
| 2604 | 2604 | } else {
|
| 2605 | 2605 | $maskFunc = call_user_func(array($this, 'mask'.$maskNo), $x, $y); |
| 2606 | - $bitMask[$y][$x] = ($maskFunc == 0)?1:0; |
|
| 2606 | + $bitMask[$y][$x] = ($maskFunc==0) ? 1 : 0; |
|
| 2607 | 2607 | } |
| 2608 | 2608 | |
| 2609 | 2609 | } |
@@ -2661,9 +2661,9 @@ discard block |
||
| 2661 | 2661 | |
| 2662 | 2662 | $d = $s; |
| 2663 | 2663 | |
| 2664 | - for($y=0; $y<$width; $y++) {
|
|
| 2665 | - for($x=0; $x<$width; $x++) {
|
|
| 2666 | - if($bitMask[$y][$x] == 1) {
|
|
| 2664 | + for ($y = 0; $y<$width; $y++) {
|
|
| 2665 | + for ($x = 0; $x<$width; $x++) {
|
|
| 2666 | + if ($bitMask[$y][$x]==1) {
|
|
| 2667 | 2667 | $d[$y][$x] = chr(ord($s[$y][$x]) ^ (int)$bitMask[$y][$x]); |
| 2668 | 2668 | } |
| 2669 | 2669 | $b += (int)(ord($d[$y][$x]) & 1); |
@@ -2688,21 +2688,21 @@ discard block |
||
| 2688 | 2688 | {
|
| 2689 | 2689 | $demerit = 0; |
| 2690 | 2690 | |
| 2691 | - for($i=0; $i<$length; $i++) {
|
|
| 2691 | + for ($i = 0; $i<$length; $i++) {
|
|
| 2692 | 2692 | |
| 2693 | - if($this->runLength[$i] >= 5) {
|
|
| 2693 | + if ($this->runLength[$i]>=5) {
|
|
| 2694 | 2694 | $demerit += (N1 + ($this->runLength[$i] - 5)); |
| 2695 | 2695 | } |
| 2696 | - if($i & 1) {
|
|
| 2697 | - if(($i >= 3) && ($i < ($length-2)) && ($this->runLength[$i] % 3 == 0)) {
|
|
| 2696 | + if ($i & 1) {
|
|
| 2697 | + if (($i>=3) && ($i<($length - 2)) && ($this->runLength[$i] % 3==0)) {
|
|
| 2698 | 2698 | $fact = (int)($this->runLength[$i] / 3); |
| 2699 | - if(($this->runLength[$i-2] == $fact) && |
|
| 2700 | - ($this->runLength[$i-1] == $fact) && |
|
| 2701 | - ($this->runLength[$i+1] == $fact) && |
|
| 2702 | - ($this->runLength[$i+2] == $fact)) {
|
|
| 2703 | - if(($this->runLength[$i-3] < 0) || ($this->runLength[$i-3] >= (4 * $fact))) {
|
|
| 2699 | + if (($this->runLength[$i - 2]==$fact) && |
|
| 2700 | + ($this->runLength[$i - 1]==$fact) && |
|
| 2701 | + ($this->runLength[$i + 1]==$fact) && |
|
| 2702 | + ($this->runLength[$i + 2]==$fact)) {
|
|
| 2703 | + if (($this->runLength[$i - 3]<0) || ($this->runLength[$i - 3]>=(4 * $fact))) {
|
|
| 2704 | 2704 | $demerit += N3; |
| 2705 | - } else if((($i+3) >= $length) || ($this->runLength[$i+3] >= (4 * $fact))) {
|
|
| 2705 | + } else if ((($i + 3)>=$length) || ($this->runLength[$i + 3]>=(4 * $fact))) {
|
|
| 2706 | 2706 | $demerit += N3; |
| 2707 | 2707 | } |
| 2708 | 2708 | } |
@@ -2718,30 +2718,30 @@ discard block |
||
| 2718 | 2718 | $head = 0; |
| 2719 | 2719 | $demerit = 0; |
| 2720 | 2720 | |
| 2721 | - for($y=0; $y<$width; $y++) {
|
|
| 2721 | + for ($y = 0; $y<$width; $y++) {
|
|
| 2722 | 2722 | $head = 0; |
| 2723 | 2723 | $this->runLength[0] = 1; |
| 2724 | 2724 | |
| 2725 | 2725 | $frameY = $frame[$y]; |
| 2726 | 2726 | |
| 2727 | 2727 | if ($y>0) |
| 2728 | - $frameYM = $frame[$y-1]; |
|
| 2728 | + $frameYM = $frame[$y - 1]; |
|
| 2729 | 2729 | |
| 2730 | - for($x=0; $x<$width; $x++) {
|
|
| 2731 | - if(($x > 0) && ($y > 0)) {
|
|
| 2732 | - $b22 = ord($frameY[$x]) & ord($frameY[$x-1]) & ord($frameYM[$x]) & ord($frameYM[$x-1]); |
|
| 2733 | - $w22 = ord($frameY[$x]) | ord($frameY[$x-1]) | ord($frameYM[$x]) | ord($frameYM[$x-1]); |
|
| 2730 | + for ($x = 0; $x<$width; $x++) {
|
|
| 2731 | + if (($x>0) && ($y>0)) {
|
|
| 2732 | + $b22 = ord($frameY[$x]) & ord($frameY[$x - 1]) & ord($frameYM[$x]) & ord($frameYM[$x - 1]); |
|
| 2733 | + $w22 = ord($frameY[$x]) | ord($frameY[$x - 1]) | ord($frameYM[$x]) | ord($frameYM[$x - 1]); |
|
| 2734 | 2734 | |
| 2735 | - if(($b22 | ($w22 ^ 1))&1) {
|
|
| 2735 | + if (($b22 | ($w22 ^ 1)) & 1) {
|
|
| 2736 | 2736 | $demerit += N2; |
| 2737 | 2737 | } |
| 2738 | 2738 | } |
| 2739 | - if(($x == 0) && (ord($frameY[$x]) & 1)) {
|
|
| 2739 | + if (($x==0) && (ord($frameY[$x]) & 1)) {
|
|
| 2740 | 2740 | $this->runLength[0] = -1; |
| 2741 | 2741 | $head = 1; |
| 2742 | 2742 | $this->runLength[$head] = 1; |
| 2743 | - } else if($x > 0) {
|
|
| 2744 | - if((ord($frameY[$x]) ^ ord($frameY[$x-1])) & 1) {
|
|
| 2743 | + } else if ($x>0) {
|
|
| 2744 | + if ((ord($frameY[$x]) ^ ord($frameY[$x - 1])) & 1) {
|
|
| 2745 | 2745 | $head++; |
| 2746 | 2746 | $this->runLength[$head] = 1; |
| 2747 | 2747 | } else {
|
@@ -2750,20 +2750,20 @@ discard block |
||
| 2750 | 2750 | } |
| 2751 | 2751 | } |
| 2752 | 2752 | |
| 2753 | - $demerit += $this->calcN1N3($head+1); |
|
| 2753 | + $demerit += $this->calcN1N3($head + 1); |
|
| 2754 | 2754 | } |
| 2755 | 2755 | |
| 2756 | - for($x=0; $x<$width; $x++) {
|
|
| 2756 | + for ($x = 0; $x<$width; $x++) {
|
|
| 2757 | 2757 | $head = 0; |
| 2758 | 2758 | $this->runLength[0] = 1; |
| 2759 | 2759 | |
| 2760 | - for($y=0; $y<$width; $y++) {
|
|
| 2761 | - if($y == 0 && (ord($frame[$y][$x]) & 1)) {
|
|
| 2760 | + for ($y = 0; $y<$width; $y++) {
|
|
| 2761 | + if ($y==0 && (ord($frame[$y][$x]) & 1)) {
|
|
| 2762 | 2762 | $this->runLength[0] = -1; |
| 2763 | 2763 | $head = 1; |
| 2764 | 2764 | $this->runLength[$head] = 1; |
| 2765 | - } else if($y > 0) {
|
|
| 2766 | - if((ord($frame[$y][$x]) ^ ord($frame[$y-1][$x])) & 1) {
|
|
| 2765 | + } else if ($y>0) {
|
|
| 2766 | + if ((ord($frame[$y][$x]) ^ ord($frame[$y - 1][$x])) & 1) {
|
|
| 2767 | 2767 | $head++; |
| 2768 | 2768 | $this->runLength[$head] = 1; |
| 2769 | 2769 | } else {
|
@@ -2772,7 +2772,7 @@ discard block |
||
| 2772 | 2772 | } |
| 2773 | 2773 | } |
| 2774 | 2774 | |
| 2775 | - $demerit += $this->calcN1N3($head+1); |
|
| 2775 | + $demerit += $this->calcN1N3($head + 1); |
|
| 2776 | 2776 | } |
| 2777 | 2777 | |
| 2778 | 2778 | return $demerit; |
@@ -2786,13 +2786,13 @@ discard block |
||
| 2786 | 2786 | $bestMaskNum = 0; |
| 2787 | 2787 | $bestMask = array(); |
| 2788 | 2788 | |
| 2789 | - $checked_masks = array(0,1,2,3,4,5,6,7); |
|
| 2789 | + $checked_masks = array(0, 1, 2, 3, 4, 5, 6, 7); |
|
| 2790 | 2790 | |
| 2791 | - if (QR_FIND_FROM_RANDOM !== false) {
|
|
| 2791 | + if (QR_FIND_FROM_RANDOM!==false) {
|
|
| 2792 | 2792 | |
| 2793 | - $howManuOut = 8-(QR_FIND_FROM_RANDOM % 9); |
|
| 2794 | - for ($i = 0; $i < $howManuOut; $i++) {
|
|
| 2795 | - $remPos = rand (0, count($checked_masks)-1); |
|
| 2793 | + $howManuOut = 8 - (QR_FIND_FROM_RANDOM % 9); |
|
| 2794 | + for ($i = 0; $i<$howManuOut; $i++) {
|
|
| 2795 | + $remPos = rand(0, count($checked_masks) - 1); |
|
| 2796 | 2796 | unset($checked_masks[$remPos]); |
| 2797 | 2797 | $checked_masks = array_values($checked_masks); |
| 2798 | 2798 | } |
@@ -2801,7 +2801,7 @@ discard block |
||
| 2801 | 2801 | |
| 2802 | 2802 | $bestMask = $frame; |
| 2803 | 2803 | |
| 2804 | - foreach($checked_masks as $i) {
|
|
| 2804 | + foreach ($checked_masks as $i) {
|
|
| 2805 | 2805 | $mask = array_fill(0, $width, str_repeat("\0", $width));
|
| 2806 | 2806 | |
| 2807 | 2807 | $demerit = 0; |
@@ -2812,7 +2812,7 @@ discard block |
||
| 2812 | 2812 | $demerit = (int)((int)(abs($blacks - 50) / 5) * N4); |
| 2813 | 2813 | $demerit += $this->evaluateSymbol($width, $mask); |
| 2814 | 2814 | |
| 2815 | - if($demerit < $minDemerit) {
|
|
| 2815 | + if ($demerit<$minDemerit) {
|
|
| 2816 | 2816 | $minDemerit = $demerit; |
| 2817 | 2817 | $bestMask = $mask; |
| 2818 | 2818 | $bestMaskNum = $i; |
@@ -2892,10 +2892,10 @@ discard block |
||
| 2892 | 2892 | //---------------------------------------------------------------------- |
| 2893 | 2893 | public function __construct(QRinput $input) |
| 2894 | 2894 | { |
| 2895 | - $spec = array(0,0,0,0,0); |
|
| 2895 | + $spec = array(0, 0, 0, 0, 0); |
|
| 2896 | 2896 | |
| 2897 | 2897 | $this->datacode = $input->getByteStream(); |
| 2898 | - if(is_null($this->datacode)) { |
|
| 2898 | + if (is_null($this->datacode)) { |
|
| 2899 | 2899 | throw new Exception('null imput string'); |
| 2900 | 2900 | } |
| 2901 | 2901 | |
@@ -2909,7 +2909,7 @@ discard block |
||
| 2909 | 2909 | $this->blocks = QRspec::rsBlockNum($spec); |
| 2910 | 2910 | |
| 2911 | 2911 | $ret = $this->init($spec); |
| 2912 | - if($ret < 0) { |
|
| 2912 | + if ($ret<0) { |
|
| 2913 | 2913 | throw new Exception('block alloc error'); |
| 2914 | 2914 | return null; |
| 2915 | 2915 | } |
@@ -2928,29 +2928,29 @@ discard block |
||
| 2928 | 2928 | $blockNo = 0; |
| 2929 | 2929 | $dataPos = 0; |
| 2930 | 2930 | $eccPos = 0; |
| 2931 | - for($i=0; $i<QRspec::rsBlockNum1($spec); $i++) { |
|
| 2932 | - $ecc = array_slice($this->ecccode,$eccPos); |
|
| 2933 | - $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs); |
|
| 2934 | - $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc); |
|
| 2931 | + for ($i = 0; $i<QRspec::rsBlockNum1($spec); $i++) { |
|
| 2932 | + $ecc = array_slice($this->ecccode, $eccPos); |
|
| 2933 | + $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs); |
|
| 2934 | + $this->ecccode = array_merge(array_slice($this->ecccode, 0, $eccPos), $ecc); |
|
| 2935 | 2935 | |
| 2936 | 2936 | $dataPos += $dl; |
| 2937 | 2937 | $eccPos += $el; |
| 2938 | 2938 | $blockNo++; |
| 2939 | 2939 | } |
| 2940 | 2940 | |
| 2941 | - if(QRspec::rsBlockNum2($spec) == 0) |
|
| 2941 | + if (QRspec::rsBlockNum2($spec)==0) |
|
| 2942 | 2942 | return 0; |
| 2943 | 2943 | |
| 2944 | 2944 | $dl = QRspec::rsDataCodes2($spec); |
| 2945 | 2945 | $el = QRspec::rsEccCodes2($spec); |
| 2946 | 2946 | $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el); |
| 2947 | 2947 | |
| 2948 | - if($rs == NULL) return -1; |
|
| 2948 | + if ($rs==NULL) return -1; |
|
| 2949 | 2949 | |
| 2950 | - for($i=0; $i<QRspec::rsBlockNum2($spec); $i++) { |
|
| 2951 | - $ecc = array_slice($this->ecccode,$eccPos); |
|
| 2950 | + for ($i = 0; $i<QRspec::rsBlockNum2($spec); $i++) { |
|
| 2951 | + $ecc = array_slice($this->ecccode, $eccPos); |
|
| 2952 | 2952 | $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs); |
| 2953 | - $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc); |
|
| 2953 | + $this->ecccode = array_merge(array_slice($this->ecccode, 0, $eccPos), $ecc); |
|
| 2954 | 2954 | |
| 2955 | 2955 | $dataPos += $dl; |
| 2956 | 2956 | $eccPos += $el; |
@@ -2965,14 +2965,14 @@ discard block |
||
| 2965 | 2965 | { |
| 2966 | 2966 | $ret; |
| 2967 | 2967 | |
| 2968 | - if($this->count < $this->dataLength) { |
|
| 2968 | + if ($this->count<$this->dataLength) { |
|
| 2969 | 2969 | $row = $this->count % $this->blocks; |
| 2970 | 2970 | $col = $this->count / $this->blocks; |
| 2971 | - if($col >= $this->rsblocks[0]->dataLength) { |
|
| 2971 | + if ($col>=$this->rsblocks[0]->dataLength) { |
|
| 2972 | 2972 | $row += $this->b1; |
| 2973 | 2973 | } |
| 2974 | 2974 | $ret = $this->rsblocks[$row]->data[$col]; |
| 2975 | - } else if($this->count < $this->dataLength + $this->eccLength) { |
|
| 2975 | + } else if ($this->count<$this->dataLength + $this->eccLength) { |
|
| 2976 | 2976 | $row = ($this->count - $this->dataLength) % $this->blocks; |
| 2977 | 2977 | $col = ($this->count - $this->dataLength) / $this->blocks; |
| 2978 | 2978 | $ret = $this->rsblocks[$row]->ecc[$col]; |
@@ -2996,10 +2996,10 @@ discard block |
||
| 2996 | 2996 | //---------------------------------------------------------------------- |
| 2997 | 2997 | public function encodeMask(QRinput $input, $mask) |
| 2998 | 2998 | { |
| 2999 | - if($input->getVersion() < 0 || $input->getVersion() > QRSPEC_VERSION_MAX) { |
|
| 2999 | + if ($input->getVersion()<0 || $input->getVersion()>QRSPEC_VERSION_MAX) { |
|
| 3000 | 3000 | throw new Exception('wrong version'); |
| 3001 | 3001 | } |
| 3002 | - if($input->getErrorCorrectionLevel() > QR_ECLEVEL_H) { |
|
| 3002 | + if ($input->getErrorCorrectionLevel()>QR_ECLEVEL_H) { |
|
| 3003 | 3003 | throw new Exception('wrong level'); |
| 3004 | 3004 | } |
| 3005 | 3005 | |
@@ -3012,17 +3012,17 @@ discard block |
||
| 3012 | 3012 | $frame = QRspec::newFrame($version); |
| 3013 | 3013 | |
| 3014 | 3014 | $filler = new FrameFiller($width, $frame); |
| 3015 | - if(is_null($filler)) { |
|
| 3015 | + if (is_null($filler)) { |
|
| 3016 | 3016 | return NULL; |
| 3017 | 3017 | } |
| 3018 | 3018 | |
| 3019 | 3019 | // inteleaved data and ecc codes |
| 3020 | - for($i=0; $i<$raw->dataLength + $raw->eccLength; $i++) { |
|
| 3020 | + for ($i = 0; $i<$raw->dataLength + $raw->eccLength; $i++) { |
|
| 3021 | 3021 | $code = $raw->getCode(); |
| 3022 | 3022 | $bit = 0x80; |
| 3023 | - for($j=0; $j<8; $j++) { |
|
| 3023 | + for ($j = 0; $j<8; $j++) { |
|
| 3024 | 3024 | $addr = $filler->next(); |
| 3025 | - $filler->setFrameAt($addr, 0x02 | (($bit & $code) != 0)); |
|
| 3025 | + $filler->setFrameAt($addr, 0x02 | (($bit & $code)!=0)); |
|
| 3026 | 3026 | $bit = $bit >> 1; |
| 3027 | 3027 | } |
| 3028 | 3028 | } |
@@ -3033,7 +3033,7 @@ discard block |
||
| 3033 | 3033 | |
| 3034 | 3034 | // remainder bits |
| 3035 | 3035 | $j = QRspec::getRemainder($version); |
| 3036 | - for($i=0; $i<$j; $i++) { |
|
| 3036 | + for ($i = 0; $i<$j; $i++) { |
|
| 3037 | 3037 | $addr = $filler->next(); |
| 3038 | 3038 | $filler->setFrameAt($addr, 0x02); |
| 3039 | 3039 | } |
@@ -3044,7 +3044,7 @@ discard block |
||
| 3044 | 3044 | |
| 3045 | 3045 | // masking |
| 3046 | 3046 | $maskObj = new QRmask(); |
| 3047 | - if($mask < 0) { |
|
| 3047 | + if ($mask<0) { |
|
| 3048 | 3048 | |
| 3049 | 3049 | if (QR_FIND_BEST_MASK) { |
| 3050 | 3050 | $masked = $maskObj->mask($width, $frame, $input->getErrorCorrectionLevel()); |
@@ -3055,7 +3055,7 @@ discard block |
||
| 3055 | 3055 | $masked = $maskObj->makeMask($width, $frame, $mask, $input->getErrorCorrectionLevel()); |
| 3056 | 3056 | } |
| 3057 | 3057 | |
| 3058 | - if($masked == NULL) { |
|
| 3058 | + if ($masked==NULL) { |
|
| 3059 | 3059 | return NULL; |
| 3060 | 3060 | } |
| 3061 | 3061 | |
@@ -3077,16 +3077,16 @@ discard block |
||
| 3077 | 3077 | //---------------------------------------------------------------------- |
| 3078 | 3078 | public function encodeString8bit($string, $version, $level) |
| 3079 | 3079 | { |
| 3080 | - if(string == NULL) { |
|
| 3080 | + if (string==NULL) { |
|
| 3081 | 3081 | throw new Exception('empty string!'); |
| 3082 | 3082 | return NULL; |
| 3083 | 3083 | } |
| 3084 | 3084 | |
| 3085 | 3085 | $input = new QRinput($version, $level); |
| 3086 | - if($input == NULL) return NULL; |
|
| 3086 | + if ($input==NULL) return NULL; |
|
| 3087 | 3087 | |
| 3088 | 3088 | $ret = $input->append($input, QR_MODE_8, strlen($string), str_split($string)); |
| 3089 | - if($ret < 0) { |
|
| 3089 | + if ($ret<0) { |
|
| 3090 | 3090 | unset($input); |
| 3091 | 3091 | return NULL; |
| 3092 | 3092 | } |
@@ -3097,16 +3097,16 @@ discard block |
||
| 3097 | 3097 | public function encodeString($string, $version, $level, $hint, $casesensitive) |
| 3098 | 3098 | { |
| 3099 | 3099 | |
| 3100 | - if($hint != QR_MODE_8 && $hint != QR_MODE_KANJI) { |
|
| 3100 | + if ($hint!=QR_MODE_8 && $hint!=QR_MODE_KANJI) { |
|
| 3101 | 3101 | throw new Exception('bad hint'); |
| 3102 | 3102 | return NULL; |
| 3103 | 3103 | } |
| 3104 | 3104 | |
| 3105 | 3105 | $input = new QRinput($version, $level); |
| 3106 | - if($input == NULL) return NULL; |
|
| 3106 | + if ($input==NULL) return NULL; |
|
| 3107 | 3107 | |
| 3108 | 3108 | $ret = QRsplit::splitStringToQRinput($string, $input, $hint, $casesensitive); |
| 3109 | - if($ret < 0) { |
|
| 3109 | + if ($ret<0) { |
|
| 3110 | 3110 | return NULL; |
| 3111 | 3111 | } |
| 3112 | 3112 | |
@@ -3114,10 +3114,10 @@ discard block |
||
| 3114 | 3114 | } |
| 3115 | 3115 | |
| 3116 | 3116 | //---------------------------------------------------------------------- |
| 3117 | - public static function png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint=false, $back_color = 0xFFFFFF, $fore_color = 0x000000) |
|
| 3117 | + public static function png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint = false, $back_color = 0xFFFFFF, $fore_color = 0x000000) |
|
| 3118 | 3118 | { |
| 3119 | 3119 | $enc = QRencode::factory($level, $size, $margin, $back_color, $fore_color); |
| 3120 | - return $enc->encodePNG($text, $outfile, $saveandprint=false); |
|
| 3120 | + return $enc->encodePNG($text, $outfile, $saveandprint = false); |
|
| 3121 | 3121 | } |
| 3122 | 3122 | |
| 3123 | 3123 | //---------------------------------------------------------------------- |
@@ -3128,17 +3128,17 @@ discard block |
||
| 3128 | 3128 | } |
| 3129 | 3129 | |
| 3130 | 3130 | //---------------------------------------------------------------------- |
| 3131 | - public static function eps($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint=false, $back_color = 0xFFFFFF, $fore_color = 0x000000, $cmyk = false) |
|
| 3131 | + public static function eps($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint = false, $back_color = 0xFFFFFF, $fore_color = 0x000000, $cmyk = false) |
|
| 3132 | 3132 | { |
| 3133 | 3133 | $enc = QRencode::factory($level, $size, $margin, $back_color, $fore_color, $cmyk); |
| 3134 | - return $enc->encodeEPS($text, $outfile, $saveandprint=false); |
|
| 3134 | + return $enc->encodeEPS($text, $outfile, $saveandprint = false); |
|
| 3135 | 3135 | } |
| 3136 | 3136 | |
| 3137 | 3137 | //---------------------------------------------------------------------- |
| 3138 | - public static function svg($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint=false, $back_color = 0xFFFFFF, $fore_color = 0x000000) |
|
| 3138 | + public static function svg($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint = false, $back_color = 0xFFFFFF, $fore_color = 0x000000) |
|
| 3139 | 3139 | { |
| 3140 | 3140 | $enc = QRencode::factory($level, $size, $margin, $back_color, $fore_color); |
| 3141 | - return $enc->encodeSVG($text, $outfile, $saveandprint=false); |
|
| 3141 | + return $enc->encodeSVG($text, $outfile, $saveandprint = false); |
|
| 3142 | 3142 | } |
| 3143 | 3143 | |
| 3144 | 3144 | //---------------------------------------------------------------------- |
@@ -3188,7 +3188,7 @@ discard block |
||
| 3188 | 3188 | { |
| 3189 | 3189 | do { |
| 3190 | 3190 | |
| 3191 | - if($this->bit == -1) { |
|
| 3191 | + if ($this->bit==-1) { |
|
| 3192 | 3192 | $this->bit = 0; |
| 3193 | 3193 | return array('x'=>$this->x, 'y'=>$this->y); |
| 3194 | 3194 | } |
@@ -3197,7 +3197,7 @@ discard block |
||
| 3197 | 3197 | $y = $this->y; |
| 3198 | 3198 | $w = $this->width; |
| 3199 | 3199 | |
| 3200 | - if($this->bit == 0) { |
|
| 3200 | + if ($this->bit==0) { |
|
| 3201 | 3201 | $x--; |
| 3202 | 3202 | $this->bit++; |
| 3203 | 3203 | } else { |
@@ -3206,33 +3206,33 @@ discard block |
||
| 3206 | 3206 | $this->bit--; |
| 3207 | 3207 | } |
| 3208 | 3208 | |
| 3209 | - if($this->dir < 0) { |
|
| 3210 | - if($y < 0) { |
|
| 3209 | + if ($this->dir<0) { |
|
| 3210 | + if ($y<0) { |
|
| 3211 | 3211 | $y = 0; |
| 3212 | 3212 | $x -= 2; |
| 3213 | 3213 | $this->dir = 1; |
| 3214 | - if($x == 6) { |
|
| 3214 | + if ($x==6) { |
|
| 3215 | 3215 | $x--; |
| 3216 | 3216 | $y = 9; |
| 3217 | 3217 | } |
| 3218 | 3218 | } |
| 3219 | 3219 | } else { |
| 3220 | - if($y == $w) { |
|
| 3220 | + if ($y==$w) { |
|
| 3221 | 3221 | $y = $w - 1; |
| 3222 | 3222 | $x -= 2; |
| 3223 | 3223 | $this->dir = -1; |
| 3224 | - if($x == 6) { |
|
| 3224 | + if ($x==6) { |
|
| 3225 | 3225 | $x--; |
| 3226 | 3226 | $y -= 8; |
| 3227 | 3227 | } |
| 3228 | 3228 | } |
| 3229 | 3229 | } |
| 3230 | - if($x < 0 || $y < 0) return null; |
|
| 3230 | + if ($x<0 || $y<0) return null; |
|
| 3231 | 3231 | |
| 3232 | 3232 | $this->x = $x; |
| 3233 | 3233 | $this->y = $y; |
| 3234 | 3234 | |
| 3235 | - } while(ord($this->frame[$y][$x]) & 0x80); |
|
| 3235 | + } while (ord($this->frame[$y][$x]) & 0x80); |
|
| 3236 | 3236 | |
| 3237 | 3237 | return array('x'=>$x, 'y'=>$y); |
| 3238 | 3238 | } |
@@ -3300,7 +3300,7 @@ discard block |
||
| 3300 | 3300 | { |
| 3301 | 3301 | $code = new QRcode(); |
| 3302 | 3302 | |
| 3303 | - if($this->eightbit) { |
|
| 3303 | + if ($this->eightbit) { |
|
| 3304 | 3304 | $code->encodeString8bit($intext, $this->version, $this->level); |
| 3305 | 3305 | } else { |
| 3306 | 3306 | $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive); |
@@ -3314,7 +3314,7 @@ discard block |
||
| 3314 | 3314 | { |
| 3315 | 3315 | $code = new QRcode(); |
| 3316 | 3316 | |
| 3317 | - if($this->eightbit) { |
|
| 3317 | + if ($this->eightbit) { |
|
| 3318 | 3318 | $code->encodeString8bit($intext, $this->version, $this->level); |
| 3319 | 3319 | } else { |
| 3320 | 3320 | $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive); |
@@ -3322,7 +3322,7 @@ discard block |
||
| 3322 | 3322 | |
| 3323 | 3323 | QRtools::markTime('after_encode'); |
| 3324 | 3324 | |
| 3325 | - if ($outfile!== false) { |
|
| 3325 | + if ($outfile!==false) { |
|
| 3326 | 3326 | file_put_contents($outfile, join("\n", QRtools::binarize($code->data))); |
| 3327 | 3327 | } else { |
| 3328 | 3328 | return QRtools::binarize($code->data); |
@@ -3330,7 +3330,7 @@ discard block |
||
| 3330 | 3330 | } |
| 3331 | 3331 | |
| 3332 | 3332 | //---------------------------------------------------------------------- |
| 3333 | - public function encodePNG($intext, $outfile = false,$saveandprint=false) |
|
| 3333 | + public function encodePNG($intext, $outfile = false, $saveandprint = false) |
|
| 3334 | 3334 | { |
| 3335 | 3335 | try { |
| 3336 | 3336 | |
@@ -3339,12 +3339,12 @@ discard block |
||
| 3339 | 3339 | $err = ob_get_contents(); |
| 3340 | 3340 | ob_end_clean(); |
| 3341 | 3341 | |
| 3342 | - if ($err != '') |
|
| 3342 | + if ($err!='') |
|
| 3343 | 3343 | QRtools::log($outfile, $err); |
| 3344 | 3344 | |
| 3345 | - $maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab)+2*$this->margin)); |
|
| 3345 | + $maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab) + 2 * $this->margin)); |
|
| 3346 | 3346 | |
| 3347 | - QRimage::png($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin,$saveandprint, $this->back_color, $this->fore_color); |
|
| 3347 | + QRimage::png($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin, $saveandprint, $this->back_color, $this->fore_color); |
|
| 3348 | 3348 | |
| 3349 | 3349 | } catch (Exception $e) { |
| 3350 | 3350 | |
@@ -3354,7 +3354,7 @@ discard block |
||
| 3354 | 3354 | } |
| 3355 | 3355 | |
| 3356 | 3356 | //---------------------------------------------------------------------- |
| 3357 | - public function encodeEPS($intext, $outfile = false,$saveandprint=false) |
|
| 3357 | + public function encodeEPS($intext, $outfile = false, $saveandprint = false) |
|
| 3358 | 3358 | { |
| 3359 | 3359 | try { |
| 3360 | 3360 | |
@@ -3363,12 +3363,12 @@ discard block |
||
| 3363 | 3363 | $err = ob_get_contents(); |
| 3364 | 3364 | ob_end_clean(); |
| 3365 | 3365 | |
| 3366 | - if ($err != '') |
|
| 3366 | + if ($err!='') |
|
| 3367 | 3367 | QRtools::log($outfile, $err); |
| 3368 | 3368 | |
| 3369 | - $maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab)+2*$this->margin)); |
|
| 3369 | + $maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab) + 2 * $this->margin)); |
|
| 3370 | 3370 | |
| 3371 | - QRvect::eps($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin,$saveandprint, $this->back_color, $this->fore_color, $this->cmyk); |
|
| 3371 | + QRvect::eps($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin, $saveandprint, $this->back_color, $this->fore_color, $this->cmyk); |
|
| 3372 | 3372 | |
| 3373 | 3373 | } catch (Exception $e) { |
| 3374 | 3374 | |
@@ -3378,7 +3378,7 @@ discard block |
||
| 3378 | 3378 | } |
| 3379 | 3379 | |
| 3380 | 3380 | //---------------------------------------------------------------------- |
| 3381 | - public function encodeSVG($intext, $outfile = false,$saveandprint=false) |
|
| 3381 | + public function encodeSVG($intext, $outfile = false, $saveandprint = false) |
|
| 3382 | 3382 | { |
| 3383 | 3383 | try { |
| 3384 | 3384 | |
@@ -3387,12 +3387,12 @@ discard block |
||
| 3387 | 3387 | $err = ob_get_contents(); |
| 3388 | 3388 | ob_end_clean(); |
| 3389 | 3389 | |
| 3390 | - if ($err != '') |
|
| 3390 | + if ($err!='') |
|
| 3391 | 3391 | QRtools::log($outfile, $err); |
| 3392 | 3392 | |
| 3393 | - $maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab)+2*$this->margin)); |
|
| 3393 | + $maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab) + 2 * $this->margin)); |
|
| 3394 | 3394 | |
| 3395 | - QRvect::svg($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin,$saveandprint, $this->back_color, $this->fore_color); |
|
| 3395 | + QRvect::svg($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin, $saveandprint, $this->back_color, $this->fore_color); |
|
| 3396 | 3396 | |
| 3397 | 3397 | } catch (Exception $e) { |
| 3398 | 3398 | |
@@ -3438,21 +3438,21 @@ discard block |
||
| 3438 | 3438 | class QRvect { |
| 3439 | 3439 | |
| 3440 | 3440 | //---------------------------------------------------------------------- |
| 3441 | - public static function eps($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE, $back_color = 0xFFFFFF, $fore_color = 0x000000, $cmyk = false) |
|
| 3441 | + public static function eps($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4, $saveandprint = FALSE, $back_color = 0xFFFFFF, $fore_color = 0x000000, $cmyk = false) |
|
| 3442 | 3442 | { |
| 3443 | 3443 | $vect = self::vectEPS($frame, $pixelPerPoint, $outerFrame, $back_color, $fore_color, $cmyk); |
| 3444 | 3444 | |
| 3445 | - if ($filename === false) { |
|
| 3445 | + if ($filename===false) { |
|
| 3446 | 3446 | header("Content-Type: application/postscript"); |
| 3447 | 3447 | header('Content-Disposition: filename="qrcode.eps"'); |
| 3448 | 3448 | echo $vect; |
| 3449 | 3449 | } else { |
| 3450 | - if($saveandprint===TRUE){ |
|
| 3450 | + if ($saveandprint===TRUE) { |
|
| 3451 | 3451 | QRtools::save($vect, $filename); |
| 3452 | 3452 | header("Content-Type: application/postscript"); |
| 3453 | 3453 | header('Content-Disposition: filename="qrcode.eps"'); |
| 3454 | 3454 | echo $vect; |
| 3455 | - }else{ |
|
| 3455 | + } else { |
|
| 3456 | 3456 | QRtools::save($vect, $filename); |
| 3457 | 3457 | } |
| 3458 | 3458 | } |
@@ -3465,8 +3465,8 @@ discard block |
||
| 3465 | 3465 | $h = count($frame); |
| 3466 | 3466 | $w = strlen($frame[0]); |
| 3467 | 3467 | |
| 3468 | - $imgW = $w + 2*$outerFrame; |
|
| 3469 | - $imgH = $h + 2*$outerFrame; |
|
| 3468 | + $imgW = $w + 2 * $outerFrame; |
|
| 3469 | + $imgH = $h + 2 * $outerFrame; |
|
| 3470 | 3470 | |
| 3471 | 3471 | if ($cmyk) |
| 3472 | 3472 | { |
@@ -3523,7 +3523,7 @@ discard block |
||
| 3523 | 3523 | |
| 3524 | 3524 | // set the symbol color |
| 3525 | 3525 | $output .= $back_color_string; |
| 3526 | - $output .= '-'.$outerFrame.' -'.$outerFrame.' '.($w + 2*$outerFrame).' '.($h + 2*$outerFrame).' F'."\n"; |
|
| 3526 | + $output .= '-'.$outerFrame.' -'.$outerFrame.' '.($w + 2 * $outerFrame).' '.($h + 2 * $outerFrame).' F'."\n"; |
|
| 3527 | 3527 | |
| 3528 | 3528 | |
| 3529 | 3529 | // set the symbol color |
@@ -3531,9 +3531,9 @@ discard block |
||
| 3531 | 3531 | |
| 3532 | 3532 | // Convert the matrix into pixels |
| 3533 | 3533 | |
| 3534 | - for($i=0; $i<$h; $i++) { |
|
| 3535 | - for($j=0; $j<$w; $j++) { |
|
| 3536 | - if( $frame[$i][$j] == '1') { |
|
| 3534 | + for ($i = 0; $i<$h; $i++) { |
|
| 3535 | + for ($j = 0; $j<$w; $j++) { |
|
| 3536 | + if ($frame[$i][$j]=='1') { |
|
| 3537 | 3537 | $y = $h - 1 - $i; |
| 3538 | 3538 | $x = $j; |
| 3539 | 3539 | $output .= $x.' '.$y.' 1 1 F'."\n"; |
@@ -3542,27 +3542,27 @@ discard block |
||
| 3542 | 3542 | } |
| 3543 | 3543 | |
| 3544 | 3544 | |
| 3545 | - $output .='%%EOF'; |
|
| 3545 | + $output .= '%%EOF'; |
|
| 3546 | 3546 | |
| 3547 | 3547 | return $output; |
| 3548 | 3548 | } |
| 3549 | 3549 | |
| 3550 | 3550 | //---------------------------------------------------------------------- |
| 3551 | - public static function svg($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE, $back_color, $fore_color) |
|
| 3551 | + public static function svg($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4, $saveandprint = FALSE, $back_color, $fore_color) |
|
| 3552 | 3552 | { |
| 3553 | 3553 | $vect = self::vectSVG($frame, $pixelPerPoint, $outerFrame, $back_color, $fore_color); |
| 3554 | 3554 | |
| 3555 | - if ($filename === false) { |
|
| 3555 | + if ($filename===false) { |
|
| 3556 | 3556 | header("Content-Type: image/svg+xml"); |
| 3557 | 3557 | //header('Content-Disposition: attachment, filename="qrcode.svg"'); |
| 3558 | 3558 | echo $vect; |
| 3559 | 3559 | } else { |
| 3560 | - if($saveandprint===TRUE){ |
|
| 3560 | + if ($saveandprint===TRUE) { |
|
| 3561 | 3561 | QRtools::save($vect, $filename); |
| 3562 | 3562 | header("Content-Type: image/svg+xml"); |
| 3563 | 3563 | //header('Content-Disposition: filename="'.$filename.'"'); |
| 3564 | 3564 | echo $vect; |
| 3565 | - }else{ |
|
| 3565 | + } else { |
|
| 3566 | 3566 | QRtools::save($vect, $filename); |
| 3567 | 3567 | } |
| 3568 | 3568 | } |
@@ -3575,8 +3575,8 @@ discard block |
||
| 3575 | 3575 | $h = count($frame); |
| 3576 | 3576 | $w = strlen($frame[0]); |
| 3577 | 3577 | |
| 3578 | - $imgW = $w + 2*$outerFrame; |
|
| 3579 | - $imgH = $h + 2*$outerFrame; |
|
| 3578 | + $imgW = $w + 2 * $outerFrame; |
|
| 3579 | + $imgH = $h + 2 * $outerFrame; |
|
| 3580 | 3580 | |
| 3581 | 3581 | |
| 3582 | 3582 | $output = |
@@ -3591,7 +3591,7 @@ discard block |
||
| 3591 | 3591 | '<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" xmlns:xlink="http://www.w3.org/1999/xlink" width="'.$imgW * $pixelPerPoint.'" height="'.$imgH * $pixelPerPoint.'" viewBox="0 0 '.$imgW * $pixelPerPoint.' '.$imgH * $pixelPerPoint.'">'."\n". |
| 3592 | 3592 | '<desc></desc>'."\n"; |
| 3593 | 3593 | |
| 3594 | - if(!empty($back_color)) { |
|
| 3594 | + if (!empty($back_color)) { |
|
| 3595 | 3595 | $backgroundcolor = str_pad(dechex($back_color), 6, "0", STR_PAD_LEFT); |
| 3596 | 3596 | $output .= '<rect width="'.$imgW * $pixelPerPoint.'" height="'.$imgH * $pixelPerPoint.'" fill="#'.$backgroundcolor.'" cx="0" cy="0" />'."\n"; |
| 3597 | 3597 | } |
@@ -3605,9 +3605,9 @@ discard block |
||
| 3605 | 3605 | |
| 3606 | 3606 | // Convert the matrix into pixels |
| 3607 | 3607 | |
| 3608 | - for($i=0; $i<$h; $i++) { |
|
| 3609 | - for($j=0; $j<$w; $j++) { |
|
| 3610 | - if( $frame[$i][$j] == '1') { |
|
| 3608 | + for ($i = 0; $i<$h; $i++) { |
|
| 3609 | + for ($j = 0; $j<$w; $j++) { |
|
| 3610 | + if ($frame[$i][$j]=='1') { |
|
| 3611 | 3611 | $y = ($i + $outerFrame) * $pixelPerPoint; |
| 3612 | 3612 | $x = ($j + $outerFrame) * $pixelPerPoint; |
| 3613 | 3613 | $output .= '<use x="'.$x.'" y="'.$y.'" xlink:href="#p" />'."\n"; |
@@ -177,8 +177,9 @@ discard block |
||
| 177 | 177 | { |
| 178 | 178 | $barcode_array = array(); |
| 179 | 179 | |
| 180 | - if (!is_array($mode)) |
|
| 181 | - $mode = explode(',', $mode); |
|
| 180 | + if (!is_array($mode)) {
|
|
| 181 | + $mode = explode(',', $mode);
|
|
| 182 | + } |
|
| 182 | 183 | |
| 183 | 184 | $eccLevel = 'L'; |
| 184 | 185 | |
@@ -195,8 +196,9 @@ discard block |
||
| 195 | 196 | |
| 196 | 197 | foreach ($qrTab as $line) { |
| 197 | 198 | $arrAdd = array(); |
| 198 | - foreach(str_split($line) as $char) |
|
| 199 | - $arrAdd[] = ($char=='1')?1:0; |
|
| 199 | + foreach(str_split($line) as $char) {
|
|
| 200 | + $arrAdd[] = ($char=='1')?1:0; |
|
| 201 | + } |
|
| 200 | 202 | $barcode_array['bcode'][] = $arrAdd; |
| 201 | 203 | } |
| 202 | 204 | |
@@ -224,8 +226,9 @@ discard block |
||
| 224 | 226 | |
| 225 | 227 | $width = count($frame); |
| 226 | 228 | $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); |
| 227 | - for ($maskNo=0; $maskNo<8; $maskNo++) |
|
| 228 | - $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true); |
|
| 229 | + for ($maskNo=0; $maskNo<8; $maskNo++) {
|
|
| 230 | + $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true); |
|
| 231 | + } |
|
| 229 | 232 | } |
| 230 | 233 | |
| 231 | 234 | QRtools::markTime('after_build_cache'); |
@@ -262,8 +265,9 @@ discard block |
||
| 262 | 265 | list($usec, $sec) = explode(" ", microtime()); |
| 263 | 266 | $time = ((float)$usec + (float)$sec); |
| 264 | 267 | |
| 265 | - if (!isset($GLOBALS['qr_time_bench'])) |
|
| 266 | - $GLOBALS['qr_time_bench'] = array(); |
|
| 268 | + if (!isset($GLOBALS['qr_time_bench'])) {
|
|
| 269 | + $GLOBALS['qr_time_bench'] = array(); |
|
| 270 | + } |
|
| 267 | 271 | |
| 268 | 272 | $GLOBALS['qr_time_bench'][$markerId] = $time; |
| 269 | 273 | } |
@@ -441,8 +445,9 @@ discard block |
||
| 441 | 445 | |
| 442 | 446 | for($i=1; $i<= QRSPEC_VERSION_MAX; $i++) {
|
| 443 | 447 | $words = self::$capacity[$i][QRCAP_WORDS] - self::$capacity[$i][QRCAP_EC][$level]; |
| 444 | - if($words >= $size) |
|
| 445 | - return $i; |
|
| 448 | + if($words >= $size) {
|
|
| 449 | + return $i; |
|
| 450 | + } |
|
| 446 | 451 | } |
| 447 | 452 | |
| 448 | 453 | return -1; |
@@ -460,8 +465,9 @@ discard block |
||
| 460 | 465 | //---------------------------------------------------------------------- |
| 461 | 466 | public static function lengthIndicator($mode, $version) |
| 462 | 467 | {
|
| 463 | - if ($mode == QR_MODE_STRUCTURE) |
|
| 464 | - return 0; |
|
| 468 | + if ($mode == QR_MODE_STRUCTURE) {
|
|
| 469 | + return 0; |
|
| 470 | + } |
|
| 465 | 471 | |
| 466 | 472 | if ($version <= 9) {
|
| 467 | 473 | $l = 0; |
@@ -477,8 +483,9 @@ discard block |
||
| 477 | 483 | //---------------------------------------------------------------------- |
| 478 | 484 | public static function maximumWords($mode, $version) |
| 479 | 485 | {
|
| 480 | - if($mode == QR_MODE_STRUCTURE) |
|
| 481 | - return 3; |
|
| 486 | + if($mode == QR_MODE_STRUCTURE) {
|
|
| 487 | + return 3; |
|
| 488 | + } |
|
| 482 | 489 | |
| 483 | 490 | if($version <= 9) {
|
| 484 | 491 | $l = 0; |
@@ -624,8 +631,9 @@ discard block |
||
| 624 | 631 | //---------------------------------------------------------------------- |
| 625 | 632 | public static function putAlignmentPattern($version, &$frame, $width) |
| 626 | 633 | {
|
| 627 | - if($version < 2) |
|
| 628 | - return; |
|
| 634 | + if($version < 2) {
|
|
| 635 | + return; |
|
| 636 | + } |
|
| 629 | 637 | |
| 630 | 638 | $d = self::$alignmentPattern[$version][1] - self::$alignmentPattern[$version][0]; |
| 631 | 639 | if($d < 0) {
|
@@ -677,8 +685,9 @@ discard block |
||
| 677 | 685 | //---------------------------------------------------------------------- |
| 678 | 686 | public static function getVersionPattern($version) |
| 679 | 687 | {
|
| 680 | - if($version < 7 || $version > QRSPEC_VERSION_MAX) |
|
| 681 | - return 0; |
|
| 688 | + if($version < 7 || $version > QRSPEC_VERSION_MAX) {
|
|
| 689 | + return 0; |
|
| 690 | + } |
|
| 682 | 691 | |
| 683 | 692 | return self::$versionPattern[$version -7]; |
| 684 | 693 | } |
@@ -695,11 +704,13 @@ discard block |
||
| 695 | 704 | |
| 696 | 705 | public static function getFormatInfo($mask, $level) |
| 697 | 706 | {
|
| 698 | - if($mask < 0 || $mask > 7) |
|
| 699 | - return 0; |
|
| 707 | + if($mask < 0 || $mask > 7) {
|
|
| 708 | + return 0; |
|
| 709 | + } |
|
| 700 | 710 | |
| 701 | - if($level < 0 || $level > 3) |
|
| 702 | - return 0; |
|
| 711 | + if($level < 0 || $level > 3) {
|
|
| 712 | + return 0; |
|
| 713 | + } |
|
| 703 | 714 | |
| 704 | 715 | return self::$formatInfo[$level][$mask]; |
| 705 | 716 | } |
@@ -879,8 +890,9 @@ discard block |
||
| 879 | 890 | //---------------------------------------------------------------------- |
| 880 | 891 | public static function newFrame($version) |
| 881 | 892 | {
|
| 882 | - if($version < 1 || $version > QRSPEC_VERSION_MAX) |
|
| 883 | - return null; |
|
| 893 | + if($version < 1 || $version > QRSPEC_VERSION_MAX) {
|
|
| 894 | + return null; |
|
| 895 | + } |
|
| 884 | 896 | |
| 885 | 897 | if(!isset(self::$frames[$version])) {
|
| 886 | 898 | |
@@ -898,8 +910,9 @@ discard block |
||
| 898 | 910 | } |
| 899 | 911 | } |
| 900 | 912 | |
| 901 | - if(is_null(self::$frames[$version])) |
|
| 902 | - return null; |
|
| 913 | + if(is_null(self::$frames[$version])) {
|
|
| 914 | + return null; |
|
| 915 | + } |
|
| 903 | 916 | |
| 904 | 917 | return self::$frames[$version]; |
| 905 | 918 | } |
@@ -964,7 +977,7 @@ discard block |
||
| 964 | 977 | ImagePng($image, $filename); |
| 965 | 978 | header("Content-type: image/png"); |
| 966 | 979 | ImagePng($image); |
| 967 | - }else{ |
|
| 980 | + } else{ |
|
| 968 | 981 | ImagePng($image, $filename); |
| 969 | 982 | } |
| 970 | 983 | } |
@@ -1236,8 +1249,9 @@ discard block |
||
| 1236 | 1249 | {
|
| 1237 | 1250 | $bits = 0; |
| 1238 | 1251 | |
| 1239 | - if($version == 0) |
|
| 1240 | - $version = 1; |
|
| 1252 | + if($version == 0) {
|
|
| 1253 | + $version = 1; |
|
| 1254 | + } |
|
| 1241 | 1255 | |
| 1242 | 1256 | switch($this->mode) {
|
| 1243 | 1257 | case QR_MODE_NUM: $bits = QRinput::estimateBitsModeNum($this->size); break; |
@@ -1296,8 +1310,9 @@ discard block |
||
| 1296 | 1310 | break; |
| 1297 | 1311 | } |
| 1298 | 1312 | |
| 1299 | - if($ret < 0) |
|
| 1300 | - return -1; |
|
| 1313 | + if($ret < 0) {
|
|
| 1314 | + return -1; |
|
| 1315 | + } |
|
| 1301 | 1316 | } |
| 1302 | 1317 | |
| 1303 | 1318 | return $this->bstream->size(); |
@@ -1514,8 +1529,9 @@ discard block |
||
| 1514 | 1529 | //---------------------------------------------------------------------- |
| 1515 | 1530 | public static function checkModeKanji($size, $data) |
| 1516 | 1531 | {
|
| 1517 | - if($size & 1) |
|
| 1518 | - return false; |
|
| 1532 | + if($size & 1) {
|
|
| 1533 | + return false; |
|
| 1534 | + } |
|
| 1519 | 1535 | |
| 1520 | 1536 | for($i=0; $i<$size; $i+=2) {
|
| 1521 | 1537 | $val = (ord($data[$i]) << 8) | ord($data[$i+1]); |
@@ -1535,8 +1551,9 @@ discard block |
||
| 1535 | 1551 | |
| 1536 | 1552 | public static function check($mode, $size, $data) |
| 1537 | 1553 | {
|
| 1538 | - if($size <= 0) |
|
| 1539 | - return false; |
|
| 1554 | + if($size <= 0) {
|
|
| 1555 | + return false; |
|
| 1556 | + } |
|
| 1540 | 1557 | |
| 1541 | 1558 | switch($mode) {
|
| 1542 | 1559 | case QR_MODE_NUM: return self::checkModeNum($size, $data); break; |
@@ -1601,8 +1618,9 @@ discard block |
||
| 1601 | 1618 | $chunks = (int)($payload / 11); |
| 1602 | 1619 | $remain = $payload - $chunks * 11; |
| 1603 | 1620 | $size = $chunks * 2; |
| 1604 | - if($remain >= 6) |
|
| 1605 | - $size++; |
|
| 1621 | + if($remain >= 6) {
|
|
| 1622 | + $size++; |
|
| 1623 | + } |
|
| 1606 | 1624 | break; |
| 1607 | 1625 | case QR_MODE_8: |
| 1608 | 1626 | $size = (int)($payload / 8); |
@@ -1619,8 +1637,12 @@ discard block |
||
| 1619 | 1637 | } |
| 1620 | 1638 | |
| 1621 | 1639 | $maxsize = QRspec::maximumWords($mode, $version); |
| 1622 | - if($size < 0) $size = 0; |
|
| 1623 | - if($size > $maxsize) $size = $maxsize; |
|
| 1640 | + if($size < 0) {
|
|
| 1641 | + $size = 0; |
|
| 1642 | + } |
|
| 1643 | + if($size > $maxsize) {
|
|
| 1644 | + $size = $maxsize; |
|
| 1645 | + } |
|
| 1624 | 1646 | |
| 1625 | 1647 | return $size; |
| 1626 | 1648 | } |
@@ -1633,8 +1655,9 @@ discard block |
||
| 1633 | 1655 | foreach($this->items as $item) {
|
| 1634 | 1656 | $bits = $item->encodeBitStream($this->version); |
| 1635 | 1657 | |
| 1636 | - if($bits < 0) |
|
| 1637 | - return -1; |
|
| 1658 | + if($bits < 0) {
|
|
| 1659 | + return -1; |
|
| 1660 | + } |
|
| 1638 | 1661 | |
| 1639 | 1662 | $total += $bits; |
| 1640 | 1663 | } |
@@ -1653,8 +1676,9 @@ discard block |
||
| 1653 | 1676 | for(;;) {
|
| 1654 | 1677 | $bits = $this->createBitStream(); |
| 1655 | 1678 | |
| 1656 | - if($bits < 0) |
|
| 1657 | - return -1; |
|
| 1679 | + if($bits < 0) {
|
|
| 1680 | + return -1; |
|
| 1681 | + } |
|
| 1658 | 1682 | |
| 1659 | 1683 | $ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); |
| 1660 | 1684 | if($ver < 0) {
|
@@ -1691,8 +1715,9 @@ discard block |
||
| 1691 | 1715 | $padding = new QRbitstream(); |
| 1692 | 1716 | $ret = $padding->appendNum($words * 8 - $bits + 4, 0); |
| 1693 | 1717 | |
| 1694 | - if($ret < 0) |
|
| 1695 | - return $ret; |
|
| 1718 | + if($ret < 0) {
|
|
| 1719 | + return $ret; |
|
| 1720 | + } |
|
| 1696 | 1721 | |
| 1697 | 1722 | $padlen = $maxwords - $words; |
| 1698 | 1723 | |
@@ -1705,8 +1730,9 @@ discard block |
||
| 1705 | 1730 | |
| 1706 | 1731 | $ret = $padding->appendBytes($padlen, $padbuf); |
| 1707 | 1732 | |
| 1708 | - if($ret < 0) |
|
| 1709 | - return $ret; |
|
| 1733 | + if($ret < 0) {
|
|
| 1734 | + return $ret; |
|
| 1735 | + } |
|
| 1710 | 1736 | |
| 1711 | 1737 | } |
| 1712 | 1738 | |
@@ -1883,13 +1909,15 @@ discard block |
||
| 1883 | 1909 | //---------------------------------------------------------------------- |
| 1884 | 1910 | public function appendNum($bits, $num) |
| 1885 | 1911 | {
|
| 1886 | - if ($bits == 0) |
|
| 1887 | - return 0; |
|
| 1912 | + if ($bits == 0) {
|
|
| 1913 | + return 0; |
|
| 1914 | + } |
|
| 1888 | 1915 | |
| 1889 | 1916 | $b = QRbitstream::newFromNum($bits, $num); |
| 1890 | 1917 | |
| 1891 | - if(is_null($b)) |
|
| 1892 | - return -1; |
|
| 1918 | + if(is_null($b)) {
|
|
| 1919 | + return -1; |
|
| 1920 | + } |
|
| 1893 | 1921 | |
| 1894 | 1922 | $ret = $this->append($b); |
| 1895 | 1923 | unset($b); |
@@ -1900,13 +1928,15 @@ discard block |
||
| 1900 | 1928 | //---------------------------------------------------------------------- |
| 1901 | 1929 | public function appendBytes($size, $data) |
| 1902 | 1930 | {
|
| 1903 | - if ($size == 0) |
|
| 1904 | - return 0; |
|
| 1931 | + if ($size == 0) {
|
|
| 1932 | + return 0; |
|
| 1933 | + } |
|
| 1905 | 1934 | |
| 1906 | 1935 | $b = QRbitstream::newFromBytes($size, $data); |
| 1907 | 1936 | |
| 1908 | - if(is_null($b)) |
|
| 1909 | - return -1; |
|
| 1937 | + if(is_null($b)) {
|
|
| 1938 | + return -1; |
|
| 1939 | + } |
|
| 1910 | 1940 | |
| 1911 | 1941 | $ret = $this->append($b); |
| 1912 | 1942 | unset($b); |
@@ -2010,8 +2040,9 @@ discard block |
||
| 2010 | 2040 | //---------------------------------------------------------------------- |
| 2011 | 2041 | public static function isdigitat($str, $pos) |
| 2012 | 2042 | {
|
| 2013 | - if ($pos >= strlen($str)) |
|
| 2014 | - return false; |
|
| 2043 | + if ($pos >= strlen($str)) {
|
|
| 2044 | + return false; |
|
| 2045 | + } |
|
| 2015 | 2046 | |
| 2016 | 2047 | return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9')));
|
| 2017 | 2048 | } |
@@ -2019,8 +2050,9 @@ discard block |
||
| 2019 | 2050 | //---------------------------------------------------------------------- |
| 2020 | 2051 | public static function isalnumat($str, $pos) |
| 2021 | 2052 | {
|
| 2022 | - if ($pos >= strlen($str)) |
|
| 2023 | - return false; |
|
| 2053 | + if ($pos >= strlen($str)) {
|
|
| 2054 | + return false; |
|
| 2055 | + } |
|
| 2024 | 2056 | |
| 2025 | 2057 | return (QRinput::lookAnTable(ord($str[$pos])) >= 0); |
| 2026 | 2058 | } |
@@ -2028,8 +2060,9 @@ discard block |
||
| 2028 | 2060 | //---------------------------------------------------------------------- |
| 2029 | 2061 | public function identifyMode($pos) |
| 2030 | 2062 | {
|
| 2031 | - if ($pos >= strlen($this->dataStr)) |
|
| 2032 | - return QR_MODE_NUL; |
|
| 2063 | + if ($pos >= strlen($this->dataStr)) {
|
|
| 2064 | + return QR_MODE_NUL; |
|
| 2065 | + } |
|
| 2033 | 2066 | |
| 2034 | 2067 | $c = $this->dataStr[$pos]; |
| 2035 | 2068 | |
@@ -2083,8 +2116,9 @@ discard block |
||
| 2083 | 2116 | } |
| 2084 | 2117 | |
| 2085 | 2118 | $ret = $this->input->append(QR_MODE_NUM, $run, str_split($this->dataStr)); |
| 2086 | - if($ret < 0) |
|
| 2087 | - return -1; |
|
| 2119 | + if($ret < 0) {
|
|
| 2120 | + return -1; |
|
| 2121 | + } |
|
| 2088 | 2122 | |
| 2089 | 2123 | return $run; |
| 2090 | 2124 | } |
@@ -2130,8 +2164,9 @@ discard block |
||
| 2130 | 2164 | } |
| 2131 | 2165 | |
| 2132 | 2166 | $ret = $this->input->append(QR_MODE_AN, $run, str_split($this->dataStr)); |
| 2133 | - if($ret < 0) |
|
| 2134 | - return -1; |
|
| 2167 | + if($ret < 0) {
|
|
| 2168 | + return -1; |
|
| 2169 | + } |
|
| 2135 | 2170 | |
| 2136 | 2171 | return $run; |
| 2137 | 2172 | } |
@@ -2146,8 +2181,9 @@ discard block |
||
| 2146 | 2181 | } |
| 2147 | 2182 | |
| 2148 | 2183 | $ret = $this->input->append(QR_MODE_KANJI, $p, str_split($this->dataStr)); |
| 2149 | - if($ret < 0) |
|
| 2150 | - return -1; |
|
| 2184 | + if($ret < 0) {
|
|
| 2185 | + return -1; |
|
| 2186 | + } |
|
| 2151 | 2187 | |
| 2152 | 2188 | return $ret; |
| 2153 | 2189 | } |
@@ -2201,8 +2237,9 @@ discard block |
||
| 2201 | 2237 | $run = $p; |
| 2202 | 2238 | $ret = $this->input->append(QR_MODE_8, $run, str_split($this->dataStr)); |
| 2203 | 2239 | |
| 2204 | - if($ret < 0) |
|
| 2205 | - return -1; |
|
| 2240 | + if($ret < 0) {
|
|
| 2241 | + return -1; |
|
| 2242 | + } |
|
| 2206 | 2243 | |
| 2207 | 2244 | return $run; |
| 2208 | 2245 | } |
@@ -2212,8 +2249,9 @@ discard block |
||
| 2212 | 2249 | {
|
| 2213 | 2250 | while (strlen($this->dataStr) > 0) |
| 2214 | 2251 | {
|
| 2215 | - if($this->dataStr == '') |
|
| 2216 | - return 0; |
|
| 2252 | + if($this->dataStr == '') {
|
|
| 2253 | + return 0; |
|
| 2254 | + } |
|
| 2217 | 2255 | |
| 2218 | 2256 | $mode = $this->identifyMode(0); |
| 2219 | 2257 | |
@@ -2221,16 +2259,22 @@ discard block |
||
| 2221 | 2259 | case QR_MODE_NUM: $length = $this->eatNum(); break; |
| 2222 | 2260 | case QR_MODE_AN: $length = $this->eatAn(); break; |
| 2223 | 2261 | case QR_MODE_KANJI: |
| 2224 | - if ($mode == QR_MODE_KANJI) |
|
| 2225 | - $length = $this->eatKanji(); |
|
| 2226 | - else $length = $this->eat8(); |
|
| 2262 | + if ($mode == QR_MODE_KANJI) {
|
|
| 2263 | + $length = $this->eatKanji(); |
|
| 2264 | + } else {
|
|
| 2265 | + $length = $this->eat8(); |
|
| 2266 | + } |
|
| 2227 | 2267 | break; |
| 2228 | 2268 | default: $length = $this->eat8(); break; |
| 2229 | 2269 | |
| 2230 | 2270 | } |
| 2231 | 2271 | |
| 2232 | - if($length == 0) return 0; |
|
| 2233 | - if($length < 0) return -1; |
|
| 2272 | + if($length == 0) {
|
|
| 2273 | + return 0; |
|
| 2274 | + } |
|
| 2275 | + if($length < 0) {
|
|
| 2276 | + return -1; |
|
| 2277 | + } |
|
| 2234 | 2278 | |
| 2235 | 2279 | $this->dataStr = substr($this->dataStr, $length); |
| 2236 | 2280 | } |
@@ -2266,8 +2310,9 @@ discard block |
||
| 2266 | 2310 | |
| 2267 | 2311 | $split = new QRsplit($string, $input, $modeHint); |
| 2268 | 2312 | |
| 2269 | - if(!$casesensitive) |
|
| 2270 | - $split->toUpper(); |
|
| 2313 | + if(!$casesensitive) {
|
|
| 2314 | + $split->toUpper(); |
|
| 2315 | + } |
|
| 2271 | 2316 | |
| 2272 | 2317 | return $split->splitString(); |
| 2273 | 2318 | } |
@@ -2344,11 +2389,23 @@ discard block |
||
| 2344 | 2389 | $rs = null; |
| 2345 | 2390 | |
| 2346 | 2391 | // Check parameter ranges |
| 2347 | - if($symsize < 0 || $symsize > 8) return $rs; |
|
| 2348 | - if($fcr < 0 || $fcr >= (1<<$symsize)) return $rs; |
|
| 2349 | - if($prim <= 0 || $prim >= (1<<$symsize)) return $rs; |
|
| 2350 | - if($nroots < 0 || $nroots >= (1<<$symsize)) return $rs; // Can't have more roots than symbol values! |
|
| 2351 | - if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) return $rs; // Too much padding |
|
| 2392 | + if($symsize < 0 || $symsize > 8) {
|
|
| 2393 | + return $rs; |
|
| 2394 | + } |
|
| 2395 | + if($fcr < 0 || $fcr >= (1<<$symsize)) {
|
|
| 2396 | + return $rs; |
|
| 2397 | + } |
|
| 2398 | + if($prim <= 0 || $prim >= (1<<$symsize)) {
|
|
| 2399 | + return $rs; |
|
| 2400 | + } |
|
| 2401 | + if($nroots < 0 || $nroots >= (1<<$symsize)) {
|
|
| 2402 | + return $rs; |
|
| 2403 | + } |
|
| 2404 | + // Can't have more roots than symbol values! |
|
| 2405 | + if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) {
|
|
| 2406 | + return $rs; |
|
| 2407 | + } |
|
| 2408 | + // Too much padding |
|
| 2352 | 2409 | |
| 2353 | 2410 | $rs = new QRrsItem(); |
| 2354 | 2411 | $rs->mm = $symsize; |
@@ -2414,8 +2471,9 @@ discard block |
||
| 2414 | 2471 | } |
| 2415 | 2472 | |
| 2416 | 2473 | // convert rs->genpoly[] to index form for quicker encoding |
| 2417 | - for ($i = 0; $i <= $nroots; $i++) |
|
| 2418 | - $rs->genpoly[$i] = $rs->index_of[$rs->genpoly[$i]]; |
|
| 2474 | + for ($i = 0; $i <= $nroots; $i++) {
|
|
| 2475 | + $rs->genpoly[$i] = $rs->index_of[$rs->genpoly[$i]]; |
|
| 2476 | + } |
|
| 2419 | 2477 | |
| 2420 | 2478 | return $rs; |
| 2421 | 2479 | } |
@@ -2473,12 +2531,24 @@ discard block |
||
| 2473 | 2531 | public static function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) |
| 2474 | 2532 | {
|
| 2475 | 2533 | foreach(self::$items as $rs) {
|
| 2476 | - if($rs->pad != $pad) continue; |
|
| 2477 | - if($rs->nroots != $nroots) continue; |
|
| 2478 | - if($rs->mm != $symsize) continue; |
|
| 2479 | - if($rs->gfpoly != $gfpoly) continue; |
|
| 2480 | - if($rs->fcr != $fcr) continue; |
|
| 2481 | - if($rs->prim != $prim) continue; |
|
| 2534 | + if($rs->pad != $pad) {
|
|
| 2535 | + continue; |
|
| 2536 | + } |
|
| 2537 | + if($rs->nroots != $nroots) {
|
|
| 2538 | + continue; |
|
| 2539 | + } |
|
| 2540 | + if($rs->mm != $symsize) {
|
|
| 2541 | + continue; |
|
| 2542 | + } |
|
| 2543 | + if($rs->gfpoly != $gfpoly) {
|
|
| 2544 | + continue; |
|
| 2545 | + } |
|
| 2546 | + if($rs->fcr != $fcr) {
|
|
| 2547 | + continue; |
|
| 2548 | + } |
|
| 2549 | + if($rs->prim != $prim) {
|
|
| 2550 | + continue; |
|
| 2551 | + } |
|
| 2482 | 2552 | |
| 2483 | 2553 | return $rs; |
| 2484 | 2554 | } |
@@ -2617,8 +2687,9 @@ discard block |
||
| 2617 | 2687 | {
|
| 2618 | 2688 | $codeArr = array(); |
| 2619 | 2689 | |
| 2620 | - foreach ($bitFrame as $line) |
|
| 2621 | - $codeArr[] = join('', $line);
|
|
| 2690 | + foreach ($bitFrame as $line) {
|
|
| 2691 | + $codeArr[] = join('', $line);
|
|
| 2692 | + } |
|
| 2622 | 2693 | |
| 2623 | 2694 | return gzcompress(join("\n", $codeArr), 9);
|
| 2624 | 2695 | } |
@@ -2629,8 +2700,9 @@ discard block |
||
| 2629 | 2700 | $codeArr = array(); |
| 2630 | 2701 | |
| 2631 | 2702 | $codeLines = explode("\n", gzuncompress($code));
|
| 2632 | - foreach ($codeLines as $line) |
|
| 2633 | - $codeArr[] = str_split($line); |
|
| 2703 | + foreach ($codeLines as $line) {
|
|
| 2704 | + $codeArr[] = str_split($line); |
|
| 2705 | + } |
|
| 2634 | 2706 | |
| 2635 | 2707 | return $codeArr; |
| 2636 | 2708 | } |
@@ -2648,16 +2720,18 @@ discard block |
||
| 2648 | 2720 | $bitMask = self::unserial(file_get_contents($fileName)); |
| 2649 | 2721 | } else {
|
| 2650 | 2722 | $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d); |
| 2651 | - if (!file_exists(QR_CACHE_DIR.'mask_'.$maskNo)) |
|
| 2652 | - mkdir(QR_CACHE_DIR.'mask_'.$maskNo); |
|
| 2723 | + if (!file_exists(QR_CACHE_DIR.'mask_'.$maskNo)) {
|
|
| 2724 | + mkdir(QR_CACHE_DIR.'mask_'.$maskNo); |
|
| 2725 | + } |
|
| 2653 | 2726 | file_put_contents($fileName, self::serial($bitMask)); |
| 2654 | 2727 | } |
| 2655 | 2728 | } else {
|
| 2656 | 2729 | $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d); |
| 2657 | 2730 | } |
| 2658 | 2731 | |
| 2659 | - if ($maskGenOnly) |
|
| 2660 | - return; |
|
| 2732 | + if ($maskGenOnly) {
|
|
| 2733 | + return; |
|
| 2734 | + } |
|
| 2661 | 2735 | |
| 2662 | 2736 | $d = $s; |
| 2663 | 2737 | |
@@ -2724,8 +2798,9 @@ discard block |
||
| 2724 | 2798 | |
| 2725 | 2799 | $frameY = $frame[$y]; |
| 2726 | 2800 | |
| 2727 | - if ($y>0) |
|
| 2728 | - $frameYM = $frame[$y-1]; |
|
| 2801 | + if ($y>0) {
|
|
| 2802 | + $frameYM = $frame[$y-1]; |
|
| 2803 | + } |
|
| 2729 | 2804 | |
| 2730 | 2805 | for($x=0; $x<$width; $x++) {
|
| 2731 | 2806 | if(($x > 0) && ($y > 0)) {
|
@@ -2938,14 +3013,17 @@ discard block |
||
| 2938 | 3013 | $blockNo++; |
| 2939 | 3014 | } |
| 2940 | 3015 | |
| 2941 | - if(QRspec::rsBlockNum2($spec) == 0) |
|
| 2942 | - return 0; |
|
| 3016 | + if(QRspec::rsBlockNum2($spec) == 0) {
|
|
| 3017 | + return 0; |
|
| 3018 | + } |
|
| 2943 | 3019 | |
| 2944 | 3020 | $dl = QRspec::rsDataCodes2($spec); |
| 2945 | 3021 | $el = QRspec::rsEccCodes2($spec); |
| 2946 | 3022 | $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el); |
| 2947 | 3023 | |
| 2948 | - if($rs == NULL) return -1; |
|
| 3024 | + if($rs == NULL) {
|
|
| 3025 | + return -1; |
|
| 3026 | + } |
|
| 2949 | 3027 | |
| 2950 | 3028 | for($i=0; $i<QRspec::rsBlockNum2($spec); $i++) { |
| 2951 | 3029 | $ecc = array_slice($this->ecccode,$eccPos); |
@@ -3083,7 +3161,9 @@ discard block |
||
| 3083 | 3161 | } |
| 3084 | 3162 | |
| 3085 | 3163 | $input = new QRinput($version, $level); |
| 3086 | - if($input == NULL) return NULL; |
|
| 3164 | + if($input == NULL) {
|
|
| 3165 | + return NULL; |
|
| 3166 | + } |
|
| 3087 | 3167 | |
| 3088 | 3168 | $ret = $input->append($input, QR_MODE_8, strlen($string), str_split($string)); |
| 3089 | 3169 | if($ret < 0) { |
@@ -3103,7 +3183,9 @@ discard block |
||
| 3103 | 3183 | } |
| 3104 | 3184 | |
| 3105 | 3185 | $input = new QRinput($version, $level); |
| 3106 | - if($input == NULL) return NULL; |
|
| 3186 | + if($input == NULL) {
|
|
| 3187 | + return NULL; |
|
| 3188 | + } |
|
| 3107 | 3189 | |
| 3108 | 3190 | $ret = QRsplit::splitStringToQRinput($string, $input, $hint, $casesensitive); |
| 3109 | 3191 | if($ret < 0) { |
@@ -3227,7 +3309,9 @@ discard block |
||
| 3227 | 3309 | } |
| 3228 | 3310 | } |
| 3229 | 3311 | } |
| 3230 | - if($x < 0 || $y < 0) return null; |
|
| 3312 | + if($x < 0 || $y < 0) {
|
|
| 3313 | + return null; |
|
| 3314 | + } |
|
| 3231 | 3315 | |
| 3232 | 3316 | $this->x = $x; |
| 3233 | 3317 | $this->y = $y; |
@@ -3339,8 +3423,9 @@ discard block |
||
| 3339 | 3423 | $err = ob_get_contents(); |
| 3340 | 3424 | ob_end_clean(); |
| 3341 | 3425 | |
| 3342 | - if ($err != '') |
|
| 3343 | - QRtools::log($outfile, $err); |
|
| 3426 | + if ($err != '') {
|
|
| 3427 | + QRtools::log($outfile, $err); |
|
| 3428 | + } |
|
| 3344 | 3429 | |
| 3345 | 3430 | $maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab)+2*$this->margin)); |
| 3346 | 3431 | |
@@ -3363,8 +3448,9 @@ discard block |
||
| 3363 | 3448 | $err = ob_get_contents(); |
| 3364 | 3449 | ob_end_clean(); |
| 3365 | 3450 | |
| 3366 | - if ($err != '') |
|
| 3367 | - QRtools::log($outfile, $err); |
|
| 3451 | + if ($err != '') {
|
|
| 3452 | + QRtools::log($outfile, $err); |
|
| 3453 | + } |
|
| 3368 | 3454 | |
| 3369 | 3455 | $maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab)+2*$this->margin)); |
| 3370 | 3456 | |
@@ -3387,8 +3473,9 @@ discard block |
||
| 3387 | 3473 | $err = ob_get_contents(); |
| 3388 | 3474 | ob_end_clean(); |
| 3389 | 3475 | |
| 3390 | - if ($err != '') |
|
| 3391 | - QRtools::log($outfile, $err); |
|
| 3476 | + if ($err != '') {
|
|
| 3477 | + QRtools::log($outfile, $err); |
|
| 3478 | + } |
|
| 3392 | 3479 | |
| 3393 | 3480 | $maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab)+2*$this->margin)); |
| 3394 | 3481 | |
@@ -3452,7 +3539,7 @@ discard block |
||
| 3452 | 3539 | header("Content-Type: application/postscript"); |
| 3453 | 3540 | header('Content-Disposition: filename="qrcode.eps"'); |
| 3454 | 3541 | echo $vect; |
| 3455 | - }else{ |
|
| 3542 | + } else{ |
|
| 3456 | 3543 | QRtools::save($vect, $filename); |
| 3457 | 3544 | } |
| 3458 | 3545 | } |
@@ -3483,8 +3570,7 @@ discard block |
||
| 3483 | 3570 | $y = round((($back_color & 0x0000FF00) >> 8) / 255, 5); |
| 3484 | 3571 | $k = round(($back_color & 0x000000FF) / 255, 5); |
| 3485 | 3572 | $back_color_string = $c.' '.$m.' '.$y.' '.$k.' setcmykcolor'."\n"; |
| 3486 | - } |
|
| 3487 | - else |
|
| 3573 | + } else |
|
| 3488 | 3574 | { |
| 3489 | 3575 | // convert a hexadecimal color code into decimal eps format (green = 0 1 0, blue = 0 0 1, ...) |
| 3490 | 3576 | $r = round((($fore_color & 0xFF0000) >> 16) / 255, 5); |
@@ -3562,7 +3648,7 @@ discard block |
||
| 3562 | 3648 | header("Content-Type: image/svg+xml"); |
| 3563 | 3649 | //header('Content-Disposition: filename="'.$filename.'"'); |
| 3564 | 3650 | echo $vect; |
| 3565 | - }else{ |
|
| 3651 | + } else{ |
|
| 3566 | 3652 | QRtools::save($vect, $filename); |
| 3567 | 3653 | } |
| 3568 | 3654 | } |
@@ -25,17 +25,17 @@ |
||
| 25 | 25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 26 | 26 | */ |
| 27 | 27 | |
| 28 | - define('N1', 3);
|
|
| 29 | - define('N2', 3);
|
|
| 30 | - define('N3', 40);
|
|
| 31 | - define('N4', 10);
|
|
| 28 | + define('N1', 3);
|
|
| 29 | + define('N2', 3);
|
|
| 30 | + define('N3', 40);
|
|
| 31 | + define('N4', 10);
|
|
| 32 | 32 | |
| 33 | - class QRmask {
|
|
| 33 | + class QRmask {
|
|
| 34 | 34 | |
| 35 | - public $runLength = array(); |
|
| 35 | + public $runLength = array(); |
|
| 36 | 36 | |
| 37 | - //---------------------------------------------------------------------- |
|
| 38 | - public function __construct() |
|
| 37 | + //---------------------------------------------------------------------- |
|
| 38 | + public function __construct() |
|
| 39 | 39 | {
|
| 40 | 40 | $this->runLength = array_fill(0, QRSPEC_WIDTH_MAX + 1, 0); |
| 41 | 41 | } |
@@ -44,10 +44,10 @@ discard block |
||
| 44 | 44 | public function writeFormatInformation($width, &$frame, $mask, $level) |
| 45 | 45 | {
|
| 46 | 46 | $blacks = 0; |
| 47 | - $format = QRspec::getFormatInfo($mask, $level); |
|
| 47 | + $format = QRspec::getFormatInfo($mask, $level); |
|
| 48 | 48 | |
| 49 | - for($i=0; $i<8; $i++) {
|
|
| 50 | - if($format & 1) {
|
|
| 49 | + for ($i = 0; $i<8; $i++) {
|
|
| 50 | + if ($format & 1) {
|
|
| 51 | 51 | $blacks += 2; |
| 52 | 52 | $v = 0x85; |
| 53 | 53 | } else {
|
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | $frame[8][$width - 1 - $i] = chr($v); |
| 58 | - if($i < 6) {
|
|
| 58 | + if ($i<6) {
|
|
| 59 | 59 | $frame[$i][8] = chr($v); |
| 60 | 60 | } else {
|
| 61 | 61 | $frame[$i + 1][8] = chr($v); |
@@ -63,8 +63,8 @@ discard block |
||
| 63 | 63 | $format = $format >> 1; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - for($i=0; $i<7; $i++) {
|
|
| 67 | - if($format & 1) {
|
|
| 66 | + for ($i = 0; $i<7; $i++) {
|
|
| 67 | + if ($format & 1) {
|
|
| 68 | 68 | $blacks += 2; |
| 69 | 69 | $v = 0x85; |
| 70 | 70 | } else {
|
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | $frame[$width - 7 + $i][8] = chr($v); |
| 75 | - if($i == 0) {
|
|
| 75 | + if ($i==0) {
|
|
| 76 | 76 | $frame[8][7] = chr($v); |
| 77 | 77 | } else {
|
| 78 | 78 | $frame[8][6 - $i] = chr($v); |
@@ -85,27 +85,27 @@ discard block |
||
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | //---------------------------------------------------------------------- |
| 88 | - public function mask0($x, $y) { return ($x+$y)&1; }
|
|
| 89 | - public function mask1($x, $y) { return ($y&1); }
|
|
| 90 | - public function mask2($x, $y) { return ($x%3); }
|
|
| 91 | - public function mask3($x, $y) { return ($x+$y)%3; }
|
|
| 92 | - public function mask4($x, $y) { return (((int)($y/2))+((int)($x/3)))&1; }
|
|
| 93 | - public function mask5($x, $y) { return (($x*$y)&1)+($x*$y)%3; }
|
|
| 94 | - public function mask6($x, $y) { return ((($x*$y)&1)+($x*$y)%3)&1; }
|
|
| 95 | - public function mask7($x, $y) { return ((($x*$y)%3)+(($x+$y)&1))&1; }
|
|
| 88 | + public function mask0($x, $y) { return ($x + $y) & 1; }
|
|
| 89 | + public function mask1($x, $y) { return ($y & 1); }
|
|
| 90 | + public function mask2($x, $y) { return ($x % 3); }
|
|
| 91 | + public function mask3($x, $y) { return ($x + $y) % 3; }
|
|
| 92 | + public function mask4($x, $y) { return (((int)($y / 2)) + ((int)($x / 3))) & 1; }
|
|
| 93 | + public function mask5($x, $y) { return (($x * $y) & 1) + ($x * $y) % 3; }
|
|
| 94 | + public function mask6($x, $y) { return ((($x * $y) & 1) + ($x * $y) % 3) & 1; }
|
|
| 95 | + public function mask7($x, $y) { return ((($x * $y) % 3) + (($x + $y) & 1)) & 1; }
|
|
| 96 | 96 | |
| 97 | 97 | //---------------------------------------------------------------------- |
| 98 | 98 | private function generateMaskNo($maskNo, $width, $frame) |
| 99 | 99 | {
|
| 100 | 100 | $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); |
| 101 | 101 | |
| 102 | - for($y=0; $y<$width; $y++) {
|
|
| 103 | - for($x=0; $x<$width; $x++) {
|
|
| 104 | - if(ord($frame[$y][$x]) & 0x80) {
|
|
| 102 | + for ($y = 0; $y<$width; $y++) {
|
|
| 103 | + for ($x = 0; $x<$width; $x++) {
|
|
| 104 | + if (ord($frame[$y][$x]) & 0x80) {
|
|
| 105 | 105 | $bitMask[$y][$x] = 0; |
| 106 | 106 | } else {
|
| 107 | 107 | $maskFunc = call_user_func(array($this, 'mask'.$maskNo), $x, $y); |
| 108 | - $bitMask[$y][$x] = ($maskFunc == 0)?1:0; |
|
| 108 | + $bitMask[$y][$x] = ($maskFunc==0) ? 1 : 0; |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | } |
@@ -163,9 +163,9 @@ discard block |
||
| 163 | 163 | |
| 164 | 164 | $d = $s; |
| 165 | 165 | |
| 166 | - for($y=0; $y<$width; $y++) {
|
|
| 167 | - for($x=0; $x<$width; $x++) {
|
|
| 168 | - if($bitMask[$y][$x] == 1) {
|
|
| 166 | + for ($y = 0; $y<$width; $y++) {
|
|
| 167 | + for ($x = 0; $x<$width; $x++) {
|
|
| 168 | + if ($bitMask[$y][$x]==1) {
|
|
| 169 | 169 | $d[$y][$x] = chr(ord($s[$y][$x]) ^ (int)$bitMask[$y][$x]); |
| 170 | 170 | } |
| 171 | 171 | $b += (int)(ord($d[$y][$x]) & 1); |
@@ -190,21 +190,21 @@ discard block |
||
| 190 | 190 | {
|
| 191 | 191 | $demerit = 0; |
| 192 | 192 | |
| 193 | - for($i=0; $i<$length; $i++) {
|
|
| 193 | + for ($i = 0; $i<$length; $i++) {
|
|
| 194 | 194 | |
| 195 | - if($this->runLength[$i] >= 5) {
|
|
| 195 | + if ($this->runLength[$i]>=5) {
|
|
| 196 | 196 | $demerit += (N1 + ($this->runLength[$i] - 5)); |
| 197 | 197 | } |
| 198 | - if($i & 1) {
|
|
| 199 | - if(($i >= 3) && ($i < ($length-2)) && ($this->runLength[$i] % 3 == 0)) {
|
|
| 198 | + if ($i & 1) {
|
|
| 199 | + if (($i>=3) && ($i<($length - 2)) && ($this->runLength[$i] % 3==0)) {
|
|
| 200 | 200 | $fact = (int)($this->runLength[$i] / 3); |
| 201 | - if(($this->runLength[$i-2] == $fact) && |
|
| 202 | - ($this->runLength[$i-1] == $fact) && |
|
| 203 | - ($this->runLength[$i+1] == $fact) && |
|
| 204 | - ($this->runLength[$i+2] == $fact)) {
|
|
| 205 | - if(($this->runLength[$i-3] < 0) || ($this->runLength[$i-3] >= (4 * $fact))) {
|
|
| 201 | + if (($this->runLength[$i - 2]==$fact) && |
|
| 202 | + ($this->runLength[$i - 1]==$fact) && |
|
| 203 | + ($this->runLength[$i + 1]==$fact) && |
|
| 204 | + ($this->runLength[$i + 2]==$fact)) {
|
|
| 205 | + if (($this->runLength[$i - 3]<0) || ($this->runLength[$i - 3]>=(4 * $fact))) {
|
|
| 206 | 206 | $demerit += N3; |
| 207 | - } else if((($i+3) >= $length) || ($this->runLength[$i+3] >= (4 * $fact))) {
|
|
| 207 | + } else if ((($i + 3)>=$length) || ($this->runLength[$i + 3]>=(4 * $fact))) {
|
|
| 208 | 208 | $demerit += N3; |
| 209 | 209 | } |
| 210 | 210 | } |
@@ -220,30 +220,30 @@ discard block |
||
| 220 | 220 | $head = 0; |
| 221 | 221 | $demerit = 0; |
| 222 | 222 | |
| 223 | - for($y=0; $y<$width; $y++) {
|
|
| 223 | + for ($y = 0; $y<$width; $y++) {
|
|
| 224 | 224 | $head = 0; |
| 225 | 225 | $this->runLength[0] = 1; |
| 226 | 226 | |
| 227 | 227 | $frameY = $frame[$y]; |
| 228 | 228 | |
| 229 | 229 | if ($y>0) |
| 230 | - $frameYM = $frame[$y-1]; |
|
| 230 | + $frameYM = $frame[$y - 1]; |
|
| 231 | 231 | |
| 232 | - for($x=0; $x<$width; $x++) {
|
|
| 233 | - if(($x > 0) && ($y > 0)) {
|
|
| 234 | - $b22 = ord($frameY[$x]) & ord($frameY[$x-1]) & ord($frameYM[$x]) & ord($frameYM[$x-1]); |
|
| 235 | - $w22 = ord($frameY[$x]) | ord($frameY[$x-1]) | ord($frameYM[$x]) | ord($frameYM[$x-1]); |
|
| 232 | + for ($x = 0; $x<$width; $x++) {
|
|
| 233 | + if (($x>0) && ($y>0)) {
|
|
| 234 | + $b22 = ord($frameY[$x]) & ord($frameY[$x - 1]) & ord($frameYM[$x]) & ord($frameYM[$x - 1]); |
|
| 235 | + $w22 = ord($frameY[$x]) | ord($frameY[$x - 1]) | ord($frameYM[$x]) | ord($frameYM[$x - 1]); |
|
| 236 | 236 | |
| 237 | - if(($b22 | ($w22 ^ 1))&1) {
|
|
| 237 | + if (($b22 | ($w22 ^ 1)) & 1) {
|
|
| 238 | 238 | $demerit += N2; |
| 239 | 239 | } |
| 240 | 240 | } |
| 241 | - if(($x == 0) && (ord($frameY[$x]) & 1)) {
|
|
| 241 | + if (($x==0) && (ord($frameY[$x]) & 1)) {
|
|
| 242 | 242 | $this->runLength[0] = -1; |
| 243 | 243 | $head = 1; |
| 244 | 244 | $this->runLength[$head] = 1; |
| 245 | - } else if($x > 0) {
|
|
| 246 | - if((ord($frameY[$x]) ^ ord($frameY[$x-1])) & 1) {
|
|
| 245 | + } else if ($x>0) {
|
|
| 246 | + if ((ord($frameY[$x]) ^ ord($frameY[$x - 1])) & 1) {
|
|
| 247 | 247 | $head++; |
| 248 | 248 | $this->runLength[$head] = 1; |
| 249 | 249 | } else {
|
@@ -252,20 +252,20 @@ discard block |
||
| 252 | 252 | } |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | - $demerit += $this->calcN1N3($head+1); |
|
| 255 | + $demerit += $this->calcN1N3($head + 1); |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | - for($x=0; $x<$width; $x++) {
|
|
| 258 | + for ($x = 0; $x<$width; $x++) {
|
|
| 259 | 259 | $head = 0; |
| 260 | 260 | $this->runLength[0] = 1; |
| 261 | 261 | |
| 262 | - for($y=0; $y<$width; $y++) {
|
|
| 263 | - if($y == 0 && (ord($frame[$y][$x]) & 1)) {
|
|
| 262 | + for ($y = 0; $y<$width; $y++) {
|
|
| 263 | + if ($y==0 && (ord($frame[$y][$x]) & 1)) {
|
|
| 264 | 264 | $this->runLength[0] = -1; |
| 265 | 265 | $head = 1; |
| 266 | 266 | $this->runLength[$head] = 1; |
| 267 | - } else if($y > 0) {
|
|
| 268 | - if((ord($frame[$y][$x]) ^ ord($frame[$y-1][$x])) & 1) {
|
|
| 267 | + } else if ($y>0) {
|
|
| 268 | + if ((ord($frame[$y][$x]) ^ ord($frame[$y - 1][$x])) & 1) {
|
|
| 269 | 269 | $head++; |
| 270 | 270 | $this->runLength[$head] = 1; |
| 271 | 271 | } else {
|
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | } |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | - $demerit += $this->calcN1N3($head+1); |
|
| 277 | + $demerit += $this->calcN1N3($head + 1); |
|
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 280 | return $demerit; |
@@ -288,13 +288,13 @@ discard block |
||
| 288 | 288 | $bestMaskNum = 0; |
| 289 | 289 | $bestMask = array(); |
| 290 | 290 | |
| 291 | - $checked_masks = array(0,1,2,3,4,5,6,7); |
|
| 291 | + $checked_masks = array(0, 1, 2, 3, 4, 5, 6, 7); |
|
| 292 | 292 | |
| 293 | - if (QR_FIND_FROM_RANDOM !== false) {
|
|
| 293 | + if (QR_FIND_FROM_RANDOM!==false) {
|
|
| 294 | 294 | |
| 295 | - $howManuOut = 8-(QR_FIND_FROM_RANDOM % 9); |
|
| 296 | - for ($i = 0; $i < $howManuOut; $i++) {
|
|
| 297 | - $remPos = rand (0, count($checked_masks)-1); |
|
| 295 | + $howManuOut = 8 - (QR_FIND_FROM_RANDOM % 9); |
|
| 296 | + for ($i = 0; $i<$howManuOut; $i++) {
|
|
| 297 | + $remPos = rand(0, count($checked_masks) - 1); |
|
| 298 | 298 | unset($checked_masks[$remPos]); |
| 299 | 299 | $checked_masks = array_values($checked_masks); |
| 300 | 300 | } |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | |
| 304 | 304 | $bestMask = $frame; |
| 305 | 305 | |
| 306 | - foreach($checked_masks as $i) {
|
|
| 306 | + foreach ($checked_masks as $i) {
|
|
| 307 | 307 | $mask = array_fill(0, $width, str_repeat("\0", $width));
|
| 308 | 308 | |
| 309 | 309 | $demerit = 0; |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | $demerit = (int)((int)(abs($blacks - 50) / 5) * N4); |
| 315 | 315 | $demerit += $this->evaluateSymbol($width, $mask); |
| 316 | 316 | |
| 317 | - if($demerit < $minDemerit) {
|
|
| 317 | + if ($demerit<$minDemerit) {
|
|
| 318 | 318 | $minDemerit = $demerit; |
| 319 | 319 | $bestMask = $mask; |
| 320 | 320 | $bestMaskNum = $i; |
@@ -119,8 +119,9 @@ discard block |
||
| 119 | 119 | {
|
| 120 | 120 | $codeArr = array(); |
| 121 | 121 | |
| 122 | - foreach ($bitFrame as $line) |
|
| 123 | - $codeArr[] = join('', $line);
|
|
| 122 | + foreach ($bitFrame as $line) {
|
|
| 123 | + $codeArr[] = join('', $line);
|
|
| 124 | + } |
|
| 124 | 125 | |
| 125 | 126 | return gzcompress(join("\n", $codeArr), 9);
|
| 126 | 127 | } |
@@ -131,8 +132,9 @@ discard block |
||
| 131 | 132 | $codeArr = array(); |
| 132 | 133 | |
| 133 | 134 | $codeLines = explode("\n", gzuncompress($code));
|
| 134 | - foreach ($codeLines as $line) |
|
| 135 | - $codeArr[] = str_split($line); |
|
| 135 | + foreach ($codeLines as $line) {
|
|
| 136 | + $codeArr[] = str_split($line); |
|
| 137 | + } |
|
| 136 | 138 | |
| 137 | 139 | return $codeArr; |
| 138 | 140 | } |
@@ -150,16 +152,18 @@ discard block |
||
| 150 | 152 | $bitMask = self::unserial(file_get_contents($fileName)); |
| 151 | 153 | } else {
|
| 152 | 154 | $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d); |
| 153 | - if (!file_exists(QR_CACHE_DIR.'mask_'.$maskNo)) |
|
| 154 | - mkdir(QR_CACHE_DIR.'mask_'.$maskNo); |
|
| 155 | + if (!file_exists(QR_CACHE_DIR.'mask_'.$maskNo)) {
|
|
| 156 | + mkdir(QR_CACHE_DIR.'mask_'.$maskNo); |
|
| 157 | + } |
|
| 155 | 158 | file_put_contents($fileName, self::serial($bitMask)); |
| 156 | 159 | } |
| 157 | 160 | } else {
|
| 158 | 161 | $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d); |
| 159 | 162 | } |
| 160 | 163 | |
| 161 | - if ($maskGenOnly) |
|
| 162 | - return; |
|
| 164 | + if ($maskGenOnly) {
|
|
| 165 | + return; |
|
| 166 | + } |
|
| 163 | 167 | |
| 164 | 168 | $d = $s; |
| 165 | 169 | |
@@ -226,8 +230,9 @@ discard block |
||
| 226 | 230 | |
| 227 | 231 | $frameY = $frame[$y]; |
| 228 | 232 | |
| 229 | - if ($y>0) |
|
| 230 | - $frameYM = $frame[$y-1]; |
|
| 233 | + if ($y>0) {
|
|
| 234 | + $frameYM = $frame[$y-1]; |
|
| 235 | + } |
|
| 231 | 236 | |
| 232 | 237 | for($x=0; $x<$width; $x++) {
|
| 233 | 238 | if(($x > 0) && ($y > 0)) {
|
@@ -422,7 +422,7 @@ |
||
| 422 | 422 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 423 | 423 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 424 | 424 | 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, |
| 425 | - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, |
|
| 425 | + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, |
|
| 426 | 426 | -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, |
| 427 | 427 | 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, |
| 428 | 428 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 26 | 26 | */ |
| 27 | 27 | |
| 28 | - define('STRUCTURE_HEADER_BITS', 20);
|
|
| 28 | + define('STRUCTURE_HEADER_BITS', 20);
|
|
| 29 | 29 | define('MAX_STRUCTURED_SYMBOLS', 16);
|
| 30 | 30 | |
| 31 | 31 | class QRinputItem {
|
@@ -39,12 +39,12 @@ discard block |
||
| 39 | 39 | {
|
| 40 | 40 | $setData = array_slice($data, 0, $size); |
| 41 | 41 | |
| 42 | - if (count($setData) < $size) {
|
|
| 43 | - $setData = array_merge($setData, array_fill(0,$size-count($setData),0)); |
|
| 42 | + if (count($setData)<$size) {
|
|
| 43 | + $setData = array_merge($setData, array_fill(0, $size - count($setData), 0)); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - if(!QRinput::check($mode, $size, $setData)) {
|
|
| 47 | - throw new Exception('Error m:'.$mode.',s:'.$size.',d:'.join(',',$setData));
|
|
| 46 | + if (!QRinput::check($mode, $size, $setData)) {
|
|
| 47 | + throw new Exception('Error m:'.$mode.',s:'.$size.',d:'.join(',', $setData));
|
|
| 48 | 48 | return null; |
| 49 | 49 | } |
| 50 | 50 | |
@@ -66,19 +66,19 @@ discard block |
||
| 66 | 66 | $bs->appendNum(4, $val); |
| 67 | 67 | $bs->appendNum(QRspec::lengthIndicator(QR_MODE_NUM, $version), $this->size); |
| 68 | 68 | |
| 69 | - for($i=0; $i<$words; $i++) {
|
|
| 70 | - $val = (ord($this->data[$i*3 ]) - ord('0')) * 100;
|
|
| 71 | - $val += (ord($this->data[$i*3+1]) - ord('0')) * 10;
|
|
| 72 | - $val += (ord($this->data[$i*3+2]) - ord('0'));
|
|
| 69 | + for ($i = 0; $i<$words; $i++) {
|
|
| 70 | + $val = (ord($this->data[$i * 3]) - ord('0')) * 100;
|
|
| 71 | + $val += (ord($this->data[$i * 3 + 1]) - ord('0')) * 10;
|
|
| 72 | + $val += (ord($this->data[$i * 3 + 2]) - ord('0'));
|
|
| 73 | 73 | $bs->appendNum(10, $val); |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - if($this->size - $words * 3 == 1) {
|
|
| 77 | - $val = ord($this->data[$words*3]) - ord('0');
|
|
| 76 | + if ($this->size - $words * 3==1) {
|
|
| 77 | + $val = ord($this->data[$words * 3]) - ord('0');
|
|
| 78 | 78 | $bs->appendNum(4, $val); |
| 79 | - } else if($this->size - $words * 3 == 2) {
|
|
| 80 | - $val = (ord($this->data[$words*3 ]) - ord('0')) * 10;
|
|
| 81 | - $val += (ord($this->data[$words*3+1]) - ord('0'));
|
|
| 79 | + } else if ($this->size - $words * 3==2) {
|
|
| 80 | + $val = (ord($this->data[$words * 3]) - ord('0')) * 10;
|
|
| 81 | + $val += (ord($this->data[$words * 3 + 1]) - ord('0'));
|
|
| 82 | 82 | $bs->appendNum(7, $val); |
| 83 | 83 | } |
| 84 | 84 | |
@@ -100,14 +100,14 @@ discard block |
||
| 100 | 100 | $bs->appendNum(4, 0x02); |
| 101 | 101 | $bs->appendNum(QRspec::lengthIndicator(QR_MODE_AN, $version), $this->size); |
| 102 | 102 | |
| 103 | - for($i=0; $i<$words; $i++) {
|
|
| 104 | - $val = (int)QRinput::lookAnTable(ord($this->data[$i*2 ])) * 45; |
|
| 105 | - $val += (int)QRinput::lookAnTable(ord($this->data[$i*2+1])); |
|
| 103 | + for ($i = 0; $i<$words; $i++) {
|
|
| 104 | + $val = (int)QRinput::lookAnTable(ord($this->data[$i * 2])) * 45; |
|
| 105 | + $val += (int)QRinput::lookAnTable(ord($this->data[$i * 2 + 1])); |
|
| 106 | 106 | |
| 107 | 107 | $bs->appendNum(11, $val); |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - if($this->size & 1) {
|
|
| 110 | + if ($this->size & 1) {
|
|
| 111 | 111 | $val = QRinput::lookAnTable(ord($this->data[$words * 2])); |
| 112 | 112 | $bs->appendNum(6, $val); |
| 113 | 113 | } |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | $bs->appendNum(4, 0x4); |
| 130 | 130 | $bs->appendNum(QRspec::lengthIndicator(QR_MODE_8, $version), $this->size); |
| 131 | 131 | |
| 132 | - for($i=0; $i<$this->size; $i++) {
|
|
| 132 | + for ($i = 0; $i<$this->size; $i++) {
|
|
| 133 | 133 | $bs->appendNum(8, ord($this->data[$i])); |
| 134 | 134 | } |
| 135 | 135 | |
@@ -151,9 +151,9 @@ discard block |
||
| 151 | 151 | $bs->appendNum(4, 0x8); |
| 152 | 152 | $bs->appendNum(QRspec::lengthIndicator(QR_MODE_KANJI, $version), (int)($this->size / 2)); |
| 153 | 153 | |
| 154 | - for($i=0; $i<$this->size; $i+=2) {
|
|
| 155 | - $val = (ord($this->data[$i]) << 8) | ord($this->data[$i+1]); |
|
| 156 | - if($val <= 0x9ffc) {
|
|
| 154 | + for ($i = 0; $i<$this->size; $i += 2) {
|
|
| 155 | + $val = (ord($this->data[$i]) << 8) | ord($this->data[$i + 1]); |
|
| 156 | + if ($val<=0x9ffc) {
|
|
| 157 | 157 | $val -= 0x8140; |
| 158 | 158 | } else {
|
| 159 | 159 | $val -= 0xc140; |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | public function encodeModeStructure() |
| 178 | 178 | {
|
| 179 | 179 | try {
|
| 180 | - $bs = new QRbitstream(); |
|
| 180 | + $bs = new QRbitstream(); |
|
| 181 | 181 | |
| 182 | 182 | $bs->appendNum(4, 0x03); |
| 183 | 183 | $bs->appendNum(4, ord($this->data[1]) - 1); |
@@ -197,14 +197,14 @@ discard block |
||
| 197 | 197 | {
|
| 198 | 198 | $bits = 0; |
| 199 | 199 | |
| 200 | - if($version == 0) |
|
| 200 | + if ($version==0) |
|
| 201 | 201 | $version = 1; |
| 202 | 202 | |
| 203 | - switch($this->mode) {
|
|
| 204 | - case QR_MODE_NUM: $bits = QRinput::estimateBitsModeNum($this->size); break; |
|
| 205 | - case QR_MODE_AN: $bits = QRinput::estimateBitsModeAn($this->size); break; |
|
| 206 | - case QR_MODE_8: $bits = QRinput::estimateBitsMode8($this->size); break; |
|
| 207 | - case QR_MODE_KANJI: $bits = QRinput::estimateBitsModeKanji($this->size);break; |
|
| 203 | + switch ($this->mode) {
|
|
| 204 | + case QR_MODE_NUM: $bits = QRinput::estimateBitsModeNum($this->size); break; |
|
| 205 | + case QR_MODE_AN: $bits = QRinput::estimateBitsModeAn($this->size); break; |
|
| 206 | + case QR_MODE_8: $bits = QRinput::estimateBitsMode8($this->size); break; |
|
| 207 | + case QR_MODE_KANJI: $bits = QRinput::estimateBitsModeKanji($this->size); break; |
|
| 208 | 208 | case QR_MODE_STRUCTURE: return STRUCTURE_HEADER_BITS; |
| 209 | 209 | default: |
| 210 | 210 | return 0; |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | unset($this->bstream); |
| 228 | 228 | $words = QRspec::maximumWords($this->mode, $version); |
| 229 | 229 | |
| 230 | - if($this->size > $words) {
|
|
| 230 | + if ($this->size>$words) {
|
|
| 231 | 231 | |
| 232 | 232 | $st1 = new QRinputItem($this->mode, $words, $this->data); |
| 233 | 233 | $st2 = new QRinputItem($this->mode, $this->size - $words, array_slice($this->data, $words)); |
@@ -246,18 +246,18 @@ discard block |
||
| 246 | 246 | |
| 247 | 247 | $ret = 0; |
| 248 | 248 | |
| 249 | - switch($this->mode) {
|
|
| 250 | - case QR_MODE_NUM: $ret = $this->encodeModeNum($version); break; |
|
| 251 | - case QR_MODE_AN: $ret = $this->encodeModeAn($version); break; |
|
| 252 | - case QR_MODE_8: $ret = $this->encodeMode8($version); break; |
|
| 253 | - case QR_MODE_KANJI: $ret = $this->encodeModeKanji($version);break; |
|
| 254 | - case QR_MODE_STRUCTURE: $ret = $this->encodeModeStructure(); break; |
|
| 249 | + switch ($this->mode) {
|
|
| 250 | + case QR_MODE_NUM: $ret = $this->encodeModeNum($version); break; |
|
| 251 | + case QR_MODE_AN: $ret = $this->encodeModeAn($version); break; |
|
| 252 | + case QR_MODE_8: $ret = $this->encodeMode8($version); break; |
|
| 253 | + case QR_MODE_KANJI: $ret = $this->encodeModeKanji($version); break; |
|
| 254 | + case QR_MODE_STRUCTURE: $ret = $this->encodeModeStructure(); break; |
|
| 255 | 255 | |
| 256 | 256 | default: |
| 257 | 257 | break; |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | - if($ret < 0) |
|
| 260 | + if ($ret<0) |
|
| 261 | 261 | return -1; |
| 262 | 262 | } |
| 263 | 263 | |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | //---------------------------------------------------------------------- |
| 282 | 282 | public function __construct($version = 0, $level = QR_ECLEVEL_L) |
| 283 | 283 | {
|
| 284 | - if ($version < 0 || $version > QRSPEC_VERSION_MAX || $level > QR_ECLEVEL_H) {
|
|
| 284 | + if ($version<0 || $version>QRSPEC_VERSION_MAX || $level>QR_ECLEVEL_H) {
|
|
| 285 | 285 | throw new Exception('Invalid version no');
|
| 286 | 286 | return NULL; |
| 287 | 287 | } |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | //---------------------------------------------------------------------- |
| 300 | 300 | public function setVersion($version) |
| 301 | 301 | {
|
| 302 | - if($version < 0 || $version > QRSPEC_VERSION_MAX) {
|
|
| 302 | + if ($version<0 || $version>QRSPEC_VERSION_MAX) {
|
|
| 303 | 303 | throw new Exception('Invalid version no');
|
| 304 | 304 | return -1; |
| 305 | 305 | } |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | //---------------------------------------------------------------------- |
| 319 | 319 | public function setErrorCorrectionLevel($level) |
| 320 | 320 | {
|
| 321 | - if($level > QR_ECLEVEL_H) {
|
|
| 321 | + if ($level>QR_ECLEVEL_H) {
|
|
| 322 | 322 | throw new Exception('Invalid ECLEVEL');
|
| 323 | 323 | return -1; |
| 324 | 324 | } |
@@ -350,11 +350,11 @@ discard block |
||
| 350 | 350 | |
| 351 | 351 | public function insertStructuredAppendHeader($size, $index, $parity) |
| 352 | 352 | {
|
| 353 | - if( $size > MAX_STRUCTURED_SYMBOLS ) {
|
|
| 353 | + if ($size>MAX_STRUCTURED_SYMBOLS) {
|
|
| 354 | 354 | throw new Exception('insertStructuredAppendHeader wrong size');
|
| 355 | 355 | } |
| 356 | 356 | |
| 357 | - if( $index <= 0 || $index > MAX_STRUCTURED_SYMBOLS ) {
|
|
| 357 | + if ($index<=0 || $index>MAX_STRUCTURED_SYMBOLS) {
|
|
| 358 | 358 | throw new Exception('insertStructuredAppendHeader wrong index');
|
| 359 | 359 | } |
| 360 | 360 | |
@@ -374,9 +374,9 @@ discard block |
||
| 374 | 374 | {
|
| 375 | 375 | $parity = 0; |
| 376 | 376 | |
| 377 | - foreach($this->items as $item) {
|
|
| 378 | - if($item->mode != QR_MODE_STRUCTURE) {
|
|
| 379 | - for($i=$item->size-1; $i>=0; $i--) {
|
|
| 377 | + foreach ($this->items as $item) {
|
|
| 378 | + if ($item->mode!=QR_MODE_STRUCTURE) {
|
|
| 379 | + for ($i = $item->size - 1; $i>=0; $i--) {
|
|
| 380 | 380 | $parity ^= $item->data[$i]; |
| 381 | 381 | } |
| 382 | 382 | } |
@@ -388,8 +388,8 @@ discard block |
||
| 388 | 388 | //---------------------------------------------------------------------- |
| 389 | 389 | public static function checkModeNum($size, $data) |
| 390 | 390 | {
|
| 391 | - for($i=0; $i<$size; $i++) {
|
|
| 392 | - if((ord($data[$i]) < ord('0')) || (ord($data[$i]) > ord('9'))){
|
|
| 391 | + for ($i = 0; $i<$size; $i++) {
|
|
| 392 | + if ((ord($data[$i])<ord('0')) || (ord($data[$i])>ord('9'))) {
|
|
| 393 | 393 | return false; |
| 394 | 394 | } |
| 395 | 395 | } |
@@ -403,7 +403,7 @@ discard block |
||
| 403 | 403 | $w = (int)$size / 3; |
| 404 | 404 | $bits = $w * 10; |
| 405 | 405 | |
| 406 | - switch($size - $w * 3) {
|
|
| 406 | + switch ($size - $w * 3) {
|
|
| 407 | 407 | case 1: |
| 408 | 408 | $bits += 4; |
| 409 | 409 | break; |
@@ -422,7 +422,7 @@ discard block |
||
| 422 | 422 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 423 | 423 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 424 | 424 | 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, |
| 425 | - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, |
|
| 425 | + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, |
|
| 426 | 426 | -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, |
| 427 | 427 | 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, |
| 428 | 428 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
@@ -432,14 +432,14 @@ discard block |
||
| 432 | 432 | //---------------------------------------------------------------------- |
| 433 | 433 | public static function lookAnTable($c) |
| 434 | 434 | {
|
| 435 | - return (($c > 127)?-1:self::$anTable[$c]); |
|
| 435 | + return (($c>127) ?-1 : self::$anTable[$c]); |
|
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | //---------------------------------------------------------------------- |
| 439 | 439 | public static function checkModeAn($size, $data) |
| 440 | 440 | {
|
| 441 | - for($i=0; $i<$size; $i++) {
|
|
| 442 | - if (self::lookAnTable(ord($data[$i])) == -1) {
|
|
| 441 | + for ($i = 0; $i<$size; $i++) {
|
|
| 442 | + if (self::lookAnTable(ord($data[$i]))==-1) {
|
|
| 443 | 443 | return false; |
| 444 | 444 | } |
| 445 | 445 | } |
@@ -453,7 +453,7 @@ discard block |
||
| 453 | 453 | $w = (int)($size / 2); |
| 454 | 454 | $bits = $w * 11; |
| 455 | 455 | |
| 456 | - if($size & 1) {
|
|
| 456 | + if ($size & 1) {
|
|
| 457 | 457 | $bits += 6; |
| 458 | 458 | } |
| 459 | 459 | |
@@ -475,14 +475,14 @@ discard block |
||
| 475 | 475 | //---------------------------------------------------------------------- |
| 476 | 476 | public static function checkModeKanji($size, $data) |
| 477 | 477 | {
|
| 478 | - if($size & 1) |
|
| 478 | + if ($size & 1) |
|
| 479 | 479 | return false; |
| 480 | 480 | |
| 481 | - for($i=0; $i<$size; $i+=2) {
|
|
| 482 | - $val = (ord($data[$i]) << 8) | ord($data[$i+1]); |
|
| 483 | - if( $val < 0x8140 |
|
| 484 | - || ($val > 0x9ffc && $val < 0xe040) |
|
| 485 | - || $val > 0xebbf) {
|
|
| 481 | + for ($i = 0; $i<$size; $i += 2) {
|
|
| 482 | + $val = (ord($data[$i]) << 8) | ord($data[$i + 1]); |
|
| 483 | + if ($val<0x8140 |
|
| 484 | + || ($val>0x9ffc && $val<0xe040) |
|
| 485 | + || $val>0xebbf) {
|
|
| 486 | 486 | return false; |
| 487 | 487 | } |
| 488 | 488 | } |
@@ -496,12 +496,12 @@ discard block |
||
| 496 | 496 | |
| 497 | 497 | public static function check($mode, $size, $data) |
| 498 | 498 | {
|
| 499 | - if($size <= 0) |
|
| 499 | + if ($size<=0) |
|
| 500 | 500 | return false; |
| 501 | 501 | |
| 502 | - switch($mode) {
|
|
| 503 | - case QR_MODE_NUM: return self::checkModeNum($size, $data); break; |
|
| 504 | - case QR_MODE_AN: return self::checkModeAn($size, $data); break; |
|
| 502 | + switch ($mode) {
|
|
| 503 | + case QR_MODE_NUM: return self::checkModeNum($size, $data); break; |
|
| 504 | + case QR_MODE_AN: return self::checkModeAn($size, $data); break; |
|
| 505 | 505 | case QR_MODE_KANJI: return self::checkModeKanji($size, $data); break; |
| 506 | 506 | case QR_MODE_8: return true; break; |
| 507 | 507 | case QR_MODE_STRUCTURE: return true; break; |
@@ -519,7 +519,7 @@ discard block |
||
| 519 | 519 | {
|
| 520 | 520 | $bits = 0; |
| 521 | 521 | |
| 522 | - foreach($this->items as $item) {
|
|
| 522 | + foreach ($this->items as $item) {
|
|
| 523 | 523 | $bits += $item->estimateBitStreamSizeOfEntry($version); |
| 524 | 524 | } |
| 525 | 525 | |
@@ -535,10 +535,10 @@ discard block |
||
| 535 | 535 | $prev = $version; |
| 536 | 536 | $bits = $this->estimateBitStreamSize($prev); |
| 537 | 537 | $version = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); |
| 538 | - if ($version < 0) {
|
|
| 538 | + if ($version<0) {
|
|
| 539 | 539 | return -1; |
| 540 | 540 | } |
| 541 | - } while ($version > $prev); |
|
| 541 | + } while ($version>$prev); |
|
| 542 | 542 | |
| 543 | 543 | return $version; |
| 544 | 544 | } |
@@ -547,14 +547,14 @@ discard block |
||
| 547 | 547 | public static function lengthOfCode($mode, $version, $bits) |
| 548 | 548 | {
|
| 549 | 549 | $payload = $bits - 4 - QRspec::lengthIndicator($mode, $version); |
| 550 | - switch($mode) {
|
|
| 550 | + switch ($mode) {
|
|
| 551 | 551 | case QR_MODE_NUM: |
| 552 | 552 | $chunks = (int)($payload / 10); |
| 553 | 553 | $remain = $payload - $chunks * 10; |
| 554 | 554 | $size = $chunks * 3; |
| 555 | - if($remain >= 7) {
|
|
| 555 | + if ($remain>=7) {
|
|
| 556 | 556 | $size += 2; |
| 557 | - } else if($remain >= 4) {
|
|
| 557 | + } else if ($remain>=4) {
|
|
| 558 | 558 | $size += 1; |
| 559 | 559 | } |
| 560 | 560 | break; |
@@ -562,7 +562,7 @@ discard block |
||
| 562 | 562 | $chunks = (int)($payload / 11); |
| 563 | 563 | $remain = $payload - $chunks * 11; |
| 564 | 564 | $size = $chunks * 2; |
| 565 | - if($remain >= 6) |
|
| 565 | + if ($remain>=6) |
|
| 566 | 566 | $size++; |
| 567 | 567 | break; |
| 568 | 568 | case QR_MODE_8: |
@@ -580,8 +580,8 @@ discard block |
||
| 580 | 580 | } |
| 581 | 581 | |
| 582 | 582 | $maxsize = QRspec::maximumWords($mode, $version); |
| 583 | - if($size < 0) $size = 0; |
|
| 584 | - if($size > $maxsize) $size = $maxsize; |
|
| 583 | + if ($size<0) $size = 0; |
|
| 584 | + if ($size>$maxsize) $size = $maxsize; |
|
| 585 | 585 | |
| 586 | 586 | return $size; |
| 587 | 587 | } |
@@ -591,10 +591,10 @@ discard block |
||
| 591 | 591 | {
|
| 592 | 592 | $total = 0; |
| 593 | 593 | |
| 594 | - foreach($this->items as $item) {
|
|
| 594 | + foreach ($this->items as $item) {
|
|
| 595 | 595 | $bits = $item->encodeBitStream($this->version); |
| 596 | 596 | |
| 597 | - if($bits < 0) |
|
| 597 | + if ($bits<0) |
|
| 598 | 598 | return -1; |
| 599 | 599 | |
| 600 | 600 | $total += $bits; |
@@ -607,21 +607,21 @@ discard block |
||
| 607 | 607 | public function convertData() |
| 608 | 608 | {
|
| 609 | 609 | $ver = $this->estimateVersion(); |
| 610 | - if($ver > $this->getVersion()) {
|
|
| 610 | + if ($ver>$this->getVersion()) {
|
|
| 611 | 611 | $this->setVersion($ver); |
| 612 | 612 | } |
| 613 | 613 | |
| 614 | - for(;;) {
|
|
| 614 | + for (;;) {
|
|
| 615 | 615 | $bits = $this->createBitStream(); |
| 616 | 616 | |
| 617 | - if($bits < 0) |
|
| 617 | + if ($bits<0) |
|
| 618 | 618 | return -1; |
| 619 | 619 | |
| 620 | 620 | $ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); |
| 621 | - if($ver < 0) {
|
|
| 621 | + if ($ver<0) {
|
|
| 622 | 622 | throw new Exception('WRONG VERSION');
|
| 623 | 623 | return -1; |
| 624 | - } else if($ver > $this->getVersion()) {
|
|
| 624 | + } else if ($ver>$this->getVersion()) {
|
|
| 625 | 625 | $this->setVersion($ver); |
| 626 | 626 | } else {
|
| 627 | 627 | break; |
@@ -638,11 +638,11 @@ discard block |
||
| 638 | 638 | $maxwords = QRspec::getDataLength($this->version, $this->level); |
| 639 | 639 | $maxbits = $maxwords * 8; |
| 640 | 640 | |
| 641 | - if ($maxbits == $bits) {
|
|
| 641 | + if ($maxbits==$bits) {
|
|
| 642 | 642 | return 0; |
| 643 | 643 | } |
| 644 | 644 | |
| 645 | - if ($maxbits - $bits < 5) {
|
|
| 645 | + if ($maxbits - $bits<5) {
|
|
| 646 | 646 | return $bstream->appendNum($maxbits - $bits, 0); |
| 647 | 647 | } |
| 648 | 648 | |
@@ -652,21 +652,21 @@ discard block |
||
| 652 | 652 | $padding = new QRbitstream(); |
| 653 | 653 | $ret = $padding->appendNum($words * 8 - $bits + 4, 0); |
| 654 | 654 | |
| 655 | - if($ret < 0) |
|
| 655 | + if ($ret<0) |
|
| 656 | 656 | return $ret; |
| 657 | 657 | |
| 658 | 658 | $padlen = $maxwords - $words; |
| 659 | 659 | |
| 660 | - if($padlen > 0) {
|
|
| 660 | + if ($padlen>0) {
|
|
| 661 | 661 | |
| 662 | 662 | $padbuf = array(); |
| 663 | - for($i=0; $i<$padlen; $i++) {
|
|
| 664 | - $padbuf[$i] = ($i&1)?0x11:0xec; |
|
| 663 | + for ($i = 0; $i<$padlen; $i++) {
|
|
| 664 | + $padbuf[$i] = ($i & 1) ? 0x11 : 0xec; |
|
| 665 | 665 | } |
| 666 | 666 | |
| 667 | 667 | $ret = $padding->appendBytes($padlen, $padbuf); |
| 668 | 668 | |
| 669 | - if($ret < 0) |
|
| 669 | + if ($ret<0) |
|
| 670 | 670 | return $ret; |
| 671 | 671 | |
| 672 | 672 | } |
@@ -679,15 +679,15 @@ discard block |
||
| 679 | 679 | //---------------------------------------------------------------------- |
| 680 | 680 | public function mergeBitStream() |
| 681 | 681 | {
|
| 682 | - if($this->convertData() < 0) {
|
|
| 682 | + if ($this->convertData()<0) {
|
|
| 683 | 683 | return null; |
| 684 | 684 | } |
| 685 | 685 | |
| 686 | 686 | $bstream = new QRbitstream(); |
| 687 | 687 | |
| 688 | - foreach($this->items as $item) {
|
|
| 688 | + foreach ($this->items as $item) {
|
|
| 689 | 689 | $ret = $bstream->append($item->bstream); |
| 690 | - if($ret < 0) {
|
|
| 690 | + if ($ret<0) {
|
|
| 691 | 691 | return null; |
| 692 | 692 | } |
| 693 | 693 | } |
@@ -701,12 +701,12 @@ discard block |
||
| 701 | 701 | |
| 702 | 702 | $bstream = $this->mergeBitStream(); |
| 703 | 703 | |
| 704 | - if($bstream == null) {
|
|
| 704 | + if ($bstream==null) {
|
|
| 705 | 705 | return null; |
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | $ret = $this->appendPaddingBit($bstream); |
| 709 | - if($ret < 0) {
|
|
| 709 | + if ($ret<0) {
|
|
| 710 | 710 | return null; |
| 711 | 711 | } |
| 712 | 712 | |
@@ -717,7 +717,7 @@ discard block |
||
| 717 | 717 | public function getByteStream() |
| 718 | 718 | {
|
| 719 | 719 | $bstream = $this->getBitStream(); |
| 720 | - if($bstream == null) {
|
|
| 720 | + if ($bstream==null) {
|
|
| 721 | 721 | return null; |
| 722 | 722 | } |
| 723 | 723 | |
@@ -197,8 +197,9 @@ discard block |
||
| 197 | 197 | {
|
| 198 | 198 | $bits = 0; |
| 199 | 199 | |
| 200 | - if($version == 0) |
|
| 201 | - $version = 1; |
|
| 200 | + if($version == 0) {
|
|
| 201 | + $version = 1; |
|
| 202 | + } |
|
| 202 | 203 | |
| 203 | 204 | switch($this->mode) {
|
| 204 | 205 | case QR_MODE_NUM: $bits = QRinput::estimateBitsModeNum($this->size); break; |
@@ -257,8 +258,9 @@ discard block |
||
| 257 | 258 | break; |
| 258 | 259 | } |
| 259 | 260 | |
| 260 | - if($ret < 0) |
|
| 261 | - return -1; |
|
| 261 | + if($ret < 0) {
|
|
| 262 | + return -1; |
|
| 263 | + } |
|
| 262 | 264 | } |
| 263 | 265 | |
| 264 | 266 | return $this->bstream->size(); |
@@ -475,8 +477,9 @@ discard block |
||
| 475 | 477 | //---------------------------------------------------------------------- |
| 476 | 478 | public static function checkModeKanji($size, $data) |
| 477 | 479 | {
|
| 478 | - if($size & 1) |
|
| 479 | - return false; |
|
| 480 | + if($size & 1) {
|
|
| 481 | + return false; |
|
| 482 | + } |
|
| 480 | 483 | |
| 481 | 484 | for($i=0; $i<$size; $i+=2) {
|
| 482 | 485 | $val = (ord($data[$i]) << 8) | ord($data[$i+1]); |
@@ -496,8 +499,9 @@ discard block |
||
| 496 | 499 | |
| 497 | 500 | public static function check($mode, $size, $data) |
| 498 | 501 | {
|
| 499 | - if($size <= 0) |
|
| 500 | - return false; |
|
| 502 | + if($size <= 0) {
|
|
| 503 | + return false; |
|
| 504 | + } |
|
| 501 | 505 | |
| 502 | 506 | switch($mode) {
|
| 503 | 507 | case QR_MODE_NUM: return self::checkModeNum($size, $data); break; |
@@ -562,8 +566,9 @@ discard block |
||
| 562 | 566 | $chunks = (int)($payload / 11); |
| 563 | 567 | $remain = $payload - $chunks * 11; |
| 564 | 568 | $size = $chunks * 2; |
| 565 | - if($remain >= 6) |
|
| 566 | - $size++; |
|
| 569 | + if($remain >= 6) {
|
|
| 570 | + $size++; |
|
| 571 | + } |
|
| 567 | 572 | break; |
| 568 | 573 | case QR_MODE_8: |
| 569 | 574 | $size = (int)($payload / 8); |
@@ -580,8 +585,12 @@ discard block |
||
| 580 | 585 | } |
| 581 | 586 | |
| 582 | 587 | $maxsize = QRspec::maximumWords($mode, $version); |
| 583 | - if($size < 0) $size = 0; |
|
| 584 | - if($size > $maxsize) $size = $maxsize; |
|
| 588 | + if($size < 0) {
|
|
| 589 | + $size = 0; |
|
| 590 | + } |
|
| 591 | + if($size > $maxsize) {
|
|
| 592 | + $size = $maxsize; |
|
| 593 | + } |
|
| 585 | 594 | |
| 586 | 595 | return $size; |
| 587 | 596 | } |
@@ -594,8 +603,9 @@ discard block |
||
| 594 | 603 | foreach($this->items as $item) {
|
| 595 | 604 | $bits = $item->encodeBitStream($this->version); |
| 596 | 605 | |
| 597 | - if($bits < 0) |
|
| 598 | - return -1; |
|
| 606 | + if($bits < 0) {
|
|
| 607 | + return -1; |
|
| 608 | + } |
|
| 599 | 609 | |
| 600 | 610 | $total += $bits; |
| 601 | 611 | } |
@@ -614,8 +624,9 @@ discard block |
||
| 614 | 624 | for(;;) {
|
| 615 | 625 | $bits = $this->createBitStream(); |
| 616 | 626 | |
| 617 | - if($bits < 0) |
|
| 618 | - return -1; |
|
| 627 | + if($bits < 0) {
|
|
| 628 | + return -1; |
|
| 629 | + } |
|
| 619 | 630 | |
| 620 | 631 | $ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); |
| 621 | 632 | if($ver < 0) {
|
@@ -652,8 +663,9 @@ discard block |
||
| 652 | 663 | $padding = new QRbitstream(); |
| 653 | 664 | $ret = $padding->appendNum($words * 8 - $bits + 4, 0); |
| 654 | 665 | |
| 655 | - if($ret < 0) |
|
| 656 | - return $ret; |
|
| 666 | + if($ret < 0) {
|
|
| 667 | + return $ret; |
|
| 668 | + } |
|
| 657 | 669 | |
| 658 | 670 | $padlen = $maxwords - $words; |
| 659 | 671 | |
@@ -666,8 +678,9 @@ discard block |
||
| 666 | 678 | |
| 667 | 679 | $ret = $padding->appendBytes($padlen, $padbuf); |
| 668 | 680 | |
| 669 | - if($ret < 0) |
|
| 670 | - return $ret; |
|
| 681 | + if($ret < 0) {
|
|
| 682 | + return $ret; |
|
| 683 | + } |
|
| 671 | 684 | |
| 672 | 685 | } |
| 673 | 686 | |
@@ -27,19 +27,19 @@ discard block |
||
| 27 | 27 | class QRimage { |
| 28 | 28 | |
| 29 | 29 | //---------------------------------------------------------------------- |
| 30 | - public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE, $back_color, $fore_color) |
|
| 30 | + public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4, $saveandprint = FALSE, $back_color, $fore_color) |
|
| 31 | 31 | { |
| 32 | 32 | $image = self::image($frame, $pixelPerPoint, $outerFrame, $back_color, $fore_color); |
| 33 | 33 | |
| 34 | - if ($filename === false) { |
|
| 34 | + if ($filename===false) { |
|
| 35 | 35 | Header("Content-type: image/png"); |
| 36 | 36 | ImagePng($image); |
| 37 | 37 | } else { |
| 38 | - if($saveandprint===TRUE){ |
|
| 38 | + if ($saveandprint===TRUE) { |
|
| 39 | 39 | ImagePng($image, $filename); |
| 40 | 40 | header("Content-type: image/png"); |
| 41 | 41 | ImagePng($image); |
| 42 | - }else{ |
|
| 42 | + } else { |
|
| 43 | 43 | @ImagePng($image, $filename); |
| 44 | 44 | } |
| 45 | 45 | } |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | { |
| 53 | 53 | $image = self::image($frame, $pixelPerPoint, $outerFrame); |
| 54 | 54 | |
| 55 | - if ($filename === false) { |
|
| 55 | + if ($filename===false) { |
|
| 56 | 56 | Header("Content-type: image/jpeg"); |
| 57 | 57 | ImageJpeg($image, null, $q); |
| 58 | 58 | } else { |
@@ -68,10 +68,10 @@ discard block |
||
| 68 | 68 | $h = count($frame); |
| 69 | 69 | $w = strlen($frame[0]); |
| 70 | 70 | |
| 71 | - $imgW = $w + 2*$outerFrame; |
|
| 72 | - $imgH = $h + 2*$outerFrame; |
|
| 71 | + $imgW = $w + 2 * $outerFrame; |
|
| 72 | + $imgH = $h + 2 * $outerFrame; |
|
| 73 | 73 | |
| 74 | - $base_image =ImageCreate($imgW, $imgH); |
|
| 74 | + $base_image = ImageCreate($imgW, $imgH); |
|
| 75 | 75 | |
| 76 | 76 | // convert a hexadecimal color code into decimal eps format (green = 0 1 0, blue = 0 0 1, ...) |
| 77 | 77 | $r1 = round((($fore_color & 0xFF0000) >> 16), 5); |
@@ -85,20 +85,20 @@ discard block |
||
| 85 | 85 | |
| 86 | 86 | |
| 87 | 87 | |
| 88 | - $col[0] = ImageColorAllocate($base_image,$r2,$b2,$g2); |
|
| 89 | - $col[1] = ImageColorAllocate($base_image,$r1,$b1,$g1); |
|
| 88 | + $col[0] = ImageColorAllocate($base_image, $r2, $b2, $g2); |
|
| 89 | + $col[1] = ImageColorAllocate($base_image, $r1, $b1, $g1); |
|
| 90 | 90 | |
| 91 | 91 | imagefill($base_image, 0, 0, $col[0]); |
| 92 | 92 | |
| 93 | - for($y=0; $y<$h; $y++) { |
|
| 94 | - for($x=0; $x<$w; $x++) { |
|
| 95 | - if ($frame[$y][$x] == '1') { |
|
| 96 | - ImageSetPixel($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]); |
|
| 93 | + for ($y = 0; $y<$h; $y++) { |
|
| 94 | + for ($x = 0; $x<$w; $x++) { |
|
| 95 | + if ($frame[$y][$x]=='1') { |
|
| 96 | + ImageSetPixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]); |
|
| 97 | 97 | } |
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - $target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint); |
|
| 101 | + $target_image = ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint); |
|
| 102 | 102 | ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH); |
| 103 | 103 | ImageDestroy($base_image); |
| 104 | 104 | |
@@ -39,7 +39,7 @@ |
||
| 39 | 39 | ImagePng($image, $filename); |
| 40 | 40 | header("Content-type: image/png"); |
| 41 | 41 | ImagePng($image); |
| 42 | - }else{ |
|
| 42 | + } else{ |
|
| 43 | 43 | @ImagePng($image, $filename); |
| 44 | 44 | } |
| 45 | 45 | } |
@@ -34,4 +34,4 @@ |
||
| 34 | 34 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 35 | 35 | */ |
| 36 | 36 | |
| 37 | - |
|
| 38 | 37 | \ No newline at end of file |
| 38 | + |
|
| 39 | 39 | \ No newline at end of file |
@@ -60,7 +60,7 @@ |
||
| 60 | 60 | $outputCode .= "\n\n".$anotherCode."\n\n"; |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - $versionDataEx = explode("\n", file_get_contents($versionFile));
|
|
| 63 | + $versionDataEx = explode("\n", file_get_contents($versionFile));
|
|
| 64 | 64 | |
| 65 | 65 | $outputContents = file_get_contents($headerFile); |
| 66 | 66 | $outputContents .= "\n\n/*\n * Version: ".trim($versionDataEx[0])."\n * Build: ".trim($versionDataEx[1])."\n */\n\n"; |
@@ -52,11 +52,11 @@ |
||
| 52 | 52 | |
| 53 | 53 | $outputCode = ''; |
| 54 | 54 | |
| 55 | - foreach($fileList as $fileName) {
|
|
| 55 | + foreach ($fileList as $fileName) {
|
|
| 56 | 56 | $outputCode .= "\n\n".'//---- '.basename($fileName).' -----------------------------'."\n\n"; |
| 57 | 57 | $anotherCode = file_get_contents($fileName); |
| 58 | - $anotherCode = preg_replace ('/^<\?php/', '', $anotherCode);
|
|
| 59 | - $anotherCode = preg_replace ('/\?>\*$/', '', $anotherCode);
|
|
| 58 | + $anotherCode = preg_replace('/^<\?php/', '', $anotherCode);
|
|
| 59 | + $anotherCode = preg_replace('/\?>\*$/', '', $anotherCode);
|
|
| 60 | 60 | $outputCode .= "\n\n".$anotherCode."\n\n"; |
| 61 | 61 | } |
| 62 | 62 | |