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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +23 -0
- data/Gemfile +2 -0
- data/README.md +3 -2
- data/data/fonts/fab/LICENSE +137 -6
- data/data/fonts/fab/fa-brands.ttf +0 -0
- data/data/fonts/fab/fab.yml +82 -10
- data/data/fonts/far/LICENSE +137 -6
- data/data/fonts/far/fa-regular.ttf +0 -0
- data/data/fonts/far/far.yml +107 -2
- data/data/fonts/fas/LICENSE +137 -6
- data/data/fonts/fas/fa-solid.ttf +0 -0
- data/data/fonts/fas/fas.yml +988 -24
- data/data/fonts/mdi/LICENSE +20 -0
- data/data/fonts/mdi/materialdesignicons-webfont.ttf +0 -0
- data/data/fonts/mdi/mdi.yml +7099 -0
- data/examples/mdi.rb +36 -0
- data/lib/prawn/icon/base.rb +2 -2
- data/lib/prawn/icon/compatibility.rb +14 -17
- data/lib/prawn/icon/configuration.rb +3 -3
- data/lib/prawn/icon/errors.rb +2 -2
- data/lib/prawn/icon/font_data.rb +14 -12
- data/lib/prawn/icon/interface.rb +3 -5
- data/lib/prawn/icon/parser.rb +14 -12
- data/lib/prawn/icon/version.rb +3 -3
- data/lib/prawn/icon.rb +2 -2
- data/prawn-icon.gemspec +12 -10
- data/spec/integration/icon_spec.rb +17 -2
- metadata +29 -24
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
|
data/lib/prawn/icon/base.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
#
|
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 =
|
35
|
-
@translate ||=
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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
|
56
|
-
[Prawn::Icon - DEPRECATION WARNING]
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
#
|
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('
|
35
|
+
File.expand_path('../../..', __dir__)
|
36
36
|
end
|
37
37
|
# :nocov:
|
38
38
|
end
|
data/lib/prawn/icon/errors.rb
CHANGED
data/lib/prawn/icon/font_data.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
#
|
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
|
-
|
67
|
-
.
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
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
|
-
|
77
|
+
font.to_s
|
78
|
+
end
|
77
79
|
end
|
78
80
|
|
79
81
|
def specifier
|
data/lib/prawn/icon/interface.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
#
|
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
|
data/lib/prawn/icon/parser.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
#
|
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
|
-
|
35
|
-
|
36
|
-
|
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
|
-
|
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:
|
107
|
-
size:
|
108
|
-
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)
|
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
|
data/lib/prawn/icon/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
#
|
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 = '
|
11
|
+
VERSION = '4.0.0'
|
12
12
|
end
|
13
13
|
end
|
data/lib/prawn/icon.rb
CHANGED
data/prawn-icon.gemspec
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
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 = [
|
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 =
|
35
|
-
|
36
|
-
|
37
|
-
|
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(
|
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(
|
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:
|
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:
|
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:
|
48
|
+
name: pdf-reader
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
51
|
- - ">="
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
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:
|
60
|
+
version: '1.4'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
|
-
name:
|
62
|
+
name: rake
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
|
-
- - "
|
65
|
+
- - ">="
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version: 0
|
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
|
74
|
+
version: '0'
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
|
-
name:
|
76
|
+
name: rspec
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
79
|
- - ">="
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version:
|
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:
|
88
|
+
version: 3.5.0
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
|
-
name:
|
90
|
+
name: rubocop
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
92
92
|
requirements:
|
93
|
-
- - "
|
93
|
+
- - "~>"
|
94
94
|
- !ruby/object:Gem::Version
|
95
|
-
version:
|
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:
|
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: |
|
118
|
-
|
119
|
-
|
120
|
-
|
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.
|
206
|
+
rubygems_version: 3.5.23
|
202
207
|
signing_key:
|
203
208
|
specification_version: 4
|
204
209
|
summary: Provides icon fonts for PrawnPDF
|