prawn-qrcode 0.2.2.1 → 0.3.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.
@@ -12,20 +12,20 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
  require 'rubygems'
15
- require 'prawn/core'
15
+ require 'prawn'
16
16
  require_relative '../lib/prawn/qrcode'
17
17
 
18
- qrcode = RQRCode::QRCode.new 'https://github.com/jabbrwcky/prawn-qrcode', :size=>5
18
+ qrcode = RQRCode::QRCode.new('https://github.com/jabbrwcky/prawn-qrcode', :size=>5)
19
19
 
20
20
  Prawn::Document::new(:page_size => "A4") do
21
21
  text "Prawn QR Code sample 1: Predefined QR-Code"
22
- move_down 15
23
-
22
+ move_down 10
24
23
  text "Sample predefined QR-Code (with stroked bounds) Size of QRCode dots: 1pt (1/72 in)"
24
+ move_down 45
25
25
  render_qr_code(qrcode)
26
-
27
- move_down 20
26
+ move_down 10
28
27
  text "Sample predefined QR-Code (without stroked bounds) Size of QRCode dots: 1pt (1/72 in)"
28
+ move_down 45
29
29
  render_qr_code(qrcode, :stroke=>false)
30
30
  render_file("prepared.pdf")
31
- end
31
+ end
@@ -0,0 +1,5 @@
1
+ module Prawn
2
+ module QRCode
3
+ VERSION = "0.3.0"
4
+ end
5
+ end
data/lib/prawn/qrcode.rb CHANGED
@@ -25,116 +25,106 @@ require 'rqrcode'
25
25
  # *Copyright*:: Copyright (c) 2011 Jens Hausherr
26
26
  # *License*:: Apache License, Version 2.0
27
27
  #
28
- module QRCode
28
+ module Prawn
29
+ module QRCode
30
+ # The default size for QR Code modules is 1/72 in
31
+ DEFAULT_DOTSIZE = 1.to_f
29
32
 
30
- # The default size for QR Code modules is 1/72 in
31
- DEFAULT_DOTSIZE = 1.to_f
33
+ # Prints a QR Code to the PDF document. The QR Code creation happens on the fly.
34
+ #
35
+ # content:: The string to render as content of the QR Code
36
+ #
37
+ # *options:: Named optional parameters
38
+ #
39
+ # +:level+:: Error correction level to use. One of: (:l,:m,:h,:q), Defaults to :m
40
+ # +:extent+:: Size of QR Code given in pt (1 pt == 1/72 in)
41
+ # +:pos+:: Two-element array containing the position at which the QR-Code should be rendered. Defaults to [0,cursor]
42
+ # +:dot+:: Size of QR Code module/dot. Calculated from extent or defaulting to 1pt
43
+ # +:stroke+:: boolean value whether to draw bounds around the QR Code.
44
+ # Defaults to true.
45
+ # +:align+:: Optional alignment within the current bounding box. Valid values are :left, :right, and :center. If set
46
+ # This option overrides the horizontal positioning specified in :pos. Defaults to nil.
47
+ # +:debug+:: Optional boolean, renders a coordinate grid around the QRCode if true (uses Prawn#stroke_axis)
48
+ #
49
+ def print_qr_code(content, level: :m, dot: DEFAULT_DOTSIZE, pos: [0,cursor], stroke: true, **options)
50
+ qr_version = 0
51
+ dot_size = dot
32
52
 
