prawn-icon 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/prawn/icon/font_data.rb +10 -14
- data/lib/prawn/icon/version.rb +1 -1
- data/prawn-icon.gemspec +1 -1
- data/spec/integration/icon_spec.rb +12 -2
- data/spec/unit/font_data_spec.rb +11 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b72801a22245be5c21023bc4dd96f34a9888c3b
|
4
|
+
data.tar.gz: 43384f7f447921f7ff5a4dae77fe1aaf4e5ee369
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b83ad4e37b575f040ca394ccbb0378bdeef0671ee5106a775ae57bda71113eb85bd0cf000a465f52d56669bd118d77059b33971f921e6f774ea8d0a69bf3bc14
|
7
|
+
data.tar.gz: 9cf1c9a029f4487ba0551e9a16c8138e91c39d1c9498b7d9a72a189518e14af2605976f836f1f17193063a9521dc93310e4a62f571c9384ee90e26b408c81333
|
data/lib/prawn/icon/font_data.rb
CHANGED
@@ -12,12 +12,13 @@ module Prawn
|
|
12
12
|
class Icon
|
13
13
|
class FontData
|
14
14
|
class << self
|
15
|
-
#
|
16
|
-
#
|
15
|
+
# Font data lazy-loader that will initialize
|
16
|
+
# icon fonts by document.
|
17
17
|
def load(document, set)
|
18
18
|
set = set.to_sym
|
19
|
-
@data
|
19
|
+
@data ||= {}
|
20
20
|
@data[set] ||= FontData.new(document, set: set)
|
21
|
+
@data[set].load_fonts(document)
|
21
22
|
end
|
22
23
|
|
23
24
|
# Release all font references if requested.
|
@@ -44,9 +45,8 @@ module Prawn
|
|
44
45
|
attr_reader :set
|
45
46
|
|
46
47
|
def initialize(document, opts = {})
|
47
|
-
@pdf = document
|
48
48
|
@set = opts[:set] || :fa
|
49
|
-
|
49
|
+
load_fonts(document)
|
50
50
|
end
|
51
51
|
|
52
52
|
def font_version
|
@@ -57,6 +57,11 @@ module Prawn
|
|
57
57
|
File.join(File.dirname(path), "#{@set}.yml")
|
58
58
|
end
|
59
59
|
|
60
|
+
def load_fonts(document)
|
61
|
+
document.font_families[@set.to_s] ||= { normal: path }
|
62
|
+
self
|
63
|
+
end
|
64
|
+
|
60
65
|
def path
|
61
66
|
ttf = File.join(Icon::FONTDIR, @set.to_s, '*.ttf')
|
62
67
|
fonts = Dir[ttf]
|
@@ -92,15 +97,6 @@ module Prawn
|
|
92
97
|
def yaml
|
93
98
|
@yaml ||= YAML.load_file legend_path
|
94
99
|
end
|
95
|
-
|
96
|
-
private
|
97
|
-
|
98
|
-
def update_document_fonts!
|
99
|
-
@pdf.font_families.update(
|
100
|
-
@set.to_s => {
|
101
|
-
normal: path
|
102
|
-
})
|
103
|
-
end
|
104
100
|
end
|
105
101
|
end
|
106
102
|
end
|
data/lib/prawn/icon/version.rb
CHANGED
data/prawn-icon.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.required_ruby_version = '>= 1.9.3'
|
14
14
|
spec.required_rubygems_version = '>= 1.3.6'
|
15
15
|
|
16
|
-
spec.homepage =
|
16
|
+
spec.homepage = 'https://github.com/jessedoyle/prawn-icon/'
|
17
17
|
|
18
18
|
spec.test_files = Dir['spec/*_spec.rb']
|
19
19
|
spec.authors = ['Jesse Doyle']
|
@@ -22,14 +22,24 @@ describe Prawn::Icon::Interface do
|
|
22
22
|
context 'inline_format: true' do
|
23
23
|
it 'should handle text options (size)' do
|
24
24
|
pdf = create_pdf
|
25
|
-
# We need to flush the font cache here...
|
26
|
-
Prawn::Icon::FontData.release_data
|
27
25
|
pdf.icon '<icon size="60">fa-arrows</icon>', inline_format: true
|
28
26
|
text = PDF::Inspector::Text.analyze(pdf.render)
|
29
27
|
|
30
28
|
expect(text.strings.first).to eq("\uf047")
|
31
29
|
expect(text.font_settings.first[:size]).to eq(60.0)
|
32
30
|
end
|
31
|
+
|
32
|
+
it 'should be able to render on mulitple documents' do
|
33
|
+
pdf1 = create_pdf
|
34
|
+
pdf2 = create_pdf
|
35
|
+
pdf1.icon '<icon>fa-arrows</icon>', inline_format: true
|
36
|
+
pdf2.icon '<icon>fa-arrows</icon>', inline_format: true
|
37
|
+
text1 = PDF::Inspector::Text.analyze(pdf1.render)
|
38
|
+
text2 = PDF::Inspector::Text.analyze(pdf2.render)
|
39
|
+
|
40
|
+
expect(text1.strings.first).to eq("\uf047")
|
41
|
+
expect(text2.strings.first).to eq("\uf047")
|
42
|
+
end
|
33
43
|
end
|
34
44
|
|
35
45
|
context 'without options' do
|
data/spec/unit/font_data_spec.rb
CHANGED
@@ -17,7 +17,7 @@ describe Prawn::Icon::FontData do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
describe '::load' do
|
20
|
-
it 'should
|
20
|
+
it 'should only load a single object for multiple documents' do
|
21
21
|
pdf = create_pdf
|
22
22
|
data = Prawn::Icon::FontData.load(pdf, 'fa')
|
23
23
|
obj_id_1 = data.__id__
|
@@ -110,6 +110,16 @@ describe Prawn::Icon::FontData do
|
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
113
|
+
describe '#load_fonts' do
|
114
|
+
it 'should return a FontData object' do
|
115
|
+
pdf = create_pdf
|
116
|
+
data = Prawn::Icon::FontData.new(pdf)
|
117
|
+
ret_val = data.load_fonts(pdf)
|
118
|
+
|
119
|
+
expect(ret_val.is_a? Prawn::Icon::FontData).to be_true
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
113
123
|
describe '#path' do
|
114
124
|
it 'should have a valid path to a TTF file' do
|
115
125
|
pdf = create_pdf
|
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: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jesse Doyle
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: prawn
|