prawn-icon 1.3.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Binary file
data/data/fonts/pf/pf.yml CHANGED
@@ -1,98 +1,119 @@
1
+ ---
1
2
  pf:
2
- __font_version__: '1.1.2'
3
- amazon: "\uf000"
4
- american-express: "\uf001"
5
- american-express-alt: "\uf002"
6
- atm: "\uf003"
7
- bankomat: "\uf004"
8
- bank-transfer: "\uf005"
9
- bitcoin: "\uf006"
10
- bitcoin-sign: "\uf007"
11
- braintree: "\uf008"
12
- btc: "\uf009"
13
- card: "\uf00a"
14
- carta-si: "\uf00b"
15
- cash: "\uf00c"
16
- cash-on-delivery: "\uf00d"
17
- cb: "\uf00e"
18
- cirrus: "\uf00f"
19
- cirrus-alt: "\uf010"
20
- clickandbuy: "\uf011"
21
- credit-card: "\uf012"
22
- diners: "\uf013"
23
- discover: "\uf014"
24
- ec: "\uf015"
25
- eps: "\uf016"
26
- eur: "\uf017"
27
- facture: "\uf018"
28
- fattura: "\uf019"
29
- flattr: "\uf01a"
30
- giropay: "\uf01b"
31
- gittip: "\uf01c"
32
- gratipay: "\uf01c"
33
- google-wallet: "\uf01d"
34
- google-wallet-alt: "\uf01e"
35
- gbp: "\uf01f"
36
- ideal: "\uf020"
37
- ils: "\uf021"
38
- inr: "\uf022"
39
- invoice: "\uf023"
40
- invoice-sign: "\uf024"
41
- invoice-sign-alt: "\uf025"
42
- invoice-sign-alt-o: "\uf026"
43
- invoice-sign-o: "\uf027"
44
- jcb: "\uf028"
45
- jpy: "\uf029"
46
- krw: "\uf02a"
47
- maestro: "\uf02b"
48
- maestro-alt: "\uf02c"
49
- mastercard: "\uf02d"
50
- mastercard-alt: "\uf02e"
51
- mastercard-securecode: "\uf02f"
52
- ogone: "\uf030"
53
- paybox: "\uf031"
54
- paylife: "\uf032"
55
- paypal: "\uf033"
56
- paypal-alt: "\uf034"
57
- paysafecard: "\uf035"
58
- postepay: "\uf036"
59
- quick: "\uf037"
60
- rechnung: "\uf038"
61
- ripple: "\uf039"
62
- rub: "\uf03a"
63
- skrill: "\uf03b"
64
- sofort: "\uf03c"
65
- square: "\uf03d"
66
- stripe: "\uf03e"
67
- truste: "\uf03f"
68
- try: "\uf040"
69
- unionpay: "\uf041"
70
- usd: "\uf042"
71
- verified-by-visa: "\uf043"
72
- verisign: "\uf044"
73
- visa: "\uf045"
74
- visa-electron: "\uf046"
75
- western-union: "\uf047"
76
- western-union-alt: "\uf048"
77
- wirecard: "\uf049"
78
- sepa: "\uf04a"
79
- sepa-alt: "\uf04b"
80
- apple-pay: "\uf04c"
81
- interac: "\uf04d"
82
- paymill: "\uf04e"
83
- dankort: "\uf04f"
84
- bancontact-mister-cash: "\uf050"
85
- moip: "\uf051"
86
- pagseguro: "\uf052"
87
- cash-on-pickup: "\uf053"
88
- sage: "\uf054"
89
- elo: "\uf055"
90
- elo-alt: "\uf056"
91
- payu: "\uf057"
92
- mercado-pago: "\uf058"
93
- mercado-pago-sign: "\uf059"
94
- payshop: "\uf05a"
95
- multibanco: "\uf05b"
96
- gratipay-sign: "\uf05c"
97
- six: "\uf05d"
98
- cashcloud: "\uf05e"
3
+ __font_version__: 1.2.5
4
+ amazon: ""
5
+ american-express: ""
6
+ american-express-alt: ""
7
+ atm: ""
8
+ bankomat: ""
9
+ bank-transfer: ""
10
+ bitcoin: ""
11
+ bitcoin-sign: ""
12
+ braintree: ""
13
+ btc: ""
14
+ card: ""
15
+ carta-si: ""
16
+ cash: ""
17
+ cash-on-delivery: ""
18
+ cb: ""
19
+ cirrus: ""
20
+ cirrus-alt: ""
21
+ clickandbuy: ""
22
+ credit-card: ""
23
+ diners: ""
24
+ discover: ""
25
+ ec: ""
26
+ eps: ""
27
+ eur: ""
28
+ facture: ""
29
+ fattura: ""
30
+ flattr: ""
31
+ giropay: ""
32
+ google-wallet: ""
33
+ google-wallet-alt: ""
34
+ gpb: ""
35
+ gratipay: ""
36
+ ideal: ""
37
+ ils: ""
38
+ inr: ""
39
+ invoice: ""
40
+ invoice-sign: ""
41
+ invoice-sign-alt: ""
42
+ invoice-sign-alt-o: ""
43
+ invoice-sign-o: ""
44
+ jcb: ""
45
+ jpy: ""
46
+ krw: ""
47
+ maestro: ""
48
+ maestro-alt: ""
49
+ mastercard: ""
50
+ mastercard-alt: ""
51
+ mastercard-securecode: ""
52
+ ogone: ""
53
+ paybox: ""
54
+ paylife: ""
55
+ paypal: ""
56
+ paypal-alt: ""
57
+ paysafecard: ""
58
+ postepay: ""
59
+ quick: ""
60
+ rechnung: ""
61
+ ripple: ""
62
+ rub: ""
63
+ skrill: ""
64
+ sofort: ""
65
+ square: ""
66
+ stripe: ""
67
+ truste: ""
68
+ try: ""
69
+ unionpay: ""
70
+ usd: ""
71
+ verified-by-visa: ""
72
+ verisign: ""
73
+ visa: ""
74
+ visa-electron: ""
75
+ western-union: ""
76
+ western-union-alt: ""
77
+ wirecard: ""
78
+ sepa: ""
79
+ sepa-alt: ""
80
+ apple-pay: ""
81
+ interac: ""
82
+ paymill: ""
83
+ dankort: ""
84
+ bancontact-mister-cash: ""
85
+ moip: ""
86
+ pagseguro: ""
87
+ cash-on-pickup: ""
88
+ sage: ""
89
+ elo: ""
90
+ elo-alt: ""
91
+ payu: ""
92
+ mercado-pago: ""
93
+ mercado-pago-sign: ""
94
+ payshop: ""
95
+ multibanco: ""
96
+ gratipay-sign: ""
97
+ six: ""
98
+ cashcloud: ""
99
+ interac-alt: ""
100
+ klarna: ""
101
+ bitpay: ""
102
+ venmo: ""
103
+ visa-debit: ""
104
+ alipay: ""
105
+ diners-alt: ""
106
+ hipercard: ""
107
+ skrill-alt: ""
108
+ shopify: ""
109
+ direct-debit: ""
110
+ sodexo: ""
111
+ bpay: ""
112
+ contactless: ""
113
+ contactless-alt: ""
114
+ eth: ""
115
+ ltc: ""
116
+ visa-pay: ""
117
+ wechat-pay: ""
118
+ amazon-pay: ""
119
+ amazon-pay-alt: ""
Binary file
Binary file
@@ -3,33 +3,41 @@
3
3
  require_relative '../lib/prawn/icon'
