escpos 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -2
- data/examples/IMG_20160608_001339_HDR.jpg +0 -0
- data/examples/IMG_20160610_161302_HDR.jpg +0 -0
- data/examples/IMG_20160610_204358_HDR.jpg +0 -0
- data/lib/escpos/helpers.rb +53 -33
- data/lib/escpos/printer.rb +1 -1
- data/lib/escpos/version.rb +1 -1
- data/lib/escpos.rb +48 -0
- data/test/fixtures/styles.erb +7 -1
- data/test/lib/escpos/printer_test.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb7ee79d9d2c9a0bb174647d37bba0dc123f50ef
|
4
|
+
data.tar.gz: 217b77168da1f85b9e35fc60c03de5b1cfc4e21a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26dbc112a89688ed3cff1abf4feff0dd87360b4d27393524dff4c04a59fcc6e4924d291149fb70e2c120c9d12e9b2aa051bdbbb34b408f5efcb9a688d4f894cb
|
7
|
+
data.tar.gz: f9defcbfa5b312537a8c41504d1e2f9d82a6dd762e3587f005ba39f56fc608e3db181be20065251adb7bfbb75d8ac95be475b4ddff005911695828e91a902775
|
data/README.md
CHANGED
@@ -8,6 +8,9 @@ Add this line to your application's Gemfile:
|
|
8
8
|
|
9
9
|
```ruby
|
10
10
|
gem 'escpos'
|
11
|
+
|
12
|
+
# see https://github.com/escpos/escpos-image
|
13
|
+
gem 'escpos-image' # add this if you want to print PNG images
|
11
14
|
```
|
12
15
|
|
13
16
|
And then execute:
|
@@ -18,6 +21,12 @@ Or install it yourself as:
|
|
18
21
|
|
19
22
|
$ gem install escpos
|
20
23
|
|
24
|
+
## Examples
|
25
|
+
|
26
|
+
![](https://github.com/escpos/escpos/blob/master/examples/IMG_20160608_001339_HDR.jpg)
|
27
|
+
![](https://github.com/escpos/escpos/blob/master/examples/IMG_20160610_161302_HDR.jpg)
|
28
|
+
![](https://github.com/escpos/escpos/blob/master/examples/IMG_20160610_204358_HDR.jpg)
|
29
|
+
|
21
30
|
## Usage
|
22
31
|
|
23
32
|
```ruby
|
@@ -64,8 +73,8 @@ report = MyReport.new 'path/to/my_report.erb'
|
|
64
73
|
|
65
74
|
- text: Normal text formatting
|
66
75
|
- double_height: Double height text
|
67
|
-
- quad_text, big, title header, double_width_double_height, double_height_double_width: Double width & Double height text
|
68
|
-
- double_width: Double
|
76
|
+
- quad_text, big, title, header, double_width_double_height, double_height_double_width: Double width & Double height text
|
77
|
+
- double_width: Double width text
|
69
78
|
- underline, u: Underlined text
|
70
79
|
- underline2, u2: Stronger underlined text
|
71
80
|
- bold, b: Bold text
|
Binary file
|
Binary file
|
Binary file
|
data/lib/escpos/helpers.rb
CHANGED
@@ -2,37 +2,48 @@ module Escpos
|
|
2
2
|
module Helpers
|
3
3
|
|
4
4
|
# Encodes UTF-8 string to encoding acceptable for the printer
|
5
|
-
# The printer must be set to that encoding
|
5
|
+
# The printer must be set to that encoding
|
6
6
|
# Available encodings can be listed in console using Encoding.constants
|
7
7
|
def encode(data, opts = {})
|
8
|
-
data.encode(opts.fetch(:encoding
|
8
|
+
data.encode(opts.fetch(:encoding), 'UTF-8', {
|
9
9
|
invalid: opts.fetch(:invalid, :replace),
|
10
10
|
undef: opts.fetch(:undef, :replace),
|
11
11
|
replace: opts.fetch(:replace, '?')
|
12
12
|
})
|
13
13
|
end
|
14
14
|
|
15
|
+
# Set printer encoding
|
16
|
+
# example: encoding(Escpos::CP_ISO8859_2)
|
17
|
+
def encoding(data)
|
18
|
+
[
|
19
|
+
Escpos.sequence(Escpos::CP_SET),
|
20
|
+
Escpos.sequence(data)
|
21
|
+
].join
|
22
|
+
end
|
23
|
+
alias :set_encoding :encoding
|
24
|
+
alias :set_printer_encoding :encoding
|
25
|
+
|
15
26
|
def text(data)
|
16
27
|
[
|
17
|
-
Escpos.sequence(TXT_NORMAL),
|
28
|
+
Escpos.sequence(Escpos::TXT_NORMAL),
|
18
29
|
data,
|
19
|
-
Escpos.sequence(TXT_NORMAL),
|
30
|
+
Escpos.sequence(Escpos::TXT_NORMAL),
|
20
31
|
].join
|
21
32
|
end
|
22
33
|
|
23
34
|
def double_height(data)
|
24
35
|
[
|
25
|
-
Escpos.sequence(TXT_2HEIGHT),
|
36
|
+
Escpos.sequence(Escpos::TXT_2HEIGHT),
|
26
37
|
data,
|
27
|
-
Escpos.sequence(TXT_NORMAL),
|
38
|
+
Escpos.sequence(Escpos::TXT_NORMAL),
|
28
39
|
].join
|
29
40
|
end
|
30
41
|
|
31
42
|
def quad_text(data)
|
32
43
|
[
|
33
|
-
Escpos.sequence(TXT_4SQUARE),
|
44
|
+
Escpos.sequence(Escpos::TXT_4SQUARE),
|
34
45
|
data,
|
35
|
-
Escpos.sequence(TXT_NORMAL),
|
46
|
+
Escpos.sequence(Escpos::TXT_NORMAL),
|
36
47
|
].join
|
37
48
|
end
|
38
49
|
alias :big :quad_text
|
@@ -43,67 +54,76 @@ module Escpos
|
|
43
54
|
|
44
55
|
def double_width(data)
|
45
56
|
[
|
46
|
-
Escpos.sequence(TXT_2WIDTH),
|
57
|
+
Escpos.sequence(Escpos::TXT_2WIDTH),
|
47
58
|
data,
|
48
|
-
Escpos.sequence(TXT_NORMAL),
|
59
|
+
Escpos.sequence(Escpos::TXT_NORMAL),
|
49
60
|
].join
|
50
61
|
end
|
51
62
|
|
52
63
|
def underline(data)
|
53
64
|
[
|
54
|
-
Escpos.sequence(TXT_UNDERL_ON),
|
65
|
+
Escpos.sequence(Escpos::TXT_UNDERL_ON),
|
55
66
|
data,
|
56
|
-
Escpos.sequence(TXT_UNDERL_OFF),
|
67
|
+
Escpos.sequence(Escpos::TXT_UNDERL_OFF),
|
57
68
|
].join
|
58
69
|
end
|
59
70
|
alias :u :underline
|
60
71
|
|
61
72
|
def underline2(data)
|
62
73
|
[
|
63
|
-
Escpos.sequence(TXT_UNDERL2_ON),
|
74
|
+
Escpos.sequence(Escpos::TXT_UNDERL2_ON),
|
64
75
|
data,
|
65
|
-
Escpos.sequence(TXT_UNDERL_OFF),
|
76
|
+
Escpos.sequence(Escpos::TXT_UNDERL_OFF),
|
66
77
|
].join
|
67
78
|
end
|
68
79
|
alias :u2 :underline2
|
69
80
|
|
70
81
|
def bold(data)
|
71
82
|
[
|
72
|
-
Escpos.sequence(TXT_BOLD_ON),
|
83
|
+
Escpos.sequence(Escpos::TXT_BOLD_ON),
|
73
84
|
data,
|
74
|
-
Escpos.sequence(TXT_BOLD_OFF),
|
85
|
+
Escpos.sequence(Escpos::TXT_BOLD_OFF),
|
75
86
|
].join
|
76
87
|
end
|
77
88
|
alias :b :bold
|
78
89
|
|
79
|
-
def left(data)
|
90
|
+
def left(data = '')
|
91
|
+
[
|
92
|
+
Escpos.sequence(Escpos::TXT_ALIGN_LT),
|
93
|
+
data,
|
94
|
+
Escpos.sequence(Escpos::TXT_ALIGN_LT),
|
95
|
+
].join
|
96
|
+
end
|
97
|
+
|
98
|
+
def right(data = '')
|
80
99
|
[
|
81
|
-
Escpos.sequence(
|
100
|
+
Escpos.sequence(Escpos::TXT_ALIGN_RT),
|
82
101
|
data,
|
83
|
-
Escpos.sequence(TXT_ALIGN_LT),
|
102
|
+
Escpos.sequence(Escpos::TXT_ALIGN_LT),
|
84
103
|
].join
|
85
104
|
end
|
86
105
|
|
87
|
-
def
|
106
|
+
def center(data = '')
|
88
107
|
[
|
89
|
-
Escpos.sequence(
|
108
|
+
Escpos.sequence(Escpos::TXT_ALIGN_CT),
|
90
109
|
data,
|
91
|
-
Escpos.sequence(TXT_ALIGN_LT),
|
110
|
+
Escpos.sequence(Escpos::TXT_ALIGN_LT),
|
92
111
|
].join
|
93
112
|
end
|
94
113
|
|
95
|
-
def
|
114
|
+
def inverted(data)
|
96
115
|
[
|
97
|
-
Escpos.sequence(
|
116
|
+
Escpos.sequence(Escpos::TXT_INVERT_ON),
|
98
117
|
data,
|
99
|
-
Escpos.sequence(
|
118
|
+
Escpos.sequence(Escpos::TXT_INVERT_OFF),
|
100
119
|
].join
|
101
120
|
end
|
121
|
+
alias :invert :inverted
|
102
122
|
|
103
123
|
def barcode(data, opts = {})
|
104
|
-
text_position = opts.fetch(:text_position, BARCODE_TXT_OFF)
|
105
|
-
unless [BARCODE_TXT_OFF, BARCODE_TXT_ABV, BARCODE_TXT_BLW, BARCODE_TXT_BTH].include?(text_position)
|
106
|
-
raise ArgumentError("Text position must be one of the following: BARCODE_TXT_OFF, BARCODE_TXT_ABV, BARCODE_TXT_BLW, BARCODE_TXT_BTH.")
|
124
|
+
text_position = opts.fetch(:text_position, Escpos::BARCODE_TXT_OFF)
|
125
|
+
unless [Escpos::BARCODE_TXT_OFF, Escpos::BARCODE_TXT_ABV, Escpos::BARCODE_TXT_BLW, Escpos::BARCODE_TXT_BTH].include?(text_position)
|
126
|
+
raise ArgumentError("Text position must be one of the following: Escpos::BARCODE_TXT_OFF, Escpos::BARCODE_TXT_ABV, Escpos::BARCODE_TXT_BLW, Escpos::BARCODE_TXT_BTH.")
|
107
127
|
end
|
108
128
|
height = opts.fetch(:height, 50)
|
109
129
|
raise ArgumentError("Height must be in range from 1 to 255.") if height && (height < 1 || height > 255)
|
@@ -111,21 +131,21 @@ module Escpos
|
|
111
131
|
raise ArgumentError("Width must be in range from 2 to 6.") if width && (width < 2 || width > 6)
|
112
132
|
[
|
113
133
|
Escpos.sequence(text_position),
|
114
|
-
Escpos.sequence(BARCODE_WIDTH),
|
134
|
+
Escpos.sequence(Escpos::BARCODE_WIDTH),
|
115
135
|
Escpos.sequence([width]),
|
116
|
-
Escpos.sequence(BARCODE_HEIGHT),
|
136
|
+
Escpos.sequence(Escpos::BARCODE_HEIGHT),
|
117
137
|
Escpos.sequence([height]),
|
118
|
-
Escpos.sequence(opts.fetch(:format, BARCODE_EAN13)),
|
138
|
+
Escpos.sequence(opts.fetch(:format, Escpos::BARCODE_EAN13)),
|
119
139
|
data
|
120
140
|
].join
|
121
141
|
end
|
122
142
|
|
123
143
|
def partial_cut
|
124
|
-
Escpos.sequence(PAPER_PARTIAL_CUT)
|
144
|
+
Escpos.sequence(Escpos::PAPER_PARTIAL_CUT)
|
125
145
|
end
|
126
146
|
|
127
147
|
def cut
|
128
|
-
Escpos.sequence(PAPER_FULL_CUT)
|
148
|
+
Escpos.sequence(Escpos::PAPER_FULL_CUT)
|
129
149
|
end
|
130
150
|
|
131
151
|
end
|
data/lib/escpos/printer.rb
CHANGED
data/lib/escpos/version.rb
CHANGED
data/lib/escpos.rb
CHANGED
@@ -20,11 +20,57 @@ module Escpos
|
|
20
20
|
# Paper
|
21
21
|
PAPER_FULL_CUT = [ 0x1d, 0x56, 0x00 ] # Full paper cut
|
22
22
|
PAPER_PARTIAL_CUT = [ 0x1d, 0x56, 0x01 ] # Partial paper cut
|
23
|
+
PAPER_CUT_A = [ 0x1d, 0x56, 0x41 ] # Paper cut A
|
24
|
+
PAPER_CUT_B = [ 0x1d, 0x56, 0x42 ] # Paper cut B
|
23
25
|
|
24
26
|
# Cash Drawer
|
25
27
|
CD_KICK_2 = [ 0x1b, 0x70, 0x00 ] # Send pulse to pin 2
|
26
28
|
CD_KICK_5 = [ 0x1b, 0x70, 0x01 ] # Send pulse to pin 5
|
27
29
|
|
30
|
+
# Code Pages
|
31
|
+
CP_SET = [ 0x1b, 0x74 ] # Set Code Page
|
32
|
+
CP_CP437 = [ 0x0 ]
|
33
|
+
CP_CP850 = [ 0x2 ]
|
34
|
+
CP_CP860 = [ 0x3 ]
|
35
|
+
CP_CP863 = [ 0x4 ]
|
36
|
+
CP_CP865 = [ 0x5 ]
|
37
|
+
CP_CP1251 = [ 0x6 ]
|
38
|
+
CP_CP866 = [ 0x7 ]
|
39
|
+
CP_MACCYRILLIC = [ 0x8 ]
|
40
|
+
CP_CP775 = [ 0x9 ]
|
41
|
+
CP_CP1253 = [ 0x10 ]
|
42
|
+
CP_CP737 = [ 0x11 ]
|
43
|
+
CP_CP857 = [ 0x12 ]
|
44
|
+
CP_ISO8859_9 = [ 0x13 ]
|
45
|
+
CP_CP864 = [ 0x14 ]
|
46
|
+
CP_CP862 = [ 0x15 ]
|
47
|
+
CP_ISO8859_2 = [ 0x16 ]
|
48
|
+
CP_CP1253_ALT = [ 0x17 ]
|
49
|
+
CP_CP1250 = [ 0x18 ]
|
50
|
+
CP_CP858 = [ 0x19 ]
|
51
|
+
CP_CP1254 = [ 0x20 ]
|
52
|
+
CP_CP737_ALT = [ 0x24 ]
|
53
|
+
CP_CP1257 = [ 0x25 ]
|
54
|
+
CP_CP847 = [ 0x26 ]
|
55
|
+
CP_CP885 = [ 0x28 ]
|
56
|
+
CP_CP857_ALT = [ 0x29 ]
|
57
|
+
CP_CP1250_ALT = [ 0x30 ]
|
58
|
+
CP_CP775_ALT = [ 0x31 ]
|
59
|
+
CP_CP1254_ALT = [ 0x32 ]
|
60
|
+
CP_CP1256 = [ 0x34 ]
|
61
|
+
CP_CP1258 = [ 0x35 ]
|
62
|
+
CP_ISO8859_2_ALT = [ 0x36 ]
|
63
|
+
CP_ISO8859_3 = [ 0x37 ]
|
64
|
+
CP_ISO8859_4 = [ 0x38 ]
|
65
|
+
CP_ISO8859_5 = [ 0x39 ]
|
66
|
+
CP_ISO8859_6 = [ 0x40 ]
|
67
|
+
CP_ISO8859_7 = [ 0x41 ]
|
68
|
+
CP_ISO8859_8 = [ 0x42 ]
|
69
|
+
CP_ISO8859_9_ALT = [ 0x43 ]
|
70
|
+
CP_ISO8859_15 = [ 0x44 ]
|
71
|
+
CP_CP856 = [ 0x47 ]
|
72
|
+
CP_CP874 = [ 0x47 ]
|
73
|
+
|
28
74
|
# Text formating
|
29
75
|
TXT_NORMAL = [ 0x1b, 0x21, 0x00 ] # Normal text
|
30
76
|
TXT_2HEIGHT = [ 0x1b, 0x21, 0x10 ] # Double height text
|
@@ -40,6 +86,8 @@ module Escpos
|
|
40
86
|
TXT_ALIGN_LT = [ 0x1b, 0x61, 0x00 ] # Left justification
|
41
87
|
TXT_ALIGN_CT = [ 0x1b, 0x61, 0x01 ] # Centering
|
42
88
|
TXT_ALIGN_RT = [ 0x1b, 0x61, 0x02 ] # Right justification
|
89
|
+
TXT_INVERT_ON = [ 0x1d, 0x42, 0x01 ] # Inverted coloer text
|
90
|
+
TXT_INVERT_OFF = [ 0x1d, 0x42, 0x00 ] # Inverted coloer text
|
43
91
|
|
44
92
|
# Barcodes
|
45
93
|
BARCODE_TXT_OFF = [ 0x1d, 0x48, 0x00 ] # HRI barcode chars OFF
|
data/test/fixtures/styles.erb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
Unformatted text
|
2
2
|
|
3
|
-
<%=
|
3
|
+
<%= set_printer_encoding(Escpos::CP_ISO8859_2) %>
|
4
|
+
|
5
|
+
<%= encode "UTF-8 to ISO-8859-2 text: (ěščřžýáíéúů)", encoding: "ISO-8859-2" %>
|
4
6
|
|
5
7
|
<%= text "Normal text" %>
|
6
8
|
|
@@ -22,6 +24,10 @@ Unformatted text
|
|
22
24
|
|
23
25
|
<%= center "Centered text" %>
|
24
26
|
|
27
|
+
<%= left %>
|
28
|
+
|
29
|
+
<%= invert "Inverted color text" %>
|
30
|
+
|
25
31
|
<%= barcode "8594404000572" %>
|
26
32
|
|
27
33
|
|
@@ -11,7 +11,7 @@ class TestPrinter < Minitest::Test
|
|
11
11
|
@printer.write template.result(Class.new { include Escpos::Helpers }.new.instance_eval { binding })
|
12
12
|
@printer.cut!
|
13
13
|
#pp @printer.to_base64
|
14
|
-
assert_equal @printer.to_base64, '
|
14
|
+
assert_equal @printer.to_base64, 'G0BVbmZvcm1hdHRlZCB0ZXh0CgobdBYKClVURi04IHRvIElTTy04ODU5LTIgdGV4dDogKOy56Pi+/eHt6fr5KQoKGyEATm9ybWFsIHRleHQbIQAKChshEERvdWJsZSBoZWlnaHQgdGV4dBshAAoKGyEgRG91YmxlIHdpZHRoIHRleHQbIQAKChshMFF1YWQgYXJlYSB0ZXh0GyEACgobLQFVbmRlcmxpbmVkIHRleHQbLQAKChstAlVuZGVybGluZWQgdGV4dCAoMikbLQAKChtFAUJvbGQgdGV4dBtFAAoKG2EATGVmdCBhbGlnbmVkIHRleHQbYQAKChthAlJpZ2h0IGFsaWduZWQgdGV4dBthAAoKG2EBQ2VudGVyZWQgdGV4dBthAAoKG2EAG2EACgodQgFJbnZlcnRlZCBjb2xvciB0ZXh0HUIACgodSAAddwMdaDIdawI4NTk0NDA0MDAwNTcyCgoKCgodVgA='
|
15
15
|
end
|
16
16
|
|
17
17
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: escpos
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Svoboda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -69,6 +69,9 @@ files:
|
|
69
69
|
- bin/setup
|
70
70
|
- config
|
71
71
|
- escpos.gemspec
|
72
|
+
- examples/IMG_20160608_001339_HDR.jpg
|
73
|
+
- examples/IMG_20160610_161302_HDR.jpg
|
74
|
+
- examples/IMG_20160610_204358_HDR.jpg
|
72
75
|
- examples/report.erb
|
73
76
|
- examples/report.rb
|
74
77
|
- lib/escpos.rb
|
@@ -101,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
104
|
version: '0'
|
102
105
|
requirements: []
|
103
106
|
rubyforge_project:
|
104
|
-
rubygems_version: 2.
|
107
|
+
rubygems_version: 2.6.4
|
105
108
|
signing_key:
|
106
109
|
specification_version: 4
|
107
110
|
summary: A ruby implementation of ESC/POS (thermal) printer command specification.
|