Commit 3f4b0782 authored by Andrey's avatar Andrey

Added code pages support

parent ade19f67
......@@ -8,6 +8,7 @@
const esc = '\x1B';
const gs = '\x1D';
const fs = '\x1C';
// Miscellaneous
const cInit = '$esc@'; // Initialize printer
......@@ -32,6 +33,7 @@ const cFontB = '${esc}M1'; // Font B
const cTurn90On = '${esc}V1'; // Turn 90° clockwise rotation mode on
const cTurn90Off = '${esc}V0'; // Turn 90° clockwise rotation mode off
const cCodeTable = '${esc}t'; // Select character code table [N]
const cKanjiCancel = '$fs.'; // Cancel Kanji character mode
// Print Position
const cAlignLeft = '${esc}a0'; // Left justification
......
......@@ -19,6 +19,7 @@ class PosStyles {
this.height = PosTextSize.size1,
this.width = PosTextSize.size1,
this.fontType = PosFontType.fontA,
this.codeTable,
});
final bool bold;
......@@ -29,4 +30,5 @@ class PosStyles {
final PosTextSize height;
final PosTextSize width;
final PosFontType fontType;
final PosCodeTable codeTable;
}
......@@ -21,7 +21,7 @@ class Printer {
}
final Socket _socket;
PosCodeTable _codeTable = PosCodeTable.pc437;
PosCodeTable _codeTable;
/// Creates a new socket connection to the network printer.
///
......@@ -42,13 +42,16 @@ class Printer {
_socket.destroy();
}
void setCodeTable(PosCodeTable codeTable) {
/// Set global code table which will be used instead of the default printer's code table
void setGlobalCodeTable(PosCodeTable codeTable) {
_codeTable = codeTable;
_socket.add(
Uint8List.fromList(
List.from(cCodeTable.codeUnits)..add(codeTable.value),
),
);
if (codeTable != null) {
_socket.add(
Uint8List.fromList(
List.from(cCodeTable.codeUnits)..add(codeTable.value),
),
);
}
}
/// Generic print for internal use
......@@ -63,7 +66,6 @@ class Printer {
final int pos = colInd == 0 ? 0 : (512 * colInd / 11 - 1).round();
final hexStr = pos.toRadixString(16).padLeft(3, '0');
final hexPair = HEX.decode(hexStr);
// print('dec: $pos \t hex: $hexStr \t pair $hexPair');
_socket.write(styles.bold ? cBoldOn : cBoldOff);
_socket.write(styles.turn90 ? cTurn90On : cTurn90Off);
......@@ -87,7 +89,16 @@ class Printer {
),
);
_socket.write(cKanjiCancel);
if (styles.codeTable != null) {
_socket.add(
Uint8List.fromList(
List.from(cCodeTable.codeUnits)..add(styles.codeTable.value),
),
);
}
_socket.write(text);
// TOOD Kanji set
}
/// Sens raw command(s)
......@@ -107,6 +118,32 @@ class Printer {
reset();
}
/// Print selected code table.
///
/// If [codeTable] is null, global code table is used.
/// If global code table is null, default printer code table is used.
void printCodeTable({PosCodeTable codeTable}) {
_socket.write(cKanjiCancel);
if (codeTable != null) {
_socket.add(
Uint8List.fromList(
List.from(cCodeTable.codeUnits)..add(codeTable.value),
),
);
}
final List<int> list = [];
for (int i = 0; i < 256; i++) {
list.add(i);
}
_socket.add(
Uint8List.fromList(List.from(list)),
);
reset();
}
/// Print a row.
///
/// A row contains up to 12 columns. A column has a width between 1 and 12.
......@@ -152,7 +189,7 @@ class Printer {
/// Clear the buffer and reset text styles
void reset() {
_socket.write(cInit);
setCodeTable(_codeTable);
setGlobalCodeTable(_codeTable);
}
/// Skips [n] lines
......
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