33
- # Prints a QR Code to the PDF document. The QR Code creation happens on the fly.
34
- #
35
- # content:: The string to render as content of the QR Code
36
- #
37
- # *options:: Named optional parameters
38
- #
39
- # +:level+:: Error correction level to use. One of: (:l,:m,:h,:q), Defaults to :m
40
- # +:extent+:: Size of QR Code given in pt (1 pt == 1/72 in)
41
- # +:pos+:: Two-element array containing the position at which the QR-Code should be rendered. Defaults to [0,cursor]
42
- # +:dot+:: Size of QR Code module/dot. Calculated from extent or defaulting to 1pt
43
- # +:stroke+:: boolean value whether to draw bounds around the QR Code.
44
- # Defaults to true.
45
- # +:align+:: Optional alignment within the current bounding box. Valid values are :left, :right, and :center. If set
46
- # This option overrides the horizontal positioning specified in :pos. Defaults to nil.
47
- #
48
- def print_qr_code(content, *options)
49
- opt = options.extract_options!
50
- qr_version = 0
51
- level = opt[:level] || :m
52
- extent = opt[:extent].to_f
53
- dot_size = opt[:dot].to_f || DEFAULT_DOTSIZE
54
- begin
55
- qr_version +=1
56
- qr_code = RQRCode::QRCode.new(content, :size=>qr_version, :level=>level)
53
+ begin
54
+ qr_version += 1
55
+ qr_code = RQRCode::QRCode.new(content, size: qr_version, level: level)
56
+ dot = options[:extent] / (8 + qr_code.modules.length) if options[:extent]
57
57
 
58
- dot_size = extent/(8+qr_code.modules.length) if extent
59
- render_qr_code(qr_code, opt.merge(:dot=>dot_size))
60
- rescue RQRCode::QRCodeRunTimeError
61
- if qr_version <40
62
- retry
63
- else
64
- raise
58
+ render_qr_code(qr_code, dot: dot, pos: pos, stroke: stroke, **options)
59
+ rescue RQRCode::QRCodeRunTimeError
60
+ if qr_version < 40
61
+ retry
62
+ else
63
+ raise
64
+ end
65
65
  end
66
66
  end
67
- end
68
-
69
- # Renders a prepared QR Code (RQRCode::QRCode) object.
70
- #
71
- # qr_code:: The QR Code (an RQRCode::QRCode) to render
72
- #
73
- # *options:: Named optional parameters
74
- # +:extent+:: Size of QR Code given in pt (1 pt == 1/72 in)
75
- # +:pos+:: Two-element array containing the position at which the QR-Code should be rendered. Defaults to [0,cursor]
76
- # +:dot+:: Size of QR Code module/dot. Calculated from extent or defaulting to 1pt
77
- # +:stroke+:: boolean value whether to draw bounds around the QR Code. Defaults to true.
78
- # +:align+:: Optional alignment within the current bounding box. Valid values are :left, :right, and :center. If set
79
- # This option overrides the horizontal positioning specified in :pos. Defaults to nil.
80
- def render_qr_code(qr_code, *options)
81
- opt = options.extract_options!
82
- dot = opt[:dot].to_f || DEFAULT_DOTSIZE
83
- extent= opt[:extent].to_f || (8+qr_code.modules.length) * dot
84
- stroke = true
85
- stroke = opt[:stroke] if opt.has_key?(:stroke)
86
-
87
- foreground_color = opt[:foreground_color] || '000000'
88
- background_color = opt[:background_color] || 'FFFFFF'
89
- stroke_color = opt[:stroke_color] || '000000'
90
-
91
- pos = opt[:pos] ||[0, cursor]
92
-
93
- align = opt[:align]
94
- case(align)
95
- when :center
96
- pos[0] = (@bounding_box.right / 2) - (extent / 2)
97
- when :right
98
- pos[0] = @bounding_box.right - extent
99
- when :left
100
- pos[0] = 0;
101
- end
102
-
103
- stroke_color stroke_color
104
- fill_color background_color
105
67
 
