rqrcode 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7559f2004d53b9642306d26b1b95926564216889
4
- data.tar.gz: df2bbd25ba80e1975f52dfc0bc354cfff547d17f
3
+ metadata.gz: 1275547d28967654aa0f1ba1a450c5daa31c582a
4
+ data.tar.gz: c6ae31e4cdea2370f20a147cbc6f41f6d7d2fdc6
5
5
  SHA512:
6
- metadata.gz: 814b04bb242a2ee751eafdeb102ef95d8cf53be4c9d71fc7577b1a225fd5fccd702ca19b4f641f0bb3ca150213a7c9e8635e3e9ddb2e3808c8355689465a1a4a
7
- data.tar.gz: fdf2cbd54b99a59c1085707799718c84c3f8d28ad0a11754914fa9cece4ecfd4659e23af8faaa8830580296a5e2dece5b32e128461679f5735db865f4aec8e46
6
+ metadata.gz: 916f34ba9af9afffbfd8ba55116fc130b32a3ffb89db779da2af89df0c167fe49138fd625a33f1f48d648729ae488742921b2dfa10f6349743ff9ac7d865f7e3
7
+ data.tar.gz: 6ebffce16883fcf0951c6bd601915e1335a709b216cfa2255e1c56b45e496e42b301724f117d81134f403a93960d743b7eb3676239584562622eec216a33226e
@@ -1,9 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.0
4
- - 2.1.0
3
+ - 2.2.2
4
+ - 2.1.6
5
5
  - 2.0.0
6
6
  - 1.9.3
7
7
  - 1.8.7
8
8
  - jruby-18mode
9
- - jruby-19mode
9
+ - jruby-19mode
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ *0.7.0* (Aug 15, 2015)
2
+
3
+ - Added shape_rendering option for as_svg
4
+
1
5
  *0.6.0* (Jun 2, 2015)
2
6
 
3
7
  - Improved png rendering. Previous png rendering could result in hard to scan qrcodes.
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem "chunky_png", ~> "1.0"
3
+ gem "chunky_png", "~> 1.0"
4
4
 
5
5
  group :test, :development do
6
6
  gem 'rake'
data/README.md CHANGED
@@ -4,6 +4,10 @@
4
4
 
5
5
  ## Short changelog
6
6
 
7
+ *0.7.0* (Aug 15, 2015)
8
+
9
+ - Added shape_rendering option for as_svg
10
+
7
11
  *0.6.0* (Jun 2, 2015)
8
12
 
9
13
  - Improved png rendering. Previous png rendering could result in hard to scan qrcodes.
@@ -25,128 +29,127 @@ Let's clear up some rQRCode stuff.
25
29
  * The interface is simple and assumes you just want to encode a string into a QR code
26
30
  * QR code is trademarked by Denso Wave inc
27
31
 
28
- ## Resources
29
-
30
- * wikipedia:: http://en.wikipedia.org/wiki/QR_Code
31
- * Denso-Wave website:: http://www.denso-wave.com/qrcode/index-e.html
32
- * kaywa:: http://qrcode.kaywa.com
33
-
34
32
  ## Installing
35
33
 
36
34
  You may get the latest stable version from Rubygems.
37
35
 
38
- gem install rqrcode
39
-
40
- You can also get the latest source from https://github.com/whomwah/rqrcode
36
+ ```ruby
37
+ gem install rqrcode
38
+ ```
41
39
 
42
- git clone git://github.com/whomwah/rqrcode.git
40
+ ## Using rQRCode
43
41
 
44
- ## Tests
42
+ ```ruby
43
+ require 'rqrcode'
45
44
 
46
- To run the tests:
45
+ qrcode = RQRCode::QRCode.new("http://github.com/")
46
+ image = qrcode.as_png
47
+ svg = qrcode.as_svg
48
+ html = qrcode.as_html
49
+ string = qrcode.to_s
50
+ ```
47
51
 
48
- $ rake
52
+ ## Image Rendering
53
+ ### SVG
49
54
 
50
- ## Loading rQRCode Itself
55
+ The SVG renderer will produce a stand-alone SVG as a `String`
51
56
 
