Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

image method support single density (TM-U220) #69

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/src/commands.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,6 @@ const cCashDrawerPin5 = '${esc}p130';

// QR Code
const cQrHeader = '$gs(k';

//Print control mode
const cControlHeader = '$gs(K';
44 changes: 36 additions & 8 deletions lib/src/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -144,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);
Expand Down Expand Up @@ -217,6 +220,7 @@ class Generator {
return ((0xFFFFFFFF ^ (0x1 << shift)) & uint32) |
((newValue ? 1 : 0) << shift);
}

// ************************ (end) Internal helpers ************************

//**************************** Public command generators ************************
Expand Down Expand Up @@ -567,20 +571,32 @@ class Generator {
/// Print an image using (ESC *) command
///
/// [image] is an instanse of class from [Image library](https://pub.dev/packages/image)
List<int> image(Image imgSrc, {PosAlign align = PosAlign.center}) {
List<int> image(Image imgSrc,
{PosAlign align = PosAlign.center, bool isDoubleDensity = true}) {
List<int> 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;
Image image;
if (!isDoubleDensity) {
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
}
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<List<int>> blobs = _toColumnFormat(imageRotated, lineHeight * 8);

// Compress according to line density
Expand All @@ -592,7 +608,7 @@ class Generator {
}

final int heightPx = imageRotated.height;
const int densityByte =
int densityByte =
(highDensityHorizontal ? 1 : 0) + (highDensityVertical ? 32 : 0);

final List<int> header = List.from(cBitImg.codeUnits);
Expand Down Expand Up @@ -721,6 +737,17 @@ class Generator {
return bytes;
}

//0 - 17
//or 48 - 59
//TM-T82II m = 0 – 11, 48 – 59
List<int> printSpeech(int level) {
List<int> 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<int> drawer({PosDrawer pin = PosDrawer.pin2}) {
List<int> bytes = [];
Expand Down Expand Up @@ -754,6 +781,7 @@ class Generator {
bytes += emptyLines(linesAfter + 1);
return bytes;
}

// ************************ (end) Public command generators ************************

// ************************ (end) Internal command generators ************************
Expand Down Expand Up @@ -835,5 +863,5 @@ class Generator {
bytes += emptyLines(linesAfter + 1);
return bytes;
}
// ************************ (end) Internal command generators ************************
// ************************ (end) Internal command generators ************************
}
75 changes: 41 additions & 34 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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"