prawn-icon 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +54 -1
  3. data/GPLv2 +21 -22
  4. data/README.md +10 -10
  5. data/data/fonts/fab/LICENSE +34 -0
  6. data/data/fonts/fab/fa-brands.ttf +0 -0
  7. data/data/fonts/fab/fab.yml +333 -0
  8. data/data/fonts/far/LICENSE +34 -0
  9. data/data/fonts/far/fa-regular.ttf +0 -0
  10. data/data/fonts/far/far.yml +119 -0
  11. data/data/fonts/fas/LICENSE +34 -0
  12. data/data/fonts/fas/fa-solid.ttf +0 -0
  13. data/data/fonts/fas/fas.yml +503 -0
  14. data/data/fonts/pf/paymentfont-webfont.ttf +0 -0
  15. data/data/fonts/pf/pf.yml +118 -97
  16. data/examples/fas-beer-inline.png +0 -0
  17. data/examples/fas-beer.png +0 -0
  18. data/examples/fontawesome.rb +28 -20
  19. data/examples/foundation_icons.rb +1 -1
  20. data/examples/paymentfont.rb +1 -1
  21. data/lib/prawn/icon.rb +3 -200
  22. data/lib/prawn/icon/base.rb +19 -0
  23. data/lib/prawn/icon/errors.rb +21 -0
  24. data/lib/prawn/icon/font_data.rb +11 -13
  25. data/lib/prawn/icon/interface.rb +208 -0
  26. data/lib/prawn/icon/parser.rb +45 -53
  27. data/lib/prawn/icon/version.rb +1 -1
  28. data/prawn-icon.gemspec +8 -9
  29. data/spec/integration/icon_spec.rb +80 -60
  30. data/spec/spec_helper.rb +4 -0
  31. data/spec/support/parser_helper.rb +1 -1
  32. data/spec/support/pdf_helper.rb +1 -1
  33. data/spec/unit/base_spec.rb +15 -0
  34. data/spec/unit/errors/icon_key_empty_spec.rb +19 -0
  35. data/spec/unit/errors/icon_not_found_spec.rb +19 -0
  36. data/spec/unit/font_data_spec.rb +54 -73
  37. data/spec/unit/icon_spec.rb +20 -27
  38. data/spec/unit/parser_spec.rb +66 -63
  39. metadata +35 -41
  40. data/data/fonts/fa/LICENSE +0 -4
  41. data/data/fonts/fa/fa.yml +0 -676
  42. data/data/fonts/fa/fontawesome.ttf +0 -0
  43. data/data/fonts/octicon/LICENSE +0 -9
  44. data/data/fonts/octicon/octicon.yml +0 -192
  45. data/data/fonts/octicon/octicons.ttf +0 -0
  46. data/examples/fa-beer-inline.png +0 -0
  47. data/examples/fa-beer.png +0 -0
  48. data/examples/octicons.rb +0 -35
@@ -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
@@ -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::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
@@ -5,7 +5,7 @@ require_relative 'example_helper'
5
5
 
6
6
  Prawn::Document.generate('foundation_icons.pdf') do
7
7
  deja_path = File.join \
8
- Prawn::Icon::FONTDIR, 'DejaVuSans.ttf'
8
+ Prawn::Icon::Base::FONTDIR, 'DejaVuSans.ttf'
9
9
 
