prawn-icon 3.0.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/examples/mdi.rb ADDED
@@ -0,0 +1,36 @@
1
+ # All example code may be executed by calling `rake legend`
2
+
3
+ require_relative '../lib/prawn/icon'
4
+ require_relative 'example_helper'
5
+
6
+ Prawn::Document.generate('mdi_icons.pdf') do
7
+ deja_path = Prawn::Icon.configuration.font_directory
8
+ .join('DejaVuSans.ttf')
9
+ .to_s
10
+
11
+ font_families.update({
12
+ 'deja' => { normal: deja_path }
13
+ })
14
+
15
+ font('deja')
16
+
17
+ icons = icon_keys(self, 'mdi')
18
+ required_pages = number_of_pages(self, 'mdi')
19
+
20
+ define_grid(columns: 6, rows: 12, gutter: 16)
21
+
22
+ sub_header = 'Material Design Icons'
23
+ link = 'https://materialdesignicons.com/'
24
+ page_header sub_header, link
25
+
26
+ first_page_icons icons do |icon_key|
27
+ # Just call the +icon+ method and pass in an icon key
28
+ icon icon_key, size: 20, align: :center
29
+ end
30
+
31
+ start_new_page
32
+
33
+ page_icons icons, required_pages do |icon_key|
34
+ icon icon_key, size: 20, align: :center
35
+ end
36
+ end
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
2
- #
1
+ # frozen_string_literal: true
2
+
3
3
  # base.rb - Base configuration for Prawn::Icon.
4
4
  #
5
5
  # Copyright September 2016, Jesse Doyle. All rights reserved.
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
2
- #
1
+ # frozen_string_literal: true
2
+
3
3
  # compatibility.rb - Prawn::Icon FontAwesome 4/5 compatibility shim.
4
4
  #
5
5
  # Copyright March 2018, Jesse Doyle. All rights reserved.
@@ -31,14 +31,12 @@ module Prawn
31
31
  self.key = opts.fetch(:key)
32
32
  end
33
33
 
34
- def translate(io = STDERR)
35
- @translate ||= begin
36
- if key.start_with?('fa-')
37
- map.tap { |replaced| warning(replaced, key, io) }
38
- else
39
- key
40
- end
41
- end
34
+ def translate(io = $stderr)
35
+ @translate ||= if key.start_with?('fa-')
36
+ map.tap { |replaced| warning(replaced, key, io) }
37
+ else
38
+ key
39
+ end
42
40
  end
43
41
 
44
42
  private
@@ -52,14 +50,13 @@ module Prawn
52
50
  end
53
51
 
54
52
  def warning(new_key, old_key, io)
55
- io.puts <<-DEPRECATION
56
- [Prawn::Icon - DEPRECATION WARNING]
57
- FontAwesome 4 icon was referenced as '#{old_key}'.
58
- Use the FontAwesome 5 icon '#{new_key}' instead.
59
- This compatibility layer will be removed in Prawn::Icon 4.0.0.
60
- DEPRECATION
53
+ io.puts <<~DEPRECATION
54
+ [Prawn::Icon - DEPRECATION WARNING]
55
+ FontAwesome 4 icon was referenced as '#{old_key}'.
56
+ Use the FontAwesome 5 icon '#{new_key}' instead.
57
+ This compatibility layer will be removed in a future major release.
58
+ DEPRECATION
61
59
  end
62
60
  end
63
61
  end
64
62
  end
65
- # rubocop:enable Metrics/ClassLength
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
2
- #
1
+ # frozen_string_literal: true
2
+
3
3
  # configuration.rb: Prawn icon configuration.
4
4
  #
5
5
  # Copyright October 2020, Jesse Doyle. All rights reserved.
@@ -32,7 +32,7 @@ module Prawn
32
32
  end
33
33
 
34
34
  def failsafe_gem_path
35
- File.expand_path('../../../..', __FILE__)
35
+ File.expand_path('../../..', __dir__)
36
36
  end
37
37
  # :nocov:
38
38
  end
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
2
- #
1
+ # frozen_string_literal: true
2
+
3
3
  # errors.rb - Prawn::Icon standard errors.
4
4
  #
5
5
  # Copyright September 2016, Jesse Doyle. All rights reserved.
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
2
- #
1
+ # frozen_string_literal: true
2
+
3
3
  # font_data.rb: Icon font metadata container/cache.
