prawn-icon 1.4.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -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'
@@ -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.4.0'.freeze
11
+ VERSION = '2.0.0'.freeze
12
12
  end
13
13
  end
@@ -33,7 +33,7 @@ Gem::Specification.new do |spec|
33
33
 
34
34
  spec.description = <<-END_DESC
35
35
  Prawn::Icon provides various icon fonts including
36
- FontAwesome, Foundation Icons and GitHub Octicons
36
+ FontAwesome, PaymentFont and Foundation Icons
37
37
  for use with the Prawn PDF toolkit.
38
38
  END_DESC
39
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
@@ -12,7 +12,7 @@ describe Prawn::Icon::Errors::IconNotFound do
12
12
  end
13
13
 
14
14
  it 'is thrown on an invalid icon key' do
15
- proc = Proc.new { pdf.icon 'fa-an invalid key' }
15
+ proc = Proc.new { pdf.icon 'far-an invalid key' }
16
16
 
17
17
  expect(proc).to raise_error(described_class)
18
18
  end
@@ -8,21 +8,21 @@ require 'spec_helper'
8
8
 
9
9
  describe Prawn::Icon::FontData do
10
10
  let(:pdf) { create_pdf }
11
- let(:fontawesome) { Prawn::Icon::FontData.new(pdf, set: :fa) }
11
+ let(:fontawesome) { Prawn::Icon::FontData.new(pdf, set: :far) }
12
12
 
13
13
  before { Prawn::Icon::FontData.release_data }
14
14
 
15
15
  describe '#initialize' do
16
- before { Prawn::Icon::FontData.new(pdf, set: :fa) }
16
+ before { Prawn::Icon::FontData.new(pdf, set: :far) }
17
17
 
18
18
  it 'should update font_families on initialization' do
19
- expect(pdf.font_families['fa']).not_to be_nil
19
+ expect(pdf.font_families['far']).not_to be_nil
20
20
  end
21
21
  end
22
22
 
23
23
  describe '::load' do
24
24
  context 'specifier is a string' do
25
- let(:data) { Prawn::Icon::FontData.load(pdf, 'fa') }
25
+ let(:data) { Prawn::Icon::FontData.load(pdf, 'far') }
26
26
 
27
27
  it 'should load the font' do
28
28
  expect(data).not_to be_nil
@@ -30,7 +30,7 @@ describe Prawn::Icon::FontData do
30
30
 
31
31
  it 'should only load a single object for multiple documents' do
32
32
  obj_id_1 = data.object_id
33
- second = Prawn::Icon::FontData.load(pdf, 'fa')
33
+ second = Prawn::Icon::FontData.load(pdf, 'far')
34
34
  obj_id_2 = second.object_id
35
35
 
36
36
  expect(obj_id_1).to eq(obj_id_2)
@@ -38,7 +38,7 @@ describe Prawn::Icon::FontData do
38
38
  end
39
39
 
40
40
  context 'specifier is a symbol' do
41
- let(:data) { Prawn::Icon::FontData.load(pdf, :fa) }
41
+ let(:data) { Prawn::Icon::FontData.load(pdf, :far) }
42
42
 
43
43
  it 'should load the font' do
44
44
  expect(data).not_to be_nil
@@ -48,9 +48,8 @@ describe Prawn::Icon::FontData do
48
48
 
49
49
  describe '::release_data' do
50
50
  it 'should remove all data references if requested' do
51
- Prawn::Icon::FontData.load(pdf, :fa)
51
+ Prawn::Icon::FontData.load(pdf, :far)
52
52
  Prawn::Icon::FontData.load(pdf, :fi)
53
- Prawn::Icon::FontData.load(pdf, :octicon)
54
53
  data = Prawn::Icon::FontData.release_data
55
54
 
56
55
  expect(data).to be_empty
@@ -59,7 +58,7 @@ describe Prawn::Icon::FontData do
59
58
 
60
59
  describe '::unicode_from_key' do
61
60
  it 'should provide a UTF-8 string for a valid key' do
62
- unicode = Prawn::Icon::FontData.unicode_from_key(pdf, 'fa-arrows')
61
+ unicode = Prawn::Icon::FontData.unicode_from_key(pdf, 'far-address-book')
63
62
  valid = unicode.force_encoding('UTF-8').valid_encoding?
64
63
 
65
64
  expect(valid).to be true
@@ -68,8 +67,8 @@ describe Prawn::Icon::FontData do
68
67
 
69
68
  describe '::specifier_from_key' do
70
69
  it 'should provide the font specifier from a valid key' do
71
- specifier = Prawn::Icon::FontData.specifier_from_key('fa-arrows')
72
- expect(specifier).to eq(:fa)
70
+ specifier = Prawn::Icon::FontData.specifier_from_key('far-address-book')
71
+ expect(specifier).to eq(:far)
73
72
  end
74
73
 
75
74
  it 'should error when key is nil' do
@@ -129,13 +128,13 @@ describe Prawn::Icon::FontData do
129
128
  it 'should retrieve the string specifier from the yaml legend file' do
130
129
  specifier = fontawesome.specifier
131
130
 
132
- expect(specifier).to eq('fa')
131
+ expect(specifier).to eq('far')
133
132
  end
134
133
  end
135
134
 
136
135
  describe '#unicode' do
137
136
  it 'should provide a valid UTF-8 encoded string for a valid key' do
138
- unicode = fontawesome.unicode('arrows')
137
+ unicode = fontawesome.unicode('address-book')
139
138
  valid = unicode.force_encoding('UTF-8').valid_encoding?
140
139
 
141
140
  expect(valid).to be true
@@ -167,13 +166,13 @@ describe Prawn::Icon::FontData do
167
166
  it 'should return a hash with the specifier as the first key' do
168
167
  yaml = fontawesome.yaml
169
168
  key = yaml.keys.first
170
- mapping = yaml['fa']
169
+ mapping = yaml['far']
171
170
  inner_key = mapping.keys.last
172
171
  inner_value = mapping.values.last
173
172
  proc = Proc.new { inner_value.force_encoding('UTF-8').valid_encoding? }
174
173
 
175
174
  expect(yaml).to be_a(Hash)
176
- expect(key).to eq('fa')
175
+ expect(key).to eq('far')
177
176
  expect(inner_key).to be_a(String)
178
177
  expect(inner_value).to be_a(String)
179
178
  expect(proc.call).to be true