10
10
  font_families.update({
11
11
  'deja' => { normal: deja_path }
@@ -5,7 +5,7 @@ require_relative 'example_helper'
5
5
 
6
6
  Prawn::Document.generate('paymentfont.pdf') do
7
7
  deja_path = File.join \
8
- Prawn::Icon::FONTDIR, 'DejaVuSans.ttf'
8
+ Prawn::Icon::Base::FONTDIR, 'DejaVuSans.ttf'
9
9
 
10
10
  font_families.update({
11
11
  'deja' => { normal: deja_path }
@@ -6,207 +6,10 @@
6
6
  #
7
7
  # This is free software. Please see the LICENSE and COPYING files for details.
8
8
 
9
- require 'prawn'
9
+ require_relative 'icon/version'
10
+ require_relative 'icon/base'
10
11
  require_relative 'icon/font_data'
11
12
  require_relative 'icon/parser'
12
-
13
- module Prawn
14
- module Errors
15
- # Error raised when an icon glyph is not found
16
- #
17
- IconNotFound = Class.new(StandardError)
18
-
19
- # Error raised when an icon key is not provided
20
- #
21
- IconKeyEmpty = Class.new(StandardError)
22
- end
23
-
24
- # Easy icon font usage within Prawn. Currently
25
- # supported icon fonts include: FontAwesome,
26
- # Zurb Foundicons, GitHub Octicons, as well as
27
- # PaymentFont.
28
- #
29
- # = Icon Keys
30
- #
31
- # Icon keys must be supplied to most +Prawn::Icon+
32
- # methods. Keys map directly to a unicode character
33
- # within the font that produces a given icon. As a
34
- # rule, included icon keys should match the keys from
35
- # the font provider. The icon key mapping is specified
36
- # in the font's +legend_file+, which is a +YAML+ file
37
- # located in Prawn::Icon::FONTDIR/font/font.yml.
38
- #
39
- # Prawn::Icon::
40
- # Houses the methods and interfaces necessary for
41
- # rendering icons to the Prawn::Document.
42
- #
43
- # Prawn::Icon::FontData::
44
- # Used to store various information about an icon font,
45
- # including the key-to-unicode mapping information.
46
- # Also houses methods to cache and lazily load the
47
- # requested font data on a document basis.
48
- #
49
- # Prawn::Icon::Parser::
50
- # Used to initially parse icons that are used with the
51
- # inline_format: true option. The input string is parsed
52
- # once for <icon></icon> tags, then the output is provided
53
- # to Prawn's internal formatted text parser.
54
- #
55
- class Icon
56
- FONTDIR = File.join \
57
- File.expand_path('../../..', __FILE__), 'data/fonts'
58
-
59
- module Interface
60
- # Set up and draw an icon on this document. This
61
- # method operates much like +Prawn::Text::Box+.
62
- #
63
- # == Parameters:
64
- # key::
65
- # Contains the key to a particular icon within
66
- # a font family. If :inline_format is true,
67
- # then key may contain formatted text marked
68
- # with <icon></icon> tags and any tag supported
69
- # by Prawn's parser.
70
- #
71
- # opts::
72
- # A hash of options that may be supplied to
73
- # the underlying +text+ method call.
74
- #
75
- # == Examples:
76
- # pdf.icon 'fa-beer'
77
- # pdf.icon '<icon color="0099FF">fa-arrows</icon>',
78
- # inline_format: true
79
- #
80
- def icon(key, opts = {})
81
- i = make_icon(key, opts)
82
- i.render
83
- i
84
- end
85
-
86
- # Initialize a new icon object, but do
87
- # not render it to the document.
88
- #
89
- # == Parameters:
90
- # key::
91
- # Contains the key to a particular icon within
92
- # a font family. If :inline_format is true,
93
- # then key may contain formatted text marked
94
- # with <icon></icon> tags and any tag supported
95
- # by Prawn's parser.
96
- #
97
- # opts::
98
- # A hash of options that may be supplied to
99
- # the underlying text method call.
100
- #
101
- def make_icon(key, opts = {})
102
- if opts[:inline_format]
103
- inline_icon(key, opts)
104
- else
105
- Icon.new(key, self, opts)
106
- end
107
- end
108
-
109
- # Initialize a new formatted text box containing
110
- # icon information, but don't render it to the
111
- # document.
112
- #
113
- # == Parameters:
114
- # text::
115
- # Input text to be parsed initially for <icon>
116
- # tags, then passed to Prawn's formatted text
117
- # parser.
118
- #
119
- # opts::
120
- # A hash of options that may be supplied to the
121
- # underlying text call.
122
- #
123
- def inline_icon(text, opts = {})
124
- parsed = Icon::Parser.format(self, text)
125
- content = Text::Formatted::Parser.format(parsed)
126
- opts.merge!(inline_format: true, document: self)
127
- Text::Formatted::Box.new(content, opts)
128
- end
129
-
130
- # Initialize a new Prawn::Icon, but don't render
131
- # the icon to a document. Intended to be used as
132
- # an entry of a data array when combined with
133
- # Prawn::Table.
134
- #
135
- # == Parameters:
136
- # key::
137
- # Contains the key to a particular icon within
138
- # a font family. The key may contain a string
139
- # with format tags if +inline_format: true+ in
140
- # the +opts+ hash.
141
- #
142
- # opts::
143
- # A hash of options that may be supplied to the
144
- # underlying text call.
145
- #
146
- # == Returns:
147
- # A Hash containing +font+ and +content+ keys
148
- # that match the data necessary for the
149
- # specified icon.
150
- #
151
- # eg. { font: 'fa', content: '\uf047' }
152
- #
153
- # Note that the +font+ key will not be set
154
- # if +inline_format: true+.
155
- #
156
- # == Examples:
157
- # require 'prawn/table'
158
- #
159
- # data = [
160
- # # Explicit brackets must be used here
161
- # [pdf.table_icon('fa-arrows'), 'Cell 1'],
162
- # ['Cell 2', 'Cell 3']
163
- # ]
164
- #
165
- # pdf.table(data) => (2 x 2 table)
166
- #
167
- def table_icon(key, opts = {})
168
- if opts[:inline_format]
169
- content = Icon::Parser.format(self, key)
170
- opts.merge(content: content)
171
- else
172
- make_icon(key, opts).format_hash
173
- end
174
- end
175
- end
176
-
177
- attr_reader :set, :unicode
178
-
179
- def initialize(key, document, opts = {})
180
- @pdf = document
181
- @set = opts[:set] ||
182
- FontData.specifier_from_key(key)
183
- @data = FontData.load(document, @set)
184
- @key = strip_specifier_from_key(key)
185
- @unicode = @data.unicode(@key)
186
- @options = opts
187
- end
188
-
189
- def format_hash
190
- base = { font: @set.to_s, content: @unicode }
191
- opts = @options.dup
192
- # Prawn::Table renames :color to :text_color
193
- opts[:text_color] = opts.delete(:color)
194
- base.merge(opts)
195
- end
196
-
197
- def render
198
- @pdf.font(@data.path) do
199
- @pdf.text @unicode, @options
200
- end
201
- end
202
-
203
- private
204
-
205
- def strip_specifier_from_key(key) #:nodoc:
206
- reg = Regexp.new "#{@data.specifier}-"
207
- key.sub(reg, '') # Only one specifier
208
- end
209
- end
210
- end
13
+ require_relative 'icon/interface'
211
14
 
212
15
  Prawn::Document.extensions << Prawn::Icon::Interface