oshpark-rqrcode 0.10.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/CHANGELOG +97 -0
- data/LICENSE +19 -0
- data/README.md +230 -0
- data/lib/rqrcode.rb +20 -0
- data/lib/rqrcode/core_ext.rb +5 -0
- data/lib/rqrcode/core_ext/array.rb +5 -0
- data/lib/rqrcode/core_ext/array/behavior.rb +12 -0
- data/lib/rqrcode/core_ext/integer.rb +5 -0
- data/lib/rqrcode/core_ext/integer/bitwise.rb +13 -0
- data/lib/rqrcode/export/ansi.rb +78 -0
- data/lib/rqrcode/export/gerber.rb +93 -0
- data/lib/rqrcode/export/html.rb +53 -0
- data/lib/rqrcode/export/png.rb +117 -0
- data/lib/rqrcode/export/svg.rb +53 -0
- data/lib/rqrcode/qrcode.rb +4 -0
- data/lib/rqrcode/qrcode/qr_8bit_byte.rb +36 -0
- data/lib/rqrcode/qrcode/qr_alphanumeric.rb +47 -0
- data/lib/rqrcode/qrcode/qr_bit_buffer.rb +99 -0
- data/lib/rqrcode/qrcode/qr_code.rb +585 -0
- data/lib/rqrcode/qrcode/qr_math.rb +63 -0
- data/lib/rqrcode/qrcode/qr_numeric.rb +57 -0
- data/lib/rqrcode/qrcode/qr_polynomial.rb +78 -0
- data/lib/rqrcode/qrcode/qr_rs_block.rb +314 -0
- data/lib/rqrcode/qrcode/qr_util.rb +272 -0
- data/lib/rqrcode/version.rb +3 -0
- data/test/data.rb +25 -0
- data/test/test_helper.rb +5 -0
- data/test/test_regresions.rb +10 -0
- data/test/test_rqrcode.rb +155 -0
- data/test/test_rqrcode_export.rb +27 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d8a8625fec3d70b078e3a0958af0d2ef70ef847e
|
4
|
+
data.tar.gz: e4b112278c20a60221ba5c55189a61ae478b3009
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: eed82f240841536ce65373291db6240e459a307fd764576e0a37d1be2da3673de1eb29b7588397e9e5894b44709e0577dce507eac53f7016fbaf2620cec173ee
|
7
|
+
data.tar.gz: 961043e60d8e1da13d30785f7348b87bb2407fa81dd6c77161beeb5af373a204afc7ab865172a9263271506a840de9fec2f96b4d73795e600680b9ec1de1bc67
|
data/CHANGELOG
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
*0.10.1* (Feb 11, 2016)
|
2
|
+
|
3
|
+
- Changed so that gem wont include images and tests.
|
4
|
+
|
5
|
+
*0.10.0* (Feb 11, 2016)
|
6
|
+
|
7
|
+
- Merged as_ansi by [Andy Brody](https://github.com/ab)
|
8
|
+
|
9
|
+
*0.8.2* (Jan 3, 2016)
|
10
|
+
|
11
|
+
- Fix source encoding problem introduced in 0.8.1
|
12
|
+
|
13
|
+
*0.9.0* (Jan 3, 2016)
|
14
|
+
|
15
|
+
- Added support for auto selecting qrcode size up to level 40. (only worked up to level 10 before)
|
16
|
+
- Added numeric support during auto selection of qrcode mode.
|
17
|
+
|
18
|
+
*0.8.1* (Jan 3, 2016)
|
19
|
+
|
20
|
+
- Remove active support specific `present?`.
|
21
|
+
- Fix so that all tests are run.
|
22
|
+
|
23
|
+
*0.8.0* (Dec 18, 2015)
|
24
|
+
|
25
|
+
- Added numeric QR code support
|
26
|
+
- Dropped Ruby v1.8 support
|
27
|
+
|
28
|
+
*0.7.0* (Aug 15, 2015)
|
29
|
+
|
30
|
+
- Added shape_rendering option for as_svg
|
31
|
+
|
32
|
+
*0.6.0* (Jun 2, 2015)
|
33
|
+
|
34
|
+
- Improved png rendering. Previous png rendering could result in hard to scan qrcodes.
|
35
|
+
*Big thanks to Bart Jedrocha*
|
36
|
+
|
37
|
+
*0.5.5* (Apr 25, 2015)
|
38
|
+
|
39
|
+
- Fixed major bug. The rs block data was missing resulting in qr codes failing to be generated.
|
40
|
+
*Upgrade highly recomended!!*
|
41
|
+
|
42
|
+
*0.5.4* (Nov 11th, 2013)
|
43
|
+
|
44
|
+
* Added as_html, Big thanks to Jon Evans!
|
45
|
+
|
46
|
+
*0.4.2* (Sep 1st, 2011)
|
47
|
+
|
48
|
+
* Proper namespace CoreExtensions and only extend when needed [https://github.com/metaskills]
|
49
|
+
* fix for running tests on 1.9
|
50
|
+
|
51
|
+
*0.4.1* (Aug 16th, 2011)
|
52
|
+
|
53
|
+
* Compute common patterns only once (5% to 10% speedup) [https://github.com/gioele]
|
54
|
+
|
55
|
+
*0.4.0* (Aug 13th, 2011)
|
56
|
+
|
57
|
+
* Code optimization: 30% speedup [https://github.com/gioele]
|
58
|
+
* refactor gem layout
|
59
|
+
|
60
|
+
*0.3.4* (May 23rd, 2011)
|
61
|
+
|
62
|
+
* add the more Rubyish QRCode#dark? alias for #is_dark [https://github.com/dasch]
|
63
|
+
|
64
|
+
*0.3.3* (Feb 1st, 2011)
|
65
|
+
|
66
|
+
* check to see if the level is valid
|
67
|
+
* fix for 'rszf' bug by [Rob la Lau https://github.com/ohreally]
|
68
|
+
|
69
|
+
*0.3.2* (Mar 15th, 2009)
|
70
|
+
|
71
|
+
* Ruby 1.9 fixes by [Tore Darell http://tore.darell.no] [Chris Mowforth http://blog.99th.st]
|
72
|
+
|
73
|
+
*0.3.1* (Nov 24th, 2008)
|
74
|
+
|
75
|
+
* expanded RS block table to QRcode version 40 [Vladislav Gorodetskiy]
|
76
|
+
|
77
|
+
*0.3.0* (Feb 28th, 2008)
|
78
|
+
|
79
|
+
* added more documentation
|
80
|
+
* changed to_console to to_s (what was I thinking)
|
81
|
+
* add more tests
|
82
|
+
|
83
|
+
*0.2.1* (Feb 24th, 2008)
|
84
|
+
|
85
|
+
* small changes to rakefile and readme
|
86
|
+
* small change to to_console method
|
87
|
+
* make console_count method private (use modules.size instead)
|
88
|
+
* slowy updating rdocs
|
89
|
+
|
90
|
+
*0.2.0* (Feb 23rd, 2008)
|
91
|
+
|
92
|
+
* Split files up [DR]
|
93
|
+
* added rdoc comment ... more to do there
|
94
|
+
|
95
|
+
*0.1.0* (Feb 22rd, 2008)
|
96
|
+
|
97
|
+
* Initial Release [DR]
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2008 Duncan Robertson
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to
|
5
|
+
deal in the Software without restriction, including without limitation the
|
6
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
7
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
16
|
+
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
19
|
+
|
data/README.md
ADDED
@@ -0,0 +1,230 @@
|
|
1
|
+
# rQRCode, Encode QRCodes
|
2
|
+
|
3
|
+
[](https://travis-ci.org/whomwah/rqrcode)
|
4
|
+
|
5
|
+
**All users of rqrcode are highly recomended to upgrade to version 0.5.5 ore later!**
|
6
|
+
|
7
|
+
## Short changelog
|
8
|
+
|
9
|
+
*0.10.1* (Feb 11, 2016)
|
10
|
+
|
11
|
+
- Changed so that gem wont include images and tests.
|
12
|
+
|
13
|
+
*0.10.0* (Feb 11, 2016)
|
14
|
+
|
15
|
+
- Merged as_ansi by [Andy Brody](https://github.com/ab)
|
16
|
+
|
17
|
+
*0.9.0* (Jan 3, 2016)
|
18
|
+
|
19
|
+
- Added support for auto selecting qrcode size up to level 40. (only worked up to level 10 before)
|
20
|
+
- Added numeric support during auto selection of qrcode mode.
|
21
|
+
|
22
|
+
*0.8.1* (Jan 3, 2016)
|
23
|
+
|
24
|
+
- Remove active support specific `present?`.
|
25
|
+
- Fix so that all tests are run.
|
26
|
+
|
27
|
+
*0.8.0* (Dec 18, 2015)
|
28
|
+
|
29
|
+
- Added numeric QR code support
|
30
|
+
- Dropped Ruby v1.8 support
|
31
|
+
|
32
|
+
## Overview
|
33
|
+
|
34
|
+
rQRCode is a library for encoding QR Codes in Ruby. It has a simple interface with all the standard qrcode options. It was adapted from the Javascript library by Kazuhiko Arase.
|
35
|
+
|
36
|
+
Let's clear up some rQRCode stuff.
|
37
|
+
|
38
|
+
* rQRCode is a __ruby only library__ It requires no native libraries. Just Ruby!
|
39
|
+
* It is an encoding library. You can't decode QR codes with it.
|
40
|
+
* The interface is simple and assumes you just want to encode a string into a QR code
|
41
|
+
* QR code is trademarked by Denso Wave inc
|
42
|
+
|
43
|
+
## Installing
|
44
|
+
|
45
|
+
You may get the latest stable version from Rubygems.
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
gem install rqrcode
|
49
|
+
```
|
50
|
+
|
51
|
+
## Using rQRCode
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
require 'rqrcode'
|
55
|
+
|
56
|
+
qrcode = RQRCode::QRCode.new("http://github.com/")
|
57
|
+
image = qrcode.as_png
|
58
|
+
svg = qrcode.as_svg
|
59
|
+
html = qrcode.as_html
|
60
|
+
string = qrcode.as_ansi
|
61
|
+
string = qrcode.to_s
|
62
|
+
gerber = qrcode.as_gerber
|
63
|
+
```
|
64
|
+
|
65
|
+
## Image Rendering
|
66
|
+
### SVG
|
67
|
+
|
68
|
+
The SVG renderer will produce a stand-alone SVG as a `String`
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
qrcode = RQRCode::QRCode.new("http://github.com/")
|
72
|
+
# With default options specified explicitly
|
73
|
+
svg = qrcode.as_svg(offset: 0, color: '000',
|
74
|
+
shape_rendering: 'crispEdges',
|
75
|
+
module_size: 11)
|
76
|
+
```
|
77
|
+
|
78
|
+

|
79
|
+
|
80
|
+
### ANSI
|
81
|
+
|
82
|
+
The ANSI renderer will produce as a string with ANSI color codes.
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
qrcode = RQRCode::QRCode.new("http://github.com/")
|
86
|
+
# With default options specified explicitly
|
87
|
+
svg = qrcode.as_ansi_(light: "\033[47m", dark: "\033[40m",
|
88
|
+
fill_character: ' ',
|
89
|
+
quiet_zone_size: 4)
|
90
|
+
```
|
91
|
+
|
92
|
+

|
93
|
+
|
94
|
+
### PNG
|
95
|
+
|
96
|
+
The library can produce a PNG. Result will be a `ChunkyPNG::Image` instance.
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
qrcode = RQRCode::QRCode.new("http://github.com/")
|
100
|
+
# With default options specified explicitly
|
101
|
+
png = qrcode.as_png(
|
102
|
+
resize_gte_to: false,
|
103
|
+
resize_exactly_to: false,
|
104
|
+
fill: 'white',
|
105
|
+
color: 'black',
|
106
|
+
size: 120,
|
107
|
+
border_modules: 4,
|
108
|
+
module_px_size: 6,
|
109
|
+
file: nil # path to write
|
110
|
+
)
|
111
|
+
IO.write("/tmp/github-qrcode.png", png.to_s)
|
112
|
+
```
|
113
|
+
|
114
|
+

|
115
|
+
|
116
|
+
### Gerber / RS-274x
|
117
|
+
qrcode = RQRCode::QRcode.new("http://github.com/")
|
118
|
+
gerber = qrcode.as_gerber(
|
119
|
+
precision: 6,
|
120
|
+
pixel_width: 0.010, # inches
|
121
|
+
x_origin: 0.000, # inches
|
122
|
+
y_origin: 0.000, # inches
|
123
|
+
quiet_zone_size: 1,
|
124
|
+
mirrored: false
|
125
|
+
)
|
126
|
+
IO.write("qrcode.ger, gerber)
|
127
|
+
|
128
|
+
## HTML Rendering
|
129
|
+
### In your controller
|
130
|
+
```ruby
|
131
|
+
@qr = RQRCode::QRCode.new( 'https://github.com/whomwah/rqrcode', :size => 4, :level => :h )
|
132
|
+
```
|
133
|
+
|
134
|
+
### In your view
|
135
|
+
```html
|
136
|
+
<%= raw @qr.as_html %>
|
137
|
+
```
|
138
|
+
|
139
|
+
### CSS
|
140
|
+
```css
|
141
|
+
table {
|
142
|
+
border-width: 0;
|
143
|
+
border-style: none;
|
144
|
+
border-color: #0000ff;
|
145
|
+
border-collapse: collapse;
|
146
|
+
}
|
147
|
+
|
148
|
+
td {
|
149
|
+
border-left: solid 10px #000;
|
150
|
+
padding: 0;
|
151
|
+
margin: 0;
|
152
|
+
width: 0px;
|
153
|
+
height: 10px;
|
154
|
+
}
|
155
|
+
|
156
|
+
td.black { border-color: #000; }
|
157
|
+
td.white { border-color: #fff; }
|
158
|
+
```
|
159
|
+
|
160
|
+
## On the console
|
161
|
+
|
162
|
+
```ruby
|
163
|
+
qr = RQRCode::QRCode.new( 'my string to generate', :size => 4, :level => :h )
|
164
|
+
puts qr.to_s
|
165
|
+
```
|
166
|
+
|
167
|
+
Output:
|
168
|
+
|
169
|
+
```
|
170
|
+
xxxxxxx x x x x x xx xxxxxxx
|
171
|
+
x x xxx xxxxxx xxx x x
|
172
|
+
x xxx x xxxxx x xx x xxx x
|
173
|
+
... etc
|
174
|
+
```
|
175
|
+
|
176
|
+
## Doing your own rendering
|
177
|
+
```ruby
|
178
|
+
qr = RQRCode::QRCode.new( 'my string to generate', :size => 4, :level => :h )
|
179
|
+
qr.modules.each do |row|
|
180
|
+
row.each do |col|
|
181
|
+
print col ? "X" : " "
|
182
|
+
end
|
183
|
+
print "\n"
|
184
|
+
end
|
185
|
+
```
|
186
|
+
|
187
|
+
## Specifying QR code mode
|
188
|
+
|
189
|
+
Sometimes you may want to specify the QR code mode explicitly.
|
190
|
+
|
191
|
+
It is done via the `mode` option. Allowed values are: `number`, `alphanumeric` and `byte_8bit`.
|
192
|
+
|
193
|
+
```ruby
|
194
|
+
qr = RQRCode::QRCode.new( '1234567890', :size => 2, :level => :m, :mode => :number )
|
195
|
+
```
|
196
|
+
|
197
|
+
|
198
|
+
## API Documentation
|
199
|
+
|
200
|
+
[http://www.rubydoc.info/gems/rqrcode](http://www.rubydoc.info/gems/rqrcode)
|
201
|
+
|
202
|
+
## Resources
|
203
|
+
|
204
|
+
* wikipedia:: http://en.wikipedia.org/wiki/QR_Code
|
205
|
+
* Denso-Wave website:: http://www.denso-wave.com/qrcode/index-e.html
|
206
|
+
* kaywa:: http://qrcode.kaywa.com
|
207
|
+
|
208
|
+
## Authors
|
209
|
+
|
210
|
+
Original author: Duncan Robertson
|
211
|
+
|
212
|
+
Special thanks to the following people for submitting patches:
|
213
|
+
|
214
|
+
* [Andy Brody](https://github.com/ab)
|
215
|
+
* [Chris Mowforth](http://blog.99th.st)
|
216
|
+
* [Daniel Schierbeck](https://github.com/dasch)
|
217
|
+
* [Gioele Barabucci](https://github.com/gioele)
|
218
|
+
* [Ken Collins](https://github.com/metaskills)
|
219
|
+
* [Rob la Lau](https://github.com/ohreally)
|
220
|
+
* [Tore Darell](http://tore.darell.no)
|
221
|
+
* Vladislav Gorodetskiy
|
222
|
+
|
223
|
+
## Contributing
|
224
|
+
* Fork the project
|
225
|
+
* Send a pull request
|
226
|
+
* Don't touch the .gemspec, I'll do that when I release a new version
|
227
|
+
|
228
|
+
## Copyright
|
229
|
+
|
230
|
+
MIT License (http://www.opensource.org/licenses/mit-license.html)
|
data/lib/rqrcode.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
#--
|
4
|
+
# Copyright 2008 by Duncan Robertson (duncan@whomwah.com).
|
5
|
+
# All rights reserved.
|
6
|
+
|
7
|
+
# Permission is granted for use, copying, modification, distribution,
|
8
|
+
# and distribution of modified versions of this work as long as the
|
9
|
+
# above copyright notice is included.
|
10
|
+
#++
|
11
|
+
|
12
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
13
|
+
|
14
|
+
require "rqrcode/core_ext"
|
15
|
+
require "rqrcode/qrcode"
|
16
|
+
require 'rqrcode/export/png'
|
17
|
+
require 'rqrcode/export/svg'
|
18
|
+
require 'rqrcode/export/html'
|
19
|
+
require 'rqrcode/export/ansi'
|
20
|
+
require 'rqrcode/export/gerber'
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module RQRCode
|
2
|
+
module Export
|
3
|
+
module ANSI
|
4
|
+
##
|
5
|
+
# Returns a string of the QR code as
|
6
|
+
# characters writen with ANSI background set.
|
7
|
+
#
|
8
|
+
# Options:
|
9
|
+
# light: Foreground ("\033[47m")
|
10
|
+
# dark: Background ANSI code. ("\033[47m")
|
11
|
+
# fill_character: The written character. (' ')
|
12
|
+
# quiet_zone_size: (4)
|
13
|
+
#
|
14
|
+
def as_ansi(options={})
|
15
|
+
options = {
|
16
|
+
light: "\033[47m",
|
17
|
+
dark: "\033[40m",
|
18
|
+
fill_character: ' ',
|
19
|
+
quiet_zone_size: 4
|
20
|
+
}.merge(options)
|
21
|
+
|
22
|
+
normal = "\033[m"
|
23
|
+
light = options.fetch(:light)
|
24
|
+
dark = options.fetch(:dark)
|
25
|
+
fill_character = options.fetch(:fill_character)
|
26
|
+
quiet_zone_size = options.fetch(:quiet_zone_size)
|
27
|
+
|
28
|
+
output = ''
|
29
|
+
|
30
|
+
@modules.each_index do |c|
|
31
|
+
|
32
|
+
# start row with quiet zone
|
33
|
+
row = light + fill_character * quiet_zone_size
|
34
|
+
previous_dark = false
|
35
|
+
|
36
|
+
@modules.each_index do |r|
|
37
|
+
if is_dark(c, r)
|
38
|
+
# dark
|
39
|
+
if previous_dark != true
|
40
|
+
row << dark
|
41
|
+
previous_dark = true
|
42
|
+
end
|
43
|
+
row << fill_character
|
44
|
+
else
|
45
|
+
# light
|
46
|
+
if previous_dark != false
|
47
|
+
row << light
|
48
|
+
previous_dark = false
|
49
|
+
end
|
50
|
+
row << fill_character
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# add quiet zone
|
55
|
+
if previous_dark != false
|
56
|
+
row << light
|
57
|
+
end
|
58
|
+
row << fill_character * quiet_zone_size
|
59
|
+
|
60
|
+
# always end with reset and newline
|
61
|
+
row << normal + "\n"
|
62
|
+
|
63
|
+
output << row
|
64
|
+
end
|
65
|
+
|
66
|
+
# count the row width so we can add quiet zone rows
|
67
|
+
width = output.each_line.first.scan(fill_character).length
|
68
|
+
|
69
|
+
quiet_row = light + fill_character * width + normal + "\n"
|
70
|
+
quiet_rows = quiet_row * quiet_zone_size
|
71
|
+
|
72
|
+
return quiet_rows + output + quiet_rows
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
RQRCode::QRCode.send :include, RQRCode::Export::ANSI
|