4
4
  #
5
5
  # Copyright October 2014, Jesse Doyle. All rights reserved.
@@ -63,17 +63,19 @@ module Prawn
63
63
  end
64
64
 
65
65
  def path
66
- font = Icon.configuration.font_directory
67
- .join(@set.to_s)
68
- .glob('*.ttf')
69
- .first
70
-
71
- if font.nil?
72
- raise Prawn::Errors::UnknownFont,
73
- "Icon font not found for set: #{@set}"
74
- end
66
+ @path = begin
67
+ font = Icon.configuration.font_directory
68
+ .join(@set.to_s)
69
+ .glob('*.ttf')
70
+ .first
71
+
72
+ if font.nil?
73
+ raise Prawn::Errors::UnknownFont,
74
+ "Icon font not found for set: #{@set}"
75
+ end
75
76
 
76
- @path ||= font.to_s
77
+ font.to_s
78
+ end
77
79
  end
78
80
 
79
81
  def specifier
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
2
- #
1
+ # frozen_string_literal: true
2
+
3
3
  # interface.rb: Prawn extension module and logic.
4
4
  #
5
5
  # Copyright October 2016, Jesse Doyle. All rights reserved.
@@ -199,9 +199,7 @@ module Prawn
199
199
  Text::Formatted::Box.new(content, opts).tap do |box|
200
200
  box.render(dry_run: true)
201
201
  self.y -= box.height
202
- unless opts.fetch(:final_gap, true)
203
- self.y -= box.line_gap + box.leading
204
- end
202
+ self.y -= box.line_gap + box.leading unless opts.fetch(:final_gap, true)
205
203
  end
206
204
  end
207
205
  end
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
2
- #
1
+ # frozen_string_literal: true
2
+
3
3
  # parser.rb: Prawn icon tag text parser (pseudo-HTML).
4
4
  #
5
5
  # Copyright October 2014, Jesse Doyle. All rights reserved.
@@ -31,15 +31,17 @@ module Prawn
31
31
  #
32
32
  class Parser
33
33
  PARSER_REGEX = Regexp.new \
34
- '<icon[^>]*>|</icon>',
35
- Regexp::IGNORECASE |
36
- Regexp::MULTILINE
34
+ '<icon[^>]*>|</icon>',
35
+ Regexp::IGNORECASE |
36
+ Regexp::MULTILINE
37
37
 
38
- CONTENT_REGEX = /<icon[^>]*>(?<content>[^<]*)<\/icon>/mi
38
+ CONTENT_REGEX = /<icon[^>]*>(?<content>[^<]*)<\/icon>/mi.freeze
39
39
 
40
- TAG_REGEX = /<icon[^>]*>[^<]*<\/icon>/mi
40
+ TAG_REGEX = /<icon[^>]*>[^<]*<\/icon>/mi.freeze
41
41
 
42
- ATTR_REGEX = /(?<attr>[a-zA-Z]*)=["|'](?<val>(\w*[^["|']]))["|']/mi
42
+ # rubocop:disable Lint/MixedRegexpCaptureTypes
43
+ ATTR_REGEX = /(?<attr>[a-zA-Z]*)=["|'](?<val>(\w*[^["|']]))["|']/mi.freeze
44
+ # rubocop:enable Lint/MixedRegexpCaptureTypes
43
45
 
44
46
  class << self
45
47
  def format(document, string)
@@ -103,9 +105,9 @@ module Prawn
103
105
  options ||= {}
104
106
  options = config[index] if config.any?
105
107
  info = {
106
- set: FontData.specifier_from_key(key),
107
- size: options[:size],
108
- color: options[:color],
108
+ set: FontData.specifier_from_key(key),
109
+ size: options[:size],
110
+ color: options[:color],
109
111
  content: FontData.unicode_from_key(document, key)
110
112
  }
111
113
  icons << info
@@ -115,7 +117,7 @@ module Prawn
115
117
 
116
118
  private
117
119
 
118
- def attr_hash(value) #:nodoc:
120
+ def attr_hash(value) # :nodoc:
119
121
  # If attr == size, we must cast value to float,
120
122
  # else symbolize the key and map it to value
121
123
  if value[0] =~ /size/i
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
2
- #
1
+ # frozen_string_literal: true
2
+
3
3
  # version.rb: Prawn icon versioning.