52
- You have installed the gem already, yeah?
57
+ ```ruby
58
+ qrcode = RQRCode::QRCode.new("http://github.com/")
59
+ # With default options specified explicitly
60
+ svg = qrcode.as_svg(offset: 0, color: '000',
61
+ shape_rendering: 'crispEdges',
62
+ module_size: 11)
63
+ ```
53
64
 
54
- require 'rubygems'
55
- require 'rqrcode'
65
+ ### PNG
56
66
 
57
- ## Simple QRCode generation to screen
67
+ The library can produce a PNG. Result will be a `ChunkyPNG::Image` instance.
58
68
 
59
69
  ```ruby
60
- qr = RQRCode::QRCode.new( 'my string to generate', :size => 4, :level => :h )
61
- puts qr.to_s
62
- #
63
- # Prints:
64
- # xxxxxxx x x x x x xx xxxxxxx
65
- # x x xxx xxxxxx xxx x x
66
- # x xxx x xxxxx x xx x xxx x
67
- # ... etc
70
+ qrcode = RQRCode::QRCode.new("http://github.com/")
71
+ # With default options specified explicitly
72
+ png = qrcode.as_png(
73
+ resize_gte_to: false,
74
+ resize_exactly_to: false,
75
+ fill: 'white',
76
+ color: 'black',
77
+ size: 120,
78
+ border_modules: 4,
79
+ file: false,
80
+ module_px_size: 6,
81
+ output_file: nil # path to write
82
+ )
68
83
  ```
69
84
 
70
- ## Simple QRCode generation to template (RubyOnRails)
71
- ### Controller
85
+ ## HTML Rendering
86
+ ### In your controller
72
87
  ```ruby
73
- @qr = RQRCode::QRCode.new( 'my string to generate', :size => 4, :level => :h )
88
+ @qr = RQRCode::QRCode.new( 'https://github.com/whomwah/rqrcode', :size => 4, :level => :h )
74
89
  ```
75
- ### View: (minimal styling added)
76
- ```erb
77
- <style type="text/css">
90
+
91
+ ### In your view
92
+ ```html
93
+ <%= raw @qr.as_html %>
94
+ ```
95
+
96
+ ### CSS
97
+ ```css
78
98
  table {
79
99
  border-width: 0;
80
100
  border-style: none;
81
101
  border-color: #0000ff;
82
102
  border-collapse: collapse;
83
103
  }
104
+
84
105
  td {
85
- border-width: 0;
86
- border-style: none;
87
- border-color: #0000ff;
88
- border-collapse: collapse;
89
- padding: 0;
90
- margin: 0;
91
- width: 10px;
92
- height: 10px;
106
+ border-left: solid 10px #000;
107
+ padding: 0;
108
+ margin: 0;
109
+ width: 0px;
110
+ height: 10px;
93
111
  }
