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

Flutter 3.10 #109

Open
wants to merge 1 commit 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [1.1.1]

- Supports latest Image library (4.0.17) 22/05/2023
- Supports Flutter 3.10

## [1.1.0]

- Null-Safety
Expand Down
1 change: 0 additions & 1 deletion example/example.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:image/image.dart';
import 'dart:typed_data';
import 'package:flutter/services.dart';
import 'package:esc_pos_utils/esc_pos_utils.dart';

Expand Down
39 changes: 19 additions & 20 deletions lib/src/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
import 'dart:convert';
import 'dart:typed_data' show Uint8List;
import 'package:hex/hex.dart';
import 'package:image/image.dart';
import 'package:image/image.dart' as im;
import 'package:gbk_codec/gbk_codec.dart';
import 'package:esc_pos_utils/esc_pos_utils.dart';
import 'enums.dart';
import 'commands.dart';

class Generator {
Expand Down Expand Up @@ -136,25 +135,25 @@ class Generator {
///
/// [image] Image to extract from
/// [lineHeight] Printed line height in dots
List<List<int>> _toColumnFormat(Image imgSrc, int lineHeight) {
final Image image = Image.from(imgSrc); // make a copy
List<List<int>> _toColumnFormat(im.Image imgSrc, int lineHeight) {
final im.Image image = im.Image.from(imgSrc); // make a copy

// Determine new width: closest integer that is divisible by lineHeight
final int widthPx = (image.width + lineHeight) - (image.width % lineHeight);
final int heightPx = image.height;

// Create a black bottom layer
final biggerImage = copyResize(image, width: widthPx, height: heightPx);
fill(biggerImage, 0);
final biggerImage = im.copyResize(image, width: widthPx, height: heightPx);
im.fill(biggerImage, color: im.ColorRgb8(0, 0, 0));
// Insert source image into bigger one
drawImage(biggerImage, image, dstX: 0, dstY: 0);
im.compositeImage(biggerImage, image, dstX: 0, dstY: 0);

int left = 0;
final List<List<int>> blobs = [];

while (left < widthPx) {
final Image slice = copyCrop(biggerImage, left, 0, lineHeight, heightPx);
final Uint8List bytes = slice.getBytes(format: Format.luminance);
final im.Image slice = im.copyCrop(biggerImage, x: left, y: 0, width: lineHeight, height: heightPx);
final Uint8List bytes = slice.getBytes(order: im.ChannelOrder.grayAlpha);
blobs.add(bytes);
left += lineHeight;
}
Expand All @@ -163,17 +162,17 @@ class Generator {
}

/// Image rasterization
List<int> _toRasterFormat(Image imgSrc) {
final Image image = Image.from(imgSrc); // make a copy
List<int> _toRasterFormat(im.Image imgSrc) {
final im.Image image = im.Image.from(imgSrc); // make a copy
final int widthPx = image.width;
final int heightPx = image.height;

grayscale(image);
invert(image);
im.grayscale(image);
im.invert(image);

// R/G/B channels are same -> keep only one channel
final List<int> oneChannelBytes = [];
final List<int> buffer = image.getBytes(format: Format.rgba);
final List<int> buffer = image.getBytes(order: im.ChannelOrder.rgba);
for (int i = 0; i < buffer.length; i += 4) {
oneChannelBytes.add(buffer[i]);
}
Expand Down Expand Up @@ -567,18 +566,18 @@ 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(im.Image imgSrc, {PosAlign align = PosAlign.center}) {
List<int> bytes = [];
// Image alignment
bytes += setStyles(PosStyles().copyWith(align: align));

final Image image = Image.from(imgSrc); // make a copy
final im.Image image = im.Image.from(imgSrc); // make a copy
const bool highDensityHorizontal = true;
const bool highDensityVertical = true;

invert(image);
flip(image, Flip.horizontal);
final Image imageRotated = copyRotate(image, 270);
im.invert(image);
im.flip(image, direction: im.FlipDirection.horizontal);
final im.Image imageRotated = im.copyRotate(image, angle: 270);

const int lineHeight = highDensityVertical ? 3 : 1;
final List<List<int>> blobs = _toColumnFormat(imageRotated, lineHeight * 8);
Expand Down Expand Up @@ -615,7 +614,7 @@ class Generator {
///
/// [image] is an instanse of class from [Image library](https://pub.dev/packages/image)
List<int> imageRaster(
Image image, {
im.Image image, {
PosAlign align = PosAlign.center,
bool highDensityHorizontal = true,
bool highDensityVertical = true,
Expand Down
18 changes: 9 additions & 9 deletions lib/src/pos_styles.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ class PosStyles {

// Init all fields with default values
const PosStyles.defaults({
this.bold: false,
this.reverse: false,
this.underline: false,
this.turn90: false,
this.align: PosAlign.left,
this.height: PosTextSize.size1,
this.width: PosTextSize.size1,
this.fontType: PosFontType.fontA,
this.codeTable: "CP437",
this.bold = false,
this.reverse = false,
this.underline = false,
this.turn90 = false,
this.align = PosAlign.left,
this.height = PosTextSize.size1,
this.width = PosTextSize.size1,
this.fontType = PosFontType.fontA,
this.codeTable = "CP437",
});

final bool bold;
Expand Down
Loading