106
- bounding_box pos, :width => extent, :height => extent do |box|
107
- fill_color foreground_color
68
+ # Renders a prepared QR Code (RQRCode::QRCode) object.
69
+ #
70
+ # qr_code:: The QR Code (an RQRCode::QRCode) to render
71
+ #
72
+ # *options:: Named optional parameters
73
+ # +:extent+:: Size of QR Code given in pt (1 pt == 1/72 in)
74
+ # +:pos+:: Two-element array containing the position at which the QR-Code should be rendered. Defaults to [0,cursor]
75
+ # +:dot+:: Size of QR Code module/dot. Calculated from extent or defaulting to 1pt
76
+ # +:stroke+:: boolean value whether to draw bounds around the QR Code. Defaults to true.
77
+ # +:align+:: Optional alignment within the current bounding box. Valid values are :left, :right, and :center. If set
78
+ # This option overrides the horizontal positioning specified in :pos. Defaults to nil.
79
+ # +:debug+:: Optional boolean, renders a coordinate grid around the QRCode if true (uses Prawn#stroke_axis)
80
+ #
81
+ def render_qr_code(qr_code, dot: DEFAULT_DOTSIZE, pos: [0,cursor], stroke: true, foreground_color: '000000', background_color: 'FFFFFF', stroke_color: '000000', **options)
82
+ extent = extent || (8 + qr_code.modules.length) * dot
108
83
 
109
- if stroke
110
- stroke_bounds
84
+ case options[:align]
85
+ when :center
86
+ pos[0] = (@bounding_box.right / 2) - (extent / 2)
87
+ when :right
88
+ pos[0] = @bounding_box.right - extent
89
+ when :left
90
+ pos[0] = 0
111
91
  end
112
92
 
113
- pos_y = 4*dot +qr_code.modules.length * dot
93
+ fill_color background_color
94
+
95
+ bounding_box(pos, width: extent, height: extent) do |_box|
96
+ fill_color foreground_color
97
+ pos_y = 4 * dot + qr_code.modules.length * dot
114
98
 
115
- qr_code.modules.each_index do |row|
116
- pos_x = 4*dot
117
- dark_col = 0
118
- qr_code.modules.each_index do |col|
119
- move_to [pos_x, pos_y]
120
- if qr_code.dark?(row, col)
121
- dark_col = dark_col+1
122
- else
123
- if (dark_col>0)
124
- fill { rectangle([pos_x - dark_col*dot, pos_y], dot*dark_col, dot) }
125
- dark_col = 0
99
+ qr_code.modules.each_index do |row|
100
+ pos_x = 4 * dot
101
+ dark_col = 0
102
+ qr_code.modules.each_index do |col|
103
+ move_to [pos_x, pos_y]
104
+ if qr_code.dark?(row, col)
105
+ dark_col += 1
106
+ else
107
+ if dark_col > 0
108
+ fill { rectangle([pos_x - dark_col * dot, pos_y], dot * dark_col, dot) }
109
+ dark_col = 0
110
+ end
126
111
  end
112
+ pos_x += dot
127
113
  end
128
- pos_x = pos_x + dot
114
+ if dark_col > 0
115
+ fill { rectangle([pos_x - dark_col * dot, pos_y], dot * dark_col, dot) }
116
+ end
117
+ pos_y -= dot
129
118
  end
130
- if (dark_col > 0)
131
- fill { rectangle([pos_x - dark_col*dot, pos_y], dot*dark_col, dot) }
119
+
120
+ if stroke
121
+ fill_color stroke_color
122
+ stroke_bounds
132
123
  end
133
- pos_y = pos_y - dot
124
+ stroke_axis(at: [-1,-1], negative_axes_length: 0, color: '0C0C0C', step_length: 50) if options[:debug]
134
125
  end
135
126
  end
136
127
  end
137
-
138
128
  end
139
129
 
140
- Prawn::Document.extensions << QRCode
130
+ Prawn::Document.extensions << Prawn::QRCode
data/prawn-qrcode.gemspec CHANGED
@@ -1,4 +1,5 @@
1
- # Copyright 2011-2014 Jens Hausherr
1
+ # coding: utf-8
2
+ # Copyright 2011-2017 Jens Hausherr
2
3
  #
3
4
  # Licensed under the Apache License, Version 2.0 (the "License");
4
5
  # you may not use this file except in compliance with the License.
@@ -12,30 +13,37 @@
12
13
  # See the License for the specific language governing permissions and
13
14
  # limitations under the License.
14
15
 
16
+ lib = File.expand_path('../lib', __FILE__)
17
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
18
+ require 'prawn/qrcode/version'
19
+
15
20
  Gem::Specification.new do |spec|
