@@ -72,43 +72,43 @@ discard block |
||
72 | 72 | function find_match($curlscore,$curcscore,$curgtlang,$langval,$charval, |
73 | 73 | $gtlang) |
74 | 74 | { |
75 | - if($curlscore < $langval) { |
|
75 | + if($curlscore < $langval) { |
|
76 | 76 | $curlscore=$langval; |
77 | 77 | $curcscore=$charval; |
78 | 78 | $curgtlang=$gtlang; |
79 | - } else if ($curlscore == $langval) { |
|
79 | + } else if ($curlscore == $langval) { |
|
80 | 80 | if($curcscore < $charval) { |
81 | - $curcscore=$charval; |
|
82 | - $curgtlang=$gtlang; |
|
81 | + $curcscore=$charval; |
|
82 | + $curgtlang=$gtlang; |
|
83 | 83 | } |
84 | - } |
|
85 | - return array($curlscore, $curcscore, $curgtlang); |
|
84 | + } |
|
85 | + return array($curlscore, $curcscore, $curgtlang); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | function al2gt($gettextlangs, $mime) { |
89 | - /* default to "everything is acceptable", as RFC2616 specifies */ |
|
90 | - $acceptLang=(($_SERVER["HTTP_ACCEPT_LANGUAGE"] == '') ? '*' : |
|
89 | + /* default to "everything is acceptable", as RFC2616 specifies */ |
|
90 | + $acceptLang=(($_SERVER["HTTP_ACCEPT_LANGUAGE"] == '') ? '*' : |
|
91 | 91 | $_SERVER["HTTP_ACCEPT_LANGUAGE"]); |
92 | - $acceptChar=(($_SERVER["HTTP_ACCEPT_CHARSET"] == '') ? '*' : |
|
92 | + $acceptChar=(($_SERVER["HTTP_ACCEPT_CHARSET"] == '') ? '*' : |
|
93 | 93 | $_SERVER["HTTP_ACCEPT_CHARSET"]); |
94 | - $alparts=@preg_split("/,/",$acceptLang); |
|
95 | - $acparts=@preg_split("/,/",$acceptChar); |
|
94 | + $alparts=@preg_split("/,/",$acceptLang); |
|
95 | + $acparts=@preg_split("/,/",$acceptChar); |
|
96 | 96 | |
97 | - /* Parse the contents of the Accept-Language header.*/ |
|
98 | - foreach($alparts as $part) { |
|
97 | + /* Parse the contents of the Accept-Language header.*/ |
|
98 | + foreach($alparts as $part) { |
|
99 | 99 | $part=trim($part); |
100 | 100 | if(preg_match("/;/", $part)) { |
101 | - $lang=@preg_split("/;/",$part); |
|
102 | - $score=@preg_split("/=/",$lang[1]); |
|
103 | - $alscores[$lang[0]]=$score[1]; |
|
101 | + $lang=@preg_split("/;/",$part); |
|
102 | + $score=@preg_split("/=/",$lang[1]); |
|
103 | + $alscores[$lang[0]]=$score[1]; |
|
104 | 104 | } else { |
105 | - $alscores[$part]=1; |
|
105 | + $alscores[$part]=1; |
|
106 | + } |
|
106 | 107 | } |
107 | - } |
|
108 | 108 | |
109 | - /* Do the same for the Accept-Charset header. */ |
|
109 | + /* Do the same for the Accept-Charset header. */ |
|
110 | 110 | |
111 | - /* RFC2616: ``If no "*" is present in an Accept-Charset field, then |
|
111 | + /* RFC2616: ``If no "*" is present in an Accept-Charset field, then |
|
112 | 112 | * all character sets not explicitly mentioned get a quality value of |
113 | 113 | * 0, except for ISO-8859-1, which gets a quality value of 1 if not |
114 | 114 | * explicitly mentioned.'' |
@@ -116,31 +116,31 @@ discard block |
||
116 | 116 | * Making it 2 for the time being, so that we |
117 | 117 | * can distinguish between "not specified" and "specified as 1" later |
118 | 118 | * on. */ |
119 | - $acscores["ISO-8859-1"]=2; |
|
119 | + $acscores["ISO-8859-1"]=2; |
|
120 | 120 | |
121 | - foreach($acparts as $part) { |
|
121 | + foreach($acparts as $part) { |
|
122 | 122 | $part=trim($part); |
123 | 123 | if(preg_match("/;/", $part)) { |
124 | - $cs=@preg_split("/;/",$part); |
|
125 | - $score=@preg_split("/=/",$cs[1]); |
|
126 | - $acscores[strtoupper($cs[0])]=$score[1]; |
|
124 | + $cs=@preg_split("/;/",$part); |
|
125 | + $score=@preg_split("/=/",$cs[1]); |
|
126 | + $acscores[strtoupper($cs[0])]=$score[1]; |
|
127 | 127 | } else { |
128 | - $acscores[strtoupper($part)]=1; |
|
128 | + $acscores[strtoupper($part)]=1; |
|
129 | + } |
|
129 | 130 | } |
130 | - } |
|
131 | - if($acscores["ISO-8859-1"]==2) { |
|
131 | + if($acscores["ISO-8859-1"]==2) { |
|
132 | 132 | $acscores["ISO-8859-1"]=(isset($acscores["*"])?$acscores["*"]:1); |
133 | - } |
|
133 | + } |
|
134 | 134 | |
135 | - /* |
|
135 | + /* |
|
136 | 136 | * Loop through the available languages/encodings, and pick the one |
137 | 137 | * with the highest score, excluding the ones with a charset the user |
138 | 138 | * did not include. |
139 | 139 | */ |
140 | - $curlscore=0; |
|
141 | - $curcscore=0; |
|
142 | - $curgtlang=null; |
|
143 | - foreach($gettextlangs as $gtlang) { |
|
140 | + $curlscore=0; |
|
141 | + $curcscore=0; |
|
142 | + $curgtlang=null; |
|
143 | + foreach($gettextlangs as $gtlang) { |
|
144 | 144 | |
145 | 145 | $tmp1=preg_replace("/\_/","-",$gtlang); |
146 | 146 | $tmp2=@preg_split("/\./",$tmp1); |
@@ -149,38 +149,38 @@ discard block |
||
149 | 149 | $noct=@preg_split("/-/",$allang); |
150 | 150 | |
151 | 151 | $testvals=array( |
152 | - array(@$alscores[$allang], @$acscores[$gtcs]), |
|
153 | - array(@$alscores[$noct[0]], @$acscores[$gtcs]), |
|
154 | - array(@$alscores[$allang], @$acscores["*"]), |
|
155 | - array(@$alscores[$noct[0]], @$acscores["*"]), |
|
156 | - array(@$alscores["*"], @$acscores[$gtcs]), |
|
157 | - array(@$alscores["*"], @$acscores["*"])); |
|
152 | + array(@$alscores[$allang], @$acscores[$gtcs]), |
|
153 | + array(@$alscores[$noct[0]], @$acscores[$gtcs]), |
|
154 | + array(@$alscores[$allang], @$acscores["*"]), |
|
155 | + array(@$alscores[$noct[0]], @$acscores["*"]), |
|
156 | + array(@$alscores["*"], @$acscores[$gtcs]), |
|
157 | + array(@$alscores["*"], @$acscores["*"])); |
|
158 | 158 | |
159 | 159 | $found=false; |
160 | 160 | foreach($testvals as $tval) { |
161 | - if(!$found && isset($tval[0]) && isset($tval[1])) { |
|
161 | + if(!$found && isset($tval[0]) && isset($tval[1])) { |
|
162 | 162 | $arr=find_match($curlscore, $curcscore, $curgtlang, $tval[0], |
163 | - $tval[1], $gtlang); |
|
163 | + $tval[1], $gtlang); |
|
164 | 164 | $curlscore=$arr[0]; |
165 | 165 | $curcscore=$arr[1]; |
166 | 166 | $curgtlang=$arr[2]; |
167 | 167 | $found=true; |
168 | - } |
|
168 | + } |
|
169 | + } |
|
169 | 170 | } |
170 | - } |
|
171 | 171 | |
172 | - /* We must re-parse the gettext-string now, since we may have found it |
|
172 | + /* We must re-parse the gettext-string now, since we may have found it |
|
173 | 173 | * through a "*" qualifier.*/ |
174 | 174 | |
175 | - $gtparts=@preg_split("/\./",$curgtlang); |
|
176 | - $tmp=strtolower($gtparts[0]); |
|
177 | - $lang=preg_replace("/\_/", "-", $tmp); |
|
178 | - $charset=$gtparts[1]; |
|
175 | + $gtparts=@preg_split("/\./",$curgtlang); |
|
176 | + $tmp=strtolower($gtparts[0]); |
|
177 | + $lang=preg_replace("/\_/", "-", $tmp); |
|
178 | + $charset=$gtparts[1]; |
|
179 | 179 | |
180 | - header("Content-Language: $lang"); |
|
181 | - header("Content-Type: $mime; charset=$charset"); |
|
180 | + header("Content-Language: $lang"); |
|
181 | + header("Content-Type: $mime; charset=$charset"); |
|
182 | 182 | |
183 | - return $curgtlang; |
|
183 | + return $curgtlang; |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | ?> |
@@ -69,17 +69,17 @@ discard block |
||
69 | 69 | |
70 | 70 | /* not really important, this one; perhaps I could've put it inline with |
71 | 71 | * the rest. */ |
72 | -function find_match($curlscore,$curcscore,$curgtlang,$langval,$charval, |
|
72 | +function find_match($curlscore, $curcscore, $curgtlang, $langval, $charval, |
|
73 | 73 | $gtlang) |
74 | 74 | { |
75 | - if($curlscore < $langval) { |
|
76 | - $curlscore=$langval; |
|
77 | - $curcscore=$charval; |
|
78 | - $curgtlang=$gtlang; |
|
75 | + if ($curlscore < $langval) { |
|
76 | + $curlscore = $langval; |
|
77 | + $curcscore = $charval; |
|
78 | + $curgtlang = $gtlang; |
|
79 | 79 | } else if ($curlscore == $langval) { |
80 | - if($curcscore < $charval) { |
|
81 | - $curcscore=$charval; |
|
82 | - $curgtlang=$gtlang; |
|
80 | + if ($curcscore < $charval) { |
|
81 | + $curcscore = $charval; |
|
82 | + $curgtlang = $gtlang; |
|
83 | 83 | } |
84 | 84 | } |
85 | 85 | return array($curlscore, $curcscore, $curgtlang); |
@@ -87,22 +87,20 @@ discard block |
||
87 | 87 | |
88 | 88 | function al2gt($gettextlangs, $mime) { |
89 | 89 | /* default to "everything is acceptable", as RFC2616 specifies */ |
90 | - $acceptLang=(($_SERVER["HTTP_ACCEPT_LANGUAGE"] == '') ? '*' : |
|
91 | - $_SERVER["HTTP_ACCEPT_LANGUAGE"]); |
|
92 | - $acceptChar=(($_SERVER["HTTP_ACCEPT_CHARSET"] == '') ? '*' : |
|
93 | - $_SERVER["HTTP_ACCEPT_CHARSET"]); |
|
94 | - $alparts=@preg_split("/,/",$acceptLang); |
|
95 | - $acparts=@preg_split("/,/",$acceptChar); |
|
90 | + $acceptLang = (($_SERVER["HTTP_ACCEPT_LANGUAGE"] == '') ? '*' : $_SERVER["HTTP_ACCEPT_LANGUAGE"]); |
|
91 | + $acceptChar = (($_SERVER["HTTP_ACCEPT_CHARSET"] == '') ? '*' : $_SERVER["HTTP_ACCEPT_CHARSET"]); |
|
92 | + $alparts = @preg_split("/,/", $acceptLang); |
|
93 | + $acparts = @preg_split("/,/", $acceptChar); |
|
96 | 94 | |
97 | 95 | /* Parse the contents of the Accept-Language header.*/ |
98 | - foreach($alparts as $part) { |
|
99 | - $part=trim($part); |
|
100 | - if(preg_match("/;/", $part)) { |
|
101 | - $lang=@preg_split("/;/",$part); |
|
102 | - $score=@preg_split("/=/",$lang[1]); |
|
103 | - $alscores[$lang[0]]=$score[1]; |
|
96 | + foreach ($alparts as $part) { |
|
97 | + $part = trim($part); |
|
98 | + if (preg_match("/;/", $part)) { |
|
99 | + $lang = @preg_split("/;/", $part); |
|
100 | + $score = @preg_split("/=/", $lang[1]); |
|
101 | + $alscores[$lang[0]] = $score[1]; |
|
104 | 102 | } else { |
105 | - $alscores[$part]=1; |
|
103 | + $alscores[$part] = 1; |
|
106 | 104 | } |
107 | 105 | } |
108 | 106 | |
@@ -116,20 +114,20 @@ discard block |
||
116 | 114 | * Making it 2 for the time being, so that we |
117 | 115 | * can distinguish between "not specified" and "specified as 1" later |
118 | 116 | * on. */ |
119 | - $acscores["ISO-8859-1"]=2; |
|
117 | + $acscores["ISO-8859-1"] = 2; |
|
120 | 118 | |
121 | - foreach($acparts as $part) { |
|
122 | - $part=trim($part); |
|
123 | - if(preg_match("/;/", $part)) { |
|
124 | - $cs=@preg_split("/;/",$part); |
|
125 | - $score=@preg_split("/=/",$cs[1]); |
|
126 | - $acscores[strtoupper($cs[0])]=$score[1]; |
|
119 | + foreach ($acparts as $part) { |
|
120 | + $part = trim($part); |
|
121 | + if (preg_match("/;/", $part)) { |
|
122 | + $cs = @preg_split("/;/", $part); |
|
123 | + $score = @preg_split("/=/", $cs[1]); |
|
124 | + $acscores[strtoupper($cs[0])] = $score[1]; |
|
127 | 125 | } else { |
128 | - $acscores[strtoupper($part)]=1; |
|
126 | + $acscores[strtoupper($part)] = 1; |
|
129 | 127 | } |
130 | 128 | } |
131 | - if($acscores["ISO-8859-1"]==2) { |
|
132 | - $acscores["ISO-8859-1"]=(isset($acscores["*"])?$acscores["*"]:1); |
|
129 | + if ($acscores["ISO-8859-1"] == 2) { |
|
130 | + $acscores["ISO-8859-1"] = (isset($acscores["*"]) ? $acscores["*"] : 1); |
|
133 | 131 | } |
134 | 132 | |
135 | 133 | /* |
@@ -137,18 +135,18 @@ discard block |
||
137 | 135 | * with the highest score, excluding the ones with a charset the user |
138 | 136 | * did not include. |
139 | 137 | */ |
140 | - $curlscore=0; |
|
141 | - $curcscore=0; |
|
142 | - $curgtlang=null; |
|
143 | - foreach($gettextlangs as $gtlang) { |
|
138 | + $curlscore = 0; |
|
139 | + $curcscore = 0; |
|
140 | + $curgtlang = null; |
|
141 | + foreach ($gettextlangs as $gtlang) { |
|
144 | 142 | |
145 | - $tmp1=preg_replace("/\_/","-",$gtlang); |
|
146 | - $tmp2=@preg_split("/\./",$tmp1); |
|
147 | - $allang=strtolower($tmp2[0]); |
|
148 | - $gtcs=strtoupper($tmp2[1]); |
|
149 | - $noct=@preg_split("/-/",$allang); |
|
143 | + $tmp1 = preg_replace("/\_/", "-", $gtlang); |
|
144 | + $tmp2 = @preg_split("/\./", $tmp1); |
|
145 | + $allang = strtolower($tmp2[0]); |
|
146 | + $gtcs = strtoupper($tmp2[1]); |
|
147 | + $noct = @preg_split("/-/", $allang); |
|
150 | 148 | |
151 | - $testvals=array( |
|
149 | + $testvals = array( |
|
152 | 150 | array(@$alscores[$allang], @$acscores[$gtcs]), |
153 | 151 | array(@$alscores[$noct[0]], @$acscores[$gtcs]), |
154 | 152 | array(@$alscores[$allang], @$acscores["*"]), |
@@ -156,15 +154,15 @@ discard block |
||
156 | 154 | array(@$alscores["*"], @$acscores[$gtcs]), |
157 | 155 | array(@$alscores["*"], @$acscores["*"])); |
158 | 156 | |
159 | - $found=false; |
|
160 | - foreach($testvals as $tval) { |
|
161 | - if(!$found && isset($tval[0]) && isset($tval[1])) { |
|
162 | - $arr=find_match($curlscore, $curcscore, $curgtlang, $tval[0], |
|
157 | + $found = false; |
|
158 | + foreach ($testvals as $tval) { |
|
159 | + if (!$found && isset($tval[0]) && isset($tval[1])) { |
|
160 | + $arr = find_match($curlscore, $curcscore, $curgtlang, $tval[0], |
|
163 | 161 | $tval[1], $gtlang); |
164 | - $curlscore=$arr[0]; |
|
165 | - $curcscore=$arr[1]; |
|
166 | - $curgtlang=$arr[2]; |
|
167 | - $found=true; |
|
162 | + $curlscore = $arr[0]; |
|
163 | + $curcscore = $arr[1]; |
|
164 | + $curgtlang = $arr[2]; |
|
165 | + $found = true; |
|
168 | 166 | } |
169 | 167 | } |
170 | 168 | } |
@@ -172,10 +170,10 @@ discard block |
||
172 | 170 | /* We must re-parse the gettext-string now, since we may have found it |
173 | 171 | * through a "*" qualifier.*/ |
174 | 172 | |
175 | - $gtparts=@preg_split("/\./",$curgtlang); |
|
176 | - $tmp=strtolower($gtparts[0]); |
|
177 | - $lang=preg_replace("/\_/", "-", $tmp); |
|
178 | - $charset=$gtparts[1]; |
|
173 | + $gtparts = @preg_split("/\./", $curgtlang); |
|
174 | + $tmp = strtolower($gtparts[0]); |
|
175 | + $lang = preg_replace("/\_/", "-", $tmp); |
|
176 | + $charset = $gtparts[1]; |
|
179 | 177 | |
180 | 178 | header("Content-Language: $lang"); |
181 | 179 | header("Content-Type: $mime; charset=$charset"); |
@@ -58,10 +58,10 @@ discard block |
||
58 | 58 | //---------------------------------------------------------------------- |
59 | 59 | public function __construct(QRinput $input) |
60 | 60 | { |
61 | - $spec = array(0,0,0,0,0); |
|
61 | + $spec = array(0, 0, 0, 0, 0); |
|
62 | 62 | |
63 | 63 | $this->datacode = $input->getByteStream(); |
64 | - if(is_null($this->datacode)) { |
|
64 | + if (is_null($this->datacode)) { |
|
65 | 65 | throw new Exception('null imput string'); |
66 | 66 | } |
67 | 67 | |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | $this->blocks = QRspec::rsBlockNum($spec); |
76 | 76 | |
77 | 77 | $ret = $this->init($spec); |
78 | - if($ret < 0) { |
|
78 | + if ($ret < 0) { |
|
79 | 79 | throw new Exception('block alloc error'); |
80 | 80 | return null; |
81 | 81 | } |
@@ -94,29 +94,29 @@ discard block |
||
94 | 94 | $blockNo = 0; |
95 | 95 | $dataPos = 0; |
96 | 96 | $eccPos = 0; |
97 | - for($i=0; $i<QRspec::rsBlockNum1($spec); $i++) { |
|
98 | - $ecc = array_slice($this->ecccode,$eccPos); |
|
99 | - $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs); |
|
100 | - $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc); |
|
97 | + for ($i = 0; $i < QRspec::rsBlockNum1($spec); $i++) { |
|
98 | + $ecc = array_slice($this->ecccode, $eccPos); |
|
99 | + $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs); |
|
100 | + $this->ecccode = array_merge(array_slice($this->ecccode, 0, $eccPos), $ecc); |
|
101 | 101 | |
102 | 102 | $dataPos += $dl; |
103 | 103 | $eccPos += $el; |
104 | 104 | $blockNo++; |
105 | 105 | } |
106 | 106 | |
107 | - if(QRspec::rsBlockNum2($spec) == 0) |
|
107 | + if (QRspec::rsBlockNum2($spec) == 0) |
|
108 | 108 | return 0; |
109 | 109 | |
110 | 110 | $dl = QRspec::rsDataCodes2($spec); |
111 | 111 | $el = QRspec::rsEccCodes2($spec); |
112 | 112 | $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el); |
113 | 113 | |
114 | - if($rs == null) return -1; |
|
114 | + if ($rs == null) return -1; |
|
115 | 115 | |
116 | - for($i=0; $i<QRspec::rsBlockNum2($spec); $i++) { |
|
117 | - $ecc = array_slice($this->ecccode,$eccPos); |
|
116 | + for ($i = 0; $i < QRspec::rsBlockNum2($spec); $i++) { |
|
117 | + $ecc = array_slice($this->ecccode, $eccPos); |
|
118 | 118 | $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs); |
119 | - $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc); |
|
119 | + $this->ecccode = array_merge(array_slice($this->ecccode, 0, $eccPos), $ecc); |
|
120 | 120 | |
121 | 121 | $dataPos += $dl; |
122 | 122 | $eccPos += $el; |
@@ -131,14 +131,14 @@ discard block |
||
131 | 131 | { |
132 | 132 | $ret = 0; |
133 | 133 | |
134 | - if($this->count < $this->dataLength) { |
|
134 | + if ($this->count < $this->dataLength) { |
|
135 | 135 | $row = $this->count % $this->blocks; |
136 | 136 | $col = $this->count / $this->blocks; |
137 | - if($col >= $this->rsblocks[0]->dataLength) { |
|
137 | + if ($col >= $this->rsblocks[0]->dataLength) { |
|
138 | 138 | $row += $this->b1; |
139 | 139 | } |
140 | 140 | $ret = $this->rsblocks[$row]->data[$col]; |
141 | - } else if($this->count < $this->dataLength + $this->eccLength) { |
|
141 | + } else if ($this->count < $this->dataLength + $this->eccLength) { |
|
142 | 142 | $row = ($this->count - $this->dataLength) % $this->blocks; |
143 | 143 | $col = ($this->count - $this->dataLength) / $this->blocks; |
144 | 144 | $ret = $this->rsblocks[$row]->ecc[$col]; |
@@ -162,10 +162,10 @@ discard block |
||
162 | 162 | //---------------------------------------------------------------------- |
163 | 163 | public function encodeMask(QRinput $input, $mask) |
164 | 164 | { |
165 | - if($input->getVersion() < 0 || $input->getVersion() > QRSPEC_VERSION_MAX) { |
|
165 | + if ($input->getVersion() < 0 || $input->getVersion() > QRSPEC_VERSION_MAX) { |
|
166 | 166 | throw new Exception('wrong version'); |
167 | 167 | } |
168 | - if($input->getErrorCorrectionLevel() > QR_ECLEVEL_H) { |
|
168 | + if ($input->getErrorCorrectionLevel() > QR_ECLEVEL_H) { |
|
169 | 169 | throw new Exception('wrong level'); |
170 | 170 | } |
171 | 171 | |
@@ -178,15 +178,15 @@ discard block |
||
178 | 178 | $frame = QRspec::newFrame($version); |
179 | 179 | |
180 | 180 | $filler = new FrameFiller($width, $frame); |
181 | - if(is_null($filler)) { |
|
181 | + if (is_null($filler)) { |
|
182 | 182 | return null; |
183 | 183 | } |
184 | 184 | |
185 | 185 | // inteleaved data and ecc codes |
186 | - for($i=0; $i<$raw->dataLength + $raw->eccLength; $i++) { |
|
186 | + for ($i = 0; $i < $raw->dataLength + $raw->eccLength; $i++) { |
|
187 | 187 | $code = $raw->getCode(); |
188 | 188 | $bit = 0x80; |
189 | - for($j=0; $j<8; $j++) { |
|
189 | + for ($j = 0; $j < 8; $j++) { |
|
190 | 190 | $addr = $filler->next(); |
191 | 191 | $filler->setFrameAt($addr, 0x02 | (($bit & $code) != 0)); |
192 | 192 | $bit = $bit >> 1; |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | |
200 | 200 | // remainder bits |
201 | 201 | $j = QRspec::getRemainder($version); |
202 | - for($i=0; $i<$j; $i++) { |
|
202 | + for ($i = 0; $i < $j; $i++) { |
|
203 | 203 | $addr = $filler->next(); |
204 | 204 | $filler->setFrameAt($addr, 0x02); |
205 | 205 | } |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | |
211 | 211 | // masking |
212 | 212 | $maskObj = new QRmask(); |
213 | - if($mask < 0) { |
|
213 | + if ($mask < 0) { |
|
214 | 214 | |
215 | 215 | if (QR_FIND_BEST_MASK) { |
216 | 216 | $masked = $maskObj->mask($width, $frame, $input->getErrorCorrectionLevel()); |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | $masked = $maskObj->makeMask($width, $frame, $mask, $input->getErrorCorrectionLevel()); |
222 | 222 | } |
223 | 223 | |
224 | - if($masked == null) { |
|
224 | + if ($masked == null) { |
|
225 | 225 | return null; |
226 | 226 | } |
227 | 227 | |
@@ -243,16 +243,16 @@ discard block |
||
243 | 243 | //---------------------------------------------------------------------- |
244 | 244 | public function encodeString8bit($string, $version, $level) |
245 | 245 | { |
246 | - if(string == null) { |
|
246 | + if (string == null) { |
|
247 | 247 | throw new Exception('empty string!'); |
248 | 248 | return null; |
249 | 249 | } |
250 | 250 | |
251 | 251 | $input = new QRinput($version, $level); |
252 | - if($input == null) return null; |
|
252 | + if ($input == null) return null; |
|
253 | 253 | |
254 | 254 | $ret = $input->append($input, QR_MODE_8, strlen($string), str_split($string)); |
255 | - if($ret < 0) { |
|
255 | + if ($ret < 0) { |
|
256 | 256 | unset($input); |
257 | 257 | return null; |
258 | 258 | } |
@@ -263,16 +263,16 @@ discard block |
||
263 | 263 | public function encodeString($string, $version, $level, $hint, $casesensitive) |
264 | 264 | { |
265 | 265 | |
266 | - if($hint != QR_MODE_8 && $hint != QR_MODE_KANJI) { |
|
266 | + if ($hint != QR_MODE_8 && $hint != QR_MODE_KANJI) { |
|
267 | 267 | throw new Exception('bad hint'); |
268 | 268 | return null; |
269 | 269 | } |
270 | 270 | |
271 | 271 | $input = new QRinput($version, $level); |
272 | - if($input == null) return null; |
|
272 | + if ($input == null) return null; |
|
273 | 273 | |
274 | 274 | $ret = QRsplit::splitStringToQRinput($string, $input, $hint, $casesensitive); |
275 | - if($ret < 0) { |
|
275 | + if ($ret < 0) { |
|
276 | 276 | return null; |
277 | 277 | } |
278 | 278 | |
@@ -280,10 +280,10 @@ discard block |
||
280 | 280 | } |
281 | 281 | |
282 | 282 | //---------------------------------------------------------------------- |
283 | - public static function png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint=false) |
|
283 | + public static function png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint = false) |
|
284 | 284 | { |
285 | 285 | $enc = QRencode::factory($level, $size, $margin); |
286 | - return $enc->encodePNG($text, $outfile, $saveandprint=false); |
|
286 | + return $enc->encodePNG($text, $outfile, $saveandprint = false); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | //---------------------------------------------------------------------- |
@@ -340,7 +340,7 @@ discard block |
||
340 | 340 | { |
341 | 341 | do { |
342 | 342 | |
343 | - if($this->bit == -1) { |
|
343 | + if ($this->bit == -1) { |
|
344 | 344 | $this->bit = 0; |
345 | 345 | return array('x'=>$this->x, 'y'=>$this->y); |
346 | 346 | } |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | $y = $this->y; |
350 | 350 | $w = $this->width; |
351 | 351 | |
352 | - if($this->bit == 0) { |
|
352 | + if ($this->bit == 0) { |
|
353 | 353 | $x--; |
354 | 354 | $this->bit++; |
355 | 355 | } else { |
@@ -358,33 +358,33 @@ discard block |
||
358 | 358 | $this->bit--; |
359 | 359 | } |
360 | 360 | |
361 | - if($this->dir < 0) { |
|
362 | - if($y < 0) { |
|
361 | + if ($this->dir < 0) { |
|
362 | + if ($y < 0) { |
|
363 | 363 | $y = 0; |
364 | 364 | $x -= 2; |
365 | 365 | $this->dir = 1; |
366 | - if($x == 6) { |
|
366 | + if ($x == 6) { |
|
367 | 367 | $x--; |
368 | 368 | $y = 9; |
369 | 369 | } |
370 | 370 | } |
371 | 371 | } else { |
372 | - if($y == $w) { |
|
372 | + if ($y == $w) { |
|
373 | 373 | $y = $w - 1; |
374 | 374 | $x -= 2; |
375 | 375 | $this->dir = -1; |
376 | - if($x == 6) { |
|
376 | + if ($x == 6) { |
|
377 | 377 | $x--; |
378 | 378 | $y -= 8; |
379 | 379 | } |
380 | 380 | } |
381 | 381 | } |
382 | - if($x < 0 || $y < 0) return null; |
|
382 | + if ($x < 0 || $y < 0) return null; |
|
383 | 383 | |
384 | 384 | $this->x = $x; |
385 | 385 | $this->y = $y; |
386 | 386 | |
387 | - } while(ord($this->frame[$y][$x]) & 0x80); |
|
387 | + } while (ord($this->frame[$y][$x]) & 0x80); |
|
388 | 388 | |
389 | 389 | return array('x'=>$x, 'y'=>$y); |
390 | 390 | } |
@@ -447,7 +447,7 @@ discard block |
||
447 | 447 | { |
448 | 448 | $code = new QRcode(); |
449 | 449 | |
450 | - if($this->eightbit) { |
|
450 | + if ($this->eightbit) { |
|
451 | 451 | $code->encodeString8bit($intext, $this->version, $this->level); |
452 | 452 | } else { |
453 | 453 | $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive); |
@@ -461,7 +461,7 @@ discard block |
||
461 | 461 | { |
462 | 462 | $code = new QRcode(); |
463 | 463 | |
464 | - if($this->eightbit) { |
|
464 | + if ($this->eightbit) { |
|
465 | 465 | $code->encodeString8bit($intext, $this->version, $this->level); |
466 | 466 | } else { |
467 | 467 | $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive); |
@@ -469,7 +469,7 @@ discard block |
||
469 | 469 | |
470 | 470 | QRtools::markTime('after_encode'); |
471 | 471 | |
472 | - if ($outfile!== false) { |
|
472 | + if ($outfile !== false) { |
|
473 | 473 | file_put_contents($outfile, join("\n", QRtools::binarize($code->data))); |
474 | 474 | } else { |
475 | 475 | return QRtools::binarize($code->data); |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | } |
478 | 478 | |
479 | 479 | //---------------------------------------------------------------------- |
480 | - public function encodePNG($intext, $outfile = false,$saveandprint=false) |
|
480 | + public function encodePNG($intext, $outfile = false, $saveandprint = false) |
|
481 | 481 | { |
482 | 482 | try { |
483 | 483 | |
@@ -489,9 +489,9 @@ discard block |
||
489 | 489 | if ($err != '') |
490 | 490 | QRtools::log($outfile, $err); |
491 | 491 | |
492 | - $maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab)+2*$this->margin)); |
|
492 | + $maxSize = (int) (QR_PNG_MAXIMUM_SIZE / (count($tab) + 2 * $this->margin)); |
|
493 | 493 | |
494 | - QRimage::png($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin,$saveandprint); |
|
494 | + QRimage::png($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin, $saveandprint); |
|
495 | 495 | |
496 | 496 | } catch (Exception $e) { |
497 | 497 |
@@ -104,14 +104,17 @@ discard block |
||
104 | 104 | $blockNo++; |
105 | 105 | } |
106 | 106 | |
107 | - if(QRspec::rsBlockNum2($spec) == 0) |
|
108 | - return 0; |
|
107 | + if(QRspec::rsBlockNum2($spec) == 0) { |
|
108 | + return 0; |
|
109 | + } |
|
109 | 110 | |
110 | 111 | $dl = QRspec::rsDataCodes2($spec); |
111 | 112 | $el = QRspec::rsEccCodes2($spec); |
112 | 113 | $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el); |
113 | 114 | |
114 | - if($rs == null) return -1; |
|
115 | + if($rs == null) { |
|
116 | + return -1; |
|
117 | + } |
|
115 | 118 | |
116 | 119 | for($i=0; $i<QRspec::rsBlockNum2($spec); $i++) { |
117 | 120 | $ecc = array_slice($this->ecccode,$eccPos); |
@@ -249,7 +252,9 @@ discard block |
||
249 | 252 | } |
250 | 253 | |
251 | 254 | $input = new QRinput($version, $level); |
252 | - if($input == null) return null; |
|
255 | + if($input == null) { |
|
256 | + return null; |
|
257 | + } |
|
253 | 258 | |
254 | 259 | $ret = $input->append($input, QR_MODE_8, strlen($string), str_split($string)); |
255 | 260 | if($ret < 0) { |
@@ -269,7 +274,9 @@ discard block |
||
269 | 274 | } |
270 | 275 | |
271 | 276 | $input = new QRinput($version, $level); |
272 | - if($input == null) return null; |
|
277 | + if($input == null) { |
|
278 | + return null; |
|
279 | + } |
|
273 | 280 | |
274 | 281 | $ret = QRsplit::splitStringToQRinput($string, $input, $hint, $casesensitive); |
275 | 282 | if($ret < 0) { |
@@ -379,7 +386,9 @@ discard block |
||
379 | 386 | } |
380 | 387 | } |
381 | 388 | } |
382 | - if($x < 0 || $y < 0) return null; |
|
389 | + if($x < 0 || $y < 0) { |
|
390 | + return null; |
|
391 | + } |
|
383 | 392 | |
384 | 393 | $this->x = $x; |
385 | 394 | $this->y = $y; |
@@ -486,8 +495,9 @@ discard block |
||
486 | 495 | $err = ob_get_contents(); |
487 | 496 | ob_end_clean(); |
488 | 497 | |
489 | - if ($err != '') |
|
490 | - QRtools::log($outfile, $err); |
|
498 | + if ($err != '') { |
|
499 | + QRtools::log($outfile, $err); |
|
500 | + } |
|
491 | 501 | |
492 | 502 | $maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab)+2*$this->margin)); |
493 | 503 |
@@ -30,16 +30,16 @@ discard block |
||
30 | 30 | |
31 | 31 | class QRrsItem { |
32 | 32 | |
33 | - public $mm; // Bits per symbol |
|
34 | - public $nn; // Symbols per block (= (1<<mm)-1) |
|
35 | - public $alpha_to = array(); // log lookup table |
|
36 | - public $index_of = array(); // Antilog lookup table |
|
37 | - public $genpoly = array(); // Generator polynomial |
|
38 | - public $nroots; // Number of generator roots = number of parity symbols |
|
39 | - public $fcr; // First consecutive root, index form |
|
40 | - public $prim; // Primitive element, index form |
|
41 | - public $iprim; // prim-th root of 1, index form |
|
42 | - public $pad; // Padding bytes in shortened block |
|
33 | + public $mm; // Bits per symbol |
|
34 | + public $nn; // Symbols per block (= (1<<mm)-1) |
|
35 | + public $alpha_to = array(); // log lookup table |
|
36 | + public $index_of = array(); // Antilog lookup table |
|
37 | + public $genpoly = array(); // Generator polynomial |
|
38 | + public $nroots; // Number of generator roots = number of parity symbols |
|
39 | + public $fcr; // First consecutive root, index form |
|
40 | + public $prim; // Primitive element, index form |
|
41 | + public $iprim; // prim-th root of 1, index form |
|
42 | + public $pad; // Padding bytes in shortened block |
|
43 | 43 | public $gfpoly; |
44 | 44 | |
45 | 45 | //---------------------------------------------------------------------- |
@@ -63,47 +63,47 @@ discard block |
||
63 | 63 | $rs = null; |
64 | 64 | |
65 | 65 | // Check parameter ranges |
66 | - if($symsize < 0 || $symsize > 8) return $rs; |
|
67 | - if($fcr < 0 || $fcr >= (1<<$symsize)) return $rs; |
|
68 | - if($prim <= 0 || $prim >= (1<<$symsize)) return $rs; |
|
69 | - if($nroots < 0 || $nroots >= (1<<$symsize)) return $rs; // Can't have more roots than symbol values! |
|
70 | - if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) return $rs; // Too much padding |
|
66 | + if ($symsize < 0 || $symsize > 8) return $rs; |
|
67 | + if ($fcr < 0 || $fcr >= (1 << $symsize)) return $rs; |
|
68 | + if ($prim <= 0 || $prim >= (1 << $symsize)) return $rs; |
|
69 | + if ($nroots < 0 || $nroots >= (1 << $symsize)) return $rs; // Can't have more roots than symbol values! |
|
70 | + if ($pad < 0 || $pad >= ((1 << $symsize) - 1 - $nroots)) return $rs; // Too much padding |
|
71 | 71 | |
72 | 72 | $rs = new QRrsItem(); |
73 | 73 | $rs->mm = $symsize; |
74 | - $rs->nn = (1<<$symsize)-1; |
|
74 | + $rs->nn = (1 << $symsize) - 1; |
|
75 | 75 | $rs->pad = $pad; |
76 | 76 | |
77 | - $rs->alpha_to = array_fill(0, $rs->nn+1, 0); |
|
78 | - $rs->index_of = array_fill(0, $rs->nn+1, 0); |
|
77 | + $rs->alpha_to = array_fill(0, $rs->nn + 1, 0); |
|
78 | + $rs->index_of = array_fill(0, $rs->nn + 1, 0); |
|
79 | 79 | |
80 | 80 | // PHP style macro replacement ;) |
81 | - $NN =& $rs->nn; |
|
82 | - $A0 =& $NN; |
|
81 | + $NN = & $rs->nn; |
|
82 | + $A0 = & $NN; |
|
83 | 83 | |
84 | 84 | // Generate Galois field lookup tables |
85 | 85 | $rs->index_of[0] = $A0; // log(zero) = -inf |
86 | 86 | $rs->alpha_to[$A0] = 0; // alpha**-inf = 0 |
87 | 87 | $sr = 1; |
88 | 88 | |
89 | - for($i=0; $i<$rs->nn; $i++) { |
|
89 | + for ($i = 0; $i < $rs->nn; $i++) { |
|
90 | 90 | $rs->index_of[$sr] = $i; |
91 | 91 | $rs->alpha_to[$i] = $sr; |
92 | 92 | $sr <<= 1; |
93 | - if($sr & (1<<$symsize)) { |
|
93 | + if ($sr & (1 << $symsize)) { |
|
94 | 94 | $sr ^= $gfpoly; |
95 | 95 | } |
96 | 96 | $sr &= $rs->nn; |
97 | 97 | } |
98 | 98 | |
99 | - if($sr != 1){ |
|
99 | + if ($sr != 1) { |
|
100 | 100 | // field generator polynomial is not primitive! |
101 | 101 | $rs = null; |
102 | 102 | return $rs; |
103 | 103 | } |
104 | 104 | |
105 | 105 | /* Form RS code generator polynomial from its roots */ |
106 | - $rs->genpoly = array_fill(0, $nroots+1, 0); |
|
106 | + $rs->genpoly = array_fill(0, $nroots + 1, 0); |
|
107 | 107 | |
108 | 108 | $rs->fcr = $fcr; |
109 | 109 | $rs->prim = $prim; |
@@ -111,21 +111,21 @@ discard block |
||
111 | 111 | $rs->gfpoly = $gfpoly; |
112 | 112 | |
113 | 113 | /* Find prim-th root of 1, used in decoding */ |
114 | - for($iprim=1;($iprim % $prim) != 0;$iprim += $rs->nn) |
|
114 | + for ($iprim = 1; ($iprim % $prim) != 0; $iprim += $rs->nn) |
|
115 | 115 | ; // intentional empty-body loop! |
116 | 116 | |
117 | - $rs->iprim = (int)($iprim / $prim); |
|
117 | + $rs->iprim = (int) ($iprim / $prim); |
|
118 | 118 | $rs->genpoly[0] = 1; |
119 | 119 | |
120 | - for ($i = 0,$root=$fcr*$prim; $i < $nroots; $i++, $root += $prim) { |
|
121 | - $rs->genpoly[$i+1] = 1; |
|
120 | + for ($i = 0, $root = $fcr * $prim; $i < $nroots; $i++, $root += $prim) { |
|
121 | + $rs->genpoly[$i + 1] = 1; |
|
122 | 122 | |
123 | 123 | // Multiply rs->genpoly[] by @**(root + x) |
124 | 124 | for ($j = $i; $j > 0; $j--) { |
125 | 125 | if ($rs->genpoly[$j] != 0) { |
126 | - $rs->genpoly[$j] = $rs->genpoly[$j-1] ^ $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[$j]] + $root)]; |
|
126 | + $rs->genpoly[$j] = $rs->genpoly[$j - 1] ^ $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[$j]] + $root)]; |
|
127 | 127 | } else { |
128 | - $rs->genpoly[$j] = $rs->genpoly[$j-1]; |
|
128 | + $rs->genpoly[$j] = $rs->genpoly[$j - 1]; |
|
129 | 129 | } |
130 | 130 | } |
131 | 131 | // rs->genpoly[0] can never be zero |
@@ -142,38 +142,38 @@ discard block |
||
142 | 142 | //---------------------------------------------------------------------- |
143 | 143 | public function encode_rs_char($data, &$parity) |
144 | 144 | { |
145 | - $MM =& $this->mm; |
|
146 | - $NN =& $this->nn; |
|
147 | - $ALPHA_TO =& $this->alpha_to; |
|
148 | - $INDEX_OF =& $this->index_of; |
|
149 | - $GENPOLY =& $this->genpoly; |
|
150 | - $NROOTS =& $this->nroots; |
|
151 | - $FCR =& $this->fcr; |
|
152 | - $PRIM =& $this->prim; |
|
153 | - $IPRIM =& $this->iprim; |
|
154 | - $PAD =& $this->pad; |
|
155 | - $A0 =& $NN; |
|
145 | + $MM = & $this->mm; |
|
146 | + $NN = & $this->nn; |
|
147 | + $ALPHA_TO = & $this->alpha_to; |
|
148 | + $INDEX_OF = & $this->index_of; |
|
149 | + $GENPOLY = & $this->genpoly; |
|
150 | + $NROOTS = & $this->nroots; |
|
151 | + $FCR = & $this->fcr; |
|
152 | + $PRIM = & $this->prim; |
|
153 | + $IPRIM = & $this->iprim; |
|
154 | + $PAD = & $this->pad; |
|
155 | + $A0 = & $NN; |
|
156 | 156 | |
157 | 157 | $parity = array_fill(0, $NROOTS, 0); |
158 | 158 | |
159 | - for($i=0; $i< ($NN-$NROOTS-$PAD); $i++) { |
|
159 | + for ($i = 0; $i < ($NN - $NROOTS - $PAD); $i++) { |
|
160 | 160 | |
161 | 161 | $feedback = $INDEX_OF[$data[$i] ^ $parity[0]]; |
162 | - if($feedback != $A0) { |
|
162 | + if ($feedback != $A0) { |
|
163 | 163 | // feedback term is non-zero |
164 | 164 | |
165 | 165 | // This line is unnecessary when GENPOLY[NROOTS] is unity, as it must |
166 | 166 | // always be for the polynomials constructed by init_rs() |
167 | 167 | $feedback = $this->modnn($NN - $GENPOLY[$NROOTS] + $feedback); |
168 | 168 | |
169 | - for($j=1;$j<$NROOTS;$j++) { |
|
170 | - $parity[$j] ^= $ALPHA_TO[$this->modnn($feedback + $GENPOLY[$NROOTS-$j])]; |
|
169 | + for ($j = 1; $j < $NROOTS; $j++) { |
|
170 | + $parity[$j] ^= $ALPHA_TO[$this->modnn($feedback + $GENPOLY[$NROOTS - $j])]; |
|
171 | 171 | } |
172 | 172 | } |
173 | 173 | |
174 | 174 | // Shift |
175 | 175 | array_shift($parity); |
176 | - if($feedback != $A0) { |
|
176 | + if ($feedback != $A0) { |
|
177 | 177 | array_push($parity, $ALPHA_TO[$this->modnn($feedback + $GENPOLY[0])]); |
178 | 178 | } else { |
179 | 179 | array_push($parity, 0); |
@@ -191,13 +191,13 @@ discard block |
||
191 | 191 | //---------------------------------------------------------------------- |
192 | 192 | public static function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) |
193 | 193 | { |
194 | - foreach(self::$items as $rs) { |
|
195 | - if($rs->pad != $pad) continue; |
|
196 | - if($rs->nroots != $nroots) continue; |
|
197 | - if($rs->mm != $symsize) continue; |
|
198 | - if($rs->gfpoly != $gfpoly) continue; |
|
199 | - if($rs->fcr != $fcr) continue; |
|
200 | - if($rs->prim != $prim) continue; |
|
194 | + foreach (self::$items as $rs) { |
|
195 | + if ($rs->pad != $pad) continue; |
|
196 | + if ($rs->nroots != $nroots) continue; |
|
197 | + if ($rs->mm != $symsize) continue; |
|
198 | + if ($rs->gfpoly != $gfpoly) continue; |
|
199 | + if ($rs->fcr != $fcr) continue; |
|
200 | + if ($rs->prim != $prim) continue; |
|
201 | 201 | |
202 | 202 | return $rs; |
203 | 203 | } |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | class QRimage { |
28 | 28 | |
29 | 29 | //---------------------------------------------------------------------- |
30 | - public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=false) |
|
30 | + public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4, $saveandprint = false) |
|
31 | 31 | { |
32 | 32 | $image = self::image($frame, $pixelPerPoint, $outerFrame); |
33 | 33 | |
@@ -35,11 +35,11 @@ discard block |
||
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 | } |
@@ -68,25 +68,25 @@ 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 | - $col[0] = ImageColorAllocate($base_image,255,255,255); |
|
77 | - $col[1] = ImageColorAllocate($base_image,0,0,0); |
|
76 | + $col[0] = ImageColorAllocate($base_image, 255, 255, 255); |
|
77 | + $col[1] = ImageColorAllocate($base_image, 0, 0, 0); |
|
78 | 78 | |
79 | 79 | imagefill($base_image, 0, 0, $col[0]); |
80 | 80 | |
81 | - for($y=0; $y<$h; $y++) { |
|
82 | - for($x=0; $x<$w; $x++) { |
|
81 | + for ($y = 0; $y < $h; $y++) { |
|
82 | + for ($x = 0; $x < $w; $x++) { |
|
83 | 83 | if ($frame[$y][$x] == '1') { |
84 | - ImageSetPixel($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]); |
|
84 | + ImageSetPixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]); |
|
85 | 85 | } |
86 | 86 | } |
87 | 87 | } |
88 | 88 | |
89 | - $target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint); |
|
89 | + $target_image = ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint); |
|
90 | 90 | ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH); |
91 | 91 | ImageDestroy($base_image); |
92 | 92 |
@@ -93,168 +93,168 @@ discard block |
||
93 | 93 | // definitions |
94 | 94 | if (!defined('QRCODEDEFS')) { |
95 | 95 | |
96 | - /** |
|
97 | - * Indicate that definitions for this class are set |
|
98 | - */ |
|
99 | - define('QRCODEDEFS', true); |
|
100 | - |
|
101 | - // ----------------------------------------------------- |
|
102 | - |
|
103 | - // Encoding modes (characters which can be encoded in QRcode) |
|
104 | - |
|
105 | - /** |
|
106 | - * Encoding mode |
|
107 | - */ |
|
108 | - define('QR_MODE_NL', -1); |
|
109 | - |
|
110 | - /** |
|
111 | - * Encoding mode numeric (0-9). 3 characters are encoded to 10bit length. In theory, 7089 characters or less can be stored in a QRcode. |
|
112 | - */ |
|
113 | - define('QR_MODE_NM', 0); |
|
114 | - |
|
115 | - /** |
|
116 | - * Encoding mode alphanumeric (0-9A-Z $%*+-./:) 45characters. 2 characters are encoded to 11bit length. In theory, 4296 characters or less can be stored in a QRcode. |
|
117 | - */ |
|
118 | - define('QR_MODE_AN', 1); |
|
119 | - |
|
120 | - /** |
|
121 | - * Encoding mode 8bit byte data. In theory, 2953 characters or less can be stored in a QRcode. |
|
122 | - */ |
|
123 | - define('QR_MODE_8B', 2); |
|
124 | - |
|
125 | - /** |
|
126 | - * Encoding mode KANJI. A KANJI character (multibyte character) is encoded to 13bit length. In theory, 1817 characters or less can be stored in a QRcode. |
|
127 | - */ |
|
128 | - define('QR_MODE_KJ', 3); |
|
129 | - |
|
130 | - /** |
|
131 | - * Encoding mode STRUCTURED (currently unsupported) |
|
132 | - */ |
|
133 | - define('QR_MODE_ST', 4); |
|
134 | - |
|
135 | - // ----------------------------------------------------- |
|
136 | - |
|
137 | - // Levels of error correction. |
|
138 | - // QRcode has a function of an error correcting for miss reading that white is black. |
|
139 | - // Error correcting is defined in 4 level as below. |
|
140 | - |
|
141 | - /** |
|
142 | - * Error correction level L : About 7% or less errors can be corrected. |
|
143 | - */ |
|
144 | - define('QR_ECLEVEL_L', 0); |
|
145 | - |
|
146 | - /** |
|
147 | - * Error correction level M : About 15% or less errors can be corrected. |
|
148 | - */ |
|
149 | - define('QR_ECLEVEL_M', 1); |
|
150 | - |
|
151 | - /** |
|
152 | - * Error correction level Q : About 25% or less errors can be corrected. |
|
153 | - */ |
|
154 | - define('QR_ECLEVEL_Q', 2); |
|
155 | - |
|
156 | - /** |
|
157 | - * Error correction level H : About 30% or less errors can be corrected. |
|
158 | - */ |
|
159 | - define('QR_ECLEVEL_H', 3); |
|
160 | - |
|
161 | - // ----------------------------------------------------- |
|
162 | - |
|
163 | - // Version. Size of QRcode is defined as version. |
|
164 | - // Version is from 1 to 40. |
|
165 | - // Version 1 is 21*21 matrix. And 4 modules increases whenever 1 version increases. |
|
166 | - // So version 40 is 177*177 matrix. |
|
167 | - |
|
168 | - /** |
|
169 | - * Maximum QR Code version. |
|
170 | - */ |
|
171 | - define('QRSPEC_VERSION_MAX', 40); |
|
172 | - |
|
173 | - /** |
|
174 | - * Maximum matrix size for maximum version (version 40 is 177*177 matrix). |
|
175 | - */ |
|
96 | + /** |
|
97 | + * Indicate that definitions for this class are set |
|
98 | + */ |
|
99 | + define('QRCODEDEFS', true); |
|
100 | + |
|
101 | + // ----------------------------------------------------- |
|
102 | + |
|
103 | + // Encoding modes (characters which can be encoded in QRcode) |
|
104 | + |
|
105 | + /** |
|
106 | + * Encoding mode |
|
107 | + */ |
|
108 | + define('QR_MODE_NL', -1); |
|
109 | + |
|
110 | + /** |
|
111 | + * Encoding mode numeric (0-9). 3 characters are encoded to 10bit length. In theory, 7089 characters or less can be stored in a QRcode. |
|
112 | + */ |
|
113 | + define('QR_MODE_NM', 0); |
|
114 | + |
|
115 | + /** |
|
116 | + * Encoding mode alphanumeric (0-9A-Z $%*+-./:) 45characters. 2 characters are encoded to 11bit length. In theory, 4296 characters or less can be stored in a QRcode. |
|
117 | + */ |
|
118 | + define('QR_MODE_AN', 1); |
|
119 | + |
|
120 | + /** |
|
121 | + * Encoding mode 8bit byte data. In theory, 2953 characters or less can be stored in a QRcode. |
|
122 | + */ |
|
123 | + define('QR_MODE_8B', 2); |
|
124 | + |
|
125 | + /** |
|
126 | + * Encoding mode KANJI. A KANJI character (multibyte character) is encoded to 13bit length. In theory, 1817 characters or less can be stored in a QRcode. |
|
127 | + */ |
|
128 | + define('QR_MODE_KJ', 3); |
|
129 | + |
|
130 | + /** |
|
131 | + * Encoding mode STRUCTURED (currently unsupported) |
|
132 | + */ |
|
133 | + define('QR_MODE_ST', 4); |
|
134 | + |
|
135 | + // ----------------------------------------------------- |
|
136 | + |
|
137 | + // Levels of error correction. |
|
138 | + // QRcode has a function of an error correcting for miss reading that white is black. |
|
139 | + // Error correcting is defined in 4 level as below. |
|
140 | + |
|
141 | + /** |
|
142 | + * Error correction level L : About 7% or less errors can be corrected. |
|
143 | + */ |
|
144 | + define('QR_ECLEVEL_L', 0); |
|
145 | + |
|
146 | + /** |
|
147 | + * Error correction level M : About 15% or less errors can be corrected. |
|
148 | + */ |
|
149 | + define('QR_ECLEVEL_M', 1); |
|
150 | + |
|
151 | + /** |
|
152 | + * Error correction level Q : About 25% or less errors can be corrected. |
|
153 | + */ |
|
154 | + define('QR_ECLEVEL_Q', 2); |
|
155 | + |
|
156 | + /** |
|
157 | + * Error correction level H : About 30% or less errors can be corrected. |
|
158 | + */ |
|
159 | + define('QR_ECLEVEL_H', 3); |
|
160 | + |
|
161 | + // ----------------------------------------------------- |
|
162 | + |
|
163 | + // Version. Size of QRcode is defined as version. |
|
164 | + // Version is from 1 to 40. |
|
165 | + // Version 1 is 21*21 matrix. And 4 modules increases whenever 1 version increases. |
|
166 | + // So version 40 is 177*177 matrix. |
|
167 | + |
|
168 | + /** |
|
169 | + * Maximum QR Code version. |
|
170 | + */ |
|
171 | + define('QRSPEC_VERSION_MAX', 40); |
|
172 | + |
|
173 | + /** |
|
174 | + * Maximum matrix size for maximum version (version 40 is 177*177 matrix). |
|
175 | + */ |
|
176 | 176 | define('QRSPEC_WIDTH_MAX', 177); |
177 | 177 | |
178 | - // ----------------------------------------------------- |
|
178 | + // ----------------------------------------------------- |
|
179 | 179 | |
180 | - /** |
|
181 | - * Matrix index to get width from $capacity array. |
|
182 | - */ |
|
180 | + /** |
|
181 | + * Matrix index to get width from $capacity array. |
|
182 | + */ |
|
183 | 183 | define('QRCAP_WIDTH', 0); |
184 | 184 | |
185 | 185 | /** |
186 | - * Matrix index to get number of words from $capacity array. |
|
187 | - */ |
|
186 | + * Matrix index to get number of words from $capacity array. |
|
187 | + */ |
|
188 | 188 | define('QRCAP_WORDS', 1); |
189 | 189 | |
190 | 190 | /** |
191 | - * Matrix index to get remainder from $capacity array. |
|
192 | - */ |
|
191 | + * Matrix index to get remainder from $capacity array. |
|
192 | + */ |
|
193 | 193 | define('QRCAP_REMINDER', 2); |
194 | 194 | |
195 | 195 | /** |
196 | - * Matrix index to get error correction level from $capacity array. |
|
197 | - */ |
|
196 | + * Matrix index to get error correction level from $capacity array. |
|
197 | + */ |
|
198 | 198 | define('QRCAP_EC', 3); |
199 | 199 | |
200 | - // ----------------------------------------------------- |
|
200 | + // ----------------------------------------------------- |
|
201 | 201 | |
202 | - // Structure (currently usupported) |
|
202 | + // Structure (currently usupported) |
|
203 | 203 | |
204 | - /** |
|
205 | - * Number of header bits for structured mode |
|
206 | - */ |
|
204 | + /** |
|
205 | + * Number of header bits for structured mode |
|
206 | + */ |
|
207 | 207 | define('STRUCTURE_HEADER_BITS', 20); |
208 | 208 | |
209 | 209 | /** |
210 | - * Max number of symbols for structured mode |
|
211 | - */ |
|
210 | + * Max number of symbols for structured mode |
|
211 | + */ |
|
212 | 212 | define('MAX_STRUCTURED_SYMBOLS', 16); |
213 | 213 | |
214 | - // ----------------------------------------------------- |
|
214 | + // ----------------------------------------------------- |
|
215 | 215 | |
216 | 216 | // Masks |
217 | 217 | |
218 | 218 | /** |
219 | - * Down point base value for case 1 mask pattern (concatenation of same color in a line or a column) |
|
220 | - */ |
|
219 | + * Down point base value for case 1 mask pattern (concatenation of same color in a line or a column) |
|
220 | + */ |
|
221 | 221 | define('N1', 3); |
222 | 222 | |
223 | 223 | /** |
224 | - * Down point base value for case 2 mask pattern (module block of same color) |
|
225 | - */ |
|
226 | - define('N2', 3); |
|
224 | + * Down point base value for case 2 mask pattern (module block of same color) |
|
225 | + */ |
|
226 | + define('N2', 3); |
|
227 | 227 | |
228 | 228 | /** |
229 | - * Down point base value for case 3 mask pattern (1:1:3:1:1(dark:bright:dark:bright:dark)pattern in a line or a column) |
|
230 | - */ |
|
231 | - define('N3', 40); |
|
229 | + * Down point base value for case 3 mask pattern (1:1:3:1:1(dark:bright:dark:bright:dark)pattern in a line or a column) |
|
230 | + */ |
|
231 | + define('N3', 40); |
|
232 | 232 | |
233 | 233 | /** |
234 | - * Down point base value for case 4 mask pattern (ration of dark modules in whole) |
|
235 | - */ |
|
236 | - define('N4', 10); |
|
234 | + * Down point base value for case 4 mask pattern (ration of dark modules in whole) |
|
235 | + */ |
|
236 | + define('N4', 10); |
|
237 | 237 | |
238 | - // ----------------------------------------------------- |
|
238 | + // ----------------------------------------------------- |
|
239 | 239 | |
240 | - // Optimization settings |
|
240 | + // Optimization settings |
|
241 | 241 | |
242 | - /** |
|
243 | - * if true, estimates best mask (spec. default, but extremally slow; set to false to significant performance boost but (propably) worst quality code |
|
244 | - */ |
|
245 | - define('QR_FIND_BEST_MASK', true); |
|
242 | + /** |
|
243 | + * if true, estimates best mask (spec. default, but extremally slow; set to false to significant performance boost but (propably) worst quality code |
|
244 | + */ |
|
245 | + define('QR_FIND_BEST_MASK', true); |
|
246 | 246 | |
247 | - /** |
|
248 | - * if false, checks all masks available, otherwise value tells count of masks need to be checked, mask id are got randomly |
|
249 | - */ |
|
250 | - define('QR_FIND_FROM_RANDOM', 2); |
|
247 | + /** |
|
248 | + * if false, checks all masks available, otherwise value tells count of masks need to be checked, mask id are got randomly |
|
249 | + */ |
|
250 | + define('QR_FIND_FROM_RANDOM', 2); |
|
251 | 251 | |
252 | - /** |
|
253 | - * when QR_FIND_BEST_MASK === false |
|
254 | - */ |
|
255 | - define('QR_DEFAULT_MASK', 2); |
|
252 | + /** |
|
253 | + * when QR_FIND_BEST_MASK === false |
|
254 | + */ |
|
255 | + define('QR_DEFAULT_MASK', 2); |
|
256 | 256 | |
257 | - // ----------------------------------------------------- |
|
257 | + // ----------------------------------------------------- |
|
258 | 258 | |
259 | 259 | } // end of definitions |
260 | 260 | |
@@ -262,2614 +262,2614 @@ discard block |
||
262 | 262 | |
263 | 263 | if (!class_exists('QRcode', false)) { |
264 | 264 | |
265 | - // for compaibility with PHP4 |
|
266 | - if (!function_exists('str_split')) { |
|
267 | - /** |
|
268 | - * Convert a string to an array (needed for PHP4 compatibility) |
|
269 | - * @param string $string The input string. |
|
270 | - * @param int $split_length Maximum length of the chunk. |
|
271 | - * @return If the optional split_length parameter is specified, the returned array will be broken down into chunks with each being split_length in length, otherwise each chunk will be one character in length. FALSE is returned if split_length is less than 1. If the split_length length exceeds the length of string , the entire string is returned as the first (and only) array element. |
|
272 | - */ |
|
273 | - function str_split($string, $split_length=1) { |
|
274 | - if ((strlen($string) > $split_length) or (!$split_length)) { |
|
275 | - do { |
|
276 | - $c = strlen($string); |
|
277 | - $parts[] = substr($string, 0, $split_length); |
|
278 | - $string = substr($string, $split_length); |
|
279 | - } while ($string !== false); |
|
280 | - } else { |
|
281 | - $parts = array($string); |
|
282 | - } |
|
283 | - return $parts; |
|
284 | - } |
|
285 | - } |
|
286 | - |
|
287 | - // ##################################################### |
|
288 | - |
|
289 | - /** |
|
290 | - * Class to create QR-code arrays for TCPDF class. |
|
291 | - * QR Code symbol is a 2D barcode that can be scanned by handy terminals such as a mobile phone with CCD. |
|
292 | - * The capacity of QR Code is up to 7000 digits or 4000 characters, and has high robustness. |
|
293 | - * This class supports QR Code model 2, described in JIS (Japanese Industrial Standards) X0510:2004 or ISO/IEC 18004. |
|
294 | - * Currently the following features are not supported: ECI and FNC1 mode, Micro QR Code, QR Code model 1, Structured mode. |
|
295 | - * |
|
296 | - * This class is derived from "PHP QR Code encoder" by Dominik Dzienia (http://phpqrcode.sourceforge.net/) based on "libqrencode C library 3.1.1." by Kentaro Fukuchi (http://megaui.net/fukuchi/works/qrencode/index.en.html), contains Reed-Solomon code written by Phil Karn, KA9Q. QR Code is registered trademark of DENSO WAVE INCORPORATED (http://www.denso-wave.com/qrcode/index-e.html). |
|
297 | - * Please read comments on this class source file for full copyright and license information. |
|
298 | - * |
|
299 | - * @name QRcode |
|
300 | - * @package com.tecnick.tcpdf |
|
301 | - * @abstract Class for generating QR-code array for TCPDF. |
|
302 | - * @author Nicola Asuni |
|
303 | - * @copyright 2010 Nicola Asuni - Tecnick.com S.r.l (www.tecnick.com) Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - [email protected] |
|
304 | - * @link http://www.tcpdf.org |
|
305 | - * @license http://www.gnu.org/copyleft/lesser.html LGPL |
|
306 | - * @version 1.0.002 |
|
307 | - */ |
|
308 | - class QRcode { |
|
309 | - |
|
310 | - /** |
|
311 | - * @var barcode array to be returned which is readable by TCPDF |
|
312 | - * @access protected |
|
313 | - */ |
|
314 | - protected $barcode_array = array(); |
|
315 | - |
|
316 | - /** |
|
317 | - * @var QR code version. Size of QRcode is defined as version. Version is from 1 to 40. Version 1 is 21*21 matrix. And 4 modules increases whenever 1 version increases. So version 40 is 177*177 matrix. |
|
318 | - * @access protected |
|
319 | - */ |
|
320 | - protected $version = 0; |
|
321 | - |
|
322 | - /** |
|
323 | - * @var Levels of error correction. See definitions for possible values. |
|
324 | - * @access protected |
|
325 | - */ |
|
326 | - protected $level = QR_ECLEVEL_L; |
|
327 | - |
|
328 | - /** |
|
329 | - * @var Encoding mode |
|
330 | - * @access protected |
|
331 | - */ |
|
332 | - protected $hint = QR_MODE_8B; |
|
333 | - |
|
334 | - /** |
|
335 | - * @var if true the input string will be converted to uppercase |
|
336 | - * @access protected |
|
337 | - */ |
|
338 | - protected $casesensitive = true; |
|
339 | - |
|
340 | - /** |
|
341 | - * @var structured QR code (not supported yet) |
|
342 | - * @access protected |
|
343 | - */ |
|
344 | - protected $structured = 0; |
|
345 | - |
|
346 | - /** |
|
347 | - * @var mask data |
|
348 | - * @access protected |
|
349 | - */ |
|
350 | - protected $data; |
|
351 | - |
|
352 | - // FrameFiller |
|
353 | - |
|
354 | - /** |
|
355 | - * @var width |
|
356 | - * @access protected |
|
357 | - */ |
|
358 | - protected $width; |
|
359 | - |
|
360 | - /** |
|
361 | - * @var frame |
|
362 | - * @access protected |
|
363 | - */ |
|
364 | - protected $frame; |
|
365 | - |
|
366 | - /** |
|
367 | - * @var X position of bit |
|
368 | - * @access protected |
|
369 | - */ |
|
370 | - protected $x; |
|
371 | - |
|
372 | - /** |
|
373 | - * @var Y position of bit |
|
374 | - * @access protected |
|
375 | - */ |
|
376 | - protected $y; |
|
377 | - |
|
378 | - /** |
|
379 | - * @var direction |
|
380 | - * @access protected |
|
381 | - */ |
|
382 | - protected $dir; |
|
383 | - |
|
384 | - /** |
|
385 | - * @var single bit |
|
386 | - * @access protected |
|
387 | - */ |
|
388 | - protected $bit; |
|
389 | - |
|
390 | - // ---- QRrawcode ---- |
|
391 | - |
|
392 | - /** |
|
393 | - * @var data code |
|
394 | - * @access protected |
|
395 | - */ |
|
396 | - protected $datacode = array(); |
|
397 | - |
|
398 | - /** |
|
399 | - * @var error correction code |
|
400 | - * @access protected |
|
401 | - */ |
|
402 | - protected $ecccode = array(); |
|
403 | - |
|
404 | - /** |
|
405 | - * @var blocks |
|
406 | - * @access protected |
|
407 | - */ |
|
408 | - protected $blocks; |
|
409 | - |
|
410 | - /** |
|
411 | - * @var Reed-Solomon blocks |
|
412 | - * @access protected |
|
413 | - */ |
|
414 | - protected $rsblocks = array(); //of RSblock |
|
415 | - |
|
416 | - /** |
|
417 | - * @var counter |
|
418 | - * @access protected |
|
419 | - */ |
|
420 | - protected $count; |
|
421 | - |
|
422 | - /** |
|
423 | - * @var data length |
|
424 | - * @access protected |
|
425 | - */ |
|
426 | - protected $dataLength; |
|
427 | - |
|
428 | - /** |
|
429 | - * @var error correction length |
|
430 | - * @access protected |
|
431 | - */ |
|
432 | - protected $eccLength; |
|
433 | - |
|
434 | - /** |
|
435 | - * @var b1 |
|
436 | - * @access protected |
|
437 | - */ |
|
438 | - protected $b1; |
|
439 | - |
|
440 | - // ---- QRmask ---- |
|
441 | - |
|
442 | - /** |
|
443 | - * @var run length |
|
444 | - * @access protected |
|
445 | - */ |
|
446 | - protected $runLength = array(); |
|
447 | - |
|
448 | - // ---- QRsplit ---- |
|
449 | - |
|
450 | - /** |
|
451 | - * @var input data string |
|
452 | - * @access protected |
|
453 | - */ |
|
454 | - protected $dataStr = ''; |
|
455 | - |
|
456 | - /** |
|
457 | - * @var input items |
|
458 | - * @access protected |
|
459 | - */ |
|
460 | - protected $items; |
|
461 | - |
|
462 | - // Reed-Solomon items |
|
463 | - |
|
464 | - /** |
|
465 | - * @var Reed-Solomon items |
|
466 | - * @access protected |
|
467 | - */ |
|
468 | - protected $rsitems = array(); |
|
469 | - |
|
470 | - /** |
|
471 | - * @var array of frames |
|
472 | - * @access protected |
|
473 | - */ |
|
474 | - protected $frames = array(); |
|
475 | - |
|
476 | - /** |
|
477 | - * @var alphabet-numeric convesion table |
|
478 | - * @access protected |
|
479 | - */ |
|
480 | - protected $anTable = array( |
|
481 | - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // |
|
482 | - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // |
|
483 | - 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, // |
|
484 | - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, // |
|
485 | - -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, // |
|
486 | - 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, // |
|
487 | - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // |
|
488 | - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 // |
|
489 | - ); |
|
490 | - |
|
491 | - /** |
|
492 | - * @var array Table of the capacity of symbols |
|
493 | - * See Table 1 (pp.13) and Table 12-16 (pp.30-36), JIS X0510:2004. |
|
494 | - * @access protected |
|
495 | - */ |
|
496 | - protected $capacity = array( |
|
497 | - array( 0, 0, 0, array( 0, 0, 0, 0)), // |
|
498 | - array( 21, 26, 0, array( 7, 10, 13, 17)), // 1 |
|
499 | - array( 25, 44, 7, array( 10, 16, 22, 28)), // |
|
500 | - array( 29, 70, 7, array( 15, 26, 36, 44)), // |
|
501 | - array( 33, 100, 7, array( 20, 36, 52, 64)), // |
|
502 | - array( 37, 134, 7, array( 26, 48, 72, 88)), // 5 |
|
503 | - array( 41, 172, 7, array( 36, 64, 96, 112)), // |
|
504 | - array( 45, 196, 0, array( 40, 72, 108, 130)), // |
|
505 | - array( 49, 242, 0, array( 48, 88, 132, 156)), // |
|
506 | - array( 53, 292, 0, array( 60, 110, 160, 192)), // |
|
507 | - array( 57, 346, 0, array( 72, 130, 192, 224)), // 10 |
|
508 | - array( 61, 404, 0, array( 80, 150, 224, 264)), // |
|
509 | - array( 65, 466, 0, array( 96, 176, 260, 308)), // |
|
510 | - array( 69, 532, 0, array( 104, 198, 288, 352)), // |
|
511 | - array( 73, 581, 3, array( 120, 216, 320, 384)), // |
|
512 | - array( 77, 655, 3, array( 132, 240, 360, 432)), // 15 |
|
513 | - array( 81, 733, 3, array( 144, 280, 408, 480)), // |
|
514 | - array( 85, 815, 3, array( 168, 308, 448, 532)), // |
|
515 | - array( 89, 901, 3, array( 180, 338, 504, 588)), // |
|
516 | - array( 93, 991, 3, array( 196, 364, 546, 650)), // |
|
517 | - array( 97, 1085, 3, array( 224, 416, 600, 700)), // 20 |
|
518 | - array(101, 1156, 4, array( 224, 442, 644, 750)), // |
|
519 | - array(105, 1258, 4, array( 252, 476, 690, 816)), // |
|
520 | - array(109, 1364, 4, array( 270, 504, 750, 900)), // |
|
521 | - array(113, 1474, 4, array( 300, 560, 810, 960)), // |
|
522 | - array(117, 1588, 4, array( 312, 588, 870, 1050)), // 25 |
|
523 | - array(121, 1706, 4, array( 336, 644, 952, 1110)), // |
|
524 | - array(125, 1828, 4, array( 360, 700, 1020, 1200)), // |
|
525 | - array(129, 1921, 3, array( 390, 728, 1050, 1260)), // |
|
526 | - array(133, 2051, 3, array( 420, 784, 1140, 1350)), // |
|
527 | - array(137, 2185, 3, array( 450, 812, 1200, 1440)), // 30 |
|
528 | - array(141, 2323, 3, array( 480, 868, 1290, 1530)), // |
|
529 | - array(145, 2465, 3, array( 510, 924, 1350, 1620)), // |
|
530 | - array(149, 2611, 3, array( 540, 980, 1440, 1710)), // |
|
531 | - array(153, 2761, 3, array( 570, 1036, 1530, 1800)), // |
|
532 | - array(157, 2876, 0, array( 570, 1064, 1590, 1890)), // 35 |
|
533 | - array(161, 3034, 0, array( 600, 1120, 1680, 1980)), // |
|
534 | - array(165, 3196, 0, array( 630, 1204, 1770, 2100)), // |
|
535 | - array(169, 3362, 0, array( 660, 1260, 1860, 2220)), // |
|
536 | - array(173, 3532, 0, array( 720, 1316, 1950, 2310)), // |
|
537 | - array(177, 3706, 0, array( 750, 1372, 2040, 2430)) // 40 |
|
538 | - ); |
|
539 | - |
|
540 | - /** |
|
541 | - * @var array Length indicator |
|
542 | - * @access protected |
|
543 | - */ |
|
544 | - protected $lengthTableBits = array( |
|
545 | - array(10, 12, 14), |
|
546 | - array( 9, 11, 13), |
|
547 | - array( 8, 16, 16), |
|
548 | - array( 8, 10, 12) |
|
549 | - ); |
|
550 | - |
|
551 | - /** |
|
552 | - * @var array Table of the error correction code (Reed-Solomon block) |
|
553 | - * See Table 12-16 (pp.30-36), JIS X0510:2004. |
|
554 | - * @access protected |
|
555 | - */ |
|
556 | - protected $eccTable = array( |
|
557 | - array(array( 0, 0), array( 0, 0), array( 0, 0), array( 0, 0)), // |
|
558 | - array(array( 1, 0), array( 1, 0), array( 1, 0), array( 1, 0)), // 1 |
|
559 | - array(array( 1, 0), array( 1, 0), array( 1, 0), array( 1, 0)), // |
|
560 | - array(array( 1, 0), array( 1, 0), array( 2, 0), array( 2, 0)), // |
|
561 | - array(array( 1, 0), array( 2, 0), array( 2, 0), array( 4, 0)), // |
|
562 | - array(array( 1, 0), array( 2, 0), array( 2, 2), array( 2, 2)), // 5 |
|
563 | - array(array( 2, 0), array( 4, 0), array( 4, 0), array( 4, 0)), // |
|
564 | - array(array( 2, 0), array( 4, 0), array( 2, 4), array( 4, 1)), // |
|
565 | - array(array( 2, 0), array( 2, 2), array( 4, 2), array( 4, 2)), // |
|
566 | - array(array( 2, 0), array( 3, 2), array( 4, 4), array( 4, 4)), // |
|
567 | - array(array( 2, 2), array( 4, 1), array( 6, 2), array( 6, 2)), // 10 |
|
568 | - array(array( 4, 0), array( 1, 4), array( 4, 4), array( 3, 8)), // |
|
569 | - array(array( 2, 2), array( 6, 2), array( 4, 6), array( 7, 4)), // |
|
570 | - array(array( 4, 0), array( 8, 1), array( 8, 4), array(12, 4)), // |
|
571 | - array(array( 3, 1), array( 4, 5), array(11, 5), array(11, 5)), // |
|
572 | - array(array( 5, 1), array( 5, 5), array( 5, 7), array(11, 7)), // 15 |
|
573 | - array(array( 5, 1), array( 7, 3), array(15, 2), array( 3, 13)), // |
|
574 | - array(array( 1, 5), array(10, 1), array( 1, 15), array( 2, 17)), // |
|
575 | - array(array( 5, 1), array( 9, 4), array(17, 1), array( 2, 19)), // |
|
576 | - array(array( 3, 4), array( 3, 11), array(17, 4), array( 9, 16)), // |
|
577 | - array(array( 3, 5), array( 3, 13), array(15, 5), array(15, 10)), // 20 |
|
578 | - array(array( 4, 4), array(17, 0), array(17, 6), array(19, 6)), // |
|
579 | - array(array( 2, 7), array(17, 0), array( 7, 16), array(34, 0)), // |
|
580 | - array(array( 4, 5), array( 4, 14), array(11, 14), array(16, 14)), // |
|
581 | - array(array( 6, 4), array( 6, 14), array(11, 16), array(30, 2)), // |
|
582 | - array(array( 8, 4), array( 8, 13), array( 7, 22), array(22, 13)), // 25 |
|
583 | - array(array(10, 2), array(19, 4), array(28, 6), array(33, 4)), // |
|
584 | - array(array( 8, 4), array(22, 3), array( 8, 26), array(12, 28)), // |
|
585 | - array(array( 3, 10), array( 3, 23), array( 4, 31), array(11, 31)), // |
|
586 | - array(array( 7, 7), array(21, 7), array( 1, 37), array(19, 26)), // |
|
587 | - array(array( 5, 10), array(19, 10), array(15, 25), array(23, 25)), // 30 |
|
588 | - array(array(13, 3), array( 2, 29), array(42, 1), array(23, 28)), // |
|
589 | - array(array(17, 0), array(10, 23), array(10, 35), array(19, 35)), // |
|
590 | - array(array(17, 1), array(14, 21), array(29, 19), array(11, 46)), // |
|
591 | - array(array(13, 6), array(14, 23), array(44, 7), array(59, 1)), // |
|
592 | - array(array(12, 7), array(12, 26), array(39, 14), array(22, 41)), // 35 |
|
593 | - array(array( 6, 14), array( 6, 34), array(46, 10), array( 2, 64)), // |
|
594 | - array(array(17, 4), array(29, 14), array(49, 10), array(24, 46)), // |
|
595 | - array(array( 4, 18), array(13, 32), array(48, 14), array(42, 32)), // |
|
596 | - array(array(20, 4), array(40, 7), array(43, 22), array(10, 67)), // |
|
597 | - array(array(19, 6), array(18, 31), array(34, 34), array(20, 61)) // 40 |
|
598 | - ); |
|
599 | - |
|
600 | - /** |
|
601 | - * @var array Positions of alignment patterns. |
|
602 | - * This array includes only the second and the third position of the alignment patterns. Rest of them can be calculated from the distance between them. |
|
603 | - * See Table 1 in Appendix E (pp.71) of JIS X0510:2004. |
|
604 | - * @access protected |
|
605 | - */ |
|
606 | - protected $alignmentPattern = array( |
|
607 | - array( 0, 0), |
|
608 | - array( 0, 0), array(18, 0), array(22, 0), array(26, 0), array(30, 0), // 1- 5 |
|
609 | - array(34, 0), array(22, 38), array(24, 42), array(26, 46), array(28, 50), // 6-10 |
|
610 | - array(30, 54), array(32, 58), array(34, 62), array(26, 46), array(26, 48), // 11-15 |
|
611 | - array(26, 50), array(30, 54), array(30, 56), array(30, 58), array(34, 62), // 16-20 |
|
612 | - array(28, 50), array(26, 50), array(30, 54), array(28, 54), array(32, 58), // 21-25 |
|
613 | - array(30, 58), array(34, 62), array(26, 50), array(30, 54), array(26, 52), // 26-30 |
|
614 | - array(30, 56), array(34, 60), array(30, 58), array(34, 62), array(30, 54), // 31-35 |
|
615 | - array(24, 50), array(28, 54), array(32, 58), array(26, 54), array(30, 58) // 35-40 |
|
616 | - ); |
|
617 | - |
|
618 | - /** |
|
619 | - * @var array Version information pattern (BCH coded). |
|
620 | - * See Table 1 in Appendix D (pp.68) of JIS X0510:2004. |
|
621 | - * size: [QRSPEC_VERSION_MAX - 6] |
|
622 | - * @access protected |
|
623 | - */ |
|
624 | - protected $versionPattern = array( |
|
625 | - 0x07c94, 0x085bc, 0x09a99, 0x0a4d3, 0x0bbf6, 0x0c762, 0x0d847, 0x0e60d, // |
|
626 | - 0x0f928, 0x10b78, 0x1145d, 0x12a17, 0x13532, 0x149a6, 0x15683, 0x168c9, // |
|
627 | - 0x177ec, 0x18ec4, 0x191e1, 0x1afab, 0x1b08e, 0x1cc1a, 0x1d33f, 0x1ed75, // |
|
628 | - 0x1f250, 0x209d5, 0x216f0, 0x228ba, 0x2379f, 0x24b0b, 0x2542e, 0x26a64, // |
|
629 | - 0x27541, 0x28c69 |
|
630 | - ); |
|
631 | - |
|
632 | - /** |
|
633 | - * @var array Format information |
|
634 | - * @access protected |
|
635 | - */ |
|
636 | - protected $formatInfo = array( |
|
637 | - array(0x77c4, 0x72f3, 0x7daa, 0x789d, 0x662f, 0x6318, 0x6c41, 0x6976), // |
|
638 | - array(0x5412, 0x5125, 0x5e7c, 0x5b4b, 0x45f9, 0x40ce, 0x4f97, 0x4aa0), // |
|
639 | - array(0x355f, 0x3068, 0x3f31, 0x3a06, 0x24b4, 0x2183, 0x2eda, 0x2bed), // |
|
640 | - array(0x1689, 0x13be, 0x1ce7, 0x19d0, 0x0762, 0x0255, 0x0d0c, 0x083b) // |
|
641 | - ); |
|
642 | - |
|
643 | - |
|
644 | - // ------------------------------------------------- |
|
645 | - // ------------------------------------------------- |
|
646 | - |
|
647 | - |
|
648 | - /** |
|
649 | - * This is the class constructor. |
|
650 | - * Creates a QRcode object |
|
651 | - * @param string $code code to represent using QRcode |
|
652 | - * @param string $eclevel error level: <ul><li>L : About 7% or less errors can be corrected.</li><li>M : About 15% or less errors can be corrected.</li><li>Q : About 25% or less errors can be corrected.</li><li>H : About 30% or less errors can be corrected.</li></ul> |
|
653 | - * @access public |
|
654 | - * @since 1.0.000 |
|
655 | - */ |
|
656 | - public function __construct($code, $eclevel = 'L') { |
|
657 | - $barcode_array = array(); |
|
658 | - if ((is_null($code)) or ($code == '\0') or ($code == '')) { |
|
659 | - return false; |
|
660 | - } |
|
661 | - // set error correction level |
|
662 | - $this->level = array_search($eclevel, array('L', 'M', 'Q', 'H')); |
|
663 | - if ($this->level === false) { |
|
664 | - $this->level = QR_ECLEVEL_L; |
|
665 | - } |
|
666 | - if (($this->hint != QR_MODE_8B) and ($this->hint != QR_MODE_KJ)) { |
|
667 | - return false; |
|
668 | - } |
|
669 | - if (($this->version < 0) or ($this->version > QRSPEC_VERSION_MAX)) { |
|
670 | - return false; |
|
671 | - } |
|
672 | - $this->items = array(); |
|
673 | - $this->encodeString($code); |
|
674 | - $qrTab = $this->binarize($this->data); |
|
675 | - $size = count($qrTab); |
|
676 | - $barcode_array['num_rows'] = $size; |
|
677 | - $barcode_array['num_cols'] = $size; |
|
678 | - $barcode_array['bcode'] = array(); |
|
679 | - foreach ($qrTab as $line) { |
|
680 | - $arrAdd = array(); |
|
681 | - foreach (str_split($line) as $char) { |
|
682 | - $arrAdd[] = ($char=='1')?1:0; |
|
683 | - } |
|
684 | - $barcode_array['bcode'][] = $arrAdd; |
|
685 | - } |
|
686 | - $this->barcode_array = $barcode_array; |
|
687 | - } |
|
688 | - |
|
689 | - /** |
|
690 | - * Returns a barcode array which is readable by TCPDF |
|
691 | - * @return array barcode array readable by TCPDF; |
|
692 | - * @access public |
|
693 | - */ |
|
694 | - public function getBarcodeArray() { |
|
695 | - return $this->barcode_array; |
|
696 | - } |
|
697 | - |
|
698 | - /** |
|
699 | - * Convert the frame in binary form |
|
700 | - * @param array $frame array to binarize |
|
701 | - * @return array frame in binary form |
|
702 | - */ |
|
703 | - protected function binarize($frame) { |
|
704 | - $len = count($frame); |
|
705 | - // the frame is square (width = height) |
|
706 | - foreach ($frame as &$frameLine) { |
|
707 | - for ($i=0; $i<$len; $i++) { |
|
708 | - $frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0'; |
|
709 | - } |
|
710 | - } |
|
711 | - return $frame; |
|
712 | - } |
|
713 | - |
|
714 | - /** |
|
715 | - * Encode the input string to QR code |
|
716 | - * @param string $string input string to encode |
|
717 | - */ |
|
718 | - protected function encodeString($string) { |
|
719 | - $this->dataStr = $string; |
|
720 | - if (!$this->casesensitive) { |
|
721 | - $this->toUpper(); |
|
722 | - } |
|
723 | - $ret = $this->splitString(); |
|
724 | - if ($ret < 0) { |
|
725 | - return null; |
|
726 | - } |
|
727 | - $this->encodeMask(-1); |
|
728 | - } |
|
729 | - |
|
730 | - /** |
|
731 | - * Encode mask |
|
732 | - * @param int $mask masking mode |
|
733 | - */ |
|
734 | - protected function encodeMask($mask) { |
|
735 | - $spec = array(0, 0, 0, 0, 0); |
|
736 | - $this->datacode = $this->getByteStream($this->items); |
|
737 | - if (is_null($this->datacode)) { |
|
738 | - return null; |
|
739 | - } |
|
740 | - $spec = $this->getEccSpec($this->version, $this->level, $spec); |
|
741 | - $this->b1 = $this->rsBlockNum1($spec); |
|
742 | - $this->dataLength = $this->rsDataLength($spec); |
|
743 | - $this->eccLength = $this->rsEccLength($spec); |
|
744 | - $this->ecccode = array_fill(0, $this->eccLength, 0); |
|
745 | - $this->blocks = $this->rsBlockNum($spec); |
|
746 | - $ret = $this->init($spec); |
|
747 | - if ($ret < 0) { |
|
748 | - return null; |
|
749 | - } |
|
750 | - $this->count = 0; |
|
751 | - $this->width = $this->getWidth($this->version); |
|
752 | - $this->frame = $this->newFrame($this->version); |
|
753 | - $this->x = $this->width - 1; |
|
754 | - $this->y = $this->width - 1; |
|
755 | - $this->dir = -1; |
|
756 | - $this->bit = -1; |
|
757 | - // inteleaved data and ecc codes |
|
758 | - for ($i=0; $i < ($this->dataLength + $this->eccLength); $i++) { |
|
759 | - $code = $this->getCode(); |
|
760 | - $bit = 0x80; |
|
761 | - for ($j=0; $j<8; $j++) { |
|
762 | - $addr = $this->getNextPosition(); |
|
763 | - $this->setFrameAt($addr, 0x02 | (($bit & $code) != 0)); |
|
764 | - $bit = $bit >> 1; |
|
765 | - } |
|
766 | - } |
|
767 | - // remainder bits |
|
768 | - $j = $this->getRemainder($this->version); |
|
769 | - for ($i=0; $i<$j; $i++) { |
|
770 | - $addr = $this->getNextPosition(); |
|
771 | - $this->setFrameAt($addr, 0x02); |
|
772 | - } |
|
773 | - // masking |
|
774 | - $this->runLength = array_fill(0, QRSPEC_WIDTH_MAX + 1, 0); |
|
775 | - if ($mask < 0) { |
|
776 | - if (QR_FIND_BEST_MASK) { |
|
777 | - $masked = $this->mask($this->width, $this->frame, $this->level); |
|
778 | - } else { |
|
779 | - $masked = $this->makeMask($this->width, $this->frame, (intval(QR_DEFAULT_MASK) % 8), $this->level); |
|
780 | - } |
|
781 | - } else { |
|
782 | - $masked = $this->makeMask($this->width, $this->frame, $mask, $this->level); |
|
783 | - } |
|
784 | - if ($masked == null) { |
|
785 | - return null; |
|
786 | - } |
|
787 | - $this->data = $masked; |
|
788 | - } |
|
789 | - |
|
790 | - // - - - - - - - - - - - - - - - - - - - - - - - - - |
|
791 | - |
|
792 | - // FrameFiller |
|
793 | - |
|
794 | - /** |
|
795 | - * Set frame value at specified position |
|
796 | - * @param array $at x,y position |
|
797 | - * @param int $val value of the character to set |
|
798 | - */ |
|
799 | - protected function setFrameAt($at, $val) { |
|
800 | - $this->frame[$at['y']][$at['x']] = chr($val); |
|
801 | - } |
|
802 | - |
|
803 | - /** |
|
804 | - * Get frame value at specified position |
|
805 | - * @param array $at x,y position |
|
806 | - * @return value at specified position |
|
807 | - */ |
|
808 | - protected function getFrameAt($at) { |
|
809 | - return ord($this->frame[$at['y']][$at['x']]); |
|
810 | - } |
|
811 | - |
|
812 | - /** |
|
813 | - * Return the next frame position |
|
814 | - * @return array of x,y coordinates |
|
815 | - */ |
|
816 | - protected function getNextPosition() { |
|
817 | - do { |
|
818 | - if ($this->bit == -1) { |
|
819 | - $this->bit = 0; |
|
820 | - return array('x'=>$this->x, 'y'=>$this->y); |
|
821 | - } |
|
822 | - $x = $this->x; |
|
823 | - $y = $this->y; |
|
824 | - $w = $this->width; |
|
825 | - if ($this->bit == 0) { |
|
826 | - $x--; |
|
827 | - $this->bit++; |
|
828 | - } else { |
|
829 | - $x++; |
|
830 | - $y += $this->dir; |
|
831 | - $this->bit--; |
|
832 | - } |
|
833 | - if ($this->dir < 0) { |
|
834 | - if ($y < 0) { |
|
835 | - $y = 0; |
|
836 | - $x -= 2; |
|
837 | - $this->dir = 1; |
|
838 | - if ($x == 6) { |
|
839 | - $x--; |
|
840 | - $y = 9; |
|
841 | - } |
|
842 | - } |
|
843 | - } else { |
|
844 | - if ($y == $w) { |
|
845 | - $y = $w - 1; |
|
846 | - $x -= 2; |
|
847 | - $this->dir = -1; |
|
848 | - if ($x == 6) { |
|
849 | - $x--; |
|
850 | - $y -= 8; |
|
851 | - } |
|
852 | - } |
|
853 | - } |
|
854 | - if (($x < 0) or ($y < 0)) { |
|
855 | - return null; |
|
856 | - } |
|
857 | - $this->x = $x; |
|
858 | - $this->y = $y; |
|
859 | - } while(ord($this->frame[$y][$x]) & 0x80); |
|
860 | - return array('x'=>$x, 'y'=>$y); |
|
861 | - } |
|
862 | - |
|
863 | - // - - - - - - - - - - - - - - - - - - - - - - - - - |
|
864 | - |
|
865 | - // QRrawcode |
|
866 | - |
|
867 | - /** |
|
868 | - * Initialize code. |
|
869 | - * @param array $spec array of ECC specification |
|
870 | - * @return 0 in case of success, -1 in case of error |
|
871 | - */ |
|
872 | - protected function init($spec) { |
|
873 | - $dl = $this->rsDataCodes1($spec); |
|
874 | - $el = $this->rsEccCodes1($spec); |
|
875 | - $rs = $this->init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el); |
|
876 | - $blockNo = 0; |
|
877 | - $dataPos = 0; |
|
878 | - $eccPos = 0; |
|
879 | - $endfor = $this->rsBlockNum1($spec); |
|
880 | - for ($i=0; $i < $endfor; ++$i) { |
|
881 | - $ecc = array_slice($this->ecccode, $eccPos); |
|
882 | - $this->rsblocks[$blockNo] = array(); |
|
883 | - $this->rsblocks[$blockNo]['dataLength'] = $dl; |
|
884 | - $this->rsblocks[$blockNo]['data'] = array_slice($this->datacode, $dataPos); |
|
885 | - $this->rsblocks[$blockNo]['eccLength'] = $el; |
|
886 | - $ecc = $this->encode_rs_char($rs, $this->rsblocks[$blockNo]['data'], $ecc); |
|
887 | - $this->rsblocks[$blockNo]['ecc'] = $ecc; |
|
888 | - $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc); |
|
889 | - $dataPos += $dl; |
|
890 | - $eccPos += $el; |
|
891 | - $blockNo++; |
|
892 | - } |
|
893 | - if ($this->rsBlockNum2($spec) == 0) { |
|
894 | - return 0; |
|
895 | - } |
|
896 | - $dl = $this->rsDataCodes2($spec); |
|
897 | - $el = $this->rsEccCodes2($spec); |
|
898 | - $rs = $this->init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el); |
|
899 | - if ($rs == null) { |
|
900 | - return -1; |
|
901 | - } |
|
902 | - $endfor = $this->rsBlockNum2($spec); |
|
903 | - for ($i=0; $i < $endfor; ++$i) { |
|
904 | - $ecc = array_slice($this->ecccode, $eccPos); |
|
905 | - $this->rsblocks[$blockNo] = array(); |
|
906 | - $this->rsblocks[$blockNo]['dataLength'] = $dl; |
|
907 | - $this->rsblocks[$blockNo]['data'] = array_slice($this->datacode, $dataPos); |
|
908 | - $this->rsblocks[$blockNo]['eccLength'] = $el; |
|
909 | - $ecc = $this->encode_rs_char($rs, $this->rsblocks[$blockNo]['data'], $ecc); |
|
910 | - $this->rsblocks[$blockNo]['ecc'] = $ecc; |
|
911 | - $this->ecccode = array_merge(array_slice($this->ecccode, 0, $eccPos), $ecc); |
|
912 | - $dataPos += $dl; |
|
913 | - $eccPos += $el; |
|
914 | - $blockNo++; |
|
915 | - } |
|
916 | - return 0; |
|
917 | - } |
|
918 | - |
|
919 | - /** |
|
920 | - * Return Reed-Solomon block code. |
|
921 | - * @return array rsblocks |
|
922 | - */ |
|
923 | - protected function getCode() { |
|
924 | - if ($this->count < $this->dataLength) { |
|
925 | - $row = $this->count % $this->blocks; |
|
926 | - $col = $this->count / $this->blocks; |
|
927 | - if ($col >= $this->rsblocks[0]['dataLength']) { |
|
928 | - $row += $this->b1; |
|
929 | - } |
|
930 | - $ret = $this->rsblocks[$row]['data'][$col]; |
|
931 | - } elseif ($this->count < $this->dataLength + $this->eccLength) { |
|
932 | - $row = ($this->count - $this->dataLength) % $this->blocks; |
|
933 | - $col = ($this->count - $this->dataLength) / $this->blocks; |
|
934 | - $ret = $this->rsblocks[$row]['ecc'][$col]; |
|
935 | - } else { |
|
936 | - return 0; |
|
937 | - } |
|
938 | - $this->count++; |
|
939 | - return $ret; |
|
940 | - } |
|
941 | - |
|
942 | - // - - - - - - - - - - - - - - - - - - - - - - - - - |
|
943 | - |
|
944 | - // QRmask |
|
945 | - |
|
946 | - /** |
|
947 | - * Write Format Information on frame and returns the number of black bits |
|
948 | - * @param int $width frame width |
|
949 | - * @param array $frame frame |
|
950 | - * @param array $mask masking mode |
|
951 | - * @param int $level error correction level |
|
952 | - * @return int blacks |
|
953 | - */ |
|
954 | - protected function writeFormatInformation($width, &$frame, $mask, $level) { |
|
955 | - $blacks = 0; |
|
956 | - $format = $this->getFormatInfo($mask, $level); |
|
957 | - for ($i=0; $i<8; ++$i) { |
|
958 | - if ($format & 1) { |
|
959 | - $blacks += 2; |
|
960 | - $v = 0x85; |
|
961 | - } else { |
|
962 | - $v = 0x84; |
|
963 | - } |
|
964 | - $frame[8][$width - 1 - $i] = chr($v); |
|
965 | - if ($i < 6) { |
|
966 | - $frame[$i][8] = chr($v); |
|
967 | - } else { |
|
968 | - $frame[$i + 1][8] = chr($v); |
|
969 | - } |
|
970 | - $format = $format >> 1; |
|
971 | - } |
|
972 | - for ($i=0; $i<7; ++$i) { |
|
973 | - if ($format & 1) { |
|
974 | - $blacks += 2; |
|
975 | - $v = 0x85; |
|
976 | - } else { |
|
977 | - $v = 0x84; |
|
978 | - } |
|
979 | - $frame[$width - 7 + $i][8] = chr($v); |
|
980 | - if ($i == 0) { |
|
981 | - $frame[8][7] = chr($v); |
|
982 | - } else { |
|
983 | - $frame[8][6 - $i] = chr($v); |
|
984 | - } |
|
985 | - $format = $format >> 1; |
|
986 | - } |
|
987 | - return $blacks; |
|
988 | - } |
|
989 | - |
|
990 | - /** |
|
991 | - * mask0 |
|
992 | - * @param int $x X position |
|
993 | - * @param int $y Y position |
|
994 | - * @return int mask |
|
995 | - */ |
|
996 | - protected function mask0($x, $y) { |
|
997 | - return ($x + $y) & 1; |
|
998 | - } |
|
999 | - |
|
1000 | - /** |
|
1001 | - * mask1 |
|
1002 | - * @param int $x X position |
|
1003 | - * @param int $y Y position |
|
1004 | - * @return int mask |
|
1005 | - */ |
|
1006 | - protected function mask1($x, $y) { |
|
1007 | - return ($y & 1); |
|
1008 | - } |
|
1009 | - |
|
1010 | - /** |
|
1011 | - * mask2 |
|
1012 | - * @param int $x X position |
|
1013 | - * @param int $y Y position |
|
1014 | - * @return int mask |
|
1015 | - */ |
|
1016 | - protected function mask2($x, $y) { |
|
1017 | - return ($x % 3); |
|
1018 | - } |
|
1019 | - |
|
1020 | - /** |
|
1021 | - * mask3 |
|
1022 | - * @param int $x X position |
|
1023 | - * @param int $y Y position |
|
1024 | - * @return int mask |
|
1025 | - */ |
|
1026 | - protected function mask3($x, $y) { |
|
1027 | - return ($x + $y) % 3; |
|
1028 | - } |
|
1029 | - |
|
1030 | - /** |
|
1031 | - * mask4 |
|
1032 | - * @param int $x X position |
|
1033 | - * @param int $y Y position |
|
1034 | - * @return int mask |
|
1035 | - */ |
|
1036 | - protected function mask4($x, $y) { |
|
1037 | - return (((int)($y / 2)) + ((int)($x / 3))) & 1; |
|
1038 | - } |
|
1039 | - |
|
1040 | - /** |
|
1041 | - * mask5 |
|
1042 | - * @param int $x X position |
|
1043 | - * @param int $y Y position |
|
1044 | - * @return int mask |
|
1045 | - */ |
|
1046 | - protected function mask5($x, $y) { |
|
1047 | - return (($x * $y) & 1) + ($x * $y) % 3; |
|
1048 | - } |
|
1049 | - |
|
1050 | - /** |
|
1051 | - * mask6 |
|
1052 | - * @param int $x X position |
|
1053 | - * @param int $y Y position |
|
1054 | - * @return int mask |
|
1055 | - */ |
|
1056 | - protected function mask6($x, $y) { |
|
1057 | - return ((($x * $y) & 1) + ($x * $y) % 3) & 1; |
|
1058 | - } |
|
1059 | - |
|
1060 | - /** |
|
1061 | - * mask7 |
|
1062 | - * @param int $x X position |
|
1063 | - * @param int $y Y position |
|
1064 | - * @return int mask |
|
1065 | - */ |
|
1066 | - protected function mask7($x, $y) { |
|
1067 | - return ((($x * $y) % 3) + (($x + $y) & 1)) & 1; |
|
1068 | - } |
|
1069 | - |
|
1070 | - /** |
|
1071 | - * Return bitmask |
|
1072 | - * @param int $maskNo mask number |
|
1073 | - * @param int $width width |
|
1074 | - * @param array $frame frame |
|
1075 | - * @return array bitmask |
|
1076 | - */ |
|
1077 | - protected function generateMaskNo($maskNo, $width, $frame) { |
|
1078 | - $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); |
|
1079 | - for ($y=0; $y<$width; ++$y) { |
|
1080 | - for ($x=0; $x<$width; ++$x) { |
|
1081 | - if (ord($frame[$y][$x]) & 0x80) { |
|
1082 | - $bitMask[$y][$x] = 0; |
|
1083 | - } else { |
|
1084 | - $maskFunc = call_user_func(array($this, 'mask'.$maskNo), $x, $y); |
|
1085 | - $bitMask[$y][$x] = ($maskFunc == 0)?1:0; |
|
1086 | - } |
|
1087 | - } |
|
1088 | - } |
|
1089 | - return $bitMask; |
|
1090 | - } |
|
1091 | - |
|
1092 | - /** |
|
1093 | - * makeMaskNo |
|
1094 | - * @param int $maskNo |
|
1095 | - * @param int $width |
|
1096 | - * @param int $s |
|
1097 | - * @param int $d |
|
1098 | - * @param boolean $maskGenOnly |
|
1099 | - * @return int b |
|
1100 | - */ |
|
1101 | - protected function makeMaskNo($maskNo, $width, $s, &$d, $maskGenOnly=false) { |
|
1102 | - $b = 0; |
|
1103 | - $bitMask = array(); |
|
1104 | - $bitMask = $this->generateMaskNo($maskNo, $width, $s); |
|
1105 | - if ($maskGenOnly) { |
|
1106 | - return; |
|
1107 | - } |
|
1108 | - $d = $s; |
|
1109 | - for ($y=0; $y<$width; ++$y) { |
|
1110 | - for ($x=0; $x<$width; ++$x) { |
|
1111 | - if ($bitMask[$y][$x] == 1) { |
|
1112 | - $d[$y][$x] = chr(ord($s[$y][$x]) ^ (int)$bitMask[$y][$x]); |
|
1113 | - } |
|
1114 | - $b += (int)(ord($d[$y][$x]) & 1); |
|
1115 | - } |
|
1116 | - } |
|
1117 | - return $b; |
|
1118 | - } |
|
1119 | - |
|
1120 | - /** |
|
1121 | - * makeMask |
|
1122 | - * @param int $width |
|
1123 | - * @param array $frame |
|
1124 | - * @param int $maskNo |
|
1125 | - * @param int $level |
|
1126 | - * @return array mask |
|
1127 | - */ |
|
1128 | - protected function makeMask($width, $frame, $maskNo, $level) { |
|
1129 | - $masked = array_fill(0, $width, str_repeat("\0", $width)); |
|
1130 | - $this->makeMaskNo($maskNo, $width, $frame, $masked); |
|
1131 | - $this->writeFormatInformation($width, $masked, $maskNo, $level); |
|
1132 | - return $masked; |
|
1133 | - } |
|
1134 | - |
|
1135 | - /** |
|
1136 | - * calcN1N3 |
|
1137 | - * @param int $length |
|
1138 | - * @return int demerit |
|
1139 | - */ |
|
1140 | - protected function calcN1N3($length) { |
|
1141 | - $demerit = 0; |
|
1142 | - for ($i=0; $i<$length; ++$i) { |
|
1143 | - if ($this->runLength[$i] >= 5) { |
|
1144 | - $demerit += (N1 + ($this->runLength[$i] - 5)); |
|
1145 | - } |
|
1146 | - if ($i & 1) { |
|
1147 | - if (($i >= 3) and ($i < ($length-2)) and ($this->runLength[$i] % 3 == 0)) { |
|
1148 | - $fact = (int)($this->runLength[$i] / 3); |
|
1149 | - if (($this->runLength[$i-2] == $fact) |
|
1150 | - and ($this->runLength[$i-1] == $fact) |
|
1151 | - and ($this->runLength[$i+1] == $fact) |
|
1152 | - and ($this->runLength[$i+2] == $fact)) { |
|
1153 | - if (($this->runLength[$i-3] < 0) or ($this->runLength[$i-3] >= (4 * $fact))) { |
|
1154 | - $demerit += N3; |
|
1155 | - } elseif ((($i+3) >= $length) or ($this->runLength[$i+3] >= (4 * $fact))) { |
|
1156 | - $demerit += N3; |
|
1157 | - } |
|
1158 | - } |
|
1159 | - } |
|
1160 | - } |
|
1161 | - } |
|
1162 | - return $demerit; |
|
1163 | - } |
|
1164 | - |
|
1165 | - /** |
|
1166 | - * evaluateSymbol |
|
1167 | - * @param int $width |
|
1168 | - * @param array $frame |
|
1169 | - * @return int demerit |
|
1170 | - */ |
|
1171 | - protected function evaluateSymbol($width, $frame) { |
|
1172 | - $head = 0; |
|
1173 | - $demerit = 0; |
|
1174 | - for ($y=0; $y<$width; ++$y) { |
|
1175 | - $head = 0; |
|
1176 | - $this->runLength[0] = 1; |
|
1177 | - $frameY = $frame[$y]; |
|
1178 | - if ($y > 0) { |
|
1179 | - $frameYM = $frame[$y-1]; |
|
1180 | - } |
|
1181 | - for ($x=0; $x<$width; ++$x) { |
|
1182 | - if (($x > 0) and ($y > 0)) { |
|
1183 | - $b22 = ord($frameY[$x]) & ord($frameY[$x-1]) & ord($frameYM[$x]) & ord($frameYM[$x-1]); |
|
1184 | - $w22 = ord($frameY[$x]) | ord($frameY[$x-1]) | ord($frameYM[$x]) | ord($frameYM[$x-1]); |
|
1185 | - if (($b22 | ($w22 ^ 1)) & 1) { |
|
1186 | - $demerit += N2; |
|
1187 | - } |
|
1188 | - } |
|
1189 | - if (($x == 0) and (ord($frameY[$x]) & 1)) { |
|
1190 | - $this->runLength[0] = -1; |
|
1191 | - $head = 1; |
|
1192 | - $this->runLength[$head] = 1; |
|
1193 | - } elseif ($x > 0) { |
|
1194 | - if ((ord($frameY[$x]) ^ ord($frameY[$x-1])) & 1) { |
|
1195 | - $head++; |
|
1196 | - $this->runLength[$head] = 1; |
|
1197 | - } else { |
|
1198 | - $this->runLength[$head]++; |
|
1199 | - } |
|
1200 | - } |
|
1201 | - } |
|
1202 | - $demerit += $this->calcN1N3($head+1); |
|
1203 | - } |
|
1204 | - for ($x=0; $x<$width; ++$x) { |
|
1205 | - $head = 0; |
|
1206 | - $this->runLength[0] = 1; |
|
1207 | - for ($y=0; $y<$width; ++$y) { |
|
1208 | - if (($y == 0) and (ord($frame[$y][$x]) & 1)) { |
|
1209 | - $this->runLength[0] = -1; |
|
1210 | - $head = 1; |
|
1211 | - $this->runLength[$head] = 1; |
|
1212 | - } elseif ($y > 0) { |
|
1213 | - if ((ord($frame[$y][$x]) ^ ord($frame[$y-1][$x])) & 1) { |
|
1214 | - $head++; |
|
1215 | - $this->runLength[$head] = 1; |
|
1216 | - } else { |
|
1217 | - $this->runLength[$head]++; |
|
1218 | - } |
|
1219 | - } |
|
1220 | - } |
|
1221 | - $demerit += $this->calcN1N3($head+1); |
|
1222 | - } |
|
1223 | - return $demerit; |
|
1224 | - } |
|
1225 | - |
|
1226 | - /** |
|
1227 | - * mask |
|
1228 | - * @param int $width |
|
1229 | - * @param array $frame |
|
1230 | - * @param int $level |
|
1231 | - * @return array best mask |
|
1232 | - */ |
|
1233 | - protected function mask($width, $frame, $level) { |
|
1234 | - $minDemerit = PHP_INT_MAX; |
|
1235 | - $bestMaskNum = 0; |
|
1236 | - $bestMask = array(); |
|
1237 | - $checked_masks = array(0, 1, 2, 3, 4, 5, 6, 7); |
|
1238 | - if (QR_FIND_FROM_RANDOM !== false) { |
|
1239 | - $howManuOut = 8 - (QR_FIND_FROM_RANDOM % 9); |
|
1240 | - for ($i = 0; $i < $howManuOut; ++$i) { |
|
1241 | - $remPos = rand (0, count($checked_masks)-1); |
|
1242 | - unset($checked_masks[$remPos]); |
|
1243 | - $checked_masks = array_values($checked_masks); |
|
1244 | - } |
|
1245 | - } |
|
1246 | - $bestMask = $frame; |
|
1247 | - foreach ($checked_masks as $i) { |
|
1248 | - $mask = array_fill(0, $width, str_repeat("\0", $width)); |
|
1249 | - $demerit = 0; |
|
1250 | - $blacks = 0; |
|
1251 | - $blacks = $this->makeMaskNo($i, $width, $frame, $mask); |
|
1252 | - $blacks += $this->writeFormatInformation($width, $mask, $i, $level); |
|
1253 | - $blacks = (int)(100 * $blacks / ($width * $width)); |
|
1254 | - $demerit = (int)((int)(abs($blacks - 50) / 5) * N4); |
|
1255 | - $demerit += $this->evaluateSymbol($width, $mask); |
|
1256 | - if ($demerit < $minDemerit) { |
|
1257 | - $minDemerit = $demerit; |
|
1258 | - $bestMask = $mask; |
|
1259 | - $bestMaskNum = $i; |
|
1260 | - } |
|
1261 | - } |
|
1262 | - return $bestMask; |
|
1263 | - } |
|
1264 | - |
|
1265 | - // - - - - - - - - - - - - - - - - - - - - - - - - - |
|
1266 | - |
|
1267 | - // QRsplit |
|
1268 | - |
|
1269 | - /** |
|
1270 | - * Return true if the character at specified position is a number |
|
1271 | - * @param string $str string |
|
1272 | - * @param int $pos characted position |
|
1273 | - * @return boolean true of false |
|
1274 | - */ |
|
1275 | - protected function isdigitat($str, $pos) { |
|
1276 | - if ($pos >= strlen($str)) { |
|
1277 | - return false; |
|
1278 | - } |
|
1279 | - return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9'))); |
|
1280 | - } |
|
1281 | - |
|
1282 | - /** |
|
1283 | - * Return true if the character at specified position is an alphanumeric character |
|
1284 | - * @param string $str string |
|
1285 | - * @param int $pos characted position |
|
1286 | - * @return boolean true of false |
|
1287 | - */ |
|
1288 | - protected function isalnumat($str, $pos) { |
|
1289 | - if ($pos >= strlen($str)) { |
|
1290 | - return false; |
|
1291 | - } |
|
1292 | - return ($this->lookAnTable(ord($str[$pos])) >= 0); |
|
1293 | - } |
|
1294 | - |
|
1295 | - /** |
|
1296 | - * identifyMode |
|
1297 | - * @param int $pos |
|
1298 | - * @return int mode |
|
1299 | - */ |
|
1300 | - protected function identifyMode($pos) { |
|
1301 | - if ($pos >= strlen($this->dataStr)) { |
|
1302 | - return QR_MODE_NL; |
|
1303 | - } |
|
1304 | - $c = $this->dataStr[$pos]; |
|
1305 | - if ($this->isdigitat($this->dataStr, $pos)) { |
|
1306 | - return QR_MODE_NM; |
|
1307 | - } elseif ($this->isalnumat($this->dataStr, $pos)) { |
|
1308 | - return QR_MODE_AN; |
|
1309 | - } elseif ($this->hint == QR_MODE_KJ) { |
|
1310 | - if ($pos+1 < strlen($this->dataStr)) { |
|
1311 | - $d = $this->dataStr[$pos+1]; |
|
1312 | - $word = (ord($c) << 8) | ord($d); |
|
1313 | - if (($word >= 0x8140 && $word <= 0x9ffc) or ($word >= 0xe040 && $word <= 0xebbf)) { |
|
1314 | - return QR_MODE_KJ; |
|
1315 | - } |
|
1316 | - } |
|
1317 | - } |
|
1318 | - return QR_MODE_8B; |
|
1319 | - } |
|
1320 | - |
|
1321 | - /** |
|
1322 | - * eatNum |
|
1323 | - * @return int run |
|
1324 | - */ |
|
1325 | - protected function eatNum() { |
|
1326 | - $ln = $this->lengthIndicator(QR_MODE_NM, $this->version); |
|
1327 | - $p = 0; |
|
1328 | - while($this->isdigitat($this->dataStr, $p)) { |
|
1329 | - $p++; |
|
1330 | - } |
|
1331 | - $run = $p; |
|
1332 | - $mode = $this->identifyMode($p); |
|
1333 | - if ($mode == QR_MODE_8B) { |
|
1334 | - $dif = $this->estimateBitsModeNum($run) + 4 + $ln |
|
1335 | - + $this->estimateBitsMode8(1) // + 4 + l8 |
|
1336 | - - $this->estimateBitsMode8($run + 1); // - 4 - l8 |
|
1337 | - if ($dif > 0) { |
|
1338 | - return $this->eat8(); |
|
1339 | - } |
|
1340 | - } |
|
1341 | - if ($mode == QR_MODE_AN) { |
|
1342 | - $dif = $this->estimateBitsModeNum($run) + 4 + $ln |
|
1343 | - + $this->estimateBitsModeAn(1) // + 4 + la |
|
1344 | - - $this->estimateBitsModeAn($run + 1);// - 4 - la |
|
1345 | - if ($dif > 0) { |
|
1346 | - return $this->eatAn(); |
|
1347 | - } |
|
1348 | - } |
|
1349 | - $this->items = $this->appendNewInputItem($this->items, QR_MODE_NM, $run, str_split($this->dataStr)); |
|
1350 | - return $run; |
|
1351 | - } |
|
1352 | - |
|
1353 | - /** |
|
1354 | - * eatAn |
|
1355 | - * @return int run |
|
1356 | - */ |
|
1357 | - protected function eatAn() { |
|
1358 | - $la = $this->lengthIndicator(QR_MODE_AN, $this->version); |
|
1359 | - $ln = $this->lengthIndicator(QR_MODE_NM, $this->version); |
|
1360 | - $p = 0; |
|
1361 | - while($this->isalnumat($this->dataStr, $p)) { |
|
1362 | - if ($this->isdigitat($this->dataStr, $p)) { |
|
1363 | - $q = $p; |
|
1364 | - while($this->isdigitat($this->dataStr, $q)) { |
|
1365 | - $q++; |
|
1366 | - } |
|
1367 | - $dif = $this->estimateBitsModeAn($p) // + 4 + la |
|
1368 | - + $this->estimateBitsModeNum($q - $p) + 4 + $ln |
|
1369 | - - $this->estimateBitsModeAn($q); // - 4 - la |
|
1370 | - if ($dif < 0) { |
|
1371 | - break; |
|
1372 | - } else { |
|
1373 | - $p = $q; |
|
1374 | - } |
|
1375 | - } else { |
|
1376 | - $p++; |
|
1377 | - } |
|
1378 | - } |
|
1379 | - $run = $p; |
|
1380 | - if (!$this->isalnumat($this->dataStr, $p)) { |
|
1381 | - $dif = $this->estimateBitsModeAn($run) + 4 + $la |
|
1382 | - + $this->estimateBitsMode8(1) // + 4 + l8 |
|
1383 | - - $this->estimateBitsMode8($run + 1); // - 4 - l8 |
|
1384 | - if ($dif > 0) { |
|
1385 | - return $this->eat8(); |
|
1386 | - } |
|
1387 | - } |
|
1388 | - $this->items = $this->appendNewInputItem($this->items, QR_MODE_AN, $run, str_split($this->dataStr)); |
|
1389 | - return $run; |
|
1390 | - } |
|
1391 | - |
|
1392 | - /** |
|
1393 | - * eatKanji |
|
1394 | - * @return int run |
|
1395 | - */ |
|
1396 | - protected function eatKanji() { |
|
1397 | - $p = 0; |
|
1398 | - while($this->identifyMode($p) == QR_MODE_KJ) { |
|
1399 | - $p += 2; |
|
1400 | - } |
|
1401 | - $this->items = $this->appendNewInputItem($this->items, QR_MODE_KJ, $p, str_split($this->dataStr)); |
|
1402 | - return $p; |
|
1403 | - } |
|
1404 | - |
|
1405 | - /** |
|
1406 | - * eat8 |
|
1407 | - * @return int run |
|
1408 | - */ |
|
1409 | - protected function eat8() { |
|
1410 | - $la = $this->lengthIndicator(QR_MODE_AN, $this->version); |
|
1411 | - $ln = $this->lengthIndicator(QR_MODE_NM, $this->version); |
|
1412 | - $p = 1; |
|
1413 | - $dataStrLen = strlen($this->dataStr); |
|
1414 | - while($p < $dataStrLen) { |
|
1415 | - $mode = $this->identifyMode($p); |
|
1416 | - if ($mode == QR_MODE_KJ) { |
|
1417 | - break; |
|
1418 | - } |
|
1419 | - if ($mode == QR_MODE_NM) { |
|
1420 | - $q = $p; |
|
1421 | - while($this->isdigitat($this->dataStr, $q)) { |
|
1422 | - $q++; |
|
1423 | - } |
|
1424 | - $dif = $this->estimateBitsMode8($p) // + 4 + l8 |
|
1425 | - + $this->estimateBitsModeNum($q - $p) + 4 + $ln |
|
1426 | - - $this->estimateBitsMode8($q); // - 4 - l8 |
|
1427 | - if ($dif < 0) { |
|
1428 | - break; |
|
1429 | - } else { |
|
1430 | - $p = $q; |
|
1431 | - } |
|
1432 | - } elseif ($mode == QR_MODE_AN) { |
|
1433 | - $q = $p; |
|
1434 | - while($this->isalnumat($this->dataStr, $q)) { |
|
1435 | - $q++; |
|
1436 | - } |
|
1437 | - $dif = $this->estimateBitsMode8($p) // + 4 + l8 |
|
1438 | - + $this->estimateBitsModeAn($q - $p) + 4 + $la |
|
1439 | - - $this->estimateBitsMode8($q); // - 4 - l8 |
|
1440 | - if ($dif < 0) { |
|
1441 | - break; |
|
1442 | - } else { |
|
1443 | - $p = $q; |
|
1444 | - } |
|
1445 | - } else { |
|
1446 | - $p++; |
|
1447 | - } |
|
1448 | - } |
|
1449 | - $run = $p; |
|
1450 | - $this->items = $this->appendNewInputItem($this->items, QR_MODE_8B, $run, str_split($this->dataStr)); |
|
1451 | - return $run; |
|
1452 | - } |
|
1453 | - |
|
1454 | - /** |
|
1455 | - * splitString |
|
1456 | - */ |
|
1457 | - protected function splitString() { |
|
1458 | - while (strlen($this->dataStr) > 0) { |
|
1459 | - if ($this->dataStr == '') { |
|
1460 | - return 0; |
|
1461 | - } |
|
1462 | - $mode = $this->identifyMode(0); |
|
1463 | - switch ($mode) { |
|
1464 | - case QR_MODE_NM: { |
|
1465 | - $length = $this->eatNum(); |
|
1466 | - break; |
|
1467 | - } |
|
1468 | - case QR_MODE_AN: { |
|
1469 | - $length = $this->eatAn(); |
|
1470 | - break; |
|
1471 | - } |
|
1472 | - case QR_MODE_KJ: { |
|
1473 | - if ($this->hint == QR_MODE_KJ) { |
|
1474 | - $length = $this->eatKanji(); |
|
1475 | - } else { |
|
1476 | - $length = $this->eat8(); |
|
1477 | - } |
|
1478 | - break; |
|
1479 | - } |
|
1480 | - default: { |
|
1481 | - $length = $this->eat8(); |
|
1482 | - break; |
|
1483 | - } |
|
1484 | - } |
|
1485 | - if ($length == 0) { |
|
1486 | - return 0; |
|
1487 | - } |
|
1488 | - if ($length < 0) { |
|
1489 | - return -1; |
|
1490 | - } |
|
1491 | - $this->dataStr = substr($this->dataStr, $length); |
|
1492 | - } |
|
1493 | - } |
|
1494 | - |
|
1495 | - /** |
|
1496 | - * toUpper |
|
1497 | - */ |
|
1498 | - protected function toUpper() { |
|
1499 | - $stringLen = strlen($this->dataStr); |
|
1500 | - $p = 0; |
|
1501 | - while ($p < $stringLen) { |
|
1502 | - $mode = $this->identifyMode(substr($this->dataStr, $p)); |
|
1503 | - if ($mode == QR_MODE_KJ) { |
|
1504 | - $p += 2; |
|
1505 | - } else { |
|
1506 | - if ((ord($this->dataStr[$p]) >= ord('a')) and (ord($this->dataStr[$p]) <= ord('z'))) { |
|
1507 | - $this->dataStr[$p] = chr(ord($this->dataStr[$p]) - 32); |
|
1508 | - } |
|
1509 | - $p++; |
|
1510 | - } |
|
1511 | - } |
|
1512 | - return $this->dataStr; |
|
1513 | - } |
|
1514 | - |
|
1515 | - // - - - - - - - - - - - - - - - - - - - - - - - - - |
|
1516 | - |
|
1517 | - // QRinputItem |
|
1518 | - |
|
1519 | - /** |
|
1520 | - * newInputItem |
|
1521 | - * @param int $mode |
|
1522 | - * @param int $size |
|
1523 | - * @param array $data |
|
1524 | - * @param array $bstream |
|
1525 | - * @return array input item |
|
1526 | - */ |
|
1527 | - protected function newInputItem($mode, $size, $data, $bstream=null) { |
|
1528 | - $setData = array_slice($data, 0, $size); |
|
1529 | - if (count($setData) < $size) { |
|
1530 | - $setData = array_merge($setData, array_fill(0, ($size - count($setData)), 0)); |
|
1531 | - } |
|
1532 | - if (!$this->check($mode, $size, $setData)) { |
|
1533 | - return null; |
|
1534 | - } |
|
1535 | - $inputitem = array(); |
|
1536 | - $inputitem['mode'] = $mode; |
|
1537 | - $inputitem['size'] = $size; |
|
1538 | - $inputitem['data'] = $setData; |
|
1539 | - $inputitem['bstream'] = $bstream; |
|
1540 | - return $inputitem; |
|
1541 | - } |
|
1542 | - |
|
1543 | - /** |
|
1544 | - * encodeModeNum |
|
1545 | - * @param array $inputitem |
|
1546 | - * @param int $version |
|
1547 | - * @return array input item |
|
1548 | - */ |
|
1549 | - protected function encodeModeNum($inputitem, $version) { |
|
1550 | - $words = (int)($inputitem['size'] / 3); |
|
1551 | - $inputitem['bstream'] = array(); |
|
1552 | - $val = 0x1; |
|
1553 | - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, $val); |
|
1554 | - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_NM, $version), $inputitem['size']); |
|
1555 | - for ($i=0; $i < $words; ++$i) { |
|
1556 | - $val = (ord($inputitem['data'][$i*3 ]) - ord('0')) * 100; |
|
1557 | - $val += (ord($inputitem['data'][$i*3+1]) - ord('0')) * 10; |
|
1558 | - $val += (ord($inputitem['data'][$i*3+2]) - ord('0')); |
|
1559 | - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 10, $val); |
|
1560 | - } |
|
1561 | - if ($inputitem['size'] - $words * 3 == 1) { |
|
1562 | - $val = ord($inputitem['data'][$words*3]) - ord('0'); |
|
1563 | - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, $val); |
|
1564 | - } elseif (($inputitem['size'] - ($words * 3)) == 2) { |
|
1565 | - $val = (ord($inputitem['data'][$words*3 ]) - ord('0')) * 10; |
|
1566 | - $val += (ord($inputitem['data'][$words*3+1]) - ord('0')); |
|
1567 | - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 7, $val); |
|
1568 | - } |
|
1569 | - return $inputitem; |
|
1570 | - } |
|
1571 | - |
|
1572 | - /** |
|
1573 | - * encodeModeAn |
|
1574 | - * @param array $inputitem |
|
1575 | - * @param int $version |
|
1576 | - * @return array input item |
|
1577 | - */ |
|
1578 | - protected function encodeModeAn($inputitem, $version) { |
|
1579 | - $words = (int)($inputitem['size'] / 2); |
|
1580 | - $inputitem['bstream'] = array(); |
|
1581 | - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x02); |
|
1582 | - $inputitem['bstream'] = $this->appendNum(v, $this->lengthIndicator(QR_MODE_AN, $version), $inputitem['size']); |
|
1583 | - for ($i=0; $i < $words; ++$i) { |
|
1584 | - $val = (int)$this->lookAnTable(ord($inputitem['data'][$i*2 ])) * 45; |
|
1585 | - $val += (int)$this->lookAnTable(ord($inputitem['data'][$i*2+1])); |
|
1586 | - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 11, $val); |
|
1587 | - } |
|
1588 | - if ($inputitem['size'] & 1) { |
|
1589 | - $val = $this->lookAnTable(ord($inputitem['data'][($words * 2)])); |
|
1590 | - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 6, $val); |
|
1591 | - } |
|
1592 | - return $inputitem; |
|
1593 | - } |
|
1594 | - |
|
1595 | - /** |
|
1596 | - * encodeMode8 |
|
1597 | - * @param array $inputitem |
|
1598 | - * @param int $version |
|
1599 | - * @return array input item |
|
1600 | - */ |
|
1601 | - protected function encodeMode8($inputitem, $version) { |
|
1602 | - $inputitem['bstream'] = array(); |
|
1603 | - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x4); |
|
1604 | - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_8B, $version), $inputitem['size']); |
|
1605 | - for ($i=0; $i < $inputitem['size']; ++$i) { |
|
1606 | - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 8, ord($inputitem['data'][$i])); |
|
1607 | - } |
|
1608 | - return $inputitem; |
|
1609 | - } |
|
1610 | - |
|
1611 | - /** |
|
1612 | - * encodeModeKanji |
|
1613 | - * @param array $inputitem |
|
1614 | - * @param int $version |
|
1615 | - * @return array input item |
|
1616 | - */ |
|
1617 | - protected function encodeModeKanji($inputitem, $version) { |
|
1618 | - $inputitem['bstream'] = array(); |
|
1619 | - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x8); |
|
1620 | - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_KJ, $version), (int)($inputitem['size'] / 2)); |
|
1621 | - for ($i=0; $i<$inputitem['size']; $i+=2) { |
|
1622 | - $val = (ord($inputitem['data'][$i]) << 8) | ord($inputitem['data'][$i+1]); |
|
1623 | - if ($val <= 0x9ffc) { |
|
1624 | - $val -= 0x8140; |
|
1625 | - } else { |
|
1626 | - $val -= 0xc140; |
|
1627 | - } |
|
1628 | - $h = ($val >> 8) * 0xc0; |
|
1629 | - $val = ($val & 0xff) + $h; |
|
1630 | - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 13, $val); |
|
1631 | - } |
|
1632 | - return $inputitem; |
|
1633 | - } |
|
1634 | - |
|
1635 | - /** |
|
1636 | - * encodeModeStructure |
|
1637 | - * @param array $inputitem |
|
1638 | - * @return array input item |
|
1639 | - */ |
|
1640 | - protected function encodeModeStructure($inputitem) { |
|
1641 | - $inputitem['bstream'] = array(); |
|
1642 | - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x03); |
|
1643 | - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, ord($inputitem['data'][1]) - 1); |
|
1644 | - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, ord($inputitem['data'][0]) - 1); |
|
1645 | - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 8, ord($inputitem['data'][2])); |
|
1646 | - return $inputitem; |
|
1647 | - } |
|
1648 | - |
|
1649 | - /** |
|
1650 | - * encodeBitStream |
|
1651 | - * @param array $inputitem |
|
1652 | - * @param int $version |
|
1653 | - * @return array input item |
|
1654 | - */ |
|
1655 | - protected function encodeBitStream($inputitem, $version) { |
|
1656 | - $inputitem['bstream'] = array(); |
|
1657 | - $words = $this->maximumWords($inputitem['mode'], $version); |
|
1658 | - if ($inputitem['size'] > $words) { |
|
1659 | - $st1 = $this->newInputItem($inputitem['mode'], $words, $inputitem['data']); |
|
1660 | - $st2 = $this->newInputItem($inputitem['mode'], $inputitem['size'] - $words, array_slice($inputitem['data'], $words)); |
|
1661 | - $st1 = $this->encodeBitStream($st1, $version); |
|
1662 | - $st2 = $this->encodeBitStream($st2, $version); |
|
1663 | - $inputitem['bstream'] = array(); |
|
1664 | - $inputitem['bstream'] = $this->appendBitstream($inputitem['bstream'], $st1['bstream']); |
|
1665 | - $inputitem['bstream'] = $this->appendBitstream($inputitem['bstream'], $st2['bstream']); |
|
1666 | - } else { |
|
1667 | - switch($inputitem['mode']) { |
|
1668 | - case QR_MODE_NM: { |
|
1669 | - $inputitem = $this->encodeModeNum($inputitem, $version); |
|
1670 | - break; |
|
1671 | - } |
|
1672 | - case QR_MODE_AN: { |
|
1673 | - $inputitem = $this->encodeModeAn($inputitem, $version); |
|
1674 | - break; |
|
1675 | - } |
|
1676 | - case QR_MODE_8B: { |
|
1677 | - $inputitem = $this->encodeMode8($inputitem, $version); |
|
1678 | - break; |
|
1679 | - } |
|
1680 | - case QR_MODE_KJ: { |
|
1681 | - $inputitem = $this->encodeModeKanji($inputitem, $version); |
|
1682 | - break; |
|
1683 | - } |
|
1684 | - case QR_MODE_ST: { |
|
1685 | - $inputitem = $this->encodeModeStructure($inputitem); |
|
1686 | - break; |
|
1687 | - } |
|
1688 | - default: { |
|
1689 | - break; |
|
1690 | - } |
|
1691 | - } |
|
1692 | - } |
|
1693 | - return $inputitem; |
|
1694 | - } |
|
1695 | - |
|
1696 | - // - - - - - - - - - - - - - - - - - - - - - - - - - |
|
1697 | - |
|
1698 | - // QRinput |
|
1699 | - |
|
1700 | - /** |
|
1701 | - * Append data to an input object. |
|
1702 | - * The data is copied and appended to the input object. |
|
1703 | - * @param array items input items |
|
1704 | - * @param int $mode encoding mode. |
|
1705 | - * @param int $size size of data (byte). |
|
1706 | - * @param array $data array of input data. |
|
1707 | - * @return items |
|
1708 | - * |
|
1709 | - */ |
|
1710 | - protected function appendNewInputItem($items, $mode, $size, $data) { |
|
1711 | - $items[] = $this->newInputItem($mode, $size, $data); |
|
1712 | - return $items; |
|
1713 | - } |
|
1714 | - |
|
1715 | - /** |
|
1716 | - * insertStructuredAppendHeader |
|
1717 | - * @param array $items |
|
1718 | - * @param int $size |
|
1719 | - * @param int $index |
|
1720 | - * @param int $parity |
|
1721 | - * @return array items |
|
1722 | - */ |
|
1723 | - protected function insertStructuredAppendHeader($items, $size, $index, $parity) { |
|
1724 | - if ($size > MAX_STRUCTURED_SYMBOLS) { |
|
1725 | - return -1; |
|
1726 | - } |
|
1727 | - if (($index <= 0) or ($index > MAX_STRUCTURED_SYMBOLS)) { |
|
1728 | - return -1; |
|
1729 | - } |
|
1730 | - $buf = array($size, $index, $parity); |
|
1731 | - $entry = $this->newInputItem(QR_MODE_ST, 3, buf); |
|
1732 | - array_unshift($items, $entry); |
|
1733 | - return $items; |
|
1734 | - } |
|
1735 | - |
|
1736 | - /** |
|
1737 | - * calcParity |
|
1738 | - * @param array $items |
|
1739 | - * @return int parity |
|
1740 | - */ |
|
1741 | - protected function calcParity($items) { |
|
1742 | - $parity = 0; |
|
1743 | - foreach ($items as $item) { |
|
1744 | - if ($item['mode'] != QR_MODE_ST) { |
|
1745 | - for ($i=$item['size']-1; $i>=0; --$i) { |
|
1746 | - $parity ^= $item['data'][$i]; |
|
1747 | - } |
|
1748 | - } |
|
1749 | - } |
|
1750 | - return $parity; |
|
1751 | - } |
|
1752 | - |
|
1753 | - /** |
|
1754 | - * checkModeNum |
|
1755 | - * @param int $size |
|
1756 | - * @param array $data |
|
1757 | - * @return boolean true or false |
|
1758 | - */ |
|
1759 | - protected function checkModeNum($size, $data) { |
|
1760 | - for ($i=0; $i<$size; ++$i) { |
|
1761 | - if ((ord($data[$i]) < ord('0')) or (ord($data[$i]) > ord('9'))){ |
|
1762 | - return false; |
|
1763 | - } |
|
1764 | - } |
|
1765 | - return true; |
|
1766 | - } |
|
1767 | - |
|
1768 | - /** |
|
1769 | - * estimateBitsModeNum |
|
1770 | - * @param int $size |
|
1771 | - * @return int number of bits |
|
1772 | - */ |
|
1773 | - protected function estimateBitsModeNum($size) { |
|
1774 | - $w = (int)$size / 3; |
|
1775 | - $bits = $w * 10; |
|
1776 | - switch($size - $w * 3) { |
|
1777 | - case 1: { |
|
1778 | - $bits += 4; |
|
1779 | - break; |
|
1780 | - } |
|
1781 | - case 2: { |
|
1782 | - $bits += 7; |
|
1783 | - break; |
|
1784 | - } |
|
1785 | - default: { |
|
1786 | - break; |
|
1787 | - } |
|
1788 | - } |
|
1789 | - return $bits; |
|
1790 | - } |
|
1791 | - |
|
1792 | - /** |
|
1793 | - * Look up the alphabet-numeric convesion table (see JIS X0510:2004, pp.19). |
|
1794 | - * @param int $c character value |
|
1795 | - * @return value |
|
1796 | - */ |
|
1797 | - protected function lookAnTable($c) { |
|
1798 | - return (($c > 127)?-1:$this->anTable[$c]); |
|
1799 | - } |
|
1800 | - |
|
1801 | - /** |
|
1802 | - * checkModeAn |
|
1803 | - * @param int $size |
|
1804 | - * @param array $data |
|
1805 | - * @return boolean true or false |
|
1806 | - */ |
|
1807 | - protected function checkModeAn($size, $data) { |
|
1808 | - for ($i=0; $i<$size; ++$i) { |
|
1809 | - if ($this->lookAnTable(ord($data[$i])) == -1) { |
|
1810 | - return false; |
|
1811 | - } |
|
1812 | - } |
|
1813 | - return true; |
|
1814 | - } |
|
1815 | - |
|
1816 | - /** |
|
1817 | - * estimateBitsModeAn |
|
1818 | - * @param int $size |
|
1819 | - * @return int number of bits |
|
1820 | - */ |
|
1821 | - protected function estimateBitsModeAn($size) { |
|
1822 | - $w = (int)($size / 2); |
|
1823 | - $bits = $w * 11; |
|
1824 | - if ($size & 1) { |
|
1825 | - $bits += 6; |
|
1826 | - } |
|
1827 | - return $bits; |
|
1828 | - } |
|
1829 | - |
|
1830 | - /** |
|
1831 | - * estimateBitsMode8 |
|
1832 | - * @param int $size |
|
1833 | - * @return int number of bits |
|
1834 | - */ |
|
1835 | - protected function estimateBitsMode8($size) { |
|
1836 | - return $size * 8; |
|
1837 | - } |
|
1838 | - |
|
1839 | - /** |
|
1840 | - * estimateBitsModeKanji |
|
1841 | - * @param int $size |
|
1842 | - * @return int number of bits |
|
1843 | - */ |
|
1844 | - protected function estimateBitsModeKanji($size) { |
|
1845 | - return (int)(($size / 2) * 13); |
|
1846 | - } |
|
1847 | - |
|
1848 | - /** |
|
1849 | - * checkModeKanji |
|
1850 | - * @param int $size |
|
1851 | - * @param array $data |
|
1852 | - * @return boolean true or false |
|
1853 | - */ |
|
1854 | - protected function checkModeKanji($size, $data) { |
|
1855 | - if ($size & 1) { |
|
1856 | - return false; |
|
1857 | - } |
|
1858 | - for ($i=0; $i<$size; $i+=2) { |
|
1859 | - $val = (ord($data[$i]) << 8) | ord($data[$i+1]); |
|
1860 | - if (($val < 0x8140) or (($val > 0x9ffc) and ($val < 0xe040)) or ($val > 0xebbf)) { |
|
1861 | - return false; |
|
1862 | - } |
|
1863 | - } |
|
1864 | - return true; |
|
1865 | - } |
|
1866 | - |
|
1867 | - /** |
|
1868 | - * Validate the input data. |
|
1869 | - * @param int $mode encoding mode. |
|
1870 | - * @param int $size size of data (byte). |
|
1871 | - * @param array data data to validate |
|
1872 | - * @return boolean true in case of valid data, false otherwise |
|
1873 | - */ |
|
1874 | - protected function check($mode, $size, $data) { |
|
1875 | - if ($size <= 0) { |
|
1876 | - return false; |
|
1877 | - } |
|
1878 | - switch($mode) { |
|
1879 | - case QR_MODE_NM: { |
|
1880 | - return $this->checkModeNum($size, $data); |
|
1881 | - } |
|
1882 | - case QR_MODE_AN: { |
|
1883 | - return $this->checkModeAn($size, $data); |
|
1884 | - } |
|
1885 | - case QR_MODE_KJ: { |
|
1886 | - return $this->checkModeKanji($size, $data); |
|
1887 | - } |
|
1888 | - case QR_MODE_8B: { |
|
1889 | - return true; |
|
1890 | - } |
|
1891 | - case QR_MODE_ST: { |
|
1892 | - return true; |
|
1893 | - } |
|
1894 | - default: { |
|
1895 | - break; |
|
1896 | - } |
|
1897 | - } |
|
1898 | - return false; |
|
1899 | - } |
|
1900 | - |
|
1901 | - /** |
|
1902 | - * estimateBitStreamSize |
|
1903 | - * @param array $items |
|
1904 | - * @param int $version |
|
1905 | - * @return int bits |
|
1906 | - */ |
|
1907 | - protected function estimateBitStreamSize($items, $version) { |
|
1908 | - $bits = 0; |
|
1909 | - if ($version == 0) { |
|
1910 | - $version = 1; |
|
1911 | - } |
|
1912 | - foreach ($items as $item) { |
|
1913 | - switch($item['mode']) { |
|
1914 | - case QR_MODE_NM: { |
|
1915 | - $bits = $this->estimateBitsModeNum($item['size']); |
|
1916 | - break; |
|
1917 | - } |
|
1918 | - case QR_MODE_AN: { |
|
1919 | - $bits = $this->estimateBitsModeAn($item['size']); |
|
1920 | - break; |
|
1921 | - } |
|
1922 | - case QR_MODE_8B: { |
|
1923 | - $bits = $this->estimateBitsMode8($item['size']); |
|
1924 | - break; |
|
1925 | - } |
|
1926 | - case QR_MODE_KJ: { |
|
1927 | - $bits = $this->estimateBitsModeKanji($item['size']); |
|
1928 | - break; |
|
1929 | - } |
|
1930 | - case QR_MODE_ST: { |
|
1931 | - return STRUCTURE_HEADER_BITS; |
|
1932 | - } |
|
1933 | - default: { |
|
1934 | - return 0; |
|
1935 | - } |
|
1936 | - } |
|
1937 | - $l = $this->lengthIndicator($item['mode'], $version); |
|
1938 | - $m = 1 << $l; |
|
1939 | - $num = (int)(($item['size'] + $m - 1) / $m); |
|
1940 | - $bits += $num * (4 + $l); |
|
1941 | - } |
|
1942 | - return $bits; |
|
1943 | - } |
|
1944 | - |
|
1945 | - /** |
|
1946 | - * estimateVersion |
|
1947 | - * @param array $items |
|
1948 | - * @return int version |
|
1949 | - */ |
|
1950 | - protected function estimateVersion($items) { |
|
1951 | - $version = 0; |
|
1952 | - $prev = 0; |
|
1953 | - do { |
|
1954 | - $prev = $version; |
|
1955 | - $bits = $this->estimateBitStreamSize($items, $prev); |
|
1956 | - $version = $this->getMinimumVersion((int)(($bits + 7) / 8), $this->level); |
|
1957 | - if ($version < 0) { |
|
1958 | - return -1; |
|
1959 | - } |
|
1960 | - } while ($version > $prev); |
|
1961 | - return $version; |
|
1962 | - } |
|
1963 | - |
|
1964 | - /** |
|
1965 | - * lengthOfCode |
|
1966 | - * @param int $mode |
|
1967 | - * @param int $version |
|
1968 | - * @param int $bits |
|
1969 | - * @return int size |
|
1970 | - */ |
|
1971 | - protected function lengthOfCode($mode, $version, $bits) { |
|
1972 | - $payload = $bits - 4 - $this->lengthIndicator($mode, $version); |
|
1973 | - switch($mode) { |
|
1974 | - case QR_MODE_NM: { |
|
1975 | - $chunks = (int)($payload / 10); |
|
1976 | - $remain = $payload - $chunks * 10; |
|
1977 | - $size = $chunks * 3; |
|
1978 | - if ($remain >= 7) { |
|
1979 | - $size += 2; |
|
1980 | - } elseif ($remain >= 4) { |
|
1981 | - $size += 1; |
|
1982 | - } |
|
1983 | - break; |
|
1984 | - } |
|
1985 | - case QR_MODE_AN: { |
|
1986 | - $chunks = (int)($payload / 11); |
|
1987 | - $remain = $payload - $chunks * 11; |
|
1988 | - $size = $chunks * 2; |
|
1989 | - if ($remain >= 6) { |
|
1990 | - ++$size; |
|
1991 | - } |
|
1992 | - break; |
|
1993 | - } |
|
1994 | - case QR_MODE_8B: { |
|
1995 | - $size = (int)($payload / 8); |
|
1996 | - break; |
|
1997 | - } |
|
1998 | - case QR_MODE_KJ: { |
|
1999 | - $size = (int)(($payload / 13) * 2); |
|
2000 | - break; |
|
2001 | - } |
|
2002 | - case QR_MODE_ST: { |
|
2003 | - $size = (int)($payload / 8); |
|
2004 | - break; |
|
2005 | - } |
|
2006 | - default: { |
|
2007 | - $size = 0; |
|
2008 | - break; |
|
2009 | - } |
|
2010 | - } |
|
2011 | - $maxsize = $this->maximumWords($mode, $version); |
|
2012 | - if ($size < 0) { |
|
2013 | - $size = 0; |
|
2014 | - } |
|
2015 | - if ($size > $maxsize) { |
|
2016 | - $size = $maxsize; |
|
2017 | - } |
|
2018 | - return $size; |
|
2019 | - } |
|
2020 | - |
|
2021 | - /** |
|
2022 | - * createBitStream |
|
2023 | - * @param array $items |
|
2024 | - * @return array of items and total bits |
|
2025 | - */ |
|
2026 | - protected function createBitStream($items) { |
|
2027 | - $total = 0; |
|
2028 | - foreach ($items as $key => $item) { |
|
2029 | - $items[$key] = $this->encodeBitStream($item, $this->version); |
|
2030 | - $bits = count($items[$key]['bstream']); |
|
2031 | - $total += $bits; |
|
2032 | - } |
|
2033 | - return array($items, $total); |
|
2034 | - } |
|
2035 | - |
|
2036 | - /** |
|
2037 | - * convertData |
|
2038 | - * @param array $items |
|
2039 | - * @return array items |
|
2040 | - */ |
|
2041 | - protected function convertData($items) { |
|
2042 | - $ver = $this->estimateVersion($items); |
|
2043 | - if ($ver > $this->version) { |
|
2044 | - $this->version = $ver; |
|
2045 | - } |
|
2046 | - for (;;) { |
|
2047 | - $cbs = $this->createBitStream($items); |
|
2048 | - $items = $cbs[0]; |
|
2049 | - $bits = $cbs[1]; |
|
2050 | - if ($bits < 0) { |
|
2051 | - return -1; |
|
2052 | - } |
|
2053 | - $ver = $this->getMinimumVersion((int)(($bits + 7) / 8), $this->level); |
|
2054 | - if ($ver < 0) { |
|
2055 | - return -1; |
|
2056 | - } elseif ($ver > $this->version) { |
|
2057 | - $this->version = $ver; |
|
2058 | - } else { |
|
2059 | - break; |
|
2060 | - } |
|
2061 | - } |
|
2062 | - return $items; |
|
2063 | - } |
|
2064 | - |
|
2065 | - /** |
|
2066 | - * Append Padding Bit to bitstream |
|
2067 | - * @param array $bstream |
|
2068 | - * @return array bitstream |
|
2069 | - */ |
|
2070 | - protected function appendPaddingBit($bstream) { |
|
2071 | - $bits = count($bstream); |
|
2072 | - $maxwords = $this->getDataLength($this->version, $this->level); |
|
2073 | - $maxbits = $maxwords * 8; |
|
2074 | - if ($maxbits == $bits) { |
|
2075 | - return 0; |
|
2076 | - } |
|
2077 | - if ($maxbits - $bits < 5) { |
|
2078 | - return $this->appendNum($bstream, $maxbits - $bits, 0); |
|
2079 | - } |
|
2080 | - $bits += 4; |
|
2081 | - $words = (int)(($bits + 7) / 8); |
|
2082 | - $padding = array(); |
|
2083 | - $padding = $this->appendNum($padding, $words * 8 - $bits + 4, 0); |
|
2084 | - $padlen = $maxwords - $words; |
|
2085 | - if ($padlen > 0) { |
|
2086 | - $padbuf = array(); |
|
2087 | - for ($i=0; $i<$padlen; ++$i) { |
|
2088 | - $padbuf[$i] = ($i&1)?0x11:0xec; |
|
2089 | - } |
|
2090 | - $padding = $this->appendBytes($padding, $padlen, $padbuf); |
|
2091 | - } |
|
2092 | - return $this->appendBitstream($bstream, $padding); |
|
2093 | - } |
|
2094 | - |
|
2095 | - /** |
|
2096 | - * mergeBitStream |
|
2097 | - * @param array $bstream |
|
2098 | - * @return array bitstream |
|
2099 | - */ |
|
2100 | - protected function mergeBitStream($items) { |
|
2101 | - $items = $this->convertData($items); |
|
2102 | - $bstream = array(); |
|
2103 | - foreach ($items as $item) { |
|
2104 | - $bstream = $this->appendBitstream($bstream, $item['bstream']); |
|
2105 | - } |
|
2106 | - return $bstream; |
|
2107 | - } |
|
2108 | - |
|
2109 | - /** |
|
2110 | - * Returns a stream of bits. |
|
2111 | - * @param int $items |
|
2112 | - * @return array padded merged byte stream |
|
2113 | - */ |
|
2114 | - protected function getBitStream($items) { |
|
2115 | - $bstream = $this->mergeBitStream($items); |
|
2116 | - return $this->appendPaddingBit($bstream); |
|
2117 | - } |
|
2118 | - |
|
2119 | - /** |
|
2120 | - * Pack all bit streams padding bits into a byte array. |
|
2121 | - * @param int $items |
|
2122 | - * @return array padded merged byte stream |
|
2123 | - */ |
|
2124 | - protected function getByteStream($items) { |
|
2125 | - $bstream = $this->getBitStream($items); |
|
2126 | - return $this->bitstreamToByte($bstream); |
|
2127 | - } |
|
2128 | - |
|
2129 | - // - - - - - - - - - - - - - - - - - - - - - - - - - |
|
2130 | - |
|
2131 | - // QRbitstream |
|
2132 | - |
|
2133 | - /** |
|
2134 | - * Return an array with zeros |
|
2135 | - * @param int $setLength array size |
|
2136 | - * @return array |
|
2137 | - */ |
|
2138 | - protected function allocate($setLength) { |
|
2139 | - return array_fill(0, $setLength, 0); |
|
2140 | - } |
|
2141 | - |
|
2142 | - /** |
|
2143 | - * Return new bitstream from number |
|
2144 | - * @param int $bits number of bits |
|
2145 | - * @param int $num number |
|
2146 | - * @return array bitstream |
|
2147 | - */ |
|
2148 | - protected function newFromNum($bits, $num) { |
|
2149 | - $bstream = $this->allocate($bits); |
|
2150 | - $mask = 1 << ($bits - 1); |
|
2151 | - for ($i=0; $i<$bits; ++$i) { |
|
2152 | - if ($num & $mask) { |
|
2153 | - $bstream[$i] = 1; |
|
2154 | - } else { |
|
2155 | - $bstream[$i] = 0; |
|
2156 | - } |
|
2157 | - $mask = $mask >> 1; |
|
2158 | - } |
|
2159 | - return $bstream; |
|
2160 | - } |
|
2161 | - |
|
2162 | - /** |
|
2163 | - * Return new bitstream from bytes |
|
2164 | - * @param int $size size |
|
2165 | - * @param array $data bytes |
|
2166 | - * @return array bitstream |
|
2167 | - */ |
|
2168 | - protected function newFromBytes($size, $data) { |
|
2169 | - $bstream = $this->allocate($size * 8); |
|
2170 | - $p=0; |
|
2171 | - for ($i=0; $i<$size; ++$i) { |
|
2172 | - $mask = 0x80; |
|
2173 | - for ($j=0; $j<8; ++$j) { |
|
2174 | - if ($data[$i] & $mask) { |
|
2175 | - $bstream[$p] = 1; |
|
2176 | - } else { |
|
2177 | - $bstream[$p] = 0; |
|
2178 | - } |
|
2179 | - $p++; |
|
2180 | - $mask = $mask >> 1; |
|
2181 | - } |
|
2182 | - } |
|
2183 | - return $bstream; |
|
2184 | - } |
|
2185 | - |
|
2186 | - /** |
|
2187 | - * Append one bitstream to another |
|
2188 | - * @param array $bitstream original bitstream |
|
2189 | - * @param array $append bitstream to append |
|
2190 | - * @return array bitstream |
|
2191 | - */ |
|
2192 | - protected function appendBitstream($bitstream, $append) { |
|
2193 | - if ((!is_array($append)) or (count($append) == 0)) { |
|
2194 | - return $bitstream; |
|
2195 | - } |
|
2196 | - if (count($bitstream) == 0) { |
|
2197 | - return $append; |
|
2198 | - } |
|
2199 | - return array_values(array_merge($bitstream, $append)); |
|
2200 | - } |
|
2201 | - |
|
2202 | - /** |
|
2203 | - * Append one bitstream created from number to another |
|
2204 | - * @param array $bitstream original bitstream |
|
2205 | - * @param int $bits number of bits |
|
2206 | - * @param int $num number |
|
2207 | - * @return array bitstream |
|
2208 | - */ |
|
2209 | - protected function appendNum($bitstream, $bits, $num) { |
|
2210 | - if ($bits == 0) { |
|
2211 | - return 0; |
|
2212 | - } |
|
2213 | - $b = $this->newFromNum($bits, $num); |
|
2214 | - return $this->appendBitstream($bitstream, $b); |
|
2215 | - } |
|
2216 | - |
|
2217 | - /** |
|
2218 | - * Append one bitstream created from bytes to another |
|
2219 | - * @param array $bitstream original bitstream |
|
2220 | - * @param int $size size |
|
2221 | - * @param array $data bytes |
|
2222 | - * @return array bitstream |
|
2223 | - */ |
|
2224 | - protected function appendBytes($bitstream, $size, $data) { |
|
2225 | - if ($size == 0) { |
|
2226 | - return 0; |
|
2227 | - } |
|
2228 | - $b = $this->newFromBytes($size, $data); |
|
2229 | - return $this->appendBitstream($bitstream, $b); |
|
2230 | - } |
|
2231 | - |
|
2232 | - /** |
|
2233 | - * Convert bitstream to bytes |
|
2234 | - * @param array $bitstream original bitstream |
|
2235 | - * @return array of bytes |
|
2236 | - */ |
|
2237 | - protected function bitstreamToByte($bstream) { |
|
2238 | - $size = count($bstream); |
|
2239 | - if ($size == 0) { |
|
2240 | - return array(); |
|
2241 | - } |
|
2242 | - $data = array_fill(0, (int)(($size + 7) / 8), 0); |
|
2243 | - $bytes = (int)($size / 8); |
|
2244 | - $p = 0; |
|
2245 | - for ($i=0; $i<$bytes; $i++) { |
|
2246 | - $v = 0; |
|
2247 | - for ($j=0; $j<8; $j++) { |
|
2248 | - $v = $v << 1; |
|
2249 | - $v |= $bstream[$p]; |
|
2250 | - $p++; |
|
2251 | - } |
|
2252 | - $data[$i] = $v; |
|
2253 | - } |
|
2254 | - if ($size & 7) { |
|
2255 | - $v = 0; |
|
2256 | - for ($j=0; $j<($size & 7); $j++) { |
|
2257 | - $v = $v << 1; |
|
2258 | - $v |= $bstream[$p]; |
|
2259 | - $p++; |
|
2260 | - } |
|
2261 | - $data[$bytes] = $v; |
|
2262 | - } |
|
2263 | - return $data; |
|
2264 | - } |
|
2265 | - |
|
2266 | - // - - - - - - - - - - - - - - - - - - - - - - - - - |
|
2267 | - |
|
2268 | - // QRspec |
|
2269 | - |
|
2270 | - /** |
|
2271 | - * Replace a value on the array at the specified position |
|
2272 | - * @param array $srctab |
|
2273 | - * @param int $x X position |
|
2274 | - * @param int $y Y position |
|
2275 | - * @param string $repl value to replace |
|
2276 | - * @param int $replLen length of the repl string |
|
2277 | - * @return array srctab |
|
2278 | - */ |
|
2279 | - protected function qrstrset($srctab, $x, $y, $repl, $replLen=false) { |
|
2280 | - $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl)); |
|
2281 | - return $srctab; |
|
2282 | - } |
|
2283 | - |
|
2284 | - /** |
|
2285 | - * Return maximum data code length (bytes) for the version. |
|
2286 | - * @param int $version version |
|
2287 | - * @param int $level error correction level |
|
2288 | - * @return int maximum size (bytes) |
|
2289 | - */ |
|
2290 | - protected function getDataLength($version, $level) { |
|
2291 | - return $this->capacity[$version][QRCAP_WORDS] - $this->capacity[$version][QRCAP_EC][$level]; |
|
2292 | - } |
|
2293 | - |
|
2294 | - /** |
|
2295 | - * Return maximum error correction code length (bytes) for the version. |
|
2296 | - * @param int $version version |
|
2297 | - * @param int $level error correction level |
|
2298 | - * @return int ECC size (bytes) |
|
2299 | - */ |
|
2300 | - protected function getECCLength($version, $level){ |
|
2301 | - return $this->capacity[$version][QRCAP_EC][$level]; |
|
2302 | - } |
|
2303 | - |
|
2304 | - /** |
|
2305 | - * Return the width of the symbol for the version. |
|
2306 | - * @param int $version version |
|
2307 | - * @return int width |
|
2308 | - */ |
|
2309 | - protected function getWidth($version) { |
|
2310 | - return $this->capacity[$version][QRCAP_WIDTH]; |
|
2311 | - } |
|
2312 | - |
|
2313 | - /** |
|
2314 | - * Return the numer of remainder bits. |
|
2315 | - * @param int $version version |
|
2316 | - * @return int number of remainder bits |
|
2317 | - */ |
|
2318 | - protected function getRemainder($version) { |
|
2319 | - return $this->capacity[$version][QRCAP_REMINDER]; |
|
2320 | - } |
|
2321 | - |
|
2322 | - /** |
|
2323 | - * Return a version number that satisfies the input code length. |
|
2324 | - * @param int $size input code length (byte) |
|
2325 | - * @param int $level error correction level |
|
2326 | - * @return int version number |
|
2327 | - */ |
|
2328 | - protected function getMinimumVersion($size, $level) { |
|
2329 | - for ($i=1; $i <= QRSPEC_VERSION_MAX; ++$i) { |
|
2330 | - $words = $this->capacity[$i][QRCAP_WORDS] - $this->capacity[$i][QRCAP_EC][$level]; |
|
2331 | - if ($words >= $size) { |
|
2332 | - return $i; |
|
2333 | - } |
|
2334 | - } |
|
2335 | - return -1; |
|
2336 | - } |
|
2337 | - |
|
2338 | - /** |
|
2339 | - * Return the size of length indicator for the mode and version. |
|
2340 | - * @param int $mode encoding mode |
|
2341 | - * @param int $version version |
|
2342 | - * @return int the size of the appropriate length indicator (bits). |
|
2343 | - */ |
|
2344 | - protected function lengthIndicator($mode, $version) { |
|
2345 | - if ($mode == QR_MODE_ST) { |
|
2346 | - return 0; |
|
2347 | - } |
|
2348 | - if ($version <= 9) { |
|
2349 | - $l = 0; |
|
2350 | - } elseif ($version <= 26) { |
|
2351 | - $l = 1; |
|
2352 | - } else { |
|
2353 | - $l = 2; |
|
2354 | - } |
|
2355 | - return $this->lengthTableBits[$mode][$l]; |
|
2356 | - } |
|
2357 | - |
|
2358 | - /** |
|
2359 | - * Return the maximum length for the mode and version. |
|
2360 | - * @param int $mode encoding mode |
|
2361 | - * @param int $version version |
|
2362 | - * @return int the maximum length (bytes) |
|
2363 | - */ |
|
2364 | - protected function maximumWords($mode, $version) { |
|
2365 | - if ($mode == QR_MODE_ST) { |
|
2366 | - return 3; |
|
2367 | - } |
|
2368 | - if ($version <= 9) { |
|
2369 | - $l = 0; |
|
2370 | - } else if ($version <= 26) { |
|
2371 | - $l = 1; |
|
2372 | - } else { |
|
2373 | - $l = 2; |
|
2374 | - } |
|
2375 | - $bits = $this->lengthTableBits[$mode][$l]; |
|
2376 | - $words = (1 << $bits) - 1; |
|
2377 | - if ($mode == QR_MODE_KJ) { |
|
2378 | - $words *= 2; // the number of bytes is required |
|
2379 | - } |
|
2380 | - return $words; |
|
2381 | - } |
|
2382 | - |
|
2383 | - /** |
|
2384 | - * Return an array of ECC specification. |
|
2385 | - * @param int $version version |
|
2386 | - * @param int $level error correction level |
|
2387 | - * @param array $spec an array of ECC specification contains as following: {# of type1 blocks, # of data code, # of ecc code, # of type2 blocks, # of data code} |
|
2388 | - * @return array spec |
|
2389 | - */ |
|
2390 | - protected function getEccSpec($version, $level, $spec) { |
|
2391 | - if (count($spec) < 5) { |
|
2392 | - $spec = array(0, 0, 0, 0, 0); |
|
2393 | - } |
|
2394 | - $b1 = $this->eccTable[$version][$level][0]; |
|
2395 | - $b2 = $this->eccTable[$version][$level][1]; |
|
2396 | - $data = $this->getDataLength($version, $level); |
|
2397 | - $ecc = $this->getECCLength($version, $level); |
|
2398 | - if ($b2 == 0) { |
|
2399 | - $spec[0] = $b1; |
|
2400 | - $spec[1] = (int)($data / $b1); |
|
2401 | - $spec[2] = (int)($ecc / $b1); |
|
2402 | - $spec[3] = 0; |
|
2403 | - $spec[4] = 0; |
|
2404 | - } else { |
|
2405 | - $spec[0] = $b1; |
|
2406 | - $spec[1] = (int)($data / ($b1 + $b2)); |
|
2407 | - $spec[2] = (int)($ecc / ($b1 + $b2)); |
|
2408 | - $spec[3] = $b2; |
|
2409 | - $spec[4] = $spec[1] + 1; |
|
2410 | - } |
|
2411 | - return $spec; |
|
2412 | - } |
|
2413 | - |
|
2414 | - /** |
|
2415 | - * Put an alignment marker. |
|
2416 | - * @param array $frame frame |
|
2417 | - * @param int $width width |
|
2418 | - * @param int $ox X center coordinate of the pattern |
|
2419 | - * @param int $oy Y center coordinate of the pattern |
|
2420 | - * @return array frame |
|
2421 | - */ |
|
2422 | - protected function putAlignmentMarker($frame, $ox, $oy) { |
|
2423 | - $finder = array( |
|
2424 | - "\xa1\xa1\xa1\xa1\xa1", |
|
2425 | - "\xa1\xa0\xa0\xa0\xa1", |
|
2426 | - "\xa1\xa0\xa1\xa0\xa1", |
|
2427 | - "\xa1\xa0\xa0\xa0\xa1", |
|
2428 | - "\xa1\xa1\xa1\xa1\xa1" |
|
2429 | - ); |
|
2430 | - $yStart = $oy - 2; |
|
2431 | - $xStart = $ox - 2; |
|
2432 | - for ($y=0; $y < 5; $y++) { |
|
2433 | - $frame = $this->qrstrset($frame, $xStart, $yStart+$y, $finder[$y]); |
|
2434 | - } |
|
2435 | - return $frame; |
|
2436 | - } |
|
2437 | - |
|
2438 | - /** |
|
2439 | - * Put an alignment pattern. |
|
2440 | - * @param int $version version |
|
2441 | - * @param array $fram frame |
|
2442 | - * @param int $width width |
|
2443 | - * @return array frame |
|
2444 | - */ |
|
2445 | - protected function putAlignmentPattern($version, $frame, $width) { |
|
2446 | - if ($version < 2) { |
|
2447 | - return $frame; |
|
2448 | - } |
|
2449 | - $d = $this->alignmentPattern[$version][1] - $this->alignmentPattern[$version][0]; |
|
2450 | - if ($d < 0) { |
|
2451 | - $w = 2; |
|
2452 | - } else { |
|
2453 | - $w = (int)(($width - $this->alignmentPattern[$version][0]) / $d + 2); |
|
2454 | - } |
|
2455 | - if ($w * $w - 3 == 1) { |
|
2456 | - $x = $this->alignmentPattern[$version][0]; |
|
2457 | - $y = $this->alignmentPattern[$version][0]; |
|
2458 | - $frame = $this->putAlignmentMarker($frame, $x, $y); |
|
2459 | - return $frame; |
|
2460 | - } |
|
2461 | - $cx = $this->alignmentPattern[$version][0]; |
|
2462 | - $wo = $w - 1; |
|
2463 | - for ($x=1; $x < $wo; ++$x) { |
|
2464 | - $frame = $this->putAlignmentMarker($frame, 6, $cx); |
|
2465 | - $frame = $this->putAlignmentMarker($frame, $cx, 6); |
|
2466 | - $cx += $d; |
|
2467 | - } |
|
2468 | - $cy = $this->alignmentPattern[$version][0]; |
|
2469 | - for ($y=0; $y < $wo; ++$y) { |
|
2470 | - $cx = $this->alignmentPattern[$version][0]; |
|
2471 | - for ($x=0; $x < $wo; ++$x) { |
|
2472 | - $frame = $this->putAlignmentMarker($frame, $cx, $cy); |
|
2473 | - $cx += $d; |
|
2474 | - } |
|
2475 | - $cy += $d; |
|
2476 | - } |
|
2477 | - return $frame; |
|
2478 | - } |
|
2479 | - |
|
2480 | - /** |
|
2481 | - * Return BCH encoded version information pattern that is used for the symbol of version 7 or greater. Use lower 18 bits. |
|
2482 | - * @param int $version version |
|
2483 | - * @return BCH encoded version information pattern |
|
2484 | - */ |
|
2485 | - protected function getVersionPattern($version) { |
|
2486 | - if (($version < 7) or ($version > QRSPEC_VERSION_MAX)) { |
|
2487 | - return 0; |
|
2488 | - } |
|
2489 | - return $this->versionPattern[($version - 7)]; |
|
2490 | - } |
|
2491 | - |
|
2492 | - /** |
|
2493 | - * Return BCH encoded format information pattern. |
|
2494 | - * @param array $mask |
|
2495 | - * @param int $level error correction level |
|
2496 | - * @return BCH encoded format information pattern |
|
2497 | - */ |
|
2498 | - protected function getFormatInfo($mask, $level) { |
|
2499 | - if (($mask < 0) or ($mask > 7)) { |
|
2500 | - return 0; |
|
2501 | - } |
|
2502 | - if (($level < 0) or ($level > 3)) { |
|
2503 | - return 0; |
|
2504 | - } |
|
2505 | - return $this->formatInfo[$level][$mask]; |
|
2506 | - } |
|
2507 | - |
|
2508 | - /** |
|
2509 | - * Put a finder pattern. |
|
2510 | - * @param array $frame frame |
|
2511 | - * @param int $width width |
|
2512 | - * @param int $ox X center coordinate of the pattern |
|
2513 | - * @param int $oy Y center coordinate of the pattern |
|
2514 | - * @return array frame |
|
2515 | - */ |
|
2516 | - protected function putFinderPattern($frame, $ox, $oy) { |
|
2517 | - $finder = array( |
|
2518 | - "\xc1\xc1\xc1\xc1\xc1\xc1\xc1", |
|
2519 | - "\xc1\xc0\xc0\xc0\xc0\xc0\xc1", |
|
2520 | - "\xc1\xc0\xc1\xc1\xc1\xc0\xc1", |
|
2521 | - "\xc1\xc0\xc1\xc1\xc1\xc0\xc1", |
|
2522 | - "\xc1\xc0\xc1\xc1\xc1\xc0\xc1", |
|
2523 | - "\xc1\xc0\xc0\xc0\xc0\xc0\xc1", |
|
2524 | - "\xc1\xc1\xc1\xc1\xc1\xc1\xc1" |
|
2525 | - ); |
|
2526 | - for ($y=0; $y < 7; $y++) { |
|
2527 | - $frame = $this->qrstrset($frame, $ox, ($oy + $y), $finder[$y]); |
|
2528 | - } |
|
2529 | - return $frame; |
|
2530 | - } |
|
2531 | - |
|
2532 | - /** |
|
2533 | - * Return a copy of initialized frame. |
|
2534 | - * @param int $version version |
|
2535 | - * @return Array of unsigned char. |
|
2536 | - */ |
|
2537 | - protected function createFrame($version) { |
|
2538 | - $width = $this->capacity[$version][QRCAP_WIDTH]; |
|
2539 | - $frameLine = str_repeat ("\0", $width); |
|
2540 | - $frame = array_fill(0, $width, $frameLine); |
|
2541 | - // Finder pattern |
|
2542 | - $frame = $this->putFinderPattern($frame, 0, 0); |
|
2543 | - $frame = $this->putFinderPattern($frame, $width - 7, 0); |
|
2544 | - $frame = $this->putFinderPattern($frame, 0, $width - 7); |
|
2545 | - // Separator |
|
2546 | - $yOffset = $width - 7; |
|
2547 | - for ($y=0; $y < 7; ++$y) { |
|
2548 | - $frame[$y][7] = "\xc0"; |
|
2549 | - $frame[$y][$width - 8] = "\xc0"; |
|
2550 | - $frame[$yOffset][7] = "\xc0"; |
|
2551 | - ++$yOffset; |
|
2552 | - } |
|
2553 | - $setPattern = str_repeat("\xc0", 8); |
|
2554 | - $frame = $this->qrstrset($frame, 0, 7, $setPattern); |
|
2555 | - $frame = $this->qrstrset($frame, $width-8, 7, $setPattern); |
|
2556 | - $frame = $this->qrstrset($frame, 0, $width - 8, $setPattern); |
|
2557 | - // Format info |
|
2558 | - $setPattern = str_repeat("\x84", 9); |
|
2559 | - $frame = $this->qrstrset($frame, 0, 8, $setPattern); |
|
2560 | - $frame = $this->qrstrset($frame, $width - 8, 8, $setPattern, 8); |
|
2561 | - $yOffset = $width - 8; |
|
2562 | - for ($y=0; $y < 8; ++$y,++$yOffset) { |
|
2563 | - $frame[$y][8] = "\x84"; |
|
2564 | - $frame[$yOffset][8] = "\x84"; |
|
2565 | - } |
|
2566 | - // Timing pattern |
|
2567 | - $wo = $width - 15; |
|
2568 | - for ($i=1; $i < $wo; ++$i) { |
|
2569 | - $frame[6][7+$i] = chr(0x90 | ($i & 1)); |
|
2570 | - $frame[7+$i][6] = chr(0x90 | ($i & 1)); |
|
2571 | - } |
|
2572 | - // Alignment pattern |
|
2573 | - $frame = $this->putAlignmentPattern($version, $frame, $width); |
|
2574 | - // Version information |
|
2575 | - if ($version >= 7) { |
|
2576 | - $vinf = $this->getVersionPattern($version); |
|
2577 | - $v = $vinf; |
|
2578 | - for ($x=0; $x<6; ++$x) { |
|
2579 | - for ($y=0; $y<3; ++$y) { |
|
2580 | - $frame[($width - 11)+$y][$x] = chr(0x88 | ($v & 1)); |
|
2581 | - $v = $v >> 1; |
|
2582 | - } |
|
2583 | - } |
|
2584 | - $v = $vinf; |
|
2585 | - for ($y=0; $y<6; ++$y) { |
|
2586 | - for ($x=0; $x<3; ++$x) { |
|
2587 | - $frame[$y][$x+($width - 11)] = chr(0x88 | ($v & 1)); |
|
2588 | - $v = $v >> 1; |
|
2589 | - } |
|
2590 | - } |
|
2591 | - } |
|
2592 | - // and a little bit... |
|
2593 | - $frame[$width - 8][8] = "\x81"; |
|
2594 | - return $frame; |
|
2595 | - } |
|
2596 | - |
|
2597 | - /** |
|
2598 | - * Set new frame for the specified version. |
|
2599 | - * @param int $version version |
|
2600 | - * @return Array of unsigned char. |
|
2601 | - */ |
|
2602 | - protected function newFrame($version) { |
|
2603 | - if (($version < 1) or ($version > QRSPEC_VERSION_MAX)) { |
|
2604 | - return null; |
|
2605 | - } |
|
2606 | - if (!isset($this->frames[$version])) { |
|
2607 | - $this->frames[$version] = $this->createFrame($version); |
|
2608 | - } |
|
2609 | - if (is_null($this->frames[$version])) { |
|
2610 | - return null; |
|
2611 | - } |
|
2612 | - return $this->frames[$version]; |
|
2613 | - } |
|
2614 | - |
|
2615 | - /** |
|
2616 | - * Return block number 0 |
|
2617 | - * @param array $spec |
|
2618 | - * @return int value |
|
2619 | - */ |
|
2620 | - protected function rsBlockNum($spec) { |
|
2621 | - return ($spec[0] + $spec[3]); |
|
2622 | - } |
|
2623 | - |
|
2624 | - /** |
|
2625 | - * Return block number 1 |
|
2626 | - * @param array $spec |
|
2627 | - * @return int value |
|
2628 | - */ |
|
2629 | - protected function rsBlockNum1($spec) { |
|
2630 | - return $spec[0]; |
|
2631 | - } |
|
2632 | - |
|
2633 | - /** |
|
2634 | - * Return data codes 1 |
|
2635 | - * @param array $spec |
|
2636 | - * @return int value |
|
2637 | - */ |
|
2638 | - protected function rsDataCodes1($spec) { |
|
2639 | - return $spec[1]; |
|
2640 | - } |
|
2641 | - |
|
2642 | - /** |
|
2643 | - * Return ecc codes 1 |
|
2644 | - * @param array $spec |
|
2645 | - * @return int value |
|
2646 | - */ |
|
2647 | - protected function rsEccCodes1($spec) { |
|
2648 | - return $spec[2]; |
|
2649 | - } |
|
2650 | - |
|
2651 | - /** |
|
2652 | - * Return block number 2 |
|
2653 | - * @param array $spec |
|
2654 | - * @return int value |
|
2655 | - */ |
|
2656 | - protected function rsBlockNum2($spec) { |
|
2657 | - return $spec[3]; |
|
2658 | - } |
|
2659 | - |
|
2660 | - /** |
|
2661 | - * Return data codes 2 |
|
2662 | - * @param array $spec |
|
2663 | - * @return int value |
|
2664 | - */ |
|
2665 | - protected function rsDataCodes2($spec) { |
|
2666 | - return $spec[4]; |
|
2667 | - } |
|
2668 | - |
|
2669 | - /** |
|
2670 | - * Return ecc codes 2 |
|
2671 | - * @param array $spec |
|
2672 | - * @return int value |
|
2673 | - */ |
|
2674 | - protected function rsEccCodes2($spec) { |
|
2675 | - return $spec[2]; |
|
2676 | - } |
|
2677 | - |
|
2678 | - /** |
|
2679 | - * Return data length |
|
2680 | - * @param array $spec |
|
2681 | - * @return int value |
|
2682 | - */ |
|
2683 | - protected function rsDataLength($spec) { |
|
2684 | - return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]); |
|
2685 | - } |
|
2686 | - |
|
2687 | - /** |
|
2688 | - * Return ecc length |
|
2689 | - * @param array $spec |
|
2690 | - * @return int value |
|
2691 | - */ |
|
2692 | - protected function rsEccLength($spec) { |
|
2693 | - return ($spec[0] + $spec[3]) * $spec[2]; |
|
2694 | - } |
|
2695 | - |
|
2696 | - // - - - - - - - - - - - - - - - - - - - - - - - - - |
|
2697 | - |
|
2698 | - // QRrs |
|
2699 | - |
|
2700 | - /** |
|
2701 | - * Initialize a Reed-Solomon codec and add it to existing rsitems |
|
2702 | - * @param int $symsize symbol size, bits |
|
2703 | - * @param int $gfpoly Field generator polynomial coefficients |
|
2704 | - * @param int $fcr first root of RS code generator polynomial, index form |
|
2705 | - * @param int $prim primitive element to generate polynomial roots |
|
2706 | - * @param int $nroots RS code generator polynomial degree (number of roots) |
|
2707 | - * @param int $pad padding bytes at front of shortened block |
|
2708 | - * @return array Array of RS values:<ul><li>mm = Bits per symbol;</li><li>nn = Symbols per block;</li><li>alpha_to = log lookup table array;</li><li>index_of = Antilog lookup table array;</li><li>genpoly = Generator polynomial array;</li><li>nroots = Number of generator;</li><li>roots = number of parity symbols;</li><li>fcr = First consecutive root, index form;</li><li>prim = Primitive element, index form;</li><li>iprim = prim-th root of 1, index form;</li><li>pad = Padding bytes in shortened block;</li><li>gfpoly</ul>. |
|
2709 | - */ |
|
2710 | - protected function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) { |
|
2711 | - foreach ($this->rsitems as $rs) { |
|
2712 | - if (($rs['pad'] != $pad) or ($rs['nroots'] != $nroots) or ($rs['mm'] != $symsize) |
|
2713 | - or ($rs['gfpoly'] != $gfpoly) or ($rs['fcr'] != $fcr) or ($rs['prim'] != $prim)) { |
|
2714 | - continue; |
|
2715 | - } |
|
2716 | - return $rs; |
|
2717 | - } |
|
2718 | - $rs = $this->init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad); |
|
2719 | - array_unshift($this->rsitems, $rs); |
|
2720 | - return $rs; |
|
2721 | - } |
|
2722 | - |
|
2723 | - // - - - - - - - - - - - - - - - - - - - - - - - - - |
|
2724 | - |
|
2725 | - // QRrsItem |
|
2726 | - |
|
2727 | - /** |
|
2728 | - * modnn |
|
2729 | - * @param array RS values |
|
2730 | - * @param int $x X position |
|
2731 | - * @return int X osition |
|
2732 | - */ |
|
2733 | - protected function modnn($rs, $x) { |
|
2734 | - while ($x >= $rs['nn']) { |
|
2735 | - $x -= $rs['nn']; |
|
2736 | - $x = ($x >> $rs['mm']) + ($x & $rs['nn']); |
|
2737 | - } |
|
2738 | - return $x; |
|
2739 | - } |
|
2740 | - |
|
2741 | - /** |
|
2742 | - * Initialize a Reed-Solomon codec and returns an array of values. |
|
2743 | - * @param int $symsize symbol size, bits |
|
2744 | - * @param int $gfpoly Field generator polynomial coefficients |
|
2745 | - * @param int $fcr first root of RS code generator polynomial, index form |
|
2746 | - * @param int $prim primitive element to generate polynomial roots |
|
2747 | - * @param int $nroots RS code generator polynomial degree (number of roots) |
|
2748 | - * @param int $pad padding bytes at front of shortened block |
|
2749 | - * @return array Array of RS values:<ul><li>mm = Bits per symbol;</li><li>nn = Symbols per block;</li><li>alpha_to = log lookup table array;</li><li>index_of = Antilog lookup table array;</li><li>genpoly = Generator polynomial array;</li><li>nroots = Number of generator;</li><li>roots = number of parity symbols;</li><li>fcr = First consecutive root, index form;</li><li>prim = Primitive element, index form;</li><li>iprim = prim-th root of 1, index form;</li><li>pad = Padding bytes in shortened block;</li><li>gfpoly</ul>. |
|
2750 | - */ |
|
2751 | - protected function init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) { |
|
2752 | - // Based on Reed solomon encoder by Phil Karn, KA9Q (GNU-LGPLv2) |
|
2753 | - $rs = null; |
|
2754 | - // Check parameter ranges |
|
2755 | - if (($symsize < 0) or ($symsize > 8)) { |
|
2756 | - return $rs; |
|
2757 | - } |
|
2758 | - if (($fcr < 0) or ($fcr >= (1<<$symsize))) { |
|
2759 | - return $rs; |
|
2760 | - } |
|
2761 | - if (($prim <= 0) or ($prim >= (1<<$symsize))) { |
|
2762 | - return $rs; |
|
2763 | - } |
|
2764 | - if (($nroots < 0) or ($nroots >= (1<<$symsize))) { |
|
2765 | - return $rs; |
|
2766 | - } |
|
2767 | - if (($pad < 0) or ($pad >= ((1<<$symsize) -1 - $nroots))) { |
|
2768 | - return $rs; |
|
2769 | - } |
|
2770 | - $rs = array(); |
|
2771 | - $rs['mm'] = $symsize; |
|
2772 | - $rs['nn'] = (1 << $symsize) - 1; |
|
2773 | - $rs['pad'] = $pad; |
|
2774 | - $rs['alpha_to'] = array_fill(0, ($rs['nn'] + 1), 0); |
|
2775 | - $rs['index_of'] = array_fill(0, ($rs['nn'] + 1), 0); |
|
2776 | - // PHP style macro replacement ;) |
|
2777 | - $NN =& $rs['nn']; |
|
2778 | - $A0 =& $NN; |
|
2779 | - // Generate Galois field lookup tables |
|
2780 | - $rs['index_of'][0] = $A0; // log(zero) = -inf |
|
2781 | - $rs['alpha_to'][$A0] = 0; // alpha**-inf = 0 |
|
2782 | - $sr = 1; |
|
2783 | - for ($i=0; $i<$rs['nn']; ++$i) { |
|
2784 | - $rs['index_of'][$sr] = $i; |
|
2785 | - $rs['alpha_to'][$i] = $sr; |
|
2786 | - $sr <<= 1; |
|
2787 | - if ($sr & (1 << $symsize)) { |
|
2788 | - $sr ^= $gfpoly; |
|
2789 | - } |
|
2790 | - $sr &= $rs['nn']; |
|
2791 | - } |
|
2792 | - if ($sr != 1) { |
|
2793 | - // field generator polynomial is not primitive! |
|
2794 | - return null; |
|
2795 | - } |
|
2796 | - // Form RS code generator polynomial from its roots |
|
2797 | - $rs['genpoly'] = array_fill(0, ($nroots + 1), 0); |
|
2798 | - $rs['fcr'] = $fcr; |
|
2799 | - $rs['prim'] = $prim; |
|
2800 | - $rs['nroots'] = $nroots; |
|
2801 | - $rs['gfpoly'] = $gfpoly; |
|
2802 | - // Find prim-th root of 1, used in decoding |
|
2803 | - for ($iprim=1; ($iprim % $prim) != 0; $iprim += $rs['nn']) { |
|
2804 | - ; // intentional empty-body loop! |
|
2805 | - } |
|
2806 | - $rs['iprim'] = (int)($iprim / $prim); |
|
2807 | - $rs['genpoly'][0] = 1; |
|
2808 | - |
|
2809 | - |
|
2810 | - for ($i = 0,$root=$fcr*$prim; $i < $nroots; $i++, $root += $prim) { |
|
2811 | - $rs['genpoly'][$i+1] = 1; |
|
2812 | - // Multiply rs->genpoly[] by @**(root + x) |
|
2813 | - for ($j = $i; $j > 0; --$j) { |
|
2814 | - if ($rs['genpoly'][$j] != 0) { |
|
2815 | - $rs['genpoly'][$j] = $rs['genpoly'][$j-1] ^ $rs['alpha_to'][$this->modnn($rs, $rs['index_of'][$rs['genpoly'][$j]] + $root)]; |
|
2816 | - } else { |
|
2817 | - $rs['genpoly'][$j] = $rs['genpoly'][$j-1]; |
|
2818 | - } |
|
2819 | - } |
|
2820 | - // rs->genpoly[0] can never be zero |
|
2821 | - $rs['genpoly'][0] = $rs['alpha_to'][$this->modnn($rs, $rs['index_of'][$rs['genpoly'][0]] + $root)]; |
|
2822 | - } |
|
2823 | - // convert rs->genpoly[] to index form for quicker encoding |
|
2824 | - for ($i = 0; $i <= $nroots; ++$i) { |
|
2825 | - $rs['genpoly'][$i] = $rs['index_of'][$rs['genpoly'][$i]]; |
|
2826 | - } |
|
2827 | - return $rs; |
|
2828 | - } |
|
2829 | - |
|
2830 | - /** |
|
2831 | - * Encode a Reed-Solomon codec and returns the parity array |
|
2832 | - * @param array $rs RS values |
|
2833 | - * @param array $data data |
|
2834 | - * @param array $parity parity |
|
2835 | - * @return parity array |
|
2836 | - */ |
|
2837 | - protected function encode_rs_char($rs, $data, $parity) { |
|
2838 | - $MM =& $rs['mm']; // bits per symbol |
|
2839 | - $NN =& $rs['nn']; // the total number of symbols in a RS block |
|
2840 | - $ALPHA_TO =& $rs['alpha_to']; // the address of an array of NN elements to convert Galois field elements in index (log) form to polynomial form |
|
2841 | - $INDEX_OF =& $rs['index_of']; // the address of an array of NN elements to convert Galois field elements in polynomial form to index (log) form |
|
2842 | - $GENPOLY =& $rs['genpoly']; // an array of NROOTS+1 elements containing the generator polynomial in index form |
|
2843 | - $NROOTS =& $rs['nroots']; // the number of roots in the RS code generator polynomial, which is the same as the number of parity symbols in a block |
|
2844 | - $FCR =& $rs['fcr']; // first consecutive root, index form |
|
2845 | - $PRIM =& $rs['prim']; // primitive element, index form |
|
2846 | - $IPRIM =& $rs['iprim']; // prim-th root of 1, index form |
|
2847 | - $PAD =& $rs['pad']; // the number of pad symbols in a block |
|
2848 | - $A0 =& $NN; |
|
2849 | - $parity = array_fill(0, $NROOTS, 0); |
|
2850 | - for ($i=0; $i < ($NN - $NROOTS - $PAD); $i++) { |
|
2851 | - $feedback = $INDEX_OF[$data[$i] ^ $parity[0]]; |
|
2852 | - if ($feedback != $A0) { |
|
2853 | - // feedback term is non-zero |
|
2854 | - // This line is unnecessary when GENPOLY[NROOTS] is unity, as it must |
|
2855 | - // always be for the polynomials constructed by init_rs() |
|
2856 | - $feedback = $this->modnn($rs, $NN - $GENPOLY[$NROOTS] + $feedback); |
|
2857 | - for ($j=1; $j < $NROOTS; ++$j) { |
|
2858 | - $parity[$j] ^= $ALPHA_TO[$this->modnn($rs, $feedback + $GENPOLY[($NROOTS - $j)])]; |
|
2859 | - } |
|
2860 | - } |
|
2861 | - // Shift |
|
2862 | - array_shift($parity); |
|
2863 | - if ($feedback != $A0) { |
|
2864 | - array_push($parity, $ALPHA_TO[$this->modnn($rs, $feedback + $GENPOLY[0])]); |
|
2865 | - } else { |
|
2866 | - array_push($parity, 0); |
|
2867 | - } |
|
2868 | - } |
|
2869 | - return $parity; |
|
2870 | - } |
|
2871 | - |
|
2872 | - } // end QRcode class |
|
265 | + // for compaibility with PHP4 |
|
266 | + if (!function_exists('str_split')) { |
|
267 | + /** |
|
268 | + * Convert a string to an array (needed for PHP4 compatibility) |
|
269 | + * @param string $string The input string. |
|
270 | + * @param int $split_length Maximum length of the chunk. |
|
271 | + * @return If the optional split_length parameter is specified, the returned array will be broken down into chunks with each being split_length in length, otherwise each chunk will be one character in length. FALSE is returned if split_length is less than 1. If the split_length length exceeds the length of string , the entire string is returned as the first (and only) array element. |
|
272 | + */ |
|
273 | + function str_split($string, $split_length=1) { |
|
274 | + if ((strlen($string) > $split_length) or (!$split_length)) { |
|
275 | + do { |
|
276 | + $c = strlen($string); |
|
277 | + $parts[] = substr($string, 0, $split_length); |
|
278 | + $string = substr($string, $split_length); |
|
279 | + } while ($string !== false); |
|
280 | + } else { |
|
281 | + $parts = array($string); |
|
282 | + } |
|
283 | + return $parts; |
|
284 | + } |
|
285 | + } |
|
286 | + |
|
287 | + // ##################################################### |
|
288 | + |
|
289 | + /** |
|
290 | + * Class to create QR-code arrays for TCPDF class. |
|
291 | + * QR Code symbol is a 2D barcode that can be scanned by handy terminals such as a mobile phone with CCD. |
|
292 | + * The capacity of QR Code is up to 7000 digits or 4000 characters, and has high robustness. |
|
293 | + * This class supports QR Code model 2, described in JIS (Japanese Industrial Standards) X0510:2004 or ISO/IEC 18004. |
|
294 | + * Currently the following features are not supported: ECI and FNC1 mode, Micro QR Code, QR Code model 1, Structured mode. |
|
295 | + * |
|
296 | + * This class is derived from "PHP QR Code encoder" by Dominik Dzienia (http://phpqrcode.sourceforge.net/) based on "libqrencode C library 3.1.1." by Kentaro Fukuchi (http://megaui.net/fukuchi/works/qrencode/index.en.html), contains Reed-Solomon code written by Phil Karn, KA9Q. QR Code is registered trademark of DENSO WAVE INCORPORATED (http://www.denso-wave.com/qrcode/index-e.html). |
|
297 | + * Please read comments on this class source file for full copyright and license information. |
|
298 | + * |
|
299 | + * @name QRcode |
|
300 | + * @package com.tecnick.tcpdf |
|
301 | + * @abstract Class for generating QR-code array for TCPDF. |
|
302 | + * @author Nicola Asuni |
|
303 | + * @copyright 2010 Nicola Asuni - Tecnick.com S.r.l (www.tecnick.com) Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - [email protected] |
|
304 | + * @link http://www.tcpdf.org |
|
305 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL |
|
306 | + * @version 1.0.002 |
|
307 | + */ |
|
308 | + class QRcode { |
|
309 | + |
|
310 | + /** |
|
311 | + * @var barcode array to be returned which is readable by TCPDF |
|
312 | + * @access protected |
|
313 | + */ |
|
314 | + protected $barcode_array = array(); |
|
315 | + |
|
316 | + /** |
|
317 | + * @var QR code version. Size of QRcode is defined as version. Version is from 1 to 40. Version 1 is 21*21 matrix. And 4 modules increases whenever 1 version increases. So version 40 is 177*177 matrix. |
|
318 | + * @access protected |
|
319 | + */ |
|
320 | + protected $version = 0; |
|
321 | + |
|
322 | + /** |
|
323 | + * @var Levels of error correction. See definitions for possible values. |
|
324 | + * @access protected |
|
325 | + */ |
|
326 | + protected $level = QR_ECLEVEL_L; |
|
327 | + |
|
328 | + /** |
|
329 | + * @var Encoding mode |
|
330 | + * @access protected |
|
331 | + */ |
|
332 | + protected $hint = QR_MODE_8B; |
|
333 | + |
|
334 | + /** |
|
335 | + * @var if true the input string will be converted to uppercase |
|
336 | + * @access protected |
|
337 | + */ |
|
338 | + protected $casesensitive = true; |
|
339 | + |
|
340 | + /** |
|
341 | + * @var structured QR code (not supported yet) |
|
342 | + * @access protected |
|
343 | + */ |
|
344 | + protected $structured = 0; |
|
345 | + |
|
346 | + /** |
|
347 | + * @var mask data |
|
348 | + * @access protected |
|
349 | + */ |
|
350 | + protected $data; |
|
351 | + |
|
352 | + // FrameFiller |
|
353 | + |
|
354 | + /** |
|
355 | + * @var width |
|
356 | + * @access protected |
|
357 | + */ |
|
358 | + protected $width; |
|
359 | + |
|
360 | + /** |
|
361 | + * @var frame |
|
362 | + * @access protected |
|
363 | + */ |
|
364 | + protected $frame; |
|
365 | + |
|
366 | + /** |
|
367 | + * @var X position of bit |
|
368 | + * @access protected |
|
369 | + */ |
|
370 | + protected $x; |
|
371 | + |
|
372 | + /** |
|
373 | + * @var Y position of bit |
|
374 | + * @access protected |
|
375 | + */ |
|
376 | + protected $y; |
|
377 | + |
|
378 | + /** |
|
379 | + * @var direction |
|
380 | + * @access protected |
|
381 | + */ |
|
382 | + protected $dir; |
|
383 | + |
|
384 | + /** |
|
385 | + * @var single bit |
|
386 | + * @access protected |
|
387 | + */ |
|
388 | + protected $bit; |
|
389 | + |
|
390 | + // ---- QRrawcode ---- |
|
391 | + |
|
392 | + /** |
|
393 | + * @var data code |
|
394 | + * @access protected |
|
395 | + */ |
|
396 | + protected $datacode = array(); |
|
397 | + |
|
398 | + /** |
|
399 | + * @var error correction code |
|
400 | + * @access protected |
|
401 | + */ |
|
402 | + protected $ecccode = array(); |
|
403 | + |
|
404 | + /** |
|
405 | + * @var blocks |
|
406 | + * @access protected |
|
407 | + */ |
|
408 | + protected $blocks; |
|
409 | + |
|
410 | + /** |
|
411 | + * @var Reed-Solomon blocks |
|
412 | + * @access protected |
|
413 | + */ |
|
414 | + protected $rsblocks = array(); //of RSblock |
|
415 | + |
|
416 | + /** |
|
417 | + * @var counter |
|
418 | + * @access protected |
|
419 | + */ |
|
420 | + protected $count; |
|
421 | + |
|
422 | + /** |
|
423 | + * @var data length |
|
424 | + * @access protected |
|
425 | + */ |
|
426 | + protected $dataLength; |
|
427 | + |
|
428 | + /** |
|
429 | + * @var error correction length |
|
430 | + * @access protected |
|
431 | + */ |
|
432 | + protected $eccLength; |
|
433 | + |
|
434 | + /** |
|
435 | + * @var b1 |
|
436 | + * @access protected |
|
437 | + */ |
|
438 | + protected $b1; |
|
439 | + |
|
440 | + // ---- QRmask ---- |
|
441 | + |
|
442 | + /** |
|
443 | + * @var run length |
|
444 | + * @access protected |
|
445 | + */ |
|
446 | + protected $runLength = array(); |
|
447 | + |
|
448 | + // ---- QRsplit ---- |
|
449 | + |
|
450 | + /** |
|
451 | + * @var input data string |
|
452 | + * @access protected |
|
453 | + */ |
|
454 | + protected $dataStr = ''; |
|
455 | + |
|
456 | + /** |
|
457 | + * @var input items |
|
458 | + * @access protected |
|
459 | + */ |
|
460 | + protected $items; |
|
461 | + |
|
462 | + // Reed-Solomon items |
|
463 | + |
|
464 | + /** |
|
465 | + * @var Reed-Solomon items |
|
466 | + * @access protected |
|
467 | + */ |
|
468 | + protected $rsitems = array(); |
|
469 | + |
|
470 | + /** |
|
471 | + * @var array of frames |
|
472 | + * @access protected |
|
473 | + */ |
|
474 | + protected $frames = array(); |
|
475 | + |
|
476 | + /** |
|
477 | + * @var alphabet-numeric convesion table |
|
478 | + * @access protected |
|
479 | + */ |
|
480 | + protected $anTable = array( |
|
481 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // |
|
482 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // |
|
483 | + 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, // |
|
484 | + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, // |
|
485 | + -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, // |
|
486 | + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, // |
|
487 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // |
|
488 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 // |
|
489 | + ); |
|
490 | + |
|
491 | + /** |
|
492 | + * @var array Table of the capacity of symbols |
|
493 | + * See Table 1 (pp.13) and Table 12-16 (pp.30-36), JIS X0510:2004. |
|
494 | + * @access protected |
|
495 | + */ |
|
496 | + protected $capacity = array( |
|
497 | + array( 0, 0, 0, array( 0, 0, 0, 0)), // |
|
498 | + array( 21, 26, 0, array( 7, 10, 13, 17)), // 1 |
|
499 | + array( 25, 44, 7, array( 10, 16, 22, 28)), // |
|
500 | + array( 29, 70, 7, array( 15, 26, 36, 44)), // |
|
501 | + array( 33, 100, 7, array( 20, 36, 52, 64)), // |
|
502 | + array( 37, 134, 7, array( 26, 48, 72, 88)), // 5 |
|
503 | + array( 41, 172, 7, array( 36, 64, 96, 112)), // |
|
504 | + array( 45, 196, 0, array( 40, 72, 108, 130)), // |
|
505 | + array( 49, 242, 0, array( 48, 88, 132, 156)), // |
|
506 | + array( 53, 292, 0, array( 60, 110, 160, 192)), // |
|
507 | + array( 57, 346, 0, array( 72, 130, 192, 224)), // 10 |
|
508 | + array( 61, 404, 0, array( 80, 150, 224, 264)), // |
|
509 | + array( 65, 466, 0, array( 96, 176, 260, 308)), // |
|
510 | + array( 69, 532, 0, array( 104, 198, 288, 352)), // |
|
511 | + array( 73, 581, 3, array( 120, 216, 320, 384)), // |
|
512 | + array( 77, 655, 3, array( 132, 240, 360, 432)), // 15 |
|
513 | + array( 81, 733, 3, array( 144, 280, 408, 480)), // |
|
514 | + array( 85, 815, 3, array( 168, 308, 448, 532)), // |
|
515 | + array( 89, 901, 3, array( 180, 338, 504, 588)), // |
|
516 | + array( 93, 991, 3, array( 196, 364, 546, 650)), // |
|
517 | + array( 97, 1085, 3, array( 224, 416, 600, 700)), // 20 |
|
518 | + array(101, 1156, 4, array( 224, 442, 644, 750)), // |
|
519 | + array(105, 1258, 4, array( 252, 476, 690, 816)), // |
|
520 | + array(109, 1364, 4, array( 270, 504, 750, 900)), // |
|
521 | + array(113, 1474, 4, array( 300, 560, 810, 960)), // |
|
522 | + array(117, 1588, 4, array( 312, 588, 870, 1050)), // 25 |
|
523 | + array(121, 1706, 4, array( 336, 644, 952, 1110)), // |
|
524 | + array(125, 1828, 4, array( 360, 700, 1020, 1200)), // |
|
525 | + array(129, 1921, 3, array( 390, 728, 1050, 1260)), // |
|
526 | + array(133, 2051, 3, array( 420, 784, 1140, 1350)), // |
|
527 | + array(137, 2185, 3, array( 450, 812, 1200, 1440)), // 30 |
|
528 | + array(141, 2323, 3, array( 480, 868, 1290, 1530)), // |
|
529 | + array(145, 2465, 3, array( 510, 924, 1350, 1620)), // |
|
530 | + array(149, 2611, 3, array( 540, 980, 1440, 1710)), // |
|
531 | + array(153, 2761, 3, array( 570, 1036, 1530, 1800)), // |
|
532 | + array(157, 2876, 0, array( 570, 1064, 1590, 1890)), // 35 |
|
533 | + array(161, 3034, 0, array( 600, 1120, 1680, 1980)), // |
|
534 | + array(165, 3196, 0, array( 630, 1204, 1770, 2100)), // |
|
535 | + array(169, 3362, 0, array( 660, 1260, 1860, 2220)), // |
|
536 | + array(173, 3532, 0, array( 720, 1316, 1950, 2310)), // |
|
537 | + array(177, 3706, 0, array( 750, 1372, 2040, 2430)) // 40 |
|
538 | + ); |
|
539 | + |
|
540 | + /** |
|
541 | + * @var array Length indicator |
|
542 | + * @access protected |
|
543 | + */ |
|
544 | + protected $lengthTableBits = array( |
|
545 | + array(10, 12, 14), |
|
546 | + array( 9, 11, 13), |
|
547 | + array( 8, 16, 16), |
|
548 | + array( 8, 10, 12) |
|
549 | + ); |
|
550 | + |
|
551 | + /** |
|
552 | + * @var array Table of the error correction code (Reed-Solomon block) |
|
553 | + * See Table 12-16 (pp.30-36), JIS X0510:2004. |
|
554 | + * @access protected |
|
555 | + */ |
|
556 | + protected $eccTable = array( |
|
557 | + array(array( 0, 0), array( 0, 0), array( 0, 0), array( 0, 0)), // |
|
558 | + array(array( 1, 0), array( 1, 0), array( 1, 0), array( 1, 0)), // 1 |
|
559 | + array(array( 1, 0), array( 1, 0), array( 1, 0), array( 1, 0)), // |
|
560 | + array(array( 1, 0), array( 1, 0), array( 2, 0), array( 2, 0)), // |
|
561 | + array(array( 1, 0), array( 2, 0), array( 2, 0), array( 4, 0)), // |
|
562 | + array(array( 1, 0), array( 2, 0), array( 2, 2), array( 2, 2)), // 5 |
|
563 | + array(array( 2, 0), array( 4, 0), array( 4, 0), array( 4, 0)), // |
|
564 | + array(array( 2, 0), array( 4, 0), array( 2, 4), array( 4, 1)), // |
|
565 | + array(array( 2, 0), array( 2, 2), array( 4, 2), array( 4, 2)), // |
|
566 | + array(array( 2, 0), array( 3, 2), array( 4, 4), array( 4, 4)), // |
|
567 | + array(array( 2, 2), array( 4, 1), array( 6, 2), array( 6, 2)), // 10 |
|
568 | + array(array( 4, 0), array( 1, 4), array( 4, 4), array( 3, 8)), // |
|
569 | + array(array( 2, 2), array( 6, 2), array( 4, 6), array( 7, 4)), // |
|
570 | + array(array( 4, 0), array( 8, 1), array( 8, 4), array(12, 4)), // |
|
571 | + array(array( 3, 1), array( 4, 5), array(11, 5), array(11, 5)), // |
|
572 | + array(array( 5, 1), array( 5, 5), array( 5, 7), array(11, 7)), // 15 |
|
573 | + array(array( 5, 1), array( 7, 3), array(15, 2), array( 3, 13)), // |
|
574 | + array(array( 1, 5), array(10, 1), array( 1, 15), array( 2, 17)), // |
|
575 | + array(array( 5, 1), array( 9, 4), array(17, 1), array( 2, 19)), // |
|
576 | + array(array( 3, 4), array( 3, 11), array(17, 4), array( 9, 16)), // |
|
577 | + array(array( 3, 5), array( 3, 13), array(15, 5), array(15, 10)), // 20 |
|
578 | + array(array( 4, 4), array(17, 0), array(17, 6), array(19, 6)), // |
|
579 | + array(array( 2, 7), array(17, 0), array( 7, 16), array(34, 0)), // |
|
580 | + array(array( 4, 5), array( 4, 14), array(11, 14), array(16, 14)), // |
|
581 | + array(array( 6, 4), array( 6, 14), array(11, 16), array(30, 2)), // |
|
582 | + array(array( 8, 4), array( 8, 13), array( 7, 22), array(22, 13)), // 25 |
|
583 | + array(array(10, 2), array(19, 4), array(28, 6), array(33, 4)), // |
|
584 | + array(array( 8, 4), array(22, 3), array( 8, 26), array(12, 28)), // |
|
585 | + array(array( 3, 10), array( 3, 23), array( 4, 31), array(11, 31)), // |
|
586 | + array(array( 7, 7), array(21, 7), array( 1, 37), array(19, 26)), // |
|
587 | + array(array( 5, 10), array(19, 10), array(15, 25), array(23, 25)), // 30 |
|
588 | + array(array(13, 3), array( 2, 29), array(42, 1), array(23, 28)), // |
|
589 | + array(array(17, 0), array(10, 23), array(10, 35), array(19, 35)), // |
|
590 | + array(array(17, 1), array(14, 21), array(29, 19), array(11, 46)), // |
|
591 | + array(array(13, 6), array(14, 23), array(44, 7), array(59, 1)), // |
|
592 | + array(array(12, 7), array(12, 26), array(39, 14), array(22, 41)), // 35 |
|
593 | + array(array( 6, 14), array( 6, 34), array(46, 10), array( 2, 64)), // |
|
594 | + array(array(17, 4), array(29, 14), array(49, 10), array(24, 46)), // |
|
595 | + array(array( 4, 18), array(13, 32), array(48, 14), array(42, 32)), // |
|
596 | + array(array(20, 4), array(40, 7), array(43, 22), array(10, 67)), // |
|
597 | + array(array(19, 6), array(18, 31), array(34, 34), array(20, 61)) // 40 |
|
598 | + ); |
|
599 | + |
|
600 | + /** |
|
601 | + * @var array Positions of alignment patterns. |
|
602 | + * This array includes only the second and the third position of the alignment patterns. Rest of them can be calculated from the distance between them. |
|
603 | + * See Table 1 in Appendix E (pp.71) of JIS X0510:2004. |
|
604 | + * @access protected |
|
605 | + */ |
|
606 | + protected $alignmentPattern = array( |
|
607 | + array( 0, 0), |
|
608 | + array( 0, 0), array(18, 0), array(22, 0), array(26, 0), array(30, 0), // 1- 5 |
|
609 | + array(34, 0), array(22, 38), array(24, 42), array(26, 46), array(28, 50), // 6-10 |
|
610 | + array(30, 54), array(32, 58), array(34, 62), array(26, 46), array(26, 48), // 11-15 |
|
611 | + array(26, 50), array(30, 54), array(30, 56), array(30, 58), array(34, 62), // 16-20 |
|
612 | + array(28, 50), array(26, 50), array(30, 54), array(28, 54), array(32, 58), // 21-25 |
|
613 | + array(30, 58), array(34, 62), array(26, 50), array(30, 54), array(26, 52), // 26-30 |
|
614 | + array(30, 56), array(34, 60), array(30, 58), array(34, 62), array(30, 54), // 31-35 |
|
615 | + array(24, 50), array(28, 54), array(32, 58), array(26, 54), array(30, 58) // 35-40 |
|
616 | + ); |
|
617 | + |
|
618 | + /** |
|
619 | + * @var array Version information pattern (BCH coded). |
|
620 | + * See Table 1 in Appendix D (pp.68) of JIS X0510:2004. |
|
621 | + * size: [QRSPEC_VERSION_MAX - 6] |
|
622 | + * @access protected |
|
623 | + */ |
|
624 | + protected $versionPattern = array( |
|
625 | + 0x07c94, 0x085bc, 0x09a99, 0x0a4d3, 0x0bbf6, 0x0c762, 0x0d847, 0x0e60d, // |
|
626 | + 0x0f928, 0x10b78, 0x1145d, 0x12a17, 0x13532, 0x149a6, 0x15683, 0x168c9, // |
|
627 | + 0x177ec, 0x18ec4, 0x191e1, 0x1afab, 0x1b08e, 0x1cc1a, 0x1d33f, 0x1ed75, // |
|
628 | + 0x1f250, 0x209d5, 0x216f0, 0x228ba, 0x2379f, 0x24b0b, 0x2542e, 0x26a64, // |
|
629 | + 0x27541, 0x28c69 |
|
630 | + ); |
|
631 | + |
|
632 | + /** |
|
633 | + * @var array Format information |
|
634 | + * @access protected |
|
635 | + */ |
|
636 | + protected $formatInfo = array( |
|
637 | + array(0x77c4, 0x72f3, 0x7daa, 0x789d, 0x662f, 0x6318, 0x6c41, 0x6976), // |
|
638 | + array(0x5412, 0x5125, 0x5e7c, 0x5b4b, 0x45f9, 0x40ce, 0x4f97, 0x4aa0), // |
|
639 | + array(0x355f, 0x3068, 0x3f31, 0x3a06, 0x24b4, 0x2183, 0x2eda, 0x2bed), // |
|
640 | + array(0x1689, 0x13be, 0x1ce7, 0x19d0, 0x0762, 0x0255, 0x0d0c, 0x083b) // |
|
641 | + ); |
|
642 | + |
|
643 | + |
|
644 | + // ------------------------------------------------- |
|
645 | + // ------------------------------------------------- |
|
646 | + |
|
647 | + |
|
648 | + /** |
|
649 | + * This is the class constructor. |
|
650 | + * Creates a QRcode object |
|
651 | + * @param string $code code to represent using QRcode |
|
652 | + * @param string $eclevel error level: <ul><li>L : About 7% or less errors can be corrected.</li><li>M : About 15% or less errors can be corrected.</li><li>Q : About 25% or less errors can be corrected.</li><li>H : About 30% or less errors can be corrected.</li></ul> |
|
653 | + * @access public |
|
654 | + * @since 1.0.000 |
|
655 | + */ |
|
656 | + public function __construct($code, $eclevel = 'L') { |
|
657 | + $barcode_array = array(); |
|
658 | + if ((is_null($code)) or ($code == '\0') or ($code == '')) { |
|
659 | + return false; |
|
660 | + } |
|
661 | + // set error correction level |
|
662 | + $this->level = array_search($eclevel, array('L', 'M', 'Q', 'H')); |
|
663 | + if ($this->level === false) { |
|
664 | + $this->level = QR_ECLEVEL_L; |
|
665 | + } |
|
666 | + if (($this->hint != QR_MODE_8B) and ($this->hint != QR_MODE_KJ)) { |
|
667 | + return false; |
|
668 | + } |
|
669 | + if (($this->version < 0) or ($this->version > QRSPEC_VERSION_MAX)) { |
|
670 | + return false; |
|
671 | + } |
|
672 | + $this->items = array(); |
|
673 | + $this->encodeString($code); |
|
674 | + $qrTab = $this->binarize($this->data); |
|
675 | + $size = count($qrTab); |
|
676 | + $barcode_array['num_rows'] = $size; |
|
677 | + $barcode_array['num_cols'] = $size; |
|
678 | + $barcode_array['bcode'] = array(); |
|
679 | + foreach ($qrTab as $line) { |
|
680 | + $arrAdd = array(); |
|
681 | + foreach (str_split($line) as $char) { |
|
682 | + $arrAdd[] = ($char=='1')?1:0; |
|
683 | + } |
|
684 | + $barcode_array['bcode'][] = $arrAdd; |
|
685 | + } |
|
686 | + $this->barcode_array = $barcode_array; |
|
687 | + } |
|
688 | + |
|
689 | + /** |
|
690 | + * Returns a barcode array which is readable by TCPDF |
|
691 | + * @return array barcode array readable by TCPDF; |
|
692 | + * @access public |
|
693 | + */ |
|
694 | + public function getBarcodeArray() { |
|
695 | + return $this->barcode_array; |
|
696 | + } |
|
697 | + |
|
698 | + /** |
|
699 | + * Convert the frame in binary form |
|
700 | + * @param array $frame array to binarize |
|
701 | + * @return array frame in binary form |
|
702 | + */ |
|
703 | + protected function binarize($frame) { |
|
704 | + $len = count($frame); |
|
705 | + // the frame is square (width = height) |
|
706 | + foreach ($frame as &$frameLine) { |
|
707 | + for ($i=0; $i<$len; $i++) { |
|
708 | + $frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0'; |
|
709 | + } |
|
710 | + } |
|
711 | + return $frame; |
|
712 | + } |
|
713 | + |
|
714 | + /** |
|
715 | + * Encode the input string to QR code |
|
716 | + * @param string $string input string to encode |
|
717 | + */ |
|
718 | + protected function encodeString($string) { |
|
719 | + $this->dataStr = $string; |
|
720 | + if (!$this->casesensitive) { |
|
721 | + $this->toUpper(); |
|
722 | + } |
|
723 | + $ret = $this->splitString(); |
|
724 | + if ($ret < 0) { |
|
725 | + return null; |
|
726 | + } |
|
727 | + $this->encodeMask(-1); |
|
728 | + } |
|
729 | + |
|
730 | + /** |
|
731 | + * Encode mask |
|
732 | + * @param int $mask masking mode |
|
733 | + */ |
|
734 | + protected function encodeMask($mask) { |
|
735 | + $spec = array(0, 0, 0, 0, 0); |
|
736 | + $this->datacode = $this->getByteStream($this->items); |
|
737 | + if (is_null($this->datacode)) { |
|
738 | + return null; |
|
739 | + } |
|
740 | + $spec = $this->getEccSpec($this->version, $this->level, $spec); |
|
741 | + $this->b1 = $this->rsBlockNum1($spec); |
|
742 | + $this->dataLength = $this->rsDataLength($spec); |
|
743 | + $this->eccLength = $this->rsEccLength($spec); |
|
744 | + $this->ecccode = array_fill(0, $this->eccLength, 0); |
|
745 | + $this->blocks = $this->rsBlockNum($spec); |
|
746 | + $ret = $this->init($spec); |
|
747 | + if ($ret < 0) { |
|
748 | + return null; |
|
749 | + } |
|
750 | + $this->count = 0; |
|
751 | + $this->width = $this->getWidth($this->version); |
|
752 | + $this->frame = $this->newFrame($this->version); |
|
753 | + $this->x = $this->width - 1; |
|
754 | + $this->y = $this->width - 1; |
|
755 | + $this->dir = -1; |
|
756 | + $this->bit = -1; |
|
757 | + // inteleaved data and ecc codes |
|
758 | + for ($i=0; $i < ($this->dataLength + $this->eccLength); $i++) { |
|
759 | + $code = $this->getCode(); |
|
760 | + $bit = 0x80; |
|
761 | + for ($j=0; $j<8; $j++) { |
|
762 | + $addr = $this->getNextPosition(); |
|
763 | + $this->setFrameAt($addr, 0x02 | (($bit & $code) != 0)); |
|
764 | + $bit = $bit >> 1; |
|
765 | + } |
|
766 | + } |
|
767 | + // remainder bits |
|
768 | + $j = $this->getRemainder($this->version); |
|
769 | + for ($i=0; $i<$j; $i++) { |
|
770 | + $addr = $this->getNextPosition(); |
|
771 | + $this->setFrameAt($addr, 0x02); |
|
772 | + } |
|
773 | + // masking |
|
774 | + $this->runLength = array_fill(0, QRSPEC_WIDTH_MAX + 1, 0); |
|
775 | + if ($mask < 0) { |
|
776 | + if (QR_FIND_BEST_MASK) { |
|
777 | + $masked = $this->mask($this->width, $this->frame, $this->level); |
|
778 | + } else { |
|
779 | + $masked = $this->makeMask($this->width, $this->frame, (intval(QR_DEFAULT_MASK) % 8), $this->level); |
|
780 | + } |
|
781 | + } else { |
|
782 | + $masked = $this->makeMask($this->width, $this->frame, $mask, $this->level); |
|
783 | + } |
|
784 | + if ($masked == null) { |
|
785 | + return null; |
|
786 | + } |
|
787 | + $this->data = $masked; |
|
788 | + } |
|
789 | + |
|
790 | + // - - - - - - - - - - - - - - - - - - - - - - - - - |
|
791 | + |
|
792 | + // FrameFiller |
|
793 | + |
|
794 | + /** |
|
795 | + * Set frame value at specified position |
|
796 | + * @param array $at x,y position |
|
797 | + * @param int $val value of the character to set |
|
798 | + */ |
|
799 | + protected function setFrameAt($at, $val) { |
|
800 | + $this->frame[$at['y']][$at['x']] = chr($val); |
|
801 | + } |
|
802 | + |
|
803 | + /** |
|
804 | + * Get frame value at specified position |
|
805 | + * @param array $at x,y position |
|
806 | + * @return value at specified position |
|
807 | + */ |
|
808 | + protected function getFrameAt($at) { |
|
809 | + return ord($this->frame[$at['y']][$at['x']]); |
|
810 | + } |
|
811 | + |
|
812 | + /** |
|
813 | + * Return the next frame position |
|
814 | + * @return array of x,y coordinates |
|
815 | + */ |
|
816 | + protected function getNextPosition() { |
|
817 | + do { |
|
818 | + if ($this->bit == -1) { |
|
819 | + $this->bit = 0; |
|
820 | + return array('x'=>$this->x, 'y'=>$this->y); |
|
821 | + } |
|
822 | + $x = $this->x; |
|
823 | + $y = $this->y; |
|
824 | + $w = $this->width; |
|
825 | + if ($this->bit == 0) { |
|
826 | + $x--; |
|
827 | + $this->bit++; |
|
828 | + } else { |
|
829 | + $x++; |
|
830 | + $y += $this->dir; |
|
831 | + $this->bit--; |
|
832 | + } |
|
833 | + if ($this->dir < 0) { |
|
834 | + if ($y < 0) { |
|
835 | + $y = 0; |
|
836 | + $x -= 2; |
|
837 | + $this->dir = 1; |
|
838 | + if ($x == 6) { |
|
839 | + $x--; |
|
840 | + $y = 9; |
|
841 | + } |
|
842 | + } |
|
843 | + } else { |
|
844 | + if ($y == $w) { |
|
845 | + $y = $w - 1; |
|
846 | + $x -= 2; |
|
847 | + $this->dir = -1; |
|
848 | + if ($x == 6) { |
|
849 | + $x--; |
|
850 | + $y -= 8; |
|
851 | + } |
|
852 | + } |
|
853 | + } |
|
854 | + if (($x < 0) or ($y < 0)) { |
|
855 | + return null; |
|
856 | + } |
|
857 | + $this->x = $x; |
|
858 | + $this->y = $y; |
|
859 | + } while(ord($this->frame[$y][$x]) & 0x80); |
|
860 | + return array('x'=>$x, 'y'=>$y); |
|
861 | + } |
|
862 | + |
|
863 | + // - - - - - - - - - - - - - - - - - - - - - - - - - |
|
864 | + |
|
865 | + // QRrawcode |
|
866 | + |
|
867 | + /** |
|
868 | + * Initialize code. |
|
869 | + * @param array $spec array of ECC specification |
|
870 | + * @return 0 in case of success, -1 in case of error |
|
871 | + */ |
|
872 | + protected function init($spec) { |
|
873 | + $dl = $this->rsDataCodes1($spec); |
|
874 | + $el = $this->rsEccCodes1($spec); |
|
875 | + $rs = $this->init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el); |
|
876 | + $blockNo = 0; |
|
877 | + $dataPos = 0; |
|
878 | + $eccPos = 0; |
|
879 | + $endfor = $this->rsBlockNum1($spec); |
|
880 | + for ($i=0; $i < $endfor; ++$i) { |
|
881 | + $ecc = array_slice($this->ecccode, $eccPos); |
|
882 | + $this->rsblocks[$blockNo] = array(); |
|
883 | + $this->rsblocks[$blockNo]['dataLength'] = $dl; |
|
884 | + $this->rsblocks[$blockNo]['data'] = array_slice($this->datacode, $dataPos); |
|
885 | + $this->rsblocks[$blockNo]['eccLength'] = $el; |
|
886 | + $ecc = $this->encode_rs_char($rs, $this->rsblocks[$blockNo]['data'], $ecc); |
|
887 | + $this->rsblocks[$blockNo]['ecc'] = $ecc; |
|
888 | + $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc); |
|
889 | + $dataPos += $dl; |
|
890 | + $eccPos += $el; |
|
891 | + $blockNo++; |
|
892 | + } |
|
893 | + if ($this->rsBlockNum2($spec) == 0) { |
|
894 | + return 0; |
|
895 | + } |
|
896 | + $dl = $this->rsDataCodes2($spec); |
|
897 | + $el = $this->rsEccCodes2($spec); |
|
898 | + $rs = $this->init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el); |
|
899 | + if ($rs == null) { |
|
900 | + return -1; |
|
901 | + } |
|
902 | + $endfor = $this->rsBlockNum2($spec); |
|
903 | + for ($i=0; $i < $endfor; ++$i) { |
|
904 | + $ecc = array_slice($this->ecccode, $eccPos); |
|
905 | + $this->rsblocks[$blockNo] = array(); |
|
906 | + $this->rsblocks[$blockNo]['dataLength'] = $dl; |
|
907 | + $this->rsblocks[$blockNo]['data'] = array_slice($this->datacode, $dataPos); |
|
908 | + $this->rsblocks[$blockNo]['eccLength'] = $el; |
|
909 | + $ecc = $this->encode_rs_char($rs, $this->rsblocks[$blockNo]['data'], $ecc); |
|
910 | + $this->rsblocks[$blockNo]['ecc'] = $ecc; |
|
911 | + $this->ecccode = array_merge(array_slice($this->ecccode, 0, $eccPos), $ecc); |
|
912 | + $dataPos += $dl; |
|
913 | + $eccPos += $el; |
|
914 | + $blockNo++; |
|
915 | + } |
|
916 | + return 0; |
|
917 | + } |
|
918 | + |
|
919 | + /** |
|
920 | + * Return Reed-Solomon block code. |
|
921 | + * @return array rsblocks |
|
922 | + */ |
|
923 | + protected function getCode() { |
|
924 | + if ($this->count < $this->dataLength) { |
|
925 | + $row = $this->count % $this->blocks; |
|
926 | + $col = $this->count / $this->blocks; |
|
927 | + if ($col >= $this->rsblocks[0]['dataLength']) { |
|
928 | + $row += $this->b1; |
|
929 | + } |
|
930 | + $ret = $this->rsblocks[$row]['data'][$col]; |
|
931 | + } elseif ($this->count < $this->dataLength + $this->eccLength) { |
|
932 | + $row = ($this->count - $this->dataLength) % $this->blocks; |
|
933 | + $col = ($this->count - $this->dataLength) / $this->blocks; |
|
934 | + $ret = $this->rsblocks[$row]['ecc'][$col]; |
|
935 | + } else { |
|
936 | + return 0; |
|
937 | + } |
|
938 | + $this->count++; |
|
939 | + return $ret; |
|
940 | + } |
|
941 | + |
|
942 | + // - - - - - - - - - - - - - - - - - - - - - - - - - |
|
943 | + |
|
944 | + // QRmask |
|
945 | + |
|
946 | + /** |
|
947 | + * Write Format Information on frame and returns the number of black bits |
|
948 | + * @param int $width frame width |
|
949 | + * @param array $frame frame |
|
950 | + * @param array $mask masking mode |
|
951 | + * @param int $level error correction level |
|
952 | + * @return int blacks |
|
953 | + */ |
|
954 | + protected function writeFormatInformation($width, &$frame, $mask, $level) { |
|
955 | + $blacks = 0; |
|
956 | + $format = $this->getFormatInfo($mask, $level); |
|
957 | + for ($i=0; $i<8; ++$i) { |
|
958 | + if ($format & 1) { |
|
959 | + $blacks += 2; |
|
960 | + $v = 0x85; |
|
961 | + } else { |
|
962 | + $v = 0x84; |
|
963 | + } |
|
964 | + $frame[8][$width - 1 - $i] = chr($v); |
|
965 | + if ($i < 6) { |
|
966 | + $frame[$i][8] = chr($v); |
|
967 | + } else { |
|
968 | + $frame[$i + 1][8] = chr($v); |
|
969 | + } |
|
970 | + $format = $format >> 1; |
|
971 | + } |
|
972 | + for ($i=0; $i<7; ++$i) { |
|
973 | + if ($format & 1) { |
|
974 | + $blacks += 2; |
|
975 | + $v = 0x85; |
|
976 | + } else { |
|
977 | + $v = 0x84; |
|
978 | + } |
|
979 | + $frame[$width - 7 + $i][8] = chr($v); |
|
980 | + if ($i == 0) { |
|
981 | + $frame[8][7] = chr($v); |
|
982 | + } else { |
|
983 | + $frame[8][6 - $i] = chr($v); |
|
984 | + } |
|
985 | + $format = $format >> 1; |
|
986 | + } |
|
987 | + return $blacks; |
|
988 | + } |
|
989 | + |
|
990 | + /** |
|
991 | + * mask0 |
|
992 | + * @param int $x X position |
|
993 | + * @param int $y Y position |
|
994 | + * @return int mask |
|
995 | + */ |
|
996 | + protected function mask0($x, $y) { |
|
997 | + return ($x + $y) & 1; |
|
998 | + } |
|
999 | + |
|
1000 | + /** |
|
1001 | + * mask1 |
|
1002 | + * @param int $x X position |
|
1003 | + * @param int $y Y position |
|
1004 | + * @return int mask |
|
1005 | + */ |
|
1006 | + protected function mask1($x, $y) { |
|
1007 | + return ($y & 1); |
|
1008 | + } |
|
1009 | + |
|
1010 | + /** |
|
1011 | + * mask2 |
|
1012 | + * @param int $x X position |
|
1013 | + * @param int $y Y position |
|
1014 | + * @return int mask |
|
1015 | + */ |
|
1016 | + protected function mask2($x, $y) { |
|
1017 | + return ($x % 3); |
|
1018 | + } |
|
1019 | + |
|
1020 | + /** |
|
1021 | + * mask3 |
|
1022 | + * @param int $x X position |
|
1023 | + * @param int $y Y position |
|
1024 | + * @return int mask |
|
1025 | + */ |
|
1026 | + protected function mask3($x, $y) { |
|
1027 | + return ($x + $y) % 3; |
|
1028 | + } |
|
1029 | + |
|
1030 | + /** |
|
1031 | + * mask4 |
|
1032 | + * @param int $x X position |
|
1033 | + * @param int $y Y position |
|
1034 | + * @return int mask |
|
1035 | + */ |
|
1036 | + protected function mask4($x, $y) { |
|
1037 | + return (((int)($y / 2)) + ((int)($x / 3))) & 1; |
|
1038 | + } |
|
1039 | + |
|
1040 | + /** |
|
1041 | + * mask5 |
|
1042 | + * @param int $x X position |
|
1043 | + * @param int $y Y position |
|
1044 | + * @return int mask |
|
1045 | + */ |
|
1046 | + protected function mask5($x, $y) { |
|
1047 | + return (($x * $y) & 1) + ($x * $y) % 3; |
|
1048 | + } |
|
1049 | + |
|
1050 | + /** |
|
1051 | + * mask6 |
|
1052 | + * @param int $x X position |
|
1053 | + * @param int $y Y position |
|
1054 | + * @return int mask |
|
1055 | + */ |
|
1056 | + protected function mask6($x, $y) { |
|
1057 | + return ((($x * $y) & 1) + ($x * $y) % 3) & 1; |
|
1058 | + } |
|
1059 | + |
|
1060 | + /** |
|
1061 | + * mask7 |
|
1062 | + * @param int $x X position |
|
1063 | + * @param int $y Y position |
|
1064 | + * @return int mask |
|
1065 | + */ |
|
1066 | + protected function mask7($x, $y) { |
|
1067 | + return ((($x * $y) % 3) + (($x + $y) & 1)) & 1; |
|
1068 | + } |
|
1069 | + |
|
1070 | + /** |
|
1071 | + * Return bitmask |
|
1072 | + * @param int $maskNo mask number |
|
1073 | + * @param int $width width |
|
1074 | + * @param array $frame frame |
|
1075 | + * @return array bitmask |
|
1076 | + */ |
|
1077 | + protected function generateMaskNo($maskNo, $width, $frame) { |
|
1078 | + $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); |
|
1079 | + for ($y=0; $y<$width; ++$y) { |
|
1080 | + for ($x=0; $x<$width; ++$x) { |
|
1081 | + if (ord($frame[$y][$x]) & 0x80) { |
|
1082 | + $bitMask[$y][$x] = 0; |
|
1083 | + } else { |
|
1084 | + $maskFunc = call_user_func(array($this, 'mask'.$maskNo), $x, $y); |
|
1085 | + $bitMask[$y][$x] = ($maskFunc == 0)?1:0; |
|
1086 | + } |
|
1087 | + } |
|
1088 | + } |
|
1089 | + return $bitMask; |
|
1090 | + } |
|
1091 | + |
|
1092 | + /** |
|
1093 | + * makeMaskNo |
|
1094 | + * @param int $maskNo |
|
1095 | + * @param int $width |
|
1096 | + * @param int $s |
|
1097 | + * @param int $d |
|
1098 | + * @param boolean $maskGenOnly |
|
1099 | + * @return int b |
|
1100 | + */ |
|
1101 | + protected function makeMaskNo($maskNo, $width, $s, &$d, $maskGenOnly=false) { |
|
1102 | + $b = 0; |
|
1103 | + $bitMask = array(); |
|
1104 | + $bitMask = $this->generateMaskNo($maskNo, $width, $s); |
|
1105 | + if ($maskGenOnly) { |
|
1106 | + return; |
|
1107 | + } |
|
1108 | + $d = $s; |
|
1109 | + for ($y=0; $y<$width; ++$y) { |
|
1110 | + for ($x=0; $x<$width; ++$x) { |
|
1111 | + if ($bitMask[$y][$x] == 1) { |
|
1112 | + $d[$y][$x] = chr(ord($s[$y][$x]) ^ (int)$bitMask[$y][$x]); |
|
1113 | + } |
|
1114 | + $b += (int)(ord($d[$y][$x]) & 1); |
|
1115 | + } |
|
1116 | + } |
|
1117 | + return $b; |
|
1118 | + } |
|
1119 | + |
|
1120 | + /** |
|
1121 | + * makeMask |
|
1122 | + * @param int $width |
|
1123 | + * @param array $frame |
|
1124 | + * @param int $maskNo |
|
1125 | + * @param int $level |
|
1126 | + * @return array mask |
|
1127 | + */ |
|
1128 | + protected function makeMask($width, $frame, $maskNo, $level) { |
|
1129 | + $masked = array_fill(0, $width, str_repeat("\0", $width)); |
|
1130 | + $this->makeMaskNo($maskNo, $width, $frame, $masked); |
|
1131 | + $this->writeFormatInformation($width, $masked, $maskNo, $level); |
|
1132 | + return $masked; |
|
1133 | + } |
|
1134 | + |
|
1135 | + /** |
|
1136 | + * calcN1N3 |
|
1137 | + * @param int $length |
|
1138 | + * @return int demerit |
|
1139 | + */ |
|
1140 | + protected function calcN1N3($length) { |
|
1141 | + $demerit = 0; |
|
1142 | + for ($i=0; $i<$length; ++$i) { |
|
1143 | + if ($this->runLength[$i] >= 5) { |
|
1144 | + $demerit += (N1 + ($this->runLength[$i] - 5)); |
|
1145 | + } |
|
1146 | + if ($i & 1) { |
|
1147 | + if (($i >= 3) and ($i < ($length-2)) and ($this->runLength[$i] % 3 == 0)) { |
|
1148 | + $fact = (int)($this->runLength[$i] / 3); |
|
1149 | + if (($this->runLength[$i-2] == $fact) |
|
1150 | + and ($this->runLength[$i-1] == $fact) |
|
1151 | + and ($this->runLength[$i+1] == $fact) |
|
1152 | + and ($this->runLength[$i+2] == $fact)) { |
|
1153 | + if (($this->runLength[$i-3] < 0) or ($this->runLength[$i-3] >= (4 * $fact))) { |
|
1154 | + $demerit += N3; |
|
1155 | + } elseif ((($i+3) >= $length) or ($this->runLength[$i+3] >= (4 * $fact))) { |
|
1156 | + $demerit += N3; |
|
1157 | + } |
|
1158 | + } |
|
1159 | + } |
|
1160 | + } |
|
1161 | + } |
|
1162 | + return $demerit; |
|
1163 | + } |
|
1164 | + |
|
1165 | + /** |
|
1166 | + * evaluateSymbol |
|
1167 | + * @param int $width |
|
1168 | + * @param array $frame |
|
1169 | + * @return int demerit |
|
1170 | + */ |
|
1171 | + protected function evaluateSymbol($width, $frame) { |
|
1172 | + $head = 0; |
|
1173 | + $demerit = 0; |
|
1174 | + for ($y=0; $y<$width; ++$y) { |
|
1175 | + $head = 0; |
|
1176 | + $this->runLength[0] = 1; |
|
1177 | + $frameY = $frame[$y]; |
|
1178 | + if ($y > 0) { |
|
1179 | + $frameYM = $frame[$y-1]; |
|
1180 | + } |
|
1181 | + for ($x=0; $x<$width; ++$x) { |
|
1182 | + if (($x > 0) and ($y > 0)) { |
|
1183 | + $b22 = ord($frameY[$x]) & ord($frameY[$x-1]) & ord($frameYM[$x]) & ord($frameYM[$x-1]); |
|
1184 | + $w22 = ord($frameY[$x]) | ord($frameY[$x-1]) | ord($frameYM[$x]) | ord($frameYM[$x-1]); |
|
1185 | + if (($b22 | ($w22 ^ 1)) & 1) { |
|
1186 | + $demerit += N2; |
|
1187 | + } |
|
1188 | + } |
|
1189 | + if (($x == 0) and (ord($frameY[$x]) & 1)) { |
|
1190 | + $this->runLength[0] = -1; |
|
1191 | + $head = 1; |
|
1192 | + $this->runLength[$head] = 1; |
|
1193 | + } elseif ($x > 0) { |
|
1194 | + if ((ord($frameY[$x]) ^ ord($frameY[$x-1])) & 1) { |
|
1195 | + $head++; |
|
1196 | + $this->runLength[$head] = 1; |
|
1197 | + } else { |
|
1198 | + $this->runLength[$head]++; |
|
1199 | + } |
|
1200 | + } |
|
1201 | + } |
|
1202 | + $demerit += $this->calcN1N3($head+1); |
|
1203 | + } |
|
1204 | + for ($x=0; $x<$width; ++$x) { |
|
1205 | + $head = 0; |
|
1206 | + $this->runLength[0] = 1; |
|
1207 | + for ($y=0; $y<$width; ++$y) { |
|
1208 | + if (($y == 0) and (ord($frame[$y][$x]) & 1)) { |
|
1209 | + $this->runLength[0] = -1; |
|
1210 | + $head = 1; |
|
1211 | + $this->runLength[$head] = 1; |
|
1212 | + } elseif ($y > 0) { |
|
1213 | + if ((ord($frame[$y][$x]) ^ ord($frame[$y-1][$x])) & 1) { |
|
1214 | + $head++; |
|
1215 | + $this->runLength[$head] = 1; |
|
1216 | + } else { |
|
1217 | + $this->runLength[$head]++; |
|
1218 | + } |
|
1219 | + } |
|
1220 | + } |
|
1221 | + $demerit += $this->calcN1N3($head+1); |
|
1222 | + } |
|
1223 | + return $demerit; |
|
1224 | + } |
|
1225 | + |
|
1226 | + /** |
|
1227 | + * mask |
|
1228 | + * @param int $width |
|
1229 | + * @param array $frame |
|
1230 | + * @param int $level |
|
1231 | + * @return array best mask |
|
1232 | + */ |
|
1233 | + protected function mask($width, $frame, $level) { |
|
1234 | + $minDemerit = PHP_INT_MAX; |
|
1235 | + $bestMaskNum = 0; |
|
1236 | + $bestMask = array(); |
|
1237 | + $checked_masks = array(0, 1, 2, 3, 4, 5, 6, 7); |
|
1238 | + if (QR_FIND_FROM_RANDOM !== false) { |
|
1239 | + $howManuOut = 8 - (QR_FIND_FROM_RANDOM % 9); |
|
1240 | + for ($i = 0; $i < $howManuOut; ++$i) { |
|
1241 | + $remPos = rand (0, count($checked_masks)-1); |
|
1242 | + unset($checked_masks[$remPos]); |
|
1243 | + $checked_masks = array_values($checked_masks); |
|
1244 | + } |
|
1245 | + } |
|
1246 | + $bestMask = $frame; |
|
1247 | + foreach ($checked_masks as $i) { |
|
1248 | + $mask = array_fill(0, $width, str_repeat("\0", $width)); |
|
1249 | + $demerit = 0; |
|
1250 | + $blacks = 0; |
|
1251 | + $blacks = $this->makeMaskNo($i, $width, $frame, $mask); |
|
1252 | + $blacks += $this->writeFormatInformation($width, $mask, $i, $level); |
|
1253 | + $blacks = (int)(100 * $blacks / ($width * $width)); |
|
1254 | + $demerit = (int)((int)(abs($blacks - 50) / 5) * N4); |
|
1255 | + $demerit += $this->evaluateSymbol($width, $mask); |
|
1256 | + if ($demerit < $minDemerit) { |
|
1257 | + $minDemerit = $demerit; |
|
1258 | + $bestMask = $mask; |
|
1259 | + $bestMaskNum = $i; |
|
1260 | + } |
|
1261 | + } |
|
1262 | + return $bestMask; |
|
1263 | + } |
|
1264 | + |
|
1265 | + // - - - - - - - - - - - - - - - - - - - - - - - - - |
|
1266 | + |
|
1267 | + // QRsplit |
|
1268 | + |
|
1269 | + /** |
|
1270 | + * Return true if the character at specified position is a number |
|
1271 | + * @param string $str string |
|
1272 | + * @param int $pos characted position |
|
1273 | + * @return boolean true of false |
|
1274 | + */ |
|
1275 | + protected function isdigitat($str, $pos) { |
|
1276 | + if ($pos >= strlen($str)) { |
|
1277 | + return false; |
|
1278 | + } |
|
1279 | + return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9'))); |
|
1280 | + } |
|
1281 | + |
|
1282 | + /** |
|
1283 | + * Return true if the character at specified position is an alphanumeric character |
|
1284 | + * @param string $str string |
|
1285 | + * @param int $pos characted position |
|
1286 | + * @return boolean true of false |
|
1287 | + */ |
|
1288 | + protected function isalnumat($str, $pos) { |
|
1289 | + if ($pos >= strlen($str)) { |
|
1290 | + return false; |
|
1291 | + } |
|
1292 | + return ($this->lookAnTable(ord($str[$pos])) >= 0); |
|
1293 | + } |
|
1294 | + |
|
1295 | + /** |
|
1296 | + * identifyMode |
|
1297 | + * @param int $pos |
|
1298 | + * @return int mode |
|
1299 | + */ |
|
1300 | + protected function identifyMode($pos) { |
|
1301 | + if ($pos >= strlen($this->dataStr)) { |
|
1302 | + return QR_MODE_NL; |
|
1303 | + } |
|
1304 | + $c = $this->dataStr[$pos]; |
|
1305 | + if ($this->isdigitat($this->dataStr, $pos)) { |
|
1306 | + return QR_MODE_NM; |
|
1307 | + } elseif ($this->isalnumat($this->dataStr, $pos)) { |
|
1308 | + return QR_MODE_AN; |
|
1309 | + } elseif ($this->hint == QR_MODE_KJ) { |
|
1310 | + if ($pos+1 < strlen($this->dataStr)) { |
|
1311 | + $d = $this->dataStr[$pos+1]; |
|
1312 | + $word = (ord($c) << 8) | ord($d); |
|
1313 | + if (($word >= 0x8140 && $word <= 0x9ffc) or ($word >= 0xe040 && $word <= 0xebbf)) { |
|
1314 | + return QR_MODE_KJ; |
|
1315 | + } |
|
1316 | + } |
|
1317 | + } |
|
1318 | + return QR_MODE_8B; |
|
1319 | + } |
|
1320 | + |
|
1321 | + /** |
|
1322 | + * eatNum |
|
1323 | + * @return int run |
|
1324 | + */ |
|
1325 | + protected function eatNum() { |
|
1326 | + $ln = $this->lengthIndicator(QR_MODE_NM, $this->version); |
|
1327 | + $p = 0; |
|
1328 | + while($this->isdigitat($this->dataStr, $p)) { |
|
1329 | + $p++; |
|
1330 | + } |
|
1331 | + $run = $p; |
|
1332 | + $mode = $this->identifyMode($p); |
|
1333 | + if ($mode == QR_MODE_8B) { |
|
1334 | + $dif = $this->estimateBitsModeNum($run) + 4 + $ln |
|
1335 | + + $this->estimateBitsMode8(1) // + 4 + l8 |
|
1336 | + - $this->estimateBitsMode8($run + 1); // - 4 - l8 |
|
1337 | + if ($dif > 0) { |
|
1338 | + return $this->eat8(); |
|
1339 | + } |
|
1340 | + } |
|
1341 | + if ($mode == QR_MODE_AN) { |
|
1342 | + $dif = $this->estimateBitsModeNum($run) + 4 + $ln |
|
1343 | + + $this->estimateBitsModeAn(1) // + 4 + la |
|
1344 | + - $this->estimateBitsModeAn($run + 1);// - 4 - la |
|
1345 | + if ($dif > 0) { |
|
1346 | + return $this->eatAn(); |
|
1347 | + } |
|
1348 | + } |
|
1349 | + $this->items = $this->appendNewInputItem($this->items, QR_MODE_NM, $run, str_split($this->dataStr)); |
|
1350 | + return $run; |
|
1351 | + } |
|
1352 | + |
|
1353 | + /** |
|
1354 | + * eatAn |
|
1355 | + * @return int run |
|
1356 | + */ |
|
1357 | + protected function eatAn() { |
|
1358 | + $la = $this->lengthIndicator(QR_MODE_AN, $this->version); |
|
1359 | + $ln = $this->lengthIndicator(QR_MODE_NM, $this->version); |
|
1360 | + $p = 0; |
|
1361 | + while($this->isalnumat($this->dataStr, $p)) { |
|
1362 | + if ($this->isdigitat($this->dataStr, $p)) { |
|
1363 | + $q = $p; |
|
1364 | + while($this->isdigitat($this->dataStr, $q)) { |
|
1365 | + $q++; |
|
1366 | + } |
|
1367 | + $dif = $this->estimateBitsModeAn($p) // + 4 + la |
|
1368 | + + $this->estimateBitsModeNum($q - $p) + 4 + $ln |
|
1369 | + - $this->estimateBitsModeAn($q); // - 4 - la |
|
1370 | + if ($dif < 0) { |
|
1371 | + break; |
|
1372 | + } else { |
|
1373 | + $p = $q; |
|
1374 | + } |
|
1375 | + } else { |
|
1376 | + $p++; |
|
1377 | + } |
|
1378 | + } |
|
1379 | + $run = $p; |
|
1380 | + if (!$this->isalnumat($this->dataStr, $p)) { |
|
1381 | + $dif = $this->estimateBitsModeAn($run) + 4 + $la |
|
1382 | + + $this->estimateBitsMode8(1) // + 4 + l8 |
|
1383 | + - $this->estimateBitsMode8($run + 1); // - 4 - l8 |
|
1384 | + if ($dif > 0) { |
|
1385 | + return $this->eat8(); |
|
1386 | + } |
|
1387 | + } |
|
1388 | + $this->items = $this->appendNewInputItem($this->items, QR_MODE_AN, $run, str_split($this->dataStr)); |
|
1389 | + return $run; |
|
1390 | + } |
|
1391 | + |
|
1392 | + /** |
|
1393 | + * eatKanji |
|
1394 | + * @return int run |
|
1395 | + */ |
|
1396 | + protected function eatKanji() { |
|
1397 | + $p = 0; |
|
1398 | + while($this->identifyMode($p) == QR_MODE_KJ) { |
|
1399 | + $p += 2; |
|
1400 | + } |
|
1401 | + $this->items = $this->appendNewInputItem($this->items, QR_MODE_KJ, $p, str_split($this->dataStr)); |
|
1402 | + return $p; |
|
1403 | + } |
|
1404 | + |
|
1405 | + /** |
|
1406 | + * eat8 |
|
1407 | + * @return int run |
|
1408 | + */ |
|
1409 | + protected function eat8() { |
|
1410 | + $la = $this->lengthIndicator(QR_MODE_AN, $this->version); |
|
1411 | + $ln = $this->lengthIndicator(QR_MODE_NM, $this->version); |
|
1412 | + $p = 1; |
|
1413 | + $dataStrLen = strlen($this->dataStr); |
|
1414 | + while($p < $dataStrLen) { |
|
1415 | + $mode = $this->identifyMode($p); |
|
1416 | + if ($mode == QR_MODE_KJ) { |
|
1417 | + break; |
|
1418 | + } |
|
1419 | + if ($mode == QR_MODE_NM) { |
|
1420 | + $q = $p; |
|
1421 | + while($this->isdigitat($this->dataStr, $q)) { |
|
1422 | + $q++; |
|
1423 | + } |
|
1424 | + $dif = $this->estimateBitsMode8($p) // + 4 + l8 |
|
1425 | + + $this->estimateBitsModeNum($q - $p) + 4 + $ln |
|
1426 | + - $this->estimateBitsMode8($q); // - 4 - l8 |
|
1427 | + if ($dif < 0) { |
|
1428 | + break; |
|
1429 | + } else { |
|
1430 | + $p = $q; |
|
1431 | + } |
|
1432 | + } elseif ($mode == QR_MODE_AN) { |
|
1433 | + $q = $p; |
|
1434 | + while($this->isalnumat($this->dataStr, $q)) { |
|
1435 | + $q++; |
|
1436 | + } |
|
1437 | + $dif = $this->estimateBitsMode8($p) // + 4 + l8 |
|
1438 | + + $this->estimateBitsModeAn($q - $p) + 4 + $la |
|
1439 | + - $this->estimateBitsMode8($q); // - 4 - l8 |
|
1440 | + if ($dif < 0) { |
|
1441 | + break; |
|
1442 | + } else { |
|
1443 | + $p = $q; |
|
1444 | + } |
|
1445 | + } else { |
|
1446 | + $p++; |
|
1447 | + } |
|
1448 | + } |
|
1449 | + $run = $p; |
|
1450 | + $this->items = $this->appendNewInputItem($this->items, QR_MODE_8B, $run, str_split($this->dataStr)); |
|
1451 | + return $run; |
|
1452 | + } |
|
1453 | + |
|
1454 | + /** |
|
1455 | + * splitString |
|
1456 | + */ |
|
1457 | + protected function splitString() { |
|
1458 | + while (strlen($this->dataStr) > 0) { |
|
1459 | + if ($this->dataStr == '') { |
|
1460 | + return 0; |
|
1461 | + } |
|
1462 | + $mode = $this->identifyMode(0); |
|
1463 | + switch ($mode) { |
|
1464 | + case QR_MODE_NM: { |
|
1465 | + $length = $this->eatNum(); |
|
1466 | + break; |
|
1467 | + } |
|
1468 | + case QR_MODE_AN: { |
|
1469 | + $length = $this->eatAn(); |
|
1470 | + break; |
|
1471 | + } |
|
1472 | + case QR_MODE_KJ: { |
|
1473 | + if ($this->hint == QR_MODE_KJ) { |
|
1474 | + $length = $this->eatKanji(); |
|
1475 | + } else { |
|
1476 | + $length = $this->eat8(); |
|
1477 | + } |
|
1478 | + break; |
|
1479 | + } |
|
1480 | + default: { |
|
1481 | + $length = $this->eat8(); |
|
1482 | + break; |
|
1483 | + } |
|
1484 | + } |
|
1485 | + if ($length == 0) { |
|
1486 | + return 0; |
|
1487 | + } |
|
1488 | + if ($length < 0) { |
|
1489 | + return -1; |
|
1490 | + } |
|
1491 | + $this->dataStr = substr($this->dataStr, $length); |
|
1492 | + } |
|
1493 | + } |
|
1494 | + |
|
1495 | + /** |
|
1496 | + * toUpper |
|
1497 | + */ |
|
1498 | + protected function toUpper() { |
|
1499 | + $stringLen = strlen($this->dataStr); |
|
1500 | + $p = 0; |
|
1501 | + while ($p < $stringLen) { |
|
1502 | + $mode = $this->identifyMode(substr($this->dataStr, $p)); |
|
1503 | + if ($mode == QR_MODE_KJ) { |
|
1504 | + $p += 2; |
|
1505 | + } else { |
|
1506 | + if ((ord($this->dataStr[$p]) >= ord('a')) and (ord($this->dataStr[$p]) <= ord('z'))) { |
|
1507 | + $this->dataStr[$p] = chr(ord($this->dataStr[$p]) - 32); |
|
1508 | + } |
|
1509 | + $p++; |
|
1510 | + } |
|
1511 | + } |
|
1512 | + return $this->dataStr; |
|
1513 | + } |
|
1514 | + |
|
1515 | + // - - - - - - - - - - - - - - - - - - - - - - - - - |
|
1516 | + |
|
1517 | + // QRinputItem |
|
1518 | + |
|
1519 | + /** |
|
1520 | + * newInputItem |
|
1521 | + * @param int $mode |
|
1522 | + * @param int $size |
|
1523 | + * @param array $data |
|
1524 | + * @param array $bstream |
|
1525 | + * @return array input item |
|
1526 | + */ |
|
1527 | + protected function newInputItem($mode, $size, $data, $bstream=null) { |
|
1528 | + $setData = array_slice($data, 0, $size); |
|
1529 | + if (count($setData) < $size) { |
|
1530 | + $setData = array_merge($setData, array_fill(0, ($size - count($setData)), 0)); |
|
1531 | + } |
|
1532 | + if (!$this->check($mode, $size, $setData)) { |
|
1533 | + return null; |
|
1534 | + } |
|
1535 | + $inputitem = array(); |
|
1536 | + $inputitem['mode'] = $mode; |
|
1537 | + $inputitem['size'] = $size; |
|
1538 | + $inputitem['data'] = $setData; |
|
1539 | + $inputitem['bstream'] = $bstream; |
|
1540 | + return $inputitem; |
|
1541 | + } |
|
1542 | + |
|
1543 | + /** |
|
1544 | + * encodeModeNum |
|
1545 | + * @param array $inputitem |
|
1546 | + * @param int $version |
|
1547 | + * @return array input item |
|
1548 | + */ |
|
1549 | + protected function encodeModeNum($inputitem, $version) { |
|
1550 | + $words = (int)($inputitem['size'] / 3); |
|
1551 | + $inputitem['bstream'] = array(); |
|
1552 | + $val = 0x1; |
|
1553 | + $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, $val); |
|
1554 | + $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_NM, $version), $inputitem['size']); |
|
1555 | + for ($i=0; $i < $words; ++$i) { |
|
1556 | + $val = (ord($inputitem['data'][$i*3 ]) - ord('0')) * 100; |
|
1557 | + $val += (ord($inputitem['data'][$i*3+1]) - ord('0')) * 10; |
|
1558 | + $val += (ord($inputitem['data'][$i*3+2]) - ord('0')); |
|
1559 | + $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 10, $val); |
|
1560 | + } |
|
1561 | + if ($inputitem['size'] - $words * 3 == 1) { |
|
1562 | + $val = ord($inputitem['data'][$words*3]) - ord('0'); |
|
1563 | + $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, $val); |
|
1564 | + } elseif (($inputitem['size'] - ($words * 3)) == 2) { |
|
1565 | + $val = (ord($inputitem['data'][$words*3 ]) - ord('0')) * 10; |
|
1566 | + $val += (ord($inputitem['data'][$words*3+1]) - ord('0')); |
|
1567 | + $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 7, $val); |
|
1568 | + } |
|
1569 | + return $inputitem; |
|
1570 | + } |
|
1571 | + |
|
1572 | + /** |
|
1573 | + * encodeModeAn |
|
1574 | + * @param array $inputitem |
|
1575 | + * @param int $version |
|
1576 | + * @return array input item |
|
1577 | + */ |
|
1578 | + protected function encodeModeAn($inputitem, $version) { |
|
1579 | + $words = (int)($inputitem['size'] / 2); |
|
1580 | + $inputitem['bstream'] = array(); |
|
1581 | + $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x02); |
|
1582 | + $inputitem['bstream'] = $this->appendNum(v, $this->lengthIndicator(QR_MODE_AN, $version), $inputitem['size']); |
|
1583 | + for ($i=0; $i < $words; ++$i) { |
|
1584 | + $val = (int)$this->lookAnTable(ord($inputitem['data'][$i*2 ])) * 45; |
|
1585 | + $val += (int)$this->lookAnTable(ord($inputitem['data'][$i*2+1])); |
|
1586 | + $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 11, $val); |
|
1587 | + } |
|
1588 | + if ($inputitem['size'] & 1) { |
|
1589 | + $val = $this->lookAnTable(ord($inputitem['data'][($words * 2)])); |
|
1590 | + $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 6, $val); |
|
1591 | + } |
|
1592 | + return $inputitem; |
|
1593 | + } |
|
1594 | + |
|
1595 | + /** |
|
1596 | + * encodeMode8 |
|
1597 | + * @param array $inputitem |
|
1598 | + * @param int $version |
|
1599 | + * @return array input item |
|
1600 | + */ |
|
1601 | + protected function encodeMode8($inputitem, $version) { |
|
1602 | + $inputitem['bstream'] = array(); |
|
1603 | + $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x4); |
|
1604 | + $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_8B, $version), $inputitem['size']); |
|
1605 | + for ($i=0; $i < $inputitem['size']; ++$i) { |
|
1606 | + $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 8, ord($inputitem['data'][$i])); |
|
1607 | + } |
|
1608 | + return $inputitem; |
|
1609 | + } |
|
1610 | + |
|
1611 | + /** |
|
1612 | + * encodeModeKanji |
|
1613 | + * @param array $inputitem |
|
1614 | + * @param int $version |
|
1615 | + * @return array input item |
|
1616 | + */ |
|
1617 | + protected function encodeModeKanji($inputitem, $version) { |
|
1618 | + $inputitem['bstream'] = array(); |
|
1619 | + $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x8); |
|
1620 | + $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_KJ, $version), (int)($inputitem['size'] / 2)); |
|
1621 | + for ($i=0; $i<$inputitem['size']; $i+=2) { |
|
1622 | + $val = (ord($inputitem['data'][$i]) << 8) | ord($inputitem['data'][$i+1]); |
|
1623 | + if ($val <= 0x9ffc) { |
|
1624 | + $val -= 0x8140; |
|
1625 | + } else { |
|
1626 | + $val -= 0xc140; |
|
1627 | + } |
|
1628 | + $h = ($val >> 8) * 0xc0; |
|
1629 | + $val = ($val & 0xff) + $h; |
|
1630 | + $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 13, $val); |
|
1631 | + } |
|
1632 | + return $inputitem; |
|
1633 | + } |
|
1634 | + |
|
1635 | + /** |
|
1636 | + * encodeModeStructure |
|
1637 | + * @param array $inputitem |
|
1638 | + * @return array input item |
|
1639 | + */ |
|
1640 | + protected function encodeModeStructure($inputitem) { |
|
1641 | + $inputitem['bstream'] = array(); |
|
1642 | + $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x03); |
|
1643 | + $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, ord($inputitem['data'][1]) - 1); |
|
1644 | + $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, ord($inputitem['data'][0]) - 1); |
|
1645 | + $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 8, ord($inputitem['data'][2])); |
|
1646 | + return $inputitem; |
|
1647 | + } |
|
1648 | + |
|
1649 | + /** |
|
1650 | + * encodeBitStream |
|
1651 | + * @param array $inputitem |
|
1652 | + * @param int $version |
|
1653 | + * @return array input item |
|
1654 | + */ |
|
1655 | + protected function encodeBitStream($inputitem, $version) { |
|
1656 | + $inputitem['bstream'] = array(); |
|
1657 | + $words = $this->maximumWords($inputitem['mode'], $version); |
|
1658 | + if ($inputitem['size'] > $words) { |
|
1659 | + $st1 = $this->newInputItem($inputitem['mode'], $words, $inputitem['data']); |
|
1660 | + $st2 = $this->newInputItem($inputitem['mode'], $inputitem['size'] - $words, array_slice($inputitem['data'], $words)); |
|
1661 | + $st1 = $this->encodeBitStream($st1, $version); |
|
1662 | + $st2 = $this->encodeBitStream($st2, $version); |
|
1663 | + $inputitem['bstream'] = array(); |
|
1664 | + $inputitem['bstream'] = $this->appendBitstream($inputitem['bstream'], $st1['bstream']); |
|
1665 | + $inputitem['bstream'] = $this->appendBitstream($inputitem['bstream'], $st2['bstream']); |
|
1666 | + } else { |
|
1667 | + switch($inputitem['mode']) { |
|
1668 | + case QR_MODE_NM: { |
|
1669 | + $inputitem = $this->encodeModeNum($inputitem, $version); |
|
1670 | + break; |
|
1671 | + } |
|
1672 | + case QR_MODE_AN: { |
|
1673 | + $inputitem = $this->encodeModeAn($inputitem, $version); |
|
1674 | + break; |
|
1675 | + } |
|
1676 | + case QR_MODE_8B: { |
|
1677 | + $inputitem = $this->encodeMode8($inputitem, $version); |
|
1678 | + break; |
|
1679 | + } |
|
1680 | + case QR_MODE_KJ: { |
|
1681 | + $inputitem = $this->encodeModeKanji($inputitem, $version); |
|
1682 | + break; |
|
1683 | + } |
|
1684 | + case QR_MODE_ST: { |
|
1685 | + $inputitem = $this->encodeModeStructure($inputitem); |
|
1686 | + break; |
|
1687 | + } |
|
1688 | + default: { |
|
1689 | + break; |
|
1690 | + } |
|
1691 | + } |
|
1692 | + } |
|
1693 | + return $inputitem; |
|
1694 | + } |
|
1695 | + |
|
1696 | + // - - - - - - - - - - - - - - - - - - - - - - - - - |
|
1697 | + |
|
1698 | + // QRinput |
|
1699 | + |
|
1700 | + /** |
|
1701 | + * Append data to an input object. |
|
1702 | + * The data is copied and appended to the input object. |
|
1703 | + * @param array items input items |
|
1704 | + * @param int $mode encoding mode. |
|
1705 | + * @param int $size size of data (byte). |
|
1706 | + * @param array $data array of input data. |
|
1707 | + * @return items |
|
1708 | + * |
|
1709 | + */ |
|
1710 | + protected function appendNewInputItem($items, $mode, $size, $data) { |
|
1711 | + $items[] = $this->newInputItem($mode, $size, $data); |
|
1712 | + return $items; |
|
1713 | + } |
|
1714 | + |
|
1715 | + /** |
|
1716 | + * insertStructuredAppendHeader |
|
1717 | + * @param array $items |
|
1718 | + * @param int $size |
|
1719 | + * @param int $index |
|
1720 | + * @param int $parity |
|
1721 | + * @return array items |
|
1722 | + */ |
|
1723 | + protected function insertStructuredAppendHeader($items, $size, $index, $parity) { |
|
1724 | + if ($size > MAX_STRUCTURED_SYMBOLS) { |
|
1725 | + return -1; |
|
1726 | + } |
|
1727 | + if (($index <= 0) or ($index > MAX_STRUCTURED_SYMBOLS)) { |
|
1728 | + return -1; |
|
1729 | + } |
|
1730 | + $buf = array($size, $index, $parity); |
|
1731 | + $entry = $this->newInputItem(QR_MODE_ST, 3, buf); |
|
1732 | + array_unshift($items, $entry); |
|
1733 | + return $items; |
|
1734 | + } |
|
1735 | + |
|
1736 | + /** |
|
1737 | + * calcParity |
|
1738 | + * @param array $items |
|
1739 | + * @return int parity |
|
1740 | + */ |
|
1741 | + protected function calcParity($items) { |
|
1742 | + $parity = 0; |
|
1743 | + foreach ($items as $item) { |
|
1744 | + if ($item['mode'] != QR_MODE_ST) { |
|
1745 | + for ($i=$item['size']-1; $i>=0; --$i) { |
|
1746 | + $parity ^= $item['data'][$i]; |
|
1747 | + } |
|
1748 | + } |
|
1749 | + } |
|
1750 | + return $parity; |
|
1751 | + } |
|
1752 | + |
|
1753 | + /** |
|
1754 | + * checkModeNum |
|
1755 | + * @param int $size |
|
1756 | + * @param array $data |
|
1757 | + * @return boolean true or false |
|
1758 | + */ |
|
1759 | + protected function checkModeNum($size, $data) { |
|
1760 | + for ($i=0; $i<$size; ++$i) { |
|
1761 | + if ((ord($data[$i]) < ord('0')) or (ord($data[$i]) > ord('9'))){ |
|
1762 | + return false; |
|
1763 | + } |
|
1764 | + } |
|
1765 | + return true; |
|
1766 | + } |
|
1767 | + |
|
1768 | + /** |
|
1769 | + * estimateBitsModeNum |
|
1770 | + * @param int $size |
|
1771 | + * @return int number of bits |
|
1772 | + */ |
|
1773 | + protected function estimateBitsModeNum($size) { |
|
1774 | + $w = (int)$size / 3; |
|
1775 | + $bits = $w * 10; |
|
1776 | + switch($size - $w * 3) { |
|
1777 | + case 1: { |
|
1778 | + $bits += 4; |
|
1779 | + break; |
|
1780 | + } |
|
1781 | + case 2: { |
|
1782 | + $bits += 7; |
|
1783 | + break; |
|
1784 | + } |
|
1785 | + default: { |
|
1786 | + break; |
|
1787 | + } |
|
1788 | + } |
|
1789 | + return $bits; |
|
1790 | + } |
|
1791 | + |
|
1792 | + /** |
|
1793 | + * Look up the alphabet-numeric convesion table (see JIS X0510:2004, pp.19). |
|
1794 | + * @param int $c character value |
|
1795 | + * @return value |
|
1796 | + */ |
|
1797 | + protected function lookAnTable($c) { |
|
1798 | + return (($c > 127)?-1:$this->anTable[$c]); |
|
1799 | + } |
|
1800 | + |
|
1801 | + /** |
|
1802 | + * checkModeAn |
|
1803 | + * @param int $size |
|
1804 | + * @param array $data |
|
1805 | + * @return boolean true or false |
|
1806 | + */ |
|
1807 | + protected function checkModeAn($size, $data) { |
|
1808 | + for ($i=0; $i<$size; ++$i) { |
|
1809 | + if ($this->lookAnTable(ord($data[$i])) == -1) { |
|
1810 | + return false; |
|
1811 | + } |
|
1812 | + } |
|
1813 | + return true; |
|
1814 | + } |
|
1815 | + |
|
1816 | + /** |
|
1817 | + * estimateBitsModeAn |
|
1818 | + * @param int $size |
|
1819 | + * @return int number of bits |
|
1820 | + */ |
|
1821 | + protected function estimateBitsModeAn($size) { |
|
1822 | + $w = (int)($size / 2); |
|
1823 | + $bits = $w * 11; |
|
1824 | + if ($size & 1) { |
|
1825 | + $bits += 6; |
|
1826 | + } |
|
1827 | + return $bits; |
|
1828 | + } |
|
1829 | + |
|
1830 | + /** |
|
1831 | + * estimateBitsMode8 |
|
1832 | + * @param int $size |
|
1833 | + * @return int number of bits |
|
1834 | + */ |
|
1835 | + protected function estimateBitsMode8($size) { |
|
1836 | + return $size * 8; |
|
1837 | + } |
|
1838 | + |
|
1839 | + /** |
|
1840 | + * estimateBitsModeKanji |
|
1841 | + * @param int $size |
|
1842 | + * @return int number of bits |
|
1843 | + */ |
|
1844 | + protected function estimateBitsModeKanji($size) { |
|
1845 | + return (int)(($size / 2) * 13); |
|
1846 | + } |
|
1847 | + |
|
1848 | + /** |
|
1849 | + * checkModeKanji |
|
1850 | + * @param int $size |
|
1851 | + * @param array $data |
|
1852 | + * @return boolean true or false |
|
1853 | + */ |
|
1854 | + protected function checkModeKanji($size, $data) { |
|
1855 | + if ($size & 1) { |
|
1856 | + return false; |
|
1857 | + } |
|
1858 | + for ($i=0; $i<$size; $i+=2) { |
|
1859 | + $val = (ord($data[$i]) << 8) | ord($data[$i+1]); |
|
1860 | + if (($val < 0x8140) or (($val > 0x9ffc) and ($val < 0xe040)) or ($val > 0xebbf)) { |
|
1861 | + return false; |
|
1862 | + } |
|
1863 | + } |
|
1864 | + return true; |
|
1865 | + } |
|
1866 | + |
|
1867 | + /** |
|
1868 | + * Validate the input data. |
|
1869 | + * @param int $mode encoding mode. |
|
1870 | + * @param int $size size of data (byte). |
|
1871 | + * @param array data data to validate |
|
1872 | + * @return boolean true in case of valid data, false otherwise |
|
1873 | + */ |
|
1874 | + protected function check($mode, $size, $data) { |
|
1875 | + if ($size <= 0) { |
|
1876 | + return false; |
|
1877 | + } |
|
1878 | + switch($mode) { |
|
1879 | + case QR_MODE_NM: { |
|
1880 | + return $this->checkModeNum($size, $data); |
|
1881 | + } |
|
1882 | + case QR_MODE_AN: { |
|
1883 | + return $this->checkModeAn($size, $data); |
|
1884 | + } |
|
1885 | + case QR_MODE_KJ: { |
|
1886 | + return $this->checkModeKanji($size, $data); |
|
1887 | + } |
|
1888 | + case QR_MODE_8B: { |
|
1889 | + return true; |
|
1890 | + } |
|
1891 | + case QR_MODE_ST: { |
|
1892 | + return true; |
|
1893 | + } |
|
1894 | + default: { |
|
1895 | + break; |
|
1896 | + } |
|
1897 | + } |
|
1898 | + return false; |
|
1899 | + } |
|
1900 | + |
|
1901 | + /** |
|
1902 | + * estimateBitStreamSize |
|
1903 | + * @param array $items |
|
1904 | + * @param int $version |
|
1905 | + * @return int bits |
|
1906 | + */ |
|
1907 | + protected function estimateBitStreamSize($items, $version) { |
|
1908 | + $bits = 0; |
|
1909 | + if ($version == 0) { |
|
1910 | + $version = 1; |
|
1911 | + } |
|
1912 | + foreach ($items as $item) { |
|
1913 | + switch($item['mode']) { |
|
1914 | + case QR_MODE_NM: { |
|
1915 | + $bits = $this->estimateBitsModeNum($item['size']); |
|
1916 | + break; |
|
1917 | + } |
|
1918 | + case QR_MODE_AN: { |
|
1919 | + $bits = $this->estimateBitsModeAn($item['size']); |
|
1920 | + break; |
|
1921 | + } |
|
1922 | + case QR_MODE_8B: { |
|
1923 | + $bits = $this->estimateBitsMode8($item['size']); |
|
1924 | + break; |
|
1925 | + } |
|
1926 | + case QR_MODE_KJ: { |
|
1927 | + $bits = $this->estimateBitsModeKanji($item['size']); |
|
1928 | + break; |
|
1929 | + } |
|
1930 | + case QR_MODE_ST: { |
|
1931 | + return STRUCTURE_HEADER_BITS; |
|
1932 | + } |
|
1933 | + default: { |
|
1934 | + return 0; |
|
1935 | + } |
|
1936 | + } |
|
1937 | + $l = $this->lengthIndicator($item['mode'], $version); |
|
1938 | + $m = 1 << $l; |
|
1939 | + $num = (int)(($item['size'] + $m - 1) / $m); |
|
1940 | + $bits += $num * (4 + $l); |
|
1941 | + } |
|
1942 | + return $bits; |
|
1943 | + } |
|
1944 | + |
|
1945 | + /** |
|
1946 | + * estimateVersion |
|
1947 | + * @param array $items |
|
1948 | + * @return int version |
|
1949 | + */ |
|
1950 | + protected function estimateVersion($items) { |
|
1951 | + $version = 0; |
|
1952 | + $prev = 0; |
|
1953 | + do { |
|
1954 | + $prev = $version; |
|
1955 | + $bits = $this->estimateBitStreamSize($items, $prev); |
|
1956 | + $version = $this->getMinimumVersion((int)(($bits + 7) / 8), $this->level); |
|
1957 | + if ($version < 0) { |
|
1958 | + return -1; |
|
1959 | + } |
|
1960 | + } while ($version > $prev); |
|
1961 | + return $version; |
|
1962 | + } |
|
1963 | + |
|
1964 | + /** |
|
1965 | + * lengthOfCode |
|
1966 | + * @param int $mode |
|
1967 | + * @param int $version |
|
1968 | + * @param int $bits |
|
1969 | + * @return int size |
|
1970 | + */ |
|
1971 | + protected function lengthOfCode($mode, $version, $bits) { |
|
1972 | + $payload = $bits - 4 - $this->lengthIndicator($mode, $version); |
|
1973 | + switch($mode) { |
|
1974 | + case QR_MODE_NM: { |
|
1975 | + $chunks = (int)($payload / 10); |
|
1976 | + $remain = $payload - $chunks * 10; |
|
1977 | + $size = $chunks * 3; |
|
1978 | + if ($remain >= 7) { |
|
1979 | + $size += 2; |
|
1980 | + } elseif ($remain >= 4) { |
|
1981 | + $size += 1; |
|
1982 | + } |
|
1983 | + break; |
|
1984 | + } |
|
1985 | + case QR_MODE_AN: { |
|
1986 | + $chunks = (int)($payload / 11); |
|
1987 | + $remain = $payload - $chunks * 11; |
|
1988 | + $size = $chunks * 2; |
|
1989 | + if ($remain >= 6) { |
|
1990 | + ++$size; |
|
1991 | + } |
|
1992 | + break; |
|
1993 | + } |
|
1994 | + case QR_MODE_8B: { |
|
1995 | + $size = (int)($payload / 8); |
|
1996 | + break; |
|
1997 | + } |
|
1998 | + case QR_MODE_KJ: { |
|
1999 | + $size = (int)(($payload / 13) * 2); |
|
2000 | + break; |
|
2001 | + } |
|
2002 | + case QR_MODE_ST: { |
|
2003 | + $size = (int)($payload / 8); |
|
2004 | + break; |
|
2005 | + } |
|
2006 | + default: { |
|
2007 | + $size = 0; |
|
2008 | + break; |
|
2009 | + } |
|
2010 | + } |
|
2011 | + $maxsize = $this->maximumWords($mode, $version); |
|
2012 | + if ($size < 0) { |
|
2013 | + $size = 0; |
|
2014 | + } |
|
2015 | + if ($size > $maxsize) { |
|
2016 | + $size = $maxsize; |
|
2017 | + } |
|
2018 | + return $size; |
|
2019 | + } |
|
2020 | + |
|
2021 | + /** |
|
2022 | + * createBitStream |
|
2023 | + * @param array $items |
|
2024 | + * @return array of items and total bits |
|
2025 | + */ |
|
2026 | + protected function createBitStream($items) { |
|
2027 | + $total = 0; |
|
2028 | + foreach ($items as $key => $item) { |
|
2029 | + $items[$key] = $this->encodeBitStream($item, $this->version); |
|
2030 | + $bits = count($items[$key]['bstream']); |
|
2031 | + $total += $bits; |
|
2032 | + } |
|
2033 | + return array($items, $total); |
|
2034 | + } |
|
2035 | + |
|
2036 | + /** |
|
2037 | + * convertData |
|
2038 | + * @param array $items |
|
2039 | + * @return array items |
|
2040 | + */ |
|
2041 | + protected function convertData($items) { |
|
2042 | + $ver = $this->estimateVersion($items); |
|
2043 | + if ($ver > $this->version) { |
|
2044 | + $this->version = $ver; |
|
2045 | + } |
|
2046 | + for (;;) { |
|
2047 | + $cbs = $this->createBitStream($items); |
|
2048 | + $items = $cbs[0]; |
|
2049 | + $bits = $cbs[1]; |
|
2050 | + if ($bits < 0) { |
|
2051 | + return -1; |
|
2052 | + } |
|
2053 | + $ver = $this->getMinimumVersion((int)(($bits + 7) / 8), $this->level); |
|
2054 | + if ($ver < 0) { |
|
2055 | + return -1; |
|
2056 | + } elseif ($ver > $this->version) { |
|
2057 | + $this->version = $ver; |
|
2058 | + } else { |
|
2059 | + break; |
|
2060 | + } |
|
2061 | + } |
|
2062 | + return $items; |
|
2063 | + } |
|
2064 | + |
|
2065 | + /** |
|
2066 | + * Append Padding Bit to bitstream |
|
2067 | + * @param array $bstream |
|
2068 | + * @return array bitstream |
|
2069 | + */ |
|
2070 | + protected function appendPaddingBit($bstream) { |
|
2071 | + $bits = count($bstream); |
|
2072 | + $maxwords = $this->getDataLength($this->version, $this->level); |
|
2073 | + $maxbits = $maxwords * 8; |
|
2074 | + if ($maxbits == $bits) { |
|
2075 | + return 0; |
|
2076 | + } |
|
2077 | + if ($maxbits - $bits < 5) { |
|
2078 | + return $this->appendNum($bstream, $maxbits - $bits, 0); |
|
2079 | + } |
|
2080 | + $bits += 4; |
|
2081 | + $words = (int)(($bits + 7) / 8); |
|
2082 | + $padding = array(); |
|
2083 | + $padding = $this->appendNum($padding, $words * 8 - $bits + 4, 0); |
|
2084 | + $padlen = $maxwords - $words; |
|
2085 | + if ($padlen > 0) { |
|
2086 | + $padbuf = array(); |
|
2087 | + for ($i=0; $i<$padlen; ++$i) { |
|
2088 | + $padbuf[$i] = ($i&1)?0x11:0xec; |
|
2089 | + } |
|
2090 | + $padding = $this->appendBytes($padding, $padlen, $padbuf); |
|
2091 | + } |
|
2092 | + return $this->appendBitstream($bstream, $padding); |
|
2093 | + } |
|
2094 | + |
|
2095 | + /** |
|
2096 | + * mergeBitStream |
|
2097 | + * @param array $bstream |
|
2098 | + * @return array bitstream |
|
2099 | + */ |
|
2100 | + protected function mergeBitStream($items) { |
|
2101 | + $items = $this->convertData($items); |
|
2102 | + $bstream = array(); |
|
2103 | + foreach ($items as $item) { |
|
2104 | + $bstream = $this->appendBitstream($bstream, $item['bstream']); |
|
2105 | + } |
|
2106 | + return $bstream; |
|
2107 | + } |
|
2108 | + |
|
2109 | + /** |
|
2110 | + * Returns a stream of bits. |
|
2111 | + * @param int $items |
|
2112 | + * @return array padded merged byte stream |
|
2113 | + */ |
|
2114 | + protected function getBitStream($items) { |
|
2115 | + $bstream = $this->mergeBitStream($items); |
|
2116 | + return $this->appendPaddingBit($bstream); |
|
2117 | + } |
|
2118 | + |
|
2119 | + /** |
|
2120 | + * Pack all bit streams padding bits into a byte array. |
|
2121 | + * @param int $items |
|
2122 | + * @return array padded merged byte stream |
|
2123 | + */ |
|
2124 | + protected function getByteStream($items) { |
|
2125 | + $bstream = $this->getBitStream($items); |
|
2126 | + return $this->bitstreamToByte($bstream); |
|
2127 | + } |
|
2128 | + |
|
2129 | + // - - - - - - - - - - - - - - - - - - - - - - - - - |
|
2130 | + |
|
2131 | + // QRbitstream |
|
2132 | + |
|
2133 | + /** |
|
2134 | + * Return an array with zeros |
|
2135 | + * @param int $setLength array size |
|
2136 | + * @return array |
|
2137 | + */ |
|
2138 | + protected function allocate($setLength) { |
|
2139 | + return array_fill(0, $setLength, 0); |
|
2140 | + } |
|
2141 | + |
|
2142 | + /** |
|
2143 | + * Return new bitstream from number |
|
2144 | + * @param int $bits number of bits |
|
2145 | + * @param int $num number |
|
2146 | + * @return array bitstream |
|
2147 | + */ |
|
2148 | + protected function newFromNum($bits, $num) { |
|
2149 | + $bstream = $this->allocate($bits); |
|
2150 | + $mask = 1 << ($bits - 1); |
|
2151 | + for ($i=0; $i<$bits; ++$i) { |
|
2152 | + if ($num & $mask) { |
|
2153 | + $bstream[$i] = 1; |
|
2154 | + } else { |
|
2155 | + $bstream[$i] = 0; |
|
2156 | + } |
|
2157 | + $mask = $mask >> 1; |
|
2158 | + } |
|
2159 | + return $bstream; |
|
2160 | + } |
|
2161 | + |
|
2162 | + /** |
|
2163 | + * Return new bitstream from bytes |
|
2164 | + * @param int $size size |
|
2165 | + * @param array $data bytes |
|
2166 | + * @return array bitstream |
|
2167 | + */ |
|
2168 | + protected function newFromBytes($size, $data) { |
|
2169 | + $bstream = $this->allocate($size * 8); |
|
2170 | + $p=0; |
|
2171 | + for ($i=0; $i<$size; ++$i) { |
|
2172 | + $mask = 0x80; |
|
2173 | + for ($j=0; $j<8; ++$j) { |
|
2174 | + if ($data[$i] & $mask) { |
|
2175 | + $bstream[$p] = 1; |
|
2176 | + } else { |
|
2177 | + $bstream[$p] = 0; |
|
2178 | + } |
|
2179 | + $p++; |
|
2180 | + $mask = $mask >> 1; |
|
2181 | + } |
|
2182 | + } |
|
2183 | + return $bstream; |
|
2184 | + } |
|
2185 | + |
|
2186 | + /** |
|
2187 | + * Append one bitstream to another |
|
2188 | + * @param array $bitstream original bitstream |
|
2189 | + * @param array $append bitstream to append |
|
2190 | + * @return array bitstream |
|
2191 | + */ |
|
2192 | + protected function appendBitstream($bitstream, $append) { |
|
2193 | + if ((!is_array($append)) or (count($append) == 0)) { |
|
2194 | + return $bitstream; |
|
2195 | + } |
|
2196 | + if (count($bitstream) == 0) { |
|
2197 | + return $append; |
|
2198 | + } |
|
2199 | + return array_values(array_merge($bitstream, $append)); |
|
2200 | + } |
|
2201 | + |
|
2202 | + /** |
|
2203 | + * Append one bitstream created from number to another |
|
2204 | + * @param array $bitstream original bitstream |
|
2205 | + * @param int $bits number of bits |
|
2206 | + * @param int $num number |
|
2207 | + * @return array bitstream |
|
2208 | + */ |
|
2209 | + protected function appendNum($bitstream, $bits, $num) { |
|
2210 | + if ($bits == 0) { |
|
2211 | + return 0; |
|
2212 | + } |
|
2213 | + $b = $this->newFromNum($bits, $num); |
|
2214 | + return $this->appendBitstream($bitstream, $b); |
|
2215 | + } |
|
2216 | + |
|
2217 | + /** |
|
2218 | + * Append one bitstream created from bytes to another |
|
2219 | + * @param array $bitstream original bitstream |
|
2220 | + * @param int $size size |
|
2221 | + * @param array $data bytes |
|
2222 | + * @return array bitstream |
|
2223 | + */ |
|
2224 | + protected function appendBytes($bitstream, $size, $data) { |
|
2225 | + if ($size == 0) { |
|
2226 | + return 0; |
|
2227 | + } |
|
2228 | + $b = $this->newFromBytes($size, $data); |
|
2229 | + return $this->appendBitstream($bitstream, $b); |
|
2230 | + } |
|
2231 | + |
|
2232 | + /** |
|
2233 | + * Convert bitstream to bytes |
|
2234 | + * @param array $bitstream original bitstream |
|
2235 | + * @return array of bytes |
|
2236 | + */ |
|
2237 | + protected function bitstreamToByte($bstream) { |
|
2238 | + $size = count($bstream); |
|
2239 | + if ($size == 0) { |
|
2240 | + return array(); |
|
2241 | + } |
|
2242 | + $data = array_fill(0, (int)(($size + 7) / 8), 0); |
|
2243 | + $bytes = (int)($size / 8); |
|
2244 | + $p = 0; |
|
2245 | + for ($i=0; $i<$bytes; $i++) { |
|
2246 | + $v = 0; |
|
2247 | + for ($j=0; $j<8; $j++) { |
|
2248 | + $v = $v << 1; |
|
2249 | + $v |= $bstream[$p]; |
|
2250 | + $p++; |
|
2251 | + } |
|
2252 | + $data[$i] = $v; |
|
2253 | + } |
|
2254 | + if ($size & 7) { |
|
2255 | + $v = 0; |
|
2256 | + for ($j=0; $j<($size & 7); $j++) { |
|
2257 | + $v = $v << 1; |
|
2258 | + $v |= $bstream[$p]; |
|
2259 | + $p++; |
|
2260 | + } |
|
2261 | + $data[$bytes] = $v; |
|
2262 | + } |
|
2263 | + return $data; |
|
2264 | + } |
|
2265 | + |
|
2266 | + // - - - - - - - - - - - - - - - - - - - - - - - - - |
|
2267 | + |
|
2268 | + // QRspec |
|
2269 | + |
|
2270 | + /** |
|
2271 | + * Replace a value on the array at the specified position |
|
2272 | + * @param array $srctab |
|
2273 | + * @param int $x X position |
|
2274 | + * @param int $y Y position |
|
2275 | + * @param string $repl value to replace |
|
2276 | + * @param int $replLen length of the repl string |
|
2277 | + * @return array srctab |
|
2278 | + */ |
|
2279 | + protected function qrstrset($srctab, $x, $y, $repl, $replLen=false) { |
|
2280 | + $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl)); |
|
2281 | + return $srctab; |
|
2282 | + } |
|
2283 | + |
|
2284 | + /** |
|
2285 | + * Return maximum data code length (bytes) for the version. |
|
2286 | + * @param int $version version |
|
2287 | + * @param int $level error correction level |
|
2288 | + * @return int maximum size (bytes) |
|
2289 | + */ |
|
2290 | + protected function getDataLength($version, $level) { |
|
2291 | + return $this->capacity[$version][QRCAP_WORDS] - $this->capacity[$version][QRCAP_EC][$level]; |
|
2292 | + } |
|
2293 | + |
|
2294 | + /** |
|
2295 | + * Return maximum error correction code length (bytes) for the version. |
|
2296 | + * @param int $version version |
|
2297 | + * @param int $level error correction level |
|
2298 | + * @return int ECC size (bytes) |
|
2299 | + */ |
|
2300 | + protected function getECCLength($version, $level){ |
|
2301 | + return $this->capacity[$version][QRCAP_EC][$level]; |
|
2302 | + } |
|
2303 | + |
|
2304 | + /** |
|
2305 | + * Return the width of the symbol for the version. |
|
2306 | + * @param int $version version |
|
2307 | + * @return int width |
|
2308 | + */ |
|
2309 | + protected function getWidth($version) { |
|
2310 | + return $this->capacity[$version][QRCAP_WIDTH]; |
|
2311 | + } |
|
2312 | + |
|
2313 | + /** |
|
2314 | + * Return the numer of remainder bits. |
|
2315 | + * @param int $version version |
|
2316 | + * @return int number of remainder bits |
|
2317 | + */ |
|
2318 | + protected function getRemainder($version) { |
|
2319 | + return $this->capacity[$version][QRCAP_REMINDER]; |
|
2320 | + } |
|
2321 | + |
|
2322 | + /** |
|
2323 | + * Return a version number that satisfies the input code length. |
|
2324 | + * @param int $size input code length (byte) |
|
2325 | + * @param int $level error correction level |
|
2326 | + * @return int version number |
|
2327 | + */ |
|
2328 | + protected function getMinimumVersion($size, $level) { |
|
2329 | + for ($i=1; $i <= QRSPEC_VERSION_MAX; ++$i) { |
|
2330 | + $words = $this->capacity[$i][QRCAP_WORDS] - $this->capacity[$i][QRCAP_EC][$level]; |
|
2331 | + if ($words >= $size) { |
|
2332 | + return $i; |
|
2333 | + } |
|
2334 | + } |
|
2335 | + return -1; |
|
2336 | + } |
|
2337 | + |
|
2338 | + /** |
|
2339 | + * Return the size of length indicator for the mode and version. |
|
2340 | + * @param int $mode encoding mode |
|
2341 | + * @param int $version version |
|
2342 | + * @return int the size of the appropriate length indicator (bits). |
|
2343 | + */ |
|
2344 | + protected function lengthIndicator($mode, $version) { |
|
2345 | + if ($mode == QR_MODE_ST) { |
|
2346 | + return 0; |
|
2347 | + } |
|
2348 | + if ($version <= 9) { |
|
2349 | + $l = 0; |
|
2350 | + } elseif ($version <= 26) { |
|
2351 | + $l = 1; |
|
2352 | + } else { |
|
2353 | + $l = 2; |
|
2354 | + } |
|
2355 | + return $this->lengthTableBits[$mode][$l]; |
|
2356 | + } |
|
2357 | + |
|
2358 | + /** |
|
2359 | + * Return the maximum length for the mode and version. |
|
2360 | + * @param int $mode encoding mode |
|
2361 | + * @param int $version version |
|
2362 | + * @return int the maximum length (bytes) |
|
2363 | + */ |
|
2364 | + protected function maximumWords($mode, $version) { |
|
2365 | + if ($mode == QR_MODE_ST) { |
|
2366 | + return 3; |
|
2367 | + } |
|
2368 | + if ($version <= 9) { |
|
2369 | + $l = 0; |
|
2370 | + } else if ($version <= 26) { |
|
2371 | + $l = 1; |
|
2372 | + } else { |
|
2373 | + $l = 2; |
|
2374 | + } |
|
2375 | + $bits = $this->lengthTableBits[$mode][$l]; |
|
2376 | + $words = (1 << $bits) - 1; |
|
2377 | + if ($mode == QR_MODE_KJ) { |
|
2378 | + $words *= 2; // the number of bytes is required |
|
2379 | + } |
|
2380 | + return $words; |
|
2381 | + } |
|
2382 | + |
|
2383 | + /** |
|
2384 | + * Return an array of ECC specification. |
|
2385 | + * @param int $version version |
|
2386 | + * @param int $level error correction level |
|
2387 | + * @param array $spec an array of ECC specification contains as following: {# of type1 blocks, # of data code, # of ecc code, # of type2 blocks, # of data code} |
|
2388 | + * @return array spec |
|
2389 | + */ |
|
2390 | + protected function getEccSpec($version, $level, $spec) { |
|
2391 | + if (count($spec) < 5) { |
|
2392 | + $spec = array(0, 0, 0, 0, 0); |
|
2393 | + } |
|
2394 | + $b1 = $this->eccTable[$version][$level][0]; |
|
2395 | + $b2 = $this->eccTable[$version][$level][1]; |
|
2396 | + $data = $this->getDataLength($version, $level); |
|
2397 | + $ecc = $this->getECCLength($version, $level); |
|
2398 | + if ($b2 == 0) { |
|
2399 | + $spec[0] = $b1; |
|
2400 | + $spec[1] = (int)($data / $b1); |
|
2401 | + $spec[2] = (int)($ecc / $b1); |
|
2402 | + $spec[3] = 0; |
|
2403 | + $spec[4] = 0; |
|
2404 | + } else { |
|
2405 | + $spec[0] = $b1; |
|
2406 | + $spec[1] = (int)($data / ($b1 + $b2)); |
|
2407 | + $spec[2] = (int)($ecc / ($b1 + $b2)); |
|
2408 | + $spec[3] = $b2; |
|
2409 | + $spec[4] = $spec[1] + 1; |
|
2410 | + } |
|
2411 | + return $spec; |
|
2412 | + } |
|
2413 | + |
|
2414 | + /** |
|
2415 | + * Put an alignment marker. |
|
2416 | + * @param array $frame frame |
|
2417 | + * @param int $width width |
|
2418 | + * @param int $ox X center coordinate of the pattern |
|
2419 | + * @param int $oy Y center coordinate of the pattern |
|
2420 | + * @return array frame |
|
2421 | + */ |
|
2422 | + protected function putAlignmentMarker($frame, $ox, $oy) { |
|
2423 | + $finder = array( |
|
2424 | + "\xa1\xa1\xa1\xa1\xa1", |
|
2425 | + "\xa1\xa0\xa0\xa0\xa1", |
|
2426 | + "\xa1\xa0\xa1\xa0\xa1", |
|
2427 | + "\xa1\xa0\xa0\xa0\xa1", |
|
2428 | + "\xa1\xa1\xa1\xa1\xa1" |
|
2429 | + ); |
|
2430 | + $yStart = $oy - 2; |
|
2431 | + $xStart = $ox - 2; |
|
2432 | + for ($y=0; $y < 5; $y++) { |
|
2433 | + $frame = $this->qrstrset($frame, $xStart, $yStart+$y, $finder[$y]); |
|
2434 | + } |
|
2435 | + return $frame; |
|
2436 | + } |
|
2437 | + |
|
2438 | + /** |
|
2439 | + * Put an alignment pattern. |
|
2440 | + * @param int $version version |
|
2441 | + * @param array $fram frame |
|
2442 | + * @param int $width width |
|
2443 | + * @return array frame |
|
2444 | + */ |
|
2445 | + protected function putAlignmentPattern($version, $frame, $width) { |
|
2446 | + if ($version < 2) { |
|
2447 | + return $frame; |
|
2448 | + } |
|
2449 | + $d = $this->alignmentPattern[$version][1] - $this->alignmentPattern[$version][0]; |
|
2450 | + if ($d < 0) { |
|
2451 | + $w = 2; |
|
2452 | + } else { |
|
2453 | + $w = (int)(($width - $this->alignmentPattern[$version][0]) / $d + 2); |
|
2454 | + } |
|
2455 | + if ($w * $w - 3 == 1) { |
|
2456 | + $x = $this->alignmentPattern[$version][0]; |
|
2457 | + $y = $this->alignmentPattern[$version][0]; |
|
2458 | + $frame = $this->putAlignmentMarker($frame, $x, $y); |
|
2459 | + return $frame; |
|
2460 | + } |
|
2461 | + $cx = $this->alignmentPattern[$version][0]; |
|
2462 | + $wo = $w - 1; |
|
2463 | + for ($x=1; $x < $wo; ++$x) { |
|
2464 | + $frame = $this->putAlignmentMarker($frame, 6, $cx); |
|
2465 | + $frame = $this->putAlignmentMarker($frame, $cx, 6); |
|
2466 | + $cx += $d; |
|
2467 | + } |
|
2468 | + $cy = $this->alignmentPattern[$version][0]; |
|
2469 | + for ($y=0; $y < $wo; ++$y) { |
|
2470 | + $cx = $this->alignmentPattern[$version][0]; |
|
2471 | + for ($x=0; $x < $wo; ++$x) { |
|
2472 | + $frame = $this->putAlignmentMarker($frame, $cx, $cy); |
|
2473 | + $cx += $d; |
|
2474 | + } |
|
2475 | + $cy += $d; |
|
2476 | + } |
|
2477 | + return $frame; |
|
2478 | + } |
|
2479 | + |
|
2480 | + /** |
|
2481 | + * Return BCH encoded version information pattern that is used for the symbol of version 7 or greater. Use lower 18 bits. |
|
2482 | + * @param int $version version |
|
2483 | + * @return BCH encoded version information pattern |
|
2484 | + */ |
|
2485 | + protected function getVersionPattern($version) { |
|
2486 | + if (($version < 7) or ($version > QRSPEC_VERSION_MAX)) { |
|
2487 | + return 0; |
|
2488 | + } |
|
2489 | + return $this->versionPattern[($version - 7)]; |
|
2490 | + } |
|
2491 | + |
|
2492 | + /** |
|
2493 | + * Return BCH encoded format information pattern. |
|
2494 | + * @param array $mask |
|
2495 | + * @param int $level error correction level |
|
2496 | + * @return BCH encoded format information pattern |
|
2497 | + */ |
|
2498 | + protected function getFormatInfo($mask, $level) { |
|
2499 | + if (($mask < 0) or ($mask > 7)) { |
|
2500 | + return 0; |
|
2501 | + } |
|
2502 | + if (($level < 0) or ($level > 3)) { |
|
2503 | + return 0; |
|
2504 | + } |
|
2505 | + return $this->formatInfo[$level][$mask]; |
|
2506 | + } |
|
2507 | + |
|
2508 | + /** |
|
2509 | + * Put a finder pattern. |
|
2510 | + * @param array $frame frame |
|
2511 | + * @param int $width width |
|
2512 | + * @param int $ox X center coordinate of the pattern |
|
2513 | + * @param int $oy Y center coordinate of the pattern |
|
2514 | + * @return array frame |
|
2515 | + */ |
|
2516 | + protected function putFinderPattern($frame, $ox, $oy) { |
|
2517 | + $finder = array( |
|
2518 | + "\xc1\xc1\xc1\xc1\xc1\xc1\xc1", |
|
2519 | + "\xc1\xc0\xc0\xc0\xc0\xc0\xc1", |
|
2520 | + "\xc1\xc0\xc1\xc1\xc1\xc0\xc1", |
|
2521 | + "\xc1\xc0\xc1\xc1\xc1\xc0\xc1", |
|
2522 | + "\xc1\xc0\xc1\xc1\xc1\xc0\xc1", |
|
2523 | + "\xc1\xc0\xc0\xc0\xc0\xc0\xc1", |
|
2524 | + "\xc1\xc1\xc1\xc1\xc1\xc1\xc1" |
|
2525 | + ); |
|
2526 | + for ($y=0; $y < 7; $y++) { |
|
2527 | + $frame = $this->qrstrset($frame, $ox, ($oy + $y), $finder[$y]); |
|
2528 | + } |
|
2529 | + return $frame; |
|
2530 | + } |
|
2531 | + |
|
2532 | + /** |
|
2533 | + * Return a copy of initialized frame. |
|
2534 | + * @param int $version version |
|
2535 | + * @return Array of unsigned char. |
|
2536 | + */ |
|
2537 | + protected function createFrame($version) { |
|
2538 | + $width = $this->capacity[$version][QRCAP_WIDTH]; |
|
2539 | + $frameLine = str_repeat ("\0", $width); |
|
2540 | + $frame = array_fill(0, $width, $frameLine); |
|
2541 | + // Finder pattern |
|
2542 | + $frame = $this->putFinderPattern($frame, 0, 0); |
|
2543 | + $frame = $this->putFinderPattern($frame, $width - 7, 0); |
|
2544 | + $frame = $this->putFinderPattern($frame, 0, $width - 7); |
|
2545 | + // Separator |
|
2546 | + $yOffset = $width - 7; |
|
2547 | + for ($y=0; $y < 7; ++$y) { |
|
2548 | + $frame[$y][7] = "\xc0"; |
|
2549 | + $frame[$y][$width - 8] = "\xc0"; |
|
2550 | + $frame[$yOffset][7] = "\xc0"; |
|
2551 | + ++$yOffset; |
|
2552 | + } |
|
2553 | + $setPattern = str_repeat("\xc0", 8); |
|
2554 | + $frame = $this->qrstrset($frame, 0, 7, $setPattern); |
|
2555 | + $frame = $this->qrstrset($frame, $width-8, 7, $setPattern); |
|
2556 | + $frame = $this->qrstrset($frame, 0, $width - 8, $setPattern); |
|
2557 | + // Format info |
|
2558 | + $setPattern = str_repeat("\x84", 9); |
|
2559 | + $frame = $this->qrstrset($frame, 0, 8, $setPattern); |
|
2560 | + $frame = $this->qrstrset($frame, $width - 8, 8, $setPattern, 8); |
|
2561 | + $yOffset = $width - 8; |
|
2562 | + for ($y=0; $y < 8; ++$y,++$yOffset) { |
|
2563 | + $frame[$y][8] = "\x84"; |
|
2564 | + $frame[$yOffset][8] = "\x84"; |
|
2565 | + } |
|
2566 | + // Timing pattern |
|
2567 | + $wo = $width - 15; |
|
2568 | + for ($i=1; $i < $wo; ++$i) { |
|
2569 | + $frame[6][7+$i] = chr(0x90 | ($i & 1)); |
|
2570 | + $frame[7+$i][6] = chr(0x90 | ($i & 1)); |
|
2571 | + } |
|
2572 | + // Alignment pattern |
|
2573 | + $frame = $this->putAlignmentPattern($version, $frame, $width); |
|
2574 | + // Version information |
|
2575 | + if ($version >= 7) { |
|
2576 | + $vinf = $this->getVersionPattern($version); |
|
2577 | + $v = $vinf; |
|
2578 | + for ($x=0; $x<6; ++$x) { |
|
2579 | + for ($y=0; $y<3; ++$y) { |
|
2580 | + $frame[($width - 11)+$y][$x] = chr(0x88 | ($v & 1)); |
|
2581 | + $v = $v >> 1; |
|
2582 | + } |
|
2583 | + } |
|
2584 | + $v = $vinf; |
|
2585 | + for ($y=0; $y<6; ++$y) { |
|
2586 | + for ($x=0; $x<3; ++$x) { |
|
2587 | + $frame[$y][$x+($width - 11)] = chr(0x88 | ($v & 1)); |
|
2588 | + $v = $v >> 1; |
|
2589 | + } |
|
2590 | + } |
|
2591 | + } |
|
2592 | + // and a little bit... |
|
2593 | + $frame[$width - 8][8] = "\x81"; |
|
2594 | + return $frame; |
|
2595 | + } |
|
2596 | + |
|
2597 | + /** |
|
2598 | + * Set new frame for the specified version. |
|
2599 | + * @param int $version version |
|
2600 | + * @return Array of unsigned char. |
|
2601 | + */ |
|
2602 | + protected function newFrame($version) { |
|
2603 | + if (($version < 1) or ($version > QRSPEC_VERSION_MAX)) { |
|
2604 | + return null; |
|
2605 | + } |
|
2606 | + if (!isset($this->frames[$version])) { |
|
2607 | + $this->frames[$version] = $this->createFrame($version); |
|
2608 | + } |
|
2609 | + if (is_null($this->frames[$version])) { |
|
2610 | + return null; |
|
2611 | + } |
|
2612 | + return $this->frames[$version]; |
|
2613 | + } |
|
2614 | + |
|
2615 | + /** |
|
2616 | + * Return block number 0 |
|
2617 | + * @param array $spec |
|
2618 | + * @return int value |
|
2619 | + */ |
|
2620 | + protected function rsBlockNum($spec) { |
|
2621 | + return ($spec[0] + $spec[3]); |
|
2622 | + } |
|
2623 | + |
|
2624 | + /** |
|
2625 | + * Return block number 1 |
|
2626 | + * @param array $spec |
|
2627 | + * @return int value |
|
2628 | + */ |
|
2629 | + protected function rsBlockNum1($spec) { |
|
2630 | + return $spec[0]; |
|
2631 | + } |
|
2632 | + |
|
2633 | + /** |
|
2634 | + * Return data codes 1 |
|
2635 | + * @param array $spec |
|
2636 | + * @return int value |
|
2637 | + */ |
|
2638 | + protected function rsDataCodes1($spec) { |
|
2639 | + return $spec[1]; |
|
2640 | + } |
|
2641 | + |
|
2642 | + /** |
|
2643 | + * Return ecc codes 1 |
|
2644 | + * @param array $spec |
|
2645 | + * @return int value |
|
2646 | + */ |
|
2647 | + protected function rsEccCodes1($spec) { |
|
2648 | + return $spec[2]; |
|
2649 | + } |
|
2650 | + |
|
2651 | + /** |
|
2652 | + * Return block number 2 |
|
2653 | + * @param array $spec |
|
2654 | + * @return int value |
|
2655 | + */ |
|
2656 | + protected function rsBlockNum2($spec) { |
|
2657 | + return $spec[3]; |
|
2658 | + } |
|
2659 | + |
|
2660 | + /** |
|
2661 | + * Return data codes 2 |
|
2662 | + * @param array $spec |
|
2663 | + * @return int value |
|
2664 | + */ |
|
2665 | + protected function rsDataCodes2($spec) { |
|
2666 | + return $spec[4]; |
|
2667 | + } |
|
2668 | + |
|
2669 | + /** |
|
2670 | + * Return ecc codes 2 |
|
2671 | + * @param array $spec |
|
2672 | + * @return int value |
|
2673 | + */ |
|
2674 | + protected function rsEccCodes2($spec) { |
|
2675 | + return $spec[2]; |
|
2676 | + } |
|
2677 | + |
|
2678 | + /** |
|
2679 | + * Return data length |
|
2680 | + * @param array $spec |
|
2681 | + * @return int value |
|
2682 | + */ |
|
2683 | + protected function rsDataLength($spec) { |
|
2684 | + return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]); |
|
2685 | + } |
|
2686 | + |
|
2687 | + /** |
|
2688 | + * Return ecc length |
|
2689 | + * @param array $spec |
|
2690 | + * @return int value |
|
2691 | + */ |
|
2692 | + protected function rsEccLength($spec) { |
|
2693 | + return ($spec[0] + $spec[3]) * $spec[2]; |
|
2694 | + } |
|
2695 | + |
|
2696 | + // - - - - - - - - - - - - - - - - - - - - - - - - - |
|
2697 | + |
|
2698 | + // QRrs |
|
2699 | + |
|
2700 | + /** |
|
2701 | + * Initialize a Reed-Solomon codec and add it to existing rsitems |
|
2702 | + * @param int $symsize symbol size, bits |
|
2703 | + * @param int $gfpoly Field generator polynomial coefficients |
|
2704 | + * @param int $fcr first root of RS code generator polynomial, index form |
|
2705 | + * @param int $prim primitive element to generate polynomial roots |
|
2706 | + * @param int $nroots RS code generator polynomial degree (number of roots) |
|
2707 | + * @param int $pad padding bytes at front of shortened block |
|
2708 | + * @return array Array of RS values:<ul><li>mm = Bits per symbol;</li><li>nn = Symbols per block;</li><li>alpha_to = log lookup table array;</li><li>index_of = Antilog lookup table array;</li><li>genpoly = Generator polynomial array;</li><li>nroots = Number of generator;</li><li>roots = number of parity symbols;</li><li>fcr = First consecutive root, index form;</li><li>prim = Primitive element, index form;</li><li>iprim = prim-th root of 1, index form;</li><li>pad = Padding bytes in shortened block;</li><li>gfpoly</ul>. |
|
2709 | + */ |
|
2710 | + protected function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) { |
|
2711 | + foreach ($this->rsitems as $rs) { |
|
2712 | + if (($rs['pad'] != $pad) or ($rs['nroots'] != $nroots) or ($rs['mm'] != $symsize) |
|
2713 | + or ($rs['gfpoly'] != $gfpoly) or ($rs['fcr'] != $fcr) or ($rs['prim'] != $prim)) { |
|
2714 | + continue; |
|
2715 | + } |
|
2716 | + return $rs; |
|
2717 | + } |
|
2718 | + $rs = $this->init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad); |
|
2719 | + array_unshift($this->rsitems, $rs); |
|
2720 | + return $rs; |
|
2721 | + } |
|
2722 | + |
|
2723 | + // - - - - - - - - - - - - - - - - - - - - - - - - - |
|
2724 | + |
|
2725 | + // QRrsItem |
|
2726 | + |
|
2727 | + /** |
|
2728 | + * modnn |
|
2729 | + * @param array RS values |
|
2730 | + * @param int $x X position |
|
2731 | + * @return int X osition |
|
2732 | + */ |
|
2733 | + protected function modnn($rs, $x) { |
|
2734 | + while ($x >= $rs['nn']) { |
|
2735 | + $x -= $rs['nn']; |
|
2736 | + $x = ($x >> $rs['mm']) + ($x & $rs['nn']); |
|
2737 | + } |
|
2738 | + return $x; |
|
2739 | + } |
|
2740 | + |
|
2741 | + /** |
|
2742 | + * Initialize a Reed-Solomon codec and returns an array of values. |
|
2743 | + * @param int $symsize symbol size, bits |
|
2744 | + * @param int $gfpoly Field generator polynomial coefficients |
|
2745 | + * @param int $fcr first root of RS code generator polynomial, index form |
|
2746 | + * @param int $prim primitive element to generate polynomial roots |
|
2747 | + * @param int $nroots RS code generator polynomial degree (number of roots) |
|
2748 | + * @param int $pad padding bytes at front of shortened block |
|
2749 | + * @return array Array of RS values:<ul><li>mm = Bits per symbol;</li><li>nn = Symbols per block;</li><li>alpha_to = log lookup table array;</li><li>index_of = Antilog lookup table array;</li><li>genpoly = Generator polynomial array;</li><li>nroots = Number of generator;</li><li>roots = number of parity symbols;</li><li>fcr = First consecutive root, index form;</li><li>prim = Primitive element, index form;</li><li>iprim = prim-th root of 1, index form;</li><li>pad = Padding bytes in shortened block;</li><li>gfpoly</ul>. |
|
2750 | + */ |
|
2751 | + protected function init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) { |
|
2752 | + // Based on Reed solomon encoder by Phil Karn, KA9Q (GNU-LGPLv2) |
|
2753 | + $rs = null; |
|
2754 | + // Check parameter ranges |
|
2755 | + if (($symsize < 0) or ($symsize > 8)) { |
|
2756 | + return $rs; |
|
2757 | + } |
|
2758 | + if (($fcr < 0) or ($fcr >= (1<<$symsize))) { |
|
2759 | + return $rs; |
|
2760 | + } |
|
2761 | + if (($prim <= 0) or ($prim >= (1<<$symsize))) { |
|
2762 | + return $rs; |
|
2763 | + } |
|
2764 | + if (($nroots < 0) or ($nroots >= (1<<$symsize))) { |
|
2765 | + return $rs; |
|
2766 | + } |
|
2767 | + if (($pad < 0) or ($pad >= ((1<<$symsize) -1 - $nroots))) { |
|
2768 | + return $rs; |
|
2769 | + } |
|
2770 | + $rs = array(); |
|
2771 | + $rs['mm'] = $symsize; |
|
2772 | + $rs['nn'] = (1 << $symsize) - 1; |
|
2773 | + $rs['pad'] = $pad; |
|
2774 | + $rs['alpha_to'] = array_fill(0, ($rs['nn'] + 1), 0); |
|
2775 | + $rs['index_of'] = array_fill(0, ($rs['nn'] + 1), 0); |
|
2776 | + // PHP style macro replacement ;) |
|
2777 | + $NN =& $rs['nn']; |
|
2778 | + $A0 =& $NN; |
|
2779 | + // Generate Galois field lookup tables |
|
2780 | + $rs['index_of'][0] = $A0; // log(zero) = -inf |
|
2781 | + $rs['alpha_to'][$A0] = 0; // alpha**-inf = 0 |
|
2782 | + $sr = 1; |
|
2783 | + for ($i=0; $i<$rs['nn']; ++$i) { |
|
2784 | + $rs['index_of'][$sr] = $i; |
|
2785 | + $rs['alpha_to'][$i] = $sr; |
|
2786 | + $sr <<= 1; |
|
2787 | + if ($sr & (1 << $symsize)) { |
|
2788 | + $sr ^= $gfpoly; |
|
2789 | + } |
|
2790 | + $sr &= $rs['nn']; |
|
2791 | + } |
|
2792 | + if ($sr != 1) { |
|
2793 | + // field generator polynomial is not primitive! |
|
2794 | + return null; |
|
2795 | + } |
|
2796 | + // Form RS code generator polynomial from its roots |
|
2797 | + $rs['genpoly'] = array_fill(0, ($nroots + 1), 0); |
|
2798 | + $rs['fcr'] = $fcr; |
|
2799 | + $rs['prim'] = $prim; |
|
2800 | + $rs['nroots'] = $nroots; |
|
2801 | + $rs['gfpoly'] = $gfpoly; |
|
2802 | + // Find prim-th root of 1, used in decoding |
|
2803 | + for ($iprim=1; ($iprim % $prim) != 0; $iprim += $rs['nn']) { |
|
2804 | + ; // intentional empty-body loop! |
|
2805 | + } |
|
2806 | + $rs['iprim'] = (int)($iprim / $prim); |
|
2807 | + $rs['genpoly'][0] = 1; |
|
2808 | + |
|
2809 | + |
|
2810 | + for ($i = 0,$root=$fcr*$prim; $i < $nroots; $i++, $root += $prim) { |
|
2811 | + $rs['genpoly'][$i+1] = 1; |
|
2812 | + // Multiply rs->genpoly[] by @**(root + x) |
|
2813 | + for ($j = $i; $j > 0; --$j) { |
|
2814 | + if ($rs['genpoly'][$j] != 0) { |
|
2815 | + $rs['genpoly'][$j] = $rs['genpoly'][$j-1] ^ $rs['alpha_to'][$this->modnn($rs, $rs['index_of'][$rs['genpoly'][$j]] + $root)]; |
|
2816 | + } else { |
|
2817 | + $rs['genpoly'][$j] = $rs['genpoly'][$j-1]; |
|
2818 | + } |
|
2819 | + } |
|
2820 | + // rs->genpoly[0] can never be zero |
|
2821 | + $rs['genpoly'][0] = $rs['alpha_to'][$this->modnn($rs, $rs['index_of'][$rs['genpoly'][0]] + $root)]; |
|
2822 | + } |
|
2823 | + // convert rs->genpoly[] to index form for quicker encoding |
|
2824 | + for ($i = 0; $i <= $nroots; ++$i) { |
|
2825 | + $rs['genpoly'][$i] = $rs['index_of'][$rs['genpoly'][$i]]; |
|
2826 | + } |
|
2827 | + return $rs; |
|
2828 | + } |
|
2829 | + |
|
2830 | + /** |
|
2831 | + * Encode a Reed-Solomon codec and returns the parity array |
|
2832 | + * @param array $rs RS values |
|
2833 | + * @param array $data data |
|
2834 | + * @param array $parity parity |
|
2835 | + * @return parity array |
|
2836 | + */ |
|
2837 | + protected function encode_rs_char($rs, $data, $parity) { |
|
2838 | + $MM =& $rs['mm']; // bits per symbol |
|
2839 | + $NN =& $rs['nn']; // the total number of symbols in a RS block |
|
2840 | + $ALPHA_TO =& $rs['alpha_to']; // the address of an array of NN elements to convert Galois field elements in index (log) form to polynomial form |
|
2841 | + $INDEX_OF =& $rs['index_of']; // the address of an array of NN elements to convert Galois field elements in polynomial form to index (log) form |
|
2842 | + $GENPOLY =& $rs['genpoly']; // an array of NROOTS+1 elements containing the generator polynomial in index form |
|
2843 | + $NROOTS =& $rs['nroots']; // the number of roots in the RS code generator polynomial, which is the same as the number of parity symbols in a block |
|
2844 | + $FCR =& $rs['fcr']; // first consecutive root, index form |
|
2845 | + $PRIM =& $rs['prim']; // primitive element, index form |
|
2846 | + $IPRIM =& $rs['iprim']; // prim-th root of 1, index form |
|
2847 | + $PAD =& $rs['pad']; // the number of pad symbols in a block |
|
2848 | + $A0 =& $NN; |
|
2849 | + $parity = array_fill(0, $NROOTS, 0); |
|
2850 | + for ($i=0; $i < ($NN - $NROOTS - $PAD); $i++) { |
|
2851 | + $feedback = $INDEX_OF[$data[$i] ^ $parity[0]]; |
|
2852 | + if ($feedback != $A0) { |
|
2853 | + // feedback term is non-zero |
|
2854 | + // This line is unnecessary when GENPOLY[NROOTS] is unity, as it must |
|
2855 | + // always be for the polynomials constructed by init_rs() |
|
2856 | + $feedback = $this->modnn($rs, $NN - $GENPOLY[$NROOTS] + $feedback); |
|
2857 | + for ($j=1; $j < $NROOTS; ++$j) { |
|
2858 | + $parity[$j] ^= $ALPHA_TO[$this->modnn($rs, $feedback + $GENPOLY[($NROOTS - $j)])]; |
|
2859 | + } |
|
2860 | + } |
|
2861 | + // Shift |
|
2862 | + array_shift($parity); |
|
2863 | + if ($feedback != $A0) { |
|
2864 | + array_push($parity, $ALPHA_TO[$this->modnn($rs, $feedback + $GENPOLY[0])]); |
|
2865 | + } else { |
|
2866 | + array_push($parity, 0); |
|
2867 | + } |
|
2868 | + } |
|
2869 | + return $parity; |
|
2870 | + } |
|
2871 | + |
|
2872 | + } // end QRcode class |
|
2873 | 2873 | |
2874 | 2874 | } // END OF "class_exists QRcode" |
2875 | 2875 | ?> |
@@ -180,12 +180,12 @@ discard block |
||
180 | 180 | /** |
181 | 181 | * Matrix index to get width from $capacity array. |
182 | 182 | */ |
183 | - define('QRCAP_WIDTH', 0); |
|
183 | + define('QRCAP_WIDTH', 0); |
|
184 | 184 | |
185 | 185 | /** |
186 | 186 | * Matrix index to get number of words from $capacity array. |
187 | 187 | */ |
188 | - define('QRCAP_WORDS', 1); |
|
188 | + define('QRCAP_WORDS', 1); |
|
189 | 189 | |
190 | 190 | /** |
191 | 191 | * Matrix index to get remainder from $capacity array. |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | /** |
196 | 196 | * Matrix index to get error correction level from $capacity array. |
197 | 197 | */ |
198 | - define('QRCAP_EC', 3); |
|
198 | + define('QRCAP_EC', 3); |
|
199 | 199 | |
200 | 200 | // ----------------------------------------------------- |
201 | 201 | |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | /** |
205 | 205 | * Number of header bits for structured mode |
206 | 206 | */ |
207 | - define('STRUCTURE_HEADER_BITS', 20); |
|
207 | + define('STRUCTURE_HEADER_BITS', 20); |
|
208 | 208 | |
209 | 209 | /** |
210 | 210 | * Max number of symbols for structured mode |
@@ -218,12 +218,12 @@ discard block |
||
218 | 218 | /** |
219 | 219 | * Down point base value for case 1 mask pattern (concatenation of same color in a line or a column) |
220 | 220 | */ |
221 | - define('N1', 3); |
|
221 | + define('N1', 3); |
|
222 | 222 | |
223 | 223 | /** |
224 | 224 | * Down point base value for case 2 mask pattern (module block of same color) |
225 | 225 | */ |
226 | - define('N2', 3); |
|
226 | + define('N2', 3); |
|
227 | 227 | |
228 | 228 | /** |
229 | 229 | * Down point base value for case 3 mask pattern (1:1:3:1:1(dark:bright:dark:bright:dark)pattern in a line or a column) |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | * @param int $split_length Maximum length of the chunk. |
271 | 271 | * @return If the optional split_length parameter is specified, the returned array will be broken down into chunks with each being split_length in length, otherwise each chunk will be one character in length. FALSE is returned if split_length is less than 1. If the split_length length exceeds the length of string , the entire string is returned as the first (and only) array element. |
272 | 272 | */ |
273 | - function str_split($string, $split_length=1) { |
|
273 | + function str_split($string, $split_length = 1) { |
|
274 | 274 | if ((strlen($string) > $split_length) or (!$split_length)) { |
275 | 275 | do { |
276 | 276 | $c = strlen($string); |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // |
482 | 482 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // |
483 | 483 | 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, // |
484 | - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, // |
|
484 | + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, // |
|
485 | 485 | -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, // |
486 | 486 | 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, // |
487 | 487 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // |
@@ -494,47 +494,47 @@ discard block |
||
494 | 494 | * @access protected |
495 | 495 | */ |
496 | 496 | protected $capacity = array( |
497 | - array( 0, 0, 0, array( 0, 0, 0, 0)), // |
|
498 | - array( 21, 26, 0, array( 7, 10, 13, 17)), // 1 |
|
499 | - array( 25, 44, 7, array( 10, 16, 22, 28)), // |
|
500 | - array( 29, 70, 7, array( 15, 26, 36, 44)), // |
|
501 | - array( 33, 100, 7, array( 20, 36, 52, 64)), // |
|
502 | - array( 37, 134, 7, array( 26, 48, 72, 88)), // 5 |
|
503 | - array( 41, 172, 7, array( 36, 64, 96, 112)), // |
|
504 | - array( 45, 196, 0, array( 40, 72, 108, 130)), // |
|
505 | - array( 49, 242, 0, array( 48, 88, 132, 156)), // |
|
506 | - array( 53, 292, 0, array( 60, 110, 160, 192)), // |
|
507 | - array( 57, 346, 0, array( 72, 130, 192, 224)), // 10 |
|
508 | - array( 61, 404, 0, array( 80, 150, 224, 264)), // |
|
509 | - array( 65, 466, 0, array( 96, 176, 260, 308)), // |
|
510 | - array( 69, 532, 0, array( 104, 198, 288, 352)), // |
|
511 | - array( 73, 581, 3, array( 120, 216, 320, 384)), // |
|
512 | - array( 77, 655, 3, array( 132, 240, 360, 432)), // 15 |
|
513 | - array( 81, 733, 3, array( 144, 280, 408, 480)), // |
|
514 | - array( 85, 815, 3, array( 168, 308, 448, 532)), // |
|
515 | - array( 89, 901, 3, array( 180, 338, 504, 588)), // |
|
516 | - array( 93, 991, 3, array( 196, 364, 546, 650)), // |
|
517 | - array( 97, 1085, 3, array( 224, 416, 600, 700)), // 20 |
|
518 | - array(101, 1156, 4, array( 224, 442, 644, 750)), // |
|
519 | - array(105, 1258, 4, array( 252, 476, 690, 816)), // |
|
520 | - array(109, 1364, 4, array( 270, 504, 750, 900)), // |
|
521 | - array(113, 1474, 4, array( 300, 560, 810, 960)), // |
|
522 | - array(117, 1588, 4, array( 312, 588, 870, 1050)), // 25 |
|
523 | - array(121, 1706, 4, array( 336, 644, 952, 1110)), // |
|
524 | - array(125, 1828, 4, array( 360, 700, 1020, 1200)), // |
|
525 | - array(129, 1921, 3, array( 390, 728, 1050, 1260)), // |
|
526 | - array(133, 2051, 3, array( 420, 784, 1140, 1350)), // |
|
527 | - array(137, 2185, 3, array( 450, 812, 1200, 1440)), // 30 |
|
528 | - array(141, 2323, 3, array( 480, 868, 1290, 1530)), // |
|
529 | - array(145, 2465, 3, array( 510, 924, 1350, 1620)), // |
|
530 | - array(149, 2611, 3, array( 540, 980, 1440, 1710)), // |
|
531 | - array(153, 2761, 3, array( 570, 1036, 1530, 1800)), // |
|
532 | - array(157, 2876, 0, array( 570, 1064, 1590, 1890)), // 35 |
|
533 | - array(161, 3034, 0, array( 600, 1120, 1680, 1980)), // |
|
534 | - array(165, 3196, 0, array( 630, 1204, 1770, 2100)), // |
|
535 | - array(169, 3362, 0, array( 660, 1260, 1860, 2220)), // |
|
536 | - array(173, 3532, 0, array( 720, 1316, 1950, 2310)), // |
|
537 | - array(177, 3706, 0, array( 750, 1372, 2040, 2430)) // 40 |
|
497 | + array(0, 0, 0, array(0, 0, 0, 0)), // |
|
498 | + array(21, 26, 0, array(7, 10, 13, 17)), // 1 |
|
499 | + array(25, 44, 7, array(10, 16, 22, 28)), // |
|
500 | + array(29, 70, 7, array(15, 26, 36, 44)), // |
|
501 | + array(33, 100, 7, array(20, 36, 52, 64)), // |
|
502 | + array(37, 134, 7, array(26, 48, 72, 88)), // 5 |
|
503 | + array(41, 172, 7, array(36, 64, 96, 112)), // |
|
504 | + array(45, 196, 0, array(40, 72, 108, 130)), // |
|
505 | + array(49, 242, 0, array(48, 88, 132, 156)), // |
|
506 | + array(53, 292, 0, array(60, 110, 160, 192)), // |
|
507 | + array(57, 346, 0, array(72, 130, 192, 224)), // 10 |
|
508 | + array(61, 404, 0, array(80, 150, 224, 264)), // |
|
509 | + array(65, 466, 0, array(96, 176, 260, 308)), // |
|
510 | + array(69, 532, 0, array(104, 198, 288, 352)), // |
|
511 | + array(73, 581, 3, array(120, 216, 320, 384)), // |
|
512 | + array(77, 655, 3, array(132, 240, 360, 432)), // 15 |
|
513 | + array(81, 733, 3, array(144, 280, 408, 480)), // |
|
514 | + array(85, 815, 3, array(168, 308, 448, 532)), // |
|
515 | + array(89, 901, 3, array(180, 338, 504, 588)), // |
|
516 | + array(93, 991, 3, array(196, 364, 546, 650)), // |
|
517 | + array(97, 1085, 3, array(224, 416, 600, 700)), // 20 |
|
518 | + array(101, 1156, 4, array(224, 442, 644, 750)), // |
|
519 | + array(105, 1258, 4, array(252, 476, 690, 816)), // |
|
520 | + array(109, 1364, 4, array(270, 504, 750, 900)), // |
|
521 | + array(113, 1474, 4, array(300, 560, 810, 960)), // |
|
522 | + array(117, 1588, 4, array(312, 588, 870, 1050)), // 25 |
|
523 | + array(121, 1706, 4, array(336, 644, 952, 1110)), // |
|
524 | + array(125, 1828, 4, array(360, 700, 1020, 1200)), // |
|
525 | + array(129, 1921, 3, array(390, 728, 1050, 1260)), // |
|
526 | + array(133, 2051, 3, array(420, 784, 1140, 1350)), // |
|
527 | + array(137, 2185, 3, array(450, 812, 1200, 1440)), // 30 |
|
528 | + array(141, 2323, 3, array(480, 868, 1290, 1530)), // |
|
529 | + array(145, 2465, 3, array(510, 924, 1350, 1620)), // |
|
530 | + array(149, 2611, 3, array(540, 980, 1440, 1710)), // |
|
531 | + array(153, 2761, 3, array(570, 1036, 1530, 1800)), // |
|
532 | + array(157, 2876, 0, array(570, 1064, 1590, 1890)), // 35 |
|
533 | + array(161, 3034, 0, array(600, 1120, 1680, 1980)), // |
|
534 | + array(165, 3196, 0, array(630, 1204, 1770, 2100)), // |
|
535 | + array(169, 3362, 0, array(660, 1260, 1860, 2220)), // |
|
536 | + array(173, 3532, 0, array(720, 1316, 1950, 2310)), // |
|
537 | + array(177, 3706, 0, array(750, 1372, 2040, 2430)) // 40 |
|
538 | 538 | ); |
539 | 539 | |
540 | 540 | /** |
@@ -543,9 +543,9 @@ discard block |
||
543 | 543 | */ |
544 | 544 | protected $lengthTableBits = array( |
545 | 545 | array(10, 12, 14), |
546 | - array( 9, 11, 13), |
|
547 | - array( 8, 16, 16), |
|
548 | - array( 8, 10, 12) |
|
546 | + array(9, 11, 13), |
|
547 | + array(8, 16, 16), |
|
548 | + array(8, 10, 12) |
|
549 | 549 | ); |
550 | 550 | |
551 | 551 | /** |
@@ -554,47 +554,47 @@ discard block |
||
554 | 554 | * @access protected |
555 | 555 | */ |
556 | 556 | protected $eccTable = array( |
557 | - array(array( 0, 0), array( 0, 0), array( 0, 0), array( 0, 0)), // |
|
558 | - array(array( 1, 0), array( 1, 0), array( 1, 0), array( 1, 0)), // 1 |
|
559 | - array(array( 1, 0), array( 1, 0), array( 1, 0), array( 1, 0)), // |
|
560 | - array(array( 1, 0), array( 1, 0), array( 2, 0), array( 2, 0)), // |
|
561 | - array(array( 1, 0), array( 2, 0), array( 2, 0), array( 4, 0)), // |
|
562 | - array(array( 1, 0), array( 2, 0), array( 2, 2), array( 2, 2)), // 5 |
|
563 | - array(array( 2, 0), array( 4, 0), array( 4, 0), array( 4, 0)), // |
|
564 | - array(array( 2, 0), array( 4, 0), array( 2, 4), array( 4, 1)), // |
|
565 | - array(array( 2, 0), array( 2, 2), array( 4, 2), array( 4, 2)), // |
|
566 | - array(array( 2, 0), array( 3, 2), array( 4, 4), array( 4, 4)), // |
|
567 | - array(array( 2, 2), array( 4, 1), array( 6, 2), array( 6, 2)), // 10 |
|
568 | - array(array( 4, 0), array( 1, 4), array( 4, 4), array( 3, 8)), // |
|
569 | - array(array( 2, 2), array( 6, 2), array( 4, 6), array( 7, 4)), // |
|
570 | - array(array( 4, 0), array( 8, 1), array( 8, 4), array(12, 4)), // |
|
571 | - array(array( 3, 1), array( 4, 5), array(11, 5), array(11, 5)), // |
|
572 | - array(array( 5, 1), array( 5, 5), array( 5, 7), array(11, 7)), // 15 |
|
573 | - array(array( 5, 1), array( 7, 3), array(15, 2), array( 3, 13)), // |
|
574 | - array(array( 1, 5), array(10, 1), array( 1, 15), array( 2, 17)), // |
|
575 | - array(array( 5, 1), array( 9, 4), array(17, 1), array( 2, 19)), // |
|
576 | - array(array( 3, 4), array( 3, 11), array(17, 4), array( 9, 16)), // |
|
577 | - array(array( 3, 5), array( 3, 13), array(15, 5), array(15, 10)), // 20 |
|
578 | - array(array( 4, 4), array(17, 0), array(17, 6), array(19, 6)), // |
|
579 | - array(array( 2, 7), array(17, 0), array( 7, 16), array(34, 0)), // |
|
580 | - array(array( 4, 5), array( 4, 14), array(11, 14), array(16, 14)), // |
|
581 | - array(array( 6, 4), array( 6, 14), array(11, 16), array(30, 2)), // |
|
582 | - array(array( 8, 4), array( 8, 13), array( 7, 22), array(22, 13)), // 25 |
|
583 | - array(array(10, 2), array(19, 4), array(28, 6), array(33, 4)), // |
|
584 | - array(array( 8, 4), array(22, 3), array( 8, 26), array(12, 28)), // |
|
585 | - array(array( 3, 10), array( 3, 23), array( 4, 31), array(11, 31)), // |
|
586 | - array(array( 7, 7), array(21, 7), array( 1, 37), array(19, 26)), // |
|
587 | - array(array( 5, 10), array(19, 10), array(15, 25), array(23, 25)), // 30 |
|
588 | - array(array(13, 3), array( 2, 29), array(42, 1), array(23, 28)), // |
|
589 | - array(array(17, 0), array(10, 23), array(10, 35), array(19, 35)), // |
|
590 | - array(array(17, 1), array(14, 21), array(29, 19), array(11, 46)), // |
|
591 | - array(array(13, 6), array(14, 23), array(44, 7), array(59, 1)), // |
|
592 | - array(array(12, 7), array(12, 26), array(39, 14), array(22, 41)), // 35 |
|
593 | - array(array( 6, 14), array( 6, 34), array(46, 10), array( 2, 64)), // |
|
594 | - array(array(17, 4), array(29, 14), array(49, 10), array(24, 46)), // |
|
595 | - array(array( 4, 18), array(13, 32), array(48, 14), array(42, 32)), // |
|
596 | - array(array(20, 4), array(40, 7), array(43, 22), array(10, 67)), // |
|
597 | - array(array(19, 6), array(18, 31), array(34, 34), array(20, 61)) // 40 |
|
557 | + array(array(0, 0), array(0, 0), array(0, 0), array(0, 0)), // |
|
558 | + array(array(1, 0), array(1, 0), array(1, 0), array(1, 0)), // 1 |
|
559 | + array(array(1, 0), array(1, 0), array(1, 0), array(1, 0)), // |
|
560 | + array(array(1, 0), array(1, 0), array(2, 0), array(2, 0)), // |
|
561 | + array(array(1, 0), array(2, 0), array(2, 0), array(4, 0)), // |
|
562 | + array(array(1, 0), array(2, 0), array(2, 2), array(2, 2)), // 5 |
|
563 | + array(array(2, 0), array(4, 0), array(4, 0), array(4, 0)), // |
|
564 | + array(array(2, 0), array(4, 0), array(2, 4), array(4, 1)), // |
|
565 | + array(array(2, 0), array(2, 2), array(4, 2), array(4, 2)), // |
|
566 | + array(array(2, 0), array(3, 2), array(4, 4), array(4, 4)), // |
|
567 | + array(array(2, 2), array(4, 1), array(6, 2), array(6, 2)), // 10 |
|
568 | + array(array(4, 0), array(1, 4), array(4, 4), array(3, 8)), // |
|
569 | + array(array(2, 2), array(6, 2), array(4, 6), array(7, 4)), // |
|
570 | + array(array(4, 0), array(8, 1), array(8, 4), array(12, 4)), // |
|
571 | + array(array(3, 1), array(4, 5), array(11, 5), array(11, 5)), // |
|
572 | + array(array(5, 1), array(5, 5), array(5, 7), array(11, 7)), // 15 |
|
573 | + array(array(5, 1), array(7, 3), array(15, 2), array(3, 13)), // |
|
574 | + array(array(1, 5), array(10, 1), array(1, 15), array(2, 17)), // |
|
575 | + array(array(5, 1), array(9, 4), array(17, 1), array(2, 19)), // |
|
576 | + array(array(3, 4), array(3, 11), array(17, 4), array(9, 16)), // |
|
577 | + array(array(3, 5), array(3, 13), array(15, 5), array(15, 10)), // 20 |
|
578 | + array(array(4, 4), array(17, 0), array(17, 6), array(19, 6)), // |
|
579 | + array(array(2, 7), array(17, 0), array(7, 16), array(34, 0)), // |
|
580 | + array(array(4, 5), array(4, 14), array(11, 14), array(16, 14)), // |
|
581 | + array(array(6, 4), array(6, 14), array(11, 16), array(30, 2)), // |
|
582 | + array(array(8, 4), array(8, 13), array(7, 22), array(22, 13)), // 25 |
|
583 | + array(array(10, 2), array(19, 4), array(28, 6), array(33, 4)), // |
|
584 | + array(array(8, 4), array(22, 3), array(8, 26), array(12, 28)), // |
|
585 | + array(array(3, 10), array(3, 23), array(4, 31), array(11, 31)), // |
|
586 | + array(array(7, 7), array(21, 7), array(1, 37), array(19, 26)), // |
|
587 | + array(array(5, 10), array(19, 10), array(15, 25), array(23, 25)), // 30 |
|
588 | + array(array(13, 3), array(2, 29), array(42, 1), array(23, 28)), // |
|
589 | + array(array(17, 0), array(10, 23), array(10, 35), array(19, 35)), // |
|
590 | + array(array(17, 1), array(14, 21), array(29, 19), array(11, 46)), // |
|
591 | + array(array(13, 6), array(14, 23), array(44, 7), array(59, 1)), // |
|
592 | + array(array(12, 7), array(12, 26), array(39, 14), array(22, 41)), // 35 |
|
593 | + array(array(6, 14), array(6, 34), array(46, 10), array(2, 64)), // |
|
594 | + array(array(17, 4), array(29, 14), array(49, 10), array(24, 46)), // |
|
595 | + array(array(4, 18), array(13, 32), array(48, 14), array(42, 32)), // |
|
596 | + array(array(20, 4), array(40, 7), array(43, 22), array(10, 67)), // |
|
597 | + array(array(19, 6), array(18, 31), array(34, 34), array(20, 61)) // 40 |
|
598 | 598 | ); |
599 | 599 | |
600 | 600 | /** |
@@ -604,9 +604,9 @@ discard block |
||
604 | 604 | * @access protected |
605 | 605 | */ |
606 | 606 | protected $alignmentPattern = array( |
607 | - array( 0, 0), |
|
608 | - array( 0, 0), array(18, 0), array(22, 0), array(26, 0), array(30, 0), // 1- 5 |
|
609 | - array(34, 0), array(22, 38), array(24, 42), array(26, 46), array(28, 50), // 6-10 |
|
607 | + array(0, 0), |
|
608 | + array(0, 0), array(18, 0), array(22, 0), array(26, 0), array(30, 0), // 1- 5 |
|
609 | + array(34, 0), array(22, 38), array(24, 42), array(26, 46), array(28, 50), // 6-10 |
|
610 | 610 | array(30, 54), array(32, 58), array(34, 62), array(26, 46), array(26, 48), // 11-15 |
611 | 611 | array(26, 50), array(30, 54), array(30, 56), array(30, 58), array(34, 62), // 16-20 |
612 | 612 | array(28, 50), array(26, 50), array(30, 54), array(28, 54), array(32, 58), // 21-25 |
@@ -679,7 +679,7 @@ discard block |
||
679 | 679 | foreach ($qrTab as $line) { |
680 | 680 | $arrAdd = array(); |
681 | 681 | foreach (str_split($line) as $char) { |
682 | - $arrAdd[] = ($char=='1')?1:0; |
|
682 | + $arrAdd[] = ($char == '1') ? 1 : 0; |
|
683 | 683 | } |
684 | 684 | $barcode_array['bcode'][] = $arrAdd; |
685 | 685 | } |
@@ -704,8 +704,8 @@ discard block |
||
704 | 704 | $len = count($frame); |
705 | 705 | // the frame is square (width = height) |
706 | 706 | foreach ($frame as &$frameLine) { |
707 | - for ($i=0; $i<$len; $i++) { |
|
708 | - $frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0'; |
|
707 | + for ($i = 0; $i < $len; $i++) { |
|
708 | + $frameLine[$i] = (ord($frameLine[$i]) & 1) ? '1' : '0'; |
|
709 | 709 | } |
710 | 710 | } |
711 | 711 | return $frame; |
@@ -755,10 +755,10 @@ discard block |
||
755 | 755 | $this->dir = -1; |
756 | 756 | $this->bit = -1; |
757 | 757 | // inteleaved data and ecc codes |
758 | - for ($i=0; $i < ($this->dataLength + $this->eccLength); $i++) { |
|
758 | + for ($i = 0; $i < ($this->dataLength + $this->eccLength); $i++) { |
|
759 | 759 | $code = $this->getCode(); |
760 | 760 | $bit = 0x80; |
761 | - for ($j=0; $j<8; $j++) { |
|
761 | + for ($j = 0; $j < 8; $j++) { |
|
762 | 762 | $addr = $this->getNextPosition(); |
763 | 763 | $this->setFrameAt($addr, 0x02 | (($bit & $code) != 0)); |
764 | 764 | $bit = $bit >> 1; |
@@ -766,7 +766,7 @@ discard block |
||
766 | 766 | } |
767 | 767 | // remainder bits |
768 | 768 | $j = $this->getRemainder($this->version); |
769 | - for ($i=0; $i<$j; $i++) { |
|
769 | + for ($i = 0; $i < $j; $i++) { |
|
770 | 770 | $addr = $this->getNextPosition(); |
771 | 771 | $this->setFrameAt($addr, 0x02); |
772 | 772 | } |
@@ -856,7 +856,7 @@ discard block |
||
856 | 856 | } |
857 | 857 | $this->x = $x; |
858 | 858 | $this->y = $y; |
859 | - } while(ord($this->frame[$y][$x]) & 0x80); |
|
859 | + } while (ord($this->frame[$y][$x]) & 0x80); |
|
860 | 860 | return array('x'=>$x, 'y'=>$y); |
861 | 861 | } |
862 | 862 | |
@@ -877,7 +877,7 @@ discard block |
||
877 | 877 | $dataPos = 0; |
878 | 878 | $eccPos = 0; |
879 | 879 | $endfor = $this->rsBlockNum1($spec); |
880 | - for ($i=0; $i < $endfor; ++$i) { |
|
880 | + for ($i = 0; $i < $endfor; ++$i) { |
|
881 | 881 | $ecc = array_slice($this->ecccode, $eccPos); |
882 | 882 | $this->rsblocks[$blockNo] = array(); |
883 | 883 | $this->rsblocks[$blockNo]['dataLength'] = $dl; |
@@ -885,7 +885,7 @@ discard block |
||
885 | 885 | $this->rsblocks[$blockNo]['eccLength'] = $el; |
886 | 886 | $ecc = $this->encode_rs_char($rs, $this->rsblocks[$blockNo]['data'], $ecc); |
887 | 887 | $this->rsblocks[$blockNo]['ecc'] = $ecc; |
888 | - $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc); |
|
888 | + $this->ecccode = array_merge(array_slice($this->ecccode, 0, $eccPos), $ecc); |
|
889 | 889 | $dataPos += $dl; |
890 | 890 | $eccPos += $el; |
891 | 891 | $blockNo++; |
@@ -900,7 +900,7 @@ discard block |
||
900 | 900 | return -1; |
901 | 901 | } |
902 | 902 | $endfor = $this->rsBlockNum2($spec); |
903 | - for ($i=0; $i < $endfor; ++$i) { |
|
903 | + for ($i = 0; $i < $endfor; ++$i) { |
|
904 | 904 | $ecc = array_slice($this->ecccode, $eccPos); |
905 | 905 | $this->rsblocks[$blockNo] = array(); |
906 | 906 | $this->rsblocks[$blockNo]['dataLength'] = $dl; |
@@ -953,8 +953,8 @@ discard block |
||
953 | 953 | */ |
954 | 954 | protected function writeFormatInformation($width, &$frame, $mask, $level) { |
955 | 955 | $blacks = 0; |
956 | - $format = $this->getFormatInfo($mask, $level); |
|
957 | - for ($i=0; $i<8; ++$i) { |
|
956 | + $format = $this->getFormatInfo($mask, $level); |
|
957 | + for ($i = 0; $i < 8; ++$i) { |
|
958 | 958 | if ($format & 1) { |
959 | 959 | $blacks += 2; |
960 | 960 | $v = 0x85; |
@@ -969,7 +969,7 @@ discard block |
||
969 | 969 | } |
970 | 970 | $format = $format >> 1; |
971 | 971 | } |
972 | - for ($i=0; $i<7; ++$i) { |
|
972 | + for ($i = 0; $i < 7; ++$i) { |
|
973 | 973 | if ($format & 1) { |
974 | 974 | $blacks += 2; |
975 | 975 | $v = 0x85; |
@@ -1034,7 +1034,7 @@ discard block |
||
1034 | 1034 | * @return int mask |
1035 | 1035 | */ |
1036 | 1036 | protected function mask4($x, $y) { |
1037 | - return (((int)($y / 2)) + ((int)($x / 3))) & 1; |
|
1037 | + return (((int) ($y / 2)) + ((int) ($x / 3))) & 1; |
|
1038 | 1038 | } |
1039 | 1039 | |
1040 | 1040 | /** |
@@ -1076,13 +1076,13 @@ discard block |
||
1076 | 1076 | */ |
1077 | 1077 | protected function generateMaskNo($maskNo, $width, $frame) { |
1078 | 1078 | $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); |
1079 | - for ($y=0; $y<$width; ++$y) { |
|
1080 | - for ($x=0; $x<$width; ++$x) { |
|
1079 | + for ($y = 0; $y < $width; ++$y) { |
|
1080 | + for ($x = 0; $x < $width; ++$x) { |
|
1081 | 1081 | if (ord($frame[$y][$x]) & 0x80) { |
1082 | 1082 | $bitMask[$y][$x] = 0; |
1083 | 1083 | } else { |
1084 | 1084 | $maskFunc = call_user_func(array($this, 'mask'.$maskNo), $x, $y); |
1085 | - $bitMask[$y][$x] = ($maskFunc == 0)?1:0; |
|
1085 | + $bitMask[$y][$x] = ($maskFunc == 0) ? 1 : 0; |
|
1086 | 1086 | } |
1087 | 1087 | } |
1088 | 1088 | } |
@@ -1098,7 +1098,7 @@ discard block |
||
1098 | 1098 | * @param boolean $maskGenOnly |
1099 | 1099 | * @return int b |
1100 | 1100 | */ |
1101 | - protected function makeMaskNo($maskNo, $width, $s, &$d, $maskGenOnly=false) { |
|
1101 | + protected function makeMaskNo($maskNo, $width, $s, &$d, $maskGenOnly = false) { |
|
1102 | 1102 | $b = 0; |
1103 | 1103 | $bitMask = array(); |
1104 | 1104 | $bitMask = $this->generateMaskNo($maskNo, $width, $s); |
@@ -1106,12 +1106,12 @@ discard block |
||
1106 | 1106 | return; |
1107 | 1107 | } |
1108 | 1108 | $d = $s; |
1109 | - for ($y=0; $y<$width; ++$y) { |
|
1110 | - for ($x=0; $x<$width; ++$x) { |
|
1109 | + for ($y = 0; $y < $width; ++$y) { |
|
1110 | + for ($x = 0; $x < $width; ++$x) { |
|
1111 | 1111 | if ($bitMask[$y][$x] == 1) { |
1112 | - $d[$y][$x] = chr(ord($s[$y][$x]) ^ (int)$bitMask[$y][$x]); |
|
1112 | + $d[$y][$x] = chr(ord($s[$y][$x]) ^ (int) $bitMask[$y][$x]); |
|
1113 | 1113 | } |
1114 | - $b += (int)(ord($d[$y][$x]) & 1); |
|
1114 | + $b += (int) (ord($d[$y][$x]) & 1); |
|
1115 | 1115 | } |
1116 | 1116 | } |
1117 | 1117 | return $b; |
@@ -1139,20 +1139,20 @@ discard block |
||
1139 | 1139 | */ |
1140 | 1140 | protected function calcN1N3($length) { |
1141 | 1141 | $demerit = 0; |
1142 | - for ($i=0; $i<$length; ++$i) { |
|
1142 | + for ($i = 0; $i < $length; ++$i) { |
|
1143 | 1143 | if ($this->runLength[$i] >= 5) { |
1144 | 1144 | $demerit += (N1 + ($this->runLength[$i] - 5)); |
1145 | 1145 | } |
1146 | 1146 | if ($i & 1) { |
1147 | - if (($i >= 3) and ($i < ($length-2)) and ($this->runLength[$i] % 3 == 0)) { |
|
1148 | - $fact = (int)($this->runLength[$i] / 3); |
|
1149 | - if (($this->runLength[$i-2] == $fact) |
|
1150 | - and ($this->runLength[$i-1] == $fact) |
|
1151 | - and ($this->runLength[$i+1] == $fact) |
|
1152 | - and ($this->runLength[$i+2] == $fact)) { |
|
1153 | - if (($this->runLength[$i-3] < 0) or ($this->runLength[$i-3] >= (4 * $fact))) { |
|
1147 | + if (($i >= 3) and ($i < ($length - 2)) and ($this->runLength[$i] % 3 == 0)) { |
|
1148 | + $fact = (int) ($this->runLength[$i] / 3); |
|
1149 | + if (($this->runLength[$i - 2] == $fact) |
|
1150 | + and ($this->runLength[$i - 1] == $fact) |
|
1151 | + and ($this->runLength[$i + 1] == $fact) |
|
1152 | + and ($this->runLength[$i + 2] == $fact)) { |
|
1153 | + if (($this->runLength[$i - 3] < 0) or ($this->runLength[$i - 3] >= (4 * $fact))) { |
|
1154 | 1154 | $demerit += N3; |
1155 | - } elseif ((($i+3) >= $length) or ($this->runLength[$i+3] >= (4 * $fact))) { |
|
1155 | + } elseif ((($i + 3) >= $length) or ($this->runLength[$i + 3] >= (4 * $fact))) { |
|
1156 | 1156 | $demerit += N3; |
1157 | 1157 | } |
1158 | 1158 | } |
@@ -1171,17 +1171,17 @@ discard block |
||
1171 | 1171 | protected function evaluateSymbol($width, $frame) { |
1172 | 1172 | $head = 0; |
1173 | 1173 | $demerit = 0; |
1174 | - for ($y=0; $y<$width; ++$y) { |
|
1174 | + for ($y = 0; $y < $width; ++$y) { |
|
1175 | 1175 | $head = 0; |
1176 | 1176 | $this->runLength[0] = 1; |
1177 | 1177 | $frameY = $frame[$y]; |
1178 | 1178 | if ($y > 0) { |
1179 | - $frameYM = $frame[$y-1]; |
|
1179 | + $frameYM = $frame[$y - 1]; |
|
1180 | 1180 | } |
1181 | - for ($x=0; $x<$width; ++$x) { |
|
1181 | + for ($x = 0; $x < $width; ++$x) { |
|
1182 | 1182 | if (($x > 0) and ($y > 0)) { |
1183 | - $b22 = ord($frameY[$x]) & ord($frameY[$x-1]) & ord($frameYM[$x]) & ord($frameYM[$x-1]); |
|
1184 | - $w22 = ord($frameY[$x]) | ord($frameY[$x-1]) | ord($frameYM[$x]) | ord($frameYM[$x-1]); |
|
1183 | + $b22 = ord($frameY[$x]) & ord($frameY[$x - 1]) & ord($frameYM[$x]) & ord($frameYM[$x - 1]); |
|
1184 | + $w22 = ord($frameY[$x]) | ord($frameY[$x - 1]) | ord($frameYM[$x]) | ord($frameYM[$x - 1]); |
|
1185 | 1185 | if (($b22 | ($w22 ^ 1)) & 1) { |
1186 | 1186 | $demerit += N2; |
1187 | 1187 | } |
@@ -1191,7 +1191,7 @@ discard block |
||
1191 | 1191 | $head = 1; |
1192 | 1192 | $this->runLength[$head] = 1; |
1193 | 1193 | } elseif ($x > 0) { |
1194 | - if ((ord($frameY[$x]) ^ ord($frameY[$x-1])) & 1) { |
|
1194 | + if ((ord($frameY[$x]) ^ ord($frameY[$x - 1])) & 1) { |
|
1195 | 1195 | $head++; |
1196 | 1196 | $this->runLength[$head] = 1; |
1197 | 1197 | } else { |
@@ -1199,18 +1199,18 @@ discard block |
||
1199 | 1199 | } |
1200 | 1200 | } |
1201 | 1201 | } |
1202 | - $demerit += $this->calcN1N3($head+1); |
|
1202 | + $demerit += $this->calcN1N3($head + 1); |
|
1203 | 1203 | } |
1204 | - for ($x=0; $x<$width; ++$x) { |
|
1204 | + for ($x = 0; $x < $width; ++$x) { |
|
1205 | 1205 | $head = 0; |
1206 | 1206 | $this->runLength[0] = 1; |
1207 | - for ($y=0; $y<$width; ++$y) { |
|
1207 | + for ($y = 0; $y < $width; ++$y) { |
|
1208 | 1208 | if (($y == 0) and (ord($frame[$y][$x]) & 1)) { |
1209 | 1209 | $this->runLength[0] = -1; |
1210 | 1210 | $head = 1; |
1211 | 1211 | $this->runLength[$head] = 1; |
1212 | 1212 | } elseif ($y > 0) { |
1213 | - if ((ord($frame[$y][$x]) ^ ord($frame[$y-1][$x])) & 1) { |
|
1213 | + if ((ord($frame[$y][$x]) ^ ord($frame[$y - 1][$x])) & 1) { |
|
1214 | 1214 | $head++; |
1215 | 1215 | $this->runLength[$head] = 1; |
1216 | 1216 | } else { |
@@ -1218,7 +1218,7 @@ discard block |
||
1218 | 1218 | } |
1219 | 1219 | } |
1220 | 1220 | } |
1221 | - $demerit += $this->calcN1N3($head+1); |
|
1221 | + $demerit += $this->calcN1N3($head + 1); |
|
1222 | 1222 | } |
1223 | 1223 | return $demerit; |
1224 | 1224 | } |
@@ -1237,8 +1237,8 @@ discard block |
||
1237 | 1237 | $checked_masks = array(0, 1, 2, 3, 4, 5, 6, 7); |
1238 | 1238 | if (QR_FIND_FROM_RANDOM !== false) { |
1239 | 1239 | $howManuOut = 8 - (QR_FIND_FROM_RANDOM % 9); |
1240 | - for ($i = 0; $i < $howManuOut; ++$i) { |
|
1241 | - $remPos = rand (0, count($checked_masks)-1); |
|
1240 | + for ($i = 0; $i < $howManuOut; ++$i) { |
|
1241 | + $remPos = rand(0, count($checked_masks) - 1); |
|
1242 | 1242 | unset($checked_masks[$remPos]); |
1243 | 1243 | $checked_masks = array_values($checked_masks); |
1244 | 1244 | } |
@@ -1250,8 +1250,8 @@ discard block |
||
1250 | 1250 | $blacks = 0; |
1251 | 1251 | $blacks = $this->makeMaskNo($i, $width, $frame, $mask); |
1252 | 1252 | $blacks += $this->writeFormatInformation($width, $mask, $i, $level); |
1253 | - $blacks = (int)(100 * $blacks / ($width * $width)); |
|
1254 | - $demerit = (int)((int)(abs($blacks - 50) / 5) * N4); |
|
1253 | + $blacks = (int) (100 * $blacks / ($width * $width)); |
|
1254 | + $demerit = (int) ((int) (abs($blacks - 50) / 5) * N4); |
|
1255 | 1255 | $demerit += $this->evaluateSymbol($width, $mask); |
1256 | 1256 | if ($demerit < $minDemerit) { |
1257 | 1257 | $minDemerit = $demerit; |
@@ -1276,7 +1276,7 @@ discard block |
||
1276 | 1276 | if ($pos >= strlen($str)) { |
1277 | 1277 | return false; |
1278 | 1278 | } |
1279 | - return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9'))); |
|
1279 | + return ((ord($str[$pos]) >= ord('0')) && (ord($str[$pos]) <= ord('9'))); |
|
1280 | 1280 | } |
1281 | 1281 | |
1282 | 1282 | /** |
@@ -1307,8 +1307,8 @@ discard block |
||
1307 | 1307 | } elseif ($this->isalnumat($this->dataStr, $pos)) { |
1308 | 1308 | return QR_MODE_AN; |
1309 | 1309 | } elseif ($this->hint == QR_MODE_KJ) { |
1310 | - if ($pos+1 < strlen($this->dataStr)) { |
|
1311 | - $d = $this->dataStr[$pos+1]; |
|
1310 | + if ($pos + 1 < strlen($this->dataStr)) { |
|
1311 | + $d = $this->dataStr[$pos + 1]; |
|
1312 | 1312 | $word = (ord($c) << 8) | ord($d); |
1313 | 1313 | if (($word >= 0x8140 && $word <= 0x9ffc) or ($word >= 0xe040 && $word <= 0xebbf)) { |
1314 | 1314 | return QR_MODE_KJ; |
@@ -1325,7 +1325,7 @@ discard block |
||
1325 | 1325 | protected function eatNum() { |
1326 | 1326 | $ln = $this->lengthIndicator(QR_MODE_NM, $this->version); |
1327 | 1327 | $p = 0; |
1328 | - while($this->isdigitat($this->dataStr, $p)) { |
|
1328 | + while ($this->isdigitat($this->dataStr, $p)) { |
|
1329 | 1329 | $p++; |
1330 | 1330 | } |
1331 | 1331 | $run = $p; |
@@ -1341,7 +1341,7 @@ discard block |
||
1341 | 1341 | if ($mode == QR_MODE_AN) { |
1342 | 1342 | $dif = $this->estimateBitsModeNum($run) + 4 + $ln |
1343 | 1343 | + $this->estimateBitsModeAn(1) // + 4 + la |
1344 | - - $this->estimateBitsModeAn($run + 1);// - 4 - la |
|
1344 | + - $this->estimateBitsModeAn($run + 1); // - 4 - la |
|
1345 | 1345 | if ($dif > 0) { |
1346 | 1346 | return $this->eatAn(); |
1347 | 1347 | } |
@@ -1355,13 +1355,13 @@ discard block |
||
1355 | 1355 | * @return int run |
1356 | 1356 | */ |
1357 | 1357 | protected function eatAn() { |
1358 | - $la = $this->lengthIndicator(QR_MODE_AN, $this->version); |
|
1358 | + $la = $this->lengthIndicator(QR_MODE_AN, $this->version); |
|
1359 | 1359 | $ln = $this->lengthIndicator(QR_MODE_NM, $this->version); |
1360 | 1360 | $p = 0; |
1361 | - while($this->isalnumat($this->dataStr, $p)) { |
|
1361 | + while ($this->isalnumat($this->dataStr, $p)) { |
|
1362 | 1362 | if ($this->isdigitat($this->dataStr, $p)) { |
1363 | 1363 | $q = $p; |
1364 | - while($this->isdigitat($this->dataStr, $q)) { |
|
1364 | + while ($this->isdigitat($this->dataStr, $q)) { |
|
1365 | 1365 | $q++; |
1366 | 1366 | } |
1367 | 1367 | $dif = $this->estimateBitsModeAn($p) // + 4 + la |
@@ -1395,7 +1395,7 @@ discard block |
||
1395 | 1395 | */ |
1396 | 1396 | protected function eatKanji() { |
1397 | 1397 | $p = 0; |
1398 | - while($this->identifyMode($p) == QR_MODE_KJ) { |
|
1398 | + while ($this->identifyMode($p) == QR_MODE_KJ) { |
|
1399 | 1399 | $p += 2; |
1400 | 1400 | } |
1401 | 1401 | $this->items = $this->appendNewInputItem($this->items, QR_MODE_KJ, $p, str_split($this->dataStr)); |
@@ -1411,14 +1411,14 @@ discard block |
||
1411 | 1411 | $ln = $this->lengthIndicator(QR_MODE_NM, $this->version); |
1412 | 1412 | $p = 1; |
1413 | 1413 | $dataStrLen = strlen($this->dataStr); |
1414 | - while($p < $dataStrLen) { |
|
1414 | + while ($p < $dataStrLen) { |
|
1415 | 1415 | $mode = $this->identifyMode($p); |
1416 | 1416 | if ($mode == QR_MODE_KJ) { |
1417 | 1417 | break; |
1418 | 1418 | } |
1419 | 1419 | if ($mode == QR_MODE_NM) { |
1420 | 1420 | $q = $p; |
1421 | - while($this->isdigitat($this->dataStr, $q)) { |
|
1421 | + while ($this->isdigitat($this->dataStr, $q)) { |
|
1422 | 1422 | $q++; |
1423 | 1423 | } |
1424 | 1424 | $dif = $this->estimateBitsMode8($p) // + 4 + l8 |
@@ -1431,7 +1431,7 @@ discard block |
||
1431 | 1431 | } |
1432 | 1432 | } elseif ($mode == QR_MODE_AN) { |
1433 | 1433 | $q = $p; |
1434 | - while($this->isalnumat($this->dataStr, $q)) { |
|
1434 | + while ($this->isalnumat($this->dataStr, $q)) { |
|
1435 | 1435 | $q++; |
1436 | 1436 | } |
1437 | 1437 | $dif = $this->estimateBitsMode8($p) // + 4 + l8 |
@@ -1524,7 +1524,7 @@ discard block |
||
1524 | 1524 | * @param array $bstream |
1525 | 1525 | * @return array input item |
1526 | 1526 | */ |
1527 | - protected function newInputItem($mode, $size, $data, $bstream=null) { |
|
1527 | + protected function newInputItem($mode, $size, $data, $bstream = null) { |
|
1528 | 1528 | $setData = array_slice($data, 0, $size); |
1529 | 1529 | if (count($setData) < $size) { |
1530 | 1530 | $setData = array_merge($setData, array_fill(0, ($size - count($setData)), 0)); |
@@ -1547,23 +1547,23 @@ discard block |
||
1547 | 1547 | * @return array input item |
1548 | 1548 | */ |
1549 | 1549 | protected function encodeModeNum($inputitem, $version) { |
1550 | - $words = (int)($inputitem['size'] / 3); |
|
1550 | + $words = (int) ($inputitem['size'] / 3); |
|
1551 | 1551 | $inputitem['bstream'] = array(); |
1552 | 1552 | $val = 0x1; |
1553 | 1553 | $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, $val); |
1554 | 1554 | $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_NM, $version), $inputitem['size']); |
1555 | - for ($i=0; $i < $words; ++$i) { |
|
1556 | - $val = (ord($inputitem['data'][$i*3 ]) - ord('0')) * 100; |
|
1557 | - $val += (ord($inputitem['data'][$i*3+1]) - ord('0')) * 10; |
|
1558 | - $val += (ord($inputitem['data'][$i*3+2]) - ord('0')); |
|
1555 | + for ($i = 0; $i < $words; ++$i) { |
|
1556 | + $val = (ord($inputitem['data'][$i * 3]) - ord('0')) * 100; |
|
1557 | + $val += (ord($inputitem['data'][$i * 3 + 1]) - ord('0')) * 10; |
|
1558 | + $val += (ord($inputitem['data'][$i * 3 + 2]) - ord('0')); |
|
1559 | 1559 | $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 10, $val); |
1560 | 1560 | } |
1561 | 1561 | if ($inputitem['size'] - $words * 3 == 1) { |
1562 | - $val = ord($inputitem['data'][$words*3]) - ord('0'); |
|
1562 | + $val = ord($inputitem['data'][$words * 3]) - ord('0'); |
|
1563 | 1563 | $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, $val); |
1564 | 1564 | } elseif (($inputitem['size'] - ($words * 3)) == 2) { |
1565 | - $val = (ord($inputitem['data'][$words*3 ]) - ord('0')) * 10; |
|
1566 | - $val += (ord($inputitem['data'][$words*3+1]) - ord('0')); |
|
1565 | + $val = (ord($inputitem['data'][$words * 3]) - ord('0')) * 10; |
|
1566 | + $val += (ord($inputitem['data'][$words * 3 + 1]) - ord('0')); |
|
1567 | 1567 | $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 7, $val); |
1568 | 1568 | } |
1569 | 1569 | return $inputitem; |
@@ -1576,13 +1576,13 @@ discard block |
||
1576 | 1576 | * @return array input item |
1577 | 1577 | */ |
1578 | 1578 | protected function encodeModeAn($inputitem, $version) { |
1579 | - $words = (int)($inputitem['size'] / 2); |
|
1579 | + $words = (int) ($inputitem['size'] / 2); |
|
1580 | 1580 | $inputitem['bstream'] = array(); |
1581 | 1581 | $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x02); |
1582 | 1582 | $inputitem['bstream'] = $this->appendNum(v, $this->lengthIndicator(QR_MODE_AN, $version), $inputitem['size']); |
1583 | - for ($i=0; $i < $words; ++$i) { |
|
1584 | - $val = (int)$this->lookAnTable(ord($inputitem['data'][$i*2 ])) * 45; |
|
1585 | - $val += (int)$this->lookAnTable(ord($inputitem['data'][$i*2+1])); |
|
1583 | + for ($i = 0; $i < $words; ++$i) { |
|
1584 | + $val = (int) $this->lookAnTable(ord($inputitem['data'][$i * 2])) * 45; |
|
1585 | + $val += (int) $this->lookAnTable(ord($inputitem['data'][$i * 2 + 1])); |
|
1586 | 1586 | $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 11, $val); |
1587 | 1587 | } |
1588 | 1588 | if ($inputitem['size'] & 1) { |
@@ -1602,7 +1602,7 @@ discard block |
||
1602 | 1602 | $inputitem['bstream'] = array(); |
1603 | 1603 | $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x4); |
1604 | 1604 | $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_8B, $version), $inputitem['size']); |
1605 | - for ($i=0; $i < $inputitem['size']; ++$i) { |
|
1605 | + for ($i = 0; $i < $inputitem['size']; ++$i) { |
|
1606 | 1606 | $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 8, ord($inputitem['data'][$i])); |
1607 | 1607 | } |
1608 | 1608 | return $inputitem; |
@@ -1617,9 +1617,9 @@ discard block |
||
1617 | 1617 | protected function encodeModeKanji($inputitem, $version) { |
1618 | 1618 | $inputitem['bstream'] = array(); |
1619 | 1619 | $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x8); |
1620 | - $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_KJ, $version), (int)($inputitem['size'] / 2)); |
|
1621 | - for ($i=0; $i<$inputitem['size']; $i+=2) { |
|
1622 | - $val = (ord($inputitem['data'][$i]) << 8) | ord($inputitem['data'][$i+1]); |
|
1620 | + $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_KJ, $version), (int) ($inputitem['size'] / 2)); |
|
1621 | + for ($i = 0; $i < $inputitem['size']; $i += 2) { |
|
1622 | + $val = (ord($inputitem['data'][$i]) << 8) | ord($inputitem['data'][$i + 1]); |
|
1623 | 1623 | if ($val <= 0x9ffc) { |
1624 | 1624 | $val -= 0x8140; |
1625 | 1625 | } else { |
@@ -1664,7 +1664,7 @@ discard block |
||
1664 | 1664 | $inputitem['bstream'] = $this->appendBitstream($inputitem['bstream'], $st1['bstream']); |
1665 | 1665 | $inputitem['bstream'] = $this->appendBitstream($inputitem['bstream'], $st2['bstream']); |
1666 | 1666 | } else { |
1667 | - switch($inputitem['mode']) { |
|
1667 | + switch ($inputitem['mode']) { |
|
1668 | 1668 | case QR_MODE_NM: { |
1669 | 1669 | $inputitem = $this->encodeModeNum($inputitem, $version); |
1670 | 1670 | break; |
@@ -1742,7 +1742,7 @@ discard block |
||
1742 | 1742 | $parity = 0; |
1743 | 1743 | foreach ($items as $item) { |
1744 | 1744 | if ($item['mode'] != QR_MODE_ST) { |
1745 | - for ($i=$item['size']-1; $i>=0; --$i) { |
|
1745 | + for ($i = $item['size'] - 1; $i >= 0; --$i) { |
|
1746 | 1746 | $parity ^= $item['data'][$i]; |
1747 | 1747 | } |
1748 | 1748 | } |
@@ -1757,8 +1757,8 @@ discard block |
||
1757 | 1757 | * @return boolean true or false |
1758 | 1758 | */ |
1759 | 1759 | protected function checkModeNum($size, $data) { |
1760 | - for ($i=0; $i<$size; ++$i) { |
|
1761 | - if ((ord($data[$i]) < ord('0')) or (ord($data[$i]) > ord('9'))){ |
|
1760 | + for ($i = 0; $i < $size; ++$i) { |
|
1761 | + if ((ord($data[$i]) < ord('0')) or (ord($data[$i]) > ord('9'))) { |
|
1762 | 1762 | return false; |
1763 | 1763 | } |
1764 | 1764 | } |
@@ -1771,9 +1771,9 @@ discard block |
||
1771 | 1771 | * @return int number of bits |
1772 | 1772 | */ |
1773 | 1773 | protected function estimateBitsModeNum($size) { |
1774 | - $w = (int)$size / 3; |
|
1774 | + $w = (int) $size / 3; |
|
1775 | 1775 | $bits = $w * 10; |
1776 | - switch($size - $w * 3) { |
|
1776 | + switch ($size - $w * 3) { |
|
1777 | 1777 | case 1: { |
1778 | 1778 | $bits += 4; |
1779 | 1779 | break; |
@@ -1795,7 +1795,7 @@ discard block |
||
1795 | 1795 | * @return value |
1796 | 1796 | */ |
1797 | 1797 | protected function lookAnTable($c) { |
1798 | - return (($c > 127)?-1:$this->anTable[$c]); |
|
1798 | + return (($c > 127) ?-1 : $this->anTable[$c]); |
|
1799 | 1799 | } |
1800 | 1800 | |
1801 | 1801 | /** |
@@ -1805,7 +1805,7 @@ discard block |
||
1805 | 1805 | * @return boolean true or false |
1806 | 1806 | */ |
1807 | 1807 | protected function checkModeAn($size, $data) { |
1808 | - for ($i=0; $i<$size; ++$i) { |
|
1808 | + for ($i = 0; $i < $size; ++$i) { |
|
1809 | 1809 | if ($this->lookAnTable(ord($data[$i])) == -1) { |
1810 | 1810 | return false; |
1811 | 1811 | } |
@@ -1819,7 +1819,7 @@ discard block |
||
1819 | 1819 | * @return int number of bits |
1820 | 1820 | */ |
1821 | 1821 | protected function estimateBitsModeAn($size) { |
1822 | - $w = (int)($size / 2); |
|
1822 | + $w = (int) ($size / 2); |
|
1823 | 1823 | $bits = $w * 11; |
1824 | 1824 | if ($size & 1) { |
1825 | 1825 | $bits += 6; |
@@ -1842,7 +1842,7 @@ discard block |
||
1842 | 1842 | * @return int number of bits |
1843 | 1843 | */ |
1844 | 1844 | protected function estimateBitsModeKanji($size) { |
1845 | - return (int)(($size / 2) * 13); |
|
1845 | + return (int) (($size / 2) * 13); |
|
1846 | 1846 | } |
1847 | 1847 | |
1848 | 1848 | /** |
@@ -1855,8 +1855,8 @@ discard block |
||
1855 | 1855 | if ($size & 1) { |
1856 | 1856 | return false; |
1857 | 1857 | } |
1858 | - for ($i=0; $i<$size; $i+=2) { |
|
1859 | - $val = (ord($data[$i]) << 8) | ord($data[$i+1]); |
|
1858 | + for ($i = 0; $i < $size; $i += 2) { |
|
1859 | + $val = (ord($data[$i]) << 8) | ord($data[$i + 1]); |
|
1860 | 1860 | if (($val < 0x8140) or (($val > 0x9ffc) and ($val < 0xe040)) or ($val > 0xebbf)) { |
1861 | 1861 | return false; |
1862 | 1862 | } |
@@ -1875,7 +1875,7 @@ discard block |
||
1875 | 1875 | if ($size <= 0) { |
1876 | 1876 | return false; |
1877 | 1877 | } |
1878 | - switch($mode) { |
|
1878 | + switch ($mode) { |
|
1879 | 1879 | case QR_MODE_NM: { |
1880 | 1880 | return $this->checkModeNum($size, $data); |
1881 | 1881 | } |
@@ -1910,7 +1910,7 @@ discard block |
||
1910 | 1910 | $version = 1; |
1911 | 1911 | } |
1912 | 1912 | foreach ($items as $item) { |
1913 | - switch($item['mode']) { |
|
1913 | + switch ($item['mode']) { |
|
1914 | 1914 | case QR_MODE_NM: { |
1915 | 1915 | $bits = $this->estimateBitsModeNum($item['size']); |
1916 | 1916 | break; |
@@ -1936,7 +1936,7 @@ discard block |
||
1936 | 1936 | } |
1937 | 1937 | $l = $this->lengthIndicator($item['mode'], $version); |
1938 | 1938 | $m = 1 << $l; |
1939 | - $num = (int)(($item['size'] + $m - 1) / $m); |
|
1939 | + $num = (int) (($item['size'] + $m - 1) / $m); |
|
1940 | 1940 | $bits += $num * (4 + $l); |
1941 | 1941 | } |
1942 | 1942 | return $bits; |
@@ -1953,7 +1953,7 @@ discard block |
||
1953 | 1953 | do { |
1954 | 1954 | $prev = $version; |
1955 | 1955 | $bits = $this->estimateBitStreamSize($items, $prev); |
1956 | - $version = $this->getMinimumVersion((int)(($bits + 7) / 8), $this->level); |
|
1956 | + $version = $this->getMinimumVersion((int) (($bits + 7) / 8), $this->level); |
|
1957 | 1957 | if ($version < 0) { |
1958 | 1958 | return -1; |
1959 | 1959 | } |
@@ -1970,9 +1970,9 @@ discard block |
||
1970 | 1970 | */ |
1971 | 1971 | protected function lengthOfCode($mode, $version, $bits) { |
1972 | 1972 | $payload = $bits - 4 - $this->lengthIndicator($mode, $version); |
1973 | - switch($mode) { |
|
1973 | + switch ($mode) { |
|
1974 | 1974 | case QR_MODE_NM: { |
1975 | - $chunks = (int)($payload / 10); |
|
1975 | + $chunks = (int) ($payload / 10); |
|
1976 | 1976 | $remain = $payload - $chunks * 10; |
1977 | 1977 | $size = $chunks * 3; |
1978 | 1978 | if ($remain >= 7) { |
@@ -1983,7 +1983,7 @@ discard block |
||
1983 | 1983 | break; |
1984 | 1984 | } |
1985 | 1985 | case QR_MODE_AN: { |
1986 | - $chunks = (int)($payload / 11); |
|
1986 | + $chunks = (int) ($payload / 11); |
|
1987 | 1987 | $remain = $payload - $chunks * 11; |
1988 | 1988 | $size = $chunks * 2; |
1989 | 1989 | if ($remain >= 6) { |
@@ -1992,15 +1992,15 @@ discard block |
||
1992 | 1992 | break; |
1993 | 1993 | } |
1994 | 1994 | case QR_MODE_8B: { |
1995 | - $size = (int)($payload / 8); |
|
1995 | + $size = (int) ($payload / 8); |
|
1996 | 1996 | break; |
1997 | 1997 | } |
1998 | 1998 | case QR_MODE_KJ: { |
1999 | - $size = (int)(($payload / 13) * 2); |
|
1999 | + $size = (int) (($payload / 13) * 2); |
|
2000 | 2000 | break; |
2001 | 2001 | } |
2002 | 2002 | case QR_MODE_ST: { |
2003 | - $size = (int)($payload / 8); |
|
2003 | + $size = (int) ($payload / 8); |
|
2004 | 2004 | break; |
2005 | 2005 | } |
2006 | 2006 | default: { |
@@ -2050,7 +2050,7 @@ discard block |
||
2050 | 2050 | if ($bits < 0) { |
2051 | 2051 | return -1; |
2052 | 2052 | } |
2053 | - $ver = $this->getMinimumVersion((int)(($bits + 7) / 8), $this->level); |
|
2053 | + $ver = $this->getMinimumVersion((int) (($bits + 7) / 8), $this->level); |
|
2054 | 2054 | if ($ver < 0) { |
2055 | 2055 | return -1; |
2056 | 2056 | } elseif ($ver > $this->version) { |
@@ -2078,14 +2078,14 @@ discard block |
||
2078 | 2078 | return $this->appendNum($bstream, $maxbits - $bits, 0); |
2079 | 2079 | } |
2080 | 2080 | $bits += 4; |
2081 | - $words = (int)(($bits + 7) / 8); |
|
2081 | + $words = (int) (($bits + 7) / 8); |
|
2082 | 2082 | $padding = array(); |
2083 | 2083 | $padding = $this->appendNum($padding, $words * 8 - $bits + 4, 0); |
2084 | 2084 | $padlen = $maxwords - $words; |
2085 | 2085 | if ($padlen > 0) { |
2086 | 2086 | $padbuf = array(); |
2087 | - for ($i=0; $i<$padlen; ++$i) { |
|
2088 | - $padbuf[$i] = ($i&1)?0x11:0xec; |
|
2087 | + for ($i = 0; $i < $padlen; ++$i) { |
|
2088 | + $padbuf[$i] = ($i & 1) ? 0x11 : 0xec; |
|
2089 | 2089 | } |
2090 | 2090 | $padding = $this->appendBytes($padding, $padlen, $padbuf); |
2091 | 2091 | } |
@@ -2148,7 +2148,7 @@ discard block |
||
2148 | 2148 | protected function newFromNum($bits, $num) { |
2149 | 2149 | $bstream = $this->allocate($bits); |
2150 | 2150 | $mask = 1 << ($bits - 1); |
2151 | - for ($i=0; $i<$bits; ++$i) { |
|
2151 | + for ($i = 0; $i < $bits; ++$i) { |
|
2152 | 2152 | if ($num & $mask) { |
2153 | 2153 | $bstream[$i] = 1; |
2154 | 2154 | } else { |
@@ -2167,10 +2167,10 @@ discard block |
||
2167 | 2167 | */ |
2168 | 2168 | protected function newFromBytes($size, $data) { |
2169 | 2169 | $bstream = $this->allocate($size * 8); |
2170 | - $p=0; |
|
2171 | - for ($i=0; $i<$size; ++$i) { |
|
2170 | + $p = 0; |
|
2171 | + for ($i = 0; $i < $size; ++$i) { |
|
2172 | 2172 | $mask = 0x80; |
2173 | - for ($j=0; $j<8; ++$j) { |
|
2173 | + for ($j = 0; $j < 8; ++$j) { |
|
2174 | 2174 | if ($data[$i] & $mask) { |
2175 | 2175 | $bstream[$p] = 1; |
2176 | 2176 | } else { |
@@ -2239,12 +2239,12 @@ discard block |
||
2239 | 2239 | if ($size == 0) { |
2240 | 2240 | return array(); |
2241 | 2241 | } |
2242 | - $data = array_fill(0, (int)(($size + 7) / 8), 0); |
|
2243 | - $bytes = (int)($size / 8); |
|
2242 | + $data = array_fill(0, (int) (($size + 7) / 8), 0); |
|
2243 | + $bytes = (int) ($size / 8); |
|
2244 | 2244 | $p = 0; |
2245 | - for ($i=0; $i<$bytes; $i++) { |
|
2245 | + for ($i = 0; $i < $bytes; $i++) { |
|
2246 | 2246 | $v = 0; |
2247 | - for ($j=0; $j<8; $j++) { |
|
2247 | + for ($j = 0; $j < 8; $j++) { |
|
2248 | 2248 | $v = $v << 1; |
2249 | 2249 | $v |= $bstream[$p]; |
2250 | 2250 | $p++; |
@@ -2253,7 +2253,7 @@ discard block |
||
2253 | 2253 | } |
2254 | 2254 | if ($size & 7) { |
2255 | 2255 | $v = 0; |
2256 | - for ($j=0; $j<($size & 7); $j++) { |
|
2256 | + for ($j = 0; $j < ($size & 7); $j++) { |
|
2257 | 2257 | $v = $v << 1; |
2258 | 2258 | $v |= $bstream[$p]; |
2259 | 2259 | $p++; |
@@ -2276,8 +2276,8 @@ discard block |
||
2276 | 2276 | * @param int $replLen length of the repl string |
2277 | 2277 | * @return array srctab |
2278 | 2278 | */ |
2279 | - protected function qrstrset($srctab, $x, $y, $repl, $replLen=false) { |
|
2280 | - $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl)); |
|
2279 | + protected function qrstrset($srctab, $x, $y, $repl, $replLen = false) { |
|
2280 | + $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false) ?substr($repl, 0, $replLen) : $repl, $x, ($replLen !== false) ? $replLen : strlen($repl)); |
|
2281 | 2281 | return $srctab; |
2282 | 2282 | } |
2283 | 2283 | |
@@ -2297,7 +2297,7 @@ discard block |
||
2297 | 2297 | * @param int $level error correction level |
2298 | 2298 | * @return int ECC size (bytes) |
2299 | 2299 | */ |
2300 | - protected function getECCLength($version, $level){ |
|
2300 | + protected function getECCLength($version, $level) { |
|
2301 | 2301 | return $this->capacity[$version][QRCAP_EC][$level]; |
2302 | 2302 | } |
2303 | 2303 | |
@@ -2326,8 +2326,8 @@ discard block |
||
2326 | 2326 | * @return int version number |
2327 | 2327 | */ |
2328 | 2328 | protected function getMinimumVersion($size, $level) { |
2329 | - for ($i=1; $i <= QRSPEC_VERSION_MAX; ++$i) { |
|
2330 | - $words = $this->capacity[$i][QRCAP_WORDS] - $this->capacity[$i][QRCAP_EC][$level]; |
|
2329 | + for ($i = 1; $i <= QRSPEC_VERSION_MAX; ++$i) { |
|
2330 | + $words = $this->capacity[$i][QRCAP_WORDS] - $this->capacity[$i][QRCAP_EC][$level]; |
|
2331 | 2331 | if ($words >= $size) { |
2332 | 2332 | return $i; |
2333 | 2333 | } |
@@ -2397,14 +2397,14 @@ discard block |
||
2397 | 2397 | $ecc = $this->getECCLength($version, $level); |
2398 | 2398 | if ($b2 == 0) { |
2399 | 2399 | $spec[0] = $b1; |
2400 | - $spec[1] = (int)($data / $b1); |
|
2401 | - $spec[2] = (int)($ecc / $b1); |
|
2400 | + $spec[1] = (int) ($data / $b1); |
|
2401 | + $spec[2] = (int) ($ecc / $b1); |
|
2402 | 2402 | $spec[3] = 0; |
2403 | 2403 | $spec[4] = 0; |
2404 | 2404 | } else { |
2405 | 2405 | $spec[0] = $b1; |
2406 | - $spec[1] = (int)($data / ($b1 + $b2)); |
|
2407 | - $spec[2] = (int)($ecc / ($b1 + $b2)); |
|
2406 | + $spec[1] = (int) ($data / ($b1 + $b2)); |
|
2407 | + $spec[2] = (int) ($ecc / ($b1 + $b2)); |
|
2408 | 2408 | $spec[3] = $b2; |
2409 | 2409 | $spec[4] = $spec[1] + 1; |
2410 | 2410 | } |
@@ -2429,8 +2429,8 @@ discard block |
||
2429 | 2429 | ); |
2430 | 2430 | $yStart = $oy - 2; |
2431 | 2431 | $xStart = $ox - 2; |
2432 | - for ($y=0; $y < 5; $y++) { |
|
2433 | - $frame = $this->qrstrset($frame, $xStart, $yStart+$y, $finder[$y]); |
|
2432 | + for ($y = 0; $y < 5; $y++) { |
|
2433 | + $frame = $this->qrstrset($frame, $xStart, $yStart + $y, $finder[$y]); |
|
2434 | 2434 | } |
2435 | 2435 | return $frame; |
2436 | 2436 | } |
@@ -2450,7 +2450,7 @@ discard block |
||
2450 | 2450 | if ($d < 0) { |
2451 | 2451 | $w = 2; |
2452 | 2452 | } else { |
2453 | - $w = (int)(($width - $this->alignmentPattern[$version][0]) / $d + 2); |
|
2453 | + $w = (int) (($width - $this->alignmentPattern[$version][0]) / $d + 2); |
|
2454 | 2454 | } |
2455 | 2455 | if ($w * $w - 3 == 1) { |
2456 | 2456 | $x = $this->alignmentPattern[$version][0]; |
@@ -2460,15 +2460,15 @@ discard block |
||
2460 | 2460 | } |
2461 | 2461 | $cx = $this->alignmentPattern[$version][0]; |
2462 | 2462 | $wo = $w - 1; |
2463 | - for ($x=1; $x < $wo; ++$x) { |
|
2463 | + for ($x = 1; $x < $wo; ++$x) { |
|
2464 | 2464 | $frame = $this->putAlignmentMarker($frame, 6, $cx); |
2465 | - $frame = $this->putAlignmentMarker($frame, $cx, 6); |
|
2465 | + $frame = $this->putAlignmentMarker($frame, $cx, 6); |
|
2466 | 2466 | $cx += $d; |
2467 | 2467 | } |
2468 | 2468 | $cy = $this->alignmentPattern[$version][0]; |
2469 | - for ($y=0; $y < $wo; ++$y) { |
|
2469 | + for ($y = 0; $y < $wo; ++$y) { |
|
2470 | 2470 | $cx = $this->alignmentPattern[$version][0]; |
2471 | - for ($x=0; $x < $wo; ++$x) { |
|
2471 | + for ($x = 0; $x < $wo; ++$x) { |
|
2472 | 2472 | $frame = $this->putAlignmentMarker($frame, $cx, $cy); |
2473 | 2473 | $cx += $d; |
2474 | 2474 | } |
@@ -2523,7 +2523,7 @@ discard block |
||
2523 | 2523 | "\xc1\xc0\xc0\xc0\xc0\xc0\xc1", |
2524 | 2524 | "\xc1\xc1\xc1\xc1\xc1\xc1\xc1" |
2525 | 2525 | ); |
2526 | - for ($y=0; $y < 7; $y++) { |
|
2526 | + for ($y = 0; $y < 7; $y++) { |
|
2527 | 2527 | $frame = $this->qrstrset($frame, $ox, ($oy + $y), $finder[$y]); |
2528 | 2528 | } |
2529 | 2529 | return $frame; |
@@ -2536,7 +2536,7 @@ discard block |
||
2536 | 2536 | */ |
2537 | 2537 | protected function createFrame($version) { |
2538 | 2538 | $width = $this->capacity[$version][QRCAP_WIDTH]; |
2539 | - $frameLine = str_repeat ("\0", $width); |
|
2539 | + $frameLine = str_repeat("\0", $width); |
|
2540 | 2540 | $frame = array_fill(0, $width, $frameLine); |
2541 | 2541 | // Finder pattern |
2542 | 2542 | $frame = $this->putFinderPattern($frame, 0, 0); |
@@ -2544,7 +2544,7 @@ discard block |
||
2544 | 2544 | $frame = $this->putFinderPattern($frame, 0, $width - 7); |
2545 | 2545 | // Separator |
2546 | 2546 | $yOffset = $width - 7; |
2547 | - for ($y=0; $y < 7; ++$y) { |
|
2547 | + for ($y = 0; $y < 7; ++$y) { |
|
2548 | 2548 | $frame[$y][7] = "\xc0"; |
2549 | 2549 | $frame[$y][$width - 8] = "\xc0"; |
2550 | 2550 | $frame[$yOffset][7] = "\xc0"; |
@@ -2552,22 +2552,22 @@ discard block |
||
2552 | 2552 | } |
2553 | 2553 | $setPattern = str_repeat("\xc0", 8); |
2554 | 2554 | $frame = $this->qrstrset($frame, 0, 7, $setPattern); |
2555 | - $frame = $this->qrstrset($frame, $width-8, 7, $setPattern); |
|
2555 | + $frame = $this->qrstrset($frame, $width - 8, 7, $setPattern); |
|
2556 | 2556 | $frame = $this->qrstrset($frame, 0, $width - 8, $setPattern); |
2557 | 2557 | // Format info |
2558 | 2558 | $setPattern = str_repeat("\x84", 9); |
2559 | 2559 | $frame = $this->qrstrset($frame, 0, 8, $setPattern); |
2560 | 2560 | $frame = $this->qrstrset($frame, $width - 8, 8, $setPattern, 8); |
2561 | 2561 | $yOffset = $width - 8; |
2562 | - for ($y=0; $y < 8; ++$y,++$yOffset) { |
|
2562 | + for ($y = 0; $y < 8; ++$y, ++$yOffset) { |
|
2563 | 2563 | $frame[$y][8] = "\x84"; |
2564 | 2564 | $frame[$yOffset][8] = "\x84"; |
2565 | 2565 | } |
2566 | 2566 | // Timing pattern |
2567 | 2567 | $wo = $width - 15; |
2568 | - for ($i=1; $i < $wo; ++$i) { |
|
2569 | - $frame[6][7+$i] = chr(0x90 | ($i & 1)); |
|
2570 | - $frame[7+$i][6] = chr(0x90 | ($i & 1)); |
|
2568 | + for ($i = 1; $i < $wo; ++$i) { |
|
2569 | + $frame[6][7 + $i] = chr(0x90 | ($i & 1)); |
|
2570 | + $frame[7 + $i][6] = chr(0x90 | ($i & 1)); |
|
2571 | 2571 | } |
2572 | 2572 | // Alignment pattern |
2573 | 2573 | $frame = $this->putAlignmentPattern($version, $frame, $width); |
@@ -2575,16 +2575,16 @@ discard block |
||
2575 | 2575 | if ($version >= 7) { |
2576 | 2576 | $vinf = $this->getVersionPattern($version); |
2577 | 2577 | $v = $vinf; |
2578 | - for ($x=0; $x<6; ++$x) { |
|
2579 | - for ($y=0; $y<3; ++$y) { |
|
2580 | - $frame[($width - 11)+$y][$x] = chr(0x88 | ($v & 1)); |
|
2578 | + for ($x = 0; $x < 6; ++$x) { |
|
2579 | + for ($y = 0; $y < 3; ++$y) { |
|
2580 | + $frame[($width - 11) + $y][$x] = chr(0x88 | ($v & 1)); |
|
2581 | 2581 | $v = $v >> 1; |
2582 | 2582 | } |
2583 | 2583 | } |
2584 | 2584 | $v = $vinf; |
2585 | - for ($y=0; $y<6; ++$y) { |
|
2586 | - for ($x=0; $x<3; ++$x) { |
|
2587 | - $frame[$y][$x+($width - 11)] = chr(0x88 | ($v & 1)); |
|
2585 | + for ($y = 0; $y < 6; ++$y) { |
|
2586 | + for ($x = 0; $x < 3; ++$x) { |
|
2587 | + $frame[$y][$x + ($width - 11)] = chr(0x88 | ($v & 1)); |
|
2588 | 2588 | $v = $v >> 1; |
2589 | 2589 | } |
2590 | 2590 | } |
@@ -2755,16 +2755,16 @@ discard block |
||
2755 | 2755 | if (($symsize < 0) or ($symsize > 8)) { |
2756 | 2756 | return $rs; |
2757 | 2757 | } |
2758 | - if (($fcr < 0) or ($fcr >= (1<<$symsize))) { |
|
2758 | + if (($fcr < 0) or ($fcr >= (1 << $symsize))) { |
|
2759 | 2759 | return $rs; |
2760 | 2760 | } |
2761 | - if (($prim <= 0) or ($prim >= (1<<$symsize))) { |
|
2761 | + if (($prim <= 0) or ($prim >= (1 << $symsize))) { |
|
2762 | 2762 | return $rs; |
2763 | 2763 | } |
2764 | - if (($nroots < 0) or ($nroots >= (1<<$symsize))) { |
|
2764 | + if (($nroots < 0) or ($nroots >= (1 << $symsize))) { |
|
2765 | 2765 | return $rs; |
2766 | 2766 | } |
2767 | - if (($pad < 0) or ($pad >= ((1<<$symsize) -1 - $nroots))) { |
|
2767 | + if (($pad < 0) or ($pad >= ((1 << $symsize) - 1 - $nroots))) { |
|
2768 | 2768 | return $rs; |
2769 | 2769 | } |
2770 | 2770 | $rs = array(); |
@@ -2774,13 +2774,13 @@ discard block |
||
2774 | 2774 | $rs['alpha_to'] = array_fill(0, ($rs['nn'] + 1), 0); |
2775 | 2775 | $rs['index_of'] = array_fill(0, ($rs['nn'] + 1), 0); |
2776 | 2776 | // PHP style macro replacement ;) |
2777 | - $NN =& $rs['nn']; |
|
2778 | - $A0 =& $NN; |
|
2777 | + $NN = & $rs['nn']; |
|
2778 | + $A0 = & $NN; |
|
2779 | 2779 | // Generate Galois field lookup tables |
2780 | 2780 | $rs['index_of'][0] = $A0; // log(zero) = -inf |
2781 | 2781 | $rs['alpha_to'][$A0] = 0; // alpha**-inf = 0 |
2782 | 2782 | $sr = 1; |
2783 | - for ($i=0; $i<$rs['nn']; ++$i) { |
|
2783 | + for ($i = 0; $i < $rs['nn']; ++$i) { |
|
2784 | 2784 | $rs['index_of'][$sr] = $i; |
2785 | 2785 | $rs['alpha_to'][$i] = $sr; |
2786 | 2786 | $sr <<= 1; |
@@ -2800,21 +2800,21 @@ discard block |
||
2800 | 2800 | $rs['nroots'] = $nroots; |
2801 | 2801 | $rs['gfpoly'] = $gfpoly; |
2802 | 2802 | // Find prim-th root of 1, used in decoding |
2803 | - for ($iprim=1; ($iprim % $prim) != 0; $iprim += $rs['nn']) { |
|
2803 | + for ($iprim = 1; ($iprim % $prim) != 0; $iprim += $rs['nn']) { |
|
2804 | 2804 | ; // intentional empty-body loop! |
2805 | 2805 | } |
2806 | - $rs['iprim'] = (int)($iprim / $prim); |
|
2806 | + $rs['iprim'] = (int) ($iprim / $prim); |
|
2807 | 2807 | $rs['genpoly'][0] = 1; |
2808 | 2808 | |
2809 | 2809 | |
2810 | - for ($i = 0,$root=$fcr*$prim; $i < $nroots; $i++, $root += $prim) { |
|
2811 | - $rs['genpoly'][$i+1] = 1; |
|
2810 | + for ($i = 0, $root = $fcr * $prim; $i < $nroots; $i++, $root += $prim) { |
|
2811 | + $rs['genpoly'][$i + 1] = 1; |
|
2812 | 2812 | // Multiply rs->genpoly[] by @**(root + x) |
2813 | 2813 | for ($j = $i; $j > 0; --$j) { |
2814 | 2814 | if ($rs['genpoly'][$j] != 0) { |
2815 | - $rs['genpoly'][$j] = $rs['genpoly'][$j-1] ^ $rs['alpha_to'][$this->modnn($rs, $rs['index_of'][$rs['genpoly'][$j]] + $root)]; |
|
2815 | + $rs['genpoly'][$j] = $rs['genpoly'][$j - 1] ^ $rs['alpha_to'][$this->modnn($rs, $rs['index_of'][$rs['genpoly'][$j]] + $root)]; |
|
2816 | 2816 | } else { |
2817 | - $rs['genpoly'][$j] = $rs['genpoly'][$j-1]; |
|
2817 | + $rs['genpoly'][$j] = $rs['genpoly'][$j - 1]; |
|
2818 | 2818 | } |
2819 | 2819 | } |
2820 | 2820 | // rs->genpoly[0] can never be zero |
@@ -2835,26 +2835,26 @@ discard block |
||
2835 | 2835 | * @return parity array |
2836 | 2836 | */ |
2837 | 2837 | protected function encode_rs_char($rs, $data, $parity) { |
2838 | - $MM =& $rs['mm']; // bits per symbol |
|
2839 | - $NN =& $rs['nn']; // the total number of symbols in a RS block |
|
2840 | - $ALPHA_TO =& $rs['alpha_to']; // the address of an array of NN elements to convert Galois field elements in index (log) form to polynomial form |
|
2841 | - $INDEX_OF =& $rs['index_of']; // the address of an array of NN elements to convert Galois field elements in polynomial form to index (log) form |
|
2842 | - $GENPOLY =& $rs['genpoly']; // an array of NROOTS+1 elements containing the generator polynomial in index form |
|
2843 | - $NROOTS =& $rs['nroots']; // the number of roots in the RS code generator polynomial, which is the same as the number of parity symbols in a block |
|
2844 | - $FCR =& $rs['fcr']; // first consecutive root, index form |
|
2845 | - $PRIM =& $rs['prim']; // primitive element, index form |
|
2846 | - $IPRIM =& $rs['iprim']; // prim-th root of 1, index form |
|
2847 | - $PAD =& $rs['pad']; // the number of pad symbols in a block |
|
2848 | - $A0 =& $NN; |
|
2838 | + $MM = & $rs['mm']; // bits per symbol |
|
2839 | + $NN = & $rs['nn']; // the total number of symbols in a RS block |
|
2840 | + $ALPHA_TO = & $rs['alpha_to']; // the address of an array of NN elements to convert Galois field elements in index (log) form to polynomial form |
|
2841 | + $INDEX_OF = & $rs['index_of']; // the address of an array of NN elements to convert Galois field elements in polynomial form to index (log) form |
|
2842 | + $GENPOLY = & $rs['genpoly']; // an array of NROOTS+1 elements containing the generator polynomial in index form |
|
2843 | + $NROOTS = & $rs['nroots']; // the number of roots in the RS code generator polynomial, which is the same as the number of parity symbols in a block |
|
2844 | + $FCR = & $rs['fcr']; // first consecutive root, index form |
|
2845 | + $PRIM = & $rs['prim']; // primitive element, index form |
|
2846 | + $IPRIM = & $rs['iprim']; // prim-th root of 1, index form |
|
2847 | + $PAD = & $rs['pad']; // the number of pad symbols in a block |
|
2848 | + $A0 = & $NN; |
|
2849 | 2849 | $parity = array_fill(0, $NROOTS, 0); |
2850 | - for ($i=0; $i < ($NN - $NROOTS - $PAD); $i++) { |
|
2850 | + for ($i = 0; $i < ($NN - $NROOTS - $PAD); $i++) { |
|
2851 | 2851 | $feedback = $INDEX_OF[$data[$i] ^ $parity[0]]; |
2852 | 2852 | if ($feedback != $A0) { |
2853 | 2853 | // feedback term is non-zero |
2854 | 2854 | // This line is unnecessary when GENPOLY[NROOTS] is unity, as it must |
2855 | 2855 | // always be for the polynomials constructed by init_rs() |
2856 | 2856 | $feedback = $this->modnn($rs, $NN - $GENPOLY[$NROOTS] + $feedback); |
2857 | - for ($j=1; $j < $NROOTS; ++$j) { |
|
2857 | + for ($j = 1; $j < $NROOTS; ++$j) { |
|
2858 | 2858 | $parity[$j] ^= $ALPHA_TO[$this->modnn($rs, $feedback + $GENPOLY[($NROOTS - $j)])]; |
2859 | 2859 | } |
2860 | 2860 | } |
@@ -93,11 +93,11 @@ discard block |
||
93 | 93 | // Supported output formats |
94 | 94 | |
95 | 95 | define('QR_FORMAT_TEXT', 0); |
96 | - define('QR_FORMAT_PNG', 1); |
|
96 | + define('QR_FORMAT_PNG', 1); |
|
97 | 97 | |
98 | 98 | class qrstr { |
99 | 99 | public static function set(&$srctab, $x, $y, $repl, $replLen = false) { |
100 | - $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl)); |
|
100 | + $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false) ?substr($repl, 0, $replLen) : $repl, $x, ($replLen !== false) ? $replLen : strlen($repl)); |
|
101 | 101 | } |
102 | 102 | } |
103 | 103 | |
@@ -114,15 +114,15 @@ discard block |
||
114 | 114 | * Config file, tuned-up for merged verion |
115 | 115 | */ |
116 | 116 | |
117 | - define('QR_CACHEABLE', false); // use cache - more disk reads but less CPU power, masks and format templates are stored there |
|
118 | - define('QR_CACHE_DIR', false); // used when QR_CACHEABLE === true |
|
119 | - define('QR_LOG_DIR', false); // default error logs dir |
|
117 | + define('QR_CACHEABLE', false); // use cache - more disk reads but less CPU power, masks and format templates are stored there |
|
118 | + define('QR_CACHE_DIR', false); // used when QR_CACHEABLE === true |
|
119 | + define('QR_LOG_DIR', false); // default error logs dir |
|
120 | 120 | |
121 | - 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 |
|
122 | - 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 |
|
123 | - define('QR_DEFAULT_MASK', 2); // when QR_FIND_BEST_MASK === false |
|
121 | + 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 |
|
122 | + 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 |
|
123 | + define('QR_DEFAULT_MASK', 2); // when QR_FIND_BEST_MASK === false |
|
124 | 124 | |
125 | - 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 |
|
125 | + 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 | 126 | |
127 | 127 | |
128 | 128 | |
@@ -163,8 +163,8 @@ discard block |
||
163 | 163 | $len = count($frame); |
164 | 164 | foreach ($frame as &$frameLine) { |
165 | 165 | |
166 | - for($i=0; $i<$len; $i++) { |
|
167 | - $frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0'; |
|
166 | + for ($i = 0; $i < $len; $i++) { |
|
167 | + $frameLine[$i] = (ord($frameLine[$i]) & 1) ? '1' : '0'; |
|
168 | 168 | } |
169 | 169 | } |
170 | 170 | |
@@ -194,8 +194,8 @@ discard block |
||
194 | 194 | |
195 | 195 | foreach ($qrTab as $line) { |
196 | 196 | $arrAdd = array(); |
197 | - foreach(str_split($line) as $char) |
|
198 | - $arrAdd[] = ($char=='1')?1:0; |
|
197 | + foreach (str_split($line) as $char) |
|
198 | + $arrAdd[] = ($char == '1') ? 1 : 0; |
|
199 | 199 | $barcode_array['bcode'][] = $arrAdd; |
200 | 200 | } |
201 | 201 | |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | QRtools::markTime('before_build_cache'); |
215 | 215 | |
216 | 216 | $mask = new QRmask(); |
217 | - for ($a=1; $a <= QRSPEC_VERSION_MAX; $a++) { |
|
217 | + for ($a = 1; $a <= QRSPEC_VERSION_MAX; $a++) { |
|
218 | 218 | $frame = QRspec::newFrame($a); |
219 | 219 | if (QR_IMAGE) { |
220 | 220 | $fileName = QR_CACHE_DIR.'frame_'.$a.'.png'; |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | |
224 | 224 | $width = count($frame); |
225 | 225 | $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); |
226 | - for ($maskNo=0; $maskNo<8; $maskNo++) |
|
226 | + for ($maskNo = 0; $maskNo < 8; $maskNo++) |
|
227 | 227 | $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true); |
228 | 228 | } |
229 | 229 | |
@@ -248,8 +248,8 @@ discard block |
||
248 | 248 | public static function dumpMask($frame) |
249 | 249 | { |
250 | 250 | $width = count($frame); |
251 | - for($y=0;$y<$width;$y++) { |
|
252 | - for($x=0;$x<$width;$x++) { |
|
251 | + for ($y = 0; $y < $width; $y++) { |
|
252 | + for ($x = 0; $x < $width; $x++) { |
|
253 | 253 | echo ord($frame[$y][$x]).','; |
254 | 254 | } |
255 | 255 | } |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | public static function markTime($markerId) |
260 | 260 | { |
261 | 261 | list($usec, $sec) = explode(" ", microtime()); |
262 | - $time = ((float)$usec + (float)$sec); |
|
262 | + $time = ((float) $usec + (float) $sec); |
|
263 | 263 | |
264 | 264 | if (!isset($GLOBALS['qr_time_bench'])) |
265 | 265 | $GLOBALS['qr_time_bench'] = array(); |
@@ -280,9 +280,9 @@ discard block |
||
280 | 280 | <thead><tr style="border-bottom:1px solid silver"><td colspan="2" style="text-align:center">BENCHMARK</td></tr></thead> |
281 | 281 | <tbody>'; |
282 | 282 | |
283 | - foreach($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) { |
|
283 | + foreach ($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) { |
|
284 | 284 | if ($p > 0) { |
285 | - echo '<tr><th style="text-align:right">till '.$markerId.': </th><td>'.number_format($thisTime-$lastTime, 6).'s</td></tr>'; |
|
285 | + echo '<tr><th style="text-align:right">till '.$markerId.': </th><td>'.number_format($thisTime - $lastTime, 6).'s</td></tr>'; |
|
286 | 286 | } else { |
287 | 287 | $startTime = $thisTime; |
288 | 288 | } |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | } |
293 | 293 | |
294 | 294 | echo '</tbody><tfoot> |
295 | - <tr style="border-top:2px solid black"><th style="text-align:right">TOTAL: </th><td>'.number_format($lastTime-$startTime, 6).'s</td></tr> |
|
295 | + <tr style="border-top:2px solid black"><th style="text-align:right">TOTAL: </th><td>'.number_format($lastTime - $startTime, 6).'s</td></tr> |
|
296 | 296 | </tfoot> |
297 | 297 | </table>'; |
298 | 298 | } |
@@ -344,57 +344,57 @@ discard block |
||
344 | 344 | */ |
345 | 345 | |
346 | 346 | define('QRSPEC_VERSION_MAX', 40); |
347 | - define('QRSPEC_WIDTH_MAX', 177); |
|
347 | + define('QRSPEC_WIDTH_MAX', 177); |
|
348 | 348 | |
349 | - define('QRCAP_WIDTH', 0); |
|
350 | - define('QRCAP_WORDS', 1); |
|
351 | - define('QRCAP_REMINDER', 2); |
|
352 | - define('QRCAP_EC', 3); |
|
349 | + define('QRCAP_WIDTH', 0); |
|
350 | + define('QRCAP_WORDS', 1); |
|
351 | + define('QRCAP_REMINDER', 2); |
|
352 | + define('QRCAP_EC', 3); |
|
353 | 353 | |
354 | 354 | class QRspec { |
355 | 355 | |
356 | 356 | public static $capacity = array( |
357 | - array( 0, 0, 0, array( 0, 0, 0, 0)), |
|
358 | - array( 21, 26, 0, array( 7, 10, 13, 17)), // 1 |
|
359 | - array( 25, 44, 7, array( 10, 16, 22, 28)), |
|
360 | - array( 29, 70, 7, array( 15, 26, 36, 44)), |
|
361 | - array( 33, 100, 7, array( 20, 36, 52, 64)), |
|
362 | - array( 37, 134, 7, array( 26, 48, 72, 88)), // 5 |
|
363 | - array( 41, 172, 7, array( 36, 64, 96, 112)), |
|
364 | - array( 45, 196, 0, array( 40, 72, 108, 130)), |
|
365 | - array( 49, 242, 0, array( 48, 88, 132, 156)), |
|
366 | - array( 53, 292, 0, array( 60, 110, 160, 192)), |
|
367 | - array( 57, 346, 0, array( 72, 130, 192, 224)), //10 |
|
368 | - array( 61, 404, 0, array( 80, 150, 224, 264)), |
|
369 | - array( 65, 466, 0, array( 96, 176, 260, 308)), |
|
370 | - array( 69, 532, 0, array( 104, 198, 288, 352)), |
|
371 | - array( 73, 581, 3, array( 120, 216, 320, 384)), |
|
372 | - array( 77, 655, 3, array( 132, 240, 360, 432)), //15 |
|
373 | - array( 81, 733, 3, array( 144, 280, 408, 480)), |
|
374 | - array( 85, 815, 3, array( 168, 308, 448, 532)), |
|
375 | - array( 89, 901, 3, array( 180, 338, 504, 588)), |
|
376 | - array( 93, 991, 3, array( 196, 364, 546, 650)), |
|
377 | - array( 97, 1085, 3, array( 224, 416, 600, 700)), //20 |
|
378 | - array(101, 1156, 4, array( 224, 442, 644, 750)), |
|
379 | - array(105, 1258, 4, array( 252, 476, 690, 816)), |
|
380 | - array(109, 1364, 4, array( 270, 504, 750, 900)), |
|
381 | - array(113, 1474, 4, array( 300, 560, 810, 960)), |
|
382 | - array(117, 1588, 4, array( 312, 588, 870, 1050)), //25 |
|
383 | - array(121, 1706, 4, array( 336, 644, 952, 1110)), |
|
384 | - array(125, 1828, 4, array( 360, 700, 1020, 1200)), |
|
385 | - array(129, 1921, 3, array( 390, 728, 1050, 1260)), |
|
386 | - array(133, 2051, 3, array( 420, 784, 1140, 1350)), |
|
387 | - array(137, 2185, 3, array( 450, 812, 1200, 1440)), //30 |
|
388 | - array(141, 2323, 3, array( 480, 868, 1290, 1530)), |
|
389 | - array(145, 2465, 3, array( 510, 924, 1350, 1620)), |
|
390 | - array(149, 2611, 3, array( 540, 980, 1440, 1710)), |
|
391 | - array(153, 2761, 3, array( 570, 1036, 1530, 1800)), |
|
392 | - array(157, 2876, 0, array( 570, 1064, 1590, 1890)), //35 |
|
393 | - array(161, 3034, 0, array( 600, 1120, 1680, 1980)), |
|
394 | - array(165, 3196, 0, array( 630, 1204, 1770, 2100)), |
|
395 | - array(169, 3362, 0, array( 660, 1260, 1860, 2220)), |
|
396 | - array(173, 3532, 0, array( 720, 1316, 1950, 2310)), |
|
397 | - array(177, 3706, 0, array( 750, 1372, 2040, 2430)) //40 |
|
357 | + array(0, 0, 0, array(0, 0, 0, 0)), |
|
358 | + array(21, 26, 0, array(7, 10, 13, 17)), // 1 |
|
359 | + array(25, 44, 7, array(10, 16, 22, 28)), |
|
360 | + array(29, 70, 7, array(15, 26, 36, 44)), |
|
361 | + array(33, 100, 7, array(20, 36, 52, 64)), |
|
362 | + array(37, 134, 7, array(26, 48, 72, 88)), // 5 |
|
363 | + array(41, 172, 7, array(36, 64, 96, 112)), |
|
364 | + array(45, 196, 0, array(40, 72, 108, 130)), |
|
365 | + array(49, 242, 0, array(48, 88, 132, 156)), |
|
366 | + array(53, 292, 0, array(60, 110, 160, 192)), |
|
367 | + array(57, 346, 0, array(72, 130, 192, 224)), //10 |
|
368 | + array(61, 404, 0, array(80, 150, 224, 264)), |
|
369 | + array(65, 466, 0, array(96, 176, 260, 308)), |
|
370 | + array(69, 532, 0, array(104, 198, 288, 352)), |
|
371 | + array(73, 581, 3, array(120, 216, 320, 384)), |
|
372 | + array(77, 655, 3, array(132, 240, 360, 432)), //15 |
|
373 | + array(81, 733, 3, array(144, 280, 408, 480)), |
|
374 | + array(85, 815, 3, array(168, 308, 448, 532)), |
|
375 | + array(89, 901, 3, array(180, 338, 504, 588)), |
|
376 | + array(93, 991, 3, array(196, 364, 546, 650)), |
|
377 | + array(97, 1085, 3, array(224, 416, 600, 700)), //20 |
|
378 | + array(101, 1156, 4, array(224, 442, 644, 750)), |
|
379 | + array(105, 1258, 4, array(252, 476, 690, 816)), |
|
380 | + array(109, 1364, 4, array(270, 504, 750, 900)), |
|
381 | + array(113, 1474, 4, array(300, 560, 810, 960)), |
|
382 | + array(117, 1588, 4, array(312, 588, 870, 1050)), //25 |
|
383 | + array(121, 1706, 4, array(336, 644, 952, 1110)), |
|
384 | + array(125, 1828, 4, array(360, 700, 1020, 1200)), |
|
385 | + array(129, 1921, 3, array(390, 728, 1050, 1260)), |
|
386 | + array(133, 2051, 3, array(420, 784, 1140, 1350)), |
|
387 | + array(137, 2185, 3, array(450, 812, 1200, 1440)), //30 |
|
388 | + array(141, 2323, 3, array(480, 868, 1290, 1530)), |
|
389 | + array(145, 2465, 3, array(510, 924, 1350, 1620)), |
|
390 | + array(149, 2611, 3, array(540, 980, 1440, 1710)), |
|
391 | + array(153, 2761, 3, array(570, 1036, 1530, 1800)), |
|
392 | + array(157, 2876, 0, array(570, 1064, 1590, 1890)), //35 |
|
393 | + array(161, 3034, 0, array(600, 1120, 1680, 1980)), |
|
394 | + array(165, 3196, 0, array(630, 1204, 1770, 2100)), |
|
395 | + array(169, 3362, 0, array(660, 1260, 1860, 2220)), |
|
396 | + array(173, 3532, 0, array(720, 1316, 1950, 2310)), |
|
397 | + array(177, 3706, 0, array(750, 1372, 2040, 2430)) //40 |
|
398 | 398 | ); |
399 | 399 | |
400 | 400 | //---------------------------------------------------------------------- |
@@ -425,9 +425,9 @@ discard block |
||
425 | 425 | public static function getMinimumVersion($size, $level) |
426 | 426 | { |
427 | 427 | |
428 | - for($i=1; $i<= QRSPEC_VERSION_MAX; $i++) { |
|
429 | - $words = self::$capacity[$i][QRCAP_WORDS] - self::$capacity[$i][QRCAP_EC][$level]; |
|
430 | - if($words >= $size) |
|
428 | + for ($i = 1; $i <= QRSPEC_VERSION_MAX; $i++) { |
|
429 | + $words = self::$capacity[$i][QRCAP_WORDS] - self::$capacity[$i][QRCAP_EC][$level]; |
|
430 | + if ($words >= $size) |
|
431 | 431 | return $i; |
432 | 432 | } |
433 | 433 | |
@@ -438,9 +438,9 @@ discard block |
||
438 | 438 | |
439 | 439 | public static $lengthTableBits = array( |
440 | 440 | array(10, 12, 14), |
441 | - array( 9, 11, 13), |
|
442 | - array( 8, 16, 16), |
|
443 | - array( 8, 10, 12) |
|
441 | + array(9, 11, 13), |
|
442 | + array(8, 16, 16), |
|
443 | + array(8, 10, 12) |
|
444 | 444 | ); |
445 | 445 | |
446 | 446 | //---------------------------------------------------------------------- |
@@ -463,12 +463,12 @@ discard block |
||
463 | 463 | //---------------------------------------------------------------------- |
464 | 464 | public static function maximumWords($mode, $version) |
465 | 465 | { |
466 | - if($mode == QR_MODE_STRUCTURE) |
|
466 | + if ($mode == QR_MODE_STRUCTURE) |
|
467 | 467 | return 3; |
468 | 468 | |
469 | - if($version <= 9) { |
|
469 | + if ($version <= 9) { |
|
470 | 470 | $l = 0; |
471 | - } else if($version <= 26) { |
|
471 | + } else if ($version <= 26) { |
|
472 | 472 | $l = 1; |
473 | 473 | } else { |
474 | 474 | $l = 2; |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | $bits = self::$lengthTableBits[$mode][$l]; |
478 | 478 | $words = (1 << $bits) - 1; |
479 | 479 | |
480 | - if($mode == QR_MODE_KANJI) { |
|
480 | + if ($mode == QR_MODE_KANJI) { |
|
481 | 481 | $words *= 2; // the number of bytes is required |
482 | 482 | } |
483 | 483 | |
@@ -489,47 +489,47 @@ discard block |
||
489 | 489 | // See Table 12-16 (pp.30-36), JIS X0510:2004. |
490 | 490 | |
491 | 491 | public static $eccTable = array( |
492 | - array(array( 0, 0), array( 0, 0), array( 0, 0), array( 0, 0)), |
|
493 | - array(array( 1, 0), array( 1, 0), array( 1, 0), array( 1, 0)), // 1 |
|
494 | - array(array( 1, 0), array( 1, 0), array( 1, 0), array( 1, 0)), |
|
495 | - array(array( 1, 0), array( 1, 0), array( 2, 0), array( 2, 0)), |
|
496 | - array(array( 1, 0), array( 2, 0), array( 2, 0), array( 4, 0)), |
|
497 | - array(array( 1, 0), array( 2, 0), array( 2, 2), array( 2, 2)), // 5 |
|
498 | - array(array( 2, 0), array( 4, 0), array( 4, 0), array( 4, 0)), |
|
499 | - array(array( 2, 0), array( 4, 0), array( 2, 4), array( 4, 1)), |
|
500 | - array(array( 2, 0), array( 2, 2), array( 4, 2), array( 4, 2)), |
|
501 | - array(array( 2, 0), array( 3, 2), array( 4, 4), array( 4, 4)), |
|
502 | - array(array( 2, 2), array( 4, 1), array( 6, 2), array( 6, 2)), //10 |
|
503 | - array(array( 4, 0), array( 1, 4), array( 4, 4), array( 3, 8)), |
|
504 | - array(array( 2, 2), array( 6, 2), array( 4, 6), array( 7, 4)), |
|
505 | - array(array( 4, 0), array( 8, 1), array( 8, 4), array(12, 4)), |
|
506 | - array(array( 3, 1), array( 4, 5), array(11, 5), array(11, 5)), |
|
507 | - array(array( 5, 1), array( 5, 5), array( 5, 7), array(11, 7)), //15 |
|
508 | - array(array( 5, 1), array( 7, 3), array(15, 2), array( 3, 13)), |
|
509 | - array(array( 1, 5), array(10, 1), array( 1, 15), array( 2, 17)), |
|
510 | - array(array( 5, 1), array( 9, 4), array(17, 1), array( 2, 19)), |
|
511 | - array(array( 3, 4), array( 3, 11), array(17, 4), array( 9, 16)), |
|
512 | - array(array( 3, 5), array( 3, 13), array(15, 5), array(15, 10)), //20 |
|
513 | - array(array( 4, 4), array(17, 0), array(17, 6), array(19, 6)), |
|
514 | - array(array( 2, 7), array(17, 0), array( 7, 16), array(34, 0)), |
|
515 | - array(array( 4, 5), array( 4, 14), array(11, 14), array(16, 14)), |
|
516 | - array(array( 6, 4), array( 6, 14), array(11, 16), array(30, 2)), |
|
517 | - array(array( 8, 4), array( 8, 13), array( 7, 22), array(22, 13)), //25 |
|
518 | - array(array(10, 2), array(19, 4), array(28, 6), array(33, 4)), |
|
519 | - array(array( 8, 4), array(22, 3), array( 8, 26), array(12, 28)), |
|
520 | - array(array( 3, 10), array( 3, 23), array( 4, 31), array(11, 31)), |
|
521 | - array(array( 7, 7), array(21, 7), array( 1, 37), array(19, 26)), |
|
522 | - array(array( 5, 10), array(19, 10), array(15, 25), array(23, 25)), //30 |
|
523 | - array(array(13, 3), array( 2, 29), array(42, 1), array(23, 28)), |
|
524 | - array(array(17, 0), array(10, 23), array(10, 35), array(19, 35)), |
|
525 | - array(array(17, 1), array(14, 21), array(29, 19), array(11, 46)), |
|
526 | - array(array(13, 6), array(14, 23), array(44, 7), array(59, 1)), |
|
527 | - array(array(12, 7), array(12, 26), array(39, 14), array(22, 41)), //35 |
|
528 | - array(array( 6, 14), array( 6, 34), array(46, 10), array( 2, 64)), |
|
529 | - array(array(17, 4), array(29, 14), array(49, 10), array(24, 46)), |
|
530 | - array(array( 4, 18), array(13, 32), array(48, 14), array(42, 32)), |
|
531 | - array(array(20, 4), array(40, 7), array(43, 22), array(10, 67)), |
|
532 | - array(array(19, 6), array(18, 31), array(34, 34), array(20, 61)),//40 |
|
492 | + array(array(0, 0), array(0, 0), array(0, 0), array(0, 0)), |
|
493 | + array(array(1, 0), array(1, 0), array(1, 0), array(1, 0)), // 1 |
|
494 | + array(array(1, 0), array(1, 0), array(1, 0), array(1, 0)), |
|
495 | + array(array(1, 0), array(1, 0), array(2, 0), array(2, 0)), |
|
496 | + array(array(1, 0), array(2, 0), array(2, 0), array(4, 0)), |
|
497 | + array(array(1, 0), array(2, 0), array(2, 2), array(2, 2)), // 5 |
|
498 | + array(array(2, 0), array(4, 0), array(4, 0), array(4, 0)), |
|
499 | + array(array(2, 0), array(4, 0), array(2, 4), array(4, 1)), |
|
500 | + array(array(2, 0), array(2, 2), array(4, 2), array(4, 2)), |
|
501 | + array(array(2, 0), array(3, 2), array(4, 4), array(4, 4)), |
|
502 | + array(array(2, 2), array(4, 1), array(6, 2), array(6, 2)), //10 |
|
503 | + array(array(4, 0), array(1, 4), array(4, 4), array(3, 8)), |
|
504 | + array(array(2, 2), array(6, 2), array(4, 6), array(7, 4)), |
|
505 | + array(array(4, 0), array(8, 1), array(8, 4), array(12, 4)), |
|
506 | + array(array(3, 1), array(4, 5), array(11, 5), array(11, 5)), |
|
507 | + array(array(5, 1), array(5, 5), array(5, 7), array(11, 7)), //15 |
|
508 | + array(array(5, 1), array(7, 3), array(15, 2), array(3, 13)), |
|
509 | + array(array(1, 5), array(10, 1), array(1, 15), array(2, 17)), |
|
510 | + array(array(5, 1), array(9, 4), array(17, 1), array(2, 19)), |
|
511 | + array(array(3, 4), array(3, 11), array(17, 4), array(9, 16)), |
|
512 | + array(array(3, 5), array(3, 13), array(15, 5), array(15, 10)), //20 |
|
513 | + array(array(4, 4), array(17, 0), array(17, 6), array(19, 6)), |
|
514 | + array(array(2, 7), array(17, 0), array(7, 16), array(34, 0)), |
|
515 | + array(array(4, 5), array(4, 14), array(11, 14), array(16, 14)), |
|
516 | + array(array(6, 4), array(6, 14), array(11, 16), array(30, 2)), |
|
517 | + array(array(8, 4), array(8, 13), array(7, 22), array(22, 13)), //25 |
|
518 | + array(array(10, 2), array(19, 4), array(28, 6), array(33, 4)), |
|
519 | + array(array(8, 4), array(22, 3), array(8, 26), array(12, 28)), |
|
520 | + array(array(3, 10), array(3, 23), array(4, 31), array(11, 31)), |
|
521 | + array(array(7, 7), array(21, 7), array(1, 37), array(19, 26)), |
|
522 | + array(array(5, 10), array(19, 10), array(15, 25), array(23, 25)), //30 |
|
523 | + array(array(13, 3), array(2, 29), array(42, 1), array(23, 28)), |
|
524 | + array(array(17, 0), array(10, 23), array(10, 35), array(19, 35)), |
|
525 | + array(array(17, 1), array(14, 21), array(29, 19), array(11, 46)), |
|
526 | + array(array(13, 6), array(14, 23), array(44, 7), array(59, 1)), |
|
527 | + array(array(12, 7), array(12, 26), array(39, 14), array(22, 41)), //35 |
|
528 | + array(array(6, 14), array(6, 34), array(46, 10), array(2, 64)), |
|
529 | + array(array(17, 4), array(29, 14), array(49, 10), array(24, 46)), |
|
530 | + array(array(4, 18), array(13, 32), array(48, 14), array(42, 32)), |
|
531 | + array(array(20, 4), array(40, 7), array(43, 22), array(10, 67)), |
|
532 | + array(array(19, 6), array(18, 31), array(34, 34), array(20, 61)), //40 |
|
533 | 533 | ); |
534 | 534 | |
535 | 535 | //---------------------------------------------------------------------- |
@@ -538,7 +538,7 @@ discard block |
||
538 | 538 | public static function getEccSpec($version, $level, array &$spec) |
539 | 539 | { |
540 | 540 | if (count($spec) < 5) { |
541 | - $spec = array(0,0,0,0,0); |
|
541 | + $spec = array(0, 0, 0, 0, 0); |
|
542 | 542 | } |
543 | 543 | |
544 | 544 | $b1 = self::$eccTable[$version][$level][0]; |
@@ -546,16 +546,16 @@ discard block |
||
546 | 546 | $data = self::getDataLength($version, $level); |
547 | 547 | $ecc = self::getECCLength($version, $level); |
548 | 548 | |
549 | - if($b2 == 0) { |
|
549 | + if ($b2 == 0) { |
|
550 | 550 | $spec[0] = $b1; |
551 | - $spec[1] = (int)($data / $b1); |
|
552 | - $spec[2] = (int)($ecc / $b1); |
|
551 | + $spec[1] = (int) ($data / $b1); |
|
552 | + $spec[2] = (int) ($ecc / $b1); |
|
553 | 553 | $spec[3] = 0; |
554 | 554 | $spec[4] = 0; |
555 | 555 | } else { |
556 | 556 | $spec[0] = $b1; |
557 | - $spec[1] = (int)($data / ($b1 + $b2)); |
|
558 | - $spec[2] = (int)($ecc / ($b1 + $b2)); |
|
557 | + $spec[1] = (int) ($data / ($b1 + $b2)); |
|
558 | + $spec[2] = (int) ($ecc / ($b1 + $b2)); |
|
559 | 559 | $spec[3] = $b2; |
560 | 560 | $spec[4] = $spec[1] + 1; |
561 | 561 | } |
@@ -571,9 +571,9 @@ discard block |
||
571 | 571 | // See Table 1 in Appendix E (pp.71) of JIS X0510:2004. |
572 | 572 | |
573 | 573 | public static $alignmentPattern = array( |
574 | - array( 0, 0), |
|
575 | - array( 0, 0), array(18, 0), array(22, 0), array(26, 0), array(30, 0), // 1- 5 |
|
576 | - array(34, 0), array(22, 38), array(24, 42), array(26, 46), array(28, 50), // 6-10 |
|
574 | + array(0, 0), |
|
575 | + array(0, 0), array(18, 0), array(22, 0), array(26, 0), array(30, 0), // 1- 5 |
|
576 | + array(34, 0), array(22, 38), array(24, 42), array(26, 46), array(28, 50), // 6-10 |
|
577 | 577 | array(30, 54), array(32, 58), array(34, 62), array(26, 46), array(26, 48), //11-15 |
578 | 578 | array(26, 50), array(30, 54), array(30, 56), array(30, 58), array(34, 62), //16-20 |
579 | 579 | array(28, 50), array(26, 50), array(30, 54), array(28, 54), array(32, 58), //21-25 |
@@ -599,28 +599,28 @@ discard block |
||
599 | 599 | "\xa1\xa1\xa1\xa1\xa1" |
600 | 600 | ); |
601 | 601 | |
602 | - $yStart = $oy-2; |
|
603 | - $xStart = $ox-2; |
|
602 | + $yStart = $oy - 2; |
|
603 | + $xStart = $ox - 2; |
|
604 | 604 | |
605 | - for($y=0; $y<5; $y++) { |
|
606 | - QRstr::set($frame, $xStart, $yStart+$y, $finder[$y]); |
|
605 | + for ($y = 0; $y < 5; $y++) { |
|
606 | + QRstr::set($frame, $xStart, $yStart + $y, $finder[$y]); |
|
607 | 607 | } |
608 | 608 | } |
609 | 609 | |
610 | 610 | //---------------------------------------------------------------------- |
611 | 611 | public static function putAlignmentPattern($version, &$frame, $width) |
612 | 612 | { |
613 | - if($version < 2) |
|
613 | + if ($version < 2) |
|
614 | 614 | return; |
615 | 615 | |
616 | 616 | $d = self::$alignmentPattern[$version][1] - self::$alignmentPattern[$version][0]; |
617 | - if($d < 0) { |
|
617 | + if ($d < 0) { |
|
618 | 618 | $w = 2; |
619 | 619 | } else { |
620 | - $w = (int)(($width - self::$alignmentPattern[$version][0]) / $d + 2); |
|
620 | + $w = (int) (($width - self::$alignmentPattern[$version][0]) / $d + 2); |
|
621 | 621 | } |
622 | 622 | |
623 | - if($w * $w - 3 == 1) { |
|
623 | + if ($w * $w - 3 == 1) { |
|
624 | 624 | $x = self::$alignmentPattern[$version][0]; |
625 | 625 | $y = self::$alignmentPattern[$version][0]; |
626 | 626 | self::putAlignmentMarker($frame, $x, $y); |
@@ -628,16 +628,16 @@ discard block |
||
628 | 628 | } |
629 | 629 | |
630 | 630 | $cx = self::$alignmentPattern[$version][0]; |
631 | - for($x=1; $x<$w - 1; $x++) { |
|
631 | + for ($x = 1; $x < $w - 1; $x++) { |
|
632 | 632 | self::putAlignmentMarker($frame, 6, $cx); |
633 | - self::putAlignmentMarker($frame, $cx, 6); |
|
633 | + self::putAlignmentMarker($frame, $cx, 6); |
|
634 | 634 | $cx += $d; |
635 | 635 | } |
636 | 636 | |
637 | 637 | $cy = self::$alignmentPattern[$version][0]; |
638 | - for($y=0; $y<$w-1; $y++) { |
|
638 | + for ($y = 0; $y < $w - 1; $y++) { |
|
639 | 639 | $cx = self::$alignmentPattern[$version][0]; |
640 | - for($x=0; $x<$w-1; $x++) { |
|
640 | + for ($x = 0; $x < $w - 1; $x++) { |
|
641 | 641 | self::putAlignmentMarker($frame, $cx, $cy); |
642 | 642 | $cx += $d; |
643 | 643 | } |
@@ -663,10 +663,10 @@ discard block |
||
663 | 663 | //---------------------------------------------------------------------- |
664 | 664 | public static function getVersionPattern($version) |
665 | 665 | { |
666 | - if($version < 7 || $version > QRSPEC_VERSION_MAX) |
|
666 | + if ($version < 7 || $version > QRSPEC_VERSION_MAX) |
|
667 | 667 | return 0; |
668 | 668 | |
669 | - return self::$versionPattern[$version -7]; |
|
669 | + return self::$versionPattern[$version - 7]; |
|
670 | 670 | } |
671 | 671 | |
672 | 672 | // Format information -------------------------------------------------- |
@@ -681,10 +681,10 @@ discard block |
||
681 | 681 | |
682 | 682 | public static function getFormatInfo($mask, $level) |
683 | 683 | { |
684 | - if($mask < 0 || $mask > 7) |
|
684 | + if ($mask < 0 || $mask > 7) |
|
685 | 685 | return 0; |
686 | 686 | |
687 | - if($level < 0 || $level > 3) |
|
687 | + if ($level < 0 || $level > 3) |
|
688 | 688 | return 0; |
689 | 689 | |
690 | 690 | return self::$formatInfo[$level][$mask]; |
@@ -713,8 +713,8 @@ discard block |
||
713 | 713 | "\xc1\xc1\xc1\xc1\xc1\xc1\xc1" |
714 | 714 | ); |
715 | 715 | |
716 | - for($y=0; $y<7; $y++) { |
|
717 | - QRstr::set($frame, $ox, $oy+$y, $finder[$y]); |
|
716 | + for ($y = 0; $y < 7; $y++) { |
|
717 | + QRstr::set($frame, $ox, $oy + $y, $finder[$y]); |
|
718 | 718 | } |
719 | 719 | } |
720 | 720 | |
@@ -722,7 +722,7 @@ discard block |
||
722 | 722 | public static function createFrame($version) |
723 | 723 | { |
724 | 724 | $width = self::$capacity[$version][QRCAP_WIDTH]; |
725 | - $frameLine = str_repeat ("\0", $width); |
|
725 | + $frameLine = str_repeat("\0", $width); |
|
726 | 726 | $frame = array_fill(0, $width, $frameLine); |
727 | 727 | |
728 | 728 | // Finder pattern |
@@ -733,7 +733,7 @@ discard block |
||
733 | 733 | // Separator |
734 | 734 | $yOffset = $width - 7; |
735 | 735 | |
736 | - for($y=0; $y<7; $y++) { |
|
736 | + for ($y = 0; $y < 7; $y++) { |
|
737 | 737 | $frame[$y][7] = "\xc0"; |
738 | 738 | $frame[$y][$width - 8] = "\xc0"; |
739 | 739 | $frame[$yOffset][7] = "\xc0"; |
@@ -743,7 +743,7 @@ discard block |
||
743 | 743 | $setPattern = str_repeat("\xc0", 8); |
744 | 744 | |
745 | 745 | QRstr::set($frame, 0, 7, $setPattern); |
746 | - QRstr::set($frame, $width-8, 7, $setPattern); |
|
746 | + QRstr::set($frame, $width - 8, 7, $setPattern); |
|
747 | 747 | QRstr::set($frame, 0, $width - 8, $setPattern); |
748 | 748 | |
749 | 749 | // Format info |
@@ -753,38 +753,38 @@ discard block |
||
753 | 753 | |
754 | 754 | $yOffset = $width - 8; |
755 | 755 | |
756 | - for($y=0; $y<8; $y++,$yOffset++) { |
|
756 | + for ($y = 0; $y < 8; $y++, $yOffset++) { |
|
757 | 757 | $frame[$y][8] = "\x84"; |
758 | 758 | $frame[$yOffset][8] = "\x84"; |
759 | 759 | } |
760 | 760 | |
761 | 761 | // Timing pattern |
762 | 762 | |
763 | - for($i=1; $i<$width-15; $i++) { |
|
764 | - $frame[6][7+$i] = chr(0x90 | ($i & 1)); |
|
765 | - $frame[7+$i][6] = chr(0x90 | ($i & 1)); |
|
763 | + for ($i = 1; $i < $width - 15; $i++) { |
|
764 | + $frame[6][7 + $i] = chr(0x90 | ($i & 1)); |
|
765 | + $frame[7 + $i][6] = chr(0x90 | ($i & 1)); |
|
766 | 766 | } |
767 | 767 | |
768 | 768 | // Alignment pattern |
769 | 769 | self::putAlignmentPattern($version, $frame, $width); |
770 | 770 | |
771 | 771 | // Version information |
772 | - if($version >= 7) { |
|
772 | + if ($version >= 7) { |
|
773 | 773 | $vinf = self::getVersionPattern($version); |
774 | 774 | |
775 | 775 | $v = $vinf; |
776 | 776 | |
777 | - for($x=0; $x<6; $x++) { |
|
778 | - for($y=0; $y<3; $y++) { |
|
779 | - $frame[($width - 11)+$y][$x] = chr(0x88 | ($v & 1)); |
|
777 | + for ($x = 0; $x < 6; $x++) { |
|
778 | + for ($y = 0; $y < 3; $y++) { |
|
779 | + $frame[($width - 11) + $y][$x] = chr(0x88 | ($v & 1)); |
|
780 | 780 | $v = $v >> 1; |
781 | 781 | } |
782 | 782 | } |
783 | 783 | |
784 | 784 | $v = $vinf; |
785 | - for($y=0; $y<6; $y++) { |
|
786 | - for($x=0; $x<3; $x++) { |
|
787 | - $frame[$y][$x+($width - 11)] = chr(0x88 | ($v & 1)); |
|
785 | + for ($y = 0; $y < 6; $y++) { |
|
786 | + for ($x = 0; $x < 3; $x++) { |
|
787 | + $frame[$y][$x + ($width - 11)] = chr(0x88 | ($v & 1)); |
|
788 | 788 | $v = $v >> 1; |
789 | 789 | } |
790 | 790 | } |
@@ -818,16 +818,16 @@ discard block |
||
818 | 818 | } else { |
819 | 819 | |
820 | 820 | foreach ($frame as &$frameLine) { |
821 | - $frameLine = join('<span class="m"> </span>', explode("\xc0", $frameLine)); |
|
821 | + $frameLine = join('<span class="m"> </span>', explode("\xc0", $frameLine)); |
|
822 | 822 | $frameLine = join('<span class="m">▒</span>', explode("\xc1", $frameLine)); |
823 | - $frameLine = join('<span class="p"> </span>', explode("\xa0", $frameLine)); |
|
823 | + $frameLine = join('<span class="p"> </span>', explode("\xa0", $frameLine)); |
|
824 | 824 | $frameLine = join('<span class="p">▒</span>', explode("\xa1", $frameLine)); |
825 | 825 | $frameLine = join('<span class="s">◇</span>', explode("\x84", $frameLine)); //format 0 |
826 | 826 | $frameLine = join('<span class="s">◆</span>', explode("\x85", $frameLine)); //format 1 |
827 | 827 | $frameLine = join('<span class="x">☢</span>', explode("\x81", $frameLine)); //special bit |
828 | - $frameLine = join('<span class="c"> </span>', explode("\x90", $frameLine)); //clock 0 |
|
828 | + $frameLine = join('<span class="c"> </span>', explode("\x90", $frameLine)); //clock 0 |
|
829 | 829 | $frameLine = join('<span class="c">◷</span>', explode("\x91", $frameLine)); //clock 1 |
830 | - $frameLine = join('<span class="f"> </span>', explode("\x88", $frameLine)); //version |
|
830 | + $frameLine = join('<span class="f"> </span>', explode("\x88", $frameLine)); //version |
|
831 | 831 | $frameLine = join('<span class="f">▒</span>', explode("\x89", $frameLine)); //version |
832 | 832 | $frameLine = join('♦', explode("\x01", $frameLine)); |
833 | 833 | $frameLine = join('⋅', explode("\0", $frameLine)); |
@@ -865,10 +865,10 @@ discard block |
||
865 | 865 | //---------------------------------------------------------------------- |
866 | 866 | public static function newFrame($version) |
867 | 867 | { |
868 | - if($version < 1 || $version > QRSPEC_VERSION_MAX) |
|
868 | + if ($version < 1 || $version > QRSPEC_VERSION_MAX) |
|
869 | 869 | return null; |
870 | 870 | |
871 | - if(!isset(self::$frames[$version])) { |
|
871 | + if (!isset(self::$frames[$version])) { |
|
872 | 872 | |
873 | 873 | $fileName = QR_CACHE_DIR.'frame_'.$version.'.dat'; |
874 | 874 | |
@@ -884,22 +884,22 @@ discard block |
||
884 | 884 | } |
885 | 885 | } |
886 | 886 | |
887 | - if(is_null(self::$frames[$version])) |
|
887 | + if (is_null(self::$frames[$version])) |
|
888 | 888 | return null; |
889 | 889 | |
890 | 890 | return self::$frames[$version]; |
891 | 891 | } |
892 | 892 | |
893 | 893 | //---------------------------------------------------------------------- |
894 | - public static function rsBlockNum($spec) { return $spec[0] + $spec[3]; } |
|
895 | - public static function rsBlockNum1($spec) { return $spec[0]; } |
|
896 | - public static function rsDataCodes1($spec) { return $spec[1]; } |
|
897 | - public static function rsEccCodes1($spec) { return $spec[2]; } |
|
898 | - public static function rsBlockNum2($spec) { return $spec[3]; } |
|
899 | - public static function rsDataCodes2($spec) { return $spec[4]; } |
|
900 | - public static function rsEccCodes2($spec) { return $spec[2]; } |
|
901 | - public static function rsDataLength($spec) { return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]); } |
|
902 | - public static function rsEccLength($spec) { return ($spec[0] + $spec[3]) * $spec[2]; } |
|
894 | + public static function rsBlockNum($spec) { return $spec[0] + $spec[3]; } |
|
895 | + public static function rsBlockNum1($spec) { return $spec[0]; } |
|
896 | + public static function rsDataCodes1($spec) { return $spec[1]; } |
|
897 | + public static function rsEccCodes1($spec) { return $spec[2]; } |
|
898 | + public static function rsBlockNum2($spec) { return $spec[3]; } |
|
899 | + public static function rsDataCodes2($spec) { return $spec[4]; } |
|
900 | + public static function rsEccCodes2($spec) { return $spec[2]; } |
|
901 | + public static function rsDataLength($spec) { return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]); } |
|
902 | + public static function rsEccLength($spec) { return ($spec[0] + $spec[3]) * $spec[2]; } |
|
903 | 903 | |
904 | 904 | } |
905 | 905 | |
@@ -938,7 +938,7 @@ discard block |
||
938 | 938 | class QRimage { |
939 | 939 | |
940 | 940 | //---------------------------------------------------------------------- |
941 | - public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=false) |
|
941 | + public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4, $saveandprint = false) |
|
942 | 942 | { |
943 | 943 | $image = self::image($frame, $pixelPerPoint, $outerFrame); |
944 | 944 | |
@@ -946,11 +946,11 @@ discard block |
||
946 | 946 | Header("Content-type: image/png"); |
947 | 947 | ImagePng($image); |
948 | 948 | } else { |
949 | - if($saveandprint===true){ |
|
949 | + if ($saveandprint === true) { |
|
950 | 950 | ImagePng($image, $filename); |
951 | 951 | header("Content-type: image/png"); |
952 | 952 | ImagePng($image); |
953 | - }else{ |
|
953 | + } else { |
|
954 | 954 | ImagePng($image, $filename); |
955 | 955 | } |
956 | 956 | } |
@@ -979,25 +979,25 @@ discard block |
||
979 | 979 | $h = count($frame); |
980 | 980 | $w = strlen($frame[0]); |
981 | 981 | |
982 | - $imgW = $w + 2*$outerFrame; |
|
983 | - $imgH = $h + 2*$outerFrame; |
|
982 | + $imgW = $w + 2 * $outerFrame; |
|
983 | + $imgH = $h + 2 * $outerFrame; |
|
984 | 984 | |
985 | - $base_image =ImageCreate($imgW, $imgH); |
|
985 | + $base_image = ImageCreate($imgW, $imgH); |
|
986 | 986 | |
987 | - $col[0] = ImageColorAllocate($base_image,255,255,255); |
|
988 | - $col[1] = ImageColorAllocate($base_image,0,0,0); |
|
987 | + $col[0] = ImageColorAllocate($base_image, 255, 255, 255); |
|
988 | + $col[1] = ImageColorAllocate($base_image, 0, 0, 0); |
|
989 | 989 | |
990 | 990 | imagefill($base_image, 0, 0, $col[0]); |
991 | 991 | |
992 | - for($y=0; $y<$h; $y++) { |
|
993 | - for($x=0; $x<$w; $x++) { |
|
992 | + for ($y = 0; $y < $h; $y++) { |
|
993 | + for ($x = 0; $x < $w; $x++) { |
|
994 | 994 | if ($frame[$y][$x] == '1') { |
995 | - ImageSetPixel($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]); |
|
995 | + ImageSetPixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]); |
|
996 | 996 | } |
997 | 997 | } |
998 | 998 | } |
999 | 999 | |
1000 | - $target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint); |
|
1000 | + $target_image = ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint); |
|
1001 | 1001 | ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH); |
1002 | 1002 | ImageDestroy($base_image); |
1003 | 1003 | |
@@ -1038,7 +1038,7 @@ discard block |
||
1038 | 1038 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
1039 | 1039 | */ |
1040 | 1040 | |
1041 | - define('STRUCTURE_HEADER_BITS', 20); |
|
1041 | + define('STRUCTURE_HEADER_BITS', 20); |
|
1042 | 1042 | define('MAX_STRUCTURED_SYMBOLS', 16); |
1043 | 1043 | |
1044 | 1044 | class QRinputItem { |
@@ -1053,11 +1053,11 @@ discard block |
||
1053 | 1053 | $setData = array_slice($data, 0, $size); |
1054 | 1054 | |
1055 | 1055 | if (count($setData) < $size) { |
1056 | - $setData = array_merge($setData, array_fill(0,$size-count($setData),0)); |
|
1056 | + $setData = array_merge($setData, array_fill(0, $size - count($setData), 0)); |
|
1057 | 1057 | } |
1058 | 1058 | |
1059 | - if(!QRinput::check($mode, $size, $setData)) { |
|
1060 | - throw new Exception('Error m:'.$mode.',s:'.$size.',d:'.join(',',$setData)); |
|
1059 | + if (!QRinput::check($mode, $size, $setData)) { |
|
1060 | + throw new Exception('Error m:'.$mode.',s:'.$size.',d:'.join(',', $setData)); |
|
1061 | 1061 | return null; |
1062 | 1062 | } |
1063 | 1063 | |
@@ -1072,26 +1072,26 @@ discard block |
||
1072 | 1072 | { |
1073 | 1073 | try { |
1074 | 1074 | |
1075 | - $words = (int)($this->size / 3); |
|
1075 | + $words = (int) ($this->size / 3); |
|
1076 | 1076 | $bs = new QRbitstream(); |
1077 | 1077 | |
1078 | 1078 | $val = 0x1; |
1079 | 1079 | $bs->appendNum(4, $val); |
1080 | 1080 | $bs->appendNum(QRspec::lengthIndicator(QR_MODE_NUM, $version), $this->size); |
1081 | 1081 | |
1082 | - for($i=0; $i<$words; $i++) { |
|
1083 | - $val = (ord($this->data[$i*3 ]) - ord('0')) * 100; |
|
1084 | - $val += (ord($this->data[$i*3+1]) - ord('0')) * 10; |
|
1085 | - $val += (ord($this->data[$i*3+2]) - ord('0')); |
|
1082 | + for ($i = 0; $i < $words; $i++) { |
|
1083 | + $val = (ord($this->data[$i * 3]) - ord('0')) * 100; |
|
1084 | + $val += (ord($this->data[$i * 3 + 1]) - ord('0')) * 10; |
|
1085 | + $val += (ord($this->data[$i * 3 + 2]) - ord('0')); |
|
1086 | 1086 | $bs->appendNum(10, $val); |
1087 | 1087 | } |
1088 | 1088 | |
1089 | - if($this->size - $words * 3 == 1) { |
|
1090 | - $val = ord($this->data[$words*3]) - ord('0'); |
|
1089 | + if ($this->size - $words * 3 == 1) { |
|
1090 | + $val = ord($this->data[$words * 3]) - ord('0'); |
|
1091 | 1091 | $bs->appendNum(4, $val); |
1092 | - } else if($this->size - $words * 3 == 2) { |
|
1093 | - $val = (ord($this->data[$words*3 ]) - ord('0')) * 10; |
|
1094 | - $val += (ord($this->data[$words*3+1]) - ord('0')); |
|
1092 | + } else if ($this->size - $words * 3 == 2) { |
|
1093 | + $val = (ord($this->data[$words * 3]) - ord('0')) * 10; |
|
1094 | + $val += (ord($this->data[$words * 3 + 1]) - ord('0')); |
|
1095 | 1095 | $bs->appendNum(7, $val); |
1096 | 1096 | } |
1097 | 1097 | |
@@ -1107,20 +1107,20 @@ discard block |
||
1107 | 1107 | public function encodeModeAn($version) |
1108 | 1108 | { |
1109 | 1109 | try { |
1110 | - $words = (int)($this->size / 2); |
|
1110 | + $words = (int) ($this->size / 2); |
|
1111 | 1111 | $bs = new QRbitstream(); |
1112 | 1112 | |
1113 | 1113 | $bs->appendNum(4, 0x02); |
1114 | 1114 | $bs->appendNum(QRspec::lengthIndicator(QR_MODE_AN, $version), $this->size); |
1115 | 1115 | |
1116 | - for($i=0; $i<$words; $i++) { |
|
1117 | - $val = (int)QRinput::lookAnTable(ord($this->data[$i*2 ])) * 45; |
|
1118 | - $val += (int)QRinput::lookAnTable(ord($this->data[$i*2+1])); |
|
1116 | + for ($i = 0; $i < $words; $i++) { |
|
1117 | + $val = (int) QRinput::lookAnTable(ord($this->data[$i * 2])) * 45; |
|
1118 | + $val += (int) QRinput::lookAnTable(ord($this->data[$i * 2 + 1])); |
|
1119 | 1119 | |
1120 | 1120 | $bs->appendNum(11, $val); |
1121 | 1121 | } |
1122 | 1122 | |
1123 | - if($this->size & 1) { |
|
1123 | + if ($this->size & 1) { |
|
1124 | 1124 | $val = QRinput::lookAnTable(ord($this->data[$words * 2])); |
1125 | 1125 | $bs->appendNum(6, $val); |
1126 | 1126 | } |
@@ -1142,7 +1142,7 @@ discard block |
||
1142 | 1142 | $bs->appendNum(4, 0x4); |
1143 | 1143 | $bs->appendNum(QRspec::lengthIndicator(QR_MODE_8, $version), $this->size); |
1144 | 1144 | |
1145 | - for($i=0; $i<$this->size; $i++) { |
|
1145 | + for ($i = 0; $i < $this->size; $i++) { |
|
1146 | 1146 | $bs->appendNum(8, ord($this->data[$i])); |
1147 | 1147 | } |
1148 | 1148 | |
@@ -1162,11 +1162,11 @@ discard block |
||
1162 | 1162 | $bs = new QRbitrtream(); |
1163 | 1163 | |
1164 | 1164 | $bs->appendNum(4, 0x8); |
1165 | - $bs->appendNum(QRspec::lengthIndicator(QR_MODE_KANJI, $version), (int)($this->size / 2)); |
|
1165 | + $bs->appendNum(QRspec::lengthIndicator(QR_MODE_KANJI, $version), (int) ($this->size / 2)); |
|
1166 | 1166 | |
1167 | - for($i=0; $i<$this->size; $i+=2) { |
|
1168 | - $val = (ord($this->data[$i]) << 8) | ord($this->data[$i+1]); |
|
1169 | - if($val <= 0x9ffc) { |
|
1167 | + for ($i = 0; $i < $this->size; $i += 2) { |
|
1168 | + $val = (ord($this->data[$i]) << 8) | ord($this->data[$i + 1]); |
|
1169 | + if ($val <= 0x9ffc) { |
|
1170 | 1170 | $val -= 0x8140; |
1171 | 1171 | } else { |
1172 | 1172 | $val -= 0xc140; |
@@ -1190,7 +1190,7 @@ discard block |
||
1190 | 1190 | public function encodeModeStructure() |
1191 | 1191 | { |
1192 | 1192 | try { |
1193 | - $bs = new QRbitstream(); |
|
1193 | + $bs = new QRbitstream(); |
|
1194 | 1194 | |
1195 | 1195 | $bs->appendNum(4, 0x03); |
1196 | 1196 | $bs->appendNum(4, ord($this->data[1]) - 1); |
@@ -1210,14 +1210,14 @@ discard block |
||
1210 | 1210 | { |
1211 | 1211 | $bits = 0; |
1212 | 1212 | |
1213 | - if($version == 0) |
|
1213 | + if ($version == 0) |
|
1214 | 1214 | $version = 1; |
1215 | 1215 | |
1216 | - switch($this->mode) { |
|
1217 | - case QR_MODE_NUM: $bits = QRinput::estimateBitsModeNum($this->size); break; |
|
1218 | - case QR_MODE_AN: $bits = QRinput::estimateBitsModeAn($this->size); break; |
|
1219 | - case QR_MODE_8: $bits = QRinput::estimateBitsMode8($this->size); break; |
|
1220 | - case QR_MODE_KANJI: $bits = QRinput::estimateBitsModeKanji($this->size);break; |
|
1216 | + switch ($this->mode) { |
|
1217 | + case QR_MODE_NUM: $bits = QRinput::estimateBitsModeNum($this->size); break; |
|
1218 | + case QR_MODE_AN: $bits = QRinput::estimateBitsModeAn($this->size); break; |
|
1219 | + case QR_MODE_8: $bits = QRinput::estimateBitsMode8($this->size); break; |
|
1220 | + case QR_MODE_KANJI: $bits = QRinput::estimateBitsModeKanji($this->size); break; |
|
1221 | 1221 | case QR_MODE_STRUCTURE: return STRUCTURE_HEADER_BITS; |
1222 | 1222 | default: |
1223 | 1223 | return 0; |
@@ -1225,7 +1225,7 @@ discard block |
||
1225 | 1225 | |
1226 | 1226 | $l = QRspec::lengthIndicator($this->mode, $version); |
1227 | 1227 | $m = 1 << $l; |
1228 | - $num = (int)(($this->size + $m - 1) / $m); |
|
1228 | + $num = (int) (($this->size + $m - 1) / $m); |
|
1229 | 1229 | |
1230 | 1230 | $bits += $num * (4 + $l); |
1231 | 1231 | |
@@ -1240,7 +1240,7 @@ discard block |
||
1240 | 1240 | unset($this->bstream); |
1241 | 1241 | $words = QRspec::maximumWords($this->mode, $version); |
1242 | 1242 | |
1243 | - if($this->size > $words) { |
|
1243 | + if ($this->size > $words) { |
|
1244 | 1244 | |
1245 | 1245 | $st1 = new QRinputItem($this->mode, $words, $this->data); |
1246 | 1246 | $st2 = new QRinputItem($this->mode, $this->size - $words, array_slice($this->data, $words)); |
@@ -1259,18 +1259,18 @@ discard block |
||
1259 | 1259 | |
1260 | 1260 | $ret = 0; |
1261 | 1261 | |
1262 | - switch($this->mode) { |
|
1263 | - case QR_MODE_NUM: $ret = $this->encodeModeNum($version); break; |
|
1264 | - case QR_MODE_AN: $ret = $this->encodeModeAn($version); break; |
|
1265 | - case QR_MODE_8: $ret = $this->encodeMode8($version); break; |
|
1266 | - case QR_MODE_KANJI: $ret = $this->encodeModeKanji($version);break; |
|
1267 | - case QR_MODE_STRUCTURE: $ret = $this->encodeModeStructure(); break; |
|
1262 | + switch ($this->mode) { |
|
1263 | + case QR_MODE_NUM: $ret = $this->encodeModeNum($version); break; |
|
1264 | + case QR_MODE_AN: $ret = $this->encodeModeAn($version); break; |
|
1265 | + case QR_MODE_8: $ret = $this->encodeMode8($version); break; |
|
1266 | + case QR_MODE_KANJI: $ret = $this->encodeModeKanji($version); break; |
|
1267 | + case QR_MODE_STRUCTURE: $ret = $this->encodeModeStructure(); break; |
|
1268 | 1268 | |
1269 | 1269 | default: |
1270 | 1270 | break; |
1271 | 1271 | } |
1272 | 1272 | |
1273 | - if($ret < 0) |
|
1273 | + if ($ret < 0) |
|
1274 | 1274 | return -1; |
1275 | 1275 | } |
1276 | 1276 | |
@@ -1312,7 +1312,7 @@ discard block |
||
1312 | 1312 | //---------------------------------------------------------------------- |
1313 | 1313 | public function setVersion($version) |
1314 | 1314 | { |
1315 | - if($version < 0 || $version > QRSPEC_VERSION_MAX) { |
|
1315 | + if ($version < 0 || $version > QRSPEC_VERSION_MAX) { |
|
1316 | 1316 | throw new Exception('Invalid version no'); |
1317 | 1317 | return -1; |
1318 | 1318 | } |
@@ -1331,7 +1331,7 @@ discard block |
||
1331 | 1331 | //---------------------------------------------------------------------- |
1332 | 1332 | public function setErrorCorrectionLevel($level) |
1333 | 1333 | { |
1334 | - if($level > QR_ECLEVEL_H) { |
|
1334 | + if ($level > QR_ECLEVEL_H) { |
|
1335 | 1335 | throw new Exception('Invalid ECLEVEL'); |
1336 | 1336 | return -1; |
1337 | 1337 | } |
@@ -1363,11 +1363,11 @@ discard block |
||
1363 | 1363 | |
1364 | 1364 | public function insertStructuredAppendHeader($size, $index, $parity) |
1365 | 1365 | { |
1366 | - if( $size > MAX_STRUCTURED_SYMBOLS ) { |
|
1366 | + if ($size > MAX_STRUCTURED_SYMBOLS) { |
|
1367 | 1367 | throw new Exception('insertStructuredAppendHeader wrong size'); |
1368 | 1368 | } |
1369 | 1369 | |
1370 | - if( $index <= 0 || $index > MAX_STRUCTURED_SYMBOLS ) { |
|
1370 | + if ($index <= 0 || $index > MAX_STRUCTURED_SYMBOLS) { |
|
1371 | 1371 | throw new Exception('insertStructuredAppendHeader wrong index'); |
1372 | 1372 | } |
1373 | 1373 | |
@@ -1387,9 +1387,9 @@ discard block |
||
1387 | 1387 | { |
1388 | 1388 | $parity = 0; |
1389 | 1389 | |
1390 | - foreach($this->items as $item) { |
|
1391 | - if($item->mode != QR_MODE_STRUCTURE) { |
|
1392 | - for($i=$item->size-1; $i>=0; $i--) { |
|
1390 | + foreach ($this->items as $item) { |
|
1391 | + if ($item->mode != QR_MODE_STRUCTURE) { |
|
1392 | + for ($i = $item->size - 1; $i >= 0; $i--) { |
|
1393 | 1393 | $parity ^= $item->data[$i]; |
1394 | 1394 | } |
1395 | 1395 | } |
@@ -1401,8 +1401,8 @@ discard block |
||
1401 | 1401 | //---------------------------------------------------------------------- |
1402 | 1402 | public static function checkModeNum($size, $data) |
1403 | 1403 | { |
1404 | - for($i=0; $i<$size; $i++) { |
|
1405 | - if((ord($data[$i]) < ord('0')) || (ord($data[$i]) > ord('9'))){ |
|
1404 | + for ($i = 0; $i < $size; $i++) { |
|
1405 | + if ((ord($data[$i]) < ord('0')) || (ord($data[$i]) > ord('9'))) { |
|
1406 | 1406 | return false; |
1407 | 1407 | } |
1408 | 1408 | } |
@@ -1413,10 +1413,10 @@ discard block |
||
1413 | 1413 | //---------------------------------------------------------------------- |
1414 | 1414 | public static function estimateBitsModeNum($size) |
1415 | 1415 | { |
1416 | - $w = (int)$size / 3; |
|
1416 | + $w = (int) $size / 3; |
|
1417 | 1417 | $bits = $w * 10; |
1418 | 1418 | |
1419 | - switch($size - $w * 3) { |
|
1419 | + switch ($size - $w * 3) { |
|
1420 | 1420 | case 1: |
1421 | 1421 | $bits += 4; |
1422 | 1422 | break; |
@@ -1435,7 +1435,7 @@ discard block |
||
1435 | 1435 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
1436 | 1436 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
1437 | 1437 | 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, |
1438 | - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, |
|
1438 | + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, |
|
1439 | 1439 | -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, |
1440 | 1440 | 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, |
1441 | 1441 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
@@ -1445,13 +1445,13 @@ discard block |
||
1445 | 1445 | //---------------------------------------------------------------------- |
1446 | 1446 | public static function lookAnTable($c) |
1447 | 1447 | { |
1448 | - return (($c > 127)?-1:self::$anTable[$c]); |
|
1448 | + return (($c > 127) ?-1 : self::$anTable[$c]); |
|
1449 | 1449 | } |
1450 | 1450 | |
1451 | 1451 | //---------------------------------------------------------------------- |
1452 | 1452 | public static function checkModeAn($size, $data) |
1453 | 1453 | { |
1454 | - for($i=0; $i<$size; $i++) { |
|
1454 | + for ($i = 0; $i < $size; $i++) { |
|
1455 | 1455 | if (self::lookAnTable(ord($data[$i])) == -1) { |
1456 | 1456 | return false; |
1457 | 1457 | } |
@@ -1463,10 +1463,10 @@ discard block |
||
1463 | 1463 | //---------------------------------------------------------------------- |
1464 | 1464 | public static function estimateBitsModeAn($size) |
1465 | 1465 | { |
1466 | - $w = (int)($size / 2); |
|
1466 | + $w = (int) ($size / 2); |
|
1467 | 1467 | $bits = $w * 11; |
1468 | 1468 | |
1469 | - if($size & 1) { |
|
1469 | + if ($size & 1) { |
|
1470 | 1470 | $bits += 6; |
1471 | 1471 | } |
1472 | 1472 | |
@@ -1482,18 +1482,18 @@ discard block |
||
1482 | 1482 | //---------------------------------------------------------------------- |
1483 | 1483 | public function estimateBitsModeKanji($size) |
1484 | 1484 | { |
1485 | - return (int)(($size / 2) * 13); |
|
1485 | + return (int) (($size / 2) * 13); |
|
1486 | 1486 | } |
1487 | 1487 | |
1488 | 1488 | //---------------------------------------------------------------------- |
1489 | 1489 | public static function checkModeKanji($size, $data) |
1490 | 1490 | { |
1491 | - if($size & 1) |
|
1491 | + if ($size & 1) |
|
1492 | 1492 | return false; |
1493 | 1493 | |
1494 | - for($i=0; $i<$size; $i+=2) { |
|
1495 | - $val = (ord($data[$i]) << 8) | ord($data[$i+1]); |
|
1496 | - if( $val < 0x8140 |
|
1494 | + for ($i = 0; $i < $size; $i += 2) { |
|
1495 | + $val = (ord($data[$i]) << 8) | ord($data[$i + 1]); |
|
1496 | + if ($val < 0x8140 |
|
1497 | 1497 | || ($val > 0x9ffc && $val < 0xe040) |
1498 | 1498 | || $val > 0xebbf) { |
1499 | 1499 | return false; |
@@ -1509,12 +1509,12 @@ discard block |
||
1509 | 1509 | |
1510 | 1510 | public static function check($mode, $size, $data) |
1511 | 1511 | { |
1512 | - if($size <= 0) |
|
1512 | + if ($size <= 0) |
|
1513 | 1513 | return false; |
1514 | 1514 | |
1515 | - switch($mode) { |
|
1516 | - case QR_MODE_NUM: return self::checkModeNum($size, $data); break; |
|
1517 | - case QR_MODE_AN: return self::checkModeAn($size, $data); break; |
|
1515 | + switch ($mode) { |
|
1516 | + case QR_MODE_NUM: return self::checkModeNum($size, $data); break; |
|
1517 | + case QR_MODE_AN: return self::checkModeAn($size, $data); break; |
|
1518 | 1518 | case QR_MODE_KANJI: return self::checkModeKanji($size, $data); break; |
1519 | 1519 | case QR_MODE_8: return true; break; |
1520 | 1520 | case QR_MODE_STRUCTURE: return true; break; |
@@ -1532,7 +1532,7 @@ discard block |
||
1532 | 1532 | { |
1533 | 1533 | $bits = 0; |
1534 | 1534 | |
1535 | - foreach($this->items as $item) { |
|
1535 | + foreach ($this->items as $item) { |
|
1536 | 1536 | $bits += $item->estimateBitStreamSizeOfEntry($version); |
1537 | 1537 | } |
1538 | 1538 | |
@@ -1547,7 +1547,7 @@ discard block |
||
1547 | 1547 | do { |
1548 | 1548 | $prev = $version; |
1549 | 1549 | $bits = $this->estimateBitStreamSize($prev); |
1550 | - $version = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); |
|
1550 | + $version = QRspec::getMinimumVersion((int) (($bits + 7) / 8), $this->level); |
|
1551 | 1551 | if ($version < 0) { |
1552 | 1552 | return -1; |
1553 | 1553 | } |
@@ -1560,32 +1560,32 @@ discard block |
||
1560 | 1560 | public static function lengthOfCode($mode, $version, $bits) |
1561 | 1561 | { |
1562 | 1562 | $payload = $bits - 4 - QRspec::lengthIndicator($mode, $version); |
1563 | - switch($mode) { |
|
1563 | + switch ($mode) { |
|
1564 | 1564 | case QR_MODE_NUM: |
1565 | - $chunks = (int)($payload / 10); |
|
1565 | + $chunks = (int) ($payload / 10); |
|
1566 | 1566 | $remain = $payload - $chunks * 10; |
1567 | 1567 | $size = $chunks * 3; |
1568 | - if($remain >= 7) { |
|
1568 | + if ($remain >= 7) { |
|
1569 | 1569 | $size += 2; |
1570 | - } else if($remain >= 4) { |
|
1570 | + } else if ($remain >= 4) { |
|
1571 | 1571 | $size += 1; |
1572 | 1572 | } |
1573 | 1573 | break; |
1574 | 1574 | case QR_MODE_AN: |
1575 | - $chunks = (int)($payload / 11); |
|
1575 | + $chunks = (int) ($payload / 11); |
|
1576 | 1576 | $remain = $payload - $chunks * 11; |
1577 | 1577 | $size = $chunks * 2; |
1578 | - if($remain >= 6) |
|
1578 | + if ($remain >= 6) |
|
1579 | 1579 | $size++; |
1580 | 1580 | break; |
1581 | 1581 | case QR_MODE_8: |
1582 | - $size = (int)($payload / 8); |
|
1582 | + $size = (int) ($payload / 8); |
|
1583 | 1583 | break; |
1584 | 1584 | case QR_MODE_KANJI: |
1585 | - $size = (int)(($payload / 13) * 2); |
|
1585 | + $size = (int) (($payload / 13) * 2); |
|
1586 | 1586 | break; |
1587 | 1587 | case QR_MODE_STRUCTURE: |
1588 | - $size = (int)($payload / 8); |
|
1588 | + $size = (int) ($payload / 8); |
|
1589 | 1589 | break; |
1590 | 1590 | default: |
1591 | 1591 | $size = 0; |
@@ -1593,8 +1593,8 @@ discard block |
||
1593 | 1593 | } |
1594 | 1594 | |
1595 | 1595 | $maxsize = QRspec::maximumWords($mode, $version); |
1596 | - if($size < 0) $size = 0; |
|
1597 | - if($size > $maxsize) $size = $maxsize; |
|
1596 | + if ($size < 0) $size = 0; |
|
1597 | + if ($size > $maxsize) $size = $maxsize; |
|
1598 | 1598 | |
1599 | 1599 | return $size; |
1600 | 1600 | } |
@@ -1604,10 +1604,10 @@ discard block |
||
1604 | 1604 | { |
1605 | 1605 | $total = 0; |
1606 | 1606 | |
1607 | - foreach($this->items as $item) { |
|
1607 | + foreach ($this->items as $item) { |
|
1608 | 1608 | $bits = $item->encodeBitStream($this->version); |
1609 | 1609 | |
1610 | - if($bits < 0) |
|
1610 | + if ($bits < 0) |
|
1611 | 1611 | return -1; |
1612 | 1612 | |
1613 | 1613 | $total += $bits; |
@@ -1620,21 +1620,21 @@ discard block |
||
1620 | 1620 | public function convertData() |
1621 | 1621 | { |
1622 | 1622 | $ver = $this->estimateVersion(); |
1623 | - if($ver > $this->getVersion()) { |
|
1623 | + if ($ver > $this->getVersion()) { |
|
1624 | 1624 | $this->setVersion($ver); |
1625 | 1625 | } |
1626 | 1626 | |
1627 | - for(;;) { |
|
1627 | + for (;;) { |
|
1628 | 1628 | $bits = $this->createBitStream(); |
1629 | 1629 | |
1630 | - if($bits < 0) |
|
1630 | + if ($bits < 0) |
|
1631 | 1631 | return -1; |
1632 | 1632 | |
1633 | - $ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); |
|
1634 | - if($ver < 0) { |
|
1633 | + $ver = QRspec::getMinimumVersion((int) (($bits + 7) / 8), $this->level); |
|
1634 | + if ($ver < 0) { |
|
1635 | 1635 | throw new Exception('WRONG VERSION'); |
1636 | 1636 | return -1; |
1637 | - } else if($ver > $this->getVersion()) { |
|
1637 | + } else if ($ver > $this->getVersion()) { |
|
1638 | 1638 | $this->setVersion($ver); |
1639 | 1639 | } else { |
1640 | 1640 | break; |
@@ -1660,26 +1660,26 @@ discard block |
||
1660 | 1660 | } |
1661 | 1661 | |
1662 | 1662 | $bits += 4; |
1663 | - $words = (int)(($bits + 7) / 8); |
|
1663 | + $words = (int) (($bits + 7) / 8); |
|
1664 | 1664 | |
1665 | 1665 | $padding = new QRbitstream(); |
1666 | 1666 | $ret = $padding->appendNum($words * 8 - $bits + 4, 0); |
1667 | 1667 | |
1668 | - if($ret < 0) |
|
1668 | + if ($ret < 0) |
|
1669 | 1669 | return $ret; |
1670 | 1670 | |
1671 | 1671 | $padlen = $maxwords - $words; |
1672 | 1672 | |
1673 | - if($padlen > 0) { |
|
1673 | + if ($padlen > 0) { |
|
1674 | 1674 | |
1675 | 1675 | $padbuf = array(); |
1676 | - for($i=0; $i<$padlen; $i++) { |
|
1677 | - $padbuf[$i] = ($i&1)?0x11:0xec; |
|
1676 | + for ($i = 0; $i < $padlen; $i++) { |
|
1677 | + $padbuf[$i] = ($i & 1) ? 0x11 : 0xec; |
|
1678 | 1678 | } |
1679 | 1679 | |
1680 | 1680 | $ret = $padding->appendBytes($padlen, $padbuf); |
1681 | 1681 | |
1682 | - if($ret < 0) |
|
1682 | + if ($ret < 0) |
|
1683 | 1683 | return $ret; |
1684 | 1684 | |
1685 | 1685 | } |
@@ -1692,15 +1692,15 @@ discard block |
||
1692 | 1692 | //---------------------------------------------------------------------- |
1693 | 1693 | public function mergeBitStream() |
1694 | 1694 | { |
1695 | - if($this->convertData() < 0) { |
|
1695 | + if ($this->convertData() < 0) { |
|
1696 | 1696 | return null; |
1697 | 1697 | } |
1698 | 1698 | |
1699 | 1699 | $bstream = new QRbitstream(); |
1700 | 1700 | |
1701 | - foreach($this->items as $item) { |
|
1701 | + foreach ($this->items as $item) { |
|
1702 | 1702 | $ret = $bstream->append($item->bstream); |
1703 | - if($ret < 0) { |
|
1703 | + if ($ret < 0) { |
|
1704 | 1704 | return null; |
1705 | 1705 | } |
1706 | 1706 | } |
@@ -1714,12 +1714,12 @@ discard block |
||
1714 | 1714 | |
1715 | 1715 | $bstream = $this->mergeBitStream(); |
1716 | 1716 | |
1717 | - if($bstream == null) { |
|
1717 | + if ($bstream == null) { |
|
1718 | 1718 | return null; |
1719 | 1719 | } |
1720 | 1720 | |
1721 | 1721 | $ret = $this->appendPaddingBit($bstream); |
1722 | - if($ret < 0) { |
|
1722 | + if ($ret < 0) { |
|
1723 | 1723 | return null; |
1724 | 1724 | } |
1725 | 1725 | |
@@ -1730,7 +1730,7 @@ discard block |
||
1730 | 1730 | public function getByteStream() |
1731 | 1731 | { |
1732 | 1732 | $bstream = $this->getBitStream(); |
1733 | - if($bstream == null) { |
|
1733 | + if ($bstream == null) { |
|
1734 | 1734 | return null; |
1735 | 1735 | } |
1736 | 1736 | |
@@ -1798,8 +1798,8 @@ discard block |
||
1798 | 1798 | $bstream->allocate($bits); |
1799 | 1799 | |
1800 | 1800 | $mask = 1 << ($bits - 1); |
1801 | - for($i=0; $i<$bits; $i++) { |
|
1802 | - if($num & $mask) { |
|
1801 | + for ($i = 0; $i < $bits; $i++) { |
|
1802 | + if ($num & $mask) { |
|
1803 | 1803 | $bstream->data[$i] = 1; |
1804 | 1804 | } else { |
1805 | 1805 | $bstream->data[$i] = 0; |
@@ -1815,12 +1815,12 @@ discard block |
||
1815 | 1815 | { |
1816 | 1816 | $bstream = new QRbitstream(); |
1817 | 1817 | $bstream->allocate($size * 8); |
1818 | - $p=0; |
|
1818 | + $p = 0; |
|
1819 | 1819 | |
1820 | - for($i=0; $i<$size; $i++) { |
|
1820 | + for ($i = 0; $i < $size; $i++) { |
|
1821 | 1821 | $mask = 0x80; |
1822 | - for($j=0; $j<8; $j++) { |
|
1823 | - if($data[$i] & $mask) { |
|
1822 | + for ($j = 0; $j < 8; $j++) { |
|
1823 | + if ($data[$i] & $mask) { |
|
1824 | 1824 | $bstream->data[$p] = 1; |
1825 | 1825 | } else { |
1826 | 1826 | $bstream->data[$p] = 0; |
@@ -1840,11 +1840,11 @@ discard block |
||
1840 | 1840 | return -1; |
1841 | 1841 | } |
1842 | 1842 | |
1843 | - if($arg->size() == 0) { |
|
1843 | + if ($arg->size() == 0) { |
|
1844 | 1844 | return 0; |
1845 | 1845 | } |
1846 | 1846 | |
1847 | - if($this->size() == 0) { |
|
1847 | + if ($this->size() == 0) { |
|
1848 | 1848 | $this->data = $arg->data; |
1849 | 1849 | return 0; |
1850 | 1850 | } |
@@ -1862,7 +1862,7 @@ discard block |
||
1862 | 1862 | |
1863 | 1863 | $b = QRbitstream::newFromNum($bits, $num); |
1864 | 1864 | |
1865 | - if(is_null($b)) |
|
1865 | + if (is_null($b)) |
|
1866 | 1866 | return -1; |
1867 | 1867 | |
1868 | 1868 | $ret = $this->append($b); |
@@ -1879,7 +1879,7 @@ discard block |
||
1879 | 1879 | |
1880 | 1880 | $b = QRbitstream::newFromBytes($size, $data); |
1881 | 1881 | |
1882 | - if(is_null($b)) |
|
1882 | + if (is_null($b)) |
|
1883 | 1883 | return -1; |
1884 | 1884 | |
1885 | 1885 | $ret = $this->append($b); |
@@ -1894,18 +1894,18 @@ discard block |
||
1894 | 1894 | |
1895 | 1895 | $size = $this->size(); |
1896 | 1896 | |
1897 | - if($size == 0) { |
|
1897 | + if ($size == 0) { |
|
1898 | 1898 | return array(); |
1899 | 1899 | } |
1900 | 1900 | |
1901 | - $data = array_fill(0, (int)(($size + 7) / 8), 0); |
|
1902 | - $bytes = (int)($size / 8); |
|
1901 | + $data = array_fill(0, (int) (($size + 7) / 8), 0); |
|
1902 | + $bytes = (int) ($size / 8); |
|
1903 | 1903 | |
1904 | 1904 | $p = 0; |
1905 | 1905 | |
1906 | - for($i=0; $i<$bytes; $i++) { |
|
1906 | + for ($i = 0; $i < $bytes; $i++) { |
|
1907 | 1907 | $v = 0; |
1908 | - for($j=0; $j<8; $j++) { |
|
1908 | + for ($j = 0; $j < 8; $j++) { |
|
1909 | 1909 | $v = $v << 1; |
1910 | 1910 | $v |= $this->data[$p]; |
1911 | 1911 | $p++; |
@@ -1913,9 +1913,9 @@ discard block |
||
1913 | 1913 | $data[$i] = $v; |
1914 | 1914 | } |
1915 | 1915 | |
1916 | - if($size & 7) { |
|
1916 | + if ($size & 7) { |
|
1917 | 1917 | $v = 0; |
1918 | - for($j=0; $j<($size & 7); $j++) { |
|
1918 | + for ($j = 0; $j < ($size & 7); $j++) { |
|
1919 | 1919 | $v = $v << 1; |
1920 | 1920 | $v |= $this->data[$p]; |
1921 | 1921 | $p++; |
@@ -1987,7 +1987,7 @@ discard block |
||
1987 | 1987 | if ($pos >= strlen($str)) |
1988 | 1988 | return false; |
1989 | 1989 | |
1990 | - return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9'))); |
|
1990 | + return ((ord($str[$pos]) >= ord('0')) && (ord($str[$pos]) <= ord('9'))); |
|
1991 | 1991 | } |
1992 | 1992 | |
1993 | 1993 | //---------------------------------------------------------------------- |
@@ -2007,17 +2007,17 @@ discard block |
||
2007 | 2007 | |
2008 | 2008 | $c = $this->dataStr[$pos]; |
2009 | 2009 | |
2010 | - if(self::isdigitat($this->dataStr, $pos)) { |
|
2010 | + if (self::isdigitat($this->dataStr, $pos)) { |
|
2011 | 2011 | return QR_MODE_NUM; |
2012 | - } else if(self::isalnumat($this->dataStr, $pos)) { |
|
2012 | + } else if (self::isalnumat($this->dataStr, $pos)) { |
|
2013 | 2013 | return QR_MODE_AN; |
2014 | - } else if($this->modeHint == QR_MODE_KANJI) { |
|
2014 | + } else if ($this->modeHint == QR_MODE_KANJI) { |
|
2015 | 2015 | |
2016 | - if ($pos+1 < strlen($this->dataStr)) |
|
2016 | + if ($pos + 1 < strlen($this->dataStr)) |
|
2017 | 2017 | { |
2018 | - $d = $this->dataStr[$pos+1]; |
|
2018 | + $d = $this->dataStr[$pos + 1]; |
|
2019 | 2019 | $word = (ord($c) << 8) | ord($d); |
2020 | - if(($word >= 0x8140 && $word <= 0x9ffc) || ($word >= 0xe040 && $word <= 0xebbf)) { |
|
2020 | + if (($word >= 0x8140 && $word <= 0x9ffc) || ($word >= 0xe040 && $word <= 0xebbf)) { |
|
2021 | 2021 | return QR_MODE_KANJI; |
2022 | 2022 | } |
2023 | 2023 | } |
@@ -2032,32 +2032,32 @@ discard block |
||
2032 | 2032 | $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion()); |
2033 | 2033 | |
2034 | 2034 | $p = 0; |
2035 | - while(self::isdigitat($this->dataStr, $p)) { |
|
2035 | + while (self::isdigitat($this->dataStr, $p)) { |
|
2036 | 2036 | $p++; |
2037 | 2037 | } |
2038 | 2038 | |
2039 | 2039 | $run = $p; |
2040 | 2040 | $mode = $this->identifyMode($p); |
2041 | 2041 | |
2042 | - if($mode == QR_MODE_8) { |
|
2042 | + if ($mode == QR_MODE_8) { |
|
2043 | 2043 | $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln |
2044 | 2044 | + QRinput::estimateBitsMode8(1) // + 4 + l8 |
2045 | 2045 | - QRinput::estimateBitsMode8($run + 1); // - 4 - l8 |
2046 | - if($dif > 0) { |
|
2046 | + if ($dif > 0) { |
|
2047 | 2047 | return $this->eat8(); |
2048 | 2048 | } |
2049 | 2049 | } |
2050 | - if($mode == QR_MODE_AN) { |
|
2050 | + if ($mode == QR_MODE_AN) { |
|
2051 | 2051 | $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln |
2052 | 2052 | + QRinput::estimateBitsModeAn(1) // + 4 + la |
2053 | - - QRinput::estimateBitsModeAn($run + 1);// - 4 - la |
|
2054 | - if($dif > 0) { |
|
2053 | + - QRinput::estimateBitsModeAn($run + 1); // - 4 - la |
|
2054 | + if ($dif > 0) { |
|
2055 | 2055 | return $this->eatAn(); |
2056 | 2056 | } |
2057 | 2057 | } |
2058 | 2058 | |
2059 | 2059 | $ret = $this->input->append(QR_MODE_NUM, $run, str_split($this->dataStr)); |
2060 | - if($ret < 0) |
|
2060 | + if ($ret < 0) |
|
2061 | 2061 | return -1; |
2062 | 2062 | |
2063 | 2063 | return $run; |
@@ -2066,15 +2066,15 @@ discard block |
||
2066 | 2066 | //---------------------------------------------------------------------- |
2067 | 2067 | public function eatAn() |
2068 | 2068 | { |
2069 | - $la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion()); |
|
2069 | + $la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion()); |
|
2070 | 2070 | $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion()); |
2071 | 2071 | |
2072 | 2072 | $p = 0; |
2073 | 2073 | |
2074 | - while(self::isalnumat($this->dataStr, $p)) { |
|
2075 | - if(self::isdigitat($this->dataStr, $p)) { |
|
2074 | + while (self::isalnumat($this->dataStr, $p)) { |
|
2075 | + if (self::isdigitat($this->dataStr, $p)) { |
|
2076 | 2076 | $q = $p; |
2077 | - while(self::isdigitat($this->dataStr, $q)) { |
|
2077 | + while (self::isdigitat($this->dataStr, $q)) { |
|
2078 | 2078 | $q++; |
2079 | 2079 | } |
2080 | 2080 | |
@@ -2082,7 +2082,7 @@ discard block |
||
2082 | 2082 | + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln |
2083 | 2083 | - QRinput::estimateBitsModeAn($q); // - 4 - la |
2084 | 2084 | |
2085 | - if($dif < 0) { |
|
2085 | + if ($dif < 0) { |
|
2086 | 2086 | break; |
2087 | 2087 | } else { |
2088 | 2088 | $p = $q; |
@@ -2094,17 +2094,17 @@ discard block |
||
2094 | 2094 | |
2095 | 2095 | $run = $p; |
2096 | 2096 | |
2097 | - if(!self::isalnumat($this->dataStr, $p)) { |
|
2097 | + if (!self::isalnumat($this->dataStr, $p)) { |
|
2098 | 2098 | $dif = QRinput::estimateBitsModeAn($run) + 4 + $la |
2099 | 2099 | + QRinput::estimateBitsMode8(1) // + 4 + l8 |
2100 | 2100 | - QRinput::estimateBitsMode8($run + 1); // - 4 - l8 |
2101 | - if($dif > 0) { |
|
2101 | + if ($dif > 0) { |
|
2102 | 2102 | return $this->eat8(); |
2103 | 2103 | } |
2104 | 2104 | } |
2105 | 2105 | |
2106 | 2106 | $ret = $this->input->append(QR_MODE_AN, $run, str_split($this->dataStr)); |
2107 | - if($ret < 0) |
|
2107 | + if ($ret < 0) |
|
2108 | 2108 | return -1; |
2109 | 2109 | |
2110 | 2110 | return $run; |
@@ -2115,12 +2115,12 @@ discard block |
||
2115 | 2115 | { |
2116 | 2116 | $p = 0; |
2117 | 2117 | |
2118 | - while($this->identifyMode($p) == QR_MODE_KANJI) { |
|
2118 | + while ($this->identifyMode($p) == QR_MODE_KANJI) { |
|
2119 | 2119 | $p += 2; |
2120 | 2120 | } |
2121 | 2121 | |
2122 | 2122 | $ret = $this->input->append(QR_MODE_KANJI, $p, str_split($this->dataStr)); |
2123 | - if($ret < 0) |
|
2123 | + if ($ret < 0) |
|
2124 | 2124 | return -1; |
2125 | 2125 | |
2126 | 2126 | return $run; |
@@ -2135,34 +2135,34 @@ discard block |
||
2135 | 2135 | $p = 1; |
2136 | 2136 | $dataStrLen = strlen($this->dataStr); |
2137 | 2137 | |
2138 | - while($p < $dataStrLen) { |
|
2138 | + while ($p < $dataStrLen) { |
|
2139 | 2139 | |
2140 | 2140 | $mode = $this->identifyMode($p); |
2141 | - if($mode == QR_MODE_KANJI) { |
|
2141 | + if ($mode == QR_MODE_KANJI) { |
|
2142 | 2142 | break; |
2143 | 2143 | } |
2144 | - if($mode == QR_MODE_NUM) { |
|
2144 | + if ($mode == QR_MODE_NUM) { |
|
2145 | 2145 | $q = $p; |
2146 | - while(self::isdigitat($this->dataStr, $q)) { |
|
2146 | + while (self::isdigitat($this->dataStr, $q)) { |
|
2147 | 2147 | $q++; |
2148 | 2148 | } |
2149 | 2149 | $dif = QRinput::estimateBitsMode8($p) // + 4 + l8 |
2150 | 2150 | + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln |
2151 | 2151 | - QRinput::estimateBitsMode8($q); // - 4 - l8 |
2152 | - if($dif < 0) { |
|
2152 | + if ($dif < 0) { |
|
2153 | 2153 | break; |
2154 | 2154 | } else { |
2155 | 2155 | $p = $q; |
2156 | 2156 | } |
2157 | - } else if($mode == QR_MODE_AN) { |
|
2157 | + } else if ($mode == QR_MODE_AN) { |
|
2158 | 2158 | $q = $p; |
2159 | - while(self::isalnumat($this->dataStr, $q)) { |
|
2159 | + while (self::isalnumat($this->dataStr, $q)) { |
|
2160 | 2160 | $q++; |
2161 | 2161 | } |
2162 | 2162 | $dif = QRinput::estimateBitsMode8($p) // + 4 + l8 |
2163 | 2163 | + QRinput::estimateBitsModeAn($q - $p) + 4 + $la |
2164 | 2164 | - QRinput::estimateBitsMode8($q); // - 4 - l8 |
2165 | - if($dif < 0) { |
|
2165 | + if ($dif < 0) { |
|
2166 | 2166 | break; |
2167 | 2167 | } else { |
2168 | 2168 | $p = $q; |
@@ -2175,7 +2175,7 @@ discard block |
||
2175 | 2175 | $run = $p; |
2176 | 2176 | $ret = $this->input->append(QR_MODE_8, $run, str_split($this->dataStr)); |
2177 | 2177 | |
2178 | - if($ret < 0) |
|
2178 | + if ($ret < 0) |
|
2179 | 2179 | return -1; |
2180 | 2180 | |
2181 | 2181 | return $run; |
@@ -2186,7 +2186,7 @@ discard block |
||
2186 | 2186 | { |
2187 | 2187 | while (strlen($this->dataStr) > 0) |
2188 | 2188 | { |
2189 | - if($this->dataStr == '') |
|
2189 | + if ($this->dataStr == '') |
|
2190 | 2190 | return 0; |
2191 | 2191 | |
2192 | 2192 | $mode = $this->identifyMode(0); |
@@ -2203,8 +2203,8 @@ discard block |
||
2203 | 2203 | |
2204 | 2204 | } |
2205 | 2205 | |
2206 | - if($length == 0) return 0; |
|
2207 | - if($length < 0) return -1; |
|
2206 | + if ($length == 0) return 0; |
|
2207 | + if ($length < 0) return -1; |
|
2208 | 2208 | |
2209 | 2209 | $this->dataStr = substr($this->dataStr, $length); |
2210 | 2210 | } |
@@ -2216,9 +2216,9 @@ discard block |
||
2216 | 2216 | $stringLen = strlen($this->dataStr); |
2217 | 2217 | $p = 0; |
2218 | 2218 | |
2219 | - while ($p<$stringLen) { |
|
2219 | + while ($p < $stringLen) { |
|
2220 | 2220 | $mode = self::identifyMode(substr($this->dataStr, $p)); |
2221 | - if($mode == QR_MODE_KANJI) { |
|
2221 | + if ($mode == QR_MODE_KANJI) { |
|
2222 | 2222 | $p += 2; |
2223 | 2223 | } else { |
2224 | 2224 | if (ord($this->dataStr[$p]) >= ord('a') && ord($this->dataStr[$p]) <= ord('z')) { |
@@ -2234,13 +2234,13 @@ discard block |
||
2234 | 2234 | //---------------------------------------------------------------------- |
2235 | 2235 | public static function splitStringToQRinput($string, QRinput $input, $modeHint, $casesensitive = true) |
2236 | 2236 | { |
2237 | - if(is_null($string) || $string == '\0' || $string == '') { |
|
2237 | + if (is_null($string) || $string == '\0' || $string == '') { |
|
2238 | 2238 | throw new Exception('empty string!!!'); |
2239 | 2239 | } |
2240 | 2240 | |
2241 | 2241 | $split = new QRsplit($string, $input, $modeHint); |
2242 | 2242 | |
2243 | - if(!$casesensitive) |
|
2243 | + if (!$casesensitive) |
|
2244 | 2244 | $split->toUpper(); |
2245 | 2245 | |
2246 | 2246 | return $split->splitString(); |
@@ -2285,16 +2285,16 @@ discard block |
||
2285 | 2285 | |
2286 | 2286 | class QRrsItem { |
2287 | 2287 | |
2288 | - public $mm; // Bits per symbol |
|
2289 | - public $nn; // Symbols per block (= (1<<mm)-1) |
|
2290 | - public $alpha_to = array(); // log lookup table |
|
2291 | - public $index_of = array(); // Antilog lookup table |
|
2292 | - public $genpoly = array(); // Generator polynomial |
|
2293 | - public $nroots; // Number of generator roots = number of parity symbols |
|
2294 | - public $fcr; // First consecutive root, index form |
|
2295 | - public $prim; // Primitive element, index form |
|
2296 | - public $iprim; // prim-th root of 1, index form |
|
2297 | - public $pad; // Padding bytes in shortened block |
|
2288 | + public $mm; // Bits per symbol |
|
2289 | + public $nn; // Symbols per block (= (1<<mm)-1) |
|
2290 | + public $alpha_to = array(); // log lookup table |
|
2291 | + public $index_of = array(); // Antilog lookup table |
|
2292 | + public $genpoly = array(); // Generator polynomial |
|
2293 | + public $nroots; // Number of generator roots = number of parity symbols |
|
2294 | + public $fcr; // First consecutive root, index form |
|
2295 | + public $prim; // Primitive element, index form |
|
2296 | + public $iprim; // prim-th root of 1, index form |
|
2297 | + public $pad; // Padding bytes in shortened block |
|
2298 | 2298 | public $gfpoly; |
2299 | 2299 | |
2300 | 2300 | //---------------------------------------------------------------------- |
@@ -2318,47 +2318,47 @@ discard block |
||
2318 | 2318 | $rs = null; |
2319 | 2319 | |
2320 | 2320 | // Check parameter ranges |
2321 | - if($symsize < 0 || $symsize > 8) return $rs; |
|
2322 | - if($fcr < 0 || $fcr >= (1<<$symsize)) return $rs; |
|
2323 | - if($prim <= 0 || $prim >= (1<<$symsize)) return $rs; |
|
2324 | - if($nroots < 0 || $nroots >= (1<<$symsize)) return $rs; // Can't have more roots than symbol values! |
|
2325 | - if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) return $rs; // Too much padding |
|
2321 | + if ($symsize < 0 || $symsize > 8) return $rs; |
|
2322 | + if ($fcr < 0 || $fcr >= (1 << $symsize)) return $rs; |
|
2323 | + if ($prim <= 0 || $prim >= (1 << $symsize)) return $rs; |
|
2324 | + if ($nroots < 0 || $nroots >= (1 << $symsize)) return $rs; // Can't have more roots than symbol values! |
|
2325 | + if ($pad < 0 || $pad >= ((1 << $symsize) - 1 - $nroots)) return $rs; // Too much padding |
|
2326 | 2326 | |
2327 | 2327 | $rs = new QRrsItem(); |
2328 | 2328 | $rs->mm = $symsize; |
2329 | - $rs->nn = (1<<$symsize)-1; |
|
2329 | + $rs->nn = (1 << $symsize) - 1; |
|
2330 | 2330 | $rs->pad = $pad; |
2331 | 2331 | |
2332 | - $rs->alpha_to = array_fill(0, $rs->nn+1, 0); |
|
2333 | - $rs->index_of = array_fill(0, $rs->nn+1, 0); |
|
2332 | + $rs->alpha_to = array_fill(0, $rs->nn + 1, 0); |
|
2333 | + $rs->index_of = array_fill(0, $rs->nn + 1, 0); |
|
2334 | 2334 | |
2335 | 2335 | // PHP style macro replacement ;) |
2336 | - $NN =& $rs->nn; |
|
2337 | - $A0 =& $NN; |
|
2336 | + $NN = & $rs->nn; |
|
2337 | + $A0 = & $NN; |
|
2338 | 2338 | |
2339 | 2339 | // Generate Galois field lookup tables |
2340 | 2340 | $rs->index_of[0] = $A0; // log(zero) = -inf |
2341 | 2341 | $rs->alpha_to[$A0] = 0; // alpha**-inf = 0 |
2342 | 2342 | $sr = 1; |
2343 | 2343 | |
2344 | - for($i=0; $i<$rs->nn; $i++) { |
|
2344 | + for ($i = 0; $i < $rs->nn; $i++) { |
|
2345 | 2345 | $rs->index_of[$sr] = $i; |
2346 | 2346 | $rs->alpha_to[$i] = $sr; |
2347 | 2347 | $sr <<= 1; |
2348 | - if($sr & (1<<$symsize)) { |
|
2348 | + if ($sr & (1 << $symsize)) { |
|
2349 | 2349 | $sr ^= $gfpoly; |
2350 | 2350 | } |
2351 | 2351 | $sr &= $rs->nn; |
2352 | 2352 | } |
2353 | 2353 | |
2354 | - if($sr != 1){ |
|
2354 | + if ($sr != 1) { |
|
2355 | 2355 | // field generator polynomial is not primitive! |
2356 | 2356 | $rs = null; |
2357 | 2357 | return $rs; |
2358 | 2358 | } |
2359 | 2359 | |
2360 | 2360 | /* Form RS code generator polynomial from its roots */ |
2361 | - $rs->genpoly = array_fill(0, $nroots+1, 0); |
|
2361 | + $rs->genpoly = array_fill(0, $nroots + 1, 0); |
|
2362 | 2362 | |
2363 | 2363 | $rs->fcr = $fcr; |
2364 | 2364 | $rs->prim = $prim; |
@@ -2366,21 +2366,21 @@ discard block |
||
2366 | 2366 | $rs->gfpoly = $gfpoly; |
2367 | 2367 | |
2368 | 2368 | /* Find prim-th root of 1, used in decoding */ |
2369 | - for($iprim=1;($iprim % $prim) != 0;$iprim += $rs->nn) |
|
2369 | + for ($iprim = 1; ($iprim % $prim) != 0; $iprim += $rs->nn) |
|
2370 | 2370 | ; // intentional empty-body loop! |
2371 | 2371 | |
2372 | - $rs->iprim = (int)($iprim / $prim); |
|
2372 | + $rs->iprim = (int) ($iprim / $prim); |
|
2373 | 2373 | $rs->genpoly[0] = 1; |
2374 | 2374 | |
2375 | - for ($i = 0,$root=$fcr*$prim; $i < $nroots; $i++, $root += $prim) { |
|
2376 | - $rs->genpoly[$i+1] = 1; |
|
2375 | + for ($i = 0, $root = $fcr * $prim; $i < $nroots; $i++, $root += $prim) { |
|
2376 | + $rs->genpoly[$i + 1] = 1; |
|
2377 | 2377 | |
2378 | 2378 | // Multiply rs->genpoly[] by @**(root + x) |
2379 | 2379 | for ($j = $i; $j > 0; $j--) { |
2380 | 2380 | if ($rs->genpoly[$j] != 0) { |
2381 | - $rs->genpoly[$j] = $rs->genpoly[$j-1] ^ $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[$j]] + $root)]; |
|
2381 | + $rs->genpoly[$j] = $rs->genpoly[$j - 1] ^ $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[$j]] + $root)]; |
|
2382 | 2382 | } else { |
2383 | - $rs->genpoly[$j] = $rs->genpoly[$j-1]; |
|
2383 | + $rs->genpoly[$j] = $rs->genpoly[$j - 1]; |
|
2384 | 2384 | } |
2385 | 2385 | } |
2386 | 2386 | // rs->genpoly[0] can never be zero |
@@ -2397,38 +2397,38 @@ discard block |
||
2397 | 2397 | //---------------------------------------------------------------------- |
2398 | 2398 | public function encode_rs_char($data, &$parity) |
2399 | 2399 | { |
2400 | - $MM =& $this->mm; |
|
2401 | - $NN =& $this->nn; |
|
2402 | - $ALPHA_TO =& $this->alpha_to; |
|
2403 | - $INDEX_OF =& $this->index_of; |
|
2404 | - $GENPOLY =& $this->genpoly; |
|
2405 | - $NROOTS =& $this->nroots; |
|
2406 | - $FCR =& $this->fcr; |
|
2407 | - $PRIM =& $this->prim; |
|
2408 | - $IPRIM =& $this->iprim; |
|
2409 | - $PAD =& $this->pad; |
|
2410 | - $A0 =& $NN; |
|
2400 | + $MM = & $this->mm; |
|
2401 | + $NN = & $this->nn; |
|
2402 | + $ALPHA_TO = & $this->alpha_to; |
|
2403 | + $INDEX_OF = & $this->index_of; |
|
2404 | + $GENPOLY = & $this->genpoly; |
|
2405 | + $NROOTS = & $this->nroots; |
|
2406 | + $FCR = & $this->fcr; |
|
2407 | + $PRIM = & $this->prim; |
|
2408 | + $IPRIM = & $this->iprim; |
|
2409 | + $PAD = & $this->pad; |
|
2410 | + $A0 = & $NN; |
|
2411 | 2411 | |
2412 | 2412 | $parity = array_fill(0, $NROOTS, 0); |
2413 | 2413 | |
2414 | - for($i=0; $i< ($NN-$NROOTS-$PAD); $i++) { |
|
2414 | + for ($i = 0; $i < ($NN - $NROOTS - $PAD); $i++) { |
|
2415 | 2415 | |
2416 | 2416 | $feedback = $INDEX_OF[$data[$i] ^ $parity[0]]; |
2417 | - if($feedback != $A0) { |
|
2417 | + if ($feedback != $A0) { |
|
2418 | 2418 | // feedback term is non-zero |
2419 | 2419 | |
2420 | 2420 | // This line is unnecessary when GENPOLY[NROOTS] is unity, as it must |
2421 | 2421 | // always be for the polynomials constructed by init_rs() |
2422 | 2422 | $feedback = $this->modnn($NN - $GENPOLY[$NROOTS] + $feedback); |
2423 | 2423 | |
2424 | - for($j=1;$j<$NROOTS;$j++) { |
|
2425 | - $parity[$j] ^= $ALPHA_TO[$this->modnn($feedback + $GENPOLY[$NROOTS-$j])]; |
|
2424 | + for ($j = 1; $j < $NROOTS; $j++) { |
|
2425 | + $parity[$j] ^= $ALPHA_TO[$this->modnn($feedback + $GENPOLY[$NROOTS - $j])]; |
|
2426 | 2426 | } |
2427 | 2427 | } |
2428 | 2428 | |
2429 | 2429 | // Shift |
2430 | 2430 | array_shift($parity); |
2431 | - if($feedback != $A0) { |
|
2431 | + if ($feedback != $A0) { |
|
2432 | 2432 | array_push($parity, $ALPHA_TO[$this->modnn($feedback + $GENPOLY[0])]); |
2433 | 2433 | } else { |
2434 | 2434 | array_push($parity, 0); |
@@ -2446,13 +2446,13 @@ discard block |
||
2446 | 2446 | //---------------------------------------------------------------------- |
2447 | 2447 | public static function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) |
2448 | 2448 | { |
2449 | - foreach(self::$items as $rs) { |
|
2450 | - if($rs->pad != $pad) continue; |
|
2451 | - if($rs->nroots != $nroots) continue; |
|
2452 | - if($rs->mm != $symsize) continue; |
|
2453 | - if($rs->gfpoly != $gfpoly) continue; |
|
2454 | - if($rs->fcr != $fcr) continue; |
|
2455 | - if($rs->prim != $prim) continue; |
|
2449 | + foreach (self::$items as $rs) { |
|
2450 | + if ($rs->pad != $pad) continue; |
|
2451 | + if ($rs->nroots != $nroots) continue; |
|
2452 | + if ($rs->mm != $symsize) continue; |
|
2453 | + if ($rs->gfpoly != $gfpoly) continue; |
|
2454 | + if ($rs->fcr != $fcr) continue; |
|
2455 | + if ($rs->prim != $prim) continue; |
|
2456 | 2456 | |
2457 | 2457 | return $rs; |
2458 | 2458 | } |
@@ -2516,10 +2516,10 @@ discard block |
||
2516 | 2516 | public function writeFormatInformation($width, &$frame, $mask, $level) |
2517 | 2517 | { |
2518 | 2518 | $blacks = 0; |
2519 | - $format = QRspec::getFormatInfo($mask, $level); |
|
2519 | + $format = QRspec::getFormatInfo($mask, $level); |
|
2520 | 2520 | |
2521 | - for($i=0; $i<8; $i++) { |
|
2522 | - if($format & 1) { |
|
2521 | + for ($i = 0; $i < 8; $i++) { |
|
2522 | + if ($format & 1) { |
|
2523 | 2523 | $blacks += 2; |
2524 | 2524 | $v = 0x85; |
2525 | 2525 | } else { |
@@ -2527,7 +2527,7 @@ discard block |
||
2527 | 2527 | } |
2528 | 2528 | |
2529 | 2529 | $frame[8][$width - 1 - $i] = chr($v); |
2530 | - if($i < 6) { |
|
2530 | + if ($i < 6) { |
|
2531 | 2531 | $frame[$i][8] = chr($v); |
2532 | 2532 | } else { |
2533 | 2533 | $frame[$i + 1][8] = chr($v); |
@@ -2535,8 +2535,8 @@ discard block |
||
2535 | 2535 | $format = $format >> 1; |
2536 | 2536 | } |
2537 | 2537 | |
2538 | - for($i=0; $i<7; $i++) { |
|
2539 | - if($format & 1) { |
|
2538 | + for ($i = 0; $i < 7; $i++) { |
|
2539 | + if ($format & 1) { |
|
2540 | 2540 | $blacks += 2; |
2541 | 2541 | $v = 0x85; |
2542 | 2542 | } else { |
@@ -2544,7 +2544,7 @@ discard block |
||
2544 | 2544 | } |
2545 | 2545 | |
2546 | 2546 | $frame[$width - 7 + $i][8] = chr($v); |
2547 | - if($i == 0) { |
|
2547 | + if ($i == 0) { |
|
2548 | 2548 | $frame[8][7] = chr($v); |
2549 | 2549 | } else { |
2550 | 2550 | $frame[8][6 - $i] = chr($v); |
@@ -2557,27 +2557,27 @@ discard block |
||
2557 | 2557 | } |
2558 | 2558 | |
2559 | 2559 | //---------------------------------------------------------------------- |
2560 | - public function mask0($x, $y) { return ($x+$y)&1; } |
|
2561 | - public function mask1($x, $y) { return ($y&1); } |
|
2562 | - public function mask2($x, $y) { return ($x%3); } |
|
2563 | - public function mask3($x, $y) { return ($x+$y)%3; } |
|
2564 | - public function mask4($x, $y) { return (((int)($y/2))+((int)($x/3)))&1; } |
|
2565 | - public function mask5($x, $y) { return (($x*$y)&1)+($x*$y)%3; } |
|
2566 | - public function mask6($x, $y) { return ((($x*$y)&1)+($x*$y)%3)&1; } |
|
2567 | - public function mask7($x, $y) { return ((($x*$y)%3)+(($x+$y)&1))&1; } |
|
2560 | + public function mask0($x, $y) { return ($x + $y) & 1; } |
|
2561 | + public function mask1($x, $y) { return ($y & 1); } |
|
2562 | + public function mask2($x, $y) { return ($x % 3); } |
|
2563 | + public function mask3($x, $y) { return ($x + $y) % 3; } |
|
2564 | + public function mask4($x, $y) { return (((int) ($y / 2)) + ((int) ($x / 3))) & 1; } |
|
2565 | + public function mask5($x, $y) { return (($x * $y) & 1) + ($x * $y) % 3; } |
|
2566 | + public function mask6($x, $y) { return ((($x * $y) & 1) + ($x * $y) % 3) & 1; } |
|
2567 | + public function mask7($x, $y) { return ((($x * $y) % 3) + (($x + $y) & 1)) & 1; } |
|
2568 | 2568 | |
2569 | 2569 | //---------------------------------------------------------------------- |
2570 | 2570 | private function generateMaskNo($maskNo, $width, $frame) |
2571 | 2571 | { |
2572 | 2572 | $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); |
2573 | 2573 | |
2574 | - for($y=0; $y<$width; $y++) { |
|
2575 | - for($x=0; $x<$width; $x++) { |
|
2576 | - if(ord($frame[$y][$x]) & 0x80) { |
|
2574 | + for ($y = 0; $y < $width; $y++) { |
|
2575 | + for ($x = 0; $x < $width; $x++) { |
|
2576 | + if (ord($frame[$y][$x]) & 0x80) { |
|
2577 | 2577 | $bitMask[$y][$x] = 0; |
2578 | 2578 | } else { |
2579 | 2579 | $maskFunc = call_user_func(array($this, 'mask'.$maskNo), $x, $y); |
2580 | - $bitMask[$y][$x] = ($maskFunc == 0)?1:0; |
|
2580 | + $bitMask[$y][$x] = ($maskFunc == 0) ? 1 : 0; |
|
2581 | 2581 | } |
2582 | 2582 | |
2583 | 2583 | } |
@@ -2635,12 +2635,12 @@ discard block |
||
2635 | 2635 | |
2636 | 2636 | $d = $s; |
2637 | 2637 | |
2638 | - for($y=0; $y<$width; $y++) { |
|
2639 | - for($x=0; $x<$width; $x++) { |
|
2640 | - if($bitMask[$y][$x] == 1) { |
|
2641 | - $d[$y][$x] = chr(ord($s[$y][$x]) ^ (int)$bitMask[$y][$x]); |
|
2638 | + for ($y = 0; $y < $width; $y++) { |
|
2639 | + for ($x = 0; $x < $width; $x++) { |
|
2640 | + if ($bitMask[$y][$x] == 1) { |
|
2641 | + $d[$y][$x] = chr(ord($s[$y][$x]) ^ (int) $bitMask[$y][$x]); |
|
2642 | 2642 | } |
2643 | - $b += (int)(ord($d[$y][$x]) & 1); |
|
2643 | + $b += (int) (ord($d[$y][$x]) & 1); |
|
2644 | 2644 | } |
2645 | 2645 | } |
2646 | 2646 | |
@@ -2662,21 +2662,21 @@ discard block |
||
2662 | 2662 | { |
2663 | 2663 | $demerit = 0; |
2664 | 2664 | |
2665 | - for($i=0; $i<$length; $i++) { |
|
2665 | + for ($i = 0; $i < $length; $i++) { |
|
2666 | 2666 | |
2667 | - if($this->runLength[$i] >= 5) { |
|
2667 | + if ($this->runLength[$i] >= 5) { |
|
2668 | 2668 | $demerit += (N1 + ($this->runLength[$i] - 5)); |
2669 | 2669 | } |
2670 | - if($i & 1) { |
|
2671 | - if(($i >= 3) && ($i < ($length-2)) && ($this->runLength[$i] % 3 == 0)) { |
|
2672 | - $fact = (int)($this->runLength[$i] / 3); |
|
2673 | - if(($this->runLength[$i-2] == $fact) && |
|
2674 | - ($this->runLength[$i-1] == $fact) && |
|
2675 | - ($this->runLength[$i+1] == $fact) && |
|
2676 | - ($this->runLength[$i+2] == $fact)) { |
|
2677 | - if(($this->runLength[$i-3] < 0) || ($this->runLength[$i-3] >= (4 * $fact))) { |
|
2670 | + if ($i & 1) { |
|
2671 | + if (($i >= 3) && ($i < ($length - 2)) && ($this->runLength[$i] % 3 == 0)) { |
|
2672 | + $fact = (int) ($this->runLength[$i] / 3); |
|
2673 | + if (($this->runLength[$i - 2] == $fact) && |
|
2674 | + ($this->runLength[$i - 1] == $fact) && |
|
2675 | + ($this->runLength[$i + 1] == $fact) && |
|
2676 | + ($this->runLength[$i + 2] == $fact)) { |
|
2677 | + if (($this->runLength[$i - 3] < 0) || ($this->runLength[$i - 3] >= (4 * $fact))) { |
|
2678 | 2678 | $demerit += N3; |
2679 | - } else if((($i+3) >= $length) || ($this->runLength[$i+3] >= (4 * $fact))) { |
|
2679 | + } else if ((($i + 3) >= $length) || ($this->runLength[$i + 3] >= (4 * $fact))) { |
|
2680 | 2680 | $demerit += N3; |
2681 | 2681 | } |
2682 | 2682 | } |
@@ -2692,30 +2692,30 @@ discard block |
||
2692 | 2692 | $head = 0; |
2693 | 2693 | $demerit = 0; |
2694 | 2694 | |
2695 | - for($y=0; $y<$width; $y++) { |
|
2695 | + for ($y = 0; $y < $width; $y++) { |
|
2696 | 2696 | $head = 0; |
2697 | 2697 | $this->runLength[0] = 1; |
2698 | 2698 | |
2699 | 2699 | $frameY = $frame[$y]; |
2700 | 2700 | |
2701 | - if ($y>0) |
|
2702 | - $frameYM = $frame[$y-1]; |
|
2701 | + if ($y > 0) |
|
2702 | + $frameYM = $frame[$y - 1]; |
|
2703 | 2703 | |
2704 | - for($x=0; $x<$width; $x++) { |
|
2705 | - if(($x > 0) && ($y > 0)) { |
|
2706 | - $b22 = ord($frameY[$x]) & ord($frameY[$x-1]) & ord($frameYM[$x]) & ord($frameYM[$x-1]); |
|
2707 | - $w22 = ord($frameY[$x]) | ord($frameY[$x-1]) | ord($frameYM[$x]) | ord($frameYM[$x-1]); |
|
2704 | + for ($x = 0; $x < $width; $x++) { |
|
2705 | + if (($x > 0) && ($y > 0)) { |
|
2706 | + $b22 = ord($frameY[$x]) & ord($frameY[$x - 1]) & ord($frameYM[$x]) & ord($frameYM[$x - 1]); |
|
2707 | + $w22 = ord($frameY[$x]) | ord($frameY[$x - 1]) | ord($frameYM[$x]) | ord($frameYM[$x - 1]); |
|
2708 | 2708 | |
2709 | - if(($b22 | ($w22 ^ 1))&1) { |
|
2709 | + if (($b22 | ($w22 ^ 1)) & 1) { |
|
2710 | 2710 | $demerit += N2; |
2711 | 2711 | } |
2712 | 2712 | } |
2713 | - if(($x == 0) && (ord($frameY[$x]) & 1)) { |
|
2713 | + if (($x == 0) && (ord($frameY[$x]) & 1)) { |
|
2714 | 2714 | $this->runLength[0] = -1; |
2715 | 2715 | $head = 1; |
2716 | 2716 | $this->runLength[$head] = 1; |
2717 | - } else if($x > 0) { |
|
2718 | - if((ord($frameY[$x]) ^ ord($frameY[$x-1])) & 1) { |
|
2717 | + } else if ($x > 0) { |
|
2718 | + if ((ord($frameY[$x]) ^ ord($frameY[$x - 1])) & 1) { |
|
2719 | 2719 | $head++; |
2720 | 2720 | $this->runLength[$head] = 1; |
2721 | 2721 | } else { |
@@ -2724,20 +2724,20 @@ discard block |
||
2724 | 2724 | } |
2725 | 2725 | } |
2726 | 2726 | |
2727 | - $demerit += $this->calcN1N3($head+1); |
|
2727 | + $demerit += $this->calcN1N3($head + 1); |
|
2728 | 2728 | } |
2729 | 2729 | |
2730 | - for($x=0; $x<$width; $x++) { |
|
2730 | + for ($x = 0; $x < $width; $x++) { |
|
2731 | 2731 | $head = 0; |
2732 | 2732 | $this->runLength[0] = 1; |
2733 | 2733 | |
2734 | - for($y=0; $y<$width; $y++) { |
|
2735 | - if($y == 0 && (ord($frame[$y][$x]) & 1)) { |
|
2734 | + for ($y = 0; $y < $width; $y++) { |
|
2735 | + if ($y == 0 && (ord($frame[$y][$x]) & 1)) { |
|
2736 | 2736 | $this->runLength[0] = -1; |
2737 | 2737 | $head = 1; |
2738 | 2738 | $this->runLength[$head] = 1; |
2739 | - } else if($y > 0) { |
|
2740 | - if((ord($frame[$y][$x]) ^ ord($frame[$y-1][$x])) & 1) { |
|
2739 | + } else if ($y > 0) { |
|
2740 | + if ((ord($frame[$y][$x]) ^ ord($frame[$y - 1][$x])) & 1) { |
|
2741 | 2741 | $head++; |
2742 | 2742 | $this->runLength[$head] = 1; |
2743 | 2743 | } else { |
@@ -2746,7 +2746,7 @@ discard block |
||
2746 | 2746 | } |
2747 | 2747 | } |
2748 | 2748 | |
2749 | - $demerit += $this->calcN1N3($head+1); |
|
2749 | + $demerit += $this->calcN1N3($head + 1); |
|
2750 | 2750 | } |
2751 | 2751 | |
2752 | 2752 | return $demerit; |
@@ -2760,13 +2760,13 @@ discard block |
||
2760 | 2760 | $bestMaskNum = 0; |
2761 | 2761 | $bestMask = array(); |
2762 | 2762 | |
2763 | - $checked_masks = array(0,1,2,3,4,5,6,7); |
|
2763 | + $checked_masks = array(0, 1, 2, 3, 4, 5, 6, 7); |
|
2764 | 2764 | |
2765 | 2765 | if (QR_FIND_FROM_RANDOM !== false) { |
2766 | 2766 | |
2767 | - $howManuOut = 8-(QR_FIND_FROM_RANDOM % 9); |
|
2768 | - for ($i = 0; $i < $howManuOut; $i++) { |
|
2769 | - $remPos = rand (0, count($checked_masks)-1); |
|
2767 | + $howManuOut = 8 - (QR_FIND_FROM_RANDOM % 9); |
|
2768 | + for ($i = 0; $i < $howManuOut; $i++) { |
|
2769 | + $remPos = rand(0, count($checked_masks) - 1); |
|
2770 | 2770 | unset($checked_masks[$remPos]); |
2771 | 2771 | $checked_masks = array_values($checked_masks); |
2772 | 2772 | } |
@@ -2775,18 +2775,18 @@ discard block |
||
2775 | 2775 | |
2776 | 2776 | $bestMask = $frame; |
2777 | 2777 | |
2778 | - foreach($checked_masks as $i) { |
|
2778 | + foreach ($checked_masks as $i) { |
|
2779 | 2779 | $mask = array_fill(0, $width, str_repeat("\0", $width)); |
2780 | 2780 | |
2781 | 2781 | $demerit = 0; |
2782 | 2782 | $blacks = 0; |
2783 | 2783 | $blacks = $this->makeMaskNo($i, $width, $frame, $mask); |
2784 | 2784 | $blacks += $this->writeFormatInformation($width, $mask, $i, $level); |
2785 | - $blacks = (int)(100 * $blacks / ($width * $width)); |
|
2786 | - $demerit = (int)((int)(abs($blacks - 50) / 5) * N4); |
|
2785 | + $blacks = (int) (100 * $blacks / ($width * $width)); |
|
2786 | + $demerit = (int) ((int) (abs($blacks - 50) / 5) * N4); |
|
2787 | 2787 | $demerit += $this->evaluateSymbol($width, $mask); |
2788 | 2788 | |
2789 | - if($demerit < $minDemerit) { |
|
2789 | + if ($demerit < $minDemerit) { |
|
2790 | 2790 | $minDemerit = $demerit; |
2791 | 2791 | $bestMask = $mask; |
2792 | 2792 | $bestMaskNum = $i; |
@@ -2866,10 +2866,10 @@ discard block |
||
2866 | 2866 | //---------------------------------------------------------------------- |
2867 | 2867 | public function __construct(QRinput $input) |
2868 | 2868 | { |
2869 | - $spec = array(0,0,0,0,0); |
|
2869 | + $spec = array(0, 0, 0, 0, 0); |
|
2870 | 2870 | |
2871 | 2871 | $this->datacode = $input->getByteStream(); |
2872 | - if(is_null($this->datacode)) { |
|
2872 | + if (is_null($this->datacode)) { |
|
2873 | 2873 | throw new Exception('null imput string'); |
2874 | 2874 | } |
2875 | 2875 | |
@@ -2883,7 +2883,7 @@ discard block |
||
2883 | 2883 | $this->blocks = QRspec::rsBlockNum($spec); |
2884 | 2884 | |
2885 | 2885 | $ret = $this->init($spec); |
2886 | - if($ret < 0) { |
|
2886 | + if ($ret < 0) { |
|
2887 | 2887 | throw new Exception('block alloc error'); |
2888 | 2888 | return null; |
2889 | 2889 | } |
@@ -2902,29 +2902,29 @@ discard block |
||
2902 | 2902 | $blockNo = 0; |
2903 | 2903 | $dataPos = 0; |
2904 | 2904 | $eccPos = 0; |
2905 | - for($i=0; $i<QRspec::rsBlockNum1($spec); $i++) { |
|
2906 | - $ecc = array_slice($this->ecccode,$eccPos); |
|
2907 | - $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs); |
|
2908 | - $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc); |
|
2905 | + for ($i = 0; $i < QRspec::rsBlockNum1($spec); $i++) { |
|
2906 | + $ecc = array_slice($this->ecccode, $eccPos); |
|
2907 | + $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs); |
|
2908 | + $this->ecccode = array_merge(array_slice($this->ecccode, 0, $eccPos), $ecc); |
|
2909 | 2909 | |
2910 | 2910 | $dataPos += $dl; |
2911 | 2911 | $eccPos += $el; |
2912 | 2912 | $blockNo++; |
2913 | 2913 | } |
2914 | 2914 | |
2915 | - if(QRspec::rsBlockNum2($spec) == 0) |
|
2915 | + if (QRspec::rsBlockNum2($spec) == 0) |
|
2916 | 2916 | return 0; |
2917 | 2917 | |
2918 | 2918 | $dl = QRspec::rsDataCodes2($spec); |
2919 | 2919 | $el = QRspec::rsEccCodes2($spec); |
2920 | 2920 | $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el); |
2921 | 2921 | |
2922 | - if($rs == null) return -1; |
|
2922 | + if ($rs == null) return -1; |
|
2923 | 2923 | |
2924 | - for($i=0; $i<QRspec::rsBlockNum2($spec); $i++) { |
|
2925 | - $ecc = array_slice($this->ecccode,$eccPos); |
|
2924 | + for ($i = 0; $i < QRspec::rsBlockNum2($spec); $i++) { |
|
2925 | + $ecc = array_slice($this->ecccode, $eccPos); |
|
2926 | 2926 | $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs); |
2927 | - $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc); |
|
2927 | + $this->ecccode = array_merge(array_slice($this->ecccode, 0, $eccPos), $ecc); |
|
2928 | 2928 | |
2929 | 2929 | $dataPos += $dl; |
2930 | 2930 | $eccPos += $el; |
@@ -2939,14 +2939,14 @@ discard block |
||
2939 | 2939 | { |
2940 | 2940 | $ret = 0; |
2941 | 2941 | |
2942 | - if($this->count < $this->dataLength) { |
|
2942 | + if ($this->count < $this->dataLength) { |
|
2943 | 2943 | $row = $this->count % $this->blocks; |
2944 | 2944 | $col = $this->count / $this->blocks; |
2945 | - if($col >= $this->rsblocks[0]->dataLength) { |
|
2945 | + if ($col >= $this->rsblocks[0]->dataLength) { |
|
2946 | 2946 | $row += $this->b1; |
2947 | 2947 | } |
2948 | 2948 | $ret = $this->rsblocks[$row]->data[$col]; |
2949 | - } else if($this->count < $this->dataLength + $this->eccLength) { |
|
2949 | + } else if ($this->count < $this->dataLength + $this->eccLength) { |
|
2950 | 2950 | $row = ($this->count - $this->dataLength) % $this->blocks; |
2951 | 2951 | $col = ($this->count - $this->dataLength) / $this->blocks; |
2952 | 2952 | $ret = $this->rsblocks[$row]->ecc[$col]; |
@@ -2970,10 +2970,10 @@ discard block |
||
2970 | 2970 | //---------------------------------------------------------------------- |
2971 | 2971 | public function encodeMask(QRinput $input, $mask) |
2972 | 2972 | { |
2973 | - if($input->getVersion() < 0 || $input->getVersion() > QRSPEC_VERSION_MAX) { |
|
2973 | + if ($input->getVersion() < 0 || $input->getVersion() > QRSPEC_VERSION_MAX) { |
|
2974 | 2974 | throw new Exception('wrong version'); |
2975 | 2975 | } |
2976 | - if($input->getErrorCorrectionLevel() > QR_ECLEVEL_H) { |
|
2976 | + if ($input->getErrorCorrectionLevel() > QR_ECLEVEL_H) { |
|
2977 | 2977 | throw new Exception('wrong level'); |
2978 | 2978 | } |
2979 | 2979 | |
@@ -2986,15 +2986,15 @@ discard block |
||
2986 | 2986 | $frame = QRspec::newFrame($version); |
2987 | 2987 | |
2988 | 2988 | $filler = new FrameFiller($width, $frame); |
2989 | - if(is_null($filler)) { |
|
2989 | + if (is_null($filler)) { |
|
2990 | 2990 | return null; |
2991 | 2991 | } |
2992 | 2992 | |
2993 | 2993 | // inteleaved data and ecc codes |
2994 | - for($i=0; $i<$raw->dataLength + $raw->eccLength; $i++) { |
|
2994 | + for ($i = 0; $i < $raw->dataLength + $raw->eccLength; $i++) { |
|
2995 | 2995 | $code = $raw->getCode(); |
2996 | 2996 | $bit = 0x80; |
2997 | - for($j=0; $j<8; $j++) { |
|
2997 | + for ($j = 0; $j < 8; $j++) { |
|
2998 | 2998 | $addr = $filler->next(); |
2999 | 2999 | $filler->setFrameAt($addr, 0x02 | (($bit & $code) != 0)); |
3000 | 3000 | $bit = $bit >> 1; |
@@ -3007,7 +3007,7 @@ discard block |
||
3007 | 3007 | |
3008 | 3008 | // remainder bits |
3009 | 3009 | $j = QRspec::getRemainder($version); |
3010 | - for($i=0; $i<$j; $i++) { |
|
3010 | + for ($i = 0; $i < $j; $i++) { |
|
3011 | 3011 | $addr = $filler->next(); |
3012 | 3012 | $filler->setFrameAt($addr, 0x02); |
3013 | 3013 | } |
@@ -3018,7 +3018,7 @@ discard block |
||
3018 | 3018 | |
3019 | 3019 | // masking |
3020 | 3020 | $maskObj = new QRmask(); |
3021 | - if($mask < 0) { |
|
3021 | + if ($mask < 0) { |
|
3022 | 3022 | |
3023 | 3023 | if (QR_FIND_BEST_MASK) { |
3024 | 3024 | $masked = $maskObj->mask($width, $frame, $input->getErrorCorrectionLevel()); |
@@ -3029,7 +3029,7 @@ discard block |
||
3029 | 3029 | $masked = $maskObj->makeMask($width, $frame, $mask, $input->getErrorCorrectionLevel()); |
3030 | 3030 | } |
3031 | 3031 | |
3032 | - if($masked == null) { |
|
3032 | + if ($masked == null) { |
|
3033 | 3033 | return null; |
3034 | 3034 | } |
3035 | 3035 | |
@@ -3051,16 +3051,16 @@ discard block |
||
3051 | 3051 | //---------------------------------------------------------------------- |
3052 | 3052 | public function encodeString8bit($string, $version, $level) |
3053 | 3053 | { |
3054 | - if(string == null) { |
|
3054 | + if (string == null) { |
|
3055 | 3055 | throw new Exception('empty string!'); |
3056 | 3056 | return null; |
3057 | 3057 | } |
3058 | 3058 | |
3059 | 3059 | $input = new QRinput($version, $level); |
3060 | - if($input == null) return null; |
|
3060 | + if ($input == null) return null; |
|
3061 | 3061 | |
3062 | 3062 | $ret = $input->append(QR_MODE_8, strlen($string), str_split($string)); |
3063 | - if($ret < 0) { |
|
3063 | + if ($ret < 0) { |
|
3064 | 3064 | unset($input); |
3065 | 3065 | return null; |
3066 | 3066 | } |
@@ -3071,16 +3071,16 @@ discard block |
||
3071 | 3071 | public function encodeString($string, $version, $level, $hint, $casesensitive) |
3072 | 3072 | { |
3073 | 3073 | |
3074 | - if($hint != QR_MODE_8 && $hint != QR_MODE_KANJI) { |
|
3074 | + if ($hint != QR_MODE_8 && $hint != QR_MODE_KANJI) { |
|
3075 | 3075 | throw new Exception('bad hint'); |
3076 | 3076 | return null; |
3077 | 3077 | } |
3078 | 3078 | |
3079 | 3079 | $input = new QRinput($version, $level); |
3080 | - if($input == null) return null; |
|
3080 | + if ($input == null) return null; |
|
3081 | 3081 | |
3082 | 3082 | $ret = QRsplit::splitStringToQRinput($string, $input, $hint, $casesensitive); |
3083 | - if($ret < 0) { |
|
3083 | + if ($ret < 0) { |
|
3084 | 3084 | return null; |
3085 | 3085 | } |
3086 | 3086 | |
@@ -3088,10 +3088,10 @@ discard block |
||
3088 | 3088 | } |
3089 | 3089 | |
3090 | 3090 | //---------------------------------------------------------------------- |
3091 | - public static function png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint=false) |
|
3091 | + public static function png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint = false) |
|
3092 | 3092 | { |
3093 | 3093 | $enc = QRencode::factory($level, $size, $margin); |
3094 | - return $enc->encodePNG($text, $outfile, $saveandprint=false); |
|
3094 | + return $enc->encodePNG($text, $outfile, $saveandprint = false); |
|
3095 | 3095 | } |
3096 | 3096 | |
3097 | 3097 | //---------------------------------------------------------------------- |
@@ -3148,7 +3148,7 @@ discard block |
||
3148 | 3148 | { |
3149 | 3149 | do { |
3150 | 3150 | |
3151 | - if($this->bit == -1) { |
|
3151 | + if ($this->bit == -1) { |
|
3152 | 3152 | $this->bit = 0; |
3153 | 3153 | return array('x'=>$this->x, 'y'=>$this->y); |
3154 | 3154 | } |
@@ -3157,7 +3157,7 @@ discard block |
||
3157 | 3157 | $y = $this->y; |
3158 | 3158 | $w = $this->width; |
3159 | 3159 | |
3160 | - if($this->bit == 0) { |
|
3160 | + if ($this->bit == 0) { |
|
3161 | 3161 | $x--; |
3162 | 3162 | $this->bit++; |
3163 | 3163 | } else { |
@@ -3166,33 +3166,33 @@ discard block |
||
3166 | 3166 | $this->bit--; |
3167 | 3167 | } |
3168 | 3168 | |
3169 | - if($this->dir < 0) { |
|
3170 | - if($y < 0) { |
|
3169 | + if ($this->dir < 0) { |
|
3170 | + if ($y < 0) { |
|
3171 | 3171 | $y = 0; |
3172 | 3172 | $x -= 2; |
3173 | 3173 | $this->dir = 1; |
3174 | - if($x == 6) { |
|
3174 | + if ($x == 6) { |
|
3175 | 3175 | $x--; |
3176 | 3176 | $y = 9; |
3177 | 3177 | } |
3178 | 3178 | } |
3179 | 3179 | } else { |
3180 | - if($y == $w) { |
|
3180 | + if ($y == $w) { |
|
3181 | 3181 | $y = $w - 1; |
3182 | 3182 | $x -= 2; |
3183 | 3183 | $this->dir = -1; |
3184 | - if($x == 6) { |
|
3184 | + if ($x == 6) { |
|
3185 | 3185 | $x--; |
3186 | 3186 | $y -= 8; |
3187 | 3187 | } |
3188 | 3188 | } |
3189 | 3189 | } |
3190 | - if($x < 0 || $y < 0) return null; |
|
3190 | + if ($x < 0 || $y < 0) return null; |
|
3191 | 3191 | |
3192 | 3192 | $this->x = $x; |
3193 | 3193 | $this->y = $y; |
3194 | 3194 | |
3195 | - } while(ord($this->frame[$y][$x]) & 0x80); |
|
3195 | + } while (ord($this->frame[$y][$x]) & 0x80); |
|
3196 | 3196 | |
3197 | 3197 | return array('x'=>$x, 'y'=>$y); |
3198 | 3198 | } |
@@ -3255,7 +3255,7 @@ discard block |
||
3255 | 3255 | { |
3256 | 3256 | $code = new QRcode(); |
3257 | 3257 | |
3258 | - if($this->eightbit) { |
|
3258 | + if ($this->eightbit) { |
|
3259 | 3259 | $code->encodeString8bit($intext, $this->version, $this->level); |
3260 | 3260 | } else { |
3261 | 3261 | $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive); |
@@ -3269,7 +3269,7 @@ discard block |
||
3269 | 3269 | { |
3270 | 3270 | $code = new QRcode(); |
3271 | 3271 | |
3272 | - if($this->eightbit) { |
|
3272 | + if ($this->eightbit) { |
|
3273 | 3273 | $code->encodeString8bit($intext, $this->version, $this->level); |
3274 | 3274 | } else { |
3275 | 3275 | $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive); |
@@ -3277,7 +3277,7 @@ discard block |
||
3277 | 3277 | |
3278 | 3278 | QRtools::markTime('after_encode'); |
3279 | 3279 | |
3280 | - if ($outfile!== false) { |
|
3280 | + if ($outfile !== false) { |
|
3281 | 3281 | file_put_contents($outfile, join("\n", QRtools::binarize($code->data))); |
3282 | 3282 | } else { |
3283 | 3283 | return QRtools::binarize($code->data); |
@@ -3285,7 +3285,7 @@ discard block |
||
3285 | 3285 | } |
3286 | 3286 | |
3287 | 3287 | //---------------------------------------------------------------------- |
3288 | - public function encodePNG($intext, $outfile = false,$saveandprint=false) |
|
3288 | + public function encodePNG($intext, $outfile = false, $saveandprint = false) |
|
3289 | 3289 | { |
3290 | 3290 | try { |
3291 | 3291 | |
@@ -3297,9 +3297,9 @@ discard block |
||
3297 | 3297 | if ($err != '') |
3298 | 3298 | QRtools::log($outfile, $err); |
3299 | 3299 | |
3300 | - $maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab)+2*$this->margin)); |
|
3300 | + $maxSize = (int) (QR_PNG_MAXIMUM_SIZE / (count($tab) + 2 * $this->margin)); |
|
3301 | 3301 | |
3302 | - QRimage::png($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin,$saveandprint); |
|
3302 | + QRimage::png($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin, $saveandprint); |
|
3303 | 3303 | |
3304 | 3304 | } catch (Exception $e) { |
3305 | 3305 |
@@ -176,8 +176,9 @@ discard block |
||
176 | 176 | { |
177 | 177 | $barcode_array = array(); |
178 | 178 | |
179 | - if (!is_array($mode)) |
|
180 | - $mode = explode(',', $mode); |
|
179 | + if (!is_array($mode)) { |
|
180 | + $mode = explode(',', $mode); |
|
181 | + } |
|
181 | 182 | |
182 | 183 | $eccLevel = 'L'; |
183 | 184 | |
@@ -194,8 +195,9 @@ discard block |
||
194 | 195 | |
195 | 196 | foreach ($qrTab as $line) { |
196 | 197 | $arrAdd = array(); |
197 | - foreach(str_split($line) as $char) |
|
198 | - $arrAdd[] = ($char=='1')?1:0; |
|
198 | + foreach(str_split($line) as $char) { |
|
199 | + $arrAdd[] = ($char=='1')?1:0; |
|
200 | + } |
|
199 | 201 | $barcode_array['bcode'][] = $arrAdd; |
200 | 202 | } |
201 | 203 | |
@@ -223,8 +225,9 @@ discard block |
||
223 | 225 | |
224 | 226 | $width = count($frame); |
225 | 227 | $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); |
226 | - for ($maskNo=0; $maskNo<8; $maskNo++) |
|
227 | - $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true); |
|
228 | + for ($maskNo=0; $maskNo<8; $maskNo++) { |
|
229 | + $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true); |
|
230 | + } |
|
228 | 231 | } |
229 | 232 | |
230 | 233 | QRtools::markTime('after_build_cache'); |
@@ -261,8 +264,9 @@ discard block |
||
261 | 264 | list($usec, $sec) = explode(" ", microtime()); |
262 | 265 | $time = ((float)$usec + (float)$sec); |
263 | 266 | |
264 | - if (!isset($GLOBALS['qr_time_bench'])) |
|
265 | - $GLOBALS['qr_time_bench'] = array(); |
|
267 | + if (!isset($GLOBALS['qr_time_bench'])) { |
|
268 | + $GLOBALS['qr_time_bench'] = array(); |
|
269 | + } |
|
266 | 270 | |
267 | 271 | $GLOBALS['qr_time_bench'][$markerId] = $time; |
268 | 272 | } |
@@ -427,8 +431,9 @@ discard block |
||
427 | 431 | |
428 | 432 | for($i=1; $i<= QRSPEC_VERSION_MAX; $i++) { |
429 | 433 | $words = self::$capacity[$i][QRCAP_WORDS] - self::$capacity[$i][QRCAP_EC][$level]; |
430 | - if($words >= $size) |
|
431 | - return $i; |
|
434 | + if($words >= $size) { |
|
435 | + return $i; |
|
436 | + } |
|
432 | 437 | } |
433 | 438 | |
434 | 439 | return -1; |
@@ -446,8 +451,9 @@ discard block |
||
446 | 451 | //---------------------------------------------------------------------- |
447 | 452 | public static function lengthIndicator($mode, $version) |
448 | 453 | { |
449 | - if ($mode == QR_MODE_STRUCTURE) |
|
450 | - return 0; |
|
454 | + if ($mode == QR_MODE_STRUCTURE) { |
|
455 | + return 0; |
|
456 | + } |
|
451 | 457 | |
452 | 458 | if ($version <= 9) { |
453 | 459 | $l = 0; |
@@ -463,8 +469,9 @@ discard block |
||
463 | 469 | //---------------------------------------------------------------------- |
464 | 470 | public static function maximumWords($mode, $version) |
465 | 471 | { |
466 | - if($mode == QR_MODE_STRUCTURE) |
|
467 | - return 3; |
|
472 | + if($mode == QR_MODE_STRUCTURE) { |
|
473 | + return 3; |
|
474 | + } |
|
468 | 475 | |
469 | 476 | if($version <= 9) { |
470 | 477 | $l = 0; |
@@ -610,8 +617,9 @@ discard block |
||
610 | 617 | //---------------------------------------------------------------------- |
611 | 618 | public static function putAlignmentPattern($version, &$frame, $width) |
612 | 619 | { |
613 | - if($version < 2) |
|
614 | - return; |
|
620 | + if($version < 2) { |
|
621 | + return; |
|
622 | + } |
|
615 | 623 | |
616 | 624 | $d = self::$alignmentPattern[$version][1] - self::$alignmentPattern[$version][0]; |
617 | 625 | if($d < 0) { |
@@ -663,8 +671,9 @@ discard block |
||
663 | 671 | //---------------------------------------------------------------------- |
664 | 672 | public static function getVersionPattern($version) |
665 | 673 | { |
666 | - if($version < 7 || $version > QRSPEC_VERSION_MAX) |
|
667 | - return 0; |
|
674 | + if($version < 7 || $version > QRSPEC_VERSION_MAX) { |
|
675 | + return 0; |
|
676 | + } |
|
668 | 677 | |
669 | 678 | return self::$versionPattern[$version -7]; |
670 | 679 | } |
@@ -681,11 +690,13 @@ discard block |
||
681 | 690 | |
682 | 691 | public static function getFormatInfo($mask, $level) |
683 | 692 | { |
684 | - if($mask < 0 || $mask > 7) |
|
685 | - return 0; |
|
693 | + if($mask < 0 || $mask > 7) { |
|
694 | + return 0; |
|
695 | + } |
|
686 | 696 | |
687 | - if($level < 0 || $level > 3) |
|
688 | - return 0; |
|
697 | + if($level < 0 || $level > 3) { |
|
698 | + return 0; |
|
699 | + } |
|
689 | 700 | |
690 | 701 | return self::$formatInfo[$level][$mask]; |
691 | 702 | } |
@@ -865,8 +876,9 @@ discard block |
||
865 | 876 | //---------------------------------------------------------------------- |
866 | 877 | public static function newFrame($version) |
867 | 878 | { |
868 | - if($version < 1 || $version > QRSPEC_VERSION_MAX) |
|
869 | - return null; |
|
879 | + if($version < 1 || $version > QRSPEC_VERSION_MAX) { |
|
880 | + return null; |
|
881 | + } |
|
870 | 882 | |
871 | 883 | if(!isset(self::$frames[$version])) { |
872 | 884 | |
@@ -884,8 +896,9 @@ discard block |
||
884 | 896 | } |
885 | 897 | } |
886 | 898 | |
887 | - if(is_null(self::$frames[$version])) |
|
888 | - return null; |
|
899 | + if(is_null(self::$frames[$version])) { |
|
900 | + return null; |
|
901 | + } |
|
889 | 902 | |
890 | 903 | return self::$frames[$version]; |
891 | 904 | } |
@@ -950,7 +963,7 @@ discard block |
||
950 | 963 | ImagePng($image, $filename); |
951 | 964 | header("Content-type: image/png"); |
952 | 965 | ImagePng($image); |
953 | - }else{ |
|
966 | + } else{ |
|
954 | 967 | ImagePng($image, $filename); |
955 | 968 | } |
956 | 969 | } |
@@ -1210,8 +1223,9 @@ discard block |
||
1210 | 1223 | { |
1211 | 1224 | $bits = 0; |
1212 | 1225 | |
1213 | - if($version == 0) |
|
1214 | - $version = 1; |
|
1226 | + if($version == 0) { |
|
1227 | + $version = 1; |
|
1228 | + } |
|
1215 | 1229 | |
1216 | 1230 | switch($this->mode) { |
1217 | 1231 | case QR_MODE_NUM: $bits = QRinput::estimateBitsModeNum($this->size); break; |
@@ -1270,8 +1284,9 @@ discard block |
||
1270 | 1284 | break; |
1271 | 1285 | } |
1272 | 1286 | |
1273 | - if($ret < 0) |
|
1274 | - return -1; |
|
1287 | + if($ret < 0) { |
|
1288 | + return -1; |
|
1289 | + } |
|
1275 | 1290 | } |
1276 | 1291 | |
1277 | 1292 | return $this->bstream->size(); |
@@ -1488,8 +1503,9 @@ discard block |
||
1488 | 1503 | //---------------------------------------------------------------------- |
1489 | 1504 | public static function checkModeKanji($size, $data) |
1490 | 1505 | { |
1491 | - if($size & 1) |
|
1492 | - return false; |
|
1506 | + if($size & 1) { |
|
1507 | + return false; |
|
1508 | + } |
|
1493 | 1509 | |
1494 | 1510 | for($i=0; $i<$size; $i+=2) { |
1495 | 1511 | $val = (ord($data[$i]) << 8) | ord($data[$i+1]); |
@@ -1509,8 +1525,9 @@ discard block |
||
1509 | 1525 | |
1510 | 1526 | public static function check($mode, $size, $data) |
1511 | 1527 | { |
1512 | - if($size <= 0) |
|
1513 | - return false; |
|
1528 | + if($size <= 0) { |
|
1529 | + return false; |
|
1530 | + } |
|
1514 | 1531 | |
1515 | 1532 | switch($mode) { |
1516 | 1533 | case QR_MODE_NUM: return self::checkModeNum($size, $data); break; |
@@ -1575,8 +1592,9 @@ discard block |
||
1575 | 1592 | $chunks = (int)($payload / 11); |
1576 | 1593 | $remain = $payload - $chunks * 11; |
1577 | 1594 | $size = $chunks * 2; |
1578 | - if($remain >= 6) |
|
1579 | - $size++; |
|
1595 | + if($remain >= 6) { |
|
1596 | + $size++; |
|
1597 | + } |
|
1580 | 1598 | break; |
1581 | 1599 | case QR_MODE_8: |
1582 | 1600 | $size = (int)($payload / 8); |
@@ -1593,8 +1611,12 @@ discard block |
||
1593 | 1611 | } |
1594 | 1612 | |
1595 | 1613 | $maxsize = QRspec::maximumWords($mode, $version); |
1596 | - if($size < 0) $size = 0; |
|
1597 | - if($size > $maxsize) $size = $maxsize; |
|
1614 | + if($size < 0) { |
|
1615 | + $size = 0; |
|
1616 | + } |
|
1617 | + if($size > $maxsize) { |
|
1618 | + $size = $maxsize; |
|
1619 | + } |
|
1598 | 1620 | |
1599 | 1621 | return $size; |
1600 | 1622 | } |
@@ -1607,8 +1629,9 @@ discard block |
||
1607 | 1629 | foreach($this->items as $item) { |
1608 | 1630 | $bits = $item->encodeBitStream($this->version); |
1609 | 1631 | |
1610 | - if($bits < 0) |
|
1611 | - return -1; |
|
1632 | + if($bits < 0) { |
|
1633 | + return -1; |
|
1634 | + } |
|
1612 | 1635 | |
1613 | 1636 | $total += $bits; |
1614 | 1637 | } |
@@ -1627,8 +1650,9 @@ discard block |
||
1627 | 1650 | for(;;) { |
1628 | 1651 | $bits = $this->createBitStream(); |
1629 | 1652 | |
1630 | - if($bits < 0) |
|
1631 | - return -1; |
|
1653 | + if($bits < 0) { |
|
1654 | + return -1; |
|
1655 | + } |
|
1632 | 1656 | |
1633 | 1657 | $ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); |
1634 | 1658 | if($ver < 0) { |
@@ -1665,8 +1689,9 @@ discard block |
||
1665 | 1689 | $padding = new QRbitstream(); |
1666 | 1690 | $ret = $padding->appendNum($words * 8 - $bits + 4, 0); |
1667 | 1691 | |
1668 | - if($ret < 0) |
|
1669 | - return $ret; |
|
1692 | + if($ret < 0) { |
|
1693 | + return $ret; |
|
1694 | + } |
|
1670 | 1695 | |
1671 | 1696 | $padlen = $maxwords - $words; |
1672 | 1697 | |
@@ -1679,8 +1704,9 @@ discard block |
||
1679 | 1704 | |
1680 | 1705 | $ret = $padding->appendBytes($padlen, $padbuf); |
1681 | 1706 | |
1682 | - if($ret < 0) |
|
1683 | - return $ret; |
|
1707 | + if($ret < 0) { |
|
1708 | + return $ret; |
|
1709 | + } |
|
1684 | 1710 | |
1685 | 1711 | } |
1686 | 1712 | |
@@ -1857,13 +1883,15 @@ discard block |
||
1857 | 1883 | //---------------------------------------------------------------------- |
1858 | 1884 | public function appendNum($bits, $num) |
1859 | 1885 | { |
1860 | - if ($bits == 0) |
|
1861 | - return 0; |
|
1886 | + if ($bits == 0) { |
|
1887 | + return 0; |
|
1888 | + } |
|
1862 | 1889 | |
1863 | 1890 | $b = QRbitstream::newFromNum($bits, $num); |
1864 | 1891 | |
1865 | - if(is_null($b)) |
|
1866 | - return -1; |
|
1892 | + if(is_null($b)) { |
|
1893 | + return -1; |
|
1894 | + } |
|
1867 | 1895 | |
1868 | 1896 | $ret = $this->append($b); |
1869 | 1897 | unset($b); |
@@ -1874,13 +1902,15 @@ discard block |
||
1874 | 1902 | //---------------------------------------------------------------------- |
1875 | 1903 | public function appendBytes($size, $data) |
1876 | 1904 | { |
1877 | - if ($size == 0) |
|
1878 | - return 0; |
|
1905 | + if ($size == 0) { |
|
1906 | + return 0; |
|
1907 | + } |
|
1879 | 1908 | |
1880 | 1909 | $b = QRbitstream::newFromBytes($size, $data); |
1881 | 1910 | |
1882 | - if(is_null($b)) |
|
1883 | - return -1; |
|
1911 | + if(is_null($b)) { |
|
1912 | + return -1; |
|
1913 | + } |
|
1884 | 1914 | |
1885 | 1915 | $ret = $this->append($b); |
1886 | 1916 | unset($b); |
@@ -1984,8 +2014,9 @@ discard block |
||
1984 | 2014 | //---------------------------------------------------------------------- |
1985 | 2015 | public static function isdigitat($str, $pos) |
1986 | 2016 | { |
1987 | - if ($pos >= strlen($str)) |
|
1988 | - return false; |
|
2017 | + if ($pos >= strlen($str)) { |
|
2018 | + return false; |
|
2019 | + } |
|
1989 | 2020 | |
1990 | 2021 | return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9'))); |
1991 | 2022 | } |
@@ -1993,8 +2024,9 @@ discard block |
||
1993 | 2024 | //---------------------------------------------------------------------- |
1994 | 2025 | public static function isalnumat($str, $pos) |
1995 | 2026 | { |
1996 | - if ($pos >= strlen($str)) |
|
1997 | - return false; |
|
2027 | + if ($pos >= strlen($str)) { |
|
2028 | + return false; |
|
2029 | + } |
|
1998 | 2030 | |
1999 | 2031 | return (QRinput::lookAnTable(ord($str[$pos])) >= 0); |
2000 | 2032 | } |
@@ -2002,8 +2034,9 @@ discard block |
||
2002 | 2034 | //---------------------------------------------------------------------- |
2003 | 2035 | public function identifyMode($pos) |
2004 | 2036 | { |
2005 | - if ($pos >= strlen($this->dataStr)) |
|
2006 | - return QR_MODE_NUL; |
|
2037 | + if ($pos >= strlen($this->dataStr)) { |
|
2038 | + return QR_MODE_NUL; |
|
2039 | + } |
|
2007 | 2040 | |
2008 | 2041 | $c = $this->dataStr[$pos]; |
2009 | 2042 | |
@@ -2057,8 +2090,9 @@ discard block |
||
2057 | 2090 | } |
2058 | 2091 | |
2059 | 2092 | $ret = $this->input->append(QR_MODE_NUM, $run, str_split($this->dataStr)); |
2060 | - if($ret < 0) |
|
2061 | - return -1; |
|
2093 | + if($ret < 0) { |
|
2094 | + return -1; |
|
2095 | + } |
|
2062 | 2096 | |
2063 | 2097 | return $run; |
2064 | 2098 | } |
@@ -2104,8 +2138,9 @@ discard block |
||
2104 | 2138 | } |
2105 | 2139 | |
2106 | 2140 | $ret = $this->input->append(QR_MODE_AN, $run, str_split($this->dataStr)); |
2107 | - if($ret < 0) |
|
2108 | - return -1; |
|
2141 | + if($ret < 0) { |
|
2142 | + return -1; |
|
2143 | + } |
|
2109 | 2144 | |
2110 | 2145 | return $run; |
2111 | 2146 | } |
@@ -2120,8 +2155,9 @@ discard block |
||
2120 | 2155 | } |
2121 | 2156 | |
2122 | 2157 | $ret = $this->input->append(QR_MODE_KANJI, $p, str_split($this->dataStr)); |
2123 | - if($ret < 0) |
|
2124 | - return -1; |
|
2158 | + if($ret < 0) { |
|
2159 | + return -1; |
|
2160 | + } |
|
2125 | 2161 | |
2126 | 2162 | return $run; |
2127 | 2163 | } |
@@ -2175,8 +2211,9 @@ discard block |
||
2175 | 2211 | $run = $p; |
2176 | 2212 | $ret = $this->input->append(QR_MODE_8, $run, str_split($this->dataStr)); |
2177 | 2213 | |
2178 | - if($ret < 0) |
|
2179 | - return -1; |
|
2214 | + if($ret < 0) { |
|
2215 | + return -1; |
|
2216 | + } |
|
2180 | 2217 | |
2181 | 2218 | return $run; |
2182 | 2219 | } |
@@ -2186,8 +2223,9 @@ discard block |
||
2186 | 2223 | { |
2187 | 2224 | while (strlen($this->dataStr) > 0) |
2188 | 2225 | { |
2189 | - if($this->dataStr == '') |
|
2190 | - return 0; |
|
2226 | + if($this->dataStr == '') { |
|
2227 | + return 0; |
|
2228 | + } |
|
2191 | 2229 | |
2192 | 2230 | $mode = $this->identifyMode(0); |
2193 | 2231 | |
@@ -2195,16 +2233,22 @@ discard block |
||
2195 | 2233 | case QR_MODE_NUM: $length = $this->eatNum(); break; |
2196 | 2234 | case QR_MODE_AN: $length = $this->eatAn(); break; |
2197 | 2235 | case QR_MODE_KANJI: |
2198 | - if ($this->modeHint == QR_MODE_KANJI) |
|
2199 | - $length = $this->eatKanji(); |
|
2200 | - else $length = $this->eat8(); |
|
2236 | + if ($this->modeHint == QR_MODE_KANJI) { |
|
2237 | + $length = $this->eatKanji(); |
|
2238 | + } else { |
|
2239 | + $length = $this->eat8(); |
|
2240 | + } |
|
2201 | 2241 | break; |
2202 | 2242 | default: $length = $this->eat8(); break; |
2203 | 2243 | |
2204 | 2244 | } |
2205 | 2245 | |
2206 | - if($length == 0) return 0; |
|
2207 | - if($length < 0) return -1; |
|
2246 | + if($length == 0) { |
|
2247 | + return 0; |
|
2248 | + } |
|
2249 | + if($length < 0) { |
|
2250 | + return -1; |
|
2251 | + } |
|
2208 | 2252 | |
2209 | 2253 | $this->dataStr = substr($this->dataStr, $length); |
2210 | 2254 | } |
@@ -2240,8 +2284,9 @@ discard block |
||
2240 | 2284 | |
2241 | 2285 | $split = new QRsplit($string, $input, $modeHint); |
2242 | 2286 | |
2243 | - if(!$casesensitive) |
|
2244 | - $split->toUpper(); |
|
2287 | + if(!$casesensitive) { |
|
2288 | + $split->toUpper(); |
|
2289 | + } |
|
2245 | 2290 | |
2246 | 2291 | return $split->splitString(); |
2247 | 2292 | } |
@@ -2318,11 +2363,23 @@ discard block |
||
2318 | 2363 | $rs = null; |
2319 | 2364 | |
2320 | 2365 | // Check parameter ranges |
2321 | - if($symsize < 0 || $symsize > 8) return $rs; |
|
2322 | - if($fcr < 0 || $fcr >= (1<<$symsize)) return $rs; |
|
2323 | - if($prim <= 0 || $prim >= (1<<$symsize)) return $rs; |
|
2324 | - if($nroots < 0 || $nroots >= (1<<$symsize)) return $rs; // Can't have more roots than symbol values! |
|
2325 | - if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) return $rs; // Too much padding |
|
2366 | + if($symsize < 0 || $symsize > 8) { |
|
2367 | + return $rs; |
|
2368 | + } |
|
2369 | + if($fcr < 0 || $fcr >= (1<<$symsize)) { |
|
2370 | + return $rs; |
|
2371 | + } |
|
2372 | + if($prim <= 0 || $prim >= (1<<$symsize)) { |
|
2373 | + return $rs; |
|
2374 | + } |
|
2375 | + if($nroots < 0 || $nroots >= (1<<$symsize)) { |
|
2376 | + return $rs; |
|
2377 | + } |
|
2378 | + // Can't have more roots than symbol values! |
|
2379 | + if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) { |
|
2380 | + return $rs; |
|
2381 | + } |
|
2382 | + // Too much padding |
|
2326 | 2383 | |
2327 | 2384 | $rs = new QRrsItem(); |
2328 | 2385 | $rs->mm = $symsize; |
@@ -2388,8 +2445,9 @@ discard block |
||
2388 | 2445 | } |
2389 | 2446 | |
2390 | 2447 | // convert rs->genpoly[] to index form for quicker encoding |
2391 | - for ($i = 0; $i <= $nroots; $i++) |
|
2392 | - $rs->genpoly[$i] = $rs->index_of[$rs->genpoly[$i]]; |
|
2448 | + for ($i = 0; $i <= $nroots; $i++) { |
|
2449 | + $rs->genpoly[$i] = $rs->index_of[$rs->genpoly[$i]]; |
|
2450 | + } |
|
2393 | 2451 | |
2394 | 2452 | return $rs; |
2395 | 2453 | } |
@@ -2447,12 +2505,24 @@ discard block |
||
2447 | 2505 | public static function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) |
2448 | 2506 | { |
2449 | 2507 | foreach(self::$items as $rs) { |
2450 | - if($rs->pad != $pad) continue; |
|
2451 | - if($rs->nroots != $nroots) continue; |
|
2452 | - if($rs->mm != $symsize) continue; |
|
2453 | - if($rs->gfpoly != $gfpoly) continue; |
|
2454 | - if($rs->fcr != $fcr) continue; |
|
2455 | - if($rs->prim != $prim) continue; |
|
2508 | + if($rs->pad != $pad) { |
|
2509 | + continue; |
|
2510 | + } |
|
2511 | + if($rs->nroots != $nroots) { |
|
2512 | + continue; |
|
2513 | + } |
|
2514 | + if($rs->mm != $symsize) { |
|
2515 | + continue; |
|
2516 | + } |
|
2517 | + if($rs->gfpoly != $gfpoly) { |
|
2518 | + continue; |
|
2519 | + } |
|
2520 | + if($rs->fcr != $fcr) { |
|
2521 | + continue; |
|
2522 | + } |
|
2523 | + if($rs->prim != $prim) { |
|
2524 | + continue; |
|
2525 | + } |
|
2456 | 2526 | |
2457 | 2527 | return $rs; |
2458 | 2528 | } |
@@ -2591,8 +2661,9 @@ discard block |
||
2591 | 2661 | { |
2592 | 2662 | $codeArr = array(); |
2593 | 2663 | |
2594 | - foreach ($bitFrame as $line) |
|
2595 | - $codeArr[] = join('', $line); |
|
2664 | + foreach ($bitFrame as $line) { |
|
2665 | + $codeArr[] = join('', $line); |
|
2666 | + } |
|
2596 | 2667 | |
2597 | 2668 | return gzcompress(join("\n", $codeArr), 9); |
2598 | 2669 | } |
@@ -2603,8 +2674,9 @@ discard block |
||
2603 | 2674 | $codeArr = array(); |
2604 | 2675 | |
2605 | 2676 | $codeLines = explode("\n", gzuncompress($code)); |
2606 | - foreach ($codeLines as $line) |
|
2607 | - $codeArr[] = str_split($line); |
|
2677 | + foreach ($codeLines as $line) { |
|
2678 | + $codeArr[] = str_split($line); |
|
2679 | + } |
|
2608 | 2680 | |
2609 | 2681 | return $codeArr; |
2610 | 2682 | } |
@@ -2622,16 +2694,18 @@ discard block |
||
2622 | 2694 | $bitMask = self::unserial(file_get_contents($fileName)); |
2623 | 2695 | } else { |
2624 | 2696 | $bitMask = $this->generateMaskNo($maskNo, $width, $s); |
2625 | - if (!file_exists(QR_CACHE_DIR.'mask_'.$maskNo)) |
|
2626 | - mkdir(QR_CACHE_DIR.'mask_'.$maskNo); |
|
2697 | + if (!file_exists(QR_CACHE_DIR.'mask_'.$maskNo)) { |
|
2698 | + mkdir(QR_CACHE_DIR.'mask_'.$maskNo); |
|
2699 | + } |
|
2627 | 2700 | file_put_contents($fileName, self::serial($bitMask)); |
2628 | 2701 | } |
2629 | 2702 | } else { |
2630 | 2703 | $bitMask = $this->generateMaskNo($maskNo, $width, $s); |
2631 | 2704 | } |
2632 | 2705 | |
2633 | - if ($maskGenOnly) |
|
2634 | - return; |
|
2706 | + if ($maskGenOnly) { |
|
2707 | + return; |
|
2708 | + } |
|
2635 | 2709 | |
2636 | 2710 | $d = $s; |
2637 | 2711 | |
@@ -2698,8 +2772,9 @@ discard block |
||
2698 | 2772 | |
2699 | 2773 | $frameY = $frame[$y]; |
2700 | 2774 | |
2701 | - if ($y>0) |
|
2702 | - $frameYM = $frame[$y-1]; |
|
2775 | + if ($y>0) { |
|
2776 | + $frameYM = $frame[$y-1]; |
|
2777 | + } |
|
2703 | 2778 | |
2704 | 2779 | for($x=0; $x<$width; $x++) { |
2705 | 2780 | if(($x > 0) && ($y > 0)) { |
@@ -2912,14 +2987,17 @@ discard block |
||
2912 | 2987 | $blockNo++; |
2913 | 2988 | } |
2914 | 2989 | |
2915 | - if(QRspec::rsBlockNum2($spec) == 0) |
|
2916 | - return 0; |
|
2990 | + if(QRspec::rsBlockNum2($spec) == 0) { |
|
2991 | + return 0; |
|
2992 | + } |
|
2917 | 2993 | |
2918 | 2994 | $dl = QRspec::rsDataCodes2($spec); |
2919 | 2995 | $el = QRspec::rsEccCodes2($spec); |
2920 | 2996 | $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el); |
2921 | 2997 | |
2922 | - if($rs == null) return -1; |
|
2998 | + if($rs == null) { |
|
2999 | + return -1; |
|
3000 | + } |
|
2923 | 3001 | |
2924 | 3002 | for($i=0; $i<QRspec::rsBlockNum2($spec); $i++) { |
2925 | 3003 | $ecc = array_slice($this->ecccode,$eccPos); |
@@ -3057,7 +3135,9 @@ discard block |
||
3057 | 3135 | } |
3058 | 3136 | |
3059 | 3137 | $input = new QRinput($version, $level); |
3060 | - if($input == null) return null; |
|
3138 | + if($input == null) { |
|
3139 | + return null; |
|
3140 | + } |
|
3061 | 3141 | |
3062 | 3142 | $ret = $input->append(QR_MODE_8, strlen($string), str_split($string)); |
3063 | 3143 | if($ret < 0) { |
@@ -3077,7 +3157,9 @@ discard block |
||
3077 | 3157 | } |
3078 | 3158 | |
3079 | 3159 | $input = new QRinput($version, $level); |
3080 | - if($input == null) return null; |
|
3160 | + if($input == null) { |
|
3161 | + return null; |
|
3162 | + } |
|
3081 | 3163 | |
3082 | 3164 | $ret = QRsplit::splitStringToQRinput($string, $input, $hint, $casesensitive); |
3083 | 3165 | if($ret < 0) { |
@@ -3187,7 +3269,9 @@ discard block |
||
3187 | 3269 | } |
3188 | 3270 | } |
3189 | 3271 | } |
3190 | - if($x < 0 || $y < 0) return null; |
|
3272 | + if($x < 0 || $y < 0) { |
|
3273 | + return null; |
|
3274 | + } |
|
3191 | 3275 | |
3192 | 3276 | $this->x = $x; |
3193 | 3277 | $this->y = $y; |
@@ -3294,8 +3378,9 @@ discard block |
||
3294 | 3378 | $err = ob_get_contents(); |
3295 | 3379 | ob_end_clean(); |
3296 | 3380 | |
3297 | - if ($err != '') |
|
3298 | - QRtools::log($outfile, $err); |
|
3381 | + if ($err != '') { |
|
3382 | + QRtools::log($outfile, $err); |
|
3383 | + } |
|
3299 | 3384 | |
3300 | 3385 | $maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab)+2*$this->margin)); |
3301 | 3386 |
@@ -34,75 +34,75 @@ discard block |
||
34 | 34 | * that you don't want to keep in memory) |
35 | 35 | */ |
36 | 36 | class gettext_reader { |
37 | - //public: |
|
38 | - var $error = 0; // public variable that holds error code (0 if no error) |
|
39 | - |
|
40 | - //private: |
|
41 | - var $BYTEORDER = 0; // 0: low endian, 1: big endian |
|
42 | - var $STREAM = null; |
|
43 | - var $short_circuit = false; |
|
44 | - var $enable_cache = false; |
|
45 | - var $originals = null; // offset of original table |
|
46 | - var $translations = null; // offset of translation table |
|
47 | - var $pluralheader = null; // cache header field for plural forms |
|
48 | - var $total = 0; // total string count |
|
49 | - var $table_originals = null; // table for original strings (offsets) |
|
50 | - var $table_translations = null; // table for translated strings (offsets) |
|
51 | - var $cache_translations = null; // original -> translation mapping |
|
52 | - |
|
53 | - |
|
54 | - /* Methods */ |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * Reads a 32bit Integer from the Stream |
|
59 | - * |
|
60 | - * @access private |
|
61 | - * @return Integer from the Stream |
|
62 | - */ |
|
63 | - function readint() { |
|
64 | - if ($this->BYTEORDER == 0) { |
|
37 | + //public: |
|
38 | + var $error = 0; // public variable that holds error code (0 if no error) |
|
39 | + |
|
40 | + //private: |
|
41 | + var $BYTEORDER = 0; // 0: low endian, 1: big endian |
|
42 | + var $STREAM = null; |
|
43 | + var $short_circuit = false; |
|
44 | + var $enable_cache = false; |
|
45 | + var $originals = null; // offset of original table |
|
46 | + var $translations = null; // offset of translation table |
|
47 | + var $pluralheader = null; // cache header field for plural forms |
|
48 | + var $total = 0; // total string count |
|
49 | + var $table_originals = null; // table for original strings (offsets) |
|
50 | + var $table_translations = null; // table for translated strings (offsets) |
|
51 | + var $cache_translations = null; // original -> translation mapping |
|
52 | + |
|
53 | + |
|
54 | + /* Methods */ |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * Reads a 32bit Integer from the Stream |
|
59 | + * |
|
60 | + * @access private |
|
61 | + * @return Integer from the Stream |
|
62 | + */ |
|
63 | + function readint() { |
|
64 | + if ($this->BYTEORDER == 0) { |
|
65 | 65 | // low endian |
66 | 66 | $input=unpack('V', $this->STREAM->read(4)); |
67 | 67 | return array_shift($input); |
68 | - } else { |
|
68 | + } else { |
|
69 | 69 | // big endian |
70 | 70 | $input=unpack('N', $this->STREAM->read(4)); |
71 | 71 | return array_shift($input); |
72 | - } |
|
72 | + } |
|
73 | 73 | } |
74 | 74 | |
75 | - function read($bytes) { |
|
75 | + function read($bytes) { |
|
76 | 76 | return $this->STREAM->read($bytes); |
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * Reads an array of Integers from the Stream |
|
81 | - * |
|
82 | - * @param int count How many elements should be read |
|
83 | - * @return Array of Integers |
|
84 | - */ |
|
85 | - function readintarray($count) { |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * Reads an array of Integers from the Stream |
|
81 | + * |
|
82 | + * @param int count How many elements should be read |
|
83 | + * @return Array of Integers |
|
84 | + */ |
|
85 | + function readintarray($count) { |
|
86 | 86 | if ($this->BYTEORDER == 0) { |
87 | 87 | // low endian |
88 | 88 | return unpack('V'.$count, $this->STREAM->read(4 * $count)); |
89 | - } else { |
|
89 | + } else { |
|
90 | 90 | // big endian |
91 | 91 | return unpack('N'.$count, $this->STREAM->read(4 * $count)); |
92 | - } |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Constructor |
|
97 | - * |
|
98 | - * @param object Reader the StreamReader object |
|
99 | - * @param boolean enable_cache Enable or disable caching of strings (default on) |
|
100 | - */ |
|
101 | - function __construct($Reader, $enable_cache = true) { |
|
92 | + } |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Constructor |
|
97 | + * |
|
98 | + * @param object Reader the StreamReader object |
|
99 | + * @param boolean enable_cache Enable or disable caching of strings (default on) |
|
100 | + */ |
|
101 | + function __construct($Reader, $enable_cache = true) { |
|
102 | 102 | // If there isn't a StreamReader, turn on short circuit mode. |
103 | 103 | if (! $Reader || isset($Reader->error) ) { |
104 | - $this->short_circuit = true; |
|
105 | - return; |
|
104 | + $this->short_circuit = true; |
|
105 | + return; |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | // Caching can be turned off |
@@ -114,12 +114,12 @@ discard block |
||
114 | 114 | $this->STREAM = $Reader; |
115 | 115 | $magic = $this->read(4); |
116 | 116 | if ($magic == $MAGIC1) { |
117 | - $this->BYTEORDER = 1; |
|
117 | + $this->BYTEORDER = 1; |
|
118 | 118 | } elseif ($magic == $MAGIC2) { |
119 | - $this->BYTEORDER = 0; |
|
119 | + $this->BYTEORDER = 0; |
|
120 | 120 | } else { |
121 | - $this->error = 1; // not MO file |
|
122 | - return false; |
|
121 | + $this->error = 1; // not MO file |
|
122 | + return false; |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | // FIXME: Do we care about revision? We should. |
@@ -128,154 +128,154 @@ discard block |
||
128 | 128 | $this->total = $this->readint(); |
129 | 129 | $this->originals = $this->readint(); |
130 | 130 | $this->translations = $this->readint(); |
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Loads the translation tables from the MO file into the cache |
|
135 | - * If caching is enabled, also loads all strings into a cache |
|
136 | - * to speed up translation lookups |
|
137 | - * |
|
138 | - * @access private |
|
139 | - */ |
|
140 | - function load_tables() { |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Loads the translation tables from the MO file into the cache |
|
135 | + * If caching is enabled, also loads all strings into a cache |
|
136 | + * to speed up translation lookups |
|
137 | + * |
|
138 | + * @access private |
|
139 | + */ |
|
140 | + function load_tables() { |
|
141 | 141 | if (is_array($this->cache_translations) && |
142 | 142 | is_array($this->table_originals) && |
143 | 143 | is_array($this->table_translations)) |
144 | - return; |
|
144 | + return; |
|
145 | 145 | |
146 | 146 | /* get original and translations tables */ |
147 | 147 | if (!is_array($this->table_originals)) { |
148 | - $this->STREAM->seekto($this->originals); |
|
149 | - $this->table_originals = $this->readintarray($this->total * 2); |
|
148 | + $this->STREAM->seekto($this->originals); |
|
149 | + $this->table_originals = $this->readintarray($this->total * 2); |
|
150 | 150 | } |
151 | 151 | if (!is_array($this->table_translations)) { |
152 | - $this->STREAM->seekto($this->translations); |
|
153 | - $this->table_translations = $this->readintarray($this->total * 2); |
|
152 | + $this->STREAM->seekto($this->translations); |
|
153 | + $this->table_translations = $this->readintarray($this->total * 2); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | if ($this->enable_cache) { |
157 | - $this->cache_translations = array (); |
|
158 | - /* read all strings in the cache */ |
|
159 | - for ($i = 0; $i < $this->total; $i++) { |
|
157 | + $this->cache_translations = array (); |
|
158 | + /* read all strings in the cache */ |
|
159 | + for ($i = 0; $i < $this->total; $i++) { |
|
160 | 160 | $this->STREAM->seekto($this->table_originals[$i * 2 + 2]); |
161 | 161 | $original = $this->STREAM->read($this->table_originals[$i * 2 + 1]); |
162 | 162 | $this->STREAM->seekto($this->table_translations[$i * 2 + 2]); |
163 | 163 | $translation = $this->STREAM->read($this->table_translations[$i * 2 + 1]); |
164 | 164 | $this->cache_translations[$original] = $translation; |
165 | - } |
|
165 | + } |
|
166 | + } |
|
166 | 167 | } |
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Returns a string from the "originals" table |
|
171 | - * |
|
172 | - * @access private |
|
173 | - * @param int num Offset number of original string |
|
174 | - * @return string Requested string if found, otherwise '' |
|
175 | - */ |
|
176 | - function get_original_string($num) { |
|
168 | + |
|
169 | + /** |
|
170 | + * Returns a string from the "originals" table |
|
171 | + * |
|
172 | + * @access private |
|
173 | + * @param int num Offset number of original string |
|
174 | + * @return string Requested string if found, otherwise '' |
|
175 | + */ |
|
176 | + function get_original_string($num) { |
|
177 | 177 | $length = $this->table_originals[$num * 2 + 1]; |
178 | 178 | $offset = $this->table_originals[$num * 2 + 2]; |
179 | 179 | if (! $length) |
180 | - return ''; |
|
180 | + return ''; |
|
181 | 181 | $this->STREAM->seekto($offset); |
182 | 182 | $data = $this->STREAM->read($length); |
183 | 183 | return (string)$data; |
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Returns a string from the "translations" table |
|
188 | - * |
|
189 | - * @access private |
|
190 | - * @param int num Offset number of original string |
|
191 | - * @return string Requested string if found, otherwise '' |
|
192 | - */ |
|
193 | - function get_translation_string($num) { |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Returns a string from the "translations" table |
|
188 | + * |
|
189 | + * @access private |
|
190 | + * @param int num Offset number of original string |
|
191 | + * @return string Requested string if found, otherwise '' |
|
192 | + */ |
|
193 | + function get_translation_string($num) { |
|
194 | 194 | $length = $this->table_translations[$num * 2 + 1]; |
195 | 195 | $offset = $this->table_translations[$num * 2 + 2]; |
196 | 196 | if (! $length) |
197 | - return ''; |
|
197 | + return ''; |
|
198 | 198 | $this->STREAM->seekto($offset); |
199 | 199 | $data = $this->STREAM->read($length); |
200 | 200 | return (string)$data; |
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * Binary search for string |
|
205 | - * |
|
206 | - * @access private |
|
207 | - * @param string string |
|
208 | - * @param int start (internally used in recursive function) |
|
209 | - * @param int end (internally used in recursive function) |
|
210 | - * @return int string number (offset in originals table) |
|
211 | - */ |
|
212 | - function find_string($string, $start = -1, $end = -1) { |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * Binary search for string |
|
205 | + * |
|
206 | + * @access private |
|
207 | + * @param string string |
|
208 | + * @param int start (internally used in recursive function) |
|
209 | + * @param int end (internally used in recursive function) |
|
210 | + * @return int string number (offset in originals table) |
|
211 | + */ |
|
212 | + function find_string($string, $start = -1, $end = -1) { |
|
213 | 213 | if (($start == -1) or ($end == -1)) { |
214 | - // find_string is called with only one parameter, set start end end |
|
215 | - $start = 0; |
|
216 | - $end = $this->total; |
|
214 | + // find_string is called with only one parameter, set start end end |
|
215 | + $start = 0; |
|
216 | + $end = $this->total; |
|
217 | 217 | } |
218 | 218 | if (abs($start - $end) <= 1) { |
219 | - // We're done, now we either found the string, or it doesn't exist |
|
220 | - $txt = $this->get_original_string($start); |
|
221 | - if ($string == $txt) |
|
219 | + // We're done, now we either found the string, or it doesn't exist |
|
220 | + $txt = $this->get_original_string($start); |
|
221 | + if ($string == $txt) |
|
222 | 222 | return $start; |
223 | - else |
|
223 | + else |
|
224 | 224 | return -1; |
225 | 225 | } else if ($start > $end) { |
226 | - // start > end -> turn around and start over |
|
227 | - return $this->find_string($string, $end, $start); |
|
226 | + // start > end -> turn around and start over |
|
227 | + return $this->find_string($string, $end, $start); |
|
228 | 228 | } else { |
229 | - // Divide table in two parts |
|
230 | - $half = (int)(($start + $end) / 2); |
|
231 | - $cmp = strcmp($string, $this->get_original_string($half)); |
|
232 | - if ($cmp == 0) |
|
229 | + // Divide table in two parts |
|
230 | + $half = (int)(($start + $end) / 2); |
|
231 | + $cmp = strcmp($string, $this->get_original_string($half)); |
|
232 | + if ($cmp == 0) |
|
233 | 233 | // string is exactly in the middle => return it |
234 | 234 | return $half; |
235 | - else if ($cmp < 0) |
|
235 | + else if ($cmp < 0) |
|
236 | 236 | // The string is in the upper half |
237 | 237 | return $this->find_string($string, $start, $half); |
238 | - else |
|
238 | + else |
|
239 | 239 | // The string is in the lower half |
240 | 240 | return $this->find_string($string, $half, $end); |
241 | 241 | } |
242 | - } |
|
243 | - |
|
244 | - /** |
|
245 | - * Translates a string |
|
246 | - * |
|
247 | - * @access public |
|
248 | - * @param string string to be translated |
|
249 | - * @return string translated string (or original, if not found) |
|
250 | - */ |
|
251 | - function translate($string) { |
|
242 | + } |
|
243 | + |
|
244 | + /** |
|
245 | + * Translates a string |
|
246 | + * |
|
247 | + * @access public |
|
248 | + * @param string string to be translated |
|
249 | + * @return string translated string (or original, if not found) |
|
250 | + */ |
|
251 | + function translate($string) { |
|
252 | 252 | if ($this->short_circuit) |
253 | - return $string; |
|
253 | + return $string; |
|
254 | 254 | $this->load_tables(); |
255 | 255 | |
256 | 256 | if ($this->enable_cache) { |
257 | - // Caching enabled, get translated string from cache |
|
258 | - if (array_key_exists($string, $this->cache_translations)) |
|
257 | + // Caching enabled, get translated string from cache |
|
258 | + if (array_key_exists($string, $this->cache_translations)) |
|
259 | 259 | return $this->cache_translations[$string]; |
260 | - else |
|
260 | + else |
|
261 | 261 | return $string; |
262 | 262 | } else { |
263 | - // Caching not enabled, try to find string |
|
264 | - $num = $this->find_string($string); |
|
265 | - if ($num == -1) |
|
263 | + // Caching not enabled, try to find string |
|
264 | + $num = $this->find_string($string); |
|
265 | + if ($num == -1) |
|
266 | 266 | return $string; |
267 | - else |
|
267 | + else |
|
268 | 268 | return $this->get_translation_string($num); |
269 | 269 | } |
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * Sanitize plural form expression for use in PHP eval call. |
|
274 | - * |
|
275 | - * @access private |
|
276 | - * @return string sanitized plural form expression |
|
277 | - */ |
|
278 | - function sanitize_plural_expression($expr) { |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * Sanitize plural form expression for use in PHP eval call. |
|
274 | + * |
|
275 | + * @access private |
|
276 | + * @return string sanitized plural form expression |
|
277 | + */ |
|
278 | + function sanitize_plural_expression($expr) { |
|
279 | 279 | // Get rid of disallowed characters. |
280 | 280 | $expr = preg_replace('@[^a-zA-Z0-9_:;\(\)\?\|\&=!<>+*/\%-]@', '', $expr); |
281 | 281 | |
@@ -284,74 +284,74 @@ discard block |
||
284 | 284 | $res = ''; |
285 | 285 | $p = 0; |
286 | 286 | for ($i = 0; $i < strlen($expr); $i++) { |
287 | - $ch = $expr[$i]; |
|
288 | - switch ($ch) { |
|
289 | - case '?': |
|
287 | + $ch = $expr[$i]; |
|
288 | + switch ($ch) { |
|
289 | + case '?': |
|
290 | 290 | $res .= ' ? ('; |
291 | 291 | $p++; |
292 | 292 | break; |
293 | - case ':': |
|
293 | + case ':': |
|
294 | 294 | $res .= ') : ('; |
295 | 295 | break; |
296 | - case ';': |
|
296 | + case ';': |
|
297 | 297 | $res .= str_repeat( ')', $p) . ';'; |
298 | 298 | $p = 0; |
299 | 299 | break; |
300 | - default: |
|
300 | + default: |
|
301 | 301 | $res .= $ch; |
302 | - } |
|
302 | + } |
|
303 | 303 | } |
304 | 304 | return $res; |
305 | - } |
|
306 | - |
|
307 | - /** |
|
308 | - * Parse full PO header and extract only plural forms line. |
|
309 | - * |
|
310 | - * @access private |
|
311 | - * @return string verbatim plural form header field |
|
312 | - */ |
|
313 | - function extract_plural_forms_header_from_po_header($header) { |
|
305 | + } |
|
306 | + |
|
307 | + /** |
|
308 | + * Parse full PO header and extract only plural forms line. |
|
309 | + * |
|
310 | + * @access private |
|
311 | + * @return string verbatim plural form header field |
|
312 | + */ |
|
313 | + function extract_plural_forms_header_from_po_header($header) { |
|
314 | 314 | if (preg_match("/(^|\n)plural-forms: ([^\n]*)\n/i", $header, $regs)) |
315 | - $expr = $regs[2]; |
|
315 | + $expr = $regs[2]; |
|
316 | 316 | else |
317 | - $expr = "nplurals=2; plural=n == 1 ? 0 : 1;"; |
|
317 | + $expr = "nplurals=2; plural=n == 1 ? 0 : 1;"; |
|
318 | 318 | return $expr; |
319 | - } |
|
320 | - |
|
321 | - /** |
|
322 | - * Get possible plural forms from MO header |
|
323 | - * |
|
324 | - * @access private |
|
325 | - * @return string plural form header |
|
326 | - */ |
|
327 | - function get_plural_forms() { |
|
319 | + } |
|
320 | + |
|
321 | + /** |
|
322 | + * Get possible plural forms from MO header |
|
323 | + * |
|
324 | + * @access private |
|
325 | + * @return string plural form header |
|
326 | + */ |
|
327 | + function get_plural_forms() { |
|
328 | 328 | // lets assume message number 0 is header |
329 | 329 | // this is true, right? |
330 | 330 | $this->load_tables(); |
331 | 331 | |
332 | 332 | // cache header field for plural forms |
333 | 333 | if (! is_string($this->pluralheader)) { |
334 | - if ($this->enable_cache) { |
|
334 | + if ($this->enable_cache) { |
|
335 | 335 | $header = $this->cache_translations[""]; |
336 | - } else { |
|
336 | + } else { |
|
337 | 337 | $header = $this->get_translation_string(0); |
338 | - } |
|
339 | - $expr = $this->extract_plural_forms_header_from_po_header($header); |
|
340 | - $this->pluralheader = $this->sanitize_plural_expression($expr); |
|
338 | + } |
|
339 | + $expr = $this->extract_plural_forms_header_from_po_header($header); |
|
340 | + $this->pluralheader = $this->sanitize_plural_expression($expr); |
|
341 | 341 | } |
342 | 342 | return $this->pluralheader; |
343 | - } |
|
344 | - |
|
345 | - /** |
|
346 | - * Detects which plural form to take |
|
347 | - * |
|
348 | - * @access private |
|
349 | - * @param n count |
|
350 | - * @return int array index of the right plural form |
|
351 | - */ |
|
352 | - function select_string($n) { |
|
343 | + } |
|
344 | + |
|
345 | + /** |
|
346 | + * Detects which plural form to take |
|
347 | + * |
|
348 | + * @access private |
|
349 | + * @param n count |
|
350 | + * @return int array index of the right plural form |
|
351 | + */ |
|
352 | + function select_string($n) { |
|
353 | 353 | if (!is_int($n)) { |
354 | - throw new InvalidArgumentException( |
|
354 | + throw new InvalidArgumentException( |
|
355 | 355 | "Select_string only accepts integers: " . $n); |
356 | 356 | } |
357 | 357 | $string = $this->get_plural_forms(); |
@@ -365,22 +365,22 @@ discard block |
||
365 | 365 | eval("$string"); |
366 | 366 | if ($plural >= $total) $plural = $total - 1; |
367 | 367 | return $plural; |
368 | - } |
|
369 | - |
|
370 | - /** |
|
371 | - * Plural version of gettext |
|
372 | - * |
|
373 | - * @access public |
|
374 | - * @param string single |
|
375 | - * @param string plural |
|
376 | - * @param string number |
|
377 | - * @return translated plural form |
|
378 | - */ |
|
379 | - function ngettext($single, $plural, $number) { |
|
368 | + } |
|
369 | + |
|
370 | + /** |
|
371 | + * Plural version of gettext |
|
372 | + * |
|
373 | + * @access public |
|
374 | + * @param string single |
|
375 | + * @param string plural |
|
376 | + * @param string number |
|
377 | + * @return translated plural form |
|
378 | + */ |
|
379 | + function ngettext($single, $plural, $number) { |
|
380 | 380 | if ($this->short_circuit) { |
381 | - if ($number != 1) |
|
381 | + if ($number != 1) |
|
382 | 382 | return $plural; |
383 | - else |
|
383 | + else |
|
384 | 384 | return $single; |
385 | 385 | } |
386 | 386 | |
@@ -392,45 +392,45 @@ discard block |
||
392 | 392 | |
393 | 393 | |
394 | 394 | if ($this->enable_cache) { |
395 | - if (! array_key_exists($key, $this->cache_translations)) { |
|
395 | + if (! array_key_exists($key, $this->cache_translations)) { |
|
396 | 396 | return ($number != 1) ? $plural : $single; |
397 | - } else { |
|
397 | + } else { |
|
398 | 398 | $result = $this->cache_translations[$key]; |
399 | 399 | $list = explode(chr(0), $result); |
400 | 400 | return $list[$select]; |
401 | - } |
|
401 | + } |
|
402 | 402 | } else { |
403 | - $num = $this->find_string($key); |
|
404 | - if ($num == -1) { |
|
403 | + $num = $this->find_string($key); |
|
404 | + if ($num == -1) { |
|
405 | 405 | return ($number != 1) ? $plural : $single; |
406 | - } else { |
|
406 | + } else { |
|
407 | 407 | $result = $this->get_translation_string($num); |
408 | 408 | $list = explode(chr(0), $result); |
409 | 409 | return $list[$select]; |
410 | - } |
|
410 | + } |
|
411 | + } |
|
411 | 412 | } |
412 | - } |
|
413 | 413 | |
414 | - function pgettext($context, $msgid) { |
|
414 | + function pgettext($context, $msgid) { |
|
415 | 415 | $key = $context . chr(4) . $msgid; |
416 | 416 | $ret = $this->translate($key); |
417 | 417 | if (strpos($ret, "\004") !== false) { |
418 | - return $msgid; |
|
418 | + return $msgid; |
|
419 | 419 | } else { |
420 | - return $ret; |
|
420 | + return $ret; |
|
421 | + } |
|
421 | 422 | } |
422 | - } |
|
423 | 423 | |
424 | - function npgettext($context, $singular, $plural, $number) { |
|
424 | + function npgettext($context, $singular, $plural, $number) { |
|
425 | 425 | $key = $context . chr(4) . $singular; |
426 | 426 | $ret = $this->ngettext($key, $plural, $number); |
427 | 427 | if (strpos($ret, "\004") !== false) { |
428 | - return $singular; |
|
428 | + return $singular; |
|
429 | 429 | } else { |
430 | - return $ret; |
|
430 | + return $ret; |
|
431 | 431 | } |
432 | 432 | |
433 | - } |
|
433 | + } |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | ?> |
@@ -38,17 +38,17 @@ discard block |
||
38 | 38 | var $error = 0; // public variable that holds error code (0 if no error) |
39 | 39 | |
40 | 40 | //private: |
41 | - var $BYTEORDER = 0; // 0: low endian, 1: big endian |
|
41 | + var $BYTEORDER = 0; // 0: low endian, 1: big endian |
|
42 | 42 | var $STREAM = null; |
43 | 43 | var $short_circuit = false; |
44 | 44 | var $enable_cache = false; |
45 | - var $originals = null; // offset of original table |
|
46 | - var $translations = null; // offset of translation table |
|
47 | - var $pluralheader = null; // cache header field for plural forms |
|
48 | - var $total = 0; // total string count |
|
49 | - var $table_originals = null; // table for original strings (offsets) |
|
50 | - var $table_translations = null; // table for translated strings (offsets) |
|
51 | - var $cache_translations = null; // original -> translation mapping |
|
45 | + var $originals = null; // offset of original table |
|
46 | + var $translations = null; // offset of translation table |
|
47 | + var $pluralheader = null; // cache header field for plural forms |
|
48 | + var $total = 0; // total string count |
|
49 | + var $table_originals = null; // table for original strings (offsets) |
|
50 | + var $table_translations = null; // table for translated strings (offsets) |
|
51 | + var $cache_translations = null; // original -> translation mapping |
|
52 | 52 | |
53 | 53 | |
54 | 54 | /* Methods */ |
@@ -63,11 +63,11 @@ discard block |
||
63 | 63 | function readint() { |
64 | 64 | if ($this->BYTEORDER == 0) { |
65 | 65 | // low endian |
66 | - $input=unpack('V', $this->STREAM->read(4)); |
|
66 | + $input = unpack('V', $this->STREAM->read(4)); |
|
67 | 67 | return array_shift($input); |
68 | 68 | } else { |
69 | 69 | // big endian |
70 | - $input=unpack('N', $this->STREAM->read(4)); |
|
70 | + $input = unpack('N', $this->STREAM->read(4)); |
|
71 | 71 | return array_shift($input); |
72 | 72 | } |
73 | 73 | } |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | */ |
101 | 101 | function __construct($Reader, $enable_cache = true) { |
102 | 102 | // If there isn't a StreamReader, turn on short circuit mode. |
103 | - if (! $Reader || isset($Reader->error) ) { |
|
103 | + if (!$Reader || isset($Reader->error)) { |
|
104 | 104 | $this->short_circuit = true; |
105 | 105 | return; |
106 | 106 | } |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | } |
155 | 155 | |
156 | 156 | if ($this->enable_cache) { |
157 | - $this->cache_translations = array (); |
|
157 | + $this->cache_translations = array(); |
|
158 | 158 | /* read all strings in the cache */ |
159 | 159 | for ($i = 0; $i < $this->total; $i++) { |
160 | 160 | $this->STREAM->seekto($this->table_originals[$i * 2 + 2]); |
@@ -176,11 +176,11 @@ discard block |
||
176 | 176 | function get_original_string($num) { |
177 | 177 | $length = $this->table_originals[$num * 2 + 1]; |
178 | 178 | $offset = $this->table_originals[$num * 2 + 2]; |
179 | - if (! $length) |
|
179 | + if (!$length) |
|
180 | 180 | return ''; |
181 | 181 | $this->STREAM->seekto($offset); |
182 | 182 | $data = $this->STREAM->read($length); |
183 | - return (string)$data; |
|
183 | + return (string) $data; |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | /** |
@@ -193,11 +193,11 @@ discard block |
||
193 | 193 | function get_translation_string($num) { |
194 | 194 | $length = $this->table_translations[$num * 2 + 1]; |
195 | 195 | $offset = $this->table_translations[$num * 2 + 2]; |
196 | - if (! $length) |
|
196 | + if (!$length) |
|
197 | 197 | return ''; |
198 | 198 | $this->STREAM->seekto($offset); |
199 | 199 | $data = $this->STREAM->read($length); |
200 | - return (string)$data; |
|
200 | + return (string) $data; |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | return $this->find_string($string, $end, $start); |
228 | 228 | } else { |
229 | 229 | // Divide table in two parts |
230 | - $half = (int)(($start + $end) / 2); |
|
230 | + $half = (int) (($start + $end) / 2); |
|
231 | 231 | $cmp = strcmp($string, $this->get_original_string($half)); |
232 | 232 | if ($cmp == 0) |
233 | 233 | // string is exactly in the middle => return it |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | $res .= ') : ('; |
295 | 295 | break; |
296 | 296 | case ';': |
297 | - $res .= str_repeat( ')', $p) . ';'; |
|
297 | + $res .= str_repeat(')', $p).';'; |
|
298 | 298 | $p = 0; |
299 | 299 | break; |
300 | 300 | default: |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | $this->load_tables(); |
331 | 331 | |
332 | 332 | // cache header field for plural forms |
333 | - if (! is_string($this->pluralheader)) { |
|
333 | + if (!is_string($this->pluralheader)) { |
|
334 | 334 | if ($this->enable_cache) { |
335 | 335 | $header = $this->cache_translations[""]; |
336 | 336 | } else { |
@@ -352,12 +352,12 @@ discard block |
||
352 | 352 | function select_string($n) { |
353 | 353 | if (!is_int($n)) { |
354 | 354 | throw new InvalidArgumentException( |
355 | - "Select_string only accepts integers: " . $n); |
|
355 | + "Select_string only accepts integers: ".$n); |
|
356 | 356 | } |
357 | 357 | $string = $this->get_plural_forms(); |
358 | - $string = str_replace('nplurals',"\$total",$string); |
|
359 | - $string = str_replace("n",$n,$string); |
|
360 | - $string = str_replace('plural',"\$plural",$string); |
|
358 | + $string = str_replace('nplurals', "\$total", $string); |
|
359 | + $string = str_replace("n", $n, $string); |
|
360 | + $string = str_replace('plural', "\$plural", $string); |
|
361 | 361 | |
362 | 362 | $total = 0; |
363 | 363 | $plural = 0; |
@@ -388,11 +388,11 @@ discard block |
||
388 | 388 | $select = $this->select_string($number); |
389 | 389 | |
390 | 390 | // this should contains all strings separated by NULLs |
391 | - $key = $single . chr(0) . $plural; |
|
391 | + $key = $single.chr(0).$plural; |
|
392 | 392 | |
393 | 393 | |
394 | 394 | if ($this->enable_cache) { |
395 | - if (! array_key_exists($key, $this->cache_translations)) { |
|
395 | + if (!array_key_exists($key, $this->cache_translations)) { |
|
396 | 396 | return ($number != 1) ? $plural : $single; |
397 | 397 | } else { |
398 | 398 | $result = $this->cache_translations[$key]; |
@@ -412,7 +412,7 @@ discard block |
||
412 | 412 | } |
413 | 413 | |
414 | 414 | function pgettext($context, $msgid) { |
415 | - $key = $context . chr(4) . $msgid; |
|
415 | + $key = $context.chr(4).$msgid; |
|
416 | 416 | $ret = $this->translate($key); |
417 | 417 | if (strpos($ret, "\004") !== false) { |
418 | 418 | return $msgid; |
@@ -422,7 +422,7 @@ discard block |
||
422 | 422 | } |
423 | 423 | |
424 | 424 | function npgettext($context, $singular, $plural, $number) { |
425 | - $key = $context . chr(4) . $singular; |
|
425 | + $key = $context.chr(4).$singular; |
|
426 | 426 | $ret = $this->ngettext($key, $plural, $number); |
427 | 427 | if (strpos($ret, "\004") !== false) { |
428 | 428 | return $singular; |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | // LC_MESSAGES is not available if php-gettext is not loaded |
36 | 36 | // while the other constants are already available from session extension. |
37 | 37 | if (!defined('LC_MESSAGES')) { |
38 | - define('LC_MESSAGES', 5); |
|
38 | + define('LC_MESSAGES', 5); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | require('streams.php'); |
@@ -53,9 +53,9 @@ discard block |
||
53 | 53 | |
54 | 54 | /* Class to hold a single domain included in $text_domains. */ |
55 | 55 | class domain { |
56 | - var $l10n; |
|
57 | - var $path; |
|
58 | - var $codeset; |
|
56 | + var $l10n; |
|
57 | + var $path; |
|
58 | + var $codeset; |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | // Utility functions |
@@ -64,50 +64,50 @@ discard block |
||
64 | 64 | * Return a list of locales to try for any POSIX-style locale specification. |
65 | 65 | */ |
66 | 66 | function get_list_of_locales($locale) { |
67 | - /* Figure out all possible locale names and start with the most |
|
67 | + /* Figure out all possible locale names and start with the most |
|
68 | 68 | * specific ones. I.e. for sr_CS.UTF-8@latin, look through all of |
69 | 69 | * sr_CS.UTF-8@latin, sr_CS@latin, sr@latin, sr_CS.UTF-8, sr_CS, sr. |
70 | 70 | */ |
71 | - $locale_names = array(); |
|
72 | - $lang = null; |
|
73 | - $country = null; |
|
74 | - $charset = null; |
|
75 | - $modifier = null; |
|
76 | - if ($locale) { |
|
71 | + $locale_names = array(); |
|
72 | + $lang = null; |
|
73 | + $country = null; |
|
74 | + $charset = null; |
|
75 | + $modifier = null; |
|
76 | + if ($locale) { |
|
77 | 77 | if (preg_match("/^(?P<lang>[a-z]{2,3})" // language code |
78 | - ."(?:_(?P<country>[A-Z]{2}))?" // country code |
|
79 | - ."(?:\.(?P<charset>[-A-Za-z0-9_]+))?" // charset |
|
80 | - ."(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/", // @ modifier |
|
81 | - $locale, $matches)) { |
|
78 | + ."(?:_(?P<country>[A-Z]{2}))?" // country code |
|
79 | + ."(?:\.(?P<charset>[-A-Za-z0-9_]+))?" // charset |
|
80 | + ."(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/", // @ modifier |
|
81 | + $locale, $matches)) { |
|
82 | 82 | |
83 | - if (isset($matches["lang"])) $lang = $matches["lang"]; |
|
84 | - if (isset($matches["country"])) $country = $matches["country"]; |
|
85 | - if (isset($matches["charset"])) $charset = $matches["charset"]; |
|
86 | - if (isset($matches["modifier"])) $modifier = $matches["modifier"]; |
|
83 | + if (isset($matches["lang"])) $lang = $matches["lang"]; |
|
84 | + if (isset($matches["country"])) $country = $matches["country"]; |
|
85 | + if (isset($matches["charset"])) $charset = $matches["charset"]; |
|
86 | + if (isset($matches["modifier"])) $modifier = $matches["modifier"]; |
|
87 | 87 | |
88 | - if ($modifier) { |
|
88 | + if ($modifier) { |
|
89 | 89 | if ($country) { |
90 | - if ($charset) |
|
90 | + if ($charset) |
|
91 | 91 | array_push($locale_names, "${lang}_$country.$charset@$modifier"); |
92 | - array_push($locale_names, "${lang}_$country@$modifier"); |
|
92 | + array_push($locale_names, "${lang}_$country@$modifier"); |
|
93 | 93 | } elseif ($charset) |
94 | 94 | array_push($locale_names, "${lang}.$charset@$modifier"); |
95 | 95 | array_push($locale_names, "$lang@$modifier"); |
96 | - } |
|
97 | - if ($country) { |
|
96 | + } |
|
97 | + if ($country) { |
|
98 | 98 | if ($charset) |
99 | - array_push($locale_names, "${lang}_$country.$charset"); |
|
99 | + array_push($locale_names, "${lang}_$country.$charset"); |
|
100 | 100 | array_push($locale_names, "${lang}_$country"); |
101 | - } elseif ($charset) |
|
102 | - array_push($locale_names, "${lang}.$charset"); |
|
103 | - array_push($locale_names, $lang); |
|
101 | + } elseif ($charset) |
|
102 | + array_push($locale_names, "${lang}.$charset"); |
|
103 | + array_push($locale_names, $lang); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | // If the locale name doesn't match POSIX style, just include it as-is. |
107 | 107 | if (!in_array($locale, $locale_names)) |
108 | - array_push($locale_names, $locale); |
|
109 | - } |
|
110 | - return $locale_names; |
|
108 | + array_push($locale_names, $locale); |
|
109 | + } |
|
110 | + return $locale_names; |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -126,19 +126,19 @@ discard block |
||
126 | 126 | $locale_names = get_list_of_locales($locale); |
127 | 127 | $input = null; |
128 | 128 | foreach ($locale_names as $locale) { |
129 | - $full_path = $bound_path . $locale . "/" . $subpath; |
|
130 | - if (file_exists($full_path)) { |
|
129 | + $full_path = $bound_path . $locale . "/" . $subpath; |
|
130 | + if (file_exists($full_path)) { |
|
131 | 131 | $input = new FileReader($full_path); |
132 | 132 | break; |
133 | - } |
|
133 | + } |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | if (!array_key_exists($domain, $text_domains)) { |
137 | - // Initialize an empty domain object. |
|
138 | - $text_domains[$domain] = new domain(); |
|
137 | + // Initialize an empty domain object. |
|
138 | + $text_domains[$domain] = new domain(); |
|
139 | 139 | } |
140 | 140 | $text_domains[$domain]->l10n = new gettext_reader($input, |
141 | - $enable_cache); |
|
141 | + $enable_cache); |
|
142 | 142 | } |
143 | 143 | return $text_domains[$domain]->l10n; |
144 | 144 | } |
@@ -174,13 +174,13 @@ discard block |
||
174 | 174 | * Convert the given string to the encoding set by bind_textdomain_codeset. |
175 | 175 | */ |
176 | 176 | function _encode($text) { |
177 | - $target_encoding = _get_codeset(); |
|
178 | - if (function_exists("mb_detect_encoding")) { |
|
177 | + $target_encoding = _get_codeset(); |
|
178 | + if (function_exists("mb_detect_encoding")) { |
|
179 | 179 | $source_encoding = mb_detect_encoding($text); |
180 | 180 | if ($source_encoding != $target_encoding) |
181 | - $text = mb_convert_encoding($text, $target_encoding, $source_encoding); |
|
182 | - } |
|
183 | - return $text; |
|
181 | + $text = mb_convert_encoding($text, $target_encoding, $source_encoding); |
|
182 | + } |
|
183 | + return $text; |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | |
@@ -190,9 +190,9 @@ discard block |
||
190 | 190 | * Returns passed in $locale, or environment variable $LANG if $locale == ''. |
191 | 191 | */ |
192 | 192 | function _get_default_locale($locale) { |
193 | - if ($locale == '') // emulate variable support |
|
193 | + if ($locale == '') // emulate variable support |
|
194 | 194 | return getenv('LANG'); |
195 | - else |
|
195 | + else |
|
196 | 196 | return $locale; |
197 | 197 | } |
198 | 198 | |
@@ -210,20 +210,20 @@ discard block |
||
210 | 210 | return _setlocale($category, $CURRENTLOCALE); |
211 | 211 | } else { |
212 | 212 | if (function_exists('setlocale')) { |
213 | - $ret = setlocale($category, $locale); |
|
214 | - if (($locale == '' and !$ret) or // failed setting it by env |
|
213 | + $ret = setlocale($category, $locale); |
|
214 | + if (($locale == '' and !$ret) or // failed setting it by env |
|
215 | 215 | ($locale != '' and $ret != $locale)) { // failed setting it |
216 | 216 | // Failed setting it according to environment. |
217 | 217 | $CURRENTLOCALE = _get_default_locale($locale); |
218 | 218 | $EMULATEGETTEXT = 1; |
219 | - } else { |
|
219 | + } else { |
|
220 | 220 | $CURRENTLOCALE = $ret; |
221 | 221 | $EMULATEGETTEXT = 0; |
222 | - } |
|
222 | + } |
|
223 | 223 | } else { |
224 | - // No function setlocale(), emulate it all. |
|
225 | - $CURRENTLOCALE = _get_default_locale($locale); |
|
226 | - $EMULATEGETTEXT = 1; |
|
224 | + // No function setlocale(), emulate it all. |
|
225 | + $CURRENTLOCALE = _get_default_locale($locale); |
|
226 | + $EMULATEGETTEXT = 1; |
|
227 | 227 | } |
228 | 228 | // Allow locale to be changed on the go for one translation domain. |
229 | 229 | global $text_domains, $default_domain; |
@@ -241,15 +241,15 @@ discard block |
||
241 | 241 | global $text_domains; |
242 | 242 | // ensure $path ends with a slash ('/' should work for both, but lets still play nice) |
243 | 243 | if (substr(php_uname(), 0, 7) == "Windows") { |
244 | - if ($path[strlen($path)-1] != '\\' and $path[strlen($path)-1] != '/') |
|
244 | + if ($path[strlen($path)-1] != '\\' and $path[strlen($path)-1] != '/') |
|
245 | 245 | $path .= '\\'; |
246 | 246 | } else { |
247 | - if ($path[strlen($path)-1] != '/') |
|
247 | + if ($path[strlen($path)-1] != '/') |
|
248 | 248 | $path .= '/'; |
249 | 249 | } |
250 | 250 | if (!array_key_exists($domain, $text_domains)) { |
251 | - // Initialize an empty domain object. |
|
252 | - $text_domains[$domain] = new domain(); |
|
251 | + // Initialize an empty domain object. |
|
252 | + $text_domains[$domain] = new domain(); |
|
253 | 253 | } |
254 | 254 | $text_domains[$domain]->path = $path; |
255 | 255 | } |
@@ -426,29 +426,29 @@ discard block |
||
426 | 426 | } |
427 | 427 | function T_dcngettext($domain, $singular, $plural, $number, $category) { |
428 | 428 | if (_check_locale_and_function()) |
429 | - return dcngettext($domain, $singular, $plural, $number, $category); |
|
429 | + return dcngettext($domain, $singular, $plural, $number, $category); |
|
430 | 430 | else return _dcngettext($domain, $singular, $plural, $number, $category); |
431 | 431 | } |
432 | 432 | |
433 | 433 | function T_pgettext($context, $msgid) { |
434 | - if (_check_locale_and_function('pgettext')) |
|
435 | - return pgettext($context, $msgid); |
|
436 | - else |
|
437 | - return _pgettext($context, $msgid); |
|
434 | + if (_check_locale_and_function('pgettext')) |
|
435 | + return pgettext($context, $msgid); |
|
436 | + else |
|
437 | + return _pgettext($context, $msgid); |
|
438 | 438 | } |
439 | 439 | |
440 | 440 | function T_dpgettext($domain, $context, $msgid) { |
441 | - if (_check_locale_and_function('dpgettext')) |
|
442 | - return dpgettext($domain, $context, $msgid); |
|
443 | - else |
|
444 | - return _dpgettext($domain, $context, $msgid); |
|
441 | + if (_check_locale_and_function('dpgettext')) |
|
442 | + return dpgettext($domain, $context, $msgid); |
|
443 | + else |
|
444 | + return _dpgettext($domain, $context, $msgid); |
|
445 | 445 | } |
446 | 446 | |
447 | 447 | function T_dcpgettext($domain, $context, $msgid, $category) { |
448 | - if (_check_locale_and_function('dcpgettext')) |
|
449 | - return dcpgettext($domain, $context, $msgid, $category); |
|
450 | - else |
|
451 | - return _dcpgettext($domain, $context, $msgid, $category); |
|
448 | + if (_check_locale_and_function('dcpgettext')) |
|
449 | + return dcpgettext($domain, $context, $msgid, $category); |
|
450 | + else |
|
451 | + return _dcpgettext($domain, $context, $msgid, $category); |
|
452 | 452 | } |
453 | 453 | |
454 | 454 | function T_npgettext($context, $singular, $plural, $number) { |
@@ -459,17 +459,17 @@ discard block |
||
459 | 459 | } |
460 | 460 | |
461 | 461 | function T_dnpgettext($domain, $context, $singular, $plural, $number) { |
462 | - if (_check_locale_and_function('dnpgettext')) |
|
463 | - return dnpgettext($domain, $context, $singular, $plural, $number); |
|
464 | - else |
|
465 | - return _dnpgettext($domain, $context, $singular, $plural, $number); |
|
462 | + if (_check_locale_and_function('dnpgettext')) |
|
463 | + return dnpgettext($domain, $context, $singular, $plural, $number); |
|
464 | + else |
|
465 | + return _dnpgettext($domain, $context, $singular, $plural, $number); |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | function T_dcnpgettext($domain, $context, $singular, $plural, |
469 | - $number, $category) { |
|
469 | + $number, $category) { |
|
470 | 470 | if (_check_locale_and_function('dcnpgettext')) |
471 | 471 | return dcnpgettext($domain, $context, $singular, |
472 | - $plural, $number, $category); |
|
472 | + $plural, $number, $category); |
|
473 | 473 | else |
474 | 474 | return _dcnpgettext($domain, $context, $singular, |
475 | 475 | $plural, $number, $category); |
@@ -526,9 +526,9 @@ discard block |
||
526 | 526 | return _dcpgettext($domain, $context, $msgid, $category); |
527 | 527 | } |
528 | 528 | function dcnpgettext($domain, $context, $singular, $plural, |
529 | - $number, $category) { |
|
530 | - return _dcnpgettext($domain, $context, $singular, $plural, |
|
531 | - $number, $category); |
|
529 | + $number, $category) { |
|
530 | + return _dcnpgettext($domain, $context, $singular, $plural, |
|
531 | + $number, $category); |
|
532 | 532 | } |
533 | 533 | } |
534 | 534 |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | define('LABEL_BASE_INDEX', -1024); |
6 | 6 | define('PLUGIN_FEED_BASE_INDEX', -128); |
7 | 7 | |
8 | -define('COOKIE_LIFETIME_LONG', 86400*365); |
|
8 | +define('COOKIE_LIFETIME_LONG', 86400 * 365); |
|
9 | 9 | |
10 | 10 | $fetch_last_error = false; |
11 | 11 | $fetch_last_error_code = false; |
@@ -57,13 +57,13 @@ discard block |
||
57 | 57 | // feed limit for one update batch |
58 | 58 | define_default('DAEMON_SLEEP_INTERVAL', 120); |
59 | 59 | // default sleep interval between feed updates (sec) |
60 | -define_default('MAX_CACHE_FILE_SIZE', 64*1024*1024); |
|
60 | +define_default('MAX_CACHE_FILE_SIZE', 64 * 1024 * 1024); |
|
61 | 61 | // do not cache files larger than that (bytes) |
62 | -define_default('MAX_DOWNLOAD_FILE_SIZE', 16*1024*1024); |
|
62 | +define_default('MAX_DOWNLOAD_FILE_SIZE', 16 * 1024 * 1024); |
|
63 | 63 | // do not download general files larger than that (bytes) |
64 | 64 | define_default('CACHE_MAX_DAYS', 7); |
65 | 65 | // max age in days for various automatically cached (temporary) files |
66 | -define_default('MAX_CONDITIONAL_INTERVAL', 3600*12); |
|
66 | +define_default('MAX_CONDITIONAL_INTERVAL', 3600 * 12); |
|
67 | 67 | // max interval between forced unconditional updates for servers |
68 | 68 | // not complying with http if-modified-since (seconds) |
69 | 69 | define_default('MAX_FETCH_REQUESTS_PER_HOST', 25); |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | require_once 'db-prefs.php'; |
158 | 158 | require_once 'controls.php'; |
159 | 159 | |
160 | -define('SELF_USER_AGENT', 'Tiny Tiny RSS/' . get_version() . ' (http://tt-rss.org/)'); |
|
160 | +define('SELF_USER_AGENT', 'Tiny Tiny RSS/'.get_version().' (http://tt-rss.org/)'); |
|
161 | 161 | ini_set('user_agent', SELF_USER_AGENT); |
162 | 162 | |
163 | 163 | $schema_version = false; |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | if (!is_array($options)) { |
202 | 202 | |
203 | 203 | // falling back on compatibility shim |
204 | - $option_names = [ "url", "type", "login", "pass", "post_query", "timeout", "last_modified", "useragent" ]; |
|
204 | + $option_names = ["url", "type", "login", "pass", "post_query", "timeout", "last_modified", "useragent"]; |
|
205 | 205 | $tmp = []; |
206 | 206 | |
207 | 207 | for ($i = 0; $i < func_num_args(); $i++) { |
@@ -228,13 +228,13 @@ discard block |
||
228 | 228 | $url = str_replace(' ', '%20', $url); |
229 | 229 | |
230 | 230 | if (strpos($url, "//") === 0) |
231 | - $url = 'http:' . $url; |
|
231 | + $url = 'http:'.$url; |
|
232 | 232 | |
233 | 233 | $url_host = parse_url($url, PHP_URL_HOST); |
234 | 234 | $fetch_domain_hits[$url_host] += 1; |
235 | 235 | |
236 | 236 | if ($fetch_domain_hits[$url_host] > MAX_FETCH_REQUESTS_PER_HOST) { |
237 | - user_error("Exceeded fetch request quota for $url_host: " . $fetch_domain_hits[$url_host], E_USER_WARNING); |
|
237 | + user_error("Exceeded fetch request quota for $url_host: ".$fetch_domain_hits[$url_host], E_USER_WARNING); |
|
238 | 238 | #return false; |
239 | 239 | } |
240 | 240 | |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | array_push($curl_http_headers, "If-Modified-Since: $last_modified"); |
251 | 251 | |
252 | 252 | if ($http_accept) |
253 | - array_push($curl_http_headers, "Accept: " . $http_accept); |
|
253 | + array_push($curl_http_headers, "Accept: ".$http_accept); |
|
254 | 254 | |
255 | 255 | if (count($curl_http_headers) > 0) |
256 | 256 | curl_setopt($ch, CURLOPT_HTTPHEADER, $curl_http_headers); |
@@ -263,11 +263,10 @@ discard block |
||
263 | 263 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
264 | 264 | curl_setopt($ch, CURLOPT_HEADER, true); |
265 | 265 | curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); |
266 | - curl_setopt($ch, CURLOPT_USERAGENT, $useragent ? $useragent : |
|
267 | - SELF_USER_AGENT); |
|
266 | + curl_setopt($ch, CURLOPT_USERAGENT, $useragent ? $useragent : SELF_USER_AGENT); |
|
268 | 267 | curl_setopt($ch, CURLOPT_ENCODING, ""); |
269 | 268 | |
270 | - if ($http_referrer) |
|
269 | + if ($http_referrer) |
|
271 | 270 | curl_setopt($ch, CURLOPT_REFERER, $http_referrer); |
272 | 271 | |
273 | 272 | if ($max_size) { |
@@ -276,7 +275,7 @@ discard block |
||
276 | 275 | |
277 | 276 | // holy shit closures in php |
278 | 277 | // download & upload are *expected* sizes respectively, could be zero |
279 | - curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, function($curl_handle, $download_size, $downloaded, $upload_size, $uploaded) use( &$max_size) { |
|
278 | + curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, function($curl_handle, $download_size, $downloaded, $upload_size, $uploaded) use(&$max_size) { |
|
280 | 279 | Debug::log("[curl progressfunction] $downloaded $max_size", Debug::$LOG_EXTENDED); |
281 | 280 | |
282 | 281 | return ($downloaded > $max_size) ? 1 : 0; // if max size is set, abort when exceeding it |
@@ -336,7 +335,7 @@ discard block |
||
336 | 335 | if ($http_code != 200 || $type && strpos($fetch_last_content_type, "$type") === false) { |
337 | 336 | |
338 | 337 | if (curl_errno($ch) != 0) { |
339 | - $fetch_last_error .= "; " . curl_errno($ch) . " " . curl_error($ch); |
|
338 | + $fetch_last_error .= "; ".curl_errno($ch)." ".curl_error($ch); |
|
340 | 339 | } |
341 | 340 | |
342 | 341 | $fetch_last_error_content = $contents; |
@@ -345,7 +344,7 @@ discard block |
||
345 | 344 | } |
346 | 345 | |
347 | 346 | if (!$contents) { |
348 | - $fetch_last_error = curl_errno($ch) . " " . curl_error($ch); |
|
347 | + $fetch_last_error = curl_errno($ch)." ".curl_error($ch); |
|
349 | 348 | curl_close($ch); |
350 | 349 | return false; |
351 | 350 | } |
@@ -365,7 +364,7 @@ discard block |
||
365 | 364 | |
366 | 365 | $fetch_curl_used = false; |
367 | 366 | |
368 | - if ($login && $pass){ |
|
367 | + if ($login && $pass) { |
|
369 | 368 | $url_parts = array(); |
370 | 369 | |
371 | 370 | preg_match("/(^[^:]*):\/\/(.*)/", $url, $url_parts); |
@@ -373,7 +372,7 @@ discard block |
||
373 | 372 | $pass = urlencode($pass); |
374 | 373 | |
375 | 374 | if ($url_parts[1] && $url_parts[2]) { |
376 | - $url = $url_parts[1] . "://$login:$pass@" . $url_parts[2]; |
|
375 | + $url = $url_parts[1]."://$login:$pass@".$url_parts[2]; |
|
377 | 376 | } |
378 | 377 | } |
379 | 378 | |
@@ -441,7 +440,7 @@ discard block |
||
441 | 440 | $error = error_get_last(); |
442 | 441 | |
443 | 442 | if ($error['message'] != $old_error['message']) { |
444 | - $fetch_last_error .= "; " . $error["message"]; |
|
443 | + $fetch_last_error .= "; ".$error["message"]; |
|
445 | 444 | } |
446 | 445 | |
447 | 446 | $fetch_last_error_content = $data; |
@@ -516,15 +515,15 @@ discard block |
||
516 | 515 | |
517 | 516 | function get_ssl_certificate_id() { |
518 | 517 | if ($_SERVER["REDIRECT_SSL_CLIENT_M_SERIAL"]) { |
519 | - return sha1($_SERVER["REDIRECT_SSL_CLIENT_M_SERIAL"] . |
|
520 | - $_SERVER["REDIRECT_SSL_CLIENT_V_START"] . |
|
521 | - $_SERVER["REDIRECT_SSL_CLIENT_V_END"] . |
|
518 | + return sha1($_SERVER["REDIRECT_SSL_CLIENT_M_SERIAL"]. |
|
519 | + $_SERVER["REDIRECT_SSL_CLIENT_V_START"]. |
|
520 | + $_SERVER["REDIRECT_SSL_CLIENT_V_END"]. |
|
522 | 521 | $_SERVER["REDIRECT_SSL_CLIENT_S_DN"]); |
523 | 522 | } |
524 | 523 | if ($_SERVER["SSL_CLIENT_M_SERIAL"]) { |
525 | - return sha1($_SERVER["SSL_CLIENT_M_SERIAL"] . |
|
526 | - $_SERVER["SSL_CLIENT_V_START"] . |
|
527 | - $_SERVER["SSL_CLIENT_V_END"] . |
|
524 | + return sha1($_SERVER["SSL_CLIENT_M_SERIAL"]. |
|
525 | + $_SERVER["SSL_CLIENT_V_START"]. |
|
526 | + $_SERVER["SSL_CLIENT_V_END"]. |
|
528 | 527 | $_SERVER["SSL_CLIENT_S_DN"]); |
529 | 528 | } |
530 | 529 | return ""; |
@@ -659,7 +658,7 @@ discard block |
||
659 | 658 | function logout_user() { |
660 | 659 | @session_destroy(); |
661 | 660 | if (isset($_COOKIE[session_name()])) { |
662 | - setcookie(session_name(), '', time()-42000, '/'); |
|
661 | + setcookie(session_name(), '', time() - 42000, '/'); |
|
663 | 662 | } |
664 | 663 | session_commit(); |
665 | 664 | } |
@@ -743,7 +742,7 @@ discard block |
||
743 | 742 | |
744 | 743 | function truncate_string($str, $max_len, $suffix = '…') { |
745 | 744 | if (mb_strlen($str, "utf-8") > $max_len) { |
746 | - return mb_substr($str, 0, $max_len, "utf-8") . $suffix; |
|
745 | + return mb_substr($str, 0, $max_len, "utf-8").$suffix; |
|
747 | 746 | } else { |
748 | 747 | return $str; |
749 | 748 | } |
@@ -753,7 +752,7 @@ discard block |
||
753 | 752 | $startString = mb_substr($original, 0, $position, "UTF-8"); |
754 | 753 | $endString = mb_substr($original, $position + $length, mb_strlen($original), "UTF-8"); |
755 | 754 | |
756 | - $out = $startString . $replacement . $endString; |
|
755 | + $out = $startString.$replacement.$endString; |
|
757 | 756 | |
758 | 757 | return $out; |
759 | 758 | } |
@@ -891,9 +890,9 @@ discard block |
||
891 | 890 | } |
892 | 891 | |
893 | 892 | function file_is_locked($filename) { |
894 | - if (file_exists(LOCK_DIRECTORY . "/$filename")) { |
|
893 | + if (file_exists(LOCK_DIRECTORY."/$filename")) { |
|
895 | 894 | if (function_exists('flock')) { |
896 | - $fp = @fopen(LOCK_DIRECTORY . "/$filename", "r"); |
|
895 | + $fp = @fopen(LOCK_DIRECTORY."/$filename", "r"); |
|
897 | 896 | if ($fp) { |
898 | 897 | if (flock($fp, LOCK_EX | LOCK_NB)) { |
899 | 898 | flock($fp, LOCK_UN); |
@@ -914,11 +913,11 @@ discard block |
||
914 | 913 | |
915 | 914 | |
916 | 915 | function make_lockfile($filename) { |
917 | - $fp = fopen(LOCK_DIRECTORY . "/$filename", "w"); |
|
916 | + $fp = fopen(LOCK_DIRECTORY."/$filename", "w"); |
|
918 | 917 | |
919 | 918 | if ($fp && flock($fp, LOCK_EX | LOCK_NB)) { |
920 | 919 | $stat_h = fstat($fp); |
921 | - $stat_f = stat(LOCK_DIRECTORY . "/$filename"); |
|
920 | + $stat_f = stat(LOCK_DIRECTORY."/$filename"); |
|
922 | 921 | |
923 | 922 | if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { |
924 | 923 | if ($stat_h["ino"] != $stat_f["ino"] || |
@@ -929,7 +928,7 @@ discard block |
||
929 | 928 | } |
930 | 929 | |
931 | 930 | if (function_exists('posix_getpid')) { |
932 | - fwrite($fp, posix_getpid() . "\n"); |
|
931 | + fwrite($fp, posix_getpid()."\n"); |
|
933 | 932 | } |
934 | 933 | return $fp; |
935 | 934 | } else { |
@@ -938,10 +937,10 @@ discard block |
||
938 | 937 | } |
939 | 938 | |
940 | 939 | function make_stampfile($filename) { |
941 | - $fp = fopen(LOCK_DIRECTORY . "/$filename", "w"); |
|
940 | + $fp = fopen(LOCK_DIRECTORY."/$filename", "w"); |
|
942 | 941 | |
943 | 942 | if (flock($fp, LOCK_EX | LOCK_NB)) { |
944 | - fwrite($fp, time() . "\n"); |
|
943 | + fwrite($fp, time()."\n"); |
|
945 | 944 | flock($fp, LOCK_UN); |
946 | 945 | fclose($fp); |
947 | 946 | return true; |
@@ -991,7 +990,7 @@ discard block |
||
991 | 990 | $params["is_default_pw"] = Pref_Prefs::isdefaultpassword(); |
992 | 991 | $params["label_base_index"] = (int) LABEL_BASE_INDEX; |
993 | 992 | |
994 | - $theme = get_pref( "USER_CSS_THEME", false, false); |
|
993 | + $theme = get_pref("USER_CSS_THEME", false, false); |
|
995 | 994 | $params["theme"] = theme_exists($theme) ? $theme : ""; |
996 | 995 | |
997 | 996 | $params["plugins"] = implode(", ", PluginHost::getInstance()->get_plugin_names()); |
@@ -1215,13 +1214,13 @@ discard block |
||
1215 | 1214 | } |
1216 | 1215 | } |
1217 | 1216 | |
1218 | - if (file_exists(LOCK_DIRECTORY . "/update_daemon.lock")) { |
|
1217 | + if (file_exists(LOCK_DIRECTORY."/update_daemon.lock")) { |
|
1219 | 1218 | |
1220 | 1219 | $data['daemon_is_running'] = (int) file_is_locked("update_daemon.lock"); |
1221 | 1220 | |
1222 | 1221 | if (time() - $_SESSION["daemon_stamp_check"] > 30) { |
1223 | 1222 | |
1224 | - $stamp = (int) @file_get_contents(LOCK_DIRECTORY . "/update_daemon.stamp"); |
|
1223 | + $stamp = (int) @file_get_contents(LOCK_DIRECTORY."/update_daemon.stamp"); |
|
1225 | 1224 | |
1226 | 1225 | if ($stamp) { |
1227 | 1226 | $stamp_delta = time() - $stamp; |
@@ -1264,7 +1263,7 @@ discard block |
||
1264 | 1263 | $res = trim($str); if (!$res) return ''; |
1265 | 1264 | |
1266 | 1265 | $doc = new DOMDocument(); |
1267 | - $doc->loadHTML('<?xml encoding="UTF-8">' . $res); |
|
1266 | + $doc->loadHTML('<?xml encoding="UTF-8">'.$res); |
|
1268 | 1267 | $xpath = new DOMXPath($doc); |
1269 | 1268 | |
1270 | 1269 | $rewrite_base_url = $site_url ? $site_url : get_self_url_prefix(); |
@@ -1363,7 +1362,7 @@ discard block |
||
1363 | 1362 | 'ol', 'p', 'picture', 'pre', 'q', 'ruby', 'rp', 'rt', 's', 'samp', 'section', |
1364 | 1363 | 'small', 'source', 'span', 'strike', 'strong', 'sub', 'summary', |
1365 | 1364 | 'sup', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'time', |
1366 | - 'tr', 'track', 'tt', 'u', 'ul', 'var', 'wbr', 'video', 'xml:namespace' ); |
|
1365 | + 'tr', 'track', 'tt', 'u', 'ul', 'var', 'wbr', 'video', 'xml:namespace'); |
|
1367 | 1366 | |
1368 | 1367 | if ($_SESSION['hasSandbox']) $allowed_elements[] = 'iframe'; |
1369 | 1368 | |
@@ -1498,8 +1497,8 @@ discard block |
||
1498 | 1497 | |
1499 | 1498 | // this returns SELF_URL_PATH sans ending slash |
1500 | 1499 | function get_self_url_prefix() { |
1501 | - if (strrpos(SELF_URL_PATH, "/") === strlen(SELF_URL_PATH)-1) { |
|
1502 | - return substr(SELF_URL_PATH, 0, strlen(SELF_URL_PATH)-1); |
|
1500 | + if (strrpos(SELF_URL_PATH, "/") === strlen(SELF_URL_PATH) - 1) { |
|
1501 | + return substr(SELF_URL_PATH, 0, strlen(SELF_URL_PATH) - 1); |
|
1503 | 1502 | } else { |
1504 | 1503 | return SELF_URL_PATH; |
1505 | 1504 | } |
@@ -1508,11 +1507,11 @@ discard block |
||
1508 | 1507 | /* TODO: This needs to use bcrypt */ |
1509 | 1508 | function encrypt_password($pass, $salt = '', $mode2 = false) { |
1510 | 1509 | if ($salt && $mode2) { |
1511 | - return "MODE2:" . hash('sha256', $salt . $pass); |
|
1510 | + return "MODE2:".hash('sha256', $salt.$pass); |
|
1512 | 1511 | } else if ($salt) { |
1513 | - return "SHA1X:" . sha1("$salt:$pass"); |
|
1512 | + return "SHA1X:".sha1("$salt:$pass"); |
|
1514 | 1513 | } else { |
1515 | - return "SHA1:" . sha1($pass); |
|
1514 | + return "SHA1:".sha1($pass); |
|
1516 | 1515 | } |
1517 | 1516 | } |
1518 | 1517 | |
@@ -1523,7 +1522,7 @@ discard block |
||
1523 | 1522 | } |
1524 | 1523 | |
1525 | 1524 | function build_url($parts) { |
1526 | - return $parts['scheme'] . "://" . $parts['host'] . $parts['path']; |
|
1525 | + return $parts['scheme']."://".$parts['host'].$parts['path']; |
|
1527 | 1526 | } |
1528 | 1527 | |
1529 | 1528 | function cleanup_url_path($path) { |
@@ -1567,7 +1566,7 @@ discard block |
||
1567 | 1566 | $dir = dirname($parts['path']); |
1568 | 1567 | $dir !== '/' && $dir .= '/'; |
1569 | 1568 | } |
1570 | - $parts['path'] = $dir . $rel_url; |
|
1569 | + $parts['path'] = $dir.$rel_url; |
|
1571 | 1570 | $parts['path'] = cleanup_url_path($parts['path']); |
1572 | 1571 | |
1573 | 1572 | return build_url($parts); |
@@ -1654,12 +1653,12 @@ discard block |
||
1654 | 1653 | |
1655 | 1654 | for ($i = 0; $i < $l10n->total; $i++) { |
1656 | 1655 | $orig = $l10n->get_original_string($i); |
1657 | - if(strpos($orig, "\000") !== false) { // Plural forms |
|
1656 | + if (strpos($orig, "\000") !== false) { // Plural forms |
|
1658 | 1657 | $key = explode(chr(0), $orig); |
1659 | 1658 | print T_js_decl($key[0], _ngettext($key[0], $key[1], 1)); // Singular |
1660 | 1659 | print T_js_decl($key[1], _ngettext($key[0], $key[1], 2)); // Plural |
1661 | 1660 | } else { |
1662 | - $translation = _dgettext($domain,$orig); |
|
1661 | + $translation = _dgettext($domain, $orig); |
|
1663 | 1662 | print T_js_decl($orig, $translation); |
1664 | 1663 | } |
1665 | 1664 | } |
@@ -1715,7 +1714,7 @@ discard block |
||
1715 | 1714 | if (file_exists($filename)) { |
1716 | 1715 | $ext = pathinfo($filename, PATHINFO_EXTENSION); |
1717 | 1716 | |
1718 | - return "data:image/$ext;base64," . base64_encode(file_get_contents($filename)); |
|
1717 | + return "data:image/$ext;base64,".base64_encode(file_get_contents($filename)); |
|
1719 | 1718 | } else { |
1720 | 1719 | return ""; |
1721 | 1720 | } |
@@ -1752,7 +1751,7 @@ discard block |
||
1752 | 1751 | |
1753 | 1752 | header("Content-type: $mimetype"); |
1754 | 1753 | |
1755 | - $stamp = gmdate("D, d M Y H:i:s", filemtime($filename)) . " GMT"; |
|
1754 | + $stamp = gmdate("D, d M Y H:i:s", filemtime($filename))." GMT"; |
|
1756 | 1755 | header("Last-Modified: $stamp", true); |
1757 | 1756 | |
1758 | 1757 | return readfile($filename); |
@@ -1762,7 +1761,7 @@ discard block |
||
1762 | 1761 | } |
1763 | 1762 | |
1764 | 1763 | function arr_qmarks($arr) { |
1765 | - return str_repeat('?,', count($arr) - 1) . '?'; |
|
1764 | + return str_repeat('?,', count($arr) - 1).'?'; |
|
1766 | 1765 | } |
1767 | 1766 | |
1768 | 1767 | function get_scripts_timestamp() { |
@@ -1797,7 +1796,7 @@ discard block |
||
1797 | 1796 | } else if (PHP_OS === "Darwin") { |
1798 | 1797 | $ttrss_version = "UNKNOWN (Unsupported, Darwin)"; |
1799 | 1798 | } else if (file_exists("$root_dir/version_static.txt")) { |
1800 | - $ttrss_version = trim(file_get_contents("$root_dir/version_static.txt")) . " (Unsupported)"; |
|
1799 | + $ttrss_version = trim(file_get_contents("$root_dir/version_static.txt"))." (Unsupported)"; |
|
1801 | 1800 | } else if (is_dir("$root_dir/.git")) { |
1802 | 1801 | $rc = 0; |
1803 | 1802 | $output = []; |
@@ -1815,10 +1814,10 @@ discard block |
||
1815 | 1814 | $git_commit = $commit; |
1816 | 1815 | $git_timestamp = $timestamp; |
1817 | 1816 | |
1818 | - $ttrss_version = strftime("%y.%m", $timestamp) . "-$commit"; |
|
1817 | + $ttrss_version = strftime("%y.%m", $timestamp)."-$commit"; |
|
1819 | 1818 | } |
1820 | 1819 | } else { |
1821 | - user_error("Unable to determine version (using $root_dir): " . implode("\n", $output), E_USER_WARNING); |
|
1820 | + user_error("Unable to determine version (using $root_dir): ".implode("\n", $output), E_USER_WARNING); |
|
1822 | 1821 | } |
1823 | 1822 | } |
1824 | 1823 |