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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +54 -1
- data/GPLv2 +21 -22
- data/README.md +10 -10
- data/data/fonts/fab/LICENSE +34 -0
- data/data/fonts/fab/fa-brands.ttf +0 -0
- data/data/fonts/fab/fab.yml +333 -0
- data/data/fonts/far/LICENSE +34 -0
- data/data/fonts/far/fa-regular.ttf +0 -0
- data/data/fonts/far/far.yml +119 -0
- data/data/fonts/fas/LICENSE +34 -0
- data/data/fonts/fas/fa-solid.ttf +0 -0
- data/data/fonts/fas/fas.yml +503 -0
- data/data/fonts/pf/paymentfont-webfont.ttf +0 -0
- data/data/fonts/pf/pf.yml +118 -97
- data/examples/fas-beer-inline.png +0 -0
- data/examples/fas-beer.png +0 -0
- data/examples/fontawesome.rb +28 -20
- data/examples/foundation_icons.rb +1 -1
- data/examples/paymentfont.rb +1 -1
- data/lib/prawn/icon.rb +3 -200
- data/lib/prawn/icon/base.rb +19 -0
- data/lib/prawn/icon/errors.rb +21 -0
- data/lib/prawn/icon/font_data.rb +11 -13
- data/lib/prawn/icon/interface.rb +208 -0
- data/lib/prawn/icon/parser.rb +45 -53
- data/lib/prawn/icon/version.rb +1 -1
- data/prawn-icon.gemspec +8 -9
- data/spec/integration/icon_spec.rb +80 -60
- data/spec/spec_helper.rb +4 -0
- data/spec/support/parser_helper.rb +1 -1
- data/spec/support/pdf_helper.rb +1 -1
- data/spec/unit/base_spec.rb +15 -0
- data/spec/unit/errors/icon_key_empty_spec.rb +19 -0
- data/spec/unit/errors/icon_not_found_spec.rb +19 -0
- data/spec/unit/font_data_spec.rb +54 -73
- data/spec/unit/icon_spec.rb +20 -27
- data/spec/unit/parser_spec.rb +66 -63
- metadata +35 -41
- data/data/fonts/fa/LICENSE +0 -4
- data/data/fonts/fa/fa.yml +0 -676
- data/data/fonts/fa/fontawesome.ttf +0 -0
- data/data/fonts/octicon/LICENSE +0 -9
- data/data/fonts/octicon/octicon.yml +0 -192
- data/data/fonts/octicon/octicons.ttf +0 -0
- data/examples/fa-beer-inline.png +0 -0
- data/examples/fa-beer.png +0 -0
- data/examples/octicons.rb +0 -35
Binary file
|
data/data/fonts/pf/pf.yml
CHANGED
@@ -1,98 +1,119 @@
|
|
1
|
+
---
|
1
2
|
pf:
|
2
|
-
__font_version__:
|
3
|
-
amazon: "
|
4
|
-
american-express: "
|
5
|
-
american-express-alt: "
|
6
|
-
atm: "
|
7
|
-
bankomat: "
|
8
|
-
bank-transfer: "
|
9
|
-
bitcoin: "
|
10
|
-
bitcoin-sign: "
|
11
|
-
braintree: "
|
12
|
-
btc: "
|
13
|
-
card: "
|
14
|
-
carta-si: "
|
15
|
-
cash: "
|
16
|
-
cash-on-delivery: "
|
17
|
-
cb: "
|
18
|
-
cirrus: "
|
19
|
-
cirrus-alt: "
|
20
|
-
clickandbuy: "
|
21
|
-
credit-card: "
|
22
|
-
diners: "
|
23
|
-
discover: "
|
24
|
-
ec: "
|
25
|
-
eps: "
|
26
|
-
eur: "
|
27
|
-
facture: "
|
28
|
-
fattura: "
|
29
|
-
flattr: "
|
30
|
-
giropay: "
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
invoice: "
|
40
|
-
invoice-sign: "
|
41
|
-
invoice-sign-alt: "
|
42
|
-
invoice-sign-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
maestro: "
|
48
|
-
|
49
|
-
mastercard: "
|
50
|
-
mastercard-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
paypal: "
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
visa: "
|
74
|
-
|
75
|
-
western-union: "
|
76
|
-
|
77
|
-
|
78
|
-
sepa: "
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
elo: "
|
90
|
-
|
91
|
-
|
92
|
-
mercado-pago: "
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
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
|
data/examples/fontawesome.rb
CHANGED
@@ -3,33 +3,41 @@
|
|
3
3
|
require_relative '../lib/prawn/icon'
|
4
4
|
require_relative 'example_helper'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
STYLES = {
|
7
|
+
fab: 'Brands',
|
8
|
+
far: 'Regular',
|
9
|
+
fas: 'Solid'
|
10
|
+
}.freeze
|
9
11
|
|
10
|
-
|
11
|
-
|
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
|
-
|
17
|
+
font_families.update(
|
18
|
+
'deja' => { normal: deja_path }
|
19
|
+
)
|
15
20
|
|
16
|
-
|
17
|
-
required_pages = number_of_pages(self, 'fa')
|
21
|
+
font('deja')
|
18
22
|
|
19
|
-
|
23
|
+
icons = icon_keys(self, specifier.to_s)
|
24
|
+
required_pages = number_of_pages(self, specifier.to_s)
|
20
25
|
|
21
|
-
|
22
|
-
link = 'http://fontawesome.io/icons/'
|
23
|
-
page_header sub_header, link
|
26
|
+
define_grid(columns: 6, rows: 12, gutter: 16)
|
24
27
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
37
|
+
start_new_page
|
31
38
|
|
32
|
-
|
33
|
-
|
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 }
|
data/examples/paymentfont.rb
CHANGED
data/lib/prawn/icon.rb
CHANGED
@@ -6,207 +6,10 @@
|
|
6
6
|
#
|
7
7
|
# This is free software. Please see the LICENSE and COPYING files for details.
|
8
8
|
|
9
|
-
|
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
|