ruby-zint 1.5.0-x86_64-linux-gnu

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +9 -0
  3. data/LICENSE.txt +21 -0
  4. data/README.md +146 -0
  5. data/ext/ruby-zint/extconf.rb +113 -0
  6. data/lib/3.4/libzint.so +0 -0
  7. data/lib/ruby-zint.rb +1 -0
  8. data/lib/zint/aus_post.rb +8 -0
  9. data/lib/zint/aus_redirect.rb +8 -0
  10. data/lib/zint/aus_reply.rb +8 -0
  11. data/lib/zint/aus_route.rb +8 -0
  12. data/lib/zint/azrune.rb +8 -0
  13. data/lib/zint/aztec.rb +8 -0
  14. data/lib/zint/barcode.rb +550 -0
  15. data/lib/zint/bc_412.rb +8 -0
  16. data/lib/zint/bitmap.rb +4 -0
  17. data/lib/zint/bitmap_pixel.rb +4 -0
  18. data/lib/zint/c25iata.rb +8 -0
  19. data/lib/zint/c25ind.rb +8 -0
  20. data/lib/zint/c25inter.rb +8 -0
  21. data/lib/zint/c25logic.rb +8 -0
  22. data/lib/zint/c25matrix.rb +8 -0
  23. data/lib/zint/c25standard.rb +8 -0
  24. data/lib/zint/cep_net.rb +8 -0
  25. data/lib/zint/channel.rb +8 -0
  26. data/lib/zint/codabar.rb +8 -0
  27. data/lib/zint/codablock_f.rb +8 -0
  28. data/lib/zint/code11.rb +8 -0
  29. data/lib/zint/code128.rb +8 -0
  30. data/lib/zint/code128ab.rb +8 -0
  31. data/lib/zint/code128b.rb +5 -0
  32. data/lib/zint/code16k.rb +8 -0
  33. data/lib/zint/code32.rb +8 -0
  34. data/lib/zint/code39.rb +8 -0
  35. data/lib/zint/code49.rb +8 -0
  36. data/lib/zint/code93.rb +8 -0
  37. data/lib/zint/code_one.rb +8 -0
  38. data/lib/zint/constants/capability_flags.rb +21 -0
  39. data/lib/zint/constants/debug_flags.rb +9 -0
  40. data/lib/zint/constants/errors.rb +20 -0
  41. data/lib/zint/constants/input_data_types.rb +16 -0
  42. data/lib/zint/constants/output_options.rb +24 -0
  43. data/lib/zint/constants/specific_options.rb +13 -0
  44. data/lib/zint/constants/symbologies.rb +138 -0
  45. data/lib/zint/constants/warn_levels.rb +9 -0
  46. data/lib/zint/constants/warnings.rb +12 -0
  47. data/lib/zint/daft.rb +8 -0
  48. data/lib/zint/data_matrix.rb +19 -0
  49. data/lib/zint/dbarexp.rb +8 -0
  50. data/lib/zint/dbarexpstk.rb +8 -0
  51. data/lib/zint/dbarltd.rb +8 -0
  52. data/lib/zint/dbaromn.rb +8 -0
  53. data/lib/zint/dbaromnstk.rb +8 -0
  54. data/lib/zint/dbarstk.rb +8 -0
  55. data/lib/zint/dependencies.rb +15 -0
  56. data/lib/zint/dot_code.rb +8 -0
  57. data/lib/zint/dpd.rb +8 -0
  58. data/lib/zint/dpident.rb +8 -0
  59. data/lib/zint/dpleit.rb +8 -0
  60. data/lib/zint/dxfilmedge.rb +8 -0
  61. data/lib/zint/ean128.rb +8 -0
  62. data/lib/zint/ean14.rb +8 -0
  63. data/lib/zint/eanx.rb +8 -0
  64. data/lib/zint/eanxchk.rb +8 -0
  65. data/lib/zint/excode39.rb +8 -0
  66. data/lib/zint/fim.rb +8 -0
  67. data/lib/zint/flat.rb +8 -0
  68. data/lib/zint/grid_matrix.rb +8 -0
  69. data/lib/zint/gs1_128.rb +10 -0
  70. data/lib/zint/hanxin.rb +8 -0
  71. data/lib/zint/hibc128.rb +8 -0
  72. data/lib/zint/hibc39.rb +8 -0
  73. data/lib/zint/hibcaztec.rb +8 -0
  74. data/lib/zint/hibcblockf.rb +8 -0
  75. data/lib/zint/hibcdm.rb +8 -0
  76. data/lib/zint/hibcmicpdf.rb +8 -0
  77. data/lib/zint/hibcpdf.rb +8 -0
  78. data/lib/zint/hibcqr.rb +8 -0
  79. data/lib/zint/isbnx.rb +8 -0
  80. data/lib/zint/itf14.rb +8 -0
  81. data/lib/zint/japan_post.rb +8 -0
  82. data/lib/zint/kix.rb +8 -0
  83. data/lib/zint/korea_post.rb +8 -0
  84. data/lib/zint/logmars.rb +8 -0
  85. data/lib/zint/mailmark.rb +8 -0
  86. data/lib/zint/mailmark_2d.rb +8 -0
  87. data/lib/zint/mailmark_4s.rb +8 -0
  88. data/lib/zint/maxi_code.rb +8 -0
  89. data/lib/zint/micro_pdf417.rb +8 -0
  90. data/lib/zint/micro_qr.rb +8 -0
  91. data/lib/zint/msiplessey.rb +8 -0
  92. data/lib/zint/native.rb +106 -0
  93. data/lib/zint/nve18.rb +8 -0
  94. data/lib/zint/one_code.rb +8 -0
  95. data/lib/zint/pdf417.rb +8 -0
  96. data/lib/zint/pdf417comp.rb +8 -0
  97. data/lib/zint/pdf417trunc.rb +8 -0
  98. data/lib/zint/pharma.rb +8 -0
  99. data/lib/zint/pharmatwo.rb +8 -0
  100. data/lib/zint/planet.rb +8 -0
  101. data/lib/zint/plessey.rb +8 -0
  102. data/lib/zint/postnet.rb +8 -0
  103. data/lib/zint/pzn.rb +8 -0
  104. data/lib/zint/qr.rb +18 -0
  105. data/lib/zint/rmqr.rb +8 -0
  106. data/lib/zint/rss14.rb +8 -0
  107. data/lib/zint/rss14stack.rb +8 -0
  108. data/lib/zint/rss14stackomni.rb +8 -0
  109. data/lib/zint/rssexp.rb +8 -0
  110. data/lib/zint/rssexpstack.rb +8 -0
  111. data/lib/zint/rssltd.rb +8 -0
  112. data/lib/zint/structs/seg.rb +26 -0
  113. data/lib/zint/structs/structapp.rb +25 -0
  114. data/lib/zint/structs/symbol.rb +57 -0
  115. data/lib/zint/structs/vector.rb +54 -0
  116. data/lib/zint/structs/vector_circle.rb +32 -0
  117. data/lib/zint/structs/vector_hexagon.rb +31 -0
  118. data/lib/zint/structs/vector_rect.rb +37 -0
  119. data/lib/zint/structs/vector_string.rb +50 -0
  120. data/lib/zint/telepen.rb +8 -0
  121. data/lib/zint/telepennum.rb +8 -0
  122. data/lib/zint/ultra.rb +8 -0
  123. data/lib/zint/upc_a.rb +8 -0
  124. data/lib/zint/upc_a_chk.rb +8 -0
  125. data/lib/zint/upc_e.rb +8 -0
  126. data/lib/zint/upc_e_chk.rb +8 -0
  127. data/lib/zint/upnqr.rb +8 -0
  128. data/lib/zint/upu_s10.rb +8 -0
  129. data/lib/zint/uspsimail.rb +8 -0
  130. data/lib/zint/version.rb +3 -0
  131. data/lib/zint/vin.rb +8 -0
  132. data/lib/zint/zint_recipe.rb +31 -0
  133. data/lib/zint.rb +170 -0
  134. data/ruby-zint.gemspec +43 -0
  135. metadata +305 -0
@@ -0,0 +1,550 @@
1
+ module Zint
2
+ # Base class to represent the barcode
3
+ #
4
+ # @example Create new barcode
5
+ # barcode = Zint::Barcode.new(value: "Test", symbology: Zint::BARCODE_QRCODE, option_1: 1)
6
+ # barcode.to_file(path: "qr.png")
7
+ class Barcode
8
+ include Native
9
+
10
+ class AlreadyGenerated < Error; end
11
+
12
+ # @return [String, NilClass] Content of the barcode
13
+ attr_accessor :value
14
+ # @return [String, NilClass] Path to input file with content of the barcode
15
+ attr_accessor :input_file
16
+
17
+ # @param value [String, NilClass] Content of the barcode
18
+ # @param input_file [String, NilClass] Path to input file with content of the barcode
19
+ # @param segments [Array<Hash>, NilClass] Array of ECI segments to encode
20
+ # @param symbology [Integer] Type of barcode
21
+ # @param kwargs [Hash] Specific options for zint symbol (height, scale, ...)
22
+ def initialize(value: nil, input_file: nil, segments: nil, symbology: Zint::BARCODE_CODE128, **kwargs)
23
+ raise ArgumentError, "value, input_file or segments must be given!" if value&.empty? && input_file&.empty? && segments.nil?
24
+ raise ArgumentError, "input_file not found!" if input_file && !File.exist?(input_file)
25
+
26
+ @zint_symbol = Native.ZBarcode_Create
27
+ self.symbology = symbology
28
+ kwargs.each do |k, v|
29
+ send(:"#{k}=", v)
30
+ end
31
+
32
+ @value = value
33
+ @input_file = input_file
34
+ encode_segments(segments)
35
+ end
36
+
37
+ # Exports barcode to file
38
+ #
39
+ # @param path [String] Path to export file.
40
+ # Contains the name of the file to output a resulting barcode symbol to.
41
+ # Must end in .png, .gif, .bmp, .emf, .eps, .pcx, .svg, .tif or .txt
42
+ # @param rotate_angle [Integer] Rotate angle in degrees (0, 90, 180, 270)
43
+ def to_file(path:, rotate_angle: 0)
44
+ unless outfile == "out.png"
45
+ raise AlreadyGenerated, "to_file was already executed"
46
+ end
47
+ @zint_symbol[:outfile] = path
48
+
49
+ if input_file
50
+ call_function(:ZBarcode_Encode_File_and_Print, @zint_symbol, input_file, rotate_angle)
51
+ elsif @p_segments
52
+ call_seg_function(:ZBarcode_Encode_Segs_and_Print, rotate_angle)
53
+ else
54
+ call_function(:ZBarcode_Encode_and_Print, @zint_symbol, value, value.bytesize, rotate_angle)
55
+ end
56
+ end
57
+
58
+ # Exports barcode to memory file
59
+ #
60
+ # @param extension [String] Extension exported memory file
61
+ # @param rotate_angle [Integer] Rotate angle in degrees (0, 90, 180, 270)
62
+ # @return [String] Exported memory file
63
+ def to_memory_file(extension: ".png", rotate_angle: 0)
64
+ @zint_symbol[:output_options] = Zint::BARCODE_MEMORY_FILE
65
+
66
+ to_file(path: extension, rotate_angle: rotate_angle)
67
+
68
+ @zint_symbol[:memfile].read_bytes(@zint_symbol[:memfile_size])
69
+ end
70
+
71
+ # Exports barcode to buffer
72
+ #
73
+ # @param rotate_angle [Integer] Rotate angle in degrees (0, 90, 180, 270)
74
+ # @return [String] Exported barcode buffer
75
+ def to_buffer(rotate_angle: 0)
76
+ unless @zint_symbol[:bitmap].null?
77
+ raise AlreadyGenerated, "to_vector was already executed"
78
+ end
79
+ @zint_symbol[:output_options] = Zint::OUT_BUFFER_INTERMEDIATE
80
+
81
+ if input_file
82
+ call_function(:ZBarcode_Encode_File_and_Buffer, @zint_symbol, input_file, rotate_angle)
83
+ elsif @p_segments
84
+ call_seg_function(:ZBarcode_Encode_Segs_and_Buffer, rotate_angle)
85
+ else
86
+ call_function(:ZBarcode_Encode_and_Buffer, @zint_symbol, value, value.bytesize, rotate_angle)
87
+ end
88
+
89
+ @zint_symbol[:bitmap].read_bytes(@zint_symbol[:bitmap_width] * @zint_symbol[:bitmap_height])
90
+ end
91
+
92
+ # Exports barcode to buffer
93
+ #
94
+ # @param rotate_angle [Integer] Rotate angle in degrees (0, 90, 180, 270)
95
+ # @return [Zint::Bitmap] Exported bitmap
96
+ def to_bitmap(rotate_angle: 0)
97
+ zint_bitmap = to_buffer(rotate_angle: rotate_angle)
98
+
99
+ pixels = []
100
+ @zint_symbol[:bitmap_height].times do |row|
101
+ @zint_symbol[:bitmap_width].times do |column|
102
+ pixels << BitmapPixel.new(column, row, zint_bitmap[pixels.size])
103
+ end
104
+ end
105
+
106
+ Bitmap.new(@zint_symbol[:bitmap_width], @zint_symbol[:bitmap_height], pixels)
107
+ end
108
+
109
+ # Exports barcode as Zint vector
110
+ #
111
+ # @param rotate_angle [Integer] Rotate angle in degrees (0, 90, 180, 270)
112
+ # @return [Zint::Structs::Vector] Vector data of barcode
113
+ def to_vector(rotate_angle: 0)
114
+ unless @zint_symbol[:vector].pointer.null?
115
+ raise AlreadyGenerated, "to_vector was already executed"
116
+ end
117
+ if input_file
118
+ call_function(:ZBarcode_Encode_File_and_Buffer_Vector, @zint_symbol, input_file, rotate_angle)
119
+ elsif @p_segments
120
+ call_seg_function(:ZBarcode_Encode_Segs_and_Buffer_Vector, rotate_angle)
121
+ else
122
+ call_function(:ZBarcode_Encode_and_Buffer_Vector, @zint_symbol, value, value.bytesize, rotate_angle)
123
+ end
124
+
125
+ v = @zint_symbol[:vector]
126
+ # Avoid garbage collection of Symbol before Vector, since the Vector is also freed by ZBarcode_Delete()
127
+ v.instance_variable_set(:@symbol, @zint_symbol)
128
+ v
129
+ end
130
+
131
+ # Encodes the symbology without exporting to a bitmap or vector data
132
+ #
133
+ # This method fills the output accessors of the {Barcode} object.
134
+ #
135
+ # @return self
136
+ def encode
137
+ if input_file
138
+ call_function(:ZBarcode_Encode_File, @zint_symbol, input_file)
139
+ elsif @p_segments
140
+ call_seg_function(:ZBarcode_Encode_Segs)
141
+ else
142
+ call_function(:ZBarcode_Encode, @zint_symbol, value, value.bytesize)
143
+ end
144
+ self
145
+ end
146
+
147
+ # Free barcode and all memory associated with it.
148
+ #
149
+ # Note: This method is dangerous insofar, that previously exported vectors (by #to_vector ) are no longer usable and any access to them will result in a segfault.
150
+ # It is better to not call this method and leave cleaning up to the garbage collector.
151
+ def free
152
+ @zint_symbol.pointer.free
153
+ end
154
+
155
+ # Attributes
156
+
157
+ # Gets type of barcode
158
+ def symbology
159
+ @zint_symbol[:symbology]
160
+ end
161
+
162
+ # Sets symbol to use (see BARCODE_XXX below)
163
+ #
164
+ # @param type [Integer] Type of barcode
165
+ def symbology=(type)
166
+ @zint_symbol[:symbology] = type
167
+ end
168
+
169
+ # Gets height of barcode
170
+ def height
171
+ @zint_symbol[:height]
172
+ end
173
+
174
+ # Sets height in X-dimensions (ignored for fixed-width barcodes)
175
+ #
176
+ # @param height [Float] Height of barcode
177
+ def height=(height)
178
+ @zint_symbol[:height] = height
179
+ end
180
+
181
+ # Gets scale factor of barcode
182
+ def scale
183
+ @zint_symbol[:scale]
184
+ end
185
+
186
+ # Sets scale factor when printing barcode
187
+ #
188
+ # @param scale [Float] Scale of barcode
189
+ def scale=(scale)
190
+ @zint_symbol[:scale] = scale
191
+ end
192
+
193
+ # Gets width in X-dimensions of whitespace to left & right of barcode
194
+ def whitespace_width
195
+ @zint_symbol[:whitespace_width]
196
+ end
197
+
198
+ # Sets width in X-dimensions of whitespace to left & right of barcode
199
+ #
200
+ # @param whitespace_width [Integer] Whitespace width of barcode
201
+ def whitespace_width=(whitespace_width)
202
+ @zint_symbol[:whitespace_width] = whitespace_width
203
+ end
204
+
205
+ # Gets height in X-dimensions of whitespace above & below the barcode
206
+ def whitespace_height
207
+ @zint_symbol[:whitespace_height]
208
+ end
209
+
210
+ # Sets height in X-dimensions of whitespace above & below the barcode
211
+ #
212
+ # @param whitespace_height [Integer] Whitespace height of barcode
213
+ def whitespace_height=(whitespace_height)
214
+ @zint_symbol[:whitespace_height] = whitespace_height
215
+ end
216
+
217
+ # Gets size of border in X-dimensions
218
+ def border_width
219
+ @zint_symbol[:border_width]
220
+ end
221
+
222
+ # Sets size of border in X-dimensions
223
+ #
224
+ # @param border_width [Integer] Border width of barcode
225
+ def border_width=(border_width)
226
+ @zint_symbol[:border_width] = border_width
227
+ end
228
+
229
+ # Gets output options of barcode
230
+ def output_options
231
+ @zint_symbol[:output_options]
232
+ end
233
+
234
+ # Set various output parameters (bind, box etc, see below) of barcode
235
+ #
236
+ # @param output_options [Integer] Output options of barcode
237
+ def output_options=(output_options)
238
+ @zint_symbol[:output_options] = output_options
239
+ end
240
+
241
+ # Gets foreground colour of barcode
242
+ def fgcolour
243
+ @zint_symbol[:fgcolour].to_s
244
+ end
245
+
246
+ # Sets foreground as RGB/RGBA hexadecimal string, 6 or 8 characters, NUL-terminated
247
+ #
248
+ # @param fgcolour [String] Foreground colour of barcode
249
+ def fgcolour=(fgcolour)
250
+ @zint_symbol[:fgcolour] = fgcolour
251
+ end
252
+
253
+ # Gets background colour of barcode
254
+ def bgcolour
255
+ @zint_symbol[:bgcolour].to_s
256
+ end
257
+
258
+ # Sets background as RGB/RGBA hexadecimal string, 6 or 8 characters, NUL-terminated
259
+ #
260
+ # @param bgcolour [String] Background color of barcode
261
+ def bgcolour=(bgcolour)
262
+ @zint_symbol[:bgcolour] = bgcolour
263
+ end
264
+
265
+ # Contains the name of the file to output a resulting barcode symbol to.
266
+ #
267
+ # Must end in .png, .gif, .bmp, .emf, .eps, .pcx, .svg, .tif or .txt
268
+ def outfile
269
+ @zint_symbol[:outfile].to_s
270
+ end
271
+
272
+ # Gets option 1 of barcode
273
+ def option_1
274
+ @zint_symbol[:option_1]
275
+ end
276
+
277
+ # Sets option 1 (symbol-specific options (see "../docs/manual.txt"))
278
+ #
279
+ # @param option_1 [Integer] Option 1 of barcode
280
+ def option_1=(option_1)
281
+ @zint_symbol[:option_1] = option_1
282
+ end
283
+
284
+ # Gets option 2 of barcode
285
+ def option_2
286
+ @zint_symbol[:option_2]
287
+ end
288
+
289
+ # Sets option 2 (symbol-specific options) of barcode
290
+ #
291
+ # @param option_2 [Integer] Option 2 of barcode
292
+ def option_2=(option_2)
293
+ @zint_symbol[:option_2] = option_2
294
+ end
295
+
296
+ # Gets option 3 of barcode
297
+ def option_3
298
+ @zint_symbol[:option_3]
299
+ end
300
+
301
+ # Sets option 3 (symbol-specific options) of barcode
302
+ #
303
+ # @param option_3 [Integer] Option 3 of barcode
304
+ def option_3=(option_3)
305
+ @zint_symbol[:option_3] = option_3
306
+ end
307
+
308
+ # Gets show_hrt of barcode
309
+ def show_hrt
310
+ @zint_symbol[:show_hrt]
311
+ end
312
+
313
+ # Sets show_hrt of barcode
314
+ # show = 1 or hide = 0 Human Readable Text. Default is show (1)
315
+ #
316
+ # @param show_hrt [Integer] show_hrt of barcode
317
+ def show_hrt=(show_hrt)
318
+ @zint_symbol[:show_hrt] = show_hrt
319
+ end
320
+
321
+ # Gets input mode of barcode
322
+ def input_mode
323
+ @zint_symbol[:input_mode]
324
+ end
325
+
326
+ # Sets encoding of input data (see DATA_MODE etc below). Default DATA_MODE
327
+ #
328
+ # @param input_mode [Integer] Input mode of barcode
329
+ def input_mode=(input_mode)
330
+ @zint_symbol[:input_mode] = input_mode
331
+ end
332
+
333
+ # Gets ECI of barcode
334
+ def eci
335
+ @zint_symbol[:eci]
336
+ end
337
+
338
+ # Sets extended Channel Interpretation. Default 0 (none)
339
+ #
340
+ # @param eci [Integer] ECI of barcode
341
+ def eci=(eci)
342
+ @zint_symbol[:eci] = eci
343
+ end
344
+
345
+ # Gets resolution of output in dots per mm (BMP/EMF/PCX/PNG/TIF only). Default 0 (none)
346
+ def dpmm
347
+ @zint_symbol[:dpmm]
348
+ end
349
+
350
+ # Sets resolution of output in dots per mm (BMP/EMF/PCX/PNG/TIF only). Default 0 (none)
351
+ #
352
+ # @param dpmm [Float] Resolution of output in dots per mm
353
+ def dpmm=(dpmm)
354
+ @zint_symbol[:dpmm] = dpmm
355
+ end
356
+
357
+ # Gets height in X-dimensions that EAN/UPC guard bars descend. Default 5
358
+ def guard_descent
359
+ @zint_symbol[:guard_descent]
360
+ end
361
+
362
+ # Sets height in X-dimensions that EAN/UPC guard bars descend. Default 5
363
+ #
364
+ # @param guard_descent [Float] Height in X-dimensions that EAN/UPC guard bars descend
365
+ def guard_descent=(guard_descent)
366
+ @zint_symbol[:guard_descent] = guard_descent
367
+ end
368
+
369
+ # Gets structured append info. Default structapp.count 0 (none)
370
+ def structapp
371
+ @zint_symbol[:structapp]
372
+ end
373
+
374
+ # Sets structured append info. Default structapp.count 0 (none)
375
+ #
376
+ # @param structapp [Structs::Structapp] Structured append info
377
+ def structapp=(structapp)
378
+ @zint_symbol[:structapp] = structapp
379
+ end
380
+
381
+ # Human Readable Text, which usually consists of input data plus one more check digit. Uses UTF-8 formatting.
382
+ def text
383
+ @zint_symbol[:text].to_ptr.read_bytes(@zint_symbol[:text_length]).force_encoding(Encoding::UTF_8)
384
+ end
385
+
386
+ # Gets rows of barcode
387
+ def rows
388
+ @zint_symbol[:rows]
389
+ end
390
+
391
+ # Gets width of barcode
392
+ def width
393
+ @zint_symbol[:width]
394
+ end
395
+
396
+ # Gets primary message data for more complex symbols
397
+ def primary
398
+ @zint_symbol[:primary].to_s
399
+ end
400
+
401
+ # Sets primary message data (MaxiCode, Composite), NUL-terminated of barcode
402
+ #
403
+ # @param primary [String] Primary of barcode
404
+ def primary=(primary)
405
+ @zint_symbol[:primary] = primary
406
+ end
407
+
408
+ # Gets encoded data of barcode as internal FFI::StructLayout::CharArray object
409
+ #
410
+ # Don't use this method, it might be changed in future releases.
411
+ def encoded_data_raw_ffi
412
+ @zint_symbol[:encoded_data]
413
+ end
414
+
415
+ # Return the raw encoded data as array of strings.
416
+ #
417
+ # Each row of the symbology is represented by one item of the array.
418
+ # The columns are represented by "0" and "1" characters of the stings.
419
+ #
420
+ # @example
421
+ # Zint::DataMatrix.new(value: "12345").encode.encoded_data_as_array_of_strings
422
+ # # => ["1010101010",
423
+ # # "1101100111",
424
+ # # "1100010110",
425
+ # # "1100110101",
426
+ # # "1100111000",
427
+ # # "1000011111",
428
+ # # "1101011110",
429
+ # # "1110000111",
430
+ # # "1101100100",
431
+ # # "1111111111"]
432
+ #
433
+ # @return [Array<String>] encoded data
434
+ def encoded_data_as_array_of_strings
435
+ rows.times.map do |row|
436
+ binstr = @zint_symbol[:encoded_data].to_ptr.get_bytes(144 * row, (width + 7) / 8)
437
+ binstr.unpack1("b*")[0, width]
438
+ end
439
+ end
440
+
441
+ # Gets row heights of barcode as internal FFI::Struct::InlineArray object
442
+ #
443
+ # Don't use this method, it might be changed in future releases.
444
+ def row_height_raw_ffi
445
+ @zint_symbol[:row_height]
446
+ end
447
+
448
+ # Gets heights of all barcode rows
449
+ #
450
+ # @example
451
+ # Zint::Kix.new(value: "130203").encode.row_heights
452
+ # # => [3.0, 2.0, 3.0]
453
+ #
454
+ # @return [Array<Float>] row heights
455
+ def row_heights
456
+ @zint_symbol[:row_height].to_a[0, rows]
457
+ end
458
+
459
+ # Gets error message in the event that an error occurred
460
+ def errtxt
461
+ @zint_symbol[:errtxt].to_s.force_encoding(Encoding::UTF_8)
462
+ end
463
+
464
+ # Gets bitmap width of barcode
465
+ def bitmap_width
466
+ @zint_symbol[:bitmap_width]
467
+ end
468
+
469
+ # Gets bitmap height of barcode
470
+ def bitmap_height
471
+ @zint_symbol[:bitmap_height]
472
+ end
473
+
474
+ # Gets dot size of barcode
475
+ def dot_size
476
+ @zint_symbol[:dot_size]
477
+ end
478
+
479
+ # Sets size of dots used in BARCODE_DOTTY_MODE
480
+ #
481
+ # @param dot_size [Float] Dot size of barcode
482
+ def dot_size=(dot_size)
483
+ @zint_symbol[:dot_size] = dot_size
484
+ end
485
+
486
+ # Gets debugging flags
487
+ def debug
488
+ @zint_symbol[:debug]
489
+ end
490
+
491
+ # Sets debugging flags
492
+ #
493
+ # @param debug [Integer] Debug level of barcode
494
+ def debug=(debug)
495
+ @zint_symbol[:debug] = debug
496
+ end
497
+
498
+ # Gets warn level of barcode
499
+ def warn_level
500
+ @zint_symbol[:warn_level]
501
+ end
502
+
503
+ # Sets warn level (affects error/warning value returned by Zint API (see WARN_XXX below)) of barcode
504
+ #
505
+ # @param warn_level [Integer] Warn level of barcode
506
+ def warn_level=(warn_level)
507
+ @zint_symbol[:warn_level] = warn_level
508
+ end
509
+
510
+ private
511
+
512
+ def reset_symbol
513
+ call_function(:ZBarcode_Clear, @zint_symbol)
514
+ end
515
+
516
+ def call_function(function_name, *args)
517
+ error_code = Native.send(function_name.to_sym, *args)
518
+
519
+ if Zint::ERRORS[error_code]
520
+ Native.raise_error(error_code, @zint_symbol[:errtxt])
521
+ end
522
+
523
+ error_code
524
+ end
525
+
526
+ def call_seg_function(function_name, *args)
527
+ call_function(function_name, @zint_symbol, @p_segments, @p_strings.size, *args)
528
+ end
529
+
530
+ def encode_segments(segments)
531
+ @p_segments = nil
532
+ return unless segments
533
+
534
+ raise ArgumentError, "segments must be Array<Hash<source: String, eci: Integer>>!" if !segments.is_a?(Array) || !segments.first.is_a?(Hash)
535
+
536
+ @p_segments = FFI::MemoryPointer.new Structs::Seg, segments.size
537
+ @p_strings = [] # Prevent garbage collection
538
+ segments.each_with_index do |seg, sidx|
539
+ p_seg = Structs::Seg.new(@p_segments + Structs::Seg.size * sidx)
540
+ source = seg[:source] || raise(ArgumentError, ":source not defined")
541
+ eci = seg[:eci] || raise(ArgumentError, ":eci not defined")
542
+
543
+ @p_strings << FFI::MemoryPointer.from_string(source)
544
+ p_seg[:source] = @p_strings.last
545
+ p_seg[:length] = source.bytesize
546
+ p_seg[:eci] = eci
547
+ end
548
+ end
549
+ end
550
+ end
@@ -0,0 +1,8 @@
1
+ module Zint
2
+ # IBM BC412 (SEMI T1-95)
3
+ class Bc412 < Barcode
4
+ def initialize(value: nil, input_file: nil, **kwargs)
5
+ super(value: value, input_file: input_file, symbology: Zint::BARCODE_BC412, **kwargs)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ module Zint
2
+ # A class to represents a pixel from the bitmap
3
+ Bitmap = Struct.new(:width, :height, :pixels)
4
+ end
@@ -0,0 +1,4 @@
1
+ module Zint
2
+ # A class to represents a pixel from the bitmap
3
+ BitmapPixel = Struct.new(:x, :y, :colour)
4
+ end
@@ -0,0 +1,8 @@
1
+ module Zint
2
+ # 2 of 5 IATA
3
+ class C25iata < Barcode
4
+ def initialize(value: nil, input_file: nil, **kwargs)
5
+ super(value: value, input_file: input_file, symbology: Zint::BARCODE_C25IATA, **kwargs)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Zint
2
+ # 2 of 5 Industrial
3
+ class C25ind < Barcode
4
+ def initialize(value: nil, input_file: nil, **kwargs)
5
+ super(value: value, input_file: input_file, symbology: Zint::BARCODE_C25IND, **kwargs)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Zint
2
+ # 2 of 5 Interleaved
3
+ class C25inter < Barcode
4
+ def initialize(value: nil, input_file: nil, **kwargs)
5
+ super(value: value, input_file: input_file, symbology: Zint::BARCODE_C25INTER, **kwargs)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Zint
2
+ # 2 of 5 Data Logic
3
+ class C25logic < Barcode
4
+ def initialize(value: nil, input_file: nil, **kwargs)
5
+ super(value: value, input_file: input_file, symbology: Zint::BARCODE_C25LOGIC, **kwargs)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Zint
2
+ # Legacy
3
+ class C25matrix < Barcode
4
+ def initialize(value: nil, input_file: nil, **kwargs)
5
+ super(value: value, input_file: input_file, symbology: Zint::BARCODE_C25MATRIX, **kwargs)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Zint
2
+ # 2 of 5 Standard (Matrix)
3
+ class C25standard < Barcode
4
+ def initialize(value: nil, input_file: nil, **kwargs)
5
+ super(value: value, input_file: input_file, symbology: Zint::BARCODE_C25STANDARD, **kwargs)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Zint
2
+ # Brazilian CEPNet Postal Code
3
+ class CepNet < Barcode
4
+ def initialize(value: nil, input_file: nil, **kwargs)
5
+ super(value: value, input_file: input_file, symbology: Zint::BARCODE_CEPNET, **kwargs)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Zint
2
+ # Channel Code
3
+ class Channel < Barcode
4
+ def initialize(value: nil, input_file: nil, **kwargs)
5
+ super(value: value, input_file: input_file, symbology: Zint::BARCODE_CHANNEL, **kwargs)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Zint
2
+ # Codabar
3
+ class Codabar < Barcode
4
+ def initialize(value: nil, input_file: nil, **kwargs)
5
+ super(value: value, input_file: input_file, symbology: Zint::BARCODE_CODABAR, **kwargs)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Zint
2
+ # Codablock-F
3
+ class CodablockF < Barcode
4
+ def initialize(value: nil, input_file: nil, **kwargs)
5
+ super(value: value, input_file: input_file, symbology: Zint::BARCODE_CODABLOCKF, **kwargs)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Zint
2
+ # Code 11
3
+ class Code11 < Barcode
4
+ def initialize(value: nil, input_file: nil, **kwargs)
5
+ super(value: value, input_file: input_file, symbology: Zint::BARCODE_CODE11, **kwargs)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Zint
2
+ # Code 128
3
+ class Code128 < Barcode
4
+ def initialize(value: nil, input_file: nil, **kwargs)
5
+ super(value: value, input_file: input_file, symbology: Zint::BARCODE_CODE128, **kwargs)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Zint
2
+ # Code 128 (Suppress Code Set C)
3
+ class Code128AB < Barcode
4
+ def initialize(value: nil, input_file: nil, **kwargs)
5
+ super(value: value, input_file: input_file, symbology: Zint::BARCODE_CODE128AB, **kwargs)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Zint
2
+ # Legacy
3
+ class Code128B < Code128AB
4
+ end
5
+ end