| 1 | <?php |
||
| 22 | class Kanji extends QRDataAbstract{ |
||
| 23 | |||
| 24 | protected int $datamode = QRCode::DATA_KANJI; |
||
|
|
|||
| 25 | |||
| 26 | protected array $lengthBits = [8, 10, 12]; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @inheritdoc |
||
| 30 | */ |
||
| 31 | protected function getLength(string $data):int{ |
||
| 32 | return mb_strlen($data, 'SJIS'); |
||
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @inheritdoc |
||
| 37 | */ |
||
| 38 | protected function write(string $data):void{ |
||
| 39 | $len = strlen($data); |
||
| 40 | |||
| 41 | for($i = 0; $i + 1 < $len; $i += 2){ |
||
| 42 | $c = ((0xff & ord($data[$i])) << 8) | (0xff & ord($data[$i + 1])); |
||
| 43 | |||
| 44 | if(0x8140 <= $c && $c <= 0x9FFC){ |
||
| 45 | $c -= 0x8140; |
||
| 46 | } |
||
| 47 | elseif(0xE040 <= $c && $c <= 0xEBBF){ |
||
| 48 | $c -= 0xC140; |
||
| 49 | } |
||
| 50 | else{ |
||
| 51 | throw new QRCodeDataException(sprintf('illegal char at %d [%d]', $i + 1, $c)); |
||
| 52 | } |
||
| 53 | |||
| 54 | $this->bitBuffer->put((($c >> 8) & 0xff) * 0xC0 + ($c & 0xff), 13); |
||
| 55 | |||
| 56 | } |
||
| 57 | |||
| 58 | if($i < $len){ |
||
| 59 | throw new QRCodeDataException(sprintf('illegal char at %d', $i + 1)); |
||
| 60 | } |
||
| 61 | |||
| 62 | } |
||
| 63 | |||
| 64 | } |
||
| 65 |