ruby-zint 1.3.0 → 1.4.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 486ea5eb1e9c5382337612a19ce2101cbbcba980dc30b9d1ff702f2dbc4beba9
4
- data.tar.gz: 0be779d097b3e9f99d7c79d4f8da8895c2e8931ea6be84165f77d40bc9f0a5a8
3
+ metadata.gz: 64af83d59b1d29bdae5808430c36817e3517bee6cd7bbd34147cb377cccc02b2
4
+ data.tar.gz: 17a44a73c35894b6b7f7f8b884e18fa622400746cf9331c19e68b43994a2f958
5
5
  SHA512:
6
- metadata.gz: a33d8244d461e0dac91b66f086aa153d26ed188ae418fa3b1ba1d03139e424d678b2ef92a988f8db7c23d6e46627912e2f04a753c66e77b7c5b1b51e9383f3e5
7
- data.tar.gz: c97890ca409f5393478f14b4630147229c8e4f282b640a51ff781d98fc8f4c31f42eaed3167d9e16d6b2dc021884af14fd92a75234f573bcbb46562db62d326d
6
+ metadata.gz: 580e3329db01adf7bae175780221cc3dbdbb45f4578e439e6c1cb6425e28ca7b0118f11576cb463d8588da6298ccf963f7edf481cba15b6b37d2d902bb1280b7
7
+ data.tar.gz: ce7b11a96fd7ce11a16ecd97b4b479beb2a2ca09eb67da67409096b0b0a6b1eedd77eb1059b3cd9894ec426b36df9f6ef5bd52720eb39b75b2db7e47276eaa33
data/Gemfile CHANGED
@@ -16,3 +16,5 @@ gem "byebug"
16
16
  gem "standard", "~> 1.3"
17
17
 
18
18
  gem "mini_portile2"
19
+
20
+ gem "yard"
data/README.md CHANGED
@@ -44,6 +44,10 @@ Optionally set the install option by running bundler like so:
44
44
  bundle config build.ruby-zint --enable-system-libzint
45
45
  ```
46
46
 
47
+ ### PNG support
48
+
49
+ Please install libpng (e. g. `apt install libpng-dev`) before installing the gem if you want to use the PNG format.
50
+
47
51
  ## Usage
48
52
 
49
53
  ```ruby
data/Rakefile CHANGED
@@ -3,9 +3,12 @@ require "rspec/core/rake_task"
3
3
  require_relative "lib/zint/zint_recipe"
4
4
 
5
5
  CLOBBER.include "pkg"
6
- CLEAN.include "ports"
6
+ CLOBBER.add("ports/*").exclude(%r{ports/archives$})
7
7
  CLEAN.include "tmp"
8
8
  CLEAN.include "ext/ruby-zint/tmp"
9
+ CLEAN.include "lib/*.a"
10
+ CLEAN.include "lib/*.so*"
11
+ CLEAN.include "lib/*.dll*"
9
12
 
10
13
  RSpec::Core::RakeTask.new(:spec)
11
14
 
data/lib/zint/barcode.rb CHANGED
@@ -25,7 +25,7 @@ module Zint
25
25
  @zint_symbol = Native.ZBarcode_Create
26
26
  self.symbology = symbology
27
27
  kwargs.each do |k, v|
28
- send("#{k}=", v)
28
+ send(:"#{k}=", v)
29
29
  end
30
30
 
31
31
  @value = value
@@ -39,7 +39,7 @@ module Zint
39
39
  # Must end in .png, .gif, .bmp, .emf, .eps, .pcx, .svg, .tif or .txt
40
40
  # @param rotate_angle [Integer] Rotate angle in degrees (0, 90, 180, 270)
41
41
  def to_file(path:, rotate_angle: 0)
42
- unless outfile == 'out.png'
42
+ unless outfile == "out.png"
43
43
  raise AlreadyGenerated, "to_file was already executed"
44
44
  end
45
45
  @zint_symbol[:outfile] = path
@@ -47,7 +47,7 @@ module Zint
47
47
  if input_file
48
48
  call_function(:ZBarcode_Encode_File_and_Print, @zint_symbol, input_file, rotate_angle)
49
49
  else
50
- call_function(:ZBarcode_Encode_and_Print, @zint_symbol, value, 0, rotate_angle)
50
+ call_function(:ZBarcode_Encode_and_Print, @zint_symbol, value, value.bytesize, rotate_angle)
51
51
  end
52
52
  end
53
53
 
@@ -83,10 +83,10 @@ module Zint
83
83
  if input_file
84
84
  call_function(:ZBarcode_Encode_File_and_Buffer, @zint_symbol, input_file, rotate_angle)
