Commit 35f1a446 authored by Andrey's avatar Andrey

Added height/width size. Added cut mode. Fixed feed and reverse feed bugs.

parent 2d8cc467
import 'package:esc_pos_printer/esc_pos_printer.dart';
import 'package:esc_pos_printer/src/printer.dart';
main() {
Printer.connect('192.168.0.123').then((printer) {
printer.reset();
printer.println('Normal text');
printer.println('Bold text', bold: true);
printer.println('Reverse text', reverse: true);
printer.println('Underlined text', underline: true);
printer.println('Align left', align: TextAlign.left);
printer.println('Align center', align: TextAlign.center);
printer.println('Align right', align: TextAlign.right);
printer.println('Align left', align: PosTextAlign.left);
printer.println('Align center', align: PosTextAlign.center);
printer.println('Align right', align: PosTextAlign.right);
printer.cut();
......
......@@ -12,7 +12,8 @@ const cCutPart = '${esc}m'; // Execute paper partial cut.
// Character
const cReverseOn = '${gs}B1'; // Turn white/black reverse print mode on
const cReverseOff = '${gs}B0'; // Turn white/black reverse print mode off
const cSizeN = '$gs!'; // Select character size [N]
const cSizeGSn = '$gs!'; // Select character size [N]
const cSizeESCn = '$esc!'; // Select character size [N]
const cUnderlineOff = '$esc-0'; // Turns off underline mode
const cUnderline1dot = '$esc-1'; // Turns on underline mode (1-dot thick)
const cUnderline2dots = '$esc-2'; // Turns on underline mode (2-dots thick)
......
import 'dart:io';
import 'dart:typed_data';
import 'commands.dart';
enum TextAlign { left, center, right }
enum CutMode { normal, partial, full }
enum PosTextAlign { left, center, right }
enum PosCutMode { normal, partial, full }
class PosTextSizeHeight {
final value;
const PosTextSizeHeight._internal(this.value);
static const normal = const PosTextSizeHeight._internal(0x00);
static const double = const PosTextSizeHeight._internal(0x10);
}
class PosTextSizeWidth {
final value;
const PosTextSizeWidth._internal(this.value);
static const normal = const PosTextSizeWidth._internal(0x00);
static const double = const PosTextSizeWidth._internal(0x20);
}
/// Abstract printer.
class Printer {
......@@ -46,22 +61,24 @@ class Printer {
bool bold = false,
bool reverse = false,
bool underline = false,
TextAlign align = TextAlign.left,
int charHeight = -1, // TODO replace by font size
int charWidth = -1,
PosTextAlign align = PosTextAlign.left,
PosTextSizeHeight height = PosTextSizeHeight.normal,
PosTextSizeWidth width = PosTextSizeWidth.normal,
int linesAfter = 0,
}) {
_socket.write(bold ? cBoldOn : cBoldOff);
_socket.write(reverse ? cReverseOn : cReverseOff);
_socket.write(underline ? cUnderline1dot : cUnderlineOff);
_socket.write(align == TextAlign.left
_socket.write(align == PosTextAlign.left
? cAlignLeft
: (align == TextAlign.center ? cAlignCenter : cAlignRight));
: (align == PosTextAlign.center ? cAlignCenter : cAlignRight));
if (charHeight > 0 && charWidth > 0) {
var n = 16 * (charWidth - 1) + (charHeight - 1);
_socket.writeAll([cSizeN, n]);
}
// Font size
_socket.add(
Uint8List.fromList(
List.from(cSizeESCn.codeUnits)..add(height.value + width.value),
),
);
_socket.writeln(text);
emptyLines(linesAfter);
......@@ -80,19 +97,27 @@ class Printer {
void feed(int n) {
if (n >= 0 && n <= 255) {
_socket.writeAll([cFeedN, n.toString()]);
_socket.add(
Uint8List.fromList(
List.from(cFeedN.codeUnits)..add(n),
),
);
}
}
void reverseFeed(int n) {
_socket.writeAll([cReverseFeedN, n.toString()]);
_socket.add(
Uint8List.fromList(
List.from(cReverseFeedN.codeUnits)..add(n),
),
);
}
void cut({CutMode mode = CutMode.normal}) {
void cut({PosCutMode mode = PosCutMode.normal}) {
_socket.write('\n\n\n\n\n');
if (mode == CutMode.partial) {
if (mode == PosCutMode.partial) {
_socket.write(cCutPart);
} else if (mode == CutMode.full) {
} else if (mode == PosCutMode.full) {
_socket.write(cCutFull);
} else {
_socket.write(cCut);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment