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
f64bd703
Commit
f64bd703
authored
Sep 05, 2019
by
Andrey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Barcode class and enums moved to barcode.dart.
parent
2b79cd77
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
221 additions
and
220 deletions
+221
-220
esc_pos_printer.dart
lib/esc_pos_printer.dart
+1
-0
barcode.dart
lib/src/barcode.dart
+219
-0
enums.dart
lib/src/enums.dart
+0
-220
printer.dart
lib/src/printer.dart
+1
-0
No files found.
lib/esc_pos_printer.dart
View file @
f64bd703
...
...
@@ -6,6 +6,7 @@
*/
library
esc_pos_printer
;
export
'./src/barcode.dart'
;
export
'./src/enums.dart'
;
export
'./src/pos_column.dart'
;
export
'./src/pos_styles.dart'
;
...
...
lib/src/barcode.dart
0 → 100644
View file @
f64bd703
class
BarcodeType
{
const
BarcodeType
.
_internal
(
this
.
value
);
final
int
value
;
/// UPC-A
static
const
upcA
=
BarcodeType
.
_internal
(
0
);
/// UPC-E
static
const
upcE
=
BarcodeType
.
_internal
(
1
);
/// JAN13 (EAN13)
static
const
ean13
=
BarcodeType
.
_internal
(
2
);
/// JAN8 (EAN8)
static
const
ean8
=
BarcodeType
.
_internal
(
3
);
/// CODE39
static
const
code39
=
BarcodeType
.
_internal
(
4
);
/// ITF (Interleaved 2 of 5)
static
const
itf
=
BarcodeType
.
_internal
(
5
);
/// CODABAR (NW-7)
static
const
codabar
=
BarcodeType
.
_internal
(
6
);
}
class
BarcodeText
{
const
BarcodeText
.
_internal
(
this
.
value
);
final
int
value
;
/// Not printed
static
const
none
=
BarcodeText
.
_internal
(
0
);
/// Above the barcode
static
const
above
=
BarcodeText
.
_internal
(
1
);
/// Below the barcode
static
const
below
=
BarcodeText
.
_internal
(
2
);
/// Both above and below the barcode
static
const
both
=
BarcodeText
.
_internal
(
3
);
}
class
BarcodeFont
{
const
BarcodeFont
.
_internal
(
this
.
value
);
final
int
value
;
static
const
fontA
=
BarcodeText
.
_internal
(
0
);
static
const
fontB
=
BarcodeText
.
_internal
(
1
);
static
const
fontC
=
BarcodeText
.
_internal
(
2
);
static
const
fontD
=
BarcodeText
.
_internal
(
3
);
static
const
fontE
=
BarcodeText
.
_internal
(
4
);
static
const
specialA
=
BarcodeText
.
_internal
(
97
);
static
const
specialB
=
BarcodeText
.
_internal
(
98
);
}
class
Barcode
{
/// UPC-A
///
/// k = 11, 12
/// d = '0' – '9'
Barcode
.
upcA
(
List
<
int
>
data
)
{
_type
=
BarcodeType
.
upcA
;
_data
=
data
;
final
k
=
data
.
length
;
if
(
k
!=
11
||
k
!=
12
)
{
throw
Exception
(
'Barcode: Wrong data range'
);
}
final
numeric
=
RegExp
(
r'^[0-9]$'
);
final
bool
isDataValid
=
data
.
every
((
d
)
=>
numeric
.
hasMatch
(
d
.
toString
()));
if
(!
isDataValid
)
{
throw
Exception
(
'Barcode: Data is not valid'
);
}
}
/// UPC-E
///
/// k = 6 – 8, 11, 12
/// d = '0' – '9' (However, d0 = '0' when k = 7, 8, 11, 12)
Barcode
.
upcE
(
List
<
int
>
data
)
{
_type
=
BarcodeType
.
upcE
;
_data
=
data
;
final
k
=
data
.
length
;
if
(![
6
,
7
,
8
,
11
,
12
].
contains
(
k
))
{
throw
Exception
(
'Barcode: Wrong data range'
);
}
if
([
7
,
8
,
11
,
12
].
contains
(
k
)
&&
data
[
0
].
toString
()
!=
'0'
)
{
throw
Exception
(
'Barcode: Data is not valid'
);
}
final
numeric
=
RegExp
(
r'^[0-9]$'
);
final
bool
isDataValid
=
data
.
every
((
d
)
=>
numeric
.
hasMatch
(
d
.
toString
()));
if
(!
isDataValid
)
{
throw
Exception
(
'Barcode: Data is not valid'
);
}
}
/// JAN13 (EAN13)
///
/// k = 12, 13
/// d = '0' – '9'
Barcode
.
ean13
(
List
<
int
>
data
)
{
_type
=
BarcodeType
.
ean13
;
_data
=
data
;
final
k
=
data
.
length
;
if
(
k
!=
12
||
k
!=
13
)
{
throw
Exception
(
'Barcode: Wrong data range'
);
}
final
numeric
=
RegExp
(
r'^[0-9]$'
);
final
bool
isDataValid
=
data
.
every
((
d
)
=>
numeric
.
hasMatch
(
d
.
toString
()));
if
(!
isDataValid
)
{
throw
Exception
(
'Barcode: Data is not valid'
);
}
}
/// JAN8 (EAN8)
///
/// k = 7, 8
/// d = '0' – '9'
Barcode
.
ean8
(
List
<
int
>
data
)
{
_type
=
BarcodeType
.
ean8
;
_data
=
data
;
final
k
=
data
.
length
;
if
(
k
!=
7
||
k
!=
8
)
{
throw
Exception
(
'Barcode: Wrong data range'
);
}
final
numeric
=
RegExp
(
r'^[0-9]$'
);
final
bool
isDataValid
=
data
.
every
((
d
)
=>
numeric
.
hasMatch
(
d
.
toString
()));
if
(!
isDataValid
)
{
throw
Exception
(
'Barcode: Data is not valid'
);
}
}
/// CODE39
///
/// k >= 1
/// d: '0'–'9', A–Z, SP, $, %, *, +, -, ., /
Barcode
.
code39
(
List
<
int
>
data
)
{
_type
=
BarcodeType
.
code39
;
_data
=
data
;
final
k
=
data
.
length
;
if
(
k
<
1
)
{
throw
Exception
(
'Barcode: Wrong data range'
);
}
final
regex
=
RegExp
(
r'^[0-9A-Z \$\%\*\+\-\.\/]$'
);
final
bool
isDataValid
=
data
.
every
((
d
)
=>
regex
.
hasMatch
(
d
.
toString
()));
if
(!
isDataValid
)
{
throw
Exception
(
'Barcode: Data is not valid'
);
}
}
/// ITF (Interleaved 2 of 5)
///
/// k >= 2 (even number)
/// d = '0'–'9'
Barcode
.
itf
(
List
<
int
>
data
)
{
_type
=
BarcodeType
.
itf
;
_data
=
data
;
final
k
=
data
.
length
;
if
(
k
<
2
||
!
k
.
isEven
)
{
throw
Exception
(
'Barcode: Wrong data range'
);
}
final
numeric
=
RegExp
(
r'^[0-9]$'
);
final
bool
isDataValid
=
data
.
every
((
d
)
=>
numeric
.
hasMatch
(
d
.
toString
()));
if
(!
isDataValid
)
{
throw
Exception
(
'Barcode: Data is not valid'
);
}
}
/// CODABAR (NW-7)
///
/// k >= 2
/// d: '0'–'9', A–D, a–d, $, +, −, ., /, :
/// However, d0 = A–D, dk = A–D (65-68)
/// d1 = a-d, dk = a-d (97-100)
Barcode
.
codabar
(
List
<
int
>
data
)
{
_type
=
BarcodeType
.
codabar
;
_data
=
data
;
final
k
=
data
.
length
;
if
(
k
<
2
)
{
throw
Exception
(
'Barcode: Wrong data range'
);
}
final
regex
=
RegExp
(
r'^[0-9A-Da-d\$\+\-\.\/\:]$'
);
final
bool
isDataValid
=
data
.
every
((
d
)
=>
regex
.
hasMatch
(
d
.
toString
()));
if
(!
isDataValid
)
{
throw
Exception
(
'Barcode: Data is not valid'
);
}
if
(!((
data
[
0
]
>=
65
&&
data
[
0
]
<=
68
)
&&
(
data
[
k
-
1
]
>=
65
&&
data
[
k
-
1
]
<=
68
)))
{
throw
Exception
(
'Barcode: Wrong data range'
);
}
if
(!((
data
[
0
]
>=
97
&&
data
[
0
]
<=
100
)
&&
(
data
[
k
-
1
]
>=
97
&&
data
[
k
-
1
]
<=
100
)))
{
throw
Exception
(
'Barcode: Wrong data range'
);
}
}
BarcodeType
_type
;
List
<
int
>
_data
;
BarcodeType
get
type
=>
_type
;
List
<
int
>
get
data
=>
_data
.
map
<
int
>((
d
)
=>
d
.
toString
().
codeUnitAt
(
0
));
}
lib/src/enums.dart
View file @
f64bd703
...
...
@@ -92,223 +92,3 @@ class PosCodeTable {
/// Space page
static
const
spacePage
=
PosCodeTable
.
_internal
(
255
);
}
class
BarcodeType
{
const
BarcodeType
.
_internal
(
this
.
value
);
final
int
value
;
/// UPC-A
static
const
upcA
=
BarcodeType
.
_internal
(
0
);
/// UPC-E
static
const
upcE
=
BarcodeType
.
_internal
(
1
);
/// JAN13 (EAN13)
static
const
ean13
=
BarcodeType
.
_internal
(
2
);
/// JAN8 (EAN8)
static
const
ean8
=
BarcodeType
.
_internal
(
3
);
/// CODE39
static
const
code39
=
BarcodeType
.
_internal
(
4
);
/// ITF (Interleaved 2 of 5)
static
const
itf
=
BarcodeType
.
_internal
(
5
);
/// CODABAR (NW-7)
static
const
codabar
=
BarcodeType
.
_internal
(
6
);
}
class
Barcode
{
/// UPC-A
///
/// k = 11, 12
/// d = '0' – '9'
Barcode
.
upcA
(
List
<
int
>
data
)
{
_type
=
BarcodeType
.
upcA
;
_data
=
data
;
final
k
=
data
.
length
;
if
(
k
!=
11
||
k
!=
12
)
{
throw
Exception
(
'Barcode: Wrong data range'
);
}
final
numeric
=
RegExp
(
r'^[0-9]$'
);
final
bool
isDataValid
=
data
.
every
((
d
)
=>
numeric
.
hasMatch
(
d
.
toString
()));
if
(!
isDataValid
)
{
throw
Exception
(
'Barcode: Data is not valid'
);
}
}
/// UPC-E
///
/// k = 6 – 8, 11, 12
/// d = '0' – '9' (However, d0 = '0' when k = 7, 8, 11, 12)
Barcode
.
upcE
(
List
<
int
>
data
)
{
_type
=
BarcodeType
.
upcE
;
_data
=
data
;
final
k
=
data
.
length
;
if
(![
6
,
7
,
8
,
11
,
12
].
contains
(
k
))
{
throw
Exception
(
'Barcode: Wrong data range'
);
}
if
([
7
,
8
,
11
,
12
].
contains
(
k
)
&&
data
[
0
].
toString
()
!=
'0'
)
{
throw
Exception
(
'Barcode: Data is not valid'
);
}
final
numeric
=
RegExp
(
r'^[0-9]$'
);
final
bool
isDataValid
=
data
.
every
((
d
)
=>
numeric
.
hasMatch
(
d
.
toString
()));
if
(!
isDataValid
)
{
throw
Exception
(
'Barcode: Data is not valid'
);
}
}
/// JAN13 (EAN13)
///
/// k = 12, 13
/// d = '0' – '9'
Barcode
.
ean13
(
List
<
int
>
data
)
{
_type
=
BarcodeType
.
ean13
;
_data
=
data
;
final
k
=
data
.
length
;
if
(
k
!=
12
||
k
!=
13
)
{
throw
Exception
(
'Barcode: Wrong data range'
);
}
final
numeric
=
RegExp
(
r'^[0-9]$'
);
final
bool
isDataValid
=
data
.
every
((
d
)
=>
numeric
.
hasMatch
(
d
.
toString
()));
if
(!
isDataValid
)
{
throw
Exception
(
'Barcode: Data is not valid'
);
}
}
/// JAN8 (EAN8)
///
/// k = 7, 8
/// d = '0' – '9'
Barcode
.
ean8
(
List
<
int
>
data
)
{
_type
=
BarcodeType
.
ean8
;
_data
=
data
;
final
k
=
data
.
length
;
if
(
k
!=
7
||
k
!=
8
)
{
throw
Exception
(
'Barcode: Wrong data range'
);
}
final
numeric
=
RegExp
(
r'^[0-9]$'
);
final
bool
isDataValid
=
data
.
every
((
d
)
=>
numeric
.
hasMatch
(
d
.
toString
()));
if
(!
isDataValid
)
{
throw
Exception
(
'Barcode: Data is not valid'
);
}
}
/// CODE39
///
/// k >= 1
/// d: '0'–'9', A–Z, SP, $, %, *, +, -, ., /
Barcode
.
code39
(
List
<
int
>
data
)
{
_type
=
BarcodeType
.
code39
;
_data
=
data
;
final
k
=
data
.
length
;
if
(
k
<
1
)
{
throw
Exception
(
'Barcode: Wrong data range'
);
}
final
regex
=
RegExp
(
r'^[0-9A-Z \$\%\*\+\-\.\/]$'
);
final
bool
isDataValid
=
data
.
every
((
d
)
=>
regex
.
hasMatch
(
d
.
toString
()));
if
(!
isDataValid
)
{
throw
Exception
(
'Barcode: Data is not valid'
);
}
}
/// ITF (Interleaved 2 of 5)
///
/// k >= 2 (even number)
/// d = '0'–'9'
Barcode
.
itf
(
List
<
int
>
data
)
{
_type
=
BarcodeType
.
itf
;
_data
=
data
;
final
k
=
data
.
length
;
if
(
k
<
2
||
!
k
.
isEven
)
{
throw
Exception
(
'Barcode: Wrong data range'
);
}
final
numeric
=
RegExp
(
r'^[0-9]$'
);
final
bool
isDataValid
=
data
.
every
((
d
)
=>
numeric
.
hasMatch
(
d
.
toString
()));
if
(!
isDataValid
)
{
throw
Exception
(
'Barcode: Data is not valid'
);
}
}
/// CODABAR (NW-7)
///
/// k >= 2
/// d: '0'–'9', A–D, a–d, $, +, −, ., /, :
/// However, d0 = A–D, dk = A–D (65-68)
/// d1 = a-d, dk = a-d (97-100)
Barcode
.
codabar
(
List
<
int
>
data
)
{
_type
=
BarcodeType
.
codabar
;
_data
=
data
;
final
k
=
data
.
length
;
if
(
k
<
2
)
{
throw
Exception
(
'Barcode: Wrong data range'
);
}
final
regex
=
RegExp
(
r'^[0-9A-Da-d\$\+\-\.\/\:]$'
);
final
bool
isDataValid
=
data
.
every
((
d
)
=>
regex
.
hasMatch
(
d
.
toString
()));
if
(!
isDataValid
)
{
throw
Exception
(
'Barcode: Data is not valid'
);
}
if
(!((
data
[
0
]
>=
65
&&
data
[
0
]
<=
68
)
&&
(
data
[
k
-
1
]
>=
65
&&
data
[
k
-
1
]
<=
68
)))
{
throw
Exception
(
'Barcode: Wrong data range'
);
}
if
(!((
data
[
0
]
>=
97
&&
data
[
0
]
<=
100
)
&&
(
data
[
k
-
1
]
>=
97
&&
data
[
k
-
1
]
<=
100
)))
{
throw
Exception
(
'Barcode: Wrong data range'
);
}
}
BarcodeType
_type
;
List
<
int
>
_data
;
BarcodeType
get
type
=>
_type
;
List
<
int
>
get
data
=>
_data
.
map
<
int
>((
d
)
=>
d
.
toString
().
codeUnitAt
(
0
));
}
class
BarcodeText
{
const
BarcodeText
.
_internal
(
this
.
value
);
final
int
value
;
/// Not printed
static
const
none
=
BarcodeText
.
_internal
(
0
);
/// Above the barcode
static
const
above
=
BarcodeText
.
_internal
(
1
);
/// Below the barcode
static
const
below
=
BarcodeText
.
_internal
(
2
);
/// Both above and below the barcode
static
const
both
=
BarcodeText
.
_internal
(
3
);
}
class
BarcodeFont
{
const
BarcodeFont
.
_internal
(
this
.
value
);
final
int
value
;
static
const
fontA
=
BarcodeText
.
_internal
(
0
);
static
const
fontB
=
BarcodeText
.
_internal
(
1
);
static
const
fontC
=
BarcodeText
.
_internal
(
2
);
static
const
fontD
=
BarcodeText
.
_internal
(
3
);
static
const
fontE
=
BarcodeText
.
_internal
(
4
);
static
const
specialA
=
BarcodeText
.
_internal
(
97
);
static
const
specialB
=
BarcodeText
.
_internal
(
98
);
}
lib/src/printer.dart
View file @
f64bd703
...
...
@@ -11,6 +11,7 @@ import 'dart:io';
import
'dart:typed_data'
;
import
'package:hex/hex.dart'
;
import
'package:image/image.dart'
;
import
'barcode.dart'
;
import
'commands.dart'
;
import
'enums.dart'
;
import
'pos_column.dart'
;
...
...
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