diff --git a/example/example.dart b/example/example.dart index 85c0a1c..338256e 100644 --- a/example/example.dart +++ b/example/example.dart @@ -1,7 +1,7 @@ import 'package:image/image.dart'; import 'dart:typed_data'; import 'package:flutter/services.dart'; -import 'package:esc_pos_utils/esc_pos_utils.dart'; +import 'package:esc_pos_utils_plus/esc_pos_utils.dart'; Future main() async { final profile = await CapabilityProfile.load(); diff --git a/lib/src/capability_profile.dart b/lib/src/capability_profile.dart index 019bae2..adb6673 100644 --- a/lib/src/capability_profile.dart +++ b/lib/src/capability_profile.dart @@ -22,7 +22,7 @@ class CapabilityProfile { /// Public factory static Future load({String name = 'default'}) async { final content = await rootBundle - .loadString('packages/esc_pos_utils/resources/capabilities.json'); + .loadString('packages/esc_pos_utils_plus/resources/capabilities.json'); Map capabilities = json.decode(content); var profile = capabilities['profiles'][name]; @@ -57,7 +57,7 @@ class CapabilityProfile { static Future> getAvailableProfiles() async { final content = await rootBundle - .loadString('packages/esc_pos_utils/resources/capabilities.json'); + .loadString('packages/esc_pos_utils_plus/resources/capabilities.json'); Map capabilities = json.decode(content); var profiles = capabilities['profiles']; diff --git a/lib/src/generator.dart b/lib/src/generator.dart index 6b464a6..cf698e7 100644 --- a/lib/src/generator.dart +++ b/lib/src/generator.dart @@ -11,8 +11,7 @@ import 'dart:typed_data' show Uint8List; import 'package:hex/hex.dart'; import 'package:image/image.dart'; import 'package:gbk_codec/gbk_codec.dart'; -import 'package:esc_pos_utils/esc_pos_utils.dart'; -import 'enums.dart'; +import 'package:esc_pos_utils_plus/esc_pos_utils.dart'; import 'commands.dart'; class Generator { @@ -145,16 +144,19 @@ class Generator { // Create a black bottom layer final biggerImage = copyResize(image, width: widthPx, height: heightPx); - fill(biggerImage, 0); + fill(biggerImage, color: ColorRgb8(0, 0, 0)); // Insert source image into bigger one - drawImage(biggerImage, image, dstX: 0, dstY: 0); + compositeImage(biggerImage, image, dstX: 0, dstY: 0); int left = 0; final List> blobs = []; while (left < widthPx) { - final Image slice = copyCrop(biggerImage, left, 0, lineHeight, heightPx); - final Uint8List bytes = slice.getBytes(format: Format.luminance); + final Image slice = copyCrop(biggerImage, + x: left, y: 0, width: lineHeight, height: heightPx); + grayscale(slice); + final imgBinary = slice.convert(numChannels: 1); + final Uint8List bytes = imgBinary.getBytes(); blobs.add(bytes); left += lineHeight; } @@ -173,7 +175,7 @@ class Generator { // R/G/B channels are same -> keep only one channel final List oneChannelBytes = []; - final List buffer = image.getBytes(format: Format.rgba); + final List buffer = image.getBytes(order: ChannelOrder.rgba); for (int i = 0; i < buffer.length; i += 4) { oneChannelBytes.add(buffer[i]); } @@ -215,7 +217,7 @@ class Generator { /// Replaces a single bit in a 32-bit unsigned integer. int _transformUint32Bool(int uint32, int shift, bool newValue) { return ((0xFFFFFFFF ^ (0x1 << shift)) & uint32) | - ((newValue ? 1 : 0) << shift); + ((newValue ? 1 : 0) << shift); } // ************************ (end) Internal helpers ************************ @@ -280,7 +282,7 @@ class Generator { } if (styles.underline != _styles.underline) { bytes += - styles.underline ? cUnderline1dot.codeUnits : cUnderlineOff.codeUnits; + styles.underline ? cUnderline1dot.codeUnits : cUnderlineOff.codeUnits; _styles = _styles.copyWith(underline: styles.underline); } @@ -342,12 +344,12 @@ class Generator { } List text( - String text, { - PosStyles styles = const PosStyles(), - int linesAfter = 0, - bool containsChinese = false, - int? maxCharsPerLine, - }) { + String text, { + PosStyles styles = const PosStyles(), + int linesAfter = 0, + bool containsChinese = false, + int? maxCharsPerLine, + }) { List bytes = []; if (!containsChinese) { bytes += _text( @@ -470,7 +472,7 @@ class Generator { for (int i = 0; i < cols.length; ++i) { int 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); double charWidth = _getCharWidth(cols[i].styles); double fromPos = _colIndToPosition(colInd); final double toPos = @@ -488,7 +490,7 @@ class Generator { if (realCharactersNb > maxCharactersNb) { // Print max possible and split to the next row Uint8List encodedToPrintNextRow = - encodedToPrint.sublist(maxCharactersNb); + encodedToPrint.sublist(maxCharactersNb); encodedToPrint = encodedToPrint.sublist(0, maxCharactersNb); isNextRow = true; nextRow.add(PosColumn( @@ -577,8 +579,8 @@ class Generator { const bool highDensityVertical = true; invert(image); - flip(image, Flip.horizontal); - final Image imageRotated = copyRotate(image, 270); + flip(image, direction: FlipDirection.horizontal); + final Image imageRotated = copyRotate(image, angle: 270); const int lineHeight = highDensityVertical ? 3 : 1; final List> blobs = _toColumnFormat(imageRotated, lineHeight * 8); @@ -615,12 +617,12 @@ class Generator { /// /// [image] is an instanse of class from [Image library](https://pub.dev/packages/image) List imageRaster( - Image image, { - PosAlign align = PosAlign.center, - bool highDensityHorizontal = true, - bool highDensityVertical = true, - PosImageFn imageFn = PosImageFn.bitImageRaster, - }) { + Image image, { + PosAlign align = PosAlign.center, + bool highDensityHorizontal = true, + bool highDensityVertical = true, + PosImageFn imageFn = PosImageFn.bitImageRaster, + }) { List bytes = []; // Image alignment bytes += setStyles(PosStyles().copyWith(align: align)); @@ -666,13 +668,13 @@ class Generator { /// [height] range: 1 - 255. The units depend on the printer model. /// Width, height, font, text position settings are effective until performing of ESC @, reset or power-off. List barcode( - Barcode barcode, { - int? width, - int? height, - BarcodeFont? font, - BarcodeText textPos = BarcodeText.below, - PosAlign align = PosAlign.center, - }) { + Barcode barcode, { + int? width, + int? height, + BarcodeFont? font, + BarcodeText textPos = BarcodeText.below, + PosAlign align = PosAlign.center, + }) { List bytes = []; // Set alignment bytes += setStyles(PosStyles().copyWith(align: align)); @@ -708,11 +710,11 @@ class Generator { /// Print a QR Code List qrcode( - String text, { - PosAlign align = PosAlign.center, - QRSize size = QRSize.Size4, - QRCorrection cor = QRCorrection.L, - }) { + String text, { + PosAlign align = PosAlign.center, + QRSize size = QRSize.Size4, + QRCorrection cor = QRCorrection.L, + }) { List bytes = []; // Set alignment bytes += setStyles(PosStyles().copyWith(align: align)); @@ -743,11 +745,11 @@ class Generator { } List textEncoded( - Uint8List textBytes, { - PosStyles styles = const PosStyles(), - int linesAfter = 0, - int? maxCharsPerLine, - }) { + Uint8List textBytes, { + PosStyles styles = const PosStyles(), + int linesAfter = 0, + int? maxCharsPerLine, + }) { List bytes = []; bytes += _text(textBytes, styles: styles, maxCharsPerLine: maxCharsPerLine); // Ensure at least one line break after the text @@ -761,17 +763,17 @@ class Generator { /// /// [colInd] range: 0..11. If null: do not define the position List _text( - Uint8List textBytes, { - PosStyles styles = const PosStyles(), - int? colInd = 0, - bool isKanji = false, - int colWidth = 12, - int? maxCharsPerLine, - }) { + Uint8List textBytes, { + PosStyles styles = const PosStyles(), + int? colInd = 0, + bool isKanji = false, + int colWidth = 12, + int? maxCharsPerLine, + }) { List bytes = []; if (colInd != null) { double charWidth = - _getCharWidth(styles, maxCharsPerLine: maxCharsPerLine); + _getCharWidth(styles, maxCharsPerLine: maxCharsPerLine); double fromPos = _colIndToPosition(colInd); // Align @@ -808,11 +810,11 @@ class Generator { /// Prints one line of styled mixed (chinese and latin symbols) text List _mixedKanji( - String text, { - PosStyles styles = const PosStyles(), - int linesAfter = 0, - int? maxCharsPerLine, - }) { + String text, { + PosStyles styles = const PosStyles(), + int linesAfter = 0, + int? maxCharsPerLine, + }) { List bytes = []; final list = _getLexemes(text); final List lexemes = list[0]; @@ -835,5 +837,5 @@ class Generator { bytes += emptyLines(linesAfter + 1); return bytes; } - // ************************ (end) Internal command generators ************************ -} +// ************************ (end) Internal command generators ************************ +} \ No newline at end of file diff --git a/lib/src/qrcode.dart b/lib/src/qrcode.dart index ec4b801..2cbf4a8 100644 --- a/lib/src/qrcode.dart +++ b/lib/src/qrcode.dart @@ -6,7 +6,7 @@ * See LICENSE for distribution and usage details. */ -import 'package:esc_pos_utils/src/commands.dart'; +import 'package:esc_pos_utils_plus/src/commands.dart'; import 'dart:convert'; class QRSize { diff --git a/pubspec.lock b/pubspec.lock index 3447480..b7ccc8d 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -5,72 +5,74 @@ packages: dependency: transitive description: name: archive - url: "https://pub.dartlang.org" + sha256: a92e39b291073bb840a72cf43d96d2a63c74e9a485d227833e8ea0054d16ad16 + url: "https://pub.dev" source: hosted version: "3.1.2" async: dependency: transitive description: name: async - url: "https://pub.dartlang.org" + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" source: hosted - version: "2.8.2" + version: "2.11.0" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.dartlang.org" + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.1" characters: dependency: transitive description: name: characters - url: "https://pub.dartlang.org" + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" source: hosted - version: "1.2.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.1" + version: "1.3.0" clock: dependency: transitive description: name: clock - url: "https://pub.dartlang.org" + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.1.1" collection: dependency: transitive description: name: collection - url: "https://pub.dartlang.org" + sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c" + url: "https://pub.dev" source: hosted - version: "1.15.0" + version: "1.17.1" crypto: dependency: transitive description: name: crypto - url: "https://pub.dartlang.org" + sha256: cf75650c66c0316274e21d7c43d3dea246273af5955bd94e8184837cd577575c + url: "https://pub.dev" source: hosted version: "3.0.1" csslib: dependency: transitive description: name: csslib - url: "https://pub.dartlang.org" + sha256: f857285c8dc0b4f2f77b49a1c083ff8c75223a7549de20f3e607df58cf497a43 + url: "https://pub.dev" source: hosted version: "0.17.0" fake_async: dependency: transitive description: name: fake_async - url: "https://pub.dartlang.org" + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.3.1" flutter: dependency: "direct main" description: flutter @@ -85,58 +87,82 @@ packages: dependency: "direct main" description: name: gbk_codec - url: "https://pub.dartlang.org" + sha256: "3af5311fc9393115e3650ae6023862adf998051a804a08fb804f042724999f61" + url: "https://pub.dev" source: hosted version: "0.4.0" hex: dependency: "direct main" description: name: hex - url: "https://pub.dartlang.org" + sha256: "4e7cd54e4b59ba026432a6be2dd9d96e4c5205725194997193bf871703b82c4a" + url: "https://pub.dev" source: hosted version: "0.2.0" html: dependency: transitive description: name: html - url: "https://pub.dartlang.org" + sha256: bfef906cbd4e78ef49ae511d9074aebd1d2251482ef601a280973e8b58b51bbf + url: "https://pub.dev" source: hosted version: "0.15.0" image: dependency: "direct main" description: name: image - url: "https://pub.dartlang.org" + sha256: a72242c9a0ffb65d03de1b7113bc4e189686fc07c7147b8b41811d0dd0e0d9bf + url: "https://pub.dev" source: hosted - version: "3.0.5" + version: "4.0.17" + js: + dependency: transitive + description: + name: js + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + url: "https://pub.dev" + source: hosted + version: "0.6.7" matcher: dependency: transitive description: name: matcher - url: "https://pub.dartlang.org" + sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb" + url: "https://pub.dev" + source: hosted + version: "0.12.15" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724 + url: "https://pub.dev" source: hosted - version: "0.12.11" + version: "0.2.0" meta: dependency: transitive description: name: meta - url: "https://pub.dartlang.org" + sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" + url: "https://pub.dev" source: hosted - version: "1.7.0" + version: "1.9.1" path: dependency: transitive description: name: path - url: "https://pub.dartlang.org" + sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + url: "https://pub.dev" source: hosted - version: "1.8.0" + version: "1.8.3" petitparser: dependency: transitive description: name: petitparser - url: "https://pub.dartlang.org" + sha256: cb3798bef7fc021ac45b308f4b51208a152792445cce0448c9a4ba5879dd8750 + url: "https://pub.dev" source: hosted - version: "4.3.0" + version: "5.4.0" sky_engine: dependency: transitive description: flutter @@ -146,64 +172,73 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.dartlang.org" + sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250 + url: "https://pub.dev" source: hosted - version: "1.8.1" + version: "1.9.1" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.dartlang.org" + sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 + url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.11.0" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.dartlang.org" + sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.1" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.dartlang.org" + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.2.0" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.dartlang.org" + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.2.1" test_api: dependency: transitive description: name: test_api - url: "https://pub.dartlang.org" + sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb + url: "https://pub.dev" source: hosted - version: "0.4.3" + version: "0.5.1" typed_data: dependency: transitive description: name: typed_data - url: "https://pub.dartlang.org" + sha256: "53bdf7e979cfbf3e28987552fd72f637e63f3c8724c9e56d9246942dc2fa36ee" + url: "https://pub.dev" source: hosted version: "1.3.0" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.dartlang.org" + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.4" xml: dependency: transitive description: name: xml - url: "https://pub.dartlang.org" + sha256: "5bc72e1e45e941d825fd7468b9b4cc3b9327942649aeb6fc5cdbf135f0a86e84" + url: "https://pub.dev" source: hosted - version: "5.3.0" + version: "6.3.0" sdks: - dart: ">=2.14.0 <3.0.0" + dart: ">=3.0.0-0 <4.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 5db09d0..ac9b25b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,17 +1,17 @@ -name: esc_pos_utils +name: esc_pos_utils_plus description: Basic Flutter/Dart classes for ESC/POS printing. Ticket class generates ESC/POS commands that can be sent to a thermal printer. version: 1.1.0 homepage: https://github.com/andrey-ushakov/esc_pos_utils environment: - sdk: ">=2.12.0 <3.0.0" + sdk: ">=2.12.0 <4.0.0" dependencies: flutter: sdk: flutter hex: ^0.2.0 gbk_codec: ^0.4.0 - image: ^3.0.2 + image: ^4.0.15 dev_dependencies: flutter_test: @@ -19,4 +19,4 @@ dev_dependencies: flutter: assets: - - packages/esc_pos_utils/resources/capabilities.json + - packages/esc_pos_utils_plus/resources/capabilities.json diff --git a/test/esc_pos_utils_test.dart b/test/esc_pos_utils_test.dart index f50dbae..2f6b825 100644 --- a/test/esc_pos_utils_test.dart +++ b/test/esc_pos_utils_test.dart @@ -1,7 +1,5 @@ import 'package:flutter_test/flutter_test.dart'; -import 'package:esc_pos_utils/esc_pos_utils.dart'; - void main() { test('Tests not implemented', () { expect(1, 1);