16
21
  spec.name = "prawn-qrcode"
17
- spec.version = "0.2.2.1"
22
+ spec.version = Prawn::QRCode::VERSION
18
23
  spec.platform = Gem::Platform::RUBY
19
24
  spec.summary = "Print QR Codes in PDF"
20
25
  spec.licenses = [ 'Apache License 2.0' ]
21
26
  spec.files = Dir.glob("{examples,lib}/**/**/*") +
22
27
  ["Rakefile", "prawn-qrcode.gemspec"]
23
28
  spec.require_path = "lib"
24
- spec.required_ruby_version = '>= 1.8.7'
29
+ spec.required_ruby_version = '>= 2.0.0'
25
30
  spec.required_rubygems_version = ">= 1.3.6"
26
31
 
27
32
  spec.extra_rdoc_files = %w{README.md LICENSE}
28
33
  spec.rdoc_options << '--title' << 'Prawn/QRCode Documentation' <<
29
34
  '--main' << 'README.md' << '-q'
30
35
  spec.authors = ["Jens Hausherr"]
31
- spec.email = ["jabbrwcky@googlemail.com"]
32
- #spec.rubyforge_project = "prawn-qrcode"
36
+ spec.email = ["jabbrwcky@gmail.com"]
33
37
  spec.homepage = "http://github.com/jabbrwcky/prawn-qrcode"
34
38
 
35
39
  spec.description = <<END_DESC
36
40
  Prawn/QRCode simplifies the generation and rendering of QRCodes in Prawn PDF documents.
37
41
  END_DESC
38
42
 
39
- spec.add_dependency('prawn', '>= 0.11.1')
43
+ spec.add_dependency('prawn', '>=1')
40
44
  spec.add_dependency('rqrcode', '>=0.4.1')
45
+
46
+ spec.add_development_dependency "bundler", "~> 1.13"
47
+ spec.add_development_dependency "rake", "~> 10.0"
48
+ #spec.add_development_dependency "rspec", "~> 3.0"
41
49
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prawn-qrcode
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Hausherr
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-13 00:00:00.000000000 Z
11
+ date: 2017-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prawn
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.11.1
19
+ version: '1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.11.1
26
+ version: '1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rqrcode
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,10 +38,38 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.4.1
41
- description: |2
42
- Prawn/QRCode simplifies the generation and rendering of QRCodes in Prawn PDF documents.
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.13'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.13'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: " Prawn/QRCode simplifies the generation and rendering of QRCodes in
70
+ Prawn PDF documents.\n"
43
71
  email:
44
- - jabbrwcky@googlemail.com
72
+ - jabbrwcky@gmail.com
45
73
  executables: []
46
74
  extensions: []
47
75
  extra_rdoc_files:
@@ -51,10 +79,14 @@ files:
51
79
  - LICENSE
52
80
  - README.md
53
81
  - Rakefile
82
+ - examples/autosize.pdf
54
83
  - examples/autosize_qrcode.rb
84
+ - examples/dotsize.pdf
55
85
  - examples/dotsize_qrcode.rb
86
+ - examples/prepared.pdf
56
87
  - examples/prepared_qrcode.rb
57
88
  - lib/prawn/qrcode.rb
89
+ - lib/prawn/qrcode/version.rb
58
90
  - prawn-qrcode.gemspec
59
91
  homepage: http://github.com/jabbrwcky/prawn-qrcode
60
92
  licenses:
@@ -73,7 +105,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
73
105
  requirements:
74
106
  - - ">="
75
107
  - !ruby/object:Gem::Version
76
- version: 1.8.7
108
+ version: 2.0.0
77
109
  required_rubygems_version: !ruby/object:Gem::Requirement
78
110
  requirements:
79
111
  - - ">="
@@ -81,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
113
  version: 1.3.6
82
114
  requirements: []
83
115
  rubyforge_project:
84
- rubygems_version: 2.2.2
116
+ rubygems_version: 2.5.1
85
117
  signing_key:
86
118
  specification_version: 4
87
119
  summary: Print QR Codes in PDF