barcode_pao 0.0.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 +7 -0
- data/LICENSE +21 -0
- data/README.md +187 -0
- data/lib/barcode_pao/native/SDL2.dll +0 -0
- data/lib/barcode_pao/native/SDL2_image.dll +0 -0
- data/lib/barcode_pao/native/SDL2_ttf.dll +0 -0
- data/lib/barcode_pao/native/barcode_pao.dll +0 -0
- data/lib/barcode_pao/version.rb +5 -0
- data/lib/barcode_pao/wrapper.rb +401 -0
- data/lib/barcode_pao.rb +4 -0
- metadata +69 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 18903ec6754d492acb8a89f3ffa0ea66cf48ff35bb03a03d0de44c71caf88af9
|
|
4
|
+
data.tar.gz: ec0b8a2f3b7d0e6a521a4608a775b72a42604bb31f2c60bcf061206b4a0d37b0
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 8d5608945fe1dedaa4575ccecddd9a0156a8b310e478d1cbe5366762c7b40e6949f6e575413ab24b7cdf71ec3c1b271a7d456858cde3ea0ed7edff02393b59ae
|
|
7
|
+
data.tar.gz: 20fdb92768d96804592a57773bff0275d78b6cbe90927b69fc5804db53277611df71c932a8819ad83d37643c15b49fefabc53158c6af1bea57f49a8e390ec7a9
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Pao
|
|
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 all
|
|
13
|
+
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 THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# barcode_pao
|
|
2
|
+
|
|
3
|
+
クロスプラットフォーム バーコード生成ライブラリ for Ruby(Native FFI版)
|
|
4
|
+
|
|
5
|
+
## 概要
|
|
6
|
+
|
|
7
|
+
`barcode_pao` は、C++ バーコードエンジンを FFI(Foreign Function Interface)で直接呼び出す高速なRuby gemです。ネイティブコードを直接実行するため、高速なバーコード生成が可能です。
|
|
8
|
+
|
|
9
|
+
## 必要条件
|
|
10
|
+
|
|
11
|
+
- Ruby 3.0以上
|
|
12
|
+
- ffi gem
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
gem install ffi
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## 対応バーコード(18種)
|
|
19
|
+
|
|
20
|
+
### 1次元バーコード(11種)
|
|
21
|
+
- **Code39** - 英数字対応の汎用バーコード
|
|
22
|
+
- **Code93** - Code39の拡張版
|
|
23
|
+
- **Code128** - 全ASCII文字対応の高密度バーコード
|
|
24
|
+
- **GS1-128** - 物流・流通向けバーコード(コンビニ収納代行対応)
|
|
25
|
+
- **NW-7 (Codabar)** - 血液銀行・宅配便向けバーコード
|
|
26
|
+
- **Matrix 2 of 5** - 工業用バーコード
|
|
27
|
+
- **NEC 2 of 5** - NECが開発した2 of 5系バーコード
|
|
28
|
+
- **JAN-8** - 日本の商品コード(8桁)
|
|
29
|
+
- **JAN-13** - 日本の商品コード(13桁)
|
|
30
|
+
- **UPC-A** - 北米の商品コード(12桁)
|
|
31
|
+
- **UPC-E** - UPC-Aの短縮版(8桁)
|
|
32
|
+
|
|
33
|
+
### GS1 DataBar(3種)
|
|
34
|
+
- **GS1 DataBar 14** - 標準型(オムニ/スタック対応)
|
|
35
|
+
- **GS1 DataBar Limited** - 限定型
|
|
36
|
+
- **GS1 DataBar Expanded** - 拡張型(スタック対応)
|
|
37
|
+
|
|
38
|
+
### 2次元バーコード(3種)
|
|
39
|
+
- **QRコード** - 日本発の2次元コード
|
|
40
|
+
- **DataMatrix** - 工業用途の2次元コード
|
|
41
|
+
- **PDF417** - 運転免許証等で使用される2次元コード
|
|
42
|
+
|
|
43
|
+
### 特殊バーコード(1種)
|
|
44
|
+
- **郵便カスタマバーコード** - 日本郵便の住所表示バーコード
|
|
45
|
+
|
|
46
|
+
## インストール
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
gem install barcode_pao
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## 使用例
|
|
53
|
+
|
|
54
|
+
### QRコード生成
|
|
55
|
+
|
|
56
|
+
```ruby
|
|
57
|
+
require "barcode_pao"
|
|
58
|
+
|
|
59
|
+
# QRコードインスタンスを作成
|
|
60
|
+
qr = BarcodePao::QRCode.new
|
|
61
|
+
|
|
62
|
+
# エラー訂正レベルを設定(L/M/Q/H)
|
|
63
|
+
qr.set_error_correction_level("H")
|
|
64
|
+
|
|
65
|
+
# バーコード生成
|
|
66
|
+
qr.draw("https://example.com", 200)
|
|
67
|
+
|
|
68
|
+
# Base64エンコードされた画像を取得
|
|
69
|
+
base64_image = qr.get_image_base64
|
|
70
|
+
puts base64_image
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Code128バーコード生成
|
|
74
|
+
|
|
75
|
+
```ruby
|
|
76
|
+
code128 = BarcodePao::Code128.new("svg")
|
|
77
|
+
|
|
78
|
+
# テキスト表示を有効化
|
|
79
|
+
code128.set_show_text(true)
|
|
80
|
+
|
|
81
|
+
# バーコード生成
|
|
82
|
+
code128.draw("ABC-12345", 300, 100)
|
|
83
|
+
|
|
84
|
+
# SVGデータを取得
|
|
85
|
+
svg_data = code128.get_svg
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### 色のカスタマイズ
|
|
89
|
+
|
|
90
|
+
```ruby
|
|
91
|
+
code39 = BarcodePao::Code39.new
|
|
92
|
+
|
|
93
|
+
# 前景色(バーの色)をRGBAで設定
|
|
94
|
+
code39.set_foreground_color(0, 0, 128, 255) # 紺色
|
|
95
|
+
|
|
96
|
+
# 背景色をRGBAで設定
|
|
97
|
+
code39.set_background_color(255, 255, 200, 255) # 薄黄色
|
|
98
|
+
|
|
99
|
+
code39.draw("12345", 200, 80)
|
|
100
|
+
base64_image = code39.get_image_base64
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### GS1-128 コンビニ収納代行バーコード
|
|
104
|
+
|
|
105
|
+
```ruby
|
|
106
|
+
gs1 = BarcodePao::GS1128.new
|
|
107
|
+
gs1.set_show_text(true)
|
|
108
|
+
|
|
109
|
+
# 標準料金代理収納用バーコード
|
|
110
|
+
convenience_code = "9101234567890123456789012345678901234567890123"
|
|
111
|
+
gs1.draw(convenience_code, 400, 100)
|
|
112
|
+
base64_image = gs1.get_image_base64
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### 郵便カスタマバーコード
|
|
116
|
+
|
|
117
|
+
```ruby
|
|
118
|
+
yubin = BarcodePao::YubinCustomer.new
|
|
119
|
+
|
|
120
|
+
# 郵便番号 + 住所表示番号
|
|
121
|
+
code = "1000001-1-2-3"
|
|
122
|
+
yubin.draw(code, 50) # 高さのみ指定
|
|
123
|
+
base64_image = yubin.get_image_base64
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## API リファレンス
|
|
127
|
+
|
|
128
|
+
### 共通メソッド(全バーコードクラス)
|
|
129
|
+
|
|
130
|
+
| メソッド | 説明 |
|
|
131
|
+
|---------|------|
|
|
132
|
+
| `set_output_format(format)` | 出力フォーマットを設定("png", "jpeg", "svg")|
|
|
133
|
+
| `set_foreground_color(r, g, b, a)` | 前景色(バーの色)を設定 |
|
|
134
|
+
| `set_background_color(r, g, b, a)` | 背景色を設定 |
|
|
135
|
+
| `get_image_base64` | Base64エンコードされた画像を取得 |
|
|
136
|
+
| `get_svg` | SVG文字列を取得 |
|
|
137
|
+
|
|
138
|
+
### 1次元バーコード固有メソッド
|
|
139
|
+
|
|
140
|
+
| メソッド | 説明 |
|
|
141
|
+
|---------|------|
|
|
142
|
+
| `set_show_text(show)` | バーコード下のテキスト表示 |
|
|
143
|
+
| `set_text_font_scale(scale)` | テキストのフォントサイズスケール |
|
|
144
|
+
| `set_text_gap(scale)` | バーとテキストの間隔 |
|
|
145
|
+
| `set_fit_width(fit)` | 幅に合わせてバーを調整 |
|
|
146
|
+
| `set_px_adjust_black(adjust)` | 黒バーのピクセル調整 |
|
|
147
|
+
| `set_px_adjust_white(adjust)` | 白バーのピクセル調整 |
|
|
148
|
+
|
|
149
|
+
### 2次元バーコード固有メソッド
|
|
150
|
+
|
|
151
|
+
| クラス | メソッド | 説明 |
|
|
152
|
+
|--------|---------|------|
|
|
153
|
+
| QRCode | `set_error_correction_level(level)` | エラー訂正レベル(L/M/Q/H)|
|
|
154
|
+
| QRCode | `set_version(version)` | バージョン(0=自動, 1-40)|
|
|
155
|
+
| QRCode | `set_encode_mode(mode)` | エンコードモード(NUMERIC/ALPHANUMERIC/BYTE/KANJI)|
|
|
156
|
+
| DataMatrix | `set_code_size(size)` | シンボルサイズ("AUTO", "10x10"など)|
|
|
157
|
+
| DataMatrix | `set_encode_scheme(scheme)` | エンコードスキーム(AUTO/ASCII/C40/TEXT/X12/EDIFACT/BASE256)|
|
|
158
|
+
| PDF417 | `set_error_level(level)` | エラー訂正レベル(-1=自動, 0-8)|
|
|
159
|
+
| PDF417 | `set_columns(columns)` | 列数 |
|
|
160
|
+
| PDF417 | `set_rows(rows)` | 行数 |
|
|
161
|
+
|
|
162
|
+
## 出力フォーマット
|
|
163
|
+
|
|
164
|
+
| フォーマット | 説明 |
|
|
165
|
+
|-------------|------|
|
|
166
|
+
| `png` | PNG画像(デフォルト)|
|
|
167
|
+
| `jpeg` | JPEG画像 |
|
|
168
|
+
| `svg` | SVGベクター画像 |
|
|
169
|
+
|
|
170
|
+
## WASM版との違い
|
|
171
|
+
|
|
172
|
+
| | Native FFI版 | WASM版 |
|
|
173
|
+
|---|------------|--------|
|
|
174
|
+
| パッケージ名 | `barcode_pao` | `barcode_pao_wasm` |
|
|
175
|
+
| 実行方式 | C++ DLL/SO を直接呼び出し | Node.js 経由で WASM 実行 |
|
|
176
|
+
| 速度 | 高速 | やや遅い |
|
|
177
|
+
| 依存 | ffi gem + ネイティブDLL | Node.js |
|
|
178
|
+
| API | 同じ | 同じ |
|
|
179
|
+
|
|
180
|
+
## ライセンス
|
|
181
|
+
|
|
182
|
+
MIT License
|
|
183
|
+
|
|
184
|
+
## 関連パッケージ
|
|
185
|
+
|
|
186
|
+
- [barcode_pao_wasm (RubyGems)](https://rubygems.org/gems/barcode_pao_wasm) - Ruby WASM版
|
|
187
|
+
- [barcode-pao-wasm (Python)](https://pypi.org/project/barcode-pao-wasm/) - Python WASM版
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "ffi"
|
|
4
|
+
|
|
5
|
+
module BarcodePao
|
|
6
|
+
FORMAT_PNG = "png"
|
|
7
|
+
FORMAT_JPEG = "jpeg"
|
|
8
|
+
FORMAT_SVG = "svg"
|
|
9
|
+
|
|
10
|
+
# Barcode type IDs (matching barcode_ffi.h)
|
|
11
|
+
BC_CODE39 = 0
|
|
12
|
+
BC_CODE93 = 1
|
|
13
|
+
BC_CODE128 = 2
|
|
14
|
+
BC_GS1_128 = 3
|
|
15
|
+
BC_NW7 = 4
|
|
16
|
+
BC_MATRIX2OF5 = 5
|
|
17
|
+
BC_NEC2OF5 = 6
|
|
18
|
+
BC_JAN8 = 7
|
|
19
|
+
BC_JAN13 = 8
|
|
20
|
+
BC_UPC_A = 9
|
|
21
|
+
BC_UPC_E = 10
|
|
22
|
+
BC_ITF = 11
|
|
23
|
+
BC_GS1_DATABAR_14 = 12
|
|
24
|
+
BC_GS1_DATABAR_LIMITED = 13
|
|
25
|
+
BC_GS1_DATABAR_EXPANDED = 14
|
|
26
|
+
BC_YUBIN_CUSTOMER = 15
|
|
27
|
+
BC_QR = 16
|
|
28
|
+
BC_DATAMATRIX = 17
|
|
29
|
+
BC_PDF417 = 18
|
|
30
|
+
|
|
31
|
+
# --- Native FFI Bindings ---
|
|
32
|
+
module Native
|
|
33
|
+
extend FFI::Library
|
|
34
|
+
|
|
35
|
+
def self.find_library
|
|
36
|
+
native_dir = File.join(File.dirname(__FILE__), "native")
|
|
37
|
+
if FFI::Platform.windows?
|
|
38
|
+
# Preload dependent DLLs so barcode_pao.dll can find them
|
|
39
|
+
%w[SDL2.dll SDL2_image.dll SDL2_ttf.dll].each do |dep|
|
|
40
|
+
dep_path = File.join(native_dir, dep)
|
|
41
|
+
FFI::DynamicLibrary.open(dep_path, FFI::DynamicLibrary::RTLD_GLOBAL) if File.exist?(dep_path)
|
|
42
|
+
end
|
|
43
|
+
File.join(native_dir, "barcode_pao.dll")
|
|
44
|
+
elsif FFI::Platform.mac?
|
|
45
|
+
File.join(native_dir, "libbarcode_pao.dylib")
|
|
46
|
+
else
|
|
47
|
+
File.join(native_dir, "libbarcode_pao.so")
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
ffi_lib find_library
|
|
52
|
+
|
|
53
|
+
# Create / Destroy
|
|
54
|
+
attach_function :barcode_create, [:int], :pointer
|
|
55
|
+
attach_function :barcode_destroy, [:pointer], :void
|
|
56
|
+
|
|
57
|
+
# Common settings
|
|
58
|
+
attach_function :barcode_set_output_format, [:pointer, :string], :void
|
|
59
|
+
attach_function :barcode_set_foreground_color, [:pointer, :int, :int, :int, :int], :void
|
|
60
|
+
attach_function :barcode_set_background_color, [:pointer, :int, :int, :int, :int], :void
|
|
61
|
+
attach_function :barcode_set_px_adjust_black, [:pointer, :int], :void
|
|
62
|
+
attach_function :barcode_set_px_adjust_white, [:pointer, :int], :void
|
|
63
|
+
attach_function :barcode_set_fit_width, [:pointer, :int], :void
|
|
64
|
+
|
|
65
|
+
# 1D settings
|
|
66
|
+
attach_function :barcode_set_show_text, [:pointer, :int], :void
|
|
67
|
+
attach_function :barcode_set_text_font_scale, [:pointer, :double], :void
|
|
68
|
+
attach_function :barcode_set_text_gap, [:pointer, :double], :void
|
|
69
|
+
attach_function :barcode_set_text_even_spacing, [:pointer, :int], :void
|
|
70
|
+
|
|
71
|
+
# 2D settings
|
|
72
|
+
attach_function :barcode_set_string_encoding, [:pointer, :string], :void
|
|
73
|
+
|
|
74
|
+
# Type-specific settings
|
|
75
|
+
attach_function :barcode_set_show_start_stop, [:pointer, :int], :void
|
|
76
|
+
attach_function :barcode_set_code_mode, [:pointer, :string], :void
|
|
77
|
+
attach_function :barcode_set_extended_guard, [:pointer, :int], :void
|
|
78
|
+
attach_function :barcode_set_error_correction_level, [:pointer, :string], :void
|
|
79
|
+
attach_function :barcode_set_version, [:pointer, :int], :void
|
|
80
|
+
attach_function :barcode_set_encode_mode, [:pointer, :string], :void
|
|
81
|
+
attach_function :barcode_set_code_size, [:pointer, :string], :void
|
|
82
|
+
attach_function :barcode_set_encode_scheme, [:pointer, :string], :void
|
|
83
|
+
attach_function :barcode_set_error_level, [:pointer, :int], :void
|
|
84
|
+
attach_function :barcode_set_columns, [:pointer, :int], :void
|
|
85
|
+
attach_function :barcode_set_rows, [:pointer, :int], :void
|
|
86
|
+
attach_function :barcode_set_aspect_ratio, [:pointer, :double], :void
|
|
87
|
+
attach_function :barcode_set_y_height, [:pointer, :int], :void
|
|
88
|
+
attach_function :barcode_set_symbol_type_14, [:pointer, :string], :void
|
|
89
|
+
attach_function :barcode_set_symbol_type_exp, [:pointer, :string], :void
|
|
90
|
+
attach_function :barcode_set_no_of_columns, [:pointer, :int], :void
|
|
91
|
+
|
|
92
|
+
# Draw
|
|
93
|
+
attach_function :barcode_draw_1d, [:pointer, :string, :int, :int], :int
|
|
94
|
+
attach_function :barcode_draw_2d, [:pointer, :string, :int], :int
|
|
95
|
+
attach_function :barcode_draw_2d_rect, [:pointer, :string, :int, :int], :int
|
|
96
|
+
attach_function :barcode_draw_yubin, [:pointer, :string, :int], :int
|
|
97
|
+
|
|
98
|
+
# Get results
|
|
99
|
+
attach_function :barcode_get_base64, [:pointer], :string
|
|
100
|
+
attach_function :barcode_get_svg, [:pointer], :string
|
|
101
|
+
attach_function :barcode_is_svg_output, [:pointer], :int
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# --- Base class with handle lifecycle ---
|
|
105
|
+
class BarcodeBase
|
|
106
|
+
attr_reader :output_format
|
|
107
|
+
|
|
108
|
+
def initialize(type_id, output_format = FORMAT_PNG)
|
|
109
|
+
@handle = Native.barcode_create(type_id)
|
|
110
|
+
raise "failed to create barcode handle for type #{type_id}" if @handle.null?
|
|
111
|
+
@output_format = output_format
|
|
112
|
+
Native.barcode_set_output_format(@handle, output_format)
|
|
113
|
+
ObjectSpace.define_finalizer(self, BarcodeBase.release(@handle))
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def self.release(handle)
|
|
117
|
+
proc { Native.barcode_destroy(handle) }
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def set_output_format(fmt)
|
|
121
|
+
@output_format = fmt
|
|
122
|
+
Native.barcode_set_output_format(@handle, fmt)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def set_foreground_color(r, g, b, a = 255)
|
|
126
|
+
Native.barcode_set_foreground_color(@handle, r, g, b, a)
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def set_background_color(r, g, b, a = 255)
|
|
130
|
+
Native.barcode_set_background_color(@handle, r, g, b, a)
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def set_px_adjust_black(val)
|
|
134
|
+
Native.barcode_set_px_adjust_black(@handle, val)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def set_px_adjust_white(val)
|
|
138
|
+
Native.barcode_set_px_adjust_white(@handle, val)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def set_fit_width(fit)
|
|
142
|
+
Native.barcode_set_fit_width(@handle, fit ? 1 : 0)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def get_image_base64
|
|
146
|
+
Native.barcode_get_base64(@handle)
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def get_svg
|
|
150
|
+
Native.barcode_get_svg(@handle)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def svg_output?
|
|
154
|
+
Native.barcode_is_svg_output(@handle) == 1
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
# --- 1D base ---
|
|
159
|
+
class BarcodeBase1D < BarcodeBase
|
|
160
|
+
def set_show_text(show)
|
|
161
|
+
Native.barcode_set_show_text(@handle, show ? 1 : 0)
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def set_text_font_scale(scale)
|
|
165
|
+
Native.barcode_set_text_font_scale(@handle, scale.to_f)
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def set_text_gap(scale)
|
|
169
|
+
Native.barcode_set_text_gap(@handle, scale.to_f)
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def set_text_even_spacing(even)
|
|
173
|
+
Native.barcode_set_text_even_spacing(@handle, even ? 1 : 0)
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
def draw(code, width, height)
|
|
177
|
+
result = Native.barcode_draw_1d(@handle, code, width, height)
|
|
178
|
+
raise "draw failed" if result != 1
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
# --- 2D base ---
|
|
183
|
+
class BarcodeBase2D < BarcodeBase
|
|
184
|
+
def set_string_encoding(encoding)
|
|
185
|
+
Native.barcode_set_string_encoding(@handle, encoding)
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
def draw(code, size)
|
|
189
|
+
result = Native.barcode_draw_2d(@handle, code, size)
|
|
190
|
+
raise "draw failed" if result != 1
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
# --- Concrete 1D types ---
|
|
195
|
+
|
|
196
|
+
class Code39 < BarcodeBase1D
|
|
197
|
+
def initialize(output_format = FORMAT_PNG)
|
|
198
|
+
super(BC_CODE39, output_format)
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
def set_show_start_stop(show)
|
|
202
|
+
Native.barcode_set_show_start_stop(@handle, show ? 1 : 0)
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
class Code93 < BarcodeBase1D
|
|
207
|
+
def initialize(output_format = FORMAT_PNG)
|
|
208
|
+
super(BC_CODE93, output_format)
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
class Code128 < BarcodeBase1D
|
|
213
|
+
def initialize(output_format = FORMAT_PNG)
|
|
214
|
+
super(BC_CODE128, output_format)
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
def set_code_mode(mode)
|
|
218
|
+
Native.barcode_set_code_mode(@handle, mode)
|
|
219
|
+
end
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
class GS1128 < BarcodeBase1D
|
|
223
|
+
def initialize(output_format = FORMAT_PNG)
|
|
224
|
+
super(BC_GS1_128, output_format)
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
class NW7 < BarcodeBase1D
|
|
229
|
+
def initialize(output_format = FORMAT_PNG)
|
|
230
|
+
super(BC_NW7, output_format)
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
def set_show_start_stop(show)
|
|
234
|
+
Native.barcode_set_show_start_stop(@handle, show ? 1 : 0)
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
class ITF < BarcodeBase1D
|
|
239
|
+
def initialize(output_format = FORMAT_PNG)
|
|
240
|
+
super(BC_ITF, output_format)
|
|
241
|
+
end
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
class Matrix2of5 < BarcodeBase1D
|
|
245
|
+
def initialize(output_format = FORMAT_PNG)
|
|
246
|
+
super(BC_MATRIX2OF5, output_format)
|
|
247
|
+
end
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
class NEC2of5 < BarcodeBase1D
|
|
251
|
+
def initialize(output_format = FORMAT_PNG)
|
|
252
|
+
super(BC_NEC2OF5, output_format)
|
|
253
|
+
end
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
class JAN8 < BarcodeBase1D
|
|
257
|
+
def initialize(output_format = FORMAT_PNG)
|
|
258
|
+
super(BC_JAN8, output_format)
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
def set_extended_guard(ext)
|
|
262
|
+
Native.barcode_set_extended_guard(@handle, ext ? 1 : 0)
|
|
263
|
+
end
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
class JAN13 < BarcodeBase1D
|
|
267
|
+
def initialize(output_format = FORMAT_PNG)
|
|
268
|
+
super(BC_JAN13, output_format)
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
def set_extended_guard(ext)
|
|
272
|
+
Native.barcode_set_extended_guard(@handle, ext ? 1 : 0)
|
|
273
|
+
end
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
class UPCA < BarcodeBase1D
|
|
277
|
+
def initialize(output_format = FORMAT_PNG)
|
|
278
|
+
super(BC_UPC_A, output_format)
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
def set_extended_guard(ext)
|
|
282
|
+
Native.barcode_set_extended_guard(@handle, ext ? 1 : 0)
|
|
283
|
+
end
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
class UPCE < BarcodeBase1D
|
|
287
|
+
def initialize(output_format = FORMAT_PNG)
|
|
288
|
+
super(BC_UPC_E, output_format)
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
def set_extended_guard(ext)
|
|
292
|
+
Native.barcode_set_extended_guard(@handle, ext ? 1 : 0)
|
|
293
|
+
end
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
class GS1DataBar14 < BarcodeBase1D
|
|
297
|
+
def initialize(output_format = FORMAT_PNG)
|
|
298
|
+
super(BC_GS1_DATABAR_14, output_format)
|
|
299
|
+
end
|
|
300
|
+
|
|
301
|
+
def set_symbol_type(type_str)
|
|
302
|
+
Native.barcode_set_symbol_type_14(@handle, type_str)
|
|
303
|
+
end
|
|
304
|
+
end
|
|
305
|
+
|
|
306
|
+
class GS1DataBarLimited < BarcodeBase1D
|
|
307
|
+
def initialize(output_format = FORMAT_PNG)
|
|
308
|
+
super(BC_GS1_DATABAR_LIMITED, output_format)
|
|
309
|
+
end
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
class GS1DataBarExpanded < BarcodeBase1D
|
|
313
|
+
def initialize(output_format = FORMAT_PNG)
|
|
314
|
+
super(BC_GS1_DATABAR_EXPANDED, output_format)
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
def set_symbol_type(type_str)
|
|
318
|
+
Native.barcode_set_symbol_type_exp(@handle, type_str)
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
def set_no_of_columns(cols)
|
|
322
|
+
Native.barcode_set_no_of_columns(@handle, cols)
|
|
323
|
+
end
|
|
324
|
+
end
|
|
325
|
+
|
|
326
|
+
class YubinCustomer < BarcodeBase
|
|
327
|
+
def initialize(output_format = FORMAT_PNG)
|
|
328
|
+
super(BC_YUBIN_CUSTOMER, output_format)
|
|
329
|
+
end
|
|
330
|
+
|
|
331
|
+
def draw(code, height)
|
|
332
|
+
result = Native.barcode_draw_yubin(@handle, code, height)
|
|
333
|
+
raise "draw failed" if result != 1
|
|
334
|
+
end
|
|
335
|
+
end
|
|
336
|
+
|
|
337
|
+
# --- 2D types ---
|
|
338
|
+
|
|
339
|
+
class QRCode < BarcodeBase2D
|
|
340
|
+
def initialize(output_format = FORMAT_PNG)
|
|
341
|
+
super(BC_QR, output_format)
|
|
342
|
+
end
|
|
343
|
+
|
|
344
|
+
def set_error_correction_level(level)
|
|
345
|
+
Native.barcode_set_error_correction_level(@handle, level)
|
|
346
|
+
end
|
|
347
|
+
|
|
348
|
+
def set_version(version)
|
|
349
|
+
Native.barcode_set_version(@handle, version)
|
|
350
|
+
end
|
|
351
|
+
|
|
352
|
+
def set_encode_mode(mode)
|
|
353
|
+
Native.barcode_set_encode_mode(@handle, mode)
|
|
354
|
+
end
|
|
355
|
+
end
|
|
356
|
+
|
|
357
|
+
class DataMatrix < BarcodeBase2D
|
|
358
|
+
def initialize(output_format = FORMAT_PNG)
|
|
359
|
+
super(BC_DATAMATRIX, output_format)
|
|
360
|
+
end
|
|
361
|
+
|
|
362
|
+
def set_code_size(size)
|
|
363
|
+
Native.barcode_set_code_size(@handle, size)
|
|
364
|
+
end
|
|
365
|
+
|
|
366
|
+
def set_encode_scheme(scheme)
|
|
367
|
+
Native.barcode_set_encode_scheme(@handle, scheme)
|
|
368
|
+
end
|
|
369
|
+
end
|
|
370
|
+
|
|
371
|
+
class PDF417 < BarcodeBase2D
|
|
372
|
+
def initialize(output_format = FORMAT_PNG)
|
|
373
|
+
super(BC_PDF417, output_format)
|
|
374
|
+
end
|
|
375
|
+
|
|
376
|
+
def set_error_level(level)
|
|
377
|
+
Native.barcode_set_error_level(@handle, level)
|
|
378
|
+
end
|
|
379
|
+
|
|
380
|
+
def set_columns(cols)
|
|
381
|
+
Native.barcode_set_columns(@handle, cols)
|
|
382
|
+
end
|
|
383
|
+
|
|
384
|
+
def set_rows(rows)
|
|
385
|
+
Native.barcode_set_rows(@handle, rows)
|
|
386
|
+
end
|
|
387
|
+
|
|
388
|
+
def set_aspect_ratio(ratio)
|
|
389
|
+
Native.barcode_set_aspect_ratio(@handle, ratio.to_f)
|
|
390
|
+
end
|
|
391
|
+
|
|
392
|
+
def set_y_height(y)
|
|
393
|
+
Native.barcode_set_y_height(@handle, y)
|
|
394
|
+
end
|
|
395
|
+
|
|
396
|
+
def draw(code, width, height)
|
|
397
|
+
result = Native.barcode_draw_2d_rect(@handle, code, width, height)
|
|
398
|
+
raise "draw failed" if result != 1
|
|
399
|
+
end
|
|
400
|
+
end
|
|
401
|
+
end
|
data/lib/barcode_pao.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: barcode_pao
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Pao
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: ffi
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '1.15'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '1.15'
|
|
26
|
+
description: 'Barcode.Ruby Native is a barcode generation library using C++ FFI, supporting
|
|
27
|
+
18 barcode types: Code39, Code93, Code128, GS1-128, NW-7, ITF, Matrix 2of5, NEC
|
|
28
|
+
2of5, JAN-8, JAN-13, UPC-A, UPC-E, GS1 DataBar (Standard/Limited/Expanded), QR Code,
|
|
29
|
+
DataMatrix, PDF417, and Japan Post Customer Barcode. Output formats: PNG, JPEG,
|
|
30
|
+
SVG.'
|
|
31
|
+
email:
|
|
32
|
+
- info@pao.ac
|
|
33
|
+
executables: []
|
|
34
|
+
extensions: []
|
|
35
|
+
extra_rdoc_files: []
|
|
36
|
+
files:
|
|
37
|
+
- LICENSE
|
|
38
|
+
- README.md
|
|
39
|
+
- lib/barcode_pao.rb
|
|
40
|
+
- lib/barcode_pao/native/SDL2.dll
|
|
41
|
+
- lib/barcode_pao/native/SDL2_image.dll
|
|
42
|
+
- lib/barcode_pao/native/SDL2_ttf.dll
|
|
43
|
+
- lib/barcode_pao/native/barcode_pao.dll
|
|
44
|
+
- lib/barcode_pao/version.rb
|
|
45
|
+
- lib/barcode_pao/wrapper.rb
|
|
46
|
+
homepage: https://www.pao.ac/barcode.ruby/
|
|
47
|
+
licenses:
|
|
48
|
+
- MIT
|
|
49
|
+
metadata:
|
|
50
|
+
homepage_uri: https://www.pao.ac/barcode.ruby/
|
|
51
|
+
source_code_uri: https://github.com/pao-xx/barcode-pao-ruby
|
|
52
|
+
rdoc_options: []
|
|
53
|
+
require_paths:
|
|
54
|
+
- lib
|
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
56
|
+
requirements:
|
|
57
|
+
- - ">="
|
|
58
|
+
- !ruby/object:Gem::Version
|
|
59
|
+
version: 3.0.0
|
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
|
+
requirements:
|
|
62
|
+
- - ">="
|
|
63
|
+
- !ruby/object:Gem::Version
|
|
64
|
+
version: '0'
|
|
65
|
+
requirements: []
|
|
66
|
+
rubygems_version: 3.6.9
|
|
67
|
+
specification_version: 4
|
|
68
|
+
summary: Barcode generation library - 18 barcode types (Native FFI)
|
|
69
|
+
test_files: []
|