rqrcode-with-patches 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ /pkg/
2
+ .rvmrc
3
+ Gemfile.lock
data/CHANGELOG ADDED
@@ -0,0 +1,52 @@
1
+ *0.4.2* (Sep 1st, 2011)
2
+
3
+ * Proper namespace CoreExtensions and only extend when needed [https://github.com/metaskills]
4
+ * fix for running tests on 1.9
5
+
6
+ *0.4.1* (Aug 16th, 2011)
7
+
8
+ * Compute common patterns only once (5% to 10% speedup) [https://github.com/gioele]
9
+
10
+ *0.4.0* (Aug 13th, 2011)
11
+
12
+ * Code optimization: 30% speedup [https://github.com/gioele]
13
+ * refactor gem layout
14
+
15
+ *0.3.4* (May 23rd, 2011)
16
+
17
+ * add the more Rubyish QRCode#dark? alias for #is_dark [https://github.com/dasch]
18
+
19
+ *0.3.3* (Feb 1st, 2011)
20
+
21
+ * check to see if the level is valid
22
+ * fix for 'rszf' bug by [Rob la Lau https://github.com/ohreally]
23
+
24
+ *0.3.2* (Mar 15th, 2009)
25
+
26
+ * Ruby 1.9 fixes by [Tore Darell http://tore.darell.no] [Chris Mowforth http://blog.99th.st]
27
+
28
+ *0.3.1* (Nov 24th, 2008)
29
+
30
+ * expanded RS block table to QRcode version 40 [Vladislav Gorodetskiy]
31
+
32
+ *0.3.0* (Feb 28th, 2008)
33
+
34
+ * added more documentation
35
+ * changed to_console to to_s (what was I thinking)
36
+ * add more tests
37
+
38
+ *0.2.1* (Feb 24th, 2008)
39
+
40
+ * small changes to rakefile and readme
41
+ * small change to to_console method
42
+ * make console_count method private (use modules.size instead)
43
+ * slowy updating rdocs
44
+
45
+ *0.2.0* (Feb 23rd, 2008)
46
+
47
+ * Split files up [DR]
48
+ * added rdoc comment ... more to do there
49
+
50
+ *0.1.0* (Feb 22rd, 2008)
51
+
52
+ * Initial Release [DR]
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'http://rubygems.org'
2
+ gemspec
3
+
4
+
5
+ gem "chunky_png"
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,147 @@
1
+ # rQRCode, Encode QRCodes
2
+
3
+ I have republished this gem as rqrcode-with-patches as Duncan seams to have abandoned the project.
4
+
5
+ ## Overview
6
+
7
+ 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.
8
+
9
+ Let's clear up some rQRCode stuff.
10
+
11
+ * rQRCode is a __standalone library__ It requires no other libraries. Just Ruby!
12
+ * It is an encoding library. You can't decode QR codes with it.
13
+ * The interface is simple and assumes you just want to encode a string into a QR code
14
+ * QR code is trademarked by Denso Wave inc
15
+
16
+ ## Resources
17
+
18
+ * wikipedia:: http://en.wikipedia.org/wiki/QR_Code
19
+ * Denso-Wave website:: http://www.denso-wave.com/qrcode/index-e.html
20
+ * kaywa:: http://qrcode.kaywa.com
21
+
22
+ ## Installing
23
+
24
+ You may get the latest stable version from Rubygems.
25
+
26
+ gem install rqrcode
27
+
28
+ You can also get the latest source from http://github.com/whomwah/rqrcode
29
+
30
+ git clone git://github.com/whomwah/rqrcode.git
31
+
32
+ ## Tests
33
+
34
+ To run the tests:
35
+
36
+ $ rake
37
+
38
+ ## Loading rQRCode Itself
39
+
40
+ You have installed the gem already, yeah?
41
+
42
+ require 'rubygems'
43
+ require 'rqrcode'
44
+
45
+ ## Simple QRCode generation to screen
46
+
47
+ ```ruby
48
+ qr = RQRCode::QRCode.new( 'my string to generate', :size => 4, :level => :h )
49
+ puts qr.to_s
50
+ #
51
+ # Prints:
52
+ # xxxxxxx x x x x x xx xxxxxxx
53
+ # x x xxx xxxxxx xxx x x
54
+ # x xxx x xxxxx x xx x xxx x
55
+ # ... etc
56
+ ```
57
+
58
+ ## Simple QRCode generation to template (RubyOnRails)
59
+ ### Controller
60
+ ```ruby
61
+ @qr = RQRCode::QRCode.new( 'my string to generate', :size => 4, :level => :h )
62
+ ```
63
+ ### View: (minimal styling added)
64
+ ```erb
65
+ <style type="text/css">
66
+ table {
67
+ border-width: 0;
68
+ border-style: none;
69
+ border-color: #0000ff;
70
+ border-collapse: collapse;
71
+ }
72
+ td {
73
+ border-width: 0;
74
+ border-style: none;
75
+ border-color: #0000ff;
76
+ border-collapse: collapse;
77
+ padding: 0;
78
+ margin: 0;
79
+ width: 10px;
80
+ height: 10px;
81
+ }
82
+ td.black { background-color: #000; }
83
+ td.white { background-color: #fff; }
84
+ </style>
85
+
86
+ <table>
87
+ <% @qr.modules.each_index do |x| %>
88
+ <tr>
89
+ <% @qr.modules.each_index do |y| %>
90
+ <% if @qr.dark?(x,y) %>
91
+ <td class="black"/>
92
+ <% else %>
93
+ <td class="white"/>
94
+ <% end %>
95
+ <% end %>
96
+ </tr>
97
+ <% end %>
98
+ </table>
99
+ ```
100
+
101
+ ## Exporting
102
+
103
+ You can also require optional export features:
104
+
105
+ * SVG -> no dependencies
106
+ * PNG -> depends on 'chunky_png' gem
107
+ * JPG -> depends on 'mini_magick' gem
108
+
109
+ Example to render png:
110
+
111
+ ```ruby
112
+ require 'rqrcode/export/png'
113
+ image = RQRCode::QRCode.new("nice qr").as_png
114
+ ```
115
+
116
+ Notice the 'as\_png'. Same goes for 'as\_svg', 'as\_xxx'.
117
+
118
+ ### Export Options
119
+
120
+ Exporters support these options:
121
+
122
+ * size - Image size, in pixels.
123
+ * fill - Background color, defaults to 'white'
124
+ * color - Foreground color, defaults to 'black'
125
+
126
+ ## Authors
127
+
128
+ Original author: Duncan Robertson
129
+
130
+ Special thanks to the following people for submitting patches:
131
+
132
+ * [Chris Mowforth](http://blog.99th.st)
133
+ * [Daniel Schierbeck](https://github.com/dasch)
134
+ * [Gioele Barabucci](https://github.com/gioele)
135
+ * [Ken Collins](https://github.com/metaskills)
136
+ * [Rob la Lau](https://github.com/ohreally)
137
+ * [Tore Darell](http://tore.darell.no)
138
+ * Vladislav Gorodetskiy
139
+
140
+ ## Contributing
141
+ * Fork the project
142
+ * Send a pull request
143
+ * Don't touch the .gemspec, I'll do that when I release a new version
144
+
145
+ ## Copyright
146
+
147
+ MIT Licence (http://www.opensource.org/licenses/mit-license.html)
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'rake/testtask'
2
+ require 'bundler'
3
+
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ desc "Run tests"
7
+ Rake::TestTask.new do |t|
8
+ t.libs << "lib"
9
+ t.libs << "test"
10
+ t.test_files = FileList['test/test_*.rb']
11
+ t.verbose = true
12
+ end
13
+
14
+ task :default => [:test]
data/lib/rqrcode.rb ADDED
@@ -0,0 +1,15 @@
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
+ require "rqrcode/core_ext"
13
+ require "rqrcode/qrcode"
14
+ require 'rqrcode/export/png'
15
+ require 'rqrcode/export/svg'
@@ -0,0 +1,5 @@
1
+ Dir[File.dirname(__FILE__) + "/core_ext/*.rb"].sort.each do |path|
2
+ filename = File.basename(path)
3
+ require "rqrcode/core_ext/#{filename}"
4
+ end
5
+
@@ -0,0 +1,5 @@
1
+ require 'rqrcode/core_ext/array/behavior'
2
+
3
+ class Array #:nodoc:
4
+ include RQRCode::CoreExtensions::Array::Behavior
5
+ end
@@ -0,0 +1,12 @@
1
+ module RQRCode
2
+ module CoreExtensions #:nodoc:
3
+ module Array #:nodoc:
4
+ module Behavior
5
+ def extract_options!
6
+ last.is_a?(::Hash) ? pop : {}
7
+ end unless [].respond_to?(:extract_options!)
8
+ end
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,5 @@
1
+ require 'rqrcode/core_ext/integer/bitwise'
2
+
3
+ class Integer #:nodoc:
4
+ include RQRCode::CoreExtensions::Integer::Bitwise
5
+ end
@@ -0,0 +1,13 @@
1
+ module RQRCode
2
+ module CoreExtensions #:nodoc:
3
+ module Integer #:nodoc:
4
+ module Bitwise
5
+ def rszf(count)
6
+ # zero fill right shift
7
+ (self >> count) & ((2 ** ((self.size * 8) - count))-1)
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+
@@ -0,0 +1,76 @@
1
+ require 'chunky_png'
2
+
3
+ # This class creates PNG files.
4
+ # Code from: https://github.com/DCarper/rqrcode
5
+ module RQRCode
6
+ module Export
7
+ module PNG
8
+
9
+ # Render the PNG from the Qrcode.
10
+ #
11
+ # Options:
12
+ # module_px_size - Image size, in pixels.
13
+ # fill - Background ChunkyPNG::Color, defaults to 'white'
14
+ # color - Foreground ChunkyPNG::Color, defaults to 'black'
15
+ # border - Border thickness, in pixels
16
+ #
17
+ # It first creates an image where 1px = 1 module, then resizes.
18
+ # Defaults to 90x90 pixels, customizable by option.
19
+ #
20
+ def as_png(options = {})
21
+
22
+ default_img_options = {
23
+ :resize_gte_to => false,
24
+ :resize_exactly_to => false,
25
+ :fill => 'white',
26
+ :color => 'black',
27
+ :border_modules => 4,
28
+ :file => false,
29
+ :module_px_size => 6
30
+ }
31
+ options = default_img_options.merge(options) # reverse_merge
32
+
33
+ fill = ChunkyPNG::Color(options[:fill])
34
+ color = ChunkyPNG::Color(options[:color])
35
+ output_file = options[:file]
36
+ border = options[:border_modules]
37
+ total_border = border * 2
38
+ module_px_size = if options[:resize_gte_to]
39
+ (options[:resize_gte_to].to_f / (self.module_count + total_border).to_f).ceil.to_i
40
+ else
41
+ options[:module_px_size]
42
+ end
43
+ border_px = border * module_px_size
44
+ total_border_px = border_px * 2
45
+ resize_to = options[:resize_exactly_to]
46
+
47
+ img_size = module_px_size * self.module_count
48
+ total_img_size = img_size + total_border_px
49
+
50
+ png = ChunkyPNG::Image.new(total_img_size, total_img_size, fill)
51
+
52
+ self.modules.each_index do |x|
53
+ self.modules.each_index do |y|
54
+ if self.dark?(x, y)
55
+ (0...module_px_size).each do |i|
56
+ (0...module_px_size).each do |j|
57
+ png[(y * module_px_size) + border_px + j , (x * module_px_size) + border_px + i] = color
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ png = png.resize(resize_to, resize_to) if resize_to
65
+
66
+ if output_file
67
+ png.save(output_file,{ :color_mode => ChunkyPNG::COLOR_GRAYSCALE, :bit_depth =>1})
68
+ end
69
+ png
70
+ end
71
+
72
+ end
73
+ end
74
+ end
75
+
76
+ RQRCode::QRCode.send :include, RQRCode::Export::PNG
@@ -0,0 +1,47 @@
1
+ # This class creates a SVG files.
2
+ # Code from: https://github.com/samvincent/rqrcode-rails3
3
+ module RQRCode
4
+ module Export
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 SVG
13
+ def as_svg(options={})
14
+ offset = options[:offset].to_i || 0
15
+ color = options[:color] || "000"
16
+
17
+ # height and width dependent on offset and QR complexity
18
+ dimension = (self.module_count*11) + (2*offset)
19
+
20
+ xml_tag = %{<?xml version="1.0" standalone="yes"?>}
21
+ 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}">}
22
+ close_tag = "</svg>"
23
+
24
+ result = []
25
+ self.modules.each_index do |c|
26
+ tmp = []
27
+ self.modules.each_index do |r|
28
+ y = c*11 + offset
29
+ x = r*11 + offset
30
+
31
+ next unless self.is_dark(c, r)
32
+ tmp << %{<rect width="11" height="11" x="#{x}" y="#{y}" style="fill:##{color}"/>}
33
+ end
34
+ result << tmp.join
35
+ end
36
+
37
+ if options[:fill]
38
+ result.unshift %{<rect width="#{dimension}" height="#{dimension}" x="0" y="0" style="fill:##{options[:fill]}"/>}
39
+ end
40
+
41
+ [xml_tag, open_tag, result, close_tag].flatten.join("\n")
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ RQRCode::QRCode.send :include, RQRCode::Export::SVG
@@ -0,0 +1,4 @@
1
+ Dir[File.dirname(__FILE__) + "/qrcode/*.rb"].sort.each do |path|
2
+ filename = File.basename(path)
3
+ require "rqrcode/qrcode/#{filename}"
4
+ end