[SignalingServer] Optimize dependent modules
[platform/framework/web/wrtjs.git] / device_home / node_modules / qrcode / lib / core / kanji-data.js
1 var Mode = require('./mode')
2 var Utils = require('./utils')
3
4 function KanjiData (data) {
5   this.mode = Mode.KANJI
6   this.data = data
7 }
8
9 KanjiData.getBitsLength = function getBitsLength (length) {
10   return length * 13
11 }
12
13 KanjiData.prototype.getLength = function getLength () {
14   return this.data.length
15 }
16
17 KanjiData.prototype.getBitsLength = function getBitsLength () {
18   return KanjiData.getBitsLength(this.data.length)
19 }
20
21 KanjiData.prototype.write = function (bitBuffer) {
22   var i
23
24   // In the Shift JIS system, Kanji characters are represented by a two byte combination.
25   // These byte values are shifted from the JIS X 0208 values.
26   // JIS X 0208 gives details of the shift coded representation.
27   for (i = 0; i < this.data.length; i++) {
28     var value = Utils.toSJIS(this.data[i])
29
30     // For characters with Shift JIS values from 0x8140 to 0x9FFC:
31     if (value >= 0x8140 && value <= 0x9FFC) {
32       // Subtract 0x8140 from Shift JIS value
33       value -= 0x8140
34
35     // For characters with Shift JIS values from 0xE040 to 0xEBBF
36     } else if (value >= 0xE040 && value <= 0xEBBF) {
37       // Subtract 0xC140 from Shift JIS value
38       value -= 0xC140
39     } else {
40       throw new Error(
41         'Invalid SJIS character: ' + this.data[i] + '\n' +
42         'Make sure your charset is UTF-8')
43     }
44
45     // Multiply most significant byte of result by 0xC0
46     // and add least significant byte to product
47     value = (((value >>> 8) & 0xff) * 0xC0) + (value & 0xff)
48
49     // Convert result to a 13-bit binary string
50     bitBuffer.put(value, 13)
51   }
52 }
53
54 module.exports = KanjiData