zebra-zpl 1.1.3 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +79 -71
- data/README.md +442 -439
- data/docs/example.rb +290 -290
- data/lib/zebra/zpl/barcode.rb +124 -72
- data/lib/zebra/zpl/barcode_type.rb +38 -37
- data/lib/zebra/zpl/font.rb +48 -47
- data/lib/zebra/zpl/graphic.rb +93 -91
- data/lib/zebra/zpl/label.rb +89 -86
- data/lib/zebra/zpl/text.rb +82 -104
- data/lib/zebra/zpl/version.rb +5 -5
- data/spec/zebra/zpl/barcode_spec.rb +270 -203
- data/spec/zebra/zpl/image_spec.rb +146 -146
- data/spec/zebra/zpl/label_spec.rb +110 -126
- data/spec/zebra/zpl/text_spec.rb +109 -144
- metadata +3 -3
data/lib/zebra/zpl/label.rb
CHANGED
@@ -1,86 +1,89 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Zebra
|
4
|
-
module Zpl
|
5
|
-
class Label
|
6
|
-
class InvalidPrintSpeedError < StandardError; end
|
7
|
-
class
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
#
|
39
|
-
io << "^
|
40
|
-
# ^
|
41
|
-
io << "^
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
#
|
50
|
-
|
51
|
-
#
|
52
|
-
# io << "
|
53
|
-
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
tempfile
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Zebra
|
4
|
+
module Zpl
|
5
|
+
class Label
|
6
|
+
class InvalidPrintSpeedError < StandardError; end
|
7
|
+
class PrintSpeedNotInformedError < StandardError; end
|
8
|
+
|
9
|
+
attr_writer :copies, :label_shift
|
10
|
+
attr_reader :elements, :tempfile
|
11
|
+
attr_accessor :width, :length, :print_speed
|
12
|
+
|
13
|
+
def initialize(options = {})
|
14
|
+
options.each_pair { |key, value| self.__send__("#{key}=", value) if self.respond_to?("#{key}=") }
|
15
|
+
@elements = []
|
16
|
+
end
|
17
|
+
|
18
|
+
def print_speed=(s)
|
19
|
+
raise InvalidPrintSpeedError unless (0..14).include?(s)
|
20
|
+
@print_speed = s
|
21
|
+
end
|
22
|
+
|
23
|
+
def copies
|
24
|
+
@copies || 1
|
25
|
+
end
|
26
|
+
|
27
|
+
def label_shift
|
28
|
+
@label_shift || 10
|
29
|
+
end
|
30
|
+
|
31
|
+
def <<(element)
|
32
|
+
element.width = self.width if element.respond_to?("width=") && element.width.nil?
|
33
|
+
elements << element
|
34
|
+
end
|
35
|
+
|
36
|
+
def dump_contents(io = STDOUT)
|
37
|
+
check_required_configurations
|
38
|
+
# Start format
|
39
|
+
io << "^XA"
|
40
|
+
# ^LL<label height in dots>,<space between labels in dots>
|
41
|
+
# io << "^LL#{length},#{gap}\n" if length && gap
|
42
|
+
io << "^LL#{length}" if length
|
43
|
+
# ^LH<label home - x,y coordinates of top left label>
|
44
|
+
io << "^LH0,0"
|
45
|
+
# ^LS<shift the label to the left(or right)>
|
46
|
+
io << "^LS#{label_shift}"
|
47
|
+
# ^PW<label width in dots>
|
48
|
+
io << "^PW#{width}" if width
|
49
|
+
# Print Rate(speed) (^PR command)
|
50
|
+
io << "^PR#{print_speed}"
|
51
|
+
# Density (D command) "Carried over from EPL, does this exist in ZPL ????"
|
52
|
+
# io << "D#{print_density}\n" if print_density
|
53
|
+
|
54
|
+
# TEST ZPL (comment everything else out)...
|
55
|
+
# io << "^XA^WD*:*.FNT*^XZ"
|
56
|
+
# TEST ZPL SEGMENT
|
57
|
+
# io << "^WD*:*.FNT*"
|
58
|
+
# TEST AND GET CONFIGS
|
59
|
+
# io << "^HH"
|
60
|
+
|
61
|
+
elements.each do |element|
|
62
|
+
io << element.to_zpl
|
63
|
+
end
|
64
|
+
# Specify how many copies to print
|
65
|
+
io << "^PQ#{copies}"
|
66
|
+
# End format
|
67
|
+
io << "^XZ"
|
68
|
+
end
|
69
|
+
|
70
|
+
def persist
|
71
|
+
tempfile = Tempfile.new "zebra_label"
|
72
|
+
dump_contents tempfile
|
73
|
+
tempfile.close
|
74
|
+
@tempfile = tempfile
|
75
|
+
tempfile
|
76
|
+
end
|
77
|
+
|
78
|
+
def persisted?
|
79
|
+
!!self.tempfile
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
def check_required_configurations
|
85
|
+
raise PrintSpeedNotInformedError unless print_speed
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
data/lib/zebra/zpl/text.rb
CHANGED
@@ -1,104 +1,82 @@
|
|
1
|
-
require "zebra/zpl/printable"
|
2
|
-
|
3
|
-
module Zebra
|
4
|
-
module Zpl
|
5
|
-
class Text
|
6
|
-
include Printable
|
7
|
-
|
8
|
-
class InvalidMaxLinesError < StandardError; end
|
9
|
-
|
10
|
-
attr_reader :font_size, :font_type, :width, :line_spacing, :hanging_indent, :bold
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
@
|
45
|
-
end
|
46
|
-
|
47
|
-
def font_type
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
@
|
54
|
-
end
|
55
|
-
|
56
|
-
def
|
57
|
-
@
|
58
|
-
end
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
def
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
# @v_multiplier = multiplier
|
84
|
-
# end
|
85
|
-
|
86
|
-
def to_zpl
|
87
|
-
check_attributes
|
88
|
-
if !bold.nil?
|
89
|
-
"^FW#{rotation}^CF#{font_type},#{font_size}^CI28^FO#{x+2},#{y}^FB#{width},#{max_lines},#{line_spacing},#{justification},#{hanging_indent}^FD#{data}^FS" +
|
90
|
-
"^FW#{rotation}^CF#{font_type},#{font_size}^CI28^FO#{x},#{y+2}^FB#{width},#{max_lines},#{line_spacing},#{justification},#{hanging_indent}^FD#{data}^FS"
|
91
|
-
else
|
92
|
-
"^FW#{rotation}^CF#{font_type},#{font_size}^CI28^FO#{x},#{y}^FB#{width},#{max_lines},#{line_spacing},#{justification},#{hanging_indent}^FD#{data}^FS"
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
private
|
97
|
-
|
98
|
-
def check_attributes
|
99
|
-
super
|
100
|
-
raise MissingAttributeError.new("the font_size to be used is not given") unless @font_size
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
1
|
+
require "zebra/zpl/printable"
|
2
|
+
|
3
|
+
module Zebra
|
4
|
+
module Zpl
|
5
|
+
class Text
|
6
|
+
include Printable
|
7
|
+
|
8
|
+
class InvalidMaxLinesError < StandardError; end
|
9
|
+
|
10
|
+
attr_reader :font_size, :font_type, :width, :line_spacing, :hanging_indent, :bold
|
11
|
+
attr_writer :reverse_print
|
12
|
+
|
13
|
+
def font_size=(f)
|
14
|
+
FontSize.validate_font_size f
|
15
|
+
@font_size = f
|
16
|
+
end
|
17
|
+
|
18
|
+
def bold=(value)
|
19
|
+
@bold = value
|
20
|
+
end
|
21
|
+
|
22
|
+
def width=(width)
|
23
|
+
if (margin.nil? || margin < 1)
|
24
|
+
@width = width || 0
|
25
|
+
else
|
26
|
+
@width = (width - (margin*2))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def max_lines=(value)
|
31
|
+
raise InvalidMaxLinesError unless value.to_i >= 1
|
32
|
+
@max_lines = value
|
33
|
+
end
|
34
|
+
|
35
|
+
def max_lines
|
36
|
+
@max_lines || 4
|
37
|
+
end
|
38
|
+
|
39
|
+
def line_spacing=(value)
|
40
|
+
@line_spacing = value || 0
|
41
|
+
end
|
42
|
+
|
43
|
+
def hanging_indent=(value)
|
44
|
+
@hanging_indent = value || 0
|
45
|
+
end
|
46
|
+
|
47
|
+
def font_type=(type)
|
48
|
+
FontType.validate_font_type type
|
49
|
+
@font_type = type
|
50
|
+
end
|
51
|
+
|
52
|
+
def font_type
|
53
|
+
@font_type || FontType::TYPE_0
|
54
|
+
end
|
55
|
+
|
56
|
+
def reverse_print
|
57
|
+
@reverse_print || false
|
58
|
+
end
|
59
|
+
|
60
|
+
def to_zpl
|
61
|
+
check_attributes
|
62
|
+
if !bold.nil?
|
63
|
+
"^FW#{rotation}^A#{font_type},#{font_size}^CI28^FO#{x+1},#{y}^FB#{width},#{max_lines},#{line_spacing},#{justification},#{hanging_indent}#{appear_in_reverse}^FD#{data}^FS" +
|
64
|
+
"^FW#{rotation}^A#{font_type},#{font_size}^CI28^FO#{x},#{y+1}^FB#{width},#{max_lines},#{line_spacing},#{justification},#{hanging_indent}#{appear_in_reverse}^FD#{data}^FS"
|
65
|
+
else
|
66
|
+
"^FW#{rotation}^A#{font_type},#{font_size}^CI28^FO#{x},#{y}^FB#{width},#{max_lines},#{line_spacing},#{justification},#{hanging_indent}#{appear_in_reverse}^FD#{data}^FS"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def check_attributes
|
73
|
+
super
|
74
|
+
raise MissingAttributeError.new("the font_size to be used is not given") unless @font_size
|
75
|
+
end
|
76
|
+
|
77
|
+
def appear_in_reverse
|
78
|
+
reverse_print ? '^FR' : ''
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/lib/zebra/zpl/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
module Zebra
|
2
|
-
module Zpl
|
3
|
-
VERSION = '1.1.
|
4
|
-
end
|
5
|
-
end
|
1
|
+
module Zebra
|
2
|
+
module Zpl
|
3
|
+
VERSION = '1.1.4'.freeze
|
4
|
+
end
|
5
|
+
end
|