diff --git a/lib/esc_pos_utils.dart b/lib/esc_pos_utils.dart index f757794..cb58905 100644 --- a/lib/esc_pos_utils.dart +++ b/lib/esc_pos_utils.dart @@ -13,3 +13,4 @@ export './src/enums.dart'; export './src/pos_column.dart'; export './src/pos_styles.dart'; export './src/ticket.dart'; +export './src/qrcode.dart'; diff --git a/lib/src/qrcode.dart b/lib/src/qrcode.dart new file mode 100644 index 0000000..278cdab --- /dev/null +++ b/lib/src/qrcode.dart @@ -0,0 +1,43 @@ + +import 'package:gbk_codec/gbk_codec.dart'; + +import 'enums.dart'; + +class QRSize { + const QRSize._internal(this.value); + final List value; + + static const Zero4 = QRSize._internal([0x1d, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x43, 0x04]); + + static const Zero5 = QRSize._internal([0x1d, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x43, 0x05]); + + static const Zero6 = QRSize._internal([0x1d, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x43, 0x06]); + + static const Zero7 = QRSize._internal([0x1d, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x43, 0x07]); + + static const Zero8 = QRSize._internal([0x1d, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x43, 0x08]); + +} + + +class QRCode { + List _data = []; + List get data => _data; + List _gbkText; + + QRCode(QRSize size, PosAlign align, String text){ + _data += size.value; + _data += [0x1d, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x45, 0x30]; + _gbkText = gbk_bytes.encode(text); + // 设置数据长度 + _data += [0x1d, 0x28, 0x6b, _gbkText.length + 3, 0x00, 0x31,0x50,0x30]; + _data += _gbkText; + + // 设置二维码位置 + _data += [0x1b ,0x61 ,align.index]; + _data += [0x1d, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x52, 0x30]; + _data += [0x1d, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x51, 0x30]; + + } + +} \ No newline at end of file diff --git a/lib/src/ticket.dart b/lib/src/ticket.dart index 63ecbdf..ab19b4b 100644 --- a/lib/src/ticket.dart +++ b/lib/src/ticket.dart @@ -8,6 +8,7 @@ import 'dart:convert'; import 'dart:typed_data' show Uint8List; +import 'package:esc_pos_utils/src/qrcode.dart'; import 'package:gbk_codec/gbk_codec.dart'; import 'package:hex/hex.dart'; import 'package:image/image.dart'; @@ -156,6 +157,7 @@ class Ticket { bool isKanji = false, int colWidth = 12, int maxCharsPerLine, + bool inline }) { // Calculate maxCharsPerLine int charsPerLine; @@ -194,9 +196,11 @@ class Ticket { final hexPair = HEX.decode(hexStr); // Position - bytes += Uint8List.fromList( - List.from(cPos.codeUnits)..addAll([hexPair[1], hexPair[0]]), - ); + if(!inline){ + bytes += Uint8List.fromList( + List.from(cPos.codeUnits)..addAll([hexPair[1], hexPair[0]]), + ); + } setStyles(styles, isKanji: isKanji); @@ -291,6 +295,7 @@ class Ticket { styles: styles, isKanji: isLexemeChinese[i], maxCharsPerLine: maxCharsPerLine, + inline: i>0 ); } @@ -352,6 +357,7 @@ class Ticket { colInd: colInd, colWidth: cols[i].width, isKanji: isLexemeChinese[j], + inline: j>0 ); } } @@ -628,6 +634,14 @@ class Ticket { } } + void qrcode( + QRCode code + ) { + // 固定头部,表明下面我要开始发功了 + bytes += [0x1b, 0x40]; + bytes += code.data; + } + /// Print a barcode /// /// [width] range and units are different depending on the printer model (some printers use 1..5). diff --git a/pubspec.lock b/pubspec.lock new file mode 100644 index 0000000..442f776 --- /dev/null +++ b/pubspec.lock @@ -0,0 +1,216 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + archive: + dependency: transitive + description: + name: archive + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.0.11" + args: + dependency: transitive + description: + name: args + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.5.2" + async: + dependency: transitive + description: + name: async + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.4.0" + boolean_selector: + dependency: transitive + description: + name: boolean_selector + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.5" + charcode: + dependency: transitive + description: + name: charcode + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.1.2" + collection: + dependency: transitive + description: + name: collection + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.14.11" + convert: + dependency: transitive + description: + name: convert + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.1.1" + crypto: + dependency: transitive + description: + name: crypto + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.1.3" + csslib: + dependency: transitive + description: + name: csslib + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.16.1" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + flutter_test: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" + gbk_codec: + dependency: "direct main" + description: + name: gbk_codec + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.3.2" + hex: + dependency: "direct main" + description: + name: hex + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.1.2" + html: + dependency: transitive + description: + name: html + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.14.0+3" + image: + dependency: "direct main" + description: + name: image + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.1.4" + matcher: + dependency: transitive + description: + name: matcher + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.12.6" + meta: + dependency: transitive + description: + name: meta + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.1.8" + path: + dependency: transitive + description: + name: path + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.6.4" + pedantic: + dependency: transitive + description: + name: pedantic + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.8.0+1" + petitparser: + dependency: transitive + description: + name: petitparser + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.4.0" + quiver: + dependency: transitive + description: + name: quiver + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.0.5" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.99" + source_span: + dependency: transitive + description: + name: source_span + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.5.5" + stack_trace: + dependency: transitive + description: + name: stack_trace + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.9.3" + stream_channel: + dependency: transitive + description: + name: stream_channel + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.0.0" + string_scanner: + dependency: transitive + description: + name: string_scanner + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.5" + term_glyph: + dependency: transitive + description: + name: term_glyph + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.1.0" + test_api: + dependency: transitive + description: + name: test_api + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.2.11" + typed_data: + dependency: transitive + description: + name: typed_data + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.1.6" + vector_math: + dependency: transitive + description: + name: vector_math + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.0.8" + xml: + dependency: transitive + description: + name: xml + url: "https://pub.flutter-io.cn" + source: hosted + version: "3.5.0" +sdks: + dart: ">=2.4.0 <3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 60be682..8fe6bc0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: esc_pos_utils description: Basic Flutter/Dart classes for ESC/POS printing. Ticket class generates ESC/POS commands that can be sent to a thermal printer. -version: 0.3.5 +version: 0.3.7 homepage: https://github.com/andrey-ushakov/esc_pos_utils environment: