prawn-qrcode 0.1.0
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.
- data/LICENSE +174 -0
- data/README.md +45 -0
- data/Rakefile +25 -0
- data/examples/autosize_qrcode.rb +38 -0
- data/examples/autosized code.pdf +7396 -0
- data/examples/dotsize.pdf +7396 -0
- data/examples/dotsize_qrcode.rb +37 -0
- data/examples/examples.iml +10 -0
- data/examples/prepared code.pdf +5640 -0
- data/examples/prepared_qrcode.rb +31 -0
- data/lib/lib.iml +10 -0
- data/lib/prawn/qrcode.rb +100 -0
- data/prawn-qrcode.gemspec +41 -0
- metadata +88 -0
@@ -0,0 +1,31 @@
|
|
1
|
+
# Copyright 2011 Jens Hausherr
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
require 'rubygems'
|
15
|
+
require 'prawn/core'
|
16
|
+
require_relative '../lib/prawn/qrcode'
|
17
|
+
|
18
|
+
qrcode = RQRCode::QRCode.new 'https://github.com/jabbrwcky/prawn-qrcode', :size=>5
|
19
|
+
|
20
|
+
Prawn::Document::new(:page_size => "A4") do
|
21
|
+
text "Prawn QR Code sample 1: Predefined QR-Code"
|
22
|
+
move_down 15
|
23
|
+
|
24
|
+
text "Sample predefined QR-Code (with stroked bounds) Size of QRCode dots: 1pt (1/72 in)"
|
25
|
+
render_qr_code(qrcode)
|
26
|
+
|
27
|
+
move_down 20
|
28
|
+
text "Sample predefined QR-Code (without stroked bounds) Size of QRCode dots: 1pt (1/72 in)"
|
29
|
+
render_qr_code(qrcode, :stroke=>false)
|
30
|
+
render_file("prepared.pdf")
|
31
|
+
end
|
data/lib/lib.iml
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="RUBY_MODULE" version="4">
|
3
|
+
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
4
|
+
<exclude-output />
|
5
|
+
<content url="file://$MODULE_DIR$" />
|
6
|
+
<orderEntry type="inheritedJdk" />
|
7
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
8
|
+
</component>
|
9
|
+
</module>
|
10
|
+
|
data/lib/prawn/qrcode.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# Copyright 2011 Jens Hausherr
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
require 'prawn'
|
15
|
+
require 'rqrcode'
|
16
|
+
|
17
|
+
# Extension for Prawn::Document for rendering QR codes.
|
18
|
+
#
|
19
|
+
# Author:: Jens Hausherr (mailto:jabbrwcky@googlemail.com)
|
20
|
+
# Copyright:: Copyright (c) 2011 Jens Hausherr
|
21
|
+
# License:: Apache License, Version 2.0
|
22
|
+
#
|
23
|
+
module QRCode
|
24
|
+
|
25
|
+
# The default size for QR Code modules is 1/72 in
|
26
|
+
DEFAULT_DOTSIZE = 1
|
27
|
+
|
28
|
+
# Prints a QR Code to the PDF document. The QR code creation happens on the fly.
|
29
|
+
#
|
30
|
+
# @param content [string] The string to put into the QR Code
|
31
|
+
# @param *options Named optional parameters
|
32
|
+
# :level:: Error correction level to use (:l,:m,:h,:q), Defaults to :m
|
33
|
+
# :exent:: Size of QR Code given in pt (1 pt == 1/72 in)
|
34
|
+
# :pos:: Two-element array containing the position at which the QR-Code sholud be rendered.
|
35
|
+
# Defaults to [0,cursor]
|
36
|
+
# :dot:: Size of QR Code module/dot. Calculated from extent or defaulting to 1pt
|
37
|
+
# :stroke:: boolean value whether to draw bounds around the QR Code.
|
38
|
+
# Defaults to true.
|
39
|
+
def print_qr_code(content, *options)
|
40
|
+
opt = options.extract_options!
|
41
|
+
qr_version = 0
|
42
|
+
level = opt[:level] || :m
|
43
|
+
extent = opt[:extent]
|
44
|
+
dot_size = opt[:dot] || DEFAULT_DOTSIZE
|
45
|
+
begin
|
46
|
+
qr_version +=1
|
47
|
+
qr_code = RQRCode::QRCode.new(content, :size=>qr_version, :level=>level)
|
48
|
+
|
49
|
+
dot_size = extent/(8+qr_code.modules.length) if extent
|
50
|
+
render_qr_code(qr_code, :dot=>dot_size, :pos=>opt[:pos], :stroke=>opt[:stroke])
|
51
|
+
rescue RQRCode::QRCodeRunTimeError
|
52
|
+
if qr_version <40
|
53
|
+
retry
|
54
|
+
else
|
55
|
+
raise
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# Renders a prepared QR Code object.
|
61
|
+
#
|
62
|
+
# @param qr_code [RQRCode::QRCode] The QR Code to render
|
63
|
+
# @param *options Named optional parameters
|
64
|
+
# :exent:: Size of QR Code given in pt (1 pt == 1/72 in)
|
65
|
+
# :pos:: Two-element array containing the position at which the QR-Code sholud be rendered.
|
66
|
+
# Defaults to [0,cursor]
|
67
|
+
# :dot:: Size of QR Code module/dot. Calculated from extent or defaulting to 1pt
|
68
|
+
# :stroke:: boolean value whether to draw bounds around the QR Code.
|
69
|
+
# Defaults to true.
|
70
|
+
def render_qr_code(qr_code, *options)
|
71
|
+
opt = options.extract_options!
|
72
|
+
dot = opt[:dot] || DEFAULT_DOTSIZE
|
73
|
+
extent= opt[:extent] || (8+qr_code.modules.length) * dot
|
74
|
+
stroke = (opt.has_key?(:stroke) && opt[:stroke].nil?) || opt[:stroke]
|
75
|
+
pos = opt[:pos] ||[0,cursor]
|
76
|
+
|
77
|
+
bounding_box pos, :width => extent, :height => extent do |box|
|
78
|
+
if stroke
|
79
|
+
stroke_bounds
|
80
|
+
end
|
81
|
+
|
82
|
+
pos_y = 4*dot +qr_code.modules.length * dot
|
83
|
+
|
84
|
+
qr_code.modules.each_index do |row|
|
85
|
+
pos_x = 4*dot
|
86
|
+
qr_code.modules.each_index do |col|
|
87
|
+
move_to [pos_x, pos_y]
|
88
|
+
if qr_code.dark?(row, col)
|
89
|
+
fill { rectangle([pos_x, pos_y], dot, dot) }
|
90
|
+
end
|
91
|
+
pos_x = pos_x + dot
|
92
|
+
end
|
93
|
+
pos_y = pos_y - dot
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
Prawn::Document.extensions << QRCode
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# Copyright 2011 Jens Hausherr
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
PRAWN_QRCODE_VERSION = "0.1.0"
|
16
|
+
|
17
|
+
Gem::Specification.new do |spec|
|
18
|
+
spec.name = "prawn-qrcode"
|
19
|
+
spec.version = PRAWN_QRCODE_VERSION
|
20
|
+
spec.platform = Gem::Platform::RUBY
|
21
|
+
spec.summary = "Print QR Codes in PDF"
|
22
|
+
spec.files = Dir.glob("{examples,lib}/**/**/*") +
|
23
|
+
["Rakefile", "prawn-qrcode.gemspec"]
|
24
|
+
spec.require_path = "lib"
|
25
|
+
spec.required_ruby_version = '>= 1.8.7'
|
26
|
+
spec.required_rubygems_version = ">= 1.3.6"
|
27
|
+
|
28
|
+
spec.extra_rdoc_files = %w{README.md LICENSE}
|
29
|
+
spec.rdoc_options << '--title' << 'Prawn/QRCode Documentation' <<
|
30
|
+
'--main' << 'README.md' << '-q'
|
31
|
+
spec.authors = ["Jens Hausherr"]
|
32
|
+
spec.email = ["jabbrwcky@googlemail.com"]
|
33
|
+
#spec.rubyforge_project = "prawn-qrcode"
|
34
|
+
spec.add_dependency('prawn', '~>0.11.1')
|
35
|
+
spec.add_dependency('rqrcode', '~>0.4.1')
|
36
|
+
spec.homepage = "http://github.com/jabbrwcky/prawn-qrcode"
|
37
|
+
spec.description = <<END_DESC
|
38
|
+
Prawn/QRCode simplifies the generation and rendering of QRCodes in Prawn PDF documents.
|
39
|
+
QR Codes
|
40
|
+
END_DESC
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: prawn-qrcode
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jens Hausherr
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-09-01 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: prawn
|
16
|
+
requirement: &70310456256060 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.11.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70310456256060
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rqrcode
|
27
|
+
requirement: &70310456255300 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.4.1
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70310456255300
|
36
|
+
description: ! " Prawn/QRCode simplifies the generation and rendering of QRCodes
|
37
|
+
in Prawn PDF documents.\n QR Codes\n"
|
38
|
+
email:
|
39
|
+
- jabbrwcky@googlemail.com
|
40
|
+
executables: []
|
41
|
+
extensions: []
|
42
|
+
extra_rdoc_files:
|
43
|
+
- README.md
|
44
|
+
- LICENSE
|
45
|
+
files:
|
46
|
+
- examples/autosize_qrcode.rb
|
47
|
+
- examples/autosized code.pdf
|
48
|
+
- examples/dotsize.pdf
|
49
|
+
- examples/dotsize_qrcode.rb
|
50
|
+
- examples/examples.iml
|
51
|
+
- examples/prepared code.pdf
|
52
|
+
- examples/prepared_qrcode.rb
|
53
|
+
- lib/lib.iml
|
54
|
+
- lib/prawn/qrcode.rb
|
55
|
+
- Rakefile
|
56
|
+
- prawn-qrcode.gemspec
|
57
|
+
- README.md
|
58
|
+
- LICENSE
|
59
|
+
homepage: http://github.com/jabbrwcky/prawn-qrcode
|
60
|
+
licenses: []
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options:
|
63
|
+
- --title
|
64
|
+
- Prawn/QRCode Documentation
|
65
|
+
- --main
|
66
|
+
- README.md
|
67
|
+
- -q
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.8.7
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 1.3.6
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 1.8.10
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: Print QR Codes in PDF
|
88
|
+
test_files: []
|