94
- td.black { background-color: #000; }
95
- td.white { background-color: #fff; }
96
- </style>
97
112
 
98
- <%= raw @qr.as_html %>
113
+ td.black { border-color: #000; }
114
+ td.white { border-color: #fff; }
99
115
  ```
116
+
117
+ ## On the console
100
118
 
101
- If you want to generate the HTML manually for customization, you can start with the following:
102
-
103
- ```erb
104
- <table>
105
- <% @qr.modules.each_index do |x| %>
106
- <tr>
107
- <% @qr.modules.each_index do |y| %>
108
- <% if @qr.dark?(x,y) %>
109
- <td class="black"/>
110
- <% else %>
111
- <td class="white"/>
112
- <% end %>
113
- <% end %>
114
- </tr>
115
- <% end %>
116
- </table>
119
+ ```ruby
120
+ qr = RQRCode::QRCode.new( 'my string to generate', :size => 4, :level => :h )
121
+ puts qr.to_s
117
122
  ```
118
123
 
119
- ## Exporting
120
-
121
- You can also require optional export features:
124
+ Output:
122
125
 
123
- * SVG -> no dependencies
124
- * PNG -> depends on 'chunky_png' gem
125
- * JPG -> depends on 'mini_magick' gem
126
-
127
- Example to render png:
126
+ ```
127
+ xxxxxxx x x x x x xx xxxxxxx
128
+ x x xxx xxxxxx xxx x x
129
+ x xxx x xxxxx x xx x xxx x
130
+ ... etc
131
+ ```
128
132
 
133
+ ## Doing your own rendering
129
134
  ```ruby
130
- require 'rqrcode/export/png'
131
- image = RQRCode::QRCode.new("nice qr").as_png
135
+ qr = RQRCode::QRCode.new( 'my string to generate', :size => 4, :level => :h )
136
+ qr.modules.each do |row|
137
+ row.each do |col|
138
+ print col ? "X" : " "
139
+ end
140
+ print "\n"
141
+ end
132
142
  ```
133
143
 
134
- Notice the 'as\_png'. Same goes for 'as\_svg', 'as\_xxx'.
135
-
136
- ### Export Options
144
+ ## API Documentation
137
145
 
138
- Exporters support these options:
146
+ [http://www.rubydoc.info/gems/rqrcode](http://www.rubydoc.info/gems/rqrcode)
139
147
 
140
- * size - Image size, in pixels.
141
- * fill - Background color, defaults to 'white'
142
- * color - Foreground color, defaults to 'black'
143
-
144
- SVG Export supports the parameter `module_size` to generate smaller or larger QR Codes
148
+ ## Resources
145
149
 
146
- ```ruby
147
- require 'rqrcode/export/svg'
148
- svg = RQRCode::QRCode.new("nice qr").as_svg(:module_size => 6)
149
- ```
150
+ * wikipedia:: http://en.wikipedia.org/wiki/QR_Code
151
+ * Denso-Wave website:: http://www.denso-wave.com/qrcode/index-e.html
152
+ * kaywa:: http://qrcode.kaywa.com
150
153
 
151
154
  ## Authors
152
155
 
data/TODO.md CHANGED
@@ -1,3 +1,4 @@
1
+ - Add to_ansi rendering_
1
2
  - Add Numeric mode
2
3
  - Add Kanji mode
3
4
  - Add ECI Mode
@@ -11,7 +11,7 @@ module RQRCode
11
11
  # There are two sizing algoritams.
12
12
  #
13
13
  # - Original that can result in blurry and hard to scan images
14
- # - Google's Chart API inspired sizing that risizes the module size to fit within the given image size.
14
+ # - Google's Chart API inspired sizing that resizes the module size to fit within the given image size.
15
15
  #
16
16
  # The Googleis one will be used when no options are given or when the new size option is used.
17
17
  #
@@ -3,24 +3,28 @@
3
3
  module RQRCode
4
4
  module Export
5
5
 
6
- # Render the SVG from the Qrcode.
7
- #
8
- # Options:
9
- # offset - Padding around the QR Code (e.g. 10)
10
- # fill - Background color (e.g "ffffff" or :white)
11
- # color - Foreground color for the code (e.g. "000000" or :black)
12
- # module_size - The Pixel size of each module (e.g. 11)
13
6
  module SVG
7
+
8
+ # Render the SVG from the Qrcode.
9
+ #
10
+ # Options:
11
+ # offset - Padding around the QR Code (e.g. 10)
12
+ # fill - Background color (e.g "ffffff" or :white)
13
+ # color - Foreground color for the code (e.g. "000000" or :black)
14
+ # module_size - The Pixel size of each module (e.g. 11)
15
+ # shape_rendering - Defaults to crispEdges
16
+ #
14
17
  def as_svg(options={})
15
18
  offset = options[:offset].to_i || 0
16
19
  color = options[:color] || "000"
20
+ shape_rendering = options[:shape_rendering] || "crispEdges"
17
21
  module_size = options[:module_size] || 11
18
22
 
19
23
  # height and width dependent on offset and QR complexity
20
24
  dimension = (self.module_count*module_size) + (2*offset)
21
25
 
22
26
  xml_tag = %{<?xml version="1.0" standalone="yes"?>}
23
- open_tag = %{<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ev="http://www.w3.org/2001/xml-events" width="#{dimension}" height="#{dimension}">}
27
+ open_tag = %{<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ev="http://www.w3.org/2001/xml-events" width="#{dimension}" height="#{dimension}" shape-rendering="#{shape_rendering}">}
24
28
  close_tag = "</svg>"
25
29
 
26
30
  result = []
@@ -121,6 +121,10 @@ module RQRCode #:nodoc:
121
121
 
122
122
  max_size_array = QRMAXDIGITS[level][mode]
123
123
  size = options[:size] || smallest_size_for(string, max_size_array)
124
+
125
+ if size > QRUtil.max_size
126
+ raise QRCodeArgumentError, "Given size greater than maximum possible size of #{QRUtil.max_size}"
127
+ end
124
128
 
125
129
  @error_correct_level = QRERRORCORRECTLEVEL[level]
126
130
  @version = size
@@ -160,31 +164,32 @@ module RQRCode #:nodoc:
160
164
  # x x xxx xxxxxx xxx x x
161
165
  # x xxx x xxxxx x xx x xxx x
162
166
  #
163
- # instance._to_s( :true => 'E', :false => 'Q') =>
167
+ # instance._to_s( :dark => 'E', :light => 'Q') =>
164
168
  # EEEEEEEQEQQEQEQQQEQEQQEEQQEEEEEEE
165
169
  # EQQQQQEQQEEEQQEEEEEEQEEEQQEQQQQQE
166
170
  # EQEEEQEQQEEEEEQEQQQQQQQEEQEQEEEQE
167
171
  #
168
-
169
172
  def to_s( *args )
170
173
  options = args.extract_options!
171
- row = options[:true] || 'x'
172
- col = options[:false] || ' '
173
-
174
- res = []
175
-
176
- @modules.each_index do |c|
177
- tmp = []
178
- @modules.each_index do |r|
179
- if is_dark(c,r)
180
- tmp << row
181
- else
182
- tmp << col
183
- end
174
+ dark = options[:dark] || options[:true] || 'x'
175
+ light = options[:light] || options[:false] || ' '
176
+ quiet_zone_size = options[:quiet_zone_size] || 0
177
+
178
+ rows = []
179
+
180
+ @modules.each do |row|
181
+ cols = light * quiet_zone_size
182
+ row.each do |col|
183
+ cols += (col ? dark : light)
184
184
  end
185
- res << tmp.join
186
- end
187
- res.join("\n")
185
+ rows << cols
186
+ end
187
+
188
+ quiet_zone_size.times do
189
+ rows.unshift(light * (rows.first.length / light.size))
190
+ rows << light * (rows.first.length / light.size)
191
+ end
192
+ rows.join("\n")
188
193
  end
189
194
 
190
195
  protected
@@ -392,7 +397,7 @@ module RQRCode #:nodoc:
392
397
  buffer.end_of_message(max_data_bits)
393
398
 
394
399
  if buffer.get_length_in_bits > max_data_bits
395
- raise QRCodeRunTimeError, "code length overflow. (#{buffer.get_length_in_bits}>#{max_data_bits})"
400
+ raise QRCodeRunTimeError, "code length overflow. (#{buffer.get_length_in_bits}>#{max_data_bits}). (Try a larger size!)"
396
401
  end
397
402
 
398
403
  buffer.pad_until(max_data_bits)
@@ -73,6 +73,10 @@ module RQRCode #:nodoc:
73
73
  QRMODE[:mode_kanji] => [8, 10, 12],
74
74
  }
75
75
 
76
+ def QRUtil.max_size
77
+ PATTERN_POSITION_TABLE.count
78
+ end
79
+
76
80
  def QRUtil.get_bch_format_info( data )
77
81
  d = data << 10
78
82
  while QRUtil.get_bch_digit(d) - QRUtil.get_bch_digit(G15) >= 0
@@ -1,3 +1,3 @@
1
1
  module RQRCode
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -101,6 +101,12 @@ class QRCodeTest < Test::Unit::TestCase
101
101
  assert RQRCode::QRCode.new("40952", :size => 1, :level => :h)
102
102
  assert RQRCode::QRCode.new("40932", :size => 1, :level => :h)
103
103
  end
104
+
105
+ def test_exceed_max_size
106
+ assert_raise RQRCode::QRCodeArgumentError do
107
+ RQRCode::QRCode.new( 'duncan', :size => 41 )
108
+ end
109
+ end
104
110
 
105
111
  def test_levels
106
112
  assert RQRCode::QRCode.new("duncan", :level => :l)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rqrcode
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Björn Blomqvist
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-06-03 00:00:00.000000000 Z
12
+ date: 2015-08-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chunky_png
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  version: 1.3.6
118
118
  requirements: []
119
119
  rubyforge_project:
120
- rubygems_version: 2.1.11
120
+ rubygems_version: 2.4.8
121
121
  signing_key:
122
122
  specification_version: 4
123
123
  summary: A library to encode QR Codes