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.
data/docs/example.rb CHANGED
@@ -1,277 +1,290 @@
1
-
2
- def print_zpl_str(name, label)
3
- zpl = ''
4
- label.dump_contents zpl
5
- puts "\n#{name}:\n#{zpl}\n\n"
6
- end
7
-
8
- def new_label
9
- Zebra::Zpl::Label.new(
10
- width: 600,
11
- length: 305,
12
- print_speed: 6,
13
- print_density: 5,
14
- copies: 1
15
- )
16
- end
17
-
18
- ################################################################################
19
- # Text
20
- ################################################################################
21
- label = new_label
22
- text = Zebra::Zpl::Text.new(
23
- data: "Hello, printer!",
24
- position: [10, 125],
25
- font_size: Zebra::Zpl::FontSize::SIZE_5,
26
- justification: Zebra::Zpl::Justification::CENTER
27
- )
28
- box = Zebra::Zpl::Graphic.new(
29
- graphic_type: 'B',
30
- position: [10,5],
31
- graphic_width: label.width,
32
- graphic_height: label.length-10,
33
- line_thickness: 1,
34
- rounding_degree: 1
35
- )
36
- label << text
37
- label << box
38
- print_zpl_str('text', label)
39
-
40
- ################################################################################
41
- # Barcode
42
- ################################################################################
43
- label = new_label
44
- barcode = Zebra::Zpl::Barcode.new(
45
- data: 'F112358',
46
- position: [80, 50],
47
- height: 150,
48
- width: 4,
49
- print_human_readable_code: true,
50
- type: Zebra::Zpl::BarcodeType::CODE_128_AUTO
51
- )
52
- label << barcode
53
- print_zpl_str('barcode', label)
54
-
55
- ################################################################################
56
- # QR Code
57
- ################################################################################
58
- label = new_label
59
- qrcode = Zebra::Zpl::Qrcode.new(
60
- data: 'www.github.com',
61
- position: [200, 45],
62
- scale_factor: 8,
63
- correction_level: 'H',
64
- )
65
- label << qrcode
66
- print_zpl_str('qrcode', label)
67
-
68
- ################################################################################
69
- # Data Matrix
70
- ################################################################################
71
- label = new_label
72
- datamatrix = Zebra::Zpl::Datamatrix.new(
73
- data: 'www.github.com',
74
- position: [225, 75],
75
- symbol_height: 10,
76
- aspect_ratio: 1
77
- )
78
- label << datamatrix
79
- print_zpl_str('datamatrix', label)
80
-
81
- ################################################################################
82
- # Graphics
83
- ################################################################################
84
- label = new_label
85
- box = Zebra::Zpl::Graphic.new(
86
- graphic_type: 'B',
87
- position: [10,10],
88
- graphic_width: 80,
89
- graphic_height: 80,
90
- line_thickness: 2,
91
- rounding_degree: 2
92
- )
93
- circle = Zebra::Zpl::Graphic.new(
94
- graphic_type: 'C',
95
- position: [100,10],
96
- graphic_width: 80,
97
- line_thickness: 3
98
- )
99
- diagonal1 = Zebra::Zpl::Graphic.new(
100
- graphic_type: 'D',
101
- position: [190,10],
102
- graphic_width: 80,
103
- graphic_height: 80,
104
- line_thickness: 3,
105
- orientation: 'R'
106
- )
107
- diagonal2 = diagonal1.dup
108
- diagonal2.orientation = 'L'
109
- ellipse = Zebra::Zpl::Graphic.new(
110
- graphic_type: 'E',
111
- position: [280,10],
112
- graphic_width: 40,
113
- graphic_height: 80,
114
- line_thickness: 3
115
- )
116
- symbol = Zebra::Zpl::Graphic.new(
117
- graphic_type: 'S',
118
- symbol_type: 'B',
119
- position: [335,10],
120
- graphic_width: 80,
121
- graphic_height: 80
122
- )
123
-
124
- label << box
125
- label << circle
126
- label << diagonal1
127
- label << diagonal2
128
- label << ellipse
129
- label << symbol
130
- label.elements.each { |e| e.position = [e.x + 110 , e.y + 90] }
131
- print_zpl_str('graphics', label)
132
-
133
- ################################################################################
134
- # Images
135
- ################################################################################
136
- label = new_label
137
- image = Zebra::Zpl::Image.new(
138
- path: File.expand_path('./images/earth.jpg', File.dirname(__FILE__)),
139
- position: [145, 0],
140
- width: 305,
141
- height: 305
142
- )
143
- label << image
144
- print_zpl_str('image', label)
145
-
146
- # inverted image
147
- label = new_label
148
- image = Zebra::Zpl::Image.new(
149
- path: File.expand_path('./images/earth.jpg', File.dirname(__FILE__)),
150
- position: [145, 0],
151
- width: 305,
152
- height: 305,
153
- invert: true
154
- )
155
- label << image
156
- print_zpl_str('image_inverted', label)
157
-
158
- ################################################################################
159
- # Image Manipulation
160
- ################################################################################
161
- label = new_label
162
- image = Zebra::Zpl::Image.new(
163
- path: File.expand_path('./images/ruby.png', File.dirname(__FILE__)),
164
- position: [0, 0],
165
- width: 305,
166
- height: 305,
167
- black_threshold: 0.65
168
- )
169
- src = image.source
170
- src.background('white').flatten
171
-
172
- # perform edge detection on the image
173
- MiniMagick::Tool::Convert.new do |convert|
174
- convert << src.path
175
- convert << '-colorspace' << 'gray'
176
- convert << '-edge' << '4'
177
- convert << '-negate'
178
- convert << src.path
179
- end
180
-
181
- src.trim
182
-
183
- label << image
184
- print_zpl_str('image_manipulation', label)
185
-
186
- ################################################################################
187
- # Justification
188
- ################################################################################
189
- label = new_label
190
- t1 = Zebra::Zpl::Text.new(
191
- data: "ZPL",
192
- position: [10, 25],
193
- font_size: Zebra::Zpl::FontSize::SIZE_5,
194
- justification: Zebra::Zpl::Justification::LEFT
195
- )
196
- t2 = Zebra::Zpl::Text.new(
197
- data: "ZPL",
198
- position: [10, 65],
199
- font_size: Zebra::Zpl::FontSize::SIZE_5,
200
- justification: Zebra::Zpl::Justification::CENTER
201
- )
202
- t3 = Zebra::Zpl::Text.new(
203
- data: "ZPL",
204
- position: [10, 105],
205
- font_size: Zebra::Zpl::FontSize::SIZE_5,
206
- justification: Zebra::Zpl::Justification::RIGHT
207
- )
208
- t4 = Zebra::Zpl::Text.new(
209
- data: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua",
210
- position: [10, 180],
211
- font_size: Zebra::Zpl::FontSize::SIZE_4,
212
- justification: Zebra::Zpl::Justification::JUSTIFIED
213
- )
214
- box = Zebra::Zpl::Graphic.new(
215
- graphic_type: 'B',
216
- position: [10,5],
217
- graphic_width: label.width,
218
- graphic_height: label.length-10,
219
- line_thickness: 1,
220
- rounding_degree: 1
221
- )
222
- label << t1
223
- label << t2
224
- label << t3
225
- label << t4
226
- label << box
227
- print_zpl_str('justification', label)
228
-
229
- ################################################################################
230
- # Rotation
231
- ################################################################################
232
- label = new_label
233
- t1 = Zebra::Zpl::Text.new(
234
- data: "Zero",
235
- position: [10, 125],
236
- font_size: Zebra::Zpl::FontSize::SIZE_5,
237
- rotation: Zebra::Zpl::Rotation::NO_ROTATION,
238
- max_lines: 1
239
- )
240
- t2 = Zebra::Zpl::Text.new(
241
- data: "90",
242
- position: [100, 125],
243
- font_size: Zebra::Zpl::FontSize::SIZE_5,
244
- rotation: Zebra::Zpl::Rotation::DEGREES_90,
245
- max_lines: 1
246
- )
247
- t3 = Zebra::Zpl::Text.new(
248
- data: "180",
249
- position: [175, 125],
250
- font_size: Zebra::Zpl::FontSize::SIZE_5,
251
- rotation: Zebra::Zpl::Rotation::DEGREES_180,
252
- justification: Zebra::Zpl::Justification::RIGHT,
253
- max_lines: 1
254
- )
255
- t4 = Zebra::Zpl::Text.new(
256
- data: "270",
257
- position: [275, 125],
258
- font_size: Zebra::Zpl::FontSize::SIZE_5,
259
- rotation: Zebra::Zpl::Rotation::DEGREES_270,
260
- justification: Zebra::Zpl::Justification::RIGHT,
261
- max_lines: 1
262
- )
263
- box = Zebra::Zpl::Graphic.new(
264
- graphic_type: 'B',
265
- position: [10,5],
266
- graphic_width: label.width,
267
- graphic_height: label.length-10,
268
- line_thickness: 1,
269
- rounding_degree: 1
270
- )
271
- label << t1
272
- label << t2
273
- label << t3
274
- label << t4
275
- label.elements.each { |e| e.position = [e.x + 150, e.y] }
276
- label << box
277
- print_zpl_str('rotation', label)
1
+ require_relative '../lib/zebra/zpl'
2
+
3
+ def print_zpl_str(name, label)
4
+ zpl = ''
5
+ label.dump_contents zpl
6
+ puts "\n#{name}:\n#{zpl}\n\n"
7
+ end
8
+
9
+ def new_label
10
+ Zebra::Zpl::Label.new(
11
+ width: 600,
12
+ length: 305,
13
+ print_speed: 6,
14
+ print_density: 5,
15
+ copies: 1
16
+ )
17
+ end
18
+
19
+ ################################################################################
20
+ # Text
21
+ ################################################################################
22
+ label = new_label
23
+ text = Zebra::Zpl::Text.new(
24
+ data: "Hello, printer!",
25
+ position: [10, 125],
26
+ font_size: Zebra::Zpl::FontSize::SIZE_5,
27
+ justification: Zebra::Zpl::Justification::CENTER
28
+ )
29
+ box = Zebra::Zpl::Graphic.new(
30
+ graphic_type: 'B',
31
+ position: [10,5],
32
+ graphic_width: label.width,
33
+ graphic_height: label.length-10,
34
+ line_thickness: 1,
35
+ rounding_degree: 1
36
+ )
37
+ label << text
38
+ label << box
39
+ print_zpl_str('text', label)
40
+
41
+ ################################################################################
42
+ # Raw ZPL
43
+ ################################################################################
44
+ label = new_label
45
+ zpl_string = "^GFA,1300,1300,13,,::::::O01IFE,N01KFE,N0MFC,M03NF,M0OFC,L03PF,L0QF8,K01QFE,K03RF,K07RF8,J01SFC,J03F9OFE7E,J07F01MFE03F,J07E007LF803F8,J0FE003KFE001FC,I01FEI0FC00FC001FE,I03FCI04M01FF,I07FCQ01FF,I07FCQ01FF8,I0FFCQ01FFC,I0FFEQ01FFC,001FFEQ01FFE,:003FFEQ03IF,003FFEQ01IF,007FFCR0IF,007FFCR0IF8,007FF8R07FF8,00IFS03FF8,00IFS03FFC,:00FFES01FFC,01FFES01FFC,01FFES01FFE,:01FFCS01FFE,:::::01FFES01FFE,::01FFES03FFE,01IFS03FFE,01IFS03FFC,01IF8R07FFC,00IF8R0IFC,00IFCR0IFC,00IFEQ01IFC,00JFQ03IF8,007IF8P07IF8,007IFCP0JF8,007JFO03JF,003F87FCN0KF,003F81FFM03JFE,001F80FFEK01KFE,001FC07FFCJ0LFC,I0FF03FF8J0LFC,I0FF03FF8J07KF8,I07F81FF8J07KF8,I03F807F8J07KF,I03FC004K07JFE,I01FCN07JFE,J0FEN07JFC,J07FN07JF8,J03F8M07JF,J01FCM07IFE,K0FFM07IFC,K07IF8J07IF8,K03IF8J07IF,L0IF8J07FFC,L07FF8J07FF8,L01FF8J07FE,M0FF8J07F8,M01F8J07E,N07K038,,::::::::::::::^FS"
46
+ raw_zpl = Zebra::Zpl::Raw.new(
47
+ data: zpl_string,
48
+ position: [50, 50],
49
+ )
50
+ label << raw_zpl
51
+ print_zpl_str('raw_zpl', label)
52
+
53
+ ################################################################################
54
+ # Barcode
55
+ ################################################################################
56
+ label = new_label
57
+ barcode = Zebra::Zpl::Barcode.new(
58
+ data: 'F112358',
59
+ position: [80, 50],
60
+ height: 150,
61
+ width: 4,
62
+ print_human_readable_code: true,
63
+ type: Zebra::Zpl::BarcodeType::CODE_128_AUTO
64
+ )
65
+ label << barcode
66
+ print_zpl_str('barcode', label)
67
+
68
+ ################################################################################
69
+ # QR Code
70
+ ################################################################################
71
+ label = new_label
72
+ qrcode = Zebra::Zpl::Qrcode.new(
73
+ data: 'www.github.com',
74
+ position: [200, 45],
75
+ scale_factor: 8,
76
+ correction_level: 'H',
77
+ )
78
+ label << qrcode
79
+ print_zpl_str('qrcode', label)
80
+
81
+ ################################################################################
82
+ # Data Matrix
83
+ ################################################################################
84
+ label = new_label
85
+ datamatrix = Zebra::Zpl::Datamatrix.new(
86
+ data: 'www.github.com',
87
+ position: [225, 75],
88
+ symbol_height: 10,
89
+ aspect_ratio: 1
90
+ )
91
+ label << datamatrix
92
+ print_zpl_str('datamatrix', label)
93
+
94
+ ################################################################################
95
+ # Graphics
96
+ ################################################################################
97
+ label = new_label
98
+ box = Zebra::Zpl::Graphic.new(
99
+ graphic_type: 'B',
100
+ position: [10,10],
101
+ graphic_width: 80,
102
+ graphic_height: 80,
103
+ line_thickness: 2,
104
+ rounding_degree: 2
105
+ )
106
+ circle = Zebra::Zpl::Graphic.new(
107
+ graphic_type: 'C',
108
+ position: [100,10],
109
+ graphic_width: 80,
110
+ line_thickness: 3
111
+ )
112
+ diagonal1 = Zebra::Zpl::Graphic.new(
113
+ graphic_type: 'D',
114
+ position: [190,10],
115
+ graphic_width: 80,
116
+ graphic_height: 80,
117
+ line_thickness: 3,
118
+ orientation: 'R'
119
+ )
120
+ diagonal2 = diagonal1.dup
121
+ diagonal2.orientation = 'L'
122
+ ellipse = Zebra::Zpl::Graphic.new(
123
+ graphic_type: 'E',
124
+ position: [280,10],
125
+ graphic_width: 40,
126
+ graphic_height: 80,
127
+ line_thickness: 3
128
+ )
129
+ symbol = Zebra::Zpl::Graphic.new(
130
+ graphic_type: 'S',
131
+ symbol_type: 'B',
132
+ position: [335,10],
133
+ graphic_width: 80,
134
+ graphic_height: 80
135
+ )
136
+
137
+ label << box
138
+ label << circle
139
+ label << diagonal1
140
+ label << diagonal2
141
+ label << ellipse
142
+ label << symbol
143
+ label.elements.each { |e| e.position = [e.x + 110 , e.y + 90] }
144
+ print_zpl_str('graphics', label)
145
+
146
+ ################################################################################
147
+ # Images
148
+ ################################################################################
149
+ label = new_label
150
+ image = Zebra::Zpl::Image.new(
151
+ path: File.expand_path('./images/earth.jpg', File.dirname(__FILE__)),
152
+ position: [145, 0],
153
+ width: 305,
154
+ height: 305
155
+ )
156
+ label << image
157
+ print_zpl_str('image', label)
158
+
159
+ # inverted image
160
+ label = new_label
161
+ image = Zebra::Zpl::Image.new(
162
+ path: File.expand_path('./images/earth.jpg', File.dirname(__FILE__)),
163
+ position: [145, 0],
164
+ width: 305,
165
+ height: 305,
166
+ invert: true
167
+ )
168
+ label << image
169
+ print_zpl_str('image_inverted', label)
170
+
171
+ ################################################################################
172
+ # Image Manipulation
173
+ ################################################################################
174
+ label = new_label
175
+ image = Zebra::Zpl::Image.new(
176
+ path: File.expand_path('./images/ruby.png', File.dirname(__FILE__)),
177
+ position: [0, 0],
178
+ width: 305,
179
+ height: 305,
180
+ black_threshold: 0.65
181
+ )
182
+ src = image.source
183
+ src.background('white').flatten
184
+
185
+ # perform edge detection on the image
186
+ MiniMagick::Tool::Convert.new do |convert|
187
+ convert << src.path
188
+ convert << '-colorspace' << 'gray'
189
+ convert << '-edge' << '4'
190
+ convert << '-negate'
191
+ convert << src.path
192
+ end
193
+
194
+ src.trim
195
+
196
+ label << image
197
+ print_zpl_str('image_manipulation', label)
198
+
199
+ ################################################################################
200
+ # Justification
201
+ ################################################################################
202
+ label = new_label
203
+ t1 = Zebra::Zpl::Text.new(
204
+ data: "ZPL",
205
+ position: [10, 25],
206
+ font_size: Zebra::Zpl::FontSize::SIZE_5,
207
+ justification: Zebra::Zpl::Justification::LEFT
208
+ )
209
+ t2 = Zebra::Zpl::Text.new(
210
+ data: "ZPL",
211
+ position: [10, 65],
212
+ font_size: Zebra::Zpl::FontSize::SIZE_5,
213
+ justification: Zebra::Zpl::Justification::CENTER
214
+ )
215
+ t3 = Zebra::Zpl::Text.new(
216
+ data: "ZPL",
217
+ position: [10, 105],
218
+ font_size: Zebra::Zpl::FontSize::SIZE_5,
219
+ justification: Zebra::Zpl::Justification::RIGHT
220
+ )
221
+ t4 = Zebra::Zpl::Text.new(
222
+ data: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua",
223
+ position: [10, 180],
224
+ font_size: Zebra::Zpl::FontSize::SIZE_4,
225
+ justification: Zebra::Zpl::Justification::JUSTIFIED
226
+ )
227
+ box = Zebra::Zpl::Graphic.new(
228
+ graphic_type: 'B',
229
+ position: [10,5],
230
+ graphic_width: label.width,
231
+ graphic_height: label.length-10,
232
+ line_thickness: 1,
233
+ rounding_degree: 1
234
+ )
235
+ label << t1
236
+ label << t2
237
+ label << t3
238
+ label << t4
239
+ label << box
240
+ print_zpl_str('justification', label)
241
+
242
+ ################################################################################
243
+ # Rotation
244
+ ################################################################################
245
+ label = new_label
246
+ t1 = Zebra::Zpl::Text.new(
247
+ data: "Zero",
248
+ position: [10, 125],
249
+ font_size: Zebra::Zpl::FontSize::SIZE_5,
250
+ rotation: Zebra::Zpl::Rotation::NO_ROTATION,
251
+ max_lines: 1
252
+ )
253
+ t2 = Zebra::Zpl::Text.new(
254
+ data: "90",
255
+ position: [100, 125],
256
+ font_size: Zebra::Zpl::FontSize::SIZE_5,
257
+ rotation: Zebra::Zpl::Rotation::DEGREES_90,
258
+ max_lines: 1
259
+ )
260
+ t3 = Zebra::Zpl::Text.new(
261
+ data: "180",
262
+ position: [175, 125],
263
+ font_size: Zebra::Zpl::FontSize::SIZE_5,
264
+ rotation: Zebra::Zpl::Rotation::DEGREES_180,
265
+ justification: Zebra::Zpl::Justification::RIGHT,
266
+ max_lines: 1
267
+ )
268
+ t4 = Zebra::Zpl::Text.new(
269
+ data: "270",
270
+ position: [275, 125],
271
+ font_size: Zebra::Zpl::FontSize::SIZE_5,
272
+ rotation: Zebra::Zpl::Rotation::DEGREES_270,
273
+ justification: Zebra::Zpl::Justification::RIGHT,
274
+ max_lines: 1
275
+ )
276
+ box = Zebra::Zpl::Graphic.new(
277
+ graphic_type: 'B',
278
+ position: [10,5],
279
+ graphic_width: label.width,
280
+ graphic_height: label.length-10,
281
+ line_thickness: 1,
282
+ rounding_degree: 1
283
+ )
284
+ label << t1
285
+ label << t2
286
+ label << t3
287
+ label << t4
288
+ label.elements.each { |e| e.position = [e.x + 150, e.y] }
289
+ label << box
290
+ print_zpl_str('rotation', label)