From 68edb22aa848166d674d4307b2f4aab69cd17452 Mon Sep 17 00:00:00 2001 From: rhyme Date: Mon, 28 Feb 2022 09:42:28 +0800 Subject: [PATCH 1/4] image method support single density (TM-U220) --- lib/src/generator.dart | 17 ++++++---- pubspec.lock | 75 +++++++++++++++++++++++------------------- 2 files changed, 52 insertions(+), 40 deletions(-) diff --git a/lib/src/generator.dart b/lib/src/generator.dart index 6b464a6..d56a5ee 100644 --- a/lib/src/generator.dart +++ b/lib/src/generator.dart @@ -22,9 +22,11 @@ class Generator { final PaperSize _paperSize; CapabilityProfile _profile; int? _maxCharsPerLine; + // Global styles String? _codeTable; PosFontType? _font; + // Current styles PosStyles _styles = PosStyles(); int spaceBetweenRows; @@ -217,6 +219,7 @@ class Generator { return ((0xFFFFFFFF ^ (0x1 << shift)) & uint32) | ((newValue ? 1 : 0) << shift); } + // ************************ (end) Internal helpers ************************ //**************************** Public command generators ************************ @@ -567,20 +570,21 @@ class Generator { /// Print an image using (ESC *) command /// /// [image] is an instanse of class from [Image library](https://pub.dev/packages/image) - List image(Image imgSrc, {PosAlign align = PosAlign.center}) { + List image(Image imgSrc, + {PosAlign align = PosAlign.center, bool isDoubleDensity = true}) { List bytes = []; // Image alignment bytes += setStyles(PosStyles().copyWith(align: align)); final Image image = Image.from(imgSrc); // make a copy - const bool highDensityHorizontal = true; - const bool highDensityVertical = true; + bool highDensityHorizontal = isDoubleDensity; + bool highDensityVertical = isDoubleDensity; invert(image); flip(image, Flip.horizontal); final Image imageRotated = copyRotate(image, 270); - const int lineHeight = highDensityVertical ? 3 : 1; + int lineHeight = highDensityVertical ? 3 : 1; final List> blobs = _toColumnFormat(imageRotated, lineHeight * 8); // Compress according to line density @@ -592,7 +596,7 @@ class Generator { } final int heightPx = imageRotated.height; - const int densityByte = + int densityByte = (highDensityHorizontal ? 1 : 0) + (highDensityVertical ? 32 : 0); final List header = List.from(cBitImg.codeUnits); @@ -754,6 +758,7 @@ class Generator { bytes += emptyLines(linesAfter + 1); return bytes; } + // ************************ (end) Public command generators ************************ // ************************ (end) Internal command generators ************************ @@ -835,5 +840,5 @@ class Generator { bytes += emptyLines(linesAfter + 1); return bytes; } - // ************************ (end) Internal command generators ************************ +// ************************ (end) Internal command generators ************************ } diff --git a/pubspec.lock b/pubspec.lock index 3447480..7084936 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -5,70 +5,70 @@ packages: dependency: transitive description: name: archive - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "3.1.2" + version: "3.2.1" async: dependency: transitive description: name: async - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.8.2" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.1.0" characters: dependency: transitive description: name: characters - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.2.0" charcode: dependency: transitive description: name: charcode - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.3.1" clock: dependency: transitive description: name: clock - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.1.0" collection: dependency: transitive description: name: collection - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.15.0" crypto: dependency: transitive description: name: crypto - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "3.0.1" csslib: dependency: transitive description: name: csslib - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "0.17.0" + version: "0.17.1" fake_async: dependency: transitive description: name: fake_async - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.2.0" flutter: @@ -85,58 +85,65 @@ packages: dependency: "direct main" description: name: gbk_codec - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "0.4.0" hex: dependency: "direct main" description: name: hex - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "0.2.0" html: dependency: transitive description: name: html - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "0.15.0" image: dependency: "direct main" description: name: image - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "3.0.5" + version: "3.1.3" matcher: dependency: transitive description: name: matcher - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "0.12.11" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.1.3" meta: dependency: transitive description: name: meta - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.7.0" path: dependency: transitive description: name: path - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.8.0" petitparser: dependency: transitive description: name: petitparser - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "4.3.0" + version: "4.4.0" sky_engine: dependency: transitive description: flutter @@ -146,64 +153,64 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.8.1" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.2.0" test_api: dependency: transitive description: name: test_api - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "0.4.3" + version: "0.4.8" typed_data: dependency: transitive description: name: typed_data - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.3.0" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.0" + version: "2.1.1" xml: dependency: transitive description: name: xml - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "5.3.0" + version: "5.3.1" sdks: dart: ">=2.14.0 <3.0.0" From df3d8c7f85ceed31a8cca69fd9db3651643da9ff Mon Sep 17 00:00:00 2001 From: rhyme Date: Tue, 1 Mar 2022 09:45:51 +0800 Subject: [PATCH 2/4] update --- lib/src/generator.dart | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/src/generator.dart b/lib/src/generator.dart index d56a5ee..a24fa62 100644 --- a/lib/src/generator.dart +++ b/lib/src/generator.dart @@ -576,7 +576,12 @@ class Generator { // Image alignment bytes += setStyles(PosStyles().copyWith(align: align)); - final Image image = Image.from(imgSrc); // make a copy + Image image; + if (!isDoubleDensity) { + image = copyResize(imgSrc,width: imgSrc.width~/2); + } else { + image = Image.from(imgSrc); // make a copy + } bool highDensityHorizontal = isDoubleDensity; bool highDensityVertical = isDoubleDensity; From adf11f5702523e17938bf83a4965c31795eebfe1 Mon Sep 17 00:00:00 2001 From: rhyme Date: Tue, 1 Mar 2022 21:05:01 +0800 Subject: [PATCH 3/4] update --- lib/src/generator.dart | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/src/generator.dart b/lib/src/generator.dart index a24fa62..bc57de0 100644 --- a/lib/src/generator.dart +++ b/lib/src/generator.dart @@ -146,7 +146,8 @@ class Generator { final int heightPx = image.height; // Create a black bottom layer - final biggerImage = copyResize(image, width: widthPx, height: heightPx); + final biggerImage = copyResize(image, + width: widthPx, height: heightPx, interpolation: Interpolation.linear); fill(biggerImage, 0); // Insert source image into bigger one drawImage(biggerImage, image, dstX: 0, dstY: 0); @@ -578,7 +579,12 @@ class Generator { Image image; if (!isDoubleDensity) { - image = copyResize(imgSrc,width: imgSrc.width~/2); + int size = 558 ~/ 2; + if (_paperSize == PaperSize.mm58) { + size = 375 ~/ 2; + } + image = + copyResize(imgSrc, width: size, interpolation: Interpolation.linear); } else { image = Image.from(imgSrc); // make a copy } @@ -590,6 +596,7 @@ class Generator { final Image imageRotated = copyRotate(image, 270); int lineHeight = highDensityVertical ? 3 : 1; + final List> blobs = _toColumnFormat(imageRotated, lineHeight * 8); // Compress according to line density From f6a163cc7cde66bae7f008b3c08e79548e045e4c Mon Sep 17 00:00:00 2001 From: rhyme Date: Thu, 30 Jun 2022 14:38:30 +0800 Subject: [PATCH 4/4] add speech --- lib/src/commands.dart | 3 +++ lib/src/generator.dart | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/src/commands.dart b/lib/src/commands.dart index 34d9994..46e3c21 100644 --- a/lib/src/commands.dart +++ b/lib/src/commands.dart @@ -66,3 +66,6 @@ const cCashDrawerPin5 = '${esc}p130'; // QR Code const cQrHeader = '$gs(k'; + +//Print control mode +const cControlHeader = '$gs(K'; diff --git a/lib/src/generator.dart b/lib/src/generator.dart index bc57de0..888e4b1 100644 --- a/lib/src/generator.dart +++ b/lib/src/generator.dart @@ -737,6 +737,17 @@ class Generator { return bytes; } + //0 - 17 + //or 48 - 59 + //TM-T82II m = 0 – 11, 48 – 59 + List printSpeech(int level) { + List bytes = []; + // FN 167. QR Code: Set the size of module + // pL pH fn m + bytes += cControlHeader.codeUnits + [0x02, 0x00, 0x32, level]; + return bytes; + } + /// Open cash drawer List drawer({PosDrawer pin = PosDrawer.pin2}) { List bytes = [];