85
85
  else
86
- call_function(:ZBarcode_Encode_and_Buffer, @zint_symbol, value, 0, rotate_angle)
86
+ call_function(:ZBarcode_Encode_and_Buffer, @zint_symbol, value, value.bytesize, rotate_angle)
87
87
  end
88
88
 
89
- @zint_symbol[:bitmap].read_bytes((@zint_symbol[:bitmap_width] * @zint_symbol[:bitmap_height]))
89
+ @zint_symbol[:bitmap].read_bytes(@zint_symbol[:bitmap_width] * @zint_symbol[:bitmap_height])
90
90
  end
91
91
 
92
92
  # Exports barcode to buffer
@@ -117,7 +117,7 @@ module Zint
117
117
  if input_file
118
118
  call_function(:ZBarcode_Encode_File_and_Buffer_Vector, @zint_symbol, input_file, rotate_angle)
119
119
  else
120
- call_function(:ZBarcode_Encode_and_Buffer_Vector, @zint_symbol, value, 0, rotate_angle)
120
+ call_function(:ZBarcode_Encode_and_Buffer_Vector, @zint_symbol, value, value.bytesize, rotate_angle)
121
121
  end
122
122
 
123
123
  v = @zint_symbol[:vector]
@@ -126,6 +126,20 @@ module Zint
126
126
  v
127
127
  end
128
128
 
129
+ # Encodes the symbology without exporting to a bitmap or vector data
130
+ #
131
+ # This method fills the output accessors of the {Barcode} object.
132
+ #
133
+ # @return self
134
+ def encode
135
+ if input_file
136
+ call_function(:ZBarcode_Encode_File, @zint_symbol, input_file)
137
+ else
138
+ call_function(:ZBarcode_Encode, @zint_symbol, value, value.bytesize)
139
+ end
140
+ self
141
+ end
142
+
129
143
  # Free barcode and all memory associated with it.
130
144
  #
131
145
  # 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.
@@ -377,13 +391,6 @@ module Zint
377
391
  @zint_symbol[:text].to_s.force_encoding(Encoding::UTF_8)
378
392
  end
379
393
 
380
- # Sets Human Readable Text (if any), UTF-8, NUL-terminated (output only) of barcode
381
- #
382
- # @param text [String] Text of barcode
383
- def text=(text)
384
- @zint_symbol[:text] = text
385
- end
386
-
387
394
  # Gets rows of barcode
388
395
  def rows
389
396
  @zint_symbol[:rows]
@@ -406,23 +413,57 @@ module Zint
406
413
  @zint_symbol[:primary] = primary
407
414
  end
408
415
 
409
- # Gets encoded data of barcode
410
- def encoded_data
416
+ # Gets encoded data of barcode as internal FFI::StructLayout::CharArray object
417
+ #
418
+ # Don't use this method, it might be changed in future releases.
419
+ def encoded_data_raw_ffi
411
420
  @zint_symbol[:encoded_data]
412
421
  end
413
422
 
414
- # Sets encoded data (output only). Allows for rows of 1144 modules of barcode
415
- #
416
- # @param encoded_data [String] Encoded data of barcode
417
- def encoded_data=(encoded_data)
418
- @zint_symbol[:encoded_data] = encoded_data
423
+ # Return the raw encoded data as array of strings.
424
+ #
425
+ # Each row of the symbology is represented by one item of the array.
426
+ # The columns are represented by "0" and "1" characters of the stings.
427
+ #
428
+ # @example
429
+ # Zint::DataMatrix.new(value: "12345").encode.encoded_data_as_array_of_strings
430
+ # # => ["1010101010",
431
+ # # "1101100111",
432
+ # # "1100010110",
433
+ # # "1100110101",
434
+ # # "1100111000",
435
+ # # "1000011111",
436
+ # # "1101011110",
437
+ # # "1110000111",
438
+ # # "1101100100",
439
+ # # "1111111111"]
440
+ #
441
+ # @return [Array<String>] encoded data
442
+ def encoded_data_as_array_of_strings
443
+ rows.times.map do |row|
444
+ binstr = @zint_symbol[:encoded_data].to_ptr.get_bytes(144 * row, (width + 7) / 8)
445
+ binstr.unpack1("b*")[0, width]
446
+ end
419
447
  end
420
448
 
421
- # Gets row height of barcode
422
- def row_height
449
+ # Gets row heights of barcode as internal FFI::Struct::InlineArray object
450
+ #
451
+ # Don't use this method, it might be changed in future releases.
452
+ def row_height_raw_ffi
423
453
  @zint_symbol[:row_height]
424
454
  end
425
455
 