4
4
  require_relative 'example_helper'
5
5
 
6
- Prawn::Document.generate('fontawesome.pdf') do
7
- deja_path = File.join \
8
- Prawn::Icon::Base::FONTDIR, 'DejaVuSans.ttf'
6
+ STYLES = {
7
+ fab: 'Brands',
8
+ far: 'Regular',
9
+ fas: 'Solid'
10
+ }.freeze
9
11
 
10
- font_families.update({
11
- 'deja' => { normal: deja_path }
12
- })
12
+ STYLES.each do |specifier, type|
13
+ Prawn::Document.generate("fontawesome_#{type.downcase}.pdf") do
14
+ deja_path = File.join \
15
+ Prawn::Icon::Base::FONTDIR, 'DejaVuSans.ttf'
13
16
 
14
- font('deja')
17
+ font_families.update(
18
+ 'deja' => { normal: deja_path }
19
+ )
15
20
 
16
- icons = icon_keys(self, 'fa')
17
- required_pages = number_of_pages(self, 'fa')
21
+ font('deja')
18
22
 
19
- define_grid(columns: 6, rows: 12, gutter: 16)
23
+ icons = icon_keys(self, specifier.to_s)
24
+ required_pages = number_of_pages(self, specifier.to_s)
20
25
 
21
- sub_header = 'FontAwesome'
22
- link = 'http://fontawesome.io/icons/'
23
- page_header sub_header, link
26
+ define_grid(columns: 6, rows: 12, gutter: 16)
24
27
 
