line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Protocol::Star::Linemode - Generates a formatted byte string for Star POS printers |
2
|
|
|
|
|
|
|
# Copyright (c) 2013 Peter Stuifzand |
3
|
|
|
|
|
|
|
# Copyright (c) 2013 Other contributors as noted in the AUTHORS file |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# Protocol::Star::Linemode is free software; you can redistribute it and/or |
6
|
|
|
|
|
|
|
# modify it under the terms of the GNU Lesser General Public License as |
7
|
|
|
|
|
|
|
# published by the Free Software Foundation; either version 3 of the License, |
8
|
|
|
|
|
|
|
# or (at your option) any later version. |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# Protocol::Star::Linemode is distributed in the hope that it will be useful, |
11
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser |
13
|
|
|
|
|
|
|
# General Public License for more details. |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
# You should have received a copy of the GNU Lesser General Public License |
16
|
|
|
|
|
|
|
# along with this program. If not, see . |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
package Protocol::Star::Linemode; |
19
|
|
|
|
|
|
|
our $VERSION = '1.0.0'; |
20
|
1
|
|
|
1
|
|
52193
|
use Moo; |
|
1
|
|
|
|
|
31137
|
|
|
1
|
|
|
|
|
6
|
|
21
|
|
|
|
|
|
|
with qw/ |
22
|
|
|
|
|
|
|
Protocol::Star::Linemode::Generated |
23
|
|
|
|
|
|
|
/; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has _data => ( |
26
|
|
|
|
|
|
|
is => 'rw', |
27
|
|
|
|
|
|
|
default => sub { '' }, |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub append { |
31
|
2
|
|
|
2
|
0
|
6
|
my ($self, @data) = @_; |
32
|
2
|
|
|
|
|
34
|
$self->_data($self->_data . (join '', @data)); |
33
|
2
|
|
|
|
|
5
|
return; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub result { |
37
|
2
|
|
|
2
|
0
|
9
|
my $self = shift; |
38
|
2
|
|
|
|
|
11
|
return $self->_data; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub append_pack { |
42
|
2
|
|
|
2
|
0
|
6
|
my ($self, $format, @args) = @_; |
43
|
2
|
|
|
|
|
17
|
$self->append( |
44
|
|
|
|
|
|
|
pack($format, @args) |
45
|
|
|
|
|
|
|
); |
46
|
2
|
|
|
|
|
7
|
return; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub create_normal_code { |
50
|
0
|
|
|
0
|
0
|
0
|
my ($nargs, @code) = @_; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
0
|
my $len = $nargs + scalar @code; |
53
|
0
|
|
|
|
|
0
|
my $pack_format = 'C' x $len; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
return sub { |
56
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
57
|
0
|
|
|
|
|
0
|
my @args = @_; |
58
|
0
|
|
|
|
|
0
|
$self->append_pack($pack_format, @code, @args); |
59
|
0
|
|
|
|
|
0
|
return; |
60
|
|
|
|
|
|
|
} |
61
|
0
|
|
|
|
|
0
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub create_escape_code { |
64
|
0
|
|
|
0
|
0
|
0
|
my ($nargs, @code) = @_; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
0
|
my $len = 1 + $nargs + scalar @code; |
67
|
0
|
|
|
|
|
0
|
my $pack_format = 'C' x $len; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
return sub { |
70
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
71
|
0
|
|
|
|
|
0
|
my @args = @_; |
72
|
0
|
|
|
|
|
0
|
$self->append_pack($pack_format, 0x1B, @code, @args); |
73
|
0
|
|
|
|
|
0
|
return; |
74
|
|
|
|
|
|
|
} |
75
|
0
|
|
|
|
|
0
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
#BEGIN { |
78
|
|
|
|
|
|
|
# no strict 'refs'; |
79
|
|
|
|
|
|
|
# my @escape_specs = ( |
80
|
|
|
|
|
|
|
# [ 'select_font', 1, 0x1E, 0x46 ], |
81
|
|
|
|
|
|
|
# [ 'select_code_page', 1, 0x1D, 0x74 ], |
82
|
|
|
|
|
|
|
# [ 'set_slash_zero', 1, 0x27 ], |
83
|
|
|
|
|
|
|
# [ 'specify_international_character_set', 1, 0x52 ], |
84
|
|
|
|
|
|
|
# [ 'specify_12_dot_pitch', 0, 0x4D ], |
85
|
|
|
|
|
|
|
# [ 'specify_15_dot_pitch', 0, 0x50 ], |
86
|
|
|
|
|
|
|
# [ 'specify_16_dot_pitch', 0, 0x3A ], |
87
|
|
|
|
|
|
|
# [ 'specify_14_dot_pitch', 0, 0x67 ], |
88
|
|
|
|
|
|
|
# [ 'set_expanded_width_height', 2, 0x69 ], |
89
|
|
|
|
|
|
|
# [ 'set_expanded_width', 1, 0x57 ], |
90
|
|
|
|
|
|
|
# [ 'set_expanded_height', 1, 0x68 ], |
91
|
|
|
|
|
|
|
# [ 'set_double_high', 0, 0x0E ], |
92
|
|
|
|
|
|
|
# [ 'cancel_double_high', 0, 0x14 ], |
93
|
|
|
|
|
|
|
# [ 'set_emphazied_printing', 0, 0x45 ], |
94
|
|
|
|
|
|
|
# [ 'cancel_emphazied_printing', 0, 0x46 ], |
95
|
|
|
|
|
|
|
# [ 'select_underline_mode', 1, 0x2D ], |
96
|
|
|
|
|
|
|
# [ 'select_upperline_mode', 1, 0x5F ], |
97
|
|
|
|
|
|
|
# [ 'select_inverse', 0, 0x34 ], |
98
|
|
|
|
|
|
|
# [ 'cancel_inverse', 0, 0x35 ], |
99
|
|
|
|
|
|
|
# [ 'feed_n_lines', 1, 0x61 ], |
100
|
|
|
|
|
|
|
# [ 'set_page_length', 1, 0x43 ], |
101
|
|
|
|
|
|
|
# [ 'set_page_length_in_24mm_units', 1, 0x43, 0x00 ], |
102
|
|
|
|
|
|
|
# [ 'set_left_margin', 1, 0x6C, ], |
103
|
|
|
|
|
|
|
# [ 'set_right_margin', 1, 0x51, ], |
104
|
|
|
|
|
|
|
# [ 'move_absolute_position', 2, 0x1D, 0x41 ], |
105
|
|
|
|
|
|
|
# [ 'move_relative_position', 2, 0x1D, 0x52 ], |
106
|
|
|
|
|
|
|
# [ 'specify_alignment', 1, 0x1D, 0x61 ], |
107
|
|
|
|
|
|
|
# [ 'align_left', 0, 0x1D, 0x61, 0x00 ], |
108
|
|
|
|
|
|
|
# [ 'align_center', 0, 0x1D, 0x61, 0x01 ], |
109
|
|
|
|
|
|
|
# [ 'align_right', 0, 0x1D, 0x61, 0x02 ], |
110
|
|
|
|
|
|
|
# ); |
111
|
|
|
|
|
|
|
# |
112
|
|
|
|
|
|
|
# my @specs = ( |
113
|
|
|
|
|
|
|
# [ 'set_double_wide', 1, 0x0E ], |
114
|
|
|
|
|
|
|
# [ 'cancel_double_wide', 1, 0x14 ], |
115
|
|
|
|
|
|
|
# [ 'select_upside_down', 0, 0x0F ], |
116
|
|
|
|
|
|
|
# [ 'cancel_upside_down', 0, 0x12 ], |
117
|
|
|
|
|
|
|
# [ 'lf', 0, 0x0A ], |
118
|
|
|
|
|
|
|
# [ 'cr', 0, 0x13 ], |
119
|
|
|
|
|
|
|
# [ 'form_feed', 0, 0x0C ], |
120
|
|
|
|
|
|
|
# [ 'vertical_tab', 0, 0x0B ], |
121
|
|
|
|
|
|
|
# [ 'horizontal_tab', 0, 0x09 ], |
122
|
|
|
|
|
|
|
# ); |
123
|
|
|
|
|
|
|
# |
124
|
|
|
|
|
|
|
# for my $spec (@escape_specs) { |
125
|
|
|
|
|
|
|
# my $name = shift @$spec; |
126
|
|
|
|
|
|
|
# my $nargs = shift @$spec; |
127
|
|
|
|
|
|
|
# *{$name} = create_escape_code($nargs, @$spec); |
128
|
|
|
|
|
|
|
# } |
129
|
|
|
|
|
|
|
# for my $spec (@specs) { |
130
|
|
|
|
|
|
|
# my $name = shift @$spec; |
131
|
|
|
|
|
|
|
# my $nargs = shift @$spec; |
132
|
|
|
|
|
|
|
# *{$name} = create_normal_code($nargs, @$spec); |
133
|
|
|
|
|
|
|
# } |
134
|
|
|
|
|
|
|
#} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub text { |
137
|
1
|
|
|
1
|
0
|
11
|
my ($self, $text) = @_; |
138
|
1
|
|
|
|
|
4
|
$self->append_pack('A*', $text); |
139
|
1
|
|
|
|
|
3
|
return; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
1; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 NAME |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Protocol::Star::Linemode - Generates a formatted byte string for Star POS printers |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 SYNOPSIS |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
use Protocol::Star::Linemode; |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
my $p = Protocol::Star::Linemode->new; |
153
|
|
|
|
|
|
|
$p->set_emphasized_printing; |
154
|
|
|
|
|
|
|
$p->text("Hello world"); |
155
|
|
|
|
|
|
|
$p->cancel_emphasized_printing; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
my $formatted_output = $p->result; |
158
|
|
|
|
|
|
|
# Send $formatted_output to printer |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 Converting from 0.1.2 to 1.0.0 |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=over 4 |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=item * Create a L object instead of the L object |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=back |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 AUTHOR |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Peter Stuifzand Epeter@stuifzand.euE |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 COPYRIGHT |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Copyright 2013 - Peter Stuifzand |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head1 LICENSE |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
179
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head1 SEE ALSO |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=cut |