456
+ # Gets heights of all barcode rows
457
+ #
458
+ # @example
459
+ # Zint::Kix.new(value: "130203").encode.row_heights
460
+ # # => [3.0, 2.0, 3.0]
461
+ #
462
+ # @return [Array<Float>] row heights
463
+ def row_heights
464
+ @zint_symbol[:row_height].to_a[0, rows]
465
+ end
466
+
426
467
  # Gets error message in the event that an error occurred
427
468
  def errtxt
428
469
  @zint_symbol[:errtxt].to_s.force_encoding(Encoding::UTF_8)
data/lib/zint/native.rb CHANGED
@@ -17,60 +17,60 @@ module Zint
17
17
  typedef :int32, :rotate_angle
18
18
  typedef :int32, :symbol_id
19
19
  typedef :uint32, :cap_flag
20
- typedef :string, :source
20
+ typedef :pointer, :source
21
21
 
22
22
  # Create and initialize a symbol structure
23
- attach_function(:ZBarcode_Create, [], :zint_symbol)
23
+ attach_function(:ZBarcode_Create, [], :zint_symbol, blocking: true)
24
24
 
25
25
  # Free any output buffers that may have been created and initialize output fields
26
- attach_function(:ZBarcode_Clear, [:zint_symbol], :void)
26
+ attach_function(:ZBarcode_Clear, [:zint_symbol], :void, blocking: true)
27
27
 
28
28
  # Free a symbol structure, including any output buffers
29
29
  #
30
30
  # For use with ruby's garbage collector ZBarcode_Delete must be called with a plain :pointer and not an :zint_symbol.
31
- attach_function(:ZBarcode_Delete, [:pointer], :void)
31
+ attach_function(:ZBarcode_Delete, [:pointer], :void, blocking: true)
32
32
 
33
33
  # Encode a barcode. If `length` is 0, `source` must be NUL-terminated.
34
- attach_function(:ZBarcode_Encode, [:zint_symbol, :source, :length], :error_code)
34
+ attach_function(:ZBarcode_Encode, [:zint_symbol, :source, :length], :error_code, blocking: true)
35
35
 
36
36
  # Encode a barcode using input data from file `filename`
37
- attach_function(:ZBarcode_Encode_File, [:zint_symbol, :filename], :error_code)
37
+ attach_function(:ZBarcode_Encode_File, [:zint_symbol, :filename], :error_code, blocking: true)
38
38
 
39
39
  # Output a previously encoded symbol to file `symbol->outfile`
40
- attach_function(:ZBarcode_Print, [:zint_symbol, :rotate_angle], :error_code)
40
+ attach_function(:ZBarcode_Print, [:zint_symbol, :rotate_angle], :error_code, blocking: true)
41
41
 
42
42
  # Encode and output a symbol to file `symbol->outfile`
43
- attach_function(:ZBarcode_Encode_and_Print, [:zint_symbol, :source, :length, :rotate_angle], :error_code)
43
+ attach_function(:ZBarcode_Encode_and_Print, [:zint_symbol, :source, :length, :rotate_angle], :error_code, blocking: true)
44
44
 
45
45
  # Encode a symbol using input data from file `filename` and output to file `symbol->outfile`
46
- attach_function(:ZBarcode_Encode_File_and_Print, [:zint_symbol, :filename, :rotate_angle], :error_code)
46
+ attach_function(:ZBarcode_Encode_File_and_Print, [:zint_symbol, :filename, :rotate_angle], :error_code, blocking: true)
47
47
 
48
48
  # Output a previously encoded symbol to memory as raster (`symbol->bitmap`)
49
- attach_function(:ZBarcode_Buffer, [:zint_symbol, :rotate_angle], :error_code)
49
+ attach_function(:ZBarcode_Buffer, [:zint_symbol, :rotate_angle], :error_code, blocking: true)
50
50
 
51
51
  # Encode and output a symbol to memory as raster (`symbol->bitmap`)
52
- attach_function(:ZBarcode_Encode_and_Buffer, [:zint_symbol, :source, :length, :rotate_angle], :error_code)
52
+ attach_function(:ZBarcode_Encode_and_Buffer, [:zint_symbol, :source, :length, :rotate_angle], :error_code, blocking: true)
53
53
 
54
54
  # Encode a symbol using input data from file `filename` and output to memory as raster (`symbol->bitmap`)
55
- attach_function(:ZBarcode_Encode_File_and_Buffer, [:zint_symbol, :filename, :rotate_angle], :error_code)
55
+ attach_function(:ZBarcode_Encode_File_and_Buffer, [:zint_symbol, :filename, :rotate_angle], :error_code, blocking: true)
56
56
 