25
- first_page_icons icons do |icon_key|
26
- # Just call the +icon+ method and pass in an icon key
27
- icon icon_key, size: 20, align: :center
28
- end
28
+ sub_header = "FontAwesome | #{type}"
29
+ link = 'http://fontawesome.io/icons/'
30
+ page_header sub_header, link
31
+
32
+ first_page_icons icons do |icon_key|
33
+ # Just call the +icon+ method and pass in an icon key
34
+ icon icon_key, size: 20, align: :center
35
+ end
29
36
 
30
- start_new_page
37
+ start_new_page
31
38
 
32
- page_icons icons, required_pages do |icon_key|
33
- icon icon_key, size: 20, align: :center
39
+ page_icons icons, required_pages do |icon_key|
40
+ icon icon_key, size: 20, align: :center
41
+ end
34
42
  end
35
43
  end
data/lib/prawn/icon.rb CHANGED
@@ -6,6 +6,7 @@
6
6
  #
7
7
  # This is free software. Please see the LICENSE and COPYING files for details.
8
8
 
9
+ require_relative 'icon/version'
9
10
  require_relative 'icon/base'
10
11
  require_relative 'icon/font_data'
11
12
  require_relative 'icon/parser'
@@ -1,3 +1,11 @@
1
+ # encoding: utf-8
2
+ #
3
+ # errors.rb - Prawn::Icon standard errors.
4
+ #
5
+ # Copyright September 2016, Jesse Doyle. All rights reserved.
6
+ #
7
+ # This is free software. Please see the LICENSE and COPYING files for details.
8
+
1
9
  module Prawn
2
10
  class Icon
3
11
  module Errors
@@ -45,7 +45,7 @@ module Prawn
45
45
  attr_reader :set
46
46
 
47
47
  def initialize(document, opts = {})
48
- @set = opts[:set] || :fa
48
+ @set = opts.fetch(:set)
49
49
  load_fonts(document)
50
50
  end
51
51
 
@@ -9,8 +9,7 @@
9
9
  module Prawn
10
10
  # Easy icon font usage within Prawn. Currently
11
11
  # supported icon fonts include: FontAwesome,
12
- # Zurb Foundicons, GitHub Octicons, as well as
13
- # PaymentFont.
12
+ # Zurb Foundicons and PaymentFont.
14
13
  #
15
14
  # = Icon Keys
16
15
  #
@@ -58,8 +57,8 @@ module Prawn
58
57
  # the underlying +text+ method call.
59
58
  #
60
59
  # == Examples:
61
- # pdf.icon 'fa-beer'
62
- # pdf.icon '<icon color="0099FF">fa-arrows</icon>',
60
+ # pdf.icon 'fas-beer'
61
+ # pdf.icon '<icon color="0099FF">fas-user-circle</icon>',
63
62
  # inline_format: true
64
63
  #
65
64
  def icon(key, opts = {})
@@ -135,7 +134,7 @@ module Prawn
135
134
  # that match the data necessary for the
136
135
  # specified icon.
137
136
  #
138
- # eg. { font: 'fa', content: '\uf047' }
137
+ # eg. { font: 'fas', content: "\uf2b9" }
139
138
  #
140
139
  # Note that the +font+ key will not be set
141
140
  # if +inline_format: true+.
@@ -145,7 +144,7 @@ module Prawn
145
144
  #
146
145
  # data = [
147
146
  # # Explicit brackets must be used here
