2017-12-03 04:45:02 +00:00
|
|
|
/*globals debug: false */
|
2013-10-10 18:03:07 +00:00
|
|
|
/*exported Printer */
|
|
|
|
|
|
|
|
function Printer() {
|
|
|
|
var _printer = null;
|
2017-12-03 04:45:02 +00:00
|
|
|
var _linebuffer = '';
|
|
|
|
|
2013-10-10 18:03:07 +00:00
|
|
|
return {
|
|
|
|
putChar: function(val) {
|
|
|
|
if (!_printer || _printer.closed) {
|
2016-11-22 05:17:34 +00:00
|
|
|
_printer = window.open('', '_blank','toolbar=0,location=0');
|
2016-11-28 01:28:49 +00:00
|
|
|
if (_printer) {
|
|
|
|
_printer.document.title = 'Printer';
|
|
|
|
_printer.document.write('<div style="font: 12px courier">');
|
|
|
|
_printer.document.write('<span>');
|
|
|
|
window.focus();
|
|
|
|
}
|
2013-10-10 18:03:07 +00:00
|
|
|
}
|
2017-12-03 04:45:02 +00:00
|
|
|
var c = String.fromCharCode(val & 0x7f);
|
2016-11-28 01:28:49 +00:00
|
|
|
if (_printer) {
|
|
|
|
if (c == '\r') {
|
|
|
|
_printer.document.write('<br /></span>');
|
|
|
|
} else if (c == ' ') {
|
|
|
|
_printer.document.write(' ');
|
|
|
|
} else {
|
|
|
|
_printer.document.write(c);
|
|
|
|
}
|
2017-12-03 04:45:02 +00:00
|
|
|
} else {
|
|
|
|
if (c == '\r') {
|
|
|
|
debug(_linebuffer);
|
|
|
|
_linebuffer = '';
|
|
|
|
} else if (c == ' ') {
|
|
|
|
_linebuffer += c;
|
|
|
|
}
|
2013-10-10 18:03:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|