57
57
  # Output a previously encoded symbol to memory as vector (`symbol->vector`)
58
- attach_function(:ZBarcode_Buffer_Vector, [:zint_symbol, :rotate_angle], :error_code)
58
+ attach_function(:ZBarcode_Buffer_Vector, [:zint_symbol, :rotate_angle], :error_code, blocking: true)
59
59
 
60
60
  # Encode and output a symbol to memory as vector (`symbol->vector`)
61
- attach_function(:ZBarcode_Encode_and_Buffer_Vector, [:zint_symbol, :source, :length, :rotate_angle], :error_code)
61
+ attach_function(:ZBarcode_Encode_and_Buffer_Vector, [:zint_symbol, :source, :length, :rotate_angle], :error_code, blocking: true)
62
62
 
63
63
  # Encode a symbol using input data from file `filename` and output to memory as vector (`symbol->vector`)
64
- attach_function(:ZBarcode_Encode_File_and_Buffer_Vector, [:zint_symbol, :filename, :rotate_angle], :error_code)
64
+ attach_function(:ZBarcode_Encode_File_and_Buffer_Vector, [:zint_symbol, :filename, :rotate_angle], :error_code, blocking: true)
65
65
 
66
66
  # Is `symbol_id` a recognized symbology?
67
- attach_function(:ZBarcode_ValidID, [:symbol_id], :bool)
67
+ attach_function(:ZBarcode_ValidID, [:symbol_id], :bool, blocking: true)
68
68
 
69
69
  # Return the capability flags for symbology `symbol_id` that match `cap_flag`
70
- attach_function(:ZBarcode_Cap, [:symbol_id, :cap_flag], :uint32)
70
+ attach_function(:ZBarcode_Cap, [:symbol_id, :cap_flag], :uint32, blocking: true)
71
71
 
72
72
  # Return the version of Zint linked to
73
- attach_function(:ZBarcode_Version, [], :int32)
73
+ attach_function(:ZBarcode_Version, [], :int32, blocking: true)
74
74
 
75
75
  # Raises specific error for API return code
76
76
  #
@@ -18,22 +18,22 @@ module Zint
18
18
  self[:width]
19
19
  end
20
20
 
21
- # Calls the given block and passes a VectorRect object for each rectangle to be printed.
21
+ # Calls the given block and passes a {VectorRect} object for each rectangle to be printed.
22
22
  def each_rectangle(&block)
23
23
  each_vector(:rectangles, &block)
24
24
  end
25
25
 
26
- # Calls the given block and passes a VectorHexagon object for each hexagon to be printed.
26
+ # Calls the given block and passes a {VectorHexagon} object for each hexagon to be printed.
27
27
  def each_hexagon(&block)
28
28
  each_vector(:hexagons, &block)
29
29
  end
30
30
 
31
- # Calls the given block and passes a VectorString object for each text string to be printed.
31
+ # Calls the given block and passes a {VectorString} object for each text string to be printed.
32
32
  def each_string(&block)
33
33
  each_vector(:strings, &block)
34
34
  end
35
35
 
36
- # Calls the given block and passes a VectorCircle object for each circle to be printed.
36
+ # Calls the given block and passes a {VectorCircle} object for each circle to be printed.
37
37
  def each_circle(&block)
38
38
  each_vector(:circles, &block)
39
39
  end
data/lib/zint/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Zint
2
- VERSION = "1.3.0"
2
+ VERSION = "1.4.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-zint
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elias Fröhner
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2023-05-12 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: ffi
@@ -38,7 +37,6 @@ dependencies:
38
37
  - - "~>"
39
38
  - !ruby/object:Gem::Version
40
39
  version: '2.1'
41
- description:
42
40
  email:
43
41
  - apiwalker96@gmail.com
44
42
  executables: []
@@ -296,7 +294,7 @@ metadata:
296
294
  homepage_uri: https://github.com/api-walker/ruby-zint
297
295
  source_code_uri: https://github.com/api-walker/ruby-zint
298
296
  msys2_mingw_dependencies: cmake libpng
299
- post_install_message:
297
+ documentation_uri: https://rubydoc.info/gems/ruby-zint
300
298
  rdoc_options:
301
299
  - "--main"
302
300
  - README.md
@@ -317,8 +315,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
317
315
  - !ruby/object:Gem::Version
318
316
  version: '0'
319
317
  requirements: []
320
- rubygems_version: 3.4.8
321
- signing_key:
318
+ rubygems_version: 3.7.0
322
319
  specification_version: 4
323
320
  summary: Ruby FFI binding for libzint
324
321
  test_files: []