Last active
March 19, 2020 02:20
-
-
Save tresf/1a07be4af2fd4a6acb64c3fd19ef0ee4 to your computer and use it in GitHub Desktop.
Crude UTF-8 to KZ-1048 conversion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Author: A. Tres Finocchiaro | |
* Date: 2020-03-18 | |
* License: Public Domain | |
*/ | |
// Crude UTF-8 to KZ-1048 conversion | |
const KZ_1048 = { | |
'Ђ' : '\x80', 'Ѓ' : '\x81', 'ѓ' : '\x83', '€' : '\x88', 'Љ' : '\x8A', 'Њ' : '\x8C', 'Қ' : '\x8D', 'Һ' : '\x8E', 'Џ' : '\x8F', | |
'ђ' : '\x90', 'љ' : '\x9A', 'њ' : '\x9C', 'қ' : '\x9D', 'һ' : '\x9E', 'џ' : '\x9F', | |
'Ұ' : '\xA1', 'ұ' : '\xA2', 'Ә' : '\xA3', '¤' : '\xA4', 'Ө' : '\xA5', '¦' : '\xA6', 'Ё' : '\xA8', 'Ғ' : '\xAA', 'Ү' : '\xAF', | |
'І' : '\xB2', 'і' : '\xB3', 'ө' : '\xB4', 'µ' : '\xB5', 'ё' : '\xB8', '№' : '\xB9', 'ғ' : '\xBA', 'ә' : '\xBC', 'Ң' : '\xBD', 'ң' : '\xBE', 'ү' : '\xBF', | |
'А' : '\xC0', 'Б' : '\xC1', 'В' : '\xC2', 'Г' : '\xC3', 'Д' : '\xC4', 'Е' : '\xC5', 'Ж' : '\xC6', 'З' : '\xC7', 'И' : '\xC8', 'Й' : '\xC9', 'К' : '\xCA', 'Л' : '\xCB', 'М' : '\xCC', 'Н' : '\xCD', 'О' : '\xCE', 'П' : '\xCF', | |
'Р' : '\xD0', 'С' : '\xD1', 'Т' : '\xD2', 'У' : '\xD3', 'Ф' : '\xD4', 'Х' : '\xD5', 'Ц' : '\xD6', 'Ч' : '\xD7', 'Ш' : '\xD8', 'Щ' : '\xD9', 'Ъ' : '\xDA', 'Ы' : '\xDB', 'Ь' : '\xDC', 'Э' : '\xDD', 'Ю' : '\xDE', 'Я' : '\xDF', | |
'а' : '\xE0', 'б' : '\xE1', 'в' : '\xE2', 'г' : '\xE3', 'д' : '\xE4', 'е' : '\xE5', 'ж' : '\xE6', 'з' : '\xE7', 'и' : '\xE8', 'й' : '\xE9', 'к' : '\xEA', 'л' : '\xEB', 'м' : '\xEC', 'н' : '\xED', 'о' : '\xEE', 'п' : '\xEF', | |
'р' : '\xF0', 'с' : '\xF1', 'т' : '\xF2', 'у' : '\xF3', 'ф' : '\xF4', 'х' : '\xF5', 'ц' : '\xF6', 'ч' : '\xF7', 'ш' : '\xF8', 'щ' : '\xF9', 'ъ' : '\xFA', 'ы' : '\xFB', 'ь' : '\xFC', 'э' : '\xFD', 'ю' : '\xFE', 'я' : '\xFF' | |
} | |
// Crude character replacement | |
function convert(map, str) { | |
for (var char in map) { | |
if (map.hasOwnProperty(char) && str.indexOf(char) !== -1) { | |
var re = new RegExp(char, 'g'); | |
str = str.replace(re, map[char]); | |
} | |
} | |
return str; | |
} | |
var text = 'Қазақтың әйгілі күйші композиторы,\nдирижері, қазақтың музыкалық мәдениетіне\nөшпес із қалдырған Нұрғиса Тілендиевке\n1998 жылы Халық Қаһарманы атағы берілді.'; | |
// and then send it to a printer, etc | |
// Use an encoding which will preserve the bytes exactly | |
var config = qz.configs.create('TM-T88', { encoding: 'ISO-8859-1' }); | |
// Prepare our data | |
var data = [ | |
/* Toggle KZ-1048 in ESCPOS */ | |
'\x1B' + '\x74' + '\x35', // ESC t 53 (decimal) = KZ-1048: Kazakhstan | |
convert(KZ_1048, text) + '\n\n\n\n\n\n' | |
]; | |
// Send it to the printer | |
qz.print(config, data); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment