zebra-zpl 1.1.2 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -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 InvalidPrintDensityError < StandardError; end
8
- class PrintSpeedNotInformedError < StandardError; end
9
-
10
- attr_writer :copies
11
- attr_reader :elements, :tempfile
12
- attr_accessor :width, :length, :print_speed
13
-
14
- def initialize(options = {})
15
- options.each_pair { |key, value| self.__send__("#{key}=", value) if self.respond_to?("#{key}=") }
16
- @elements = []
17
- end
18
-
19
- def print_speed=(s)
20
- raise InvalidPrintSpeedError unless (0..6).include?(s)
21
- @print_speed = s
22
- end
23
-
24
- def copies
25
- @copies || 1
26
- end
27
-
28
- def <<(element)
29
- element.width = self.width if element.respond_to?("width=") && element.width.nil?
30
- elements << element
31
- end
32
-
33
- def dump_contents(io = STDOUT)
34
- check_required_configurations
35
- # Start format
36
- io << "^XA"
37
- # ^LL<label height in dots>,<space between labels in dots>
38
- # io << "^LL#{length},#{gap}\n" if length && gap
39
- io << "^LL#{length}" if length
40
- # ^LH<label home - x,y coordinates of top left label>
41
- io << "^LH0,0"
42
- # ^LS<shift the label to the left(or right)>
43
- io << "^LS10"
44
- # ^PW<label width in dots>
45
- io << "^PW#{width}" if width
46
- # Print Rate(speed) (^PR command)
47
- io << "^PR#{print_speed}"
48
- # Density (D command) "Carried over from EPL, does this exist in ZPL ????"
49
- # io << "D#{print_density}\n" if print_density
50
-
51
- # TEST ZPL (comment everything else out)...
52
- # io << "^XA^WD*:*.FNT*^XZ"
53
- # TEST ZPL SEGMENT
54
- # io << "^WD*:*.FNT*"
55
- # TEST AND GET CONFIGS
56
- # io << "^HH"
57
-
58
- elements.each do |element|
59
- io << element.to_zpl
60
- end
61
- # Specify how many copies to print
62
- io << "^PQ#{copies}"
63
- # End format
64
- io << "^XZ"
65
- end
66
-
67
- def persist
68
- tempfile = Tempfile.new "zebra_label"
69
- dump_contents tempfile
70
- tempfile.close
71
- @tempfile = tempfile
72
- tempfile
73
- end
74
-
75
- def persisted?
76
- !!self.tempfile
77
- end
78
-
79
- private
80
-
81
- def check_required_configurations
82
- raise PrintSpeedNotInformedError unless print_speed
83
- end
84
- end
85
- end
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
@@ -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
- def font_size=(f)
13
- FontSize.validate_font_size f
14
- @font_size = f
15
- end
16
-
17
- def bold=(value)
18
- @bold = value
19
- end
20
-
21
- def width=(width)
22
- unless (margin.nil? || margin < 1)
23
- @width = (width - (margin*2))
24
- else
25
- @width = width || 0
26
- end
27
- end
28
-
29
- def max_lines=(value)
30
- raise InvalidMaxLinesError unless value.to_i >= 1
31
- @max_lines = value
32
- end
33
-
34
- def line_spacing=(value)
35
- @line_spacing = value || 0
36
- end
37
-
38
- def hanging_indent=(value)
39
- @hanging_indent = value || 0
40
- end
41
-
42
- def font_type=(type)
43
- FontType.validate_font_type type
44
- @font_type = type
45
- end
46
-
47
- def font_type
48
- @font_type || FontType::TYPE_0
49
- end
50
-
51
- def print_mode=(mode)
52
- PrintMode.validate_mode mode
53
- @print_mode = mode
54
- end
55
-
56
- def print_mode
57
- @print_mode || PrintMode::NORMAL
58
- end
59
-
60
- # def h_multiplier
61
- # @h_multiplier || HorizontalMultiplier::VALUE_1
62
- # end
63
- #
64
- # def v_multiplier
65
- # @v_multiplier || VerticalMultiplier::VALUE_1
66
- # end
67
-
68
- def print_mode
69
- @print_mode || PrintMode::NORMAL
70
- end
71
-
72
- def max_lines
73
- @max_lines || 4
74
- end
75
-
76
- # def h_multiplier=(multiplier)
77
- # HorizontalMultiplier.validate_multiplier multiplier
78
- # @h_multiplier = multiplier
79
- # end
80
- #
81
- # def v_multiplier=(multiplier)
82
- # VerticalMultiplier.validate_multiplier multiplier
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
@@ -1,5 +1,5 @@
1
- module Zebra
2
- module Zpl
3
- VERSION = '1.1.2'.freeze
4
- end
5
- end
1
+ module Zebra
2
+ module Zpl
3
+ VERSION = '1.1.4'.freeze
4
+ end
5
+ end