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
0db38e74
Commit
0db38e74
authored
Jun 12, 2019
by
Andrey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added PosString class. Updated methods and example.
parent
bbf5ce66
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
55 additions
and
49 deletions
+55
-49
example.dart
example/example.dart
+9
-9
esc_pos_printer.dart
lib/esc_pos_printer.dart
+1
-0
enums.dart
lib/src/enums.dart
+0
-17
pos_string.dart
lib/src/pos_string.dart
+30
-0
printer.dart
lib/src/printer.dart
+15
-23
No files found.
example/example.dart
View file @
0db38e74
...
...
@@ -4,15 +4,15 @@ import 'package:esc_pos_printer/src/printer.dart';
void
main
(
)
{
Printer
.
connect
(
'192.168.0.123'
).
then
((
printer
)
{
printer
.
reset
();
printer
.
println
(
'Normal text'
);
printer
.
println
(
'Bold text'
,
bold:
true
);
printer
.
println
(
'Reverse text'
,
reverse:
true
);
printer
.
println
(
'Underlined text'
,
underline:
true
);
printer
.
println
(
'Align left'
,
align:
PosTextAlign
.
left
);
printer
.
println
(
'Align center'
,
align:
PosTextAlign
.
center
);
printer
.
println
(
'Align right'
,
align:
PosTextAlign
.
right
);
printer
.
println
(
'Text size 2
'
,
height:
PosTextSize
.
size2
,
width:
PosTextSize
.
size2
);
printer
.
println
(
PosString
(
'Normal text'
)
);
printer
.
println
(
PosString
(
'Bold text'
,
bold:
true
)
);
printer
.
println
(
PosString
(
'Reverse text'
,
reverse:
true
)
);
printer
.
println
(
PosString
(
'Underlined text'
,
underline:
true
)
);
printer
.
println
(
PosString
(
'Align left'
,
align:
PosTextAlign
.
left
)
);
printer
.
println
(
PosString
(
'Align center'
,
align:
PosTextAlign
.
center
)
);
printer
.
println
(
PosString
(
'Align right'
,
align:
PosTextAlign
.
right
)
);
printer
.
println
(
PosString
(
'Text size 200%
'
,
height:
PosTextSize
.
size2
,
width:
PosTextSize
.
size2
)
)
;
printer
.
cut
();
...
...
lib/esc_pos_printer.dart
View file @
0db38e74
...
...
@@ -8,4 +8,5 @@ library esc_pos_printer;
export
'./src/enums.dart'
;
export
'./src/exceptions.dart'
;
export
'./src/pos_string.dart'
;
export
'./src/printer.dart'
;
lib/src/enums.dart
View file @
0db38e74
...
...
@@ -31,20 +31,3 @@ class PosBeepDuration {
static
const
beep400ms
=
PosBeepDuration
.
_internal
(
8
);
static
const
beep450ms
=
PosBeepDuration
.
_internal
(
9
);
}
// class PosCol {
// const PosCol._internal(this.value);
// final int value;
// static const col1 = PosCol._internal(1);
// static const col2 = PosCol._internal(2);
// static const col3 = PosCol._internal(3);
// static const col4 = PosCol._internal(4);
// static const col5 = PosCol._internal(5);
// static const col6 = PosCol._internal(6);
// static const col7 = PosCol._internal(7);
// static const col8 = PosCol._internal(8);
// static const col9 = PosCol._internal(9);
// static const col10 = PosCol._internal(10);
// static const col11 = PosCol._internal(11);
// static const col12 = PosCol._internal(12);
// }
lib/src/pos_string.dart
0 → 100644
View file @
0db38e74
import
'enums.dart'
;
class
PosString
{
PosString
(
this
.
text
,
{
this
.
bold
=
false
,
this
.
reverse
=
false
,
this
.
underline
=
false
,
this
.
align
=
PosTextAlign
.
left
,
this
.
height
=
PosTextSize
.
size1
,
this
.
width
=
PosTextSize
.
size1
,
this
.
fontType
=
PosFontType
.
fontA
,
this
.
linesAfter
=
0
,
});
String
text
;
bool
bold
=
false
;
bool
reverse
=
false
;
bool
underline
=
false
;
PosTextAlign
align
=
PosTextAlign
.
left
;
PosTextSize
height
=
PosTextSize
.
size1
;
PosTextSize
width
=
PosTextSize
.
size1
;
PosFontType
fontType
=
PosFontType
.
fontA
;
int
linesAfter
=
0
;
@override
String
toString
()
{
return
text
;
}
}
lib/src/printer.dart
View file @
0db38e74
...
...
@@ -4,8 +4,9 @@ import 'package:hex/hex.dart';
import
'commands.dart'
;
import
'enums.dart'
;
import
'exceptions.dart'
;
import
'pos_string.dart'
;
///
Printer.
///
Network printer
class
Printer
{
Printer
(
this
.
_socket
)
{
reset
();
...
...
@@ -29,37 +30,28 @@ class Printer {
_socket
.
destroy
();
}
void
println
(
String
text
,
{
bool
bold
=
false
,
bool
reverse
=
false
,
bool
underline
=
false
,
PosTextAlign
align
=
PosTextAlign
.
left
,
PosTextSize
height
=
PosTextSize
.
size1
,
PosTextSize
width
=
PosTextSize
.
size1
,
PosFontType
fontType
=
PosFontType
.
fontA
,
int
linesAfter
=
0
,
})
{
_socket
.
write
(
bold
?
cBoldOn
:
cBoldOff
);
_socket
.
write
(
reverse
?
cReverseOn
:
cReverseOff
);
_socket
.
write
(
underline
?
cUnderline1dot
:
cUnderlineOff
);
_socket
.
write
(
align
==
PosTextAlign
.
left
void
println
(
PosString
data
)
{
_socket
.
write
(
data
.
bold
?
cBoldOn
:
cBoldOff
);
_socket
.
write
(
data
.
reverse
?
cReverseOn
:
cReverseOff
);
_socket
.
write
(
data
.
underline
?
cUnderline1dot
:
cUnderlineOff
);
_socket
.
write
(
data
.
align
==
PosTextAlign
.
left
?
cAlignLeft
:
(
align
==
PosTextAlign
.
center
?
cAlignCenter
:
cAlignRight
));
_socket
.
write
(
fontType
==
PosFontType
.
fontA
?
cFontA
:
cFontB
);
:
(
data
.
align
==
PosTextAlign
.
center
?
cAlignCenter
:
cAlignRight
));
_socket
.
write
(
data
.
fontType
==
PosFontType
.
fontA
?
cFontA
:
cFontB
);
// Text size
_socket
.
add
(
Uint8List
.
fromList
(
List
.
from
(
cSizeGSn
.
codeUnits
)..
add
(
PosTextSize
.
decSize
(
height
,
width
)),
List
.
from
(
cSizeGSn
.
codeUnits
)
..
add
(
PosTextSize
.
decSize
(
data
.
height
,
data
.
width
)),
),
);
_socket
.
writeln
(
text
);
emptyLines
(
linesAfter
);
_socket
.
writeln
(
data
.
text
);
emptyLines
(
data
.
linesAfter
);
reset
();
}
void
printRow
(
List
<
int
>
cols
,
List
<
String
>
data
)
{
void
printRow
(
List
<
int
>
cols
,
List
<
Pos
String
>
data
)
{
final
validRange
=
cols
.
every
((
val
)
=>
val
>=
1
&&
val
<=
12
);
if
(!
validRange
)
{
throw
PosRowException
(
'Column width should be between 1..12'
);
...
...
@@ -80,7 +72,7 @@ class Printer {
_socket
.
writeln
();
}
void
_printCol
(
int
i
,
String
data
)
{
void
_printCol
(
int
i
,
Pos
String
data
)
{
final
int
pos
=
i
==
0
?
0
:
(
512
*
i
/
11
-
1
).
round
();
final
hexStr
=
pos
.
toRadixString
(
16
).
padLeft
(
3
,
'0'
);
final
hexPair
=
HEX
.
decode
(
hexStr
);
...
...
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