4
4
  #
5
5
  # Copyright October 2014, Jesse Doyle. All rights reserved.
@@ -8,6 +8,6 @@
8
8
 
9
9
  module Prawn
10
10
  class Icon
11
- VERSION = '3.0.0'.freeze
11
+ VERSION = '4.0.0'
12
12
  end
13
13
  end
data/lib/prawn/icon.rb CHANGED
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
2
- #
1
+ # frozen_string_literal: true
2
+
3
3
  # icon.rb: Prawn icon functionality.
4
4
  #
5
5
  # Copyright October 2014, Jesse Doyle. All rights reserved.
data/prawn-icon.gemspec CHANGED
@@ -1,4 +1,6 @@
1
- basedir = File.expand_path(File.dirname(__FILE__))
1
+ # frozen_string_literal: true
2
+
3
+ basedir = __dir__
2
4
  require "#{basedir}/lib/prawn/icon/version"
3
5
 
4
6
  Gem::Specification.new do |spec|
@@ -17,23 +19,23 @@ Gem::Specification.new do |spec|
17
19
 
18
20
  spec.homepage = 'https://github.com/jessedoyle/prawn-icon/'
19
21
 
20
- spec.test_files = Dir['spec/*_spec.rb']
21
22
  spec.authors = ['Jesse Doyle']
22
23
  spec.email = ['jdoyle@ualberta.ca']
23
- spec.licenses = ['RUBY', 'GPL-2', 'GPL-3']
24
+ spec.licenses = %w[RUBY GPL-2 GPL-3]
24
25
 
25
26
  spec.add_dependency('prawn', '>= 1.1.0', '< 3.0.0')
26
27
 
27
28
  spec.add_development_dependency('pdf-inspector', '>= 1.2.1')
28
- spec.add_development_dependency('rspec', '>= 3.5.0')
29
- spec.add_development_dependency('rubocop', '~> 0.49.1')
30
- spec.add_development_dependency('rake')
31
29
  spec.add_development_dependency('pdf-reader', '>= 1.4')
30
+ spec.add_development_dependency('rake')
31
+ spec.add_development_dependency('rspec', '>= 3.5.0')
32
+ spec.add_development_dependency('rubocop', '~> 1.35.1')
32
33
  spec.add_development_dependency('simplecov')
33
34
 
34
- spec.description = <<-END_DESC
35
- Prawn::Icon provides various icon fonts including
36
- FontAwesome, PaymentFont and Foundation Icons
37
- for use with the Prawn PDF toolkit.
35
+ spec.description = <<~END_DESC
36
+ Prawn::Icon provides various icon fonts including
37
+ FontAwesome, PaymentFont and Foundation Icons
38
+ for use with the Prawn PDF toolkit.
38
39
  END_DESC
40
+ spec.metadata['rubygems_mfa_required'] = 'true'
39
41
  end
@@ -68,7 +68,7 @@ describe Prawn::Icon::Interface do
68
68
  inspector = PDF::Inspector::Text.analyze(pdf.render)
69
69
  y = inspector.positions[1].last.round
70
70
 
71
- expect(y).to eq(723)
71
+ expect(y).to eq(722)
72
72
  end
73
73
  end
74
74
  end
@@ -154,7 +154,7 @@ describe Prawn::Icon::Interface do
154
154
  x, y = inspector.positions[0]
155
155
 
156
156
  expect(x).to eq(200)
157
- expect(y.round).to eq(90)
157
+ expect(y.round).to eq(89)
158
158
  end
159
159
 
160
160
  it 'handles final_gap: false correctly' do
@@ -261,4 +261,19 @@ describe Prawn::Icon do
261
261
  expect(text.strings.first).to eq('')
262
262
  end
263
263
  end
264
+
265
+ context 'Material Design Icons' do
266
+ it 'renders Material Design Icon glyphs' do
267
+ pdf.icon 'mdi-beer'
268
+ text = PDF::Inspector::Text.analyze(pdf.render)
269
+
270
+ # NOTE: Prawn <= 2.4.0 incorrectly handled unicode codepoints
271
+ # see: https://github.com/prawnpdf/prawn/pull/1327#issuecomment-1905817491
272
+ if Gem::Version.new(Prawn::VERSION) <= Gem::Version.new('2.4.0')
273
+ expect(text.strings.first).to eq("\u{F009}")
274
+ else
275
+ expect(text.strings.first).to eq("\u{F0098}")
276
+ end
277
+ end
278
+ end
264
279
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prawn-icon
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesse Doyle
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-11 00:00:00.000000000 Z
11
+ date: 2024-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prawn
@@ -45,61 +45,61 @@ dependencies:
45
45
  - !ruby/object:Gem::Version