148
- # [pdf.table_icon('fa-arrows'), 'Cell 1'],
147
+ # [pdf.table_icon('fas-coffee'), 'Cell 1'],
149
148
  # ['Cell 2', 'Cell 3']
150
149
  # ]
151
150
  #
@@ -8,6 +8,6 @@
8
8
 
9
9
  module Prawn
10
10
  class Icon
11
- VERSION = '1.3.0'.freeze
11
+ VERSION = '2.0.0'.freeze
12
12
  end
13
13
  end
data/prawn-icon.gemspec CHANGED
@@ -1,16 +1,15 @@
1
1
  basedir = File.expand_path(File.dirname(__FILE__))
2
2
  require "#{basedir}/lib/prawn/icon/version"
3
3
 
4
- # rubocop:disable Metrics/BlockLength
5
4
  Gem::Specification.new do |spec|
6
5
  spec.name = 'prawn-icon'
7
6
  spec.version = Prawn::Icon::VERSION
8
7
  spec.platform = Gem::Platform::RUBY
9
8
  spec.summary = 'Provides icon fonts for PrawnPDF'
10
9
  spec.files = Dir.glob('{lib,spec,data,examples}/**/**/*') +
11
- %w(prawn-icon.gemspec Gemfile Rakefile) +
12
- %w(README.md CHANGELOG.md) +
13
- %w(COPYING LICENSE GPLv2 GPLv3)
10
+ %w[prawn-icon.gemspec Gemfile Rakefile] +
11
+ %w[README.md CHANGELOG.md] +
12
+ %w[COPYING LICENSE GPLv2 GPLv3]
14
13
 
15
14
  spec.require_path = 'lib'
16
15
  spec.required_ruby_version = '>= 1.9.3'
@@ -25,16 +24,16 @@ Gem::Specification.new do |spec|
25
24
 
26
25
  spec.add_dependency('prawn', '>= 1.1.0', '< 3.0.0')
27
26
 
28
- spec.add_development_dependency('pdf-inspector', '~> 1.2.1')
29
- spec.add_development_dependency('rspec', '~> 3.5.0')
30
- spec.add_development_dependency('rubocop', '~> 0.44.1')
27
+ 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')
31
30
  spec.add_development_dependency('rake')
32
- spec.add_development_dependency('pdf-reader', '~> 1.4')
33
- spec.add_development_dependency('simplecov', '~> 0.12')
31
+ spec.add_development_dependency('pdf-reader', '>= 1.4')
32
+ spec.add_development_dependency('simplecov')
34
33
 
35
34
  spec.description = <<-END_DESC
36
35
  Prawn::Icon provides various icon fonts including
37
- FontAwesome, Foundation Icons and GitHub Octicons
36
+ FontAwesome, PaymentFont and Foundation Icons
38
37
  for use with the Prawn PDF toolkit.
39
38
  END_DESC
40
39
  end
@@ -13,7 +13,7 @@ describe Prawn::Icon::Interface do
13
13
  context 'valid icon key' do
14
14
  context 'with options' do
15
15
  it 'should handle text options (size)' do
16
- pdf.icon 'fa-arrows', size: 60
16
+ pdf.icon 'far-address-book', size: 60
17
17
  text = PDF::Inspector::Text.analyze(pdf.render)
18
18
 
19
19
  expect(text.font_settings.first[:size]).to eq(60)
@@ -22,27 +22,27 @@ describe Prawn::Icon::Interface do
22
22
 
23
23
  context 'inline_format: true' do
24
24
  it 'should handle text options (size)' do
25
- pdf.icon '<icon size="60">fa-arrows</icon>', inline_format: true
25
+ pdf.icon '<icon size="60">far-address-book</icon>', inline_format: true
26
26
  text = PDF::Inspector::Text.analyze(pdf.render)
27
27
 
28
- expect(text.strings.first).to eq("\uf047")
28
+ expect(text.strings.first).to eq('')
29
29
  expect(text.font_settings.first[:size]).to eq(60.0)
30
30
  end
31
31
 
32
32
  it 'should be able to render on multiple documents' do
33
33
  pdf1 = create_pdf
34
34
  pdf2 = create_pdf
