esc_pos_dart 1.4.1
esc_pos_dart: ^1.4.1 copied to clipboard
ESC/POS thermal WiFi printer support for Dart (non-Flutter dependent).
1.4.1 #
CapabilityProfile: the capabilities are now embedded in the Dart source instead of loaded frompackage:esc_pos_dart/resources/capabilities.json. FixesUnsupported operation: Isolate.resolvePackageUriSyncon Flutter apps (issue #10).- Removed dependency:
resource_portable.
1.4.0 #
-
DecoderEscPos:- New options:
lenient,textDecoding(EscPosTextDecoding.latin1/codeTable),defaultCodeTable,detectUtf8,maxBarcodeDataLength. Defaults keep the previous (strict, latin1) behavior. - Lenient mode never throws: unknown/invalid commands →
CommandEscPosUnknown, a command truncated at the end of the data →CommandEscPosTruncated(seewarnings:DecoderWarning). Ignorable control chars are dropped. - Streaming API:
add(chunk)+close()(a command split between chunks is decoded when complete);decodeis a complete block. Newcommands,consumedBytes,pendingBytes. - Bounds-checked parsing: truncated data throws a
FormatException(strict) instead of aRangeError. - Decodes the ESC/GS/FS/DLE commands sent by POS software and by
GeneratorEscPositself (previously aFormatException): underline, reverse, turn90, upside-down, double-strike, print mode (ESC !), feed dots, raster images (GS v 0,GS ( L,GS 8 L), barcodes (GS k, both forms) and settings, QR Codes (GS ( k), cash drawer (ESC p,DLE DC4), beeper, Kanji (FS &/FS .), international charset, status requests (DLE EOT,GS r,GS a,GS I,ESC u,ESC v), and many generic/setup commands (skipped with their parameters). - New commands (with
toJson/fromJson):CommandEscPosUnderline,CommandEscPosReverse,CommandEscPosTurn90,CommandEscPosUpsideDown,CommandEscPosDoubleStrike,CommandEscPosPrintMode,CommandEscPosFeedDots,CommandEscPosRasterImage(toImage()),CommandEscPosBarcode,CommandEscPosBarcodeSetting,CommandEscPosQRCode,CommandEscPosDrawer,CommandEscPosBeep,CommandEscPosKanji,CommandEscPosIntlCharset,CommandEscPosStatusRequest,CommandEscPosUnknown,CommandEscPosTruncated. CommandEscPosBitImage.toImage(): decodes the column format (scaled to the printer resolution).CommandEscPosCut: optionalfeed(GS V 65..104 n);GS V '0'/'1'andESC i/ESC mdecoded.- Fixed:
GS !with bytes>= 0x80(crash);ESC a '2'(right); bold uses the low bit; text pending before an end of job (FF) is now emitted beforeend_job(was emitted after it).
- New options:
-
EscPosToPrinterDocument(new): converts decoded commands intoPrinterDocuments (text lines with styles, HR, feeds, tabs/absolute positions, images, barcodes, QR Codes; split by cut/end of job). -
PrinterDocument:- New commands:
PrinterCommandBarcode,PrinterCommandQRCode(PrinterCommandType.barcode/qrcode). fromJson: newignoreUnknownCommandsparameter.
- New commands:
-
Barcode.rawandBarcodeType.fromValue/name. -
getCharsetDecoder,getCharsetCodePageandCharCodeTableEscPos.decoder. -
GeneratorEscPos.imageRaster(imageFn: PosImageFn.graphics):GS ( Lwidth (xL xH) is now in dots (was bytes). -
NetworkPrinter.ensureConnected: noFuturereturned inside thetryblock. -
New tests:
test/decoder_esc_pos_test.dart(sequences, generator round-trips with pixel comparison, JSON, truncated prefixes, fuzz, streaming split at every byte, code tables, converter end-to-end). -
Fixes (review):
GeneratorEscPos:- Images: any input format (grayscale/1-channel, palette, 16-bit...) is normalized to 8-bit RGBA, with
transparent pixels as white. 1-channel images used to print all white (
image) or black (imageRaster), and transparent pixels black (imageRaster). image(ESC *): no extra blank stripe when the height is a multiple of 24.imageRaster:GS v 0density bits fixed (horizontal/vertical were swapped);graphicsdata larger than 64 KB usesGS 8 L(4-byte length; was truncated)._intLowHigh: correct maximum ((1 << 8n) - 1; the operator precedence allowed overflowing values).row: the overflowing text of a column is printed in the next rows (was dropped); no infinite recursion when a column can't hold 1 char; mixed Chinese text: one position per column; positions encoded with_intLowHigh(removed thehexdependency).- Code tables: the text is encoded with the code table sent to the printer (
ESC t) byreset,setGlobalCodeTableandsetStyles(codeTable:)(it was encoded as latin1 after areset, e.g.éprinted asΘin CP437);selectCharCodeTableupdatesglobalStyles.codeTable. printCodeTable: restores the previous code table (forced) and prints only the printable bytes (32..255).globalStylesstarts with the printer defaults: a style (width, height, font, align) is restored after a styled text/image even without areset.feed/reverseFeed: values larger than 255 are split (were dropped / overflowed).hr:linesAfteris applied (GenericPrinter.hralso forwardslen).
- Images: any input format (grayscale/1-channel, palette, 16-bit...) is normalized to 8-bit RGBA, with
transparent pixels as white. 1-channel images used to print all white (
QRCode: data larger than 252 bytes (2-bytepL pH; the length overflowed), maximum7089bytes.Barcode:_convertDatakeeps all the chars of each element (Barcode.code128(['{A', '1'])).NetworkPrinter:- Default port
9100(was91000, invalid). - A connection closed/reset by the printer doesn't crash the process (unhandled
SocketException) andisConnectedbecomesfalse. connectto another host/port reconnects;disconnectbeforeconnectdoesn't throw.disconnectflushes and closes the socket before destroying it (pending data was discarded); newflush.transmissionOfStatus:timeoutparameter (waited forever), ignores previously received bytes, returnsnullwithout a reply.
- Default port
PrinterDocument.toStringwith no commands (threwStateError).PrinterCommandImage.fromJson: optionalmimeType(PNG/JPEG detected by signature) andalign; raw RGB data length is validated.PrinterCommandCut.fromJson:fulldefaults totrue.CapabilityProfile:getCodePageIdis case-insensitive; newgetCodePageName;capabilities.jsonis loaded once (cached).DecoderEscPos(strict): after aFormatExceptionthe decoder can be reused (the invalid/truncated data was decoded again by the next call).EscPosToPrinterDocument:ESC @resets the barcode settings; the feed of a cut (cutFeedLines, default 4, added byGenerator.cut) is not converted to a feed (document -> bytes -> document is now a fixed point).- New
codePageCharset(profile code page name -> charset).
-
Tests:
generator_test.dart,network_printer_test.dart(integration: a local fake printer socket),models_test.dart(round trips document -> bytes -> document and JSON -> bytes). 101 tests; coverage 93.7% (was 77.2%).
1.3.2 #
-
PrinterDocument:- Added
fontTypefield with default'a'. - Updated constructor to accept
fontTypeparameter, normalizing to lowercase and trimming. - Updated
fromJsonandtoJsonto includefontType. - Updated
printmethod to applyfontTypealong withfontSizein styles and printer commands.
- Added
-
Generator:- Updated
getCharsPerLineto accept named parameters and apply font width scaling conditionally. - Updated
getCharWidthto pass named parametermaxCharsPerLine. - Updated
hrmethod to calculate line length considering font width scaling.
- Updated
1.3.1 #
-
PrinterDocument:print: added optionalselectCharCodeTableparameter.print: pass initialPosStyleswith font size toprinter.reset().print: ensurefontSizestyle is applied viaprinter.setStyles().
-
PrinterCommandStyle:- Changed all fields to nullable.
- Added
constconstructor anddefaultsconstructor. fromJson: no longer provide default values; fields nullable.toJson: serialize only non-null fields.toPosStyles: treat null booleans as false; convert nullable width/height toPosTextSizeor null.- Removed internal
getPosTextSizemethod.
-
GenericPrinter:resetmethod now accepts optionalPosStylesparameter and passes it to generator.
-
DecoderEscPos:- Added support for GS command 0x21 to decode font size.
- Added
CommandEscPosFontSizecommand with width and height size parameters. - Updated
CommandEscPos.fromJsonto supportfont-sizecommand.
-
enums.dart:- Added
PosTextSize.encodeSizeto encode width and height into a single int. - Added
PosTextSize.decodeSizeto decode int into width and heightPosTextSizevalues.
- Added
-
Generator:resetnow accepts optionalPosStylesparameter.- Added
setAlignmethod with optionalforceparameter. - Updated
setGlobalCodeTableandsetFontto acceptforceparameter. - Updated
setStylesto handle nullable width and height, and encode font size usingPosTextSize.encodeSize. - Updated
getCharWidthandgetCharsPerLineto handle nullable width and global styles fallback.
-
GeneratorEscPos:- Implemented
resetwith optionalstylesparameter, applying initial styles with defaults. - Implemented
setAlignto update alignment if changed or forced. - Updated
setStylesto handle nullable height and width, and encode font size accordingly.
- Implemented
-
PosStyles:-
Made
heightandwidthnullable. -
Added
copyWithDefaultsmethod to fill null fields from defaults or parameters. -
Updated constructors to allow nullable height and width.
-
PosTextSize:- Added static method
withValue(int value)to return aPosTextSizeenum matching the given value or null if none matches.
- Added static method
-
1.3.0 #
-
PrinterDocument:- Added
fontSizefield with clamped range 1 to 8. - Updated constructor to accept optional
fontSizeparameter.- Breaking change: The constructor now uses named parameters.
- Updated
fromJsonandtoJsonto handlefontSize.
- Added
-
Generator:- Updated
getCharsPerLineto adjust character count based onPosStyles.widthscaling.
- Updated
-
Dependencies:
- Updated
imageto ^4.8.0. - Updated
testto ^1.30.0. - Updated
dependency_validatorto ^5.0.4.
- Updated
1.2.1 #
-
PrinterDocument:print: added optional parameterselectCharCodeTableto select character code table before printing.
-
GenericPrinter:- Added method
selectCharCodeTable({int codeTable = 0})to send ESC/POS command to select character code table.
- Added method
-
Generator(abstract):- Added methods and properties for character code table support:
selectCharCodeTable({int codeTable = 0})int? get selectedCharCodeTableString? get selectedCharsetCharsetEncoder? get selectedCharsetEncoder
- Added methods and properties for character code table support:
-
GeneratorEscPos:- Implemented character code table selection and tracking:
_selectedCharCodeTable,_selectedCharset,_selectedCharsetEncoderfields.selectCharCodeTableupdates selected table and charset encoder.resetclears selected character code table.
- Added enum
CharCodeTableEscPosmapping ESC/POS code tables to charset names and encoders. - Updated text encoding to use selected charset encoder if available.
- Implemented character code table selection and tracking:
-
char_encoder.dart:- Added comprehensive charset encoder resolution via
getCharsetEncoder(String? name)usingcharsetpackage. - Updated
encodeCharsto accept optionalCharsetEncoderor charset name and fallback to latin1 or utf8 if encoding fails.
- Added comprehensive charset encoder resolution via
-
Dependency updates:
- Added
charset: ^2.0.1 - Updated
imageto ^4.7.2 - Updated
collectionto ^1.19.1 - Updated
testto ^1.29.0 - Updated
dependency_validatorto ^5.0.3 - Updated
coverageto ^1.15.0
- Added
1.2.0 #
-
Migrate to
image: ^4.5.4. -
image: ^4.5.4
-
test: ^1.26.2
-
dependency_validator: ^5.0.2
-
coverage: ^1.14.1
1.1.3 #
-
DecoderEscPos:- Fix decoding of Bit Image, calculating the correct data length.
-
CommandEscPosBitImage:- Added field
lineBreak.
- Added field
-
coverage: ^1.13.1
1.1.2 #
-
Generator:- Fix
getCharsPerLineto usestyles.fontType. cut: change parameter toextraLines = 4.hr: fix call togetMaxCharsPerLineto usestyles.fontType ?? globalFont.
- Fix
-
GeneratorEscPos:- Consider character margin for max characters per line.
-
PrinterCommandHR:- Fix JSON: add parameter
style.
- Fix JSON: add parameter
-
PrinterCommandImage:- Added
decodeImage. - Fix JSON: add parameter
mimeType.
- Added
1.1.1 #
Generator:cut: rollback default value forextraLinesto3. Most printers need at least 3 extra lines.
1.1.0 #
-
Converted to Dart enums:
PaperSize,PosTextSize,PosBeepDuration.
-
PosStyles:alignnullable.fontTypenullable.
-
Generatornow is a base class.- Added fields
newLineandnormalizeNewLines. - Renamed
setGlobalFonttosetFont. - Added
styledBlock. cut: parameterextraLines = 2.globalFontnow is a getter toglobalStyles.fontType ?? PosFontType.fontA.- Implementation:
GeneratorEscPos(ESC/POS)- Ensure that command styles won't affect global style.
- Added fields
-
New
DecoderandDecoderEscPos. -
PrinterCommandStyle:- Field
alignnow is aPosAlign. - Field
fontTypenow is aPosFontType.
- Field
-
PrinterDocument:print:- Added parameters
resetandendJob. - Send a
resetcommand before start printing. - Send a
endJobcommand at the end of printing.
- Added parameters
addHR: added parameterstyle.
-
collection: ^1.19.0
-
lints: ^5.1.1
1.0.6 #
🚀 Refactor: Refactor NetworkPrinter into GenericPrinter class.
🚀 New BytesPrinter.
-
sdk: ^3.6.0
-
resource_portable: ^3.1.2
-
test: ^1.25.15
-
coverage: ^1.11.1
-
intl: ^0.20.2
1.0.5 #
-
New
encodeChars, to avoid encoding errors. -
Optimize imports.
-
image: ^3.3.0
-
resource_portable: ^3.1.0
-
collection: ^1.18.0
-
lints: ^4.0.0
-
test: ^1.25.11
-
dependency_validator: ^3.2.3
-
coverage: ^1.11.0
-
intl: ^0.20.1
1.0.4 #
- Fix
NetworkPrinter.disconnectdelay.
1.0.3 #
- Added support to optional command
GS r(transmission of status). - Added
end jobcommand. - Added
NetworkPrinter.ensureConnected.
1.0.2 #
- Added
PrinterCommand.toString. - Fixed load of resource:
package:esc_pos_dart/resources/capabilities.json. - collection: ^1.17.2
1.0.1 #
- New
PrinterDocument.
1.0.0 #
- Dart pure version:
- Adjusted for Dart 3.
- Removed any Flutter dependency.
- Fixed lints.
- Added full printing example.
Original Work #
This package is based on the packages esc_pos_printer and esc_pos_utils by Andrey Ushakov (andrey-ushakov@GitHub). Both packages are Flutter dependent, which makes it impossible to use in Dart pure applications.