1 var Mode = require('./mode')
2 var Utils = require('./utils')
4 function KanjiData (data) {
9 KanjiData.getBitsLength = function getBitsLength (length) {
13 KanjiData.prototype.getLength = function getLength () {
14 return this.data.length
17 KanjiData.prototype.getBitsLength = function getBitsLength () {
18 return KanjiData.getBitsLength(this.data.length)
21 KanjiData.prototype.write = function (bitBuffer) {
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])
30 // For characters with Shift JIS values from 0x8140 to 0x9FFC:
31 if (value >= 0x8140 && value <= 0x9FFC) {
32 // Subtract 0x8140 from Shift JIS value
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
41 'Invalid SJIS character: ' + this.data[i] + '\n' +
42 'Make sure your charset is UTF-8')
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)
49 // Convert result to a 13-bit binary string
50 bitBuffer.put(value, 13)
54 module.exports = KanjiData