35
- pdf1.icon '<icon>fa-arrows</icon>', inline_format: true
36
- pdf2.icon '<icon>fa-arrows</icon>', inline_format: true
35
+ pdf1.icon '<icon>far-address-book</icon>', inline_format: true
36
+ pdf2.icon '<icon>far-address-book</icon>', inline_format: true
37
37
  text1 = PDF::Inspector::Text.analyze(pdf1.render)
38
38
  text2 = PDF::Inspector::Text.analyze(pdf2.render)
39
39
 
40
- expect(text1.strings.first).to eq("\uf047")
41
- expect(text2.strings.first).to eq("\uf047")
40
+ expect(text1.strings.first).to eq('')
41
+ expect(text2.strings.first).to eq('')
42
42
  end
43
43
 
44
44
  it 'renders the icon at the proper cursor position (#24)' do
45
- icon_text = '<icon>fa-info-circle</icon> icon here!'
45
+ icon_text = '<icon>fas-info-circle</icon> icon here!'
46
46
  pdf.text 'Start'
47
47
  pdf.move_down 10
48
48
  pdf.text 'More'
@@ -57,7 +57,7 @@ describe Prawn::Icon::Interface do
57
57
 
58
58
  context 'with final_gap: false' do
59
59
  it 'renders the icon without a final gap' do
60
- icon = pdf.icon '<icon size="60">fa-arrows</icon>',
60
+ icon = pdf.icon '<icon size="60">far-address-book</icon>',
61
61
  inline_format: true,
62
62
  final_gap: false
63
63
  expect(icon.at.last.round).to eq(792)
@@ -67,17 +67,17 @@ describe Prawn::Icon::Interface do
67
67
 
68
68
  context 'without options' do
69
69
  it 'should render an icon to document' do
70
- pdf.icon 'fa-arrows'
70
+ pdf.icon 'far-address-book'
71
71
  text = PDF::Inspector::Text.analyze(pdf.render)
72
72
 
73
- expect(text.strings.first).to eq("\uf047")
73
+ expect(text.strings.first).to eq('')
74
74
  end
75
75
  end
76
76
  end
77
77
 
78
78
  context 'invalid icon key' do
79
79
  it 'should raise IconNotFound' do
80
- proc = Proc.new { pdf.icon 'fa-__INVALID' }
80
+ proc = Proc.new { pdf.icon 'far-__INVALID' }
81
81
 
82
82
  expect(proc).to raise_error(Prawn::Icon::Errors::IconNotFound)
83
83
  end
@@ -95,7 +95,7 @@ describe Prawn::Icon::Interface do
95
95
  describe '::make_icon' do
96
96
  context ':inline_format => false (default)' do
97
97
  it 'should return a Prawn::Icon instance' do
98
- icon = pdf.make_icon 'fa-arrows'
98
+ icon = pdf.make_icon 'far-address-book'
99
99
 
100
100
  expect(icon).to be_a(Prawn::Icon)
101
101
  end
@@ -103,7 +103,7 @@ describe Prawn::Icon::Interface do
103
103
 
104
104
  context ':inline_format => true' do
105
105
  it 'should return a Prawn::::Text::Formatted::Box instance' do
106
- icon = pdf.make_icon '<icon>fa-arrows</icon>', inline_format: true
106
+ icon = pdf.make_icon '<icon>far-address-book</icon>', inline_format: true
107
107
 
108
108
  expect(icon).to be_a(Prawn::Text::Formatted::Box)
109
109
  end
@@ -112,7 +112,7 @@ describe Prawn::Icon::Interface do
112
112
 
113
113
  describe '::inline_icon' do
114
114
  it 'should return a Prawn::Text::Formatted::Box instance' do
115
- icon = pdf.inline_icon '<icon>fa-arrows</icon>'
115
+ icon = pdf.inline_icon '<icon>far-address-book</icon>'
116
116
 
117
117
  expect(icon).to be_a(Prawn::Text::Formatted::Box)
118
118
  end
@@ -121,20 +121,20 @@ describe Prawn::Icon::Interface do
121
121
  describe '::table_icon' do
122
122
  context 'inline_format: false (default)' do
123
123
  it 'should return a hash with font and content keys' do
