Commit 211f5282 authored by Andrey's avatar Andrey

Can print rows/cols with mixed chinese/non-chinese texts.

parent 422ba482
...@@ -12,6 +12,7 @@ import 'pos_styles.dart'; ...@@ -12,6 +12,7 @@ import 'pos_styles.dart';
class PosColumn { class PosColumn {
PosColumn({ PosColumn({
this.text = '', this.text = '',
this.containsChinese = false,
this.width = 2, this.width = 2,
this.styles = const PosStyles(), this.styles = const PosStyles(),
}) { }) {
...@@ -21,6 +22,7 @@ class PosColumn { ...@@ -21,6 +22,7 @@ class PosColumn {
} }
String text; String text;
bool containsChinese;
int width; int width;
PosStyles styles; PosStyles styles;
} }
...@@ -165,19 +165,14 @@ class Printer { ...@@ -165,19 +165,14 @@ class Printer {
} }
} }
/// Prints one line of styled mixed (chinese and latin symbols) text /// Break text into chinese/non-chinese lexemes
void _printlnMixedKanji( List _getLexemes(String text) {
String text, {
PosStyles styles = const PosStyles(),
int linesAfter = 0,
}) {
// Break text into lexemes
final List<String> lexemes = [];
final List<bool> isLexemeChinese = [];
bool _isChinese(String ch) { bool _isChinese(String ch) {
return ch.codeUnitAt(0) > 255 ? true : false; return ch.codeUnitAt(0) > 255 ? true : false;
} }
final List<String> lexemes = [];
final List<bool> isLexemeChinese = [];
int start = 0; int start = 0;
int end = 0; int end = 0;
bool curLexemeChinese = _isChinese(text[0]); bool curLexemeChinese = _isChinese(text[0]);
...@@ -195,6 +190,19 @@ class Printer { ...@@ -195,6 +190,19 @@ class Printer {
lexemes.add(text.substring(start, end + 1)); lexemes.add(text.substring(start, end + 1));
isLexemeChinese.add(curLexemeChinese); isLexemeChinese.add(curLexemeChinese);
return <dynamic>[lexemes, isLexemeChinese];
}
/// Prints one line of styled mixed (chinese and latin symbols) text
void _printlnMixedKanji(
String text, {
PosStyles styles = const PosStyles(),
int linesAfter = 0,
}) {
final list = _getLexemes(text);
final List<String> lexemes = list[0];
final List<bool> isLexemeChinese = list[1];
// Print each lexeme using codetable OR kanji // Print each lexeme using codetable OR kanji
for (var i = 0; i < lexemes.length; ++i) { for (var i = 0; i < lexemes.length; ++i) {
_print( _print(
...@@ -250,12 +258,29 @@ class Printer { ...@@ -250,12 +258,29 @@ class Printer {
for (int i = 0; i < cols.length; ++i) { for (int i = 0; i < cols.length; ++i) {
final colInd = final colInd =
cols.sublist(0, i).fold(0, (int sum, col) => sum + col.width); cols.sublist(0, i).fold(0, (int sum, col) => sum + col.width);
if (!cols[i].containsChinese) {
_print( _print(
cols[i].text, cols[i].text,
styles: cols[i].styles, styles: cols[i].styles,
colInd: colInd, colInd: colInd,
colWidth: cols[i].width, colWidth: cols[i].width,
); );
} else {
final list = _getLexemes(cols[i].text);
final List<String> lexemes = list[0];
final List<bool> isLexemeChinese = list[1];
// Print each lexeme using codetable OR kanji
for (var j = 0; j < lexemes.length; ++j) {
_print(
lexemes[j],
styles: cols[i].styles,
colInd: colInd,
colWidth: cols[i].width,
kanjiOff: !isLexemeChinese[j],
);
}
}
} }
_socket.writeln(); _socket.writeln();
......
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