ruby-zint-es 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.standard.yml +5 -0
- data/.yardopts +9 -0
- data/Gemfile +18 -0
- data/LICENSE.txt +21 -0
- data/README.md +114 -0
- data/Rakefile +20 -0
- data/ext/ruby-zint/extconf.rb +86 -0
- data/lib/ruby-zint.rb +1 -0
- data/lib/zint/aus_post.rb +8 -0
- data/lib/zint/aus_redirect.rb +8 -0
- data/lib/zint/aus_reply.rb +8 -0
- data/lib/zint/aus_route.rb +8 -0
- data/lib/zint/azrune.rb +8 -0
- data/lib/zint/aztec.rb +8 -0
- data/lib/zint/barcode.rb +498 -0
- data/lib/zint/bc_412.rb +8 -0
- data/lib/zint/bitmap.rb +4 -0
- data/lib/zint/bitmap_pixel.rb +4 -0
- data/lib/zint/c25iata.rb +8 -0
- data/lib/zint/c25ind.rb +8 -0
- data/lib/zint/c25inter.rb +8 -0
- data/lib/zint/c25logic.rb +8 -0
- data/lib/zint/c25matrix.rb +8 -0
- data/lib/zint/c25standard.rb +8 -0
- data/lib/zint/cep_net.rb +8 -0
- data/lib/zint/channel.rb +8 -0
- data/lib/zint/codabar.rb +8 -0
- data/lib/zint/codablock_f.rb +8 -0
- data/lib/zint/code11.rb +8 -0
- data/lib/zint/code128.rb +8 -0
- data/lib/zint/code128ab.rb +8 -0
- data/lib/zint/code128b.rb +5 -0
- data/lib/zint/code16k.rb +8 -0
- data/lib/zint/code32.rb +8 -0
- data/lib/zint/code39.rb +8 -0
- data/lib/zint/code49.rb +8 -0
- data/lib/zint/code93.rb +8 -0
- data/lib/zint/code_one.rb +8 -0
- data/lib/zint/constants/capability_flags.rb +21 -0
- data/lib/zint/constants/debug_flags.rb +9 -0
- data/lib/zint/constants/errors.rb +19 -0
- data/lib/zint/constants/input_data_types.rb +15 -0
- data/lib/zint/constants/output_options.rb +21 -0
- data/lib/zint/constants/specific_options.rb +12 -0
- data/lib/zint/constants/symbologies.rb +137 -0
- data/lib/zint/constants/warn_levels.rb +9 -0
- data/lib/zint/constants/warnings.rb +12 -0
- data/lib/zint/daft.rb +8 -0
- data/lib/zint/data_matrix.rb +19 -0
- data/lib/zint/dbarexp.rb +8 -0
- data/lib/zint/dbarexpstk.rb +8 -0
- data/lib/zint/dbarltd.rb +8 -0
- data/lib/zint/dbaromn.rb +8 -0
- data/lib/zint/dbaromnstk.rb +8 -0
- data/lib/zint/dbarstk.rb +8 -0
- data/lib/zint/dependencies.rb +7 -0
- data/lib/zint/dot_code.rb +8 -0
- data/lib/zint/dpd.rb +8 -0
- data/lib/zint/dpident.rb +8 -0
- data/lib/zint/dpleit.rb +8 -0
- data/lib/zint/ean128.rb +8 -0
- data/lib/zint/ean14.rb +8 -0
- data/lib/zint/eanx.rb +8 -0
- data/lib/zint/eanxchk.rb +8 -0
- data/lib/zint/excode39.rb +8 -0
- data/lib/zint/fim.rb +8 -0
- data/lib/zint/flat.rb +8 -0
- data/lib/zint/grid_matrix.rb +8 -0
- data/lib/zint/gs1_128.rb +10 -0
- data/lib/zint/hanxin.rb +8 -0
- data/lib/zint/hibc128.rb +8 -0
- data/lib/zint/hibc39.rb +8 -0
- data/lib/zint/hibcaztec.rb +8 -0
- data/lib/zint/hibcblockf.rb +8 -0
- data/lib/zint/hibcdm.rb +8 -0
- data/lib/zint/hibcmicpdf.rb +8 -0
- data/lib/zint/hibcpdf.rb +8 -0
- data/lib/zint/hibcqr.rb +8 -0
- data/lib/zint/isbnx.rb +8 -0
- data/lib/zint/itf14.rb +8 -0
- data/lib/zint/japan_post.rb +8 -0
- data/lib/zint/kix.rb +8 -0
- data/lib/zint/korea_post.rb +8 -0
- data/lib/zint/logmars.rb +8 -0
- data/lib/zint/mailmark.rb +8 -0
- data/lib/zint/mailmark_2d.rb +8 -0
- data/lib/zint/mailmark_4s.rb +8 -0
- data/lib/zint/maxi_code.rb +8 -0
- data/lib/zint/micro_pdf417.rb +8 -0
- data/lib/zint/micro_qr.rb +8 -0
- data/lib/zint/msiplessey.rb +8 -0
- data/lib/zint/native.rb +87 -0
- data/lib/zint/nve18.rb +8 -0
- data/lib/zint/one_code.rb +8 -0
- data/lib/zint/pdf417.rb +8 -0
- data/lib/zint/pdf417comp.rb +8 -0
- data/lib/zint/pdf417trunc.rb +8 -0
- data/lib/zint/pharma.rb +8 -0
- data/lib/zint/pharmatwo.rb +8 -0
- data/lib/zint/planet.rb +8 -0
- data/lib/zint/plessey.rb +8 -0
- data/lib/zint/postnet.rb +8 -0
- data/lib/zint/pzn.rb +8 -0
- data/lib/zint/qr.rb +18 -0
- data/lib/zint/rmqr.rb +8 -0
- data/lib/zint/rss14.rb +8 -0
- data/lib/zint/rss14stack.rb +8 -0
- data/lib/zint/rss14stackomni.rb +8 -0
- data/lib/zint/rssexp.rb +8 -0
- data/lib/zint/rssexpstack.rb +8 -0
- data/lib/zint/rssltd.rb +8 -0
- data/lib/zint/structs/structapp.rb +25 -0
- data/lib/zint/structs/symbol.rb +49 -0
- data/lib/zint/structs/vector.rb +54 -0
- data/lib/zint/structs/vector_circle.rb +32 -0
- data/lib/zint/structs/vector_hexagon.rb +31 -0
- data/lib/zint/structs/vector_rect.rb +37 -0
- data/lib/zint/structs/vector_string.rb +50 -0
- data/lib/zint/telepen.rb +8 -0
- data/lib/zint/telepennum.rb +8 -0
- data/lib/zint/ultra.rb +8 -0
- data/lib/zint/upc_a.rb +8 -0
- data/lib/zint/upc_a_chk.rb +8 -0
- data/lib/zint/upc_e.rb +8 -0
- data/lib/zint/upc_e_chk.rb +8 -0
- data/lib/zint/upnqr.rb +8 -0
- data/lib/zint/upu_s10.rb +8 -0
- data/lib/zint/uspsimail.rb +8 -0
- data/lib/zint/version.rb +3 -0
- data/lib/zint/vin.rb +8 -0
- data/lib/zint/zint_recipe.rb +27 -0
- data/lib/zint.rb +168 -0
- data/ports/archives/zint-2.12.0-src.tar.gz +0 -0
- data/ruby-zint.gemspec +40 -0
- metadata +326 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 92fde3cbd7c7505839dd00d583b3049d6f422da2865930391ecc1b8dda152961
|
4
|
+
data.tar.gz: a27b0d4c92f1b9ebb141e979657d2013e51a8cae39230d3b47fbc79794058ecf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6dd2ffece6670eede302bfea50669f9bdd0b493d04dd126adb57fbbfa1cc67091d26484977465ae4cdf9617b6f7ec871cf50f94ff8e82d6008533b3d277e3684
|
7
|
+
data.tar.gz: 492f659304defdd87f05176ebb7da4da01e976474855f542b81942364cb33989267bf50f61dfdcddff69dcf99acd9852b2e611de404269bf8551c48ae4f3a5d1
|
data/.rspec
ADDED
data/.standard.yml
ADDED
data/.yardopts
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in ruby-zint.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
gem "rake", "~> 13.0"
|
7
|
+
|
8
|
+
gem "rspec", "~> 3.0"
|
9
|
+
|
10
|
+
gem "simplecov", require: false
|
11
|
+
|
12
|
+
gem "chunky_png"
|
13
|
+
|
14
|
+
gem "byebug"
|
15
|
+
|
16
|
+
gem "standard", "~> 1.3"
|
17
|
+
|
18
|
+
gem "mini_portile2"
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Elias Fröhner
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
# ruby-zint
|
2
|
+
|
3
|
+
[![CI](https://github.com/api-walker/ruby-zint/actions/workflows/main.yml/badge.svg)](https://github.com/api-walker/ruby-zint/actions/workflows/main.yml)
|
4
|
+
|
5
|
+
This gem is a Ruby FFI binding for the [libzint](http://www.zint.org.uk) barcode generation library.
|
6
|
+
|
7
|
+
See the [documentation](https://rubydoc.info/github/api-walker/ruby-zint) for a full API description.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
By default ruby-zint first tries to use libzint installed on the system.
|
12
|
+
If libzint can't be found or if it isn't a supported version, then the zint version, bundled into the gem, is compiled and used.
|
13
|
+
Both install methods can be enforced by using `--enable-system-libzint` or `--disable-system-libzint` options, see below.
|
14
|
+
|
15
|
+
### With libzint source code (recommended)
|
16
|
+
First install CMake with your package manager (e. g. `apt install cmake`).
|
17
|
+
|
18
|
+
Afterwards install the gem and force builtin libzint:
|
19
|
+
|
20
|
+
```
|
21
|
+
$ gem install ruby-zint -- --disable-system-libzint
|
22
|
+
```
|
23
|
+
|
24
|
+
### With system libraries
|
25
|
+
|
26
|
+
Install the libzint binary with your package manager (e. g. `apt install zint` or perhaps `brew install zint`).
|
27
|
+
|
28
|
+
Other platforms require building [from source](https://www.zint.org.uk/manual/chapter/2).
|
29
|
+
|
30
|
+
**NOTE:** It is assumed that you are using libzint with the version [2.12](https://sourceforge.net/projects/zint/files/zint/2.12.0/).
|
31
|
+
|
32
|
+
Then install this gem and enforce system libzint:
|
33
|
+
|
34
|
+
```
|
35
|
+
$ gem install ruby-zint -- --enable-system-libzint
|
36
|
+
```
|
37
|
+
|
38
|
+
### Gemfile
|
39
|
+
|
40
|
+
Include `gem "ruby-zint"` in your Gemfile.
|
41
|
+
Optionally set the install option by running bundler like so:
|
42
|
+
|
43
|
+
```
|
44
|
+
bundle config build.ruby-zint --enable-system-libzint
|
45
|
+
```
|
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
|
+
|
51
|
+
## Usage
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
require "zint"
|
55
|
+
|
56
|
+
barcode = Zint::Barcode.new(value: "Test", symbology: Zint::BARCODE_CODE128)
|
57
|
+
|
58
|
+
# Export to file
|
59
|
+
barcode.to_file(path: "out.png")
|
60
|
+
|
61
|
+
# Export file to memory
|
62
|
+
barcode.to_memory_file(extension: ".png")
|
63
|
+
|
64
|
+
# Write from Bitmap to own canvas
|
65
|
+
require "chunky_png"
|
66
|
+
png = ChunkyPNG::Image.new(bitmap.width, bitmap.height, ChunkyPNG::Color::TRANSPARENT)
|
67
|
+
white = ChunkyPNG::Color("white")
|
68
|
+
black = ChunkyPNG::Color("black")
|
69
|
+
|
70
|
+
bitmap = barcode.to_bitmap
|
71
|
+
bitmap.pixels.each do |pixel|
|
72
|
+
png.compose_pixel(pixel.x, pixel.y, (pixel.colour == "1") ? black : white)
|
73
|
+
end
|
74
|
+
|
75
|
+
png.save("out.png")
|
76
|
+
|
77
|
+
# Use vector export
|
78
|
+
vec = Zint::Qr.new(value: "Test").to_vector
|
79
|
+
png = ChunkyPNG::Image.new(vec.width.to_i, vec.height.to_i, ChunkyPNG::Color::WHITE)
|
80
|
+
vec.each_rectangle do |rec|
|
81
|
+
png.rect(rec.x.to_i, rec.y.to_i,
|
82
|
+
rec.x.to_i+rec.width.to_i-1, rec.y.to_i+rec.height.to_i-1,
|
83
|
+
ChunkyPNG::Color::BLACK, ChunkyPNG::Color::BLACK)
|
84
|
+
end
|
85
|
+
png.save("out.png")
|
86
|
+
|
87
|
+
# See also manual: https://zint.org.uk/manual/chapter/5#buffering-symbols-in-memory-vector
|
88
|
+
|
89
|
+
# Use file as input
|
90
|
+
barcode = Zint::Barcode.new(input_file: "/tmp/test.txt")
|
91
|
+
barcode.to_file(path: "out.png")
|
92
|
+
|
93
|
+
# Use of comfort classes
|
94
|
+
|
95
|
+
# EAN
|
96
|
+
ean_barcode = Zint::Eanx.new(value: "012345678912")
|
97
|
+
ean_barcode.to_file(path: "ean.png")
|
98
|
+
|
99
|
+
# Code128
|
100
|
+
code_128_barcode = Zint::Code128.new(value: "012345678912")
|
101
|
+
code_128_barcode.to_file(path: "code_128.png")
|
102
|
+
|
103
|
+
```
|
104
|
+
|
105
|
+
## Contributing
|
106
|
+
|
107
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/api-walker/ruby-zint.
|
108
|
+
|
109
|
+
## License
|
110
|
+
|
111
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
112
|
+
|
113
|
+
## Credits
|
114
|
+
The project is based on the work and ideas of Angel Pizarro's [zint](https://github.com/delagoya/zint). I would also like to say a big thank you to [Lars Kanis](https://github.com/larskanis) for his great contributions.
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
require_relative "lib/zint/zint_recipe"
|
4
|
+
|
5
|
+
CLOBBER.include "pkg"
|
6
|
+
CLEAN.include "ports"
|
7
|
+
CLEAN.include "tmp"
|
8
|
+
CLEAN.include "ext/ruby-zint/tmp"
|
9
|
+
|
10
|
+
RSpec::Core::RakeTask.new(:spec)
|
11
|
+
|
12
|
+
require "standard/rake"
|
13
|
+
|
14
|
+
task default: %i[spec standard]
|
15
|
+
|
16
|
+
task gem: :build
|
17
|
+
task :compile do
|
18
|
+
sh "ruby -C ext/ruby-zint extconf.rb --disable-system-libzint"
|
19
|
+
sh "make -C ext/ruby-zint install RUBYARCHDIR=../../lib"
|
20
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# #!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "ffi"
|
5
|
+
require "fileutils"
|
6
|
+
|
7
|
+
if RUBY_PLATFORM.match?(/java/)
|
8
|
+
# JRuby's C extension support is disabled by default, so we can not use it
|
9
|
+
|
10
|
+
# Implement very simple verions of mkmf-helpers used below
|
11
|
+
def enable_config(name, default = nil)
|
12
|
+
if ARGV.include?("--enable-#{name}")
|
13
|
+
true
|
14
|
+
elsif ARGV.include?("--disable-#{name}")
|
15
|
+
false
|
16
|
+
else
|
17
|
+
default
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def arg_config(name)
|
22
|
+
ARGV.include?(name)
|
23
|
+
end
|
24
|
+
else
|
25
|
+
require "mkmf"
|
26
|
+
end
|
27
|
+
|
28
|
+
if RUBY_PLATFORM.match?(/darwin/)
|
29
|
+
ENV["SDKROOT"] ||= `xcrun --sdk macosx --show-sdk-path`.chomp
|
30
|
+
end
|
31
|
+
|
32
|
+
def do_help
|
33
|
+
print <<~HELP
|
34
|
+
usage: ruby #{$0} [options]
|
35
|
+
--enable-system-libzint / --disable-system-libzint
|
36
|
+
Force use of system or builtin libzint library.
|
37
|
+
Default is to prefer system libraries and fallback to builtin.
|
38
|
+
HELP
|
39
|
+
exit! 0
|
40
|
+
end
|
41
|
+
|
42
|
+
do_help if arg_config("--help")
|
43
|
+
|
44
|
+
def libzint_usable?
|
45
|
+
m = Module.new do
|
46
|
+
extend FFI::Library
|
47
|
+
|
48
|
+
ffi_lib(%w[libzint.so.2.12 libzint zint])
|
49
|
+
attach_function(:ZBarcode_Version, [], :int32)
|
50
|
+
end
|
51
|
+
|
52
|
+
(21200...21300) === m.ZBarcode_Version
|
53
|
+
rescue LoadError
|
54
|
+
false
|
55
|
+
end
|
56
|
+
|
57
|
+
def build_bundled_libzint
|
58
|
+
puts "Build"
|
59
|
+
require_relative "../../lib/zint/zint_recipe"
|
60
|
+
|
61
|
+
recipe = Zint::ZintRecipe.new
|
62
|
+
recipe.cook_and_activate
|
63
|
+
recipe.path
|
64
|
+
end
|
65
|
+
|
66
|
+
unless enable_config("system-libzint", libzint_usable?)
|
67
|
+
# Unable to load libzint library on this system,
|
68
|
+
# so we build our bundled version:
|
69
|
+
libzint_path = build_bundled_libzint
|
70
|
+
end
|
71
|
+
|
72
|
+
# Create a Makefile which copies the libzint library files to the gem's lib dir.
|
73
|
+
File.open("Makefile", "wb") do |mf|
|
74
|
+
mf.puts <<~EOT
|
75
|
+
RUBYARCHDIR = #{RbConfig::MAKEFILE_CONFIG["sitearchdir"].dump}
|
76
|
+
all:
|
77
|
+
clean:
|
78
|
+
install:
|
79
|
+
EOT
|
80
|
+
|
81
|
+
if libzint_path
|
82
|
+
mf.puts <<-EOT
|
83
|
+
cp -r #{libzint_path.dump}/*/libzint* $(RUBYARCHDIR)
|
84
|
+
EOT
|
85
|
+
end
|
86
|
+
end
|
data/lib/ruby-zint.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "zint"
|
data/lib/zint/azrune.rb
ADDED