124
- icon = pdf.table_icon 'fa-arrows'
124
+ icon = pdf.table_icon 'far-address-book'
125
125
 
126
126
  expect(icon).to be_a(Hash)
127
- expect(icon[:font]).to eq('fa')
128
- expect(icon[:content]).to eq("\uf047")
127
+ expect(icon[:font]).to eq('far')
128
+ expect(icon[:content]).to eq('')
129
129
  end
130
130
  end
131
131
 
132
132
  context 'inline_format: true' do
133
133
  it 'should convert <icon> to <font> tags' do
134
- icon = pdf.table_icon '<icon>fa-user</icon>', inline_format: true
134
+ icon = pdf.table_icon '<icon>fas-user</icon>', inline_format: true
135
135
 
136
136
  expect(icon).to be_a(Hash)
137
- expect(icon[:content]).to eq('<font name="fa"></font>')
137
+ expect(icon[:content]).to eq('<font name="fas"></font>')
138
138
  expect(icon[:inline_format]).to be true
139
139
  end
140
140
 
@@ -149,8 +149,8 @@ describe Prawn::Icon::Interface do
149
149
 
150
150
  context 'multiple icons' do
151
151
  it 'should ignore any text not in an icon tag' do
152
- a = ['<icon>fa-user</icon> Some Text <icon>fi-laptop</icon>', inline_format: true]
153
- out = '<font name="fa"></font> Some Text <font name="fi"></font>'
152
+ a = ['<icon>fas-user</icon> Some Text <icon>fi-laptop</icon>', inline_format: true]
153
+ out = '<font name="fas"></font> Some Text <font name="fi"></font>'
154
154
  icon = pdf.table_icon(*a)
155
155
 
156
156
  expect(icon).to be_a(Hash)
@@ -165,30 +165,39 @@ end
165
165
  describe Prawn::Icon do
166
166
  let(:pdf) { create_pdf }
167
167
 
168
- context 'FontAwesome' do
169
- it 'should render FontAwesome glyphs' do
170
- pdf.icon 'fa-user'
168
+ context 'FontAwesome | Regular' do
169
+ it 'should render regular glyphs' do
170
+ pdf.icon 'far-user'
171
171
  text = PDF::Inspector::Text.analyze(pdf.render)
172
172
 
173
- expect(text.strings.first).to eq("")
173
+ expect(text.strings.first).to eq('')
174
174
  end
175
175
  end
176
176
 
177
- context 'Foundation Icons' do
178
- it 'should render Foundation glyphs' do
179
- pdf.icon 'fi-laptop'
177
+ context 'FontAwesome | Solid' do
178
+ it 'should render solid glyphs' do
179
+ pdf.icon 'fas-user'
180
180
  text = PDF::Inspector::Text.analyze(pdf.render)
181
181
 
182
- expect(text.strings.first).to eq("")
182
+ expect(text.strings.first).to eq('')
183
183
  end
184
184
  end
185
185
 
186
- context 'GitHub Octicons' do
187
- it 'should render GitHub Octicon glyphs' do
188
- pdf.icon 'octicon-logo-github'
186
+ context 'FontAwesome | Brands' do
187
+ it 'should render FontAwesome glyphs' do
188
+ pdf.icon 'fab-amazon'
189
+ text = PDF::Inspector::Text.analyze(pdf.render)
190
+
191
+ expect(text.strings.first).to eq('')
192
+ end
193
+ end
194
+
195
+ context 'Foundation Icons' do
196
+ it 'should render Foundation glyphs' do
197
+ pdf.icon 'fi-laptop'
189
198
  text = PDF::Inspector::Text.analyze(pdf.render)
190
199
 
191
- expect(text.strings.first).to eq("")
200
+ expect(text.strings.first).to eq('')
192
201
  end
193
202
  end
194
203
 
@@ -197,7 +206,7 @@ describe Prawn::Icon do
197
206
  pdf.icon 'pf-amazon'
198
207
  text = PDF::Inspector::Text.analyze(pdf.render)
199
208
 
200
- expect(text.strings.first).to eq("")
209
+ expect(text.strings.first).to eq('')
201
210
  end
202
211
  end
203
212
  end