46
46
  version: 1.2.1
47
47
  - !ruby/object:Gem::Dependency
48
- name: rspec
48
+ name: pdf-reader
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - ">="
52
52
  - !ruby/object:Gem::Version
53
- version: 3.5.0
53
+ version: '1.4'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - ">="
59
59
  - !ruby/object:Gem::Version
60
- version: 3.5.0
60
+ version: '1.4'
61
61
  - !ruby/object:Gem::Dependency
62
- name: rubocop
62
+ name: rake
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
- - - "~>"
65
+ - - ">="
66
66
  - !ruby/object:Gem::Version
67
- version: 0.49.1
67
+ version: '0'
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
- - - "~>"
72
+ - - ">="
73
73
  - !ruby/object:Gem::Version
74
- version: 0.49.1
74
+ version: '0'
75
75
  - !ruby/object:Gem::Dependency
76
- name: rake
76
+ name: rspec
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - ">="
80
80
  - !ruby/object:Gem::Version
81
- version: '0'
81
+ version: 3.5.0
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - ">="
87
87
  - !ruby/object:Gem::Version
88
- version: '0'
88
+ version: 3.5.0
89
89
  - !ruby/object:Gem::Dependency
90
- name: pdf-reader
90
+ name: rubocop
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
- - - ">="
93
+ - - "~>"
94
94
  - !ruby/object:Gem::Version
95
- version: '1.4'
95
+ version: 1.35.1
96
96
  type: :development
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
- - - ">="
100
+ - - "~>"
101
101
  - !ruby/object:Gem::Version
102
- version: '1.4'
102
+ version: 1.35.1
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: simplecov
105
105
  requirement: !ruby/object:Gem::Requirement
@@ -114,10 +114,10 @@ dependencies:
114
114
  - - ">="
115
115
  - !ruby/object:Gem::Version
116
116
  version: '0'
117
- description: |2
118
- Prawn::Icon provides various icon fonts including
119
- FontAwesome, PaymentFont and Foundation Icons
120
- for use with the Prawn PDF toolkit.
117
+ description: |
118
+ Prawn::Icon provides various icon fonts including
119
+ FontAwesome, PaymentFont and Foundation Icons
120
+ for use with the Prawn PDF toolkit.
121
121
  email:
122
122
  - jdoyle@ualberta.ca
123
123
  executables: []
@@ -146,6 +146,9 @@ files:
146
146
  - data/fonts/fi/LICENSE
147
147
  - data/fonts/fi/fi.yml
148
148
  - data/fonts/fi/foundation-icons.ttf
149
+ - data/fonts/mdi/LICENSE
150
+ - data/fonts/mdi/materialdesignicons-webfont.ttf
151
+ - data/fonts/mdi/mdi.yml
149
152
  - data/fonts/pf/LICENSE
150
153
  - data/fonts/pf/paymentfont-webfont.ttf
151
154
  - data/fonts/pf/pf.yml
@@ -154,6 +157,7 @@ files:
154
157
  - examples/fas-beer.png
155
158
  - examples/fontawesome.rb
156
159
  - examples/foundation_icons.rb
160
+ - examples/mdi.rb
157
161
  - examples/paymentfont.rb
158
162
  - lib/prawn/icon.rb
159
163
  - lib/prawn/icon/base.rb
@@ -182,7 +186,8 @@ licenses:
182
186
  - RUBY
183
187
  - GPL-2
184
188
  - GPL-3
185
- metadata: {}
189
+ metadata:
190
+ rubygems_mfa_required: 'true'
186
191
  post_install_message:
187
192
  rdoc_options: []
188
193
  require_paths:
@@ -198,7 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
198
203
  - !ruby/object:Gem::Version
199
204
  version: 1.3.6
200
205
  requirements: []
201
- rubygems_version: 3.1.2
206
+ rubygems_version: 3.5.23
202
207
  signing_key:
203
208
  specification_version: 4
204
209
  summary: Provides icon fonts for PrawnPDF