Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
E
esc_pos_print_plus
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dio Maulana
esc_pos_print_plus
Commits
6ede0dc7
Commit
6ede0dc7
authored
Sep 03, 2019
by
Andrey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed raw lib. Code refactoring.
parent
af1d0cd6
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
20 deletions
+34
-20
CHANGELOG.md
CHANGELOG.md
+5
-0
printer.dart
lib/src/printer.dart
+28
-18
pubspec.yaml
pubspec.yaml
+1
-2
No files found.
CHANGELOG.md
View file @
6ede0dc7
## [1.3.1]
*
Removed raw lib
*
Code refactoring
## [1.3.0]
*
Image printing method has been improved
*
Using ESC
*
command to print images instead of outdated GS v 0
...
...
lib/src/printer.dart
View file @
6ede0dc7
...
...
@@ -11,7 +11,6 @@ import 'dart:io';
import
'dart:typed_data'
;
import
'package:hex/hex.dart'
;
import
'package:image/image.dart'
;
import
'package:raw/raw.dart'
;
import
'commands.dart'
;
import
'enums.dart'
;
import
'pos_column.dart'
;
...
...
@@ -311,7 +310,7 @@ class Printer {
/// Floyd–Steinberg dithering
///
/// 1 pixel = 1 byte
List
<
int
>
ditherImage
(
List
<
int
>
bytes
,
int
width
,
int
height
)
{
List
<
int
>
_
ditherImage
(
List
<
int
>
bytes
,
int
width
,
int
height
)
{
int
index
(
int
x
,
int
y
)
{
return
x
+
y
*
width
;
}
...
...
@@ -370,6 +369,31 @@ class Printer {
return
ditherBytes
;
}
/// 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
);
}
/// Merges each 8 values (bits) into one byte
List
<
int
>
_packBitsIntoBytes
(
List
<
int
>
bytes
)
{
const
pxPerLine
=
8
;
final
List
<
int
>
res
=
<
int
>[];
const
threshold
=
127
;
// set the greyscale -> b/w threshold here
for
(
int
i
=
0
;
i
<
bytes
.
length
;
i
+=
pxPerLine
)
{
int
newVal
=
0
;
for
(
int
j
=
0
;
j
<
pxPerLine
;
j
++)
{
newVal
=
_transformUint32Bool
(
newVal
,
pxPerLine
-
j
,
bytes
[
i
+
j
]
>
threshold
,
);
}
res
.
add
(
newVal
~/
2
);
}
return
res
;
}
/// Print image using ESC *
///
/// [image] is an instanse of class from [Image library](https://pub.dev/packages/image)
...
...
@@ -388,24 +412,10 @@ class Printer {
// Compress according to line density
// Line height contains 8 or 24 pixels of src image
// Each blobs[i] contains greyscale bytes [0-255]
const
int
pxPerLine
=
24
~/
lineHeight
;
//
const int pxPerLine = 24 ~/ lineHeight;
for
(
int
blobInd
=
0
;
blobInd
<
blobs
.
length
;
blobInd
++)
{
// print(blobs[blobInd].length);
// output 24 packed int with 24 b/w bits each
final
List
<
int
>
newBlob
=
<
int
>[];
const
threshold
=
127
;
// set the greyscale -> b/w threshold here
for
(
int
i
=
0
;
i
<
blobs
[
blobInd
].
length
;
i
+=
pxPerLine
)
{
int
newVal
=
0
;
for
(
int
j
=
0
;
j
<
pxPerLine
;
j
++)
{
newVal
=
transformUint32Bool
(
newVal
,
pxPerLine
-
j
,
blobs
[
blobInd
][
i
+
j
]
>
threshold
,
);
}
newBlob
.
add
(
newVal
~/
2
);
}
blobs
[
blobInd
]
=
newBlob
;
blobs
[
blobInd
]
=
_packBitsIntoBytes
(
blobs
[
blobInd
]);
}
final
int
heightPx
=
imageRotated
.
height
;
...
...
pubspec.yaml
View file @
6ede0dc7
name
:
esc_pos_printer
description
:
The library allows to print receipts using a ESC/POS (usually thermal) network printer. It can be used in Flutter or Dart projects. In Flutter, both Android and iOS are supported.
version
:
1.3.
0
version
:
1.3.
1
author
:
Andrey Ushakov <flutter@tablemi.com>
homepage
:
https://github.com/andrey-ushakov/esc_pos_printer
...
...
@@ -12,7 +12,6 @@ dependencies:
sdk
:
flutter
hex
:
^0.1.2
image
:
^2.1.4
raw
:
^0.2.0
dev_dependencies
:
flutter_test
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment